chsc.c 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110
  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->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. continue;
  362. }
  363. old_lpm = sch->lpm;
  364. sch->lpm = ((sch->schib.pmcw.pim &
  365. sch->schib.pmcw.pam &
  366. sch->schib.pmcw.pom)
  367. | chp_mask) & sch->opm;
  368. if (!old_lpm && sch->lpm)
  369. device_trigger_reprobe(sch);
  370. else if (sch->driver && sch->driver->verify)
  371. sch->driver->verify(&sch->dev);
  372. spin_unlock_irq(&sch->lock);
  373. put_device(&sch->dev);
  374. if (fla_mask == 0xffff)
  375. break;
  376. }
  377. return rc;
  378. }
  379. static int
  380. __get_chpid_from_lir(void *data)
  381. {
  382. struct lir {
  383. u8 iq;
  384. u8 ic;
  385. u16 sci;
  386. /* incident-node descriptor */
  387. u32 indesc[28];
  388. /* attached-node descriptor */
  389. u32 andesc[28];
  390. /* incident-specific information */
  391. u32 isinfo[28];
  392. } *lir;
  393. lir = (struct lir*) data;
  394. if (!(lir->iq&0x80))
  395. /* NULL link incident record */
  396. return -EINVAL;
  397. if (!(lir->indesc[0]&0xc0000000))
  398. /* node descriptor not valid */
  399. return -EINVAL;
  400. if (!(lir->indesc[0]&0x10000000))
  401. /* don't handle device-type nodes - FIXME */
  402. return -EINVAL;
  403. /* Byte 3 contains the chpid. Could also be CTCA, but we don't care */
  404. return (u16) (lir->indesc[0]&0x000000ff);
  405. }
  406. int
  407. chsc_process_crw(void)
  408. {
  409. int chpid, ret;
  410. struct {
  411. struct chsc_header request;
  412. u32 reserved1;
  413. u32 reserved2;
  414. u32 reserved3;
  415. struct chsc_header response;
  416. u32 reserved4;
  417. u8 flags;
  418. u8 vf; /* validity flags */
  419. u8 rs; /* reporting source */
  420. u8 cc; /* content code */
  421. u16 fla; /* full link address */
  422. u16 rsid; /* reporting source id */
  423. u32 reserved5;
  424. u32 reserved6;
  425. u32 ccdf[96]; /* content-code dependent field */
  426. /* ccdf has to be big enough for a link-incident record */
  427. } *sei_area;
  428. if (!sei_page)
  429. return 0;
  430. /*
  431. * build the chsc request block for store event information
  432. * and do the call
  433. * This function is only called by the machine check handler thread,
  434. * so we don't need locking for the sei_page.
  435. */
  436. sei_area = sei_page;
  437. CIO_TRACE_EVENT( 2, "prcss");
  438. ret = 0;
  439. do {
  440. int ccode, status;
  441. memset(sei_area, 0, sizeof(*sei_area));
  442. sei_area->request = (struct chsc_header) {
  443. .length = 0x0010,
  444. .code = 0x000e,
  445. };
  446. ccode = chsc(sei_area);
  447. if (ccode > 0)
  448. return 0;
  449. switch (sei_area->response.code) {
  450. /* for debug purposes, check for problems */
  451. case 0x0001:
  452. CIO_CRW_EVENT(4, "chsc_process_crw: event information "
  453. "successfully stored\n");
  454. break; /* everything ok */
  455. case 0x0002:
  456. CIO_CRW_EVENT(2,
  457. "chsc_process_crw: invalid command!\n");
  458. return 0;
  459. case 0x0003:
  460. CIO_CRW_EVENT(2, "chsc_process_crw: error in chsc "
  461. "request block!\n");
  462. return 0;
  463. case 0x0005:
  464. CIO_CRW_EVENT(2, "chsc_process_crw: no event "
  465. "information stored\n");
  466. return 0;
  467. default:
  468. CIO_CRW_EVENT(2, "chsc_process_crw: chsc response %d\n",
  469. sei_area->response.code);
  470. return 0;
  471. }
  472. /* Check if we might have lost some information. */
  473. if (sei_area->flags & 0x40)
  474. CIO_CRW_EVENT(2, "chsc_process_crw: Event information "
  475. "has been lost due to overflow!\n");
  476. if (sei_area->rs != 4) {
  477. CIO_CRW_EVENT(2, "chsc_process_crw: reporting source "
  478. "(%04X) isn't a chpid!\n",
  479. sei_area->rsid);
  480. continue;
  481. }
  482. /* which kind of information was stored? */
  483. switch (sei_area->cc) {
  484. case 1: /* link incident*/
  485. CIO_CRW_EVENT(4, "chsc_process_crw: "
  486. "channel subsystem reports link incident,"
  487. " reporting source is chpid %x\n",
  488. sei_area->rsid);
  489. chpid = __get_chpid_from_lir(sei_area->ccdf);
  490. if (chpid < 0)
  491. CIO_CRW_EVENT(4, "%s: Invalid LIR, skipping\n",
  492. __FUNCTION__);
  493. else
  494. s390_set_chpid_offline(chpid);
  495. break;
  496. case 2: /* i/o resource accessibiliy */
  497. CIO_CRW_EVENT(4, "chsc_process_crw: "
  498. "channel subsystem reports some I/O "
  499. "devices may have become accessible\n");
  500. pr_debug("Data received after sei: \n");
  501. pr_debug("Validity flags: %x\n", sei_area->vf);
  502. /* allocate a new channel path structure, if needed */
  503. status = get_chp_status(sei_area->rsid);
  504. if (status < 0)
  505. new_channel_path(sei_area->rsid);
  506. else if (!status)
  507. return 0;
  508. if ((sei_area->vf & 0x80) == 0) {
  509. pr_debug("chpid: %x\n", sei_area->rsid);
  510. ret = s390_process_res_acc(sei_area->rsid,
  511. 0, 0);
  512. } else if ((sei_area->vf & 0xc0) == 0x80) {
  513. pr_debug("chpid: %x link addr: %x\n",
  514. sei_area->rsid, sei_area->fla);
  515. ret = s390_process_res_acc(sei_area->rsid,
  516. sei_area->fla,
  517. 0xff00);
  518. } else if ((sei_area->vf & 0xc0) == 0xc0) {
  519. pr_debug("chpid: %x full link addr: %x\n",
  520. sei_area->rsid, sei_area->fla);
  521. ret = s390_process_res_acc(sei_area->rsid,
  522. sei_area->fla,
  523. 0xffff);
  524. }
  525. pr_debug("\n");
  526. break;
  527. default: /* other stuff */
  528. CIO_CRW_EVENT(4, "chsc_process_crw: event %d\n",
  529. sei_area->cc);
  530. break;
  531. }
  532. } while (sei_area->flags & 0x80);
  533. return ret;
  534. }
  535. static int
  536. chp_add(int chpid)
  537. {
  538. struct subchannel *sch;
  539. int irq, ret, rc;
  540. char dbf_txt[15];
  541. if (!get_chp_status(chpid))
  542. return 0; /* no need to do the rest */
  543. sprintf(dbf_txt, "cadd%x", chpid);
  544. CIO_TRACE_EVENT(2, dbf_txt);
  545. rc = 0;
  546. for (irq = 0; irq < __MAX_SUBCHANNELS; irq++) {
  547. int i;
  548. sch = get_subchannel_by_schid(irq);
  549. if (!sch) {
  550. struct schib schib;
  551. if (stsch(irq, &schib)) {
  552. /* We're through */
  553. if (need_rescan)
  554. rc = -EAGAIN;
  555. break;
  556. }
  557. if (need_rescan) {
  558. rc = -EAGAIN;
  559. continue;
  560. }
  561. /* Put it on the slow path. */
  562. ret = css_enqueue_subchannel_slow(irq);
  563. if (ret) {
  564. css_clear_subchannel_slow_list();
  565. need_rescan = 1;
  566. }
  567. rc = -EAGAIN;
  568. continue;
  569. }
  570. spin_lock(&sch->lock);
  571. for (i=0; i<8; i++)
  572. if (sch->schib.pmcw.chpid[i] == chpid) {
  573. if (stsch(sch->irq, &sch->schib) != 0) {
  574. /* Endgame. */
  575. spin_unlock(&sch->lock);
  576. return rc;
  577. }
  578. break;
  579. }
  580. if (i==8) {
  581. spin_unlock(&sch->lock);
  582. return rc;
  583. }
  584. sch->lpm = ((sch->schib.pmcw.pim &
  585. sch->schib.pmcw.pam &
  586. sch->schib.pmcw.pom)
  587. | 0x80 >> i) & sch->opm;
  588. if (sch->driver && sch->driver->verify)
  589. sch->driver->verify(&sch->dev);
  590. spin_unlock(&sch->lock);
  591. put_device(&sch->dev);
  592. }
  593. return rc;
  594. }
  595. /*
  596. * Handling of crw machine checks with channel path source.
  597. */
  598. int
  599. chp_process_crw(int chpid, int on)
  600. {
  601. if (on == 0) {
  602. /* Path has gone. We use the link incident routine.*/
  603. s390_set_chpid_offline(chpid);
  604. return 0; /* De-register is async anyway. */
  605. }
  606. /*
  607. * Path has come. Allocate a new channel path structure,
  608. * if needed.
  609. */
  610. if (get_chp_status(chpid) < 0)
  611. new_channel_path(chpid);
  612. /* Avoid the extra overhead in process_rec_acc. */
  613. return chp_add(chpid);
  614. }
  615. static inline int
  616. __check_for_io_and_kill(struct subchannel *sch, int index)
  617. {
  618. int cc;
  619. if (!device_is_online(sch))
  620. /* cio could be doing I/O. */
  621. return 0;
  622. cc = stsch(sch->irq, &sch->schib);
  623. if (cc)
  624. return 0;
  625. if (sch->schib.scsw.actl && sch->schib.pmcw.lpum == (0x80 >> index)) {
  626. device_set_waiting(sch);
  627. return 1;
  628. }
  629. return 0;
  630. }
  631. static inline void
  632. __s390_subchannel_vary_chpid(struct subchannel *sch, __u8 chpid, int on)
  633. {
  634. int chp, old_lpm;
  635. unsigned long flags;
  636. if (!sch->ssd_info.valid)
  637. return;
  638. spin_lock_irqsave(&sch->lock, flags);
  639. old_lpm = sch->lpm;
  640. for (chp = 0; chp < 8; chp++) {
  641. if (sch->ssd_info.chpid[chp] != chpid)
  642. continue;
  643. if (on) {
  644. sch->opm |= (0x80 >> chp);
  645. sch->lpm |= (0x80 >> chp);
  646. if (!old_lpm)
  647. device_trigger_reprobe(sch);
  648. else if (sch->driver && sch->driver->verify)
  649. sch->driver->verify(&sch->dev);
  650. } else {
  651. sch->opm &= ~(0x80 >> chp);
  652. sch->lpm &= ~(0x80 >> chp);
  653. /*
  654. * Give running I/O a grace period in which it
  655. * can successfully terminate, even using the
  656. * just varied off path. Then kill it.
  657. */
  658. if (!__check_for_io_and_kill(sch, chp) && !sch->lpm) {
  659. if (css_enqueue_subchannel_slow(sch->irq)) {
  660. css_clear_subchannel_slow_list();
  661. need_rescan = 1;
  662. }
  663. } else if (sch->driver && sch->driver->verify)
  664. sch->driver->verify(&sch->dev);
  665. }
  666. break;
  667. }
  668. spin_unlock_irqrestore(&sch->lock, flags);
  669. }
  670. static int
  671. s390_subchannel_vary_chpid_off(struct device *dev, void *data)
  672. {
  673. struct subchannel *sch;
  674. __u8 *chpid;
  675. sch = to_subchannel(dev);
  676. chpid = data;
  677. __s390_subchannel_vary_chpid(sch, *chpid, 0);
  678. return 0;
  679. }
  680. static int
  681. s390_subchannel_vary_chpid_on(struct device *dev, void *data)
  682. {
  683. struct subchannel *sch;
  684. __u8 *chpid;
  685. sch = to_subchannel(dev);
  686. chpid = data;
  687. __s390_subchannel_vary_chpid(sch, *chpid, 1);
  688. return 0;
  689. }
  690. /*
  691. * Function: s390_vary_chpid
  692. * Varies the specified chpid online or offline
  693. */
  694. static int
  695. s390_vary_chpid( __u8 chpid, int on)
  696. {
  697. char dbf_text[15];
  698. int status, irq, ret;
  699. struct subchannel *sch;
  700. sprintf(dbf_text, on?"varyon%x":"varyoff%x", chpid);
  701. CIO_TRACE_EVENT( 2, dbf_text);
  702. status = get_chp_status(chpid);
  703. if (status < 0) {
  704. printk(KERN_ERR "Can't vary unknown chpid %02X\n", chpid);
  705. return -EINVAL;
  706. }
  707. if (!on && !status) {
  708. printk(KERN_ERR "chpid %x is already offline\n", chpid);
  709. return -EINVAL;
  710. }
  711. set_chp_logically_online(chpid, on);
  712. /*
  713. * Redo PathVerification on the devices the chpid connects to
  714. */
  715. bus_for_each_dev(&css_bus_type, NULL, &chpid, on ?
  716. s390_subchannel_vary_chpid_on :
  717. s390_subchannel_vary_chpid_off);
  718. if (!on)
  719. goto out;
  720. /* Scan for new devices on varied on path. */
  721. for (irq = 0; irq < __MAX_SUBCHANNELS; irq++) {
  722. struct schib schib;
  723. if (need_rescan)
  724. break;
  725. sch = get_subchannel_by_schid(irq);
  726. if (sch) {
  727. put_device(&sch->dev);
  728. continue;
  729. }
  730. if (stsch(irq, &schib))
  731. /* We're through */
  732. break;
  733. /* Put it on the slow path. */
  734. ret = css_enqueue_subchannel_slow(irq);
  735. if (ret) {
  736. css_clear_subchannel_slow_list();
  737. need_rescan = 1;
  738. }
  739. }
  740. out:
  741. if (need_rescan || css_slow_subchannels_exist())
  742. queue_work(slow_path_wq, &slow_path_work);
  743. return 0;
  744. }
  745. /*
  746. * Files for the channel path entries.
  747. */
  748. static ssize_t
  749. chp_status_show(struct device *dev, struct device_attribute *attr, char *buf)
  750. {
  751. struct channel_path *chp = container_of(dev, struct channel_path, dev);
  752. if (!chp)
  753. return 0;
  754. return (get_chp_status(chp->id) ? sprintf(buf, "online\n") :
  755. sprintf(buf, "offline\n"));
  756. }
  757. static ssize_t
  758. chp_status_write(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  759. {
  760. struct channel_path *cp = container_of(dev, struct channel_path, dev);
  761. char cmd[10];
  762. int num_args;
  763. int error;
  764. num_args = sscanf(buf, "%5s", cmd);
  765. if (!num_args)
  766. return count;
  767. if (!strnicmp(cmd, "on", 2))
  768. error = s390_vary_chpid(cp->id, 1);
  769. else if (!strnicmp(cmd, "off", 3))
  770. error = s390_vary_chpid(cp->id, 0);
  771. else
  772. error = -EINVAL;
  773. return error < 0 ? error : count;
  774. }
  775. static DEVICE_ATTR(status, 0644, chp_status_show, chp_status_write);
  776. static ssize_t
  777. chp_type_show(struct device *dev, struct device_attribute *attr, char *buf)
  778. {
  779. struct channel_path *chp = container_of(dev, struct channel_path, dev);
  780. if (!chp)
  781. return 0;
  782. return sprintf(buf, "%x\n", chp->desc.desc);
  783. }
  784. static DEVICE_ATTR(type, 0444, chp_type_show, NULL);
  785. static struct attribute * chp_attrs[] = {
  786. &dev_attr_status.attr,
  787. &dev_attr_type.attr,
  788. NULL,
  789. };
  790. static struct attribute_group chp_attr_group = {
  791. .attrs = chp_attrs,
  792. };
  793. static void
  794. chp_release(struct device *dev)
  795. {
  796. struct channel_path *cp;
  797. cp = container_of(dev, struct channel_path, dev);
  798. kfree(cp);
  799. }
  800. static int
  801. chsc_determine_channel_path_description(int chpid,
  802. struct channel_path_desc *desc)
  803. {
  804. int ccode, ret;
  805. struct {
  806. struct chsc_header request;
  807. u32 : 24;
  808. u32 first_chpid : 8;
  809. u32 : 24;
  810. u32 last_chpid : 8;
  811. u32 zeroes1;
  812. struct chsc_header response;
  813. u32 zeroes2;
  814. struct channel_path_desc desc;
  815. } *scpd_area;
  816. scpd_area = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
  817. if (!scpd_area)
  818. return -ENOMEM;
  819. scpd_area->request = (struct chsc_header) {
  820. .length = 0x0010,
  821. .code = 0x0002,
  822. };
  823. scpd_area->first_chpid = chpid;
  824. scpd_area->last_chpid = chpid;
  825. ccode = chsc(scpd_area);
  826. if (ccode > 0) {
  827. ret = (ccode == 3) ? -ENODEV : -EBUSY;
  828. goto out;
  829. }
  830. switch (scpd_area->response.code) {
  831. case 0x0001: /* Success. */
  832. memcpy(desc, &scpd_area->desc,
  833. sizeof(struct channel_path_desc));
  834. ret = 0;
  835. break;
  836. case 0x0003: /* Invalid block. */
  837. case 0x0007: /* Invalid format. */
  838. case 0x0008: /* Other invalid block. */
  839. CIO_CRW_EVENT(2, "Error in chsc request block!\n");
  840. ret = -EINVAL;
  841. break;
  842. case 0x0004: /* Command not provided in model. */
  843. CIO_CRW_EVENT(2, "Model does not provide scpd\n");
  844. ret = -EOPNOTSUPP;
  845. break;
  846. default:
  847. CIO_CRW_EVENT(2, "Unknown CHSC response %d\n",
  848. scpd_area->response.code);
  849. ret = -EIO;
  850. }
  851. out:
  852. free_page((unsigned long)scpd_area);
  853. return ret;
  854. }
  855. /*
  856. * Entries for chpids on the system bus.
  857. * This replaces /proc/chpids.
  858. */
  859. static int
  860. new_channel_path(int chpid)
  861. {
  862. struct channel_path *chp;
  863. int ret;
  864. chp = kmalloc(sizeof(struct channel_path), GFP_KERNEL);
  865. if (!chp)
  866. return -ENOMEM;
  867. memset(chp, 0, sizeof(struct channel_path));
  868. /* fill in status, etc. */
  869. chp->id = chpid;
  870. chp->state = 1;
  871. chp->dev = (struct device) {
  872. .parent = &css_bus_device,
  873. .release = chp_release,
  874. };
  875. snprintf(chp->dev.bus_id, BUS_ID_SIZE, "chp0.%x", chpid);
  876. /* Obtain channel path description and fill it in. */
  877. ret = chsc_determine_channel_path_description(chpid, &chp->desc);
  878. if (ret)
  879. goto out_free;
  880. /* make it known to the system */
  881. ret = device_register(&chp->dev);
  882. if (ret) {
  883. printk(KERN_WARNING "%s: could not register %02x\n",
  884. __func__, chpid);
  885. goto out_free;
  886. }
  887. ret = sysfs_create_group(&chp->dev.kobj, &chp_attr_group);
  888. if (ret) {
  889. device_unregister(&chp->dev);
  890. goto out_free;
  891. } else
  892. chps[chpid] = chp;
  893. return ret;
  894. out_free:
  895. kfree(chp);
  896. return ret;
  897. }
  898. void *
  899. chsc_get_chp_desc(struct subchannel *sch, int chp_no)
  900. {
  901. struct channel_path *chp;
  902. struct channel_path_desc *desc;
  903. chp = chps[sch->schib.pmcw.chpid[chp_no]];
  904. if (!chp)
  905. return NULL;
  906. desc = kmalloc(sizeof(struct channel_path_desc), GFP_KERNEL);
  907. if (!desc)
  908. return NULL;
  909. memcpy(desc, &chp->desc, sizeof(struct channel_path_desc));
  910. return desc;
  911. }
  912. static int __init
  913. chsc_alloc_sei_area(void)
  914. {
  915. sei_page = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
  916. if (!sei_page)
  917. printk(KERN_WARNING"Can't allocate page for processing of " \
  918. "chsc machine checks!\n");
  919. return (sei_page ? 0 : -ENOMEM);
  920. }
  921. subsys_initcall(chsc_alloc_sei_area);
  922. struct css_general_char css_general_characteristics;
  923. struct css_chsc_char css_chsc_characteristics;
  924. int __init
  925. chsc_determine_css_characteristics(void)
  926. {
  927. int result;
  928. struct {
  929. struct chsc_header request;
  930. u32 reserved1;
  931. u32 reserved2;
  932. u32 reserved3;
  933. struct chsc_header response;
  934. u32 reserved4;
  935. u32 general_char[510];
  936. u32 chsc_char[518];
  937. } *scsc_area;
  938. scsc_area = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
  939. if (!scsc_area) {
  940. printk(KERN_WARNING"cio: Was not able to determine available" \
  941. "CHSCs due to no memory.\n");
  942. return -ENOMEM;
  943. }
  944. scsc_area->request = (struct chsc_header) {
  945. .length = 0x0010,
  946. .code = 0x0010,
  947. };
  948. result = chsc(scsc_area);
  949. if (result) {
  950. printk(KERN_WARNING"cio: Was not able to determine " \
  951. "available CHSCs, cc=%i.\n", result);
  952. result = -EIO;
  953. goto exit;
  954. }
  955. if (scsc_area->response.code != 1) {
  956. printk(KERN_WARNING"cio: Was not able to determine " \
  957. "available CHSCs.\n");
  958. result = -EIO;
  959. goto exit;
  960. }
  961. memcpy(&css_general_characteristics, scsc_area->general_char,
  962. sizeof(css_general_characteristics));
  963. memcpy(&css_chsc_characteristics, scsc_area->chsc_char,
  964. sizeof(css_chsc_characteristics));
  965. exit:
  966. free_page ((unsigned long) scsc_area);
  967. return result;
  968. }
  969. EXPORT_SYMBOL_GPL(css_general_characteristics);
  970. EXPORT_SYMBOL_GPL(css_chsc_characteristics);