Lines Matching refs:fip

83  * @fip: The FCoE controller
86 static void fcoe_ctlr_set_state(struct fcoe_ctlr *fip, enum fip_state state)
88 if (state == fip->state)
90 if (fip->lp)
91 LIBFCOE_FIP_DBG(fip, "state %s -> %s\n",
92 fcoe_ctlr_state(fip->state), fcoe_ctlr_state(state));
93 fip->state = state;
122 * @fip: The FCoE controller
124 static void fcoe_ctlr_map_dest(struct fcoe_ctlr *fip)
126 if (fip->mode == FIP_MODE_VN2VN)
127 hton24(fip->dest_addr, FIP_VN_FC_MAP);
129 hton24(fip->dest_addr, FIP_DEF_FC_MAP);
130 hton24(fip->dest_addr + 3, 0);
131 fip->map_dest = 1;
136 * @fip: The FCoE controller to initialize
139 void fcoe_ctlr_init(struct fcoe_ctlr *fip, enum fip_mode mode)
141 fcoe_ctlr_set_state(fip, FIP_ST_LINK_WAIT);
142 fip->mode = mode;
143 fip->fip_resp = false;
144 INIT_LIST_HEAD(&fip->fcfs);
145 mutex_init(&fip->ctlr_mutex);
146 spin_lock_init(&fip->ctlr_lock);
147 fip->flogi_oxid = FC_XID_UNKNOWN;
148 timer_setup(&fip->timer, fcoe_ctlr_timeout, 0);
149 INIT_WORK(&fip->timer_work, fcoe_ctlr_timer_work);
150 INIT_WORK(&fip->recv_work, fcoe_ctlr_recv_work);
151 skb_queue_head_init(&fip->fip_recv_list);
159 * Called with fip->ctlr_mutex held
163 struct fcoe_ctlr *fip = new->fip;
168 LIBFCOE_FIP_DBG(fip, "New FCF fab %16.16llx mac %pM\n",
192 ctlr_dev = fcoe_ctlr_to_ctlr_dev(fip);
219 list_add(&new->list, &fip->fcfs);
220 fip->fcf_count++;
232 * Called with fip->ctlr_mutex held
236 struct fcoe_ctlr *fip = new->fip;
241 fip->fcf_count--;
252 cdev = fcoe_ctlr_to_ctlr_dev(fip);
266 * @fip: The FCoE controller whose FCFs are to be reset
270 static void fcoe_ctlr_reset_fcfs(struct fcoe_ctlr *fip)
275 fip->sel_fcf = NULL;
276 list_for_each_entry_safe(fcf, next, &fip->fcfs, list) {
279 WARN_ON(fip->fcf_count);
281 fip->sel_time = 0;
286 * @fip: The FCoE controller to tear down
296 void fcoe_ctlr_destroy(struct fcoe_ctlr *fip)
298 cancel_work_sync(&fip->recv_work);
299 skb_queue_purge(&fip->fip_recv_list);
301 mutex_lock(&fip->ctlr_mutex);
302 fcoe_ctlr_set_state(fip, FIP_ST_DISABLED);
303 fcoe_ctlr_reset_fcfs(fip);
304 mutex_unlock(&fip->ctlr_mutex);
305 del_timer_sync(&fip->timer);
306 cancel_work_sync(&fip->timer_work);
312 * @fip: The FCoE controller
318 static void fcoe_ctlr_announce(struct fcoe_ctlr *fip)
323 mutex_lock(&fip->ctlr_mutex);
324 spin_lock_bh(&fip->ctlr_lock);
326 kfree_skb(fip->flogi_req);
327 fip->flogi_req = NULL;
328 list_for_each_entry(fcf, &fip->fcfs, list)
331 spin_unlock_bh(&fip->ctlr_lock);
332 sel = fip->sel_fcf;
334 if (sel && ether_addr_equal(sel->fcf_mac, fip->dest_addr))
336 if (!is_zero_ether_addr(fip->dest_addr)) {
339 fip->lp->host->host_no, fip->dest_addr);
340 eth_zero_addr(fip->dest_addr);
345 fip->lp->host->host_no, sel->fcf_mac);
346 memcpy(fip->dest_addr, sel->fcoe_mac, ETH_ALEN);
347 fip->map_dest = 0;
350 mutex_unlock(&fip->ctlr_mutex);
355 * @fip: The FCoE controller to get the maximum FCoE size from
360 static inline u32 fcoe_ctlr_fcoe_size(struct fcoe_ctlr *fip)
367 return fip->lp->mfs + sizeof(struct fc_frame_header) +
373 * @fip: The FCoE controller to send the solicitation on
376 static void fcoe_ctlr_solicit(struct fcoe_ctlr *fip, struct fcoe_fcf *fcf)
381 struct fip_header fip;
398 memcpy(sol->eth.h_source, fip->ctl_src_addr, ETH_ALEN);
401 sol->fip.fip_ver = FIP_VER_ENCAPS(FIP_VER);
402 sol->fip.fip_op = htons(FIP_OP_DISC);
403 sol->fip.fip_subcode = FIP_SC_SOL;
404 sol->fip.fip_dl_len = htons(sizeof(sol->desc) / FIP_BPW);
405 sol->fip.fip_flags = htons(FIP_FL_FPMA);
406 if (fip->spma)
407 sol->fip.fip_flags |= htons(FIP_FL_SPMA);
411 memcpy(sol->desc.mac.fd_mac, fip->ctl_src_addr, ETH_ALEN);
415 put_unaligned_be64(fip->lp->wwnn, &sol->desc.wwnn.fd_wwn);
417 fcoe_size = fcoe_ctlr_fcoe_size(fip);
424 skb->priority = fip->priority;
427 fip->send(fip, skb);
430 fip->sol_time = jiffies;
435 * @fip: The FCoE controller to start
439 void fcoe_ctlr_link_up(struct fcoe_ctlr *fip)
441 mutex_lock(&fip->ctlr_mutex);
442 if (fip->state == FIP_ST_NON_FIP || fip->state == FIP_ST_AUTO) {
443 mutex_unlock(&fip->ctlr_mutex);
444 fc_linkup(fip->lp);
445 } else if (fip->state == FIP_ST_LINK_WAIT) {
446 if (fip->mode == FIP_MODE_NON_FIP)
447 fcoe_ctlr_set_state(fip, FIP_ST_NON_FIP);
449 fcoe_ctlr_set_state(fip, FIP_ST_AUTO);
450 switch (fip->mode) {
452 LIBFCOE_FIP_DBG(fip, "invalid mode %d\n", fip->mode);
455 LIBFCOE_FIP_DBG(fip, "%s", "setting AUTO mode.\n");
459 mutex_unlock(&fip->ctlr_mutex);
460 fc_linkup(fip->lp);
461 fcoe_ctlr_solicit(fip, NULL);
464 fcoe_ctlr_vn_start(fip);
465 mutex_unlock(&fip->ctlr_mutex);
466 fc_linkup(fip->lp);
470 mutex_unlock(&fip->ctlr_mutex);
476 * @fip: The FCoE controller to reset
478 static void fcoe_ctlr_reset(struct fcoe_ctlr *fip)
480 fcoe_ctlr_reset_fcfs(fip);
481 del_timer(&fip->timer);
482 fip->ctlr_ka_time = 0;
483 fip->port_ka_time = 0;
484 fip->sol_time = 0;
485 fip->flogi_oxid = FC_XID_UNKNOWN;
486 fcoe_ctlr_map_dest(fip);
491 * @fip: The FCoE controller to be stopped
498 int fcoe_ctlr_link_down(struct fcoe_ctlr *fip)
502 LIBFCOE_FIP_DBG(fip, "link down.\n");
503 mutex_lock(&fip->ctlr_mutex);
504 fcoe_ctlr_reset(fip);
505 link_dropped = fip->state != FIP_ST_LINK_WAIT;
506 fcoe_ctlr_set_state(fip, FIP_ST_LINK_WAIT);
507 mutex_unlock(&fip->ctlr_mutex);
510 fc_linkdown(fip->lp);
517 * @fip: The FCoE controller to send the FKA on
529 static void fcoe_ctlr_send_keep_alive(struct fcoe_ctlr *fip,
536 struct fip_header fip;
544 fcf = fip->sel_fcf;
545 lp = fip->lp;
560 kal->fip.fip_ver = FIP_VER_ENCAPS(FIP_VER);
561 kal->fip.fip_op = htons(FIP_OP_CTRL);
562 kal->fip.fip_subcode = FIP_SC_KEEP_ALIVE;
563 kal->fip.fip_dl_len = htons((sizeof(kal->mac) +
565 kal->fip.fip_flags = htons(FIP_FL_FPMA);
566 if (fip->spma)
567 kal->fip.fip_flags |= htons(FIP_FL_SPMA);
571 memcpy(kal->mac.fd_mac, fip->ctl_src_addr, ETH_ALEN);
576 memcpy(vn->fd_mac, fip->get_src_addr(lport), ETH_ALEN);
582 skb->priority = fip->priority;
585 fip->send(fip, skb);
590 * @fip: The FCoE controller for the ELS frame
604 static int fcoe_ctlr_encaps(struct fcoe_ctlr *fip, struct fc_lport *lport,
609 struct fip_header fip;
626 if (fcoe_ctlr_vn_lookup(fip, d_id, cap->eth.h_dest))
630 fcf = fip->sel_fcf;
634 fip_flags &= fip->spma ? FIP_FL_SPMA | FIP_FL_FPMA :
640 memcpy(cap->eth.h_source, fip->ctl_src_addr, ETH_ALEN);
643 cap->fip.fip_ver = FIP_VER_ENCAPS(FIP_VER);
644 cap->fip.fip_op = htons(FIP_OP_LS);
646 cap->fip.fip_subcode = FIP_SC_REP;
648 cap->fip.fip_subcode = FIP_SC_REQ;
649 cap->fip.fip_flags = htons(fip_flags);
660 memcpy(mac->fd_mac, fip->get_src_addr(lport), ETH_ALEN);
661 } else if (fip->mode == FIP_MODE_VN2VN) {
663 hton24(mac->fd_mac + 3, fip->port_id);
665 LIBFCOE_FIP_DBG(fip, "FLOGI/FDISC sent with SPMA\n");
666 memcpy(mac->fd_mac, fip->ctl_src_addr, ETH_ALEN);
668 LIBFCOE_FIP_DBG(fip, "FLOGI/FDISC sent with FPMA\n");
672 cap->fip.fip_dl_len = htons(dlen / FIP_BPW);
675 skb->priority = fip->priority;
683 * @fip: FCoE controller.
697 int fcoe_ctlr_els_send(struct fcoe_ctlr *fip, struct fc_lport *lport,
710 if (op == ELS_FLOGI && fip->mode != FIP_MODE_VN2VN) {
711 old_xid = fip->flogi_oxid;
712 fip->flogi_oxid = ntohs(fh->fh_ox_id);
713 if (fip->state == FIP_ST_AUTO) {
715 fip->flogi_count = 0;
716 fip->flogi_count++;
717 if (fip->flogi_count < 3)
719 fcoe_ctlr_map_dest(fip);
722 if (fip->state == FIP_ST_NON_FIP)
723 fcoe_ctlr_map_dest(fip);
726 if (fip->state == FIP_ST_NON_FIP)
728 if (!fip->sel_fcf && fip->mode != FIP_MODE_VN2VN)
733 if (fip->mode == FIP_MODE_VN2VN)
735 spin_lock_bh(&fip->ctlr_lock);
736 kfree_skb(fip->flogi_req);
737 fip->flogi_req = skb;
738 fip->flogi_req_send = 1;
739 spin_unlock_bh(&fip->ctlr_lock);
740 schedule_work(&fip->timer_work);
748 if (fip->mode == FIP_MODE_VN2VN) {
749 if (fip->state != FIP_ST_VNMP_UP)
754 if (fip->state != FIP_ST_ENABLED)
769 if (fip->state == FIP_ST_NON_FIP) {
770 if (fip->flogi_oxid == FC_XID_UNKNOWN)
772 fip->flogi_oxid = FC_XID_UNKNOWN;
774 fip->update_mac(lport, mac);
783 if (fip->state != FIP_ST_ENABLED &&
784 fip->state != FIP_ST_VNMP_UP)
788 LIBFCOE_FIP_DBG(fip, "els_send op %u d_id %x\n",
790 if (fcoe_ctlr_encaps(fip, lport, op, skb, ntoh24(fh->fh_d_id)))
792 fip->send(fip, skb);
795 LIBFCOE_FIP_DBG(fip, "drop els_send op %u d_id %x\n",
804 * @fip: The FCoE controller to free FCFs on
819 static unsigned long fcoe_ctlr_age_fcfs(struct fcoe_ctlr *fip)
830 list_for_each_entry_safe(fcf, next, &fip->fcfs, list) {
832 if (fip->sel_fcf == fcf) {
836 miss_cnt = this_cpu_inc_return(fip->lp->stats->MissDiscAdvCount);
840 fip->lp->host->host_no, fcf->fabric_name,
848 if (fip->sel_fcf == fcf)
849 fip->sel_fcf = NULL;
857 this_cpu_inc(fip->lp->stats->VLinkFailureCount);
872 if (sel_time && !fip->sel_fcf && !fip->sel_time) {
874 fip->sel_time = sel_time;
882 * @fip: The FCoE controller receiving the advertisement
889 static int fcoe_ctlr_parse_adv(struct fcoe_ctlr *fip,
926 LIBFCOE_FIP_DBG(fip, "Duplicate Critical "
945 LIBFCOE_FIP_DBG(fip,
986 LIBFCOE_FIP_DBG(fip, "unexpected descriptor type %x "
1001 LIBFCOE_FIP_DBG(fip, "adv missing descriptors mask %x\n",
1008 LIBFCOE_FIP_DBG(fip, "FIP length error in descriptor type %x len %zu\n",
1015 * @fip: The FCoE controller receiving the advertisement
1018 static void fcoe_ctlr_recv_adv(struct fcoe_ctlr *fip, struct sk_buff *skb)
1028 if (fcoe_ctlr_parse_adv(fip, skb, &new))
1031 mutex_lock(&fip->ctlr_mutex);
1032 first = list_empty(&fip->fcfs);
1033 list_for_each_entry(fcf, &fip->fcfs, list) {
1043 if (fip->fcf_count >= FCOE_CTLR_FCF_LIMIT)
1051 fcf->fip = fip;
1071 if (fcf == fip->sel_fcf && !fcf->fd_flags) {
1072 fip->ctlr_ka_time -= fcf->fka_period;
1073 fip->ctlr_ka_time += new.fka_period;
1074 if (time_before(fip->ctlr_ka_time, fip->timer.expires))
1075 mod_timer(&fip->timer, fip->ctlr_ka_time);
1084 LIBFCOE_FIP_DBG(fip, "New FCF fab %16.16llx mac %pM\n",
1092 fcoe_ctlr_solicit(fip, fcf);
1100 if (first && time_after(jiffies, fip->sol_time + sol_tov))
1101 fcoe_ctlr_solicit(fip, NULL);
1110 list_move(&fcf->list, &fip->fcfs);
1116 if (mtu_valid && !fip->sel_fcf && !fip->sel_time &&
1118 fip->sel_time = jiffies +
1120 if (!timer_pending(&fip->timer) ||
1121 time_before(fip->sel_time, fip->timer.expires))
1122 mod_timer(&fip->timer, fip->sel_time);
1126 mutex_unlock(&fip->ctlr_mutex);
1131 * @fip: The FCoE controller which received the packet
1134 static void fcoe_ctlr_recv_els(struct fcoe_ctlr *fip, struct sk_buff *skb)
1136 struct fc_lport *lport = fip->lp;
1172 LIBFCOE_FIP_DBG(fip, "Duplicate Critical "
1180 sel = fip->sel_fcf;
1182 LIBFCOE_FIP_DBG(fip, "FIP descriptors "
1212 LIBFCOE_FIP_DBG(fip, "FIP descriptors "
1226 LIBFCOE_FIP_DBG(fip, "unexpected descriptor type %x "
1232 LIBFCOE_FIP_DBG(fip, "FIP descriptors "
1247 sub == FIP_SC_REP && fip->mode != FIP_MODE_VN2VN) {
1250 LIBFCOE_FIP_DBG(fip,
1257 if (fip->flogi_oxid == ntohs(fh->fh_ox_id)) {
1258 fip->flogi_oxid = FC_XID_UNKNOWN;
1260 fcoe_ctlr_announce(fip);
1263 !fcoe_ctlr_flogi_retry(fip))
1269 LIBFCOE_FIP_DBG(fip, "Missing critical descriptors "
1293 LIBFCOE_FIP_DBG(fip, "FIP length error in descriptor type %x len %zu\n",
1301 * @fip: The FCoE controller that received the frame
1307 static void fcoe_ctlr_recv_clr_vlink(struct fcoe_ctlr *fip,
1316 struct fcoe_fcf *fcf = fip->sel_fcf;
1317 struct fc_lport *lport = fip->lp;
1326 LIBFCOE_FIP_DBG(fip, "Clear Virtual Link received\n");
1333 LIBFCOE_FIP_DBG(fip, "Resetting fcoe_ctlr as FCF has not been "
1335 mutex_lock(&fip->ctlr_mutex);
1336 fcoe_ctlr_reset(fip);
1337 mutex_unlock(&fip->ctlr_mutex);
1347 LIBFCOE_FIP_DBG(fip, "Dropping CVL due to source address "
1357 LIBFCOE_FIP_DBG(fip, "lport not logged in, resoliciting\n");
1358 mutex_lock(&fip->ctlr_mutex);
1359 fcoe_ctlr_reset(fip);
1360 mutex_unlock(&fip->ctlr_mutex);
1361 fc_lport_reset(fip->lp);
1362 fcoe_ctlr_solicit(fip, NULL);
1395 LIBFCOE_FIP_DBG(fip, "Duplicate Critical "
1424 mutex_lock(&fip->ctlr_mutex);
1426 fcoe_ctlr_reset(fip);
1427 mutex_unlock(&fip->ctlr_mutex);
1444 LIBFCOE_FIP_DBG(fip, "missing descriptors mask %x\n",
1447 LIBFCOE_FIP_DBG(fip, "CVL: no Vx_Port descriptor found\n");
1452 mutex_lock(&fip->ctlr_mutex);
1454 fcoe_ctlr_reset(fip);
1455 mutex_unlock(&fip->ctlr_mutex);
1462 fc_lport_reset(fip->lp);
1463 fcoe_ctlr_solicit(fip, NULL);
1467 LIBFCOE_FIP_DBG(fip, "performing Clear Virtual Link\n");
1479 if (!ether_addr_equal(fip->get_src_addr(vn_port),
1496 fc_lport_reset(fip->lp);
1497 fcoe_ctlr_solicit(fip, NULL);
1507 * @fip: The FCoE controller that received the packet
1512 void fcoe_ctlr_recv(struct fcoe_ctlr *fip, struct sk_buff *skb)
1517 skb_queue_tail(&fip->fip_recv_list, skb);
1518 schedule_work(&fip->recv_work);
1524 * @fip: The FCoE controller that received the frame
1529 static int fcoe_ctlr_recv_handler(struct fcoe_ctlr *fip, struct sk_buff *skb)
1543 if (fip->mode == FIP_MODE_VN2VN) {
1544 if (!ether_addr_equal(eh->h_dest, fip->ctl_src_addr) &&
1548 } else if (!ether_addr_equal(eh->h_dest, fip->ctl_src_addr) &&
1560 mutex_lock(&fip->ctlr_mutex);
1561 state = fip->state;
1563 fip->map_dest = 0;
1564 fcoe_ctlr_set_state(fip, FIP_ST_ENABLED);
1566 LIBFCOE_FIP_DBG(fip, "Using FIP mode\n");
1568 fip_vlan_resp = fip->fip_resp;
1569 mutex_unlock(&fip->ctlr_mutex);
1571 if (fip->mode == FIP_MODE_VN2VN && op == FIP_OP_VN2VN)
1572 return fcoe_ctlr_vn_recv(fip, skb);
1575 LIBFCOE_FIP_DBG(fip, "fip vlan discovery\n");
1576 return fcoe_ctlr_vlan_recv(fip, skb);
1584 fcoe_ctlr_recv_els(fip, skb); /* consumes skb */
1592 fcoe_ctlr_recv_adv(fip, skb);
1594 fcoe_ctlr_recv_clr_vlink(fip, skb);
1604 * @fip: The FCoE controller
1615 static struct fcoe_fcf *fcoe_ctlr_select(struct fcoe_ctlr *fip)
1618 struct fcoe_fcf *best = fip->sel_fcf;
1620 list_for_each_entry(fcf, &fip->fcfs, list) {
1621 LIBFCOE_FIP_DBG(fip, "consider FCF fab %16.16llx "
1628 LIBFCOE_FIP_DBG(fip, "FCF for fab %16.16llx "
1641 LIBFCOE_FIP_DBG(fip, "Conflicting fabric, VFID, "
1646 fip->sel_fcf = best;
1648 LIBFCOE_FIP_DBG(fip, "using FCF mac %pM\n", best->fcf_mac);
1649 fip->port_ka_time = jiffies +
1651 fip->ctlr_ka_time = jiffies + best->fka_period;
1652 if (time_before(fip->ctlr_ka_time, fip->timer.expires))
1653 mod_timer(&fip->timer, fip->ctlr_ka_time);
1660 * @fip: The FCoE controller
1665 * Caller must verify that fip->sel_fcf is not NULL.
1667 static int fcoe_ctlr_flogi_send_locked(struct fcoe_ctlr *fip)
1674 skb_orig = fip->flogi_req;
1684 fip->flogi_req = NULL;
1687 error = fcoe_ctlr_encaps(fip, fip->lp, FIP_DT_FLOGI, skb,
1693 fip->send(fip, skb);
1694 fip->sel_fcf->flogi_sent = 1;
1700 * @fip: The FCoE controller
1705 static int fcoe_ctlr_flogi_retry(struct fcoe_ctlr *fip)
1710 mutex_lock(&fip->ctlr_mutex);
1711 spin_lock_bh(&fip->ctlr_lock);
1712 LIBFCOE_FIP_DBG(fip, "re-sending FLOGI - reselect\n");
1713 fcf = fcoe_ctlr_select(fip);
1715 kfree_skb(fip->flogi_req);
1716 fip->flogi_req = NULL;
1719 fcoe_ctlr_solicit(fip, NULL);
1720 error = fcoe_ctlr_flogi_send_locked(fip);
1722 spin_unlock_bh(&fip->ctlr_lock);
1723 mutex_unlock(&fip->ctlr_mutex);
1730 * @fip: The FCoE controller that timed out
1736 static void fcoe_ctlr_flogi_send(struct fcoe_ctlr *fip)
1740 spin_lock_bh(&fip->ctlr_lock);
1741 fcf = fip->sel_fcf;
1742 if (!fcf || !fip->flogi_req_send)
1745 LIBFCOE_FIP_DBG(fip, "sending FLOGI\n");
1752 LIBFCOE_FIP_DBG(fip, "sending FLOGI - reselect\n");
1753 fcf = fcoe_ctlr_select(fip);
1755 LIBFCOE_FIP_DBG(fip, "sending FLOGI - clearing\n");
1756 list_for_each_entry(fcf, &fip->fcfs, list)
1758 fcf = fcoe_ctlr_select(fip);
1762 fcoe_ctlr_flogi_send_locked(fip);
1763 fip->flogi_req_send = 0;
1765 LIBFCOE_FIP_DBG(fip, "No FCF selected - defer send\n");
1767 spin_unlock_bh(&fip->ctlr_lock);
1776 struct fcoe_ctlr *fip = from_timer(fip, t, timer);
1778 schedule_work(&fip->timer_work);
1790 struct fcoe_ctlr *fip;
1800 fip = container_of(work, struct fcoe_ctlr, timer_work);
1801 if (fip->mode == FIP_MODE_VN2VN)
1802 return fcoe_ctlr_vn_timeout(fip);
1803 mutex_lock(&fip->ctlr_mutex);
1804 if (fip->state == FIP_ST_DISABLED) {
1805 mutex_unlock(&fip->ctlr_mutex);
1809 fcf = fip->sel_fcf;
1810 next_timer = fcoe_ctlr_age_fcfs(fip);
1812 sel = fip->sel_fcf;
1813 if (!sel && fip->sel_time) {
1814 if (time_after_eq(jiffies, fip->sel_time)) {
1815 sel = fcoe_ctlr_select(fip);
1816 fip->sel_time = 0;
1817 } else if (time_after(next_timer, fip->sel_time))
1818 next_timer = fip->sel_time;
1821 if (sel && fip->flogi_req_send)
1822 fcoe_ctlr_flogi_send(fip);
1827 if (time_after_eq(jiffies, fip->ctlr_ka_time)) {
1828 fip->ctlr_ka_time = jiffies + sel->fka_period;
1831 if (time_after(next_timer, fip->ctlr_ka_time))
1832 next_timer = fip->ctlr_ka_time;
1834 if (time_after_eq(jiffies, fip->port_ka_time)) {
1835 fip->port_ka_time = jiffies +
1839 if (time_after(next_timer, fip->port_ka_time))
1840 next_timer = fip->port_ka_time;
1842 if (!list_empty(&fip->fcfs))
1843 mod_timer(&fip->timer, next_timer);
1844 mutex_unlock(&fip->ctlr_mutex);
1847 fc_lport_reset(fip->lp);
1849 fcoe_ctlr_solicit(fip, NULL);
1853 fcoe_ctlr_send_keep_alive(fip, NULL, 0, fip->ctl_src_addr);
1856 mutex_lock(&fip->lp->lp_mutex);
1857 mac = fip->get_src_addr(fip->lp);
1858 fcoe_ctlr_send_keep_alive(fip, fip->lp, 1, mac);
1859 list_for_each_entry(vport, &fip->lp->vports, list) {
1860 mac = fip->get_src_addr(vport);
1861 fcoe_ctlr_send_keep_alive(fip, vport, 1, mac);
1863 mutex_unlock(&fip->lp->lp_mutex);
1873 struct fcoe_ctlr *fip;
1876 fip = container_of(recv_work, struct fcoe_ctlr, recv_work);
1877 while ((skb = skb_dequeue(&fip->fip_recv_list)))
1878 fcoe_ctlr_recv_handler(fip, skb);
1883 * @fip: The FCoE controller
1890 * by fip->flogi_oxid != FC_XID_UNKNOWN.
1897 int fcoe_ctlr_recv_flogi(struct fcoe_ctlr *fip, struct fc_lport *lport,
1911 fip->flogi_oxid == ntohs(fh->fh_ox_id)) {
1913 mutex_lock(&fip->ctlr_mutex);
1914 if (fip->state != FIP_ST_AUTO && fip->state != FIP_ST_NON_FIP) {
1915 mutex_unlock(&fip->ctlr_mutex);
1918 fcoe_ctlr_set_state(fip, FIP_ST_NON_FIP);
1919 LIBFCOE_FIP_DBG(fip,
1929 fcoe_ctlr_map_dest(fip);
1931 memcpy(fip->dest_addr, sa, ETH_ALEN);
1932 fip->map_dest = 0;
1934 fip->flogi_oxid = FC_XID_UNKNOWN;
1935 mutex_unlock(&fip->ctlr_mutex);
1941 mutex_lock(&fip->ctlr_mutex);
1942 if (fip->state == FIP_ST_AUTO || fip->state == FIP_ST_NON_FIP) {
1943 memcpy(fip->dest_addr, sa, ETH_ALEN);
1944 fip->map_dest = 0;
1945 if (fip->state == FIP_ST_AUTO)
1946 LIBFCOE_FIP_DBG(fip, "received non-FIP FLOGI. "
1948 fcoe_ctlr_set_state(fip, FIP_ST_NON_FIP);
1950 mutex_unlock(&fip->ctlr_mutex);
2008 * @fip: The FCoE controller
2013 static void fcoe_ctlr_vn_send(struct fcoe_ctlr *fip,
2020 struct fip_header fip;
2051 hton24(frame->eth.h_source + 3, fip->port_id);
2053 memcpy(frame->eth.h_source, fip->ctl_src_addr, ETH_ALEN);
2057 frame->fip.fip_ver = FIP_VER_ENCAPS(FIP_VER);
2058 frame->fip.fip_op = htons(FIP_OP_VN2VN);
2059 frame->fip.fip_subcode = sub;
2060 frame->fip.fip_dl_len = htons(dlen / FIP_BPW);
2064 memcpy(frame->mac.fd_mac, fip->ctl_src_addr, ETH_ALEN);
2068 put_unaligned_be64(fip->lp->wwnn, &frame->wwnn.fd_wwn);
2073 hton24(frame->vn.fd_mac + 3, fip->port_id);
2074 hton24(frame->vn.fd_fc_id, fip->port_id);
2075 put_unaligned_be64(fip->lp->wwpn, &frame->vn.fd_wwpn);
2085 ff->fd_fts = fip->lp->fcts;
2088 if (fip->lp->service_params & FCP_SPPF_INIT_FCN)
2090 if (fip->lp->service_params & FCP_SPPF_TARG_FCN)
2098 size->fd_size = htons(fcoe_ctlr_fcoe_size(fip));
2103 skb->priority = fip->priority;
2107 fip->send(fip, skb);
2122 struct fcoe_ctlr *fip = lport->disc.priv;
2125 LIBFCOE_FIP_DBG(fip, "vn_rport_callback %x event %d\n",
2128 mutex_lock(&fip->ctlr_mutex);
2138 LIBFCOE_FIP_DBG(fip,
2147 mutex_unlock(&fip->ctlr_mutex);
2184 struct fcoe_ctlr *fip = lport->disc.priv;
2186 mutex_lock(&fip->ctlr_mutex);
2188 mutex_unlock(&fip->ctlr_mutex);
2207 * @fip: The FCoE controller
2211 static void fcoe_ctlr_vn_restart(struct fcoe_ctlr *fip)
2216 fcoe_ctlr_disc_stop_locked(fip->lp);
2225 port_id = fip->port_id;
2226 if (fip->probe_tries)
2227 port_id = prandom_u32_state(&fip->rnd_state) & 0xffff;
2229 port_id = fip->lp->wwpn & 0xffff;
2232 fip->port_id = port_id;
2234 if (fip->probe_tries < FIP_VN_RLIM_COUNT) {
2235 fip->probe_tries++;
2239 mod_timer(&fip->timer, jiffies + msecs_to_jiffies(wait));
2240 fcoe_ctlr_set_state(fip, FIP_ST_VNMP_START);
2245 * @fip: The FCoE controller
2249 static void fcoe_ctlr_vn_start(struct fcoe_ctlr *fip)
2251 fip->probe_tries = 0;
2252 prandom_seed_state(&fip->rnd_state, fip->lp->wwpn);
2253 fcoe_ctlr_vn_restart(fip);
2258 * @fip: The FCoE controller
2265 static int fcoe_ctlr_vn_parse(struct fcoe_ctlr *fip,
2299 LIBFCOE_FIP_DBG(fip, "vn_parse unknown subcode %u\n", sub);
2316 LIBFCOE_FIP_DBG(fip,
2332 LIBFCOE_FIP_DBG(fip,
2366 LIBFCOE_FIP_DBG(fip, "unexpected descriptor type %x "
2379 LIBFCOE_FIP_DBG(fip, "FIP length error in descriptor type %x len %zu\n",
2386 * @fip: The FCoE controller
2390 static void fcoe_ctlr_vn_send_claim(struct fcoe_ctlr *fip)
2392 fcoe_ctlr_vn_send(fip, FIP_SC_VN_CLAIM_NOTIFY, fcoe_all_vn2vn, 0);
2393 fip->sol_time = jiffies;
2398 * @fip: The FCoE controller
2403 static void fcoe_ctlr_vn_probe_req(struct fcoe_ctlr *fip,
2406 if (frport->rdata.ids.port_id != fip->port_id)
2409 switch (fip->state) {
2412 LIBFCOE_FIP_DBG(fip, "vn_probe_req: send reply, state %x\n",
2413 fip->state);
2414 fcoe_ctlr_vn_send(fip, FIP_SC_VN_PROBE_REP,
2426 if (fip->lp->wwpn > frport->rdata.ids.port_name &&
2428 LIBFCOE_FIP_DBG(fip, "vn_probe_req: "
2430 fcoe_ctlr_vn_send(fip, FIP_SC_VN_PROBE_REP,
2436 LIBFCOE_FIP_DBG(fip, "vn_probe_req: "
2438 fcoe_ctlr_vn_restart(fip);
2441 LIBFCOE_FIP_DBG(fip, "vn_probe_req: ignore state %x\n",
2442 fip->state);
2449 * @fip: The FCoE controller
2454 static void fcoe_ctlr_vn_probe_reply(struct fcoe_ctlr *fip,
2457 if (frport->rdata.ids.port_id != fip->port_id)
2459 switch (fip->state) {
2464 LIBFCOE_FIP_DBG(fip, "vn_probe_reply: restart state %x\n",
2465 fip->state);
2466 fcoe_ctlr_vn_restart(fip);
2469 LIBFCOE_FIP_DBG(fip, "vn_probe_reply: send claim notify\n");
2470 fcoe_ctlr_vn_send_claim(fip);
2479 * @fip: The FCoE controller
2484 static void fcoe_ctlr_vn_add(struct fcoe_ctlr *fip, struct fcoe_rport *new)
2486 struct fc_lport *lport = fip->lp;
2493 if (port_id == fip->port_id)
2514 LIBFCOE_FIP_DBG(fip, "vn_add rport logoff %6.6x\n", port_id);
2523 LIBFCOE_FIP_DBG(fip, "vn_add rport %6.6x %s state %d\n",
2536 * @fip: The FCoE controller
2542 static int fcoe_ctlr_vn_lookup(struct fcoe_ctlr *fip, u32 port_id, u8 *mac)
2544 struct fc_lport *lport = fip->lp;
2561 * @fip: The FCoE controller
2566 static void fcoe_ctlr_vn_claim_notify(struct fcoe_ctlr *fip,
2570 LIBFCOE_FIP_DBG(fip, "send probe req for P2P/REC\n");
2571 fcoe_ctlr_vn_send(fip, FIP_SC_VN_PROBE_REQ, fcoe_all_vn2vn, 0);
2574 switch (fip->state) {
2578 if (new->rdata.ids.port_id == fip->port_id) {
2579 LIBFCOE_FIP_DBG(fip, "vn_claim_notify: "
2581 fip->state);
2582 fcoe_ctlr_vn_restart(fip);
2587 if (new->rdata.ids.port_id == fip->port_id) {
2588 if (new->rdata.ids.port_name > fip->lp->wwpn) {
2589 LIBFCOE_FIP_DBG(fip, "vn_claim_notify: "
2591 fcoe_ctlr_vn_restart(fip);
2594 LIBFCOE_FIP_DBG(fip, "vn_claim_notify: "
2596 fcoe_ctlr_vn_send_claim(fip);
2599 LIBFCOE_FIP_DBG(fip, "vn_claim_notify: send reply to %x\n",
2601 fcoe_ctlr_vn_send(fip, FIP_SC_VN_CLAIM_REP, new->enode_mac,
2603 fcoe_ctlr_fcoe_size(fip)));
2604 fcoe_ctlr_vn_add(fip, new);
2607 LIBFCOE_FIP_DBG(fip, "vn_claim_notify: "
2616 * @fip: The FCoE controller that received the frame
2621 static void fcoe_ctlr_vn_claim_resp(struct fcoe_ctlr *fip,
2624 LIBFCOE_FIP_DBG(fip, "claim resp from from rport %x - state %s\n",
2625 new->rdata.ids.port_id, fcoe_ctlr_state(fip->state));
2626 if (fip->state == FIP_ST_VNMP_UP || fip->state == FIP_ST_VNMP_CLAIM)
2627 fcoe_ctlr_vn_add(fip, new);
2632 * @fip: The FCoE controller that received the frame
2637 static void fcoe_ctlr_vn_beacon(struct fcoe_ctlr *fip,
2640 struct fc_lport *lport = fip->lp;
2645 LIBFCOE_FIP_DBG(fip, "p2p beacon while in vn2vn mode\n");
2646 fcoe_ctlr_vn_send(fip, FIP_SC_VN_PROBE_REQ, fcoe_all_vn2vn, 0);
2655 LIBFCOE_FIP_DBG(fip, "beacon from rport %x\n",
2657 if (!frport->time && fip->state == FIP_ST_VNMP_UP) {
2658 LIBFCOE_FIP_DBG(fip, "beacon expired "
2668 if (fip->state != FIP_ST_VNMP_UP)
2676 LIBFCOE_FIP_DBG(fip, "beacon from new rport %x. sending claim notify\n",
2679 fip->sol_time + msecs_to_jiffies(FIP_VN_ANN_WAIT)))
2680 fcoe_ctlr_vn_send_claim(fip);
2685 * @fip: The FCoE controller
2691 static unsigned long fcoe_ctlr_vn_age(struct fcoe_ctlr *fip)
2693 struct fc_lport *lport = fip->lp;
2713 LIBFCOE_FIP_DBG(fip,
2727 * @fip: The FCoE controller that received the frame
2733 static int fcoe_ctlr_vn_recv(struct fcoe_ctlr *fip, struct sk_buff *skb)
2743 if (fip->lp->vlan)
2746 if (vlan_id && vlan_id != fip->lp->vlan) {
2747 LIBFCOE_FIP_DBG(fip, "vn_recv drop frame sub %x vlan %d\n",
2753 rc = fcoe_ctlr_vn_parse(fip, skb, &frport);
2755 LIBFCOE_FIP_DBG(fip, "vn_recv vn_parse error %d\n", rc);
2759 mutex_lock(&fip->ctlr_mutex);
2762 fcoe_ctlr_vn_probe_req(fip, &frport);
2765 fcoe_ctlr_vn_probe_reply(fip, &frport);
2768 fcoe_ctlr_vn_claim_notify(fip, &frport);
2771 fcoe_ctlr_vn_claim_resp(fip, &frport);
2774 fcoe_ctlr_vn_beacon(fip, &frport);
2777 LIBFCOE_FIP_DBG(fip, "vn_recv unknown subcode %d\n", sub);
2781 mutex_unlock(&fip->ctlr_mutex);
2789 * @fip: The FCoE controller
2796 static int fcoe_ctlr_vlan_parse(struct fcoe_ctlr *fip,
2819 LIBFCOE_FIP_DBG(fip, "vn_parse unknown subcode %u\n", sub);
2836 LIBFCOE_FIP_DBG(fip,
2852 LIBFCOE_FIP_DBG(fip,
2867 LIBFCOE_FIP_DBG(fip, "unexpected descriptor type %x "
2880 LIBFCOE_FIP_DBG(fip, "FIP length error in descriptor type %x len %zu\n",
2887 * @fip: The FCoE controller
2891 static void fcoe_ctlr_vlan_send(struct fcoe_ctlr *fip,
2898 struct fip_header fip;
2913 LIBFCOE_FIP_DBG(fip, "fip %s vlan notification, vlan %d\n",
2914 fip->mode == FIP_MODE_VN2VN ? "vn2vn" : "fcf",
2915 fip->lp->vlan);
2921 memcpy(frame->eth.h_source, fip->ctl_src_addr, ETH_ALEN);
2924 frame->fip.fip_ver = FIP_VER_ENCAPS(FIP_VER);
2925 frame->fip.fip_op = htons(FIP_OP_VLAN);
2926 frame->fip.fip_subcode = sub;
2927 frame->fip.fip_dl_len = htons(dlen / FIP_BPW);
2931 memcpy(frame->mac.fd_mac, fip->ctl_src_addr, ETH_ALEN);
2935 put_unaligned_be16(fip->lp->vlan, &frame->vlan.fd_vlan);
2939 skb->priority = fip->priority;
2943 fip->send(fip, skb);
2948 * @fip: The FCoE controller
2953 static void fcoe_ctlr_vlan_disc_reply(struct fcoe_ctlr *fip,
2958 if (fip->mode == FIP_MODE_VN2VN)
2961 fcoe_ctlr_vlan_send(fip, sub, frport->enode_mac);
2966 * @fip: The FCoE controller
2969 static int fcoe_ctlr_vlan_recv(struct fcoe_ctlr *fip, struct sk_buff *skb)
2978 rc = fcoe_ctlr_vlan_parse(fip, skb, &frport);
2980 LIBFCOE_FIP_DBG(fip, "vlan_recv vlan_parse error %d\n", rc);
2983 mutex_lock(&fip->ctlr_mutex);
2985 fcoe_ctlr_vlan_disc_reply(fip, &frport);
2986 mutex_unlock(&fip->ctlr_mutex);
3027 struct fcoe_ctlr *fip = disc->priv;
3033 schedule_work(&fip->timer_work);
3039 * @fip: The FCoE controller
3045 static void fcoe_ctlr_vn_disc(struct fcoe_ctlr *fip)
3047 struct fc_lport *lport = fip->lp;
3071 * @fip: The FCoE controller
3073 static void fcoe_ctlr_vn_timeout(struct fcoe_ctlr *fip)
3079 mutex_lock(&fip->ctlr_mutex);
3080 switch (fip->state) {
3082 fcoe_ctlr_set_state(fip, FIP_ST_VNMP_PROBE1);
3083 LIBFCOE_FIP_DBG(fip, "vn_timeout: send 1st probe request\n");
3084 fcoe_ctlr_vn_send(fip, FIP_SC_VN_PROBE_REQ, fcoe_all_vn2vn, 0);
3088 fcoe_ctlr_set_state(fip, FIP_ST_VNMP_PROBE2);
3089 LIBFCOE_FIP_DBG(fip, "vn_timeout: send 2nd probe request\n");
3090 fcoe_ctlr_vn_send(fip, FIP_SC_VN_PROBE_REQ, fcoe_all_vn2vn, 0);
3094 fcoe_ctlr_set_state(fip, FIP_ST_VNMP_CLAIM);
3095 new_port_id = fip->port_id;
3098 fcoe_ctlr_map_dest(fip);
3099 fip->update_mac(fip->lp, mac);
3100 LIBFCOE_FIP_DBG(fip, "vn_timeout: send claim notify\n");
3101 fcoe_ctlr_vn_send_claim(fip);
3109 next_time = fip->sol_time + msecs_to_jiffies(FIP_VN_ANN_WAIT);
3111 fcoe_ctlr_set_state(fip, FIP_ST_VNMP_UP);
3112 LIBFCOE_FIP_DBG(fip, "vn_timeout: send vn2vn beacon\n");
3113 fcoe_ctlr_vn_send(fip, FIP_SC_VN_BEACON,
3116 fip->port_ka_time = next_time;
3118 fcoe_ctlr_vn_disc(fip);
3121 next_time = fcoe_ctlr_vn_age(fip);
3122 if (time_after_eq(jiffies, fip->port_ka_time)) {
3123 LIBFCOE_FIP_DBG(fip, "vn_timeout: send vn2vn beacon\n");
3124 fcoe_ctlr_vn_send(fip, FIP_SC_VN_BEACON,
3126 fip->port_ka_time = jiffies +
3130 if (time_before(fip->port_ka_time, next_time))
3131 next_time = fip->port_ka_time;
3136 WARN(1, "unexpected state %d\n", fip->state);
3139 mod_timer(&fip->timer, next_time);
3141 mutex_unlock(&fip->ctlr_mutex);
3145 fc_lport_set_local_id(fip->lp, new_port_id);
3151 * @fip: The FCoE controller whose mode is changing
3152 * @fip_mode: The new fip mode
3160 static void fcoe_ctlr_mode_set(struct fc_lport *lport, struct fcoe_ctlr *fip,
3175 priv = fip;
3192 * @fip: The FCoE controller in use by the local port
3198 int fcoe_libfc_config(struct fc_lport *lport, struct fcoe_ctlr *fip,
3209 fcoe_ctlr_mode_set(lport, fip, fip->mode);
3217 struct fcoe_ctlr *fip = fcoe_ctlr_device_priv(ctlr_dev);
3220 mutex_lock(&fip->ctlr_mutex);
3225 fcf_dev->selected = (fcf == fip->sel_fcf) ? 1 : 0;
3230 mutex_unlock(&fip->ctlr_mutex);