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).
830 list_for_each_entry_safe(fcf, next, &fip->fcfs, list) { in fcoe_ctlr_age_fcfs()
831 deadline = fcf->time + fcf->fka_period + fcf->fka_period / 2; in fcoe_ctlr_age_fcfs()
832 if (fip->sel_fcf == fcf) { in fcoe_ctlr_age_fcfs()
836 miss_cnt = this_cpu_inc_return(fip->lp->stats->MissDiscAdvCount); in fcoe_ctlr_age_fcfs()
840 fip->lp->host->host_no, fcf->fabric_name, in fcoe_ctlr_age_fcfs()
846 deadline += fcf->fka_period; in fcoe_ctlr_age_fcfs()
848 if (fip->sel_fcf == fcf) in fcoe_ctlr_age_fcfs()
849 fip->sel_fcf = NULL; in fcoe_ctlr_age_fcfs()
855 list_del(&fcf->list); in fcoe_ctlr_age_fcfs()
856 list_add(&fcf->list, &del_list); in fcoe_ctlr_age_fcfs()
857 this_cpu_inc(fip->lp->stats->VLinkFailureCount); in fcoe_ctlr_age_fcfs()
862 (!sel_time || time_before(sel_time, fcf->time))) in fcoe_ctlr_age_fcfs()
863 sel_time = fcf->time; in fcoe_ctlr_age_fcfs()
872 if (sel_time && !fip->sel_fcf && !fip->sel_time) { in fcoe_ctlr_age_fcfs()
874 fip->sel_time = sel_time; in fcoe_ctlr_age_fcfs()
881 * fcoe_ctlr_parse_adv() - Decode a FIP advertisement into a new FCF entry
883 * @skb: The received FIP advertisement frame
903 fcf->fka_period = msecs_to_jiffies(FCOE_CTLR_DEF_FKA); in fcoe_ctlr_parse_adv()
905 fiph = (struct fip_header *)skb->data; in fcoe_ctlr_parse_adv()
906 fcf->flags = ntohs(fiph->fip_flags); in fcoe_ctlr_parse_adv()
914 rlen = ntohs(fiph->fip_dl_len) * 4; in fcoe_ctlr_parse_adv()
915 if (rlen + sizeof(*fiph) > skb->len) in fcoe_ctlr_parse_adv()
916 return -EINVAL; in fcoe_ctlr_parse_adv()
920 dlen = desc->fip_dlen * FIP_BPW; in fcoe_ctlr_parse_adv()
922 return -EINVAL; in fcoe_ctlr_parse_adv()
924 if ((desc->fip_dtype < 32) && in fcoe_ctlr_parse_adv()
925 !(desc_mask & 1U << desc->fip_dtype)) { in fcoe_ctlr_parse_adv()
928 return -EINVAL; in fcoe_ctlr_parse_adv()
930 switch (desc->fip_dtype) { in fcoe_ctlr_parse_adv()
934 fcf->pri = ((struct fip_pri_desc *)desc)->fd_pri; in fcoe_ctlr_parse_adv()
940 memcpy(fcf->fcf_mac, in fcoe_ctlr_parse_adv()
941 ((struct fip_mac_desc *)desc)->fd_mac, in fcoe_ctlr_parse_adv()
943 memcpy(fcf->fcoe_mac, fcf->fcf_mac, ETH_ALEN); in fcoe_ctlr_parse_adv()
944 if (!is_valid_ether_addr(fcf->fcf_mac)) { in fcoe_ctlr_parse_adv()
947 fcf->fcf_mac); in fcoe_ctlr_parse_adv()
948 return -EINVAL; in fcoe_ctlr_parse_adv()
956 fcf->switch_name = get_unaligned_be64(&wwn->fd_wwn); in fcoe_ctlr_parse_adv()
963 fcf->fabric_name = get_unaligned_be64(&fab->fd_wwn); in fcoe_ctlr_parse_adv()
964 fcf->vfid = ntohs(fab->fd_vfid); in fcoe_ctlr_parse_adv()
965 fcf->fc_map = ntoh24(fab->fd_map); in fcoe_ctlr_parse_adv()
972 if (fka->fd_flags & FIP_FKA_ADV_D) in fcoe_ctlr_parse_adv()
973 fcf->fd_flags = 1; in fcoe_ctlr_parse_adv()
974 t = ntohl(fka->fd_fka_period); in fcoe_ctlr_parse_adv()
976 fcf->fka_period = msecs_to_jiffies(t); in fcoe_ctlr_parse_adv()
987 "in FIP adv\n", desc->fip_dtype); in fcoe_ctlr_parse_adv()
989 if (desc->fip_dtype < FIP_DT_NON_CRITICAL) in fcoe_ctlr_parse_adv()
990 return -EINVAL; in fcoe_ctlr_parse_adv()
994 rlen -= dlen; in fcoe_ctlr_parse_adv()
996 if (!fcf->fc_map || (fcf->fc_map & 0x10000)) in fcoe_ctlr_parse_adv()
997 return -EINVAL; in fcoe_ctlr_parse_adv()
998 if (!fcf->switch_name) in fcoe_ctlr_parse_adv()
999 return -EINVAL; in fcoe_ctlr_parse_adv()
1003 return -EINVAL; in fcoe_ctlr_parse_adv()
1009 desc->fip_dtype, dlen); in fcoe_ctlr_parse_adv()
1010 return -EINVAL; in fcoe_ctlr_parse_adv()
1014 * fcoe_ctlr_recv_adv() - Handle an incoming advertisement
1031 mutex_lock(&fip->ctlr_mutex); in fcoe_ctlr_recv_adv()
1032 first = list_empty(&fip->fcfs); in fcoe_ctlr_recv_adv()
1033 list_for_each_entry(fcf, &fip->fcfs, list) { in fcoe_ctlr_recv_adv()
1034 if (fcf->switch_name == new.switch_name && in fcoe_ctlr_recv_adv()
1035 fcf->fabric_name == new.fabric_name && in fcoe_ctlr_recv_adv()
1036 fcf->fc_map == new.fc_map && in fcoe_ctlr_recv_adv()
1037 ether_addr_equal(fcf->fcf_mac, new.fcf_mac)) { in fcoe_ctlr_recv_adv()
1043 if (fip->fcf_count >= FCOE_CTLR_FCF_LIMIT) in fcoe_ctlr_recv_adv()
1051 fcf->fip = fip; in fcoe_ctlr_recv_adv()
1062 * Update the FCF's keep-alive descriptor flags. in fcoe_ctlr_recv_adv()
1067 fcf->fd_flags = new.fd_flags; in fcoe_ctlr_recv_adv()
1069 fcf->flags = new.flags; in fcoe_ctlr_recv_adv()
1071 if (fcf == fip->sel_fcf && !fcf->fd_flags) { in fcoe_ctlr_recv_adv()
1072 fip->ctlr_ka_time -= fcf->fka_period; in fcoe_ctlr_recv_adv()
1073 fip->ctlr_ka_time += new.fka_period; in fcoe_ctlr_recv_adv()
1074 if (time_before(fip->ctlr_ka_time, fip->timer.expires)) in fcoe_ctlr_recv_adv()
1075 mod_timer(&fip->timer, fip->ctlr_ka_time); in fcoe_ctlr_recv_adv()
1077 fcf->fka_period = new.fka_period; in fcoe_ctlr_recv_adv()
1078 memcpy(fcf->fcf_mac, new.fcf_mac, ETH_ALEN); in fcoe_ctlr_recv_adv()
1082 fcf->time = jiffies; in fcoe_ctlr_recv_adv()
1085 fcf->fabric_name, fcf->fcf_mac); in fcoe_ctlr_recv_adv()
1100 if (first && time_after(jiffies, fip->sol_time + sol_tov)) in fcoe_ctlr_recv_adv()
1110 list_move(&fcf->list, &fip->fcfs); in fcoe_ctlr_recv_adv()
1116 if (mtu_valid && !fip->sel_fcf && !fip->sel_time && in fcoe_ctlr_recv_adv()
1118 fip->sel_time = jiffies + in fcoe_ctlr_recv_adv()
1120 if (!timer_pending(&fip->timer) || in fcoe_ctlr_recv_adv()
1121 time_before(fip->sel_time, fip->timer.expires)) in fcoe_ctlr_recv_adv()
1122 mod_timer(&fip->timer, fip->sel_time); in fcoe_ctlr_recv_adv()
1126 mutex_unlock(&fip->ctlr_mutex); in fcoe_ctlr_recv_adv()
1130 * fcoe_ctlr_recv_els() - Handle an incoming FIP encapsulated ELS frame
1136 struct fc_lport *lport = fip->lp; in fcoe_ctlr_recv_els()
1145 u8 sub; in fcoe_ctlr_recv_els() local
1153 fiph = (struct fip_header *)skb->data; in fcoe_ctlr_recv_els()
1154 sub = fiph->fip_subcode; in fcoe_ctlr_recv_els()
1155 if (sub != FIP_SC_REQ && sub != FIP_SC_REP) in fcoe_ctlr_recv_els()
1158 rlen = ntohs(fiph->fip_dl_len) * 4; in fcoe_ctlr_recv_els()
1159 if (rlen + sizeof(*fiph) > skb->len) in fcoe_ctlr_recv_els()
1165 dlen = desc->fip_dlen * FIP_BPW; in fcoe_ctlr_recv_els()
1169 if (desc->fip_dtype < 32) { in fcoe_ctlr_recv_els()
1170 if ((desc->fip_dtype != FIP_DT_MAC) && in fcoe_ctlr_recv_els()
1171 (desc_mask & 1U << desc->fip_dtype)) { in fcoe_ctlr_recv_els()
1176 desc_mask |= (1 << desc->fip_dtype); in fcoe_ctlr_recv_els()
1178 switch (desc->fip_dtype) { in fcoe_ctlr_recv_els()
1180 sel = fip->sel_fcf; in fcoe_ctlr_recv_els()
1196 ((struct fip_mac_desc *)desc)->fd_mac, in fcoe_ctlr_recv_els()
1203 memcpy(sel->fcoe_mac, in fcoe_ctlr_recv_els()
1204 ((struct fip_mac_desc *)desc)->fd_mac, in fcoe_ctlr_recv_els()
1220 els_len = dlen - sizeof(*els); in fcoe_ctlr_recv_els()
1223 els_dtype = desc->fip_dtype; in fcoe_ctlr_recv_els()
1227 "in FIP adv\n", desc->fip_dtype); in fcoe_ctlr_recv_els()
1229 if (desc->fip_dtype < FIP_DT_NON_CRITICAL) in fcoe_ctlr_recv_els()
1239 rlen -= dlen; in fcoe_ctlr_recv_els()
1247 sub == FIP_SC_REP && fip->mode != FIP_MODE_VN2VN) { in fcoe_ctlr_recv_els()
1255 memcpy(fr_cb(fp)->granted_mac, granted_mac, ETH_ALEN); in fcoe_ctlr_recv_els()
1257 if (fip->flogi_oxid == ntohs(fh->fh_ox_id)) { in fcoe_ctlr_recv_els()
1258 fip->flogi_oxid = FC_XID_UNKNOWN; in fcoe_ctlr_recv_els()
1277 skb_pull(skb, (u8 *)fh - skb->data); in fcoe_ctlr_recv_els()
1286 this_cpu_inc(lport->stats->RxFrames); in fcoe_ctlr_recv_els()
1287 this_cpu_add(lport->stats->RxWords, skb->len / FIP_BPW); in fcoe_ctlr_recv_els()
1294 desc->fip_dtype, dlen); in fcoe_ctlr_recv_els()
1300 * fcoe_ctlr_recv_clr_vlink() - Handle an incoming link reset frame
1301 * @fip: The FCoE controller that received the frame
1316 struct fcoe_fcf *fcf = fip->sel_fcf; in fcoe_ctlr_recv_clr_vlink()
1317 struct fc_lport *lport = fip->lp; in fcoe_ctlr_recv_clr_vlink()
1323 struct fip_header *fh = (struct fip_header *)skb->data; in fcoe_ctlr_recv_clr_vlink()
1335 mutex_lock(&fip->ctlr_mutex); in fcoe_ctlr_recv_clr_vlink()
1337 mutex_unlock(&fip->ctlr_mutex); in fcoe_ctlr_recv_clr_vlink()
1346 if (!ether_addr_equal(eh->h_source, fcf->fcf_mac)) { in fcoe_ctlr_recv_clr_vlink()
1348 "mismatch with FCF src=%pM\n", eh->h_source); in fcoe_ctlr_recv_clr_vlink()
1356 if (!lport->port_id) { in fcoe_ctlr_recv_clr_vlink()
1358 mutex_lock(&fip->ctlr_mutex); in fcoe_ctlr_recv_clr_vlink()
1360 mutex_unlock(&fip->ctlr_mutex); in fcoe_ctlr_recv_clr_vlink()
1361 fc_lport_reset(fip->lp); in fcoe_ctlr_recv_clr_vlink()
1371 rlen = ntohs(fh->fip_dl_len) * FIP_BPW; in fcoe_ctlr_recv_clr_vlink()
1375 * Actually need to subtract 'sizeof(*mp) - sizeof(*wp)' from 'rlen' in fcoe_ctlr_recv_clr_vlink()
1388 dlen = desc->fip_dlen * FIP_BPW; in fcoe_ctlr_recv_clr_vlink()
1392 if ((desc->fip_dtype < 32) && in fcoe_ctlr_recv_clr_vlink()
1393 (desc->fip_dtype != FIP_DT_VN_ID) && in fcoe_ctlr_recv_clr_vlink()
1394 !(desc_mask & 1U << desc->fip_dtype)) { in fcoe_ctlr_recv_clr_vlink()
1399 switch (desc->fip_dtype) { in fcoe_ctlr_recv_clr_vlink()
1404 if (!ether_addr_equal(mp->fd_mac, fcf->fcf_mac)) in fcoe_ctlr_recv_clr_vlink()
1412 if (get_unaligned_be64(&wp->fd_wwn) != fcf->switch_name) in fcoe_ctlr_recv_clr_vlink()
1422 ntoh24(vp->fd_fc_id)); in fcoe_ctlr_recv_clr_vlink()
1424 mutex_lock(&fip->ctlr_mutex); in fcoe_ctlr_recv_clr_vlink()
1425 this_cpu_inc(lport->stats->VLinkFailureCount); in fcoe_ctlr_recv_clr_vlink()
1427 mutex_unlock(&fip->ctlr_mutex); in fcoe_ctlr_recv_clr_vlink()
1432 if (desc->fip_dtype < FIP_DT_NON_CRITICAL) in fcoe_ctlr_recv_clr_vlink()
1437 rlen -= dlen; in fcoe_ctlr_recv_clr_vlink()
1452 mutex_lock(&fip->ctlr_mutex); in fcoe_ctlr_recv_clr_vlink()
1453 this_cpu_inc(lport->stats->VLinkFailureCount); in fcoe_ctlr_recv_clr_vlink()
1455 mutex_unlock(&fip->ctlr_mutex); in fcoe_ctlr_recv_clr_vlink()
1457 mutex_lock(&lport->lp_mutex); in fcoe_ctlr_recv_clr_vlink()
1458 list_for_each_entry(vn_port, &lport->vports, list) in fcoe_ctlr_recv_clr_vlink()
1460 mutex_unlock(&lport->lp_mutex); in fcoe_ctlr_recv_clr_vlink()
1462 fc_lport_reset(fip->lp); in fcoe_ctlr_recv_clr_vlink()
1471 ntoh24(vp->fd_fc_id)); in fcoe_ctlr_recv_clr_vlink()
1479 if (!ether_addr_equal(fip->get_src_addr(vn_port), in fcoe_ctlr_recv_clr_vlink()
1480 vp->fd_mac) || in fcoe_ctlr_recv_clr_vlink()
1481 get_unaligned_be64(&vp->fd_wwpn) != in fcoe_ctlr_recv_clr_vlink()
1482 vn_port->wwpn) in fcoe_ctlr_recv_clr_vlink()
1496 fc_lport_reset(fip->lp); in fcoe_ctlr_recv_clr_vlink()
1506 * fcoe_ctlr_recv() - Receive a FIP packet
1517 skb_queue_tail(&fip->fip_recv_list, skb); in fcoe_ctlr_recv()
1518 schedule_work(&fip->recv_work); in fcoe_ctlr_recv()
1523 * fcoe_ctlr_recv_handler() - Receive a FIP frame
1524 * @fip: The FCoE controller that received the frame
1525 * @skb: The received FIP frame
1527 * Returns non-zero if the frame is dropped.
1536 u8 sub; in fcoe_ctlr_recv_handler() local
1540 if (skb->len < sizeof(*fiph)) in fcoe_ctlr_recv_handler()
1543 if (fip->mode == FIP_MODE_VN2VN) { in fcoe_ctlr_recv_handler()
1544 if (!ether_addr_equal(eh->h_dest, fip->ctl_src_addr) && in fcoe_ctlr_recv_handler()
1545 !ether_addr_equal(eh->h_dest, fcoe_all_vn2vn) && in fcoe_ctlr_recv_handler()
1546 !ether_addr_equal(eh->h_dest, fcoe_all_p2p)) in fcoe_ctlr_recv_handler()
1548 } else if (!ether_addr_equal(eh->h_dest, fip->ctl_src_addr) && in fcoe_ctlr_recv_handler()
1549 !ether_addr_equal(eh->h_dest, fcoe_all_enode)) in fcoe_ctlr_recv_handler()
1551 fiph = (struct fip_header *)skb->data; in fcoe_ctlr_recv_handler()
1552 op = ntohs(fiph->fip_op); in fcoe_ctlr_recv_handler()
1553 sub = fiph->fip_subcode; in fcoe_ctlr_recv_handler()
1555 if (FIP_VER_DECAPS(fiph->fip_ver) != FIP_VER) in fcoe_ctlr_recv_handler()
1557 if (ntohs(fiph->fip_dl_len) * FIP_BPW + sizeof(*fiph) > skb->len) in fcoe_ctlr_recv_handler()
1560 mutex_lock(&fip->ctlr_mutex); in fcoe_ctlr_recv_handler()
1561 state = fip->state; in fcoe_ctlr_recv_handler()
1563 fip->map_dest = 0; in fcoe_ctlr_recv_handler()
1568 fip_vlan_resp = fip->fip_resp; in fcoe_ctlr_recv_handler()
1569 mutex_unlock(&fip->ctlr_mutex); in fcoe_ctlr_recv_handler()
1571 if (fip->mode == FIP_MODE_VN2VN && op == FIP_OP_VN2VN) in fcoe_ctlr_recv_handler()
1591 if (op == FIP_OP_DISC && sub == FIP_SC_ADV) in fcoe_ctlr_recv_handler()
1593 else if (op == FIP_OP_CTRL && sub == FIP_SC_CLR_VLINK) in fcoe_ctlr_recv_handler()
1599 return -1; in fcoe_ctlr_recv_handler()
1603 * fcoe_ctlr_select() - Select the best FCF (if possible)
1618 struct fcoe_fcf *best = fip->sel_fcf; in fcoe_ctlr_select()
1620 list_for_each_entry(fcf, &fip->fcfs, list) { in fcoe_ctlr_select()
1624 fcf->fabric_name, fcf->vfid, fcf->fcf_mac, in fcoe_ctlr_select()
1625 fcf->fc_map, fcoe_ctlr_mtu_valid(fcf), in fcoe_ctlr_select()
1626 fcf->flogi_sent, fcf->pri); in fcoe_ctlr_select()
1630 fcf->fabric_name, fcf->fc_map, in fcoe_ctlr_select()
1631 (fcf->flags & FIP_FL_SOL) ? "" : "in", in fcoe_ctlr_select()
1632 (fcf->flags & FIP_FL_AVAIL) ? in fcoe_ctlr_select()
1636 if (!best || fcf->pri < best->pri || best->flogi_sent) in fcoe_ctlr_select()
1638 if (fcf->fabric_name != best->fabric_name || in fcoe_ctlr_select()
1639 fcf->vfid != best->vfid || in fcoe_ctlr_select()
1640 fcf->fc_map != best->fc_map) { in fcoe_ctlr_select()
1642 "or FC-MAP\n"); in fcoe_ctlr_select()
1646 fip->sel_fcf = best; in fcoe_ctlr_select()
1648 LIBFCOE_FIP_DBG(fip, "using FCF mac %pM\n", best->fcf_mac); in fcoe_ctlr_select()
1649 fip->port_ka_time = jiffies + in fcoe_ctlr_select()
1651 fip->ctlr_ka_time = jiffies + best->fka_period; in fcoe_ctlr_select()
1652 if (time_before(fip->ctlr_ka_time, fip->timer.expires)) in fcoe_ctlr_select()
1653 mod_timer(&fip->timer, fip->ctlr_ka_time); in fcoe_ctlr_select()
1659 * fcoe_ctlr_flogi_send_locked() - send FIP-encapsulated FLOGI to current FCF
1662 * Returns non-zero error if it could not be sent.
1665 * Caller must verify that fip->sel_fcf is not NULL.
1674 skb_orig = fip->flogi_req; in fcoe_ctlr_flogi_send_locked()
1676 return -EINVAL; in fcoe_ctlr_flogi_send_locked()
1684 fip->flogi_req = NULL; in fcoe_ctlr_flogi_send_locked()
1686 fh = (struct fc_frame_header *)skb->data; in fcoe_ctlr_flogi_send_locked()
1687 error = fcoe_ctlr_encaps(fip, fip->lp, FIP_DT_FLOGI, skb, in fcoe_ctlr_flogi_send_locked()
1688 ntoh24(fh->fh_d_id)); in fcoe_ctlr_flogi_send_locked()
1693 fip->send(fip, skb); in fcoe_ctlr_flogi_send_locked()
1694 fip->sel_fcf->flogi_sent = 1; in fcoe_ctlr_flogi_send_locked()
1699 * fcoe_ctlr_flogi_retry() - resend FLOGI request to a new FCF if possible
1702 * Returns non-zero error code if there's no FLOGI request to retry or
1710 mutex_lock(&fip->ctlr_mutex); in fcoe_ctlr_flogi_retry()
1711 spin_lock_bh(&fip->ctlr_lock); in fcoe_ctlr_flogi_retry()
1712 LIBFCOE_FIP_DBG(fip, "re-sending FLOGI - reselect\n"); in fcoe_ctlr_flogi_retry()
1714 if (!fcf || fcf->flogi_sent) { in fcoe_ctlr_flogi_retry()
1715 kfree_skb(fip->flogi_req); in fcoe_ctlr_flogi_retry()
1716 fip->flogi_req = NULL; in fcoe_ctlr_flogi_retry()
1717 error = -ENOENT; in fcoe_ctlr_flogi_retry()
1722 spin_unlock_bh(&fip->ctlr_lock); in fcoe_ctlr_flogi_retry()
1723 mutex_unlock(&fip->ctlr_mutex); in fcoe_ctlr_flogi_retry()
1729 * fcoe_ctlr_flogi_send() - Handle sending of FIP FLOGI.
1740 spin_lock_bh(&fip->ctlr_lock); in fcoe_ctlr_flogi_send()
1741 fcf = fip->sel_fcf; in fcoe_ctlr_flogi_send()
1742 if (!fcf || !fip->flogi_req_send) in fcoe_ctlr_flogi_send()
1751 if (fcf->flogi_sent) { in fcoe_ctlr_flogi_send()
1752 LIBFCOE_FIP_DBG(fip, "sending FLOGI - reselect\n"); in fcoe_ctlr_flogi_send()
1754 if (!fcf || fcf->flogi_sent) { in fcoe_ctlr_flogi_send()
1755 LIBFCOE_FIP_DBG(fip, "sending FLOGI - clearing\n"); in fcoe_ctlr_flogi_send()
1756 list_for_each_entry(fcf, &fip->fcfs, list) in fcoe_ctlr_flogi_send()
1757 fcf->flogi_sent = 0; in fcoe_ctlr_flogi_send()
1763 fip->flogi_req_send = 0; in fcoe_ctlr_flogi_send()
1765 LIBFCOE_FIP_DBG(fip, "No FCF selected - defer send\n"); in fcoe_ctlr_flogi_send()
1767 spin_unlock_bh(&fip->ctlr_lock); in fcoe_ctlr_flogi_send()
1771 * fcoe_ctlr_timeout() - FIP timeout handler
1778 schedule_work(&fip->timer_work); in fcoe_ctlr_timeout()
1782 * fcoe_ctlr_timer_work() - Worker thread function for timer work
1786 * Sends keep-alives and resets.
1801 if (fip->mode == FIP_MODE_VN2VN) in fcoe_ctlr_timer_work()
1803 mutex_lock(&fip->ctlr_mutex); in fcoe_ctlr_timer_work()
1804 if (fip->state == FIP_ST_DISABLED) { in fcoe_ctlr_timer_work()
1805 mutex_unlock(&fip->ctlr_mutex); in fcoe_ctlr_timer_work()
1809 fcf = fip->sel_fcf; in fcoe_ctlr_timer_work()
1812 sel = fip->sel_fcf; in fcoe_ctlr_timer_work()
1813 if (!sel && fip->sel_time) { in fcoe_ctlr_timer_work()
1814 if (time_after_eq(jiffies, fip->sel_time)) { in fcoe_ctlr_timer_work()
1816 fip->sel_time = 0; in fcoe_ctlr_timer_work()
1817 } else if (time_after(next_timer, fip->sel_time)) in fcoe_ctlr_timer_work()
1818 next_timer = fip->sel_time; in fcoe_ctlr_timer_work()
1821 if (sel && fip->flogi_req_send) in fcoe_ctlr_timer_work()
1826 if (sel && !sel->fd_flags) { in fcoe_ctlr_timer_work()
1827 if (time_after_eq(jiffies, fip->ctlr_ka_time)) { in fcoe_ctlr_timer_work()
1828 fip->ctlr_ka_time = jiffies + sel->fka_period; in fcoe_ctlr_timer_work()
1831 if (time_after(next_timer, fip->ctlr_ka_time)) in fcoe_ctlr_timer_work()
1832 next_timer = fip->ctlr_ka_time; in fcoe_ctlr_timer_work()
1834 if (time_after_eq(jiffies, fip->port_ka_time)) { in fcoe_ctlr_timer_work()
1835 fip->port_ka_time = jiffies + in fcoe_ctlr_timer_work()
1839 if (time_after(next_timer, fip->port_ka_time)) in fcoe_ctlr_timer_work()
1840 next_timer = fip->port_ka_time; in fcoe_ctlr_timer_work()
1842 if (!list_empty(&fip->fcfs)) in fcoe_ctlr_timer_work()
1843 mod_timer(&fip->timer, next_timer); in fcoe_ctlr_timer_work()
1844 mutex_unlock(&fip->ctlr_mutex); in fcoe_ctlr_timer_work()
1847 fc_lport_reset(fip->lp); in fcoe_ctlr_timer_work()
1853 fcoe_ctlr_send_keep_alive(fip, NULL, 0, fip->ctl_src_addr); in fcoe_ctlr_timer_work()
1856 mutex_lock(&fip->lp->lp_mutex); in fcoe_ctlr_timer_work()
1857 mac = fip->get_src_addr(fip->lp); in fcoe_ctlr_timer_work()
1858 fcoe_ctlr_send_keep_alive(fip, fip->lp, 1, mac); in fcoe_ctlr_timer_work()
1859 list_for_each_entry(vport, &fip->lp->vports, list) { in fcoe_ctlr_timer_work()
1860 mac = fip->get_src_addr(vport); in fcoe_ctlr_timer_work()
1863 mutex_unlock(&fip->lp->lp_mutex); in fcoe_ctlr_timer_work()
1868 * fcoe_ctlr_recv_work() - Worker thread function for receiving FIP frames
1877 while ((skb = skb_dequeue(&fip->fip_recv_list))) in fcoe_ctlr_recv_work()
1882 * fcoe_ctlr_recv_flogi() - Snoop pre-FIP receipt of FLOGI response
1885 * @fp: The FC frame to snoop
1890 * by fip->flogi_oxid != FC_XID_UNKNOWN.
1892 * The caller is responsible for freeing the frame.
1895 * Return non-zero if the frame should not be delivered to libfc.
1904 sa = eth_hdr(&fp->skb)->h_source; in fcoe_ctlr_recv_flogi()
1906 if (fh->fh_type != FC_TYPE_ELS) in fcoe_ctlr_recv_flogi()
1910 if (op == ELS_LS_ACC && fh->fh_r_ctl == FC_RCTL_ELS_REP && in fcoe_ctlr_recv_flogi()
1911 fip->flogi_oxid == ntohs(fh->fh_ox_id)) { in fcoe_ctlr_recv_flogi()
1913 mutex_lock(&fip->ctlr_mutex); in fcoe_ctlr_recv_flogi()
1914 if (fip->state != FIP_ST_AUTO && fip->state != FIP_ST_NON_FIP) { in fcoe_ctlr_recv_flogi()
1915 mutex_unlock(&fip->ctlr_mutex); in fcoe_ctlr_recv_flogi()
1916 return -EINVAL; in fcoe_ctlr_recv_flogi()
1920 "received FLOGI LS_ACC using non-FIP mode\n"); in fcoe_ctlr_recv_flogi()
1924 * If the src mac addr is FC_OUI-based, then we mark the in fcoe_ctlr_recv_flogi()
1925 * address_mode flag to use FC_OUI-based Ethernet DA. in fcoe_ctlr_recv_flogi()
1931 memcpy(fip->dest_addr, sa, ETH_ALEN); in fcoe_ctlr_recv_flogi()
1932 fip->map_dest = 0; in fcoe_ctlr_recv_flogi()
1934 fip->flogi_oxid = FC_XID_UNKNOWN; in fcoe_ctlr_recv_flogi()
1935 mutex_unlock(&fip->ctlr_mutex); in fcoe_ctlr_recv_flogi()
1936 fc_fcoe_set_mac(fr_cb(fp)->granted_mac, fh->fh_d_id); in fcoe_ctlr_recv_flogi()
1937 } else if (op == ELS_FLOGI && fh->fh_r_ctl == FC_RCTL_ELS_REQ && sa) { in fcoe_ctlr_recv_flogi()
1939 * Save source MAC for point-to-point responses. in fcoe_ctlr_recv_flogi()
1941 mutex_lock(&fip->ctlr_mutex); in fcoe_ctlr_recv_flogi()
1942 if (fip->state == FIP_ST_AUTO || fip->state == FIP_ST_NON_FIP) { in fcoe_ctlr_recv_flogi()
1943 memcpy(fip->dest_addr, sa, ETH_ALEN); in fcoe_ctlr_recv_flogi()
1944 fip->map_dest = 0; in fcoe_ctlr_recv_flogi()
1945 if (fip->state == FIP_ST_AUTO) in fcoe_ctlr_recv_flogi()
1946 LIBFCOE_FIP_DBG(fip, "received non-FIP FLOGI. " in fcoe_ctlr_recv_flogi()
1947 "Setting non-FIP mode\n"); in fcoe_ctlr_recv_flogi()
1950 mutex_unlock(&fip->ctlr_mutex); in fcoe_ctlr_recv_flogi()
1957 * fcoe_wwn_from_mac() - Converts a 48-bit IEEE MAC address to a 64-bit FC WWN
1998 * fcoe_ctlr_rport() - return the fcoe_rport for a given fc_rport_priv
2007 * fcoe_ctlr_vn_send() - Send a FIP VN2VN Probe Request or Reply.
2009 * @sub: sub-opcode for probe request, reply, or advertisement.
2014 enum fip_vn2vn_subcode sub, in fcoe_ctlr_vn_send() argument
2024 } __packed * frame; in fcoe_ctlr_vn_send() local
2031 len = sizeof(*frame); in fcoe_ctlr_vn_send()
2033 if (sub == FIP_SC_VN_CLAIM_NOTIFY || sub == FIP_SC_VN_CLAIM_REP) { in fcoe_ctlr_vn_send()
2038 dlen += sizeof(frame->mac) + sizeof(frame->wwnn) + sizeof(frame->vn); in fcoe_ctlr_vn_send()
2045 frame = (struct fip_vn2vn_probe_frame *)skb->data; in fcoe_ctlr_vn_send()
2046 memset(frame, 0, len); in fcoe_ctlr_vn_send()
2047 memcpy(frame->eth.h_dest, dest, ETH_ALEN); in fcoe_ctlr_vn_send()
2049 if (sub == FIP_SC_VN_BEACON) { in fcoe_ctlr_vn_send()
2050 hton24(frame->eth.h_source, FIP_VN_FC_MAP); in fcoe_ctlr_vn_send()
2051 hton24(frame->eth.h_source + 3, fip->port_id); in fcoe_ctlr_vn_send()
2053 memcpy(frame->eth.h_source, fip->ctl_src_addr, ETH_ALEN); in fcoe_ctlr_vn_send()
2055 frame->eth.h_proto = htons(ETH_P_FIP); in fcoe_ctlr_vn_send()
2057 frame->fip.fip_ver = FIP_VER_ENCAPS(FIP_VER); in fcoe_ctlr_vn_send()
2058 frame->fip.fip_op = htons(FIP_OP_VN2VN); in fcoe_ctlr_vn_send()
2059 frame->fip.fip_subcode = sub; in fcoe_ctlr_vn_send()
2060 frame->fip.fip_dl_len = htons(dlen / FIP_BPW); in fcoe_ctlr_vn_send()
2062 frame->mac.fd_desc.fip_dtype = FIP_DT_MAC; in fcoe_ctlr_vn_send()
2063 frame->mac.fd_desc.fip_dlen = sizeof(frame->mac) / FIP_BPW; in fcoe_ctlr_vn_send()
2064 memcpy(frame->mac.fd_mac, fip->ctl_src_addr, ETH_ALEN); in fcoe_ctlr_vn_send()
2066 frame->wwnn.fd_desc.fip_dtype = FIP_DT_NAME; in fcoe_ctlr_vn_send()
2067 frame->wwnn.fd_desc.fip_dlen = sizeof(frame->wwnn) / FIP_BPW; in fcoe_ctlr_vn_send()
2068 put_unaligned_be64(fip->lp->wwnn, &frame->wwnn.fd_wwn); in fcoe_ctlr_vn_send()
2070 frame->vn.fd_desc.fip_dtype = FIP_DT_VN_ID; in fcoe_ctlr_vn_send()
2071 frame->vn.fd_desc.fip_dlen = sizeof(frame->vn) / FIP_BPW; in fcoe_ctlr_vn_send()
2072 hton24(frame->vn.fd_mac, FIP_VN_FC_MAP); in fcoe_ctlr_vn_send()
2073 hton24(frame->vn.fd_mac + 3, fip->port_id); in fcoe_ctlr_vn_send()
2074 hton24(frame->vn.fd_fc_id, fip->port_id); in fcoe_ctlr_vn_send()
2075 put_unaligned_be64(fip->lp->wwpn, &frame->vn.fd_wwpn); in fcoe_ctlr_vn_send()
2078 * For claims, add FC-4 features. in fcoe_ctlr_vn_send()
2079 * TBD: Add interface to get fc-4 types and features from libfc. in fcoe_ctlr_vn_send()
2081 if (sub == FIP_SC_VN_CLAIM_NOTIFY || sub == FIP_SC_VN_CLAIM_REP) { in fcoe_ctlr_vn_send()
2082 ff = (struct fip_fc4_feat *)(frame + 1); in fcoe_ctlr_vn_send()
2083 ff->fd_desc.fip_dtype = FIP_DT_FC4F; in fcoe_ctlr_vn_send()
2084 ff->fd_desc.fip_dlen = sizeof(*ff) / FIP_BPW; in fcoe_ctlr_vn_send()
2085 ff->fd_fts = fip->lp->fcts; in fcoe_ctlr_vn_send()
2088 if (fip->lp->service_params & FCP_SPPF_INIT_FCN) in fcoe_ctlr_vn_send()
2090 if (fip->lp->service_params & FCP_SPPF_TARG_FCN) in fcoe_ctlr_vn_send()
2093 ff->fd_ff.fd_feat[FC_TYPE_FCP * 4 / 32] = htonl(fcp_feat); in fcoe_ctlr_vn_send()
2096 size->fd_desc.fip_dtype = FIP_DT_FCOE_SIZE; in fcoe_ctlr_vn_send()
2097 size->fd_desc.fip_dlen = sizeof(*size) / FIP_BPW; in fcoe_ctlr_vn_send()
2098 size->fd_size = htons(fcoe_ctlr_fcoe_size(fip)); in fcoe_ctlr_vn_send()
2102 skb->protocol = htons(ETH_P_FIP); in fcoe_ctlr_vn_send()
2103 skb->priority = fip->priority; in fcoe_ctlr_vn_send()
2107 fip->send(fip, skb); in fcoe_ctlr_vn_send()
2111 * fcoe_ctlr_vn_rport_callback - Event handler for rport events.
2122 struct fcoe_ctlr *fip = lport->disc.priv; in fcoe_ctlr_vn_rport_callback()
2126 rdata->ids.port_id, event); in fcoe_ctlr_vn_rport_callback()
2128 mutex_lock(&fip->ctlr_mutex); in fcoe_ctlr_vn_rport_callback()
2131 frport->login_count = 0; in fcoe_ctlr_vn_rport_callback()
2136 frport->login_count++; in fcoe_ctlr_vn_rport_callback()
2137 if (frport->login_count > FCOE_CTLR_VN2VN_LOGIN_LIMIT) { in fcoe_ctlr_vn_rport_callback()
2140 rdata->ids.port_id); in fcoe_ctlr_vn_rport_callback()
2147 mutex_unlock(&fip->ctlr_mutex); in fcoe_ctlr_vn_rport_callback()
2155 * fcoe_ctlr_disc_stop_locked() - stop discovery in VN2VN mode
2164 mutex_lock(&lport->disc.disc_mutex); in fcoe_ctlr_disc_stop_locked()
2165 list_for_each_entry_rcu(rdata, &lport->disc.rports, peers) { in fcoe_ctlr_disc_stop_locked()
2166 if (kref_get_unless_zero(&rdata->kref)) { in fcoe_ctlr_disc_stop_locked()
2168 kref_put(&rdata->kref, fc_rport_destroy); in fcoe_ctlr_disc_stop_locked()
2171 lport->disc.disc_callback = NULL; in fcoe_ctlr_disc_stop_locked()
2172 mutex_unlock(&lport->disc.disc_mutex); in fcoe_ctlr_disc_stop_locked()
2176 * fcoe_ctlr_disc_stop() - stop discovery in VN2VN mode
2184 struct fcoe_ctlr *fip = lport->disc.priv; in fcoe_ctlr_disc_stop()
2186 mutex_lock(&fip->ctlr_mutex); in fcoe_ctlr_disc_stop()
2188 mutex_unlock(&fip->ctlr_mutex); in fcoe_ctlr_disc_stop()
2192 * fcoe_ctlr_disc_stop_final() - stop discovery for shutdown in VN2VN mode
2206 * fcoe_ctlr_vn_restart() - VN2VN probe restart with new port_id
2216 fcoe_ctlr_disc_stop_locked(fip->lp); in fcoe_ctlr_vn_restart()
2223 * Don't use reserved IDs, use another non-zero value, just as random. in fcoe_ctlr_vn_restart()
2225 port_id = fip->port_id; in fcoe_ctlr_vn_restart()
2226 if (fip->probe_tries) in fcoe_ctlr_vn_restart()
2227 port_id = prandom_u32_state(&fip->rnd_state) & 0xffff; in fcoe_ctlr_vn_restart()
2229 port_id = fip->lp->wwpn & 0xffff; in fcoe_ctlr_vn_restart()
2232 fip->port_id = port_id; in fcoe_ctlr_vn_restart()
2234 if (fip->probe_tries < FIP_VN_RLIM_COUNT) { in fcoe_ctlr_vn_restart()
2235 fip->probe_tries++; in fcoe_ctlr_vn_restart()
2239 mod_timer(&fip->timer, jiffies + msecs_to_jiffies(wait)); in fcoe_ctlr_vn_restart()
2244 * fcoe_ctlr_vn_start() - Start in VN2VN mode
2251 fip->probe_tries = 0; in fcoe_ctlr_vn_start()
2252 prandom_seed_state(&fip->rnd_state, fip->lp->wwpn); in fcoe_ctlr_vn_start()
2257 * fcoe_ctlr_vn_parse - parse probe request or response
2262 * Returns non-zero error number on error.
2279 u8 sub; in fcoe_ctlr_vn_parse() local
2281 fiph = (struct fip_header *)skb->data; in fcoe_ctlr_vn_parse()
2282 frport->flags = ntohs(fiph->fip_flags); in fcoe_ctlr_vn_parse()
2284 sub = fiph->fip_subcode; in fcoe_ctlr_vn_parse()
2285 switch (sub) { in fcoe_ctlr_vn_parse()
2299 LIBFCOE_FIP_DBG(fip, "vn_parse unknown subcode %u\n", sub); in fcoe_ctlr_vn_parse()
2300 return -EINVAL; in fcoe_ctlr_vn_parse()
2303 rlen = ntohs(fiph->fip_dl_len) * 4; in fcoe_ctlr_vn_parse()
2304 if (rlen + sizeof(*fiph) > skb->len) in fcoe_ctlr_vn_parse()
2305 return -EINVAL; in fcoe_ctlr_vn_parse()
2309 dlen = desc->fip_dlen * FIP_BPW; in fcoe_ctlr_vn_parse()
2311 return -EINVAL; in fcoe_ctlr_vn_parse()
2313 dtype = desc->fip_dtype; in fcoe_ctlr_vn_parse()
2320 dtype, sub); in fcoe_ctlr_vn_parse()
2321 return -EINVAL; in fcoe_ctlr_vn_parse()
2331 if (!is_valid_ether_addr(macd->fd_mac)) { in fcoe_ctlr_vn_parse()
2334 macd->fd_mac); in fcoe_ctlr_vn_parse()
2335 return -EINVAL; in fcoe_ctlr_vn_parse()
2337 memcpy(frport->enode_mac, macd->fd_mac, ETH_ALEN); in fcoe_ctlr_vn_parse()
2343 frport->rdata.ids.node_name = in fcoe_ctlr_vn_parse()
2344 get_unaligned_be64(&wwn->fd_wwn); in fcoe_ctlr_vn_parse()
2350 memcpy(frport->vn_mac, vn->fd_mac, ETH_ALEN); in fcoe_ctlr_vn_parse()
2351 frport->rdata.ids.port_id = ntoh24(vn->fd_fc_id); in fcoe_ctlr_vn_parse()
2352 frport->rdata.ids.port_name = in fcoe_ctlr_vn_parse()
2353 get_unaligned_be64(&vn->fd_wwpn); in fcoe_ctlr_vn_parse()
2363 frport->fcoe_len = ntohs(size->fd_size); in fcoe_ctlr_vn_parse()
2370 return -EINVAL; in fcoe_ctlr_vn_parse()
2374 rlen -= dlen; in fcoe_ctlr_vn_parse()
2381 return -EINVAL; in fcoe_ctlr_vn_parse()
2385 * fcoe_ctlr_vn_send_claim() - send multicast FIP VN2VN Claim Notification.
2393 fip->sol_time = jiffies; in fcoe_ctlr_vn_send_claim()
2397 * fcoe_ctlr_vn_probe_req() - handle incoming VN2VN probe request.
2406 if (frport->rdata.ids.port_id != fip->port_id) in fcoe_ctlr_vn_probe_req()
2409 switch (fip->state) { in fcoe_ctlr_vn_probe_req()
2413 fip->state); in fcoe_ctlr_vn_probe_req()
2415 frport->enode_mac, 0); in fcoe_ctlr_vn_probe_req()
2426 if (fip->lp->wwpn > frport->rdata.ids.port_name && in fcoe_ctlr_vn_probe_req()
2427 !(frport->flags & FIP_FL_REC_OR_P2P)) { in fcoe_ctlr_vn_probe_req()
2431 frport->enode_mac, 0); in fcoe_ctlr_vn_probe_req()
2442 fip->state); in fcoe_ctlr_vn_probe_req()
2448 * fcoe_ctlr_vn_probe_reply() - handle incoming VN2VN probe reply.
2457 if (frport->rdata.ids.port_id != fip->port_id) in fcoe_ctlr_vn_probe_reply()
2459 switch (fip->state) { in fcoe_ctlr_vn_probe_reply()
2465 fip->state); in fcoe_ctlr_vn_probe_reply()
2478 * fcoe_ctlr_vn_add() - Add a VN2VN entry to the list, based on a claim reply.
2480 * @new: newly-parsed FCoE rport as a template for new rdata
2486 struct fc_lport *lport = fip->lp; in fcoe_ctlr_vn_add()
2492 port_id = new->rdata.ids.port_id; in fcoe_ctlr_vn_add()
2493 if (port_id == fip->port_id) in fcoe_ctlr_vn_add()
2496 mutex_lock(&lport->disc.disc_mutex); in fcoe_ctlr_vn_add()
2499 mutex_unlock(&lport->disc.disc_mutex); in fcoe_ctlr_vn_add()
2502 mutex_lock(&rdata->rp_mutex); in fcoe_ctlr_vn_add()
2503 mutex_unlock(&lport->disc.disc_mutex); in fcoe_ctlr_vn_add()
2505 rdata->ops = &fcoe_ctlr_vn_rport_ops; in fcoe_ctlr_vn_add()
2506 rdata->disc_id = lport->disc.disc_id; in fcoe_ctlr_vn_add()
2508 ids = &rdata->ids; in fcoe_ctlr_vn_add()
2509 if ((ids->port_name != -1 && in fcoe_ctlr_vn_add()
2510 ids->port_name != new->rdata.ids.port_name) || in fcoe_ctlr_vn_add()
2511 (ids->node_name != -1 && in fcoe_ctlr_vn_add()
2512 ids->node_name != new->rdata.ids.node_name)) { in fcoe_ctlr_vn_add()
2513 mutex_unlock(&rdata->rp_mutex); in fcoe_ctlr_vn_add()
2516 mutex_lock(&rdata->rp_mutex); in fcoe_ctlr_vn_add()
2518 ids->port_name = new->rdata.ids.port_name; in fcoe_ctlr_vn_add()
2519 ids->node_name = new->rdata.ids.node_name; in fcoe_ctlr_vn_add()
2520 mutex_unlock(&rdata->rp_mutex); in fcoe_ctlr_vn_add()
2524 port_id, frport->fcoe_len ? "old" : "new", in fcoe_ctlr_vn_add()
2525 rdata->rp_state); in fcoe_ctlr_vn_add()
2526 frport->fcoe_len = new->fcoe_len; in fcoe_ctlr_vn_add()
2527 frport->flags = new->flags; in fcoe_ctlr_vn_add()
2528 frport->login_count = new->login_count; in fcoe_ctlr_vn_add()
2529 memcpy(frport->enode_mac, new->enode_mac, ETH_ALEN); in fcoe_ctlr_vn_add()
2530 memcpy(frport->vn_mac, new->vn_mac, ETH_ALEN); in fcoe_ctlr_vn_add()
2531 frport->time = 0; in fcoe_ctlr_vn_add()
2535 * fcoe_ctlr_vn_lookup() - Find VN remote port's MAC address
2540 * Returns non-zero error if no remote port found.
2544 struct fc_lport *lport = fip->lp; in fcoe_ctlr_vn_lookup()
2547 int ret = -1; in fcoe_ctlr_vn_lookup()
2552 memcpy(mac, frport->enode_mac, ETH_ALEN); in fcoe_ctlr_vn_lookup()
2554 kref_put(&rdata->kref, fc_rport_destroy); in fcoe_ctlr_vn_lookup()
2560 * fcoe_ctlr_vn_claim_notify() - handle received FIP VN2VN Claim Notification
2562 * @new: newly-parsed FCoE rport as a template for new rdata
2569 if (new->flags & FIP_FL_REC_OR_P2P) { in fcoe_ctlr_vn_claim_notify()
2574 switch (fip->state) { in fcoe_ctlr_vn_claim_notify()
2578 if (new->rdata.ids.port_id == fip->port_id) { in fcoe_ctlr_vn_claim_notify()
2581 fip->state); in fcoe_ctlr_vn_claim_notify()
2587 if (new->rdata.ids.port_id == fip->port_id) { in fcoe_ctlr_vn_claim_notify()
2588 if (new->rdata.ids.port_name > fip->lp->wwpn) { in fcoe_ctlr_vn_claim_notify()
2600 new->rdata.ids.port_id); in fcoe_ctlr_vn_claim_notify()
2601 fcoe_ctlr_vn_send(fip, FIP_SC_VN_CLAIM_REP, new->enode_mac, in fcoe_ctlr_vn_claim_notify()
2602 min((u32)new->fcoe_len, in fcoe_ctlr_vn_claim_notify()
2609 new->rdata.ids.port_id); in fcoe_ctlr_vn_claim_notify()
2615 * fcoe_ctlr_vn_claim_resp() - handle received Claim Response
2616 * @fip: The FCoE controller that received the frame
2617 * @new: newly-parsed FCoE rport from the Claim Response
2624 LIBFCOE_FIP_DBG(fip, "claim resp from from rport %x - state %s\n", in fcoe_ctlr_vn_claim_resp()
2625 new->rdata.ids.port_id, fcoe_ctlr_state(fip->state)); in fcoe_ctlr_vn_claim_resp()
2626 if (fip->state == FIP_ST_VNMP_UP || fip->state == FIP_ST_VNMP_CLAIM) in fcoe_ctlr_vn_claim_resp()
2631 * fcoe_ctlr_vn_beacon() - handle received beacon.
2632 * @fip: The FCoE controller that received the frame
2633 * @new: newly-parsed FCoE rport from the Beacon
2640 struct fc_lport *lport = fip->lp; in fcoe_ctlr_vn_beacon()
2644 if (new->flags & FIP_FL_REC_OR_P2P) { in fcoe_ctlr_vn_beacon()
2649 rdata = fc_rport_lookup(lport, new->rdata.ids.port_id); in fcoe_ctlr_vn_beacon()
2651 if (rdata->ids.node_name == new->rdata.ids.node_name && in fcoe_ctlr_vn_beacon()
2652 rdata->ids.port_name == new->rdata.ids.port_name) { in fcoe_ctlr_vn_beacon()
2656 rdata->ids.port_id); in fcoe_ctlr_vn_beacon()
2657 if (!frport->time && fip->state == FIP_ST_VNMP_UP) { in fcoe_ctlr_vn_beacon()
2660 rdata->ids.port_id); in fcoe_ctlr_vn_beacon()
2663 frport->time = jiffies; in fcoe_ctlr_vn_beacon()
2665 kref_put(&rdata->kref, fc_rport_destroy); in fcoe_ctlr_vn_beacon()
2668 if (fip->state != FIP_ST_VNMP_UP) in fcoe_ctlr_vn_beacon()
2677 new->rdata.ids.port_id); in fcoe_ctlr_vn_beacon()
2679 fip->sol_time + msecs_to_jiffies(FIP_VN_ANN_WAIT))) in fcoe_ctlr_vn_beacon()
2684 * fcoe_ctlr_vn_age() - Check for VN_ports without recent beacons
2689 * Returns the soonest time for next age-out or a time far in the future.
2693 struct fc_lport *lport = fip->lp; in fcoe_ctlr_vn_age()
2700 mutex_lock(&lport->disc.disc_mutex); in fcoe_ctlr_vn_age()
2701 list_for_each_entry_rcu(rdata, &lport->disc.rports, peers) { in fcoe_ctlr_vn_age()
2702 if (!kref_get_unless_zero(&rdata->kref)) in fcoe_ctlr_vn_age()
2705 if (!frport->time) { in fcoe_ctlr_vn_age()
2706 kref_put(&rdata->kref, fc_rport_destroy); in fcoe_ctlr_vn_age()
2709 deadline = frport->time + in fcoe_ctlr_vn_age()
2712 frport->time = 0; in fcoe_ctlr_vn_age()
2715 rdata->ids.port_name, rdata->ids.port_id); in fcoe_ctlr_vn_age()
2719 kref_put(&rdata->kref, fc_rport_destroy); in fcoe_ctlr_vn_age()
2721 mutex_unlock(&lport->disc.disc_mutex); in fcoe_ctlr_vn_age()
2726 * fcoe_ctlr_vn_recv() - Receive a FIP frame
2727 * @fip: The FCoE controller that received the frame
2728 * @skb: The received FIP frame
2730 * Returns non-zero if the frame is dropped.
2731 * Always consumes the frame.
2736 enum fip_vn2vn_subcode sub; in fcoe_ctlr_vn_recv() local
2740 fiph = (struct fip_header *)skb->data; in fcoe_ctlr_vn_recv()
2741 sub = fiph->fip_subcode; in fcoe_ctlr_vn_recv()
2743 if (fip->lp->vlan) in fcoe_ctlr_vn_recv()
2746 if (vlan_id && vlan_id != fip->lp->vlan) { in fcoe_ctlr_vn_recv()
2747 LIBFCOE_FIP_DBG(fip, "vn_recv drop frame sub %x vlan %d\n", in fcoe_ctlr_vn_recv()
2748 sub, vlan_id); in fcoe_ctlr_vn_recv()
2749 rc = -EAGAIN; in fcoe_ctlr_vn_recv()
2759 mutex_lock(&fip->ctlr_mutex); in fcoe_ctlr_vn_recv()
2760 switch (sub) { in fcoe_ctlr_vn_recv()
2777 LIBFCOE_FIP_DBG(fip, "vn_recv unknown subcode %d\n", sub); in fcoe_ctlr_vn_recv()
2778 rc = -1; in fcoe_ctlr_vn_recv()
2781 mutex_unlock(&fip->ctlr_mutex); in fcoe_ctlr_vn_recv()
2788 * fcoe_ctlr_vlan_parse - parse vlan discovery request or response
2793 * Returns non-zero error number on error.
2808 u8 sub; in fcoe_ctlr_vlan_parse() local
2810 fiph = (struct fip_header *)skb->data; in fcoe_ctlr_vlan_parse()
2811 frport->flags = ntohs(fiph->fip_flags); in fcoe_ctlr_vlan_parse()
2813 sub = fiph->fip_subcode; in fcoe_ctlr_vlan_parse()
2814 switch (sub) { in fcoe_ctlr_vlan_parse()
2819 LIBFCOE_FIP_DBG(fip, "vn_parse unknown subcode %u\n", sub); in fcoe_ctlr_vlan_parse()
2820 return -EINVAL; in fcoe_ctlr_vlan_parse()
2823 rlen = ntohs(fiph->fip_dl_len) * 4; in fcoe_ctlr_vlan_parse()
2824 if (rlen + sizeof(*fiph) > skb->len) in fcoe_ctlr_vlan_parse()
2825 return -EINVAL; in fcoe_ctlr_vlan_parse()
2829 dlen = desc->fip_dlen * FIP_BPW; in fcoe_ctlr_vlan_parse()
2831 return -EINVAL; in fcoe_ctlr_vlan_parse()
2833 dtype = desc->fip_dtype; in fcoe_ctlr_vlan_parse()
2840 dtype, sub); in fcoe_ctlr_vlan_parse()
2841 return -EINVAL; in fcoe_ctlr_vlan_parse()
2851 if (!is_valid_ether_addr(macd->fd_mac)) { in fcoe_ctlr_vlan_parse()
2854 macd->fd_mac); in fcoe_ctlr_vlan_parse()
2855 return -EINVAL; in fcoe_ctlr_vlan_parse()
2857 memcpy(frport->enode_mac, macd->fd_mac, ETH_ALEN); in fcoe_ctlr_vlan_parse()
2863 frport->rdata.ids.node_name = in fcoe_ctlr_vlan_parse()
2864 get_unaligned_be64(&wwn->fd_wwn); in fcoe_ctlr_vlan_parse()
2871 return -EINVAL; in fcoe_ctlr_vlan_parse()
2875 rlen -= dlen; in fcoe_ctlr_vlan_parse()
2882 return -EINVAL; in fcoe_ctlr_vlan_parse()
2886 * fcoe_ctlr_vlan_send() - Send a FIP VLAN Notification
2888 * @sub: sub-opcode for vlan notification or vn2vn vlan notification
2892 enum fip_vlan_subcode sub, in fcoe_ctlr_vlan_send() argument
2901 } __packed * frame; in fcoe_ctlr_vlan_send() local
2905 len = sizeof(*frame); in fcoe_ctlr_vlan_send()
2906 dlen = sizeof(frame->mac) + sizeof(frame->vlan); in fcoe_ctlr_vlan_send()
2914 fip->mode == FIP_MODE_VN2VN ? "vn2vn" : "fcf", in fcoe_ctlr_vlan_send()
2915 fip->lp->vlan); in fcoe_ctlr_vlan_send()
2917 frame = (struct fip_vlan_notify_frame *)skb->data; in fcoe_ctlr_vlan_send()
2918 memset(frame, 0, len); in fcoe_ctlr_vlan_send()
2919 memcpy(frame->eth.h_dest, dest, ETH_ALEN); in fcoe_ctlr_vlan_send()
2921 memcpy(frame->eth.h_source, fip->ctl_src_addr, ETH_ALEN); in fcoe_ctlr_vlan_send()
2922 frame->eth.h_proto = htons(ETH_P_FIP); in fcoe_ctlr_vlan_send()
2924 frame->fip.fip_ver = FIP_VER_ENCAPS(FIP_VER); in fcoe_ctlr_vlan_send()
2925 frame->fip.fip_op = htons(FIP_OP_VLAN); in fcoe_ctlr_vlan_send()
2926 frame->fip.fip_subcode = sub; in fcoe_ctlr_vlan_send()
2927 frame->fip.fip_dl_len = htons(dlen / FIP_BPW); in fcoe_ctlr_vlan_send()
2929 frame->mac.fd_desc.fip_dtype = FIP_DT_MAC; in fcoe_ctlr_vlan_send()
2930 frame->mac.fd_desc.fip_dlen = sizeof(frame->mac) / FIP_BPW; in fcoe_ctlr_vlan_send()
2931 memcpy(frame->mac.fd_mac, fip->ctl_src_addr, ETH_ALEN); in fcoe_ctlr_vlan_send()
2933 frame->vlan.fd_desc.fip_dtype = FIP_DT_VLAN; in fcoe_ctlr_vlan_send()
2934 frame->vlan.fd_desc.fip_dlen = sizeof(frame->vlan) / FIP_BPW; in fcoe_ctlr_vlan_send()
2935 put_unaligned_be16(fip->lp->vlan, &frame->vlan.fd_vlan); in fcoe_ctlr_vlan_send()
2938 skb->protocol = htons(ETH_P_FIP); in fcoe_ctlr_vlan_send()
2939 skb->priority = fip->priority; in fcoe_ctlr_vlan_send()
2943 fip->send(fip, skb); in fcoe_ctlr_vlan_send()
2947 * fcoe_ctlr_vlan_disc_reply() - send FIP VLAN Discovery Notification.
2949 * @frport: The newly-parsed FCoE rport from the Discovery Request
2956 enum fip_vlan_subcode sub = FIP_SC_VL_NOTE; in fcoe_ctlr_vlan_disc_reply() local
2958 if (fip->mode == FIP_MODE_VN2VN) in fcoe_ctlr_vlan_disc_reply()
2959 sub = FIP_SC_VL_VN2VN_NOTE; in fcoe_ctlr_vlan_disc_reply()
2961 fcoe_ctlr_vlan_send(fip, sub, frport->enode_mac); in fcoe_ctlr_vlan_disc_reply()
2965 * fcoe_ctlr_vlan_recv - vlan request receive handler for VN2VN mode.
2972 enum fip_vlan_subcode sub; in fcoe_ctlr_vlan_recv() local
2976 fiph = (struct fip_header *)skb->data; in fcoe_ctlr_vlan_recv()
2977 sub = fiph->fip_subcode; in fcoe_ctlr_vlan_recv()
2983 mutex_lock(&fip->ctlr_mutex); in fcoe_ctlr_vlan_recv()
2984 if (sub == FIP_SC_VL_REQ) in fcoe_ctlr_vlan_recv()
2986 mutex_unlock(&fip->ctlr_mutex); in fcoe_ctlr_vlan_recv()
2994 * fcoe_ctlr_disc_recv - discovery receive handler for VN2VN mode.
2996 * @fp: The received frame
2999 * fabric-generated ELSes.
3012 * fcoe_ctlr_disc_start - start discovery for VN2VN mode.
3026 struct fc_disc *disc = &lport->disc; in fcoe_ctlr_disc_start()
3027 struct fcoe_ctlr *fip = disc->priv; in fcoe_ctlr_disc_start()
3029 mutex_lock(&disc->disc_mutex); in fcoe_ctlr_disc_start()
3030 disc->disc_callback = callback; in fcoe_ctlr_disc_start()
3031 disc->disc_id = (disc->disc_id + 2) | 1; in fcoe_ctlr_disc_start()
3032 disc->pending = 1; in fcoe_ctlr_disc_start()
3033 schedule_work(&fip->timer_work); in fcoe_ctlr_disc_start()
3034 mutex_unlock(&disc->disc_mutex); in fcoe_ctlr_disc_start()
3038 * fcoe_ctlr_vn_disc() - report FIP VN_port discovery results after claim state.
3047 struct fc_lport *lport = fip->lp; in fcoe_ctlr_vn_disc()
3048 struct fc_disc *disc = &lport->disc; in fcoe_ctlr_vn_disc()
3053 mutex_lock(&disc->disc_mutex); in fcoe_ctlr_vn_disc()
3054 callback = disc->pending ? disc->disc_callback : NULL; in fcoe_ctlr_vn_disc()
3055 disc->pending = 0; in fcoe_ctlr_vn_disc()
3056 list_for_each_entry_rcu(rdata, &disc->rports, peers) { in fcoe_ctlr_vn_disc()
3057 if (!kref_get_unless_zero(&rdata->kref)) in fcoe_ctlr_vn_disc()
3060 if (frport->time) in fcoe_ctlr_vn_disc()
3062 kref_put(&rdata->kref, fc_rport_destroy); in fcoe_ctlr_vn_disc()
3064 mutex_unlock(&disc->disc_mutex); in fcoe_ctlr_vn_disc()
3070 * fcoe_ctlr_vn_timeout - timer work function for VN2VN mode.
3079 mutex_lock(&fip->ctlr_mutex); in fcoe_ctlr_vn_timeout()
3080 switch (fip->state) { in fcoe_ctlr_vn_timeout()
3095 new_port_id = fip->port_id; in fcoe_ctlr_vn_timeout()
3099 fip->update_mac(fip->lp, mac); in fcoe_ctlr_vn_timeout()
3109 next_time = fip->sol_time + msecs_to_jiffies(FIP_VN_ANN_WAIT); in fcoe_ctlr_vn_timeout()
3116 fip->port_ka_time = next_time; in fcoe_ctlr_vn_timeout()
3122 if (time_after_eq(jiffies, fip->port_ka_time)) { in fcoe_ctlr_vn_timeout()
3126 fip->port_ka_time = jiffies + in fcoe_ctlr_vn_timeout()
3130 if (time_before(fip->port_ka_time, next_time)) in fcoe_ctlr_vn_timeout()
3131 next_time = fip->port_ka_time; in fcoe_ctlr_vn_timeout()
3136 WARN(1, "unexpected state %d\n", fip->state); in fcoe_ctlr_vn_timeout()
3139 mod_timer(&fip->timer, next_time); in fcoe_ctlr_vn_timeout()
3141 mutex_unlock(&fip->ctlr_mutex); in fcoe_ctlr_vn_timeout()
3145 fc_lport_set_local_id(fip->lp, new_port_id); in fcoe_ctlr_vn_timeout()
3149 * fcoe_ctlr_mode_set() - Set or reset the ctlr's mode
3165 WARN_ON(lport->state != LPORT_ST_RESET && in fcoe_ctlr_mode_set()
3166 lport->state != LPORT_ST_DISABLED); in fcoe_ctlr_mode_set()
3169 lport->rport_priv_size = sizeof(struct fcoe_rport); in fcoe_ctlr_mode_set()
3170 lport->point_to_multipoint = 1; in fcoe_ctlr_mode_set()
3171 lport->tt.disc_recv_req = fcoe_ctlr_disc_recv; in fcoe_ctlr_mode_set()
3172 lport->tt.disc_start = fcoe_ctlr_disc_start; in fcoe_ctlr_mode_set()
3173 lport->tt.disc_stop = fcoe_ctlr_disc_stop; in fcoe_ctlr_mode_set()
3174 lport->tt.disc_stop_final = fcoe_ctlr_disc_stop_final; in fcoe_ctlr_mode_set()
3177 lport->rport_priv_size = 0; in fcoe_ctlr_mode_set()
3178 lport->point_to_multipoint = 0; in fcoe_ctlr_mode_set()
3179 lport->tt.disc_recv_req = NULL; in fcoe_ctlr_mode_set()
3180 lport->tt.disc_start = NULL; in fcoe_ctlr_mode_set()
3181 lport->tt.disc_stop = NULL; in fcoe_ctlr_mode_set()
3182 lport->tt.disc_stop_final = NULL; in fcoe_ctlr_mode_set()
3190 * fcoe_libfc_config() - Sets up libfc related properties for local port
3194 * @init_fcp: If non-zero, the FCP portion of libfc should be initialized
3202 memcpy(&lport->tt, tt, sizeof(*tt)); in fcoe_libfc_config()
3204 return -ENOMEM; in fcoe_libfc_config()
3209 fcoe_ctlr_mode_set(lport, fip, fip->mode); in fcoe_libfc_config()
3220 mutex_lock(&fip->ctlr_mutex); in fcoe_fcf_get_selected()
3221 mutex_lock(&ctlr_dev->lock); in fcoe_fcf_get_selected()
3225 fcf_dev->selected = (fcf == fip->sel_fcf) ? 1 : 0; in fcoe_fcf_get_selected()
3227 fcf_dev->selected = 0; in fcoe_fcf_get_selected()
3229 mutex_unlock(&ctlr_dev->lock); in fcoe_fcf_get_selected()
3230 mutex_unlock(&fip->ctlr_mutex); in fcoe_fcf_get_selected()
3237 struct fc_lport *lport = ctlr->lp; in fcoe_ctlr_set_fip_mode()
3239 mutex_lock(&ctlr->ctlr_mutex); in fcoe_ctlr_set_fip_mode()
3240 switch (ctlr_dev->mode) { in fcoe_ctlr_set_fip_mode()
3242 ctlr->mode = FIP_MODE_VN2VN; in fcoe_ctlr_set_fip_mode()
3246 ctlr->mode = FIP_MODE_FABRIC; in fcoe_ctlr_set_fip_mode()
3250 mutex_unlock(&ctlr->ctlr_mutex); in fcoe_ctlr_set_fip_mode()
3252 fcoe_ctlr_mode_set(lport, ctlr, ctlr->mode); in fcoe_ctlr_set_fip_mode()