chsc.c 22 KB

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