chsc.c 22 KB

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