chsc.c 22 KB

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