device_status.c 12 KB

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