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