Deleted Added
full compact
4a5,7
> * Modifications to support NetBSD and media selection:
> * Copyright (c) 1997 Jason R. Thorpe. All rights reserved.
> *
27c30
< * $Id: if_fxp.c,v 1.37 1997/07/25 23:41:12 davidg Exp $
---
> * $Id$
38d40
< #include <sys/sockio.h>
45a48
> #include <net/if_media.h>
49d51
< #include <netinet/if_ether.h>
60a63,98
> #if defined(__NetBSD__)
>
> #include <sys/ioctl.h>
> #include <sys/errno.h>
> #include <sys/device.h>
>
> #include <net/if_dl.h>
> #include <net/if_ether.h>
>
> #include <netinet/if_inarp.h>
>
> #include <vm/vm.h>
>
> #include <machine/cpu.h>
> #include <machine/bus.h>
> #include <machine/intr.h>
>
> #include <dev/pci/if_fxpreg.h>
> #include <dev/pci/if_fxpvar.h>
>
> #include <dev/pci/pcivar.h>
> #include <dev/pci/pcireg.h>
> #include <dev/pci/pcidevs.h>
>
> #ifdef __alpha__ /* XXX */
> /* XXX XXX NEED REAL DMA MAPPING SUPPORT XXX XXX */
> #undef vtophys
> #define vtophys(va) alpha_XXX_dmamap((vm_offset_t)(va))
> #endif /* __alpha__ */
>
> #else /* __FreeBSD__ */
>
> #include <sys/sockio.h>
>
> #include <netinet/if_ether.h>
>
66a105
> #include <pci/if_fxpvar.h>
68,82c107
< struct fxp_softc {
< struct arpcom arpcom; /* per-interface network data */
< struct fxp_csr *csr; /* control/status registers */
< struct fxp_cb_tx *cbl_base; /* base of TxCB list */
< struct fxp_cb_tx *cbl_first; /* first active TxCB in list */
< struct fxp_cb_tx *cbl_last; /* last active TxCB in list */
< struct mbuf *rfa_headm; /* first mbuf in receive frame area */
< struct mbuf *rfa_tailm; /* last mbuf in receive frame area */
< struct fxp_stats *fxp_stats; /* Pointer to interface stats */
< int tx_queued; /* # of active TxCB's */
< int promisc_mode; /* promiscuous mode enabled */
< int phy_primary_addr; /* address of primary PHY */
< int phy_primary_device; /* device type of primary PHY */
< int phy_10Mbps_only; /* PHY is 10Mbps-only device */
< };
---
> #endif /* __NetBSD__ */
84c109,118
< static u_long fxp_count;
---
> /*
> * NOTE! On the Alpha, we have an alignment constraint. The
> * card DMAs the packet immediately following the RFA. However,
> * the first thing in the packet is a 14-byte Ethernet header.
> * This means that the packet is misaligned. To compensate,
> * we actually offset the RFA 2 bytes into the cluster. This
> * alignes the packet after the Ethernet header at a 32-bit
> * boundary. HOWEVER! This means that the RFA is misaligned!
> */
> #define RFA_ALIGNMENT_FUDGE 2
86a121,136
> * Inline function to copy a 16-bit aligned 32-bit quantity.
> */
> static __inline void fxp_lwcopy __P((volatile u_int32_t *,
> volatile u_int32_t *));
> static __inline void
> fxp_lwcopy(src, dst)
> volatile u_int32_t *src, *dst;
> {
> volatile u_int16_t *a = (u_int16_t *)src;
> volatile u_int16_t *b = (u_int16_t *)dst;
>
> b[0] = a[0];
> b[1] = a[1];
> }
>
> /*
119,122c169,213
< static inline void fxp_scb_wait __P((struct fxp_csr *));
< static char *fxp_probe __P((pcici_t, pcidi_t));
< static void fxp_attach __P((pcici_t, int));
< static void fxp_intr __P((void *));
---
> /* Supported media types. */
> struct fxp_supported_media {
> const int fsm_phy; /* PHY type */
> const int *fsm_media; /* the media array */
> const int fsm_nmedia; /* the number of supported media */
> const int fsm_defmedia; /* default media for this PHY */
> };
>
> const int fxp_media_standard[] = {
> IFM_ETHER|IFM_10_T,
> IFM_ETHER|IFM_10_T|IFM_FDX,
> IFM_ETHER|IFM_100_TX,
> IFM_ETHER|IFM_100_TX|IFM_FDX,
> IFM_ETHER|IFM_AUTO,
> };
> #define FXP_MEDIA_STANDARD_DEFMEDIA (IFM_ETHER|IFM_AUTO)
>
> const int fxp_media_default[] = {
> IFM_ETHER|IFM_MANUAL, /* XXX IFM_AUTO ? */
> };
> #define FXP_MEDIA_DEFAULT_DEFMEDIA (IFM_ETHER|IFM_MANUAL)
>
> const struct fxp_supported_media fxp_media[] = {
> { FXP_PHY_DP83840, fxp_media_standard,
> sizeof(fxp_media_standard) / sizeof(fxp_media_standard[0]),
> FXP_MEDIA_STANDARD_DEFMEDIA },
> { FXP_PHY_DP83840A, fxp_media_standard,
> sizeof(fxp_media_standard) / sizeof(fxp_media_standard[0]),
> FXP_MEDIA_STANDARD_DEFMEDIA },
> { FXP_PHY_82555, fxp_media_standard,
> sizeof(fxp_media_standard) / sizeof(fxp_media_standard[0]),
> FXP_MEDIA_STANDARD_DEFMEDIA },
> { FXP_PHY_80C24, fxp_media_default,
> sizeof(fxp_media_default) / sizeof(fxp_media_default[0]),
> FXP_MEDIA_DEFAULT_DEFMEDIA },
> };
> #define NFXPMEDIA (sizeof(fxp_media) / sizeof(fxp_media[0]))
>
> static int fxp_mediachange __P((struct ifnet *));
> static void fxp_mediastatus __P((struct ifnet *, struct ifmediareq *));
>
> void fxp_set_media __P((struct fxp_softc *, int));
>
> static inline void fxp_scb_wait __P((struct fxp_softc *));
> static FXP_INTR_TYPE fxp_intr __P((void *));
124c215,216
< static int fxp_ioctl __P((struct ifnet *, int, caddr_t));
---
> static int fxp_ioctl __P((struct ifnet *,
> FXP_IOCTLCMD_TYPE, caddr_t));
129,132c221,225
< static void fxp_shutdown __P((int, void *));
< static int fxp_mdi_read __P((struct fxp_csr *, int, int));
< static void fxp_mdi_write __P((struct fxp_csr *, int, int, int));
< static void fxp_read_eeprom __P((struct fxp_csr *, u_short *, int, int));
---
> static int fxp_mdi_read __P((struct fxp_softc *, int, int));
> static void fxp_mdi_write __P((struct fxp_softc *, int, int, int));
> static void fxp_read_eeprom __P((struct fxp_softc *, u_int16_t *,
> int, int));
> static int fxp_attach_common __P((struct fxp_softc *, u_int8_t *));
133a227
> void fxp_stats_update __P((void *));
135,145d228
< timeout_t fxp_stats_update;
<
< static struct pci_device fxp_device = {
< "fxp",
< fxp_probe,
< fxp_attach,
< &fxp_count,
< NULL
< };
< DATA_SET(pcidevice_set, fxp_device);
<
187,188c270,271
< fxp_scb_wait(csr)
< struct fxp_csr *csr;
---
> fxp_scb_wait(sc)
> struct fxp_softc *sc;
192c275,276
< while ((csr->scb_command & FXP_SCB_COMMAND_MASK) && --i);
---
> while ((CSR_READ_1(sc, FXP_CSR_SCB_COMMAND) & FXP_SCB_COMMAND_MASK)
> && --i);
194a279,306
> /*************************************************************
> * Operating system-specific autoconfiguration glue
> *************************************************************/
>
> #if defined(__NetBSD__)
>
> #ifdef __BROKEN_INDIRECT_CONFIG
> static int fxp_match __P((struct device *, void *, void *));
> #else
> static int fxp_match __P((struct device *, struct cfdata *, void *));
> #endif
> static void fxp_attach __P((struct device *, struct device *, void *));
>
> static void fxp_shutdown __P((void *));
>
> /* Compensate for lack of a generic ether_ioctl() */
> static int fxp_ether_ioctl __P((struct ifnet *,
> FXP_IOCTLCMD_TYPE, caddr_t));
> #define ether_ioctl fxp_ether_ioctl
>
> struct cfattach fxp_ca = {
> sizeof(struct fxp_softc), fxp_match, fxp_attach
> };
>
> struct cfdriver fxp_cd = {
> NULL, "fxp", DV_IFNET
> };
>
195a308,489
> * Check if a device is an 82557.
> */
> static int
> fxp_match(parent, match, aux)
> struct device *parent;
> #ifdef __BROKEN_INDIRECT_CONFIG
> void *match;
> #else
> struct cfdata *match;
> #endif
> void *aux;
> {
> struct pci_attach_args *pa = aux;
>
> if (PCI_VENDOR(pa->pa_id) != PCI_VENDOR_INTEL)
> return (0);
>
> switch (PCI_PRODUCT(pa->pa_id)) {
> case PCI_PRODUCT_INTEL_82557:
> return (1);
> }
>
> return (0);
> }
>
> static void
> fxp_attach(parent, self, aux)
> struct device *parent, *self;
> void *aux;
> {
> struct fxp_softc *sc = (struct fxp_softc *)self;
> struct pci_attach_args *pa = aux;
> pci_chipset_tag_t pc = pa->pa_pc;
> pci_intr_handle_t ih;
> const char *intrstr = NULL;
> u_int8_t enaddr[6];
> struct ifnet *ifp;
>
> /*
> * Map control/status registers.
> */
> if (pci_mapreg_map(pa, FXP_PCI_MMBA, PCI_MAPREG_TYPE_MEM, 0,
> &sc->sc_st, &sc->sc_sh, NULL, NULL)) {
> printf(": can't map registers\n");
> return;
> }
> printf(": Intel EtherExpress Pro 10/100B Ethernet\n");
>
> /*
> * Allocate our interrupt.
> */
> if (pci_intr_map(pc, pa->pa_intrtag, pa->pa_intrpin,
> pa->pa_intrline, &ih)) {
> printf("%s: couldn't map interrupt\n", sc->sc_dev.dv_xname);
> return;
> }
> intrstr = pci_intr_string(pc, ih);
> sc->sc_ih = pci_intr_establish(pc, ih, IPL_NET, fxp_intr, sc);
> if (sc->sc_ih == NULL) {
> printf("%s: couldn't establish interrupt",
> sc->sc_dev.dv_xname);
> if (intrstr != NULL)
> printf(" at %s", intrstr);
> printf("\n");
> return;
> }
> printf("%s: interrupting at %s\n", sc->sc_dev.dv_xname, intrstr);
>
> /* Do generic parts of attach. */
> if (fxp_attach_common(sc, enaddr)) {
> /* Failed! */
> return;
> }
>
> printf("%s: Ethernet address %s%s\n", sc->sc_dev.dv_xname,
> ether_sprintf(enaddr), sc->phy_10Mbps_only ? ", 10Mbps" : "");
>
> ifp = &sc->sc_ethercom.ec_if;
> bcopy(sc->sc_dev.dv_xname, ifp->if_xname, IFNAMSIZ);
> ifp->if_softc = sc;
> ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
> ifp->if_ioctl = fxp_ioctl;
> ifp->if_start = fxp_start;
> ifp->if_watchdog = fxp_watchdog;
>
> /*
> * Attach the interface.
> */
> if_attach(ifp);
> ether_ifattach(ifp, enaddr);
> #if NBPFILTER > 0
> bpfattach(&sc->sc_ethercom.ec_if.if_bpf, ifp, DLT_EN10MB,
> sizeof(struct ether_header));
> #endif
>
> /*
> * Add shutdown hook so that DMA is disabled prior to reboot. Not
> * doing do could allow DMA to corrupt kernel memory during the
> * reboot before the driver initializes.
> */
> shutdownhook_establish(fxp_shutdown, sc);
> }
>
> /*
> * Device shutdown routine. Called at system shutdown after sync. The
> * main purpose of this routine is to shut off receiver DMA so that
> * kernel memory doesn't get clobbered during warmboot.
> */
> static void
> fxp_shutdown(sc)
> void *sc;
> {
> fxp_stop((struct fxp_softc *) sc);
> }
>
> static int
> fxp_ether_ioctl(ifp, cmd, data)
> struct ifnet *ifp;
> FXP_IOCTLCMD_TYPE cmd;
> caddr_t data;
> {
> struct ifaddr *ifa = (struct ifaddr *) data;
> struct fxp_softc *sc = ifp->if_softc;
>
> switch (cmd) {
> case SIOCSIFADDR:
> ifp->if_flags |= IFF_UP;
>
> switch (ifa->ifa_addr->sa_family) {
> #ifdef INET
> case AF_INET:
> fxp_init(sc);
> arp_ifinit(ifp, ifa);
> break;
> #endif
> #ifdef NS
> case AF_NS:
> {
> register struct ns_addr *ina = &IA_SNS(ifa)->sns_addr;
>
> if (ns_nullhost(*ina))
> ina->x_host = *(union ns_host *)
> LLADDR(ifp->if_sadl);
> else
> bcopy(ina->x_host.c_host, LLADDR(ifp->if_sadl),
> ifp->if_addrlen);
> /* Set new address. */
> fxp_init(sc);
> break;
> }
> #endif
> default:
> fxp_init(sc);
> break;
> }
> break;
>
> default:
> return (EINVAL);
> }
>
> return (0);
> }
>
> #else /* __FreeBSD__ */
>
> static u_long fxp_count;
> static char *fxp_probe __P((pcici_t, pcidi_t));
> static void fxp_attach __P((pcici_t, int));
>
> static void fxp_shutdown __P((int, void *));
>
> static struct pci_device fxp_device = {
> "fxp",
> fxp_probe,
> fxp_attach,
> &fxp_count,
> NULL
> };
> DATA_SET(pcidevice_set, fxp_device);
>
> /*
210,212d503
< /*
< * Allocate data structures and attach the device.
< */
219d509
< struct ifnet *ifp;
221,222c511,512
< int s, i;
< u_short data;
---
> struct ifnet *ifp;
> int s;
241,246d530
< * Reset to a stable state.
< */
< sc->csr->port = FXP_PORT_SELECTIVE_RESET;
< DELAY(10);
<
< /*
253a538,620
> /* Do generic parts of attach. */
> if (fxp_attach_common(sc, sc->arpcom.ac_enaddr)) {
> /* Failed! */
> (void) pci_unmap_int(config_id);
> goto fail;
> }
>
> printf("fxp%d: Ethernet address %6D%s\n", unit,
> sc->arpcom.ac_enaddr, ":", sc->phy_10Mbps_only ? ", 10Mbps" : "");
>
> ifp = &sc->arpcom.ac_if;
> ifp->if_unit = unit;
> ifp->if_name = "fxp";
> ifp->if_output = ether_output;
> ifp->if_baudrate = 100000000;
> ifp->if_init = fxp_init;
> ifp->if_softc = sc;
> ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
> ifp->if_ioctl = fxp_ioctl;
> ifp->if_start = fxp_start;
> ifp->if_watchdog = fxp_watchdog;
>
> /*
> * Attach the interface.
> */
> if_attach(ifp);
> ether_ifattach(ifp);
> #if NBPFILTER > 0
> bpfattach(ifp, DLT_EN10MB, sizeof(struct ether_header));
> #endif
>
> /*
> * Add shutdown hook so that DMA is disabled prior to reboot. Not
> * doing do could allow DMA to corrupt kernel memory during the
> * reboot before the driver initializes.
> */
> at_shutdown(fxp_shutdown, sc, SHUTDOWN_POST_SYNC);
>
> splx(s);
> return;
>
> fail:
> free(sc, M_DEVBUF);
> splx(s);
> }
>
> /*
> * Device shutdown routine. Called at system shutdown after sync. The
> * main purpose of this routine is to shut off receiver DMA so that
> * kernel memory doesn't get clobbered during warmboot.
> */
> static void
> fxp_shutdown(howto, sc)
> int howto;
> void *sc;
> {
> fxp_stop((struct fxp_softc *) sc);
> }
>
> #endif /* __NetBSD__ */
>
> /*************************************************************
> * End of operating system-specific autoconfiguration glue
> *************************************************************/
>
> /*
> * Do generic parts of attach.
> */
> static int
> fxp_attach_common(sc, enaddr)
> struct fxp_softc *sc;
> u_int8_t *enaddr;
> {
> u_int16_t data;
> int i, nmedia, defmedia;
> const int *media;
>
> /*
> * Reset to a stable state.
> */
> CSR_WRITE_4(sc, FXP_CSR_PORT, FXP_PORT_SELECTIVE_RESET);
> DELAY(10);
>
257c624
< goto malloc_fail;
---
> goto fail;
261c628
< goto malloc_fail;
---
> goto fail;
269c636
< goto malloc_fail;
---
> goto fail;
276c643
< fxp_read_eeprom(sc->csr, (u_short *)&data, 6, 1);
---
> fxp_read_eeprom(sc, (u_int16_t *)&data, 6, 1);
281,292d647
< ifp = &sc->arpcom.ac_if;
< ifp->if_softc = sc;
< ifp->if_unit = unit;
< ifp->if_name = "fxp";
< ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
< ifp->if_ioctl = fxp_ioctl;
< ifp->if_output = ether_output;
< ifp->if_start = fxp_start;
< ifp->if_watchdog = fxp_watchdog;
< ifp->if_baudrate = 100000000;
< ifp->if_init = fxp_init;
<
294c649
< * Read MAC address
---
> * Read MAC address.
296,300c651
< fxp_read_eeprom(sc->csr, (u_short *)sc->arpcom.ac_enaddr, 0, 3);
< printf("fxp%d: Ethernet address %6D", unit, sc->arpcom.ac_enaddr, ":");
< if (sc->phy_10Mbps_only)
< printf(", 10Mbps");
< printf("\n");
---
> fxp_read_eeprom(sc, (u_int16_t *)enaddr, 0, 3);
303c654
< * Attach the interface.
---
> * Initialize the media structures.
305,306d655
< if_attach(ifp);
< ether_ifattach(ifp);
308,310c657,659
< #if NBPFILTER > 0
< bpfattach(ifp, DLT_EN10MB, sizeof(struct ether_header));
< #endif
---
> media = fxp_media_default;
> nmedia = sizeof(fxp_media_default) / sizeof(fxp_media_default[0]);
> defmedia = FXP_MEDIA_DEFAULT_DEFMEDIA;
312,317c661,667
< /*
< * Add shutdown hook so that DMA is disabled prior to reboot. Not
< * doing do could allow DMA to corrupt kernel memory during the
< * reboot before the driver initializes.
< */
< at_shutdown(fxp_shutdown, sc, SHUTDOWN_POST_SYNC);
---
> for (i = 0; i < NFXPMEDIA; i++) {
> if (sc->phy_primary_device == fxp_media[i].fsm_phy) {
> media = fxp_media[i].fsm_media;
> nmedia = fxp_media[i].fsm_nmedia;
> defmedia = fxp_media[i].fsm_defmedia;
> }
> }
319,320c669,675
< splx(s);
< return;
---
> ifmedia_init(&sc->sc_media, 0, fxp_mediachange, fxp_mediastatus);
> for (i = 0; i < nmedia; i++) {
> if (IFM_SUBTYPE(media[i]) == IFM_100_TX && sc->phy_10Mbps_only)
> continue;
> ifmedia_add(&sc->sc_media, media[i], 0, NULL);
> }
> ifmedia_set(&sc->sc_media, defmedia);
322,325c677,681
< malloc_fail:
< printf("fxp%d: Failed to malloc memory\n", unit);
< (void) pci_unmap_int(config_id);
< if (sc && sc->cbl_base)
---
> return (0);
>
> fail:
> printf(FXP_FORMAT ": Failed to malloc memory\n", FXP_ARGS(sc));
> if (sc->cbl_base)
327c683
< if (sc && sc->fxp_stats)
---
> if (sc->fxp_stats)
330c686
< if (sc && sc->rfa_headm)
---
> if (sc->rfa_headm)
332,335c688,689
< fail:
< if (sc)
< free(sc, M_DEVBUF);
< splx(s);
---
>
> return (ENOMEM);
346,347c700,701
< fxp_read_eeprom(csr, data, offset, words)
< struct fxp_csr *csr;
---
> fxp_read_eeprom(sc, data, offset, words)
> struct fxp_softc *sc;
352c706
< u_short reg;
---
> u_int16_t reg;
356c710
< csr->eeprom_control = FXP_EEPROM_EECS;
---
> CSR_WRITE_2(sc, FXP_CSR_EEPROMCONTROL, FXP_EEPROM_EECS);
366,367c720,722
< csr->eeprom_control = reg;
< csr->eeprom_control = reg | FXP_EEPROM_EESK;
---
> CSR_WRITE_2(sc, FXP_CSR_EEPROMCONTROL, reg);
> CSR_WRITE_2(sc, FXP_CSR_EEPROMCONTROL,
> reg | FXP_EEPROM_EESK);
369c724
< csr->eeprom_control = reg;
---
> CSR_WRITE_2(sc, FXP_CSR_EEPROMCONTROL, reg);
381,382c736,738
< csr->eeprom_control = reg;
< csr->eeprom_control = reg | FXP_EEPROM_EESK;
---
> CSR_WRITE_2(sc, FXP_CSR_EEPROMCONTROL, reg);
> CSR_WRITE_2(sc, FXP_CSR_EEPROMCONTROL,
> reg | FXP_EEPROM_EESK);
384c740
< csr->eeprom_control = reg;
---
> CSR_WRITE_2(sc, FXP_CSR_EEPROMCONTROL, reg);
393c749,750
< csr->eeprom_control = reg | FXP_EEPROM_EESK;
---
> CSR_WRITE_2(sc, FXP_CSR_EEPROMCONTROL,
> reg | FXP_EEPROM_EESK);
395c752,753
< if (csr->eeprom_control & FXP_EEPROM_EEDO)
---
> if (CSR_READ_2(sc, FXP_CSR_EEPROMCONTROL) &
> FXP_EEPROM_EEDO)
397c755
< csr->eeprom_control = reg;
---
> CSR_WRITE_2(sc, FXP_CSR_EEPROMCONTROL, reg);
400c758
< csr->eeprom_control = 0;
---
> CSR_WRITE_2(sc, FXP_CSR_EEPROMCONTROL, 0);
406,418d763
< * Device shutdown routine. Called at system shutdown after sync. The
< * main purpose of this routine is to shut off receiver DMA so that
< * kernel memory doesn't get clobbered during warmboot.
< */
< static void
< fxp_shutdown(howto, sc)
< int howto;
< void *sc;
< {
< fxp_stop((struct fxp_softc *) sc);
< }
<
< /*
426d770
< struct fxp_csr *csr = sc->csr;
490c834,835
< m_copydata(mb_head, 0, mb_head->m_pkthdr.len, mtod(mn, caddr_t));
---
> m_copydata(mb_head, 0, mb_head->m_pkthdr.len,
> mtod(mn, caddr_t));
529c874
< fxp_scb_wait(csr);
---
> fxp_scb_wait(sc);
535c880
< csr->scb_command = FXP_SCB_COMMAND_CU_RESUME;
---
> CSR_WRITE_1(sc, FXP_CSR_SCB_COMMAND, FXP_SCB_COMMAND_CU_RESUME);
542c887
< bpf_mtap(ifp, mb_head);
---
> bpf_mtap(FXP_BPFTAP_ARG(ifp), mb_head);
556c901
< static void
---
> static FXP_INTR_TYPE
561,562c906
< struct fxp_csr *csr = sc->csr;
< struct ifnet *ifp = &sc->arpcom.ac_if;
---
> struct ifnet *ifp = &sc->sc_if;
563a908,910
> #if defined(__NetBSD__)
> int claimed = 0;
> #endif
565c912,915
< while ((statack = csr->scb_statack) != 0) {
---
> while ((statack = CSR_READ_1(sc, FXP_CSR_SCB_STATACK)) != 0) {
> #if defined(__NetBSD__)
> claimed = 1;
> #endif
569c919
< csr->scb_statack = statack;
---
> CSR_WRITE_1(sc, FXP_CSR_SCB_STATACK, statack);
606c956,957
< rfa = (struct fxp_rfa *)m->m_ext.ext_buf;
---
> rfa = (struct fxp_rfa *)(m->m_ext.ext_buf +
> RFA_ALIGNMENT_FUDGE);
616,617c967,969
< * Add a new buffer to the receive chain. If this
< * fails, the old buffer is recycled instead.
---
> * Add a new buffer to the receive chain.
> * If this fails, the old buffer is recycled
> * instead.
621c973
< u_short total_len;
---
> u_int16_t total_len;
623,624c975,978
< total_len = rfa->actual_size & (MCLBYTES - 1);
< if (total_len < sizeof(struct ether_header)) {
---
> total_len = rfa->actual_size &
> (MCLBYTES - 1);
> if (total_len <
> sizeof(struct ether_header)) {
629c983,984
< m->m_pkthdr.len = m->m_len = total_len -
---
> m->m_pkthdr.len = m->m_len =
> total_len -
634c989,991
< bpf_tap(ifp, mtod(m, caddr_t), total_len);
---
> bpf_tap(FXP_BPFTAP_ARG(ifp),
> mtod(m, caddr_t),
> total_len);
636c993,994
< * Only pass this packet up if it is for us.
---
> * Only pass this packet up
> * if it is for us.
638,640c996,1001
< if ((ifp->if_flags & IFF_PROMISC) &&
< (rfa->rfa_status & FXP_RFA_STATUS_IAMATCH) &&
< (eh->ether_dhost[0] & 1) == 0) {
---
> if ((ifp->if_flags &
> IFF_PROMISC) &&
> (rfa->rfa_status &
> FXP_RFA_STATUS_IAMATCH) &&
> (eh->ether_dhost[0] & 1)
> == 0) {
645,646c1006,1008
< #endif
< m->m_data += sizeof(struct ether_header);
---
> #endif /* NBPFILTER > 0 */
> m->m_data +=
> sizeof(struct ether_header);
652,654c1014,1019
< fxp_scb_wait(csr);
< csr->scb_general = vtophys(sc->rfa_headm->m_ext.ext_buf);
< csr->scb_command = FXP_SCB_COMMAND_RU_START;
---
> fxp_scb_wait(sc);
> CSR_WRITE_4(sc, FXP_CSR_SCB_GENERAL,
> vtophys(sc->rfa_headm->m_ext.ext_buf) +
> RFA_ALIGNMENT_FUDGE);
> CSR_WRITE_1(sc, FXP_CSR_SCB_COMMAND,
> FXP_SCB_COMMAND_RU_START);
657a1023,1025
> #if defined(__NetBSD__)
> return (claimed);
> #endif
676c1044
< struct ifnet *ifp = &sc->arpcom.ac_if;
---
> struct ifnet *ifp = &sc->sc_if;
700c1068,1069
< if ((sc->csr->scb_command & FXP_SCB_COMMAND_MASK) == 0) {
---
> if ((CSR_READ_1(sc, FXP_CSR_SCB_COMMAND) &
> FXP_SCB_COMMAND_MASK) == 0) {
706,707c1075,1077
< sc->csr->scb_command = FXP_SCB_COMMAND_CU_DUMPRESET;
< fxp_scb_wait(sc->csr);
---
> CSR_WRITE_1(sc, FXP_CSR_SCB_COMMAND,
> FXP_SCB_COMMAND_CU_DUMPRESET);
> fxp_scb_wait(sc);
738c1108
< struct ifnet *ifp = &sc->arpcom.ac_if;
---
> struct ifnet *ifp = &sc->sc_if;
750c1120
< sc->csr->port = FXP_PORT_SELECTIVE_RESET;
---
> CSR_WRITE_4(sc, FXP_CSR_PORT, FXP_PORT_SELECTIVE_RESET);
795c1165,1167
< log(LOG_ERR, "fxp%d: device timeout\n", ifp->if_unit);
---
> struct fxp_softc *sc = ifp->if_softc;
>
> log(LOG_ERR, FXP_FORMAT ": device timeout\n", FXP_ARGS(sc));
798c1170
< fxp_init(ifp->if_softc);
---
> fxp_init(sc);
806c1178
< struct ifnet *ifp = &sc->arpcom.ac_if;
---
> struct ifnet *ifp = &sc->sc_if;
810d1181
< struct fxp_csr *csr = sc->csr;
832,833c1203,1204
< csr->scb_general = 0;
< csr->scb_command = FXP_SCB_COMMAND_CU_BASE;
---
> CSR_WRITE_4(sc, FXP_CSR_SCB_GENERAL, 0);
> CSR_WRITE_1(sc, FXP_CSR_SCB_COMMAND, FXP_SCB_COMMAND_CU_BASE);
835,836c1206,1207
< fxp_scb_wait(csr);
< csr->scb_command = FXP_SCB_COMMAND_RU_BASE;
---
> fxp_scb_wait(sc);
> CSR_WRITE_1(sc, FXP_CSR_SCB_COMMAND, FXP_SCB_COMMAND_RU_BASE);
841,843c1212,1214
< fxp_scb_wait(csr);
< csr->scb_general = vtophys(sc->fxp_stats);
< csr->scb_command = FXP_SCB_COMMAND_CU_DUMP_ADR;
---
> fxp_scb_wait(sc);
> CSR_WRITE_4(sc, FXP_CSR_SCB_GENERAL, vtophys(sc->fxp_stats));
> CSR_WRITE_1(sc, FXP_CSR_SCB_COMMAND, FXP_SCB_COMMAND_CU_DUMP_ADR);
896,898c1267,1269
< fxp_scb_wait(csr);
< csr->scb_general = vtophys(cbp);
< csr->scb_command = FXP_SCB_COMMAND_CU_START;
---
> fxp_scb_wait(sc);
> CSR_WRITE_4(sc, FXP_CSR_SCB_GENERAL, vtophys(cbp));
> CSR_WRITE_1(sc, FXP_CSR_SCB_COMMAND, FXP_SCB_COMMAND_CU_START);
909a1281,1283
> #if defined(__NetBSD__)
> bcopy(LLADDR(ifp->if_sadl), (void *)cb_ias->macaddr, 6);
> #else
911a1286
> #endif /* __NetBSD__ */
916,917c1291,1292
< fxp_scb_wait(csr);
< csr->scb_command = FXP_SCB_COMMAND_CU_START;
---
> fxp_scb_wait(sc);
> CSR_WRITE_1(sc, FXP_CSR_SCB_COMMAND, FXP_SCB_COMMAND_CU_START);
942,943c1317,1318
< fxp_scb_wait(csr);
< csr->scb_command = FXP_SCB_COMMAND_CU_START;
---
> fxp_scb_wait(sc);
> CSR_WRITE_1(sc, FXP_CSR_SCB_COMMAND, FXP_SCB_COMMAND_CU_START);
948,950c1323,1326
< fxp_scb_wait(csr);
< csr->scb_general = vtophys(sc->rfa_headm->m_ext.ext_buf);
< csr->scb_command = FXP_SCB_COMMAND_RU_START;
---
> fxp_scb_wait(sc);
> CSR_WRITE_4(sc, FXP_CSR_SCB_GENERAL,
> vtophys(sc->rfa_headm->m_ext.ext_buf) + RFA_ALIGNMENT_FUDGE);
> CSR_WRITE_1(sc, FXP_CSR_SCB_COMMAND, FXP_SCB_COMMAND_RU_START);
953c1329
< * Toggle a few bits in the PHY.
---
> * Set current media.
954a1331,1348
> fxp_set_media(sc, sc->sc_media.ifm_cur->ifm_media);
>
> ifp->if_flags |= IFF_RUNNING;
> ifp->if_flags &= ~IFF_OACTIVE;
> splx(s);
>
> /*
> * Start stats updater.
> */
> timeout(fxp_stats_update, sc, hz);
> }
>
> void
> fxp_set_media(sc, media)
> struct fxp_softc *sc;
> int media;
> {
>
958,959c1352,1353
< fxp_mdi_write(sc->csr, sc->phy_primary_addr, FXP_DP83840_PCR,
< fxp_mdi_read(sc->csr, sc->phy_primary_addr, FXP_DP83840_PCR) |
---
> fxp_mdi_write(sc, sc->phy_primary_addr, FXP_DP83840_PCR,
> fxp_mdi_read(sc, sc->phy_primary_addr, FXP_DP83840_PCR) |
965,972c1359
< /*
< * If link0 is set, disable auto-negotiation and then:
< * If link1 is unset = 10Mbps
< * If link1 is set = 100Mbps
< * If link2 is unset = half duplex
< * If link2 is set = full duplex
< */
< if (ifp->if_flags & IFF_LINK0) {
---
> if (IFM_SUBTYPE(media) != IFM_AUTO) {
975,980c1362,1369
< flags = (ifp->if_flags & IFF_LINK1) ?
< FXP_PHY_BMCR_SPEED_100M : 0;
< flags |= (ifp->if_flags & IFF_LINK2) ?
< FXP_PHY_BMCR_FULLDUPLEX : 0;
< fxp_mdi_write(sc->csr, sc->phy_primary_addr, FXP_PHY_BMCR,
< (fxp_mdi_read(sc->csr, sc->phy_primary_addr, FXP_PHY_BMCR) &
---
> flags = (IFM_SUBTYPE(media) == IFM_100_TX) ?
> FXP_PHY_BMCR_SPEED_100M : 0;
> flags |= (media & IFM_FDX) ?
> FXP_PHY_BMCR_FULLDUPLEX : 0;
> fxp_mdi_write(sc, sc->phy_primary_addr,
> FXP_PHY_BMCR,
> (fxp_mdi_read(sc, sc->phy_primary_addr,
> FXP_PHY_BMCR) &
984,986c1373,1376
< fxp_mdi_write(sc->csr, sc->phy_primary_addr, FXP_PHY_BMCR,
< (fxp_mdi_read(sc->csr, sc->phy_primary_addr, FXP_PHY_BMCR) |
< FXP_PHY_BMCR_AUTOEN));
---
> fxp_mdi_write(sc, sc->phy_primary_addr,
> FXP_PHY_BMCR,
> (fxp_mdi_read(sc, sc->phy_primary_addr,
> FXP_PHY_BMCR) | FXP_PHY_BMCR_AUTOEN));
996,997c1386,1389
< printf("fxp%d: warning: unsupported PHY, type = %d, addr = %d\n",
< ifp->if_unit, sc->phy_primary_device, sc->phy_primary_addr);
---
> printf(FXP_FORMAT
> ": warning: unsupported PHY, type = %d, addr = %d\n",
> FXP_ARGS(sc), sc->phy_primary_device,
> sc->phy_primary_addr);
998a1391
> }
1000,1002c1393,1401
< ifp->if_flags |= IFF_RUNNING;
< ifp->if_flags &= ~IFF_OACTIVE;
< splx(s);
---
> /*
> * Change media according to request.
> */
> int
> fxp_mediachange(ifp)
> struct ifnet *ifp;
> {
> struct fxp_softc *sc = ifp->if_softc;
> struct ifmedia *ifm = &sc->sc_media;
1004,1007c1403,1407
< /*
< * Start stats updater.
< */
< timeout(fxp_stats_update, sc, hz);
---
> if (IFM_TYPE(ifm->ifm_media) != IFM_ETHER)
> return (EINVAL);
>
> fxp_set_media(sc, ifm->ifm_media);
> return (0);
1010a1411,1446
> * Notify the world which media we're using.
> */
> void
> fxp_mediastatus(ifp, ifmr)
> struct ifnet *ifp;
> struct ifmediareq *ifmr;
> {
> struct fxp_softc *sc = ifp->if_softc;
> int flags;
>
> switch (sc->phy_primary_device) {
> case FXP_PHY_DP83840:
> case FXP_PHY_DP83840A:
> case FXP_PHY_82555:
> flags = fxp_mdi_read(sc, sc->phy_primary_addr, FXP_PHY_BMCR);
> ifmr->ifm_active = IFM_ETHER;
> if (flags & FXP_PHY_BMCR_AUTOEN)
> ifmr->ifm_active |= IFM_AUTO;
> else {
> if (flags & FXP_PHY_BMCR_SPEED_100M)
> ifmr->ifm_active |= IFM_100_TX;
> else
> ifmr->ifm_active |= IFM_10_T;
>
> if (flags & FXP_PHY_BMCR_FULLDUPLEX)
> ifmr->ifm_active |= IFM_FDX;
> }
> break;
>
> case FXP_PHY_80C24:
> default:
> ifmr->ifm_active = IFM_ETHER|IFM_MANUAL; /* XXX IFM_AUTO ? */
> }
> }
>
> /*
1022a1459
> u_int32_t v;
1041a1479
>
1042a1481,1486
> * Move the data pointer up so that the incoming data packet
> * will be 32-bit aligned.
> */
> m->m_data += RFA_ALIGNMENT_FUDGE;
>
> /*
1048c1492
< rfa->size = MCLBYTES - sizeof(struct fxp_rfa);
---
> rfa->size = MCLBYTES - sizeof(struct fxp_rfa) - RFA_ALIGNMENT_FUDGE;
1049a1494,1498
> /*
> * Initialize the rest of the RFA. Note that since the RFA
> * is misaligned, we cannot store values directly. Instead,
> * we use an optimized, inline copy.
> */
1052,1053d1500
< rfa->link_addr = -1;
< rfa->rbd_addr = -1;
1054a1502,1506
>
> v = -1;
> fxp_lwcopy(&v, &rfa->link_addr);
> fxp_lwcopy(&v, &rfa->rbd_addr);
>
1060c1512,1513
< p_rfa = (struct fxp_rfa *) sc->rfa_tailm->m_ext.ext_buf;
---
> p_rfa = (struct fxp_rfa *) (sc->rfa_tailm->m_ext.ext_buf +
> RFA_ALIGNMENT_FUDGE);
1062c1515,1516
< p_rfa->link_addr = vtophys(rfa);
---
> v = vtophys(rfa);
> fxp_lwcopy(&v, &p_rfa->link_addr);
1073,1074c1527,1528
< fxp_mdi_read(csr, phy, reg)
< struct fxp_csr *csr;
---
> fxp_mdi_read(sc, phy, reg)
> struct fxp_softc *sc;
1081c1535,1536
< csr->mdi_control = (FXP_MDI_READ << 26) | (reg << 16) | (phy << 21);
---
> CSR_WRITE_4(sc, FXP_CSR_MDICONTROL,
> (FXP_MDI_READ << 26) | (reg << 16) | (phy << 21));
1083c1538,1539
< while (((value = csr->mdi_control) & 0x10000000) == 0 && count--)
---
> while (((value = CSR_READ_4(sc, FXP_CSR_MDICONTROL)) & 0x10000000) == 0
> && count--)
1087c1543,1544
< printf("fxp_mdi_read: timed out\n");
---
> printf(FXP_FORMAT ": fxp_mdi_read: timed out\n",
> FXP_ARGS(sc));
1093,1094c1550,1551
< fxp_mdi_write(csr, phy, reg, value)
< struct fxp_csr *csr;
---
> fxp_mdi_write(sc, phy, reg, value)
> struct fxp_softc *sc;
1101,1102c1558,1560
< csr->mdi_control = (FXP_MDI_WRITE << 26) | (reg << 16) | (phy << 21)
< | (value & 0xffff);
---
> CSR_WRITE_4(sc, FXP_CSR_MDICONTROL,
> (FXP_MDI_WRITE << 26) | (reg << 16) | (phy << 21) |
> (value & 0xffff));
1104c1562,1563
< while ((csr->mdi_control & 0x10000000) == 0 && count--)
---
> while((CSR_READ_4(sc, FXP_CSR_MDICONTROL) & 0x10000000) == 0 &&
> count--)
1108c1567,1568
< printf("fxp_mdi_write: timed out\n");
---
> printf(FXP_FORMAT ": fxp_mdi_write: timed out\n",
> FXP_ARGS(sc));
1114c1574
< int command;
---
> FXP_IOCTLCMD_TYPE command;
1117d1576
< struct ifaddr *ifa = (struct ifaddr *) data;
1119c1578
< struct ifreq *ifr = (struct ifreq *) data;
---
> struct ifreq *ifr = (struct ifreq *)data;
1126a1586
> #if !defined(__NetBSD__)
1128a1589
> #endif
1149a1611,1628
> #if defined(__NetBSD__)
> {
> struct ifreq *ifr = (struct ifreq *) data;
>
> error = (command == SIOCADDMULTI) ?
> ether_addmulti(ifr, &sc->sc_ethercom) :
> ether_delmulti(ifr, &sc->sc_ethercom);
>
> if (error == ENETRESET) {
> /*
> * Multicast list has changed; set the hardware
> * filter accordingly.
> */
> fxp_init(sc);
> error = 0;
> }
> }
> #else /* __FreeBSD__ */
1155a1635
> #endif /* __NetBSD__ */
1157a1638,1642
> case SIOCSIFMEDIA:
> case SIOCGIFMEDIA:
> error = ifmedia_ioctl(ifp, ifr, &sc->sc_media, command);
> break;
>