svn commit: r241616 - in head/sys: dev/ixgbe net
Maksim Yevmenkin
emax at freebsd.org
Wed Oct 17 15:26:22 UTC 2012
On Wed, Oct 17, 2012 at 6:51 AM, John Baldwin <jhb at 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 at 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
More information about the svn-src-head
mailing list