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 488decab9a6SRomain Perier hw->scsi_dma_pool = dma_pool_create("csio_scsi_dma_pool", 489decab9a6SRomain Perier &hw->pdev->dev, CSIO_SCSI_RSP_LEN, 490decab9a6SRomain Perier 8, 0); 491decab9a6SRomain Perier if (!hw->scsi_dma_pool) 492a3667aaeSNaresh Kumar Inna goto err_free_rn_pool; 493a3667aaeSNaresh Kumar Inna 494a3667aaeSNaresh Kumar Inna return 0; 495a3667aaeSNaresh Kumar Inna 496a3667aaeSNaresh Kumar Inna err_free_rn_pool: 497a3667aaeSNaresh Kumar Inna mempool_destroy(hw->rnode_mempool); 498a3667aaeSNaresh Kumar Inna hw->rnode_mempool = NULL; 499a3667aaeSNaresh Kumar Inna err_free_mb_mempool: 500a3667aaeSNaresh Kumar Inna mempool_destroy(hw->mb_mempool); 501a3667aaeSNaresh Kumar Inna hw->mb_mempool = NULL; 502a3667aaeSNaresh Kumar Inna err: 503a3667aaeSNaresh Kumar Inna return rv; 504a3667aaeSNaresh Kumar Inna } 505a3667aaeSNaresh Kumar Inna 506a3667aaeSNaresh Kumar Inna static void 507a3667aaeSNaresh Kumar Inna csio_resource_free(struct csio_hw *hw) 508a3667aaeSNaresh Kumar Inna { 509decab9a6SRomain Perier dma_pool_destroy(hw->scsi_dma_pool); 510decab9a6SRomain Perier hw->scsi_dma_pool = NULL; 511a3667aaeSNaresh Kumar Inna mempool_destroy(hw->rnode_mempool); 512a3667aaeSNaresh Kumar Inna hw->rnode_mempool = NULL; 513a3667aaeSNaresh Kumar Inna mempool_destroy(hw->mb_mempool); 514a3667aaeSNaresh Kumar Inna hw->mb_mempool = NULL; 515a3667aaeSNaresh Kumar Inna } 516a3667aaeSNaresh Kumar Inna 517a3667aaeSNaresh Kumar Inna /* 518a3667aaeSNaresh Kumar Inna * csio_hw_alloc - Allocate and initialize the HW module. 519a3667aaeSNaresh Kumar Inna * @pdev: PCI device. 520a3667aaeSNaresh Kumar Inna * 521a3667aaeSNaresh Kumar Inna * Allocates HW structure, DMA, memory resources, maps BARS to 522a3667aaeSNaresh Kumar Inna * host memory and initializes HW module. 523a3667aaeSNaresh Kumar Inna */ 5246f039790SGreg Kroah-Hartman static struct csio_hw *csio_hw_alloc(struct pci_dev *pdev) 525a3667aaeSNaresh Kumar Inna { 526a3667aaeSNaresh Kumar Inna struct csio_hw *hw; 527a3667aaeSNaresh Kumar Inna 528a3667aaeSNaresh Kumar Inna hw = kzalloc(sizeof(struct csio_hw), GFP_KERNEL); 529a3667aaeSNaresh Kumar Inna if (!hw) 530a3667aaeSNaresh Kumar Inna goto err; 531a3667aaeSNaresh Kumar Inna 532a3667aaeSNaresh Kumar Inna hw->pdev = pdev; 533a3667aaeSNaresh Kumar Inna strncpy(hw->drv_version, CSIO_DRV_VERSION, 32); 534a3667aaeSNaresh Kumar Inna 535a3667aaeSNaresh Kumar Inna /* memory pool/DMA pool allocation */ 536a3667aaeSNaresh Kumar Inna if (csio_resource_alloc(hw)) 537a3667aaeSNaresh Kumar Inna goto err_free_hw; 538a3667aaeSNaresh Kumar Inna 539a3667aaeSNaresh Kumar Inna /* Get the start address of registers from BAR 0 */ 540a3667aaeSNaresh Kumar Inna hw->regstart = ioremap_nocache(pci_resource_start(pdev, 0), 541a3667aaeSNaresh Kumar Inna pci_resource_len(pdev, 0)); 542a3667aaeSNaresh Kumar Inna if (!hw->regstart) { 543a3667aaeSNaresh Kumar Inna csio_err(hw, "Could not map BAR 0, regstart = %p\n", 544a3667aaeSNaresh Kumar Inna hw->regstart); 545a3667aaeSNaresh Kumar Inna goto err_resource_free; 546a3667aaeSNaresh Kumar Inna } 547a3667aaeSNaresh Kumar Inna 548a3667aaeSNaresh Kumar Inna csio_hw_init_workers(hw); 549a3667aaeSNaresh Kumar Inna 550a3667aaeSNaresh Kumar Inna if (csio_hw_init(hw)) 551a3667aaeSNaresh Kumar Inna goto err_unmap_bar; 552a3667aaeSNaresh Kumar Inna 553a3667aaeSNaresh Kumar Inna csio_dfs_create(hw); 554a3667aaeSNaresh Kumar Inna 555a3667aaeSNaresh Kumar Inna csio_dbg(hw, "hw:%p\n", hw); 556a3667aaeSNaresh Kumar Inna 557a3667aaeSNaresh Kumar Inna return hw; 558a3667aaeSNaresh Kumar Inna 559a3667aaeSNaresh Kumar Inna err_unmap_bar: 560a3667aaeSNaresh Kumar Inna csio_hw_exit_workers(hw); 561a3667aaeSNaresh Kumar Inna iounmap(hw->regstart); 562a3667aaeSNaresh Kumar Inna err_resource_free: 563a3667aaeSNaresh Kumar Inna csio_resource_free(hw); 564a3667aaeSNaresh Kumar Inna err_free_hw: 565a3667aaeSNaresh Kumar Inna kfree(hw); 566a3667aaeSNaresh Kumar Inna err: 567a3667aaeSNaresh Kumar Inna return NULL; 568a3667aaeSNaresh Kumar Inna } 569a3667aaeSNaresh Kumar Inna 570a3667aaeSNaresh Kumar Inna /* 571a3667aaeSNaresh Kumar Inna * csio_hw_free - Uninitialize and free the HW module. 572a3667aaeSNaresh Kumar Inna * @hw: The HW module 573a3667aaeSNaresh Kumar Inna * 574a3667aaeSNaresh Kumar Inna * Disable interrupts, uninit the HW module, free resources, free hw. 575a3667aaeSNaresh Kumar Inna */ 576a3667aaeSNaresh Kumar Inna static void 577a3667aaeSNaresh Kumar Inna csio_hw_free(struct csio_hw *hw) 578a3667aaeSNaresh Kumar Inna { 579a3667aaeSNaresh Kumar Inna csio_intr_disable(hw, true); 580a3667aaeSNaresh Kumar Inna csio_hw_exit_workers(hw); 581a3667aaeSNaresh Kumar Inna csio_hw_exit(hw); 582a3667aaeSNaresh Kumar Inna iounmap(hw->regstart); 583a3667aaeSNaresh Kumar Inna csio_dfs_destroy(hw); 584a3667aaeSNaresh Kumar Inna csio_resource_free(hw); 585a3667aaeSNaresh Kumar Inna kfree(hw); 586a3667aaeSNaresh Kumar Inna } 587a3667aaeSNaresh Kumar Inna 588a3667aaeSNaresh Kumar Inna /** 589a3667aaeSNaresh Kumar Inna * csio_shost_init - Create and initialize the lnode module. 590a3667aaeSNaresh Kumar Inna * @hw: The HW module. 591a3667aaeSNaresh Kumar Inna * @dev: The device associated with this invocation. 592a3667aaeSNaresh Kumar Inna * @probe: Called from probe context or not? 593a3667aaeSNaresh Kumar Inna * @os_pln: Parent lnode if any. 594a3667aaeSNaresh Kumar Inna * 595a3667aaeSNaresh Kumar Inna * Allocates lnode structure via scsi_host_alloc, initializes 596a3667aaeSNaresh Kumar Inna * shost, initializes lnode module and registers with SCSI ML 597a3667aaeSNaresh Kumar Inna * via scsi_host_add. This function is shared between physical and 598a3667aaeSNaresh Kumar Inna * virtual node ports. 599a3667aaeSNaresh Kumar Inna */ 600a3667aaeSNaresh Kumar Inna struct csio_lnode * 601a3667aaeSNaresh Kumar Inna csio_shost_init(struct csio_hw *hw, struct device *dev, 602a3667aaeSNaresh Kumar Inna bool probe, struct csio_lnode *pln) 603a3667aaeSNaresh Kumar Inna { 604a3667aaeSNaresh Kumar Inna struct Scsi_Host *shost = NULL; 605a3667aaeSNaresh Kumar Inna struct csio_lnode *ln; 606a3667aaeSNaresh Kumar Inna 607a3667aaeSNaresh Kumar Inna csio_fcoe_shost_template.cmd_per_lun = csio_lun_qdepth; 608a3667aaeSNaresh Kumar Inna csio_fcoe_shost_vport_template.cmd_per_lun = csio_lun_qdepth; 609a3667aaeSNaresh Kumar Inna 610a3667aaeSNaresh Kumar Inna /* 611a3667aaeSNaresh Kumar Inna * hw->pdev is the physical port's PCI dev structure, 612a3667aaeSNaresh Kumar Inna * which will be different from the NPIV dev structure. 613a3667aaeSNaresh Kumar Inna */ 614a3667aaeSNaresh Kumar Inna if (dev == &hw->pdev->dev) 615a3667aaeSNaresh Kumar Inna shost = scsi_host_alloc( 616a3667aaeSNaresh Kumar Inna &csio_fcoe_shost_template, 617a3667aaeSNaresh Kumar Inna sizeof(struct csio_lnode)); 618a3667aaeSNaresh Kumar Inna else 619a3667aaeSNaresh Kumar Inna shost = scsi_host_alloc( 620a3667aaeSNaresh Kumar Inna &csio_fcoe_shost_vport_template, 621a3667aaeSNaresh Kumar Inna sizeof(struct csio_lnode)); 622a3667aaeSNaresh Kumar Inna 623a3667aaeSNaresh Kumar Inna if (!shost) 624a3667aaeSNaresh Kumar Inna goto err; 625a3667aaeSNaresh Kumar Inna 626a3667aaeSNaresh Kumar Inna ln = shost_priv(shost); 627a3667aaeSNaresh Kumar Inna memset(ln, 0, sizeof(struct csio_lnode)); 628a3667aaeSNaresh Kumar Inna 629a3667aaeSNaresh Kumar Inna /* Link common lnode to this lnode */ 630a3667aaeSNaresh Kumar Inna ln->dev_num = (shost->host_no << 16); 631a3667aaeSNaresh Kumar Inna 632a3667aaeSNaresh Kumar Inna shost->can_queue = CSIO_MAX_QUEUE; 633a3667aaeSNaresh Kumar Inna shost->this_id = -1; 634a3667aaeSNaresh Kumar Inna shost->unique_id = shost->host_no; 635a3667aaeSNaresh Kumar Inna shost->max_cmd_len = 16; /* Max CDB length supported */ 636a3667aaeSNaresh Kumar Inna shost->max_id = min_t(uint32_t, csio_fcoe_rnodes, 637a3667aaeSNaresh Kumar Inna hw->fres_info.max_ssns); 638a3667aaeSNaresh Kumar Inna shost->max_lun = CSIO_MAX_LUN; 639a3667aaeSNaresh Kumar Inna if (dev == &hw->pdev->dev) 640a3667aaeSNaresh Kumar Inna shost->transportt = csio_fcoe_transport; 641a3667aaeSNaresh Kumar Inna else 642a3667aaeSNaresh Kumar Inna shost->transportt = csio_fcoe_transport_vport; 643a3667aaeSNaresh Kumar Inna 644a3667aaeSNaresh Kumar Inna /* root lnode */ 645a3667aaeSNaresh Kumar Inna if (!hw->rln) 646a3667aaeSNaresh Kumar Inna hw->rln = ln; 647a3667aaeSNaresh Kumar Inna 648a3667aaeSNaresh Kumar Inna /* Other initialization here: Common, Transport specific */ 649a3667aaeSNaresh Kumar Inna if (csio_lnode_init(ln, hw, pln)) 650a3667aaeSNaresh Kumar Inna goto err_shost_put; 651a3667aaeSNaresh Kumar Inna 652a3667aaeSNaresh Kumar Inna if (scsi_add_host(shost, dev)) 653a3667aaeSNaresh Kumar Inna goto err_lnode_exit; 654a3667aaeSNaresh Kumar Inna 655a3667aaeSNaresh Kumar Inna return ln; 656a3667aaeSNaresh Kumar Inna 657a3667aaeSNaresh Kumar Inna err_lnode_exit: 658a3667aaeSNaresh Kumar Inna csio_lnode_exit(ln); 659a3667aaeSNaresh Kumar Inna err_shost_put: 660a3667aaeSNaresh Kumar Inna scsi_host_put(shost); 661a3667aaeSNaresh Kumar Inna err: 662a3667aaeSNaresh Kumar Inna return NULL; 663a3667aaeSNaresh Kumar Inna } 664a3667aaeSNaresh Kumar Inna 665a3667aaeSNaresh Kumar Inna /** 666a3667aaeSNaresh Kumar Inna * csio_shost_exit - De-instantiate the shost. 667a3667aaeSNaresh Kumar Inna * @ln: The lnode module corresponding to the shost. 668a3667aaeSNaresh Kumar Inna * 669a3667aaeSNaresh Kumar Inna */ 670a3667aaeSNaresh Kumar Inna void 671a3667aaeSNaresh Kumar Inna csio_shost_exit(struct csio_lnode *ln) 672a3667aaeSNaresh Kumar Inna { 673a3667aaeSNaresh Kumar Inna struct Scsi_Host *shost = csio_ln_to_shost(ln); 674a3667aaeSNaresh Kumar Inna struct csio_hw *hw = csio_lnode_to_hw(ln); 675a3667aaeSNaresh Kumar Inna 676a3667aaeSNaresh Kumar Inna /* Inform transport */ 677a3667aaeSNaresh Kumar Inna fc_remove_host(shost); 678a3667aaeSNaresh Kumar Inna 679a3667aaeSNaresh Kumar Inna /* Inform SCSI ML */ 680a3667aaeSNaresh Kumar Inna scsi_remove_host(shost); 681a3667aaeSNaresh Kumar Inna 682a3667aaeSNaresh Kumar Inna /* Flush all the events, so that any rnode removal events 683a3667aaeSNaresh Kumar Inna * already queued are all handled, before we remove the lnode. 684a3667aaeSNaresh Kumar Inna */ 685a3667aaeSNaresh Kumar Inna spin_lock_irq(&hw->lock); 686a3667aaeSNaresh Kumar Inna csio_evtq_flush(hw); 687a3667aaeSNaresh Kumar Inna spin_unlock_irq(&hw->lock); 688a3667aaeSNaresh Kumar Inna 689a3667aaeSNaresh Kumar Inna csio_lnode_exit(ln); 690a3667aaeSNaresh Kumar Inna scsi_host_put(shost); 691a3667aaeSNaresh Kumar Inna } 692a3667aaeSNaresh Kumar Inna 693a3667aaeSNaresh Kumar Inna struct csio_lnode * 694a3667aaeSNaresh Kumar Inna csio_lnode_alloc(struct csio_hw *hw) 695a3667aaeSNaresh Kumar Inna { 696a3667aaeSNaresh Kumar Inna return csio_shost_init(hw, &hw->pdev->dev, false, NULL); 697a3667aaeSNaresh Kumar Inna } 698a3667aaeSNaresh Kumar Inna 699a3667aaeSNaresh Kumar Inna void 700a3667aaeSNaresh Kumar Inna csio_lnodes_block_request(struct csio_hw *hw) 701a3667aaeSNaresh Kumar Inna { 702a3667aaeSNaresh Kumar Inna struct Scsi_Host *shost; 703a3667aaeSNaresh Kumar Inna struct csio_lnode *sln; 704a3667aaeSNaresh Kumar Inna struct csio_lnode *ln; 705a3667aaeSNaresh Kumar Inna struct list_head *cur_ln, *cur_cln; 706a3667aaeSNaresh Kumar Inna struct csio_lnode **lnode_list; 707a3667aaeSNaresh Kumar Inna int cur_cnt = 0, ii; 708a3667aaeSNaresh Kumar Inna 709a3667aaeSNaresh Kumar Inna lnode_list = kzalloc((sizeof(struct csio_lnode *) * hw->num_lns), 710a3667aaeSNaresh Kumar Inna GFP_KERNEL); 711a3667aaeSNaresh Kumar Inna if (!lnode_list) { 712a3667aaeSNaresh Kumar Inna csio_err(hw, "Failed to allocate lnodes_list"); 713a3667aaeSNaresh Kumar Inna return; 714a3667aaeSNaresh Kumar Inna } 715a3667aaeSNaresh Kumar Inna 716a3667aaeSNaresh Kumar Inna spin_lock_irq(&hw->lock); 717a3667aaeSNaresh Kumar Inna /* Traverse sibling lnodes */ 718a3667aaeSNaresh Kumar Inna list_for_each(cur_ln, &hw->sln_head) { 719a3667aaeSNaresh Kumar Inna sln = (struct csio_lnode *) cur_ln; 720a3667aaeSNaresh Kumar Inna lnode_list[cur_cnt++] = sln; 721a3667aaeSNaresh Kumar Inna 722a3667aaeSNaresh Kumar Inna /* Traverse children lnodes */ 723a3667aaeSNaresh Kumar Inna list_for_each(cur_cln, &sln->cln_head) 724a3667aaeSNaresh Kumar Inna lnode_list[cur_cnt++] = (struct csio_lnode *) cur_cln; 725a3667aaeSNaresh Kumar Inna } 726a3667aaeSNaresh Kumar Inna spin_unlock_irq(&hw->lock); 727a3667aaeSNaresh Kumar Inna 728a3667aaeSNaresh Kumar Inna for (ii = 0; ii < cur_cnt; ii++) { 729a3667aaeSNaresh Kumar Inna csio_dbg(hw, "Blocking IOs on lnode: %p\n", lnode_list[ii]); 730a3667aaeSNaresh Kumar Inna ln = lnode_list[ii]; 731a3667aaeSNaresh Kumar Inna shost = csio_ln_to_shost(ln); 732a3667aaeSNaresh Kumar Inna scsi_block_requests(shost); 733a3667aaeSNaresh Kumar Inna 734a3667aaeSNaresh Kumar Inna } 735a3667aaeSNaresh Kumar Inna kfree(lnode_list); 736a3667aaeSNaresh Kumar Inna } 737a3667aaeSNaresh Kumar Inna 738a3667aaeSNaresh Kumar Inna void 739a3667aaeSNaresh Kumar Inna csio_lnodes_unblock_request(struct csio_hw *hw) 740a3667aaeSNaresh Kumar Inna { 741a3667aaeSNaresh Kumar Inna struct csio_lnode *ln; 742a3667aaeSNaresh Kumar Inna struct Scsi_Host *shost; 743a3667aaeSNaresh Kumar Inna struct csio_lnode *sln; 744a3667aaeSNaresh Kumar Inna struct list_head *cur_ln, *cur_cln; 745a3667aaeSNaresh Kumar Inna struct csio_lnode **lnode_list; 746a3667aaeSNaresh Kumar Inna int cur_cnt = 0, ii; 747a3667aaeSNaresh Kumar Inna 748a3667aaeSNaresh Kumar Inna lnode_list = kzalloc((sizeof(struct csio_lnode *) * hw->num_lns), 749a3667aaeSNaresh Kumar Inna GFP_KERNEL); 750a3667aaeSNaresh Kumar Inna if (!lnode_list) { 751a3667aaeSNaresh Kumar Inna csio_err(hw, "Failed to allocate lnodes_list"); 752a3667aaeSNaresh Kumar Inna return; 753a3667aaeSNaresh Kumar Inna } 754a3667aaeSNaresh Kumar Inna 755a3667aaeSNaresh Kumar Inna spin_lock_irq(&hw->lock); 756a3667aaeSNaresh Kumar Inna /* Traverse sibling lnodes */ 757a3667aaeSNaresh Kumar Inna list_for_each(cur_ln, &hw->sln_head) { 758a3667aaeSNaresh Kumar Inna sln = (struct csio_lnode *) cur_ln; 759a3667aaeSNaresh Kumar Inna lnode_list[cur_cnt++] = sln; 760a3667aaeSNaresh Kumar Inna 761a3667aaeSNaresh Kumar Inna /* Traverse children lnodes */ 762a3667aaeSNaresh Kumar Inna list_for_each(cur_cln, &sln->cln_head) 763a3667aaeSNaresh Kumar Inna lnode_list[cur_cnt++] = (struct csio_lnode *) cur_cln; 764a3667aaeSNaresh Kumar Inna } 765a3667aaeSNaresh Kumar Inna spin_unlock_irq(&hw->lock); 766a3667aaeSNaresh Kumar Inna 767a3667aaeSNaresh Kumar Inna for (ii = 0; ii < cur_cnt; ii++) { 768a3667aaeSNaresh Kumar Inna csio_dbg(hw, "unblocking IOs on lnode: %p\n", lnode_list[ii]); 769a3667aaeSNaresh Kumar Inna ln = lnode_list[ii]; 770a3667aaeSNaresh Kumar Inna shost = csio_ln_to_shost(ln); 771a3667aaeSNaresh Kumar Inna scsi_unblock_requests(shost); 772a3667aaeSNaresh Kumar Inna } 773a3667aaeSNaresh Kumar Inna kfree(lnode_list); 774a3667aaeSNaresh Kumar Inna } 775a3667aaeSNaresh Kumar Inna 776a3667aaeSNaresh Kumar Inna void 777a3667aaeSNaresh Kumar Inna csio_lnodes_block_by_port(struct csio_hw *hw, uint8_t portid) 778a3667aaeSNaresh Kumar Inna { 779a3667aaeSNaresh Kumar Inna struct csio_lnode *ln; 780a3667aaeSNaresh Kumar Inna struct Scsi_Host *shost; 781a3667aaeSNaresh Kumar Inna struct csio_lnode *sln; 782a3667aaeSNaresh Kumar Inna struct list_head *cur_ln, *cur_cln; 783a3667aaeSNaresh Kumar Inna struct csio_lnode **lnode_list; 784a3667aaeSNaresh Kumar Inna int cur_cnt = 0, ii; 785a3667aaeSNaresh Kumar Inna 786a3667aaeSNaresh Kumar Inna lnode_list = kzalloc((sizeof(struct csio_lnode *) * hw->num_lns), 787a3667aaeSNaresh Kumar Inna GFP_KERNEL); 788a3667aaeSNaresh Kumar Inna if (!lnode_list) { 789a3667aaeSNaresh Kumar Inna csio_err(hw, "Failed to allocate lnodes_list"); 790a3667aaeSNaresh Kumar Inna return; 791a3667aaeSNaresh Kumar Inna } 792a3667aaeSNaresh Kumar Inna 793a3667aaeSNaresh Kumar Inna spin_lock_irq(&hw->lock); 794a3667aaeSNaresh Kumar Inna /* Traverse sibling lnodes */ 795a3667aaeSNaresh Kumar Inna list_for_each(cur_ln, &hw->sln_head) { 796a3667aaeSNaresh Kumar Inna sln = (struct csio_lnode *) cur_ln; 797a3667aaeSNaresh Kumar Inna if (sln->portid != portid) 798a3667aaeSNaresh Kumar Inna continue; 799a3667aaeSNaresh Kumar Inna 800a3667aaeSNaresh Kumar Inna lnode_list[cur_cnt++] = sln; 801a3667aaeSNaresh Kumar Inna 802a3667aaeSNaresh Kumar Inna /* Traverse children lnodes */ 803a3667aaeSNaresh Kumar Inna list_for_each(cur_cln, &sln->cln_head) 804a3667aaeSNaresh Kumar Inna lnode_list[cur_cnt++] = (struct csio_lnode *) cur_cln; 805a3667aaeSNaresh Kumar Inna } 806a3667aaeSNaresh Kumar Inna spin_unlock_irq(&hw->lock); 807a3667aaeSNaresh Kumar Inna 808a3667aaeSNaresh Kumar Inna for (ii = 0; ii < cur_cnt; ii++) { 809a3667aaeSNaresh Kumar Inna csio_dbg(hw, "Blocking IOs on lnode: %p\n", lnode_list[ii]); 810a3667aaeSNaresh Kumar Inna ln = lnode_list[ii]; 811a3667aaeSNaresh Kumar Inna shost = csio_ln_to_shost(ln); 812a3667aaeSNaresh Kumar Inna scsi_block_requests(shost); 813a3667aaeSNaresh Kumar Inna } 814a3667aaeSNaresh Kumar Inna kfree(lnode_list); 815a3667aaeSNaresh Kumar Inna } 816a3667aaeSNaresh Kumar Inna 817a3667aaeSNaresh Kumar Inna void 818a3667aaeSNaresh Kumar Inna csio_lnodes_unblock_by_port(struct csio_hw *hw, uint8_t portid) 819a3667aaeSNaresh Kumar Inna { 820a3667aaeSNaresh Kumar Inna struct csio_lnode *ln; 821a3667aaeSNaresh Kumar Inna struct Scsi_Host *shost; 822a3667aaeSNaresh Kumar Inna struct csio_lnode *sln; 823a3667aaeSNaresh Kumar Inna struct list_head *cur_ln, *cur_cln; 824a3667aaeSNaresh Kumar Inna struct csio_lnode **lnode_list; 825a3667aaeSNaresh Kumar Inna int cur_cnt = 0, ii; 826a3667aaeSNaresh Kumar Inna 827a3667aaeSNaresh Kumar Inna lnode_list = kzalloc((sizeof(struct csio_lnode *) * hw->num_lns), 828a3667aaeSNaresh Kumar Inna GFP_KERNEL); 829a3667aaeSNaresh Kumar Inna if (!lnode_list) { 830a3667aaeSNaresh Kumar Inna csio_err(hw, "Failed to allocate lnodes_list"); 831a3667aaeSNaresh Kumar Inna return; 832a3667aaeSNaresh Kumar Inna } 833a3667aaeSNaresh Kumar Inna 834a3667aaeSNaresh Kumar Inna spin_lock_irq(&hw->lock); 835a3667aaeSNaresh Kumar Inna /* Traverse sibling lnodes */ 836a3667aaeSNaresh Kumar Inna list_for_each(cur_ln, &hw->sln_head) { 837a3667aaeSNaresh Kumar Inna sln = (struct csio_lnode *) cur_ln; 838a3667aaeSNaresh Kumar Inna if (sln->portid != portid) 839a3667aaeSNaresh Kumar Inna continue; 840a3667aaeSNaresh Kumar Inna lnode_list[cur_cnt++] = sln; 841a3667aaeSNaresh Kumar Inna 842a3667aaeSNaresh Kumar Inna /* Traverse children lnodes */ 843a3667aaeSNaresh Kumar Inna list_for_each(cur_cln, &sln->cln_head) 844a3667aaeSNaresh Kumar Inna lnode_list[cur_cnt++] = (struct csio_lnode *) cur_cln; 845a3667aaeSNaresh Kumar Inna } 846a3667aaeSNaresh Kumar Inna spin_unlock_irq(&hw->lock); 847a3667aaeSNaresh Kumar Inna 848a3667aaeSNaresh Kumar Inna for (ii = 0; ii < cur_cnt; ii++) { 849a3667aaeSNaresh Kumar Inna csio_dbg(hw, "unblocking IOs on lnode: %p\n", lnode_list[ii]); 850a3667aaeSNaresh Kumar Inna ln = lnode_list[ii]; 851a3667aaeSNaresh Kumar Inna shost = csio_ln_to_shost(ln); 852a3667aaeSNaresh Kumar Inna scsi_unblock_requests(shost); 853a3667aaeSNaresh Kumar Inna } 854a3667aaeSNaresh Kumar Inna kfree(lnode_list); 855a3667aaeSNaresh Kumar Inna } 856a3667aaeSNaresh Kumar Inna 857a3667aaeSNaresh Kumar Inna void 858a3667aaeSNaresh Kumar Inna csio_lnodes_exit(struct csio_hw *hw, bool npiv) 859a3667aaeSNaresh Kumar Inna { 860a3667aaeSNaresh Kumar Inna struct csio_lnode *sln; 861a3667aaeSNaresh Kumar Inna struct csio_lnode *ln; 862a3667aaeSNaresh Kumar Inna struct list_head *cur_ln, *cur_cln; 863a3667aaeSNaresh Kumar Inna struct csio_lnode **lnode_list; 864a3667aaeSNaresh Kumar Inna int cur_cnt = 0, ii; 865a3667aaeSNaresh Kumar Inna 866a3667aaeSNaresh Kumar Inna lnode_list = kzalloc((sizeof(struct csio_lnode *) * hw->num_lns), 867a3667aaeSNaresh Kumar Inna GFP_KERNEL); 868a3667aaeSNaresh Kumar Inna if (!lnode_list) { 869a3667aaeSNaresh Kumar Inna csio_err(hw, "lnodes_exit: Failed to allocate lnodes_list.\n"); 870a3667aaeSNaresh Kumar Inna return; 871a3667aaeSNaresh Kumar Inna } 872a3667aaeSNaresh Kumar Inna 873a3667aaeSNaresh Kumar Inna /* Get all child lnodes(NPIV ports) */ 874a3667aaeSNaresh Kumar Inna spin_lock_irq(&hw->lock); 875a3667aaeSNaresh Kumar Inna list_for_each(cur_ln, &hw->sln_head) { 876a3667aaeSNaresh Kumar Inna sln = (struct csio_lnode *) cur_ln; 877a3667aaeSNaresh Kumar Inna 878a3667aaeSNaresh Kumar Inna /* Traverse children lnodes */ 879a3667aaeSNaresh Kumar Inna list_for_each(cur_cln, &sln->cln_head) 880a3667aaeSNaresh Kumar Inna lnode_list[cur_cnt++] = (struct csio_lnode *) cur_cln; 881a3667aaeSNaresh Kumar Inna } 882a3667aaeSNaresh Kumar Inna spin_unlock_irq(&hw->lock); 883a3667aaeSNaresh Kumar Inna 884a3667aaeSNaresh Kumar Inna /* Delete NPIV lnodes */ 885a3667aaeSNaresh Kumar Inna for (ii = 0; ii < cur_cnt; ii++) { 886a3667aaeSNaresh Kumar Inna csio_dbg(hw, "Deleting child lnode: %p\n", lnode_list[ii]); 887a3667aaeSNaresh Kumar Inna ln = lnode_list[ii]; 888a3667aaeSNaresh Kumar Inna fc_vport_terminate(ln->fc_vport); 889a3667aaeSNaresh Kumar Inna } 890a3667aaeSNaresh Kumar Inna 891a3667aaeSNaresh Kumar Inna /* Delete only npiv lnodes */ 892a3667aaeSNaresh Kumar Inna if (npiv) 893a3667aaeSNaresh Kumar Inna goto free_lnodes; 894a3667aaeSNaresh Kumar Inna 895a3667aaeSNaresh Kumar Inna cur_cnt = 0; 896a3667aaeSNaresh Kumar Inna /* Get all physical lnodes */ 897a3667aaeSNaresh Kumar Inna spin_lock_irq(&hw->lock); 898a3667aaeSNaresh Kumar Inna /* Traverse sibling lnodes */ 899a3667aaeSNaresh Kumar Inna list_for_each(cur_ln, &hw->sln_head) { 900a3667aaeSNaresh Kumar Inna sln = (struct csio_lnode *) cur_ln; 901a3667aaeSNaresh Kumar Inna lnode_list[cur_cnt++] = sln; 902a3667aaeSNaresh Kumar Inna } 903a3667aaeSNaresh Kumar Inna spin_unlock_irq(&hw->lock); 904a3667aaeSNaresh Kumar Inna 905a3667aaeSNaresh Kumar Inna /* Delete physical lnodes */ 906a3667aaeSNaresh Kumar Inna for (ii = 0; ii < cur_cnt; ii++) { 907a3667aaeSNaresh Kumar Inna csio_dbg(hw, "Deleting parent lnode: %p\n", lnode_list[ii]); 908a3667aaeSNaresh Kumar Inna csio_shost_exit(lnode_list[ii]); 909a3667aaeSNaresh Kumar Inna } 910a3667aaeSNaresh Kumar Inna 911a3667aaeSNaresh Kumar Inna free_lnodes: 912a3667aaeSNaresh Kumar Inna kfree(lnode_list); 913a3667aaeSNaresh Kumar Inna } 914a3667aaeSNaresh Kumar Inna 915a3667aaeSNaresh Kumar Inna /* 916a3667aaeSNaresh Kumar Inna * csio_lnode_init_post: Set lnode attributes after starting HW. 917a3667aaeSNaresh Kumar Inna * @ln: lnode. 918a3667aaeSNaresh Kumar Inna * 919a3667aaeSNaresh Kumar Inna */ 920a3667aaeSNaresh Kumar Inna static void 921a3667aaeSNaresh Kumar Inna csio_lnode_init_post(struct csio_lnode *ln) 922a3667aaeSNaresh Kumar Inna { 923a3667aaeSNaresh Kumar Inna struct Scsi_Host *shost = csio_ln_to_shost(ln); 924a3667aaeSNaresh Kumar Inna 925a3667aaeSNaresh Kumar Inna csio_fchost_attr_init(ln); 926a3667aaeSNaresh Kumar Inna 927a3667aaeSNaresh Kumar Inna scsi_scan_host(shost); 928a3667aaeSNaresh Kumar Inna } 929a3667aaeSNaresh Kumar Inna 930a3667aaeSNaresh Kumar Inna /* 931a3667aaeSNaresh Kumar Inna * csio_probe_one - Instantiate this function. 932a3667aaeSNaresh Kumar Inna * @pdev: PCI device 933a3667aaeSNaresh Kumar Inna * @id: Device ID 934a3667aaeSNaresh Kumar Inna * 935a3667aaeSNaresh Kumar Inna * This is the .probe() callback of the driver. This function: 936a3667aaeSNaresh Kumar Inna * - Initializes the PCI function by enabling MMIO, setting bus 937a3667aaeSNaresh Kumar Inna * mastership and setting DMA mask. 938a3667aaeSNaresh Kumar Inna * - Allocates HW structure, DMA, memory resources, maps BARS to 939a3667aaeSNaresh Kumar Inna * host memory and initializes HW module. 940a3667aaeSNaresh Kumar Inna * - Allocates lnode structure via scsi_host_alloc, initializes 941a3667aaeSNaresh Kumar Inna * shost, initialized lnode module and registers with SCSI ML 942a3667aaeSNaresh Kumar Inna * via scsi_host_add. 943a3667aaeSNaresh Kumar Inna * - Enables interrupts, and starts the chip by kicking off the 944a3667aaeSNaresh Kumar Inna * HW state machine. 945a3667aaeSNaresh Kumar Inna * - Once hardware is ready, initiated scan of the host via 946a3667aaeSNaresh Kumar Inna * scsi_scan_host. 947a3667aaeSNaresh Kumar Inna */ 9486f039790SGreg Kroah-Hartman static int csio_probe_one(struct pci_dev *pdev, const struct pci_device_id *id) 949a3667aaeSNaresh Kumar Inna { 950a3667aaeSNaresh Kumar Inna int rv; 951a3667aaeSNaresh Kumar Inna int bars; 952a3667aaeSNaresh Kumar Inna int i; 953a3667aaeSNaresh Kumar Inna struct csio_hw *hw; 954a3667aaeSNaresh Kumar Inna struct csio_lnode *ln; 955a3667aaeSNaresh Kumar Inna 9564bbd458eSVarun Prakash /* probe only T5 and T6 cards */ 9574bbd458eSVarun Prakash if (!csio_is_t5((pdev->device & CSIO_HW_CHIP_MASK)) && 9584bbd458eSVarun Prakash !csio_is_t6((pdev->device & CSIO_HW_CHIP_MASK))) 9593fedeab1SHariprasad Shenai return -ENODEV; 9603fedeab1SHariprasad Shenai 961a3667aaeSNaresh Kumar Inna rv = csio_pci_init(pdev, &bars); 962a3667aaeSNaresh Kumar Inna if (rv) 963a3667aaeSNaresh Kumar Inna goto err; 964a3667aaeSNaresh Kumar Inna 965a3667aaeSNaresh Kumar Inna hw = csio_hw_alloc(pdev); 966a3667aaeSNaresh Kumar Inna if (!hw) { 967a3667aaeSNaresh Kumar Inna rv = -ENODEV; 968a3667aaeSNaresh Kumar Inna goto err_pci_exit; 969a3667aaeSNaresh Kumar Inna } 970a3667aaeSNaresh Kumar Inna 971*ff6e88f1SVarun Prakash if (!pcie_relaxed_ordering_enabled(pdev)) 972*ff6e88f1SVarun Prakash hw->flags |= CSIO_HWF_ROOT_NO_RELAXED_ORDERING; 973*ff6e88f1SVarun Prakash 974a3667aaeSNaresh Kumar Inna pci_set_drvdata(pdev, hw); 975a3667aaeSNaresh Kumar Inna 97682f0fd06SVarun Prakash rv = csio_hw_start(hw); 97782f0fd06SVarun Prakash if (rv) { 97882f0fd06SVarun Prakash if (rv == -EINVAL) { 979a3667aaeSNaresh Kumar Inna dev_err(&pdev->dev, 980a3667aaeSNaresh Kumar Inna "Failed to start FW, continuing in debug mode.\n"); 981a3667aaeSNaresh Kumar Inna return 0; 982a3667aaeSNaresh Kumar Inna } 98382f0fd06SVarun Prakash goto err_lnode_exit; 98482f0fd06SVarun Prakash } 985a3667aaeSNaresh Kumar Inna 986a3667aaeSNaresh Kumar Inna sprintf(hw->fwrev_str, "%u.%u.%u.%u\n", 987b2e1a3f0SHariprasad Shenai FW_HDR_FW_VER_MAJOR_G(hw->fwrev), 988b2e1a3f0SHariprasad Shenai FW_HDR_FW_VER_MINOR_G(hw->fwrev), 989b2e1a3f0SHariprasad Shenai FW_HDR_FW_VER_MICRO_G(hw->fwrev), 990b2e1a3f0SHariprasad Shenai FW_HDR_FW_VER_BUILD_G(hw->fwrev)); 991a3667aaeSNaresh Kumar Inna 992a3667aaeSNaresh Kumar Inna for (i = 0; i < hw->num_pports; i++) { 993a3667aaeSNaresh Kumar Inna ln = csio_shost_init(hw, &pdev->dev, true, NULL); 994a3667aaeSNaresh Kumar Inna if (!ln) { 995a3667aaeSNaresh Kumar Inna rv = -ENODEV; 996a3667aaeSNaresh Kumar Inna break; 997a3667aaeSNaresh Kumar Inna } 998a3667aaeSNaresh Kumar Inna /* Initialize portid */ 999a3667aaeSNaresh Kumar Inna ln->portid = hw->pport[i].portid; 1000a3667aaeSNaresh Kumar Inna 1001a3667aaeSNaresh Kumar Inna spin_lock_irq(&hw->lock); 1002a3667aaeSNaresh Kumar Inna if (csio_lnode_start(ln) != 0) 1003a3667aaeSNaresh Kumar Inna rv = -ENODEV; 1004a3667aaeSNaresh Kumar Inna spin_unlock_irq(&hw->lock); 1005a3667aaeSNaresh Kumar Inna 1006a3667aaeSNaresh Kumar Inna if (rv) 1007a3667aaeSNaresh Kumar Inna break; 1008a3667aaeSNaresh Kumar Inna 1009a3667aaeSNaresh Kumar Inna csio_lnode_init_post(ln); 1010a3667aaeSNaresh Kumar Inna } 1011a3667aaeSNaresh Kumar Inna 1012a3667aaeSNaresh Kumar Inna if (rv) 1013a3667aaeSNaresh Kumar Inna goto err_lnode_exit; 1014a3667aaeSNaresh Kumar Inna 1015a3667aaeSNaresh Kumar Inna return 0; 1016a3667aaeSNaresh Kumar Inna 1017a3667aaeSNaresh Kumar Inna err_lnode_exit: 1018a3667aaeSNaresh Kumar Inna csio_lnodes_block_request(hw); 1019a3667aaeSNaresh Kumar Inna spin_lock_irq(&hw->lock); 1020a3667aaeSNaresh Kumar Inna csio_hw_stop(hw); 1021a3667aaeSNaresh Kumar Inna spin_unlock_irq(&hw->lock); 1022a3667aaeSNaresh Kumar Inna csio_lnodes_unblock_request(hw); 1023a3667aaeSNaresh Kumar Inna csio_lnodes_exit(hw, 0); 1024a3667aaeSNaresh Kumar Inna csio_hw_free(hw); 1025a3667aaeSNaresh Kumar Inna err_pci_exit: 1026a3667aaeSNaresh Kumar Inna csio_pci_exit(pdev, &bars); 1027a3667aaeSNaresh Kumar Inna err: 1028a3667aaeSNaresh Kumar Inna dev_err(&pdev->dev, "probe of device failed: %d\n", rv); 1029a3667aaeSNaresh Kumar Inna return rv; 1030a3667aaeSNaresh Kumar Inna } 1031a3667aaeSNaresh Kumar Inna 1032a3667aaeSNaresh Kumar Inna /* 1033a3667aaeSNaresh Kumar Inna * csio_remove_one - Remove one instance of the driver at this PCI function. 1034a3667aaeSNaresh Kumar Inna * @pdev: PCI device 1035a3667aaeSNaresh Kumar Inna * 1036a3667aaeSNaresh Kumar Inna * Used during hotplug operation. 1037a3667aaeSNaresh Kumar Inna */ 10386f039790SGreg Kroah-Hartman static void csio_remove_one(struct pci_dev *pdev) 1039a3667aaeSNaresh Kumar Inna { 1040a3667aaeSNaresh Kumar Inna struct csio_hw *hw = pci_get_drvdata(pdev); 1041a3667aaeSNaresh Kumar Inna int bars = pci_select_bars(pdev, IORESOURCE_MEM); 1042a3667aaeSNaresh Kumar Inna 1043a3667aaeSNaresh Kumar Inna csio_lnodes_block_request(hw); 1044a3667aaeSNaresh Kumar Inna spin_lock_irq(&hw->lock); 1045a3667aaeSNaresh Kumar Inna 1046a3667aaeSNaresh Kumar Inna /* Stops lnode, Rnode s/m 1047a3667aaeSNaresh Kumar Inna * Quiesce IOs. 1048a3667aaeSNaresh Kumar Inna * All sessions with remote ports are unregistered. 1049a3667aaeSNaresh Kumar Inna */ 1050a3667aaeSNaresh Kumar Inna csio_hw_stop(hw); 1051a3667aaeSNaresh Kumar Inna spin_unlock_irq(&hw->lock); 1052a3667aaeSNaresh Kumar Inna csio_lnodes_unblock_request(hw); 1053a3667aaeSNaresh Kumar Inna 1054a3667aaeSNaresh Kumar Inna csio_lnodes_exit(hw, 0); 1055a3667aaeSNaresh Kumar Inna csio_hw_free(hw); 1056a3667aaeSNaresh Kumar Inna csio_pci_exit(pdev, &bars); 1057a3667aaeSNaresh Kumar Inna } 1058a3667aaeSNaresh Kumar Inna 1059a3667aaeSNaresh Kumar Inna /* 1060a3667aaeSNaresh Kumar Inna * csio_pci_error_detected - PCI error was detected 1061a3667aaeSNaresh Kumar Inna * @pdev: PCI device 1062a3667aaeSNaresh Kumar Inna * 1063a3667aaeSNaresh Kumar Inna */ 1064a3667aaeSNaresh Kumar Inna static pci_ers_result_t 1065a3667aaeSNaresh Kumar Inna csio_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state) 1066a3667aaeSNaresh Kumar Inna { 1067a3667aaeSNaresh Kumar Inna struct csio_hw *hw = pci_get_drvdata(pdev); 1068a3667aaeSNaresh Kumar Inna 1069a3667aaeSNaresh Kumar Inna csio_lnodes_block_request(hw); 1070a3667aaeSNaresh Kumar Inna spin_lock_irq(&hw->lock); 1071a3667aaeSNaresh Kumar Inna 1072a3667aaeSNaresh Kumar Inna /* Post PCI error detected evt to HW s/m 1073a3667aaeSNaresh Kumar Inna * HW s/m handles this evt by quiescing IOs, unregisters rports 1074a3667aaeSNaresh Kumar Inna * and finally takes the device to offline. 1075a3667aaeSNaresh Kumar Inna */ 1076a3667aaeSNaresh Kumar Inna csio_post_event(&hw->sm, CSIO_HWE_PCIERR_DETECTED); 1077a3667aaeSNaresh Kumar Inna spin_unlock_irq(&hw->lock); 1078a3667aaeSNaresh Kumar Inna csio_lnodes_unblock_request(hw); 1079a3667aaeSNaresh Kumar Inna csio_lnodes_exit(hw, 0); 1080a3667aaeSNaresh Kumar Inna csio_intr_disable(hw, true); 1081a3667aaeSNaresh Kumar Inna pci_disable_device(pdev); 1082a3667aaeSNaresh Kumar Inna return state == pci_channel_io_perm_failure ? 1083a3667aaeSNaresh Kumar Inna PCI_ERS_RESULT_DISCONNECT : PCI_ERS_RESULT_NEED_RESET; 1084a3667aaeSNaresh Kumar Inna } 1085a3667aaeSNaresh Kumar Inna 1086a3667aaeSNaresh Kumar Inna /* 1087a3667aaeSNaresh Kumar Inna * csio_pci_slot_reset - PCI slot has been reset. 1088a3667aaeSNaresh Kumar Inna * @pdev: PCI device 1089a3667aaeSNaresh Kumar Inna * 1090a3667aaeSNaresh Kumar Inna */ 1091a3667aaeSNaresh Kumar Inna static pci_ers_result_t 1092a3667aaeSNaresh Kumar Inna csio_pci_slot_reset(struct pci_dev *pdev) 1093a3667aaeSNaresh Kumar Inna { 1094a3667aaeSNaresh Kumar Inna struct csio_hw *hw = pci_get_drvdata(pdev); 1095a3667aaeSNaresh Kumar Inna int ready; 1096a3667aaeSNaresh Kumar Inna 1097a3667aaeSNaresh Kumar Inna if (pci_enable_device(pdev)) { 1098a3667aaeSNaresh Kumar Inna dev_err(&pdev->dev, "cannot re-enable device in slot reset\n"); 1099a3667aaeSNaresh Kumar Inna return PCI_ERS_RESULT_DISCONNECT; 1100a3667aaeSNaresh Kumar Inna } 1101a3667aaeSNaresh Kumar Inna 1102a3667aaeSNaresh Kumar Inna pci_set_master(pdev); 1103a3667aaeSNaresh Kumar Inna pci_restore_state(pdev); 1104a3667aaeSNaresh Kumar Inna pci_save_state(pdev); 1105a3667aaeSNaresh Kumar Inna pci_cleanup_aer_uncorrect_error_status(pdev); 1106a3667aaeSNaresh Kumar Inna 1107a3667aaeSNaresh Kumar Inna /* Bring HW s/m to ready state. 1108a3667aaeSNaresh Kumar Inna * but don't resume IOs. 1109a3667aaeSNaresh Kumar Inna */ 1110a3667aaeSNaresh Kumar Inna spin_lock_irq(&hw->lock); 1111a3667aaeSNaresh Kumar Inna csio_post_event(&hw->sm, CSIO_HWE_PCIERR_SLOT_RESET); 1112a3667aaeSNaresh Kumar Inna ready = csio_is_hw_ready(hw); 1113a3667aaeSNaresh Kumar Inna spin_unlock_irq(&hw->lock); 1114a3667aaeSNaresh Kumar Inna 1115a3667aaeSNaresh Kumar Inna if (ready) { 1116a3667aaeSNaresh Kumar Inna return PCI_ERS_RESULT_RECOVERED; 1117a3667aaeSNaresh Kumar Inna } else { 1118a3667aaeSNaresh Kumar Inna dev_err(&pdev->dev, "Can't initialize HW when in slot reset\n"); 1119a3667aaeSNaresh Kumar Inna return PCI_ERS_RESULT_DISCONNECT; 1120a3667aaeSNaresh Kumar Inna } 1121a3667aaeSNaresh Kumar Inna } 1122a3667aaeSNaresh Kumar Inna 1123a3667aaeSNaresh Kumar Inna /* 1124a3667aaeSNaresh Kumar Inna * csio_pci_resume - Resume normal operations 1125a3667aaeSNaresh Kumar Inna * @pdev: PCI device 1126a3667aaeSNaresh Kumar Inna * 1127a3667aaeSNaresh Kumar Inna */ 1128a3667aaeSNaresh Kumar Inna static void 1129a3667aaeSNaresh Kumar Inna csio_pci_resume(struct pci_dev *pdev) 1130a3667aaeSNaresh Kumar Inna { 1131a3667aaeSNaresh Kumar Inna struct csio_hw *hw = pci_get_drvdata(pdev); 1132a3667aaeSNaresh Kumar Inna struct csio_lnode *ln; 1133a3667aaeSNaresh Kumar Inna int rv = 0; 1134a3667aaeSNaresh Kumar Inna int i; 1135a3667aaeSNaresh Kumar Inna 1136a3667aaeSNaresh Kumar Inna /* Bring the LINK UP and Resume IO */ 1137a3667aaeSNaresh Kumar Inna 1138a3667aaeSNaresh Kumar Inna for (i = 0; i < hw->num_pports; i++) { 1139a3667aaeSNaresh Kumar Inna ln = csio_shost_init(hw, &pdev->dev, true, NULL); 1140a3667aaeSNaresh Kumar Inna if (!ln) { 1141a3667aaeSNaresh Kumar Inna rv = -ENODEV; 1142a3667aaeSNaresh Kumar Inna break; 1143a3667aaeSNaresh Kumar Inna } 1144a3667aaeSNaresh Kumar Inna /* Initialize portid */ 1145a3667aaeSNaresh Kumar Inna ln->portid = hw->pport[i].portid; 1146a3667aaeSNaresh Kumar Inna 1147a3667aaeSNaresh Kumar Inna spin_lock_irq(&hw->lock); 1148a3667aaeSNaresh Kumar Inna if (csio_lnode_start(ln) != 0) 1149a3667aaeSNaresh Kumar Inna rv = -ENODEV; 1150a3667aaeSNaresh Kumar Inna spin_unlock_irq(&hw->lock); 1151a3667aaeSNaresh Kumar Inna 1152a3667aaeSNaresh Kumar Inna if (rv) 1153a3667aaeSNaresh Kumar Inna break; 1154a3667aaeSNaresh Kumar Inna 1155a3667aaeSNaresh Kumar Inna csio_lnode_init_post(ln); 1156a3667aaeSNaresh Kumar Inna } 1157a3667aaeSNaresh Kumar Inna 1158a3667aaeSNaresh Kumar Inna if (rv) 1159a3667aaeSNaresh Kumar Inna goto err_resume_exit; 1160a3667aaeSNaresh Kumar Inna 1161a3667aaeSNaresh Kumar Inna return; 1162a3667aaeSNaresh Kumar Inna 1163a3667aaeSNaresh Kumar Inna err_resume_exit: 1164a3667aaeSNaresh Kumar Inna csio_lnodes_block_request(hw); 1165a3667aaeSNaresh Kumar Inna spin_lock_irq(&hw->lock); 1166a3667aaeSNaresh Kumar Inna csio_hw_stop(hw); 1167a3667aaeSNaresh Kumar Inna spin_unlock_irq(&hw->lock); 1168a3667aaeSNaresh Kumar Inna csio_lnodes_unblock_request(hw); 1169a3667aaeSNaresh Kumar Inna csio_lnodes_exit(hw, 0); 1170a3667aaeSNaresh Kumar Inna csio_hw_free(hw); 1171a3667aaeSNaresh Kumar Inna dev_err(&pdev->dev, "resume of device failed: %d\n", rv); 1172a3667aaeSNaresh Kumar Inna } 1173a3667aaeSNaresh Kumar Inna 1174a3667aaeSNaresh Kumar Inna static struct pci_error_handlers csio_err_handler = { 1175a3667aaeSNaresh Kumar Inna .error_detected = csio_pci_error_detected, 1176a3667aaeSNaresh Kumar Inna .slot_reset = csio_pci_slot_reset, 1177a3667aaeSNaresh Kumar Inna .resume = csio_pci_resume, 1178a3667aaeSNaresh Kumar Inna }; 1179a3667aaeSNaresh Kumar Inna 11803fedeab1SHariprasad Shenai /* 11813fedeab1SHariprasad Shenai * Macros needed to support the PCI Device ID Table ... 11823fedeab1SHariprasad Shenai */ 11833fedeab1SHariprasad Shenai #define CH_PCI_DEVICE_ID_TABLE_DEFINE_BEGIN \ 1184768ffc66SHariprasad Shenai static const struct pci_device_id csio_pci_tbl[] = { 11853fb4c22eSPraveen Madhavan /* Define for FCoE uses PF6 */ 11863fb4c22eSPraveen Madhavan #define CH_PCI_DEVICE_ID_FUNCTION 0x6 1187a3667aaeSNaresh Kumar Inna 11883fedeab1SHariprasad Shenai #define CH_PCI_ID_TABLE_ENTRY(devid) \ 11893fedeab1SHariprasad Shenai { PCI_VDEVICE(CHELSIO, (devid)), 0 } 11903fedeab1SHariprasad Shenai 11913fedeab1SHariprasad Shenai #define CH_PCI_DEVICE_ID_TABLE_DEFINE_END { 0, } } 11923fedeab1SHariprasad Shenai 11933fedeab1SHariprasad Shenai #include "t4_pci_id_tbl.h" 1194a3667aaeSNaresh Kumar Inna 1195a3667aaeSNaresh Kumar Inna static struct pci_driver csio_pci_driver = { 1196a3667aaeSNaresh Kumar Inna .name = KBUILD_MODNAME, 1197a3667aaeSNaresh Kumar Inna .driver = { 1198a3667aaeSNaresh Kumar Inna .owner = THIS_MODULE, 1199a3667aaeSNaresh Kumar Inna }, 1200a3667aaeSNaresh Kumar Inna .id_table = csio_pci_tbl, 1201a3667aaeSNaresh Kumar Inna .probe = csio_probe_one, 1202a3667aaeSNaresh Kumar Inna .remove = csio_remove_one, 1203a3667aaeSNaresh Kumar Inna .err_handler = &csio_err_handler, 1204a3667aaeSNaresh Kumar Inna }; 1205a3667aaeSNaresh Kumar Inna 1206a3667aaeSNaresh Kumar Inna /* 1207a3667aaeSNaresh Kumar Inna * csio_init - Chelsio storage driver initialization function. 1208a3667aaeSNaresh Kumar Inna * 1209a3667aaeSNaresh Kumar Inna */ 1210a3667aaeSNaresh Kumar Inna static int __init 1211a3667aaeSNaresh Kumar Inna csio_init(void) 1212a3667aaeSNaresh Kumar Inna { 1213a3667aaeSNaresh Kumar Inna int rv = -ENOMEM; 1214a3667aaeSNaresh Kumar Inna 1215a3667aaeSNaresh Kumar Inna pr_info("%s %s\n", CSIO_DRV_DESC, CSIO_DRV_VERSION); 1216a3667aaeSNaresh Kumar Inna 1217a3667aaeSNaresh Kumar Inna csio_dfs_init(); 1218a3667aaeSNaresh Kumar Inna 1219a3667aaeSNaresh Kumar Inna csio_fcoe_transport = fc_attach_transport(&csio_fc_transport_funcs); 1220a3667aaeSNaresh Kumar Inna if (!csio_fcoe_transport) 1221a3667aaeSNaresh Kumar Inna goto err; 1222a3667aaeSNaresh Kumar Inna 1223a3667aaeSNaresh Kumar Inna csio_fcoe_transport_vport = 1224a3667aaeSNaresh Kumar Inna fc_attach_transport(&csio_fc_transport_vport_funcs); 1225a3667aaeSNaresh Kumar Inna if (!csio_fcoe_transport_vport) 1226a3667aaeSNaresh Kumar Inna goto err_vport; 1227a3667aaeSNaresh Kumar Inna 1228a3667aaeSNaresh Kumar Inna rv = pci_register_driver(&csio_pci_driver); 1229a3667aaeSNaresh Kumar Inna if (rv) 1230a3667aaeSNaresh Kumar Inna goto err_pci; 1231a3667aaeSNaresh Kumar Inna 1232a3667aaeSNaresh Kumar Inna return 0; 1233a3667aaeSNaresh Kumar Inna 1234a3667aaeSNaresh Kumar Inna err_pci: 1235a3667aaeSNaresh Kumar Inna fc_release_transport(csio_fcoe_transport_vport); 1236a3667aaeSNaresh Kumar Inna err_vport: 1237a3667aaeSNaresh Kumar Inna fc_release_transport(csio_fcoe_transport); 1238a3667aaeSNaresh Kumar Inna err: 1239a3667aaeSNaresh Kumar Inna csio_dfs_exit(); 1240a3667aaeSNaresh Kumar Inna return rv; 1241a3667aaeSNaresh Kumar Inna } 1242a3667aaeSNaresh Kumar Inna 1243a3667aaeSNaresh Kumar Inna /* 1244a3667aaeSNaresh Kumar Inna * csio_exit - Chelsio storage driver uninitialization . 1245a3667aaeSNaresh Kumar Inna * 1246a3667aaeSNaresh Kumar Inna * Function that gets called in the unload path. 1247a3667aaeSNaresh Kumar Inna */ 1248a3667aaeSNaresh Kumar Inna static void __exit 1249a3667aaeSNaresh Kumar Inna csio_exit(void) 1250a3667aaeSNaresh Kumar Inna { 1251a3667aaeSNaresh Kumar Inna pci_unregister_driver(&csio_pci_driver); 1252a3667aaeSNaresh Kumar Inna csio_dfs_exit(); 1253a3667aaeSNaresh Kumar Inna fc_release_transport(csio_fcoe_transport_vport); 1254a3667aaeSNaresh Kumar Inna fc_release_transport(csio_fcoe_transport); 1255a3667aaeSNaresh Kumar Inna } 1256a3667aaeSNaresh Kumar Inna 1257a3667aaeSNaresh Kumar Inna module_init(csio_init); 1258a3667aaeSNaresh Kumar Inna module_exit(csio_exit); 1259a3667aaeSNaresh Kumar Inna MODULE_AUTHOR(CSIO_DRV_AUTHOR); 1260a3667aaeSNaresh Kumar Inna MODULE_DESCRIPTION(CSIO_DRV_DESC); 1261a3667aaeSNaresh Kumar Inna MODULE_LICENSE(CSIO_DRV_LICENSE); 1262a3667aaeSNaresh Kumar Inna MODULE_DEVICE_TABLE(pci, csio_pci_tbl); 1263a3667aaeSNaresh Kumar Inna MODULE_VERSION(CSIO_DRV_VERSION); 12647cc16380SArvind Bhushan MODULE_FIRMWARE(FW_FNAME_T5); 12654bbd458eSVarun Prakash MODULE_FIRMWARE(FW_FNAME_T6); 1266