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