chsc.c 36 KB

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