From owner-svn-src-all@FreeBSD.ORG Wed Oct 17 15:26:22 2012 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 8CA8D982; Wed, 17 Oct 2012 15:26:22 +0000 (UTC) (envelope-from maksim.yevmenkin@gmail.com) Received: from mail-pa0-f54.google.com (mail-pa0-f54.google.com [209.85.220.54]) by mx1.freebsd.org (Postfix) with ESMTP id 47AA38FC12; Wed, 17 Oct 2012 15:26:22 +0000 (UTC) Received: by mail-pa0-f54.google.com with SMTP id bi1so7798903pad.13 for ; Wed, 17 Oct 2012 08:26:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type; bh=o55VzB/mhX9F/hXhdrpeDWb2UW3n81GXXNlTTalLgoU=; b=tJJbsAbb1h6OkbK+eCqe3EgCPzHo4RH02SXS9e2pkj16RHkugFDDoyBAKcPITiAJb+ zO+yNPzHEMKS1Ua42gC8SZw5W8O3zxyzKmrs1FhpDzWEV1u90S8T35oQrlZsM53AYBDm J5dt/mNDTND/HGhLbsXZzkqvWMtB+HnmiERl+mCXLDi9CZxcObsQC93vRzuMXHpPSerB GAG7+D07WjgdMmOVAnvCzF0EkYr0EbG/P8+43egmCtIoBs0XoZ9J4Fg/YuIz3N6Z67f+ z1YR/CtVJv71K2aTCORc4vhdFI9sXfwjhWplnlpTRh/4Vqkv10WZ2d205pcN1hW+BXEB xpkA== MIME-Version: 1.0 Received: by 10.66.79.69 with SMTP id h5mr51644702pax.12.1350487581772; Wed, 17 Oct 2012 08:26:21 -0700 (PDT) Sender: maksim.yevmenkin@gmail.com Received: by 10.68.240.38 with HTTP; Wed, 17 Oct 2012 08:26:21 -0700 (PDT) In-Reply-To: <201210170951.23800.jhb@freebsd.org> References: <201210162018.q9GKIG9q013028@svn.freebsd.org> <201210161702.06330.jhb@freebsd.org> <201210170951.23800.jhb@freebsd.org> Date: Wed, 17 Oct 2012 08:26:21 -0700 X-Google-Sender-Auth: u_EM7A58mHEoQpskMPst1PnHGK0 Message-ID: Subject: Re: svn commit: r241616 - in head/sys: dev/ixgbe net From: Maksim Yevmenkin To: John Baldwin Content-Type: text/plain; charset=ISO-8859-1 Cc: svn-src-head@freebsd.org, svn-src-all@freebsd.org, src-committers@freebsd.org X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 17 Oct 2012 15:26:22 -0000 On Wed, Oct 17, 2012 at 6:51 AM, John Baldwin 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