device_id.c 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. /*
  2. * drivers/s390/cio/device_id.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. * Sense ID functions.
  10. */
  11. #include <linux/module.h>
  12. #include <linux/init.h>
  13. #include <linux/kernel.h>
  14. #include <asm/ccwdev.h>
  15. #include <asm/delay.h>
  16. #include <asm/cio.h>
  17. #include <asm/lowcore.h>
  18. #include <asm/diag.h>
  19. #include "cio.h"
  20. #include "cio_debug.h"
  21. #include "css.h"
  22. #include "device.h"
  23. #include "ioasm.h"
  24. #include "io_sch.h"
  25. /*
  26. * Input :
  27. * devno - device number
  28. * ps - pointer to sense ID data area
  29. * Output : none
  30. */
  31. static void
  32. VM_virtual_device_info (__u16 devno, struct senseid *ps)
  33. {
  34. static struct {
  35. int vrdcvcla, vrdcvtyp, cu_type;
  36. } vm_devices[] = {
  37. { 0x08, 0x01, 0x3480 },
  38. { 0x08, 0x02, 0x3430 },
  39. { 0x08, 0x10, 0x3420 },
  40. { 0x08, 0x42, 0x3424 },
  41. { 0x08, 0x44, 0x9348 },
  42. { 0x08, 0x81, 0x3490 },
  43. { 0x08, 0x82, 0x3422 },
  44. { 0x10, 0x41, 0x1403 },
  45. { 0x10, 0x42, 0x3211 },
  46. { 0x10, 0x43, 0x3203 },
  47. { 0x10, 0x45, 0x3800 },
  48. { 0x10, 0x47, 0x3262 },
  49. { 0x10, 0x48, 0x3820 },
  50. { 0x10, 0x49, 0x3800 },
  51. { 0x10, 0x4a, 0x4245 },
  52. { 0x10, 0x4b, 0x4248 },
  53. { 0x10, 0x4d, 0x3800 },
  54. { 0x10, 0x4e, 0x3820 },
  55. { 0x10, 0x4f, 0x3820 },
  56. { 0x10, 0x82, 0x2540 },
  57. { 0x10, 0x84, 0x3525 },
  58. { 0x20, 0x81, 0x2501 },
  59. { 0x20, 0x82, 0x2540 },
  60. { 0x20, 0x84, 0x3505 },
  61. { 0x40, 0x01, 0x3278 },
  62. { 0x40, 0x04, 0x3277 },
  63. { 0x40, 0x80, 0x2250 },
  64. { 0x40, 0xc0, 0x5080 },
  65. { 0x80, 0x00, 0x3215 },
  66. };
  67. struct diag210 diag_data;
  68. int ccode, i;
  69. CIO_TRACE_EVENT (4, "VMvdinf");
  70. diag_data = (struct diag210) {
  71. .vrdcdvno = devno,
  72. .vrdclen = sizeof (diag_data),
  73. };
  74. ccode = diag210 (&diag_data);
  75. ps->reserved = 0xff;
  76. /* Special case for bloody osa devices. */
  77. if (diag_data.vrdcvcla == 0x02 &&
  78. diag_data.vrdcvtyp == 0x20) {
  79. ps->cu_type = 0x3088;
  80. ps->cu_model = 0x60;
  81. return;
  82. }
  83. for (i = 0; i < ARRAY_SIZE(vm_devices); i++)
  84. if (diag_data.vrdcvcla == vm_devices[i].vrdcvcla &&
  85. diag_data.vrdcvtyp == vm_devices[i].vrdcvtyp) {
  86. ps->cu_type = vm_devices[i].cu_type;
  87. return;
  88. }
  89. CIO_MSG_EVENT(0, "DIAG X'210' for device %04X returned (cc = %d):"
  90. "vdev class : %02X, vdev type : %04X \n ... "
  91. "rdev class : %02X, rdev type : %04X, "
  92. "rdev model: %02X\n",
  93. devno, ccode,
  94. diag_data.vrdcvcla, diag_data.vrdcvtyp,
  95. diag_data.vrdcrccl, diag_data.vrdccrty,
  96. diag_data.vrdccrmd);
  97. }
  98. /*
  99. * Start Sense ID helper function.
  100. * Try to obtain the 'control unit'/'device type' information
  101. * associated with the subchannel.
  102. */
  103. static int
  104. __ccw_device_sense_id_start(struct ccw_device *cdev)
  105. {
  106. struct subchannel *sch;
  107. struct ccw1 *ccw;
  108. int ret;
  109. sch = to_subchannel(cdev->dev.parent);
  110. /* Setup sense channel program. */
  111. ccw = cdev->private->iccws;
  112. ccw->cmd_code = CCW_CMD_SENSE_ID;
  113. ccw->cda = (__u32) __pa (&cdev->private->senseid);
  114. ccw->count = sizeof (struct senseid);
  115. ccw->flags = CCW_FLAG_SLI;
  116. /* Reset device status. */
  117. memset(&cdev->private->irb, 0, sizeof(struct irb));
  118. /* Try on every path. */
  119. ret = -ENODEV;
  120. while (cdev->private->imask != 0) {
  121. if ((sch->opm & cdev->private->imask) != 0 &&
  122. cdev->private->iretry > 0) {
  123. cdev->private->iretry--;
  124. /* Reset internal retry indication. */
  125. cdev->private->flags.intretry = 0;
  126. ret = cio_start (sch, cdev->private->iccws,
  127. cdev->private->imask);
  128. /* ret is 0, -EBUSY, -EACCES or -ENODEV */
  129. if (ret != -EACCES)
  130. return ret;
  131. }
  132. cdev->private->imask >>= 1;
  133. cdev->private->iretry = 5;
  134. }
  135. return ret;
  136. }
  137. void
  138. ccw_device_sense_id_start(struct ccw_device *cdev)
  139. {
  140. int ret;
  141. memset (&cdev->private->senseid, 0, sizeof (struct senseid));
  142. cdev->private->senseid.cu_type = 0xFFFF;
  143. cdev->private->imask = 0x80;
  144. cdev->private->iretry = 5;
  145. ret = __ccw_device_sense_id_start(cdev);
  146. if (ret && ret != -EBUSY)
  147. ccw_device_sense_id_done(cdev, ret);
  148. }
  149. /*
  150. * Called from interrupt context to check if a valid answer
  151. * to Sense ID was received.
  152. */
  153. static int
  154. ccw_device_check_sense_id(struct ccw_device *cdev)
  155. {
  156. struct subchannel *sch;
  157. struct irb *irb;
  158. sch = to_subchannel(cdev->dev.parent);
  159. irb = &cdev->private->irb;
  160. /* Did we get a proper answer ? */
  161. if (cdev->private->senseid.cu_type != 0xFFFF &&
  162. cdev->private->senseid.reserved == 0xFF) {
  163. if (irb->scsw.count < sizeof (struct senseid) - 8)
  164. cdev->private->flags.esid = 1;
  165. return 0; /* Success */
  166. }
  167. /* Check the error cases. */
  168. if (irb->scsw.fctl & (SCSW_FCTL_HALT_FUNC | SCSW_FCTL_CLEAR_FUNC)) {
  169. /* Retry Sense ID if requested. */
  170. if (cdev->private->flags.intretry) {
  171. cdev->private->flags.intretry = 0;
  172. return -EAGAIN;
  173. }
  174. return -ETIME;
  175. }
  176. if (irb->esw.esw0.erw.cons && (irb->ecw[0] & SNS0_CMD_REJECT)) {
  177. /*
  178. * if the device doesn't support the SenseID
  179. * command further retries wouldn't help ...
  180. * NB: We don't check here for intervention required like we
  181. * did before, because tape devices with no tape inserted
  182. * may present this status *in conjunction with* the
  183. * sense id information. So, for intervention required,
  184. * we use the "whack it until it talks" strategy...
  185. */
  186. CIO_MSG_EVENT(2, "SenseID : device %04x on Subchannel "
  187. "0.%x.%04x reports cmd reject\n",
  188. cdev->private->dev_id.devno, sch->schid.ssid,
  189. sch->schid.sch_no);
  190. return -EOPNOTSUPP;
  191. }
  192. if (irb->esw.esw0.erw.cons) {
  193. CIO_MSG_EVENT(2, "SenseID : UC on dev 0.%x.%04x, "
  194. "lpum %02X, cnt %02d, sns :"
  195. " %02X%02X%02X%02X %02X%02X%02X%02X ...\n",
  196. cdev->private->dev_id.ssid,
  197. cdev->private->dev_id.devno,
  198. irb->esw.esw0.sublog.lpum,
  199. irb->esw.esw0.erw.scnt,
  200. irb->ecw[0], irb->ecw[1],
  201. irb->ecw[2], irb->ecw[3],
  202. irb->ecw[4], irb->ecw[5],
  203. irb->ecw[6], irb->ecw[7]);
  204. return -EAGAIN;
  205. }
  206. if (irb->scsw.cc == 3) {
  207. u8 lpm;
  208. lpm = to_io_private(sch)->orb.lpm;
  209. if ((lpm & sch->schib.pmcw.pim & sch->schib.pmcw.pam) != 0)
  210. CIO_MSG_EVENT(2, "SenseID : path %02X for device %04x "
  211. "on subchannel 0.%x.%04x is "
  212. "'not operational'\n", lpm,
  213. cdev->private->dev_id.devno,
  214. sch->schid.ssid, sch->schid.sch_no);
  215. return -EACCES;
  216. }
  217. /* Hmm, whatever happened, try again. */
  218. CIO_MSG_EVENT(2, "SenseID : start_IO() for device %04x on "
  219. "subchannel 0.%x.%04x returns status %02X%02X\n",
  220. cdev->private->dev_id.devno, sch->schid.ssid,
  221. sch->schid.sch_no,
  222. irb->scsw.dstat, irb->scsw.cstat);
  223. return -EAGAIN;
  224. }
  225. /*
  226. * Got interrupt for Sense ID.
  227. */
  228. void
  229. ccw_device_sense_id_irq(struct ccw_device *cdev, enum dev_event dev_event)
  230. {
  231. struct subchannel *sch;
  232. struct irb *irb;
  233. int ret;
  234. sch = to_subchannel(cdev->dev.parent);
  235. irb = (struct irb *) __LC_IRB;
  236. /* Retry sense id, if needed. */
  237. if (irb->scsw.stctl ==
  238. (SCSW_STCTL_STATUS_PEND | SCSW_STCTL_ALERT_STATUS)) {
  239. if ((irb->scsw.cc == 1) || !irb->scsw.actl) {
  240. ret = __ccw_device_sense_id_start(cdev);
  241. if (ret && ret != -EBUSY)
  242. ccw_device_sense_id_done(cdev, ret);
  243. }
  244. return;
  245. }
  246. if (ccw_device_accumulate_and_sense(cdev, irb) != 0)
  247. return;
  248. ret = ccw_device_check_sense_id(cdev);
  249. memset(&cdev->private->irb, 0, sizeof(struct irb));
  250. switch (ret) {
  251. /* 0, -ETIME, -EOPNOTSUPP, -EAGAIN or -EACCES */
  252. case 0: /* Sense id succeeded. */
  253. case -ETIME: /* Sense id stopped by timeout. */
  254. ccw_device_sense_id_done(cdev, ret);
  255. break;
  256. case -EACCES: /* channel is not operational. */
  257. sch->lpm &= ~cdev->private->imask;
  258. cdev->private->imask >>= 1;
  259. cdev->private->iretry = 5;
  260. /* fall through. */
  261. case -EAGAIN: /* try again. */
  262. ret = __ccw_device_sense_id_start(cdev);
  263. if (ret == 0 || ret == -EBUSY)
  264. break;
  265. /* fall through. */
  266. default: /* Sense ID failed. Try asking VM. */
  267. if (MACHINE_IS_VM) {
  268. VM_virtual_device_info (cdev->private->dev_id.devno,
  269. &cdev->private->senseid);
  270. if (cdev->private->senseid.cu_type != 0xFFFF) {
  271. /* Got the device information from VM. */
  272. ccw_device_sense_id_done(cdev, 0);
  273. return;
  274. }
  275. }
  276. /*
  277. * If we can't couldn't identify the device type we
  278. * consider the device "not operational".
  279. */
  280. ccw_device_sense_id_done(cdev, -ENODEV);
  281. break;
  282. }
  283. }