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. int cc;
  220. cc = cio_clear(sch);
  221. if (cc == -ENODEV)
  222. goto out_unreg;
  223. /* Call handler. */
  224. if (sch->driver && sch->driver->termination)
  225. sch->driver->termination(&sch->dev);
  226. goto out_unlock;
  227. }
  228. /* trigger path verification. */
  229. if (sch->driver && sch->driver->verify)
  230. sch->driver->verify(&sch->dev);
  231. out_unlock:
  232. spin_unlock_irq(&sch->lock);
  233. return 0;
  234. out_unreg:
  235. spin_unlock_irq(&sch->lock);
  236. sch->lpm = 0;
  237. if (css_enqueue_subchannel_slow(sch->schid)) {
  238. css_clear_subchannel_slow_list();
  239. need_rescan = 1;
  240. }
  241. return 0;
  242. }
  243. static inline void
  244. s390_set_chpid_offline( __u8 chpid)
  245. {
  246. char dbf_txt[15];
  247. struct device *dev;
  248. sprintf(dbf_txt, "chpr%x", chpid);
  249. CIO_TRACE_EVENT(2, dbf_txt);
  250. if (get_chp_status(chpid) <= 0)
  251. return;
  252. dev = get_device(&css[0]->chps[chpid]->dev);
  253. bus_for_each_dev(&css_bus_type, NULL, to_channelpath(dev),
  254. s390_subchannel_remove_chpid);
  255. if (need_rescan || css_slow_subchannels_exist())
  256. queue_work(slow_path_wq, &slow_path_work);
  257. put_device(dev);
  258. }
  259. struct res_acc_data {
  260. struct channel_path *chp;
  261. u32 fla_mask;
  262. u16 fla;
  263. };
  264. static int
  265. s390_process_res_acc_sch(struct res_acc_data *res_data, struct subchannel *sch)
  266. {
  267. int found;
  268. int chp;
  269. int ccode;
  270. found = 0;
  271. for (chp = 0; chp <= 7; chp++)
  272. /*
  273. * check if chpid is in information updated by ssd
  274. */
  275. if (sch->ssd_info.valid &&
  276. sch->ssd_info.chpid[chp] == res_data->chp->id &&
  277. (sch->ssd_info.fla[chp] & res_data->fla_mask)
  278. == res_data->fla) {
  279. found = 1;
  280. break;
  281. }
  282. if (found == 0)
  283. return 0;
  284. /*
  285. * Do a stsch to update our subchannel structure with the
  286. * new path information and eventually check for logically
  287. * offline chpids.
  288. */
  289. ccode = stsch(sch->schid, &sch->schib);
  290. if (ccode > 0)
  291. return 0;
  292. return 0x80 >> chp;
  293. }
  294. static inline int
  295. s390_process_res_acc_new_sch(struct subchannel_id schid)
  296. {
  297. struct schib schib;
  298. int ret;
  299. /*
  300. * We don't know the device yet, but since a path
  301. * may be available now to the device we'll have
  302. * to do recognition again.
  303. * Since we don't have any idea about which chpid
  304. * that beast may be on we'll have to do a stsch
  305. * on all devices, grr...
  306. */
  307. if (stsch_err(schid, &schib))
  308. /* We're through */
  309. return need_rescan ? -EAGAIN : -ENXIO;
  310. /* Put it on the slow path. */
  311. ret = css_enqueue_subchannel_slow(schid);
  312. if (ret) {
  313. css_clear_subchannel_slow_list();
  314. need_rescan = 1;
  315. return -EAGAIN;
  316. }
  317. return 0;
  318. }
  319. static int
  320. __s390_process_res_acc(struct subchannel_id schid, void *data)
  321. {
  322. int chp_mask, old_lpm;
  323. struct res_acc_data *res_data;
  324. struct subchannel *sch;
  325. res_data = (struct res_acc_data *)data;
  326. sch = get_subchannel_by_schid(schid);
  327. if (!sch)
  328. /* Check if a subchannel is newly available. */
  329. return s390_process_res_acc_new_sch(schid);
  330. spin_lock_irq(&sch->lock);
  331. chp_mask = s390_process_res_acc_sch(res_data, sch);
  332. if (chp_mask == 0) {
  333. spin_unlock_irq(&sch->lock);
  334. return 0;
  335. }
  336. old_lpm = sch->lpm;
  337. sch->lpm = ((sch->schib.pmcw.pim &
  338. sch->schib.pmcw.pam &
  339. sch->schib.pmcw.pom)
  340. | chp_mask) & sch->opm;
  341. if (!old_lpm && sch->lpm)
  342. device_trigger_reprobe(sch);
  343. else if (sch->driver && sch->driver->verify)
  344. sch->driver->verify(&sch->dev);
  345. spin_unlock_irq(&sch->lock);
  346. put_device(&sch->dev);
  347. return (res_data->fla_mask == 0xffff) ? -ENODEV : 0;
  348. }
  349. static int
  350. s390_process_res_acc (struct res_acc_data *res_data)
  351. {
  352. int rc;
  353. char dbf_txt[15];
  354. sprintf(dbf_txt, "accpr%x", res_data->chp->id);
  355. CIO_TRACE_EVENT( 2, dbf_txt);
  356. if (res_data->fla != 0) {
  357. sprintf(dbf_txt, "fla%x", res_data->fla);
  358. CIO_TRACE_EVENT( 2, dbf_txt);
  359. }
  360. /*
  361. * I/O resources may have become accessible.
  362. * Scan through all subchannels that may be concerned and
  363. * do a validation on those.
  364. * The more information we have (info), the less scanning
  365. * will we have to do.
  366. */
  367. rc = for_each_subchannel(__s390_process_res_acc, res_data);
  368. if (css_slow_subchannels_exist())
  369. rc = -EAGAIN;
  370. else if (rc != -EAGAIN)
  371. rc = 0;
  372. return rc;
  373. }
  374. static int
  375. __get_chpid_from_lir(void *data)
  376. {
  377. struct lir {
  378. u8 iq;
  379. u8 ic;
  380. u16 sci;
  381. /* incident-node descriptor */
  382. u32 indesc[28];
  383. /* attached-node descriptor */
  384. u32 andesc[28];
  385. /* incident-specific information */
  386. u32 isinfo[28];
  387. } *lir;
  388. lir = (struct lir*) data;
  389. if (!(lir->iq&0x80))
  390. /* NULL link incident record */
  391. return -EINVAL;
  392. if (!(lir->indesc[0]&0xc0000000))
  393. /* node descriptor not valid */
  394. return -EINVAL;
  395. if (!(lir->indesc[0]&0x10000000))
  396. /* don't handle device-type nodes - FIXME */
  397. return -EINVAL;
  398. /* Byte 3 contains the chpid. Could also be CTCA, but we don't care */
  399. return (u16) (lir->indesc[0]&0x000000ff);
  400. }
  401. int
  402. chsc_process_crw(void)
  403. {
  404. int chpid, ret;
  405. struct res_acc_data res_data;
  406. struct {
  407. struct chsc_header request;
  408. u32 reserved1;
  409. u32 reserved2;
  410. u32 reserved3;
  411. struct chsc_header response;
  412. u32 reserved4;
  413. u8 flags;
  414. u8 vf; /* validity flags */
  415. u8 rs; /* reporting source */
  416. u8 cc; /* content code */
  417. u16 fla; /* full link address */
  418. u16 rsid; /* reporting source id */
  419. u32 reserved5;
  420. u32 reserved6;
  421. u32 ccdf[96]; /* content-code dependent field */
  422. /* ccdf has to be big enough for a link-incident record */
  423. } *sei_area;
  424. if (!sei_page)
  425. return 0;
  426. /*
  427. * build the chsc request block for store event information
  428. * and do the call
  429. * This function is only called by the machine check handler thread,
  430. * so we don't need locking for the sei_page.
  431. */
  432. sei_area = sei_page;
  433. CIO_TRACE_EVENT( 2, "prcss");
  434. ret = 0;
  435. do {
  436. int ccode, status;
  437. struct device *dev;
  438. memset(sei_area, 0, sizeof(*sei_area));
  439. memset(&res_data, 0, sizeof(struct res_acc_data));
  440. sei_area->request.length = 0x0010;
  441. sei_area->request.code = 0x000e;
  442. ccode = chsc(sei_area);
  443. if (ccode > 0)
  444. return 0;
  445. switch (sei_area->response.code) {
  446. /* for debug purposes, check for problems */
  447. case 0x0001:
  448. CIO_CRW_EVENT(4, "chsc_process_crw: event information "
  449. "successfully stored\n");
  450. break; /* everything ok */
  451. case 0x0002:
  452. CIO_CRW_EVENT(2,
  453. "chsc_process_crw: invalid command!\n");
  454. return 0;
  455. case 0x0003:
  456. CIO_CRW_EVENT(2, "chsc_process_crw: error in chsc "
  457. "request block!\n");
  458. return 0;
  459. case 0x0005:
  460. CIO_CRW_EVENT(2, "chsc_process_crw: no event "
  461. "information stored\n");
  462. return 0;
  463. default:
  464. CIO_CRW_EVENT(2, "chsc_process_crw: chsc response %d\n",
  465. sei_area->response.code);
  466. return 0;
  467. }
  468. /* Check if we might have lost some information. */
  469. if (sei_area->flags & 0x40)
  470. CIO_CRW_EVENT(2, "chsc_process_crw: Event information "
  471. "has been lost due to overflow!\n");
  472. if (sei_area->rs != 4) {
  473. CIO_CRW_EVENT(2, "chsc_process_crw: reporting source "
  474. "(%04X) isn't a chpid!\n",
  475. sei_area->rsid);
  476. continue;
  477. }
  478. /* which kind of information was stored? */
  479. switch (sei_area->cc) {
  480. case 1: /* link incident*/
  481. CIO_CRW_EVENT(4, "chsc_process_crw: "
  482. "channel subsystem reports link incident,"
  483. " reporting source is chpid %x\n",
  484. sei_area->rsid);
  485. chpid = __get_chpid_from_lir(sei_area->ccdf);
  486. if (chpid < 0)
  487. CIO_CRW_EVENT(4, "%s: Invalid LIR, skipping\n",
  488. __FUNCTION__);
  489. else
  490. s390_set_chpid_offline(chpid);
  491. break;
  492. case 2: /* i/o resource accessibiliy */
  493. CIO_CRW_EVENT(4, "chsc_process_crw: "
  494. "channel subsystem reports some I/O "
  495. "devices may have become accessible\n");
  496. pr_debug("Data received after sei: \n");
  497. pr_debug("Validity flags: %x\n", sei_area->vf);
  498. /* allocate a new channel path structure, if needed */
  499. status = get_chp_status(sei_area->rsid);
  500. if (status < 0)
  501. new_channel_path(sei_area->rsid);
  502. else if (!status)
  503. break;
  504. dev = get_device(&css[0]->chps[sei_area->rsid]->dev);
  505. res_data.chp = to_channelpath(dev);
  506. pr_debug("chpid: %x", sei_area->rsid);
  507. if ((sei_area->vf & 0xc0) != 0) {
  508. res_data.fla = sei_area->fla;
  509. if ((sei_area->vf & 0xc0) == 0xc0) {
  510. pr_debug(" full link addr: %x",
  511. sei_area->fla);
  512. res_data.fla_mask = 0xffff;
  513. } else {
  514. pr_debug(" link addr: %x",
  515. sei_area->fla);
  516. res_data.fla_mask = 0xff00;
  517. }
  518. }
  519. ret = s390_process_res_acc(&res_data);
  520. pr_debug("\n\n");
  521. put_device(dev);
  522. break;
  523. default: /* other stuff */
  524. CIO_CRW_EVENT(4, "chsc_process_crw: event %d\n",
  525. sei_area->cc);
  526. break;
  527. }
  528. } while (sei_area->flags & 0x80);
  529. return ret;
  530. }
  531. static inline int
  532. __chp_add_new_sch(struct subchannel_id schid)
  533. {
  534. struct schib schib;
  535. int ret;
  536. if (stsch(schid, &schib))
  537. /* We're through */
  538. return need_rescan ? -EAGAIN : -ENXIO;
  539. /* Put it on the slow path. */
  540. ret = css_enqueue_subchannel_slow(schid);
  541. if (ret) {
  542. css_clear_subchannel_slow_list();
  543. need_rescan = 1;
  544. return -EAGAIN;
  545. }
  546. return 0;
  547. }
  548. static int
  549. __chp_add(struct subchannel_id schid, void *data)
  550. {
  551. int i;
  552. struct channel_path *chp;
  553. struct subchannel *sch;
  554. chp = (struct channel_path *)data;
  555. sch = get_subchannel_by_schid(schid);
  556. if (!sch)
  557. /* Check if the subchannel is now available. */
  558. return __chp_add_new_sch(schid);
  559. spin_lock_irq(&sch->lock);
  560. for (i=0; i<8; i++)
  561. if (sch->schib.pmcw.chpid[i] == chp->id) {
  562. if (stsch(sch->schid, &sch->schib) != 0) {
  563. /* Endgame. */
  564. spin_unlock_irq(&sch->lock);
  565. return -ENXIO;
  566. }
  567. break;
  568. }
  569. if (i==8) {
  570. spin_unlock_irq(&sch->lock);
  571. return 0;
  572. }
  573. sch->lpm = ((sch->schib.pmcw.pim &
  574. sch->schib.pmcw.pam &
  575. sch->schib.pmcw.pom)
  576. | 0x80 >> i) & sch->opm;
  577. if (sch->driver && sch->driver->verify)
  578. sch->driver->verify(&sch->dev);
  579. spin_unlock_irq(&sch->lock);
  580. put_device(&sch->dev);
  581. return 0;
  582. }
  583. static int
  584. chp_add(int chpid)
  585. {
  586. int rc;
  587. char dbf_txt[15];
  588. struct device *dev;
  589. if (!get_chp_status(chpid))
  590. return 0; /* no need to do the rest */
  591. sprintf(dbf_txt, "cadd%x", chpid);
  592. CIO_TRACE_EVENT(2, dbf_txt);
  593. dev = get_device(&css[0]->chps[chpid]->dev);
  594. rc = for_each_subchannel(__chp_add, to_channelpath(dev));
  595. if (css_slow_subchannels_exist())
  596. rc = -EAGAIN;
  597. if (rc != -EAGAIN)
  598. rc = 0;
  599. put_device(dev);
  600. return rc;
  601. }
  602. /*
  603. * Handling of crw machine checks with channel path source.
  604. */
  605. int
  606. chp_process_crw(int chpid, int on)
  607. {
  608. if (on == 0) {
  609. /* Path has gone. We use the link incident routine.*/
  610. s390_set_chpid_offline(chpid);
  611. return 0; /* De-register is async anyway. */
  612. }
  613. /*
  614. * Path has come. Allocate a new channel path structure,
  615. * if needed.
  616. */
  617. if (get_chp_status(chpid) < 0)
  618. new_channel_path(chpid);
  619. /* Avoid the extra overhead in process_rec_acc. */
  620. return chp_add(chpid);
  621. }
  622. static inline int
  623. __check_for_io_and_kill(struct subchannel *sch, int index)
  624. {
  625. int cc;
  626. if (!device_is_online(sch))
  627. /* cio could be doing I/O. */
  628. return 0;
  629. cc = stsch(sch->schid, &sch->schib);
  630. if (cc)
  631. return 0;
  632. if (sch->schib.scsw.actl && sch->schib.pmcw.lpum == (0x80 >> index)) {
  633. device_set_waiting(sch);
  634. return 1;
  635. }
  636. return 0;
  637. }
  638. static inline void
  639. __s390_subchannel_vary_chpid(struct subchannel *sch, __u8 chpid, int on)
  640. {
  641. int chp, old_lpm;
  642. unsigned long flags;
  643. if (!sch->ssd_info.valid)
  644. return;
  645. spin_lock_irqsave(&sch->lock, flags);
  646. old_lpm = sch->lpm;
  647. for (chp = 0; chp < 8; chp++) {
  648. if (sch->ssd_info.chpid[chp] != chpid)
  649. continue;
  650. if (on) {
  651. sch->opm |= (0x80 >> chp);
  652. sch->lpm |= (0x80 >> chp);
  653. if (!old_lpm)
  654. device_trigger_reprobe(sch);
  655. else if (sch->driver && sch->driver->verify)
  656. sch->driver->verify(&sch->dev);
  657. } else {
  658. sch->opm &= ~(0x80 >> chp);
  659. sch->lpm &= ~(0x80 >> chp);
  660. /*
  661. * Give running I/O a grace period in which it
  662. * can successfully terminate, even using the
  663. * just varied off path. Then kill it.
  664. */
  665. if (!__check_for_io_and_kill(sch, chp) && !sch->lpm) {
  666. if (css_enqueue_subchannel_slow(sch->schid)) {
  667. css_clear_subchannel_slow_list();
  668. need_rescan = 1;
  669. }
  670. } else if (sch->driver && sch->driver->verify)
  671. sch->driver->verify(&sch->dev);
  672. }
  673. break;
  674. }
  675. spin_unlock_irqrestore(&sch->lock, flags);
  676. }
  677. static int
  678. s390_subchannel_vary_chpid_off(struct device *dev, void *data)
  679. {
  680. struct subchannel *sch;
  681. __u8 *chpid;
  682. sch = to_subchannel(dev);
  683. chpid = data;
  684. __s390_subchannel_vary_chpid(sch, *chpid, 0);
  685. return 0;
  686. }
  687. static int
  688. s390_subchannel_vary_chpid_on(struct device *dev, void *data)
  689. {
  690. struct subchannel *sch;
  691. __u8 *chpid;
  692. sch = to_subchannel(dev);
  693. chpid = data;
  694. __s390_subchannel_vary_chpid(sch, *chpid, 1);
  695. return 0;
  696. }
  697. static int
  698. __s390_vary_chpid_on(struct subchannel_id schid, void *data)
  699. {
  700. struct schib schib;
  701. struct subchannel *sch;
  702. sch = get_subchannel_by_schid(schid);
  703. if (sch) {
  704. put_device(&sch->dev);
  705. return 0;
  706. }
  707. if (stsch_err(schid, &schib))
  708. /* We're through */
  709. return -ENXIO;
  710. /* Put it on the slow path. */
  711. if (css_enqueue_subchannel_slow(schid)) {
  712. css_clear_subchannel_slow_list();
  713. need_rescan = 1;
  714. return -EAGAIN;
  715. }
  716. return 0;
  717. }
  718. /*
  719. * Function: s390_vary_chpid
  720. * Varies the specified chpid online or offline
  721. */
  722. static int
  723. s390_vary_chpid( __u8 chpid, int on)
  724. {
  725. char dbf_text[15];
  726. int status;
  727. sprintf(dbf_text, on?"varyon%x":"varyoff%x", chpid);
  728. CIO_TRACE_EVENT( 2, dbf_text);
  729. status = get_chp_status(chpid);
  730. if (status < 0) {
  731. printk(KERN_ERR "Can't vary unknown chpid %02X\n", chpid);
  732. return -EINVAL;
  733. }
  734. if (!on && !status) {
  735. printk(KERN_ERR "chpid %x is already offline\n", chpid);
  736. return -EINVAL;
  737. }
  738. set_chp_logically_online(chpid, on);
  739. /*
  740. * Redo PathVerification on the devices the chpid connects to
  741. */
  742. bus_for_each_dev(&css_bus_type, NULL, &chpid, on ?
  743. s390_subchannel_vary_chpid_on :
  744. s390_subchannel_vary_chpid_off);
  745. if (on)
  746. /* Scan for new devices on varied on path. */
  747. for_each_subchannel(__s390_vary_chpid_on, NULL);
  748. if (need_rescan || css_slow_subchannels_exist())
  749. queue_work(slow_path_wq, &slow_path_work);
  750. return 0;
  751. }
  752. /*
  753. * Channel measurement related functions
  754. */
  755. static ssize_t
  756. chp_measurement_chars_read(struct kobject *kobj, char *buf, loff_t off,
  757. size_t count)
  758. {
  759. struct channel_path *chp;
  760. unsigned int size;
  761. chp = to_channelpath(container_of(kobj, struct device, kobj));
  762. if (!chp->cmg_chars)
  763. return 0;
  764. size = sizeof(struct cmg_chars);
  765. if (off > size)
  766. return 0;
  767. if (off + count > size)
  768. count = size - off;
  769. memcpy(buf, chp->cmg_chars + off, count);
  770. return count;
  771. }
  772. static struct bin_attribute chp_measurement_chars_attr = {
  773. .attr = {
  774. .name = "measurement_chars",
  775. .mode = S_IRUSR,
  776. .owner = THIS_MODULE,
  777. },
  778. .size = sizeof(struct cmg_chars),
  779. .read = chp_measurement_chars_read,
  780. };
  781. static void
  782. chp_measurement_copy_block(struct cmg_entry *buf,
  783. struct channel_subsystem *css, int chpid)
  784. {
  785. void *area;
  786. struct cmg_entry *entry, reference_buf;
  787. int idx;
  788. if (chpid < 128) {
  789. area = css->cub_addr1;
  790. idx = chpid;
  791. } else {
  792. area = css->cub_addr2;
  793. idx = chpid - 128;
  794. }
  795. entry = area + (idx * sizeof(struct cmg_entry));
  796. do {
  797. memcpy(buf, entry, sizeof(*entry));
  798. memcpy(&reference_buf, entry, sizeof(*entry));
  799. } while (reference_buf.values[0] != buf->values[0]);
  800. }
  801. static ssize_t
  802. chp_measurement_read(struct kobject *kobj, char *buf, loff_t off, size_t count)
  803. {
  804. struct channel_path *chp;
  805. struct channel_subsystem *css;
  806. unsigned int size;
  807. chp = to_channelpath(container_of(kobj, struct device, kobj));
  808. css = to_css(chp->dev.parent);
  809. size = sizeof(struct cmg_entry);
  810. /* Only allow single reads. */
  811. if (off || count < size)
  812. return 0;
  813. chp_measurement_copy_block((struct cmg_entry *)buf, css, chp->id);
  814. count = size;
  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);