chsc.c 21 KB

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