Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * |
| 3 | * linux/drivers/s390/scsi/zfcp_aux.c |
| 4 | * |
| 5 | * FCP adapter driver for IBM eServer zSeries |
| 6 | * |
| 7 | * (C) Copyright IBM Corp. 2002, 2004 |
| 8 | * |
| 9 | * Author(s): Martin Peschke <mpeschke@de.ibm.com> |
| 10 | * Raimund Schroeder <raimund.schroeder@de.ibm.com> |
| 11 | * Aron Zeh |
| 12 | * Wolfgang Taphorn |
| 13 | * Stefan Bader <stefan.bader@de.ibm.com> |
| 14 | * Heiko Carstens <heiko.carstens@de.ibm.com> |
| 15 | * Andreas Herrmann <aherrman@de.ibm.com> |
| 16 | * |
| 17 | * This program is free software; you can redistribute it and/or modify |
| 18 | * it under the terms of the GNU General Public License as published by |
| 19 | * the Free Software Foundation; either version 2, or (at your option) |
| 20 | * any later version. |
| 21 | * |
| 22 | * This program is distributed in the hope that it will be useful, |
| 23 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 24 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 25 | * GNU General Public License for more details. |
| 26 | * |
| 27 | * You should have received a copy of the GNU General Public License |
| 28 | * along with this program; if not, write to the Free Software |
| 29 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 30 | */ |
| 31 | |
| 32 | #define ZFCP_AUX_REVISION "$Revision: 1.145 $" |
| 33 | |
| 34 | #include "zfcp_ext.h" |
| 35 | |
| 36 | /* accumulated log level (module parameter) */ |
| 37 | static u32 loglevel = ZFCP_LOG_LEVEL_DEFAULTS; |
| 38 | static char *device; |
| 39 | /*********************** FUNCTION PROTOTYPES *********************************/ |
| 40 | |
| 41 | /* written against the module interface */ |
| 42 | static int __init zfcp_module_init(void); |
| 43 | |
| 44 | /* FCP related */ |
| 45 | static void zfcp_ns_gid_pn_handler(unsigned long); |
| 46 | |
| 47 | /* miscellaneous */ |
| 48 | static inline int zfcp_sg_list_alloc(struct zfcp_sg_list *, size_t); |
| 49 | static inline void zfcp_sg_list_free(struct zfcp_sg_list *); |
| 50 | static inline int zfcp_sg_list_copy_from_user(struct zfcp_sg_list *, |
| 51 | void __user *, size_t); |
| 52 | static inline int zfcp_sg_list_copy_to_user(void __user *, |
| 53 | struct zfcp_sg_list *, size_t); |
| 54 | |
Andreas Herrmann | bd6ae2f | 2005-04-21 16:14:31 -0400 | [diff] [blame] | 55 | static long zfcp_cfdc_dev_ioctl(struct file *, unsigned int, unsigned long); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | |
| 57 | #define ZFCP_CFDC_IOC_MAGIC 0xDD |
| 58 | #define ZFCP_CFDC_IOC \ |
| 59 | _IOWR(ZFCP_CFDC_IOC_MAGIC, 0, struct zfcp_cfdc_sense_data) |
| 60 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | |
| 62 | static struct file_operations zfcp_cfdc_fops = { |
| e183b06b | 2005-04-02 13:57:17 -0600 | [diff] [blame] | 63 | .unlocked_ioctl = zfcp_cfdc_dev_ioctl, |
| 64 | #ifdef CONFIG_COMPAT |
| 65 | .compat_ioctl = zfcp_cfdc_dev_ioctl |
| 66 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | }; |
| 68 | |
| 69 | static struct miscdevice zfcp_cfdc_misc = { |
| 70 | .minor = ZFCP_CFDC_DEV_MINOR, |
| 71 | .name = ZFCP_CFDC_DEV_NAME, |
| 72 | .fops = &zfcp_cfdc_fops |
| 73 | }; |
| 74 | |
| 75 | /*********************** KERNEL/MODULE PARAMETERS ***************************/ |
| 76 | |
| 77 | /* declare driver module init/cleanup functions */ |
| 78 | module_init(zfcp_module_init); |
| 79 | |
| 80 | MODULE_AUTHOR("Heiko Carstens <heiko.carstens@de.ibm.com>, " |
| 81 | "Andreas Herrman <aherrman@de.ibm.com>, " |
| 82 | "Martin Peschke <mpeschke@de.ibm.com>, " |
| 83 | "Raimund Schroeder <raimund.schroeder@de.ibm.com>, " |
| 84 | "Wolfgang Taphorn <taphorn@de.ibm.com>, " |
| 85 | "Aron Zeh <arzeh@de.ibm.com>, " |
| 86 | "IBM Deutschland Entwicklung GmbH"); |
| 87 | MODULE_DESCRIPTION |
| 88 | ("FCP (SCSI over Fibre Channel) HBA driver for IBM eServer zSeries"); |
| 89 | MODULE_LICENSE("GPL"); |
| 90 | |
| 6f71d9b | 2005-04-10 23:04:28 -0500 | [diff] [blame] | 91 | module_param(device, charp, 0400); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | MODULE_PARM_DESC(device, "specify initial device"); |
| 93 | |
| 6f71d9b | 2005-04-10 23:04:28 -0500 | [diff] [blame] | 94 | module_param(loglevel, uint, 0400); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | MODULE_PARM_DESC(loglevel, |
| 96 | "log levels, 8 nibbles: " |
| 97 | "FC ERP QDIO CIO Config FSF SCSI Other, " |
| 98 | "levels: 0=none 1=normal 2=devel 3=trace"); |
| 99 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | /****************************************************************/ |
| 101 | /************** Functions without logging ***********************/ |
| 102 | /****************************************************************/ |
| 103 | |
| 104 | void |
| 105 | _zfcp_hex_dump(char *addr, int count) |
| 106 | { |
| 107 | int i; |
| 108 | for (i = 0; i < count; i++) { |
| 109 | printk("%02x", addr[i]); |
| 110 | if ((i % 4) == 3) |
| 111 | printk(" "); |
| 112 | if ((i % 32) == 31) |
| 113 | printk("\n"); |
| 114 | } |
| 115 | if (((i-1) % 32) != 31) |
| 116 | printk("\n"); |
| 117 | } |
| 118 | |
| 119 | /****************************************************************/ |
| 120 | /************** Uncategorised Functions *************************/ |
| 121 | /****************************************************************/ |
| 122 | |
| 123 | #define ZFCP_LOG_AREA ZFCP_LOG_AREA_OTHER |
| 124 | |
| 125 | static inline int |
| 126 | zfcp_fsf_req_is_scsi_cmnd(struct zfcp_fsf_req *fsf_req) |
| 127 | { |
| 128 | return ((fsf_req->fsf_command == FSF_QTCB_FCP_CMND) && |
| 129 | !(fsf_req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT)); |
| 130 | } |
| 131 | |
| 132 | void |
| 133 | zfcp_cmd_dbf_event_fsf(const char *text, struct zfcp_fsf_req *fsf_req, |
| 134 | void *add_data, int add_length) |
| 135 | { |
| 136 | struct zfcp_adapter *adapter = fsf_req->adapter; |
| 137 | struct scsi_cmnd *scsi_cmnd; |
| 138 | int level = 3; |
| 139 | int i; |
| 140 | unsigned long flags; |
| 141 | |
| 142 | spin_lock_irqsave(&adapter->dbf_lock, flags); |
| 143 | if (zfcp_fsf_req_is_scsi_cmnd(fsf_req)) { |
| 144 | scsi_cmnd = fsf_req->data.send_fcp_command_task.scsi_cmnd; |
| 145 | debug_text_event(adapter->cmd_dbf, level, "fsferror"); |
| 146 | debug_text_event(adapter->cmd_dbf, level, text); |
| 147 | debug_event(adapter->cmd_dbf, level, &fsf_req, |
| 148 | sizeof (unsigned long)); |
| 149 | debug_event(adapter->cmd_dbf, level, &fsf_req->seq_no, |
| 150 | sizeof (u32)); |
| 151 | debug_event(adapter->cmd_dbf, level, &scsi_cmnd, |
| 152 | sizeof (unsigned long)); |
| 153 | debug_event(adapter->cmd_dbf, level, &scsi_cmnd->cmnd, |
| 154 | min(ZFCP_CMD_DBF_LENGTH, (int)scsi_cmnd->cmd_len)); |
| 155 | for (i = 0; i < add_length; i += ZFCP_CMD_DBF_LENGTH) |
| 156 | debug_event(adapter->cmd_dbf, |
| 157 | level, |
| 158 | (char *) add_data + i, |
| 159 | min(ZFCP_CMD_DBF_LENGTH, add_length - i)); |
| 160 | } |
| 161 | spin_unlock_irqrestore(&adapter->dbf_lock, flags); |
| 162 | } |
| 163 | |
| 164 | /* XXX additionally log unit if available */ |
| 165 | /* ---> introduce new parameter for unit, see 2.4 code */ |
| 166 | void |
| 167 | zfcp_cmd_dbf_event_scsi(const char *text, struct scsi_cmnd *scsi_cmnd) |
| 168 | { |
| 169 | struct zfcp_adapter *adapter; |
| 170 | union zfcp_req_data *req_data; |
| 171 | struct zfcp_fsf_req *fsf_req; |
| 172 | int level = ((host_byte(scsi_cmnd->result) != 0) ? 1 : 5); |
| 173 | unsigned long flags; |
| 174 | |
| 175 | adapter = (struct zfcp_adapter *) scsi_cmnd->device->host->hostdata[0]; |
| 176 | req_data = (union zfcp_req_data *) scsi_cmnd->host_scribble; |
| 177 | fsf_req = (req_data ? req_data->send_fcp_command_task.fsf_req : NULL); |
| 178 | spin_lock_irqsave(&adapter->dbf_lock, flags); |
| 179 | debug_text_event(adapter->cmd_dbf, level, "hostbyte"); |
| 180 | debug_text_event(adapter->cmd_dbf, level, text); |
| 181 | debug_event(adapter->cmd_dbf, level, &scsi_cmnd->result, sizeof (u32)); |
| 182 | debug_event(adapter->cmd_dbf, level, &scsi_cmnd, |
| 183 | sizeof (unsigned long)); |
| 184 | debug_event(adapter->cmd_dbf, level, &scsi_cmnd->cmnd, |
| 185 | min(ZFCP_CMD_DBF_LENGTH, (int)scsi_cmnd->cmd_len)); |
| 186 | if (likely(fsf_req)) { |
| 187 | debug_event(adapter->cmd_dbf, level, &fsf_req, |
| 188 | sizeof (unsigned long)); |
| 189 | debug_event(adapter->cmd_dbf, level, &fsf_req->seq_no, |
| 190 | sizeof (u32)); |
| 191 | } else { |
| 192 | debug_text_event(adapter->cmd_dbf, level, ""); |
| 193 | debug_text_event(adapter->cmd_dbf, level, ""); |
| 194 | } |
| 195 | spin_unlock_irqrestore(&adapter->dbf_lock, flags); |
| 196 | } |
| 197 | |
| 198 | void |
| 199 | zfcp_in_els_dbf_event(struct zfcp_adapter *adapter, const char *text, |
| 200 | struct fsf_status_read_buffer *status_buffer, int length) |
| 201 | { |
| 202 | int level = 1; |
| 203 | int i; |
| 204 | |
| 205 | debug_text_event(adapter->in_els_dbf, level, text); |
| 206 | debug_event(adapter->in_els_dbf, level, &status_buffer->d_id, 8); |
| 207 | for (i = 0; i < length; i += ZFCP_IN_ELS_DBF_LENGTH) |
| 208 | debug_event(adapter->in_els_dbf, |
| 209 | level, |
| 210 | (char *) status_buffer->payload + i, |
| 211 | min(ZFCP_IN_ELS_DBF_LENGTH, length - i)); |
| 212 | } |
| 213 | |
| 214 | /** |
| 215 | * zfcp_device_setup - setup function |
| 216 | * @str: pointer to parameter string |
| 217 | * |
| 218 | * Parse "device=..." parameter string. |
| 219 | */ |
| 220 | static int __init |
Andreas Herrmann | cd8a383 | 2005-06-13 13:22:25 +0200 | [diff] [blame] | 221 | zfcp_device_setup(char *devstr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 222 | { |
Andreas Herrmann | cd8a383 | 2005-06-13 13:22:25 +0200 | [diff] [blame] | 223 | char *tmp, *str; |
| 224 | size_t len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 225 | |
Andreas Herrmann | cd8a383 | 2005-06-13 13:22:25 +0200 | [diff] [blame] | 226 | if (!devstr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 227 | return 0; |
| 228 | |
Andreas Herrmann | cd8a383 | 2005-06-13 13:22:25 +0200 | [diff] [blame] | 229 | len = strlen(devstr) + 1; |
| 230 | str = (char *) kmalloc(len, GFP_KERNEL); |
| 231 | if (!str) |
| 232 | goto err_out; |
| 233 | memcpy(str, devstr, len); |
| 234 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 235 | tmp = strchr(str, ','); |
| 236 | if (!tmp) |
| 237 | goto err_out; |
| 238 | *tmp++ = '\0'; |
| 239 | strncpy(zfcp_data.init_busid, str, BUS_ID_SIZE); |
| 240 | zfcp_data.init_busid[BUS_ID_SIZE-1] = '\0'; |
| 241 | |
| 242 | zfcp_data.init_wwpn = simple_strtoull(tmp, &tmp, 0); |
| 243 | if (*tmp++ != ',') |
| 244 | goto err_out; |
| 245 | if (*tmp == '\0') |
| 246 | goto err_out; |
| 247 | |
| 248 | zfcp_data.init_fcp_lun = simple_strtoull(tmp, &tmp, 0); |
| 249 | if (*tmp != '\0') |
| 250 | goto err_out; |
Andreas Herrmann | cd8a383 | 2005-06-13 13:22:25 +0200 | [diff] [blame] | 251 | kfree(str); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 252 | return 1; |
| 253 | |
| 254 | err_out: |
| 255 | ZFCP_LOG_NORMAL("Parse error for device parameter string %s\n", str); |
Andreas Herrmann | cd8a383 | 2005-06-13 13:22:25 +0200 | [diff] [blame] | 256 | kfree(str); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 257 | return 0; |
| 258 | } |
| 259 | |
| 260 | static void __init |
| 261 | zfcp_init_device_configure(void) |
| 262 | { |
| 263 | struct zfcp_adapter *adapter; |
| 264 | struct zfcp_port *port; |
| 265 | struct zfcp_unit *unit; |
| 266 | |
| 267 | down(&zfcp_data.config_sema); |
| 268 | read_lock_irq(&zfcp_data.config_lock); |
| 269 | adapter = zfcp_get_adapter_by_busid(zfcp_data.init_busid); |
| 270 | if (adapter) |
| 271 | zfcp_adapter_get(adapter); |
| 272 | read_unlock_irq(&zfcp_data.config_lock); |
| 273 | |
| 274 | if (adapter == NULL) |
| 275 | goto out_adapter; |
| 276 | port = zfcp_port_enqueue(adapter, zfcp_data.init_wwpn, 0, 0); |
| 277 | if (!port) |
| 278 | goto out_port; |
| 279 | unit = zfcp_unit_enqueue(port, zfcp_data.init_fcp_lun); |
| 280 | if (!unit) |
| 281 | goto out_unit; |
| 282 | up(&zfcp_data.config_sema); |
| 283 | ccw_device_set_online(adapter->ccw_device); |
| 284 | zfcp_erp_wait(adapter); |
| 285 | down(&zfcp_data.config_sema); |
| 286 | zfcp_unit_put(unit); |
| 287 | out_unit: |
| 288 | zfcp_port_put(port); |
| 289 | out_port: |
| 290 | zfcp_adapter_put(adapter); |
| 291 | out_adapter: |
| 292 | up(&zfcp_data.config_sema); |
| 293 | return; |
| 294 | } |
| 295 | |
| 296 | static int __init |
| 297 | zfcp_module_init(void) |
| 298 | { |
| 299 | |
| 300 | int retval = 0; |
| 301 | |
| 302 | atomic_set(&zfcp_data.loglevel, loglevel); |
| 303 | |
| 304 | /* initialize adapter list */ |
| 305 | INIT_LIST_HEAD(&zfcp_data.adapter_list_head); |
| 306 | |
| 307 | /* initialize adapters to be removed list head */ |
| 308 | INIT_LIST_HEAD(&zfcp_data.adapter_remove_lh); |
| 309 | |
| 310 | zfcp_transport_template = fc_attach_transport(&zfcp_transport_functions); |
| 311 | if (!zfcp_transport_template) |
| 312 | return -ENODEV; |
| 313 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 314 | retval = misc_register(&zfcp_cfdc_misc); |
| 315 | if (retval != 0) { |
| 316 | ZFCP_LOG_INFO("registration of misc device " |
| 317 | "zfcp_cfdc failed\n"); |
| e183b06b | 2005-04-02 13:57:17 -0600 | [diff] [blame] | 318 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 319 | } |
| 320 | |
| e183b06b | 2005-04-02 13:57:17 -0600 | [diff] [blame] | 321 | ZFCP_LOG_TRACE("major/minor for zfcp_cfdc: %d/%d\n", |
| 322 | ZFCP_CFDC_DEV_MAJOR, zfcp_cfdc_misc.minor); |
| 323 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 324 | /* Initialise proc semaphores */ |
| 325 | sema_init(&zfcp_data.config_sema, 1); |
| 326 | |
| 327 | /* initialise configuration rw lock */ |
| 328 | rwlock_init(&zfcp_data.config_lock); |
| 329 | |
| 330 | /* save address of data structure managing the driver module */ |
| 331 | zfcp_data.scsi_host_template.module = THIS_MODULE; |
| 332 | |
| 333 | /* setup dynamic I/O */ |
| 334 | retval = zfcp_ccw_register(); |
| 335 | if (retval) { |
| 336 | ZFCP_LOG_NORMAL("registration with common I/O layer failed\n"); |
| 337 | goto out_ccw_register; |
| 338 | } |
| 339 | |
| 340 | if (zfcp_device_setup(device)) |
| 341 | zfcp_init_device_configure(); |
| 342 | |
| 343 | goto out; |
| 344 | |
| 345 | out_ccw_register: |
| 346 | misc_deregister(&zfcp_cfdc_misc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 347 | out: |
| 348 | return retval; |
| 349 | } |
| 350 | |
| 351 | /* |
| 352 | * function: zfcp_cfdc_dev_ioctl |
| 353 | * |
| 354 | * purpose: Handle control file upload/download transaction via IOCTL |
| 355 | * interface |
| 356 | * |
| 357 | * returns: 0 - Operation completed successfuly |
| 358 | * -ENOTTY - Unknown IOCTL command |
| 359 | * -EINVAL - Invalid sense data record |
| 360 | * -ENXIO - The FCP adapter is not available |
| 361 | * -EOPNOTSUPP - The FCP adapter does not have CFDC support |
| 362 | * -ENOMEM - Insufficient memory |
| 363 | * -EFAULT - User space memory I/O operation fault |
| 364 | * -EPERM - Cannot create or queue FSF request or create SBALs |
| 365 | * -ERESTARTSYS- Received signal (is mapped to EAGAIN by VFS) |
| 366 | */ |
| e183b06b | 2005-04-02 13:57:17 -0600 | [diff] [blame] | 367 | static long |
| 368 | zfcp_cfdc_dev_ioctl(struct file *file, unsigned int command, |
| 369 | unsigned long buffer) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 370 | { |
| 371 | struct zfcp_cfdc_sense_data *sense_data, __user *sense_data_user; |
| 372 | struct zfcp_adapter *adapter = NULL; |
| 373 | struct zfcp_fsf_req *fsf_req = NULL; |
| 374 | struct zfcp_sg_list *sg_list = NULL; |
| 375 | u32 fsf_command, option; |
| 376 | char *bus_id = NULL; |
| 377 | int retval = 0; |
| 378 | |
| 379 | sense_data = kmalloc(sizeof(struct zfcp_cfdc_sense_data), GFP_KERNEL); |
| 380 | if (sense_data == NULL) { |
| 381 | retval = -ENOMEM; |
| 382 | goto out; |
| 383 | } |
| 384 | |
| 385 | sg_list = kmalloc(sizeof(struct zfcp_sg_list), GFP_KERNEL); |
| 386 | if (sg_list == NULL) { |
| 387 | retval = -ENOMEM; |
| 388 | goto out; |
| 389 | } |
| 390 | memset(sg_list, 0, sizeof(*sg_list)); |
| 391 | |
| 392 | if (command != ZFCP_CFDC_IOC) { |
| 393 | ZFCP_LOG_INFO("IOC request code 0x%x invalid\n", command); |
| 394 | retval = -ENOTTY; |
| 395 | goto out; |
| 396 | } |
| 397 | |
| 398 | if ((sense_data_user = (void __user *) buffer) == NULL) { |
| 399 | ZFCP_LOG_INFO("sense data record is required\n"); |
| 400 | retval = -EINVAL; |
| 401 | goto out; |
| 402 | } |
| 403 | |
| 404 | retval = copy_from_user(sense_data, sense_data_user, |
| 405 | sizeof(struct zfcp_cfdc_sense_data)); |
| 406 | if (retval) { |
| 407 | retval = -EFAULT; |
| 408 | goto out; |
| 409 | } |
| 410 | |
| 411 | if (sense_data->signature != ZFCP_CFDC_SIGNATURE) { |
| 412 | ZFCP_LOG_INFO("invalid sense data request signature 0x%08x\n", |
| 413 | ZFCP_CFDC_SIGNATURE); |
| 414 | retval = -EINVAL; |
| 415 | goto out; |
| 416 | } |
| 417 | |
| 418 | switch (sense_data->command) { |
| 419 | |
| 420 | case ZFCP_CFDC_CMND_DOWNLOAD_NORMAL: |
| 421 | fsf_command = FSF_QTCB_DOWNLOAD_CONTROL_FILE; |
| 422 | option = FSF_CFDC_OPTION_NORMAL_MODE; |
| 423 | break; |
| 424 | |
| 425 | case ZFCP_CFDC_CMND_DOWNLOAD_FORCE: |
| 426 | fsf_command = FSF_QTCB_DOWNLOAD_CONTROL_FILE; |
| 427 | option = FSF_CFDC_OPTION_FORCE; |
| 428 | break; |
| 429 | |
| 430 | case ZFCP_CFDC_CMND_FULL_ACCESS: |
| 431 | fsf_command = FSF_QTCB_DOWNLOAD_CONTROL_FILE; |
| 432 | option = FSF_CFDC_OPTION_FULL_ACCESS; |
| 433 | break; |
| 434 | |
| 435 | case ZFCP_CFDC_CMND_RESTRICTED_ACCESS: |
| 436 | fsf_command = FSF_QTCB_DOWNLOAD_CONTROL_FILE; |
| 437 | option = FSF_CFDC_OPTION_RESTRICTED_ACCESS; |
| 438 | break; |
| 439 | |
| 440 | case ZFCP_CFDC_CMND_UPLOAD: |
| 441 | fsf_command = FSF_QTCB_UPLOAD_CONTROL_FILE; |
| 442 | option = 0; |
| 443 | break; |
| 444 | |
| 445 | default: |
| 446 | ZFCP_LOG_INFO("invalid command code 0x%08x\n", |
| 447 | sense_data->command); |
| 448 | retval = -EINVAL; |
| 449 | goto out; |
| 450 | } |
| 451 | |
| 452 | bus_id = kmalloc(BUS_ID_SIZE, GFP_KERNEL); |
| 453 | if (bus_id == NULL) { |
| 454 | retval = -ENOMEM; |
| 455 | goto out; |
| 456 | } |
| 457 | snprintf(bus_id, BUS_ID_SIZE, "%d.%d.%04x", |
| 458 | (sense_data->devno >> 24), |
| 459 | (sense_data->devno >> 16) & 0xFF, |
| 460 | (sense_data->devno & 0xFFFF)); |
| 461 | |
| 462 | read_lock_irq(&zfcp_data.config_lock); |
| 463 | adapter = zfcp_get_adapter_by_busid(bus_id); |
| 464 | if (adapter) |
| 465 | zfcp_adapter_get(adapter); |
| 466 | read_unlock_irq(&zfcp_data.config_lock); |
| 467 | |
| 468 | kfree(bus_id); |
| 469 | |
| 470 | if (adapter == NULL) { |
| 471 | ZFCP_LOG_INFO("invalid adapter\n"); |
| 472 | retval = -ENXIO; |
| 473 | goto out; |
| 474 | } |
| 475 | |
| 476 | if (sense_data->command & ZFCP_CFDC_WITH_CONTROL_FILE) { |
| 477 | retval = zfcp_sg_list_alloc(sg_list, |
| 478 | ZFCP_CFDC_MAX_CONTROL_FILE_SIZE); |
| 479 | if (retval) { |
| 480 | retval = -ENOMEM; |
| 481 | goto out; |
| 482 | } |
| 483 | } |
| 484 | |
| 485 | if ((sense_data->command & ZFCP_CFDC_DOWNLOAD) && |
| 486 | (sense_data->command & ZFCP_CFDC_WITH_CONTROL_FILE)) { |
| 487 | retval = zfcp_sg_list_copy_from_user( |
| 488 | sg_list, &sense_data_user->control_file, |
| 489 | ZFCP_CFDC_MAX_CONTROL_FILE_SIZE); |
| 490 | if (retval) { |
| 491 | retval = -EFAULT; |
| 492 | goto out; |
| 493 | } |
| 494 | } |
| 495 | |
| 496 | retval = zfcp_fsf_control_file(adapter, &fsf_req, fsf_command, |
| 497 | option, sg_list); |
| 498 | if (retval) |
| 499 | goto out; |
| 500 | |
| 501 | if ((fsf_req->qtcb->prefix.prot_status != FSF_PROT_GOOD) && |
| 502 | (fsf_req->qtcb->prefix.prot_status != FSF_PROT_FSF_STATUS_PRESENTED)) { |
| 503 | retval = -ENXIO; |
| 504 | goto out; |
| 505 | } |
| 506 | |
| 507 | sense_data->fsf_status = fsf_req->qtcb->header.fsf_status; |
| 508 | memcpy(&sense_data->fsf_status_qual, |
| 509 | &fsf_req->qtcb->header.fsf_status_qual, |
| 510 | sizeof(union fsf_status_qual)); |
| 511 | memcpy(&sense_data->payloads, &fsf_req->qtcb->bottom.support.els, 256); |
| 512 | |
| 513 | retval = copy_to_user(sense_data_user, sense_data, |
| 514 | sizeof(struct zfcp_cfdc_sense_data)); |
| 515 | if (retval) { |
| 516 | retval = -EFAULT; |
| 517 | goto out; |
| 518 | } |
| 519 | |
| 520 | if (sense_data->command & ZFCP_CFDC_UPLOAD) { |
| 521 | retval = zfcp_sg_list_copy_to_user( |
| 522 | &sense_data_user->control_file, sg_list, |
| 523 | ZFCP_CFDC_MAX_CONTROL_FILE_SIZE); |
| 524 | if (retval) { |
| 525 | retval = -EFAULT; |
| 526 | goto out; |
| 527 | } |
| 528 | } |
| 529 | |
| 530 | out: |
| 531 | if (fsf_req != NULL) |
Andreas Herrmann | 1db2c9c | 2005-06-13 13:20:35 +0200 | [diff] [blame] | 532 | zfcp_fsf_req_free(fsf_req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 533 | |
| 534 | if ((adapter != NULL) && (retval != -ENXIO)) |
| 535 | zfcp_adapter_put(adapter); |
| 536 | |
| 537 | if (sg_list != NULL) { |
| 538 | zfcp_sg_list_free(sg_list); |
| 539 | kfree(sg_list); |
| 540 | } |
| 541 | |
| 542 | if (sense_data != NULL) |
| 543 | kfree(sense_data); |
| 544 | |
| 545 | return retval; |
| 546 | } |
| 547 | |
| 548 | |
| 549 | /** |
| 550 | * zfcp_sg_list_alloc - create a scatter-gather list of the specified size |
| 551 | * @sg_list: structure describing a scatter gather list |
| 552 | * @size: size of scatter-gather list |
| 553 | * Return: 0 on success, else -ENOMEM |
| 554 | * |
| 555 | * In sg_list->sg a pointer to the created scatter-gather list is returned, |
| 556 | * or NULL if we run out of memory. sg_list->count specifies the number of |
| 557 | * elements of the scatter-gather list. The maximum size of a single element |
| 558 | * in the scatter-gather list is PAGE_SIZE. |
| 559 | */ |
| 560 | static inline int |
| 561 | zfcp_sg_list_alloc(struct zfcp_sg_list *sg_list, size_t size) |
| 562 | { |
| 563 | struct scatterlist *sg; |
| 564 | unsigned int i; |
| 565 | int retval = 0; |
| 566 | void *address; |
| 567 | |
| 568 | BUG_ON(sg_list == NULL); |
| 569 | |
| 570 | sg_list->count = size >> PAGE_SHIFT; |
| 571 | if (size & ~PAGE_MASK) |
| 572 | sg_list->count++; |
| 573 | sg_list->sg = kmalloc(sg_list->count * sizeof(struct scatterlist), |
| 574 | GFP_KERNEL); |
| 575 | if (sg_list->sg == NULL) { |
| 576 | sg_list->count = 0; |
| 577 | retval = -ENOMEM; |
| 578 | goto out; |
| 579 | } |
| 580 | memset(sg_list->sg, 0, sg_list->count * sizeof(struct scatterlist)); |
| 581 | |
| 582 | for (i = 0, sg = sg_list->sg; i < sg_list->count; i++, sg++) { |
| 583 | sg->length = min(size, PAGE_SIZE); |
| 584 | sg->offset = 0; |
| 585 | address = (void *) get_zeroed_page(GFP_KERNEL); |
| 586 | if (address == NULL) { |
| 587 | sg_list->count = i; |
| 588 | zfcp_sg_list_free(sg_list); |
| 589 | retval = -ENOMEM; |
| 590 | goto out; |
| 591 | } |
| 592 | zfcp_address_to_sg(address, sg); |
| 593 | size -= sg->length; |
| 594 | } |
| 595 | |
| 596 | out: |
| 597 | return retval; |
| 598 | } |
| 599 | |
| 600 | |
| 601 | /** |
| 602 | * zfcp_sg_list_free - free memory of a scatter-gather list |
| 603 | * @sg_list: structure describing a scatter-gather list |
| 604 | * |
| 605 | * Memory for each element in the scatter-gather list is freed. |
| 606 | * Finally sg_list->sg is freed itself and sg_list->count is reset. |
| 607 | */ |
| 608 | static inline void |
| 609 | zfcp_sg_list_free(struct zfcp_sg_list *sg_list) |
| 610 | { |
| 611 | struct scatterlist *sg; |
| 612 | unsigned int i; |
| 613 | |
| 614 | BUG_ON(sg_list == NULL); |
| 615 | |
| 616 | for (i = 0, sg = sg_list->sg; i < sg_list->count; i++, sg++) |
| 617 | free_page((unsigned long) zfcp_sg_to_address(sg)); |
| 618 | |
| 619 | sg_list->count = 0; |
| 620 | kfree(sg_list->sg); |
| 621 | } |
| 622 | |
| 623 | /** |
| 624 | * zfcp_sg_size - determine size of a scatter-gather list |
| 625 | * @sg: array of (struct scatterlist) |
| 626 | * @sg_count: elements in array |
| 627 | * Return: size of entire scatter-gather list |
| 628 | */ |
| 629 | size_t |
| 630 | zfcp_sg_size(struct scatterlist *sg, unsigned int sg_count) |
| 631 | { |
| 632 | unsigned int i; |
| 633 | struct scatterlist *p; |
| 634 | size_t size; |
| 635 | |
| 636 | size = 0; |
| 637 | for (i = 0, p = sg; i < sg_count; i++, p++) { |
| 638 | BUG_ON(p == NULL); |
| 639 | size += p->length; |
| 640 | } |
| 641 | |
| 642 | return size; |
| 643 | } |
| 644 | |
| 645 | |
| 646 | /** |
| 647 | * zfcp_sg_list_copy_from_user -copy data from user space to scatter-gather list |
| 648 | * @sg_list: structure describing a scatter-gather list |
| 649 | * @user_buffer: pointer to buffer in user space |
| 650 | * @size: number of bytes to be copied |
| 651 | * Return: 0 on success, -EFAULT if copy_from_user fails. |
| 652 | */ |
| 653 | static inline int |
| 654 | zfcp_sg_list_copy_from_user(struct zfcp_sg_list *sg_list, |
| 655 | void __user *user_buffer, |
| 656 | size_t size) |
| 657 | { |
| 658 | struct scatterlist *sg; |
| 659 | unsigned int length; |
| 660 | void *zfcp_buffer; |
| 661 | int retval = 0; |
| 662 | |
| 663 | BUG_ON(sg_list == NULL); |
| 664 | |
| 665 | if (zfcp_sg_size(sg_list->sg, sg_list->count) < size) |
| 666 | return -EFAULT; |
| 667 | |
| 668 | for (sg = sg_list->sg; size > 0; sg++) { |
| 669 | length = min((unsigned int)size, sg->length); |
| 670 | zfcp_buffer = zfcp_sg_to_address(sg); |
| 671 | if (copy_from_user(zfcp_buffer, user_buffer, length)) { |
| 672 | retval = -EFAULT; |
| 673 | goto out; |
| 674 | } |
| 675 | user_buffer += length; |
| 676 | size -= length; |
| 677 | } |
| 678 | |
| 679 | out: |
| 680 | return retval; |
| 681 | } |
| 682 | |
| 683 | |
| 684 | /** |
| 685 | * zfcp_sg_list_copy_to_user - copy data from scatter-gather list to user space |
| 686 | * @user_buffer: pointer to buffer in user space |
| 687 | * @sg_list: structure describing a scatter-gather list |
| 688 | * @size: number of bytes to be copied |
| 689 | * Return: 0 on success, -EFAULT if copy_to_user fails |
| 690 | */ |
| 691 | static inline int |
| 692 | zfcp_sg_list_copy_to_user(void __user *user_buffer, |
| 693 | struct zfcp_sg_list *sg_list, |
| 694 | size_t size) |
| 695 | { |
| 696 | struct scatterlist *sg; |
| 697 | unsigned int length; |
| 698 | void *zfcp_buffer; |
| 699 | int retval = 0; |
| 700 | |
| 701 | BUG_ON(sg_list == NULL); |
| 702 | |
| 703 | if (zfcp_sg_size(sg_list->sg, sg_list->count) < size) |
| 704 | return -EFAULT; |
| 705 | |
| 706 | for (sg = sg_list->sg; size > 0; sg++) { |
| 707 | length = min((unsigned int) size, sg->length); |
| 708 | zfcp_buffer = zfcp_sg_to_address(sg); |
| 709 | if (copy_to_user(user_buffer, zfcp_buffer, length)) { |
| 710 | retval = -EFAULT; |
| 711 | goto out; |
| 712 | } |
| 713 | user_buffer += length; |
| 714 | size -= length; |
| 715 | } |
| 716 | |
| 717 | out: |
| 718 | return retval; |
| 719 | } |
| 720 | |
| 721 | |
| 722 | #undef ZFCP_LOG_AREA |
| 723 | |
| 724 | /****************************************************************/ |
| 725 | /****** Functions for configuration/set-up of structures ********/ |
| 726 | /****************************************************************/ |
| 727 | |
| 728 | #define ZFCP_LOG_AREA ZFCP_LOG_AREA_CONFIG |
| 729 | |
| 730 | /** |
| 731 | * zfcp_get_unit_by_lun - find unit in unit list of port by FCP LUN |
| 732 | * @port: pointer to port to search for unit |
| 733 | * @fcp_lun: FCP LUN to search for |
| 734 | * Traverse list of all units of a port and return pointer to a unit |
| 735 | * with the given FCP LUN. |
| 736 | */ |
| 737 | struct zfcp_unit * |
| 738 | zfcp_get_unit_by_lun(struct zfcp_port *port, fcp_lun_t fcp_lun) |
| 739 | { |
| 740 | struct zfcp_unit *unit; |
| 741 | int found = 0; |
| 742 | |
| 743 | list_for_each_entry(unit, &port->unit_list_head, list) { |
| 744 | if ((unit->fcp_lun == fcp_lun) && |
| 745 | !atomic_test_mask(ZFCP_STATUS_COMMON_REMOVE, &unit->status)) |
| 746 | { |
| 747 | found = 1; |
| 748 | break; |
| 749 | } |
| 750 | } |
| 751 | return found ? unit : NULL; |
| 752 | } |
| 753 | |
| 754 | /** |
| 755 | * zfcp_get_port_by_wwpn - find port in port list of adapter by wwpn |
| 756 | * @adapter: pointer to adapter to search for port |
| 757 | * @wwpn: wwpn to search for |
| 758 | * Traverse list of all ports of an adapter and return pointer to a port |
| 759 | * with the given wwpn. |
| 760 | */ |
| 761 | struct zfcp_port * |
| 762 | zfcp_get_port_by_wwpn(struct zfcp_adapter *adapter, wwn_t wwpn) |
| 763 | { |
| 764 | struct zfcp_port *port; |
| 765 | int found = 0; |
| 766 | |
| 767 | list_for_each_entry(port, &adapter->port_list_head, list) { |
| 768 | if ((port->wwpn == wwpn) && |
| 769 | !(atomic_read(&port->status) & |
| 770 | (ZFCP_STATUS_PORT_NO_WWPN | ZFCP_STATUS_COMMON_REMOVE))) { |
| 771 | found = 1; |
| 772 | break; |
| 773 | } |
| 774 | } |
| 775 | return found ? port : NULL; |
| 776 | } |
| 777 | |
| 778 | /** |
| 779 | * zfcp_get_port_by_did - find port in port list of adapter by d_id |
| 780 | * @adapter: pointer to adapter to search for port |
| 781 | * @d_id: d_id to search for |
| 782 | * Traverse list of all ports of an adapter and return pointer to a port |
| 783 | * with the given d_id. |
| 784 | */ |
| 785 | struct zfcp_port * |
| 786 | zfcp_get_port_by_did(struct zfcp_adapter *adapter, u32 d_id) |
| 787 | { |
| 788 | struct zfcp_port *port; |
| 789 | int found = 0; |
| 790 | |
| 791 | list_for_each_entry(port, &adapter->port_list_head, list) { |
| 792 | if ((port->d_id == d_id) && |
| 793 | !atomic_test_mask(ZFCP_STATUS_COMMON_REMOVE, &port->status)) |
| 794 | { |
| 795 | found = 1; |
| 796 | break; |
| 797 | } |
| 798 | } |
| 799 | return found ? port : NULL; |
| 800 | } |
| 801 | |
| 802 | /** |
| 803 | * zfcp_get_adapter_by_busid - find adpater in adapter list by bus_id |
| 804 | * @bus_id: bus_id to search for |
| 805 | * Traverse list of all adapters and return pointer to an adapter |
| 806 | * with the given bus_id. |
| 807 | */ |
| 808 | struct zfcp_adapter * |
| 809 | zfcp_get_adapter_by_busid(char *bus_id) |
| 810 | { |
| 811 | struct zfcp_adapter *adapter; |
| 812 | int found = 0; |
| 813 | |
| 814 | list_for_each_entry(adapter, &zfcp_data.adapter_list_head, list) { |
| 815 | if ((strncmp(bus_id, zfcp_get_busid_by_adapter(adapter), |
| 816 | BUS_ID_SIZE) == 0) && |
| 817 | !atomic_test_mask(ZFCP_STATUS_COMMON_REMOVE, |
| 818 | &adapter->status)){ |
| 819 | found = 1; |
| 820 | break; |
| 821 | } |
| 822 | } |
| 823 | return found ? adapter : NULL; |
| 824 | } |
| 825 | |
| 826 | /** |
| 827 | * zfcp_unit_enqueue - enqueue unit to unit list of a port. |
| 828 | * @port: pointer to port where unit is added |
| 829 | * @fcp_lun: FCP LUN of unit to be enqueued |
| 830 | * Return: pointer to enqueued unit on success, NULL on error |
| 831 | * Locks: config_sema must be held to serialize changes to the unit list |
| 832 | * |
| 833 | * Sets up some unit internal structures and creates sysfs entry. |
| 834 | */ |
| 835 | struct zfcp_unit * |
| 836 | zfcp_unit_enqueue(struct zfcp_port *port, fcp_lun_t fcp_lun) |
| 837 | { |
| 838 | struct zfcp_unit *unit, *tmp_unit; |
| 839 | scsi_lun_t scsi_lun; |
| 840 | int found; |
| 841 | |
| 842 | /* |
| 843 | * check that there is no unit with this FCP_LUN already in list |
| 844 | * and enqueue it. |
| 845 | * Note: Unlike for the adapter and the port, this is an error |
| 846 | */ |
| 847 | read_lock_irq(&zfcp_data.config_lock); |
| 848 | unit = zfcp_get_unit_by_lun(port, fcp_lun); |
| 849 | read_unlock_irq(&zfcp_data.config_lock); |
| 850 | if (unit) |
| 851 | return NULL; |
| 852 | |
| 853 | unit = kmalloc(sizeof (struct zfcp_unit), GFP_KERNEL); |
| 854 | if (!unit) |
| 855 | return NULL; |
| 856 | memset(unit, 0, sizeof (struct zfcp_unit)); |
| 857 | |
| 858 | /* initialise reference count stuff */ |
| 859 | atomic_set(&unit->refcount, 0); |
| 860 | init_waitqueue_head(&unit->remove_wq); |
| 861 | |
| 862 | unit->port = port; |
| 863 | unit->fcp_lun = fcp_lun; |
| 864 | |
| 865 | /* setup for sysfs registration */ |
| 866 | snprintf(unit->sysfs_device.bus_id, BUS_ID_SIZE, "0x%016llx", fcp_lun); |
| 867 | unit->sysfs_device.parent = &port->sysfs_device; |
| 868 | unit->sysfs_device.release = zfcp_sysfs_unit_release; |
| 869 | dev_set_drvdata(&unit->sysfs_device, unit); |
| 870 | |
| 871 | /* mark unit unusable as long as sysfs registration is not complete */ |
| 872 | atomic_set_mask(ZFCP_STATUS_COMMON_REMOVE, &unit->status); |
| 873 | |
| 874 | if (device_register(&unit->sysfs_device)) { |
| 875 | kfree(unit); |
| 876 | return NULL; |
| 877 | } |
| 878 | |
| 879 | if (zfcp_sysfs_unit_create_files(&unit->sysfs_device)) { |
| 880 | device_unregister(&unit->sysfs_device); |
| 881 | return NULL; |
| 882 | } |
| 883 | |
| 884 | zfcp_unit_get(unit); |
| 885 | |
| 886 | scsi_lun = 0; |
| 887 | found = 0; |
| 888 | write_lock_irq(&zfcp_data.config_lock); |
| 889 | list_for_each_entry(tmp_unit, &port->unit_list_head, list) { |
| 890 | if (tmp_unit->scsi_lun != scsi_lun) { |
| 891 | found = 1; |
| 892 | break; |
| 893 | } |
| 894 | scsi_lun++; |
| 895 | } |
| 896 | unit->scsi_lun = scsi_lun; |
| 897 | if (found) |
| 898 | list_add_tail(&unit->list, &tmp_unit->list); |
| 899 | else |
| 900 | list_add_tail(&unit->list, &port->unit_list_head); |
| 901 | atomic_clear_mask(ZFCP_STATUS_COMMON_REMOVE, &unit->status); |
| 902 | atomic_set_mask(ZFCP_STATUS_COMMON_RUNNING, &unit->status); |
| 903 | write_unlock_irq(&zfcp_data.config_lock); |
| 904 | |
| 905 | port->units++; |
| 906 | zfcp_port_get(port); |
| 907 | |
| 908 | return unit; |
| 909 | } |
| 910 | |
| 911 | void |
| 912 | zfcp_unit_dequeue(struct zfcp_unit *unit) |
| 913 | { |
| 914 | zfcp_unit_wait(unit); |
| 915 | write_lock_irq(&zfcp_data.config_lock); |
| 916 | list_del(&unit->list); |
| 917 | write_unlock_irq(&zfcp_data.config_lock); |
| 918 | unit->port->units--; |
| 919 | zfcp_port_put(unit->port); |
| 920 | zfcp_sysfs_unit_remove_files(&unit->sysfs_device); |
| 921 | device_unregister(&unit->sysfs_device); |
| 922 | } |
| 923 | |
| 924 | static void * |
| 925 | zfcp_mempool_alloc(unsigned int __nocast gfp_mask, void *size) |
| 926 | { |
| 927 | return kmalloc((size_t) size, gfp_mask); |
| 928 | } |
| 929 | |
| 930 | static void |
| 931 | zfcp_mempool_free(void *element, void *size) |
| 932 | { |
| 933 | kfree(element); |
| 934 | } |
| 935 | |
| 936 | /* |
| 937 | * Allocates a combined QTCB/fsf_req buffer for erp actions and fcp/SCSI |
| 938 | * commands. |
| 939 | * It also genrates fcp-nameserver request/response buffer and unsolicited |
| 940 | * status read fsf_req buffers. |
| 941 | * |
| 942 | * locks: must only be called with zfcp_data.config_sema taken |
| 943 | */ |
| 944 | static int |
| 945 | zfcp_allocate_low_mem_buffers(struct zfcp_adapter *adapter) |
| 946 | { |
| 947 | adapter->pool.fsf_req_erp = |
| 948 | mempool_create(ZFCP_POOL_FSF_REQ_ERP_NR, |
| 949 | zfcp_mempool_alloc, zfcp_mempool_free, (void *) |
| 950 | sizeof(struct zfcp_fsf_req_pool_element)); |
| 951 | |
| 952 | if (NULL == adapter->pool.fsf_req_erp) |
| 953 | return -ENOMEM; |
| 954 | |
| 955 | adapter->pool.fsf_req_scsi = |
| 956 | mempool_create(ZFCP_POOL_FSF_REQ_SCSI_NR, |
| 957 | zfcp_mempool_alloc, zfcp_mempool_free, (void *) |
| 958 | sizeof(struct zfcp_fsf_req_pool_element)); |
| 959 | |
| 960 | if (NULL == adapter->pool.fsf_req_scsi) |
| 961 | return -ENOMEM; |
| 962 | |
| 963 | adapter->pool.fsf_req_abort = |
| 964 | mempool_create(ZFCP_POOL_FSF_REQ_ABORT_NR, |
| 965 | zfcp_mempool_alloc, zfcp_mempool_free, (void *) |
| 966 | sizeof(struct zfcp_fsf_req_pool_element)); |
| 967 | |
| 968 | if (NULL == adapter->pool.fsf_req_abort) |
| 969 | return -ENOMEM; |
| 970 | |
| 971 | adapter->pool.fsf_req_status_read = |
| 972 | mempool_create(ZFCP_POOL_STATUS_READ_NR, |
| 973 | zfcp_mempool_alloc, zfcp_mempool_free, |
| 974 | (void *) sizeof(struct zfcp_fsf_req)); |
| 975 | |
| 976 | if (NULL == adapter->pool.fsf_req_status_read) |
| 977 | return -ENOMEM; |
| 978 | |
| 979 | adapter->pool.data_status_read = |
| 980 | mempool_create(ZFCP_POOL_STATUS_READ_NR, |
| 981 | zfcp_mempool_alloc, zfcp_mempool_free, |
| 982 | (void *) sizeof(struct fsf_status_read_buffer)); |
| 983 | |
| 984 | if (NULL == adapter->pool.data_status_read) |
| 985 | return -ENOMEM; |
| 986 | |
| 987 | adapter->pool.data_gid_pn = |
| 988 | mempool_create(ZFCP_POOL_DATA_GID_PN_NR, |
| 989 | zfcp_mempool_alloc, zfcp_mempool_free, (void *) |
| 990 | sizeof(struct zfcp_gid_pn_data)); |
| 991 | |
| 992 | if (NULL == adapter->pool.data_gid_pn) |
| 993 | return -ENOMEM; |
| 994 | |
| 995 | return 0; |
| 996 | } |
| 997 | |
| 998 | /** |
| 999 | * zfcp_free_low_mem_buffers - free memory pools of an adapter |
| 1000 | * @adapter: pointer to zfcp_adapter for which memory pools should be freed |
| 1001 | * locking: zfcp_data.config_sema must be held |
| 1002 | */ |
| 1003 | static void |
| 1004 | zfcp_free_low_mem_buffers(struct zfcp_adapter *adapter) |
| 1005 | { |
| 1006 | if (adapter->pool.fsf_req_erp) |
| 1007 | mempool_destroy(adapter->pool.fsf_req_erp); |
| 1008 | if (adapter->pool.fsf_req_scsi) |
| 1009 | mempool_destroy(adapter->pool.fsf_req_scsi); |
| 1010 | if (adapter->pool.fsf_req_abort) |
| 1011 | mempool_destroy(adapter->pool.fsf_req_abort); |
| 1012 | if (adapter->pool.fsf_req_status_read) |
| 1013 | mempool_destroy(adapter->pool.fsf_req_status_read); |
| 1014 | if (adapter->pool.data_status_read) |
| 1015 | mempool_destroy(adapter->pool.data_status_read); |
| 1016 | if (adapter->pool.data_gid_pn) |
| 1017 | mempool_destroy(adapter->pool.data_gid_pn); |
| 1018 | } |
| 1019 | |
| 1020 | /** |
| 1021 | * zfcp_adapter_debug_register - registers debug feature for an adapter |
| 1022 | * @adapter: pointer to adapter for which debug features should be registered |
| 1023 | * return: -ENOMEM on error, 0 otherwise |
| 1024 | */ |
| 1025 | int |
| 1026 | zfcp_adapter_debug_register(struct zfcp_adapter *adapter) |
| 1027 | { |
| 1028 | char dbf_name[20]; |
| 1029 | |
| 1030 | /* debug feature area which records SCSI command failures (hostbyte) */ |
| 1031 | spin_lock_init(&adapter->dbf_lock); |
| 1032 | |
| 1033 | sprintf(dbf_name, ZFCP_CMD_DBF_NAME "%s", |
| 1034 | zfcp_get_busid_by_adapter(adapter)); |
| 1035 | adapter->cmd_dbf = debug_register(dbf_name, ZFCP_CMD_DBF_INDEX, |
| 1036 | ZFCP_CMD_DBF_AREAS, |
| 1037 | ZFCP_CMD_DBF_LENGTH); |
| 1038 | debug_register_view(adapter->cmd_dbf, &debug_hex_ascii_view); |
| 1039 | debug_set_level(adapter->cmd_dbf, ZFCP_CMD_DBF_LEVEL); |
| 1040 | |
| 1041 | /* debug feature area which records SCSI command aborts */ |
| 1042 | sprintf(dbf_name, ZFCP_ABORT_DBF_NAME "%s", |
| 1043 | zfcp_get_busid_by_adapter(adapter)); |
| 1044 | adapter->abort_dbf = debug_register(dbf_name, ZFCP_ABORT_DBF_INDEX, |
| 1045 | ZFCP_ABORT_DBF_AREAS, |
| 1046 | ZFCP_ABORT_DBF_LENGTH); |
| 1047 | debug_register_view(adapter->abort_dbf, &debug_hex_ascii_view); |
| 1048 | debug_set_level(adapter->abort_dbf, ZFCP_ABORT_DBF_LEVEL); |
| 1049 | |
| 1050 | /* debug feature area which records incoming ELS commands */ |
| 1051 | sprintf(dbf_name, ZFCP_IN_ELS_DBF_NAME "%s", |
| 1052 | zfcp_get_busid_by_adapter(adapter)); |
| 1053 | adapter->in_els_dbf = debug_register(dbf_name, ZFCP_IN_ELS_DBF_INDEX, |
| 1054 | ZFCP_IN_ELS_DBF_AREAS, |
| 1055 | ZFCP_IN_ELS_DBF_LENGTH); |
| 1056 | debug_register_view(adapter->in_els_dbf, &debug_hex_ascii_view); |
| 1057 | debug_set_level(adapter->in_els_dbf, ZFCP_IN_ELS_DBF_LEVEL); |
| 1058 | |
| 1059 | /* debug feature area which records erp events */ |
| 1060 | sprintf(dbf_name, ZFCP_ERP_DBF_NAME "%s", |
| 1061 | zfcp_get_busid_by_adapter(adapter)); |
| 1062 | adapter->erp_dbf = debug_register(dbf_name, ZFCP_ERP_DBF_INDEX, |
| 1063 | ZFCP_ERP_DBF_AREAS, |
| 1064 | ZFCP_ERP_DBF_LENGTH); |
| 1065 | debug_register_view(adapter->erp_dbf, &debug_hex_ascii_view); |
| 1066 | debug_set_level(adapter->erp_dbf, ZFCP_ERP_DBF_LEVEL); |
| 1067 | |
| 1068 | if (!(adapter->cmd_dbf && adapter->abort_dbf && |
| 1069 | adapter->in_els_dbf && adapter->erp_dbf)) { |
| 1070 | zfcp_adapter_debug_unregister(adapter); |
| 1071 | return -ENOMEM; |
| 1072 | } |
| 1073 | |
| 1074 | return 0; |
| 1075 | |
| 1076 | } |
| 1077 | |
| 1078 | /** |
| 1079 | * zfcp_adapter_debug_unregister - unregisters debug feature for an adapter |
| 1080 | * @adapter: pointer to adapter for which debug features should be unregistered |
| 1081 | */ |
| 1082 | void |
| 1083 | zfcp_adapter_debug_unregister(struct zfcp_adapter *adapter) |
| 1084 | { |
| 1085 | debug_unregister(adapter->abort_dbf); |
| 1086 | debug_unregister(adapter->cmd_dbf); |
| 1087 | debug_unregister(adapter->erp_dbf); |
| 1088 | debug_unregister(adapter->in_els_dbf); |
| 1089 | adapter->abort_dbf = NULL; |
| 1090 | adapter->cmd_dbf = NULL; |
| 1091 | adapter->erp_dbf = NULL; |
| 1092 | adapter->in_els_dbf = NULL; |
| 1093 | } |
| 1094 | |
| 1095 | void |
| 1096 | zfcp_dummy_release(struct device *dev) |
| 1097 | { |
| 1098 | return; |
| 1099 | } |
| 1100 | |
| 1101 | /* |
| 1102 | * Enqueues an adapter at the end of the adapter list in the driver data. |
| 1103 | * All adapter internal structures are set up. |
| 1104 | * Proc-fs entries are also created. |
| 1105 | * |
| 1106 | * returns: 0 if a new adapter was successfully enqueued |
| 1107 | * ZFCP_KNOWN if an adapter with this devno was already present |
| 1108 | * -ENOMEM if alloc failed |
| 1109 | * locks: config_sema must be held to serialise changes to the adapter list |
| 1110 | */ |
| 1111 | struct zfcp_adapter * |
| 1112 | zfcp_adapter_enqueue(struct ccw_device *ccw_device) |
| 1113 | { |
| 1114 | int retval = 0; |
| 1115 | struct zfcp_adapter *adapter; |
| 1116 | |
| 1117 | /* |
| 1118 | * Note: It is safe to release the list_lock, as any list changes |
| 1119 | * are protected by the config_sema, which must be held to get here |
| 1120 | */ |
| 1121 | |
| 1122 | /* try to allocate new adapter data structure (zeroed) */ |
| 1123 | adapter = kmalloc(sizeof (struct zfcp_adapter), GFP_KERNEL); |
| 1124 | if (!adapter) { |
| 1125 | ZFCP_LOG_INFO("error: allocation of base adapter " |
| 1126 | "structure failed\n"); |
| 1127 | goto out; |
| 1128 | } |
| 1129 | memset(adapter, 0, sizeof (struct zfcp_adapter)); |
| 1130 | |
| 1131 | ccw_device->handler = NULL; |
| 1132 | |
| 1133 | /* save ccw_device pointer */ |
| 1134 | adapter->ccw_device = ccw_device; |
| 1135 | |
| 1136 | retval = zfcp_qdio_allocate_queues(adapter); |
| 1137 | if (retval) |
| 1138 | goto queues_alloc_failed; |
| 1139 | |
| 1140 | retval = zfcp_qdio_allocate(adapter); |
| 1141 | if (retval) |
| 1142 | goto qdio_allocate_failed; |
| 1143 | |
| 1144 | retval = zfcp_allocate_low_mem_buffers(adapter); |
| 1145 | if (retval) { |
| 1146 | ZFCP_LOG_INFO("error: pool allocation failed\n"); |
| 1147 | goto failed_low_mem_buffers; |
| 1148 | } |
| 1149 | |
| 1150 | /* initialise reference count stuff */ |
| 1151 | atomic_set(&adapter->refcount, 0); |
| 1152 | init_waitqueue_head(&adapter->remove_wq); |
| 1153 | |
| 1154 | /* initialise list of ports */ |
| 1155 | INIT_LIST_HEAD(&adapter->port_list_head); |
| 1156 | |
| 1157 | /* initialise list of ports to be removed */ |
| 1158 | INIT_LIST_HEAD(&adapter->port_remove_lh); |
| 1159 | |
| 1160 | /* initialize list of fsf requests */ |
Andreas Herrmann | 1db2c9c | 2005-06-13 13:20:35 +0200 | [diff] [blame] | 1161 | spin_lock_init(&adapter->fsf_req_list_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1162 | INIT_LIST_HEAD(&adapter->fsf_req_list_head); |
| 1163 | |
| 1164 | /* initialize abort lock */ |
| 1165 | rwlock_init(&adapter->abort_lock); |
| 1166 | |
| 1167 | /* initialise some erp stuff */ |
| 1168 | init_waitqueue_head(&adapter->erp_thread_wqh); |
| 1169 | init_waitqueue_head(&adapter->erp_done_wqh); |
| 1170 | |
| 1171 | /* initialize lock of associated request queue */ |
| 1172 | rwlock_init(&adapter->request_queue.queue_lock); |
| 1173 | |
| 1174 | /* intitialise SCSI ER timer */ |
| 1175 | init_timer(&adapter->scsi_er_timer); |
| 1176 | |
| 1177 | /* set FC service class used per default */ |
| 1178 | adapter->fc_service_class = ZFCP_FC_SERVICE_CLASS_DEFAULT; |
| 1179 | |
| 1180 | sprintf(adapter->name, "%s", zfcp_get_busid_by_adapter(adapter)); |
| 1181 | ASCEBC(adapter->name, strlen(adapter->name)); |
| 1182 | |
| 1183 | /* mark adapter unusable as long as sysfs registration is not complete */ |
| 1184 | atomic_set_mask(ZFCP_STATUS_COMMON_REMOVE, &adapter->status); |
| 1185 | |
| 1186 | adapter->ccw_device = ccw_device; |
| 1187 | dev_set_drvdata(&ccw_device->dev, adapter); |
| 1188 | |
| 1189 | if (zfcp_sysfs_adapter_create_files(&ccw_device->dev)) |
| 1190 | goto sysfs_failed; |
| 1191 | |
| 1192 | adapter->generic_services.parent = &adapter->ccw_device->dev; |
| 1193 | adapter->generic_services.release = zfcp_dummy_release; |
| 1194 | snprintf(adapter->generic_services.bus_id, BUS_ID_SIZE, |
| 1195 | "generic_services"); |
| 1196 | |
| 1197 | if (device_register(&adapter->generic_services)) |
| 1198 | goto generic_services_failed; |
| 1199 | |
| 1200 | /* put allocated adapter at list tail */ |
| 1201 | write_lock_irq(&zfcp_data.config_lock); |
| 1202 | atomic_clear_mask(ZFCP_STATUS_COMMON_REMOVE, &adapter->status); |
| 1203 | list_add_tail(&adapter->list, &zfcp_data.adapter_list_head); |
| 1204 | write_unlock_irq(&zfcp_data.config_lock); |
| 1205 | |
| 1206 | zfcp_data.adapters++; |
| 1207 | |
| 1208 | goto out; |
| 1209 | |
| 1210 | generic_services_failed: |
| 1211 | zfcp_sysfs_adapter_remove_files(&adapter->ccw_device->dev); |
| 1212 | sysfs_failed: |
| 1213 | dev_set_drvdata(&ccw_device->dev, NULL); |
| 1214 | failed_low_mem_buffers: |
| 1215 | zfcp_free_low_mem_buffers(adapter); |
| 1216 | if (qdio_free(ccw_device) != 0) |
| 1217 | ZFCP_LOG_NORMAL("bug: qdio_free for adapter %s failed\n", |
| 1218 | zfcp_get_busid_by_adapter(adapter)); |
| 1219 | qdio_allocate_failed: |
| 1220 | zfcp_qdio_free_queues(adapter); |
| 1221 | queues_alloc_failed: |
| 1222 | kfree(adapter); |
| 1223 | adapter = NULL; |
| 1224 | out: |
| 1225 | return adapter; |
| 1226 | } |
| 1227 | |
| 1228 | /* |
| 1229 | * returns: 0 - struct zfcp_adapter data structure successfully removed |
| 1230 | * !0 - struct zfcp_adapter data structure could not be removed |
| 1231 | * (e.g. still used) |
| 1232 | * locks: adapter list write lock is assumed to be held by caller |
| 1233 | * adapter->fsf_req_list_lock is taken and released within this |
| 1234 | * function and must not be held on entry |
| 1235 | */ |
| 1236 | void |
| 1237 | zfcp_adapter_dequeue(struct zfcp_adapter *adapter) |
| 1238 | { |
| 1239 | int retval = 0; |
| 1240 | unsigned long flags; |
| 1241 | |
| 1242 | device_unregister(&adapter->generic_services); |
| 1243 | zfcp_sysfs_adapter_remove_files(&adapter->ccw_device->dev); |
| 1244 | dev_set_drvdata(&adapter->ccw_device->dev, NULL); |
| 1245 | /* sanity check: no pending FSF requests */ |
Andreas Herrmann | 1db2c9c | 2005-06-13 13:20:35 +0200 | [diff] [blame] | 1246 | spin_lock_irqsave(&adapter->fsf_req_list_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1247 | retval = !list_empty(&adapter->fsf_req_list_head); |
Andreas Herrmann | 1db2c9c | 2005-06-13 13:20:35 +0200 | [diff] [blame] | 1248 | spin_unlock_irqrestore(&adapter->fsf_req_list_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1249 | if (retval) { |
| 1250 | ZFCP_LOG_NORMAL("bug: adapter %s (%p) still in use, " |
| 1251 | "%i requests outstanding\n", |
| 1252 | zfcp_get_busid_by_adapter(adapter), adapter, |
| 1253 | atomic_read(&adapter->fsf_reqs_active)); |
| 1254 | retval = -EBUSY; |
| 1255 | goto out; |
| 1256 | } |
| 1257 | |
| 1258 | /* remove specified adapter data structure from list */ |
| 1259 | write_lock_irq(&zfcp_data.config_lock); |
| 1260 | list_del(&adapter->list); |
| 1261 | write_unlock_irq(&zfcp_data.config_lock); |
| 1262 | |
| 1263 | /* decrease number of adapters in list */ |
| 1264 | zfcp_data.adapters--; |
| 1265 | |
| 1266 | ZFCP_LOG_TRACE("adapter %s (%p) removed from list, " |
| 1267 | "%i adapters still in list\n", |
| 1268 | zfcp_get_busid_by_adapter(adapter), |
| 1269 | adapter, zfcp_data.adapters); |
| 1270 | |
| 1271 | retval = qdio_free(adapter->ccw_device); |
| 1272 | if (retval) |
| 1273 | ZFCP_LOG_NORMAL("bug: qdio_free for adapter %s failed\n", |
| 1274 | zfcp_get_busid_by_adapter(adapter)); |
| 1275 | |
| 1276 | zfcp_free_low_mem_buffers(adapter); |
| 1277 | /* free memory of adapter data structure and queues */ |
| 1278 | zfcp_qdio_free_queues(adapter); |
| 1279 | ZFCP_LOG_TRACE("freeing adapter structure\n"); |
| 1280 | kfree(adapter); |
| 1281 | out: |
| 1282 | return; |
| 1283 | } |
| 1284 | |
| 1285 | /** |
| 1286 | * zfcp_port_enqueue - enqueue port to port list of adapter |
| 1287 | * @adapter: adapter where remote port is added |
| 1288 | * @wwpn: WWPN of the remote port to be enqueued |
| 1289 | * @status: initial status for the port |
| 1290 | * @d_id: destination id of the remote port to be enqueued |
| 1291 | * Return: pointer to enqueued port on success, NULL on error |
| 1292 | * Locks: config_sema must be held to serialize changes to the port list |
| 1293 | * |
| 1294 | * All port internal structures are set up and the sysfs entry is generated. |
| 1295 | * d_id is used to enqueue ports with a well known address like the Directory |
| 1296 | * Service for nameserver lookup. |
| 1297 | */ |
| 1298 | struct zfcp_port * |
| 1299 | zfcp_port_enqueue(struct zfcp_adapter *adapter, wwn_t wwpn, u32 status, |
| 1300 | u32 d_id) |
| 1301 | { |
Andreas Herrmann | 3859f6a | 2005-08-27 11:07:54 -0700 | [diff] [blame^] | 1302 | struct zfcp_port *port; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1303 | int check_wwpn; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1304 | |
| 1305 | check_wwpn = !(status & ZFCP_STATUS_PORT_NO_WWPN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1306 | /* |
| 1307 | * check that there is no port with this WWPN already in list |
| 1308 | */ |
| 1309 | if (check_wwpn) { |
| 1310 | read_lock_irq(&zfcp_data.config_lock); |
| 1311 | port = zfcp_get_port_by_wwpn(adapter, wwpn); |
| 1312 | read_unlock_irq(&zfcp_data.config_lock); |
| 1313 | if (port) |
| 1314 | return NULL; |
| 1315 | } |
| 1316 | |
| 1317 | port = kmalloc(sizeof (struct zfcp_port), GFP_KERNEL); |
| 1318 | if (!port) |
| 1319 | return NULL; |
| 1320 | memset(port, 0, sizeof (struct zfcp_port)); |
| 1321 | |
| 1322 | /* initialise reference count stuff */ |
| 1323 | atomic_set(&port->refcount, 0); |
| 1324 | init_waitqueue_head(&port->remove_wq); |
| 1325 | |
| 1326 | INIT_LIST_HEAD(&port->unit_list_head); |
| 1327 | INIT_LIST_HEAD(&port->unit_remove_lh); |
| 1328 | |
| 1329 | port->adapter = adapter; |
| 1330 | |
| 1331 | if (check_wwpn) |
| 1332 | port->wwpn = wwpn; |
| 1333 | |
| 1334 | atomic_set_mask(status, &port->status); |
| 1335 | |
| 1336 | /* setup for sysfs registration */ |
| 1337 | if (status & ZFCP_STATUS_PORT_WKA) { |
| 1338 | switch (d_id) { |
| 1339 | case ZFCP_DID_DIRECTORY_SERVICE: |
| 1340 | snprintf(port->sysfs_device.bus_id, BUS_ID_SIZE, |
| 1341 | "directory"); |
| 1342 | break; |
| 1343 | case ZFCP_DID_MANAGEMENT_SERVICE: |
| 1344 | snprintf(port->sysfs_device.bus_id, BUS_ID_SIZE, |
| 1345 | "management"); |
| 1346 | break; |
| 1347 | case ZFCP_DID_KEY_DISTRIBUTION_SERVICE: |
| 1348 | snprintf(port->sysfs_device.bus_id, BUS_ID_SIZE, |
| 1349 | "key_distribution"); |
| 1350 | break; |
| 1351 | case ZFCP_DID_ALIAS_SERVICE: |
| 1352 | snprintf(port->sysfs_device.bus_id, BUS_ID_SIZE, |
| 1353 | "alias"); |
| 1354 | break; |
| 1355 | case ZFCP_DID_TIME_SERVICE: |
| 1356 | snprintf(port->sysfs_device.bus_id, BUS_ID_SIZE, |
| 1357 | "time"); |
| 1358 | break; |
| 1359 | default: |
| 1360 | kfree(port); |
| 1361 | return NULL; |
| 1362 | } |
| 1363 | port->d_id = d_id; |
| 1364 | port->sysfs_device.parent = &adapter->generic_services; |
| 1365 | } else { |
| 1366 | snprintf(port->sysfs_device.bus_id, |
| 1367 | BUS_ID_SIZE, "0x%016llx", wwpn); |
Andreas Herrmann | 3859f6a | 2005-08-27 11:07:54 -0700 | [diff] [blame^] | 1368 | port->sysfs_device.parent = &adapter->ccw_device->dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1369 | } |
| 1370 | port->sysfs_device.release = zfcp_sysfs_port_release; |
| 1371 | dev_set_drvdata(&port->sysfs_device, port); |
| 1372 | |
| 1373 | /* mark port unusable as long as sysfs registration is not complete */ |
| 1374 | atomic_set_mask(ZFCP_STATUS_COMMON_REMOVE, &port->status); |
| 1375 | |
| 1376 | if (device_register(&port->sysfs_device)) { |
| 1377 | kfree(port); |
| 1378 | return NULL; |
| 1379 | } |
| 1380 | |
| 1381 | if (zfcp_sysfs_port_create_files(&port->sysfs_device, status)) { |
| 1382 | device_unregister(&port->sysfs_device); |
| 1383 | return NULL; |
| 1384 | } |
| 1385 | |
| 1386 | zfcp_port_get(port); |
| 1387 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1388 | write_lock_irq(&zfcp_data.config_lock); |
Andreas Herrmann | 3859f6a | 2005-08-27 11:07:54 -0700 | [diff] [blame^] | 1389 | list_add_tail(&port->list, &adapter->port_list_head); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1390 | atomic_clear_mask(ZFCP_STATUS_COMMON_REMOVE, &port->status); |
| 1391 | atomic_set_mask(ZFCP_STATUS_COMMON_RUNNING, &port->status); |
| 1392 | if (d_id == ZFCP_DID_DIRECTORY_SERVICE) |
| 1393 | if (!adapter->nameserver_port) |
| 1394 | adapter->nameserver_port = port; |
| 1395 | adapter->ports++; |
| 1396 | write_unlock_irq(&zfcp_data.config_lock); |
| 1397 | |
| 1398 | zfcp_adapter_get(adapter); |
| 1399 | |
| 1400 | return port; |
| 1401 | } |
| 1402 | |
| 1403 | void |
| 1404 | zfcp_port_dequeue(struct zfcp_port *port) |
| 1405 | { |
Andreas Herrmann | 3859f6a | 2005-08-27 11:07:54 -0700 | [diff] [blame^] | 1406 | struct fc_port *rport; |
| 1407 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1408 | zfcp_port_wait(port); |
| 1409 | write_lock_irq(&zfcp_data.config_lock); |
| 1410 | list_del(&port->list); |
| 1411 | port->adapter->ports--; |
| 1412 | write_unlock_irq(&zfcp_data.config_lock); |
Andreas Herrmann | 3859f6a | 2005-08-27 11:07:54 -0700 | [diff] [blame^] | 1413 | if (port->rport) |
| 1414 | fc_remote_port_delete(rport); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1415 | zfcp_adapter_put(port->adapter); |
| 1416 | zfcp_sysfs_port_remove_files(&port->sysfs_device, |
| 1417 | atomic_read(&port->status)); |
| 1418 | device_unregister(&port->sysfs_device); |
| 1419 | } |
| 1420 | |
| 1421 | /* Enqueues a nameserver port */ |
| 1422 | int |
| 1423 | zfcp_nameserver_enqueue(struct zfcp_adapter *adapter) |
| 1424 | { |
| 1425 | struct zfcp_port *port; |
| 1426 | |
| 1427 | port = zfcp_port_enqueue(adapter, 0, ZFCP_STATUS_PORT_WKA, |
| 1428 | ZFCP_DID_DIRECTORY_SERVICE); |
| 1429 | if (!port) { |
| 1430 | ZFCP_LOG_INFO("error: enqueue of nameserver port for " |
| 1431 | "adapter %s failed\n", |
| 1432 | zfcp_get_busid_by_adapter(adapter)); |
| 1433 | return -ENXIO; |
| 1434 | } |
| 1435 | zfcp_port_put(port); |
| 1436 | |
| 1437 | return 0; |
| 1438 | } |
| 1439 | |
| 1440 | #undef ZFCP_LOG_AREA |
| 1441 | |
| 1442 | /****************************************************************/ |
| 1443 | /******* Fibre Channel Standard related Functions **************/ |
| 1444 | /****************************************************************/ |
| 1445 | |
| 1446 | #define ZFCP_LOG_AREA ZFCP_LOG_AREA_FC |
| 1447 | |
| 1448 | void |
| 1449 | zfcp_fsf_incoming_els_rscn(struct zfcp_adapter *adapter, |
| 1450 | struct fsf_status_read_buffer *status_buffer) |
| 1451 | { |
| 1452 | struct fcp_rscn_head *fcp_rscn_head; |
| 1453 | struct fcp_rscn_element *fcp_rscn_element; |
| 1454 | struct zfcp_port *port; |
| 1455 | u16 i; |
| 1456 | u16 no_entries; |
| 1457 | u32 range_mask; |
| 1458 | unsigned long flags; |
| 1459 | |
| 1460 | fcp_rscn_head = (struct fcp_rscn_head *) status_buffer->payload; |
| 1461 | fcp_rscn_element = (struct fcp_rscn_element *) status_buffer->payload; |
| 1462 | |
| 1463 | /* see FC-FS */ |
| 1464 | no_entries = (fcp_rscn_head->payload_len / 4); |
| 1465 | |
| 1466 | zfcp_in_els_dbf_event(adapter, "##rscn", status_buffer, |
| 1467 | fcp_rscn_head->payload_len); |
| 1468 | |
| 1469 | debug_text_event(adapter->erp_dbf, 1, "unsol_els_rscn:"); |
| 1470 | for (i = 1; i < no_entries; i++) { |
| 1471 | /* skip head and start with 1st element */ |
| 1472 | fcp_rscn_element++; |
| 1473 | switch (fcp_rscn_element->addr_format) { |
| 1474 | case ZFCP_PORT_ADDRESS: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1475 | range_mask = ZFCP_PORTS_RANGE_PORT; |
| 1476 | break; |
| 1477 | case ZFCP_AREA_ADDRESS: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1478 | range_mask = ZFCP_PORTS_RANGE_AREA; |
| 1479 | break; |
| 1480 | case ZFCP_DOMAIN_ADDRESS: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1481 | range_mask = ZFCP_PORTS_RANGE_DOMAIN; |
| 1482 | break; |
| 1483 | case ZFCP_FABRIC_ADDRESS: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1484 | range_mask = ZFCP_PORTS_RANGE_FABRIC; |
| 1485 | break; |
| 1486 | default: |
| 1487 | ZFCP_LOG_INFO("incoming RSCN with unknown " |
| 1488 | "address format\n"); |
| 1489 | continue; |
| 1490 | } |
| 1491 | read_lock_irqsave(&zfcp_data.config_lock, flags); |
| 1492 | list_for_each_entry(port, &adapter->port_list_head, list) { |
| 1493 | if (atomic_test_mask |
| 1494 | (ZFCP_STATUS_PORT_WKA, &port->status)) |
| 1495 | continue; |
| 1496 | /* Do we know this port? If not skip it. */ |
| 1497 | if (!atomic_test_mask |
| 1498 | (ZFCP_STATUS_PORT_DID_DID, &port->status)) { |
| 1499 | ZFCP_LOG_INFO("incoming RSCN, trying to open " |
| 1500 | "port 0x%016Lx\n", port->wwpn); |
| 1501 | debug_text_event(adapter->erp_dbf, 1, |
| 1502 | "unsol_els_rscnu:"); |
| 1503 | zfcp_erp_port_reopen(port, |
| 1504 | ZFCP_STATUS_COMMON_ERP_FAILED); |
| 1505 | continue; |
| 1506 | } |
| 1507 | |
| 1508 | /* |
| 1509 | * FIXME: race: d_id might being invalidated |
| 1510 | * (...DID_DID reset) |
| 1511 | */ |
| 1512 | if ((port->d_id & range_mask) |
| 1513 | == (fcp_rscn_element->nport_did & range_mask)) { |
| 1514 | ZFCP_LOG_TRACE("reopen did 0x%08x\n", |
| 1515 | fcp_rscn_element->nport_did); |
| 1516 | /* |
| 1517 | * Unfortunately, an RSCN does not specify the |
| 1518 | * type of change a target underwent. We assume |
| 1519 | * that it makes sense to reopen the link. |
| 1520 | * FIXME: Shall we try to find out more about |
| 1521 | * the target and link state before closing it? |
| 1522 | * How to accomplish this? (nameserver?) |
| 1523 | * Where would such code be put in? |
| 1524 | * (inside or outside erp) |
| 1525 | */ |
| 1526 | ZFCP_LOG_INFO("incoming RSCN, trying to open " |
| 1527 | "port 0x%016Lx\n", port->wwpn); |
| 1528 | debug_text_event(adapter->erp_dbf, 1, |
| 1529 | "unsol_els_rscnk:"); |
| 1530 | zfcp_test_link(port); |
| 1531 | } |
| 1532 | } |
| 1533 | read_unlock_irqrestore(&zfcp_data.config_lock, flags); |
| 1534 | } |
| 1535 | } |
| 1536 | |
| 1537 | static void |
| 1538 | zfcp_fsf_incoming_els_plogi(struct zfcp_adapter *adapter, |
| 1539 | struct fsf_status_read_buffer *status_buffer) |
| 1540 | { |
| 1541 | logi *els_logi = (logi *) status_buffer->payload; |
| 1542 | struct zfcp_port *port; |
| 1543 | unsigned long flags; |
| 1544 | |
| 1545 | zfcp_in_els_dbf_event(adapter, "##plogi", status_buffer, 28); |
| 1546 | |
| 1547 | read_lock_irqsave(&zfcp_data.config_lock, flags); |
| 1548 | list_for_each_entry(port, &adapter->port_list_head, list) { |
| 1549 | if (port->wwpn == (*(wwn_t *) & els_logi->nport_wwn)) |
| 1550 | break; |
| 1551 | } |
| 1552 | read_unlock_irqrestore(&zfcp_data.config_lock, flags); |
| 1553 | |
| 1554 | if (!port || (port->wwpn != (*(wwn_t *) & els_logi->nport_wwn))) { |
| 1555 | ZFCP_LOG_DEBUG("ignored incoming PLOGI for nonexisting port " |
| 1556 | "with d_id 0x%08x on adapter %s\n", |
| 1557 | status_buffer->d_id, |
| 1558 | zfcp_get_busid_by_adapter(adapter)); |
| 1559 | } else { |
| 1560 | debug_text_event(adapter->erp_dbf, 1, "unsol_els_plogi:"); |
| 1561 | debug_event(adapter->erp_dbf, 1, &els_logi->nport_wwn, 8); |
| 1562 | zfcp_erp_port_forced_reopen(port, 0); |
| 1563 | } |
| 1564 | } |
| 1565 | |
| 1566 | static void |
| 1567 | zfcp_fsf_incoming_els_logo(struct zfcp_adapter *adapter, |
| 1568 | struct fsf_status_read_buffer *status_buffer) |
| 1569 | { |
| 1570 | struct fcp_logo *els_logo = (struct fcp_logo *) status_buffer->payload; |
| 1571 | struct zfcp_port *port; |
| 1572 | unsigned long flags; |
| 1573 | |
| 1574 | zfcp_in_els_dbf_event(adapter, "##logo", status_buffer, 16); |
| 1575 | |
| 1576 | read_lock_irqsave(&zfcp_data.config_lock, flags); |
| 1577 | list_for_each_entry(port, &adapter->port_list_head, list) { |
| 1578 | if (port->wwpn == els_logo->nport_wwpn) |
| 1579 | break; |
| 1580 | } |
| 1581 | read_unlock_irqrestore(&zfcp_data.config_lock, flags); |
| 1582 | |
| 1583 | if (!port || (port->wwpn != els_logo->nport_wwpn)) { |
| 1584 | ZFCP_LOG_DEBUG("ignored incoming LOGO for nonexisting port " |
| 1585 | "with d_id 0x%08x on adapter %s\n", |
| 1586 | status_buffer->d_id, |
| 1587 | zfcp_get_busid_by_adapter(adapter)); |
| 1588 | } else { |
| 1589 | debug_text_event(adapter->erp_dbf, 1, "unsol_els_logo:"); |
| 1590 | debug_event(adapter->erp_dbf, 1, &els_logo->nport_wwpn, 8); |
| 1591 | zfcp_erp_port_forced_reopen(port, 0); |
| 1592 | } |
| 1593 | } |
| 1594 | |
| 1595 | static void |
| 1596 | zfcp_fsf_incoming_els_unknown(struct zfcp_adapter *adapter, |
| 1597 | struct fsf_status_read_buffer *status_buffer) |
| 1598 | { |
| 1599 | zfcp_in_els_dbf_event(adapter, "##undef", status_buffer, 24); |
| 1600 | ZFCP_LOG_NORMAL("warning: unknown incoming ELS 0x%08x " |
| 1601 | "for adapter %s\n", *(u32 *) (status_buffer->payload), |
| 1602 | zfcp_get_busid_by_adapter(adapter)); |
| 1603 | |
| 1604 | } |
| 1605 | |
| 1606 | void |
| 1607 | zfcp_fsf_incoming_els(struct zfcp_fsf_req *fsf_req) |
| 1608 | { |
| 1609 | struct fsf_status_read_buffer *status_buffer; |
| 1610 | u32 els_type; |
| 1611 | struct zfcp_adapter *adapter; |
| 1612 | |
| 1613 | status_buffer = fsf_req->data.status_read.buffer; |
| 1614 | els_type = *(u32 *) (status_buffer->payload); |
| 1615 | adapter = fsf_req->adapter; |
| 1616 | |
| 1617 | if (els_type == LS_PLOGI) |
| 1618 | zfcp_fsf_incoming_els_plogi(adapter, status_buffer); |
| 1619 | else if (els_type == LS_LOGO) |
| 1620 | zfcp_fsf_incoming_els_logo(adapter, status_buffer); |
| 1621 | else if ((els_type & 0xffff0000) == LS_RSCN) |
| 1622 | /* we are only concerned with the command, not the length */ |
| 1623 | zfcp_fsf_incoming_els_rscn(adapter, status_buffer); |
| 1624 | else |
| 1625 | zfcp_fsf_incoming_els_unknown(adapter, status_buffer); |
| 1626 | } |
| 1627 | |
| 1628 | |
| 1629 | /** |
| 1630 | * zfcp_gid_pn_buffers_alloc - allocate buffers for GID_PN nameserver request |
| 1631 | * @gid_pn: pointer to return pointer to struct zfcp_gid_pn_data |
| 1632 | * @pool: pointer to mempool_t if non-null memory pool is used for allocation |
| 1633 | */ |
| 1634 | static int |
| 1635 | zfcp_gid_pn_buffers_alloc(struct zfcp_gid_pn_data **gid_pn, mempool_t *pool) |
| 1636 | { |
| 1637 | struct zfcp_gid_pn_data *data; |
| 1638 | |
| 1639 | if (pool != NULL) { |
| 1640 | data = mempool_alloc(pool, GFP_ATOMIC); |
| 1641 | if (likely(data != NULL)) { |
| 1642 | data->ct.pool = pool; |
| 1643 | } |
| 1644 | } else { |
| 1645 | data = kmalloc(sizeof(struct zfcp_gid_pn_data), GFP_ATOMIC); |
| 1646 | } |
| 1647 | |
| 1648 | if (NULL == data) |
| 1649 | return -ENOMEM; |
| 1650 | |
| 1651 | memset(data, 0, sizeof(*data)); |
| 1652 | data->ct.req = &data->req; |
| 1653 | data->ct.resp = &data->resp; |
| 1654 | data->ct.req_count = data->ct.resp_count = 1; |
| 1655 | zfcp_address_to_sg(&data->ct_iu_req, &data->req); |
| 1656 | zfcp_address_to_sg(&data->ct_iu_resp, &data->resp); |
| 1657 | data->req.length = sizeof(struct ct_iu_gid_pn_req); |
| 1658 | data->resp.length = sizeof(struct ct_iu_gid_pn_resp); |
| 1659 | |
| 1660 | *gid_pn = data; |
| 1661 | return 0; |
| 1662 | } |
| 1663 | |
| 1664 | /** |
| 1665 | * zfcp_gid_pn_buffers_free - free buffers for GID_PN nameserver request |
| 1666 | * @gid_pn: pointer to struct zfcp_gid_pn_data which has to be freed |
| 1667 | */ |
| 1668 | static void |
| 1669 | zfcp_gid_pn_buffers_free(struct zfcp_gid_pn_data *gid_pn) |
| 1670 | { |
| 1671 | if ((gid_pn->ct.pool != 0)) |
| 1672 | mempool_free(gid_pn, gid_pn->ct.pool); |
| 1673 | else |
| 1674 | kfree(gid_pn); |
| 1675 | |
| 1676 | return; |
| 1677 | } |
| 1678 | |
| 1679 | /** |
| 1680 | * zfcp_ns_gid_pn_request - initiate GID_PN nameserver request |
| 1681 | * @erp_action: pointer to zfcp_erp_action where GID_PN request is needed |
| 1682 | */ |
| 1683 | int |
| 1684 | zfcp_ns_gid_pn_request(struct zfcp_erp_action *erp_action) |
| 1685 | { |
| 1686 | int ret; |
| 1687 | struct ct_iu_gid_pn_req *ct_iu_req; |
| 1688 | struct zfcp_gid_pn_data *gid_pn; |
| 1689 | struct zfcp_adapter *adapter = erp_action->adapter; |
| 1690 | |
| 1691 | ret = zfcp_gid_pn_buffers_alloc(&gid_pn, adapter->pool.data_gid_pn); |
| 1692 | if (ret < 0) { |
| 1693 | ZFCP_LOG_INFO("error: buffer allocation for gid_pn nameserver " |
| 1694 | "request failed for adapter %s\n", |
| 1695 | zfcp_get_busid_by_adapter(adapter)); |
| 1696 | goto out; |
| 1697 | } |
| 1698 | |
| 1699 | /* setup nameserver request */ |
| 1700 | ct_iu_req = zfcp_sg_to_address(gid_pn->ct.req); |
| 1701 | ct_iu_req->header.revision = ZFCP_CT_REVISION; |
| 1702 | ct_iu_req->header.gs_type = ZFCP_CT_DIRECTORY_SERVICE; |
| 1703 | ct_iu_req->header.gs_subtype = ZFCP_CT_NAME_SERVER; |
| 1704 | ct_iu_req->header.options = ZFCP_CT_SYNCHRONOUS; |
| 1705 | ct_iu_req->header.cmd_rsp_code = ZFCP_CT_GID_PN; |
| 1706 | ct_iu_req->header.max_res_size = ZFCP_CT_MAX_SIZE; |
| 1707 | ct_iu_req->wwpn = erp_action->port->wwpn; |
| 1708 | |
| 1709 | /* setup parameters for send generic command */ |
| 1710 | gid_pn->ct.port = adapter->nameserver_port; |
| 1711 | gid_pn->ct.handler = zfcp_ns_gid_pn_handler; |
| 1712 | gid_pn->ct.handler_data = (unsigned long) gid_pn; |
| 1713 | gid_pn->ct.timeout = ZFCP_NS_GID_PN_TIMEOUT; |
| 1714 | gid_pn->ct.timer = &erp_action->timer; |
| 1715 | gid_pn->port = erp_action->port; |
| 1716 | |
| 1717 | ret = zfcp_fsf_send_ct(&gid_pn->ct, adapter->pool.fsf_req_erp, |
| 1718 | erp_action); |
| 1719 | if (ret) { |
| 1720 | ZFCP_LOG_INFO("error: initiation of gid_pn nameserver request " |
| 1721 | "failed for adapter %s\n", |
| 1722 | zfcp_get_busid_by_adapter(adapter)); |
| 1723 | |
| 1724 | zfcp_gid_pn_buffers_free(gid_pn); |
| 1725 | } |
| 1726 | |
| 1727 | out: |
| 1728 | return ret; |
| 1729 | } |
| 1730 | |
| 1731 | /** |
| 1732 | * zfcp_ns_gid_pn_handler - handler for GID_PN nameserver request |
| 1733 | * @data: unsigned long, contains pointer to struct zfcp_gid_pn_data |
| 1734 | */ |
| 1735 | static void zfcp_ns_gid_pn_handler(unsigned long data) |
| 1736 | { |
| 1737 | struct zfcp_port *port; |
| 1738 | struct zfcp_send_ct *ct; |
| 1739 | struct ct_iu_gid_pn_req *ct_iu_req; |
| 1740 | struct ct_iu_gid_pn_resp *ct_iu_resp; |
| 1741 | struct zfcp_gid_pn_data *gid_pn; |
| 1742 | |
| 1743 | |
| 1744 | gid_pn = (struct zfcp_gid_pn_data *) data; |
| 1745 | port = gid_pn->port; |
| 1746 | ct = &gid_pn->ct; |
| 1747 | ct_iu_req = zfcp_sg_to_address(ct->req); |
| 1748 | ct_iu_resp = zfcp_sg_to_address(ct->resp); |
| 1749 | |
Andreas Herrmann | 66c8684 | 2005-06-13 13:13:45 +0200 | [diff] [blame] | 1750 | if (ct->status != 0) |
| 1751 | goto failed; |
| 1752 | |
| 1753 | if (zfcp_check_ct_response(&ct_iu_resp->header)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1754 | /* FIXME: do we need some specific erp entry points */ |
| 1755 | atomic_set_mask(ZFCP_STATUS_PORT_INVALID_WWPN, &port->status); |
| 1756 | goto failed; |
| 1757 | } |
| 1758 | /* paranoia */ |
| 1759 | if (ct_iu_req->wwpn != port->wwpn) { |
| 1760 | ZFCP_LOG_NORMAL("bug: wwpn 0x%016Lx returned by nameserver " |
| 1761 | "lookup does not match expected wwpn 0x%016Lx " |
| 1762 | "for adapter %s\n", ct_iu_req->wwpn, port->wwpn, |
| 1763 | zfcp_get_busid_by_port(port)); |
| 1764 | goto mismatch; |
| 1765 | } |
| 1766 | |
| 1767 | /* looks like a valid d_id */ |
| 1768 | port->d_id = ct_iu_resp->d_id & ZFCP_DID_MASK; |
| 1769 | atomic_set_mask(ZFCP_STATUS_PORT_DID_DID, &port->status); |
| 1770 | ZFCP_LOG_DEBUG("adapter %s: wwpn=0x%016Lx ---> d_id=0x%08x\n", |
| 1771 | zfcp_get_busid_by_port(port), port->wwpn, port->d_id); |
| 1772 | goto out; |
| 1773 | |
| 1774 | mismatch: |
| 1775 | ZFCP_LOG_DEBUG("CT IUs do not match:\n"); |
| 1776 | ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG, (char *) ct_iu_req, |
| 1777 | sizeof(struct ct_iu_gid_pn_req)); |
| 1778 | ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG, (char *) ct_iu_resp, |
| 1779 | sizeof(struct ct_iu_gid_pn_resp)); |
| 1780 | |
| 1781 | failed: |
| 1782 | ZFCP_LOG_NORMAL("warning: failed gid_pn nameserver request for wwpn " |
| 1783 | "0x%016Lx for adapter %s\n", |
| 1784 | port->wwpn, zfcp_get_busid_by_port(port)); |
| 1785 | out: |
| 1786 | zfcp_gid_pn_buffers_free(gid_pn); |
| 1787 | return; |
| 1788 | } |
| 1789 | |
| 1790 | /* reject CT_IU reason codes acc. to FC-GS-4 */ |
| 1791 | static const struct zfcp_rc_entry zfcp_ct_rc[] = { |
| 1792 | {0x01, "invalid command code"}, |
| 1793 | {0x02, "invalid version level"}, |
| 1794 | {0x03, "logical error"}, |
| 1795 | {0x04, "invalid CT_IU size"}, |
| 1796 | {0x05, "logical busy"}, |
| 1797 | {0x07, "protocol error"}, |
| 1798 | {0x09, "unable to perform command request"}, |
| 1799 | {0x0b, "command not supported"}, |
| 1800 | {0x0d, "server not available"}, |
| 1801 | {0x0e, "session could not be established"}, |
| 1802 | {0xff, "vendor specific error"}, |
| 1803 | {0, NULL}, |
| 1804 | }; |
| 1805 | |
| 1806 | /* LS_RJT reason codes acc. to FC-FS */ |
| 1807 | static const struct zfcp_rc_entry zfcp_ls_rjt_rc[] = { |
| 1808 | {0x01, "invalid LS_Command code"}, |
| 1809 | {0x03, "logical error"}, |
| 1810 | {0x05, "logical busy"}, |
| 1811 | {0x07, "protocol error"}, |
| 1812 | {0x09, "unable to perform command request"}, |
| 1813 | {0x0b, "command not supported"}, |
| 1814 | {0x0e, "command already in progress"}, |
| 1815 | {0xff, "vendor specific error"}, |
| 1816 | {0, NULL}, |
| 1817 | }; |
| 1818 | |
| 1819 | /* reject reason codes according to FC-PH/FC-FS */ |
| 1820 | static const struct zfcp_rc_entry zfcp_p_rjt_rc[] = { |
| 1821 | {0x01, "invalid D_ID"}, |
| 1822 | {0x02, "invalid S_ID"}, |
| 1823 | {0x03, "Nx_Port not available, temporary"}, |
| 1824 | {0x04, "Nx_Port not available, permament"}, |
| 1825 | {0x05, "class not supported"}, |
| 1826 | {0x06, "delimiter usage error"}, |
| 1827 | {0x07, "TYPE not supported"}, |
| 1828 | {0x08, "invalid Link_Control"}, |
| 1829 | {0x09, "invalid R_CTL field"}, |
| 1830 | {0x0a, "invalid F_CTL field"}, |
| 1831 | {0x0b, "invalid OX_ID"}, |
| 1832 | {0x0c, "invalid RX_ID"}, |
| 1833 | {0x0d, "invalid SEQ_ID"}, |
| 1834 | {0x0e, "invalid DF_CTL"}, |
| 1835 | {0x0f, "invalid SEQ_CNT"}, |
| 1836 | {0x10, "invalid parameter field"}, |
| 1837 | {0x11, "exchange error"}, |
| 1838 | {0x12, "protocol error"}, |
| 1839 | {0x13, "incorrect length"}, |
| 1840 | {0x14, "unsupported ACK"}, |
| 1841 | {0x15, "class of service not supported by entity at FFFFFE"}, |
| 1842 | {0x16, "login required"}, |
| 1843 | {0x17, "excessive sequences attempted"}, |
| 1844 | {0x18, "unable to establish exchange"}, |
| 1845 | {0x1a, "fabric path not available"}, |
| 1846 | {0x1b, "invalid VC_ID (class 4)"}, |
| 1847 | {0x1c, "invalid CS_CTL field"}, |
| 1848 | {0x1d, "insufficient resources for VC (class 4)"}, |
| 1849 | {0x1f, "invalid class of service"}, |
| 1850 | {0x20, "preemption request rejected"}, |
| 1851 | {0x21, "preemption not enabled"}, |
| 1852 | {0x22, "multicast error"}, |
| 1853 | {0x23, "multicast error terminate"}, |
| 1854 | {0x24, "process login required"}, |
| 1855 | {0xff, "vendor specific reject"}, |
| 1856 | {0, NULL}, |
| 1857 | }; |
| 1858 | |
| 1859 | /** |
| 1860 | * zfcp_rc_description - return description for given reaon code |
| 1861 | * @code: reason code |
| 1862 | * @rc_table: table of reason codes and descriptions |
| 1863 | */ |
| 1864 | static inline const char * |
| 1865 | zfcp_rc_description(u8 code, const struct zfcp_rc_entry *rc_table) |
| 1866 | { |
| 1867 | const char *descr = "unknown reason code"; |
| 1868 | |
| 1869 | do { |
| 1870 | if (code == rc_table->code) { |
| 1871 | descr = rc_table->description; |
| 1872 | break; |
| 1873 | } |
| 1874 | rc_table++; |
| 1875 | } while (rc_table->code && rc_table->description); |
| 1876 | |
| 1877 | return descr; |
| 1878 | } |
| 1879 | |
| 1880 | /** |
| 1881 | * zfcp_check_ct_response - evaluate reason code for CT_IU |
| 1882 | * @rjt: response payload to an CT_IU request |
| 1883 | * Return: 0 for accept CT_IU, 1 for reject CT_IU or invlid response code |
| 1884 | */ |
| 1885 | int |
| 1886 | zfcp_check_ct_response(struct ct_hdr *rjt) |
| 1887 | { |
| 1888 | if (rjt->cmd_rsp_code == ZFCP_CT_ACCEPT) |
| 1889 | return 0; |
| 1890 | |
| 1891 | if (rjt->cmd_rsp_code != ZFCP_CT_REJECT) { |
| 1892 | ZFCP_LOG_NORMAL("error: invalid Generic Service command/" |
| 1893 | "response code (0x%04hx)\n", |
| 1894 | rjt->cmd_rsp_code); |
| 1895 | return 1; |
| 1896 | } |
| 1897 | |
| 1898 | ZFCP_LOG_INFO("Generic Service command rejected\n"); |
| 1899 | ZFCP_LOG_INFO("%s (0x%02x, 0x%02x, 0x%02x)\n", |
| 1900 | zfcp_rc_description(rjt->reason_code, zfcp_ct_rc), |
| 1901 | (u32) rjt->reason_code, (u32) rjt->reason_code_expl, |
| 1902 | (u32) rjt->vendor_unique); |
| 1903 | |
| 1904 | return 1; |
| 1905 | } |
| 1906 | |
| 1907 | /** |
| 1908 | * zfcp_print_els_rjt - print reject parameter and description for ELS reject |
| 1909 | * @rjt_par: reject parameter acc. to FC-PH/FC-FS |
| 1910 | * @rc_table: table of reason codes and descriptions |
| 1911 | */ |
| 1912 | static inline void |
| 1913 | zfcp_print_els_rjt(struct zfcp_ls_rjt_par *rjt_par, |
| 1914 | const struct zfcp_rc_entry *rc_table) |
| 1915 | { |
| 1916 | ZFCP_LOG_INFO("%s (%02x %02x %02x %02x)\n", |
| 1917 | zfcp_rc_description(rjt_par->reason_code, rc_table), |
| 1918 | (u32) rjt_par->action, (u32) rjt_par->reason_code, |
| 1919 | (u32) rjt_par->reason_expl, (u32) rjt_par->vendor_unique); |
| 1920 | } |
| 1921 | |
| 1922 | /** |
| 1923 | * zfcp_fsf_handle_els_rjt - evaluate status qualifier/reason code on ELS reject |
| 1924 | * @sq: status qualifier word |
| 1925 | * @rjt_par: reject parameter as described in FC-PH and FC-FS |
| 1926 | * Return: -EROMTEIO for LS_RJT, -EREMCHG for invalid D_ID, -EIO else |
| 1927 | */ |
| 1928 | int |
| 1929 | zfcp_handle_els_rjt(u32 sq, struct zfcp_ls_rjt_par *rjt_par) |
| 1930 | { |
| 1931 | int ret = -EIO; |
| 1932 | |
| 1933 | if (sq == FSF_IOSTAT_NPORT_RJT) { |
| 1934 | ZFCP_LOG_INFO("ELS rejected (P_RJT)\n"); |
| 1935 | zfcp_print_els_rjt(rjt_par, zfcp_p_rjt_rc); |
| 1936 | /* invalid d_id */ |
| 1937 | if (rjt_par->reason_code == 0x01) |
| 1938 | ret = -EREMCHG; |
| 1939 | } else if (sq == FSF_IOSTAT_FABRIC_RJT) { |
| 1940 | ZFCP_LOG_INFO("ELS rejected (F_RJT)\n"); |
| 1941 | zfcp_print_els_rjt(rjt_par, zfcp_p_rjt_rc); |
| 1942 | /* invalid d_id */ |
| 1943 | if (rjt_par->reason_code == 0x01) |
| 1944 | ret = -EREMCHG; |
| 1945 | } else if (sq == FSF_IOSTAT_LS_RJT) { |
| 1946 | ZFCP_LOG_INFO("ELS rejected (LS_RJT)\n"); |
| 1947 | zfcp_print_els_rjt(rjt_par, zfcp_ls_rjt_rc); |
| 1948 | ret = -EREMOTEIO; |
| 1949 | } else |
| 1950 | ZFCP_LOG_INFO("unexpected SQ: 0x%02x\n", sq); |
| 1951 | |
| 1952 | return ret; |
| 1953 | } |
| 1954 | |
| 1955 | #undef ZFCP_LOG_AREA |