Deleted Added
full compact
if_fxp.c (44907) if_fxp.c (45720)
1/*
2 * Copyright (c) 1995, David Greenman
3 * All rights reserved.
4 *
5 * Modifications to support NetBSD and media selection:
6 * Copyright (c) 1997 Jason R. Thorpe. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 13 unchanged lines hidden (view full) ---

22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 * SUCH DAMAGE.
29 *
1/*
2 * Copyright (c) 1995, David Greenman
3 * All rights reserved.
4 *
5 * Modifications to support NetBSD and media selection:
6 * Copyright (c) 1997 Jason R. Thorpe. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 13 unchanged lines hidden (view full) ---

22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 * SUCH DAMAGE.
29 *
30 * $Id: if_fxp.c,v 1.65 1999/03/17 16:44:53 luigi Exp $
30 * $Id: if_fxp.c,v 1.66 1999/03/20 04:51:25 wes Exp $
31 */
32
33/*
34 * Intel EtherExpress Pro/100B PCI Fast Ethernet driver
35 */
36
37#include "bpfilter.h"
38

--- 45 unchanged lines hidden (view full) ---

84/* XXX XXX NEED REAL DMA MAPPING SUPPORT XXX XXX */
85#undef vtophys
86#define vtophys(va) alpha_XXX_dmamap((vm_offset_t)(va))
87#endif /* __alpha__ */
88
89#else /* __FreeBSD__ */
90
91#include <sys/sockio.h>
31 */
32
33/*
34 * Intel EtherExpress Pro/100B PCI Fast Ethernet driver
35 */
36
37#include "bpfilter.h"
38

--- 45 unchanged lines hidden (view full) ---

84/* XXX XXX NEED REAL DMA MAPPING SUPPORT XXX XXX */
85#undef vtophys
86#define vtophys(va) alpha_XXX_dmamap((vm_offset_t)(va))
87#endif /* __alpha__ */
88
89#else /* __FreeBSD__ */
90
91#include <sys/sockio.h>
92#include <sys/bus.h>
93#include <machine/bus.h>
94#include <sys/rman.h>
95#include <machine/resource.h>
92
93#include <net/ethernet.h>
94#include <net/if_arp.h>
95
96#include <vm/vm.h> /* for vtophys */
97#include <vm/pmap.h> /* for vtophys */
98#include <machine/clock.h> /* for DELAY */
99

--- 386 unchanged lines hidden (view full) ---

486 return (EINVAL);
487 }
488
489 return (0);
490}
491
492#else /* __FreeBSD__ */
493
96
97#include <net/ethernet.h>
98#include <net/if_arp.h>
99
100#include <vm/vm.h> /* for vtophys */
101#include <vm/pmap.h> /* for vtophys */
102#include <machine/clock.h> /* for DELAY */
103

--- 386 unchanged lines hidden (view full) ---

