Lines Matching +full:sub +full:- +full:frame
1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (c) 2008-2009 Cisco Systems, Inc. All rights reserved.
6 * Maintained at www.Open-FCoE.org
82 * fcoe_ctlr_set_state() - Set and do debug printing for the new FIP state.
88 if (state == fip->state) in fcoe_ctlr_set_state()
90 if (fip->lp) in fcoe_ctlr_set_state()
91 LIBFCOE_FIP_DBG(fip, "state %s -> %s\n", in fcoe_ctlr_set_state()
92 fcoe_ctlr_state(fip->state), fcoe_ctlr_state(state)); in fcoe_ctlr_set_state()
93 fip->state = state; in fcoe_ctlr_set_state()
97 * fcoe_ctlr_mtu_valid() - Check if a FCF's MTU is valid
100 * Return non-zero if FCF fcoe_size has been validated.
104 return (fcf->flags & FIP_FL_SOL) != 0; in fcoe_ctlr_mtu_valid()
108 * fcoe_ctlr_fcf_usable() - Check if a FCF is usable
111 * Return non-zero if the FCF is usable.
117 return (fcf->flags & flags) == flags; in fcoe_ctlr_fcf_usable()
121 * fcoe_ctlr_map_dest() - Set flag and OUI for mapping destination addresses
126 if (fip->mode == FIP_MODE_VN2VN) in fcoe_ctlr_map_dest()
127 hton24(fip->dest_addr, FIP_VN_FC_MAP); in fcoe_ctlr_map_dest()
129 hton24(fip->dest_addr, FIP_DEF_FC_MAP); in fcoe_ctlr_map_dest()
130 hton24(fip->dest_addr + 3, 0); in fcoe_ctlr_map_dest()
131 fip->map_dest = 1; in fcoe_ctlr_map_dest()
135 * fcoe_ctlr_init() - Initialize the FCoE Controller instance
142 fip->mode = mode; in fcoe_ctlr_init()
143 fip->fip_resp = false; in fcoe_ctlr_init()
144 INIT_LIST_HEAD(&fip->fcfs); in fcoe_ctlr_init()
145 mutex_init(&fip->ctlr_mutex); in fcoe_ctlr_init()
146 spin_lock_init(&fip->ctlr_lock); in fcoe_ctlr_init()
147 fip->flogi_oxid = FC_XID_UNKNOWN; in fcoe_ctlr_init()
148 timer_setup(&fip->timer, fcoe_ctlr_timeout, 0); in fcoe_ctlr_init()
149 INIT_WORK(&fip->timer_work, fcoe_ctlr_timer_work); in fcoe_ctlr_init()
150 INIT_WORK(&fip->recv_work, fcoe_ctlr_recv_work); in fcoe_ctlr_init()
151 skb_queue_head_init(&fip->fip_recv_list); in fcoe_ctlr_init()
156 * fcoe_sysfs_fcf_add() - Add a fcoe_fcf{,_device} to a fcoe_ctlr{,_device}
159 * Called with fip->ctlr_mutex held
163 struct fcoe_ctlr *fip = new->fip; in fcoe_sysfs_fcf_add()
166 int rc = -ENOMEM; in fcoe_sysfs_fcf_add()
169 new->fabric_name, new->fcf_mac); in fcoe_sysfs_fcf_add()
175 temp->fabric_name = new->fabric_name; in fcoe_sysfs_fcf_add()
176 temp->switch_name = new->switch_name; in fcoe_sysfs_fcf_add()
177 temp->fc_map = new->fc_map; in fcoe_sysfs_fcf_add()
178 temp->vfid = new->vfid; in fcoe_sysfs_fcf_add()
179 memcpy(temp->mac, new->fcf_mac, ETH_ALEN); in fcoe_sysfs_fcf_add()
180 temp->priority = new->pri; in fcoe_sysfs_fcf_add()
181 temp->fka_period = new->fka_period; in fcoe_sysfs_fcf_add()
182 temp->selected = 0; /* default to unselected */ in fcoe_sysfs_fcf_add()
194 mutex_lock(&ctlr_dev->lock); in fcoe_sysfs_fcf_add()
197 rc = -ENOMEM; in fcoe_sysfs_fcf_add()
198 mutex_unlock(&ctlr_dev->lock); in fcoe_sysfs_fcf_add()
210 * non-NULL priv pointer. in fcoe_sysfs_fcf_add()
212 BUG_ON(fcf_dev->priv); in fcoe_sysfs_fcf_add()
214 fcf_dev->priv = new; in fcoe_sysfs_fcf_add()
215 new->fcf_dev = fcf_dev; in fcoe_sysfs_fcf_add()
216 mutex_unlock(&ctlr_dev->lock); in fcoe_sysfs_fcf_add()
219 list_add(&new->list, &fip->fcfs); in fcoe_sysfs_fcf_add()
220 fip->fcf_count++; in fcoe_sysfs_fcf_add()
229 * fcoe_sysfs_fcf_del() - Remove a fcoe_fcf{,_device} to a fcoe_ctlr{,_device}
232 * Called with fip->ctlr_mutex held
236 struct fcoe_ctlr *fip = new->fip; in fcoe_sysfs_fcf_del()
240 list_del(&new->list); in fcoe_sysfs_fcf_del()
241 fip->fcf_count--; in fcoe_sysfs_fcf_del()
254 mutex_lock(&cdev->lock); in fcoe_sysfs_fcf_del()
257 new->fcf_dev = NULL; in fcoe_sysfs_fcf_del()
259 mutex_unlock(&cdev->lock); in fcoe_sysfs_fcf_del()
265 * fcoe_ctlr_reset_fcfs() - Reset and free all FCFs for a controller
275 fip->sel_fcf = NULL; in fcoe_ctlr_reset_fcfs()
276 list_for_each_entry_safe(fcf, next, &fip->fcfs, list) { in fcoe_ctlr_reset_fcfs()
279 WARN_ON(fip->fcf_count); in fcoe_ctlr_reset_fcfs()
281 fip->sel_time = 0; in fcoe_ctlr_reset_fcfs()
285 * fcoe_ctlr_destroy() - Disable and tear down a FCoE controller
298 cancel_work_sync(&fip->recv_work); in fcoe_ctlr_destroy()
299 skb_queue_purge(&fip->fip_recv_list); in fcoe_ctlr_destroy()
301 mutex_lock(&fip->ctlr_mutex); in fcoe_ctlr_destroy()
304 mutex_unlock(&fip->ctlr_mutex); in fcoe_ctlr_destroy()
305 del_timer_sync(&fip->timer); in fcoe_ctlr_destroy()
306 cancel_work_sync(&fip->timer_work); in fcoe_ctlr_destroy()
311 * fcoe_ctlr_announce() - announce new FCF selection
323 mutex_lock(&fip->ctlr_mutex); in fcoe_ctlr_announce()
324 spin_lock_bh(&fip->ctlr_lock); in fcoe_ctlr_announce()
326 kfree_skb(fip->flogi_req); in fcoe_ctlr_announce()
327 fip->flogi_req = NULL; in fcoe_ctlr_announce()
328 list_for_each_entry(fcf, &fip->fcfs, list) in fcoe_ctlr_announce()
329 fcf->flogi_sent = 0; in fcoe_ctlr_announce()
331 spin_unlock_bh(&fip->ctlr_lock); in fcoe_ctlr_announce()
332 sel = fip->sel_fcf; in fcoe_ctlr_announce()
334 if (sel && ether_addr_equal(sel->fcf_mac, fip->dest_addr)) in fcoe_ctlr_announce()
336 if (!is_zero_ether_addr(fip->dest_addr)) { in fcoe_ctlr_announce()
338 "FIP Fibre-Channel Forwarder MAC %pM deselected\n", in fcoe_ctlr_announce()
339 fip->lp->host->host_no, fip->dest_addr); in fcoe_ctlr_announce()
340 eth_zero_addr(fip->dest_addr); in fcoe_ctlr_announce()
344 "Fibre-Channel Forwarder MAC %pM\n", in fcoe_ctlr_announce()
345 fip->lp->host->host_no, sel->fcf_mac); in fcoe_ctlr_announce()
346 memcpy(fip->dest_addr, sel->fcoe_mac, ETH_ALEN); in fcoe_ctlr_announce()
347 fip->map_dest = 0; in fcoe_ctlr_announce()
350 mutex_unlock(&fip->ctlr_mutex); in fcoe_ctlr_announce()
354 * fcoe_ctlr_fcoe_size() - Return the maximum FCoE size required for VN_Port
363 * Determine the max FCoE frame size allowed, including in fcoe_ctlr_fcoe_size()
365 * Note: lp->mfs is currently the payload size, not the frame size. in fcoe_ctlr_fcoe_size()
367 return fip->lp->mfs + sizeof(struct fc_frame_header) + in fcoe_ctlr_fcoe_size()
372 * fcoe_ctlr_solicit() - Send a FIP solicitation
394 sol = (struct fip_sol *)skb->data; in fcoe_ctlr_solicit()
397 memcpy(sol->eth.h_dest, fcf ? fcf->fcf_mac : fcoe_all_fcfs, ETH_ALEN); in fcoe_ctlr_solicit()
398 memcpy(sol->eth.h_source, fip->ctl_src_addr, ETH_ALEN); in fcoe_ctlr_solicit()
399 sol->eth.h_proto = htons(ETH_P_FIP); in fcoe_ctlr_solicit()
401 sol->fip.fip_ver = FIP_VER_ENCAPS(FIP_VER); in fcoe_ctlr_solicit()
402 sol->fip.fip_op = htons(FIP_OP_DISC); in fcoe_ctlr_solicit()
403 sol->fip.fip_subcode = FIP_SC_SOL; in fcoe_ctlr_solicit()
404 sol->fip.fip_dl_len = htons(sizeof(sol->desc) / FIP_BPW); in fcoe_ctlr_solicit()
405 sol->fip.fip_flags = htons(FIP_FL_FPMA); in fcoe_ctlr_solicit()
406 if (fip->spma) in fcoe_ctlr_solicit()
407 sol->fip.fip_flags |= htons(FIP_FL_SPMA); in fcoe_ctlr_solicit()
409 sol->desc.mac.fd_desc.fip_dtype = FIP_DT_MAC; in fcoe_ctlr_solicit()
410 sol->desc.mac.fd_desc.fip_dlen = sizeof(sol->desc.mac) / FIP_BPW; in fcoe_ctlr_solicit()
411 memcpy(sol->desc.mac.fd_mac, fip->ctl_src_addr, ETH_ALEN); in fcoe_ctlr_solicit()
413 sol->desc.wwnn.fd_desc.fip_dtype = FIP_DT_NAME; in fcoe_ctlr_solicit()
414 sol->desc.wwnn.fd_desc.fip_dlen = sizeof(sol->desc.wwnn) / FIP_BPW; in fcoe_ctlr_solicit()
415 put_unaligned_be64(fip->lp->wwnn, &sol->desc.wwnn.fd_wwn); in fcoe_ctlr_solicit()
418 sol->desc.size.fd_desc.fip_dtype = FIP_DT_FCOE_SIZE; in fcoe_ctlr_solicit()
419 sol->desc.size.fd_desc.fip_dlen = sizeof(sol->desc.size) / FIP_BPW; in fcoe_ctlr_solicit()
420 sol->desc.size.fd_size = htons(fcoe_size); in fcoe_ctlr_solicit()
423 skb->protocol = htons(ETH_P_FIP); in fcoe_ctlr_solicit()
424 skb->priority = fip->priority; in fcoe_ctlr_solicit()
427 fip->send(fip, skb); in fcoe_ctlr_solicit()
430 fip->sol_time = jiffies; in fcoe_ctlr_solicit()
434 * fcoe_ctlr_link_up() - Start FCoE controller
441 mutex_lock(&fip->ctlr_mutex); in fcoe_ctlr_link_up()
442 if (fip->state == FIP_ST_NON_FIP || fip->state == FIP_ST_AUTO) { in fcoe_ctlr_link_up()
443 mutex_unlock(&fip->ctlr_mutex); in fcoe_ctlr_link_up()
444 fc_linkup(fip->lp); in fcoe_ctlr_link_up()
445 } else if (fip->state == FIP_ST_LINK_WAIT) { in fcoe_ctlr_link_up()
446 if (fip->mode == FIP_MODE_NON_FIP) in fcoe_ctlr_link_up()
450 switch (fip->mode) { in fcoe_ctlr_link_up()
452 LIBFCOE_FIP_DBG(fip, "invalid mode %d\n", fip->mode); in fcoe_ctlr_link_up()
459 mutex_unlock(&fip->ctlr_mutex); in fcoe_ctlr_link_up()
460 fc_linkup(fip->lp); in fcoe_ctlr_link_up()
465 mutex_unlock(&fip->ctlr_mutex); in fcoe_ctlr_link_up()
466 fc_linkup(fip->lp); in fcoe_ctlr_link_up()
470 mutex_unlock(&fip->ctlr_mutex); in fcoe_ctlr_link_up()
475 * fcoe_ctlr_reset() - Reset a FCoE controller
481 del_timer(&fip->timer); in fcoe_ctlr_reset()
482 fip->ctlr_ka_time = 0; in fcoe_ctlr_reset()
483 fip->port_ka_time = 0; in fcoe_ctlr_reset()
484 fip->sol_time = 0; in fcoe_ctlr_reset()
485 fip->flogi_oxid = FC_XID_UNKNOWN; in fcoe_ctlr_reset()
490 * fcoe_ctlr_link_down() - Stop a FCoE controller
493 * Returns non-zero if the link was up and now isn't.
503 mutex_lock(&fip->ctlr_mutex); in fcoe_ctlr_link_down()
505 link_dropped = fip->state != FIP_ST_LINK_WAIT; in fcoe_ctlr_link_down()
507 mutex_unlock(&fip->ctlr_mutex); in fcoe_ctlr_link_down()
510 fc_linkdown(fip->lp); in fcoe_ctlr_link_down()
516 * fcoe_ctlr_send_keep_alive() - Send a keep-alive to the selected FCF
519 * @ports: 0 for controller keep-alive, 1 for port keep-alive
522 * A controller keep-alive is sent every fka_period (typically 8 seconds).
525 * A port keep-alive is sent every 90 seconds while logged in.
527 * The destination is the FCF's F-port.
544 fcf = fip->sel_fcf; in fcoe_ctlr_send_keep_alive()
545 lp = fip->lp; in fcoe_ctlr_send_keep_alive()
546 if (!fcf || (ports && !lp->port_id)) in fcoe_ctlr_send_keep_alive()
554 kal = (struct fip_kal *)skb->data; in fcoe_ctlr_send_keep_alive()
556 memcpy(kal->eth.h_dest, fcf->fcf_mac, ETH_ALEN); in fcoe_ctlr_send_keep_alive()
557 memcpy(kal->eth.h_source, sa, ETH_ALEN); in fcoe_ctlr_send_keep_alive()
558 kal->eth.h_proto = htons(ETH_P_FIP); in fcoe_ctlr_send_keep_alive()
560 kal->fip.fip_ver = FIP_VER_ENCAPS(FIP_VER); in fcoe_ctlr_send_keep_alive()
561 kal->fip.fip_op = htons(FIP_OP_CTRL); in fcoe_ctlr_send_keep_alive()
562 kal->fip.fip_subcode = FIP_SC_KEEP_ALIVE; in fcoe_ctlr_send_keep_alive()
563 kal->fip.fip_dl_len = htons((sizeof(kal->mac) + in fcoe_ctlr_send_keep_alive()
565 kal->fip.fip_flags = htons(FIP_FL_FPMA); in fcoe_ctlr_send_keep_alive()
566 if (fip->spma) in fcoe_ctlr_send_keep_alive()
567 kal->fip.fip_flags |= htons(FIP_FL_SPMA); in fcoe_ctlr_send_keep_alive()
569 kal->mac.fd_desc.fip_dtype = FIP_DT_MAC; in fcoe_ctlr_send_keep_alive()
570 kal->mac.fd_desc.fip_dlen = sizeof(kal->mac) / FIP_BPW; in fcoe_ctlr_send_keep_alive()
571 memcpy(kal->mac.fd_mac, fip->ctl_src_addr, ETH_ALEN); in fcoe_ctlr_send_keep_alive()
574 vn->fd_desc.fip_dtype = FIP_DT_VN_ID; in fcoe_ctlr_send_keep_alive()
575 vn->fd_desc.fip_dlen = sizeof(*vn) / FIP_BPW; in fcoe_ctlr_send_keep_alive()
576 memcpy(vn->fd_mac, fip->get_src_addr(lport), ETH_ALEN); in fcoe_ctlr_send_keep_alive()
577 hton24(vn->fd_fc_id, lport->port_id); in fcoe_ctlr_send_keep_alive()
578 put_unaligned_be64(lport->wwpn, &vn->fd_wwpn); in fcoe_ctlr_send_keep_alive()
581 skb->protocol = htons(ETH_P_FIP); in fcoe_ctlr_send_keep_alive()
582 skb->priority = fip->priority; in fcoe_ctlr_send_keep_alive()
585 fip->send(fip, skb); in fcoe_ctlr_send_keep_alive()
589 * fcoe_ctlr_encaps() - Encapsulate an ELS frame for FIP, without sending it
590 * @fip: The FCoE controller for the ELS frame
592 * @dtype: The FIP descriptor type for the frame
593 * @skb: The FCoE ELS frame including FC header but no FCoE headers
596 * Returns non-zero error code on failure.
619 fh = (struct fc_frame_header *)skb->data; in fcoe_ctlr_encaps()
621 dlen = sizeof(struct fip_encaps) + skb->len; /* len before push */ in fcoe_ctlr_encaps()
625 if (lport->point_to_multipoint) { in fcoe_ctlr_encaps()
626 if (fcoe_ctlr_vn_lookup(fip, d_id, cap->eth.h_dest)) in fcoe_ctlr_encaps()
627 return -ENODEV; in fcoe_ctlr_encaps()
630 fcf = fip->sel_fcf; in fcoe_ctlr_encaps()
632 return -ENODEV; in fcoe_ctlr_encaps()
633 fip_flags = fcf->flags; in fcoe_ctlr_encaps()
634 fip_flags &= fip->spma ? FIP_FL_SPMA | FIP_FL_FPMA : in fcoe_ctlr_encaps()
637 return -ENODEV; in fcoe_ctlr_encaps()
638 memcpy(cap->eth.h_dest, fcf->fcf_mac, ETH_ALEN); in fcoe_ctlr_encaps()
640 memcpy(cap->eth.h_source, fip->ctl_src_addr, ETH_ALEN); in fcoe_ctlr_encaps()
641 cap->eth.h_proto = htons(ETH_P_FIP); in fcoe_ctlr_encaps()
643 cap->fip.fip_ver = FIP_VER_ENCAPS(FIP_VER); in fcoe_ctlr_encaps()
644 cap->fip.fip_op = htons(FIP_OP_LS); in fcoe_ctlr_encaps()
646 cap->fip.fip_subcode = FIP_SC_REP; in fcoe_ctlr_encaps()
648 cap->fip.fip_subcode = FIP_SC_REQ; in fcoe_ctlr_encaps()
649 cap->fip.fip_flags = htons(fip_flags); in fcoe_ctlr_encaps()
651 cap->encaps.fd_desc.fip_dtype = dtype; in fcoe_ctlr_encaps()
652 cap->encaps.fd_desc.fip_dlen = dlen / FIP_BPW; in fcoe_ctlr_encaps()
657 mac->fd_desc.fip_dtype = FIP_DT_MAC; in fcoe_ctlr_encaps()
658 mac->fd_desc.fip_dlen = sizeof(*mac) / FIP_BPW; in fcoe_ctlr_encaps()
660 memcpy(mac->fd_mac, fip->get_src_addr(lport), ETH_ALEN); in fcoe_ctlr_encaps()
661 } else if (fip->mode == FIP_MODE_VN2VN) { in fcoe_ctlr_encaps()
662 hton24(mac->fd_mac, FIP_VN_FC_MAP); in fcoe_ctlr_encaps()
663 hton24(mac->fd_mac + 3, fip->port_id); in fcoe_ctlr_encaps()
666 memcpy(mac->fd_mac, fip->ctl_src_addr, ETH_ALEN); in fcoe_ctlr_encaps()
672 cap->fip.fip_dl_len = htons(dlen / FIP_BPW); in fcoe_ctlr_encaps()
674 skb->protocol = htons(ETH_P_FIP); in fcoe_ctlr_encaps()
675 skb->priority = fip->priority; in fcoe_ctlr_encaps()
682 * fcoe_ctlr_els_send() - Send an ELS frame encapsulated by FIP if appropriate.
685 * @skb: FCoE ELS frame including FC header but no FCoE headers.
687 * Returns a non-zero error code if the frame should not be sent.
688 * Returns zero if the caller should send the frame with FCoE encapsulation.
694 * This is called from the lower-level driver with spinlocks held,
707 fh = (struct fc_frame_header *)skb->data; in fcoe_ctlr_els_send()
710 if (op == ELS_FLOGI && fip->mode != FIP_MODE_VN2VN) { in fcoe_ctlr_els_send()
711 old_xid = fip->flogi_oxid; in fcoe_ctlr_els_send()
712 fip->flogi_oxid = ntohs(fh->fh_ox_id); in fcoe_ctlr_els_send()
713 if (fip->state == FIP_ST_AUTO) { in fcoe_ctlr_els_send()
715 fip->flogi_count = 0; in fcoe_ctlr_els_send()
716 fip->flogi_count++; in fcoe_ctlr_els_send()
717 if (fip->flogi_count < 3) in fcoe_ctlr_els_send()
722 if (fip->state == FIP_ST_NON_FIP) in fcoe_ctlr_els_send()
726 if (fip->state == FIP_ST_NON_FIP) in fcoe_ctlr_els_send()
728 if (!fip->sel_fcf && fip->mode != FIP_MODE_VN2VN) in fcoe_ctlr_els_send()
733 if (fip->mode == FIP_MODE_VN2VN) in fcoe_ctlr_els_send()
735 spin_lock_bh(&fip->ctlr_lock); in fcoe_ctlr_els_send()
736 kfree_skb(fip->flogi_req); in fcoe_ctlr_els_send()
737 fip->flogi_req = skb; in fcoe_ctlr_els_send()
738 fip->flogi_req_send = 1; in fcoe_ctlr_els_send()
739 spin_unlock_bh(&fip->ctlr_lock); in fcoe_ctlr_els_send()
740 schedule_work(&fip->timer_work); in fcoe_ctlr_els_send()
741 return -EINPROGRESS; in fcoe_ctlr_els_send()
743 if (ntoh24(fh->fh_s_id)) in fcoe_ctlr_els_send()
748 if (fip->mode == FIP_MODE_VN2VN) { in fcoe_ctlr_els_send()
749 if (fip->state != FIP_ST_VNMP_UP) in fcoe_ctlr_els_send()
751 if (ntoh24(fh->fh_d_id) == FC_FID_FLOGI) in fcoe_ctlr_els_send()
754 if (fip->state != FIP_ST_ENABLED) in fcoe_ctlr_els_send()
756 if (ntoh24(fh->fh_d_id) != FC_FID_FLOGI) in fcoe_ctlr_els_send()
763 * If non-FIP, we may have gotten an SID by accepting an FLOGI in fcoe_ctlr_els_send()
764 * from a point-to-point connection. Switch to using in fcoe_ctlr_els_send()
769 if (fip->state == FIP_ST_NON_FIP) { in fcoe_ctlr_els_send()
770 if (fip->flogi_oxid == FC_XID_UNKNOWN) in fcoe_ctlr_els_send()
772 fip->flogi_oxid = FC_XID_UNKNOWN; in fcoe_ctlr_els_send()
773 fc_fcoe_set_mac(mac, fh->fh_d_id); in fcoe_ctlr_els_send()
774 fip->update_mac(lport, mac); in fcoe_ctlr_els_send()
783 if (fip->state != FIP_ST_ENABLED && in fcoe_ctlr_els_send()
784 fip->state != FIP_ST_VNMP_UP) in fcoe_ctlr_els_send()
789 op, ntoh24(fh->fh_d_id)); in fcoe_ctlr_els_send()
790 if (fcoe_ctlr_encaps(fip, lport, op, skb, ntoh24(fh->fh_d_id))) in fcoe_ctlr_els_send()
792 fip->send(fip, skb); in fcoe_ctlr_els_send()
793 return -EINPROGRESS; in fcoe_ctlr_els_send()
796 op, ntoh24(fh->fh_d_id)); in fcoe_ctlr_els_send()
798 return -EINVAL; in fcoe_ctlr_els_send()
803 * fcoe_ctlr_age_fcfs() - Reset and free all old FCFs for a controller
810 * times its keep-alive period.
815 * for the corresponding FCF for 1.5 * FKA_ADV_PERIOD (FC-BB-5 LESB).
831 stats = per_cpu_ptr(fip->lp->stats, get_cpu()); in fcoe_ctlr_age_fcfs()
833 list_for_each_entry_safe(fcf, next, &fip->fcfs, list) { in fcoe_ctlr_age_fcfs()
834 deadline = fcf->time + fcf->fka_period + fcf->fka_period / 2; in fcoe_ctlr_age_fcfs()
835 if (fip->sel_fcf == fcf) { in fcoe_ctlr_age_fcfs()
837 stats->MissDiscAdvCount++; in fcoe_ctlr_age_fcfs()
841 fip->lp->host->host_no, fcf->fabric_name, in fcoe_ctlr_age_fcfs()
842 stats->MissDiscAdvCount); in fcoe_ctlr_age_fcfs()
847 deadline += fcf->fka_period; in fcoe_ctlr_age_fcfs()
849 if (fip->sel_fcf == fcf) in fcoe_ctlr_age_fcfs()
850 fip->sel_fcf = NULL; in fcoe_ctlr_age_fcfs()
856 list_del(&fcf->list); in fcoe_ctlr_age_fcfs()
857 list_add(&fcf->list, &del_list); in fcoe_ctlr_age_fcfs()
858 stats->VLinkFailureCount++; in fcoe_ctlr_age_fcfs()
863 (!sel_time || time_before(sel_time, fcf->time))) in fcoe_ctlr_age_fcfs()
864 sel_time = fcf->time; in fcoe_ctlr_age_fcfs()
874 if (sel_time && !fip->sel_fcf && !fip->sel_time) { in fcoe_ctlr_age_fcfs()
876 fip->sel_time = sel_time; in fcoe_ctlr_age_fcfs()
883 * fcoe_ctlr_parse_adv() - Decode a FIP advertisement into a new FCF entry
885 * @skb: The received FIP advertisement frame
905 fcf->fka_period = msecs_to_jiffies(FCOE_CTLR_DEF_FKA); in fcoe_ctlr_parse_adv()
907 fiph = (struct fip_header *)skb->data; in fcoe_ctlr_parse_adv()
908 fcf->flags = ntohs(fiph->fip_flags); in fcoe_ctlr_parse_adv()
916 rlen = ntohs(fiph->fip_dl_len) * 4; in fcoe_ctlr_parse_adv()
917 if (rlen + sizeof(*fiph) > skb->len) in fcoe_ctlr_parse_adv()
918 return -EINVAL; in fcoe_ctlr_parse_adv()
922 dlen = desc->fip_dlen * FIP_BPW; in fcoe_ctlr_parse_adv()
924 return -EINVAL; in fcoe_ctlr_parse_adv()
926 if ((desc->fip_dtype < 32) && in fcoe_ctlr_parse_adv()
927 !(desc_mask & 1U << desc->fip_dtype)) { in fcoe_ctlr_parse_adv()
930 return -EINVAL; in fcoe_ctlr_parse_adv()
932 switch (desc->fip_dtype) { in fcoe_ctlr_parse_adv()
936 fcf->pri = ((struct fip_pri_desc *)desc)->fd_pri; in fcoe_ctlr_parse_adv()
942 memcpy(fcf->fcf_mac, in fcoe_ctlr_parse_adv()
943 ((struct fip_mac_desc *)desc)->fd_mac, in fcoe_ctlr_parse_adv()
945 memcpy(fcf->fcoe_mac, fcf->fcf_mac, ETH_ALEN); in fcoe_ctlr_parse_adv()
946 if (!is_valid_ether_addr(fcf->fcf_mac)) { in fcoe_ctlr_parse_adv()
949 fcf->fcf_mac); in fcoe_ctlr_parse_adv()
950 return -EINVAL; in fcoe_ctlr_parse_adv()
958 fcf->switch_name = get_unaligned_be64(&wwn->fd_wwn); in fcoe_ctlr_parse_adv()
965 fcf->fabric_name = get_unaligned_be64(&fab->fd_wwn); in fcoe_ctlr_parse_adv()
966 fcf->vfid = ntohs(fab->fd_vfid); in fcoe_ctlr_parse_adv()
967 fcf->fc_map = ntoh24(fab->fd_map); in fcoe_ctlr_parse_adv()
974 if (fka->fd_flags & FIP_FKA_ADV_D) in fcoe_ctlr_parse_adv()
975 fcf->fd_flags = 1; in fcoe_ctlr_parse_adv()
976 t = ntohl(fka->fd_fka_period); in fcoe_ctlr_parse_adv()
978 fcf->fka_period = msecs_to_jiffies(t); in fcoe_ctlr_parse_adv()
989 "in FIP adv\n", desc->fip_dtype); in fcoe_ctlr_parse_adv()
991 if (desc->fip_dtype < FIP_DT_NON_CRITICAL) in fcoe_ctlr_parse_adv()
992 return -EINVAL; in fcoe_ctlr_parse_adv()
996 rlen -= dlen; in fcoe_ctlr_parse_adv()
998 if (!fcf->fc_map || (fcf->fc_map & 0x10000)) in fcoe_ctlr_parse_adv()
999 return -EINVAL; in fcoe_ctlr_parse_adv()
1000 if (!fcf->switch_name) in fcoe_ctlr_parse_adv()
1001 return -EINVAL; in fcoe_ctlr_parse_adv()
1005 return -EINVAL; in fcoe_ctlr_parse_adv()
1011 desc->fip_dtype, dlen); in fcoe_ctlr_parse_adv()
1012 return -EINVAL; in fcoe_ctlr_parse_adv()
1016 * fcoe_ctlr_recv_adv() - Handle an incoming advertisement
1033 mutex_lock(&fip->ctlr_mutex); in fcoe_ctlr_recv_adv()
1034 first = list_empty(&fip->fcfs); in fcoe_ctlr_recv_adv()
1035 list_for_each_entry(fcf, &fip->fcfs, list) { in fcoe_ctlr_recv_adv()
1036 if (fcf->switch_name == new.switch_name && in fcoe_ctlr_recv_adv()
1037 fcf->fabric_name == new.fabric_name && in fcoe_ctlr_recv_adv()
1038 fcf->fc_map == new.fc_map && in fcoe_ctlr_recv_adv()
1039 ether_addr_equal(fcf->fcf_mac, new.fcf_mac)) { in fcoe_ctlr_recv_adv()
1045 if (fip->fcf_count >= FCOE_CTLR_FCF_LIMIT) in fcoe_ctlr_recv_adv()
1053 fcf->fip = fip; in fcoe_ctlr_recv_adv()
1064 * Update the FCF's keep-alive descriptor flags. in fcoe_ctlr_recv_adv()
1069 fcf->fd_flags = new.fd_flags; in fcoe_ctlr_recv_adv()
1071 fcf->flags = new.flags; in fcoe_ctlr_recv_adv()
1073 if (fcf == fip->sel_fcf && !fcf->fd_flags) { in fcoe_ctlr_recv_adv()
1074 fip->ctlr_ka_time -= fcf->fka_period; in fcoe_ctlr_recv_adv()
1075 fip->ctlr_ka_time += new.fka_period; in fcoe_ctlr_recv_adv()
1076 if (time_before(fip->ctlr_ka_time, fip->timer.expires)) in fcoe_ctlr_recv_adv()
1077 mod_timer(&fip->timer, fip->ctlr_ka_time); in fcoe_ctlr_recv_adv()
1079 fcf->fka_period = new.fka_period; in fcoe_ctlr_recv_adv()
1080 memcpy(fcf->fcf_mac, new.fcf_mac, ETH_ALEN); in fcoe_ctlr_recv_adv()
1084 fcf->time = jiffies; in fcoe_ctlr_recv_adv()
1087 fcf->fabric_name, fcf->fcf_mac); in fcoe_ctlr_recv_adv()
1102 if (first && time_after(jiffies, fip->sol_time + sol_tov)) in fcoe_ctlr_recv_adv()
1112 list_move(&fcf->list, &fip->fcfs); in fcoe_ctlr_recv_adv()
1118 if (mtu_valid && !fip->sel_fcf && !fip->sel_time && in fcoe_ctlr_recv_adv()
1120 fip->sel_time = jiffies + in fcoe_ctlr_recv_adv()
1122 if (!timer_pending(&fip->timer) || in fcoe_ctlr_recv_adv()
1123 time_before(fip->sel_time, fip->timer.expires)) in fcoe_ctlr_recv_adv()
1124 mod_timer(&fip->timer, fip->sel_time); in fcoe_ctlr_recv_adv()
1128 mutex_unlock(&fip->ctlr_mutex); in fcoe_ctlr_recv_adv()
1132 * fcoe_ctlr_recv_els() - Handle an incoming FIP encapsulated ELS frame
1138 struct fc_lport *lport = fip->lp; in fcoe_ctlr_recv_els()
1148 u8 sub; in fcoe_ctlr_recv_els() local
1156 fiph = (struct fip_header *)skb->data; in fcoe_ctlr_recv_els()
1157 sub = fiph->fip_subcode; in fcoe_ctlr_recv_els()
1158 if (sub != FIP_SC_REQ && sub != FIP_SC_REP) in fcoe_ctlr_recv_els()
1161 rlen = ntohs(fiph->fip_dl_len) * 4; in fcoe_ctlr_recv_els()
1162 if (rlen + sizeof(*fiph) > skb->len) in fcoe_ctlr_recv_els()
1168 dlen = desc->fip_dlen * FIP_BPW; in fcoe_ctlr_recv_els()
1172 if (desc->fip_dtype < 32) { in fcoe_ctlr_recv_els()
1173 if ((desc->fip_dtype != FIP_DT_MAC) && in fcoe_ctlr_recv_els()
1174 (desc_mask & 1U << desc->fip_dtype)) { in fcoe_ctlr_recv_els()
1179 desc_mask |= (1 << desc->fip_dtype); in fcoe_ctlr_recv_els()
1181 switch (desc->fip_dtype) { in fcoe_ctlr_recv_els()
1183 sel = fip->sel_fcf; in fcoe_ctlr_recv_els()
1199 ((struct fip_mac_desc *)desc)->fd_mac, in fcoe_ctlr_recv_els()
1206 memcpy(sel->fcoe_mac, in fcoe_ctlr_recv_els()
1207 ((struct fip_mac_desc *)desc)->fd_mac, in fcoe_ctlr_recv_els()
1223 els_len = dlen - sizeof(*els); in fcoe_ctlr_recv_els()
1226 els_dtype = desc->fip_dtype; in fcoe_ctlr_recv_els()
1230 "in FIP adv\n", desc->fip_dtype); in fcoe_ctlr_recv_els()
1232 if (desc->fip_dtype < FIP_DT_NON_CRITICAL) in fcoe_ctlr_recv_els()
1242 rlen -= dlen; in fcoe_ctlr_recv_els()
1250 sub == FIP_SC_REP && fip->mode != FIP_MODE_VN2VN) { in fcoe_ctlr_recv_els()
1258 memcpy(fr_cb(fp)->granted_mac, granted_mac, ETH_ALEN); in fcoe_ctlr_recv_els()
1260 if (fip->flogi_oxid == ntohs(fh->fh_ox_id)) { in fcoe_ctlr_recv_els()
1261 fip->flogi_oxid = FC_XID_UNKNOWN; in fcoe_ctlr_recv_els()
1280 skb_pull(skb, (u8 *)fh - skb->data); in fcoe_ctlr_recv_els()
1289 stats = per_cpu_ptr(lport->stats, get_cpu()); in fcoe_ctlr_recv_els()
1290 stats->RxFrames++; in fcoe_ctlr_recv_els()
1291 stats->RxWords += skb->len / FIP_BPW; in fcoe_ctlr_recv_els()
1299 desc->fip_dtype, dlen); in fcoe_ctlr_recv_els()
1305 * fcoe_ctlr_recv_els() - Handle an incoming link reset frame
1306 * @fip: The FCoE controller that received the frame
1321 struct fcoe_fcf *fcf = fip->sel_fcf; in fcoe_ctlr_recv_clr_vlink()
1322 struct fc_lport *lport = fip->lp; in fcoe_ctlr_recv_clr_vlink()
1328 struct fip_header *fh = (struct fip_header *)skb->data; in fcoe_ctlr_recv_clr_vlink()
1340 mutex_lock(&fip->ctlr_mutex); in fcoe_ctlr_recv_clr_vlink()
1342 mutex_unlock(&fip->ctlr_mutex); in fcoe_ctlr_recv_clr_vlink()
1351 if (!ether_addr_equal(eh->h_source, fcf->fcf_mac)) { in fcoe_ctlr_recv_clr_vlink()
1353 "mismatch with FCF src=%pM\n", eh->h_source); in fcoe_ctlr_recv_clr_vlink()
1361 if (!lport->port_id) { in fcoe_ctlr_recv_clr_vlink()
1363 mutex_lock(&fip->ctlr_mutex); in fcoe_ctlr_recv_clr_vlink()
1365 mutex_unlock(&fip->ctlr_mutex); in fcoe_ctlr_recv_clr_vlink()
1366 fc_lport_reset(fip->lp); in fcoe_ctlr_recv_clr_vlink()
1376 rlen = ntohs(fh->fip_dl_len) * FIP_BPW; in fcoe_ctlr_recv_clr_vlink()
1380 * Actually need to subtract 'sizeof(*mp) - sizeof(*wp)' from 'rlen' in fcoe_ctlr_recv_clr_vlink()
1393 dlen = desc->fip_dlen * FIP_BPW; in fcoe_ctlr_recv_clr_vlink()
1397 if ((desc->fip_dtype < 32) && in fcoe_ctlr_recv_clr_vlink()
1398 (desc->fip_dtype != FIP_DT_VN_ID) && in fcoe_ctlr_recv_clr_vlink()
1399 !(desc_mask & 1U << desc->fip_dtype)) { in fcoe_ctlr_recv_clr_vlink()
1404 switch (desc->fip_dtype) { in fcoe_ctlr_recv_clr_vlink()
1409 if (!ether_addr_equal(mp->fd_mac, fcf->fcf_mac)) in fcoe_ctlr_recv_clr_vlink()
1417 if (get_unaligned_be64(&wp->fd_wwn) != fcf->switch_name) in fcoe_ctlr_recv_clr_vlink()
1427 ntoh24(vp->fd_fc_id)); in fcoe_ctlr_recv_clr_vlink()
1429 mutex_lock(&fip->ctlr_mutex); in fcoe_ctlr_recv_clr_vlink()
1430 per_cpu_ptr(lport->stats, in fcoe_ctlr_recv_clr_vlink()
1431 get_cpu())->VLinkFailureCount++; in fcoe_ctlr_recv_clr_vlink()
1434 mutex_unlock(&fip->ctlr_mutex); in fcoe_ctlr_recv_clr_vlink()
1439 if (desc->fip_dtype < FIP_DT_NON_CRITICAL) in fcoe_ctlr_recv_clr_vlink()
1444 rlen -= dlen; in fcoe_ctlr_recv_clr_vlink()
1459 mutex_lock(&fip->ctlr_mutex); in fcoe_ctlr_recv_clr_vlink()
1460 per_cpu_ptr(lport->stats, get_cpu())->VLinkFailureCount++; in fcoe_ctlr_recv_clr_vlink()
1463 mutex_unlock(&fip->ctlr_mutex); in fcoe_ctlr_recv_clr_vlink()
1465 mutex_lock(&lport->lp_mutex); in fcoe_ctlr_recv_clr_vlink()
1466 list_for_each_entry(vn_port, &lport->vports, list) in fcoe_ctlr_recv_clr_vlink()
1468 mutex_unlock(&lport->lp_mutex); in fcoe_ctlr_recv_clr_vlink()
1470 fc_lport_reset(fip->lp); in fcoe_ctlr_recv_clr_vlink()
1479 ntoh24(vp->fd_fc_id)); in fcoe_ctlr_recv_clr_vlink()
1487 if (!ether_addr_equal(fip->get_src_addr(vn_port), in fcoe_ctlr_recv_clr_vlink()
1488 vp->fd_mac) || in fcoe_ctlr_recv_clr_vlink()
1489 get_unaligned_be64(&vp->fd_wwpn) != in fcoe_ctlr_recv_clr_vlink()
1490 vn_port->wwpn) in fcoe_ctlr_recv_clr_vlink()
1504 fc_lport_reset(fip->lp); in fcoe_ctlr_recv_clr_vlink()
1514 * fcoe_ctlr_recv() - Receive a FIP packet
1525 skb_queue_tail(&fip->fip_recv_list, skb); in fcoe_ctlr_recv()
1526 schedule_work(&fip->recv_work); in fcoe_ctlr_recv()
1531 * fcoe_ctlr_recv_handler() - Receive a FIP frame
1532 * @fip: The FCoE controller that received the frame
1533 * @skb: The received FIP frame
1535 * Returns non-zero if the frame is dropped.
1544 u8 sub; in fcoe_ctlr_recv_handler() local
1548 if (skb->len < sizeof(*fiph)) in fcoe_ctlr_recv_handler()
1551 if (fip->mode == FIP_MODE_VN2VN) { in fcoe_ctlr_recv_handler()
1552 if (!ether_addr_equal(eh->h_dest, fip->ctl_src_addr) && in fcoe_ctlr_recv_handler()
1553 !ether_addr_equal(eh->h_dest, fcoe_all_vn2vn) && in fcoe_ctlr_recv_handler()
1554 !ether_addr_equal(eh->h_dest, fcoe_all_p2p)) in fcoe_ctlr_recv_handler()
1556 } else if (!ether_addr_equal(eh->h_dest, fip->ctl_src_addr) && in fcoe_ctlr_recv_handler()
1557 !ether_addr_equal(eh->h_dest, fcoe_all_enode)) in fcoe_ctlr_recv_handler()
1559 fiph = (struct fip_header *)skb->data; in fcoe_ctlr_recv_handler()
1560 op = ntohs(fiph->fip_op); in fcoe_ctlr_recv_handler()
1561 sub = fiph->fip_subcode; in fcoe_ctlr_recv_handler()
1563 if (FIP_VER_DECAPS(fiph->fip_ver) != FIP_VER) in fcoe_ctlr_recv_handler()
1565 if (ntohs(fiph->fip_dl_len) * FIP_BPW + sizeof(*fiph) > skb->len) in fcoe_ctlr_recv_handler()
1568 mutex_lock(&fip->ctlr_mutex); in fcoe_ctlr_recv_handler()
1569 state = fip->state; in fcoe_ctlr_recv_handler()
1571 fip->map_dest = 0; in fcoe_ctlr_recv_handler()
1576 fip_vlan_resp = fip->fip_resp; in fcoe_ctlr_recv_handler()
1577 mutex_unlock(&fip->ctlr_mutex); in fcoe_ctlr_recv_handler()
1579 if (fip->mode == FIP_MODE_VN2VN && op == FIP_OP_VN2VN) in fcoe_ctlr_recv_handler()
1599 if (op == FIP_OP_DISC && sub == FIP_SC_ADV) in fcoe_ctlr_recv_handler()
1601 else if (op == FIP_OP_CTRL && sub == FIP_SC_CLR_VLINK) in fcoe_ctlr_recv_handler()
1607 return -1; in fcoe_ctlr_recv_handler()
1611 * fcoe_ctlr_select() - Select the best FCF (if possible)
1626 struct fcoe_fcf *best = fip->sel_fcf; in fcoe_ctlr_select()
1628 list_for_each_entry(fcf, &fip->fcfs, list) { in fcoe_ctlr_select()
1632 fcf->fabric_name, fcf->vfid, fcf->fcf_mac, in fcoe_ctlr_select()
1633 fcf->fc_map, fcoe_ctlr_mtu_valid(fcf), in fcoe_ctlr_select()
1634 fcf->flogi_sent, fcf->pri); in fcoe_ctlr_select()
1638 fcf->fabric_name, fcf->fc_map, in fcoe_ctlr_select()
1639 (fcf->flags & FIP_FL_SOL) ? "" : "in", in fcoe_ctlr_select()
1640 (fcf->flags & FIP_FL_AVAIL) ? in fcoe_ctlr_select()
1644 if (!best || fcf->pri < best->pri || best->flogi_sent) in fcoe_ctlr_select()
1646 if (fcf->fabric_name != best->fabric_name || in fcoe_ctlr_select()
1647 fcf->vfid != best->vfid || in fcoe_ctlr_select()
1648 fcf->fc_map != best->fc_map) { in fcoe_ctlr_select()
1650 "or FC-MAP\n"); in fcoe_ctlr_select()
1654 fip->sel_fcf = best; in fcoe_ctlr_select()
1656 LIBFCOE_FIP_DBG(fip, "using FCF mac %pM\n", best->fcf_mac); in fcoe_ctlr_select()
1657 fip->port_ka_time = jiffies + in fcoe_ctlr_select()
1659 fip->ctlr_ka_time = jiffies + best->fka_period; in fcoe_ctlr_select()
1660 if (time_before(fip->ctlr_ka_time, fip->timer.expires)) in fcoe_ctlr_select()
1661 mod_timer(&fip->timer, fip->ctlr_ka_time); in fcoe_ctlr_select()
1667 * fcoe_ctlr_flogi_send_locked() - send FIP-encapsulated FLOGI to current FCF
1670 * Returns non-zero error if it could not be sent.
1673 * Caller must verify that fip->sel_fcf is not NULL.
1682 skb_orig = fip->flogi_req; in fcoe_ctlr_flogi_send_locked()
1684 return -EINVAL; in fcoe_ctlr_flogi_send_locked()
1692 fip->flogi_req = NULL; in fcoe_ctlr_flogi_send_locked()
1694 fh = (struct fc_frame_header *)skb->data; in fcoe_ctlr_flogi_send_locked()
1695 error = fcoe_ctlr_encaps(fip, fip->lp, FIP_DT_FLOGI, skb, in fcoe_ctlr_flogi_send_locked()
1696 ntoh24(fh->fh_d_id)); in fcoe_ctlr_flogi_send_locked()
1701 fip->send(fip, skb); in fcoe_ctlr_flogi_send_locked()
1702 fip->sel_fcf->flogi_sent = 1; in fcoe_ctlr_flogi_send_locked()
1707 * fcoe_ctlr_flogi_retry() - resend FLOGI request to a new FCF if possible
1710 * Returns non-zero error code if there's no FLOGI request to retry or
1718 mutex_lock(&fip->ctlr_mutex); in fcoe_ctlr_flogi_retry()
1719 spin_lock_bh(&fip->ctlr_lock); in fcoe_ctlr_flogi_retry()
1720 LIBFCOE_FIP_DBG(fip, "re-sending FLOGI - reselect\n"); in fcoe_ctlr_flogi_retry()
1722 if (!fcf || fcf->flogi_sent) { in fcoe_ctlr_flogi_retry()
1723 kfree_skb(fip->flogi_req); in fcoe_ctlr_flogi_retry()
1724 fip->flogi_req = NULL; in fcoe_ctlr_flogi_retry()
1725 error = -ENOENT; in fcoe_ctlr_flogi_retry()
1730 spin_unlock_bh(&fip->ctlr_lock); in fcoe_ctlr_flogi_retry()
1731 mutex_unlock(&fip->ctlr_mutex); in fcoe_ctlr_flogi_retry()
1737 * fcoe_ctlr_flogi_send() - Handle sending of FIP FLOGI.
1748 spin_lock_bh(&fip->ctlr_lock); in fcoe_ctlr_flogi_send()
1749 fcf = fip->sel_fcf; in fcoe_ctlr_flogi_send()
1750 if (!fcf || !fip->flogi_req_send) in fcoe_ctlr_flogi_send()
1759 if (fcf->flogi_sent) { in fcoe_ctlr_flogi_send()
1760 LIBFCOE_FIP_DBG(fip, "sending FLOGI - reselect\n"); in fcoe_ctlr_flogi_send()
1762 if (!fcf || fcf->flogi_sent) { in fcoe_ctlr_flogi_send()
1763 LIBFCOE_FIP_DBG(fip, "sending FLOGI - clearing\n"); in fcoe_ctlr_flogi_send()
1764 list_for_each_entry(fcf, &fip->fcfs, list) in fcoe_ctlr_flogi_send()
1765 fcf->flogi_sent = 0; in fcoe_ctlr_flogi_send()
1771 fip->flogi_req_send = 0; in fcoe_ctlr_flogi_send()
1773 LIBFCOE_FIP_DBG(fip, "No FCF selected - defer send\n"); in fcoe_ctlr_flogi_send()
1775 spin_unlock_bh(&fip->ctlr_lock); in fcoe_ctlr_flogi_send()
1779 * fcoe_ctlr_timeout() - FIP timeout handler
1786 schedule_work(&fip->timer_work); in fcoe_ctlr_timeout()
1790 * fcoe_ctlr_timer_work() - Worker thread function for timer work
1794 * Sends keep-alives and resets.
1809 if (fip->mode == FIP_MODE_VN2VN) in fcoe_ctlr_timer_work()
1811 mutex_lock(&fip->ctlr_mutex); in fcoe_ctlr_timer_work()
1812 if (fip->state == FIP_ST_DISABLED) { in fcoe_ctlr_timer_work()
1813 mutex_unlock(&fip->ctlr_mutex); in fcoe_ctlr_timer_work()
1817 fcf = fip->sel_fcf; in fcoe_ctlr_timer_work()
1820 sel = fip->sel_fcf; in fcoe_ctlr_timer_work()
1821 if (!sel && fip->sel_time) { in fcoe_ctlr_timer_work()
1822 if (time_after_eq(jiffies, fip->sel_time)) { in fcoe_ctlr_timer_work()
1824 fip->sel_time = 0; in fcoe_ctlr_timer_work()
1825 } else if (time_after(next_timer, fip->sel_time)) in fcoe_ctlr_timer_work()
1826 next_timer = fip->sel_time; in fcoe_ctlr_timer_work()
1829 if (sel && fip->flogi_req_send) in fcoe_ctlr_timer_work()
1834 if (sel && !sel->fd_flags) { in fcoe_ctlr_timer_work()
1835 if (time_after_eq(jiffies, fip->ctlr_ka_time)) { in fcoe_ctlr_timer_work()
1836 fip->ctlr_ka_time = jiffies + sel->fka_period; in fcoe_ctlr_timer_work()
1839 if (time_after(next_timer, fip->ctlr_ka_time)) in fcoe_ctlr_timer_work()
1840 next_timer = fip->ctlr_ka_time; in fcoe_ctlr_timer_work()
1842 if (time_after_eq(jiffies, fip->port_ka_time)) { in fcoe_ctlr_timer_work()
1843 fip->port_ka_time = jiffies + in fcoe_ctlr_timer_work()
1847 if (time_after(next_timer, fip->port_ka_time)) in fcoe_ctlr_timer_work()
1848 next_timer = fip->port_ka_time; in fcoe_ctlr_timer_work()
1850 if (!list_empty(&fip->fcfs)) in fcoe_ctlr_timer_work()
1851 mod_timer(&fip->timer, next_timer); in fcoe_ctlr_timer_work()
1852 mutex_unlock(&fip->ctlr_mutex); in fcoe_ctlr_timer_work()
1855 fc_lport_reset(fip->lp); in fcoe_ctlr_timer_work()
1861 fcoe_ctlr_send_keep_alive(fip, NULL, 0, fip->ctl_src_addr); in fcoe_ctlr_timer_work()
1864 mutex_lock(&fip->lp->lp_mutex); in fcoe_ctlr_timer_work()
1865 mac = fip->get_src_addr(fip->lp); in fcoe_ctlr_timer_work()
1866 fcoe_ctlr_send_keep_alive(fip, fip->lp, 1, mac); in fcoe_ctlr_timer_work()
1867 list_for_each_entry(vport, &fip->lp->vports, list) { in fcoe_ctlr_timer_work()
1868 mac = fip->get_src_addr(vport); in fcoe_ctlr_timer_work()
1871 mutex_unlock(&fip->lp->lp_mutex); in fcoe_ctlr_timer_work()
1876 * fcoe_ctlr_recv_work() - Worker thread function for receiving FIP frames
1885 while ((skb = skb_dequeue(&fip->fip_recv_list))) in fcoe_ctlr_recv_work()
1890 * fcoe_ctlr_recv_flogi() - Snoop pre-FIP receipt of FLOGI response
1893 * @fp: The FC frame to snoop
1898 * by fip->flogi_oxid != FC_XID_UNKNOWN.
1900 * The caller is responsible for freeing the frame.
1903 * Return non-zero if the frame should not be delivered to libfc.
1912 sa = eth_hdr(&fp->skb)->h_source; in fcoe_ctlr_recv_flogi()
1914 if (fh->fh_type != FC_TYPE_ELS) in fcoe_ctlr_recv_flogi()
1918 if (op == ELS_LS_ACC && fh->fh_r_ctl == FC_RCTL_ELS_REP && in fcoe_ctlr_recv_flogi()
1919 fip->flogi_oxid == ntohs(fh->fh_ox_id)) { in fcoe_ctlr_recv_flogi()
1921 mutex_lock(&fip->ctlr_mutex); in fcoe_ctlr_recv_flogi()
1922 if (fip->state != FIP_ST_AUTO && fip->state != FIP_ST_NON_FIP) { in fcoe_ctlr_recv_flogi()
1923 mutex_unlock(&fip->ctlr_mutex); in fcoe_ctlr_recv_flogi()
1924 return -EINVAL; in fcoe_ctlr_recv_flogi()
1928 "received FLOGI LS_ACC using non-FIP mode\n"); in fcoe_ctlr_recv_flogi()
1932 * If the src mac addr is FC_OUI-based, then we mark the in fcoe_ctlr_recv_flogi()
1933 * address_mode flag to use FC_OUI-based Ethernet DA. in fcoe_ctlr_recv_flogi()
1939 memcpy(fip->dest_addr, sa, ETH_ALEN); in fcoe_ctlr_recv_flogi()
1940 fip->map_dest = 0; in fcoe_ctlr_recv_flogi()
1942 fip->flogi_oxid = FC_XID_UNKNOWN; in fcoe_ctlr_recv_flogi()
1943 mutex_unlock(&fip->ctlr_mutex); in fcoe_ctlr_recv_flogi()
1944 fc_fcoe_set_mac(fr_cb(fp)->granted_mac, fh->fh_d_id); in fcoe_ctlr_recv_flogi()
1945 } else if (op == ELS_FLOGI && fh->fh_r_ctl == FC_RCTL_ELS_REQ && sa) { in fcoe_ctlr_recv_flogi()
1947 * Save source MAC for point-to-point responses. in fcoe_ctlr_recv_flogi()
1949 mutex_lock(&fip->ctlr_mutex); in fcoe_ctlr_recv_flogi()
1950 if (fip->state == FIP_ST_AUTO || fip->state == FIP_ST_NON_FIP) { in fcoe_ctlr_recv_flogi()
1951 memcpy(fip->dest_addr, sa, ETH_ALEN); in fcoe_ctlr_recv_flogi()
1952 fip->map_dest = 0; in fcoe_ctlr_recv_flogi()
1953 if (fip->state == FIP_ST_AUTO) in fcoe_ctlr_recv_flogi()
1954 LIBFCOE_FIP_DBG(fip, "received non-FIP FLOGI. " in fcoe_ctlr_recv_flogi()
1955 "Setting non-FIP mode\n"); in fcoe_ctlr_recv_flogi()
1958 mutex_unlock(&fip->ctlr_mutex); in fcoe_ctlr_recv_flogi()
1965 * fcoe_wwn_from_mac() - Converts a 48-bit IEEE MAC address to a 64-bit FC WWN
2006 * fcoe_ctlr_rport() - return the fcoe_rport for a given fc_rport_priv
2015 * fcoe_ctlr_vn_send() - Send a FIP VN2VN Probe Request or Reply.
2017 * @sub: sub-opcode for probe request, reply, or advertisement.
2022 enum fip_vn2vn_subcode sub, in fcoe_ctlr_vn_send() argument
2032 } __packed * frame; in fcoe_ctlr_vn_send() local
2039 len = sizeof(*frame); in fcoe_ctlr_vn_send()
2041 if (sub == FIP_SC_VN_CLAIM_NOTIFY || sub == FIP_SC_VN_CLAIM_REP) { in fcoe_ctlr_vn_send()
2046 dlen += sizeof(frame->mac) + sizeof(frame->wwnn) + sizeof(frame->vn); in fcoe_ctlr_vn_send()
2053 frame = (struct fip_vn2vn_probe_frame *)skb->data; in fcoe_ctlr_vn_send()
2054 memset(frame, 0, len); in fcoe_ctlr_vn_send()
2055 memcpy(frame->eth.h_dest, dest, ETH_ALEN); in fcoe_ctlr_vn_send()
2057 if (sub == FIP_SC_VN_BEACON) { in fcoe_ctlr_vn_send()
2058 hton24(frame->eth.h_source, FIP_VN_FC_MAP); in fcoe_ctlr_vn_send()
2059 hton24(frame->eth.h_source + 3, fip->port_id); in fcoe_ctlr_vn_send()
2061 memcpy(frame->eth.h_source, fip->ctl_src_addr, ETH_ALEN); in fcoe_ctlr_vn_send()
2063 frame->eth.h_proto = htons(ETH_P_FIP); in fcoe_ctlr_vn_send()
2065 frame->fip.fip_ver = FIP_VER_ENCAPS(FIP_VER); in fcoe_ctlr_vn_send()
2066 frame->fip.fip_op = htons(FIP_OP_VN2VN); in fcoe_ctlr_vn_send()
2067 frame->fip.fip_subcode = sub; in fcoe_ctlr_vn_send()
2068 frame->fip.fip_dl_len = htons(dlen / FIP_BPW); in fcoe_ctlr_vn_send()
2070 frame->mac.fd_desc.fip_dtype = FIP_DT_MAC; in fcoe_ctlr_vn_send()
2071 frame->mac.fd_desc.fip_dlen = sizeof(frame->mac) / FIP_BPW; in fcoe_ctlr_vn_send()
2072 memcpy(frame->mac.fd_mac, fip->ctl_src_addr, ETH_ALEN); in fcoe_ctlr_vn_send()
2074 frame->wwnn.fd_desc.fip_dtype = FIP_DT_NAME; in fcoe_ctlr_vn_send()
2075 frame->wwnn.fd_desc.fip_dlen = sizeof(frame->wwnn) / FIP_BPW; in fcoe_ctlr_vn_send()
2076 put_unaligned_be64(fip->lp->wwnn, &frame->wwnn.fd_wwn); in fcoe_ctlr_vn_send()
2078 frame->vn.fd_desc.fip_dtype = FIP_DT_VN_ID; in fcoe_ctlr_vn_send()
2079 frame->vn.fd_desc.fip_dlen = sizeof(frame->vn) / FIP_BPW; in fcoe_ctlr_vn_send()
2080 hton24(frame->vn.fd_mac, FIP_VN_FC_MAP); in fcoe_ctlr_vn_send()
2081 hton24(frame->vn.fd_mac + 3, fip->port_id); in fcoe_ctlr_vn_send()
2082 hton24(frame->vn.fd_fc_id, fip->port_id); in fcoe_ctlr_vn_send()
2083 put_unaligned_be64(fip->lp->wwpn, &frame->vn.fd_wwpn); in fcoe_ctlr_vn_send()
2086 * For claims, add FC-4 features. in fcoe_ctlr_vn_send()
2087 * TBD: Add interface to get fc-4 types and features from libfc. in fcoe_ctlr_vn_send()
2089 if (sub == FIP_SC_VN_CLAIM_NOTIFY || sub == FIP_SC_VN_CLAIM_REP) { in fcoe_ctlr_vn_send()
2090 ff = (struct fip_fc4_feat *)(frame + 1); in fcoe_ctlr_vn_send()
2091 ff->fd_desc.fip_dtype = FIP_DT_FC4F; in fcoe_ctlr_vn_send()
2092 ff->fd_desc.fip_dlen = sizeof(*ff) / FIP_BPW; in fcoe_ctlr_vn_send()
2093 ff->fd_fts = fip->lp->fcts; in fcoe_ctlr_vn_send()
2096 if (fip->lp->service_params & FCP_SPPF_INIT_FCN) in fcoe_ctlr_vn_send()
2098 if (fip->lp->service_params & FCP_SPPF_TARG_FCN) in fcoe_ctlr_vn_send()
2101 ff->fd_ff.fd_feat[FC_TYPE_FCP * 4 / 32] = htonl(fcp_feat); in fcoe_ctlr_vn_send()
2104 size->fd_desc.fip_dtype = FIP_DT_FCOE_SIZE; in fcoe_ctlr_vn_send()
2105 size->fd_desc.fip_dlen = sizeof(*size) / FIP_BPW; in fcoe_ctlr_vn_send()
2106 size->fd_size = htons(fcoe_ctlr_fcoe_size(fip)); in fcoe_ctlr_vn_send()
2110 skb->protocol = htons(ETH_P_FIP); in fcoe_ctlr_vn_send()
2111 skb->priority = fip->priority; in fcoe_ctlr_vn_send()
2115 fip->send(fip, skb); in fcoe_ctlr_vn_send()
2119 * fcoe_ctlr_vn_rport_callback - Event handler for rport events.
2130 struct fcoe_ctlr *fip = lport->disc.priv; in fcoe_ctlr_vn_rport_callback()
2134 rdata->ids.port_id, event); in fcoe_ctlr_vn_rport_callback()
2136 mutex_lock(&fip->ctlr_mutex); in fcoe_ctlr_vn_rport_callback()
2139 frport->login_count = 0; in fcoe_ctlr_vn_rport_callback()
2144 frport->login_count++; in fcoe_ctlr_vn_rport_callback()
2145 if (frport->login_count > FCOE_CTLR_VN2VN_LOGIN_LIMIT) { in fcoe_ctlr_vn_rport_callback()
2148 rdata->ids.port_id); in fcoe_ctlr_vn_rport_callback()
2155 mutex_unlock(&fip->ctlr_mutex); in fcoe_ctlr_vn_rport_callback()
2163 * fcoe_ctlr_disc_stop_locked() - stop discovery in VN2VN mode
2172 mutex_lock(&lport->disc.disc_mutex); in fcoe_ctlr_disc_stop_locked()
2173 list_for_each_entry_rcu(rdata, &lport->disc.rports, peers) { in fcoe_ctlr_disc_stop_locked()
2174 if (kref_get_unless_zero(&rdata->kref)) { in fcoe_ctlr_disc_stop_locked()
2176 kref_put(&rdata->kref, fc_rport_destroy); in fcoe_ctlr_disc_stop_locked()
2179 lport->disc.disc_callback = NULL; in fcoe_ctlr_disc_stop_locked()
2180 mutex_unlock(&lport->disc.disc_mutex); in fcoe_ctlr_disc_stop_locked()
2184 * fcoe_ctlr_disc_stop() - stop discovery in VN2VN mode
2192 struct fcoe_ctlr *fip = lport->disc.priv; in fcoe_ctlr_disc_stop()
2194 mutex_lock(&fip->ctlr_mutex); in fcoe_ctlr_disc_stop()
2196 mutex_unlock(&fip->ctlr_mutex); in fcoe_ctlr_disc_stop()
2200 * fcoe_ctlr_disc_stop_final() - stop discovery for shutdown in VN2VN mode
2214 * fcoe_ctlr_vn_restart() - VN2VN probe restart with new port_id
2224 fcoe_ctlr_disc_stop_locked(fip->lp); in fcoe_ctlr_vn_restart()
2231 * Don't use reserved IDs, use another non-zero value, just as random. in fcoe_ctlr_vn_restart()
2233 port_id = fip->port_id; in fcoe_ctlr_vn_restart()
2234 if (fip->probe_tries) in fcoe_ctlr_vn_restart()
2235 port_id = prandom_u32_state(&fip->rnd_state) & 0xffff; in fcoe_ctlr_vn_restart()
2237 port_id = fip->lp->wwpn & 0xffff; in fcoe_ctlr_vn_restart()
2240 fip->port_id = port_id; in fcoe_ctlr_vn_restart()
2242 if (fip->probe_tries < FIP_VN_RLIM_COUNT) { in fcoe_ctlr_vn_restart()
2243 fip->probe_tries++; in fcoe_ctlr_vn_restart()
2247 mod_timer(&fip->timer, jiffies + msecs_to_jiffies(wait)); in fcoe_ctlr_vn_restart()
2252 * fcoe_ctlr_vn_start() - Start in VN2VN mode
2259 fip->probe_tries = 0; in fcoe_ctlr_vn_start()
2260 prandom_seed_state(&fip->rnd_state, fip->lp->wwpn); in fcoe_ctlr_vn_start()
2265 * fcoe_ctlr_vn_parse - parse probe request or response
2270 * Returns non-zero error number on error.
2287 u8 sub; in fcoe_ctlr_vn_parse() local
2289 fiph = (struct fip_header *)skb->data; in fcoe_ctlr_vn_parse()
2290 frport->flags = ntohs(fiph->fip_flags); in fcoe_ctlr_vn_parse()
2292 sub = fiph->fip_subcode; in fcoe_ctlr_vn_parse()
2293 switch (sub) { in fcoe_ctlr_vn_parse()
2307 LIBFCOE_FIP_DBG(fip, "vn_parse unknown subcode %u\n", sub); in fcoe_ctlr_vn_parse()
2308 return -EINVAL; in fcoe_ctlr_vn_parse()
2311 rlen = ntohs(fiph->fip_dl_len) * 4; in fcoe_ctlr_vn_parse()
2312 if (rlen + sizeof(*fiph) > skb->len) in fcoe_ctlr_vn_parse()
2313 return -EINVAL; in fcoe_ctlr_vn_parse()
2317 dlen = desc->fip_dlen * FIP_BPW; in fcoe_ctlr_vn_parse()
2319 return -EINVAL; in fcoe_ctlr_vn_parse()
2321 dtype = desc->fip_dtype; in fcoe_ctlr_vn_parse()
2328 dtype, sub); in fcoe_ctlr_vn_parse()
2329 return -EINVAL; in fcoe_ctlr_vn_parse()
2339 if (!is_valid_ether_addr(macd->fd_mac)) { in fcoe_ctlr_vn_parse()
2342 macd->fd_mac); in fcoe_ctlr_vn_parse()
2343 return -EINVAL; in fcoe_ctlr_vn_parse()
2345 memcpy(frport->enode_mac, macd->fd_mac, ETH_ALEN); in fcoe_ctlr_vn_parse()
2351 frport->rdata.ids.node_name = in fcoe_ctlr_vn_parse()
2352 get_unaligned_be64(&wwn->fd_wwn); in fcoe_ctlr_vn_parse()
2358 memcpy(frport->vn_mac, vn->fd_mac, ETH_ALEN); in fcoe_ctlr_vn_parse()
2359 frport->rdata.ids.port_id = ntoh24(vn->fd_fc_id); in fcoe_ctlr_vn_parse()
2360 frport->rdata.ids.port_name = in fcoe_ctlr_vn_parse()
2361 get_unaligned_be64(&vn->fd_wwpn); in fcoe_ctlr_vn_parse()
2371 frport->fcoe_len = ntohs(size->fd_size); in fcoe_ctlr_vn_parse()
2378 return -EINVAL; in fcoe_ctlr_vn_parse()
2382 rlen -= dlen; in fcoe_ctlr_vn_parse()
2389 return -EINVAL; in fcoe_ctlr_vn_parse()
2393 * fcoe_ctlr_vn_send_claim() - send multicast FIP VN2VN Claim Notification.
2401 fip->sol_time = jiffies; in fcoe_ctlr_vn_send_claim()
2405 * fcoe_ctlr_vn_probe_req() - handle incoming VN2VN probe request.
2414 if (frport->rdata.ids.port_id != fip->port_id) in fcoe_ctlr_vn_probe_req()
2417 switch (fip->state) { in fcoe_ctlr_vn_probe_req()
2421 fip->state); in fcoe_ctlr_vn_probe_req()
2423 frport->enode_mac, 0); in fcoe_ctlr_vn_probe_req()
2434 if (fip->lp->wwpn > frport->rdata.ids.port_name && in fcoe_ctlr_vn_probe_req()
2435 !(frport->flags & FIP_FL_REC_OR_P2P)) { in fcoe_ctlr_vn_probe_req()
2439 frport->enode_mac, 0); in fcoe_ctlr_vn_probe_req()
2450 fip->state); in fcoe_ctlr_vn_probe_req()
2456 * fcoe_ctlr_vn_probe_reply() - handle incoming VN2VN probe reply.
2465 if (frport->rdata.ids.port_id != fip->port_id) in fcoe_ctlr_vn_probe_reply()
2467 switch (fip->state) { in fcoe_ctlr_vn_probe_reply()
2473 fip->state); in fcoe_ctlr_vn_probe_reply()
2486 * fcoe_ctlr_vn_add() - Add a VN2VN entry to the list, based on a claim reply.
2488 * @new: newly-parsed FCoE rport as a template for new rdata
2494 struct fc_lport *lport = fip->lp; in fcoe_ctlr_vn_add()
2500 port_id = new->rdata.ids.port_id; in fcoe_ctlr_vn_add()
2501 if (port_id == fip->port_id) in fcoe_ctlr_vn_add()
2504 mutex_lock(&lport->disc.disc_mutex); in fcoe_ctlr_vn_add()
2507 mutex_unlock(&lport->disc.disc_mutex); in fcoe_ctlr_vn_add()
2510 mutex_lock(&rdata->rp_mutex); in fcoe_ctlr_vn_add()
2511 mutex_unlock(&lport->disc.disc_mutex); in fcoe_ctlr_vn_add()
2513 rdata->ops = &fcoe_ctlr_vn_rport_ops; in fcoe_ctlr_vn_add()
2514 rdata->disc_id = lport->disc.disc_id; in fcoe_ctlr_vn_add()
2516 ids = &rdata->ids; in fcoe_ctlr_vn_add()
2517 if ((ids->port_name != -1 && in fcoe_ctlr_vn_add()
2518 ids->port_name != new->rdata.ids.port_name) || in fcoe_ctlr_vn_add()
2519 (ids->node_name != -1 && in fcoe_ctlr_vn_add()
2520 ids->node_name != new->rdata.ids.node_name)) { in fcoe_ctlr_vn_add()
2521 mutex_unlock(&rdata->rp_mutex); in fcoe_ctlr_vn_add()
2524 mutex_lock(&rdata->rp_mutex); in fcoe_ctlr_vn_add()
2526 ids->port_name = new->rdata.ids.port_name; in fcoe_ctlr_vn_add()
2527 ids->node_name = new->rdata.ids.node_name; in fcoe_ctlr_vn_add()
2528 mutex_unlock(&rdata->rp_mutex); in fcoe_ctlr_vn_add()
2532 port_id, frport->fcoe_len ? "old" : "new", in fcoe_ctlr_vn_add()
2533 rdata->rp_state); in fcoe_ctlr_vn_add()
2534 frport->fcoe_len = new->fcoe_len; in fcoe_ctlr_vn_add()
2535 frport->flags = new->flags; in fcoe_ctlr_vn_add()
2536 frport->login_count = new->login_count; in fcoe_ctlr_vn_add()
2537 memcpy(frport->enode_mac, new->enode_mac, ETH_ALEN); in fcoe_ctlr_vn_add()
2538 memcpy(frport->vn_mac, new->vn_mac, ETH_ALEN); in fcoe_ctlr_vn_add()
2539 frport->time = 0; in fcoe_ctlr_vn_add()
2543 * fcoe_ctlr_vn_lookup() - Find VN remote port's MAC address
2548 * Returns non-zero error if no remote port found.
2552 struct fc_lport *lport = fip->lp; in fcoe_ctlr_vn_lookup()
2555 int ret = -1; in fcoe_ctlr_vn_lookup()
2560 memcpy(mac, frport->enode_mac, ETH_ALEN); in fcoe_ctlr_vn_lookup()
2562 kref_put(&rdata->kref, fc_rport_destroy); in fcoe_ctlr_vn_lookup()
2568 * fcoe_ctlr_vn_claim_notify() - handle received FIP VN2VN Claim Notification
2570 * @new: newly-parsed FCoE rport as a template for new rdata
2577 if (new->flags & FIP_FL_REC_OR_P2P) { in fcoe_ctlr_vn_claim_notify()
2582 switch (fip->state) { in fcoe_ctlr_vn_claim_notify()
2586 if (new->rdata.ids.port_id == fip->port_id) { in fcoe_ctlr_vn_claim_notify()
2589 fip->state); in fcoe_ctlr_vn_claim_notify()
2595 if (new->rdata.ids.port_id == fip->port_id) { in fcoe_ctlr_vn_claim_notify()
2596 if (new->rdata.ids.port_name > fip->lp->wwpn) { in fcoe_ctlr_vn_claim_notify()
2608 new->rdata.ids.port_id); in fcoe_ctlr_vn_claim_notify()
2609 fcoe_ctlr_vn_send(fip, FIP_SC_VN_CLAIM_REP, new->enode_mac, in fcoe_ctlr_vn_claim_notify()
2610 min((u32)new->fcoe_len, in fcoe_ctlr_vn_claim_notify()
2617 new->rdata.ids.port_id); in fcoe_ctlr_vn_claim_notify()
2623 * fcoe_ctlr_vn_claim_resp() - handle received Claim Response
2624 * @fip: The FCoE controller that received the frame
2625 * @new: newly-parsed FCoE rport from the Claim Response
2632 LIBFCOE_FIP_DBG(fip, "claim resp from from rport %x - state %s\n", in fcoe_ctlr_vn_claim_resp()
2633 new->rdata.ids.port_id, fcoe_ctlr_state(fip->state)); in fcoe_ctlr_vn_claim_resp()
2634 if (fip->state == FIP_ST_VNMP_UP || fip->state == FIP_ST_VNMP_CLAIM) in fcoe_ctlr_vn_claim_resp()
2639 * fcoe_ctlr_vn_beacon() - handle received beacon.
2640 * @fip: The FCoE controller that received the frame
2641 * @new: newly-parsed FCoE rport from the Beacon
2648 struct fc_lport *lport = fip->lp; in fcoe_ctlr_vn_beacon()
2652 if (new->flags & FIP_FL_REC_OR_P2P) { in fcoe_ctlr_vn_beacon()
2657 rdata = fc_rport_lookup(lport, new->rdata.ids.port_id); in fcoe_ctlr_vn_beacon()
2659 if (rdata->ids.node_name == new->rdata.ids.node_name && in fcoe_ctlr_vn_beacon()
2660 rdata->ids.port_name == new->rdata.ids.port_name) { in fcoe_ctlr_vn_beacon()
2664 rdata->ids.port_id); in fcoe_ctlr_vn_beacon()
2665 if (!frport->time && fip->state == FIP_ST_VNMP_UP) { in fcoe_ctlr_vn_beacon()
2668 rdata->ids.port_id); in fcoe_ctlr_vn_beacon()
2671 frport->time = jiffies; in fcoe_ctlr_vn_beacon()
2673 kref_put(&rdata->kref, fc_rport_destroy); in fcoe_ctlr_vn_beacon()
2676 if (fip->state != FIP_ST_VNMP_UP) in fcoe_ctlr_vn_beacon()
2685 new->rdata.ids.port_id); in fcoe_ctlr_vn_beacon()
2687 fip->sol_time + msecs_to_jiffies(FIP_VN_ANN_WAIT))) in fcoe_ctlr_vn_beacon()
2692 * fcoe_ctlr_vn_age() - Check for VN_ports without recent beacons
2697 * Returns the soonest time for next age-out or a time far in the future.
2701 struct fc_lport *lport = fip->lp; in fcoe_ctlr_vn_age()
2708 mutex_lock(&lport->disc.disc_mutex); in fcoe_ctlr_vn_age()
2709 list_for_each_entry_rcu(rdata, &lport->disc.rports, peers) { in fcoe_ctlr_vn_age()
2710 if (!kref_get_unless_zero(&rdata->kref)) in fcoe_ctlr_vn_age()
2713 if (!frport->time) { in fcoe_ctlr_vn_age()
2714 kref_put(&rdata->kref, fc_rport_destroy); in fcoe_ctlr_vn_age()
2717 deadline = frport->time + in fcoe_ctlr_vn_age()
2720 frport->time = 0; in fcoe_ctlr_vn_age()
2723 rdata->ids.port_name, rdata->ids.port_id); in fcoe_ctlr_vn_age()
2727 kref_put(&rdata->kref, fc_rport_destroy); in fcoe_ctlr_vn_age()
2729 mutex_unlock(&lport->disc.disc_mutex); in fcoe_ctlr_vn_age()
2734 * fcoe_ctlr_vn_recv() - Receive a FIP frame
2735 * @fip: The FCoE controller that received the frame
2736 * @skb: The received FIP frame
2738 * Returns non-zero if the frame is dropped.
2739 * Always consumes the frame.
2744 enum fip_vn2vn_subcode sub; in fcoe_ctlr_vn_recv() local
2748 fiph = (struct fip_header *)skb->data; in fcoe_ctlr_vn_recv()
2749 sub = fiph->fip_subcode; in fcoe_ctlr_vn_recv()
2751 if (fip->lp->vlan) in fcoe_ctlr_vn_recv()
2754 if (vlan_id && vlan_id != fip->lp->vlan) { in fcoe_ctlr_vn_recv()
2755 LIBFCOE_FIP_DBG(fip, "vn_recv drop frame sub %x vlan %d\n", in fcoe_ctlr_vn_recv()
2756 sub, vlan_id); in fcoe_ctlr_vn_recv()
2757 rc = -EAGAIN; in fcoe_ctlr_vn_recv()
2767 mutex_lock(&fip->ctlr_mutex); in fcoe_ctlr_vn_recv()
2768 switch (sub) { in fcoe_ctlr_vn_recv()
2785 LIBFCOE_FIP_DBG(fip, "vn_recv unknown subcode %d\n", sub); in fcoe_ctlr_vn_recv()
2786 rc = -1; in fcoe_ctlr_vn_recv()
2789 mutex_unlock(&fip->ctlr_mutex); in fcoe_ctlr_vn_recv()
2796 * fcoe_ctlr_vlan_parse - parse vlan discovery request or response
2801 * Returns non-zero error number on error.
2816 u8 sub; in fcoe_ctlr_vlan_parse() local
2818 fiph = (struct fip_header *)skb->data; in fcoe_ctlr_vlan_parse()
2819 frport->flags = ntohs(fiph->fip_flags); in fcoe_ctlr_vlan_parse()
2821 sub = fiph->fip_subcode; in fcoe_ctlr_vlan_parse()
2822 switch (sub) { in fcoe_ctlr_vlan_parse()
2827 LIBFCOE_FIP_DBG(fip, "vn_parse unknown subcode %u\n", sub); in fcoe_ctlr_vlan_parse()
2828 return -EINVAL; in fcoe_ctlr_vlan_parse()
2831 rlen = ntohs(fiph->fip_dl_len) * 4; in fcoe_ctlr_vlan_parse()
2832 if (rlen + sizeof(*fiph) > skb->len) in fcoe_ctlr_vlan_parse()
2833 return -EINVAL; in fcoe_ctlr_vlan_parse()
2837 dlen = desc->fip_dlen * FIP_BPW; in fcoe_ctlr_vlan_parse()
2839 return -EINVAL; in fcoe_ctlr_vlan_parse()
2841 dtype = desc->fip_dtype; in fcoe_ctlr_vlan_parse()
2848 dtype, sub); in fcoe_ctlr_vlan_parse()
2849 return -EINVAL; in fcoe_ctlr_vlan_parse()
2859 if (!is_valid_ether_addr(macd->fd_mac)) { in fcoe_ctlr_vlan_parse()
2862 macd->fd_mac); in fcoe_ctlr_vlan_parse()
2863 return -EINVAL; in fcoe_ctlr_vlan_parse()
2865 memcpy(frport->enode_mac, macd->fd_mac, ETH_ALEN); in fcoe_ctlr_vlan_parse()
2871 frport->rdata.ids.node_name = in fcoe_ctlr_vlan_parse()
2872 get_unaligned_be64(&wwn->fd_wwn); in fcoe_ctlr_vlan_parse()
2879 return -EINVAL; in fcoe_ctlr_vlan_parse()
2883 rlen -= dlen; in fcoe_ctlr_vlan_parse()
2890 return -EINVAL; in fcoe_ctlr_vlan_parse()
2894 * fcoe_ctlr_vlan_send() - Send a FIP VLAN Notification
2896 * @sub: sub-opcode for vlan notification or vn2vn vlan notification
2900 enum fip_vlan_subcode sub, in fcoe_ctlr_vlan_send() argument
2909 } __packed * frame; in fcoe_ctlr_vlan_send() local
2913 len = sizeof(*frame); in fcoe_ctlr_vlan_send()
2914 dlen = sizeof(frame->mac) + sizeof(frame->vlan); in fcoe_ctlr_vlan_send()
2922 fip->mode == FIP_MODE_VN2VN ? "vn2vn" : "fcf", in fcoe_ctlr_vlan_send()
2923 fip->lp->vlan); in fcoe_ctlr_vlan_send()
2925 frame = (struct fip_vlan_notify_frame *)skb->data; in fcoe_ctlr_vlan_send()
2926 memset(frame, 0, len); in fcoe_ctlr_vlan_send()
2927 memcpy(frame->eth.h_dest, dest, ETH_ALEN); in fcoe_ctlr_vlan_send()
2929 memcpy(frame->eth.h_source, fip->ctl_src_addr, ETH_ALEN); in fcoe_ctlr_vlan_send()
2930 frame->eth.h_proto = htons(ETH_P_FIP); in fcoe_ctlr_vlan_send()
2932 frame->fip.fip_ver = FIP_VER_ENCAPS(FIP_VER); in fcoe_ctlr_vlan_send()
2933 frame->fip.fip_op = htons(FIP_OP_VLAN); in fcoe_ctlr_vlan_send()
2934 frame->fip.fip_subcode = sub; in fcoe_ctlr_vlan_send()
2935 frame->fip.fip_dl_len = htons(dlen / FIP_BPW); in fcoe_ctlr_vlan_send()
2937 frame->mac.fd_desc.fip_dtype = FIP_DT_MAC; in fcoe_ctlr_vlan_send()
2938 frame->mac.fd_desc.fip_dlen = sizeof(frame->mac) / FIP_BPW; in fcoe_ctlr_vlan_send()
2939 memcpy(frame->mac.fd_mac, fip->ctl_src_addr, ETH_ALEN); in fcoe_ctlr_vlan_send()
2941 frame->vlan.fd_desc.fip_dtype = FIP_DT_VLAN; in fcoe_ctlr_vlan_send()
2942 frame->vlan.fd_desc.fip_dlen = sizeof(frame->vlan) / FIP_BPW; in fcoe_ctlr_vlan_send()
2943 put_unaligned_be16(fip->lp->vlan, &frame->vlan.fd_vlan); in fcoe_ctlr_vlan_send()
2946 skb->protocol = htons(ETH_P_FIP); in fcoe_ctlr_vlan_send()
2947 skb->priority = fip->priority; in fcoe_ctlr_vlan_send()
2951 fip->send(fip, skb); in fcoe_ctlr_vlan_send()
2955 * fcoe_ctlr_vlan_disk_reply() - send FIP VLAN Discovery Notification.
2957 * @frport: The newly-parsed FCoE rport from the Discovery Request
2964 enum fip_vlan_subcode sub = FIP_SC_VL_NOTE; in fcoe_ctlr_vlan_disc_reply() local
2966 if (fip->mode == FIP_MODE_VN2VN) in fcoe_ctlr_vlan_disc_reply()
2967 sub = FIP_SC_VL_VN2VN_NOTE; in fcoe_ctlr_vlan_disc_reply()
2969 fcoe_ctlr_vlan_send(fip, sub, frport->enode_mac); in fcoe_ctlr_vlan_disc_reply()
2973 * fcoe_ctlr_vlan_recv - vlan request receive handler for VN2VN mode.
2980 enum fip_vlan_subcode sub; in fcoe_ctlr_vlan_recv() local
2984 fiph = (struct fip_header *)skb->data; in fcoe_ctlr_vlan_recv()
2985 sub = fiph->fip_subcode; in fcoe_ctlr_vlan_recv()
2991 mutex_lock(&fip->ctlr_mutex); in fcoe_ctlr_vlan_recv()
2992 if (sub == FIP_SC_VL_REQ) in fcoe_ctlr_vlan_recv()
2994 mutex_unlock(&fip->ctlr_mutex); in fcoe_ctlr_vlan_recv()
3002 * fcoe_ctlr_disc_recv - discovery receive handler for VN2VN mode.
3004 * @fp: The received frame
3007 * fabric-generated ELSes.
3020 * fcoe_ctlr_disc_start - start discovery for VN2VN mode.
3034 struct fc_disc *disc = &lport->disc; in fcoe_ctlr_disc_start()
3035 struct fcoe_ctlr *fip = disc->priv; in fcoe_ctlr_disc_start()
3037 mutex_lock(&disc->disc_mutex); in fcoe_ctlr_disc_start()
3038 disc->disc_callback = callback; in fcoe_ctlr_disc_start()
3039 disc->disc_id = (disc->disc_id + 2) | 1; in fcoe_ctlr_disc_start()
3040 disc->pending = 1; in fcoe_ctlr_disc_start()
3041 schedule_work(&fip->timer_work); in fcoe_ctlr_disc_start()
3042 mutex_unlock(&disc->disc_mutex); in fcoe_ctlr_disc_start()
3046 * fcoe_ctlr_vn_disc() - report FIP VN_port discovery results after claim state.
3055 struct fc_lport *lport = fip->lp; in fcoe_ctlr_vn_disc()
3056 struct fc_disc *disc = &lport->disc; in fcoe_ctlr_vn_disc()
3061 mutex_lock(&disc->disc_mutex); in fcoe_ctlr_vn_disc()
3062 callback = disc->pending ? disc->disc_callback : NULL; in fcoe_ctlr_vn_disc()
3063 disc->pending = 0; in fcoe_ctlr_vn_disc()
3064 list_for_each_entry_rcu(rdata, &disc->rports, peers) { in fcoe_ctlr_vn_disc()
3065 if (!kref_get_unless_zero(&rdata->kref)) in fcoe_ctlr_vn_disc()
3068 if (frport->time) in fcoe_ctlr_vn_disc()
3070 kref_put(&rdata->kref, fc_rport_destroy); in fcoe_ctlr_vn_disc()
3072 mutex_unlock(&disc->disc_mutex); in fcoe_ctlr_vn_disc()
3078 * fcoe_ctlr_vn_timeout - timer work function for VN2VN mode.
3087 mutex_lock(&fip->ctlr_mutex); in fcoe_ctlr_vn_timeout()
3088 switch (fip->state) { in fcoe_ctlr_vn_timeout()
3103 new_port_id = fip->port_id; in fcoe_ctlr_vn_timeout()
3107 fip->update_mac(fip->lp, mac); in fcoe_ctlr_vn_timeout()
3117 next_time = fip->sol_time + msecs_to_jiffies(FIP_VN_ANN_WAIT); in fcoe_ctlr_vn_timeout()
3124 fip->port_ka_time = next_time; in fcoe_ctlr_vn_timeout()
3130 if (time_after_eq(jiffies, fip->port_ka_time)) { in fcoe_ctlr_vn_timeout()
3134 fip->port_ka_time = jiffies + in fcoe_ctlr_vn_timeout()
3138 if (time_before(fip->port_ka_time, next_time)) in fcoe_ctlr_vn_timeout()
3139 next_time = fip->port_ka_time; in fcoe_ctlr_vn_timeout()
3144 WARN(1, "unexpected state %d\n", fip->state); in fcoe_ctlr_vn_timeout()
3147 mod_timer(&fip->timer, next_time); in fcoe_ctlr_vn_timeout()
3149 mutex_unlock(&fip->ctlr_mutex); in fcoe_ctlr_vn_timeout()
3153 fc_lport_set_local_id(fip->lp, new_port_id); in fcoe_ctlr_vn_timeout()
3157 * fcoe_ctlr_mode_set() - Set or reset the ctlr's mode
3173 WARN_ON(lport->state != LPORT_ST_RESET && in fcoe_ctlr_mode_set()
3174 lport->state != LPORT_ST_DISABLED); in fcoe_ctlr_mode_set()
3177 lport->rport_priv_size = sizeof(struct fcoe_rport); in fcoe_ctlr_mode_set()
3178 lport->point_to_multipoint = 1; in fcoe_ctlr_mode_set()
3179 lport->tt.disc_recv_req = fcoe_ctlr_disc_recv; in fcoe_ctlr_mode_set()
3180 lport->tt.disc_start = fcoe_ctlr_disc_start; in fcoe_ctlr_mode_set()
3181 lport->tt.disc_stop = fcoe_ctlr_disc_stop; in fcoe_ctlr_mode_set()
3182 lport->tt.disc_stop_final = fcoe_ctlr_disc_stop_final; in fcoe_ctlr_mode_set()
3185 lport->rport_priv_size = 0; in fcoe_ctlr_mode_set()
3186 lport->point_to_multipoint = 0; in fcoe_ctlr_mode_set()
3187 lport->tt.disc_recv_req = NULL; in fcoe_ctlr_mode_set()
3188 lport->tt.disc_start = NULL; in fcoe_ctlr_mode_set()
3189 lport->tt.disc_stop = NULL; in fcoe_ctlr_mode_set()
3190 lport->tt.disc_stop_final = NULL; in fcoe_ctlr_mode_set()
3198 * fcoe_libfc_config() - Sets up libfc related properties for local port
3202 * @init_fcp: If non-zero, the FCP portion of libfc should be initialized
3210 memcpy(&lport->tt, tt, sizeof(*tt)); in fcoe_libfc_config()
3212 return -ENOMEM; in fcoe_libfc_config()
3217 fcoe_ctlr_mode_set(lport, fip, fip->mode); in fcoe_libfc_config()
3228 mutex_lock(&fip->ctlr_mutex); in fcoe_fcf_get_selected()
3229 mutex_lock(&ctlr_dev->lock); in fcoe_fcf_get_selected()
3233 fcf_dev->selected = (fcf == fip->sel_fcf) ? 1 : 0; in fcoe_fcf_get_selected()
3235 fcf_dev->selected = 0; in fcoe_fcf_get_selected()
3237 mutex_unlock(&ctlr_dev->lock); in fcoe_fcf_get_selected()
3238 mutex_unlock(&fip->ctlr_mutex); in fcoe_fcf_get_selected()
3245 struct fc_lport *lport = ctlr->lp; in fcoe_ctlr_set_fip_mode()
3247 mutex_lock(&ctlr->ctlr_mutex); in fcoe_ctlr_set_fip_mode()
3248 switch (ctlr_dev->mode) { in fcoe_ctlr_set_fip_mode()
3250 ctlr->mode = FIP_MODE_VN2VN; in fcoe_ctlr_set_fip_mode()
3254 ctlr->mode = FIP_MODE_FABRIC; in fcoe_ctlr_set_fip_mode()
3258 mutex_unlock(&ctlr->ctlr_mutex); in fcoe_ctlr_set_fip_mode()
3260 fcoe_ctlr_mode_set(lport, ctlr, ctlr->mode); in fcoe_ctlr_set_fip_mode()