chsc.c 22 KB

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