device_id.c 9.1 KB

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