18 #include <linux/module.h>
20 #include <linux/string.h>
21 #include <linux/slab.h>
22 #include <linux/errno.h>
24 #include <linux/pci.h>
29 #include <linux/if_ether.h>
44 #define PCI_DEVICE_ID_CISCO_FNIC 0x0045
47 #define FNIC_NOTIFY_TIMER_PERIOD (2 * HZ)
80 static int fnic_slave_alloc(
struct scsi_device *sdev)
86 if (!rport || fc_remote_port_chkready(rport))
100 .slave_alloc = fnic_slave_alloc,
108 .max_sectors = 0xffff,
113 fnic_set_rport_dev_loss_tmo(
struct fc_rport *rport,
u32 timeout)
127 .show_host_node_name = 1,
128 .show_host_port_name = 1,
129 .show_host_supported_classes = 1,
130 .show_host_supported_fc4s = 1,
131 .show_host_active_fc4s = 1,
132 .show_host_maxframe_size = 1,
133 .show_host_port_id = 1,
134 .show_host_supported_speeds = 1,
135 .get_host_speed = fnic_get_host_speed,
136 .show_host_speed = 1,
137 .show_host_port_type = 1,
139 .show_host_port_state = 1,
140 .show_host_symbolic_name = 1,
141 .show_rport_maxframe_size = 1,
142 .show_rport_supported_classes = 1,
143 .show_host_fabric_name = 1,
144 .show_starget_node_name = 1,
145 .show_starget_port_name = 1,
146 .show_starget_port_id = 1,
147 .show_rport_dev_loss_tmo = 1,
148 .set_rport_dev_loss_tmo = fnic_set_rport_dev_loss_tmo,
150 .get_fc_host_stats = fnic_get_stats,
163 switch (port_speed) {
176 struct fc_lport *lp = shost_priv(host);
177 struct fnic *fnic = lport_priv(lp);
188 spin_unlock_irqrestore(&fnic->
fnic_lock, flags);
192 "fnic: Get vnic stats failed"
198 stats->
tx_words = vs->
tx.tx_unicast_bytes_ok / 4;
200 stats->
rx_words = vs->
rx.rx_unicast_bytes_ok / 4;
217 error_status =
ioread32(&fnic->
wq[i].ctrl->error_status);
220 "WQ[%d] error_status"
221 " %d\n", i, error_status);
224 for (i = 0; i < fnic->
rq_count; i++) {
225 error_status =
ioread32(&fnic->
rq[i].ctrl->error_status);
228 "RQ[%d] error_status"
229 " %d\n", i, error_status);
236 "CWQ[%d] error_status"
237 " %d\n", i, error_status);
247 spin_unlock_irqrestore(&fnic->
fnic_lock, flags);
250 spin_unlock_irqrestore(&fnic->
fnic_lock, flags);
256 static int fnic_notify_set(
struct fnic *fnic)
272 "Interrupt mode should be set up"
273 " before devcmd notify set %d\n",
282 static void fnic_notify_timer(
unsigned long data)
284 struct fnic *fnic = (
struct fnic *)data;
291 static void fnic_notify_timer_start(
struct fnic *fnic)
316 err =
start(vdev, arg);
334 static int fnic_cleanup(
struct fnic *fnic)
343 for (i = 0; i < fnic->
rq_count; i++) {
367 for (i = 0; i < fnic->
rq_count; i++)
373 for (i = 0; i < fnic->
cq_count; i++)
385 static void fnic_iounmap(
struct fnic *fnic)
387 if (fnic->
bar0.vaddr)
397 struct fnic *fnic = lport_priv(lport);
417 lp = libfc_host_alloc(&fnic_host_template,
sizeof(
struct fnic));
424 fnic = lport_priv(lp);
436 "Unable to alloc shared tag map\n");
437 goto err_out_free_hba;
441 pci_set_drvdata(pdev, fnic);
448 "Cannot enable PCI device, aborting.\n");
449 goto err_out_free_hba;
455 "Cannot enable PCI resources, aborting\n");
456 goto err_out_disable_device;
470 "No usable DMA configuration "
472 goto err_out_release_regions;
474 err = pci_set_consistent_dma_mask(pdev,
DMA_BIT_MASK(32));
477 "Unable to obtain 32-bit DMA "
478 "for consistent allocations, aborting.\n");
479 goto err_out_release_regions;
482 err = pci_set_consistent_dma_mask(pdev,
DMA_BIT_MASK(40));
485 "Unable to obtain 40-bit DMA "
486 "for consistent allocations, aborting.\n");
487 goto err_out_release_regions;
494 "BAR0 not memory-map'able, aborting.\n");
496 goto err_out_release_regions;
499 fnic->
bar0.vaddr = pci_iomap(pdev, 0, 0);
503 if (!fnic->
bar0.vaddr) {
505 "Cannot memory-map BAR0 res hdr, "
508 goto err_out_release_regions;
514 "vNIC registration failed, "
517 goto err_out_iounmap;
524 "vNIC dev open failed, aborting.\n");
525 goto err_out_vnic_unregister;
531 "vNIC dev init failed, aborting.\n");
532 goto err_out_dev_close;
538 "vNIC get MAC addr failed \n");
539 goto err_out_dev_close;
548 "Get vNIC configuration failed, "
550 goto err_out_dev_close;
561 "Failed to set intr mode, "
563 goto err_out_dev_close;
569 "Failed to alloc vNIC resources, "
571 goto err_out_clear_intr;
591 fnic->
io_req_pool = mempool_create_slab_pool(2, fnic_io_req_cache);
593 goto err_out_free_resources;
597 goto err_out_free_ioreq_pool;
602 goto err_out_free_dflt_pool;
612 fnic->
ctlr.get_src_addr = fnic_get_mac;
615 "firmware supports FIP\n");
623 "firmware uses non-FIP mode\n");
632 err = fnic_notify_set(fnic);
635 "Failed to alloc notify buffer, aborting.\n");
636 goto err_out_free_max_pool;
642 fnic_notify_timer, (
unsigned long)fnic);
645 for (i = 0; i < fnic->
rq_count; i++) {
649 "fnic_alloc_rq_frame can't alloc "
651 goto err_out_free_rq_buf;
659 err = scsi_add_host(lp->
host, &pdev->
dev);
662 "fnic: scsi_add_host failed...exiting\n");
663 goto err_out_free_rq_buf;
681 fc_set_wwnn(lp, fnic->
config.node_wwn);
682 fc_set_wwpn(lp, fnic->
config.port_wwn);
689 goto err_out_remove_scsi_host;
692 fc_lport_init_stats(lp);
699 goto err_out_free_exch_mgr;
709 spin_unlock_irqrestore(&fnic_list_lock, flags);
714 skb_queue_head_init(&fnic->
tx_queue);
719 for (i = 0; i < fnic->
rq_count; i++)
731 "Unable to request irq.\n");
732 goto err_out_free_exch_mgr;
738 fnic_notify_timer_start(fnic);
742 err_out_free_exch_mgr:
744 err_out_remove_scsi_host:
748 for (i = 0; i < fnic->
rq_count; i++)
751 err_out_free_max_pool:
753 err_out_free_dflt_pool:
755 err_out_free_ioreq_pool:
757 err_out_free_resources:
763 err_out_vnic_unregister:
767 err_out_release_regions:
769 err_out_disable_device:
779 struct fnic *fnic = pci_get_drvdata(pdev);
791 spin_unlock_irqrestore(&fnic->
fnic_lock, flags);
813 spin_unlock_irqrestore(&fnic->
fnic_lock, flags);
830 spin_unlock_irqrestore(&fnic_list_lock, flags);
844 pci_set_drvdata(pdev,
NULL);
850 .id_table = fnic_id_table,
855 static int __init fnic_init_module(
void)
871 goto err_create_fnic_sgl_slab_dflt;
883 goto err_create_fnic_sgl_slab_max;
890 if (!fnic_io_req_cache) {
893 goto err_create_fnic_ioreq_slab;
900 goto err_create_fnic_workq;
904 INIT_LIST_HEAD(&fnic_list);
907 if (!fnic_fc_transport) {
910 goto err_fc_transport;
914 err = pci_register_driver(&fnic_driver);
917 goto err_pci_register;
925 err_create_fnic_workq:
927 err_create_fnic_ioreq_slab:
929 err_create_fnic_sgl_slab_max:
931 err_create_fnic_sgl_slab_dflt:
935 static void __exit fnic_cleanup_module(
void)