chsc.c 26 KB

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