chsc.c 36 KB

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