^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /* bnx2i.c: QLogic NetXtreme II iSCSI driver.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Copyright (c) 2006 - 2013 Broadcom Corporation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * Copyright (c) 2007, 2008 Red Hat, Inc. All rights reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (c) 2007, 2008 Mike Christie
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Copyright (c) 2014, QLogic Corporation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * This program is free software; you can redistribute it and/or modify
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * it under the terms of the GNU General Public License as published by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) * the Free Software Foundation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) * Written by: Anil Veerabhadrappa (anilgv@broadcom.com)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) * Previously Maintained by: Eddie Wai (eddie.wai@broadcom.com)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) * Maintained by: QLogic-Storage-Upstream@qlogic.com
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include "bnx2i.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) static struct list_head adapter_list = LIST_HEAD_INIT(adapter_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) static u32 adapter_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #define DRV_MODULE_NAME "bnx2i"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #define DRV_MODULE_VERSION "2.7.10.1"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #define DRV_MODULE_RELDATE "Jul 16, 2014"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) static char version[] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) "QLogic NetXtreme II iSCSI Driver " DRV_MODULE_NAME \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) " v" DRV_MODULE_VERSION " (" DRV_MODULE_RELDATE ")\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) MODULE_AUTHOR("Anil Veerabhadrappa <anilgv@broadcom.com> and "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) "Eddie Wai <eddie.wai@broadcom.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) MODULE_DESCRIPTION("QLogic NetXtreme II BCM5706/5708/5709/57710/57711/57712"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) "/57800/57810/57840 iSCSI Driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) MODULE_VERSION(DRV_MODULE_VERSION);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) static DEFINE_MUTEX(bnx2i_dev_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) unsigned int event_coal_min = 24;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) module_param(event_coal_min, int, 0664);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) MODULE_PARM_DESC(event_coal_min, "Event Coalescing Minimum Commands");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) unsigned int event_coal_div = 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) module_param(event_coal_div, int, 0664);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) MODULE_PARM_DESC(event_coal_div, "Event Coalescing Divide Factor");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) unsigned int en_tcp_dack = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) module_param(en_tcp_dack, int, 0664);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) MODULE_PARM_DESC(en_tcp_dack, "Enable TCP Delayed ACK");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) unsigned int error_mask1 = 0x00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) module_param(error_mask1, uint, 0664);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) MODULE_PARM_DESC(error_mask1, "Config FW iSCSI Error Mask #1");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) unsigned int error_mask2 = 0x00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) module_param(error_mask2, uint, 0664);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) MODULE_PARM_DESC(error_mask2, "Config FW iSCSI Error Mask #2");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) unsigned int sq_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) module_param(sq_size, int, 0664);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) MODULE_PARM_DESC(sq_size, "Configure SQ size");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) unsigned int rq_size = BNX2I_RQ_WQES_DEFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) module_param(rq_size, int, 0664);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) MODULE_PARM_DESC(rq_size, "Configure RQ size");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) u64 iscsi_error_mask = 0x00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) DEFINE_PER_CPU(struct bnx2i_percpu_s, bnx2i_percpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) * bnx2i_identify_device - identifies NetXtreme II device type
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) * @hba: Adapter structure pointer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) * @dev: Corresponding cnic device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) * This function identifies the NX2 device type and sets appropriate
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) * queue mailbox register access method, 5709 requires driver to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) * access MBOX regs using *bin* mode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) void bnx2i_identify_device(struct bnx2i_hba *hba, struct cnic_dev *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) hba->cnic_dev_type = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) if (test_bit(CNIC_F_BNX2_CLASS, &dev->flags)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) if (hba->pci_did == PCI_DEVICE_ID_NX2_5706 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) hba->pci_did == PCI_DEVICE_ID_NX2_5706S) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) set_bit(BNX2I_NX2_DEV_5706, &hba->cnic_dev_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) } else if (hba->pci_did == PCI_DEVICE_ID_NX2_5708 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) hba->pci_did == PCI_DEVICE_ID_NX2_5708S) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) set_bit(BNX2I_NX2_DEV_5708, &hba->cnic_dev_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) } else if (hba->pci_did == PCI_DEVICE_ID_NX2_5709 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) hba->pci_did == PCI_DEVICE_ID_NX2_5709S) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) set_bit(BNX2I_NX2_DEV_5709, &hba->cnic_dev_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) hba->mail_queue_access = BNX2I_MQ_BIN_MODE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) } else if (test_bit(CNIC_F_BNX2X_CLASS, &dev->flags)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) set_bit(BNX2I_NX2_DEV_57710, &hba->cnic_dev_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) printk(KERN_ALERT "bnx2i: unknown device, 0x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) hba->pci_did);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) * get_adapter_list_head - returns head of adapter list
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) struct bnx2i_hba *get_adapter_list_head(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) struct bnx2i_hba *hba = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) struct bnx2i_hba *tmp_hba;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) if (!adapter_count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) goto hba_not_found;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) mutex_lock(&bnx2i_dev_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) list_for_each_entry(tmp_hba, &adapter_list, link) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) if (tmp_hba->cnic && tmp_hba->cnic->cm_select_dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) hba = tmp_hba;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) mutex_unlock(&bnx2i_dev_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) hba_not_found:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) return hba;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) * bnx2i_find_hba_for_cnic - maps cnic device instance to bnx2i adapter instance
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) * @cnic: pointer to cnic device instance
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) struct bnx2i_hba *bnx2i_find_hba_for_cnic(struct cnic_dev *cnic)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) struct bnx2i_hba *hba, *temp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) mutex_lock(&bnx2i_dev_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) list_for_each_entry_safe(hba, temp, &adapter_list, link) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) if (hba->cnic == cnic) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) mutex_unlock(&bnx2i_dev_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) return hba;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) mutex_unlock(&bnx2i_dev_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) * bnx2i_start - cnic callback to initialize & start adapter instance
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) * @handle: transparent handle pointing to adapter structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) * This function maps adapter structure to pcidev structure and initiates
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) * firmware handshake to enable/initialize on chip iscsi components
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) * This bnx2i - cnic interface api callback is issued after following
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) * 2 conditions are met -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) * a) underlying network interface is up (marked by event 'NETDEV_UP'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) * from netdev
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) * b) bnx2i adapter instance is registered
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) void bnx2i_start(void *handle)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) #define BNX2I_INIT_POLL_TIME (1000 / HZ)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) struct bnx2i_hba *hba = handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) int i = HZ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) /* On some bnx2x devices, it is possible that iSCSI is no
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) * longer supported after firmware is downloaded. In that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) * case, the iscsi_init_msg will return failure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) bnx2i_send_fw_iscsi_init_msg(hba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) while (!test_bit(ADAPTER_STATE_UP, &hba->adapter_state) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) !test_bit(ADAPTER_STATE_INIT_FAILED, &hba->adapter_state) && i--)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) msleep(BNX2I_INIT_POLL_TIME);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) * bnx2i_chip_cleanup - local routine to handle chip cleanup
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) * @hba: Adapter instance to register
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) * Driver checks if adapter still has any active connections before
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) * executing the cleanup process
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) static void bnx2i_chip_cleanup(struct bnx2i_hba *hba)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) struct bnx2i_endpoint *bnx2i_ep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) struct list_head *pos, *tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) if (hba->ofld_conns_active) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) /* Stage to force the disconnection
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) * This is the case where the daemon is either slow or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) * not present
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) printk(KERN_ALERT "bnx2i: (%s) chip cleanup for %d active "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) "connections\n", hba->netdev->name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) hba->ofld_conns_active);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) mutex_lock(&hba->net_dev_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) list_for_each_safe(pos, tmp, &hba->ep_active_list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) bnx2i_ep = list_entry(pos, struct bnx2i_endpoint, link);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) /* Clean up the chip only */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) bnx2i_hw_ep_disconnect(bnx2i_ep);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) bnx2i_ep->cm_sk = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) mutex_unlock(&hba->net_dev_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) * bnx2i_stop - cnic callback to shutdown adapter instance
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) * @handle: transparent handle pointing to adapter structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) * driver checks if adapter is already in shutdown mode, if not start
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) * the shutdown process
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) void bnx2i_stop(void *handle)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) struct bnx2i_hba *hba = handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) int conns_active;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) int wait_delay = 1 * HZ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) /* check if cleanup happened in GOING_DOWN context */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) if (!test_and_set_bit(ADAPTER_STATE_GOING_DOWN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) &hba->adapter_state)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) iscsi_host_for_each_session(hba->shost,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) bnx2i_drop_session);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) wait_delay = hba->hba_shutdown_tmo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) /* Wait for inflight offload connection tasks to complete before
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) * proceeding. Forcefully terminate all connection recovery in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) * progress at the earliest, either in bind(), send_pdu(LOGIN),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) * or conn_start()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) wait_event_interruptible_timeout(hba->eh_wait,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) (list_empty(&hba->ep_ofld_list) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) list_empty(&hba->ep_destroy_list)),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 2 * HZ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) /* Wait for all endpoints to be torn down, Chip will be reset once
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) * control returns to network driver. So it is required to cleanup and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) * release all connection resources before returning from this routine.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) while (hba->ofld_conns_active) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) conns_active = hba->ofld_conns_active;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) wait_event_interruptible_timeout(hba->eh_wait,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) (hba->ofld_conns_active != conns_active),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) wait_delay);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) if (hba->ofld_conns_active == conns_active)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) bnx2i_chip_cleanup(hba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) /* This flag should be cleared last so that ep_disconnect() gracefully
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) * cleans up connection context
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) clear_bit(ADAPTER_STATE_GOING_DOWN, &hba->adapter_state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) clear_bit(ADAPTER_STATE_UP, &hba->adapter_state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) * bnx2i_init_one - initialize an adapter instance and allocate memory resources
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) * @hba: bnx2i adapter instance
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) * @cnic: cnic device handle
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) * Global resource lock is held during critical sections below. This routine is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) * called from either cnic_register_driver() or device hot plug context and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) * and does majority of device specific initialization
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) static int bnx2i_init_one(struct bnx2i_hba *hba, struct cnic_dev *cnic)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) mutex_lock(&bnx2i_dev_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) if (!cnic->max_iscsi_conn) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) printk(KERN_ALERT "bnx2i: dev %s does not support "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) "iSCSI\n", hba->netdev->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) rc = -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) hba->cnic = cnic;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) rc = cnic->register_device(cnic, CNIC_ULP_ISCSI, hba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) if (!rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) hba->age++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) set_bit(BNX2I_CNIC_REGISTERED, &hba->reg_with_cnic);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) list_add_tail(&hba->link, &adapter_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) adapter_count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) } else if (rc == -EBUSY) /* duplicate registration */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) printk(KERN_ALERT "bnx2i, duplicate registration"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) "hba=%p, cnic=%p\n", hba, cnic);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) else if (rc == -EAGAIN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) printk(KERN_ERR "bnx2i, driver not registered\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) else if (rc == -EINVAL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) printk(KERN_ERR "bnx2i, invalid type %d\n", CNIC_ULP_ISCSI);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) printk(KERN_ERR "bnx2i dev reg, unknown error, %d\n", rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) mutex_unlock(&bnx2i_dev_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) * bnx2i_ulp_init - initialize an adapter instance
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) * @dev: cnic device handle
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) * Called from cnic_register_driver() context to initialize all enumerated
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) * cnic devices. This routine allocate adapter structure and other
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) * device specific resources.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) void bnx2i_ulp_init(struct cnic_dev *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) struct bnx2i_hba *hba;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) /* Allocate a HBA structure for this device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) hba = bnx2i_alloc_hba(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) if (!hba) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) printk(KERN_ERR "bnx2i init: hba initialization failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) /* Get PCI related information and update hba struct members */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) clear_bit(BNX2I_CNIC_REGISTERED, &hba->reg_with_cnic);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) if (bnx2i_init_one(hba, dev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) printk(KERN_ERR "bnx2i - hba %p init failed\n", hba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) bnx2i_free_hba(hba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) * bnx2i_ulp_exit - shuts down adapter instance and frees all resources
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) * @dev: cnic device handle
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) void bnx2i_ulp_exit(struct cnic_dev *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) struct bnx2i_hba *hba;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) hba = bnx2i_find_hba_for_cnic(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) if (!hba) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) printk(KERN_INFO "bnx2i_ulp_exit: hba not "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) "found, dev 0x%p\n", dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) mutex_lock(&bnx2i_dev_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) list_del_init(&hba->link);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) adapter_count--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) if (test_bit(BNX2I_CNIC_REGISTERED, &hba->reg_with_cnic)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) hba->cnic->unregister_device(hba->cnic, CNIC_ULP_ISCSI);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) clear_bit(BNX2I_CNIC_REGISTERED, &hba->reg_with_cnic);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) mutex_unlock(&bnx2i_dev_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) bnx2i_free_hba(hba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) * bnx2i_get_stats - Retrieve various statistic from iSCSI offload
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) * @handle: bnx2i_hba
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) * function callback exported via bnx2i - cnic driver interface to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) * retrieve various iSCSI offload related statistics.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) int bnx2i_get_stats(void *handle)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) struct bnx2i_hba *hba = handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) struct iscsi_stats_info *stats;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) if (!hba)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) stats = (struct iscsi_stats_info *)hba->cnic->stats_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) if (!stats)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) strlcpy(stats->version, DRV_MODULE_VERSION, sizeof(stats->version));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) memcpy(stats->mac_add1 + 2, hba->cnic->mac_addr, ETH_ALEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) stats->max_frame_size = hba->netdev->mtu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) stats->txq_size = hba->max_sqes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) stats->rxq_size = hba->max_cqes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) stats->txq_avg_depth = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) stats->rxq_avg_depth = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) GET_STATS_64(hba, stats, rx_pdus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) GET_STATS_64(hba, stats, rx_bytes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) GET_STATS_64(hba, stats, tx_pdus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) GET_STATS_64(hba, stats, tx_bytes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) * bnx2i_cpu_online - Create a receive thread for an online CPU
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) * @cpu: cpu index for the online cpu
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) static int bnx2i_cpu_online(unsigned int cpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) struct bnx2i_percpu_s *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) struct task_struct *thread;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) p = &per_cpu(bnx2i_percpu, cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) thread = kthread_create_on_node(bnx2i_percpu_io_thread, (void *)p,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) cpu_to_node(cpu),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) "bnx2i_thread/%d", cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) if (IS_ERR(thread))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) return PTR_ERR(thread);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) /* bind thread to the cpu */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) kthread_bind(thread, cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) p->iothread = thread;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) wake_up_process(thread);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) static int bnx2i_cpu_offline(unsigned int cpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) struct bnx2i_percpu_s *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) struct task_struct *thread;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) struct bnx2i_work *work, *tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) /* Prevent any new work from being queued for this CPU */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) p = &per_cpu(bnx2i_percpu, cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) spin_lock_bh(&p->p_work_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) thread = p->iothread;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) p->iothread = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) /* Free all work in the list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) list_for_each_entry_safe(work, tmp, &p->work_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) list_del_init(&work->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) bnx2i_process_scsi_cmd_resp(work->session,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) work->bnx2i_conn, &work->cqe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) kfree(work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) spin_unlock_bh(&p->p_work_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) if (thread)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) kthread_stop(thread);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) static enum cpuhp_state bnx2i_online_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) * bnx2i_mod_init - module init entry point
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) * initialize any driver wide global data structures such as endpoint pool,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) * tcp port manager/queue, sysfs. finally driver will register itself
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) * with the cnic module
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) static int __init bnx2i_mod_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) unsigned cpu = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) struct bnx2i_percpu_s *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) printk(KERN_INFO "%s", version);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) if (sq_size && !is_power_of_2(sq_size))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) sq_size = roundup_pow_of_two(sq_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) bnx2i_scsi_xport_template =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) iscsi_register_transport(&bnx2i_iscsi_transport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) if (!bnx2i_scsi_xport_template) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) printk(KERN_ERR "Could not register bnx2i transport.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) err = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) err = cnic_register_driver(CNIC_ULP_ISCSI, &bnx2i_cnic_cb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) printk(KERN_ERR "Could not register bnx2i cnic driver.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) goto unreg_xport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) /* Create percpu kernel threads to handle iSCSI I/O completions */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) for_each_possible_cpu(cpu) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) p = &per_cpu(bnx2i_percpu, cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) INIT_LIST_HEAD(&p->work_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) spin_lock_init(&p->p_work_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) p->iothread = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) err = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "scsi/bnx2i:online",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) bnx2i_cpu_online, bnx2i_cpu_offline);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) goto unreg_driver;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) bnx2i_online_state = err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) unreg_driver:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) cnic_unregister_driver(CNIC_ULP_ISCSI);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) unreg_xport:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) iscsi_unregister_transport(&bnx2i_iscsi_transport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) * bnx2i_mod_exit - module cleanup/exit entry point
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) * Global resource lock and host adapter lock is held during critical sections
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) * in this function. Driver will browse through the adapter list, cleans-up
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) * each instance, unregisters iscsi transport name and finally driver will
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) * unregister itself with the cnic module
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) static void __exit bnx2i_mod_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) struct bnx2i_hba *hba;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) mutex_lock(&bnx2i_dev_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) while (!list_empty(&adapter_list)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) hba = list_entry(adapter_list.next, struct bnx2i_hba, link);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) list_del(&hba->link);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) adapter_count--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) if (test_bit(BNX2I_CNIC_REGISTERED, &hba->reg_with_cnic)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) bnx2i_chip_cleanup(hba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) hba->cnic->unregister_device(hba->cnic, CNIC_ULP_ISCSI);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) clear_bit(BNX2I_CNIC_REGISTERED, &hba->reg_with_cnic);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) bnx2i_free_hba(hba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) mutex_unlock(&bnx2i_dev_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) cpuhp_remove_state(bnx2i_online_state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) iscsi_unregister_transport(&bnx2i_iscsi_transport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) cnic_unregister_driver(CNIC_ULP_ISCSI);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) module_init(bnx2i_mod_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) module_exit(bnx2i_mod_exit);