xref: /linux/drivers/scsi/csiostor/csio_init.c (revision 4bbd458eaa789959f23f4c998d30b972715e1013)
1a3667aaeSNaresh Kumar Inna /*
2a3667aaeSNaresh Kumar Inna  * This file is part of the Chelsio FCoE driver for Linux.
3a3667aaeSNaresh Kumar Inna  *
4a3667aaeSNaresh Kumar Inna  * Copyright (c) 2008-2012 Chelsio Communications, Inc. All rights reserved.
5a3667aaeSNaresh Kumar Inna  *
6a3667aaeSNaresh Kumar Inna  * This software is available to you under a choice of one of two
7a3667aaeSNaresh Kumar Inna  * licenses.  You may choose to be licensed under the terms of the GNU
8a3667aaeSNaresh Kumar Inna  * General Public License (GPL) Version 2, available from the file
9a3667aaeSNaresh Kumar Inna  * COPYING in the main directory of this source tree, or the
10a3667aaeSNaresh Kumar Inna  * OpenIB.org BSD license below:
11a3667aaeSNaresh Kumar Inna  *
12a3667aaeSNaresh Kumar Inna  *     Redistribution and use in source and binary forms, with or
13a3667aaeSNaresh Kumar Inna  *     without modification, are permitted provided that the following
14a3667aaeSNaresh Kumar Inna  *     conditions are met:
15a3667aaeSNaresh Kumar Inna  *
16a3667aaeSNaresh Kumar Inna  *      - Redistributions of source code must retain the above
17a3667aaeSNaresh Kumar Inna  *        copyright notice, this list of conditions and the following
18a3667aaeSNaresh Kumar Inna  *        disclaimer.
19a3667aaeSNaresh Kumar Inna  *
20a3667aaeSNaresh Kumar Inna  *      - Redistributions in binary form must reproduce the above
21a3667aaeSNaresh Kumar Inna  *        copyright notice, this list of conditions and the following
22a3667aaeSNaresh Kumar Inna  *        disclaimer in the documentation and/or other materials
23a3667aaeSNaresh Kumar Inna  *        provided with the distribution.
24a3667aaeSNaresh Kumar Inna  *
25a3667aaeSNaresh Kumar Inna  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
26a3667aaeSNaresh Kumar Inna  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27a3667aaeSNaresh Kumar Inna  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
28a3667aaeSNaresh Kumar Inna  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
29a3667aaeSNaresh Kumar Inna  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
30a3667aaeSNaresh Kumar Inna  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
31a3667aaeSNaresh Kumar Inna  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
32a3667aaeSNaresh Kumar Inna  * SOFTWARE.
33a3667aaeSNaresh Kumar Inna  */
34a3667aaeSNaresh Kumar Inna 
35a3667aaeSNaresh Kumar Inna #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
36a3667aaeSNaresh Kumar Inna 
37a3667aaeSNaresh Kumar Inna #include <linux/kernel.h>
38a3667aaeSNaresh Kumar Inna #include <linux/module.h>
39a3667aaeSNaresh Kumar Inna #include <linux/init.h>
40a3667aaeSNaresh Kumar Inna #include <linux/pci.h>
41a3667aaeSNaresh Kumar Inna #include <linux/aer.h>
42a3667aaeSNaresh Kumar Inna #include <linux/mm.h>
43a3667aaeSNaresh Kumar Inna #include <linux/notifier.h>
44a3667aaeSNaresh Kumar Inna #include <linux/kdebug.h>
45a3667aaeSNaresh Kumar Inna #include <linux/seq_file.h>
46a3667aaeSNaresh Kumar Inna #include <linux/debugfs.h>
47a3667aaeSNaresh Kumar Inna #include <linux/string.h>
48a3667aaeSNaresh Kumar Inna #include <linux/export.h>
49a3667aaeSNaresh Kumar Inna 
50a3667aaeSNaresh Kumar Inna #include "csio_init.h"
51a3667aaeSNaresh Kumar Inna #include "csio_defs.h"
52a3667aaeSNaresh Kumar Inna 
53a3667aaeSNaresh Kumar Inna #define CSIO_MIN_MEMPOOL_SZ	64
54a3667aaeSNaresh Kumar Inna 
55a3667aaeSNaresh Kumar Inna static struct dentry *csio_debugfs_root;
56a3667aaeSNaresh Kumar Inna 
57a3667aaeSNaresh Kumar Inna static struct scsi_transport_template *csio_fcoe_transport;
58a3667aaeSNaresh Kumar Inna static struct scsi_transport_template *csio_fcoe_transport_vport;
59a3667aaeSNaresh Kumar Inna 
60a3667aaeSNaresh Kumar Inna /*
61a3667aaeSNaresh Kumar Inna  * debugfs support
62a3667aaeSNaresh Kumar Inna  */
63a3667aaeSNaresh Kumar Inna static ssize_t
64a3667aaeSNaresh Kumar Inna csio_mem_read(struct file *file, char __user *buf, size_t count, loff_t *ppos)
65a3667aaeSNaresh Kumar Inna {
66a3667aaeSNaresh Kumar Inna 	loff_t pos = *ppos;
67496ad9aaSAl Viro 	loff_t avail = file_inode(file)->i_size;
68a3667aaeSNaresh Kumar Inna 	unsigned int mem = (uintptr_t)file->private_data & 3;
69a3667aaeSNaresh Kumar Inna 	struct csio_hw *hw = file->private_data - mem;
70a3667aaeSNaresh Kumar Inna 
71a3667aaeSNaresh Kumar Inna 	if (pos < 0)
72a3667aaeSNaresh Kumar Inna 		return -EINVAL;
73a3667aaeSNaresh Kumar Inna 	if (pos >= avail)
74a3667aaeSNaresh Kumar Inna 		return 0;
75a3667aaeSNaresh Kumar Inna 	if (count > avail - pos)
76a3667aaeSNaresh Kumar Inna 		count = avail - pos;
77a3667aaeSNaresh Kumar Inna 
78a3667aaeSNaresh Kumar Inna 	while (count) {
79a3667aaeSNaresh Kumar Inna 		size_t len;
80a3667aaeSNaresh Kumar Inna 		int ret, ofst;
81a3667aaeSNaresh Kumar Inna 		__be32 data[16];
82a3667aaeSNaresh Kumar Inna 
83a3667aaeSNaresh Kumar Inna 		if (mem == MEM_MC)
847cc16380SArvind Bhushan 			ret = hw->chip_ops->chip_mc_read(hw, 0, pos,
857cc16380SArvind Bhushan 							 data, NULL);
86a3667aaeSNaresh Kumar Inna 		else
877cc16380SArvind Bhushan 			ret = hw->chip_ops->chip_edc_read(hw, mem, pos,
887cc16380SArvind Bhushan 							  data, NULL);
89a3667aaeSNaresh Kumar Inna 		if (ret)
90a3667aaeSNaresh Kumar Inna 			return ret;
91a3667aaeSNaresh Kumar Inna 
92a3667aaeSNaresh Kumar Inna 		ofst = pos % sizeof(data);
93a3667aaeSNaresh Kumar Inna 		len = min(count, sizeof(data) - ofst);
94a3667aaeSNaresh Kumar Inna 		if (copy_to_user(buf, (u8 *)data + ofst, len))
95a3667aaeSNaresh Kumar Inna 			return -EFAULT;
96a3667aaeSNaresh Kumar Inna 
97a3667aaeSNaresh Kumar Inna 		buf += len;
98a3667aaeSNaresh Kumar Inna 		pos += len;
99a3667aaeSNaresh Kumar Inna 		count -= len;
100a3667aaeSNaresh Kumar Inna 	}
101a3667aaeSNaresh Kumar Inna 	count = pos - *ppos;
102a3667aaeSNaresh Kumar Inna 	*ppos = pos;
103a3667aaeSNaresh Kumar Inna 	return count;
104a3667aaeSNaresh Kumar Inna }
105a3667aaeSNaresh Kumar Inna 
106a3667aaeSNaresh Kumar Inna static const struct file_operations csio_mem_debugfs_fops = {
107a3667aaeSNaresh Kumar Inna 	.owner   = THIS_MODULE,
108f07cda8fSWei Yongjun 	.open    = simple_open,
109a3667aaeSNaresh Kumar Inna 	.read    = csio_mem_read,
110a3667aaeSNaresh Kumar Inna 	.llseek  = default_llseek,
111a3667aaeSNaresh Kumar Inna };
112a3667aaeSNaresh Kumar Inna 
1137cc16380SArvind Bhushan void csio_add_debugfs_mem(struct csio_hw *hw, const char *name,
114a3667aaeSNaresh Kumar Inna 				 unsigned int idx, unsigned int size_mb)
115a3667aaeSNaresh Kumar Inna {
116e59b4e91SDavid Howells 	debugfs_create_file_size(name, S_IRUSR, hw->debugfs_root,
117e59b4e91SDavid Howells 				 (void *)hw + idx, &csio_mem_debugfs_fops,
118e59b4e91SDavid Howells 				 size_mb << 20);
119a3667aaeSNaresh Kumar Inna }
120a3667aaeSNaresh Kumar Inna 
1216f039790SGreg Kroah-Hartman static int csio_setup_debugfs(struct csio_hw *hw)
122a3667aaeSNaresh Kumar Inna {
123a3667aaeSNaresh Kumar Inna 	int i;
124a3667aaeSNaresh Kumar Inna 
125a3667aaeSNaresh Kumar Inna 	if (IS_ERR_OR_NULL(hw->debugfs_root))
126a3667aaeSNaresh Kumar Inna 		return -1;
127a3667aaeSNaresh Kumar Inna 
1286559a7e8SHariprasad Shenai 	i = csio_rd_reg32(hw, MA_TARGET_MEM_ENABLE_A);
1296559a7e8SHariprasad Shenai 	if (i & EDRAM0_ENABLE_F)
130a3667aaeSNaresh Kumar Inna 		csio_add_debugfs_mem(hw, "edc0", MEM_EDC0, 5);
1316559a7e8SHariprasad Shenai 	if (i & EDRAM1_ENABLE_F)
132a3667aaeSNaresh Kumar Inna 		csio_add_debugfs_mem(hw, "edc1", MEM_EDC1, 5);
1337cc16380SArvind Bhushan 
1347cc16380SArvind Bhushan 	hw->chip_ops->chip_dfs_create_ext_mem(hw);
135a3667aaeSNaresh Kumar Inna 	return 0;
136a3667aaeSNaresh Kumar Inna }
137a3667aaeSNaresh Kumar Inna 
138a3667aaeSNaresh Kumar Inna /*
139a3667aaeSNaresh Kumar Inna  * csio_dfs_create - Creates and sets up per-hw debugfs.
140a3667aaeSNaresh Kumar Inna  *
141a3667aaeSNaresh Kumar Inna  */
142a3667aaeSNaresh Kumar Inna static int
143a3667aaeSNaresh Kumar Inna csio_dfs_create(struct csio_hw *hw)
144a3667aaeSNaresh Kumar Inna {
145a3667aaeSNaresh Kumar Inna 	if (csio_debugfs_root) {
146a3667aaeSNaresh Kumar Inna 		hw->debugfs_root = debugfs_create_dir(pci_name(hw->pdev),
147a3667aaeSNaresh Kumar Inna 							csio_debugfs_root);
148a3667aaeSNaresh Kumar Inna 		csio_setup_debugfs(hw);
149a3667aaeSNaresh Kumar Inna 	}
150a3667aaeSNaresh Kumar Inna 
151a3667aaeSNaresh Kumar Inna 	return 0;
152a3667aaeSNaresh Kumar Inna }
153a3667aaeSNaresh Kumar Inna 
154a3667aaeSNaresh Kumar Inna /*
155a3667aaeSNaresh Kumar Inna  * csio_dfs_destroy - Destroys per-hw debugfs.
156a3667aaeSNaresh Kumar Inna  */
157a3667aaeSNaresh Kumar Inna static int
158a3667aaeSNaresh Kumar Inna csio_dfs_destroy(struct csio_hw *hw)
159a3667aaeSNaresh Kumar Inna {
160a3667aaeSNaresh Kumar Inna 	if (hw->debugfs_root)
161a3667aaeSNaresh Kumar Inna 		debugfs_remove_recursive(hw->debugfs_root);
162a3667aaeSNaresh Kumar Inna 
163a3667aaeSNaresh Kumar Inna 	return 0;
164a3667aaeSNaresh Kumar Inna }
165a3667aaeSNaresh Kumar Inna 
166a3667aaeSNaresh Kumar Inna /*
167a3667aaeSNaresh Kumar Inna  * csio_dfs_init - Debug filesystem initialization for the module.
168a3667aaeSNaresh Kumar Inna  *
169a3667aaeSNaresh Kumar Inna  */
170a3667aaeSNaresh Kumar Inna static int
171a3667aaeSNaresh Kumar Inna csio_dfs_init(void)
172a3667aaeSNaresh Kumar Inna {
173a3667aaeSNaresh Kumar Inna 	csio_debugfs_root = debugfs_create_dir(KBUILD_MODNAME, NULL);
174a3667aaeSNaresh Kumar Inna 	if (!csio_debugfs_root)
175a3667aaeSNaresh Kumar Inna 		pr_warn("Could not create debugfs entry, continuing\n");
176a3667aaeSNaresh Kumar Inna 
177a3667aaeSNaresh Kumar Inna 	return 0;
178a3667aaeSNaresh Kumar Inna }
179a3667aaeSNaresh Kumar Inna 
180a3667aaeSNaresh Kumar Inna /*
181a3667aaeSNaresh Kumar Inna  * csio_dfs_exit - debugfs cleanup for the module.
182a3667aaeSNaresh Kumar Inna  */
183a3667aaeSNaresh Kumar Inna static void
184a3667aaeSNaresh Kumar Inna csio_dfs_exit(void)
185a3667aaeSNaresh Kumar Inna {
186a3667aaeSNaresh Kumar Inna 	debugfs_remove(csio_debugfs_root);
187a3667aaeSNaresh Kumar Inna }
188a3667aaeSNaresh Kumar Inna 
189a3667aaeSNaresh Kumar Inna /*
190a3667aaeSNaresh Kumar Inna  * csio_pci_init - PCI initialization.
191a3667aaeSNaresh Kumar Inna  * @pdev: PCI device.
192a3667aaeSNaresh Kumar Inna  * @bars: Bitmask of bars to be requested.
193a3667aaeSNaresh Kumar Inna  *
194a3667aaeSNaresh Kumar Inna  * Initializes the PCI function by enabling MMIO, setting bus
195a3667aaeSNaresh Kumar Inna  * mastership and setting DMA mask.
196a3667aaeSNaresh Kumar Inna  */
197a3667aaeSNaresh Kumar Inna static int
198a3667aaeSNaresh Kumar Inna csio_pci_init(struct pci_dev *pdev, int *bars)
199a3667aaeSNaresh Kumar Inna {
200a3667aaeSNaresh Kumar Inna 	int rv = -ENODEV;
201a3667aaeSNaresh Kumar Inna 
202a3667aaeSNaresh Kumar Inna 	*bars = pci_select_bars(pdev, IORESOURCE_MEM);
203a3667aaeSNaresh Kumar Inna 
204a3667aaeSNaresh Kumar Inna 	if (pci_enable_device_mem(pdev))
205a3667aaeSNaresh Kumar Inna 		goto err;
206a3667aaeSNaresh Kumar Inna 
207a3667aaeSNaresh Kumar Inna 	if (pci_request_selected_regions(pdev, *bars, KBUILD_MODNAME))
208a3667aaeSNaresh Kumar Inna 		goto err_disable_device;
209a3667aaeSNaresh Kumar Inna 
210a3667aaeSNaresh Kumar Inna 	pci_set_master(pdev);
211a3667aaeSNaresh Kumar Inna 	pci_try_set_mwi(pdev);
212a3667aaeSNaresh Kumar Inna 
213a3667aaeSNaresh Kumar Inna 	if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(64))) {
214a3667aaeSNaresh Kumar Inna 		pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64));
215a3667aaeSNaresh Kumar Inna 	} else if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(32))) {
216a3667aaeSNaresh Kumar Inna 		pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
217a3667aaeSNaresh Kumar Inna 	} else {
218a3667aaeSNaresh Kumar Inna 		dev_err(&pdev->dev, "No suitable DMA available.\n");
219a3667aaeSNaresh Kumar Inna 		goto err_release_regions;
220a3667aaeSNaresh Kumar Inna 	}
221a3667aaeSNaresh Kumar Inna 
222a3667aaeSNaresh Kumar Inna 	return 0;
223a3667aaeSNaresh Kumar Inna 
224a3667aaeSNaresh Kumar Inna err_release_regions:
225a3667aaeSNaresh Kumar Inna 	pci_release_selected_regions(pdev, *bars);
226a3667aaeSNaresh Kumar Inna err_disable_device:
227a3667aaeSNaresh Kumar Inna 	pci_disable_device(pdev);
228a3667aaeSNaresh Kumar Inna err:
229a3667aaeSNaresh Kumar Inna 	return rv;
230a3667aaeSNaresh Kumar Inna 
231a3667aaeSNaresh Kumar Inna }
232a3667aaeSNaresh Kumar Inna 
233a3667aaeSNaresh Kumar Inna /*
234a3667aaeSNaresh Kumar Inna  * csio_pci_exit - PCI unitialization.
235a3667aaeSNaresh Kumar Inna  * @pdev: PCI device.
236a3667aaeSNaresh Kumar Inna  * @bars: Bars to be released.
237a3667aaeSNaresh Kumar Inna  *
238a3667aaeSNaresh Kumar Inna  */
239a3667aaeSNaresh Kumar Inna static void
240a3667aaeSNaresh Kumar Inna csio_pci_exit(struct pci_dev *pdev, int *bars)
241a3667aaeSNaresh Kumar Inna {
242a3667aaeSNaresh Kumar Inna 	pci_release_selected_regions(pdev, *bars);
243a3667aaeSNaresh Kumar Inna 	pci_disable_device(pdev);
244a3667aaeSNaresh Kumar Inna }
245a3667aaeSNaresh Kumar Inna 
246a3667aaeSNaresh Kumar Inna /*
247a3667aaeSNaresh Kumar Inna  * csio_hw_init_workers - Initialize the HW module's worker threads.
248a3667aaeSNaresh Kumar Inna  * @hw: HW module.
249a3667aaeSNaresh Kumar Inna  *
250a3667aaeSNaresh Kumar Inna  */
251a3667aaeSNaresh Kumar Inna static void
252a3667aaeSNaresh Kumar Inna csio_hw_init_workers(struct csio_hw *hw)
253a3667aaeSNaresh Kumar Inna {
254a3667aaeSNaresh Kumar Inna 	INIT_WORK(&hw->evtq_work, csio_evtq_worker);
255a3667aaeSNaresh Kumar Inna }
256a3667aaeSNaresh Kumar Inna 
257a3667aaeSNaresh Kumar Inna static void
258a3667aaeSNaresh Kumar Inna csio_hw_exit_workers(struct csio_hw *hw)
259a3667aaeSNaresh Kumar Inna {
260a3667aaeSNaresh Kumar Inna 	cancel_work_sync(&hw->evtq_work);
261a3667aaeSNaresh Kumar Inna 	flush_scheduled_work();
262a3667aaeSNaresh Kumar Inna }
263a3667aaeSNaresh Kumar Inna 
264a3667aaeSNaresh Kumar Inna static int
265a3667aaeSNaresh Kumar Inna csio_create_queues(struct csio_hw *hw)
266a3667aaeSNaresh Kumar Inna {
267a3667aaeSNaresh Kumar Inna 	int i, j;
268a3667aaeSNaresh Kumar Inna 	struct csio_mgmtm *mgmtm = csio_hw_to_mgmtm(hw);
269a3667aaeSNaresh Kumar Inna 	int rv;
270a3667aaeSNaresh Kumar Inna 	struct csio_scsi_cpu_info *info;
271a3667aaeSNaresh Kumar Inna 
272a3667aaeSNaresh Kumar Inna 	if (hw->flags & CSIO_HWF_Q_FW_ALLOCED)
273a3667aaeSNaresh Kumar Inna 		return 0;
274a3667aaeSNaresh Kumar Inna 
275a3667aaeSNaresh Kumar Inna 	if (hw->intr_mode != CSIO_IM_MSIX) {
276a3667aaeSNaresh Kumar Inna 		rv = csio_wr_iq_create(hw, NULL, hw->intr_iq_idx,
277a3667aaeSNaresh Kumar Inna 					0, hw->pport[0].portid, false, NULL);
278a3667aaeSNaresh Kumar Inna 		if (rv != 0) {
279a3667aaeSNaresh Kumar Inna 			csio_err(hw, " Forward Interrupt IQ failed!: %d\n", rv);
280a3667aaeSNaresh Kumar Inna 			return rv;
281a3667aaeSNaresh Kumar Inna 		}
282a3667aaeSNaresh Kumar Inna 	}
283a3667aaeSNaresh Kumar Inna 
284a3667aaeSNaresh Kumar Inna 	/* FW event queue */
285a3667aaeSNaresh Kumar Inna 	rv = csio_wr_iq_create(hw, NULL, hw->fwevt_iq_idx,
286a3667aaeSNaresh Kumar Inna 			       csio_get_fwevt_intr_idx(hw),
287a3667aaeSNaresh Kumar Inna 			       hw->pport[0].portid, true, NULL);
288a3667aaeSNaresh Kumar Inna 	if (rv != 0) {
289a3667aaeSNaresh Kumar Inna 		csio_err(hw, "FW event IQ config failed!: %d\n", rv);
290a3667aaeSNaresh Kumar Inna 		return rv;
291a3667aaeSNaresh Kumar Inna 	}
292a3667aaeSNaresh Kumar Inna 
293a3667aaeSNaresh Kumar Inna 	/* Create mgmt queue */
294a3667aaeSNaresh Kumar Inna 	rv = csio_wr_eq_create(hw, NULL, mgmtm->eq_idx,
295a3667aaeSNaresh Kumar Inna 			mgmtm->iq_idx, hw->pport[0].portid, NULL);
296a3667aaeSNaresh Kumar Inna 
297a3667aaeSNaresh Kumar Inna 	if (rv != 0) {
298a3667aaeSNaresh Kumar Inna 		csio_err(hw, "Mgmt EQ create failed!: %d\n", rv);
299a3667aaeSNaresh Kumar Inna 		goto err;
300a3667aaeSNaresh Kumar Inna 	}
301a3667aaeSNaresh Kumar Inna 
302a3667aaeSNaresh Kumar Inna 	/* Create SCSI queues */
303a3667aaeSNaresh Kumar Inna 	for (i = 0; i < hw->num_pports; i++) {
304a3667aaeSNaresh Kumar Inna 		info = &hw->scsi_cpu_info[i];
305a3667aaeSNaresh Kumar Inna 
306a3667aaeSNaresh Kumar Inna 		for (j = 0; j < info->max_cpus; j++) {
307a3667aaeSNaresh Kumar Inna 			struct csio_scsi_qset *sqset = &hw->sqset[i][j];
308a3667aaeSNaresh Kumar Inna 
309a3667aaeSNaresh Kumar Inna 			rv = csio_wr_iq_create(hw, NULL, sqset->iq_idx,
310a3667aaeSNaresh Kumar Inna 					       sqset->intr_idx, i, false, NULL);
311a3667aaeSNaresh Kumar Inna 			if (rv != 0) {
312a3667aaeSNaresh Kumar Inna 				csio_err(hw,
313a3667aaeSNaresh Kumar Inna 				   "SCSI module IQ config failed [%d][%d]:%d\n",
314a3667aaeSNaresh Kumar Inna 				   i, j, rv);
315a3667aaeSNaresh Kumar Inna 				goto err;
316a3667aaeSNaresh Kumar Inna 			}
317a3667aaeSNaresh Kumar Inna 			rv = csio_wr_eq_create(hw, NULL, sqset->eq_idx,
318a3667aaeSNaresh Kumar Inna 					       sqset->iq_idx, i, NULL);
319a3667aaeSNaresh Kumar Inna 			if (rv != 0) {
320a3667aaeSNaresh Kumar Inna 				csio_err(hw,
321a3667aaeSNaresh Kumar Inna 				   "SCSI module EQ config failed [%d][%d]:%d\n",
322a3667aaeSNaresh Kumar Inna 				   i, j, rv);
323a3667aaeSNaresh Kumar Inna 				goto err;
324a3667aaeSNaresh Kumar Inna 			}
325a3667aaeSNaresh Kumar Inna 		} /* for all CPUs */
326a3667aaeSNaresh Kumar Inna 	} /* For all ports */
327a3667aaeSNaresh Kumar Inna 
328a3667aaeSNaresh Kumar Inna 	hw->flags |= CSIO_HWF_Q_FW_ALLOCED;
329a3667aaeSNaresh Kumar Inna 	return 0;
330a3667aaeSNaresh Kumar Inna err:
331a3667aaeSNaresh Kumar Inna 	csio_wr_destroy_queues(hw, true);
332a3667aaeSNaresh Kumar Inna 	return -EINVAL;
333a3667aaeSNaresh Kumar Inna }
334a3667aaeSNaresh Kumar Inna 
335a3667aaeSNaresh Kumar Inna /*
336a3667aaeSNaresh Kumar Inna  * csio_config_queues - Configure the DMA queues.
337a3667aaeSNaresh Kumar Inna  * @hw: HW module.
338a3667aaeSNaresh Kumar Inna  *
339a3667aaeSNaresh Kumar Inna  * Allocates memory for queues are registers them with FW.
340a3667aaeSNaresh Kumar Inna  */
341a3667aaeSNaresh Kumar Inna int
342a3667aaeSNaresh Kumar Inna csio_config_queues(struct csio_hw *hw)
343a3667aaeSNaresh Kumar Inna {
344a3667aaeSNaresh Kumar Inna 	int i, j, idx, k = 0;
345a3667aaeSNaresh Kumar Inna 	int rv;
346a3667aaeSNaresh Kumar Inna 	struct csio_scsi_qset *sqset;
347a3667aaeSNaresh Kumar Inna 	struct csio_mgmtm *mgmtm = csio_hw_to_mgmtm(hw);
348a3667aaeSNaresh Kumar Inna 	struct csio_scsi_qset *orig;
349a3667aaeSNaresh Kumar Inna 	struct csio_scsi_cpu_info *info;
350a3667aaeSNaresh Kumar Inna 
351a3667aaeSNaresh Kumar Inna 	if (hw->flags & CSIO_HWF_Q_MEM_ALLOCED)
352a3667aaeSNaresh Kumar Inna 		return csio_create_queues(hw);
353a3667aaeSNaresh Kumar Inna 
354a3667aaeSNaresh Kumar Inna 	/* Calculate number of SCSI queues for MSIX we would like */
355a3667aaeSNaresh Kumar Inna 	hw->num_scsi_msix_cpus = num_online_cpus();
356a3667aaeSNaresh Kumar Inna 	hw->num_sqsets = num_online_cpus() * hw->num_pports;
357a3667aaeSNaresh Kumar Inna 
358a3667aaeSNaresh Kumar Inna 	if (hw->num_sqsets > CSIO_MAX_SCSI_QSETS) {
359a3667aaeSNaresh Kumar Inna 		hw->num_sqsets = CSIO_MAX_SCSI_QSETS;
360a3667aaeSNaresh Kumar Inna 		hw->num_scsi_msix_cpus = CSIO_MAX_SCSI_CPU;
361a3667aaeSNaresh Kumar Inna 	}
362a3667aaeSNaresh Kumar Inna 
363a3667aaeSNaresh Kumar Inna 	/* Initialize max_cpus, may get reduced during msix allocations */
364a3667aaeSNaresh Kumar Inna 	for (i = 0; i < hw->num_pports; i++)
365a3667aaeSNaresh Kumar Inna 		hw->scsi_cpu_info[i].max_cpus = hw->num_scsi_msix_cpus;
366a3667aaeSNaresh Kumar Inna 
367a3667aaeSNaresh Kumar Inna 	csio_dbg(hw, "nsqsets:%d scpus:%d\n",
368a3667aaeSNaresh Kumar Inna 		    hw->num_sqsets, hw->num_scsi_msix_cpus);
369a3667aaeSNaresh Kumar Inna 
370a3667aaeSNaresh Kumar Inna 	csio_intr_enable(hw);
371a3667aaeSNaresh Kumar Inna 
372a3667aaeSNaresh Kumar Inna 	if (hw->intr_mode != CSIO_IM_MSIX) {
373a3667aaeSNaresh Kumar Inna 
374a3667aaeSNaresh Kumar Inna 		/* Allocate Forward interrupt iq. */
375a3667aaeSNaresh Kumar Inna 		hw->intr_iq_idx = csio_wr_alloc_q(hw, CSIO_INTR_IQSIZE,
376a3667aaeSNaresh Kumar Inna 						CSIO_INTR_WRSIZE, CSIO_INGRESS,
377a3667aaeSNaresh Kumar Inna 						(void *)hw, 0, 0, NULL);
378a3667aaeSNaresh Kumar Inna 		if (hw->intr_iq_idx == -1) {
379a3667aaeSNaresh Kumar Inna 			csio_err(hw,
380a3667aaeSNaresh Kumar Inna 				 "Forward interrupt queue creation failed\n");
381a3667aaeSNaresh Kumar Inna 			goto intr_disable;
382a3667aaeSNaresh Kumar Inna 		}
383a3667aaeSNaresh Kumar Inna 	}
384a3667aaeSNaresh Kumar Inna 
385a3667aaeSNaresh Kumar Inna 	/* Allocate the FW evt queue */
386a3667aaeSNaresh Kumar Inna 	hw->fwevt_iq_idx = csio_wr_alloc_q(hw, CSIO_FWEVT_IQSIZE,
387a3667aaeSNaresh Kumar Inna 					   CSIO_FWEVT_WRSIZE,
388a3667aaeSNaresh Kumar Inna 					   CSIO_INGRESS, (void *)hw,
389a3667aaeSNaresh Kumar Inna 					   CSIO_FWEVT_FLBUFS, 0,
390a3667aaeSNaresh Kumar Inna 					   csio_fwevt_intx_handler);
391a3667aaeSNaresh Kumar Inna 	if (hw->fwevt_iq_idx == -1) {
392a3667aaeSNaresh Kumar Inna 		csio_err(hw, "FW evt queue creation failed\n");
393a3667aaeSNaresh Kumar Inna 		goto intr_disable;
394a3667aaeSNaresh Kumar Inna 	}
395a3667aaeSNaresh Kumar Inna 
396a3667aaeSNaresh Kumar Inna 	/* Allocate the mgmt queue */
397a3667aaeSNaresh Kumar Inna 	mgmtm->eq_idx = csio_wr_alloc_q(hw, CSIO_MGMT_EQSIZE,
398a3667aaeSNaresh Kumar Inna 				      CSIO_MGMT_EQ_WRSIZE,
399a3667aaeSNaresh Kumar Inna 				      CSIO_EGRESS, (void *)hw, 0, 0, NULL);
400a3667aaeSNaresh Kumar Inna 	if (mgmtm->eq_idx == -1) {
401a3667aaeSNaresh Kumar Inna 		csio_err(hw, "Failed to alloc egress queue for mgmt module\n");
402a3667aaeSNaresh Kumar Inna 		goto intr_disable;
403a3667aaeSNaresh Kumar Inna 	}
404a3667aaeSNaresh Kumar Inna 
405a3667aaeSNaresh Kumar Inna 	/* Use FW IQ for MGMT req completion */
406a3667aaeSNaresh Kumar Inna 	mgmtm->iq_idx = hw->fwevt_iq_idx;
407a3667aaeSNaresh Kumar Inna 
408a3667aaeSNaresh Kumar Inna 	/* Allocate SCSI queues */
409a3667aaeSNaresh Kumar Inna 	for (i = 0; i < hw->num_pports; i++) {
410a3667aaeSNaresh Kumar Inna 		info = &hw->scsi_cpu_info[i];
411a3667aaeSNaresh Kumar Inna 
412a3667aaeSNaresh Kumar Inna 		for (j = 0; j < hw->num_scsi_msix_cpus; j++) {
413a3667aaeSNaresh Kumar Inna 			sqset = &hw->sqset[i][j];
414a3667aaeSNaresh Kumar Inna 
415a3667aaeSNaresh Kumar Inna 			if (j >= info->max_cpus) {
416a3667aaeSNaresh Kumar Inna 				k = j % info->max_cpus;
417a3667aaeSNaresh Kumar Inna 				orig = &hw->sqset[i][k];
418a3667aaeSNaresh Kumar Inna 				sqset->eq_idx = orig->eq_idx;
419a3667aaeSNaresh Kumar Inna 				sqset->iq_idx = orig->iq_idx;
420a3667aaeSNaresh Kumar Inna 				continue;
421a3667aaeSNaresh Kumar Inna 			}
422a3667aaeSNaresh Kumar Inna 
423a3667aaeSNaresh Kumar Inna 			idx = csio_wr_alloc_q(hw, csio_scsi_eqsize, 0,
424a3667aaeSNaresh Kumar Inna 					      CSIO_EGRESS, (void *)hw, 0, 0,
425a3667aaeSNaresh Kumar Inna 					      NULL);
426a3667aaeSNaresh Kumar Inna 			if (idx == -1) {
427a3667aaeSNaresh Kumar Inna 				csio_err(hw, "EQ creation failed for idx:%d\n",
428a3667aaeSNaresh Kumar Inna 					    idx);
429a3667aaeSNaresh Kumar Inna 				goto intr_disable;
430a3667aaeSNaresh Kumar Inna 			}
431a3667aaeSNaresh Kumar Inna 
432a3667aaeSNaresh Kumar Inna 			sqset->eq_idx = idx;
433a3667aaeSNaresh Kumar Inna 
434a3667aaeSNaresh Kumar Inna 			idx = csio_wr_alloc_q(hw, CSIO_SCSI_IQSIZE,
435a3667aaeSNaresh Kumar Inna 					     CSIO_SCSI_IQ_WRSZ, CSIO_INGRESS,
436a3667aaeSNaresh Kumar Inna 					     (void *)hw, 0, 0,
437a3667aaeSNaresh Kumar Inna 					     csio_scsi_intx_handler);
438a3667aaeSNaresh Kumar Inna 			if (idx == -1) {
439a3667aaeSNaresh Kumar Inna 				csio_err(hw, "IQ creation failed for idx:%d\n",
440a3667aaeSNaresh Kumar Inna 					    idx);
441a3667aaeSNaresh Kumar Inna 				goto intr_disable;
442a3667aaeSNaresh Kumar Inna 			}
443a3667aaeSNaresh Kumar Inna 			sqset->iq_idx = idx;
444a3667aaeSNaresh Kumar Inna 		} /* for all CPUs */
445a3667aaeSNaresh Kumar Inna 	} /* For all ports */
446a3667aaeSNaresh Kumar Inna 
447a3667aaeSNaresh Kumar Inna 	hw->flags |= CSIO_HWF_Q_MEM_ALLOCED;
448a3667aaeSNaresh Kumar Inna 
449a3667aaeSNaresh Kumar Inna 	rv = csio_create_queues(hw);
450a3667aaeSNaresh Kumar Inna 	if (rv != 0)
451a3667aaeSNaresh Kumar Inna 		goto intr_disable;
452a3667aaeSNaresh Kumar Inna 
453a3667aaeSNaresh Kumar Inna 	/*
454a3667aaeSNaresh Kumar Inna 	 * Now request IRQs for the vectors. In the event of a failure,
455a3667aaeSNaresh Kumar Inna 	 * cleanup is handled internally by this function.
456a3667aaeSNaresh Kumar Inna 	 */
457a3667aaeSNaresh Kumar Inna 	rv = csio_request_irqs(hw);
458a3667aaeSNaresh Kumar Inna 	if (rv != 0)
459a3667aaeSNaresh Kumar Inna 		return -EINVAL;
460a3667aaeSNaresh Kumar Inna 
461a3667aaeSNaresh Kumar Inna 	return 0;
462a3667aaeSNaresh Kumar Inna 
463a3667aaeSNaresh Kumar Inna intr_disable:
464a3667aaeSNaresh Kumar Inna 	csio_intr_disable(hw, false);
465a3667aaeSNaresh Kumar Inna 
466a3667aaeSNaresh Kumar Inna 	return -EINVAL;
467a3667aaeSNaresh Kumar Inna }
468a3667aaeSNaresh Kumar Inna 
469a3667aaeSNaresh Kumar Inna static int
470a3667aaeSNaresh Kumar Inna csio_resource_alloc(struct csio_hw *hw)
471a3667aaeSNaresh Kumar Inna {
472a3667aaeSNaresh Kumar Inna 	struct csio_wrm *wrm = csio_hw_to_wrm(hw);
473a3667aaeSNaresh Kumar Inna 	int rv = -ENOMEM;
474a3667aaeSNaresh Kumar Inna 
475a3667aaeSNaresh Kumar Inna 	wrm->num_q = ((CSIO_MAX_SCSI_QSETS * 2) + CSIO_HW_NIQ +
476a3667aaeSNaresh Kumar Inna 		       CSIO_HW_NEQ + CSIO_HW_NFLQ + CSIO_HW_NINTXQ);
477a3667aaeSNaresh Kumar Inna 
478a3667aaeSNaresh Kumar Inna 	hw->mb_mempool = mempool_create_kmalloc_pool(CSIO_MIN_MEMPOOL_SZ,
479a3667aaeSNaresh Kumar Inna 						  sizeof(struct csio_mb));
480a3667aaeSNaresh Kumar Inna 	if (!hw->mb_mempool)
481a3667aaeSNaresh Kumar Inna 		goto err;
482a3667aaeSNaresh Kumar Inna 
483a3667aaeSNaresh Kumar Inna 	hw->rnode_mempool = mempool_create_kmalloc_pool(CSIO_MIN_MEMPOOL_SZ,
484a3667aaeSNaresh Kumar Inna 						     sizeof(struct csio_rnode));
485a3667aaeSNaresh Kumar Inna 	if (!hw->rnode_mempool)
486a3667aaeSNaresh Kumar Inna 		goto err_free_mb_mempool;
487a3667aaeSNaresh Kumar Inna 
488a3667aaeSNaresh Kumar Inna 	hw->scsi_pci_pool = pci_pool_create("csio_scsi_pci_pool", hw->pdev,
489a3667aaeSNaresh Kumar Inna 					    CSIO_SCSI_RSP_LEN, 8, 0);
490a3667aaeSNaresh Kumar Inna 	if (!hw->scsi_pci_pool)
491a3667aaeSNaresh Kumar Inna 		goto err_free_rn_pool;
492a3667aaeSNaresh Kumar Inna 
493a3667aaeSNaresh Kumar Inna 	return 0;
494a3667aaeSNaresh Kumar Inna 
495a3667aaeSNaresh Kumar Inna err_free_rn_pool:
496a3667aaeSNaresh Kumar Inna 	mempool_destroy(hw->rnode_mempool);
497a3667aaeSNaresh Kumar Inna 	hw->rnode_mempool = NULL;
498a3667aaeSNaresh Kumar Inna err_free_mb_mempool:
499a3667aaeSNaresh Kumar Inna 	mempool_destroy(hw->mb_mempool);
500a3667aaeSNaresh Kumar Inna 	hw->mb_mempool = NULL;
501a3667aaeSNaresh Kumar Inna err:
502a3667aaeSNaresh Kumar Inna 	return rv;
503a3667aaeSNaresh Kumar Inna }
504a3667aaeSNaresh Kumar Inna 
505a3667aaeSNaresh Kumar Inna static void
506a3667aaeSNaresh Kumar Inna csio_resource_free(struct csio_hw *hw)
507a3667aaeSNaresh Kumar Inna {
508a3667aaeSNaresh Kumar Inna 	pci_pool_destroy(hw->scsi_pci_pool);
509a3667aaeSNaresh Kumar Inna 	hw->scsi_pci_pool = NULL;
510a3667aaeSNaresh Kumar Inna 	mempool_destroy(hw->rnode_mempool);
511a3667aaeSNaresh Kumar Inna 	hw->rnode_mempool = NULL;
512a3667aaeSNaresh Kumar Inna 	mempool_destroy(hw->mb_mempool);
513a3667aaeSNaresh Kumar Inna 	hw->mb_mempool = NULL;
514a3667aaeSNaresh Kumar Inna }
515a3667aaeSNaresh Kumar Inna 
516a3667aaeSNaresh Kumar Inna /*
517a3667aaeSNaresh Kumar Inna  * csio_hw_alloc - Allocate and initialize the HW module.
518a3667aaeSNaresh Kumar Inna  * @pdev: PCI device.
519a3667aaeSNaresh Kumar Inna  *
520a3667aaeSNaresh Kumar Inna  * Allocates HW structure, DMA, memory resources, maps BARS to
521a3667aaeSNaresh Kumar Inna  * host memory and initializes HW module.
522a3667aaeSNaresh Kumar Inna  */
5236f039790SGreg Kroah-Hartman static struct csio_hw *csio_hw_alloc(struct pci_dev *pdev)
524a3667aaeSNaresh Kumar Inna {
525a3667aaeSNaresh Kumar Inna 	struct csio_hw *hw;
526a3667aaeSNaresh Kumar Inna 
527a3667aaeSNaresh Kumar Inna 	hw = kzalloc(sizeof(struct csio_hw), GFP_KERNEL);
528a3667aaeSNaresh Kumar Inna 	if (!hw)
529a3667aaeSNaresh Kumar Inna 		goto err;
530a3667aaeSNaresh Kumar Inna 
531a3667aaeSNaresh Kumar Inna 	hw->pdev = pdev;
532a3667aaeSNaresh Kumar Inna 	strncpy(hw->drv_version, CSIO_DRV_VERSION, 32);
533a3667aaeSNaresh Kumar Inna 
534a3667aaeSNaresh Kumar Inna 	/* memory pool/DMA pool allocation */
535a3667aaeSNaresh Kumar Inna 	if (csio_resource_alloc(hw))
536a3667aaeSNaresh Kumar Inna 		goto err_free_hw;
537a3667aaeSNaresh Kumar Inna 
538a3667aaeSNaresh Kumar Inna 	/* Get the start address of registers from BAR 0 */
539a3667aaeSNaresh Kumar Inna 	hw->regstart = ioremap_nocache(pci_resource_start(pdev, 0),
540a3667aaeSNaresh Kumar Inna 				       pci_resource_len(pdev, 0));
541a3667aaeSNaresh Kumar Inna 	if (!hw->regstart) {
542a3667aaeSNaresh Kumar Inna 		csio_err(hw, "Could not map BAR 0, regstart = %p\n",
543a3667aaeSNaresh Kumar Inna 			 hw->regstart);
544a3667aaeSNaresh Kumar Inna 		goto err_resource_free;
545a3667aaeSNaresh Kumar Inna 	}
546a3667aaeSNaresh Kumar Inna 
547a3667aaeSNaresh Kumar Inna 	csio_hw_init_workers(hw);
548a3667aaeSNaresh Kumar Inna 
549a3667aaeSNaresh Kumar Inna 	if (csio_hw_init(hw))
550a3667aaeSNaresh Kumar Inna 		goto err_unmap_bar;
551a3667aaeSNaresh Kumar Inna 
552a3667aaeSNaresh Kumar Inna 	csio_dfs_create(hw);
553a3667aaeSNaresh Kumar Inna 
554a3667aaeSNaresh Kumar Inna 	csio_dbg(hw, "hw:%p\n", hw);
555a3667aaeSNaresh Kumar Inna 
556a3667aaeSNaresh Kumar Inna 	return hw;
557a3667aaeSNaresh Kumar Inna 
558a3667aaeSNaresh Kumar Inna err_unmap_bar:
559a3667aaeSNaresh Kumar Inna 	csio_hw_exit_workers(hw);
560a3667aaeSNaresh Kumar Inna 	iounmap(hw->regstart);
561a3667aaeSNaresh Kumar Inna err_resource_free:
562a3667aaeSNaresh Kumar Inna 	csio_resource_free(hw);
563a3667aaeSNaresh Kumar Inna err_free_hw:
564a3667aaeSNaresh Kumar Inna 	kfree(hw);
565a3667aaeSNaresh Kumar Inna err:
566a3667aaeSNaresh Kumar Inna 	return NULL;
567a3667aaeSNaresh Kumar Inna }
568a3667aaeSNaresh Kumar Inna 
569a3667aaeSNaresh Kumar Inna /*
570a3667aaeSNaresh Kumar Inna  * csio_hw_free - Uninitialize and free the HW module.
571a3667aaeSNaresh Kumar Inna  * @hw: The HW module
572a3667aaeSNaresh Kumar Inna  *
573a3667aaeSNaresh Kumar Inna  * Disable interrupts, uninit the HW module, free resources, free hw.
574a3667aaeSNaresh Kumar Inna  */
575a3667aaeSNaresh Kumar Inna static void
576a3667aaeSNaresh Kumar Inna csio_hw_free(struct csio_hw *hw)
577a3667aaeSNaresh Kumar Inna {
578a3667aaeSNaresh Kumar Inna 	csio_intr_disable(hw, true);
579a3667aaeSNaresh Kumar Inna 	csio_hw_exit_workers(hw);
580a3667aaeSNaresh Kumar Inna 	csio_hw_exit(hw);
581a3667aaeSNaresh Kumar Inna 	iounmap(hw->regstart);
582a3667aaeSNaresh Kumar Inna 	csio_dfs_destroy(hw);
583a3667aaeSNaresh Kumar Inna 	csio_resource_free(hw);
584a3667aaeSNaresh Kumar Inna 	kfree(hw);
585a3667aaeSNaresh Kumar Inna }
586a3667aaeSNaresh Kumar Inna 
587a3667aaeSNaresh Kumar Inna /**
588a3667aaeSNaresh Kumar Inna  * csio_shost_init - Create and initialize the lnode module.
589a3667aaeSNaresh Kumar Inna  * @hw:		The HW module.
590a3667aaeSNaresh Kumar Inna  * @dev:	The device associated with this invocation.
591a3667aaeSNaresh Kumar Inna  * @probe:	Called from probe context or not?
592a3667aaeSNaresh Kumar Inna  * @os_pln:	Parent lnode if any.
593a3667aaeSNaresh Kumar Inna  *
594a3667aaeSNaresh Kumar Inna  * Allocates lnode structure via scsi_host_alloc, initializes
595a3667aaeSNaresh Kumar Inna  * shost, initializes lnode module and registers with SCSI ML
596a3667aaeSNaresh Kumar Inna  * via scsi_host_add. This function is shared between physical and
597a3667aaeSNaresh Kumar Inna  * virtual node ports.
598a3667aaeSNaresh Kumar Inna  */
599a3667aaeSNaresh Kumar Inna struct csio_lnode *
600a3667aaeSNaresh Kumar Inna csio_shost_init(struct csio_hw *hw, struct device *dev,
601a3667aaeSNaresh Kumar Inna 		  bool probe, struct csio_lnode *pln)
602a3667aaeSNaresh Kumar Inna {
603a3667aaeSNaresh Kumar Inna 	struct Scsi_Host  *shost = NULL;
604a3667aaeSNaresh Kumar Inna 	struct csio_lnode *ln;
605a3667aaeSNaresh Kumar Inna 
606a3667aaeSNaresh Kumar Inna 	csio_fcoe_shost_template.cmd_per_lun = csio_lun_qdepth;
607a3667aaeSNaresh Kumar Inna 	csio_fcoe_shost_vport_template.cmd_per_lun = csio_lun_qdepth;
608a3667aaeSNaresh Kumar Inna 
609a3667aaeSNaresh Kumar Inna 	/*
610a3667aaeSNaresh Kumar Inna 	 * hw->pdev is the physical port's PCI dev structure,
611a3667aaeSNaresh Kumar Inna 	 * which will be different from the NPIV dev structure.
612a3667aaeSNaresh Kumar Inna 	 */
613a3667aaeSNaresh Kumar Inna 	if (dev == &hw->pdev->dev)
614a3667aaeSNaresh Kumar Inna 		shost = scsi_host_alloc(
615a3667aaeSNaresh Kumar Inna 				&csio_fcoe_shost_template,
616a3667aaeSNaresh Kumar Inna 				sizeof(struct csio_lnode));
617a3667aaeSNaresh Kumar Inna 	else
618a3667aaeSNaresh Kumar Inna 		shost = scsi_host_alloc(
619a3667aaeSNaresh Kumar Inna 				&csio_fcoe_shost_vport_template,
620a3667aaeSNaresh Kumar Inna 				sizeof(struct csio_lnode));
621a3667aaeSNaresh Kumar Inna 
622a3667aaeSNaresh Kumar Inna 	if (!shost)
623a3667aaeSNaresh Kumar Inna 		goto err;
624a3667aaeSNaresh Kumar Inna 
625a3667aaeSNaresh Kumar Inna 	ln = shost_priv(shost);
626a3667aaeSNaresh Kumar Inna 	memset(ln, 0, sizeof(struct csio_lnode));
627a3667aaeSNaresh Kumar Inna 
628a3667aaeSNaresh Kumar Inna 	/* Link common lnode to this lnode */
629a3667aaeSNaresh Kumar Inna 	ln->dev_num = (shost->host_no << 16);
630a3667aaeSNaresh Kumar Inna 
631a3667aaeSNaresh Kumar Inna 	shost->can_queue = CSIO_MAX_QUEUE;
632a3667aaeSNaresh Kumar Inna 	shost->this_id = -1;
633a3667aaeSNaresh Kumar Inna 	shost->unique_id = shost->host_no;
634a3667aaeSNaresh Kumar Inna 	shost->max_cmd_len = 16; /* Max CDB length supported */
635a3667aaeSNaresh Kumar Inna 	shost->max_id = min_t(uint32_t, csio_fcoe_rnodes,
636a3667aaeSNaresh Kumar Inna 			      hw->fres_info.max_ssns);
637a3667aaeSNaresh Kumar Inna 	shost->max_lun = CSIO_MAX_LUN;
638a3667aaeSNaresh Kumar Inna 	if (dev == &hw->pdev->dev)
639a3667aaeSNaresh Kumar Inna 		shost->transportt = csio_fcoe_transport;
640a3667aaeSNaresh Kumar Inna 	else
641a3667aaeSNaresh Kumar Inna 		shost->transportt = csio_fcoe_transport_vport;
642a3667aaeSNaresh Kumar Inna 
643a3667aaeSNaresh Kumar Inna 	/* root lnode */
644a3667aaeSNaresh Kumar Inna 	if (!hw->rln)
645a3667aaeSNaresh Kumar Inna 		hw->rln = ln;
646a3667aaeSNaresh Kumar Inna 
647a3667aaeSNaresh Kumar Inna 	/* Other initialization here: Common, Transport specific */
648a3667aaeSNaresh Kumar Inna 	if (csio_lnode_init(ln, hw, pln))
649a3667aaeSNaresh Kumar Inna 		goto err_shost_put;
650a3667aaeSNaresh Kumar Inna 
651a3667aaeSNaresh Kumar Inna 	if (scsi_add_host(shost, dev))
652a3667aaeSNaresh Kumar Inna 		goto err_lnode_exit;
653a3667aaeSNaresh Kumar Inna 
654a3667aaeSNaresh Kumar Inna 	return ln;
655a3667aaeSNaresh Kumar Inna 
656a3667aaeSNaresh Kumar Inna err_lnode_exit:
657a3667aaeSNaresh Kumar Inna 	csio_lnode_exit(ln);
658a3667aaeSNaresh Kumar Inna err_shost_put:
659a3667aaeSNaresh Kumar Inna 	scsi_host_put(shost);
660a3667aaeSNaresh Kumar Inna err:
661a3667aaeSNaresh Kumar Inna 	return NULL;
662a3667aaeSNaresh Kumar Inna }
663a3667aaeSNaresh Kumar Inna 
664a3667aaeSNaresh Kumar Inna /**
665a3667aaeSNaresh Kumar Inna  * csio_shost_exit - De-instantiate the shost.
666a3667aaeSNaresh Kumar Inna  * @ln:		The lnode module corresponding to the shost.
667a3667aaeSNaresh Kumar Inna  *
668a3667aaeSNaresh Kumar Inna  */
669a3667aaeSNaresh Kumar Inna void
670a3667aaeSNaresh Kumar Inna csio_shost_exit(struct csio_lnode *ln)
671a3667aaeSNaresh Kumar Inna {
672a3667aaeSNaresh Kumar Inna 	struct Scsi_Host *shost = csio_ln_to_shost(ln);
673a3667aaeSNaresh Kumar Inna 	struct csio_hw *hw = csio_lnode_to_hw(ln);
674a3667aaeSNaresh Kumar Inna 
675a3667aaeSNaresh Kumar Inna 	/* Inform transport */
676a3667aaeSNaresh Kumar Inna 	fc_remove_host(shost);
677a3667aaeSNaresh Kumar Inna 
678a3667aaeSNaresh Kumar Inna 	/* Inform SCSI ML */
679a3667aaeSNaresh Kumar Inna 	scsi_remove_host(shost);
680a3667aaeSNaresh Kumar Inna 
681a3667aaeSNaresh Kumar Inna 	/* Flush all the events, so that any rnode removal events
682a3667aaeSNaresh Kumar Inna 	 * already queued are all handled, before we remove the lnode.
683a3667aaeSNaresh Kumar Inna 	 */
684a3667aaeSNaresh Kumar Inna 	spin_lock_irq(&hw->lock);
685a3667aaeSNaresh Kumar Inna 	csio_evtq_flush(hw);
686a3667aaeSNaresh Kumar Inna 	spin_unlock_irq(&hw->lock);
687a3667aaeSNaresh Kumar Inna 
688a3667aaeSNaresh Kumar Inna 	csio_lnode_exit(ln);
689a3667aaeSNaresh Kumar Inna 	scsi_host_put(shost);
690a3667aaeSNaresh Kumar Inna }
691a3667aaeSNaresh Kumar Inna 
692a3667aaeSNaresh Kumar Inna struct csio_lnode *
693a3667aaeSNaresh Kumar Inna csio_lnode_alloc(struct csio_hw *hw)
694a3667aaeSNaresh Kumar Inna {
695a3667aaeSNaresh Kumar Inna 	return csio_shost_init(hw, &hw->pdev->dev, false, NULL);
696a3667aaeSNaresh Kumar Inna }
697a3667aaeSNaresh Kumar Inna 
698a3667aaeSNaresh Kumar Inna void
699a3667aaeSNaresh Kumar Inna csio_lnodes_block_request(struct csio_hw *hw)
700a3667aaeSNaresh Kumar Inna {
701a3667aaeSNaresh Kumar Inna 	struct Scsi_Host  *shost;
702a3667aaeSNaresh Kumar Inna 	struct csio_lnode *sln;
703a3667aaeSNaresh Kumar Inna 	struct csio_lnode *ln;
704a3667aaeSNaresh Kumar Inna 	struct list_head *cur_ln, *cur_cln;
705a3667aaeSNaresh Kumar Inna 	struct csio_lnode **lnode_list;
706a3667aaeSNaresh Kumar Inna 	int cur_cnt = 0, ii;
707a3667aaeSNaresh Kumar Inna 
708a3667aaeSNaresh Kumar Inna 	lnode_list = kzalloc((sizeof(struct csio_lnode *) * hw->num_lns),
709a3667aaeSNaresh Kumar Inna 			GFP_KERNEL);
710a3667aaeSNaresh Kumar Inna 	if (!lnode_list) {
711a3667aaeSNaresh Kumar Inna 		csio_err(hw, "Failed to allocate lnodes_list");
712a3667aaeSNaresh Kumar Inna 		return;
713a3667aaeSNaresh Kumar Inna 	}
714a3667aaeSNaresh Kumar Inna 
715a3667aaeSNaresh Kumar Inna 	spin_lock_irq(&hw->lock);
716a3667aaeSNaresh Kumar Inna 	/* Traverse sibling lnodes */
717a3667aaeSNaresh Kumar Inna 	list_for_each(cur_ln, &hw->sln_head) {
718a3667aaeSNaresh Kumar Inna 		sln = (struct csio_lnode *) cur_ln;
719a3667aaeSNaresh Kumar Inna 		lnode_list[cur_cnt++] = sln;
720a3667aaeSNaresh Kumar Inna 
721a3667aaeSNaresh Kumar Inna 		/* Traverse children lnodes */
722a3667aaeSNaresh Kumar Inna 		list_for_each(cur_cln, &sln->cln_head)
723a3667aaeSNaresh Kumar Inna 			lnode_list[cur_cnt++] = (struct csio_lnode *) cur_cln;
724a3667aaeSNaresh Kumar Inna 	}
725a3667aaeSNaresh Kumar Inna 	spin_unlock_irq(&hw->lock);
726a3667aaeSNaresh Kumar Inna 
727a3667aaeSNaresh Kumar Inna 	for (ii = 0; ii < cur_cnt; ii++) {
728a3667aaeSNaresh Kumar Inna 		csio_dbg(hw, "Blocking IOs on lnode: %p\n", lnode_list[ii]);
729a3667aaeSNaresh Kumar Inna 		ln = lnode_list[ii];
730a3667aaeSNaresh Kumar Inna 		shost = csio_ln_to_shost(ln);
731a3667aaeSNaresh Kumar Inna 		scsi_block_requests(shost);
732a3667aaeSNaresh Kumar Inna 
733a3667aaeSNaresh Kumar Inna 	}
734a3667aaeSNaresh Kumar Inna 	kfree(lnode_list);
735a3667aaeSNaresh Kumar Inna }
736a3667aaeSNaresh Kumar Inna 
737a3667aaeSNaresh Kumar Inna void
738a3667aaeSNaresh Kumar Inna csio_lnodes_unblock_request(struct csio_hw *hw)
739a3667aaeSNaresh Kumar Inna {
740a3667aaeSNaresh Kumar Inna 	struct csio_lnode *ln;
741a3667aaeSNaresh Kumar Inna 	struct Scsi_Host  *shost;
742a3667aaeSNaresh Kumar Inna 	struct csio_lnode *sln;
743a3667aaeSNaresh Kumar Inna 	struct list_head *cur_ln, *cur_cln;
744a3667aaeSNaresh Kumar Inna 	struct csio_lnode **lnode_list;
745a3667aaeSNaresh Kumar Inna 	int cur_cnt = 0, ii;
746a3667aaeSNaresh Kumar Inna 
747a3667aaeSNaresh Kumar Inna 	lnode_list = kzalloc((sizeof(struct csio_lnode *) * hw->num_lns),
748a3667aaeSNaresh Kumar Inna 			GFP_KERNEL);
749a3667aaeSNaresh Kumar Inna 	if (!lnode_list) {
750a3667aaeSNaresh Kumar Inna 		csio_err(hw, "Failed to allocate lnodes_list");
751a3667aaeSNaresh Kumar Inna 		return;
752a3667aaeSNaresh Kumar Inna 	}
753a3667aaeSNaresh Kumar Inna 
754a3667aaeSNaresh Kumar Inna 	spin_lock_irq(&hw->lock);
755a3667aaeSNaresh Kumar Inna 	/* Traverse sibling lnodes */
756a3667aaeSNaresh Kumar Inna 	list_for_each(cur_ln, &hw->sln_head) {
757a3667aaeSNaresh Kumar Inna 		sln = (struct csio_lnode *) cur_ln;
758a3667aaeSNaresh Kumar Inna 		lnode_list[cur_cnt++] = sln;
759a3667aaeSNaresh Kumar Inna 
760a3667aaeSNaresh Kumar Inna 		/* Traverse children lnodes */
761a3667aaeSNaresh Kumar Inna 		list_for_each(cur_cln, &sln->cln_head)
762a3667aaeSNaresh Kumar Inna 			lnode_list[cur_cnt++] = (struct csio_lnode *) cur_cln;
763a3667aaeSNaresh Kumar Inna 	}
764a3667aaeSNaresh Kumar Inna 	spin_unlock_irq(&hw->lock);
765a3667aaeSNaresh Kumar Inna 
766a3667aaeSNaresh Kumar Inna 	for (ii = 0; ii < cur_cnt; ii++) {
767a3667aaeSNaresh Kumar Inna 		csio_dbg(hw, "unblocking IOs on lnode: %p\n", lnode_list[ii]);
768a3667aaeSNaresh Kumar Inna 		ln = lnode_list[ii];
769a3667aaeSNaresh Kumar Inna 		shost = csio_ln_to_shost(ln);
770a3667aaeSNaresh Kumar Inna 		scsi_unblock_requests(shost);
771a3667aaeSNaresh Kumar Inna 	}
772a3667aaeSNaresh Kumar Inna 	kfree(lnode_list);
773a3667aaeSNaresh Kumar Inna }
774a3667aaeSNaresh Kumar Inna 
775a3667aaeSNaresh Kumar Inna void
776a3667aaeSNaresh Kumar Inna csio_lnodes_block_by_port(struct csio_hw *hw, uint8_t portid)
777a3667aaeSNaresh Kumar Inna {
778a3667aaeSNaresh Kumar Inna 	struct csio_lnode *ln;
779a3667aaeSNaresh Kumar Inna 	struct Scsi_Host  *shost;
780a3667aaeSNaresh Kumar Inna 	struct csio_lnode *sln;
781a3667aaeSNaresh Kumar Inna 	struct list_head *cur_ln, *cur_cln;
782a3667aaeSNaresh Kumar Inna 	struct csio_lnode **lnode_list;
783a3667aaeSNaresh Kumar Inna 	int cur_cnt = 0, ii;
784a3667aaeSNaresh Kumar Inna 
785a3667aaeSNaresh Kumar Inna 	lnode_list = kzalloc((sizeof(struct csio_lnode *) * hw->num_lns),
786a3667aaeSNaresh Kumar Inna 			GFP_KERNEL);
787a3667aaeSNaresh Kumar Inna 	if (!lnode_list) {
788a3667aaeSNaresh Kumar Inna 		csio_err(hw, "Failed to allocate lnodes_list");
789a3667aaeSNaresh Kumar Inna 		return;
790a3667aaeSNaresh Kumar Inna 	}
791a3667aaeSNaresh Kumar Inna 
792a3667aaeSNaresh Kumar Inna 	spin_lock_irq(&hw->lock);
793a3667aaeSNaresh Kumar Inna 	/* Traverse sibling lnodes */
794a3667aaeSNaresh Kumar Inna 	list_for_each(cur_ln, &hw->sln_head) {
795a3667aaeSNaresh Kumar Inna 		sln = (struct csio_lnode *) cur_ln;
796a3667aaeSNaresh Kumar Inna 		if (sln->portid != portid)
797a3667aaeSNaresh Kumar Inna 			continue;
798a3667aaeSNaresh Kumar Inna 
799a3667aaeSNaresh Kumar Inna 		lnode_list[cur_cnt++] = sln;
800a3667aaeSNaresh Kumar Inna 
801a3667aaeSNaresh Kumar Inna 		/* Traverse children lnodes */
802a3667aaeSNaresh Kumar Inna 		list_for_each(cur_cln, &sln->cln_head)
803a3667aaeSNaresh Kumar Inna 			lnode_list[cur_cnt++] = (struct csio_lnode *) cur_cln;
804a3667aaeSNaresh Kumar Inna 	}
805a3667aaeSNaresh Kumar Inna 	spin_unlock_irq(&hw->lock);
806a3667aaeSNaresh Kumar Inna 
807a3667aaeSNaresh Kumar Inna 	for (ii = 0; ii < cur_cnt; ii++) {
808a3667aaeSNaresh Kumar Inna 		csio_dbg(hw, "Blocking IOs on lnode: %p\n", lnode_list[ii]);
809a3667aaeSNaresh Kumar Inna 		ln = lnode_list[ii];
810a3667aaeSNaresh Kumar Inna 		shost = csio_ln_to_shost(ln);
811a3667aaeSNaresh Kumar Inna 		scsi_block_requests(shost);
812a3667aaeSNaresh Kumar Inna 	}
813a3667aaeSNaresh Kumar Inna 	kfree(lnode_list);
814a3667aaeSNaresh Kumar Inna }
815a3667aaeSNaresh Kumar Inna 
816a3667aaeSNaresh Kumar Inna void
817a3667aaeSNaresh Kumar Inna csio_lnodes_unblock_by_port(struct csio_hw *hw, uint8_t portid)
818a3667aaeSNaresh Kumar Inna {
819a3667aaeSNaresh Kumar Inna 	struct csio_lnode *ln;
820a3667aaeSNaresh Kumar Inna 	struct Scsi_Host  *shost;
821a3667aaeSNaresh Kumar Inna 	struct csio_lnode *sln;
822a3667aaeSNaresh Kumar Inna 	struct list_head *cur_ln, *cur_cln;
823a3667aaeSNaresh Kumar Inna 	struct csio_lnode **lnode_list;
824a3667aaeSNaresh Kumar Inna 	int cur_cnt = 0, ii;
825a3667aaeSNaresh Kumar Inna 
826a3667aaeSNaresh Kumar Inna 	lnode_list = kzalloc((sizeof(struct csio_lnode *) * hw->num_lns),
827a3667aaeSNaresh Kumar Inna 			GFP_KERNEL);
828a3667aaeSNaresh Kumar Inna 	if (!lnode_list) {
829a3667aaeSNaresh Kumar Inna 		csio_err(hw, "Failed to allocate lnodes_list");
830a3667aaeSNaresh Kumar Inna 		return;
831a3667aaeSNaresh Kumar Inna 	}
832a3667aaeSNaresh Kumar Inna 
833a3667aaeSNaresh Kumar Inna 	spin_lock_irq(&hw->lock);
834a3667aaeSNaresh Kumar Inna 	/* Traverse sibling lnodes */
835a3667aaeSNaresh Kumar Inna 	list_for_each(cur_ln, &hw->sln_head) {
836a3667aaeSNaresh Kumar Inna 		sln = (struct csio_lnode *) cur_ln;
837a3667aaeSNaresh Kumar Inna 		if (sln->portid != portid)
838a3667aaeSNaresh Kumar Inna 			continue;
839a3667aaeSNaresh Kumar Inna 		lnode_list[cur_cnt++] = sln;
840a3667aaeSNaresh Kumar Inna 
841a3667aaeSNaresh Kumar Inna 		/* Traverse children lnodes */
842a3667aaeSNaresh Kumar Inna 		list_for_each(cur_cln, &sln->cln_head)
843a3667aaeSNaresh Kumar Inna 			lnode_list[cur_cnt++] = (struct csio_lnode *) cur_cln;
844a3667aaeSNaresh Kumar Inna 	}
845a3667aaeSNaresh Kumar Inna 	spin_unlock_irq(&hw->lock);
846a3667aaeSNaresh Kumar Inna 
847a3667aaeSNaresh Kumar Inna 	for (ii = 0; ii < cur_cnt; ii++) {
848a3667aaeSNaresh Kumar Inna 		csio_dbg(hw, "unblocking IOs on lnode: %p\n", lnode_list[ii]);
849a3667aaeSNaresh Kumar Inna 		ln = lnode_list[ii];
850a3667aaeSNaresh Kumar Inna 		shost = csio_ln_to_shost(ln);
851a3667aaeSNaresh Kumar Inna 		scsi_unblock_requests(shost);
852a3667aaeSNaresh Kumar Inna 	}
853a3667aaeSNaresh Kumar Inna 	kfree(lnode_list);
854a3667aaeSNaresh Kumar Inna }
855a3667aaeSNaresh Kumar Inna 
856a3667aaeSNaresh Kumar Inna void
857a3667aaeSNaresh Kumar Inna csio_lnodes_exit(struct csio_hw *hw, bool npiv)
858a3667aaeSNaresh Kumar Inna {
859a3667aaeSNaresh Kumar Inna 	struct csio_lnode *sln;
860a3667aaeSNaresh Kumar Inna 	struct csio_lnode *ln;
861a3667aaeSNaresh Kumar Inna 	struct list_head *cur_ln, *cur_cln;
862a3667aaeSNaresh Kumar Inna 	struct csio_lnode **lnode_list;
863a3667aaeSNaresh Kumar Inna 	int cur_cnt = 0, ii;
864a3667aaeSNaresh Kumar Inna 
865a3667aaeSNaresh Kumar Inna 	lnode_list = kzalloc((sizeof(struct csio_lnode *) * hw->num_lns),
866a3667aaeSNaresh Kumar Inna 			GFP_KERNEL);
867a3667aaeSNaresh Kumar Inna 	if (!lnode_list) {
868a3667aaeSNaresh Kumar Inna 		csio_err(hw, "lnodes_exit: Failed to allocate lnodes_list.\n");
869a3667aaeSNaresh Kumar Inna 		return;
870a3667aaeSNaresh Kumar Inna 	}
871a3667aaeSNaresh Kumar Inna 
872a3667aaeSNaresh Kumar Inna 	/* Get all child lnodes(NPIV ports) */
873a3667aaeSNaresh Kumar Inna 	spin_lock_irq(&hw->lock);
874a3667aaeSNaresh Kumar Inna 	list_for_each(cur_ln, &hw->sln_head) {
875a3667aaeSNaresh Kumar Inna 		sln = (struct csio_lnode *) cur_ln;
876a3667aaeSNaresh Kumar Inna 
877a3667aaeSNaresh Kumar Inna 		/* Traverse children lnodes */
878a3667aaeSNaresh Kumar Inna 		list_for_each(cur_cln, &sln->cln_head)
879a3667aaeSNaresh Kumar Inna 			lnode_list[cur_cnt++] = (struct csio_lnode *) cur_cln;
880a3667aaeSNaresh Kumar Inna 	}
881a3667aaeSNaresh Kumar Inna 	spin_unlock_irq(&hw->lock);
882a3667aaeSNaresh Kumar Inna 
883a3667aaeSNaresh Kumar Inna 	/* Delete NPIV lnodes */
884a3667aaeSNaresh Kumar Inna 	for (ii = 0; ii < cur_cnt; ii++) {
885a3667aaeSNaresh Kumar Inna 		csio_dbg(hw, "Deleting child lnode: %p\n", lnode_list[ii]);
886a3667aaeSNaresh Kumar Inna 		ln = lnode_list[ii];
887a3667aaeSNaresh Kumar Inna 		fc_vport_terminate(ln->fc_vport);
888a3667aaeSNaresh Kumar Inna 	}
889a3667aaeSNaresh Kumar Inna 
890a3667aaeSNaresh Kumar Inna 	/* Delete only npiv lnodes */
891a3667aaeSNaresh Kumar Inna 	if (npiv)
892a3667aaeSNaresh Kumar Inna 		goto free_lnodes;
893a3667aaeSNaresh Kumar Inna 
894a3667aaeSNaresh Kumar Inna 	cur_cnt = 0;
895a3667aaeSNaresh Kumar Inna 	/* Get all physical lnodes */
896a3667aaeSNaresh Kumar Inna 	spin_lock_irq(&hw->lock);
897a3667aaeSNaresh Kumar Inna 	/* Traverse sibling lnodes */
898a3667aaeSNaresh Kumar Inna 	list_for_each(cur_ln, &hw->sln_head) {
899a3667aaeSNaresh Kumar Inna 		sln = (struct csio_lnode *) cur_ln;
900a3667aaeSNaresh Kumar Inna 		lnode_list[cur_cnt++] = sln;
901a3667aaeSNaresh Kumar Inna 	}
902a3667aaeSNaresh Kumar Inna 	spin_unlock_irq(&hw->lock);
903a3667aaeSNaresh Kumar Inna 
904a3667aaeSNaresh Kumar Inna 	/* Delete physical lnodes */
905a3667aaeSNaresh Kumar Inna 	for (ii = 0; ii < cur_cnt; ii++) {
906a3667aaeSNaresh Kumar Inna 		csio_dbg(hw, "Deleting parent lnode: %p\n", lnode_list[ii]);
907a3667aaeSNaresh Kumar Inna 		csio_shost_exit(lnode_list[ii]);
908a3667aaeSNaresh Kumar Inna 	}
909a3667aaeSNaresh Kumar Inna 
910a3667aaeSNaresh Kumar Inna free_lnodes:
911a3667aaeSNaresh Kumar Inna 	kfree(lnode_list);
912a3667aaeSNaresh Kumar Inna }
913a3667aaeSNaresh Kumar Inna 
914a3667aaeSNaresh Kumar Inna /*
915a3667aaeSNaresh Kumar Inna  * csio_lnode_init_post: Set lnode attributes after starting HW.
916a3667aaeSNaresh Kumar Inna  * @ln: lnode.
917a3667aaeSNaresh Kumar Inna  *
918a3667aaeSNaresh Kumar Inna  */
919a3667aaeSNaresh Kumar Inna static void
920a3667aaeSNaresh Kumar Inna csio_lnode_init_post(struct csio_lnode *ln)
921a3667aaeSNaresh Kumar Inna {
922a3667aaeSNaresh Kumar Inna 	struct Scsi_Host  *shost = csio_ln_to_shost(ln);
923a3667aaeSNaresh Kumar Inna 
924a3667aaeSNaresh Kumar Inna 	csio_fchost_attr_init(ln);
925a3667aaeSNaresh Kumar Inna 
926a3667aaeSNaresh Kumar Inna 	scsi_scan_host(shost);
927a3667aaeSNaresh Kumar Inna }
928a3667aaeSNaresh Kumar Inna 
929a3667aaeSNaresh Kumar Inna /*
930a3667aaeSNaresh Kumar Inna  * csio_probe_one - Instantiate this function.
931a3667aaeSNaresh Kumar Inna  * @pdev: PCI device
932a3667aaeSNaresh Kumar Inna  * @id: Device ID
933a3667aaeSNaresh Kumar Inna  *
934a3667aaeSNaresh Kumar Inna  * This is the .probe() callback of the driver. This function:
935a3667aaeSNaresh Kumar Inna  * - Initializes the PCI function by enabling MMIO, setting bus
936a3667aaeSNaresh Kumar Inna  *   mastership and setting DMA mask.
937a3667aaeSNaresh Kumar Inna  * - Allocates HW structure, DMA, memory resources, maps BARS to
938a3667aaeSNaresh Kumar Inna  *   host memory and initializes HW module.
939a3667aaeSNaresh Kumar Inna  * - Allocates lnode structure via scsi_host_alloc, initializes
940a3667aaeSNaresh Kumar Inna  *   shost, initialized lnode module and registers with SCSI ML
941a3667aaeSNaresh Kumar Inna  *   via scsi_host_add.
942a3667aaeSNaresh Kumar Inna  * - Enables interrupts, and starts the chip by kicking off the
943a3667aaeSNaresh Kumar Inna  *   HW state machine.
944a3667aaeSNaresh Kumar Inna  * - Once hardware is ready, initiated scan of the host via
945a3667aaeSNaresh Kumar Inna  *   scsi_scan_host.
946a3667aaeSNaresh Kumar Inna  */
9476f039790SGreg Kroah-Hartman static int csio_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
948a3667aaeSNaresh Kumar Inna {
949a3667aaeSNaresh Kumar Inna 	int rv;
950a3667aaeSNaresh Kumar Inna 	int bars;
951a3667aaeSNaresh Kumar Inna 	int i;
952a3667aaeSNaresh Kumar Inna 	struct csio_hw *hw;
953a3667aaeSNaresh Kumar Inna 	struct csio_lnode *ln;
954a3667aaeSNaresh Kumar Inna 
955*4bbd458eSVarun Prakash 	/* probe only T5 and T6 cards */
956*4bbd458eSVarun Prakash 	if (!csio_is_t5((pdev->device & CSIO_HW_CHIP_MASK)) &&
957*4bbd458eSVarun Prakash 	    !csio_is_t6((pdev->device & CSIO_HW_CHIP_MASK)))
9583fedeab1SHariprasad Shenai 		return -ENODEV;
9593fedeab1SHariprasad Shenai 
960a3667aaeSNaresh Kumar Inna 	rv = csio_pci_init(pdev, &bars);
961a3667aaeSNaresh Kumar Inna 	if (rv)
962a3667aaeSNaresh Kumar Inna 		goto err;
963a3667aaeSNaresh Kumar Inna 
964a3667aaeSNaresh Kumar Inna 	hw = csio_hw_alloc(pdev);
965a3667aaeSNaresh Kumar Inna 	if (!hw) {
966a3667aaeSNaresh Kumar Inna 		rv = -ENODEV;
967a3667aaeSNaresh Kumar Inna 		goto err_pci_exit;
968a3667aaeSNaresh Kumar Inna 	}
969a3667aaeSNaresh Kumar Inna 
970a3667aaeSNaresh Kumar Inna 	pci_set_drvdata(pdev, hw);
971a3667aaeSNaresh Kumar Inna 
972a3667aaeSNaresh Kumar Inna 	if (csio_hw_start(hw) != 0) {
973a3667aaeSNaresh Kumar Inna 		dev_err(&pdev->dev,
974a3667aaeSNaresh Kumar Inna 			"Failed to start FW, continuing in debug mode.\n");
975a3667aaeSNaresh Kumar Inna 		return 0;
976a3667aaeSNaresh Kumar Inna 	}
977a3667aaeSNaresh Kumar Inna 
978a3667aaeSNaresh Kumar Inna 	sprintf(hw->fwrev_str, "%u.%u.%u.%u\n",
979b2e1a3f0SHariprasad Shenai 		    FW_HDR_FW_VER_MAJOR_G(hw->fwrev),
980b2e1a3f0SHariprasad Shenai 		    FW_HDR_FW_VER_MINOR_G(hw->fwrev),
981b2e1a3f0SHariprasad Shenai 		    FW_HDR_FW_VER_MICRO_G(hw->fwrev),
982b2e1a3f0SHariprasad Shenai 		    FW_HDR_FW_VER_BUILD_G(hw->fwrev));
983a3667aaeSNaresh Kumar Inna 
984a3667aaeSNaresh Kumar Inna 	for (i = 0; i < hw->num_pports; i++) {
985a3667aaeSNaresh Kumar Inna 		ln = csio_shost_init(hw, &pdev->dev, true, NULL);
986a3667aaeSNaresh Kumar Inna 		if (!ln) {
987a3667aaeSNaresh Kumar Inna 			rv = -ENODEV;
988a3667aaeSNaresh Kumar Inna 			break;
989a3667aaeSNaresh Kumar Inna 		}
990a3667aaeSNaresh Kumar Inna 		/* Initialize portid */
991a3667aaeSNaresh Kumar Inna 		ln->portid = hw->pport[i].portid;
992a3667aaeSNaresh Kumar Inna 
993a3667aaeSNaresh Kumar Inna 		spin_lock_irq(&hw->lock);
994a3667aaeSNaresh Kumar Inna 		if (csio_lnode_start(ln) != 0)
995a3667aaeSNaresh Kumar Inna 			rv = -ENODEV;
996a3667aaeSNaresh Kumar Inna 		spin_unlock_irq(&hw->lock);
997a3667aaeSNaresh Kumar Inna 
998a3667aaeSNaresh Kumar Inna 		if (rv)
999a3667aaeSNaresh Kumar Inna 			break;
1000a3667aaeSNaresh Kumar Inna 
1001a3667aaeSNaresh Kumar Inna 		csio_lnode_init_post(ln);
1002a3667aaeSNaresh Kumar Inna 	}
1003a3667aaeSNaresh Kumar Inna 
1004a3667aaeSNaresh Kumar Inna 	if (rv)
1005a3667aaeSNaresh Kumar Inna 		goto err_lnode_exit;
1006a3667aaeSNaresh Kumar Inna 
1007a3667aaeSNaresh Kumar Inna 	return 0;
1008a3667aaeSNaresh Kumar Inna 
1009a3667aaeSNaresh Kumar Inna err_lnode_exit:
1010a3667aaeSNaresh Kumar Inna 	csio_lnodes_block_request(hw);
1011a3667aaeSNaresh Kumar Inna 	spin_lock_irq(&hw->lock);
1012a3667aaeSNaresh Kumar Inna 	csio_hw_stop(hw);
1013a3667aaeSNaresh Kumar Inna 	spin_unlock_irq(&hw->lock);
1014a3667aaeSNaresh Kumar Inna 	csio_lnodes_unblock_request(hw);
1015a3667aaeSNaresh Kumar Inna 	csio_lnodes_exit(hw, 0);
1016a3667aaeSNaresh Kumar Inna 	csio_hw_free(hw);
1017a3667aaeSNaresh Kumar Inna err_pci_exit:
1018a3667aaeSNaresh Kumar Inna 	csio_pci_exit(pdev, &bars);
1019a3667aaeSNaresh Kumar Inna err:
1020a3667aaeSNaresh Kumar Inna 	dev_err(&pdev->dev, "probe of device failed: %d\n", rv);
1021a3667aaeSNaresh Kumar Inna 	return rv;
1022a3667aaeSNaresh Kumar Inna }
1023a3667aaeSNaresh Kumar Inna 
1024a3667aaeSNaresh Kumar Inna /*
1025a3667aaeSNaresh Kumar Inna  * csio_remove_one - Remove one instance of the driver at this PCI function.
1026a3667aaeSNaresh Kumar Inna  * @pdev: PCI device
1027a3667aaeSNaresh Kumar Inna  *
1028a3667aaeSNaresh Kumar Inna  * Used during hotplug operation.
1029a3667aaeSNaresh Kumar Inna  */
10306f039790SGreg Kroah-Hartman static void csio_remove_one(struct pci_dev *pdev)
1031a3667aaeSNaresh Kumar Inna {
1032a3667aaeSNaresh Kumar Inna 	struct csio_hw *hw = pci_get_drvdata(pdev);
1033a3667aaeSNaresh Kumar Inna 	int bars = pci_select_bars(pdev, IORESOURCE_MEM);
1034a3667aaeSNaresh Kumar Inna 
1035a3667aaeSNaresh Kumar Inna 	csio_lnodes_block_request(hw);
1036a3667aaeSNaresh Kumar Inna 	spin_lock_irq(&hw->lock);
1037a3667aaeSNaresh Kumar Inna 
1038a3667aaeSNaresh Kumar Inna 	/* Stops lnode, Rnode s/m
1039a3667aaeSNaresh Kumar Inna 	 * Quiesce IOs.
1040a3667aaeSNaresh Kumar Inna 	 * All sessions with remote ports are unregistered.
1041a3667aaeSNaresh Kumar Inna 	 */
1042a3667aaeSNaresh Kumar Inna 	csio_hw_stop(hw);
1043a3667aaeSNaresh Kumar Inna 	spin_unlock_irq(&hw->lock);
1044a3667aaeSNaresh Kumar Inna 	csio_lnodes_unblock_request(hw);
1045a3667aaeSNaresh Kumar Inna 
1046a3667aaeSNaresh Kumar Inna 	csio_lnodes_exit(hw, 0);
1047a3667aaeSNaresh Kumar Inna 	csio_hw_free(hw);
1048a3667aaeSNaresh Kumar Inna 	csio_pci_exit(pdev, &bars);
1049a3667aaeSNaresh Kumar Inna }
1050a3667aaeSNaresh Kumar Inna 
1051a3667aaeSNaresh Kumar Inna /*
1052a3667aaeSNaresh Kumar Inna  * csio_pci_error_detected - PCI error was detected
1053a3667aaeSNaresh Kumar Inna  * @pdev: PCI device
1054a3667aaeSNaresh Kumar Inna  *
1055a3667aaeSNaresh Kumar Inna  */
1056a3667aaeSNaresh Kumar Inna static pci_ers_result_t
1057a3667aaeSNaresh Kumar Inna csio_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
1058a3667aaeSNaresh Kumar Inna {
1059a3667aaeSNaresh Kumar Inna 	struct csio_hw *hw = pci_get_drvdata(pdev);
1060a3667aaeSNaresh Kumar Inna 
1061a3667aaeSNaresh Kumar Inna 	csio_lnodes_block_request(hw);
1062a3667aaeSNaresh Kumar Inna 	spin_lock_irq(&hw->lock);
1063a3667aaeSNaresh Kumar Inna 
1064a3667aaeSNaresh Kumar Inna 	/* Post PCI error detected evt to HW s/m
1065a3667aaeSNaresh Kumar Inna 	 * HW s/m handles this evt by quiescing IOs, unregisters rports
1066a3667aaeSNaresh Kumar Inna 	 * and finally takes the device to offline.
1067a3667aaeSNaresh Kumar Inna 	 */
1068a3667aaeSNaresh Kumar Inna 	csio_post_event(&hw->sm, CSIO_HWE_PCIERR_DETECTED);
1069a3667aaeSNaresh Kumar Inna 	spin_unlock_irq(&hw->lock);
1070a3667aaeSNaresh Kumar Inna 	csio_lnodes_unblock_request(hw);
1071a3667aaeSNaresh Kumar Inna 	csio_lnodes_exit(hw, 0);
1072a3667aaeSNaresh Kumar Inna 	csio_intr_disable(hw, true);
1073a3667aaeSNaresh Kumar Inna 	pci_disable_device(pdev);
1074a3667aaeSNaresh Kumar Inna 	return state == pci_channel_io_perm_failure ?
1075a3667aaeSNaresh Kumar Inna 		PCI_ERS_RESULT_DISCONNECT : PCI_ERS_RESULT_NEED_RESET;
1076a3667aaeSNaresh Kumar Inna }
1077a3667aaeSNaresh Kumar Inna 
1078a3667aaeSNaresh Kumar Inna /*
1079a3667aaeSNaresh Kumar Inna  * csio_pci_slot_reset - PCI slot has been reset.
1080a3667aaeSNaresh Kumar Inna  * @pdev: PCI device
1081a3667aaeSNaresh Kumar Inna  *
1082a3667aaeSNaresh Kumar Inna  */
1083a3667aaeSNaresh Kumar Inna static pci_ers_result_t
1084a3667aaeSNaresh Kumar Inna csio_pci_slot_reset(struct pci_dev *pdev)
1085a3667aaeSNaresh Kumar Inna {
1086a3667aaeSNaresh Kumar Inna 	struct csio_hw *hw = pci_get_drvdata(pdev);
1087a3667aaeSNaresh Kumar Inna 	int ready;
1088a3667aaeSNaresh Kumar Inna 
1089a3667aaeSNaresh Kumar Inna 	if (pci_enable_device(pdev)) {
1090a3667aaeSNaresh Kumar Inna 		dev_err(&pdev->dev, "cannot re-enable device in slot reset\n");
1091a3667aaeSNaresh Kumar Inna 		return PCI_ERS_RESULT_DISCONNECT;
1092a3667aaeSNaresh Kumar Inna 	}
1093a3667aaeSNaresh Kumar Inna 
1094a3667aaeSNaresh Kumar Inna 	pci_set_master(pdev);
1095a3667aaeSNaresh Kumar Inna 	pci_restore_state(pdev);
1096a3667aaeSNaresh Kumar Inna 	pci_save_state(pdev);
1097a3667aaeSNaresh Kumar Inna 	pci_cleanup_aer_uncorrect_error_status(pdev);
1098a3667aaeSNaresh Kumar Inna 
1099a3667aaeSNaresh Kumar Inna 	/* Bring HW s/m to ready state.
1100a3667aaeSNaresh Kumar Inna 	 * but don't resume IOs.
1101a3667aaeSNaresh Kumar Inna 	 */
1102a3667aaeSNaresh Kumar Inna 	spin_lock_irq(&hw->lock);
1103a3667aaeSNaresh Kumar Inna 	csio_post_event(&hw->sm, CSIO_HWE_PCIERR_SLOT_RESET);
1104a3667aaeSNaresh Kumar Inna 	ready = csio_is_hw_ready(hw);
1105a3667aaeSNaresh Kumar Inna 	spin_unlock_irq(&hw->lock);
1106a3667aaeSNaresh Kumar Inna 
1107a3667aaeSNaresh Kumar Inna 	if (ready) {
1108a3667aaeSNaresh Kumar Inna 		return PCI_ERS_RESULT_RECOVERED;
1109a3667aaeSNaresh Kumar Inna 	} else {
1110a3667aaeSNaresh Kumar Inna 		dev_err(&pdev->dev, "Can't initialize HW when in slot reset\n");
1111a3667aaeSNaresh Kumar Inna 		return PCI_ERS_RESULT_DISCONNECT;
1112a3667aaeSNaresh Kumar Inna 	}
1113a3667aaeSNaresh Kumar Inna }
1114a3667aaeSNaresh Kumar Inna 
1115a3667aaeSNaresh Kumar Inna /*
1116a3667aaeSNaresh Kumar Inna  * csio_pci_resume - Resume normal operations
1117a3667aaeSNaresh Kumar Inna  * @pdev: PCI device
1118a3667aaeSNaresh Kumar Inna  *
1119a3667aaeSNaresh Kumar Inna  */
1120a3667aaeSNaresh Kumar Inna static void
1121a3667aaeSNaresh Kumar Inna csio_pci_resume(struct pci_dev *pdev)
1122a3667aaeSNaresh Kumar Inna {
1123a3667aaeSNaresh Kumar Inna 	struct csio_hw *hw = pci_get_drvdata(pdev);
1124a3667aaeSNaresh Kumar Inna 	struct csio_lnode *ln;
1125a3667aaeSNaresh Kumar Inna 	int rv = 0;
1126a3667aaeSNaresh Kumar Inna 	int i;
1127a3667aaeSNaresh Kumar Inna 
1128a3667aaeSNaresh Kumar Inna 	/* Bring the LINK UP and Resume IO */
1129a3667aaeSNaresh Kumar Inna 
1130a3667aaeSNaresh Kumar Inna 	for (i = 0; i < hw->num_pports; i++) {
1131a3667aaeSNaresh Kumar Inna 		ln = csio_shost_init(hw, &pdev->dev, true, NULL);
1132a3667aaeSNaresh Kumar Inna 		if (!ln) {
1133a3667aaeSNaresh Kumar Inna 			rv = -ENODEV;
1134a3667aaeSNaresh Kumar Inna 			break;
1135a3667aaeSNaresh Kumar Inna 		}
1136a3667aaeSNaresh Kumar Inna 		/* Initialize portid */
1137a3667aaeSNaresh Kumar Inna 		ln->portid = hw->pport[i].portid;
1138a3667aaeSNaresh Kumar Inna 
1139a3667aaeSNaresh Kumar Inna 		spin_lock_irq(&hw->lock);
1140a3667aaeSNaresh Kumar Inna 		if (csio_lnode_start(ln) != 0)
1141a3667aaeSNaresh Kumar Inna 			rv = -ENODEV;
1142a3667aaeSNaresh Kumar Inna 		spin_unlock_irq(&hw->lock);
1143a3667aaeSNaresh Kumar Inna 
1144a3667aaeSNaresh Kumar Inna 		if (rv)
1145a3667aaeSNaresh Kumar Inna 			break;
1146a3667aaeSNaresh Kumar Inna 
1147a3667aaeSNaresh Kumar Inna 		csio_lnode_init_post(ln);
1148a3667aaeSNaresh Kumar Inna 	}
1149a3667aaeSNaresh Kumar Inna 
1150a3667aaeSNaresh Kumar Inna 	if (rv)
1151a3667aaeSNaresh Kumar Inna 		goto err_resume_exit;
1152a3667aaeSNaresh Kumar Inna 
1153a3667aaeSNaresh Kumar Inna 	return;
1154a3667aaeSNaresh Kumar Inna 
1155a3667aaeSNaresh Kumar Inna err_resume_exit:
1156a3667aaeSNaresh Kumar Inna 	csio_lnodes_block_request(hw);
1157a3667aaeSNaresh Kumar Inna 	spin_lock_irq(&hw->lock);
1158a3667aaeSNaresh Kumar Inna 	csio_hw_stop(hw);
1159a3667aaeSNaresh Kumar Inna 	spin_unlock_irq(&hw->lock);
1160a3667aaeSNaresh Kumar Inna 	csio_lnodes_unblock_request(hw);
1161a3667aaeSNaresh Kumar Inna 	csio_lnodes_exit(hw, 0);
1162a3667aaeSNaresh Kumar Inna 	csio_hw_free(hw);
1163a3667aaeSNaresh Kumar Inna 	dev_err(&pdev->dev, "resume of device failed: %d\n", rv);
1164a3667aaeSNaresh Kumar Inna }
1165a3667aaeSNaresh Kumar Inna 
1166a3667aaeSNaresh Kumar Inna static struct pci_error_handlers csio_err_handler = {
1167a3667aaeSNaresh Kumar Inna 	.error_detected = csio_pci_error_detected,
1168a3667aaeSNaresh Kumar Inna 	.slot_reset	= csio_pci_slot_reset,
1169a3667aaeSNaresh Kumar Inna 	.resume		= csio_pci_resume,
1170a3667aaeSNaresh Kumar Inna };
1171a3667aaeSNaresh Kumar Inna 
11723fedeab1SHariprasad Shenai /*
11733fedeab1SHariprasad Shenai  *  Macros needed to support the PCI Device ID Table ...
11743fedeab1SHariprasad Shenai  */
11753fedeab1SHariprasad Shenai #define CH_PCI_DEVICE_ID_TABLE_DEFINE_BEGIN \
1176768ffc66SHariprasad Shenai 	static const struct pci_device_id csio_pci_tbl[] = {
11773fb4c22eSPraveen Madhavan /* Define for FCoE uses PF6 */
11783fb4c22eSPraveen Madhavan #define CH_PCI_DEVICE_ID_FUNCTION	0x6
1179a3667aaeSNaresh Kumar Inna 
11803fedeab1SHariprasad Shenai #define CH_PCI_ID_TABLE_ENTRY(devid) \
11813fedeab1SHariprasad Shenai 		{ PCI_VDEVICE(CHELSIO, (devid)), 0 }
11823fedeab1SHariprasad Shenai 
11833fedeab1SHariprasad Shenai #define CH_PCI_DEVICE_ID_TABLE_DEFINE_END { 0, } }
11843fedeab1SHariprasad Shenai 
11853fedeab1SHariprasad Shenai #include "t4_pci_id_tbl.h"
1186a3667aaeSNaresh Kumar Inna 
1187a3667aaeSNaresh Kumar Inna static struct pci_driver csio_pci_driver = {
1188a3667aaeSNaresh Kumar Inna 	.name		= KBUILD_MODNAME,
1189a3667aaeSNaresh Kumar Inna 	.driver		= {
1190a3667aaeSNaresh Kumar Inna 		.owner	= THIS_MODULE,
1191a3667aaeSNaresh Kumar Inna 	},
1192a3667aaeSNaresh Kumar Inna 	.id_table	= csio_pci_tbl,
1193a3667aaeSNaresh Kumar Inna 	.probe		= csio_probe_one,
1194a3667aaeSNaresh Kumar Inna 	.remove		= csio_remove_one,
1195a3667aaeSNaresh Kumar Inna 	.err_handler	= &csio_err_handler,
1196a3667aaeSNaresh Kumar Inna };
1197a3667aaeSNaresh Kumar Inna 
1198a3667aaeSNaresh Kumar Inna /*
1199a3667aaeSNaresh Kumar Inna  * csio_init - Chelsio storage driver initialization function.
1200a3667aaeSNaresh Kumar Inna  *
1201a3667aaeSNaresh Kumar Inna  */
1202a3667aaeSNaresh Kumar Inna static int __init
1203a3667aaeSNaresh Kumar Inna csio_init(void)
1204a3667aaeSNaresh Kumar Inna {
1205a3667aaeSNaresh Kumar Inna 	int rv = -ENOMEM;
1206a3667aaeSNaresh Kumar Inna 
1207a3667aaeSNaresh Kumar Inna 	pr_info("%s %s\n", CSIO_DRV_DESC, CSIO_DRV_VERSION);
1208a3667aaeSNaresh Kumar Inna 
1209a3667aaeSNaresh Kumar Inna 	csio_dfs_init();
1210a3667aaeSNaresh Kumar Inna 
1211a3667aaeSNaresh Kumar Inna 	csio_fcoe_transport = fc_attach_transport(&csio_fc_transport_funcs);
1212a3667aaeSNaresh Kumar Inna 	if (!csio_fcoe_transport)
1213a3667aaeSNaresh Kumar Inna 		goto err;
1214a3667aaeSNaresh Kumar Inna 
1215a3667aaeSNaresh Kumar Inna 	csio_fcoe_transport_vport =
1216a3667aaeSNaresh Kumar Inna 			fc_attach_transport(&csio_fc_transport_vport_funcs);
1217a3667aaeSNaresh Kumar Inna 	if (!csio_fcoe_transport_vport)
1218a3667aaeSNaresh Kumar Inna 		goto err_vport;
1219a3667aaeSNaresh Kumar Inna 
1220a3667aaeSNaresh Kumar Inna 	rv = pci_register_driver(&csio_pci_driver);
1221a3667aaeSNaresh Kumar Inna 	if (rv)
1222a3667aaeSNaresh Kumar Inna 		goto err_pci;
1223a3667aaeSNaresh Kumar Inna 
1224a3667aaeSNaresh Kumar Inna 	return 0;
1225a3667aaeSNaresh Kumar Inna 
1226a3667aaeSNaresh Kumar Inna err_pci:
1227a3667aaeSNaresh Kumar Inna 	fc_release_transport(csio_fcoe_transport_vport);
1228a3667aaeSNaresh Kumar Inna err_vport:
1229a3667aaeSNaresh Kumar Inna 	fc_release_transport(csio_fcoe_transport);
1230a3667aaeSNaresh Kumar Inna err:
1231a3667aaeSNaresh Kumar Inna 	csio_dfs_exit();
1232a3667aaeSNaresh Kumar Inna 	return rv;
1233a3667aaeSNaresh Kumar Inna }
1234a3667aaeSNaresh Kumar Inna 
1235a3667aaeSNaresh Kumar Inna /*
1236a3667aaeSNaresh Kumar Inna  * csio_exit - Chelsio storage driver uninitialization .
1237a3667aaeSNaresh Kumar Inna  *
1238a3667aaeSNaresh Kumar Inna  * Function that gets called in the unload path.
1239a3667aaeSNaresh Kumar Inna  */
1240a3667aaeSNaresh Kumar Inna static void __exit
1241a3667aaeSNaresh Kumar Inna csio_exit(void)
1242a3667aaeSNaresh Kumar Inna {
1243a3667aaeSNaresh Kumar Inna 	pci_unregister_driver(&csio_pci_driver);
1244a3667aaeSNaresh Kumar Inna 	csio_dfs_exit();
1245a3667aaeSNaresh Kumar Inna 	fc_release_transport(csio_fcoe_transport_vport);
1246a3667aaeSNaresh Kumar Inna 	fc_release_transport(csio_fcoe_transport);
1247a3667aaeSNaresh Kumar Inna }
1248a3667aaeSNaresh Kumar Inna 
1249a3667aaeSNaresh Kumar Inna module_init(csio_init);
1250a3667aaeSNaresh Kumar Inna module_exit(csio_exit);
1251a3667aaeSNaresh Kumar Inna MODULE_AUTHOR(CSIO_DRV_AUTHOR);
1252a3667aaeSNaresh Kumar Inna MODULE_DESCRIPTION(CSIO_DRV_DESC);
1253a3667aaeSNaresh Kumar Inna MODULE_LICENSE(CSIO_DRV_LICENSE);
1254a3667aaeSNaresh Kumar Inna MODULE_DEVICE_TABLE(pci, csio_pci_tbl);
1255a3667aaeSNaresh Kumar Inna MODULE_VERSION(CSIO_DRV_VERSION);
12567cc16380SArvind Bhushan MODULE_FIRMWARE(FW_FNAME_T5);
1257*4bbd458eSVarun Prakash MODULE_FIRMWARE(FW_FNAME_T6);
1258