1 /*-
2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3 *
4 * Copyright (c) 2005, M. Warner Losh
5 * All rights reserved.
6 * Copyright (c) 1995, David Greenman
7 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 * notice unmodified, this list of conditions, and the following
14 * disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE.
30 */
31
32 #include <sys/cdefs.h>
33 __FBSDID("$FreeBSD: stable/12/sys/dev/ed/if_ed_sic.c 326255 2017-11-27 14:52:40Z pfg $");
34
35 #include "opt_ed.h"
36
37 #ifdef ED_SIC
38 #include <sys/param.h>
39 #include <sys/systm.h>
40 #include <sys/sockio.h>
41 #include <sys/mbuf.h>
42 #include <sys/kernel.h>
43 #include <sys/socket.h>
44 #include <sys/syslog.h>
45
46 #include <sys/bus.h>
47
48 #include <machine/bus.h>
49 #include <sys/rman.h>
50 #include <machine/resource.h>
51
52 #include <net/ethernet.h>
53 #include <net/if.h>
54 #include <net/if_arp.h>
55 #include <net/if_dl.h>
56 #include <net/if_mib.h>
57 #include <net/if_media.h>
58
59 #include <net/bpf.h>
60
61 #include <dev/ed/if_edreg.h>
62 #include <dev/ed/if_edvar.h>
63
64 /*
65 * Probe and vendor-specific initialization routine for SIC boards
66 */
67 int
ed_probe_SIC(device_t dev,int port_rid,int flags)68 ed_probe_SIC(device_t dev, int port_rid, int flags)
69 {
70 struct ed_softc *sc = device_get_softc(dev);
71 int error;
72 int i;
73 u_int memsize;
74 u_long pmem;
75 u_char sum;
76
77 error = ed_alloc_port(dev, 0, ED_SIC_IO_PORTS);
78 if (error)
79 return (error);
80
81 sc->asic_offset = ED_SIC_ASIC_OFFSET;
82 sc->nic_offset = ED_SIC_NIC_OFFSET;
83
84 memsize = 16384;
85 /* XXX Needs to allow different msize */
86 error = ed_alloc_memory(dev, 0, memsize);
87 if (error)
88 return (error);
89
90 sc->mem_start = 0;
91 sc->mem_size = memsize;
92
93 pmem = rman_get_start(sc->mem_res);
94 error = ed_isa_mem_ok(dev, pmem, memsize);
95 if (error)
96 return (error);
97
98 /* Reset card to force it into a known state. */
99 ed_asic_outb(sc, 0, 0x00);
100 DELAY(100);
101
102 /*
103 * Here we check the card ROM, if the checksum passes, and the
104 * type code and ethernet address check out, then we know we have
105 * an SIC card.
106 */
107 ed_asic_outb(sc, 0, 0x81);
108 DELAY(100);
109
110 sum = bus_space_read_1(sc->mem_bst, sc->mem_bsh, 6);
111 for (i = 0; i < ETHER_ADDR_LEN; i++)
112 sum ^= (sc->enaddr[i] =
113 bus_space_read_1(sc->mem_bst, sc->mem_bsh, i));
114 #ifdef ED_DEBUG
115 device_printf(dev, "ed_probe_sic: got address %6D\n",
116 sc->enaddr, ":");
117 #endif
118 if (sum != 0)
119 return (ENXIO);
120 if ((sc->enaddr[0] | sc->enaddr[1] | sc->enaddr[2]) == 0)
121 return (ENXIO);
122
123 sc->vendor = ED_VENDOR_SIC;
124 sc->type_str = "SIC";
125 sc->isa16bit = 0;
126 sc->cr_proto = 0;
127
128 /*
129 * SIC RAM page 0x0000-0x3fff(or 0x7fff)
130 */
131 ed_asic_outb(sc, 0, 0x80);
132 DELAY(100);
133
134 error = ed_clear_memory(dev);
135 if (error)
136 return (error);
137
138 sc->mem_shared = 1;
139 sc->mem_end = sc->mem_start + sc->mem_size;
140
141 /*
142 * allocate one xmit buffer if < 16k, two buffers otherwise
143 */
144 if ((sc->mem_size < 16384) || (flags & ED_FLAGS_NO_MULTI_BUFFERING))
145 sc->txb_cnt = 1;
146 else
147 sc->txb_cnt = 2;
148 sc->tx_page_start = 0;
149
150 sc->rec_page_start = sc->tx_page_start + ED_TXBUF_SIZE * sc->txb_cnt;
151 sc->rec_page_stop = sc->tx_page_start + sc->mem_size / ED_PAGE_SIZE;
152
153 sc->mem_ring = sc->mem_start + sc->txb_cnt * ED_PAGE_SIZE * ED_TXBUF_SIZE;
154
155 sc->sc_write_mbufs = ed_shmem_write_mbufs;
156 return (0);
157 }
158
159 #endif /* ED_SIC */
160