Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 17 Apr 2015 12:40:28 +0000 (UTC)
From:      Gleb Smirnoff <glebius@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-projects@freebsd.org
Subject:   svn commit: r281653 - in projects/ifnet/sys: dev/cxgbe dev/cxgbe/tom net netinet
Message-ID:  <201504171240.t3HCeS4g046814@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: glebius
Date: Fri Apr 17 12:40:27 2015
New Revision: 281653
URL: https://svnweb.freebsd.org/changeset/base/281653

Log:
  - TOEDEV is now a generic softc, available via if_getsoftc()/if_setsoftc().
  - cxgbe(4) uses its own cookie to store its struct port_info pointer on
    a vlan(4) and on parent.
  - cxgbe(4) uses ifop_vlan_event to set the cookie.
  
  Not tested.
  
  XXX: the Chelsio TOE code still needs if_var.h

Modified:
  projects/ifnet/sys/dev/cxgbe/t4_main.c
  projects/ifnet/sys/dev/cxgbe/tom/t4_connect.c
  projects/ifnet/sys/dev/cxgbe/tom/t4_cpl_io.c
  projects/ifnet/sys/dev/cxgbe/tom/t4_ddp.c
  projects/ifnet/sys/dev/cxgbe/tom/t4_listen.c
  projects/ifnet/sys/dev/cxgbe/tom/t4_tom.c
  projects/ifnet/sys/dev/cxgbe/tom/t4_tom_l2t.c
  projects/ifnet/sys/net/if.h
  projects/ifnet/sys/net/if_debug.c
  projects/ifnet/sys/net/if_var.h
  projects/ifnet/sys/net/if_vlan.c
  projects/ifnet/sys/netinet/tcp_offload.c
  projects/ifnet/sys/netinet/toecore.c

Modified: projects/ifnet/sys/dev/cxgbe/t4_main.c
==============================================================================
--- projects/ifnet/sys/dev/cxgbe/t4_main.c	Fri Apr 17 12:27:34 2015	(r281652)
+++ projects/ifnet/sys/dev/cxgbe/t4_main.c	Fri Apr 17 12:40:27 2015	(r281653)
@@ -153,6 +153,7 @@ static int cxgbe_ioctl(if_t, unsigned lo
 static int cxgbe_transmit(if_t, struct mbuf *);
 static void cxgbe_qflush(if_t);
 static uint64_t cxgbe_get_counter(if_t, ift_counter);
+static void cxgbe_vlan_event(if_t, uint16_t, if_t);
 static int cxgbe_media_change(if_t);
 static void cxgbe_media_status(if_t, struct ifmediareq *);
 
@@ -169,6 +170,7 @@ static struct ifdriver cxgbe_ifdrv = {
 		.ifop_transmit = cxgbe_transmit,
 		.ifop_qflush = cxgbe_qflush,
 		.ifop_get_counter = cxgbe_get_counter,
+		.ifop_vlan_event = cxgbe_vlan_event,
 	},
 	.ifdrv_name = "cxgbe",
 	.ifdrv_type = IFT_ETHER,
@@ -1133,6 +1135,7 @@ cxgbe_attach(device_t dev)
 	ifat.ifat_softc = pi;
 	ifat.ifat_dunit = device_get_unit(dev);
 	pi->ifp = if_attach(&ifat);
+	if_setsoftc(pi->ifp, IF_CXGBE_PORT, pi);
 
 #ifdef DEV_NETMAP
 	/* nm_media handled here to keep implementation private to this file */
@@ -4338,6 +4341,15 @@ cxgbe_tick(void *arg)
 	PORT_UNLOCK(pi);
 }
 
