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