device_id.c 5.9 KB

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