chsc.c 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * S/390 common I/O routines -- channel subsystem call
  4. *
  5. * Copyright IBM Corp. 1999,2012
  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 <linux/mutex.h>
  17. #include <linux/pci.h>
  18. #include <asm/cio.h>
  19. #include <asm/chpid.h>
  20. #include <asm/chsc.h>
  21. #include <asm/crw.h>
  22. #include <asm/isc.h>
  23. #include <asm/ebcdic.h>
  24. #include "css.h"
  25. #include "cio.h"
  26. #include "cio_debug.h"
  27. #include "ioasm.h"
  28. #include "chp.h"
  29. #include "chsc.h"
  30. static void *sei_page;
  31. static void *chsc_page;
  32. static DEFINE_SPINLOCK(chsc_page_lock);
  33. #define SEI_VF_FLA 0xc0 /* VF flag for Full Link Address */
  34. #define SEI_RS_CHPID 0x4 /* 4 in RS field indicates CHPID */
  35. static BLOCKING_NOTIFIER_HEAD(chsc_notifiers);
  36. int chsc_notifier_register(struct notifier_block *nb)
  37. {
  38. return blocking_notifier_chain_register(&chsc_notifiers, nb);
  39. }
  40. EXPORT_SYMBOL(chsc_notifier_register);
  41. int chsc_notifier_unregister(struct notifier_block *nb)
  42. {
  43. return blocking_notifier_chain_unregister(&chsc_notifiers, nb);
  44. }
  45. EXPORT_SYMBOL(chsc_notifier_unregister);
  46. /**
  47. * chsc_error_from_response() - convert a chsc response to an error
  48. * @response: chsc response code
  49. *
  50. * Returns an appropriate Linux error code for @response.
  51. */
  52. int chsc_error_from_response(int response)
  53. {
  54. switch (response) {
  55. case 0x0001:
  56. return 0;
  57. case 0x0002:
  58. case 0x0003:
  59. case 0x0006:
  60. case 0x0007:
  61. case 0x0008:
  62. case 0x000a:
  63. case 0x0104:
  64. return -EINVAL;
  65. case 0x0004:
  66. case 0x0106: /* "Wrong Channel Parm" for the op 0x003d */
  67. return -EOPNOTSUPP;
  68. case 0x000b:
  69. case 0x0107: /* "Channel busy" for the op 0x003d */
  70. return -EBUSY;
  71. case 0x0100:
  72. case 0x0102:
  73. return -ENOMEM;
  74. case 0x0108: /* "HW limit exceeded" for the op 0x003d */
  75. return -EUSERS;
  76. default:
  77. return -EIO;
  78. }
  79. }
  80. EXPORT_SYMBOL_GPL(chsc_error_from_response);
  81. struct chsc_ssd_area {
  82. struct chsc_header request;
  83. u16 :10;
  84. u16 ssid:2;
  85. u16 :4;
  86. u16 f_sch; /* first subchannel */
  87. u16 :16;
  88. u16 l_sch; /* last subchannel */
  89. u32 :32;
  90. struct chsc_header response;
  91. u32 :32;
  92. u8 sch_valid : 1;
  93. u8 dev_valid : 1;
  94. u8 st : 3; /* subchannel type */
  95. u8 zeroes : 3;
  96. u8 unit_addr; /* unit address */
  97. u16 devno; /* device number */
  98. u8 path_mask;
  99. u8 fla_valid_mask;
  100. u16 sch; /* subchannel */
  101. u8 chpid[8]; /* chpids 0-7 */
  102. u16 fla[8]; /* full link addresses 0-7 */
  103. } __packed __aligned(PAGE_SIZE);
  104. int chsc_get_ssd_info(struct subchannel_id schid, struct chsc_ssd_info *ssd)
  105. {
  106. struct chsc_ssd_area *ssd_area;
  107. unsigned long flags;
  108. int ccode;
  109. int ret;
  110. int i;
  111. int mask;
  112. spin_lock_irqsave(&chsc_page_lock, flags);
  113. memset(chsc_page, 0, PAGE_SIZE);
  114. ssd_area = chsc_page;
  115. ssd_area->request.length = 0x0010;
  116. ssd_area->request.code = 0x0004;
  117. ssd_area->ssid = schid.ssid;
  118. ssd_area->f_sch = schid.sch_no;
  119. ssd_area->l_sch = schid.sch_no;
  120. ccode = chsc(ssd_area);
  121. /* Check response. */
  122. if (ccode > 0) {
  123. ret = (ccode == 3) ? -ENODEV : -EBUSY;
  124. goto out;
  125. }
  126. ret = chsc_error_from_response(ssd_area->response.code);
  127. if (ret != 0) {
  128. CIO_MSG_EVENT(2, "chsc: ssd failed for 0.%x.%04x (rc=%04x)\n",
  129. schid.ssid, schid.sch_no,
  130. ssd_area->response.code);
  131. goto out;
  132. }
  133. if (!ssd_area->sch_valid) {
  134. ret = -ENODEV;
  135. goto out;
  136. }
  137. /* Copy data */
  138. ret = 0;
  139. memset(ssd, 0, sizeof(struct chsc_ssd_info));
  140. if ((ssd_area->st != SUBCHANNEL_TYPE_IO) &&
  141. (ssd_area->st != SUBCHANNEL_TYPE_MSG))
  142. goto out;
  143. ssd->path_mask = ssd_area->path_mask;
  144. ssd->fla_valid_mask = ssd_area->fla_valid_mask;
  145. for (i = 0; i < 8; i++) {
  146. mask = 0x80 >> i;
  147. if (ssd_area->path_mask & mask) {
  148. chp_id_init(&ssd->chpid[i]);
  149. ssd->chpid[i].id = ssd_area->chpid[i];
  150. }
  151. if (ssd_area->fla_valid_mask & mask)
  152. ssd->fla[i] = ssd_area->fla[i];
  153. }
  154. out:
  155. spin_unlock_irqrestore(&chsc_page_lock, flags);
  156. return ret;
  157. }
  158. /**
  159. * chsc_ssqd() - store subchannel QDIO data (SSQD)
  160. * @schid: id of the subchannel on which SSQD is performed
  161. * @ssqd: request and response block for SSQD
  162. *
  163. * Returns 0 on success.
  164. */
  165. int chsc_ssqd(struct subchannel_id schid, struct chsc_ssqd_area *ssqd)
  166. {
  167. memset(ssqd, 0, sizeof(*ssqd));
  168. ssqd->request.length = 0x0010;
  169. ssqd->request.code = 0x0024;
  170. ssqd->first_sch = schid.sch_no;
  171. ssqd->last_sch = schid.sch_no;
  172. ssqd->ssid = schid.ssid;
  173. if (chsc(ssqd))
  174. return -EIO;
  175. return chsc_error_from_response(ssqd->response.code);
  176. }
  177. EXPORT_SYMBOL_GPL(chsc_ssqd);
  178. /**
  179. * chsc_sadc() - set adapter device controls (SADC)
  180. * @schid: id of the subchannel on which SADC is performed
  181. * @scssc: request and response block for SADC
  182. * @summary_indicator_addr: summary indicator address
  183. * @subchannel_indicator_addr: subchannel indicator address
  184. * @isc: Interruption Subclass for this subchannel
  185. *
  186. * Returns 0 on success.
  187. */
  188. int chsc_sadc(struct subchannel_id schid, struct chsc_scssc_area *scssc,
  189. dma64_t summary_indicator_addr, dma64_t subchannel_indicator_addr, u8 isc)
  190. {
  191. memset(scssc, 0, sizeof(*scssc));
  192. scssc->request.length = 0x0fe0;
  193. scssc->request.code = 0x0021;
  194. scssc->operation_code = 0;
  195. scssc->summary_indicator_addr = summary_indicator_addr;
  196. scssc->subchannel_indicator_addr = subchannel_indicator_addr;
  197. scssc->ks = PAGE_DEFAULT_KEY >> 4;
  198. scssc->kc = PAGE_DEFAULT_KEY >> 4;
  199. scssc->isc = isc;
  200. scssc->schid = schid;
  201. /* enable the time delay disablement facility */
  202. if (css_general_characteristics.aif_tdd)
  203. scssc->word_with_d_bit = 0x10000000;
  204. if (chsc(scssc))
  205. return -EIO;
  206. return chsc_error_from_response(scssc->response.code);
  207. }
  208. EXPORT_SYMBOL_GPL(chsc_sadc);
  209. static int s390_subchannel_remove_chpid(struct subchannel *sch, void *data)
  210. {
  211. spin_lock_irq(&sch->lock);
  212. if (sch->driver && sch->driver->chp_event)
  213. if (sch->driver->chp_event(sch, data, CHP_OFFLINE) != 0)
  214. goto out_unreg;
  215. spin_unlock_irq(&sch->lock);
  216. return 0;
  217. out_unreg:
  218. sch->lpm = 0;
  219. spin_unlock_irq(&sch->lock);
  220. css_schedule_eval(sch->schid);
  221. return 0;
  222. }
  223. void chsc_chp_offline(struct chp_id chpid)
  224. {
  225. struct channel_path *chp = chpid_to_chp(chpid);
  226. struct chp_link link;
  227. char dbf_txt[15];
  228. sprintf(dbf_txt, "chpr%x.%02x", chpid.cssid, chpid.id);
  229. CIO_TRACE_EVENT(2, dbf_txt);
  230. if (chp_get_status(chpid) <= 0)
  231. return;
  232. memset(&link, 0, sizeof(struct chp_link));
  233. link.chpid = chpid;
  234. /* Wait until previous actions have settled. */
  235. css_wait_for_slow_path();
  236. mutex_lock(&chp->lock);
  237. chp_update_desc(chp);
  238. mutex_unlock(&chp->lock);
  239. for_each_subchannel_staged(s390_subchannel_remove_chpid, NULL, &link);
  240. }
  241. static int __s390_process_res_acc(struct subchannel *sch, void *data)
  242. {
  243. spin_lock_irq(&sch->lock);
  244. if (sch->driver && sch->driver->chp_event)
  245. sch->driver->chp_event(sch, data, CHP_ONLINE);
  246. spin_unlock_irq(&sch->lock);
  247. return 0;
  248. }
  249. static void s390_process_res_acc(struct chp_link *link)
  250. {
  251. char dbf_txt[15];
  252. sprintf(dbf_txt, "accpr%x.%02x", link->chpid.cssid,
  253. link->chpid.id);
  254. CIO_TRACE_EVENT( 2, dbf_txt);
  255. if (link->fla != 0) {
  256. sprintf(dbf_txt, "fla%x", link->fla);
  257. CIO_TRACE_EVENT( 2, dbf_txt);
  258. }
  259. /* Wait until previous actions have settled. */
  260. css_wait_for_slow_path();
  261. /*
  262. * I/O resources may have become accessible.
  263. * Scan through all subchannels that may be concerned and
  264. * do a validation on those.
  265. * The more information we have (info), the less scanning
  266. * will we have to do.
  267. */
  268. for_each_subchannel_staged(__s390_process_res_acc, NULL, link);
  269. css_schedule_reprobe();
  270. }
  271. static int process_fces_event(struct subchannel *sch, void *data)
  272. {
  273. spin_lock_irq(&sch->lock);
  274. if (sch->driver && sch->driver->chp_event)
  275. sch->driver->chp_event(sch, data, CHP_FCES_EVENT);
  276. spin_unlock_irq(&sch->lock);
  277. return 0;
  278. }
  279. struct chsc_sei_nt0_area {
  280. u8 flags;
  281. u8 vf; /* validity flags */
  282. u8 rs; /* reporting source */
  283. u8 cc; /* content code */
  284. u16 fla; /* full link address */
  285. u16 rsid; /* reporting source id */
  286. u32 reserved1;
  287. u32 reserved2;
  288. /* ccdf has to be big enough for a link-incident record */
  289. u8 ccdf[PAGE_SIZE - 24 - 16]; /* content-code dependent field */
  290. } __packed;
  291. struct chsc_sei_nt2_area {
  292. u8 flags; /* p and v bit */
  293. u8 reserved1;
  294. u8 reserved2;
  295. u8 cc; /* content code */
  296. u32 reserved3[13];
  297. u8 ccdf[PAGE_SIZE - 24 - 56]; /* content-code dependent field */
  298. } __packed;
  299. #define CHSC_SEI_NT0 (1ULL << 63)
  300. #define CHSC_SEI_NT2 (1ULL << 61)
  301. struct chsc_sei {
  302. struct chsc_header request;
  303. u32 reserved1;
  304. u64 ntsm; /* notification type mask */
  305. struct chsc_header response;
  306. u32 :24;
  307. u8 nt;
  308. union {
  309. struct chsc_sei_nt0_area nt0_area;
  310. struct chsc_sei_nt2_area nt2_area;
  311. u8 nt_area[PAGE_SIZE - 24];
  312. } u;
  313. } __packed __aligned(PAGE_SIZE);
  314. /*
  315. * Link Incident Record as defined in SA22-7202, "ESCON I/O Interface"
  316. */
  317. #define LIR_IQ_CLASS_INFO 0
  318. #define LIR_IQ_CLASS_DEGRADED 1
  319. #define LIR_IQ_CLASS_NOT_OPERATIONAL 2
  320. struct lir {
  321. struct {
  322. u32 null:1;
  323. u32 reserved:3;
  324. u32 class:2;
  325. u32 reserved2:2;
  326. } __packed iq;
  327. u32 ic:8;
  328. u32 reserved:16;
  329. struct node_descriptor incident_node;
  330. struct node_descriptor attached_node;
  331. u8 reserved2[32];
  332. } __packed;
  333. #define PARAMS_LEN 10 /* PARAMS=xx,xxxxxx */
  334. #define NODEID_LEN 35 /* NODEID=tttttt/mdl,mmm.ppssssssssssss,xxxx */
  335. /* Copy EBCIDC text, convert to ASCII and optionally add delimiter. */
  336. static char *store_ebcdic(char *dest, const char *src, unsigned long len,
  337. char delim)
  338. {
  339. memcpy(dest, src, len);
  340. EBCASC(dest, len);
  341. if (delim)
  342. dest[len++] = delim;
  343. return dest + len;
  344. }
  345. static void chsc_link_from_sei(struct chp_link *link,
  346. struct chsc_sei_nt0_area *sei_area)
  347. {
  348. if ((sei_area->vf & SEI_VF_FLA) != 0) {
  349. link->fla = sei_area->fla;
  350. link->fla_mask = ((sei_area->vf & SEI_VF_FLA) == SEI_VF_FLA) ?
  351. 0xffff : 0xff00;
  352. }
  353. }
  354. /* Format node ID and parameters for output in LIR log message. */
  355. static void format_node_data(char *params, char *id, struct node_descriptor *nd)
  356. {
  357. memset(params, 0, PARAMS_LEN);
  358. memset(id, 0, NODEID_LEN);
  359. if (nd->validity != ND_VALIDITY_VALID) {
  360. strscpy(params, "n/a", PARAMS_LEN);
  361. strscpy(id, "n/a", NODEID_LEN);
  362. return;
  363. }
  364. /* PARAMS=xx,xxxxxx */
  365. snprintf(params, PARAMS_LEN, "%02x,%06x", nd->byte0, nd->params);
  366. /* NODEID=tttttt/mdl,mmm.ppssssssssssss,xxxx */
  367. id = store_ebcdic(id, nd->type, sizeof(nd->type), '/');
  368. id = store_ebcdic(id, nd->model, sizeof(nd->model), ',');
  369. id = store_ebcdic(id, nd->manufacturer, sizeof(nd->manufacturer), '.');
  370. id = store_ebcdic(id, nd->plant, sizeof(nd->plant), 0);
  371. id = store_ebcdic(id, nd->seq, sizeof(nd->seq), ',');
  372. sprintf(id, "%04X", nd->tag);
  373. }
  374. static void chsc_process_sei_link_incident(struct chsc_sei_nt0_area *sei_area)
  375. {
  376. struct lir *lir = (struct lir *) &sei_area->ccdf;
  377. char iuparams[PARAMS_LEN], iunodeid[NODEID_LEN], auparams[PARAMS_LEN],
  378. aunodeid[NODEID_LEN];
  379. CIO_CRW_EVENT(4, "chsc: link incident (rs=%02x, rs_id=%04x, iq=%02x)\n",
  380. sei_area->rs, sei_area->rsid, sei_area->ccdf[0]);
  381. /* Ignore NULL Link Incident Records. */
  382. if (lir->iq.null)
  383. return;
  384. /* Inform user that a link requires maintenance actions because it has
  385. * become degraded or not operational. Note that this log message is
  386. * the primary intention behind a Link Incident Record. */
  387. format_node_data(iuparams, iunodeid, &lir->incident_node);
  388. format_node_data(auparams, aunodeid, &lir->attached_node);
  389. switch (lir->iq.class) {
  390. case LIR_IQ_CLASS_DEGRADED:
  391. pr_warn("Link degraded: RS=%02x RSID=%04x IC=%02x "
  392. "IUPARAMS=%s IUNODEID=%s AUPARAMS=%s AUNODEID=%s\n",
  393. sei_area->rs, sei_area->rsid, lir->ic, iuparams,
  394. iunodeid, auparams, aunodeid);
  395. break;
  396. case LIR_IQ_CLASS_NOT_OPERATIONAL:
  397. pr_err("Link stopped: RS=%02x RSID=%04x IC=%02x "
  398. "IUPARAMS=%s IUNODEID=%s AUPARAMS=%s AUNODEID=%s\n",
  399. sei_area->rs, sei_area->rsid, lir->ic, iuparams,
  400. iunodeid, auparams, aunodeid);
  401. break;
  402. default:
  403. break;
  404. }
  405. }
  406. static void chsc_process_sei_res_acc(struct chsc_sei_nt0_area *sei_area)
  407. {
  408. struct channel_path *chp;
  409. struct chp_link link;
  410. struct chp_id chpid;
  411. int status;
  412. CIO_CRW_EVENT(4, "chsc: resource accessibility event (rs=%02x, "
  413. "rs_id=%04x)\n", sei_area->rs, sei_area->rsid);
  414. if (sei_area->rs != 4)
  415. return;
  416. chp_id_init(&chpid);
  417. chpid.id = sei_area->rsid;
  418. /* allocate a new channel path structure, if needed */
  419. status = chp_get_status(chpid);
  420. if (!status)
  421. return;
  422. if (status < 0) {
  423. chp_new(chpid);
  424. } else {
  425. chp = chpid_to_chp(chpid);
  426. mutex_lock(&chp->lock);
  427. chp_update_desc(chp);
  428. mutex_unlock(&chp->lock);
  429. }
  430. memset(&link, 0, sizeof(struct chp_link));
  431. link.chpid = chpid;
  432. chsc_link_from_sei(&link, sei_area);
  433. s390_process_res_acc(&link);
  434. }
  435. static void chsc_process_sei_chp_avail(struct chsc_sei_nt0_area *sei_area)
  436. {
  437. struct channel_path *chp;
  438. struct chp_id chpid;
  439. u8 *data;
  440. int num;
  441. CIO_CRW_EVENT(4, "chsc: channel path availability information\n");
  442. if (sei_area->rs != 0)
  443. return;
  444. data = sei_area->ccdf;
  445. chp_id_init(&chpid);
  446. for (num = 0; num <= __MAX_CHPID; num++) {
  447. if (!chp_test_bit(data, num))
  448. continue;
  449. chpid.id = num;
  450. CIO_CRW_EVENT(4, "Update information for channel path "
  451. "%x.%02x\n", chpid.cssid, chpid.id);
  452. chp = chpid_to_chp(chpid);
  453. if (!chp) {
  454. chp_new(chpid);
  455. continue;
  456. }
  457. mutex_lock(&chp->lock);
  458. chp_update_desc(chp);
  459. mutex_unlock(&chp->lock);
  460. }
  461. }
  462. struct chp_config_data {
  463. u8 map[32];
  464. u8 op;
  465. u8 pc;
  466. };
  467. static void chsc_process_sei_chp_config(struct chsc_sei_nt0_area *sei_area)
  468. {
  469. struct chp_config_data *data;
  470. struct chp_id chpid;
  471. int num;
  472. char *events[3] = {"configure", "deconfigure", "cancel deconfigure"};
  473. CIO_CRW_EVENT(4, "chsc: channel-path-configuration notification\n");
  474. if (sei_area->rs != 0)
  475. return;
  476. data = (struct chp_config_data *) &(sei_area->ccdf);
  477. chp_id_init(&chpid);
  478. for (num = 0; num <= __MAX_CHPID; num++) {
  479. if (!chp_test_bit(data->map, num))
  480. continue;
  481. chpid.id = num;
  482. pr_notice("Processing %s for channel path %x.%02x\n",
  483. events[data->op], chpid.cssid, chpid.id);
  484. switch (data->op) {
  485. case 0:
  486. chp_cfg_schedule(chpid, 1);
  487. break;
  488. case 1:
  489. chp_cfg_schedule(chpid, 0);
  490. break;
  491. case 2:
  492. chp_cfg_cancel_deconfigure(chpid);
  493. break;
  494. }
  495. }
  496. }
  497. static void chsc_process_sei_scm_change(struct chsc_sei_nt0_area *sei_area)
  498. {
  499. int ret;
  500. CIO_CRW_EVENT(4, "chsc: scm change notification\n");
  501. if (sei_area->rs != 7)
  502. return;
  503. ret = scm_update_information();
  504. if (ret)
  505. CIO_CRW_EVENT(0, "chsc: updating change notification"
  506. " failed (rc=%d).\n", ret);
  507. }
  508. static void chsc_process_sei_scm_avail(struct chsc_sei_nt0_area *sei_area)
  509. {
  510. int ret;
  511. CIO_CRW_EVENT(4, "chsc: scm available information\n");
  512. if (sei_area->rs != 7)
  513. return;
  514. ret = scm_process_availability_information();
  515. if (ret)
  516. CIO_CRW_EVENT(0, "chsc: process availability information"
  517. " failed (rc=%d).\n", ret);
  518. }
  519. static void chsc_process_sei_ap_cfg_chg(struct chsc_sei_nt0_area *sei_area)
  520. {
  521. CIO_CRW_EVENT(3, "chsc: ap config changed\n");
  522. if (sei_area->rs != 5)
  523. return;
  524. blocking_notifier_call_chain(&chsc_notifiers,
  525. CHSC_NOTIFY_AP_CFG, NULL);
  526. }
  527. static void chsc_process_sei_fces_event(struct chsc_sei_nt0_area *sei_area)
  528. {
  529. struct chp_link link;
  530. struct chp_id chpid;
  531. struct channel_path *chp;
  532. CIO_CRW_EVENT(4,
  533. "chsc: FCES status notification (rs=%02x, rs_id=%04x, FCES-status=%x)\n",
  534. sei_area->rs, sei_area->rsid, sei_area->ccdf[0]);
  535. if (sei_area->rs != SEI_RS_CHPID)
  536. return;
  537. chp_id_init(&chpid);
  538. chpid.id = sei_area->rsid;
  539. /* Ignore the event on unknown/invalid chp */
  540. chp = chpid_to_chp(chpid);
  541. if (!chp)
  542. return;
  543. memset(&link, 0, sizeof(struct chp_link));
  544. link.chpid = chpid;
  545. chsc_link_from_sei(&link, sei_area);
  546. for_each_subchannel_staged(process_fces_event, NULL, &link);
  547. }
  548. static void chsc_process_sei_nt2(struct chsc_sei_nt2_area *sei_area)
  549. {
  550. switch (sei_area->cc) {
  551. case 1:
  552. zpci_event_error(sei_area->ccdf);
  553. break;
  554. case 2:
  555. zpci_event_availability(sei_area->ccdf);
  556. break;
  557. default:
  558. CIO_CRW_EVENT(2, "chsc: sei nt2 unhandled cc=%d\n",
  559. sei_area->cc);
  560. break;
  561. }
  562. }
  563. static void chsc_process_sei_nt0(struct chsc_sei_nt0_area *sei_area)
  564. {
  565. /* which kind of information was stored? */
  566. switch (sei_area->cc) {
  567. case 1: /* link incident*/
  568. chsc_process_sei_link_incident(sei_area);
  569. break;
  570. case 2: /* i/o resource accessibility */
  571. chsc_process_sei_res_acc(sei_area);
  572. break;
  573. case 3: /* ap config changed */
  574. chsc_process_sei_ap_cfg_chg(sei_area);
  575. break;
  576. case 7: /* channel-path-availability information */
  577. chsc_process_sei_chp_avail(sei_area);
  578. break;
  579. case 8: /* channel-path-configuration notification */
  580. chsc_process_sei_chp_config(sei_area);
  581. break;
  582. case 12: /* scm change notification */
  583. chsc_process_sei_scm_change(sei_area);
  584. break;
  585. case 14: /* scm available notification */
  586. chsc_process_sei_scm_avail(sei_area);
  587. break;
  588. case 15: /* FCES event notification */
  589. chsc_process_sei_fces_event(sei_area);
  590. break;
  591. default: /* other stuff */
  592. CIO_CRW_EVENT(2, "chsc: sei nt0 unhandled cc=%d\n",
  593. sei_area->cc);
  594. break;
  595. }
  596. /* Check if we might have lost some information. */
  597. if (sei_area->flags & 0x40) {
  598. CIO_CRW_EVENT(2, "chsc: event overflow\n");
  599. css_schedule_eval_all();
  600. }
  601. }
  602. static void chsc_process_event_information(struct chsc_sei *sei, u64 ntsm)
  603. {
  604. static int ntsm_unsupported;
  605. while (true) {
  606. memset(sei, 0, sizeof(*sei));
  607. sei->request.length = 0x0010;
  608. sei->request.code = 0x000e;
  609. if (!ntsm_unsupported)
  610. sei->ntsm = ntsm;
  611. if (chsc(sei))
  612. break;
  613. if (sei->response.code != 0x0001) {
  614. CIO_CRW_EVENT(2, "chsc: sei failed (rc=%04x, ntsm=%llx)\n",
  615. sei->response.code, sei->ntsm);
  616. if (sei->response.code == 3 && sei->ntsm) {
  617. /* Fallback for old firmware. */
  618. ntsm_unsupported = 1;
  619. continue;
  620. }
  621. break;
  622. }
  623. CIO_CRW_EVENT(2, "chsc: sei successful (nt=%d)\n", sei->nt);
  624. switch (sei->nt) {
  625. case 0:
  626. chsc_process_sei_nt0(&sei->u.nt0_area);
  627. break;
  628. case 2:
  629. chsc_process_sei_nt2(&sei->u.nt2_area);
  630. break;
  631. default:
  632. CIO_CRW_EVENT(2, "chsc: unhandled nt: %d\n", sei->nt);
  633. break;
  634. }
  635. if (!(sei->u.nt0_area.flags & 0x80))
  636. break;
  637. }
  638. }
  639. /*
  640. * Handle channel subsystem related CRWs.
  641. * Use store event information to find out what's going on.
  642. *
  643. * Note: Access to sei_page is serialized through machine check handler
  644. * thread, so no need for locking.
  645. */
  646. static void chsc_process_crw(struct crw *crw0, struct crw *crw1, int overflow)
  647. {
  648. struct chsc_sei *sei = sei_page;
  649. if (overflow) {
  650. css_schedule_eval_all();
  651. return;
  652. }
  653. CIO_CRW_EVENT(2, "CRW reports slct=%d, oflw=%d, "
  654. "chn=%d, rsc=%X, anc=%d, erc=%X, rsid=%X\n",
  655. crw0->slct, crw0->oflw, crw0->chn, crw0->rsc, crw0->anc,
  656. crw0->erc, crw0->rsid);
  657. CIO_TRACE_EVENT(2, "prcss");
  658. chsc_process_event_information(sei, CHSC_SEI_NT0 | CHSC_SEI_NT2);
  659. }
  660. void chsc_chp_online(struct chp_id chpid)
  661. {
  662. struct channel_path *chp = chpid_to_chp(chpid);
  663. struct chp_link link;
  664. char dbf_txt[15];
  665. sprintf(dbf_txt, "cadd%x.%02x", chpid.cssid, chpid.id);
  666. CIO_TRACE_EVENT(2, dbf_txt);
  667. if (chp_get_status(chpid) != 0) {
  668. memset(&link, 0, sizeof(struct chp_link));
  669. link.chpid = chpid;
  670. /* Wait until previous actions have settled. */
  671. css_wait_for_slow_path();
  672. mutex_lock(&chp->lock);
  673. chp_update_desc(chp);
  674. mutex_unlock(&chp->lock);
  675. for_each_subchannel_staged(__s390_process_res_acc, NULL,
  676. &link);
  677. css_schedule_reprobe();
  678. }
  679. }
  680. static void __s390_subchannel_vary_chpid(struct subchannel *sch,
  681. struct chp_id chpid, int on)
  682. {
  683. unsigned long flags;
  684. struct chp_link link;
  685. memset(&link, 0, sizeof(struct chp_link));
  686. link.chpid = chpid;
  687. spin_lock_irqsave(&sch->lock, flags);
  688. if (sch->driver && sch->driver->chp_event)
  689. sch->driver->chp_event(sch, &link,
  690. on ? CHP_VARY_ON : CHP_VARY_OFF);
  691. spin_unlock_irqrestore(&sch->lock, flags);
  692. }
  693. static int s390_subchannel_vary_chpid_off(struct subchannel *sch, void *data)
  694. {
  695. struct chp_id *chpid = data;
  696. __s390_subchannel_vary_chpid(sch, *chpid, 0);
  697. return 0;
  698. }
  699. static int s390_subchannel_vary_chpid_on(struct subchannel *sch, void *data)
  700. {
  701. struct chp_id *chpid = data;
  702. __s390_subchannel_vary_chpid(sch, *chpid, 1);
  703. return 0;
  704. }
  705. /**
  706. * chsc_chp_vary - propagate channel-path vary operation to subchannels
  707. * @chpid: channl-path ID
  708. * @on: non-zero for vary online, zero for vary offline
  709. */
  710. int chsc_chp_vary(struct chp_id chpid, int on)
  711. {
  712. struct channel_path *chp = chpid_to_chp(chpid);
  713. /*
  714. * Redo PathVerification on the devices the chpid connects to
  715. */
  716. if (on) {
  717. /* Try to update the channel path description. */
  718. chp_update_desc(chp);
  719. for_each_subchannel_staged(s390_subchannel_vary_chpid_on,
  720. NULL, &chpid);
  721. css_schedule_reprobe();
  722. } else
  723. for_each_subchannel_staged(s390_subchannel_vary_chpid_off,
  724. NULL, &chpid);
  725. return 0;
  726. }
  727. static void
  728. chsc_remove_cmg_attr(struct channel_subsystem *css)
  729. {
  730. int i;
  731. for (i = 0; i <= __MAX_CHPID; i++) {
  732. if (!css->chps[i])
  733. continue;
  734. chp_remove_cmg_attr(css->chps[i]);
  735. }
  736. }
  737. static int
  738. chsc_add_cmg_attr(struct channel_subsystem *css)
  739. {
  740. int i, ret;
  741. ret = 0;
  742. for (i = 0; i <= __MAX_CHPID; i++) {
  743. if (!css->chps[i])
  744. continue;
  745. ret = chp_add_cmg_attr(css->chps[i]);
  746. if (ret)
  747. goto cleanup;
  748. }
  749. return ret;
  750. cleanup:
  751. while (i--) {
  752. if (!css->chps[i])
  753. continue;
  754. chp_remove_cmg_attr(css->chps[i]);
  755. }
  756. return ret;
  757. }
  758. int __chsc_do_secm(struct channel_subsystem *css, int enable)
  759. {
  760. struct {
  761. struct chsc_header request;
  762. u32 operation_code : 2;
  763. u32 : 1;
  764. u32 e : 1;
  765. u32 : 28;
  766. u32 key : 4;
  767. u32 : 28;
  768. dma64_t cub[CSS_NUM_CUB_PAGES];
  769. dma64_t ecub[CSS_NUM_ECUB_PAGES];
  770. u32 reserved[5];
  771. struct chsc_header response;
  772. u32 status : 8;
  773. u32 : 4;
  774. u32 fmt : 4;
  775. u32 : 16;
  776. } __packed *secm_area;
  777. unsigned long flags;
  778. int ret, ccode, i;
  779. spin_lock_irqsave(&chsc_page_lock, flags);
  780. memset(chsc_page, 0, PAGE_SIZE);
  781. secm_area = chsc_page;
  782. secm_area->request.length = 0x0050;
  783. secm_area->request.code = 0x0016;
  784. secm_area->key = PAGE_DEFAULT_KEY >> 4;
  785. secm_area->e = 1;
  786. for (i = 0; i < CSS_NUM_CUB_PAGES; i++)
  787. secm_area->cub[i] = (__force dma64_t)virt_to_dma32(css->cub[i]);
  788. for (i = 0; i < CSS_NUM_ECUB_PAGES; i++)
  789. secm_area->ecub[i] = virt_to_dma64(css->ecub[i]);
  790. secm_area->operation_code = enable ? 0 : 1;
  791. ccode = chsc(secm_area);
  792. if (ccode > 0) {
  793. ret = (ccode == 3) ? -ENODEV : -EBUSY;
  794. goto out;
  795. }
  796. switch (secm_area->response.code) {
  797. case 0x0102:
  798. case 0x0103:
  799. ret = -EINVAL;
  800. break;
  801. default:
  802. ret = chsc_error_from_response(secm_area->response.code);
  803. }
  804. if (ret != 0)
  805. CIO_CRW_EVENT(2, "chsc: secm failed (rc=%04x)\n",
  806. secm_area->response.code);
  807. out:
  808. spin_unlock_irqrestore(&chsc_page_lock, flags);
  809. return ret;
  810. }
  811. static int cub_alloc(struct channel_subsystem *css)
  812. {
  813. int i;
  814. for (i = 0; i < CSS_NUM_CUB_PAGES; i++) {
  815. css->cub[i] = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
  816. if (!css->cub[i])
  817. return -ENOMEM;
  818. }
  819. for (i = 0; i < CSS_NUM_ECUB_PAGES; i++) {
  820. css->ecub[i] = (void *)get_zeroed_page(GFP_KERNEL);
  821. if (!css->ecub[i])
  822. return -ENOMEM;
  823. }
  824. return 0;
  825. }
  826. static void cub_free(struct channel_subsystem *css)
  827. {
  828. int i;
  829. for (i = 0; i < CSS_NUM_CUB_PAGES; i++) {
  830. free_page((unsigned long)css->cub[i]);
  831. css->cub[i] = NULL;
  832. }
  833. for (i = 0; i < CSS_NUM_ECUB_PAGES; i++) {
  834. free_page((unsigned long)css->ecub[i]);
  835. css->ecub[i] = NULL;
  836. }
  837. }
  838. int
  839. chsc_secm(struct channel_subsystem *css, int enable)
  840. {
  841. int ret;
  842. if (enable && !css->cm_enabled) {
  843. ret = cub_alloc(css);
  844. if (ret)
  845. goto out;
  846. }
  847. ret = __chsc_do_secm(css, enable);
  848. if (!ret) {
  849. css->cm_enabled = enable;
  850. if (css->cm_enabled) {
  851. ret = chsc_add_cmg_attr(css);
  852. if (ret) {
  853. __chsc_do_secm(css, 0);
  854. css->cm_enabled = 0;
  855. }
  856. } else
  857. chsc_remove_cmg_attr(css);
  858. }
  859. out:
  860. if (!css->cm_enabled)
  861. cub_free(css);
  862. return ret;
  863. }
  864. int chsc_determine_channel_path_desc(struct chp_id chpid, int fmt, int rfmt,
  865. int c, int m, void *page)
  866. {
  867. struct chsc_scpd *scpd_area;
  868. int ccode, ret;
  869. if ((rfmt == 1 || rfmt == 0) && c == 1 &&
  870. !css_general_characteristics.fcs)
  871. return -EINVAL;
  872. if ((rfmt == 2) && !css_general_characteristics.cib)
  873. return -EINVAL;
  874. if ((rfmt == 3) && !css_general_characteristics.util_str)
  875. return -EINVAL;
  876. memset(page, 0, PAGE_SIZE);
  877. scpd_area = page;
  878. scpd_area->request.length = 0x0010;
  879. scpd_area->request.code = 0x0002;
  880. scpd_area->cssid = chpid.cssid;
  881. scpd_area->first_chpid = chpid.id;
  882. scpd_area->last_chpid = chpid.id;
  883. scpd_area->m = m;
  884. scpd_area->c = c;
  885. scpd_area->fmt = fmt;
  886. scpd_area->rfmt = rfmt;
  887. ccode = chsc(scpd_area);
  888. if (ccode > 0)
  889. return (ccode == 3) ? -ENODEV : -EBUSY;
  890. ret = chsc_error_from_response(scpd_area->response.code);
  891. if (ret)
  892. CIO_CRW_EVENT(2, "chsc: scpd failed (rc=%04x)\n",
  893. scpd_area->response.code);
  894. return ret;
  895. }
  896. EXPORT_SYMBOL_GPL(chsc_determine_channel_path_desc);
  897. #define chsc_det_chp_desc(FMT, c) \
  898. int chsc_determine_fmt##FMT##_channel_path_desc( \
  899. struct chp_id chpid, struct channel_path_desc_fmt##FMT *desc) \
  900. { \
  901. struct chsc_scpd *scpd_area; \
  902. unsigned long flags; \
  903. int ret; \
  904. \
  905. spin_lock_irqsave(&chsc_page_lock, flags); \
  906. scpd_area = chsc_page; \
  907. ret = chsc_determine_channel_path_desc(chpid, 0, FMT, c, 0, \
  908. scpd_area); \
  909. if (ret) \
  910. goto out; \
  911. \
  912. memcpy(desc, scpd_area->data, sizeof(*desc)); \
  913. out: \
  914. spin_unlock_irqrestore(&chsc_page_lock, flags); \
  915. return ret; \
  916. }
  917. chsc_det_chp_desc(0, 0)
  918. chsc_det_chp_desc(1, 1)
  919. chsc_det_chp_desc(3, 0)
  920. static void
  921. chsc_initialize_cmg_chars(struct channel_path *chp, u8 cmcv,
  922. struct cmg_chars *chars)
  923. {
  924. int i, mask;
  925. for (i = 0; i < NR_MEASUREMENT_CHARS; i++) {
  926. mask = 0x80 >> (i + 3);
  927. if (cmcv & mask)
  928. chp->cmg_chars.values[i] = chars->values[i];
  929. else
  930. chp->cmg_chars.values[i] = 0;
  931. }
  932. }
  933. static unsigned long scmc_get_speed(u32 s, u32 p)
  934. {
  935. unsigned long speed = s;
  936. if (!p)
  937. p = 8;
  938. while (p--)
  939. speed *= 10;
  940. return speed;
  941. }
  942. int chsc_get_channel_measurement_chars(struct channel_path *chp)
  943. {
  944. unsigned long flags;
  945. int ccode, ret;
  946. struct {
  947. struct chsc_header request;
  948. u32 : 24;
  949. u32 first_chpid : 8;
  950. u32 : 24;
  951. u32 last_chpid : 8;
  952. u32 zeroes1;
  953. struct chsc_header response;
  954. u32 zeroes2;
  955. u32 not_valid : 1;
  956. u32 shared : 1;
  957. u32 extended : 1;
  958. u32 : 21;
  959. u32 chpid : 8;
  960. u32 cmcv : 5;
  961. u32 : 7;
  962. u32 cmgp : 4;
  963. u32 cmgq : 8;
  964. u32 cmg : 8;
  965. u32 : 16;
  966. u32 cmgs : 16;
  967. u32 data[NR_MEASUREMENT_CHARS];
  968. } *scmc_area;
  969. chp->shared = -1;
  970. chp->cmg = -1;
  971. chp->extended = 0;
  972. chp->speed = 0;
  973. if (!css_chsc_characteristics.scmc || !css_chsc_characteristics.secm)
  974. return -EINVAL;
  975. spin_lock_irqsave(&chsc_page_lock, flags);
  976. memset(chsc_page, 0, PAGE_SIZE);
  977. scmc_area = chsc_page;
  978. scmc_area->request.length = 0x0010;
  979. scmc_area->request.code = 0x0022;
  980. scmc_area->first_chpid = chp->chpid.id;
  981. scmc_area->last_chpid = chp->chpid.id;
  982. ccode = chsc(scmc_area);
  983. if (ccode > 0) {
  984. ret = (ccode == 3) ? -ENODEV : -EBUSY;
  985. goto out;
  986. }
  987. ret = chsc_error_from_response(scmc_area->response.code);
  988. if (ret) {
  989. CIO_CRW_EVENT(2, "chsc: scmc failed (rc=%04x)\n",
  990. scmc_area->response.code);
  991. goto out;
  992. }
  993. if (scmc_area->not_valid)
  994. goto out;
  995. chp->cmg = scmc_area->cmg;
  996. chp->shared = scmc_area->shared;
  997. chp->extended = scmc_area->extended;
  998. chp->speed = scmc_get_speed(scmc_area->cmgs, scmc_area->cmgp);
  999. chsc_initialize_cmg_chars(chp, scmc_area->cmcv,
  1000. (struct cmg_chars *) &scmc_area->data);
  1001. out:
  1002. spin_unlock_irqrestore(&chsc_page_lock, flags);
  1003. return ret;
  1004. }
  1005. int __init chsc_init(void)
  1006. {
  1007. int ret;
  1008. sei_page = (void *)get_zeroed_page(GFP_KERNEL);
  1009. chsc_page = (void *)get_zeroed_page(GFP_KERNEL);
  1010. if (!sei_page || !chsc_page) {
  1011. ret = -ENOMEM;
  1012. goto out_err;
  1013. }
  1014. ret = crw_register_handler(CRW_RSC_CSS, chsc_process_crw);
  1015. if (ret)
  1016. goto out_err;
  1017. return ret;
  1018. out_err:
  1019. free_page((unsigned long)chsc_page);
  1020. free_page((unsigned long)sei_page);
  1021. return ret;
  1022. }
  1023. void __init chsc_init_cleanup(void)
  1024. {
  1025. crw_unregister_handler(CRW_RSC_CSS);
  1026. free_page((unsigned long)chsc_page);
  1027. free_page((unsigned long)sei_page);
  1028. }
  1029. int __chsc_enable_facility(struct chsc_sda_area *sda_area, int operation_code)
  1030. {
  1031. int ret;
  1032. sda_area->request.length = 0x0400;
  1033. sda_area->request.code = 0x0031;
  1034. sda_area->operation_code = operation_code;
  1035. ret = chsc(sda_area);
  1036. if (ret > 0) {
  1037. ret = (ret == 3) ? -ENODEV : -EBUSY;
  1038. goto out;
  1039. }
  1040. switch (sda_area->response.code) {
  1041. case 0x0101:
  1042. ret = -EOPNOTSUPP;
  1043. break;
  1044. default:
  1045. ret = chsc_error_from_response(sda_area->response.code);
  1046. }
  1047. out:
  1048. return ret;
  1049. }
  1050. int chsc_enable_facility(int operation_code)
  1051. {
  1052. struct chsc_sda_area *sda_area;
  1053. unsigned long flags;
  1054. int ret;
  1055. spin_lock_irqsave(&chsc_page_lock, flags);
  1056. memset(chsc_page, 0, PAGE_SIZE);
  1057. sda_area = chsc_page;
  1058. ret = __chsc_enable_facility(sda_area, operation_code);
  1059. if (ret != 0)
  1060. CIO_CRW_EVENT(2, "chsc: sda (oc=%x) failed (rc=%04x)\n",
  1061. operation_code, sda_area->response.code);
  1062. spin_unlock_irqrestore(&chsc_page_lock, flags);
  1063. return ret;
  1064. }
  1065. int __init chsc_get_cssid_iid(int idx, u8 *cssid, u8 *iid)
  1066. {
  1067. struct {
  1068. struct chsc_header request;
  1069. u8 atype;
  1070. u32 : 24;
  1071. u32 reserved1[6];
  1072. struct chsc_header response;
  1073. u32 reserved2[3];
  1074. struct {
  1075. u8 cssid;
  1076. u8 iid;
  1077. u32 : 16;
  1078. } list[];
  1079. } *sdcal_area;
  1080. int ret;
  1081. spin_lock_irq(&chsc_page_lock);
  1082. memset(chsc_page, 0, PAGE_SIZE);
  1083. sdcal_area = chsc_page;
  1084. sdcal_area->request.length = 0x0020;
  1085. sdcal_area->request.code = 0x0034;
  1086. sdcal_area->atype = 4;
  1087. ret = chsc(sdcal_area);
  1088. if (ret) {
  1089. ret = (ret == 3) ? -ENODEV : -EBUSY;
  1090. goto exit;
  1091. }
  1092. ret = chsc_error_from_response(sdcal_area->response.code);
  1093. if (ret) {
  1094. CIO_CRW_EVENT(2, "chsc: sdcal failed (rc=%04x)\n",
  1095. sdcal_area->response.code);
  1096. goto exit;
  1097. }
  1098. if ((addr_t) &sdcal_area->list[idx] <
  1099. (addr_t) &sdcal_area->response + sdcal_area->response.length) {
  1100. *cssid = sdcal_area->list[idx].cssid;
  1101. *iid = sdcal_area->list[idx].iid;
  1102. }
  1103. else
  1104. ret = -ENODEV;
  1105. exit:
  1106. spin_unlock_irq(&chsc_page_lock);
  1107. return ret;
  1108. }
  1109. struct css_general_char css_general_characteristics;
  1110. struct css_chsc_char css_chsc_characteristics;
  1111. int __init
  1112. chsc_determine_css_characteristics(void)
  1113. {
  1114. unsigned long flags;
  1115. int result;
  1116. struct {
  1117. struct chsc_header request;
  1118. u32 reserved1;
  1119. u32 reserved2;
  1120. u32 reserved3;
  1121. struct chsc_header response;
  1122. u32 reserved4;
  1123. u32 general_char[510];
  1124. u32 chsc_char[508];
  1125. } *scsc_area;
  1126. spin_lock_irqsave(&chsc_page_lock, flags);
  1127. memset(chsc_page, 0, PAGE_SIZE);
  1128. scsc_area = chsc_page;
  1129. scsc_area->request.length = 0x0010;
  1130. scsc_area->request.code = 0x0010;
  1131. result = chsc(scsc_area);
  1132. if (result) {
  1133. result = (result == 3) ? -ENODEV : -EBUSY;
  1134. goto exit;
  1135. }
  1136. result = chsc_error_from_response(scsc_area->response.code);
  1137. if (result == 0) {
  1138. memcpy(&css_general_characteristics, scsc_area->general_char,
  1139. sizeof(css_general_characteristics));
  1140. memcpy(&css_chsc_characteristics, scsc_area->chsc_char,
  1141. sizeof(css_chsc_characteristics));
  1142. } else
  1143. CIO_CRW_EVENT(2, "chsc: scsc failed (rc=%04x)\n",
  1144. scsc_area->response.code);
  1145. exit:
  1146. spin_unlock_irqrestore(&chsc_page_lock, flags);
  1147. return result;
  1148. }
  1149. EXPORT_SYMBOL_GPL(css_general_characteristics);
  1150. EXPORT_SYMBOL_GPL(css_chsc_characteristics);
  1151. int chsc_sstpc(void *page, unsigned int op, u16 ctrl, long *clock_delta)
  1152. {
  1153. struct {
  1154. struct chsc_header request;
  1155. unsigned int rsvd0;
  1156. unsigned int op : 8;
  1157. unsigned int rsvd1 : 8;
  1158. unsigned int ctrl : 16;
  1159. unsigned int rsvd2[5];
  1160. struct chsc_header response;
  1161. unsigned int rsvd3[3];
  1162. s64 clock_delta;
  1163. unsigned int rsvd4[2];
  1164. } *rr;
  1165. int rc;
  1166. memset(page, 0, PAGE_SIZE);
  1167. rr = page;
  1168. rr->request.length = 0x0020;
  1169. rr->request.code = 0x0033;
  1170. rr->op = op;
  1171. rr->ctrl = ctrl;
  1172. rc = chsc(rr);
  1173. if (rc)
  1174. return -EIO;
  1175. rc = (rr->response.code == 0x0001) ? 0 : -EIO;
  1176. if (clock_delta)
  1177. *clock_delta = rr->clock_delta;
  1178. return rc;
  1179. }
  1180. int chsc_sstpi(void *page, void *result, size_t size)
  1181. {
  1182. struct {
  1183. struct chsc_header request;
  1184. unsigned int rsvd0[3];
  1185. struct chsc_header response;
  1186. char data[];
  1187. } *rr;
  1188. int rc;
  1189. memset(page, 0, PAGE_SIZE);
  1190. rr = page;
  1191. rr->request.length = 0x0010;
  1192. rr->request.code = 0x0038;
  1193. rc = chsc(rr);
  1194. if (rc)
  1195. return -EIO;
  1196. memcpy(result, &rr->data, size);
  1197. return (rr->response.code == 0x0001) ? 0 : -EIO;
  1198. }
  1199. int chsc_stzi(void *page, void *result, size_t size)
  1200. {
  1201. struct {
  1202. struct chsc_header request;
  1203. unsigned int rsvd0[3];
  1204. struct chsc_header response;
  1205. char data[];
  1206. } *rr;
  1207. int rc;
  1208. memset(page, 0, PAGE_SIZE);
  1209. rr = page;
  1210. rr->request.length = 0x0010;
  1211. rr->request.code = 0x003e;
  1212. rc = chsc(rr);
  1213. if (rc)
  1214. return -EIO;
  1215. memcpy(result, &rr->data, size);
  1216. return (rr->response.code == 0x0001) ? 0 : -EIO;
  1217. }
  1218. int chsc_siosl(struct subchannel_id schid)
  1219. {
  1220. struct {
  1221. struct chsc_header request;
  1222. u32 word1;
  1223. struct subchannel_id sid;
  1224. u32 word3;
  1225. struct chsc_header response;
  1226. u32 word[11];
  1227. } *siosl_area;
  1228. unsigned long flags;
  1229. int ccode;
  1230. int rc;
  1231. spin_lock_irqsave(&chsc_page_lock, flags);
  1232. memset(chsc_page, 0, PAGE_SIZE);
  1233. siosl_area = chsc_page;
  1234. siosl_area->request.length = 0x0010;
  1235. siosl_area->request.code = 0x0046;
  1236. siosl_area->word1 = 0x80000000;
  1237. siosl_area->sid = schid;
  1238. ccode = chsc(siosl_area);
  1239. if (ccode > 0) {
  1240. if (ccode == 3)
  1241. rc = -ENODEV;
  1242. else
  1243. rc = -EBUSY;
  1244. CIO_MSG_EVENT(2, "chsc: chsc failed for 0.%x.%04x (ccode=%d)\n",
  1245. schid.ssid, schid.sch_no, ccode);
  1246. goto out;
  1247. }
  1248. rc = chsc_error_from_response(siosl_area->response.code);
  1249. if (rc)
  1250. CIO_MSG_EVENT(2, "chsc: siosl failed for 0.%x.%04x (rc=%04x)\n",
  1251. schid.ssid, schid.sch_no,
  1252. siosl_area->response.code);
  1253. else
  1254. CIO_MSG_EVENT(4, "chsc: siosl succeeded for 0.%x.%04x\n",
  1255. schid.ssid, schid.sch_no);
  1256. out:
  1257. spin_unlock_irqrestore(&chsc_page_lock, flags);
  1258. return rc;
  1259. }
  1260. EXPORT_SYMBOL_GPL(chsc_siosl);
  1261. /**
  1262. * chsc_scm_info() - store SCM information (SSI)
  1263. * @scm_area: request and response block for SSI
  1264. * @token: continuation token
  1265. *
  1266. * Returns 0 on success.
  1267. */
  1268. int chsc_scm_info(struct chsc_scm_info *scm_area, u64 token)
  1269. {
  1270. int ccode, ret;
  1271. memset(scm_area, 0, sizeof(*scm_area));
  1272. scm_area->request.length = 0x0020;
  1273. scm_area->request.code = 0x004C;
  1274. scm_area->reqtok = token;
  1275. ccode = chsc(scm_area);
  1276. if (ccode > 0) {
  1277. ret = (ccode == 3) ? -ENODEV : -EBUSY;
  1278. goto out;
  1279. }
  1280. ret = chsc_error_from_response(scm_area->response.code);
  1281. if (ret != 0)
  1282. CIO_MSG_EVENT(2, "chsc: scm info failed (rc=%04x)\n",
  1283. scm_area->response.code);
  1284. out:
  1285. return ret;
  1286. }
  1287. EXPORT_SYMBOL_GPL(chsc_scm_info);
  1288. /**
  1289. * chsc_pnso() - Perform Network-Subchannel Operation
  1290. * @schid: id of the subchannel on which PNSO is performed
  1291. * @pnso_area: request and response block for the operation
  1292. * @oc: Operation Code
  1293. * @resume_token: resume token for multiblock response
  1294. * @cnc: Boolean change-notification control
  1295. *
  1296. * pnso_area must be allocated by the caller with get_zeroed_page(GFP_KERNEL)
  1297. *
  1298. * Returns 0 on success.
  1299. */
  1300. int chsc_pnso(struct subchannel_id schid, struct chsc_pnso_area *pnso_area,
  1301. u8 oc, struct chsc_pnso_resume_token resume_token, int cnc)
  1302. {
  1303. memset(pnso_area, 0, sizeof(*pnso_area));
  1304. pnso_area->request.length = 0x0030;
  1305. pnso_area->request.code = 0x003d; /* network-subchannel operation */
  1306. pnso_area->m = schid.m;
  1307. pnso_area->ssid = schid.ssid;
  1308. pnso_area->sch = schid.sch_no;
  1309. pnso_area->cssid = schid.cssid;
  1310. pnso_area->oc = oc;
  1311. pnso_area->resume_token = resume_token;
  1312. pnso_area->n = (cnc != 0);
  1313. if (chsc(pnso_area))
  1314. return -EIO;
  1315. return chsc_error_from_response(pnso_area->response.code);
  1316. }
  1317. int chsc_sgib(u32 origin)
  1318. {
  1319. struct {
  1320. struct chsc_header request;
  1321. u16 op;
  1322. u8 reserved01[2];
  1323. u8 reserved02:4;
  1324. u8 fmt:4;
  1325. u8 reserved03[7];
  1326. /* operation data area begin */
  1327. u8 reserved04[4];
  1328. u32 gib_origin;
  1329. u8 reserved05[10];
  1330. u8 aix;
  1331. u8 reserved06[4029];
  1332. struct chsc_header response;
  1333. u8 reserved07[4];
  1334. } *sgib_area;
  1335. int ret;
  1336. spin_lock_irq(&chsc_page_lock);
  1337. memset(chsc_page, 0, PAGE_SIZE);
  1338. sgib_area = chsc_page;
  1339. sgib_area->request.length = 0x0fe0;
  1340. sgib_area->request.code = 0x0021;
  1341. sgib_area->op = 0x1;
  1342. sgib_area->gib_origin = origin;
  1343. ret = chsc(sgib_area);
  1344. if (ret == 0)
  1345. ret = chsc_error_from_response(sgib_area->response.code);
  1346. spin_unlock_irq(&chsc_page_lock);
  1347. return ret;
  1348. }
  1349. EXPORT_SYMBOL_GPL(chsc_sgib);
  1350. #define SCUD_REQ_LEN 0x10 /* SCUD request block length */
  1351. #define SCUD_REQ_CMD 0x4b /* SCUD Command Code */
  1352. struct chse_cudb {
  1353. u16 flags:8;
  1354. u16 chp_valid:8;
  1355. u16 cu;
  1356. u32 esm_valid:8;
  1357. u32:24;
  1358. u8 chpid[8];
  1359. u32:32;
  1360. u32:32;
  1361. u8 esm[8];
  1362. u32 efla[8];
  1363. } __packed;
  1364. struct chsc_scud {
  1365. struct chsc_header request;
  1366. u16:4;
  1367. u16 fmt:4;
  1368. u16 cssid:8;
  1369. u16 first_cu;
  1370. u16:16;
  1371. u16 last_cu;
  1372. u32:32;
  1373. struct chsc_header response;
  1374. u16:4;
  1375. u16 fmt_resp:4;
  1376. u32:24;
  1377. struct chse_cudb cudb[];
  1378. } __packed;
  1379. /**
  1380. * chsc_scud() - Store control-unit description.
  1381. * @cu: number of the control-unit
  1382. * @esm: 8 1-byte endpoint security mode values
  1383. * @esm_valid: validity mask for @esm
  1384. *
  1385. * Interface to retrieve information about the endpoint security
  1386. * modes for up to 8 paths of a control unit.
  1387. *
  1388. * Returns 0 on success.
  1389. */
  1390. int chsc_scud(u16 cu, u64 *esm, u8 *esm_valid)
  1391. {
  1392. struct chsc_scud *scud = chsc_page;
  1393. int ret;
  1394. spin_lock_irq(&chsc_page_lock);
  1395. memset(chsc_page, 0, PAGE_SIZE);
  1396. scud->request.length = SCUD_REQ_LEN;
  1397. scud->request.code = SCUD_REQ_CMD;
  1398. scud->fmt = 0;
  1399. scud->cssid = 0;
  1400. scud->first_cu = cu;
  1401. scud->last_cu = cu;
  1402. ret = chsc(scud);
  1403. if (!ret)
  1404. ret = chsc_error_from_response(scud->response.code);
  1405. if (!ret && (scud->response.length <= 8 || scud->fmt_resp != 0
  1406. || !(scud->cudb[0].flags & 0x80)
  1407. || scud->cudb[0].cu != cu)) {
  1408. CIO_MSG_EVENT(2, "chsc: scud failed rc=%04x, L2=%04x "
  1409. "FMT=%04x, cudb.flags=%02x, cudb.cu=%04x",
  1410. scud->response.code, scud->response.length,
  1411. scud->fmt_resp, scud->cudb[0].flags, scud->cudb[0].cu);
  1412. ret = -EINVAL;
  1413. }
  1414. if (ret)
  1415. goto out;
  1416. memcpy(esm, scud->cudb[0].esm, sizeof(*esm));
  1417. *esm_valid = scud->cudb[0].esm_valid;
  1418. out:
  1419. spin_unlock_irq(&chsc_page_lock);
  1420. return ret;
  1421. }
  1422. EXPORT_SYMBOL_GPL(chsc_scud);