AMD EPYC Embedded 3000 10Gig NIC

2023-05-13 Thread Denis Fondras
Allow detection of AMD EPYC Embedded 3000 10Gig NIC.

OK ?

Index: dev/pci/pcidevs
===
RCS file: /cvs/src/sys/dev/pci/pcidevs,v
retrieving revision 1.2036
diff -u -p -r1.2036 pcidevs
--- dev/pci/pcidevs 12 May 2023 11:42:22 -  1.2036
+++ dev/pci/pcidevs 13 May 2023 15:59:12 -
@@ -757,6 +757,7 @@ product AMD 17_PCIE_2   0x1453  17h PCIE
 product AMD 17_PCIE_3  0x1454  17h PCIE
 product AMD 17_CCP_1   0x1456  17h Crypto
 product AMD 17_HDA 0x1457  17h HD Audio
+product AMD EPYC_TENGB 0x1458  EPYC Embedded 3000 10Gig NIC
 product AMD 17_XHCI_1  0x145c  17h xHCI
 product AMD 17_XHCI_2  0x145f  17h xHCI
 product AMD 17_DF_10x1460  17h Data Fabric



Re: nd6 remove kernel lock

2023-05-13 Thread Alexander Bluhm
On Fri, May 12, 2023 at 11:43:42AM +, Klemens Nanni wrote:
> On Fri, May 12, 2023 at 12:18:12AM +0200, Alexander Bluhm wrote:
> > Access rt_llinfo either with nd6 mutex or exclusive netlock.
> 
> Can you leave a comment at the read-only ioctl wrt. exclusive net lock?

Even better.  nd6_lookup() must be mp-safe as it is called by
ip6_forward6() via nd6_is_addr_neighbor().  Just put the mutex
around rt_llinfo in nd6_ioctl() and keep the netlock shared.

ok?

bluhm

Index: netinet6/nd6.c
===
RCS file: /data/mirror/openbsd/cvs/src/sys/netinet6/nd6.c,v
retrieving revision 1.279
diff -u -p -r1.279 nd6.c
--- netinet6/nd6.c  12 May 2023 12:42:16 -  1.279
+++ netinet6/nd6.c  13 May 2023 14:28:57 -
@@ -306,7 +306,7 @@ nd6_llinfo_timer(struct rtentry *rt)
struct sockaddr_in6 *dst = satosin6(rt_key(rt));
struct ifnet *ifp;
 
-   NET_ASSERT_LOCKED();
+   NET_ASSERT_LOCKED_EXCLUSIVE();
 
if ((ifp = if_get(rt->rt_ifidx)) == NULL)
return 1;
@@ -557,9 +557,11 @@ nd6_lookup(const struct in6_addr *addr6,
rtableid);
if (error)
return (NULL);
+   mtx_enter(_mtx);
ln = (struct llinfo_nd6 *)rt->rt_llinfo;
if (ln != NULL)
ln->ln_state = ND6_LLINFO_NOSTATE;
+   mtx_leave(_mtx);
} else
return (NULL);
}
@@ -665,7 +667,7 @@ nd6_free(struct rtentry *rt)
struct in6_addr in6 = satosin6(rt_key(rt))->sin6_addr;
struct ifnet *ifp;
 
-   NET_ASSERT_LOCKED();
+   NET_ASSERT_LOCKED_EXCLUSIVE();
 
ifp = if_get(rt->rt_ifidx);
 
@@ -705,6 +707,8 @@ nd6_nud_hint(struct rtentry *rt)
struct llinfo_nd6 *ln;
struct ifnet *ifp;
 
+   NET_ASSERT_LOCKED_EXCLUSIVE();
+
ifp = if_get(rt->rt_ifidx);
if (ifp == NULL)
return;
@@ -990,8 +994,10 @@ nd6_ioctl(u_long cmd, caddr_t data, stru
}
 
