device_id.c 9.1 KB

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