chsc.c 26 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162
  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. #ifdef CONFIG_PCI
  397. switch (sei_area->cc) {
  398. case 1:
  399. zpci_event_error(sei_area->ccdf);
  400. break;
  401. case 2:
  402. zpci_event_availability(sei_area->ccdf);
  403. break;
  404. default:
  405. CIO_CRW_EVENT(2, "chsc: unhandled sei content code %d\n",
  406. sei_area->cc);
  407. break;
  408. }
  409. #endif
  410. }
  411. static void chsc_process_sei_nt0(struct chsc_sei_nt0_area *sei_area)
  412. {
  413. /* which kind of information was stored? */
  414. switch (sei_area->cc) {
  415. case 1: /* link incident*/
  416. chsc_process_sei_link_incident(sei_area);
  417. break;
  418. case 2: /* i/o resource accessibility */
  419. chsc_process_sei_res_acc(sei_area);
  420. break;
  421. case 7: /* channel-path-availability information */
  422. chsc_process_sei_chp_avail(sei_area);
  423. break;
  424. case 8: /* channel-path-configuration notification */
  425. chsc_process_sei_chp_config(sei_area);
  426. break;
  427. case 12: /* scm change notification */
  428. chsc_process_sei_scm_change(sei_area);
  429. break;
  430. default: /* other stuff */
  431. CIO_CRW_EVENT(4, "chsc: unhandled sei content code %d\n",
  432. sei_area->cc);
  433. break;
  434. }
  435. }
  436. static int __chsc_process_crw(struct chsc_sei *sei, u64 ntsm)
  437. {
  438. do {
  439. memset(sei, 0, sizeof(*sei));
  440. sei->request.length = 0x0010;
  441. sei->request.code = 0x000e;
  442. sei->ntsm = ntsm;
  443. if (chsc(sei))
  444. break;
  445. if (sei->response.code == 0x0001) {
  446. CIO_CRW_EVENT(2, "chsc: sei successful\n");
  447. /* Check if we might have lost some information. */
  448. if (sei->u.nt0_area.flags & 0x40) {
  449. CIO_CRW_EVENT(2, "chsc: event overflow\n");
  450. css_schedule_eval_all();
  451. }
  452. switch (sei->nt) {
  453. case 0:
  454. chsc_process_sei_nt0(&sei->u.nt0_area);
  455. break;
  456. case 2:
  457. chsc_process_sei_nt2(&sei->u.nt2_area);
  458. break;
  459. default:
  460. CIO_CRW_EVENT(2, "chsc: unhandled nt=%d\n",
  461. sei->nt);
  462. break;
  463. }
  464. } else {
  465. CIO_CRW_EVENT(2, "chsc: sei failed (rc=%04x)\n",
  466. sei->response.code);
  467. break;
  468. }
  469. } while (sei->u.nt0_area.flags & 0x80);
  470. return 0;
  471. }
  472. static void chsc_process_crw(struct crw *crw0, struct crw *crw1, int overflow)
  473. {
  474. struct chsc_sei *sei;
  475. if (overflow) {
  476. css_schedule_eval_all();
  477. return;
  478. }
  479. CIO_CRW_EVENT(2, "CRW reports slct=%d, oflw=%d, "
  480. "chn=%d, rsc=%X, anc=%d, erc=%X, rsid=%X\n",
  481. crw0->slct, crw0->oflw, crw0->chn, crw0->rsc, crw0->anc,
  482. crw0->erc, crw0->rsid);
  483. if (!sei_page)
  484. return;
  485. /* Access to sei_page is serialized through machine check handler
  486. * thread, so no need for locking. */
  487. sei = sei_page;
  488. CIO_TRACE_EVENT(2, "prcss");
  489. __chsc_process_crw(sei, CHSC_SEI_NT0 | CHSC_SEI_NT2);
  490. }
  491. void chsc_chp_online(struct chp_id chpid)
  492. {
  493. char dbf_txt[15];
  494. struct chp_link link;
  495. sprintf(dbf_txt, "cadd%x.%02x", chpid.cssid, chpid.id);
  496. CIO_TRACE_EVENT(2, dbf_txt);
  497. if (chp_get_status(chpid) != 0) {
  498. memset(&link, 0, sizeof(struct chp_link));
  499. link.chpid = chpid;
  500. /* Wait until previous actions have settled. */
  501. css_wait_for_slow_path();
  502. for_each_subchannel_staged(__s390_process_res_acc, NULL,
  503. &link);
  504. }
  505. }
  506. static void __s390_subchannel_vary_chpid(struct subchannel *sch,
  507. struct chp_id chpid, int on)
  508. {
  509. unsigned long flags;
  510. struct chp_link link;
  511. memset(&link, 0, sizeof(struct chp_link));
  512. link.chpid = chpid;
  513. spin_lock_irqsave(sch->lock, flags);
  514. if (sch->driver && sch->driver->chp_event)
  515. sch->driver->chp_event(sch, &link,
  516. on ? CHP_VARY_ON : CHP_VARY_OFF);
  517. spin_unlock_irqrestore(sch->lock, flags);
  518. }
  519. static int s390_subchannel_vary_chpid_off(struct subchannel *sch, void *data)
  520. {
  521. struct chp_id *chpid = data;
  522. __s390_subchannel_vary_chpid(sch, *chpid, 0);
  523. return 0;
  524. }
  525. static int s390_subchannel_vary_chpid_on(struct subchannel *sch, void *data)
  526. {
  527. struct chp_id *chpid = data;
  528. __s390_subchannel_vary_chpid(sch, *chpid, 1);
  529. return 0;
  530. }
  531. static int
  532. __s390_vary_chpid_on(struct subchannel_id schid, void *data)
  533. {
  534. struct schib schib;
  535. if (stsch_err(schid, &schib))
  536. /* We're through */
  537. return -ENXIO;
  538. /* Put it on the slow path. */
  539. css_schedule_eval(schid);
  540. return 0;
  541. }
  542. /**
  543. * chsc_chp_vary - propagate channel-path vary operation to subchannels
  544. * @chpid: channl-path ID
  545. * @on: non-zero for vary online, zero for vary offline
  546. */
  547. int chsc_chp_vary(struct chp_id chpid, int on)
  548. {
  549. struct channel_path *chp = chpid_to_chp(chpid);
  550. /* Wait until previous actions have settled. */
  551. css_wait_for_slow_path();
  552. /*
  553. * Redo PathVerification on the devices the chpid connects to
  554. */
  555. if (on) {
  556. /* Try to update the channel path descritor. */
  557. chsc_determine_base_channel_path_desc(chpid, &chp->desc);
  558. for_each_subchannel_staged(s390_subchannel_vary_chpid_on,
  559. __s390_vary_chpid_on, &chpid);
  560. } else
  561. for_each_subchannel_staged(s390_subchannel_vary_chpid_off,
  562. NULL, &chpid);
  563. return 0;
  564. }
  565. static void
  566. chsc_remove_cmg_attr(struct channel_subsystem *css)
  567. {
  568. int i;
  569. for (i = 0; i <= __MAX_CHPID; i++) {
  570. if (!css->chps[i])
  571. continue;
  572. chp_remove_cmg_attr(css->chps[i]);
  573. }
  574. }
  575. static int
  576. chsc_add_cmg_attr(struct channel_subsystem *css)
  577. {
  578. int i, ret;
  579. ret = 0;
  580. for (i = 0; i <= __MAX_CHPID; i++) {
  581. if (!css->chps[i])
  582. continue;
  583. ret = chp_add_cmg_attr(css->chps[i]);
  584. if (ret)
  585. goto cleanup;
  586. }
  587. return ret;
  588. cleanup:
  589. for (--i; i >= 0; i--) {
  590. if (!css->chps[i])
  591. continue;
  592. chp_remove_cmg_attr(css->chps[i]);
  593. }
  594. return ret;
  595. }
  596. int __chsc_do_secm(struct channel_subsystem *css, int enable)
  597. {
  598. struct {
  599. struct chsc_header request;
  600. u32 operation_code : 2;
  601. u32 : 30;
  602. u32 key : 4;
  603. u32 : 28;
  604. u32 zeroes1;
  605. u32 cub_addr1;
  606. u32 zeroes2;
  607. u32 cub_addr2;
  608. u32 reserved[13];
  609. struct chsc_header response;
  610. u32 status : 8;
  611. u32 : 4;
  612. u32 fmt : 4;
  613. u32 : 16;
  614. } __attribute__ ((packed)) *secm_area;
  615. int ret, ccode;
  616. spin_lock_irq(&chsc_page_lock);
  617. memset(chsc_page, 0, PAGE_SIZE);
  618. secm_area = chsc_page;
  619. secm_area->request.length = 0x0050;
  620. secm_area->request.code = 0x0016;
  621. secm_area->key = PAGE_DEFAULT_KEY >> 4;
  622. secm_area->cub_addr1 = (u64)(unsigned long)css->cub_addr1;
  623. secm_area->cub_addr2 = (u64)(unsigned long)css->cub_addr2;
  624. secm_area->operation_code = enable ? 0 : 1;
  625. ccode = chsc(secm_area);
  626. if (ccode > 0) {
  627. ret = (ccode == 3) ? -ENODEV : -EBUSY;
  628. goto out;
  629. }
  630. switch (secm_area->response.code) {
  631. case 0x0102:
  632. case 0x0103:
  633. ret = -EINVAL;
  634. break;
  635. default:
  636. ret = chsc_error_from_response(secm_area->response.code);
  637. }
  638. if (ret != 0)
  639. CIO_CRW_EVENT(2, "chsc: secm failed (rc=%04x)\n",
  640. secm_area->response.code);
  641. out:
  642. spin_unlock_irq(&chsc_page_lock);
  643. return ret;
  644. }
  645. int
  646. chsc_secm(struct channel_subsystem *css, int enable)
  647. {
  648. int ret;
  649. if (enable && !css->cm_enabled) {
  650. css->cub_addr1 = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
  651. css->cub_addr2 = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
  652. if (!css->cub_addr1 || !css->cub_addr2) {
  653. free_page((unsigned long)css->cub_addr1);
  654. free_page((unsigned long)css->cub_addr2);
  655. return -ENOMEM;
  656. }
  657. }
  658. ret = __chsc_do_secm(css, enable);
  659. if (!ret) {
  660. css->cm_enabled = enable;
  661. if (css->cm_enabled) {
  662. ret = chsc_add_cmg_attr(css);
  663. if (ret) {
  664. __chsc_do_secm(css, 0);
  665. css->cm_enabled = 0;
  666. }
  667. } else
  668. chsc_remove_cmg_attr(css);
  669. }
  670. if (!css->cm_enabled) {
  671. free_page((unsigned long)css->cub_addr1);
  672. free_page((unsigned long)css->cub_addr2);
  673. }
  674. return ret;
  675. }
  676. int chsc_determine_channel_path_desc(struct chp_id chpid, int fmt, int rfmt,
  677. int c, int m, void *page)
  678. {
  679. struct chsc_scpd *scpd_area;
  680. int ccode, ret;
  681. if ((rfmt == 1) && !css_general_characteristics.fcs)
  682. return -EINVAL;
  683. if ((rfmt == 2) && !css_general_characteristics.cib)
  684. return -EINVAL;
  685. memset(page, 0, PAGE_SIZE);
  686. scpd_area = page;
  687. scpd_area->request.length = 0x0010;
  688. scpd_area->request.code = 0x0002;
  689. scpd_area->cssid = chpid.cssid;
  690. scpd_area->first_chpid = chpid.id;
  691. scpd_area->last_chpid = chpid.id;
  692. scpd_area->m = m;
  693. scpd_area->c = c;
  694. scpd_area->fmt = fmt;
  695. scpd_area->rfmt = rfmt;
  696. ccode = chsc(scpd_area);
  697. if (ccode > 0)
  698. return (ccode == 3) ? -ENODEV : -EBUSY;
  699. ret = chsc_error_from_response(scpd_area->response.code);
  700. if (ret)
  701. CIO_CRW_EVENT(2, "chsc: scpd failed (rc=%04x)\n",
  702. scpd_area->response.code);
  703. return ret;
  704. }
  705. EXPORT_SYMBOL_GPL(chsc_determine_channel_path_desc);
  706. int chsc_determine_base_channel_path_desc(struct chp_id chpid,
  707. struct channel_path_desc *desc)
  708. {
  709. struct chsc_response_struct *chsc_resp;
  710. struct chsc_scpd *scpd_area;
  711. unsigned long flags;
  712. int ret;
  713. spin_lock_irqsave(&chsc_page_lock, flags);
  714. scpd_area = chsc_page;
  715. ret = chsc_determine_channel_path_desc(chpid, 0, 0, 0, 0, scpd_area);
  716. if (ret)
  717. goto out;
  718. chsc_resp = (void *)&scpd_area->response;
  719. memcpy(desc, &chsc_resp->data, sizeof(*desc));
  720. out:
  721. spin_unlock_irqrestore(&chsc_page_lock, flags);
  722. return ret;
  723. }
  724. int chsc_determine_fmt1_channel_path_desc(struct chp_id chpid,
  725. struct channel_path_desc_fmt1 *desc)
  726. {
  727. struct chsc_response_struct *chsc_resp;
  728. struct chsc_scpd *scpd_area;
  729. int ret;
  730. spin_lock_irq(&chsc_page_lock);
  731. scpd_area = chsc_page;
  732. ret = chsc_determine_channel_path_desc(chpid, 0, 0, 1, 0, scpd_area);
  733. if (ret)
  734. goto out;
  735. chsc_resp = (void *)&scpd_area->response;
  736. memcpy(desc, &chsc_resp->data, sizeof(*desc));
  737. out:
  738. spin_unlock_irq(&chsc_page_lock);
  739. return ret;
  740. }
  741. static void
  742. chsc_initialize_cmg_chars(struct channel_path *chp, u8 cmcv,
  743. struct cmg_chars *chars)
  744. {
  745. struct cmg_chars *cmg_chars;
  746. int i, mask;
  747. cmg_chars = chp->cmg_chars;
  748. for (i = 0; i < NR_MEASUREMENT_CHARS; i++) {
  749. mask = 0x80 >> (i + 3);
  750. if (cmcv & mask)
  751. cmg_chars->values[i] = chars->values[i];
  752. else
  753. cmg_chars->values[i] = 0;
  754. }
  755. }
  756. int chsc_get_channel_measurement_chars(struct channel_path *chp)
  757. {
  758. struct cmg_chars *cmg_chars;
  759. int ccode, ret;
  760. struct {
  761. struct chsc_header request;
  762. u32 : 24;
  763. u32 first_chpid : 8;
  764. u32 : 24;
  765. u32 last_chpid : 8;
  766. u32 zeroes1;
  767. struct chsc_header response;
  768. u32 zeroes2;
  769. u32 not_valid : 1;
  770. u32 shared : 1;
  771. u32 : 22;
  772. u32 chpid : 8;
  773. u32 cmcv : 5;
  774. u32 : 11;
  775. u32 cmgq : 8;
  776. u32 cmg : 8;
  777. u32 zeroes3;
  778. u32 data[NR_MEASUREMENT_CHARS];
  779. } __attribute__ ((packed)) *scmc_area;
  780. chp->cmg_chars = NULL;
  781. cmg_chars = kmalloc(sizeof(*cmg_chars), GFP_KERNEL);
  782. if (!cmg_chars)
  783. return -ENOMEM;
  784. spin_lock_irq(&chsc_page_lock);
  785. memset(chsc_page, 0, PAGE_SIZE);
  786. scmc_area = chsc_page;
  787. scmc_area->request.length = 0x0010;
  788. scmc_area->request.code = 0x0022;
  789. scmc_area->first_chpid = chp->chpid.id;
  790. scmc_area->last_chpid = chp->chpid.id;
  791. ccode = chsc(scmc_area);
  792. if (ccode > 0) {
  793. ret = (ccode == 3) ? -ENODEV : -EBUSY;
  794. goto out;
  795. }
  796. ret = chsc_error_from_response(scmc_area->response.code);
  797. if (ret) {
  798. CIO_CRW_EVENT(2, "chsc: scmc failed (rc=%04x)\n",
  799. scmc_area->response.code);
  800. goto out;
  801. }
  802. if (scmc_area->not_valid) {
  803. chp->cmg = -1;
  804. chp->shared = -1;
  805. goto out;
  806. }
  807. chp->cmg = scmc_area->cmg;
  808. chp->shared = scmc_area->shared;
  809. if (chp->cmg != 2 && chp->cmg != 3) {
  810. /* No cmg-dependent data. */
  811. goto out;
  812. }
  813. chp->cmg_chars = cmg_chars;
  814. chsc_initialize_cmg_chars(chp, scmc_area->cmcv,
  815. (struct cmg_chars *) &scmc_area->data);
  816. out:
  817. spin_unlock_irq(&chsc_page_lock);
  818. if (!chp->cmg_chars)
  819. kfree(cmg_chars);
  820. return ret;
  821. }
  822. int __init chsc_init(void)
  823. {
  824. int ret;
  825. sei_page = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
  826. chsc_page = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
  827. if (!sei_page || !chsc_page) {
  828. ret = -ENOMEM;
  829. goto out_err;
  830. }
  831. ret = crw_register_handler(CRW_RSC_CSS, chsc_process_crw);
  832. if (ret)
  833. goto out_err;
  834. return ret;
  835. out_err:
  836. free_page((unsigned long)chsc_page);
  837. free_page((unsigned long)sei_page);
  838. return ret;
  839. }
  840. void __init chsc_init_cleanup(void)
  841. {
  842. crw_unregister_handler(CRW_RSC_CSS);
  843. free_page((unsigned long)chsc_page);
  844. free_page((unsigned long)sei_page);
  845. }
  846. int chsc_enable_facility(int operation_code)
  847. {
  848. unsigned long flags;
  849. int ret;
  850. struct {
  851. struct chsc_header request;
  852. u8 reserved1:4;
  853. u8 format:4;
  854. u8 reserved2;
  855. u16 operation_code;
  856. u32 reserved3;
  857. u32 reserved4;
  858. u32 operation_data_area[252];
  859. struct chsc_header response;
  860. u32 reserved5:4;
  861. u32 format2:4;
  862. u32 reserved6:24;
  863. } __attribute__ ((packed)) *sda_area;
  864. spin_lock_irqsave(&chsc_page_lock, flags);
  865. memset(chsc_page, 0, PAGE_SIZE);
  866. sda_area = chsc_page;
  867. sda_area->request.length = 0x0400;
  868. sda_area->request.code = 0x0031;
  869. sda_area->operation_code = operation_code;
  870. ret = chsc(sda_area);
  871. if (ret > 0) {
  872. ret = (ret == 3) ? -ENODEV : -EBUSY;
  873. goto out;
  874. }
  875. switch (sda_area->response.code) {
  876. case 0x0101:
  877. ret = -EOPNOTSUPP;
  878. break;
  879. default:
  880. ret = chsc_error_from_response(sda_area->response.code);
  881. }
  882. if (ret != 0)
  883. CIO_CRW_EVENT(2, "chsc: sda (oc=%x) failed (rc=%04x)\n",
  884. operation_code, sda_area->response.code);
  885. out:
  886. spin_unlock_irqrestore(&chsc_page_lock, flags);
  887. return ret;
  888. }
  889. struct css_general_char css_general_characteristics;
  890. struct css_chsc_char css_chsc_characteristics;
  891. int __init
  892. chsc_determine_css_characteristics(void)
  893. {
  894. int result;
  895. struct {
  896. struct chsc_header request;
  897. u32 reserved1;
  898. u32 reserved2;
  899. u32 reserved3;
  900. struct chsc_header response;
  901. u32 reserved4;
  902. u32 general_char[510];
  903. u32 chsc_char[508];
  904. } __attribute__ ((packed)) *scsc_area;
  905. spin_lock_irq(&chsc_page_lock);
  906. memset(chsc_page, 0, PAGE_SIZE);
  907. scsc_area = chsc_page;
  908. scsc_area->request.length = 0x0010;
  909. scsc_area->request.code = 0x0010;
  910. result = chsc(scsc_area);
  911. if (result) {
  912. result = (result == 3) ? -ENODEV : -EBUSY;
  913. goto exit;
  914. }
  915. result = chsc_error_from_response(scsc_area->response.code);
  916. if (result == 0) {
  917. memcpy(&css_general_characteristics, scsc_area->general_char,
  918. sizeof(css_general_characteristics));
  919. memcpy(&css_chsc_characteristics, scsc_area->chsc_char,
  920. sizeof(css_chsc_characteristics));
  921. } else
  922. CIO_CRW_EVENT(2, "chsc: scsc failed (rc=%04x)\n",
  923. scsc_area->response.code);
  924. exit:
  925. spin_unlock_irq(&chsc_page_lock);
  926. return result;
  927. }
  928. EXPORT_SYMBOL_GPL(css_general_characteristics);
  929. EXPORT_SYMBOL_GPL(css_chsc_characteristics);
  930. int chsc_sstpc(void *page, unsigned int op, u16 ctrl)
  931. {
  932. struct {
  933. struct chsc_header request;
  934. unsigned int rsvd0;
  935. unsigned int op : 8;
  936. unsigned int rsvd1 : 8;
  937. unsigned int ctrl : 16;
  938. unsigned int rsvd2[5];
  939. struct chsc_header response;
  940. unsigned int rsvd3[7];
  941. } __attribute__ ((packed)) *rr;
  942. int rc;
  943. memset(page, 0, PAGE_SIZE);
  944. rr = page;
  945. rr->request.length = 0x0020;
  946. rr->request.code = 0x0033;
  947. rr->op = op;
  948. rr->ctrl = ctrl;
  949. rc = chsc(rr);
  950. if (rc)
  951. return -EIO;
  952. rc = (rr->response.code == 0x0001) ? 0 : -EIO;
  953. return rc;
  954. }
  955. int chsc_sstpi(void *page, void *result, size_t size)
  956. {
  957. struct {
  958. struct chsc_header request;
  959. unsigned int rsvd0[3];
  960. struct chsc_header response;
  961. char data[size];
  962. } __attribute__ ((packed)) *rr;
  963. int rc;
  964. memset(page, 0, PAGE_SIZE);
  965. rr = page;
  966. rr->request.length = 0x0010;
  967. rr->request.code = 0x0038;
  968. rc = chsc(rr);
  969. if (rc)
  970. return -EIO;
  971. memcpy(result, &rr->data, size);
  972. return (rr->response.code == 0x0001) ? 0 : -EIO;
  973. }
  974. int chsc_siosl(struct subchannel_id schid)
  975. {
  976. struct {
  977. struct chsc_header request;
  978. u32 word1;
  979. struct subchannel_id sid;
  980. u32 word3;
  981. struct chsc_header response;
  982. u32 word[11];
  983. } __attribute__ ((packed)) *siosl_area;
  984. unsigned long flags;
  985. int ccode;
  986. int rc;
  987. spin_lock_irqsave(&chsc_page_lock, flags);
  988. memset(chsc_page, 0, PAGE_SIZE);
  989. siosl_area = chsc_page;
  990. siosl_area->request.length = 0x0010;
  991. siosl_area->request.code = 0x0046;
  992. siosl_area->word1 = 0x80000000;
  993. siosl_area->sid = schid;
  994. ccode = chsc(siosl_area);
  995. if (ccode > 0) {
  996. if (ccode == 3)
  997. rc = -ENODEV;
  998. else
  999. rc = -EBUSY;
  1000. CIO_MSG_EVENT(2, "chsc: chsc failed for 0.%x.%04x (ccode=%d)\n",
  1001. schid.ssid, schid.sch_no, ccode);
  1002. goto out;
  1003. }
  1004. rc = chsc_error_from_response(siosl_area->response.code);
  1005. if (rc)
  1006. CIO_MSG_EVENT(2, "chsc: siosl failed for 0.%x.%04x (rc=%04x)\n",
  1007. schid.ssid, schid.sch_no,
  1008. siosl_area->response.code);
  1009. else
  1010. CIO_MSG_EVENT(4, "chsc: siosl succeeded for 0.%x.%04x\n",
  1011. schid.ssid, schid.sch_no);
  1012. out:
  1013. spin_unlock_irqrestore(&chsc_page_lock, flags);
  1014. return rc;
  1015. }
  1016. EXPORT_SYMBOL_GPL(chsc_siosl);
  1017. /**
  1018. * chsc_scm_info() - store SCM information (SSI)
  1019. * @scm_area: request and response block for SSI
  1020. * @token: continuation token
  1021. *
  1022. * Returns 0 on success.
  1023. */
  1024. int chsc_scm_info(struct chsc_scm_info *scm_area, u64 token)
  1025. {
  1026. int ccode, ret;
  1027. memset(scm_area, 0, sizeof(*scm_area));
  1028. scm_area->request.length = 0x0020;
  1029. scm_area->request.code = 0x004C;
  1030. scm_area->reqtok = token;
  1031. ccode = chsc(scm_area);
  1032. if (ccode > 0) {
  1033. ret = (ccode == 3) ? -ENODEV : -EBUSY;
  1034. goto out;
  1035. }
  1036. ret = chsc_error_from_response(scm_area->response.code);
  1037. if (ret != 0)
  1038. CIO_MSG_EVENT(2, "chsc: scm info failed (rc=%04x)\n",
  1039. scm_area->response.code);
  1040. out:
  1041. return ret;
  1042. }
  1043. EXPORT_SYMBOL_GPL(chsc_scm_info);