18c2ecf20Sopenharmony_ci/*
28c2ecf20Sopenharmony_ci * Copyright 2014 Cisco Systems, Inc.  All rights reserved.
38c2ecf20Sopenharmony_ci *
48c2ecf20Sopenharmony_ci * This program is free software; you may redistribute it and/or modify
58c2ecf20Sopenharmony_ci * it under the terms of the GNU General Public License as published by
68c2ecf20Sopenharmony_ci * the Free Software Foundation; version 2 of the License.
78c2ecf20Sopenharmony_ci *
88c2ecf20Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
98c2ecf20Sopenharmony_ci * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
108c2ecf20Sopenharmony_ci * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
118c2ecf20Sopenharmony_ci * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
128c2ecf20Sopenharmony_ci * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
138c2ecf20Sopenharmony_ci * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
148c2ecf20Sopenharmony_ci * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
158c2ecf20Sopenharmony_ci * SOFTWARE.
168c2ecf20Sopenharmony_ci */
178c2ecf20Sopenharmony_ci
188c2ecf20Sopenharmony_ci#include <linux/module.h>
198c2ecf20Sopenharmony_ci#include <linux/mempool.h>
208c2ecf20Sopenharmony_ci#include <linux/string.h>
218c2ecf20Sopenharmony_ci#include <linux/slab.h>
228c2ecf20Sopenharmony_ci#include <linux/errno.h>
238c2ecf20Sopenharmony_ci#include <linux/init.h>
248c2ecf20Sopenharmony_ci#include <linux/pci.h>
258c2ecf20Sopenharmony_ci#include <linux/skbuff.h>
268c2ecf20Sopenharmony_ci#include <linux/interrupt.h>
278c2ecf20Sopenharmony_ci#include <linux/spinlock.h>
288c2ecf20Sopenharmony_ci#include <linux/workqueue.h>
298c2ecf20Sopenharmony_ci#include <scsi/scsi_host.h>
308c2ecf20Sopenharmony_ci#include <scsi/scsi_tcq.h>
318c2ecf20Sopenharmony_ci
328c2ecf20Sopenharmony_ci#include "snic.h"
338c2ecf20Sopenharmony_ci#include "snic_fwint.h"
348c2ecf20Sopenharmony_ci
358c2ecf20Sopenharmony_ci#define PCI_DEVICE_ID_CISCO_SNIC	0x0046
368c2ecf20Sopenharmony_ci
378c2ecf20Sopenharmony_ci/* Supported devices by snic module */
388c2ecf20Sopenharmony_cistatic struct pci_device_id snic_id_table[] = {
398c2ecf20Sopenharmony_ci	{PCI_DEVICE(0x1137, PCI_DEVICE_ID_CISCO_SNIC) },
408c2ecf20Sopenharmony_ci	{ 0, }	/* end of table */
418c2ecf20Sopenharmony_ci};
428c2ecf20Sopenharmony_ci
438c2ecf20Sopenharmony_ciunsigned int snic_log_level = 0x0;
448c2ecf20Sopenharmony_cimodule_param(snic_log_level, int, S_IRUGO|S_IWUSR);
458c2ecf20Sopenharmony_ciMODULE_PARM_DESC(snic_log_level, "bitmask for snic logging levels");
468c2ecf20Sopenharmony_ci
478c2ecf20Sopenharmony_ci#ifdef CONFIG_SCSI_SNIC_DEBUG_FS
488c2ecf20Sopenharmony_ciunsigned int snic_trace_max_pages = 16;
498c2ecf20Sopenharmony_cimodule_param(snic_trace_max_pages, uint, S_IRUGO|S_IWUSR);
508c2ecf20Sopenharmony_ciMODULE_PARM_DESC(snic_trace_max_pages,
518c2ecf20Sopenharmony_ci		"Total allocated memory pages for snic trace buffer");
528c2ecf20Sopenharmony_ci
538c2ecf20Sopenharmony_ci#endif
548c2ecf20Sopenharmony_ciunsigned int snic_max_qdepth = SNIC_DFLT_QUEUE_DEPTH;
558c2ecf20Sopenharmony_cimodule_param(snic_max_qdepth, uint, S_IRUGO | S_IWUSR);
568c2ecf20Sopenharmony_ciMODULE_PARM_DESC(snic_max_qdepth, "Queue depth to report for each LUN");
578c2ecf20Sopenharmony_ci
588c2ecf20Sopenharmony_ci/*
598c2ecf20Sopenharmony_ci * snic_slave_alloc : callback function to SCSI Mid Layer, called on
608c2ecf20Sopenharmony_ci * scsi device initialization.
618c2ecf20Sopenharmony_ci */
628c2ecf20Sopenharmony_cistatic int
638c2ecf20Sopenharmony_cisnic_slave_alloc(struct scsi_device *sdev)
648c2ecf20Sopenharmony_ci{
658c2ecf20Sopenharmony_ci	struct snic_tgt *tgt = starget_to_tgt(scsi_target(sdev));
668c2ecf20Sopenharmony_ci
678c2ecf20Sopenharmony_ci	if (!tgt || snic_tgt_chkready(tgt))
688c2ecf20Sopenharmony_ci		return -ENXIO;
698c2ecf20Sopenharmony_ci
708c2ecf20Sopenharmony_ci	return 0;
718c2ecf20Sopenharmony_ci}
728c2ecf20Sopenharmony_ci
738c2ecf20Sopenharmony_ci/*
748c2ecf20Sopenharmony_ci * snic_slave_configure : callback function to SCSI Mid Layer, called on
758c2ecf20Sopenharmony_ci * scsi device initialization.
768c2ecf20Sopenharmony_ci */
778c2ecf20Sopenharmony_cistatic int
788c2ecf20Sopenharmony_cisnic_slave_configure(struct scsi_device *sdev)
798c2ecf20Sopenharmony_ci{
808c2ecf20Sopenharmony_ci	struct snic *snic = shost_priv(sdev->host);
818c2ecf20Sopenharmony_ci	u32 qdepth = 0, max_ios = 0;
828c2ecf20Sopenharmony_ci	int tmo = SNIC_DFLT_CMD_TIMEOUT * HZ;
838c2ecf20Sopenharmony_ci
848c2ecf20Sopenharmony_ci	/* Set Queue Depth */
858c2ecf20Sopenharmony_ci	max_ios = snic_max_qdepth;
868c2ecf20Sopenharmony_ci	qdepth = min_t(u32, max_ios, SNIC_MAX_QUEUE_DEPTH);
878c2ecf20Sopenharmony_ci	scsi_change_queue_depth(sdev, qdepth);
888c2ecf20Sopenharmony_ci
898c2ecf20Sopenharmony_ci	if (snic->fwinfo.io_tmo > 1)
908c2ecf20Sopenharmony_ci		tmo = snic->fwinfo.io_tmo * HZ;
918c2ecf20Sopenharmony_ci
928c2ecf20Sopenharmony_ci	/* FW requires extended timeouts */
938c2ecf20Sopenharmony_ci	blk_queue_rq_timeout(sdev->request_queue, tmo);
948c2ecf20Sopenharmony_ci
958c2ecf20Sopenharmony_ci	return 0;
968c2ecf20Sopenharmony_ci}
978c2ecf20Sopenharmony_ci
988c2ecf20Sopenharmony_cistatic int
998c2ecf20Sopenharmony_cisnic_change_queue_depth(struct scsi_device *sdev, int qdepth)
1008c2ecf20Sopenharmony_ci{
1018c2ecf20Sopenharmony_ci	struct snic *snic = shost_priv(sdev->host);
1028c2ecf20Sopenharmony_ci	int qsz = 0;
1038c2ecf20Sopenharmony_ci
1048c2ecf20Sopenharmony_ci	qsz = min_t(u32, qdepth, SNIC_MAX_QUEUE_DEPTH);
1058c2ecf20Sopenharmony_ci	if (qsz < sdev->queue_depth)
1068c2ecf20Sopenharmony_ci		atomic64_inc(&snic->s_stats.misc.qsz_rampdown);
1078c2ecf20Sopenharmony_ci	else if (qsz > sdev->queue_depth)
1088c2ecf20Sopenharmony_ci		atomic64_inc(&snic->s_stats.misc.qsz_rampup);
1098c2ecf20Sopenharmony_ci
1108c2ecf20Sopenharmony_ci	atomic64_set(&snic->s_stats.misc.last_qsz, sdev->queue_depth);
1118c2ecf20Sopenharmony_ci
1128c2ecf20Sopenharmony_ci	scsi_change_queue_depth(sdev, qsz);
1138c2ecf20Sopenharmony_ci
1148c2ecf20Sopenharmony_ci	return sdev->queue_depth;
1158c2ecf20Sopenharmony_ci}
1168c2ecf20Sopenharmony_ci
1178c2ecf20Sopenharmony_cistatic struct scsi_host_template snic_host_template = {
1188c2ecf20Sopenharmony_ci	.module = THIS_MODULE,
1198c2ecf20Sopenharmony_ci	.name = SNIC_DRV_NAME,
1208c2ecf20Sopenharmony_ci	.queuecommand = snic_queuecommand,
1218c2ecf20Sopenharmony_ci	.eh_abort_handler = snic_abort_cmd,
1228c2ecf20Sopenharmony_ci	.eh_device_reset_handler = snic_device_reset,
1238c2ecf20Sopenharmony_ci	.eh_host_reset_handler = snic_host_reset,
1248c2ecf20Sopenharmony_ci	.slave_alloc = snic_slave_alloc,
1258c2ecf20Sopenharmony_ci	.slave_configure = snic_slave_configure,
1268c2ecf20Sopenharmony_ci	.change_queue_depth = snic_change_queue_depth,
1278c2ecf20Sopenharmony_ci	.this_id = -1,
1288c2ecf20Sopenharmony_ci	.cmd_per_lun = SNIC_DFLT_QUEUE_DEPTH,
1298c2ecf20Sopenharmony_ci	.can_queue = SNIC_MAX_IO_REQ,
1308c2ecf20Sopenharmony_ci	.sg_tablesize = SNIC_MAX_SG_DESC_CNT,
1318c2ecf20Sopenharmony_ci	.max_sectors = 0x800,
1328c2ecf20Sopenharmony_ci	.shost_attrs = snic_attrs,
1338c2ecf20Sopenharmony_ci	.track_queue_depth = 1,
1348c2ecf20Sopenharmony_ci	.cmd_size = sizeof(struct snic_internal_io_state),
1358c2ecf20Sopenharmony_ci	.proc_name = "snic_scsi",
1368c2ecf20Sopenharmony_ci};
1378c2ecf20Sopenharmony_ci
1388c2ecf20Sopenharmony_ci/*
1398c2ecf20Sopenharmony_ci * snic_handle_link_event : Handles link events such as link up/down/error
1408c2ecf20Sopenharmony_ci */
1418c2ecf20Sopenharmony_civoid
1428c2ecf20Sopenharmony_cisnic_handle_link_event(struct snic *snic)
1438c2ecf20Sopenharmony_ci{
1448c2ecf20Sopenharmony_ci	unsigned long flags;
1458c2ecf20Sopenharmony_ci
1468c2ecf20Sopenharmony_ci	spin_lock_irqsave(&snic->snic_lock, flags);
1478c2ecf20Sopenharmony_ci	if (snic->stop_link_events) {
1488c2ecf20Sopenharmony_ci		spin_unlock_irqrestore(&snic->snic_lock, flags);
1498c2ecf20Sopenharmony_ci
1508c2ecf20Sopenharmony_ci		return;
1518c2ecf20Sopenharmony_ci	}
1528c2ecf20Sopenharmony_ci	spin_unlock_irqrestore(&snic->snic_lock, flags);
1538c2ecf20Sopenharmony_ci
1548c2ecf20Sopenharmony_ci	queue_work(snic_glob->event_q, &snic->link_work);
1558c2ecf20Sopenharmony_ci} /* end of snic_handle_link_event */
1568c2ecf20Sopenharmony_ci
1578c2ecf20Sopenharmony_ci/*
1588c2ecf20Sopenharmony_ci * snic_notify_set : sets notification area
1598c2ecf20Sopenharmony_ci * This notification area is to receive events from fw
1608c2ecf20Sopenharmony_ci * Note: snic supports only MSIX interrupts, in which we can just call
1618c2ecf20Sopenharmony_ci *  svnic_dev_notify_set directly
1628c2ecf20Sopenharmony_ci */
1638c2ecf20Sopenharmony_cistatic int
1648c2ecf20Sopenharmony_cisnic_notify_set(struct snic *snic)
1658c2ecf20Sopenharmony_ci{
1668c2ecf20Sopenharmony_ci	int ret = 0;
1678c2ecf20Sopenharmony_ci	enum vnic_dev_intr_mode intr_mode;
1688c2ecf20Sopenharmony_ci
1698c2ecf20Sopenharmony_ci	intr_mode = svnic_dev_get_intr_mode(snic->vdev);
1708c2ecf20Sopenharmony_ci
1718c2ecf20Sopenharmony_ci	if (intr_mode == VNIC_DEV_INTR_MODE_MSIX) {
1728c2ecf20Sopenharmony_ci		ret = svnic_dev_notify_set(snic->vdev, SNIC_MSIX_ERR_NOTIFY);
1738c2ecf20Sopenharmony_ci	} else {
1748c2ecf20Sopenharmony_ci		SNIC_HOST_ERR(snic->shost,
1758c2ecf20Sopenharmony_ci			      "Interrupt mode should be setup before devcmd notify set %d\n",
1768c2ecf20Sopenharmony_ci			      intr_mode);
1778c2ecf20Sopenharmony_ci		ret = -1;
1788c2ecf20Sopenharmony_ci	}
1798c2ecf20Sopenharmony_ci
1808c2ecf20Sopenharmony_ci	return ret;
1818c2ecf20Sopenharmony_ci} /* end of snic_notify_set */
1828c2ecf20Sopenharmony_ci
1838c2ecf20Sopenharmony_ci/*
1848c2ecf20Sopenharmony_ci * snic_dev_wait : polls vnic open status.
1858c2ecf20Sopenharmony_ci */
1868c2ecf20Sopenharmony_cistatic int
1878c2ecf20Sopenharmony_cisnic_dev_wait(struct vnic_dev *vdev,
1888c2ecf20Sopenharmony_ci		int (*start)(struct vnic_dev *, int),
1898c2ecf20Sopenharmony_ci		int (*finished)(struct vnic_dev *, int *),
1908c2ecf20Sopenharmony_ci		int arg)
1918c2ecf20Sopenharmony_ci{
1928c2ecf20Sopenharmony_ci	unsigned long time;
1938c2ecf20Sopenharmony_ci	int ret, done;
1948c2ecf20Sopenharmony_ci	int retry_cnt = 0;
1958c2ecf20Sopenharmony_ci
1968c2ecf20Sopenharmony_ci	ret = start(vdev, arg);
1978c2ecf20Sopenharmony_ci	if (ret)
1988c2ecf20Sopenharmony_ci		return ret;
1998c2ecf20Sopenharmony_ci
2008c2ecf20Sopenharmony_ci	/*
2018c2ecf20Sopenharmony_ci	 * Wait for func to complete...2 seconds max.
2028c2ecf20Sopenharmony_ci	 *
2038c2ecf20Sopenharmony_ci	 * Sometimes schedule_timeout_uninterruptible take long	time
2048c2ecf20Sopenharmony_ci	 * to wakeup, which results skipping retry. The retry counter
2058c2ecf20Sopenharmony_ci	 * ensures to retry at least two times.
2068c2ecf20Sopenharmony_ci	 */
2078c2ecf20Sopenharmony_ci	time = jiffies + (HZ * 2);
2088c2ecf20Sopenharmony_ci	do {
2098c2ecf20Sopenharmony_ci		ret = finished(vdev, &done);
2108c2ecf20Sopenharmony_ci		if (ret)
2118c2ecf20Sopenharmony_ci			return ret;
2128c2ecf20Sopenharmony_ci
2138c2ecf20Sopenharmony_ci		if (done)
2148c2ecf20Sopenharmony_ci			return 0;
2158c2ecf20Sopenharmony_ci		schedule_timeout_uninterruptible(HZ/10);
2168c2ecf20Sopenharmony_ci		++retry_cnt;
2178c2ecf20Sopenharmony_ci	} while (time_after(time, jiffies) || (retry_cnt < 3));
2188c2ecf20Sopenharmony_ci
2198c2ecf20Sopenharmony_ci	return -ETIMEDOUT;
2208c2ecf20Sopenharmony_ci} /* end of snic_dev_wait */
2218c2ecf20Sopenharmony_ci
2228c2ecf20Sopenharmony_ci/*
2238c2ecf20Sopenharmony_ci * snic_cleanup: called by snic_remove
2248c2ecf20Sopenharmony_ci * Stops the snic device, masks all interrupts, Completed CQ entries are
2258c2ecf20Sopenharmony_ci * drained. Posted WQ/RQ/Copy-WQ entries are cleanup
2268c2ecf20Sopenharmony_ci */
2278c2ecf20Sopenharmony_cistatic int
2288c2ecf20Sopenharmony_cisnic_cleanup(struct snic *snic)
2298c2ecf20Sopenharmony_ci{
2308c2ecf20Sopenharmony_ci	unsigned int i;
2318c2ecf20Sopenharmony_ci	int ret;
2328c2ecf20Sopenharmony_ci
2338c2ecf20Sopenharmony_ci	svnic_dev_disable(snic->vdev);
2348c2ecf20Sopenharmony_ci	for (i = 0; i < snic->intr_count; i++)
2358c2ecf20Sopenharmony_ci		svnic_intr_mask(&snic->intr[i]);
2368c2ecf20Sopenharmony_ci
2378c2ecf20Sopenharmony_ci	for (i = 0; i < snic->wq_count; i++) {
2388c2ecf20Sopenharmony_ci		ret = svnic_wq_disable(&snic->wq[i]);
2398c2ecf20Sopenharmony_ci		if (ret)
2408c2ecf20Sopenharmony_ci			return ret;
2418c2ecf20Sopenharmony_ci	}
2428c2ecf20Sopenharmony_ci
2438c2ecf20Sopenharmony_ci	/* Clean up completed IOs */
2448c2ecf20Sopenharmony_ci	snic_fwcq_cmpl_handler(snic, -1);
2458c2ecf20Sopenharmony_ci
2468c2ecf20Sopenharmony_ci	snic_wq_cmpl_handler(snic, -1);
2478c2ecf20Sopenharmony_ci
2488c2ecf20Sopenharmony_ci	/* Clean up the IOs that have not completed */
2498c2ecf20Sopenharmony_ci	for (i = 0; i < snic->wq_count; i++)
2508c2ecf20Sopenharmony_ci		svnic_wq_clean(&snic->wq[i], snic_free_wq_buf);
2518c2ecf20Sopenharmony_ci
2528c2ecf20Sopenharmony_ci	for (i = 0; i < snic->cq_count; i++)
2538c2ecf20Sopenharmony_ci		svnic_cq_clean(&snic->cq[i]);
2548c2ecf20Sopenharmony_ci
2558c2ecf20Sopenharmony_ci	for (i = 0; i < snic->intr_count; i++)
2568c2ecf20Sopenharmony_ci		svnic_intr_clean(&snic->intr[i]);
2578c2ecf20Sopenharmony_ci
2588c2ecf20Sopenharmony_ci	/* Cleanup snic specific requests */
2598c2ecf20Sopenharmony_ci	snic_free_all_untagged_reqs(snic);
2608c2ecf20Sopenharmony_ci
2618c2ecf20Sopenharmony_ci	/* Cleanup Pending SCSI commands */
2628c2ecf20Sopenharmony_ci	snic_shutdown_scsi_cleanup(snic);
2638c2ecf20Sopenharmony_ci
2648c2ecf20Sopenharmony_ci	for (i = 0; i < SNIC_REQ_MAX_CACHES; i++)
2658c2ecf20Sopenharmony_ci		mempool_destroy(snic->req_pool[i]);
2668c2ecf20Sopenharmony_ci
2678c2ecf20Sopenharmony_ci	return 0;
2688c2ecf20Sopenharmony_ci} /* end of snic_cleanup */
2698c2ecf20Sopenharmony_ci
2708c2ecf20Sopenharmony_ci
2718c2ecf20Sopenharmony_cistatic void
2728c2ecf20Sopenharmony_cisnic_iounmap(struct snic *snic)
2738c2ecf20Sopenharmony_ci{
2748c2ecf20Sopenharmony_ci	if (snic->bar0.vaddr)
2758c2ecf20Sopenharmony_ci		iounmap(snic->bar0.vaddr);
2768c2ecf20Sopenharmony_ci}
2778c2ecf20Sopenharmony_ci
2788c2ecf20Sopenharmony_ci/*
2798c2ecf20Sopenharmony_ci * snic_vdev_open_done : polls for svnic_dev_open cmd completion.
2808c2ecf20Sopenharmony_ci */
2818c2ecf20Sopenharmony_cistatic int
2828c2ecf20Sopenharmony_cisnic_vdev_open_done(struct vnic_dev *vdev, int *done)
2838c2ecf20Sopenharmony_ci{
2848c2ecf20Sopenharmony_ci	struct snic *snic = svnic_dev_priv(vdev);
2858c2ecf20Sopenharmony_ci	int ret;
2868c2ecf20Sopenharmony_ci	int nretries = 5;
2878c2ecf20Sopenharmony_ci
2888c2ecf20Sopenharmony_ci	do {
2898c2ecf20Sopenharmony_ci		ret = svnic_dev_open_done(vdev, done);
2908c2ecf20Sopenharmony_ci		if (ret == 0)
2918c2ecf20Sopenharmony_ci			break;
2928c2ecf20Sopenharmony_ci
2938c2ecf20Sopenharmony_ci		SNIC_HOST_INFO(snic->shost, "VNIC_DEV_OPEN Timedout.\n");
2948c2ecf20Sopenharmony_ci	} while (nretries--);
2958c2ecf20Sopenharmony_ci
2968c2ecf20Sopenharmony_ci	return ret;
2978c2ecf20Sopenharmony_ci} /* end of snic_vdev_open_done */
2988c2ecf20Sopenharmony_ci
2998c2ecf20Sopenharmony_ci/*
3008c2ecf20Sopenharmony_ci * snic_add_host : registers scsi host with ML
3018c2ecf20Sopenharmony_ci */
3028c2ecf20Sopenharmony_cistatic int
3038c2ecf20Sopenharmony_cisnic_add_host(struct Scsi_Host *shost, struct pci_dev *pdev)
3048c2ecf20Sopenharmony_ci{
3058c2ecf20Sopenharmony_ci	int ret = 0;
3068c2ecf20Sopenharmony_ci
3078c2ecf20Sopenharmony_ci	ret = scsi_add_host(shost, &pdev->dev);
3088c2ecf20Sopenharmony_ci	if (ret) {
3098c2ecf20Sopenharmony_ci		SNIC_HOST_ERR(shost,
3108c2ecf20Sopenharmony_ci			      "snic: scsi_add_host failed. %d\n",
3118c2ecf20Sopenharmony_ci			      ret);
3128c2ecf20Sopenharmony_ci
3138c2ecf20Sopenharmony_ci		return ret;
3148c2ecf20Sopenharmony_ci	}
3158c2ecf20Sopenharmony_ci
3168c2ecf20Sopenharmony_ci	SNIC_BUG_ON(shost->work_q != NULL);
3178c2ecf20Sopenharmony_ci	snprintf(shost->work_q_name, sizeof(shost->work_q_name), "scsi_wq_%d",
3188c2ecf20Sopenharmony_ci		 shost->host_no);
3198c2ecf20Sopenharmony_ci	shost->work_q = create_singlethread_workqueue(shost->work_q_name);
3208c2ecf20Sopenharmony_ci	if (!shost->work_q) {
3218c2ecf20Sopenharmony_ci		SNIC_HOST_ERR(shost, "Failed to Create ScsiHost wq.\n");
3228c2ecf20Sopenharmony_ci
3238c2ecf20Sopenharmony_ci		ret = -ENOMEM;
3248c2ecf20Sopenharmony_ci	}
3258c2ecf20Sopenharmony_ci
3268c2ecf20Sopenharmony_ci	return ret;
3278c2ecf20Sopenharmony_ci} /* end of snic_add_host */
3288c2ecf20Sopenharmony_ci
3298c2ecf20Sopenharmony_cistatic void
3308c2ecf20Sopenharmony_cisnic_del_host(struct Scsi_Host *shost)
3318c2ecf20Sopenharmony_ci{
3328c2ecf20Sopenharmony_ci	if (!shost->work_q)
3338c2ecf20Sopenharmony_ci		return;
3348c2ecf20Sopenharmony_ci
3358c2ecf20Sopenharmony_ci	destroy_workqueue(shost->work_q);
3368c2ecf20Sopenharmony_ci	shost->work_q = NULL;
3378c2ecf20Sopenharmony_ci	scsi_remove_host(shost);
3388c2ecf20Sopenharmony_ci}
3398c2ecf20Sopenharmony_ci
3408c2ecf20Sopenharmony_ciint
3418c2ecf20Sopenharmony_cisnic_get_state(struct snic *snic)
3428c2ecf20Sopenharmony_ci{
3438c2ecf20Sopenharmony_ci	return atomic_read(&snic->state);
3448c2ecf20Sopenharmony_ci}
3458c2ecf20Sopenharmony_ci
3468c2ecf20Sopenharmony_civoid
3478c2ecf20Sopenharmony_cisnic_set_state(struct snic *snic, enum snic_state state)
3488c2ecf20Sopenharmony_ci{
3498c2ecf20Sopenharmony_ci	SNIC_HOST_INFO(snic->shost, "snic state change from %s to %s\n",
3508c2ecf20Sopenharmony_ci		       snic_state_to_str(snic_get_state(snic)),
3518c2ecf20Sopenharmony_ci		       snic_state_to_str(state));
3528c2ecf20Sopenharmony_ci
3538c2ecf20Sopenharmony_ci	atomic_set(&snic->state, state);
3548c2ecf20Sopenharmony_ci}
3558c2ecf20Sopenharmony_ci
3568c2ecf20Sopenharmony_ci/*
3578c2ecf20Sopenharmony_ci * snic_probe : Initialize the snic interface.
3588c2ecf20Sopenharmony_ci */
3598c2ecf20Sopenharmony_cistatic int
3608c2ecf20Sopenharmony_cisnic_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
3618c2ecf20Sopenharmony_ci{
3628c2ecf20Sopenharmony_ci	struct Scsi_Host *shost;
3638c2ecf20Sopenharmony_ci	struct snic *snic;
3648c2ecf20Sopenharmony_ci	mempool_t *pool;
3658c2ecf20Sopenharmony_ci	unsigned long flags;
3668c2ecf20Sopenharmony_ci	u32 max_ios = 0;
3678c2ecf20Sopenharmony_ci	int ret, i;
3688c2ecf20Sopenharmony_ci
3698c2ecf20Sopenharmony_ci	/* Device Information */
3708c2ecf20Sopenharmony_ci	SNIC_INFO("snic device %4x:%4x:%4x:%4x: ",
3718c2ecf20Sopenharmony_ci		  pdev->vendor, pdev->device, pdev->subsystem_vendor,
3728c2ecf20Sopenharmony_ci		  pdev->subsystem_device);
3738c2ecf20Sopenharmony_ci
3748c2ecf20Sopenharmony_ci	SNIC_INFO("snic device bus %x: slot %x: fn %x\n",
3758c2ecf20Sopenharmony_ci		  pdev->bus->number, PCI_SLOT(pdev->devfn),
3768c2ecf20Sopenharmony_ci		  PCI_FUNC(pdev->devfn));
3778c2ecf20Sopenharmony_ci
3788c2ecf20Sopenharmony_ci	/*
3798c2ecf20Sopenharmony_ci	 * Allocate SCSI Host and setup association between host, and snic
3808c2ecf20Sopenharmony_ci	 */
3818c2ecf20Sopenharmony_ci	shost = scsi_host_alloc(&snic_host_template, sizeof(struct snic));
3828c2ecf20Sopenharmony_ci	if (!shost) {
3838c2ecf20Sopenharmony_ci		SNIC_ERR("Unable to alloc scsi_host\n");
3848c2ecf20Sopenharmony_ci		ret = -ENOMEM;
3858c2ecf20Sopenharmony_ci
3868c2ecf20Sopenharmony_ci		goto prob_end;
3878c2ecf20Sopenharmony_ci	}
3888c2ecf20Sopenharmony_ci	snic = shost_priv(shost);
3898c2ecf20Sopenharmony_ci	snic->shost = shost;
3908c2ecf20Sopenharmony_ci
3918c2ecf20Sopenharmony_ci	snprintf(snic->name, sizeof(snic->name) - 1, "%s%d", SNIC_DRV_NAME,
3928c2ecf20Sopenharmony_ci		 shost->host_no);
3938c2ecf20Sopenharmony_ci
3948c2ecf20Sopenharmony_ci	SNIC_HOST_INFO(shost,
3958c2ecf20Sopenharmony_ci		       "snic%d = %p shost = %p device bus %x: slot %x: fn %x\n",
3968c2ecf20Sopenharmony_ci		       shost->host_no, snic, shost, pdev->bus->number,
3978c2ecf20Sopenharmony_ci		       PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn));
3988c2ecf20Sopenharmony_ci#ifdef CONFIG_SCSI_SNIC_DEBUG_FS
3998c2ecf20Sopenharmony_ci	/* Per snic debugfs init */
4008c2ecf20Sopenharmony_ci	snic_stats_debugfs_init(snic);
4018c2ecf20Sopenharmony_ci#endif
4028c2ecf20Sopenharmony_ci
4038c2ecf20Sopenharmony_ci	/* Setup PCI Resources */
4048c2ecf20Sopenharmony_ci	pci_set_drvdata(pdev, snic);
4058c2ecf20Sopenharmony_ci	snic->pdev = pdev;
4068c2ecf20Sopenharmony_ci
4078c2ecf20Sopenharmony_ci	ret = pci_enable_device(pdev);
4088c2ecf20Sopenharmony_ci	if (ret) {
4098c2ecf20Sopenharmony_ci		SNIC_HOST_ERR(shost,
4108c2ecf20Sopenharmony_ci			      "Cannot enable PCI Resources, aborting : %d\n",
4118c2ecf20Sopenharmony_ci			      ret);
4128c2ecf20Sopenharmony_ci
4138c2ecf20Sopenharmony_ci		goto err_free_snic;
4148c2ecf20Sopenharmony_ci	}
4158c2ecf20Sopenharmony_ci
4168c2ecf20Sopenharmony_ci	ret = pci_request_regions(pdev, SNIC_DRV_NAME);
4178c2ecf20Sopenharmony_ci	if (ret) {
4188c2ecf20Sopenharmony_ci		SNIC_HOST_ERR(shost,
4198c2ecf20Sopenharmony_ci			      "Cannot obtain PCI Resources, aborting : %d\n",
4208c2ecf20Sopenharmony_ci			      ret);
4218c2ecf20Sopenharmony_ci
4228c2ecf20Sopenharmony_ci		goto err_pci_disable;
4238c2ecf20Sopenharmony_ci	}
4248c2ecf20Sopenharmony_ci
4258c2ecf20Sopenharmony_ci	pci_set_master(pdev);
4268c2ecf20Sopenharmony_ci
4278c2ecf20Sopenharmony_ci	/*
4288c2ecf20Sopenharmony_ci	 * Query PCI Controller on system for DMA addressing
4298c2ecf20Sopenharmony_ci	 * limitation for the device. Try 43-bit first, and
4308c2ecf20Sopenharmony_ci	 * fail to 32-bit.
4318c2ecf20Sopenharmony_ci	 */
4328c2ecf20Sopenharmony_ci	ret = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(43));
4338c2ecf20Sopenharmony_ci	if (ret) {
4348c2ecf20Sopenharmony_ci		ret = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
4358c2ecf20Sopenharmony_ci		if (ret) {
4368c2ecf20Sopenharmony_ci			SNIC_HOST_ERR(shost,
4378c2ecf20Sopenharmony_ci				      "No Usable DMA Configuration, aborting %d\n",
4388c2ecf20Sopenharmony_ci				      ret);
4398c2ecf20Sopenharmony_ci			goto err_rel_regions;
4408c2ecf20Sopenharmony_ci		}
4418c2ecf20Sopenharmony_ci	}
4428c2ecf20Sopenharmony_ci
4438c2ecf20Sopenharmony_ci	/* Map vNIC resources from BAR0 */
4448c2ecf20Sopenharmony_ci	if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
4458c2ecf20Sopenharmony_ci		SNIC_HOST_ERR(shost, "BAR0 not memory mappable aborting.\n");
4468c2ecf20Sopenharmony_ci
4478c2ecf20Sopenharmony_ci		ret = -ENODEV;
4488c2ecf20Sopenharmony_ci		goto err_rel_regions;
4498c2ecf20Sopenharmony_ci	}
4508c2ecf20Sopenharmony_ci
4518c2ecf20Sopenharmony_ci	snic->bar0.vaddr = pci_iomap(pdev, 0, 0);
4528c2ecf20Sopenharmony_ci	if (!snic->bar0.vaddr) {
4538c2ecf20Sopenharmony_ci		SNIC_HOST_ERR(shost,
4548c2ecf20Sopenharmony_ci			      "Cannot memory map BAR0 res hdr aborting.\n");
4558c2ecf20Sopenharmony_ci
4568c2ecf20Sopenharmony_ci		ret = -ENODEV;
4578c2ecf20Sopenharmony_ci		goto err_rel_regions;
4588c2ecf20Sopenharmony_ci	}
4598c2ecf20Sopenharmony_ci
4608c2ecf20Sopenharmony_ci	snic->bar0.bus_addr = pci_resource_start(pdev, 0);
4618c2ecf20Sopenharmony_ci	snic->bar0.len = pci_resource_len(pdev, 0);
4628c2ecf20Sopenharmony_ci	SNIC_BUG_ON(snic->bar0.bus_addr == 0);
4638c2ecf20Sopenharmony_ci
4648c2ecf20Sopenharmony_ci	/* Devcmd2 Resource Allocation and Initialization */
4658c2ecf20Sopenharmony_ci	snic->vdev = svnic_dev_alloc_discover(NULL, snic, pdev, &snic->bar0, 1);
4668c2ecf20Sopenharmony_ci	if (!snic->vdev) {
4678c2ecf20Sopenharmony_ci		SNIC_HOST_ERR(shost, "vNIC Resource Discovery Failed.\n");
4688c2ecf20Sopenharmony_ci
4698c2ecf20Sopenharmony_ci		ret = -ENODEV;
4708c2ecf20Sopenharmony_ci		goto err_iounmap;
4718c2ecf20Sopenharmony_ci	}
4728c2ecf20Sopenharmony_ci
4738c2ecf20Sopenharmony_ci	ret = svnic_dev_cmd_init(snic->vdev, 0);
4748c2ecf20Sopenharmony_ci	if (ret) {
4758c2ecf20Sopenharmony_ci		SNIC_HOST_INFO(shost, "Devcmd2 Init Failed. err = %d\n", ret);
4768c2ecf20Sopenharmony_ci
4778c2ecf20Sopenharmony_ci		goto err_vnic_unreg;
4788c2ecf20Sopenharmony_ci	}
4798c2ecf20Sopenharmony_ci
4808c2ecf20Sopenharmony_ci	ret = snic_dev_wait(snic->vdev, svnic_dev_open, snic_vdev_open_done, 0);
4818c2ecf20Sopenharmony_ci	if (ret) {
4828c2ecf20Sopenharmony_ci		SNIC_HOST_ERR(shost,
4838c2ecf20Sopenharmony_ci			      "vNIC dev open failed, aborting. %d\n",
4848c2ecf20Sopenharmony_ci			      ret);
4858c2ecf20Sopenharmony_ci
4868c2ecf20Sopenharmony_ci		goto err_vnic_unreg;
4878c2ecf20Sopenharmony_ci	}
4888c2ecf20Sopenharmony_ci
4898c2ecf20Sopenharmony_ci	ret = svnic_dev_init(snic->vdev, 0);
4908c2ecf20Sopenharmony_ci	if (ret) {
4918c2ecf20Sopenharmony_ci		SNIC_HOST_ERR(shost,
4928c2ecf20Sopenharmony_ci			      "vNIC dev init failed. aborting. %d\n",
4938c2ecf20Sopenharmony_ci			      ret);
4948c2ecf20Sopenharmony_ci
4958c2ecf20Sopenharmony_ci		goto err_dev_close;
4968c2ecf20Sopenharmony_ci	}
4978c2ecf20Sopenharmony_ci
4988c2ecf20Sopenharmony_ci	/* Get vNIC information */
4998c2ecf20Sopenharmony_ci	ret = snic_get_vnic_config(snic);
5008c2ecf20Sopenharmony_ci	if (ret) {
5018c2ecf20Sopenharmony_ci		SNIC_HOST_ERR(shost,
5028c2ecf20Sopenharmony_ci			      "Get vNIC configuration failed, aborting. %d\n",
5038c2ecf20Sopenharmony_ci			      ret);
5048c2ecf20Sopenharmony_ci
5058c2ecf20Sopenharmony_ci		goto err_dev_close;
5068c2ecf20Sopenharmony_ci	}
5078c2ecf20Sopenharmony_ci
5088c2ecf20Sopenharmony_ci	/* Configure Maximum Outstanding IO reqs */
5098c2ecf20Sopenharmony_ci	max_ios = snic->config.io_throttle_count;
5108c2ecf20Sopenharmony_ci	if (max_ios != SNIC_UCSM_DFLT_THROTTLE_CNT_BLD)
5118c2ecf20Sopenharmony_ci		shost->can_queue = min_t(u32, SNIC_MAX_IO_REQ,
5128c2ecf20Sopenharmony_ci					 max_t(u32, SNIC_MIN_IO_REQ, max_ios));
5138c2ecf20Sopenharmony_ci
5148c2ecf20Sopenharmony_ci	snic->max_tag_id = shost->can_queue;
5158c2ecf20Sopenharmony_ci
5168c2ecf20Sopenharmony_ci	shost->max_lun = snic->config.luns_per_tgt;
5178c2ecf20Sopenharmony_ci	shost->max_id = SNIC_MAX_TARGET;
5188c2ecf20Sopenharmony_ci
5198c2ecf20Sopenharmony_ci	shost->max_cmd_len = MAX_COMMAND_SIZE; /*defined in scsi_cmnd.h*/
5208c2ecf20Sopenharmony_ci
5218c2ecf20Sopenharmony_ci	snic_get_res_counts(snic);
5228c2ecf20Sopenharmony_ci
5238c2ecf20Sopenharmony_ci	/*
5248c2ecf20Sopenharmony_ci	 * Assumption: Only MSIx is supported
5258c2ecf20Sopenharmony_ci	 */
5268c2ecf20Sopenharmony_ci	ret = snic_set_intr_mode(snic);
5278c2ecf20Sopenharmony_ci	if (ret) {
5288c2ecf20Sopenharmony_ci		SNIC_HOST_ERR(shost,
5298c2ecf20Sopenharmony_ci			      "Failed to set intr mode aborting. %d\n",
5308c2ecf20Sopenharmony_ci			      ret);
5318c2ecf20Sopenharmony_ci
5328c2ecf20Sopenharmony_ci		goto err_dev_close;
5338c2ecf20Sopenharmony_ci	}
5348c2ecf20Sopenharmony_ci
5358c2ecf20Sopenharmony_ci	ret = snic_alloc_vnic_res(snic);
5368c2ecf20Sopenharmony_ci	if (ret) {
5378c2ecf20Sopenharmony_ci		SNIC_HOST_ERR(shost,
5388c2ecf20Sopenharmony_ci			      "Failed to alloc vNIC resources aborting. %d\n",
5398c2ecf20Sopenharmony_ci			      ret);
5408c2ecf20Sopenharmony_ci
5418c2ecf20Sopenharmony_ci		goto err_clear_intr;
5428c2ecf20Sopenharmony_ci	}
5438c2ecf20Sopenharmony_ci
5448c2ecf20Sopenharmony_ci	/* Initialize specific lists */
5458c2ecf20Sopenharmony_ci	INIT_LIST_HEAD(&snic->list);
5468c2ecf20Sopenharmony_ci
5478c2ecf20Sopenharmony_ci	/*
5488c2ecf20Sopenharmony_ci	 * spl_cmd_list for maintaining snic specific cmds
5498c2ecf20Sopenharmony_ci	 * such as EXCH_VER_REQ, REPORT_TARGETS etc
5508c2ecf20Sopenharmony_ci	 */
5518c2ecf20Sopenharmony_ci	INIT_LIST_HEAD(&snic->spl_cmd_list);
5528c2ecf20Sopenharmony_ci	spin_lock_init(&snic->spl_cmd_lock);
5538c2ecf20Sopenharmony_ci
5548c2ecf20Sopenharmony_ci	/* initialize all snic locks */
5558c2ecf20Sopenharmony_ci	spin_lock_init(&snic->snic_lock);
5568c2ecf20Sopenharmony_ci
5578c2ecf20Sopenharmony_ci	for (i = 0; i < SNIC_WQ_MAX; i++)
5588c2ecf20Sopenharmony_ci		spin_lock_init(&snic->wq_lock[i]);
5598c2ecf20Sopenharmony_ci
5608c2ecf20Sopenharmony_ci	for (i = 0; i < SNIC_IO_LOCKS; i++)
5618c2ecf20Sopenharmony_ci		spin_lock_init(&snic->io_req_lock[i]);
5628c2ecf20Sopenharmony_ci
5638c2ecf20Sopenharmony_ci	pool = mempool_create_slab_pool(2,
5648c2ecf20Sopenharmony_ci				snic_glob->req_cache[SNIC_REQ_CACHE_DFLT_SGL]);
5658c2ecf20Sopenharmony_ci	if (!pool) {
5668c2ecf20Sopenharmony_ci		SNIC_HOST_ERR(shost, "dflt sgl pool creation failed\n");
5678c2ecf20Sopenharmony_ci
5688c2ecf20Sopenharmony_ci		ret = -ENOMEM;
5698c2ecf20Sopenharmony_ci		goto err_free_res;
5708c2ecf20Sopenharmony_ci	}
5718c2ecf20Sopenharmony_ci
5728c2ecf20Sopenharmony_ci	snic->req_pool[SNIC_REQ_CACHE_DFLT_SGL] = pool;
5738c2ecf20Sopenharmony_ci
5748c2ecf20Sopenharmony_ci	pool = mempool_create_slab_pool(2,
5758c2ecf20Sopenharmony_ci				snic_glob->req_cache[SNIC_REQ_CACHE_MAX_SGL]);
5768c2ecf20Sopenharmony_ci	if (!pool) {
5778c2ecf20Sopenharmony_ci		SNIC_HOST_ERR(shost, "max sgl pool creation failed\n");
5788c2ecf20Sopenharmony_ci
5798c2ecf20Sopenharmony_ci		ret = -ENOMEM;
5808c2ecf20Sopenharmony_ci		goto err_free_dflt_sgl_pool;
5818c2ecf20Sopenharmony_ci	}
5828c2ecf20Sopenharmony_ci
5838c2ecf20Sopenharmony_ci	snic->req_pool[SNIC_REQ_CACHE_MAX_SGL] = pool;
5848c2ecf20Sopenharmony_ci
5858c2ecf20Sopenharmony_ci	pool = mempool_create_slab_pool(2,
5868c2ecf20Sopenharmony_ci				snic_glob->req_cache[SNIC_REQ_TM_CACHE]);
5878c2ecf20Sopenharmony_ci	if (!pool) {
5888c2ecf20Sopenharmony_ci		SNIC_HOST_ERR(shost, "snic tmreq info pool creation failed.\n");
5898c2ecf20Sopenharmony_ci
5908c2ecf20Sopenharmony_ci		ret = -ENOMEM;
5918c2ecf20Sopenharmony_ci		goto err_free_max_sgl_pool;
5928c2ecf20Sopenharmony_ci	}
5938c2ecf20Sopenharmony_ci
5948c2ecf20Sopenharmony_ci	snic->req_pool[SNIC_REQ_TM_CACHE] = pool;
5958c2ecf20Sopenharmony_ci
5968c2ecf20Sopenharmony_ci	/* Initialize snic state */
5978c2ecf20Sopenharmony_ci	atomic_set(&snic->state, SNIC_INIT);
5988c2ecf20Sopenharmony_ci
5998c2ecf20Sopenharmony_ci	atomic_set(&snic->ios_inflight, 0);
6008c2ecf20Sopenharmony_ci
6018c2ecf20Sopenharmony_ci	/* Setup notification buffer area */
6028c2ecf20Sopenharmony_ci	ret = snic_notify_set(snic);
6038c2ecf20Sopenharmony_ci	if (ret) {
6048c2ecf20Sopenharmony_ci		SNIC_HOST_ERR(shost,
6058c2ecf20Sopenharmony_ci			      "Failed to alloc notify buffer aborting. %d\n",
6068c2ecf20Sopenharmony_ci			      ret);
6078c2ecf20Sopenharmony_ci
6088c2ecf20Sopenharmony_ci		goto err_free_tmreq_pool;
6098c2ecf20Sopenharmony_ci	}
6108c2ecf20Sopenharmony_ci
6118c2ecf20Sopenharmony_ci	spin_lock_irqsave(&snic_glob->snic_list_lock, flags);
6128c2ecf20Sopenharmony_ci	list_add_tail(&snic->list, &snic_glob->snic_list);
6138c2ecf20Sopenharmony_ci	spin_unlock_irqrestore(&snic_glob->snic_list_lock, flags);
6148c2ecf20Sopenharmony_ci
6158c2ecf20Sopenharmony_ci	snic_disc_init(&snic->disc);
6168c2ecf20Sopenharmony_ci	INIT_WORK(&snic->tgt_work, snic_handle_tgt_disc);
6178c2ecf20Sopenharmony_ci	INIT_WORK(&snic->disc_work, snic_handle_disc);
6188c2ecf20Sopenharmony_ci	INIT_WORK(&snic->link_work, snic_handle_link);
6198c2ecf20Sopenharmony_ci
6208c2ecf20Sopenharmony_ci	/* Enable all queues */
6218c2ecf20Sopenharmony_ci	for (i = 0; i < snic->wq_count; i++)
6228c2ecf20Sopenharmony_ci		svnic_wq_enable(&snic->wq[i]);
6238c2ecf20Sopenharmony_ci
6248c2ecf20Sopenharmony_ci	ret = svnic_dev_enable_wait(snic->vdev);
6258c2ecf20Sopenharmony_ci	if (ret) {
6268c2ecf20Sopenharmony_ci		SNIC_HOST_ERR(shost,
6278c2ecf20Sopenharmony_ci			      "vNIC dev enable failed w/ error %d\n",
6288c2ecf20Sopenharmony_ci			      ret);
6298c2ecf20Sopenharmony_ci
6308c2ecf20Sopenharmony_ci		goto err_vdev_enable;
6318c2ecf20Sopenharmony_ci	}
6328c2ecf20Sopenharmony_ci
6338c2ecf20Sopenharmony_ci	ret = snic_request_intr(snic);
6348c2ecf20Sopenharmony_ci	if (ret) {
6358c2ecf20Sopenharmony_ci		SNIC_HOST_ERR(shost, "Unable to request irq. %d\n", ret);
6368c2ecf20Sopenharmony_ci
6378c2ecf20Sopenharmony_ci		goto err_req_intr;
6388c2ecf20Sopenharmony_ci	}
6398c2ecf20Sopenharmony_ci
6408c2ecf20Sopenharmony_ci	for (i = 0; i < snic->intr_count; i++)
6418c2ecf20Sopenharmony_ci		svnic_intr_unmask(&snic->intr[i]);
6428c2ecf20Sopenharmony_ci
6438c2ecf20Sopenharmony_ci	/* Get snic params */
6448c2ecf20Sopenharmony_ci	ret = snic_get_conf(snic);
6458c2ecf20Sopenharmony_ci	if (ret) {
6468c2ecf20Sopenharmony_ci		SNIC_HOST_ERR(shost,
6478c2ecf20Sopenharmony_ci			      "Failed to get snic io config from FW w err %d\n",
6488c2ecf20Sopenharmony_ci			      ret);
6498c2ecf20Sopenharmony_ci
6508c2ecf20Sopenharmony_ci		goto err_get_conf;
6518c2ecf20Sopenharmony_ci	}
6528c2ecf20Sopenharmony_ci
6538c2ecf20Sopenharmony_ci	/*
6548c2ecf20Sopenharmony_ci	 * Initialization done with PCI system, hardware, firmware.
6558c2ecf20Sopenharmony_ci	 * Add shost to SCSI
6568c2ecf20Sopenharmony_ci	 */
6578c2ecf20Sopenharmony_ci	ret = snic_add_host(shost, pdev);
6588c2ecf20Sopenharmony_ci	if (ret) {
6598c2ecf20Sopenharmony_ci		SNIC_HOST_ERR(shost,
6608c2ecf20Sopenharmony_ci			      "Adding scsi host Failed ... exiting. %d\n",
6618c2ecf20Sopenharmony_ci			      ret);
6628c2ecf20Sopenharmony_ci
6638c2ecf20Sopenharmony_ci		goto err_get_conf;
6648c2ecf20Sopenharmony_ci	}
6658c2ecf20Sopenharmony_ci
6668c2ecf20Sopenharmony_ci	snic_set_state(snic, SNIC_ONLINE);
6678c2ecf20Sopenharmony_ci
6688c2ecf20Sopenharmony_ci	ret = snic_disc_start(snic);
6698c2ecf20Sopenharmony_ci	if (ret) {
6708c2ecf20Sopenharmony_ci		SNIC_HOST_ERR(shost, "snic_probe:Discovery Failed w err = %d\n",
6718c2ecf20Sopenharmony_ci			      ret);
6728c2ecf20Sopenharmony_ci
6738c2ecf20Sopenharmony_ci		goto err_get_conf;
6748c2ecf20Sopenharmony_ci	}
6758c2ecf20Sopenharmony_ci
6768c2ecf20Sopenharmony_ci	SNIC_HOST_INFO(shost, "SNIC Device Probe Successful.\n");
6778c2ecf20Sopenharmony_ci
6788c2ecf20Sopenharmony_ci	return 0;
6798c2ecf20Sopenharmony_ci
6808c2ecf20Sopenharmony_cierr_get_conf:
6818c2ecf20Sopenharmony_ci	snic_free_all_untagged_reqs(snic);
6828c2ecf20Sopenharmony_ci
6838c2ecf20Sopenharmony_ci	for (i = 0; i < snic->intr_count; i++)
6848c2ecf20Sopenharmony_ci		svnic_intr_mask(&snic->intr[i]);
6858c2ecf20Sopenharmony_ci
6868c2ecf20Sopenharmony_ci	snic_free_intr(snic);
6878c2ecf20Sopenharmony_ci
6888c2ecf20Sopenharmony_cierr_req_intr:
6898c2ecf20Sopenharmony_ci	svnic_dev_disable(snic->vdev);
6908c2ecf20Sopenharmony_ci
6918c2ecf20Sopenharmony_cierr_vdev_enable:
6928c2ecf20Sopenharmony_ci	svnic_dev_notify_unset(snic->vdev);
6938c2ecf20Sopenharmony_ci
6948c2ecf20Sopenharmony_ci	for (i = 0; i < snic->wq_count; i++) {
6958c2ecf20Sopenharmony_ci		int rc = 0;
6968c2ecf20Sopenharmony_ci
6978c2ecf20Sopenharmony_ci		rc = svnic_wq_disable(&snic->wq[i]);
6988c2ecf20Sopenharmony_ci		if (rc) {
6998c2ecf20Sopenharmony_ci			SNIC_HOST_ERR(shost,
7008c2ecf20Sopenharmony_ci				      "WQ Disable Failed w/ err = %d\n", rc);
7018c2ecf20Sopenharmony_ci
7028c2ecf20Sopenharmony_ci			 break;
7038c2ecf20Sopenharmony_ci		}
7048c2ecf20Sopenharmony_ci	}
7058c2ecf20Sopenharmony_ci	snic_del_host(snic->shost);
7068c2ecf20Sopenharmony_ci
7078c2ecf20Sopenharmony_cierr_free_tmreq_pool:
7088c2ecf20Sopenharmony_ci	mempool_destroy(snic->req_pool[SNIC_REQ_TM_CACHE]);
7098c2ecf20Sopenharmony_ci
7108c2ecf20Sopenharmony_cierr_free_max_sgl_pool:
7118c2ecf20Sopenharmony_ci	mempool_destroy(snic->req_pool[SNIC_REQ_CACHE_MAX_SGL]);
7128c2ecf20Sopenharmony_ci
7138c2ecf20Sopenharmony_cierr_free_dflt_sgl_pool:
7148c2ecf20Sopenharmony_ci	mempool_destroy(snic->req_pool[SNIC_REQ_CACHE_DFLT_SGL]);
7158c2ecf20Sopenharmony_ci
7168c2ecf20Sopenharmony_cierr_free_res:
7178c2ecf20Sopenharmony_ci	snic_free_vnic_res(snic);
7188c2ecf20Sopenharmony_ci
7198c2ecf20Sopenharmony_cierr_clear_intr:
7208c2ecf20Sopenharmony_ci	snic_clear_intr_mode(snic);
7218c2ecf20Sopenharmony_ci
7228c2ecf20Sopenharmony_cierr_dev_close:
7238c2ecf20Sopenharmony_ci	svnic_dev_close(snic->vdev);
7248c2ecf20Sopenharmony_ci
7258c2ecf20Sopenharmony_cierr_vnic_unreg:
7268c2ecf20Sopenharmony_ci	svnic_dev_unregister(snic->vdev);
7278c2ecf20Sopenharmony_ci
7288c2ecf20Sopenharmony_cierr_iounmap:
7298c2ecf20Sopenharmony_ci	snic_iounmap(snic);
7308c2ecf20Sopenharmony_ci
7318c2ecf20Sopenharmony_cierr_rel_regions:
7328c2ecf20Sopenharmony_ci	pci_release_regions(pdev);
7338c2ecf20Sopenharmony_ci
7348c2ecf20Sopenharmony_cierr_pci_disable:
7358c2ecf20Sopenharmony_ci	pci_disable_device(pdev);
7368c2ecf20Sopenharmony_ci
7378c2ecf20Sopenharmony_cierr_free_snic:
7388c2ecf20Sopenharmony_ci#ifdef CONFIG_SCSI_SNIC_DEBUG_FS
7398c2ecf20Sopenharmony_ci	snic_stats_debugfs_remove(snic);
7408c2ecf20Sopenharmony_ci#endif
7418c2ecf20Sopenharmony_ci	scsi_host_put(shost);
7428c2ecf20Sopenharmony_ci	pci_set_drvdata(pdev, NULL);
7438c2ecf20Sopenharmony_ci
7448c2ecf20Sopenharmony_ciprob_end:
7458c2ecf20Sopenharmony_ci	SNIC_INFO("sNIC device : bus %d: slot %d: fn %d Registration Failed.\n",
7468c2ecf20Sopenharmony_ci		  pdev->bus->number, PCI_SLOT(pdev->devfn),
7478c2ecf20Sopenharmony_ci		  PCI_FUNC(pdev->devfn));
7488c2ecf20Sopenharmony_ci
7498c2ecf20Sopenharmony_ci	return ret;
7508c2ecf20Sopenharmony_ci} /* end of snic_probe */
7518c2ecf20Sopenharmony_ci
7528c2ecf20Sopenharmony_ci
7538c2ecf20Sopenharmony_ci/*
7548c2ecf20Sopenharmony_ci * snic_remove : invoked on unbinding the interface to cleanup the
7558c2ecf20Sopenharmony_ci * resources allocated in snic_probe on initialization.
7568c2ecf20Sopenharmony_ci */
7578c2ecf20Sopenharmony_cistatic void
7588c2ecf20Sopenharmony_cisnic_remove(struct pci_dev *pdev)
7598c2ecf20Sopenharmony_ci{
7608c2ecf20Sopenharmony_ci	struct snic *snic = pci_get_drvdata(pdev);
7618c2ecf20Sopenharmony_ci	unsigned long flags;
7628c2ecf20Sopenharmony_ci
7638c2ecf20Sopenharmony_ci	if (!snic) {
7648c2ecf20Sopenharmony_ci		SNIC_INFO("sNIC dev: bus %d slot %d fn %d snic inst is null.\n",
7658c2ecf20Sopenharmony_ci			  pdev->bus->number, PCI_SLOT(pdev->devfn),
7668c2ecf20Sopenharmony_ci			  PCI_FUNC(pdev->devfn));
7678c2ecf20Sopenharmony_ci
7688c2ecf20Sopenharmony_ci		return;
7698c2ecf20Sopenharmony_ci	}
7708c2ecf20Sopenharmony_ci
7718c2ecf20Sopenharmony_ci	/*
7728c2ecf20Sopenharmony_ci	 * Mark state so that the workqueue thread stops forwarding
7738c2ecf20Sopenharmony_ci	 * received frames and link events. ISR and other threads
7748c2ecf20Sopenharmony_ci	 * that can queue work items will also stop creating work
7758c2ecf20Sopenharmony_ci	 * items on the snic workqueue
7768c2ecf20Sopenharmony_ci	 */
7778c2ecf20Sopenharmony_ci	snic_set_state(snic, SNIC_OFFLINE);
7788c2ecf20Sopenharmony_ci	spin_lock_irqsave(&snic->snic_lock, flags);
7798c2ecf20Sopenharmony_ci	snic->stop_link_events = 1;
7808c2ecf20Sopenharmony_ci	spin_unlock_irqrestore(&snic->snic_lock, flags);
7818c2ecf20Sopenharmony_ci
7828c2ecf20Sopenharmony_ci	flush_workqueue(snic_glob->event_q);
7838c2ecf20Sopenharmony_ci	snic_disc_term(snic);
7848c2ecf20Sopenharmony_ci
7858c2ecf20Sopenharmony_ci	spin_lock_irqsave(&snic->snic_lock, flags);
7868c2ecf20Sopenharmony_ci	snic->in_remove = 1;
7878c2ecf20Sopenharmony_ci	spin_unlock_irqrestore(&snic->snic_lock, flags);
7888c2ecf20Sopenharmony_ci
7898c2ecf20Sopenharmony_ci	/*
7908c2ecf20Sopenharmony_ci	 * This stops the snic device, masks all interrupts, Completed
7918c2ecf20Sopenharmony_ci	 * CQ entries are drained. Posted WQ/RQ/Copy-WQ entries are
7928c2ecf20Sopenharmony_ci	 * cleanup
7938c2ecf20Sopenharmony_ci	 */
7948c2ecf20Sopenharmony_ci	snic_cleanup(snic);
7958c2ecf20Sopenharmony_ci
7968c2ecf20Sopenharmony_ci	spin_lock_irqsave(&snic_glob->snic_list_lock, flags);
7978c2ecf20Sopenharmony_ci	list_del(&snic->list);
7988c2ecf20Sopenharmony_ci	spin_unlock_irqrestore(&snic_glob->snic_list_lock, flags);
7998c2ecf20Sopenharmony_ci
8008c2ecf20Sopenharmony_ci	snic_tgt_del_all(snic);
8018c2ecf20Sopenharmony_ci#ifdef CONFIG_SCSI_SNIC_DEBUG_FS
8028c2ecf20Sopenharmony_ci	snic_stats_debugfs_remove(snic);
8038c2ecf20Sopenharmony_ci#endif
8048c2ecf20Sopenharmony_ci	snic_del_host(snic->shost);
8058c2ecf20Sopenharmony_ci
8068c2ecf20Sopenharmony_ci	svnic_dev_notify_unset(snic->vdev);
8078c2ecf20Sopenharmony_ci	snic_free_intr(snic);
8088c2ecf20Sopenharmony_ci	snic_free_vnic_res(snic);
8098c2ecf20Sopenharmony_ci	snic_clear_intr_mode(snic);
8108c2ecf20Sopenharmony_ci	svnic_dev_close(snic->vdev);
8118c2ecf20Sopenharmony_ci	svnic_dev_unregister(snic->vdev);
8128c2ecf20Sopenharmony_ci	snic_iounmap(snic);
8138c2ecf20Sopenharmony_ci	pci_release_regions(pdev);
8148c2ecf20Sopenharmony_ci	pci_disable_device(pdev);
8158c2ecf20Sopenharmony_ci	pci_set_drvdata(pdev, NULL);
8168c2ecf20Sopenharmony_ci
8178c2ecf20Sopenharmony_ci	/* this frees Scsi_Host and snic memory (continuous chunk) */
8188c2ecf20Sopenharmony_ci	scsi_host_put(snic->shost);
8198c2ecf20Sopenharmony_ci} /* end of snic_remove */
8208c2ecf20Sopenharmony_ci
8218c2ecf20Sopenharmony_ci
8228c2ecf20Sopenharmony_cistruct snic_global *snic_glob;
8238c2ecf20Sopenharmony_ci
8248c2ecf20Sopenharmony_ci/*
8258c2ecf20Sopenharmony_ci * snic_global_data_init: Initialize SNIC Global Data
8268c2ecf20Sopenharmony_ci * Notes: All the global lists, variables should be part of global data
8278c2ecf20Sopenharmony_ci * this helps in debugging.
8288c2ecf20Sopenharmony_ci */
8298c2ecf20Sopenharmony_cistatic int
8308c2ecf20Sopenharmony_cisnic_global_data_init(void)
8318c2ecf20Sopenharmony_ci{
8328c2ecf20Sopenharmony_ci	int ret = 0;
8338c2ecf20Sopenharmony_ci	struct kmem_cache *cachep;
8348c2ecf20Sopenharmony_ci	ssize_t len = 0;
8358c2ecf20Sopenharmony_ci
8368c2ecf20Sopenharmony_ci	snic_glob = kzalloc(sizeof(*snic_glob), GFP_KERNEL);
8378c2ecf20Sopenharmony_ci
8388c2ecf20Sopenharmony_ci	if (!snic_glob) {
8398c2ecf20Sopenharmony_ci		SNIC_ERR("Failed to allocate Global Context.\n");
8408c2ecf20Sopenharmony_ci
8418c2ecf20Sopenharmony_ci		ret = -ENOMEM;
8428c2ecf20Sopenharmony_ci		goto gdi_end;
8438c2ecf20Sopenharmony_ci	}
8448c2ecf20Sopenharmony_ci
8458c2ecf20Sopenharmony_ci#ifdef CONFIG_SCSI_SNIC_DEBUG_FS
8468c2ecf20Sopenharmony_ci	/* Debugfs related Initialization */
8478c2ecf20Sopenharmony_ci	/* Create debugfs entries for snic */
8488c2ecf20Sopenharmony_ci	snic_debugfs_init();
8498c2ecf20Sopenharmony_ci
8508c2ecf20Sopenharmony_ci	/* Trace related Initialization */
8518c2ecf20Sopenharmony_ci	/* Allocate memory for trace buffer */
8528c2ecf20Sopenharmony_ci	ret = snic_trc_init();
8538c2ecf20Sopenharmony_ci	if (ret < 0) {
8548c2ecf20Sopenharmony_ci		SNIC_ERR("Trace buffer init failed, SNIC tracing disabled\n");
8558c2ecf20Sopenharmony_ci		snic_trc_free();
8568c2ecf20Sopenharmony_ci		/* continue even if it fails */
8578c2ecf20Sopenharmony_ci	}
8588c2ecf20Sopenharmony_ci
8598c2ecf20Sopenharmony_ci#endif
8608c2ecf20Sopenharmony_ci	INIT_LIST_HEAD(&snic_glob->snic_list);
8618c2ecf20Sopenharmony_ci	spin_lock_init(&snic_glob->snic_list_lock);
8628c2ecf20Sopenharmony_ci
8638c2ecf20Sopenharmony_ci	/* Create a cache for allocation of snic_host_req+default size ESGLs */
8648c2ecf20Sopenharmony_ci	len = sizeof(struct snic_req_info);
8658c2ecf20Sopenharmony_ci	len += sizeof(struct snic_host_req) + sizeof(struct snic_dflt_sgl);
8668c2ecf20Sopenharmony_ci	cachep = kmem_cache_create("snic_req_dfltsgl", len, SNIC_SG_DESC_ALIGN,
8678c2ecf20Sopenharmony_ci				   SLAB_HWCACHE_ALIGN, NULL);
8688c2ecf20Sopenharmony_ci	if (!cachep) {
8698c2ecf20Sopenharmony_ci		SNIC_ERR("Failed to create snic default sgl slab\n");
8708c2ecf20Sopenharmony_ci		ret = -ENOMEM;
8718c2ecf20Sopenharmony_ci
8728c2ecf20Sopenharmony_ci		goto err_dflt_req_slab;
8738c2ecf20Sopenharmony_ci	}
8748c2ecf20Sopenharmony_ci	snic_glob->req_cache[SNIC_REQ_CACHE_DFLT_SGL] = cachep;
8758c2ecf20Sopenharmony_ci
8768c2ecf20Sopenharmony_ci	/* Create a cache for allocation of max size Extended SGLs */
8778c2ecf20Sopenharmony_ci	len = sizeof(struct snic_req_info);
8788c2ecf20Sopenharmony_ci	len += sizeof(struct snic_host_req) + sizeof(struct snic_max_sgl);
8798c2ecf20Sopenharmony_ci	cachep = kmem_cache_create("snic_req_maxsgl", len, SNIC_SG_DESC_ALIGN,
8808c2ecf20Sopenharmony_ci				   SLAB_HWCACHE_ALIGN, NULL);
8818c2ecf20Sopenharmony_ci	if (!cachep) {
8828c2ecf20Sopenharmony_ci		SNIC_ERR("Failed to create snic max sgl slab\n");
8838c2ecf20Sopenharmony_ci		ret = -ENOMEM;
8848c2ecf20Sopenharmony_ci
8858c2ecf20Sopenharmony_ci		goto err_max_req_slab;
8868c2ecf20Sopenharmony_ci	}
8878c2ecf20Sopenharmony_ci	snic_glob->req_cache[SNIC_REQ_CACHE_MAX_SGL] = cachep;
8888c2ecf20Sopenharmony_ci
8898c2ecf20Sopenharmony_ci	len = sizeof(struct snic_host_req);
8908c2ecf20Sopenharmony_ci	cachep = kmem_cache_create("snic_req_maxsgl", len, SNIC_SG_DESC_ALIGN,
8918c2ecf20Sopenharmony_ci				   SLAB_HWCACHE_ALIGN, NULL);
8928c2ecf20Sopenharmony_ci	if (!cachep) {
8938c2ecf20Sopenharmony_ci		SNIC_ERR("Failed to create snic tm req slab\n");
8948c2ecf20Sopenharmony_ci		ret = -ENOMEM;
8958c2ecf20Sopenharmony_ci
8968c2ecf20Sopenharmony_ci		goto err_tmreq_slab;
8978c2ecf20Sopenharmony_ci	}
8988c2ecf20Sopenharmony_ci	snic_glob->req_cache[SNIC_REQ_TM_CACHE] = cachep;
8998c2ecf20Sopenharmony_ci
9008c2ecf20Sopenharmony_ci	/* snic_event queue */
9018c2ecf20Sopenharmony_ci	snic_glob->event_q = create_singlethread_workqueue("snic_event_wq");
9028c2ecf20Sopenharmony_ci	if (!snic_glob->event_q) {
9038c2ecf20Sopenharmony_ci		SNIC_ERR("snic event queue create failed\n");
9048c2ecf20Sopenharmony_ci		ret = -ENOMEM;
9058c2ecf20Sopenharmony_ci
9068c2ecf20Sopenharmony_ci		goto err_eventq;
9078c2ecf20Sopenharmony_ci	}
9088c2ecf20Sopenharmony_ci
9098c2ecf20Sopenharmony_ci	return ret;
9108c2ecf20Sopenharmony_ci
9118c2ecf20Sopenharmony_cierr_eventq:
9128c2ecf20Sopenharmony_ci	kmem_cache_destroy(snic_glob->req_cache[SNIC_REQ_TM_CACHE]);
9138c2ecf20Sopenharmony_ci
9148c2ecf20Sopenharmony_cierr_tmreq_slab:
9158c2ecf20Sopenharmony_ci	kmem_cache_destroy(snic_glob->req_cache[SNIC_REQ_CACHE_MAX_SGL]);
9168c2ecf20Sopenharmony_ci
9178c2ecf20Sopenharmony_cierr_max_req_slab:
9188c2ecf20Sopenharmony_ci	kmem_cache_destroy(snic_glob->req_cache[SNIC_REQ_CACHE_DFLT_SGL]);
9198c2ecf20Sopenharmony_ci
9208c2ecf20Sopenharmony_cierr_dflt_req_slab:
9218c2ecf20Sopenharmony_ci#ifdef CONFIG_SCSI_SNIC_DEBUG_FS
9228c2ecf20Sopenharmony_ci	snic_trc_free();
9238c2ecf20Sopenharmony_ci	snic_debugfs_term();
9248c2ecf20Sopenharmony_ci#endif
9258c2ecf20Sopenharmony_ci	kfree(snic_glob);
9268c2ecf20Sopenharmony_ci	snic_glob = NULL;
9278c2ecf20Sopenharmony_ci
9288c2ecf20Sopenharmony_cigdi_end:
9298c2ecf20Sopenharmony_ci	return ret;
9308c2ecf20Sopenharmony_ci} /* end of snic_glob_init */
9318c2ecf20Sopenharmony_ci
9328c2ecf20Sopenharmony_ci/*
9338c2ecf20Sopenharmony_ci * snic_global_data_cleanup : Frees SNIC Global Data
9348c2ecf20Sopenharmony_ci */
9358c2ecf20Sopenharmony_cistatic void
9368c2ecf20Sopenharmony_cisnic_global_data_cleanup(void)
9378c2ecf20Sopenharmony_ci{
9388c2ecf20Sopenharmony_ci	SNIC_BUG_ON(snic_glob == NULL);
9398c2ecf20Sopenharmony_ci
9408c2ecf20Sopenharmony_ci	destroy_workqueue(snic_glob->event_q);
9418c2ecf20Sopenharmony_ci	kmem_cache_destroy(snic_glob->req_cache[SNIC_REQ_TM_CACHE]);
9428c2ecf20Sopenharmony_ci	kmem_cache_destroy(snic_glob->req_cache[SNIC_REQ_CACHE_MAX_SGL]);
9438c2ecf20Sopenharmony_ci	kmem_cache_destroy(snic_glob->req_cache[SNIC_REQ_CACHE_DFLT_SGL]);
9448c2ecf20Sopenharmony_ci
9458c2ecf20Sopenharmony_ci#ifdef CONFIG_SCSI_SNIC_DEBUG_FS
9468c2ecf20Sopenharmony_ci	/* Freeing Trace Resources */
9478c2ecf20Sopenharmony_ci	snic_trc_free();
9488c2ecf20Sopenharmony_ci
9498c2ecf20Sopenharmony_ci	/* Freeing Debugfs Resources */
9508c2ecf20Sopenharmony_ci	snic_debugfs_term();
9518c2ecf20Sopenharmony_ci#endif
9528c2ecf20Sopenharmony_ci	kfree(snic_glob);
9538c2ecf20Sopenharmony_ci	snic_glob = NULL;
9548c2ecf20Sopenharmony_ci} /* end of snic_glob_cleanup */
9558c2ecf20Sopenharmony_ci
9568c2ecf20Sopenharmony_cistatic struct pci_driver snic_driver = {
9578c2ecf20Sopenharmony_ci	.name = SNIC_DRV_NAME,
9588c2ecf20Sopenharmony_ci	.id_table = snic_id_table,
9598c2ecf20Sopenharmony_ci	.probe = snic_probe,
9608c2ecf20Sopenharmony_ci	.remove = snic_remove,
9618c2ecf20Sopenharmony_ci};
9628c2ecf20Sopenharmony_ci
9638c2ecf20Sopenharmony_cistatic int __init
9648c2ecf20Sopenharmony_cisnic_init_module(void)
9658c2ecf20Sopenharmony_ci{
9668c2ecf20Sopenharmony_ci	int ret = 0;
9678c2ecf20Sopenharmony_ci
9688c2ecf20Sopenharmony_ci#ifndef __x86_64__
9698c2ecf20Sopenharmony_ci	SNIC_INFO("SNIC Driver is supported only for x86_64 platforms!\n");
9708c2ecf20Sopenharmony_ci	add_taint(TAINT_CPU_OUT_OF_SPEC, LOCKDEP_STILL_OK);
9718c2ecf20Sopenharmony_ci#endif
9728c2ecf20Sopenharmony_ci
9738c2ecf20Sopenharmony_ci	SNIC_INFO("%s, ver %s\n", SNIC_DRV_DESCRIPTION, SNIC_DRV_VERSION);
9748c2ecf20Sopenharmony_ci
9758c2ecf20Sopenharmony_ci	ret = snic_global_data_init();
9768c2ecf20Sopenharmony_ci	if (ret) {
9778c2ecf20Sopenharmony_ci		SNIC_ERR("Failed to Initialize Global Data.\n");
9788c2ecf20Sopenharmony_ci
9798c2ecf20Sopenharmony_ci		return ret;
9808c2ecf20Sopenharmony_ci	}
9818c2ecf20Sopenharmony_ci
9828c2ecf20Sopenharmony_ci	ret = pci_register_driver(&snic_driver);
9838c2ecf20Sopenharmony_ci	if (ret < 0) {
9848c2ecf20Sopenharmony_ci		SNIC_ERR("PCI driver register error\n");
9858c2ecf20Sopenharmony_ci
9868c2ecf20Sopenharmony_ci		goto err_pci_reg;
9878c2ecf20Sopenharmony_ci	}
9888c2ecf20Sopenharmony_ci
9898c2ecf20Sopenharmony_ci	return ret;
9908c2ecf20Sopenharmony_ci
9918c2ecf20Sopenharmony_cierr_pci_reg:
9928c2ecf20Sopenharmony_ci	snic_global_data_cleanup();
9938c2ecf20Sopenharmony_ci
9948c2ecf20Sopenharmony_ci	return ret;
9958c2ecf20Sopenharmony_ci}
9968c2ecf20Sopenharmony_ci
9978c2ecf20Sopenharmony_cistatic void __exit
9988c2ecf20Sopenharmony_cisnic_cleanup_module(void)
9998c2ecf20Sopenharmony_ci{
10008c2ecf20Sopenharmony_ci	pci_unregister_driver(&snic_driver);
10018c2ecf20Sopenharmony_ci	snic_global_data_cleanup();
10028c2ecf20Sopenharmony_ci}
10038c2ecf20Sopenharmony_ci
10048c2ecf20Sopenharmony_cimodule_init(snic_init_module);
10058c2ecf20Sopenharmony_cimodule_exit(snic_cleanup_module);
10068c2ecf20Sopenharmony_ci
10078c2ecf20Sopenharmony_ciMODULE_LICENSE("GPL v2");
10088c2ecf20Sopenharmony_ciMODULE_DESCRIPTION(SNIC_DRV_DESCRIPTION);
10098c2ecf20Sopenharmony_ciMODULE_VERSION(SNIC_DRV_VERSION);
10108c2ecf20Sopenharmony_ciMODULE_DEVICE_TABLE(pci, snic_id_table);
10118c2ecf20Sopenharmony_ciMODULE_AUTHOR("Narsimhulu Musini <nmusini@cisco.com>, "
10128c2ecf20Sopenharmony_ci	      "Sesidhar Baddela <sebaddel@cisco.com>");
1013