i82596.c revision 1.13 1 1.13 skrll /* $NetBSD: i82596.c,v 1.13 2006/07/08 16:24:08 skrll Exp $ */
2 1.1 jkunz
3 1.1 jkunz /*
4 1.1 jkunz * Copyright (c) 2003 Jochen Kunz.
5 1.1 jkunz * All rights reserved.
6 1.1 jkunz *
7 1.1 jkunz * Redistribution and use in source and binary forms, with or without
8 1.1 jkunz * modification, are permitted provided that the following conditions
9 1.1 jkunz * are met:
10 1.1 jkunz * 1. Redistributions of source code must retain the above copyright
11 1.1 jkunz * notice, this list of conditions and the following disclaimer.
12 1.1 jkunz * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 jkunz * notice, this list of conditions and the following disclaimer in the
14 1.1 jkunz * documentation and/or other materials provided with the distribution.
15 1.1 jkunz * 3. The name of Jochen Kunz may not be used to endorse or promote
16 1.1 jkunz * products derived from this software without specific prior
17 1.1 jkunz * written permission.
18 1.1 jkunz *
19 1.1 jkunz * THIS SOFTWARE IS PROVIDED BY JOCHEN KUNZ
20 1.1 jkunz * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 1.1 jkunz * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 1.1 jkunz * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JOCHEN KUNZ
23 1.1 jkunz * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 1.1 jkunz * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 1.1 jkunz * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 1.1 jkunz * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 1.1 jkunz * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 1.1 jkunz * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 1.1 jkunz * POSSIBILITY OF SUCH DAMAGE.
30 1.1 jkunz */
31 1.1 jkunz
32 1.1 jkunz /*
33 1.8 perry * Driver for the Intel i82596 10MBit/s Ethernet chip.
34 1.1 jkunz * It operates the i82596 in 32-Bit Linear Mode, opposed to the old i82586
35 1.8 perry * ie(4) driver (src/sys/dev/ic/i82586.c), that degrades the i82596 to
36 1.1 jkunz * i82586 compatibility mode.
37 1.13 skrll *
38 1.1 jkunz * Documentation about this chip can be found on http://www.openpa.net/
39 1.1 jkunz * file names 29021806.pdf and 29021906.pdf
40 1.1 jkunz */
41 1.1 jkunz
42 1.1 jkunz #include <sys/cdefs.h>
43 1.13 skrll __KERNEL_RCSID(0, "$NetBSD: i82596.c,v 1.13 2006/07/08 16:24:08 skrll Exp $");
44 1.1 jkunz
45 1.1 jkunz /* autoconfig and device stuff */
46 1.1 jkunz #include <sys/param.h>
47 1.1 jkunz #include <sys/device.h>
48 1.1 jkunz #include <sys/conf.h>
49 1.1 jkunz #include "locators.h"
50 1.1 jkunz #include "ioconf.h"
51 1.1 jkunz
52 1.1 jkunz /* bus_space / bus_dma etc. */
53 1.1 jkunz #include <machine/bus.h>
54 1.1 jkunz #include <machine/intr.h>
55 1.1 jkunz
56 1.1 jkunz /* general system data and functions */
57 1.1 jkunz #include <sys/systm.h>
58 1.1 jkunz #include <sys/ioctl.h>
59 1.1 jkunz
60 1.1 jkunz /* tsleep / sleep / wakeup */
61 1.1 jkunz #include <sys/proc.h>
62 1.1 jkunz /* hz for above */
63 1.1 jkunz #include <sys/kernel.h>
64 1.1 jkunz
65 1.1 jkunz /* network stuff */
66 1.1 jkunz #include <net/if.h>
67 1.1 jkunz #include <net/if_dl.h>
68 1.1 jkunz #include <net/if_media.h>
69 1.1 jkunz #include <net/if_ether.h>
70 1.1 jkunz #include <sys/socket.h>
71 1.1 jkunz #include <sys/mbuf.h>
72 1.1 jkunz
73 1.1 jkunz #include "bpfilter.h"
74 1.8 perry #if NBPFILTER > 0
75 1.1 jkunz #include <net/bpf.h>
76 1.8 perry #endif
77 1.1 jkunz
78 1.1 jkunz #include <dev/ic/i82596reg.h>
79 1.1 jkunz #include <dev/ic/i82596var.h>
80 1.1 jkunz
81 1.1 jkunz /* Supported chip variants */
82 1.10 skrll const char *i82596_typenames[] = { "unknown", "DX/SX", "CA" };
83 1.1 jkunz
84 1.1 jkunz /* media change and status callback */
85 1.1 jkunz static int iee_mediachange(struct ifnet *);
86 1.1 jkunz static void iee_mediastatus(struct ifnet *, struct ifmediareq *);
87 1.1 jkunz
88 1.1 jkunz /* interface routines to upper protocols */
89 1.1 jkunz static void iee_start(struct ifnet *); /* initiate output */
90 1.1 jkunz static int iee_ioctl(struct ifnet *, u_long, caddr_t); /* ioctl routine */
91 1.1 jkunz static int iee_init(struct ifnet *); /* init routine */
92 1.1 jkunz static void iee_stop(struct ifnet *, int); /* stop routine */
93 1.1 jkunz static void iee_watchdog(struct ifnet *); /* timer routine */
94 1.1 jkunz static void iee_drain(struct ifnet *); /* release resources */
95 1.1 jkunz
96 1.1 jkunz /* internal helper functions */
97 1.7 tsutsui static void iee_cb_setup(struct iee_softc *, uint32_t);
98 1.1 jkunz
99 1.1 jkunz /*
100 1.13 skrll * Things a MD frontend has to provide:
101 1.13 skrll *
102 1.13 skrll * The functions via function pointers in the softc:
103 1.13 skrll * int (*sc_iee_cmd)(struct iee_softc *sc, uint32_t cmd);
104 1.13 skrll * int (*sc_iee_reset)(struct iee_softc *sc);
105 1.13 skrll * void (*sc_mediastatus)(struct ifnet *, struct ifmediareq *);
106 1.13 skrll * int (*sc_mediachange)(struct ifnet *);
107 1.13 skrll *
108 1.13 skrll * sc_iee_cmd(): send a command to the i82596 by writing the cmd parameter
109 1.13 skrll * to the SCP cmd word and issuing a Channel Attention.
110 1.13 skrll * sc_iee_reset(): initiate a reset, supply the address of the SCP to the
111 1.13 skrll * chip, wait for the chip to initialize and ACK interrupts that
112 1.13 skrll * this may have caused by calling (sc->sc_iee_cmd)(sc, IEE_SCB_ACK);
113 1.13 skrll * This functions must carefully bus_dmamap_sync() all data they have touched!
114 1.13 skrll *
115 1.13 skrll * sc_mediastatus() and sc_mediachange() are just MD hooks to the according
116 1.13 skrll * MI functions. The MD frontend may set this pointers to NULL when they
117 1.13 skrll * are not needed.
118 1.13 skrll *
119 1.13 skrll * sc->sc_type has to be set to I82596_UNKNOWN or I82596_DX or I82596_CA.
120 1.13 skrll * This is for printing out the correct chip type at attach time only. The
121 1.13 skrll * MI backend doesn't distinguish different chip types when programming
122 1.13 skrll * the chip.
123 1.13 skrll *
124 1.13 skrll * sc->sc_flags has to be set to 0 on little endian hardware and to
125 1.13 skrll * IEE_NEED_SWAP on big endian hardware, when endianess conversion is not
126 1.13 skrll * done by the bus attachment. Usually you need to set IEE_NEED_SWAP
127 1.13 skrll * when IEE_SYSBUS_BE is set in the sysbus byte.
128 1.13 skrll *
129 1.13 skrll * sc->sc_cl_align must be set to 1 or to the cache line size. When set to
130 1.13 skrll * 1 no special alignment of DMA descriptors is done. If sc->sc_cl_align != 1
131 1.13 skrll * it forces alignment of the data structures in the shared memory to a multiple
132 1.13 skrll * of sc->sc_cl_align. This is needed on archs like hp700 that have non DMA
133 1.13 skrll * I/O coherent caches and are unable to map the shared memory uncachable.
134 1.13 skrll * (At least pre PA7100LC CPUs are unable to map memory uncachable.)
135 1.13 skrll *
136 1.13 skrll * sc->sc_cl_align MUST BE INITIALIZED BEFORE THE FOLLOWING MACROS ARE USED:
137 1.13 skrll * SC_* IEE_*_SZ IEE_*_OFF IEE_SHMEM_MAX (shell style glob(3) pattern)
138 1.13 skrll *
139 1.13 skrll * The MD frontend has to allocate a piece of DMA memory at least of
140 1.13 skrll * IEE_SHMEM_MAX bytes size. All communication with the chip is done via
141 1.13 skrll * this shared memory. If possible map this memory non-cachable on
142 1.13 skrll * archs with non DMA I/O coherent caches. The base of the memory needs
143 1.13 skrll * to be aligned to an even address if sc->sc_cl_align == 1 and aligned
144 1.13 skrll * to a cache line if sc->sc_cl_align != 1.
145 1.13 skrll *
146 1.13 skrll * An interrupt with iee_intr() as handler must be established.
147 1.13 skrll *
148 1.13 skrll * Call void iee_attach(struct iee_softc *sc, uint8_t *ether_address,
149 1.13 skrll * int *media, int nmedia, int defmedia); when everything is set up. First
150 1.13 skrll * parameter is a pointer to the MI softc, ether_address is an array that
151 1.13 skrll * contains the ethernet address. media is an array of the media types
152 1.13 skrll * provided by the hardware. The members of this array are supplied to
153 1.13 skrll * ifmedia_add() in sequence. nmedia is the count of elements in media.
154 1.13 skrll * defmedia is the default media that is set via ifmedia_set().
155 1.13 skrll * nmedia and defmedia are ignored when media == NULL.
156 1.13 skrll *
157 1.13 skrll * The MD backend may call iee_detach() to detach the device.
158 1.13 skrll *
159 1.13 skrll * See sys/arch/hp700/gsc/if_iee_gsc.c for an example.
160 1.13 skrll */
161 1.1 jkunz
162 1.1 jkunz
163 1.1 jkunz /*
164 1.13 skrll * How frame reception is done:
165 1.13 skrll * Each Receive Frame Descriptor has one associated Receive Buffer Descriptor.
166 1.13 skrll * Each RBD points to the data area of an mbuf cluster. The RFDs are linked
167 1.13 skrll * together in a circular list. sc->sc_rx_done is the count of RFDs in the
168 1.13 skrll * list already processed / the number of the RFD that has to be checked for
169 1.13 skrll * a new frame first at the next RX interrupt. Upon successful reception of
170 1.13 skrll * a frame the mbuf cluster is handled to upper protocol layers, a new mbuf
171 1.13 skrll * cluster is allocated and the RFD / RBD are reinitialized accordingly.
172 1.13 skrll *
173 1.13 skrll * When a RFD list overrun occurred the whole RFD and RBD lists are reinitialized
174 1.13 skrll * and frame reception is started again.
175 1.13 skrll */
176 1.1 jkunz int
177 1.1 jkunz iee_intr(void *intarg)
178 1.1 jkunz {
179 1.1 jkunz struct iee_softc *sc = intarg;
180 1.1 jkunz struct ifnet *ifp = &sc->sc_ethercom.ec_if;
181 1.1 jkunz struct iee_rfd *rfd;
182 1.1 jkunz struct iee_rbd *rbd;
183 1.1 jkunz bus_dmamap_t rx_map;
184 1.1 jkunz struct mbuf *rx_mbuf;
185 1.1 jkunz struct mbuf *new_mbuf;
186 1.1 jkunz int scb_status;
187 1.1 jkunz int scb_cmd;
188 1.6 tsutsui int n, col;
189 1.1 jkunz
190 1.1 jkunz if ((ifp->if_flags & IFF_RUNNING) == 0) {
191 1.1 jkunz (sc->sc_iee_cmd)(sc, IEE_SCB_ACK);
192 1.1 jkunz return(1);
193 1.1 jkunz }
194 1.1 jkunz bus_dmamap_sync(sc->sc_dmat, sc->sc_shmem_map, 0, IEE_SHMEM_MAX,
195 1.1 jkunz BUS_DMASYNC_POSTREAD);
196 1.1 jkunz scb_status = SC_SCB->scb_status;
197 1.1 jkunz scb_cmd = SC_SCB->scb_cmd;
198 1.1 jkunz rfd = SC_RFD(sc->sc_rx_done);
199 1.2 jkunz while ((rfd->rfd_status & IEE_RFD_C) != 0) {
200 1.1 jkunz /* At least one packet was received. */
201 1.1 jkunz rbd = SC_RBD(sc->sc_rx_done);
202 1.1 jkunz rx_map = sc->sc_rx_map[sc->sc_rx_done];
203 1.1 jkunz rx_mbuf = sc->sc_rx_mbuf[sc->sc_rx_done];
204 1.1 jkunz SC_RBD((sc->sc_rx_done + IEE_NRFD - 1) % IEE_NRFD)->rbd_size
205 1.1 jkunz &= ~IEE_RBD_EL;
206 1.1 jkunz if ((rfd->rfd_status & IEE_RFD_OK) == 0
207 1.1 jkunz || (rbd->rbd_count & IEE_RBD_EOF) == 0
208 1.1 jkunz || (rbd->rbd_count & IEE_RBD_F) == 0){
209 1.1 jkunz /* Receive error, skip frame and reuse buffer. */
210 1.1 jkunz rfd->rfd_status = 0;
211 1.1 jkunz rbd->rbd_count = 0;
212 1.1 jkunz rbd->rbd_size = IEE_RBD_EL | rx_map->dm_segs[0].ds_len;
213 1.1 jkunz printf("%s: iee_intr: receive error %d, rfd_status="
214 1.8 perry "0x%.4x, rfd_count=0x%.4x\n", sc->sc_dev.dv_xname,
215 1.1 jkunz ++sc->sc_rx_err, rfd->rfd_status, rbd->rbd_count);
216 1.1 jkunz sc->sc_rx_done = (sc->sc_rx_done + 1) % IEE_NRFD;
217 1.1 jkunz continue;
218 1.1 jkunz }
219 1.1 jkunz rfd->rfd_status = 0;
220 1.1 jkunz bus_dmamap_sync(sc->sc_dmat, rx_map, 0, rx_mbuf->m_ext.ext_size,
221 1.1 jkunz BUS_DMASYNC_POSTREAD);
222 1.8 perry rx_mbuf->m_pkthdr.len = rx_mbuf->m_len =
223 1.1 jkunz rbd->rbd_count & IEE_RBD_COUNT;
224 1.1 jkunz rx_mbuf->m_pkthdr.rcvif = ifp;
225 1.1 jkunz MGETHDR(new_mbuf, M_DONTWAIT, MT_DATA);
226 1.1 jkunz if (new_mbuf == NULL) {
227 1.1 jkunz printf("%s: iee_intr: can't allocate mbuf\n",
228 1.1 jkunz sc->sc_dev.dv_xname);
229 1.1 jkunz break;
230 1.1 jkunz }
231 1.1 jkunz MCLAIM(new_mbuf, &sc->sc_ethercom.ec_rx_mowner);
232 1.1 jkunz MCLGET(new_mbuf, M_DONTWAIT);
233 1.1 jkunz if ((new_mbuf->m_flags & M_EXT) == 0) {
234 1.8 perry printf("%s: iee_intr: can't alloc mbuf cluster\n",
235 1.1 jkunz sc->sc_dev.dv_xname);
236 1.1 jkunz m_freem(new_mbuf);
237 1.1 jkunz break;
238 1.1 jkunz }
239 1.1 jkunz bus_dmamap_unload(sc->sc_dmat, rx_map);
240 1.8 perry if (bus_dmamap_load(sc->sc_dmat, rx_map,
241 1.8 perry new_mbuf->m_ext.ext_buf, new_mbuf->m_ext.ext_size,
242 1.1 jkunz NULL, BUS_DMA_READ | BUS_DMA_NOWAIT) != 0)
243 1.1 jkunz panic("%s: iee_intr: can't load RX DMA map\n",
244 1.1 jkunz sc->sc_dev.dv_xname);
245 1.1 jkunz bus_dmamap_sync(sc->sc_dmat, rx_map, 0,
246 1.1 jkunz new_mbuf->m_ext.ext_size, BUS_DMASYNC_PREREAD);
247 1.1 jkunz #if NBPFILTER > 0
248 1.1 jkunz if (ifp->if_bpf != 0)
249 1.1 jkunz bpf_mtap(ifp->if_bpf, rx_mbuf);
250 1.1 jkunz #endif /* NBPFILTER > 0 */
251 1.1 jkunz (*ifp->if_input)(ifp, rx_mbuf);
252 1.1 jkunz ifp->if_ipackets++;
253 1.1 jkunz sc->sc_rx_mbuf[sc->sc_rx_done] = new_mbuf;
254 1.1 jkunz rbd->rbd_count = 0;
255 1.1 jkunz rbd->rbd_size = IEE_RBD_EL | rx_map->dm_segs[0].ds_len;
256 1.1 jkunz rbd->rbd_rb_addr = rx_map->dm_segs[0].ds_addr;
257 1.1 jkunz sc->sc_rx_done = (sc->sc_rx_done + 1) % IEE_NRFD;
258 1.1 jkunz rfd = SC_RFD(sc->sc_rx_done);
259 1.1 jkunz }
260 1.1 jkunz if ((scb_status & IEE_SCB_RUS) == IEE_SCB_RUS_NR1
261 1.1 jkunz || (scb_status & IEE_SCB_RUS) == IEE_SCB_RUS_NR2
262 1.1 jkunz || (scb_status & IEE_SCB_RUS) == IEE_SCB_RUS_NR3) {
263 1.1 jkunz /* Receive Overrun, reinit receive ring buffer. */
264 1.1 jkunz for (n = 0 ; n < IEE_NRFD ; n++) {
265 1.1 jkunz SC_RFD(n)->rfd_cmd = IEE_RFD_SF;
266 1.1 jkunz SC_RFD(n)->rfd_link_addr = IEE_PHYS_SHMEM(IEE_RFD_OFF
267 1.1 jkunz + IEE_RFD_SZ * ((n + 1) % IEE_NRFD));
268 1.8 perry SC_RBD(n)->rbd_next_rbd = IEE_PHYS_SHMEM(IEE_RBD_OFF
269 1.1 jkunz + IEE_RBD_SZ * ((n + 1) % IEE_NRFD));
270 1.8 perry SC_RBD(n)->rbd_size = IEE_RBD_EL |
271 1.1 jkunz sc->sc_rx_map[n]->dm_segs[0].ds_len;
272 1.8 perry SC_RBD(n)->rbd_rb_addr =
273 1.1 jkunz sc->sc_rx_map[n]->dm_segs[0].ds_addr;
274 1.1 jkunz }
275 1.1 jkunz SC_RFD(0)->rfd_rbd_addr = IEE_PHYS_SHMEM(IEE_RBD_OFF);
276 1.1 jkunz sc->sc_rx_done = 0;
277 1.8 perry bus_dmamap_sync(sc->sc_dmat, sc->sc_shmem_map, IEE_RFD_OFF,
278 1.1 jkunz IEE_RFD_LIST_SZ + IEE_RBD_LIST_SZ, BUS_DMASYNC_PREWRITE);
279 1.1 jkunz (sc->sc_iee_cmd)(sc, IEE_SCB_RUC_ST);
280 1.8 perry printf("%s: iee_intr: receive ring buffer overrun\n",
281 1.1 jkunz sc->sc_dev.dv_xname);
282 1.2 jkunz }
283 1.1 jkunz
284 1.8 perry if (sc->sc_next_cb != 0
285 1.2 jkunz && (SC_CB(sc->sc_next_cb - 1)->cb_status & IEE_CB_C) != 0) {
286 1.1 jkunz /* CMD list finished */
287 1.1 jkunz ifp->if_timer = 0;
288 1.1 jkunz if (sc->sc_next_tbd != 0) {
289 1.12 skrll /* A TX CMD list finished, cleanup */
290 1.1 jkunz for (n = 0 ; n < sc->sc_next_cb ; n++) {
291 1.1 jkunz m_freem(sc->sc_tx_mbuf[n]);
292 1.1 jkunz sc->sc_tx_mbuf[n] = NULL;
293 1.1 jkunz bus_dmamap_unload(sc->sc_dmat,sc->sc_tx_map[n]);
294 1.8 perry if ((SC_CB(n)->cb_status & IEE_CB_COL) != 0 &&
295 1.1 jkunz (SC_CB(n)->cb_status & IEE_CB_MAXCOL) == 0)
296 1.6 tsutsui col = 16;
297 1.1 jkunz else
298 1.8 perry col = SC_CB(n)->cb_status
299 1.1 jkunz & IEE_CB_MAXCOL;
300 1.6 tsutsui sc->sc_tx_col += col;
301 1.6 tsutsui if ((SC_CB(n)->cb_status & IEE_CB_OK) != 0) {
302 1.6 tsutsui ifp->if_opackets++;
303 1.6 tsutsui ifp->if_collisions += col;
304 1.6 tsutsui }
305 1.1 jkunz }
306 1.1 jkunz sc->sc_next_tbd = 0;
307 1.1 jkunz ifp->if_flags &= ~IFF_OACTIVE;
308 1.1 jkunz }
309 1.1 jkunz for (n = 0 ; n < sc->sc_next_cb ; n++) {
310 1.1 jkunz /* Check if a CMD failed, but ignore TX errors. */
311 1.1 jkunz if ((SC_CB(n)->cb_cmd & IEE_CB_CMD) != IEE_CB_CMD_TR
312 1.2 jkunz && ((SC_CB(n)->cb_status & IEE_CB_OK) == 0))
313 1.8 perry printf("%s: iee_intr: scb_status=0x%x "
314 1.1 jkunz "scb_cmd=0x%x failed command %d: "
315 1.8 perry "cb_status[%d]=0x%.4x cb_cmd[%d]=0x%.4x\n",
316 1.8 perry sc->sc_dev.dv_xname, scb_status, scb_cmd,
317 1.1 jkunz ++sc->sc_cmd_err, n, SC_CB(n)->cb_status,
318 1.1 jkunz n, SC_CB(n)->cb_cmd);
319 1.1 jkunz }
320 1.1 jkunz sc->sc_next_cb = 0;
321 1.1 jkunz if ((sc->sc_flags & IEE_WANT_MCAST) != 0) {
322 1.8 perry iee_cb_setup(sc, IEE_CB_CMD_MCS | IEE_CB_S | IEE_CB_EL
323 1.1 jkunz | IEE_CB_I);
324 1.1 jkunz (sc->sc_iee_cmd)(sc, IEE_SCB_CUC_EXE);
325 1.1 jkunz } else
326 1.12 skrll /* Try to get deferred packets going. */
327 1.1 jkunz iee_start(ifp);
328 1.1 jkunz }
329 1.1 jkunz if (IEE_SWAP(SC_SCB->scb_crc_err) != sc->sc_crc_err) {
330 1.1 jkunz sc->sc_crc_err = IEE_SWAP(SC_SCB->scb_crc_err);
331 1.8 perry printf("%s: iee_intr: crc_err=%d\n", sc->sc_dev.dv_xname,
332 1.1 jkunz sc->sc_crc_err);
333 1.1 jkunz }
334 1.1 jkunz if (IEE_SWAP(SC_SCB->scb_align_err) != sc->sc_align_err) {
335 1.1 jkunz sc->sc_align_err = IEE_SWAP(SC_SCB->scb_align_err);
336 1.8 perry printf("%s: iee_intr: align_err=%d\n", sc->sc_dev.dv_xname,
337 1.1 jkunz sc->sc_align_err);
338 1.1 jkunz }
339 1.1 jkunz if (IEE_SWAP(SC_SCB->scb_resource_err) != sc->sc_resource_err) {
340 1.1 jkunz sc->sc_resource_err = IEE_SWAP(SC_SCB->scb_resource_err);
341 1.8 perry printf("%s: iee_intr: resource_err=%d\n", sc->sc_dev.dv_xname,
342 1.1 jkunz sc->sc_resource_err);
343 1.1 jkunz }
344 1.1 jkunz if (IEE_SWAP(SC_SCB->scb_overrun_err) != sc->sc_overrun_err) {
345 1.1 jkunz sc->sc_overrun_err = IEE_SWAP(SC_SCB->scb_overrun_err);
346 1.8 perry printf("%s: iee_intr: overrun_err=%d\n", sc->sc_dev.dv_xname,
347 1.1 jkunz sc->sc_overrun_err);
348 1.1 jkunz }
349 1.1 jkunz if (IEE_SWAP(SC_SCB->scb_rcvcdt_err) != sc->sc_rcvcdt_err) {
350 1.1 jkunz sc->sc_rcvcdt_err = IEE_SWAP(SC_SCB->scb_rcvcdt_err);
351 1.8 perry printf("%s: iee_intr: rcvcdt_err=%d\n", sc->sc_dev.dv_xname,
352 1.1 jkunz sc->sc_rcvcdt_err);
353 1.1 jkunz }
354 1.1 jkunz if (IEE_SWAP(SC_SCB->scb_short_fr_err) != sc->sc_short_fr_err) {
355 1.1 jkunz sc->sc_short_fr_err = IEE_SWAP(SC_SCB->scb_short_fr_err);
356 1.8 perry printf("%s: iee_intr: short_fr_err=%d\n", sc->sc_dev.dv_xname,
357 1.1 jkunz sc->sc_short_fr_err);
358 1.1 jkunz }
359 1.8 perry bus_dmamap_sync(sc->sc_dmat, sc->sc_shmem_map, 0, IEE_SHMEM_MAX,
360 1.2 jkunz BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
361 1.1 jkunz (sc->sc_iee_cmd)(sc, IEE_SCB_ACK);
362 1.1 jkunz return(1);
363 1.1 jkunz }
364 1.1 jkunz
365 1.1 jkunz
366 1.1 jkunz
367 1.1 jkunz /*
368 1.13 skrll * How Command Block List Processing is done.
369 1.13 skrll *
370 1.13 skrll * A running CBL is never manipulated. If there is a CBL already running,
371 1.13 skrll * further CMDs are deferred until the current list is done. A new list is
372 1.13 skrll * setup when the old one has finished.
373 1.13 skrll * This eases programming. To manipulate a running CBL it is necessary to
374 1.13 skrll * suspend the Command Unit to avoid race conditions. After a suspend
375 1.13 skrll * is sent we have to wait for an interrupt that ACKs the suspend. Then
376 1.13 skrll * we can manipulate the CBL and resume operation. I am not sure that this
377 1.13 skrll * is more effective then the current, much simpler approach. => KISS
378 1.13 skrll * See i82596CA data sheet page 26.
379 1.13 skrll *
380 1.13 skrll * A CBL is running or on the way to be set up when (sc->sc_next_cb != 0).
381 1.13 skrll *
382 1.13 skrll * A CBL may consist of TX CMDs, and _only_ TX CMDs.
383 1.13 skrll * A TX CBL is running or on the way to be set up when
384 1.13 skrll * ((sc->sc_next_cb != 0) && (sc->sc_next_tbd != 0)).
385 1.13 skrll *
386 1.13 skrll * A CBL may consist of other non-TX CMDs like IAS or CONF, and _only_
387 1.13 skrll * non-TX CMDs.
388 1.13 skrll *
389 1.13 skrll * This comes mostly through the way how an Ethernet driver works and
390 1.13 skrll * because running CBLs are not manipulated when they are on the way. If
391 1.13 skrll * if_start() is called there will be TX CMDs enqueued so we have a running
392 1.13 skrll * CBL and other CMDs from e.g. if_ioctl() will be deferred and vice versa.
393 1.13 skrll *
394 1.13 skrll * The Multicast Setup Command is special. A MCS needs more space than
395 1.13 skrll * a single CB has. Actual space requirement depends on the length of the
396 1.13 skrll * multicast list. So we always defer MCS until other CBLs are finished,
397 1.13 skrll * then we setup a CONF CMD in the first CB. The CONF CMD is needed to
398 1.13 skrll * turn ALLMULTI on the hardware on or off. The MCS is the 2nd CB and may
399 1.13 skrll * use all the remaining space in the CBL and the Transmit Buffer Descriptor
400 1.13 skrll * List. (Therefore CBL and TBDL must be continuous in physical and virtual
401 1.13 skrll * memory. This is guaranteed through the definitions of the list offsets
402 1.13 skrll * in i82596reg.h and because it is only a single DMA segment used for all
403 1.13 skrll * lists.) When ALLMULTI is enabled via the CONF CMD, the MCS is run with
404 1.13 skrll * a multicast list length of 0, thus disabling the multicast filter.
405 1.13 skrll * A deferred MCS is signaled via ((sc->sc_flags & IEE_WANT_MCAST) != 0)
406 1.13 skrll */
407 1.1 jkunz void
408 1.7 tsutsui iee_cb_setup(struct iee_softc *sc, uint32_t cmd)
409 1.1 jkunz {
410 1.1 jkunz struct iee_cb *cb = SC_CB(sc->sc_next_cb);
411 1.1 jkunz struct ifnet *ifp = &sc->sc_ethercom.ec_if;
412 1.1 jkunz struct ether_multistep step;
413 1.1 jkunz struct ether_multi *enm;
414 1.1 jkunz
415 1.1 jkunz memset(cb, 0, IEE_CB_SZ);
416 1.1 jkunz cb->cb_cmd = cmd;
417 1.1 jkunz switch(cmd & IEE_CB_CMD) {
418 1.1 jkunz case IEE_CB_CMD_NOP: /* NOP CMD */
419 1.1 jkunz break;
420 1.1 jkunz case IEE_CB_CMD_IAS: /* Individual Address Setup */
421 1.9 he memcpy(__UNVOLATILE(cb->cb_ind_addr), LLADDR(ifp->if_sadl),
422 1.1 jkunz ETHER_ADDR_LEN);
423 1.1 jkunz break;
424 1.1 jkunz case IEE_CB_CMD_CONF: /* Configure */
425 1.9 he memcpy(__UNVOLATILE(cb->cb_cf), sc->sc_cf, sc->sc_cf[0]
426 1.1 jkunz & IEE_CF_0_CNT_M);
427 1.1 jkunz break;
428 1.1 jkunz case IEE_CB_CMD_MCS: /* Multicast Setup */
429 1.1 jkunz if (sc->sc_next_cb != 0) {
430 1.1 jkunz sc->sc_flags |= IEE_WANT_MCAST;
431 1.1 jkunz return;
432 1.1 jkunz }
433 1.1 jkunz sc->sc_flags &= ~IEE_WANT_MCAST;
434 1.1 jkunz if ((sc->sc_cf[8] & IEE_CF_8_PRM) != 0) {
435 1.1 jkunz /* Need no multicast filter in promisc mode. */
436 1.8 perry iee_cb_setup(sc, IEE_CB_CMD_CONF | IEE_CB_S | IEE_CB_EL
437 1.1 jkunz | IEE_CB_I);
438 1.1 jkunz return;
439 1.1 jkunz }
440 1.1 jkunz /* Leave room for a CONF CMD to en/dis-able ALLMULTI mode */
441 1.1 jkunz cb = SC_CB(sc->sc_next_cb + 1);
442 1.1 jkunz cb->cb_cmd = cmd;
443 1.1 jkunz cb->cb_mcast.mc_size = 0;
444 1.1 jkunz ETHER_FIRST_MULTI(step, &sc->sc_ethercom, enm);
445 1.1 jkunz while (enm != NULL) {
446 1.8 perry if (memcmp(enm->enm_addrlo, enm->enm_addrhi,
447 1.8 perry ETHER_ADDR_LEN) != 0 || cb->cb_mcast.mc_size
448 1.1 jkunz * ETHER_ADDR_LEN + 2 * IEE_CB_SZ
449 1.1 jkunz > IEE_CB_LIST_SZ + IEE_TBD_LIST_SZ) {
450 1.1 jkunz cb->cb_mcast.mc_size = 0;
451 1.1 jkunz break;
452 1.1 jkunz }
453 1.9 he memcpy(__UNVOLATILE(&cb->cb_mcast.mc_addrs[
454 1.9 he cb->cb_mcast.mc_size * ETHER_ADDR_LEN]),
455 1.1 jkunz enm->enm_addrlo, ETHER_ADDR_LEN);
456 1.1 jkunz ETHER_NEXT_MULTI(step, enm);
457 1.1 jkunz cb->cb_mcast.mc_size++;
458 1.1 jkunz }
459 1.1 jkunz if (cb->cb_mcast.mc_size == 0) {
460 1.1 jkunz /* Can't do exact mcast filtering, do ALLMULTI mode. */
461 1.1 jkunz ifp->if_flags |= IFF_ALLMULTI;
462 1.1 jkunz sc->sc_cf[11] &= ~IEE_CF_11_MCALL;
463 1.1 jkunz } else {
464 1.1 jkunz /* disable ALLMULTI and load mcast list */
465 1.1 jkunz ifp->if_flags &= ~IFF_ALLMULTI;
466 1.1 jkunz sc->sc_cf[11] |= IEE_CF_11_MCALL;
467 1.1 jkunz /* Mcast setup may need more then IEE_CB_SZ bytes. */
468 1.8 perry bus_dmamap_sync(sc->sc_dmat, sc->sc_shmem_map,
469 1.8 perry IEE_CB_OFF, IEE_CB_LIST_SZ + IEE_TBD_LIST_SZ,
470 1.1 jkunz BUS_DMASYNC_PREWRITE);
471 1.1 jkunz }
472 1.1 jkunz iee_cb_setup(sc, IEE_CB_CMD_CONF);
473 1.1 jkunz break;
474 1.1 jkunz case IEE_CB_CMD_TR: /* Transmit */
475 1.1 jkunz cb->cb_transmit.tx_tbd_addr = IEE_PHYS_SHMEM(IEE_TBD_OFF
476 1.1 jkunz + IEE_TBD_SZ * sc->sc_next_tbd);
477 1.12 skrll cb->cb_cmd |= IEE_CB_SF; /* Always use Flexible Mode. */
478 1.1 jkunz break;
479 1.1 jkunz case IEE_CB_CMD_TDR: /* Time Domain Reflectometry */
480 1.1 jkunz break;
481 1.1 jkunz case IEE_CB_CMD_DUMP: /* Dump */
482 1.1 jkunz break;
483 1.1 jkunz case IEE_CB_CMD_DIAG: /* Diagnose */
484 1.1 jkunz break;
485 1.1 jkunz default:
486 1.1 jkunz /* can't happen */
487 1.1 jkunz break;
488 1.1 jkunz }
489 1.8 perry cb->cb_link_addr = IEE_PHYS_SHMEM(IEE_CB_OFF + IEE_CB_SZ *
490 1.1 jkunz (sc->sc_next_cb + 1));
491 1.8 perry bus_dmamap_sync(sc->sc_dmat, sc->sc_shmem_map, IEE_CB_OFF
492 1.1 jkunz + IEE_CB_SZ * sc->sc_next_cb, IEE_CB_SZ, BUS_DMASYNC_PREWRITE);
493 1.1 jkunz sc->sc_next_cb++;
494 1.1 jkunz ifp->if_timer = 5;
495 1.1 jkunz return;
496 1.1 jkunz }
497 1.1 jkunz
498 1.1 jkunz
499 1.1 jkunz
500 1.1 jkunz void
501 1.8 perry iee_attach(struct iee_softc *sc, uint8_t *eth_addr, int *media, int nmedia,
502 1.1 jkunz int defmedia)
503 1.1 jkunz {
504 1.1 jkunz struct ifnet *ifp = &sc->sc_ethercom.ec_if;
505 1.1 jkunz int n;
506 1.1 jkunz
507 1.1 jkunz /* Set pointer to Intermediate System Configuration Pointer. */
508 1.1 jkunz /* Phys. addr. in big endian order. (Big endian as defined by Intel.) */
509 1.1 jkunz SC_SCP->scp_iscp_addr = IEE_SWAP(IEE_PHYS_SHMEM(IEE_ISCP_OFF));
510 1.1 jkunz /* Set pointer to System Control Block. */
511 1.1 jkunz /* Phys. addr. in big endian order. (Big endian as defined by Intel.) */
512 1.1 jkunz SC_ISCP->iscp_scb_addr = IEE_SWAP(IEE_PHYS_SHMEM(IEE_SCB_OFF));
513 1.1 jkunz /* Set pointer to Receive Frame Area. (physical address) */
514 1.1 jkunz SC_SCB->scb_rfa_addr = IEE_PHYS_SHMEM(IEE_RFD_OFF);
515 1.1 jkunz /* Set pointer to Command Block. (physical address) */
516 1.1 jkunz SC_SCB->scb_cmd_blk_addr = IEE_PHYS_SHMEM(IEE_CB_OFF);
517 1.1 jkunz
518 1.1 jkunz ifmedia_init(&sc->sc_ifmedia, 0, iee_mediachange, iee_mediastatus);
519 1.1 jkunz if (media != NULL) {
520 1.1 jkunz for (n = 0 ; n < nmedia ; n++)
521 1.1 jkunz ifmedia_add(&sc->sc_ifmedia, media[n], 0, NULL);
522 1.1 jkunz ifmedia_set(&sc->sc_ifmedia, defmedia);
523 1.1 jkunz } else {
524 1.1 jkunz ifmedia_add(&sc->sc_ifmedia, IFM_ETHER | IFM_NONE, 0, NULL);
525 1.1 jkunz ifmedia_set(&sc->sc_ifmedia, IFM_ETHER | IFM_NONE);
526 1.1 jkunz }
527 1.1 jkunz
528 1.1 jkunz ifp->if_softc = sc;
529 1.1 jkunz strcpy(ifp->if_xname, sc->sc_dev.dv_xname);
530 1.1 jkunz ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
531 1.1 jkunz ifp->if_start = iee_start; /* initiate output routine */
532 1.1 jkunz ifp->if_ioctl = iee_ioctl; /* ioctl routine */
533 1.1 jkunz ifp->if_init = iee_init; /* init routine */
534 1.1 jkunz ifp->if_stop = iee_stop; /* stop routine */
535 1.1 jkunz ifp->if_watchdog = iee_watchdog; /* timer routine */
536 1.1 jkunz ifp->if_drain = iee_drain; /* routine to release resources */
537 1.1 jkunz IFQ_SET_READY(&ifp->if_snd);
538 1.1 jkunz /* iee supports IEEE 802.1Q Virtual LANs, see vlan(4). */
539 1.1 jkunz sc->sc_ethercom.ec_capabilities |= ETHERCAP_VLAN_MTU;
540 1.1 jkunz
541 1.1 jkunz if_attach(ifp);
542 1.1 jkunz ether_ifattach(ifp, eth_addr);
543 1.1 jkunz
544 1.1 jkunz aprint_normal(": Intel 82596%s address %s\n",
545 1.1 jkunz i82596_typenames[ sc->sc_type], ether_sprintf(eth_addr));
546 1.1 jkunz
547 1.1 jkunz for (n = 0 ; n < IEE_NCB ; n++)
548 1.1 jkunz sc->sc_tx_map[n] = NULL;
549 1.1 jkunz for (n = 0 ; n < IEE_NRFD ; n++) {
550 1.1 jkunz sc->sc_rx_mbuf[n] = NULL;
551 1.1 jkunz sc->sc_rx_map[n] = NULL;
552 1.1 jkunz }
553 1.1 jkunz sc->sc_tx_timeout = 0;
554 1.1 jkunz sc->sc_setup_timeout = 0;
555 1.1 jkunz (sc->sc_iee_reset)(sc);
556 1.1 jkunz return;
557 1.1 jkunz }
558 1.1 jkunz
559 1.1 jkunz
560 1.1 jkunz
561 1.1 jkunz void
562 1.1 jkunz iee_detach(struct iee_softc *sc, int flags)
563 1.1 jkunz {
564 1.1 jkunz struct ifnet *ifp = &sc->sc_ethercom.ec_if;
565 1.1 jkunz
566 1.1 jkunz if ((ifp->if_flags & IFF_RUNNING) != 0)
567 1.1 jkunz iee_stop(ifp, 1);
568 1.1 jkunz ether_ifdetach(ifp);
569 1.1 jkunz if_detach(ifp);
570 1.1 jkunz return;
571 1.1 jkunz }
572 1.1 jkunz
573 1.1 jkunz
574 1.1 jkunz
575 1.1 jkunz /* media change and status callback */
576 1.1 jkunz int
577 1.1 jkunz iee_mediachange(struct ifnet *ifp)
578 1.1 jkunz {
579 1.1 jkunz struct iee_softc *sc = ifp->if_softc;
580 1.8 perry
581 1.1 jkunz if (sc->sc_mediachange != NULL)
582 1.1 jkunz return ((sc->sc_mediachange)(ifp));
583 1.1 jkunz return(0);
584 1.1 jkunz }
585 1.1 jkunz
586 1.1 jkunz
587 1.1 jkunz
588 1.1 jkunz void
589 1.1 jkunz iee_mediastatus(struct ifnet *ifp, struct ifmediareq *ifmreq)
590 1.1 jkunz {
591 1.1 jkunz struct iee_softc *sc = ifp->if_softc;
592 1.1 jkunz
593 1.1 jkunz if (sc->sc_mediastatus != NULL)
594 1.1 jkunz return ((sc->sc_mediastatus)(ifp, ifmreq));
595 1.1 jkunz return;
596 1.1 jkunz }
597 1.1 jkunz
598 1.1 jkunz
599 1.1 jkunz
600 1.1 jkunz /* initiate output routine */
601 1.1 jkunz void
602 1.1 jkunz iee_start(struct ifnet *ifp)
603 1.1 jkunz {
604 1.1 jkunz struct iee_softc *sc = ifp->if_softc;
605 1.1 jkunz struct mbuf *m = NULL;
606 1.1 jkunz int t;
607 1.1 jkunz int n;
608 1.1 jkunz
609 1.1 jkunz if (sc->sc_next_cb != 0)
610 1.12 skrll /* There is already a CMD running. Defer packet enqueuing. */
611 1.1 jkunz return;
612 1.1 jkunz for (t = 0 ; t < IEE_NCB ; t++) {
613 1.1 jkunz IFQ_DEQUEUE(&ifp->if_snd, sc->sc_tx_mbuf[t]);
614 1.1 jkunz if (sc->sc_tx_mbuf[t] == NULL)
615 1.1 jkunz break;
616 1.1 jkunz if (bus_dmamap_load_mbuf(sc->sc_dmat, sc->sc_tx_map[t],
617 1.1 jkunz sc->sc_tx_mbuf[t], BUS_DMA_WRITE | BUS_DMA_NOWAIT) != 0) {
618 1.1 jkunz /*
619 1.8 perry * The packet needs more TBD then we support.
620 1.8 perry * Copy the packet into a mbuf cluster to get it out.
621 1.1 jkunz */
622 1.8 perry printf("%s: iee_start: failed to load DMA map\n",
623 1.1 jkunz sc->sc_dev.dv_xname);
624 1.1 jkunz MGETHDR(m, M_DONTWAIT, MT_DATA);
625 1.1 jkunz if (m == NULL) {
626 1.1 jkunz printf("%s: iee_start: can't allocate mbuf\n",
627 1.1 jkunz sc->sc_dev.dv_xname);
628 1.1 jkunz m_freem(sc->sc_tx_mbuf[t]);
629 1.1 jkunz t--;
630 1.1 jkunz continue;
631 1.1 jkunz }
632 1.1 jkunz MCLAIM(m, &sc->sc_ethercom.ec_rx_mowner);
633 1.1 jkunz MCLGET(m, M_DONTWAIT);
634 1.1 jkunz if ((m->m_flags & M_EXT) == 0) {
635 1.1 jkunz printf("%s: iee_start: can't allocate mbuf "
636 1.1 jkunz "cluster\n", sc->sc_dev.dv_xname);
637 1.1 jkunz m_freem(sc->sc_tx_mbuf[t]);
638 1.1 jkunz m_freem(m);
639 1.1 jkunz t--;
640 1.1 jkunz continue;
641 1.1 jkunz }
642 1.8 perry m_copydata(sc->sc_tx_mbuf[t], 0,
643 1.1 jkunz sc->sc_tx_mbuf[t]->m_pkthdr.len, mtod(m, caddr_t));
644 1.1 jkunz m->m_pkthdr.len = sc->sc_tx_mbuf[t]->m_pkthdr.len;
645 1.1 jkunz m->m_len = sc->sc_tx_mbuf[t]->m_pkthdr.len;
646 1.1 jkunz m_freem(sc->sc_tx_mbuf[t]);
647 1.1 jkunz sc->sc_tx_mbuf[t] = m;
648 1.1 jkunz if(bus_dmamap_load_mbuf(sc->sc_dmat, sc->sc_tx_map[t],
649 1.1 jkunz m, BUS_DMA_WRITE | BUS_DMA_NOWAIT) != 0) {
650 1.1 jkunz printf("%s: iee_start: can't load TX DMA map\n",
651 1.1 jkunz sc->sc_dev.dv_xname);
652 1.1 jkunz m_freem(sc->sc_tx_mbuf[t]);
653 1.1 jkunz t--;
654 1.1 jkunz continue;
655 1.1 jkunz }
656 1.1 jkunz }
657 1.1 jkunz for (n = 0 ; n < sc->sc_tx_map[t]->dm_nsegs ; n++) {
658 1.1 jkunz SC_TBD(sc->sc_next_tbd + n)->tbd_tb_addr =
659 1.1 jkunz sc->sc_tx_map[t]->dm_segs[n].ds_addr;
660 1.1 jkunz SC_TBD(sc->sc_next_tbd + n)->tbd_size =
661 1.1 jkunz sc->sc_tx_map[t]->dm_segs[n].ds_len;
662 1.1 jkunz SC_TBD(sc->sc_next_tbd + n)->tbd_link_addr =
663 1.8 perry IEE_PHYS_SHMEM(IEE_TBD_OFF + IEE_TBD_SZ
664 1.1 jkunz * (sc->sc_next_tbd + n + 1));
665 1.1 jkunz }
666 1.1 jkunz SC_TBD(sc->sc_next_tbd + n - 1)->tbd_size |= IEE_CB_EL;
667 1.1 jkunz bus_dmamap_sync(sc->sc_dmat, sc->sc_tx_map[t], 0,
668 1.1 jkunz sc->sc_tx_map[t]->dm_mapsize, BUS_DMASYNC_PREWRITE);
669 1.1 jkunz IFQ_POLL(&ifp->if_snd, m);
670 1.1 jkunz if (m == NULL)
671 1.1 jkunz iee_cb_setup(sc, IEE_CB_CMD_TR | IEE_CB_S | IEE_CB_EL
672 1.1 jkunz | IEE_CB_I);
673 1.1 jkunz else
674 1.1 jkunz iee_cb_setup(sc, IEE_CB_CMD_TR);
675 1.1 jkunz sc->sc_next_tbd += n;
676 1.1 jkunz #if NBPFILTER > 0
677 1.1 jkunz /* Pass packet to bpf if someone listens. */
678 1.1 jkunz if (ifp->if_bpf)
679 1.1 jkunz bpf_mtap(ifp->if_bpf, sc->sc_tx_mbuf[t]);
680 1.1 jkunz #endif
681 1.1 jkunz }
682 1.1 jkunz if (t == 0)
683 1.1 jkunz /* No packets got set up for TX. */
684 1.1 jkunz return;
685 1.1 jkunz if (t == IEE_NCB)
686 1.1 jkunz ifp->if_flags |= IFF_OACTIVE;
687 1.1 jkunz bus_dmamap_sync(sc->sc_dmat, sc->sc_shmem_map, IEE_CB_SZ,
688 1.1 jkunz IEE_CB_LIST_SZ + IEE_TBD_LIST_SZ, BUS_DMASYNC_PREWRITE);
689 1.1 jkunz (sc->sc_iee_cmd)(sc, IEE_SCB_CUC_EXE);
690 1.1 jkunz return;
691 1.1 jkunz }
692 1.1 jkunz
693 1.1 jkunz
694 1.1 jkunz
695 1.1 jkunz /* ioctl routine */
696 1.1 jkunz int
697 1.1 jkunz iee_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
698 1.1 jkunz {
699 1.1 jkunz struct iee_softc *sc = ifp->if_softc;
700 1.1 jkunz int s;
701 1.1 jkunz int err;
702 1.1 jkunz
703 1.1 jkunz s = splnet();
704 1.4 thorpej switch (cmd) {
705 1.4 thorpej case SIOCSIFMEDIA:
706 1.4 thorpej case SIOCGIFMEDIA:
707 1.4 thorpej err = ifmedia_ioctl(ifp, (struct ifreq *) data,
708 1.4 thorpej &sc->sc_ifmedia, cmd);
709 1.4 thorpej break;
710 1.4 thorpej
711 1.4 thorpej default:
712 1.1 jkunz err = ether_ioctl(ifp, cmd, data);
713 1.4 thorpej if (err == ENETRESET) {
714 1.4 thorpej /*
715 1.4 thorpej * Multicast list as changed; set the hardware filter
716 1.4 thorpej * accordingly.
717 1.4 thorpej */
718 1.4 thorpej if (ifp->if_flags & IFF_RUNNING) {
719 1.4 thorpej iee_cb_setup(sc, IEE_CB_CMD_MCS | IEE_CB_S |
720 1.4 thorpej IEE_CB_EL | IEE_CB_I);
721 1.4 thorpej if ((sc->sc_flags & IEE_WANT_MCAST) == 0)
722 1.4 thorpej (*sc->sc_iee_cmd)(sc, IEE_SCB_CUC_EXE);
723 1.4 thorpej }
724 1.3 thorpej err = 0;
725 1.4 thorpej }
726 1.4 thorpej break;
727 1.1 jkunz }
728 1.1 jkunz splx(s);
729 1.1 jkunz return(err);
730 1.1 jkunz }
731 1.1 jkunz
732 1.1 jkunz
733 1.1 jkunz
734 1.1 jkunz /* init routine */
735 1.1 jkunz int
736 1.1 jkunz iee_init(struct ifnet *ifp)
737 1.1 jkunz {
738 1.1 jkunz struct iee_softc *sc = ifp->if_softc;
739 1.1 jkunz int r;
740 1.1 jkunz int t;
741 1.1 jkunz int n;
742 1.1 jkunz int err;
743 1.1 jkunz
744 1.1 jkunz sc->sc_next_cb = 0;
745 1.1 jkunz sc->sc_next_tbd = 0;
746 1.1 jkunz sc->sc_flags &= ~IEE_WANT_MCAST;
747 1.1 jkunz sc->sc_rx_done = 0;
748 1.1 jkunz SC_SCB->scb_crc_err = 0;
749 1.1 jkunz SC_SCB->scb_align_err = 0;
750 1.1 jkunz SC_SCB->scb_resource_err = 0;
751 1.1 jkunz SC_SCB->scb_overrun_err = 0;
752 1.1 jkunz SC_SCB->scb_rcvcdt_err = 0;
753 1.1 jkunz SC_SCB->scb_short_fr_err = 0;
754 1.1 jkunz sc->sc_crc_err = 0;
755 1.1 jkunz sc->sc_align_err = 0;
756 1.1 jkunz sc->sc_resource_err = 0;
757 1.1 jkunz sc->sc_overrun_err = 0;
758 1.1 jkunz sc->sc_rcvcdt_err = 0;
759 1.1 jkunz sc->sc_short_fr_err = 0;
760 1.1 jkunz sc->sc_tx_col = 0;
761 1.1 jkunz sc->sc_rx_err = 0;
762 1.1 jkunz sc->sc_cmd_err = 0;
763 1.1 jkunz /* Create Transmit DMA maps. */
764 1.1 jkunz for (t = 0 ; t < IEE_NCB ; t++) {
765 1.1 jkunz if (sc->sc_tx_map[t] == NULL && bus_dmamap_create(sc->sc_dmat,
766 1.8 perry MCLBYTES, IEE_NTBD, MCLBYTES, 0, BUS_DMA_NOWAIT,
767 1.1 jkunz &sc->sc_tx_map[t]) != 0) {
768 1.8 perry printf("%s: iee_init: can't create TX DMA map\n",
769 1.1 jkunz sc->sc_dev.dv_xname);
770 1.1 jkunz for (n = 0 ; n < t ; n++)
771 1.8 perry bus_dmamap_destroy(sc->sc_dmat,
772 1.1 jkunz sc->sc_tx_map[n]);
773 1.1 jkunz return(ENOBUFS);
774 1.1 jkunz }
775 1.1 jkunz }
776 1.1 jkunz /* Initialize Receive Frame and Receive Buffer Descriptors */
777 1.1 jkunz err = 0;
778 1.1 jkunz memset(SC_RFD(0), 0, IEE_RFD_LIST_SZ);
779 1.1 jkunz memset(SC_RBD(0), 0, IEE_RBD_LIST_SZ);
780 1.1 jkunz for (r = 0 ; r < IEE_NRFD ; r++) {
781 1.1 jkunz SC_RFD(r)->rfd_cmd = IEE_RFD_SF;
782 1.1 jkunz SC_RFD(r)->rfd_link_addr = IEE_PHYS_SHMEM(IEE_RFD_OFF
783 1.1 jkunz + IEE_RFD_SZ * ((r + 1) % IEE_NRFD));
784 1.1 jkunz
785 1.8 perry SC_RBD(r)->rbd_next_rbd = IEE_PHYS_SHMEM(IEE_RBD_OFF
786 1.1 jkunz + IEE_RBD_SZ * ((r + 1) % IEE_NRFD));
787 1.1 jkunz if (sc->sc_rx_mbuf[r] == NULL) {
788 1.1 jkunz MGETHDR(sc->sc_rx_mbuf[r], M_DONTWAIT, MT_DATA);
789 1.1 jkunz if (sc->sc_rx_mbuf[r] == NULL) {
790 1.8 perry printf("%s: iee_init: can't allocate mbuf\n",
791 1.1 jkunz sc->sc_dev.dv_xname);
792 1.1 jkunz err = 1;
793 1.1 jkunz break;
794 1.1 jkunz }
795 1.1 jkunz MCLAIM(sc->sc_rx_mbuf[r],&sc->sc_ethercom.ec_rx_mowner);
796 1.1 jkunz MCLGET(sc->sc_rx_mbuf[r], M_DONTWAIT);
797 1.1 jkunz if ((sc->sc_rx_mbuf[r]->m_flags & M_EXT) == 0) {
798 1.1 jkunz printf("%s: iee_init: can't allocate mbuf"
799 1.1 jkunz " cluster\n", sc->sc_dev.dv_xname);
800 1.1 jkunz m_freem(sc->sc_rx_mbuf[r]);
801 1.1 jkunz err = 1;
802 1.1 jkunz break;
803 1.1 jkunz }
804 1.1 jkunz }
805 1.1 jkunz if (sc->sc_rx_map[r] == NULL && bus_dmamap_create(sc->sc_dmat,
806 1.8 perry MCLBYTES, 1, MCLBYTES , 0, BUS_DMA_NOWAIT,
807 1.1 jkunz &sc->sc_rx_map[r]) != 0) {
808 1.1 jkunz printf("%s: iee_init: can't create RX "
809 1.1 jkunz "DMA map\n", sc->sc_dev.dv_xname);
810 1.1 jkunz m_freem(sc->sc_rx_mbuf[r]);
811 1.1 jkunz err = 1;
812 1.1 jkunz break;
813 1.1 jkunz }
814 1.1 jkunz if (bus_dmamap_load(sc->sc_dmat, sc->sc_rx_map[r],
815 1.8 perry sc->sc_rx_mbuf[r]->m_ext.ext_buf,
816 1.1 jkunz sc->sc_rx_mbuf[r]->m_ext.ext_size, NULL,
817 1.1 jkunz BUS_DMA_READ | BUS_DMA_NOWAIT) != 0) {
818 1.1 jkunz printf("%s: iee_init: can't load RX DMA map\n",
819 1.1 jkunz sc->sc_dev.dv_xname);
820 1.1 jkunz bus_dmamap_destroy(sc->sc_dmat, sc->sc_rx_map[r]);
821 1.1 jkunz m_freem(sc->sc_rx_mbuf[r]);
822 1.1 jkunz err = 1;
823 1.1 jkunz break;
824 1.1 jkunz }
825 1.1 jkunz bus_dmamap_sync(sc->sc_dmat, sc->sc_rx_map[r], 0,
826 1.1 jkunz sc->sc_rx_mbuf[r]->m_ext.ext_size, BUS_DMASYNC_PREREAD);
827 1.1 jkunz SC_RBD(r)->rbd_size = sc->sc_rx_map[r]->dm_segs[0].ds_len;
828 1.1 jkunz SC_RBD(r)->rbd_rb_addr= sc->sc_rx_map[r]->dm_segs[0].ds_addr;
829 1.1 jkunz }
830 1.1 jkunz SC_RFD(0)->rfd_rbd_addr = IEE_PHYS_SHMEM(IEE_RBD_OFF);
831 1.1 jkunz if (err != 0) {
832 1.1 jkunz for (n = 0 ; n < r; n++) {
833 1.1 jkunz m_freem(sc->sc_rx_mbuf[n]);
834 1.1 jkunz sc->sc_rx_mbuf[n] = NULL;
835 1.1 jkunz bus_dmamap_unload(sc->sc_dmat, sc->sc_rx_map[n]);
836 1.1 jkunz bus_dmamap_destroy(sc->sc_dmat, sc->sc_rx_map[n]);
837 1.1 jkunz sc->sc_rx_map[n] = NULL;
838 1.1 jkunz }
839 1.1 jkunz for (n = 0 ; n < t ; n++) {
840 1.1 jkunz bus_dmamap_destroy(sc->sc_dmat, sc->sc_tx_map[n]);
841 1.1 jkunz sc->sc_tx_map[n] = NULL;
842 1.1 jkunz }
843 1.1 jkunz return(ENOBUFS);
844 1.1 jkunz }
845 1.1 jkunz
846 1.1 jkunz (sc->sc_iee_reset)(sc);
847 1.1 jkunz iee_cb_setup(sc, IEE_CB_CMD_IAS);
848 1.1 jkunz sc->sc_cf[0] = IEE_CF_0_DEF | IEE_CF_0_PREF;
849 1.1 jkunz sc->sc_cf[1] = IEE_CF_1_DEF;
850 1.1 jkunz sc->sc_cf[2] = IEE_CF_2_DEF;
851 1.8 perry sc->sc_cf[3] = IEE_CF_3_ADDRLEN_DEF | IEE_CF_3_NSAI
852 1.1 jkunz | IEE_CF_3_PREAMLEN_DEF;
853 1.1 jkunz sc->sc_cf[4] = IEE_CF_4_DEF;
854 1.1 jkunz sc->sc_cf[5] = IEE_CF_5_DEF;
855 1.1 jkunz sc->sc_cf[6] = IEE_CF_6_DEF;
856 1.1 jkunz sc->sc_cf[7] = IEE_CF_7_DEF;
857 1.1 jkunz sc->sc_cf[8] = IEE_CF_8_DEF;
858 1.1 jkunz sc->sc_cf[9] = IEE_CF_9_DEF;
859 1.1 jkunz sc->sc_cf[10] = IEE_CF_10_DEF;
860 1.1 jkunz sc->sc_cf[11] = IEE_CF_11_DEF & ~IEE_CF_11_LNGFLD;
861 1.1 jkunz sc->sc_cf[12] = IEE_CF_12_DEF;
862 1.1 jkunz sc->sc_cf[13] = IEE_CF_13_DEF;
863 1.1 jkunz iee_cb_setup(sc, IEE_CB_CMD_CONF | IEE_CB_S | IEE_CB_EL);
864 1.1 jkunz SC_SCB->scb_rfa_addr = IEE_PHYS_SHMEM(IEE_RFD_OFF);
865 1.1 jkunz bus_dmamap_sync(sc->sc_dmat, sc->sc_shmem_map, 0, IEE_SHMEM_MAX,
866 1.1 jkunz BUS_DMASYNC_PREWRITE);
867 1.1 jkunz (sc->sc_iee_cmd)(sc, IEE_SCB_CUC_EXE | IEE_SCB_RUC_ST);
868 1.1 jkunz /* Issue a Channel Attention to ACK interrupts we may have caused. */
869 1.1 jkunz (sc->sc_iee_cmd)(sc, IEE_SCB_ACK);
870 1.1 jkunz
871 1.1 jkunz /* Mark the interface as running and ready to RX/TX packets. */
872 1.1 jkunz ifp->if_flags |= IFF_RUNNING;
873 1.1 jkunz ifp->if_flags &= ~IFF_OACTIVE;
874 1.1 jkunz return(0);
875 1.1 jkunz }
876 1.1 jkunz
877 1.1 jkunz
878 1.1 jkunz
879 1.1 jkunz /* stop routine */
880 1.1 jkunz void
881 1.1 jkunz iee_stop(struct ifnet *ifp, int disable)
882 1.1 jkunz {
883 1.1 jkunz struct iee_softc *sc = ifp->if_softc;
884 1.1 jkunz int n;
885 1.1 jkunz
886 1.1 jkunz ifp->if_flags &= ~IFF_RUNNING;
887 1.1 jkunz ifp->if_flags |= IFF_OACTIVE;
888 1.1 jkunz ifp->if_timer = 0;
889 1.1 jkunz /* Reset the chip to get it quiet. */
890 1.1 jkunz (sc->sc_iee_reset)(ifp->if_softc);
891 1.1 jkunz /* Issue a Channel Attention to ACK interrupts we may have caused. */
892 1.1 jkunz (sc->sc_iee_cmd)(ifp->if_softc, IEE_SCB_ACK);
893 1.12 skrll /* Release any dynamically allocated resources. */
894 1.1 jkunz for (n = 0 ; n < IEE_NCB ; n++) {
895 1.1 jkunz if (sc->sc_tx_map[n] != NULL)
896 1.1 jkunz bus_dmamap_destroy(sc->sc_dmat, sc->sc_tx_map[n]);
897 1.1 jkunz sc->sc_tx_map[n] = NULL;
898 1.1 jkunz }
899 1.1 jkunz for (n = 0 ; n < IEE_NRFD ; n++) {
900 1.1 jkunz if (sc->sc_rx_mbuf[n] != NULL)
901 1.1 jkunz m_freem(sc->sc_rx_mbuf[n]);
902 1.1 jkunz sc->sc_rx_mbuf[n] = NULL;
903 1.1 jkunz if (sc->sc_rx_map[n] != NULL) {
904 1.1 jkunz bus_dmamap_unload(sc->sc_dmat, sc->sc_rx_map[n]);
905 1.1 jkunz bus_dmamap_destroy(sc->sc_dmat, sc->sc_rx_map[n]);
906 1.1 jkunz }
907 1.1 jkunz sc->sc_rx_map[n] = NULL;
908 1.1 jkunz }
909 1.1 jkunz return;
910 1.1 jkunz }
911 1.1 jkunz
912 1.1 jkunz
913 1.1 jkunz
914 1.1 jkunz /* timer routine */
915 1.1 jkunz void
916 1.1 jkunz iee_watchdog(struct ifnet *ifp)
917 1.1 jkunz {
918 1.1 jkunz struct iee_softc *sc = ifp->if_softc;
919 1.1 jkunz
920 1.1 jkunz (sc->sc_iee_reset)(sc);
921 1.1 jkunz if (sc->sc_next_tbd != 0)
922 1.8 perry printf("%s: iee_watchdog: transmit timeout %d\n",
923 1.1 jkunz sc->sc_dev.dv_xname, ++sc->sc_tx_timeout);
924 1.1 jkunz else
925 1.8 perry printf("%s: iee_watchdog: setup timeout %d\n",
926 1.1 jkunz sc->sc_dev.dv_xname, ++sc->sc_setup_timeout);
927 1.1 jkunz iee_init(ifp);
928 1.1 jkunz return;
929 1.1 jkunz }
930 1.1 jkunz
931 1.1 jkunz
932 1.1 jkunz
933 1.1 jkunz /* routine to release res. */
934 1.1 jkunz void
935 1.1 jkunz iee_drain(struct ifnet *ifp)
936 1.1 jkunz {
937 1.1 jkunz iee_stop(ifp, 0);
938 1.1 jkunz return;
939 1.1 jkunz }
940