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