]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - drivers/scsi/fnic/fnic_main.c
fnic: Failing to queue aborts due to Q full cause terminate driver timeout
[mirror_ubuntu-bionic-kernel.git] / drivers / scsi / fnic / fnic_main.c
CommitLineData
5df6d737
AJ
1/*
2 * Copyright 2008 Cisco Systems, Inc. All rights reserved.
3 * Copyright 2007 Nuova Systems, Inc. All rights reserved.
4 *
5 * This program is free software; you may redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; version 2 of the License.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
10 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
11 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
12 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
13 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
14 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
15 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
16 * SOFTWARE.
17 */
18#include <linux/module.h>
19#include <linux/mempool.h>
20#include <linux/string.h>
5a0e3ad6 21#include <linux/slab.h>
5df6d737
AJ
22#include <linux/errno.h>
23#include <linux/init.h>
24#include <linux/pci.h>
25#include <linux/skbuff.h>
26#include <linux/interrupt.h>
27#include <linux/spinlock.h>
28#include <linux/workqueue.h>
78112e55
JE
29#include <linux/if_ether.h>
30#include <scsi/fc/fc_fip.h>
5df6d737
AJ
31#include <scsi/scsi_host.h>
32#include <scsi/scsi_transport.h>
33#include <scsi/scsi_transport_fc.h>
34#include <scsi/scsi_tcq.h>
35#include <scsi/libfc.h>
36#include <scsi/fc_frame.h>
37
38#include "vnic_dev.h"
39#include "vnic_intr.h"
40#include "vnic_stats.h"
41#include "fnic_io.h"
d3c995f1 42#include "fnic_fip.h"
5df6d737
AJ
43#include "fnic.h"
44
45#define PCI_DEVICE_ID_CISCO_FNIC 0x0045
46
47/* Timer to poll notification area for events. Used for MSI interrupts */
48#define FNIC_NOTIFY_TIMER_PERIOD (2 * HZ)
49
50static struct kmem_cache *fnic_sgl_cache[FNIC_SGL_NUM_CACHES];
51static struct kmem_cache *fnic_io_req_cache;
52LIST_HEAD(fnic_list);
53DEFINE_SPINLOCK(fnic_list_lock);
54
55/* Supported devices by fnic module */
56static struct pci_device_id fnic_id_table[] = {
57 { PCI_DEVICE(PCI_VENDOR_ID_CISCO, PCI_DEVICE_ID_CISCO_FNIC) },
58 { 0, }
59};
60
61MODULE_DESCRIPTION(DRV_DESCRIPTION);
62MODULE_AUTHOR("Abhijeet Joglekar <abjoglek@cisco.com>, "
63 "Joseph R. Eykholt <jeykholt@cisco.com>");
64MODULE_LICENSE("GPL v2");
65MODULE_VERSION(DRV_VERSION);
66MODULE_DEVICE_TABLE(pci, fnic_id_table);
67
68unsigned int fnic_log_level;
69module_param(fnic_log_level, int, S_IRUGO|S_IWUSR);
70MODULE_PARM_DESC(fnic_log_level, "bit mask of fnic logging levels");
71
4d7007b4
HP
72unsigned int fnic_trace_max_pages = 16;
73module_param(fnic_trace_max_pages, uint, S_IRUGO|S_IWUSR);
74MODULE_PARM_DESC(fnic_trace_max_pages, "Total allocated memory pages "
75 "for fnic trace buffer");
5df6d737 76
fc85799e
HP
77static unsigned int fnic_max_qdepth = FNIC_DFLT_QUEUE_DEPTH;
78module_param(fnic_max_qdepth, uint, S_IRUGO|S_IWUSR);
79MODULE_PARM_DESC(fnic_max_qdepth, "Queue depth to report for each LUN");
80
5df6d737
AJ
81static struct libfc_function_template fnic_transport_template = {
82 .frame_send = fnic_send,
78112e55 83 .lport_set_port_id = fnic_set_port_id,
5df6d737
AJ
84 .fcp_abort_io = fnic_empty_scsi_cleanup,
85 .fcp_cleanup = fnic_empty_scsi_cleanup,
86 .exch_mgr_reset = fnic_exch_mgr_reset
87};
88
89static int fnic_slave_alloc(struct scsi_device *sdev)
90{
91 struct fc_rport *rport = starget_to_rport(scsi_target(sdev));
5df6d737
AJ
92
93 sdev->tagged_supported = 1;
94
95 if (!rport || fc_remote_port_chkready(rport))
96 return -ENXIO;
97
fc85799e 98 scsi_activate_tcq(sdev, fnic_max_qdepth);
5df6d737
AJ
99 return 0;
100}
101
102static struct scsi_host_template fnic_host_template = {
103 .module = THIS_MODULE,
104 .name = DRV_NAME,
105 .queuecommand = fnic_queuecommand,
106 .eh_abort_handler = fnic_abort_cmd,
107 .eh_device_reset_handler = fnic_device_reset,
108 .eh_host_reset_handler = fnic_host_reset,
109 .slave_alloc = fnic_slave_alloc,
110 .change_queue_depth = fc_change_queue_depth,
111 .change_queue_type = fc_change_queue_type,
112 .this_id = -1,
113 .cmd_per_lun = 3,
c8ff03c6 114 .can_queue = FNIC_DFLT_IO_REQ,
5df6d737
AJ
115 .use_clustering = ENABLE_CLUSTERING,
116 .sg_tablesize = FNIC_MAX_SG_DESC_CNT,
117 .max_sectors = 0xffff,
118 .shost_attrs = fnic_attrs,
119};
120
8196a934 121static void
48586820 122fnic_set_rport_dev_loss_tmo(struct fc_rport *rport, u32 timeout)
8196a934 123{
48586820
MC
124 if (timeout)
125 rport->dev_loss_tmo = timeout;
126 else
127 rport->dev_loss_tmo = 1;
8196a934
MC
128}
129
5df6d737
AJ
130static void fnic_get_host_speed(struct Scsi_Host *shost);
131static struct scsi_transport_template *fnic_fc_transport;
132static struct fc_host_statistics *fnic_get_stats(struct Scsi_Host *);
1adee040 133static void fnic_reset_host_stats(struct Scsi_Host *);
5df6d737
AJ
134
135static struct fc_function_template fnic_fc_functions = {
136
137 .show_host_node_name = 1,
138 .show_host_port_name = 1,
139 .show_host_supported_classes = 1,
140 .show_host_supported_fc4s = 1,
141 .show_host_active_fc4s = 1,
142 .show_host_maxframe_size = 1,
143 .show_host_port_id = 1,
144 .show_host_supported_speeds = 1,
145 .get_host_speed = fnic_get_host_speed,
146 .show_host_speed = 1,
147 .show_host_port_type = 1,
148 .get_host_port_state = fc_get_host_port_state,
149 .show_host_port_state = 1,
150 .show_host_symbolic_name = 1,
151 .show_rport_maxframe_size = 1,
152 .show_rport_supported_classes = 1,
153 .show_host_fabric_name = 1,
154 .show_starget_node_name = 1,
155 .show_starget_port_name = 1,
156 .show_starget_port_id = 1,
157 .show_rport_dev_loss_tmo = 1,
48586820 158 .set_rport_dev_loss_tmo = fnic_set_rport_dev_loss_tmo,
5df6d737
AJ
159 .issue_fc_host_lip = fnic_reset,
160 .get_fc_host_stats = fnic_get_stats,
1adee040 161 .reset_fc_host_stats = fnic_reset_host_stats,
5df6d737
AJ
162 .dd_fcrport_size = sizeof(struct fc_rport_libfc_priv),
163 .terminate_rport_io = fnic_terminate_rport_io,
76d8737c 164 .bsg_request = fc_lport_bsg_request,
5df6d737
AJ
165};
166
167static void fnic_get_host_speed(struct Scsi_Host *shost)
168{
169 struct fc_lport *lp = shost_priv(shost);
170 struct fnic *fnic = lport_priv(lp);
171 u32 port_speed = vnic_dev_port_speed(fnic->vdev);
172
173 /* Add in other values as they get defined in fw */
174 switch (port_speed) {
175 case 10000:
176 fc_host_speed(shost) = FC_PORTSPEED_10GBIT;
177 break;
178 default:
179 fc_host_speed(shost) = FC_PORTSPEED_10GBIT;
180 break;
181 }
182}
183
184static struct fc_host_statistics *fnic_get_stats(struct Scsi_Host *host)
185{
186 int ret;
187 struct fc_lport *lp = shost_priv(host);
188 struct fnic *fnic = lport_priv(lp);
189 struct fc_host_statistics *stats = &lp->host_stats;
190 struct vnic_stats *vs;
191 unsigned long flags;
192
193 if (time_before(jiffies, fnic->stats_time + HZ / FNIC_STATS_RATE_LIMIT))
194 return stats;
195 fnic->stats_time = jiffies;
196
197 spin_lock_irqsave(&fnic->fnic_lock, flags);
198 ret = vnic_dev_stats_dump(fnic->vdev, &fnic->stats);
199 spin_unlock_irqrestore(&fnic->fnic_lock, flags);
200
201 if (ret) {
202 FNIC_MAIN_DBG(KERN_DEBUG, fnic->lport->host,
203 "fnic: Get vnic stats failed"
204 " 0x%x", ret);
205 return stats;
206 }
207 vs = fnic->stats;
208 stats->tx_frames = vs->tx.tx_unicast_frames_ok;
209 stats->tx_words = vs->tx.tx_unicast_bytes_ok / 4;
210 stats->rx_frames = vs->rx.rx_unicast_frames_ok;
211 stats->rx_words = vs->rx.rx_unicast_bytes_ok / 4;
212 stats->error_frames = vs->tx.tx_errors + vs->rx.rx_errors;
213 stats->dumped_frames = vs->tx.tx_drops + vs->rx.rx_drop;
214 stats->invalid_crc_count = vs->rx.rx_crc_errors;
1adee040
NM
215 stats->seconds_since_last_reset =
216 (jiffies - fnic->stats_reset_time) / HZ;
5df6d737
AJ
217 stats->fcp_input_megabytes = div_u64(fnic->fcp_input_bytes, 1000000);
218 stats->fcp_output_megabytes = div_u64(fnic->fcp_output_bytes, 1000000);
219
220 return stats;
221}
222
1adee040
NM
223/*
224 * fnic_dump_fchost_stats
225 * note : dumps fc_statistics into system logs
226 */
227void fnic_dump_fchost_stats(struct Scsi_Host *host,
228 struct fc_host_statistics *stats)
229{
230 FNIC_MAIN_NOTE(KERN_NOTICE, host,
231 "fnic: seconds since last reset = %llu\n",
232 stats->seconds_since_last_reset);
233 FNIC_MAIN_NOTE(KERN_NOTICE, host,
234 "fnic: tx frames = %llu\n",
235 stats->tx_frames);
236 FNIC_MAIN_NOTE(KERN_NOTICE, host,
237 "fnic: tx words = %llu\n",
238 stats->tx_words);
239 FNIC_MAIN_NOTE(KERN_NOTICE, host,
240 "fnic: rx frames = %llu\n",
241 stats->rx_frames);
242 FNIC_MAIN_NOTE(KERN_NOTICE, host,
243 "fnic: rx words = %llu\n",
244 stats->rx_words);
245 FNIC_MAIN_NOTE(KERN_NOTICE, host,
246 "fnic: lip count = %llu\n",
247 stats->lip_count);
248 FNIC_MAIN_NOTE(KERN_NOTICE, host,
249 "fnic: nos count = %llu\n",
250 stats->nos_count);
251 FNIC_MAIN_NOTE(KERN_NOTICE, host,
252 "fnic: error frames = %llu\n",
253 stats->error_frames);
254 FNIC_MAIN_NOTE(KERN_NOTICE, host,
255 "fnic: dumped frames = %llu\n",
256 stats->dumped_frames);
257 FNIC_MAIN_NOTE(KERN_NOTICE, host,
258 "fnic: link failure count = %llu\n",
259 stats->link_failure_count);
260 FNIC_MAIN_NOTE(KERN_NOTICE, host,
261 "fnic: loss of sync count = %llu\n",
262 stats->loss_of_sync_count);
263 FNIC_MAIN_NOTE(KERN_NOTICE, host,
264 "fnic: loss of signal count = %llu\n",
265 stats->loss_of_signal_count);
266 FNIC_MAIN_NOTE(KERN_NOTICE, host,
267 "fnic: prim seq protocol err count = %llu\n",
268 stats->prim_seq_protocol_err_count);
269 FNIC_MAIN_NOTE(KERN_NOTICE, host,
270 "fnic: invalid tx word count= %llu\n",
271 stats->invalid_tx_word_count);
272 FNIC_MAIN_NOTE(KERN_NOTICE, host,
273 "fnic: invalid crc count = %llu\n",
274 stats->invalid_crc_count);
275 FNIC_MAIN_NOTE(KERN_NOTICE, host,
276 "fnic: fcp input requests = %llu\n",
277 stats->fcp_input_requests);
278 FNIC_MAIN_NOTE(KERN_NOTICE, host,
279 "fnic: fcp output requests = %llu\n",
280 stats->fcp_output_requests);
281 FNIC_MAIN_NOTE(KERN_NOTICE, host,
282 "fnic: fcp control requests = %llu\n",
283 stats->fcp_control_requests);
284 FNIC_MAIN_NOTE(KERN_NOTICE, host,
285 "fnic: fcp input megabytes = %llu\n",
286 stats->fcp_input_megabytes);
287 FNIC_MAIN_NOTE(KERN_NOTICE, host,
288 "fnic: fcp output megabytes = %llu\n",
289 stats->fcp_output_megabytes);
290 return;
291}
292
293/*
294 * fnic_reset_host_stats : clears host stats
295 * note : called when reset_statistics set under sysfs dir
296 */
297static void fnic_reset_host_stats(struct Scsi_Host *host)
298{
299 int ret;
300 struct fc_lport *lp = shost_priv(host);
301 struct fnic *fnic = lport_priv(lp);
302 struct fc_host_statistics *stats;
303 unsigned long flags;
304
305 /* dump current stats, before clearing them */
306 stats = fnic_get_stats(host);
307 fnic_dump_fchost_stats(host, stats);
308
309 spin_lock_irqsave(&fnic->fnic_lock, flags);
310 ret = vnic_dev_stats_clear(fnic->vdev);
311 spin_unlock_irqrestore(&fnic->fnic_lock, flags);
312
313 if (ret) {
314 FNIC_MAIN_DBG(KERN_DEBUG, fnic->lport->host,
315 "fnic: Reset vnic stats failed"
316 " 0x%x", ret);
317 return;
318 }
319 fnic->stats_reset_time = jiffies;
320 memset(stats, 0, sizeof(*stats));
321
322 return;
323}
324
5df6d737
AJ
325void fnic_log_q_error(struct fnic *fnic)
326{
327 unsigned int i;
328 u32 error_status;
329
330 for (i = 0; i < fnic->raw_wq_count; i++) {
331 error_status = ioread32(&fnic->wq[i].ctrl->error_status);
332 if (error_status)
333 shost_printk(KERN_ERR, fnic->lport->host,
334 "WQ[%d] error_status"
335 " %d\n", i, error_status);
336 }
337
338 for (i = 0; i < fnic->rq_count; i++) {
339 error_status = ioread32(&fnic->rq[i].ctrl->error_status);
340 if (error_status)
341 shost_printk(KERN_ERR, fnic->lport->host,
342 "RQ[%d] error_status"
343 " %d\n", i, error_status);
344 }
345
346 for (i = 0; i < fnic->wq_copy_count; i++) {
347 error_status = ioread32(&fnic->wq_copy[i].ctrl->error_status);
348 if (error_status)
349 shost_printk(KERN_ERR, fnic->lport->host,
350 "CWQ[%d] error_status"
351 " %d\n", i, error_status);
352 }
353}
354
355void fnic_handle_link_event(struct fnic *fnic)
356{
357 unsigned long flags;
358
359 spin_lock_irqsave(&fnic->fnic_lock, flags);
360 if (fnic->stop_rx_link_events) {
361 spin_unlock_irqrestore(&fnic->fnic_lock, flags);
362 return;
363 }
364 spin_unlock_irqrestore(&fnic->fnic_lock, flags);
365
366 queue_work(fnic_event_queue, &fnic->link_work);
367
368}
369
370static int fnic_notify_set(struct fnic *fnic)
371{
372 int err;
373
374 switch (vnic_dev_get_intr_mode(fnic->vdev)) {
375 case VNIC_DEV_INTR_MODE_INTX:
376 err = vnic_dev_notify_set(fnic->vdev, FNIC_INTX_NOTIFY);
377 break;
378 case VNIC_DEV_INTR_MODE_MSI:
379 err = vnic_dev_notify_set(fnic->vdev, -1);
380 break;
381 case VNIC_DEV_INTR_MODE_MSIX:
382 err = vnic_dev_notify_set(fnic->vdev, FNIC_MSIX_ERR_NOTIFY);
383 break;
384 default:
385 shost_printk(KERN_ERR, fnic->lport->host,
386 "Interrupt mode should be set up"
387 " before devcmd notify set %d\n",
388 vnic_dev_get_intr_mode(fnic->vdev));
389 err = -1;
390 break;
391 }
392
393 return err;
394}
395
396static void fnic_notify_timer(unsigned long data)
397{
398 struct fnic *fnic = (struct fnic *)data;
399
400 fnic_handle_link_event(fnic);
401 mod_timer(&fnic->notify_timer,
402 round_jiffies(jiffies + FNIC_NOTIFY_TIMER_PERIOD));
403}
404
d3c995f1
HP
405static void fnic_fip_notify_timer(unsigned long data)
406{
407 struct fnic *fnic = (struct fnic *)data;
408
409 fnic_handle_fip_timer(fnic);
410}
411
5df6d737
AJ
412static void fnic_notify_timer_start(struct fnic *fnic)
413{
414 switch (vnic_dev_get_intr_mode(fnic->vdev)) {
415 case VNIC_DEV_INTR_MODE_MSI:
416 /*
417 * Schedule first timeout immediately. The driver is
418 * initiatialized and ready to look for link up notification
419 */
420 mod_timer(&fnic->notify_timer, jiffies);
421 break;
422 default:
423 /* Using intr for notification for INTx/MSI-X */
424 break;
425 };
426}
427
428static int fnic_dev_wait(struct vnic_dev *vdev,
429 int (*start)(struct vnic_dev *, int),
430 int (*finished)(struct vnic_dev *, int *),
431 int arg)
432{
433 unsigned long time;
434 int done;
435 int err;
436
437 err = start(vdev, arg);
438 if (err)
439 return err;
440
441 /* Wait for func to complete...2 seconds max */
442 time = jiffies + (HZ * 2);
443 do {
444 err = finished(vdev, &done);
445 if (err)
446 return err;
447 if (done)
448 return 0;
449 schedule_timeout_uninterruptible(HZ / 10);
450 } while (time_after(time, jiffies));
451
452 return -ETIMEDOUT;
453}
454
455static int fnic_cleanup(struct fnic *fnic)
456{
457 unsigned int i;
458 int err;
5df6d737
AJ
459
460 vnic_dev_disable(fnic->vdev);
461 for (i = 0; i < fnic->intr_count; i++)
462 vnic_intr_mask(&fnic->intr[i]);
463
464 for (i = 0; i < fnic->rq_count; i++) {
465 err = vnic_rq_disable(&fnic->rq[i]);
466 if (err)
467 return err;
468 }
469 for (i = 0; i < fnic->raw_wq_count; i++) {
470 err = vnic_wq_disable(&fnic->wq[i]);
471 if (err)
472 return err;
473 }
474 for (i = 0; i < fnic->wq_copy_count; i++) {
475 err = vnic_wq_copy_disable(&fnic->wq_copy[i]);
476 if (err)
477 return err;
478 }
479
480 /* Clean up completed IOs and FCS frames */
481 fnic_wq_copy_cmpl_handler(fnic, -1);
482 fnic_wq_cmpl_handler(fnic, -1);
483 fnic_rq_cmpl_handler(fnic, -1);
484
485 /* Clean up the IOs and FCS frames that have not completed */
486 for (i = 0; i < fnic->raw_wq_count; i++)
487 vnic_wq_clean(&fnic->wq[i], fnic_free_wq_buf);
488 for (i = 0; i < fnic->rq_count; i++)
489 vnic_rq_clean(&fnic->rq[i], fnic_free_rq_buf);
490 for (i = 0; i < fnic->wq_copy_count; i++)
491 vnic_wq_copy_clean(&fnic->wq_copy[i],
492 fnic_wq_copy_cleanup_handler);
493
494 for (i = 0; i < fnic->cq_count; i++)
495 vnic_cq_clean(&fnic->cq[i]);
496 for (i = 0; i < fnic->intr_count; i++)
497 vnic_intr_clean(&fnic->intr[i]);
498
5df6d737
AJ
499 mempool_destroy(fnic->io_req_pool);
500 for (i = 0; i < FNIC_SGL_NUM_CACHES; i++)
501 mempool_destroy(fnic->io_sgl_pool[i]);
502
503 return 0;
504}
505
506static void fnic_iounmap(struct fnic *fnic)
507{
508 if (fnic->bar0.vaddr)
509 iounmap(fnic->bar0.vaddr);
510}
511
78112e55
JE
512/**
513 * fnic_get_mac() - get assigned data MAC address for FIP code.
514 * @lport: local port.
515 */
516static u8 *fnic_get_mac(struct fc_lport *lport)
517{
518 struct fnic *fnic = lport_priv(lport);
519
520 return fnic->data_src_addr;
521}
522
d3c995f1
HP
523static void fnic_set_vlan(struct fnic *fnic, u16 vlan_id)
524{
525 u16 old_vlan;
526 old_vlan = vnic_dev_set_default_vlan(fnic->vdev, vlan_id);
527}
528
6f039790 529static int fnic_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
5df6d737
AJ
530{
531 struct Scsi_Host *host;
532 struct fc_lport *lp;
533 struct fnic *fnic;
534 mempool_t *pool;
535 int err;
536 int i;
537 unsigned long flags;
538
539 /*
540 * Allocate SCSI Host and set up association between host,
541 * local port, and fnic
542 */
86221969
CL
543 lp = libfc_host_alloc(&fnic_host_template, sizeof(struct fnic));
544 if (!lp) {
545 printk(KERN_ERR PFX "Unable to alloc libfc local port\n");
5df6d737
AJ
546 err = -ENOMEM;
547 goto err_out;
548 }
86221969 549 host = lp->host;
5df6d737
AJ
550 fnic = lport_priv(lp);
551 fnic->lport = lp;
78112e55 552 fnic->ctlr.lp = lp;
5df6d737
AJ
553
554 snprintf(fnic->name, sizeof(fnic->name) - 1, "%s%d", DRV_NAME,
555 host->host_no);
556
557 host->transportt = fnic_fc_transport;
558
67125b02
HP
559 err = fnic_stats_debugfs_init(fnic);
560 if (err) {
561 shost_printk(KERN_ERR, fnic->lport->host,
562 "Failed to initialize debugfs for stats\n");
563 fnic_stats_debugfs_remove(fnic);
564 }
565
5df6d737
AJ
566 /* Setup PCI resources */
567 pci_set_drvdata(pdev, fnic);
568
569 fnic->pdev = pdev;
570
571 err = pci_enable_device(pdev);
572 if (err) {
573 shost_printk(KERN_ERR, fnic->lport->host,
574 "Cannot enable PCI device, aborting.\n");
575 goto err_out_free_hba;
576 }
577
578 err = pci_request_regions(pdev, DRV_NAME);
579 if (err) {
580 shost_printk(KERN_ERR, fnic->lport->host,
581 "Cannot enable PCI resources, aborting\n");
582 goto err_out_disable_device;
583 }
584
585 pci_set_master(pdev);
586
587 /* Query PCI controller on system for DMA addressing
87aa619c 588 * limitation for the device. Try 64-bit first, and
5df6d737
AJ
589 * fail to 32-bit.
590 */
87aa619c 591 err = pci_set_dma_mask(pdev, DMA_BIT_MASK(64));
5df6d737 592 if (err) {
e3f47cc7 593 err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
5df6d737
AJ
594 if (err) {
595 shost_printk(KERN_ERR, fnic->lport->host,
596 "No usable DMA configuration "
597 "aborting\n");
598 goto err_out_release_regions;
599 }
e3f47cc7 600 err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
5df6d737
AJ
601 if (err) {
602 shost_printk(KERN_ERR, fnic->lport->host,
603 "Unable to obtain 32-bit DMA "
604 "for consistent allocations, aborting.\n");
605 goto err_out_release_regions;
606 }
607 } else {
87aa619c 608 err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64));
5df6d737
AJ
609 if (err) {
610 shost_printk(KERN_ERR, fnic->lport->host,
87aa619c 611 "Unable to obtain 64-bit DMA "
5df6d737
AJ
612 "for consistent allocations, aborting.\n");
613 goto err_out_release_regions;
614 }
615 }
616
617 /* Map vNIC resources from BAR0 */
618 if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
619 shost_printk(KERN_ERR, fnic->lport->host,
620 "BAR0 not memory-map'able, aborting.\n");
621 err = -ENODEV;
622 goto err_out_release_regions;
623 }
624
625 fnic->bar0.vaddr = pci_iomap(pdev, 0, 0);
626 fnic->bar0.bus_addr = pci_resource_start(pdev, 0);
627 fnic->bar0.len = pci_resource_len(pdev, 0);
628
629 if (!fnic->bar0.vaddr) {
630 shost_printk(KERN_ERR, fnic->lport->host,
631 "Cannot memory-map BAR0 res hdr, "
632 "aborting.\n");
633 err = -ENODEV;
634 goto err_out_release_regions;
635 }
636
637 fnic->vdev = vnic_dev_register(NULL, fnic, pdev, &fnic->bar0);
638 if (!fnic->vdev) {
639 shost_printk(KERN_ERR, fnic->lport->host,
640 "vNIC registration failed, "
641 "aborting.\n");
642 err = -ENODEV;
643 goto err_out_iounmap;
644 }
645
646 err = fnic_dev_wait(fnic->vdev, vnic_dev_open,
647 vnic_dev_open_done, 0);
648 if (err) {
649 shost_printk(KERN_ERR, fnic->lport->host,
650 "vNIC dev open failed, aborting.\n");
651 goto err_out_vnic_unregister;
652 }
653
654 err = vnic_dev_init(fnic->vdev, 0);
655 if (err) {
656 shost_printk(KERN_ERR, fnic->lport->host,
657 "vNIC dev init failed, aborting.\n");
658 goto err_out_dev_close;
659 }
660
78112e55 661 err = vnic_dev_mac_addr(fnic->vdev, fnic->ctlr.ctl_src_addr);
5df6d737
AJ
662 if (err) {
663 shost_printk(KERN_ERR, fnic->lport->host,
664 "vNIC get MAC addr failed \n");
665 goto err_out_dev_close;
666 }
78112e55
JE
667 /* set data_src for point-to-point mode and to keep it non-zero */
668 memcpy(fnic->data_src_addr, fnic->ctlr.ctl_src_addr, ETH_ALEN);
5df6d737
AJ
669
670 /* Get vNIC configuration */
671 err = fnic_get_vnic_config(fnic);
672 if (err) {
673 shost_printk(KERN_ERR, fnic->lport->host,
674 "Get vNIC configuration failed, "
675 "aborting.\n");
676 goto err_out_dev_close;
677 }
fc85799e
HP
678
679 /* Configure Maximum Outstanding IO reqs*/
680 if (fnic->config.io_throttle_count != FNIC_UCSM_DFLT_THROTTLE_CNT_BLD) {
681 host->can_queue = min_t(u32, FNIC_MAX_IO_REQ,
682 max_t(u32, FNIC_MIN_IO_REQ,
683 fnic->config.io_throttle_count));
684 }
685 fnic->fnic_max_tag_id = host->can_queue;
686
687 err = scsi_init_shared_tag_map(host, fnic->fnic_max_tag_id);
688 if (err) {
689 shost_printk(KERN_ERR, fnic->lport->host,
690 "Unable to alloc shared tag map\n");
691 goto err_out_dev_close;
692 }
693
5df6d737
AJ
694 host->max_lun = fnic->config.luns_per_tgt;
695 host->max_id = FNIC_MAX_FCP_TARGET;
da87bfab 696 host->max_cmd_len = FCOE_MAX_CMD_LEN;
5df6d737
AJ
697
698 fnic_get_res_counts(fnic);
699
700 err = fnic_set_intr_mode(fnic);
701 if (err) {
702 shost_printk(KERN_ERR, fnic->lport->host,
703 "Failed to set intr mode, "
704 "aborting.\n");
705 goto err_out_dev_close;
706 }
707
5df6d737
AJ
708 err = fnic_alloc_vnic_resources(fnic);
709 if (err) {
710 shost_printk(KERN_ERR, fnic->lport->host,
711 "Failed to alloc vNIC resources, "
712 "aborting.\n");
2e76f767 713 goto err_out_clear_intr;
5df6d737
AJ
714 }
715
716
717 /* initialize all fnic locks */
718 spin_lock_init(&fnic->fnic_lock);
719
720 for (i = 0; i < FNIC_WQ_MAX; i++)
721 spin_lock_init(&fnic->wq_lock[i]);
722
723 for (i = 0; i < FNIC_WQ_COPY_MAX; i++) {
724 spin_lock_init(&fnic->wq_copy_lock[i]);
725 fnic->wq_copy_desc_low[i] = DESC_CLEAN_LOW_WATERMARK;
726 fnic->fw_ack_recd[i] = 0;
727 fnic->fw_ack_index[i] = -1;
728 }
729
730 for (i = 0; i < FNIC_IO_LOCKS; i++)
731 spin_lock_init(&fnic->io_req_lock[i]);
732
733 fnic->io_req_pool = mempool_create_slab_pool(2, fnic_io_req_cache);
734 if (!fnic->io_req_pool)
735 goto err_out_free_resources;
736
0c79c742 737 pool = mempool_create_slab_pool(2, fnic_sgl_cache[FNIC_SGL_CACHE_DFLT]);
5df6d737
AJ
738 if (!pool)
739 goto err_out_free_ioreq_pool;
740 fnic->io_sgl_pool[FNIC_SGL_CACHE_DFLT] = pool;
741
0c79c742 742 pool = mempool_create_slab_pool(2, fnic_sgl_cache[FNIC_SGL_CACHE_MAX]);
5df6d737
AJ
743 if (!pool)
744 goto err_out_free_dflt_pool;
745 fnic->io_sgl_pool[FNIC_SGL_CACHE_MAX] = pool;
746
747 /* setup vlan config, hw inserts vlan header */
748 fnic->vlan_hw_insert = 1;
749 fnic->vlan_id = 0;
750
78112e55
JE
751 /* Initialize the FIP fcoe_ctrl struct */
752 fnic->ctlr.send = fnic_eth_send;
753 fnic->ctlr.update_mac = fnic_update_mac;
754 fnic->ctlr.get_src_addr = fnic_get_mac;
78112e55
JE
755 if (fnic->config.flags & VFCF_FIP_CAPABLE) {
756 shost_printk(KERN_INFO, fnic->lport->host,
757 "firmware supports FIP\n");
aaa5e569
VSVB
758 /* enable directed and multicast */
759 vnic_dev_packet_filter(fnic->vdev, 1, 1, 0, 0, 0);
78112e55
JE
760 vnic_dev_add_addr(fnic->vdev, FIP_ALL_ENODE_MACS);
761 vnic_dev_add_addr(fnic->vdev, fnic->ctlr.ctl_src_addr);
d3c995f1 762 fnic->set_vlan = fnic_set_vlan;
3d902ac0 763 fcoe_ctlr_init(&fnic->ctlr, FIP_MODE_AUTO);
d3c995f1
HP
764 setup_timer(&fnic->fip_timer, fnic_fip_notify_timer,
765 (unsigned long)fnic);
766 spin_lock_init(&fnic->vlans_lock);
767 INIT_WORK(&fnic->fip_frame_work, fnic_handle_fip_frame);
768 INIT_WORK(&fnic->event_work, fnic_handle_event);
769 skb_queue_head_init(&fnic->fip_frame_queue);
d3c995f1
HP
770 INIT_LIST_HEAD(&fnic->evlist);
771 INIT_LIST_HEAD(&fnic->vlans);
78112e55
JE
772 } else {
773 shost_printk(KERN_INFO, fnic->lport->host,
774 "firmware uses non-FIP mode\n");
3d902ac0 775 fcoe_ctlr_init(&fnic->ctlr, FIP_MODE_NON_FIP);
c8ff03c6 776 fnic->ctlr.state = FIP_ST_NON_FIP;
78112e55 777 }
5df6d737
AJ
778 fnic->state = FNIC_IN_FC_MODE;
779
03298552
HP
780 atomic_set(&fnic->in_flight, 0);
781 fnic->state_flags = FNIC_FLAGS_NONE;
782
5df6d737
AJ
783 /* Enable hardware stripping of vlan header on ingress */
784 fnic_set_nic_config(fnic, 0, 0, 0, 0, 0, 0, 1);
785
786 /* Setup notification buffer area */
787 err = fnic_notify_set(fnic);
788 if (err) {
789 shost_printk(KERN_ERR, fnic->lport->host,
790 "Failed to alloc notify buffer, aborting.\n");
791 goto err_out_free_max_pool;
792 }
793
794 /* Setup notify timer when using MSI interrupts */
795 if (vnic_dev_get_intr_mode(fnic->vdev) == VNIC_DEV_INTR_MODE_MSI)
796 setup_timer(&fnic->notify_timer,
797 fnic_notify_timer, (unsigned long)fnic);
798
799 /* allocate RQ buffers and post them to RQ*/
800 for (i = 0; i < fnic->rq_count; i++) {
801 err = vnic_rq_fill(&fnic->rq[i], fnic_alloc_rq_frame);
802 if (err) {
803 shost_printk(KERN_ERR, fnic->lport->host,
804 "fnic_alloc_rq_frame can't alloc "
805 "frame\n");
806 goto err_out_free_rq_buf;
807 }
808 }
809
810 /*
811 * Initialization done with PCI system, hardware, firmware.
812 * Add host to SCSI
813 */
814 err = scsi_add_host(lp->host, &pdev->dev);
815 if (err) {
816 shost_printk(KERN_ERR, fnic->lport->host,
817 "fnic: scsi_add_host failed...exiting\n");
818 goto err_out_free_rq_buf;
819 }
820
821 /* Start local port initiatialization */
822
823 lp->link_up = 0;
5df6d737 824
5df6d737 825 lp->max_retry_count = fnic->config.flogi_retries;
a3666955 826 lp->max_rport_retry_count = fnic->config.plogi_retries;
5df6d737
AJ
827 lp->service_params = (FCP_SPPF_INIT_FCN | FCP_SPPF_RD_XRDY_DIS |
828 FCP_SPPF_CONF_COMPL);
829 if (fnic->config.flags & VFCF_FCP_SEQ_LVL_ERR)
830 lp->service_params |= FCP_SPPF_RETRY;
831
832 lp->boot_time = jiffies;
833 lp->e_d_tov = fnic->config.ed_tov;
834 lp->r_a_tov = fnic->config.ra_tov;
835 lp->link_supported_speeds = FC_PORTSPEED_10GBIT;
836 fc_set_wwnn(lp, fnic->config.node_wwn);
837 fc_set_wwpn(lp, fnic->config.port_wwn);
838
e10f8c66 839 fcoe_libfc_config(lp, &fnic->ctlr, &fnic_transport_template, 0);
5df6d737 840
52ff878c
VD
841 if (!fc_exch_mgr_alloc(lp, FC_CLASS_3, FCPIO_HOST_EXCH_RANGE_START,
842 FCPIO_HOST_EXCH_RANGE_END, NULL)) {
843 err = -ENOMEM;
844 goto err_out_remove_scsi_host;
845 }
846
c693a71d 847 fc_lport_init_stats(lp);
1adee040 848 fnic->stats_reset_time = jiffies;
c693a71d 849
5df6d737
AJ
850 fc_lport_config(lp);
851
852 if (fc_set_mfs(lp, fnic->config.maxdatafieldsize +
853 sizeof(struct fc_frame_header))) {
854 err = -EINVAL;
855 goto err_out_free_exch_mgr;
856 }
857 fc_host_maxframe_size(lp->host) = lp->mfs;
48586820 858 fc_host_dev_loss_tmo(lp->host) = fnic->config.port_down_timeout / 1000;
5df6d737
AJ
859
860 sprintf(fc_host_symbolic_name(lp->host),
861 DRV_NAME " v" DRV_VERSION " over %s", fnic->name);
862
863 spin_lock_irqsave(&fnic_list_lock, flags);
864 list_add_tail(&fnic->list, &fnic_list);
865 spin_unlock_irqrestore(&fnic_list_lock, flags);
866
867 INIT_WORK(&fnic->link_work, fnic_handle_link);
868 INIT_WORK(&fnic->frame_work, fnic_handle_frame);
869 skb_queue_head_init(&fnic->frame_queue);
78112e55 870 skb_queue_head_init(&fnic->tx_queue);
5df6d737
AJ
871
872 /* Enable all queues */
873 for (i = 0; i < fnic->raw_wq_count; i++)
874 vnic_wq_enable(&fnic->wq[i]);
875 for (i = 0; i < fnic->rq_count; i++)
876 vnic_rq_enable(&fnic->rq[i]);
877 for (i = 0; i < fnic->wq_copy_count; i++)
878 vnic_wq_copy_enable(&fnic->wq_copy[i]);
879
880 fc_fabric_login(lp);
881
882 vnic_dev_enable(fnic->vdev);
2e76f767
AJ
883
884 err = fnic_request_intr(fnic);
885 if (err) {
886 shost_printk(KERN_ERR, fnic->lport->host,
887 "Unable to request irq.\n");
888 goto err_out_free_exch_mgr;
889 }
890
5df6d737
AJ
891 for (i = 0; i < fnic->intr_count; i++)
892 vnic_intr_unmask(&fnic->intr[i]);
893
894 fnic_notify_timer_start(fnic);
895
896 return 0;
897
898err_out_free_exch_mgr:
52ff878c 899 fc_exch_mgr_free(lp);
5df6d737 900err_out_remove_scsi_host:
78112e55
JE
901 fc_remove_host(lp->host);
902 scsi_remove_host(lp->host);
5df6d737
AJ
903err_out_free_rq_buf:
904 for (i = 0; i < fnic->rq_count; i++)
905 vnic_rq_clean(&fnic->rq[i], fnic_free_rq_buf);
906 vnic_dev_notify_unset(fnic->vdev);
907err_out_free_max_pool:
908 mempool_destroy(fnic->io_sgl_pool[FNIC_SGL_CACHE_MAX]);
909err_out_free_dflt_pool:
910 mempool_destroy(fnic->io_sgl_pool[FNIC_SGL_CACHE_DFLT]);
911err_out_free_ioreq_pool:
912 mempool_destroy(fnic->io_req_pool);
913err_out_free_resources:
914 fnic_free_vnic_resources(fnic);
5df6d737
AJ
915err_out_clear_intr:
916 fnic_clear_intr_mode(fnic);
917err_out_dev_close:
918 vnic_dev_close(fnic->vdev);
919err_out_vnic_unregister:
920 vnic_dev_unregister(fnic->vdev);
921err_out_iounmap:
922 fnic_iounmap(fnic);
923err_out_release_regions:
924 pci_release_regions(pdev);
925err_out_disable_device:
926 pci_disable_device(pdev);
927err_out_free_hba:
67125b02 928 fnic_stats_debugfs_remove(fnic);
5df6d737
AJ
929 scsi_host_put(lp->host);
930err_out:
931 return err;
932}
933
6f039790 934static void fnic_remove(struct pci_dev *pdev)
5df6d737
AJ
935{
936 struct fnic *fnic = pci_get_drvdata(pdev);
78112e55 937 struct fc_lport *lp = fnic->lport;
5df6d737
AJ
938 unsigned long flags;
939
940 /*
941 * Mark state so that the workqueue thread stops forwarding
942 * received frames and link events to the local port. ISR and
943 * other threads that can queue work items will also stop
944 * creating work items on the fnic workqueue
945 */
946 spin_lock_irqsave(&fnic->fnic_lock, flags);
947 fnic->stop_rx_link_events = 1;
948 spin_unlock_irqrestore(&fnic->fnic_lock, flags);
949
950 if (vnic_dev_get_intr_mode(fnic->vdev) == VNIC_DEV_INTR_MODE_MSI)
951 del_timer_sync(&fnic->notify_timer);
952
953 /*
954 * Flush the fnic event queue. After this call, there should
955 * be no event queued for this fnic device in the workqueue
956 */
957 flush_workqueue(fnic_event_queue);
958 skb_queue_purge(&fnic->frame_queue);
78112e55 959 skb_queue_purge(&fnic->tx_queue);
5df6d737 960
d3c995f1
HP
961 if (fnic->config.flags & VFCF_FIP_CAPABLE) {
962 del_timer_sync(&fnic->fip_timer);
963 skb_queue_purge(&fnic->fip_frame_queue);
964 fnic_fcoe_reset_vlans(fnic);
965 fnic_fcoe_evlist_free(fnic);
966 }
967
5df6d737
AJ
968 /*
969 * Log off the fabric. This stops all remote ports, dns port,
970 * logs off the fabric. This flushes all rport, disc, lport work
971 * before returning
972 */
973 fc_fabric_logoff(fnic->lport);
974
975 spin_lock_irqsave(&fnic->fnic_lock, flags);
976 fnic->in_remove = 1;
977 spin_unlock_irqrestore(&fnic->fnic_lock, flags);
978
78112e55
JE
979 fcoe_ctlr_destroy(&fnic->ctlr);
980 fc_lport_destroy(lp);
67125b02 981 fnic_stats_debugfs_remove(fnic);
5df6d737
AJ
982
983 /*
984 * This stops the fnic device, masks all interrupts. Completed
985 * CQ entries are drained. Posted WQ/RQ/Copy-WQ entries are
986 * cleaned up
987 */
988 fnic_cleanup(fnic);
989
990 BUG_ON(!skb_queue_empty(&fnic->frame_queue));
78112e55 991 BUG_ON(!skb_queue_empty(&fnic->tx_queue));
5df6d737
AJ
992
993 spin_lock_irqsave(&fnic_list_lock, flags);
994 list_del(&fnic->list);
995 spin_unlock_irqrestore(&fnic_list_lock, flags);
996
997 fc_remove_host(fnic->lport->host);
998 scsi_remove_host(fnic->lport->host);
52ff878c 999 fc_exch_mgr_free(fnic->lport);
5df6d737 1000 vnic_dev_notify_unset(fnic->vdev);
5df6d737 1001 fnic_free_intr(fnic);
2e76f767 1002 fnic_free_vnic_resources(fnic);
5df6d737
AJ
1003 fnic_clear_intr_mode(fnic);
1004 vnic_dev_close(fnic->vdev);
1005 vnic_dev_unregister(fnic->vdev);
1006 fnic_iounmap(fnic);
1007 pci_release_regions(pdev);
1008 pci_disable_device(pdev);
78112e55 1009 scsi_host_put(lp->host);
5df6d737
AJ
1010}
1011
1012static struct pci_driver fnic_driver = {
1013 .name = DRV_NAME,
1014 .id_table = fnic_id_table,
1015 .probe = fnic_probe,
6f039790 1016 .remove = fnic_remove,
5df6d737
AJ
1017};
1018
1019static int __init fnic_init_module(void)
1020{
1021 size_t len;
1022 int err = 0;
1023
1024 printk(KERN_INFO PFX "%s, ver %s\n", DRV_DESCRIPTION, DRV_VERSION);
1025
67125b02
HP
1026 /* Create debugfs entries for fnic */
1027 err = fnic_debugfs_init();
1028 if (err < 0) {
1029 printk(KERN_ERR PFX "Failed to create fnic directory "
1030 "for tracing and stats logging\n");
1031 fnic_debugfs_terminate();
1032 }
1033
4d7007b4
HP
1034 /* Allocate memory for trace buffer */
1035 err = fnic_trace_buf_init();
1036 if (err < 0) {
1037 printk(KERN_ERR PFX "Trace buffer initialization Failed "
1038 "Fnic Tracing utility is disabled\n");
1039 fnic_trace_free();
1040 }
1041
5df6d737
AJ
1042 /* Create a cache for allocation of default size sgls */
1043 len = sizeof(struct fnic_dflt_sgl_list);
1044 fnic_sgl_cache[FNIC_SGL_CACHE_DFLT] = kmem_cache_create
1045 ("fnic_sgl_dflt", len + FNIC_SG_DESC_ALIGN, FNIC_SG_DESC_ALIGN,
0c79c742 1046 SLAB_HWCACHE_ALIGN,
5df6d737
AJ
1047 NULL);
1048 if (!fnic_sgl_cache[FNIC_SGL_CACHE_DFLT]) {
1049 printk(KERN_ERR PFX "failed to create fnic dflt sgl slab\n");
1050 err = -ENOMEM;
1051 goto err_create_fnic_sgl_slab_dflt;
1052 }
1053
1054 /* Create a cache for allocation of max size sgls*/
1055 len = sizeof(struct fnic_sgl_list);
1056 fnic_sgl_cache[FNIC_SGL_CACHE_MAX] = kmem_cache_create
1057 ("fnic_sgl_max", len + FNIC_SG_DESC_ALIGN, FNIC_SG_DESC_ALIGN,
d3c995f1
HP
1058 SLAB_HWCACHE_ALIGN,
1059 NULL);
5df6d737
AJ
1060 if (!fnic_sgl_cache[FNIC_SGL_CACHE_MAX]) {
1061 printk(KERN_ERR PFX "failed to create fnic max sgl slab\n");
1062 err = -ENOMEM;
1063 goto err_create_fnic_sgl_slab_max;
1064 }
1065
1066 /* Create a cache of io_req structs for use via mempool */
1067 fnic_io_req_cache = kmem_cache_create("fnic_io_req",
1068 sizeof(struct fnic_io_req),
1069 0, SLAB_HWCACHE_ALIGN, NULL);
1070 if (!fnic_io_req_cache) {
1071 printk(KERN_ERR PFX "failed to create fnic io_req slab\n");
1072 err = -ENOMEM;
1073 goto err_create_fnic_ioreq_slab;
1074 }
1075
1076 fnic_event_queue = create_singlethread_workqueue("fnic_event_wq");
1077 if (!fnic_event_queue) {
1078 printk(KERN_ERR PFX "fnic work queue create failed\n");
1079 err = -ENOMEM;
1080 goto err_create_fnic_workq;
1081 }
1082
1083 spin_lock_init(&fnic_list_lock);
1084 INIT_LIST_HEAD(&fnic_list);
1085
e09056b2
CL
1086 fnic_fip_queue = create_singlethread_workqueue("fnic_fip_q");
1087 if (!fnic_fip_queue) {
1088 printk(KERN_ERR PFX "fnic FIP work queue create failed\n");
1089 err = -ENOMEM;
1090 goto err_create_fip_workq;
1091 }
1092
5df6d737
AJ
1093 fnic_fc_transport = fc_attach_transport(&fnic_fc_functions);
1094 if (!fnic_fc_transport) {
1095 printk(KERN_ERR PFX "fc_attach_transport error\n");
1096 err = -ENOMEM;
1097 goto err_fc_transport;
1098 }
1099
1100 /* register the driver with PCI system */
1101 err = pci_register_driver(&fnic_driver);
1102 if (err < 0) {
1103 printk(KERN_ERR PFX "pci register error\n");
1104 goto err_pci_register;
1105 }
1106 return err;
1107
1108err_pci_register:
1109 fc_release_transport(fnic_fc_transport);
1110err_fc_transport:
e09056b2
CL
1111 destroy_workqueue(fnic_fip_queue);
1112err_create_fip_workq:
5df6d737
AJ
1113 destroy_workqueue(fnic_event_queue);
1114err_create_fnic_workq:
1115 kmem_cache_destroy(fnic_io_req_cache);
1116err_create_fnic_ioreq_slab:
1117 kmem_cache_destroy(fnic_sgl_cache[FNIC_SGL_CACHE_MAX]);
1118err_create_fnic_sgl_slab_max:
1119 kmem_cache_destroy(fnic_sgl_cache[FNIC_SGL_CACHE_DFLT]);
1120err_create_fnic_sgl_slab_dflt:
4d7007b4 1121 fnic_trace_free();
67125b02 1122 fnic_debugfs_terminate();
5df6d737
AJ
1123 return err;
1124}
1125
1126static void __exit fnic_cleanup_module(void)
1127{
1128 pci_unregister_driver(&fnic_driver);
1129 destroy_workqueue(fnic_event_queue);
d3c995f1
HP
1130 if (fnic_fip_queue) {
1131 flush_workqueue(fnic_fip_queue);
1132 destroy_workqueue(fnic_fip_queue);
1133 }
5df6d737
AJ
1134 kmem_cache_destroy(fnic_sgl_cache[FNIC_SGL_CACHE_MAX]);
1135 kmem_cache_destroy(fnic_sgl_cache[FNIC_SGL_CACHE_DFLT]);
1136 kmem_cache_destroy(fnic_io_req_cache);
1137 fc_release_transport(fnic_fc_transport);
4d7007b4 1138 fnic_trace_free();
67125b02 1139 fnic_debugfs_terminate();
5df6d737
AJ
1140}
1141
1142module_init(fnic_init_module);
1143module_exit(fnic_cleanup_module);
1144