chsc.c 36 KB

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