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