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