chsc.c 25 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114
  1. /*
  2. * drivers/s390/cio/chsc.c
  3. * S/390 common I/O routines -- channel subsystem call
  4. * $Revision: 1.119 $
  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->irq;
  91. ssd_area->l_sch = sch->irq;
  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, sch->irq);
  131. /*
  132. * There may have been a new subchannel type defined in the
  133. * time since this code was written; since we don't know which
  134. * fields have meaning and what to do with it we just jump out
  135. */
  136. return 0;
  137. } else {
  138. const char *type[4] = {"I/O", "chsc", "message", "ADM"};
  139. CIO_CRW_EVENT(6, "ssd: sch %04x is %s subchannel\n",
  140. sch->irq, type[ssd_area->st]);
  141. sch->ssd_info.valid = 1;
  142. sch->ssd_info.type = ssd_area->st;
  143. }
  144. if (ssd_area->st == 0 || ssd_area->st == 2) {
  145. for (j = 0; j < 8; j++) {
  146. if (!((0x80 >> j) & ssd_area->path_mask &
  147. ssd_area->fla_valid_mask))
  148. continue;
  149. sch->ssd_info.chpid[j] = ssd_area->chpid[j];
  150. sch->ssd_info.fla[j] = ssd_area->fla[j];
  151. }
  152. }
  153. return 0;
  154. }
  155. int
  156. css_get_ssd_info(struct subchannel *sch)
  157. {
  158. int ret;
  159. void *page;
  160. page = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
  161. if (!page)
  162. return -ENOMEM;
  163. spin_lock_irq(&sch->lock);
  164. ret = chsc_get_sch_desc_irq(sch, page);
  165. if (ret) {
  166. static int cio_chsc_err_msg;
  167. if (!cio_chsc_err_msg) {
  168. printk(KERN_ERR
  169. "chsc_get_sch_descriptions:"
  170. " Error %d while doing chsc; "
  171. "processing some machine checks may "
  172. "not work\n", ret);
  173. cio_chsc_err_msg = 1;
  174. }
  175. }
  176. spin_unlock_irq(&sch->lock);
  177. free_page((unsigned long)page);
  178. if (!ret) {
  179. int j, chpid;
  180. /* Allocate channel path structures, if needed. */
  181. for (j = 0; j < 8; j++) {
  182. chpid = sch->ssd_info.chpid[j];
  183. if (chpid && (get_chp_status(chpid) < 0))
  184. new_channel_path(chpid);
  185. }
  186. }
  187. return ret;
  188. }
  189. static int
  190. s390_subchannel_remove_chpid(struct device *dev, void *data)
  191. {
  192. int j;
  193. int mask;
  194. struct subchannel *sch;
  195. __u8 *chpid;
  196. struct schib schib;
  197. sch = to_subchannel(dev);
  198. chpid = data;
  199. for (j = 0; j < 8; j++)
  200. if (sch->schib.pmcw.chpid[j] == *chpid)
  201. break;
  202. if (j >= 8)
  203. return 0;
  204. mask = 0x80 >> j;
  205. spin_lock(&sch->lock);
  206. stsch(sch->irq, &schib);
  207. if (!schib.pmcw.dnv)
  208. goto out_unreg;
  209. memcpy(&sch->schib, &schib, sizeof(struct schib));
  210. /* Check for single path devices. */
  211. if (sch->schib.pmcw.pim == 0x80)
  212. goto out_unreg;
  213. if (sch->vpm == mask)
  214. goto out_unreg;
  215. if ((sch->schib.scsw.actl & (SCSW_ACTL_CLEAR_PEND |
  216. SCSW_ACTL_HALT_PEND |
  217. SCSW_ACTL_START_PEND |
  218. SCSW_ACTL_RESUME_PEND)) &&
  219. (sch->schib.pmcw.lpum == mask)) {
  220. int cc = cio_cancel(sch);
  221. if (cc == -ENODEV)
  222. goto out_unreg;
  223. if (cc == -EINVAL) {
  224. cc = cio_clear(sch);
  225. if (cc == -ENODEV)
  226. goto out_unreg;
  227. /* Call handler. */
  228. if (sch->driver && sch->driver->termination)
  229. sch->driver->termination(&sch->dev);
  230. goto out_unlock;
  231. }
  232. } else if ((sch->schib.scsw.actl & SCSW_ACTL_DEVACT) &&
  233. (sch->schib.scsw.actl & SCSW_ACTL_SCHACT) &&
  234. (sch->schib.pmcw.lpum == mask)) {
  235. int cc;
  236. cc = cio_clear(sch);
  237. if (cc == -ENODEV)
  238. goto out_unreg;
  239. /* Call handler. */
  240. if (sch->driver && sch->driver->termination)
  241. sch->driver->termination(&sch->dev);
  242. goto out_unlock;
  243. }
  244. /* trigger path verification. */
  245. if (sch->driver && sch->driver->verify)
  246. sch->driver->verify(&sch->dev);
  247. out_unlock:
  248. spin_unlock(&sch->lock);
  249. return 0;
  250. out_unreg:
  251. spin_unlock(&sch->lock);
  252. sch->lpm = 0;
  253. if (css_enqueue_subchannel_slow(sch->irq)) {
  254. css_clear_subchannel_slow_list();
  255. need_rescan = 1;
  256. }
  257. return 0;
  258. }
  259. static inline void
  260. s390_set_chpid_offline( __u8 chpid)
  261. {
  262. char dbf_txt[15];
  263. sprintf(dbf_txt, "chpr%x", chpid);
  264. CIO_TRACE_EVENT(2, dbf_txt);
  265. if (get_chp_status(chpid) <= 0)
  266. return;
  267. bus_for_each_dev(&css_bus_type, NULL, &chpid,
  268. s390_subchannel_remove_chpid);
  269. if (need_rescan || css_slow_subchannels_exist())
  270. queue_work(slow_path_wq, &slow_path_work);
  271. }
  272. static int
  273. s390_process_res_acc_sch(u8 chpid, __u16 fla, u32 fla_mask,
  274. struct subchannel *sch)
  275. {
  276. int found;
  277. int chp;
  278. int ccode;
  279. found = 0;
  280. for (chp = 0; chp <= 7; chp++)
  281. /*
  282. * check if chpid is in information updated by ssd
  283. */
  284. if (sch->ssd_info.valid &&
  285. sch->ssd_info.chpid[chp] == chpid &&
  286. (sch->ssd_info.fla[chp] & fla_mask) == fla) {
  287. found = 1;
  288. break;
  289. }
  290. if (found == 0)
  291. return 0;
  292. /*
  293. * Do a stsch to update our subchannel structure with the
  294. * new path information and eventually check for logically
  295. * offline chpids.
  296. */
  297. ccode = stsch(sch->irq, &sch->schib);
  298. if (ccode > 0)
  299. return 0;
  300. return 0x80 >> chp;
  301. }
  302. static int
  303. s390_process_res_acc (u8 chpid, __u16 fla, u32 fla_mask)
  304. {
  305. struct subchannel *sch;
  306. int irq, rc;
  307. char dbf_txt[15];
  308. sprintf(dbf_txt, "accpr%x", chpid);
  309. CIO_TRACE_EVENT( 2, dbf_txt);
  310. if (fla != 0) {
  311. sprintf(dbf_txt, "fla%x", fla);
  312. CIO_TRACE_EVENT( 2, dbf_txt);
  313. }
  314. /*
  315. * I/O resources may have become accessible.
  316. * Scan through all subchannels that may be concerned and
  317. * do a validation on those.
  318. * The more information we have (info), the less scanning
  319. * will we have to do.
  320. */
  321. if (!get_chp_status(chpid))
  322. return 0; /* no need to do the rest */
  323. rc = 0;
  324. for (irq = 0; irq < __MAX_SUBCHANNELS; irq++) {
  325. int chp_mask, old_lpm;
  326. sch = get_subchannel_by_schid(irq);
  327. if (!sch) {
  328. struct schib schib;
  329. int ret;
  330. /*
  331. * We don't know the device yet, but since a path
  332. * may be available now to the device we'll have
  333. * to do recognition again.
  334. * Since we don't have any idea about which chpid
  335. * that beast may be on we'll have to do a stsch
  336. * on all devices, grr...
  337. */
  338. if (stsch(irq, &schib)) {
  339. /* We're through */
  340. if (need_rescan)
  341. rc = -EAGAIN;
  342. break;
  343. }
  344. if (need_rescan) {
  345. rc = -EAGAIN;
  346. continue;
  347. }
  348. /* Put it on the slow path. */
  349. ret = css_enqueue_subchannel_slow(irq);
  350. if (ret) {
  351. css_clear_subchannel_slow_list();
  352. need_rescan = 1;
  353. }
  354. rc = -EAGAIN;
  355. continue;
  356. }
  357. spin_lock_irq(&sch->lock);
  358. chp_mask = s390_process_res_acc_sch(chpid, fla, fla_mask, sch);
  359. if (chp_mask == 0) {
  360. spin_unlock_irq(&sch->lock);
  361. if (fla_mask != 0)
  362. break;
  363. else
  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 != 0)
  378. break;
  379. }
  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 irq, ret, rc;
  543. char dbf_txt[15];
  544. if (!get_chp_status(chpid))
  545. return 0; /* no need to do the rest */
  546. sprintf(dbf_txt, "cadd%x", chpid);
  547. CIO_TRACE_EVENT(2, dbf_txt);
  548. rc = 0;
  549. for (irq = 0; irq < __MAX_SUBCHANNELS; irq++) {
  550. int i;
  551. sch = get_subchannel_by_schid(irq);
  552. if (!sch) {
  553. struct schib schib;
  554. if (stsch(irq, &schib)) {
  555. /* We're through */
  556. if (need_rescan)
  557. rc = -EAGAIN;
  558. break;
  559. }
  560. if (need_rescan) {
  561. rc = -EAGAIN;
  562. continue;
  563. }
  564. /* Put it on the slow path. */
  565. ret = css_enqueue_subchannel_slow(irq);
  566. if (ret) {
  567. css_clear_subchannel_slow_list();
  568. need_rescan = 1;
  569. }
  570. rc = -EAGAIN;
  571. continue;
  572. }
  573. spin_lock(&sch->lock);
  574. for (i=0; i<8; i++)
  575. if (sch->schib.pmcw.chpid[i] == chpid) {
  576. if (stsch(sch->irq, &sch->schib) != 0) {
  577. /* Endgame. */
  578. spin_unlock(&sch->lock);
  579. return rc;
  580. }
  581. break;
  582. }
  583. if (i==8) {
  584. spin_unlock(&sch->lock);
  585. return rc;
  586. }
  587. sch->lpm = ((sch->schib.pmcw.pim &
  588. sch->schib.pmcw.pam &
  589. sch->schib.pmcw.pom)
  590. | 0x80 >> i) & sch->opm;
  591. if (sch->driver && sch->driver->verify)
  592. sch->driver->verify(&sch->dev);
  593. spin_unlock(&sch->lock);
  594. put_device(&sch->dev);
  595. }
  596. return rc;
  597. }
  598. /*
  599. * Handling of crw machine checks with channel path source.
  600. */
  601. int
  602. chp_process_crw(int chpid, int on)
  603. {
  604. if (on == 0) {
  605. /* Path has gone. We use the link incident routine.*/
  606. s390_set_chpid_offline(chpid);
  607. return 0; /* De-register is async anyway. */
  608. }
  609. /*
  610. * Path has come. Allocate a new channel path structure,
  611. * if needed.
  612. */
  613. if (get_chp_status(chpid) < 0)
  614. new_channel_path(chpid);
  615. /* Avoid the extra overhead in process_rec_acc. */
  616. return chp_add(chpid);
  617. }
  618. static inline int
  619. __check_for_io_and_kill(struct subchannel *sch, int index)
  620. {
  621. int cc;
  622. if (!device_is_online(sch))
  623. /* cio could be doing I/O. */
  624. return 0;
  625. cc = stsch(sch->irq, &sch->schib);
  626. if (cc)
  627. return 0;
  628. if (sch->schib.scsw.actl && sch->schib.pmcw.lpum == (0x80 >> index)) {
  629. device_set_waiting(sch);
  630. return 1;
  631. }
  632. return 0;
  633. }
  634. static inline void
  635. __s390_subchannel_vary_chpid(struct subchannel *sch, __u8 chpid, int on)
  636. {
  637. int chp, old_lpm;
  638. unsigned long flags;
  639. if (!sch->ssd_info.valid)
  640. return;
  641. spin_lock_irqsave(&sch->lock, flags);
  642. old_lpm = sch->lpm;
  643. for (chp = 0; chp < 8; chp++) {
  644. if (sch->ssd_info.chpid[chp] != chpid)
  645. continue;
  646. if (on) {
  647. sch->opm |= (0x80 >> chp);
  648. sch->lpm |= (0x80 >> chp);
  649. if (!old_lpm)
  650. device_trigger_reprobe(sch);
  651. else if (sch->driver && sch->driver->verify)
  652. sch->driver->verify(&sch->dev);
  653. } else {
  654. sch->opm &= ~(0x80 >> chp);
  655. sch->lpm &= ~(0x80 >> chp);
  656. /*
  657. * Give running I/O a grace period in which it
  658. * can successfully terminate, even using the
  659. * just varied off path. Then kill it.
  660. */
  661. if (!__check_for_io_and_kill(sch, chp) && !sch->lpm) {
  662. if (css_enqueue_subchannel_slow(sch->irq)) {
  663. css_clear_subchannel_slow_list();
  664. need_rescan = 1;
  665. }
  666. } else if (sch->driver && sch->driver->verify)
  667. sch->driver->verify(&sch->dev);
  668. }
  669. break;
  670. }
  671. spin_unlock_irqrestore(&sch->lock, flags);
  672. }
  673. static int
  674. s390_subchannel_vary_chpid_off(struct device *dev, void *data)
  675. {
  676. struct subchannel *sch;
  677. __u8 *chpid;
  678. sch = to_subchannel(dev);
  679. chpid = data;
  680. __s390_subchannel_vary_chpid(sch, *chpid, 0);
  681. return 0;
  682. }
  683. static int
  684. s390_subchannel_vary_chpid_on(struct device *dev, void *data)
  685. {
  686. struct subchannel *sch;
  687. __u8 *chpid;
  688. sch = to_subchannel(dev);
  689. chpid = data;
  690. __s390_subchannel_vary_chpid(sch, *chpid, 1);
  691. return 0;
  692. }
  693. /*
  694. * Function: s390_vary_chpid
  695. * Varies the specified chpid online or offline
  696. */
  697. static int
  698. s390_vary_chpid( __u8 chpid, int on)
  699. {
  700. char dbf_text[15];
  701. int status, irq, ret;
  702. struct subchannel *sch;
  703. sprintf(dbf_text, on?"varyon%x":"varyoff%x", chpid);
  704. CIO_TRACE_EVENT( 2, dbf_text);
  705. status = get_chp_status(chpid);
  706. if (status < 0) {
  707. printk(KERN_ERR "Can't vary unknown chpid %02X\n", chpid);
  708. return -EINVAL;
  709. }
  710. if (!on && !status) {
  711. printk(KERN_ERR "chpid %x is already offline\n", chpid);
  712. return -EINVAL;
  713. }
  714. set_chp_logically_online(chpid, on);
  715. /*
  716. * Redo PathVerification on the devices the chpid connects to
  717. */
  718. bus_for_each_dev(&css_bus_type, NULL, &chpid, on ?
  719. s390_subchannel_vary_chpid_on :
  720. s390_subchannel_vary_chpid_off);
  721. if (!on)
  722. goto out;
  723. /* Scan for new devices on varied on path. */
  724. for (irq = 0; irq < __MAX_SUBCHANNELS; irq++) {
  725. struct schib schib;
  726. if (need_rescan)
  727. break;
  728. sch = get_subchannel_by_schid(irq);
  729. if (sch) {
  730. put_device(&sch->dev);
  731. continue;
  732. }
  733. if (stsch(irq, &schib))
  734. /* We're through */
  735. break;
  736. /* Put it on the slow path. */
  737. ret = css_enqueue_subchannel_slow(irq);
  738. if (ret) {
  739. css_clear_subchannel_slow_list();
  740. need_rescan = 1;
  741. }
  742. }
  743. out:
  744. if (need_rescan || css_slow_subchannels_exist())
  745. queue_work(slow_path_wq, &slow_path_work);
  746. return 0;
  747. }
  748. /*
  749. * Files for the channel path entries.
  750. */
  751. static ssize_t
  752. chp_status_show(struct device *dev, struct device_attribute *attr, char *buf)
  753. {
  754. struct channel_path *chp = container_of(dev, struct channel_path, dev);
  755. if (!chp)
  756. return 0;
  757. return (get_chp_status(chp->id) ? sprintf(buf, "online\n") :
  758. sprintf(buf, "offline\n"));
  759. }
  760. static ssize_t
  761. chp_status_write(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  762. {
  763. struct channel_path *cp = container_of(dev, struct channel_path, dev);
  764. char cmd[10];
  765. int num_args;
  766. int error;
  767. num_args = sscanf(buf, "%5s", cmd);
  768. if (!num_args)
  769. return count;
  770. if (!strnicmp(cmd, "on", 2))
  771. error = s390_vary_chpid(cp->id, 1);
  772. else if (!strnicmp(cmd, "off", 3))
  773. error = s390_vary_chpid(cp->id, 0);
  774. else
  775. error = -EINVAL;
  776. return error < 0 ? error : count;
  777. }
  778. static DEVICE_ATTR(status, 0644, chp_status_show, chp_status_write);
  779. static ssize_t
  780. chp_type_show(struct device *dev, struct device_attribute *attr, char *buf)
  781. {
  782. struct channel_path *chp = container_of(dev, struct channel_path, dev);
  783. if (!chp)
  784. return 0;
  785. return sprintf(buf, "%x\n", chp->desc.desc);
  786. }
  787. static DEVICE_ATTR(type, 0444, chp_type_show, NULL);
  788. static struct attribute * chp_attrs[] = {
  789. &dev_attr_status.attr,
  790. &dev_attr_type.attr,
  791. NULL,
  792. };
  793. static struct attribute_group chp_attr_group = {
  794. .attrs = chp_attrs,
  795. };
  796. static void
  797. chp_release(struct device *dev)
  798. {
  799. struct channel_path *cp;
  800. cp = container_of(dev, struct channel_path, dev);
  801. kfree(cp);
  802. }
  803. static int
  804. chsc_determine_channel_path_description(int chpid,
  805. struct channel_path_desc *desc)
  806. {
  807. int ccode, ret;
  808. struct {
  809. struct chsc_header request;
  810. u32 : 24;
  811. u32 first_chpid : 8;
  812. u32 : 24;
  813. u32 last_chpid : 8;
  814. u32 zeroes1;
  815. struct chsc_header response;
  816. u32 zeroes2;
  817. struct channel_path_desc desc;
  818. } *scpd_area;
  819. scpd_area = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
  820. if (!scpd_area)
  821. return -ENOMEM;
  822. scpd_area->request = (struct chsc_header) {
  823. .length = 0x0010,
  824. .code = 0x0002,
  825. };
  826. scpd_area->first_chpid = chpid;
  827. scpd_area->last_chpid = chpid;
  828. ccode = chsc(scpd_area);
  829. if (ccode > 0) {
  830. ret = (ccode == 3) ? -ENODEV : -EBUSY;
  831. goto out;
  832. }
  833. switch (scpd_area->response.code) {
  834. case 0x0001: /* Success. */
  835. memcpy(desc, &scpd_area->desc,
  836. sizeof(struct channel_path_desc));
  837. ret = 0;
  838. break;
  839. case 0x0003: /* Invalid block. */
  840. case 0x0007: /* Invalid format. */
  841. case 0x0008: /* Other invalid block. */
  842. CIO_CRW_EVENT(2, "Error in chsc request block!\n");
  843. ret = -EINVAL;
  844. break;
  845. case 0x0004: /* Command not provided in model. */
  846. CIO_CRW_EVENT(2, "Model does not provide scpd\n");
  847. ret = -EOPNOTSUPP;
  848. break;
  849. default:
  850. CIO_CRW_EVENT(2, "Unknown CHSC response %d\n",
  851. scpd_area->response.code);
  852. ret = -EIO;
  853. }
  854. out:
  855. free_page((unsigned long)scpd_area);
  856. return ret;
  857. }
  858. /*
  859. * Entries for chpids on the system bus.
  860. * This replaces /proc/chpids.
  861. */
  862. static int
  863. new_channel_path(int chpid)
  864. {
  865. struct channel_path *chp;
  866. int ret;
  867. chp = kmalloc(sizeof(struct channel_path), GFP_KERNEL);
  868. if (!chp)
  869. return -ENOMEM;
  870. memset(chp, 0, sizeof(struct channel_path));
  871. /* fill in status, etc. */
  872. chp->id = chpid;
  873. chp->state = 1;
  874. chp->dev = (struct device) {
  875. .parent = &css_bus_device,
  876. .release = chp_release,
  877. };
  878. snprintf(chp->dev.bus_id, BUS_ID_SIZE, "chp0.%x", chpid);
  879. /* Obtain channel path description and fill it in. */
  880. ret = chsc_determine_channel_path_description(chpid, &chp->desc);
  881. if (ret)
  882. goto out_free;
  883. /* make it known to the system */
  884. ret = device_register(&chp->dev);
  885. if (ret) {
  886. printk(KERN_WARNING "%s: could not register %02x\n",
  887. __func__, chpid);
  888. goto out_free;
  889. }
  890. ret = sysfs_create_group(&chp->dev.kobj, &chp_attr_group);
  891. if (ret) {
  892. device_unregister(&chp->dev);
  893. goto out_free;
  894. } else
  895. chps[chpid] = chp;
  896. return ret;
  897. out_free:
  898. kfree(chp);
  899. return ret;
  900. }
  901. void *
  902. chsc_get_chp_desc(struct subchannel *sch, int chp_no)
  903. {
  904. struct channel_path *chp;
  905. struct channel_path_desc *desc;
  906. chp = chps[sch->schib.pmcw.chpid[chp_no]];
  907. if (!chp)
  908. return NULL;
  909. desc = kmalloc(sizeof(struct channel_path_desc), GFP_KERNEL);
  910. if (!desc)
  911. return NULL;
  912. memcpy(desc, &chp->desc, sizeof(struct channel_path_desc));
  913. return desc;
  914. }
  915. static int __init
  916. chsc_alloc_sei_area(void)
  917. {
  918. sei_page = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
  919. if (!sei_page)
  920. printk(KERN_WARNING"Can't allocate page for processing of " \
  921. "chsc machine checks!\n");
  922. return (sei_page ? 0 : -ENOMEM);
  923. }
  924. subsys_initcall(chsc_alloc_sei_area);
  925. struct css_general_char css_general_characteristics;
  926. struct css_chsc_char css_chsc_characteristics;
  927. int __init
  928. chsc_determine_css_characteristics(void)
  929. {
  930. int result;
  931. struct {
  932. struct chsc_header request;
  933. u32 reserved1;
  934. u32 reserved2;
  935. u32 reserved3;
  936. struct chsc_header response;
  937. u32 reserved4;
  938. u32 general_char[510];
  939. u32 chsc_char[518];
  940. } *scsc_area;
  941. scsc_area = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
  942. if (!scsc_area) {
  943. printk(KERN_WARNING"cio: Was not able to determine available" \
  944. "CHSCs due to no memory.\n");
  945. return -ENOMEM;
  946. }
  947. scsc_area->request = (struct chsc_header) {
  948. .length = 0x0010,
  949. .code = 0x0010,
  950. };
  951. result = chsc(scsc_area);
  952. if (result) {
  953. printk(KERN_WARNING"cio: Was not able to determine " \
  954. "available CHSCs, cc=%i.\n", result);
  955. result = -EIO;
  956. goto exit;
  957. }
  958. if (scsc_area->response.code != 1) {
  959. printk(KERN_WARNING"cio: Was not able to determine " \
  960. "available CHSCs.\n");
  961. result = -EIO;
  962. goto exit;
  963. }
  964. memcpy(&css_general_characteristics, scsc_area->general_char,
  965. sizeof(css_general_characteristics));
  966. memcpy(&css_chsc_characteristics, scsc_area->chsc_char,
  967. sizeof(css_chsc_characteristics));
  968. exit:
  969. free_page ((unsigned long) scsc_area);
  970. return result;
  971. }
  972. EXPORT_SYMBOL_GPL(css_general_characteristics);
  973. EXPORT_SYMBOL_GPL(css_chsc_characteristics);