zfcp_aux.c (57c237731b92fadc7d44824276313ec330b1989b) zfcp_aux.c (1daa4eb50fa5cd4c8f9c55452606e786fd42053b)
1/*
2 * zfcp device driver
3 *
4 * Module interface and handling of zfcp data structures.
5 *
6 * Copyright IBM Corporation 2002, 2010
7 */
8

--- 42 unchanged lines hidden (view full) ---

51 return kmem_cache_create(name, size, roundup_pow_of_two(size), 0, NULL);
52}
53
54static void __init zfcp_init_device_configure(char *busid, u64 wwpn, u64 lun)
55{
56 struct ccw_device *cdev;
57 struct zfcp_adapter *adapter;
58 struct zfcp_port *port;
1/*
2 * zfcp device driver
3 *
4 * Module interface and handling of zfcp data structures.
5 *
6 * Copyright IBM Corporation 2002, 2010
7 */
8

--- 42 unchanged lines hidden (view full) ---

51 return kmem_cache_create(name, size, roundup_pow_of_two(size), 0, NULL);
52}
53
54static void __init zfcp_init_device_configure(char *busid, u64 wwpn, u64 lun)
55{
56 struct ccw_device *cdev;
57 struct zfcp_adapter *adapter;
58 struct zfcp_port *port;
59 struct zfcp_unit *unit;
60
61 cdev = get_ccwdev_by_busid(&zfcp_ccw_driver, busid);
62 if (!cdev)
63 return;
64
65 if (ccw_device_set_online(cdev))
66 goto out_ccw_device;
67
68 adapter = zfcp_ccw_adapter_by_cdev(cdev);
69 if (!adapter)
70 goto out_ccw_device;
71
72 port = zfcp_get_port_by_wwpn(adapter, wwpn);
73 if (!port)
74 goto out_port;
59
60 cdev = get_ccwdev_by_busid(&zfcp_ccw_driver, busid);
61 if (!cdev)
62 return;
63
64 if (ccw_device_set_online(cdev))
65 goto out_ccw_device;
66
67 adapter = zfcp_ccw_adapter_by_cdev(cdev);
68 if (!adapter)
69 goto out_ccw_device;
70
71 port = zfcp_get_port_by_wwpn(adapter, wwpn);
72 if (!port)
73 goto out_port;
75
76 flush_work(&port->rport_work);
74 flush_work(&port->rport_work);
77 unit = zfcp_unit_enqueue(port, lun);
78 if (IS_ERR(unit))
79 goto out_unit;
80
75
81 zfcp_erp_unit_reopen(unit, 0, "auidc_1", NULL);
82 zfcp_erp_wait(adapter);
83 zfcp_scsi_scan(unit);
84
85out_unit:
76 zfcp_unit_add(port, lun);
86 put_device(&port->dev);
77 put_device(&port->dev);
78
87out_port:
88 zfcp_ccw_adapter_put(adapter);
89out_ccw_device:
90 put_device(&cdev->dev);
91 return;
92}
93
94static void __init zfcp_init_device_setup(char *devstr)

--- 115 unchanged lines hidden (view full) ---

210 kmem_cache_destroy(zfcp_data.sr_buffer_cache);
211 kmem_cache_destroy(zfcp_data.qtcb_cache);
212 kmem_cache_destroy(zfcp_data.gpn_ft_cache);
213}
214
215module_exit(zfcp_module_exit);
216
217/**
79out_port:
80 zfcp_ccw_adapter_put(adapter);
81out_ccw_device:
82 put_device(&cdev->dev);
83 return;
84}
85
86static void __init zfcp_init_device_setup(char *devstr)

--- 115 unchanged lines hidden (view full) ---

202 kmem_cache_destroy(zfcp_data.sr_buffer_cache);
203 kmem_cache_destroy(zfcp_data.qtcb_cache);
204 kmem_cache_destroy(zfcp_data.gpn_ft_cache);
205}
206
207module_exit(zfcp_module_exit);
208
209/**
218 * zfcp_get_unit_by_lun - find unit in unit list of port by FCP LUN
219 * @port: pointer to port to search for unit
220 * @fcp_lun: FCP LUN to search for
221 *
222 * Returns: pointer to zfcp_unit or NULL
223 */
224struct zfcp_unit *zfcp_get_unit_by_lun(struct zfcp_port *port, u64 fcp_lun)
225{
226 unsigned long flags;
227 struct zfcp_unit *unit;
228
229 read_lock_irqsave(&port->unit_list_lock, flags);
230 list_for_each_entry(unit, &port->unit_list, list)
231 if (unit->fcp_lun == fcp_lun) {
232 if (!get_device(&unit->dev))
233 unit = NULL;
234 read_unlock_irqrestore(&port->unit_list_lock, flags);
235 return unit;
236 }
237 read_unlock_irqrestore(&port->unit_list_lock, flags);
238 return NULL;
239}
240
241/**
242 * zfcp_get_port_by_wwpn - find port in port list of adapter by wwpn
243 * @adapter: pointer to adapter to search for port
244 * @wwpn: wwpn to search for
245 *
246 * Returns: pointer to zfcp_port or NULL
247 */
248struct zfcp_port *zfcp_get_port_by_wwpn(struct zfcp_adapter *adapter,
249 u64 wwpn)

