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