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
324 mutex_lock(&fip->ctlr_mutex); in fcoe_ctlr_announce()
325 spin_lock_irqsave(&fip->ctlr_lock, flags); in fcoe_ctlr_announce()
327 kfree_skb(fip->flogi_req); in fcoe_ctlr_announce()
328 fip->flogi_req = NULL; in fcoe_ctlr_announce()
329 list_for_each_entry(fcf, &fip->fcfs, list) in fcoe_ctlr_announce()
330 fcf->flogi_sent = 0; in fcoe_ctlr_announce()
332 spin_unlock_irqrestore(&fip->ctlr_lock, flags); in fcoe_ctlr_announce()
333 sel = fip->sel_fcf; in fcoe_ctlr_announce()
335 if (sel && ether_addr_equal(sel->fcf_mac, fip->dest_addr)) in fcoe_ctlr_announce()
337 if (!is_zero_ether_addr(fip->dest_addr)) { in fcoe_ctlr_announce()
339 "FIP Fibre-Channel Forwarder MAC %pM deselected\n", in fcoe_ctlr_announce()
340 fip->lp->host->host_no, fip->dest_addr); in fcoe_ctlr_announce()
341 eth_zero_addr(fip->dest_addr); in fcoe_ctlr_announce()
345 "Fibre-Channel Forwarder MAC %pM\n", in fcoe_ctlr_announce()
346 fip->lp->host->host_no, sel->fcf_mac); in fcoe_ctlr_announce()
347 memcpy(fip->dest_addr, sel->fcoe_mac, ETH_ALEN); in fcoe_ctlr_announce()
348 fip->map_dest = 0; in fcoe_ctlr_announce()
351 mutex_unlock(&fip->ctlr_mutex); in fcoe_ctlr_announce()
355 * fcoe_ctlr_fcoe_size() - Return the maximum FCoE size required for VN_Port
364 * Determine the max FCoE frame size allowed, including in fcoe_ctlr_fcoe_size()
366 * Note: lp->mfs is currently the payload size, not the frame size. in fcoe_ctlr_fcoe_size()
368 return fip->lp->mfs + sizeof(struct fc_frame_header) + in fcoe_ctlr_fcoe_size()
373 * fcoe_ctlr_solicit() - Send a FIP solicitation
395 sol = (struct fip_sol *)skb->data; in fcoe_ctlr_solicit()
398 memcpy(sol->eth.h_dest, fcf ? fcf->fcf_mac : fcoe_all_fcfs, ETH_ALEN); in fcoe_ctlr_solicit()
399 memcpy(sol->eth.h_source, fip->ctl_src_addr, ETH_ALEN); in fcoe_ctlr_solicit()
400 sol->eth.h_proto = htons(ETH_P_FIP); in fcoe_ctlr_solicit()
402 sol->fip.fip_ver = FIP_VER_ENCAPS(FIP_VER); in fcoe_ctlr_solicit()
403 sol->fip.fip_op = htons(FIP_OP_DISC); in fcoe_ctlr_solicit()
404 sol->fip.fip_subcode = FIP_SC_SOL; in fcoe_ctlr_solicit()
405 sol->fip.fip_dl_len = htons(sizeof(sol->desc) / FIP_BPW); in fcoe_ctlr_solicit()
406 sol->fip.fip_flags = htons(FIP_FL_FPMA); in fcoe_ctlr_solicit()
407 if (fip->spma) in fcoe_ctlr_solicit()
408 sol->fip.fip_flags |= htons(FIP_FL_SPMA); in fcoe_ctlr_solicit()
410 sol->desc.mac.fd_desc.fip_dtype = FIP_DT_MAC; in fcoe_ctlr_solicit()
411 sol->desc.mac.fd_desc.fip_dlen = sizeof(sol->desc.mac) / FIP_BPW; in fcoe_ctlr_solicit()
412 memcpy(sol->desc.mac.fd_mac, fip->ctl_src_addr, ETH_ALEN); in fcoe_ctlr_solicit()
414 sol->desc.wwnn.fd_desc.fip_dtype = FIP_DT_NAME; in fcoe_ctlr_solicit()
415 sol->desc.wwnn.fd_desc.fip_dlen = sizeof(sol->desc.wwnn) / FIP_BPW; in fcoe_ctlr_solicit()
416 put_unaligned_be64(fip->lp->wwnn, &sol->desc.wwnn.fd_wwn); in fcoe_ctlr_solicit()
419 sol->desc.size.fd_desc.fip_dtype = FIP_DT_FCOE_SIZE; in fcoe_ctlr_solicit()
420 sol->desc.size.fd_desc.fip_dlen = sizeof(sol->desc.size) / FIP_BPW; in fcoe_ctlr_solicit()
421 sol->desc.size.fd_size = htons(fcoe_size); in fcoe_ctlr_solicit()
424 skb->protocol = htons(ETH_P_FIP); in fcoe_ctlr_solicit()
425 skb->priority = fip->priority; in fcoe_ctlr_solicit()
428 fip->send(fip, skb); in fcoe_ctlr_solicit()
431 fip->sol_time = jiffies; in fcoe_ctlr_solicit()
435 * fcoe_ctlr_link_up() - Start FCoE controller
442 mutex_lock(&fip->ctlr_mutex); in fcoe_ctlr_link_up()
443 if (fip->state == FIP_ST_NON_FIP || fip->state == FIP_ST_AUTO) { in fcoe_ctlr_link_up()
444 mutex_unlock(&fip->ctlr_mutex); in fcoe_ctlr_link_up()
445 fc_linkup(fip->lp); in fcoe_ctlr_link_up()
446 } else if (fip->state == FIP_ST_LINK_WAIT) { in fcoe_ctlr_link_up()
447 if (fip->mode == FIP_MODE_NON_FIP) in fcoe_ctlr_link_up()
451 switch (fip->mode) { in fcoe_ctlr_link_up()
453 LIBFCOE_FIP_DBG(fip, "invalid mode %d\n", fip->mode); in fcoe_ctlr_link_up()
460 mutex_unlock(&fip->ctlr_mutex); in fcoe_ctlr_link_up()
461 fc_linkup(fip->lp); in fcoe_ctlr_link_up()
466 mutex_unlock(&fip->ctlr_mutex); in fcoe_ctlr_link_up()
467 fc_linkup(fip->lp); in fcoe_ctlr_link_up()
471 mutex_unlock(&fip->ctlr_mutex); in fcoe_ctlr_link_up()
476 * fcoe_ctlr_reset() - Reset a FCoE controller
482 del_timer(&fip->timer); in fcoe_ctlr_reset()
483 fip->ctlr_ka_time = 0; in fcoe_ctlr_reset()
484 fip->port_ka_time = 0; in fcoe_ctlr_reset()
485 fip->sol_time = 0; in fcoe_ctlr_reset()
486 fip->flogi_oxid = FC_XID_UNKNOWN; in fcoe_ctlr_reset()
491 * fcoe_ctlr_link_down() - Stop a FCoE controller
494 * Returns non-zero if the link was up and now isn't.
504 mutex_lock(&fip->ctlr_mutex); in fcoe_ctlr_link_down()
506 link_dropped = fip->state != FIP_ST_LINK_WAIT; in fcoe_ctlr_link_down()
508 mutex_unlock(&fip->ctlr_mutex); in fcoe_ctlr_link_down()
511 fc_linkdown(fip->lp); in fcoe_ctlr_link_down()
517 * fcoe_ctlr_send_keep_alive() - Send a keep-alive to the selected FCF
520 * @ports: 0 for controller keep-alive, 1 for port keep-alive
523 * A controller keep-alive is sent every fka_period (typically 8 seconds).
526 * A port keep-alive is sent every 90 seconds while logged in.
528 * The destination is the FCF's F-port.
545 fcf = fip->sel_fcf; in fcoe_ctlr_send_keep_alive()
546 lp = fip->lp; in fcoe_ctlr_send_keep_alive()
547 if (!fcf || (ports && !lp->port_id)) in fcoe_ctlr_send_keep_alive()
555 kal = (struct fip_kal *)skb->data; in fcoe_ctlr_send_keep_alive()
557 memcpy(kal->eth.h_dest, fcf->fcf_mac, ETH_ALEN); in fcoe_ctlr_send_keep_alive()
558 memcpy(kal->eth.h_source, sa, ETH_ALEN); in fcoe_ctlr_send_keep_alive()
559 kal->eth.h_proto = htons(ETH_P_FIP); in fcoe_ctlr_send_keep_alive()
561 kal->fip.fip_ver = FIP_VER_ENCAPS(FIP_VER); in fcoe_ctlr_send_keep_alive()
562 kal->fip.fip_op = htons(FIP_OP_CTRL); in fcoe_ctlr_send_keep_alive()
563 kal->fip.fip_subcode = FIP_SC_KEEP_ALIVE; in fcoe_ctlr_send_keep_alive()
564 kal->fip.fip_dl_len = htons((sizeof(kal->mac) + in fcoe_ctlr_send_keep_alive()
566 kal->fip.fip_flags = htons(FIP_FL_FPMA); in fcoe_ctlr_send_keep_alive()
567 if (fip->spma) in fcoe_ctlr_send_keep_alive()
568 kal->fip.fip_flags |= htons(FIP_FL_SPMA); in fcoe_ctlr_send_keep_alive()
570 kal->mac.fd_desc.fip_dtype = FIP_DT_MAC; in fcoe_ctlr_send_keep_alive()
571 kal->mac.fd_desc.fip_dlen = sizeof(kal->mac) / FIP_BPW; in fcoe_ctlr_send_keep_alive()
572 memcpy(kal->mac.fd_mac, fip->ctl_src_addr, ETH_ALEN); in fcoe_ctlr_send_keep_alive()
575 vn->fd_desc.fip_dtype = FIP_DT_VN_ID; in fcoe_ctlr_send_keep_alive()
576 vn->fd_desc.fip_dlen = sizeof(*vn) / FIP_BPW; in fcoe_ctlr_send_keep_alive()
577 memcpy(vn->fd_mac, fip->get_src_addr(lport), ETH_ALEN); in fcoe_ctlr_send_keep_alive()
578 hton24(vn->fd_fc_id, lport->port_id); in fcoe_ctlr_send_keep_alive()
579 put_unaligned_be64(lport->wwpn, &vn->fd_wwpn); in fcoe_ctlr_send_keep_alive()
582 skb->protocol = htons(ETH_P_FIP); in fcoe_ctlr_send_keep_alive()
583 skb->priority = fip->priority; in fcoe_ctlr_send_keep_alive()
586 fip->send(fip, skb); in fcoe_ctlr_send_keep_alive()
590 * fcoe_ctlr_encaps() - Encapsulate an ELS frame for FIP, without sending it
591 * @fip: The FCoE controller for the ELS frame
593 * @dtype: The FIP descriptor type for the frame
594 * @skb: The FCoE ELS frame including FC header but no FCoE headers
597 * Returns non-zero error code on failure.
620 fh = (struct fc_frame_header *)skb->data; in fcoe_ctlr_encaps()
622 dlen = sizeof(struct fip_encaps) + skb->len; /* len before push */ in fcoe_ctlr_encaps()
626 if (lport->point_to_multipoint) { in fcoe_ctlr_encaps()
627 if (fcoe_ctlr_vn_lookup(fip, d_id, cap->eth.h_dest)) in fcoe_ctlr_encaps()
628 return -ENODEV; in fcoe_ctlr_encaps()
631 fcf = fip->sel_fcf; in fcoe_ctlr_encaps()
633 return -ENODEV; in fcoe_ctlr_encaps()
634 fip_flags = fcf->flags; in fcoe_ctlr_encaps()
635 fip_flags &= fip->spma ? FIP_FL_SPMA | FIP_FL_FPMA : in fcoe_ctlr_encaps()
638 return -ENODEV; in fcoe_ctlr_encaps()
639 memcpy(cap->eth.h_dest, fcf->fcf_mac, ETH_ALEN); in fcoe_ctlr_encaps()
641 memcpy(cap->eth.h_source, fip->ctl_src_addr, ETH_ALEN); in fcoe_ctlr_encaps()
642 cap->eth.h_proto = htons(ETH_P_FIP); in fcoe_ctlr_encaps()
644 cap->fip.fip_ver = FIP_VER_ENCAPS(FIP_VER); in fcoe_ctlr_encaps()
645 cap->fip.fip_op = htons(FIP_OP_LS); in fcoe_ctlr_encaps()
647 cap->fip.fip_subcode = FIP_SC_REP; in fcoe_ctlr_encaps()
649 cap->fip.fip_subcode = FIP_SC_REQ; in fcoe_ctlr_encaps()
650 cap->fip.fip_flags = htons(fip_flags); in fcoe_ctlr_encaps()
652 cap->encaps.fd_desc.fip_dtype = dtype; in fcoe_ctlr_encaps()
653 cap->encaps.fd_desc.fip_dlen = dlen / FIP_BPW; in fcoe_ctlr_encaps()
658 mac->fd_desc.fip_dtype = FIP_DT_MAC; in fcoe_ctlr_encaps()
659 mac->fd_desc.fip_dlen = sizeof(*mac) / FIP_BPW; in fcoe_ctlr_encaps()
661 memcpy(mac->fd_mac, fip->get_src_addr(lport), ETH_ALEN); in fcoe_ctlr_encaps()
662 } else if (fip->mode == FIP_MODE_VN2VN) { in fcoe_ctlr_encaps()
663 hton24(mac->fd_mac, FIP_VN_FC_MAP); in fcoe_ctlr_encaps()
664 hton24(mac->fd_mac + 3, fip->port_id); in fcoe_ctlr_encaps()
667 memcpy(mac->fd_mac, fip->ctl_src_addr, ETH_ALEN); in fcoe_ctlr_encaps()
673 cap->fip.fip_dl_len = htons(dlen / FIP_BPW); in fcoe_ctlr_encaps()
675 skb->protocol = htons(ETH_P_FIP); in fcoe_ctlr_encaps()
676 skb->priority = fip->priority; in fcoe_ctlr_encaps()
683 * fcoe_ctlr_els_send() - Send an ELS frame encapsulated by FIP if appropriate.
686 * @skb: FCoE ELS frame including FC header but no FCoE headers.
688 * Returns a non-zero error code if the frame should not be sent.
689 * Returns zero if the caller should send the frame with FCoE encapsulation.
695 * This is called from the lower-level driver with spinlocks held,
709 fh = (struct fc_frame_header *)skb->data; in fcoe_ctlr_els_send()
712 if (op == ELS_FLOGI && fip->mode != FIP_MODE_VN2VN) { in fcoe_ctlr_els_send()
713 old_xid = fip->flogi_oxid; in fcoe_ctlr_els_send()
714 fip->flogi_oxid = ntohs(fh->fh_ox_id); in fcoe_ctlr_els_send()
715 if (fip->state == FIP_ST_AUTO) { in fcoe_ctlr_els_send()
717 fip->flogi_count = 0; in fcoe_ctlr_els_send()
718 fip->flogi_count++; in fcoe_ctlr_els_send()
719 if (fip->flogi_count < 3) in fcoe_ctlr_els_send()
724 if (fip->state == FIP_ST_NON_FIP) in fcoe_ctlr_els_send()
728 if (fip->state == FIP_ST_NON_FIP) in fcoe_ctlr_els_send()
730 if (!fip->sel_fcf && fip->mode != FIP_MODE_VN2VN) in fcoe_ctlr_els_send()
735 if (fip->mode == FIP_MODE_VN2VN) in fcoe_ctlr_els_send()
737 spin_lock_irqsave(&fip->ctlr_lock, flags); in fcoe_ctlr_els_send()
738 kfree_skb(fip->flogi_req); in fcoe_ctlr_els_send()
739 fip->flogi_req = skb; in fcoe_ctlr_els_send()
740 fip->flogi_req_send = 1; in fcoe_ctlr_els_send()
741 spin_unlock_irqrestore(&fip->ctlr_lock, flags); in fcoe_ctlr_els_send()
742 schedule_work(&fip->timer_work); in fcoe_ctlr_els_send()
743 return -EINPROGRESS; in fcoe_ctlr_els_send()
745 if (ntoh24(fh->fh_s_id)) in fcoe_ctlr_els_send()
750 if (fip->mode == FIP_MODE_VN2VN) { in fcoe_ctlr_els_send()
751 if (fip->state != FIP_ST_VNMP_UP) in fcoe_ctlr_els_send()
753 if (ntoh24(fh->fh_d_id) == FC_FID_FLOGI) in fcoe_ctlr_els_send()
756 if (fip->state != FIP_ST_ENABLED) in fcoe_ctlr_els_send()
758 if (ntoh24(fh->fh_d_id) != FC_FID_FLOGI) in fcoe_ctlr_els_send()
765 * If non-FIP, we may have gotten an SID by accepting an FLOGI in fcoe_ctlr_els_send()
766 * from a point-to-point connection. Switch to using in fcoe_ctlr_els_send()
771 if (fip->state == FIP_ST_NON_FIP) { in fcoe_ctlr_els_send()
772 if (fip->flogi_oxid == FC_XID_UNKNOWN) in fcoe_ctlr_els_send()
774 fip->flogi_oxid = FC_XID_UNKNOWN; in fcoe_ctlr_els_send()
775 fc_fcoe_set_mac(mac, fh->fh_d_id); in fcoe_ctlr_els_send()
776 fip->update_mac(lport, mac); in fcoe_ctlr_els_send()
785 if (fip->state != FIP_ST_ENABLED && in fcoe_ctlr_els_send()
786 fip->state != FIP_ST_VNMP_UP) in fcoe_ctlr_els_send()
791 op, ntoh24(fh->fh_d_id)); in fcoe_ctlr_els_send()
792 if (fcoe_ctlr_encaps(fip, lport, op, skb, ntoh24(fh->fh_d_id))) in fcoe_ctlr_els_send()
794 fip->send(fip, skb); in fcoe_ctlr_els_send()
795 return -EINPROGRESS; in fcoe_ctlr_els_send()
798 op, ntoh24(fh->fh_d_id)); in fcoe_ctlr_els_send()
800 return -EINVAL; in fcoe_ctlr_els_send()
805 * fcoe_ctlr_age_fcfs() - Reset and free all old FCFs for a controller
812 * times its keep-alive period.
817 * for the corresponding FCF for 1.5 * FKA_ADV_PERIOD (FC-BB-5 LESB).
833 stats = per_cpu_ptr(fip->lp->stats, get_cpu()); in fcoe_ctlr_age_fcfs()
835 list_for_each_entry_safe(fcf, next, &fip->fcfs, list) { in fcoe_ctlr_age_fcfs()
836 deadline = fcf->time + fcf->fka_period + fcf->fka_period / 2; in fcoe_ctlr_age_fcfs()
837 if (fip->sel_fcf == fcf) { in fcoe_ctlr_age_fcfs()
839 stats->MissDiscAdvCount++; in fcoe_ctlr_age_fcfs()
843 fip->lp->host->host_no, fcf->fabric_name, in fcoe_ctlr_age_fcfs()
844 stats->MissDiscAdvCount); in fcoe_ctlr_age_fcfs()
849 deadline += fcf->fka_period; in fcoe_ctlr_age_fcfs()
851 if (fip->sel_fcf == fcf) in fcoe_ctlr_age_fcfs()
852 fip->sel_fcf = NULL; in fcoe_ctlr_age_fcfs()
858 list_del(&fcf->list); in fcoe_ctlr_age_fcfs()
859 list_add(&fcf->list, &del_list); in fcoe_ctlr_age_fcfs()
860 stats->VLinkFailureCount++; in fcoe_ctlr_age_fcfs()
865 (!sel_time || time_before(sel_time, fcf->time))) in fcoe_ctlr_age_fcfs()
866 sel_time = fcf->time; in fcoe_ctlr_age_fcfs()
876 if (sel_time && !fip->sel_fcf && !fip->sel_time) { in fcoe_ctlr_age_fcfs()
878 fip->sel_time = sel_time; in fcoe_ctlr_age_fcfs()
885 * fcoe_ctlr_parse_adv() - Decode a FIP advertisement into a new FCF entry
887 * @skb: The received FIP advertisement frame
907 fcf->fka_period = msecs_to_jiffies(FCOE_CTLR_DEF_FKA); in fcoe_ctlr_parse_adv()
909 fiph = (struct fip_header *)skb->data; in fcoe_ctlr_parse_adv()
910 fcf->flags = ntohs(fiph->fip_flags); in fcoe_ctlr_parse_adv()
918 rlen = ntohs(fiph->fip_dl_len) * 4; in fcoe_ctlr_parse_adv()
919 if (rlen + sizeof(*fiph) > skb->len) in fcoe_ctlr_parse_adv()
920 return -EINVAL; in fcoe_ctlr_parse_adv()
924 dlen = desc->fip_dlen * FIP_BPW; in fcoe_ctlr_parse_adv()
926 return -EINVAL; in fcoe_ctlr_parse_adv()
928 if ((desc->fip_dtype < 32) && in fcoe_ctlr_parse_adv()
929 !(desc_mask & 1U << desc->fip_dtype)) { in fcoe_ctlr_parse_adv()
932 return -EINVAL; in fcoe_ctlr_parse_adv()
934 switch (desc->fip_dtype) { in fcoe_ctlr_parse_adv()
938 fcf->pri = ((struct fip_pri_desc *)desc)->fd_pri; in fcoe_ctlr_parse_adv()
944 memcpy(fcf->fcf_mac, in fcoe_ctlr_parse_adv()
945 ((struct fip_mac_desc *)desc)->fd_mac, in fcoe_ctlr_parse_adv()
947 memcpy(fcf->fcoe_mac, fcf->fcf_mac, ETH_ALEN); in fcoe_ctlr_parse_adv()
948 if (!is_valid_ether_addr(fcf->fcf_mac)) { in fcoe_ctlr_parse_adv()
951 fcf->fcf_mac); in fcoe_ctlr_parse_adv()
952 return -EINVAL; in fcoe_ctlr_parse_adv()
960 fcf->switch_name = get_unaligned_be64(&wwn->fd_wwn); in fcoe_ctlr_parse_adv()
967 fcf->fabric_name = get_unaligned_be64(&fab->fd_wwn); in fcoe_ctlr_parse_adv()
968 fcf->vfid = ntohs(fab->fd_vfid); in fcoe_ctlr_parse_adv()
969 fcf->fc_map = ntoh24(fab->fd_map); in fcoe_ctlr_parse_adv()
976 if (fka->fd_flags & FIP_FKA_ADV_D) in fcoe_ctlr_parse_adv()
977 fcf->fd_flags = 1; in fcoe_ctlr_parse_adv()
978 t = ntohl(fka->fd_fka_period); in fcoe_ctlr_parse_adv()
980 fcf->fka_period = msecs_to_jiffies(t); in fcoe_ctlr_parse_adv()
991 "in FIP adv\n", desc->fip_dtype); in fcoe_ctlr_parse_adv()
993 if (desc->fip_dtype < FIP_DT_NON_CRITICAL) in fcoe_ctlr_parse_adv()
994 return -EINVAL; in fcoe_ctlr_parse_adv()
998 rlen -= dlen; in fcoe_ctlr_parse_adv()
1000 if (!fcf->fc_map || (fcf->fc_map & 0x10000)) in fcoe_ctlr_parse_adv()
1001 return -EINVAL; in fcoe_ctlr_parse_adv()
1002 if (!fcf->switch_name) in fcoe_ctlr_parse_adv()
1003 return -EINVAL; in fcoe_ctlr_parse_adv()
1007 return -EINVAL; in fcoe_ctlr_parse_adv()
1013 desc->fip_dtype, dlen); in fcoe_ctlr_parse_adv()
1014 return -EINVAL; in fcoe_ctlr_parse_adv()
1018 * fcoe_ctlr_recv_adv() - Handle an incoming advertisement
1035 mutex_lock(&fip->ctlr_mutex); in fcoe_ctlr_recv_adv()
1036 first = list_empty(&fip->fcfs); in fcoe_ctlr_recv_adv()
1037 list_for_each_entry(fcf, &fip->fcfs, list) { in fcoe_ctlr_recv_adv()
1038 if (fcf->switch_name == new.switch_name && in fcoe_ctlr_recv_adv()
1039 fcf->fabric_name == new.fabric_name && in fcoe_ctlr_recv_adv()
1040 fcf->fc_map == new.fc_map && in fcoe_ctlr_recv_adv()
1041 ether_addr_equal(fcf->fcf_mac, new.fcf_mac)) { in fcoe_ctlr_recv_adv()
1047 if (fip->fcf_count >= FCOE_CTLR_FCF_LIMIT) in fcoe_ctlr_recv_adv()
1055 fcf->fip = fip; in fcoe_ctlr_recv_adv()
1066 * Update the FCF's keep-alive descriptor flags. in fcoe_ctlr_recv_adv()
1071 fcf->fd_flags = new.fd_flags; in fcoe_ctlr_recv_adv()
1073 fcf->flags = new.flags; in fcoe_ctlr_recv_adv()
1075 if (fcf == fip->sel_fcf && !fcf->fd_flags) { in fcoe_ctlr_recv_adv()
1076 fip->ctlr_ka_time -= fcf->fka_period; in fcoe_ctlr_recv_adv()
1077 fip->ctlr_ka_time += new.fka_period; in fcoe_ctlr_recv_adv()
1078 if (time_before(fip->ctlr_ka_time, fip->timer.expires)) in fcoe_ctlr_recv_adv()
1079 mod_timer(&fip->timer, fip->ctlr_ka_time); in fcoe_ctlr_recv_adv()
1081 fcf->fka_period = new.fka_period; in fcoe_ctlr_recv_adv()
1082 memcpy(fcf->fcf_mac, new.fcf_mac, ETH_ALEN); in fcoe_ctlr_recv_adv()
1086 fcf->time = jiffies; in fcoe_ctlr_recv_adv()
1089 fcf->fabric_name, fcf->fcf_mac); in fcoe_ctlr_recv_adv()
1104 if (first && time_after(jiffies, fip->sol_time + sol_tov)) in fcoe_ctlr_recv_adv()
1114 list_move(&fcf->list, &fip->fcfs); in fcoe_ctlr_recv_adv()
1120 if (mtu_valid && !fip->sel_fcf && !fip->sel_time && in fcoe_ctlr_recv_adv()
1122 fip->sel_time = jiffies + in fcoe_ctlr_recv_adv()
1124 if (!timer_pending(&fip->timer) || in fcoe_ctlr_recv_adv()
1125 time_before(fip->sel_time, fip->timer.expires)) in fcoe_ctlr_recv_adv()
1126 mod_timer(&fip->timer, fip->sel_time); in fcoe_ctlr_recv_adv()
1130 mutex_unlock(&fip->ctlr_mutex); in fcoe_ctlr_recv_adv()
1134 * fcoe_ctlr_recv_els() - Handle an incoming FIP encapsulated ELS frame
1140 struct fc_lport *lport = fip->lp; in fcoe_ctlr_recv_els()
1150 u8 sub; in fcoe_ctlr_recv_els() local
1158 fiph = (struct fip_header *)skb->data; in fcoe_ctlr_recv_els()
1159 sub = fiph->fip_subcode; in fcoe_ctlr_recv_els()
1160 if (sub != FIP_SC_REQ && sub != FIP_SC_REP) in fcoe_ctlr_recv_els()
1163 rlen = ntohs(fiph->fip_dl_len) * 4; in fcoe_ctlr_recv_els()
1164 if (rlen + sizeof(*fiph) > skb->len) in fcoe_ctlr_recv_els()
1170 dlen = desc->fip_dlen * FIP_BPW; in fcoe_ctlr_recv_els()
1174 if (desc->fip_dtype < 32) { in fcoe_ctlr_recv_els()
1175 if ((desc->fip_dtype != FIP_DT_MAC) && in fcoe_ctlr_recv_els()
1176 (desc_mask & 1U << desc->fip_dtype)) { in fcoe_ctlr_recv_els()
1181 desc_mask |= (1 << desc->fip_dtype); in fcoe_ctlr_recv_els()
1183 switch (desc->fip_dtype) { in fcoe_ctlr_recv_els()
1185 sel = fip->sel_fcf; in fcoe_ctlr_recv_els()
1201 ((struct fip_mac_desc *)desc)->fd_mac, in fcoe_ctlr_recv_els()
1208 memcpy(sel->fcoe_mac, in fcoe_ctlr_recv_els()
1209 ((struct fip_mac_desc *)desc)->fd_mac, in fcoe_ctlr_recv_els()
1225 els_len = dlen - sizeof(*els); in fcoe_ctlr_recv_els()
1228 els_dtype = desc->fip_dtype; in fcoe_ctlr_recv_els()
1232 "in FIP adv\n", desc->fip_dtype); in fcoe_ctlr_recv_els()
1234 if (desc->fip_dtype < FIP_DT_NON_CRITICAL) in fcoe_ctlr_recv_els()
1244 rlen -= dlen; in fcoe_ctlr_recv_els()
1252 sub == FIP_SC_REP && fip->mode != FIP_MODE_VN2VN) { in fcoe_ctlr_recv_els()
1260 memcpy(fr_cb(fp)->granted_mac, granted_mac, ETH_ALEN); in fcoe_ctlr_recv_els()
1262 if (fip->flogi_oxid == ntohs(fh->fh_ox_id)) { in fcoe_ctlr_recv_els()
1263 fip->flogi_oxid = FC_XID_UNKNOWN; in fcoe_ctlr_recv_els()
1282 skb_pull(skb, (u8 *)fh - skb->data); in fcoe_ctlr_recv_els()
1291 stats = per_cpu_ptr(lport->stats, get_cpu()); in fcoe_ctlr_recv_els()
1292 stats->RxFrames++; in fcoe_ctlr_recv_els()
1293 stats->RxWords += skb->len / FIP_BPW; in fcoe_ctlr_recv_els()
1301 desc->fip_dtype, dlen); in fcoe_ctlr_recv_els()
1307 * fcoe_ctlr_recv_els() - Handle an incoming link reset frame
1308 * @fip: The FCoE controller that received the frame
1323 struct fcoe_fcf *fcf = fip->sel_fcf; in fcoe_ctlr_recv_clr_vlink()
1324 struct fc_lport *lport = fip->lp; in fcoe_ctlr_recv_clr_vlink()
1330 struct fip_header *fh = (struct fip_header *)skb->data; in fcoe_ctlr_recv_clr_vlink()
1342 mutex_lock(&fip->ctlr_mutex); in fcoe_ctlr_recv_clr_vlink()
1344 mutex_unlock(&fip->ctlr_mutex); in fcoe_ctlr_recv_clr_vlink()
1353 if (!ether_addr_equal(eh->h_source, fcf->fcf_mac)) { in fcoe_ctlr_recv_clr_vlink()
1355 "mismatch with FCF src=%pM\n", eh->h_source); in fcoe_ctlr_recv_clr_vlink()
1363 if (!lport->port_id) { in fcoe_ctlr_recv_clr_vlink()
1365 mutex_lock(&fip->ctlr_mutex); in fcoe_ctlr_recv_clr_vlink()
1367 mutex_unlock(&fip->ctlr_mutex); in fcoe_ctlr_recv_clr_vlink()
1368 fc_lport_reset(fip->lp); in fcoe_ctlr_recv_clr_vlink()
1378 rlen = ntohs(fh->fip_dl_len) * FIP_BPW; in fcoe_ctlr_recv_clr_vlink()
1382 * Actually need to subtract 'sizeof(*mp) - sizeof(*wp)' from 'rlen' in fcoe_ctlr_recv_clr_vlink()
1395 dlen = desc->fip_dlen * FIP_BPW; in fcoe_ctlr_recv_clr_vlink()
1399 if ((desc->fip_dtype < 32) && in fcoe_ctlr_recv_clr_vlink()
1400 (desc->fip_dtype != FIP_DT_VN_ID) && in fcoe_ctlr_recv_clr_vlink()
1401 !(desc_mask & 1U << desc->fip_dtype)) { in fcoe_ctlr_recv_clr_vlink()
1406 switch (desc->fip_dtype) { in fcoe_ctlr_recv_clr_vlink()
1411 if (!ether_addr_equal(mp->fd_mac, fcf->fcf_mac)) in fcoe_ctlr_recv_clr_vlink()
1419 if (get_unaligned_be64(&wp->fd_wwn) != fcf->switch_name) in fcoe_ctlr_recv_clr_vlink()
1429 ntoh24(vp->fd_fc_id)); in fcoe_ctlr_recv_clr_vlink()
1431 mutex_lock(&fip->ctlr_mutex); in fcoe_ctlr_recv_clr_vlink()
1432 per_cpu_ptr(lport->stats, in fcoe_ctlr_recv_clr_vlink()
1433 get_cpu())->VLinkFailureCount++; in fcoe_ctlr_recv_clr_vlink()
1436 mutex_unlock(&fip->ctlr_mutex); in fcoe_ctlr_recv_clr_vlink()
1441 if (desc->fip_dtype < FIP_DT_NON_CRITICAL) in fcoe_ctlr_recv_clr_vlink()
1446 rlen -= dlen; in fcoe_ctlr_recv_clr_vlink()
1461 mutex_lock(&fip->ctlr_mutex); in fcoe_ctlr_recv_clr_vlink()
1462 per_cpu_ptr(lport->stats, get_cpu())->VLinkFailureCount++; in fcoe_ctlr_recv_clr_vlink()
1465 mutex_unlock(&fip->ctlr_mutex); in fcoe_ctlr_recv_clr_vlink()
1467 mutex_lock(&lport->lp_mutex); in fcoe_ctlr_recv_clr_vlink()
1468 list_for_each_entry(vn_port, &lport->vports, list) in fcoe_ctlr_recv_clr_vlink()
1470 mutex_unlock(&lport->lp_mutex); in fcoe_ctlr_recv_clr_vlink()
1472 fc_lport_reset(fip->lp); in fcoe_ctlr_recv_clr_vlink()
1481 ntoh24(vp->fd_fc_id)); in fcoe_ctlr_recv_clr_vlink()
1489 if (!ether_addr_equal(fip->get_src_addr(vn_port), in fcoe_ctlr_recv_clr_vlink()
1490 vp->fd_mac) || in fcoe_ctlr_recv_clr_vlink()
1491 get_unaligned_be64(&vp->fd_wwpn) != in fcoe_ctlr_recv_clr_vlink()
1492 vn_port->wwpn) in fcoe_ctlr_recv_clr_vlink()
1506 fc_lport_reset(fip->lp); in fcoe_ctlr_recv_clr_vlink()
1516 * fcoe_ctlr_recv() - Receive a FIP packet
1527 skb_queue_tail(&fip->fip_recv_list, skb); in fcoe_ctlr_recv()
1528 schedule_work(&fip->recv_work); in fcoe_ctlr_recv()
1533 * fcoe_ctlr_recv_handler() - Receive a FIP frame
1534 * @fip: The FCoE controller that received the frame
1535 * @skb: The received FIP frame
1537 * Returns non-zero if the frame is dropped.
1546 u8 sub; in fcoe_ctlr_recv_handler() local
1550 if (skb->len < sizeof(*fiph)) in fcoe_ctlr_recv_handler()
1553 if (fip->mode == FIP_MODE_VN2VN) { in fcoe_ctlr_recv_handler()
1554 if (!ether_addr_equal(eh->h_dest, fip->ctl_src_addr) && in fcoe_ctlr_recv_handler()
1555 !ether_addr_equal(eh->h_dest, fcoe_all_vn2vn) && in fcoe_ctlr_recv_handler()
1556 !ether_addr_equal(eh->h_dest, fcoe_all_p2p)) in fcoe_ctlr_recv_handler()
1558 } else if (!ether_addr_equal(eh->h_dest, fip->ctl_src_addr) && in fcoe_ctlr_recv_handler()
1559 !ether_addr_equal(eh->h_dest, fcoe_all_enode)) in fcoe_ctlr_recv_handler()
1561 fiph = (struct fip_header *)skb->data; in fcoe_ctlr_recv_handler()
1562 op = ntohs(fiph->fip_op); in fcoe_ctlr_recv_handler()
1563 sub = fiph->fip_subcode; in fcoe_ctlr_recv_handler()
1565 if (FIP_VER_DECAPS(fiph->fip_ver) != FIP_VER) in fcoe_ctlr_recv_handler()
1567 if (ntohs(fiph->fip_dl_len) * FIP_BPW + sizeof(*fiph) > skb->len) in fcoe_ctlr_recv_handler()
1570 mutex_lock(&fip->ctlr_mutex); in fcoe_ctlr_recv_handler()
1571 state = fip->state; in fcoe_ctlr_recv_handler()
1573 fip->map_dest = 0; in fcoe_ctlr_recv_handler()
1578 fip_vlan_resp = fip->fip_resp; in fcoe_ctlr_recv_handler()
1579 mutex_unlock(&fip->ctlr_mutex); in fcoe_ctlr_recv_handler()
1581 if (fip->mode == FIP_MODE_VN2VN && op == FIP_OP_VN2VN) in fcoe_ctlr_recv_handler()
1601 if (op == FIP_OP_DISC && sub == FIP_SC_ADV) in fcoe_ctlr_recv_handler()
1603 else if (op == FIP_OP_CTRL && sub == FIP_SC_CLR_VLINK) in fcoe_ctlr_recv_handler()
1609 return -1; in fcoe_ctlr_recv_handler()
1613 * fcoe_ctlr_select() - Select the best FCF (if possible)
1628 struct fcoe_fcf *best = fip->sel_fcf; in fcoe_ctlr_select()
1630 list_for_each_entry(fcf, &fip->fcfs, list) { in fcoe_ctlr_select()
1634 fcf->fabric_name, fcf->vfid, fcf->fcf_mac, in fcoe_ctlr_select()
1635 fcf->fc_map, fcoe_ctlr_mtu_valid(fcf), in fcoe_ctlr_select()
1636 fcf->flogi_sent, fcf->pri); in fcoe_ctlr_select()
1640 fcf->fabric_name, fcf->fc_map, in fcoe_ctlr_select()
1641 (fcf->flags & FIP_FL_SOL) ? "" : "in", in fcoe_ctlr_select()
1642 (fcf->flags & FIP_FL_AVAIL) ? in fcoe_ctlr_select()
1646 if (!best || fcf->pri < best->pri || best->flogi_sent) in fcoe_ctlr_select()
1648 if (fcf->fabric_name != best->fabric_name || in fcoe_ctlr_select()
1649 fcf->vfid != best->vfid || in fcoe_ctlr_select()
1650 fcf->fc_map != best->fc_map) { in fcoe_ctlr_select()
1652 "or FC-MAP\n"); in fcoe_ctlr_select()
1656 fip->sel_fcf = best; in fcoe_ctlr_select()
1658 LIBFCOE_FIP_DBG(fip, "using FCF mac %pM\n", best->fcf_mac); in fcoe_ctlr_select()
1659 fip->port_ka_time = jiffies + in fcoe_ctlr_select()
1661 fip->ctlr_ka_time = jiffies + best->fka_period; in fcoe_ctlr_select()
1662 if (time_before(fip->ctlr_ka_time, fip->timer.expires)) in fcoe_ctlr_select()
1663 mod_timer(&fip->timer, fip->ctlr_ka_time); in fcoe_ctlr_select()
1669 * fcoe_ctlr_flogi_send_locked() - send FIP-encapsulated FLOGI to current FCF
1672 * Returns non-zero error if it could not be sent.
1675 * Caller must verify that fip->sel_fcf is not NULL.
1684 skb_orig = fip->flogi_req; in fcoe_ctlr_flogi_send_locked()
1686 return -EINVAL; in fcoe_ctlr_flogi_send_locked()
1694 fip->flogi_req = NULL; in fcoe_ctlr_flogi_send_locked()
1696 fh = (struct fc_frame_header *)skb->data; in fcoe_ctlr_flogi_send_locked()
1697 error = fcoe_ctlr_encaps(fip, fip->lp, FIP_DT_FLOGI, skb, in fcoe_ctlr_flogi_send_locked()
1698 ntoh24(fh->fh_d_id)); in fcoe_ctlr_flogi_send_locked()
1703 fip->send(fip, skb); in fcoe_ctlr_flogi_send_locked()
1704 fip->sel_fcf->flogi_sent = 1; in fcoe_ctlr_flogi_send_locked()
1709 * fcoe_ctlr_flogi_retry() - resend FLOGI request to a new FCF if possible
1712 * Returns non-zero error code if there's no FLOGI request to retry or
1721 mutex_lock(&fip->ctlr_mutex); in fcoe_ctlr_flogi_retry()
1722 spin_lock_irqsave(&fip->ctlr_lock, flags); in fcoe_ctlr_flogi_retry()
1723 LIBFCOE_FIP_DBG(fip, "re-sending FLOGI - reselect\n"); in fcoe_ctlr_flogi_retry()
1725 if (!fcf || fcf->flogi_sent) { in fcoe_ctlr_flogi_retry()
1726 kfree_skb(fip->flogi_req); in fcoe_ctlr_flogi_retry()
1727 fip->flogi_req = NULL; in fcoe_ctlr_flogi_retry()
1728 error = -ENOENT; in fcoe_ctlr_flogi_retry()
1733 spin_unlock_irqrestore(&fip->ctlr_lock, flags); in fcoe_ctlr_flogi_retry()
1734 mutex_unlock(&fip->ctlr_mutex); in fcoe_ctlr_flogi_retry()
1740 * fcoe_ctlr_flogi_send() - Handle sending of FIP FLOGI.
1752 spin_lock_irqsave(&fip->ctlr_lock, flags); in fcoe_ctlr_flogi_send()
1753 fcf = fip->sel_fcf; in fcoe_ctlr_flogi_send()
1754 if (!fcf || !fip->flogi_req_send) in fcoe_ctlr_flogi_send()
1763 if (fcf->flogi_sent) { in fcoe_ctlr_flogi_send()
1764 LIBFCOE_FIP_DBG(fip, "sending FLOGI - reselect\n"); in fcoe_ctlr_flogi_send()
1766 if (!fcf || fcf->flogi_sent) { in fcoe_ctlr_flogi_send()
1767 LIBFCOE_FIP_DBG(fip, "sending FLOGI - clearing\n"); in fcoe_ctlr_flogi_send()
1768 list_for_each_entry(fcf, &fip->fcfs, list) in fcoe_ctlr_flogi_send()
1769 fcf->flogi_sent = 0; in fcoe_ctlr_flogi_send()
1775 fip->flogi_req_send = 0; in fcoe_ctlr_flogi_send()
1777 LIBFCOE_FIP_DBG(fip, "No FCF selected - defer send\n"); in fcoe_ctlr_flogi_send()
1779 spin_unlock_irqrestore(&fip->ctlr_lock, flags); in fcoe_ctlr_flogi_send()
1783 * fcoe_ctlr_timeout() - FIP timeout handler
1790 schedule_work(&fip->timer_work); in fcoe_ctlr_timeout()
1794 * fcoe_ctlr_timer_work() - Worker thread function for timer work
1798 * Sends keep-alives and resets.
1813 if (fip->mode == FIP_MODE_VN2VN) in fcoe_ctlr_timer_work()
1815 mutex_lock(&fip->ctlr_mutex); in fcoe_ctlr_timer_work()
1816 if (fip->state == FIP_ST_DISABLED) { in fcoe_ctlr_timer_work()
1817 mutex_unlock(&fip->ctlr_mutex); in fcoe_ctlr_timer_work()
1821 fcf = fip->sel_fcf; in fcoe_ctlr_timer_work()
1824 sel = fip->sel_fcf; in fcoe_ctlr_timer_work()
1825 if (!sel && fip->sel_time) { in fcoe_ctlr_timer_work()
1826 if (time_after_eq(jiffies, fip->sel_time)) { in fcoe_ctlr_timer_work()
1828 fip->sel_time = 0; in fcoe_ctlr_timer_work()
1829 } else if (time_after(next_timer, fip->sel_time)) in fcoe_ctlr_timer_work()
1830 next_timer = fip->sel_time; in fcoe_ctlr_timer_work()
1833 if (sel && fip->flogi_req_send) in fcoe_ctlr_timer_work()
1838 if (sel && !sel->fd_flags) { in fcoe_ctlr_timer_work()
1839 if (time_after_eq(jiffies, fip->ctlr_ka_time)) { in fcoe_ctlr_timer_work()
1840 fip->ctlr_ka_time = jiffies + sel->fka_period; in fcoe_ctlr_timer_work()
1843 if (time_after(next_timer, fip->ctlr_ka_time)) in fcoe_ctlr_timer_work()
1844 next_timer = fip->ctlr_ka_time; in fcoe_ctlr_timer_work()
1846 if (time_after_eq(jiffies, fip->port_ka_time)) { in fcoe_ctlr_timer_work()
1847 fip->port_ka_time = jiffies + in fcoe_ctlr_timer_work()
1851 if (time_after(next_timer, fip->port_ka_time)) in fcoe_ctlr_timer_work()
1852 next_timer = fip->port_ka_time; in fcoe_ctlr_timer_work()
1854 if (!list_empty(&fip->fcfs)) in fcoe_ctlr_timer_work()
1855 mod_timer(&fip->timer, next_timer); in fcoe_ctlr_timer_work()
1856 mutex_unlock(&fip->ctlr_mutex); in fcoe_ctlr_timer_work()
1859 fc_lport_reset(fip->lp); in fcoe_ctlr_timer_work()
1865 fcoe_ctlr_send_keep_alive(fip, NULL, 0, fip->ctl_src_addr); in fcoe_ctlr_timer_work()
1868 mutex_lock(&fip->lp->lp_mutex); in fcoe_ctlr_timer_work()
1869 mac = fip->get_src_addr(fip->lp); in fcoe_ctlr_timer_work()
1870 fcoe_ctlr_send_keep_alive(fip, fip->lp, 1, mac); in fcoe_ctlr_timer_work()
1871 list_for_each_entry(vport, &fip->lp->vports, list) { in fcoe_ctlr_timer_work()
1872 mac = fip->get_src_addr(vport); in fcoe_ctlr_timer_work()
1875 mutex_unlock(&fip->lp->lp_mutex); in fcoe_ctlr_timer_work()
1880 * fcoe_ctlr_recv_work() - Worker thread function for receiving FIP frames
1889 while ((skb = skb_dequeue(&fip->fip_recv_list))) in fcoe_ctlr_recv_work()
1894 * fcoe_ctlr_recv_flogi() - Snoop pre-FIP receipt of FLOGI response
1897 * @fp: The FC frame to snoop
1902 * by fip->flogi_oxid != FC_XID_UNKNOWN.
1904 * The caller is responsible for freeing the frame.
1907 * Return non-zero if the frame should not be delivered to libfc.
1916 sa = eth_hdr(&fp->skb)->h_source; in fcoe_ctlr_recv_flogi()
1918 if (fh->fh_type != FC_TYPE_ELS) in fcoe_ctlr_recv_flogi()
1922 if (op == ELS_LS_ACC && fh->fh_r_ctl == FC_RCTL_ELS_REP && in fcoe_ctlr_recv_flogi()
1923 fip->flogi_oxid == ntohs(fh->fh_ox_id)) { in fcoe_ctlr_recv_flogi()
1925 mutex_lock(&fip->ctlr_mutex); in fcoe_ctlr_recv_flogi()
1926 if (fip->state != FIP_ST_AUTO && fip->state != FIP_ST_NON_FIP) { in fcoe_ctlr_recv_flogi()
1927 mutex_unlock(&fip->ctlr_mutex); in fcoe_ctlr_recv_flogi()
1928 return -EINVAL; in fcoe_ctlr_recv_flogi()
1932 "received FLOGI LS_ACC using non-FIP mode\n"); in fcoe_ctlr_recv_flogi()
1936 * If the src mac addr is FC_OUI-based, then we mark the in fcoe_ctlr_recv_flogi()
1937 * address_mode flag to use FC_OUI-based Ethernet DA. 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()
1946 fip->flogi_oxid = FC_XID_UNKNOWN; in fcoe_ctlr_recv_flogi()
1947 mutex_unlock(&fip->ctlr_mutex); in fcoe_ctlr_recv_flogi()
1948 fc_fcoe_set_mac(fr_cb(fp)->granted_mac, fh->fh_d_id); in fcoe_ctlr_recv_flogi()
1949 } else if (op == ELS_FLOGI && fh->fh_r_ctl == FC_RCTL_ELS_REQ && sa) { in fcoe_ctlr_recv_flogi()
1951 * Save source MAC for point-to-point responses. in fcoe_ctlr_recv_flogi()
1953 mutex_lock(&fip->ctlr_mutex); in fcoe_ctlr_recv_flogi()
1954 if (fip->state == FIP_ST_AUTO || fip->state == FIP_ST_NON_FIP) { in fcoe_ctlr_recv_flogi()
1955 memcpy(fip->dest_addr, sa, ETH_ALEN); in fcoe_ctlr_recv_flogi()
1956 fip->map_dest = 0; in fcoe_ctlr_recv_flogi()
1957 if (fip->state == FIP_ST_AUTO) in fcoe_ctlr_recv_flogi()
1958 LIBFCOE_FIP_DBG(fip, "received non-FIP FLOGI. " in fcoe_ctlr_recv_flogi()
1959 "Setting non-FIP mode\n"); in fcoe_ctlr_recv_flogi()
1962 mutex_unlock(&fip->ctlr_mutex); in fcoe_ctlr_recv_flogi()
1969 * fcoe_wwn_from_mac() - Converts a 48-bit IEEE MAC address to a 64-bit FC WWN
2010 * fcoe_ctlr_rport() - return the fcoe_rport for a given fc_rport_priv
2019 * fcoe_ctlr_vn_send() - Send a FIP VN2VN Probe Request or Reply.
2021 * @sub: sub-opcode for probe request, reply, or advertisement.
2026 enum fip_vn2vn_subcode sub, in fcoe_ctlr_vn_send() argument
2036 } __packed * frame; in fcoe_ctlr_vn_send() local
2043 len = sizeof(*frame); in fcoe_ctlr_vn_send()
2045 if (sub == FIP_SC_VN_CLAIM_NOTIFY || sub == FIP_SC_VN_CLAIM_REP) { in fcoe_ctlr_vn_send()
2050 dlen += sizeof(frame->mac) + sizeof(frame->wwnn) + sizeof(frame->vn); in fcoe_ctlr_vn_send()
2057 frame = (struct fip_vn2vn_probe_frame *)skb->data; in fcoe_ctlr_vn_send()
2058 memset(frame, 0, len); in fcoe_ctlr_vn_send()
2059 memcpy(frame->eth.h_dest, dest, ETH_ALEN); in fcoe_ctlr_vn_send()
2061 if (sub == FIP_SC_VN_BEACON) { in fcoe_ctlr_vn_send()
2062 hton24(frame->eth.h_source, FIP_VN_FC_MAP); in fcoe_ctlr_vn_send()
2063 hton24(frame->eth.h_source + 3, fip->port_id); in fcoe_ctlr_vn_send()
2065 memcpy(frame->eth.h_source, fip->ctl_src_addr, ETH_ALEN); in fcoe_ctlr_vn_send()
2067 frame->eth.h_proto = htons(ETH_P_FIP); in fcoe_ctlr_vn_send()
2069 frame->fip.fip_ver = FIP_VER_ENCAPS(FIP_VER); in fcoe_ctlr_vn_send()
2070 frame->fip.fip_op = htons(FIP_OP_VN2VN); in fcoe_ctlr_vn_send()
2071 frame->fip.fip_subcode = sub; in fcoe_ctlr_vn_send()
2072 frame->fip.fip_dl_len = htons(dlen / FIP_BPW); in fcoe_ctlr_vn_send()
2074 frame->mac.fd_desc.fip_dtype = FIP_DT_MAC; in fcoe_ctlr_vn_send()
2075 frame->mac.fd_desc.fip_dlen = sizeof(frame->mac) / FIP_BPW; in fcoe_ctlr_vn_send()
2076 memcpy(frame->mac.fd_mac, fip->ctl_src_addr, ETH_ALEN); in fcoe_ctlr_vn_send()
2078 frame->wwnn.fd_desc.fip_dtype = FIP_DT_NAME; in fcoe_ctlr_vn_send()
2079 frame->wwnn.fd_desc.fip_dlen = sizeof(frame->wwnn) / FIP_BPW; in fcoe_ctlr_vn_send()
2080 put_unaligned_be64(fip->lp->wwnn, &frame->wwnn.fd_wwn); in fcoe_ctlr_vn_send()
2082 frame->vn.fd_desc.fip_dtype = FIP_DT_VN_ID; in fcoe_ctlr_vn_send()
2083 frame->vn.fd_desc.fip_dlen = sizeof(frame->vn) / FIP_BPW; in fcoe_ctlr_vn_send()
2084 hton24(frame->vn.fd_mac, FIP_VN_FC_MAP); in fcoe_ctlr_vn_send()
2085 hton24(frame->vn.fd_mac + 3, fip->port_id); in fcoe_ctlr_vn_send()
2086 hton24(frame->vn.fd_fc_id, fip->port_id); in fcoe_ctlr_vn_send()
2087 put_unaligned_be64(fip->lp->wwpn, &frame->vn.fd_wwpn); in fcoe_ctlr_vn_send()
2090 * For claims, add FC-4 features. in fcoe_ctlr_vn_send()
2091 * TBD: Add interface to get fc-4 types and features from libfc. in fcoe_ctlr_vn_send()
2093 if (sub == FIP_SC_VN_CLAIM_NOTIFY || sub == FIP_SC_VN_CLAIM_REP) { in fcoe_ctlr_vn_send()
2094 ff = (struct fip_fc4_feat *)(frame + 1); in fcoe_ctlr_vn_send()
2095 ff->fd_desc.fip_dtype = FIP_DT_FC4F; in fcoe_ctlr_vn_send()
2096 ff->fd_desc.fip_dlen = sizeof(*ff) / FIP_BPW; in fcoe_ctlr_vn_send()
2097 ff->fd_fts = fip->lp->fcts; in fcoe_ctlr_vn_send()
2100 if (fip->lp->service_params & FCP_SPPF_INIT_FCN) in fcoe_ctlr_vn_send()
2102 if (fip->lp->service_params & FCP_SPPF_TARG_FCN) in fcoe_ctlr_vn_send()
2105 ff->fd_ff.fd_feat[FC_TYPE_FCP * 4 / 32] = htonl(fcp_feat); in fcoe_ctlr_vn_send()
2108 size->fd_desc.fip_dtype = FIP_DT_FCOE_SIZE; in fcoe_ctlr_vn_send()
2109 size->fd_desc.fip_dlen = sizeof(*size) / FIP_BPW; in fcoe_ctlr_vn_send()
2110 size->fd_size = htons(fcoe_ctlr_fcoe_size(fip)); in fcoe_ctlr_vn_send()
2114 skb->protocol = htons(ETH_P_FIP); in fcoe_ctlr_vn_send()
2115 skb->priority = fip->priority; in fcoe_ctlr_vn_send()
2119 fip->send(fip, skb); in fcoe_ctlr_vn_send()
2123 * fcoe_ctlr_vn_rport_callback - Event handler for rport events.
2134 struct fcoe_ctlr *fip = lport->disc.priv; in fcoe_ctlr_vn_rport_callback()
2138 rdata->ids.port_id, event); in fcoe_ctlr_vn_rport_callback()
2140 mutex_lock(&fip->ctlr_mutex); in fcoe_ctlr_vn_rport_callback()
2143 frport->login_count = 0; in fcoe_ctlr_vn_rport_callback()
2148 frport->login_count++; in fcoe_ctlr_vn_rport_callback()
2149 if (frport->login_count > FCOE_CTLR_VN2VN_LOGIN_LIMIT) { in fcoe_ctlr_vn_rport_callback()
2152 rdata->ids.port_id); in fcoe_ctlr_vn_rport_callback()
2159 mutex_unlock(&fip->ctlr_mutex); in fcoe_ctlr_vn_rport_callback()
2167 * fcoe_ctlr_disc_stop_locked() - stop discovery in VN2VN mode
2176 mutex_lock(&lport->disc.disc_mutex); in fcoe_ctlr_disc_stop_locked()
2177 list_for_each_entry_rcu(rdata, &lport->disc.rports, peers) { in fcoe_ctlr_disc_stop_locked()
2178 if (kref_get_unless_zero(&rdata->kref)) { in fcoe_ctlr_disc_stop_locked()
2180 kref_put(&rdata->kref, fc_rport_destroy); in fcoe_ctlr_disc_stop_locked()
2183 lport->disc.disc_callback = NULL; in fcoe_ctlr_disc_stop_locked()
2184 mutex_unlock(&lport->disc.disc_mutex); in fcoe_ctlr_disc_stop_locked()
2188 * fcoe_ctlr_disc_stop() - stop discovery in VN2VN mode
2196 struct fcoe_ctlr *fip = lport->disc.priv; in fcoe_ctlr_disc_stop()
2198 mutex_lock(&fip->ctlr_mutex); in fcoe_ctlr_disc_stop()
2200 mutex_unlock(&fip->ctlr_mutex); in fcoe_ctlr_disc_stop()
2204 * fcoe_ctlr_disc_stop_final() - stop discovery for shutdown in VN2VN mode
2218 * fcoe_ctlr_vn_restart() - VN2VN probe restart with new port_id
2228 fcoe_ctlr_disc_stop_locked(fip->lp); in fcoe_ctlr_vn_restart()
2235 * Don't use reserved IDs, use another non-zero value, just as random. in fcoe_ctlr_vn_restart()
2237 port_id = fip->port_id; in fcoe_ctlr_vn_restart()
2238 if (fip->probe_tries) in fcoe_ctlr_vn_restart()
2239 port_id = prandom_u32_state(&fip->rnd_state) & 0xffff; in fcoe_ctlr_vn_restart()
2241 port_id = fip->lp->wwpn & 0xffff; in fcoe_ctlr_vn_restart()
2244 fip->port_id = port_id; in fcoe_ctlr_vn_restart()
2246 if (fip->probe_tries < FIP_VN_RLIM_COUNT) { in fcoe_ctlr_vn_restart()
2247 fip->probe_tries++; in fcoe_ctlr_vn_restart()
2251 mod_timer(&fip->timer, jiffies + msecs_to_jiffies(wait)); in fcoe_ctlr_vn_restart()
2256 * fcoe_ctlr_vn_start() - Start in VN2VN mode
2263 fip->probe_tries = 0; in fcoe_ctlr_vn_start()
2264 prandom_seed_state(&fip->rnd_state, fip->lp->wwpn); in fcoe_ctlr_vn_start()
2269 * fcoe_ctlr_vn_parse - parse probe request or response
2274 * Returns non-zero error number on error.
2291 u8 sub; in fcoe_ctlr_vn_parse() local
2293 fiph = (struct fip_header *)skb->data; in fcoe_ctlr_vn_parse()
2294 frport->flags = ntohs(fiph->fip_flags); in fcoe_ctlr_vn_parse()
2296 sub = fiph->fip_subcode; in fcoe_ctlr_vn_parse()
2297 switch (sub) { in fcoe_ctlr_vn_parse()
2311 LIBFCOE_FIP_DBG(fip, "vn_parse unknown subcode %u\n", sub); in fcoe_ctlr_vn_parse()
2312 return -EINVAL; in fcoe_ctlr_vn_parse()
2315 rlen = ntohs(fiph->fip_dl_len) * 4; in fcoe_ctlr_vn_parse()
2316 if (rlen + sizeof(*fiph) > skb->len) in fcoe_ctlr_vn_parse()
2317 return -EINVAL; in fcoe_ctlr_vn_parse()
2321 dlen = desc->fip_dlen * FIP_BPW; in fcoe_ctlr_vn_parse()
2323 return -EINVAL; in fcoe_ctlr_vn_parse()
2325 dtype = desc->fip_dtype; in fcoe_ctlr_vn_parse()
2332 dtype, sub); in fcoe_ctlr_vn_parse()
2333 return -EINVAL; in fcoe_ctlr_vn_parse()
2343 if (!is_valid_ether_addr(macd->fd_mac)) { in fcoe_ctlr_vn_parse()
2346 macd->fd_mac); in fcoe_ctlr_vn_parse()
2347 return -EINVAL; in fcoe_ctlr_vn_parse()
2349 memcpy(frport->enode_mac, macd->fd_mac, ETH_ALEN); in fcoe_ctlr_vn_parse()
2355 frport->rdata.ids.node_name = in fcoe_ctlr_vn_parse()
2356 get_unaligned_be64(&wwn->fd_wwn); in fcoe_ctlr_vn_parse()
2362 memcpy(frport->vn_mac, vn->fd_mac, ETH_ALEN); in fcoe_ctlr_vn_parse()
2363 frport->rdata.ids.port_id = ntoh24(vn->fd_fc_id); in fcoe_ctlr_vn_parse()
2364 frport->rdata.ids.port_name = in fcoe_ctlr_vn_parse()
2365 get_unaligned_be64(&vn->fd_wwpn); in fcoe_ctlr_vn_parse()
2375 frport->fcoe_len = ntohs(size->fd_size); in fcoe_ctlr_vn_parse()
2382 return -EINVAL; in fcoe_ctlr_vn_parse()
2386 rlen -= dlen; in fcoe_ctlr_vn_parse()
2393 return -EINVAL; in fcoe_ctlr_vn_parse()
2397 * fcoe_ctlr_vn_send_claim() - send multicast FIP VN2VN Claim Notification.
2405 fip->sol_time = jiffies; in fcoe_ctlr_vn_send_claim()
2409 * fcoe_ctlr_vn_probe_req() - handle incoming VN2VN probe request.
2418 if (frport->rdata.ids.port_id != fip->port_id) in fcoe_ctlr_vn_probe_req()
2421 switch (fip->state) { in fcoe_ctlr_vn_probe_req()
2425 fip->state); in fcoe_ctlr_vn_probe_req()
2427 frport->enode_mac, 0); in fcoe_ctlr_vn_probe_req()
2438 if (fip->lp->wwpn > frport->rdata.ids.port_name && in fcoe_ctlr_vn_probe_req()
2439 !(frport->flags & FIP_FL_REC_OR_P2P)) { in fcoe_ctlr_vn_probe_req()
2443 frport->enode_mac, 0); in fcoe_ctlr_vn_probe_req()
2454 fip->state); in fcoe_ctlr_vn_probe_req()
2460 * fcoe_ctlr_vn_probe_reply() - handle incoming VN2VN probe reply.
2469 if (frport->rdata.ids.port_id != fip->port_id) in fcoe_ctlr_vn_probe_reply()
2471 switch (fip->state) { in fcoe_ctlr_vn_probe_reply()
2477 fip->state); in fcoe_ctlr_vn_probe_reply()
2490 * fcoe_ctlr_vn_add() - Add a VN2VN entry to the list, based on a claim reply.
2492 * @new: newly-parsed FCoE rport as a template for new rdata
2498 struct fc_lport *lport = fip->lp; in fcoe_ctlr_vn_add()
2504 port_id = new->rdata.ids.port_id; in fcoe_ctlr_vn_add()
2505 if (port_id == fip->port_id) in fcoe_ctlr_vn_add()
2508 mutex_lock(&lport->disc.disc_mutex); in fcoe_ctlr_vn_add()
2511 mutex_unlock(&lport->disc.disc_mutex); in fcoe_ctlr_vn_add()
2514 mutex_lock(&rdata->rp_mutex); in fcoe_ctlr_vn_add()
2515 mutex_unlock(&lport->disc.disc_mutex); in fcoe_ctlr_vn_add()
2517 rdata->ops = &fcoe_ctlr_vn_rport_ops; in fcoe_ctlr_vn_add()
2518 rdata->disc_id = lport->disc.disc_id; in fcoe_ctlr_vn_add()
2520 ids = &rdata->ids; in fcoe_ctlr_vn_add()
2521 if ((ids->port_name != -1 && in fcoe_ctlr_vn_add()
2522 ids->port_name != new->rdata.ids.port_name) || in fcoe_ctlr_vn_add()
2523 (ids->node_name != -1 && in fcoe_ctlr_vn_add()
2524 ids->node_name != new->rdata.ids.node_name)) { in fcoe_ctlr_vn_add()
2525 mutex_unlock(&rdata->rp_mutex); in fcoe_ctlr_vn_add()
2528 mutex_lock(&rdata->rp_mutex); in fcoe_ctlr_vn_add()
2530 ids->port_name = new->rdata.ids.port_name; in fcoe_ctlr_vn_add()
2531 ids->node_name = new->rdata.ids.node_name; in fcoe_ctlr_vn_add()
2532 mutex_unlock(&rdata->rp_mutex); in fcoe_ctlr_vn_add()
2536 port_id, frport->fcoe_len ? "old" : "new", in fcoe_ctlr_vn_add()
2537 rdata->rp_state); in fcoe_ctlr_vn_add()
2538 frport->fcoe_len = new->fcoe_len; in fcoe_ctlr_vn_add()
2539 frport->flags = new->flags; in fcoe_ctlr_vn_add()
2540 frport->login_count = new->login_count; in fcoe_ctlr_vn_add()
2541 memcpy(frport->enode_mac, new->enode_mac, ETH_ALEN); in fcoe_ctlr_vn_add()
2542 memcpy(frport->vn_mac, new->vn_mac, ETH_ALEN); in fcoe_ctlr_vn_add()
2543 frport->time = 0; in fcoe_ctlr_vn_add()
2547 * fcoe_ctlr_vn_lookup() - Find VN remote port's MAC address
2552 * Returns non-zero error if no remote port found.
2556 struct fc_lport *lport = fip->lp; in fcoe_ctlr_vn_lookup()
2559 int ret = -1; in fcoe_ctlr_vn_lookup()
2564 memcpy(mac, frport->enode_mac, ETH_ALEN); in fcoe_ctlr_vn_lookup()
2566 kref_put(&rdata->kref, fc_rport_destroy); in fcoe_ctlr_vn_lookup()
2572 * fcoe_ctlr_vn_claim_notify() - handle received FIP VN2VN Claim Notification
2574 * @new: newly-parsed FCoE rport as a template for new rdata
2581 if (new->flags & FIP_FL_REC_OR_P2P) { in fcoe_ctlr_vn_claim_notify()
2586 switch (fip->state) { in fcoe_ctlr_vn_claim_notify()
2590 if (new->rdata.ids.port_id == fip->port_id) { in fcoe_ctlr_vn_claim_notify()
2593 fip->state); in fcoe_ctlr_vn_claim_notify()
2599 if (new->rdata.ids.port_id == fip->port_id) { in fcoe_ctlr_vn_claim_notify()
2600 if (new->rdata.ids.port_name > fip->lp->wwpn) { in fcoe_ctlr_vn_claim_notify()
2612 new->rdata.ids.port_id); in fcoe_ctlr_vn_claim_notify()
2613 fcoe_ctlr_vn_send(fip, FIP_SC_VN_CLAIM_REP, new->enode_mac, in fcoe_ctlr_vn_claim_notify()
2614 min((u32)new->fcoe_len, in fcoe_ctlr_vn_claim_notify()
2621 new->rdata.ids.port_id); in fcoe_ctlr_vn_claim_notify()
2627 * fcoe_ctlr_vn_claim_resp() - handle received Claim Response
2628 * @fip: The FCoE controller that received the frame
2629 * @new: newly-parsed FCoE rport from the Claim Response
2636 LIBFCOE_FIP_DBG(fip, "claim resp from from rport %x - state %s\n", in fcoe_ctlr_vn_claim_resp()
2637 new->rdata.ids.port_id, fcoe_ctlr_state(fip->state)); in fcoe_ctlr_vn_claim_resp()
2638 if (fip->state == FIP_ST_VNMP_UP || fip->state == FIP_ST_VNMP_CLAIM) in fcoe_ctlr_vn_claim_resp()
2643 * fcoe_ctlr_vn_beacon() - handle received beacon.
2644 * @fip: The FCoE controller that received the frame
2645 * @new: newly-parsed FCoE rport from the Beacon
2652 struct fc_lport *lport = fip->lp; in fcoe_ctlr_vn_beacon()
2656 if (new->flags & FIP_FL_REC_OR_P2P) { in fcoe_ctlr_vn_beacon()
2661 rdata = fc_rport_lookup(lport, new->rdata.ids.port_id); in fcoe_ctlr_vn_beacon()
2663 if (rdata->ids.node_name == new->rdata.ids.node_name && in fcoe_ctlr_vn_beacon()
2664 rdata->ids.port_name == new->rdata.ids.port_name) { in fcoe_ctlr_vn_beacon()
2668 rdata->ids.port_id); in fcoe_ctlr_vn_beacon()
2669 if (!frport->time && fip->state == FIP_ST_VNMP_UP) { in fcoe_ctlr_vn_beacon()
2672 rdata->ids.port_id); in fcoe_ctlr_vn_beacon()
2675 frport->time = jiffies; in fcoe_ctlr_vn_beacon()
2677 kref_put(&rdata->kref, fc_rport_destroy); in fcoe_ctlr_vn_beacon()
2680 if (fip->state != FIP_ST_VNMP_UP) in fcoe_ctlr_vn_beacon()
2689 new->rdata.ids.port_id); in fcoe_ctlr_vn_beacon()
2691 fip->sol_time + msecs_to_jiffies(FIP_VN_ANN_WAIT))) in fcoe_ctlr_vn_beacon()
2696 * fcoe_ctlr_vn_age() - Check for VN_ports without recent beacons
2701 * Returns the soonest time for next age-out or a time far in the future.
2705 struct fc_lport *lport = fip->lp; in fcoe_ctlr_vn_age()
2712 mutex_lock(&lport->disc.disc_mutex); in fcoe_ctlr_vn_age()
2713 list_for_each_entry_rcu(rdata, &lport->disc.rports, peers) { in fcoe_ctlr_vn_age()
2714 if (!kref_get_unless_zero(&rdata->kref)) in fcoe_ctlr_vn_age()
2717 if (!frport->time) { in fcoe_ctlr_vn_age()
2718 kref_put(&rdata->kref, fc_rport_destroy); in fcoe_ctlr_vn_age()
2721 deadline = frport->time + in fcoe_ctlr_vn_age()
2724 frport->time = 0; in fcoe_ctlr_vn_age()
2727 rdata->ids.port_name, rdata->ids.port_id); in fcoe_ctlr_vn_age()
2731 kref_put(&rdata->kref, fc_rport_destroy); in fcoe_ctlr_vn_age()
2733 mutex_unlock(&lport->disc.disc_mutex); in fcoe_ctlr_vn_age()
2738 * fcoe_ctlr_vn_recv() - Receive a FIP frame
2739 * @fip: The FCoE controller that received the frame
2740 * @skb: The received FIP frame
2742 * Returns non-zero if the frame is dropped.
2743 * Always consumes the frame.
2748 enum fip_vn2vn_subcode sub; in fcoe_ctlr_vn_recv() local
2752 fiph = (struct fip_header *)skb->data; in fcoe_ctlr_vn_recv()
2753 sub = fiph->fip_subcode; in fcoe_ctlr_vn_recv()
2755 if (fip->lp->vlan) in fcoe_ctlr_vn_recv()
2758 if (vlan_id && vlan_id != fip->lp->vlan) { in fcoe_ctlr_vn_recv()
2759 LIBFCOE_FIP_DBG(fip, "vn_recv drop frame sub %x vlan %d\n", in fcoe_ctlr_vn_recv()
2760 sub, vlan_id); in fcoe_ctlr_vn_recv()
2761 rc = -EAGAIN; in fcoe_ctlr_vn_recv()
2771 mutex_lock(&fip->ctlr_mutex); in fcoe_ctlr_vn_recv()
2772 switch (sub) { in fcoe_ctlr_vn_recv()
2789 LIBFCOE_FIP_DBG(fip, "vn_recv unknown subcode %d\n", sub); in fcoe_ctlr_vn_recv()
2790 rc = -1; in fcoe_ctlr_vn_recv()
2793 mutex_unlock(&fip->ctlr_mutex); in fcoe_ctlr_vn_recv()
2800 * fcoe_ctlr_vlan_parse - parse vlan discovery request or response
2805 * Returns non-zero error number on error.
2820 u8 sub; in fcoe_ctlr_vlan_parse() local
2822 fiph = (struct fip_header *)skb->data; in fcoe_ctlr_vlan_parse()
2823 frport->flags = ntohs(fiph->fip_flags); in fcoe_ctlr_vlan_parse()
2825 sub = fiph->fip_subcode; in fcoe_ctlr_vlan_parse()
2826 switch (sub) { in fcoe_ctlr_vlan_parse()
2831 LIBFCOE_FIP_DBG(fip, "vn_parse unknown subcode %u\n", sub); in fcoe_ctlr_vlan_parse()
2832 return -EINVAL; in fcoe_ctlr_vlan_parse()
2835 rlen = ntohs(fiph->fip_dl_len) * 4; in fcoe_ctlr_vlan_parse()
2836 if (rlen + sizeof(*fiph) > skb->len) in fcoe_ctlr_vlan_parse()
2837 return -EINVAL; in fcoe_ctlr_vlan_parse()
2841 dlen = desc->fip_dlen * FIP_BPW; in fcoe_ctlr_vlan_parse()
2843 return -EINVAL; in fcoe_ctlr_vlan_parse()
2845 dtype = desc->fip_dtype; in fcoe_ctlr_vlan_parse()
2852 dtype, sub); in fcoe_ctlr_vlan_parse()
2853 return -EINVAL; in fcoe_ctlr_vlan_parse()
2863 if (!is_valid_ether_addr(macd->fd_mac)) { in fcoe_ctlr_vlan_parse()
2866 macd->fd_mac); in fcoe_ctlr_vlan_parse()
2867 return -EINVAL; in fcoe_ctlr_vlan_parse()
2869 memcpy(frport->enode_mac, macd->fd_mac, ETH_ALEN); in fcoe_ctlr_vlan_parse()
2875 frport->rdata.ids.node_name = in fcoe_ctlr_vlan_parse()
2876 get_unaligned_be64(&wwn->fd_wwn); in fcoe_ctlr_vlan_parse()
2883 return -EINVAL; in fcoe_ctlr_vlan_parse()
2887 rlen -= dlen; in fcoe_ctlr_vlan_parse()
2894 return -EINVAL; in fcoe_ctlr_vlan_parse()
2898 * fcoe_ctlr_vlan_send() - Send a FIP VLAN Notification
2900 * @sub: sub-opcode for vlan notification or vn2vn vlan notification
2904 enum fip_vlan_subcode sub, in fcoe_ctlr_vlan_send() argument
2913 } __packed * frame; in fcoe_ctlr_vlan_send() local
2917 len = sizeof(*frame); in fcoe_ctlr_vlan_send()
2918 dlen = sizeof(frame->mac) + sizeof(frame->vlan); in fcoe_ctlr_vlan_send()
2926 fip->mode == FIP_MODE_VN2VN ? "vn2vn" : "fcf", in fcoe_ctlr_vlan_send()
2927 fip->lp->vlan); in fcoe_ctlr_vlan_send()
2929 frame = (struct fip_vlan_notify_frame *)skb->data; in fcoe_ctlr_vlan_send()
2930 memset(frame, 0, len); in fcoe_ctlr_vlan_send()
2931 memcpy(frame->eth.h_dest, dest, ETH_ALEN); in fcoe_ctlr_vlan_send()
2933 memcpy(frame->eth.h_source, fip->ctl_src_addr, ETH_ALEN); in fcoe_ctlr_vlan_send()
2934 frame->eth.h_proto = htons(ETH_P_FIP); in fcoe_ctlr_vlan_send()
2936 frame->fip.fip_ver = FIP_VER_ENCAPS(FIP_VER); in fcoe_ctlr_vlan_send()
2937 frame->fip.fip_op = htons(FIP_OP_VLAN); in fcoe_ctlr_vlan_send()
2938 frame->fip.fip_subcode = sub; in fcoe_ctlr_vlan_send()
2939 frame->fip.fip_dl_len = htons(dlen / FIP_BPW); in fcoe_ctlr_vlan_send()
2941 frame->mac.fd_desc.fip_dtype = FIP_DT_MAC; in fcoe_ctlr_vlan_send()
2942 frame->mac.fd_desc.fip_dlen = sizeof(frame->mac) / FIP_BPW; in fcoe_ctlr_vlan_send()
2943 memcpy(frame->mac.fd_mac, fip->ctl_src_addr, ETH_ALEN); in fcoe_ctlr_vlan_send()
2945 frame->vlan.fd_desc.fip_dtype = FIP_DT_VLAN; in fcoe_ctlr_vlan_send()
2946 frame->vlan.fd_desc.fip_dlen = sizeof(frame->vlan) / FIP_BPW; in fcoe_ctlr_vlan_send()
2947 put_unaligned_be16(fip->lp->vlan, &frame->vlan.fd_vlan); in fcoe_ctlr_vlan_send()
2950 skb->protocol = htons(ETH_P_FIP); in fcoe_ctlr_vlan_send()
2951 skb->priority = fip->priority; in fcoe_ctlr_vlan_send()
2955 fip->send(fip, skb); in fcoe_ctlr_vlan_send()
2959 * fcoe_ctlr_vlan_disk_reply() - send FIP VLAN Discovery Notification.
2961 * @frport: The newly-parsed FCoE rport from the Discovery Request
2968 enum fip_vlan_subcode sub = FIP_SC_VL_NOTE; in fcoe_ctlr_vlan_disc_reply() local
2970 if (fip->mode == FIP_MODE_VN2VN) in fcoe_ctlr_vlan_disc_reply()
2971 sub = FIP_SC_VL_VN2VN_NOTE; in fcoe_ctlr_vlan_disc_reply()
2973 fcoe_ctlr_vlan_send(fip, sub, frport->enode_mac); in fcoe_ctlr_vlan_disc_reply()
2977 * fcoe_ctlr_vlan_recv - vlan request receive handler for VN2VN mode.
2984 enum fip_vlan_subcode sub; in fcoe_ctlr_vlan_recv() local
2988 fiph = (struct fip_header *)skb->data; in fcoe_ctlr_vlan_recv()
2989 sub = fiph->fip_subcode; in fcoe_ctlr_vlan_recv()
2995 mutex_lock(&fip->ctlr_mutex); in fcoe_ctlr_vlan_recv()
2996 if (sub == FIP_SC_VL_REQ) in fcoe_ctlr_vlan_recv()
2998 mutex_unlock(&fip->ctlr_mutex); in fcoe_ctlr_vlan_recv()
3006 * fcoe_ctlr_disc_recv - discovery receive handler for VN2VN mode.
3008 * @fp: The received frame
3011 * fabric-generated ELSes.
3024 * fcoe_ctlr_disc_start - start discovery for VN2VN mode.
3038 struct fc_disc *disc = &lport->disc; in fcoe_ctlr_disc_start()
3039 struct fcoe_ctlr *fip = disc->priv; in fcoe_ctlr_disc_start()
3041 mutex_lock(&disc->disc_mutex); in fcoe_ctlr_disc_start()
3042 disc->disc_callback = callback; in fcoe_ctlr_disc_start()
3043 disc->disc_id = (disc->disc_id + 2) | 1; in fcoe_ctlr_disc_start()
3044 disc->pending = 1; in fcoe_ctlr_disc_start()
3045 schedule_work(&fip->timer_work); in fcoe_ctlr_disc_start()
3046 mutex_unlock(&disc->disc_mutex); in fcoe_ctlr_disc_start()
3050 * fcoe_ctlr_vn_disc() - report FIP VN_port discovery results after claim state.
3059 struct fc_lport *lport = fip->lp; in fcoe_ctlr_vn_disc()
3060 struct fc_disc *disc = &lport->disc; in fcoe_ctlr_vn_disc()
3065 mutex_lock(&disc->disc_mutex); in fcoe_ctlr_vn_disc()
3066 callback = disc->pending ? disc->disc_callback : NULL; in fcoe_ctlr_vn_disc()
3067 disc->pending = 0; in fcoe_ctlr_vn_disc()
3068 list_for_each_entry_rcu(rdata, &disc->rports, peers) { in fcoe_ctlr_vn_disc()
3069 if (!kref_get_unless_zero(&rdata->kref)) in fcoe_ctlr_vn_disc()
3072 if (frport->time) in fcoe_ctlr_vn_disc()
3074 kref_put(&rdata->kref, fc_rport_destroy); in fcoe_ctlr_vn_disc()
3076 mutex_unlock(&disc->disc_mutex); in fcoe_ctlr_vn_disc()
3082 * fcoe_ctlr_vn_timeout - timer work function for VN2VN mode.
3091 mutex_lock(&fip->ctlr_mutex); in fcoe_ctlr_vn_timeout()
3092 switch (fip->state) { in fcoe_ctlr_vn_timeout()
3107 new_port_id = fip->port_id; in fcoe_ctlr_vn_timeout()
3111 fip->update_mac(fip->lp, mac); in fcoe_ctlr_vn_timeout()
3121 next_time = fip->sol_time + msecs_to_jiffies(FIP_VN_ANN_WAIT); in fcoe_ctlr_vn_timeout()
3128 fip->port_ka_time = next_time; in fcoe_ctlr_vn_timeout()
3134 if (time_after_eq(jiffies, fip->port_ka_time)) { in fcoe_ctlr_vn_timeout()
3138 fip->port_ka_time = jiffies + in fcoe_ctlr_vn_timeout()
3142 if (time_before(fip->port_ka_time, next_time)) in fcoe_ctlr_vn_timeout()
3143 next_time = fip->port_ka_time; in fcoe_ctlr_vn_timeout()
3148 WARN(1, "unexpected state %d\n", fip->state); in fcoe_ctlr_vn_timeout()
3151 mod_timer(&fip->timer, next_time); in fcoe_ctlr_vn_timeout()
3153 mutex_unlock(&fip->ctlr_mutex); in fcoe_ctlr_vn_timeout()
3157 fc_lport_set_local_id(fip->lp, new_port_id); in fcoe_ctlr_vn_timeout()
3161 * fcoe_ctlr_mode_set() - Set or reset the ctlr's mode
3177 WARN_ON(lport->state != LPORT_ST_RESET && in fcoe_ctlr_mode_set()
3178 lport->state != LPORT_ST_DISABLED); in fcoe_ctlr_mode_set()
3181 lport->rport_priv_size = sizeof(struct fcoe_rport); in fcoe_ctlr_mode_set()
3182 lport->point_to_multipoint = 1; in fcoe_ctlr_mode_set()
3183 lport->tt.disc_recv_req = fcoe_ctlr_disc_recv; in fcoe_ctlr_mode_set()
3184 lport->tt.disc_start = fcoe_ctlr_disc_start; in fcoe_ctlr_mode_set()
3185 lport->tt.disc_stop = fcoe_ctlr_disc_stop; in fcoe_ctlr_mode_set()
3186 lport->tt.disc_stop_final = fcoe_ctlr_disc_stop_final; in fcoe_ctlr_mode_set()
3189 lport->rport_priv_size = 0; in fcoe_ctlr_mode_set()
3190 lport->point_to_multipoint = 0; in fcoe_ctlr_mode_set()
3191 lport->tt.disc_recv_req = NULL; in fcoe_ctlr_mode_set()
3192 lport->tt.disc_start = NULL; in fcoe_ctlr_mode_set()
3193 lport->tt.disc_stop = NULL; in fcoe_ctlr_mode_set()
3194 lport->tt.disc_stop_final = NULL; in fcoe_ctlr_mode_set()
3202 * fcoe_libfc_config() - Sets up libfc related properties for local port
3206 * @init_fcp: If non-zero, the FCP portion of libfc should be initialized
3214 memcpy(&lport->tt, tt, sizeof(*tt)); in fcoe_libfc_config()
3216 return -ENOMEM; in fcoe_libfc_config()
3221 fcoe_ctlr_mode_set(lport, fip, fip->mode); in fcoe_libfc_config()
3232 mutex_lock(&fip->ctlr_mutex); in fcoe_fcf_get_selected()
3233 mutex_lock(&ctlr_dev->lock); in fcoe_fcf_get_selected()
3237 fcf_dev->selected = (fcf == fip->sel_fcf) ? 1 : 0; in fcoe_fcf_get_selected()
3239 fcf_dev->selected = 0; in fcoe_fcf_get_selected()
3241 mutex_unlock(&ctlr_dev->lock); in fcoe_fcf_get_selected()
3242 mutex_unlock(&fip->ctlr_mutex); in fcoe_fcf_get_selected()
3249 struct fc_lport *lport = ctlr->lp; in fcoe_ctlr_set_fip_mode()
3251 mutex_lock(&ctlr->ctlr_mutex); in fcoe_ctlr_set_fip_mode()
3252 switch (ctlr_dev->mode) { in fcoe_ctlr_set_fip_mode()
3254 ctlr->mode = FIP_MODE_VN2VN; in fcoe_ctlr_set_fip_mode()
3258 ctlr->mode = FIP_MODE_FABRIC; in fcoe_ctlr_set_fip_mode()
3262 mutex_unlock(&ctlr->ctlr_mutex); in fcoe_ctlr_set_fip_mode()
3264 fcoe_ctlr_mode_set(lport, ctlr, ctlr->mode); in fcoe_ctlr_set_fip_mode()