device_id.c 9.1 KB

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