chsc.c 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584
  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.length = 0x0010;
  87. ssd_area->request.code = 0x0004;
  88. ssd_area->ssid = sch->schid.ssid;
  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 0.%x.%04x\n", ssd_area->st,
  130. sch->schid.ssid, 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 0.%x.%04x is %s subchannel\n",
  140. sch->schid.ssid, sch->schid.sch_no,
  141. 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. struct channel_path *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->id)
  202. break;
  203. if (j >= 8)
  204. return 0;
  205. mask = 0x80 >> j;
  206. spin_lock_irq(&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_DEVACT) &&
  217. (sch->schib.scsw.actl & SCSW_ACTL_SCHACT) &&
  218. (sch->schib.pmcw.lpum == mask) &&
  219. (sch->vpm == 0)) {
  220. int cc;
  221. cc = cio_clear(sch);
  222. if (cc == -ENODEV)
  223. goto out_unreg;
  224. /* Call handler. */
  225. if (sch->driver && sch->driver->termination)
  226. sch->driver->termination(&sch->dev);
  227. goto out_unlock;
  228. }
  229. /* trigger path verification. */
  230. if (sch->driver && sch->driver->verify)
  231. sch->driver->verify(&sch->dev);
  232. out_unlock:
  233. spin_unlock_irq(&sch->lock);
  234. return 0;
  235. out_unreg:
  236. spin_unlock_irq(&sch->lock);
  237. sch->lpm = 0;
  238. if (css_enqueue_subchannel_slow(sch->schid)) {
  239. css_clear_subchannel_slow_list();
  240. need_rescan = 1;
  241. }
  242. return 0;
  243. }
  244. static inline void
  245. s390_set_chpid_offline( __u8 chpid)
  246. {
  247. char dbf_txt[15];
  248. struct device *dev;
  249. sprintf(dbf_txt, "chpr%x", chpid);
  250. CIO_TRACE_EVENT(2, dbf_txt);
  251. if (get_chp_status(chpid) <= 0)
  252. return;
  253. dev = get_device(&css[0]->chps[chpid]->dev);
  254. bus_for_each_dev(&css_bus_type, NULL, to_channelpath(dev),
  255. s390_subchannel_remove_chpid);
  256. if (need_rescan || css_slow_subchannels_exist())
  257. queue_work(slow_path_wq, &slow_path_work);
  258. put_device(dev);
  259. }
  260. struct res_acc_data {
  261. struct channel_path *chp;
  262. u32 fla_mask;
  263. u16 fla;
  264. };
  265. static int
  266. s390_process_res_acc_sch(struct res_acc_data *res_data, struct subchannel *sch)
  267. {
  268. int found;
  269. int chp;
  270. int ccode;
  271. found = 0;
  272. for (chp = 0; chp <= 7; chp++)
  273. /*
  274. * check if chpid is in information updated by ssd
  275. */
  276. if (sch->ssd_info.valid &&
  277. sch->ssd_info.chpid[chp] == res_data->chp->id &&
  278. (sch->ssd_info.fla[chp] & res_data->fla_mask)
  279. == res_data->fla) {
  280. found = 1;
  281. break;
  282. }
  283. if (found == 0)
  284. return 0;
  285. /*
  286. * Do a stsch to update our subchannel structure with the
  287. * new path information and eventually check for logically
  288. * offline chpids.
  289. */
  290. ccode = stsch(sch->schid, &sch->schib);
  291. if (ccode > 0)
  292. return 0;
  293. return 0x80 >> chp;
  294. }
  295. static inline int
  296. s390_process_res_acc_new_sch(struct subchannel_id schid)
  297. {
  298. struct schib schib;
  299. int ret;
  300. /*
  301. * We don't know the device yet, but since a path
  302. * may be available now to the device we'll have
  303. * to do recognition again.
  304. * Since we don't have any idea about which chpid
  305. * that beast may be on we'll have to do a stsch
  306. * on all devices, grr...
  307. */
  308. if (stsch_err(schid, &schib))
  309. /* We're through */
  310. return need_rescan ? -EAGAIN : -ENXIO;
  311. /* Put it on the slow path. */
  312. ret = css_enqueue_subchannel_slow(schid);
  313. if (ret) {
  314. css_clear_subchannel_slow_list();
  315. need_rescan = 1;
  316. return -EAGAIN;
  317. }
  318. return 0;
  319. }
  320. static int
  321. __s390_process_res_acc(struct subchannel_id schid, void *data)
  322. {
  323. int chp_mask, old_lpm;
  324. struct res_acc_data *res_data;
  325. struct subchannel *sch;
  326. res_data = (struct res_acc_data *)data;
  327. sch = get_subchannel_by_schid(schid);
  328. if (!sch)
  329. /* Check if a subchannel is newly available. */
  330. return s390_process_res_acc_new_sch(schid);
  331. spin_lock_irq(&sch->lock);
  332. chp_mask = s390_process_res_acc_sch(res_data, sch);
  333. if (chp_mask == 0) {
  334. spin_unlock_irq(&sch->lock);
  335. return 0;
  336. }
  337. old_lpm = sch->lpm;
  338. sch->lpm = ((sch->schib.pmcw.pim &
  339. sch->schib.pmcw.pam &
  340. sch->schib.pmcw.pom)
  341. | chp_mask) & sch->opm;
  342. if (!old_lpm && sch->lpm)
  343. device_trigger_reprobe(sch);
  344. else if (sch->driver && sch->driver->verify)
  345. sch->driver->verify(&sch->dev);
  346. spin_unlock_irq(&sch->lock);
  347. put_device(&sch->dev);
  348. return (res_data->fla_mask == 0xffff) ? -ENODEV : 0;
  349. }
  350. static int
  351. s390_process_res_acc (struct res_acc_data *res_data)
  352. {
  353. int rc;
  354. char dbf_txt[15];
  355. sprintf(dbf_txt, "accpr%x", res_data->chp->id);
  356. CIO_TRACE_EVENT( 2, dbf_txt);
  357. if (res_data->fla != 0) {
  358. sprintf(dbf_txt, "fla%x", res_data->fla);
  359. CIO_TRACE_EVENT( 2, dbf_txt);
  360. }
  361. /*
  362. * I/O resources may have become accessible.
  363. * Scan through all subchannels that may be concerned and
  364. * do a validation on those.
  365. * The more information we have (info), the less scanning
  366. * will we have to do.
  367. */
  368. rc = for_each_subchannel(__s390_process_res_acc, res_data);
  369. if (css_slow_subchannels_exist())
  370. rc = -EAGAIN;
  371. else if (rc != -EAGAIN)
  372. rc = 0;
  373. return rc;
  374. }
  375. static int
  376. __get_chpid_from_lir(void *data)
  377. {
  378. struct lir {
  379. u8 iq;
  380. u8 ic;
  381. u16 sci;
  382. /* incident-node descriptor */
  383. u32 indesc[28];
  384. /* attached-node descriptor */
  385. u32 andesc[28];
  386. /* incident-specific information */
  387. u32 isinfo[28];
  388. } *lir;
  389. lir = (struct lir*) data;
  390. if (!(lir->iq&0x80))
  391. /* NULL link incident record */
  392. return -EINVAL;
  393. if (!(lir->indesc[0]&0xc0000000))
  394. /* node descriptor not valid */
  395. return -EINVAL;
  396. if (!(lir->indesc[0]&0x10000000))
  397. /* don't handle device-type nodes - FIXME */
  398. return -EINVAL;
  399. /* Byte 3 contains the chpid. Could also be CTCA, but we don't care */
  400. return (u16) (lir->indesc[0]&0x000000ff);
  401. }
  402. int
  403. chsc_process_crw(void)
  404. {
  405. int chpid, ret;
  406. struct res_acc_data res_data;
  407. struct {
  408. struct chsc_header request;
  409. u32 reserved1;
  410. u32 reserved2;
  411. u32 reserved3;
  412. struct chsc_header response;
  413. u32 reserved4;
  414. u8 flags;
  415. u8 vf; /* validity flags */
  416. u8 rs; /* reporting source */
  417. u8 cc; /* content code */
  418. u16 fla; /* full link address */
  419. u16 rsid; /* reporting source id */
  420. u32 reserved5;
  421. u32 reserved6;
  422. u32 ccdf[96]; /* content-code dependent field */
  423. /* ccdf has to be big enough for a link-incident record */
  424. } *sei_area;
  425. if (!sei_page)
  426. return 0;
  427. /*
  428. * build the chsc request block for store event information
  429. * and do the call
  430. * This function is only called by the machine check handler thread,
  431. * so we don't need locking for the sei_page.
  432. */
  433. sei_area = sei_page;
  434. CIO_TRACE_EVENT( 2, "prcss");
  435. ret = 0;
  436. do {
  437. int ccode, status;
  438. struct device *dev;
  439. memset(sei_area, 0, sizeof(*sei_area));
  440. memset(&res_data, 0, sizeof(struct res_acc_data));
  441. sei_area->request.length = 0x0010;
  442. sei_area->request.code = 0x000e;
  443. ccode = chsc(sei_area);
  444. if (ccode > 0)
  445. return 0;
  446. switch (sei_area->response.code) {
  447. /* for debug purposes, check for problems */
  448. case 0x0001:
  449. CIO_CRW_EVENT(4, "chsc_process_crw: event information "
  450. "successfully stored\n");
  451. break; /* everything ok */
  452. case 0x0002:
  453. CIO_CRW_EVENT(2,
  454. "chsc_process_crw: invalid command!\n");
  455. return 0;
  456. case 0x0003:
  457. CIO_CRW_EVENT(2, "chsc_process_crw: error in chsc "
  458. "request block!\n");
  459. return 0;
  460. case 0x0005:
  461. CIO_CRW_EVENT(2, "chsc_process_crw: no event "
  462. "information stored\n");
  463. return 0;
  464. default:
  465. CIO_CRW_EVENT(2, "chsc_process_crw: chsc response %d\n",
  466. sei_area->response.code);
  467. return 0;
  468. }
  469. /* Check if we might have lost some information. */
  470. if (sei_area->flags & 0x40)
  471. CIO_CRW_EVENT(2, "chsc_process_crw: Event information "
  472. "has been lost due to overflow!\n");
  473. if (sei_area->rs != 4) {
  474. CIO_CRW_EVENT(2, "chsc_process_crw: reporting source "
  475. "(%04X) isn't a chpid!\n",
  476. sei_area->rsid);
  477. continue;
  478. }
  479. /* which kind of information was stored? */
  480. switch (sei_area->cc) {
  481. case 1: /* link incident*/
  482. CIO_CRW_EVENT(4, "chsc_process_crw: "
  483. "channel subsystem reports link incident,"
  484. " reporting source is chpid %x\n",
  485. sei_area->rsid);
  486. chpid = __get_chpid_from_lir(sei_area->ccdf);
  487. if (chpid < 0)
  488. CIO_CRW_EVENT(4, "%s: Invalid LIR, skipping\n",
  489. __FUNCTION__);
  490. else
  491. s390_set_chpid_offline(chpid);
  492. break;
  493. case 2: /* i/o resource accessibiliy */
  494. CIO_CRW_EVENT(4, "chsc_process_crw: "
  495. "channel subsystem reports some I/O "
  496. "devices may have become accessible\n");
  497. pr_debug("Data received after sei: \n");
  498. pr_debug("Validity flags: %x\n", sei_area->vf);
  499. /* allocate a new channel path structure, if needed */
  500. status = get_chp_status(sei_area->rsid);
  501. if (status < 0)
  502. new_channel_path(sei_area->rsid);
  503. else if (!status)
  504. break;
  505. dev = get_device(&css[0]->chps[sei_area->rsid]->dev);
  506. res_data.chp = to_channelpath(dev);
  507. pr_debug("chpid: %x", sei_area->rsid);
  508. if ((sei_area->vf & 0xc0) != 0) {
  509. res_data.fla = sei_area->fla;
  510. if ((sei_area->vf & 0xc0) == 0xc0) {
  511. pr_debug(" full link addr: %x",
  512. sei_area->fla);
  513. res_data.fla_mask = 0xffff;
  514. } else {
  515. pr_debug(" link addr: %x",
  516. sei_area->fla);
  517. res_data.fla_mask = 0xff00;
  518. }
  519. }
  520. ret = s390_process_res_acc(&res_data);
  521. pr_debug("\n\n");
  522. put_device(dev);
  523. break;
  524. default: /* other stuff */
  525. CIO_CRW_EVENT(4, "chsc_process_crw: event %d\n",
  526. sei_area->cc);
  527. break;
  528. }
  529. } while (sei_area->flags & 0x80);
  530. return ret;
  531. }
  532. static inline int
  533. __chp_add_new_sch(struct subchannel_id schid)
  534. {
  535. struct schib schib;
  536. int ret;
  537. if (stsch(schid, &schib))
  538. /* We're through */
  539. return need_rescan ? -EAGAIN : -ENXIO;
  540. /* Put it on the slow path. */
  541. ret = css_enqueue_subchannel_slow(schid);
  542. if (ret) {
  543. css_clear_subchannel_slow_list();
  544. need_rescan = 1;
  545. return -EAGAIN;
  546. }
  547. return 0;
  548. }
  549. static int
  550. __chp_add(struct subchannel_id schid, void *data)
  551. {
  552. int i;
  553. struct channel_path *chp;
  554. struct subchannel *sch;
  555. chp = (struct channel_path *)data;
  556. sch = get_subchannel_by_schid(schid);
  557. if (!sch)
  558. /* Check if the subchannel is now available. */
  559. return __chp_add_new_sch(schid);
  560. spin_lock_irq(&sch->lock);
  561. for (i=0; i<8; i++)
  562. if (sch->schib.pmcw.chpid[i] == chp->id) {
  563. if (stsch(sch->schid, &sch->schib) != 0) {
  564. /* Endgame. */
  565. spin_unlock(&sch->lock);
  566. return -ENXIO;
  567. }
  568. break;
  569. }
  570. if (i==8) {
  571. spin_unlock(&sch->lock);
  572. return 0;
  573. }
  574. sch->lpm = ((sch->schib.pmcw.pim &
  575. sch->schib.pmcw.pam &
  576. sch->schib.pmcw.pom)
  577. | 0x80 >> i) & sch->opm;
  578. if (sch->driver && sch->driver->verify)
  579. sch->driver->verify(&sch->dev);
  580. spin_unlock_irq(&sch->lock);
  581. put_device(&sch->dev);
  582. return 0;
  583. }
  584. static int
  585. chp_add(int chpid)
  586. {
  587. int rc;
  588. char dbf_txt[15];
  589. struct device *dev;
  590. if (!get_chp_status(chpid))
  591. return 0; /* no need to do the rest */
  592. sprintf(dbf_txt, "cadd%x", chpid);
  593. CIO_TRACE_EVENT(2, dbf_txt);
  594. dev = get_device(&css[0]->chps[chpid]->dev);
  595. rc = for_each_subchannel(__chp_add, to_channelpath(dev));
  596. if (css_slow_subchannels_exist())
  597. rc = -EAGAIN;
  598. if (rc != -EAGAIN)
  599. rc = 0;
  600. put_device(dev);
  601. return rc;
  602. }
  603. /*
  604. * Handling of crw machine checks with channel path source.
  605. */
  606. int
  607. chp_process_crw(int chpid, int on)
  608. {
  609. if (on == 0) {
  610. /* Path has gone. We use the link incident routine.*/
  611. s390_set_chpid_offline(chpid);
  612. return 0; /* De-register is async anyway. */
  613. }
  614. /*
  615. * Path has come. Allocate a new channel path structure,
  616. * if needed.
  617. */
  618. if (get_chp_status(chpid) < 0)
  619. new_channel_path(chpid);
  620. /* Avoid the extra overhead in process_rec_acc. */
  621. return chp_add(chpid);
  622. }
  623. static inline int
  624. __check_for_io_and_kill(struct subchannel *sch, int index)
  625. {
  626. int cc;
  627. if (!device_is_online(sch))
  628. /* cio could be doing I/O. */
  629. return 0;
  630. cc = stsch(sch->schid, &sch->schib);
  631. if (cc)
  632. return 0;
  633. if (sch->schib.scsw.actl && sch->schib.pmcw.lpum == (0x80 >> index)) {
  634. device_set_waiting(sch);
  635. return 1;
  636. }
  637. return 0;
  638. }
  639. static inline void
  640. __s390_subchannel_vary_chpid(struct subchannel *sch, __u8 chpid, int on)
  641. {
  642. int chp, old_lpm;
  643. unsigned long flags;
  644. if (!sch->ssd_info.valid)
  645. return;
  646. spin_lock_irqsave(&sch->lock, flags);
  647. old_lpm = sch->lpm;
  648. for (chp = 0; chp < 8; chp++) {
  649. if (sch->ssd_info.chpid[chp] != chpid)
  650. continue;
  651. if (on) {
  652. sch->opm |= (0x80 >> chp);
  653. sch->lpm |= (0x80 >> chp);
  654. if (!old_lpm)
  655. device_trigger_reprobe(sch);
  656. else if (sch->driver && sch->driver->verify)
  657. sch->driver->verify(&sch->dev);
  658. } else {
  659. sch->opm &= ~(0x80 >> chp);
  660. sch->lpm &= ~(0x80 >> chp);
  661. /*
  662. * Give running I/O a grace period in which it
  663. * can successfully terminate, even using the
  664. * just varied off path. Then kill it.
  665. */
  666. if (!__check_for_io_and_kill(sch, chp) && !sch->lpm) {
  667. if (css_enqueue_subchannel_slow(sch->schid)) {
  668. css_clear_subchannel_slow_list();
  669. need_rescan = 1;
  670. }
  671. } else if (sch->driver && sch->driver->verify)
  672. sch->driver->verify(&sch->dev);
  673. }
  674. break;
  675. }
  676. spin_unlock_irqrestore(&sch->lock, flags);
  677. }
  678. static int
  679. s390_subchannel_vary_chpid_off(struct device *dev, void *data)
  680. {
  681. struct subchannel *sch;
  682. __u8 *chpid;
  683. sch = to_subchannel(dev);
  684. chpid = data;
  685. __s390_subchannel_vary_chpid(sch, *chpid, 0);
  686. return 0;
  687. }
  688. static int
  689. s390_subchannel_vary_chpid_on(struct device *dev, void *data)
  690. {
  691. struct subchannel *sch;
  692. __u8 *chpid;
  693. sch = to_subchannel(dev);
  694. chpid = data;
  695. __s390_subchannel_vary_chpid(sch, *chpid, 1);
  696. return 0;
  697. }
  698. static int
  699. __s390_vary_chpid_on(struct subchannel_id schid, void *data)
  700. {
  701. struct schib schib;
  702. struct subchannel *sch;
  703. sch = get_subchannel_by_schid(schid);
  704. if (sch) {
  705. put_device(&sch->dev);
  706. return 0;
  707. }
  708. if (stsch_err(schid, &schib))
  709. /* We're through */
  710. return -ENXIO;
  711. /* Put it on the slow path. */
  712. if (css_enqueue_subchannel_slow(schid)) {
  713. css_clear_subchannel_slow_list();
  714. need_rescan = 1;
  715. return -EAGAIN;
  716. }
  717. return 0;
  718. }
  719. /*
  720. * Function: s390_vary_chpid
  721. * Varies the specified chpid online or offline
  722. */
  723. static int
  724. s390_vary_chpid( __u8 chpid, int on)
  725. {
  726. char dbf_text[15];
  727. int status;
  728. sprintf(dbf_text, on?"varyon%x":"varyoff%x", chpid);
  729. CIO_TRACE_EVENT( 2, dbf_text);
  730. status = get_chp_status(chpid);
  731. if (status < 0) {
  732. printk(KERN_ERR "Can't vary unknown chpid %02X\n", chpid);
  733. return -EINVAL;
  734. }
  735. if (!on && !status) {
  736. printk(KERN_ERR "chpid %x is already offline\n", chpid);
  737. return -EINVAL;
  738. }
  739. set_chp_logically_online(chpid, on);
  740. /*
  741. * Redo PathVerification on the devices the chpid connects to
  742. */
  743. bus_for_each_dev(&css_bus_type, NULL, &chpid, on ?
  744. s390_subchannel_vary_chpid_on :
  745. s390_subchannel_vary_chpid_off);
  746. if (on)
  747. /* Scan for new devices on varied on path. */
  748. for_each_subchannel(__s390_vary_chpid_on, NULL);
  749. if (need_rescan || css_slow_subchannels_exist())
  750. queue_work(slow_path_wq, &slow_path_work);
  751. return 0;
  752. }
  753. /*
  754. * Channel measurement related functions
  755. */
  756. static ssize_t
  757. chp_measurement_chars_read(struct kobject *kobj, char *buf, loff_t off,
  758. size_t count)
  759. {
  760. struct channel_path *chp;
  761. unsigned int size;
  762. chp = to_channelpath(container_of(kobj, struct device, kobj));
  763. if (!chp->cmg_chars)
  764. return 0;
  765. size = sizeof(struct cmg_chars);
  766. if (off > size)
  767. return 0;
  768. if (off + count > size)
  769. count = size - off;
  770. memcpy(buf, chp->cmg_chars + off, count);
  771. return count;
  772. }
  773. static struct bin_attribute chp_measurement_chars_attr = {
  774. .attr = {
  775. .name = "measurement_chars",
  776. .mode = S_IRUSR,
  777. .owner = THIS_MODULE,
  778. },
  779. .size = sizeof(struct cmg_chars),
  780. .read = chp_measurement_chars_read,
  781. };
  782. static void
  783. chp_measurement_copy_block(struct cmg_entry *buf,
  784. struct channel_subsystem *css, int chpid)
  785. {
  786. void *area;
  787. struct cmg_entry *entry, reference_buf;
  788. int idx;
  789. if (chpid < 128) {
  790. area = css->cub_addr1;
  791. idx = chpid;
  792. } else {
  793. area = css->cub_addr2;
  794. idx = chpid - 128;
  795. }
  796. entry = area + (idx * sizeof(struct cmg_entry));
  797. do {
  798. memcpy(buf, entry, sizeof(*entry));
  799. memcpy(&reference_buf, entry, sizeof(*entry));
  800. } while (reference_buf.values[0] != buf->values[0]);
  801. }
  802. static ssize_t
  803. chp_measurement_read(struct kobject *kobj, char *buf, loff_t off, size_t count)
  804. {
  805. struct channel_path *chp;
  806. struct channel_subsystem *css;
  807. unsigned int size;
  808. chp = to_channelpath(container_of(kobj, struct device, kobj));
  809. css = to_css(chp->dev.parent);
  810. size = sizeof(struct cmg_chars);
  811. /* Only allow single reads. */
  812. if (off || count < size)
  813. return 0;
  814. chp_measurement_copy_block((struct cmg_entry *)buf, css, chp->id);
  815. return count;
  816. }
  817. static struct bin_attribute chp_measurement_attr = {
  818. .attr = {
  819. .name = "measurement",
  820. .mode = S_IRUSR,
  821. .owner = THIS_MODULE,
  822. },
  823. .size = sizeof(struct cmg_entry),
  824. .read = chp_measurement_read,
  825. };
  826. static void
  827. chsc_remove_chp_cmg_attr(struct channel_path *chp)
  828. {
  829. sysfs_remove_bin_file(&chp->dev.kobj, &chp_measurement_chars_attr);
  830. sysfs_remove_bin_file(&chp->dev.kobj, &chp_measurement_attr);
  831. }
  832. static int
  833. chsc_add_chp_cmg_attr(struct channel_path *chp)
  834. {
  835. int ret;
  836. ret = sysfs_create_bin_file(&chp->dev.kobj,
  837. &chp_measurement_chars_attr);
  838. if (ret)
  839. return ret;
  840. ret = sysfs_create_bin_file(&chp->dev.kobj, &chp_measurement_attr);
  841. if (ret)
  842. sysfs_remove_bin_file(&chp->dev.kobj,
  843. &chp_measurement_chars_attr);
  844. return ret;
  845. }
  846. static void
  847. chsc_remove_cmg_attr(struct channel_subsystem *css)
  848. {
  849. int i;
  850. for (i = 0; i <= __MAX_CHPID; i++) {
  851. if (!css->chps[i])
  852. continue;
  853. chsc_remove_chp_cmg_attr(css->chps[i]);
  854. }
  855. }
  856. static int
  857. chsc_add_cmg_attr(struct channel_subsystem *css)
  858. {
  859. int i, ret;
  860. ret = 0;
  861. for (i = 0; i <= __MAX_CHPID; i++) {
  862. if (!css->chps[i])
  863. continue;
  864. ret = chsc_add_chp_cmg_attr(css->chps[i]);
  865. if (ret)
  866. goto cleanup;
  867. }
  868. return ret;
  869. cleanup:
  870. for (--i; i >= 0; i--) {
  871. if (!css->chps[i])
  872. continue;
  873. chsc_remove_chp_cmg_attr(css->chps[i]);
  874. }
  875. return ret;
  876. }
  877. static int
  878. __chsc_do_secm(struct channel_subsystem *css, int enable, void *page)
  879. {
  880. struct {
  881. struct chsc_header request;
  882. u32 operation_code : 2;
  883. u32 : 30;
  884. u32 key : 4;
  885. u32 : 28;
  886. u32 zeroes1;
  887. u32 cub_addr1;
  888. u32 zeroes2;
  889. u32 cub_addr2;
  890. u32 reserved[13];
  891. struct chsc_header response;
  892. u32 status : 8;
  893. u32 : 4;
  894. u32 fmt : 4;
  895. u32 : 16;
  896. } *secm_area;
  897. int ret, ccode;
  898. secm_area = page;
  899. secm_area->request.length = 0x0050;
  900. secm_area->request.code = 0x0016;
  901. secm_area->key = PAGE_DEFAULT_KEY;
  902. secm_area->cub_addr1 = (u64)(unsigned long)css->cub_addr1;
  903. secm_area->cub_addr2 = (u64)(unsigned long)css->cub_addr2;
  904. secm_area->operation_code = enable ? 0 : 1;
  905. ccode = chsc(secm_area);
  906. if (ccode > 0)
  907. return (ccode == 3) ? -ENODEV : -EBUSY;
  908. switch (secm_area->response.code) {
  909. case 0x0001: /* Success. */
  910. ret = 0;
  911. break;
  912. case 0x0003: /* Invalid block. */
  913. case 0x0007: /* Invalid format. */
  914. case 0x0008: /* Other invalid block. */
  915. CIO_CRW_EVENT(2, "Error in chsc request block!\n");
  916. ret = -EINVAL;
  917. break;
  918. case 0x0004: /* Command not provided in model. */
  919. CIO_CRW_EVENT(2, "Model does not provide secm\n");
  920. ret = -EOPNOTSUPP;
  921. break;
  922. case 0x0102: /* cub adresses incorrect */
  923. CIO_CRW_EVENT(2, "Invalid addresses in chsc request block\n");
  924. ret = -EINVAL;
  925. break;
  926. case 0x0103: /* key error */
  927. CIO_CRW_EVENT(2, "Access key error in secm\n");
  928. ret = -EINVAL;
  929. break;
  930. case 0x0105: /* error while starting */
  931. CIO_CRW_EVENT(2, "Error while starting channel measurement\n");
  932. ret = -EIO;
  933. break;
  934. default:
  935. CIO_CRW_EVENT(2, "Unknown CHSC response %d\n",
  936. secm_area->response.code);
  937. ret = -EIO;
  938. }
  939. return ret;
  940. }
  941. int
  942. chsc_secm(struct channel_subsystem *css, int enable)
  943. {
  944. void *secm_area;
  945. int ret;
  946. secm_area = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
  947. if (!secm_area)
  948. return -ENOMEM;
  949. mutex_lock(&css->mutex);
  950. if (enable && !css->cm_enabled) {
  951. css->cub_addr1 = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
  952. css->cub_addr2 = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
  953. if (!css->cub_addr1 || !css->cub_addr2) {
  954. free_page((unsigned long)css->cub_addr1);
  955. free_page((unsigned long)css->cub_addr2);
  956. free_page((unsigned long)secm_area);
  957. mutex_unlock(&css->mutex);
  958. return -ENOMEM;
  959. }
  960. }
  961. ret = __chsc_do_secm(css, enable, secm_area);
  962. if (!ret) {
  963. css->cm_enabled = enable;
  964. if (css->cm_enabled) {
  965. ret = chsc_add_cmg_attr(css);
  966. if (ret) {
  967. memset(secm_area, 0, PAGE_SIZE);
  968. __chsc_do_secm(css, 0, secm_area);
  969. css->cm_enabled = 0;
  970. }
  971. } else
  972. chsc_remove_cmg_attr(css);
  973. }
  974. if (enable && !css->cm_enabled) {
  975. free_page((unsigned long)css->cub_addr1);
  976. free_page((unsigned long)css->cub_addr2);
  977. }
  978. mutex_unlock(&css->mutex);
  979. free_page((unsigned long)secm_area);
  980. return ret;
  981. }
  982. /*
  983. * Files for the channel path entries.
  984. */
  985. static ssize_t
  986. chp_status_show(struct device *dev, struct device_attribute *attr, char *buf)
  987. {
  988. struct channel_path *chp = container_of(dev, struct channel_path, dev);
  989. if (!chp)
  990. return 0;
  991. return (get_chp_status(chp->id) ? sprintf(buf, "online\n") :
  992. sprintf(buf, "offline\n"));
  993. }
  994. static ssize_t
  995. chp_status_write(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  996. {
  997. struct channel_path *cp = container_of(dev, struct channel_path, dev);
  998. char cmd[10];
  999. int num_args;
  1000. int error;
  1001. num_args = sscanf(buf, "%5s", cmd);
  1002. if (!num_args)
  1003. return count;
  1004. if (!strnicmp(cmd, "on", 2))
  1005. error = s390_vary_chpid(cp->id, 1);
  1006. else if (!strnicmp(cmd, "off", 3))
  1007. error = s390_vary_chpid(cp->id, 0);
  1008. else
  1009. error = -EINVAL;
  1010. return error < 0 ? error : count;
  1011. }
  1012. static DEVICE_ATTR(status, 0644, chp_status_show, chp_status_write);
  1013. static ssize_t
  1014. chp_type_show(struct device *dev, struct device_attribute *attr, char *buf)
  1015. {
  1016. struct channel_path *chp = container_of(dev, struct channel_path, dev);
  1017. if (!chp)
  1018. return 0;
  1019. return sprintf(buf, "%x\n", chp->desc.desc);
  1020. }
  1021. static DEVICE_ATTR(type, 0444, chp_type_show, NULL);
  1022. static ssize_t
  1023. chp_cmg_show(struct device *dev, struct device_attribute *attr, char *buf)
  1024. {
  1025. struct channel_path *chp = to_channelpath(dev);
  1026. if (!chp)
  1027. return 0;
  1028. if (chp->cmg == -1) /* channel measurements not available */
  1029. return sprintf(buf, "unknown\n");
  1030. return sprintf(buf, "%x\n", chp->cmg);
  1031. }
  1032. static DEVICE_ATTR(cmg, 0444, chp_cmg_show, NULL);
  1033. static ssize_t
  1034. chp_shared_show(struct device *dev, struct device_attribute *attr, char *buf)
  1035. {
  1036. struct channel_path *chp = to_channelpath(dev);
  1037. if (!chp)
  1038. return 0;
  1039. if (chp->shared == -1) /* channel measurements not available */
  1040. return sprintf(buf, "unknown\n");
  1041. return sprintf(buf, "%x\n", chp->shared);
  1042. }
  1043. static DEVICE_ATTR(shared, 0444, chp_shared_show, NULL);
  1044. static struct attribute * chp_attrs[] = {
  1045. &dev_attr_status.attr,
  1046. &dev_attr_type.attr,
  1047. &dev_attr_cmg.attr,
  1048. &dev_attr_shared.attr,
  1049. NULL,
  1050. };
  1051. static struct attribute_group chp_attr_group = {
  1052. .attrs = chp_attrs,
  1053. };
  1054. static void
  1055. chp_release(struct device *dev)
  1056. {
  1057. struct channel_path *cp;
  1058. cp = container_of(dev, struct channel_path, dev);
  1059. kfree(cp);
  1060. }
  1061. static int
  1062. chsc_determine_channel_path_description(int chpid,
  1063. struct channel_path_desc *desc)
  1064. {
  1065. int ccode, ret;
  1066. struct {
  1067. struct chsc_header request;
  1068. u32 : 24;
  1069. u32 first_chpid : 8;
  1070. u32 : 24;
  1071. u32 last_chpid : 8;
  1072. u32 zeroes1;
  1073. struct chsc_header response;
  1074. u32 zeroes2;
  1075. struct channel_path_desc desc;
  1076. } *scpd_area;
  1077. scpd_area = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
  1078. if (!scpd_area)
  1079. return -ENOMEM;
  1080. scpd_area->request.length = 0x0010;
  1081. scpd_area->request.code = 0x0002;
  1082. scpd_area->first_chpid = chpid;
  1083. scpd_area->last_chpid = chpid;
  1084. ccode = chsc(scpd_area);
  1085. if (ccode > 0) {
  1086. ret = (ccode == 3) ? -ENODEV : -EBUSY;
  1087. goto out;
  1088. }
  1089. switch (scpd_area->response.code) {
  1090. case 0x0001: /* Success. */
  1091. memcpy(desc, &scpd_area->desc,
  1092. sizeof(struct channel_path_desc));
  1093. ret = 0;
  1094. break;
  1095. case 0x0003: /* Invalid block. */
  1096. case 0x0007: /* Invalid format. */
  1097. case 0x0008: /* Other invalid block. */
  1098. CIO_CRW_EVENT(2, "Error in chsc request block!\n");
  1099. ret = -EINVAL;
  1100. break;
  1101. case 0x0004: /* Command not provided in model. */
  1102. CIO_CRW_EVENT(2, "Model does not provide scpd\n");
  1103. ret = -EOPNOTSUPP;
  1104. break;
  1105. default:
  1106. CIO_CRW_EVENT(2, "Unknown CHSC response %d\n",
  1107. scpd_area->response.code);
  1108. ret = -EIO;
  1109. }
  1110. out:
  1111. free_page((unsigned long)scpd_area);
  1112. return ret;
  1113. }
  1114. static void
  1115. chsc_initialize_cmg_chars(struct channel_path *chp, u8 cmcv,
  1116. struct cmg_chars *chars)
  1117. {
  1118. switch (chp->cmg) {
  1119. case 2:
  1120. case 3:
  1121. chp->cmg_chars = kmalloc(sizeof(struct cmg_chars),
  1122. GFP_KERNEL);
  1123. if (chp->cmg_chars) {
  1124. int i, mask;
  1125. struct cmg_chars *cmg_chars;
  1126. cmg_chars = chp->cmg_chars;
  1127. for (i = 0; i < NR_MEASUREMENT_CHARS; i++) {
  1128. mask = 0x80 >> (i + 3);
  1129. if (cmcv & mask)
  1130. cmg_chars->values[i] = chars->values[i];
  1131. else
  1132. cmg_chars->values[i] = 0;
  1133. }
  1134. }
  1135. break;
  1136. default:
  1137. /* No cmg-dependent data. */
  1138. break;
  1139. }
  1140. }
  1141. static int
  1142. chsc_get_channel_measurement_chars(struct channel_path *chp)
  1143. {
  1144. int ccode, ret;
  1145. struct {
  1146. struct chsc_header request;
  1147. u32 : 24;
  1148. u32 first_chpid : 8;
  1149. u32 : 24;
  1150. u32 last_chpid : 8;
  1151. u32 zeroes1;
  1152. struct chsc_header response;
  1153. u32 zeroes2;
  1154. u32 not_valid : 1;
  1155. u32 shared : 1;
  1156. u32 : 22;
  1157. u32 chpid : 8;
  1158. u32 cmcv : 5;
  1159. u32 : 11;
  1160. u32 cmgq : 8;
  1161. u32 cmg : 8;
  1162. u32 zeroes3;
  1163. u32 data[NR_MEASUREMENT_CHARS];
  1164. } *scmc_area;
  1165. scmc_area = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
  1166. if (!scmc_area)
  1167. return -ENOMEM;
  1168. scmc_area->request.length = 0x0010;
  1169. scmc_area->request.code = 0x0022;
  1170. scmc_area->first_chpid = chp->id;
  1171. scmc_area->last_chpid = chp->id;
  1172. ccode = chsc(scmc_area);
  1173. if (ccode > 0) {
  1174. ret = (ccode == 3) ? -ENODEV : -EBUSY;
  1175. goto out;
  1176. }
  1177. switch (scmc_area->response.code) {
  1178. case 0x0001: /* Success. */
  1179. if (!scmc_area->not_valid) {
  1180. chp->cmg = scmc_area->cmg;
  1181. chp->shared = scmc_area->shared;
  1182. chsc_initialize_cmg_chars(chp, scmc_area->cmcv,
  1183. (struct cmg_chars *)
  1184. &scmc_area->data);
  1185. } else {
  1186. chp->cmg = -1;
  1187. chp->shared = -1;
  1188. }
  1189. ret = 0;
  1190. break;
  1191. case 0x0003: /* Invalid block. */
  1192. case 0x0007: /* Invalid format. */
  1193. case 0x0008: /* Invalid bit combination. */
  1194. CIO_CRW_EVENT(2, "Error in chsc request block!\n");
  1195. ret = -EINVAL;
  1196. break;
  1197. case 0x0004: /* Command not provided. */
  1198. CIO_CRW_EVENT(2, "Model does not provide scmc\n");
  1199. ret = -EOPNOTSUPP;
  1200. break;
  1201. default:
  1202. CIO_CRW_EVENT(2, "Unknown CHSC response %d\n",
  1203. scmc_area->response.code);
  1204. ret = -EIO;
  1205. }
  1206. out:
  1207. free_page((unsigned long)scmc_area);
  1208. return ret;
  1209. }
  1210. /*
  1211. * Entries for chpids on the system bus.
  1212. * This replaces /proc/chpids.
  1213. */
  1214. static int
  1215. new_channel_path(int chpid)
  1216. {
  1217. struct channel_path *chp;
  1218. int ret;
  1219. chp = kzalloc(sizeof(struct channel_path), GFP_KERNEL);
  1220. if (!chp)
  1221. return -ENOMEM;
  1222. /* fill in status, etc. */
  1223. chp->id = chpid;
  1224. chp->state = 1;
  1225. chp->dev = (struct device) {
  1226. .parent = &css[0]->device,
  1227. .release = chp_release,
  1228. };
  1229. snprintf(chp->dev.bus_id, BUS_ID_SIZE, "chp0.%x", chpid);
  1230. /* Obtain channel path description and fill it in. */
  1231. ret = chsc_determine_channel_path_description(chpid, &chp->desc);
  1232. if (ret)
  1233. goto out_free;
  1234. /* Get channel-measurement characteristics. */
  1235. if (css_characteristics_avail && css_chsc_characteristics.scmc
  1236. && css_chsc_characteristics.secm) {
  1237. ret = chsc_get_channel_measurement_chars(chp);
  1238. if (ret)
  1239. goto out_free;
  1240. } else {
  1241. static int msg_done;
  1242. if (!msg_done) {
  1243. printk(KERN_WARNING "cio: Channel measurements not "
  1244. "available, continuing.\n");
  1245. msg_done = 1;
  1246. }
  1247. chp->cmg = -1;
  1248. }
  1249. /* make it known to the system */
  1250. ret = device_register(&chp->dev);
  1251. if (ret) {
  1252. printk(KERN_WARNING "%s: could not register %02x\n",
  1253. __func__, chpid);
  1254. goto out_free;
  1255. }
  1256. ret = sysfs_create_group(&chp->dev.kobj, &chp_attr_group);
  1257. if (ret) {
  1258. device_unregister(&chp->dev);
  1259. goto out_free;
  1260. }
  1261. mutex_lock(&css[0]->mutex);
  1262. if (css[0]->cm_enabled) {
  1263. ret = chsc_add_chp_cmg_attr(chp);
  1264. if (ret) {
  1265. sysfs_remove_group(&chp->dev.kobj, &chp_attr_group);
  1266. device_unregister(&chp->dev);
  1267. mutex_unlock(&css[0]->mutex);
  1268. goto out_free;
  1269. }
  1270. }
  1271. css[0]->chps[chpid] = chp;
  1272. mutex_unlock(&css[0]->mutex);
  1273. return ret;
  1274. out_free:
  1275. kfree(chp);
  1276. return ret;
  1277. }
  1278. void *
  1279. chsc_get_chp_desc(struct subchannel *sch, int chp_no)
  1280. {
  1281. struct channel_path *chp;
  1282. struct channel_path_desc *desc;
  1283. chp = css[0]->chps[sch->schib.pmcw.chpid[chp_no]];
  1284. if (!chp)
  1285. return NULL;
  1286. desc = kmalloc(sizeof(struct channel_path_desc), GFP_KERNEL);
  1287. if (!desc)
  1288. return NULL;
  1289. memcpy(desc, &chp->desc, sizeof(struct channel_path_desc));
  1290. return desc;
  1291. }
  1292. static int __init
  1293. chsc_alloc_sei_area(void)
  1294. {
  1295. sei_page = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
  1296. if (!sei_page)
  1297. printk(KERN_WARNING"Can't allocate page for processing of " \
  1298. "chsc machine checks!\n");
  1299. return (sei_page ? 0 : -ENOMEM);
  1300. }
  1301. int __init
  1302. chsc_enable_facility(int operation_code)
  1303. {
  1304. int ret;
  1305. struct {
  1306. struct chsc_header request;
  1307. u8 reserved1:4;
  1308. u8 format:4;
  1309. u8 reserved2;
  1310. u16 operation_code;
  1311. u32 reserved3;
  1312. u32 reserved4;
  1313. u32 operation_data_area[252];
  1314. struct chsc_header response;
  1315. u32 reserved5:4;
  1316. u32 format2:4;
  1317. u32 reserved6:24;
  1318. } *sda_area;
  1319. sda_area = (void *)get_zeroed_page(GFP_KERNEL|GFP_DMA);
  1320. if (!sda_area)
  1321. return -ENOMEM;
  1322. sda_area->request.length = 0x0400;
  1323. sda_area->request.code = 0x0031;
  1324. sda_area->operation_code = operation_code;
  1325. ret = chsc(sda_area);
  1326. if (ret > 0) {
  1327. ret = (ret == 3) ? -ENODEV : -EBUSY;
  1328. goto out;
  1329. }
  1330. switch (sda_area->response.code) {
  1331. case 0x0001: /* everything ok */
  1332. ret = 0;
  1333. break;
  1334. case 0x0003: /* invalid request block */
  1335. case 0x0007:
  1336. ret = -EINVAL;
  1337. break;
  1338. case 0x0004: /* command not provided */
  1339. case 0x0101: /* facility not provided */
  1340. ret = -EOPNOTSUPP;
  1341. break;
  1342. default: /* something went wrong */
  1343. ret = -EIO;
  1344. }
  1345. out:
  1346. free_page((unsigned long)sda_area);
  1347. return ret;
  1348. }
  1349. subsys_initcall(chsc_alloc_sei_area);
  1350. struct css_general_char css_general_characteristics;
  1351. struct css_chsc_char css_chsc_characteristics;
  1352. int __init
  1353. chsc_determine_css_characteristics(void)
  1354. {
  1355. int result;
  1356. struct {
  1357. struct chsc_header request;
  1358. u32 reserved1;
  1359. u32 reserved2;
  1360. u32 reserved3;
  1361. struct chsc_header response;
  1362. u32 reserved4;
  1363. u32 general_char[510];
  1364. u32 chsc_char[518];
  1365. } *scsc_area;
  1366. scsc_area = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
  1367. if (!scsc_area) {
  1368. printk(KERN_WARNING"cio: Was not able to determine available" \
  1369. "CHSCs due to no memory.\n");
  1370. return -ENOMEM;
  1371. }
  1372. scsc_area->request.length = 0x0010;
  1373. scsc_area->request.code = 0x0010;
  1374. result = chsc(scsc_area);
  1375. if (result) {
  1376. printk(KERN_WARNING"cio: Was not able to determine " \
  1377. "available CHSCs, cc=%i.\n", result);
  1378. result = -EIO;
  1379. goto exit;
  1380. }
  1381. if (scsc_area->response.code != 1) {
  1382. printk(KERN_WARNING"cio: Was not able to determine " \
  1383. "available CHSCs.\n");
  1384. result = -EIO;
  1385. goto exit;
  1386. }
  1387. memcpy(&css_general_characteristics, scsc_area->general_char,
  1388. sizeof(css_general_characteristics));
  1389. memcpy(&css_chsc_characteristics, scsc_area->chsc_char,
  1390. sizeof(css_chsc_characteristics));
  1391. exit:
  1392. free_page ((unsigned long) scsc_area);
  1393. return result;
  1394. }
  1395. EXPORT_SYMBOL_GPL(css_general_characteristics);
  1396. EXPORT_SYMBOL_GPL(css_chsc_characteristics);