rt = nd6_lookup(_addr, 0, ifp, ifp->if_rdomain);
+   mtx_enter(_mtx);
if (rt == NULL ||
(ln = (struct llinfo_nd6 *)rt->rt_llinfo) == NULL) {
+   mtx_leave(_mtx);
rtfree(rt);
NET_UNLOCK_SHARED();
return (EINVAL);
@@ -1006,6 +1012,7 @@ nd6_ioctl(u_long cmd, caddr_t data, stru
nbi->asked = ln->ln_asked;
nbi->isrouter = ln->ln_router;
nbi->expire = expire;
+   mtx_leave(_mtx);
 
rtfree(rt);
NET_UNLOCK_SHARED();
@@ -1035,6 +1042,8 @@ nd6_cache_lladdr(struct ifnet *ifp, cons
int llchange;
int newstate = 0;
 
+   NET_ASSERT_LOCKED_EXCLUSIVE();
+
if (!ifp)
panic("%s: ifp == NULL", __func__);
if (!from)
@@ -1294,23 +1303,20 @@ nd6_resolve(struct ifnet *ifp, struct rt
goto bad;
}
 
-   KERNEL_LOCK();
-   if (!ISSET(rt->rt_flags, RTF_LLINFO)) {
-   KERNEL_UNLOCK();
+   mtx_enter(_mtx);
+   ln = (struct llinfo_nd6 *)rt->rt_llinfo;
+   if (ln == NULL) {
+   mtx_leave(_mtx);
goto bad;
}
-   ln = (struct llinfo_nd6 *)rt->rt_llinfo;
-   KASSERT(ln != NULL);
 
/*
 * Move this entry to the head of the queue so that it is less likely
 * for this entry to be a target of forced garbage collection (see
 * nd6_rtrequest()).
 */
-   mtx_enter(_mtx);
TAILQ_REMOVE(_list, ln, ln_list);
TAILQ_INSERT_HEAD(_list, ln, ln_list);
-   mtx_leave(_mtx);
 
/*
 * The first time we send a packet to a neighbor whose entry is
@@ -1331,7 +1337,7 @@ nd6_resolve(struct ifnet *ifp, struct rt
 * send the packet.
 */
if (ln->ln_state > ND6_LLINFO_INCOMPLETE) {
-   KERNEL_UNLOCK();
+   mtx_leave(_mtx);
 
sdl = satosdl(rt->rt_gateway);
if (sdl->sdl_alen != ETHER_ADDR_LEN) {
@@ -1377,7 +1383,7 @@ nd6_resolve(struct ifnet *ifp, struct rt
saddr6 = ln->ln_saddr6;
solicit = 1;
}
-   KERNEL_UNLOCK();
+   mtx_leave(_mtx);
 
if (solicit)
nd6_ns_output(ifp, NULL, (dst)->sin6_addr, , 0);



Re: seperate LRO/TSO flags

2023-05-13 Thread Christian Weisgerber
Jan Klemkow:

> This diff introduces separate flags for TCP offloading.  We split this
> into LRO (large receive offloading) and TSO (TCP segmentation
> offloading).  Thus, we are able to turn it on/off separately.

Wait, why do we even have a knob for TSO?

We specifically decided not to have a knob for checksum offloading,
because it should just work out of the box, and if it doesn't, then
it should be disabled by the driver.  It should not be the admin's
task to figure out if the implementation is broken and to fiddle
with the knobs (hi, FreeBSD!).

I would assume that line of thinking extends to TSO.

-- 
Christian "naddy" Weisgerber  na...@mips.inka.de



Re: ipv4 header checksum

2023-05-13 Thread Claudio Jeker
On Sat, May 13, 2023 at 01:38:07AM +0200, Alexander Bluhm wrote:
> Hi,
> 
> Instead of implementing IPv4 header checksum everywhere differently,
> introduce in_hdr_cksum_out().  It is used like in_proto_cksum_out().
> 
> ok?

OK claudio@
 
> bluhm
> 
> Index: net/if_bridge.c
> ===
> RCS file: /data/mirror/openbsd/cvs/src/sys/net/if_bridge.c,v
> retrieving revision 1.366
> diff -u -p -r1.366 if_bridge.c
> --- net/if_bridge.c   7 May 2023 16:23:23 -   1.366
> +++ net/if_bridge.c   12 May 2023 20:43:06 -
> @@ -1735,15 +1735,8 @@ bridge_ip(struct ifnet *brifp, int dir, 
>   return (NULL);
>   if (m->m_len < sizeof(struct ip))
>   goto dropit;
> + in_hdr_cksum_out(m, ifp);
>   in_proto_cksum_out(m, ifp);
> - ip = mtod(m, struct ip *);
> - ip->ip_sum = 0;
> - if (0 && (ifp->if_capabilities & IFCAP_CSUM_IPv4))
> - m->m_pkthdr.csum_flags |= M_IPV4_CSUM_OUT;
> - else {
> - ipstat_inc(ips_outswcsum);
> - ip->ip_sum = in_cksum(m, hlen);
> - }
>  
>  #if NPF > 0
>   if (dir == BRIDGE_IN &&
> @@ -1993,8 +1986,7 @@ bridge_send_icmp_err(struct ifnet *ifp,
>   ip->ip_off &= htons(IP_DF);
>   ip->ip_id = htons(ip_randomid());
>   ip->ip_ttl = MAXTTL;
> - ip->ip_sum = 0;
> - ip->ip_sum = in_cksum(m, hlen);
> + in_hdr_cksum_out(m, NULL);
>  
>   /* Swap ethernet addresses */
>   bcopy(>ether_dhost, _tmp, sizeof(ether_tmp));
> Index: net/if_gre.c
> ===
> RCS file: /data/mirror/openbsd/cvs/src/sys/net/if_gre.c,v
> retrieving revision 1.173
> diff -u -p -r1.173 if_gre.c
> --- net/if_gre.c  13 Apr 2023 02:19:05 -  1.173
> +++ net/if_gre.c  12 May 2023 20:43:06 -
> @@ -3028,8 +3028,7 @@ gre_keepalive_send(void *arg)
>  
>   ip = mtod(m, struct ip *);
>   ip->ip_id = htons(ip_randomid());
> - ip->ip_sum = 0;
> - ip->ip_sum = in_cksum(m, sizeof(*ip));
> + in_hdr_cksum_out(m, NULL);
>  
>   proto = htons(ETHERTYPE_IP);
>   break;
> Index: net/pf.c
> ===
> RCS file: /data/mirror/openbsd/cvs/src/sys/net/pf.c,v
> retrieving revision 1.1178
> diff -u -p -r1.1178 pf.c
> --- net/pf.c  10 May 2023 12:07:16 -  1.1178
> +++ net/pf.c  12 May 2023 20:43:06 -
> @@ -2868,7 +2868,7 @@ pf_change_icmp_af(struct mbuf *m, int ip
>   ip4->ip_p = pd2->proto;
>   ip4->ip_src = src->v4;
>   ip4->ip_dst = dst->v4;
> - ip4->ip_sum = in_cksum(n, ip4->ip_hl << 2);
> + in_hdr_cksum_out(n, NULL);
>   break;
>   case AF_INET6:
>   ip6 = mtod(n, struct ip6_hdr *);
> @@ -6549,13 +6549,7 @@ pf_route(struct pf_pdesc *pd, struct pf_
>   }
>  
>   if (ntohs(ip->ip_len) <= ifp->if_mtu) {
> - ip->ip_sum = 0;
> - if (ifp->if_capabilities & IFCAP_CSUM_IPv4)
> - m0->m_pkthdr.csum_flags |= M_IPV4_CSUM_OUT;
> - else {
> - ipstat_inc(ips_outswcsum);
> - ip->ip_sum = in_cksum(m0, ip->ip_hl << 2);
> - }
> + in_hdr_cksum_out(m0, ifp);
>   in_proto_cksum_out(m0, ifp);
>   ifp->if_output(ifp, m0, sintosa(dst), rt);
>   goto done;
> Index: netinet/in.h
> ===
> RCS file: /data/mirror/openbsd/cvs/src/sys/netinet/in.h,v
> retrieving revision 1.143
> diff -u -p -r1.143 in.h
> --- netinet/in.h  10 May 2023 12:07:16 -  1.143
> +++ netinet/in.h  12 May 2023 20:43:06 -
> @@ -779,6 +779,7 @@ int  in_broadcast(struct in_addr, u_in
>  int in_canforward(struct in_addr);
>  int in_cksum(struct mbuf *, int);
>  int in4_cksum(struct mbuf *, u_int8_t, int, int);
> +voidin_hdr_cksum_out(struct mbuf *, struct ifnet *);
>  voidin_proto_cksum_out(struct mbuf *, struct ifnet *);
>  int in_ifcap_cksum(struct mbuf *, struct ifnet *, int);
>  voidin_ifdetach(struct ifnet *);
> Index: netinet/ip_divert.c
> ===
> RCS file: /data/mirror/openbsd/cvs/src/sys/netinet/ip_divert.c,v
> retrieving revision 1.90
> diff -u -p -r1.90 ip_divert.c
> --- netinet/ip_divert.c   4 Apr 2023 10:12:03 -   1.90
> +++ netinet/ip_divert.c   12 May 2023 20:43:06 -
> @@ -157,8 +157,7 @@ divert_output(struct inpcb *inp, struct 
>* since the userspace application may have modified the packet
>* prior to reinjection.
>*/
> - ip->ip_sum = 0;
> - ip->ip_sum =