Chad Dupuis | de909d8 | 2015-10-19 15:40:36 -0400 | [diff] [blame] | 1 | /* bnx2fc_fcoe.c: QLogic Linux FCoE offload driver. |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 2 | * This file contains the code that interacts with libfc, libfcoe, |
| 3 | * cnic modules to create FCoE instances, send/receive non-offloaded |
| 4 | * FIP/FCoE packets, listen to link events etc. |
| 5 | * |
Chad Dupuis | 97586090 | 2015-10-19 15:40:35 -0400 | [diff] [blame] | 6 | * Copyright (c) 2008-2013 Broadcom Corporation |
Chad Dupuis | 21144b8 | 2017-06-26 08:59:34 -0700 | [diff] [blame] | 7 | * Copyright (c) 2014-2016 QLogic Corporation |
| 8 | * Copyright (c) 2016-2017 Cavium Inc. |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 9 | * |
| 10 | * This program is free software; you can redistribute it and/or modify |
| 11 | * it under the terms of the GNU General Public License as published by |
| 12 | * the Free Software Foundation. |
| 13 | * |
| 14 | * Written by: Bhanu Prakash Gollapudi (bprakash@broadcom.com) |
| 15 | */ |
| 16 | |
| 17 | #include "bnx2fc.h" |
| 18 | |
Jakub Kicinski | cc69837 | 2020-11-20 14:50:52 -0800 | [diff] [blame] | 19 | #include <linux/ethtool.h> |
| 20 | |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 21 | static struct list_head adapter_list; |
Bhanu Prakash Gollapudi | aea71a0 | 2011-07-26 14:51:39 -0700 | [diff] [blame] | 22 | static struct list_head if_list; |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 23 | static u32 adapter_count; |
| 24 | static DEFINE_MUTEX(bnx2fc_dev_lock); |
| 25 | DEFINE_PER_CPU(struct bnx2fc_percpu_s, bnx2fc_percpu); |
| 26 | |
| 27 | #define DRV_MODULE_NAME "bnx2fc" |
| 28 | #define DRV_MODULE_VERSION BNX2FC_VERSION |
Chad Dupuis | edb394b | 2015-10-19 15:40:41 -0400 | [diff] [blame] | 29 | #define DRV_MODULE_RELDATE "October 15, 2015" |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 30 | |
| 31 | |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 32 | static char version[] = |
Chad Dupuis | de909d8 | 2015-10-19 15:40:36 -0400 | [diff] [blame] | 33 | "QLogic FCoE Driver " DRV_MODULE_NAME \ |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 34 | " v" DRV_MODULE_VERSION " (" DRV_MODULE_RELDATE ")\n"; |
| 35 | |
| 36 | |
| 37 | MODULE_AUTHOR("Bhanu Prakash Gollapudi <bprakash@broadcom.com>"); |
Chad Dupuis | de909d8 | 2015-10-19 15:40:36 -0400 | [diff] [blame] | 38 | MODULE_DESCRIPTION("QLogic FCoE Driver"); |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 39 | MODULE_LICENSE("GPL"); |
| 40 | MODULE_VERSION(DRV_MODULE_VERSION); |
| 41 | |
| 42 | #define BNX2FC_MAX_QUEUE_DEPTH 256 |
| 43 | #define BNX2FC_MIN_QUEUE_DEPTH 32 |
| 44 | #define FCOE_WORD_TO_BYTE 4 |
| 45 | |
| 46 | static struct scsi_transport_template *bnx2fc_transport_template; |
| 47 | static struct scsi_transport_template *bnx2fc_vport_xport_template; |
| 48 | |
| 49 | struct workqueue_struct *bnx2fc_wq; |
| 50 | |
| 51 | /* bnx2fc structure needs only one instance of the fcoe_percpu_s structure. |
| 52 | * Here the io threads are per cpu but the l2 thread is just one |
| 53 | */ |
| 54 | struct fcoe_percpu_s bnx2fc_global; |
Jason Yan | 5c2ef01 | 2020-09-12 11:37:58 +0800 | [diff] [blame] | 55 | static DEFINE_SPINLOCK(bnx2fc_global_lock); |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 56 | |
| 57 | static struct cnic_ulp_ops bnx2fc_cnic_cb; |
| 58 | static struct libfc_function_template bnx2fc_libfc_fcn_templ; |
| 59 | static struct scsi_host_template bnx2fc_shost_template; |
| 60 | static struct fc_function_template bnx2fc_transport_function; |
Robert Love | 8d55e50 | 2012-05-22 19:06:26 -0700 | [diff] [blame] | 61 | static struct fcoe_sysfs_function_template bnx2fc_fcoe_sysfs_templ; |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 62 | static struct fc_function_template bnx2fc_vport_xport_function; |
Hannes Reinecke | 1917d42 | 2016-07-04 10:29:19 +0200 | [diff] [blame] | 63 | static int bnx2fc_create(struct net_device *netdev, enum fip_mode fip_mode); |
Bhanu Prakash Gollapudi | eccdcd0 | 2011-08-24 18:56:42 -0700 | [diff] [blame] | 64 | static void __bnx2fc_destroy(struct bnx2fc_interface *interface); |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 65 | static int bnx2fc_destroy(struct net_device *net_device); |
| 66 | static int bnx2fc_enable(struct net_device *netdev); |
| 67 | static int bnx2fc_disable(struct net_device *netdev); |
| 68 | |
Robert Love | 6e89ea3 | 2012-11-27 06:53:40 +0000 | [diff] [blame] | 69 | /* fcoe_syfs control interface handlers */ |
| 70 | static int bnx2fc_ctlr_alloc(struct net_device *netdev); |
| 71 | static int bnx2fc_ctlr_enabled(struct fcoe_ctlr_device *cdev); |
| 72 | |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 73 | static void bnx2fc_recv_frame(struct sk_buff *skb); |
| 74 | |
Bhanu Prakash Gollapudi | aea71a0 | 2011-07-26 14:51:39 -0700 | [diff] [blame] | 75 | static void bnx2fc_start_disc(struct bnx2fc_interface *interface); |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 76 | static int bnx2fc_shost_config(struct fc_lport *lport, struct device *dev); |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 77 | static int bnx2fc_lport_config(struct fc_lport *lport); |
Bhanu Prakash Gollapudi | 0eb43b4 | 2013-04-22 19:22:30 +0000 | [diff] [blame] | 78 | static int bnx2fc_em_config(struct fc_lport *lport, struct bnx2fc_hba *hba); |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 79 | static int bnx2fc_bind_adapter_devices(struct bnx2fc_hba *hba); |
| 80 | static void bnx2fc_unbind_adapter_devices(struct bnx2fc_hba *hba); |
| 81 | static int bnx2fc_bind_pcidev(struct bnx2fc_hba *hba); |
| 82 | static void bnx2fc_unbind_pcidev(struct bnx2fc_hba *hba); |
Bhanu Prakash Gollapudi | aea71a0 | 2011-07-26 14:51:39 -0700 | [diff] [blame] | 83 | static struct fc_lport *bnx2fc_if_create(struct bnx2fc_interface *interface, |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 84 | struct device *parent, int npiv); |
John Meneghini | 847f9ea | 2022-01-14 23:00:44 -0500 | [diff] [blame] | 85 | static void bnx2fc_port_destroy(struct fcoe_port *port); |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 86 | |
| 87 | static struct bnx2fc_hba *bnx2fc_hba_lookup(struct net_device *phys_dev); |
Bhanu Prakash Gollapudi | aea71a0 | 2011-07-26 14:51:39 -0700 | [diff] [blame] | 88 | static struct bnx2fc_interface *bnx2fc_interface_lookup(struct net_device |
| 89 | *phys_dev); |
Bhanu Prakash Gollapudi | abc49a9 | 2011-08-04 17:38:42 -0700 | [diff] [blame] | 90 | static inline void bnx2fc_interface_put(struct bnx2fc_interface *interface); |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 91 | static struct bnx2fc_hba *bnx2fc_find_hba_for_cnic(struct cnic_dev *cnic); |
| 92 | |
| 93 | static int bnx2fc_fw_init(struct bnx2fc_hba *hba); |
| 94 | static void bnx2fc_fw_destroy(struct bnx2fc_hba *hba); |
| 95 | |
| 96 | static void bnx2fc_port_shutdown(struct fc_lport *lport); |
Bhanu Prakash Gollapudi | aea71a0 | 2011-07-26 14:51:39 -0700 | [diff] [blame] | 97 | static void bnx2fc_stop(struct bnx2fc_interface *interface); |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 98 | static int __init bnx2fc_mod_init(void); |
| 99 | static void __exit bnx2fc_mod_exit(void); |
| 100 | |
| 101 | unsigned int bnx2fc_debug_level; |
| 102 | module_param_named(debug_logging, bnx2fc_debug_level, int, S_IRUGO|S_IWUSR); |
Jose Castillo | d4faee0 | 2016-01-29 14:39:26 +0000 | [diff] [blame] | 103 | MODULE_PARM_DESC(debug_logging, |
| 104 | "Option to enable extended logging,\n" |
| 105 | "\t\tDefault is 0 - no logging.\n" |
| 106 | "\t\t0x01 - SCSI cmd error, cleanup.\n" |
| 107 | "\t\t0x02 - Session setup, cleanup, etc.\n" |
| 108 | "\t\t0x04 - lport events, link, mtu, etc.\n" |
| 109 | "\t\t0x08 - ELS logs.\n" |
| 110 | "\t\t0x10 - fcoe L2 fame related logs.\n" |
| 111 | "\t\t0xff - LOG all messages."); |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 112 | |
Jason Yan | 5c2ef01 | 2020-09-12 11:37:58 +0800 | [diff] [blame] | 113 | static uint bnx2fc_devloss_tmo; |
Joe Carnuccio | 10755d3 | 2016-04-07 09:07:56 -0400 | [diff] [blame] | 114 | module_param_named(devloss_tmo, bnx2fc_devloss_tmo, uint, S_IRUGO); |
| 115 | MODULE_PARM_DESC(devloss_tmo, " Change devloss_tmo for the remote ports " |
| 116 | "attached via bnx2fc."); |
| 117 | |
Jason Yan | 5c2ef01 | 2020-09-12 11:37:58 +0800 | [diff] [blame] | 118 | static uint bnx2fc_max_luns = BNX2FC_MAX_LUN; |
Joe Carnuccio | 10755d3 | 2016-04-07 09:07:56 -0400 | [diff] [blame] | 119 | module_param_named(max_luns, bnx2fc_max_luns, uint, S_IRUGO); |
| 120 | MODULE_PARM_DESC(max_luns, " Change the default max_lun per SCSI host. Default " |
| 121 | "0xffff."); |
| 122 | |
Jason Yan | 5c2ef01 | 2020-09-12 11:37:58 +0800 | [diff] [blame] | 123 | static uint bnx2fc_queue_depth; |
Joe Carnuccio | 10755d3 | 2016-04-07 09:07:56 -0400 | [diff] [blame] | 124 | module_param_named(queue_depth, bnx2fc_queue_depth, uint, S_IRUGO); |
| 125 | MODULE_PARM_DESC(queue_depth, " Change the default queue depth of SCSI devices " |
| 126 | "attached via bnx2fc."); |
| 127 | |
Jason Yan | 5c2ef01 | 2020-09-12 11:37:58 +0800 | [diff] [blame] | 128 | static uint bnx2fc_log_fka; |
Chad Dupuis | 3f12f76 | 2016-04-07 09:07:57 -0400 | [diff] [blame] | 129 | module_param_named(log_fka, bnx2fc_log_fka, uint, S_IRUGO|S_IWUSR); |
| 130 | MODULE_PARM_DESC(log_fka, " Print message to kernel log when fcoe is " |
| 131 | "initiating a FIP keep alive when debug logging is enabled."); |
| 132 | |
Bhanu Prakash Gollapudi | f72f6979 | 2011-10-03 16:45:02 -0700 | [diff] [blame] | 133 | static inline struct net_device *bnx2fc_netdev(const struct fc_lport *lport) |
| 134 | { |
| 135 | return ((struct bnx2fc_interface *) |
| 136 | ((struct fcoe_port *)lport_priv(lport))->priv)->netdev; |
| 137 | } |
| 138 | |
Robert Love | 8d55e50 | 2012-05-22 19:06:26 -0700 | [diff] [blame] | 139 | static void bnx2fc_fcf_get_vlan_id(struct fcoe_fcf_device *fcf_dev) |
| 140 | { |
| 141 | struct fcoe_ctlr_device *ctlr_dev = |
| 142 | fcoe_fcf_dev_to_ctlr_dev(fcf_dev); |
| 143 | struct fcoe_ctlr *ctlr = fcoe_ctlr_device_priv(ctlr_dev); |
| 144 | struct bnx2fc_interface *fcoe = fcoe_ctlr_priv(ctlr); |
| 145 | |
| 146 | fcf_dev->vlan_id = fcoe->vlan_id; |
| 147 | } |
| 148 | |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 149 | static void bnx2fc_clean_rx_queue(struct fc_lport *lp) |
| 150 | { |
| 151 | struct fcoe_percpu_s *bg; |
| 152 | struct fcoe_rcv_info *fr; |
| 153 | struct sk_buff_head *list; |
| 154 | struct sk_buff *skb, *next; |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 155 | |
| 156 | bg = &bnx2fc_global; |
| 157 | spin_lock_bh(&bg->fcoe_rx_list.lock); |
| 158 | list = &bg->fcoe_rx_list; |
David S. Miller | 1173ab7 | 2018-08-07 23:43:51 -0700 | [diff] [blame] | 159 | skb_queue_walk_safe(list, skb, next) { |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 160 | fr = fcoe_dev_from_skb(skb); |
| 161 | if (fr->fr_dev == lp) { |
| 162 | __skb_unlink(skb, list); |
| 163 | kfree_skb(skb); |
| 164 | } |
| 165 | } |
| 166 | spin_unlock_bh(&bg->fcoe_rx_list.lock); |
| 167 | } |
| 168 | |
| 169 | int bnx2fc_get_paged_crc_eof(struct sk_buff *skb, int tlen) |
| 170 | { |
| 171 | int rc; |
| 172 | spin_lock(&bnx2fc_global_lock); |
| 173 | rc = fcoe_get_paged_crc_eof(skb, tlen, &bnx2fc_global); |
| 174 | spin_unlock(&bnx2fc_global_lock); |
| 175 | |
| 176 | return rc; |
| 177 | } |
| 178 | |
| 179 | static void bnx2fc_abort_io(struct fc_lport *lport) |
| 180 | { |
| 181 | /* |
| 182 | * This function is no-op for bnx2fc, but we do |
| 183 | * not want to leave it as NULL either, as libfc |
| 184 | * can call the default function which is |
| 185 | * fc_fcp_abort_io. |
| 186 | */ |
| 187 | } |
| 188 | |
| 189 | static void bnx2fc_cleanup(struct fc_lport *lport) |
| 190 | { |
| 191 | struct fcoe_port *port = lport_priv(lport); |
Bhanu Prakash Gollapudi | aea71a0 | 2011-07-26 14:51:39 -0700 | [diff] [blame] | 192 | struct bnx2fc_interface *interface = port->priv; |
| 193 | struct bnx2fc_hba *hba = interface->hba; |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 194 | struct bnx2fc_rport *tgt; |
| 195 | int i; |
| 196 | |
| 197 | BNX2FC_MISC_DBG("Entered %s\n", __func__); |
| 198 | mutex_lock(&hba->hba_mutex); |
| 199 | spin_lock_bh(&hba->hba_lock); |
| 200 | for (i = 0; i < BNX2FC_NUM_MAX_SESS; i++) { |
| 201 | tgt = hba->tgt_ofld_list[i]; |
| 202 | if (tgt) { |
| 203 | /* Cleanup IOs belonging to requested vport */ |
| 204 | if (tgt->port == port) { |
| 205 | spin_unlock_bh(&hba->hba_lock); |
| 206 | BNX2FC_TGT_DBG(tgt, "flush/cleanup\n"); |
| 207 | bnx2fc_flush_active_ios(tgt); |
| 208 | spin_lock_bh(&hba->hba_lock); |
| 209 | } |
| 210 | } |
| 211 | } |
| 212 | spin_unlock_bh(&hba->hba_lock); |
| 213 | mutex_unlock(&hba->hba_mutex); |
| 214 | } |
| 215 | |
| 216 | static int bnx2fc_xmit_l2_frame(struct bnx2fc_rport *tgt, |
| 217 | struct fc_frame *fp) |
| 218 | { |
| 219 | struct fc_rport_priv *rdata = tgt->rdata; |
| 220 | struct fc_frame_header *fh; |
| 221 | int rc = 0; |
| 222 | |
| 223 | fh = fc_frame_header_get(fp); |
| 224 | BNX2FC_TGT_DBG(tgt, "Xmit L2 frame rport = 0x%x, oxid = 0x%x, " |
| 225 | "r_ctl = 0x%x\n", rdata->ids.port_id, |
| 226 | ntohs(fh->fh_ox_id), fh->fh_r_ctl); |
| 227 | if ((fh->fh_type == FC_TYPE_ELS) && |
| 228 | (fh->fh_r_ctl == FC_RCTL_ELS_REQ)) { |
| 229 | |
| 230 | switch (fc_frame_payload_op(fp)) { |
| 231 | case ELS_ADISC: |
| 232 | rc = bnx2fc_send_adisc(tgt, fp); |
| 233 | break; |
| 234 | case ELS_LOGO: |
| 235 | rc = bnx2fc_send_logo(tgt, fp); |
| 236 | break; |
| 237 | case ELS_RLS: |
| 238 | rc = bnx2fc_send_rls(tgt, fp); |
| 239 | break; |
| 240 | default: |
| 241 | break; |
| 242 | } |
| 243 | } else if ((fh->fh_type == FC_TYPE_BLS) && |
| 244 | (fh->fh_r_ctl == FC_RCTL_BA_ABTS)) |
| 245 | BNX2FC_TGT_DBG(tgt, "ABTS frame\n"); |
| 246 | else { |
| 247 | BNX2FC_TGT_DBG(tgt, "Send L2 frame type 0x%x " |
| 248 | "rctl 0x%x thru non-offload path\n", |
| 249 | fh->fh_type, fh->fh_r_ctl); |
| 250 | return -ENODEV; |
| 251 | } |
| 252 | if (rc) |
| 253 | return -ENOMEM; |
| 254 | else |
| 255 | return 0; |
| 256 | } |
| 257 | |
| 258 | /** |
| 259 | * bnx2fc_xmit - bnx2fc's FCoE frame transmit function |
| 260 | * |
| 261 | * @lport: the associated local port |
| 262 | * @fp: the fc_frame to be transmitted |
| 263 | */ |
| 264 | static int bnx2fc_xmit(struct fc_lport *lport, struct fc_frame *fp) |
| 265 | { |
| 266 | struct ethhdr *eh; |
| 267 | struct fcoe_crc_eof *cp; |
| 268 | struct sk_buff *skb; |
| 269 | struct fc_frame_header *fh; |
Bhanu Prakash Gollapudi | aea71a0 | 2011-07-26 14:51:39 -0700 | [diff] [blame] | 270 | struct bnx2fc_interface *interface; |
Robert Love | fd8f890 | 2012-05-22 19:06:16 -0700 | [diff] [blame] | 271 | struct fcoe_ctlr *ctlr; |
Bhanu Prakash Gollapudi | aea71a0 | 2011-07-26 14:51:39 -0700 | [diff] [blame] | 272 | struct bnx2fc_hba *hba; |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 273 | struct fcoe_port *port; |
| 274 | struct fcoe_hdr *hp; |
| 275 | struct bnx2fc_rport *tgt; |
Vasu Dev | 1bd49b4 | 2012-05-25 10:26:43 -0700 | [diff] [blame] | 276 | struct fc_stats *stats; |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 277 | u8 sof, eof; |
| 278 | u32 crc; |
| 279 | unsigned int hlen, tlen, elen; |
| 280 | int wlen, rc = 0; |
| 281 | |
| 282 | port = (struct fcoe_port *)lport_priv(lport); |
Bhanu Prakash Gollapudi | aea71a0 | 2011-07-26 14:51:39 -0700 | [diff] [blame] | 283 | interface = port->priv; |
Robert Love | fd8f890 | 2012-05-22 19:06:16 -0700 | [diff] [blame] | 284 | ctlr = bnx2fc_to_ctlr(interface); |
Bhanu Prakash Gollapudi | aea71a0 | 2011-07-26 14:51:39 -0700 | [diff] [blame] | 285 | hba = interface->hba; |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 286 | |
| 287 | fh = fc_frame_header_get(fp); |
| 288 | |
| 289 | skb = fp_skb(fp); |
| 290 | if (!lport->link_up) { |
| 291 | BNX2FC_HBA_DBG(lport, "bnx2fc_xmit link down\n"); |
| 292 | kfree_skb(skb); |
| 293 | return 0; |
| 294 | } |
| 295 | |
| 296 | if (unlikely(fh->fh_r_ctl == FC_RCTL_ELS_REQ)) { |
Robert Love | fd8f890 | 2012-05-22 19:06:16 -0700 | [diff] [blame] | 297 | if (!ctlr->sel_fcf) { |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 298 | BNX2FC_HBA_DBG(lport, "FCF not selected yet!\n"); |
| 299 | kfree_skb(skb); |
| 300 | return -EINVAL; |
| 301 | } |
Robert Love | fd8f890 | 2012-05-22 19:06:16 -0700 | [diff] [blame] | 302 | if (fcoe_ctlr_els_send(ctlr, lport, skb)) |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 303 | return 0; |
| 304 | } |
| 305 | |
| 306 | sof = fr_sof(fp); |
| 307 | eof = fr_eof(fp); |
| 308 | |
| 309 | /* |
| 310 | * Snoop the frame header to check if the frame is for |
| 311 | * an offloaded session |
| 312 | */ |
| 313 | /* |
| 314 | * tgt_ofld_list access is synchronized using |
| 315 | * both hba mutex and hba lock. Atleast hba mutex or |
| 316 | * hba lock needs to be held for read access. |
| 317 | */ |
| 318 | |
| 319 | spin_lock_bh(&hba->hba_lock); |
| 320 | tgt = bnx2fc_tgt_lookup(port, ntoh24(fh->fh_d_id)); |
| 321 | if (tgt && (test_bit(BNX2FC_FLAG_SESSION_READY, &tgt->flags))) { |
| 322 | /* This frame is for offloaded session */ |
| 323 | BNX2FC_HBA_DBG(lport, "xmit: Frame is for offloaded session " |
| 324 | "port_id = 0x%x\n", ntoh24(fh->fh_d_id)); |
| 325 | spin_unlock_bh(&hba->hba_lock); |
| 326 | rc = bnx2fc_xmit_l2_frame(tgt, fp); |
| 327 | if (rc != -ENODEV) { |
| 328 | kfree_skb(skb); |
| 329 | return rc; |
| 330 | } |
| 331 | } else { |
| 332 | spin_unlock_bh(&hba->hba_lock); |
| 333 | } |
| 334 | |
| 335 | elen = sizeof(struct ethhdr); |
| 336 | hlen = sizeof(struct fcoe_hdr); |
| 337 | tlen = sizeof(struct fcoe_crc_eof); |
| 338 | wlen = (skb->len - tlen + sizeof(crc)) / FCOE_WORD_TO_BYTE; |
| 339 | |
| 340 | skb->ip_summed = CHECKSUM_NONE; |
| 341 | crc = fcoe_fc_crc(fp); |
| 342 | |
| 343 | /* copy port crc and eof to the skb buff */ |
| 344 | if (skb_is_nonlinear(skb)) { |
| 345 | skb_frag_t *frag; |
| 346 | if (bnx2fc_get_paged_crc_eof(skb, tlen)) { |
| 347 | kfree_skb(skb); |
| 348 | return -ENOMEM; |
| 349 | } |
| 350 | frag = &skb_shinfo(skb)->frags[skb_shinfo(skb)->nr_frags - 1]; |
Jonathan Lemon | b54c9d5 | 2019-07-30 07:40:33 -0700 | [diff] [blame] | 351 | cp = kmap_atomic(skb_frag_page(frag)) + skb_frag_off(frag); |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 352 | } else { |
Johannes Berg | 4df864c | 2017-06-16 14:29:21 +0200 | [diff] [blame] | 353 | cp = skb_put(skb, tlen); |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 354 | } |
| 355 | |
| 356 | memset(cp, 0, sizeof(*cp)); |
| 357 | cp->fcoe_eof = eof; |
| 358 | cp->fcoe_crc32 = cpu_to_le32(~crc); |
| 359 | if (skb_is_nonlinear(skb)) { |
Cong Wang | 77dfce0 | 2011-11-25 23:14:23 +0800 | [diff] [blame] | 360 | kunmap_atomic(cp); |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 361 | cp = NULL; |
| 362 | } |
| 363 | |
| 364 | /* adjust skb network/transport offsets to match mac/fcoe/port */ |
| 365 | skb_push(skb, elen + hlen); |
| 366 | skb_reset_mac_header(skb); |
| 367 | skb_reset_network_header(skb); |
| 368 | skb->mac_len = elen; |
| 369 | skb->protocol = htons(ETH_P_FCOE); |
Bhanu Prakash Gollapudi | aea71a0 | 2011-07-26 14:51:39 -0700 | [diff] [blame] | 370 | skb->dev = interface->netdev; |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 371 | |
| 372 | /* fill up mac and fcoe headers */ |
| 373 | eh = eth_hdr(skb); |
| 374 | eh->h_proto = htons(ETH_P_FCOE); |
Robert Love | fd8f890 | 2012-05-22 19:06:16 -0700 | [diff] [blame] | 375 | if (ctlr->map_dest) |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 376 | fc_fcoe_set_mac(eh->h_dest, fh->fh_d_id); |
| 377 | else |
| 378 | /* insert GW address */ |
Robert Love | fd8f890 | 2012-05-22 19:06:16 -0700 | [diff] [blame] | 379 | memcpy(eh->h_dest, ctlr->dest_addr, ETH_ALEN); |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 380 | |
Robert Love | fd8f890 | 2012-05-22 19:06:16 -0700 | [diff] [blame] | 381 | if (unlikely(ctlr->flogi_oxid != FC_XID_UNKNOWN)) |
| 382 | memcpy(eh->h_source, ctlr->ctl_src_addr, ETH_ALEN); |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 383 | else |
| 384 | memcpy(eh->h_source, port->data_src_addr, ETH_ALEN); |
| 385 | |
| 386 | hp = (struct fcoe_hdr *)(eh + 1); |
| 387 | memset(hp, 0, sizeof(*hp)); |
| 388 | if (FC_FCOE_VER) |
| 389 | FC_FCOE_ENCAPS_VER(hp, FC_FCOE_VER); |
| 390 | hp->fcoe_sof = sof; |
| 391 | |
| 392 | /* fcoe lso, mss is in max_payload which is non-zero for FCP data */ |
| 393 | if (lport->seq_offload && fr_max_payload(fp)) { |
| 394 | skb_shinfo(skb)->gso_type = SKB_GSO_FCOE; |
| 395 | skb_shinfo(skb)->gso_size = fr_max_payload(fp); |
| 396 | } else { |
| 397 | skb_shinfo(skb)->gso_type = 0; |
| 398 | skb_shinfo(skb)->gso_size = 0; |
| 399 | } |
| 400 | |
| 401 | /*update tx stats */ |
Vasu Dev | 1bd49b4 | 2012-05-25 10:26:43 -0700 | [diff] [blame] | 402 | stats = per_cpu_ptr(lport->stats, get_cpu()); |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 403 | stats->TxFrames++; |
| 404 | stats->TxWords += wlen; |
| 405 | put_cpu(); |
| 406 | |
| 407 | /* send down to lld */ |
| 408 | fr_dev(fp) = lport; |
| 409 | if (port->fcoe_pending_queue.qlen) |
| 410 | fcoe_check_wait_queue(lport, skb); |
| 411 | else if (fcoe_start_io(skb)) |
| 412 | fcoe_check_wait_queue(lport, skb); |
| 413 | |
| 414 | return 0; |
| 415 | } |
| 416 | |
| 417 | /** |
| 418 | * bnx2fc_rcv - This is bnx2fc's receive function called by NET_RX_SOFTIRQ |
| 419 | * |
| 420 | * @skb: the receive socket buffer |
| 421 | * @dev: associated net device |
| 422 | * @ptype: context |
| 423 | * @olddev: last device |
| 424 | * |
| 425 | * This function receives the packet and builds FC frame and passes it up |
| 426 | */ |
| 427 | static int bnx2fc_rcv(struct sk_buff *skb, struct net_device *dev, |
| 428 | struct packet_type *ptype, struct net_device *olddev) |
| 429 | { |
| 430 | struct fc_lport *lport; |
Bhanu Prakash Gollapudi | aea71a0 | 2011-07-26 14:51:39 -0700 | [diff] [blame] | 431 | struct bnx2fc_interface *interface; |
Robert Love | fd8f890 | 2012-05-22 19:06:16 -0700 | [diff] [blame] | 432 | struct fcoe_ctlr *ctlr; |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 433 | struct fcoe_rcv_info *fr; |
| 434 | struct fcoe_percpu_s *bg; |
Maurizio Lombardi | 01a4cc4 | 2014-11-20 11:17:33 +0100 | [diff] [blame] | 435 | struct sk_buff *tmp_skb; |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 436 | |
Bhanu Prakash Gollapudi | aea71a0 | 2011-07-26 14:51:39 -0700 | [diff] [blame] | 437 | interface = container_of(ptype, struct bnx2fc_interface, |
| 438 | fcoe_packet_type); |
Robert Love | fd8f890 | 2012-05-22 19:06:16 -0700 | [diff] [blame] | 439 | ctlr = bnx2fc_to_ctlr(interface); |
| 440 | lport = ctlr->lp; |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 441 | |
| 442 | if (unlikely(lport == NULL)) { |
Bhanu Prakash Gollapudi | b2a554f | 2011-06-27 23:30:53 -0700 | [diff] [blame] | 443 | printk(KERN_ERR PFX "bnx2fc_rcv: lport is NULL\n"); |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 444 | goto err; |
| 445 | } |
| 446 | |
Maurizio Lombardi | 01a4cc4 | 2014-11-20 11:17:33 +0100 | [diff] [blame] | 447 | tmp_skb = skb_share_check(skb, GFP_ATOMIC); |
| 448 | if (!tmp_skb) |
| 449 | goto err; |
| 450 | |
| 451 | skb = tmp_skb; |
| 452 | |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 453 | if (unlikely(eth_hdr(skb)->h_proto != htons(ETH_P_FCOE))) { |
Bhanu Prakash Gollapudi | b2a554f | 2011-06-27 23:30:53 -0700 | [diff] [blame] | 454 | printk(KERN_ERR PFX "bnx2fc_rcv: Wrong FC type frame\n"); |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 455 | goto err; |
| 456 | } |
| 457 | |
| 458 | /* |
| 459 | * Check for minimum frame length, and make sure required FCoE |
| 460 | * and FC headers are pulled into the linear data area. |
| 461 | */ |
| 462 | if (unlikely((skb->len < FCOE_MIN_FRAME) || |
| 463 | !pskb_may_pull(skb, FCOE_HEADER_LEN))) |
| 464 | goto err; |
| 465 | |
| 466 | skb_set_transport_header(skb, sizeof(struct fcoe_hdr)); |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 467 | |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 468 | fr = fcoe_dev_from_skb(skb); |
| 469 | fr->fr_dev = lport; |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 470 | |
| 471 | bg = &bnx2fc_global; |
Neil Horman | fc05ab7 | 2012-03-09 14:50:13 -0800 | [diff] [blame] | 472 | spin_lock(&bg->fcoe_rx_list.lock); |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 473 | |
| 474 | __skb_queue_tail(&bg->fcoe_rx_list, skb); |
| 475 | if (bg->fcoe_rx_list.qlen == 1) |
Sebastian Andrzej Siewior | 4b9bc86 | 2016-04-12 17:16:54 +0200 | [diff] [blame] | 476 | wake_up_process(bg->kthread); |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 477 | |
Neil Horman | fc05ab7 | 2012-03-09 14:50:13 -0800 | [diff] [blame] | 478 | spin_unlock(&bg->fcoe_rx_list.lock); |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 479 | |
| 480 | return 0; |
| 481 | err: |
| 482 | kfree_skb(skb); |
| 483 | return -1; |
| 484 | } |
| 485 | |
| 486 | static int bnx2fc_l2_rcv_thread(void *arg) |
| 487 | { |
| 488 | struct fcoe_percpu_s *bg = arg; |
| 489 | struct sk_buff *skb; |
| 490 | |
Dongsheng Yang | 8698a74 | 2014-03-11 18:09:12 +0800 | [diff] [blame] | 491 | set_user_nice(current, MIN_NICE); |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 492 | set_current_state(TASK_INTERRUPTIBLE); |
| 493 | while (!kthread_should_stop()) { |
| 494 | schedule(); |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 495 | spin_lock_bh(&bg->fcoe_rx_list.lock); |
| 496 | while ((skb = __skb_dequeue(&bg->fcoe_rx_list)) != NULL) { |
| 497 | spin_unlock_bh(&bg->fcoe_rx_list.lock); |
| 498 | bnx2fc_recv_frame(skb); |
| 499 | spin_lock_bh(&bg->fcoe_rx_list.lock); |
| 500 | } |
Bhanu Gollapudi | fee7871 | 2011-03-21 18:51:13 -0700 | [diff] [blame] | 501 | __set_current_state(TASK_INTERRUPTIBLE); |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 502 | spin_unlock_bh(&bg->fcoe_rx_list.lock); |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 503 | } |
Bhanu Gollapudi | fee7871 | 2011-03-21 18:51:13 -0700 | [diff] [blame] | 504 | __set_current_state(TASK_RUNNING); |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 505 | return 0; |
| 506 | } |
| 507 | |
| 508 | |
| 509 | static void bnx2fc_recv_frame(struct sk_buff *skb) |
| 510 | { |
John Meneghini | 936bd03 | 2022-01-24 09:51:10 -0500 | [diff] [blame] | 511 | u64 crc_err; |
| 512 | u32 fr_len, fr_crc; |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 513 | struct fc_lport *lport; |
| 514 | struct fcoe_rcv_info *fr; |
Vasu Dev | 1bd49b4 | 2012-05-25 10:26:43 -0700 | [diff] [blame] | 515 | struct fc_stats *stats; |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 516 | struct fc_frame_header *fh; |
| 517 | struct fcoe_crc_eof crc_eof; |
| 518 | struct fc_frame *fp; |
| 519 | struct fc_lport *vn_port; |
Chad Dupuis | 56ffd3a | 2017-06-26 08:59:32 -0700 | [diff] [blame] | 520 | struct fcoe_port *port, *phys_port; |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 521 | u8 *mac = NULL; |
| 522 | u8 *dest_mac = NULL; |
| 523 | struct fcoe_hdr *hp; |
Chad Dupuis | 56ffd3a | 2017-06-26 08:59:32 -0700 | [diff] [blame] | 524 | struct bnx2fc_interface *interface; |
| 525 | struct fcoe_ctlr *ctlr; |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 526 | |
| 527 | fr = fcoe_dev_from_skb(skb); |
| 528 | lport = fr->fr_dev; |
| 529 | if (unlikely(lport == NULL)) { |
Bhanu Prakash Gollapudi | b2a554f | 2011-06-27 23:30:53 -0700 | [diff] [blame] | 530 | printk(KERN_ERR PFX "Invalid lport struct\n"); |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 531 | kfree_skb(skb); |
| 532 | return; |
| 533 | } |
| 534 | |
| 535 | if (skb_is_nonlinear(skb)) |
| 536 | skb_linearize(skb); |
| 537 | mac = eth_hdr(skb)->h_source; |
| 538 | dest_mac = eth_hdr(skb)->h_dest; |
| 539 | |
| 540 | /* Pull the header */ |
| 541 | hp = (struct fcoe_hdr *) skb_network_header(skb); |
| 542 | fh = (struct fc_frame_header *) skb_transport_header(skb); |
| 543 | skb_pull(skb, sizeof(struct fcoe_hdr)); |
| 544 | fr_len = skb->len - sizeof(struct fcoe_crc_eof); |
| 545 | |
John Meneghini | 936bd03 | 2022-01-24 09:51:10 -0500 | [diff] [blame] | 546 | stats = per_cpu_ptr(lport->stats, get_cpu()); |
| 547 | stats->RxFrames++; |
| 548 | stats->RxWords += fr_len / FCOE_WORD_TO_BYTE; |
| 549 | put_cpu(); |
| 550 | |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 551 | fp = (struct fc_frame *)skb; |
| 552 | fc_frame_init(fp); |
| 553 | fr_dev(fp) = lport; |
| 554 | fr_sof(fp) = hp->fcoe_sof; |
| 555 | if (skb_copy_bits(skb, fr_len, &crc_eof, sizeof(crc_eof))) { |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 556 | kfree_skb(skb); |
| 557 | return; |
| 558 | } |
| 559 | fr_eof(fp) = crc_eof.fcoe_eof; |
| 560 | fr_crc(fp) = crc_eof.fcoe_crc32; |
| 561 | if (pskb_trim(skb, fr_len)) { |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 562 | kfree_skb(skb); |
| 563 | return; |
| 564 | } |
| 565 | |
Chad Dupuis | 56ffd3a | 2017-06-26 08:59:32 -0700 | [diff] [blame] | 566 | phys_port = lport_priv(lport); |
| 567 | interface = phys_port->priv; |
| 568 | ctlr = bnx2fc_to_ctlr(interface); |
| 569 | |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 570 | fh = fc_frame_header_get(fp); |
| 571 | |
Chad Dupuis | 56ffd3a | 2017-06-26 08:59:32 -0700 | [diff] [blame] | 572 | if (ntoh24(&dest_mac[3]) != ntoh24(fh->fh_d_id)) { |
| 573 | BNX2FC_HBA_DBG(lport, "FC frame d_id mismatch with MAC %pM.\n", |
| 574 | dest_mac); |
| 575 | kfree_skb(skb); |
| 576 | return; |
| 577 | } |
| 578 | |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 579 | vn_port = fc_vport_id_lookup(lport, ntoh24(fh->fh_d_id)); |
| 580 | if (vn_port) { |
| 581 | port = lport_priv(vn_port); |
Joe Perches | 6942df7 | 2013-09-02 03:32:33 +0000 | [diff] [blame] | 582 | if (!ether_addr_equal(port->data_src_addr, dest_mac)) { |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 583 | BNX2FC_HBA_DBG(lport, "fpma mismatch\n"); |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 584 | kfree_skb(skb); |
| 585 | return; |
| 586 | } |
| 587 | } |
Chad Dupuis | 56ffd3a | 2017-06-26 08:59:32 -0700 | [diff] [blame] | 588 | if (ctlr->state) { |
| 589 | if (!ether_addr_equal(mac, ctlr->dest_addr)) { |
| 590 | BNX2FC_HBA_DBG(lport, "Wrong source address: mac:%pM dest_addr:%pM.\n", |
| 591 | mac, ctlr->dest_addr); |
| 592 | kfree_skb(skb); |
| 593 | return; |
| 594 | } |
| 595 | } |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 596 | if (fh->fh_r_ctl == FC_RCTL_DD_SOL_DATA && |
| 597 | fh->fh_type == FC_TYPE_FCP) { |
| 598 | /* Drop FCP data. We dont this in L2 path */ |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 599 | kfree_skb(skb); |
| 600 | return; |
| 601 | } |
| 602 | if (fh->fh_r_ctl == FC_RCTL_ELS_REQ && |
| 603 | fh->fh_type == FC_TYPE_ELS) { |
| 604 | switch (fc_frame_payload_op(fp)) { |
| 605 | case ELS_LOGO: |
| 606 | if (ntoh24(fh->fh_s_id) == FC_FID_FLOGI) { |
| 607 | /* drop non-FIP LOGO */ |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 608 | kfree_skb(skb); |
| 609 | return; |
| 610 | } |
| 611 | break; |
| 612 | } |
| 613 | } |
Bhanu Prakash Gollapudi | 3f8744d | 2011-08-04 17:38:48 -0700 | [diff] [blame] | 614 | |
| 615 | if (fh->fh_r_ctl == FC_RCTL_BA_ABTS) { |
| 616 | /* Drop incoming ABTS */ |
Bhanu Prakash Gollapudi | 3f8744d | 2011-08-04 17:38:48 -0700 | [diff] [blame] | 617 | kfree_skb(skb); |
| 618 | return; |
| 619 | } |
| 620 | |
Chad Dupuis | 56ffd3a | 2017-06-26 08:59:32 -0700 | [diff] [blame] | 621 | /* |
| 622 | * If the destination ID from the frame header does not match what we |
| 623 | * have on record for lport and the search for a NPIV port came up |
| 624 | * empty then this is not addressed to our port so simply drop it. |
| 625 | */ |
| 626 | if (lport->port_id != ntoh24(fh->fh_d_id) && !vn_port) { |
| 627 | BNX2FC_HBA_DBG(lport, "Dropping frame due to destination mismatch: lport->port_id=%x fh->d_id=%x.\n", |
| 628 | lport->port_id, ntoh24(fh->fh_d_id)); |
| 629 | kfree_skb(skb); |
| 630 | return; |
| 631 | } |
| 632 | |
John Meneghini | 936bd03 | 2022-01-24 09:51:10 -0500 | [diff] [blame] | 633 | fr_crc = le32_to_cpu(fr_crc(fp)); |
Neil Horman | d576a5e | 2014-06-23 10:41:02 -0400 | [diff] [blame] | 634 | |
John Meneghini | 936bd03 | 2022-01-24 09:51:10 -0500 | [diff] [blame] | 635 | if (unlikely(fr_crc != ~crc32(~0, skb->data, fr_len))) { |
| 636 | stats = per_cpu_ptr(lport->stats, get_cpu()); |
| 637 | crc_err = (stats->InvalidCRCCount++); |
| 638 | put_cpu(); |
| 639 | if (crc_err < 5) |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 640 | printk(KERN_WARNING PFX "dropping frame with " |
| 641 | "CRC error\n"); |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 642 | kfree_skb(skb); |
| 643 | return; |
| 644 | } |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 645 | fc_exch_recv(lport, fp); |
| 646 | } |
| 647 | |
| 648 | /** |
| 649 | * bnx2fc_percpu_io_thread - thread per cpu for ios |
| 650 | * |
| 651 | * @arg: ptr to bnx2fc_percpu_info structure |
| 652 | */ |
Baoyou Xie | 3f7d67d | 2016-09-04 14:52:21 +0800 | [diff] [blame] | 653 | static int bnx2fc_percpu_io_thread(void *arg) |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 654 | { |
| 655 | struct bnx2fc_percpu_s *p = arg; |
| 656 | struct bnx2fc_work *work, *tmp; |
| 657 | LIST_HEAD(work_list); |
| 658 | |
Dongsheng Yang | 8698a74 | 2014-03-11 18:09:12 +0800 | [diff] [blame] | 659 | set_user_nice(current, MIN_NICE); |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 660 | set_current_state(TASK_INTERRUPTIBLE); |
| 661 | while (!kthread_should_stop()) { |
| 662 | schedule(); |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 663 | spin_lock_bh(&p->fp_work_lock); |
| 664 | while (!list_empty(&p->work_list)) { |
| 665 | list_splice_init(&p->work_list, &work_list); |
| 666 | spin_unlock_bh(&p->fp_work_lock); |
| 667 | |
| 668 | list_for_each_entry_safe(work, tmp, &work_list, list) { |
| 669 | list_del_init(&work->list); |
Javed Hasan | 7733111 | 2020-03-26 22:48:47 -0700 | [diff] [blame] | 670 | bnx2fc_process_cq_compl(work->tgt, work->wqe, |
| 671 | work->rq_data, |
| 672 | work->num_rq, |
| 673 | work->task); |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 674 | kfree(work); |
| 675 | } |
| 676 | |
| 677 | spin_lock_bh(&p->fp_work_lock); |
| 678 | } |
Bhanu Gollapudi | fee7871 | 2011-03-21 18:51:13 -0700 | [diff] [blame] | 679 | __set_current_state(TASK_INTERRUPTIBLE); |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 680 | spin_unlock_bh(&p->fp_work_lock); |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 681 | } |
Bhanu Gollapudi | fee7871 | 2011-03-21 18:51:13 -0700 | [diff] [blame] | 682 | __set_current_state(TASK_RUNNING); |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 683 | |
| 684 | return 0; |
| 685 | } |
| 686 | |
| 687 | static struct fc_host_statistics *bnx2fc_get_host_stats(struct Scsi_Host *shost) |
| 688 | { |
| 689 | struct fc_host_statistics *bnx2fc_stats; |
| 690 | struct fc_lport *lport = shost_priv(shost); |
| 691 | struct fcoe_port *port = lport_priv(lport); |
Bhanu Prakash Gollapudi | aea71a0 | 2011-07-26 14:51:39 -0700 | [diff] [blame] | 692 | struct bnx2fc_interface *interface = port->priv; |
| 693 | struct bnx2fc_hba *hba = interface->hba; |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 694 | struct fcoe_statistics_params *fw_stats; |
| 695 | int rc = 0; |
| 696 | |
| 697 | fw_stats = (struct fcoe_statistics_params *)hba->stats_buffer; |
| 698 | if (!fw_stats) |
| 699 | return NULL; |
| 700 | |
Maurizio Lombardi | c2dd893 | 2017-05-24 14:09:44 +0200 | [diff] [blame] | 701 | mutex_lock(&hba->hba_stats_mutex); |
| 702 | |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 703 | bnx2fc_stats = fc_get_host_stats(shost); |
| 704 | |
| 705 | init_completion(&hba->stat_req_done); |
| 706 | if (bnx2fc_send_stat_req(hba)) |
Maurizio Lombardi | c2dd893 | 2017-05-24 14:09:44 +0200 | [diff] [blame] | 707 | goto unlock_stats_mutex; |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 708 | rc = wait_for_completion_timeout(&hba->stat_req_done, (2 * HZ)); |
| 709 | if (!rc) { |
| 710 | BNX2FC_HBA_DBG(lport, "FW stat req timed out\n"); |
Maurizio Lombardi | c2dd893 | 2017-05-24 14:09:44 +0200 | [diff] [blame] | 711 | goto unlock_stats_mutex; |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 712 | } |
Bhanu Prakash Gollapudi | f246fe2 | 2012-12-21 19:40:32 -0800 | [diff] [blame] | 713 | BNX2FC_STATS(hba, rx_stat2, fc_crc_cnt); |
| 714 | bnx2fc_stats->invalid_crc_count += hba->bfw_stats.fc_crc_cnt; |
| 715 | BNX2FC_STATS(hba, tx_stat, fcoe_tx_pkt_cnt); |
| 716 | bnx2fc_stats->tx_frames += hba->bfw_stats.fcoe_tx_pkt_cnt; |
| 717 | BNX2FC_STATS(hba, tx_stat, fcoe_tx_byte_cnt); |
| 718 | bnx2fc_stats->tx_words += ((hba->bfw_stats.fcoe_tx_byte_cnt) / 4); |
| 719 | BNX2FC_STATS(hba, rx_stat0, fcoe_rx_pkt_cnt); |
| 720 | bnx2fc_stats->rx_frames += hba->bfw_stats.fcoe_rx_pkt_cnt; |
| 721 | BNX2FC_STATS(hba, rx_stat0, fcoe_rx_byte_cnt); |
| 722 | bnx2fc_stats->rx_words += ((hba->bfw_stats.fcoe_rx_byte_cnt) / 4); |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 723 | |
| 724 | bnx2fc_stats->dumped_frames = 0; |
| 725 | bnx2fc_stats->lip_count = 0; |
| 726 | bnx2fc_stats->nos_count = 0; |
| 727 | bnx2fc_stats->loss_of_sync_count = 0; |
| 728 | bnx2fc_stats->loss_of_signal_count = 0; |
| 729 | bnx2fc_stats->prim_seq_protocol_err_count = 0; |
| 730 | |
Bhanu Prakash Gollapudi | f246fe2 | 2012-12-21 19:40:32 -0800 | [diff] [blame] | 731 | memcpy(&hba->prev_stats, hba->stats_buffer, |
| 732 | sizeof(struct fcoe_statistics_params)); |
Maurizio Lombardi | c2dd893 | 2017-05-24 14:09:44 +0200 | [diff] [blame] | 733 | |
| 734 | unlock_stats_mutex: |
| 735 | mutex_unlock(&hba->hba_stats_mutex); |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 736 | return bnx2fc_stats; |
| 737 | } |
| 738 | |
| 739 | static int bnx2fc_shost_config(struct fc_lport *lport, struct device *dev) |
| 740 | { |
| 741 | struct fcoe_port *port = lport_priv(lport); |
Bhanu Prakash Gollapudi | aea71a0 | 2011-07-26 14:51:39 -0700 | [diff] [blame] | 742 | struct bnx2fc_interface *interface = port->priv; |
Bhanu Prakash Gollapudi | c13d2b6 | 2013-03-08 13:28:51 -0800 | [diff] [blame] | 743 | struct bnx2fc_hba *hba = interface->hba; |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 744 | struct Scsi_Host *shost = lport->host; |
| 745 | int rc = 0; |
| 746 | |
| 747 | shost->max_cmd_len = BNX2FC_MAX_CMD_LEN; |
Joe Carnuccio | 10755d3 | 2016-04-07 09:07:56 -0400 | [diff] [blame] | 748 | shost->max_lun = bnx2fc_max_luns; |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 749 | shost->max_id = BNX2FC_MAX_FCP_TGT; |
| 750 | shost->max_channel = 0; |
| 751 | if (lport->vport) |
| 752 | shost->transportt = bnx2fc_vport_xport_template; |
| 753 | else |
| 754 | shost->transportt = bnx2fc_transport_template; |
| 755 | |
| 756 | /* Add the new host to SCSI-ml */ |
| 757 | rc = scsi_add_host(lport->host, dev); |
| 758 | if (rc) { |
| 759 | printk(KERN_ERR PFX "Error on scsi_add_host\n"); |
| 760 | return rc; |
| 761 | } |
| 762 | if (!lport->vport) |
| 763 | fc_host_max_npiv_vports(lport->host) = USHRT_MAX; |
Bhanu Prakash Gollapudi | c13d2b6 | 2013-03-08 13:28:51 -0800 | [diff] [blame] | 764 | snprintf(fc_host_symbolic_name(lport->host), 256, |
Saurav Kashyap | 17d87c4 | 2014-07-03 08:18:28 -0400 | [diff] [blame] | 765 | "%s (QLogic %s) v%s over %s", |
Bhanu Prakash Gollapudi | c13d2b6 | 2013-03-08 13:28:51 -0800 | [diff] [blame] | 766 | BNX2FC_NAME, hba->chip_num, BNX2FC_VERSION, |
Bhanu Prakash Gollapudi | aea71a0 | 2011-07-26 14:51:39 -0700 | [diff] [blame] | 767 | interface->netdev->name); |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 768 | |
| 769 | return 0; |
| 770 | } |
| 771 | |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 772 | static int bnx2fc_link_ok(struct fc_lport *lport) |
| 773 | { |
| 774 | struct fcoe_port *port = lport_priv(lport); |
Bhanu Prakash Gollapudi | aea71a0 | 2011-07-26 14:51:39 -0700 | [diff] [blame] | 775 | struct bnx2fc_interface *interface = port->priv; |
| 776 | struct bnx2fc_hba *hba = interface->hba; |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 777 | struct net_device *dev = hba->phys_dev; |
| 778 | int rc = 0; |
| 779 | |
| 780 | if ((dev->flags & IFF_UP) && netif_carrier_ok(dev)) |
| 781 | clear_bit(ADAPTER_STATE_LINK_DOWN, &hba->adapter_state); |
| 782 | else { |
| 783 | set_bit(ADAPTER_STATE_LINK_DOWN, &hba->adapter_state); |
| 784 | rc = -1; |
| 785 | } |
| 786 | return rc; |
| 787 | } |
| 788 | |
| 789 | /** |
| 790 | * bnx2fc_get_link_state - get network link state |
| 791 | * |
| 792 | * @hba: adapter instance pointer |
| 793 | * |
| 794 | * updates adapter structure flag based on netdev state |
| 795 | */ |
| 796 | void bnx2fc_get_link_state(struct bnx2fc_hba *hba) |
| 797 | { |
Bhanu Prakash Gollapudi | aea71a0 | 2011-07-26 14:51:39 -0700 | [diff] [blame] | 798 | if (test_bit(__LINK_STATE_NOCARRIER, &hba->phys_dev->state)) |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 799 | set_bit(ADAPTER_STATE_LINK_DOWN, &hba->adapter_state); |
| 800 | else |
| 801 | clear_bit(ADAPTER_STATE_LINK_DOWN, &hba->adapter_state); |
| 802 | } |
| 803 | |
Bhanu Prakash Gollapudi | 5243960 | 2011-08-04 17:38:50 -0700 | [diff] [blame] | 804 | static int bnx2fc_net_config(struct fc_lport *lport, struct net_device *netdev) |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 805 | { |
| 806 | struct bnx2fc_hba *hba; |
Bhanu Prakash Gollapudi | aea71a0 | 2011-07-26 14:51:39 -0700 | [diff] [blame] | 807 | struct bnx2fc_interface *interface; |
Robert Love | fd8f890 | 2012-05-22 19:06:16 -0700 | [diff] [blame] | 808 | struct fcoe_ctlr *ctlr; |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 809 | struct fcoe_port *port; |
| 810 | u64 wwnn, wwpn; |
| 811 | |
| 812 | port = lport_priv(lport); |
Bhanu Prakash Gollapudi | aea71a0 | 2011-07-26 14:51:39 -0700 | [diff] [blame] | 813 | interface = port->priv; |
Robert Love | fd8f890 | 2012-05-22 19:06:16 -0700 | [diff] [blame] | 814 | ctlr = bnx2fc_to_ctlr(interface); |
Bhanu Prakash Gollapudi | aea71a0 | 2011-07-26 14:51:39 -0700 | [diff] [blame] | 815 | hba = interface->hba; |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 816 | |
| 817 | /* require support for get_pauseparam ethtool op. */ |
| 818 | if (!hba->phys_dev->ethtool_ops || |
| 819 | !hba->phys_dev->ethtool_ops->get_pauseparam) |
| 820 | return -EOPNOTSUPP; |
| 821 | |
Bhanu Gollapudi | 1294bfe | 2011-03-17 17:13:34 -0700 | [diff] [blame] | 822 | if (fc_set_mfs(lport, BNX2FC_MFS)) |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 823 | return -EINVAL; |
| 824 | |
| 825 | skb_queue_head_init(&port->fcoe_pending_queue); |
| 826 | port->fcoe_pending_queue_active = 0; |
Kees Cook | 1305910 | 2017-09-21 13:12:15 -0700 | [diff] [blame] | 827 | timer_setup(&port->timer, fcoe_queue_timer, 0); |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 828 | |
Yi Zou | 0e0f9cd | 2012-12-06 06:24:44 +0000 | [diff] [blame] | 829 | fcoe_link_speed_update(lport); |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 830 | |
| 831 | if (!lport->vport) { |
Bhanu Prakash Gollapudi | 5243960 | 2011-08-04 17:38:50 -0700 | [diff] [blame] | 832 | if (fcoe_get_wwn(netdev, &wwnn, NETDEV_FCOE_WWNN)) |
Robert Love | fd8f890 | 2012-05-22 19:06:16 -0700 | [diff] [blame] | 833 | wwnn = fcoe_wwn_from_mac(ctlr->ctl_src_addr, |
Bhanu Prakash Gollapudi | 5243960 | 2011-08-04 17:38:50 -0700 | [diff] [blame] | 834 | 1, 0); |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 835 | BNX2FC_HBA_DBG(lport, "WWNN = 0x%llx\n", wwnn); |
| 836 | fc_set_wwnn(lport, wwnn); |
| 837 | |
Bhanu Prakash Gollapudi | 5243960 | 2011-08-04 17:38:50 -0700 | [diff] [blame] | 838 | if (fcoe_get_wwn(netdev, &wwpn, NETDEV_FCOE_WWPN)) |
Robert Love | fd8f890 | 2012-05-22 19:06:16 -0700 | [diff] [blame] | 839 | wwpn = fcoe_wwn_from_mac(ctlr->ctl_src_addr, |
Bhanu Prakash Gollapudi | 5243960 | 2011-08-04 17:38:50 -0700 | [diff] [blame] | 840 | 2, 0); |
| 841 | |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 842 | BNX2FC_HBA_DBG(lport, "WWPN = 0x%llx\n", wwpn); |
| 843 | fc_set_wwpn(lport, wwpn); |
| 844 | } |
| 845 | |
| 846 | return 0; |
| 847 | } |
| 848 | |
Kees Cook | 1305910 | 2017-09-21 13:12:15 -0700 | [diff] [blame] | 849 | static void bnx2fc_destroy_timer(struct timer_list *t) |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 850 | { |
Kees Cook | 1305910 | 2017-09-21 13:12:15 -0700 | [diff] [blame] | 851 | struct bnx2fc_hba *hba = from_timer(hba, t, destroy_timer); |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 852 | |
Bhanu Prakash Gollapudi | cd703ae | 2011-08-04 17:38:43 -0700 | [diff] [blame] | 853 | printk(KERN_ERR PFX "ERROR:bnx2fc_destroy_timer - " |
| 854 | "Destroy compl not received!!\n"); |
Bhanu Prakash Gollapudi | aea71a0 | 2011-07-26 14:51:39 -0700 | [diff] [blame] | 855 | set_bit(BNX2FC_FLAG_DESTROY_CMPL, &hba->flags); |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 856 | wake_up_interruptible(&hba->destroy_wait); |
| 857 | } |
| 858 | |
| 859 | /** |
| 860 | * bnx2fc_indicate_netevent - Generic netdev event handler |
| 861 | * |
| 862 | * @context: adapter structure pointer |
| 863 | * @event: event type |
Michael Chan | 415199f | 2011-07-20 14:55:24 +0000 | [diff] [blame] | 864 | * @vlan_id: vlan id - associated vlan id with this event |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 865 | * |
| 866 | * Handles NETDEV_UP, NETDEV_DOWN, NETDEV_GOING_DOWN,NETDEV_CHANGE and |
Bhanu Prakash Gollapudi | abc49a9 | 2011-08-04 17:38:42 -0700 | [diff] [blame] | 867 | * NETDEV_CHANGE_MTU events. Handle NETDEV_UNREGISTER only for vlans. |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 868 | */ |
Michael Chan | 415199f | 2011-07-20 14:55:24 +0000 | [diff] [blame] | 869 | static void bnx2fc_indicate_netevent(void *context, unsigned long event, |
| 870 | u16 vlan_id) |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 871 | { |
| 872 | struct bnx2fc_hba *hba = (struct bnx2fc_hba *)context; |
Robert Love | 6e89ea3 | 2012-11-27 06:53:40 +0000 | [diff] [blame] | 873 | struct fcoe_ctlr_device *cdev; |
Bhanu Prakash Gollapudi | aea71a0 | 2011-07-26 14:51:39 -0700 | [diff] [blame] | 874 | struct fc_lport *lport; |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 875 | struct fc_lport *vport; |
Bhanu Prakash Gollapudi | abc49a9 | 2011-08-04 17:38:42 -0700 | [diff] [blame] | 876 | struct bnx2fc_interface *interface, *tmp; |
Robert Love | fd8f890 | 2012-05-22 19:06:16 -0700 | [diff] [blame] | 877 | struct fcoe_ctlr *ctlr; |
Bhanu Prakash Gollapudi | aea71a0 | 2011-07-26 14:51:39 -0700 | [diff] [blame] | 878 | int wait_for_upload = 0; |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 879 | u32 link_possible = 1; |
| 880 | |
Bhanu Prakash Gollapudi | abc49a9 | 2011-08-04 17:38:42 -0700 | [diff] [blame] | 881 | if (vlan_id != 0 && event != NETDEV_UNREGISTER) |
Michael Chan | 415199f | 2011-07-20 14:55:24 +0000 | [diff] [blame] | 882 | return; |
| 883 | |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 884 | switch (event) { |
| 885 | case NETDEV_UP: |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 886 | if (!test_bit(ADAPTER_STATE_UP, &hba->adapter_state)) |
| 887 | printk(KERN_ERR "indicate_netevent: "\ |
Bhanu Prakash Gollapudi | aea71a0 | 2011-07-26 14:51:39 -0700 | [diff] [blame] | 888 | "hba is not UP!!\n"); |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 889 | break; |
| 890 | |
| 891 | case NETDEV_DOWN: |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 892 | clear_bit(ADAPTER_STATE_GOING_DOWN, &hba->adapter_state); |
| 893 | clear_bit(ADAPTER_STATE_UP, &hba->adapter_state); |
| 894 | link_possible = 0; |
| 895 | break; |
| 896 | |
| 897 | case NETDEV_GOING_DOWN: |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 898 | set_bit(ADAPTER_STATE_GOING_DOWN, &hba->adapter_state); |
| 899 | link_possible = 0; |
| 900 | break; |
| 901 | |
| 902 | case NETDEV_CHANGE: |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 903 | break; |
| 904 | |
Bhanu Prakash Gollapudi | abc49a9 | 2011-08-04 17:38:42 -0700 | [diff] [blame] | 905 | case NETDEV_UNREGISTER: |
| 906 | if (!vlan_id) |
| 907 | return; |
| 908 | mutex_lock(&bnx2fc_dev_lock); |
| 909 | list_for_each_entry_safe(interface, tmp, &if_list, list) { |
Nithin Nayak Sujir | 26b2982 | 2011-08-30 15:54:50 -0700 | [diff] [blame] | 910 | if (interface->hba == hba && |
| 911 | interface->vlan_id == (vlan_id & VLAN_VID_MASK)) |
| 912 | __bnx2fc_destroy(interface); |
Bhanu Prakash Gollapudi | abc49a9 | 2011-08-04 17:38:42 -0700 | [diff] [blame] | 913 | } |
| 914 | mutex_unlock(&bnx2fc_dev_lock); |
| 915 | return; |
| 916 | |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 917 | default: |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 918 | return; |
| 919 | } |
| 920 | |
Bhanu Prakash Gollapudi | aea71a0 | 2011-07-26 14:51:39 -0700 | [diff] [blame] | 921 | mutex_lock(&bnx2fc_dev_lock); |
| 922 | list_for_each_entry(interface, &if_list, list) { |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 923 | |
Bhanu Prakash Gollapudi | aea71a0 | 2011-07-26 14:51:39 -0700 | [diff] [blame] | 924 | if (interface->hba != hba) |
| 925 | continue; |
| 926 | |
Robert Love | fd8f890 | 2012-05-22 19:06:16 -0700 | [diff] [blame] | 927 | ctlr = bnx2fc_to_ctlr(interface); |
| 928 | lport = ctlr->lp; |
Bhanu Prakash Gollapudi | aea71a0 | 2011-07-26 14:51:39 -0700 | [diff] [blame] | 929 | BNX2FC_HBA_DBG(lport, "netevent handler - event=%s %ld\n", |
| 930 | interface->netdev->name, event); |
| 931 | |
Yi Zou | 0e0f9cd | 2012-12-06 06:24:44 +0000 | [diff] [blame] | 932 | fcoe_link_speed_update(lport); |
Bhanu Prakash Gollapudi | aea71a0 | 2011-07-26 14:51:39 -0700 | [diff] [blame] | 933 | |
Robert Love | 6e89ea3 | 2012-11-27 06:53:40 +0000 | [diff] [blame] | 934 | cdev = fcoe_ctlr_to_ctlr_dev(ctlr); |
Bhanu Prakash Gollapudi | aea71a0 | 2011-07-26 14:51:39 -0700 | [diff] [blame] | 935 | |
| 936 | if (link_possible && !bnx2fc_link_ok(lport)) { |
Robert Love | 6e89ea3 | 2012-11-27 06:53:40 +0000 | [diff] [blame] | 937 | switch (cdev->enabled) { |
| 938 | case FCOE_CTLR_DISABLED: |
| 939 | pr_info("Link up while interface is disabled.\n"); |
| 940 | break; |
| 941 | case FCOE_CTLR_ENABLED: |
| 942 | case FCOE_CTLR_UNUSED: |
| 943 | /* Reset max recv frame size to default */ |
| 944 | fc_set_mfs(lport, BNX2FC_MFS); |
| 945 | /* |
| 946 | * ctlr link up will only be handled during |
| 947 | * enable to avoid sending discovery |
| 948 | * solicitation on a stale vlan |
| 949 | */ |
| 950 | if (interface->enabled) |
| 951 | fcoe_ctlr_link_up(ctlr); |
Jason Yan | acfcb72 | 2020-04-21 11:40:19 +0800 | [diff] [blame] | 952 | } |
Robert Love | fd8f890 | 2012-05-22 19:06:16 -0700 | [diff] [blame] | 953 | } else if (fcoe_ctlr_link_down(ctlr)) { |
Robert Love | 6e89ea3 | 2012-11-27 06:53:40 +0000 | [diff] [blame] | 954 | switch (cdev->enabled) { |
| 955 | case FCOE_CTLR_DISABLED: |
| 956 | pr_info("Link down while interface is disabled.\n"); |
| 957 | break; |
| 958 | case FCOE_CTLR_ENABLED: |
| 959 | case FCOE_CTLR_UNUSED: |
| 960 | mutex_lock(&lport->lp_mutex); |
| 961 | list_for_each_entry(vport, &lport->vports, list) |
| 962 | fc_host_port_type(vport->host) = |
| 963 | FC_PORTTYPE_UNKNOWN; |
| 964 | mutex_unlock(&lport->lp_mutex); |
| 965 | fc_host_port_type(lport->host) = |
| 966 | FC_PORTTYPE_UNKNOWN; |
| 967 | per_cpu_ptr(lport->stats, |
| 968 | get_cpu())->LinkFailureCount++; |
| 969 | put_cpu(); |
| 970 | fcoe_clean_pending_queue(lport); |
| 971 | wait_for_upload = 1; |
Jason Yan | acfcb72 | 2020-04-21 11:40:19 +0800 | [diff] [blame] | 972 | } |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 973 | } |
| 974 | } |
Bhanu Prakash Gollapudi | aea71a0 | 2011-07-26 14:51:39 -0700 | [diff] [blame] | 975 | mutex_unlock(&bnx2fc_dev_lock); |
| 976 | |
| 977 | if (wait_for_upload) { |
| 978 | clear_bit(ADAPTER_STATE_READY, &hba->adapter_state); |
| 979 | init_waitqueue_head(&hba->shutdown_wait); |
| 980 | BNX2FC_MISC_DBG("indicate_netevent " |
| 981 | "num_ofld_sess = %d\n", |
| 982 | hba->num_ofld_sess); |
| 983 | hba->wait_for_link_down = 1; |
| 984 | wait_event_interruptible(hba->shutdown_wait, |
| 985 | (hba->num_ofld_sess == 0)); |
| 986 | BNX2FC_MISC_DBG("wakeup - num_ofld_sess = %d\n", |
| 987 | hba->num_ofld_sess); |
| 988 | hba->wait_for_link_down = 0; |
| 989 | |
| 990 | if (signal_pending(current)) |
| 991 | flush_signals(current); |
| 992 | } |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 993 | } |
| 994 | |
| 995 | static int bnx2fc_libfc_config(struct fc_lport *lport) |
| 996 | { |
| 997 | |
| 998 | /* Set the function pointers set by bnx2fc driver */ |
| 999 | memcpy(&lport->tt, &bnx2fc_libfc_fcn_templ, |
| 1000 | sizeof(struct libfc_function_template)); |
| 1001 | fc_elsct_init(lport); |
| 1002 | fc_exch_init(lport); |
Robert Love | 0807619 | 2013-03-25 11:00:28 -0700 | [diff] [blame] | 1003 | fc_disc_init(lport); |
| 1004 | fc_disc_config(lport, lport); |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 1005 | return 0; |
| 1006 | } |
| 1007 | |
Bhanu Prakash Gollapudi | 0eb43b4 | 2013-04-22 19:22:30 +0000 | [diff] [blame] | 1008 | static int bnx2fc_em_config(struct fc_lport *lport, struct bnx2fc_hba *hba) |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 1009 | { |
Bhanu Prakash Gollapudi | 0eb43b4 | 2013-04-22 19:22:30 +0000 | [diff] [blame] | 1010 | int fcoe_min_xid, fcoe_max_xid; |
Bhanu Prakash Gollapudi | 7d742f6 | 2012-01-23 18:00:48 -0800 | [diff] [blame] | 1011 | |
Bhanu Prakash Gollapudi | 0eb43b4 | 2013-04-22 19:22:30 +0000 | [diff] [blame] | 1012 | fcoe_min_xid = hba->max_xid + 1; |
Bhanu Prakash Gollapudi | 7d742f6 | 2012-01-23 18:00:48 -0800 | [diff] [blame] | 1013 | if (nr_cpu_ids <= 2) |
Bhanu Prakash Gollapudi | 0eb43b4 | 2013-04-22 19:22:30 +0000 | [diff] [blame] | 1014 | fcoe_max_xid = hba->max_xid + FCOE_XIDS_PER_CPU_OFFSET; |
Bhanu Prakash Gollapudi | 7d742f6 | 2012-01-23 18:00:48 -0800 | [diff] [blame] | 1015 | else |
Bhanu Prakash Gollapudi | 0eb43b4 | 2013-04-22 19:22:30 +0000 | [diff] [blame] | 1016 | fcoe_max_xid = hba->max_xid + FCOE_MAX_XID_OFFSET; |
| 1017 | if (!fc_exch_mgr_alloc(lport, FC_CLASS_3, fcoe_min_xid, |
| 1018 | fcoe_max_xid, NULL)) { |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 1019 | printk(KERN_ERR PFX "em_config:fc_exch_mgr_alloc failed\n"); |
| 1020 | return -ENOMEM; |
| 1021 | } |
| 1022 | |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 1023 | return 0; |
| 1024 | } |
| 1025 | |
| 1026 | static int bnx2fc_lport_config(struct fc_lport *lport) |
| 1027 | { |
| 1028 | lport->link_up = 0; |
| 1029 | lport->qfull = 0; |
Bhanu Prakash Gollapudi | 44c570b | 2012-01-23 18:00:47 -0800 | [diff] [blame] | 1030 | lport->max_retry_count = BNX2FC_MAX_RETRY_CNT; |
| 1031 | lport->max_rport_retry_count = BNX2FC_MAX_RPORT_RETRY_CNT; |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 1032 | lport->e_d_tov = 2 * 1000; |
| 1033 | lport->r_a_tov = 10 * 1000; |
| 1034 | |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 1035 | lport->service_params = (FCP_SPPF_INIT_FCN | FCP_SPPF_RD_XRDY_DIS | |
| 1036 | FCP_SPPF_RETRY | FCP_SPPF_CONF_COMPL); |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 1037 | lport->does_npiv = 1; |
| 1038 | |
| 1039 | memset(&lport->rnid_gen, 0, sizeof(struct fc_els_rnid_gen)); |
| 1040 | lport->rnid_gen.rnid_atype = BNX2FC_RNID_HBA; |
| 1041 | |
| 1042 | /* alloc stats structure */ |
| 1043 | if (fc_lport_init_stats(lport)) |
| 1044 | return -ENOMEM; |
| 1045 | |
| 1046 | /* Finish fc_lport configuration */ |
| 1047 | fc_lport_config(lport); |
| 1048 | |
| 1049 | return 0; |
| 1050 | } |
| 1051 | |
| 1052 | /** |
| 1053 | * bnx2fc_fip_recv - handle a received FIP frame. |
| 1054 | * |
| 1055 | * @skb: the received skb |
| 1056 | * @dev: associated &net_device |
| 1057 | * @ptype: the &packet_type structure which was used to register this handler. |
| 1058 | * @orig_dev: original receive &net_device, in case @ dev is a bond. |
| 1059 | * |
| 1060 | * Returns: 0 for success |
| 1061 | */ |
| 1062 | static int bnx2fc_fip_recv(struct sk_buff *skb, struct net_device *dev, |
| 1063 | struct packet_type *ptype, |
| 1064 | struct net_device *orig_dev) |
| 1065 | { |
Bhanu Prakash Gollapudi | aea71a0 | 2011-07-26 14:51:39 -0700 | [diff] [blame] | 1066 | struct bnx2fc_interface *interface; |
Robert Love | fd8f890 | 2012-05-22 19:06:16 -0700 | [diff] [blame] | 1067 | struct fcoe_ctlr *ctlr; |
Bhanu Prakash Gollapudi | aea71a0 | 2011-07-26 14:51:39 -0700 | [diff] [blame] | 1068 | interface = container_of(ptype, struct bnx2fc_interface, |
| 1069 | fip_packet_type); |
Robert Love | fd8f890 | 2012-05-22 19:06:16 -0700 | [diff] [blame] | 1070 | ctlr = bnx2fc_to_ctlr(interface); |
| 1071 | fcoe_ctlr_recv(ctlr, skb); |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 1072 | return 0; |
| 1073 | } |
| 1074 | |
| 1075 | /** |
| 1076 | * bnx2fc_update_src_mac - Update Ethernet MAC filters. |
| 1077 | * |
Lee Jones | ca63d8e | 2020-07-13 08:46:23 +0100 | [diff] [blame] | 1078 | * @lport: The local port |
| 1079 | * @addr: Location of data to copy |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 1080 | * |
| 1081 | * Remove any previously-set unicast MAC filter. |
| 1082 | * Add secondary FCoE MAC address filter for our OUI. |
| 1083 | */ |
| 1084 | static void bnx2fc_update_src_mac(struct fc_lport *lport, u8 *addr) |
| 1085 | { |
| 1086 | struct fcoe_port *port = lport_priv(lport); |
| 1087 | |
| 1088 | memcpy(port->data_src_addr, addr, ETH_ALEN); |
| 1089 | } |
| 1090 | |
| 1091 | /** |
| 1092 | * bnx2fc_get_src_mac - return the ethernet source address for an lport |
| 1093 | * |
| 1094 | * @lport: libfc port |
| 1095 | */ |
| 1096 | static u8 *bnx2fc_get_src_mac(struct fc_lport *lport) |
| 1097 | { |
| 1098 | struct fcoe_port *port; |
| 1099 | |
| 1100 | port = (struct fcoe_port *)lport_priv(lport); |
| 1101 | return port->data_src_addr; |
| 1102 | } |
| 1103 | |
| 1104 | /** |
| 1105 | * bnx2fc_fip_send - send an Ethernet-encapsulated FIP frame. |
| 1106 | * |
| 1107 | * @fip: FCoE controller. |
| 1108 | * @skb: FIP Packet. |
| 1109 | */ |
| 1110 | static void bnx2fc_fip_send(struct fcoe_ctlr *fip, struct sk_buff *skb) |
| 1111 | { |
Chad Dupuis | 3f12f76 | 2016-04-07 09:07:57 -0400 | [diff] [blame] | 1112 | struct fip_header *fiph; |
| 1113 | struct ethhdr *eth_hdr; |
| 1114 | u16 op; |
| 1115 | u8 sub; |
| 1116 | |
| 1117 | fiph = (struct fip_header *) ((void *)skb->data + 2 * ETH_ALEN + 2); |
| 1118 | eth_hdr = (struct ethhdr *)skb_mac_header(skb); |
| 1119 | op = ntohs(fiph->fip_op); |
| 1120 | sub = fiph->fip_subcode; |
| 1121 | |
| 1122 | if (op == FIP_OP_CTRL && sub == FIP_SC_SOL && bnx2fc_log_fka) |
| 1123 | BNX2FC_MISC_DBG("Sending FKA from %pM to %pM.\n", |
| 1124 | eth_hdr->h_source, eth_hdr->h_dest); |
| 1125 | |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 1126 | skb->dev = bnx2fc_from_ctlr(fip)->netdev; |
| 1127 | dev_queue_xmit(skb); |
| 1128 | } |
| 1129 | |
| 1130 | static int bnx2fc_vport_create(struct fc_vport *vport, bool disabled) |
| 1131 | { |
| 1132 | struct Scsi_Host *shost = vport_to_shost(vport); |
| 1133 | struct fc_lport *n_port = shost_priv(shost); |
| 1134 | struct fcoe_port *port = lport_priv(n_port); |
Bhanu Prakash Gollapudi | aea71a0 | 2011-07-26 14:51:39 -0700 | [diff] [blame] | 1135 | struct bnx2fc_interface *interface = port->priv; |
| 1136 | struct net_device *netdev = interface->netdev; |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 1137 | struct fc_lport *vn_port; |
Bhanu Prakash Gollapudi | 861efc5 | 2011-08-04 17:38:51 -0700 | [diff] [blame] | 1138 | int rc; |
| 1139 | char buf[32]; |
| 1140 | |
| 1141 | rc = fcoe_validate_vport_create(vport); |
| 1142 | if (rc) { |
| 1143 | fcoe_wwn_to_str(vport->port_name, buf, sizeof(buf)); |
| 1144 | printk(KERN_ERR PFX "Failed to create vport, " |
| 1145 | "WWPN (0x%s) already exists\n", |
| 1146 | buf); |
| 1147 | return rc; |
| 1148 | } |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 1149 | |
Bhanu Prakash Gollapudi | aea71a0 | 2011-07-26 14:51:39 -0700 | [diff] [blame] | 1150 | if (!test_bit(BNX2FC_FLAG_FW_INIT_DONE, &interface->hba->flags)) { |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 1151 | printk(KERN_ERR PFX "vn ports cannot be created on" |
Bhanu Prakash Gollapudi | aea71a0 | 2011-07-26 14:51:39 -0700 | [diff] [blame] | 1152 | "this interface\n"); |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 1153 | return -EIO; |
| 1154 | } |
Jiri Pirko | 4bc71cb | 2011-09-03 03:34:30 +0000 | [diff] [blame] | 1155 | rtnl_lock(); |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 1156 | mutex_lock(&bnx2fc_dev_lock); |
Bhanu Prakash Gollapudi | aea71a0 | 2011-07-26 14:51:39 -0700 | [diff] [blame] | 1157 | vn_port = bnx2fc_if_create(interface, &vport->dev, 1); |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 1158 | mutex_unlock(&bnx2fc_dev_lock); |
Jiri Pirko | 4bc71cb | 2011-09-03 03:34:30 +0000 | [diff] [blame] | 1159 | rtnl_unlock(); |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 1160 | |
Dan Carpenter | b6829c7 | 2014-11-04 13:37:17 +0300 | [diff] [blame] | 1161 | if (!vn_port) { |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 1162 | printk(KERN_ERR PFX "bnx2fc_vport_create (%s) failed\n", |
| 1163 | netdev->name); |
| 1164 | return -EIO; |
| 1165 | } |
| 1166 | |
Joe Carnuccio | 10755d3 | 2016-04-07 09:07:56 -0400 | [diff] [blame] | 1167 | if (bnx2fc_devloss_tmo) |
| 1168 | fc_host_dev_loss_tmo(vn_port->host) = bnx2fc_devloss_tmo; |
| 1169 | |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 1170 | if (disabled) { |
| 1171 | fc_vport_set_state(vport, FC_VPORT_DISABLED); |
| 1172 | } else { |
| 1173 | vn_port->boot_time = jiffies; |
| 1174 | fc_lport_init(vn_port); |
| 1175 | fc_fabric_login(vn_port); |
| 1176 | fc_vport_setlink(vn_port); |
| 1177 | } |
| 1178 | return 0; |
| 1179 | } |
| 1180 | |
Bhanu Prakash Gollapudi | abc49a9 | 2011-08-04 17:38:42 -0700 | [diff] [blame] | 1181 | static void bnx2fc_free_vport(struct bnx2fc_hba *hba, struct fc_lport *lport) |
| 1182 | { |
| 1183 | struct bnx2fc_lport *blport, *tmp; |
| 1184 | |
| 1185 | spin_lock_bh(&hba->hba_lock); |
| 1186 | list_for_each_entry_safe(blport, tmp, &hba->vports, list) { |
| 1187 | if (blport->lport == lport) { |
| 1188 | list_del(&blport->list); |
| 1189 | kfree(blport); |
| 1190 | } |
| 1191 | } |
| 1192 | spin_unlock_bh(&hba->hba_lock); |
| 1193 | } |
| 1194 | |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 1195 | static int bnx2fc_vport_destroy(struct fc_vport *vport) |
| 1196 | { |
| 1197 | struct Scsi_Host *shost = vport_to_shost(vport); |
| 1198 | struct fc_lport *n_port = shost_priv(shost); |
| 1199 | struct fc_lport *vn_port = vport->dd_data; |
| 1200 | struct fcoe_port *port = lport_priv(vn_port); |
Bhanu Prakash Gollapudi | abc49a9 | 2011-08-04 17:38:42 -0700 | [diff] [blame] | 1201 | struct bnx2fc_interface *interface = port->priv; |
Bhanu Prakash Gollapudi | cdf5466 | 2011-08-04 17:38:39 -0700 | [diff] [blame] | 1202 | struct fc_lport *v_port; |
| 1203 | bool found = false; |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 1204 | |
| 1205 | mutex_lock(&n_port->lp_mutex); |
Bhanu Prakash Gollapudi | cdf5466 | 2011-08-04 17:38:39 -0700 | [diff] [blame] | 1206 | list_for_each_entry(v_port, &n_port->vports, list) |
| 1207 | if (v_port->vport == vport) { |
| 1208 | found = true; |
| 1209 | break; |
| 1210 | } |
| 1211 | |
| 1212 | if (!found) { |
| 1213 | mutex_unlock(&n_port->lp_mutex); |
| 1214 | return -ENOENT; |
| 1215 | } |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 1216 | list_del(&vn_port->list); |
| 1217 | mutex_unlock(&n_port->lp_mutex); |
Bhanu Prakash Gollapudi | abc49a9 | 2011-08-04 17:38:42 -0700 | [diff] [blame] | 1218 | bnx2fc_free_vport(interface->hba, port->lport); |
| 1219 | bnx2fc_port_shutdown(port->lport); |
John Meneghini | 847f9ea | 2022-01-14 23:00:44 -0500 | [diff] [blame] | 1220 | bnx2fc_port_destroy(port); |
Bhanu Prakash Gollapudi | abc49a9 | 2011-08-04 17:38:42 -0700 | [diff] [blame] | 1221 | bnx2fc_interface_put(interface); |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 1222 | return 0; |
| 1223 | } |
| 1224 | |
| 1225 | static int bnx2fc_vport_disable(struct fc_vport *vport, bool disable) |
| 1226 | { |
| 1227 | struct fc_lport *lport = vport->dd_data; |
| 1228 | |
| 1229 | if (disable) { |
| 1230 | fc_vport_set_state(vport, FC_VPORT_DISABLED); |
| 1231 | fc_fabric_logoff(lport); |
| 1232 | } else { |
| 1233 | lport->boot_time = jiffies; |
| 1234 | fc_fabric_login(lport); |
| 1235 | fc_vport_setlink(lport); |
| 1236 | } |
| 1237 | return 0; |
| 1238 | } |
| 1239 | |
| 1240 | |
Bhanu Prakash Gollapudi | 776cebc | 2011-08-04 17:38:40 -0700 | [diff] [blame] | 1241 | static int bnx2fc_interface_setup(struct bnx2fc_interface *interface) |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 1242 | { |
Bhanu Prakash Gollapudi | aea71a0 | 2011-07-26 14:51:39 -0700 | [diff] [blame] | 1243 | struct net_device *netdev = interface->netdev; |
| 1244 | struct net_device *physdev = interface->hba->phys_dev; |
Robert Love | fd8f890 | 2012-05-22 19:06:16 -0700 | [diff] [blame] | 1245 | struct fcoe_ctlr *ctlr = bnx2fc_to_ctlr(interface); |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 1246 | struct netdev_hw_addr *ha; |
| 1247 | int sel_san_mac = 0; |
| 1248 | |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 1249 | /* setup Source MAC Address */ |
| 1250 | rcu_read_lock(); |
| 1251 | for_each_dev_addr(physdev, ha) { |
| 1252 | BNX2FC_MISC_DBG("net_config: ha->type = %d, fip_mac = ", |
| 1253 | ha->type); |
| 1254 | printk(KERN_INFO "%2x:%2x:%2x:%2x:%2x:%2x\n", ha->addr[0], |
| 1255 | ha->addr[1], ha->addr[2], ha->addr[3], |
| 1256 | ha->addr[4], ha->addr[5]); |
| 1257 | |
| 1258 | if ((ha->type == NETDEV_HW_ADDR_T_SAN) && |
| 1259 | (is_valid_ether_addr(ha->addr))) { |
Robert Love | fd8f890 | 2012-05-22 19:06:16 -0700 | [diff] [blame] | 1260 | memcpy(ctlr->ctl_src_addr, ha->addr, |
Bhanu Prakash Gollapudi | aea71a0 | 2011-07-26 14:51:39 -0700 | [diff] [blame] | 1261 | ETH_ALEN); |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 1262 | sel_san_mac = 1; |
| 1263 | BNX2FC_MISC_DBG("Found SAN MAC\n"); |
| 1264 | } |
| 1265 | } |
| 1266 | rcu_read_unlock(); |
| 1267 | |
| 1268 | if (!sel_san_mac) |
| 1269 | return -ENODEV; |
| 1270 | |
Bhanu Prakash Gollapudi | aea71a0 | 2011-07-26 14:51:39 -0700 | [diff] [blame] | 1271 | interface->fip_packet_type.func = bnx2fc_fip_recv; |
| 1272 | interface->fip_packet_type.type = htons(ETH_P_FIP); |
| 1273 | interface->fip_packet_type.dev = netdev; |
| 1274 | dev_add_pack(&interface->fip_packet_type); |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 1275 | |
Bhanu Prakash Gollapudi | aea71a0 | 2011-07-26 14:51:39 -0700 | [diff] [blame] | 1276 | interface->fcoe_packet_type.func = bnx2fc_rcv; |
| 1277 | interface->fcoe_packet_type.type = __constant_htons(ETH_P_FCOE); |
| 1278 | interface->fcoe_packet_type.dev = netdev; |
| 1279 | dev_add_pack(&interface->fcoe_packet_type); |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 1280 | |
| 1281 | return 0; |
| 1282 | } |
| 1283 | |
| 1284 | static int bnx2fc_attach_transport(void) |
| 1285 | { |
| 1286 | bnx2fc_transport_template = |
| 1287 | fc_attach_transport(&bnx2fc_transport_function); |
| 1288 | |
| 1289 | if (bnx2fc_transport_template == NULL) { |
| 1290 | printk(KERN_ERR PFX "Failed to attach FC transport\n"); |
| 1291 | return -ENODEV; |
| 1292 | } |
| 1293 | |
| 1294 | bnx2fc_vport_xport_template = |
| 1295 | fc_attach_transport(&bnx2fc_vport_xport_function); |
| 1296 | if (bnx2fc_vport_xport_template == NULL) { |
| 1297 | printk(KERN_ERR PFX |
| 1298 | "Failed to attach FC transport for vport\n"); |
| 1299 | fc_release_transport(bnx2fc_transport_template); |
| 1300 | bnx2fc_transport_template = NULL; |
| 1301 | return -ENODEV; |
| 1302 | } |
| 1303 | return 0; |
| 1304 | } |
| 1305 | static void bnx2fc_release_transport(void) |
| 1306 | { |
| 1307 | fc_release_transport(bnx2fc_transport_template); |
| 1308 | fc_release_transport(bnx2fc_vport_xport_template); |
| 1309 | bnx2fc_transport_template = NULL; |
| 1310 | bnx2fc_vport_xport_template = NULL; |
| 1311 | } |
| 1312 | |
| 1313 | static void bnx2fc_interface_release(struct kref *kref) |
| 1314 | { |
Robert Love | 8d55e50 | 2012-05-22 19:06:26 -0700 | [diff] [blame] | 1315 | struct fcoe_ctlr_device *ctlr_dev; |
Bhanu Prakash Gollapudi | aea71a0 | 2011-07-26 14:51:39 -0700 | [diff] [blame] | 1316 | struct bnx2fc_interface *interface; |
Robert Love | fd8f890 | 2012-05-22 19:06:16 -0700 | [diff] [blame] | 1317 | struct fcoe_ctlr *ctlr; |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 1318 | struct net_device *netdev; |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 1319 | |
Bhanu Prakash Gollapudi | aea71a0 | 2011-07-26 14:51:39 -0700 | [diff] [blame] | 1320 | interface = container_of(kref, struct bnx2fc_interface, kref); |
Nithin Nayak Sujir | 068bdce | 2011-04-25 12:30:09 -0700 | [diff] [blame] | 1321 | BNX2FC_MISC_DBG("Interface is being released\n"); |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 1322 | |
Robert Love | fd8f890 | 2012-05-22 19:06:16 -0700 | [diff] [blame] | 1323 | ctlr = bnx2fc_to_ctlr(interface); |
Robert Love | 8d55e50 | 2012-05-22 19:06:26 -0700 | [diff] [blame] | 1324 | ctlr_dev = fcoe_ctlr_to_ctlr_dev(ctlr); |
Bhanu Prakash Gollapudi | aea71a0 | 2011-07-26 14:51:39 -0700 | [diff] [blame] | 1325 | netdev = interface->netdev; |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 1326 | |
| 1327 | /* tear-down FIP controller */ |
Bhanu Prakash Gollapudi | aea71a0 | 2011-07-26 14:51:39 -0700 | [diff] [blame] | 1328 | if (test_and_clear_bit(BNX2FC_CTLR_INIT_DONE, &interface->if_flags)) |
Robert Love | fd8f890 | 2012-05-22 19:06:16 -0700 | [diff] [blame] | 1329 | fcoe_ctlr_destroy(ctlr); |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 1330 | |
Robert Love | 8d55e50 | 2012-05-22 19:06:26 -0700 | [diff] [blame] | 1331 | fcoe_ctlr_device_delete(ctlr_dev); |
Bhanu Prakash Gollapudi | aea71a0 | 2011-07-26 14:51:39 -0700 | [diff] [blame] | 1332 | |
| 1333 | dev_put(netdev); |
| 1334 | module_put(THIS_MODULE); |
| 1335 | } |
| 1336 | |
| 1337 | static inline void bnx2fc_interface_get(struct bnx2fc_interface *interface) |
| 1338 | { |
| 1339 | kref_get(&interface->kref); |
| 1340 | } |
| 1341 | |
| 1342 | static inline void bnx2fc_interface_put(struct bnx2fc_interface *interface) |
| 1343 | { |
| 1344 | kref_put(&interface->kref, bnx2fc_interface_release); |
| 1345 | } |
| 1346 | static void bnx2fc_hba_destroy(struct bnx2fc_hba *hba) |
| 1347 | { |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 1348 | /* Free the command manager */ |
| 1349 | if (hba->cmd_mgr) { |
| 1350 | bnx2fc_cmd_mgr_free(hba->cmd_mgr); |
| 1351 | hba->cmd_mgr = NULL; |
| 1352 | } |
Bhanu Prakash Gollapudi | aea71a0 | 2011-07-26 14:51:39 -0700 | [diff] [blame] | 1353 | kfree(hba->tgt_ofld_list); |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 1354 | bnx2fc_unbind_pcidev(hba); |
| 1355 | kfree(hba); |
| 1356 | } |
| 1357 | |
| 1358 | /** |
Bhanu Prakash Gollapudi | aea71a0 | 2011-07-26 14:51:39 -0700 | [diff] [blame] | 1359 | * bnx2fc_hba_create - create a new bnx2fc hba |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 1360 | * |
| 1361 | * @cnic: pointer to cnic device |
| 1362 | * |
Bhanu Prakash Gollapudi | aea71a0 | 2011-07-26 14:51:39 -0700 | [diff] [blame] | 1363 | * Creates a new FCoE hba on the given device. |
| 1364 | * |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 1365 | */ |
Bhanu Prakash Gollapudi | aea71a0 | 2011-07-26 14:51:39 -0700 | [diff] [blame] | 1366 | static struct bnx2fc_hba *bnx2fc_hba_create(struct cnic_dev *cnic) |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 1367 | { |
| 1368 | struct bnx2fc_hba *hba; |
Barak Witkowski | 2e499d3 | 2012-06-26 01:31:19 +0000 | [diff] [blame] | 1369 | struct fcoe_capabilities *fcoe_cap; |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 1370 | int rc; |
| 1371 | |
| 1372 | hba = kzalloc(sizeof(*hba), GFP_KERNEL); |
| 1373 | if (!hba) { |
| 1374 | printk(KERN_ERR PFX "Unable to allocate hba structure\n"); |
| 1375 | return NULL; |
| 1376 | } |
| 1377 | spin_lock_init(&hba->hba_lock); |
| 1378 | mutex_init(&hba->hba_mutex); |
Maurizio Lombardi | c2dd893 | 2017-05-24 14:09:44 +0200 | [diff] [blame] | 1379 | mutex_init(&hba->hba_stats_mutex); |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 1380 | |
| 1381 | hba->cnic = cnic; |
Bhanu Prakash Gollapudi | 0eb43b4 | 2013-04-22 19:22:30 +0000 | [diff] [blame] | 1382 | |
| 1383 | hba->max_tasks = cnic->max_fcoe_exchanges; |
| 1384 | hba->elstm_xids = (hba->max_tasks / 2); |
| 1385 | hba->max_outstanding_cmds = hba->elstm_xids; |
| 1386 | hba->max_xid = (hba->max_tasks - 1); |
| 1387 | |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 1388 | rc = bnx2fc_bind_pcidev(hba); |
Bhanu Prakash Gollapudi | aea71a0 | 2011-07-26 14:51:39 -0700 | [diff] [blame] | 1389 | if (rc) { |
| 1390 | printk(KERN_ERR PFX "create_adapter: bind error\n"); |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 1391 | goto bind_err; |
Bhanu Prakash Gollapudi | aea71a0 | 2011-07-26 14:51:39 -0700 | [diff] [blame] | 1392 | } |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 1393 | hba->phys_dev = cnic->netdev; |
Bhanu Prakash Gollapudi | aea71a0 | 2011-07-26 14:51:39 -0700 | [diff] [blame] | 1394 | hba->next_conn_id = 0; |
| 1395 | |
| 1396 | hba->tgt_ofld_list = |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 1397 | kcalloc(BNX2FC_NUM_MAX_SESS, sizeof(struct bnx2fc_rport *), |
Bhanu Prakash Gollapudi | aea71a0 | 2011-07-26 14:51:39 -0700 | [diff] [blame] | 1398 | GFP_KERNEL); |
| 1399 | if (!hba->tgt_ofld_list) { |
| 1400 | printk(KERN_ERR PFX "Unable to allocate tgt offload list\n"); |
| 1401 | goto tgtofld_err; |
| 1402 | } |
| 1403 | |
| 1404 | hba->num_ofld_sess = 0; |
| 1405 | |
Bhanu Prakash Gollapudi | 0eb43b4 | 2013-04-22 19:22:30 +0000 | [diff] [blame] | 1406 | hba->cmd_mgr = bnx2fc_cmd_mgr_alloc(hba); |
Bhanu Prakash Gollapudi | aea71a0 | 2011-07-26 14:51:39 -0700 | [diff] [blame] | 1407 | if (!hba->cmd_mgr) { |
| 1408 | printk(KERN_ERR PFX "em_config:bnx2fc_cmd_mgr_alloc failed\n"); |
| 1409 | goto cmgr_err; |
| 1410 | } |
Barak Witkowski | 2e499d3 | 2012-06-26 01:31:19 +0000 | [diff] [blame] | 1411 | fcoe_cap = &hba->fcoe_cap; |
| 1412 | |
| 1413 | fcoe_cap->capability1 = BNX2FC_TM_MAX_SQES << |
| 1414 | FCOE_IOS_PER_CONNECTION_SHIFT; |
| 1415 | fcoe_cap->capability1 |= BNX2FC_NUM_MAX_SESS << |
| 1416 | FCOE_LOGINS_PER_PORT_SHIFT; |
Bhanu Prakash Gollapudi | 0eb43b4 | 2013-04-22 19:22:30 +0000 | [diff] [blame] | 1417 | fcoe_cap->capability2 = hba->max_outstanding_cmds << |
Barak Witkowski | 2e499d3 | 2012-06-26 01:31:19 +0000 | [diff] [blame] | 1418 | FCOE_NUMBER_OF_EXCHANGES_SHIFT; |
| 1419 | fcoe_cap->capability2 |= BNX2FC_MAX_NPIV << |
| 1420 | FCOE_NPIV_WWN_PER_PORT_SHIFT; |
| 1421 | fcoe_cap->capability3 = BNX2FC_NUM_MAX_SESS << |
| 1422 | FCOE_TARGETS_SUPPORTED_SHIFT; |
Bhanu Prakash Gollapudi | 0eb43b4 | 2013-04-22 19:22:30 +0000 | [diff] [blame] | 1423 | fcoe_cap->capability3 |= hba->max_outstanding_cmds << |
Barak Witkowski | 2e499d3 | 2012-06-26 01:31:19 +0000 | [diff] [blame] | 1424 | FCOE_OUTSTANDING_COMMANDS_SHIFT; |
| 1425 | fcoe_cap->capability4 = FCOE_CAPABILITY4_STATEFUL; |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 1426 | |
| 1427 | init_waitqueue_head(&hba->shutdown_wait); |
| 1428 | init_waitqueue_head(&hba->destroy_wait); |
Bhanu Prakash Gollapudi | aea71a0 | 2011-07-26 14:51:39 -0700 | [diff] [blame] | 1429 | INIT_LIST_HEAD(&hba->vports); |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 1430 | |
| 1431 | return hba; |
Bhanu Prakash Gollapudi | aea71a0 | 2011-07-26 14:51:39 -0700 | [diff] [blame] | 1432 | |
| 1433 | cmgr_err: |
| 1434 | kfree(hba->tgt_ofld_list); |
| 1435 | tgtofld_err: |
| 1436 | bnx2fc_unbind_pcidev(hba); |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 1437 | bind_err: |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 1438 | kfree(hba); |
| 1439 | return NULL; |
| 1440 | } |
| 1441 | |
Baoyou Xie | 3f7d67d | 2016-09-04 14:52:21 +0800 | [diff] [blame] | 1442 | static struct bnx2fc_interface * |
| 1443 | bnx2fc_interface_create(struct bnx2fc_hba *hba, |
| 1444 | struct net_device *netdev, |
Sedat Dilek | 8beb90a | 2019-02-15 13:19:20 +0100 | [diff] [blame] | 1445 | enum fip_mode fip_mode) |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 1446 | { |
Robert Love | 8d55e50 | 2012-05-22 19:06:26 -0700 | [diff] [blame] | 1447 | struct fcoe_ctlr_device *ctlr_dev; |
Bhanu Prakash Gollapudi | aea71a0 | 2011-07-26 14:51:39 -0700 | [diff] [blame] | 1448 | struct bnx2fc_interface *interface; |
Robert Love | fd8f890 | 2012-05-22 19:06:16 -0700 | [diff] [blame] | 1449 | struct fcoe_ctlr *ctlr; |
| 1450 | int size; |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 1451 | int rc = 0; |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 1452 | |
Robert Love | fd8f890 | 2012-05-22 19:06:16 -0700 | [diff] [blame] | 1453 | size = (sizeof(*interface) + sizeof(struct fcoe_ctlr)); |
Robert Love | 8d55e50 | 2012-05-22 19:06:26 -0700 | [diff] [blame] | 1454 | ctlr_dev = fcoe_ctlr_device_add(&netdev->dev, &bnx2fc_fcoe_sysfs_templ, |
| 1455 | size); |
| 1456 | if (!ctlr_dev) { |
Bhanu Prakash Gollapudi | aea71a0 | 2011-07-26 14:51:39 -0700 | [diff] [blame] | 1457 | printk(KERN_ERR PFX "Unable to allocate interface structure\n"); |
| 1458 | return NULL; |
| 1459 | } |
Robert Love | 8d55e50 | 2012-05-22 19:06:26 -0700 | [diff] [blame] | 1460 | ctlr = fcoe_ctlr_device_priv(ctlr_dev); |
Robert Love | 9d34876 | 2013-09-05 07:47:27 +0000 | [diff] [blame] | 1461 | ctlr->cdev = ctlr_dev; |
Robert Love | fd8f890 | 2012-05-22 19:06:16 -0700 | [diff] [blame] | 1462 | interface = fcoe_ctlr_priv(ctlr); |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 1463 | dev_hold(netdev); |
Bhanu Prakash Gollapudi | aea71a0 | 2011-07-26 14:51:39 -0700 | [diff] [blame] | 1464 | kref_init(&interface->kref); |
| 1465 | interface->hba = hba; |
| 1466 | interface->netdev = netdev; |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 1467 | |
| 1468 | /* Initialize FIP */ |
Robert Love | fd8f890 | 2012-05-22 19:06:16 -0700 | [diff] [blame] | 1469 | fcoe_ctlr_init(ctlr, fip_mode); |
| 1470 | ctlr->send = bnx2fc_fip_send; |
| 1471 | ctlr->update_mac = bnx2fc_update_src_mac; |
| 1472 | ctlr->get_src_addr = bnx2fc_get_src_mac; |
Bhanu Prakash Gollapudi | aea71a0 | 2011-07-26 14:51:39 -0700 | [diff] [blame] | 1473 | set_bit(BNX2FC_CTLR_INIT_DONE, &interface->if_flags); |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 1474 | |
Bhanu Prakash Gollapudi | 776cebc | 2011-08-04 17:38:40 -0700 | [diff] [blame] | 1475 | rc = bnx2fc_interface_setup(interface); |
Bhanu Prakash Gollapudi | aea71a0 | 2011-07-26 14:51:39 -0700 | [diff] [blame] | 1476 | if (!rc) |
| 1477 | return interface; |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 1478 | |
Robert Love | fd8f890 | 2012-05-22 19:06:16 -0700 | [diff] [blame] | 1479 | fcoe_ctlr_destroy(ctlr); |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 1480 | dev_put(netdev); |
Robert Love | 8d55e50 | 2012-05-22 19:06:26 -0700 | [diff] [blame] | 1481 | fcoe_ctlr_device_delete(ctlr_dev); |
Bhanu Prakash Gollapudi | aea71a0 | 2011-07-26 14:51:39 -0700 | [diff] [blame] | 1482 | return NULL; |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 1483 | } |
| 1484 | |
| 1485 | /** |
| 1486 | * bnx2fc_if_create - Create FCoE instance on a given interface |
| 1487 | * |
Bhanu Prakash Gollapudi | aea71a0 | 2011-07-26 14:51:39 -0700 | [diff] [blame] | 1488 | * @interface: FCoE interface to create a local port on |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 1489 | * @parent: Device pointer to be the parent in sysfs for the SCSI host |
| 1490 | * @npiv: Indicates if the port is vport or not |
| 1491 | * |
| 1492 | * Creates a fc_lport instance and a Scsi_Host instance and configure them. |
| 1493 | * |
| 1494 | * Returns: Allocated fc_lport or an error pointer |
| 1495 | */ |
Bhanu Prakash Gollapudi | aea71a0 | 2011-07-26 14:51:39 -0700 | [diff] [blame] | 1496 | static struct fc_lport *bnx2fc_if_create(struct bnx2fc_interface *interface, |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 1497 | struct device *parent, int npiv) |
| 1498 | { |
Robert Love | fd8f890 | 2012-05-22 19:06:16 -0700 | [diff] [blame] | 1499 | struct fcoe_ctlr *ctlr = bnx2fc_to_ctlr(interface); |
Vasu Dev | 134a4e2 | 2011-04-28 15:55:44 -0700 | [diff] [blame] | 1500 | struct fc_lport *lport, *n_port; |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 1501 | struct fcoe_port *port; |
| 1502 | struct Scsi_Host *shost; |
| 1503 | struct fc_vport *vport = dev_to_vport(parent); |
Bhanu Prakash Gollapudi | d36b327 | 2011-05-27 11:47:27 -0700 | [diff] [blame] | 1504 | struct bnx2fc_lport *blport; |
Bhanu Prakash Gollapudi | 0eb43b4 | 2013-04-22 19:22:30 +0000 | [diff] [blame] | 1505 | struct bnx2fc_hba *hba = interface->hba; |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 1506 | int rc = 0; |
| 1507 | |
Bhanu Prakash Gollapudi | d36b327 | 2011-05-27 11:47:27 -0700 | [diff] [blame] | 1508 | blport = kzalloc(sizeof(struct bnx2fc_lport), GFP_KERNEL); |
| 1509 | if (!blport) { |
Robert Love | fd8f890 | 2012-05-22 19:06:16 -0700 | [diff] [blame] | 1510 | BNX2FC_HBA_DBG(ctlr->lp, "Unable to alloc blport\n"); |
Bhanu Prakash Gollapudi | d36b327 | 2011-05-27 11:47:27 -0700 | [diff] [blame] | 1511 | return NULL; |
| 1512 | } |
| 1513 | |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 1514 | /* Allocate Scsi_Host structure */ |
Bhanu Prakash Gollapudi | 0eb43b4 | 2013-04-22 19:22:30 +0000 | [diff] [blame] | 1515 | bnx2fc_shost_template.can_queue = hba->max_outstanding_cmds; |
Vasu Dev | 134a4e2 | 2011-04-28 15:55:44 -0700 | [diff] [blame] | 1516 | if (!npiv) |
| 1517 | lport = libfc_host_alloc(&bnx2fc_shost_template, sizeof(*port)); |
| 1518 | else |
| 1519 | lport = libfc_vport_create(vport, sizeof(*port)); |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 1520 | |
| 1521 | if (!lport) { |
| 1522 | printk(KERN_ERR PFX "could not allocate scsi host structure\n"); |
Bhanu Prakash Gollapudi | d36b327 | 2011-05-27 11:47:27 -0700 | [diff] [blame] | 1523 | goto free_blport; |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 1524 | } |
| 1525 | shost = lport->host; |
| 1526 | port = lport_priv(lport); |
| 1527 | port->lport = lport; |
Bhanu Prakash Gollapudi | aea71a0 | 2011-07-26 14:51:39 -0700 | [diff] [blame] | 1528 | port->priv = interface; |
Yi Zou | c3d7909 | 2012-12-06 06:24:29 +0000 | [diff] [blame] | 1529 | port->get_netdev = bnx2fc_netdev; |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 1530 | |
| 1531 | /* Configure fcoe_port */ |
| 1532 | rc = bnx2fc_lport_config(lport); |
| 1533 | if (rc) |
| 1534 | goto lp_config_err; |
| 1535 | |
| 1536 | if (npiv) { |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 1537 | printk(KERN_ERR PFX "Setting vport names, 0x%llX 0x%llX\n", |
| 1538 | vport->node_name, vport->port_name); |
| 1539 | fc_set_wwnn(lport, vport->node_name); |
| 1540 | fc_set_wwpn(lport, vport->port_name); |
| 1541 | } |
| 1542 | /* Configure netdev and networking properties of the lport */ |
Bhanu Prakash Gollapudi | 5243960 | 2011-08-04 17:38:50 -0700 | [diff] [blame] | 1543 | rc = bnx2fc_net_config(lport, interface->netdev); |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 1544 | if (rc) { |
| 1545 | printk(KERN_ERR PFX "Error on bnx2fc_net_config\n"); |
| 1546 | goto lp_config_err; |
| 1547 | } |
| 1548 | |
| 1549 | rc = bnx2fc_shost_config(lport, parent); |
| 1550 | if (rc) { |
Colin Ian King | ab9dd49 | 2017-12-01 09:37:25 +0000 | [diff] [blame] | 1551 | printk(KERN_ERR PFX "Couldn't configure shost for %s\n", |
Bhanu Prakash Gollapudi | aea71a0 | 2011-07-26 14:51:39 -0700 | [diff] [blame] | 1552 | interface->netdev->name); |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 1553 | goto lp_config_err; |
| 1554 | } |
| 1555 | |
| 1556 | /* Initialize the libfc library */ |
| 1557 | rc = bnx2fc_libfc_config(lport); |
| 1558 | if (rc) { |
Colin Ian King | ab9dd49 | 2017-12-01 09:37:25 +0000 | [diff] [blame] | 1559 | printk(KERN_ERR PFX "Couldn't configure libfc\n"); |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 1560 | goto shost_err; |
| 1561 | } |
| 1562 | fc_host_port_type(lport->host) = FC_PORTTYPE_UNKNOWN; |
| 1563 | |
Joe Carnuccio | 10755d3 | 2016-04-07 09:07:56 -0400 | [diff] [blame] | 1564 | if (bnx2fc_devloss_tmo) |
| 1565 | fc_host_dev_loss_tmo(shost) = bnx2fc_devloss_tmo; |
| 1566 | |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 1567 | /* Allocate exchange manager */ |
Vasu Dev | 134a4e2 | 2011-04-28 15:55:44 -0700 | [diff] [blame] | 1568 | if (!npiv) |
Bhanu Prakash Gollapudi | 0eb43b4 | 2013-04-22 19:22:30 +0000 | [diff] [blame] | 1569 | rc = bnx2fc_em_config(lport, hba); |
Vasu Dev | 134a4e2 | 2011-04-28 15:55:44 -0700 | [diff] [blame] | 1570 | else { |
| 1571 | shost = vport_to_shost(vport); |
| 1572 | n_port = shost_priv(shost); |
| 1573 | rc = fc_exch_mgr_list_clone(n_port, lport); |
| 1574 | } |
| 1575 | |
| 1576 | if (rc) { |
| 1577 | printk(KERN_ERR PFX "Error on bnx2fc_em_config\n"); |
| 1578 | goto shost_err; |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 1579 | } |
| 1580 | |
Bhanu Prakash Gollapudi | aea71a0 | 2011-07-26 14:51:39 -0700 | [diff] [blame] | 1581 | bnx2fc_interface_get(interface); |
Bhanu Prakash Gollapudi | d36b327 | 2011-05-27 11:47:27 -0700 | [diff] [blame] | 1582 | |
| 1583 | spin_lock_bh(&hba->hba_lock); |
| 1584 | blport->lport = lport; |
| 1585 | list_add_tail(&blport->list, &hba->vports); |
| 1586 | spin_unlock_bh(&hba->hba_lock); |
| 1587 | |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 1588 | return lport; |
| 1589 | |
| 1590 | shost_err: |
| 1591 | scsi_remove_host(shost); |
| 1592 | lp_config_err: |
| 1593 | scsi_host_put(lport->host); |
Bhanu Prakash Gollapudi | d36b327 | 2011-05-27 11:47:27 -0700 | [diff] [blame] | 1594 | free_blport: |
| 1595 | kfree(blport); |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 1596 | return NULL; |
| 1597 | } |
| 1598 | |
Bhanu Prakash Gollapudi | 013068f | 2011-08-30 15:54:52 -0700 | [diff] [blame] | 1599 | static void bnx2fc_net_cleanup(struct bnx2fc_interface *interface) |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 1600 | { |
| 1601 | /* Dont listen for Ethernet packets anymore */ |
Bhanu Prakash Gollapudi | aea71a0 | 2011-07-26 14:51:39 -0700 | [diff] [blame] | 1602 | __dev_remove_pack(&interface->fcoe_packet_type); |
| 1603 | __dev_remove_pack(&interface->fip_packet_type); |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 1604 | synchronize_net(); |
| 1605 | } |
| 1606 | |
Bhanu Prakash Gollapudi | 776cebc | 2011-08-04 17:38:40 -0700 | [diff] [blame] | 1607 | static void bnx2fc_interface_cleanup(struct bnx2fc_interface *interface) |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 1608 | { |
Robert Love | fd8f890 | 2012-05-22 19:06:16 -0700 | [diff] [blame] | 1609 | struct fcoe_ctlr *ctlr = bnx2fc_to_ctlr(interface); |
| 1610 | struct fc_lport *lport = ctlr->lp; |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 1611 | struct fcoe_port *port = lport_priv(lport); |
Bhanu Prakash Gollapudi | 9be17fc | 2011-08-04 17:38:41 -0700 | [diff] [blame] | 1612 | struct bnx2fc_hba *hba = interface->hba; |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 1613 | |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 1614 | /* Stop the transmit retry timer */ |
| 1615 | del_timer_sync(&port->timer); |
| 1616 | |
| 1617 | /* Free existing transmit skbs */ |
| 1618 | fcoe_clean_pending_queue(lport); |
| 1619 | |
Bhanu Prakash Gollapudi | 013068f | 2011-08-30 15:54:52 -0700 | [diff] [blame] | 1620 | bnx2fc_net_cleanup(interface); |
Bhanu Prakash Gollapudi | 9be17fc | 2011-08-04 17:38:41 -0700 | [diff] [blame] | 1621 | |
Bhanu Prakash Gollapudi | abc49a9 | 2011-08-04 17:38:42 -0700 | [diff] [blame] | 1622 | bnx2fc_free_vport(hba, lport); |
Bhanu Prakash Gollapudi | 9be17fc | 2011-08-04 17:38:41 -0700 | [diff] [blame] | 1623 | } |
| 1624 | |
| 1625 | static void bnx2fc_if_destroy(struct fc_lport *lport) |
| 1626 | { |
| 1627 | |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 1628 | /* Free queued packets for the receive thread */ |
| 1629 | bnx2fc_clean_rx_queue(lport); |
| 1630 | |
| 1631 | /* Detach from scsi-ml */ |
| 1632 | fc_remove_host(lport->host); |
| 1633 | scsi_remove_host(lport->host); |
| 1634 | |
| 1635 | /* |
| 1636 | * Note that only the physical lport will have the exchange manager. |
| 1637 | * for vports, this function is NOP |
| 1638 | */ |
| 1639 | fc_exch_mgr_free(lport); |
| 1640 | |
| 1641 | /* Free memory used by statistical counters */ |
| 1642 | fc_lport_free_stats(lport); |
| 1643 | |
| 1644 | /* Release Scsi_Host */ |
| 1645 | scsi_host_put(lport->host); |
| 1646 | } |
| 1647 | |
Bhanu Prakash Gollapudi | eccdcd0 | 2011-08-24 18:56:42 -0700 | [diff] [blame] | 1648 | static void __bnx2fc_destroy(struct bnx2fc_interface *interface) |
Bhanu Prakash Gollapudi | abc49a9 | 2011-08-04 17:38:42 -0700 | [diff] [blame] | 1649 | { |
Robert Love | fd8f890 | 2012-05-22 19:06:16 -0700 | [diff] [blame] | 1650 | struct fcoe_ctlr *ctlr = bnx2fc_to_ctlr(interface); |
| 1651 | struct fc_lport *lport = ctlr->lp; |
Bhanu Prakash Gollapudi | 0cbf32e | 2011-08-30 15:54:51 -0700 | [diff] [blame] | 1652 | struct fcoe_port *port = lport_priv(lport); |
Bhanu Prakash Gollapudi | abc49a9 | 2011-08-04 17:38:42 -0700 | [diff] [blame] | 1653 | |
| 1654 | bnx2fc_interface_cleanup(interface); |
| 1655 | bnx2fc_stop(interface); |
Bhanu Prakash Gollapudi | abc49a9 | 2011-08-04 17:38:42 -0700 | [diff] [blame] | 1656 | list_del(&interface->list); |
John Meneghini | 847f9ea | 2022-01-14 23:00:44 -0500 | [diff] [blame] | 1657 | bnx2fc_port_destroy(port); |
Bhanu Prakash Gollapudi | abc49a9 | 2011-08-04 17:38:42 -0700 | [diff] [blame] | 1658 | bnx2fc_interface_put(interface); |
Bhanu Prakash Gollapudi | abc49a9 | 2011-08-04 17:38:42 -0700 | [diff] [blame] | 1659 | } |
| 1660 | |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 1661 | /** |
| 1662 | * bnx2fc_destroy - Destroy a bnx2fc FCoE interface |
| 1663 | * |
Lee Jones | ca63d8e | 2020-07-13 08:46:23 +0100 | [diff] [blame] | 1664 | * @netdev: The net device that the FCoE interface is on |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 1665 | * |
| 1666 | * Called from sysfs. |
| 1667 | * |
| 1668 | * Returns: 0 for success |
| 1669 | */ |
| 1670 | static int bnx2fc_destroy(struct net_device *netdev) |
| 1671 | { |
Bhanu Prakash Gollapudi | aea71a0 | 2011-07-26 14:51:39 -0700 | [diff] [blame] | 1672 | struct bnx2fc_interface *interface = NULL; |
Bhanu Prakash Gollapudi | 2a7b29c | 2012-01-23 18:00:46 -0800 | [diff] [blame] | 1673 | struct workqueue_struct *timer_work_queue; |
Robert Love | fd8f890 | 2012-05-22 19:06:16 -0700 | [diff] [blame] | 1674 | struct fcoe_ctlr *ctlr; |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 1675 | int rc = 0; |
| 1676 | |
Nithin Sujir | 6702ca1 | 2011-03-17 17:13:27 -0700 | [diff] [blame] | 1677 | rtnl_lock(); |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 1678 | mutex_lock(&bnx2fc_dev_lock); |
Bhanu Prakash Gollapudi | aea71a0 | 2011-07-26 14:51:39 -0700 | [diff] [blame] | 1679 | |
| 1680 | interface = bnx2fc_interface_lookup(netdev); |
Robert Love | fd8f890 | 2012-05-22 19:06:16 -0700 | [diff] [blame] | 1681 | ctlr = bnx2fc_to_ctlr(interface); |
| 1682 | if (!interface || !ctlr->lp) { |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 1683 | rc = -ENODEV; |
Bhanu Prakash Gollapudi | aea71a0 | 2011-07-26 14:51:39 -0700 | [diff] [blame] | 1684 | printk(KERN_ERR PFX "bnx2fc_destroy: interface or lport not found\n"); |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 1685 | goto netdev_err; |
| 1686 | } |
| 1687 | |
Bhanu Prakash Gollapudi | 2a7b29c | 2012-01-23 18:00:46 -0800 | [diff] [blame] | 1688 | timer_work_queue = interface->timer_work_queue; |
Bhanu Prakash Gollapudi | eccdcd0 | 2011-08-24 18:56:42 -0700 | [diff] [blame] | 1689 | __bnx2fc_destroy(interface); |
Bhanu Prakash Gollapudi | 2a7b29c | 2012-01-23 18:00:46 -0800 | [diff] [blame] | 1690 | destroy_workqueue(timer_work_queue); |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 1691 | |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 1692 | netdev_err: |
| 1693 | mutex_unlock(&bnx2fc_dev_lock); |
| 1694 | rtnl_unlock(); |
| 1695 | return rc; |
| 1696 | } |
| 1697 | |
John Meneghini | 847f9ea | 2022-01-14 23:00:44 -0500 | [diff] [blame] | 1698 | static void bnx2fc_port_destroy(struct fcoe_port *port) |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 1699 | { |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 1700 | struct fc_lport *lport; |
| 1701 | |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 1702 | lport = port->lport; |
John Meneghini | 847f9ea | 2022-01-14 23:00:44 -0500 | [diff] [blame] | 1703 | BNX2FC_HBA_DBG(lport, "Entered %s, destroying lport %p\n", __func__, lport); |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 1704 | |
Bhanu Prakash Gollapudi | 9be17fc | 2011-08-04 17:38:41 -0700 | [diff] [blame] | 1705 | bnx2fc_if_destroy(lport); |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 1706 | } |
| 1707 | |
| 1708 | static void bnx2fc_unbind_adapter_devices(struct bnx2fc_hba *hba) |
| 1709 | { |
| 1710 | bnx2fc_free_fw_resc(hba); |
| 1711 | bnx2fc_free_task_ctx(hba); |
| 1712 | } |
| 1713 | |
| 1714 | /** |
| 1715 | * bnx2fc_bind_adapter_devices - binds bnx2fc adapter with the associated |
| 1716 | * pci structure |
| 1717 | * |
| 1718 | * @hba: Adapter instance |
| 1719 | */ |
| 1720 | static int bnx2fc_bind_adapter_devices(struct bnx2fc_hba *hba) |
| 1721 | { |
| 1722 | if (bnx2fc_setup_task_ctx(hba)) |
| 1723 | goto mem_err; |
| 1724 | |
| 1725 | if (bnx2fc_setup_fw_resc(hba)) |
| 1726 | goto mem_err; |
| 1727 | |
| 1728 | return 0; |
| 1729 | mem_err: |
| 1730 | bnx2fc_unbind_adapter_devices(hba); |
| 1731 | return -ENOMEM; |
| 1732 | } |
| 1733 | |
| 1734 | static int bnx2fc_bind_pcidev(struct bnx2fc_hba *hba) |
| 1735 | { |
| 1736 | struct cnic_dev *cnic; |
Bhanu Prakash Gollapudi | c13d2b6 | 2013-03-08 13:28:51 -0800 | [diff] [blame] | 1737 | struct pci_dev *pdev; |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 1738 | |
| 1739 | if (!hba->cnic) { |
| 1740 | printk(KERN_ERR PFX "cnic is NULL\n"); |
| 1741 | return -ENODEV; |
| 1742 | } |
| 1743 | cnic = hba->cnic; |
Bhanu Prakash Gollapudi | c13d2b6 | 2013-03-08 13:28:51 -0800 | [diff] [blame] | 1744 | pdev = hba->pcidev = cnic->pcidev; |
| 1745 | if (!hba->pcidev) |
| 1746 | return -ENODEV; |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 1747 | |
Bhanu Prakash Gollapudi | c13d2b6 | 2013-03-08 13:28:51 -0800 | [diff] [blame] | 1748 | switch (pdev->device) { |
| 1749 | case PCI_DEVICE_ID_NX2_57710: |
| 1750 | strncpy(hba->chip_num, "BCM57710", BCM_CHIP_LEN); |
| 1751 | break; |
| 1752 | case PCI_DEVICE_ID_NX2_57711: |
| 1753 | strncpy(hba->chip_num, "BCM57711", BCM_CHIP_LEN); |
| 1754 | break; |
| 1755 | case PCI_DEVICE_ID_NX2_57712: |
| 1756 | case PCI_DEVICE_ID_NX2_57712_MF: |
| 1757 | case PCI_DEVICE_ID_NX2_57712_VF: |
| 1758 | strncpy(hba->chip_num, "BCM57712", BCM_CHIP_LEN); |
| 1759 | break; |
| 1760 | case PCI_DEVICE_ID_NX2_57800: |
| 1761 | case PCI_DEVICE_ID_NX2_57800_MF: |
| 1762 | case PCI_DEVICE_ID_NX2_57800_VF: |
| 1763 | strncpy(hba->chip_num, "BCM57800", BCM_CHIP_LEN); |
| 1764 | break; |
| 1765 | case PCI_DEVICE_ID_NX2_57810: |
| 1766 | case PCI_DEVICE_ID_NX2_57810_MF: |
| 1767 | case PCI_DEVICE_ID_NX2_57810_VF: |
| 1768 | strncpy(hba->chip_num, "BCM57810", BCM_CHIP_LEN); |
| 1769 | break; |
| 1770 | case PCI_DEVICE_ID_NX2_57840: |
| 1771 | case PCI_DEVICE_ID_NX2_57840_MF: |
| 1772 | case PCI_DEVICE_ID_NX2_57840_VF: |
| 1773 | case PCI_DEVICE_ID_NX2_57840_2_20: |
| 1774 | case PCI_DEVICE_ID_NX2_57840_4_10: |
| 1775 | strncpy(hba->chip_num, "BCM57840", BCM_CHIP_LEN); |
| 1776 | break; |
| 1777 | default: |
| 1778 | pr_err(PFX "Unknown device id 0x%x\n", pdev->device); |
| 1779 | break; |
| 1780 | } |
| 1781 | pci_dev_get(hba->pcidev); |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 1782 | return 0; |
| 1783 | } |
| 1784 | |
| 1785 | static void bnx2fc_unbind_pcidev(struct bnx2fc_hba *hba) |
| 1786 | { |
Bhanu Prakash Gollapudi | c13d2b6 | 2013-03-08 13:28:51 -0800 | [diff] [blame] | 1787 | if (hba->pcidev) { |
| 1788 | hba->chip_num[0] = '\0'; |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 1789 | pci_dev_put(hba->pcidev); |
Bhanu Prakash Gollapudi | c13d2b6 | 2013-03-08 13:28:51 -0800 | [diff] [blame] | 1790 | } |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 1791 | hba->pcidev = NULL; |
| 1792 | } |
| 1793 | |
Barak Witkowski | 2e499d3 | 2012-06-26 01:31:19 +0000 | [diff] [blame] | 1794 | /** |
| 1795 | * bnx2fc_ulp_get_stats - cnic callback to populate FCoE stats |
| 1796 | * |
Bhaskar Chowdhury | 5fae809 | 2021-03-22 12:05:30 +0530 | [diff] [blame] | 1797 | * @handle: transport handle pointing to adapter structure |
Barak Witkowski | 2e499d3 | 2012-06-26 01:31:19 +0000 | [diff] [blame] | 1798 | */ |
| 1799 | static int bnx2fc_ulp_get_stats(void *handle) |
| 1800 | { |
| 1801 | struct bnx2fc_hba *hba = handle; |
| 1802 | struct cnic_dev *cnic; |
| 1803 | struct fcoe_stats_info *stats_addr; |
| 1804 | |
| 1805 | if (!hba) |
| 1806 | return -EINVAL; |
| 1807 | |
| 1808 | cnic = hba->cnic; |
| 1809 | stats_addr = &cnic->stats_addr->fcoe_stat; |
| 1810 | if (!stats_addr) |
| 1811 | return -EINVAL; |
| 1812 | |
| 1813 | strncpy(stats_addr->version, BNX2FC_VERSION, |
| 1814 | sizeof(stats_addr->version)); |
| 1815 | stats_addr->txq_size = BNX2FC_SQ_WQES_MAX; |
| 1816 | stats_addr->rxq_size = BNX2FC_CQ_WQES_MAX; |
| 1817 | |
| 1818 | return 0; |
| 1819 | } |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 1820 | |
| 1821 | |
| 1822 | /** |
| 1823 | * bnx2fc_ulp_start - cnic callback to initialize & start adapter instance |
| 1824 | * |
Masanari Iida | 59e13d4 | 2012-04-25 00:24:16 +0900 | [diff] [blame] | 1825 | * @handle: transport handle pointing to adapter structure |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 1826 | * |
| 1827 | * This function maps adapter structure to pcidev structure and initiates |
| 1828 | * firmware handshake to enable/initialize on-chip FCoE components. |
| 1829 | * This bnx2fc - cnic interface api callback is used after following |
| 1830 | * conditions are met - |
| 1831 | * a) underlying network interface is up (marked by event NETDEV_UP |
| 1832 | * from netdev |
| 1833 | * b) bnx2fc adatper structure is registered. |
| 1834 | */ |
| 1835 | static void bnx2fc_ulp_start(void *handle) |
| 1836 | { |
| 1837 | struct bnx2fc_hba *hba = handle; |
Bhanu Prakash Gollapudi | aea71a0 | 2011-07-26 14:51:39 -0700 | [diff] [blame] | 1838 | struct bnx2fc_interface *interface; |
Robert Love | fd8f890 | 2012-05-22 19:06:16 -0700 | [diff] [blame] | 1839 | struct fcoe_ctlr *ctlr; |
Bhanu Prakash Gollapudi | aea71a0 | 2011-07-26 14:51:39 -0700 | [diff] [blame] | 1840 | struct fc_lport *lport; |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 1841 | |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 1842 | mutex_lock(&bnx2fc_dev_lock); |
| 1843 | |
Bhanu Prakash Gollapudi | aea71a0 | 2011-07-26 14:51:39 -0700 | [diff] [blame] | 1844 | if (!test_bit(BNX2FC_FLAG_FW_INIT_DONE, &hba->flags)) |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 1845 | bnx2fc_fw_init(hba); |
| 1846 | |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 1847 | BNX2FC_MISC_DBG("bnx2fc started.\n"); |
| 1848 | |
Bhanu Prakash Gollapudi | aea71a0 | 2011-07-26 14:51:39 -0700 | [diff] [blame] | 1849 | list_for_each_entry(interface, &if_list, list) { |
| 1850 | if (interface->hba == hba) { |
Robert Love | fd8f890 | 2012-05-22 19:06:16 -0700 | [diff] [blame] | 1851 | ctlr = bnx2fc_to_ctlr(interface); |
| 1852 | lport = ctlr->lp; |
Bhanu Prakash Gollapudi | aea71a0 | 2011-07-26 14:51:39 -0700 | [diff] [blame] | 1853 | /* Kick off Fabric discovery*/ |
| 1854 | printk(KERN_ERR PFX "ulp_init: start discovery\n"); |
| 1855 | lport->tt.frame_send = bnx2fc_xmit; |
| 1856 | bnx2fc_start_disc(interface); |
| 1857 | } |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 1858 | } |
Bhanu Prakash Gollapudi | aea71a0 | 2011-07-26 14:51:39 -0700 | [diff] [blame] | 1859 | |
| 1860 | mutex_unlock(&bnx2fc_dev_lock); |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 1861 | } |
| 1862 | |
| 1863 | static void bnx2fc_port_shutdown(struct fc_lport *lport) |
| 1864 | { |
| 1865 | BNX2FC_MISC_DBG("Entered %s\n", __func__); |
| 1866 | fc_fabric_logoff(lport); |
| 1867 | fc_lport_destroy(lport); |
| 1868 | } |
| 1869 | |
Bhanu Prakash Gollapudi | aea71a0 | 2011-07-26 14:51:39 -0700 | [diff] [blame] | 1870 | static void bnx2fc_stop(struct bnx2fc_interface *interface) |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 1871 | { |
Robert Love | fd8f890 | 2012-05-22 19:06:16 -0700 | [diff] [blame] | 1872 | struct fcoe_ctlr *ctlr = bnx2fc_to_ctlr(interface); |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 1873 | struct fc_lport *lport; |
| 1874 | struct fc_lport *vport; |
| 1875 | |
Bhanu Prakash Gollapudi | aea71a0 | 2011-07-26 14:51:39 -0700 | [diff] [blame] | 1876 | if (!test_bit(BNX2FC_FLAG_FW_INIT_DONE, &interface->hba->flags)) |
| 1877 | return; |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 1878 | |
Robert Love | fd8f890 | 2012-05-22 19:06:16 -0700 | [diff] [blame] | 1879 | lport = ctlr->lp; |
Bhanu Prakash Gollapudi | aea71a0 | 2011-07-26 14:51:39 -0700 | [diff] [blame] | 1880 | bnx2fc_port_shutdown(lport); |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 1881 | |
Bhanu Prakash Gollapudi | aea71a0 | 2011-07-26 14:51:39 -0700 | [diff] [blame] | 1882 | mutex_lock(&lport->lp_mutex); |
| 1883 | list_for_each_entry(vport, &lport->vports, list) |
| 1884 | fc_host_port_type(vport->host) = |
| 1885 | FC_PORTTYPE_UNKNOWN; |
| 1886 | mutex_unlock(&lport->lp_mutex); |
| 1887 | fc_host_port_type(lport->host) = FC_PORTTYPE_UNKNOWN; |
Robert Love | fd8f890 | 2012-05-22 19:06:16 -0700 | [diff] [blame] | 1888 | fcoe_ctlr_link_down(ctlr); |
Bhanu Prakash Gollapudi | aea71a0 | 2011-07-26 14:51:39 -0700 | [diff] [blame] | 1889 | fcoe_clean_pending_queue(lport); |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 1890 | } |
| 1891 | |
| 1892 | static int bnx2fc_fw_init(struct bnx2fc_hba *hba) |
| 1893 | { |
| 1894 | #define BNX2FC_INIT_POLL_TIME (1000 / HZ) |
| 1895 | int rc = -1; |
| 1896 | int i = HZ; |
| 1897 | |
| 1898 | rc = bnx2fc_bind_adapter_devices(hba); |
| 1899 | if (rc) { |
| 1900 | printk(KERN_ALERT PFX |
| 1901 | "bnx2fc_bind_adapter_devices failed - rc = %d\n", rc); |
| 1902 | goto err_out; |
| 1903 | } |
| 1904 | |
| 1905 | rc = bnx2fc_send_fw_fcoe_init_msg(hba); |
| 1906 | if (rc) { |
| 1907 | printk(KERN_ALERT PFX |
| 1908 | "bnx2fc_send_fw_fcoe_init_msg failed - rc = %d\n", rc); |
| 1909 | goto err_unbind; |
| 1910 | } |
| 1911 | |
| 1912 | /* |
| 1913 | * Wait until the adapter init message is complete, and adapter |
| 1914 | * state is UP. |
| 1915 | */ |
| 1916 | while (!test_bit(ADAPTER_STATE_UP, &hba->adapter_state) && i--) |
| 1917 | msleep(BNX2FC_INIT_POLL_TIME); |
| 1918 | |
| 1919 | if (!test_bit(ADAPTER_STATE_UP, &hba->adapter_state)) { |
| 1920 | printk(KERN_ERR PFX "bnx2fc_start: %s failed to initialize. " |
| 1921 | "Ignoring...\n", |
| 1922 | hba->cnic->netdev->name); |
| 1923 | rc = -1; |
| 1924 | goto err_unbind; |
| 1925 | } |
| 1926 | |
| 1927 | |
Bhanu Prakash Gollapudi | aea71a0 | 2011-07-26 14:51:39 -0700 | [diff] [blame] | 1928 | set_bit(BNX2FC_FLAG_FW_INIT_DONE, &hba->flags); |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 1929 | return 0; |
| 1930 | |
| 1931 | err_unbind: |
| 1932 | bnx2fc_unbind_adapter_devices(hba); |
| 1933 | err_out: |
| 1934 | return rc; |
| 1935 | } |
| 1936 | |
| 1937 | static void bnx2fc_fw_destroy(struct bnx2fc_hba *hba) |
| 1938 | { |
Bhanu Prakash Gollapudi | aea71a0 | 2011-07-26 14:51:39 -0700 | [diff] [blame] | 1939 | if (test_and_clear_bit(BNX2FC_FLAG_FW_INIT_DONE, &hba->flags)) { |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 1940 | if (bnx2fc_send_fw_fcoe_destroy_msg(hba) == 0) { |
Kees Cook | 1305910 | 2017-09-21 13:12:15 -0700 | [diff] [blame] | 1941 | timer_setup(&hba->destroy_timer, bnx2fc_destroy_timer, |
| 1942 | 0); |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 1943 | hba->destroy_timer.expires = BNX2FC_FW_TIMEOUT + |
| 1944 | jiffies; |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 1945 | add_timer(&hba->destroy_timer); |
| 1946 | wait_event_interruptible(hba->destroy_wait, |
Bhanu Prakash Gollapudi | aea71a0 | 2011-07-26 14:51:39 -0700 | [diff] [blame] | 1947 | test_bit(BNX2FC_FLAG_DESTROY_CMPL, |
| 1948 | &hba->flags)); |
Bhanu Prakash Gollapudi | cd703ae | 2011-08-04 17:38:43 -0700 | [diff] [blame] | 1949 | clear_bit(BNX2FC_FLAG_DESTROY_CMPL, &hba->flags); |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 1950 | /* This should never happen */ |
| 1951 | if (signal_pending(current)) |
| 1952 | flush_signals(current); |
| 1953 | |
| 1954 | del_timer_sync(&hba->destroy_timer); |
| 1955 | } |
| 1956 | bnx2fc_unbind_adapter_devices(hba); |
| 1957 | } |
| 1958 | } |
| 1959 | |
| 1960 | /** |
| 1961 | * bnx2fc_ulp_stop - cnic callback to shutdown adapter instance |
| 1962 | * |
| 1963 | * @handle: transport handle pointing to adapter structure |
| 1964 | * |
| 1965 | * Driver checks if adapter is already in shutdown mode, if not start |
| 1966 | * the shutdown process. |
| 1967 | */ |
| 1968 | static void bnx2fc_ulp_stop(void *handle) |
| 1969 | { |
Bhanu Prakash Gollapudi | aea71a0 | 2011-07-26 14:51:39 -0700 | [diff] [blame] | 1970 | struct bnx2fc_hba *hba = handle; |
| 1971 | struct bnx2fc_interface *interface; |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 1972 | |
| 1973 | printk(KERN_ERR "ULP_STOP\n"); |
| 1974 | |
| 1975 | mutex_lock(&bnx2fc_dev_lock); |
Bhanu Prakash Gollapudi | aea71a0 | 2011-07-26 14:51:39 -0700 | [diff] [blame] | 1976 | if (!test_bit(BNX2FC_FLAG_FW_INIT_DONE, &hba->flags)) |
| 1977 | goto exit; |
| 1978 | list_for_each_entry(interface, &if_list, list) { |
| 1979 | if (interface->hba == hba) |
| 1980 | bnx2fc_stop(interface); |
| 1981 | } |
| 1982 | BUG_ON(hba->num_ofld_sess != 0); |
| 1983 | |
| 1984 | mutex_lock(&hba->hba_mutex); |
| 1985 | clear_bit(ADAPTER_STATE_UP, &hba->adapter_state); |
| 1986 | clear_bit(ADAPTER_STATE_GOING_DOWN, |
| 1987 | &hba->adapter_state); |
| 1988 | |
| 1989 | clear_bit(ADAPTER_STATE_READY, &hba->adapter_state); |
| 1990 | mutex_unlock(&hba->hba_mutex); |
| 1991 | |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 1992 | bnx2fc_fw_destroy(hba); |
Bhanu Prakash Gollapudi | aea71a0 | 2011-07-26 14:51:39 -0700 | [diff] [blame] | 1993 | exit: |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 1994 | mutex_unlock(&bnx2fc_dev_lock); |
| 1995 | } |
| 1996 | |
Bhanu Prakash Gollapudi | aea71a0 | 2011-07-26 14:51:39 -0700 | [diff] [blame] | 1997 | static void bnx2fc_start_disc(struct bnx2fc_interface *interface) |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 1998 | { |
Robert Love | fd8f890 | 2012-05-22 19:06:16 -0700 | [diff] [blame] | 1999 | struct fcoe_ctlr *ctlr = bnx2fc_to_ctlr(interface); |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 2000 | struct fc_lport *lport; |
| 2001 | int wait_cnt = 0; |
| 2002 | |
| 2003 | BNX2FC_MISC_DBG("Entered %s\n", __func__); |
| 2004 | /* Kick off FIP/FLOGI */ |
Bhanu Prakash Gollapudi | aea71a0 | 2011-07-26 14:51:39 -0700 | [diff] [blame] | 2005 | if (!test_bit(BNX2FC_FLAG_FW_INIT_DONE, &interface->hba->flags)) { |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 2006 | printk(KERN_ERR PFX "Init not done yet\n"); |
| 2007 | return; |
| 2008 | } |
| 2009 | |
Robert Love | fd8f890 | 2012-05-22 19:06:16 -0700 | [diff] [blame] | 2010 | lport = ctlr->lp; |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 2011 | BNX2FC_HBA_DBG(lport, "calling fc_fabric_login\n"); |
| 2012 | |
Bhanu Prakash Gollapudi | 8a5badf | 2011-08-30 15:54:48 -0700 | [diff] [blame] | 2013 | if (!bnx2fc_link_ok(lport) && interface->enabled) { |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 2014 | BNX2FC_HBA_DBG(lport, "ctlr_link_up\n"); |
Robert Love | fd8f890 | 2012-05-22 19:06:16 -0700 | [diff] [blame] | 2015 | fcoe_ctlr_link_up(ctlr); |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 2016 | fc_host_port_type(lport->host) = FC_PORTTYPE_NPORT; |
Bhanu Prakash Gollapudi | aea71a0 | 2011-07-26 14:51:39 -0700 | [diff] [blame] | 2017 | set_bit(ADAPTER_STATE_READY, &interface->hba->adapter_state); |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 2018 | } |
| 2019 | |
| 2020 | /* wait for the FCF to be selected before issuing FLOGI */ |
Robert Love | fd8f890 | 2012-05-22 19:06:16 -0700 | [diff] [blame] | 2021 | while (!ctlr->sel_fcf) { |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 2022 | msleep(250); |
| 2023 | /* give up after 3 secs */ |
| 2024 | if (++wait_cnt > 12) |
| 2025 | break; |
| 2026 | } |
Bhanu Prakash Gollapudi | 627e628 | 2011-08-04 17:38:35 -0700 | [diff] [blame] | 2027 | |
| 2028 | /* Reset max receive frame size to default */ |
| 2029 | if (fc_set_mfs(lport, BNX2FC_MFS)) |
| 2030 | return; |
| 2031 | |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 2032 | fc_lport_init(lport); |
| 2033 | fc_fabric_login(lport); |
| 2034 | } |
| 2035 | |
| 2036 | |
| 2037 | /** |
| 2038 | * bnx2fc_ulp_init - Initialize an adapter instance |
| 2039 | * |
| 2040 | * @dev : cnic device handle |
| 2041 | * Called from cnic_register_driver() context to initialize all |
| 2042 | * enumerated cnic devices. This routine allocates adapter structure |
| 2043 | * and other device specific resources. |
| 2044 | */ |
| 2045 | static void bnx2fc_ulp_init(struct cnic_dev *dev) |
| 2046 | { |
| 2047 | struct bnx2fc_hba *hba; |
| 2048 | int rc = 0; |
| 2049 | |
| 2050 | BNX2FC_MISC_DBG("Entered %s\n", __func__); |
| 2051 | /* bnx2fc works only when bnx2x is loaded */ |
Bhanu Prakash Gollapudi | aea71a0 | 2011-07-26 14:51:39 -0700 | [diff] [blame] | 2052 | if (!test_bit(CNIC_F_BNX2X_CLASS, &dev->flags) || |
| 2053 | (dev->max_fcoe_conn == 0)) { |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 2054 | printk(KERN_ERR PFX "bnx2fc FCoE not supported on %s," |
Bhanu Prakash Gollapudi | aea71a0 | 2011-07-26 14:51:39 -0700 | [diff] [blame] | 2055 | " flags: %lx fcoe_conn: %d\n", |
| 2056 | dev->netdev->name, dev->flags, dev->max_fcoe_conn); |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 2057 | return; |
| 2058 | } |
| 2059 | |
Bhanu Prakash Gollapudi | aea71a0 | 2011-07-26 14:51:39 -0700 | [diff] [blame] | 2060 | hba = bnx2fc_hba_create(dev); |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 2061 | if (!hba) { |
| 2062 | printk(KERN_ERR PFX "hba initialization failed\n"); |
| 2063 | return; |
| 2064 | } |
| 2065 | |
Chad Dupuis | f72464d | 2016-04-07 09:07:58 -0400 | [diff] [blame] | 2066 | pr_info(PFX "FCoE initialized for %s.\n", dev->netdev->name); |
| 2067 | |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 2068 | /* Add HBA to the adapter list */ |
| 2069 | mutex_lock(&bnx2fc_dev_lock); |
Bhanu Prakash Gollapudi | aea71a0 | 2011-07-26 14:51:39 -0700 | [diff] [blame] | 2070 | list_add_tail(&hba->list, &adapter_list); |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 2071 | adapter_count++; |
| 2072 | mutex_unlock(&bnx2fc_dev_lock); |
| 2073 | |
Barak Witkowski | 2e499d3 | 2012-06-26 01:31:19 +0000 | [diff] [blame] | 2074 | dev->fcoe_cap = &hba->fcoe_cap; |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 2075 | clear_bit(BNX2FC_CNIC_REGISTERED, &hba->reg_with_cnic); |
| 2076 | rc = dev->register_device(dev, CNIC_ULP_FCOE, |
| 2077 | (void *) hba); |
| 2078 | if (rc) |
Bhanu Prakash Gollapudi | b2a554f | 2011-06-27 23:30:53 -0700 | [diff] [blame] | 2079 | printk(KERN_ERR PFX "register_device failed, rc = %d\n", rc); |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 2080 | else |
| 2081 | set_bit(BNX2FC_CNIC_REGISTERED, &hba->reg_with_cnic); |
| 2082 | } |
| 2083 | |
Eddie Wai | 0680810 | 2013-09-25 22:01:20 -0700 | [diff] [blame] | 2084 | /* Assumes rtnl_lock and the bnx2fc_dev_lock are already taken */ |
| 2085 | static int __bnx2fc_disable(struct fcoe_ctlr *ctlr) |
| 2086 | { |
| 2087 | struct bnx2fc_interface *interface = fcoe_ctlr_priv(ctlr); |
| 2088 | |
Kaixu Xia | cb2b4e8 | 2020-11-08 00:52:00 +0800 | [diff] [blame] | 2089 | if (interface->enabled) { |
Eddie Wai | 0680810 | 2013-09-25 22:01:20 -0700 | [diff] [blame] | 2090 | if (!ctlr->lp) { |
| 2091 | pr_err(PFX "__bnx2fc_disable: lport not found\n"); |
| 2092 | return -ENODEV; |
| 2093 | } else { |
| 2094 | interface->enabled = false; |
| 2095 | fcoe_ctlr_link_down(ctlr); |
| 2096 | fcoe_clean_pending_queue(ctlr->lp); |
| 2097 | } |
| 2098 | } |
| 2099 | return 0; |
| 2100 | } |
| 2101 | |
Lee Jones | ca63d8e | 2020-07-13 08:46:23 +0100 | [diff] [blame] | 2102 | /* |
Robert Love | 6e89ea3 | 2012-11-27 06:53:40 +0000 | [diff] [blame] | 2103 | * Deperecated: Use bnx2fc_enabled() |
| 2104 | */ |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 2105 | static int bnx2fc_disable(struct net_device *netdev) |
| 2106 | { |
Bhanu Prakash Gollapudi | aea71a0 | 2011-07-26 14:51:39 -0700 | [diff] [blame] | 2107 | struct bnx2fc_interface *interface; |
Robert Love | fd8f890 | 2012-05-22 19:06:16 -0700 | [diff] [blame] | 2108 | struct fcoe_ctlr *ctlr; |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 2109 | int rc = 0; |
| 2110 | |
Nithin Sujir | 6702ca1 | 2011-03-17 17:13:27 -0700 | [diff] [blame] | 2111 | rtnl_lock(); |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 2112 | mutex_lock(&bnx2fc_dev_lock); |
| 2113 | |
Bhanu Prakash Gollapudi | aea71a0 | 2011-07-26 14:51:39 -0700 | [diff] [blame] | 2114 | interface = bnx2fc_interface_lookup(netdev); |
Robert Love | fd8f890 | 2012-05-22 19:06:16 -0700 | [diff] [blame] | 2115 | ctlr = bnx2fc_to_ctlr(interface); |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 2116 | |
Eddie Wai | 0680810 | 2013-09-25 22:01:20 -0700 | [diff] [blame] | 2117 | if (!interface) { |
| 2118 | rc = -ENODEV; |
| 2119 | pr_err(PFX "bnx2fc_disable: interface not found\n"); |
| 2120 | } else { |
| 2121 | rc = __bnx2fc_disable(ctlr); |
| 2122 | } |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 2123 | mutex_unlock(&bnx2fc_dev_lock); |
| 2124 | rtnl_unlock(); |
| 2125 | return rc; |
| 2126 | } |
| 2127 | |
Joe Carnuccio | 2971ff6 | 2015-08-04 09:37:30 +0300 | [diff] [blame] | 2128 | static uint bnx2fc_npiv_create_vports(struct fc_lport *lport, |
| 2129 | struct cnic_fc_npiv_tbl *npiv_tbl) |
| 2130 | { |
| 2131 | struct fc_vport_identifiers vpid; |
| 2132 | uint i, created = 0; |
Chad Dupuis | 59fb870 | 2017-06-26 08:59:35 -0700 | [diff] [blame] | 2133 | u64 wwnn = 0; |
| 2134 | char wwpn_str[32]; |
| 2135 | char wwnn_str[32]; |
Joe Carnuccio | 2971ff6 | 2015-08-04 09:37:30 +0300 | [diff] [blame] | 2136 | |
| 2137 | if (npiv_tbl->count > MAX_NPIV_ENTRIES) { |
| 2138 | BNX2FC_HBA_DBG(lport, "Exceeded count max of npiv table\n"); |
| 2139 | goto done; |
| 2140 | } |
| 2141 | |
| 2142 | /* Sanity check the first entry to make sure it's not 0 */ |
| 2143 | if (wwn_to_u64(npiv_tbl->wwnn[0]) == 0 && |
| 2144 | wwn_to_u64(npiv_tbl->wwpn[0]) == 0) { |
| 2145 | BNX2FC_HBA_DBG(lport, "First NPIV table entries invalid.\n"); |
| 2146 | goto done; |
| 2147 | } |
| 2148 | |
| 2149 | vpid.roles = FC_PORT_ROLE_FCP_INITIATOR; |
| 2150 | vpid.vport_type = FC_PORTTYPE_NPIV; |
| 2151 | vpid.disable = false; |
| 2152 | |
| 2153 | for (i = 0; i < npiv_tbl->count; i++) { |
Chad Dupuis | 59fb870 | 2017-06-26 08:59:35 -0700 | [diff] [blame] | 2154 | wwnn = wwn_to_u64(npiv_tbl->wwnn[i]); |
| 2155 | if (wwnn == 0) { |
| 2156 | /* |
| 2157 | * If we get a 0 element from for the WWNN then assume |
| 2158 | * the WWNN should be the same as the physical port. |
| 2159 | */ |
| 2160 | wwnn = lport->wwnn; |
| 2161 | } |
| 2162 | vpid.node_name = wwnn; |
Joe Carnuccio | 2971ff6 | 2015-08-04 09:37:30 +0300 | [diff] [blame] | 2163 | vpid.port_name = wwn_to_u64(npiv_tbl->wwpn[i]); |
| 2164 | scnprintf(vpid.symbolic_name, sizeof(vpid.symbolic_name), |
| 2165 | "NPIV[%u]:%016llx-%016llx", |
| 2166 | created, vpid.port_name, vpid.node_name); |
Chad Dupuis | 59fb870 | 2017-06-26 08:59:35 -0700 | [diff] [blame] | 2167 | fcoe_wwn_to_str(vpid.node_name, wwnn_str, sizeof(wwnn_str)); |
| 2168 | fcoe_wwn_to_str(vpid.port_name, wwpn_str, sizeof(wwpn_str)); |
| 2169 | BNX2FC_HBA_DBG(lport, "Creating vport %s:%s.\n", wwnn_str, |
| 2170 | wwpn_str); |
Joe Carnuccio | 2971ff6 | 2015-08-04 09:37:30 +0300 | [diff] [blame] | 2171 | if (fc_vport_create(lport->host, 0, &vpid)) |
| 2172 | created++; |
| 2173 | else |
| 2174 | BNX2FC_HBA_DBG(lport, "Failed to create vport\n"); |
| 2175 | } |
| 2176 | done: |
| 2177 | return created; |
| 2178 | } |
| 2179 | |
Eddie Wai | 0680810 | 2013-09-25 22:01:20 -0700 | [diff] [blame] | 2180 | static int __bnx2fc_enable(struct fcoe_ctlr *ctlr) |
| 2181 | { |
| 2182 | struct bnx2fc_interface *interface = fcoe_ctlr_priv(ctlr); |
Joe Carnuccio | 2971ff6 | 2015-08-04 09:37:30 +0300 | [diff] [blame] | 2183 | struct bnx2fc_hba *hba; |
Arnd Bergmann | 720ba80 | 2015-10-07 15:11:04 +0200 | [diff] [blame] | 2184 | struct cnic_fc_npiv_tbl *npiv_tbl; |
Joe Carnuccio | 2971ff6 | 2015-08-04 09:37:30 +0300 | [diff] [blame] | 2185 | struct fc_lport *lport; |
Eddie Wai | 0680810 | 2013-09-25 22:01:20 -0700 | [diff] [blame] | 2186 | |
Kaixu Xia | cb2b4e8 | 2020-11-08 00:52:00 +0800 | [diff] [blame] | 2187 | if (!interface->enabled) { |
Eddie Wai | 0680810 | 2013-09-25 22:01:20 -0700 | [diff] [blame] | 2188 | if (!ctlr->lp) { |
| 2189 | pr_err(PFX "__bnx2fc_enable: lport not found\n"); |
| 2190 | return -ENODEV; |
| 2191 | } else if (!bnx2fc_link_ok(ctlr->lp)) { |
| 2192 | fcoe_ctlr_link_up(ctlr); |
| 2193 | interface->enabled = true; |
| 2194 | } |
| 2195 | } |
Joe Carnuccio | 2971ff6 | 2015-08-04 09:37:30 +0300 | [diff] [blame] | 2196 | |
| 2197 | /* Create static NPIV ports if any are contained in NVRAM */ |
| 2198 | hba = interface->hba; |
| 2199 | lport = ctlr->lp; |
| 2200 | |
| 2201 | if (!hba) |
| 2202 | goto done; |
| 2203 | |
| 2204 | if (!hba->cnic) |
| 2205 | goto done; |
| 2206 | |
| 2207 | if (!lport) |
| 2208 | goto done; |
| 2209 | |
| 2210 | if (!lport->host) |
| 2211 | goto done; |
| 2212 | |
| 2213 | if (!hba->cnic->get_fc_npiv_tbl) |
| 2214 | goto done; |
| 2215 | |
Arnd Bergmann | 720ba80 | 2015-10-07 15:11:04 +0200 | [diff] [blame] | 2216 | npiv_tbl = kzalloc(sizeof(struct cnic_fc_npiv_tbl), GFP_KERNEL); |
| 2217 | if (!npiv_tbl) |
Joe Carnuccio | 2971ff6 | 2015-08-04 09:37:30 +0300 | [diff] [blame] | 2218 | goto done; |
| 2219 | |
Arnd Bergmann | 720ba80 | 2015-10-07 15:11:04 +0200 | [diff] [blame] | 2220 | if (hba->cnic->get_fc_npiv_tbl(hba->cnic, npiv_tbl)) |
| 2221 | goto done_free; |
| 2222 | |
| 2223 | bnx2fc_npiv_create_vports(lport, npiv_tbl); |
| 2224 | done_free: |
| 2225 | kfree(npiv_tbl); |
Joe Carnuccio | 2971ff6 | 2015-08-04 09:37:30 +0300 | [diff] [blame] | 2226 | done: |
Eddie Wai | 0680810 | 2013-09-25 22:01:20 -0700 | [diff] [blame] | 2227 | return 0; |
| 2228 | } |
| 2229 | |
Lee Jones | ca63d8e | 2020-07-13 08:46:23 +0100 | [diff] [blame] | 2230 | /* |
Robert Love | 6e89ea3 | 2012-11-27 06:53:40 +0000 | [diff] [blame] | 2231 | * Deprecated: Use bnx2fc_enabled() |
| 2232 | */ |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 2233 | static int bnx2fc_enable(struct net_device *netdev) |
| 2234 | { |
Bhanu Prakash Gollapudi | aea71a0 | 2011-07-26 14:51:39 -0700 | [diff] [blame] | 2235 | struct bnx2fc_interface *interface; |
Robert Love | fd8f890 | 2012-05-22 19:06:16 -0700 | [diff] [blame] | 2236 | struct fcoe_ctlr *ctlr; |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 2237 | int rc = 0; |
| 2238 | |
Nithin Sujir | 6702ca1 | 2011-03-17 17:13:27 -0700 | [diff] [blame] | 2239 | rtnl_lock(); |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 2240 | mutex_lock(&bnx2fc_dev_lock); |
| 2241 | |
Bhanu Prakash Gollapudi | aea71a0 | 2011-07-26 14:51:39 -0700 | [diff] [blame] | 2242 | interface = bnx2fc_interface_lookup(netdev); |
Robert Love | fd8f890 | 2012-05-22 19:06:16 -0700 | [diff] [blame] | 2243 | ctlr = bnx2fc_to_ctlr(interface); |
Eddie Wai | 0680810 | 2013-09-25 22:01:20 -0700 | [diff] [blame] | 2244 | if (!interface) { |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 2245 | rc = -ENODEV; |
Eddie Wai | 0680810 | 2013-09-25 22:01:20 -0700 | [diff] [blame] | 2246 | pr_err(PFX "bnx2fc_enable: interface not found\n"); |
| 2247 | } else { |
| 2248 | rc = __bnx2fc_enable(ctlr); |
Bhanu Prakash Gollapudi | 8a5badf | 2011-08-30 15:54:48 -0700 | [diff] [blame] | 2249 | } |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 2250 | |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 2251 | mutex_unlock(&bnx2fc_dev_lock); |
| 2252 | rtnl_unlock(); |
| 2253 | return rc; |
| 2254 | } |
| 2255 | |
| 2256 | /** |
Robert Love | 6e89ea3 | 2012-11-27 06:53:40 +0000 | [diff] [blame] | 2257 | * bnx2fc_ctlr_enabled() - Enable or disable an FCoE Controller |
| 2258 | * @cdev: The FCoE Controller that is being enabled or disabled |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 2259 | * |
Robert Love | 6e89ea3 | 2012-11-27 06:53:40 +0000 | [diff] [blame] | 2260 | * fcoe_sysfs will ensure that the state of 'enabled' has |
| 2261 | * changed, so no checking is necessary here. This routine simply |
| 2262 | * calls fcoe_enable or fcoe_disable, both of which are deprecated. |
| 2263 | * When those routines are removed the functionality can be merged |
| 2264 | * here. |
| 2265 | */ |
| 2266 | static int bnx2fc_ctlr_enabled(struct fcoe_ctlr_device *cdev) |
| 2267 | { |
| 2268 | struct fcoe_ctlr *ctlr = fcoe_ctlr_device_priv(cdev); |
Robert Love | 6e89ea3 | 2012-11-27 06:53:40 +0000 | [diff] [blame] | 2269 | |
| 2270 | switch (cdev->enabled) { |
| 2271 | case FCOE_CTLR_ENABLED: |
Eddie Wai | 0680810 | 2013-09-25 22:01:20 -0700 | [diff] [blame] | 2272 | return __bnx2fc_enable(ctlr); |
Robert Love | 6e89ea3 | 2012-11-27 06:53:40 +0000 | [diff] [blame] | 2273 | case FCOE_CTLR_DISABLED: |
Eddie Wai | 0680810 | 2013-09-25 22:01:20 -0700 | [diff] [blame] | 2274 | return __bnx2fc_disable(ctlr); |
Robert Love | 6e89ea3 | 2012-11-27 06:53:40 +0000 | [diff] [blame] | 2275 | case FCOE_CTLR_UNUSED: |
| 2276 | default: |
| 2277 | return -ENOTSUPP; |
Tom Rix | 4a9435b | 2020-11-01 06:38:12 -0800 | [diff] [blame] | 2278 | } |
Robert Love | 6e89ea3 | 2012-11-27 06:53:40 +0000 | [diff] [blame] | 2279 | } |
| 2280 | |
| 2281 | enum bnx2fc_create_link_state { |
| 2282 | BNX2FC_CREATE_LINK_DOWN, |
| 2283 | BNX2FC_CREATE_LINK_UP, |
| 2284 | }; |
| 2285 | |
| 2286 | /** |
| 2287 | * _bnx2fc_create() - Create bnx2fc FCoE interface |
| 2288 | * @netdev : The net_device object the Ethernet interface to create on |
| 2289 | * @fip_mode: The FIP mode for this creation |
| 2290 | * @link_state: The ctlr link state on creation |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 2291 | * |
Robert Love | 6e89ea3 | 2012-11-27 06:53:40 +0000 | [diff] [blame] | 2292 | * Called from either the libfcoe 'create' module parameter |
| 2293 | * via fcoe_create or from fcoe_syfs's ctlr_create file. |
| 2294 | * |
| 2295 | * libfcoe's 'create' module parameter is deprecated so some |
| 2296 | * consolidation of code can be done when that interface is |
| 2297 | * removed. |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 2298 | * |
| 2299 | * Returns: 0 for success |
| 2300 | */ |
Robert Love | 6e89ea3 | 2012-11-27 06:53:40 +0000 | [diff] [blame] | 2301 | static int _bnx2fc_create(struct net_device *netdev, |
Hannes Reinecke | 1917d42 | 2016-07-04 10:29:19 +0200 | [diff] [blame] | 2302 | enum fip_mode fip_mode, |
Robert Love | 6e89ea3 | 2012-11-27 06:53:40 +0000 | [diff] [blame] | 2303 | enum bnx2fc_create_link_state link_state) |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 2304 | { |
Robert Love | 6e89ea3 | 2012-11-27 06:53:40 +0000 | [diff] [blame] | 2305 | struct fcoe_ctlr_device *cdev; |
Robert Love | fd8f890 | 2012-05-22 19:06:16 -0700 | [diff] [blame] | 2306 | struct fcoe_ctlr *ctlr; |
Bhanu Prakash Gollapudi | aea71a0 | 2011-07-26 14:51:39 -0700 | [diff] [blame] | 2307 | struct bnx2fc_interface *interface; |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 2308 | struct bnx2fc_hba *hba; |
Bhanu Prakash Gollapudi | 7adc5a3 | 2012-06-04 16:15:44 -0700 | [diff] [blame] | 2309 | struct net_device *phys_dev = netdev; |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 2310 | struct fc_lport *lport; |
| 2311 | struct ethtool_drvinfo drvinfo; |
| 2312 | int rc = 0; |
Bhanu Prakash Gollapudi | 7adc5a3 | 2012-06-04 16:15:44 -0700 | [diff] [blame] | 2313 | int vlan_id = 0; |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 2314 | |
| 2315 | BNX2FC_MISC_DBG("Entered bnx2fc_create\n"); |
| 2316 | if (fip_mode != FIP_MODE_FABRIC) { |
| 2317 | printk(KERN_ERR "fip mode not FABRIC\n"); |
| 2318 | return -EIO; |
| 2319 | } |
| 2320 | |
Nithin Sujir | 6702ca1 | 2011-03-17 17:13:27 -0700 | [diff] [blame] | 2321 | rtnl_lock(); |
| 2322 | |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 2323 | mutex_lock(&bnx2fc_dev_lock); |
| 2324 | |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 2325 | if (!try_module_get(THIS_MODULE)) { |
| 2326 | rc = -EINVAL; |
| 2327 | goto mod_err; |
| 2328 | } |
| 2329 | |
| 2330 | /* obtain physical netdev */ |
Parav Pandit | d0d7b10 | 2017-02-04 11:00:49 -0600 | [diff] [blame] | 2331 | if (is_vlan_dev(netdev)) |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 2332 | phys_dev = vlan_dev_real_dev(netdev); |
Bhanu Prakash Gollapudi | 7adc5a3 | 2012-06-04 16:15:44 -0700 | [diff] [blame] | 2333 | |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 2334 | /* verify if the physical device is a netxtreme2 device */ |
| 2335 | if (phys_dev->ethtool_ops && phys_dev->ethtool_ops->get_drvinfo) { |
| 2336 | memset(&drvinfo, 0, sizeof(drvinfo)); |
| 2337 | phys_dev->ethtool_ops->get_drvinfo(phys_dev, &drvinfo); |
Bhanu Prakash Gollapudi | aea71a0 | 2011-07-26 14:51:39 -0700 | [diff] [blame] | 2338 | if (strncmp(drvinfo.driver, "bnx2x", strlen("bnx2x"))) { |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 2339 | printk(KERN_ERR PFX "Not a netxtreme2 device\n"); |
| 2340 | rc = -EINVAL; |
| 2341 | goto netdev_err; |
| 2342 | } |
| 2343 | } else { |
| 2344 | printk(KERN_ERR PFX "unable to obtain drv_info\n"); |
| 2345 | rc = -EINVAL; |
| 2346 | goto netdev_err; |
| 2347 | } |
| 2348 | |
Bhanu Prakash Gollapudi | aea71a0 | 2011-07-26 14:51:39 -0700 | [diff] [blame] | 2349 | /* obtain interface and initialize rest of the structure */ |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 2350 | hba = bnx2fc_hba_lookup(phys_dev); |
| 2351 | if (!hba) { |
| 2352 | rc = -ENODEV; |
| 2353 | printk(KERN_ERR PFX "bnx2fc_create: hba not found\n"); |
| 2354 | goto netdev_err; |
| 2355 | } |
| 2356 | |
Bhanu Prakash Gollapudi | aea71a0 | 2011-07-26 14:51:39 -0700 | [diff] [blame] | 2357 | if (bnx2fc_interface_lookup(netdev)) { |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 2358 | rc = -EEXIST; |
| 2359 | goto netdev_err; |
| 2360 | } |
| 2361 | |
Bhanu Prakash Gollapudi | aea71a0 | 2011-07-26 14:51:39 -0700 | [diff] [blame] | 2362 | interface = bnx2fc_interface_create(hba, netdev, fip_mode); |
| 2363 | if (!interface) { |
| 2364 | printk(KERN_ERR PFX "bnx2fc_interface_create failed\n"); |
Dan Carpenter | 2043e1f | 2014-11-04 13:37:59 +0300 | [diff] [blame] | 2365 | rc = -ENOMEM; |
Dan Carpenter | 9ae4f84 | 2018-11-01 08:25:30 +0300 | [diff] [blame] | 2366 | goto netdev_err; |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 2367 | } |
| 2368 | |
Parav Pandit | d0d7b10 | 2017-02-04 11:00:49 -0600 | [diff] [blame] | 2369 | if (is_vlan_dev(netdev)) { |
Bhanu Prakash Gollapudi | 7adc5a3 | 2012-06-04 16:15:44 -0700 | [diff] [blame] | 2370 | vlan_id = vlan_dev_vlan_id(netdev); |
| 2371 | interface->vlan_enabled = 1; |
| 2372 | } |
| 2373 | |
Robert Love | fd8f890 | 2012-05-22 19:06:16 -0700 | [diff] [blame] | 2374 | ctlr = bnx2fc_to_ctlr(interface); |
Robert Love | 01bdcb6 | 2013-03-25 11:00:26 -0700 | [diff] [blame] | 2375 | cdev = fcoe_ctlr_to_ctlr_dev(ctlr); |
Bhanu Prakash Gollapudi | aea71a0 | 2011-07-26 14:51:39 -0700 | [diff] [blame] | 2376 | interface->vlan_id = vlan_id; |
Joe Carnuccio | 10755d3 | 2016-04-07 09:07:56 -0400 | [diff] [blame] | 2377 | interface->tm_timeout = BNX2FC_TM_TIMEOUT; |
Bhanu Prakash Gollapudi | aea71a0 | 2011-07-26 14:51:39 -0700 | [diff] [blame] | 2378 | |
| 2379 | interface->timer_work_queue = |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 2380 | create_singlethread_workqueue("bnx2fc_timer_wq"); |
Bhanu Prakash Gollapudi | aea71a0 | 2011-07-26 14:51:39 -0700 | [diff] [blame] | 2381 | if (!interface->timer_work_queue) { |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 2382 | printk(KERN_ERR PFX "ulp_init could not create timer_wq\n"); |
| 2383 | rc = -EINVAL; |
| 2384 | goto ifput_err; |
| 2385 | } |
| 2386 | |
Robert Love | 01bdcb6 | 2013-03-25 11:00:26 -0700 | [diff] [blame] | 2387 | lport = bnx2fc_if_create(interface, &cdev->dev, 0); |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 2388 | if (!lport) { |
| 2389 | printk(KERN_ERR PFX "Failed to create interface (%s)\n", |
| 2390 | netdev->name); |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 2391 | rc = -EINVAL; |
| 2392 | goto if_create_err; |
| 2393 | } |
| 2394 | |
Bhanu Prakash Gollapudi | aea71a0 | 2011-07-26 14:51:39 -0700 | [diff] [blame] | 2395 | /* Add interface to if_list */ |
| 2396 | list_add_tail(&interface->list, &if_list); |
| 2397 | |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 2398 | lport->boot_time = jiffies; |
| 2399 | |
| 2400 | /* Make this master N_port */ |
Robert Love | fd8f890 | 2012-05-22 19:06:16 -0700 | [diff] [blame] | 2401 | ctlr->lp = lport; |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 2402 | |
Robert Love | 6e89ea3 | 2012-11-27 06:53:40 +0000 | [diff] [blame] | 2403 | if (link_state == BNX2FC_CREATE_LINK_UP) |
| 2404 | cdev->enabled = FCOE_CTLR_ENABLED; |
| 2405 | else |
| 2406 | cdev->enabled = FCOE_CTLR_DISABLED; |
| 2407 | |
| 2408 | if (link_state == BNX2FC_CREATE_LINK_UP && |
| 2409 | !bnx2fc_link_ok(lport)) { |
Robert Love | fd8f890 | 2012-05-22 19:06:16 -0700 | [diff] [blame] | 2410 | fcoe_ctlr_link_up(ctlr); |
Bhanu Prakash Gollapudi | 8a5badf | 2011-08-30 15:54:48 -0700 | [diff] [blame] | 2411 | fc_host_port_type(lport->host) = FC_PORTTYPE_NPORT; |
| 2412 | set_bit(ADAPTER_STATE_READY, &interface->hba->adapter_state); |
| 2413 | } |
| 2414 | |
Bhanu Prakash Gollapudi | aea71a0 | 2011-07-26 14:51:39 -0700 | [diff] [blame] | 2415 | BNX2FC_HBA_DBG(lport, "create: START DISC\n"); |
| 2416 | bnx2fc_start_disc(interface); |
Robert Love | 6e89ea3 | 2012-11-27 06:53:40 +0000 | [diff] [blame] | 2417 | |
| 2418 | if (link_state == BNX2FC_CREATE_LINK_UP) |
| 2419 | interface->enabled = true; |
| 2420 | |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 2421 | /* |
| 2422 | * Release from kref_init in bnx2fc_interface_setup, on success |
| 2423 | * lport should be holding a reference taken in bnx2fc_if_create |
| 2424 | */ |
Bhanu Prakash Gollapudi | aea71a0 | 2011-07-26 14:51:39 -0700 | [diff] [blame] | 2425 | bnx2fc_interface_put(interface); |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 2426 | /* put netdev that was held while calling dev_get_by_name */ |
| 2427 | mutex_unlock(&bnx2fc_dev_lock); |
| 2428 | rtnl_unlock(); |
| 2429 | return 0; |
| 2430 | |
| 2431 | if_create_err: |
Bhanu Prakash Gollapudi | aea71a0 | 2011-07-26 14:51:39 -0700 | [diff] [blame] | 2432 | destroy_workqueue(interface->timer_work_queue); |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 2433 | ifput_err: |
Bhanu Prakash Gollapudi | 013068f | 2011-08-30 15:54:52 -0700 | [diff] [blame] | 2434 | bnx2fc_net_cleanup(interface); |
Bhanu Prakash Gollapudi | aea71a0 | 2011-07-26 14:51:39 -0700 | [diff] [blame] | 2435 | bnx2fc_interface_put(interface); |
Bhanu Prakash Gollapudi | 7d742f6 | 2012-01-23 18:00:48 -0800 | [diff] [blame] | 2436 | goto mod_err; |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 2437 | netdev_err: |
| 2438 | module_put(THIS_MODULE); |
| 2439 | mod_err: |
| 2440 | mutex_unlock(&bnx2fc_dev_lock); |
| 2441 | rtnl_unlock(); |
| 2442 | return rc; |
| 2443 | } |
| 2444 | |
| 2445 | /** |
Robert Love | 6e89ea3 | 2012-11-27 06:53:40 +0000 | [diff] [blame] | 2446 | * bnx2fc_create() - Create a bnx2fc interface |
| 2447 | * @netdev : The net_device object the Ethernet interface to create on |
| 2448 | * @fip_mode: The FIP mode for this creation |
| 2449 | * |
| 2450 | * Called from fcoe transport |
| 2451 | * |
| 2452 | * Returns: 0 for success |
| 2453 | */ |
Hannes Reinecke | 1917d42 | 2016-07-04 10:29:19 +0200 | [diff] [blame] | 2454 | static int bnx2fc_create(struct net_device *netdev, enum fip_mode fip_mode) |
Robert Love | 6e89ea3 | 2012-11-27 06:53:40 +0000 | [diff] [blame] | 2455 | { |
| 2456 | return _bnx2fc_create(netdev, fip_mode, BNX2FC_CREATE_LINK_UP); |
| 2457 | } |
| 2458 | |
| 2459 | /** |
| 2460 | * bnx2fc_ctlr_alloc() - Allocate a bnx2fc interface from fcoe_sysfs |
| 2461 | * @netdev: The net_device to be used by the allocated FCoE Controller |
| 2462 | * |
| 2463 | * This routine is called from fcoe_sysfs. It will start the fcoe_ctlr |
| 2464 | * in a link_down state. The allows the user an opportunity to configure |
| 2465 | * the FCoE Controller from sysfs before enabling the FCoE Controller. |
| 2466 | * |
| 2467 | * Creating in with this routine starts the FCoE Controller in Fabric |
| 2468 | * mode. The user can change to VN2VN or another mode before enabling. |
| 2469 | */ |
| 2470 | static int bnx2fc_ctlr_alloc(struct net_device *netdev) |
| 2471 | { |
| 2472 | return _bnx2fc_create(netdev, FIP_MODE_FABRIC, |
| 2473 | BNX2FC_CREATE_LINK_DOWN); |
| 2474 | } |
| 2475 | |
| 2476 | /** |
Bhanu Prakash Gollapudi | aea71a0 | 2011-07-26 14:51:39 -0700 | [diff] [blame] | 2477 | * bnx2fc_find_hba_for_cnic - maps cnic instance to bnx2fc hba instance |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 2478 | * |
| 2479 | * @cnic: Pointer to cnic device instance |
| 2480 | * |
| 2481 | **/ |
| 2482 | static struct bnx2fc_hba *bnx2fc_find_hba_for_cnic(struct cnic_dev *cnic) |
| 2483 | { |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 2484 | struct bnx2fc_hba *hba; |
| 2485 | |
| 2486 | /* Called with bnx2fc_dev_lock held */ |
Bhanu Prakash Gollapudi | d71fb3b | 2012-06-07 02:19:36 -0700 | [diff] [blame] | 2487 | list_for_each_entry(hba, &adapter_list, list) { |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 2488 | if (hba->cnic == cnic) |
| 2489 | return hba; |
| 2490 | } |
| 2491 | return NULL; |
| 2492 | } |
| 2493 | |
Bhanu Prakash Gollapudi | aea71a0 | 2011-07-26 14:51:39 -0700 | [diff] [blame] | 2494 | static struct bnx2fc_interface *bnx2fc_interface_lookup(struct net_device |
| 2495 | *netdev) |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 2496 | { |
Bhanu Prakash Gollapudi | aea71a0 | 2011-07-26 14:51:39 -0700 | [diff] [blame] | 2497 | struct bnx2fc_interface *interface; |
| 2498 | |
| 2499 | /* Called with bnx2fc_dev_lock held */ |
| 2500 | list_for_each_entry(interface, &if_list, list) { |
| 2501 | if (interface->netdev == netdev) |
| 2502 | return interface; |
| 2503 | } |
| 2504 | return NULL; |
| 2505 | } |
| 2506 | |
| 2507 | static struct bnx2fc_hba *bnx2fc_hba_lookup(struct net_device |
| 2508 | *phys_dev) |
| 2509 | { |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 2510 | struct bnx2fc_hba *hba; |
| 2511 | |
| 2512 | /* Called with bnx2fc_dev_lock held */ |
Bhanu Prakash Gollapudi | aea71a0 | 2011-07-26 14:51:39 -0700 | [diff] [blame] | 2513 | list_for_each_entry(hba, &adapter_list, list) { |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 2514 | if (hba->phys_dev == phys_dev) |
| 2515 | return hba; |
| 2516 | } |
Bhanu Prakash Gollapudi | aea71a0 | 2011-07-26 14:51:39 -0700 | [diff] [blame] | 2517 | printk(KERN_ERR PFX "adapter_lookup: hba NULL\n"); |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 2518 | return NULL; |
| 2519 | } |
| 2520 | |
| 2521 | /** |
| 2522 | * bnx2fc_ulp_exit - shuts down adapter instance and frees all resources |
| 2523 | * |
Lee Jones | ca63d8e | 2020-07-13 08:46:23 +0100 | [diff] [blame] | 2524 | * @dev: cnic device handle |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 2525 | */ |
| 2526 | static void bnx2fc_ulp_exit(struct cnic_dev *dev) |
| 2527 | { |
| 2528 | struct bnx2fc_hba *hba; |
Bhanu Prakash Gollapudi | aea71a0 | 2011-07-26 14:51:39 -0700 | [diff] [blame] | 2529 | struct bnx2fc_interface *interface, *tmp; |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 2530 | |
| 2531 | BNX2FC_MISC_DBG("Entered bnx2fc_ulp_exit\n"); |
| 2532 | |
| 2533 | if (!test_bit(CNIC_F_BNX2X_CLASS, &dev->flags)) { |
| 2534 | printk(KERN_ERR PFX "bnx2fc port check: %s, flags: %lx\n", |
| 2535 | dev->netdev->name, dev->flags); |
| 2536 | return; |
| 2537 | } |
| 2538 | |
| 2539 | mutex_lock(&bnx2fc_dev_lock); |
| 2540 | hba = bnx2fc_find_hba_for_cnic(dev); |
| 2541 | if (!hba) { |
| 2542 | printk(KERN_ERR PFX "bnx2fc_ulp_exit: hba not found, dev 0%p\n", |
| 2543 | dev); |
| 2544 | mutex_unlock(&bnx2fc_dev_lock); |
| 2545 | return; |
| 2546 | } |
| 2547 | |
Bhanu Prakash Gollapudi | aea71a0 | 2011-07-26 14:51:39 -0700 | [diff] [blame] | 2548 | list_del_init(&hba->list); |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 2549 | adapter_count--; |
| 2550 | |
Bhanu Prakash Gollapudi | abc49a9 | 2011-08-04 17:38:42 -0700 | [diff] [blame] | 2551 | list_for_each_entry_safe(interface, tmp, &if_list, list) |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 2552 | /* destroy not called yet, move to quiesced list */ |
Bhanu Prakash Gollapudi | abc49a9 | 2011-08-04 17:38:42 -0700 | [diff] [blame] | 2553 | if (interface->hba == hba) |
Bhanu Prakash Gollapudi | eccdcd0 | 2011-08-24 18:56:42 -0700 | [diff] [blame] | 2554 | __bnx2fc_destroy(interface); |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 2555 | mutex_unlock(&bnx2fc_dev_lock); |
| 2556 | |
| 2557 | bnx2fc_ulp_stop(hba); |
| 2558 | /* unregister cnic device */ |
| 2559 | if (test_and_clear_bit(BNX2FC_CNIC_REGISTERED, &hba->reg_with_cnic)) |
| 2560 | hba->cnic->unregister_device(hba->cnic, CNIC_ULP_FCOE); |
Bhanu Prakash Gollapudi | aea71a0 | 2011-07-26 14:51:39 -0700 | [diff] [blame] | 2561 | bnx2fc_hba_destroy(hba); |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 2562 | } |
| 2563 | |
Chad Dupuis | 5eddc33 | 2017-06-26 08:59:37 -0700 | [diff] [blame] | 2564 | static void bnx2fc_rport_terminate_io(struct fc_rport *rport) |
| 2565 | { |
| 2566 | /* This is a no-op */ |
| 2567 | } |
| 2568 | |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 2569 | /** |
| 2570 | * bnx2fc_fcoe_reset - Resets the fcoe |
| 2571 | * |
| 2572 | * @shost: shost the reset is from |
| 2573 | * |
| 2574 | * Returns: always 0 |
| 2575 | */ |
| 2576 | static int bnx2fc_fcoe_reset(struct Scsi_Host *shost) |
| 2577 | { |
| 2578 | struct fc_lport *lport = shost_priv(shost); |
| 2579 | fc_lport_reset(lport); |
| 2580 | return 0; |
| 2581 | } |
| 2582 | |
| 2583 | |
| 2584 | static bool bnx2fc_match(struct net_device *netdev) |
| 2585 | { |
Bhanu Prakash Gollapudi | 7adc5a3 | 2012-06-04 16:15:44 -0700 | [diff] [blame] | 2586 | struct net_device *phys_dev = netdev; |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 2587 | |
Bhanu Prakash Gollapudi | 7adc5a3 | 2012-06-04 16:15:44 -0700 | [diff] [blame] | 2588 | mutex_lock(&bnx2fc_dev_lock); |
Parav Pandit | d0d7b10 | 2017-02-04 11:00:49 -0600 | [diff] [blame] | 2589 | if (is_vlan_dev(netdev)) |
Bhanu Prakash Gollapudi | 7adc5a3 | 2012-06-04 16:15:44 -0700 | [diff] [blame] | 2590 | phys_dev = vlan_dev_real_dev(netdev); |
| 2591 | |
| 2592 | if (bnx2fc_hba_lookup(phys_dev)) { |
| 2593 | mutex_unlock(&bnx2fc_dev_lock); |
| 2594 | return true; |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 2595 | } |
Bhanu Prakash Gollapudi | 7adc5a3 | 2012-06-04 16:15:44 -0700 | [diff] [blame] | 2596 | |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 2597 | mutex_unlock(&bnx2fc_dev_lock); |
| 2598 | return false; |
| 2599 | } |
| 2600 | |
| 2601 | |
| 2602 | static struct fcoe_transport bnx2fc_transport = { |
| 2603 | .name = {"bnx2fc"}, |
| 2604 | .attached = false, |
| 2605 | .list = LIST_HEAD_INIT(bnx2fc_transport.list), |
Robert Love | 6e89ea3 | 2012-11-27 06:53:40 +0000 | [diff] [blame] | 2606 | .alloc = bnx2fc_ctlr_alloc, |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 2607 | .match = bnx2fc_match, |
| 2608 | .create = bnx2fc_create, |
| 2609 | .destroy = bnx2fc_destroy, |
| 2610 | .enable = bnx2fc_enable, |
| 2611 | .disable = bnx2fc_disable, |
| 2612 | }; |
| 2613 | |
| 2614 | /** |
Thomas Gleixner | 1937f8a | 2017-07-24 12:52:59 +0200 | [diff] [blame] | 2615 | * bnx2fc_cpu_online - Create a receive thread for an online CPU |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 2616 | * |
| 2617 | * @cpu: cpu index for the online cpu |
| 2618 | */ |
Thomas Gleixner | 1937f8a | 2017-07-24 12:52:59 +0200 | [diff] [blame] | 2619 | static int bnx2fc_cpu_online(unsigned int cpu) |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 2620 | { |
| 2621 | struct bnx2fc_percpu_s *p; |
| 2622 | struct task_struct *thread; |
| 2623 | |
| 2624 | p = &per_cpu(bnx2fc_percpu, cpu); |
| 2625 | |
Eric Dumazet | 6961427 | 2012-06-04 16:15:42 -0700 | [diff] [blame] | 2626 | thread = kthread_create_on_node(bnx2fc_percpu_io_thread, |
| 2627 | (void *)p, cpu_to_node(cpu), |
| 2628 | "bnx2fc_thread/%d", cpu); |
Thomas Gleixner | 1937f8a | 2017-07-24 12:52:59 +0200 | [diff] [blame] | 2629 | if (IS_ERR(thread)) |
| 2630 | return PTR_ERR(thread); |
| 2631 | |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 2632 | /* bind thread to the cpu */ |
Thomas Gleixner | 1937f8a | 2017-07-24 12:52:59 +0200 | [diff] [blame] | 2633 | kthread_bind(thread, cpu); |
| 2634 | p->iothread = thread; |
| 2635 | wake_up_process(thread); |
| 2636 | return 0; |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 2637 | } |
| 2638 | |
Thomas Gleixner | 1937f8a | 2017-07-24 12:52:59 +0200 | [diff] [blame] | 2639 | static int bnx2fc_cpu_offline(unsigned int cpu) |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 2640 | { |
| 2641 | struct bnx2fc_percpu_s *p; |
| 2642 | struct task_struct *thread; |
| 2643 | struct bnx2fc_work *work, *tmp; |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 2644 | |
| 2645 | BNX2FC_MISC_DBG("destroying io thread for CPU %d\n", cpu); |
| 2646 | |
| 2647 | /* Prevent any new work from being queued for this CPU */ |
| 2648 | p = &per_cpu(bnx2fc_percpu, cpu); |
| 2649 | spin_lock_bh(&p->fp_work_lock); |
| 2650 | thread = p->iothread; |
| 2651 | p->iothread = NULL; |
| 2652 | |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 2653 | /* Free all work in the list */ |
Bhanu Prakash Gollapudi | 3224876 | 2011-08-04 17:38:36 -0700 | [diff] [blame] | 2654 | list_for_each_entry_safe(work, tmp, &p->work_list, list) { |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 2655 | list_del_init(&work->list); |
Javed Hasan | 7733111 | 2020-03-26 22:48:47 -0700 | [diff] [blame] | 2656 | bnx2fc_process_cq_compl(work->tgt, work->wqe, work->rq_data, |
| 2657 | work->num_rq, work->task); |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 2658 | kfree(work); |
| 2659 | } |
| 2660 | |
| 2661 | spin_unlock_bh(&p->fp_work_lock); |
| 2662 | |
| 2663 | if (thread) |
| 2664 | kthread_stop(thread); |
Sebastian Andrzej Siewior | c53b005 | 2016-12-21 20:19:50 +0100 | [diff] [blame] | 2665 | return 0; |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 2666 | } |
| 2667 | |
Joe Carnuccio | 10755d3 | 2016-04-07 09:07:56 -0400 | [diff] [blame] | 2668 | static int bnx2fc_slave_configure(struct scsi_device *sdev) |
| 2669 | { |
| 2670 | if (!bnx2fc_queue_depth) |
| 2671 | return 0; |
| 2672 | |
| 2673 | scsi_change_queue_depth(sdev, bnx2fc_queue_depth); |
| 2674 | return 0; |
| 2675 | } |
| 2676 | |
Sebastian Andrzej Siewior | c53b005 | 2016-12-21 20:19:50 +0100 | [diff] [blame] | 2677 | static enum cpuhp_state bnx2fc_online_state; |
| 2678 | |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 2679 | /** |
| 2680 | * bnx2fc_mod_init - module init entry point |
| 2681 | * |
| 2682 | * Initialize driver wide global data structures, and register |
| 2683 | * with cnic module |
| 2684 | **/ |
| 2685 | static int __init bnx2fc_mod_init(void) |
| 2686 | { |
| 2687 | struct fcoe_percpu_s *bg; |
| 2688 | struct task_struct *l2_thread; |
| 2689 | int rc = 0; |
| 2690 | unsigned int cpu = 0; |
| 2691 | struct bnx2fc_percpu_s *p; |
| 2692 | |
| 2693 | printk(KERN_INFO PFX "%s", version); |
| 2694 | |
| 2695 | /* register as a fcoe transport */ |
| 2696 | rc = fcoe_transport_attach(&bnx2fc_transport); |
| 2697 | if (rc) { |
| 2698 | printk(KERN_ERR "failed to register an fcoe transport, check " |
| 2699 | "if libfcoe is loaded\n"); |
| 2700 | goto out; |
| 2701 | } |
| 2702 | |
| 2703 | INIT_LIST_HEAD(&adapter_list); |
Bhanu Prakash Gollapudi | aea71a0 | 2011-07-26 14:51:39 -0700 | [diff] [blame] | 2704 | INIT_LIST_HEAD(&if_list); |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 2705 | mutex_init(&bnx2fc_dev_lock); |
| 2706 | adapter_count = 0; |
| 2707 | |
| 2708 | /* Attach FC transport template */ |
| 2709 | rc = bnx2fc_attach_transport(); |
| 2710 | if (rc) |
| 2711 | goto detach_ft; |
| 2712 | |
| 2713 | bnx2fc_wq = alloc_workqueue("bnx2fc", 0, 0); |
| 2714 | if (!bnx2fc_wq) { |
| 2715 | rc = -ENOMEM; |
| 2716 | goto release_bt; |
| 2717 | } |
| 2718 | |
| 2719 | bg = &bnx2fc_global; |
| 2720 | skb_queue_head_init(&bg->fcoe_rx_list); |
| 2721 | l2_thread = kthread_create(bnx2fc_l2_rcv_thread, |
| 2722 | (void *)bg, |
| 2723 | "bnx2fc_l2_thread"); |
| 2724 | if (IS_ERR(l2_thread)) { |
| 2725 | rc = PTR_ERR(l2_thread); |
| 2726 | goto free_wq; |
| 2727 | } |
| 2728 | wake_up_process(l2_thread); |
| 2729 | spin_lock_bh(&bg->fcoe_rx_list.lock); |
Sebastian Andrzej Siewior | 4b9bc86 | 2016-04-12 17:16:54 +0200 | [diff] [blame] | 2730 | bg->kthread = l2_thread; |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 2731 | spin_unlock_bh(&bg->fcoe_rx_list.lock); |
| 2732 | |
| 2733 | for_each_possible_cpu(cpu) { |
| 2734 | p = &per_cpu(bnx2fc_percpu, cpu); |
| 2735 | INIT_LIST_HEAD(&p->work_list); |
| 2736 | spin_lock_init(&p->fp_work_lock); |
| 2737 | } |
| 2738 | |
Thomas Gleixner | 1937f8a | 2017-07-24 12:52:59 +0200 | [diff] [blame] | 2739 | rc = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "scsi/bnx2fc:online", |
| 2740 | bnx2fc_cpu_online, bnx2fc_cpu_offline); |
Sebastian Andrzej Siewior | c53b005 | 2016-12-21 20:19:50 +0100 | [diff] [blame] | 2741 | if (rc < 0) |
Thomas Gleixner | 1937f8a | 2017-07-24 12:52:59 +0200 | [diff] [blame] | 2742 | goto stop_thread; |
Sebastian Andrzej Siewior | c53b005 | 2016-12-21 20:19:50 +0100 | [diff] [blame] | 2743 | bnx2fc_online_state = rc; |
Srivatsa S. Bhat | 7229b6d | 2014-03-11 02:09:45 +0530 | [diff] [blame] | 2744 | |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 2745 | cnic_register_driver(CNIC_ULP_FCOE, &bnx2fc_cnic_cb); |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 2746 | return 0; |
| 2747 | |
Thomas Gleixner | 1937f8a | 2017-07-24 12:52:59 +0200 | [diff] [blame] | 2748 | stop_thread: |
Sebastian Andrzej Siewior | c53b005 | 2016-12-21 20:19:50 +0100 | [diff] [blame] | 2749 | kthread_stop(l2_thread); |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 2750 | free_wq: |
| 2751 | destroy_workqueue(bnx2fc_wq); |
| 2752 | release_bt: |
| 2753 | bnx2fc_release_transport(); |
| 2754 | detach_ft: |
| 2755 | fcoe_transport_detach(&bnx2fc_transport); |
| 2756 | out: |
| 2757 | return rc; |
| 2758 | } |
| 2759 | |
| 2760 | static void __exit bnx2fc_mod_exit(void) |
| 2761 | { |
| 2762 | LIST_HEAD(to_be_deleted); |
| 2763 | struct bnx2fc_hba *hba, *next; |
| 2764 | struct fcoe_percpu_s *bg; |
| 2765 | struct task_struct *l2_thread; |
| 2766 | struct sk_buff *skb; |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 2767 | |
| 2768 | /* |
| 2769 | * NOTE: Since cnic calls register_driver routine rtnl_lock, |
| 2770 | * it will have higher precedence than bnx2fc_dev_lock. |
| 2771 | * unregister_device() cannot be called with bnx2fc_dev_lock |
| 2772 | * held. |
| 2773 | */ |
| 2774 | mutex_lock(&bnx2fc_dev_lock); |
Christophe JAILLET | 393c801 | 2016-09-03 09:05:48 +0200 | [diff] [blame] | 2775 | list_splice_init(&adapter_list, &to_be_deleted); |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 2776 | adapter_count = 0; |
| 2777 | mutex_unlock(&bnx2fc_dev_lock); |
| 2778 | |
| 2779 | /* Unregister with cnic */ |
Bhanu Prakash Gollapudi | aea71a0 | 2011-07-26 14:51:39 -0700 | [diff] [blame] | 2780 | list_for_each_entry_safe(hba, next, &to_be_deleted, list) { |
| 2781 | list_del_init(&hba->list); |
| 2782 | printk(KERN_ERR PFX "MOD_EXIT:destroy hba = 0x%p\n", |
| 2783 | hba); |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 2784 | bnx2fc_ulp_stop(hba); |
| 2785 | /* unregister cnic device */ |
| 2786 | if (test_and_clear_bit(BNX2FC_CNIC_REGISTERED, |
| 2787 | &hba->reg_with_cnic)) |
Bhanu Prakash Gollapudi | aea71a0 | 2011-07-26 14:51:39 -0700 | [diff] [blame] | 2788 | hba->cnic->unregister_device(hba->cnic, |
| 2789 | CNIC_ULP_FCOE); |
| 2790 | bnx2fc_hba_destroy(hba); |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 2791 | } |
| 2792 | cnic_unregister_driver(CNIC_ULP_FCOE); |
| 2793 | |
| 2794 | /* Destroy global thread */ |
| 2795 | bg = &bnx2fc_global; |
| 2796 | spin_lock_bh(&bg->fcoe_rx_list.lock); |
Sebastian Andrzej Siewior | 4b9bc86 | 2016-04-12 17:16:54 +0200 | [diff] [blame] | 2797 | l2_thread = bg->kthread; |
| 2798 | bg->kthread = NULL; |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 2799 | while ((skb = __skb_dequeue(&bg->fcoe_rx_list)) != NULL) |
| 2800 | kfree_skb(skb); |
| 2801 | |
| 2802 | spin_unlock_bh(&bg->fcoe_rx_list.lock); |
| 2803 | |
| 2804 | if (l2_thread) |
| 2805 | kthread_stop(l2_thread); |
| 2806 | |
Thomas Gleixner | 1937f8a | 2017-07-24 12:52:59 +0200 | [diff] [blame] | 2807 | cpuhp_remove_state(bnx2fc_online_state); |
Srivatsa S. Bhat | 7229b6d | 2014-03-11 02:09:45 +0530 | [diff] [blame] | 2808 | |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 2809 | destroy_workqueue(bnx2fc_wq); |
| 2810 | /* |
| 2811 | * detach from scsi transport |
| 2812 | * must happen after all destroys are done |
| 2813 | */ |
| 2814 | bnx2fc_release_transport(); |
| 2815 | |
| 2816 | /* detach from fcoe transport */ |
| 2817 | fcoe_transport_detach(&bnx2fc_transport); |
| 2818 | } |
| 2819 | |
| 2820 | module_init(bnx2fc_mod_init); |
| 2821 | module_exit(bnx2fc_mod_exit); |
| 2822 | |
Robert Love | 8d55e50 | 2012-05-22 19:06:26 -0700 | [diff] [blame] | 2823 | static struct fcoe_sysfs_function_template bnx2fc_fcoe_sysfs_templ = { |
Robert Love | 6e89ea3 | 2012-11-27 06:53:40 +0000 | [diff] [blame] | 2824 | .set_fcoe_ctlr_enabled = bnx2fc_ctlr_enabled, |
Yi Zou | b8b3e69 | 2012-12-06 06:24:59 +0000 | [diff] [blame] | 2825 | .get_fcoe_ctlr_link_fail = fcoe_ctlr_get_lesb, |
| 2826 | .get_fcoe_ctlr_vlink_fail = fcoe_ctlr_get_lesb, |
| 2827 | .get_fcoe_ctlr_miss_fka = fcoe_ctlr_get_lesb, |
| 2828 | .get_fcoe_ctlr_symb_err = fcoe_ctlr_get_lesb, |
| 2829 | .get_fcoe_ctlr_err_block = fcoe_ctlr_get_lesb, |
| 2830 | .get_fcoe_ctlr_fcs_error = fcoe_ctlr_get_lesb, |
Robert Love | 8d55e50 | 2012-05-22 19:06:26 -0700 | [diff] [blame] | 2831 | |
| 2832 | .get_fcoe_fcf_selected = fcoe_fcf_get_selected, |
| 2833 | .get_fcoe_fcf_vlan_id = bnx2fc_fcf_get_vlan_id, |
| 2834 | }; |
| 2835 | |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 2836 | static struct fc_function_template bnx2fc_transport_function = { |
| 2837 | .show_host_node_name = 1, |
| 2838 | .show_host_port_name = 1, |
| 2839 | .show_host_supported_classes = 1, |
| 2840 | .show_host_supported_fc4s = 1, |
| 2841 | .show_host_active_fc4s = 1, |
| 2842 | .show_host_maxframe_size = 1, |
| 2843 | |
| 2844 | .show_host_port_id = 1, |
| 2845 | .show_host_supported_speeds = 1, |
| 2846 | .get_host_speed = fc_get_host_speed, |
| 2847 | .show_host_speed = 1, |
| 2848 | .show_host_port_type = 1, |
| 2849 | .get_host_port_state = fc_get_host_port_state, |
| 2850 | .show_host_port_state = 1, |
| 2851 | .show_host_symbolic_name = 1, |
| 2852 | |
| 2853 | .dd_fcrport_size = (sizeof(struct fc_rport_libfc_priv) + |
| 2854 | sizeof(struct bnx2fc_rport)), |
| 2855 | .show_rport_maxframe_size = 1, |
| 2856 | .show_rport_supported_classes = 1, |
| 2857 | |
| 2858 | .show_host_fabric_name = 1, |
| 2859 | .show_starget_node_name = 1, |
| 2860 | .show_starget_port_name = 1, |
| 2861 | .show_starget_port_id = 1, |
| 2862 | .set_rport_dev_loss_tmo = fc_set_rport_loss_tmo, |
| 2863 | .show_rport_dev_loss_tmo = 1, |
| 2864 | .get_fc_host_stats = bnx2fc_get_host_stats, |
| 2865 | |
| 2866 | .issue_fc_host_lip = bnx2fc_fcoe_reset, |
| 2867 | |
Chad Dupuis | 5eddc33 | 2017-06-26 08:59:37 -0700 | [diff] [blame] | 2868 | .terminate_rport_io = bnx2fc_rport_terminate_io, |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 2869 | |
| 2870 | .vport_create = bnx2fc_vport_create, |
| 2871 | .vport_delete = bnx2fc_vport_destroy, |
| 2872 | .vport_disable = bnx2fc_vport_disable, |
Bhanu Prakash Gollapudi | e9a5289c | 2011-08-04 17:38:37 -0700 | [diff] [blame] | 2873 | .bsg_request = fc_lport_bsg_request, |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 2874 | }; |
| 2875 | |
| 2876 | static struct fc_function_template bnx2fc_vport_xport_function = { |
| 2877 | .show_host_node_name = 1, |
| 2878 | .show_host_port_name = 1, |
| 2879 | .show_host_supported_classes = 1, |
| 2880 | .show_host_supported_fc4s = 1, |
| 2881 | .show_host_active_fc4s = 1, |
| 2882 | .show_host_maxframe_size = 1, |
| 2883 | |
| 2884 | .show_host_port_id = 1, |
| 2885 | .show_host_supported_speeds = 1, |
| 2886 | .get_host_speed = fc_get_host_speed, |
| 2887 | .show_host_speed = 1, |
| 2888 | .show_host_port_type = 1, |
| 2889 | .get_host_port_state = fc_get_host_port_state, |
| 2890 | .show_host_port_state = 1, |
| 2891 | .show_host_symbolic_name = 1, |
| 2892 | |
| 2893 | .dd_fcrport_size = (sizeof(struct fc_rport_libfc_priv) + |
| 2894 | sizeof(struct bnx2fc_rport)), |
| 2895 | .show_rport_maxframe_size = 1, |
| 2896 | .show_rport_supported_classes = 1, |
| 2897 | |
| 2898 | .show_host_fabric_name = 1, |
| 2899 | .show_starget_node_name = 1, |
| 2900 | .show_starget_port_name = 1, |
| 2901 | .show_starget_port_id = 1, |
| 2902 | .set_rport_dev_loss_tmo = fc_set_rport_loss_tmo, |
| 2903 | .show_rport_dev_loss_tmo = 1, |
| 2904 | .get_fc_host_stats = fc_get_host_stats, |
| 2905 | .issue_fc_host_lip = bnx2fc_fcoe_reset, |
| 2906 | .terminate_rport_io = fc_rport_terminate_io, |
Bhanu Prakash Gollapudi | e9a5289c | 2011-08-04 17:38:37 -0700 | [diff] [blame] | 2907 | .bsg_request = fc_lport_bsg_request, |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 2908 | }; |
| 2909 | |
Joe Carnuccio | 10755d3 | 2016-04-07 09:07:56 -0400 | [diff] [blame] | 2910 | /* |
| 2911 | * Additional scsi_host attributes. |
| 2912 | */ |
| 2913 | static ssize_t |
| 2914 | bnx2fc_tm_timeout_show(struct device *dev, struct device_attribute *attr, |
| 2915 | char *buf) |
| 2916 | { |
| 2917 | struct Scsi_Host *shost = class_to_shost(dev); |
| 2918 | struct fc_lport *lport = shost_priv(shost); |
| 2919 | struct fcoe_port *port = lport_priv(lport); |
| 2920 | struct bnx2fc_interface *interface = port->priv; |
| 2921 | |
| 2922 | sprintf(buf, "%u\n", interface->tm_timeout); |
| 2923 | return strlen(buf); |
| 2924 | } |
| 2925 | |
| 2926 | static ssize_t |
| 2927 | bnx2fc_tm_timeout_store(struct device *dev, |
| 2928 | struct device_attribute *attr, const char *buf, size_t count) |
| 2929 | { |
| 2930 | struct Scsi_Host *shost = class_to_shost(dev); |
| 2931 | struct fc_lport *lport = shost_priv(shost); |
| 2932 | struct fcoe_port *port = lport_priv(lport); |
| 2933 | struct bnx2fc_interface *interface = port->priv; |
| 2934 | int rval, val; |
| 2935 | |
| 2936 | rval = kstrtouint(buf, 10, &val); |
| 2937 | if (rval) |
| 2938 | return rval; |
| 2939 | if (val > 255) |
| 2940 | return -ERANGE; |
| 2941 | |
| 2942 | interface->tm_timeout = (u8)val; |
| 2943 | return strlen(buf); |
| 2944 | } |
| 2945 | |
| 2946 | static DEVICE_ATTR(tm_timeout, S_IRUGO|S_IWUSR, bnx2fc_tm_timeout_show, |
| 2947 | bnx2fc_tm_timeout_store); |
| 2948 | |
Bart Van Assche | c3dd11d | 2021-10-12 16:35:27 -0700 | [diff] [blame] | 2949 | static struct attribute *bnx2fc_host_attrs[] = { |
| 2950 | &dev_attr_tm_timeout.attr, |
Joe Carnuccio | 10755d3 | 2016-04-07 09:07:56 -0400 | [diff] [blame] | 2951 | NULL, |
| 2952 | }; |
| 2953 | |
Bart Van Assche | c3dd11d | 2021-10-12 16:35:27 -0700 | [diff] [blame] | 2954 | ATTRIBUTE_GROUPS(bnx2fc_host); |
| 2955 | |
Lee Jones | ca63d8e | 2020-07-13 08:46:23 +0100 | [diff] [blame] | 2956 | /* |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 2957 | * scsi_host_template structure used while registering with SCSI-ml |
| 2958 | */ |
| 2959 | static struct scsi_host_template bnx2fc_shost_template = { |
| 2960 | .module = THIS_MODULE, |
Saurav Kashyap | 17d87c4 | 2014-07-03 08:18:28 -0400 | [diff] [blame] | 2961 | .name = "QLogic Offload FCoE Initiator", |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 2962 | .queuecommand = bnx2fc_queuecommand, |
Christoph Hellwig | b6a05c8 | 2017-01-30 13:18:58 +0100 | [diff] [blame] | 2963 | .eh_timed_out = fc_eh_timed_out, |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 2964 | .eh_abort_handler = bnx2fc_eh_abort, /* abts */ |
| 2965 | .eh_device_reset_handler = bnx2fc_eh_device_reset, /* lun reset */ |
| 2966 | .eh_target_reset_handler = bnx2fc_eh_target_reset, /* tgt reset */ |
| 2967 | .eh_host_reset_handler = fc_eh_host_reset, |
| 2968 | .slave_alloc = fc_slave_alloc, |
Christoph Hellwig | db5ed4d | 2014-11-13 15:08:42 +0100 | [diff] [blame] | 2969 | .change_queue_depth = scsi_change_queue_depth, |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 2970 | .this_id = -1, |
| 2971 | .cmd_per_lun = 3, |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 2972 | .sg_tablesize = BNX2FC_MAX_BDS_PER_CMD, |
Saurav Kashyap | 3c97b56 | 2019-06-24 01:29:59 -0700 | [diff] [blame] | 2973 | .dma_boundary = 0x7fff, |
| 2974 | .max_sectors = 0x3fbf, |
Christoph Hellwig | c40ecc1 | 2014-11-13 14:25:11 +0100 | [diff] [blame] | 2975 | .track_queue_depth = 1, |
Joe Carnuccio | 10755d3 | 2016-04-07 09:07:56 -0400 | [diff] [blame] | 2976 | .slave_configure = bnx2fc_slave_configure, |
Bart Van Assche | c3dd11d | 2021-10-12 16:35:27 -0700 | [diff] [blame] | 2977 | .shost_groups = bnx2fc_host_groups, |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 2978 | }; |
| 2979 | |
| 2980 | static struct libfc_function_template bnx2fc_libfc_fcn_templ = { |
| 2981 | .frame_send = bnx2fc_xmit, |
| 2982 | .elsct_send = bnx2fc_elsct_send, |
| 2983 | .fcp_abort_io = bnx2fc_abort_io, |
| 2984 | .fcp_cleanup = bnx2fc_cleanup, |
Yi Zou | b8b3e69 | 2012-12-06 06:24:59 +0000 | [diff] [blame] | 2985 | .get_lesb = fcoe_get_lesb, |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 2986 | .rport_event_callback = bnx2fc_rport_event_handler, |
| 2987 | }; |
| 2988 | |
Lee Jones | ca63d8e | 2020-07-13 08:46:23 +0100 | [diff] [blame] | 2989 | /* |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 2990 | * bnx2fc_cnic_cb - global template of bnx2fc - cnic driver interface |
| 2991 | * structure carrying callback function pointers |
| 2992 | */ |
| 2993 | static struct cnic_ulp_ops bnx2fc_cnic_cb = { |
| 2994 | .owner = THIS_MODULE, |
| 2995 | .cnic_init = bnx2fc_ulp_init, |
| 2996 | .cnic_exit = bnx2fc_ulp_exit, |
| 2997 | .cnic_start = bnx2fc_ulp_start, |
| 2998 | .cnic_stop = bnx2fc_ulp_stop, |
| 2999 | .indicate_kcqes = bnx2fc_indicate_kcqe, |
| 3000 | .indicate_netevent = bnx2fc_indicate_netevent, |
Barak Witkowski | 2e499d3 | 2012-06-26 01:31:19 +0000 | [diff] [blame] | 3001 | .cnic_get_stats = bnx2fc_ulp_get_stats, |
Bhanu Gollapudi | 853e2bd | 2011-02-04 12:10:34 -0800 | [diff] [blame] | 3002 | }; |