if_ed_pci.c revision 330897
1/*-
2 * SPDX-License-Identifier: BSD-4-Clause
3 *
4 * Copyright (c) 1996 Stefan Esser <se@freebsd.org>
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 *    notice immediately at the beginning of the file, without modification,
12 *    this list of conditions, and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 *    notice, this list of conditions and the following disclaimer in the
15 *    documentation and/or other materials provided with the distribution.
16 * 3. Absolutely no warranty of function or purpose is made by the author
17 *    Stefan Esser.
18 * 4. Modifications may be freely made to this file if the above conditions
19 *    are met.
20 */
21
22#include <sys/cdefs.h>
23__FBSDID("$FreeBSD: stable/11/sys/dev/ed/if_ed_pci.c 330897 2018-03-14 03:19:51Z eadler $");
24
25#include <sys/param.h>
26#include <sys/systm.h>
27#include <sys/socket.h>
28#include <sys/kernel.h>
29
30#include <sys/module.h>
31#include <sys/bus.h>
32
33#include <machine/bus.h>
34#include <sys/rman.h>
35#include <machine/resource.h>
36
37#include <net/if.h>
38#include <net/if_arp.h>
39#include <net/if_media.h>
40#include <net/if_mib.h>
41
42#include <dev/pci/pcireg.h>
43#include <dev/pci/pcivar.h>
44
45#include <dev/ed/if_edvar.h>
46#include <dev/ed/rtl80x9reg.h>
47
48static struct _pcsid
49{
50	uint32_t	type;
51	const char	*desc;
52} pci_ids[] =
53{
54	{ 0x140111f6, "Compex RL2000" },
55	{ 0x005812c3, "Holtek HT80232" },
56	{ 0x30008e2e, "KTI ET32P2" },
57	{ 0x50004a14, "NetVin NV5000SC" },
58	{ 0x09401050, "ProLAN" },
59	{ ED_RTL8029_PCI_ID, "RealTek 8029" }, /* Needs realtek full duplex */
60	{ 0x0e3410bd, "Surecom NE-34" },
61	{ 0x09261106, "VIA VT86C926" },
62	{ 0x19808c4a, "Winbond W89C940" },
63	{ 0x5a5a1050, "Winbond W89C940F" },
64#if 0
65	/* some Holtek needs special lovin', disabled by default */
66	/* The Holtek can report/do full duplex, but that's unimplemented */
67	{ 0x559812c3, "Holtek HT80229" },	/* Only 32-bit I/O, Holtek fdx, STOP_PG_60? */
68#endif
69	{ 0x00000000, NULL }
70};
71
72static int	ed_pci_probe(device_t);
73static int	ed_pci_attach(device_t);
74
75static int
76ed_pci_probe(device_t dev)
77{
78	uint32_t	type = pci_get_devid(dev);
79	struct _pcsid	*ep =pci_ids;
80
81	while (ep->type && ep->type != type)
82		++ep;
83	if (ep->desc == NULL)
84		return (ENXIO);
85	device_set_desc(dev, ep->desc);
86	return (BUS_PROBE_DEFAULT);
87}
88
89static int
90ed_pci_attach(device_t dev)
91{
92	struct	ed_softc *sc = device_get_softc(dev);
93	int	error = ENXIO;
94
95	/*
96	 * Probe RTL8029 cards, but allow failure and try as a generic
97	 * ne-2000.  QEMU 0.9 and earlier use the RTL8029 PCI ID, but
98	 * are areally just generic ne-2000 cards.
99	 */
100	if (pci_get_devid(dev) == ED_RTL8029_PCI_ID)
101		error = ed_probe_RTL80x9(dev, PCIR_BAR(0), 0);
102	if (error)
103		error = ed_probe_Novell(dev, PCIR_BAR(0),
104		    ED_FLAGS_FORCE_16BIT_MODE);
105	if (error) {
106		ed_release_resources(dev);
107		return (error);
108	}
109	ed_Novell_read_mac(sc);
110
111	error = ed_alloc_irq(dev, 0, RF_SHAREABLE);
112	if (error) {
113		ed_release_resources(dev);
114		return (error);
115	}
116	if (sc->sc_media_ioctl == NULL)
117		ed_gen_ifmedia_init(sc);
118	error = ed_attach(dev);
119	if (error) {
120		ed_release_resources(dev);
121		return (error);
122	}
123	error = bus_setup_intr(dev, sc->irq_res, INTR_TYPE_NET | INTR_MPSAFE,
124	    NULL, edintr, sc, &sc->irq_handle);
125	if (error)
126		ed_release_resources(dev);
127	return (error);
128}
129
130static device_method_t ed_pci_methods[] = {
131	/* Device interface */
132	DEVMETHOD(device_probe,		ed_pci_probe),
133	DEVMETHOD(device_attach,	ed_pci_attach),
134	DEVMETHOD(device_detach,	ed_detach),
135
136	{ 0, 0 }
137};
138
139static driver_t ed_pci_driver = {
140	"ed",
141	ed_pci_methods,
142	sizeof(struct ed_softc),
143};
144
145DRIVER_MODULE(ed, pci, ed_pci_driver, ed_devclass, 0, 0);
146MODULE_DEPEND(ed, pci, 1, 1, 1);
147MODULE_DEPEND(ed, ether, 1, 1, 1);
148MODULE_PNP_INFO("W32:vendor/device;D:human", pci, ed, pci_ids, sizeof(pci_ids[0]),
149    nitems(pci_ids) - 1);
150
151