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