chsc.c 24 KB

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