chsc.c 36 KB

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