chsc.c 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618
  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 = 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 = 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 = 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 check_for_io_on_path(struct subchannel *sch, int index)
  630. {
  631. int cc;
  632. if (!device_is_online(sch))
  633. /* cio could be doing I/O. */
  634. return 0;
  635. cc = stsch(sch->schid, &sch->schib);
  636. if (cc)
  637. return 0;
  638. if (sch->schib.scsw.actl && sch->schib.pmcw.lpum == (0x80 >> index))
  639. return 1;
  640. return 0;
  641. }
  642. static inline void
  643. __s390_subchannel_vary_chpid(struct subchannel *sch, __u8 chpid, int on)
  644. {
  645. int chp, old_lpm;
  646. unsigned long flags;
  647. if (!sch->ssd_info.valid)
  648. return;
  649. spin_lock_irqsave(&sch->lock, flags);
  650. old_lpm = sch->lpm;
  651. for (chp = 0; chp < 8; chp++) {
  652. if (sch->ssd_info.chpid[chp] != chpid)
  653. continue;
  654. if (on) {
  655. sch->opm |= (0x80 >> chp);
  656. sch->lpm |= (0x80 >> chp);
  657. if (!old_lpm)
  658. device_trigger_reprobe(sch);
  659. else if (sch->driver && sch->driver->verify)
  660. sch->driver->verify(&sch->dev);
  661. } else {
  662. sch->opm &= ~(0x80 >> chp);
  663. sch->lpm &= ~(0x80 >> chp);
  664. if (check_for_io_on_path(sch, chp))
  665. /* Path verification is done after killing. */
  666. device_kill_io(sch);
  667. else if (!sch->lpm) {
  668. if (css_enqueue_subchannel_slow(sch->schid)) {
  669. css_clear_subchannel_slow_list();
  670. need_rescan = 1;
  671. }
  672. } else if (sch->driver && sch->driver->verify)
  673. sch->driver->verify(&sch->dev);
  674. }
  675. break;
  676. }
  677. spin_unlock_irqrestore(&sch->lock, flags);
  678. }
  679. static int
  680. s390_subchannel_vary_chpid_off(struct device *dev, void *data)
  681. {
  682. struct subchannel *sch;
  683. __u8 *chpid;
  684. sch = to_subchannel(dev);
  685. chpid = data;
  686. __s390_subchannel_vary_chpid(sch, *chpid, 0);
  687. return 0;
  688. }
  689. static int
  690. s390_subchannel_vary_chpid_on(struct device *dev, void *data)
  691. {
  692. struct subchannel *sch;
  693. __u8 *chpid;
  694. sch = to_subchannel(dev);
  695. chpid = data;
  696. __s390_subchannel_vary_chpid(sch, *chpid, 1);
  697. return 0;
  698. }
  699. static int
  700. __s390_vary_chpid_on(struct subchannel_id schid, void *data)
  701. {
  702. struct schib schib;
  703. struct subchannel *sch;
  704. sch = get_subchannel_by_schid(schid);
  705. if (sch) {
  706. put_device(&sch->dev);
  707. return 0;
  708. }
  709. if (stsch_err(schid, &schib))
  710. /* We're through */
  711. return -ENXIO;
  712. /* Put it on the slow path. */
  713. if (css_enqueue_subchannel_slow(schid)) {
  714. css_clear_subchannel_slow_list();
  715. need_rescan = 1;
  716. return -EAGAIN;
  717. }
  718. return 0;
  719. }
  720. /*
  721. * Function: s390_vary_chpid
  722. * Varies the specified chpid online or offline
  723. */
  724. static int
  725. s390_vary_chpid( __u8 chpid, int on)
  726. {
  727. char dbf_text[15];
  728. int status;
  729. sprintf(dbf_text, on?"varyon%x":"varyoff%x", chpid);
  730. CIO_TRACE_EVENT( 2, dbf_text);
  731. status = get_chp_status(chpid);
  732. if (status < 0) {
  733. printk(KERN_ERR "Can't vary unknown chpid %02X\n", chpid);
  734. return -EINVAL;
  735. }
  736. if (!on && !status) {
  737. printk(KERN_ERR "chpid %x is already offline\n", chpid);
  738. return -EINVAL;
  739. }
  740. set_chp_logically_online(chpid, on);
  741. /*
  742. * Redo PathVerification on the devices the chpid connects to
  743. */
  744. bus_for_each_dev(&css_bus_type, NULL, &chpid, on ?
  745. s390_subchannel_vary_chpid_on :
  746. s390_subchannel_vary_chpid_off);
  747. if (on)
  748. /* Scan for new devices on varied on path. */
  749. for_each_subchannel(__s390_vary_chpid_on, NULL);
  750. if (need_rescan || css_slow_subchannels_exist())
  751. queue_work(slow_path_wq, &slow_path_work);
  752. return 0;
  753. }
  754. /*
  755. * Channel measurement related functions
  756. */
  757. static ssize_t
  758. chp_measurement_chars_read(struct kobject *kobj, char *buf, loff_t off,
  759. size_t count)
  760. {
  761. struct channel_path *chp;
  762. unsigned int size;
  763. chp = to_channelpath(container_of(kobj, struct device, kobj));
  764. if (!chp->cmg_chars)
  765. return 0;
  766. size = sizeof(struct cmg_chars);
  767. if (off > size)
  768. return 0;
  769. if (off + count > size)
  770. count = size - off;
  771. memcpy(buf, chp->cmg_chars + off, count);
  772. return count;
  773. }
  774. static struct bin_attribute chp_measurement_chars_attr = {
  775. .attr = {
  776. .name = "measurement_chars",
  777. .mode = S_IRUSR,
  778. .owner = THIS_MODULE,
  779. },
  780. .size = sizeof(struct cmg_chars),
  781. .read = chp_measurement_chars_read,
  782. };
  783. static void
  784. chp_measurement_copy_block(struct cmg_entry *buf,
  785. struct channel_subsystem *css, int chpid)
  786. {
  787. void *area;
  788. struct cmg_entry *entry, reference_buf;
  789. int idx;
  790. if (chpid < 128) {
  791. area = css->cub_addr1;
  792. idx = chpid;
  793. } else {
  794. area = css->cub_addr2;
  795. idx = chpid - 128;
  796. }
  797. entry = area + (idx * sizeof(struct cmg_entry));
  798. do {
  799. memcpy(buf, entry, sizeof(*entry));
  800. memcpy(&reference_buf, entry, sizeof(*entry));
  801. } while (reference_buf.values[0] != buf->values[0]);
  802. }
  803. static ssize_t
  804. chp_measurement_read(struct kobject *kobj, char *buf, loff_t off, size_t count)
  805. {
  806. struct channel_path *chp;
  807. struct channel_subsystem *css;
  808. unsigned int size;
  809. chp = to_channelpath(container_of(kobj, struct device, kobj));
  810. css = to_css(chp->dev.parent);
  811. size = sizeof(struct cmg_entry);
  812. /* Only allow single reads. */
  813. if (off || count < size)
  814. return 0;
  815. chp_measurement_copy_block((struct cmg_entry *)buf, css, chp->id);
  816. count = size;
  817. return count;
  818. }
  819. static struct bin_attribute chp_measurement_attr = {
  820. .attr = {
  821. .name = "measurement",
  822. .mode = S_IRUSR,
  823. .owner = THIS_MODULE,
  824. },
  825. .size = sizeof(struct cmg_entry),
  826. .read = chp_measurement_read,
  827. };
  828. static void
  829. chsc_remove_chp_cmg_attr(struct channel_path *chp)
  830. {
  831. sysfs_remove_bin_file(&chp->dev.kobj, &chp_measurement_chars_attr);
  832. sysfs_remove_bin_file(&chp->dev.kobj, &chp_measurement_attr);
  833. }
  834. static int
  835. chsc_add_chp_cmg_attr(struct channel_path *chp)
  836. {
  837. int ret;
  838. ret = sysfs_create_bin_file(&chp->dev.kobj,
  839. &chp_measurement_chars_attr);
  840. if (ret)
  841. return ret;
  842. ret = sysfs_create_bin_file(&chp->dev.kobj, &chp_measurement_attr);
  843. if (ret)
  844. sysfs_remove_bin_file(&chp->dev.kobj,
  845. &chp_measurement_chars_attr);
  846. return ret;
  847. }
  848. static void
  849. chsc_remove_cmg_attr(struct channel_subsystem *css)
  850. {
  851. int i;
  852. for (i = 0; i <= __MAX_CHPID; i++) {
  853. if (!css->chps[i])
  854. continue;
  855. chsc_remove_chp_cmg_attr(css->chps[i]);
  856. }
  857. }
  858. static int
  859. chsc_add_cmg_attr(struct channel_subsystem *css)
  860. {
  861. int i, ret;
  862. ret = 0;
  863. for (i = 0; i <= __MAX_CHPID; i++) {
  864. if (!css->chps[i])
  865. continue;
  866. ret = chsc_add_chp_cmg_attr(css->chps[i]);
  867. if (ret)
  868. goto cleanup;
  869. }
  870. return ret;
  871. cleanup:
  872. for (--i; i >= 0; i--) {
  873. if (!css->chps[i])
  874. continue;
  875. chsc_remove_chp_cmg_attr(css->chps[i]);
  876. }
  877. return ret;
  878. }
  879. static int
  880. __chsc_do_secm(struct channel_subsystem *css, int enable, void *page)
  881. {
  882. struct {
  883. struct chsc_header request;
  884. u32 operation_code : 2;
  885. u32 : 30;
  886. u32 key : 4;
  887. u32 : 28;
  888. u32 zeroes1;
  889. u32 cub_addr1;
  890. u32 zeroes2;
  891. u32 cub_addr2;
  892. u32 reserved[13];
  893. struct chsc_header response;
  894. u32 status : 8;
  895. u32 : 4;
  896. u32 fmt : 4;
  897. u32 : 16;
  898. } *secm_area;
  899. int ret, ccode;
  900. secm_area = page;
  901. secm_area->request.length = 0x0050;
  902. secm_area->request.code = 0x0016;
  903. secm_area->key = PAGE_DEFAULT_KEY;
  904. secm_area->cub_addr1 = (u64)(unsigned long)css->cub_addr1;
  905. secm_area->cub_addr2 = (u64)(unsigned long)css->cub_addr2;
  906. secm_area->operation_code = enable ? 0 : 1;
  907. ccode = chsc(secm_area);
  908. if (ccode > 0)
  909. return (ccode == 3) ? -ENODEV : -EBUSY;
  910. switch (secm_area->response.code) {
  911. case 0x0001: /* Success. */
  912. ret = 0;
  913. break;
  914. case 0x0003: /* Invalid block. */
  915. case 0x0007: /* Invalid format. */
  916. case 0x0008: /* Other invalid block. */
  917. CIO_CRW_EVENT(2, "Error in chsc request block!\n");
  918. ret = -EINVAL;
  919. break;
  920. case 0x0004: /* Command not provided in model. */
  921. CIO_CRW_EVENT(2, "Model does not provide secm\n");
  922. ret = -EOPNOTSUPP;
  923. break;
  924. case 0x0102: /* cub adresses incorrect */
  925. CIO_CRW_EVENT(2, "Invalid addresses in chsc request block\n");
  926. ret = -EINVAL;
  927. break;
  928. case 0x0103: /* key error */
  929. CIO_CRW_EVENT(2, "Access key error in secm\n");
  930. ret = -EINVAL;
  931. break;
  932. case 0x0105: /* error while starting */
  933. CIO_CRW_EVENT(2, "Error while starting channel measurement\n");
  934. ret = -EIO;
  935. break;
  936. default:
  937. CIO_CRW_EVENT(2, "Unknown CHSC response %d\n",
  938. secm_area->response.code);
  939. ret = -EIO;
  940. }
  941. return ret;
  942. }
  943. int
  944. chsc_secm(struct channel_subsystem *css, int enable)
  945. {
  946. void *secm_area;
  947. int ret;
  948. secm_area = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
  949. if (!secm_area)
  950. return -ENOMEM;
  951. mutex_lock(&css->mutex);
  952. if (enable && !css->cm_enabled) {
  953. css->cub_addr1 = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
  954. css->cub_addr2 = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
  955. if (!css->cub_addr1 || !css->cub_addr2) {
  956. free_page((unsigned long)css->cub_addr1);
  957. free_page((unsigned long)css->cub_addr2);
  958. free_page((unsigned long)secm_area);
  959. mutex_unlock(&css->mutex);
  960. return -ENOMEM;
  961. }
  962. }
  963. ret = __chsc_do_secm(css, enable, secm_area);
  964. if (!ret) {
  965. css->cm_enabled = enable;
  966. if (css->cm_enabled) {
  967. ret = chsc_add_cmg_attr(css);
  968. if (ret) {
  969. memset(secm_area, 0, PAGE_SIZE);
  970. __chsc_do_secm(css, 0, secm_area);
  971. css->cm_enabled = 0;
  972. }
  973. } else
  974. chsc_remove_cmg_attr(css);
  975. }
  976. if (enable && !css->cm_enabled) {
  977. free_page((unsigned long)css->cub_addr1);
  978. free_page((unsigned long)css->cub_addr2);
  979. }
  980. mutex_unlock(&css->mutex);
  981. free_page((unsigned long)secm_area);
  982. return ret;
  983. }
  984. /*
  985. * Files for the channel path entries.
  986. */
  987. static ssize_t
  988. chp_status_show(struct device *dev, struct device_attribute *attr, char *buf)
  989. {
  990. struct channel_path *chp = container_of(dev, struct channel_path, dev);
  991. if (!chp)
  992. return 0;
  993. return (get_chp_status(chp->id) ? sprintf(buf, "online\n") :
  994. sprintf(buf, "offline\n"));
  995. }
  996. static ssize_t
  997. chp_status_write(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  998. {
  999. struct channel_path *cp = container_of(dev, struct channel_path, dev);
  1000. char cmd[10];
  1001. int num_args;
  1002. int error;
  1003. num_args = sscanf(buf, "%5s", cmd);
  1004. if (!num_args)
  1005. return count;
  1006. if (!strnicmp(cmd, "on", 2))
  1007. error = s390_vary_chpid(cp->id, 1);
  1008. else if (!strnicmp(cmd, "off", 3))
  1009. error = s390_vary_chpid(cp->id, 0);
  1010. else
  1011. error = -EINVAL;
  1012. return error < 0 ? error : count;
  1013. }
  1014. static DEVICE_ATTR(status, 0644, chp_status_show, chp_status_write);
  1015. static ssize_t
  1016. chp_type_show(struct device *dev, struct device_attribute *attr, char *buf)
  1017. {
  1018. struct channel_path *chp = container_of(dev, struct channel_path, dev);
  1019. if (!chp)
  1020. return 0;
  1021. return sprintf(buf, "%x\n", chp->desc.desc);
  1022. }
  1023. static DEVICE_ATTR(type, 0444, chp_type_show, NULL);
  1024. static ssize_t
  1025. chp_cmg_show(struct device *dev, struct device_attribute *attr, char *buf)
  1026. {
  1027. struct channel_path *chp = to_channelpath(dev);
  1028. if (!chp)
  1029. return 0;
  1030. if (chp->cmg == -1) /* channel measurements not available */
  1031. return sprintf(buf, "unknown\n");
  1032. return sprintf(buf, "%x\n", chp->cmg);
  1033. }
  1034. static DEVICE_ATTR(cmg, 0444, chp_cmg_show, NULL);
  1035. static ssize_t
  1036. chp_shared_show(struct device *dev, struct device_attribute *attr, char *buf)
  1037. {
  1038. struct channel_path *chp = to_channelpath(dev);
  1039. if (!chp)
  1040. return 0;
  1041. if (chp->shared == -1) /* channel measurements not available */
  1042. return sprintf(buf, "unknown\n");
  1043. return sprintf(buf, "%x\n", chp->shared);
  1044. }
  1045. static DEVICE_ATTR(shared, 0444, chp_shared_show, NULL);
  1046. static struct attribute * chp_attrs[] = {
  1047. &dev_attr_status.attr,
  1048. &dev_attr_type.attr,
  1049. &dev_attr_cmg.attr,
  1050. &dev_attr_shared.attr,
  1051. NULL,
  1052. };
  1053. static struct attribute_group chp_attr_group = {
  1054. .attrs = chp_attrs,
  1055. };
  1056. static void
  1057. chp_release(struct device *dev)
  1058. {
  1059. struct channel_path *cp;
  1060. cp = container_of(dev, struct channel_path, dev);
  1061. kfree(cp);
  1062. }
  1063. static int
  1064. chsc_determine_channel_path_description(int chpid,
  1065. struct channel_path_desc *desc)
  1066. {
  1067. int ccode, ret;
  1068. struct {
  1069. struct chsc_header request;
  1070. u32 : 24;
  1071. u32 first_chpid : 8;
  1072. u32 : 24;
  1073. u32 last_chpid : 8;
  1074. u32 zeroes1;
  1075. struct chsc_header response;
  1076. u32 zeroes2;
  1077. struct channel_path_desc desc;
  1078. } *scpd_area;
  1079. scpd_area = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
  1080. if (!scpd_area)
  1081. return -ENOMEM;
  1082. scpd_area->request.length = 0x0010;
  1083. scpd_area->request.code = 0x0002;
  1084. scpd_area->first_chpid = chpid;
  1085. scpd_area->last_chpid = chpid;
  1086. ccode = chsc(scpd_area);
  1087. if (ccode > 0) {
  1088. ret = (ccode == 3) ? -ENODEV : -EBUSY;
  1089. goto out;
  1090. }
  1091. switch (scpd_area->response.code) {
  1092. case 0x0001: /* Success. */
  1093. memcpy(desc, &scpd_area->desc,
  1094. sizeof(struct channel_path_desc));
  1095. ret = 0;
  1096. break;
  1097. case 0x0003: /* Invalid block. */
  1098. case 0x0007: /* Invalid format. */
  1099. case 0x0008: /* Other invalid block. */
  1100. CIO_CRW_EVENT(2, "Error in chsc request block!\n");
  1101. ret = -EINVAL;
  1102. break;
  1103. case 0x0004: /* Command not provided in model. */
  1104. CIO_CRW_EVENT(2, "Model does not provide scpd\n");
  1105. ret = -EOPNOTSUPP;
  1106. break;
  1107. default:
  1108. CIO_CRW_EVENT(2, "Unknown CHSC response %d\n",
  1109. scpd_area->response.code);
  1110. ret = -EIO;
  1111. }
  1112. out:
  1113. free_page((unsigned long)scpd_area);
  1114. return ret;
  1115. }
  1116. static void
  1117. chsc_initialize_cmg_chars(struct channel_path *chp, u8 cmcv,
  1118. struct cmg_chars *chars)
  1119. {
  1120. switch (chp->cmg) {
  1121. case 2:
  1122. case 3:
  1123. chp->cmg_chars = kmalloc(sizeof(struct cmg_chars),
  1124. GFP_KERNEL);
  1125. if (chp->cmg_chars) {
  1126. int i, mask;
  1127. struct cmg_chars *cmg_chars;
  1128. cmg_chars = chp->cmg_chars;
  1129. for (i = 0; i < NR_MEASUREMENT_CHARS; i++) {
  1130. mask = 0x80 >> (i + 3);
  1131. if (cmcv & mask)
  1132. cmg_chars->values[i] = chars->values[i];
  1133. else
  1134. cmg_chars->values[i] = 0;
  1135. }
  1136. }
  1137. break;
  1138. default:
  1139. /* No cmg-dependent data. */
  1140. break;
  1141. }
  1142. }
  1143. static int
  1144. chsc_get_channel_measurement_chars(struct channel_path *chp)
  1145. {
  1146. int ccode, ret;
  1147. struct {
  1148. struct chsc_header request;
  1149. u32 : 24;
  1150. u32 first_chpid : 8;
  1151. u32 : 24;
  1152. u32 last_chpid : 8;
  1153. u32 zeroes1;
  1154. struct chsc_header response;
  1155. u32 zeroes2;
  1156. u32 not_valid : 1;
  1157. u32 shared : 1;
  1158. u32 : 22;
  1159. u32 chpid : 8;
  1160. u32 cmcv : 5;
  1161. u32 : 11;
  1162. u32 cmgq : 8;
  1163. u32 cmg : 8;
  1164. u32 zeroes3;
  1165. u32 data[NR_MEASUREMENT_CHARS];
  1166. } *scmc_area;
  1167. scmc_area = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
  1168. if (!scmc_area)
  1169. return -ENOMEM;
  1170. scmc_area->request.length = 0x0010;
  1171. scmc_area->request.code = 0x0022;
  1172. scmc_area->first_chpid = chp->id;
  1173. scmc_area->last_chpid = chp->id;
  1174. ccode = chsc(scmc_area);
  1175. if (ccode > 0) {
  1176. ret = (ccode == 3) ? -ENODEV : -EBUSY;
  1177. goto out;
  1178. }
  1179. switch (scmc_area->response.code) {
  1180. case 0x0001: /* Success. */
  1181. if (!scmc_area->not_valid) {
  1182. chp->cmg = scmc_area->cmg;
  1183. chp->shared = scmc_area->shared;
  1184. chsc_initialize_cmg_chars(chp, scmc_area->cmcv,
  1185. (struct cmg_chars *)
  1186. &scmc_area->data);
  1187. } else {
  1188. chp->cmg = -1;
  1189. chp->shared = -1;
  1190. }
  1191. ret = 0;
  1192. break;
  1193. case 0x0003: /* Invalid block. */
  1194. case 0x0007: /* Invalid format. */
  1195. case 0x0008: /* Invalid bit combination. */
  1196. CIO_CRW_EVENT(2, "Error in chsc request block!\n");
  1197. ret = -EINVAL;
  1198. break;
  1199. case 0x0004: /* Command not provided. */
  1200. CIO_CRW_EVENT(2, "Model does not provide scmc\n");
  1201. ret = -EOPNOTSUPP;
  1202. break;
  1203. default:
  1204. CIO_CRW_EVENT(2, "Unknown CHSC response %d\n",
  1205. scmc_area->response.code);
  1206. ret = -EIO;
  1207. }
  1208. out:
  1209. free_page((unsigned long)scmc_area);
  1210. return ret;
  1211. }
  1212. /*
  1213. * Entries for chpids on the system bus.
  1214. * This replaces /proc/chpids.
  1215. */
  1216. static int
  1217. new_channel_path(int chpid)
  1218. {
  1219. struct channel_path *chp;
  1220. int ret;
  1221. chp = kzalloc(sizeof(struct channel_path), GFP_KERNEL);
  1222. if (!chp)
  1223. return -ENOMEM;
  1224. /* fill in status, etc. */
  1225. chp->id = chpid;
  1226. chp->state = 1;
  1227. chp->dev.parent = &css[0]->device;
  1228. chp->dev.release = chp_release;
  1229. snprintf(chp->dev.bus_id, BUS_ID_SIZE, "chp0.%x", chpid);
  1230. /* Obtain channel path description and fill it in. */
  1231. ret = chsc_determine_channel_path_description(chpid, &chp->desc);
  1232. if (ret)
  1233. goto out_free;
  1234. /* Get channel-measurement characteristics. */
  1235. if (css_characteristics_avail && css_chsc_characteristics.scmc
  1236. && css_chsc_characteristics.secm) {
  1237. ret = chsc_get_channel_measurement_chars(chp);
  1238. if (ret)
  1239. goto out_free;
  1240. } else {
  1241. static int msg_done;
  1242. if (!msg_done) {
  1243. printk(KERN_WARNING "cio: Channel measurements not "
  1244. "available, continuing.\n");
  1245. msg_done = 1;
  1246. }
  1247. chp->cmg = -1;
  1248. }
  1249. /* make it known to the system */
  1250. ret = device_register(&chp->dev);
  1251. if (ret) {
  1252. printk(KERN_WARNING "%s: could not register %02x\n",
  1253. __func__, chpid);
  1254. goto out_free;
  1255. }
  1256. ret = sysfs_create_group(&chp->dev.kobj, &chp_attr_group);
  1257. if (ret) {
  1258. device_unregister(&chp->dev);
  1259. goto out_free;
  1260. }
  1261. mutex_lock(&css[0]->mutex);
  1262. if (css[0]->cm_enabled) {
  1263. ret = chsc_add_chp_cmg_attr(chp);
  1264. if (ret) {
  1265. sysfs_remove_group(&chp->dev.kobj, &chp_attr_group);
  1266. device_unregister(&chp->dev);
  1267. mutex_unlock(&css[0]->mutex);
  1268. goto out_free;
  1269. }
  1270. }
  1271. css[0]->chps[chpid] = chp;
  1272. mutex_unlock(&css[0]->mutex);
  1273. return ret;
  1274. out_free:
  1275. kfree(chp);
  1276. return ret;
  1277. }
  1278. void *
  1279. chsc_get_chp_desc(struct subchannel *sch, int chp_no)
  1280. {
  1281. struct channel_path *chp;
  1282. struct channel_path_desc *desc;
  1283. chp = css[0]->chps[sch->schib.pmcw.chpid[chp_no]];
  1284. if (!chp)
  1285. return NULL;
  1286. desc = kmalloc(sizeof(struct channel_path_desc), GFP_KERNEL);
  1287. if (!desc)
  1288. return NULL;
  1289. memcpy(desc, &chp->desc, sizeof(struct channel_path_desc));
  1290. return desc;
  1291. }
  1292. static int reset_channel_path(struct channel_path *chp)
  1293. {
  1294. int cc;
  1295. cc = rchp(chp->id);
  1296. switch (cc) {
  1297. case 0:
  1298. return 0;
  1299. case 2:
  1300. return -EBUSY;
  1301. default:
  1302. return -ENODEV;
  1303. }
  1304. }
  1305. static void reset_channel_paths_css(struct channel_subsystem *css)
  1306. {
  1307. int i;
  1308. for (i = 0; i <= __MAX_CHPID; i++) {
  1309. if (css->chps[i])
  1310. reset_channel_path(css->chps[i]);
  1311. }
  1312. }
  1313. void cio_reset_channel_paths(void)
  1314. {
  1315. int i;
  1316. for (i = 0; i <= __MAX_CSSID; i++) {
  1317. if (css[i] && css[i]->valid)
  1318. reset_channel_paths_css(css[i]);
  1319. }
  1320. }
  1321. static int __init
  1322. chsc_alloc_sei_area(void)
  1323. {
  1324. sei_page = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
  1325. if (!sei_page)
  1326. printk(KERN_WARNING"Can't allocate page for processing of " \
  1327. "chsc machine checks!\n");
  1328. return (sei_page ? 0 : -ENOMEM);
  1329. }
  1330. int __init
  1331. chsc_enable_facility(int operation_code)
  1332. {
  1333. int ret;
  1334. struct {
  1335. struct chsc_header request;
  1336. u8 reserved1:4;
  1337. u8 format:4;
  1338. u8 reserved2;
  1339. u16 operation_code;
  1340. u32 reserved3;
  1341. u32 reserved4;
  1342. u32 operation_data_area[252];
  1343. struct chsc_header response;
  1344. u32 reserved5:4;
  1345. u32 format2:4;
  1346. u32 reserved6:24;
  1347. } *sda_area;
  1348. sda_area = (void *)get_zeroed_page(GFP_KERNEL|GFP_DMA);
  1349. if (!sda_area)
  1350. return -ENOMEM;
  1351. sda_area->request.length = 0x0400;
  1352. sda_area->request.code = 0x0031;
  1353. sda_area->operation_code = operation_code;
  1354. ret = chsc(sda_area);
  1355. if (ret > 0) {
  1356. ret = (ret == 3) ? -ENODEV : -EBUSY;
  1357. goto out;
  1358. }
  1359. switch (sda_area->response.code) {
  1360. case 0x0001: /* everything ok */
  1361. ret = 0;
  1362. break;
  1363. case 0x0003: /* invalid request block */
  1364. case 0x0007:
  1365. ret = -EINVAL;
  1366. break;
  1367. case 0x0004: /* command not provided */
  1368. case 0x0101: /* facility not provided */
  1369. ret = -EOPNOTSUPP;
  1370. break;
  1371. default: /* something went wrong */
  1372. ret = -EIO;
  1373. }
  1374. out:
  1375. free_page((unsigned long)sda_area);
  1376. return ret;
  1377. }
  1378. subsys_initcall(chsc_alloc_sei_area);
  1379. struct css_general_char css_general_characteristics;
  1380. struct css_chsc_char css_chsc_characteristics;
  1381. int __init
  1382. chsc_determine_css_characteristics(void)
  1383. {
  1384. int result;
  1385. struct {
  1386. struct chsc_header request;
  1387. u32 reserved1;
  1388. u32 reserved2;
  1389. u32 reserved3;
  1390. struct chsc_header response;
  1391. u32 reserved4;
  1392. u32 general_char[510];
  1393. u32 chsc_char[518];
  1394. } *scsc_area;
  1395. scsc_area = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
  1396. if (!scsc_area) {
  1397. printk(KERN_WARNING"cio: Was not able to determine available" \
  1398. "CHSCs due to no memory.\n");
  1399. return -ENOMEM;
  1400. }
  1401. scsc_area->request.length = 0x0010;
  1402. scsc_area->request.code = 0x0010;
  1403. result = chsc(scsc_area);
  1404. if (result) {
  1405. printk(KERN_WARNING"cio: Was not able to determine " \
  1406. "available CHSCs, cc=%i.\n", result);
  1407. result = -EIO;
  1408. goto exit;
  1409. }
  1410. if (scsc_area->response.code != 1) {
  1411. printk(KERN_WARNING"cio: Was not able to determine " \
  1412. "available CHSCs.\n");
  1413. result = -EIO;
  1414. goto exit;
  1415. }
  1416. memcpy(&css_general_characteristics, scsc_area->general_char,
  1417. sizeof(css_general_characteristics));
  1418. memcpy(&css_chsc_characteristics, scsc_area->chsc_char,
  1419. sizeof(css_chsc_characteristics));
  1420. exit:
  1421. free_page ((unsigned long) scsc_area);
  1422. return result;
  1423. }
  1424. EXPORT_SYMBOL_GPL(css_general_characteristics);
  1425. EXPORT_SYMBOL_GPL(css_chsc_characteristics);