device_status.c 11 KB

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