Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 17 Oct 2012 08:26:21 -0700
From:      Maksim Yevmenkin <emax@freebsd.org>
To:        John Baldwin <jhb@freebsd.org>
Cc:        svn-src-head@freebsd.org, svn-src-all@freebsd.org, src-committers@freebsd.org
Subject:   Re: svn commit: r241616 - in head/sys: dev/ixgbe net
Message-ID:  <CAFPOs6rVjFqh4FxfSt_yhzUGvgiVQkmpP6Lbgyckz6X7Y96RQQ@mail.gmail.com>
In-Reply-To: <201210170951.23800.jhb@freebsd.org>
References:  <201210162018.q9GKIG9q013028@svn.freebsd.org> <201210161702.06330.jhb@freebsd.org> <CAFPOs6p0aQEadjPAY0nS3nf7D_hCHX0qYCGG9EwWvYPQQCeXug@mail.gmail.com> <201210170951.23800.jhb@freebsd.org>

next in thread | previous in thread | raw e-mail | index | archive | help
On Wed, Oct 17, 2012 at 6:51 AM, John Baldwin <jhb@freebsd.org> wrote:

[...]

>> > Maybe a helper 'if_set_baudrate(ifp, IF_Gbps(10))' that would DTRT.
>> > (It could be a static inline or some such).  I would just like to
>> > keep the readability.
>>
>> well, yes, i thought about it, but decided not to do it right away. we
>> could provide shortcuts/macros for "popular" baudrates, i.e. 1, 10, 40
>> and 100 Gbps. while ixgbe(4) example is not ideal, i thought it still
>> was pretty readable :)
>
> I don't really find it all that readable.  IF_Gbps(1) looks like a typo
> to a casual reader.  I really think you should have something like:

[...]

very well :)  would something like (please see below) work?

Index: sys/dev/ixgbe/ixgbe.c
===================================================================
--- sys/dev/ixgbe/ixgbe.c	(revision 241641)
+++ sys/dev/ixgbe/ixgbe.c	(working copy)
@@ -2597,8 +2597,7 @@
 		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;
Index: sys/net/if.h
===================================================================
--- sys/net/if.h	(revision 241641)
+++ sys/net/if.h	(working copy)
@@ -179,7 +179,7 @@
  * 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. */

Index: sys/net/if_var.h
===================================================================
--- sys/net/if_var.h	(revision 241641)
+++ sys/net/if_var.h	(working copy)
@@ -591,6 +591,18 @@
 } 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)
 {
	
==

thanks,
max



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