chsc.c 36 KB

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