Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 17 Oct 2012 19:24:13 +0000 (UTC)
From:      Maksim Yevmenkin <emax@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r241646 - in head/sys: dev/ixgbe net
Message-ID:  <201210171924.q9HJODvL044644@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
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? --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. */
 

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)
 {	



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