chsc.c 27 KB

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