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