Lindented 8139
authorBarret Rhoden <brho@cs.berkeley.edu>
Wed, 22 Jan 2014 04:47:59 +0000 (20:47 -0800)
committerBarret Rhoden <brho@cs.berkeley.edu>
Wed, 22 Jan 2014 19:13:14 +0000 (11:13 -0800)
Might as well do it sooner than later.

kern/drivers/net/ether8139.c

index 5ba01a1..c81e6cd 100644 (file)
 #include <smp.h>
 #include <ip.h>
 
-enum {                                 /* registers */
-       Idr0            = 0x0000,       /* MAC address */
-       Mar0            = 0x0008,       /* Multicast address */
-       Tsd0            = 0x0010,       /* Transmit Status Descriptor0 */
-       Tsad0           = 0x0020,       /* Transmit Start Address Descriptor0 */
-       Rbstart         = 0x0030,       /* Receive Buffer Start Address */
-       Erbcr           = 0x0034,       /* Early Receive Byte Count */
-       Ersr            = 0x0036,       /* Early Receive Status */
-       Cr              = 0x0037,       /* Command Register */
-       Capr            = 0x0038,       /* Current Address of Packet Read */
-       Cbr             = 0x003A,       /* Current Buffer Address */
-       Imr             = 0x003C,       /* Interrupt Mask */
-       Isr             = 0x003E,       /* Interrupt Status */
-       Tcr             = 0x0040,       /* Transmit Configuration */
-       Rcr             = 0x0044,       /* Receive Configuration */
-       Tctr            = 0x0048,       /* Timer Count */
-       Mpc             = 0x004C,       /* Missed Packet Counter */
-       Cr9346          = 0x0050,       /* 9346 Command Register */
-       Config0         = 0x0051,       /* Configuration Register 0 */
-       Config1         = 0x0052,       /* Configuration Register 1 */
-       TimerInt        = 0x0054,       /* Timer Interrupt */
-       Msr             = 0x0058,       /* Media Status */
-       Config3         = 0x0059,       /* Configuration Register 3 */
-       Config4         = 0x005A,       /* Configuration Register 4 */
-       Mulint          = 0x005C,       /* Multiple Interrupt Select */
-       RerID           = 0x005E,       /* PCI Revision ID */
-       Tsad            = 0x0060,       /* Transmit Status of all Descriptors */
-
-       Bmcr            = 0x0062,       /* Basic Mode Control */
-       Bmsr            = 0x0064,       /* Basic Mode Status */
-       Anar            = 0x0066,       /* Auto-Negotiation Advertisment */
-       Anlpar          = 0x0068,       /* Auto-Negotiation Link Partner */
-       Aner            = 0x006A,       /* Auto-Negotiation Expansion */
-       Dis             = 0x006C,       /* Disconnect Counter */
-       Fcsc            = 0x006E,       /* False Carrier Sense Counter */
-       Nwaytr          = 0x0070,       /* N-way Test */
-       Rec             = 0x0072,       /* RX_ER Counter */
-       Cscr            = 0x0074,       /* CS Configuration */
-       Phy1parm        = 0x0078,       /* PHY Parameter 1 */
-       Twparm          = 0x007C,       /* Twister Parameter */
-       Phy2parm        = 0x0080,       /* PHY Parameter 2 */
+enum {                                                 /* registers */
+       Idr0 = 0x0000,                          /* MAC address */
+       Mar0 = 0x0008,  /* Multicast address */
+       Tsd0 = 0x0010,  /* Transmit Status Descriptor0 */
+       Tsad0 = 0x0020, /* Transmit Start Address Descriptor0 */
+       Rbstart = 0x0030,       /* Receive Buffer Start Address */
+       Erbcr = 0x0034, /* Early Receive Byte Count */
+       Ersr = 0x0036,  /* Early Receive Status */
+       Cr = 0x0037,    /* Command Register */
+       Capr = 0x0038,  /* Current Address of Packet Read */
+       Cbr = 0x003A,   /* Current Buffer Address */
+       Imr = 0x003C,   /* Interrupt Mask */
+       Isr = 0x003E,   /* Interrupt Status */
+       Tcr = 0x0040,   /* Transmit Configuration */
+       Rcr = 0x0044,   /* Receive Configuration */
+       Tctr = 0x0048,  /* Timer Count */
+       Mpc = 0x004C,   /* Missed Packet Counter */
+       Cr9346 = 0x0050,        /* 9346 Command Register */
+       Config0 = 0x0051,       /* Configuration Register 0 */
+       Config1 = 0x0052,       /* Configuration Register 1 */
+       TimerInt = 0x0054,      /* Timer Interrupt */
+       Msr = 0x0058,   /* Media Status */
+       Config3 = 0x0059,       /* Configuration Register 3 */
+       Config4 = 0x005A,       /* Configuration Register 4 */
+       Mulint = 0x005C,        /* Multiple Interrupt Select */
+       RerID = 0x005E, /* PCI Revision ID */
+       Tsad = 0x0060,  /* Transmit Status of all Descriptors */
+
+       Bmcr = 0x0062,  /* Basic Mode Control */
+       Bmsr = 0x0064,  /* Basic Mode Status */
+       Anar = 0x0066,  /* Auto-Negotiation Advertisment */
+       Anlpar = 0x0068,        /* Auto-Negotiation Link Partner */
+       Aner = 0x006A,  /* Auto-Negotiation Expansion */
+       Dis = 0x006C,   /* Disconnect Counter */
+       Fcsc = 0x006E,  /* False Carrier Sense Counter */
+       Nwaytr = 0x0070,        /* N-way Test */
+       Rec = 0x0072,   /* RX_ER Counter */
+       Cscr = 0x0074,  /* CS Configuration */
+       Phy1parm = 0x0078,      /* PHY Parameter 1 */
+       Twparm = 0x007C,        /* Twister Parameter */
+       Phy2parm = 0x0080,      /* PHY Parameter 2 */
 };
 
-enum {                                 /* Cr */
-       Bufe            = 0x01,         /* Rx Buffer Empty */
-       Te              = 0x04,         /* Transmitter Enable */
-       Re              = 0x08,         /* Receiver Enable */
-       Rst             = 0x10,         /* Software Reset */
+enum {                                                 /* Cr */
+       Bufe = 0x01,                            /* Rx Buffer Empty */
+       Te = 0x04,      /* Transmitter Enable */
+       Re = 0x08,      /* Receiver Enable */
+       Rst = 0x10,     /* Software Reset */
 };
 
-enum {                                 /* Imr/Isr */
-       Rok             = 0x0001,       /* Receive OK */
-       Rer             = 0x0002,       /* Receive Error */
-       Tok             = 0x0004,       /* Transmit OK */
-       Ter             = 0x0008,       /* Transmit Error */
-       Rxovw           = 0x0010,       /* Receive Buffer Overflow */
-       PunLc           = 0x0020,       /* Packet Underrun or Link Change */
-       Fovw            = 0x0040,       /* Receive FIFO Overflow */
-       Clc             = 0x2000,       /* Cable Length Change */
-       Timerbit        = 0x4000,       /* Timer */
-       Serr            = 0x8000,       /* System Error */
+enum {                                                 /* Imr/Isr */
+       Rok = 0x0001,                           /* Receive OK */
+       Rer = 0x0002,   /* Receive Error */
+       Tok = 0x0004,   /* Transmit OK */
+       Ter = 0x0008,   /* Transmit Error */
+       Rxovw = 0x0010, /* Receive Buffer Overflow */
+       PunLc = 0x0020, /* Packet Underrun or Link Change */
+       Fovw = 0x0040,  /* Receive FIFO Overflow */
+       Clc = 0x2000,   /* Cable Length Change */
+       Timerbit = 0x4000,      /* Timer */
+       Serr = 0x8000,  /* System Error */
 };
 
-enum {                                 /* Tcr */
-       Clrabt          = 0x00000001,   /* Clear Abort */
-       TxrrSHIFT       = 4,            /* Transmit Retry Count */
-       TxrrMASK        = 0x000000F0,
-       MtxdmaSHIFT     = 8,            /* Max. DMA Burst Size */
-       MtxdmaMASK      = 0x00000700,
-       Mtxdma2048      = 0x00000700,
-       Acrc            = 0x00010000,   /* Append CRC (not) */
-       LbkSHIFT        = 17,           /* Loopback Test */
-       LbkMASK         = 0x00060000,
-       Rtl8139ArevG    = 0x00800000,   /* RTL8139A Rev. G ID */
-       IfgSHIFT        = 24,           /* Interframe Gap */
-       IfgMASK         = 0x03000000,
-       HwveridSHIFT    = 26,           /* Hardware Version ID */
-       HwveridMASK     = 0x7C000000,
+enum {                                                 /* Tcr */
+       Clrabt = 0x00000001,            /* Clear Abort */
+       TxrrSHIFT = 4,  /* Transmit Retry Count */
+       TxrrMASK = 0x000000F0,
+       MtxdmaSHIFT = 8,        /* Max. DMA Burst Size */
+       MtxdmaMASK = 0x00000700,
+       Mtxdma2048 = 0x00000700,
+       Acrc = 0x00010000,      /* Append CRC (not) */
+       LbkSHIFT = 17,  /* Loopback Test */
+       LbkMASK = 0x00060000,
+       Rtl8139ArevG = 0x00800000,      /* RTL8139A Rev. G ID */
+       IfgSHIFT = 24,  /* Interframe Gap */
+       IfgMASK = 0x03000000,
+       HwveridSHIFT = 26,      /* Hardware Version ID */
+       HwveridMASK = 0x7C000000,
 };
 
-enum {                                 /* Rcr */
-       Aap             = 0x00000001,   /* Accept All Packets */
-       Apm             = 0x00000002,   /* Accept Physical Match */
-       Am              = 0x00000004,   /* Accept Multicast */
-       Ab              = 0x00000008,   /* Accept Broadcast */
-       Ar              = 0x00000010,   /* Accept Runt */
-       Aer             = 0x00000020,   /* Accept Error */
-       Sel9356         = 0x00000040,   /* 9356 EEPROM used */
-       Wrap            = 0x00000080,   /* Rx Buffer Wrap Control */
-       MrxdmaSHIFT     = 8,            /* Max. DMA Burst Size */
-       MrxdmaMASK      = 0x00000700,
-       Mrxdmaunlimited = 0x00000700,
-       RblenSHIFT      = 11,           /* Receive Buffer Length */
-       RblenMASK       = 0x00001800,
-       Rblen8K         = 0x00000000,   /* 8KB+16 */
-       Rblen16K        = 0x00000800,   /* 16KB+16 */
-       Rblen32K        = 0x00001000,   /* 32KB+16 */
-       Rblen64K        = 0x00001800,   /* 64KB+16 */
-       RxfthSHIFT      = 13,           /* Receive Buffer Length */
-       RxfthMASK       = 0x0000E000,
-       Rxfth256        = 0x00008000,
-       Rxfthnone       = 0x0000E000,
-       Rer8            = 0x00010000,   /* Accept Error Packets > 8 bytes */
-       MulERINT        = 0x00020000,   /* Multiple Early Interrupt Select */
-       ErxthSHIFT      = 24,           /* Early Rx Threshold */
-       ErxthMASK       = 0x0F000000,
-       Erxthnone       = 0x00000000,
+enum {                                                 /* Rcr */
+       Aap = 0x00000001,                       /* Accept All Packets */
+       Apm = 0x00000002,       /* Accept Physical Match */
+       Am = 0x00000004,        /* Accept Multicast */
+       Ab = 0x00000008,        /* Accept Broadcast */
+       Ar = 0x00000010,        /* Accept Runt */
+       Aer = 0x00000020,       /* Accept Error */
+       Sel9356 = 0x00000040,   /* 9356 EEPROM used */
+       Wrap = 0x00000080,      /* Rx Buffer Wrap Control */
+       MrxdmaSHIFT = 8,        /* Max. DMA Burst Size */
+       MrxdmaMASK = 0x00000700,
+       Mrxdmaunlimited = 0x00000700,
+       RblenSHIFT = 11,        /* Receive Buffer Length */
+       RblenMASK = 0x00001800,
+       Rblen8K = 0x00000000,   /* 8KB+16 */
+       Rblen16K = 0x00000800,  /* 16KB+16 */
+       Rblen32K = 0x00001000,  /* 32KB+16 */
+       Rblen64K = 0x00001800,  /* 64KB+16 */
+       RxfthSHIFT = 13,        /* Receive Buffer Length */
+       RxfthMASK = 0x0000E000,
+       Rxfth256 = 0x00008000,
+       Rxfthnone = 0x0000E000,
+       Rer8 = 0x00010000,      /* Accept Error Packets > 8 bytes */
+       MulERINT = 0x00020000,  /* Multiple Early Interrupt Select */
+       ErxthSHIFT = 24,        /* Early Rx Threshold */
+       ErxthMASK = 0x0F000000,
+       Erxthnone = 0x00000000,
 };
 
-enum {                                 /* Received Packet Status */
-       Rcok            = 0x0001,       /* Receive Completed OK */
-       Fae             = 0x0002,       /* Frame Alignment Error */
-       Crc             = 0x0004,       /* CRC Error */
-       Long            = 0x0008,       /* Long Packet */
-       Runt            = 0x0010,       /* Runt Packet Received */
-       Ise             = 0x0020,       /* Invalid Symbol Error */
-       Bar             = 0x2000,       /* Broadcast Address Received */
-       Pam             = 0x4000,       /* Physical Address Matched */
-       Mar             = 0x8000,       /* Multicast Address Received */
+enum {                                                 /* Received Packet Status */
+       Rcok = 0x0001,                          /* Receive Completed OK */
+       Fae = 0x0002,   /* Frame Alignment Error */
+       Crc = 0x0004,   /* CRC Error */
+       Long = 0x0008,  /* Long Packet */
+       Runt = 0x0010,  /* Runt Packet Received */
+       Ise = 0x0020,   /* Invalid Symbol Error */
+       Bar = 0x2000,   /* Broadcast Address Received */
+       Pam = 0x4000,   /* Physical Address Matched */
+       Mar = 0x8000,   /* Multicast Address Received */
 };
 
-enum {                                 /* Media Status Register */
-       Rxpf            = 0x01,         /* Pause Flag */
-       Txpf            = 0x02,         /* Pause Flag */
-       Linkb           = 0x04,         /* Inverse of Link Status */
-       Speed10         = 0x08,         /* 10Mbps */
-       Auxstatus       = 0x10,         /* Aux. Power Present Status */
-       Rxfce           = 0x40,         /* Receive Flow Control Enable */
-       Txfce           = 0x80,         /* Transmit Flow Control Enable */
+enum {                                                 /* Media Status Register */
+       Rxpf = 0x01,                            /* Pause Flag */
+       Txpf = 0x02,    /* Pause Flag */
+       Linkb = 0x04,   /* Inverse of Link Status */
+       Speed10 = 0x08, /* 10Mbps */
+       Auxstatus = 0x10,       /* Aux. Power Present Status */
+       Rxfce = 0x40,   /* Receive Flow Control Enable */
+       Txfce = 0x80,   /* Transmit Flow Control Enable */
 };
 
 typedef struct Td Td;
-struct Td {                    /* Soft Transmit Descriptor */
-       int     tsd;
-       int     tsad;
-       uint8_t*        data;
-       struct block*   bp;
+struct Td {                                            /* Soft Transmit Descriptor */
+       int tsd;
+       int tsad;
+       uint8_t *data;
+       struct block *bp;
 };
 
-enum {                                 /* Tsd0 */
-       SizeSHIFT       = 0,            /* Descriptor Size */
-       SizeMASK        = 0x00001FFF,
-       Own             = 0x00002000,
-       Tun             = 0x00004000,   /* Transmit FIFO Underrun */
-       Tcok            = 0x00008000,   /* Transmit COmpleted OK */
-       EtxthSHIFT      = 16,           /* Early Tx Threshold */
-       EtxthMASK       = 0x001F0000,
-       NccSHIFT        = 24,           /* Number of Collisions Count */
-       NccMASK         = 0x0F000000,
-       Cdh             = 0x10000000,   /* CD Heartbeat */
-       Owc             = 0x20000000,   /* Out of Window Collision */
-       Tabt            = 0x40000000,   /* Transmit Abort */
-       Crs             = 0x80000000,   /* Carrier Sense Lost */
+enum {                                                 /* Tsd0 */
+       SizeSHIFT = 0,                          /* Descriptor Size */
+       SizeMASK = 0x00001FFF,
+       Own = 0x00002000,
+       Tun = 0x00004000,       /* Transmit FIFO Underrun */
+       Tcok = 0x00008000,      /* Transmit COmpleted OK */
+       EtxthSHIFT = 16,        /* Early Tx Threshold */
+       EtxthMASK = 0x001F0000,
+       NccSHIFT = 24,  /* Number of Collisions Count */
+       NccMASK = 0x0F000000,
+       Cdh = 0x10000000,       /* CD Heartbeat */
+       Owc = 0x20000000,       /* Out of Window Collision */
+       Tabt = 0x40000000,      /* Transmit Abort */
+       Crs = 0x80000000,       /* Carrier Sense Lost */
 };
 
 enum {
-       Rblen           = Rblen64K,     /* Receive Buffer Length */
-       Ntd             = 4,            /* Number of Transmit Descriptors */
-       Tdbsz           = ROUNDUP(sizeof(Etherpkt), 4),
+       Rblen = Rblen64K,                       /* Receive Buffer Length */
+       Ntd = 4,        /* Number of Transmit Descriptors */
+       Tdbsz = ROUNDUP(sizeof(Etherpkt), 4),
 };
 
 typedef struct Ctlr Ctlr;
 typedef struct Ctlr {
-       int     port;
-       Pcidevpcidev;
-       struct ctlr*    next;
-       int     active;
-       int     id;
-
-       qlock_t alock;                  /* attach */
-       spinlock_t      ilock;                  /* init */
-       void*   alloc;                  /* base of per-Ctlr allocated data */
-
-       int     rcr;                    /* receive configuration register */
-       uint8_t*        rbstart;                /* receive buffer */
-       int     rblen;                  /* receive buffer length */
-       int     ierrs;                  /* receive errors */
-
-       spinlock_t      tlock;                  /* transmit */
-       Td      td[Ntd];
-       int     ntd;                    /* descriptors active */
-       int     tdh;                    /* host index into td */
-       int     tdi;                    /* interface index into td */
-       int     etxth;                  /* early transmit threshold */
-       int     taligned;               /* packet required no alignment */
-       int     tunaligned;             /* packet required alignment */
-
-       int     dis;                    /* disconnect counter */
-       int     fcsc;                   /* false carrier sense counter */
-       int     rec;                    /* RX_ER counter */
+       int port;
+       Pcidev *pcidev;
+       struct ctlr *next;
+       int active;
+       int id;
+
+       qlock_t alock;                          /* attach */
+       spinlock_t ilock;                       /* init */
+       void *alloc;                            /* base of per-Ctlr allocated data */
+
+       int rcr;                                        /* receive configuration register */
+       uint8_t *rbstart;                       /* receive buffer */
+       int rblen;                                      /* receive buffer length */
+       int ierrs;                                      /* receive errors */
+
+       spinlock_t tlock;                       /* transmit */
+       Td td[Ntd];
+       int ntd;                                        /* descriptors active */
+       int tdh;                                        /* host index into td */
+       int tdi;                                        /* interface index into td */
+       int etxth;                                      /* early transmit threshold */
+       int taligned;                           /* packet required no alignment */
+       int tunaligned;                         /* packet required alignment */
+
+       int dis;                                        /* disconnect counter */
+       int fcsc;                                       /* false carrier sense counter */
+       int rec;                                        /* RX_ER counter */
 } Ctlr;
 
-static struct ctlrctlrhead;
-static struct ctlrctlrtail;
+static struct ctlr *ctlrhead;
+static struct ctlr *ctlrtail;
 
 #define csr8r(c, r)    (inb((c)->port+(r)))
 #define csr16r(c, r)   (ins((c)->port+(r)))
@@ -234,17 +234,16 @@ static struct ctlr* ctlrtail;
 #define csr16w(c, r, w)        (outs((c)->port+(r), (uint16_t)(w)))
 #define csr32w(c, r, l)        (outl((c)->port+(r), (uint32_t)(l)))
 
-static void
-rtl8139promiscuous(void* arg, int on)
+static void rtl8139promiscuous(void *arg, int on)
 {
        struct ether *edev;
-       struct ctlr * ctlr;
+       struct ctlr *ctlr;
 
        edev = arg;
        ctlr = edev->ctlr;
        spin_lock_irqsave(&(&ctlr->ilock)->lock);
 
-       if(on)
+       if (on)
                ctlr->rcr |= Aap;
        else
                ctlr->rcr &= ~Aap;
@@ -252,8 +251,7 @@ rtl8139promiscuous(void* arg, int on)
        spin_unlock_irqsave(&(&ctlr->ilock)->lock);
 }
 
-static long
-rtl8139ifstat(struct ether* edev, void* a, long n, uint32_t offset)
+static long rtl8139ifstat(struct ether *edev, void *a, long n, uint32_t offset)
 {
        int l;
        char *p;
@@ -262,39 +260,42 @@ rtl8139ifstat(struct ether* edev, void* a, long n, uint32_t offset)
        ctlr = edev->ctlr;
        p = kzmalloc(READSTR, 0);
        l = snprintf(p, READSTR, "rcr 0x%8.8x\n", ctlr->rcr);
-       l += snprintf(p+l, READSTR-l, "ierrs %d\n", ctlr->ierrs);
-       l += snprintf(p+l, READSTR-l, "etxth %d\n", ctlr->etxth);
-       l += snprintf(p+l, READSTR-l, "taligned %d\n", ctlr->taligned);
-       l += snprintf(p+l, READSTR-l, "tunaligned %d\n", ctlr->tunaligned);
+       l += snprintf(p + l, READSTR - l, "ierrs %d\n", ctlr->ierrs);
+       l += snprintf(p + l, READSTR - l, "etxth %d\n", ctlr->etxth);
+       l += snprintf(p + l, READSTR - l, "taligned %d\n", ctlr->taligned);
+       l += snprintf(p + l, READSTR - l, "tunaligned %d\n", ctlr->tunaligned);
        ctlr->dis += csr16r(ctlr, Dis);
-       l += snprintf(p+l, READSTR-l, "dis %d\n", ctlr->dis);
+       l += snprintf(p + l, READSTR - l, "dis %d\n", ctlr->dis);
        ctlr->fcsc += csr16r(ctlr, Fcsc);
-       l += snprintf(p+l, READSTR-l, "fcscnt %d\n", ctlr->fcsc);
+       l += snprintf(p + l, READSTR - l, "fcscnt %d\n", ctlr->fcsc);
        ctlr->rec += csr16r(ctlr, Rec);
-       l += snprintf(p+l, READSTR-l, "rec %d\n", ctlr->rec);
-
-       l += snprintf(p+l, READSTR-l, "Tcr 0x%8.8lx\n", csr32r(ctlr, Tcr));
-       l += snprintf(p+l, READSTR-l, "Config0 0x%2.2x\n", csr8r(ctlr, Config0));
-       l += snprintf(p+l, READSTR-l, "Config1 0x%2.2x\n", csr8r(ctlr, Config1));
-       l += snprintf(p+l, READSTR-l, "Msr 0x%2.2x\n", csr8r(ctlr, Msr));
-       l += snprintf(p+l, READSTR-l, "Config3 0x%2.2x\n", csr8r(ctlr, Config3));
-       l += snprintf(p+l, READSTR-l, "Config4 0x%2.2x\n", csr8r(ctlr, Config4));
-
-       l += snprintf(p+l, READSTR-l, "Bmcr 0x%4.4x\n", csr16r(ctlr, Bmcr));
-       l += snprintf(p+l, READSTR-l, "Bmsr 0x%4.4x\n", csr16r(ctlr, Bmsr));
-       l += snprintf(p+l, READSTR-l, "Anar 0x%4.4x\n", csr16r(ctlr, Anar));
-       l += snprintf(p+l, READSTR-l, "Anlpar 0x%4.4x\n", csr16r(ctlr, Anlpar));
-       l += snprintf(p+l, READSTR-l, "Aner 0x%4.4x\n", csr16r(ctlr, Aner));
-       l += snprintf(p+l, READSTR-l, "Nwaytr 0x%4.4x\n", csr16r(ctlr, Nwaytr));
-       snprintf(p+l, READSTR-l, "Cscr 0x%4.4x\n", csr16r(ctlr, Cscr));
+       l += snprintf(p + l, READSTR - l, "rec %d\n", ctlr->rec);
+
+       l += snprintf(p + l, READSTR - l, "Tcr 0x%8.8lx\n", csr32r(ctlr, Tcr));
+       l += snprintf(p + l, READSTR - l, "Config0 0x%2.2x\n",
+                                 csr8r(ctlr, Config0));
+       l += snprintf(p + l, READSTR - l, "Config1 0x%2.2x\n",
+                                 csr8r(ctlr, Config1));
+       l += snprintf(p + l, READSTR - l, "Msr 0x%2.2x\n", csr8r(ctlr, Msr));
+       l += snprintf(p + l, READSTR - l, "Config3 0x%2.2x\n",
+                                 csr8r(ctlr, Config3));
+       l += snprintf(p + l, READSTR - l, "Config4 0x%2.2x\n",
+                                 csr8r(ctlr, Config4));
+
+       l += snprintf(p + l, READSTR - l, "Bmcr 0x%4.4x\n", csr16r(ctlr, Bmcr));
+       l += snprintf(p + l, READSTR - l, "Bmsr 0x%4.4x\n", csr16r(ctlr, Bmsr));
+       l += snprintf(p + l, READSTR - l, "Anar 0x%4.4x\n", csr16r(ctlr, Anar));
+       l += snprintf(p + l, READSTR - l, "Anlpar 0x%4.4x\n", csr16r(ctlr, Anlpar));
+       l += snprintf(p + l, READSTR - l, "Aner 0x%4.4x\n", csr16r(ctlr, Aner));
+       l += snprintf(p + l, READSTR - l, "Nwaytr 0x%4.4x\n", csr16r(ctlr, Nwaytr));
+       snprintf(p + l, READSTR - l, "Cscr 0x%4.4x\n", csr16r(ctlr, Cscr));
        n = readstr(offset, a, n, p);
        kfree(p);
 
        return n;
 }
 
-static int
-rtl8139reset(struct ctlr* ctlr)
+static int rtl8139reset(struct ctlr *ctlr)
 {
        int timeo;
 
@@ -302,8 +303,8 @@ rtl8139reset(struct ctlr* ctlr)
         * Soft reset the controller.
         */
        csr8w(ctlr, Cr, Rst);
-       for(timeo = 0; timeo < 1000; timeo++){
-               if(!(csr8r(ctlr, Cr) & Rst))
+       for (timeo = 0; timeo < 1000; timeo++) {
+               if (!(csr8r(ctlr, Cr) & Rst))
                        return 0;
                delay(1);
        }
@@ -311,8 +312,7 @@ rtl8139reset(struct ctlr* ctlr)
        return -1;
 }
 
-static void
-rtl8139halt(struct ctlr* ctlr)
+static void rtl8139halt(struct ctlr *ctlr)
 {
        int i;
 
@@ -320,16 +320,15 @@ rtl8139halt(struct ctlr* ctlr)
        csr16w(ctlr, Imr, 0);
        csr16w(ctlr, Isr, ~0);
 
-       for(i = 0; i < Ntd; i++){
-               if(ctlr->td[i].bp == NULL)
+       for (i = 0; i < Ntd; i++) {
+               if (ctlr->td[i].bp == NULL)
                        continue;
                freeb(ctlr->td[i].bp);
                ctlr->td[i].bp = NULL;
        }
 }
 
-static void
-rtl8139init(struct ether* edev)
+static void rtl8139init(struct ether *edev)
 {
        int i;
        uint32_t r;
@@ -344,69 +343,72 @@ rtl8139init(struct ether* edev)
        /*
         * MAC Address.
         */
-       r = (edev->ea[3]<<24)|(edev->ea[2]<<16)|(edev->ea[1]<<8)|edev->ea[0];
+       r = (edev->ea[3] << 24) | (edev->ea[2] << 16) | (edev->ea[1] << 8) | edev->
+               ea[0];
        csr32w(ctlr, Idr0, r);
-       r = (edev->ea[5]<<8)|edev->ea[4];
-       csr32w(ctlr, Idr0+4, r);
+       r = (edev->ea[5] << 8) | edev->ea[4];
+       csr32w(ctlr, Idr0 + 4, r);
 
        /*
         * Receiver
         */
-       alloc = mmucacheinhib(( char *unused_char_p_t)ROUNDUP((uint32_t)ctlr->alloc, CACHELINESZ), ctlr->rblen+16 + Ntd*Tdbsz);
+       alloc =
+               mmucacheinhib((char *unused_char_p_t)
+                                         ROUNDUP((uint32_t) ctlr->alloc, CACHELINESZ),
+                                         ctlr->rblen + 16 + Ntd * Tdbsz);
        ctlr->rbstart = alloc;
-       alloc += ctlr->rblen+16;
-       memset(ctlr->rbstart, 0, ctlr->rblen+16);
+       alloc += ctlr->rblen + 16;
+       memset(ctlr->rbstart, 0, ctlr->rblen + 16);
        csr32w(ctlr, Rbstart, PCIWADDR(ctlr->rbstart));
-       ctlr->rcr = Rxfth256|Rblen|Mrxdmaunlimited|Ab|Apm;
+       ctlr->rcr = Rxfth256 | Rblen | Mrxdmaunlimited | Ab | Apm;
 
        /*
         * Transmitter.
         */
-       for(i = 0; i < Ntd; i++){
-               ctlr->td[i].tsd = Tsd0+i*4;
-               ctlr->td[i].tsad = Tsad0+i*4;
+       for (i = 0; i < Ntd; i++) {
+               ctlr->td[i].tsd = Tsd0 + i * 4;
+               ctlr->td[i].tsad = Tsad0 + i * 4;
                ctlr->td[i].data = alloc;
                alloc += Tdbsz;
                ctlr->td[i].bp = NULL;
        }
        ctlr->ntd = ctlr->tdh = ctlr->tdi = 0;
-       ctlr->etxth = 128/32;
+       ctlr->etxth = 128 / 32;
 
        /*
         * Interrupts.
         */
        csr32w(ctlr, TimerInt, 0);
-       csr16w(ctlr, Imr, Serr|Timerbit|Fovw|PunLc|Rxovw|Ter|Tok|Rer|Rok);
+       csr16w(ctlr, Imr,
+                  Serr | Timerbit | Fovw | PunLc | Rxovw | Ter | Tok | Rer | Rok);
        csr32w(ctlr, Mpc, 0);
 
        /*
         * Enable receiver/transmitter.
         * Need to enable before writing the Rcr or it won't take.
         */
-       csr8w(ctlr, Cr, Te|Re);
+       csr8w(ctlr, Cr, Te | Re);
        csr32w(ctlr, Tcr, Mtxdma2048);
        csr32w(ctlr, Rcr, ctlr->rcr);
 
        spin_unlock_irqsave(&(&ctlr->ilock)->lock);
 }
 
-static void
-rtl8139attach(struct ether* edev)
+static void rtl8139attach(struct ether *edev)
 {
        struct ctlr *ctlr;
 
        ctlr = edev->ctlr;
        qlock(&(&ctlr->alock)->qlock);
-       if(ctlr->alloc == NULL){
-               ctlr->rblen = 1<<((Rblen>>RblenSHIFT)+13);
-               ctlr->alloc = mallocz(ctlr->rblen+16 + Ntd*Tdbsz + CACHELINESZ, 0);
+       if (ctlr->alloc == NULL) {
+               ctlr->rblen = 1 << ((Rblen >> RblenSHIFT) + 13);
+               ctlr->alloc = mallocz(ctlr->rblen + 16 + Ntd * Tdbsz + CACHELINESZ, 0);
                rtl8139init(edev);
        }
        qunlock(&(&ctlr->alock)->qlock);
 }
 
-static void
-rtl8139txstart(struct ether* edev)
+static void rtl8139txstart(struct ether *edev)
 {
        Td *td;
        int size;
@@ -414,35 +416,33 @@ rtl8139txstart(struct ether* edev)
        struct ctlr *ctlr;
 
        ctlr = edev->ctlr;
-       while(ctlr->ntd < Ntd){
+       while (ctlr->ntd < Ntd) {
                bp = qget(edev->oq);
-               if(bp == NULL)
+               if (bp == NULL)
                        break;
                size = BLEN(bp);
 
                td = &ctlr->td[ctlr->tdh];
-               if(((int)bp->rp) & 0x03){
+               if (((int)bp->rp) & 0x03) {
                        memmove(td->data, bp->rp, size);
                        dcflush(td->data, size);
                        freeb(bp);
                        csr32w(ctlr, td->tsad, PCIWADDR(td->data));
                        ctlr->tunaligned++;
-               }
-               else{
+               } else {
                        td->bp = bp;
                        csr32w(ctlr, td->tsad, PCIWADDR(bp->rp));
                        dcflush(bp->rp, size);
                        ctlr->taligned++;
                }
-               csr32w(ctlr, td->tsd, (ctlr->etxth<<EtxthSHIFT)|size);
+               csr32w(ctlr, td->tsd, (ctlr->etxth << EtxthSHIFT) | size);
 
                ctlr->ntd++;
                ctlr->tdh = NEXT(ctlr->tdh, Ntd);
        }
 }
 
-static void
-rtl8139transmit(struct ether* edev)
+static void rtl8139transmit(struct ether *edev)
 {
        struct ctlr *ctlr;
 
@@ -452,8 +452,7 @@ rtl8139transmit(struct ether* edev)
        spin_unlock_irqsave(&(&ctlr->tlock)->lock);
 }
 
-static void
-rtl8139receive(struct ether* edev)
+static void rtl8139receive(struct ether *edev)
 {
        struct block *bp;
        struct ctlr *ctlr;
@@ -467,24 +466,24 @@ rtl8139receive(struct ether* edev)
         * Capr is where the host is reading from,
         * Cbr is where the NIC is currently writing.
         */
-       capr = (csr16r(ctlr, Capr)+16) % ctlr->rblen;
-       while(!(csr8r(ctlr, Cr) & Bufe)){
-               p = ctlr->rbstart+capr;
+       capr = (csr16r(ctlr, Capr) + 16) % ctlr->rblen;
+       while (!(csr8r(ctlr, Cr) & Bufe)) {
+               p = ctlr->rbstart + capr;
 
                /*
                 * Apparently the packet length may be 0xFFF0 if
                 * the NIC is still copying the packet into memory.
                 */
-               length = (*(p+3)<<8)|*(p+2);
-               if(length == 0xFFF0)
+               length = (*(p + 3) << 8) | *(p + 2);
+               if (length == 0xFFF0)
                        break;
-               status = (*(p+1)<<8)|*p;
-               if(!(status & Rcok)){
-                       if(status & (Ise|Fae))
+               status = (*(p + 1) << 8) | *p;
+               if (!(status & Rcok)) {
+                       if (status & (Ise | Fae))
                                edev->frames++;
-                       if(status & Crc)
+                       if (status & Crc)
                                edev->crcs++;
-                       if(status & (Runt|Long))
+                       if (status & (Runt | Long))
                                edev->buffs++;
 
                        /*
@@ -508,19 +507,19 @@ rtl8139receive(struct ether* edev)
                 * the squeeze.
                 * The packet length includes a 4 byte CRC on the end.
                 */
-               capr = (capr+4) % ctlr->rblen;
-               p = ctlr->rbstart+capr;
-               capr = (capr+length) % ctlr->rblen;
+               capr = (capr + 4) % ctlr->rblen;
+               p = ctlr->rbstart + capr;
+               capr = (capr + length) % ctlr->rblen;
 
-               if((bp = iallocb(length)) != NULL){
-                       if(p+length >= ctlr->rbstart+ctlr->rblen){
-                               l = ctlr->rbstart+ctlr->rblen - p;
+               if ((bp = iallocb(length)) != NULL) {
+                       if (p + length >= ctlr->rbstart + ctlr->rblen) {
+                               l = ctlr->rbstart + ctlr->rblen - p;
                                memmove(bp->wp, p, l);
                                bp->wp += l;
                                length -= l;
                                p = ctlr->rbstart;
                        }
-                       if(length > 0){
+                       if (length > 0) {
                                memmove(bp->wp, p, length);
                                bp->wp += length;
                        }
@@ -529,12 +528,11 @@ rtl8139receive(struct ether* edev)
                }
 
                capr = ROUNDUP(capr, 4);
-               csr16w(ctlr, Capr, capr-16);
+               csr16w(ctlr, Capr, capr - 16);
        }
 }
 
-static void
-rtl8139interrupt(Ureg*, void* arg)
+static void rtl8139interrupt(Ureg *, void *arg)
 {
        Td *td;
        struct ctlr *ctlr;
@@ -544,32 +542,32 @@ rtl8139interrupt(Ureg*, void* arg)
        edev = arg;
        ctlr = edev->ctlr;
 
-       while((isr = csr16r(ctlr, Isr)) != 0){
+       while ((isr = csr16r(ctlr, Isr)) != 0) {
                csr16w(ctlr, Isr, isr);
-               if(isr & (Fovw|PunLc|Rxovw|Rer|Rok)){
+               if (isr & (Fovw | PunLc | Rxovw | Rer | Rok)) {
                        rtl8139receive(edev);
-                       if(!(isr & Rok))
+                       if (!(isr & Rok))
                                ctlr->ierrs++;
-                       isr &= ~(Fovw|Rxovw|Rer|Rok);
+                       isr &= ~(Fovw | Rxovw | Rer | Rok);
                }
 
-               if(isr & (Ter|Tok)){
+               if (isr & (Ter | Tok)) {
                        spin_lock_irqsave(&(&ctlr->tlock)->lock);
-                       while(ctlr->ntd){
+                       while (ctlr->ntd) {
                                td = &ctlr->td[ctlr->tdi];
                                tsd = csr32r(ctlr, td->tsd);
-                               if(!(tsd & (Tabt|Tun|Tcok)))
+                               if (!(tsd & (Tabt | Tun | Tcok)))
                                        break;
 
-                               if(!(tsd & Tcok)){
-                                       if(tsd & Tun){
-                                               if(ctlr->etxth < ETHERMAXTU/32)
+                               if (!(tsd & Tcok)) {
+                                       if (tsd & Tun) {
+                                               if (ctlr->etxth < ETHERMAXTU / 32)
                                                        ctlr->etxth++;
                                        }
                                        edev->oerrs++;
                                }
 
-                               if(td->bp != NULL){
+                               if (td->bp != NULL) {
                                        freeb(td->bp);
                                        td->bp = NULL;
                                }
@@ -579,25 +577,24 @@ rtl8139interrupt(Ureg*, void* arg)
                        }
                        rtl8139txstart(edev);
                        spin_unlock_irqsave(&(&ctlr->tlock)->lock);
-                       isr &= ~(Ter|Tok);
+                       isr &= ~(Ter | Tok);
                }
 
-               if(isr & PunLc){
+               if (isr & PunLc) {
                        /*
                         * Maybe the link changed - do we care very much?
                         */
                        msr = csr8r(ctlr, Msr);
-                       if(!(msr & Linkb)){
-                               if(!(msr & Speed10) && edev->mbps != 100){
+                       if (!(msr & Linkb)) {
+                               if (!(msr & Speed10) && edev->mbps != 100) {
                                        edev->mbps = 100;
-                                       qsetlimit(edev->oq, 256*1024);
-                               }
-                               else if((msr & Speed10) && edev->mbps != 10){
+                                       qsetlimit(edev->oq, 256 * 1024);
+                               } else if ((msr & Speed10) && edev->mbps != 10) {
                                        edev->mbps = 10;
-                                       qsetlimit(edev->oq, 65*1024);
+                                       qsetlimit(edev->oq, 65 * 1024);
                                }
                        }
-                       isr &= ~(Clc|PunLc);
+                       isr &= ~(Clc | PunLc);
                }
 
                /*
@@ -607,19 +604,18 @@ rtl8139interrupt(Ureg*, void* arg)
                 * by Serr, that's pretty serious; is there anyhing to do
                 * other than try to reinitialise the chip?
                 */
-               if(isr != 0){
+               if (isr != 0) {
                        iprint("rtl8139interrupt: imr 0x%4.4x isr 0x%4.4x\n",
-                               csr16r(ctlr, Imr), isr);
-                       if(isr & Timerbit)
+                                  csr16r(ctlr, Imr), isr);
+                       if (isr & Timerbit)
                                csr32w(ctlr, TimerInt, 0);
-                       if(isr & Serr)
+                       if (isr & Serr)
                                rtl8139init(edev);
                }
        }
 }
 
-static struct ctlr*
-rtl8139match(struct ether* edev, int id)
+static struct ctlr *rtl8139match(struct ether *edev, int id)
 {
        int port;
        Pcidev *p;
@@ -629,23 +625,23 @@ rtl8139match(struct ether* edev, int id)
         * Any adapter matches if no edev->port is supplied,
         * otherwise the ports must match.
         */
-       for(ctlr = ctlrhead; ctlr != NULL; ctlr = ctlr->next){
-               if(ctlr->active)
+       for (ctlr = ctlrhead; ctlr != NULL; ctlr = ctlr->next) {
+               if (ctlr->active)
                        continue;
                p = ctlr->pcidev;
-               if(((p->did<<16)|p->vid) != id)
+               if (((p->did << 16) | p->vid) != id)
                        continue;
                port = p->mem[0].bar & ~0x01;
-               if(edev->port != 0 && edev->port != port)
+               if (edev->port != 0 && edev->port != port)
                        continue;
 
-               if(ioalloc(port, p->mem[0].size, 0, "rtl8139") < 0){
+               if (ioalloc(port, p->mem[0].size, 0, "rtl8139") < 0) {
                        printd("rtl8139: port 0x%x in use\n", port);
                        continue;
                }
 
                ctlr->port = port;
-               if(rtl8139reset(ctlr))
+               if (rtl8139reset(ctlr))
                        continue;
                pcisetbme(p);
 
@@ -656,18 +652,21 @@ rtl8139match(struct ether* edev, int id)
 }
 
 static struct {
-       char*   name;
-       int     id;
+       char *name;
+       int id;
 } rtl8139pci[] = {
-       { "rtl8139",    (0x8139<<16)|0x10EC, }, /* generic */
-       { "smc1211",    (0x1211<<16)|0x1113, }, /* SMC EZ-Card */
-       { "dfe-538tx",  (0x1300<<16)|0x1186, }, /* D-Link DFE-538TX */
-       { "dfe-560txd", (0x1340<<16)|0x1186, }, /* D-Link DFE-560TXD */
-       { NULL },
-};
-
-static int
-rtl8139pnp(struct ether* edev)
+       {
+       "rtl8139", (0x8139 << 16) | 0x10EC,},   /* generic */
+       {
+       "smc1211", (0x1211 << 16) | 0x1113,},   /* SMC EZ-Card */
+       {
+       "dfe-538tx", (0x1300 << 16) | 0x1186,}, /* D-Link DFE-538TX */
+       {
+       "dfe-560txd", (0x1340 << 16) | 0x1186,},        /* D-Link DFE-560TXD */
+       {
+NULL},};
+
+static int rtl8139pnp(struct ether *edev)
 {
        int i, id;
        Pcidev *p;
@@ -678,16 +677,16 @@ rtl8139pnp(struct ether* edev)
         * Make a list of all ethernet controllers
         * if not already done.
         */
-       if(ctlrhead == NULL){
+       if (ctlrhead == NULL) {
                p = NULL;
-               while(p = pcimatch(p, 0, 0)){
-                       if(p->ccrb != 0x02 || p->ccru != 0)
+               while (p = pcimatch(p, 0, 0)) {
+                       if (p->ccrb != 0x02 || p->ccru != 0)
                                continue;
                        ctlr = kzmalloc(sizeof(struct ctlr), 0);
                        ctlr->pcidev = p;
-                       ctlr->id = (p->did<<16)|p->vid;
+                       ctlr->id = (p->did << 16) | p->vid;
 
-                       if(ctlrhead != NULL)
+                       if (ctlrhead != NULL)
                                ctlrtail->next = ctlr;
                        else
                                ctlrhead = ctlr;
@@ -703,19 +702,20 @@ rtl8139pnp(struct ether* edev)
         * specific controller only.
         */
        id = 0;
-       for(i = 0; i < edev->nopt; i++){
-               if(cistrncmp(edev->opt[i], "id=", 3) == 0)
+       for (i = 0; i < edev->nopt; i++) {
+               if (cistrncmp(edev->opt[i], "id=", 3) == 0)
                        id = strtol(&edev->opt[i][3], NULL, 0);
        }
 
        ctlr = NULL;
-       if(id != 0)
+       if (id != 0)
                ctlr = rtl8139match(edev, id);
-       else for(i = 0; rtl8139pci[i].name; i++){
-               if((ctlr = rtl8139match(edev, rtl8139pci[i].id)) != NULL)
-                       break;
-       }
-       if(ctlr == NULL)
+       else
+               for (i = 0; rtl8139pci[i].name; i++) {
+                       if ((ctlr = rtl8139match(edev, rtl8139pci[i].id)) != NULL)
+                               break;
+               }
+       if (ctlr == NULL)
                return -1;
 
        edev->ctlr = ctlr;
@@ -728,15 +728,15 @@ rtl8139pnp(struct ether* edev)
         * If not, read it from the device and set in edev->ea.
         */
        memset(ea, 0, Eaddrlen);
-       if(memcmp(ea, edev->ea, Eaddrlen) == 0){
+       if (memcmp(ea, edev->ea, Eaddrlen) == 0) {
                i = csr32r(ctlr, Idr0);
                edev->ea[0] = i;
-               edev->ea[1] = i>>8;
-               edev->ea[2] = i>>16;
-               edev->ea[3] = i>>24;
-               i = csr32r(ctlr, Idr0+4);
+               edev->ea[1] = i >> 8;
+               edev->ea[2] = i >> 16;
+               edev->ea[3] = i >> 24;
+               i = csr32r(ctlr, Idr0 + 4);
                edev->ea[4] = i;
-               edev->ea[5] = i>>8;
+               edev->ea[5] = i >> 8;
        }
        edev->attach = rtl8139attach;
        edev->transmit = rtl8139transmit;
@@ -749,14 +749,13 @@ rtl8139pnp(struct ether* edev)
        /*
         * This should be much more dynamic but will do for now.
         */
-       if((csr8r(ctlr, Msr) & (Speed10|Linkb)) == 0)
+       if ((csr8r(ctlr, Msr) & (Speed10 | Linkb)) == 0)
                edev->mbps = 100;
 
        return 0;
 }
 
-void __etherlink
-ether8139link(void)
+void __etherlink ether8139link(void)
 {
        addethercard("rtl8139", rtl8139pnp);
 }