chsc.c 23 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024
  1. /*
  2. * drivers/s390/cio/chsc.c
  3. * S/390 common I/O routines -- channel subsystem call
  4. *
  5. * Copyright IBM Corp. 1999,2008
  6. * Author(s): Ingo Adlung (adlung@de.ibm.com)
  7. * Cornelia Huck (cornelia.huck@de.ibm.com)
  8. * Arnd Bergmann (arndb@de.ibm.com)
  9. */
  10. #define KMSG_COMPONENT "cio"
  11. #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
  12. #include <linux/module.h>
  13. #include <linux/slab.h>
  14. #include <linux/init.h>
  15. #include <linux/device.h>
  16. #include <asm/cio.h>
  17. #include <asm/chpid.h>
  18. #include <asm/chsc.h>
  19. #include <asm/crw.h>
  20. #include "css.h"
  21. #include "cio.h"
  22. #include "cio_debug.h"
  23. #include "ioasm.h"
  24. #include "chp.h"
  25. #include "chsc.h"
  26. static void *sei_page;
  27. static DEFINE_SPINLOCK(siosl_lock);
  28. static DEFINE_SPINLOCK(sda_lock);
  29. /**
  30. * chsc_error_from_response() - convert a chsc response to an error
  31. * @response: chsc response code
  32. *
  33. * Returns an appropriate Linux error code for @response.
  34. */
  35. int chsc_error_from_response(int response)
  36. {
  37. switch (response) {
  38. case 0x0001:
  39. return 0;
  40. case 0x0002:
  41. case 0x0003:
  42. case 0x0006:
  43. case 0x0007:
  44. case 0x0008:
  45. case 0x000a:
  46. case 0x0104:
  47. return -EINVAL;
  48. case 0x0004:
  49. return -EOPNOTSUPP;
  50. default:
  51. return -EIO;
  52. }
  53. }
  54. EXPORT_SYMBOL_GPL(chsc_error_from_response);
  55. struct chsc_ssd_area {
  56. struct chsc_header request;
  57. u16 :10;
  58. u16 ssid:2;
  59. u16 :4;
  60. u16 f_sch; /* first subchannel */
  61. u16 :16;
  62. u16 l_sch; /* last subchannel */
  63. u32 :32;
  64. struct chsc_header response;
  65. u32 :32;
  66. u8 sch_valid : 1;
  67. u8 dev_valid : 1;
  68. u8 st : 3; /* subchannel type */
  69. u8 zeroes : 3;
  70. u8 unit_addr; /* unit address */
  71. u16 devno; /* device number */
  72. u8 path_mask;
  73. u8 fla_valid_mask;
  74. u16 sch; /* subchannel */
  75. u8 chpid[8]; /* chpids 0-7 */
  76. u16 fla[8]; /* full link addresses 0-7 */
  77. } __attribute__ ((packed));
  78. int chsc_get_ssd_info(struct subchannel_id schid, struct chsc_ssd_info *ssd)
  79. {
  80. unsigned long page;
  81. struct chsc_ssd_area *ssd_area;
  82. int ccode;
  83. int ret;
  84. int i;
  85. int mask;
  86. page = get_zeroed_page(GFP_KERNEL | GFP_DMA);
  87. if (!page)
  88. return -ENOMEM;
  89. ssd_area = (struct chsc_ssd_area *) page;
  90. ssd_area->request.length = 0x0010;
  91. ssd_area->request.code = 0x0004;
  92. ssd_area->ssid = schid.ssid;
  93. ssd_area->f_sch = schid.sch_no;
  94. ssd_area->l_sch = schid.sch_no;
  95. ccode = chsc(ssd_area);
  96. /* Check response. */
  97. if (ccode > 0) {
  98. ret = (ccode == 3) ? -ENODEV : -EBUSY;
  99. goto out_free;
  100. }
  101. ret = chsc_error_from_response(ssd_area->response.code);
  102. if (ret != 0) {
  103. CIO_MSG_EVENT(2, "chsc: ssd failed for 0.%x.%04x (rc=%04x)\n",
  104. schid.ssid, schid.sch_no,
  105. ssd_area->response.code);
  106. goto out_free;
  107. }
  108. if (!ssd_area->sch_valid) {
  109. ret = -ENODEV;
  110. goto out_free;
  111. }
  112. /* Copy data */
  113. ret = 0;
  114. memset(ssd, 0, sizeof(struct chsc_ssd_info));
  115. if ((ssd_area->st != SUBCHANNEL_TYPE_IO) &&
  116. (ssd_area->st != SUBCHANNEL_TYPE_MSG))
  117. goto out_free;
  118. ssd->path_mask = ssd_area->path_mask;
  119. ssd->fla_valid_mask = ssd_area->fla_valid_mask;
  120. for (i = 0; i < 8; i++) {
  121. mask = 0x80 >> i;
  122. if (ssd_area->path_mask & mask) {
  123. chp_id_init(&ssd->chpid[i]);
  124. ssd->chpid[i].id = ssd_area->chpid[i];
  125. }
  126. if (ssd_area->fla_valid_mask & mask)
  127. ssd->fla[i] = ssd_area->fla[i];
  128. }
  129. out_free:
  130. free_page(page);
  131. return ret;
  132. }
  133. static int s390_subchannel_remove_chpid(struct subchannel *sch, void *data)
  134. {
  135. spin_lock_irq(sch->lock);
  136. if (sch->driver && sch->driver->chp_event)
  137. if (sch->driver->chp_event(sch, data, CHP_OFFLINE) != 0)
  138. goto out_unreg;
  139. spin_unlock_irq(sch->lock);
  140. return 0;
  141. out_unreg:
  142. sch->lpm = 0;
  143. spin_unlock_irq(sch->lock);
  144. css_schedule_eval(sch->schid);
  145. return 0;
  146. }
  147. void chsc_chp_offline(struct chp_id chpid)
  148. {
  149. char dbf_txt[15];
  150. struct chp_link link;
  151. sprintf(dbf_txt, "chpr%x.%02x", chpid.cssid, chpid.id);
  152. CIO_TRACE_EVENT(2, dbf_txt);
  153. if (chp_get_status(chpid) <= 0)
  154. return;
  155. memset(&link, 0, sizeof(struct chp_link));
  156. link.chpid = chpid;
  157. /* Wait until previous actions have settled. */
  158. css_wait_for_slow_path();
  159. for_each_subchannel_staged(s390_subchannel_remove_chpid, NULL, &link);
  160. }
  161. static int s390_process_res_acc_new_sch(struct subchannel_id schid, void *data)
  162. {
  163. struct schib schib;
  164. /*
  165. * We don't know the device yet, but since a path
  166. * may be available now to the device we'll have
  167. * to do recognition again.
  168. * Since we don't have any idea about which chpid
  169. * that beast may be on we'll have to do a stsch
  170. * on all devices, grr...
  171. */
  172. if (stsch_err(schid, &schib))
  173. /* We're through */
  174. return -ENXIO;
  175. /* Put it on the slow path. */
  176. css_schedule_eval(schid);
  177. return 0;
  178. }
  179. static int __s390_process_res_acc(struct subchannel *sch, void *data)
  180. {
  181. spin_lock_irq(sch->lock);
  182. if (sch->driver && sch->driver->chp_event)
  183. sch->driver->chp_event(sch, data, CHP_ONLINE);
  184. spin_unlock_irq(sch->lock);
  185. return 0;
  186. }
  187. static void s390_process_res_acc(struct chp_link *link)
  188. {
  189. char dbf_txt[15];
  190. sprintf(dbf_txt, "accpr%x.%02x", link->chpid.cssid,
  191. link->chpid.id);
  192. CIO_TRACE_EVENT( 2, dbf_txt);
  193. if (link->fla != 0) {
  194. sprintf(dbf_txt, "fla%x", link->fla);
  195. CIO_TRACE_EVENT( 2, dbf_txt);
  196. }
  197. /* Wait until previous actions have settled. */
  198. css_wait_for_slow_path();
  199. /*
  200. * I/O resources may have become accessible.
  201. * Scan through all subchannels that may be concerned and
  202. * do a validation on those.
  203. * The more information we have (info), the less scanning
  204. * will we have to do.
  205. */
  206. for_each_subchannel_staged(__s390_process_res_acc,
  207. s390_process_res_acc_new_sch, link);
  208. }
  209. static int
  210. __get_chpid_from_lir(void *data)
  211. {
  212. struct lir {
  213. u8 iq;
  214. u8 ic;
  215. u16 sci;
  216. /* incident-node descriptor */
  217. u32 indesc[28];
  218. /* attached-node descriptor */
  219. u32 andesc[28];
  220. /* incident-specific information */
  221. u32 isinfo[28];
  222. } __attribute__ ((packed)) *lir;
  223. lir = data;
  224. if (!(lir->iq&0x80))
  225. /* NULL link incident record */
  226. return -EINVAL;
  227. if (!(lir->indesc[0]&0xc0000000))
  228. /* node descriptor not valid */
  229. return -EINVAL;
  230. if (!(lir->indesc[0]&0x10000000))
  231. /* don't handle device-type nodes - FIXME */
  232. return -EINVAL;
  233. /* Byte 3 contains the chpid. Could also be CTCA, but we don't care */
  234. return (u16) (lir->indesc[0]&0x000000ff);
  235. }
  236. struct chsc_sei_area {
  237. struct chsc_header request;
  238. u32 reserved1;
  239. u32 reserved2;
  240. u32 reserved3;
  241. struct chsc_header response;
  242. u32 reserved4;
  243. u8 flags;
  244. u8 vf; /* validity flags */
  245. u8 rs; /* reporting source */
  246. u8 cc; /* content code */
  247. u16 fla; /* full link address */
  248. u16 rsid; /* reporting source id */
  249. u32 reserved5;
  250. u32 reserved6;
  251. u8 ccdf[4096 - 16 - 24]; /* content-code dependent field */
  252. /* ccdf has to be big enough for a link-incident record */
  253. } __attribute__ ((packed));
  254. static void chsc_process_sei_link_incident(struct chsc_sei_area *sei_area)
  255. {
  256. struct chp_id chpid;
  257. int id;
  258. CIO_CRW_EVENT(4, "chsc: link incident (rs=%02x, rs_id=%04x)\n",
  259. sei_area->rs, sei_area->rsid);
  260. if (sei_area->rs != 4)
  261. return;
  262. id = __get_chpid_from_lir(sei_area->ccdf);
  263. if (id < 0)
  264. CIO_CRW_EVENT(4, "chsc: link incident - invalid LIR\n");
  265. else {
  266. chp_id_init(&chpid);
  267. chpid.id = id;
  268. chsc_chp_offline(chpid);
  269. }
  270. }
  271. static void chsc_process_sei_res_acc(struct chsc_sei_area *sei_area)
  272. {
  273. struct chp_link link;
  274. struct chp_id chpid;
  275. int status;
  276. CIO_CRW_EVENT(4, "chsc: resource accessibility event (rs=%02x, "
  277. "rs_id=%04x)\n", sei_area->rs, sei_area->rsid);
  278. if (sei_area->rs != 4)
  279. return;
  280. chp_id_init(&chpid);
  281. chpid.id = sei_area->rsid;
  282. /* allocate a new channel path structure, if needed */
  283. status = chp_get_status(chpid);
  284. if (status < 0)
  285. chp_new(chpid);
  286. else if (!status)
  287. return;
  288. memset(&link, 0, sizeof(struct chp_link));
  289. link.chpid = chpid;
  290. if ((sei_area->vf & 0xc0) != 0) {
  291. link.fla = sei_area->fla;
  292. if ((sei_area->vf & 0xc0) == 0xc0)
  293. /* full link address */
  294. link.fla_mask = 0xffff;
  295. else
  296. /* link address */
  297. link.fla_mask = 0xff00;
  298. }
  299. s390_process_res_acc(&link);
  300. }
  301. struct chp_config_data {
  302. u8 map[32];
  303. u8 op;
  304. u8 pc;
  305. };
  306. static void chsc_process_sei_chp_config(struct chsc_sei_area *sei_area)
  307. {
  308. struct chp_config_data *data;
  309. struct chp_id chpid;
  310. int num;
  311. char *events[3] = {"configure", "deconfigure", "cancel deconfigure"};
  312. CIO_CRW_EVENT(4, "chsc: channel-path-configuration notification\n");
  313. if (sei_area->rs != 0)
  314. return;
  315. data = (struct chp_config_data *) &(sei_area->ccdf);
  316. chp_id_init(&chpid);
  317. for (num = 0; num <= __MAX_CHPID; num++) {
  318. if (!chp_test_bit(data->map, num))
  319. continue;
  320. chpid.id = num;
  321. pr_notice("Processing %s for channel path %x.%02x\n",
  322. events[data->op], chpid.cssid, chpid.id);
  323. switch (data->op) {
  324. case 0:
  325. chp_cfg_schedule(chpid, 1);
  326. break;
  327. case 1:
  328. chp_cfg_schedule(chpid, 0);
  329. break;
  330. case 2:
  331. chp_cfg_cancel_deconfigure(chpid);
  332. break;
  333. }
  334. }
  335. }
  336. static void chsc_process_sei(struct chsc_sei_area *sei_area)
  337. {
  338. /* Check if we might have lost some information. */
  339. if (sei_area->flags & 0x40) {
  340. CIO_CRW_EVENT(2, "chsc: event overflow\n");
  341. css_schedule_eval_all();
  342. }
  343. /* which kind of information was stored? */
  344. switch (sei_area->cc) {
  345. case 1: /* link incident*/
  346. chsc_process_sei_link_incident(sei_area);
  347. break;
  348. case 2: /* i/o resource accessibiliy */
  349. chsc_process_sei_res_acc(sei_area);
  350. break;
  351. case 8: /* channel-path-configuration notification */
  352. chsc_process_sei_chp_config(sei_area);
  353. break;
  354. default: /* other stuff */
  355. CIO_CRW_EVENT(4, "chsc: unhandled sei content code %d\n",
  356. sei_area->cc);
  357. break;
  358. }
  359. }
  360. static void chsc_process_crw(struct crw *crw0, struct crw *crw1, int overflow)
  361. {
  362. struct chsc_sei_area *sei_area;
  363. if (overflow) {
  364. css_schedule_eval_all();
  365. return;
  366. }
  367. CIO_CRW_EVENT(2, "CRW reports slct=%d, oflw=%d, "
  368. "chn=%d, rsc=%X, anc=%d, erc=%X, rsid=%X\n",
  369. crw0->slct, crw0->oflw, crw0->chn, crw0->rsc, crw0->anc,
  370. crw0->erc, crw0->rsid);
  371. if (!sei_page)
  372. return;
  373. /* Access to sei_page is serialized through machine check handler
  374. * thread, so no need for locking. */
  375. sei_area = sei_page;
  376. CIO_TRACE_EVENT(2, "prcss");
  377. do {
  378. memset(sei_area, 0, sizeof(*sei_area));
  379. sei_area->request.length = 0x0010;
  380. sei_area->request.code = 0x000e;
  381. if (chsc(sei_area))
  382. break;
  383. if (sei_area->response.code == 0x0001) {
  384. CIO_CRW_EVENT(4, "chsc: sei successful\n");
  385. chsc_process_sei(sei_area);
  386. } else {
  387. CIO_CRW_EVENT(2, "chsc: sei failed (rc=%04x)\n",
  388. sei_area->response.code);
  389. break;
  390. }
  391. } while (sei_area->flags & 0x80);
  392. }
  393. void chsc_chp_online(struct chp_id chpid)
  394. {
  395. char dbf_txt[15];
  396. struct chp_link link;
  397. sprintf(dbf_txt, "cadd%x.%02x", chpid.cssid, chpid.id);
  398. CIO_TRACE_EVENT(2, dbf_txt);
  399. if (chp_get_status(chpid) != 0) {
  400. memset(&link, 0, sizeof(struct chp_link));
  401. link.chpid = chpid;
  402. /* Wait until previous actions have settled. */
  403. css_wait_for_slow_path();
  404. for_each_subchannel_staged(__s390_process_res_acc, NULL,
  405. &link);
  406. }
  407. }
  408. static void __s390_subchannel_vary_chpid(struct subchannel *sch,
  409. struct chp_id chpid, int on)
  410. {
  411. unsigned long flags;
  412. struct chp_link link;
  413. memset(&link, 0, sizeof(struct chp_link));
  414. link.chpid = chpid;
  415. spin_lock_irqsave(sch->lock, flags);
  416. if (sch->driver && sch->driver->chp_event)
  417. sch->driver->chp_event(sch, &link,
  418. on ? CHP_VARY_ON : CHP_VARY_OFF);
  419. spin_unlock_irqrestore(sch->lock, flags);
  420. }
  421. static int s390_subchannel_vary_chpid_off(struct subchannel *sch, void *data)
  422. {
  423. struct chp_id *chpid = data;
  424. __s390_subchannel_vary_chpid(sch, *chpid, 0);
  425. return 0;
  426. }
  427. static int s390_subchannel_vary_chpid_on(struct subchannel *sch, void *data)
  428. {
  429. struct chp_id *chpid = data;
  430. __s390_subchannel_vary_chpid(sch, *chpid, 1);
  431. return 0;
  432. }
  433. static int
  434. __s390_vary_chpid_on(struct subchannel_id schid, void *data)
  435. {
  436. struct schib schib;
  437. if (stsch_err(schid, &schib))
  438. /* We're through */
  439. return -ENXIO;
  440. /* Put it on the slow path. */
  441. css_schedule_eval(schid);
  442. return 0;
  443. }
  444. /**
  445. * chsc_chp_vary - propagate channel-path vary operation to subchannels
  446. * @chpid: channl-path ID
  447. * @on: non-zero for vary online, zero for vary offline
  448. */
  449. int chsc_chp_vary(struct chp_id chpid, int on)
  450. {
  451. struct chp_link link;
  452. memset(&link, 0, sizeof(struct chp_link));
  453. link.chpid = chpid;
  454. /* Wait until previous actions have settled. */
  455. css_wait_for_slow_path();
  456. /*
  457. * Redo PathVerification on the devices the chpid connects to
  458. */
  459. if (on)
  460. for_each_subchannel_staged(s390_subchannel_vary_chpid_on,
  461. __s390_vary_chpid_on, &link);
  462. else
  463. for_each_subchannel_staged(s390_subchannel_vary_chpid_off,
  464. NULL, &link);
  465. return 0;
  466. }
  467. static void
  468. chsc_remove_cmg_attr(struct channel_subsystem *css)
  469. {
  470. int i;
  471. for (i = 0; i <= __MAX_CHPID; i++) {
  472. if (!css->chps[i])
  473. continue;
  474. chp_remove_cmg_attr(css->chps[i]);
  475. }
  476. }
  477. static int
  478. chsc_add_cmg_attr(struct channel_subsystem *css)
  479. {
  480. int i, ret;
  481. ret = 0;
  482. for (i = 0; i <= __MAX_CHPID; i++) {
  483. if (!css->chps[i])
  484. continue;
  485. ret = chp_add_cmg_attr(css->chps[i]);
  486. if (ret)
  487. goto cleanup;
  488. }
  489. return ret;
  490. cleanup:
  491. for (--i; i >= 0; i--) {
  492. if (!css->chps[i])
  493. continue;
  494. chp_remove_cmg_attr(css->chps[i]);
  495. }
  496. return ret;
  497. }
  498. int __chsc_do_secm(struct channel_subsystem *css, int enable, void *page)
  499. {
  500. struct {
  501. struct chsc_header request;
  502. u32 operation_code : 2;
  503. u32 : 30;
  504. u32 key : 4;
  505. u32 : 28;
  506. u32 zeroes1;
  507. u32 cub_addr1;
  508. u32 zeroes2;
  509. u32 cub_addr2;
  510. u32 reserved[13];
  511. struct chsc_header response;
  512. u32 status : 8;
  513. u32 : 4;
  514. u32 fmt : 4;
  515. u32 : 16;
  516. } __attribute__ ((packed)) *secm_area;
  517. int ret, ccode;
  518. secm_area = page;
  519. secm_area->request.length = 0x0050;
  520. secm_area->request.code = 0x0016;
  521. secm_area->key = PAGE_DEFAULT_KEY >> 4;
  522. secm_area->cub_addr1 = (u64)(unsigned long)css->cub_addr1;
  523. secm_area->cub_addr2 = (u64)(unsigned long)css->cub_addr2;
  524. secm_area->operation_code = enable ? 0 : 1;
  525. ccode = chsc(secm_area);
  526. if (ccode > 0)
  527. return (ccode == 3) ? -ENODEV : -EBUSY;
  528. switch (secm_area->response.code) {
  529. case 0x0102:
  530. case 0x0103:
  531. ret = -EINVAL;
  532. break;
  533. default:
  534. ret = chsc_error_from_response(secm_area->response.code);
  535. }
  536. if (ret != 0)
  537. CIO_CRW_EVENT(2, "chsc: secm failed (rc=%04x)\n",
  538. secm_area->response.code);
  539. return ret;
  540. }
  541. int
  542. chsc_secm(struct channel_subsystem *css, int enable)
  543. {
  544. void *secm_area;
  545. int ret;
  546. secm_area = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
  547. if (!secm_area)
  548. return -ENOMEM;
  549. if (enable && !css->cm_enabled) {
  550. css->cub_addr1 = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
  551. css->cub_addr2 = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
  552. if (!css->cub_addr1 || !css->cub_addr2) {
  553. free_page((unsigned long)css->cub_addr1);
  554. free_page((unsigned long)css->cub_addr2);
  555. free_page((unsigned long)secm_area);
  556. return -ENOMEM;
  557. }
  558. }
  559. ret = __chsc_do_secm(css, enable, secm_area);
  560. if (!ret) {
  561. css->cm_enabled = enable;
  562. if (css->cm_enabled) {
  563. ret = chsc_add_cmg_attr(css);
  564. if (ret) {
  565. memset(secm_area, 0, PAGE_SIZE);
  566. __chsc_do_secm(css, 0, secm_area);
  567. css->cm_enabled = 0;
  568. }
  569. } else
  570. chsc_remove_cmg_attr(css);
  571. }
  572. if (!css->cm_enabled) {
  573. free_page((unsigned long)css->cub_addr1);
  574. free_page((unsigned long)css->cub_addr2);
  575. }
  576. free_page((unsigned long)secm_area);
  577. return ret;
  578. }
  579. int chsc_determine_channel_path_desc(struct chp_id chpid, int fmt, int rfmt,
  580. int c, int m,
  581. struct chsc_response_struct *resp)
  582. {
  583. int ccode, ret;
  584. struct {
  585. struct chsc_header request;
  586. u32 : 2;
  587. u32 m : 1;
  588. u32 c : 1;
  589. u32 fmt : 4;
  590. u32 cssid : 8;
  591. u32 : 4;
  592. u32 rfmt : 4;
  593. u32 first_chpid : 8;
  594. u32 : 24;
  595. u32 last_chpid : 8;
  596. u32 zeroes1;
  597. struct chsc_header response;
  598. u8 data[PAGE_SIZE - 20];
  599. } __attribute__ ((packed)) *scpd_area;
  600. if ((rfmt == 1) && !css_general_characteristics.fcs)
  601. return -EINVAL;
  602. if ((rfmt == 2) && !css_general_characteristics.cib)
  603. return -EINVAL;
  604. scpd_area = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
  605. if (!scpd_area)
  606. return -ENOMEM;
  607. scpd_area->request.length = 0x0010;
  608. scpd_area->request.code = 0x0002;
  609. scpd_area->cssid = chpid.cssid;
  610. scpd_area->first_chpid = chpid.id;
  611. scpd_area->last_chpid = chpid.id;
  612. scpd_area->m = m;
  613. scpd_area->c = c;
  614. scpd_area->fmt = fmt;
  615. scpd_area->rfmt = rfmt;
  616. ccode = chsc(scpd_area);
  617. if (ccode > 0) {
  618. ret = (ccode == 3) ? -ENODEV : -EBUSY;
  619. goto out;
  620. }
  621. ret = chsc_error_from_response(scpd_area->response.code);
  622. if (ret == 0)
  623. /* Success. */
  624. memcpy(resp, &scpd_area->response, scpd_area->response.length);
  625. else
  626. CIO_CRW_EVENT(2, "chsc: scpd failed (rc=%04x)\n",
  627. scpd_area->response.code);
  628. out:
  629. free_page((unsigned long)scpd_area);
  630. return ret;
  631. }
  632. EXPORT_SYMBOL_GPL(chsc_determine_channel_path_desc);
  633. int chsc_determine_base_channel_path_desc(struct chp_id chpid,
  634. struct channel_path_desc *desc)
  635. {
  636. struct chsc_response_struct *chsc_resp;
  637. int ret;
  638. chsc_resp = kzalloc(sizeof(*chsc_resp), GFP_KERNEL);
  639. if (!chsc_resp)
  640. return -ENOMEM;
  641. ret = chsc_determine_channel_path_desc(chpid, 0, 0, 0, 0, chsc_resp);
  642. if (ret)
  643. goto out_free;
  644. memcpy(desc, &chsc_resp->data, sizeof(*desc));
  645. out_free:
  646. kfree(chsc_resp);
  647. return ret;
  648. }
  649. static void
  650. chsc_initialize_cmg_chars(struct channel_path *chp, u8 cmcv,
  651. struct cmg_chars *chars)
  652. {
  653. switch (chp->cmg) {
  654. case 2:
  655. case 3:
  656. chp->cmg_chars = kmalloc(sizeof(struct cmg_chars),
  657. GFP_KERNEL);
  658. if (chp->cmg_chars) {
  659. int i, mask;
  660. struct cmg_chars *cmg_chars;
  661. cmg_chars = chp->cmg_chars;
  662. for (i = 0; i < NR_MEASUREMENT_CHARS; i++) {
  663. mask = 0x80 >> (i + 3);
  664. if (cmcv & mask)
  665. cmg_chars->values[i] = chars->values[i];
  666. else
  667. cmg_chars->values[i] = 0;
  668. }
  669. }
  670. break;
  671. default:
  672. /* No cmg-dependent data. */
  673. break;
  674. }
  675. }
  676. int chsc_get_channel_measurement_chars(struct channel_path *chp)
  677. {
  678. int ccode, ret;
  679. struct {
  680. struct chsc_header request;
  681. u32 : 24;
  682. u32 first_chpid : 8;
  683. u32 : 24;
  684. u32 last_chpid : 8;
  685. u32 zeroes1;
  686. struct chsc_header response;
  687. u32 zeroes2;
  688. u32 not_valid : 1;
  689. u32 shared : 1;
  690. u32 : 22;
  691. u32 chpid : 8;
  692. u32 cmcv : 5;
  693. u32 : 11;
  694. u32 cmgq : 8;
  695. u32 cmg : 8;
  696. u32 zeroes3;
  697. u32 data[NR_MEASUREMENT_CHARS];
  698. } __attribute__ ((packed)) *scmc_area;
  699. scmc_area = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
  700. if (!scmc_area)
  701. return -ENOMEM;
  702. scmc_area->request.length = 0x0010;
  703. scmc_area->request.code = 0x0022;
  704. scmc_area->first_chpid = chp->chpid.id;
  705. scmc_area->last_chpid = chp->chpid.id;
  706. ccode = chsc(scmc_area);
  707. if (ccode > 0) {
  708. ret = (ccode == 3) ? -ENODEV : -EBUSY;
  709. goto out;
  710. }
  711. ret = chsc_error_from_response(scmc_area->response.code);
  712. if (ret == 0) {
  713. /* Success. */
  714. if (!scmc_area->not_valid) {
  715. chp->cmg = scmc_area->cmg;
  716. chp->shared = scmc_area->shared;
  717. chsc_initialize_cmg_chars(chp, scmc_area->cmcv,
  718. (struct cmg_chars *)
  719. &scmc_area->data);
  720. } else {
  721. chp->cmg = -1;
  722. chp->shared = -1;
  723. }
  724. } else {
  725. CIO_CRW_EVENT(2, "chsc: scmc failed (rc=%04x)\n",
  726. scmc_area->response.code);
  727. }
  728. out:
  729. free_page((unsigned long)scmc_area);
  730. return ret;
  731. }
  732. int __init chsc_alloc_sei_area(void)
  733. {
  734. int ret;
  735. sei_page = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
  736. if (!sei_page) {
  737. CIO_MSG_EVENT(0, "Can't allocate page for processing of "
  738. "chsc machine checks!\n");
  739. return -ENOMEM;
  740. }
  741. ret = crw_register_handler(CRW_RSC_CSS, chsc_process_crw);
  742. if (ret)
  743. kfree(sei_page);
  744. return ret;
  745. }
  746. void __init chsc_free_sei_area(void)
  747. {
  748. crw_unregister_handler(CRW_RSC_CSS);
  749. kfree(sei_page);
  750. }
  751. int chsc_enable_facility(int operation_code)
  752. {
  753. int ret;
  754. static struct {
  755. struct chsc_header request;
  756. u8 reserved1:4;
  757. u8 format:4;
  758. u8 reserved2;
  759. u16 operation_code;
  760. u32 reserved3;
  761. u32 reserved4;
  762. u32 operation_data_area[252];
  763. struct chsc_header response;
  764. u32 reserved5:4;
  765. u32 format2:4;
  766. u32 reserved6:24;
  767. } __attribute__ ((packed, aligned(4096))) sda_area;
  768. spin_lock(&sda_lock);
  769. memset(&sda_area, 0, sizeof(sda_area));
  770. sda_area.request.length = 0x0400;
  771. sda_area.request.code = 0x0031;
  772. sda_area.operation_code = operation_code;
  773. ret = chsc(&sda_area);
  774. if (ret > 0) {
  775. ret = (ret == 3) ? -ENODEV : -EBUSY;
  776. goto out;
  777. }
  778. switch (sda_area.response.code) {
  779. case 0x0101:
  780. ret = -EOPNOTSUPP;
  781. break;
  782. default:
  783. ret = chsc_error_from_response(sda_area.response.code);
  784. }
  785. if (ret != 0)
  786. CIO_CRW_EVENT(2, "chsc: sda (oc=%x) failed (rc=%04x)\n",
  787. operation_code, sda_area.response.code);
  788. out:
  789. spin_unlock(&sda_lock);
  790. return ret;
  791. }
  792. struct css_general_char css_general_characteristics;
  793. struct css_chsc_char css_chsc_characteristics;
  794. int __init
  795. chsc_determine_css_characteristics(void)
  796. {
  797. int result;
  798. struct {
  799. struct chsc_header request;
  800. u32 reserved1;
  801. u32 reserved2;
  802. u32 reserved3;
  803. struct chsc_header response;
  804. u32 reserved4;
  805. u32 general_char[510];
  806. u32 chsc_char[518];
  807. } __attribute__ ((packed)) *scsc_area;
  808. scsc_area = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
  809. if (!scsc_area)
  810. return -ENOMEM;
  811. scsc_area->request.length = 0x0010;
  812. scsc_area->request.code = 0x0010;
  813. result = chsc(scsc_area);
  814. if (result) {
  815. result = (result == 3) ? -ENODEV : -EBUSY;
  816. goto exit;
  817. }
  818. result = chsc_error_from_response(scsc_area->response.code);
  819. if (result == 0) {
  820. memcpy(&css_general_characteristics, scsc_area->general_char,
  821. sizeof(css_general_characteristics));
  822. memcpy(&css_chsc_characteristics, scsc_area->chsc_char,
  823. sizeof(css_chsc_characteristics));
  824. } else
  825. CIO_CRW_EVENT(2, "chsc: scsc failed (rc=%04x)\n",
  826. scsc_area->response.code);
  827. exit:
  828. free_page ((unsigned long) scsc_area);
  829. return result;
  830. }
  831. EXPORT_SYMBOL_GPL(css_general_characteristics);
  832. EXPORT_SYMBOL_GPL(css_chsc_characteristics);
  833. int chsc_sstpc(void *page, unsigned int op, u16 ctrl)
  834. {
  835. struct {
  836. struct chsc_header request;
  837. unsigned int rsvd0;
  838. unsigned int op : 8;
  839. unsigned int rsvd1 : 8;
  840. unsigned int ctrl : 16;
  841. unsigned int rsvd2[5];
  842. struct chsc_header response;
  843. unsigned int rsvd3[7];
  844. } __attribute__ ((packed)) *rr;
  845. int rc;
  846. memset(page, 0, PAGE_SIZE);
  847. rr = page;
  848. rr->request.length = 0x0020;
  849. rr->request.code = 0x0033;
  850. rr->op = op;
  851. rr->ctrl = ctrl;
  852. rc = chsc(rr);
  853. if (rc)
  854. return -EIO;
  855. rc = (rr->response.code == 0x0001) ? 0 : -EIO;
  856. return rc;
  857. }
  858. int chsc_sstpi(void *page, void *result, size_t size)
  859. {
  860. struct {
  861. struct chsc_header request;
  862. unsigned int rsvd0[3];
  863. struct chsc_header response;
  864. char data[size];
  865. } __attribute__ ((packed)) *rr;
  866. int rc;
  867. memset(page, 0, PAGE_SIZE);
  868. rr = page;
  869. rr->request.length = 0x0010;
  870. rr->request.code = 0x0038;
  871. rc = chsc(rr);
  872. if (rc)
  873. return -EIO;
  874. memcpy(result, &rr->data, size);
  875. return (rr->response.code == 0x0001) ? 0 : -EIO;
  876. }
  877. static struct {
  878. struct chsc_header request;
  879. u32 word1;
  880. struct subchannel_id sid;
  881. u32 word3;
  882. struct chsc_header response;
  883. u32 word[11];
  884. } __attribute__ ((packed)) siosl_area __attribute__ ((__aligned__(PAGE_SIZE)));
  885. int chsc_siosl(struct subchannel_id schid)
  886. {
  887. unsigned long flags;
  888. int ccode;
  889. int rc;
  890. spin_lock_irqsave(&siosl_lock, flags);
  891. memset(&siosl_area, 0, sizeof(siosl_area));
  892. siosl_area.request.length = 0x0010;
  893. siosl_area.request.code = 0x0046;
  894. siosl_area.word1 = 0x80000000;
  895. siosl_area.sid = schid;
  896. ccode = chsc(&siosl_area);
  897. if (ccode > 0) {
  898. if (ccode == 3)
  899. rc = -ENODEV;
  900. else
  901. rc = -EBUSY;
  902. CIO_MSG_EVENT(2, "chsc: chsc failed for 0.%x.%04x (ccode=%d)\n",
  903. schid.ssid, schid.sch_no, ccode);
  904. goto out;
  905. }
  906. rc = chsc_error_from_response(siosl_area.response.code);
  907. if (rc)
  908. CIO_MSG_EVENT(2, "chsc: siosl failed for 0.%x.%04x (rc=%04x)\n",
  909. schid.ssid, schid.sch_no,
  910. siosl_area.response.code);
  911. else
  912. CIO_MSG_EVENT(4, "chsc: siosl succeeded for 0.%x.%04x\n",
  913. schid.ssid, schid.sch_no);
  914. out:
  915. spin_unlock_irqrestore(&siosl_lock, flags);
  916. return rc;
  917. }
  918. EXPORT_SYMBOL_GPL(chsc_siosl);