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