chsc.c 26 KB

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