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