chsc.c 35 KB

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