device_status.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399
  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. struct subchannel *sch = to_subchannel(cdev->dev.parent);
  26. char dbf_text[15];
  27. if (!scsw_is_valid_cstat(&irb->scsw) ||
  28. !(scsw_cstat(&irb->scsw) & (SCHN_STAT_CHN_DATA_CHK |
  29. SCHN_STAT_CHN_CTRL_CHK | 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, sch->schid.ssid,
  36. sch->schid.sch_no,
  37. scsw_dstat(&irb->scsw), scsw_cstat(&irb->scsw));
  38. sprintf(dbf_text, "chk%x", sch->schid.sch_no);
  39. CIO_TRACE_EVENT(0, dbf_text);
  40. CIO_HEX_EVENT(0, irb, sizeof(struct irb));
  41. }
  42. /*
  43. * Some paths became not operational (pno bit in scsw is set).
  44. */
  45. static void
  46. ccw_device_path_notoper(struct ccw_device *cdev)
  47. {
  48. struct subchannel *sch;
  49. sch = to_subchannel(cdev->dev.parent);
  50. if (cio_update_schib(sch))
  51. goto doverify;
  52. CIO_MSG_EVENT(0, "%s(0.%x.%04x) - path(s) %02x are "
  53. "not operational \n", __func__,
  54. sch->schid.ssid, sch->schid.sch_no,
  55. sch->schib.pmcw.pnom);
  56. sch->lpm &= ~sch->schib.pmcw.pnom;
  57. doverify:
  58. cdev->private->flags.doverify = 1;
  59. }
  60. /*
  61. * Copy valid bits from the extended control word to device irb.
  62. */
  63. static void
  64. ccw_device_accumulate_ecw(struct ccw_device *cdev, struct irb *irb)
  65. {
  66. /*
  67. * Copy extended control bit if it is valid... yes there
  68. * are condition that have to be met for the extended control
  69. * bit to have meaning. Sick.
  70. */
  71. cdev->private->irb.scsw.cmd.ectl = 0;
  72. if ((irb->scsw.cmd.stctl & SCSW_STCTL_ALERT_STATUS) &&
  73. !(irb->scsw.cmd.stctl & SCSW_STCTL_INTER_STATUS))
  74. cdev->private->irb.scsw.cmd.ectl = irb->scsw.cmd.ectl;
  75. /* Check if extended control word is valid. */
  76. if (!cdev->private->irb.scsw.cmd.ectl)
  77. return;
  78. /* Copy concurrent sense / model dependent information. */
  79. memcpy (&cdev->private->irb.ecw, irb->ecw, sizeof (irb->ecw));
  80. }
  81. /*
  82. * Check if extended status word is valid.
  83. */
  84. static int
  85. ccw_device_accumulate_esw_valid(struct irb *irb)
  86. {
  87. if (!irb->scsw.cmd.eswf &&
  88. (irb->scsw.cmd.stctl == SCSW_STCTL_STATUS_PEND))
  89. return 0;
  90. if (irb->scsw.cmd.stctl ==
  91. (SCSW_STCTL_INTER_STATUS|SCSW_STCTL_STATUS_PEND) &&
  92. !(irb->scsw.cmd.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 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.cmd.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.cmd.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.cmd.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 (!(scsw_stctl(&irb->scsw) & 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 (scsw_is_valid_pno(&irb->scsw) && scsw_pno(&irb->scsw))
  187. ccw_device_path_notoper(cdev);
  188. /* No irb accumulation for transport mode irbs. */
  189. if (scsw_is_tm(&irb->scsw)) {
  190. memcpy(&cdev->private->irb, irb, sizeof(struct irb));
  191. return;
  192. }
  193. /*
  194. * Don't accumulate unsolicited interrupts.
  195. */
  196. if (!scsw_is_solicited(&irb->scsw))
  197. return;
  198. cdev_irb = &cdev->private->irb;
  199. /*
  200. * If the clear function had been performed, all formerly pending
  201. * status at the subchannel has been cleared and we must not pass
  202. * intermediate accumulated status to the device driver.
  203. */
  204. if (irb->scsw.cmd.fctl & SCSW_FCTL_CLEAR_FUNC)
  205. memset(&cdev->private->irb, 0, sizeof(struct irb));
  206. /* Copy bits which are valid only for the start function. */
  207. if (irb->scsw.cmd.fctl & SCSW_FCTL_START_FUNC) {
  208. /* Copy key. */
  209. cdev_irb->scsw.cmd.key = irb->scsw.cmd.key;
  210. /* Copy suspend control bit. */
  211. cdev_irb->scsw.cmd.sctl = irb->scsw.cmd.sctl;
  212. /* Accumulate deferred condition code. */
  213. cdev_irb->scsw.cmd.cc |= irb->scsw.cmd.cc;
  214. /* Copy ccw format bit. */
  215. cdev_irb->scsw.cmd.fmt = irb->scsw.cmd.fmt;
  216. /* Copy prefetch bit. */
  217. cdev_irb->scsw.cmd.pfch = irb->scsw.cmd.pfch;
  218. /* Copy initial-status-interruption-control. */
  219. cdev_irb->scsw.cmd.isic = irb->scsw.cmd.isic;
  220. /* Copy address limit checking control. */
  221. cdev_irb->scsw.cmd.alcc = irb->scsw.cmd.alcc;
  222. /* Copy suppress suspend bit. */
  223. cdev_irb->scsw.cmd.ssi = irb->scsw.cmd.ssi;
  224. }
  225. /* Take care of the extended control bit and extended control word. */
  226. ccw_device_accumulate_ecw(cdev, irb);
  227. /* Accumulate function control. */
  228. cdev_irb->scsw.cmd.fctl |= irb->scsw.cmd.fctl;
  229. /* Copy activity control. */
  230. cdev_irb->scsw.cmd.actl = irb->scsw.cmd.actl;
  231. /* Accumulate status control. */
  232. cdev_irb->scsw.cmd.stctl |= irb->scsw.cmd.stctl;
  233. /*
  234. * Copy ccw address if it is valid. This is a bit simplified
  235. * but should be close enough for all practical purposes.
  236. */
  237. if ((irb->scsw.cmd.stctl & SCSW_STCTL_PRIM_STATUS) ||
  238. ((irb->scsw.cmd.stctl ==
  239. (SCSW_STCTL_INTER_STATUS|SCSW_STCTL_STATUS_PEND)) &&
  240. (irb->scsw.cmd.actl & SCSW_ACTL_DEVACT) &&
  241. (irb->scsw.cmd.actl & SCSW_ACTL_SCHACT)) ||
  242. (irb->scsw.cmd.actl & SCSW_ACTL_SUSPENDED))
  243. cdev_irb->scsw.cmd.cpa = irb->scsw.cmd.cpa;
  244. /* Accumulate device status, but not the device busy flag. */
  245. cdev_irb->scsw.cmd.dstat &= ~DEV_STAT_BUSY;
  246. /* dstat is not always valid. */
  247. if (irb->scsw.cmd.stctl &
  248. (SCSW_STCTL_PRIM_STATUS | SCSW_STCTL_SEC_STATUS
  249. | SCSW_STCTL_INTER_STATUS | SCSW_STCTL_ALERT_STATUS))
  250. cdev_irb->scsw.cmd.dstat |= irb->scsw.cmd.dstat;
  251. /* Accumulate subchannel status. */
  252. cdev_irb->scsw.cmd.cstat |= irb->scsw.cmd.cstat;
  253. /* Copy residual count if it is valid. */
  254. if ((irb->scsw.cmd.stctl & SCSW_STCTL_PRIM_STATUS) &&
  255. (irb->scsw.cmd.cstat & ~(SCHN_STAT_PCI | SCHN_STAT_INCORR_LEN))
  256. == 0)
  257. cdev_irb->scsw.cmd.count = irb->scsw.cmd.count;
  258. /* Take care of bits in the extended status word. */
  259. ccw_device_accumulate_esw(cdev, irb);
  260. /*
  261. * Check whether we must issue a SENSE CCW ourselves if there is no
  262. * concurrent sense facility installed for the subchannel.
  263. * No sense is required if no delayed sense is pending
  264. * and we did not get a unit check without sense information.
  265. *
  266. * Note: We should check for ioinfo[irq]->flags.consns but VM
  267. * violates the ESA/390 architecture and doesn't present an
  268. * operand exception for virtual devices without concurrent
  269. * sense facility available/supported when enabling the
  270. * concurrent sense facility.
  271. */
  272. if ((cdev_irb->scsw.cmd.dstat & DEV_STAT_UNIT_CHECK) &&
  273. !(cdev_irb->esw.esw0.erw.cons))
  274. cdev->private->flags.dosense = 1;
  275. }
  276. /*
  277. * Do a basic sense.
  278. */
  279. int
  280. ccw_device_do_sense(struct ccw_device *cdev, struct irb *irb)
  281. {
  282. struct subchannel *sch;
  283. struct ccw1 *sense_ccw;
  284. int rc;
  285. sch = to_subchannel(cdev->dev.parent);
  286. /* A sense is required, can we do it now ? */
  287. if (scsw_actl(&irb->scsw) & (SCSW_ACTL_DEVACT | SCSW_ACTL_SCHACT))
  288. /*
  289. * we received an Unit Check but we have no final
  290. * status yet, therefore we must delay the SENSE
  291. * processing. We must not report this intermediate
  292. * status to the device interrupt handler.
  293. */
  294. return -EBUSY;
  295. /*
  296. * We have ending status but no sense information. Do a basic sense.
  297. */
  298. sense_ccw = &to_io_private(sch)->sense_ccw;
  299. sense_ccw->cmd_code = CCW_CMD_BASIC_SENSE;
  300. sense_ccw->cda = (__u32) __pa(cdev->private->irb.ecw);
  301. sense_ccw->count = SENSE_MAX_COUNT;
  302. sense_ccw->flags = CCW_FLAG_SLI;
  303. rc = cio_start(sch, sense_ccw, 0xff);
  304. if (rc == -ENODEV || rc == -EACCES)
  305. dev_fsm_event(cdev, DEV_EVENT_VERIFY);
  306. return rc;
  307. }
  308. /*
  309. * Add information from basic sense to devstat.
  310. */
  311. void
  312. ccw_device_accumulate_basic_sense(struct ccw_device *cdev, struct irb *irb)
  313. {
  314. /*
  315. * Check if the status pending bit is set in stctl.
  316. * If not, the remaining bit have no meaning and we must ignore them.
  317. * The esw is not meaningful as well...
  318. */
  319. if (!(scsw_stctl(&irb->scsw) & SCSW_STCTL_STATUS_PEND))
  320. return;
  321. /* Check for channel checks and interface control checks. */
  322. ccw_device_msg_control_check(cdev, irb);
  323. /* Check for path not operational. */
  324. if (scsw_is_valid_pno(&irb->scsw) && scsw_pno(&irb->scsw))
  325. ccw_device_path_notoper(cdev);
  326. if (!(irb->scsw.cmd.dstat & DEV_STAT_UNIT_CHECK) &&
  327. (irb->scsw.cmd.dstat & DEV_STAT_CHN_END)) {
  328. cdev->private->irb.esw.esw0.erw.cons = 1;
  329. cdev->private->flags.dosense = 0;
  330. }
  331. /* Check if path verification is required. */
  332. if (ccw_device_accumulate_esw_valid(irb) &&
  333. irb->esw.esw0.erw.pvrf)
  334. cdev->private->flags.doverify = 1;
  335. }
  336. /*
  337. * This function accumulates the status into the private devstat and
  338. * starts a basic sense if one is needed.
  339. */
  340. int
  341. ccw_device_accumulate_and_sense(struct ccw_device *cdev, struct irb *irb)
  342. {
  343. ccw_device_accumulate_irb(cdev, irb);
  344. if ((irb->scsw.cmd.actl & (SCSW_ACTL_DEVACT | SCSW_ACTL_SCHACT)) != 0)
  345. return -EBUSY;
  346. /* Check for basic sense. */
  347. if (cdev->private->flags.dosense &&
  348. !(irb->scsw.cmd.dstat & DEV_STAT_UNIT_CHECK)) {
  349. cdev->private->irb.esw.esw0.erw.cons = 1;
  350. cdev->private->flags.dosense = 0;
  351. return 0;
  352. }
  353. if (cdev->private->flags.dosense) {
  354. ccw_device_do_sense(cdev, irb);
  355. return -EBUSY;
  356. }
  357. return 0;
  358. }