2 * Copyright 2008 Cisco Systems, Inc. All rights reserved.
3 * Copyright 2007 Nuova Systems, Inc. All rights reserved.
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.
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
18 #include <linux/module.h>
19 #include <linux/mempool.h>
20 #include <linux/string.h>
21 #include <linux/errno.h>
22 #include <linux/init.h>
23 #include <linux/pci.h>
24 #include <linux/skbuff.h>
25 #include <linux/interrupt.h>
26 #include <linux/spinlock.h>
27 #include <linux/workqueue.h>
28 #include <scsi/scsi_host.h>
29 #include <scsi/scsi_transport.h>
30 #include <scsi/scsi_transport_fc.h>
31 #include <scsi/scsi_tcq.h>
32 #include <scsi/libfc.h>
33 #include <scsi/fc_frame.h>
36 #include "vnic_intr.h"
37 #include "vnic_stats.h"
41 #define PCI_DEVICE_ID_CISCO_FNIC 0x0045
43 /* Timer to poll notification area for events. Used for MSI interrupts */
44 #define FNIC_NOTIFY_TIMER_PERIOD (2 * HZ)
46 static struct kmem_cache
*fnic_sgl_cache
[FNIC_SGL_NUM_CACHES
];
47 static struct kmem_cache
*fnic_io_req_cache
;
49 DEFINE_SPINLOCK(fnic_list_lock
);
51 /* Supported devices by fnic module */
52 static struct pci_device_id fnic_id_table
[] = {
53 { PCI_DEVICE(PCI_VENDOR_ID_CISCO
, PCI_DEVICE_ID_CISCO_FNIC
) },
57 MODULE_DESCRIPTION(DRV_DESCRIPTION
);
58 MODULE_AUTHOR("Abhijeet Joglekar <abjoglek@cisco.com>, "
59 "Joseph R. Eykholt <jeykholt@cisco.com>");
60 MODULE_LICENSE("GPL v2");
61 MODULE_VERSION(DRV_VERSION
);
62 MODULE_DEVICE_TABLE(pci
, fnic_id_table
);
64 unsigned int fnic_log_level
;
65 module_param(fnic_log_level
, int, S_IRUGO
|S_IWUSR
);
66 MODULE_PARM_DESC(fnic_log_level
, "bit mask of fnic logging levels");
69 static struct libfc_function_template fnic_transport_template
= {
70 .frame_send
= fnic_send
,
71 .fcp_abort_io
= fnic_empty_scsi_cleanup
,
72 .fcp_cleanup
= fnic_empty_scsi_cleanup
,
73 .exch_mgr_reset
= fnic_exch_mgr_reset
76 static int fnic_slave_alloc(struct scsi_device
*sdev
)
78 struct fc_rport
*rport
= starget_to_rport(scsi_target(sdev
));
79 struct fc_lport
*lp
= shost_priv(sdev
->host
);
80 struct fnic
*fnic
= lport_priv(lp
);
82 sdev
->tagged_supported
= 1;
84 if (!rport
|| fc_remote_port_chkready(rport
))
87 scsi_activate_tcq(sdev
, FNIC_DFLT_QUEUE_DEPTH
);
88 rport
->dev_loss_tmo
= fnic
->config
.port_down_timeout
/ 1000;
93 static struct scsi_host_template fnic_host_template
= {
94 .module
= THIS_MODULE
,
96 .queuecommand
= fnic_queuecommand
,
97 .eh_abort_handler
= fnic_abort_cmd
,
98 .eh_device_reset_handler
= fnic_device_reset
,
99 .eh_host_reset_handler
= fnic_host_reset
,
100 .slave_alloc
= fnic_slave_alloc
,
101 .change_queue_depth
= fc_change_queue_depth
,
102 .change_queue_type
= fc_change_queue_type
,
105 .can_queue
= FNIC_MAX_IO_REQ
,
106 .use_clustering
= ENABLE_CLUSTERING
,
107 .sg_tablesize
= FNIC_MAX_SG_DESC_CNT
,
108 .max_sectors
= 0xffff,
109 .shost_attrs
= fnic_attrs
,
112 static void fnic_get_host_speed(struct Scsi_Host
*shost
);
113 static struct scsi_transport_template
*fnic_fc_transport
;
114 static struct fc_host_statistics
*fnic_get_stats(struct Scsi_Host
*);
116 static struct fc_function_template fnic_fc_functions
= {
118 .show_host_node_name
= 1,
119 .show_host_port_name
= 1,
120 .show_host_supported_classes
= 1,
121 .show_host_supported_fc4s
= 1,
122 .show_host_active_fc4s
= 1,
123 .show_host_maxframe_size
= 1,
124 .show_host_port_id
= 1,
125 .show_host_supported_speeds
= 1,
126 .get_host_speed
= fnic_get_host_speed
,
127 .show_host_speed
= 1,
128 .show_host_port_type
= 1,
129 .get_host_port_state
= fc_get_host_port_state
,
130 .show_host_port_state
= 1,
131 .show_host_symbolic_name
= 1,
132 .show_rport_maxframe_size
= 1,
133 .show_rport_supported_classes
= 1,
134 .show_host_fabric_name
= 1,
135 .show_starget_node_name
= 1,
136 .show_starget_port_name
= 1,
137 .show_starget_port_id
= 1,
138 .show_rport_dev_loss_tmo
= 1,
139 .issue_fc_host_lip
= fnic_reset
,
140 .get_fc_host_stats
= fnic_get_stats
,
141 .dd_fcrport_size
= sizeof(struct fc_rport_libfc_priv
),
142 .terminate_rport_io
= fnic_terminate_rport_io
,
145 static void fnic_get_host_speed(struct Scsi_Host
*shost
)
147 struct fc_lport
*lp
= shost_priv(shost
);
148 struct fnic
*fnic
= lport_priv(lp
);
149 u32 port_speed
= vnic_dev_port_speed(fnic
->vdev
);
151 /* Add in other values as they get defined in fw */
152 switch (port_speed
) {
154 fc_host_speed(shost
) = FC_PORTSPEED_10GBIT
;
157 fc_host_speed(shost
) = FC_PORTSPEED_10GBIT
;
162 static struct fc_host_statistics
*fnic_get_stats(struct Scsi_Host
*host
)
165 struct fc_lport
*lp
= shost_priv(host
);
166 struct fnic
*fnic
= lport_priv(lp
);
167 struct fc_host_statistics
*stats
= &lp
->host_stats
;
168 struct vnic_stats
*vs
;
171 if (time_before(jiffies
, fnic
->stats_time
+ HZ
/ FNIC_STATS_RATE_LIMIT
))
173 fnic
->stats_time
= jiffies
;
175 spin_lock_irqsave(&fnic
->fnic_lock
, flags
);
176 ret
= vnic_dev_stats_dump(fnic
->vdev
, &fnic
->stats
);
177 spin_unlock_irqrestore(&fnic
->fnic_lock
, flags
);
180 FNIC_MAIN_DBG(KERN_DEBUG
, fnic
->lport
->host
,
181 "fnic: Get vnic stats failed"
186 stats
->tx_frames
= vs
->tx
.tx_unicast_frames_ok
;
187 stats
->tx_words
= vs
->tx
.tx_unicast_bytes_ok
/ 4;
188 stats
->rx_frames
= vs
->rx
.rx_unicast_frames_ok
;
189 stats
->rx_words
= vs
->rx
.rx_unicast_bytes_ok
/ 4;
190 stats
->error_frames
= vs
->tx
.tx_errors
+ vs
->rx
.rx_errors
;
191 stats
->dumped_frames
= vs
->tx
.tx_drops
+ vs
->rx
.rx_drop
;
192 stats
->invalid_crc_count
= vs
->rx
.rx_crc_errors
;
193 stats
->seconds_since_last_reset
= (jiffies
- lp
->boot_time
) / HZ
;
194 stats
->fcp_input_megabytes
= div_u64(fnic
->fcp_input_bytes
, 1000000);
195 stats
->fcp_output_megabytes
= div_u64(fnic
->fcp_output_bytes
, 1000000);
200 void fnic_log_q_error(struct fnic
*fnic
)
205 for (i
= 0; i
< fnic
->raw_wq_count
; i
++) {
206 error_status
= ioread32(&fnic
->wq
[i
].ctrl
->error_status
);
208 shost_printk(KERN_ERR
, fnic
->lport
->host
,
209 "WQ[%d] error_status"
210 " %d\n", i
, error_status
);
213 for (i
= 0; i
< fnic
->rq_count
; i
++) {
214 error_status
= ioread32(&fnic
->rq
[i
].ctrl
->error_status
);
216 shost_printk(KERN_ERR
, fnic
->lport
->host
,
217 "RQ[%d] error_status"
218 " %d\n", i
, error_status
);
221 for (i
= 0; i
< fnic
->wq_copy_count
; i
++) {
222 error_status
= ioread32(&fnic
->wq_copy
[i
].ctrl
->error_status
);
224 shost_printk(KERN_ERR
, fnic
->lport
->host
,
225 "CWQ[%d] error_status"
226 " %d\n", i
, error_status
);
230 void fnic_handle_link_event(struct fnic
*fnic
)
234 spin_lock_irqsave(&fnic
->fnic_lock
, flags
);
235 if (fnic
->stop_rx_link_events
) {
236 spin_unlock_irqrestore(&fnic
->fnic_lock
, flags
);
239 spin_unlock_irqrestore(&fnic
->fnic_lock
, flags
);
241 queue_work(fnic_event_queue
, &fnic
->link_work
);
245 static int fnic_notify_set(struct fnic
*fnic
)
249 switch (vnic_dev_get_intr_mode(fnic
->vdev
)) {
250 case VNIC_DEV_INTR_MODE_INTX
:
251 err
= vnic_dev_notify_set(fnic
->vdev
, FNIC_INTX_NOTIFY
);
253 case VNIC_DEV_INTR_MODE_MSI
:
254 err
= vnic_dev_notify_set(fnic
->vdev
, -1);
256 case VNIC_DEV_INTR_MODE_MSIX
:
257 err
= vnic_dev_notify_set(fnic
->vdev
, FNIC_MSIX_ERR_NOTIFY
);
260 shost_printk(KERN_ERR
, fnic
->lport
->host
,
261 "Interrupt mode should be set up"
262 " before devcmd notify set %d\n",
263 vnic_dev_get_intr_mode(fnic
->vdev
));
271 static void fnic_notify_timer(unsigned long data
)
273 struct fnic
*fnic
= (struct fnic
*)data
;
275 fnic_handle_link_event(fnic
);
276 mod_timer(&fnic
->notify_timer
,
277 round_jiffies(jiffies
+ FNIC_NOTIFY_TIMER_PERIOD
));
280 static void fnic_notify_timer_start(struct fnic
*fnic
)
282 switch (vnic_dev_get_intr_mode(fnic
->vdev
)) {
283 case VNIC_DEV_INTR_MODE_MSI
:
285 * Schedule first timeout immediately. The driver is
286 * initiatialized and ready to look for link up notification
288 mod_timer(&fnic
->notify_timer
, jiffies
);
291 /* Using intr for notification for INTx/MSI-X */
296 static int fnic_dev_wait(struct vnic_dev
*vdev
,
297 int (*start
)(struct vnic_dev
*, int),
298 int (*finished
)(struct vnic_dev
*, int *),
305 err
= start(vdev
, arg
);
309 /* Wait for func to complete...2 seconds max */
310 time
= jiffies
+ (HZ
* 2);
312 err
= finished(vdev
, &done
);
317 schedule_timeout_uninterruptible(HZ
/ 10);
318 } while (time_after(time
, jiffies
));
323 static int fnic_cleanup(struct fnic
*fnic
)
328 struct fc_frame
*flogi
= NULL
;
329 struct fc_frame
*flogi_resp
= NULL
;
331 vnic_dev_disable(fnic
->vdev
);
332 for (i
= 0; i
< fnic
->intr_count
; i
++)
333 vnic_intr_mask(&fnic
->intr
[i
]);
335 for (i
= 0; i
< fnic
->rq_count
; i
++) {
336 err
= vnic_rq_disable(&fnic
->rq
[i
]);
340 for (i
= 0; i
< fnic
->raw_wq_count
; i
++) {
341 err
= vnic_wq_disable(&fnic
->wq
[i
]);
345 for (i
= 0; i
< fnic
->wq_copy_count
; i
++) {
346 err
= vnic_wq_copy_disable(&fnic
->wq_copy
[i
]);
351 /* Clean up completed IOs and FCS frames */
352 fnic_wq_copy_cmpl_handler(fnic
, -1);
353 fnic_wq_cmpl_handler(fnic
, -1);
354 fnic_rq_cmpl_handler(fnic
, -1);
356 /* Clean up the IOs and FCS frames that have not completed */
357 for (i
= 0; i
< fnic
->raw_wq_count
; i
++)
358 vnic_wq_clean(&fnic
->wq
[i
], fnic_free_wq_buf
);
359 for (i
= 0; i
< fnic
->rq_count
; i
++)
360 vnic_rq_clean(&fnic
->rq
[i
], fnic_free_rq_buf
);
361 for (i
= 0; i
< fnic
->wq_copy_count
; i
++)
362 vnic_wq_copy_clean(&fnic
->wq_copy
[i
],
363 fnic_wq_copy_cleanup_handler
);
365 for (i
= 0; i
< fnic
->cq_count
; i
++)
366 vnic_cq_clean(&fnic
->cq
[i
]);
367 for (i
= 0; i
< fnic
->intr_count
; i
++)
368 vnic_intr_clean(&fnic
->intr
[i
]);
371 * Remove cached flogi and flogi resp frames if any
372 * These frames are not in any queue, and therefore queue
373 * cleanup does not clean them. So clean them explicitly
375 spin_lock_irqsave(&fnic
->fnic_lock
, flags
);
378 flogi_resp
= fnic
->flogi_resp
;
379 fnic
->flogi_resp
= NULL
;
380 spin_unlock_irqrestore(&fnic
->fnic_lock
, flags
);
383 dev_kfree_skb(fp_skb(flogi
));
386 dev_kfree_skb(fp_skb(flogi_resp
));
388 mempool_destroy(fnic
->io_req_pool
);
389 for (i
= 0; i
< FNIC_SGL_NUM_CACHES
; i
++)
390 mempool_destroy(fnic
->io_sgl_pool
[i
]);
395 static void fnic_iounmap(struct fnic
*fnic
)
397 if (fnic
->bar0
.vaddr
)
398 iounmap(fnic
->bar0
.vaddr
);
402 * Allocate element for mempools requiring GFP_DMA flag.
403 * Otherwise, checks in kmem_flagcheck() hit BUG_ON().
405 static void *fnic_alloc_slab_dma(gfp_t gfp_mask
, void *pool_data
)
407 struct kmem_cache
*mem
= pool_data
;
409 return kmem_cache_alloc(mem
, gfp_mask
| GFP_ATOMIC
| GFP_DMA
);
412 static int __devinit
fnic_probe(struct pci_dev
*pdev
,
413 const struct pci_device_id
*ent
)
415 struct Scsi_Host
*host
;
424 * Allocate SCSI Host and set up association between host,
425 * local port, and fnic
427 host
= scsi_host_alloc(&fnic_host_template
,
428 sizeof(struct fc_lport
) + sizeof(struct fnic
));
430 printk(KERN_ERR PFX
"Unable to alloc SCSI host\n");
434 lp
= shost_priv(host
);
436 fnic
= lport_priv(lp
);
439 snprintf(fnic
->name
, sizeof(fnic
->name
) - 1, "%s%d", DRV_NAME
,
442 host
->transportt
= fnic_fc_transport
;
444 err
= scsi_init_shared_tag_map(host
, FNIC_MAX_IO_REQ
);
446 shost_printk(KERN_ERR
, fnic
->lport
->host
,
447 "Unable to alloc shared tag map\n");
448 goto err_out_free_hba
;
451 /* Setup PCI resources */
452 pci_set_drvdata(pdev
, fnic
);
456 err
= pci_enable_device(pdev
);
458 shost_printk(KERN_ERR
, fnic
->lport
->host
,
459 "Cannot enable PCI device, aborting.\n");
460 goto err_out_free_hba
;
463 err
= pci_request_regions(pdev
, DRV_NAME
);
465 shost_printk(KERN_ERR
, fnic
->lport
->host
,
466 "Cannot enable PCI resources, aborting\n");
467 goto err_out_disable_device
;
470 pci_set_master(pdev
);
472 /* Query PCI controller on system for DMA addressing
473 * limitation for the device. Try 40-bit first, and
476 err
= pci_set_dma_mask(pdev
, DMA_BIT_MASK(40));
478 err
= pci_set_dma_mask(pdev
, DMA_BIT_MASK(32));
480 shost_printk(KERN_ERR
, fnic
->lport
->host
,
481 "No usable DMA configuration "
483 goto err_out_release_regions
;
485 err
= pci_set_consistent_dma_mask(pdev
, DMA_BIT_MASK(32));
487 shost_printk(KERN_ERR
, fnic
->lport
->host
,
488 "Unable to obtain 32-bit DMA "
489 "for consistent allocations, aborting.\n");
490 goto err_out_release_regions
;
493 err
= pci_set_consistent_dma_mask(pdev
, DMA_BIT_MASK(40));
495 shost_printk(KERN_ERR
, fnic
->lport
->host
,
496 "Unable to obtain 40-bit DMA "
497 "for consistent allocations, aborting.\n");
498 goto err_out_release_regions
;
502 /* Map vNIC resources from BAR0 */
503 if (!(pci_resource_flags(pdev
, 0) & IORESOURCE_MEM
)) {
504 shost_printk(KERN_ERR
, fnic
->lport
->host
,
505 "BAR0 not memory-map'able, aborting.\n");
507 goto err_out_release_regions
;
510 fnic
->bar0
.vaddr
= pci_iomap(pdev
, 0, 0);
511 fnic
->bar0
.bus_addr
= pci_resource_start(pdev
, 0);
512 fnic
->bar0
.len
= pci_resource_len(pdev
, 0);
514 if (!fnic
->bar0
.vaddr
) {
515 shost_printk(KERN_ERR
, fnic
->lport
->host
,
516 "Cannot memory-map BAR0 res hdr, "
519 goto err_out_release_regions
;
522 fnic
->vdev
= vnic_dev_register(NULL
, fnic
, pdev
, &fnic
->bar0
);
524 shost_printk(KERN_ERR
, fnic
->lport
->host
,
525 "vNIC registration failed, "
528 goto err_out_iounmap
;
531 err
= fnic_dev_wait(fnic
->vdev
, vnic_dev_open
,
532 vnic_dev_open_done
, 0);
534 shost_printk(KERN_ERR
, fnic
->lport
->host
,
535 "vNIC dev open failed, aborting.\n");
536 goto err_out_vnic_unregister
;
539 err
= vnic_dev_init(fnic
->vdev
, 0);
541 shost_printk(KERN_ERR
, fnic
->lport
->host
,
542 "vNIC dev init failed, aborting.\n");
543 goto err_out_dev_close
;
546 err
= vnic_dev_mac_addr(fnic
->vdev
, fnic
->mac_addr
);
548 shost_printk(KERN_ERR
, fnic
->lport
->host
,
549 "vNIC get MAC addr failed \n");
550 goto err_out_dev_close
;
553 /* Get vNIC configuration */
554 err
= fnic_get_vnic_config(fnic
);
556 shost_printk(KERN_ERR
, fnic
->lport
->host
,
557 "Get vNIC configuration failed, "
559 goto err_out_dev_close
;
561 host
->max_lun
= fnic
->config
.luns_per_tgt
;
562 host
->max_id
= FNIC_MAX_FCP_TARGET
;
564 fnic_get_res_counts(fnic
);
566 err
= fnic_set_intr_mode(fnic
);
568 shost_printk(KERN_ERR
, fnic
->lport
->host
,
569 "Failed to set intr mode, "
571 goto err_out_dev_close
;
574 err
= fnic_request_intr(fnic
);
576 shost_printk(KERN_ERR
, fnic
->lport
->host
,
577 "Unable to request irq.\n");
578 goto err_out_clear_intr
;
581 err
= fnic_alloc_vnic_resources(fnic
);
583 shost_printk(KERN_ERR
, fnic
->lport
->host
,
584 "Failed to alloc vNIC resources, "
586 goto err_out_free_intr
;
590 /* initialize all fnic locks */
591 spin_lock_init(&fnic
->fnic_lock
);
593 for (i
= 0; i
< FNIC_WQ_MAX
; i
++)
594 spin_lock_init(&fnic
->wq_lock
[i
]);
596 for (i
= 0; i
< FNIC_WQ_COPY_MAX
; i
++) {
597 spin_lock_init(&fnic
->wq_copy_lock
[i
]);
598 fnic
->wq_copy_desc_low
[i
] = DESC_CLEAN_LOW_WATERMARK
;
599 fnic
->fw_ack_recd
[i
] = 0;
600 fnic
->fw_ack_index
[i
] = -1;
603 for (i
= 0; i
< FNIC_IO_LOCKS
; i
++)
604 spin_lock_init(&fnic
->io_req_lock
[i
]);
606 fnic
->io_req_pool
= mempool_create_slab_pool(2, fnic_io_req_cache
);
607 if (!fnic
->io_req_pool
)
608 goto err_out_free_resources
;
610 pool
= mempool_create(2, fnic_alloc_slab_dma
, mempool_free_slab
,
611 fnic_sgl_cache
[FNIC_SGL_CACHE_DFLT
]);
613 goto err_out_free_ioreq_pool
;
614 fnic
->io_sgl_pool
[FNIC_SGL_CACHE_DFLT
] = pool
;
616 pool
= mempool_create(2, fnic_alloc_slab_dma
, mempool_free_slab
,
617 fnic_sgl_cache
[FNIC_SGL_CACHE_MAX
]);
619 goto err_out_free_dflt_pool
;
620 fnic
->io_sgl_pool
[FNIC_SGL_CACHE_MAX
] = pool
;
622 /* setup vlan config, hw inserts vlan header */
623 fnic
->vlan_hw_insert
= 1;
626 fnic
->flogi_oxid
= FC_XID_UNKNOWN
;
628 fnic
->flogi_resp
= NULL
;
629 fnic
->state
= FNIC_IN_FC_MODE
;
631 /* Enable hardware stripping of vlan header on ingress */
632 fnic_set_nic_config(fnic
, 0, 0, 0, 0, 0, 0, 1);
634 /* Setup notification buffer area */
635 err
= fnic_notify_set(fnic
);
637 shost_printk(KERN_ERR
, fnic
->lport
->host
,
638 "Failed to alloc notify buffer, aborting.\n");
639 goto err_out_free_max_pool
;
642 /* Setup notify timer when using MSI interrupts */
643 if (vnic_dev_get_intr_mode(fnic
->vdev
) == VNIC_DEV_INTR_MODE_MSI
)
644 setup_timer(&fnic
->notify_timer
,
645 fnic_notify_timer
, (unsigned long)fnic
);
647 /* allocate RQ buffers and post them to RQ*/
648 for (i
= 0; i
< fnic
->rq_count
; i
++) {
649 err
= vnic_rq_fill(&fnic
->rq
[i
], fnic_alloc_rq_frame
);
651 shost_printk(KERN_ERR
, fnic
->lport
->host
,
652 "fnic_alloc_rq_frame can't alloc "
654 goto err_out_free_rq_buf
;
659 * Initialization done with PCI system, hardware, firmware.
662 err
= scsi_add_host(lp
->host
, &pdev
->dev
);
664 shost_printk(KERN_ERR
, fnic
->lport
->host
,
665 "fnic: scsi_add_host failed...exiting\n");
666 goto err_out_free_rq_buf
;
669 /* Start local port initiatialization */
672 lp
->tt
= fnic_transport_template
;
674 lp
->max_retry_count
= fnic
->config
.flogi_retries
;
675 lp
->max_rport_retry_count
= fnic
->config
.plogi_retries
;
676 lp
->service_params
= (FCP_SPPF_INIT_FCN
| FCP_SPPF_RD_XRDY_DIS
|
677 FCP_SPPF_CONF_COMPL
);
678 if (fnic
->config
.flags
& VFCF_FCP_SEQ_LVL_ERR
)
679 lp
->service_params
|= FCP_SPPF_RETRY
;
681 lp
->boot_time
= jiffies
;
682 lp
->e_d_tov
= fnic
->config
.ed_tov
;
683 lp
->r_a_tov
= fnic
->config
.ra_tov
;
684 lp
->link_supported_speeds
= FC_PORTSPEED_10GBIT
;
685 fc_set_wwnn(lp
, fnic
->config
.node_wwn
);
686 fc_set_wwpn(lp
, fnic
->config
.port_wwn
);
694 if (!fc_exch_mgr_alloc(lp
, FC_CLASS_3
, FCPIO_HOST_EXCH_RANGE_START
,
695 FCPIO_HOST_EXCH_RANGE_END
, NULL
)) {
697 goto err_out_remove_scsi_host
;
702 if (fc_set_mfs(lp
, fnic
->config
.maxdatafieldsize
+
703 sizeof(struct fc_frame_header
))) {
705 goto err_out_free_exch_mgr
;
707 fc_host_maxframe_size(lp
->host
) = lp
->mfs
;
709 sprintf(fc_host_symbolic_name(lp
->host
),
710 DRV_NAME
" v" DRV_VERSION
" over %s", fnic
->name
);
712 spin_lock_irqsave(&fnic_list_lock
, flags
);
713 list_add_tail(&fnic
->list
, &fnic_list
);
714 spin_unlock_irqrestore(&fnic_list_lock
, flags
);
716 INIT_WORK(&fnic
->link_work
, fnic_handle_link
);
717 INIT_WORK(&fnic
->frame_work
, fnic_handle_frame
);
718 skb_queue_head_init(&fnic
->frame_queue
);
720 /* Enable all queues */
721 for (i
= 0; i
< fnic
->raw_wq_count
; i
++)
722 vnic_wq_enable(&fnic
->wq
[i
]);
723 for (i
= 0; i
< fnic
->rq_count
; i
++)
724 vnic_rq_enable(&fnic
->rq
[i
]);
725 for (i
= 0; i
< fnic
->wq_copy_count
; i
++)
726 vnic_wq_copy_enable(&fnic
->wq_copy
[i
]);
730 vnic_dev_enable(fnic
->vdev
);
731 for (i
= 0; i
< fnic
->intr_count
; i
++)
732 vnic_intr_unmask(&fnic
->intr
[i
]);
734 fnic_notify_timer_start(fnic
);
738 err_out_free_exch_mgr
:
739 fc_exch_mgr_free(lp
);
740 err_out_remove_scsi_host
:
741 fc_remove_host(fnic
->lport
->host
);
742 scsi_remove_host(fnic
->lport
->host
);
744 for (i
= 0; i
< fnic
->rq_count
; i
++)
745 vnic_rq_clean(&fnic
->rq
[i
], fnic_free_rq_buf
);
746 vnic_dev_notify_unset(fnic
->vdev
);
747 err_out_free_max_pool
:
748 mempool_destroy(fnic
->io_sgl_pool
[FNIC_SGL_CACHE_MAX
]);
749 err_out_free_dflt_pool
:
750 mempool_destroy(fnic
->io_sgl_pool
[FNIC_SGL_CACHE_DFLT
]);
751 err_out_free_ioreq_pool
:
752 mempool_destroy(fnic
->io_req_pool
);
753 err_out_free_resources
:
754 fnic_free_vnic_resources(fnic
);
756 fnic_free_intr(fnic
);
758 fnic_clear_intr_mode(fnic
);
760 vnic_dev_close(fnic
->vdev
);
761 err_out_vnic_unregister
:
762 vnic_dev_unregister(fnic
->vdev
);
765 err_out_release_regions
:
766 pci_release_regions(pdev
);
767 err_out_disable_device
:
768 pci_disable_device(pdev
);
770 scsi_host_put(lp
->host
);
775 static void __devexit
fnic_remove(struct pci_dev
*pdev
)
777 struct fnic
*fnic
= pci_get_drvdata(pdev
);
781 * Mark state so that the workqueue thread stops forwarding
782 * received frames and link events to the local port. ISR and
783 * other threads that can queue work items will also stop
784 * creating work items on the fnic workqueue
786 spin_lock_irqsave(&fnic
->fnic_lock
, flags
);
787 fnic
->stop_rx_link_events
= 1;
788 spin_unlock_irqrestore(&fnic
->fnic_lock
, flags
);
790 if (vnic_dev_get_intr_mode(fnic
->vdev
) == VNIC_DEV_INTR_MODE_MSI
)
791 del_timer_sync(&fnic
->notify_timer
);
794 * Flush the fnic event queue. After this call, there should
795 * be no event queued for this fnic device in the workqueue
797 flush_workqueue(fnic_event_queue
);
798 skb_queue_purge(&fnic
->frame_queue
);
801 * Log off the fabric. This stops all remote ports, dns port,
802 * logs off the fabric. This flushes all rport, disc, lport work
805 fc_fabric_logoff(fnic
->lport
);
807 spin_lock_irqsave(&fnic
->fnic_lock
, flags
);
809 spin_unlock_irqrestore(&fnic
->fnic_lock
, flags
);
811 fc_lport_destroy(fnic
->lport
);
814 * This stops the fnic device, masks all interrupts. Completed
815 * CQ entries are drained. Posted WQ/RQ/Copy-WQ entries are
820 BUG_ON(!skb_queue_empty(&fnic
->frame_queue
));
822 spin_lock_irqsave(&fnic_list_lock
, flags
);
823 list_del(&fnic
->list
);
824 spin_unlock_irqrestore(&fnic_list_lock
, flags
);
826 fc_remove_host(fnic
->lport
->host
);
827 scsi_remove_host(fnic
->lport
->host
);
828 fc_exch_mgr_free(fnic
->lport
);
829 vnic_dev_notify_unset(fnic
->vdev
);
830 fnic_free_vnic_resources(fnic
);
831 fnic_free_intr(fnic
);
832 fnic_clear_intr_mode(fnic
);
833 vnic_dev_close(fnic
->vdev
);
834 vnic_dev_unregister(fnic
->vdev
);
836 pci_release_regions(pdev
);
837 pci_disable_device(pdev
);
838 pci_set_drvdata(pdev
, NULL
);
839 scsi_host_put(fnic
->lport
->host
);
842 static struct pci_driver fnic_driver
= {
844 .id_table
= fnic_id_table
,
846 .remove
= __devexit_p(fnic_remove
),
849 static int __init
fnic_init_module(void)
854 printk(KERN_INFO PFX
"%s, ver %s\n", DRV_DESCRIPTION
, DRV_VERSION
);
856 /* Create a cache for allocation of default size sgls */
857 len
= sizeof(struct fnic_dflt_sgl_list
);
858 fnic_sgl_cache
[FNIC_SGL_CACHE_DFLT
] = kmem_cache_create
859 ("fnic_sgl_dflt", len
+ FNIC_SG_DESC_ALIGN
, FNIC_SG_DESC_ALIGN
,
860 SLAB_HWCACHE_ALIGN
| SLAB_CACHE_DMA
,
862 if (!fnic_sgl_cache
[FNIC_SGL_CACHE_DFLT
]) {
863 printk(KERN_ERR PFX
"failed to create fnic dflt sgl slab\n");
865 goto err_create_fnic_sgl_slab_dflt
;
868 /* Create a cache for allocation of max size sgls*/
869 len
= sizeof(struct fnic_sgl_list
);
870 fnic_sgl_cache
[FNIC_SGL_CACHE_MAX
] = kmem_cache_create
871 ("fnic_sgl_max", len
+ FNIC_SG_DESC_ALIGN
, FNIC_SG_DESC_ALIGN
,
872 SLAB_HWCACHE_ALIGN
| SLAB_CACHE_DMA
,
874 if (!fnic_sgl_cache
[FNIC_SGL_CACHE_MAX
]) {
875 printk(KERN_ERR PFX
"failed to create fnic max sgl slab\n");
877 goto err_create_fnic_sgl_slab_max
;
880 /* Create a cache of io_req structs for use via mempool */
881 fnic_io_req_cache
= kmem_cache_create("fnic_io_req",
882 sizeof(struct fnic_io_req
),
883 0, SLAB_HWCACHE_ALIGN
, NULL
);
884 if (!fnic_io_req_cache
) {
885 printk(KERN_ERR PFX
"failed to create fnic io_req slab\n");
887 goto err_create_fnic_ioreq_slab
;
890 fnic_event_queue
= create_singlethread_workqueue("fnic_event_wq");
891 if (!fnic_event_queue
) {
892 printk(KERN_ERR PFX
"fnic work queue create failed\n");
894 goto err_create_fnic_workq
;
897 spin_lock_init(&fnic_list_lock
);
898 INIT_LIST_HEAD(&fnic_list
);
900 fnic_fc_transport
= fc_attach_transport(&fnic_fc_functions
);
901 if (!fnic_fc_transport
) {
902 printk(KERN_ERR PFX
"fc_attach_transport error\n");
904 goto err_fc_transport
;
907 /* register the driver with PCI system */
908 err
= pci_register_driver(&fnic_driver
);
910 printk(KERN_ERR PFX
"pci register error\n");
911 goto err_pci_register
;
916 fc_release_transport(fnic_fc_transport
);
918 destroy_workqueue(fnic_event_queue
);
919 err_create_fnic_workq
:
920 kmem_cache_destroy(fnic_io_req_cache
);
921 err_create_fnic_ioreq_slab
:
922 kmem_cache_destroy(fnic_sgl_cache
[FNIC_SGL_CACHE_MAX
]);
923 err_create_fnic_sgl_slab_max
:
924 kmem_cache_destroy(fnic_sgl_cache
[FNIC_SGL_CACHE_DFLT
]);
925 err_create_fnic_sgl_slab_dflt
:
929 static void __exit
fnic_cleanup_module(void)
931 pci_unregister_driver(&fnic_driver
);
932 destroy_workqueue(fnic_event_queue
);
933 kmem_cache_destroy(fnic_sgl_cache
[FNIC_SGL_CACHE_MAX
]);
934 kmem_cache_destroy(fnic_sgl_cache
[FNIC_SGL_CACHE_DFLT
]);
935 kmem_cache_destroy(fnic_io_req_cache
);
936 fc_release_transport(fnic_fc_transport
);
939 module_init(fnic_init_module
);
940 module_exit(fnic_cleanup_module
);