chsc.c 24 KB

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