From 567ba9b00a248431e7c1147c4e079fd7a11b9ecf Mon Sep 17 00:00:00 2001 From: brooks Date: Fri, 10 Jun 2005 16:49:24 +0000 Subject: Stop embedding struct ifnet at the top of driver softcs. Instead the struct ifnet or the layer 2 common structure it was embedded in have been replaced with a struct ifnet pointer to be filled by a call to the new function, if_alloc(). The layer 2 common structure is also allocated via if_alloc() based on the interface type. It is hung off the new struct ifnet member, if_l2com. This change removes the size of these structures from the kernel ABI and will allow us to better manage them as interfaces come and go. Other changes of note: - Struct arpcom is no longer referenced in normal interface code. Instead the Ethernet address is accessed via the IFP2ENADDR() macro. To enforce this ac_enaddr has been renamed to _ac_enaddr. - The second argument to ether_ifattach is now always the mac address from driver private storage rather than sometimes being ac_enaddr. Reviewed by: sobomax, sam --- sys/dev/cx/if_cx.c | 138 ++++++++++++++++++++++++++++------------------------- 1 file changed, 74 insertions(+), 64 deletions(-) (limited to 'sys/dev/cx') diff --git a/sys/dev/cx/if_cx.c b/sys/dev/cx/if_cx.c index 8ff12c0..4c7152c 100644 --- a/sys/dev/cx/if_cx.c +++ b/sys/dev/cx/if_cx.c @@ -162,7 +162,7 @@ typedef struct _drv_t { struct callout timeout_handle; #else struct ifqueue queue; - struct sppp pp; + struct ifnet *ifp; #endif struct cdev *devt; async_q aqueue; @@ -378,7 +378,7 @@ static void cx_intr (void *arg) IF_DEQUEUE (&d->queue,m); if (!m) continue; - sppp_input (&d->pp.pp_if, m); + sppp_input (d->ifp, m); } } #endif @@ -839,24 +839,33 @@ static int cx_attach (device_t dev) callout_init (&d->timeout_handle, cx_mpsafenet ? CALLOUT_MPSAFE : 0); #else /*NETGRAPH*/ - d->pp.pp_if.if_softc = d; - if_initname (&d->pp.pp_if, "cx", b->num * NCHAN + c->num); - d->pp.pp_if.if_mtu = PP_MTU; - d->pp.pp_if.if_flags = IFF_POINTOPOINT | IFF_MULTICAST | + d->ifp = if_alloc(IFT_PPP); + if (d->ifp == NULL) { + printf ("%s: cannot if_alloc() common interface\n", + d->name); + channel [b->num*NCHAN + c->num] = 0; + c->sys = 0; + cx_bus_dma_mem_free (&d->dmamem); + continue; + } + d->ifp->if_softc = d; + if_initname (d->ifp, "cx", b->num * NCHAN + c->num); + d->ifp->if_mtu = PP_MTU; + d->ifp->if_flags = IFF_POINTOPOINT | IFF_MULTICAST | IFF_NEEDSGIANT; - d->pp.pp_if.if_ioctl = cx_sioctl; - d->pp.pp_if.if_start = cx_ifstart; - d->pp.pp_if.if_watchdog = cx_ifwatchdog; - d->pp.pp_if.if_init = cx_initialize; + d->ifp->if_ioctl = cx_sioctl; + d->ifp->if_start = cx_ifstart; + d->ifp->if_watchdog = cx_ifwatchdog; + d->ifp->if_init = cx_initialize; d->queue.ifq_maxlen = 2; mtx_init (&d->queue.ifq_mtx, "cx_queue", NULL, MTX_DEF); - sppp_attach (&d->pp.pp_if); - if_attach (&d->pp.pp_if); - d->pp.pp_tlf = cx_tlf; - d->pp.pp_tls = cx_tls; + sppp_attach (d->ifp); + if_attach (d->ifp); + IFP2SP(d->ifp)->pp_tlf = cx_tlf; + IFP2SP(d->ifp)->pp_tls = cx_tls; /* If BPF is in the kernel, call the attach for it. * Size of PPP header is 4 bytes. */ - bpfattach (&d->pp.pp_if, DLT_PPP, 4); + bpfattach (d->ifp, DLT_PPP, 4); #endif /*NETGRAPH*/ } d->tty = ttyalloc (); @@ -968,11 +977,12 @@ static int cx_detach (device_t dev) mtx_destroy (&d->hi_queue.ifq_mtx); #else /* Detach from the packet filter list of interfaces. */ - bpfdetach (&d->pp.pp_if); + bpfdetach (d->ifp); /* Detach from the sync PPP list. */ - sppp_detach (&d->pp.pp_if); + sppp_detach (d->ifp); - if_detach (&d->pp.pp_if); + if_detach (d->ifp); + if_free(d->ifp); /* XXXRIK: check interconnection with irq handler */ IF_DRAIN (&d->queue); mtx_destroy (&d->queue.ifq_mtx); @@ -1033,21 +1043,21 @@ static void cx_ifwatchdog (struct ifnet *ifp) static void cx_tlf (struct sppp *sp) { - drv_t *d = sp->pp_if.if_softc; + drv_t *d = SP2IFP(sp)->if_softc; CX_DEBUG (d, ("cx_tlf\n")); /* cx_set_dtr (d->chan, 0);*/ /* cx_set_rts (d->chan, 0);*/ - if (!(d->pp.pp_flags & PP_FR) && !(d->pp.pp_if.if_flags & PP_CISCO)) + if (!(IFP2SP(d->ifp)->pp_flags & PP_FR) && !(d->ifp->if_flags & PP_CISCO)) sp->pp_down (sp); } static void cx_tls (struct sppp *sp) { - drv_t *d = sp->pp_if.if_softc; + drv_t *d = SP2IFP(sp)->if_softc; CX_DEBUG (d, ("cx_tls\n")); - if (!(d->pp.pp_flags & PP_FR) && !(d->pp.pp_if.if_flags & PP_CISCO)) + if (!(IFP2SP(d->ifp)->pp_flags & PP_FR) && !(d->ifp->if_flags & PP_CISCO)) sp->pp_up (sp); } @@ -1104,7 +1114,7 @@ static int cx_sioctl (struct ifnet *ifp, u_long cmd, caddr_t data) cx_start (d); } else if (was_up && !should_be_up) { /* Interface is going down -- stop it. */ - /* if ((d->pp.pp_flags & PP_FR) || (ifp->if_flags & PP_CISCO))*/ + /* if ((IFP2SP(d->ifp)->pp_flags & PP_FR) || (ifp->if_flags & PP_CISCO))*/ cx_down (d); } CX_UNLOCK (bd); @@ -1166,13 +1176,13 @@ static void cx_send (drv_t *d) if (! m) IF_DEQUEUE (&d->lo_queue, m); #else - m = sppp_dequeue (&d->pp.pp_if); + m = sppp_dequeue (d->ifp); #endif if (! m) return; #ifndef NETGRAPH - if (d->pp.pp_if.if_bpf) - BPF_MTAP (&d->pp.pp_if, m); + if (d->ifp->if_bpf) + BPF_MTAP (d->ifp, m); #endif len = m->m_pkthdr.len; if (! m->m_next) @@ -1189,11 +1199,11 @@ static void cx_send (drv_t *d) #ifdef NETGRAPH d->timeout = 10; #else - d->pp.pp_if.if_timer = 10; + d->ifp->if_timer = 10; #endif } #ifndef NETGRAPH - d->pp.pp_if.if_flags |= IFF_OACTIVE; + d->ifp->if_flags |= IFF_OACTIVE; #endif } @@ -1260,9 +1270,9 @@ static void cx_transmit (cx_chan_t *c, void *attachment, int len) #ifdef NETGRAPH d->timeout = 0; #else - ++d->pp.pp_if.if_opackets; - d->pp.pp_if.if_flags &= ~IFF_OACTIVE; - d->pp.pp_if.if_timer = 0; + ++d->ifp->if_opackets; + d->ifp->if_flags &= ~IFF_OACTIVE; + d->ifp->if_timer = 0; #endif cx_start (d); } @@ -1314,7 +1324,7 @@ static void cx_receive (cx_chan_t *c, char *data, int len) if (! m) { CX_DEBUG (d, ("no memory for packet\n")); #ifndef NETGRAPH - ++d->pp.pp_if.if_iqdrops; + ++d->ifp->if_iqdrops; #endif return; } @@ -1324,12 +1334,12 @@ static void cx_receive (cx_chan_t *c, char *data, int len) m->m_pkthdr.rcvif = 0; NG_SEND_DATA_ONLY (error, d->hook, m); #else - ++d->pp.pp_if.if_ipackets; - m->m_pkthdr.rcvif = &d->pp.pp_if; + ++d->ifp->if_ipackets; + m->m_pkthdr.rcvif = d->ifp; /* Check if there's a BPF listener on this interface. * If so, hand off the raw packet to bpf. */ - if (d->pp.pp_if.if_bpf) - BPF_TAP (&d->pp.pp_if, data, len); + if (d->ifp->if_bpf) + BPF_TAP (d->ifp, data, len); IF_ENQUEUE (&d->queue, m); #endif } @@ -1368,7 +1378,7 @@ static void cx_error (cx_chan_t *c, int data) } #ifndef NETGRAPH else - ++d->pp.pp_if.if_ierrors; + ++d->ifp->if_ierrors; #endif break; case CX_CRC: @@ -1385,7 +1395,7 @@ static void cx_error (cx_chan_t *c, int data) } #ifndef NETGRAPH else - ++d->pp.pp_if.if_ierrors; + ++d->ifp->if_ierrors; #endif break; case CX_OVERRUN: @@ -1402,8 +1412,8 @@ static void cx_error (cx_chan_t *c, int data) #endif #ifndef NETGRAPH else { - ++d->pp.pp_if.if_collisions; - ++d->pp.pp_if.if_ierrors; + ++d->ifp->if_collisions; + ++d->ifp->if_ierrors; } #endif break; @@ -1411,7 +1421,7 @@ static void cx_error (cx_chan_t *c, int data) CX_DEBUG (d, ("overflow error\n")); #ifndef NETGRAPH if (c->mode != M_ASYNC) - ++d->pp.pp_if.if_ierrors; + ++d->ifp->if_ierrors; #endif break; case CX_UNDERRUN: @@ -1420,9 +1430,9 @@ static void cx_error (cx_chan_t *c, int data) #ifdef NETGRAPH d->timeout = 0; #else - ++d->pp.pp_if.if_oerrors; - d->pp.pp_if.if_flags &= ~IFF_OACTIVE; - d->pp.pp_if.if_timer = 0; + ++d->ifp->if_oerrors; + d->ifp->if_flags &= ~IFF_OACTIVE; + d->ifp->if_timer = 0; cx_start (d); #endif } @@ -1440,7 +1450,7 @@ static void cx_error (cx_chan_t *c, int data) } #ifndef NETGRAPH else - ++d->pp.pp_if.if_ierrors; + ++d->ifp->if_ierrors; #endif break; default: @@ -1625,8 +1635,8 @@ static int cx_ioctl (struct cdev *dev, u_long cmd, caddr_t data, int flag, struc s = splhigh (); CX_LOCK (bd); strcpy ((char*)data, (c->mode == M_ASYNC) ? "async" : - (d->pp.pp_flags & PP_FR) ? "fr" : - (d->pp.pp_if.if_flags & PP_CISCO) ? "cisco" : "ppp"); + (IFP2SP(d->ifp)->pp_flags & PP_FR) ? "fr" : + (d->ifp->if_flags & PP_CISCO) ? "cisco" : "ppp"); CX_UNLOCK (bd); splx (s); return 0; @@ -1639,31 +1649,31 @@ static int cx_ioctl (struct cdev *dev, u_long cmd, caddr_t data, int flag, struc return error; if (c->mode == M_ASYNC) return EBUSY; - if (d->pp.pp_if.if_flags & IFF_RUNNING) + if (d->ifp->if_flags & IFF_RUNNING) return EBUSY; if (! strcmp ("cisco", (char*)data)) { - d->pp.pp_flags &= ~(PP_FR); - d->pp.pp_flags |= PP_KEEPALIVE; - d->pp.pp_if.if_flags |= PP_CISCO; + IFP2SP(d->ifp)->pp_flags &= ~(PP_FR); + IFP2SP(d->ifp)->pp_flags |= PP_KEEPALIVE; + d->ifp->if_flags |= PP_CISCO; } else if (! strcmp ("fr", (char*)data)) { - d->pp.pp_if.if_flags &= ~(PP_CISCO); - d->pp.pp_flags |= PP_FR | PP_KEEPALIVE; + d->ifp->if_flags &= ~(PP_CISCO); + IFP2SP(d->ifp)->pp_flags |= PP_FR | PP_KEEPALIVE; } else if (! strcmp ("ppp", (char*)data)) { - d->pp.pp_flags &= ~(PP_FR | PP_KEEPALIVE); - d->pp.pp_if.if_flags &= ~(PP_CISCO); + IFP2SP(d->ifp)->pp_flags &= ~(PP_FR | PP_KEEPALIVE); + d->ifp->if_flags &= ~(PP_CISCO); } else return EINVAL; return 0; case SERIAL_GETKEEPALIVE: CX_DEBUG2 (d, ("ioctl: getkeepalive\n")); - if ((d->pp.pp_flags & PP_FR) || - (d->pp.pp_if.if_flags & PP_CISCO) || + if ((IFP2SP(d->ifp)->pp_flags & PP_FR) || + (d->ifp->if_flags & PP_CISCO) || (c->mode == M_ASYNC)) return EINVAL; s = splhigh (); CX_LOCK (bd); - *(int*)data = (d->pp.pp_flags & PP_KEEPALIVE) ? 1 : 0; + *(int*)data = (IFP2SP(d->ifp)->pp_flags & PP_KEEPALIVE) ? 1 : 0; CX_UNLOCK (bd); splx (s); return 0; @@ -1674,15 +1684,15 @@ static int cx_ioctl (struct cdev *dev, u_long cmd, caddr_t data, int flag, struc error = suser (td); if (error) return error; - if ((d->pp.pp_flags & PP_FR) || - (d->pp.pp_if.if_flags & PP_CISCO)) + if ((IFP2SP(d->ifp)->pp_flags & PP_FR) || + (d->ifp->if_flags & PP_CISCO)) return EINVAL; s = splhigh (); CX_LOCK (bd); if (*(int*)data) - d->pp.pp_flags |= PP_KEEPALIVE; + IFP2SP(d->ifp)->pp_flags |= PP_KEEPALIVE; else - d->pp.pp_flags &= ~PP_KEEPALIVE; + IFP2SP(d->ifp)->pp_flags &= ~PP_KEEPALIVE; CX_UNLOCK (bd); splx (s); return 0; @@ -1898,9 +1908,9 @@ static int cx_ioctl (struct cdev *dev, u_long cmd, caddr_t data, int flag, struc splx (s); #ifndef NETGRAPH if (d->chan->debug) - d->pp.pp_if.if_flags |= IFF_DEBUG; + d->ifp->if_flags |= IFF_DEBUG; else - d->pp.pp_if.if_flags &= (~IFF_DEBUG); + d->ifp->if_flags &= (~IFF_DEBUG); #endif return 0; } -- cgit v1.1