2 * Copyright (c) 1995, 1996 Matt Thomas <matt@3am-software.com>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. The name of the author may not be used to endorse or promote products
11 * derived from this software withough specific prior written permission
13 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
14 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
15 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
16 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
17 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
18 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
19 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
20 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
22 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 * $FreeBSD: src/sys/dev/pdq/pdq_ifsubr.c,v 1.11.2.1 2000/08/02 22:39:30 peter Exp $
25 * $DragonFly: src/sys/dev/netif/pdq_layer/Attic/pdq_ifsubr.c,v 1.7 2004/07/23 07:16:27 joerg Exp $
30 * DEC PDQ FDDI Controller; code for BSD derived operating systems
32 * This module provide bus independent BSD specific O/S functions.
33 * (ie. it provides an ifnet interface to the rest of the system)
39 #include <sys/param.h>
40 #include <sys/socket.h>
41 #include <sys/sockio.h>
42 #if defined(__bsdi__) || defined(__NetBSD__)
43 #include <sys/device.h>
47 #include <net/if_dl.h>
51 #if defined(__DragonFly__) || defined(__FreeBSD__)
53 #include <netinet/in.h>
54 #include <netinet/if_ether.h>
56 #include <netinet/if_fddi.h>
58 #include <net/if_fddi.h>
62 #include <i386/isa/isavar.h>
67 #include <netns/ns_if.h>
70 #if defined(__DragonFly__) || defined(__FreeBSD__)
78 #if defined(__bsdi__) && _BSDI_VERSION < 199506 /* XXX */
84 sc->sc_ac.ac_ipaddr = IA_SIN(ifa)->sin_addr;
85 arpwhohas(&sc->sc_ac, &IA_SIN(ifa)->sin_addr);
86 #if _BSDI_VERSION >= 199401
87 ifa->ifa_rtrequest = arp_rtrequest;
88 ifa->ifa_flags |= RTF_CLONING;
98 if (sc->sc_if.if_flags & IFF_UP) {
99 sc->sc_if.if_flags |= IFF_RUNNING;
100 if (sc->sc_if.if_flags & IFF_PROMISC) {
101 sc->sc_pdq->pdq_flags |= PDQ_PROMISC;
103 sc->sc_pdq->pdq_flags &= ~PDQ_PROMISC;
105 if (sc->sc_if.if_flags & IFF_ALLMULTI) {
106 sc->sc_pdq->pdq_flags |= PDQ_ALLMULTI;
108 sc->sc_pdq->pdq_flags &= ~PDQ_ALLMULTI;
110 if (sc->sc_if.if_flags & IFF_LINK1) {
111 sc->sc_pdq->pdq_flags |= PDQ_PASS_SMT;
113 sc->sc_pdq->pdq_flags &= ~PDQ_PASS_SMT;
115 sc->sc_pdq->pdq_flags |= PDQ_RUNNING;
118 sc->sc_if.if_flags &= ~IFF_RUNNING;
119 sc->sc_pdq->pdq_flags &= ~PDQ_RUNNING;
120 pdq_stop(sc->sc_pdq);
129 * No progress was made on the transmit queue for PDQ_OS_TX_TRANSMIT
130 * seconds. Remove all queued packets.
133 ifp->if_flags &= ~IFF_OACTIVE;
137 IF_DEQUEUE(&ifp->if_snd, m);
148 pdq_softc_t *sc = (pdq_softc_t *) ((caddr_t) ifp - offsetof(pdq_softc_t, sc_ac.ac_if));
149 struct ifqueue *ifq = &ifp->if_snd;
153 if ((ifp->if_flags & IFF_RUNNING) == 0)
156 if (sc->sc_if.if_timer == 0)
157 sc->sc_if.if_timer = PDQ_OS_TX_TIMEOUT;
159 if ((sc->sc_pdq->pdq_flags & PDQ_TXOK) == 0) {
160 sc->sc_if.if_flags |= IFF_OACTIVE;
168 if (pdq_queue_transmit_data(sc->sc_pdq, m) == PDQ_FALSE) {
169 ifp->if_flags |= IFF_OACTIVE;
175 PDQ_DO_TYPE2_PRODUCER(sc->sc_pdq);
184 pdq_softc_t *sc = (pdq_softc_t *) pdq->pdq_os_ctx;
185 struct fddi_header *fh = mtod(m, struct fddi_header *);
187 sc->sc_if.if_ipackets++;
188 if (sc->sc_bpf != NULL)
190 if ((fh->fddi_fc & (FDDIFC_L|FDDIFC_F)) != FDDIFC_LLC_ASYNC) {
195 m->m_pkthdr.len = pktlen;
196 (*sc->sc_if.if_input)(&sc->sc_if, m);
200 pdq_os_restart_transmitter(
203 pdq_softc_t *sc = (pdq_softc_t *) pdq->pdq_os_ctx;
204 sc->sc_if.if_flags &= ~IFF_OACTIVE;
205 if (sc->sc_if.if_snd.ifq_head != NULL) {
206 sc->sc_if.if_timer = PDQ_OS_TX_TIMEOUT;
207 pdq_ifstart(&sc->sc_if);
209 sc->sc_if.if_timer = 0;
214 pdq_os_transmit_done(
218 pdq_softc_t *sc = (pdq_softc_t *) pdq->pdq_os_ctx;
219 if (sc->sc_bpf != NULL)
222 sc->sc_if.if_opackets++;
231 pdq_softc_t *sc = (pdq_softc_t *) pdq->pdq_os_ctx;
232 struct ifmultiaddr *ifma;
234 for (ifma = sc->sc_if.if_multiaddrs.lh_first; ifma && num_addrs > 0;
235 ifma = ifma->ifma_link.le_next) {
237 if (ifma->ifma_addr->sa_family != AF_LINK)
239 mcaddr = LLADDR((struct sockaddr_dl *)ifma->ifma_addr);
240 ((u_short *) addr->lanaddr_bytes)[0] = ((u_short *) mcaddr)[0];
241 ((u_short *) addr->lanaddr_bytes)[1] = ((u_short *) mcaddr)[1];
242 ((u_short *) addr->lanaddr_bytes)[2] = ((u_short *) mcaddr)[2];
249 pdq_ifioctl(struct ifnet *ifp, ioctl_cmd_t cmd, caddr_t data, struct ucred *cr)
251 pdq_softc_t *sc = (pdq_softc_t *) ((caddr_t) ifp - offsetof(pdq_softc_t, sc_ac.ac_if));
258 struct ifaddr *ifa = (struct ifaddr *)data;
260 ifp->if_flags |= IFF_UP;
261 switch(ifa->ifa_addr->sa_family) {
265 arp_ifinit(&sc->sc_ac.ac_if, ifa);
271 /* This magic copied from if_is.c; I don't use XNS,
272 * so I have no way of telling if this actually
276 struct ns_addr *ina = &(IA_SNS(ifa)->sns_addr);
277 if (ns_nullhost(*ina)) {
278 ina->x_host = *(union ns_host *)(sc->sc_ac.ac_enaddr);
280 ifp->if_flags &= ~IFF_RUNNING;
281 bcopy((caddr_t)ina->x_host.c_host,
282 (caddr_t)sc->sc_ac.ac_enaddr,
283 sizeof sc->sc_ac.ac_enaddr);
299 struct ifreq *ifr = (struct ifreq *)data;
300 bcopy((caddr_t) sc->sc_ac.ac_enaddr,
301 (caddr_t) ((struct sockaddr *)&ifr->ifr_data)->sa_data,
314 * Update multicast listeners
316 if (sc->sc_if.if_flags & IFF_RUNNING)
321 #if defined(SIOCSIFMTU)
322 #if !defined(ifr_mtu)
323 #define ifr_mtu ifr_metric
326 struct ifreq *ifr = (struct ifreq *)data;
328 * Set the interface MTU.
330 if (ifr->ifr_mtu > FDDIMTU) {
334 ifp->if_mtu = ifr->ifr_mtu;
337 #endif /* SIOCSIFMTU */
349 #ifndef IFF_NOTRAILERS
350 #define IFF_NOTRAILERS 0
356 ifnet_ret_t (*ifwatchdog)(int unit))
358 struct ifnet *ifp = &sc->sc_if;
360 ifp->if_flags = IFF_BROADCAST|IFF_SIMPLEX|IFF_NOTRAILERS|IFF_MULTICAST;
362 #if defined(__DragonFly__) || (defined(__FreeBSD__) && BSD >= 199506) || defined(__NetBSD__)
363 ifp->if_watchdog = pdq_ifwatchdog;
365 ifp->if_watchdog = ifwatchdog;
368 ifp->if_ioctl = pdq_ifioctl;
369 ifp->if_start = pdq_ifstart;
370 ifp->if_snd.ifq_maxlen = IFQ_MAXLEN;