*BSD News Article 33824


Return to BSD News archive

Xref: sserve comp.os.386bsd.misc:3014 comp.os.linux.misc:21034
Path: sserve!newshost.anu.edu.au!harbinger.cc.monash.edu.au!msuinfo!agate!ames!newsfeed.gsfc.nasa.gov!cesdis1.gsfc.nasa.gov!not-for-mail
From: becker@cesdis.gsfc.nasa.gov (Donald Becker)
Newsgroups: comp.os.386bsd.misc,comp.os.linux.misc
Subject: Re: source of TCP/IP (was I hope this wont ignite a major flame ...)
Date: 4 Aug 1994 02:18:11 -0400
Organization: USRA Center of Excellence in Space Data and Information Sciences
Lines: 44
Message-ID: <31q174$kpu@cesdis1.gsfc.nasa.gov>
References: <3163r7$440@quagga.ru.ac.za> <CtqrFJ.IM5@calcite.rhyolite.com> <31fd07$6pq@cesdis1.gsfc.nasa.gov> <31od8d$15l@fw.novatel.ca>
NNTP-Posting-Host: cesdis1.gsfc.nasa.gov
Mime-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit

In article <31od8d$15l@fw.novatel.ca>,
Herb Peyerl <hpeyerl@sidney.novatel.ca> wrote:
>This is an example of some of the Linux device-drivers I've seen:
>
>        short error = rx_status & 0x3C00;
>        outw(inw(ioaddr + 0x0A) | 0x00C0, ioaddr + 0x0A);

As far as I can tell this code isn't verbatim from any driver.  The closest
that I can find is the Lance driver which does

           if (status & 0x40000000) { /* There was an major error, log it. */
                int err_status = lp->tx_ring[entry].misc;
                lp->stats.tx_errors++;
                if (err_status & 0x0400) lp->stats.tx_aborted_errors++;
                if (err_status & 0x0800) lp->stats.tx_carrier_errors++;
                if (err_status & 0x1000) lp->stats.tx_window_errors++;
                if (err_status & 0x4000) lp->stats.tx_fifo_errors++;
                /* Perhaps we should re-init() after the FIFO error. */
            } else {
                if (status & 0x18000000)
                    lp->stats.collisions++;
                lp->stats.tx_packets++;
            }

OK, there are a lot of numeric constants there, and no comments.  But in
this case the constants are *good*.  I consider the code much more readable
than the alternative of writing a list of #defines in the 'constants'
section 600 lines above, just so that the constants could be used once.

We aren't looking at bit-mapped variables here.  We aren't looking at
Fortran-style common blocks.  This isn't a self-contained software function
where the values are aribitrary.  We are looking at the fixed bits from a
hardware register.

Another point to remember is that unlike software-only functions, this code
cannot be completely understood alone.  Short of duplicating the entire
databook in the comments you won't be 100% certain that you know what is
really going on. 

-- 
Donald Becker					  becker@cesdis1.gsfc.nasa.gov
USRA Center of Excellence in Space Data and Information Sciences.
Code 930.5, Goddard Space Flight Center,  Greenbelt, MD.  20771
301-286-0882	     http://cesdis.gsfc.nasa.gov/pub/people/becker/whoiam.html