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