diff options
author | Brad Smith <brad@cvs.openbsd.org> | 2006-03-25 05:00:29 +0000 |
---|---|---|
committer | Brad Smith <brad@cvs.openbsd.org> | 2006-03-25 05:00:29 +0000 |
commit | bc24c791017696468a7cc028f63ab74d74a86676 (patch) | |
tree | 570e287e8bcf81365dd98894a5d74397f52b2188 /sys/dev/pci | |
parent | 5a411b54a46b2e9024e23cf93f14b270143b5691 (diff) |
ANSI and KNF.
Diffstat (limited to 'sys/dev/pci')
-rw-r--r-- | sys/dev/pci/if_sis.c | 289 |
1 files changed, 113 insertions, 176 deletions
diff --git a/sys/dev/pci/if_sis.c b/sys/dev/pci/if_sis.c index 7ba76e81c97..3256c103d48 100644 --- a/sys/dev/pci/if_sis.c +++ b/sys/dev/pci/if_sis.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if_sis.c,v 1.63 2006/03/25 03:21:56 brad Exp $ */ +/* $OpenBSD: if_sis.c,v 1.64 2006/03/25 05:00:28 brad Exp $ */ /* * Copyright (c) 1997, 1998, 1999 * Bill Paul <wpaul@ctr.columbia.edu>. All rights reserved. @@ -59,7 +59,6 @@ */ #include "bpfilter.h" -#include "vlan.h" #include <sys/param.h> #include <sys/systm.h> @@ -105,6 +104,15 @@ int sis_probe(struct device *, void *, void *); void sis_attach(struct device *, struct device *, void *); + +struct cfattach sis_ca = { + sizeof(struct sis_softc), sis_probe, sis_attach +}; + +struct cfdriver sis_cd = { + 0, "sis", DV_IFNET +}; + int sis_intr(void *); void sis_shutdown(void *); int sis_newbuf(struct sis_softc *, struct sis_desc *, @@ -163,34 +171,38 @@ int sis_ring_init(struct sis_softc *); #define SIO_CLR(x) \ CSR_WRITE_4(sc, SIS_EECTL, CSR_READ_4(sc, SIS_EECTL) & ~x) +const struct pci_matchid sis_devices[] = { + { PCI_VENDOR_SIS, PCI_PRODUCT_SIS_900 }, + { PCI_VENDOR_SIS, PCI_PRODUCT_SIS_7016 }, + { PCI_VENDOR_NS, PCI_PRODUCT_NS_DP83815 } +}; + /* * Routine to reverse the bits in a word. Stolen almost * verbatim from /usr/games/fortune. */ -u_int16_t sis_reverse(n) - u_int16_t n; +u_int16_t +sis_reverse(u_int16_t n) { n = ((n >> 1) & 0x5555) | ((n << 1) & 0xaaaa); n = ((n >> 2) & 0x3333) | ((n << 2) & 0xcccc); n = ((n >> 4) & 0x0f0f) | ((n << 4) & 0xf0f0); n = ((n >> 8) & 0x00ff) | ((n << 8) & 0xff00); - return(n); + return (n); } -void sis_delay(sc) - struct sis_softc *sc; +void +sis_delay(struct sis_softc *sc) { int idx; for (idx = (300 / 33) + 1; idx > 0; idx--) CSR_READ_4(sc, SIS_CSR); - - return; } -void sis_eeprom_idle(sc) - struct sis_softc *sc; +void +sis_eeprom_idle(struct sis_softc *sc) { int i; @@ -211,16 +223,13 @@ void sis_eeprom_idle(sc) SIO_CLR(SIS_EECTL_CSEL); sis_delay(sc); CSR_WRITE_4(sc, SIS_EECTL, 0x00000000); - - return; } /* * Send a read command and address to the EEPROM, check for ACK. */ -void sis_eeprom_putbyte(sc, addr) - struct sis_softc *sc; - int addr; +void +sis_eeprom_putbyte(struct sis_softc *sc, int addr) { int d, i; @@ -230,28 +239,23 @@ void sis_eeprom_putbyte(sc, addr) * Feed in each bit and strobe the clock. */ for (i = 0x400; i; i >>= 1) { - if (d & i) { + if (d & i) SIO_SET(SIS_EECTL_DIN); - } else { + else SIO_CLR(SIS_EECTL_DIN); - } sis_delay(sc); SIO_SET(SIS_EECTL_CLK); sis_delay(sc); SIO_CLR(SIS_EECTL_CLK); sis_delay(sc); } - - return; } /* * Read a word of data stored in the EEPROM at address 'addr.' */ -void sis_eeprom_getword(sc, addr, dest) - struct sis_softc *sc; - int addr; - u_int16_t *dest; +void +sis_eeprom_getword(struct sis_softc *sc, int addr, u_int16_t *dest) { int i; u_int16_t word = 0; @@ -288,19 +292,14 @@ void sis_eeprom_getword(sc, addr, dest) sis_eeprom_idle(sc); *dest = word; - - return; } /* * Read a sequence of words from the EEPROM. */ -void sis_read_eeprom(sc, dest, off, cnt, swap) - struct sis_softc *sc; - caddr_t dest; - int off; - int cnt; - int swap; +void +sis_read_eeprom(struct sis_softc *sc, caddr_t dest, + int off, int cnt, int swap) { int i; u_int16_t word = 0, *ptr; @@ -313,16 +312,12 @@ void sis_read_eeprom(sc, dest, off, cnt, swap) else *ptr = word; } - - return; } #if defined(__amd64__) || defined(__i386__) -void sis_read_cmos(sc, pa, dest, off, cnt) - struct sis_softc *sc; - struct pci_attach_args *pa; - caddr_t dest; - int off, cnt; +void +sis_read_cmos(struct sis_softc *sc, struct pci_attach_args *pa, + caddr_t dest, int off, int cnt) { bus_space_tag_t btag; u_int32_t reg; @@ -346,9 +341,8 @@ void sis_read_cmos(sc, pa, dest, off, cnt) } #endif -void sis_read_mac(sc, pa) - struct sis_softc *sc; - struct pci_attach_args *pa; +void +sis_read_mac(struct sis_softc *sc, struct pci_attach_args *pa) { u_int16_t *enaddr = (u_int16_t *) &sc->arpcom.ac_enaddr; @@ -367,8 +361,8 @@ void sis_read_mac(sc, pa) SIS_SETBIT(sc, SIS_RXFILT_CTL, SIS_RXFILTCTL_ENABLE); } -void sis_read96x_mac(sc) - struct sis_softc *sc; +void +sis_read96x_mac(struct sis_softc *sc) { int i; @@ -389,8 +383,8 @@ void sis_read96x_mac(sc) /* * Sync the PHYs by setting data bit and strobing the clock 32 times. */ -void sis_mii_sync(sc) - struct sis_softc *sc; +void +sis_mii_sync(struct sis_softc *sc) { int i; @@ -402,28 +396,23 @@ void sis_mii_sync(sc) SIO_CLR(SIS_MII_CLK); DELAY(1); } - - return; } /* * Clock a series of bits through the MII. */ -void sis_mii_send(sc, bits, cnt) - struct sis_softc *sc; - u_int32_t bits; - int cnt; +void +sis_mii_send(struct sis_softc *sc, u_int32_t bits, int cnt) { int i; SIO_CLR(SIS_MII_CLK); for (i = (0x1 << (cnt - 1)); i; i >>= 1) { - if (bits & i) { + if (bits & i) SIO_SET(SIS_MII_DATA); - } else { + else SIO_CLR(SIS_MII_DATA); - } DELAY(1); SIO_CLR(SIS_MII_CLK); DELAY(1); @@ -434,10 +423,8 @@ void sis_mii_send(sc, bits, cnt) /* * Read an PHY register through the MII. */ -int sis_mii_readreg(sc, frame) - struct sis_softc *sc; - struct sis_mii_frame *frame; - +int +sis_mii_readreg(struct sis_softc *sc, struct sis_mii_frame *frame) { int i, ack, s; @@ -518,17 +505,15 @@ fail: splx(s); if (ack) - return(1); - return(0); + return (1); + return (0); } /* * Write to a PHY register through the MII. */ -int sis_mii_writereg(sc, frame) - struct sis_softc *sc; - struct sis_mii_frame *frame; - +int +sis_mii_writereg(struct sis_softc *sc, struct sis_mii_frame *frame) { int s; @@ -568,19 +553,18 @@ int sis_mii_writereg(sc, frame) splx(s); - return(0); + return (0); } -int sis_miibus_readreg(self, phy, reg) - struct device *self; - int phy, reg; +int +sis_miibus_readreg(struct device *self, int phy, int reg) { struct sis_softc *sc = (struct sis_softc *)self; struct sis_mii_frame frame; if (sc->sis_type == SIS_TYPE_83815) { if (phy != 0) - return(0); + return (0); /* * The NatSemi chip can take a while after * a reset to come ready, during which the BMSR @@ -606,7 +590,7 @@ int sis_miibus_readreg(self, phy, reg) int i, val = 0; if (phy != 0) - return(0); + return (0); CSR_WRITE_4(sc, SIS_PHYCTL, (phy << 11) | (reg << 6) | SIS_PHYOP_READ); @@ -620,15 +604,15 @@ int sis_miibus_readreg(self, phy, reg) if (i == SIS_TIMEOUT) { printf("%s: PHY failed to come ready\n", sc->sc_dev.dv_xname); - return(0); + return (0); } val = (CSR_READ_4(sc, SIS_PHYCTL) >> 16) & 0xFFFF; if (val == 0xFFFF) - return(0); + return (0); - return(val); + return (val); } else { bzero((char *)&frame, sizeof(frame)); @@ -636,14 +620,12 @@ int sis_miibus_readreg(self, phy, reg) frame.mii_regaddr = reg; sis_mii_readreg(sc, &frame); - return(frame.mii_data); + return (frame.mii_data); } } - -void sis_miibus_writereg(self, phy, reg, data) - struct device *self; - int phy, reg, data; +void +sis_miibus_writereg(struct device *self, int phy, int reg, int data) { struct sis_softc *sc = (struct sis_softc *)self; struct sis_mii_frame frame; @@ -687,18 +669,14 @@ void sis_miibus_writereg(self, phy, reg, data) frame.mii_data = data; sis_mii_writereg(sc, &frame); } - return; } void -sis_miibus_statchg(self) - struct device *self; +sis_miibus_statchg(struct device *self) { struct sis_softc *sc = (struct sis_softc *)self; sis_init(sc); - - return; } u_int32_t @@ -849,8 +827,8 @@ allmulti: CSR_WRITE_4(sc, SIS_RXFILT_CTL, ctl); } -void sis_reset(sc) - struct sis_softc *sc; +void +sis_reset(struct sis_softc *sc) { int i; @@ -875,24 +853,14 @@ void sis_reset(sc) CSR_WRITE_4(sc, NS_CLKRUN, NS_CLKRUN_PMESTS); CSR_WRITE_4(sc, NS_CLKRUN, 0); } - - return; } -const struct pci_matchid sis_devices[] = { - { PCI_VENDOR_SIS, PCI_PRODUCT_SIS_900 }, - { PCI_VENDOR_SIS, PCI_PRODUCT_SIS_7016 }, - { PCI_VENDOR_NS, PCI_PRODUCT_NS_DP83815 }, -}; - /* * Probe for an SiS chip. Check the PCI vendor and device * IDs against our list and return a device name if we find a match. */ -int sis_probe(parent, match, aux) - struct device *parent; - void *match; - void *aux; +int +sis_probe(struct device *parent, void *match, void *aux) { return (pci_matchbyid((struct pci_attach_args *)aux, sis_devices, sizeof(sis_devices)/sizeof(sis_devices[0]))); @@ -902,9 +870,8 @@ int sis_probe(parent, match, aux) * Attach the interface. Allocate softc structures, do ifmedia * setup and ethernet/BPF attach. */ -void sis_attach(parent, self, aux) - struct device *parent, *self; - void *aux; +void +sis_attach(struct device *parent, struct device *self, void *aux) { int i; const char *intrstr = NULL; @@ -1158,7 +1125,7 @@ void sis_attach(parent, self, aux) IFQ_SET_READY(&ifp->if_snd); bcopy(sc->sc_dev.dv_xname, ifp->if_xname, IFNAMSIZ); - ifp->if_capabilities |= IFCAP_VLAN_MTU; + ifp->if_capabilities = IFCAP_VLAN_MTU; sc->sc_mii.mii_ifp = ifp; sc->sc_mii.mii_readreg = sis_miibus_readreg; @@ -1194,8 +1161,8 @@ fail_1: * we arrange the descriptors in a closed ring, so that the last descriptor * points back to the first. */ -int sis_ring_init(sc) - struct sis_softc *sc; +int +sis_ring_init(struct sis_softc *sc) { struct sis_list_data *ld; struct sis_ring_data *cd; @@ -1256,10 +1223,8 @@ int sis_ring_init(sc) /* * Initialize an RX descriptor and attach an MBUF cluster. */ -int sis_newbuf(sc, c, m) - struct sis_softc *sc; - struct sis_desc *c; - struct mbuf *m; +int +sis_newbuf(struct sis_softc *sc, struct sis_desc*c, struct mbuf *m) { struct mbuf *m_new = NULL; bus_dmamap_t map; @@ -1314,8 +1279,8 @@ int sis_newbuf(sc, c, m) * A frame has been uploaded: pass the resulting mbuf chain up to * the higher level protocols. */ -void sis_rxeof(sc) - struct sis_softc *sc; +void +sis_rxeof(struct sis_softc *sc) { struct mbuf *m; struct ifnet *ifp; @@ -1397,12 +1362,11 @@ void sis_rxeof(sc) sc->sis_cdata.sis_rx_pdsc = cur_rx; } -void sis_rxeoc(sc) - struct sis_softc *sc; +void +sis_rxeoc(struct sis_softc *sc) { sis_rxeof(sc); sis_init(sc); - return; } /* @@ -1410,8 +1374,8 @@ void sis_rxeoc(sc) * the list buffers. */ -void sis_txeof(sc) - struct sis_softc *sc; +void +sis_txeof(struct sis_softc *sc) { struct ifnet *ifp; u_int32_t idx; @@ -1471,8 +1435,8 @@ void sis_txeof(sc) ifp->if_timer = (sc->sis_cdata.sis_tx_cnt == 0) ? 0 : 5; } -void sis_tick(xsc) - void *xsc; +void +sis_tick(void *xsc) { struct sis_softc *sc = (struct sis_softc *)xsc; struct mii_data *mii; @@ -1495,12 +1459,10 @@ void sis_tick(xsc) timeout_add(&sc->sis_timeout, hz); splx(s); - - return; } -int sis_intr(arg) - void *arg; +int +sis_intr(void *arg) { struct sis_softc *sc; struct ifnet *ifp; @@ -1511,7 +1473,7 @@ int sis_intr(arg) ifp = &sc->arpcom.ac_if; if (sc->sis_stopped) /* Most likely shared interrupt */ - return claimed; + return (claimed); /* Disable interrupts. */ CSR_WRITE_4(sc, SIS_IER, 0); @@ -1553,17 +1515,15 @@ int sis_intr(arg) if (!IFQ_IS_EMPTY(&ifp->if_snd)) sis_start(ifp); - return claimed; + return (claimed); } /* * Encapsulate an mbuf chain in a descriptor by coupling the mbuf data * pointers to the fragment pointers. */ -int sis_encap(sc, m_head, txidx) - struct sis_softc *sc; - struct mbuf *m_head; - u_int32_t *txidx; +int +sis_encap(struct sis_softc *sc, struct mbuf *m_head, u_int32_t *txidx) { struct sis_desc *f = NULL; int frag, cur, i; @@ -1607,7 +1567,7 @@ int sis_encap(sc, m_head, txidx) sizeof(struct sis_desc) * SIS_TX_LIST_CNT, BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE); - return(0); + return (0); } /* @@ -1617,8 +1577,8 @@ int sis_encap(sc, m_head, txidx) * physical addresses. */ -void sis_start(ifp) - struct ifnet *ifp; +void +sis_start(struct ifnet *ifp) { struct sis_softc *sc; struct mbuf *m_head = NULL; @@ -1669,12 +1629,10 @@ void sis_start(ifp) */ ifp->if_timer = 5; } - - return; } -void sis_init(xsc) - void *xsc; +void +sis_init(void *xsc) { struct sis_softc *sc = (struct sis_softc *)xsc; struct ifnet *ifp = &sc->arpcom.ac_if; @@ -1756,20 +1714,18 @@ void sis_init(xsc) } /* If we want promiscuous mode, set the allframes bit. */ - if (ifp->if_flags & IFF_PROMISC) { + if (ifp->if_flags & IFF_PROMISC) SIS_SETBIT(sc, SIS_RXFILT_CTL, SIS_RXFILTCTL_ALLPHYS); - } else { + else SIS_CLRBIT(sc, SIS_RXFILT_CTL, SIS_RXFILTCTL_ALLPHYS); - } /* * Set the capture broadcast bit to capture broadcast frames. */ - if (ifp->if_flags & IFF_BROADCAST) { + if (ifp->if_flags & IFF_BROADCAST) SIS_SETBIT(sc, SIS_RXFILT_CTL, SIS_RXFILTCTL_BROAD); - } else { + else SIS_CLRBIT(sc, SIS_RXFILT_CTL, SIS_RXFILTCTL_BROAD); - } /* * Load the multicast filter. @@ -1791,11 +1747,10 @@ void sis_init(xsc) * the PCI bus. When this bit is set, the Max DMA Burst Size * for TX/RX DMA should be no larger than 16 double words. */ - if (CSR_READ_4(sc, SIS_CFG) & SIS_CFG_EDB_MASTER_EN) { + if (CSR_READ_4(sc, SIS_CFG) & SIS_CFG_EDB_MASTER_EN) CSR_WRITE_4(sc, SIS_RX_CFG, SIS_RXCFG64); - } else { + else CSR_WRITE_4(sc, SIS_RX_CFG, SIS_RXCFG256); - } /* Accept Long Packets for VLAN support */ SIS_SETBIT(sc, SIS_RX_CFG, SIS_RXCFG_RX_JABBER); @@ -1870,15 +1825,13 @@ void sis_init(xsc) timeout_set(&sc->sis_timeout, sis_tick, sc); timeout_add(&sc->sis_timeout, hz); - - return; } /* * Set media options. */ -int sis_ifmedia_upd(ifp) - struct ifnet *ifp; +int +sis_ifmedia_upd(struct ifnet *ifp) { struct sis_softc *sc; struct mii_data *mii; @@ -1894,15 +1847,14 @@ int sis_ifmedia_upd(ifp) } mii_mediachg(mii); - return(0); + return (0); } /* * Report current media status. */ -void sis_ifmedia_sts(ifp, ifmr) - struct ifnet *ifp; - struct ifmediareq *ifmr; +void +sis_ifmedia_sts(struct ifnet *ifp, struct ifmediareq *ifmr) { struct sis_softc *sc; struct mii_data *mii; @@ -1913,14 +1865,10 @@ void sis_ifmedia_sts(ifp, ifmr) mii_pollstat(mii); ifmr->ifm_active = mii->mii_media_active; ifmr->ifm_status = mii->mii_media_status; - - return; } -int sis_ioctl(ifp, command, data) - struct ifnet *ifp; - u_long command; - caddr_t data; +int +sis_ioctl(struct ifnet *ifp, u_long command, caddr_t data) { struct sis_softc *sc = ifp->if_softc; struct ifreq *ifr = (struct ifreq *) data; @@ -2008,17 +1956,16 @@ int sis_ioctl(ifp, command, data) return(error); } -void sis_watchdog(ifp) - struct ifnet *ifp; +void +sis_watchdog(struct ifnet *ifp) { struct sis_softc *sc; int s; sc = ifp->if_softc; - if (sc->sis_stopped) { + if (sc->sis_stopped) return; - } ifp->if_oerrors++; printf("%s: watchdog timeout\n", sc->sc_dev.dv_xname); @@ -2032,15 +1979,14 @@ void sis_watchdog(ifp) sis_start(ifp); splx(s); - return; } /* * Stop the adapter and free any mbufs allocated to the * RX and TX lists. */ -void sis_stop(sc) - struct sis_softc *sc; +void +sis_stop(struct sis_softc *sc) { int i; struct ifnet *ifp; @@ -2109,19 +2055,10 @@ void sis_stop(sc) * Stop all chip I/O so that the kernel's probe routines don't * get confused by errant DMAs when rebooting. */ -void sis_shutdown(v) - void *v; +void +sis_shutdown(void *v) { struct sis_softc *sc = (struct sis_softc *)v; sis_stop(sc); } - -struct cfattach sis_ca = { - sizeof(struct sis_softc), sis_probe, sis_attach -}; - -struct cfdriver sis_cd = { - 0, "sis", DV_IFNET -}; - |