device_id.c 8.5 KB

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