chsc.c 32 KB

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