chsc.c 25 KB

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