if_msk.c revision 1.10.12.2 1 1.10.12.2 dsl /* $NetBSD: if_msk.c,v 1.10.12.2 2007/07/19 22:04:23 dsl Exp $ */
2 1.10.12.2 dsl /* $OpenBSD: if_msk.c,v 1.42 2007/01/17 02:43:02 krw Exp $ */
3 1.10.12.2 dsl
4 1.10.12.2 dsl /*
5 1.10.12.2 dsl * Copyright (c) 1997, 1998, 1999, 2000
6 1.10.12.2 dsl * Bill Paul <wpaul (at) ctr.columbia.edu>. All rights reserved.
7 1.10.12.2 dsl *
8 1.10.12.2 dsl * Redistribution and use in source and binary forms, with or without
9 1.10.12.2 dsl * modification, are permitted provided that the following conditions
10 1.10.12.2 dsl * are met:
11 1.10.12.2 dsl * 1. Redistributions of source code must retain the above copyright
12 1.10.12.2 dsl * notice, this list of conditions and the following disclaimer.
13 1.10.12.2 dsl * 2. Redistributions in binary form must reproduce the above copyright
14 1.10.12.2 dsl * notice, this list of conditions and the following disclaimer in the
15 1.10.12.2 dsl * documentation and/or other materials provided with the distribution.
16 1.10.12.2 dsl * 3. All advertising materials mentioning features or use of this software
17 1.10.12.2 dsl * must display the following acknowledgement:
18 1.10.12.2 dsl * This product includes software developed by Bill Paul.
19 1.10.12.2 dsl * 4. Neither the name of the author nor the names of any co-contributors
20 1.10.12.2 dsl * may be used to endorse or promote products derived from this software
21 1.10.12.2 dsl * without specific prior written permission.
22 1.10.12.2 dsl *
23 1.10.12.2 dsl * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND
24 1.10.12.2 dsl * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 1.10.12.2 dsl * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 1.10.12.2 dsl * ARE DISCLAIMED. IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD
27 1.10.12.2 dsl * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28 1.10.12.2 dsl * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29 1.10.12.2 dsl * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30 1.10.12.2 dsl * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31 1.10.12.2 dsl * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32 1.10.12.2 dsl * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
33 1.10.12.2 dsl * THE POSSIBILITY OF SUCH DAMAGE.
34 1.10.12.2 dsl *
35 1.10.12.2 dsl * $FreeBSD: /c/ncvs/src/sys/pci/if_sk.c,v 1.20 2000/04/22 02:16:37 wpaul Exp $
36 1.10.12.2 dsl */
37 1.10.12.2 dsl
38 1.10.12.2 dsl /*
39 1.10.12.2 dsl * Copyright (c) 2003 Nathan L. Binkert <binkertn (at) umich.edu>
40 1.10.12.2 dsl *
41 1.10.12.2 dsl * Permission to use, copy, modify, and distribute this software for any
42 1.10.12.2 dsl * purpose with or without fee is hereby granted, provided that the above
43 1.10.12.2 dsl * copyright notice and this permission notice appear in all copies.
44 1.10.12.2 dsl *
45 1.10.12.2 dsl * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
46 1.10.12.2 dsl * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
47 1.10.12.2 dsl * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
48 1.10.12.2 dsl * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
49 1.10.12.2 dsl * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
50 1.10.12.2 dsl * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
51 1.10.12.2 dsl * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
52 1.10.12.2 dsl */
53 1.10.12.2 dsl
54 1.10.12.2 dsl #include <sys/cdefs.h>
55 1.10.12.2 dsl
56 1.10.12.2 dsl #include "bpfilter.h"
57 1.10.12.2 dsl #include "rnd.h"
58 1.10.12.2 dsl
59 1.10.12.2 dsl #include <sys/param.h>
60 1.10.12.2 dsl #include <sys/systm.h>
61 1.10.12.2 dsl #include <sys/sockio.h>
62 1.10.12.2 dsl #include <sys/mbuf.h>
63 1.10.12.2 dsl #include <sys/malloc.h>
64 1.10.12.2 dsl #include <sys/kernel.h>
65 1.10.12.2 dsl #include <sys/socket.h>
66 1.10.12.2 dsl #include <sys/device.h>
67 1.10.12.2 dsl #include <sys/queue.h>
68 1.10.12.2 dsl #include <sys/callout.h>
69 1.10.12.2 dsl #include <sys/sysctl.h>
70 1.10.12.2 dsl #include <sys/endian.h>
71 1.10.12.2 dsl #ifdef __NetBSD__
72 1.10.12.2 dsl #define letoh16 htole16
73 1.10.12.2 dsl #define letoh32 htole32
74 1.10.12.2 dsl #endif
75 1.10.12.2 dsl
76 1.10.12.2 dsl #include <net/if.h>
77 1.10.12.2 dsl #include <net/if_dl.h>
78 1.10.12.2 dsl #include <net/if_types.h>
79 1.10.12.2 dsl
80 1.10.12.2 dsl #include <net/if_media.h>
81 1.10.12.2 dsl
82 1.10.12.2 dsl #if NBPFILTER > 0
83 1.10.12.2 dsl #include <net/bpf.h>
84 1.10.12.2 dsl #endif
85 1.10.12.2 dsl #if NRND > 0
86 1.10.12.2 dsl #include <sys/rnd.h>
87 1.10.12.2 dsl #endif
88 1.10.12.2 dsl
89 1.10.12.2 dsl #include <dev/mii/mii.h>
90 1.10.12.2 dsl #include <dev/mii/miivar.h>
91 1.10.12.2 dsl #include <dev/mii/brgphyreg.h>
92 1.10.12.2 dsl
93 1.10.12.2 dsl #include <dev/pci/pcireg.h>
94 1.10.12.2 dsl #include <dev/pci/pcivar.h>
95 1.10.12.2 dsl #include <dev/pci/pcidevs.h>
96 1.10.12.2 dsl
97 1.10.12.2 dsl #include <dev/pci/if_skreg.h>
98 1.10.12.2 dsl #include <dev/pci/if_mskvar.h>
99 1.10.12.2 dsl
100 1.10.12.2 dsl int mskc_probe(struct device *, struct cfdata *, void *);
101 1.10.12.2 dsl void mskc_attach(struct device *, struct device *self, void *aux);
102 1.10.12.2 dsl void mskc_shutdown(void *);
103 1.10.12.2 dsl int msk_probe(struct device *, struct cfdata *, void *);
104 1.10.12.2 dsl void msk_attach(struct device *, struct device *self, void *aux);
105 1.10.12.2 dsl int mskcprint(void *, const char *);
106 1.10.12.2 dsl int msk_intr(void *);
107 1.10.12.2 dsl void msk_intr_yukon(struct sk_if_softc *);
108 1.10.12.2 dsl __inline int msk_rxvalid(struct sk_softc *, u_int32_t, u_int32_t);
109 1.10.12.2 dsl void msk_rxeof(struct sk_if_softc *, u_int16_t, u_int32_t);
110 1.10.12.2 dsl void msk_txeof(struct sk_if_softc *, int);
111 1.10.12.2 dsl int msk_encap(struct sk_if_softc *, struct mbuf *, u_int32_t *);
112 1.10.12.2 dsl void msk_start(struct ifnet *);
113 1.10.12.2 dsl int msk_ioctl(struct ifnet *, u_long, void *);
114 1.10.12.2 dsl int msk_init(struct ifnet *);
115 1.10.12.2 dsl void msk_init_yukon(struct sk_if_softc *);
116 1.10.12.2 dsl void msk_stop(struct ifnet *, int);
117 1.10.12.2 dsl void msk_watchdog(struct ifnet *);
118 1.10.12.2 dsl int msk_ifmedia_upd(struct ifnet *);
119 1.10.12.2 dsl void msk_ifmedia_sts(struct ifnet *, struct ifmediareq *);
120 1.10.12.2 dsl void msk_reset(struct sk_softc *);
121 1.10.12.2 dsl int msk_newbuf(struct sk_if_softc *, int, struct mbuf *, bus_dmamap_t);
122 1.10.12.2 dsl int msk_alloc_jumbo_mem(struct sk_if_softc *);
123 1.10.12.2 dsl void *msk_jalloc(struct sk_if_softc *);
124 1.10.12.2 dsl void msk_jfree(struct mbuf *, void *, size_t, void *);
125 1.10.12.2 dsl int msk_init_rx_ring(struct sk_if_softc *);
126 1.10.12.2 dsl int msk_init_tx_ring(struct sk_if_softc *);
127 1.10.12.2 dsl
128 1.10.12.2 dsl void msk_update_int_mod(struct sk_softc *);
129 1.10.12.2 dsl
130 1.10.12.2 dsl int msk_miibus_readreg(struct device *, int, int);
131 1.10.12.2 dsl void msk_miibus_writereg(struct device *, int, int, int);
132 1.10.12.2 dsl void msk_miibus_statchg(struct device *);
133 1.10.12.2 dsl
134 1.10.12.2 dsl void msk_setfilt(struct sk_if_softc *, void *, int);
135 1.10.12.2 dsl void msk_setmulti(struct sk_if_softc *);
136 1.10.12.2 dsl void msk_setpromisc(struct sk_if_softc *);
137 1.10.12.2 dsl void msk_tick(void *);
138 1.10.12.2 dsl
139 1.10.12.2 dsl /* #define MSK_DEBUG 1 */
140 1.10.12.2 dsl #ifdef MSK_DEBUG
141 1.10.12.2 dsl #define DPRINTF(x) if (mskdebug) printf x
142 1.10.12.2 dsl #define DPRINTFN(n,x) if (mskdebug >= (n)) printf x
143 1.10.12.2 dsl int mskdebug = MSK_DEBUG;
144 1.10.12.2 dsl
145 1.10.12.2 dsl void msk_dump_txdesc(struct msk_tx_desc *, int);
146 1.10.12.2 dsl void msk_dump_mbuf(struct mbuf *);
147 1.10.12.2 dsl void msk_dump_bytes(const char *, int);
148 1.10.12.2 dsl #else
149 1.10.12.2 dsl #define DPRINTF(x)
150 1.10.12.2 dsl #define DPRINTFN(n,x)
151 1.10.12.2 dsl #endif
152 1.10.12.2 dsl
153 1.10.12.2 dsl static int msk_sysctl_handler(SYSCTLFN_PROTO);
154 1.10.12.2 dsl static int msk_root_num;
155 1.10.12.2 dsl
156 1.10.12.2 dsl /* supported device vendors */
157 1.10.12.2 dsl static const struct msk_product {
158 1.10.12.2 dsl pci_vendor_id_t msk_vendor;
159 1.10.12.2 dsl pci_product_id_t msk_product;
160 1.10.12.2 dsl } msk_products[] = {
161 1.10.12.2 dsl { PCI_VENDOR_DLINK, PCI_PRODUCT_DLINK_DGE550SX },
162 1.10.12.2 dsl { PCI_VENDOR_DLINK, PCI_PRODUCT_DLINK_DGE560SX },
163 1.10.12.2 dsl { PCI_VENDOR_DLINK, PCI_PRODUCT_DLINK_DGE560T },
164 1.10.12.2 dsl { PCI_VENDOR_MARVELL, PCI_PRODUCT_MARVELL_YUKON_1 },
165 1.10.12.2 dsl { PCI_VENDOR_MARVELL, PCI_PRODUCT_MARVELL_YUKON_C032 },
166 1.10.12.2 dsl { PCI_VENDOR_MARVELL, PCI_PRODUCT_MARVELL_YUKON_C033 },
167 1.10.12.2 dsl { PCI_VENDOR_MARVELL, PCI_PRODUCT_MARVELL_YUKON_C034 },
168 1.10.12.2 dsl { PCI_VENDOR_MARVELL, PCI_PRODUCT_MARVELL_YUKON_C036 },
169 1.10.12.2 dsl { PCI_VENDOR_MARVELL, PCI_PRODUCT_MARVELL_YUKON_C042 },
170 1.10.12.2 dsl { PCI_VENDOR_MARVELL, PCI_PRODUCT_MARVELL_YUKON_8035 },
171 1.10.12.2 dsl { PCI_VENDOR_MARVELL, PCI_PRODUCT_MARVELL_YUKON_8036 },
172 1.10.12.2 dsl { PCI_VENDOR_MARVELL, PCI_PRODUCT_MARVELL_YUKON_8038 },
173 1.10.12.2 dsl { PCI_VENDOR_MARVELL, PCI_PRODUCT_MARVELL_YUKON_8039 },
174 1.10.12.2 dsl { PCI_VENDOR_MARVELL, PCI_PRODUCT_MARVELL_YUKON_8050 },
175 1.10.12.2 dsl { PCI_VENDOR_MARVELL, PCI_PRODUCT_MARVELL_YUKON_8052 },
176 1.10.12.2 dsl { PCI_VENDOR_MARVELL, PCI_PRODUCT_MARVELL_YUKON_8053 },
177 1.10.12.2 dsl { PCI_VENDOR_MARVELL, PCI_PRODUCT_MARVELL_YUKON_8055 },
178 1.10.12.2 dsl { PCI_VENDOR_MARVELL, PCI_PRODUCT_MARVELL_YUKON_8056 },
179 1.10.12.2 dsl { PCI_VENDOR_MARVELL, PCI_PRODUCT_MARVELL_YUKONII_8021CU },
180 1.10.12.2 dsl { PCI_VENDOR_MARVELL, PCI_PRODUCT_MARVELL_YUKONII_8021X },
181 1.10.12.2 dsl { PCI_VENDOR_MARVELL, PCI_PRODUCT_MARVELL_YUKONII_8022CU },
182 1.10.12.2 dsl { PCI_VENDOR_MARVELL, PCI_PRODUCT_MARVELL_YUKONII_8022X },
183 1.10.12.2 dsl { PCI_VENDOR_MARVELL, PCI_PRODUCT_MARVELL_YUKONII_8061CU },
184 1.10.12.2 dsl { PCI_VENDOR_MARVELL, PCI_PRODUCT_MARVELL_YUKONII_8061X },
185 1.10.12.2 dsl { PCI_VENDOR_MARVELL, PCI_PRODUCT_MARVELL_YUKONII_8062CU },
186 1.10.12.2 dsl { PCI_VENDOR_MARVELL, PCI_PRODUCT_MARVELL_YUKONII_8062X },
187 1.10.12.2 dsl { PCI_VENDOR_SCHNEIDERKOCH, PCI_PRODUCT_SCHNEIDERKOCH_SK_9SXX },
188 1.10.12.2 dsl { PCI_VENDOR_SCHNEIDERKOCH, PCI_PRODUCT_SCHNEIDERKOCH_SK_9E21 }
189 1.10.12.2 dsl };
190 1.10.12.2 dsl
191 1.10.12.2 dsl static inline u_int32_t
192 1.10.12.2 dsl sk_win_read_4(struct sk_softc *sc, u_int32_t reg)
193 1.10.12.2 dsl {
194 1.10.12.2 dsl return CSR_READ_4(sc, reg);
195 1.10.12.2 dsl }
196 1.10.12.2 dsl
197 1.10.12.2 dsl static inline u_int16_t
198 1.10.12.2 dsl sk_win_read_2(struct sk_softc *sc, u_int32_t reg)
199 1.10.12.2 dsl {
200 1.10.12.2 dsl return CSR_READ_2(sc, reg);
201 1.10.12.2 dsl }
202 1.10.12.2 dsl
203 1.10.12.2 dsl static inline u_int8_t
204 1.10.12.2 dsl sk_win_read_1(struct sk_softc *sc, u_int32_t reg)
205 1.10.12.2 dsl {
206 1.10.12.2 dsl return CSR_READ_1(sc, reg);
207 1.10.12.2 dsl }
208 1.10.12.2 dsl
209 1.10.12.2 dsl static inline void
210 1.10.12.2 dsl sk_win_write_4(struct sk_softc *sc, u_int32_t reg, u_int32_t x)
211 1.10.12.2 dsl {
212 1.10.12.2 dsl CSR_WRITE_4(sc, reg, x);
213 1.10.12.2 dsl }
214 1.10.12.2 dsl
215 1.10.12.2 dsl static inline void
216 1.10.12.2 dsl sk_win_write_2(struct sk_softc *sc, u_int32_t reg, u_int16_t x)
217 1.10.12.2 dsl {
218 1.10.12.2 dsl CSR_WRITE_2(sc, reg, x);
219 1.10.12.2 dsl }
220 1.10.12.2 dsl
221 1.10.12.2 dsl static inline void
222 1.10.12.2 dsl sk_win_write_1(struct sk_softc *sc, u_int32_t reg, u_int8_t x)
223 1.10.12.2 dsl {
224 1.10.12.2 dsl CSR_WRITE_1(sc, reg, x);
225 1.10.12.2 dsl }
226 1.10.12.2 dsl
227 1.10.12.2 dsl int
228 1.10.12.2 dsl msk_miibus_readreg(struct device *dev, int phy, int reg)
229 1.10.12.2 dsl {
230 1.10.12.2 dsl struct sk_if_softc *sc_if = (struct sk_if_softc *)dev;
231 1.10.12.2 dsl u_int16_t val;
232 1.10.12.2 dsl int i;
233 1.10.12.2 dsl
234 1.10.12.2 dsl SK_YU_WRITE_2(sc_if, YUKON_SMICR, YU_SMICR_PHYAD(phy) |
235 1.10.12.2 dsl YU_SMICR_REGAD(reg) | YU_SMICR_OP_READ);
236 1.10.12.2 dsl
237 1.10.12.2 dsl for (i = 0; i < SK_TIMEOUT; i++) {
238 1.10.12.2 dsl DELAY(1);
239 1.10.12.2 dsl val = SK_YU_READ_2(sc_if, YUKON_SMICR);
240 1.10.12.2 dsl if (val & YU_SMICR_READ_VALID)
241 1.10.12.2 dsl break;
242 1.10.12.2 dsl }
243 1.10.12.2 dsl
244 1.10.12.2 dsl if (i == SK_TIMEOUT) {
245 1.10.12.2 dsl aprint_error("%s: phy failed to come ready\n",
246 1.10.12.2 dsl sc_if->sk_dev.dv_xname);
247 1.10.12.2 dsl return (0);
248 1.10.12.2 dsl }
249 1.10.12.2 dsl
250 1.10.12.2 dsl DPRINTFN(9, ("msk_miibus_readreg: i=%d, timeout=%d\n", i,
251 1.10.12.2 dsl SK_TIMEOUT));
252 1.10.12.2 dsl
253 1.10.12.2 dsl val = SK_YU_READ_2(sc_if, YUKON_SMIDR);
254 1.10.12.2 dsl
255 1.10.12.2 dsl DPRINTFN(9, ("msk_miibus_readreg phy=%d, reg=%#x, val=%#x\n",
256 1.10.12.2 dsl phy, reg, val));
257 1.10.12.2 dsl
258 1.10.12.2 dsl return (val);
259 1.10.12.2 dsl }
260 1.10.12.2 dsl
261 1.10.12.2 dsl void
262 1.10.12.2 dsl msk_miibus_writereg(struct device *dev, int phy, int reg, int val)
263 1.10.12.2 dsl {
264 1.10.12.2 dsl struct sk_if_softc *sc_if = (struct sk_if_softc *)dev;
265 1.10.12.2 dsl int i;
266 1.10.12.2 dsl
267 1.10.12.2 dsl DPRINTFN(9, ("msk_miibus_writereg phy=%d reg=%#x val=%#x\n",
268 1.10.12.2 dsl phy, reg, val));
269 1.10.12.2 dsl
270 1.10.12.2 dsl SK_YU_WRITE_2(sc_if, YUKON_SMIDR, val);
271 1.10.12.2 dsl SK_YU_WRITE_2(sc_if, YUKON_SMICR, YU_SMICR_PHYAD(phy) |
272 1.10.12.2 dsl YU_SMICR_REGAD(reg) | YU_SMICR_OP_WRITE);
273 1.10.12.2 dsl
274 1.10.12.2 dsl for (i = 0; i < SK_TIMEOUT; i++) {
275 1.10.12.2 dsl DELAY(1);
276 1.10.12.2 dsl if (!(SK_YU_READ_2(sc_if, YUKON_SMICR) & YU_SMICR_BUSY))
277 1.10.12.2 dsl break;
278 1.10.12.2 dsl }
279 1.10.12.2 dsl
280 1.10.12.2 dsl if (i == SK_TIMEOUT)
281 1.10.12.2 dsl aprint_error("%s: phy write timed out\n", sc_if->sk_dev.dv_xname);
282 1.10.12.2 dsl }
283 1.10.12.2 dsl
284 1.10.12.2 dsl void
285 1.10.12.2 dsl msk_miibus_statchg(struct device *dev)
286 1.10.12.2 dsl {
287 1.10.12.2 dsl struct sk_if_softc *sc_if = (struct sk_if_softc *)dev;
288 1.10.12.2 dsl struct mii_data *mii = &sc_if->sk_mii;
289 1.10.12.2 dsl struct ifmedia_entry *ife = mii->mii_media.ifm_cur;
290 1.10.12.2 dsl int gpcr;
291 1.10.12.2 dsl
292 1.10.12.2 dsl gpcr = SK_YU_READ_2(sc_if, YUKON_GPCR);
293 1.10.12.2 dsl gpcr &= (YU_GPCR_TXEN | YU_GPCR_RXEN);
294 1.10.12.2 dsl
295 1.10.12.2 dsl if (IFM_SUBTYPE(ife->ifm_media) != IFM_AUTO) {
296 1.10.12.2 dsl /* Set speed. */
297 1.10.12.2 dsl gpcr |= YU_GPCR_SPEED_DIS;
298 1.10.12.2 dsl switch (IFM_SUBTYPE(mii->mii_media_active)) {
299 1.10.12.2 dsl case IFM_1000_SX:
300 1.10.12.2 dsl case IFM_1000_LX:
301 1.10.12.2 dsl case IFM_1000_CX:
302 1.10.12.2 dsl case IFM_1000_T:
303 1.10.12.2 dsl gpcr |= (YU_GPCR_GIG | YU_GPCR_SPEED);
304 1.10.12.2 dsl break;
305 1.10.12.2 dsl case IFM_100_TX:
306 1.10.12.2 dsl gpcr |= YU_GPCR_SPEED;
307 1.10.12.2 dsl break;
308 1.10.12.2 dsl }
309 1.10.12.2 dsl
310 1.10.12.2 dsl /* Set duplex. */
311 1.10.12.2 dsl gpcr |= YU_GPCR_DPLX_DIS;
312 1.10.12.2 dsl if ((mii->mii_media_active & IFM_GMASK) == IFM_FDX)
313 1.10.12.2 dsl gpcr |= YU_GPCR_DUPLEX;
314 1.10.12.2 dsl
315 1.10.12.2 dsl /* Disable flow control. */
316 1.10.12.2 dsl gpcr |= YU_GPCR_FCTL_DIS;
317 1.10.12.2 dsl gpcr |= (YU_GPCR_FCTL_TX_DIS | YU_GPCR_FCTL_RX_DIS);
318 1.10.12.2 dsl }
319 1.10.12.2 dsl
320 1.10.12.2 dsl SK_YU_WRITE_2(sc_if, YUKON_GPCR, gpcr);
321 1.10.12.2 dsl
322 1.10.12.2 dsl DPRINTFN(9, ("msk_miibus_statchg: gpcr=%x\n",
323 1.10.12.2 dsl SK_YU_READ_2(((struct sk_if_softc *)dev), YUKON_GPCR)));
324 1.10.12.2 dsl }
325 1.10.12.2 dsl
326 1.10.12.2 dsl #define HASH_BITS 6
327 1.10.12.2 dsl
328 1.10.12.2 dsl void
329 1.10.12.2 dsl msk_setfilt(struct sk_if_softc *sc_if, void *addrv, int slot)
330 1.10.12.2 dsl {
331 1.10.12.2 dsl char *addr = addrv;
332 1.10.12.2 dsl int base = XM_RXFILT_ENTRY(slot);
333 1.10.12.2 dsl
334 1.10.12.2 dsl SK_XM_WRITE_2(sc_if, base, *(u_int16_t *)(&addr[0]));
335 1.10.12.2 dsl SK_XM_WRITE_2(sc_if, base + 2, *(u_int16_t *)(&addr[2]));
336 1.10.12.2 dsl SK_XM_WRITE_2(sc_if, base + 4, *(u_int16_t *)(&addr[4]));
337 1.10.12.2 dsl }
338 1.10.12.2 dsl
339 1.10.12.2 dsl void
340 1.10.12.2 dsl msk_setmulti(struct sk_if_softc *sc_if)
341 1.10.12.2 dsl {
342 1.10.12.2 dsl struct ifnet *ifp= &sc_if->sk_ethercom.ec_if;
343 1.10.12.2 dsl u_int32_t hashes[2] = { 0, 0 };
344 1.10.12.2 dsl int h;
345 1.10.12.2 dsl struct ethercom *ec = &sc_if->sk_ethercom;
346 1.10.12.2 dsl struct ether_multi *enm;
347 1.10.12.2 dsl struct ether_multistep step;
348 1.10.12.2 dsl u_int16_t reg;
349 1.10.12.2 dsl
350 1.10.12.2 dsl /* First, zot all the existing filters. */
351 1.10.12.2 dsl SK_YU_WRITE_2(sc_if, YUKON_MCAH1, 0);
352 1.10.12.2 dsl SK_YU_WRITE_2(sc_if, YUKON_MCAH2, 0);
353 1.10.12.2 dsl SK_YU_WRITE_2(sc_if, YUKON_MCAH3, 0);
354 1.10.12.2 dsl SK_YU_WRITE_2(sc_if, YUKON_MCAH4, 0);
355 1.10.12.2 dsl
356 1.10.12.2 dsl
357 1.10.12.2 dsl /* Now program new ones. */
358 1.10.12.2 dsl reg = SK_YU_READ_2(sc_if, YUKON_RCR);
359 1.10.12.2 dsl reg |= YU_RCR_UFLEN;
360 1.10.12.2 dsl allmulti:
361 1.10.12.2 dsl if (ifp->if_flags & IFF_ALLMULTI || ifp->if_flags & IFF_PROMISC) {
362 1.10.12.2 dsl if ((ifp->if_flags & IFF_PROMISC) != 0)
363 1.10.12.2 dsl reg &= ~(YU_RCR_UFLEN | YU_RCR_MUFLEN);
364 1.10.12.2 dsl else if ((ifp->if_flags & IFF_ALLMULTI) != 0) {
365 1.10.12.2 dsl hashes[0] = 0xFFFFFFFF;
366 1.10.12.2 dsl hashes[1] = 0xFFFFFFFF;
367 1.10.12.2 dsl }
368 1.10.12.2 dsl } else {
369 1.10.12.2 dsl /* First find the tail of the list. */
370 1.10.12.2 dsl ETHER_FIRST_MULTI(step, ec, enm);
371 1.10.12.2 dsl while (enm != NULL) {
372 1.10.12.2 dsl if (bcmp(enm->enm_addrlo, enm->enm_addrhi,
373 1.10.12.2 dsl ETHER_ADDR_LEN)) {
374 1.10.12.2 dsl ifp->if_flags |= IFF_ALLMULTI;
375 1.10.12.2 dsl goto allmulti;
376 1.10.12.2 dsl }
377 1.10.12.2 dsl h = ether_crc32_be(enm->enm_addrlo, ETHER_ADDR_LEN) &
378 1.10.12.2 dsl ((1 << HASH_BITS) - 1);
379 1.10.12.2 dsl if (h < 32)
380 1.10.12.2 dsl hashes[0] |= (1 << h);
381 1.10.12.2 dsl else
382 1.10.12.2 dsl hashes[1] |= (1 << (h - 32));
383 1.10.12.2 dsl
384 1.10.12.2 dsl ETHER_NEXT_MULTI(step, enm);
385 1.10.12.2 dsl }
386 1.10.12.2 dsl reg |= YU_RCR_MUFLEN;
387 1.10.12.2 dsl }
388 1.10.12.2 dsl
389 1.10.12.2 dsl SK_YU_WRITE_2(sc_if, YUKON_MCAH1, hashes[0] & 0xffff);
390 1.10.12.2 dsl SK_YU_WRITE_2(sc_if, YUKON_MCAH2, (hashes[0] >> 16) & 0xffff);
391 1.10.12.2 dsl SK_YU_WRITE_2(sc_if, YUKON_MCAH3, hashes[1] & 0xffff);
392 1.10.12.2 dsl SK_YU_WRITE_2(sc_if, YUKON_MCAH4, (hashes[1] >> 16) & 0xffff);
393 1.10.12.2 dsl SK_YU_WRITE_2(sc_if, YUKON_RCR, reg);
394 1.10.12.2 dsl }
395 1.10.12.2 dsl
396 1.10.12.2 dsl void
397 1.10.12.2 dsl msk_setpromisc(struct sk_if_softc *sc_if)
398 1.10.12.2 dsl {
399 1.10.12.2 dsl struct ifnet *ifp = &sc_if->sk_ethercom.ec_if;
400 1.10.12.2 dsl
401 1.10.12.2 dsl if (ifp->if_flags & IFF_PROMISC)
402 1.10.12.2 dsl SK_YU_CLRBIT_2(sc_if, YUKON_RCR,
403 1.10.12.2 dsl YU_RCR_UFLEN | YU_RCR_MUFLEN);
404 1.10.12.2 dsl else
405 1.10.12.2 dsl SK_YU_SETBIT_2(sc_if, YUKON_RCR,
406 1.10.12.2 dsl YU_RCR_UFLEN | YU_RCR_MUFLEN);
407 1.10.12.2 dsl }
408 1.10.12.2 dsl
409 1.10.12.2 dsl int
410 1.10.12.2 dsl msk_init_rx_ring(struct sk_if_softc *sc_if)
411 1.10.12.2 dsl {
412 1.10.12.2 dsl struct msk_chain_data *cd = &sc_if->sk_cdata;
413 1.10.12.2 dsl struct msk_ring_data *rd = sc_if->sk_rdata;
414 1.10.12.2 dsl int i, nexti;
415 1.10.12.2 dsl
416 1.10.12.2 dsl bzero((char *)rd->sk_rx_ring,
417 1.10.12.2 dsl sizeof(struct msk_rx_desc) * MSK_RX_RING_CNT);
418 1.10.12.2 dsl
419 1.10.12.2 dsl for (i = 0; i < MSK_RX_RING_CNT; i++) {
420 1.10.12.2 dsl cd->sk_rx_chain[i].sk_le = &rd->sk_rx_ring[i];
421 1.10.12.2 dsl if (i == (MSK_RX_RING_CNT - 1))
422 1.10.12.2 dsl nexti = 0;
423 1.10.12.2 dsl else
424 1.10.12.2 dsl nexti = i + 1;
425 1.10.12.2 dsl cd->sk_rx_chain[i].sk_next = &cd->sk_rx_chain[nexti];
426 1.10.12.2 dsl }
427 1.10.12.2 dsl
428 1.10.12.2 dsl for (i = 0; i < MSK_RX_RING_CNT; i++) {
429 1.10.12.2 dsl if (msk_newbuf(sc_if, i, NULL,
430 1.10.12.2 dsl sc_if->sk_cdata.sk_rx_jumbo_map) == ENOBUFS) {
431 1.10.12.2 dsl aprint_error("%s: failed alloc of %dth mbuf\n",
432 1.10.12.2 dsl sc_if->sk_dev.dv_xname, i);
433 1.10.12.2 dsl return (ENOBUFS);
434 1.10.12.2 dsl }
435 1.10.12.2 dsl }
436 1.10.12.2 dsl
437 1.10.12.2 dsl sc_if->sk_cdata.sk_rx_prod = MSK_RX_RING_CNT - 1;
438 1.10.12.2 dsl sc_if->sk_cdata.sk_rx_cons = 0;
439 1.10.12.2 dsl
440 1.10.12.2 dsl return (0);
441 1.10.12.2 dsl }
442 1.10.12.2 dsl
443 1.10.12.2 dsl int
444 1.10.12.2 dsl msk_init_tx_ring(struct sk_if_softc *sc_if)
445 1.10.12.2 dsl {
446 1.10.12.2 dsl struct sk_softc *sc = sc_if->sk_softc;
447 1.10.12.2 dsl struct msk_chain_data *cd = &sc_if->sk_cdata;
448 1.10.12.2 dsl struct msk_ring_data *rd = sc_if->sk_rdata;
449 1.10.12.2 dsl bus_dmamap_t dmamap;
450 1.10.12.2 dsl struct sk_txmap_entry *entry;
451 1.10.12.2 dsl int i, nexti;
452 1.10.12.2 dsl
453 1.10.12.2 dsl bzero((char *)sc_if->sk_rdata->sk_tx_ring,
454 1.10.12.2 dsl sizeof(struct msk_tx_desc) * MSK_TX_RING_CNT);
455 1.10.12.2 dsl
456 1.10.12.2 dsl SIMPLEQ_INIT(&sc_if->sk_txmap_head);
457 1.10.12.2 dsl for (i = 0; i < MSK_TX_RING_CNT; i++) {
458 1.10.12.2 dsl cd->sk_tx_chain[i].sk_le = &rd->sk_tx_ring[i];
459 1.10.12.2 dsl if (i == (MSK_TX_RING_CNT - 1))
460 1.10.12.2 dsl nexti = 0;
461 1.10.12.2 dsl else
462 1.10.12.2 dsl nexti = i + 1;
463 1.10.12.2 dsl cd->sk_tx_chain[i].sk_next = &cd->sk_tx_chain[nexti];
464 1.10.12.2 dsl
465 1.10.12.2 dsl if (bus_dmamap_create(sc->sc_dmatag, SK_JLEN, SK_NTXSEG,
466 1.10.12.2 dsl SK_JLEN, 0, BUS_DMA_NOWAIT, &dmamap))
467 1.10.12.2 dsl return (ENOBUFS);
468 1.10.12.2 dsl
469 1.10.12.2 dsl entry = malloc(sizeof(*entry), M_DEVBUF, M_NOWAIT);
470 1.10.12.2 dsl if (!entry) {
471 1.10.12.2 dsl bus_dmamap_destroy(sc->sc_dmatag, dmamap);
472 1.10.12.2 dsl return (ENOBUFS);
473 1.10.12.2 dsl }
474 1.10.12.2 dsl entry->dmamap = dmamap;
475 1.10.12.2 dsl SIMPLEQ_INSERT_HEAD(&sc_if->sk_txmap_head, entry, link);
476 1.10.12.2 dsl }
477 1.10.12.2 dsl
478 1.10.12.2 dsl sc_if->sk_cdata.sk_tx_prod = 0;
479 1.10.12.2 dsl sc_if->sk_cdata.sk_tx_cons = 0;
480 1.10.12.2 dsl sc_if->sk_cdata.sk_tx_cnt = 0;
481 1.10.12.2 dsl
482 1.10.12.2 dsl MSK_CDTXSYNC(sc_if, 0, MSK_TX_RING_CNT,
483 1.10.12.2 dsl BUS_DMASYNC_PREREAD|BUS_DMASYNC_PREWRITE);
484 1.10.12.2 dsl
485 1.10.12.2 dsl return (0);
486 1.10.12.2 dsl }
487 1.10.12.2 dsl
488 1.10.12.2 dsl int
489 1.10.12.2 dsl msk_newbuf(struct sk_if_softc *sc_if, int i, struct mbuf *m,
490 1.10.12.2 dsl bus_dmamap_t dmamap)
491 1.10.12.2 dsl {
492 1.10.12.2 dsl struct mbuf *m_new = NULL;
493 1.10.12.2 dsl struct sk_chain *c;
494 1.10.12.2 dsl struct msk_rx_desc *r;
495 1.10.12.2 dsl
496 1.10.12.2 dsl if (m == NULL) {
497 1.10.12.2 dsl void *buf = NULL;
498 1.10.12.2 dsl
499 1.10.12.2 dsl MGETHDR(m_new, M_DONTWAIT, MT_DATA);
500 1.10.12.2 dsl if (m_new == NULL)
501 1.10.12.2 dsl return (ENOBUFS);
502 1.10.12.2 dsl
503 1.10.12.2 dsl /* Allocate the jumbo buffer */
504 1.10.12.2 dsl buf = msk_jalloc(sc_if);
505 1.10.12.2 dsl if (buf == NULL) {
506 1.10.12.2 dsl m_freem(m_new);
507 1.10.12.2 dsl DPRINTFN(1, ("%s jumbo allocation failed -- packet "
508 1.10.12.2 dsl "dropped!\n", sc_if->sk_ethercom.ec_if.if_xname));
509 1.10.12.2 dsl return (ENOBUFS);
510 1.10.12.2 dsl }
511 1.10.12.2 dsl
512 1.10.12.2 dsl /* Attach the buffer to the mbuf */
513 1.10.12.2 dsl m_new->m_len = m_new->m_pkthdr.len = SK_JLEN;
514 1.10.12.2 dsl MEXTADD(m_new, buf, SK_JLEN, 0, msk_jfree, sc_if);
515 1.10.12.2 dsl } else {
516 1.10.12.2 dsl /*
517 1.10.12.2 dsl * We're re-using a previously allocated mbuf;
518 1.10.12.2 dsl * be sure to re-init pointers and lengths to
519 1.10.12.2 dsl * default values.
520 1.10.12.2 dsl */
521 1.10.12.2 dsl m_new = m;
522 1.10.12.2 dsl m_new->m_len = m_new->m_pkthdr.len = SK_JLEN;
523 1.10.12.2 dsl m_new->m_data = m_new->m_ext.ext_buf;
524 1.10.12.2 dsl }
525 1.10.12.2 dsl m_adj(m_new, ETHER_ALIGN);
526 1.10.12.2 dsl
527 1.10.12.2 dsl c = &sc_if->sk_cdata.sk_rx_chain[i];
528 1.10.12.2 dsl r = c->sk_le;
529 1.10.12.2 dsl c->sk_mbuf = m_new;
530 1.10.12.2 dsl r->sk_addr = htole32(dmamap->dm_segs[0].ds_addr +
531 1.10.12.2 dsl (((vaddr_t)m_new->m_data
532 1.10.12.2 dsl - (vaddr_t)sc_if->sk_cdata.sk_jumbo_buf)));
533 1.10.12.2 dsl r->sk_len = htole16(SK_JLEN);
534 1.10.12.2 dsl r->sk_ctl = 0;
535 1.10.12.2 dsl r->sk_opcode = SK_Y2_RXOPC_PACKET | SK_Y2_RXOPC_OWN;
536 1.10.12.2 dsl
537 1.10.12.2 dsl MSK_CDRXSYNC(sc_if, i, BUS_DMASYNC_PREWRITE|BUS_DMASYNC_PREREAD);
538 1.10.12.2 dsl
539 1.10.12.2 dsl return (0);
540 1.10.12.2 dsl }
541 1.10.12.2 dsl
542 1.10.12.2 dsl /*
543 1.10.12.2 dsl * Memory management for jumbo frames.
544 1.10.12.2 dsl */
545 1.10.12.2 dsl
546 1.10.12.2 dsl int
547 1.10.12.2 dsl msk_alloc_jumbo_mem(struct sk_if_softc *sc_if)
548 1.10.12.2 dsl {
549 1.10.12.2 dsl struct sk_softc *sc = sc_if->sk_softc;
550 1.10.12.2 dsl char *ptr, *kva;
551 1.10.12.2 dsl bus_dma_segment_t seg;
552 1.10.12.2 dsl int i, rseg, state, error;
553 1.10.12.2 dsl struct sk_jpool_entry *entry;
554 1.10.12.2 dsl
555 1.10.12.2 dsl state = error = 0;
556 1.10.12.2 dsl
557 1.10.12.2 dsl /* Grab a big chunk o' storage. */
558 1.10.12.2 dsl if (bus_dmamem_alloc(sc->sc_dmatag, MSK_JMEM, PAGE_SIZE, 0,
559 1.10.12.2 dsl &seg, 1, &rseg, BUS_DMA_NOWAIT)) {
560 1.10.12.2 dsl aprint_error(": can't alloc rx buffers");
561 1.10.12.2 dsl return (ENOBUFS);
562 1.10.12.2 dsl }
563 1.10.12.2 dsl
564 1.10.12.2 dsl state = 1;
565 1.10.12.2 dsl if (bus_dmamem_map(sc->sc_dmatag, &seg, rseg, MSK_JMEM, (void **)&kva,
566 1.10.12.2 dsl BUS_DMA_NOWAIT)) {
567 1.10.12.2 dsl aprint_error(": can't map dma buffers (%d bytes)", MSK_JMEM);
568 1.10.12.2 dsl error = ENOBUFS;
569 1.10.12.2 dsl goto out;
570 1.10.12.2 dsl }
571 1.10.12.2 dsl
572 1.10.12.2 dsl state = 2;
573 1.10.12.2 dsl if (bus_dmamap_create(sc->sc_dmatag, MSK_JMEM, 1, MSK_JMEM, 0,
574 1.10.12.2 dsl BUS_DMA_NOWAIT, &sc_if->sk_cdata.sk_rx_jumbo_map)) {
575 1.10.12.2 dsl aprint_error(": can't create dma map");
576 1.10.12.2 dsl error = ENOBUFS;
577 1.10.12.2 dsl goto out;
578 1.10.12.2 dsl }
579 1.10.12.2 dsl
580 1.10.12.2 dsl state = 3;
581 1.10.12.2 dsl if (bus_dmamap_load(sc->sc_dmatag, sc_if->sk_cdata.sk_rx_jumbo_map,
582 1.10.12.2 dsl kva, MSK_JMEM, NULL, BUS_DMA_NOWAIT)) {
583 1.10.12.2 dsl aprint_error(": can't load dma map");
584 1.10.12.2 dsl error = ENOBUFS;
585 1.10.12.2 dsl goto out;
586 1.10.12.2 dsl }
587 1.10.12.2 dsl
588 1.10.12.2 dsl state = 4;
589 1.10.12.2 dsl sc_if->sk_cdata.sk_jumbo_buf = (void *)kva;
590 1.10.12.2 dsl DPRINTFN(1,("msk_jumbo_buf = %p\n", (void *)sc_if->sk_cdata.sk_jumbo_buf));
591 1.10.12.2 dsl
592 1.10.12.2 dsl LIST_INIT(&sc_if->sk_jfree_listhead);
593 1.10.12.2 dsl LIST_INIT(&sc_if->sk_jinuse_listhead);
594 1.10.12.2 dsl
595 1.10.12.2 dsl /*
596 1.10.12.2 dsl * Now divide it up into 9K pieces and save the addresses
597 1.10.12.2 dsl * in an array.
598 1.10.12.2 dsl */
599 1.10.12.2 dsl ptr = sc_if->sk_cdata.sk_jumbo_buf;
600 1.10.12.2 dsl for (i = 0; i < MSK_JSLOTS; i++) {
601 1.10.12.2 dsl sc_if->sk_cdata.sk_jslots[i] = ptr;
602 1.10.12.2 dsl ptr += SK_JLEN;
603 1.10.12.2 dsl entry = malloc(sizeof(struct sk_jpool_entry),
604 1.10.12.2 dsl M_DEVBUF, M_NOWAIT);
605 1.10.12.2 dsl if (entry == NULL) {
606 1.10.12.2 dsl sc_if->sk_cdata.sk_jumbo_buf = NULL;
607 1.10.12.2 dsl aprint_error(": no memory for jumbo buffer queue!");
608 1.10.12.2 dsl error = ENOBUFS;
609 1.10.12.2 dsl goto out;
610 1.10.12.2 dsl }
611 1.10.12.2 dsl entry->slot = i;
612 1.10.12.2 dsl LIST_INSERT_HEAD(&sc_if->sk_jfree_listhead,
613 1.10.12.2 dsl entry, jpool_entries);
614 1.10.12.2 dsl }
615 1.10.12.2 dsl out:
616 1.10.12.2 dsl if (error != 0) {
617 1.10.12.2 dsl switch (state) {
618 1.10.12.2 dsl case 4:
619 1.10.12.2 dsl bus_dmamap_unload(sc->sc_dmatag,
620 1.10.12.2 dsl sc_if->sk_cdata.sk_rx_jumbo_map);
621 1.10.12.2 dsl case 3:
622 1.10.12.2 dsl bus_dmamap_destroy(sc->sc_dmatag,
623 1.10.12.2 dsl sc_if->sk_cdata.sk_rx_jumbo_map);
624 1.10.12.2 dsl case 2:
625 1.10.12.2 dsl bus_dmamem_unmap(sc->sc_dmatag, kva, MSK_JMEM);
626 1.10.12.2 dsl case 1:
627 1.10.12.2 dsl bus_dmamem_free(sc->sc_dmatag, &seg, rseg);
628 1.10.12.2 dsl break;
629 1.10.12.2 dsl default:
630 1.10.12.2 dsl break;
631 1.10.12.2 dsl }
632 1.10.12.2 dsl }
633 1.10.12.2 dsl
634 1.10.12.2 dsl return (error);
635 1.10.12.2 dsl }
636 1.10.12.2 dsl
637 1.10.12.2 dsl /*
638 1.10.12.2 dsl * Allocate a jumbo buffer.
639 1.10.12.2 dsl */
640 1.10.12.2 dsl void *
641 1.10.12.2 dsl msk_jalloc(struct sk_if_softc *sc_if)
642 1.10.12.2 dsl {
643 1.10.12.2 dsl struct sk_jpool_entry *entry;
644 1.10.12.2 dsl
645 1.10.12.2 dsl entry = LIST_FIRST(&sc_if->sk_jfree_listhead);
646 1.10.12.2 dsl
647 1.10.12.2 dsl if (entry == NULL)
648 1.10.12.2 dsl return (NULL);
649 1.10.12.2 dsl
650 1.10.12.2 dsl LIST_REMOVE(entry, jpool_entries);
651 1.10.12.2 dsl LIST_INSERT_HEAD(&sc_if->sk_jinuse_listhead, entry, jpool_entries);
652 1.10.12.2 dsl return (sc_if->sk_cdata.sk_jslots[entry->slot]);
653 1.10.12.2 dsl }
654 1.10.12.2 dsl
655 1.10.12.2 dsl /*
656 1.10.12.2 dsl * Release a jumbo buffer.
657 1.10.12.2 dsl */
658 1.10.12.2 dsl void
659 1.10.12.2 dsl msk_jfree(struct mbuf *m, void *buf, size_t size, void *arg)
660 1.10.12.2 dsl {
661 1.10.12.2 dsl struct sk_jpool_entry *entry;
662 1.10.12.2 dsl struct sk_if_softc *sc;
663 1.10.12.2 dsl int i, s;
664 1.10.12.2 dsl
665 1.10.12.2 dsl /* Extract the softc struct pointer. */
666 1.10.12.2 dsl sc = (struct sk_if_softc *)arg;
667 1.10.12.2 dsl
668 1.10.12.2 dsl if (sc == NULL)
669 1.10.12.2 dsl panic("msk_jfree: can't find softc pointer!");
670 1.10.12.2 dsl
671 1.10.12.2 dsl /* calculate the slot this buffer belongs to */
672 1.10.12.2 dsl i = ((vaddr_t)buf
673 1.10.12.2 dsl - (vaddr_t)sc->sk_cdata.sk_jumbo_buf) / SK_JLEN;
674 1.10.12.2 dsl
675 1.10.12.2 dsl if ((i < 0) || (i >= MSK_JSLOTS))
676 1.10.12.2 dsl panic("msk_jfree: asked to free buffer that we don't manage!");
677 1.10.12.2 dsl
678 1.10.12.2 dsl s = splvm();
679 1.10.12.2 dsl entry = LIST_FIRST(&sc->sk_jinuse_listhead);
680 1.10.12.2 dsl if (entry == NULL)
681 1.10.12.2 dsl panic("msk_jfree: buffer not in use!");
682 1.10.12.2 dsl entry->slot = i;
683 1.10.12.2 dsl LIST_REMOVE(entry, jpool_entries);
684 1.10.12.2 dsl LIST_INSERT_HEAD(&sc->sk_jfree_listhead, entry, jpool_entries);
685 1.10.12.2 dsl
686 1.10.12.2 dsl if (__predict_true(m != NULL))
687 1.10.12.2 dsl pool_cache_put(&mbpool_cache, m);
688 1.10.12.2 dsl splx(s);
689 1.10.12.2 dsl }
690 1.10.12.2 dsl
691 1.10.12.2 dsl /*
692 1.10.12.2 dsl * Set media options.
693 1.10.12.2 dsl */
694 1.10.12.2 dsl int
695 1.10.12.2 dsl msk_ifmedia_upd(struct ifnet *ifp)
696 1.10.12.2 dsl {
697 1.10.12.2 dsl struct sk_if_softc *sc_if = ifp->if_softc;
698 1.10.12.2 dsl
699 1.10.12.2 dsl mii_mediachg(&sc_if->sk_mii);
700 1.10.12.2 dsl return (0);
701 1.10.12.2 dsl }
702 1.10.12.2 dsl
703 1.10.12.2 dsl /*
704 1.10.12.2 dsl * Report current media status.
705 1.10.12.2 dsl */
706 1.10.12.2 dsl void
707 1.10.12.2 dsl msk_ifmedia_sts(struct ifnet *ifp, struct ifmediareq *ifmr)
708 1.10.12.2 dsl {
709 1.10.12.2 dsl struct sk_if_softc *sc_if = ifp->if_softc;
710 1.10.12.2 dsl
711 1.10.12.2 dsl mii_pollstat(&sc_if->sk_mii);
712 1.10.12.2 dsl ifmr->ifm_active = sc_if->sk_mii.mii_media_active;
713 1.10.12.2 dsl ifmr->ifm_status = sc_if->sk_mii.mii_media_status;
714 1.10.12.2 dsl }
715 1.10.12.2 dsl
716 1.10.12.2 dsl int
717 1.10.12.2 dsl msk_ioctl(struct ifnet *ifp, u_long command, void *data)
718 1.10.12.2 dsl {
719 1.10.12.2 dsl struct sk_if_softc *sc_if = ifp->if_softc;
720 1.10.12.2 dsl struct ifreq *ifr = (struct ifreq *) data;
721 1.10.12.2 dsl struct mii_data *mii;
722 1.10.12.2 dsl int s, error = 0;
723 1.10.12.2 dsl
724 1.10.12.2 dsl s = splnet();
725 1.10.12.2 dsl
726 1.10.12.2 dsl switch(command) {
727 1.10.12.2 dsl case SIOCSIFMTU:
728 1.10.12.2 dsl if (ifr->ifr_mtu < ETHERMIN)
729 1.10.12.2 dsl return EINVAL;
730 1.10.12.2 dsl else if (sc_if->sk_softc->sk_type != SK_YUKON_FE) {
731 1.10.12.2 dsl if (ifr->ifr_mtu > SK_JUMBO_MTU)
732 1.10.12.2 dsl error = EINVAL;
733 1.10.12.2 dsl } else if (ifr->ifr_mtu > ETHERMTU)
734 1.10.12.2 dsl error = EINVAL;
735 1.10.12.2 dsl ifp->if_mtu = ifr->ifr_mtu;
736 1.10.12.2 dsl break;
737 1.10.12.2 dsl case SIOCGIFMEDIA:
738 1.10.12.2 dsl case SIOCSIFMEDIA:
739 1.10.12.2 dsl DPRINTFN(2,("msk_ioctl: SIOC[GS]IFMEDIA\n"));
740 1.10.12.2 dsl mii = &sc_if->sk_mii;
741 1.10.12.2 dsl error = ifmedia_ioctl(ifp, ifr, &mii->mii_media, command);
742 1.10.12.2 dsl DPRINTFN(2,("msk_ioctl: SIOC[GS]IFMEDIA done\n"));
743 1.10.12.2 dsl break;
744 1.10.12.2 dsl default:
745 1.10.12.2 dsl DPRINTFN(2, ("msk_ioctl ETHER\n"));
746 1.10.12.2 dsl error = ether_ioctl(ifp, command, data);
747 1.10.12.2 dsl
748 1.10.12.2 dsl if (error == ENETRESET) {
749 1.10.12.2 dsl /*
750 1.10.12.2 dsl * Multicast list has changed; set the hardware
751 1.10.12.2 dsl * filter accordingly.
752 1.10.12.2 dsl */
753 1.10.12.2 dsl if (ifp->if_flags & IFF_RUNNING)
754 1.10.12.2 dsl msk_setmulti(sc_if);
755 1.10.12.2 dsl error = 0;
756 1.10.12.2 dsl }
757 1.10.12.2 dsl break;
758 1.10.12.2 dsl }
759 1.10.12.2 dsl
760 1.10.12.2 dsl splx(s);
761 1.10.12.2 dsl return (error);
762 1.10.12.2 dsl }
763 1.10.12.2 dsl
764 1.10.12.2 dsl void
765 1.10.12.2 dsl msk_update_int_mod(struct sk_softc *sc)
766 1.10.12.2 dsl {
767 1.10.12.2 dsl u_int32_t imtimer_ticks;
768 1.10.12.2 dsl
769 1.10.12.2 dsl /*
770 1.10.12.2 dsl * Configure interrupt moderation. The moderation timer
771 1.10.12.2 dsl * defers interrupts specified in the interrupt moderation
772 1.10.12.2 dsl * timer mask based on the timeout specified in the interrupt
773 1.10.12.2 dsl * moderation timer init register. Each bit in the timer
774 1.10.12.2 dsl * register represents one tick, so to specify a timeout in
775 1.10.12.2 dsl * microseconds, we have to multiply by the correct number of
776 1.10.12.2 dsl * ticks-per-microsecond.
777 1.10.12.2 dsl */
778 1.10.12.2 dsl switch (sc->sk_type) {
779 1.10.12.2 dsl case SK_YUKON_EC:
780 1.10.12.2 dsl case SK_YUKON_EC_U:
781 1.10.12.2 dsl imtimer_ticks = SK_IMTIMER_TICKS_YUKON_EC;
782 1.10.12.2 dsl break;
783 1.10.12.2 dsl case SK_YUKON_FE:
784 1.10.12.2 dsl imtimer_ticks = SK_IMTIMER_TICKS_YUKON_FE;
785 1.10.12.2 dsl break;
786 1.10.12.2 dsl case SK_YUKON_XL:
787 1.10.12.2 dsl imtimer_ticks = SK_IMTIMER_TICKS_YUKON_XL;
788 1.10.12.2 dsl break;
789 1.10.12.2 dsl default:
790 1.10.12.2 dsl imtimer_ticks = SK_IMTIMER_TICKS_YUKON;
791 1.10.12.2 dsl }
792 1.10.12.2 dsl aprint_verbose("%s: interrupt moderation is %d us\n",
793 1.10.12.2 dsl sc->sk_dev.dv_xname, sc->sk_int_mod);
794 1.10.12.2 dsl sk_win_write_4(sc, SK_IMTIMERINIT, SK_IM_USECS(sc->sk_int_mod));
795 1.10.12.2 dsl sk_win_write_4(sc, SK_IMMR, SK_ISR_TX1_S_EOF|SK_ISR_TX2_S_EOF|
796 1.10.12.2 dsl SK_ISR_RX1_EOF|SK_ISR_RX2_EOF);
797 1.10.12.2 dsl sk_win_write_1(sc, SK_IMTIMERCTL, SK_IMCTL_START);
798 1.10.12.2 dsl sc->sk_int_mod_pending = 0;
799 1.10.12.2 dsl }
800 1.10.12.2 dsl
801 1.10.12.2 dsl static int
802 1.10.12.2 dsl msk_lookup(const struct pci_attach_args *pa)
803 1.10.12.2 dsl {
804 1.10.12.2 dsl const struct msk_product *pmsk;
805 1.10.12.2 dsl
806 1.10.12.2 dsl for ( pmsk = &msk_products[0]; pmsk->msk_vendor != 0; pmsk++) {
807 1.10.12.2 dsl if (PCI_VENDOR(pa->pa_id) == pmsk->msk_vendor &&
808 1.10.12.2 dsl PCI_PRODUCT(pa->pa_id) == pmsk->msk_product)
809 1.10.12.2 dsl return 1;
810 1.10.12.2 dsl }
811 1.10.12.2 dsl return 0;
812 1.10.12.2 dsl }
813 1.10.12.2 dsl
814 1.10.12.2 dsl /*
815 1.10.12.2 dsl * Probe for a SysKonnect GEnesis chip. Check the PCI vendor and device
816 1.10.12.2 dsl * IDs against our list and return a device name if we find a match.
817 1.10.12.2 dsl */
818 1.10.12.2 dsl int
819 1.10.12.2 dsl mskc_probe(struct device *parent, struct cfdata *match,
820 1.10.12.2 dsl void *aux)
821 1.10.12.2 dsl {
822 1.10.12.2 dsl struct pci_attach_args *pa = (struct pci_attach_args *)aux;
823 1.10.12.2 dsl
824 1.10.12.2 dsl return msk_lookup(pa);
825 1.10.12.2 dsl }
826 1.10.12.2 dsl
827 1.10.12.2 dsl /*
828 1.10.12.2 dsl * Force the GEnesis into reset, then bring it out of reset.
829 1.10.12.2 dsl */
830 1.10.12.2 dsl void msk_reset(struct sk_softc *sc)
831 1.10.12.2 dsl {
832 1.10.12.2 dsl u_int32_t imtimer_ticks, reg1;
833 1.10.12.2 dsl int reg;
834 1.10.12.2 dsl
835 1.10.12.2 dsl DPRINTFN(2, ("msk_reset\n"));
836 1.10.12.2 dsl
837 1.10.12.2 dsl CSR_WRITE_1(sc, SK_CSR, SK_CSR_SW_RESET);
838 1.10.12.2 dsl CSR_WRITE_1(sc, SK_CSR, SK_CSR_MASTER_RESET);
839 1.10.12.2 dsl
840 1.10.12.2 dsl DELAY(1000);
841 1.10.12.2 dsl CSR_WRITE_1(sc, SK_CSR, SK_CSR_SW_UNRESET);
842 1.10.12.2 dsl DELAY(2);
843 1.10.12.2 dsl CSR_WRITE_1(sc, SK_CSR, SK_CSR_MASTER_UNRESET);
844 1.10.12.2 dsl sk_win_write_1(sc, SK_TESTCTL1, 2);
845 1.10.12.2 dsl
846 1.10.12.2 dsl reg1 = sk_win_read_4(sc, SK_Y2_PCI_REG(SK_PCI_OURREG1));
847 1.10.12.2 dsl if (sc->sk_type == SK_YUKON_XL && sc->sk_rev > SK_YUKON_XL_REV_A1)
848 1.10.12.2 dsl reg1 |= (SK_Y2_REG1_PHY1_COMA | SK_Y2_REG1_PHY2_COMA);
849 1.10.12.2 dsl else
850 1.10.12.2 dsl reg1 &= ~(SK_Y2_REG1_PHY1_COMA | SK_Y2_REG1_PHY2_COMA);
851 1.10.12.2 dsl sk_win_write_4(sc, SK_Y2_PCI_REG(SK_PCI_OURREG1), reg1);
852 1.10.12.2 dsl
853 1.10.12.2 dsl if (sc->sk_type == SK_YUKON_XL && sc->sk_rev > SK_YUKON_XL_REV_A1)
854 1.10.12.2 dsl sk_win_write_1(sc, SK_Y2_CLKGATE,
855 1.10.12.2 dsl SK_Y2_CLKGATE_LINK1_GATE_DIS |
856 1.10.12.2 dsl SK_Y2_CLKGATE_LINK2_GATE_DIS |
857 1.10.12.2 dsl SK_Y2_CLKGATE_LINK1_CORE_DIS |
858 1.10.12.2 dsl SK_Y2_CLKGATE_LINK2_CORE_DIS |
859 1.10.12.2 dsl SK_Y2_CLKGATE_LINK1_PCI_DIS | SK_Y2_CLKGATE_LINK2_PCI_DIS);
860 1.10.12.2 dsl else
861 1.10.12.2 dsl sk_win_write_1(sc, SK_Y2_CLKGATE, 0);
862 1.10.12.2 dsl
863 1.10.12.2 dsl CSR_WRITE_2(sc, SK_LINK_CTRL, SK_LINK_RESET_SET);
864 1.10.12.2 dsl CSR_WRITE_2(sc, SK_LINK_CTRL + SK_WIN_LEN, SK_LINK_RESET_SET);
865 1.10.12.2 dsl DELAY(1000);
866 1.10.12.2 dsl CSR_WRITE_2(sc, SK_LINK_CTRL, SK_LINK_RESET_CLEAR);
867 1.10.12.2 dsl CSR_WRITE_2(sc, SK_LINK_CTRL + SK_WIN_LEN, SK_LINK_RESET_CLEAR);
868 1.10.12.2 dsl
869 1.10.12.2 dsl sk_win_write_1(sc, SK_TESTCTL1, 1);
870 1.10.12.2 dsl
871 1.10.12.2 dsl DPRINTFN(2, ("msk_reset: sk_csr=%x\n", CSR_READ_1(sc, SK_CSR)));
872 1.10.12.2 dsl DPRINTFN(2, ("msk_reset: sk_link_ctrl=%x\n",
873 1.10.12.2 dsl CSR_READ_2(sc, SK_LINK_CTRL)));
874 1.10.12.2 dsl
875 1.10.12.2 dsl /* Disable ASF */
876 1.10.12.2 dsl CSR_WRITE_1(sc, SK_Y2_ASF_CSR, SK_Y2_ASF_RESET);
877 1.10.12.2 dsl CSR_WRITE_2(sc, SK_CSR, SK_CSR_ASF_OFF);
878 1.10.12.2 dsl
879 1.10.12.2 dsl /* Clear I2C IRQ noise */
880 1.10.12.2 dsl CSR_WRITE_4(sc, SK_I2CHWIRQ, 1);
881 1.10.12.2 dsl
882 1.10.12.2 dsl /* Disable hardware timer */
883 1.10.12.2 dsl CSR_WRITE_1(sc, SK_TIMERCTL, SK_IMCTL_STOP);
884 1.10.12.2 dsl CSR_WRITE_1(sc, SK_TIMERCTL, SK_IMCTL_IRQ_CLEAR);
885 1.10.12.2 dsl
886 1.10.12.2 dsl /* Disable descriptor polling */
887 1.10.12.2 dsl CSR_WRITE_4(sc, SK_DPT_TIMER_CTRL, SK_DPT_TCTL_STOP);
888 1.10.12.2 dsl
889 1.10.12.2 dsl /* Disable time stamps */
890 1.10.12.2 dsl CSR_WRITE_1(sc, SK_TSTAMP_CTL, SK_TSTAMP_STOP);
891 1.10.12.2 dsl CSR_WRITE_1(sc, SK_TSTAMP_CTL, SK_TSTAMP_IRQ_CLEAR);
892 1.10.12.2 dsl
893 1.10.12.2 dsl /* Enable RAM interface */
894 1.10.12.2 dsl sk_win_write_1(sc, SK_RAMCTL, SK_RAMCTL_UNRESET);
895 1.10.12.2 dsl for (reg = SK_TO0;reg <= SK_TO11; reg++)
896 1.10.12.2 dsl sk_win_write_1(sc, reg, 36);
897 1.10.12.2 dsl sk_win_write_1(sc, SK_RAMCTL + (SK_WIN_LEN / 2), SK_RAMCTL_UNRESET);
898 1.10.12.2 dsl for (reg = SK_TO0;reg <= SK_TO11; reg++)
899 1.10.12.2 dsl sk_win_write_1(sc, reg + (SK_WIN_LEN / 2), 36);
900 1.10.12.2 dsl
901 1.10.12.2 dsl /*
902 1.10.12.2 dsl * Configure interrupt moderation. The moderation timer
903 1.10.12.2 dsl * defers interrupts specified in the interrupt moderation
904 1.10.12.2 dsl * timer mask based on the timeout specified in the interrupt
905 1.10.12.2 dsl * moderation timer init register. Each bit in the timer
906 1.10.12.2 dsl * register represents one tick, so to specify a timeout in
907 1.10.12.2 dsl * microseconds, we have to multiply by the correct number of
908 1.10.12.2 dsl * ticks-per-microsecond.
909 1.10.12.2 dsl */
910 1.10.12.2 dsl switch (sc->sk_type) {
911 1.10.12.2 dsl case SK_YUKON_EC:
912 1.10.12.2 dsl case SK_YUKON_EC_U:
913 1.10.12.2 dsl imtimer_ticks = SK_IMTIMER_TICKS_YUKON_EC;
914 1.10.12.2 dsl break;
915 1.10.12.2 dsl case SK_YUKON_FE:
916 1.10.12.2 dsl imtimer_ticks = SK_IMTIMER_TICKS_YUKON_FE;
917 1.10.12.2 dsl break;
918 1.10.12.2 dsl case SK_YUKON_XL:
919 1.10.12.2 dsl imtimer_ticks = SK_IMTIMER_TICKS_YUKON_XL;
920 1.10.12.2 dsl break;
921 1.10.12.2 dsl default:
922 1.10.12.2 dsl imtimer_ticks = SK_IMTIMER_TICKS_YUKON;
923 1.10.12.2 dsl }
924 1.10.12.2 dsl
925 1.10.12.2 dsl /* Reset status ring. */
926 1.10.12.2 dsl bzero((char *)sc->sk_status_ring,
927 1.10.12.2 dsl MSK_STATUS_RING_CNT * sizeof(struct msk_status_desc));
928 1.10.12.2 dsl sc->sk_status_idx = 0;
929 1.10.12.2 dsl
930 1.10.12.2 dsl sk_win_write_4(sc, SK_STAT_BMU_CSR, SK_STAT_BMU_RESET);
931 1.10.12.2 dsl sk_win_write_4(sc, SK_STAT_BMU_CSR, SK_STAT_BMU_UNRESET);
932 1.10.12.2 dsl
933 1.10.12.2 dsl sk_win_write_2(sc, SK_STAT_BMU_LIDX, MSK_STATUS_RING_CNT - 1);
934 1.10.12.2 dsl sk_win_write_4(sc, SK_STAT_BMU_ADDRLO,
935 1.10.12.2 dsl sc->sk_status_map->dm_segs[0].ds_addr);
936 1.10.12.2 dsl sk_win_write_4(sc, SK_STAT_BMU_ADDRHI,
937 1.10.12.2 dsl (u_int64_t)sc->sk_status_map->dm_segs[0].ds_addr >> 32);
938 1.10.12.2 dsl if ((sc->sk_workaround & SK_STAT_BMU_FIFOIWM) != 0) {
939 1.10.12.2 dsl sk_win_write_2(sc, SK_STAT_BMU_TX_THRESH, SK_STAT_BMU_TXTHIDX_MSK);
940 1.10.12.2 dsl sk_win_write_1(sc, SK_STAT_BMU_FIFOWM, 0x21);
941 1.10.12.2 dsl sk_win_write_1(sc, SK_STAT_BMU_FIFOIWM, 0x07);
942 1.10.12.2 dsl } else {
943 1.10.12.2 dsl sk_win_write_2(sc, SK_STAT_BMU_TX_THRESH, 0x000a);
944 1.10.12.2 dsl sk_win_write_1(sc, SK_STAT_BMU_FIFOWM, 0x10);
945 1.10.12.2 dsl sk_win_write_1(sc, SK_STAT_BMU_FIFOIWM,
946 1.10.12.2 dsl ((sc->sk_workaround & SK_WA_4109) != 0) ? 0x10 : 0x04);
947 1.10.12.2 dsl sk_win_write_4(sc, SK_Y2_ISR_ITIMERINIT, 0x0190); /* 3.2us on Yukon-EC */
948 1.10.12.2 dsl }
949 1.10.12.2 dsl
950 1.10.12.2 dsl #if 0
951 1.10.12.2 dsl sk_win_write_4(sc, SK_Y2_LEV_ITIMERINIT, SK_IM_USECS(100));
952 1.10.12.2 dsl #endif
953 1.10.12.2 dsl sk_win_write_4(sc, SK_Y2_TX_ITIMERINIT, SK_IM_USECS(1000));
954 1.10.12.2 dsl
955 1.10.12.2 dsl sk_win_write_4(sc, SK_STAT_BMU_CSR, SK_STAT_BMU_ON);
956 1.10.12.2 dsl
957 1.10.12.2 dsl sk_win_write_1(sc, SK_Y2_LEV_ITIMERCTL, SK_IMCTL_START);
958 1.10.12.2 dsl sk_win_write_1(sc, SK_Y2_TX_ITIMERCTL, SK_IMCTL_START);
959 1.10.12.2 dsl sk_win_write_1(sc, SK_Y2_ISR_ITIMERCTL, SK_IMCTL_START);
960 1.10.12.2 dsl
961 1.10.12.2 dsl msk_update_int_mod(sc);
962 1.10.12.2 dsl }
963 1.10.12.2 dsl
964 1.10.12.2 dsl int
965 1.10.12.2 dsl msk_probe(struct device *parent, struct cfdata *match,
966 1.10.12.2 dsl void *aux)
967 1.10.12.2 dsl {
968 1.10.12.2 dsl struct skc_attach_args *sa = aux;
969 1.10.12.2 dsl
970 1.10.12.2 dsl if (sa->skc_port != SK_PORT_A && sa->skc_port != SK_PORT_B)
971 1.10.12.2 dsl return (0);
972 1.10.12.2 dsl
973 1.10.12.2 dsl switch (sa->skc_type) {
974 1.10.12.2 dsl case SK_YUKON_XL:
975 1.10.12.2 dsl case SK_YUKON_EC_U:
976 1.10.12.2 dsl case SK_YUKON_EC:
977 1.10.12.2 dsl case SK_YUKON_FE:
978 1.10.12.2 dsl return (1);
979 1.10.12.2 dsl }
980 1.10.12.2 dsl
981 1.10.12.2 dsl return (0);
982 1.10.12.2 dsl }
983 1.10.12.2 dsl
984 1.10.12.2 dsl /*
985 1.10.12.2 dsl * Each XMAC chip is attached as a separate logical IP interface.
986 1.10.12.2 dsl * Single port cards will have only one logical interface of course.
987 1.10.12.2 dsl */
988 1.10.12.2 dsl void
989 1.10.12.2 dsl msk_attach(struct device *parent, struct device *self, void *aux)
990 1.10.12.2 dsl {
991 1.10.12.2 dsl struct sk_if_softc *sc_if = (struct sk_if_softc *) self;
992 1.10.12.2 dsl struct sk_softc *sc = (struct sk_softc *)parent;
993 1.10.12.2 dsl struct skc_attach_args *sa = aux;
994 1.10.12.2 dsl struct ifnet *ifp;
995 1.10.12.2 dsl void *kva;
996 1.10.12.2 dsl bus_dma_segment_t seg;
997 1.10.12.2 dsl int i, rseg;
998 1.10.12.2 dsl u_int32_t chunk, val;
999 1.10.12.2 dsl
1000 1.10.12.2 dsl sc_if->sk_port = sa->skc_port;
1001 1.10.12.2 dsl sc_if->sk_softc = sc;
1002 1.10.12.2 dsl sc->sk_if[sa->skc_port] = sc_if;
1003 1.10.12.2 dsl
1004 1.10.12.2 dsl DPRINTFN(2, ("begin msk_attach: port=%d\n", sc_if->sk_port));
1005 1.10.12.2 dsl
1006 1.10.12.2 dsl /*
1007 1.10.12.2 dsl * Get station address for this interface. Note that
1008 1.10.12.2 dsl * dual port cards actually come with three station
1009 1.10.12.2 dsl * addresses: one for each port, plus an extra. The
1010 1.10.12.2 dsl * extra one is used by the SysKonnect driver software
1011 1.10.12.2 dsl * as a 'virtual' station address for when both ports
1012 1.10.12.2 dsl * are operating in failover mode. Currently we don't
1013 1.10.12.2 dsl * use this extra address.
1014 1.10.12.2 dsl */
1015 1.10.12.2 dsl for (i = 0; i < ETHER_ADDR_LEN; i++)
1016 1.10.12.2 dsl sc_if->sk_enaddr[i] =
1017 1.10.12.2 dsl sk_win_read_1(sc, SK_MAC0_0 + (sa->skc_port * 8) + i);
1018 1.10.12.2 dsl
1019 1.10.12.2 dsl aprint_normal(": Ethernet address %s\n",
1020 1.10.12.2 dsl ether_sprintf(sc_if->sk_enaddr));
1021 1.10.12.2 dsl
1022 1.10.12.2 dsl /*
1023 1.10.12.2 dsl * Set up RAM buffer addresses. The NIC will have a certain
1024 1.10.12.2 dsl * amount of SRAM on it, somewhere between 512K and 2MB. We
1025 1.10.12.2 dsl * need to divide this up a) between the transmitter and
1026 1.10.12.2 dsl * receiver and b) between the two XMACs, if this is a
1027 1.10.12.2 dsl * dual port NIC. Our algorithm is to divide up the memory
1028 1.10.12.2 dsl * evenly so that everyone gets a fair share.
1029 1.10.12.2 dsl *
1030 1.10.12.2 dsl * Just to be contrary, Yukon2 appears to have separate memory
1031 1.10.12.2 dsl * for each MAC.
1032 1.10.12.2 dsl */
1033 1.10.12.2 dsl chunk = sc->sk_ramsize - (sc->sk_ramsize + 2) / 3;
1034 1.10.12.2 dsl val = sc->sk_rboff / sizeof(u_int64_t);
1035 1.10.12.2 dsl sc_if->sk_rx_ramstart = val;
1036 1.10.12.2 dsl val += (chunk / sizeof(u_int64_t));
1037 1.10.12.2 dsl sc_if->sk_rx_ramend = val - 1;
1038 1.10.12.2 dsl chunk = sc->sk_ramsize - chunk;
1039 1.10.12.2 dsl sc_if->sk_tx_ramstart = val;
1040 1.10.12.2 dsl val += (chunk / sizeof(u_int64_t));
1041 1.10.12.2 dsl sc_if->sk_tx_ramend = val - 1;
1042 1.10.12.2 dsl
1043 1.10.12.2 dsl DPRINTFN(2, ("msk_attach: rx_ramstart=%#x rx_ramend=%#x\n"
1044 1.10.12.2 dsl " tx_ramstart=%#x tx_ramend=%#x\n",
1045 1.10.12.2 dsl sc_if->sk_rx_ramstart, sc_if->sk_rx_ramend,
1046 1.10.12.2 dsl sc_if->sk_tx_ramstart, sc_if->sk_tx_ramend));
1047 1.10.12.2 dsl
1048 1.10.12.2 dsl /* Allocate the descriptor queues. */
1049 1.10.12.2 dsl if (bus_dmamem_alloc(sc->sc_dmatag, sizeof(struct msk_ring_data),
1050 1.10.12.2 dsl PAGE_SIZE, 0, &seg, 1, &rseg, BUS_DMA_NOWAIT)) {
1051 1.10.12.2 dsl aprint_error(": can't alloc rx buffers\n");
1052 1.10.12.2 dsl goto fail;
1053 1.10.12.2 dsl }
1054 1.10.12.2 dsl if (bus_dmamem_map(sc->sc_dmatag, &seg, rseg,
1055 1.10.12.2 dsl sizeof(struct msk_ring_data), &kva, BUS_DMA_NOWAIT)) {
1056 1.10.12.2 dsl aprint_error(": can't map dma buffers (%zu bytes)\n",
1057 1.10.12.2 dsl sizeof(struct msk_ring_data));
1058 1.10.12.2 dsl goto fail_1;
1059 1.10.12.2 dsl }
1060 1.10.12.2 dsl if (bus_dmamap_create(sc->sc_dmatag, sizeof(struct msk_ring_data), 1,
1061 1.10.12.2 dsl sizeof(struct msk_ring_data), 0, BUS_DMA_NOWAIT,
1062 1.10.12.2 dsl &sc_if->sk_ring_map)) {
1063 1.10.12.2 dsl aprint_error(": can't create dma map\n");
1064 1.10.12.2 dsl goto fail_2;
1065 1.10.12.2 dsl }
1066 1.10.12.2 dsl if (bus_dmamap_load(sc->sc_dmatag, sc_if->sk_ring_map, kva,
1067 1.10.12.2 dsl sizeof(struct msk_ring_data), NULL, BUS_DMA_NOWAIT)) {
1068 1.10.12.2 dsl aprint_error(": can't load dma map\n");
1069 1.10.12.2 dsl goto fail_3;
1070 1.10.12.2 dsl }
1071 1.10.12.2 dsl sc_if->sk_rdata = (struct msk_ring_data *)kva;
1072 1.10.12.2 dsl bzero(sc_if->sk_rdata, sizeof(struct msk_ring_data));
1073 1.10.12.2 dsl
1074 1.10.12.2 dsl ifp = &sc_if->sk_ethercom.ec_if;
1075 1.10.12.2 dsl /* Try to allocate memory for jumbo buffers. */
1076 1.10.12.2 dsl if (msk_alloc_jumbo_mem(sc_if)) {
1077 1.10.12.2 dsl aprint_error(": jumbo buffer allocation failed\n");
1078 1.10.12.2 dsl goto fail_3;
1079 1.10.12.2 dsl }
1080 1.10.12.2 dsl sc_if->sk_ethercom.ec_capabilities = ETHERCAP_VLAN_MTU
1081 1.10.12.2 dsl | ETHERCAP_JUMBO_MTU;
1082 1.10.12.2 dsl
1083 1.10.12.2 dsl ifp->if_softc = sc_if;
1084 1.10.12.2 dsl ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
1085 1.10.12.2 dsl ifp->if_ioctl = msk_ioctl;
1086 1.10.12.2 dsl ifp->if_start = msk_start;
1087 1.10.12.2 dsl ifp->if_stop = msk_stop;
1088 1.10.12.2 dsl ifp->if_init = msk_init;
1089 1.10.12.2 dsl ifp->if_watchdog = msk_watchdog;
1090 1.10.12.2 dsl ifp->if_baudrate = 1000000000;
1091 1.10.12.2 dsl IFQ_SET_MAXLEN(&ifp->if_snd, MSK_TX_RING_CNT - 1);
1092 1.10.12.2 dsl IFQ_SET_READY(&ifp->if_snd);
1093 1.10.12.2 dsl strcpy(ifp->if_xname, sc_if->sk_dev.dv_xname);
1094 1.10.12.2 dsl
1095 1.10.12.2 dsl /*
1096 1.10.12.2 dsl * Do miibus setup.
1097 1.10.12.2 dsl */
1098 1.10.12.2 dsl msk_init_yukon(sc_if);
1099 1.10.12.2 dsl
1100 1.10.12.2 dsl DPRINTFN(2, ("msk_attach: 1\n"));
1101 1.10.12.2 dsl
1102 1.10.12.2 dsl sc_if->sk_mii.mii_ifp = ifp;
1103 1.10.12.2 dsl sc_if->sk_mii.mii_readreg = msk_miibus_readreg;
1104 1.10.12.2 dsl sc_if->sk_mii.mii_writereg = msk_miibus_writereg;
1105 1.10.12.2 dsl sc_if->sk_mii.mii_statchg = msk_miibus_statchg;
1106 1.10.12.2 dsl
1107 1.10.12.2 dsl ifmedia_init(&sc_if->sk_mii.mii_media, 0,
1108 1.10.12.2 dsl msk_ifmedia_upd, msk_ifmedia_sts);
1109 1.10.12.2 dsl mii_attach(self, &sc_if->sk_mii, 0xffffffff, MII_PHY_ANY,
1110 1.10.12.2 dsl MII_OFFSET_ANY, MIIF_DOPAUSE|MIIF_FORCEANEG);
1111 1.10.12.2 dsl if (LIST_FIRST(&sc_if->sk_mii.mii_phys) == NULL) {
1112 1.10.12.2 dsl aprint_error("%s: no PHY found!\n", sc_if->sk_dev.dv_xname);
1113 1.10.12.2 dsl ifmedia_add(&sc_if->sk_mii.mii_media, IFM_ETHER|IFM_MANUAL,
1114 1.10.12.2 dsl 0, NULL);
1115 1.10.12.2 dsl ifmedia_set(&sc_if->sk_mii.mii_media, IFM_ETHER|IFM_MANUAL);
1116 1.10.12.2 dsl } else
1117 1.10.12.2 dsl ifmedia_set(&sc_if->sk_mii.mii_media, IFM_ETHER|IFM_AUTO);
1118 1.10.12.2 dsl
1119 1.10.12.2 dsl callout_init(&sc_if->sk_tick_ch, 0);
1120 1.10.12.2 dsl callout_setfunc(&sc_if->sk_tick_ch, msk_tick, sc_if);
1121 1.10.12.2 dsl callout_schedule(&sc_if->sk_tick_ch, hz);
1122 1.10.12.2 dsl
1123 1.10.12.2 dsl /*
1124 1.10.12.2 dsl * Call MI attach routines.
1125 1.10.12.2 dsl */
1126 1.10.12.2 dsl if_attach(ifp);
1127 1.10.12.2 dsl ether_ifattach(ifp, sc_if->sk_enaddr);
1128 1.10.12.2 dsl
1129 1.10.12.2 dsl shutdownhook_establish(mskc_shutdown, sc);
1130 1.10.12.2 dsl
1131 1.10.12.2 dsl #if NRND > 0
1132 1.10.12.2 dsl rnd_attach_source(&sc->rnd_source, sc->sk_dev.dv_xname,
1133 1.10.12.2 dsl RND_TYPE_NET, 0);
1134 1.10.12.2 dsl #endif
1135 1.10.12.2 dsl
1136 1.10.12.2 dsl DPRINTFN(2, ("msk_attach: end\n"));
1137 1.10.12.2 dsl return;
1138 1.10.12.2 dsl
1139 1.10.12.2 dsl fail_3:
1140 1.10.12.2 dsl bus_dmamap_destroy(sc->sc_dmatag, sc_if->sk_ring_map);
1141 1.10.12.2 dsl fail_2:
1142 1.10.12.2 dsl bus_dmamem_unmap(sc->sc_dmatag, kva, sizeof(struct msk_ring_data));
1143 1.10.12.2 dsl fail_1:
1144 1.10.12.2 dsl bus_dmamem_free(sc->sc_dmatag, &seg, rseg);
1145 1.10.12.2 dsl fail:
1146 1.10.12.2 dsl sc->sk_if[sa->skc_port] = NULL;
1147 1.10.12.2 dsl }
1148 1.10.12.2 dsl
1149 1.10.12.2 dsl int
1150 1.10.12.2 dsl mskcprint(void *aux, const char *pnp)
1151 1.10.12.2 dsl {
1152 1.10.12.2 dsl struct skc_attach_args *sa = aux;
1153 1.10.12.2 dsl
1154 1.10.12.2 dsl if (pnp)
1155 1.10.12.2 dsl aprint_normal("sk port %c at %s",
1156 1.10.12.2 dsl (sa->skc_port == SK_PORT_A) ? 'A' : 'B', pnp);
1157 1.10.12.2 dsl else
1158 1.10.12.2 dsl aprint_normal(" port %c", (sa->skc_port == SK_PORT_A) ? 'A' : 'B');
1159 1.10.12.2 dsl return (UNCONF);
1160 1.10.12.2 dsl }
1161 1.10.12.2 dsl
1162 1.10.12.2 dsl /*
1163 1.10.12.2 dsl * Attach the interface. Allocate softc structures, do ifmedia
1164 1.10.12.2 dsl * setup and ethernet/BPF attach.
1165 1.10.12.2 dsl */
1166 1.10.12.2 dsl void
1167 1.10.12.2 dsl mskc_attach(struct device *parent, struct device *self, void *aux)
1168 1.10.12.2 dsl {
1169 1.10.12.2 dsl struct sk_softc *sc = (struct sk_softc *)self;
1170 1.10.12.2 dsl struct pci_attach_args *pa = aux;
1171 1.10.12.2 dsl struct skc_attach_args skca;
1172 1.10.12.2 dsl pci_chipset_tag_t pc = pa->pa_pc;
1173 1.10.12.2 dsl pcireg_t command, memtype;
1174 1.10.12.2 dsl pci_intr_handle_t ih;
1175 1.10.12.2 dsl const char *intrstr = NULL;
1176 1.10.12.2 dsl bus_size_t size;
1177 1.10.12.2 dsl int rc, sk_nodenum;
1178 1.10.12.2 dsl u_int8_t hw, skrs;
1179 1.10.12.2 dsl const char *revstr = NULL;
1180 1.10.12.2 dsl const struct sysctlnode *node;
1181 1.10.12.2 dsl void *kva;
1182 1.10.12.2 dsl bus_dma_segment_t seg;
1183 1.10.12.2 dsl int rseg;
1184 1.10.12.2 dsl
1185 1.10.12.2 dsl DPRINTFN(2, ("begin mskc_attach\n"));
1186 1.10.12.2 dsl
1187 1.10.12.2 dsl /*
1188 1.10.12.2 dsl * Handle power management nonsense.
1189 1.10.12.2 dsl */
1190 1.10.12.2 dsl command = pci_conf_read(pc, pa->pa_tag, SK_PCI_CAPID) & 0x000000FF;
1191 1.10.12.2 dsl
1192 1.10.12.2 dsl if (command == 0x01) {
1193 1.10.12.2 dsl command = pci_conf_read(pc, pa->pa_tag, SK_PCI_PWRMGMTCTRL);
1194 1.10.12.2 dsl if (command & SK_PSTATE_MASK) {
1195 1.10.12.2 dsl u_int32_t iobase, membase, irq;
1196 1.10.12.2 dsl
1197 1.10.12.2 dsl /* Save important PCI config data. */
1198 1.10.12.2 dsl iobase = pci_conf_read(pc, pa->pa_tag, SK_PCI_LOIO);
1199 1.10.12.2 dsl membase = pci_conf_read(pc, pa->pa_tag, SK_PCI_LOMEM);
1200 1.10.12.2 dsl irq = pci_conf_read(pc, pa->pa_tag, SK_PCI_INTLINE);
1201 1.10.12.2 dsl
1202 1.10.12.2 dsl /* Reset the power state. */
1203 1.10.12.2 dsl aprint_normal("%s chip is in D%d power mode "
1204 1.10.12.2 dsl "-- setting to D0\n", sc->sk_dev.dv_xname,
1205 1.10.12.2 dsl command & SK_PSTATE_MASK);
1206 1.10.12.2 dsl command &= 0xFFFFFFFC;
1207 1.10.12.2 dsl pci_conf_write(pc, pa->pa_tag,
1208 1.10.12.2 dsl SK_PCI_PWRMGMTCTRL, command);
1209 1.10.12.2 dsl
1210 1.10.12.2 dsl /* Restore PCI config data. */
1211 1.10.12.2 dsl pci_conf_write(pc, pa->pa_tag, SK_PCI_LOIO, iobase);
1212 1.10.12.2 dsl pci_conf_write(pc, pa->pa_tag, SK_PCI_LOMEM, membase);
1213 1.10.12.2 dsl pci_conf_write(pc, pa->pa_tag, SK_PCI_INTLINE, irq);
1214 1.10.12.2 dsl }
1215 1.10.12.2 dsl }
1216 1.10.12.2 dsl
1217 1.10.12.2 dsl /*
1218 1.10.12.2 dsl * Map control/status registers.
1219 1.10.12.2 dsl */
1220 1.10.12.2 dsl
1221 1.10.12.2 dsl memtype = pci_mapreg_type(pc, pa->pa_tag, SK_PCI_LOMEM);
1222 1.10.12.2 dsl switch (memtype) {
1223 1.10.12.2 dsl case PCI_MAPREG_TYPE_MEM | PCI_MAPREG_MEM_TYPE_32BIT:
1224 1.10.12.2 dsl case PCI_MAPREG_TYPE_MEM | PCI_MAPREG_MEM_TYPE_64BIT:
1225 1.10.12.2 dsl if (pci_mapreg_map(pa, SK_PCI_LOMEM,
1226 1.10.12.2 dsl memtype, 0, &sc->sk_btag, &sc->sk_bhandle,
1227 1.10.12.2 dsl NULL, &size) == 0)
1228 1.10.12.2 dsl break;
1229 1.10.12.2 dsl default:
1230 1.10.12.2 dsl aprint_error(": can't map mem space\n");
1231 1.10.12.2 dsl return;
1232 1.10.12.2 dsl }
1233 1.10.12.2 dsl
1234 1.10.12.2 dsl sc->sc_dmatag = pa->pa_dmat;
1235 1.10.12.2 dsl
1236 1.10.12.2 dsl sc->sk_type = sk_win_read_1(sc, SK_CHIPVER);
1237 1.10.12.2 dsl sc->sk_rev = (sk_win_read_1(sc, SK_CONFIG) >> 4);
1238 1.10.12.2 dsl
1239 1.10.12.2 dsl /* bail out here if chip is not recognized */
1240 1.10.12.2 dsl if (!(SK_IS_YUKON2(sc))) {
1241 1.10.12.2 dsl aprint_error(": unknown chip type: %d\n", sc->sk_type);
1242 1.10.12.2 dsl goto fail_1;
1243 1.10.12.2 dsl }
1244 1.10.12.2 dsl DPRINTFN(2, ("mskc_attach: allocate interrupt\n"));
1245 1.10.12.2 dsl
1246 1.10.12.2 dsl /* Allocate interrupt */
1247 1.10.12.2 dsl if (pci_intr_map(pa, &ih)) {
1248 1.10.12.2 dsl aprint_error(": couldn't map interrupt\n");
1249 1.10.12.2 dsl goto fail_1;
1250 1.10.12.2 dsl }
1251 1.10.12.2 dsl
1252 1.10.12.2 dsl intrstr = pci_intr_string(pc, ih);
1253 1.10.12.2 dsl sc->sk_intrhand = pci_intr_establish(pc, ih, IPL_NET, msk_intr, sc);
1254 1.10.12.2 dsl if (sc->sk_intrhand == NULL) {
1255 1.10.12.2 dsl aprint_error(": couldn't establish interrupt");
1256 1.10.12.2 dsl if (intrstr != NULL)
1257 1.10.12.2 dsl aprint_error(" at %s", intrstr);
1258 1.10.12.2 dsl aprint_error("\n");
1259 1.10.12.2 dsl goto fail_1;
1260 1.10.12.2 dsl }
1261 1.10.12.2 dsl
1262 1.10.12.2 dsl if (bus_dmamem_alloc(sc->sc_dmatag,
1263 1.10.12.2 dsl MSK_STATUS_RING_CNT * sizeof(struct msk_status_desc),
1264 1.10.12.2 dsl PAGE_SIZE, 0, &seg, 1, &rseg, BUS_DMA_NOWAIT)) {
1265 1.10.12.2 dsl aprint_error(": can't alloc status buffers\n");
1266 1.10.12.2 dsl goto fail_2;
1267 1.10.12.2 dsl }
1268 1.10.12.2 dsl
1269 1.10.12.2 dsl if (bus_dmamem_map(sc->sc_dmatag, &seg, rseg,
1270 1.10.12.2 dsl MSK_STATUS_RING_CNT * sizeof(struct msk_status_desc),
1271 1.10.12.2 dsl &kva, BUS_DMA_NOWAIT)) {
1272 1.10.12.2 dsl aprint_error(": can't map dma buffers (%zu bytes)\n",
1273 1.10.12.2 dsl MSK_STATUS_RING_CNT * sizeof(struct msk_status_desc));
1274 1.10.12.2 dsl goto fail_3;
1275 1.10.12.2 dsl }
1276 1.10.12.2 dsl if (bus_dmamap_create(sc->sc_dmatag,
1277 1.10.12.2 dsl MSK_STATUS_RING_CNT * sizeof(struct msk_status_desc), 1,
1278 1.10.12.2 dsl MSK_STATUS_RING_CNT * sizeof(struct msk_status_desc), 0,
1279 1.10.12.2 dsl BUS_DMA_NOWAIT, &sc->sk_status_map)) {
1280 1.10.12.2 dsl aprint_error(": can't create dma map\n");
1281 1.10.12.2 dsl goto fail_4;
1282 1.10.12.2 dsl }
1283 1.10.12.2 dsl if (bus_dmamap_load(sc->sc_dmatag, sc->sk_status_map, kva,
1284 1.10.12.2 dsl MSK_STATUS_RING_CNT * sizeof(struct msk_status_desc),
1285 1.10.12.2 dsl NULL, BUS_DMA_NOWAIT)) {
1286 1.10.12.2 dsl aprint_error(": can't load dma map\n");
1287 1.10.12.2 dsl goto fail_5;
1288 1.10.12.2 dsl }
1289 1.10.12.2 dsl sc->sk_status_ring = (struct msk_status_desc *)kva;
1290 1.10.12.2 dsl bzero(sc->sk_status_ring,
1291 1.10.12.2 dsl MSK_STATUS_RING_CNT * sizeof(struct msk_status_desc));
1292 1.10.12.2 dsl
1293 1.10.12.2 dsl /* Reset the adapter. */
1294 1.10.12.2 dsl msk_reset(sc);
1295 1.10.12.2 dsl
1296 1.10.12.2 dsl skrs = sk_win_read_1(sc, SK_EPROM0);
1297 1.10.12.2 dsl if (skrs == 0x00)
1298 1.10.12.2 dsl sc->sk_ramsize = 0x20000;
1299 1.10.12.2 dsl else
1300 1.10.12.2 dsl sc->sk_ramsize = skrs * (1<<12);
1301 1.10.12.2 dsl sc->sk_rboff = SK_RBOFF_0;
1302 1.10.12.2 dsl
1303 1.10.12.2 dsl DPRINTFN(2, ("mskc_attach: ramsize=%d (%dk), rboff=%d\n",
1304 1.10.12.2 dsl sc->sk_ramsize, sc->sk_ramsize / 1024,
1305 1.10.12.2 dsl sc->sk_rboff));
1306 1.10.12.2 dsl
1307 1.10.12.2 dsl switch (sc->sk_type) {
1308 1.10.12.2 dsl case SK_YUKON_XL:
1309 1.10.12.2 dsl sc->sk_name = "Yukon-2 XL";
1310 1.10.12.2 dsl break;
1311 1.10.12.2 dsl case SK_YUKON_EC_U:
1312 1.10.12.2 dsl sc->sk_name = "Yukon-2 EC Ultra";
1313 1.10.12.2 dsl break;
1314 1.10.12.2 dsl case SK_YUKON_EC:
1315 1.10.12.2 dsl sc->sk_name = "Yukon-2 EC";
1316 1.10.12.2 dsl break;
1317 1.10.12.2 dsl case SK_YUKON_FE:
1318 1.10.12.2 dsl sc->sk_name = "Yukon-2 FE";
1319 1.10.12.2 dsl break;
1320 1.10.12.2 dsl default:
1321 1.10.12.2 dsl sc->sk_name = "Yukon (Unknown)";
1322 1.10.12.2 dsl }
1323 1.10.12.2 dsl
1324 1.10.12.2 dsl if (sc->sk_type == SK_YUKON_XL) {
1325 1.10.12.2 dsl switch (sc->sk_rev) {
1326 1.10.12.2 dsl case SK_YUKON_XL_REV_A0:
1327 1.10.12.2 dsl sc->sk_workaround = 0;
1328 1.10.12.2 dsl revstr = "A0";
1329 1.10.12.2 dsl break;
1330 1.10.12.2 dsl case SK_YUKON_XL_REV_A1:
1331 1.10.12.2 dsl sc->sk_workaround = SK_WA_4109;
1332 1.10.12.2 dsl revstr = "A1";
1333 1.10.12.2 dsl break;
1334 1.10.12.2 dsl case SK_YUKON_XL_REV_A2:
1335 1.10.12.2 dsl sc->sk_workaround = SK_WA_4109;
1336 1.10.12.2 dsl revstr = "A2";
1337 1.10.12.2 dsl break;
1338 1.10.12.2 dsl case SK_YUKON_XL_REV_A3:
1339 1.10.12.2 dsl sc->sk_workaround = SK_WA_4109;
1340 1.10.12.2 dsl revstr = "A3";
1341 1.10.12.2 dsl break;
1342 1.10.12.2 dsl default:
1343 1.10.12.2 dsl sc->sk_workaround = 0;
1344 1.10.12.2 dsl break;
1345 1.10.12.2 dsl }
1346 1.10.12.2 dsl }
1347 1.10.12.2 dsl
1348 1.10.12.2 dsl if (sc->sk_type == SK_YUKON_EC) {
1349 1.10.12.2 dsl switch (sc->sk_rev) {
1350 1.10.12.2 dsl case SK_YUKON_EC_REV_A1:
1351 1.10.12.2 dsl sc->sk_workaround = SK_WA_43_418 | SK_WA_4109;
1352 1.10.12.2 dsl revstr = "A1";
1353 1.10.12.2 dsl break;
1354 1.10.12.2 dsl case SK_YUKON_EC_REV_A2:
1355 1.10.12.2 dsl sc->sk_workaround = SK_WA_4109;
1356 1.10.12.2 dsl revstr = "A2";
1357 1.10.12.2 dsl break;
1358 1.10.12.2 dsl case SK_YUKON_EC_REV_A3:
1359 1.10.12.2 dsl sc->sk_workaround = SK_WA_4109;
1360 1.10.12.2 dsl revstr = "A3";
1361 1.10.12.2 dsl break;
1362 1.10.12.2 dsl default:
1363 1.10.12.2 dsl sc->sk_workaround = 0;
1364 1.10.12.2 dsl break;
1365 1.10.12.2 dsl }
1366 1.10.12.2 dsl }
1367 1.10.12.2 dsl
1368 1.10.12.2 dsl if (sc->sk_type == SK_YUKON_FE) {
1369 1.10.12.2 dsl sc->sk_workaround = SK_WA_4109;
1370 1.10.12.2 dsl switch (sc->sk_rev) {
1371 1.10.12.2 dsl case SK_YUKON_FE_REV_A1:
1372 1.10.12.2 dsl revstr = "A1";
1373 1.10.12.2 dsl break;
1374 1.10.12.2 dsl case SK_YUKON_FE_REV_A2:
1375 1.10.12.2 dsl revstr = "A2";
1376 1.10.12.2 dsl break;
1377 1.10.12.2 dsl default:
1378 1.10.12.2 dsl sc->sk_workaround = 0;
1379 1.10.12.2 dsl break;
1380 1.10.12.2 dsl }
1381 1.10.12.2 dsl }
1382 1.10.12.2 dsl
1383 1.10.12.2 dsl if (sc->sk_type == SK_YUKON_EC_U) {
1384 1.10.12.2 dsl sc->sk_workaround = SK_WA_4109;
1385 1.10.12.2 dsl switch (sc->sk_rev) {
1386 1.10.12.2 dsl case SK_YUKON_EC_U_REV_A0:
1387 1.10.12.2 dsl revstr = "A0";
1388 1.10.12.2 dsl break;
1389 1.10.12.2 dsl case SK_YUKON_EC_U_REV_A1:
1390 1.10.12.2 dsl revstr = "A1";
1391 1.10.12.2 dsl break;
1392 1.10.12.2 dsl case SK_YUKON_EC_U_REV_B0:
1393 1.10.12.2 dsl revstr = "B0";
1394 1.10.12.2 dsl break;
1395 1.10.12.2 dsl default:
1396 1.10.12.2 dsl sc->sk_workaround = 0;
1397 1.10.12.2 dsl break;
1398 1.10.12.2 dsl }
1399 1.10.12.2 dsl }
1400 1.10.12.2 dsl
1401 1.10.12.2 dsl /* Announce the product name. */
1402 1.10.12.2 dsl aprint_normal(", %s", sc->sk_name);
1403 1.10.12.2 dsl if (revstr != NULL)
1404 1.10.12.2 dsl aprint_normal(" rev. %s", revstr);
1405 1.10.12.2 dsl aprint_normal(" (0x%x): %s\n", sc->sk_rev, intrstr);
1406 1.10.12.2 dsl
1407 1.10.12.2 dsl sc->sk_macs = 1;
1408 1.10.12.2 dsl
1409 1.10.12.2 dsl hw = sk_win_read_1(sc, SK_Y2_HWRES);
1410 1.10.12.2 dsl if ((hw & SK_Y2_HWRES_LINK_MASK) == SK_Y2_HWRES_LINK_DUAL) {
1411 1.10.12.2 dsl if ((sk_win_read_1(sc, SK_Y2_CLKGATE) &
1412 1.10.12.2 dsl SK_Y2_CLKGATE_LINK2_INACTIVE) == 0)
1413 1.10.12.2 dsl sc->sk_macs++;
1414 1.10.12.2 dsl }
1415 1.10.12.2 dsl
1416 1.10.12.2 dsl skca.skc_port = SK_PORT_A;
1417 1.10.12.2 dsl skca.skc_type = sc->sk_type;
1418 1.10.12.2 dsl skca.skc_rev = sc->sk_rev;
1419 1.10.12.2 dsl (void)config_found(&sc->sk_dev, &skca, mskcprint);
1420 1.10.12.2 dsl
1421 1.10.12.2 dsl if (sc->sk_macs > 1) {
1422 1.10.12.2 dsl skca.skc_port = SK_PORT_B;
1423 1.10.12.2 dsl skca.skc_type = sc->sk_type;
1424 1.10.12.2 dsl skca.skc_rev = sc->sk_rev;
1425 1.10.12.2 dsl (void)config_found(&sc->sk_dev, &skca, mskcprint);
1426 1.10.12.2 dsl }
1427 1.10.12.2 dsl
1428 1.10.12.2 dsl /* Turn on the 'driver is loaded' LED. */
1429 1.10.12.2 dsl CSR_WRITE_2(sc, SK_LED, SK_LED_GREEN_ON);
1430 1.10.12.2 dsl
1431 1.10.12.2 dsl /* skc sysctl setup */
1432 1.10.12.2 dsl
1433 1.10.12.2 dsl sc->sk_int_mod = SK_IM_DEFAULT;
1434 1.10.12.2 dsl sc->sk_int_mod_pending = 0;
1435 1.10.12.2 dsl
1436 1.10.12.2 dsl if ((rc = sysctl_createv(&sc->sk_clog, 0, NULL, &node,
1437 1.10.12.2 dsl 0, CTLTYPE_NODE, sc->sk_dev.dv_xname,
1438 1.10.12.2 dsl SYSCTL_DESCR("mskc per-controller controls"),
1439 1.10.12.2 dsl NULL, 0, NULL, 0, CTL_HW, msk_root_num, CTL_CREATE,
1440 1.10.12.2 dsl CTL_EOL)) != 0) {
1441 1.10.12.2 dsl aprint_normal("%s: couldn't create sysctl node\n",
1442 1.10.12.2 dsl sc->sk_dev.dv_xname);
1443 1.10.12.2 dsl goto fail_6;
1444 1.10.12.2 dsl }
1445 1.10.12.2 dsl
1446 1.10.12.2 dsl sk_nodenum = node->sysctl_num;
1447 1.10.12.2 dsl
1448 1.10.12.2 dsl /* interrupt moderation time in usecs */
1449 1.10.12.2 dsl if ((rc = sysctl_createv(&sc->sk_clog, 0, NULL, &node,
1450 1.10.12.2 dsl CTLFLAG_READWRITE,
1451 1.10.12.2 dsl CTLTYPE_INT, "int_mod",
1452 1.10.12.2 dsl SYSCTL_DESCR("msk interrupt moderation timer"),
1453 1.10.12.2 dsl msk_sysctl_handler, 0, sc,
1454 1.10.12.2 dsl 0, CTL_HW, msk_root_num, sk_nodenum, CTL_CREATE,
1455 1.10.12.2 dsl CTL_EOL)) != 0) {
1456 1.10.12.2 dsl aprint_normal("%s: couldn't create int_mod sysctl node\n",
1457 1.10.12.2 dsl sc->sk_dev.dv_xname);
1458 1.10.12.2 dsl goto fail_6;
1459 1.10.12.2 dsl }
1460 1.10.12.2 dsl
1461 1.10.12.2 dsl return;
1462 1.10.12.2 dsl
1463 1.10.12.2 dsl fail_6:
1464 1.10.12.2 dsl bus_dmamap_unload(sc->sc_dmatag, sc->sk_status_map);
1465 1.10.12.2 dsl fail_5:
1466 1.10.12.2 dsl bus_dmamap_destroy(sc->sc_dmatag, sc->sk_status_map);
1467 1.10.12.2 dsl fail_4:
1468 1.10.12.2 dsl bus_dmamem_unmap(sc->sc_dmatag, kva,
1469 1.10.12.2 dsl MSK_STATUS_RING_CNT * sizeof(struct msk_status_desc));
1470 1.10.12.2 dsl fail_3:
1471 1.10.12.2 dsl bus_dmamem_free(sc->sc_dmatag, &seg, rseg);
1472 1.10.12.2 dsl fail_2:
1473 1.10.12.2 dsl pci_intr_disestablish(pc, sc->sk_intrhand);
1474 1.10.12.2 dsl fail_1:
1475 1.10.12.2 dsl bus_space_unmap(sc->sk_btag, sc->sk_bhandle, size);
1476 1.10.12.2 dsl }
1477 1.10.12.2 dsl
1478 1.10.12.2 dsl int
1479 1.10.12.2 dsl msk_encap(struct sk_if_softc *sc_if, struct mbuf *m_head, u_int32_t *txidx)
1480 1.10.12.2 dsl {
1481 1.10.12.2 dsl struct sk_softc *sc = sc_if->sk_softc;
1482 1.10.12.2 dsl struct msk_tx_desc *f = NULL;
1483 1.10.12.2 dsl u_int32_t frag, cur;
1484 1.10.12.2 dsl int i;
1485 1.10.12.2 dsl struct sk_txmap_entry *entry;
1486 1.10.12.2 dsl bus_dmamap_t txmap;
1487 1.10.12.2 dsl
1488 1.10.12.2 dsl DPRINTFN(2, ("msk_encap\n"));
1489 1.10.12.2 dsl
1490 1.10.12.2 dsl entry = SIMPLEQ_FIRST(&sc_if->sk_txmap_head);
1491 1.10.12.2 dsl if (entry == NULL) {
1492 1.10.12.2 dsl DPRINTFN(2, ("msk_encap: no txmap available\n"));
1493 1.10.12.2 dsl return (ENOBUFS);
1494 1.10.12.2 dsl }
1495 1.10.12.2 dsl txmap = entry->dmamap;
1496 1.10.12.2 dsl
1497 1.10.12.2 dsl cur = frag = *txidx;
1498 1.10.12.2 dsl
1499 1.10.12.2 dsl #ifdef MSK_DEBUG
1500 1.10.12.2 dsl if (mskdebug >= 2)
1501 1.10.12.2 dsl msk_dump_mbuf(m_head);
1502 1.10.12.2 dsl #endif
1503 1.10.12.2 dsl
1504 1.10.12.2 dsl /*
1505 1.10.12.2 dsl * Start packing the mbufs in this chain into
1506 1.10.12.2 dsl * the fragment pointers. Stop when we run out
1507 1.10.12.2 dsl * of fragments or hit the end of the mbuf chain.
1508 1.10.12.2 dsl */
1509 1.10.12.2 dsl if (bus_dmamap_load_mbuf(sc->sc_dmatag, txmap, m_head,
1510 1.10.12.2 dsl BUS_DMA_NOWAIT)) {
1511 1.10.12.2 dsl DPRINTFN(2, ("msk_encap: dmamap failed\n"));
1512 1.10.12.2 dsl return (ENOBUFS);
1513 1.10.12.2 dsl }
1514 1.10.12.2 dsl
1515 1.10.12.2 dsl if (txmap->dm_nsegs > (MSK_TX_RING_CNT - sc_if->sk_cdata.sk_tx_cnt - 2)) {
1516 1.10.12.2 dsl DPRINTFN(2, ("msk_encap: too few descriptors free\n"));
1517 1.10.12.2 dsl bus_dmamap_unload(sc->sc_dmatag, txmap);
1518 1.10.12.2 dsl return (ENOBUFS);
1519 1.10.12.2 dsl }
1520 1.10.12.2 dsl
1521 1.10.12.2 dsl DPRINTFN(2, ("msk_encap: dm_nsegs=%d\n", txmap->dm_nsegs));
1522 1.10.12.2 dsl
1523 1.10.12.2 dsl /* Sync the DMA map. */
1524 1.10.12.2 dsl bus_dmamap_sync(sc->sc_dmatag, txmap, 0, txmap->dm_mapsize,
1525 1.10.12.2 dsl BUS_DMASYNC_PREWRITE);
1526 1.10.12.2 dsl
1527 1.10.12.2 dsl for (i = 0; i < txmap->dm_nsegs; i++) {
1528 1.10.12.2 dsl f = &sc_if->sk_rdata->sk_tx_ring[frag];
1529 1.10.12.2 dsl f->sk_addr = htole32(txmap->dm_segs[i].ds_addr);
1530 1.10.12.2 dsl f->sk_len = htole16(txmap->dm_segs[i].ds_len);
1531 1.10.12.2 dsl f->sk_ctl = 0;
1532 1.10.12.2 dsl if (i == 0)
1533 1.10.12.2 dsl f->sk_opcode = SK_Y2_TXOPC_PACKET;
1534 1.10.12.2 dsl else
1535 1.10.12.2 dsl f->sk_opcode = SK_Y2_TXOPC_BUFFER | SK_Y2_TXOPC_OWN;
1536 1.10.12.2 dsl cur = frag;
1537 1.10.12.2 dsl SK_INC(frag, MSK_TX_RING_CNT);
1538 1.10.12.2 dsl }
1539 1.10.12.2 dsl
1540 1.10.12.2 dsl sc_if->sk_cdata.sk_tx_chain[cur].sk_mbuf = m_head;
1541 1.10.12.2 dsl SIMPLEQ_REMOVE_HEAD(&sc_if->sk_txmap_head, link);
1542 1.10.12.2 dsl
1543 1.10.12.2 dsl sc_if->sk_cdata.sk_tx_map[cur] = entry;
1544 1.10.12.2 dsl sc_if->sk_rdata->sk_tx_ring[cur].sk_ctl |= SK_Y2_TXCTL_LASTFRAG;
1545 1.10.12.2 dsl
1546 1.10.12.2 dsl /* Sync descriptors before handing to chip */
1547 1.10.12.2 dsl MSK_CDTXSYNC(sc_if, *txidx, txmap->dm_nsegs,
1548 1.10.12.2 dsl BUS_DMASYNC_PREREAD|BUS_DMASYNC_PREWRITE);
1549 1.10.12.2 dsl
1550 1.10.12.2 dsl sc_if->sk_rdata->sk_tx_ring[*txidx].sk_opcode |= SK_Y2_TXOPC_OWN;
1551 1.10.12.2 dsl
1552 1.10.12.2 dsl /* Sync first descriptor to hand it off */
1553 1.10.12.2 dsl MSK_CDTXSYNC(sc_if, *txidx, 1,
1554 1.10.12.2 dsl BUS_DMASYNC_PREREAD|BUS_DMASYNC_PREWRITE);
1555 1.10.12.2 dsl
1556 1.10.12.2 dsl sc_if->sk_cdata.sk_tx_cnt += txmap->dm_nsegs;
1557 1.10.12.2 dsl
1558 1.10.12.2 dsl #ifdef MSK_DEBUG
1559 1.10.12.2 dsl if (mskdebug >= 2) {
1560 1.10.12.2 dsl struct msk_tx_desc *le;
1561 1.10.12.2 dsl u_int32_t idx;
1562 1.10.12.2 dsl for (idx = *txidx; idx != frag; SK_INC(idx, MSK_TX_RING_CNT)) {
1563 1.10.12.2 dsl le = &sc_if->sk_rdata->sk_tx_ring[idx];
1564 1.10.12.2 dsl msk_dump_txdesc(le, idx);
1565 1.10.12.2 dsl }
1566 1.10.12.2 dsl }
1567 1.10.12.2 dsl #endif
1568 1.10.12.2 dsl
1569 1.10.12.2 dsl *txidx = frag;
1570 1.10.12.2 dsl
1571 1.10.12.2 dsl DPRINTFN(2, ("msk_encap: completed successfully\n"));
1572 1.10.12.2 dsl
1573 1.10.12.2 dsl return (0);
1574 1.10.12.2 dsl }
1575 1.10.12.2 dsl
1576 1.10.12.2 dsl void
1577 1.10.12.2 dsl msk_start(struct ifnet *ifp)
1578 1.10.12.2 dsl {
1579 1.10.12.2 dsl struct sk_if_softc *sc_if = ifp->if_softc;
1580 1.10.12.2 dsl struct mbuf *m_head = NULL;
1581 1.10.12.2 dsl u_int32_t idx = sc_if->sk_cdata.sk_tx_prod;
1582 1.10.12.2 dsl int pkts = 0;
1583 1.10.12.2 dsl
1584 1.10.12.2 dsl DPRINTFN(2, ("msk_start\n"));
1585 1.10.12.2 dsl
1586 1.10.12.2 dsl while (sc_if->sk_cdata.sk_tx_chain[idx].sk_mbuf == NULL) {
1587 1.10.12.2 dsl IFQ_POLL(&ifp->if_snd, m_head);
1588 1.10.12.2 dsl if (m_head == NULL)
1589 1.10.12.2 dsl break;
1590 1.10.12.2 dsl
1591 1.10.12.2 dsl /*
1592 1.10.12.2 dsl * Pack the data into the transmit ring. If we
1593 1.10.12.2 dsl * don't have room, set the OACTIVE flag and wait
1594 1.10.12.2 dsl * for the NIC to drain the ring.
1595 1.10.12.2 dsl */
1596 1.10.12.2 dsl if (msk_encap(sc_if, m_head, &idx)) {
1597 1.10.12.2 dsl ifp->if_flags |= IFF_OACTIVE;
1598 1.10.12.2 dsl break;
1599 1.10.12.2 dsl }
1600 1.10.12.2 dsl
1601 1.10.12.2 dsl /* now we are committed to transmit the packet */
1602 1.10.12.2 dsl IFQ_DEQUEUE(&ifp->if_snd, m_head);
1603 1.10.12.2 dsl pkts++;
1604 1.10.12.2 dsl
1605 1.10.12.2 dsl /*
1606 1.10.12.2 dsl * If there's a BPF listener, bounce a copy of this frame
1607 1.10.12.2 dsl * to him.
1608 1.10.12.2 dsl */
1609 1.10.12.2 dsl #if NBPFILTER > 0
1610 1.10.12.2 dsl if (ifp->if_bpf)
1611 1.10.12.2 dsl bpf_mtap(ifp->if_bpf, m_head);
1612 1.10.12.2 dsl #endif
1613 1.10.12.2 dsl }
1614 1.10.12.2 dsl if (pkts == 0)
1615 1.10.12.2 dsl return;
1616 1.10.12.2 dsl
1617 1.10.12.2 dsl /* Transmit */
1618 1.10.12.2 dsl if (idx != sc_if->sk_cdata.sk_tx_prod) {
1619 1.10.12.2 dsl sc_if->sk_cdata.sk_tx_prod = idx;
1620 1.10.12.2 dsl SK_IF_WRITE_2(sc_if, 1, SK_TXQA1_Y2_PREF_PUTIDX, idx);
1621 1.10.12.2 dsl
1622 1.10.12.2 dsl /* Set a timeout in case the chip goes out to lunch. */
1623 1.10.12.2 dsl ifp->if_timer = 5;
1624 1.10.12.2 dsl }
1625 1.10.12.2 dsl }
1626 1.10.12.2 dsl
1627 1.10.12.2 dsl void
1628 1.10.12.2 dsl msk_watchdog(struct ifnet *ifp)
1629 1.10.12.2 dsl {
1630 1.10.12.2 dsl struct sk_if_softc *sc_if = ifp->if_softc;
1631 1.10.12.2 dsl u_int32_t reg;
1632 1.10.12.2 dsl int idx;
1633 1.10.12.2 dsl
1634 1.10.12.2 dsl /*
1635 1.10.12.2 dsl * Reclaim first as there is a possibility of losing Tx completion
1636 1.10.12.2 dsl * interrupts.
1637 1.10.12.2 dsl */
1638 1.10.12.2 dsl if (sc_if->sk_port == SK_PORT_A)
1639 1.10.12.2 dsl reg = SK_STAT_BMU_TXA1_RIDX;
1640 1.10.12.2 dsl else
1641 1.10.12.2 dsl reg = SK_STAT_BMU_TXA2_RIDX;
1642 1.10.12.2 dsl
1643 1.10.12.2 dsl idx = sk_win_read_2(sc_if->sk_softc, reg);
1644 1.10.12.2 dsl if (sc_if->sk_cdata.sk_tx_cons != idx) {
1645 1.10.12.2 dsl msk_txeof(sc_if, idx);
1646 1.10.12.2 dsl if (sc_if->sk_cdata.sk_tx_cnt != 0) {
1647 1.10.12.2 dsl aprint_error("%s: watchdog timeout\n", sc_if->sk_dev.dv_xname);
1648 1.10.12.2 dsl
1649 1.10.12.2 dsl ifp->if_oerrors++;
1650 1.10.12.2 dsl
1651 1.10.12.2 dsl /* XXX Resets both ports; we shouldn't do that. */
1652 1.10.12.2 dsl msk_reset(sc_if->sk_softc);
1653 1.10.12.2 dsl msk_init(ifp);
1654 1.10.12.2 dsl }
1655 1.10.12.2 dsl }
1656 1.10.12.2 dsl }
1657 1.10.12.2 dsl
1658 1.10.12.2 dsl void
1659 1.10.12.2 dsl mskc_shutdown(void *v)
1660 1.10.12.2 dsl {
1661 1.10.12.2 dsl struct sk_softc *sc = v;
1662 1.10.12.2 dsl
1663 1.10.12.2 dsl DPRINTFN(2, ("msk_shutdown\n"));
1664 1.10.12.2 dsl
1665 1.10.12.2 dsl /* Turn off the 'driver is loaded' LED. */
1666 1.10.12.2 dsl CSR_WRITE_2(sc, SK_LED, SK_LED_GREEN_OFF);
1667 1.10.12.2 dsl
1668 1.10.12.2 dsl msk_reset(sc);
1669 1.10.12.2 dsl }
1670 1.10.12.2 dsl
1671 1.10.12.2 dsl __inline int
1672 1.10.12.2 dsl msk_rxvalid(struct sk_softc *sc, u_int32_t stat, u_int32_t len)
1673 1.10.12.2 dsl {
1674 1.10.12.2 dsl if ((stat & (YU_RXSTAT_CRCERR | YU_RXSTAT_LONGERR |
1675 1.10.12.2 dsl YU_RXSTAT_MIIERR | YU_RXSTAT_BADFC | YU_RXSTAT_GOODFC |
1676 1.10.12.2 dsl YU_RXSTAT_JABBER)) != 0 ||
1677 1.10.12.2 dsl (stat & YU_RXSTAT_RXOK) != YU_RXSTAT_RXOK ||
1678 1.10.12.2 dsl YU_RXSTAT_BYTES(stat) != len)
1679 1.10.12.2 dsl return (0);
1680 1.10.12.2 dsl
1681 1.10.12.2 dsl return (1);
1682 1.10.12.2 dsl }
1683 1.10.12.2 dsl
1684 1.10.12.2 dsl void
1685 1.10.12.2 dsl msk_rxeof(struct sk_if_softc *sc_if, u_int16_t len, u_int32_t rxstat)
1686 1.10.12.2 dsl {
1687 1.10.12.2 dsl struct sk_softc *sc = sc_if->sk_softc;
1688 1.10.12.2 dsl struct ifnet *ifp = &sc_if->sk_ethercom.ec_if;
1689 1.10.12.2 dsl struct mbuf *m;
1690 1.10.12.2 dsl struct sk_chain *cur_rx;
1691 1.10.12.2 dsl int cur, total_len = len;
1692 1.10.12.2 dsl bus_dmamap_t dmamap;
1693 1.10.12.2 dsl
1694 1.10.12.2 dsl DPRINTFN(2, ("msk_rxeof\n"));
1695 1.10.12.2 dsl
1696 1.10.12.2 dsl cur = sc_if->sk_cdata.sk_rx_cons;
1697 1.10.12.2 dsl SK_INC(sc_if->sk_cdata.sk_rx_cons, MSK_RX_RING_CNT);
1698 1.10.12.2 dsl SK_INC(sc_if->sk_cdata.sk_rx_prod, MSK_RX_RING_CNT);
1699 1.10.12.2 dsl
1700 1.10.12.2 dsl /* Sync the descriptor */
1701 1.10.12.2 dsl MSK_CDRXSYNC(sc_if, cur, BUS_DMASYNC_POSTREAD|BUS_DMASYNC_POSTWRITE);
1702 1.10.12.2 dsl
1703 1.10.12.2 dsl cur_rx = &sc_if->sk_cdata.sk_rx_chain[cur];
1704 1.10.12.2 dsl dmamap = sc_if->sk_cdata.sk_rx_jumbo_map;
1705 1.10.12.2 dsl
1706 1.10.12.2 dsl bus_dmamap_sync(sc_if->sk_softc->sc_dmatag, dmamap, 0,
1707 1.10.12.2 dsl dmamap->dm_mapsize, BUS_DMASYNC_POSTREAD);
1708 1.10.12.2 dsl
1709 1.10.12.2 dsl m = cur_rx->sk_mbuf;
1710 1.10.12.2 dsl cur_rx->sk_mbuf = NULL;
1711 1.10.12.2 dsl
1712 1.10.12.2 dsl if (total_len < SK_MIN_FRAMELEN ||
1713 1.10.12.2 dsl total_len > SK_JUMBO_FRAMELEN ||
1714 1.10.12.2 dsl msk_rxvalid(sc, rxstat, total_len) == 0) {
1715 1.10.12.2 dsl ifp->if_ierrors++;
1716 1.10.12.2 dsl msk_newbuf(sc_if, cur, m, dmamap);
1717 1.10.12.2 dsl return;
1718 1.10.12.2 dsl }
1719 1.10.12.2 dsl
1720 1.10.12.2 dsl /*
1721 1.10.12.2 dsl * Try to allocate a new jumbo buffer. If that fails, copy the
1722 1.10.12.2 dsl * packet to mbufs and put the jumbo buffer back in the ring
1723 1.10.12.2 dsl * so it can be re-used. If allocating mbufs fails, then we
1724 1.10.12.2 dsl * have to drop the packet.
1725 1.10.12.2 dsl */
1726 1.10.12.2 dsl if (msk_newbuf(sc_if, cur, NULL, dmamap) == ENOBUFS) {
1727 1.10.12.2 dsl struct mbuf *m0;
1728 1.10.12.2 dsl m0 = m_devget(mtod(m, char *) - ETHER_ALIGN,
1729 1.10.12.2 dsl total_len + ETHER_ALIGN, 0, ifp, NULL);
1730 1.10.12.2 dsl msk_newbuf(sc_if, cur, m, dmamap);
1731 1.10.12.2 dsl if (m0 == NULL) {
1732 1.10.12.2 dsl ifp->if_ierrors++;
1733 1.10.12.2 dsl return;
1734 1.10.12.2 dsl }
1735 1.10.12.2 dsl m_adj(m0, ETHER_ALIGN);
1736 1.10.12.2 dsl m = m0;
1737 1.10.12.2 dsl } else {
1738 1.10.12.2 dsl m->m_pkthdr.rcvif = ifp;
1739 1.10.12.2 dsl m->m_pkthdr.len = m->m_len = total_len;
1740 1.10.12.2 dsl }
1741 1.10.12.2 dsl
1742 1.10.12.2 dsl ifp->if_ipackets++;
1743 1.10.12.2 dsl
1744 1.10.12.2 dsl #if NBPFILTER > 0
1745 1.10.12.2 dsl if (ifp->if_bpf)
1746 1.10.12.2 dsl bpf_mtap(ifp->if_bpf, m);
1747 1.10.12.2 dsl #endif
1748 1.10.12.2 dsl
1749 1.10.12.2 dsl /* pass it on. */
1750 1.10.12.2 dsl (*ifp->if_input)(ifp, m);
1751 1.10.12.2 dsl }
1752 1.10.12.2 dsl
1753 1.10.12.2 dsl void
1754 1.10.12.2 dsl msk_txeof(struct sk_if_softc *sc_if, int idx)
1755 1.10.12.2 dsl {
1756 1.10.12.2 dsl struct sk_softc *sc = sc_if->sk_softc;
1757 1.10.12.2 dsl struct msk_tx_desc *cur_tx;
1758 1.10.12.2 dsl struct ifnet *ifp = &sc_if->sk_ethercom.ec_if;
1759 1.10.12.2 dsl u_int32_t sk_ctl;
1760 1.10.12.2 dsl struct sk_txmap_entry *entry;
1761 1.10.12.2 dsl int cons, prog;
1762 1.10.12.2 dsl
1763 1.10.12.2 dsl DPRINTFN(2, ("msk_txeof\n"));
1764 1.10.12.2 dsl
1765 1.10.12.2 dsl /*
1766 1.10.12.2 dsl * Go through our tx ring and free mbufs for those
1767 1.10.12.2 dsl * frames that have been sent.
1768 1.10.12.2 dsl */
1769 1.10.12.2 dsl cons = sc_if->sk_cdata.sk_tx_cons;
1770 1.10.12.2 dsl prog = 0;
1771 1.10.12.2 dsl while (cons != idx) {
1772 1.10.12.2 dsl if (sc_if->sk_cdata.sk_tx_cnt <= 0)
1773 1.10.12.2 dsl break;
1774 1.10.12.2 dsl prog++;
1775 1.10.12.2 dsl MSK_CDTXSYNC(sc_if, cons, 1,
1776 1.10.12.2 dsl BUS_DMASYNC_POSTREAD|BUS_DMASYNC_POSTWRITE);
1777 1.10.12.2 dsl
1778 1.10.12.2 dsl cur_tx = &sc_if->sk_rdata->sk_tx_ring[cons];
1779 1.10.12.2 dsl sk_ctl = cur_tx->sk_ctl;
1780 1.10.12.2 dsl #ifdef MSK_DEBUG
1781 1.10.12.2 dsl if (mskdebug >= 2)
1782 1.10.12.2 dsl msk_dump_txdesc(cur_tx, cons);
1783 1.10.12.2 dsl #endif
1784 1.10.12.2 dsl if (sk_ctl & SK_Y2_TXCTL_LASTFRAG)
1785 1.10.12.2 dsl ifp->if_opackets++;
1786 1.10.12.2 dsl if (sc_if->sk_cdata.sk_tx_chain[cons].sk_mbuf != NULL) {
1787 1.10.12.2 dsl entry = sc_if->sk_cdata.sk_tx_map[cons];
1788 1.10.12.2 dsl
1789 1.10.12.2 dsl bus_dmamap_sync(sc->sc_dmatag, entry->dmamap, 0,
1790 1.10.12.2 dsl entry->dmamap->dm_mapsize, BUS_DMASYNC_POSTWRITE);
1791 1.10.12.2 dsl
1792 1.10.12.2 dsl bus_dmamap_unload(sc->sc_dmatag, entry->dmamap);
1793 1.10.12.2 dsl SIMPLEQ_INSERT_TAIL(&sc_if->sk_txmap_head, entry,
1794 1.10.12.2 dsl link);
1795 1.10.12.2 dsl sc_if->sk_cdata.sk_tx_map[cons] = NULL;
1796 1.10.12.2 dsl m_freem(sc_if->sk_cdata.sk_tx_chain[cons].sk_mbuf);
1797 1.10.12.2 dsl sc_if->sk_cdata.sk_tx_chain[cons].sk_mbuf = NULL;
1798 1.10.12.2 dsl }
1799 1.10.12.2 dsl sc_if->sk_cdata.sk_tx_cnt--;
1800 1.10.12.2 dsl SK_INC(cons, MSK_TX_RING_CNT);
1801 1.10.12.2 dsl }
1802 1.10.12.2 dsl ifp->if_timer = sc_if->sk_cdata.sk_tx_cnt > 0 ? 5 : 0;
1803 1.10.12.2 dsl
1804 1.10.12.2 dsl if (sc_if->sk_cdata.sk_tx_cnt < MSK_TX_RING_CNT - 2)
1805 1.10.12.2 dsl ifp->if_flags &= ~IFF_OACTIVE;
1806 1.10.12.2 dsl
1807 1.10.12.2 dsl if (prog > 0)
1808 1.10.12.2 dsl sc_if->sk_cdata.sk_tx_cons = cons;
1809 1.10.12.2 dsl }
1810 1.10.12.2 dsl
1811 1.10.12.2 dsl void
1812 1.10.12.2 dsl msk_tick(void *xsc_if)
1813 1.10.12.2 dsl {
1814 1.10.12.2 dsl struct sk_if_softc *sc_if = xsc_if;
1815 1.10.12.2 dsl struct mii_data *mii = &sc_if->sk_mii;
1816 1.10.12.2 dsl
1817 1.10.12.2 dsl mii_tick(mii);
1818 1.10.12.2 dsl callout_schedule(&sc_if->sk_tick_ch, hz);
1819 1.10.12.2 dsl }
1820 1.10.12.2 dsl
1821 1.10.12.2 dsl void
1822 1.10.12.2 dsl msk_intr_yukon(struct sk_if_softc *sc_if)
1823 1.10.12.2 dsl {
1824 1.10.12.2 dsl u_int8_t status;
1825 1.10.12.2 dsl
1826 1.10.12.2 dsl status = SK_IF_READ_1(sc_if, 0, SK_GMAC_ISR);
1827 1.10.12.2 dsl /* RX overrun */
1828 1.10.12.2 dsl if ((status & SK_GMAC_INT_RX_OVER) != 0) {
1829 1.10.12.2 dsl SK_IF_WRITE_1(sc_if, 0, SK_RXMF1_CTRL_TEST,
1830 1.10.12.2 dsl SK_RFCTL_RX_FIFO_OVER);
1831 1.10.12.2 dsl }
1832 1.10.12.2 dsl /* TX underrun */
1833 1.10.12.2 dsl if ((status & SK_GMAC_INT_TX_UNDER) != 0) {
1834 1.10.12.2 dsl SK_IF_WRITE_1(sc_if, 0, SK_TXMF1_CTRL_TEST,
1835 1.10.12.2 dsl SK_TFCTL_TX_FIFO_UNDER);
1836 1.10.12.2 dsl }
1837 1.10.12.2 dsl
1838 1.10.12.2 dsl DPRINTFN(2, ("msk_intr_yukon status=%#x\n", status));
1839 1.10.12.2 dsl }
1840 1.10.12.2 dsl
1841 1.10.12.2 dsl int
1842 1.10.12.2 dsl msk_intr(void *xsc)
1843 1.10.12.2 dsl {
1844 1.10.12.2 dsl struct sk_softc *sc = xsc;
1845 1.10.12.2 dsl struct sk_if_softc *sc_if0 = sc->sk_if[SK_PORT_A];
1846 1.10.12.2 dsl struct sk_if_softc *sc_if1 = sc->sk_if[SK_PORT_B];
1847 1.10.12.2 dsl struct ifnet *ifp0 = NULL, *ifp1 = NULL;
1848 1.10.12.2 dsl int claimed = 0;
1849 1.10.12.2 dsl u_int32_t status;
1850 1.10.12.2 dsl struct msk_status_desc *cur_st;
1851 1.10.12.2 dsl
1852 1.10.12.2 dsl status = CSR_READ_4(sc, SK_Y2_ISSR2);
1853 1.10.12.2 dsl if (status == 0) {
1854 1.10.12.2 dsl CSR_WRITE_4(sc, SK_Y2_ICR, 2);
1855 1.10.12.2 dsl return (0);
1856 1.10.12.2 dsl }
1857 1.10.12.2 dsl
1858 1.10.12.2 dsl status = CSR_READ_4(sc, SK_ISR);
1859 1.10.12.2 dsl
1860 1.10.12.2 dsl if (sc_if0 != NULL)
1861 1.10.12.2 dsl ifp0 = &sc_if0->sk_ethercom.ec_if;
1862 1.10.12.2 dsl if (sc_if1 != NULL)
1863 1.10.12.2 dsl ifp1 = &sc_if1->sk_ethercom.ec_if;
1864 1.10.12.2 dsl
1865 1.10.12.2 dsl if (sc_if0 && (status & SK_Y2_IMR_MAC1) &&
1866 1.10.12.2 dsl (ifp0->if_flags & IFF_RUNNING)) {
1867 1.10.12.2 dsl msk_intr_yukon(sc_if0);
1868 1.10.12.2 dsl }
1869 1.10.12.2 dsl
1870 1.10.12.2 dsl if (sc_if1 && (status & SK_Y2_IMR_MAC2) &&
1871 1.10.12.2 dsl (ifp1->if_flags & IFF_RUNNING)) {
1872 1.10.12.2 dsl msk_intr_yukon(sc_if1);
1873 1.10.12.2 dsl }
1874 1.10.12.2 dsl
1875 1.10.12.2 dsl MSK_CDSTSYNC(sc, sc->sk_status_idx,
1876 1.10.12.2 dsl BUS_DMASYNC_POSTREAD|BUS_DMASYNC_POSTWRITE);
1877 1.10.12.2 dsl cur_st = &sc->sk_status_ring[sc->sk_status_idx];
1878 1.10.12.2 dsl
1879 1.10.12.2 dsl while (cur_st->sk_opcode & SK_Y2_STOPC_OWN) {
1880 1.10.12.2 dsl cur_st->sk_opcode &= ~SK_Y2_STOPC_OWN;
1881 1.10.12.2 dsl switch (cur_st->sk_opcode) {
1882 1.10.12.2 dsl case SK_Y2_STOPC_RXSTAT:
1883 1.10.12.2 dsl msk_rxeof(sc->sk_if[cur_st->sk_link],
1884 1.10.12.2 dsl letoh16(cur_st->sk_len),
1885 1.10.12.2 dsl letoh32(cur_st->sk_status));
1886 1.10.12.2 dsl SK_IF_WRITE_2(sc->sk_if[cur_st->sk_link], 0,
1887 1.10.12.2 dsl SK_RXQ1_Y2_PREF_PUTIDX,
1888 1.10.12.2 dsl sc->sk_if[cur_st->sk_link]->sk_cdata.sk_rx_prod);
1889 1.10.12.2 dsl break;
1890 1.10.12.2 dsl case SK_Y2_STOPC_TXSTAT:
1891 1.10.12.2 dsl if (sc_if0)
1892 1.10.12.2 dsl msk_txeof(sc_if0,
1893 1.10.12.2 dsl letoh32(cur_st->sk_status)
1894 1.10.12.2 dsl & SK_Y2_ST_TXA1_MSKL);
1895 1.10.12.2 dsl if (sc_if1)
1896 1.10.12.2 dsl msk_txeof(sc_if1,
1897 1.10.12.2 dsl ((letoh32(cur_st->sk_status)
1898 1.10.12.2 dsl & SK_Y2_ST_TXA2_MSKL)
1899 1.10.12.2 dsl >> SK_Y2_ST_TXA2_SHIFTL)
1900 1.10.12.2 dsl | ((letoh16(cur_st->sk_len) & SK_Y2_ST_TXA2_MSKH) << SK_Y2_ST_TXA2_SHIFTH));
1901 1.10.12.2 dsl break;
1902 1.10.12.2 dsl default:
1903 1.10.12.2 dsl aprint_error("opcode=0x%x\n", cur_st->sk_opcode);
1904 1.10.12.2 dsl break;
1905 1.10.12.2 dsl }
1906 1.10.12.2 dsl SK_INC(sc->sk_status_idx, MSK_STATUS_RING_CNT);
1907 1.10.12.2 dsl
1908 1.10.12.2 dsl MSK_CDSTSYNC(sc, sc->sk_status_idx,
1909 1.10.12.2 dsl BUS_DMASYNC_POSTREAD|BUS_DMASYNC_POSTWRITE);
1910 1.10.12.2 dsl cur_st = &sc->sk_status_ring[sc->sk_status_idx];
1911 1.10.12.2 dsl }
1912 1.10.12.2 dsl
1913 1.10.12.2 dsl if (status & SK_Y2_IMR_BMU) {
1914 1.10.12.2 dsl CSR_WRITE_4(sc, SK_STAT_BMU_CSR, SK_STAT_BMU_IRQ_CLEAR);
1915 1.10.12.2 dsl claimed = 1;
1916 1.10.12.2 dsl }
1917 1.10.12.2 dsl
1918 1.10.12.2 dsl CSR_WRITE_4(sc, SK_Y2_ICR, 2);
1919 1.10.12.2 dsl
1920 1.10.12.2 dsl if (ifp0 != NULL && !IFQ_IS_EMPTY(&ifp0->if_snd))
1921 1.10.12.2 dsl msk_start(ifp0);
1922 1.10.12.2 dsl if (ifp1 != NULL && !IFQ_IS_EMPTY(&ifp1->if_snd))
1923 1.10.12.2 dsl msk_start(ifp1);
1924 1.10.12.2 dsl
1925 1.10.12.2 dsl #if NRND > 0
1926 1.10.12.2 dsl if (RND_ENABLED(&sc->rnd_source))
1927 1.10.12.2 dsl rnd_add_uint32(&sc->rnd_source, status);
1928 1.10.12.2 dsl #endif
1929 1.10.12.2 dsl
1930 1.10.12.2 dsl if (sc->sk_int_mod_pending)
1931 1.10.12.2 dsl msk_update_int_mod(sc);
1932 1.10.12.2 dsl
1933 1.10.12.2 dsl return claimed;
1934 1.10.12.2 dsl }
1935 1.10.12.2 dsl
1936 1.10.12.2 dsl void
1937 1.10.12.2 dsl msk_init_yukon(struct sk_if_softc *sc_if)
1938 1.10.12.2 dsl {
1939 1.10.12.2 dsl u_int32_t v;
1940 1.10.12.2 dsl u_int16_t reg;
1941 1.10.12.2 dsl struct sk_softc *sc;
1942 1.10.12.2 dsl int i;
1943 1.10.12.2 dsl
1944 1.10.12.2 dsl sc = sc_if->sk_softc;
1945 1.10.12.2 dsl
1946 1.10.12.2 dsl DPRINTFN(2, ("msk_init_yukon: start: sk_csr=%#x\n",
1947 1.10.12.2 dsl CSR_READ_4(sc_if->sk_softc, SK_CSR)));
1948 1.10.12.2 dsl
1949 1.10.12.2 dsl DPRINTFN(6, ("msk_init_yukon: 1\n"));
1950 1.10.12.2 dsl
1951 1.10.12.2 dsl /* GMAC and GPHY Reset */
1952 1.10.12.2 dsl SK_IF_WRITE_4(sc_if, 0, SK_GMAC_CTRL, SK_GMAC_RESET_SET);
1953 1.10.12.2 dsl SK_IF_WRITE_4(sc_if, 0, SK_GPHY_CTRL, SK_GPHY_RESET_SET);
1954 1.10.12.2 dsl DELAY(1000);
1955 1.10.12.2 dsl
1956 1.10.12.2 dsl DPRINTFN(6, ("msk_init_yukon: 2\n"));
1957 1.10.12.2 dsl
1958 1.10.12.2 dsl SK_IF_WRITE_4(sc_if, 0, SK_GPHY_CTRL, SK_GPHY_RESET_CLEAR);
1959 1.10.12.2 dsl SK_IF_WRITE_4(sc_if, 0, SK_GMAC_CTRL, SK_GMAC_LOOP_OFF |
1960 1.10.12.2 dsl SK_GMAC_PAUSE_ON | SK_GMAC_RESET_CLEAR);
1961 1.10.12.2 dsl
1962 1.10.12.2 dsl DPRINTFN(3, ("msk_init_yukon: gmac_ctrl=%#x\n",
1963 1.10.12.2 dsl SK_IF_READ_4(sc_if, 0, SK_GMAC_CTRL)));
1964 1.10.12.2 dsl
1965 1.10.12.2 dsl DPRINTFN(6, ("msk_init_yukon: 3\n"));
1966 1.10.12.2 dsl
1967 1.10.12.2 dsl /* unused read of the interrupt source register */
1968 1.10.12.2 dsl DPRINTFN(6, ("msk_init_yukon: 4\n"));
1969 1.10.12.2 dsl SK_IF_READ_2(sc_if, 0, SK_GMAC_ISR);
1970 1.10.12.2 dsl
1971 1.10.12.2 dsl DPRINTFN(6, ("msk_init_yukon: 4a\n"));
1972 1.10.12.2 dsl reg = SK_YU_READ_2(sc_if, YUKON_PAR);
1973 1.10.12.2 dsl DPRINTFN(6, ("msk_init_yukon: YUKON_PAR=%#x\n", reg));
1974 1.10.12.2 dsl
1975 1.10.12.2 dsl /* MIB Counter Clear Mode set */
1976 1.10.12.2 dsl reg |= YU_PAR_MIB_CLR;
1977 1.10.12.2 dsl DPRINTFN(6, ("msk_init_yukon: YUKON_PAR=%#x\n", reg));
1978 1.10.12.2 dsl DPRINTFN(6, ("msk_init_yukon: 4b\n"));
1979 1.10.12.2 dsl SK_YU_WRITE_2(sc_if, YUKON_PAR, reg);
1980 1.10.12.2 dsl
1981 1.10.12.2 dsl /* MIB Counter Clear Mode clear */
1982 1.10.12.2 dsl DPRINTFN(6, ("msk_init_yukon: 5\n"));
1983 1.10.12.2 dsl reg &= ~YU_PAR_MIB_CLR;
1984 1.10.12.2 dsl SK_YU_WRITE_2(sc_if, YUKON_PAR, reg);
1985 1.10.12.2 dsl
1986 1.10.12.2 dsl /* receive control reg */
1987 1.10.12.2 dsl DPRINTFN(6, ("msk_init_yukon: 7\n"));
1988 1.10.12.2 dsl SK_YU_WRITE_2(sc_if, YUKON_RCR, YU_RCR_CRCR);
1989 1.10.12.2 dsl
1990 1.10.12.2 dsl /* transmit control register */
1991 1.10.12.2 dsl SK_YU_WRITE_2(sc_if, YUKON_TCR, (0x04 << 10));
1992 1.10.12.2 dsl
1993 1.10.12.2 dsl /* transmit flow control register */
1994 1.10.12.2 dsl SK_YU_WRITE_2(sc_if, YUKON_TFCR, 0xffff);
1995 1.10.12.2 dsl
1996 1.10.12.2 dsl /* transmit parameter register */
1997 1.10.12.2 dsl DPRINTFN(6, ("msk_init_yukon: 8\n"));
1998 1.10.12.2 dsl SK_YU_WRITE_2(sc_if, YUKON_TPR, YU_TPR_JAM_LEN(0x3) |
1999 1.10.12.2 dsl YU_TPR_JAM_IPG(0xb) | YU_TPR_JAM2DATA_IPG(0x1c) | 0x04);
2000 1.10.12.2 dsl
2001 1.10.12.2 dsl /* serial mode register */
2002 1.10.12.2 dsl DPRINTFN(6, ("msk_init_yukon: 9\n"));
2003 1.10.12.2 dsl reg = YU_SMR_DATA_BLIND(0x1c) |
2004 1.10.12.2 dsl YU_SMR_MFL_VLAN |
2005 1.10.12.2 dsl YU_SMR_IPG_DATA(0x1e);
2006 1.10.12.2 dsl
2007 1.10.12.2 dsl if (sc->sk_type != SK_YUKON_FE)
2008 1.10.12.2 dsl reg |= YU_SMR_MFL_JUMBO;
2009 1.10.12.2 dsl
2010 1.10.12.2 dsl SK_YU_WRITE_2(sc_if, YUKON_SMR, reg);
2011 1.10.12.2 dsl
2012 1.10.12.2 dsl DPRINTFN(6, ("msk_init_yukon: 10\n"));
2013 1.10.12.2 dsl /* Setup Yukon's address */
2014 1.10.12.2 dsl for (i = 0; i < 3; i++) {
2015 1.10.12.2 dsl /* Write Source Address 1 (unicast filter) */
2016 1.10.12.2 dsl SK_YU_WRITE_2(sc_if, YUKON_SAL1 + i * 4,
2017 1.10.12.2 dsl sc_if->sk_enaddr[i * 2] |
2018 1.10.12.2 dsl sc_if->sk_enaddr[i * 2 + 1] << 8);
2019 1.10.12.2 dsl }
2020 1.10.12.2 dsl
2021 1.10.12.2 dsl for (i = 0; i < 3; i++) {
2022 1.10.12.2 dsl reg = sk_win_read_2(sc_if->sk_softc,
2023 1.10.12.2 dsl SK_MAC1_0 + i * 2 + sc_if->sk_port * 8);
2024 1.10.12.2 dsl SK_YU_WRITE_2(sc_if, YUKON_SAL2 + i * 4, reg);
2025 1.10.12.2 dsl }
2026 1.10.12.2 dsl
2027 1.10.12.2 dsl /* Set promiscuous mode */
2028 1.10.12.2 dsl msk_setpromisc(sc_if);
2029 1.10.12.2 dsl
2030 1.10.12.2 dsl /* Set multicast filter */
2031 1.10.12.2 dsl DPRINTFN(6, ("msk_init_yukon: 11\n"));
2032 1.10.12.2 dsl msk_setmulti(sc_if);
2033 1.10.12.2 dsl
2034 1.10.12.2 dsl /* enable interrupt mask for counter overflows */
2035 1.10.12.2 dsl DPRINTFN(6, ("msk_init_yukon: 12\n"));
2036 1.10.12.2 dsl SK_YU_WRITE_2(sc_if, YUKON_TIMR, 0);
2037 1.10.12.2 dsl SK_YU_WRITE_2(sc_if, YUKON_RIMR, 0);
2038 1.10.12.2 dsl SK_YU_WRITE_2(sc_if, YUKON_TRIMR, 0);
2039 1.10.12.2 dsl
2040 1.10.12.2 dsl /* Configure RX MAC FIFO Flush Mask */
2041 1.10.12.2 dsl v = YU_RXSTAT_FOFL | YU_RXSTAT_CRCERR | YU_RXSTAT_MIIERR |
2042 1.10.12.2 dsl YU_RXSTAT_BADFC | YU_RXSTAT_GOODFC | YU_RXSTAT_RUNT |
2043 1.10.12.2 dsl YU_RXSTAT_JABBER;
2044 1.10.12.2 dsl SK_IF_WRITE_2(sc_if, 0, SK_RXMF1_FLUSH_MASK, v);
2045 1.10.12.2 dsl
2046 1.10.12.2 dsl /* Configure RX MAC FIFO */
2047 1.10.12.2 dsl SK_IF_WRITE_1(sc_if, 0, SK_RXMF1_CTRL_TEST, SK_RFCTL_RESET_CLEAR);
2048 1.10.12.2 dsl SK_IF_WRITE_2(sc_if, 0, SK_RXMF1_CTRL_TEST, SK_RFCTL_OPERATION_ON |
2049 1.10.12.2 dsl SK_RFCTL_FIFO_FLUSH_ON);
2050 1.10.12.2 dsl
2051 1.10.12.2 dsl /* Increase flush threshould to 64 bytes */
2052 1.10.12.2 dsl SK_IF_WRITE_2(sc_if, 0, SK_RXMF1_FLUSH_THRESHOLD,
2053 1.10.12.2 dsl SK_RFCTL_FIFO_THRESHOLD + 1);
2054 1.10.12.2 dsl
2055 1.10.12.2 dsl /* Configure TX MAC FIFO */
2056 1.10.12.2 dsl SK_IF_WRITE_1(sc_if, 0, SK_TXMF1_CTRL_TEST, SK_TFCTL_RESET_CLEAR);
2057 1.10.12.2 dsl SK_IF_WRITE_2(sc_if, 0, SK_TXMF1_CTRL_TEST, SK_TFCTL_OPERATION_ON);
2058 1.10.12.2 dsl
2059 1.10.12.2 dsl #if 1
2060 1.10.12.2 dsl SK_YU_WRITE_2(sc_if, YUKON_GPCR, YU_GPCR_TXEN | YU_GPCR_RXEN);
2061 1.10.12.2 dsl #endif
2062 1.10.12.2 dsl DPRINTFN(6, ("msk_init_yukon: end\n"));
2063 1.10.12.2 dsl }
2064 1.10.12.2 dsl
2065 1.10.12.2 dsl /*
2066 1.10.12.2 dsl * Note that to properly initialize any part of the GEnesis chip,
2067 1.10.12.2 dsl * you first have to take it out of reset mode.
2068 1.10.12.2 dsl */
2069 1.10.12.2 dsl int
2070 1.10.12.2 dsl msk_init(struct ifnet *ifp)
2071 1.10.12.2 dsl {
2072 1.10.12.2 dsl struct sk_if_softc *sc_if = ifp->if_softc;
2073 1.10.12.2 dsl struct sk_softc *sc = sc_if->sk_softc;
2074 1.10.12.2 dsl struct mii_data *mii = &sc_if->sk_mii;
2075 1.10.12.2 dsl int s;
2076 1.10.12.2 dsl uint32_t imr, imtimer_ticks;
2077 1.10.12.2 dsl
2078 1.10.12.2 dsl
2079 1.10.12.2 dsl DPRINTFN(2, ("msk_init\n"));
2080 1.10.12.2 dsl
2081 1.10.12.2 dsl s = splnet();
2082 1.10.12.2 dsl
2083 1.10.12.2 dsl /* Cancel pending I/O and free all RX/TX buffers. */
2084 1.10.12.2 dsl msk_stop(ifp,0);
2085 1.10.12.2 dsl
2086 1.10.12.2 dsl /* Configure I2C registers */
2087 1.10.12.2 dsl
2088 1.10.12.2 dsl /* Configure XMAC(s) */
2089 1.10.12.2 dsl msk_init_yukon(sc_if);
2090 1.10.12.2 dsl mii_mediachg(mii);
2091 1.10.12.2 dsl
2092 1.10.12.2 dsl /* Configure transmit arbiter(s) */
2093 1.10.12.2 dsl SK_IF_WRITE_1(sc_if, 0, SK_TXAR1_COUNTERCTL, SK_TXARCTL_ON);
2094 1.10.12.2 dsl #if 0
2095 1.10.12.2 dsl SK_TXARCTL_ON|SK_TXARCTL_FSYNC_ON);
2096 1.10.12.2 dsl #endif
2097 1.10.12.2 dsl
2098 1.10.12.2 dsl /* Configure RAMbuffers */
2099 1.10.12.2 dsl SK_IF_WRITE_4(sc_if, 0, SK_RXRB1_CTLTST, SK_RBCTL_UNRESET);
2100 1.10.12.2 dsl SK_IF_WRITE_4(sc_if, 0, SK_RXRB1_START, sc_if->sk_rx_ramstart);
2101 1.10.12.2 dsl SK_IF_WRITE_4(sc_if, 0, SK_RXRB1_WR_PTR, sc_if->sk_rx_ramstart);
2102 1.10.12.2 dsl SK_IF_WRITE_4(sc_if, 0, SK_RXRB1_RD_PTR, sc_if->sk_rx_ramstart);
2103 1.10.12.2 dsl SK_IF_WRITE_4(sc_if, 0, SK_RXRB1_END, sc_if->sk_rx_ramend);
2104 1.10.12.2 dsl SK_IF_WRITE_4(sc_if, 0, SK_RXRB1_CTLTST, SK_RBCTL_ON);
2105 1.10.12.2 dsl
2106 1.10.12.2 dsl SK_IF_WRITE_4(sc_if, 1, SK_TXRBA1_CTLTST, SK_RBCTL_UNRESET);
2107 1.10.12.2 dsl SK_IF_WRITE_4(sc_if, 1, SK_TXRBA1_CTLTST, SK_RBCTL_STORENFWD_ON);
2108 1.10.12.2 dsl SK_IF_WRITE_4(sc_if, 1, SK_TXRBA1_START, sc_if->sk_tx_ramstart);
2109 1.10.12.2 dsl SK_IF_WRITE_4(sc_if, 1, SK_TXRBA1_WR_PTR, sc_if->sk_tx_ramstart);
2110 1.10.12.2 dsl SK_IF_WRITE_4(sc_if, 1, SK_TXRBA1_RD_PTR, sc_if->sk_tx_ramstart);
2111 1.10.12.2 dsl SK_IF_WRITE_4(sc_if, 1, SK_TXRBA1_END, sc_if->sk_tx_ramend);
2112 1.10.12.2 dsl SK_IF_WRITE_4(sc_if, 1, SK_TXRBA1_CTLTST, SK_RBCTL_ON);
2113 1.10.12.2 dsl
2114 1.10.12.2 dsl /* Configure BMUs */
2115 1.10.12.2 dsl SK_IF_WRITE_4(sc_if, 0, SK_RXQ1_BMU_CSR, 0x00000016);
2116 1.10.12.2 dsl SK_IF_WRITE_4(sc_if, 0, SK_RXQ1_BMU_CSR, 0x00000d28);
2117 1.10.12.2 dsl SK_IF_WRITE_4(sc_if, 0, SK_RXQ1_BMU_CSR, 0x00000080);
2118 1.10.12.2 dsl SK_IF_WRITE_2(sc_if, 0, SK_RXQ1_Y2_WM, 0x0600); /* XXX ??? */
2119 1.10.12.2 dsl
2120 1.10.12.2 dsl SK_IF_WRITE_4(sc_if, 1, SK_TXQA1_BMU_CSR, 0x00000016);
2121 1.10.12.2 dsl SK_IF_WRITE_4(sc_if, 1, SK_TXQA1_BMU_CSR, 0x00000d28);
2122 1.10.12.2 dsl SK_IF_WRITE_4(sc_if, 1, SK_TXQA1_BMU_CSR, 0x00000080);
2123 1.10.12.2 dsl SK_IF_WRITE_2(sc_if, 1, SK_TXQA1_Y2_WM, 0x0600); /* XXX ??? */
2124 1.10.12.2 dsl
2125 1.10.12.2 dsl /* Make sure the sync transmit queue is disabled. */
2126 1.10.12.2 dsl SK_IF_WRITE_4(sc_if, 1, SK_TXRBS1_CTLTST, SK_RBCTL_RESET);
2127 1.10.12.2 dsl
2128 1.10.12.2 dsl /* Init descriptors */
2129 1.10.12.2 dsl if (msk_init_rx_ring(sc_if) == ENOBUFS) {
2130 1.10.12.2 dsl aprint_error("%s: initialization failed: no "
2131 1.10.12.2 dsl "memory for rx buffers\n", sc_if->sk_dev.dv_xname);
2132 1.10.12.2 dsl msk_stop(ifp,0);
2133 1.10.12.2 dsl splx(s);
2134 1.10.12.2 dsl return ENOBUFS;
2135 1.10.12.2 dsl }
2136 1.10.12.2 dsl
2137 1.10.12.2 dsl if (msk_init_tx_ring(sc_if) == ENOBUFS) {
2138 1.10.12.2 dsl aprint_error("%s: initialization failed: no "
2139 1.10.12.2 dsl "memory for tx buffers\n", sc_if->sk_dev.dv_xname);
2140 1.10.12.2 dsl msk_stop(ifp,0);
2141 1.10.12.2 dsl splx(s);
2142 1.10.12.2 dsl return ENOBUFS;
2143 1.10.12.2 dsl }
2144 1.10.12.2 dsl
2145 1.10.12.2 dsl /* Set interrupt moderation if changed via sysctl. */
2146 1.10.12.2 dsl switch (sc->sk_type) {
2147 1.10.12.2 dsl case SK_YUKON_EC:
2148 1.10.12.2 dsl case SK_YUKON_EC_U:
2149 1.10.12.2 dsl imtimer_ticks = SK_IMTIMER_TICKS_YUKON_EC;
2150 1.10.12.2 dsl break;
2151 1.10.12.2 dsl case SK_YUKON_FE:
2152 1.10.12.2 dsl imtimer_ticks = SK_IMTIMER_TICKS_YUKON_FE;
2153 1.10.12.2 dsl break;
2154 1.10.12.2 dsl case SK_YUKON_XL:
2155 1.10.12.2 dsl imtimer_ticks = SK_IMTIMER_TICKS_YUKON_XL;
2156 1.10.12.2 dsl break;
2157 1.10.12.2 dsl default:
2158 1.10.12.2 dsl imtimer_ticks = SK_IMTIMER_TICKS_YUKON;
2159 1.10.12.2 dsl }
2160 1.10.12.2 dsl imr = sk_win_read_4(sc, SK_IMTIMERINIT);
2161 1.10.12.2 dsl if (imr != SK_IM_USECS(sc->sk_int_mod)) {
2162 1.10.12.2 dsl sk_win_write_4(sc, SK_IMTIMERINIT,
2163 1.10.12.2 dsl SK_IM_USECS(sc->sk_int_mod));
2164 1.10.12.2 dsl aprint_verbose("%s: interrupt moderation is %d us\n",
2165 1.10.12.2 dsl sc->sk_dev.dv_xname, sc->sk_int_mod);
2166 1.10.12.2 dsl }
2167 1.10.12.2 dsl
2168 1.10.12.2 dsl /* Initialize prefetch engine. */
2169 1.10.12.2 dsl SK_IF_WRITE_4(sc_if, 0, SK_RXQ1_Y2_PREF_CSR, 0x00000001);
2170 1.10.12.2 dsl SK_IF_WRITE_4(sc_if, 0, SK_RXQ1_Y2_PREF_CSR, 0x00000002);
2171 1.10.12.2 dsl SK_IF_WRITE_2(sc_if, 0, SK_RXQ1_Y2_PREF_LIDX, MSK_RX_RING_CNT - 1);
2172 1.10.12.2 dsl SK_IF_WRITE_4(sc_if, 0, SK_RXQ1_Y2_PREF_ADDRLO,
2173 1.10.12.2 dsl MSK_RX_RING_ADDR(sc_if, 0));
2174 1.10.12.2 dsl SK_IF_WRITE_4(sc_if, 0, SK_RXQ1_Y2_PREF_ADDRHI,
2175 1.10.12.2 dsl (u_int64_t)MSK_RX_RING_ADDR(sc_if, 0) >> 32);
2176 1.10.12.2 dsl SK_IF_WRITE_4(sc_if, 0, SK_RXQ1_Y2_PREF_CSR, 0x00000008);
2177 1.10.12.2 dsl SK_IF_READ_4(sc_if, 0, SK_RXQ1_Y2_PREF_CSR);
2178 1.10.12.2 dsl
2179 1.10.12.2 dsl SK_IF_WRITE_4(sc_if, 1, SK_TXQA1_Y2_PREF_CSR, 0x00000001);
2180 1.10.12.2 dsl SK_IF_WRITE_4(sc_if, 1, SK_TXQA1_Y2_PREF_CSR, 0x00000002);
2181 1.10.12.2 dsl SK_IF_WRITE_2(sc_if, 1, SK_TXQA1_Y2_PREF_LIDX, MSK_TX_RING_CNT - 1);
2182 1.10.12.2 dsl SK_IF_WRITE_4(sc_if, 1, SK_TXQA1_Y2_PREF_ADDRLO,
2183 1.10.12.2 dsl MSK_TX_RING_ADDR(sc_if, 0));
2184 1.10.12.2 dsl SK_IF_WRITE_4(sc_if, 1, SK_TXQA1_Y2_PREF_ADDRHI,
2185 1.10.12.2 dsl (u_int64_t)MSK_TX_RING_ADDR(sc_if, 0) >> 32);
2186 1.10.12.2 dsl SK_IF_WRITE_4(sc_if, 1, SK_TXQA1_Y2_PREF_CSR, 0x00000008);
2187 1.10.12.2 dsl SK_IF_READ_4(sc_if, 1, SK_TXQA1_Y2_PREF_CSR);
2188 1.10.12.2 dsl
2189 1.10.12.2 dsl SK_IF_WRITE_2(sc_if, 0, SK_RXQ1_Y2_PREF_PUTIDX,
2190 1.10.12.2 dsl sc_if->sk_cdata.sk_rx_prod);
2191 1.10.12.2 dsl
2192 1.10.12.2 dsl /* Configure interrupt handling */
2193 1.10.12.2 dsl if (sc_if->sk_port == SK_PORT_A)
2194 1.10.12.2 dsl sc->sk_intrmask |= SK_Y2_INTRS1;
2195 1.10.12.2 dsl else
2196 1.10.12.2 dsl sc->sk_intrmask |= SK_Y2_INTRS2;
2197 1.10.12.2 dsl sc->sk_intrmask |= SK_Y2_IMR_BMU;
2198 1.10.12.2 dsl CSR_WRITE_4(sc, SK_IMR, sc->sk_intrmask);
2199 1.10.12.2 dsl
2200 1.10.12.2 dsl ifp->if_flags |= IFF_RUNNING;
2201 1.10.12.2 dsl ifp->if_flags &= ~IFF_OACTIVE;
2202 1.10.12.2 dsl
2203 1.10.12.2 dsl callout_schedule(&sc_if->sk_tick_ch, hz);
2204 1.10.12.2 dsl
2205 1.10.12.2 dsl splx(s);
2206 1.10.12.2 dsl return 0;
2207 1.10.12.2 dsl }
2208 1.10.12.2 dsl
2209 1.10.12.2 dsl void
2210 1.10.12.2 dsl msk_stop(struct ifnet *ifp, int disable)
2211 1.10.12.2 dsl {
2212 1.10.12.2 dsl struct sk_if_softc *sc_if = ifp->if_softc;
2213 1.10.12.2 dsl struct sk_softc *sc = sc_if->sk_softc;
2214 1.10.12.2 dsl struct sk_txmap_entry *dma;
2215 1.10.12.2 dsl int i;
2216 1.10.12.2 dsl
2217 1.10.12.2 dsl DPRINTFN(2, ("msk_stop\n"));
2218 1.10.12.2 dsl
2219 1.10.12.2 dsl callout_stop(&sc_if->sk_tick_ch);
2220 1.10.12.2 dsl
2221 1.10.12.2 dsl ifp->if_flags &= ~(IFF_RUNNING|IFF_OACTIVE);
2222 1.10.12.2 dsl
2223 1.10.12.2 dsl /* Stop transfer of Tx descriptors */
2224 1.10.12.2 dsl
2225 1.10.12.2 dsl /* Stop transfer of Rx descriptors */
2226 1.10.12.2 dsl
2227 1.10.12.2 dsl /* Turn off various components of this interface. */
2228 1.10.12.2 dsl SK_XM_SETBIT_2(sc_if, XM_GPIO, XM_GPIO_RESETMAC);
2229 1.10.12.2 dsl SK_IF_WRITE_1(sc_if,0, SK_RXMF1_CTRL_TEST, SK_RFCTL_RESET_SET);
2230 1.10.12.2 dsl SK_IF_WRITE_1(sc_if,0, SK_TXMF1_CTRL_TEST, SK_TFCTL_RESET_SET);
2231 1.10.12.2 dsl SK_IF_WRITE_4(sc_if, 0, SK_RXQ1_BMU_CSR, SK_RXBMU_OFFLINE);
2232 1.10.12.2 dsl SK_IF_WRITE_4(sc_if, 0, SK_RXRB1_CTLTST, SK_RBCTL_RESET|SK_RBCTL_OFF);
2233 1.10.12.2 dsl SK_IF_WRITE_4(sc_if, 1, SK_TXQA1_BMU_CSR, SK_TXBMU_OFFLINE);
2234 1.10.12.2 dsl SK_IF_WRITE_4(sc_if, 1, SK_TXRBA1_CTLTST, SK_RBCTL_RESET|SK_RBCTL_OFF);
2235 1.10.12.2 dsl SK_IF_WRITE_1(sc_if, 0, SK_TXAR1_COUNTERCTL, SK_TXARCTL_OFF);
2236 1.10.12.2 dsl SK_IF_WRITE_1(sc_if, 0, SK_RXLED1_CTL, SK_RXLEDCTL_COUNTER_STOP);
2237 1.10.12.2 dsl SK_IF_WRITE_1(sc_if, 0, SK_TXLED1_CTL, SK_TXLEDCTL_COUNTER_STOP);
2238 1.10.12.2 dsl SK_IF_WRITE_1(sc_if, 0, SK_LINKLED1_CTL, SK_LINKLED_OFF);
2239 1.10.12.2 dsl SK_IF_WRITE_1(sc_if, 0, SK_LINKLED1_CTL, SK_LINKLED_LINKSYNC_OFF);
2240 1.10.12.2 dsl
2241 1.10.12.2 dsl SK_IF_WRITE_4(sc_if, 0, SK_RXQ1_Y2_PREF_CSR, 0x00000001);
2242 1.10.12.2 dsl SK_IF_WRITE_4(sc_if, 1, SK_TXQA1_Y2_PREF_CSR, 0x00000001);
2243 1.10.12.2 dsl
2244 1.10.12.2 dsl /* Disable interrupts */
2245 1.10.12.2 dsl if (sc_if->sk_port == SK_PORT_A)
2246 1.10.12.2 dsl sc->sk_intrmask &= ~SK_Y2_INTRS1;
2247 1.10.12.2 dsl else
2248 1.10.12.2 dsl sc->sk_intrmask &= ~SK_Y2_INTRS2;
2249 1.10.12.2 dsl CSR_WRITE_4(sc, SK_IMR, sc->sk_intrmask);
2250 1.10.12.2 dsl
2251 1.10.12.2 dsl SK_XM_READ_2(sc_if, XM_ISR);
2252 1.10.12.2 dsl SK_XM_WRITE_2(sc_if, XM_IMR, 0xFFFF);
2253 1.10.12.2 dsl
2254 1.10.12.2 dsl /* Free RX and TX mbufs still in the queues. */
2255 1.10.12.2 dsl for (i = 0; i < MSK_RX_RING_CNT; i++) {
2256 1.10.12.2 dsl if (sc_if->sk_cdata.sk_rx_chain[i].sk_mbuf != NULL) {
2257 1.10.12.2 dsl m_freem(sc_if->sk_cdata.sk_rx_chain[i].sk_mbuf);
2258 1.10.12.2 dsl sc_if->sk_cdata.sk_rx_chain[i].sk_mbuf = NULL;
2259 1.10.12.2 dsl }
2260 1.10.12.2 dsl }
2261 1.10.12.2 dsl
2262 1.10.12.2 dsl for (i = 0; i < MSK_TX_RING_CNT; i++) {
2263 1.10.12.2 dsl if (sc_if->sk_cdata.sk_tx_chain[i].sk_mbuf != NULL) {
2264 1.10.12.2 dsl m_freem(sc_if->sk_cdata.sk_tx_chain[i].sk_mbuf);
2265 1.10.12.2 dsl sc_if->sk_cdata.sk_tx_chain[i].sk_mbuf = NULL;
2266 1.10.12.2 dsl #if 1
2267 1.10.12.2 dsl SIMPLEQ_INSERT_HEAD(&sc_if->sk_txmap_head,
2268 1.10.12.2 dsl sc_if->sk_cdata.sk_tx_map[i], link);
2269 1.10.12.2 dsl sc_if->sk_cdata.sk_tx_map[i] = 0;
2270 1.10.12.2 dsl #endif
2271 1.10.12.2 dsl }
2272 1.10.12.2 dsl }
2273 1.10.12.2 dsl
2274 1.10.12.2 dsl #if 1
2275 1.10.12.2 dsl while ((dma = SIMPLEQ_FIRST(&sc_if->sk_txmap_head))) {
2276 1.10.12.2 dsl SIMPLEQ_REMOVE_HEAD(&sc_if->sk_txmap_head, link);
2277 1.10.12.2 dsl bus_dmamap_destroy(sc->sc_dmatag, dma->dmamap);
2278 1.10.12.2 dsl free(dma, M_DEVBUF);
2279 1.10.12.2 dsl }
2280 1.10.12.2 dsl #endif
2281 1.10.12.2 dsl }
2282 1.10.12.2 dsl
2283 1.10.12.2 dsl CFATTACH_DECL(mskc, sizeof(struct sk_softc), mskc_probe, mskc_attach,
2284 1.10.12.2 dsl NULL, NULL);
2285 1.10.12.2 dsl
2286 1.10.12.2 dsl CFATTACH_DECL(msk, sizeof(struct sk_if_softc), msk_probe, msk_attach,
2287 1.10.12.2 dsl NULL, NULL);
2288 1.10.12.2 dsl
2289 1.10.12.2 dsl #ifdef MSK_DEBUG
2290 1.10.12.2 dsl void
2291 1.10.12.2 dsl msk_dump_txdesc(struct msk_tx_desc *le, int idx)
2292 1.10.12.2 dsl {
2293 1.10.12.2 dsl #define DESC_PRINT(X) \
2294 1.10.12.2 dsl if (X) \
2295 1.10.12.2 dsl printf("txdesc[%d]." #X "=%#x\n", \
2296 1.10.12.2 dsl idx, X);
2297 1.10.12.2 dsl
2298 1.10.12.2 dsl DESC_PRINT(letoh32(le->sk_addr));
2299 1.10.12.2 dsl DESC_PRINT(letoh16(le->sk_len));
2300 1.10.12.2 dsl DESC_PRINT(le->sk_ctl);
2301 1.10.12.2 dsl DESC_PRINT(le->sk_opcode);
2302 1.10.12.2 dsl #undef DESC_PRINT
2303 1.10.12.2 dsl }
2304 1.10.12.2 dsl
2305 1.10.12.2 dsl void
2306 1.10.12.2 dsl msk_dump_bytes(const char *data, int len)
2307 1.10.12.2 dsl {
2308 1.10.12.2 dsl int c, i, j;
2309 1.10.12.2 dsl
2310 1.10.12.2 dsl for (i = 0; i < len; i += 16) {
2311 1.10.12.2 dsl printf("%08x ", i);
2312 1.10.12.2 dsl c = len - i;
2313 1.10.12.2 dsl if (c > 16) c = 16;
2314 1.10.12.2 dsl
2315 1.10.12.2 dsl for (j = 0; j < c; j++) {
2316 1.10.12.2 dsl printf("%02x ", data[i + j] & 0xff);
2317 1.10.12.2 dsl if ((j & 0xf) == 7 && j > 0)
2318 1.10.12.2 dsl printf(" ");
2319 1.10.12.2 dsl }
2320 1.10.12.2 dsl
2321 1.10.12.2 dsl for (; j < 16; j++)
2322 1.10.12.2 dsl printf(" ");
2323 1.10.12.2 dsl printf(" ");
2324 1.10.12.2 dsl
2325 1.10.12.2 dsl for (j = 0; j < c; j++) {
2326 1.10.12.2 dsl int ch = data[i + j] & 0xff;
2327 1.10.12.2 dsl printf("%c", ' ' <= ch && ch <= '~' ? ch : ' ');
2328 1.10.12.2 dsl }
2329 1.10.12.2 dsl
2330 1.10.12.2 dsl printf("\n");
2331 1.10.12.2 dsl
2332 1.10.12.2 dsl if (c < 16)
2333 1.10.12.2 dsl break;
2334 1.10.12.2 dsl }
2335 1.10.12.2 dsl }
2336 1.10.12.2 dsl
2337 1.10.12.2 dsl void
2338 1.10.12.2 dsl msk_dump_mbuf(struct mbuf *m)
2339 1.10.12.2 dsl {
2340 1.10.12.2 dsl int count = m->m_pkthdr.len;
2341 1.10.12.2 dsl
2342 1.10.12.2 dsl printf("m=%p, m->m_pkthdr.len=%d\n", m, m->m_pkthdr.len);
2343 1.10.12.2 dsl
2344 1.10.12.2 dsl while (count > 0 && m) {
2345 1.10.12.2 dsl printf("m=%p, m->m_data=%p, m->m_len=%d\n",
2346 1.10.12.2 dsl m, m->m_data, m->m_len);
2347 1.10.12.2 dsl msk_dump_bytes(mtod(m, char *), m->m_len);
2348 1.10.12.2 dsl
2349 1.10.12.2 dsl count -= m->m_len;
2350 1.10.12.2 dsl m = m->m_next;
2351 1.10.12.2 dsl }
2352 1.10.12.2 dsl }
2353 1.10.12.2 dsl #endif
2354 1.10.12.2 dsl
2355 1.10.12.2 dsl static int
2356 1.10.12.2 dsl msk_sysctl_handler(SYSCTLFN_ARGS)
2357 1.10.12.2 dsl {
2358 1.10.12.2 dsl int error, t;
2359 1.10.12.2 dsl struct sysctlnode node;
2360 1.10.12.2 dsl struct sk_softc *sc;
2361 1.10.12.2 dsl
2362 1.10.12.2 dsl node = *rnode;
2363 1.10.12.2 dsl sc = node.sysctl_data;
2364 1.10.12.2 dsl t = sc->sk_int_mod;
2365 1.10.12.2 dsl node.sysctl_data = &t;
2366 1.10.12.2 dsl error = sysctl_lookup(SYSCTLFN_CALL(&node));
2367 1.10.12.2 dsl if (error || newp == NULL)
2368 1.10.12.2 dsl return error;
2369 1.10.12.2 dsl
2370 1.10.12.2 dsl if (t < SK_IM_MIN || t > SK_IM_MAX)
2371 1.10.12.2 dsl return EINVAL;
2372 1.10.12.2 dsl
2373 1.10.12.2 dsl /* update the softc with sysctl-changed value, and mark
2374 1.10.12.2 dsl for hardware update */
2375 1.10.12.2 dsl sc->sk_int_mod = t;
2376 1.10.12.2 dsl sc->sk_int_mod_pending = 1;
2377 1.10.12.2 dsl return 0;
2378 1.10.12.2 dsl }
2379 1.10.12.2 dsl
2380 1.10.12.2 dsl /*
2381 1.10.12.2 dsl * Set up sysctl(3) MIB, hw.sk.* - Individual controllers will be
2382 1.10.12.2 dsl * set up in skc_attach()
2383 1.10.12.2 dsl */
2384 1.10.12.2 dsl SYSCTL_SETUP(sysctl_msk, "sysctl msk subtree setup")
2385 1.10.12.2 dsl {
2386 1.10.12.2 dsl int rc;
2387 1.10.12.2 dsl const struct sysctlnode *node;
2388 1.10.12.2 dsl
2389 1.10.12.2 dsl if ((rc = sysctl_createv(clog, 0, NULL, NULL,
2390 1.10.12.2 dsl 0, CTLTYPE_NODE, "hw", NULL,
2391 1.10.12.2 dsl NULL, 0, NULL, 0, CTL_HW, CTL_EOL)) != 0) {
2392 1.10.12.2 dsl goto err;
2393 1.10.12.2 dsl }
2394 1.10.12.2 dsl
2395 1.10.12.2 dsl if ((rc = sysctl_createv(clog, 0, NULL, &node,
2396 1.10.12.2 dsl 0, CTLTYPE_NODE, "msk",
2397 1.10.12.2 dsl SYSCTL_DESCR("msk interface controls"),
2398 1.10.12.2 dsl NULL, 0, NULL, 0, CTL_HW, CTL_CREATE, CTL_EOL)) != 0) {
2399 1.10.12.2 dsl goto err;
2400 1.10.12.2 dsl }
2401 1.10.12.2 dsl
2402 1.10.12.2 dsl msk_root_num = node->sysctl_num;
2403 1.10.12.2 dsl return;
2404 1.10.12.2 dsl
2405 1.10.12.2 dsl err:
2406 1.10.12.2 dsl aprint_error("%s: syctl_createv failed (rc = %d)\n", __func__, rc);
2407 1.10.12.2 dsl }
2408