Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Peter Oberparleiter | 9679baa | 2009-12-07 12:51:27 +0100 | [diff] [blame] | 2 | * CCW device PGID and path verification I/O handling. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | * |
Peter Oberparleiter | 9679baa | 2009-12-07 12:51:27 +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 | |
Peter Oberparleiter | 9679baa | 2009-12-07 12:51:27 +0100 | [diff] [blame] | 10 | #include <linux/kernel.h> |
| 11 | #include <linux/string.h> |
| 12 | #include <linux/types.h> |
| 13 | #include <linux/errno.h> |
| 14 | #include <linux/bitops.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | #include <asm/ccwdev.h> |
| 16 | #include <asm/cio.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | |
| 18 | #include "cio.h" |
| 19 | #include "cio_debug.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | #include "device.h" |
Cornelia Huck | cd6b4f2 | 2008-01-26 14:10:43 +0100 | [diff] [blame] | 21 | #include "io_sch.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | |
Peter Oberparleiter | de1b043 | 2009-12-07 12:51:40 +0100 | [diff] [blame] | 23 | #define PGID_RETRIES 256 |
Peter Oberparleiter | 9679baa | 2009-12-07 12:51:27 +0100 | [diff] [blame] | 24 | #define PGID_TIMEOUT (10 * HZ) |
Stefan Bader | 7b7db1b | 2006-08-30 14:33:39 +0200 | [diff] [blame] | 25 | |
| 26 | /* |
Peter Oberparleiter | 9679baa | 2009-12-07 12:51:27 +0100 | [diff] [blame] | 27 | * Process path verification data and report result. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | */ |
Peter Oberparleiter | 9679baa | 2009-12-07 12:51:27 +0100 | [diff] [blame] | 29 | static void verify_done(struct ccw_device *cdev, int rc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | { |
Cornelia Huck | 6810a2b | 2006-01-06 00:19:13 -0800 | [diff] [blame] | 31 | struct subchannel *sch = to_subchannel(cdev->dev.parent); |
Peter Oberparleiter | 9679baa | 2009-12-07 12:51:27 +0100 | [diff] [blame] | 32 | struct ccw_dev_id *id = &cdev->private->dev_id; |
Peter Oberparleiter | 454e1fa | 2009-12-07 12:51:30 +0100 | [diff] [blame] | 33 | int mpath = cdev->private->flags.mpath; |
| 34 | int pgroup = cdev->private->flags.pgroup; |
Cornelia Huck | 6810a2b | 2006-01-06 00:19:13 -0800 | [diff] [blame] | 35 | |
Peter Oberparleiter | 9679baa | 2009-12-07 12:51:27 +0100 | [diff] [blame] | 36 | if (rc) |
| 37 | goto out; |
| 38 | /* Ensure consistent multipathing state at device and channel. */ |
| 39 | if (sch->config.mp != mpath) { |
| 40 | sch->config.mp = mpath; |
| 41 | rc = cio_commit_config(sch); |
Cornelia Huck | 6810a2b | 2006-01-06 00:19:13 -0800 | [diff] [blame] | 42 | } |
Peter Oberparleiter | 9679baa | 2009-12-07 12:51:27 +0100 | [diff] [blame] | 43 | out: |
| 44 | CIO_MSG_EVENT(2, "vrfy: device 0.%x.%04x: rc=%d pgroup=%d mpath=%d " |
| 45 | "vpm=%02x\n", id->ssid, id->devno, rc, pgroup, mpath, |
| 46 | sch->vpm); |
| 47 | ccw_device_verify_done(cdev, rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | } |
| 49 | |
| 50 | /* |
Peter Oberparleiter | 9679baa | 2009-12-07 12:51:27 +0100 | [diff] [blame] | 51 | * Create channel program to perform a NOOP. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | */ |
Peter Oberparleiter | 9679baa | 2009-12-07 12:51:27 +0100 | [diff] [blame] | 53 | static void nop_build_cp(struct ccw_device *cdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | { |
Peter Oberparleiter | 9679baa | 2009-12-07 12:51:27 +0100 | [diff] [blame] | 55 | struct ccw_request *req = &cdev->private->req; |
| 56 | struct ccw1 *cp = cdev->private->iccws; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | |
Peter Oberparleiter | 9679baa | 2009-12-07 12:51:27 +0100 | [diff] [blame] | 58 | cp->cmd_code = CCW_CMD_NOOP; |
| 59 | cp->cda = 0; |
| 60 | cp->count = 0; |
| 61 | cp->flags = CCW_FLAG_SLI; |
| 62 | req->cp = cp; |
| 63 | } |
Stefan Bader | 7b7db1b | 2006-08-30 14:33:39 +0200 | [diff] [blame] | 64 | |
Peter Oberparleiter | 9679baa | 2009-12-07 12:51:27 +0100 | [diff] [blame] | 65 | /* |
| 66 | * Perform NOOP on a single path. |
| 67 | */ |
| 68 | static void nop_do(struct ccw_device *cdev) |
| 69 | { |
| 70 | struct subchannel *sch = to_subchannel(cdev->dev.parent); |
| 71 | struct ccw_request *req = &cdev->private->req; |
| 72 | |
| 73 | /* Adjust lpm. */ |
| 74 | req->lpm = lpm_adjust(req->lpm, sch->schib.pmcw.pam & sch->opm); |
| 75 | if (!req->lpm) |
| 76 | goto out_nopath; |
| 77 | nop_build_cp(cdev); |
| 78 | ccw_request_start(cdev); |
| 79 | return; |
| 80 | |
| 81 | out_nopath: |
| 82 | verify_done(cdev, sch->vpm ? 0 : -EACCES); |
| 83 | } |
| 84 | |
| 85 | /* |
| 86 | * Adjust NOOP I/O status. |
| 87 | */ |
| 88 | static enum io_status nop_filter(struct ccw_device *cdev, void *data, |
| 89 | struct irb *irb, enum io_status status) |
| 90 | { |
| 91 | /* Only subchannel status might indicate a path error. */ |
| 92 | if (status == IO_STATUS_ERROR && irb->scsw.cmd.cstat == 0) |
| 93 | return IO_DONE; |
| 94 | return status; |
| 95 | } |
| 96 | |
| 97 | /* |
| 98 | * Process NOOP request result for a single path. |
| 99 | */ |
| 100 | static void nop_callback(struct ccw_device *cdev, void *data, int rc) |
| 101 | { |
| 102 | struct subchannel *sch = to_subchannel(cdev->dev.parent); |
| 103 | struct ccw_request *req = &cdev->private->req; |
| 104 | |
| 105 | if (rc == 0) |
| 106 | sch->vpm |= req->lpm; |
| 107 | else if (rc != -EACCES) |
| 108 | goto err; |
| 109 | req->lpm >>= 1; |
| 110 | nop_do(cdev); |
| 111 | return; |
| 112 | |
| 113 | err: |
| 114 | verify_done(cdev, rc); |
| 115 | } |
| 116 | |
| 117 | /* |
| 118 | * Create channel program to perform SET PGID on a single path. |
| 119 | */ |
| 120 | static void spid_build_cp(struct ccw_device *cdev, u8 fn) |
| 121 | { |
| 122 | struct ccw_request *req = &cdev->private->req; |
| 123 | struct ccw1 *cp = cdev->private->iccws; |
| 124 | int i = 8 - ffs(req->lpm); |
| 125 | struct pgid *pgid = &cdev->private->pgid[i]; |
| 126 | |
| 127 | pgid->inf.fc = fn; |
| 128 | cp->cmd_code = CCW_CMD_SET_PGID; |
| 129 | cp->cda = (u32) (addr_t) pgid; |
| 130 | cp->count = sizeof(*pgid); |
| 131 | cp->flags = CCW_FLAG_SLI; |
| 132 | req->cp = cp; |
| 133 | } |
| 134 | |
| 135 | /* |
| 136 | * Perform establish/resign SET PGID on a single path. |
| 137 | */ |
| 138 | static void spid_do(struct ccw_device *cdev) |
| 139 | { |
| 140 | struct subchannel *sch = to_subchannel(cdev->dev.parent); |
| 141 | struct ccw_request *req = &cdev->private->req; |
| 142 | u8 fn; |
| 143 | |
Peter Oberparleiter | 52ef060 | 2009-12-07 12:51:31 +0100 | [diff] [blame] | 144 | /* Use next available path that is not already in correct state. */ |
Peter Oberparleiter | d302e1a | 2009-12-18 17:43:23 +0100 | [diff] [blame] | 145 | req->lpm = lpm_adjust(req->lpm, cdev->private->pgid_todo_mask); |
Peter Oberparleiter | 9679baa | 2009-12-07 12:51:27 +0100 | [diff] [blame] | 146 | if (!req->lpm) |
| 147 | goto out_nopath; |
| 148 | /* Channel program setup. */ |
| 149 | if (req->lpm & sch->opm) |
| 150 | fn = SPID_FUNC_ESTABLISH; |
| 151 | else |
| 152 | fn = SPID_FUNC_RESIGN; |
Peter Oberparleiter | 454e1fa | 2009-12-07 12:51:30 +0100 | [diff] [blame] | 153 | if (cdev->private->flags.mpath) |
Peter Oberparleiter | 9679baa | 2009-12-07 12:51:27 +0100 | [diff] [blame] | 154 | fn |= SPID_FUNC_MULTI_PATH; |
| 155 | spid_build_cp(cdev, fn); |
| 156 | ccw_request_start(cdev); |
| 157 | return; |
| 158 | |
| 159 | out_nopath: |
| 160 | verify_done(cdev, sch->vpm ? 0 : -EACCES); |
| 161 | } |
| 162 | |
| 163 | static void verify_start(struct ccw_device *cdev); |
| 164 | |
| 165 | /* |
| 166 | * Process SET PGID request result for a single path. |
| 167 | */ |
| 168 | static void spid_callback(struct ccw_device *cdev, void *data, int rc) |
| 169 | { |
| 170 | struct subchannel *sch = to_subchannel(cdev->dev.parent); |
| 171 | struct ccw_request *req = &cdev->private->req; |
| 172 | |
| 173 | switch (rc) { |
| 174 | case 0: |
| 175 | sch->vpm |= req->lpm & sch->opm; |
| 176 | break; |
| 177 | case -EACCES: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 | break; |
| 179 | case -EOPNOTSUPP: |
Peter Oberparleiter | 454e1fa | 2009-12-07 12:51:30 +0100 | [diff] [blame] | 180 | if (cdev->private->flags.mpath) { |
Peter Oberparleiter | 9679baa | 2009-12-07 12:51:27 +0100 | [diff] [blame] | 181 | /* Try without multipathing. */ |
Peter Oberparleiter | 454e1fa | 2009-12-07 12:51:30 +0100 | [diff] [blame] | 182 | cdev->private->flags.mpath = 0; |
Peter Oberparleiter | 9679baa | 2009-12-07 12:51:27 +0100 | [diff] [blame] | 183 | goto out_restart; |
| 184 | } |
| 185 | /* Try without pathgrouping. */ |
Peter Oberparleiter | 454e1fa | 2009-12-07 12:51:30 +0100 | [diff] [blame] | 186 | cdev->private->flags.pgroup = 0; |
Peter Oberparleiter | 9679baa | 2009-12-07 12:51:27 +0100 | [diff] [blame] | 187 | goto out_restart; |
| 188 | default: |
| 189 | goto err; |
| 190 | } |
| 191 | req->lpm >>= 1; |
| 192 | spid_do(cdev); |
| 193 | return; |
| 194 | |
| 195 | out_restart: |
| 196 | verify_start(cdev); |
| 197 | return; |
| 198 | err: |
| 199 | verify_done(cdev, rc); |
| 200 | } |
| 201 | |
Peter Oberparleiter | 52ef060 | 2009-12-07 12:51:31 +0100 | [diff] [blame] | 202 | static void spid_start(struct ccw_device *cdev) |
| 203 | { |
| 204 | struct ccw_request *req = &cdev->private->req; |
| 205 | |
| 206 | /* Initialize request data. */ |
| 207 | memset(req, 0, sizeof(*req)); |
| 208 | req->timeout = PGID_TIMEOUT; |
| 209 | req->maxretries = PGID_RETRIES; |
| 210 | req->lpm = 0x80; |
Sebastian Ott | 982bdf8 | 2010-08-09 18:12:53 +0200 | [diff] [blame] | 211 | req->singlepath = 1; |
Peter Oberparleiter | 52ef060 | 2009-12-07 12:51:31 +0100 | [diff] [blame] | 212 | req->callback = spid_callback; |
| 213 | spid_do(cdev); |
| 214 | } |
| 215 | |
Sebastian Ott | 585b954 | 2010-10-25 16:10:34 +0200 | [diff] [blame] | 216 | static int pgid_is_reset(struct pgid *p) |
| 217 | { |
| 218 | char *c; |
| 219 | |
| 220 | for (c = (char *)p + 1; c < (char *)(p + 1); c++) { |
| 221 | if (*c != 0) |
| 222 | return 0; |
| 223 | } |
| 224 | return 1; |
| 225 | } |
| 226 | |
Peter Oberparleiter | 9679baa | 2009-12-07 12:51:27 +0100 | [diff] [blame] | 227 | static int pgid_cmp(struct pgid *p1, struct pgid *p2) |
| 228 | { |
| 229 | return memcmp((char *) p1 + 1, (char *) p2 + 1, |
| 230 | sizeof(struct pgid) - 1); |
| 231 | } |
| 232 | |
| 233 | /* |
| 234 | * Determine pathgroup state from PGID data. |
| 235 | */ |
| 236 | static void pgid_analyze(struct ccw_device *cdev, struct pgid **p, |
Sebastian Ott | 585b954 | 2010-10-25 16:10:34 +0200 | [diff] [blame] | 237 | int *mismatch, int *reserved, u8 *reset) |
Peter Oberparleiter | 9679baa | 2009-12-07 12:51:27 +0100 | [diff] [blame] | 238 | { |
| 239 | struct pgid *pgid = &cdev->private->pgid[0]; |
| 240 | struct pgid *first = NULL; |
| 241 | int lpm; |
| 242 | int i; |
| 243 | |
| 244 | *mismatch = 0; |
| 245 | *reserved = 0; |
| 246 | *reset = 0; |
| 247 | for (i = 0, lpm = 0x80; i < 8; i++, pgid++, lpm >>= 1) { |
| 248 | if ((cdev->private->pgid_valid_mask & lpm) == 0) |
| 249 | continue; |
| 250 | if (pgid->inf.ps.state2 == SNID_STATE2_RESVD_ELSE) |
| 251 | *reserved = 1; |
Sebastian Ott | 585b954 | 2010-10-25 16:10:34 +0200 | [diff] [blame] | 252 | if (pgid_is_reset(pgid)) { |
| 253 | *reset |= lpm; |
Peter Oberparleiter | 9679baa | 2009-12-07 12:51:27 +0100 | [diff] [blame] | 254 | continue; |
| 255 | } |
| 256 | if (!first) { |
| 257 | first = pgid; |
| 258 | continue; |
| 259 | } |
| 260 | if (pgid_cmp(pgid, first) != 0) |
| 261 | *mismatch = 1; |
| 262 | } |
| 263 | if (!first) |
| 264 | first = &channel_subsystems[0]->global_pgid; |
| 265 | *p = first; |
| 266 | } |
| 267 | |
Peter Oberparleiter | d302e1a | 2009-12-18 17:43:23 +0100 | [diff] [blame] | 268 | static u8 pgid_to_donepm(struct ccw_device *cdev) |
Peter Oberparleiter | 52ef060 | 2009-12-07 12:51:31 +0100 | [diff] [blame] | 269 | { |
| 270 | struct subchannel *sch = to_subchannel(cdev->dev.parent); |
| 271 | struct pgid *pgid; |
| 272 | int i; |
| 273 | int lpm; |
Peter Oberparleiter | d302e1a | 2009-12-18 17:43:23 +0100 | [diff] [blame] | 274 | u8 donepm = 0; |
Peter Oberparleiter | 52ef060 | 2009-12-07 12:51:31 +0100 | [diff] [blame] | 275 | |
Peter Oberparleiter | d302e1a | 2009-12-18 17:43:23 +0100 | [diff] [blame] | 276 | /* Set bits for paths which are already in the target state. */ |
Peter Oberparleiter | 52ef060 | 2009-12-07 12:51:31 +0100 | [diff] [blame] | 277 | for (i = 0; i < 8; i++) { |
| 278 | lpm = 0x80 >> i; |
| 279 | if ((cdev->private->pgid_valid_mask & lpm) == 0) |
| 280 | continue; |
| 281 | pgid = &cdev->private->pgid[i]; |
| 282 | if (sch->opm & lpm) { |
| 283 | if (pgid->inf.ps.state1 != SNID_STATE1_GROUPED) |
| 284 | continue; |
| 285 | } else { |
| 286 | if (pgid->inf.ps.state1 != SNID_STATE1_UNGROUPED) |
| 287 | continue; |
| 288 | } |
| 289 | if (cdev->private->flags.mpath) { |
| 290 | if (pgid->inf.ps.state3 != SNID_STATE3_MULTI_PATH) |
| 291 | continue; |
| 292 | } else { |
| 293 | if (pgid->inf.ps.state3 != SNID_STATE3_SINGLE_PATH) |
| 294 | continue; |
| 295 | } |
Peter Oberparleiter | d302e1a | 2009-12-18 17:43:23 +0100 | [diff] [blame] | 296 | donepm |= lpm; |
Peter Oberparleiter | 52ef060 | 2009-12-07 12:51:31 +0100 | [diff] [blame] | 297 | } |
| 298 | |
Peter Oberparleiter | d302e1a | 2009-12-18 17:43:23 +0100 | [diff] [blame] | 299 | return donepm; |
Peter Oberparleiter | 52ef060 | 2009-12-07 12:51:31 +0100 | [diff] [blame] | 300 | } |
| 301 | |
Peter Oberparleiter | 9679baa | 2009-12-07 12:51:27 +0100 | [diff] [blame] | 302 | static void pgid_fill(struct ccw_device *cdev, struct pgid *pgid) |
| 303 | { |
| 304 | int i; |
| 305 | |
| 306 | for (i = 0; i < 8; i++) |
| 307 | memcpy(&cdev->private->pgid[i], pgid, sizeof(struct pgid)); |
| 308 | } |
| 309 | |
| 310 | /* |
| 311 | * Process SENSE PGID data and report result. |
| 312 | */ |
| 313 | static void snid_done(struct ccw_device *cdev, int rc) |
| 314 | { |
| 315 | struct ccw_dev_id *id = &cdev->private->dev_id; |
Peter Oberparleiter | 52ef060 | 2009-12-07 12:51:31 +0100 | [diff] [blame] | 316 | struct subchannel *sch = to_subchannel(cdev->dev.parent); |
Peter Oberparleiter | 9679baa | 2009-12-07 12:51:27 +0100 | [diff] [blame] | 317 | struct pgid *pgid; |
| 318 | int mismatch = 0; |
| 319 | int reserved = 0; |
Sebastian Ott | 585b954 | 2010-10-25 16:10:34 +0200 | [diff] [blame] | 320 | u8 reset = 0; |
Peter Oberparleiter | d302e1a | 2009-12-18 17:43:23 +0100 | [diff] [blame] | 321 | u8 donepm; |
Peter Oberparleiter | 9679baa | 2009-12-07 12:51:27 +0100 | [diff] [blame] | 322 | |
| 323 | if (rc) |
| 324 | goto out; |
| 325 | pgid_analyze(cdev, &pgid, &mismatch, &reserved, &reset); |
Peter Oberparleiter | 9679baa | 2009-12-07 12:51:27 +0100 | [diff] [blame] | 326 | if (reserved) |
| 327 | rc = -EUSERS; |
Peter Oberparleiter | 52ef060 | 2009-12-07 12:51:31 +0100 | [diff] [blame] | 328 | else if (mismatch) |
| 329 | rc = -EOPNOTSUPP; |
| 330 | else { |
Peter Oberparleiter | d302e1a | 2009-12-18 17:43:23 +0100 | [diff] [blame] | 331 | donepm = pgid_to_donepm(cdev); |
| 332 | sch->vpm = donepm & sch->opm; |
| 333 | cdev->private->pgid_todo_mask &= ~donepm; |
Sebastian Ott | 585b954 | 2010-10-25 16:10:34 +0200 | [diff] [blame] | 334 | cdev->private->pgid_reset_mask |= reset; |
Peter Oberparleiter | 52ef060 | 2009-12-07 12:51:31 +0100 | [diff] [blame] | 335 | pgid_fill(cdev, pgid); |
| 336 | } |
Peter Oberparleiter | 9679baa | 2009-12-07 12:51:27 +0100 | [diff] [blame] | 337 | out: |
Peter Oberparleiter | 52ef060 | 2009-12-07 12:51:31 +0100 | [diff] [blame] | 338 | CIO_MSG_EVENT(2, "snid: device 0.%x.%04x: rc=%d pvm=%02x vpm=%02x " |
Sebastian Ott | 585b954 | 2010-10-25 16:10:34 +0200 | [diff] [blame] | 339 | "todo=%02x mism=%d rsvd=%d reset=%02x\n", id->ssid, |
Peter Oberparleiter | d302e1a | 2009-12-18 17:43:23 +0100 | [diff] [blame] | 340 | id->devno, rc, cdev->private->pgid_valid_mask, sch->vpm, |
| 341 | cdev->private->pgid_todo_mask, mismatch, reserved, reset); |
Peter Oberparleiter | 52ef060 | 2009-12-07 12:51:31 +0100 | [diff] [blame] | 342 | switch (rc) { |
| 343 | case 0: |
| 344 | /* Anything left to do? */ |
Peter Oberparleiter | d302e1a | 2009-12-18 17:43:23 +0100 | [diff] [blame] | 345 | if (cdev->private->pgid_todo_mask == 0) { |
Peter Oberparleiter | 52ef060 | 2009-12-07 12:51:31 +0100 | [diff] [blame] | 346 | verify_done(cdev, sch->vpm == 0 ? -EACCES : 0); |
| 347 | return; |
| 348 | } |
| 349 | /* Perform path-grouping. */ |
| 350 | spid_start(cdev); |
| 351 | break; |
| 352 | case -EOPNOTSUPP: |
| 353 | /* Path-grouping not supported. */ |
| 354 | cdev->private->flags.pgroup = 0; |
| 355 | cdev->private->flags.mpath = 0; |
| 356 | verify_start(cdev); |
| 357 | break; |
| 358 | default: |
| 359 | verify_done(cdev, rc); |
| 360 | } |
Peter Oberparleiter | 9679baa | 2009-12-07 12:51:27 +0100 | [diff] [blame] | 361 | } |
| 362 | |
| 363 | /* |
| 364 | * Create channel program to perform a SENSE PGID on a single path. |
| 365 | */ |
| 366 | static void snid_build_cp(struct ccw_device *cdev) |
| 367 | { |
| 368 | struct ccw_request *req = &cdev->private->req; |
| 369 | struct ccw1 *cp = cdev->private->iccws; |
| 370 | int i = 8 - ffs(req->lpm); |
| 371 | |
| 372 | /* Channel program setup. */ |
| 373 | cp->cmd_code = CCW_CMD_SENSE_PGID; |
| 374 | cp->cda = (u32) (addr_t) &cdev->private->pgid[i]; |
| 375 | cp->count = sizeof(struct pgid); |
| 376 | cp->flags = CCW_FLAG_SLI; |
| 377 | req->cp = cp; |
| 378 | } |
| 379 | |
| 380 | /* |
| 381 | * Perform SENSE PGID on a single path. |
| 382 | */ |
| 383 | static void snid_do(struct ccw_device *cdev) |
| 384 | { |
| 385 | struct subchannel *sch = to_subchannel(cdev->dev.parent); |
| 386 | struct ccw_request *req = &cdev->private->req; |
| 387 | |
| 388 | /* Adjust lpm if paths are not set in pam. */ |
| 389 | req->lpm = lpm_adjust(req->lpm, sch->schib.pmcw.pam); |
| 390 | if (!req->lpm) |
| 391 | goto out_nopath; |
| 392 | snid_build_cp(cdev); |
| 393 | ccw_request_start(cdev); |
| 394 | return; |
| 395 | |
| 396 | out_nopath: |
| 397 | snid_done(cdev, cdev->private->pgid_valid_mask ? 0 : -EACCES); |
| 398 | } |
| 399 | |
| 400 | /* |
| 401 | * Process SENSE PGID request result for single path. |
| 402 | */ |
| 403 | static void snid_callback(struct ccw_device *cdev, void *data, int rc) |
| 404 | { |
| 405 | struct ccw_request *req = &cdev->private->req; |
| 406 | |
| 407 | if (rc == 0) |
| 408 | cdev->private->pgid_valid_mask |= req->lpm; |
| 409 | else if (rc != -EACCES) |
| 410 | goto err; |
| 411 | req->lpm >>= 1; |
| 412 | snid_do(cdev); |
| 413 | return; |
| 414 | |
| 415 | err: |
| 416 | snid_done(cdev, rc); |
| 417 | } |
| 418 | |
Peter Oberparleiter | 9679baa | 2009-12-07 12:51:27 +0100 | [diff] [blame] | 419 | /* |
| 420 | * Perform path verification. |
| 421 | */ |
| 422 | static void verify_start(struct ccw_device *cdev) |
| 423 | { |
| 424 | struct subchannel *sch = to_subchannel(cdev->dev.parent); |
| 425 | struct ccw_request *req = &cdev->private->req; |
Peter Oberparleiter | 52ef060 | 2009-12-07 12:51:31 +0100 | [diff] [blame] | 426 | struct ccw_dev_id *devid = &cdev->private->dev_id; |
Peter Oberparleiter | 9679baa | 2009-12-07 12:51:27 +0100 | [diff] [blame] | 427 | |
| 428 | sch->vpm = 0; |
Peter Oberparleiter | d302e1a | 2009-12-18 17:43:23 +0100 | [diff] [blame] | 429 | sch->lpm = sch->schib.pmcw.pam; |
Peter Oberparleiter | 9679baa | 2009-12-07 12:51:27 +0100 | [diff] [blame] | 430 | /* Initialize request data. */ |
| 431 | memset(req, 0, sizeof(*req)); |
| 432 | req->timeout = PGID_TIMEOUT; |
| 433 | req->maxretries = PGID_RETRIES; |
| 434 | req->lpm = 0x80; |
Sebastian Ott | 982bdf8 | 2010-08-09 18:12:53 +0200 | [diff] [blame] | 435 | req->singlepath = 1; |
Peter Oberparleiter | 454e1fa | 2009-12-07 12:51:30 +0100 | [diff] [blame] | 436 | if (cdev->private->flags.pgroup) { |
Peter Oberparleiter | 52ef060 | 2009-12-07 12:51:31 +0100 | [diff] [blame] | 437 | CIO_TRACE_EVENT(4, "snid"); |
| 438 | CIO_HEX_EVENT(4, devid, sizeof(*devid)); |
| 439 | req->callback = snid_callback; |
| 440 | snid_do(cdev); |
Peter Oberparleiter | 9679baa | 2009-12-07 12:51:27 +0100 | [diff] [blame] | 441 | } else { |
Peter Oberparleiter | 52ef060 | 2009-12-07 12:51:31 +0100 | [diff] [blame] | 442 | CIO_TRACE_EVENT(4, "nop"); |
| 443 | CIO_HEX_EVENT(4, devid, sizeof(*devid)); |
Peter Oberparleiter | 9679baa | 2009-12-07 12:51:27 +0100 | [diff] [blame] | 444 | req->filter = nop_filter; |
| 445 | req->callback = nop_callback; |
| 446 | nop_do(cdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 447 | } |
| 448 | } |
| 449 | |
Peter Oberparleiter | 9679baa | 2009-12-07 12:51:27 +0100 | [diff] [blame] | 450 | /** |
| 451 | * ccw_device_verify_start - perform path verification |
| 452 | * @cdev: ccw device |
| 453 | * |
| 454 | * Perform an I/O on each available channel path to @cdev to determine which |
| 455 | * paths are operational. The resulting path mask is stored in sch->vpm. |
| 456 | * If device options specify pathgrouping, establish a pathgroup for the |
| 457 | * operational paths. When finished, call ccw_device_verify_done with a |
| 458 | * return code specifying the result. |
| 459 | */ |
| 460 | void ccw_device_verify_start(struct ccw_device *cdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 461 | { |
Peter Oberparleiter | d302e1a | 2009-12-18 17:43:23 +0100 | [diff] [blame] | 462 | struct subchannel *sch = to_subchannel(cdev->dev.parent); |
| 463 | |
Peter Oberparleiter | 9679baa | 2009-12-07 12:51:27 +0100 | [diff] [blame] | 464 | CIO_TRACE_EVENT(4, "vrfy"); |
| 465 | CIO_HEX_EVENT(4, &cdev->private->dev_id, sizeof(cdev->private->dev_id)); |
Peter Oberparleiter | 52ef060 | 2009-12-07 12:51:31 +0100 | [diff] [blame] | 466 | /* Initialize PGID data. */ |
| 467 | memset(cdev->private->pgid, 0, sizeof(cdev->private->pgid)); |
| 468 | cdev->private->pgid_valid_mask = 0; |
Peter Oberparleiter | d302e1a | 2009-12-18 17:43:23 +0100 | [diff] [blame] | 469 | cdev->private->pgid_todo_mask = sch->schib.pmcw.pam; |
Peter Oberparleiter | 52ef060 | 2009-12-07 12:51:31 +0100 | [diff] [blame] | 470 | /* |
| 471 | * Initialize pathgroup and multipath state with target values. |
| 472 | * They may change in the course of path verification. |
| 473 | */ |
| 474 | cdev->private->flags.pgroup = cdev->private->options.pgroup; |
| 475 | cdev->private->flags.mpath = cdev->private->options.mpath; |
Peter Oberparleiter | 9679baa | 2009-12-07 12:51:27 +0100 | [diff] [blame] | 476 | cdev->private->flags.doverify = 0; |
| 477 | verify_start(cdev); |
| 478 | } |
Cornelia Huck | f1ee328 | 2006-10-04 20:02:02 +0200 | [diff] [blame] | 479 | |
Peter Oberparleiter | 9679baa | 2009-12-07 12:51:27 +0100 | [diff] [blame] | 480 | /* |
| 481 | * Process disband SET PGID request result. |
| 482 | */ |
| 483 | static void disband_callback(struct ccw_device *cdev, void *data, int rc) |
| 484 | { |
| 485 | struct subchannel *sch = to_subchannel(cdev->dev.parent); |
| 486 | struct ccw_dev_id *id = &cdev->private->dev_id; |
| 487 | |
| 488 | if (rc) |
| 489 | goto out; |
| 490 | /* Ensure consistent multipathing state at device and channel. */ |
Peter Oberparleiter | 454e1fa | 2009-12-07 12:51:30 +0100 | [diff] [blame] | 491 | cdev->private->flags.mpath = 0; |
Peter Oberparleiter | 9679baa | 2009-12-07 12:51:27 +0100 | [diff] [blame] | 492 | if (sch->config.mp) { |
| 493 | sch->config.mp = 0; |
| 494 | rc = cio_commit_config(sch); |
| 495 | } |
| 496 | out: |
| 497 | CIO_MSG_EVENT(0, "disb: device 0.%x.%04x: rc=%d\n", id->ssid, id->devno, |
| 498 | rc); |
| 499 | ccw_device_disband_done(cdev, rc); |
| 500 | } |
| 501 | |
| 502 | /** |
| 503 | * ccw_device_disband_start - disband pathgroup |
| 504 | * @cdev: ccw device |
| 505 | * |
| 506 | * Execute a SET PGID channel program on @cdev to disband a previously |
| 507 | * established pathgroup. When finished, call ccw_device_disband_done with |
| 508 | * a return code specifying the result. |
| 509 | */ |
| 510 | void ccw_device_disband_start(struct ccw_device *cdev) |
| 511 | { |
| 512 | struct subchannel *sch = to_subchannel(cdev->dev.parent); |
| 513 | struct ccw_request *req = &cdev->private->req; |
| 514 | u8 fn; |
| 515 | |
| 516 | CIO_TRACE_EVENT(4, "disb"); |
| 517 | CIO_HEX_EVENT(4, &cdev->private->dev_id, sizeof(cdev->private->dev_id)); |
| 518 | /* Request setup. */ |
| 519 | memset(req, 0, sizeof(*req)); |
| 520 | req->timeout = PGID_TIMEOUT; |
| 521 | req->maxretries = PGID_RETRIES; |
| 522 | req->lpm = sch->schib.pmcw.pam & sch->opm; |
Sebastian Ott | 982bdf8 | 2010-08-09 18:12:53 +0200 | [diff] [blame] | 523 | req->singlepath = 1; |
Peter Oberparleiter | 9679baa | 2009-12-07 12:51:27 +0100 | [diff] [blame] | 524 | req->callback = disband_callback; |
| 525 | fn = SPID_FUNC_DISBAND; |
Peter Oberparleiter | 454e1fa | 2009-12-07 12:51:30 +0100 | [diff] [blame] | 526 | if (cdev->private->flags.mpath) |
Peter Oberparleiter | 9679baa | 2009-12-07 12:51:27 +0100 | [diff] [blame] | 527 | fn |= SPID_FUNC_MULTI_PATH; |
| 528 | spid_build_cp(cdev, fn); |
| 529 | ccw_request_start(cdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 530 | } |
Peter Oberparleiter | d7d12ef | 2009-12-07 12:51:32 +0100 | [diff] [blame] | 531 | |
| 532 | static void stlck_build_cp(struct ccw_device *cdev, void *buf1, void *buf2) |
| 533 | { |
| 534 | struct ccw_request *req = &cdev->private->req; |
| 535 | struct ccw1 *cp = cdev->private->iccws; |
| 536 | |
| 537 | cp[0].cmd_code = CCW_CMD_STLCK; |
| 538 | cp[0].cda = (u32) (addr_t) buf1; |
| 539 | cp[0].count = 32; |
| 540 | cp[0].flags = CCW_FLAG_CC; |
| 541 | cp[1].cmd_code = CCW_CMD_RELEASE; |
| 542 | cp[1].cda = (u32) (addr_t) buf2; |
| 543 | cp[1].count = 32; |
| 544 | cp[1].flags = 0; |
| 545 | req->cp = cp; |
| 546 | } |
| 547 | |
| 548 | static void stlck_callback(struct ccw_device *cdev, void *data, int rc) |
| 549 | { |
| 550 | ccw_device_stlck_done(cdev, data, rc); |
| 551 | } |
| 552 | |
| 553 | /** |
| 554 | * ccw_device_stlck_start - perform unconditional release |
| 555 | * @cdev: ccw device |
| 556 | * @data: data pointer to be passed to ccw_device_stlck_done |
| 557 | * @buf1: data pointer used in channel program |
| 558 | * @buf2: data pointer used in channel program |
| 559 | * |
| 560 | * Execute a channel program on @cdev to release an existing PGID reservation. |
| 561 | * When finished, call ccw_device_stlck_done with a return code specifying the |
| 562 | * result. |
| 563 | */ |
| 564 | void ccw_device_stlck_start(struct ccw_device *cdev, void *data, void *buf1, |
| 565 | void *buf2) |
| 566 | { |
| 567 | struct subchannel *sch = to_subchannel(cdev->dev.parent); |
| 568 | struct ccw_request *req = &cdev->private->req; |
| 569 | |
| 570 | CIO_TRACE_EVENT(4, "stlck"); |
| 571 | CIO_HEX_EVENT(4, &cdev->private->dev_id, sizeof(cdev->private->dev_id)); |
| 572 | /* Request setup. */ |
| 573 | memset(req, 0, sizeof(*req)); |
| 574 | req->timeout = PGID_TIMEOUT; |
| 575 | req->maxretries = PGID_RETRIES; |
| 576 | req->lpm = sch->schib.pmcw.pam & sch->opm; |
| 577 | req->data = data; |
| 578 | req->callback = stlck_callback; |
| 579 | stlck_build_cp(cdev, buf1, buf2); |
| 580 | ccw_request_start(cdev); |
| 581 | } |
| 582 | |