chsc.c 28 KB

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