Author: emax
Date: Wed Oct 17 19:24:13 2012
New Revision: 241646
URL: http://svn.freebsd.org/changeset/base/241646

Log:
  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

Modified:
  head/sys/dev/ixgbe/ixgbe.c
  head/sys/net/if.h
  head/sys/net/if_var.h

Modified: head/sys/dev/ixgbe/ixgbe.c
==============================================================================
--- head/sys/dev/ixgbe/ixgbe.c  Wed Oct 17 19:21:52 2012        (r241645)
+++ head/sys/dev/ixgbe/ixgbe.c  Wed Oct 17 19:24:13 2012        (r241646)
@@ -2597,8 +2597,7 @@ ixgbe_setup_interface(device_t dev, stru
                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;

Modified: head/sys/net/if.h
==============================================================================
--- head/sys/net/if.h   Wed Oct 17 19:21:52 2012        (r241645)
+++ head/sys/net/if.h   Wed Oct 17 19:24:13 2012        (r241646)
@@ -179,7 +179,7 @@ struct if_data {
  * Some convenience macros used for setting ifi_baudrate.
  * XXX 1000 vs. 1024? --thor...@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. */
 

Modified: head/sys/net/if_var.h
==============================================================================
--- head/sys/net/if_var.h       Wed Oct 17 19:21:52 2012        (r241645)
+++ head/sys/net/if_var.h       Wed Oct 17 19:24:13 2012        (r241646)
@@ -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)
 {      
_______________________________________________
svn-src-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to