device_id.c 9.2 KB

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