chsc.c 24 KB

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