device_id.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. /*
  2. * CCW device SENSE ID I/O handling.
  3. *
  4. * Copyright IBM Corp. 2002, 2009
  5. * Author(s): Cornelia Huck <cornelia.huck@de.ibm.com>
  6. * Martin Schwidefsky <schwidefsky@de.ibm.com>
  7. * Peter Oberparleiter <peter.oberparleiter@de.ibm.com>
  8. */
  9. #include <linux/kernel.h>
  10. #include <linux/string.h>
  11. #include <linux/types.h>
  12. #include <linux/errno.h>
  13. #include <asm/ccwdev.h>
  14. #include <asm/setup.h>
  15. #include <asm/cio.h>
  16. #include <asm/diag.h>
  17. #include "cio.h"
  18. #include "cio_debug.h"
  19. #include "device.h"
  20. #include "io_sch.h"
  21. #define SENSE_ID_RETRIES 256
  22. #define SENSE_ID_TIMEOUT (10 * HZ)
  23. #define SENSE_ID_MIN_LEN 4
  24. #define SENSE_ID_BASIC_LEN 7
  25. /**
  26. * diag210_to_senseid - convert diag 0x210 data to sense id information
  27. * @senseid: sense id
  28. * @diag: diag 0x210 data
  29. *
  30. * Return 0 on success, non-zero otherwise.
  31. */
  32. static int diag210_to_senseid(struct senseid *senseid, struct diag210 *diag)
  33. {
  34. static struct {
  35. int class, type, cu_type;
  36. } vm_devices[] = {
  37. { 0x08, 0x01, 0x3480 },
  38. { 0x08, 0x02, 0x3430 },
  39. { 0x08, 0x10, 0x3420 },
  40. { 0x08, 0x42, 0x3424 },
  41. { 0x08, 0x44, 0x9348 },
  42. { 0x08, 0x81, 0x3490 },
  43. { 0x08, 0x82, 0x3422 },
  44. { 0x10, 0x41, 0x1403 },
  45. { 0x10, 0x42, 0x3211 },
  46. { 0x10, 0x43, 0x3203 },
  47. { 0x10, 0x45, 0x3800 },
  48. { 0x10, 0x47, 0x3262 },
  49. { 0x10, 0x48, 0x3820 },
  50. { 0x10, 0x49, 0x3800 },
  51. { 0x10, 0x4a, 0x4245 },
  52. { 0x10, 0x4b, 0x4248 },
  53. { 0x10, 0x4d, 0x3800 },
  54. { 0x10, 0x4e, 0x3820 },
  55. { 0x10, 0x4f, 0x3820 },
  56. { 0x10, 0x82, 0x2540 },
  57. { 0x10, 0x84, 0x3525 },
  58. { 0x20, 0x81, 0x2501 },
  59. { 0x20, 0x82, 0x2540 },
  60. { 0x20, 0x84, 0x3505 },
  61. { 0x40, 0x01, 0x3278 },
  62. { 0x40, 0x04, 0x3277 },
  63. { 0x40, 0x80, 0x2250 },
  64. { 0x40, 0xc0, 0x5080 },
  65. { 0x80, 0x00, 0x3215 },
  66. };
  67. int i;
  68. /* Special case for osa devices. */
  69. if (diag->vrdcvcla == 0x02 && diag->vrdcvtyp == 0x20) {
  70. senseid->cu_type = 0x3088;
  71. senseid->cu_model = 0x60;
  72. senseid->reserved = 0xff;
  73. return 0;
  74. }
  75. for (i = 0; i < ARRAY_SIZE(vm_devices); i++) {
  76. if (diag->vrdcvcla == vm_devices[i].class &&
  77. diag->vrdcvtyp == vm_devices[i].type) {
  78. senseid->cu_type = vm_devices[i].cu_type;
  79. senseid->reserved = 0xff;
  80. return 0;
  81. }
  82. }
  83. return -ENODEV;
  84. }
  85. /**
  86. * diag_get_dev_info - retrieve device information via diag 0x210
  87. * @cdev: ccw device
  88. *
  89. * Returns zero on success, non-zero otherwise.
  90. */
  91. static int diag210_get_dev_info(struct ccw_device *cdev)
  92. {
  93. struct ccw_dev_id *dev_id = &cdev->private->dev_id;
  94. struct senseid *senseid = &cdev->private->senseid;
  95. struct diag210 diag_data;
  96. int rc;
  97. if (dev_id->ssid != 0)
  98. return -ENODEV;
  99. memset(&diag_data, 0, sizeof(diag_data));
  100. diag_data.vrdcdvno = dev_id->devno;
  101. diag_data.vrdclen = sizeof(diag_data);
  102. rc = diag210(&diag_data);
  103. CIO_TRACE_EVENT(4, "diag210");
  104. CIO_HEX_EVENT(4, &rc, sizeof(rc));
  105. CIO_HEX_EVENT(4, &diag_data, sizeof(diag_data));
  106. if (rc != 0 && rc != 2)
  107. goto err_failed;
  108. if (diag210_to_senseid(senseid, &diag_data))
  109. goto err_unknown;
  110. return 0;
  111. err_unknown:
  112. CIO_MSG_EVENT(0, "snsid: device 0.%x.%04x: unknown diag210 data\n",
  113. dev_id->ssid, dev_id->devno);
  114. return -ENODEV;
  115. err_failed:
  116. CIO_MSG_EVENT(0, "snsid: device 0.%x.%04x: diag210 failed (rc=%d)\n",
  117. dev_id->ssid, dev_id->devno, rc);
  118. return -ENODEV;
  119. }
  120. /*
  121. * Initialize SENSE ID data.
  122. */
  123. static void snsid_init(struct ccw_device *cdev)
  124. {
  125. cdev->private->flags.esid = 0;
  126. memset(&cdev->private->senseid, 0, sizeof(cdev->private->senseid));
  127. cdev->private->senseid.cu_type = 0xffff;
  128. }
  129. /*
  130. * Check for complete SENSE ID data.
  131. */
  132. static int snsid_check(struct ccw_device *cdev, void *data)
  133. {
  134. struct cmd_scsw *scsw = &cdev->private->irb.scsw.cmd;
  135. int len = sizeof(struct senseid) - scsw->count;
  136. /* Check for incomplete SENSE ID data. */
  137. if (len < SENSE_ID_MIN_LEN)
  138. goto out_restart;
  139. if (cdev->private->senseid.cu_type == 0xffff)
  140. goto out_restart;
  141. /* Check for incompatible SENSE ID data. */
  142. if (cdev->private->senseid.reserved != 0xff)
  143. return -EOPNOTSUPP;
  144. /* Check for extended-identification information. */
  145. if (len > SENSE_ID_BASIC_LEN)
  146. cdev->private->flags.esid = 1;
  147. return 0;
  148. out_restart:
  149. snsid_init(cdev);
  150. return -EAGAIN;
  151. }
  152. /*
  153. * Process SENSE ID request result.
  154. */
  155. static void snsid_callback(struct ccw_device *cdev, void *data, int rc)
  156. {
  157. struct ccw_dev_id *id = &cdev->private->dev_id;
  158. struct senseid *senseid = &cdev->private->senseid;
  159. int vm = 0;
  160. if (rc && MACHINE_IS_VM) {
  161. /* Try diag 0x210 fallback on z/VM. */
  162. snsid_init(cdev);
  163. if (diag210_get_dev_info(cdev) == 0) {
  164. rc = 0;
  165. vm = 1;
  166. }
  167. }
  168. CIO_MSG_EVENT(2, "snsid: device 0.%x.%04x: rc=%d %04x/%02x "
  169. "%04x/%02x%s\n", id->ssid, id->devno, rc,
  170. senseid->cu_type, senseid->cu_model, senseid->dev_type,
  171. senseid->dev_model, vm ? " (diag210)" : "");
  172. ccw_device_sense_id_done(cdev, rc);
  173. }
  174. /**
  175. * ccw_device_sense_id_start - perform SENSE ID
  176. * @cdev: ccw device
  177. *
  178. * Execute a SENSE ID channel program on @cdev to update its sense id
  179. * information. When finished, call ccw_device_sense_id_done with a
  180. * return code specifying the result.
  181. */
  182. void ccw_device_sense_id_start(struct ccw_device *cdev)
  183. {
  184. struct subchannel *sch = to_subchannel(cdev->dev.parent);
  185. struct ccw_request *req = &cdev->private->req;
  186. struct ccw1 *cp = cdev->private->iccws;
  187. CIO_TRACE_EVENT(4, "snsid");
  188. CIO_HEX_EVENT(4, &cdev->private->dev_id, sizeof(cdev->private->dev_id));
  189. /* Data setup. */
  190. snsid_init(cdev);
  191. /* Channel program setup. */
  192. cp->cmd_code = CCW_CMD_SENSE_ID;
  193. cp->cda = (u32) (addr_t) &cdev->private->senseid;
  194. cp->count = sizeof(struct senseid);
  195. cp->flags = CCW_FLAG_SLI;
  196. /* Request setup. */
  197. memset(req, 0, sizeof(*req));
  198. req->cp = cp;
  199. req->timeout = SENSE_ID_TIMEOUT;
  200. req->maxretries = SENSE_ID_RETRIES;
  201. req->lpm = sch->schib.pmcw.pam & sch->opm;
  202. req->check = snsid_check;
  203. req->callback = snsid_callback;
  204. ccw_request_start(cdev);
  205. }