490 return (EINVAL);
491 }
492
493 return (0);
494}
495
496#else /* __FreeBSD__ */
497
494static u_long fxp_count;
495static const char *fxp_probe __P((pcici_t, pcidi_t));
496static void fxp_attach __P((pcici_t, int));
497
498static void fxp_shutdown __P((int, void *));
499
500static struct pci_device fxp_device = {
501 "fxp",
502 fxp_probe,
503 fxp_attach,
504 &fxp_count,
505 NULL
506};
507DATA_SET(pcidevice_set, fxp_device);
508
509/*
510 * Return identification string if this is device is ours.
511 */
498/*
499 * Return identification string if this is device is ours.
500 */
512static const char *
513fxp_probe(config_id, device_id)
514 pcici_t config_id;
515 pcidi_t device_id;
501static int
502fxp_probe(device_t dev)
516{
503{
517 if (((device_id & 0xffff) == FXP_VENDORID_INTEL) &&
518 ((device_id >> 16) & 0xffff) == FXP_DEVICEID_i82557)
519 return ("Intel EtherExpress Pro 10/100B Ethernet");
504 if ((pci_get_vendor(dev) == FXP_VENDORID_INTEL) &&
505 (pci_get_device(dev) == FXP_DEVICEID_i82557)) {
506 device_set_desc(dev, "Intel EtherExpress Pro 10/100B Ethernet");
507 return 0;
508 }
520
509
521 return NULL;
510 return ENXIO;
522}
523
511}
512
524static void
525fxp_attach(config_id, unit)
526 pcici_t config_id;
527 int unit;
513static int
514fxp_attach(device_t dev)
528{
515{
529 struct fxp_softc *sc;
530 vm_offset_t pbase;
516 int error = 0;
517 struct fxp_softc *sc = device_get_softc(dev);
531 struct ifnet *ifp;
532 int s;
533 u_long val;
518 struct ifnet *ifp;
519 int s;
520 u_long val;
521 int rid;
534
522
535 sc = malloc(sizeof(struct fxp_softc), M_DEVBUF, M_NOWAIT);
536 if (sc == NULL)
537 return;
538 bzero(sc, sizeof(struct fxp_softc));
539 callout_handle_init(&sc->stat_ch);
540
541 s = splimp();
542
543 /*
544 * Enable bus mastering.
545 */
523 callout_handle_init(&sc->stat_ch);
524
525 s = splimp();
526
527 /*
528 * Enable bus mastering.
529 */
546 val = pci_conf_read(config_id, PCI_COMMAND_STATUS_REG);
530 val = pci_read_config(dev, PCIR_COMMAND, 2);
547 val |= (PCIM_CMD_MEMEN|PCIM_CMD_BUSMASTEREN);
531 val |= (PCIM_CMD_MEMEN|PCIM_CMD_BUSMASTEREN);
548 pci_conf_write(config_id, PCI_COMMAND_STATUS_REG, val);
532 pci_write_config(dev, PCIR_COMMAND, val, 2);
549
550 /*
551 * Map control/status registers.
552 */
533
534 /*
535 * Map control/status registers.
536 */
553 if (!pci_map_mem(config_id, FXP_PCI_MMBA,
554 (vm_offset_t *)&sc->csr, &pbase)) {
555 printf("fxp%d: couldn't map memory\n", unit);
537 rid = FXP_PCI_MMBA;
538 sc->mem = bus_alloc_resource(dev, SYS_RES_MEMORY, &rid,
539 0, ~0, 1, RF_ACTIVE);
540 if (!sc->mem) {
541 device_printf(dev, "could not map memory\n");
542 error = ENXIO;
556 goto fail;
543 goto fail;
557 }
544 }
545 sc->csr = rman_get_virtual(sc->mem); /* XXX use bus_space */
558
559 /*
560 * Allocate our interrupt.
561 */
546
547 /*
548 * Allocate our interrupt.
549 */
562 if (!pci_map_int(config_id, fxp_intr, sc, &net_imask)) {
563 printf("fxp%d: couldn't map interrupt\n", unit);
550 rid = 0;
551 sc->irq = bus_alloc_resource(dev, SYS_RES_IRQ, &rid, 0, ~0, 1,
552 RF_SHAREABLE | RF_ACTIVE);
553 if (sc->irq == NULL) {
554 device_printf(dev, "could not map interrupt\n");
555 error = ENXIO;
564 goto fail;
565 }
566
556 goto fail;
557 }
558
559 error = bus_setup_intr(dev, sc->irq, fxp_intr, sc, &sc->ih);
560 if (error) {
561 device_printf(dev, "could not setup irq\n");
562 goto fail;
563 }
564
567 /* Do generic parts of attach. */
568 if (fxp_attach_common(sc, sc->arpcom.ac_enaddr)) {
569 /* Failed! */
565 /* Do generic parts of attach. */
566 if (fxp_attach_common(sc, sc->arpcom.ac_enaddr)) {
567 /* Failed! */
570 (void) pci_unmap_int(config_id);
568 bus_teardown_intr(dev, sc->irq, sc->ih);
569 bus_release_resource(dev, SYS_RES_IRQ, 0, sc->irq);
570 bus_release_resource(dev, SYS_RES_MEMORY, FXP_PCI_MMBA, sc->mem);
571 error = ENXIO;
571 goto fail;
572 }
573
572 goto fail;
573 }
574
574 printf("fxp%d: Ethernet address %6D%s\n", unit,
575 device_printf(dev, "Ethernet address %6D%s\n",
575 sc->arpcom.ac_enaddr, ":", sc->phy_10Mbps_only ? ", 10Mbps" : "");
576
577 ifp = &sc->arpcom.ac_if;
576 sc->arpcom.ac_enaddr, ":", sc->phy_10Mbps_only ? ", 10Mbps" : "");
577
578 ifp = &sc->arpcom.ac_if;
578 ifp->if_unit = unit;
579 ifp->if_unit = device_get_unit(dev);
579 ifp->if_name = "fxp";
580 ifp->if_output = ether_output;
581 ifp->if_baudrate = 100000000;
582 ifp->if_init = fxp_init;
583 ifp->if_softc = sc;
584 ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
585 ifp->if_ioctl = fxp_ioctl;
586 ifp->if_start = fxp_start;

--- 8 unchanged lines hidden (view full) ---

595 * TX descriptors.
596 */
597 ifp->if_snd.ifq_maxlen = FXP_NTXCB - 1;
598 ether_ifattach(ifp);
599#if NBPFILTER > 0
600 bpfattach(ifp, DLT_EN10MB, sizeof(struct ether_header));
601#endif
602
580 ifp->if_name = "fxp";
581 ifp->if_output = ether_output;
582 ifp->if_baudrate = 100000000;
583 ifp->if_init = fxp_init;
584 ifp->if_softc = sc;
585 ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
586 ifp->if_ioctl = fxp_ioctl;
587 ifp->if_start = fxp_start;

--- 8 unchanged lines hidden (view full) ---

596 * TX descriptors.
597 */
598 ifp->if_snd.ifq_maxlen = FXP_NTXCB - 1;
599 ether_ifattach(ifp);
600#if NBPFILTER > 0
601 bpfattach(ifp, DLT_EN10MB, sizeof(struct ether_header));
602#endif
603
604 splx(s);
605 return 0;
606
607 fail:
608 splx(s);
609 return error;
610}
611
612/*
613 * Detach interface.
614 */
615static int
616fxp_detach(device_t dev)
617{
618 struct fxp_softc *sc = device_get_softc(dev);
619 int s;
620
621 s = splimp();
622
603 /*
623 /*
604 * Add shutdown hook so that DMA is disabled prior to reboot. Not
605 * doing do could allow DMA to corrupt kernel memory during the
606 * reboot before the driver initializes.
624 * Close down routes etc.
607 */
625 */
608 at_shutdown(fxp_shutdown, sc, SHUTDOWN_POST_SYNC);
626 if_detach(&sc->arpcom.ac_if);
609
627
610 splx(s);
611 return;
628 /*
629 * Stop DMA and drop transmit queue.
630 */
631 fxp_stop(sc);
612
632
613 fail:
614 free(sc, M_DEVBUF);
633 /*
634 * Deallocate resources.
635 */
636 bus_teardown_intr(dev, sc->irq, sc->ih);
637 bus_release_resource(dev, SYS_RES_IRQ, 0, sc->irq);
638 bus_release_resource(dev, SYS_RES_MEMORY, FXP_PCI_MMBA, sc->mem);
639
640 /*
641 * Free all the receive buffers.
642 */
643 if (sc->rfa_headm != NULL)
644 m_freem(sc->rfa_headm);
645
646 /*
647 * Free all media structures.
648 */
649 ifmedia_removeall(&sc->sc_media);
650
651 /*
652 * Free anciliary structures.
653 */
654 free(sc->cbl_base, M_DEVBUF);
655 free(sc->fxp_stats, M_DEVBUF);
656 free(sc->mcsp, M_DEVBUF);
657
615 splx(s);
658 splx(s);
659
660 return 0;
616}
617
618/*
619 * Device shutdown routine. Called at system shutdown after sync. The
620 * main purpose of this routine is to shut off receiver DMA so that
621 * kernel memory doesn't get clobbered during warmboot.
622 */
661}
662
663/*
664 * Device shutdown routine. Called at system shutdown after sync. The
665 * main purpose of this routine is to shut off receiver DMA so that
666 * kernel memory doesn't get clobbered during warmboot.
667 */
623static void
624fxp_shutdown(howto, sc)
625 int howto;
626 void *sc;
668static int
669fxp_shutdown(device_t dev)
627{
670{
628 fxp_stop((struct fxp_softc *) sc);
671 /*
672 * Make sure that DMA is disabled prior to reboot. Not doing
673 * do could allow DMA to corrupt kernel memory during the
674 * reboot before the driver initializes.
675 */
676 fxp_stop((struct fxp_softc *) device_get_softc(dev));
677 return 0;
629}
630
678}
679
680static device_method_t fxp_methods[] = {
681 /* Device interface */
682 DEVMETHOD(device_probe, fxp_probe),
683 DEVMETHOD(device_attach, fxp_attach),
684 DEVMETHOD(device_detach, fxp_detach),
685 DEVMETHOD(device_shutdown, fxp_shutdown),
686
687 { 0, 0 }
688};
689
690static driver_t fxp_driver = {
691 "fxp",
692 fxp_methods,
693 DRIVER_TYPE_NET,
694 sizeof(struct fxp_softc),
695};
696
697static devclass_t fxp_devclass;
698
699DRIVER_MODULE(fxp, pci, fxp_driver, fxp_devclass, 0, 0);
700
631#endif /* __NetBSD__ */
632
633/*************************************************************
634 * End of operating system-specific autoconfiguration glue
635 *************************************************************/
636
637/*
638 * Do generic parts of attach.

--- 1287 unchanged lines hidden ---
701#endif /* __NetBSD__ */
702
703/*************************************************************
704 * End of operating system-specific autoconfiguration glue
705 *************************************************************/
706
707/*
708 * Do generic parts of attach.

--- 1287 unchanged lines hidden ---