chsc.c 23 KB

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