device_id.c 8.1 KB

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