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