Chandra Seetharaman | 5e7dcca | 2008-05-01 14:50:04 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Target driver for EMC CLARiiON AX/CX-series hardware. |
| 3 | * Based on code from Lars Marowsky-Bree <lmb@suse.de> |
| 4 | * and Ed Goggin <egoggin@emc.com>. |
| 5 | * |
| 6 | * Copyright (C) 2006 Red Hat, Inc. All rights reserved. |
| 7 | * Copyright (C) 2006 Mike Christie |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or modify |
| 10 | * it under the terms of the GNU General Public License as published by |
| 11 | * the Free Software Foundation; either version 2, or (at your option) |
| 12 | * any later version. |
| 13 | * |
| 14 | * This program is distributed in the hope that it will be useful, |
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | * GNU General Public License for more details. |
| 18 | * |
| 19 | * You should have received a copy of the GNU General Public License |
| 20 | * along with this program; see the file COPYING. If not, write to |
| 21 | * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. |
| 22 | */ |
| 23 | #include <scsi/scsi.h> |
| 24 | #include <scsi/scsi_eh.h> |
| 25 | #include <scsi/scsi_dh.h> |
| 26 | #include <scsi/scsi_device.h> |
| 27 | |
Hannes Reinecke | b6ff1b1 | 2008-07-17 16:53:03 -0700 | [diff] [blame] | 28 | #define CLARIION_NAME "emc" |
Chandra Seetharaman | 5e7dcca | 2008-05-01 14:50:04 -0700 | [diff] [blame] | 29 | |
| 30 | #define CLARIION_TRESPASS_PAGE 0x22 |
Hannes Reinecke | b6ff1b1 | 2008-07-17 16:53:03 -0700 | [diff] [blame] | 31 | #define CLARIION_BUFFER_SIZE 0xFC |
Chandra Seetharaman | 5e7dcca | 2008-05-01 14:50:04 -0700 | [diff] [blame] | 32 | #define CLARIION_TIMEOUT (60 * HZ) |
| 33 | #define CLARIION_RETRIES 3 |
| 34 | #define CLARIION_UNBOUND_LU -1 |
Hannes Reinecke | b6ff1b1 | 2008-07-17 16:53:03 -0700 | [diff] [blame] | 35 | #define CLARIION_SP_A 0 |
| 36 | #define CLARIION_SP_B 1 |
| 37 | |
| 38 | /* Flags */ |
| 39 | #define CLARIION_SHORT_TRESPASS 1 |
| 40 | #define CLARIION_HONOR_RESERVATIONS 2 |
| 41 | |
| 42 | /* LUN states */ |
| 43 | #define CLARIION_LUN_UNINITIALIZED -1 |
| 44 | #define CLARIION_LUN_UNBOUND 0 |
| 45 | #define CLARIION_LUN_BOUND 1 |
| 46 | #define CLARIION_LUN_OWNED 2 |
Chandra Seetharaman | 5e7dcca | 2008-05-01 14:50:04 -0700 | [diff] [blame] | 47 | |
| 48 | static unsigned char long_trespass[] = { |
Hannes Reinecke | b6ff1b1 | 2008-07-17 16:53:03 -0700 | [diff] [blame] | 49 | 0, 0, 0, 0, 0, 0, 0, 0, |
Chandra Seetharaman | 5e7dcca | 2008-05-01 14:50:04 -0700 | [diff] [blame] | 50 | CLARIION_TRESPASS_PAGE, /* Page code */ |
| 51 | 0x09, /* Page length - 2 */ |
Hannes Reinecke | b6ff1b1 | 2008-07-17 16:53:03 -0700 | [diff] [blame] | 52 | 0x01, /* Trespass code */ |
Chandra Seetharaman | 5e7dcca | 2008-05-01 14:50:04 -0700 | [diff] [blame] | 53 | 0xff, 0xff, /* Trespass target */ |
| 54 | 0, 0, 0, 0, 0, 0 /* Reserved bytes / unknown */ |
| 55 | }; |
| 56 | |
| 57 | static unsigned char short_trespass[] = { |
| 58 | 0, 0, 0, 0, |
| 59 | CLARIION_TRESPASS_PAGE, /* Page code */ |
| 60 | 0x02, /* Page length - 2 */ |
Hannes Reinecke | b6ff1b1 | 2008-07-17 16:53:03 -0700 | [diff] [blame] | 61 | 0x01, /* Trespass code */ |
Chandra Seetharaman | 5e7dcca | 2008-05-01 14:50:04 -0700 | [diff] [blame] | 62 | 0xff, /* Trespass target */ |
| 63 | }; |
| 64 | |
Hannes Reinecke | b6ff1b1 | 2008-07-17 16:53:03 -0700 | [diff] [blame] | 65 | static const char * lun_state[] = |
| 66 | { |
| 67 | "not bound", |
| 68 | "bound", |
| 69 | "owned", |
Chandra Seetharaman | 5e7dcca | 2008-05-01 14:50:04 -0700 | [diff] [blame] | 70 | }; |
| 71 | |
| 72 | struct clariion_dh_data { |
| 73 | /* |
Hannes Reinecke | b6ff1b1 | 2008-07-17 16:53:03 -0700 | [diff] [blame] | 74 | * Flags: |
| 75 | * CLARIION_SHORT_TRESPASS |
Chandra Seetharaman | 5e7dcca | 2008-05-01 14:50:04 -0700 | [diff] [blame] | 76 | * Use short trespass command (FC-series) or the long version |
| 77 | * (default for AX/CX CLARiiON arrays). |
Hannes Reinecke | b6ff1b1 | 2008-07-17 16:53:03 -0700 | [diff] [blame] | 78 | * |
| 79 | * CLARIION_HONOR_RESERVATIONS |
Chandra Seetharaman | 5e7dcca | 2008-05-01 14:50:04 -0700 | [diff] [blame] | 80 | * Whether or not (default) to honor SCSI reservations when |
| 81 | * initiating a switch-over. |
| 82 | */ |
Hannes Reinecke | b6ff1b1 | 2008-07-17 16:53:03 -0700 | [diff] [blame] | 83 | unsigned flags; |
| 84 | /* |
| 85 | * I/O buffer for both MODE_SELECT and INQUIRY commands. |
| 86 | */ |
James Bottomley | 7ae628d | 2008-09-23 07:58:59 -0700 | [diff] [blame] | 87 | unsigned char buffer[CLARIION_BUFFER_SIZE]; |
Chandra Seetharaman | 5e7dcca | 2008-05-01 14:50:04 -0700 | [diff] [blame] | 88 | /* |
| 89 | * SCSI sense buffer for commands -- assumes serial issuance |
| 90 | * and completion sequence of all commands for same multipath. |
| 91 | */ |
| 92 | unsigned char sense[SCSI_SENSE_BUFFERSIZE]; |
Hannes Reinecke | b6ff1b1 | 2008-07-17 16:53:03 -0700 | [diff] [blame] | 93 | unsigned int senselen; |
| 94 | /* |
| 95 | * LUN state |
| 96 | */ |
| 97 | int lun_state; |
| 98 | /* |
| 99 | * SP Port number |
| 100 | */ |
| 101 | int port; |
| 102 | /* |
| 103 | * which SP (A=0,B=1,UNBOUND=-1) is the default SP for this |
| 104 | * path's mapped LUN |
| 105 | */ |
Chandra Seetharaman | 5e7dcca | 2008-05-01 14:50:04 -0700 | [diff] [blame] | 106 | int default_sp; |
Hannes Reinecke | b6ff1b1 | 2008-07-17 16:53:03 -0700 | [diff] [blame] | 107 | /* |
| 108 | * which SP (A=0,B=1,UNBOUND=-1) is the active SP for this |
| 109 | * path's mapped LUN |
| 110 | */ |
Chandra Seetharaman | 5e7dcca | 2008-05-01 14:50:04 -0700 | [diff] [blame] | 111 | int current_sp; |
| 112 | }; |
| 113 | |
| 114 | static inline struct clariion_dh_data |
| 115 | *get_clariion_data(struct scsi_device *sdev) |
| 116 | { |
| 117 | struct scsi_dh_data *scsi_dh_data = sdev->scsi_dh_data; |
| 118 | BUG_ON(scsi_dh_data == NULL); |
| 119 | return ((struct clariion_dh_data *) scsi_dh_data->buf); |
| 120 | } |
| 121 | |
| 122 | /* |
| 123 | * Parse MODE_SELECT cmd reply. |
| 124 | */ |
Hannes Reinecke | b6ff1b1 | 2008-07-17 16:53:03 -0700 | [diff] [blame] | 125 | static int trespass_endio(struct scsi_device *sdev, char *sense) |
Chandra Seetharaman | 5e7dcca | 2008-05-01 14:50:04 -0700 | [diff] [blame] | 126 | { |
Hannes Reinecke | b6ff1b1 | 2008-07-17 16:53:03 -0700 | [diff] [blame] | 127 | int err = SCSI_DH_IO; |
Chandra Seetharaman | 5e7dcca | 2008-05-01 14:50:04 -0700 | [diff] [blame] | 128 | struct scsi_sense_hdr sshdr; |
Chandra Seetharaman | 5e7dcca | 2008-05-01 14:50:04 -0700 | [diff] [blame] | 129 | |
Hannes Reinecke | b6ff1b1 | 2008-07-17 16:53:03 -0700 | [diff] [blame] | 130 | if (!scsi_normalize_sense(sense, SCSI_SENSE_BUFFERSIZE, &sshdr)) { |
| 131 | sdev_printk(KERN_ERR, sdev, "%s: Found valid sense data 0x%2x, " |
Chandra Seetharaman | 5e7dcca | 2008-05-01 14:50:04 -0700 | [diff] [blame] | 132 | "0x%2x, 0x%2x while sending CLARiiON trespass " |
Hannes Reinecke | b6ff1b1 | 2008-07-17 16:53:03 -0700 | [diff] [blame] | 133 | "command.\n", CLARIION_NAME, sshdr.sense_key, |
| 134 | sshdr.asc, sshdr.ascq); |
Chandra Seetharaman | 5e7dcca | 2008-05-01 14:50:04 -0700 | [diff] [blame] | 135 | |
| 136 | if ((sshdr.sense_key == 0x05) && (sshdr.asc == 0x04) && |
| 137 | (sshdr.ascq == 0x00)) { |
| 138 | /* |
| 139 | * Array based copy in progress -- do not send |
| 140 | * mode_select or copy will be aborted mid-stream. |
| 141 | */ |
Hannes Reinecke | b6ff1b1 | 2008-07-17 16:53:03 -0700 | [diff] [blame] | 142 | sdev_printk(KERN_INFO, sdev, "%s: Array Based Copy in " |
Chandra Seetharaman | 5e7dcca | 2008-05-01 14:50:04 -0700 | [diff] [blame] | 143 | "progress while sending CLARiiON trespass " |
Hannes Reinecke | b6ff1b1 | 2008-07-17 16:53:03 -0700 | [diff] [blame] | 144 | "command.\n", CLARIION_NAME); |
Chandra Seetharaman | 5e7dcca | 2008-05-01 14:50:04 -0700 | [diff] [blame] | 145 | err = SCSI_DH_DEV_TEMP_BUSY; |
| 146 | } else if ((sshdr.sense_key == 0x02) && (sshdr.asc == 0x04) && |
| 147 | (sshdr.ascq == 0x03)) { |
| 148 | /* |
| 149 | * LUN Not Ready - Manual Intervention Required |
| 150 | * indicates in-progress ucode upgrade (NDU). |
| 151 | */ |
Hannes Reinecke | b6ff1b1 | 2008-07-17 16:53:03 -0700 | [diff] [blame] | 152 | sdev_printk(KERN_INFO, sdev, "%s: Detected in-progress " |
Chandra Seetharaman | 5e7dcca | 2008-05-01 14:50:04 -0700 | [diff] [blame] | 153 | "ucode upgrade NDU operation while sending " |
Hannes Reinecke | b6ff1b1 | 2008-07-17 16:53:03 -0700 | [diff] [blame] | 154 | "CLARiiON trespass command.\n", CLARIION_NAME); |
Chandra Seetharaman | 5e7dcca | 2008-05-01 14:50:04 -0700 | [diff] [blame] | 155 | err = SCSI_DH_DEV_TEMP_BUSY; |
| 156 | } else |
| 157 | err = SCSI_DH_DEV_FAILED; |
Hannes Reinecke | b6ff1b1 | 2008-07-17 16:53:03 -0700 | [diff] [blame] | 158 | } else { |
| 159 | sdev_printk(KERN_INFO, sdev, |
| 160 | "%s: failed to send MODE SELECT, no sense available\n", |
| 161 | CLARIION_NAME); |
Chandra Seetharaman | 5e7dcca | 2008-05-01 14:50:04 -0700 | [diff] [blame] | 162 | } |
Chandra Seetharaman | 5e7dcca | 2008-05-01 14:50:04 -0700 | [diff] [blame] | 163 | return err; |
| 164 | } |
| 165 | |
Hannes Reinecke | b6ff1b1 | 2008-07-17 16:53:03 -0700 | [diff] [blame] | 166 | static int parse_sp_info_reply(struct scsi_device *sdev, |
| 167 | struct clariion_dh_data *csdev) |
Chandra Seetharaman | 5e7dcca | 2008-05-01 14:50:04 -0700 | [diff] [blame] | 168 | { |
| 169 | int err = SCSI_DH_OK; |
Chandra Seetharaman | 5e7dcca | 2008-05-01 14:50:04 -0700 | [diff] [blame] | 170 | |
Hannes Reinecke | b6ff1b1 | 2008-07-17 16:53:03 -0700 | [diff] [blame] | 171 | /* check for in-progress ucode upgrade (NDU) */ |
| 172 | if (csdev->buffer[48] != 0) { |
| 173 | sdev_printk(KERN_NOTICE, sdev, "%s: Detected in-progress " |
| 174 | "ucode upgrade NDU operation while finding " |
| 175 | "current active SP.", CLARIION_NAME); |
| 176 | err = SCSI_DH_DEV_TEMP_BUSY; |
| 177 | goto out; |
| 178 | } |
James Bottomley | 7ae628d | 2008-09-23 07:58:59 -0700 | [diff] [blame] | 179 | if (csdev->buffer[4] > 2) { |
Hannes Reinecke | b6ff1b1 | 2008-07-17 16:53:03 -0700 | [diff] [blame] | 180 | /* Invalid buffer format */ |
| 181 | sdev_printk(KERN_NOTICE, sdev, |
| 182 | "%s: invalid VPD page 0xC0 format\n", |
| 183 | CLARIION_NAME); |
| 184 | err = SCSI_DH_NOSYS; |
| 185 | goto out; |
| 186 | } |
| 187 | switch (csdev->buffer[28] & 0x0f) { |
| 188 | case 6: |
| 189 | sdev_printk(KERN_NOTICE, sdev, |
| 190 | "%s: ALUA failover mode detected\n", |
| 191 | CLARIION_NAME); |
| 192 | break; |
| 193 | case 4: |
| 194 | /* Linux failover */ |
| 195 | break; |
| 196 | default: |
| 197 | sdev_printk(KERN_WARNING, sdev, |
| 198 | "%s: Invalid failover mode %d\n", |
| 199 | CLARIION_NAME, csdev->buffer[28] & 0x0f); |
| 200 | err = SCSI_DH_NOSYS; |
| 201 | goto out; |
Chandra Seetharaman | 5e7dcca | 2008-05-01 14:50:04 -0700 | [diff] [blame] | 202 | } |
| 203 | |
Hannes Reinecke | b6ff1b1 | 2008-07-17 16:53:03 -0700 | [diff] [blame] | 204 | csdev->default_sp = csdev->buffer[5]; |
| 205 | csdev->lun_state = csdev->buffer[4]; |
| 206 | csdev->current_sp = csdev->buffer[8]; |
| 207 | csdev->port = csdev->buffer[7]; |
| 208 | |
| 209 | out: |
Chandra Seetharaman | 5e7dcca | 2008-05-01 14:50:04 -0700 | [diff] [blame] | 210 | return err; |
| 211 | } |
| 212 | |
Hannes Reinecke | b6ff1b1 | 2008-07-17 16:53:03 -0700 | [diff] [blame] | 213 | #define emc_default_str "FC (Legacy)" |
| 214 | |
| 215 | static char * parse_sp_model(struct scsi_device *sdev, unsigned char *buffer) |
Chandra Seetharaman | 5e7dcca | 2008-05-01 14:50:04 -0700 | [diff] [blame] | 216 | { |
Hannes Reinecke | b6ff1b1 | 2008-07-17 16:53:03 -0700 | [diff] [blame] | 217 | unsigned char len = buffer[4] + 5; |
| 218 | char *sp_model = NULL; |
| 219 | unsigned char sp_len, serial_len; |
Chandra Seetharaman | 5e7dcca | 2008-05-01 14:50:04 -0700 | [diff] [blame] | 220 | |
Hannes Reinecke | b6ff1b1 | 2008-07-17 16:53:03 -0700 | [diff] [blame] | 221 | if (len < 160) { |
| 222 | sdev_printk(KERN_WARNING, sdev, |
| 223 | "%s: Invalid information section length %d\n", |
| 224 | CLARIION_NAME, len); |
| 225 | /* Check for old FC arrays */ |
| 226 | if (!strncmp(buffer + 8, "DGC", 3)) { |
| 227 | /* Old FC array, not supporting extended information */ |
| 228 | sp_model = emc_default_str; |
Chandra Seetharaman | 5e7dcca | 2008-05-01 14:50:04 -0700 | [diff] [blame] | 229 | } |
Hannes Reinecke | b6ff1b1 | 2008-07-17 16:53:03 -0700 | [diff] [blame] | 230 | goto out; |
Chandra Seetharaman | 5e7dcca | 2008-05-01 14:50:04 -0700 | [diff] [blame] | 231 | } |
Hannes Reinecke | b6ff1b1 | 2008-07-17 16:53:03 -0700 | [diff] [blame] | 232 | |
| 233 | /* |
| 234 | * Parse extended information for SP model number |
| 235 | */ |
| 236 | serial_len = buffer[160]; |
| 237 | if (serial_len == 0 || serial_len + 161 > len) { |
| 238 | sdev_printk(KERN_WARNING, sdev, |
| 239 | "%s: Invalid array serial number length %d\n", |
| 240 | CLARIION_NAME, serial_len); |
| 241 | goto out; |
| 242 | } |
| 243 | sp_len = buffer[99]; |
| 244 | if (sp_len == 0 || serial_len + sp_len + 161 > len) { |
| 245 | sdev_printk(KERN_WARNING, sdev, |
| 246 | "%s: Invalid model number length %d\n", |
| 247 | CLARIION_NAME, sp_len); |
| 248 | goto out; |
| 249 | } |
| 250 | sp_model = &buffer[serial_len + 161]; |
| 251 | /* Strip whitespace at the end */ |
| 252 | while (sp_len > 1 && sp_model[sp_len - 1] == ' ') |
| 253 | sp_len--; |
| 254 | |
| 255 | sp_model[sp_len] = '\0'; |
| 256 | |
| 257 | out: |
| 258 | return sp_model; |
Chandra Seetharaman | 5e7dcca | 2008-05-01 14:50:04 -0700 | [diff] [blame] | 259 | } |
| 260 | |
| 261 | /* |
Hannes Reinecke | 765cbc6 | 2008-07-17 16:52:51 -0700 | [diff] [blame] | 262 | * Get block request for REQ_BLOCK_PC command issued to path. Currently |
| 263 | * limited to MODE_SELECT (trespass) and INQUIRY (VPD page 0xC0) commands. |
| 264 | * |
| 265 | * Uses data and sense buffers in hardware handler context structure and |
| 266 | * assumes serial servicing of commands, both issuance and completion. |
| 267 | */ |
Hannes Reinecke | b6ff1b1 | 2008-07-17 16:53:03 -0700 | [diff] [blame] | 268 | static struct request *get_req(struct scsi_device *sdev, int cmd, |
| 269 | unsigned char *buffer) |
Chandra Seetharaman | 5e7dcca | 2008-05-01 14:50:04 -0700 | [diff] [blame] | 270 | { |
Chandra Seetharaman | 5e7dcca | 2008-05-01 14:50:04 -0700 | [diff] [blame] | 271 | struct request *rq; |
Chandra Seetharaman | 5e7dcca | 2008-05-01 14:50:04 -0700 | [diff] [blame] | 272 | int len = 0; |
| 273 | |
| 274 | rq = blk_get_request(sdev->request_queue, |
Hannes Reinecke | b6ff1b1 | 2008-07-17 16:53:03 -0700 | [diff] [blame] | 275 | (cmd == MODE_SELECT) ? WRITE : READ, GFP_NOIO); |
Chandra Seetharaman | 5e7dcca | 2008-05-01 14:50:04 -0700 | [diff] [blame] | 276 | if (!rq) { |
| 277 | sdev_printk(KERN_INFO, sdev, "get_req: blk_get_request failed"); |
| 278 | return NULL; |
| 279 | } |
| 280 | |
Hannes Reinecke | b6ff1b1 | 2008-07-17 16:53:03 -0700 | [diff] [blame] | 281 | rq->cmd_len = COMMAND_SIZE(cmd); |
Chandra Seetharaman | 5e7dcca | 2008-05-01 14:50:04 -0700 | [diff] [blame] | 282 | rq->cmd[0] = cmd; |
Chandra Seetharaman | 5e7dcca | 2008-05-01 14:50:04 -0700 | [diff] [blame] | 283 | |
| 284 | switch (cmd) { |
| 285 | case MODE_SELECT: |
Hannes Reinecke | b6ff1b1 | 2008-07-17 16:53:03 -0700 | [diff] [blame] | 286 | len = sizeof(short_trespass); |
| 287 | rq->cmd_flags |= REQ_RW; |
| 288 | rq->cmd[1] = 0x10; |
| 289 | break; |
| 290 | case MODE_SELECT_10: |
| 291 | len = sizeof(long_trespass); |
Chandra Seetharaman | 5e7dcca | 2008-05-01 14:50:04 -0700 | [diff] [blame] | 292 | rq->cmd_flags |= REQ_RW; |
| 293 | rq->cmd[1] = 0x10; |
| 294 | break; |
| 295 | case INQUIRY: |
Chandra Seetharaman | 5e7dcca | 2008-05-01 14:50:04 -0700 | [diff] [blame] | 296 | len = CLARIION_BUFFER_SIZE; |
Hannes Reinecke | b6ff1b1 | 2008-07-17 16:53:03 -0700 | [diff] [blame] | 297 | memset(buffer, 0, len); |
Chandra Seetharaman | 5e7dcca | 2008-05-01 14:50:04 -0700 | [diff] [blame] | 298 | break; |
| 299 | default: |
| 300 | BUG_ON(1); |
| 301 | break; |
| 302 | } |
| 303 | |
| 304 | rq->cmd[4] = len; |
| 305 | rq->cmd_type = REQ_TYPE_BLOCK_PC; |
Mike Christie | 6000a36 | 2008-08-19 18:45:30 -0500 | [diff] [blame] | 306 | rq->cmd_flags |= REQ_FAILFAST_DEV | REQ_FAILFAST_TRANSPORT | |
| 307 | REQ_FAILFAST_DRIVER; |
Chandra Seetharaman | 5e7dcca | 2008-05-01 14:50:04 -0700 | [diff] [blame] | 308 | rq->timeout = CLARIION_TIMEOUT; |
| 309 | rq->retries = CLARIION_RETRIES; |
| 310 | |
Hannes Reinecke | b6ff1b1 | 2008-07-17 16:53:03 -0700 | [diff] [blame] | 311 | if (blk_rq_map_kern(rq->q, rq, buffer, len, GFP_NOIO)) { |
| 312 | blk_put_request(rq); |
Chandra Seetharaman | 5e7dcca | 2008-05-01 14:50:04 -0700 | [diff] [blame] | 313 | return NULL; |
| 314 | } |
| 315 | |
| 316 | return rq; |
| 317 | } |
| 318 | |
Hannes Reinecke | b6ff1b1 | 2008-07-17 16:53:03 -0700 | [diff] [blame] | 319 | static int send_inquiry_cmd(struct scsi_device *sdev, int page, |
| 320 | struct clariion_dh_data *csdev) |
Chandra Seetharaman | 5e7dcca | 2008-05-01 14:50:04 -0700 | [diff] [blame] | 321 | { |
Hannes Reinecke | b6ff1b1 | 2008-07-17 16:53:03 -0700 | [diff] [blame] | 322 | struct request *rq = get_req(sdev, INQUIRY, csdev->buffer); |
| 323 | int err; |
Chandra Seetharaman | 5e7dcca | 2008-05-01 14:50:04 -0700 | [diff] [blame] | 324 | |
| 325 | if (!rq) |
| 326 | return SCSI_DH_RES_TEMP_UNAVAIL; |
| 327 | |
Hannes Reinecke | b6ff1b1 | 2008-07-17 16:53:03 -0700 | [diff] [blame] | 328 | rq->sense = csdev->sense; |
| 329 | memset(rq->sense, 0, SCSI_SENSE_BUFFERSIZE); |
| 330 | rq->sense_len = csdev->senselen = 0; |
| 331 | |
| 332 | rq->cmd[0] = INQUIRY; |
| 333 | if (page != 0) { |
| 334 | rq->cmd[1] = 1; |
| 335 | rq->cmd[2] = page; |
| 336 | } |
| 337 | err = blk_execute_rq(sdev->request_queue, NULL, rq, 1); |
| 338 | if (err == -EIO) { |
| 339 | sdev_printk(KERN_INFO, sdev, |
| 340 | "%s: failed to send %s INQUIRY: %x\n", |
| 341 | CLARIION_NAME, page?"EVPD":"standard", |
| 342 | rq->errors); |
| 343 | csdev->senselen = rq->sense_len; |
| 344 | err = SCSI_DH_IO; |
| 345 | } |
| 346 | |
| 347 | blk_put_request(rq); |
| 348 | |
| 349 | return err; |
Chandra Seetharaman | 5e7dcca | 2008-05-01 14:50:04 -0700 | [diff] [blame] | 350 | } |
| 351 | |
Hannes Reinecke | b6ff1b1 | 2008-07-17 16:53:03 -0700 | [diff] [blame] | 352 | static int send_trespass_cmd(struct scsi_device *sdev, |
| 353 | struct clariion_dh_data *csdev) |
Chandra Seetharaman | 5e7dcca | 2008-05-01 14:50:04 -0700 | [diff] [blame] | 354 | { |
Hannes Reinecke | b6ff1b1 | 2008-07-17 16:53:03 -0700 | [diff] [blame] | 355 | struct request *rq; |
| 356 | unsigned char *page22; |
| 357 | int err, len, cmd; |
Chandra Seetharaman | 5e7dcca | 2008-05-01 14:50:04 -0700 | [diff] [blame] | 358 | |
Hannes Reinecke | b6ff1b1 | 2008-07-17 16:53:03 -0700 | [diff] [blame] | 359 | if (csdev->flags & CLARIION_SHORT_TRESPASS) { |
| 360 | page22 = short_trespass; |
| 361 | if (!(csdev->flags & CLARIION_HONOR_RESERVATIONS)) |
| 362 | /* Set Honor Reservations bit */ |
| 363 | page22[6] |= 0x80; |
| 364 | len = sizeof(short_trespass); |
| 365 | cmd = MODE_SELECT; |
| 366 | } else { |
| 367 | page22 = long_trespass; |
| 368 | if (!(csdev->flags & CLARIION_HONOR_RESERVATIONS)) |
| 369 | /* Set Honor Reservations bit */ |
| 370 | page22[10] |= 0x80; |
| 371 | len = sizeof(long_trespass); |
| 372 | cmd = MODE_SELECT_10; |
| 373 | } |
| 374 | BUG_ON((len > CLARIION_BUFFER_SIZE)); |
| 375 | memcpy(csdev->buffer, page22, len); |
Chandra Seetharaman | 5e7dcca | 2008-05-01 14:50:04 -0700 | [diff] [blame] | 376 | |
Hannes Reinecke | b6ff1b1 | 2008-07-17 16:53:03 -0700 | [diff] [blame] | 377 | rq = get_req(sdev, cmd, csdev->buffer); |
| 378 | if (!rq) |
| 379 | return SCSI_DH_RES_TEMP_UNAVAIL; |
Chandra Seetharaman | 5e7dcca | 2008-05-01 14:50:04 -0700 | [diff] [blame] | 380 | |
Hannes Reinecke | b6ff1b1 | 2008-07-17 16:53:03 -0700 | [diff] [blame] | 381 | rq->sense = csdev->sense; |
| 382 | memset(rq->sense, 0, SCSI_SENSE_BUFFERSIZE); |
| 383 | rq->sense_len = csdev->senselen = 0; |
| 384 | |
| 385 | err = blk_execute_rq(sdev->request_queue, NULL, rq, 1); |
| 386 | if (err == -EIO) { |
| 387 | if (rq->sense_len) { |
| 388 | err = trespass_endio(sdev, csdev->sense); |
| 389 | } else { |
| 390 | sdev_printk(KERN_INFO, sdev, |
| 391 | "%s: failed to send MODE SELECT: %x\n", |
| 392 | CLARIION_NAME, rq->errors); |
| 393 | } |
| 394 | } |
| 395 | |
| 396 | blk_put_request(rq); |
| 397 | |
| 398 | return err; |
Chandra Seetharaman | 5e7dcca | 2008-05-01 14:50:04 -0700 | [diff] [blame] | 399 | } |
| 400 | |
| 401 | static int clariion_check_sense(struct scsi_device *sdev, |
| 402 | struct scsi_sense_hdr *sense_hdr) |
| 403 | { |
| 404 | switch (sense_hdr->sense_key) { |
| 405 | case NOT_READY: |
| 406 | if (sense_hdr->asc == 0x04 && sense_hdr->ascq == 0x03) |
| 407 | /* |
| 408 | * LUN Not Ready - Manual Intervention Required |
| 409 | * indicates this is a passive path. |
| 410 | * |
| 411 | * FIXME: However, if this is seen and EVPD C0 |
| 412 | * indicates that this is due to a NDU in |
| 413 | * progress, we should set FAIL_PATH too. |
| 414 | * This indicates we might have to do a SCSI |
| 415 | * inquiry in the end_io path. Ugh. |
| 416 | * |
| 417 | * Can return FAILED only when we want the error |
| 418 | * recovery process to kick in. |
| 419 | */ |
| 420 | return SUCCESS; |
| 421 | break; |
| 422 | case ILLEGAL_REQUEST: |
| 423 | if (sense_hdr->asc == 0x25 && sense_hdr->ascq == 0x01) |
| 424 | /* |
| 425 | * An array based copy is in progress. Do not |
| 426 | * fail the path, do not bypass to another PG, |
| 427 | * do not retry. Fail the IO immediately. |
| 428 | * (Actually this is the same conclusion as in |
| 429 | * the default handler, but lets make sure.) |
| 430 | * |
| 431 | * Can return FAILED only when we want the error |
| 432 | * recovery process to kick in. |
| 433 | */ |
| 434 | return SUCCESS; |
| 435 | break; |
| 436 | case UNIT_ATTENTION: |
| 437 | if (sense_hdr->asc == 0x29 && sense_hdr->ascq == 0x00) |
| 438 | /* |
| 439 | * Unit Attention Code. This is the first IO |
| 440 | * to the new path, so just retry. |
| 441 | */ |
Mike Anderson | c7dbb62 | 2008-08-12 12:11:57 -0700 | [diff] [blame] | 442 | return ADD_TO_MLQUEUE; |
Chandra Seetharaman | 5e7dcca | 2008-05-01 14:50:04 -0700 | [diff] [blame] | 443 | break; |
| 444 | } |
| 445 | |
Hannes Reinecke | b6ff1b1 | 2008-07-17 16:53:03 -0700 | [diff] [blame] | 446 | return SCSI_RETURN_NOT_HANDLED; |
| 447 | } |
| 448 | |
| 449 | static int clariion_prep_fn(struct scsi_device *sdev, struct request *req) |
| 450 | { |
| 451 | struct clariion_dh_data *h = get_clariion_data(sdev); |
| 452 | int ret = BLKPREP_OK; |
| 453 | |
| 454 | if (h->lun_state != CLARIION_LUN_OWNED) { |
| 455 | ret = BLKPREP_KILL; |
| 456 | req->cmd_flags |= REQ_QUIET; |
| 457 | } |
| 458 | return ret; |
| 459 | |
| 460 | } |
| 461 | |
| 462 | static int clariion_std_inquiry(struct scsi_device *sdev, |
| 463 | struct clariion_dh_data *csdev) |
| 464 | { |
| 465 | int err; |
| 466 | char *sp_model; |
| 467 | |
| 468 | err = send_inquiry_cmd(sdev, 0, csdev); |
| 469 | if (err != SCSI_DH_OK && csdev->senselen) { |
| 470 | struct scsi_sense_hdr sshdr; |
| 471 | |
| 472 | if (scsi_normalize_sense(csdev->sense, SCSI_SENSE_BUFFERSIZE, |
| 473 | &sshdr)) { |
| 474 | sdev_printk(KERN_ERR, sdev, "%s: INQUIRY sense code " |
| 475 | "%02x/%02x/%02x\n", CLARIION_NAME, |
| 476 | sshdr.sense_key, sshdr.asc, sshdr.ascq); |
| 477 | } |
| 478 | err = SCSI_DH_IO; |
| 479 | goto out; |
| 480 | } |
| 481 | |
| 482 | sp_model = parse_sp_model(sdev, csdev->buffer); |
| 483 | if (!sp_model) { |
| 484 | err = SCSI_DH_DEV_UNSUPP; |
| 485 | goto out; |
| 486 | } |
| 487 | |
| 488 | /* |
| 489 | * FC Series arrays do not support long trespass |
| 490 | */ |
| 491 | if (!strlen(sp_model) || !strncmp(sp_model, "FC",2)) |
| 492 | csdev->flags |= CLARIION_SHORT_TRESPASS; |
| 493 | |
| 494 | sdev_printk(KERN_INFO, sdev, |
| 495 | "%s: detected Clariion %s, flags %x\n", |
| 496 | CLARIION_NAME, sp_model, csdev->flags); |
| 497 | out: |
| 498 | return err; |
| 499 | } |
| 500 | |
| 501 | static int clariion_send_inquiry(struct scsi_device *sdev, |
| 502 | struct clariion_dh_data *csdev) |
| 503 | { |
| 504 | int err, retry = CLARIION_RETRIES; |
| 505 | |
| 506 | retry: |
| 507 | err = send_inquiry_cmd(sdev, 0xC0, csdev); |
| 508 | if (err != SCSI_DH_OK && csdev->senselen) { |
| 509 | struct scsi_sense_hdr sshdr; |
| 510 | |
| 511 | err = scsi_normalize_sense(csdev->sense, SCSI_SENSE_BUFFERSIZE, |
| 512 | &sshdr); |
| 513 | if (!err) |
| 514 | return SCSI_DH_IO; |
| 515 | |
| 516 | err = clariion_check_sense(sdev, &sshdr); |
Mike Anderson | c7dbb62 | 2008-08-12 12:11:57 -0700 | [diff] [blame] | 517 | if (retry > 0 && err == ADD_TO_MLQUEUE) { |
Hannes Reinecke | b6ff1b1 | 2008-07-17 16:53:03 -0700 | [diff] [blame] | 518 | retry--; |
| 519 | goto retry; |
| 520 | } |
| 521 | sdev_printk(KERN_ERR, sdev, "%s: INQUIRY sense code " |
| 522 | "%02x/%02x/%02x\n", CLARIION_NAME, |
| 523 | sshdr.sense_key, sshdr.asc, sshdr.ascq); |
| 524 | err = SCSI_DH_IO; |
| 525 | } else { |
| 526 | err = parse_sp_info_reply(sdev, csdev); |
| 527 | } |
| 528 | return err; |
| 529 | } |
| 530 | |
| 531 | static int clariion_activate(struct scsi_device *sdev) |
| 532 | { |
| 533 | struct clariion_dh_data *csdev = get_clariion_data(sdev); |
| 534 | int result; |
| 535 | |
| 536 | result = clariion_send_inquiry(sdev, csdev); |
| 537 | if (result != SCSI_DH_OK) |
| 538 | goto done; |
| 539 | |
| 540 | if (csdev->lun_state == CLARIION_LUN_OWNED) |
| 541 | goto done; |
| 542 | |
| 543 | result = send_trespass_cmd(sdev, csdev); |
| 544 | if (result != SCSI_DH_OK) |
| 545 | goto done; |
| 546 | sdev_printk(KERN_INFO, sdev,"%s: %s trespass command sent\n", |
| 547 | CLARIION_NAME, |
| 548 | csdev->flags&CLARIION_SHORT_TRESPASS?"short":"long" ); |
| 549 | |
| 550 | /* Update status */ |
| 551 | result = clariion_send_inquiry(sdev, csdev); |
| 552 | if (result != SCSI_DH_OK) |
| 553 | goto done; |
| 554 | |
| 555 | done: |
| 556 | sdev_printk(KERN_INFO, sdev, |
| 557 | "%s: at SP %c Port %d (%s, default SP %c)\n", |
| 558 | CLARIION_NAME, csdev->current_sp + 'A', |
| 559 | csdev->port, lun_state[csdev->lun_state], |
| 560 | csdev->default_sp + 'A'); |
| 561 | |
| 562 | return result; |
Chandra Seetharaman | 5e7dcca | 2008-05-01 14:50:04 -0700 | [diff] [blame] | 563 | } |
| 564 | |
Adrian Bunk | f08c076 | 2008-08-11 11:59:21 -0700 | [diff] [blame] | 565 | static const struct scsi_dh_devlist clariion_dev_list[] = { |
Chandra Seetharaman | 5e7dcca | 2008-05-01 14:50:04 -0700 | [diff] [blame] | 566 | {"DGC", "RAID"}, |
| 567 | {"DGC", "DISK"}, |
Hannes Reinecke | b6ff1b1 | 2008-07-17 16:53:03 -0700 | [diff] [blame] | 568 | {"DGC", "VRAID"}, |
Chandra Seetharaman | 5e7dcca | 2008-05-01 14:50:04 -0700 | [diff] [blame] | 569 | {NULL, NULL}, |
| 570 | }; |
| 571 | |
Hannes Reinecke | 765cbc6 | 2008-07-17 16:52:51 -0700 | [diff] [blame] | 572 | static int clariion_bus_attach(struct scsi_device *sdev); |
| 573 | static void clariion_bus_detach(struct scsi_device *sdev); |
Chandra Seetharaman | 5e7dcca | 2008-05-01 14:50:04 -0700 | [diff] [blame] | 574 | |
| 575 | static struct scsi_device_handler clariion_dh = { |
| 576 | .name = CLARIION_NAME, |
| 577 | .module = THIS_MODULE, |
Hannes Reinecke | 765cbc6 | 2008-07-17 16:52:51 -0700 | [diff] [blame] | 578 | .devlist = clariion_dev_list, |
| 579 | .attach = clariion_bus_attach, |
| 580 | .detach = clariion_bus_detach, |
Chandra Seetharaman | 5e7dcca | 2008-05-01 14:50:04 -0700 | [diff] [blame] | 581 | .check_sense = clariion_check_sense, |
| 582 | .activate = clariion_activate, |
Hannes Reinecke | b6ff1b1 | 2008-07-17 16:53:03 -0700 | [diff] [blame] | 583 | .prep_fn = clariion_prep_fn, |
Chandra Seetharaman | 5e7dcca | 2008-05-01 14:50:04 -0700 | [diff] [blame] | 584 | }; |
| 585 | |
| 586 | /* |
| 587 | * TODO: need some interface so we can set trespass values |
| 588 | */ |
Hannes Reinecke | 765cbc6 | 2008-07-17 16:52:51 -0700 | [diff] [blame] | 589 | static int clariion_bus_attach(struct scsi_device *sdev) |
Chandra Seetharaman | 5e7dcca | 2008-05-01 14:50:04 -0700 | [diff] [blame] | 590 | { |
Chandra Seetharaman | 5e7dcca | 2008-05-01 14:50:04 -0700 | [diff] [blame] | 591 | struct scsi_dh_data *scsi_dh_data; |
| 592 | struct clariion_dh_data *h; |
Chandra Seetharaman | 5e7dcca | 2008-05-01 14:50:04 -0700 | [diff] [blame] | 593 | unsigned long flags; |
Hannes Reinecke | b6ff1b1 | 2008-07-17 16:53:03 -0700 | [diff] [blame] | 594 | int err; |
Chandra Seetharaman | 5e7dcca | 2008-05-01 14:50:04 -0700 | [diff] [blame] | 595 | |
Hannes Reinecke | 765cbc6 | 2008-07-17 16:52:51 -0700 | [diff] [blame] | 596 | scsi_dh_data = kzalloc(sizeof(struct scsi_device_handler *) |
| 597 | + sizeof(*h) , GFP_KERNEL); |
| 598 | if (!scsi_dh_data) { |
Hannes Reinecke | b6ff1b1 | 2008-07-17 16:53:03 -0700 | [diff] [blame] | 599 | sdev_printk(KERN_ERR, sdev, "%s: Attach failed\n", |
Chandra Seetharaman | 5e7dcca | 2008-05-01 14:50:04 -0700 | [diff] [blame] | 600 | CLARIION_NAME); |
Hannes Reinecke | 765cbc6 | 2008-07-17 16:52:51 -0700 | [diff] [blame] | 601 | return -ENOMEM; |
Chandra Seetharaman | 5e7dcca | 2008-05-01 14:50:04 -0700 | [diff] [blame] | 602 | } |
| 603 | |
Hannes Reinecke | 765cbc6 | 2008-07-17 16:52:51 -0700 | [diff] [blame] | 604 | scsi_dh_data->scsi_dh = &clariion_dh; |
| 605 | h = (struct clariion_dh_data *) scsi_dh_data->buf; |
Hannes Reinecke | b6ff1b1 | 2008-07-17 16:53:03 -0700 | [diff] [blame] | 606 | h->lun_state = CLARIION_LUN_UNINITIALIZED; |
Hannes Reinecke | 765cbc6 | 2008-07-17 16:52:51 -0700 | [diff] [blame] | 607 | h->default_sp = CLARIION_UNBOUND_LU; |
| 608 | h->current_sp = CLARIION_UNBOUND_LU; |
| 609 | |
Hannes Reinecke | b6ff1b1 | 2008-07-17 16:53:03 -0700 | [diff] [blame] | 610 | err = clariion_std_inquiry(sdev, h); |
| 611 | if (err != SCSI_DH_OK) |
| 612 | goto failed; |
| 613 | |
| 614 | err = clariion_send_inquiry(sdev, h); |
| 615 | if (err != SCSI_DH_OK) |
| 616 | goto failed; |
| 617 | |
| 618 | if (!try_module_get(THIS_MODULE)) |
| 619 | goto failed; |
| 620 | |
Hannes Reinecke | 765cbc6 | 2008-07-17 16:52:51 -0700 | [diff] [blame] | 621 | spin_lock_irqsave(sdev->request_queue->queue_lock, flags); |
| 622 | sdev->scsi_dh_data = scsi_dh_data; |
| 623 | spin_unlock_irqrestore(sdev->request_queue->queue_lock, flags); |
| 624 | |
Hannes Reinecke | b6ff1b1 | 2008-07-17 16:53:03 -0700 | [diff] [blame] | 625 | sdev_printk(KERN_INFO, sdev, |
| 626 | "%s: connected to SP %c Port %d (%s, default SP %c)\n", |
| 627 | CLARIION_NAME, h->current_sp + 'A', |
| 628 | h->port, lun_state[h->lun_state], |
| 629 | h->default_sp + 'A'); |
Hannes Reinecke | 765cbc6 | 2008-07-17 16:52:51 -0700 | [diff] [blame] | 630 | |
Chandra Seetharaman | 5e7dcca | 2008-05-01 14:50:04 -0700 | [diff] [blame] | 631 | return 0; |
Hannes Reinecke | b6ff1b1 | 2008-07-17 16:53:03 -0700 | [diff] [blame] | 632 | |
| 633 | failed: |
| 634 | kfree(scsi_dh_data); |
| 635 | sdev_printk(KERN_ERR, sdev, "%s: not attached\n", |
| 636 | CLARIION_NAME); |
| 637 | return -EINVAL; |
Chandra Seetharaman | 5e7dcca | 2008-05-01 14:50:04 -0700 | [diff] [blame] | 638 | } |
| 639 | |
Hannes Reinecke | 765cbc6 | 2008-07-17 16:52:51 -0700 | [diff] [blame] | 640 | static void clariion_bus_detach(struct scsi_device *sdev) |
| 641 | { |
| 642 | struct scsi_dh_data *scsi_dh_data; |
| 643 | unsigned long flags; |
| 644 | |
| 645 | spin_lock_irqsave(sdev->request_queue->queue_lock, flags); |
| 646 | scsi_dh_data = sdev->scsi_dh_data; |
| 647 | sdev->scsi_dh_data = NULL; |
| 648 | spin_unlock_irqrestore(sdev->request_queue->queue_lock, flags); |
| 649 | |
Hannes Reinecke | b6ff1b1 | 2008-07-17 16:53:03 -0700 | [diff] [blame] | 650 | sdev_printk(KERN_NOTICE, sdev, "%s: Detached\n", |
Hannes Reinecke | 765cbc6 | 2008-07-17 16:52:51 -0700 | [diff] [blame] | 651 | CLARIION_NAME); |
| 652 | |
| 653 | kfree(scsi_dh_data); |
| 654 | module_put(THIS_MODULE); |
| 655 | } |
| 656 | |
Chandra Seetharaman | 5e7dcca | 2008-05-01 14:50:04 -0700 | [diff] [blame] | 657 | static int __init clariion_init(void) |
| 658 | { |
| 659 | int r; |
| 660 | |
| 661 | r = scsi_register_device_handler(&clariion_dh); |
| 662 | if (r != 0) |
Hannes Reinecke | b6ff1b1 | 2008-07-17 16:53:03 -0700 | [diff] [blame] | 663 | printk(KERN_ERR "%s: Failed to register scsi device handler.", |
| 664 | CLARIION_NAME); |
Chandra Seetharaman | 5e7dcca | 2008-05-01 14:50:04 -0700 | [diff] [blame] | 665 | return r; |
| 666 | } |
| 667 | |
| 668 | static void __exit clariion_exit(void) |
| 669 | { |
| 670 | scsi_unregister_device_handler(&clariion_dh); |
| 671 | } |
| 672 | |
| 673 | module_init(clariion_init); |
| 674 | module_exit(clariion_exit); |
| 675 | |
| 676 | MODULE_DESCRIPTION("EMC CX/AX/FC-family driver"); |
| 677 | MODULE_AUTHOR("Mike Christie <michaelc@cs.wisc.edu>, Chandra Seetharaman <sekharan@us.ibm.com>"); |
| 678 | MODULE_LICENSE("GPL"); |