chsc.c 27 KB

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