device_status.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385
  1. /*
  2. * drivers/s390/cio/device_status.c
  3. *
  4. * Copyright (C) 2002 IBM Deutschland Entwicklung GmbH,
  5. * IBM Corporation
  6. * Author(s): Cornelia Huck(cohuck@de.ibm.com)
  7. * Martin Schwidefsky (schwidefsky@de.ibm.com)
  8. *
  9. * Status accumulation and basic sense functions.
  10. */
  11. #include <linux/config.h>
  12. #include <linux/module.h>
  13. #include <linux/init.h>
  14. #include <asm/ccwdev.h>
  15. #include <asm/cio.h>
  16. #include "cio.h"
  17. #include "cio_debug.h"
  18. #include "css.h"
  19. #include "device.h"
  20. #include "ioasm.h"
  21. /*
  22. * Check for any kind of channel or interface control check but don't
  23. * issue the message for the console device
  24. */
  25. static inline void
  26. ccw_device_msg_control_check(struct ccw_device *cdev, struct irb *irb)
  27. {
  28. if (!(irb->scsw.cstat & (SCHN_STAT_CHN_DATA_CHK |
  29. SCHN_STAT_CHN_CTRL_CHK |
  30. SCHN_STAT_INTF_CTRL_CHK)))
  31. return;
  32. CIO_MSG_EVENT(0, "Channel-Check or Interface-Control-Check "
  33. "received"
  34. " ... device %04X on subchannel %04X, dev_stat "
  35. ": %02X sch_stat : %02X\n",
  36. cdev->private->devno, cdev->private->irq,
  37. cdev->private->irb.scsw.dstat,
  38. cdev->private->irb.scsw.cstat);
  39. if (irb->scsw.cc != 3) {
  40. char dbf_text[15];
  41. sprintf(dbf_text, "chk%x", cdev->private->irq);
  42. CIO_TRACE_EVENT(0, dbf_text);
  43. CIO_HEX_EVENT(0, &cdev->private->irb, sizeof (struct irb));
  44. }
  45. }
  46. /*
  47. * Some paths became not operational (pno bit in scsw is set).
  48. */
  49. static void
  50. ccw_device_path_notoper(struct ccw_device *cdev)
  51. {
  52. struct subchannel *sch;
  53. sch = to_subchannel(cdev->dev.parent);
  54. stsch (sch->irq, &sch->schib);
  55. CIO_MSG_EVENT(0, "%s(%04x) - path(s) %02x are "
  56. "not operational \n", __FUNCTION__, sch->irq,
  57. sch->schib.pmcw.pnom);
  58. sch->lpm &= ~sch->schib.pmcw.pnom;
  59. if (cdev->private->options.pgroup)
  60. cdev->private->flags.doverify = 1;
  61. }
  62. /*
  63. * Copy valid bits from the extended control word to device irb.
  64. */
  65. static inline void
  66. ccw_device_accumulate_ecw(struct ccw_device *cdev, struct irb *irb)
  67. {
  68. /*
  69. * Copy extended control bit if it is valid... yes there
  70. * are condition that have to be met for the extended control
  71. * bit to have meaning. Sick.
  72. */
  73. cdev->private->irb.scsw.ectl = 0;
  74. if ((irb->scsw.stctl & SCSW_STCTL_ALERT_STATUS) &&
  75. !(irb->scsw.stctl & SCSW_STCTL_INTER_STATUS))
  76. cdev->private->irb.scsw.ectl = irb->scsw.ectl;
  77. /* Check if extended control word is valid. */
  78. if (!cdev->private->irb.scsw.ectl)
  79. return;
  80. /* Copy concurrent sense / model dependent information. */
  81. memcpy (&cdev->private->irb.ecw, irb->ecw, sizeof (irb->ecw));
  82. }
  83. /*
  84. * Check if extended status word is valid.
  85. */
  86. static inline int
  87. ccw_device_accumulate_esw_valid(struct irb *irb)
  88. {
  89. if (!irb->scsw.eswf && irb->scsw.stctl == SCSW_STCTL_STATUS_PEND)
  90. return 0;
  91. if (irb->scsw.stctl ==
  92. (SCSW_STCTL_INTER_STATUS|SCSW_STCTL_STATUS_PEND) &&
  93. !(irb->scsw.actl & SCSW_ACTL_SUSPENDED))
  94. return 0;
  95. return 1;
  96. }
  97. /*
  98. * Copy valid bits from the extended status word to device irb.
  99. */
  100. static inline void
  101. ccw_device_accumulate_esw(struct ccw_device *cdev, struct irb *irb)
  102. {
  103. struct irb *cdev_irb;
  104. struct sublog *cdev_sublog, *sublog;
  105. if (!ccw_device_accumulate_esw_valid(irb))
  106. return;
  107. cdev_irb = &cdev->private->irb;
  108. /* Copy last path used mask. */
  109. cdev_irb->esw.esw1.lpum = irb->esw.esw1.lpum;
  110. /* Copy subchannel logout information if esw is of format 0. */
  111. if (irb->scsw.eswf) {
  112. cdev_sublog = &cdev_irb->esw.esw0.sublog;
  113. sublog = &irb->esw.esw0.sublog;
  114. /* Copy extended status flags. */
  115. cdev_sublog->esf = sublog->esf;
  116. /*
  117. * Copy fields that have a meaning for channel data check
  118. * channel control check and interface control check.
  119. */
  120. if (irb->scsw.cstat & (SCHN_STAT_CHN_DATA_CHK |
  121. SCHN_STAT_CHN_CTRL_CHK |
  122. SCHN_STAT_INTF_CTRL_CHK)) {
  123. /* Copy ancillary report bit. */
  124. cdev_sublog->arep = sublog->arep;
  125. /* Copy field-validity-flags. */
  126. cdev_sublog->fvf = sublog->fvf;
  127. /* Copy storage access code. */
  128. cdev_sublog->sacc = sublog->sacc;
  129. /* Copy termination code. */
  130. cdev_sublog->termc = sublog->termc;
  131. /* Copy sequence code. */
  132. cdev_sublog->seqc = sublog->seqc;
  133. }
  134. /* Copy device status check. */
  135. cdev_sublog->devsc = sublog->devsc;
  136. /* Copy secondary error. */
  137. cdev_sublog->serr = sublog->serr;
  138. /* Copy i/o-error alert. */
  139. cdev_sublog->ioerr = sublog->ioerr;
  140. /* Copy channel path timeout bit. */
  141. if (irb->scsw.cstat & SCHN_STAT_INTF_CTRL_CHK)
  142. cdev_irb->esw.esw0.erw.cpt = irb->esw.esw0.erw.cpt;
  143. /* Copy failing storage address validity flag. */
  144. cdev_irb->esw.esw0.erw.fsavf = irb->esw.esw0.erw.fsavf;
  145. if (cdev_irb->esw.esw0.erw.fsavf) {
  146. /* ... and copy the failing storage address. */
  147. memcpy(cdev_irb->esw.esw0.faddr, irb->esw.esw0.faddr,
  148. sizeof (irb->esw.esw0.faddr));
  149. /* ... and copy the failing storage address format. */
  150. cdev_irb->esw.esw0.erw.fsaf = irb->esw.esw0.erw.fsaf;
  151. }
  152. /* Copy secondary ccw address validity bit. */
  153. cdev_irb->esw.esw0.erw.scavf = irb->esw.esw0.erw.scavf;
  154. if (irb->esw.esw0.erw.scavf)
  155. /* ... and copy the secondary ccw address. */
  156. cdev_irb->esw.esw0.saddr = irb->esw.esw0.saddr;
  157. }
  158. /* FIXME: DCTI for format 2? */
  159. /* Copy authorization bit. */
  160. cdev_irb->esw.esw0.erw.auth = irb->esw.esw0.erw.auth;
  161. /* Copy path verification required flag. */
  162. cdev_irb->esw.esw0.erw.pvrf = irb->esw.esw0.erw.pvrf;
  163. if (irb->esw.esw0.erw.pvrf && cdev->private->options.pgroup)
  164. cdev->private->flags.doverify = 1;
  165. /* Copy concurrent sense bit. */
  166. cdev_irb->esw.esw0.erw.cons = irb->esw.esw0.erw.cons;
  167. if (irb->esw.esw0.erw.cons)
  168. cdev_irb->esw.esw0.erw.scnt = irb->esw.esw0.erw.scnt;
  169. }
  170. /*
  171. * Accumulate status from irb to devstat.
  172. */
  173. void
  174. ccw_device_accumulate_irb(struct ccw_device *cdev, struct irb *irb)
  175. {
  176. struct irb *cdev_irb;
  177. /*
  178. * Check if the status pending bit is set in stctl.
  179. * If not, the remaining bit have no meaning and we must ignore them.
  180. * The esw is not meaningful as well...
  181. */
  182. if (!(irb->scsw.stctl & SCSW_STCTL_STATUS_PEND))
  183. return;
  184. /* Check for channel checks and interface control checks. */
  185. ccw_device_msg_control_check(cdev, irb);
  186. /* Check for path not operational. */
  187. if (irb->scsw.pno && irb->scsw.fctl != 0 &&
  188. (!(irb->scsw.stctl & SCSW_STCTL_INTER_STATUS) ||
  189. (irb->scsw.actl & SCSW_ACTL_SUSPENDED)))
  190. ccw_device_path_notoper(cdev);
  191. /*
  192. * Don't accumulate unsolicited interrupts.
  193. */
  194. if ((irb->scsw.stctl ==
  195. (SCSW_STCTL_STATUS_PEND | SCSW_STCTL_ALERT_STATUS)) &&
  196. (!irb->scsw.cc))
  197. return;
  198. cdev_irb = &cdev->private->irb;
  199. /* Copy bits which are valid only for the start function. */
  200. if (irb->scsw.fctl & SCSW_FCTL_START_FUNC) {
  201. /* Copy key. */
  202. cdev_irb->scsw.key = irb->scsw.key;
  203. /* Copy suspend control bit. */
  204. cdev_irb->scsw.sctl = irb->scsw.sctl;
  205. /* Accumulate deferred condition code. */
  206. cdev_irb->scsw.cc |= irb->scsw.cc;
  207. /* Copy ccw format bit. */
  208. cdev_irb->scsw.fmt = irb->scsw.fmt;
  209. /* Copy prefetch bit. */
  210. cdev_irb->scsw.pfch = irb->scsw.pfch;
  211. /* Copy initial-status-interruption-control. */
  212. cdev_irb->scsw.isic = irb->scsw.isic;
  213. /* Copy address limit checking control. */
  214. cdev_irb->scsw.alcc = irb->scsw.alcc;
  215. /* Copy suppress suspend bit. */
  216. cdev_irb->scsw.ssi = irb->scsw.ssi;
  217. }
  218. /* Take care of the extended control bit and extended control word. */
  219. ccw_device_accumulate_ecw(cdev, irb);
  220. /* Accumulate function control. */
  221. cdev_irb->scsw.fctl |= irb->scsw.fctl;
  222. /* Copy activity control. */
  223. cdev_irb->scsw.actl= irb->scsw.actl;
  224. /* Accumulate status control. */
  225. cdev_irb->scsw.stctl |= irb->scsw.stctl;
  226. /*
  227. * Copy ccw address if it is valid. This is a bit simplified
  228. * but should be close enough for all practical purposes.
  229. */
  230. if ((irb->scsw.stctl & SCSW_STCTL_PRIM_STATUS) ||
  231. ((irb->scsw.stctl ==
  232. (SCSW_STCTL_INTER_STATUS|SCSW_STCTL_STATUS_PEND)) &&
  233. (irb->scsw.actl & SCSW_ACTL_DEVACT) &&
  234. (irb->scsw.actl & SCSW_ACTL_SCHACT)) ||
  235. (irb->scsw.actl & SCSW_ACTL_SUSPENDED))
  236. cdev_irb->scsw.cpa = irb->scsw.cpa;
  237. /* Accumulate device status, but not the device busy flag. */
  238. cdev_irb->scsw.dstat &= ~DEV_STAT_BUSY;
  239. cdev_irb->scsw.dstat |= irb->scsw.dstat;
  240. /* Accumulate subchannel status. */
  241. cdev_irb->scsw.cstat |= irb->scsw.cstat;
  242. /* Copy residual count if it is valid. */
  243. if ((irb->scsw.stctl & SCSW_STCTL_PRIM_STATUS) &&
  244. (irb->scsw.cstat & ~(SCHN_STAT_PCI | SCHN_STAT_INCORR_LEN)) == 0)
  245. cdev_irb->scsw.count = irb->scsw.count;
  246. /* Take care of bits in the extended status word. */
  247. ccw_device_accumulate_esw(cdev, irb);
  248. /*
  249. * Check whether we must issue a SENSE CCW ourselves if there is no
  250. * concurrent sense facility installed for the subchannel.
  251. * No sense is required if no delayed sense is pending
  252. * and we did not get a unit check without sense information.
  253. *
  254. * Note: We should check for ioinfo[irq]->flags.consns but VM
  255. * violates the ESA/390 architecture and doesn't present an
  256. * operand exception for virtual devices without concurrent
  257. * sense facility available/supported when enabling the
  258. * concurrent sense facility.
  259. */
  260. if ((cdev_irb->scsw.dstat & DEV_STAT_UNIT_CHECK) &&
  261. !(cdev_irb->esw.esw0.erw.cons))
  262. cdev->private->flags.dosense = 1;
  263. }
  264. /*
  265. * Do a basic sense.
  266. */
  267. int
  268. ccw_device_do_sense(struct ccw_device *cdev, struct irb *irb)
  269. {
  270. struct subchannel *sch;
  271. sch = to_subchannel(cdev->dev.parent);
  272. /* A sense is required, can we do it now ? */
  273. if ((irb->scsw.actl & (SCSW_ACTL_DEVACT | SCSW_ACTL_SCHACT)) != 0)
  274. /*
  275. * we received an Unit Check but we have no final
  276. * status yet, therefore we must delay the SENSE
  277. * processing. We must not report this intermediate
  278. * status to the device interrupt handler.
  279. */
  280. return -EBUSY;
  281. /*
  282. * We have ending status but no sense information. Do a basic sense.
  283. */
  284. sch = to_subchannel(cdev->dev.parent);
  285. sch->sense_ccw.cmd_code = CCW_CMD_BASIC_SENSE;
  286. sch->sense_ccw.cda = (__u32) __pa(cdev->private->irb.ecw);
  287. sch->sense_ccw.count = SENSE_MAX_COUNT;
  288. sch->sense_ccw.flags = CCW_FLAG_SLI;
  289. return cio_start (sch, &sch->sense_ccw, 0xff);
  290. }
  291. /*
  292. * Add information from basic sense to devstat.
  293. */
  294. void
  295. ccw_device_accumulate_basic_sense(struct ccw_device *cdev, struct irb *irb)
  296. {
  297. /*
  298. * Check if the status pending bit is set in stctl.
  299. * If not, the remaining bit have no meaning and we must ignore them.
  300. * The esw is not meaningful as well...
  301. */
  302. if (!(irb->scsw.stctl & SCSW_STCTL_STATUS_PEND))
  303. return;
  304. /* Check for channel checks and interface control checks. */
  305. ccw_device_msg_control_check(cdev, irb);
  306. /* Check for path not operational. */
  307. if (irb->scsw.pno && irb->scsw.fctl != 0 &&
  308. (!(irb->scsw.stctl & SCSW_STCTL_INTER_STATUS) ||
  309. (irb->scsw.actl & SCSW_ACTL_SUSPENDED)))
  310. ccw_device_path_notoper(cdev);
  311. if (!(irb->scsw.dstat & DEV_STAT_UNIT_CHECK) &&
  312. (irb->scsw.dstat & DEV_STAT_CHN_END)) {
  313. cdev->private->irb.esw.esw0.erw.cons = 1;
  314. cdev->private->flags.dosense = 0;
  315. }
  316. /* Check if path verification is required. */
  317. if (ccw_device_accumulate_esw_valid(irb) &&
  318. irb->esw.esw0.erw.pvrf && cdev->private->options.pgroup)
  319. cdev->private->flags.doverify = 1;
  320. }
  321. /*
  322. * This function accumulates the status into the private devstat and
  323. * starts a basic sense if one is needed.
  324. */
  325. int
  326. ccw_device_accumulate_and_sense(struct ccw_device *cdev, struct irb *irb)
  327. {
  328. ccw_device_accumulate_irb(cdev, irb);
  329. if ((irb->scsw.actl & (SCSW_ACTL_DEVACT | SCSW_ACTL_SCHACT)) != 0)
  330. return -EBUSY;
  331. /* Check for basic sense. */
  332. if (cdev->private->flags.dosense &&
  333. !(irb->scsw.dstat & DEV_STAT_UNIT_CHECK)) {
  334. cdev->private->irb.esw.esw0.erw.cons = 1;
  335. cdev->private->flags.dosense = 0;
  336. return 0;
  337. }
  338. if (cdev->private->flags.dosense) {
  339. ccw_device_do_sense(cdev, irb);
  340. return -EBUSY;
  341. }
  342. return 0;
  343. }