chsc.c 25 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117
  1. /*
  2. * drivers/s390/cio/chsc.c
  3. * S/390 common I/O routines -- channel subsystem call
  4. * $Revision: 1.120 $
  5. *
  6. * Copyright (C) 1999-2002 IBM Deutschland Entwicklung GmbH,
  7. * IBM Corporation
  8. * Author(s): Ingo Adlung (adlung@de.ibm.com)
  9. * Cornelia Huck (cohuck@de.ibm.com)
  10. * Arnd Bergmann (arndb@de.ibm.com)
  11. */
  12. #include <linux/module.h>
  13. #include <linux/config.h>
  14. #include <linux/slab.h>
  15. #include <linux/init.h>
  16. #include <linux/device.h>
  17. #include <asm/cio.h>
  18. #include "css.h"
  19. #include "cio.h"
  20. #include "cio_debug.h"
  21. #include "ioasm.h"
  22. #include "chsc.h"
  23. static struct channel_path *chps[NR_CHPIDS];
  24. static void *sei_page;
  25. static int new_channel_path(int chpid);
  26. static inline void
  27. set_chp_logically_online(int chp, int onoff)
  28. {
  29. chps[chp]->state = onoff;
  30. }
  31. static int
  32. get_chp_status(int chp)
  33. {
  34. return (chps[chp] ? chps[chp]->state : -ENODEV);
  35. }
  36. void
  37. chsc_validate_chpids(struct subchannel *sch)
  38. {
  39. int mask, chp;
  40. for (chp = 0; chp <= 7; chp++) {
  41. mask = 0x80 >> chp;
  42. if (!get_chp_status(sch->schib.pmcw.chpid[chp]))
  43. /* disable using this path */
  44. sch->opm &= ~mask;
  45. }
  46. }
  47. void
  48. chpid_is_actually_online(int chp)
  49. {
  50. int state;
  51. state = get_chp_status(chp);
  52. if (state < 0) {
  53. need_rescan = 1;
  54. queue_work(slow_path_wq, &slow_path_work);
  55. } else
  56. WARN_ON(!state);
  57. }
  58. /* FIXME: this is _always_ called for every subchannel. shouldn't we
  59. * process more than one at a time? */
  60. static int
  61. chsc_get_sch_desc_irq(struct subchannel *sch, void *page)
  62. {
  63. int ccode, j;
  64. struct {
  65. struct chsc_header request;
  66. u16 reserved1;
  67. u16 f_sch; /* first subchannel */
  68. u16 reserved2;
  69. u16 l_sch; /* last subchannel */
  70. u32 reserved3;
  71. struct chsc_header response;
  72. u32 reserved4;
  73. u8 sch_valid : 1;
  74. u8 dev_valid : 1;
  75. u8 st : 3; /* subchannel type */
  76. u8 zeroes : 3;
  77. u8 unit_addr; /* unit address */
  78. u16 devno; /* device number */
  79. u8 path_mask;
  80. u8 fla_valid_mask;
  81. u16 sch; /* subchannel */
  82. u8 chpid[8]; /* chpids 0-7 */
  83. u16 fla[8]; /* full link addresses 0-7 */
  84. } *ssd_area;
  85. ssd_area = page;
  86. ssd_area->request = (struct chsc_header) {
  87. .length = 0x0010,
  88. .code = 0x0004,
  89. };
  90. ssd_area->f_sch = sch->schid.sch_no;
  91. ssd_area->l_sch = sch->schid.sch_no;
  92. ccode = chsc(ssd_area);
  93. if (ccode > 0) {
  94. pr_debug("chsc returned with ccode = %d\n", ccode);
  95. return (ccode == 3) ? -ENODEV : -EBUSY;
  96. }
  97. switch (ssd_area->response.code) {
  98. case 0x0001: /* everything ok */
  99. break;
  100. case 0x0002:
  101. CIO_CRW_EVENT(2, "Invalid command!\n");
  102. return -EINVAL;
  103. case 0x0003:
  104. CIO_CRW_EVENT(2, "Error in chsc request block!\n");
  105. return -EINVAL;
  106. case 0x0004:
  107. CIO_CRW_EVENT(2, "Model does not provide ssd\n");
  108. return -EOPNOTSUPP;
  109. default:
  110. CIO_CRW_EVENT(2, "Unknown CHSC response %d\n",
  111. ssd_area->response.code);
  112. return -EIO;
  113. }
  114. /*
  115. * ssd_area->st stores the type of the detected
  116. * subchannel, with the following definitions:
  117. *
  118. * 0: I/O subchannel: All fields have meaning
  119. * 1: CHSC subchannel: Only sch_val, st and sch
  120. * have meaning
  121. * 2: Message subchannel: All fields except unit_addr
  122. * have meaning
  123. * 3: ADM subchannel: Only sch_val, st and sch
  124. * have meaning
  125. *
  126. * Other types are currently undefined.
  127. */
  128. if (ssd_area->st > 3) { /* uhm, that looks strange... */
  129. CIO_CRW_EVENT(0, "Strange subchannel type %d"
  130. " for sch %04x\n", ssd_area->st,
  131. sch->schid.sch_no);
  132. /*
  133. * There may have been a new subchannel type defined in the
  134. * time since this code was written; since we don't know which
  135. * fields have meaning and what to do with it we just jump out
  136. */
  137. return 0;
  138. } else {
  139. const char *type[4] = {"I/O", "chsc", "message", "ADM"};
  140. CIO_CRW_EVENT(6, "ssd: sch %04x is %s subchannel\n",
  141. sch->schid.sch_no, type[ssd_area->st]);
  142. sch->ssd_info.valid = 1;
  143. sch->ssd_info.type = ssd_area->st;
  144. }
  145. if (ssd_area->st == 0 || ssd_area->st == 2) {
  146. for (j = 0; j < 8; j++) {
  147. if (!((0x80 >> j) & ssd_area->path_mask &
  148. ssd_area->fla_valid_mask))
  149. continue;
  150. sch->ssd_info.chpid[j] = ssd_area->chpid[j];
  151. sch->ssd_info.fla[j] = ssd_area->fla[j];
  152. }
  153. }
  154. return 0;
  155. }
  156. int
  157. css_get_ssd_info(struct subchannel *sch)
  158. {
  159. int ret;
  160. void *page;
  161. page = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
  162. if (!page)
  163. return -ENOMEM;
  164. spin_lock_irq(&sch->lock);
  165. ret = chsc_get_sch_desc_irq(sch, page);
  166. if (ret) {
  167. static int cio_chsc_err_msg;
  168. if (!cio_chsc_err_msg) {
  169. printk(KERN_ERR
  170. "chsc_get_sch_descriptions:"
  171. " Error %d while doing chsc; "
  172. "processing some machine checks may "
  173. "not work\n", ret);
  174. cio_chsc_err_msg = 1;
  175. }
  176. }
  177. spin_unlock_irq(&sch->lock);
  178. free_page((unsigned long)page);
  179. if (!ret) {
  180. int j, chpid;
  181. /* Allocate channel path structures, if needed. */
  182. for (j = 0; j < 8; j++) {
  183. chpid = sch->ssd_info.chpid[j];
  184. if (chpid && (get_chp_status(chpid) < 0))
  185. new_channel_path(chpid);
  186. }
  187. }
  188. return ret;
  189. }
  190. static int
  191. s390_subchannel_remove_chpid(struct device *dev, void *data)
  192. {
  193. int j;
  194. int mask;
  195. struct subchannel *sch;
  196. __u8 *chpid;
  197. struct schib schib;
  198. sch = to_subchannel(dev);
  199. chpid = data;
  200. for (j = 0; j < 8; j++)
  201. if (sch->schib.pmcw.chpid[j] == *chpid)
  202. break;
  203. if (j >= 8)
  204. return 0;
  205. mask = 0x80 >> j;
  206. spin_lock(&sch->lock);
  207. stsch(sch->schid, &schib);
  208. if (!schib.pmcw.dnv)
  209. goto out_unreg;
  210. memcpy(&sch->schib, &schib, sizeof(struct schib));
  211. /* Check for single path devices. */
  212. if (sch->schib.pmcw.pim == 0x80)
  213. goto out_unreg;
  214. if (sch->vpm == mask)
  215. goto out_unreg;
  216. if ((sch->schib.scsw.actl & (SCSW_ACTL_CLEAR_PEND |
  217. SCSW_ACTL_HALT_PEND |
  218. SCSW_ACTL_START_PEND |
  219. SCSW_ACTL_RESUME_PEND)) &&
  220. (sch->schib.pmcw.lpum == mask)) {
  221. int cc = cio_cancel(sch);
  222. if (cc == -ENODEV)
  223. goto out_unreg;
  224. if (cc == -EINVAL) {
  225. cc = cio_clear(sch);
  226. if (cc == -ENODEV)
  227. goto out_unreg;
  228. /* Call handler. */
  229. if (sch->driver && sch->driver->termination)
  230. sch->driver->termination(&sch->dev);
  231. goto out_unlock;
  232. }
  233. } else if ((sch->schib.scsw.actl & SCSW_ACTL_DEVACT) &&
  234. (sch->schib.scsw.actl & SCSW_ACTL_SCHACT) &&
  235. (sch->schib.pmcw.lpum == mask)) {
  236. int cc;
  237. cc = cio_clear(sch);
  238. if (cc == -ENODEV)
  239. goto out_unreg;
  240. /* Call handler. */
  241. if (sch->driver && sch->driver->termination)
  242. sch->driver->termination(&sch->dev);
  243. goto out_unlock;
  244. }
  245. /* trigger path verification. */
  246. if (sch->driver && sch->driver->verify)
  247. sch->driver->verify(&sch->dev);
  248. out_unlock:
  249. spin_unlock(&sch->lock);
  250. return 0;
  251. out_unreg:
  252. spin_unlock(&sch->lock);
  253. sch->lpm = 0;
  254. if (css_enqueue_subchannel_slow(sch->schid)) {
  255. css_clear_subchannel_slow_list();
  256. need_rescan = 1;
  257. }
  258. return 0;
  259. }
  260. static inline void
  261. s390_set_chpid_offline( __u8 chpid)
  262. {
  263. char dbf_txt[15];
  264. sprintf(dbf_txt, "chpr%x", chpid);
  265. CIO_TRACE_EVENT(2, dbf_txt);
  266. if (get_chp_status(chpid) <= 0)
  267. return;
  268. bus_for_each_dev(&css_bus_type, NULL, &chpid,
  269. s390_subchannel_remove_chpid);
  270. if (need_rescan || css_slow_subchannels_exist())
  271. queue_work(slow_path_wq, &slow_path_work);
  272. }
  273. static int
  274. s390_process_res_acc_sch(u8 chpid, __u16 fla, u32 fla_mask,
  275. struct subchannel *sch)
  276. {
  277. int found;
  278. int chp;
  279. int ccode;
  280. found = 0;
  281. for (chp = 0; chp <= 7; chp++)
  282. /*
  283. * check if chpid is in information updated by ssd
  284. */
  285. if (sch->ssd_info.valid &&
  286. sch->ssd_info.chpid[chp] == chpid &&
  287. (sch->ssd_info.fla[chp] & fla_mask) == fla) {
  288. found = 1;
  289. break;
  290. }
  291. if (found == 0)
  292. return 0;
  293. /*
  294. * Do a stsch to update our subchannel structure with the
  295. * new path information and eventually check for logically
  296. * offline chpids.
  297. */
  298. ccode = stsch(sch->schid, &sch->schib);
  299. if (ccode > 0)
  300. return 0;
  301. return 0x80 >> chp;
  302. }
  303. static int
  304. s390_process_res_acc (u8 chpid, __u16 fla, u32 fla_mask)
  305. {
  306. struct subchannel *sch;
  307. int rc;
  308. struct subchannel_id schid;
  309. char dbf_txt[15];
  310. sprintf(dbf_txt, "accpr%x", chpid);
  311. CIO_TRACE_EVENT( 2, dbf_txt);
  312. if (fla != 0) {
  313. sprintf(dbf_txt, "fla%x", fla);
  314. CIO_TRACE_EVENT( 2, dbf_txt);
  315. }
  316. /*
  317. * I/O resources may have become accessible.
  318. * Scan through all subchannels that may be concerned and
  319. * do a validation on those.
  320. * The more information we have (info), the less scanning
  321. * will we have to do.
  322. */
  323. if (!get_chp_status(chpid))
  324. return 0; /* no need to do the rest */
  325. rc = 0;
  326. init_subchannel_id(&schid);
  327. do {
  328. int chp_mask, old_lpm;
  329. sch = get_subchannel_by_schid(schid);
  330. if (!sch) {
  331. struct schib schib;
  332. int ret;
  333. /*
  334. * We don't know the device yet, but since a path
  335. * may be available now to the device we'll have
  336. * to do recognition again.
  337. * Since we don't have any idea about which chpid
  338. * that beast may be on we'll have to do a stsch
  339. * on all devices, grr...
  340. */
  341. if (stsch(schid, &schib)) {
  342. /* We're through */
  343. if (need_rescan)
  344. rc = -EAGAIN;
  345. break;
  346. }
  347. if (need_rescan) {
  348. rc = -EAGAIN;
  349. continue;
  350. }
  351. /* Put it on the slow path. */
  352. ret = css_enqueue_subchannel_slow(schid);
  353. if (ret) {
  354. css_clear_subchannel_slow_list();
  355. need_rescan = 1;
  356. }
  357. rc = -EAGAIN;
  358. continue;
  359. }
  360. spin_lock_irq(&sch->lock);
  361. chp_mask = s390_process_res_acc_sch(chpid, fla, fla_mask, sch);
  362. if (chp_mask == 0) {
  363. spin_unlock_irq(&sch->lock);
  364. continue;
  365. }
  366. old_lpm = sch->lpm;
  367. sch->lpm = ((sch->schib.pmcw.pim &
  368. sch->schib.pmcw.pam &
  369. sch->schib.pmcw.pom)
  370. | chp_mask) & sch->opm;
  371. if (!old_lpm && sch->lpm)
  372. device_trigger_reprobe(sch);
  373. else if (sch->driver && sch->driver->verify)
  374. sch->driver->verify(&sch->dev);
  375. spin_unlock_irq(&sch->lock);
  376. put_device(&sch->dev);
  377. if (fla_mask == 0xffff)
  378. break;
  379. } while (schid.sch_no++ < __MAX_SUBCHANNEL);
  380. return rc;
  381. }
  382. static int
  383. __get_chpid_from_lir(void *data)
  384. {
  385. struct lir {
  386. u8 iq;
  387. u8 ic;
  388. u16 sci;
  389. /* incident-node descriptor */
  390. u32 indesc[28];
  391. /* attached-node descriptor */
  392. u32 andesc[28];
  393. /* incident-specific information */
  394. u32 isinfo[28];
  395. } *lir;
  396. lir = (struct lir*) data;
  397. if (!(lir->iq&0x80))
  398. /* NULL link incident record */
  399. return -EINVAL;
  400. if (!(lir->indesc[0]&0xc0000000))
  401. /* node descriptor not valid */
  402. return -EINVAL;
  403. if (!(lir->indesc[0]&0x10000000))
  404. /* don't handle device-type nodes - FIXME */
  405. return -EINVAL;
  406. /* Byte 3 contains the chpid. Could also be CTCA, but we don't care */
  407. return (u16) (lir->indesc[0]&0x000000ff);
  408. }
  409. int
  410. chsc_process_crw(void)
  411. {
  412. int chpid, ret;
  413. struct {
  414. struct chsc_header request;
  415. u32 reserved1;
  416. u32 reserved2;
  417. u32 reserved3;
  418. struct chsc_header response;
  419. u32 reserved4;
  420. u8 flags;
  421. u8 vf; /* validity flags */
  422. u8 rs; /* reporting source */
  423. u8 cc; /* content code */
  424. u16 fla; /* full link address */
  425. u16 rsid; /* reporting source id */
  426. u32 reserved5;
  427. u32 reserved6;
  428. u32 ccdf[96]; /* content-code dependent field */
  429. /* ccdf has to be big enough for a link-incident record */
  430. } *sei_area;
  431. if (!sei_page)
  432. return 0;
  433. /*
  434. * build the chsc request block for store event information
  435. * and do the call
  436. * This function is only called by the machine check handler thread,
  437. * so we don't need locking for the sei_page.
  438. */
  439. sei_area = sei_page;
  440. CIO_TRACE_EVENT( 2, "prcss");
  441. ret = 0;
  442. do {
  443. int ccode, status;
  444. memset(sei_area, 0, sizeof(*sei_area));
  445. sei_area->request = (struct chsc_header) {
  446. .length = 0x0010,
  447. .code = 0x000e,
  448. };
  449. ccode = chsc(sei_area);
  450. if (ccode > 0)
  451. return 0;
  452. switch (sei_area->response.code) {
  453. /* for debug purposes, check for problems */
  454. case 0x0001:
  455. CIO_CRW_EVENT(4, "chsc_process_crw: event information "
  456. "successfully stored\n");
  457. break; /* everything ok */
  458. case 0x0002:
  459. CIO_CRW_EVENT(2,
  460. "chsc_process_crw: invalid command!\n");
  461. return 0;
  462. case 0x0003:
  463. CIO_CRW_EVENT(2, "chsc_process_crw: error in chsc "
  464. "request block!\n");
  465. return 0;
  466. case 0x0005:
  467. CIO_CRW_EVENT(2, "chsc_process_crw: no event "
  468. "information stored\n");
  469. return 0;
  470. default:
  471. CIO_CRW_EVENT(2, "chsc_process_crw: chsc response %d\n",
  472. sei_area->response.code);
  473. return 0;
  474. }
  475. /* Check if we might have lost some information. */
  476. if (sei_area->flags & 0x40)
  477. CIO_CRW_EVENT(2, "chsc_process_crw: Event information "
  478. "has been lost due to overflow!\n");
  479. if (sei_area->rs != 4) {
  480. CIO_CRW_EVENT(2, "chsc_process_crw: reporting source "
  481. "(%04X) isn't a chpid!\n",
  482. sei_area->rsid);
  483. continue;
  484. }
  485. /* which kind of information was stored? */
  486. switch (sei_area->cc) {
  487. case 1: /* link incident*/
  488. CIO_CRW_EVENT(4, "chsc_process_crw: "
  489. "channel subsystem reports link incident,"
  490. " reporting source is chpid %x\n",
  491. sei_area->rsid);
  492. chpid = __get_chpid_from_lir(sei_area->ccdf);
  493. if (chpid < 0)
  494. CIO_CRW_EVENT(4, "%s: Invalid LIR, skipping\n",
  495. __FUNCTION__);
  496. else
  497. s390_set_chpid_offline(chpid);
  498. break;
  499. case 2: /* i/o resource accessibiliy */
  500. CIO_CRW_EVENT(4, "chsc_process_crw: "
  501. "channel subsystem reports some I/O "
  502. "devices may have become accessible\n");
  503. pr_debug("Data received after sei: \n");
  504. pr_debug("Validity flags: %x\n", sei_area->vf);
  505. /* allocate a new channel path structure, if needed */
  506. status = get_chp_status(sei_area->rsid);
  507. if (status < 0)
  508. new_channel_path(sei_area->rsid);
  509. else if (!status)
  510. return 0;
  511. if ((sei_area->vf & 0x80) == 0) {
  512. pr_debug("chpid: %x\n", sei_area->rsid);
  513. ret = s390_process_res_acc(sei_area->rsid,
  514. 0, 0);
  515. } else if ((sei_area->vf & 0xc0) == 0x80) {
  516. pr_debug("chpid: %x link addr: %x\n",
  517. sei_area->rsid, sei_area->fla);
  518. ret = s390_process_res_acc(sei_area->rsid,
  519. sei_area->fla,
  520. 0xff00);
  521. } else if ((sei_area->vf & 0xc0) == 0xc0) {
  522. pr_debug("chpid: %x full link addr: %x\n",
  523. sei_area->rsid, sei_area->fla);
  524. ret = s390_process_res_acc(sei_area->rsid,
  525. sei_area->fla,
  526. 0xffff);
  527. }
  528. pr_debug("\n");
  529. break;
  530. default: /* other stuff */
  531. CIO_CRW_EVENT(4, "chsc_process_crw: event %d\n",
  532. sei_area->cc);
  533. break;
  534. }
  535. } while (sei_area->flags & 0x80);
  536. return ret;
  537. }
  538. static int
  539. chp_add(int chpid)
  540. {
  541. struct subchannel *sch;
  542. int ret, rc;
  543. struct subchannel_id schid;
  544. char dbf_txt[15];
  545. if (!get_chp_status(chpid))
  546. return 0; /* no need to do the rest */
  547. sprintf(dbf_txt, "cadd%x", chpid);
  548. CIO_TRACE_EVENT(2, dbf_txt);
  549. rc = 0;
  550. init_subchannel_id(&schid);
  551. do {
  552. int i;
  553. sch = get_subchannel_by_schid(schid);
  554. if (!sch) {
  555. struct schib schib;
  556. if (stsch(schid, &schib)) {
  557. /* We're through */
  558. if (need_rescan)
  559. rc = -EAGAIN;
  560. break;
  561. }
  562. if (need_rescan) {
  563. rc = -EAGAIN;
  564. continue;
  565. }
  566. /* Put it on the slow path. */
  567. ret = css_enqueue_subchannel_slow(schid);
  568. if (ret) {
  569. css_clear_subchannel_slow_list();
  570. need_rescan = 1;
  571. }
  572. rc = -EAGAIN;
  573. continue;
  574. }
  575. spin_lock(&sch->lock);
  576. for (i=0; i<8; i++)
  577. if (sch->schib.pmcw.chpid[i] == chpid) {
  578. if (stsch(sch->schid, &sch->schib) != 0) {
  579. /* Endgame. */
  580. spin_unlock(&sch->lock);
  581. return rc;
  582. }
  583. break;
  584. }
  585. if (i==8) {
  586. spin_unlock(&sch->lock);
  587. return rc;
  588. }
  589. sch->lpm = ((sch->schib.pmcw.pim &
  590. sch->schib.pmcw.pam &
  591. sch->schib.pmcw.pom)
  592. | 0x80 >> i) & sch->opm;
  593. if (sch->driver && sch->driver->verify)
  594. sch->driver->verify(&sch->dev);
  595. spin_unlock(&sch->lock);
  596. put_device(&sch->dev);
  597. } while (schid.sch_no++ < __MAX_SUBCHANNEL);
  598. return rc;
  599. }
  600. /*
  601. * Handling of crw machine checks with channel path source.
  602. */
  603. int
  604. chp_process_crw(int chpid, int on)
  605. {
  606. if (on == 0) {
  607. /* Path has gone. We use the link incident routine.*/
  608. s390_set_chpid_offline(chpid);
  609. return 0; /* De-register is async anyway. */
  610. }
  611. /*
  612. * Path has come. Allocate a new channel path structure,
  613. * if needed.
  614. */
  615. if (get_chp_status(chpid) < 0)
  616. new_channel_path(chpid);
  617. /* Avoid the extra overhead in process_rec_acc. */
  618. return chp_add(chpid);
  619. }
  620. static inline int
  621. __check_for_io_and_kill(struct subchannel *sch, int index)
  622. {
  623. int cc;
  624. if (!device_is_online(sch))
  625. /* cio could be doing I/O. */
  626. return 0;
  627. cc = stsch(sch->schid, &sch->schib);
  628. if (cc)
  629. return 0;
  630. if (sch->schib.scsw.actl && sch->schib.pmcw.lpum == (0x80 >> index)) {
  631. device_set_waiting(sch);
  632. return 1;
  633. }
  634. return 0;
  635. }
  636. static inline void
  637. __s390_subchannel_vary_chpid(struct subchannel *sch, __u8 chpid, int on)
  638. {
  639. int chp, old_lpm;
  640. unsigned long flags;
  641. if (!sch->ssd_info.valid)
  642. return;
  643. spin_lock_irqsave(&sch->lock, flags);
  644. old_lpm = sch->lpm;
  645. for (chp = 0; chp < 8; chp++) {
  646. if (sch->ssd_info.chpid[chp] != chpid)
  647. continue;
  648. if (on) {
  649. sch->opm |= (0x80 >> chp);
  650. sch->lpm |= (0x80 >> chp);
  651. if (!old_lpm)
  652. device_trigger_reprobe(sch);
  653. else if (sch->driver && sch->driver->verify)
  654. sch->driver->verify(&sch->dev);
  655. } else {
  656. sch->opm &= ~(0x80 >> chp);
  657. sch->lpm &= ~(0x80 >> chp);
  658. /*
  659. * Give running I/O a grace period in which it
  660. * can successfully terminate, even using the
  661. * just varied off path. Then kill it.
  662. */
  663. if (!__check_for_io_and_kill(sch, chp) && !sch->lpm) {
  664. if (css_enqueue_subchannel_slow(sch->schid)) {
  665. css_clear_subchannel_slow_list();
  666. need_rescan = 1;
  667. }
  668. } else if (sch->driver && sch->driver->verify)
  669. sch->driver->verify(&sch->dev);
  670. }
  671. break;
  672. }
  673. spin_unlock_irqrestore(&sch->lock, flags);
  674. }
  675. static int
  676. s390_subchannel_vary_chpid_off(struct device *dev, void *data)
  677. {
  678. struct subchannel *sch;
  679. __u8 *chpid;
  680. sch = to_subchannel(dev);
  681. chpid = data;
  682. __s390_subchannel_vary_chpid(sch, *chpid, 0);
  683. return 0;
  684. }
  685. static int
  686. s390_subchannel_vary_chpid_on(struct device *dev, void *data)
  687. {
  688. struct subchannel *sch;
  689. __u8 *chpid;
  690. sch = to_subchannel(dev);
  691. chpid = data;
  692. __s390_subchannel_vary_chpid(sch, *chpid, 1);
  693. return 0;
  694. }
  695. /*
  696. * Function: s390_vary_chpid
  697. * Varies the specified chpid online or offline
  698. */
  699. static int
  700. s390_vary_chpid( __u8 chpid, int on)
  701. {
  702. char dbf_text[15];
  703. int status, ret;
  704. struct subchannel_id schid;
  705. struct subchannel *sch;
  706. sprintf(dbf_text, on?"varyon%x":"varyoff%x", chpid);
  707. CIO_TRACE_EVENT( 2, dbf_text);
  708. status = get_chp_status(chpid);
  709. if (status < 0) {
  710. printk(KERN_ERR "Can't vary unknown chpid %02X\n", chpid);
  711. return -EINVAL;
  712. }
  713. if (!on && !status) {
  714. printk(KERN_ERR "chpid %x is already offline\n", chpid);
  715. return -EINVAL;
  716. }
  717. set_chp_logically_online(chpid, on);
  718. /*
  719. * Redo PathVerification on the devices the chpid connects to
  720. */
  721. bus_for_each_dev(&css_bus_type, NULL, &chpid, on ?
  722. s390_subchannel_vary_chpid_on :
  723. s390_subchannel_vary_chpid_off);
  724. if (!on)
  725. goto out;
  726. /* Scan for new devices on varied on path. */
  727. init_subchannel_id(&schid);
  728. do {
  729. struct schib schib;
  730. if (need_rescan)
  731. break;
  732. sch = get_subchannel_by_schid(schid);
  733. if (sch) {
  734. put_device(&sch->dev);
  735. continue;
  736. }
  737. if (stsch(schid, &schib))
  738. /* We're through */
  739. break;
  740. /* Put it on the slow path. */
  741. ret = css_enqueue_subchannel_slow(schid);
  742. if (ret) {
  743. css_clear_subchannel_slow_list();
  744. need_rescan = 1;
  745. }
  746. } while (schid.sch_no++ < __MAX_SUBCHANNEL);
  747. out:
  748. if (need_rescan || css_slow_subchannels_exist())
  749. queue_work(slow_path_wq, &slow_path_work);
  750. return 0;
  751. }
  752. /*
  753. * Files for the channel path entries.
  754. */
  755. static ssize_t
  756. chp_status_show(struct device *dev, struct device_attribute *attr, char *buf)
  757. {
  758. struct channel_path *chp = container_of(dev, struct channel_path, dev);
  759. if (!chp)
  760. return 0;
  761. return (get_chp_status(chp->id) ? sprintf(buf, "online\n") :
  762. sprintf(buf, "offline\n"));
  763. }
  764. static ssize_t
  765. chp_status_write(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  766. {
  767. struct channel_path *cp = container_of(dev, struct channel_path, dev);
  768. char cmd[10];
  769. int num_args;
  770. int error;
  771. num_args = sscanf(buf, "%5s", cmd);
  772. if (!num_args)
  773. return count;
  774. if (!strnicmp(cmd, "on", 2))
  775. error = s390_vary_chpid(cp->id, 1);
  776. else if (!strnicmp(cmd, "off", 3))
  777. error = s390_vary_chpid(cp->id, 0);
  778. else
  779. error = -EINVAL;
  780. return error < 0 ? error : count;
  781. }
  782. static DEVICE_ATTR(status, 0644, chp_status_show, chp_status_write);
  783. static ssize_t
  784. chp_type_show(struct device *dev, struct device_attribute *attr, char *buf)
  785. {
  786. struct channel_path *chp = container_of(dev, struct channel_path, dev);
  787. if (!chp)
  788. return 0;
  789. return sprintf(buf, "%x\n", chp->desc.desc);
  790. }
  791. static DEVICE_ATTR(type, 0444, chp_type_show, NULL);
  792. static struct attribute * chp_attrs[] = {
  793. &dev_attr_status.attr,
  794. &dev_attr_type.attr,
  795. NULL,
  796. };
  797. static struct attribute_group chp_attr_group = {
  798. .attrs = chp_attrs,
  799. };
  800. static void
  801. chp_release(struct device *dev)
  802. {
  803. struct channel_path *cp;
  804. cp = container_of(dev, struct channel_path, dev);
  805. kfree(cp);
  806. }
  807. static int
  808. chsc_determine_channel_path_description(int chpid,
  809. struct channel_path_desc *desc)
  810. {
  811. int ccode, ret;
  812. struct {
  813. struct chsc_header request;
  814. u32 : 24;
  815. u32 first_chpid : 8;
  816. u32 : 24;
  817. u32 last_chpid : 8;
  818. u32 zeroes1;
  819. struct chsc_header response;
  820. u32 zeroes2;
  821. struct channel_path_desc desc;
  822. } *scpd_area;
  823. scpd_area = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
  824. if (!scpd_area)
  825. return -ENOMEM;
  826. scpd_area->request = (struct chsc_header) {
  827. .length = 0x0010,
  828. .code = 0x0002,
  829. };
  830. scpd_area->first_chpid = chpid;
  831. scpd_area->last_chpid = chpid;
  832. ccode = chsc(scpd_area);
  833. if (ccode > 0) {
  834. ret = (ccode == 3) ? -ENODEV : -EBUSY;
  835. goto out;
  836. }
  837. switch (scpd_area->response.code) {
  838. case 0x0001: /* Success. */
  839. memcpy(desc, &scpd_area->desc,
  840. sizeof(struct channel_path_desc));
  841. ret = 0;
  842. break;
  843. case 0x0003: /* Invalid block. */
  844. case 0x0007: /* Invalid format. */
  845. case 0x0008: /* Other invalid block. */
  846. CIO_CRW_EVENT(2, "Error in chsc request block!\n");
  847. ret = -EINVAL;
  848. break;
  849. case 0x0004: /* Command not provided in model. */
  850. CIO_CRW_EVENT(2, "Model does not provide scpd\n");
  851. ret = -EOPNOTSUPP;
  852. break;
  853. default:
  854. CIO_CRW_EVENT(2, "Unknown CHSC response %d\n",
  855. scpd_area->response.code);
  856. ret = -EIO;
  857. }
  858. out:
  859. free_page((unsigned long)scpd_area);
  860. return ret;
  861. }
  862. /*
  863. * Entries for chpids on the system bus.
  864. * This replaces /proc/chpids.
  865. */
  866. static int
  867. new_channel_path(int chpid)
  868. {
  869. struct channel_path *chp;
  870. int ret;
  871. chp = kmalloc(sizeof(struct channel_path), GFP_KERNEL);
  872. if (!chp)
  873. return -ENOMEM;
  874. memset(chp, 0, sizeof(struct channel_path));
  875. /* fill in status, etc. */
  876. chp->id = chpid;
  877. chp->state = 1;
  878. chp->dev = (struct device) {
  879. .parent = &css_bus_device,
  880. .release = chp_release,
  881. };
  882. snprintf(chp->dev.bus_id, BUS_ID_SIZE, "chp0.%x", chpid);
  883. /* Obtain channel path description and fill it in. */
  884. ret = chsc_determine_channel_path_description(chpid, &chp->desc);
  885. if (ret)
  886. goto out_free;
  887. /* make it known to the system */
  888. ret = device_register(&chp->dev);
  889. if (ret) {
  890. printk(KERN_WARNING "%s: could not register %02x\n",
  891. __func__, chpid);
  892. goto out_free;
  893. }
  894. ret = sysfs_create_group(&chp->dev.kobj, &chp_attr_group);
  895. if (ret) {
  896. device_unregister(&chp->dev);
  897. goto out_free;
  898. } else
  899. chps[chpid] = chp;
  900. return ret;
  901. out_free:
  902. kfree(chp);
  903. return ret;
  904. }
  905. void *
  906. chsc_get_chp_desc(struct subchannel *sch, int chp_no)
  907. {
  908. struct channel_path *chp;
  909. struct channel_path_desc *desc;
  910. chp = chps[sch->schib.pmcw.chpid[chp_no]];
  911. if (!chp)
  912. return NULL;
  913. desc = kmalloc(sizeof(struct channel_path_desc), GFP_KERNEL);
  914. if (!desc)
  915. return NULL;
  916. memcpy(desc, &chp->desc, sizeof(struct channel_path_desc));
  917. return desc;
  918. }
  919. static int __init
  920. chsc_alloc_sei_area(void)
  921. {
  922. sei_page = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
  923. if (!sei_page)
  924. printk(KERN_WARNING"Can't allocate page for processing of " \
  925. "chsc machine checks!\n");
  926. return (sei_page ? 0 : -ENOMEM);
  927. }
  928. subsys_initcall(chsc_alloc_sei_area);
  929. struct css_general_char css_general_characteristics;
  930. struct css_chsc_char css_chsc_characteristics;
  931. int __init
  932. chsc_determine_css_characteristics(void)
  933. {
  934. int result;
  935. struct {
  936. struct chsc_header request;
  937. u32 reserved1;
  938. u32 reserved2;
  939. u32 reserved3;
  940. struct chsc_header response;
  941. u32 reserved4;
  942. u32 general_char[510];
  943. u32 chsc_char[518];
  944. } *scsc_area;
  945. scsc_area = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
  946. if (!scsc_area) {
  947. printk(KERN_WARNING"cio: Was not able to determine available" \
  948. "CHSCs due to no memory.\n");
  949. return -ENOMEM;
  950. }
  951. scsc_area->request = (struct chsc_header) {
  952. .length = 0x0010,
  953. .code = 0x0010,
  954. };
  955. result = chsc(scsc_area);
  956. if (result) {
  957. printk(KERN_WARNING"cio: Was not able to determine " \
  958. "available CHSCs, cc=%i.\n", result);
  959. result = -EIO;
  960. goto exit;
  961. }
  962. if (scsc_area->response.code != 1) {
  963. printk(KERN_WARNING"cio: Was not able to determine " \
  964. "available CHSCs.\n");
  965. result = -EIO;
  966. goto exit;
  967. }
  968. memcpy(&css_general_characteristics, scsc_area->general_char,
  969. sizeof(css_general_characteristics));
  970. memcpy(&css_chsc_characteristics, scsc_area->chsc_char,
  971. sizeof(css_chsc_characteristics));
  972. exit:
  973. free_page ((unsigned long) scsc_area);
  974. return result;
  975. }
  976. EXPORT_SYMBOL_GPL(css_general_characteristics);
  977. EXPORT_SYMBOL_GPL(css_chsc_characteristics);