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