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)
831 stats = per_cpu_ptr(fip->lp->stats, get_cpu());
833 list_for_each_entry_safe(fcf, next, &fip->fcfs, list) {
835 if (fip->sel_fcf == fcf) {
841 fip->lp->host->host_no, fcf->fabric_name,
849 if (fip->sel_fcf == fcf)
850 fip->sel_fcf = NULL;
874 if (sel_time && !fip->sel_fcf && !fip->sel_time) {
876 fip->sel_time = sel_time;
884 * @fip: The FCoE controller receiving the advertisement
891 static int fcoe_ctlr_parse_adv(struct fcoe_ctlr *fip,
928 LIBFCOE_FIP_DBG(fip, "Duplicate Critical "
947 LIBFCOE_FIP_DBG(fip,
988 LIBFCOE_FIP_DBG(fip, "unexpected descriptor type %x "
1003 LIBFCOE_FIP_DBG(fip, "adv missing descriptors mask %x\n",
1010 LIBFCOE_FIP_DBG(fip, "FIP length error in descriptor type %x len %zu\n",
1017 * @fip: The FCoE controller receiving the advertisement
1020 static void fcoe_ctlr_recv_adv(struct fcoe_ctlr *fip, struct sk_buff *skb)
1030 if (fcoe_ctlr_parse_adv(fip, skb, &new))
1033 mutex_lock(&fip->ctlr_mutex);
1034 first = list_empty(&fip->fcfs);
1035 list_for_each_entry(fcf, &fip->fcfs, list) {
1045 if (fip->fcf_count >= FCOE_CTLR_FCF_LIMIT)
1053 fcf->fip = fip;
1073 if (fcf == fip->sel_fcf && !fcf->fd_flags) {
1074 fip->ctlr_ka_time -= fcf->fka_period;
1075 fip->ctlr_ka_time += new.fka_period;
1076 if (time_before(fip->ctlr_ka_time, fip->timer.expires))
1077 mod_timer(&fip->timer, fip->ctlr_ka_time);
1086 LIBFCOE_FIP_DBG(fip, "New FCF fab %16.16llx mac %pM\n",
1094 fcoe_ctlr_solicit(fip, fcf);
1102 if (first && time_after(jiffies, fip->sol_time + sol_tov))
1103 fcoe_ctlr_solicit(fip, NULL);
1112 list_move(&fcf->list, &fip->fcfs);
1118 if (mtu_valid && !fip->sel_fcf && !fip->sel_time &&
1120 fip->sel_time = jiffies +
1122 if (!timer_pending(&fip->timer) ||
1123 time_before(fip->sel_time, fip->timer.expires))
1124 mod_timer(&fip->timer, fip->sel_time);
1128 mutex_unlock(&fip->ctlr_mutex);
1133 * @fip: The FCoE controller which received the packet
1136 static void fcoe_ctlr_recv_els(struct fcoe_ctlr *fip, struct sk_buff *skb)
1138 struct fc_lport *lport = fip->lp;
1175 LIBFCOE_FIP_DBG(fip, "Duplicate Critical "
1183 sel = fip->sel_fcf;
1185 LIBFCOE_FIP_DBG(fip, "FIP descriptors "
1215 LIBFCOE_FIP_DBG(fip, "FIP descriptors "
1229 LIBFCOE_FIP_DBG(fip, "unexpected descriptor type %x "
1235 LIBFCOE_FIP_DBG(fip, "FIP descriptors "
1250 sub == FIP_SC_REP && fip->mode != FIP_MODE_VN2VN) {
1253 LIBFCOE_FIP_DBG(fip,
1260 if (fip->flogi_oxid == ntohs(fh->fh_ox_id)) {
1261 fip->flogi_oxid = FC_XID_UNKNOWN;
1263 fcoe_ctlr_announce(fip);
1266 !fcoe_ctlr_flogi_retry(fip))
1272 LIBFCOE_FIP_DBG(fip, "Missing critical descriptors "
1298 LIBFCOE_FIP_DBG(fip, "FIP length error in descriptor type %x len %zu\n",
1306 * @fip: The FCoE controller that received the frame
1312 static void fcoe_ctlr_recv_clr_vlink(struct fcoe_ctlr *fip,
1321 struct fcoe_fcf *fcf = fip->sel_fcf;
1322 struct fc_lport *lport = fip->lp;
1331 LIBFCOE_FIP_DBG(fip, "Clear Virtual Link received\n");
1338 LIBFCOE_FIP_DBG(fip, "Resetting fcoe_ctlr as FCF has not been "
1340 mutex_lock(&fip->ctlr_mutex);
1341 fcoe_ctlr_reset(fip);
1342 mutex_unlock(&fip->ctlr_mutex);
1352 LIBFCOE_FIP_DBG(fip, "Dropping CVL due to source address "
1362 LIBFCOE_FIP_DBG(fip, "lport not logged in, resoliciting\n");
1363 mutex_lock(&fip->ctlr_mutex);
1364 fcoe_ctlr_reset(fip);
1365 mutex_unlock(&fip->ctlr_mutex);
1366 fc_lport_reset(fip->lp);
1367 fcoe_ctlr_solicit(fip, NULL);
1400 LIBFCOE_FIP_DBG(fip, "Duplicate Critical "
1429 mutex_lock(&fip->ctlr_mutex);
1433 fcoe_ctlr_reset(fip);
1434 mutex_unlock(&fip->ctlr_mutex);
1451 LIBFCOE_FIP_DBG(fip, "missing descriptors mask %x\n",
1454 LIBFCOE_FIP_DBG(fip, "CVL: no Vx_Port descriptor found\n");
1459 mutex_lock(&fip->ctlr_mutex);
1462 fcoe_ctlr_reset(fip);
1463 mutex_unlock(&fip->ctlr_mutex);
1470 fc_lport_reset(fip->lp);
1471 fcoe_ctlr_solicit(fip, NULL);
1475 LIBFCOE_FIP_DBG(fip, "performing Clear Virtual Link\n");
1487 if (!ether_addr_equal(fip->get_src_addr(vn_port),
1504 fc_lport_reset(fip->lp);
1505 fcoe_ctlr_solicit(fip, NULL);
1515 * @fip: The FCoE controller that received the packet
1520 void fcoe_ctlr_recv(struct fcoe_ctlr *fip, struct sk_buff *skb)
1525 skb_queue_tail(&fip->fip_recv_list, skb);
1526 schedule_work(&fip->recv_work);
1532 * @fip: The FCoE controller that received the frame
1537 static int fcoe_ctlr_recv_handler(struct fcoe_ctlr *fip, struct sk_buff *skb)
1551 if (fip->mode == FIP_MODE_VN2VN) {
1552 if (!ether_addr_equal(eh->h_dest, fip->ctl_src_addr) &&
1556 } else if (!ether_addr_equal(eh->h_dest, fip->ctl_src_addr) &&
1568 mutex_lock(&fip->ctlr_mutex);
1569 state = fip->state;
1571 fip->map_dest = 0;
1572 fcoe_ctlr_set_state(fip, FIP_ST_ENABLED);
1574 LIBFCOE_FIP_DBG(fip, "Using FIP mode\n");
1576 fip_vlan_resp = fip->fip_resp;
1577 mutex_unlock(&fip->ctlr_mutex);
1579 if (fip->mode == FIP_MODE_VN2VN && op == FIP_OP_VN2VN)
1580 return fcoe_ctlr_vn_recv(fip, skb);
1583 LIBFCOE_FIP_DBG(fip, "fip vlan discovery\n");
1584 return fcoe_ctlr_vlan_recv(fip, skb);
1592 fcoe_ctlr_recv_els(fip, skb); /* consumes skb */
1600 fcoe_ctlr_recv_adv(fip, skb);
1602 fcoe_ctlr_recv_clr_vlink(fip, skb);
1612 * @fip: The FCoE controller
1623 static struct fcoe_fcf *fcoe_ctlr_select(struct fcoe_ctlr *fip)
1626 struct fcoe_fcf *best = fip->sel_fcf;
1628 list_for_each_entry(fcf, &fip->fcfs, list) {
1629 LIBFCOE_FIP_DBG(fip, "consider FCF fab %16.16llx "
1636 LIBFCOE_FIP_DBG(fip, "FCF for fab %16.16llx "
1649 LIBFCOE_FIP_DBG(fip, "Conflicting fabric, VFID, "
1654 fip->sel_fcf = best;
1656 LIBFCOE_FIP_DBG(fip, "using FCF mac %pM\n", best->fcf_mac);
1657 fip->port_ka_time = jiffies +
1659 fip->ctlr_ka_time = jiffies + best->fka_period;
1660 if (time_before(fip->ctlr_ka_time, fip->timer.expires))
1661 mod_timer(&fip->timer, fip->ctlr_ka_time);
1668 * @fip: The FCoE controller
1673 * Caller must verify that fip->sel_fcf is not NULL.
1675 static int fcoe_ctlr_flogi_send_locked(struct fcoe_ctlr *fip)
1682 skb_orig = fip->flogi_req;
1692 fip->flogi_req = NULL;
1695 error = fcoe_ctlr_encaps(fip, fip->lp, FIP_DT_FLOGI, skb,
1701 fip->send(fip, skb);
1702 fip->sel_fcf->flogi_sent = 1;
1708 * @fip: The FCoE controller
1713 static int fcoe_ctlr_flogi_retry(struct fcoe_ctlr *fip)
1718 mutex_lock(&fip->ctlr_mutex);
1719 spin_lock_bh(&fip->ctlr_lock);
1720 LIBFCOE_FIP_DBG(fip, "re-sending FLOGI - reselect\n");
1721 fcf = fcoe_ctlr_select(fip);
1723 kfree_skb(fip->flogi_req);
1724 fip->flogi_req = NULL;
1727 fcoe_ctlr_solicit(fip, NULL);
1728 error = fcoe_ctlr_flogi_send_locked(fip);
1730 spin_unlock_bh(&fip->ctlr_lock);
1731 mutex_unlock(&fip->ctlr_mutex);
1738 * @fip: The FCoE controller that timed out
1744 static void fcoe_ctlr_flogi_send(struct fcoe_ctlr *fip)
1748 spin_lock_bh(&fip->ctlr_lock);
1749 fcf = fip->sel_fcf;
1750 if (!fcf || !fip->flogi_req_send)
1753 LIBFCOE_FIP_DBG(fip, "sending FLOGI\n");
1760 LIBFCOE_FIP_DBG(fip, "sending FLOGI - reselect\n");
1761 fcf = fcoe_ctlr_select(fip);
1763 LIBFCOE_FIP_DBG(fip, "sending FLOGI - clearing\n");
1764 list_for_each_entry(fcf, &fip->fcfs, list)
1766 fcf = fcoe_ctlr_select(fip);
1770 fcoe_ctlr_flogi_send_locked(fip);
1771 fip->flogi_req_send = 0;
1773 LIBFCOE_FIP_DBG(fip, "No FCF selected - defer send\n");
1775 spin_unlock_bh(&fip->ctlr_lock);
1784 struct fcoe_ctlr *fip = from_timer(fip, t, timer);
1786 schedule_work(&fip->timer_work);
1798 struct fcoe_ctlr *fip;
1808 fip = container_of(work, struct fcoe_ctlr, timer_work);
1809 if (fip->mode == FIP_MODE_VN2VN)
1810 return fcoe_ctlr_vn_timeout(fip);
1811 mutex_lock(&fip->ctlr_mutex);
1812 if (fip->state == FIP_ST_DISABLED) {
1813 mutex_unlock(&fip->ctlr_mutex);
1817 fcf = fip->sel_fcf;
1818 next_timer = fcoe_ctlr_age_fcfs(fip);
1820 sel = fip->sel_fcf;
1821 if (!sel && fip->sel_time) {
1822 if (time_after_eq(jiffies, fip->sel_time)) {
1823 sel = fcoe_ctlr_select(fip);
1824 fip->sel_time = 0;
1825 } else if (time_after(next_timer, fip->sel_time))
1826 next_timer = fip->sel_time;
1829 if (sel && fip->flogi_req_send)
1830 fcoe_ctlr_flogi_send(fip);
1835 if (time_after_eq(jiffies, fip->ctlr_ka_time)) {
1836 fip->ctlr_ka_time = jiffies + sel->fka_period;
1839 if (time_after(next_timer, fip->ctlr_ka_time))
1840 next_timer = fip->ctlr_ka_time;
1842 if (time_after_eq(jiffies, fip->port_ka_time)) {
1843 fip->port_ka_time = jiffies +
1847 if (time_after(next_timer, fip->port_ka_time))
1848 next_timer = fip->port_ka_time;
1850 if (!list_empty(&fip->fcfs))
1851 mod_timer(&fip->timer, next_timer);
1852 mutex_unlock(&fip->ctlr_mutex);
1855 fc_lport_reset(fip->lp);
1857 fcoe_ctlr_solicit(fip, NULL);
1861 fcoe_ctlr_send_keep_alive(fip, NULL, 0, fip->ctl_src_addr);
1864 mutex_lock(&fip->lp->lp_mutex);
1865 mac = fip->get_src_addr(fip->lp);
1866 fcoe_ctlr_send_keep_alive(fip, fip->lp, 1, mac);
1867 list_for_each_entry(vport, &fip->lp->vports, list) {
1868 mac = fip->get_src_addr(vport);
1869 fcoe_ctlr_send_keep_alive(fip, vport, 1, mac);
1871 mutex_unlock(&fip->lp->lp_mutex);
1881 struct fcoe_ctlr *fip;
1884 fip = container_of(recv_work, struct fcoe_ctlr, recv_work);
1885 while ((skb = skb_dequeue(&fip->fip_recv_list)))
1886 fcoe_ctlr_recv_handler(fip, skb);
1891 * @fip: The FCoE controller
1898 * by fip->flogi_oxid != FC_XID_UNKNOWN.
1905 int fcoe_ctlr_recv_flogi(struct fcoe_ctlr *fip, struct fc_lport *lport,
1919 fip->flogi_oxid == ntohs(fh->fh_ox_id)) {
1921 mutex_lock(&fip->ctlr_mutex);
1922 if (fip->state != FIP_ST_AUTO && fip->state != FIP_ST_NON_FIP) {
1923 mutex_unlock(&fip->ctlr_mutex);
1926 fcoe_ctlr_set_state(fip, FIP_ST_NON_FIP);
1927 LIBFCOE_FIP_DBG(fip,
1937 fcoe_ctlr_map_dest(fip);
1939 memcpy(fip->dest_addr, sa, ETH_ALEN);
1940 fip->map_dest = 0;
1942 fip->flogi_oxid = FC_XID_UNKNOWN;
1943 mutex_unlock(&fip->ctlr_mutex);
1949 mutex_lock(&fip->ctlr_mutex);
1950 if (fip->state == FIP_ST_AUTO || fip->state == FIP_ST_NON_FIP) {
1951 memcpy(fip->dest_addr, sa, ETH_ALEN);
1952 fip->map_dest = 0;
1953 if (fip->state == FIP_ST_AUTO)
1954 LIBFCOE_FIP_DBG(fip, "received non-FIP FLOGI. "
1956 fcoe_ctlr_set_state(fip, FIP_ST_NON_FIP);
1958 mutex_unlock(&fip->ctlr_mutex);
2016 * @fip: The FCoE controller
2021 static void fcoe_ctlr_vn_send(struct fcoe_ctlr *fip,
2028 struct fip_header fip;
2059 hton24(frame->eth.h_source + 3, fip->port_id);
2061 memcpy(frame->eth.h_source, fip->ctl_src_addr, ETH_ALEN);
2065 frame->fip.fip_ver = FIP_VER_ENCAPS(FIP_VER);
2066 frame->fip.fip_op = htons(FIP_OP_VN2VN);
2067 frame->fip.fip_subcode = sub;
2068 frame->fip.fip_dl_len = htons(dlen / FIP_BPW);
2072 memcpy(frame->mac.fd_mac, fip->ctl_src_addr, ETH_ALEN);
2076 put_unaligned_be64(fip->lp->wwnn, &frame->wwnn.fd_wwn);
2081 hton24(frame->vn.fd_mac + 3, fip->port_id);
2082 hton24(frame->vn.fd_fc_id, fip->port_id);
2083 put_unaligned_be64(fip->lp->wwpn, &frame->vn.fd_wwpn);
2093 ff->fd_fts = fip->lp->fcts;
2096 if (fip->lp->service_params & FCP_SPPF_INIT_FCN)
2098 if (fip->lp->service_params & FCP_SPPF_TARG_FCN)
2106 size->fd_size = htons(fcoe_ctlr_fcoe_size(fip));
2111 skb->priority = fip->priority;
2115 fip->send(fip, skb);
2130 struct fcoe_ctlr *fip = lport->disc.priv;
2133 LIBFCOE_FIP_DBG(fip, "vn_rport_callback %x event %d\n",
2136 mutex_lock(&fip->ctlr_mutex);
2146 LIBFCOE_FIP_DBG(fip,
2155 mutex_unlock(&fip->ctlr_mutex);
2192 struct fcoe_ctlr *fip = lport->disc.priv;
2194 mutex_lock(&fip->ctlr_mutex);
2196 mutex_unlock(&fip->ctlr_mutex);
2215 * @fip: The FCoE controller
2219 static void fcoe_ctlr_vn_restart(struct fcoe_ctlr *fip)
2224 fcoe_ctlr_disc_stop_locked(fip->lp);
2233 port_id = fip->port_id;
2234 if (fip->probe_tries)
2235 port_id = prandom_u32_state(&fip->rnd_state) & 0xffff;
2237 port_id = fip->lp->wwpn & 0xffff;
2240 fip->port_id = port_id;
2242 if (fip->probe_tries < FIP_VN_RLIM_COUNT) {
2243 fip->probe_tries++;
2247 mod_timer(&fip->timer, jiffies + msecs_to_jiffies(wait));
2248 fcoe_ctlr_set_state(fip, FIP_ST_VNMP_START);
2253 * @fip: The FCoE controller
2257 static void fcoe_ctlr_vn_start(struct fcoe_ctlr *fip)
2259 fip->probe_tries = 0;
2260 prandom_seed_state(&fip->rnd_state, fip->lp->wwpn);
2261 fcoe_ctlr_vn_restart(fip);
2266 * @fip: The FCoE controller
2273 static int fcoe_ctlr_vn_parse(struct fcoe_ctlr *fip,
2307 LIBFCOE_FIP_DBG(fip, "vn_parse unknown subcode %u\n", sub);
2324 LIBFCOE_FIP_DBG(fip,
2340 LIBFCOE_FIP_DBG(fip,
2374 LIBFCOE_FIP_DBG(fip, "unexpected descriptor type %x "
2387 LIBFCOE_FIP_DBG(fip, "FIP length error in descriptor type %x len %zu\n",
2394 * @fip: The FCoE controller
2398 static void fcoe_ctlr_vn_send_claim(struct fcoe_ctlr *fip)
2400 fcoe_ctlr_vn_send(fip, FIP_SC_VN_CLAIM_NOTIFY, fcoe_all_vn2vn, 0);
2401 fip->sol_time = jiffies;
2406 * @fip: The FCoE controller
2411 static void fcoe_ctlr_vn_probe_req(struct fcoe_ctlr *fip,
2414 if (frport->rdata.ids.port_id != fip->port_id)
2417 switch (fip->state) {
2420 LIBFCOE_FIP_DBG(fip, "vn_probe_req: send reply, state %x\n",
2421 fip->state);
2422 fcoe_ctlr_vn_send(fip, FIP_SC_VN_PROBE_REP,
2434 if (fip->lp->wwpn > frport->rdata.ids.port_name &&
2436 LIBFCOE_FIP_DBG(fip, "vn_probe_req: "
2438 fcoe_ctlr_vn_send(fip, FIP_SC_VN_PROBE_REP,
2444 LIBFCOE_FIP_DBG(fip, "vn_probe_req: "
2446 fcoe_ctlr_vn_restart(fip);
2449 LIBFCOE_FIP_DBG(fip, "vn_probe_req: ignore state %x\n",
2450 fip->state);
2457 * @fip: The FCoE controller
2462 static void fcoe_ctlr_vn_probe_reply(struct fcoe_ctlr *fip,
2465 if (frport->rdata.ids.port_id != fip->port_id)
2467 switch (fip->state) {
2472 LIBFCOE_FIP_DBG(fip, "vn_probe_reply: restart state %x\n",
2473 fip->state);
2474 fcoe_ctlr_vn_restart(fip);
2477 LIBFCOE_FIP_DBG(fip, "vn_probe_reply: send claim notify\n");
2478 fcoe_ctlr_vn_send_claim(fip);
2487 * @fip: The FCoE controller
2492 static void fcoe_ctlr_vn_add(struct fcoe_ctlr *fip, struct fcoe_rport *new)
2494 struct fc_lport *lport = fip->lp;
2501 if (port_id == fip->port_id)
2522 LIBFCOE_FIP_DBG(fip, "vn_add rport logoff %6.6x\n", port_id);
2531 LIBFCOE_FIP_DBG(fip, "vn_add rport %6.6x %s state %d\n",
2544 * @fip: The FCoE controller
2550 static int fcoe_ctlr_vn_lookup(struct fcoe_ctlr *fip, u32 port_id, u8 *mac)
2552 struct fc_lport *lport = fip->lp;
2569 * @fip: The FCoE controller
2574 static void fcoe_ctlr_vn_claim_notify(struct fcoe_ctlr *fip,
2578 LIBFCOE_FIP_DBG(fip, "send probe req for P2P/REC\n");
2579 fcoe_ctlr_vn_send(fip, FIP_SC_VN_PROBE_REQ, fcoe_all_vn2vn, 0);
2582 switch (fip->state) {
2586 if (new->rdata.ids.port_id == fip->port_id) {
2587 LIBFCOE_FIP_DBG(fip, "vn_claim_notify: "
2589 fip->state);
2590 fcoe_ctlr_vn_restart(fip);
2595 if (new->rdata.ids.port_id == fip->port_id) {
2596 if (new->rdata.ids.port_name > fip->lp->wwpn) {
2597 LIBFCOE_FIP_DBG(fip, "vn_claim_notify: "
2599 fcoe_ctlr_vn_restart(fip);
2602 LIBFCOE_FIP_DBG(fip, "vn_claim_notify: "
2604 fcoe_ctlr_vn_send_claim(fip);
2607 LIBFCOE_FIP_DBG(fip, "vn_claim_notify: send reply to %x\n",
2609 fcoe_ctlr_vn_send(fip, FIP_SC_VN_CLAIM_REP, new->enode_mac,
2611 fcoe_ctlr_fcoe_size(fip)));
2612 fcoe_ctlr_vn_add(fip, new);
2615 LIBFCOE_FIP_DBG(fip, "vn_claim_notify: "
2624 * @fip: The FCoE controller that received the frame
2629 static void fcoe_ctlr_vn_claim_resp(struct fcoe_ctlr *fip,
2632 LIBFCOE_FIP_DBG(fip, "claim resp from from rport %x - state %s\n",
2633 new->rdata.ids.port_id, fcoe_ctlr_state(fip->state));
2634 if (fip->state == FIP_ST_VNMP_UP || fip->state == FIP_ST_VNMP_CLAIM)
2635 fcoe_ctlr_vn_add(fip, new);
2640 * @fip: The FCoE controller that received the frame
2645 static void fcoe_ctlr_vn_beacon(struct fcoe_ctlr *fip,
2648 struct fc_lport *lport = fip->lp;
2653 LIBFCOE_FIP_DBG(fip, "p2p beacon while in vn2vn mode\n");
2654 fcoe_ctlr_vn_send(fip, FIP_SC_VN_PROBE_REQ, fcoe_all_vn2vn, 0);
2663 LIBFCOE_FIP_DBG(fip, "beacon from rport %x\n",
2665 if (!frport->time && fip->state == FIP_ST_VNMP_UP) {
2666 LIBFCOE_FIP_DBG(fip, "beacon expired "
2676 if (fip->state != FIP_ST_VNMP_UP)
2684 LIBFCOE_FIP_DBG(fip, "beacon from new rport %x. sending claim notify\n",
2687 fip->sol_time + msecs_to_jiffies(FIP_VN_ANN_WAIT)))
2688 fcoe_ctlr_vn_send_claim(fip);
2693 * @fip: The FCoE controller
2699 static unsigned long fcoe_ctlr_vn_age(struct fcoe_ctlr *fip)
2701 struct fc_lport *lport = fip->lp;
2721 LIBFCOE_FIP_DBG(fip,
2735 * @fip: The FCoE controller that received the frame
2741 static int fcoe_ctlr_vn_recv(struct fcoe_ctlr *fip, struct sk_buff *skb)
2751 if (fip->lp->vlan)
2754 if (vlan_id && vlan_id != fip->lp->vlan) {
2755 LIBFCOE_FIP_DBG(fip, "vn_recv drop frame sub %x vlan %d\n",
2761 rc = fcoe_ctlr_vn_parse(fip, skb, &frport);
2763 LIBFCOE_FIP_DBG(fip, "vn_recv vn_parse error %d\n", rc);
2767 mutex_lock(&fip->ctlr_mutex);
2770 fcoe_ctlr_vn_probe_req(fip, &frport);
2773 fcoe_ctlr_vn_probe_reply(fip, &frport);
2776 fcoe_ctlr_vn_claim_notify(fip, &frport);
2779 fcoe_ctlr_vn_claim_resp(fip, &frport);
2782 fcoe_ctlr_vn_beacon(fip, &frport);
2785 LIBFCOE_FIP_DBG(fip, "vn_recv unknown subcode %d\n", sub);
2789 mutex_unlock(&fip->ctlr_mutex);
2797 * @fip: The FCoE controller
2804 static int fcoe_ctlr_vlan_parse(struct fcoe_ctlr *fip,
2827 LIBFCOE_FIP_DBG(fip, "vn_parse unknown subcode %u\n", sub);
2844 LIBFCOE_FIP_DBG(fip,
2860 LIBFCOE_FIP_DBG(fip,
2875 LIBFCOE_FIP_DBG(fip, "unexpected descriptor type %x "
2888 LIBFCOE_FIP_DBG(fip, "FIP length error in descriptor type %x len %zu\n",
2895 * @fip: The FCoE controller
2899 static void fcoe_ctlr_vlan_send(struct fcoe_ctlr *fip,
2906 struct fip_header fip;
2921 LIBFCOE_FIP_DBG(fip, "fip %s vlan notification, vlan %d\n",
2922 fip->mode == FIP_MODE_VN2VN ? "vn2vn" : "fcf",
2923 fip->lp->vlan);
2929 memcpy(frame->eth.h_source, fip->ctl_src_addr, ETH_ALEN);
2932 frame->fip.fip_ver = FIP_VER_ENCAPS(FIP_VER);
2933 frame->fip.fip_op = htons(FIP_OP_VLAN);
2934 frame->fip.fip_subcode = sub;
2935 frame->fip.fip_dl_len = htons(dlen / FIP_BPW);
2939 memcpy(frame->mac.fd_mac, fip->ctl_src_addr, ETH_ALEN);
2943 put_unaligned_be16(fip->lp->vlan, &frame->vlan.fd_vlan);
2947 skb->priority = fip->priority;
2951 fip->send(fip, skb);
2956 * @fip: The FCoE controller
2961 static void fcoe_ctlr_vlan_disc_reply(struct fcoe_ctlr *fip,
2966 if (fip->mode == FIP_MODE_VN2VN)
2969 fcoe_ctlr_vlan_send(fip, sub, frport->enode_mac);
2974 * @fip: The FCoE controller
2977 static int fcoe_ctlr_vlan_recv(struct fcoe_ctlr *fip, struct sk_buff *skb)
2986 rc = fcoe_ctlr_vlan_parse(fip, skb, &frport);
2988 LIBFCOE_FIP_DBG(fip, "vlan_recv vlan_parse error %d\n", rc);
2991 mutex_lock(&fip->ctlr_mutex);
2993 fcoe_ctlr_vlan_disc_reply(fip, &frport);
2994 mutex_unlock(&fip->ctlr_mutex);
3035 struct fcoe_ctlr *fip = disc->priv;
3041 schedule_work(&fip->timer_work);
3047 * @fip: The FCoE controller
3053 static void fcoe_ctlr_vn_disc(struct fcoe_ctlr *fip)
3055 struct fc_lport *lport = fip->lp;
3079 * @fip: The FCoE controller
3081 static void fcoe_ctlr_vn_timeout(struct fcoe_ctlr *fip)
3087 mutex_lock(&fip->ctlr_mutex);
3088 switch (fip->state) {
3090 fcoe_ctlr_set_state(fip, FIP_ST_VNMP_PROBE1);
3091 LIBFCOE_FIP_DBG(fip, "vn_timeout: send 1st probe request\n");
3092 fcoe_ctlr_vn_send(fip, FIP_SC_VN_PROBE_REQ, fcoe_all_vn2vn, 0);
3096 fcoe_ctlr_set_state(fip, FIP_ST_VNMP_PROBE2);
3097 LIBFCOE_FIP_DBG(fip, "vn_timeout: send 2nd probe request\n");
3098 fcoe_ctlr_vn_send(fip, FIP_SC_VN_PROBE_REQ, fcoe_all_vn2vn, 0);
3102 fcoe_ctlr_set_state(fip, FIP_ST_VNMP_CLAIM);
3103 new_port_id = fip->port_id;
3106 fcoe_ctlr_map_dest(fip);
3107 fip->update_mac(fip->lp, mac);
3108 LIBFCOE_FIP_DBG(fip, "vn_timeout: send claim notify\n");
3109 fcoe_ctlr_vn_send_claim(fip);
3117 next_time = fip->sol_time + msecs_to_jiffies(FIP_VN_ANN_WAIT);
3119 fcoe_ctlr_set_state(fip, FIP_ST_VNMP_UP);
3120 LIBFCOE_FIP_DBG(fip, "vn_timeout: send vn2vn beacon\n");
3121 fcoe_ctlr_vn_send(fip, FIP_SC_VN_BEACON,
3124 fip->port_ka_time = next_time;
3126 fcoe_ctlr_vn_disc(fip);
3129 next_time = fcoe_ctlr_vn_age(fip);
3130 if (time_after_eq(jiffies, fip->port_ka_time)) {
3131 LIBFCOE_FIP_DBG(fip, "vn_timeout: send vn2vn beacon\n");
3132 fcoe_ctlr_vn_send(fip, FIP_SC_VN_BEACON,
3134 fip->port_ka_time = jiffies +
3138 if (time_before(fip->port_ka_time, next_time))
3139 next_time = fip->port_ka_time;
3144 WARN(1, "unexpected state %d\n", fip->state);
3147 mod_timer(&fip->timer, next_time);
3149 mutex_unlock(&fip->ctlr_mutex);
3153 fc_lport_set_local_id(fip->lp, new_port_id);
3159 * @fip: The FCoE controller whose mode is changing
3160 * @fip_mode: The new fip mode
3168 static void fcoe_ctlr_mode_set(struct fc_lport *lport, struct fcoe_ctlr *fip,
3183 priv = fip;
3200 * @fip: The FCoE controller in use by the local port
3206 int fcoe_libfc_config(struct fc_lport *lport, struct fcoe_ctlr *fip,
3217 fcoe_ctlr_mode_set(lport, fip, fip->mode);
3225 struct fcoe_ctlr *fip = fcoe_ctlr_device_priv(ctlr_dev);
3228 mutex_lock(&fip->ctlr_mutex);
3233 fcf_dev->selected = (fcf == fip->sel_fcf) ? 1 : 0;
3238 mutex_unlock(&fip->ctlr_mutex);