Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Christof Schmitt | 553448f | 2008-06-10 18:20:58 +0200 | [diff] [blame] | 2 | * zfcp device driver |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | * |
Christof Schmitt | 553448f | 2008-06-10 18:20:58 +0200 | [diff] [blame] | 4 | * Module interface and handling of zfcp data structures. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | * |
Christof Schmitt | a2fa0ae | 2009-03-02 13:09:08 +0100 | [diff] [blame] | 6 | * Copyright IBM Corporation 2002, 2009 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | */ |
| 8 | |
Andreas Herrmann | 4a9d2d8 | 2006-05-22 18:14:08 +0200 | [diff] [blame] | 9 | /* |
| 10 | * Driver authors: |
| 11 | * Martin Peschke (originator of the driver) |
| 12 | * Raimund Schroeder |
| 13 | * Aron Zeh |
| 14 | * Wolfgang Taphorn |
| 15 | * Stefan Bader |
| 16 | * Heiko Carstens (kernel 2.6 port of the driver) |
| 17 | * Andreas Herrmann |
| 18 | * Maxim Shchetynin |
| 19 | * Volker Sameske |
| 20 | * Ralph Wuerthner |
Christof Schmitt | 553448f | 2008-06-10 18:20:58 +0200 | [diff] [blame] | 21 | * Michael Loehr |
| 22 | * Swen Schillig |
| 23 | * Christof Schmitt |
| 24 | * Martin Petermann |
| 25 | * Sven Schuetz |
Andreas Herrmann | 4a9d2d8 | 2006-05-22 18:14:08 +0200 | [diff] [blame] | 26 | */ |
| 27 | |
Christof Schmitt | ecf39d4 | 2008-12-25 13:39:53 +0100 | [diff] [blame] | 28 | #define KMSG_COMPONENT "zfcp" |
| 29 | #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt |
| 30 | |
Christof Schmitt | 45633fd | 2008-06-10 18:20:55 +0200 | [diff] [blame] | 31 | #include <linux/miscdevice.h> |
Christof Schmitt | bd43a42b7 | 2008-12-25 13:38:50 +0100 | [diff] [blame] | 32 | #include <linux/seq_file.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | #include "zfcp_ext.h" |
| 34 | |
Kay Sievers | 98df67b | 2008-12-25 13:38:55 +0100 | [diff] [blame] | 35 | #define ZFCP_BUS_ID_SIZE 20 |
| 36 | |
Andreas Herrmann | 4a9d2d8 | 2006-05-22 18:14:08 +0200 | [diff] [blame] | 37 | MODULE_AUTHOR("IBM Deutschland Entwicklung GmbH - linux390@de.ibm.com"); |
Swen Schillig | 317e6b6 | 2008-07-02 10:56:37 +0200 | [diff] [blame] | 38 | MODULE_DESCRIPTION("FCP HBA driver"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | MODULE_LICENSE("GPL"); |
| 40 | |
Christof Schmitt | 3623ecb | 2008-12-19 16:56:57 +0100 | [diff] [blame] | 41 | static char *init_device; |
| 42 | module_param_named(device, init_device, charp, 0400); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | MODULE_PARM_DESC(device, "specify initial device"); |
| 44 | |
Swen Schillig | a4623c4 | 2009-08-18 15:43:15 +0200 | [diff] [blame] | 45 | static struct kmem_cache *zfcp_cache_hw_align(const char *name, |
| 46 | unsigned long size) |
| 47 | { |
| 48 | return kmem_cache_create(name, size, roundup_pow_of_two(size), 0, NULL); |
| 49 | } |
| 50 | |
Heiko Carstens | ca2d02c | 2007-05-08 11:17:54 +0200 | [diff] [blame] | 51 | static int zfcp_reqlist_alloc(struct zfcp_adapter *adapter) |
Volker Sameske | fea9d6c | 2006-08-02 11:05:16 +0200 | [diff] [blame] | 52 | { |
Heiko Carstens | ca2d02c | 2007-05-08 11:17:54 +0200 | [diff] [blame] | 53 | int idx; |
Volker Sameske | fea9d6c | 2006-08-02 11:05:16 +0200 | [diff] [blame] | 54 | |
| 55 | adapter->req_list = kcalloc(REQUEST_LIST_SIZE, sizeof(struct list_head), |
| 56 | GFP_KERNEL); |
Volker Sameske | fea9d6c | 2006-08-02 11:05:16 +0200 | [diff] [blame] | 57 | if (!adapter->req_list) |
| 58 | return -ENOMEM; |
| 59 | |
Heiko Carstens | ca2d02c | 2007-05-08 11:17:54 +0200 | [diff] [blame] | 60 | for (idx = 0; idx < REQUEST_LIST_SIZE; idx++) |
| 61 | INIT_LIST_HEAD(&adapter->req_list[idx]); |
Volker Sameske | fea9d6c | 2006-08-02 11:05:16 +0200 | [diff] [blame] | 62 | return 0; |
| 63 | } |
| 64 | |
Swen Schillig | 317e6b6 | 2008-07-02 10:56:37 +0200 | [diff] [blame] | 65 | /** |
| 66 | * zfcp_reqlist_isempty - is the request list empty |
| 67 | * @adapter: pointer to struct zfcp_adapter |
| 68 | * |
| 69 | * Returns: true if list is empty, false otherwise |
| 70 | */ |
Volker Sameske | fea9d6c | 2006-08-02 11:05:16 +0200 | [diff] [blame] | 71 | int zfcp_reqlist_isempty(struct zfcp_adapter *adapter) |
| 72 | { |
Heiko Carstens | ca2d02c | 2007-05-08 11:17:54 +0200 | [diff] [blame] | 73 | unsigned int idx; |
Volker Sameske | fea9d6c | 2006-08-02 11:05:16 +0200 | [diff] [blame] | 74 | |
Heiko Carstens | ca2d02c | 2007-05-08 11:17:54 +0200 | [diff] [blame] | 75 | for (idx = 0; idx < REQUEST_LIST_SIZE; idx++) |
| 76 | if (!list_empty(&adapter->req_list[idx])) |
Volker Sameske | fea9d6c | 2006-08-02 11:05:16 +0200 | [diff] [blame] | 77 | return 0; |
Volker Sameske | fea9d6c | 2006-08-02 11:05:16 +0200 | [diff] [blame] | 78 | return 1; |
| 79 | } |
| 80 | |
Christof Schmitt | 3623ecb | 2008-12-19 16:56:57 +0100 | [diff] [blame] | 81 | static void __init zfcp_init_device_configure(char *busid, u64 wwpn, u64 lun) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | { |
| 83 | struct zfcp_adapter *adapter; |
| 84 | struct zfcp_port *port; |
| 85 | struct zfcp_unit *unit; |
| 86 | |
| 87 | down(&zfcp_data.config_sema); |
| 88 | read_lock_irq(&zfcp_data.config_lock); |
Christof Schmitt | 3623ecb | 2008-12-19 16:56:57 +0100 | [diff] [blame] | 89 | adapter = zfcp_get_adapter_by_busid(busid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | if (adapter) |
| 91 | zfcp_adapter_get(adapter); |
| 92 | read_unlock_irq(&zfcp_data.config_lock); |
| 93 | |
Swen Schillig | 317e6b6 | 2008-07-02 10:56:37 +0200 | [diff] [blame] | 94 | if (!adapter) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | goto out_adapter; |
Christof Schmitt | 3623ecb | 2008-12-19 16:56:57 +0100 | [diff] [blame] | 96 | port = zfcp_port_enqueue(adapter, wwpn, 0, 0); |
Swen Schillig | 317e6b6 | 2008-07-02 10:56:37 +0200 | [diff] [blame] | 97 | if (IS_ERR(port)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | goto out_port; |
Christof Schmitt | 3623ecb | 2008-12-19 16:56:57 +0100 | [diff] [blame] | 99 | unit = zfcp_unit_enqueue(port, lun); |
Swen Schillig | 317e6b6 | 2008-07-02 10:56:37 +0200 | [diff] [blame] | 100 | if (IS_ERR(unit)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | goto out_unit; |
| 102 | up(&zfcp_data.config_sema); |
| 103 | ccw_device_set_online(adapter->ccw_device); |
Swen Schillig | 091694a | 2008-10-01 12:42:25 +0200 | [diff] [blame] | 104 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | zfcp_erp_wait(adapter); |
Swen Schillig | 92d5193 | 2009-04-17 15:08:04 +0200 | [diff] [blame] | 106 | flush_work(&unit->scsi_work); |
Swen Schillig | 091694a | 2008-10-01 12:42:25 +0200 | [diff] [blame] | 107 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | down(&zfcp_data.config_sema); |
| 109 | zfcp_unit_put(unit); |
Swen Schillig | 317e6b6 | 2008-07-02 10:56:37 +0200 | [diff] [blame] | 110 | out_unit: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | zfcp_port_put(port); |
Swen Schillig | 317e6b6 | 2008-07-02 10:56:37 +0200 | [diff] [blame] | 112 | out_port: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | zfcp_adapter_put(adapter); |
Swen Schillig | 317e6b6 | 2008-07-02 10:56:37 +0200 | [diff] [blame] | 114 | out_adapter: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | up(&zfcp_data.config_sema); |
| 116 | return; |
| 117 | } |
| 118 | |
Christof Schmitt | 3623ecb | 2008-12-19 16:56:57 +0100 | [diff] [blame] | 119 | static void __init zfcp_init_device_setup(char *devstr) |
| 120 | { |
| 121 | char *token; |
| 122 | char *str; |
| 123 | char busid[ZFCP_BUS_ID_SIZE]; |
| 124 | u64 wwpn, lun; |
| 125 | |
| 126 | /* duplicate devstr and keep the original for sysfs presentation*/ |
| 127 | str = kmalloc(strlen(devstr) + 1, GFP_KERNEL); |
| 128 | if (!str) |
| 129 | return; |
| 130 | |
| 131 | strcpy(str, devstr); |
| 132 | |
| 133 | token = strsep(&str, ","); |
| 134 | if (!token || strlen(token) >= ZFCP_BUS_ID_SIZE) |
| 135 | goto err_out; |
| 136 | strncpy(busid, token, ZFCP_BUS_ID_SIZE); |
| 137 | |
| 138 | token = strsep(&str, ","); |
| 139 | if (!token || strict_strtoull(token, 0, (unsigned long long *) &wwpn)) |
| 140 | goto err_out; |
| 141 | |
| 142 | token = strsep(&str, ","); |
| 143 | if (!token || strict_strtoull(token, 0, (unsigned long long *) &lun)) |
| 144 | goto err_out; |
| 145 | |
| 146 | kfree(str); |
| 147 | zfcp_init_device_configure(busid, wwpn, lun); |
| 148 | return; |
| 149 | |
| 150 | err_out: |
| 151 | kfree(str); |
| 152 | pr_err("%s is not a valid SCSI device\n", devstr); |
| 153 | } |
| 154 | |
Swen Schillig | 317e6b6 | 2008-07-02 10:56:37 +0200 | [diff] [blame] | 155 | static int __init zfcp_module_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | { |
Heiko Carstens | dd52e0e | 2006-09-18 22:28:49 +0200 | [diff] [blame] | 157 | int retval = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 158 | |
Swen Schillig | a4623c4 | 2009-08-18 15:43:15 +0200 | [diff] [blame] | 159 | zfcp_data.gpn_ft_cache = zfcp_cache_hw_align("zfcp_gpn", |
| 160 | sizeof(struct ct_iu_gpn_ft_req)); |
| 161 | if (!zfcp_data.gpn_ft_cache) |
Heiko Carstens | dd52e0e | 2006-09-18 22:28:49 +0200 | [diff] [blame] | 162 | goto out; |
| 163 | |
Swen Schillig | a4623c4 | 2009-08-18 15:43:15 +0200 | [diff] [blame] | 164 | zfcp_data.qtcb_cache = zfcp_cache_hw_align("zfcp_qtcb", |
| 165 | sizeof(struct fsf_qtcb)); |
| 166 | if (!zfcp_data.qtcb_cache) |
| 167 | goto out_qtcb_cache; |
| 168 | |
| 169 | zfcp_data.sr_buffer_cache = zfcp_cache_hw_align("zfcp_sr", |
| 170 | sizeof(struct fsf_status_read_buffer)); |
Heiko Carstens | dd52e0e | 2006-09-18 22:28:49 +0200 | [diff] [blame] | 171 | if (!zfcp_data.sr_buffer_cache) |
| 172 | goto out_sr_cache; |
| 173 | |
Swen Schillig | a4623c4 | 2009-08-18 15:43:15 +0200 | [diff] [blame] | 174 | zfcp_data.gid_pn_cache = zfcp_cache_hw_align("zfcp_gid", |
| 175 | sizeof(struct zfcp_gid_pn_data)); |
Heiko Carstens | dd52e0e | 2006-09-18 22:28:49 +0200 | [diff] [blame] | 176 | if (!zfcp_data.gid_pn_cache) |
| 177 | goto out_gid_cache; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 | |
Swen Schillig | 317e6b6 | 2008-07-02 10:56:37 +0200 | [diff] [blame] | 179 | sema_init(&zfcp_data.config_sema, 1); |
| 180 | rwlock_init(&zfcp_data.config_lock); |
| 181 | |
Heiko Carstens | dd52e0e | 2006-09-18 22:28:49 +0200 | [diff] [blame] | 182 | zfcp_data.scsi_transport_template = |
| 183 | fc_attach_transport(&zfcp_transport_functions); |
| 184 | if (!zfcp_data.scsi_transport_template) |
| 185 | goto out_transport; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 186 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | retval = misc_register(&zfcp_cfdc_misc); |
Swen Schillig | 317e6b6 | 2008-07-02 10:56:37 +0200 | [diff] [blame] | 188 | if (retval) { |
Christof Schmitt | ecf39d4 | 2008-12-25 13:39:53 +0100 | [diff] [blame] | 189 | pr_err("Registering the misc device zfcp_cfdc failed\n"); |
Heiko Carstens | dd52e0e | 2006-09-18 22:28:49 +0200 | [diff] [blame] | 190 | goto out_misc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 191 | } |
| 192 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 193 | retval = zfcp_ccw_register(); |
| 194 | if (retval) { |
Christof Schmitt | ecf39d4 | 2008-12-25 13:39:53 +0100 | [diff] [blame] | 195 | pr_err("The zfcp device driver could not register with " |
Christof Schmitt | ff3b24f | 2008-10-01 12:42:15 +0200 | [diff] [blame] | 196 | "the common I/O layer\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | goto out_ccw_register; |
| 198 | } |
| 199 | |
Christof Schmitt | 3623ecb | 2008-12-19 16:56:57 +0100 | [diff] [blame] | 200 | if (init_device) |
| 201 | zfcp_init_device_setup(init_device); |
| 202 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | |
Swen Schillig | 317e6b6 | 2008-07-02 10:56:37 +0200 | [diff] [blame] | 204 | out_ccw_register: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | misc_deregister(&zfcp_cfdc_misc); |
Swen Schillig | 317e6b6 | 2008-07-02 10:56:37 +0200 | [diff] [blame] | 206 | out_misc: |
Heiko Carstens | dd52e0e | 2006-09-18 22:28:49 +0200 | [diff] [blame] | 207 | fc_release_transport(zfcp_data.scsi_transport_template); |
Swen Schillig | 317e6b6 | 2008-07-02 10:56:37 +0200 | [diff] [blame] | 208 | out_transport: |
Heiko Carstens | dd52e0e | 2006-09-18 22:28:49 +0200 | [diff] [blame] | 209 | kmem_cache_destroy(zfcp_data.gid_pn_cache); |
Swen Schillig | 317e6b6 | 2008-07-02 10:56:37 +0200 | [diff] [blame] | 210 | out_gid_cache: |
Heiko Carstens | dd52e0e | 2006-09-18 22:28:49 +0200 | [diff] [blame] | 211 | kmem_cache_destroy(zfcp_data.sr_buffer_cache); |
Swen Schillig | 317e6b6 | 2008-07-02 10:56:37 +0200 | [diff] [blame] | 212 | out_sr_cache: |
Swen Schillig | a4623c4 | 2009-08-18 15:43:15 +0200 | [diff] [blame] | 213 | kmem_cache_destroy(zfcp_data.qtcb_cache); |
| 214 | out_qtcb_cache: |
| 215 | kmem_cache_destroy(zfcp_data.gpn_ft_cache); |
Swen Schillig | 317e6b6 | 2008-07-02 10:56:37 +0200 | [diff] [blame] | 216 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 217 | return retval; |
| 218 | } |
| 219 | |
Swen Schillig | 317e6b6 | 2008-07-02 10:56:37 +0200 | [diff] [blame] | 220 | module_init(zfcp_module_init); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 221 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 222 | /** |
| 223 | * zfcp_get_unit_by_lun - find unit in unit list of port by FCP LUN |
| 224 | * @port: pointer to port to search for unit |
| 225 | * @fcp_lun: FCP LUN to search for |
Swen Schillig | 317e6b6 | 2008-07-02 10:56:37 +0200 | [diff] [blame] | 226 | * |
| 227 | * Returns: pointer to zfcp_unit or NULL |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 228 | */ |
Swen Schillig | 7ba58c9 | 2008-10-01 12:42:18 +0200 | [diff] [blame] | 229 | struct zfcp_unit *zfcp_get_unit_by_lun(struct zfcp_port *port, u64 fcp_lun) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 230 | { |
| 231 | struct zfcp_unit *unit; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 232 | |
Swen Schillig | 317e6b6 | 2008-07-02 10:56:37 +0200 | [diff] [blame] | 233 | list_for_each_entry(unit, &port->unit_list_head, list) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 234 | if ((unit->fcp_lun == fcp_lun) && |
Swen Schillig | 317e6b6 | 2008-07-02 10:56:37 +0200 | [diff] [blame] | 235 | !(atomic_read(&unit->status) & ZFCP_STATUS_COMMON_REMOVE)) |
| 236 | return unit; |
| 237 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 238 | } |
| 239 | |
| 240 | /** |
| 241 | * zfcp_get_port_by_wwpn - find port in port list of adapter by wwpn |
| 242 | * @adapter: pointer to adapter to search for port |
| 243 | * @wwpn: wwpn to search for |
Swen Schillig | 317e6b6 | 2008-07-02 10:56:37 +0200 | [diff] [blame] | 244 | * |
| 245 | * Returns: pointer to zfcp_port or NULL |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 246 | */ |
Swen Schillig | 317e6b6 | 2008-07-02 10:56:37 +0200 | [diff] [blame] | 247 | struct zfcp_port *zfcp_get_port_by_wwpn(struct zfcp_adapter *adapter, |
Swen Schillig | 7ba58c9 | 2008-10-01 12:42:18 +0200 | [diff] [blame] | 248 | u64 wwpn) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 249 | { |
| 250 | struct zfcp_port *port; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 251 | |
Swen Schillig | 317e6b6 | 2008-07-02 10:56:37 +0200 | [diff] [blame] | 252 | list_for_each_entry(port, &adapter->port_list_head, list) |
Christof Schmitt | a5b11dd | 2009-03-02 13:08:54 +0100 | [diff] [blame] | 253 | if ((port->wwpn == wwpn) && |
| 254 | !(atomic_read(&port->status) & ZFCP_STATUS_COMMON_REMOVE)) |
Swen Schillig | 317e6b6 | 2008-07-02 10:56:37 +0200 | [diff] [blame] | 255 | return port; |
| 256 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 257 | } |
| 258 | |
Swen Schillig | 6022192 | 2008-07-02 10:56:38 +0200 | [diff] [blame] | 259 | static void zfcp_sysfs_unit_release(struct device *dev) |
| 260 | { |
| 261 | kfree(container_of(dev, struct zfcp_unit, sysfs_device)); |
| 262 | } |
| 263 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 264 | /** |
| 265 | * zfcp_unit_enqueue - enqueue unit to unit list of a port. |
| 266 | * @port: pointer to port where unit is added |
| 267 | * @fcp_lun: FCP LUN of unit to be enqueued |
Swen Schillig | 317e6b6 | 2008-07-02 10:56:37 +0200 | [diff] [blame] | 268 | * Returns: pointer to enqueued unit on success, ERR_PTR on error |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 269 | * Locks: config_sema must be held to serialize changes to the unit list |
| 270 | * |
| 271 | * Sets up some unit internal structures and creates sysfs entry. |
| 272 | */ |
Swen Schillig | 7ba58c9 | 2008-10-01 12:42:18 +0200 | [diff] [blame] | 273 | struct zfcp_unit *zfcp_unit_enqueue(struct zfcp_port *port, u64 fcp_lun) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 274 | { |
Christof Schmitt | 462b785 | 2007-06-19 10:25:30 +0200 | [diff] [blame] | 275 | struct zfcp_unit *unit; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 276 | |
Swen Schillig | 317e6b6 | 2008-07-02 10:56:37 +0200 | [diff] [blame] | 277 | unit = kzalloc(sizeof(struct zfcp_unit), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 278 | if (!unit) |
Swen Schillig | 317e6b6 | 2008-07-02 10:56:37 +0200 | [diff] [blame] | 279 | return ERR_PTR(-ENOMEM); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 280 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 281 | atomic_set(&unit->refcount, 0); |
| 282 | init_waitqueue_head(&unit->remove_wq); |
Swen Schillig | 92d5193 | 2009-04-17 15:08:04 +0200 | [diff] [blame] | 283 | INIT_WORK(&unit->scsi_work, zfcp_scsi_scan); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 284 | |
| 285 | unit->port = port; |
| 286 | unit->fcp_lun = fcp_lun; |
| 287 | |
Cornelia Huck | 1bf5b28 | 2008-10-10 21:33:10 +0200 | [diff] [blame] | 288 | dev_set_name(&unit->sysfs_device, "0x%016llx", |
| 289 | (unsigned long long) fcp_lun); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 290 | unit->sysfs_device.parent = &port->sysfs_device; |
| 291 | unit->sysfs_device.release = zfcp_sysfs_unit_release; |
| 292 | dev_set_drvdata(&unit->sysfs_device, unit); |
| 293 | |
| 294 | /* mark unit unusable as long as sysfs registration is not complete */ |
| 295 | atomic_set_mask(ZFCP_STATUS_COMMON_REMOVE, &unit->status); |
| 296 | |
Christof Schmitt | c961585 | 2008-05-06 11:00:05 +0200 | [diff] [blame] | 297 | spin_lock_init(&unit->latencies.lock); |
| 298 | unit->latencies.write.channel.min = 0xFFFFFFFF; |
| 299 | unit->latencies.write.fabric.min = 0xFFFFFFFF; |
| 300 | unit->latencies.read.channel.min = 0xFFFFFFFF; |
| 301 | unit->latencies.read.fabric.min = 0xFFFFFFFF; |
| 302 | unit->latencies.cmd.channel.min = 0xFFFFFFFF; |
| 303 | unit->latencies.cmd.fabric.min = 0xFFFFFFFF; |
| 304 | |
Swen Schillig | 317e6b6 | 2008-07-02 10:56:37 +0200 | [diff] [blame] | 305 | read_lock_irq(&zfcp_data.config_lock); |
| 306 | if (zfcp_get_unit_by_lun(port, fcp_lun)) { |
| 307 | read_unlock_irq(&zfcp_data.config_lock); |
| 308 | goto err_out_free; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 309 | } |
Swen Schillig | 317e6b6 | 2008-07-02 10:56:37 +0200 | [diff] [blame] | 310 | read_unlock_irq(&zfcp_data.config_lock); |
| 311 | |
| 312 | if (device_register(&unit->sysfs_device)) |
| 313 | goto err_out_free; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 314 | |
Swen Schillig | 6022192 | 2008-07-02 10:56:38 +0200 | [diff] [blame] | 315 | if (sysfs_create_group(&unit->sysfs_device.kobj, |
| 316 | &zfcp_sysfs_unit_attrs)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 317 | device_unregister(&unit->sysfs_device); |
Swen Schillig | 317e6b6 | 2008-07-02 10:56:37 +0200 | [diff] [blame] | 318 | return ERR_PTR(-EIO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 319 | } |
| 320 | |
| 321 | zfcp_unit_get(unit); |
| 322 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 323 | write_lock_irq(&zfcp_data.config_lock); |
Christof Schmitt | 462b785 | 2007-06-19 10:25:30 +0200 | [diff] [blame] | 324 | list_add_tail(&unit->list, &port->unit_list_head); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 325 | atomic_clear_mask(ZFCP_STATUS_COMMON_REMOVE, &unit->status); |
| 326 | atomic_set_mask(ZFCP_STATUS_COMMON_RUNNING, &unit->status); |
Swen Schillig | 317e6b6 | 2008-07-02 10:56:37 +0200 | [diff] [blame] | 327 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 328 | write_unlock_irq(&zfcp_data.config_lock); |
| 329 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 330 | zfcp_port_get(port); |
| 331 | |
| 332 | return unit; |
Swen Schillig | 317e6b6 | 2008-07-02 10:56:37 +0200 | [diff] [blame] | 333 | |
| 334 | err_out_free: |
| 335 | kfree(unit); |
| 336 | return ERR_PTR(-EINVAL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 337 | } |
| 338 | |
Swen Schillig | 317e6b6 | 2008-07-02 10:56:37 +0200 | [diff] [blame] | 339 | /** |
| 340 | * zfcp_unit_dequeue - dequeue unit |
| 341 | * @unit: pointer to zfcp_unit |
| 342 | * |
| 343 | * waits until all work is done on unit and removes it then from the unit->list |
| 344 | * of the associated port. |
| 345 | */ |
| 346 | void zfcp_unit_dequeue(struct zfcp_unit *unit) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 347 | { |
Swen Schillig | 44cc76f | 2008-10-01 12:42:16 +0200 | [diff] [blame] | 348 | wait_event(unit->remove_wq, atomic_read(&unit->refcount) == 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 349 | write_lock_irq(&zfcp_data.config_lock); |
| 350 | list_del(&unit->list); |
| 351 | write_unlock_irq(&zfcp_data.config_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 352 | zfcp_port_put(unit->port); |
Swen Schillig | 6022192 | 2008-07-02 10:56:38 +0200 | [diff] [blame] | 353 | sysfs_remove_group(&unit->sysfs_device.kobj, &zfcp_sysfs_unit_attrs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 354 | device_unregister(&unit->sysfs_device); |
| 355 | } |
| 356 | |
Swen Schillig | 317e6b6 | 2008-07-02 10:56:37 +0200 | [diff] [blame] | 357 | static int zfcp_allocate_low_mem_buffers(struct zfcp_adapter *adapter) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 358 | { |
Swen Schillig | 317e6b6 | 2008-07-02 10:56:37 +0200 | [diff] [blame] | 359 | /* must only be called with zfcp_data.config_sema taken */ |
Swen Schillig | a4623c4 | 2009-08-18 15:43:15 +0200 | [diff] [blame] | 360 | adapter->pool.erp_req = |
| 361 | mempool_create_kmalloc_pool(1, sizeof(struct zfcp_fsf_req)); |
| 362 | if (!adapter->pool.erp_req) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 363 | return -ENOMEM; |
| 364 | |
Christof Schmitt | 799b76d | 2009-08-18 15:43:20 +0200 | [diff] [blame] | 365 | adapter->pool.gid_pn_req = |
| 366 | mempool_create_kmalloc_pool(1, sizeof(struct zfcp_fsf_req)); |
| 367 | if (!adapter->pool.gid_pn_req) |
| 368 | return -ENOMEM; |
| 369 | |
Swen Schillig | a4623c4 | 2009-08-18 15:43:15 +0200 | [diff] [blame] | 370 | adapter->pool.scsi_req = |
| 371 | mempool_create_kmalloc_pool(1, sizeof(struct zfcp_fsf_req)); |
| 372 | if (!adapter->pool.scsi_req) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 373 | return -ENOMEM; |
| 374 | |
Swen Schillig | a4623c4 | 2009-08-18 15:43:15 +0200 | [diff] [blame] | 375 | adapter->pool.scsi_abort = |
| 376 | mempool_create_kmalloc_pool(1, sizeof(struct zfcp_fsf_req)); |
| 377 | if (!adapter->pool.scsi_abort) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 378 | return -ENOMEM; |
| 379 | |
Swen Schillig | a4623c4 | 2009-08-18 15:43:15 +0200 | [diff] [blame] | 380 | adapter->pool.status_read_req = |
Swen Schillig | 317e6b6 | 2008-07-02 10:56:37 +0200 | [diff] [blame] | 381 | mempool_create_kmalloc_pool(FSF_STATUS_READS_RECOM, |
Matthew Dobson | 0eaae62a | 2006-03-26 01:37:47 -0800 | [diff] [blame] | 382 | sizeof(struct zfcp_fsf_req)); |
Swen Schillig | a4623c4 | 2009-08-18 15:43:15 +0200 | [diff] [blame] | 383 | if (!adapter->pool.status_read_req) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 384 | return -ENOMEM; |
| 385 | |
Swen Schillig | a4623c4 | 2009-08-18 15:43:15 +0200 | [diff] [blame] | 386 | adapter->pool.qtcb_pool = |
Christof Schmitt | 799b76d | 2009-08-18 15:43:20 +0200 | [diff] [blame] | 387 | mempool_create_slab_pool(4, zfcp_data.qtcb_cache); |
Swen Schillig | a4623c4 | 2009-08-18 15:43:15 +0200 | [diff] [blame] | 388 | if (!adapter->pool.qtcb_pool) |
| 389 | return -ENOMEM; |
| 390 | |
| 391 | adapter->pool.status_read_data = |
Swen Schillig | 317e6b6 | 2008-07-02 10:56:37 +0200 | [diff] [blame] | 392 | mempool_create_slab_pool(FSF_STATUS_READS_RECOM, |
Heiko Carstens | dd52e0e | 2006-09-18 22:28:49 +0200 | [diff] [blame] | 393 | zfcp_data.sr_buffer_cache); |
Swen Schillig | a4623c4 | 2009-08-18 15:43:15 +0200 | [diff] [blame] | 394 | if (!adapter->pool.status_read_data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 395 | return -ENOMEM; |
| 396 | |
Swen Schillig | a4623c4 | 2009-08-18 15:43:15 +0200 | [diff] [blame] | 397 | adapter->pool.gid_pn_data = |
Swen Schillig | 317e6b6 | 2008-07-02 10:56:37 +0200 | [diff] [blame] | 398 | mempool_create_slab_pool(1, zfcp_data.gid_pn_cache); |
Swen Schillig | a4623c4 | 2009-08-18 15:43:15 +0200 | [diff] [blame] | 399 | if (!adapter->pool.gid_pn_data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 400 | return -ENOMEM; |
| 401 | |
| 402 | return 0; |
| 403 | } |
| 404 | |
Swen Schillig | 317e6b6 | 2008-07-02 10:56:37 +0200 | [diff] [blame] | 405 | static void zfcp_free_low_mem_buffers(struct zfcp_adapter *adapter) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 406 | { |
Swen Schillig | 317e6b6 | 2008-07-02 10:56:37 +0200 | [diff] [blame] | 407 | /* zfcp_data.config_sema must be held */ |
Swen Schillig | a4623c4 | 2009-08-18 15:43:15 +0200 | [diff] [blame] | 408 | if (adapter->pool.erp_req) |
| 409 | mempool_destroy(adapter->pool.erp_req); |
| 410 | if (adapter->pool.scsi_req) |
| 411 | mempool_destroy(adapter->pool.scsi_req); |
| 412 | if (adapter->pool.scsi_abort) |
| 413 | mempool_destroy(adapter->pool.scsi_abort); |
| 414 | if (adapter->pool.qtcb_pool) |
| 415 | mempool_destroy(adapter->pool.qtcb_pool); |
| 416 | if (adapter->pool.status_read_req) |
| 417 | mempool_destroy(adapter->pool.status_read_req); |
| 418 | if (adapter->pool.status_read_data) |
| 419 | mempool_destroy(adapter->pool.status_read_data); |
| 420 | if (adapter->pool.gid_pn_data) |
| 421 | mempool_destroy(adapter->pool.gid_pn_data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 422 | } |
| 423 | |
Swen Schillig | 317e6b6 | 2008-07-02 10:56:37 +0200 | [diff] [blame] | 424 | /** |
| 425 | * zfcp_status_read_refill - refill the long running status_read_requests |
| 426 | * @adapter: ptr to struct zfcp_adapter for which the buffers should be refilled |
| 427 | * |
| 428 | * Returns: 0 on success, 1 otherwise |
| 429 | * |
| 430 | * if there are 16 or more status_read requests missing an adapter_reopen |
| 431 | * is triggered |
| 432 | */ |
Swen Schillig | d26ab06 | 2008-05-19 12:17:37 +0200 | [diff] [blame] | 433 | int zfcp_status_read_refill(struct zfcp_adapter *adapter) |
| 434 | { |
| 435 | while (atomic_read(&adapter->stat_miss) > 0) |
Swen Schillig | 564e1c8 | 2009-08-18 15:43:19 +0200 | [diff] [blame] | 436 | if (zfcp_fsf_status_read(adapter->qdio)) { |
Swen Schillig | 7afe29f | 2008-07-02 10:56:33 +0200 | [diff] [blame] | 437 | if (atomic_read(&adapter->stat_miss) >= 16) { |
Swen Schillig | 5ffd51a | 2009-03-02 13:09:04 +0100 | [diff] [blame] | 438 | zfcp_erp_adapter_reopen(adapter, 0, "axsref1", |
| 439 | NULL); |
Swen Schillig | 7afe29f | 2008-07-02 10:56:33 +0200 | [diff] [blame] | 440 | return 1; |
| 441 | } |
Swen Schillig | d26ab06 | 2008-05-19 12:17:37 +0200 | [diff] [blame] | 442 | break; |
Swen Schillig | 7afe29f | 2008-07-02 10:56:33 +0200 | [diff] [blame] | 443 | } else |
| 444 | atomic_dec(&adapter->stat_miss); |
Swen Schillig | d26ab06 | 2008-05-19 12:17:37 +0200 | [diff] [blame] | 445 | return 0; |
| 446 | } |
| 447 | |
| 448 | static void _zfcp_status_read_scheduler(struct work_struct *work) |
| 449 | { |
| 450 | zfcp_status_read_refill(container_of(work, struct zfcp_adapter, |
| 451 | stat_work)); |
| 452 | } |
| 453 | |
Christof Schmitt | bd43a42b7 | 2008-12-25 13:38:50 +0100 | [diff] [blame] | 454 | static void zfcp_print_sl(struct seq_file *m, struct service_level *sl) |
| 455 | { |
| 456 | struct zfcp_adapter *adapter = |
| 457 | container_of(sl, struct zfcp_adapter, service_level); |
| 458 | |
| 459 | seq_printf(m, "zfcp: %s microcode level %x\n", |
| 460 | dev_name(&adapter->ccw_device->dev), |
| 461 | adapter->fsf_lic_version); |
| 462 | } |
| 463 | |
Swen Schillig | 4544683 | 2009-08-18 15:43:17 +0200 | [diff] [blame] | 464 | static int zfcp_setup_adapter_work_queue(struct zfcp_adapter *adapter) |
| 465 | { |
| 466 | char name[TASK_COMM_LEN]; |
| 467 | |
| 468 | snprintf(name, sizeof(name), "zfcp_q_%s", |
| 469 | dev_name(&adapter->ccw_device->dev)); |
| 470 | adapter->work_queue = create_singlethread_workqueue(name); |
| 471 | |
| 472 | if (adapter->work_queue) |
| 473 | return 0; |
| 474 | return -ENOMEM; |
| 475 | } |
| 476 | |
| 477 | static void zfcp_destroy_adapter_work_queue(struct zfcp_adapter *adapter) |
| 478 | { |
| 479 | if (adapter->work_queue) |
| 480 | destroy_workqueue(adapter->work_queue); |
| 481 | adapter->work_queue = NULL; |
| 482 | |
| 483 | } |
| 484 | |
Swen Schillig | 317e6b6 | 2008-07-02 10:56:37 +0200 | [diff] [blame] | 485 | /** |
| 486 | * zfcp_adapter_enqueue - enqueue a new adapter to the list |
| 487 | * @ccw_device: pointer to the struct cc_device |
| 488 | * |
| 489 | * Returns: 0 if a new adapter was successfully enqueued |
| 490 | * -ENOMEM if alloc failed |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 491 | * Enqueues an adapter at the end of the adapter list in the driver data. |
| 492 | * All adapter internal structures are set up. |
| 493 | * Proc-fs entries are also created. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 494 | * locks: config_sema must be held to serialise changes to the adapter list |
| 495 | */ |
Swen Schillig | 317e6b6 | 2008-07-02 10:56:37 +0200 | [diff] [blame] | 496 | int zfcp_adapter_enqueue(struct ccw_device *ccw_device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 497 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 498 | struct zfcp_adapter *adapter; |
| 499 | |
| 500 | /* |
Swen Schillig | 41fa2ad | 2007-09-07 09:15:31 +0200 | [diff] [blame] | 501 | * Note: It is safe to release the list_lock, as any list changes |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 502 | * are protected by the config_sema, which must be held to get here |
| 503 | */ |
| 504 | |
Swen Schillig | 317e6b6 | 2008-07-02 10:56:37 +0200 | [diff] [blame] | 505 | adapter = kzalloc(sizeof(struct zfcp_adapter), GFP_KERNEL); |
Christof Schmitt | 553448f | 2008-06-10 18:20:58 +0200 | [diff] [blame] | 506 | if (!adapter) |
Swen Schillig | 317e6b6 | 2008-07-02 10:56:37 +0200 | [diff] [blame] | 507 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 508 | |
Sven Schuetz | 9d544f2 | 2009-04-06 18:31:47 +0200 | [diff] [blame] | 509 | adapter->gs = kzalloc(sizeof(struct zfcp_wka_ports), GFP_KERNEL); |
| 510 | if (!adapter->gs) { |
| 511 | kfree(adapter); |
| 512 | return -ENOMEM; |
| 513 | } |
| 514 | |
Swen Schillig | 564e1c8 | 2009-08-18 15:43:19 +0200 | [diff] [blame] | 515 | adapter->qdio = kzalloc(sizeof(struct zfcp_qdio), GFP_KERNEL); |
| 516 | if (!adapter->qdio) |
| 517 | goto qdio_mem_failed; |
| 518 | |
| 519 | adapter->qdio->adapter = adapter; |
Swen Schillig | 5771710 | 2009-08-18 15:43:21 +0200 | [diff] [blame^] | 520 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 521 | ccw_device->handler = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 522 | adapter->ccw_device = ccw_device; |
Swen Schillig | 317e6b6 | 2008-07-02 10:56:37 +0200 | [diff] [blame] | 523 | atomic_set(&adapter->refcount, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 524 | |
Swen Schillig | 564e1c8 | 2009-08-18 15:43:19 +0200 | [diff] [blame] | 525 | if (zfcp_qdio_allocate(adapter->qdio, ccw_device)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 526 | goto qdio_allocate_failed; |
| 527 | |
Swen Schillig | 00bab91 | 2008-06-10 18:20:57 +0200 | [diff] [blame] | 528 | if (zfcp_allocate_low_mem_buffers(adapter)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 529 | goto failed_low_mem_buffers; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 530 | |
Swen Schillig | 00bab91 | 2008-06-10 18:20:57 +0200 | [diff] [blame] | 531 | if (zfcp_reqlist_alloc(adapter)) |
Volker Sameske | fea9d6c | 2006-08-02 11:05:16 +0200 | [diff] [blame] | 532 | goto failed_low_mem_buffers; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 533 | |
Swen Schillig | 5771710 | 2009-08-18 15:43:21 +0200 | [diff] [blame^] | 534 | if (zfcp_dbf_adapter_register(adapter)) |
Swen Schillig | 317e6b6 | 2008-07-02 10:56:37 +0200 | [diff] [blame] | 535 | goto debug_register_failed; |
| 536 | |
Swen Schillig | 4544683 | 2009-08-18 15:43:17 +0200 | [diff] [blame] | 537 | if (zfcp_setup_adapter_work_queue(adapter)) |
| 538 | goto work_queue_failed; |
| 539 | |
Swen Schillig | 317e6b6 | 2008-07-02 10:56:37 +0200 | [diff] [blame] | 540 | init_waitqueue_head(&adapter->remove_wq); |
| 541 | init_waitqueue_head(&adapter->erp_thread_wqh); |
| 542 | init_waitqueue_head(&adapter->erp_done_wqh); |
| 543 | |
| 544 | INIT_LIST_HEAD(&adapter->port_list_head); |
Swen Schillig | 317e6b6 | 2008-07-02 10:56:37 +0200 | [diff] [blame] | 545 | INIT_LIST_HEAD(&adapter->erp_ready_head); |
| 546 | INIT_LIST_HEAD(&adapter->erp_running_head); |
| 547 | |
| 548 | spin_lock_init(&adapter->req_list_lock); |
Heiko Carstens | c48a29d | 2005-12-01 02:46:32 +0100 | [diff] [blame] | 549 | |
Swen Schillig | 564e1c8 | 2009-08-18 15:43:19 +0200 | [diff] [blame] | 550 | spin_lock_init(&adapter->qdio->req_q_lock); |
| 551 | spin_lock_init(&adapter->qdio->stat_lock); |
Heiko Carstens | c48a29d | 2005-12-01 02:46:32 +0100 | [diff] [blame] | 552 | |
Heiko Carstens | c48a29d | 2005-12-01 02:46:32 +0100 | [diff] [blame] | 553 | rwlock_init(&adapter->erp_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 554 | rwlock_init(&adapter->abort_lock); |
Swen Schillig | 317e6b6 | 2008-07-02 10:56:37 +0200 | [diff] [blame] | 555 | |
| 556 | sema_init(&adapter->erp_ready_sem, 0); |
| 557 | |
Swen Schillig | d26ab06 | 2008-05-19 12:17:37 +0200 | [diff] [blame] | 558 | INIT_WORK(&adapter->stat_work, _zfcp_status_read_scheduler); |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 559 | INIT_WORK(&adapter->scan_work, _zfcp_scan_ports_later); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 560 | |
Christof Schmitt | bd43a42b7 | 2008-12-25 13:38:50 +0100 | [diff] [blame] | 561 | adapter->service_level.seq_print = zfcp_print_sl; |
| 562 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 563 | /* mark adapter unusable as long as sysfs registration is not complete */ |
| 564 | atomic_set_mask(ZFCP_STATUS_COMMON_REMOVE, &adapter->status); |
| 565 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 566 | dev_set_drvdata(&ccw_device->dev, adapter); |
| 567 | |
Swen Schillig | 6022192 | 2008-07-02 10:56:38 +0200 | [diff] [blame] | 568 | if (sysfs_create_group(&ccw_device->dev.kobj, |
| 569 | &zfcp_sysfs_adapter_attrs)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 570 | goto sysfs_failed; |
| 571 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 572 | atomic_clear_mask(ZFCP_STATUS_COMMON_REMOVE, &adapter->status); |
Sven Schuetz | 9d544f2 | 2009-04-06 18:31:47 +0200 | [diff] [blame] | 573 | zfcp_fc_wka_ports_init(adapter); |
Swen Schillig | 828bc12 | 2009-04-17 15:08:05 +0200 | [diff] [blame] | 574 | |
Swen Schillig | 1d3aab0 | 2008-12-19 16:56:53 +0100 | [diff] [blame] | 575 | if (!zfcp_adapter_scsi_register(adapter)) |
| 576 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 577 | |
Swen Schillig | 317e6b6 | 2008-07-02 10:56:37 +0200 | [diff] [blame] | 578 | sysfs_failed: |
Swen Schillig | 4544683 | 2009-08-18 15:43:17 +0200 | [diff] [blame] | 579 | zfcp_destroy_adapter_work_queue(adapter); |
| 580 | work_queue_failed: |
Swen Schillig | 5771710 | 2009-08-18 15:43:21 +0200 | [diff] [blame^] | 581 | zfcp_dbf_adapter_unregister(adapter->dbf); |
Swen Schillig | 317e6b6 | 2008-07-02 10:56:37 +0200 | [diff] [blame] | 582 | debug_register_failed: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 583 | dev_set_drvdata(&ccw_device->dev, NULL); |
Swen Schillig | 317e6b6 | 2008-07-02 10:56:37 +0200 | [diff] [blame] | 584 | kfree(adapter->req_list); |
| 585 | failed_low_mem_buffers: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 586 | zfcp_free_low_mem_buffers(adapter); |
Swen Schillig | 317e6b6 | 2008-07-02 10:56:37 +0200 | [diff] [blame] | 587 | qdio_allocate_failed: |
Swen Schillig | 564e1c8 | 2009-08-18 15:43:19 +0200 | [diff] [blame] | 588 | zfcp_qdio_free(adapter->qdio); |
| 589 | kfree(adapter->qdio); |
| 590 | qdio_mem_failed: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 591 | kfree(adapter); |
Swen Schillig | 317e6b6 | 2008-07-02 10:56:37 +0200 | [diff] [blame] | 592 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 593 | } |
| 594 | |
Swen Schillig | 317e6b6 | 2008-07-02 10:56:37 +0200 | [diff] [blame] | 595 | /** |
| 596 | * zfcp_adapter_dequeue - remove the adapter from the resource list |
| 597 | * @adapter: pointer to struct zfcp_adapter which should be removed |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 598 | * locks: adapter list write lock is assumed to be held by caller |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 599 | */ |
Swen Schillig | 317e6b6 | 2008-07-02 10:56:37 +0200 | [diff] [blame] | 600 | void zfcp_adapter_dequeue(struct zfcp_adapter *adapter) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 601 | { |
| 602 | int retval = 0; |
| 603 | unsigned long flags; |
| 604 | |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 605 | cancel_work_sync(&adapter->scan_work); |
Swen Schillig | d26ab06 | 2008-05-19 12:17:37 +0200 | [diff] [blame] | 606 | cancel_work_sync(&adapter->stat_work); |
Christof Schmitt | 55c770f | 2009-08-18 15:43:12 +0200 | [diff] [blame] | 607 | zfcp_fc_wka_ports_force_offline(adapter->gs); |
Michael Loehr | 9f28745 | 2007-05-09 11:01:24 +0200 | [diff] [blame] | 608 | zfcp_adapter_scsi_unregister(adapter); |
Swen Schillig | 6022192 | 2008-07-02 10:56:38 +0200 | [diff] [blame] | 609 | sysfs_remove_group(&adapter->ccw_device->dev.kobj, |
| 610 | &zfcp_sysfs_adapter_attrs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 611 | dev_set_drvdata(&adapter->ccw_device->dev, NULL); |
| 612 | /* sanity check: no pending FSF requests */ |
Volker Sameske | fea9d6c | 2006-08-02 11:05:16 +0200 | [diff] [blame] | 613 | spin_lock_irqsave(&adapter->req_list_lock, flags); |
| 614 | retval = zfcp_reqlist_isempty(adapter); |
| 615 | spin_unlock_irqrestore(&adapter->req_list_lock, flags); |
Swen Schillig | 317e6b6 | 2008-07-02 10:56:37 +0200 | [diff] [blame] | 616 | if (!retval) |
| 617 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 618 | |
Swen Schillig | 4544683 | 2009-08-18 15:43:17 +0200 | [diff] [blame] | 619 | zfcp_destroy_adapter_work_queue(adapter); |
Swen Schillig | 5771710 | 2009-08-18 15:43:21 +0200 | [diff] [blame^] | 620 | zfcp_dbf_adapter_unregister(adapter->dbf); |
Swen Schillig | 564e1c8 | 2009-08-18 15:43:19 +0200 | [diff] [blame] | 621 | zfcp_qdio_free(adapter->qdio); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 622 | zfcp_free_low_mem_buffers(adapter); |
Swen Schillig | 317e6b6 | 2008-07-02 10:56:37 +0200 | [diff] [blame] | 623 | kfree(adapter->req_list); |
Andreas Herrmann | f6cd94b | 2006-01-05 09:59:34 +0100 | [diff] [blame] | 624 | kfree(adapter->fc_stats); |
| 625 | kfree(adapter->stats_reset_data); |
Sven Schuetz | 9d544f2 | 2009-04-06 18:31:47 +0200 | [diff] [blame] | 626 | kfree(adapter->gs); |
Swen Schillig | 564e1c8 | 2009-08-18 15:43:19 +0200 | [diff] [blame] | 627 | kfree(adapter->qdio); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 628 | kfree(adapter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 629 | } |
| 630 | |
Swen Schillig | 6022192 | 2008-07-02 10:56:38 +0200 | [diff] [blame] | 631 | static void zfcp_sysfs_port_release(struct device *dev) |
| 632 | { |
| 633 | kfree(container_of(dev, struct zfcp_port, sysfs_device)); |
| 634 | } |
| 635 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 636 | /** |
| 637 | * zfcp_port_enqueue - enqueue port to port list of adapter |
| 638 | * @adapter: adapter where remote port is added |
| 639 | * @wwpn: WWPN of the remote port to be enqueued |
| 640 | * @status: initial status for the port |
| 641 | * @d_id: destination id of the remote port to be enqueued |
Swen Schillig | 317e6b6 | 2008-07-02 10:56:37 +0200 | [diff] [blame] | 642 | * Returns: pointer to enqueued port on success, ERR_PTR on error |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 643 | * Locks: config_sema must be held to serialize changes to the port list |
| 644 | * |
| 645 | * All port internal structures are set up and the sysfs entry is generated. |
| 646 | * d_id is used to enqueue ports with a well known address like the Directory |
| 647 | * Service for nameserver lookup. |
| 648 | */ |
Swen Schillig | 7ba58c9 | 2008-10-01 12:42:18 +0200 | [diff] [blame] | 649 | struct zfcp_port *zfcp_port_enqueue(struct zfcp_adapter *adapter, u64 wwpn, |
Swen Schillig | 317e6b6 | 2008-07-02 10:56:37 +0200 | [diff] [blame] | 650 | u32 status, u32 d_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 651 | { |
Andreas Herrmann | 3859f6a | 2005-08-27 11:07:54 -0700 | [diff] [blame] | 652 | struct zfcp_port *port; |
Swen Schillig | 6022192 | 2008-07-02 10:56:38 +0200 | [diff] [blame] | 653 | int retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 654 | |
Swen Schillig | 317e6b6 | 2008-07-02 10:56:37 +0200 | [diff] [blame] | 655 | port = kzalloc(sizeof(struct zfcp_port), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 656 | if (!port) |
Swen Schillig | 317e6b6 | 2008-07-02 10:56:37 +0200 | [diff] [blame] | 657 | return ERR_PTR(-ENOMEM); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 658 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 659 | init_waitqueue_head(&port->remove_wq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 660 | INIT_LIST_HEAD(&port->unit_list_head); |
Christof Schmitt | 799b76d | 2009-08-18 15:43:20 +0200 | [diff] [blame] | 661 | INIT_WORK(&port->gid_pn_work, zfcp_fc_port_did_lookup); |
Christof Schmitt | 8fdf30d | 2009-03-02 13:09:01 +0100 | [diff] [blame] | 662 | INIT_WORK(&port->test_link_work, zfcp_fc_link_test_work); |
Christof Schmitt | a2fa0ae | 2009-03-02 13:09:08 +0100 | [diff] [blame] | 663 | INIT_WORK(&port->rport_work, zfcp_scsi_rport_work); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 664 | |
| 665 | port->adapter = adapter; |
Swen Schillig | 317e6b6 | 2008-07-02 10:56:37 +0200 | [diff] [blame] | 666 | port->d_id = d_id; |
| 667 | port->wwpn = wwpn; |
Christof Schmitt | a2fa0ae | 2009-03-02 13:09:08 +0100 | [diff] [blame] | 668 | port->rport_task = RPORT_NONE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 669 | |
Swen Schillig | 317e6b6 | 2008-07-02 10:56:37 +0200 | [diff] [blame] | 670 | /* mark port unusable as long as sysfs registration is not complete */ |
| 671 | atomic_set_mask(status | ZFCP_STATUS_COMMON_REMOVE, &port->status); |
| 672 | atomic_set(&port->refcount, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 673 | |
Christof Schmitt | adc90da | 2008-11-04 16:35:09 +0100 | [diff] [blame] | 674 | dev_set_name(&port->sysfs_device, "0x%016llx", |
| 675 | (unsigned long long)wwpn); |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 676 | port->sysfs_device.parent = &adapter->ccw_device->dev; |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 677 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 678 | port->sysfs_device.release = zfcp_sysfs_port_release; |
| 679 | dev_set_drvdata(&port->sysfs_device, port); |
| 680 | |
Swen Schillig | 317e6b6 | 2008-07-02 10:56:37 +0200 | [diff] [blame] | 681 | read_lock_irq(&zfcp_data.config_lock); |
Christof Schmitt | a5b11dd | 2009-03-02 13:08:54 +0100 | [diff] [blame] | 682 | if (zfcp_get_port_by_wwpn(adapter, wwpn)) { |
| 683 | read_unlock_irq(&zfcp_data.config_lock); |
| 684 | goto err_out_free; |
| 685 | } |
Swen Schillig | 317e6b6 | 2008-07-02 10:56:37 +0200 | [diff] [blame] | 686 | read_unlock_irq(&zfcp_data.config_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 687 | |
Swen Schillig | 317e6b6 | 2008-07-02 10:56:37 +0200 | [diff] [blame] | 688 | if (device_register(&port->sysfs_device)) |
| 689 | goto err_out_free; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 690 | |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 691 | retval = sysfs_create_group(&port->sysfs_device.kobj, |
| 692 | &zfcp_sysfs_port_attrs); |
Swen Schillig | 6022192 | 2008-07-02 10:56:38 +0200 | [diff] [blame] | 693 | |
| 694 | if (retval) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 695 | device_unregister(&port->sysfs_device); |
Swen Schillig | 317e6b6 | 2008-07-02 10:56:37 +0200 | [diff] [blame] | 696 | goto err_out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 697 | } |
| 698 | |
| 699 | zfcp_port_get(port); |
| 700 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 701 | write_lock_irq(&zfcp_data.config_lock); |
Andreas Herrmann | 3859f6a | 2005-08-27 11:07:54 -0700 | [diff] [blame] | 702 | list_add_tail(&port->list, &adapter->port_list_head); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 703 | atomic_clear_mask(ZFCP_STATUS_COMMON_REMOVE, &port->status); |
| 704 | atomic_set_mask(ZFCP_STATUS_COMMON_RUNNING, &port->status); |
Swen Schillig | 317e6b6 | 2008-07-02 10:56:37 +0200 | [diff] [blame] | 705 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 706 | write_unlock_irq(&zfcp_data.config_lock); |
| 707 | |
| 708 | zfcp_adapter_get(adapter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 709 | return port; |
Swen Schillig | 317e6b6 | 2008-07-02 10:56:37 +0200 | [diff] [blame] | 710 | |
| 711 | err_out_free: |
| 712 | kfree(port); |
| 713 | err_out: |
| 714 | return ERR_PTR(-EINVAL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 715 | } |
| 716 | |
Swen Schillig | 317e6b6 | 2008-07-02 10:56:37 +0200 | [diff] [blame] | 717 | /** |
| 718 | * zfcp_port_dequeue - dequeues a port from the port list of the adapter |
| 719 | * @port: pointer to struct zfcp_port which should be removed |
| 720 | */ |
| 721 | void zfcp_port_dequeue(struct zfcp_port *port) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 722 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 723 | write_lock_irq(&zfcp_data.config_lock); |
| 724 | list_del(&port->list); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 725 | write_unlock_irq(&zfcp_data.config_lock); |
Swen Schillig | a67417a | 2009-08-18 15:43:06 +0200 | [diff] [blame] | 726 | if (port->rport) { |
Christof Schmitt | 7093293 | 2009-04-17 15:08:15 +0200 | [diff] [blame] | 727 | port->rport->dd_data = NULL; |
Swen Schillig | a67417a | 2009-08-18 15:43:06 +0200 | [diff] [blame] | 728 | port->rport = NULL; |
| 729 | } |
| 730 | wait_event(port->remove_wq, atomic_read(&port->refcount) == 0); |
| 731 | cancel_work_sync(&port->rport_work); /* usually not necessary */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 732 | zfcp_adapter_put(port->adapter); |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 733 | sysfs_remove_group(&port->sysfs_device.kobj, &zfcp_sysfs_port_attrs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 734 | device_unregister(&port->sysfs_device); |
| 735 | } |
| 736 | |
Swen Schillig | 317e6b6 | 2008-07-02 10:56:37 +0200 | [diff] [blame] | 737 | /** |
| 738 | * zfcp_sg_free_table - free memory used by scatterlists |
| 739 | * @sg: pointer to scatterlist |
| 740 | * @count: number of scatterlist which are to be free'ed |
| 741 | * the scatterlist are expected to reference pages always |
| 742 | */ |
Christof Schmitt | 45633fd | 2008-06-10 18:20:55 +0200 | [diff] [blame] | 743 | void zfcp_sg_free_table(struct scatterlist *sg, int count) |
| 744 | { |
| 745 | int i; |
| 746 | |
| 747 | for (i = 0; i < count; i++, sg++) |
| 748 | if (sg) |
| 749 | free_page((unsigned long) sg_virt(sg)); |
| 750 | else |
| 751 | break; |
| 752 | } |
| 753 | |
Swen Schillig | 317e6b6 | 2008-07-02 10:56:37 +0200 | [diff] [blame] | 754 | /** |
| 755 | * zfcp_sg_setup_table - init scatterlist and allocate, assign buffers |
| 756 | * @sg: pointer to struct scatterlist |
| 757 | * @count: number of scatterlists which should be assigned with buffers |
| 758 | * of size page |
| 759 | * |
| 760 | * Returns: 0 on success, -ENOMEM otherwise |
| 761 | */ |
Christof Schmitt | 45633fd | 2008-06-10 18:20:55 +0200 | [diff] [blame] | 762 | int zfcp_sg_setup_table(struct scatterlist *sg, int count) |
| 763 | { |
| 764 | void *addr; |
| 765 | int i; |
| 766 | |
| 767 | sg_init_table(sg, count); |
| 768 | for (i = 0; i < count; i++, sg++) { |
| 769 | addr = (void *) get_zeroed_page(GFP_KERNEL); |
| 770 | if (!addr) { |
| 771 | zfcp_sg_free_table(sg, i); |
| 772 | return -ENOMEM; |
| 773 | } |
| 774 | sg_set_buf(sg, addr, PAGE_SIZE); |
| 775 | } |
| 776 | return 0; |
| 777 | } |