From 608ae712d3367c0065e17ffcd389b51075dfc160 Mon Sep 17 00:00:00 2001 From: Maksim Yevmenkin Date: Wed, 17 Oct 2012 19:24:13 +0000 Subject: [PATCH] provide helper if_initbaudrate() to set if_baudrate_pf and if_baudrate_pf. again, use ixgbe(4) as an example of how to use new helper function. Reviewed by: jhb MFC after: 1 week --- sys/dev/ixgbe/ixgbe.c | 3 +-- sys/net/if.h | 2 +- sys/net/if_var.h | 12 ++++++++++++ 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/sys/dev/ixgbe/ixgbe.c b/sys/dev/ixgbe/ixgbe.c index bb8b58c4ad04..d9f028ba5389 100644 --- a/sys/dev/ixgbe/ixgbe.c +++ b/sys/dev/ixgbe/ixgbe.c @@ -2597,8 +2597,7 @@ ixgbe_setup_interface(device_t dev, struct adapter *adapter) return (-1); } if_initname(ifp, device_get_name(dev), device_get_unit(dev)); - ifp->if_baudrate = IF_Gbps(1); - ifp->if_baudrate_pf = 1; /* 1Gbps * 10^1 = 10Gbps */ + if_initbaudrate(ifp, IF_Gbps(10)); ifp->if_init = ixgbe_init; ifp->if_softc = adapter; ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST; diff --git a/sys/net/if.h b/sys/net/if.h index 93448b5f6693..7aca535f9f73 100644 --- a/sys/net/if.h +++ b/sys/net/if.h @@ -179,7 +179,7 @@ struct if_data { * Some convenience macros used for setting ifi_baudrate. * XXX 1000 vs. 1024? --thorpej@netbsd.org */ -#define IF_Kbps(x) ((x) * 1000) /* kilobits/sec. */ +#define IF_Kbps(x) ((uintmax_t)(x) * 1000) /* kilobits/sec. */ #define IF_Mbps(x) (IF_Kbps((x) * 1000)) /* megabits/sec. */ #define IF_Gbps(x) (IF_Mbps((x) * 1000)) /* gigabits/sec. */ diff --git a/sys/net/if_var.h b/sys/net/if_var.h index d695ef429ae9..6d1097e414f8 100644 --- a/sys/net/if_var.h +++ b/sys/net/if_var.h @@ -591,6 +591,18 @@ do { \ } while (0) #ifdef _KERNEL +static __inline void +if_initbaudrate(struct ifnet *ifp, uintmax_t baud) +{ + + ifp->if_baudrate_pf = 0; + while (baud > (u_long)(~0UL)) { + baud /= 10; + ifp->if_baudrate_pf++; + } + ifp->if_baudrate = baud; +} + static __inline int drbr_enqueue(struct ifnet *ifp, struct buf_ring *br, struct mbuf *m) {