chsc.c 25 KB

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