+static void
+cxgbe_vlan_event(if_t trunk, uint16_t id, if_t vlan)
+{
+	struct port_info *pi;
+
+	pi = if_getsoftc(trunk, IF_DRIVER_SOFTC);
+	if_setsoftc(vlan, IF_CXGBE_PORT, pi);
+}
+
 static int
 cpl_not_handled(struct sge_iq *iq, const struct rss_header *rss, struct mbuf *m)
 {

Modified: projects/ifnet/sys/dev/cxgbe/tom/t4_connect.c
==============================================================================
--- projects/ifnet/sys/dev/cxgbe/tom/t4_connect.c	Fri Apr 17 12:27:34 2015	(r281652)
+++ projects/ifnet/sys/dev/cxgbe/tom/t4_connect.c	Fri Apr 17 12:40:27 2015	(r281653)
@@ -43,8 +43,6 @@ __FBSDID("$FreeBSD$");
 #include <sys/socketvar.h>
 #include <net/ethernet.h>
 #include <net/if.h>
-#include <net/if_types.h>
-#include <net/if_vlan_var.h>
 #include <net/route.h>
 #include <netinet/in.h>
 #include <netinet/in_pcb.h>
@@ -320,7 +318,6 @@ t4_connect(struct toedev *tod, struct so
 	struct tom_data *td = tod_td(tod);
 	struct toepcb *toep = NULL;
 	struct wrqe *wr = NULL;
-	struct ifnet *rt_ifp = rt->rt_ifp;
 	struct port_info *pi;
 	int mtu_idx, rscale, qid_atid, rc, isipv6;
 	struct inpcb *inp = sotoinpcb(so);
@@ -331,15 +328,12 @@ t4_connect(struct toedev *tod, struct so
 	KASSERT(nam->sa_family == AF_INET || nam->sa_family == AF_INET6,
 	    ("%s: dest addr %p has family %u", __func__, nam, nam->sa_family));
 
-	if (rt_ifp->if_type == IFT_ETHER)
-		pi = rt_ifp->if_softc;
-	else if (rt_ifp->if_type == IFT_L2VLAN) {
-		struct ifnet *ifp = VLAN_COOKIE(rt_ifp);
-
-		pi = ifp->if_softc;
-	} else if (rt_ifp->if_type == IFT_IEEE8023ADLAG)
-		DONT_OFFLOAD_ACTIVE_OPEN(ENOSYS); /* XXX: implement lagg+TOE */
-	else
+	/*
+	 * Get port of a NIC or vlan(4).
+	 * XXX: implement lagg+TOE
+	 */
+	pi = if_getsoftc(rt->rt_ifp, IF_CXGBE_PORT);
+	if (pi == NULL)
 		DONT_OFFLOAD_ACTIVE_OPEN(ENOTSUP);
 
 	toep = alloc_toepcb(pi, -1, -1, M_NOWAIT);
@@ -350,7 +344,7 @@ t4_connect(struct toedev *tod, struct so
 	if (toep->tid < 0)
 		DONT_OFFLOAD_ACTIVE_OPEN(ENOMEM);
 
-	toep->l2te = t4_l2t_get(pi, rt_ifp,
+	toep->l2te = t4_l2t_get(pi, rt->rt_ifp,
 	    rt->rt_flags & RTF_GATEWAY ? rt->rt_gateway : nam);
 	if (toep->l2te == NULL)
 		DONT_OFFLOAD_ACTIVE_OPEN(ENOMEM);

Modified: projects/ifnet/sys/dev/cxgbe/tom/t4_cpl_io.c
==============================================================================
--- projects/ifnet/sys/dev/cxgbe/tom/t4_cpl_io.c	Fri Apr 17 12:27:34 2015	(r281652)
+++ projects/ifnet/sys/dev/cxgbe/tom/t4_cpl_io.c	Fri Apr 17 12:40:27 2015	(r281653)
@@ -35,6 +35,7 @@ __FBSDID("$FreeBSD$");
 #include <sys/types.h>
 #include <sys/kernel.h>
 #include <sys/ktr.h>
+#include <sys/mbuf.h>
 #include <sys/module.h>
 #include <sys/protosw.h>
 #include <sys/domain.h>

Modified: projects/ifnet/sys/dev/cxgbe/tom/t4_ddp.c
==============================================================================
--- projects/ifnet/sys/dev/cxgbe/tom/t4_ddp.c	Fri Apr 17 12:27:34 2015	(r281652)
+++ projects/ifnet/sys/dev/cxgbe/tom/t4_ddp.c	Fri Apr 17 12:40:27 2015	(r281653)
@@ -35,6 +35,7 @@ __FBSDID("$FreeBSD$");
 #include <sys/systm.h>
 #include <sys/kernel.h>
 #include <sys/ktr.h>
+#include <sys/mbuf.h>
 #include <sys/module.h>
 #include <sys/protosw.h>
 #include <sys/proc.h>

Modified: projects/ifnet/sys/dev/cxgbe/tom/t4_listen.c
==============================================================================
--- projects/ifnet/sys/dev/cxgbe/tom/t4_listen.c	Fri Apr 17 12:27:34 2015	(r281652)
+++ projects/ifnet/sys/dev/cxgbe/tom/t4_listen.c	Fri Apr 17 12:40:27 2015	(r281653)
@@ -36,6 +36,7 @@ __FBSDID("$FreeBSD$");
 #include <sys/types.h>
 #include <sys/kernel.h>
 #include <sys/ktr.h>
+#include <sys/mbuf.h>
 #include <sys/module.h>
 #include <sys/protosw.h>
 #include <sys/refcount.h>
@@ -45,8 +46,6 @@ __FBSDID("$FreeBSD$");
 #include <sys/socketvar.h>
 #include <net/ethernet.h>
 #include <net/if.h>
-#include <net/if_types.h>
-#include <net/if_vlan_var.h>
 #include <net/route.h>
 #include <netinet/in.h>
 #include <netinet/in_pcb.h>
@@ -346,7 +345,7 @@ send_reset_synqe(struct toedev *tod, str
 	struct adapter *sc = tod->tod_softc;
 	struct mbuf *m = synqe->syn;
 	struct ifnet *ifp = m->m_pkthdr.rcvif;
-	struct port_info *pi = ifp->if_softc;
+	struct port_info *pi = if_getsoftc(ifp, IF_DRIVER_SOFTC);
 	struct l2t_entry *e = &sc->l2t->l2tab[synqe->l2e_idx];
 	struct wrqe *wr;
 	struct fw_flowc_wr *flowc;
@@ -541,7 +540,7 @@ t4_listen_start(struct toedev *tod, stru
 	 */
 	for_each_port(sc, i) {
 		if (isset(&sc->open_device_map, i) &&
-		    sc->port[i]->ifp->if_capenable & IFCAP_TOE)
+		    sc->port[i]->if_capenable & IFCAP_TOE)
 				break;
 	}
 	KASSERT(i < sc->params.nports,
@@ -822,11 +821,12 @@ done_with_synqe(struct adapter *sc, stru
 {
 	struct listen_ctx *lctx = synqe->lctx;
 	struct inpcb *inp = lctx->inp;
-	struct port_info *pi = synqe->syn->m_pkthdr.rcvif->if_softc;
 	struct l2t_entry *e = &sc->l2t->l2tab[synqe->l2e_idx];
+	struct port_info *pi;
 
 	INP_WLOCK_ASSERT(inp);
 
+	pi = if_getsoftc(synqe->syn->m_pkthdr.rcvif, IF_DRIVER_SOFTC);
 	TAILQ_REMOVE(&lctx->synq, synqe, link);
 	inp = release_lctx(sc, lctx);
 	if (inp)
@@ -1195,7 +1195,7 @@ do_pass_accept_req(struct sge_iq *iq, co
 	pi = sc->port[G_SYN_INTF(be16toh(cpl->l2info))];
 	hw_ifp = pi->ifp;	/* the cxgbeX ifnet */
 	m->m_pkthdr.rcvif = hw_ifp;
-	tod = TOEDEV(hw_ifp);
+	tod = if_getsoftc(hw_ifp, IF_TOEDEV);
 
 	/*
 	 * Figure out if there is a pseudo interface (vlan, lagg, etc.)
@@ -1206,7 +1206,7 @@ do_pass_accept_req(struct sge_iq *iq, co
 	 */
 	vid = EVL_VLANOFTAG(be16toh(cpl->vlan));
 	if (vid != 0xfff) {
-		ifp = VLAN_DEVAT(hw_ifp, vid);
+		ifp = if_vlandev(hw_ifp, vid);
 		if (ifp == NULL)
 			REJECT_PASS_ACCEPT();
 	} else
@@ -1222,7 +1222,7 @@ do_pass_accept_req(struct sge_iq *iq, co
 	if (inc.inc_flags & INC_ISIPV6) {
 
 		/* Don't offload if the ifcap isn't enabled */
-		if ((ifp->if_capenable & IFCAP_TOE6) == 0)
+		if ((pi->if_capenable & IFCAP_TOE6) == 0)
 			REJECT_PASS_ACCEPT();
 
 		/*
@@ -1234,7 +1234,7 @@ do_pass_accept_req(struct sge_iq *iq, co
 	} else {
 
 		/* Don't offload if the ifcap isn't enabled */
-		if ((ifp->if_capenable & IFCAP_TOE4) == 0)
+		if ((pi->if_capenable & IFCAP_TOE4) == 0)
 			REJECT_PASS_ACCEPT();
 
 		/*
@@ -1400,7 +1400,7 @@ reject:
 		m->m_pkthdr.csum_flags |= (CSUM_IP_CHECKED | CSUM_IP_VALID |
 		    CSUM_DATA_VALID | CSUM_PSEUDO_HDR);
 		m->m_pkthdr.csum_data = 0xffff;
-		hw_ifp->if_input(hw_ifp, m);
+		if_input(hw_ifp, m);
 	}
 
 	return (reject_reason);
@@ -1480,7 +1480,7 @@ do_pass_establish(struct sge_iq *iq, con
 	}
 
 	ifp = synqe->syn->m_pkthdr.rcvif;
-	pi = ifp->if_softc;
+	pi = if_getsoftc(ifp, IF_DRIVER_SOFTC);
 	KASSERT(pi->adapter == sc,
 	    ("%s: pi %p, sc %p mismatch", __func__, pi, sc));
 
@@ -1498,7 +1498,7 @@ reset:
 		 * we responded to the PASS_ACCEPT_REQ, and our response had the
 		 * L2T idx.
 		 */
-		send_reset_synqe(TOEDEV(ifp), synqe);
+		send_reset_synqe(if_getsoftc(ifp, IF_TOEDEV), synqe);
 		INP_WUNLOCK(inp);
 		INP_INFO_WUNLOCK(&V_tcbinfo);
 		return (0);
@@ -1548,7 +1548,7 @@ reset:
 
 		INP_WLOCK(new_inp);
 		tcp_timer_activate(intotcpcb(new_inp), TT_KEEP, 0);
-		t4_offload_socket(TOEDEV(ifp), synqe, so);
+		t4_offload_socket(if_getsoftc(ifp, IF_TOEDEV), synqe, so);
 		INP_WUNLOCK(new_inp);
 	}
 

Modified: projects/ifnet/sys/dev/cxgbe/tom/t4_tom.c
==============================================================================
--- projects/ifnet/sys/dev/cxgbe/tom/t4_tom.c	Fri Apr 17 12:27:34 2015	(r281652)
+++ projects/ifnet/sys/dev/cxgbe/tom/t4_tom.c	Fri Apr 17 12:40:27 2015	(r281653)
@@ -43,6 +43,7 @@ __FBSDID("$FreeBSD$");
 #include <sys/socketvar.h>
 #include <sys/taskqueue.h>
 #include <net/if.h>
+#include <net/if_var.h>
 #include <netinet/in.h>
 #include <netinet/in_pcb.h>
 #include <netinet/in_var.h>
@@ -1021,7 +1022,7 @@ t4_tom_activate(struct adapter *sc)
 	tod->tod_ctloutput = t4_ctloutput;
 
 	for_each_port(sc, i)
-		TOEDEV(sc->port[i]->ifp) = &td->tod;
+		if_setsoftc(sc->port[i]->ifp, IF_TOEDEV, &td->tod);
 
 	sc->tom_softc = td;
 	register_toedev(sc->tom_softc);

Modified: projects/ifnet/sys/dev/cxgbe/tom/t4_tom_l2t.c
==============================================================================
--- projects/ifnet/sys/dev/cxgbe/tom/t4_tom_l2t.c	Fri Apr 17 12:27:34 2015	(r281652)
+++ projects/ifnet/sys/dev/cxgbe/tom/t4_tom_l2t.c	Fri Apr 17 12:40:27 2015	(r281653)
@@ -43,9 +43,9 @@ __FBSDID("$FreeBSD$");
 #include <sys/sbuf.h>
 #include <sys/taskqueue.h>
 #include <net/if.h>
+#include <net/if_var.h>
 #include <net/if_types.h>
 #include <net/ethernet.h>
-#include <net/if_vlan_var.h>
 #include <net/route.h>
 #include <netinet/in.h>
 #include <netinet/toecore.h>
@@ -381,11 +381,6 @@ t4_l2t_get(struct port_info *pi, struct 
 	    ("%s: sa %p has unexpected sa_family %d", __func__, sa,
 	    sa->sa_family));
 
-#ifndef VLAN_TAG
-	if (ifp->if_type == IFT_L2VLAN)
-		return (NULL);
-#endif
-
 	hash = l2_hash(d, sa, ifp->if_index);
 	rw_wlock(&d->lock);
 	for (e = d->l2tab[hash].first; e; e = e->next) {
@@ -410,12 +405,8 @@ t4_l2t_get(struct port_info *pi, struct 
 		e->hash = hash;
 		e->lport = pi->lport;
 		atomic_store_rel_int(&e->refcnt, 1);
-#ifdef VLAN_TAG
-		if (ifp->if_type == IFT_L2VLAN)
-			VLAN_TAG(ifp, &e->vlan);
-		else
+		if (if_vlanid(ifp, &e->vlan) != 0)
 			e->vlan = VLAN_NONE;
-#endif
 		mtx_unlock(&e->lock);
 	}
 done:

Modified: projects/ifnet/sys/net/if.h
==============================================================================
--- projects/ifnet/sys/net/if.h	Fri Apr 17 12:27:34 2015	(r281652)
+++ projects/ifnet/sys/net/if.h	Fri Apr 17 12:40:27 2015	(r281653)
@@ -577,14 +577,21 @@ typedef enum {
 	IF_LLADDR,
 	IF_BPF,
 	IF_NAME,
-	IF_VLAN,
 	/*
 	 * Values do matter, since we want to avoid aliasing of frequently
 	 * used features in if_sccache cache.
 	 */
-	IF_AF_INET = 8,
-	IF_AF_INET6 = 9,
-	IF_CARP = 10,
+	IF_AF_INET = 100,
+	IF_AF_INET6,
+	IF_CARP,
+	IF_VLAN,
+	IF_TOEDEV,
+	/*
+	 * Space above 99999 is split among different vendors.
+	 *
+	 * Chelsio	10000 - 10999
+	 */
+	IF_CXGBE_PORT	= 10000,
 } ift_feature;
 
 typedef struct ifnet * if_t;

Modified: projects/ifnet/sys/net/if_debug.c
==============================================================================
--- projects/ifnet/sys/net/if_debug.c	Fri Apr 17 12:27:34 2015	(r281652)
+++ projects/ifnet/sys/net/if_debug.c	Fri Apr 17 12:40:27 2015	(r281653)
@@ -65,7 +65,6 @@ if_show_ifnet(struct ifnet *ifp)
 	IF_DB_PRINTF("%p", if_vnet);
 	IF_DB_PRINTF("%p", if_home_vnet);
 	IF_DB_PRINTF("%p", if_addr);
-	IF_DB_PRINTF("%p", if_llsoftc);
 	IF_DB_PRINTF("%p", if_label);
 	IF_DB_PRINTF("%u", if_pcount);
 	IF_DB_PRINTF("0x%08x", if_flags);

Modified: projects/ifnet/sys/net/if_var.h
==============================================================================
--- projects/ifnet/sys/net/if_var.h	Fri Apr 17 12:27:34 2015	(r281652)
+++ projects/ifnet/sys/net/if_var.h	Fri Apr 17 12:40:27 2015	(r281653)
@@ -113,7 +113,6 @@ struct ifnet {
 	LIST_ENTRY(ifnet)	if_clones;	/* on if_cloner list */
 	TAILQ_HEAD(, ifg_list)	if_groups;	/* groups of this ifnet */
 
-	void	*if_llsoftc;		/* link layer softc */
 	void	*if_l2com;		/* pointer to protocol bits */
 	uint32_t if_nsoftcs;		/* elements in if_scstore */
 	int	if_dunit;		/* unit or IF_DUNIT_NONE */
@@ -278,8 +277,6 @@ EVENTHANDLER_DECLARE(group_change_event,
 #define	IF_MINMTU	72
 #define	IF_MAXMTU	65535
 
-#define	TOEDEV(ifp)	((ifp)->if_llsoftc)
-
 /*
  * The ifaddr structure contains information about one address
  * of an interface.  They are maintained by the different address families,

Modified: projects/ifnet/sys/net/if_vlan.c
==============================================================================
--- projects/ifnet/sys/net/if_vlan.c	Fri Apr 17 12:27:34 2015	(r281652)
+++ projects/ifnet/sys/net/if_vlan.c	Fri Apr 17 12:40:27 2015	(r281653)
@@ -1473,7 +1473,7 @@ vlan_capabilities(struct ifvlan *ifv)
 	if (p->if_capabilities & IFCAP_VLAN_TOE)
 		ifp->if_capabilities |= p->if_capabilities & IFCAP_TOE;
 	if (p->if_capenable & IFCAP_VLAN_TOE) {
-		TOEDEV(ifp) = TOEDEV(p);
+		if_setsoftc(ifp, IF_TOEDEV, if_getsoftc(p, IF_TOEDEV));
 		ifp->if_capenable |= p->if_capenable & IFCAP_TOE;
 	}
 }

Modified: projects/ifnet/sys/netinet/tcp_offload.c
==============================================================================
--- projects/ifnet/sys/netinet/tcp_offload.c	Fri Apr 17 12:27:34 2015	(r281652)
+++ projects/ifnet/sys/netinet/tcp_offload.c	Fri Apr 17 12:40:27 2015	(r281653)
@@ -81,7 +81,7 @@ tcp_offload_connect(struct socket *so, s
 	if (nam->sa_family == AF_INET6 && !(ifp->if_capenable & IFCAP_TOE6))
 		goto done;
 
-	tod = TOEDEV(ifp);
+	tod = if_getsoftc(ifp, IF_TOEDEV);
 	if (tod != NULL)
 		error = tod->tod_connect(tod, so, rt, nam);
 done:

Modified: projects/ifnet/sys/netinet/toecore.c
==============================================================================
--- projects/ifnet/sys/netinet/toecore.c	Fri Apr 17 12:27:34 2015	(r281652)
+++ projects/ifnet/sys/netinet/toecore.c	Fri Apr 17 12:40:27 2015	(r281653)
@@ -407,7 +407,7 @@ toe_lle_event(void *arg __unused, struct
 	    (sa->sa_family == AF_INET6 && !(ifp->if_capenable & IFCAP_TOE6)))
 		return;
 
-	tod = TOEDEV(ifp);
+	tod = if_getsoftc(ifp, IF_TOEDEV);
 	if (tod == NULL)
 		return;
 
@@ -426,9 +426,7 @@ toe_lle_event(void *arg __unused, struct
 		    ("%s: %p resolved but not valid?", __func__, lle));
 
 		lladdr = (uint8_t *)&lle->ll_addr;
-#ifdef VLAN_TAG
-		VLAN_TAG(ifp, &vtag);
-#endif
+		if_vlanid(ifp, &vtag);
 	}
 
 	tod->tod_l2_update(tod, ifp, sa, lladdr, vtag);
@@ -493,7 +491,7 @@ restart:
 	}
 
 	if (lle->la_flags & LLE_VALID) {
-		memcpy(lladdr, &lle->ll_addr, ifp->if_addrlen);
+		memcpy(lladdr, &lle->ll_addr, if_addrlen(ifp));
 		rc = 0;
 	} else
 		rc = EWOULDBLOCK;
@@ -534,9 +532,7 @@ toe_l2_resolve(struct toedev *tod, struc
 	}
 
 	if (rc == 0) {
-#ifdef VLAN_TAG
-		if (VLAN_TAG(ifp, vtag) != 0)
-#endif
+		if (if_vlanid(ifp, vtag) != 0)
 			*vtag = 0xfff;
 	}
 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201504171240.t3HCeS4g046814>