if_vte.c revision 1.1.4.4 1 1.1.4.2 rmind /* $NetBSD: if_vte.c,v 1.1.4.4 2011/05/31 03:04:41 rmind Exp $ */
2 1.1.4.2 rmind
3 1.1.4.2 rmind /*
4 1.1.4.2 rmind * Copyright (c) 2011 Manuel Bouyer. All rights reserved.
5 1.1.4.2 rmind *
6 1.1.4.2 rmind * Redistribution and use in source and binary forms, with or without
7 1.1.4.2 rmind * modification, are permitted provided that the following conditions
8 1.1.4.2 rmind * are met:
9 1.1.4.2 rmind * 1. Redistributions of source code must retain the above copyright
10 1.1.4.2 rmind * notice, this list of conditions and the following disclaimer.
11 1.1.4.2 rmind * 2. Redistributions in binary form must reproduce the above copyright
12 1.1.4.2 rmind * notice, this list of conditions and the following disclaimer in the
13 1.1.4.2 rmind * documentation and/or other materials provided with the distribution.
14 1.1.4.2 rmind *
15 1.1.4.2 rmind * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 1.1.4.2 rmind * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 1.1.4.2 rmind * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 1.1.4.2 rmind * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19 1.1.4.2 rmind * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 1.1.4.2 rmind * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 1.1.4.2 rmind * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 1.1.4.2 rmind * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 1.1.4.2 rmind * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 1.1.4.2 rmind * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 1.1.4.2 rmind */
26 1.1.4.2 rmind
27 1.1.4.2 rmind /*-
28 1.1.4.2 rmind * Copyright (c) 2010, Pyun YongHyeon <yongari (at) FreeBSD.org>
29 1.1.4.2 rmind * All rights reserved.
30 1.1.4.2 rmind *
31 1.1.4.2 rmind * Redistribution and use in source and binary forms, with or without
32 1.1.4.2 rmind * modification, are permitted provided that the following conditions
33 1.1.4.2 rmind * are met:
34 1.1.4.2 rmind * 1. Redistributions of source code must retain the above copyright
35 1.1.4.2 rmind * notice unmodified, this list of conditions, and the following
36 1.1.4.2 rmind * disclaimer.
37 1.1.4.2 rmind * 2. Redistributions in binary form must reproduce the above copyright
38 1.1.4.2 rmind * notice, this list of conditions and the following disclaimer in the
39 1.1.4.2 rmind * documentation and/or other materials provided with the distribution.
40 1.1.4.2 rmind *
41 1.1.4.2 rmind * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
42 1.1.4.2 rmind * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 1.1.4.2 rmind * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 1.1.4.2 rmind * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 1.1.4.2 rmind * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 1.1.4.2 rmind * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 1.1.4.2 rmind * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 1.1.4.2 rmind * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 1.1.4.2 rmind * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 1.1.4.2 rmind * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 1.1.4.2 rmind * SUCH DAMAGE.
52 1.1.4.2 rmind */
53 1.1.4.2 rmind /* FreeBSD: src/sys/dev/vte/if_vte.c,v 1.2 2010/12/31 01:23:04 yongari Exp */
54 1.1.4.2 rmind
55 1.1.4.2 rmind /* Driver for DM&P Electronics, Inc, Vortex86 RDC R6040 FastEthernet. */
56 1.1.4.2 rmind
57 1.1.4.2 rmind #include <sys/cdefs.h>
58 1.1.4.2 rmind __KERNEL_RCSID(0, "$NetBSD: if_vte.c,v 1.1.4.4 2011/05/31 03:04:41 rmind Exp $");
59 1.1.4.2 rmind
60 1.1.4.2 rmind #include <sys/param.h>
61 1.1.4.2 rmind #include <sys/systm.h>
62 1.1.4.2 rmind #include <sys/mbuf.h>
63 1.1.4.2 rmind #include <sys/protosw.h>
64 1.1.4.2 rmind #include <sys/socket.h>
65 1.1.4.2 rmind #include <sys/ioctl.h>
66 1.1.4.2 rmind #include <sys/errno.h>
67 1.1.4.2 rmind #include <sys/malloc.h>
68 1.1.4.2 rmind #include <sys/kernel.h>
69 1.1.4.2 rmind #include <sys/device.h>
70 1.1.4.2 rmind #include <sys/sysctl.h>
71 1.1.4.2 rmind
72 1.1.4.2 rmind #include <net/if.h>
73 1.1.4.2 rmind #include <net/if_media.h>
74 1.1.4.2 rmind #include <net/if_types.h>
75 1.1.4.2 rmind #include <net/if_dl.h>
76 1.1.4.2 rmind #include <net/route.h>
77 1.1.4.2 rmind #include <net/netisr.h>
78 1.1.4.2 rmind
79 1.1.4.2 rmind #include <net/bpf.h>
80 1.1.4.2 rmind #include <net/bpfdesc.h>
81 1.1.4.2 rmind
82 1.1.4.2 rmind #include "rnd.h"
83 1.1.4.2 rmind #if NRND > 0
84 1.1.4.2 rmind #include <sys/rnd.h>
85 1.1.4.2 rmind #endif
86 1.1.4.2 rmind
87 1.1.4.2 rmind #include "opt_inet.h"
88 1.1.4.2 rmind #include <net/if_ether.h>
89 1.1.4.2 rmind #ifdef INET
90 1.1.4.2 rmind #include <netinet/in.h>
91 1.1.4.2 rmind #include <netinet/in_systm.h>
92 1.1.4.2 rmind #include <netinet/in_var.h>
93 1.1.4.2 rmind #include <netinet/ip.h>
94 1.1.4.2 rmind #include <netinet/if_inarp.h>
95 1.1.4.2 rmind #endif
96 1.1.4.2 rmind
97 1.1.4.2 rmind #include <sys/bus.h>
98 1.1.4.2 rmind #include <sys/intr.h>
99 1.1.4.2 rmind
100 1.1.4.2 rmind #include <dev/pci/pcireg.h>
101 1.1.4.2 rmind #include <dev/pci/pcivar.h>
102 1.1.4.2 rmind #include <dev/pci/pcidevs.h>
103 1.1.4.2 rmind
104 1.1.4.2 rmind #include <dev/mii/mii.h>
105 1.1.4.2 rmind #include <dev/mii/miivar.h>
106 1.1.4.2 rmind
107 1.1.4.2 rmind #include <dev/pci/if_vtereg.h>
108 1.1.4.2 rmind #include <dev/pci/if_vtevar.h>
109 1.1.4.2 rmind
110 1.1.4.2 rmind static int vte_match(device_t, cfdata_t, void *);
111 1.1.4.2 rmind static void vte_attach(device_t, device_t, void *);
112 1.1.4.2 rmind static int vte_detach(device_t, int);
113 1.1.4.2 rmind static int vte_dma_alloc(struct vte_softc *);
114 1.1.4.2 rmind static void vte_dma_free(struct vte_softc *);
115 1.1.4.2 rmind static struct vte_txdesc *
116 1.1.4.2 rmind vte_encap(struct vte_softc *, struct mbuf **);
117 1.1.4.2 rmind static void vte_get_macaddr(struct vte_softc *);
118 1.1.4.2 rmind static int vte_init(struct ifnet *);
119 1.1.4.2 rmind static int vte_init_rx_ring(struct vte_softc *);
120 1.1.4.2 rmind static int vte_init_tx_ring(struct vte_softc *);
121 1.1.4.2 rmind static int vte_intr(void *);
122 1.1.4.2 rmind static int vte_ifioctl(struct ifnet *, u_long, void *);
123 1.1.4.2 rmind static void vte_mac_config(struct vte_softc *);
124 1.1.4.2 rmind static int vte_miibus_readreg(device_t, int, int);
125 1.1.4.2 rmind static void vte_miibus_statchg(device_t);
126 1.1.4.2 rmind static void vte_miibus_writereg(device_t, int, int, int);
127 1.1.4.2 rmind static int vte_mediachange(struct ifnet *);
128 1.1.4.2 rmind static int vte_newbuf(struct vte_softc *, struct vte_rxdesc *);
129 1.1.4.2 rmind static void vte_reset(struct vte_softc *);
130 1.1.4.2 rmind static void vte_rxeof(struct vte_softc *);
131 1.1.4.2 rmind static void vte_rxfilter(struct vte_softc *);
132 1.1.4.2 rmind static bool vte_shutdown(device_t, int);
133 1.1.4.2 rmind static bool vte_suspend(device_t, const pmf_qual_t *);
134 1.1.4.2 rmind static bool vte_resume(device_t, const pmf_qual_t *);
135 1.1.4.2 rmind static void vte_ifstart(struct ifnet *);
136 1.1.4.2 rmind static void vte_start_mac(struct vte_softc *);
137 1.1.4.2 rmind static void vte_stats_clear(struct vte_softc *);
138 1.1.4.2 rmind static void vte_stats_update(struct vte_softc *);
139 1.1.4.2 rmind static void vte_stop(struct ifnet *, int);
140 1.1.4.2 rmind static void vte_stop_mac(struct vte_softc *);
141 1.1.4.2 rmind static void vte_tick(void *);
142 1.1.4.2 rmind static void vte_txeof(struct vte_softc *);
143 1.1.4.2 rmind static void vte_ifwatchdog(struct ifnet *);
144 1.1.4.2 rmind
145 1.1.4.2 rmind static int vte_sysctl_intrxct(SYSCTLFN_PROTO);
146 1.1.4.2 rmind static int vte_sysctl_inttxct(SYSCTLFN_PROTO);
147 1.1.4.2 rmind static int vte_root_num;
148 1.1.4.2 rmind
149 1.1.4.2 rmind #define DPRINTF(a)
150 1.1.4.2 rmind
151 1.1.4.2 rmind CFATTACH_DECL3_NEW(vte, sizeof(struct vte_softc),
152 1.1.4.2 rmind vte_match, vte_attach, vte_detach, NULL, NULL, NULL, DVF_DETACH_SHUTDOWN);
153 1.1.4.2 rmind
154 1.1.4.2 rmind
155 1.1.4.2 rmind static int
156 1.1.4.2 rmind vte_match(device_t parent, cfdata_t cf, void *aux)
157 1.1.4.2 rmind {
158 1.1.4.2 rmind struct pci_attach_args *pa = (struct pci_attach_args *)aux;
159 1.1.4.2 rmind
160 1.1.4.2 rmind if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_RDC &&
161 1.1.4.2 rmind PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_RDC_R6040)
162 1.1.4.2 rmind return 1;
163 1.1.4.2 rmind
164 1.1.4.2 rmind return 0;
165 1.1.4.2 rmind }
166 1.1.4.2 rmind
167 1.1.4.2 rmind static void
168 1.1.4.2 rmind vte_attach(device_t parent, device_t self, void *aux)
169 1.1.4.2 rmind {
170 1.1.4.2 rmind struct vte_softc *sc = device_private(self);
171 1.1.4.2 rmind struct pci_attach_args * const pa = (struct pci_attach_args *)aux;
172 1.1.4.2 rmind struct ifnet * const ifp = &sc->vte_if;
173 1.1.4.2 rmind int h_valid;
174 1.1.4.2 rmind pcireg_t reg, csr;
175 1.1.4.2 rmind pci_intr_handle_t intrhandle;
176 1.1.4.2 rmind const char *intrstr;
177 1.1.4.2 rmind int error;
178 1.1.4.2 rmind char devinfo[256];
179 1.1.4.2 rmind const struct sysctlnode *node;
180 1.1.4.2 rmind int vte_nodenum;
181 1.1.4.2 rmind
182 1.1.4.2 rmind sc->vte_dev = self;
183 1.1.4.2 rmind aprint_normal("\n");
184 1.1.4.2 rmind
185 1.1.4.2 rmind callout_init(&sc->vte_tick_ch, 0);
186 1.1.4.2 rmind
187 1.1.4.2 rmind /* Map the device. */
188 1.1.4.2 rmind h_valid = 0;
189 1.1.4.2 rmind reg = pci_conf_read(pa->pa_pc, pa->pa_tag, VTE_PCI_BMEM);
190 1.1.4.2 rmind if (PCI_MAPREG_TYPE(reg) == PCI_MAPREG_TYPE_MEM) {
191 1.1.4.2 rmind h_valid = (pci_mapreg_map(pa, VTE_PCI_BMEM,
192 1.1.4.2 rmind PCI_MAPREG_TYPE_MEM | PCI_MAPREG_MEM_TYPE_32BIT,
193 1.1.4.2 rmind 0, &sc->vte_bustag, &sc->vte_bushandle, NULL, NULL) == 0);
194 1.1.4.2 rmind }
195 1.1.4.2 rmind if (h_valid == 0) {
196 1.1.4.2 rmind reg = pci_conf_read(pa->pa_pc, pa->pa_tag, VTE_PCI_BIO);
197 1.1.4.2 rmind if (PCI_MAPREG_TYPE(reg) == PCI_MAPREG_TYPE_IO) {
198 1.1.4.2 rmind h_valid = (pci_mapreg_map(pa, VTE_PCI_BIO,
199 1.1.4.2 rmind PCI_MAPREG_TYPE_IO, 0, &sc->vte_bustag,
200 1.1.4.2 rmind &sc->vte_bushandle, NULL, NULL) == 0);
201 1.1.4.2 rmind }
202 1.1.4.2 rmind }
203 1.1.4.2 rmind if (h_valid == 0) {
204 1.1.4.2 rmind aprint_error_dev(self, "unable to map device registers\n");
205 1.1.4.2 rmind return;
206 1.1.4.2 rmind }
207 1.1.4.2 rmind sc->vte_dmatag = pa->pa_dmat;
208 1.1.4.2 rmind /* Enable the device. */
209 1.1.4.2 rmind csr = pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG);
210 1.1.4.2 rmind pci_conf_write(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG,
211 1.1.4.2 rmind csr | PCI_COMMAND_MASTER_ENABLE);
212 1.1.4.2 rmind
213 1.1.4.2 rmind pci_devinfo(pa->pa_id, pa->pa_class, 0, devinfo, sizeof(devinfo));
214 1.1.4.2 rmind aprint_normal_dev(self, "%s\n", devinfo);
215 1.1.4.2 rmind
216 1.1.4.2 rmind /* Reset the ethernet controller. */
217 1.1.4.2 rmind vte_reset(sc);
218 1.1.4.2 rmind
219 1.1.4.3 rmind if ((error = vte_dma_alloc(sc)) != 0)
220 1.1.4.2 rmind return;
221 1.1.4.2 rmind
222 1.1.4.2 rmind /* Load station address. */
223 1.1.4.2 rmind vte_get_macaddr(sc);
224 1.1.4.2 rmind
225 1.1.4.2 rmind aprint_normal_dev(self, "Ethernet address %s\n",
226 1.1.4.2 rmind ether_sprintf(sc->vte_eaddr));
227 1.1.4.2 rmind
228 1.1.4.2 rmind /* Map and establish interrupts */
229 1.1.4.2 rmind if (pci_intr_map(pa, &intrhandle)) {
230 1.1.4.2 rmind aprint_error_dev(self, "couldn't map interrupt\n");
231 1.1.4.2 rmind return;
232 1.1.4.2 rmind }
233 1.1.4.2 rmind intrstr = pci_intr_string(pa->pa_pc, intrhandle);
234 1.1.4.2 rmind sc->vte_ih = pci_intr_establish(pa->pa_pc, intrhandle, IPL_NET,
235 1.1.4.2 rmind vte_intr, sc);
236 1.1.4.2 rmind if (sc->vte_ih == NULL) {
237 1.1.4.2 rmind aprint_error_dev(self, "couldn't establish interrupt");
238 1.1.4.2 rmind if (intrstr != NULL)
239 1.1.4.2 rmind aprint_error(" at %s", intrstr);
240 1.1.4.2 rmind aprint_error("\n");
241 1.1.4.2 rmind return;
242 1.1.4.2 rmind }
243 1.1.4.2 rmind aprint_normal_dev(self, "interrupting at %s\n", intrstr);
244 1.1.4.2 rmind
245 1.1.4.2 rmind sc->vte_if.if_softc = sc;
246 1.1.4.2 rmind sc->vte_mii.mii_ifp = ifp;
247 1.1.4.2 rmind sc->vte_mii.mii_readreg = vte_miibus_readreg;
248 1.1.4.2 rmind sc->vte_mii.mii_writereg = vte_miibus_writereg;
249 1.1.4.2 rmind sc->vte_mii.mii_statchg = vte_miibus_statchg;
250 1.1.4.2 rmind sc->vte_ec.ec_mii = &sc->vte_mii;
251 1.1.4.2 rmind ifmedia_init(&sc->vte_mii.mii_media, IFM_IMASK, vte_mediachange,
252 1.1.4.2 rmind ether_mediastatus);
253 1.1.4.2 rmind mii_attach(self, &sc->vte_mii, 0xffffffff, MII_PHY_ANY,
254 1.1.4.2 rmind MII_OFFSET_ANY, 0);
255 1.1.4.2 rmind if (LIST_FIRST(&sc->vte_mii.mii_phys) == NULL) {
256 1.1.4.2 rmind ifmedia_add(&sc->vte_mii.mii_media, IFM_ETHER|IFM_NONE, 0, NULL);
257 1.1.4.2 rmind ifmedia_set(&sc->vte_mii.mii_media, IFM_ETHER|IFM_NONE);
258 1.1.4.2 rmind } else
259 1.1.4.2 rmind ifmedia_set(&sc->vte_mii.mii_media, IFM_ETHER|IFM_AUTO);
260 1.1.4.2 rmind
261 1.1.4.2 rmind /*
262 1.1.4.2 rmind * We can support 802.1Q VLAN-sized frames.
263 1.1.4.2 rmind */
264 1.1.4.2 rmind sc->vte_ec.ec_capabilities |= ETHERCAP_VLAN_MTU;
265 1.1.4.2 rmind
266 1.1.4.2 rmind strlcpy(ifp->if_xname, device_xname(self), IFNAMSIZ);
267 1.1.4.2 rmind ifp->if_flags = IFF_BROADCAST|IFF_SIMPLEX|IFF_NOTRAILERS|IFF_MULTICAST;
268 1.1.4.2 rmind ifp->if_ioctl = vte_ifioctl;
269 1.1.4.2 rmind ifp->if_start = vte_ifstart;
270 1.1.4.2 rmind ifp->if_watchdog = vte_ifwatchdog;
271 1.1.4.2 rmind ifp->if_init = vte_init;
272 1.1.4.2 rmind ifp->if_stop = vte_stop;
273 1.1.4.2 rmind ifp->if_timer = 0;
274 1.1.4.2 rmind IFQ_SET_READY(&ifp->if_snd);
275 1.1.4.2 rmind if_attach(ifp);
276 1.1.4.2 rmind ether_ifattach(&(sc)->vte_if, (sc)->vte_eaddr);
277 1.1.4.2 rmind
278 1.1.4.2 rmind if (pmf_device_register1(self, vte_suspend, vte_resume, vte_shutdown))
279 1.1.4.2 rmind pmf_class_network_register(self, ifp);
280 1.1.4.2 rmind else
281 1.1.4.2 rmind aprint_error_dev(self, "couldn't establish power handler\n");
282 1.1.4.2 rmind
283 1.1.4.2 rmind #if NRND > 0
284 1.1.4.2 rmind rnd_attach_source(&sc->rnd_source, device_xname(self),
285 1.1.4.2 rmind RND_TYPE_NET, 0);
286 1.1.4.2 rmind #endif
287 1.1.4.2 rmind if (sysctl_createv(&sc->vte_clog, 0, NULL, &node,
288 1.1.4.2 rmind 0, CTLTYPE_NODE, device_xname(sc->vte_dev),
289 1.1.4.2 rmind SYSCTL_DESCR("vte per-controller controls"),
290 1.1.4.2 rmind NULL, 0, NULL, 0, CTL_HW, vte_root_num, CTL_CREATE,
291 1.1.4.2 rmind CTL_EOL) != 0) {
292 1.1.4.2 rmind aprint_normal_dev(sc->vte_dev, "couldn't create sysctl node\n");
293 1.1.4.2 rmind return;
294 1.1.4.2 rmind }
295 1.1.4.2 rmind vte_nodenum = node->sysctl_num;
296 1.1.4.2 rmind if (sysctl_createv(&sc->vte_clog, 0, NULL, &node,
297 1.1.4.2 rmind CTLFLAG_READWRITE,
298 1.1.4.2 rmind CTLTYPE_INT, "int_rxct",
299 1.1.4.2 rmind SYSCTL_DESCR("vte RX interrupt moderation packet counter"),
300 1.1.4.2 rmind vte_sysctl_intrxct, 0, sc,
301 1.1.4.2 rmind 0, CTL_HW, vte_root_num, vte_nodenum, CTL_CREATE,
302 1.1.4.2 rmind CTL_EOL) != 0) {
303 1.1.4.2 rmind aprint_normal_dev(sc->vte_dev,
304 1.1.4.2 rmind "couldn't create int_rxct sysctl node\n");
305 1.1.4.2 rmind }
306 1.1.4.2 rmind if (sysctl_createv(&sc->vte_clog, 0, NULL, &node,
307 1.1.4.2 rmind CTLFLAG_READWRITE,
308 1.1.4.2 rmind CTLTYPE_INT, "int_txct",
309 1.1.4.2 rmind SYSCTL_DESCR("vte TX interrupt moderation packet counter"),
310 1.1.4.2 rmind vte_sysctl_inttxct, 0, sc,
311 1.1.4.2 rmind 0, CTL_HW, vte_root_num, vte_nodenum, CTL_CREATE,
312 1.1.4.2 rmind CTL_EOL) != 0) {
313 1.1.4.2 rmind aprint_normal_dev(sc->vte_dev,
314 1.1.4.2 rmind "couldn't create int_txct sysctl node\n");
315 1.1.4.2 rmind }
316 1.1.4.2 rmind }
317 1.1.4.2 rmind
318 1.1.4.2 rmind static int
319 1.1.4.2 rmind vte_detach(device_t dev, int flags __unused)
320 1.1.4.2 rmind {
321 1.1.4.2 rmind struct vte_softc *sc = device_private(dev);
322 1.1.4.2 rmind struct ifnet *ifp = &sc->vte_if;
323 1.1.4.2 rmind int s;
324 1.1.4.2 rmind
325 1.1.4.2 rmind s = splnet();
326 1.1.4.2 rmind /* Stop the interface. Callouts are stopped in it. */
327 1.1.4.2 rmind vte_stop(ifp, 1);
328 1.1.4.2 rmind splx(s);
329 1.1.4.2 rmind
330 1.1.4.2 rmind pmf_device_deregister(dev);
331 1.1.4.2 rmind
332 1.1.4.2 rmind mii_detach(&sc->vte_mii, MII_PHY_ANY, MII_OFFSET_ANY);
333 1.1.4.2 rmind ifmedia_delete_instance(&sc->vte_mii.mii_media, IFM_INST_ANY);
334 1.1.4.2 rmind
335 1.1.4.2 rmind ether_ifdetach(ifp);
336 1.1.4.2 rmind if_detach(ifp);
337 1.1.4.2 rmind
338 1.1.4.2 rmind vte_dma_free(sc);
339 1.1.4.2 rmind
340 1.1.4.2 rmind return (0);
341 1.1.4.2 rmind }
342 1.1.4.2 rmind
343 1.1.4.2 rmind static int
344 1.1.4.2 rmind vte_miibus_readreg(device_t dev, int phy, int reg)
345 1.1.4.2 rmind {
346 1.1.4.2 rmind struct vte_softc *sc = device_private(dev);
347 1.1.4.2 rmind int i;
348 1.1.4.2 rmind
349 1.1.4.2 rmind CSR_WRITE_2(sc, VTE_MMDIO, MMDIO_READ |
350 1.1.4.2 rmind (phy << MMDIO_PHY_ADDR_SHIFT) | (reg << MMDIO_REG_ADDR_SHIFT));
351 1.1.4.2 rmind for (i = VTE_PHY_TIMEOUT; i > 0; i--) {
352 1.1.4.2 rmind DELAY(5);
353 1.1.4.2 rmind if ((CSR_READ_2(sc, VTE_MMDIO) & MMDIO_READ) == 0)
354 1.1.4.2 rmind break;
355 1.1.4.2 rmind }
356 1.1.4.2 rmind
357 1.1.4.2 rmind if (i == 0) {
358 1.1.4.2 rmind aprint_error_dev(sc->vte_dev, "phy read timeout : %d\n", reg);
359 1.1.4.2 rmind return (0);
360 1.1.4.2 rmind }
361 1.1.4.2 rmind
362 1.1.4.2 rmind return (CSR_READ_2(sc, VTE_MMRD));
363 1.1.4.2 rmind }
364 1.1.4.2 rmind
365 1.1.4.2 rmind static void
366 1.1.4.2 rmind vte_miibus_writereg(device_t dev, int phy, int reg, int val)
367 1.1.4.2 rmind {
368 1.1.4.2 rmind struct vte_softc *sc = device_private(dev);
369 1.1.4.2 rmind int i;
370 1.1.4.2 rmind
371 1.1.4.2 rmind CSR_WRITE_2(sc, VTE_MMWD, val);
372 1.1.4.2 rmind CSR_WRITE_2(sc, VTE_MMDIO, MMDIO_WRITE |
373 1.1.4.2 rmind (phy << MMDIO_PHY_ADDR_SHIFT) | (reg << MMDIO_REG_ADDR_SHIFT));
374 1.1.4.2 rmind for (i = VTE_PHY_TIMEOUT; i > 0; i--) {
375 1.1.4.2 rmind DELAY(5);
376 1.1.4.2 rmind if ((CSR_READ_2(sc, VTE_MMDIO) & MMDIO_WRITE) == 0)
377 1.1.4.2 rmind break;
378 1.1.4.2 rmind }
379 1.1.4.2 rmind
380 1.1.4.2 rmind if (i == 0)
381 1.1.4.2 rmind aprint_error_dev(sc->vte_dev, "phy write timeout : %d\n", reg);
382 1.1.4.2 rmind
383 1.1.4.2 rmind }
384 1.1.4.2 rmind
385 1.1.4.2 rmind static void
386 1.1.4.2 rmind vte_miibus_statchg(device_t dev)
387 1.1.4.2 rmind {
388 1.1.4.2 rmind struct vte_softc *sc = device_private(dev);
389 1.1.4.2 rmind struct ifnet *ifp;
390 1.1.4.2 rmind uint16_t val;
391 1.1.4.2 rmind
392 1.1.4.2 rmind ifp = &sc->vte_if;
393 1.1.4.2 rmind
394 1.1.4.2 rmind DPRINTF(("vte_miibus_statchg 0x%x 0x%x\n",
395 1.1.4.2 rmind sc->vte_mii.mii_media_status, sc->vte_mii.mii_media_active));
396 1.1.4.2 rmind
397 1.1.4.2 rmind sc->vte_flags &= ~VTE_FLAG_LINK;
398 1.1.4.2 rmind if ((sc->vte_mii.mii_media_status & (IFM_ACTIVE | IFM_AVALID)) ==
399 1.1.4.2 rmind (IFM_ACTIVE | IFM_AVALID)) {
400 1.1.4.2 rmind switch (IFM_SUBTYPE(sc->vte_mii.mii_media_active)) {
401 1.1.4.2 rmind case IFM_10_T:
402 1.1.4.2 rmind case IFM_100_TX:
403 1.1.4.2 rmind sc->vte_flags |= VTE_FLAG_LINK;
404 1.1.4.2 rmind break;
405 1.1.4.2 rmind default:
406 1.1.4.2 rmind break;
407 1.1.4.2 rmind }
408 1.1.4.2 rmind }
409 1.1.4.2 rmind
410 1.1.4.2 rmind /* Stop RX/TX MACs. */
411 1.1.4.2 rmind vte_stop_mac(sc);
412 1.1.4.2 rmind /* Program MACs with resolved duplex and flow control. */
413 1.1.4.2 rmind if ((sc->vte_flags & VTE_FLAG_LINK) != 0) {
414 1.1.4.2 rmind /*
415 1.1.4.2 rmind * Timer waiting time : (63 + TIMER * 64) MII clock.
416 1.1.4.2 rmind * MII clock : 25MHz(100Mbps) or 2.5MHz(10Mbps).
417 1.1.4.2 rmind */
418 1.1.4.2 rmind if (IFM_SUBTYPE(sc->vte_mii.mii_media_active) == IFM_100_TX)
419 1.1.4.2 rmind val = 18 << VTE_IM_TIMER_SHIFT;
420 1.1.4.2 rmind else
421 1.1.4.2 rmind val = 1 << VTE_IM_TIMER_SHIFT;
422 1.1.4.2 rmind val |= sc->vte_int_rx_mod << VTE_IM_BUNDLE_SHIFT;
423 1.1.4.2 rmind /* 48.6us for 100Mbps, 50.8us for 10Mbps */
424 1.1.4.2 rmind CSR_WRITE_2(sc, VTE_MRICR, val);
425 1.1.4.2 rmind
426 1.1.4.2 rmind if (IFM_SUBTYPE(sc->vte_mii.mii_media_active) == IFM_100_TX)
427 1.1.4.2 rmind val = 18 << VTE_IM_TIMER_SHIFT;
428 1.1.4.2 rmind else
429 1.1.4.2 rmind val = 1 << VTE_IM_TIMER_SHIFT;
430 1.1.4.2 rmind val |= sc->vte_int_tx_mod << VTE_IM_BUNDLE_SHIFT;
431 1.1.4.2 rmind /* 48.6us for 100Mbps, 50.8us for 10Mbps */
432 1.1.4.2 rmind CSR_WRITE_2(sc, VTE_MTICR, val);
433 1.1.4.2 rmind
434 1.1.4.2 rmind vte_mac_config(sc);
435 1.1.4.2 rmind vte_start_mac(sc);
436 1.1.4.2 rmind DPRINTF(("vte_miibus_statchg: link\n"));
437 1.1.4.2 rmind }
438 1.1.4.2 rmind }
439 1.1.4.2 rmind
440 1.1.4.2 rmind static void
441 1.1.4.2 rmind vte_get_macaddr(struct vte_softc *sc)
442 1.1.4.2 rmind {
443 1.1.4.2 rmind uint16_t mid;
444 1.1.4.2 rmind
445 1.1.4.2 rmind /*
446 1.1.4.2 rmind * It seems there is no way to reload station address and
447 1.1.4.2 rmind * it is supposed to be set by BIOS.
448 1.1.4.2 rmind */
449 1.1.4.2 rmind mid = CSR_READ_2(sc, VTE_MID0L);
450 1.1.4.2 rmind sc->vte_eaddr[0] = (mid >> 0) & 0xFF;
451 1.1.4.2 rmind sc->vte_eaddr[1] = (mid >> 8) & 0xFF;
452 1.1.4.2 rmind mid = CSR_READ_2(sc, VTE_MID0M);
453 1.1.4.2 rmind sc->vte_eaddr[2] = (mid >> 0) & 0xFF;
454 1.1.4.2 rmind sc->vte_eaddr[3] = (mid >> 8) & 0xFF;
455 1.1.4.2 rmind mid = CSR_READ_2(sc, VTE_MID0H);
456 1.1.4.2 rmind sc->vte_eaddr[4] = (mid >> 0) & 0xFF;
457 1.1.4.2 rmind sc->vte_eaddr[5] = (mid >> 8) & 0xFF;
458 1.1.4.2 rmind }
459 1.1.4.2 rmind
460 1.1.4.2 rmind
461 1.1.4.2 rmind static int
462 1.1.4.2 rmind vte_dma_alloc(struct vte_softc *sc)
463 1.1.4.2 rmind {
464 1.1.4.2 rmind struct vte_txdesc *txd;
465 1.1.4.2 rmind struct vte_rxdesc *rxd;
466 1.1.4.2 rmind int error, i, rseg;
467 1.1.4.2 rmind
468 1.1.4.2 rmind /* create DMA map for TX ring */
469 1.1.4.2 rmind error = bus_dmamap_create(sc->vte_dmatag, VTE_TX_RING_SZ, 1,
470 1.1.4.2 rmind VTE_TX_RING_SZ, 0, BUS_DMA_NOWAIT | BUS_DMA_ALLOCNOW,
471 1.1.4.2 rmind &sc->vte_cdata.vte_tx_ring_map);
472 1.1.4.2 rmind if (error) {
473 1.1.4.2 rmind aprint_error_dev(sc->vte_dev,
474 1.1.4.2 rmind "could not create dma map for TX ring (%d)\n",
475 1.1.4.2 rmind error);
476 1.1.4.2 rmind goto fail;
477 1.1.4.2 rmind }
478 1.1.4.2 rmind /* Allocate and map DMA'able memory and load the DMA map for TX ring. */
479 1.1.4.2 rmind error = bus_dmamem_alloc(sc->vte_dmatag, VTE_TX_RING_SZ,
480 1.1.4.2 rmind VTE_TX_RING_ALIGN, 0,
481 1.1.4.2 rmind sc->vte_cdata.vte_tx_ring_seg, 1, &rseg,
482 1.1.4.2 rmind BUS_DMA_NOWAIT);
483 1.1.4.2 rmind if (error != 0) {
484 1.1.4.2 rmind aprint_error_dev(sc->vte_dev,
485 1.1.4.2 rmind "could not allocate DMA'able memory for TX ring (%d).\n",
486 1.1.4.2 rmind error);
487 1.1.4.2 rmind goto fail;
488 1.1.4.2 rmind }
489 1.1.4.2 rmind KASSERT(rseg == 1);
490 1.1.4.2 rmind error = bus_dmamem_map(sc->vte_dmatag,
491 1.1.4.2 rmind sc->vte_cdata.vte_tx_ring_seg, 1,
492 1.1.4.2 rmind VTE_TX_RING_SZ, (void **)(&sc->vte_cdata.vte_tx_ring),
493 1.1.4.2 rmind BUS_DMA_NOWAIT | BUS_DMA_COHERENT);
494 1.1.4.2 rmind if (error != 0) {
495 1.1.4.2 rmind aprint_error_dev(sc->vte_dev,
496 1.1.4.2 rmind "could not map DMA'able memory for TX ring (%d).\n",
497 1.1.4.2 rmind error);
498 1.1.4.2 rmind goto fail;
499 1.1.4.2 rmind }
500 1.1.4.2 rmind memset(sc->vte_cdata.vte_tx_ring, 0, VTE_TX_RING_SZ);
501 1.1.4.2 rmind error = bus_dmamap_load(sc->vte_dmatag,
502 1.1.4.2 rmind sc->vte_cdata.vte_tx_ring_map, sc->vte_cdata.vte_tx_ring,
503 1.1.4.2 rmind VTE_TX_RING_SZ, NULL,
504 1.1.4.2 rmind BUS_DMA_NOWAIT | BUS_DMA_READ | BUS_DMA_WRITE);
505 1.1.4.2 rmind if (error != 0) {
506 1.1.4.2 rmind aprint_error_dev(sc->vte_dev,
507 1.1.4.2 rmind "could not load DMA'able memory for TX ring.\n");
508 1.1.4.2 rmind goto fail;
509 1.1.4.2 rmind }
510 1.1.4.2 rmind
511 1.1.4.2 rmind /* create DMA map for RX ring */
512 1.1.4.2 rmind error = bus_dmamap_create(sc->vte_dmatag, VTE_RX_RING_SZ, 1,
513 1.1.4.2 rmind VTE_RX_RING_SZ, 0, BUS_DMA_NOWAIT | BUS_DMA_ALLOCNOW,
514 1.1.4.2 rmind &sc->vte_cdata.vte_rx_ring_map);
515 1.1.4.2 rmind if (error) {
516 1.1.4.2 rmind aprint_error_dev(sc->vte_dev,
517 1.1.4.2 rmind "could not create dma map for RX ring (%d)\n",
518 1.1.4.2 rmind error);
519 1.1.4.2 rmind goto fail;
520 1.1.4.2 rmind }
521 1.1.4.2 rmind /* Allocate and map DMA'able memory and load the DMA map for RX ring. */
522 1.1.4.2 rmind error = bus_dmamem_alloc(sc->vte_dmatag, VTE_RX_RING_SZ,
523 1.1.4.2 rmind VTE_RX_RING_ALIGN, 0,
524 1.1.4.2 rmind sc->vte_cdata.vte_rx_ring_seg, 1, &rseg,
525 1.1.4.2 rmind BUS_DMA_NOWAIT);
526 1.1.4.2 rmind if (error != 0) {
527 1.1.4.2 rmind aprint_error_dev(sc->vte_dev,
528 1.1.4.2 rmind "could not allocate DMA'able memory for RX ring (%d).\n",
529 1.1.4.2 rmind error);
530 1.1.4.2 rmind goto fail;
531 1.1.4.2 rmind }
532 1.1.4.2 rmind KASSERT(rseg == 1);
533 1.1.4.2 rmind error = bus_dmamem_map(sc->vte_dmatag,
534 1.1.4.2 rmind sc->vte_cdata.vte_rx_ring_seg, 1,
535 1.1.4.2 rmind VTE_RX_RING_SZ, (void **)(&sc->vte_cdata.vte_rx_ring),
536 1.1.4.2 rmind BUS_DMA_NOWAIT | BUS_DMA_COHERENT);
537 1.1.4.2 rmind if (error != 0) {
538 1.1.4.2 rmind aprint_error_dev(sc->vte_dev,
539 1.1.4.2 rmind "could not map DMA'able memory for RX ring (%d).\n",
540 1.1.4.2 rmind error);
541 1.1.4.2 rmind goto fail;
542 1.1.4.2 rmind }
543 1.1.4.2 rmind memset(sc->vte_cdata.vte_rx_ring, 0, VTE_RX_RING_SZ);
544 1.1.4.2 rmind error = bus_dmamap_load(sc->vte_dmatag,
545 1.1.4.2 rmind sc->vte_cdata.vte_rx_ring_map, sc->vte_cdata.vte_rx_ring,
546 1.1.4.2 rmind VTE_RX_RING_SZ, NULL,
547 1.1.4.2 rmind BUS_DMA_NOWAIT | BUS_DMA_READ | BUS_DMA_WRITE);
548 1.1.4.2 rmind if (error != 0) {
549 1.1.4.2 rmind aprint_error_dev(sc->vte_dev,
550 1.1.4.2 rmind "could not load DMA'able memory for RX ring (%d).\n",
551 1.1.4.2 rmind error);
552 1.1.4.2 rmind goto fail;
553 1.1.4.2 rmind }
554 1.1.4.2 rmind
555 1.1.4.2 rmind /* Create DMA maps for TX buffers. */
556 1.1.4.2 rmind for (i = 0; i < VTE_TX_RING_CNT; i++) {
557 1.1.4.2 rmind txd = &sc->vte_cdata.vte_txdesc[i];
558 1.1.4.2 rmind txd->tx_m = NULL;
559 1.1.4.2 rmind txd->tx_dmamap = NULL;
560 1.1.4.2 rmind error = bus_dmamap_create(sc->vte_dmatag, MCLBYTES,
561 1.1.4.2 rmind 1, MCLBYTES, 0, BUS_DMA_NOWAIT | BUS_DMA_ALLOCNOW,
562 1.1.4.2 rmind &txd->tx_dmamap);
563 1.1.4.2 rmind if (error != 0) {
564 1.1.4.2 rmind aprint_error_dev(sc->vte_dev,
565 1.1.4.2 rmind "could not create TX DMA map %d (%d).\n", i, error);
566 1.1.4.2 rmind goto fail;
567 1.1.4.2 rmind }
568 1.1.4.2 rmind }
569 1.1.4.2 rmind /* Create DMA maps for RX buffers. */
570 1.1.4.2 rmind if ((error = bus_dmamap_create(sc->vte_dmatag, MCLBYTES,
571 1.1.4.2 rmind 1, MCLBYTES, 0, BUS_DMA_NOWAIT | BUS_DMA_ALLOCNOW,
572 1.1.4.2 rmind &sc->vte_cdata.vte_rx_sparemap)) != 0) {
573 1.1.4.2 rmind aprint_error_dev(sc->vte_dev,
574 1.1.4.2 rmind "could not create spare RX dmamap (%d).\n", error);
575 1.1.4.2 rmind goto fail;
576 1.1.4.2 rmind }
577 1.1.4.2 rmind for (i = 0; i < VTE_RX_RING_CNT; i++) {
578 1.1.4.2 rmind rxd = &sc->vte_cdata.vte_rxdesc[i];
579 1.1.4.2 rmind rxd->rx_m = NULL;
580 1.1.4.2 rmind rxd->rx_dmamap = NULL;
581 1.1.4.2 rmind error = bus_dmamap_create(sc->vte_dmatag, MCLBYTES,
582 1.1.4.2 rmind 1, MCLBYTES, 0, BUS_DMA_NOWAIT | BUS_DMA_ALLOCNOW,
583 1.1.4.2 rmind &rxd->rx_dmamap);
584 1.1.4.2 rmind if (error != 0) {
585 1.1.4.2 rmind aprint_error_dev(sc->vte_dev,
586 1.1.4.2 rmind "could not create RX dmamap %d (%d).\n", i, error);
587 1.1.4.2 rmind goto fail;
588 1.1.4.2 rmind }
589 1.1.4.2 rmind }
590 1.1.4.2 rmind return 0;
591 1.1.4.2 rmind
592 1.1.4.2 rmind fail:
593 1.1.4.2 rmind vte_dma_free(sc);
594 1.1.4.2 rmind return (error);
595 1.1.4.2 rmind }
596 1.1.4.2 rmind
597 1.1.4.2 rmind static void
598 1.1.4.2 rmind vte_dma_free(struct vte_softc *sc)
599 1.1.4.2 rmind {
600 1.1.4.2 rmind struct vte_txdesc *txd;
601 1.1.4.2 rmind struct vte_rxdesc *rxd;
602 1.1.4.2 rmind int i;
603 1.1.4.2 rmind
604 1.1.4.2 rmind /* TX buffers. */
605 1.1.4.2 rmind for (i = 0; i < VTE_TX_RING_CNT; i++) {
606 1.1.4.2 rmind txd = &sc->vte_cdata.vte_txdesc[i];
607 1.1.4.2 rmind if (txd->tx_dmamap != NULL) {
608 1.1.4.2 rmind bus_dmamap_destroy(sc->vte_dmatag, txd->tx_dmamap);
609 1.1.4.2 rmind txd->tx_dmamap = NULL;
610 1.1.4.2 rmind }
611 1.1.4.2 rmind }
612 1.1.4.2 rmind /* RX buffers */
613 1.1.4.2 rmind for (i = 0; i < VTE_RX_RING_CNT; i++) {
614 1.1.4.2 rmind rxd = &sc->vte_cdata.vte_rxdesc[i];
615 1.1.4.2 rmind if (rxd->rx_dmamap != NULL) {
616 1.1.4.2 rmind bus_dmamap_destroy(sc->vte_dmatag, rxd->rx_dmamap);
617 1.1.4.2 rmind rxd->rx_dmamap = NULL;
618 1.1.4.2 rmind }
619 1.1.4.2 rmind }
620 1.1.4.2 rmind if (sc->vte_cdata.vte_rx_sparemap != NULL) {
621 1.1.4.2 rmind bus_dmamap_destroy(sc->vte_dmatag,
622 1.1.4.2 rmind sc->vte_cdata.vte_rx_sparemap);
623 1.1.4.2 rmind sc->vte_cdata.vte_rx_sparemap = NULL;
624 1.1.4.2 rmind }
625 1.1.4.2 rmind /* TX descriptor ring. */
626 1.1.4.2 rmind if (sc->vte_cdata.vte_tx_ring_map != NULL) {
627 1.1.4.2 rmind bus_dmamap_unload(sc->vte_dmatag,
628 1.1.4.2 rmind sc->vte_cdata.vte_tx_ring_map);
629 1.1.4.2 rmind bus_dmamap_destroy(sc->vte_dmatag,
630 1.1.4.2 rmind sc->vte_cdata.vte_tx_ring_map);
631 1.1.4.2 rmind }
632 1.1.4.2 rmind if (sc->vte_cdata.vte_tx_ring != NULL) {
633 1.1.4.2 rmind bus_dmamem_unmap(sc->vte_dmatag,
634 1.1.4.2 rmind sc->vte_cdata.vte_tx_ring, VTE_TX_RING_SZ);
635 1.1.4.2 rmind bus_dmamem_free(sc->vte_dmatag,
636 1.1.4.2 rmind sc->vte_cdata.vte_tx_ring_seg, 1);
637 1.1.4.2 rmind }
638 1.1.4.2 rmind sc->vte_cdata.vte_tx_ring = NULL;
639 1.1.4.2 rmind sc->vte_cdata.vte_tx_ring_map = NULL;
640 1.1.4.2 rmind /* RX ring. */
641 1.1.4.2 rmind if (sc->vte_cdata.vte_rx_ring_map != NULL) {
642 1.1.4.2 rmind bus_dmamap_unload(sc->vte_dmatag,
643 1.1.4.2 rmind sc->vte_cdata.vte_rx_ring_map);
644 1.1.4.2 rmind bus_dmamap_destroy(sc->vte_dmatag,
645 1.1.4.2 rmind sc->vte_cdata.vte_rx_ring_map);
646 1.1.4.2 rmind }
647 1.1.4.2 rmind if (sc->vte_cdata.vte_rx_ring != NULL) {
648 1.1.4.2 rmind bus_dmamem_unmap(sc->vte_dmatag,
649 1.1.4.2 rmind sc->vte_cdata.vte_rx_ring, VTE_RX_RING_SZ);
650 1.1.4.2 rmind bus_dmamem_free(sc->vte_dmatag,
651 1.1.4.2 rmind sc->vte_cdata.vte_rx_ring_seg, 1);
652 1.1.4.2 rmind }
653 1.1.4.2 rmind sc->vte_cdata.vte_rx_ring = NULL;
654 1.1.4.2 rmind sc->vte_cdata.vte_rx_ring_map = NULL;
655 1.1.4.2 rmind }
656 1.1.4.2 rmind
657 1.1.4.2 rmind static bool
658 1.1.4.2 rmind vte_shutdown(device_t dev, int howto)
659 1.1.4.2 rmind {
660 1.1.4.2 rmind
661 1.1.4.2 rmind return (vte_suspend(dev, NULL));
662 1.1.4.2 rmind }
663 1.1.4.2 rmind
664 1.1.4.2 rmind static bool
665 1.1.4.2 rmind vte_suspend(device_t dev, const pmf_qual_t *qual)
666 1.1.4.2 rmind {
667 1.1.4.2 rmind struct vte_softc *sc = device_private(dev);
668 1.1.4.2 rmind struct ifnet *ifp = &sc->vte_if;
669 1.1.4.2 rmind
670 1.1.4.2 rmind DPRINTF(("vte_suspend if_flags 0x%x\n", ifp->if_flags));
671 1.1.4.2 rmind if ((ifp->if_flags & IFF_RUNNING) != 0)
672 1.1.4.2 rmind vte_stop(ifp, 1);
673 1.1.4.2 rmind return (0);
674 1.1.4.2 rmind }
675 1.1.4.2 rmind
676 1.1.4.2 rmind static bool
677 1.1.4.2 rmind vte_resume(device_t dev, const pmf_qual_t *qual)
678 1.1.4.2 rmind {
679 1.1.4.2 rmind struct vte_softc *sc = device_private(dev);
680 1.1.4.2 rmind struct ifnet *ifp;
681 1.1.4.2 rmind
682 1.1.4.2 rmind ifp = &sc->vte_if;
683 1.1.4.2 rmind if ((ifp->if_flags & IFF_UP) != 0) {
684 1.1.4.2 rmind ifp->if_flags &= ~IFF_RUNNING;
685 1.1.4.2 rmind vte_init(ifp);
686 1.1.4.2 rmind }
687 1.1.4.2 rmind
688 1.1.4.2 rmind return (0);
689 1.1.4.2 rmind }
690 1.1.4.2 rmind
691 1.1.4.2 rmind static struct vte_txdesc *
692 1.1.4.2 rmind vte_encap(struct vte_softc *sc, struct mbuf **m_head)
693 1.1.4.2 rmind {
694 1.1.4.2 rmind struct vte_txdesc *txd;
695 1.1.4.2 rmind struct mbuf *m, *n;
696 1.1.4.2 rmind int copy, error, padlen;
697 1.1.4.2 rmind
698 1.1.4.2 rmind txd = &sc->vte_cdata.vte_txdesc[sc->vte_cdata.vte_tx_prod];
699 1.1.4.2 rmind m = *m_head;
700 1.1.4.2 rmind /*
701 1.1.4.2 rmind * Controller doesn't auto-pad, so we have to make sure pad
702 1.1.4.2 rmind * short frames out to the minimum frame length.
703 1.1.4.2 rmind */
704 1.1.4.2 rmind if (m->m_pkthdr.len < VTE_MIN_FRAMELEN)
705 1.1.4.2 rmind padlen = VTE_MIN_FRAMELEN - m->m_pkthdr.len;
706 1.1.4.2 rmind else
707 1.1.4.2 rmind padlen = 0;
708 1.1.4.2 rmind
709 1.1.4.2 rmind /*
710 1.1.4.2 rmind * Controller does not support multi-fragmented TX buffers.
711 1.1.4.2 rmind * Controller spends most of its TX processing time in
712 1.1.4.2 rmind * de-fragmenting TX buffers. Either faster CPU or more
713 1.1.4.2 rmind * advanced controller DMA engine is required to speed up
714 1.1.4.2 rmind * TX path processing.
715 1.1.4.2 rmind * To mitigate the de-fragmenting issue, perform deep copy
716 1.1.4.2 rmind * from fragmented mbuf chains to a pre-allocated mbuf
717 1.1.4.2 rmind * cluster with extra cost of kernel memory. For frames
718 1.1.4.2 rmind * that is composed of single TX buffer, the deep copy is
719 1.1.4.2 rmind * bypassed.
720 1.1.4.2 rmind */
721 1.1.4.2 rmind copy = 0;
722 1.1.4.2 rmind if (m->m_next != NULL)
723 1.1.4.2 rmind copy++;
724 1.1.4.2 rmind if (padlen > 0 && (M_READONLY(m) ||
725 1.1.4.2 rmind padlen > M_TRAILINGSPACE(m)))
726 1.1.4.2 rmind copy++;
727 1.1.4.2 rmind if (copy != 0) {
728 1.1.4.2 rmind n = sc->vte_cdata.vte_txmbufs[sc->vte_cdata.vte_tx_prod];
729 1.1.4.2 rmind m_copydata(m, 0, m->m_pkthdr.len, mtod(n, char *));
730 1.1.4.2 rmind n->m_pkthdr.len = m->m_pkthdr.len;
731 1.1.4.2 rmind n->m_len = m->m_pkthdr.len;
732 1.1.4.2 rmind m = n;
733 1.1.4.2 rmind txd->tx_flags |= VTE_TXMBUF;
734 1.1.4.2 rmind }
735 1.1.4.2 rmind
736 1.1.4.2 rmind if (padlen > 0) {
737 1.1.4.2 rmind /* Zero out the bytes in the pad area. */
738 1.1.4.2 rmind bzero(mtod(m, char *) + m->m_pkthdr.len, padlen);
739 1.1.4.2 rmind m->m_pkthdr.len += padlen;
740 1.1.4.2 rmind m->m_len = m->m_pkthdr.len;
741 1.1.4.2 rmind }
742 1.1.4.2 rmind
743 1.1.4.2 rmind error = bus_dmamap_load_mbuf(sc->vte_dmatag, txd->tx_dmamap, m, 0);
744 1.1.4.2 rmind if (error != 0) {
745 1.1.4.2 rmind txd->tx_flags &= ~VTE_TXMBUF;
746 1.1.4.2 rmind return (NULL);
747 1.1.4.2 rmind }
748 1.1.4.2 rmind KASSERT(txd->tx_dmamap->dm_nsegs == 1);
749 1.1.4.2 rmind bus_dmamap_sync(sc->vte_dmatag, txd->tx_dmamap, 0,
750 1.1.4.2 rmind txd->tx_dmamap->dm_mapsize, BUS_DMASYNC_PREWRITE);
751 1.1.4.2 rmind
752 1.1.4.2 rmind txd->tx_desc->dtlen =
753 1.1.4.2 rmind htole16(VTE_TX_LEN(txd->tx_dmamap->dm_segs[0].ds_len));
754 1.1.4.2 rmind txd->tx_desc->dtbp = htole32(txd->tx_dmamap->dm_segs[0].ds_addr);
755 1.1.4.2 rmind sc->vte_cdata.vte_tx_cnt++;
756 1.1.4.2 rmind /* Update producer index. */
757 1.1.4.2 rmind VTE_DESC_INC(sc->vte_cdata.vte_tx_prod, VTE_TX_RING_CNT);
758 1.1.4.2 rmind
759 1.1.4.2 rmind /* Finally hand over ownership to controller. */
760 1.1.4.2 rmind txd->tx_desc->dtst = htole16(VTE_DTST_TX_OWN);
761 1.1.4.2 rmind txd->tx_m = m;
762 1.1.4.2 rmind
763 1.1.4.2 rmind return (txd);
764 1.1.4.2 rmind }
765 1.1.4.2 rmind
766 1.1.4.2 rmind static void
767 1.1.4.2 rmind vte_ifstart(struct ifnet *ifp)
768 1.1.4.2 rmind {
769 1.1.4.2 rmind struct vte_softc *sc = ifp->if_softc;
770 1.1.4.2 rmind struct vte_txdesc *txd;
771 1.1.4.2 rmind struct mbuf *m_head, *m;
772 1.1.4.2 rmind int enq;
773 1.1.4.2 rmind
774 1.1.4.2 rmind ifp = &sc->vte_if;
775 1.1.4.2 rmind
776 1.1.4.2 rmind DPRINTF(("vte_ifstart 0x%x 0x%x\n", ifp->if_flags, sc->vte_flags));
777 1.1.4.2 rmind
778 1.1.4.2 rmind if ((ifp->if_flags & (IFF_RUNNING | IFF_OACTIVE)) !=
779 1.1.4.2 rmind IFF_RUNNING || (sc->vte_flags & VTE_FLAG_LINK) == 0)
780 1.1.4.2 rmind return;
781 1.1.4.2 rmind
782 1.1.4.2 rmind for (enq = 0; !IFQ_IS_EMPTY(&ifp->if_snd); ) {
783 1.1.4.2 rmind /* Reserve one free TX descriptor. */
784 1.1.4.2 rmind if (sc->vte_cdata.vte_tx_cnt >= VTE_TX_RING_CNT - 1) {
785 1.1.4.2 rmind ifp->if_flags |= IFF_OACTIVE;
786 1.1.4.2 rmind break;
787 1.1.4.2 rmind }
788 1.1.4.2 rmind IFQ_POLL(&ifp->if_snd, m_head);
789 1.1.4.2 rmind if (m_head == NULL)
790 1.1.4.2 rmind break;
791 1.1.4.2 rmind /*
792 1.1.4.2 rmind * Pack the data into the transmit ring. If we
793 1.1.4.2 rmind * don't have room, set the OACTIVE flag and wait
794 1.1.4.2 rmind * for the NIC to drain the ring.
795 1.1.4.2 rmind */
796 1.1.4.2 rmind DPRINTF(("vte_encap:"));
797 1.1.4.2 rmind if ((txd = vte_encap(sc, &m_head)) == NULL) {
798 1.1.4.2 rmind DPRINTF((" failed\n"));
799 1.1.4.2 rmind break;
800 1.1.4.2 rmind }
801 1.1.4.2 rmind DPRINTF((" ok\n"));
802 1.1.4.2 rmind IFQ_DEQUEUE(&ifp->if_snd, m);
803 1.1.4.2 rmind KASSERT(m == m_head);
804 1.1.4.2 rmind
805 1.1.4.2 rmind enq++;
806 1.1.4.2 rmind /*
807 1.1.4.2 rmind * If there's a BPF listener, bounce a copy of this frame
808 1.1.4.2 rmind * to him.
809 1.1.4.2 rmind */
810 1.1.4.2 rmind bpf_mtap(ifp, m_head);
811 1.1.4.2 rmind /* Free consumed TX frame. */
812 1.1.4.2 rmind if ((txd->tx_flags & VTE_TXMBUF) != 0)
813 1.1.4.2 rmind m_freem(m_head);
814 1.1.4.2 rmind }
815 1.1.4.2 rmind
816 1.1.4.2 rmind if (enq > 0) {
817 1.1.4.2 rmind bus_dmamap_sync(sc->vte_dmatag,
818 1.1.4.2 rmind sc->vte_cdata.vte_tx_ring_map, 0,
819 1.1.4.2 rmind sc->vte_cdata.vte_tx_ring_map->dm_mapsize,
820 1.1.4.2 rmind BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
821 1.1.4.2 rmind CSR_WRITE_2(sc, VTE_TX_POLL, TX_POLL_START);
822 1.1.4.2 rmind sc->vte_watchdog_timer = VTE_TX_TIMEOUT;
823 1.1.4.2 rmind }
824 1.1.4.2 rmind }
825 1.1.4.2 rmind
826 1.1.4.2 rmind static void
827 1.1.4.2 rmind vte_ifwatchdog(struct ifnet *ifp)
828 1.1.4.2 rmind {
829 1.1.4.2 rmind struct vte_softc *sc = ifp->if_softc;
830 1.1.4.2 rmind
831 1.1.4.2 rmind if (sc->vte_watchdog_timer == 0 || --sc->vte_watchdog_timer)
832 1.1.4.2 rmind return;
833 1.1.4.2 rmind
834 1.1.4.2 rmind aprint_error_dev(sc->vte_dev, "watchdog timeout -- resetting\n");
835 1.1.4.2 rmind ifp->if_oerrors++;
836 1.1.4.2 rmind vte_init(ifp);
837 1.1.4.2 rmind if (!IFQ_IS_EMPTY(&ifp->if_snd))
838 1.1.4.2 rmind vte_ifstart(ifp);
839 1.1.4.2 rmind }
840 1.1.4.2 rmind
841 1.1.4.2 rmind static int
842 1.1.4.2 rmind vte_mediachange(struct ifnet *ifp)
843 1.1.4.2 rmind {
844 1.1.4.2 rmind int error;
845 1.1.4.2 rmind struct vte_softc *sc = ifp->if_softc;
846 1.1.4.2 rmind
847 1.1.4.2 rmind if ((error = mii_mediachg(&sc->vte_mii)) == ENXIO)
848 1.1.4.2 rmind error = 0;
849 1.1.4.2 rmind else if (error != 0) {
850 1.1.4.2 rmind aprint_error_dev(sc->vte_dev, "could not set media\n");
851 1.1.4.2 rmind return error;
852 1.1.4.2 rmind }
853 1.1.4.2 rmind return 0;
854 1.1.4.2 rmind
855 1.1.4.2 rmind }
856 1.1.4.2 rmind
857 1.1.4.2 rmind static int
858 1.1.4.2 rmind vte_ifioctl(struct ifnet *ifp, u_long cmd, void *data)
859 1.1.4.2 rmind {
860 1.1.4.2 rmind struct vte_softc *sc = ifp->if_softc;
861 1.1.4.2 rmind int error, s;
862 1.1.4.2 rmind
863 1.1.4.2 rmind s = splnet();
864 1.1.4.2 rmind error = ether_ioctl(ifp, cmd, data);
865 1.1.4.2 rmind if (error == ENETRESET) {
866 1.1.4.2 rmind DPRINTF(("vte_ifioctl if_flags 0x%x\n", ifp->if_flags));
867 1.1.4.2 rmind if (ifp->if_flags & IFF_RUNNING)
868 1.1.4.2 rmind vte_rxfilter(sc);
869 1.1.4.2 rmind error = 0;
870 1.1.4.2 rmind }
871 1.1.4.2 rmind splx(s);
872 1.1.4.2 rmind return error;
873 1.1.4.2 rmind }
874 1.1.4.2 rmind
875 1.1.4.2 rmind static void
876 1.1.4.2 rmind vte_mac_config(struct vte_softc *sc)
877 1.1.4.2 rmind {
878 1.1.4.2 rmind uint16_t mcr;
879 1.1.4.2 rmind
880 1.1.4.2 rmind mcr = CSR_READ_2(sc, VTE_MCR0);
881 1.1.4.2 rmind mcr &= ~(MCR0_FC_ENB | MCR0_FULL_DUPLEX);
882 1.1.4.2 rmind if ((IFM_OPTIONS(sc->vte_mii.mii_media_active) & IFM_FDX) != 0) {
883 1.1.4.2 rmind mcr |= MCR0_FULL_DUPLEX;
884 1.1.4.2 rmind #ifdef notyet
885 1.1.4.2 rmind if ((IFM_OPTIONS(sc->vte_mii.mii->mii_media_active) & IFM_ETH_TXPAUSE) != 0)
886 1.1.4.2 rmind mcr |= MCR0_FC_ENB;
887 1.1.4.2 rmind /*
888 1.1.4.2 rmind * The data sheet is not clear whether the controller
889 1.1.4.2 rmind * honors received pause frames or not. The is no
890 1.1.4.2 rmind * separate control bit for RX pause frame so just
891 1.1.4.2 rmind * enable MCR0_FC_ENB bit.
892 1.1.4.2 rmind */
893 1.1.4.2 rmind if ((IFM_OPTIONS(sc->vte_mii.mii->mii_media_active) & IFM_ETH_RXPAUSE) != 0)
894 1.1.4.2 rmind mcr |= MCR0_FC_ENB;
895 1.1.4.2 rmind #endif
896 1.1.4.2 rmind }
897 1.1.4.2 rmind CSR_WRITE_2(sc, VTE_MCR0, mcr);
898 1.1.4.2 rmind }
899 1.1.4.2 rmind
900 1.1.4.2 rmind static void
901 1.1.4.2 rmind vte_stats_clear(struct vte_softc *sc)
902 1.1.4.2 rmind {
903 1.1.4.2 rmind
904 1.1.4.2 rmind /* Reading counter registers clears its contents. */
905 1.1.4.2 rmind CSR_READ_2(sc, VTE_CNT_RX_DONE);
906 1.1.4.2 rmind CSR_READ_2(sc, VTE_CNT_MECNT0);
907 1.1.4.2 rmind CSR_READ_2(sc, VTE_CNT_MECNT1);
908 1.1.4.2 rmind CSR_READ_2(sc, VTE_CNT_MECNT2);
909 1.1.4.2 rmind CSR_READ_2(sc, VTE_CNT_MECNT3);
910 1.1.4.2 rmind CSR_READ_2(sc, VTE_CNT_TX_DONE);
911 1.1.4.2 rmind CSR_READ_2(sc, VTE_CNT_MECNT4);
912 1.1.4.2 rmind CSR_READ_2(sc, VTE_CNT_PAUSE);
913 1.1.4.2 rmind }
914 1.1.4.2 rmind
915 1.1.4.2 rmind static void
916 1.1.4.2 rmind vte_stats_update(struct vte_softc *sc)
917 1.1.4.2 rmind {
918 1.1.4.2 rmind struct vte_hw_stats *stat;
919 1.1.4.2 rmind struct ifnet *ifp = &sc->vte_if;
920 1.1.4.2 rmind uint16_t value;
921 1.1.4.2 rmind
922 1.1.4.2 rmind stat = &sc->vte_stats;
923 1.1.4.2 rmind
924 1.1.4.2 rmind CSR_READ_2(sc, VTE_MECISR);
925 1.1.4.2 rmind /* RX stats. */
926 1.1.4.2 rmind stat->rx_frames += CSR_READ_2(sc, VTE_CNT_RX_DONE);
927 1.1.4.2 rmind value = CSR_READ_2(sc, VTE_CNT_MECNT0);
928 1.1.4.2 rmind stat->rx_bcast_frames += (value >> 8);
929 1.1.4.2 rmind stat->rx_mcast_frames += (value & 0xFF);
930 1.1.4.2 rmind value = CSR_READ_2(sc, VTE_CNT_MECNT1);
931 1.1.4.2 rmind stat->rx_runts += (value >> 8);
932 1.1.4.2 rmind stat->rx_crcerrs += (value & 0xFF);
933 1.1.4.2 rmind value = CSR_READ_2(sc, VTE_CNT_MECNT2);
934 1.1.4.2 rmind stat->rx_long_frames += (value & 0xFF);
935 1.1.4.2 rmind value = CSR_READ_2(sc, VTE_CNT_MECNT3);
936 1.1.4.2 rmind stat->rx_fifo_full += (value >> 8);
937 1.1.4.2 rmind stat->rx_desc_unavail += (value & 0xFF);
938 1.1.4.2 rmind
939 1.1.4.2 rmind /* TX stats. */
940 1.1.4.2 rmind stat->tx_frames += CSR_READ_2(sc, VTE_CNT_TX_DONE);
941 1.1.4.2 rmind value = CSR_READ_2(sc, VTE_CNT_MECNT4);
942 1.1.4.2 rmind stat->tx_underruns += (value >> 8);
943 1.1.4.2 rmind stat->tx_late_colls += (value & 0xFF);
944 1.1.4.2 rmind
945 1.1.4.2 rmind value = CSR_READ_2(sc, VTE_CNT_PAUSE);
946 1.1.4.2 rmind stat->tx_pause_frames += (value >> 8);
947 1.1.4.2 rmind stat->rx_pause_frames += (value & 0xFF);
948 1.1.4.2 rmind
949 1.1.4.2 rmind /* Update ifp counters. */
950 1.1.4.2 rmind ifp->if_opackets = stat->tx_frames;
951 1.1.4.2 rmind ifp->if_oerrors = stat->tx_late_colls + stat->tx_underruns;
952 1.1.4.2 rmind ifp->if_ipackets = stat->rx_frames;
953 1.1.4.2 rmind ifp->if_ierrors = stat->rx_crcerrs + stat->rx_runts +
954 1.1.4.2 rmind stat->rx_long_frames + stat->rx_fifo_full;
955 1.1.4.2 rmind }
956 1.1.4.2 rmind
957 1.1.4.2 rmind static int
958 1.1.4.2 rmind vte_intr(void *arg)
959 1.1.4.2 rmind {
960 1.1.4.2 rmind struct vte_softc *sc = (struct vte_softc *)arg;
961 1.1.4.2 rmind struct ifnet *ifp = &sc->vte_if;
962 1.1.4.2 rmind uint16_t status;
963 1.1.4.2 rmind int n;
964 1.1.4.2 rmind
965 1.1.4.2 rmind /* Reading VTE_MISR acknowledges interrupts. */
966 1.1.4.2 rmind status = CSR_READ_2(sc, VTE_MISR);
967 1.1.4.2 rmind DPRINTF(("vte_intr status 0x%x\n", status));
968 1.1.4.2 rmind if ((status & VTE_INTRS) == 0) {
969 1.1.4.2 rmind /* Not ours. */
970 1.1.4.2 rmind return 0;
971 1.1.4.2 rmind }
972 1.1.4.2 rmind
973 1.1.4.2 rmind /* Disable interrupts. */
974 1.1.4.2 rmind CSR_WRITE_2(sc, VTE_MIER, 0);
975 1.1.4.2 rmind for (n = 8; (status & VTE_INTRS) != 0;) {
976 1.1.4.2 rmind if ((ifp->if_flags & IFF_RUNNING) == 0)
977 1.1.4.2 rmind break;
978 1.1.4.2 rmind if ((status & (MISR_RX_DONE | MISR_RX_DESC_UNAVAIL |
979 1.1.4.2 rmind MISR_RX_FIFO_FULL)) != 0)
980 1.1.4.2 rmind vte_rxeof(sc);
981 1.1.4.2 rmind if ((status & MISR_TX_DONE) != 0)
982 1.1.4.2 rmind vte_txeof(sc);
983 1.1.4.2 rmind if ((status & MISR_EVENT_CNT_OFLOW) != 0)
984 1.1.4.2 rmind vte_stats_update(sc);
985 1.1.4.2 rmind if (!IFQ_IS_EMPTY(&ifp->if_snd))
986 1.1.4.2 rmind vte_ifstart(ifp);
987 1.1.4.2 rmind if (--n > 0)
988 1.1.4.2 rmind status = CSR_READ_2(sc, VTE_MISR);
989 1.1.4.2 rmind else
990 1.1.4.2 rmind break;
991 1.1.4.2 rmind }
992 1.1.4.2 rmind
993 1.1.4.2 rmind if ((ifp->if_flags & IFF_RUNNING) != 0) {
994 1.1.4.2 rmind /* Re-enable interrupts. */
995 1.1.4.2 rmind CSR_WRITE_2(sc, VTE_MIER, VTE_INTRS);
996 1.1.4.2 rmind }
997 1.1.4.2 rmind return 1;
998 1.1.4.2 rmind }
999 1.1.4.2 rmind
1000 1.1.4.2 rmind static void
1001 1.1.4.2 rmind vte_txeof(struct vte_softc *sc)
1002 1.1.4.2 rmind {
1003 1.1.4.2 rmind struct ifnet *ifp;
1004 1.1.4.2 rmind struct vte_txdesc *txd;
1005 1.1.4.2 rmind uint16_t status;
1006 1.1.4.2 rmind int cons, prog;
1007 1.1.4.2 rmind
1008 1.1.4.2 rmind ifp = &sc->vte_if;
1009 1.1.4.2 rmind
1010 1.1.4.2 rmind if (sc->vte_cdata.vte_tx_cnt == 0)
1011 1.1.4.2 rmind return;
1012 1.1.4.2 rmind bus_dmamap_sync(sc->vte_dmatag,
1013 1.1.4.2 rmind sc->vte_cdata.vte_tx_ring_map, 0,
1014 1.1.4.2 rmind sc->vte_cdata.vte_tx_ring_map->dm_mapsize,
1015 1.1.4.2 rmind BUS_DMASYNC_POSTREAD | BUS_DMASYNC_POSTWRITE);
1016 1.1.4.2 rmind cons = sc->vte_cdata.vte_tx_cons;
1017 1.1.4.2 rmind /*
1018 1.1.4.2 rmind * Go through our TX list and free mbufs for those
1019 1.1.4.2 rmind * frames which have been transmitted.
1020 1.1.4.2 rmind */
1021 1.1.4.2 rmind for (prog = 0; sc->vte_cdata.vte_tx_cnt > 0; prog++) {
1022 1.1.4.2 rmind txd = &sc->vte_cdata.vte_txdesc[cons];
1023 1.1.4.2 rmind status = le16toh(txd->tx_desc->dtst);
1024 1.1.4.2 rmind if ((status & VTE_DTST_TX_OWN) != 0)
1025 1.1.4.2 rmind break;
1026 1.1.4.4 rmind if ((status & VTE_DTST_TX_OK) != 0)
1027 1.1.4.4 rmind ifp->if_collisions += (status & 0xf);
1028 1.1.4.2 rmind sc->vte_cdata.vte_tx_cnt--;
1029 1.1.4.2 rmind /* Reclaim transmitted mbufs. */
1030 1.1.4.2 rmind bus_dmamap_sync(sc->vte_dmatag, txd->tx_dmamap, 0,
1031 1.1.4.2 rmind txd->tx_dmamap->dm_mapsize, BUS_DMASYNC_POSTWRITE);
1032 1.1.4.2 rmind bus_dmamap_unload(sc->vte_dmatag, txd->tx_dmamap);
1033 1.1.4.2 rmind if ((txd->tx_flags & VTE_TXMBUF) == 0)
1034 1.1.4.2 rmind m_freem(txd->tx_m);
1035 1.1.4.2 rmind txd->tx_flags &= ~VTE_TXMBUF;
1036 1.1.4.2 rmind txd->tx_m = NULL;
1037 1.1.4.2 rmind prog++;
1038 1.1.4.2 rmind VTE_DESC_INC(cons, VTE_TX_RING_CNT);
1039 1.1.4.2 rmind }
1040 1.1.4.2 rmind
1041 1.1.4.2 rmind if (prog > 0) {
1042 1.1.4.2 rmind ifp->if_flags &= ~IFF_OACTIVE;
1043 1.1.4.2 rmind sc->vte_cdata.vte_tx_cons = cons;
1044 1.1.4.2 rmind /*
1045 1.1.4.2 rmind * Unarm watchdog timer only when there is no pending
1046 1.1.4.2 rmind * frames in TX queue.
1047 1.1.4.2 rmind */
1048 1.1.4.2 rmind if (sc->vte_cdata.vte_tx_cnt == 0)
1049 1.1.4.2 rmind sc->vte_watchdog_timer = 0;
1050 1.1.4.2 rmind }
1051 1.1.4.2 rmind }
1052 1.1.4.2 rmind
1053 1.1.4.2 rmind static int
1054 1.1.4.2 rmind vte_newbuf(struct vte_softc *sc, struct vte_rxdesc *rxd)
1055 1.1.4.2 rmind {
1056 1.1.4.2 rmind struct mbuf *m;
1057 1.1.4.2 rmind bus_dmamap_t map;
1058 1.1.4.2 rmind
1059 1.1.4.2 rmind m = m_getcl(M_DONTWAIT, MT_DATA, M_PKTHDR);
1060 1.1.4.2 rmind if (m == NULL)
1061 1.1.4.2 rmind return (ENOBUFS);
1062 1.1.4.2 rmind m->m_len = m->m_pkthdr.len = MCLBYTES;
1063 1.1.4.2 rmind m_adj(m, sizeof(uint32_t));
1064 1.1.4.2 rmind
1065 1.1.4.2 rmind if (bus_dmamap_load_mbuf(sc->vte_dmatag,
1066 1.1.4.2 rmind sc->vte_cdata.vte_rx_sparemap, m, 0) != 0) {
1067 1.1.4.2 rmind m_freem(m);
1068 1.1.4.2 rmind return (ENOBUFS);
1069 1.1.4.2 rmind }
1070 1.1.4.2 rmind KASSERT(sc->vte_cdata.vte_rx_sparemap->dm_nsegs == 1);
1071 1.1.4.2 rmind
1072 1.1.4.2 rmind if (rxd->rx_m != NULL) {
1073 1.1.4.2 rmind bus_dmamap_sync(sc->vte_dmatag, rxd->rx_dmamap,
1074 1.1.4.2 rmind 0, rxd->rx_dmamap->dm_mapsize,
1075 1.1.4.2 rmind BUS_DMASYNC_POSTREAD);
1076 1.1.4.2 rmind bus_dmamap_unload(sc->vte_dmatag, rxd->rx_dmamap);
1077 1.1.4.2 rmind }
1078 1.1.4.2 rmind map = rxd->rx_dmamap;
1079 1.1.4.2 rmind rxd->rx_dmamap = sc->vte_cdata.vte_rx_sparemap;
1080 1.1.4.2 rmind sc->vte_cdata.vte_rx_sparemap = map;
1081 1.1.4.2 rmind bus_dmamap_sync(sc->vte_dmatag, rxd->rx_dmamap,
1082 1.1.4.2 rmind 0, rxd->rx_dmamap->dm_mapsize,
1083 1.1.4.2 rmind BUS_DMASYNC_PREREAD);
1084 1.1.4.2 rmind rxd->rx_m = m;
1085 1.1.4.2 rmind rxd->rx_desc->drbp =
1086 1.1.4.2 rmind htole32(rxd->rx_dmamap->dm_segs[0].ds_addr);
1087 1.1.4.2 rmind rxd->rx_desc->drlen = htole16(
1088 1.1.4.2 rmind VTE_RX_LEN(rxd->rx_dmamap->dm_segs[0].ds_len));
1089 1.1.4.2 rmind DPRINTF(("rx data %p mbuf %p buf 0x%x/0x%x\n", rxd, m, (u_int)rxd->rx_dmamap->dm_segs[0].ds_addr, rxd->rx_dmamap->dm_segs[0].ds_len));
1090 1.1.4.2 rmind rxd->rx_desc->drst = htole16(VTE_DRST_RX_OWN);
1091 1.1.4.2 rmind
1092 1.1.4.2 rmind return (0);
1093 1.1.4.2 rmind }
1094 1.1.4.2 rmind
1095 1.1.4.2 rmind static void
1096 1.1.4.2 rmind vte_rxeof(struct vte_softc *sc)
1097 1.1.4.2 rmind {
1098 1.1.4.2 rmind struct ifnet *ifp;
1099 1.1.4.2 rmind struct vte_rxdesc *rxd;
1100 1.1.4.2 rmind struct mbuf *m;
1101 1.1.4.2 rmind uint16_t status, total_len;
1102 1.1.4.2 rmind int cons, prog;
1103 1.1.4.2 rmind
1104 1.1.4.2 rmind bus_dmamap_sync(sc->vte_dmatag,
1105 1.1.4.2 rmind sc->vte_cdata.vte_rx_ring_map, 0,
1106 1.1.4.2 rmind sc->vte_cdata.vte_rx_ring_map->dm_mapsize,
1107 1.1.4.2 rmind BUS_DMASYNC_POSTREAD | BUS_DMASYNC_POSTWRITE);
1108 1.1.4.2 rmind cons = sc->vte_cdata.vte_rx_cons;
1109 1.1.4.2 rmind ifp = &sc->vte_if;
1110 1.1.4.2 rmind DPRINTF(("vte_rxeof if_flags 0x%x\n", ifp->if_flags));
1111 1.1.4.2 rmind for (prog = 0; (ifp->if_flags & IFF_RUNNING) != 0; prog++,
1112 1.1.4.2 rmind VTE_DESC_INC(cons, VTE_RX_RING_CNT)) {
1113 1.1.4.2 rmind rxd = &sc->vte_cdata.vte_rxdesc[cons];
1114 1.1.4.2 rmind status = le16toh(rxd->rx_desc->drst);
1115 1.1.4.2 rmind DPRINTF(("vte_rxoef rxd %d/%p mbuf %p status 0x%x len %d\n", cons, rxd, rxd->rx_m, status, VTE_RX_LEN(le16toh(rxd->rx_desc->drlen))));
1116 1.1.4.2 rmind if ((status & VTE_DRST_RX_OWN) != 0)
1117 1.1.4.2 rmind break;
1118 1.1.4.2 rmind total_len = VTE_RX_LEN(le16toh(rxd->rx_desc->drlen));
1119 1.1.4.2 rmind m = rxd->rx_m;
1120 1.1.4.2 rmind if ((status & VTE_DRST_RX_OK) == 0) {
1121 1.1.4.2 rmind /* Discard errored frame. */
1122 1.1.4.2 rmind rxd->rx_desc->drlen =
1123 1.1.4.2 rmind htole16(MCLBYTES - sizeof(uint32_t));
1124 1.1.4.2 rmind rxd->rx_desc->drst = htole16(VTE_DRST_RX_OWN);
1125 1.1.4.2 rmind continue;
1126 1.1.4.2 rmind }
1127 1.1.4.2 rmind if (vte_newbuf(sc, rxd) != 0) {
1128 1.1.4.2 rmind DPRINTF(("vte_rxeof newbuf failed\n"));
1129 1.1.4.2 rmind ifp->if_ierrors++;
1130 1.1.4.2 rmind rxd->rx_desc->drlen =
1131 1.1.4.2 rmind htole16(MCLBYTES - sizeof(uint32_t));
1132 1.1.4.2 rmind rxd->rx_desc->drst = htole16(VTE_DRST_RX_OWN);
1133 1.1.4.2 rmind continue;
1134 1.1.4.2 rmind }
1135 1.1.4.2 rmind
1136 1.1.4.2 rmind /*
1137 1.1.4.2 rmind * It seems there is no way to strip FCS bytes.
1138 1.1.4.2 rmind */
1139 1.1.4.2 rmind m->m_pkthdr.len = m->m_len = total_len - ETHER_CRC_LEN;
1140 1.1.4.2 rmind m->m_pkthdr.rcvif = ifp;
1141 1.1.4.2 rmind ifp->if_ipackets++;
1142 1.1.4.2 rmind bpf_mtap(ifp, m);
1143 1.1.4.2 rmind (*ifp->if_input)(ifp, m);
1144 1.1.4.2 rmind }
1145 1.1.4.2 rmind
1146 1.1.4.2 rmind if (prog > 0) {
1147 1.1.4.2 rmind /* Update the consumer index. */
1148 1.1.4.2 rmind sc->vte_cdata.vte_rx_cons = cons;
1149 1.1.4.2 rmind /*
1150 1.1.4.2 rmind * Sync updated RX descriptors such that controller see
1151 1.1.4.2 rmind * modified RX buffer addresses.
1152 1.1.4.2 rmind */
1153 1.1.4.2 rmind bus_dmamap_sync(sc->vte_dmatag,
1154 1.1.4.2 rmind sc->vte_cdata.vte_rx_ring_map, 0,
1155 1.1.4.2 rmind sc->vte_cdata.vte_rx_ring_map->dm_mapsize,
1156 1.1.4.2 rmind BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
1157 1.1.4.2 rmind #ifdef notyet
1158 1.1.4.2 rmind /*
1159 1.1.4.2 rmind * Update residue counter. Controller does not
1160 1.1.4.2 rmind * keep track of number of available RX descriptors
1161 1.1.4.2 rmind * such that driver should have to update VTE_MRDCR
1162 1.1.4.2 rmind * to make controller know how many free RX
1163 1.1.4.2 rmind * descriptors were added to controller. This is
1164 1.1.4.2 rmind * a similar mechanism used in VIA velocity
1165 1.1.4.2 rmind * controllers and it indicates controller just
1166 1.1.4.2 rmind * polls OWN bit of current RX descriptor pointer.
1167 1.1.4.2 rmind * A couple of severe issues were seen on sample
1168 1.1.4.2 rmind * board where the controller continuously emits TX
1169 1.1.4.2 rmind * pause frames once RX pause threshold crossed.
1170 1.1.4.2 rmind * Once triggered it never recovered form that
1171 1.1.4.2 rmind * state, I couldn't find a way to make it back to
1172 1.1.4.2 rmind * work at least. This issue effectively
1173 1.1.4.2 rmind * disconnected the system from network. Also, the
1174 1.1.4.2 rmind * controller used 00:00:00:00:00:00 as source
1175 1.1.4.2 rmind * station address of TX pause frame. Probably this
1176 1.1.4.2 rmind * is one of reason why vendor recommends not to
1177 1.1.4.2 rmind * enable flow control on R6040 controller.
1178 1.1.4.2 rmind */
1179 1.1.4.2 rmind CSR_WRITE_2(sc, VTE_MRDCR, prog |
1180 1.1.4.2 rmind (((VTE_RX_RING_CNT * 2) / 10) <<
1181 1.1.4.2 rmind VTE_MRDCR_RX_PAUSE_THRESH_SHIFT));
1182 1.1.4.2 rmind #endif
1183 1.1.4.2 rmind #if NRND > 0
1184 1.1.4.2 rmind if (RND_ENABLED(&sc->rnd_source))
1185 1.1.4.2 rmind rnd_add_uint32(&sc->rnd_source, prog);
1186 1.1.4.2 rmind #endif /* NRND > 0 */
1187 1.1.4.2 rmind }
1188 1.1.4.2 rmind }
1189 1.1.4.2 rmind
1190 1.1.4.2 rmind static void
1191 1.1.4.2 rmind vte_tick(void *arg)
1192 1.1.4.2 rmind {
1193 1.1.4.2 rmind struct vte_softc *sc;
1194 1.1.4.2 rmind int s = splnet();
1195 1.1.4.2 rmind
1196 1.1.4.2 rmind sc = (struct vte_softc *)arg;
1197 1.1.4.2 rmind
1198 1.1.4.2 rmind mii_tick(&sc->vte_mii);
1199 1.1.4.2 rmind vte_stats_update(sc);
1200 1.1.4.2 rmind vte_txeof(sc);
1201 1.1.4.2 rmind vte_ifwatchdog(&sc->vte_if);
1202 1.1.4.2 rmind callout_reset(&sc->vte_tick_ch, hz, vte_tick, sc);
1203 1.1.4.2 rmind splx(s);
1204 1.1.4.2 rmind }
1205 1.1.4.2 rmind
1206 1.1.4.2 rmind static void
1207 1.1.4.2 rmind vte_reset(struct vte_softc *sc)
1208 1.1.4.2 rmind {
1209 1.1.4.2 rmind uint16_t mcr;
1210 1.1.4.2 rmind int i;
1211 1.1.4.2 rmind
1212 1.1.4.2 rmind mcr = CSR_READ_2(sc, VTE_MCR1);
1213 1.1.4.2 rmind CSR_WRITE_2(sc, VTE_MCR1, mcr | MCR1_MAC_RESET);
1214 1.1.4.2 rmind for (i = VTE_RESET_TIMEOUT; i > 0; i--) {
1215 1.1.4.2 rmind DELAY(10);
1216 1.1.4.2 rmind if ((CSR_READ_2(sc, VTE_MCR1) & MCR1_MAC_RESET) == 0)
1217 1.1.4.2 rmind break;
1218 1.1.4.2 rmind }
1219 1.1.4.2 rmind if (i == 0)
1220 1.1.4.2 rmind aprint_error_dev(sc->vte_dev, "reset timeout(0x%04x)!\n", mcr);
1221 1.1.4.2 rmind /*
1222 1.1.4.2 rmind * Follow the guide of vendor recommended way to reset MAC.
1223 1.1.4.2 rmind * Vendor confirms relying on MCR1_MAC_RESET of VTE_MCR1 is
1224 1.1.4.2 rmind * not reliable so manually reset internal state machine.
1225 1.1.4.2 rmind */
1226 1.1.4.2 rmind CSR_WRITE_2(sc, VTE_MACSM, 0x0002);
1227 1.1.4.2 rmind CSR_WRITE_2(sc, VTE_MACSM, 0);
1228 1.1.4.2 rmind DELAY(5000);
1229 1.1.4.2 rmind }
1230 1.1.4.2 rmind
1231 1.1.4.2 rmind
1232 1.1.4.2 rmind static int
1233 1.1.4.2 rmind vte_init(struct ifnet *ifp)
1234 1.1.4.2 rmind {
1235 1.1.4.2 rmind struct vte_softc *sc = ifp->if_softc;
1236 1.1.4.2 rmind bus_addr_t paddr;
1237 1.1.4.2 rmind uint8_t eaddr[ETHER_ADDR_LEN];
1238 1.1.4.2 rmind int s, error;
1239 1.1.4.2 rmind
1240 1.1.4.2 rmind s = splnet();
1241 1.1.4.2 rmind /*
1242 1.1.4.2 rmind * Cancel any pending I/O.
1243 1.1.4.2 rmind */
1244 1.1.4.2 rmind vte_stop(ifp, 1);
1245 1.1.4.2 rmind /*
1246 1.1.4.2 rmind * Reset the chip to a known state.
1247 1.1.4.2 rmind */
1248 1.1.4.2 rmind vte_reset(sc);
1249 1.1.4.2 rmind
1250 1.1.4.2 rmind if ((sc->vte_if.if_flags & IFF_UP) == 0) {
1251 1.1.4.2 rmind splx(s);
1252 1.1.4.2 rmind return 0;
1253 1.1.4.2 rmind }
1254 1.1.4.2 rmind
1255 1.1.4.2 rmind /* Initialize RX descriptors. */
1256 1.1.4.2 rmind if (vte_init_rx_ring(sc) != 0) {
1257 1.1.4.2 rmind aprint_error_dev(sc->vte_dev, "no memory for RX buffers.\n");
1258 1.1.4.2 rmind vte_stop(ifp, 1);
1259 1.1.4.2 rmind splx(s);
1260 1.1.4.2 rmind return ENOMEM;
1261 1.1.4.2 rmind }
1262 1.1.4.2 rmind if (vte_init_tx_ring(sc) != 0) {
1263 1.1.4.2 rmind aprint_error_dev(sc->vte_dev, "no memory for TX buffers.\n");
1264 1.1.4.2 rmind vte_stop(ifp, 1);
1265 1.1.4.2 rmind splx(s);
1266 1.1.4.2 rmind return ENOMEM;
1267 1.1.4.2 rmind }
1268 1.1.4.2 rmind
1269 1.1.4.2 rmind /*
1270 1.1.4.2 rmind * Reprogram the station address. Controller supports up
1271 1.1.4.2 rmind * to 4 different station addresses so driver programs the
1272 1.1.4.2 rmind * first station address as its own ethernet address and
1273 1.1.4.2 rmind * configure the remaining three addresses as perfect
1274 1.1.4.2 rmind * multicast addresses.
1275 1.1.4.2 rmind */
1276 1.1.4.2 rmind memcpy(eaddr, CLLADDR(ifp->if_sadl), ETHER_ADDR_LEN);
1277 1.1.4.2 rmind CSR_WRITE_2(sc, VTE_MID0L, eaddr[1] << 8 | eaddr[0]);
1278 1.1.4.2 rmind CSR_WRITE_2(sc, VTE_MID0M, eaddr[3] << 8 | eaddr[2]);
1279 1.1.4.2 rmind CSR_WRITE_2(sc, VTE_MID0H, eaddr[5] << 8 | eaddr[4]);
1280 1.1.4.2 rmind
1281 1.1.4.2 rmind /* Set TX descriptor base addresses. */
1282 1.1.4.2 rmind paddr = sc->vte_cdata.vte_tx_ring_map->dm_segs[0].ds_addr;
1283 1.1.4.2 rmind DPRINTF(("tx paddr 0x%x\n", (u_int)paddr));
1284 1.1.4.2 rmind CSR_WRITE_2(sc, VTE_MTDSA1, paddr >> 16);
1285 1.1.4.2 rmind CSR_WRITE_2(sc, VTE_MTDSA0, paddr & 0xFFFF);
1286 1.1.4.2 rmind
1287 1.1.4.2 rmind /* Set RX descriptor base addresses. */
1288 1.1.4.2 rmind paddr = sc->vte_cdata.vte_rx_ring_map->dm_segs[0].ds_addr;
1289 1.1.4.2 rmind DPRINTF(("rx paddr 0x%x\n", (u_int)paddr));
1290 1.1.4.2 rmind CSR_WRITE_2(sc, VTE_MRDSA1, paddr >> 16);
1291 1.1.4.2 rmind CSR_WRITE_2(sc, VTE_MRDSA0, paddr & 0xFFFF);
1292 1.1.4.2 rmind /*
1293 1.1.4.2 rmind * Initialize RX descriptor residue counter and set RX
1294 1.1.4.2 rmind * pause threshold to 20% of available RX descriptors.
1295 1.1.4.2 rmind * See comments on vte_rxeof() for details on flow control
1296 1.1.4.2 rmind * issues.
1297 1.1.4.2 rmind */
1298 1.1.4.2 rmind CSR_WRITE_2(sc, VTE_MRDCR, (VTE_RX_RING_CNT & VTE_MRDCR_RESIDUE_MASK) |
1299 1.1.4.2 rmind (((VTE_RX_RING_CNT * 2) / 10) << VTE_MRDCR_RX_PAUSE_THRESH_SHIFT));
1300 1.1.4.2 rmind
1301 1.1.4.2 rmind /*
1302 1.1.4.2 rmind * Always use maximum frame size that controller can
1303 1.1.4.2 rmind * support. Otherwise received frames that has longer
1304 1.1.4.2 rmind * frame length than vte(4) MTU would be silently dropped
1305 1.1.4.2 rmind * in controller. This would break path-MTU discovery as
1306 1.1.4.2 rmind * sender wouldn't get any responses from receiver. The
1307 1.1.4.2 rmind * RX buffer size should be multiple of 4.
1308 1.1.4.2 rmind * Note, jumbo frames are silently ignored by controller
1309 1.1.4.2 rmind * and even MAC counters do not detect them.
1310 1.1.4.2 rmind */
1311 1.1.4.2 rmind CSR_WRITE_2(sc, VTE_MRBSR, VTE_RX_BUF_SIZE_MAX);
1312 1.1.4.2 rmind
1313 1.1.4.2 rmind /* Configure FIFO. */
1314 1.1.4.2 rmind CSR_WRITE_2(sc, VTE_MBCR, MBCR_FIFO_XFER_LENGTH_16 |
1315 1.1.4.2 rmind MBCR_TX_FIFO_THRESH_64 | MBCR_RX_FIFO_THRESH_16 |
1316 1.1.4.2 rmind MBCR_SDRAM_BUS_REQ_TIMER_DEFAULT);
1317 1.1.4.2 rmind
1318 1.1.4.2 rmind /*
1319 1.1.4.2 rmind * Configure TX/RX MACs. Actual resolved duplex and flow
1320 1.1.4.2 rmind * control configuration is done after detecting a valid
1321 1.1.4.2 rmind * link. Note, we don't generate early interrupt here
1322 1.1.4.2 rmind * as well since FreeBSD does not have interrupt latency
1323 1.1.4.2 rmind * problems like Windows.
1324 1.1.4.2 rmind */
1325 1.1.4.2 rmind CSR_WRITE_2(sc, VTE_MCR0, MCR0_ACCPT_LONG_PKT);
1326 1.1.4.2 rmind /*
1327 1.1.4.2 rmind * We manually keep track of PHY status changes to
1328 1.1.4.2 rmind * configure resolved duplex and flow control since only
1329 1.1.4.2 rmind * duplex configuration can be automatically reflected to
1330 1.1.4.2 rmind * MCR0.
1331 1.1.4.2 rmind */
1332 1.1.4.2 rmind CSR_WRITE_2(sc, VTE_MCR1, MCR1_PKT_LENGTH_1537 |
1333 1.1.4.2 rmind MCR1_EXCESS_COL_RETRY_16);
1334 1.1.4.2 rmind
1335 1.1.4.2 rmind /* Initialize RX filter. */
1336 1.1.4.2 rmind vte_rxfilter(sc);
1337 1.1.4.2 rmind
1338 1.1.4.2 rmind /* Disable TX/RX interrupt moderation control. */
1339 1.1.4.2 rmind CSR_WRITE_2(sc, VTE_MRICR, 0);
1340 1.1.4.2 rmind CSR_WRITE_2(sc, VTE_MTICR, 0);
1341 1.1.4.2 rmind
1342 1.1.4.2 rmind /* Enable MAC event counter interrupts. */
1343 1.1.4.2 rmind CSR_WRITE_2(sc, VTE_MECIER, VTE_MECIER_INTRS);
1344 1.1.4.2 rmind /* Clear MAC statistics. */
1345 1.1.4.2 rmind vte_stats_clear(sc);
1346 1.1.4.2 rmind
1347 1.1.4.2 rmind /* Acknowledge all pending interrupts and clear it. */
1348 1.1.4.2 rmind CSR_WRITE_2(sc, VTE_MIER, VTE_INTRS);
1349 1.1.4.2 rmind CSR_WRITE_2(sc, VTE_MISR, 0);
1350 1.1.4.2 rmind DPRINTF(("before ipend 0x%x 0x%x\n", CSR_READ_2(sc, VTE_MIER), CSR_READ_2(sc, VTE_MISR)));
1351 1.1.4.2 rmind
1352 1.1.4.2 rmind sc->vte_flags &= ~VTE_FLAG_LINK;
1353 1.1.4.2 rmind ifp->if_flags |= IFF_RUNNING;
1354 1.1.4.2 rmind ifp->if_flags &= ~IFF_OACTIVE;
1355 1.1.4.2 rmind
1356 1.1.4.4 rmind /* calling mii_mediachg will call back vte_start_mac() */
1357 1.1.4.2 rmind if ((error = mii_mediachg(&sc->vte_mii)) == ENXIO)
1358 1.1.4.2 rmind error = 0;
1359 1.1.4.2 rmind else if (error != 0) {
1360 1.1.4.2 rmind aprint_error_dev(sc->vte_dev, "could not set media\n");
1361 1.1.4.2 rmind splx(s);
1362 1.1.4.2 rmind return error;
1363 1.1.4.2 rmind }
1364 1.1.4.2 rmind
1365 1.1.4.2 rmind callout_reset(&sc->vte_tick_ch, hz, vte_tick, sc);
1366 1.1.4.2 rmind
1367 1.1.4.2 rmind DPRINTF(("ipend 0x%x 0x%x\n", CSR_READ_2(sc, VTE_MIER), CSR_READ_2(sc, VTE_MISR)));
1368 1.1.4.2 rmind splx(s);
1369 1.1.4.2 rmind return 0;
1370 1.1.4.2 rmind }
1371 1.1.4.2 rmind
1372 1.1.4.2 rmind static void
1373 1.1.4.2 rmind vte_stop(struct ifnet *ifp, int disable)
1374 1.1.4.2 rmind {
1375 1.1.4.2 rmind struct vte_softc *sc = ifp->if_softc;
1376 1.1.4.2 rmind struct vte_txdesc *txd;
1377 1.1.4.2 rmind struct vte_rxdesc *rxd;
1378 1.1.4.2 rmind int i;
1379 1.1.4.2 rmind
1380 1.1.4.2 rmind DPRINTF(("vte_stop if_flags 0x%x\n", ifp->if_flags));
1381 1.1.4.2 rmind if ((ifp->if_flags & IFF_RUNNING) == 0)
1382 1.1.4.2 rmind return;
1383 1.1.4.2 rmind /*
1384 1.1.4.2 rmind * Mark the interface down and cancel the watchdog timer.
1385 1.1.4.2 rmind */
1386 1.1.4.2 rmind ifp->if_flags &= ~(IFF_RUNNING | IFF_OACTIVE);
1387 1.1.4.2 rmind sc->vte_flags &= ~VTE_FLAG_LINK;
1388 1.1.4.2 rmind callout_stop(&sc->vte_tick_ch);
1389 1.1.4.2 rmind sc->vte_watchdog_timer = 0;
1390 1.1.4.2 rmind vte_stats_update(sc);
1391 1.1.4.2 rmind /* Disable interrupts. */
1392 1.1.4.2 rmind CSR_WRITE_2(sc, VTE_MIER, 0);
1393 1.1.4.2 rmind CSR_WRITE_2(sc, VTE_MECIER, 0);
1394 1.1.4.2 rmind /* Stop RX/TX MACs. */
1395 1.1.4.2 rmind vte_stop_mac(sc);
1396 1.1.4.2 rmind /* Clear interrupts. */
1397 1.1.4.2 rmind CSR_READ_2(sc, VTE_MISR);
1398 1.1.4.2 rmind /*
1399 1.1.4.2 rmind * Free TX/RX mbufs still in the queues.
1400 1.1.4.2 rmind */
1401 1.1.4.2 rmind for (i = 0; i < VTE_RX_RING_CNT; i++) {
1402 1.1.4.2 rmind rxd = &sc->vte_cdata.vte_rxdesc[i];
1403 1.1.4.2 rmind if (rxd->rx_m != NULL) {
1404 1.1.4.2 rmind bus_dmamap_sync(sc->vte_dmatag,
1405 1.1.4.2 rmind rxd->rx_dmamap, 0, rxd->rx_dmamap->dm_mapsize,
1406 1.1.4.2 rmind BUS_DMASYNC_POSTREAD);
1407 1.1.4.2 rmind bus_dmamap_unload(sc->vte_dmatag,
1408 1.1.4.2 rmind rxd->rx_dmamap);
1409 1.1.4.2 rmind m_freem(rxd->rx_m);
1410 1.1.4.2 rmind rxd->rx_m = NULL;
1411 1.1.4.2 rmind }
1412 1.1.4.2 rmind }
1413 1.1.4.2 rmind for (i = 0; i < VTE_TX_RING_CNT; i++) {
1414 1.1.4.2 rmind txd = &sc->vte_cdata.vte_txdesc[i];
1415 1.1.4.2 rmind if (txd->tx_m != NULL) {
1416 1.1.4.2 rmind bus_dmamap_sync(sc->vte_dmatag,
1417 1.1.4.2 rmind txd->tx_dmamap, 0, txd->tx_dmamap->dm_mapsize,
1418 1.1.4.2 rmind BUS_DMASYNC_POSTWRITE);
1419 1.1.4.2 rmind bus_dmamap_unload(sc->vte_dmatag,
1420 1.1.4.2 rmind txd->tx_dmamap);
1421 1.1.4.2 rmind if ((txd->tx_flags & VTE_TXMBUF) == 0)
1422 1.1.4.2 rmind m_freem(txd->tx_m);
1423 1.1.4.2 rmind txd->tx_m = NULL;
1424 1.1.4.2 rmind txd->tx_flags &= ~VTE_TXMBUF;
1425 1.1.4.2 rmind }
1426 1.1.4.2 rmind }
1427 1.1.4.2 rmind /* Free TX mbuf pools used for deep copy. */
1428 1.1.4.2 rmind for (i = 0; i < VTE_TX_RING_CNT; i++) {
1429 1.1.4.2 rmind if (sc->vte_cdata.vte_txmbufs[i] != NULL) {
1430 1.1.4.2 rmind m_freem(sc->vte_cdata.vte_txmbufs[i]);
1431 1.1.4.2 rmind sc->vte_cdata.vte_txmbufs[i] = NULL;
1432 1.1.4.2 rmind }
1433 1.1.4.2 rmind }
1434 1.1.4.2 rmind }
1435 1.1.4.2 rmind
1436 1.1.4.2 rmind static void
1437 1.1.4.2 rmind vte_start_mac(struct vte_softc *sc)
1438 1.1.4.2 rmind {
1439 1.1.4.2 rmind struct ifnet *ifp = &sc->vte_if;
1440 1.1.4.2 rmind uint16_t mcr;
1441 1.1.4.2 rmind int i;
1442 1.1.4.2 rmind
1443 1.1.4.2 rmind /* Enable RX/TX MACs. */
1444 1.1.4.2 rmind mcr = CSR_READ_2(sc, VTE_MCR0);
1445 1.1.4.2 rmind if ((mcr & (MCR0_RX_ENB | MCR0_TX_ENB)) !=
1446 1.1.4.2 rmind (MCR0_RX_ENB | MCR0_TX_ENB) &&
1447 1.1.4.2 rmind (ifp->if_flags & IFF_RUNNING) != 0) {
1448 1.1.4.2 rmind mcr |= MCR0_RX_ENB | MCR0_TX_ENB;
1449 1.1.4.2 rmind CSR_WRITE_2(sc, VTE_MCR0, mcr);
1450 1.1.4.2 rmind for (i = VTE_TIMEOUT; i > 0; i--) {
1451 1.1.4.2 rmind mcr = CSR_READ_2(sc, VTE_MCR0);
1452 1.1.4.2 rmind if ((mcr & (MCR0_RX_ENB | MCR0_TX_ENB)) ==
1453 1.1.4.2 rmind (MCR0_RX_ENB | MCR0_TX_ENB))
1454 1.1.4.2 rmind break;
1455 1.1.4.2 rmind DELAY(10);
1456 1.1.4.2 rmind }
1457 1.1.4.2 rmind if (i == 0)
1458 1.1.4.2 rmind aprint_error_dev(sc->vte_dev,
1459 1.1.4.2 rmind "could not enable RX/TX MAC(0x%04x)!\n", mcr);
1460 1.1.4.2 rmind }
1461 1.1.4.4 rmind vte_rxfilter(sc);
1462 1.1.4.2 rmind }
1463 1.1.4.2 rmind
1464 1.1.4.2 rmind static void
1465 1.1.4.2 rmind vte_stop_mac(struct vte_softc *sc)
1466 1.1.4.2 rmind {
1467 1.1.4.2 rmind uint16_t mcr;
1468 1.1.4.2 rmind int i;
1469 1.1.4.2 rmind
1470 1.1.4.2 rmind /* Disable RX/TX MACs. */
1471 1.1.4.2 rmind mcr = CSR_READ_2(sc, VTE_MCR0);
1472 1.1.4.2 rmind if ((mcr & (MCR0_RX_ENB | MCR0_TX_ENB)) != 0) {
1473 1.1.4.2 rmind mcr &= ~(MCR0_RX_ENB | MCR0_TX_ENB);
1474 1.1.4.2 rmind CSR_WRITE_2(sc, VTE_MCR0, mcr);
1475 1.1.4.2 rmind for (i = VTE_TIMEOUT; i > 0; i--) {
1476 1.1.4.2 rmind mcr = CSR_READ_2(sc, VTE_MCR0);
1477 1.1.4.2 rmind if ((mcr & (MCR0_RX_ENB | MCR0_TX_ENB)) == 0)
1478 1.1.4.2 rmind break;
1479 1.1.4.2 rmind DELAY(10);
1480 1.1.4.2 rmind }
1481 1.1.4.2 rmind if (i == 0)
1482 1.1.4.2 rmind aprint_error_dev(sc->vte_dev,
1483 1.1.4.2 rmind "could not disable RX/TX MAC(0x%04x)!\n", mcr);
1484 1.1.4.2 rmind }
1485 1.1.4.2 rmind }
1486 1.1.4.2 rmind
1487 1.1.4.2 rmind static int
1488 1.1.4.2 rmind vte_init_tx_ring(struct vte_softc *sc)
1489 1.1.4.2 rmind {
1490 1.1.4.2 rmind struct vte_tx_desc *desc;
1491 1.1.4.2 rmind struct vte_txdesc *txd;
1492 1.1.4.2 rmind bus_addr_t addr;
1493 1.1.4.2 rmind int i;
1494 1.1.4.2 rmind
1495 1.1.4.2 rmind sc->vte_cdata.vte_tx_prod = 0;
1496 1.1.4.2 rmind sc->vte_cdata.vte_tx_cons = 0;
1497 1.1.4.2 rmind sc->vte_cdata.vte_tx_cnt = 0;
1498 1.1.4.2 rmind
1499 1.1.4.2 rmind /* Pre-allocate TX mbufs for deep copy. */
1500 1.1.4.2 rmind for (i = 0; i < VTE_TX_RING_CNT; i++) {
1501 1.1.4.2 rmind sc->vte_cdata.vte_txmbufs[i] = m_getcl(M_DONTWAIT,
1502 1.1.4.2 rmind MT_DATA, M_PKTHDR);
1503 1.1.4.2 rmind if (sc->vte_cdata.vte_txmbufs[i] == NULL)
1504 1.1.4.2 rmind return (ENOBUFS);
1505 1.1.4.2 rmind sc->vte_cdata.vte_txmbufs[i]->m_pkthdr.len = MCLBYTES;
1506 1.1.4.2 rmind sc->vte_cdata.vte_txmbufs[i]->m_len = MCLBYTES;
1507 1.1.4.2 rmind }
1508 1.1.4.2 rmind desc = sc->vte_cdata.vte_tx_ring;
1509 1.1.4.2 rmind bzero(desc, VTE_TX_RING_SZ);
1510 1.1.4.2 rmind for (i = 0; i < VTE_TX_RING_CNT; i++) {
1511 1.1.4.2 rmind txd = &sc->vte_cdata.vte_txdesc[i];
1512 1.1.4.2 rmind txd->tx_m = NULL;
1513 1.1.4.2 rmind if (i != VTE_TX_RING_CNT - 1)
1514 1.1.4.2 rmind addr = sc->vte_cdata.vte_tx_ring_map->dm_segs[0].ds_addr +
1515 1.1.4.2 rmind sizeof(struct vte_tx_desc) * (i + 1);
1516 1.1.4.2 rmind else
1517 1.1.4.2 rmind addr = sc->vte_cdata.vte_tx_ring_map->dm_segs[0].ds_addr +
1518 1.1.4.2 rmind sizeof(struct vte_tx_desc) * 0;
1519 1.1.4.2 rmind desc = &sc->vte_cdata.vte_tx_ring[i];
1520 1.1.4.2 rmind desc->dtnp = htole32(addr);
1521 1.1.4.2 rmind DPRINTF(("tx ring desc %d addr 0x%x\n", i, (u_int)addr));
1522 1.1.4.2 rmind txd->tx_desc = desc;
1523 1.1.4.2 rmind }
1524 1.1.4.2 rmind
1525 1.1.4.2 rmind bus_dmamap_sync(sc->vte_dmatag,
1526 1.1.4.2 rmind sc->vte_cdata.vte_tx_ring_map, 0,
1527 1.1.4.2 rmind sc->vte_cdata.vte_tx_ring_map->dm_mapsize,
1528 1.1.4.2 rmind BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
1529 1.1.4.2 rmind return (0);
1530 1.1.4.2 rmind }
1531 1.1.4.2 rmind
1532 1.1.4.2 rmind static int
1533 1.1.4.2 rmind vte_init_rx_ring(struct vte_softc *sc)
1534 1.1.4.2 rmind {
1535 1.1.4.2 rmind struct vte_rx_desc *desc;
1536 1.1.4.2 rmind struct vte_rxdesc *rxd;
1537 1.1.4.2 rmind bus_addr_t addr;
1538 1.1.4.2 rmind int i;
1539 1.1.4.2 rmind
1540 1.1.4.2 rmind sc->vte_cdata.vte_rx_cons = 0;
1541 1.1.4.2 rmind desc = sc->vte_cdata.vte_rx_ring;
1542 1.1.4.2 rmind bzero(desc, VTE_RX_RING_SZ);
1543 1.1.4.2 rmind for (i = 0; i < VTE_RX_RING_CNT; i++) {
1544 1.1.4.2 rmind rxd = &sc->vte_cdata.vte_rxdesc[i];
1545 1.1.4.2 rmind rxd->rx_m = NULL;
1546 1.1.4.2 rmind if (i != VTE_RX_RING_CNT - 1)
1547 1.1.4.2 rmind addr = sc->vte_cdata.vte_rx_ring_map->dm_segs[0].ds_addr
1548 1.1.4.2 rmind + sizeof(struct vte_rx_desc) * (i + 1);
1549 1.1.4.2 rmind else
1550 1.1.4.2 rmind addr = sc->vte_cdata.vte_rx_ring_map->dm_segs[0].ds_addr
1551 1.1.4.2 rmind + sizeof(struct vte_rx_desc) * 0;
1552 1.1.4.2 rmind desc = &sc->vte_cdata.vte_rx_ring[i];
1553 1.1.4.2 rmind desc->drnp = htole32(addr);
1554 1.1.4.2 rmind DPRINTF(("rx ring desc %d addr 0x%x\n", i, (u_int)addr));
1555 1.1.4.2 rmind rxd->rx_desc = desc;
1556 1.1.4.2 rmind if (vte_newbuf(sc, rxd) != 0)
1557 1.1.4.2 rmind return (ENOBUFS);
1558 1.1.4.2 rmind }
1559 1.1.4.2 rmind
1560 1.1.4.2 rmind bus_dmamap_sync(sc->vte_dmatag,
1561 1.1.4.2 rmind sc->vte_cdata.vte_rx_ring_map, 0,
1562 1.1.4.2 rmind sc->vte_cdata.vte_rx_ring_map->dm_mapsize,
1563 1.1.4.2 rmind BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
1564 1.1.4.2 rmind
1565 1.1.4.2 rmind return (0);
1566 1.1.4.2 rmind }
1567 1.1.4.2 rmind
1568 1.1.4.2 rmind static void
1569 1.1.4.2 rmind vte_rxfilter(struct vte_softc *sc)
1570 1.1.4.2 rmind {
1571 1.1.4.2 rmind struct ether_multistep step;
1572 1.1.4.2 rmind struct ether_multi *enm;
1573 1.1.4.2 rmind struct ifnet *ifp;
1574 1.1.4.2 rmind uint8_t *eaddr;
1575 1.1.4.2 rmind uint32_t crc;
1576 1.1.4.2 rmind uint16_t rxfilt_perf[VTE_RXFILT_PERFECT_CNT][3];
1577 1.1.4.2 rmind uint16_t mchash[4], mcr;
1578 1.1.4.2 rmind int i, nperf;
1579 1.1.4.2 rmind
1580 1.1.4.2 rmind ifp = &sc->vte_if;
1581 1.1.4.2 rmind
1582 1.1.4.2 rmind DPRINTF(("vte_rxfilter\n"));
1583 1.1.4.4 rmind memset(mchash, 0, sizeof(mchash));
1584 1.1.4.2 rmind for (i = 0; i < VTE_RXFILT_PERFECT_CNT; i++) {
1585 1.1.4.2 rmind rxfilt_perf[i][0] = 0xFFFF;
1586 1.1.4.2 rmind rxfilt_perf[i][1] = 0xFFFF;
1587 1.1.4.2 rmind rxfilt_perf[i][2] = 0xFFFF;
1588 1.1.4.2 rmind }
1589 1.1.4.2 rmind
1590 1.1.4.2 rmind mcr = CSR_READ_2(sc, VTE_MCR0);
1591 1.1.4.2 rmind DPRINTF(("vte_rxfilter mcr 0x%x\n", mcr));
1592 1.1.4.4 rmind mcr &= ~(MCR0_PROMISC | MCR0_BROADCAST_DIS | MCR0_MULTICAST);
1593 1.1.4.4 rmind if ((ifp->if_flags & IFF_BROADCAST) == 0)
1594 1.1.4.4 rmind mcr |= MCR0_BROADCAST_DIS;
1595 1.1.4.2 rmind if ((ifp->if_flags & (IFF_PROMISC | IFF_ALLMULTI)) != 0) {
1596 1.1.4.2 rmind if ((ifp->if_flags & IFF_PROMISC) != 0)
1597 1.1.4.2 rmind mcr |= MCR0_PROMISC;
1598 1.1.4.2 rmind if ((ifp->if_flags & IFF_ALLMULTI) != 0)
1599 1.1.4.2 rmind mcr |= MCR0_MULTICAST;
1600 1.1.4.2 rmind mchash[0] = 0xFFFF;
1601 1.1.4.2 rmind mchash[1] = 0xFFFF;
1602 1.1.4.2 rmind mchash[2] = 0xFFFF;
1603 1.1.4.2 rmind mchash[3] = 0xFFFF;
1604 1.1.4.2 rmind goto chipit;
1605 1.1.4.2 rmind }
1606 1.1.4.2 rmind
1607 1.1.4.2 rmind ETHER_FIRST_MULTI(step, &sc->vte_ec, enm);
1608 1.1.4.2 rmind nperf = 0;
1609 1.1.4.2 rmind while (enm != NULL) {
1610 1.1.4.4 rmind if (memcmp(enm->enm_addrlo, enm->enm_addrhi, ETHER_ADDR_LEN) != 0) {
1611 1.1.4.2 rmind sc->vte_if.if_flags |= IFF_ALLMULTI;
1612 1.1.4.2 rmind mcr |= MCR0_MULTICAST;
1613 1.1.4.2 rmind mchash[0] = 0xFFFF;
1614 1.1.4.2 rmind mchash[1] = 0xFFFF;
1615 1.1.4.2 rmind mchash[2] = 0xFFFF;
1616 1.1.4.2 rmind mchash[3] = 0xFFFF;
1617 1.1.4.2 rmind goto chipit;
1618 1.1.4.2 rmind }
1619 1.1.4.2 rmind /*
1620 1.1.4.2 rmind * Program the first 3 multicast groups into
1621 1.1.4.2 rmind * the perfect filter. For all others, use the
1622 1.1.4.2 rmind * hash table.
1623 1.1.4.2 rmind */
1624 1.1.4.2 rmind if (nperf < VTE_RXFILT_PERFECT_CNT) {
1625 1.1.4.2 rmind eaddr = enm->enm_addrlo;
1626 1.1.4.2 rmind rxfilt_perf[nperf][0] = eaddr[1] << 8 | eaddr[0];
1627 1.1.4.2 rmind rxfilt_perf[nperf][1] = eaddr[3] << 8 | eaddr[2];
1628 1.1.4.2 rmind rxfilt_perf[nperf][2] = eaddr[5] << 8 | eaddr[4];
1629 1.1.4.2 rmind nperf++;
1630 1.1.4.4 rmind } else {
1631 1.1.4.4 rmind crc = ether_crc32_be(enm->enm_addrlo, ETHER_ADDR_LEN);
1632 1.1.4.4 rmind mchash[crc >> 30] |= 1 << ((crc >> 26) & 0x0F);
1633 1.1.4.2 rmind }
1634 1.1.4.2 rmind ETHER_NEXT_MULTI(step, enm);
1635 1.1.4.2 rmind }
1636 1.1.4.2 rmind if (mchash[0] != 0 || mchash[1] != 0 || mchash[2] != 0 ||
1637 1.1.4.2 rmind mchash[3] != 0)
1638 1.1.4.2 rmind mcr |= MCR0_MULTICAST;
1639 1.1.4.2 rmind
1640 1.1.4.2 rmind chipit:
1641 1.1.4.2 rmind /* Program multicast hash table. */
1642 1.1.4.2 rmind DPRINTF(("chipit write multicast\n"));
1643 1.1.4.2 rmind CSR_WRITE_2(sc, VTE_MAR0, mchash[0]);
1644 1.1.4.2 rmind CSR_WRITE_2(sc, VTE_MAR1, mchash[1]);
1645 1.1.4.2 rmind CSR_WRITE_2(sc, VTE_MAR2, mchash[2]);
1646 1.1.4.2 rmind CSR_WRITE_2(sc, VTE_MAR3, mchash[3]);
1647 1.1.4.2 rmind /* Program perfect filter table. */
1648 1.1.4.2 rmind DPRINTF(("chipit write perfect filter\n"));
1649 1.1.4.2 rmind for (i = 0; i < VTE_RXFILT_PERFECT_CNT; i++) {
1650 1.1.4.2 rmind CSR_WRITE_2(sc, VTE_RXFILTER_PEEFECT_BASE + 8 * i + 0,
1651 1.1.4.2 rmind rxfilt_perf[i][0]);
1652 1.1.4.2 rmind CSR_WRITE_2(sc, VTE_RXFILTER_PEEFECT_BASE + 8 * i + 2,
1653 1.1.4.2 rmind rxfilt_perf[i][1]);
1654 1.1.4.2 rmind CSR_WRITE_2(sc, VTE_RXFILTER_PEEFECT_BASE + 8 * i + 4,
1655 1.1.4.2 rmind rxfilt_perf[i][2]);
1656 1.1.4.2 rmind }
1657 1.1.4.2 rmind DPRINTF(("chipit mcr0 0x%x\n", mcr));
1658 1.1.4.2 rmind CSR_WRITE_2(sc, VTE_MCR0, mcr);
1659 1.1.4.2 rmind DPRINTF(("chipit read mcro\n"));
1660 1.1.4.2 rmind CSR_READ_2(sc, VTE_MCR0);
1661 1.1.4.2 rmind DPRINTF(("chipit done\n"));
1662 1.1.4.2 rmind }
1663 1.1.4.2 rmind
1664 1.1.4.2 rmind /*
1665 1.1.4.2 rmind * Set up sysctl(3) MIB, hw.vte.* - Individual controllers will be
1666 1.1.4.2 rmind * set up in vte_pci_attach()
1667 1.1.4.2 rmind */
1668 1.1.4.2 rmind SYSCTL_SETUP(sysctl_vte, "sysctl vte subtree setup")
1669 1.1.4.2 rmind {
1670 1.1.4.2 rmind int rc;
1671 1.1.4.2 rmind const struct sysctlnode *node;
1672 1.1.4.2 rmind
1673 1.1.4.2 rmind if ((rc = sysctl_createv(clog, 0, NULL, NULL,
1674 1.1.4.2 rmind 0, CTLTYPE_NODE, "hw", NULL,
1675 1.1.4.2 rmind NULL, 0, NULL, 0, CTL_HW, CTL_EOL)) != 0) {
1676 1.1.4.2 rmind goto err;
1677 1.1.4.2 rmind }
1678 1.1.4.2 rmind
1679 1.1.4.2 rmind if ((rc = sysctl_createv(clog, 0, NULL, &node,
1680 1.1.4.2 rmind 0, CTLTYPE_NODE, "vte",
1681 1.1.4.2 rmind SYSCTL_DESCR("vte interface controls"),
1682 1.1.4.2 rmind NULL, 0, NULL, 0, CTL_HW, CTL_CREATE, CTL_EOL)) != 0) {
1683 1.1.4.2 rmind goto err;
1684 1.1.4.2 rmind }
1685 1.1.4.2 rmind
1686 1.1.4.2 rmind vte_root_num = node->sysctl_num;
1687 1.1.4.2 rmind return;
1688 1.1.4.2 rmind
1689 1.1.4.2 rmind err:
1690 1.1.4.2 rmind aprint_error("%s: syctl_createv failed (rc = %d)\n", __func__, rc);
1691 1.1.4.2 rmind }
1692 1.1.4.2 rmind
1693 1.1.4.2 rmind static int
1694 1.1.4.2 rmind vte_sysctl_intrxct(SYSCTLFN_ARGS)
1695 1.1.4.2 rmind {
1696 1.1.4.2 rmind int error, t;
1697 1.1.4.2 rmind struct sysctlnode node;
1698 1.1.4.2 rmind struct vte_softc *sc;
1699 1.1.4.2 rmind
1700 1.1.4.2 rmind node = *rnode;
1701 1.1.4.2 rmind sc = node.sysctl_data;
1702 1.1.4.2 rmind t = sc->vte_int_rx_mod;
1703 1.1.4.2 rmind node.sysctl_data = &t;
1704 1.1.4.2 rmind error = sysctl_lookup(SYSCTLFN_CALL(&node));
1705 1.1.4.2 rmind if (error || newp == NULL)
1706 1.1.4.2 rmind return error;
1707 1.1.4.2 rmind if (t < VTE_IM_BUNDLE_MIN || t > VTE_IM_BUNDLE_MAX)
1708 1.1.4.2 rmind return EINVAL;
1709 1.1.4.2 rmind
1710 1.1.4.2 rmind sc->vte_int_rx_mod = t;
1711 1.1.4.2 rmind vte_miibus_statchg(sc->vte_dev);
1712 1.1.4.2 rmind return 0;
1713 1.1.4.2 rmind }
1714 1.1.4.2 rmind
1715 1.1.4.2 rmind static int
1716 1.1.4.2 rmind vte_sysctl_inttxct(SYSCTLFN_ARGS)
1717 1.1.4.2 rmind {
1718 1.1.4.2 rmind int error, t;
1719 1.1.4.2 rmind struct sysctlnode node;
1720 1.1.4.2 rmind struct vte_softc *sc;
1721 1.1.4.2 rmind
1722 1.1.4.2 rmind node = *rnode;
1723 1.1.4.2 rmind sc = node.sysctl_data;
1724 1.1.4.2 rmind t = sc->vte_int_tx_mod;
1725 1.1.4.2 rmind node.sysctl_data = &t;
1726 1.1.4.2 rmind error = sysctl_lookup(SYSCTLFN_CALL(&node));
1727 1.1.4.2 rmind if (error || newp == NULL)
1728 1.1.4.2 rmind return error;
1729 1.1.4.2 rmind
1730 1.1.4.2 rmind if (t < VTE_IM_BUNDLE_MIN || t > VTE_IM_BUNDLE_MAX)
1731 1.1.4.2 rmind return EINVAL;
1732 1.1.4.2 rmind sc->vte_int_tx_mod = t;
1733 1.1.4.2 rmind vte_miibus_statchg(sc->vte_dev);
1734 1.1.4.2 rmind return 0;
1735 1.1.4.2 rmind }
1736