2 * Copyright 2014 Cisco Systems, Inc. All rights reserved.
4 * This program is free software; you may redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 2 of the License.
8 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
9 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
10 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
11 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
12 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
13 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
14 * 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/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 <scsi/scsi_host.h>
30 #include <scsi/scsi_tcq.h>
33 #include "snic_fwint.h"
35 #define PCI_DEVICE_ID_CISCO_SNIC 0x0046
37 /* Supported devices by snic module */
38 static struct pci_device_id snic_id_table
[] = {
39 {PCI_DEVICE(0x1137, PCI_DEVICE_ID_CISCO_SNIC
) },
40 { 0, } /* end of table */
43 unsigned int snic_log_level
= 0x0;
44 module_param(snic_log_level
, int, S_IRUGO
|S_IWUSR
);
45 MODULE_PARM_DESC(snic_log_level
, "bitmask for snic logging levels");
47 #ifdef CONFIG_SCSI_SNIC_DEBUG_FS
48 unsigned int snic_trace_max_pages
= 16;
49 module_param(snic_trace_max_pages
, uint
, S_IRUGO
|S_IWUSR
);
50 MODULE_PARM_DESC(snic_trace_max_pages
,
51 "Total allocated memory pages for snic trace buffer");
54 unsigned int snic_max_qdepth
= SNIC_DFLT_QUEUE_DEPTH
;
55 module_param(snic_max_qdepth
, uint
, S_IRUGO
| S_IWUSR
);
56 MODULE_PARM_DESC(snic_max_qdepth
, "Queue depth to report for each LUN");
59 * snic_slave_alloc : callback function to SCSI Mid Layer, called on
60 * scsi device initialization.
63 snic_slave_alloc(struct scsi_device
*sdev
)
65 struct snic_tgt
*tgt
= starget_to_tgt(scsi_target(sdev
));
67 if (!tgt
|| snic_tgt_chkready(tgt
))
74 * snic_slave_configure : callback function to SCSI Mid Layer, called on
75 * scsi device initialization.
78 snic_slave_configure(struct scsi_device
*sdev
)
80 struct snic
*snic
= shost_priv(sdev
->host
);
81 u32 qdepth
= 0, max_ios
= 0;
82 int tmo
= SNIC_DFLT_CMD_TIMEOUT
* HZ
;
85 max_ios
= snic_max_qdepth
;
86 qdepth
= min_t(u32
, max_ios
, SNIC_MAX_QUEUE_DEPTH
);
87 scsi_change_queue_depth(sdev
, qdepth
);
89 if (snic
->fwinfo
.io_tmo
> 1)
90 tmo
= snic
->fwinfo
.io_tmo
* HZ
;
92 /* FW requires extended timeouts */
93 blk_queue_rq_timeout(sdev
->request_queue
, tmo
);
99 snic_change_queue_depth(struct scsi_device
*sdev
, int qdepth
)
103 qsz
= min_t(u32
, qdepth
, SNIC_MAX_QUEUE_DEPTH
);
104 scsi_change_queue_depth(sdev
, qsz
);
105 SNIC_INFO("QDepth Changed to %d\n", sdev
->queue_depth
);
107 return sdev
->queue_depth
;
110 static struct scsi_host_template snic_host_template
= {
111 .module
= THIS_MODULE
,
112 .name
= SNIC_DRV_NAME
,
113 .queuecommand
= snic_queuecommand
,
114 .eh_abort_handler
= snic_abort_cmd
,
115 .eh_device_reset_handler
= snic_device_reset
,
116 .eh_host_reset_handler
= snic_host_reset
,
117 .slave_alloc
= snic_slave_alloc
,
118 .slave_configure
= snic_slave_configure
,
119 .change_queue_depth
= snic_change_queue_depth
,
121 .cmd_per_lun
= SNIC_DFLT_QUEUE_DEPTH
,
122 .can_queue
= SNIC_MAX_IO_REQ
,
123 .use_clustering
= ENABLE_CLUSTERING
,
124 .sg_tablesize
= SNIC_MAX_SG_DESC_CNT
,
125 .max_sectors
= 0x800,
126 .shost_attrs
= snic_attrs
,
127 .track_queue_depth
= 1,
128 .cmd_size
= sizeof(struct snic_internal_io_state
),
129 .proc_name
= "snic_scsi",
133 * snic_handle_link_event : Handles link events such as link up/down/error
136 snic_handle_link_event(struct snic
*snic
)
140 spin_lock_irqsave(&snic
->snic_lock
, flags
);
141 if (snic
->stop_link_events
) {
142 spin_unlock_irqrestore(&snic
->snic_lock
, flags
);
146 spin_unlock_irqrestore(&snic
->snic_lock
, flags
);
148 queue_work(snic_glob
->event_q
, &snic
->link_work
);
149 } /* end of snic_handle_link_event */
152 * snic_notify_set : sets notification area
153 * This notification area is to receive events from fw
154 * Note: snic supports only MSIX interrupts, in which we can just call
155 * svnic_dev_notify_set directly
158 snic_notify_set(struct snic
*snic
)
161 enum vnic_dev_intr_mode intr_mode
;
163 intr_mode
= svnic_dev_get_intr_mode(snic
->vdev
);
165 if (intr_mode
== VNIC_DEV_INTR_MODE_MSIX
) {
166 ret
= svnic_dev_notify_set(snic
->vdev
, SNIC_MSIX_ERR_NOTIFY
);
168 SNIC_HOST_ERR(snic
->shost
,
169 "Interrupt mode should be setup before devcmd notify set %d\n",
175 } /* end of snic_notify_set */
178 * snic_dev_wait : polls vnic open status.
181 snic_dev_wait(struct vnic_dev
*vdev
,
182 int (*start
)(struct vnic_dev
*, int),
183 int (*finished
)(struct vnic_dev
*, int *),
190 ret
= start(vdev
, arg
);
195 * Wait for func to complete...2 seconds max.
197 * Sometimes schedule_timeout_uninterruptible take long time
198 * to wakeup, which results skipping retry. The retry counter
199 * ensures to retry at least two times.
201 time
= jiffies
+ (HZ
* 2);
203 ret
= finished(vdev
, &done
);
209 schedule_timeout_uninterruptible(HZ
/10);
211 } while (time_after(time
, jiffies
) || (retry_cnt
< 3));
214 } /* end of snic_dev_wait */
217 * snic_cleanup: called by snic_remove
218 * Stops the snic device, masks all interrupts, Completed CQ entries are
219 * drained. Posted WQ/RQ/Copy-WQ entries are cleanup
222 snic_cleanup(struct snic
*snic
)
227 svnic_dev_disable(snic
->vdev
);
228 for (i
= 0; i
< snic
->intr_count
; i
++)
229 svnic_intr_mask(&snic
->intr
[i
]);
231 for (i
= 0; i
< snic
->wq_count
; i
++) {
232 ret
= svnic_wq_disable(&snic
->wq
[i
]);
237 /* Clean up completed IOs */
238 snic_fwcq_cmpl_handler(snic
, -1);
240 snic_wq_cmpl_handler(snic
, -1);
242 /* Clean up the IOs that have not completed */
243 for (i
= 0; i
< snic
->wq_count
; i
++)
244 svnic_wq_clean(&snic
->wq
[i
], snic_free_wq_buf
);
246 for (i
= 0; i
< snic
->cq_count
; i
++)
247 svnic_cq_clean(&snic
->cq
[i
]);
249 for (i
= 0; i
< snic
->intr_count
; i
++)
250 svnic_intr_clean(&snic
->intr
[i
]);
252 /* Cleanup snic specific requests */
253 snic_free_all_untagged_reqs(snic
);
255 /* Cleanup Pending SCSI commands */
256 snic_shutdown_scsi_cleanup(snic
);
258 for (i
= 0; i
< SNIC_REQ_MAX_CACHES
; i
++)
259 mempool_destroy(snic
->req_pool
[i
]);
262 } /* end of snic_cleanup */
266 snic_iounmap(struct snic
*snic
)
268 if (snic
->bar0
.vaddr
)
269 iounmap(snic
->bar0
.vaddr
);
273 * snic_vdev_open_done : polls for svnic_dev_open cmd completion.
276 snic_vdev_open_done(struct vnic_dev
*vdev
, int *done
)
278 struct snic
*snic
= svnic_dev_priv(vdev
);
283 ret
= svnic_dev_open_done(vdev
, done
);
287 SNIC_HOST_INFO(snic
->shost
, "VNIC_DEV_OPEN Timedout.\n");
288 } while (nretries
--);
291 } /* end of snic_vdev_open_done */
294 * snic_add_host : registers scsi host with ML
297 snic_add_host(struct Scsi_Host
*shost
, struct pci_dev
*pdev
)
301 ret
= scsi_add_host(shost
, &pdev
->dev
);
304 "snic: scsi_add_host failed. %d\n",
310 SNIC_BUG_ON(shost
->work_q
!= NULL
);
311 snprintf(shost
->work_q_name
, sizeof(shost
->work_q_name
), "scsi_wq_%d",
313 shost
->work_q
= create_singlethread_workqueue(shost
->work_q_name
);
314 if (!shost
->work_q
) {
315 SNIC_HOST_ERR(shost
, "Failed to Create ScsiHost wq.\n");
321 } /* end of snic_add_host */
324 snic_del_host(struct Scsi_Host
*shost
)
329 destroy_workqueue(shost
->work_q
);
330 shost
->work_q
= NULL
;
331 scsi_remove_host(shost
);
335 snic_get_state(struct snic
*snic
)
337 return atomic_read(&snic
->state
);
341 snic_set_state(struct snic
*snic
, enum snic_state state
)
343 SNIC_HOST_INFO(snic
->shost
, "snic state change from %s to %s\n",
344 snic_state_to_str(snic_get_state(snic
)),
345 snic_state_to_str(state
));
347 atomic_set(&snic
->state
, state
);
351 * snic_probe : Initialize the snic interface.
354 snic_probe(struct pci_dev
*pdev
, const struct pci_device_id
*ent
)
356 struct Scsi_Host
*shost
;
363 /* Device Information */
364 SNIC_INFO("snic device %4x:%4x:%4x:%4x: ",
365 pdev
->vendor
, pdev
->device
, pdev
->subsystem_vendor
,
366 pdev
->subsystem_device
);
368 SNIC_INFO("snic device bus %x: slot %x: fn %x\n",
369 pdev
->bus
->number
, PCI_SLOT(pdev
->devfn
),
370 PCI_FUNC(pdev
->devfn
));
373 * Allocate SCSI Host and setup association between host, and snic
375 shost
= scsi_host_alloc(&snic_host_template
, sizeof(struct snic
));
377 SNIC_ERR("Unable to alloc scsi_host\n");
382 snic
= shost_priv(shost
);
385 snprintf(snic
->name
, sizeof(snic
->name
) - 1, "%s%d", SNIC_DRV_NAME
,
388 SNIC_HOST_INFO(shost
,
389 "snic%d = %p shost = %p device bus %x: slot %x: fn %x\n",
390 shost
->host_no
, snic
, shost
, pdev
->bus
->number
,
391 PCI_SLOT(pdev
->devfn
), PCI_FUNC(pdev
->devfn
));
392 #ifdef CONFIG_SCSI_SNIC_DEBUG_FS
393 /* Per snic debugfs init */
394 ret
= snic_stats_debugfs_init(snic
);
396 SNIC_HOST_ERR(snic
->shost
,
397 "Failed to initialize debugfs stats\n");
398 snic_stats_debugfs_remove(snic
);
402 /* Setup PCI Resources */
403 pci_set_drvdata(pdev
, snic
);
406 ret
= pci_enable_device(pdev
);
409 "Cannot enable PCI Resources, aborting : %d\n",
415 ret
= pci_request_regions(pdev
, SNIC_DRV_NAME
);
418 "Cannot obtain PCI Resources, aborting : %d\n",
421 goto err_pci_disable
;
424 pci_set_master(pdev
);
427 * Query PCI Controller on system for DMA addressing
428 * limitation for the device. Try 43-bit first, and
431 ret
= pci_set_dma_mask(pdev
, DMA_BIT_MASK(43));
433 ret
= pci_set_dma_mask(pdev
, DMA_BIT_MASK(32));
436 "No Usable DMA Configuration, aborting %d\n",
439 goto err_rel_regions
;
442 ret
= pci_set_consistent_dma_mask(pdev
, DMA_BIT_MASK(32));
445 "Unable to obtain 32-bit DMA for consistent allocations, aborting: %d\n",
448 goto err_rel_regions
;
451 ret
= pci_set_consistent_dma_mask(pdev
, DMA_BIT_MASK(43));
454 "Unable to obtain 43-bit DMA for consistent allocations. aborting: %d\n",
457 goto err_rel_regions
;
462 /* Map vNIC resources from BAR0 */
463 if (!(pci_resource_flags(pdev
, 0) & IORESOURCE_MEM
)) {
464 SNIC_HOST_ERR(shost
, "BAR0 not memory mappable aborting.\n");
467 goto err_rel_regions
;
470 snic
->bar0
.vaddr
= pci_iomap(pdev
, 0, 0);
471 if (!snic
->bar0
.vaddr
) {
473 "Cannot memory map BAR0 res hdr aborting.\n");
476 goto err_rel_regions
;
479 snic
->bar0
.bus_addr
= pci_resource_start(pdev
, 0);
480 snic
->bar0
.len
= pci_resource_len(pdev
, 0);
481 SNIC_BUG_ON(snic
->bar0
.bus_addr
== 0);
483 /* Devcmd2 Resource Allocation and Initialization */
484 snic
->vdev
= svnic_dev_alloc_discover(NULL
, snic
, pdev
, &snic
->bar0
, 1);
486 SNIC_HOST_ERR(shost
, "vNIC Resource Discovery Failed.\n");
492 ret
= svnic_dev_cmd_init(snic
->vdev
, 0);
494 SNIC_HOST_INFO(shost
, "Devcmd2 Init Failed. err = %d\n", ret
);
499 ret
= snic_dev_wait(snic
->vdev
, svnic_dev_open
, snic_vdev_open_done
, 0);
502 "vNIC dev open failed, aborting. %d\n",
508 ret
= svnic_dev_init(snic
->vdev
, 0);
511 "vNIC dev init failed. aborting. %d\n",
517 /* Get vNIC information */
518 ret
= snic_get_vnic_config(snic
);
521 "Get vNIC configuration failed, aborting. %d\n",
527 /* Configure Maximum Outstanding IO reqs */
528 max_ios
= snic
->config
.io_throttle_count
;
529 if (max_ios
!= SNIC_UCSM_DFLT_THROTTLE_CNT_BLD
)
530 shost
->can_queue
= min_t(u32
, SNIC_MAX_IO_REQ
,
531 max_t(u32
, SNIC_MIN_IO_REQ
, max_ios
));
533 snic
->max_tag_id
= shost
->can_queue
;
535 shost
->max_lun
= snic
->config
.luns_per_tgt
;
536 shost
->max_id
= SNIC_MAX_TARGET
;
538 shost
->max_cmd_len
= MAX_COMMAND_SIZE
; /*defined in scsi_cmnd.h*/
540 snic_get_res_counts(snic
);
543 * Assumption: Only MSIx is supported
545 ret
= snic_set_intr_mode(snic
);
548 "Failed to set intr mode aborting. %d\n",
554 ret
= snic_alloc_vnic_res(snic
);
557 "Failed to alloc vNIC resources aborting. %d\n",
563 /* Initialize specific lists */
564 INIT_LIST_HEAD(&snic
->list
);
567 * spl_cmd_list for maintaining snic specific cmds
568 * such as EXCH_VER_REQ, REPORT_TARGETS etc
570 INIT_LIST_HEAD(&snic
->spl_cmd_list
);
571 spin_lock_init(&snic
->spl_cmd_lock
);
573 /* initialize all snic locks */
574 spin_lock_init(&snic
->snic_lock
);
576 for (i
= 0; i
< SNIC_WQ_MAX
; i
++)
577 spin_lock_init(&snic
->wq_lock
[i
]);
579 for (i
= 0; i
< SNIC_IO_LOCKS
; i
++)
580 spin_lock_init(&snic
->io_req_lock
[i
]);
582 pool
= mempool_create_slab_pool(2,
583 snic_glob
->req_cache
[SNIC_REQ_CACHE_DFLT_SGL
]);
585 SNIC_HOST_ERR(shost
, "dflt sgl pool creation failed\n");
591 snic
->req_pool
[SNIC_REQ_CACHE_DFLT_SGL
] = pool
;
593 pool
= mempool_create_slab_pool(2,
594 snic_glob
->req_cache
[SNIC_REQ_CACHE_MAX_SGL
]);
596 SNIC_HOST_ERR(shost
, "max sgl pool creation failed\n");
599 goto err_free_dflt_sgl_pool
;
602 snic
->req_pool
[SNIC_REQ_CACHE_MAX_SGL
] = pool
;
604 pool
= mempool_create_slab_pool(2,
605 snic_glob
->req_cache
[SNIC_REQ_TM_CACHE
]);
607 SNIC_HOST_ERR(shost
, "snic tmreq info pool creation failed.\n");
610 goto err_free_max_sgl_pool
;
613 snic
->req_pool
[SNIC_REQ_TM_CACHE
] = pool
;
615 /* Initialize snic state */
616 atomic_set(&snic
->state
, SNIC_INIT
);
618 atomic_set(&snic
->ios_inflight
, 0);
620 /* Setup notification buffer area */
621 ret
= snic_notify_set(snic
);
624 "Failed to alloc notify buffer aborting. %d\n",
627 goto err_free_tmreq_pool
;
631 * Initialization done with PCI system, hardware, firmware.
634 ret
= snic_add_host(shost
, pdev
);
637 "Adding scsi host Failed ... exiting. %d\n",
640 goto err_notify_unset
;
643 spin_lock_irqsave(&snic_glob
->snic_list_lock
, flags
);
644 list_add_tail(&snic
->list
, &snic_glob
->snic_list
);
645 spin_unlock_irqrestore(&snic_glob
->snic_list_lock
, flags
);
647 snic_disc_init(&snic
->disc
);
648 INIT_WORK(&snic
->tgt_work
, snic_handle_tgt_disc
);
649 INIT_WORK(&snic
->disc_work
, snic_handle_disc
);
650 INIT_WORK(&snic
->link_work
, snic_handle_link
);
652 /* Enable all queues */
653 for (i
= 0; i
< snic
->wq_count
; i
++)
654 svnic_wq_enable(&snic
->wq
[i
]);
656 ret
= svnic_dev_enable_wait(snic
->vdev
);
659 "vNIC dev enable failed w/ error %d\n",
662 goto err_vdev_enable
;
665 ret
= snic_request_intr(snic
);
667 SNIC_HOST_ERR(shost
, "Unable to request irq. %d\n", ret
);
672 for (i
= 0; i
< snic
->intr_count
; i
++)
673 svnic_intr_unmask(&snic
->intr
[i
]);
675 snic_set_state(snic
, SNIC_ONLINE
);
677 /* Get snic params */
678 ret
= snic_get_conf(snic
);
681 "Failed to get snic io config from FW w err %d\n",
687 ret
= snic_disc_start(snic
);
689 SNIC_HOST_ERR(shost
, "snic_probe:Discovery Failed w err = %d\n",
695 SNIC_HOST_INFO(shost
, "SNIC Device Probe Successful.\n");
700 snic_free_all_untagged_reqs(snic
);
702 for (i
= 0; i
< snic
->intr_count
; i
++)
703 svnic_intr_mask(&snic
->intr
[i
]);
705 snic_free_intr(snic
);
708 svnic_dev_disable(snic
->vdev
);
711 for (i
= 0; i
< snic
->wq_count
; i
++) {
714 rc
= svnic_wq_disable(&snic
->wq
[i
]);
717 "WQ Disable Failed w/ err = %d\n", rc
);
722 snic_del_host(snic
->shost
);
725 svnic_dev_notify_unset(snic
->vdev
);
728 mempool_destroy(snic
->req_pool
[SNIC_REQ_TM_CACHE
]);
730 err_free_max_sgl_pool
:
731 mempool_destroy(snic
->req_pool
[SNIC_REQ_CACHE_MAX_SGL
]);
733 err_free_dflt_sgl_pool
:
734 mempool_destroy(snic
->req_pool
[SNIC_REQ_CACHE_DFLT_SGL
]);
737 snic_free_vnic_res(snic
);
740 snic_clear_intr_mode(snic
);
743 svnic_dev_close(snic
->vdev
);
746 svnic_dev_unregister(snic
->vdev
);
752 pci_release_regions(pdev
);
755 pci_disable_device(pdev
);
758 #ifdef CONFIG_SCSI_SNIC_DEBUG_FS
759 snic_stats_debugfs_remove(snic
);
761 scsi_host_put(shost
);
762 pci_set_drvdata(pdev
, NULL
);
765 SNIC_INFO("sNIC device : bus %d: slot %d: fn %d Registration Failed.\n",
766 pdev
->bus
->number
, PCI_SLOT(pdev
->devfn
),
767 PCI_FUNC(pdev
->devfn
));
770 } /* end of snic_probe */
774 * snic_remove : invoked on unbinding the interface to cleanup the
775 * resources allocated in snic_probe on initialization.
778 snic_remove(struct pci_dev
*pdev
)
780 struct snic
*snic
= pci_get_drvdata(pdev
);
784 SNIC_INFO("sNIC dev: bus %d slot %d fn %d snic inst is null.\n",
785 pdev
->bus
->number
, PCI_SLOT(pdev
->devfn
),
786 PCI_FUNC(pdev
->devfn
));
792 * Mark state so that the workqueue thread stops forwarding
793 * received frames and link events. ISR and other threads
794 * that can queue work items will also stop creating work
795 * items on the snic workqueue
797 snic_set_state(snic
, SNIC_OFFLINE
);
798 spin_lock_irqsave(&snic
->snic_lock
, flags
);
799 snic
->stop_link_events
= 1;
800 spin_unlock_irqrestore(&snic
->snic_lock
, flags
);
802 flush_workqueue(snic_glob
->event_q
);
803 snic_disc_term(snic
);
805 spin_lock_irqsave(&snic
->snic_lock
, flags
);
807 spin_unlock_irqrestore(&snic
->snic_lock
, flags
);
810 * This stops the snic device, masks all interrupts, Completed
811 * CQ entries are drained. Posted WQ/RQ/Copy-WQ entries are
816 spin_lock_irqsave(&snic_glob
->snic_list_lock
, flags
);
817 list_del(&snic
->list
);
818 spin_unlock_irqrestore(&snic_glob
->snic_list_lock
, flags
);
820 snic_tgt_del_all(snic
);
821 #ifdef CONFIG_SCSI_SNIC_DEBUG_FS
822 snic_stats_debugfs_remove(snic
);
824 snic_del_host(snic
->shost
);
826 svnic_dev_notify_unset(snic
->vdev
);
827 snic_free_intr(snic
);
828 snic_free_vnic_res(snic
);
829 snic_clear_intr_mode(snic
);
830 svnic_dev_close(snic
->vdev
);
831 svnic_dev_unregister(snic
->vdev
);
833 pci_release_regions(pdev
);
834 pci_disable_device(pdev
);
835 pci_set_drvdata(pdev
, NULL
);
837 /* this frees Scsi_Host and snic memory (continuous chunk) */
838 scsi_host_put(snic
->shost
);
839 } /* end of snic_remove */
842 struct snic_global
*snic_glob
;
845 * snic_global_data_init: Initialize SNIC Global Data
846 * Notes: All the global lists, variables should be part of global data
847 * this helps in debugging.
850 snic_global_data_init(void)
853 struct kmem_cache
*cachep
;
856 snic_glob
= kzalloc(sizeof(*snic_glob
), GFP_KERNEL
);
859 SNIC_ERR("Failed to allocate Global Context.\n");
865 #ifdef CONFIG_SCSI_SNIC_DEBUG_FS
866 /* Debugfs related Initialization */
867 /* Create debugfs entries for snic */
868 ret
= snic_debugfs_init();
870 SNIC_ERR("Failed to create sysfs dir for tracing and stats.\n");
872 /* continue even if it fails */
875 /* Trace related Initialization */
876 /* Allocate memory for trace buffer */
877 ret
= snic_trc_init();
879 SNIC_ERR("Trace buffer init failed, SNIC tracing disabled\n");
881 /* continue even if it fails */
885 INIT_LIST_HEAD(&snic_glob
->snic_list
);
886 spin_lock_init(&snic_glob
->snic_list_lock
);
888 /* Create a cache for allocation of snic_host_req+default size ESGLs */
889 len
= sizeof(struct snic_req_info
);
890 len
+= sizeof(struct snic_host_req
) + sizeof(struct snic_dflt_sgl
);
891 cachep
= kmem_cache_create("snic_req_dfltsgl", len
, SNIC_SG_DESC_ALIGN
,
892 SLAB_HWCACHE_ALIGN
, NULL
);
894 SNIC_ERR("Failed to create snic default sgl slab\n");
897 goto err_dflt_req_slab
;
899 snic_glob
->req_cache
[SNIC_REQ_CACHE_DFLT_SGL
] = cachep
;
901 /* Create a cache for allocation of max size Extended SGLs */
902 len
= sizeof(struct snic_req_info
);
903 len
+= sizeof(struct snic_host_req
) + sizeof(struct snic_max_sgl
);
904 cachep
= kmem_cache_create("snic_req_maxsgl", len
, SNIC_SG_DESC_ALIGN
,
905 SLAB_HWCACHE_ALIGN
, NULL
);
907 SNIC_ERR("Failed to create snic max sgl slab\n");
910 goto err_max_req_slab
;
912 snic_glob
->req_cache
[SNIC_REQ_CACHE_MAX_SGL
] = cachep
;
914 len
= sizeof(struct snic_host_req
);
915 cachep
= kmem_cache_create("snic_req_maxsgl", len
, SNIC_SG_DESC_ALIGN
,
916 SLAB_HWCACHE_ALIGN
, NULL
);
918 SNIC_ERR("Failed to create snic tm req slab\n");
923 snic_glob
->req_cache
[SNIC_REQ_TM_CACHE
] = cachep
;
925 /* snic_event queue */
926 snic_glob
->event_q
= create_singlethread_workqueue("snic_event_wq");
927 if (!snic_glob
->event_q
) {
928 SNIC_ERR("snic event queue create failed\n");
937 kmem_cache_destroy(snic_glob
->req_cache
[SNIC_REQ_TM_CACHE
]);
940 kmem_cache_destroy(snic_glob
->req_cache
[SNIC_REQ_CACHE_MAX_SGL
]);
943 kmem_cache_destroy(snic_glob
->req_cache
[SNIC_REQ_CACHE_DFLT_SGL
]);
946 #ifdef CONFIG_SCSI_SNIC_DEBUG_FS
955 } /* end of snic_glob_init */
958 * snic_global_data_cleanup : Frees SNIC Global Data
961 snic_global_data_cleanup(void)
963 SNIC_BUG_ON(snic_glob
== NULL
);
965 destroy_workqueue(snic_glob
->event_q
);
966 kmem_cache_destroy(snic_glob
->req_cache
[SNIC_REQ_TM_CACHE
]);
967 kmem_cache_destroy(snic_glob
->req_cache
[SNIC_REQ_CACHE_MAX_SGL
]);
968 kmem_cache_destroy(snic_glob
->req_cache
[SNIC_REQ_CACHE_DFLT_SGL
]);
970 #ifdef CONFIG_SCSI_SNIC_DEBUG_FS
971 /* Freeing Trace Resources */
974 /* Freeing Debugfs Resources */
979 } /* end of snic_glob_cleanup */
981 static struct pci_driver snic_driver
= {
982 .name
= SNIC_DRV_NAME
,
983 .id_table
= snic_id_table
,
985 .remove
= snic_remove
,
989 snic_init_module(void)
994 SNIC_INFO("SNIC Driver is supported only for x86_64 platforms!\n");
995 add_taint(TAINT_CPU_OUT_OF_SPEC
, LOCKDEP_STILL_OK
);
998 SNIC_INFO("%s, ver %s\n", SNIC_DRV_DESCRIPTION
, SNIC_DRV_VERSION
);
1000 ret
= snic_global_data_init();
1002 SNIC_ERR("Failed to Initialize Global Data.\n");
1007 ret
= pci_register_driver(&snic_driver
);
1009 SNIC_ERR("PCI driver register error\n");
1017 snic_global_data_cleanup();
1023 snic_cleanup_module(void)
1025 pci_unregister_driver(&snic_driver
);
1026 snic_global_data_cleanup();
1029 module_init(snic_init_module
);
1030 module_exit(snic_cleanup_module
);
1032 MODULE_LICENSE("GPL v2");
1033 MODULE_DESCRIPTION(SNIC_DRV_DESCRIPTION
);
1034 MODULE_VERSION(SNIC_DRV_VERSION
);
1035 MODULE_DEVICE_TABLE(pci
, snic_id_table
);
1036 MODULE_AUTHOR("Narsimhulu Musini <nmusini@cisco.com>, "
1037 "Sesidhar Baddela <sebaddel@cisco.com>");