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