chsc.c 27 KB

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