--- 8 unchanged lines hidden (view full) ---

258 port = NULL;
259 read_unlock_irqrestore(&adapter->port_list_lock, flags);
260 return port;
261 }
262 read_unlock_irqrestore(&adapter->port_list_lock, flags);
263 return NULL;
264}
265
210 * zfcp_get_port_by_wwpn - find port in port list of adapter by wwpn
211 * @adapter: pointer to adapter to search for port
212 * @wwpn: wwpn to search for
213 *
214 * Returns: pointer to zfcp_port or NULL
215 */
216struct zfcp_port *zfcp_get_port_by_wwpn(struct zfcp_adapter *adapter,
217 u64 wwpn)

--- 8 unchanged lines hidden (view full) ---

226 port = NULL;
227 read_unlock_irqrestore(&adapter->port_list_lock, flags);
228 return port;
229 }
230 read_unlock_irqrestore(&adapter->port_list_lock, flags);
231 return NULL;
232}
233
266/**
267 * zfcp_unit_release - dequeue unit
268 * @dev: pointer to device
269 *
270 * waits until all work is done on unit and removes it then from the unit->list
271 * of the associated port.
272 */
273static void zfcp_unit_release(struct device *dev)
274{
275 struct zfcp_unit *unit = container_of(dev, struct zfcp_unit, dev);
276
277 put_device(&unit->port->dev);
278 kfree(unit);
279}
280
281/**
282 * zfcp_unit_enqueue - enqueue unit to unit list of a port.
283 * @port: pointer to port where unit is added
284 * @fcp_lun: FCP LUN of unit to be enqueued
285 * Returns: pointer to enqueued unit on success, ERR_PTR on error
286 *
287 * Sets up some unit internal structures and creates sysfs entry.
288 */
289struct zfcp_unit *zfcp_unit_enqueue(struct zfcp_port *port, u64 fcp_lun)
290{
291 struct zfcp_unit *unit;
292 int retval = -ENOMEM;
293
294 get_device(&port->dev);
295
296 unit = zfcp_get_unit_by_lun(port, fcp_lun);
297 if (unit) {
298 put_device(&unit->dev);
299 retval = -EEXIST;
300 goto err_out;
301 }
302
303 unit = kzalloc(sizeof(struct zfcp_unit), GFP_KERNEL);
304 if (!unit)
305 goto err_out;
306
307 unit->port = port;
308 unit->fcp_lun = fcp_lun;
309 unit->dev.parent = &port->dev;
310 unit->dev.release = zfcp_unit_release;
311
312 if (dev_set_name(&unit->dev, "0x%016llx",
313 (unsigned long long) fcp_lun)) {
314 kfree(unit);
315 goto err_out;
316 }
317 retval = -EINVAL;
318
319 INIT_WORK(&unit->scsi_work, zfcp_scsi_scan_work);
320
321 spin_lock_init(&unit->latencies.lock);
322 unit->latencies.write.channel.min = 0xFFFFFFFF;
323 unit->latencies.write.fabric.min = 0xFFFFFFFF;
324 unit->latencies.read.channel.min = 0xFFFFFFFF;
325 unit->latencies.read.fabric.min = 0xFFFFFFFF;
326 unit->latencies.cmd.channel.min = 0xFFFFFFFF;
327 unit->latencies.cmd.fabric.min = 0xFFFFFFFF;
328
329 if (device_register(&unit->dev)) {
330 put_device(&unit->dev);
331 goto err_out;
332 }
333
334 if (sysfs_create_group(&unit->dev.kobj, &zfcp_sysfs_unit_attrs))
335 goto err_out_put;
336
337 write_lock_irq(&port->unit_list_lock);
338 list_add_tail(&unit->list, &port->unit_list);
339 write_unlock_irq(&port->unit_list_lock);
340
341 atomic_set_mask(ZFCP_STATUS_COMMON_RUNNING, &unit->status);
342
343 return unit;
344
345err_out_put:
346 device_unregister(&unit->dev);
347err_out:
348 put_device(&port->dev);
349 return ERR_PTR(retval);
350}
351
352static int zfcp_allocate_low_mem_buffers(struct zfcp_adapter *adapter)
353{
354 adapter->pool.erp_req =
355 mempool_create_kmalloc_pool(1, sizeof(struct zfcp_fsf_req));
356 if (!adapter->pool.erp_req)
357 return -ENOMEM;
358
359 adapter->pool.gid_pn_req =

--- 385 unchanged lines hidden ---
234static int zfcp_allocate_low_mem_buffers(struct zfcp_adapter *adapter)
235{
236 adapter->pool.erp_req =
237 mempool_create_kmalloc_pool(1, sizeof(struct zfcp_fsf_req));
238 if (!adapter->pool.erp_req)
239 return -ENOMEM;
240
241 adapter->pool.gid_pn_req =

--- 385 unchanged lines hidden ---