chsc.c 21 KB

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