device_id.c 9.0 KB

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