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