device_status.c 12 KB

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