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