aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/s390/scsi
diff options
context:
space:
mode:
authorSwen Schillig <swen@vnet.ibm.com>2008-07-02 04:56:37 -0400
committerJames Bottomley <James.Bottomley@HansenPartnership.com>2008-07-12 09:22:35 -0400
commit317e6b6519b5a34263a33f150ed57ad468b26a64 (patch)
tree074a35c260d567911b009fd70b83940cdd254bbd /drivers/s390/scsi
parentf76af7d7e36373179be7a9e09f6b0aae330549b7 (diff)
[SCSI] zfcp: Cleanup of code in zfcp_aux.c
Overall cleanup of zfcp_aux.c to simplify code and follow kernel coding style. Signed-off-by: Swen Schillig <swen@vnet.ibm.com> Signed-off-by: Christof Schmitt <christof.schmitt@de.ibm.com> Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
Diffstat (limited to 'drivers/s390/scsi')
-rw-r--r--drivers/s390/scsi/zfcp_aux.c583
-rw-r--r--drivers/s390/scsi/zfcp_ccw.c4
-rw-r--r--drivers/s390/scsi/zfcp_def.h13
-rw-r--r--drivers/s390/scsi/zfcp_erp.c2
-rw-r--r--drivers/s390/scsi/zfcp_ext.h4
-rw-r--r--drivers/s390/scsi/zfcp_fc.c18
-rw-r--r--drivers/s390/scsi/zfcp_sysfs_port.c2
7 files changed, 238 insertions, 388 deletions
diff --git a/drivers/s390/scsi/zfcp_aux.c b/drivers/s390/scsi/zfcp_aux.c
index bfcd1ba28ae1..7777729419eb 100644
--- a/drivers/s390/scsi/zfcp_aux.c
+++ b/drivers/s390/scsi/zfcp_aux.c
@@ -29,48 +29,14 @@
29#include "zfcp_ext.h" 29#include "zfcp_ext.h"
30 30
31static char *device; 31static char *device;
32/*********************** FUNCTION PROTOTYPES *********************************/
33
34/* written against the module interface */
35static int __init zfcp_module_init(void);
36
37/*********************** KERNEL/MODULE PARAMETERS ***************************/
38
39/* declare driver module init/cleanup functions */
40module_init(zfcp_module_init);
41 32
42MODULE_AUTHOR("IBM Deutschland Entwicklung GmbH - linux390@de.ibm.com"); 33MODULE_AUTHOR("IBM Deutschland Entwicklung GmbH - linux390@de.ibm.com");
43MODULE_DESCRIPTION 34MODULE_DESCRIPTION("FCP HBA driver");
44 ("FCP (SCSI over Fibre Channel) HBA driver for IBM System z9 and zSeries");
45MODULE_LICENSE("GPL"); 35MODULE_LICENSE("GPL");
46 36
47module_param(device, charp, 0400); 37module_param(device, charp, 0400);
48MODULE_PARM_DESC(device, "specify initial device"); 38MODULE_PARM_DESC(device, "specify initial device");
49 39
50/****************************************************************/
51/************** Functions without logging ***********************/
52/****************************************************************/
53
54void
55_zfcp_hex_dump(char *addr, int count)
56{
57 int i;
58 for (i = 0; i < count; i++) {
59 printk("%02x", addr[i]);
60 if ((i % 4) == 3)
61 printk(" ");
62 if ((i % 32) == 31)
63 printk("\n");
64 }
65 if (((i-1) % 32) != 31)
66 printk("\n");
67}
68
69
70/****************************************************************/
71/****** Functions to handle the request ID hash table ********/
72/****************************************************************/
73
74static int zfcp_reqlist_alloc(struct zfcp_adapter *adapter) 40static int zfcp_reqlist_alloc(struct zfcp_adapter *adapter)
75{ 41{
76 int idx; 42 int idx;
@@ -85,11 +51,12 @@ static int zfcp_reqlist_alloc(struct zfcp_adapter *adapter)
85 return 0; 51 return 0;
86} 52}
87 53
88static void zfcp_reqlist_free(struct zfcp_adapter *adapter) 54/**
89{ 55 * zfcp_reqlist_isempty - is the request list empty
90 kfree(adapter->req_list); 56 * @adapter: pointer to struct zfcp_adapter
91} 57 *
92 58 * Returns: true if list is empty, false otherwise
59 */
93int zfcp_reqlist_isempty(struct zfcp_adapter *adapter) 60int zfcp_reqlist_isempty(struct zfcp_adapter *adapter)
94{ 61{
95 unsigned int idx; 62 unsigned int idx;
@@ -100,62 +67,58 @@ int zfcp_reqlist_isempty(struct zfcp_adapter *adapter)
100 return 1; 67 return 1;
101} 68}
102 69
103/****************************************************************/ 70static int __init zfcp_device_setup(char *devstr)
104/************** Uncategorised Functions *************************/
105/****************************************************************/
106
107/**
108 * zfcp_device_setup - setup function
109 * @str: pointer to parameter string
110 *
111 * Parse "device=..." parameter string.
112 */
113static int __init
114zfcp_device_setup(char *devstr)
115{ 71{
116 char *tmp, *str; 72 char *token;
117 size_t len; 73 char *str;
118 74
119 if (!devstr) 75 if (!devstr)
120 return 0; 76 return 0;
121 77
122 len = strlen(devstr) + 1; 78 /* duplicate devstr and keep the original for sysfs presentation*/
123 str = kmalloc(len, GFP_KERNEL); 79 str = kmalloc(strlen(devstr) + 1, GFP_KERNEL);
124 if (!str) { 80 if (!str)
125 pr_err("zfcp: Could not allocate memory for "
126 "device parameter string, device not attached.\n");
127 return 0; 81 return 0;
128 }
129 memcpy(str, devstr, len);
130 82
131 tmp = strchr(str, ','); 83 strcpy(str, devstr);
132 if (!tmp)
133 goto err_out;
134 *tmp++ = '\0';
135 strncpy(zfcp_data.init_busid, str, BUS_ID_SIZE);
136 zfcp_data.init_busid[BUS_ID_SIZE-1] = '\0';
137 84
138 zfcp_data.init_wwpn = simple_strtoull(tmp, &tmp, 0); 85 token = strsep(&str, ",");
139 if (*tmp++ != ',') 86 if (!token || strlen(token) >= BUS_ID_SIZE)
140 goto err_out; 87 goto err_out;
141 if (*tmp == '\0') 88 strncpy(zfcp_data.init_busid, token, BUS_ID_SIZE);
89
90 token = strsep(&str, ",");
91 if (!token || strict_strtoull(token, 0, &zfcp_data.init_wwpn))
142 goto err_out; 92 goto err_out;
143 93
144 zfcp_data.init_fcp_lun = simple_strtoull(tmp, &tmp, 0); 94 token = strsep(&str, ",");
145 if (*tmp != '\0') 95 if (!token || strict_strtoull(token, 0, &zfcp_data.init_fcp_lun))
146 goto err_out; 96 goto err_out;
97
147 kfree(str); 98 kfree(str);
148 return 1; 99 return 1;
149 100
150 err_out: 101 err_out:
151 pr_err("zfcp: Parse error for device parameter string %s, "
152 "device not attached.\n", str);
153 kfree(str); 102 kfree(str);
103 pr_err("zfcp: Parse error for device parameter string %s, "
104 "device not attached.\n", devstr);
154 return 0; 105 return 0;
155} 106}
156 107
157static void __init 108static struct zfcp_adapter *zfcp_get_adapter_by_busid(char *bus_id)
158zfcp_init_device_configure(void) 109{
110 struct zfcp_adapter *adapter;
111
112 list_for_each_entry(adapter, &zfcp_data.adapter_list_head, list)
113 if ((strncmp(bus_id, adapter->ccw_device->dev.bus_id,
114 BUS_ID_SIZE) == 0) &&
115 !(atomic_read(&adapter->status) &
116 ZFCP_STATUS_COMMON_REMOVE))
117 return adapter;
118 return NULL;
119}
120
121static void __init zfcp_init_device_configure(void)
159{ 122{
160 struct zfcp_adapter *adapter; 123 struct zfcp_adapter *adapter;
161 struct zfcp_port *port; 124 struct zfcp_port *port;
@@ -168,92 +131,72 @@ zfcp_init_device_configure(void)
168 zfcp_adapter_get(adapter); 131 zfcp_adapter_get(adapter);
169 read_unlock_irq(&zfcp_data.config_lock); 132 read_unlock_irq(&zfcp_data.config_lock);
170 133
171 if (adapter == NULL) 134 if (!adapter)
172 goto out_adapter; 135 goto out_adapter;
173 port = zfcp_port_enqueue(adapter, zfcp_data.init_wwpn, 0, 0); 136 port = zfcp_port_enqueue(adapter, zfcp_data.init_wwpn, 0, 0);
174 if (!port) 137 if (IS_ERR(port))
175 goto out_port; 138 goto out_port;
176 unit = zfcp_unit_enqueue(port, zfcp_data.init_fcp_lun); 139 unit = zfcp_unit_enqueue(port, zfcp_data.init_fcp_lun);
177 if (!unit) 140 if (IS_ERR(unit))
178 goto out_unit; 141 goto out_unit;
179 up(&zfcp_data.config_sema); 142 up(&zfcp_data.config_sema);
180 ccw_device_set_online(adapter->ccw_device); 143 ccw_device_set_online(adapter->ccw_device);
181 zfcp_erp_wait(adapter); 144 zfcp_erp_wait(adapter);
182 down(&zfcp_data.config_sema); 145 down(&zfcp_data.config_sema);
183 zfcp_unit_put(unit); 146 zfcp_unit_put(unit);
184 out_unit: 147out_unit:
185 zfcp_port_put(port); 148 zfcp_port_put(port);
186 out_port: 149out_port:
187 zfcp_adapter_put(adapter); 150 zfcp_adapter_put(adapter);
188 out_adapter: 151out_adapter:
189 up(&zfcp_data.config_sema); 152 up(&zfcp_data.config_sema);
190 return; 153 return;
191} 154}
192 155
193static int calc_alignment(int size) 156static struct kmem_cache *zfcp_cache_create(int size, char *name)
194{ 157{
195 int align = 1; 158 int align = 1;
196
197 if (!size)
198 return 0;
199
200 while ((size - align) > 0) 159 while ((size - align) > 0)
201 align <<= 1; 160 align <<= 1;
202 161 return kmem_cache_create(name , size, align, 0, NULL);
203 return align;
204} 162}
205 163
206static int __init 164static int __init zfcp_module_init(void)
207zfcp_module_init(void)
208{ 165{
209 int retval = -ENOMEM; 166 int retval = -ENOMEM;
210 int size, align;
211 167
212 size = sizeof(struct zfcp_fsf_req_qtcb); 168 zfcp_data.fsf_req_qtcb_cache = zfcp_cache_create(
213 align = calc_alignment(size); 169 sizeof(struct zfcp_fsf_req_qtcb), "zfcp_fsf");
214 zfcp_data.fsf_req_qtcb_cache =
215 kmem_cache_create("zfcp_fsf", size, align, 0, NULL);
216 if (!zfcp_data.fsf_req_qtcb_cache) 170 if (!zfcp_data.fsf_req_qtcb_cache)
217 goto out; 171 goto out;
218 172
219 size = sizeof(struct fsf_status_read_buffer); 173 zfcp_data.sr_buffer_cache = zfcp_cache_create(
220 align = calc_alignment(size); 174 sizeof(struct fsf_status_read_buffer), "zfcp_sr");
221 zfcp_data.sr_buffer_cache =
222 kmem_cache_create("zfcp_sr", size, align, 0, NULL);
223 if (!zfcp_data.sr_buffer_cache) 175 if (!zfcp_data.sr_buffer_cache)
224 goto out_sr_cache; 176 goto out_sr_cache;
225 177
226 size = sizeof(struct zfcp_gid_pn_data); 178 zfcp_data.gid_pn_cache = zfcp_cache_create(
227 align = calc_alignment(size); 179 sizeof(struct zfcp_gid_pn_data), "zfcp_gid");
228 zfcp_data.gid_pn_cache =
229 kmem_cache_create("zfcp_gid", size, align, 0, NULL);
230 if (!zfcp_data.gid_pn_cache) 180 if (!zfcp_data.gid_pn_cache)
231 goto out_gid_cache; 181 goto out_gid_cache;
232 182
233 /* initialize adapter list */
234 INIT_LIST_HEAD(&zfcp_data.adapter_list_head); 183 INIT_LIST_HEAD(&zfcp_data.adapter_list_head);
235
236 /* initialize adapters to be removed list head */
237 INIT_LIST_HEAD(&zfcp_data.adapter_remove_lh); 184 INIT_LIST_HEAD(&zfcp_data.adapter_remove_lh);
238 185
186 sema_init(&zfcp_data.config_sema, 1);
187 rwlock_init(&zfcp_data.config_lock);
188
239 zfcp_data.scsi_transport_template = 189 zfcp_data.scsi_transport_template =
240 fc_attach_transport(&zfcp_transport_functions); 190 fc_attach_transport(&zfcp_transport_functions);
241 if (!zfcp_data.scsi_transport_template) 191 if (!zfcp_data.scsi_transport_template)
242 goto out_transport; 192 goto out_transport;
243 193
244 retval = misc_register(&zfcp_cfdc_misc); 194 retval = misc_register(&zfcp_cfdc_misc);
245 if (retval != 0) { 195 if (retval) {
246 pr_err("zfcp: registration of misc device zfcp_cfdc failed\n"); 196 pr_err("zfcp: registration of misc device zfcp_cfdc failed\n");
247 goto out_misc; 197 goto out_misc;
248 } 198 }
249 199
250 /* Initialise proc semaphores */
251 sema_init(&zfcp_data.config_sema, 1);
252
253 /* initialise configuration rw lock */
254 rwlock_init(&zfcp_data.config_lock);
255
256 /* setup dynamic I/O */
257 retval = zfcp_ccw_register(); 200 retval = zfcp_ccw_register();
258 if (retval) { 201 if (retval) {
259 pr_err("zfcp: Registration with common I/O layer failed.\n"); 202 pr_err("zfcp: Registration with common I/O layer failed.\n");
@@ -265,157 +208,83 @@ zfcp_module_init(void)
265 208
266 goto out; 209 goto out;
267 210
268 out_ccw_register: 211out_ccw_register:
269 misc_deregister(&zfcp_cfdc_misc); 212 misc_deregister(&zfcp_cfdc_misc);
270 out_misc: 213out_misc:
271 fc_release_transport(zfcp_data.scsi_transport_template); 214 fc_release_transport(zfcp_data.scsi_transport_template);
272 out_transport: 215out_transport:
273 kmem_cache_destroy(zfcp_data.gid_pn_cache); 216 kmem_cache_destroy(zfcp_data.gid_pn_cache);
274 out_gid_cache: 217out_gid_cache:
275 kmem_cache_destroy(zfcp_data.sr_buffer_cache); 218 kmem_cache_destroy(zfcp_data.sr_buffer_cache);
276 out_sr_cache: 219out_sr_cache:
277 kmem_cache_destroy(zfcp_data.fsf_req_qtcb_cache); 220 kmem_cache_destroy(zfcp_data.fsf_req_qtcb_cache);
278 out: 221out:
279 return retval; 222 return retval;
280} 223}
281 224
282/****************************************************************/ 225module_init(zfcp_module_init);
283/****** Functions for configuration/set-up of structures ********/
284/****************************************************************/
285 226
286/** 227/**
287 * zfcp_get_unit_by_lun - find unit in unit list of port by FCP LUN 228 * zfcp_get_unit_by_lun - find unit in unit list of port by FCP LUN
288 * @port: pointer to port to search for unit 229 * @port: pointer to port to search for unit
289 * @fcp_lun: FCP LUN to search for 230 * @fcp_lun: FCP LUN to search for
290 * Traverse list of all units of a port and return pointer to a unit 231 *
291 * with the given FCP LUN. 232 * Returns: pointer to zfcp_unit or NULL
292 */ 233 */
293struct zfcp_unit * 234struct zfcp_unit *zfcp_get_unit_by_lun(struct zfcp_port *port,
294zfcp_get_unit_by_lun(struct zfcp_port *port, fcp_lun_t fcp_lun) 235 fcp_lun_t fcp_lun)
295{ 236{
296 struct zfcp_unit *unit; 237 struct zfcp_unit *unit;
297 int found = 0;
298 238
299 list_for_each_entry(unit, &port->unit_list_head, list) { 239 list_for_each_entry(unit, &port->unit_list_head, list)
300 if ((unit->fcp_lun == fcp_lun) && 240 if ((unit->fcp_lun == fcp_lun) &&
301 !atomic_test_mask(ZFCP_STATUS_COMMON_REMOVE, &unit->status)) 241 !(atomic_read(&unit->status) & ZFCP_STATUS_COMMON_REMOVE))
302 { 242 return unit;
303 found = 1; 243 return NULL;
304 break;
305 }
306 }
307 return found ? unit : NULL;
308} 244}
309 245
310/** 246/**
311 * zfcp_get_port_by_wwpn - find port in port list of adapter by wwpn 247 * zfcp_get_port_by_wwpn - find port in port list of adapter by wwpn
312 * @adapter: pointer to adapter to search for port 248 * @adapter: pointer to adapter to search for port
313 * @wwpn: wwpn to search for 249 * @wwpn: wwpn to search for
314 * Traverse list of all ports of an adapter and return pointer to a port 250 *
315 * with the given wwpn. 251 * Returns: pointer to zfcp_port or NULL
316 */ 252 */
317struct zfcp_port * 253struct zfcp_port *zfcp_get_port_by_wwpn(struct zfcp_adapter *adapter,
318zfcp_get_port_by_wwpn(struct zfcp_adapter *adapter, wwn_t wwpn) 254 wwn_t wwpn)
319{ 255{
320 struct zfcp_port *port; 256 struct zfcp_port *port;
321 int found = 0;
322 257
323 list_for_each_entry(port, &adapter->port_list_head, list) { 258 list_for_each_entry(port, &adapter->port_list_head, list)
324 if ((port->wwpn == wwpn) && 259 if ((port->wwpn == wwpn) && !(atomic_read(&port->status) &
325 !(atomic_read(&port->status) & 260 (ZFCP_STATUS_PORT_NO_WWPN | ZFCP_STATUS_COMMON_REMOVE)))
326 (ZFCP_STATUS_PORT_NO_WWPN | ZFCP_STATUS_COMMON_REMOVE))) { 261 return port;
327 found = 1; 262 return NULL;
328 break;
329 }
330 }
331 return found ? port : NULL;
332}
333
334/**
335 * zfcp_get_port_by_did - find port in port list of adapter by d_id
336 * @adapter: pointer to adapter to search for port
337 * @d_id: d_id to search for
338 * Traverse list of all ports of an adapter and return pointer to a port
339 * with the given d_id.
340 */
341struct zfcp_port *
342zfcp_get_port_by_did(struct zfcp_adapter *adapter, u32 d_id)
343{
344 struct zfcp_port *port;
345 int found = 0;
346
347 list_for_each_entry(port, &adapter->port_list_head, list) {
348 if ((port->d_id == d_id) &&
349 !atomic_test_mask(ZFCP_STATUS_COMMON_REMOVE, &port->status))
350 {
351 found = 1;
352 break;
353 }
354 }
355 return found ? port : NULL;
356}
357
358/**
359 * zfcp_get_adapter_by_busid - find adpater in adapter list by bus_id
360 * @bus_id: bus_id to search for
361 * Traverse list of all adapters and return pointer to an adapter
362 * with the given bus_id.
363 */
364struct zfcp_adapter *
365zfcp_get_adapter_by_busid(char *bus_id)
366{
367 struct zfcp_adapter *adapter;
368 int found = 0;
369
370 list_for_each_entry(adapter, &zfcp_data.adapter_list_head, list) {
371 if ((strncmp(bus_id, zfcp_get_busid_by_adapter(adapter),
372 BUS_ID_SIZE) == 0) &&
373 !atomic_test_mask(ZFCP_STATUS_COMMON_REMOVE,
374 &adapter->status)){
375 found = 1;
376 break;
377 }
378 }
379 return found ? adapter : NULL;
380} 263}
381 264
382/** 265/**
383 * zfcp_unit_enqueue - enqueue unit to unit list of a port. 266 * zfcp_unit_enqueue - enqueue unit to unit list of a port.
384 * @port: pointer to port where unit is added 267 * @port: pointer to port where unit is added
385 * @fcp_lun: FCP LUN of unit to be enqueued 268 * @fcp_lun: FCP LUN of unit to be enqueued
386 * Return: pointer to enqueued unit on success, NULL on error 269 * Returns: pointer to enqueued unit on success, ERR_PTR on error
387 * Locks: config_sema must be held to serialize changes to the unit list 270 * Locks: config_sema must be held to serialize changes to the unit list
388 * 271 *
389 * Sets up some unit internal structures and creates sysfs entry. 272 * Sets up some unit internal structures and creates sysfs entry.
390 */ 273 */
391struct zfcp_unit * 274struct zfcp_unit *zfcp_unit_enqueue(struct zfcp_port *port, fcp_lun_t fcp_lun)
392zfcp_unit_enqueue(struct zfcp_port *port, fcp_lun_t fcp_lun)
393{ 275{
394 struct zfcp_unit *unit; 276 struct zfcp_unit *unit;
395 277
396 /* 278 unit = kzalloc(sizeof(struct zfcp_unit), GFP_KERNEL);
397 * check that there is no unit with this FCP_LUN already in list
398 * and enqueue it.
399 * Note: Unlike for the adapter and the port, this is an error
400 */
401 read_lock_irq(&zfcp_data.config_lock);
402 unit = zfcp_get_unit_by_lun(port, fcp_lun);
403 read_unlock_irq(&zfcp_data.config_lock);
404 if (unit)
405 return NULL;
406
407 unit = kzalloc(sizeof (struct zfcp_unit), GFP_KERNEL);
408 if (!unit) 279 if (!unit)
409 return NULL; 280 return ERR_PTR(-ENOMEM);
410 281
411 /* initialise reference count stuff */
412 atomic_set(&unit->refcount, 0); 282 atomic_set(&unit->refcount, 0);
413 init_waitqueue_head(&unit->remove_wq); 283 init_waitqueue_head(&unit->remove_wq);
414 284
415 unit->port = port; 285 unit->port = port;
416 unit->fcp_lun = fcp_lun; 286 unit->fcp_lun = fcp_lun;
417 287
418 /* setup for sysfs registration */
419 snprintf(unit->sysfs_device.bus_id, BUS_ID_SIZE, "0x%016llx", fcp_lun); 288 snprintf(unit->sysfs_device.bus_id, BUS_ID_SIZE, "0x%016llx", fcp_lun);
420 unit->sysfs_device.parent = &port->sysfs_device; 289 unit->sysfs_device.parent = &port->sysfs_device;
421 unit->sysfs_device.release = zfcp_sysfs_unit_release; 290 unit->sysfs_device.release = zfcp_sysfs_unit_release;
@@ -432,14 +301,19 @@ zfcp_unit_enqueue(struct zfcp_port *port, fcp_lun_t fcp_lun)
432 unit->latencies.cmd.channel.min = 0xFFFFFFFF; 301 unit->latencies.cmd.channel.min = 0xFFFFFFFF;
433 unit->latencies.cmd.fabric.min = 0xFFFFFFFF; 302 unit->latencies.cmd.fabric.min = 0xFFFFFFFF;
434 303
435 if (device_register(&unit->sysfs_device)) { 304 read_lock_irq(&zfcp_data.config_lock);
436 kfree(unit); 305 if (zfcp_get_unit_by_lun(port, fcp_lun)) {
437 return NULL; 306 read_unlock_irq(&zfcp_data.config_lock);
307 goto err_out_free;
438 } 308 }
309 read_unlock_irq(&zfcp_data.config_lock);
310
311 if (device_register(&unit->sysfs_device))
312 goto err_out_free;
439 313
440 if (zfcp_sysfs_unit_create_files(&unit->sysfs_device)) { 314 if (zfcp_sysfs_unit_create_files(&unit->sysfs_device)) {
441 device_unregister(&unit->sysfs_device); 315 device_unregister(&unit->sysfs_device);
442 return NULL; 316 return ERR_PTR(-EIO);
443 } 317 }
444 318
445 zfcp_unit_get(unit); 319 zfcp_unit_get(unit);
@@ -449,16 +323,27 @@ zfcp_unit_enqueue(struct zfcp_port *port, fcp_lun_t fcp_lun)
449 list_add_tail(&unit->list, &port->unit_list_head); 323 list_add_tail(&unit->list, &port->unit_list_head);
450 atomic_clear_mask(ZFCP_STATUS_COMMON_REMOVE, &unit->status); 324 atomic_clear_mask(ZFCP_STATUS_COMMON_REMOVE, &unit->status);
451 atomic_set_mask(ZFCP_STATUS_COMMON_RUNNING, &unit->status); 325 atomic_set_mask(ZFCP_STATUS_COMMON_RUNNING, &unit->status);
326
452 write_unlock_irq(&zfcp_data.config_lock); 327 write_unlock_irq(&zfcp_data.config_lock);
453 328
454 port->units++; 329 port->units++;
455 zfcp_port_get(port); 330 zfcp_port_get(port);
456 331
457 return unit; 332 return unit;
333
334err_out_free:
335 kfree(unit);
336 return ERR_PTR(-EINVAL);
458} 337}
459 338
460void 339/**
461zfcp_unit_dequeue(struct zfcp_unit *unit) 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 */
346void zfcp_unit_dequeue(struct zfcp_unit *unit)
462{ 347{
463 zfcp_unit_wait(unit); 348 zfcp_unit_wait(unit);
464 write_lock_irq(&zfcp_data.config_lock); 349 write_lock_irq(&zfcp_data.config_lock);
@@ -470,64 +355,47 @@ zfcp_unit_dequeue(struct zfcp_unit *unit)
470 device_unregister(&unit->sysfs_device); 355 device_unregister(&unit->sysfs_device);
471} 356}
472 357
473/* 358static int zfcp_allocate_low_mem_buffers(struct zfcp_adapter *adapter)
474 * Allocates a combined QTCB/fsf_req buffer for erp actions and fcp/SCSI
475 * commands.
476 * It also genrates fcp-nameserver request/response buffer and unsolicited
477 * status read fsf_req buffers.
478 *
479 * locks: must only be called with zfcp_data.config_sema taken
480 */
481static int
482zfcp_allocate_low_mem_buffers(struct zfcp_adapter *adapter)
483{ 359{
360 /* must only be called with zfcp_data.config_sema taken */
484 adapter->pool.fsf_req_erp = 361 adapter->pool.fsf_req_erp =
485 mempool_create_slab_pool(ZFCP_POOL_FSF_REQ_ERP_NR, 362 mempool_create_slab_pool(1, zfcp_data.fsf_req_qtcb_cache);
486 zfcp_data.fsf_req_qtcb_cache);
487 if (!adapter->pool.fsf_req_erp) 363 if (!adapter->pool.fsf_req_erp)
488 return -ENOMEM; 364 return -ENOMEM;
489 365
490 adapter->pool.fsf_req_scsi = 366 adapter->pool.fsf_req_scsi =
491 mempool_create_slab_pool(ZFCP_POOL_FSF_REQ_SCSI_NR, 367 mempool_create_slab_pool(1, zfcp_data.fsf_req_qtcb_cache);
492 zfcp_data.fsf_req_qtcb_cache);
493 if (!adapter->pool.fsf_req_scsi) 368 if (!adapter->pool.fsf_req_scsi)
494 return -ENOMEM; 369 return -ENOMEM;
495 370
496 adapter->pool.fsf_req_abort = 371 adapter->pool.fsf_req_abort =
497 mempool_create_slab_pool(ZFCP_POOL_FSF_REQ_ABORT_NR, 372 mempool_create_slab_pool(1, zfcp_data.fsf_req_qtcb_cache);
498 zfcp_data.fsf_req_qtcb_cache);
499 if (!adapter->pool.fsf_req_abort) 373 if (!adapter->pool.fsf_req_abort)
500 return -ENOMEM; 374 return -ENOMEM;
501 375
502 adapter->pool.fsf_req_status_read = 376 adapter->pool.fsf_req_status_read =
503 mempool_create_kmalloc_pool(ZFCP_POOL_STATUS_READ_NR, 377 mempool_create_kmalloc_pool(FSF_STATUS_READS_RECOM,
504 sizeof(struct zfcp_fsf_req)); 378 sizeof(struct zfcp_fsf_req));
505 if (!adapter->pool.fsf_req_status_read) 379 if (!adapter->pool.fsf_req_status_read)
506 return -ENOMEM; 380 return -ENOMEM;
507 381
508 adapter->pool.data_status_read = 382 adapter->pool.data_status_read =
509 mempool_create_slab_pool(ZFCP_POOL_STATUS_READ_NR, 383 mempool_create_slab_pool(FSF_STATUS_READS_RECOM,
510 zfcp_data.sr_buffer_cache); 384 zfcp_data.sr_buffer_cache);
511 if (!adapter->pool.data_status_read) 385 if (!adapter->pool.data_status_read)
512 return -ENOMEM; 386 return -ENOMEM;
513 387
514 adapter->pool.data_gid_pn = 388 adapter->pool.data_gid_pn =
515 mempool_create_slab_pool(ZFCP_POOL_DATA_GID_PN_NR, 389 mempool_create_slab_pool(1, zfcp_data.gid_pn_cache);
516 zfcp_data.gid_pn_cache);
517 if (!adapter->pool.data_gid_pn) 390 if (!adapter->pool.data_gid_pn)
518 return -ENOMEM; 391 return -ENOMEM;
519 392
520 return 0; 393 return 0;
521} 394}
522 395
523/** 396static void zfcp_free_low_mem_buffers(struct zfcp_adapter *adapter)
524 * zfcp_free_low_mem_buffers - free memory pools of an adapter
525 * @adapter: pointer to zfcp_adapter for which memory pools should be freed
526 * locking: zfcp_data.config_sema must be held
527 */
528static void
529zfcp_free_low_mem_buffers(struct zfcp_adapter *adapter)
530{ 397{
398 /* zfcp_data.config_sema must be held */
531 if (adapter->pool.fsf_req_erp) 399 if (adapter->pool.fsf_req_erp)
532 mempool_destroy(adapter->pool.fsf_req_erp); 400 mempool_destroy(adapter->pool.fsf_req_erp);
533 if (adapter->pool.fsf_req_scsi) 401 if (adapter->pool.fsf_req_scsi)
@@ -547,6 +415,15 @@ static void zfcp_dummy_release(struct device *dev)
547 return; 415 return;
548} 416}
549 417
418/**
419 * zfcp_status_read_refill - refill the long running status_read_requests
420 * @adapter: ptr to struct zfcp_adapter for which the buffers should be refilled
421 *
422 * Returns: 0 on success, 1 otherwise
423 *
424 * if there are 16 or more status_read requests missing an adapter_reopen
425 * is triggered
426 */
550int zfcp_status_read_refill(struct zfcp_adapter *adapter) 427int zfcp_status_read_refill(struct zfcp_adapter *adapter)
551{ 428{
552 while (atomic_read(&adapter->stat_miss) > 0) 429 while (atomic_read(&adapter->stat_miss) > 0)
@@ -573,27 +450,25 @@ static int zfcp_nameserver_enqueue(struct zfcp_adapter *adapter)
573 450
574 port = zfcp_port_enqueue(adapter, 0, ZFCP_STATUS_PORT_WKA, 451 port = zfcp_port_enqueue(adapter, 0, ZFCP_STATUS_PORT_WKA,
575 ZFCP_DID_DIRECTORY_SERVICE); 452 ZFCP_DID_DIRECTORY_SERVICE);
576 if (!port) 453 if (IS_ERR(port))
577 return -ENXIO; 454 return PTR_ERR(port);
578 zfcp_port_put(port); 455 zfcp_port_put(port);
579 456
580 return 0; 457 return 0;
581} 458}
582 459
583/* 460/**
461 * zfcp_adapter_enqueue - enqueue a new adapter to the list
462 * @ccw_device: pointer to the struct cc_device
463 *
464 * Returns: 0 if a new adapter was successfully enqueued
465 * -ENOMEM if alloc failed
584 * Enqueues an adapter at the end of the adapter list in the driver data. 466 * Enqueues an adapter at the end of the adapter list in the driver data.
585 * All adapter internal structures are set up. 467 * All adapter internal structures are set up.
586 * Proc-fs entries are also created. 468 * Proc-fs entries are also created.
587 *
588 * FIXME: Use -ENOMEM as return code for allocation failures
589 *
590 * returns: 0 if a new adapter was successfully enqueued
591 * ZFCP_KNOWN if an adapter with this devno was already present
592 * -ENOMEM if alloc failed
593 * locks: config_sema must be held to serialise changes to the adapter list 469 * locks: config_sema must be held to serialise changes to the adapter list
594 */ 470 */
595struct zfcp_adapter * 471int zfcp_adapter_enqueue(struct ccw_device *ccw_device)
596zfcp_adapter_enqueue(struct ccw_device *ccw_device)
597{ 472{
598 struct zfcp_adapter *adapter; 473 struct zfcp_adapter *adapter;
599 474
@@ -602,15 +477,13 @@ zfcp_adapter_enqueue(struct ccw_device *ccw_device)
602 * are protected by the config_sema, which must be held to get here 477 * are protected by the config_sema, which must be held to get here
603 */ 478 */
604 479
605 /* try to allocate new adapter data structure (zeroed) */ 480 adapter = kzalloc(sizeof(struct zfcp_adapter), GFP_KERNEL);
606 adapter = kzalloc(sizeof (struct zfcp_adapter), GFP_KERNEL);
607 if (!adapter) 481 if (!adapter)
608 goto out; 482 return -ENOMEM;
609 483
610 ccw_device->handler = NULL; 484 ccw_device->handler = NULL;
611
612 /* save ccw_device pointer */
613 adapter->ccw_device = ccw_device; 485 adapter->ccw_device = ccw_device;
486 atomic_set(&adapter->refcount, 0);
614 487
615 if (zfcp_qdio_allocate(adapter)) 488 if (zfcp_qdio_allocate(adapter))
616 goto qdio_allocate_failed; 489 goto qdio_allocate_failed;
@@ -618,47 +491,34 @@ zfcp_adapter_enqueue(struct ccw_device *ccw_device)
618 if (zfcp_allocate_low_mem_buffers(adapter)) 491 if (zfcp_allocate_low_mem_buffers(adapter))
619 goto failed_low_mem_buffers; 492 goto failed_low_mem_buffers;
620 493
621 /* initialise reference count stuff */ 494 if (zfcp_reqlist_alloc(adapter))
622 atomic_set(&adapter->refcount, 0); 495 goto failed_low_mem_buffers;
496
497 if (zfcp_adapter_debug_register(adapter))
498 goto debug_register_failed;
499
623 init_waitqueue_head(&adapter->remove_wq); 500 init_waitqueue_head(&adapter->remove_wq);
501 init_waitqueue_head(&adapter->erp_thread_wqh);
502 init_waitqueue_head(&adapter->erp_done_wqh);
624 503
625 /* initialise list of ports */
626 INIT_LIST_HEAD(&adapter->port_list_head); 504 INIT_LIST_HEAD(&adapter->port_list_head);
627
628 /* initialise list of ports to be removed */
629 INIT_LIST_HEAD(&adapter->port_remove_lh); 505 INIT_LIST_HEAD(&adapter->port_remove_lh);
506 INIT_LIST_HEAD(&adapter->erp_ready_head);
507 INIT_LIST_HEAD(&adapter->erp_running_head);
630 508
631 /* initialize list of fsf requests */
632 spin_lock_init(&adapter->req_list_lock); 509 spin_lock_init(&adapter->req_list_lock);
633 if (zfcp_reqlist_alloc(adapter))
634 goto failed_low_mem_buffers;
635
636 /* initialize debug locks */
637 510
638 spin_lock_init(&adapter->hba_dbf_lock); 511 spin_lock_init(&adapter->hba_dbf_lock);
639 spin_lock_init(&adapter->san_dbf_lock); 512 spin_lock_init(&adapter->san_dbf_lock);
640 spin_lock_init(&adapter->scsi_dbf_lock); 513 spin_lock_init(&adapter->scsi_dbf_lock);
641 spin_lock_init(&adapter->rec_dbf_lock); 514 spin_lock_init(&adapter->rec_dbf_lock);
642 515
643 if (zfcp_adapter_debug_register(adapter))
644 goto debug_register_failed;
645
646 /* initialize error recovery stuff */
647
648 rwlock_init(&adapter->erp_lock); 516 rwlock_init(&adapter->erp_lock);
649 sema_init(&adapter->erp_ready_sem, 0);
650 INIT_LIST_HEAD(&adapter->erp_ready_head);
651 INIT_LIST_HEAD(&adapter->erp_running_head);
652
653 /* initialize abort lock */
654 rwlock_init(&adapter->abort_lock); 517 rwlock_init(&adapter->abort_lock);
518 rwlock_init(&adapter->req_q.lock);
655 519
656 /* initialise some erp stuff */ 520 sema_init(&adapter->erp_ready_sem, 0);
657 init_waitqueue_head(&adapter->erp_thread_wqh);
658 init_waitqueue_head(&adapter->erp_done_wqh);
659 521
660 /* initialize lock of associated request queue */
661 rwlock_init(&adapter->req_q.lock);
662 INIT_WORK(&adapter->stat_work, _zfcp_status_read_scheduler); 522 INIT_WORK(&adapter->stat_work, _zfcp_status_read_scheduler);
663 INIT_WORK(&adapter->scan_work, _zfcp_scan_ports_later); 523 INIT_WORK(&adapter->scan_work, _zfcp_scan_ports_later);
664 524
@@ -678,7 +538,6 @@ zfcp_adapter_enqueue(struct ccw_device *ccw_device)
678 if (device_register(&adapter->generic_services)) 538 if (device_register(&adapter->generic_services))
679 goto generic_services_failed; 539 goto generic_services_failed;
680 540
681 /* put allocated adapter at list tail */
682 write_lock_irq(&zfcp_data.config_lock); 541 write_lock_irq(&zfcp_data.config_lock);
683 atomic_clear_mask(ZFCP_STATUS_COMMON_REMOVE, &adapter->status); 542 atomic_clear_mask(ZFCP_STATUS_COMMON_REMOVE, &adapter->status);
684 list_add_tail(&adapter->list, &zfcp_data.adapter_list_head); 543 list_add_tail(&adapter->list, &zfcp_data.adapter_list_head);
@@ -688,33 +547,29 @@ zfcp_adapter_enqueue(struct ccw_device *ccw_device)
688 547
689 zfcp_nameserver_enqueue(adapter); 548 zfcp_nameserver_enqueue(adapter);
690 549
691 goto out; 550 return 0;
692 551
693 generic_services_failed: 552generic_services_failed:
694 zfcp_sysfs_adapter_remove_files(&adapter->ccw_device->dev); 553 zfcp_sysfs_adapter_remove_files(&adapter->ccw_device->dev);
695 sysfs_failed: 554sysfs_failed:
696 zfcp_adapter_debug_unregister(adapter); 555 zfcp_adapter_debug_unregister(adapter);
697 debug_register_failed: 556debug_register_failed:
698 dev_set_drvdata(&ccw_device->dev, NULL); 557 dev_set_drvdata(&ccw_device->dev, NULL);
699 zfcp_reqlist_free(adapter); 558 kfree(adapter->req_list);
700 failed_low_mem_buffers: 559failed_low_mem_buffers:
701 zfcp_free_low_mem_buffers(adapter); 560 zfcp_free_low_mem_buffers(adapter);
702 qdio_allocate_failed: 561qdio_allocate_failed:
703 zfcp_qdio_free(adapter); 562 zfcp_qdio_free(adapter);
704 kfree(adapter); 563 kfree(adapter);
705 adapter = NULL; 564 return -ENOMEM;
706 out:
707 return adapter;
708} 565}
709 566
710/* 567/**
711 * returns: 0 - struct zfcp_adapter data structure successfully removed 568 * zfcp_adapter_dequeue - remove the adapter from the resource list
712 * !0 - struct zfcp_adapter data structure could not be removed 569 * @adapter: pointer to struct zfcp_adapter which should be removed
713 * (e.g. still used)
714 * locks: adapter list write lock is assumed to be held by caller 570 * locks: adapter list write lock is assumed to be held by caller
715 */ 571 */
716void 572void zfcp_adapter_dequeue(struct zfcp_adapter *adapter)
717zfcp_adapter_dequeue(struct zfcp_adapter *adapter)
718{ 573{
719 int retval = 0; 574 int retval = 0;
720 unsigned long flags; 575 unsigned long flags;
@@ -729,10 +584,8 @@ zfcp_adapter_dequeue(struct zfcp_adapter *adapter)
729 spin_lock_irqsave(&adapter->req_list_lock, flags); 584 spin_lock_irqsave(&adapter->req_list_lock, flags);
730 retval = zfcp_reqlist_isempty(adapter); 585 retval = zfcp_reqlist_isempty(adapter);
731 spin_unlock_irqrestore(&adapter->req_list_lock, flags); 586 spin_unlock_irqrestore(&adapter->req_list_lock, flags);
732 if (!retval) { 587 if (!retval)
733 retval = -EBUSY; 588 return;
734 goto out;
735 }
736 589
737 zfcp_adapter_debug_unregister(adapter); 590 zfcp_adapter_debug_unregister(adapter);
738 591
@@ -747,12 +600,10 @@ zfcp_adapter_dequeue(struct zfcp_adapter *adapter)
747 zfcp_qdio_free(adapter); 600 zfcp_qdio_free(adapter);
748 601
749 zfcp_free_low_mem_buffers(adapter); 602 zfcp_free_low_mem_buffers(adapter);
750 zfcp_reqlist_free(adapter); 603 kfree(adapter->req_list);
751 kfree(adapter->fc_stats); 604 kfree(adapter->fc_stats);
752 kfree(adapter->stats_reset_data); 605 kfree(adapter->stats_reset_data);
753 kfree(adapter); 606 kfree(adapter);
754 out:
755 return;
756} 607}
757 608
758/** 609/**
@@ -761,77 +612,58 @@ zfcp_adapter_dequeue(struct zfcp_adapter *adapter)
761 * @wwpn: WWPN of the remote port to be enqueued 612 * @wwpn: WWPN of the remote port to be enqueued
762 * @status: initial status for the port 613 * @status: initial status for the port
763 * @d_id: destination id of the remote port to be enqueued 614 * @d_id: destination id of the remote port to be enqueued
764 * Return: pointer to enqueued port on success, NULL on error 615 * Returns: pointer to enqueued port on success, ERR_PTR on error
765 * Locks: config_sema must be held to serialize changes to the port list 616 * Locks: config_sema must be held to serialize changes to the port list
766 * 617 *
767 * All port internal structures are set up and the sysfs entry is generated. 618 * All port internal structures are set up and the sysfs entry is generated.
768 * d_id is used to enqueue ports with a well known address like the Directory 619 * d_id is used to enqueue ports with a well known address like the Directory
769 * Service for nameserver lookup. 620 * Service for nameserver lookup.
770 */ 621 */
771struct zfcp_port * 622struct zfcp_port *zfcp_port_enqueue(struct zfcp_adapter *adapter, wwn_t wwpn,
772zfcp_port_enqueue(struct zfcp_adapter *adapter, wwn_t wwpn, u32 status, 623 u32 status, u32 d_id)
773 u32 d_id)
774{ 624{
775 struct zfcp_port *port; 625 struct zfcp_port *port;
776 int check_wwpn; 626 char *bus_id;
777 627
778 check_wwpn = !(status & ZFCP_STATUS_PORT_NO_WWPN); 628 port = kzalloc(sizeof(struct zfcp_port), GFP_KERNEL);
779 /*
780 * check that there is no port with this WWPN already in list
781 */
782 if (check_wwpn) {
783 read_lock_irq(&zfcp_data.config_lock);
784 port = zfcp_get_port_by_wwpn(adapter, wwpn);
785 read_unlock_irq(&zfcp_data.config_lock);
786 if (port)
787 return NULL;
788 }
789
790 port = kzalloc(sizeof (struct zfcp_port), GFP_KERNEL);
791 if (!port) 629 if (!port)
792 return NULL; 630 return ERR_PTR(-ENOMEM);
793 631
794 /* initialise reference count stuff */
795 atomic_set(&port->refcount, 0);
796 init_waitqueue_head(&port->remove_wq); 632 init_waitqueue_head(&port->remove_wq);
797 633
798 INIT_LIST_HEAD(&port->unit_list_head); 634 INIT_LIST_HEAD(&port->unit_list_head);
799 INIT_LIST_HEAD(&port->unit_remove_lh); 635 INIT_LIST_HEAD(&port->unit_remove_lh);
800 636
801 port->adapter = adapter; 637 port->adapter = adapter;
638 port->d_id = d_id;
639 port->wwpn = wwpn;
802 640
803 if (check_wwpn) 641 /* mark port unusable as long as sysfs registration is not complete */
804 port->wwpn = wwpn; 642 atomic_set_mask(status | ZFCP_STATUS_COMMON_REMOVE, &port->status);
805 643 atomic_set(&port->refcount, 0);
806 atomic_set_mask(status, &port->status);
807 644
808 /* setup for sysfs registration */
809 if (status & ZFCP_STATUS_PORT_WKA) { 645 if (status & ZFCP_STATUS_PORT_WKA) {
810 switch (d_id) { 646 switch (d_id) {
811 case ZFCP_DID_DIRECTORY_SERVICE: 647 case ZFCP_DID_DIRECTORY_SERVICE:
812 snprintf(port->sysfs_device.bus_id, BUS_ID_SIZE, 648 bus_id = "directory";
813 "directory");
814 break; 649 break;
815 case ZFCP_DID_MANAGEMENT_SERVICE: 650 case ZFCP_DID_MANAGEMENT_SERVICE:
816 snprintf(port->sysfs_device.bus_id, BUS_ID_SIZE, 651 bus_id = "management";
817 "management");
818 break; 652 break;
819 case ZFCP_DID_KEY_DISTRIBUTION_SERVICE: 653 case ZFCP_DID_KEY_DISTRIBUTION_SERVICE:
820 snprintf(port->sysfs_device.bus_id, BUS_ID_SIZE, 654 bus_id = "key_distribution";
821 "key_distribution");
822 break; 655 break;
823 case ZFCP_DID_ALIAS_SERVICE: 656 case ZFCP_DID_ALIAS_SERVICE:
824 snprintf(port->sysfs_device.bus_id, BUS_ID_SIZE, 657 bus_id = "alias";
825 "alias");
826 break; 658 break;
827 case ZFCP_DID_TIME_SERVICE: 659 case ZFCP_DID_TIME_SERVICE:
828 snprintf(port->sysfs_device.bus_id, BUS_ID_SIZE, 660 bus_id = "time";
829 "time");
830 break; 661 break;
831 default: 662 default:
832 kfree(port); 663 kfree(port);
833 return NULL; 664 return ERR_PTR(-EINVAL);
834 } 665 }
666 snprintf(port->sysfs_device.bus_id, BUS_ID_SIZE, "%s", bus_id);
835 port->sysfs_device.parent = &adapter->generic_services; 667 port->sysfs_device.parent = &adapter->generic_services;
836 } else { 668 } else {
837 snprintf(port->sysfs_device.bus_id, 669 snprintf(port->sysfs_device.bus_id,
@@ -839,22 +671,23 @@ zfcp_port_enqueue(struct zfcp_adapter *adapter, wwn_t wwpn, u32 status,
839 port->sysfs_device.parent = &adapter->ccw_device->dev; 671 port->sysfs_device.parent = &adapter->ccw_device->dev;
840 } 672 }
841 673
842 port->d_id = d_id;
843
844 port->sysfs_device.release = zfcp_sysfs_port_release; 674 port->sysfs_device.release = zfcp_sysfs_port_release;
845 dev_set_drvdata(&port->sysfs_device, port); 675 dev_set_drvdata(&port->sysfs_device, port);
846 676
847 /* mark port unusable as long as sysfs registration is not complete */ 677 read_lock_irq(&zfcp_data.config_lock);
848 atomic_set_mask(ZFCP_STATUS_COMMON_REMOVE, &port->status); 678 if (!(status & ZFCP_STATUS_PORT_NO_WWPN))
679 if (zfcp_get_port_by_wwpn(adapter, wwpn)) {
680 read_unlock_irq(&zfcp_data.config_lock);
681 goto err_out_free;
682 }
683 read_unlock_irq(&zfcp_data.config_lock);
849 684
850 if (device_register(&port->sysfs_device)) { 685 if (device_register(&port->sysfs_device))
851 kfree(port); 686 goto err_out_free;
852 return NULL;
853 }
854 687
855 if (zfcp_sysfs_port_create_files(&port->sysfs_device, status)) { 688 if (zfcp_sysfs_port_create_files(&port->sysfs_device, status)) {
856 device_unregister(&port->sysfs_device); 689 device_unregister(&port->sysfs_device);
857 return NULL; 690 goto err_out;
858 } 691 }
859 692
860 zfcp_port_get(port); 693 zfcp_port_get(port);
@@ -867,15 +700,23 @@ zfcp_port_enqueue(struct zfcp_adapter *adapter, wwn_t wwpn, u32 status,
867 if (!adapter->nameserver_port) 700 if (!adapter->nameserver_port)
868 adapter->nameserver_port = port; 701 adapter->nameserver_port = port;
869 adapter->ports++; 702 adapter->ports++;
703
870 write_unlock_irq(&zfcp_data.config_lock); 704 write_unlock_irq(&zfcp_data.config_lock);
871 705
872 zfcp_adapter_get(adapter); 706 zfcp_adapter_get(adapter);
873
874 return port; 707 return port;
708
709err_out_free:
710 kfree(port);
711err_out:
712 return ERR_PTR(-EINVAL);
875} 713}
876 714
877void 715/**
878zfcp_port_dequeue(struct zfcp_port *port) 716 * zfcp_port_dequeue - dequeues a port from the port list of the adapter
717 * @port: pointer to struct zfcp_port which should be removed
718 */
719void zfcp_port_dequeue(struct zfcp_port *port)
879{ 720{
880 zfcp_port_wait(port); 721 zfcp_port_wait(port);
881 write_lock_irq(&zfcp_data.config_lock); 722 write_lock_irq(&zfcp_data.config_lock);
@@ -891,6 +732,12 @@ zfcp_port_dequeue(struct zfcp_port *port)
891 device_unregister(&port->sysfs_device); 732 device_unregister(&port->sysfs_device);
892} 733}
893 734
735/**
736 * zfcp_sg_free_table - free memory used by scatterlists
737 * @sg: pointer to scatterlist
738 * @count: number of scatterlist which are to be free'ed
739 * the scatterlist are expected to reference pages always
740 */
894void zfcp_sg_free_table(struct scatterlist *sg, int count) 741void zfcp_sg_free_table(struct scatterlist *sg, int count)
895{ 742{
896 int i; 743 int i;
@@ -902,6 +749,14 @@ void zfcp_sg_free_table(struct scatterlist *sg, int count)
902 break; 749 break;
903} 750}
904 751
752/**
753 * zfcp_sg_setup_table - init scatterlist and allocate, assign buffers
754 * @sg: pointer to struct scatterlist
755 * @count: number of scatterlists which should be assigned with buffers
756 * of size page
757 *
758 * Returns: 0 on success, -ENOMEM otherwise
759 */
905int zfcp_sg_setup_table(struct scatterlist *sg, int count) 760int zfcp_sg_setup_table(struct scatterlist *sg, int count)
906{ 761{
907 void *addr; 762 void *addr;
diff --git a/drivers/s390/scsi/zfcp_ccw.c b/drivers/s390/scsi/zfcp_ccw.c
index da472e865e58..391dd29749f8 100644
--- a/drivers/s390/scsi/zfcp_ccw.c
+++ b/drivers/s390/scsi/zfcp_ccw.c
@@ -20,12 +20,10 @@
20 */ 20 */
21static int zfcp_ccw_probe(struct ccw_device *ccw_device) 21static int zfcp_ccw_probe(struct ccw_device *ccw_device)
22{ 22{
23 struct zfcp_adapter *adapter;
24 int retval = 0; 23 int retval = 0;
25 24
26 down(&zfcp_data.config_sema); 25 down(&zfcp_data.config_sema);
27 adapter = zfcp_adapter_enqueue(ccw_device); 26 if (zfcp_adapter_enqueue(ccw_device)) {
28 if (!adapter) {
29 dev_err(&ccw_device->dev, 27 dev_err(&ccw_device->dev,
30 "Setup of data structures failed.\n"); 28 "Setup of data structures failed.\n");
31 retval = -EINVAL; 29 retval = -EINVAL;
diff --git a/drivers/s390/scsi/zfcp_def.h b/drivers/s390/scsi/zfcp_def.h
index 7ac830c39098..d69d280359da 100644
--- a/drivers/s390/scsi/zfcp_def.h
+++ b/drivers/s390/scsi/zfcp_def.h
@@ -730,13 +730,6 @@ struct zfcp_data {
730 struct kmem_cache *gid_pn_cache; 730 struct kmem_cache *gid_pn_cache;
731}; 731};
732 732
733/* number of elements for various memory pools */
734#define ZFCP_POOL_FSF_REQ_ERP_NR 1
735#define ZFCP_POOL_FSF_REQ_SCSI_NR 1
736#define ZFCP_POOL_FSF_REQ_ABORT_NR 1
737#define ZFCP_POOL_STATUS_READ_NR FSF_STATUS_READS_RECOM
738#define ZFCP_POOL_DATA_GID_PN_NR 1
739
740/* struct used by memory pools for fsf_requests */ 733/* struct used by memory pools for fsf_requests */
741struct zfcp_fsf_req_qtcb { 734struct zfcp_fsf_req_qtcb {
742 struct zfcp_fsf_req fsf_req; 735 struct zfcp_fsf_req fsf_req;
@@ -757,12 +750,6 @@ struct zfcp_fsf_req_qtcb {
757 ((atomic_read(target) & mask) == mask) 750 ((atomic_read(target) & mask) == mask)
758#endif 751#endif
759 752
760extern void _zfcp_hex_dump(char *, int);
761#define ZFCP_HEX_DUMP(level, addr, count) \
762 if (ZFCP_LOG_CHECK(level)) { \
763 _zfcp_hex_dump(addr, count); \
764 }
765
766#define zfcp_get_busid_by_adapter(adapter) (adapter->ccw_device->dev.bus_id) 753#define zfcp_get_busid_by_adapter(adapter) (adapter->ccw_device->dev.bus_id)
767#define zfcp_get_busid_by_port(port) (zfcp_get_busid_by_adapter(port->adapter)) 754#define zfcp_get_busid_by_port(port) (zfcp_get_busid_by_adapter(port->adapter))
768#define zfcp_get_busid_by_unit(unit) (zfcp_get_busid_by_port(unit->port)) 755#define zfcp_get_busid_by_unit(unit) (zfcp_get_busid_by_port(unit->port))
diff --git a/drivers/s390/scsi/zfcp_erp.c b/drivers/s390/scsi/zfcp_erp.c
index 9b9c999cf39f..4d797e5264d9 100644
--- a/drivers/s390/scsi/zfcp_erp.c
+++ b/drivers/s390/scsi/zfcp_erp.c
@@ -1675,7 +1675,7 @@ static void zfcp_erp_open_ptp_port(struct zfcp_adapter *adapter)
1675 struct zfcp_port *port; 1675 struct zfcp_port *port;
1676 port = zfcp_port_enqueue(adapter, adapter->peer_wwpn, 0, 1676 port = zfcp_port_enqueue(adapter, adapter->peer_wwpn, 0,
1677 adapter->peer_d_id); 1677 adapter->peer_d_id);
1678 if (!port) /* error or port already attached */ 1678 if (IS_ERR(port)) /* error or port already attached */
1679 return; 1679 return;
1680 zfcp_erp_port_reopen_internal(port, 0, 150, NULL); 1680 zfcp_erp_port_reopen_internal(port, 0, 150, NULL);
1681} 1681}
diff --git a/drivers/s390/scsi/zfcp_ext.h b/drivers/s390/scsi/zfcp_ext.h
index 892476c17ff2..9caa081e52ed 100644
--- a/drivers/s390/scsi/zfcp_ext.h
+++ b/drivers/s390/scsi/zfcp_ext.h
@@ -26,9 +26,7 @@ extern void zfcp_sysfs_unit_release(struct device *);
26/**************************** CONFIGURATION *********************************/ 26/**************************** CONFIGURATION *********************************/
27extern struct zfcp_unit *zfcp_get_unit_by_lun(struct zfcp_port *, fcp_lun_t); 27extern struct zfcp_unit *zfcp_get_unit_by_lun(struct zfcp_port *, fcp_lun_t);
28extern struct zfcp_port *zfcp_get_port_by_wwpn(struct zfcp_adapter *, wwn_t); 28extern struct zfcp_port *zfcp_get_port_by_wwpn(struct zfcp_adapter *, wwn_t);
29extern struct zfcp_port *zfcp_get_port_by_did(struct zfcp_adapter *, u32); 29extern int zfcp_adapter_enqueue(struct ccw_device *);
30struct zfcp_adapter *zfcp_get_adapter_by_busid(char *);
31extern struct zfcp_adapter *zfcp_adapter_enqueue(struct ccw_device *);
32extern int zfcp_adapter_debug_register(struct zfcp_adapter *); 30extern int zfcp_adapter_debug_register(struct zfcp_adapter *);
33extern void zfcp_adapter_dequeue(struct zfcp_adapter *); 31extern void zfcp_adapter_dequeue(struct zfcp_adapter *);
34extern void zfcp_adapter_debug_unregister(struct zfcp_adapter *); 32extern void zfcp_adapter_debug_unregister(struct zfcp_adapter *);
diff --git a/drivers/s390/scsi/zfcp_fc.c b/drivers/s390/scsi/zfcp_fc.c
index 5d9367d9a12d..fbe2c76df4d7 100644
--- a/drivers/s390/scsi/zfcp_fc.c
+++ b/drivers/s390/scsi/zfcp_fc.c
@@ -39,6 +39,18 @@ struct zfcp_gpn_ft {
39 struct scatterlist sg_resp[ZFCP_GPN_FT_BUFFERS]; 39 struct scatterlist sg_resp[ZFCP_GPN_FT_BUFFERS];
40}; 40};
41 41
42static struct zfcp_port *zfcp_get_port_by_did(struct zfcp_adapter *adapter,
43 u32 d_id)
44{
45 struct zfcp_port *port;
46
47 list_for_each_entry(port, &adapter->port_list_head, list)
48 if ((port->d_id == d_id) &&
49 !atomic_test_mask(ZFCP_STATUS_COMMON_REMOVE, &port->status))
50 return port;
51 return NULL;
52}
53
42static void _zfcp_fc_incoming_rscn(struct zfcp_fsf_req *fsf_req, u32 range, 54static void _zfcp_fc_incoming_rscn(struct zfcp_fsf_req *fsf_req, u32 range,
43 struct fcp_rscn_element *elem) 55 struct fcp_rscn_element *elem)
44{ 56{
@@ -496,10 +508,10 @@ static int zfcp_scan_eval_gpn_ft(struct zfcp_gpn_ft *gpn_ft)
496 port = zfcp_port_enqueue(adapter, acc->wwpn, 508 port = zfcp_port_enqueue(adapter, acc->wwpn,
497 ZFCP_STATUS_PORT_DID_DID | 509 ZFCP_STATUS_PORT_DID_DID |
498 ZFCP_STATUS_COMMON_NOESC, d_id); 510 ZFCP_STATUS_COMMON_NOESC, d_id);
499 if (port) 511 if (IS_ERR(port))
500 zfcp_erp_port_reopen(port, 0, 149, NULL); 512 ret = PTR_ERR(port);
501 else 513 else
502 ret = -ENOMEM; 514 zfcp_erp_port_reopen(port, 0, 149, NULL);
503 if (acc->control & 0x80) /* last entry */ 515 if (acc->control & 0x80) /* last entry */
504 break; 516 break;
505 } 517 }
diff --git a/drivers/s390/scsi/zfcp_sysfs_port.c b/drivers/s390/scsi/zfcp_sysfs_port.c
index 438675f2978e..e183ff8bdb2a 100644
--- a/drivers/s390/scsi/zfcp_sysfs_port.c
+++ b/drivers/s390/scsi/zfcp_sysfs_port.c
@@ -74,7 +74,7 @@ zfcp_sysfs_unit_add_store(struct device *dev, struct device_attribute *attr, con
74 goto out; 74 goto out;
75 75
76 unit = zfcp_unit_enqueue(port, fcp_lun); 76 unit = zfcp_unit_enqueue(port, fcp_lun);
77 if (!unit) 77 if (IS_ERR(unit))
78 goto out; 78 goto out;
79 79
80 retval = 0; 80 retval = 0;