From 78195a764d5e70464a6d4f49bc08332a2a8bb4d0 Mon Sep 17 00:00:00 2001 From: Matthew Dillon Date: Mon, 28 Nov 2005 17:13:47 +0000 Subject: [PATCH] Make all network interrupt service routines MPSAFE part 1/3. Replace the critical section that was previously used to serialize access with the LWKT serializer. Integrate the serializer into the IFNET structure. Note that kern.intr_mpsafe must be set to 1 for network interrupts to actually run MPSAFE. Also note that any interrupts shared with othre non-MP drivers will cause all drivers on that interrupt to run with the Big Giant Lock. Network interrupt - Each network driver then simply passes that serializer to bus_setup_intr() so only a single serializer is required to process the entire interrupt path. LWKT serialization support is already 100% integrated into the interrupt subsystem so it will already be held as of when the registered interrupt procedure is called. Ioctl and if_* functions - All callers of if_* functions (such as if_start, if_ioctl, etc) now obtain the IFNET serializer before making the call. Thus all of these entry points into the driver will now be serialized. if_input - All code that calls if_input now ensures that the serializer is held. It will either already be held (when called from a driver), or the serializer will be wrapped around the call. When packets are forwarded or bridged between interfaces, the target interface serializer will be dropped temporarily to avoid a deadlock. Device Driver access - dev_* entry points into certain pseudo-network devices now obtain and release the serializer. This had to be done on a device-by-device basis (but there are only a few such devices). Thanks to several people for helping test the patch, in particular Sepherosa Ziehau. --- sys/bus/usb/usb_ethersubr.c | 6 +- sys/bus/usb/usb_port.h | 4 +- sys/conf/files.i386 | 3 +- sys/contrib/ipfilter/netinet/ip_fil.c | 13 +- sys/dev/atm/en/midway.c | 4 +- sys/dev/netif/an/if_an.c | 35 +--- sys/dev/netif/an/if_an_isa.c | 7 +- sys/dev/netif/an/if_an_pccard.c | 7 +- sys/dev/netif/an/if_an_pci.c | 7 +- sys/dev/netif/ar/if_ar.c | 50 ++--- sys/dev/netif/aue/if_aue.c | 4 +- sys/dev/netif/awi/awi.c | 120 ++--------- sys/dev/netif/awi/awivar.h | 4 +- sys/dev/netif/awi/if_awi_pccard.c | 28 +-- sys/dev/netif/axe/if_axe.c | 89 ++------ sys/dev/netif/bfe/if_bfe.c | 137 +++---------- sys/dev/netif/bge/if_bge.c | 55 +++-- sys/dev/netif/cm/if_cm_isa.c | 14 +- sys/dev/netif/cm/smc90cx6.c | 35 +--- sys/dev/netif/cs/if_cs.c | 39 +--- sys/dev/netif/cue/if_cue.c | 4 +- sys/dev/netif/cx/if_cx.c | 4 +- sys/dev/netif/dc/if_dc.c | 59 ++---- sys/dev/netif/de/if_de.c | 40 ++-- sys/dev/netif/de/if_devar.h | 8 +- sys/dev/netif/ed/if_ed.c | 13 +- sys/dev/netif/ed/if_ed_isa.c | 38 +++- sys/dev/netif/ed/if_ed_pccard.c | 6 +- sys/dev/netif/ed/if_ed_pci.c | 41 +++- sys/dev/netif/el/if_el.c | 43 ++-- sys/dev/netif/em/if_em.c | 226 ++++++++++++--------- sys/dev/netif/em/if_em.h | 3 +- sys/dev/netif/ep/if_ep.c | 6 +- sys/dev/netif/ep/if_ep_eisa.c | 8 +- sys/dev/netif/ep/if_ep_isa.c | 8 +- sys/dev/netif/ep/if_ep_pccard.c | 8 +- sys/dev/netif/ex/if_ex.c | 24 +-- sys/dev/netif/ex/if_ex_isa.c | 9 +- sys/dev/netif/ex/if_ex_pccard.c | 10 +- sys/dev/netif/fe/if_fe.c | 36 ++-- sys/dev/netif/fe/if_fe_pccard.c | 4 +- sys/dev/netif/fea/if_fea.c | 15 +- sys/dev/netif/fpa/if_fpa.c | 11 +- sys/dev/netif/fwe/if_fwe.c | 29 +-- sys/dev/netif/fxp/if_fxp.c | 39 ++-- sys/dev/netif/gx/if_gx.c | 40 +--- sys/dev/netif/ic/if_ic.c | 4 +- sys/dev/netif/ie/if_ie.c | 61 ++---- sys/dev/netif/kue/if_kue.c | 4 +- sys/dev/netif/le/if_le.c | 38 ++-- sys/dev/netif/lge/if_lge.c | 49 +++-- sys/dev/netif/lnc/if_lnc.c | 7 +- sys/dev/netif/lnc/if_lnc_isa.c | 13 +- sys/dev/netif/lnc/if_lnc_pci.c | 17 +- sys/dev/netif/mn/if_mn.c | 4 +- sys/dev/netif/my/if_my.c | 20 +- sys/dev/netif/my/if_myreg.h | 3 +- sys/dev/netif/ndis/if_ndis.c | 54 ++--- sys/dev/netif/nge/if_nge.c | 49 ++--- sys/dev/netif/nv/if_nv.c | 129 +++++------- sys/dev/netif/nv/if_nvreg.h | 4 +- sys/dev/netif/owi/if_owi.c | 76 +++---- sys/dev/netif/pcn/if_pcn.c | 46 ++--- sys/dev/netif/pdq_layer/pdq_ifsubr.c | 6 +- sys/dev/netif/plip/if_plip.c | 4 +- sys/dev/netif/ray/if_ray.c | 40 ++-- sys/dev/netif/rdp/if_rdp.c | 10 +- sys/dev/netif/re/if_re.c | 63 +++--- sys/dev/netif/rl/if_rl.c | 50 ++--- sys/dev/netif/rue/if_rue.c | 4 +- sys/dev/netif/sbni/Makefile | 4 +- sys/dev/netif/sbni/if_sbni.c | 19 +- sys/dev/netif/sbni/if_sbni_isa.c | 168 --------------- sys/dev/netif/sbni/if_sbni_pci.c | 25 ++- sys/dev/netif/sbsh/if_sbsh.c | 47 ++--- sys/dev/netif/sf/if_sf.c | 38 ++-- sys/dev/netif/sis/if_sis.c | 46 ++--- sys/dev/netif/sk/if_sk.c | 41 ++-- sys/dev/netif/sn/if_sn.c | 52 ++--- sys/dev/netif/sr/if_sr.c | 4 +- sys/dev/netif/ste/if_ste.c | 46 ++--- sys/dev/netif/ti/if_ti.c | 30 ++- sys/dev/netif/tl/if_tl.c | 59 +++--- sys/dev/netif/tx/if_tx.c | 49 ++--- sys/dev/netif/txp/if_txp.c | 37 ++-- sys/dev/netif/vr/if_vr.c | 50 ++--- sys/dev/netif/vx/if_vx.c | 37 ++-- sys/dev/netif/vx/if_vx_eisa.c | 8 +- sys/dev/netif/vx/if_vx_pci.c | 10 +- sys/dev/netif/wb/if_wb.c | 27 ++- sys/dev/netif/wl/if_wl.c | 35 ++-- sys/dev/netif/xe/if_xe.c | 32 ++- sys/dev/netif/xl/if_xl.c | 74 +++---- sys/kern/kern_poll.c | 38 ++-- sys/net/altq/altq_rmclass.c | 10 +- sys/net/altq/altq_subr.c | 7 +- sys/net/bpf.c | 12 +- sys/net/bridge/bridge.c | 4 +- sys/net/disc/if_disc.c | 4 +- sys/net/dummynet/ip_dummynet.c | 8 +- sys/net/ef/if_ef.c | 6 +- sys/net/faith/if_faith.c | 4 +- sys/net/gif/if_gif.c | 10 +- sys/net/gre/if_gre.c | 4 +- sys/net/i4b/driver/i4b_ipr.c | 4 +- sys/net/i4b/driver/i4b_isppp.c | 4 +- sys/net/if.c | 94 +++++++-- sys/net/if_arc.h | 5 +- sys/net/if_arcsubr.c | 21 +- sys/net/if_atm.h | 7 +- sys/net/if_atmsubr.c | 13 +- sys/net/if_ethersubr.c | 32 ++- sys/net/if_fddisubr.c | 10 +- sys/net/if_iso88025subr.c | 13 +- sys/net/if_loop.c | 9 +- sys/net/if_media.c | 8 +- sys/net/if_var.h | 54 +++-- sys/net/ifq_var.h | 43 +++- sys/net/iso88025.h | 6 +- sys/net/oldbridge/bridge.c | 4 +- sys/net/pf/if_pflog.c | 4 +- sys/net/pf/if_pfsync.c | 4 +- sys/net/pf/pf.c | 13 +- sys/net/ppp/if_ppp.c | 21 +- sys/net/sl/if_sl.c | 6 +- sys/net/sppp/if_spppsubr.c | 6 +- sys/net/stf/if_stf.c | 4 +- sys/net/tap/if_tap.c | 198 +++++++++--------- sys/net/tun/if_tun.c | 59 +++--- sys/net/vlan/if_vlan.c | 42 +++- sys/netgraph/eiface/ng_eiface.c | 12 +- sys/netgraph/ether/ng_ether.c | 11 +- sys/netgraph/fec/ng_fec.c | 43 +++- sys/netgraph/iface/ng_iface.c | 4 +- sys/netinet/if_atm.c | 13 +- sys/netinet/if_ether.c | 6 +- sys/netinet/if_fddi.h | 6 +- sys/netinet/in.c | 25 ++- sys/netinet/in_var.h | 5 +- sys/netinet/ip_flow.c | 10 +- sys/netinet/ip_output.c | 9 +- sys/netinet6/in6.c | 16 +- sys/netinet6/ip6_mroute.c | 15 +- sys/netinet6/nd6.c | 12 +- sys/netproto/802_11/ieee80211.c | 4 +- sys/netproto/802_11/ieee80211_input.c | 4 +- sys/netproto/802_11/wlan/ieee80211.c | 4 +- sys/netproto/802_11/wlan/ieee80211_input.c | 4 +- sys/netproto/atalk/aarp.c | 10 +- sys/netproto/atalk/at_control.c | 17 +- sys/netproto/atalk/ddp_output.c | 10 +- sys/netproto/atm/atm_if.c | 7 +- sys/netproto/atm/atm_var.h | 6 +- sys/netproto/ipx/ipx.c | 23 ++- sys/netproto/ipx/ipx_ip.c | 4 +- sys/netproto/ipx/ipx_outputfl.c | 6 +- sys/netproto/natm/natm.c | 33 +-- sys/netproto/ns/ns.c | 21 +- sys/netproto/ns/ns_ip.c | 4 +- sys/netproto/ns/ns_output.c | 4 +- sys/sys/bus.h | 4 +- 161 files changed, 1920 insertions(+), 2309 deletions(-) delete mode 100644 sys/dev/netif/sbni/if_sbni_isa.c diff --git a/sys/bus/usb/usb_ethersubr.c b/sys/bus/usb/usb_ethersubr.c index 1b4dc29fb8..5cc5885925 100644 --- a/sys/bus/usb/usb_ethersubr.c +++ b/sys/bus/usb/usb_ethersubr.c @@ -31,7 +31,7 @@ * * * $FreeBSD: src/sys/dev/usb/usb_ethersubr.c,v 1.17 2003/11/14 11:09:45 johan Exp $ - * $DragonFly: src/sys/bus/usb/usb_ethersubr.c,v 1.13 2005/06/02 20:40:40 dillon Exp $ + * $DragonFly: src/sys/bus/usb/usb_ethersubr.c,v 1.14 2005/11/28 17:13:23 dillon Exp $ */ /* @@ -78,10 +78,10 @@ Static int usbintr(struct netmsg *msg) struct mbuf *m = ((struct netmsg_packet *)msg)->nm_packet; struct ifnet *ifp; - crit_enter(); ifp = m->m_pkthdr.rcvif; + lwkt_serialize_enter(ifp->if_serializer); (*ifp->if_input)(ifp, m); - crit_exit(); + lwkt_serialize_exit(ifp->if_serializer); lwkt_replymsg(&msg->nm_lmsg, 0); return EASYNC; diff --git a/sys/bus/usb/usb_port.h b/sys/bus/usb/usb_port.h index a3ae3f2bc6..eaa52c2c46 100644 --- a/sys/bus/usb/usb_port.h +++ b/sys/bus/usb/usb_port.h @@ -2,7 +2,7 @@ * $OpenBSD: usb_port.h,v 1.18 2000/09/06 22:42:10 rahnds Exp $ * $NetBSD: usb_port.h,v 1.68 2005/07/30 06:14:50 skrll Exp $ * $FreeBSD: src/sys/dev/usb/usb_port.h,v 1.65 2003/11/09 23:54:21 joe Exp $ - * $DragonFly: src/sys/bus/usb/usb_port.h,v 1.13 2005/08/27 19:00:49 asmodai Exp $ + * $DragonFly: src/sys/bus/usb/usb_port.h,v 1.14 2005/11/28 17:13:23 dillon Exp $ */ /* Also already merged from NetBSD: @@ -108,7 +108,6 @@ typedef struct callout usb_callout_t; typedef struct malloc_type *usb_malloc_type; #define Ether_ifattach ether_ifattach -#define IF_INPUT(ifp, m) (*(ifp)->if_input)((ifp), (m)) #define logprintf printf @@ -223,7 +222,6 @@ typedef int usb_malloc_type; #define Ether_ifattach ether_ifattach #define if_deactivate(x) -#define IF_INPUT(ifp, m) (*(ifp)->if_input)(ifp, m) #define usbpoll usbselect #define uhidpoll uhidselect diff --git a/sys/conf/files.i386 b/sys/conf/files.i386 index 4ef116fd86..c029bf7ed6 100644 --- a/sys/conf/files.i386 +++ b/sys/conf/files.i386 @@ -2,7 +2,7 @@ # files marked standard are always included. # # $FreeBSD: src/sys/conf/files.i386,v 1.307.2.38 2003/01/02 20:41:33 kan Exp $ -# $DragonFly: src/sys/conf/Attic/files.i386,v 1.37 2005/11/02 17:19:56 dillon Exp $ +# $DragonFly: src/sys/conf/Attic/files.i386,v 1.38 2005/11/28 17:13:25 dillon Exp $ # # The long compile-with and dependency lines are required because of # limitations in config: backslash-newline doesn't work in strings, and @@ -138,7 +138,6 @@ dev/raid/pst/pst-raid.c optional pst dev/misc/puc/puc.c optional puc dev/misc/puc/pucdata.c optional puc dev/netif/sbni/if_sbni.c optional sbni -dev/netif/sbni/if_sbni_isa.c optional sbni isa dev/netif/sr/if_sr_isa.c optional sr isa dev/misc/syscons/schistory.c optional sc dev/misc/syscons/scmouse.c optional sc diff --git a/sys/contrib/ipfilter/netinet/ip_fil.c b/sys/contrib/ipfilter/netinet/ip_fil.c index bc3ba1fa28..f917003f85 100644 --- a/sys/contrib/ipfilter/netinet/ip_fil.c +++ b/sys/contrib/ipfilter/netinet/ip_fil.c @@ -6,7 +6,7 @@ * @(#)ip_fil.c 2.41 6/5/96 (C) 1993-2000 Darren Reed * @(#)$Id: ip_fil.c,v 2.42.2.60 2002/08/28 12:40:39 darrenr Exp $ * $FreeBSD: src/sys/contrib/ipfilter/netinet/ip_fil.c,v 1.25.2.7 2004/07/04 09:24:38 darrenr Exp $ - * $DragonFly: src/sys/contrib/ipfilter/netinet/ip_fil.c,v 1.19 2005/06/12 15:37:19 hsu Exp $ + * $DragonFly: src/sys/contrib/ipfilter/netinet/ip_fil.c,v 1.20 2005/11/28 17:13:35 dillon Exp $ */ #ifndef SOLARIS #define SOLARIS (defined(sun) && (defined(__svr4__) || defined(__SVR4))) @@ -1843,13 +1843,17 @@ frdest_t *fdp; # ifdef IRIX IFNET_UPPERLOCK(ifp); # endif + lwkt_serialize_enter(ifp->if_serializer); error = (*ifp->if_output)(ifp, m, (struct sockaddr *)dst, ro->ro_rt); + lwkt_serialize_exit(ifp->if_serializer); # ifdef IRIX IFNET_UPPERUNLOCK(ifp); # endif # else + lwkt_serialize_enter(ifp->if_serializer); error = (*ifp->if_output)(ifp, m, (struct sockaddr *)dst); + lwkt_serialize_exit(ifp->if_serializer); # endif goto done; } @@ -1938,7 +1942,8 @@ sendorfree: for (m = m0; m; m = m0) { m0 = m->m_act; m->m_act = 0; - if (error == 0) + if (error == 0) { + lwkt_serialize_enter(ifp->if_serializer); # if (BSD >= 199306) || (defined(IRIX) && (IRIX >= 605)) error = (*ifp->if_output)(ifp, m, (struct sockaddr *)dst, ro->ro_rt); @@ -1946,8 +1951,10 @@ sendorfree: error = (*ifp->if_output)(ifp, m, (struct sockaddr *)dst); # endif - else + lwkt_serialize_exit(ifp->if_serializer); + } else { m_freem(m); + } } } done: diff --git a/sys/dev/atm/en/midway.c b/sys/dev/atm/en/midway.c index 3b07650d45..937e055803 100644 --- a/sys/dev/atm/en/midway.c +++ b/sys/dev/atm/en/midway.c @@ -33,7 +33,7 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD: src/sys/dev/en/midway.c,v 1.19.2.1 2003/01/23 21:06:42 sam Exp $ - * $DragonFly: src/sys/dev/atm/en/midway.c,v 1.20 2005/08/27 03:05:24 hsu Exp $ + * $DragonFly: src/sys/dev/atm/en/midway.c,v 1.21 2005/11/28 17:13:37 dillon Exp $ */ /* @@ -785,7 +785,7 @@ done_probe: /* * final commit */ - atm_ifattach(ifp); + atm_ifattach(ifp, NULL); } diff --git a/sys/dev/netif/an/if_an.c b/sys/dev/netif/an/if_an.c index 0c1b8e5ead..9868b96a91 100644 --- a/sys/dev/netif/an/if_an.c +++ b/sys/dev/netif/an/if_an.c @@ -30,7 +30,7 @@ * THE POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD: src/sys/dev/an/if_an.c,v 1.2.2.13 2003/02/11 03:32:48 ambrisko Exp $ - * $DragonFly: src/sys/dev/netif/an/if_an.c,v 1.33 2005/11/22 00:24:14 dillon Exp $ + * $DragonFly: src/sys/dev/netif/an/if_an.c,v 1.34 2005/11/28 17:13:38 dillon Exp $ */ /* @@ -801,7 +801,7 @@ an_attach(sc, dev, flags) /* * Call MI attach routine. */ - ether_ifattach(ifp, sc->an_caps.an_oemaddr); + ether_ifattach(ifp, sc->an_caps.an_oemaddr, NULL); return(0); } @@ -812,14 +812,13 @@ an_detach(device_t dev) struct an_softc *sc = device_get_softc(dev); struct ifnet *ifp = &sc->arpcom.ac_if; - crit_enter(); + lwkt_serialize_enter(ifp->if_serializer); an_stop(sc); ifmedia_removeall(&sc->an_ifmedia); ether_ifdetach(ifp); bus_teardown_intr(dev, sc->irq_res, sc->irq_handle); - crit_exit(); - an_release_resources(dev); + lwkt_serialize_exit(ifp->if_serializer); return 0; } @@ -980,7 +979,7 @@ an_rxeof(sc) rx_frame.an_rx_signal_strength, rx_frame.an_rsvd0); #endif - (*ifp->if_input)(ifp, m); + ifp->if_input(ifp, m); } } else { /* MPI-350 */ @@ -1041,7 +1040,7 @@ an_rxeof(sc) rx_frame.an_rsvd0); #endif #endif - (*ifp->if_input)(ifp, m); + ifp->if_input(ifp, m); an_rx_desc.an_valid = 1; an_rx_desc.an_len = AN_RX_BUFFER_SIZE; @@ -1127,7 +1126,7 @@ an_stats_update(xsc) sc = xsc; ifp = &sc->arpcom.ac_if; - crit_enter(); + lwkt_serialize_enter(sc->arpcom.ac_if.if_serializer); sc->an_status.an_type = AN_RID_STATUS; sc->an_status.an_len = sizeof(struct an_ltv_status); @@ -1147,7 +1146,7 @@ an_stats_update(xsc) callout_reset(&sc->an_stat_timer, hz, an_stats_update, sc); - crit_exit(); + lwkt_serialize_exit(sc->arpcom.ac_if.if_serializer); } void @@ -1868,8 +1867,6 @@ an_ioctl(ifp, command, data, cr) ifr = (struct ifreq *)data; ireq = (struct ieee80211req *)data; - crit_enter(); - config = (struct an_ltv_genconfig *)&sc->areq; key = (struct an_ltv_key *)&sc->areq; status = (struct an_ltv_status *)&sc->areq; @@ -2421,8 +2418,6 @@ an_ioctl(ifp, command, data, cr) break; } - crit_exit(); - return(error != 0); } @@ -2457,7 +2452,6 @@ an_init(xsc) struct an_softc *sc = xsc; struct ifnet *ifp = &sc->arpcom.ac_if; - crit_enter(); if (ifp->if_flags & IFF_RUNNING) an_stop(sc); @@ -2469,7 +2463,6 @@ an_init(xsc) if (sc->mpi350) an_init_mpi350_desc(sc); if (an_init_tx_ring(sc)) { - crit_exit(); if_printf(ifp, "tx buffer allocation failed\n"); return; } @@ -2508,7 +2501,6 @@ an_init(xsc) sc->an_ssidlist.an_type = AN_RID_SSIDLIST; sc->an_ssidlist.an_len = sizeof(struct an_ltv_ssidlist_new); if (an_write_record(sc, (struct an_ltv_gen *)&sc->an_ssidlist)) { - crit_exit(); if_printf(ifp, "failed to set ssid list\n"); return; } @@ -2517,7 +2509,6 @@ an_init(xsc) sc->an_aplist.an_type = AN_RID_APLIST; sc->an_aplist.an_len = sizeof(struct an_ltv_aplist); if (an_write_record(sc, (struct an_ltv_gen *)&sc->an_aplist)) { - crit_exit(); if_printf(ifp, "failed to set AP list\n"); return; } @@ -2526,14 +2517,12 @@ an_init(xsc) sc->an_config.an_len = sizeof(struct an_ltv_genconfig); sc->an_config.an_type = AN_RID_GENCONFIG; if (an_write_record(sc, (struct an_ltv_gen *)&sc->an_config)) { - crit_exit(); if_printf(ifp, "failed to set configuration\n"); return; } /* Enable the MAC */ if (an_cmd(sc, AN_CMD_ENABLE, 0)) { - crit_exit(); if_printf(ifp, "failed to enable MAC\n"); return; } @@ -2548,8 +2537,6 @@ an_init(xsc) ifp->if_flags &= ~IFF_OACTIVE; callout_reset(&sc->an_stat_timer, hz, an_stats_update, sc); - - crit_exit(); } static void @@ -2730,8 +2717,6 @@ an_stop(sc) ifp = &sc->arpcom.ac_if; - crit_enter(); - an_cmd(sc, AN_CMD_FORCE_SYNCLOSS, 0); CSR_WRITE_2(sc, AN_INT_EN(sc->mpi350), 0); an_cmd(sc, AN_CMD_DISABLE, 0); @@ -2747,8 +2732,6 @@ an_stop(sc) free(sc->an_flash_buffer, M_DEVBUF); sc->an_flash_buffer = NULL; } - - crit_exit(); } static void @@ -2759,14 +2742,12 @@ an_watchdog(ifp) sc = ifp->if_softc; - crit_enter(); an_reset(sc); if (sc->mpi350) an_init_mpi350_desc(sc); an_init(sc); ifp->if_oerrors++; - crit_exit(); if_printf(ifp, "device timeout\n"); } diff --git a/sys/dev/netif/an/if_an_isa.c b/sys/dev/netif/an/if_an_isa.c index 4e7d9e251f..2357efd44b 100644 --- a/sys/dev/netif/an/if_an_isa.c +++ b/sys/dev/netif/an/if_an_isa.c @@ -30,7 +30,7 @@ * THE POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD: src/sys/dev/an/if_an_isa.c,v 1.1.2.5 2003/02/01 03:25:12 ambrisko Exp $ - * $DragonFly: src/sys/dev/netif/an/if_an_isa.c,v 1.13 2005/10/12 17:35:51 dillon Exp $ + * $DragonFly: src/sys/dev/netif/an/if_an_isa.c,v 1.14 2005/11/28 17:13:38 dillon Exp $ */ /* @@ -120,8 +120,9 @@ an_attach_isa(dev) if (error) goto fail; - error = bus_setup_intr(dev, sc->irq_res, 0, - an_intr, sc, &sc->irq_handle, NULL); + error = bus_setup_intr(dev, sc->irq_res, INTR_NETSAFE, + an_intr, sc, &sc->irq_handle, + sc->arpcom.ac_if.if_serializer); if (error) { ether_ifdetach(&sc->arpcom.ac_if); ifmedia_removeall(&sc->an_ifmedia); diff --git a/sys/dev/netif/an/if_an_pccard.c b/sys/dev/netif/an/if_an_pccard.c index b72b39c29f..17ae603446 100644 --- a/sys/dev/netif/an/if_an_pccard.c +++ b/sys/dev/netif/an/if_an_pccard.c @@ -30,7 +30,7 @@ * THE POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD: src/sys/dev/an/if_an_pccard.c,v 1.1.2.6 2003/02/01 03:25:12 ambrisko Exp $ - * $DragonFly: src/sys/dev/netif/an/if_an_pccard.c,v 1.13 2005/10/12 17:35:51 dillon Exp $ + * $DragonFly: src/sys/dev/netif/an/if_an_pccard.c,v 1.14 2005/11/28 17:13:38 dillon Exp $ */ /* @@ -161,8 +161,9 @@ an_pccard_attach(device_t dev) /* * Must setup the interrupt after the an_attach to prevent racing. */ - error = bus_setup_intr(dev, sc->irq_res, 0, - an_intr, sc, &sc->irq_handle, NULL); + error = bus_setup_intr(dev, sc->irq_res, INTR_NETSAFE, + an_intr, sc, &sc->irq_handle, + sc->arpcom.ac_if.if_serializer); if (error) { ether_ifdetach(&sc->arpcom.ac_if); ifmedia_removeall(&sc->an_ifmedia); diff --git a/sys/dev/netif/an/if_an_pci.c b/sys/dev/netif/an/if_an_pci.c index da3bff9ee9..4e0676470f 100644 --- a/sys/dev/netif/an/if_an_pci.c +++ b/sys/dev/netif/an/if_an_pci.c @@ -30,7 +30,7 @@ * THE POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD: src/sys/dev/an/if_an_pci.c,v 1.2.2.8 2003/02/11 03:32:48 ambrisko Exp $ - * $DragonFly: src/sys/dev/netif/an/if_an_pci.c,v 1.17 2005/10/12 17:35:51 dillon Exp $ + * $DragonFly: src/sys/dev/netif/an/if_an_pci.c,v 1.18 2005/11/28 17:13:38 dillon Exp $ */ /* @@ -205,8 +205,9 @@ an_attach_pci(dev) if (error) goto fail; - error = bus_setup_intr(dev, sc->irq_res, 0, - an_intr, sc, &sc->irq_handle, NULL); + error = bus_setup_intr(dev, sc->irq_res, INTR_NETSAFE, + an_intr, sc, &sc->irq_handle, + sc->arpcom.ac_if.if_serializer); if (error) { ifmedia_removeall(&sc->an_ifmedia); ether_ifdetach(&sc->arpcom.ac_if); diff --git a/sys/dev/netif/ar/if_ar.c b/sys/dev/netif/ar/if_ar.c index e26c1a7c8b..fd6f852bc2 100644 --- a/sys/dev/netif/ar/if_ar.c +++ b/sys/dev/netif/ar/if_ar.c @@ -26,7 +26,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/dev/ar/if_ar.c,v 1.66 2005/01/06 01:42:28 imp Exp $ - * $DragonFly: src/sys/dev/netif/ar/if_ar.c,v 1.17 2005/10/12 17:35:51 dillon Exp $ + * $DragonFly: src/sys/dev/netif/ar/if_ar.c,v 1.18 2005/11/28 17:13:39 dillon Exp $ */ /* @@ -55,14 +55,16 @@ #include #include #include -#include #include +#include #include #include #include #include #include +#include + #include #ifdef NETGRAPH #include @@ -149,6 +151,7 @@ struct ar_softc { }; static int next_ar_unit = 0; +static struct lwkt_serialize ar_serializer; #ifdef NETGRAPH #define DOG_HOLDOFF 6 /* dog holds off for 6 secs */ @@ -260,6 +263,7 @@ ar_attach(device_t device) int error; hc = (struct ar_hardc *)device_get_softc(device); + lwkt_serialize_init(&ar_serializer); printf("arc%d: %uK RAM, %u ports, rev %u.\n", hc->cunit, @@ -271,7 +275,7 @@ ar_attach(device_t device) error = BUS_SETUP_INTR(device_get_parent(device), device, hc->res_irq, 0, arintr, hc, - &hc->intr_cookie, NULL); + &hc->intr_cookie, &ar_serializer); if (error) return (1); @@ -324,7 +328,7 @@ ar_attach(device_t device) iface); sppp_attach((struct ifnet *)&sc->ifsppp); - if_attach(ifp); + if_attach(ifp, &ar_serializer); bpfattach(ifp, DLT_PPP, PPP_HEADER_LEN); #else /* NETGRAPH */ @@ -358,6 +362,9 @@ ar_detach(device_t device) { device_t parent = device_get_parent(device); struct ar_hardc *hc = device_get_softc(device); + int error; + + lwkt_serialize_enter(&ar_serializer); if (hc->intr_cookie != NULL) { if (BUS_TEARDOWN_INTR(parent, device, @@ -374,7 +381,10 @@ ar_detach(device_t device) FREE(hc->sc, M_DEVBUF); hc->sc = NULL; hc->mem_start = NULL; - return (ar_deallocate_resources(device)); + error = ar_deallocate_resources(device); + lwkt_serialize_exit(&ar_serializer); + + return (error); } int @@ -792,8 +802,6 @@ arioctl(struct ifnet *ifp, u_long cmd, caddr_t data, struct ucred *cr) TRC(if_printf(ifp, "arioctl %s.\n", (cmd == SIOCSIFFLAGS) ? "SIOCSIFFLAGS" : "SIOCSIFADDR");) - crit_enter(); - should_be_up = ifp->if_flags & IFF_RUNNING; if(!was_up && should_be_up) { @@ -808,8 +816,6 @@ arioctl(struct ifnet *ifp, u_long cmd, caddr_t data, struct ucred *cr) ar_down(sc); sppp_flush(ifp); } - - crit_exit(); return (0); } #endif /* NETGRAPH */ @@ -2057,13 +2063,12 @@ ngar_watchdog_frame(void * arg) struct ar_softc * sc = arg; int speed; - crit_enter(); - if (sc->running == 0) { - crit_exit(); return; /* if we are not running let timeouts die */ } + lwkt_serialize_enter(&ar_serializer); + /* * calculate the apparent throughputs * XXX a real hack @@ -2078,39 +2083,29 @@ ngar_watchdog_frame(void * arg) sc->outrate = speed; sc->inlast++; - crit_exit(); - if ((sc->inlast > QUITE_A_WHILE) && (sc->out_deficit > LOTS_OF_PACKETS)) { log(LOG_ERR, "ar%d: No response from remote end\n", sc->unit); - crit_enter(); - ar_down(sc); ar_up(sc); sc->inlast = sc->out_deficit = 0; - - crit_exit(); } else if ( sc->xmit_busy ) { /* no TX -> no TX timeouts */ if (sc->out_dog == 0) { log(LOG_ERR, "ar%d: Transmit failure.. no clock?\n", sc->unit); - crit_enter(); - arwatchdog(sc); #if 0 ar_down(sc); ar_up(sc); #endif - - crit_exit(); - sc->inlast = sc->out_deficit = 0; } else { sc->out_dog--; } } + lwkt_serialize_exit(&ar_serializer); callout_reset(&sc->timer, hz, ngar_watchdog_frame, sc); } @@ -2248,20 +2243,15 @@ ngar_rcvdata(hook_p hook, struct mbuf *m, meta_p meta) else xmitq_p = (&sc->xmitq); - crit_enter(); - if (IF_QFULL(xmitq_p)) { IF_DROP(xmitq_p); - crit_exit(); - error = ENOBUFS; goto bad; } IF_ENQUEUE(xmitq_p, m); arstart(sc); - crit_exit(); return (0); bad: @@ -2331,13 +2321,9 @@ ngar_disconnect(hook_p hook) * If it's the data hook, then free resources etc. */ if (NG_HOOK_PRIVATE(hook)) { - crit_enter(); - sc->datahooks--; if (sc->datahooks == 0) ar_down(sc); - - crit_exit(); } else { sc->debug_hook = NULL; } diff --git a/sys/dev/netif/aue/if_aue.c b/sys/dev/netif/aue/if_aue.c index 5cfca45568..1f6af85f7f 100644 --- a/sys/dev/netif/aue/if_aue.c +++ b/sys/dev/netif/aue/if_aue.c @@ -30,7 +30,7 @@ * THE POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD: src/sys/dev/usb/if_aue.c,v 1.78 2003/12/17 14:23:07 sanpei Exp $ - * $DragonFly: src/sys/dev/netif/aue/if_aue.c,v 1.28 2005/11/22 00:24:15 dillon Exp $ + * $DragonFly: src/sys/dev/netif/aue/if_aue.c,v 1.29 2005/11/28 17:13:41 dillon Exp $ */ /* @@ -725,7 +725,7 @@ USB_ATTACH(aue) /* * Call MI attach routine. */ - ether_ifattach(ifp, eaddr); + ether_ifattach(ifp, eaddr, NULL); usb_register_netisr(); sc->aue_dying = 0; diff --git a/sys/dev/netif/awi/awi.c b/sys/dev/netif/awi/awi.c index 1e76237ea7..10a0cc313b 100644 --- a/sys/dev/netif/awi/awi.c +++ b/sys/dev/netif/awi/awi.c @@ -1,7 +1,3 @@ -/* $NetBSD: awi.c,v 1.26 2000/07/21 04:48:55 onoe Exp $ */ -/* $FreeBSD: src/sys/dev/awi/awi.c,v 1.10.2.2 2003/01/23 21:06:42 sam Exp $ */ -/* $DragonFly: src/sys/dev/netif/awi/Attic/awi.c,v 1.24 2005/11/22 00:24:17 dillon Exp $ */ - /*- * Copyright (c) 1999 The NetBSD Foundation, Inc. * All rights reserved. @@ -36,6 +32,10 @@ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. + * + * $NetBSD: awi.c,v 1.26 2000/07/21 04:48:55 onoe Exp $ + * $FreeBSD: src/sys/dev/awi/awi.c,v 1.10.2.2 2003/01/23 21:06:42 sam Exp $ + * $DragonFly: src/sys/dev/netif/awi/Attic/awi.c,v 1.25 2005/11/28 17:13:41 dillon Exp $ */ /* * Driver for AMD 802.11 firmware. @@ -165,8 +165,6 @@ static int awi_cmd_scan (struct awi_softc *sc); static int awi_cmd (struct awi_softc *sc, u_int8_t cmd); static void awi_cmd_done (struct awi_softc *sc); static int awi_next_txd (struct awi_softc *sc, int len, u_int32_t *framep, u_int32_t*ntxdp); -static int awi_lock (struct awi_softc *sc); -static void awi_unlock (struct awi_softc *sc); static int awi_intr_lock (struct awi_softc *sc); static void awi_intr_unlock (struct awi_softc *sc); static int awi_cmd_wait (struct awi_softc *sc); @@ -210,23 +208,19 @@ awi_attach(sc) struct ifmediareq imr; #endif - crit_enter(); /* * Even if we can sleep in initialization state, * all other processes (e.g. ifconfig) have to wait for * completion of attaching interface. */ - sc->sc_busy = 1; sc->sc_status = AWI_ST_INIT; TAILQ_INIT(&sc->sc_scan); error = awi_init_hw(sc); if (error) { sc->sc_invalid = 1; - crit_exit(); return error; } error = awi_init_mibs(sc); - crit_exit(); if (error) { sc->sc_invalid = 1; return error; @@ -251,7 +245,9 @@ awi_attach(sc) if_printf(ifp, "IEEE802.11 %s %dMbps (firmware %s)\n", sc->sc_mib_phy.IEEE_PHY_Type == AWI_PHY_TYPE_FH ? "FH" : "DS", sc->sc_tx_rate / 10, sc->sc_banner); - ether_ifattach(ifp, sc->sc_mib_addr.aMAC_Address); + ether_ifattach(ifp, sc->sc_mib_addr.aMAC_Address, NULL); + + lwkt_serialize_enter(ifp->if_serializer); #ifdef IFM_IEEE80211 ifmedia_init(&sc->sc_media, 0, awi_media_change, awi_media_status); @@ -271,12 +267,9 @@ awi_attach(sc) awi_media_status(ifp, &imr); ifmedia_set(&sc->sc_media, imr.ifm_active); #endif - - /* ready to accept ioctl */ - awi_unlock(sc); - /* Attach is successful. */ sc->sc_attached = 1; + lwkt_serialize_exit(ifp->if_serializer); return 0; } @@ -294,12 +287,8 @@ awi_ioctl(ifp, cmd, data, cr) struct ieee80211_nwid nwid; u_int8_t *p; - crit_enter(); + error = 0; - /* serialize ioctl */ - error = awi_lock(sc); - if (error) - goto cantlock; switch (cmd) { case SIOCSIFADDR: ifp->if_flags |= IFF_UP; @@ -395,9 +384,6 @@ awi_ioctl(ifp, cmd, data, cr) error = awi_wicfg(ifp, cmd, data); break; } - awi_unlock(sc); - cantlock: - crit_exit(); return error; } @@ -545,7 +531,7 @@ awi_intr(arg) { struct awi_softc *sc = arg; u_int16_t status; - int error, handled = 0, ocansleep; + int error, handled = 0; if (!sc->sc_enabled || !sc->sc_enab_intr || sc->sc_invalid) return 0; @@ -553,8 +539,6 @@ awi_intr(arg) am79c930_gcr_setbits(&sc->sc_chip, AM79C930_GCR_DISPWDN | AM79C930_GCR_ECINT); awi_write_1(sc, AWI_DIS_PWRDN, 1); - ocansleep = sc->sc_cansleep; - sc->sc_cansleep = 0; for (;;) { error = awi_intr_lock(sc); @@ -584,7 +568,6 @@ awi_intr(arg) (void)awi_next_scan(sc); } } - sc->sc_cansleep = ocansleep; am79c930_gcr_clearbits(&sc->sc_chip, AM79C930_GCR_DISPWDN); awi_write_1(sc, AWI_DIS_PWRDN, 0); return handled; @@ -692,15 +675,12 @@ awi_watchdog(ifp) struct ifnet *ifp; { struct awi_softc *sc = ifp->if_softc; - int ocansleep; if (sc->sc_invalid) { ifp->if_timer = 0; return; } - ocansleep = sc->sc_cansleep; - sc->sc_cansleep = 0; if (sc->sc_tx_timer && --sc->sc_tx_timer == 0) { if_printf(ifp, "transmit timeout\n"); awi_txint(sc); @@ -733,7 +713,6 @@ awi_watchdog(ifp) ifp->if_timer = 0; else ifp->if_timer = 1; - sc->sc_cansleep = ocansleep; } static void @@ -1039,7 +1018,7 @@ awi_input(sc, m, rxts, rssi) break; } ifp->if_ipackets++; - (*ifp->if_input)(ifp, m); + ifp->if_input(ifp, m); break; case IEEE80211_FC0_TYPE_MGT: if ((wh->i_fc[1] & IEEE80211_FC1_DIR_MASK) != @@ -1225,13 +1204,9 @@ awi_init_hw(sc) status = awi_read_1(sc, AWI_SELFTEST); if ((status & 0xf0) == 0xf0) break; - if (sc->sc_cansleep) { - sc->sc_sleep_cnt++; - (void)tsleep(sc, 0, "awitst", 1); - sc->sc_sleep_cnt--; - } else { - DELAY(1000*1000/hz); - } + sc->sc_sleep_cnt++; + (void)tsleep(sc, 0, "awitst", 1); + sc->sc_sleep_cnt--; } if (status != AWI_SELFTEST_PASSED) { if_printf(ifp, "failed to complete selftest (code %x)\n", @@ -1271,8 +1246,6 @@ awi_init_hw(sc) printf(" (no hardware)\n"); else if (error != EWOULDBLOCK) printf(" (error %d)\n", error); - else if (sc->sc_cansleep) - printf(" (lost interrupt)\n"); else printf(" (command timeout)\n"); } @@ -2315,53 +2288,6 @@ awi_next_txd(sc, len, framep, ntxdp) return 0; } -static int -awi_lock(sc) - struct awi_softc *sc; -{ - int error = 0; - - if (curproc == NULL) { - /* - * XXX - * Though driver ioctl should be called with context, - * KAME ipv6 stack calls ioctl in interrupt for now. - * We simply abort the request if there are other - * ioctl requests in progress. - */ - if (sc->sc_busy) { - return EWOULDBLOCK; - if (sc->sc_invalid) - return ENXIO; - } - sc->sc_busy = 1; - sc->sc_cansleep = 0; - return 0; - } - while (sc->sc_busy) { - if (sc->sc_invalid) - return ENXIO; - sc->sc_sleep_cnt++; - error = tsleep(sc, PCATCH, "awilck", 0); - sc->sc_sleep_cnt--; - if (error) - return error; - } - sc->sc_busy = 1; - sc->sc_cansleep = 1; - return 0; -} - -static void -awi_unlock(sc) - struct awi_softc *sc; -{ - sc->sc_busy = 0; - sc->sc_cansleep = 0; - if (sc->sc_sleep_cnt) - wakeup(sc); -} - static int awi_intr_lock(sc) struct awi_softc *sc; @@ -2415,21 +2341,9 @@ awi_cmd_wait(sc) sc->sc_invalid = 1; return ENXIO; } - if (sc->sc_cansleep) { - sc->sc_sleep_cnt++; - error = tsleep(sc, 0, "awicmd", - AWI_CMD_TIMEOUT*hz/1000); - sc->sc_sleep_cnt--; - } else { - if (awi_read_1(sc, AWI_CMD_STATUS) != AWI_STAT_IDLE) { - awi_cmd_done(sc); - break; - } - if (i++ >= AWI_CMD_TIMEOUT*1000/10) - error = EWOULDBLOCK; - else - DELAY(10); - } + sc->sc_sleep_cnt++; + error = tsleep(sc, 0, "awicmd", AWI_CMD_TIMEOUT*hz/1000); + sc->sc_sleep_cnt--; if (error) break; } diff --git a/sys/dev/netif/awi/awivar.h b/sys/dev/netif/awi/awivar.h index 68aeeaefb2..55e80047e4 100644 --- a/sys/dev/netif/awi/awivar.h +++ b/sys/dev/netif/awi/awivar.h @@ -1,6 +1,6 @@ /* $NetBSD: awivar.h,v 1.12 2000/07/21 04:48:56 onoe Exp $ */ /* $FreeBSD: src/sys/dev/awi/awivar.h,v 1.6.2.1 2000/12/07 04:09:39 imp Exp $ */ -/* $DragonFly: src/sys/dev/netif/awi/Attic/awivar.h,v 1.6 2005/06/13 20:25:56 joerg Exp $ */ +/* $DragonFly: src/sys/dev/netif/awi/Attic/awivar.h,v 1.7 2005/11/28 17:13:41 dillon Exp $ */ /*- * Copyright (c) 1999 The NetBSD Foundation, Inc. @@ -99,8 +99,6 @@ struct awi_softc struct ifmedia sc_media; enum awi_status sc_status; unsigned int sc_enabled:1, - sc_busy:1, - sc_cansleep:1, sc_invalid:1, sc_enab_intr:1, sc_format_llc:1, diff --git a/sys/dev/netif/awi/if_awi_pccard.c b/sys/dev/netif/awi/if_awi_pccard.c index d17281f665..bd60232bc8 100644 --- a/sys/dev/netif/awi/if_awi_pccard.c +++ b/sys/dev/netif/awi/if_awi_pccard.c @@ -23,7 +23,7 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD: src/sys/dev/awi/if_awi_pccard.c,v 1.5.2.1 2000/12/07 04:09:39 imp Exp $ - * $DragonFly: src/sys/dev/netif/awi/Attic/if_awi_pccard.c,v 1.13 2005/10/12 17:35:51 dillon Exp $ + * $DragonFly: src/sys/dev/netif/awi/Attic/if_awi_pccard.c,v 1.14 2005/11/28 17:13:41 dillon Exp $ */ #include @@ -187,23 +187,25 @@ awi_pccard_attach(device_t dev) } else am79c930_chip_init(&sc->sc_chip, 0); - error = bus_setup_intr(dev, psc->sc_irq_res, 0, - (void (*)(void *))awi_intr, sc, - &psc->sc_intrhand, NULL); - if (error) { - device_printf(dev, "awi_pccard_attach: intr setup failed\n"); - goto fail; - } - - sc->sc_cansleep = 1; sc->sc_enabled = 1; sc->sc_ifp = &sc->sc_ec.ac_if; error = awi_attach(sc); sc->sc_enabled = 0; /*XXX*/ - if (error == 0) - return 0; - device_printf(dev, "awi_pccard_attach: awi_attach failed\n"); + + if (error) { + device_printf(dev, "awi_pccard_attach: awi_attach failed\n"); + goto fail; + } + + error = bus_setup_intr(dev, psc->sc_irq_res, INTR_NETSAFE, + (void (*)(void *))awi_intr, sc, + &psc->sc_intrhand, sc->sc_ifp->if_serializer); + if (error) { + device_printf(dev, "awi_pccard_attach: intr setup failed\n"); + goto fail; + } + return 0; fail: if (psc->sc_intrhand) { diff --git a/sys/dev/netif/axe/if_axe.c b/sys/dev/netif/axe/if_axe.c index de154d4aab..8faa08f981 100644 --- a/sys/dev/netif/axe/if_axe.c +++ b/sys/dev/netif/axe/if_axe.c @@ -30,7 +30,7 @@ * THE POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD: src/sys/dev/usb/if_axe.c,v 1.10 2003/12/08 07:54:14 obrien Exp $ - * $DragonFly: src/sys/dev/netif/axe/if_axe.c,v 1.18 2005/11/22 00:24:18 dillon Exp $ + * $DragonFly: src/sys/dev/netif/axe/if_axe.c,v 1.19 2005/11/28 17:13:41 dillon Exp $ */ /* * ASIX Electronics AX88172 USB 2.0 ethernet driver. Used in the @@ -209,10 +209,7 @@ axe_miibus_readreg(device_ptr_t dev, int phy, int reg) usbd_status err; u_int16_t val; - crit_enter(); - if (sc->axe_dying) { - crit_exit(); return(0); } @@ -223,17 +220,14 @@ axe_miibus_readreg(device_ptr_t dev, int phy, int reg) */ if (sc->axe_phyaddrs[0] != AXE_NOPHY && phy != sc->axe_phyaddrs[0]) { - crit_exit(); return (0); } if (sc->axe_phyaddrs[1] != AXE_NOPHY && phy != sc->axe_phyaddrs[1]) { - crit_exit(); return (0); } #endif if (sc->axe_phyaddrs[0] != 0xFF && sc->axe_phyaddrs[0] != phy) { - crit_exit(); return (0); } @@ -241,8 +235,6 @@ axe_miibus_readreg(device_ptr_t dev, int phy, int reg) err = axe_cmd(sc, AXE_CMD_MII_READ_REG, reg, phy, (void *)&val); axe_cmd(sc, AXE_CMD_MII_OPMODE_HW, 0, 0, NULL); - crit_exit(); - if (err) { if_printf(&sc->arpcom.ac_if, "read PHY failed\n"); return(-1); @@ -260,10 +252,7 @@ axe_miibus_writereg(device_ptr_t dev, int phy, int reg, int val) struct axe_softc *sc = USBGETSOFTC(dev); usbd_status err; - crit_enter(); - if (sc->axe_dying) { - crit_exit(); return(0); } @@ -271,8 +260,6 @@ axe_miibus_writereg(device_ptr_t dev, int phy, int reg, int val) err = axe_cmd(sc, AXE_CMD_MII_WRITE_REG, reg, phy, (void *)&val); axe_cmd(sc, AXE_CMD_MII_OPMODE_HW, 0, 0, NULL); - crit_exit(); - if (err) { if_printf(&sc->arpcom.ac_if, "write PHY failed\n"); return(-1); @@ -338,14 +325,11 @@ axe_setmulti(struct axe_softc *sc) u_int16_t rxmode; u_int8_t hashtbl[8] = { 0, 0, 0, 0, 0, 0, 0, 0 }; - crit_enter(); - axe_cmd(sc, AXE_CMD_RXCTL_READ, 0, 0, (void *)&rxmode); if (ifp->if_flags & IFF_ALLMULTI || ifp->if_flags & IFF_PROMISC) { rxmode |= AXE_RXCMD_ALLMULTI; axe_cmd(sc, AXE_CMD_RXCTL_WRITE, 0, rxmode, NULL); - crit_exit(); return; } else rxmode &= ~AXE_RXCMD_ALLMULTI; @@ -363,8 +347,6 @@ axe_setmulti(struct axe_softc *sc) axe_cmd(sc, AXE_CMD_WRITE_MCAST, 0, 0, (void *)&hashtbl); axe_cmd(sc, AXE_CMD_RXCTL_WRITE, 0, rxmode, NULL); - - crit_exit(); } Static void @@ -502,7 +484,7 @@ USB_ATTACH(axe) * Call MI attach routine. */ - ether_ifattach(ifp, eaddr); + ether_ifattach(ifp, eaddr, NULL); sc->axe_dying = 0; @@ -517,8 +499,6 @@ axe_detach(device_ptr_t dev) struct axe_softc *sc = device_get_softc(dev); struct ifnet *ifp = &sc->arpcom.ac_if; - crit_enter(); - sc->axe_dying = 1; callout_stop(&sc->axe_stat_timer); ether_ifdetach(ifp); @@ -530,8 +510,6 @@ axe_detach(device_ptr_t dev) if (sc->axe_ep[AXE_ENDPT_INTR] != NULL) usbd_abort_pipe(sc->axe_ep[AXE_ENDPT_INTR]); - crit_exit(); - return(0); } @@ -619,12 +597,10 @@ axe_rxstart(struct ifnet *ifp) struct axe_softc *sc = ifp->if_softc; struct axe_chain *c; - crit_enter(); c = &sc->axe_cdata.axe_rx_chain[sc->axe_cdata.axe_rx_prod]; if (axe_newbuf(sc, c, NULL) == ENOBUFS) { ifp->if_ierrors++; - crit_exit(); return; } @@ -633,8 +609,6 @@ axe_rxstart(struct ifnet *ifp) c, mtod(c->axe_mbuf, char *), AXE_BUFSZ, USBD_SHORT_XFER_OK, USBD_NO_TIMEOUT, axe_rxeof); usbd_transfer(c->axe_xfer); - - crit_exit(); } /* @@ -650,16 +624,16 @@ axe_rxeof(usbd_xfer_handle xfer, usbd_private_handle priv, usbd_status status) struct mbuf *m; int total_len = 0; - crit_enter(); + lwkt_serialize_enter(ifp->if_serializer); if (!(ifp->if_flags & IFF_RUNNING)) { - crit_exit(); + lwkt_serialize_exit(ifp->if_serializer); return; } if (status != USBD_NORMAL_COMPLETION) { if (status == USBD_NOT_STARTED || status == USBD_CANCELLED) { - crit_exit(); + lwkt_serialize_exit(ifp->if_serializer); return; } if (usbd_ratecheck(&sc->axe_rx_notice)) { @@ -687,8 +661,7 @@ axe_rxeof(usbd_xfer_handle xfer, usbd_private_handle priv, usbd_status status) /* Put the packet on the special USB input queue. */ usb_ether_input(m); axe_rxstart(ifp); - - crit_exit(); + lwkt_serialize_exit(ifp->if_serializer); return; done: /* Setup new transfer. */ @@ -696,8 +669,7 @@ done: c, mtod(c->axe_mbuf, char *), AXE_BUFSZ, USBD_SHORT_XFER_OK, USBD_NO_TIMEOUT, axe_rxeof); usbd_transfer(c->axe_xfer); - - crit_exit(); + lwkt_serialize_exit(ifp->if_serializer); } /* @@ -713,17 +685,16 @@ axe_txeof(usbd_xfer_handle xfer, usbd_private_handle priv, usbd_status status) struct ifnet *ifp = &sc->arpcom.ac_if; usbd_status err; - crit_enter(); - + lwkt_serialize_enter(ifp->if_serializer); if (status != USBD_NORMAL_COMPLETION) { if (status == USBD_NOT_STARTED || status == USBD_CANCELLED) { - crit_exit(); + lwkt_serialize_exit(ifp->if_serializer); return; } if_printf(ifp, "usb error on tx: %s\n", usbd_errstr(status)); if (status == USBD_STALLED) usbd_clear_endpoint_stall(sc->axe_ep[AXE_ENDPT_TX]); - crit_exit(); + lwkt_serialize_exit(ifp->if_serializer); return; } @@ -743,8 +714,7 @@ axe_txeof(usbd_xfer_handle xfer, usbd_private_handle priv, usbd_status status) if (!ifq_is_empty(&ifp->if_snd)) (*ifp->if_start)(ifp); - - crit_exit(); + lwkt_serialize_exit(ifp->if_serializer); } Static void @@ -758,8 +728,7 @@ axe_tick(void *xsc) if (mii == NULL) return; - crit_enter(); - + lwkt_serialize_enter(ifp->if_serializer); mii_tick(mii); if (!sc->axe_link && mii->mii_media_status & IFM_ACTIVE && IFM_SUBTYPE(mii->mii_media_active) != IFM_NONE) { @@ -767,10 +736,8 @@ axe_tick(void *xsc) if (!ifq_is_empty(&ifp->if_snd)) axe_start(ifp); } - callout_reset(&sc->axe_stat_timer, hz, axe_tick, sc); - - crit_exit(); + lwkt_serialize_exit(ifp->if_serializer); } Static int @@ -810,27 +777,21 @@ axe_start(struct ifnet *ifp) struct axe_softc *sc = ifp->if_softc; struct mbuf *m_head = NULL; - crit_enter(); - if (!sc->axe_link) { - crit_exit(); return; } if (ifp->if_flags & IFF_OACTIVE) { - crit_exit(); return; } m_head = ifq_poll(&ifp->if_snd); if (m_head == NULL) { - crit_exit(); return; } if (axe_encap(sc, m_head, 0)) { ifp->if_flags |= IFF_OACTIVE; - crit_exit(); return; } ifq_dequeue(&ifp->if_snd, m_head); @@ -847,8 +808,6 @@ axe_start(struct ifnet *ifp) * Set a timeout in case the chip goes out to lunch. */ ifp->if_timer = 5; - - crit_exit(); } Static void @@ -860,10 +819,7 @@ axe_init(void *xsc) usbd_status err; int i, rxmode; - crit_enter(); - if (ifp->if_flags & IFF_RUNNING) { - crit_exit(); return; } @@ -882,14 +838,12 @@ axe_init(void *xsc) /* Init TX ring. */ if (axe_tx_list_init(sc) == ENOBUFS) { - crit_exit(); if_printf(ifp, "tx list init failed\n"); return; } /* Init RX ring. */ if (axe_rx_list_init(sc) == ENOBUFS) { - crit_exit(); if_printf(ifp, "rx list init failed\n"); return; } @@ -918,7 +872,6 @@ axe_init(void *xsc) err = usbd_open_pipe(sc->axe_iface, sc->axe_ed[AXE_ENDPT_RX], USBD_EXCLUSIVE_USE, &sc->axe_ep[AXE_ENDPT_RX]); if (err) { - crit_exit(); if_printf(ifp, "open rx pipe failed: %s\n", usbd_errstr(err)); return; } @@ -926,7 +879,6 @@ axe_init(void *xsc) err = usbd_open_pipe(sc->axe_iface, sc->axe_ed[AXE_ENDPT_TX], USBD_EXCLUSIVE_USE, &sc->axe_ep[AXE_ENDPT_TX]); if (err) { - crit_exit(); if_printf(ifp, "open tx pipe failed: %s\n", usbd_errstr(err)); return; } @@ -944,8 +896,6 @@ axe_init(void *xsc) ifp->if_flags &= ~IFF_OACTIVE; callout_reset(&sc->axe_stat_timer, hz, axe_tick, sc); - - crit_exit(); } Static int @@ -957,8 +907,6 @@ axe_ioctl(struct ifnet *ifp, u_long command, caddr_t data, struct ucred *cr) u_int16_t rxmode; int error = 0; - crit_enter(); - switch(command) { case SIOCSIFFLAGS: if (ifp->if_flags & IFF_UP) { @@ -1004,9 +952,6 @@ axe_ioctl(struct ifnet *ifp, u_long command, caddr_t data, struct ucred *cr) error = ether_ioctl(ifp, command, data); break; } - - crit_exit(); - return(error); } @@ -1017,8 +962,6 @@ axe_watchdog(struct ifnet *ifp) struct axe_chain *c; usbd_status stat; - crit_enter(); - ifp->if_oerrors++; if_printf(ifp, "watchdog timeout\n"); @@ -1028,8 +971,6 @@ axe_watchdog(struct ifnet *ifp) if (!ifq_is_empty(&ifp->if_snd)) axe_start(ifp); - - crit_exit(); } /* @@ -1043,8 +984,6 @@ axe_stop(struct axe_softc *sc) struct ifnet *ifp; int i; - crit_enter(); - ifp = &sc->arpcom.ac_if; ifp->if_timer = 0; @@ -1129,8 +1068,6 @@ axe_stop(struct axe_softc *sc) ifp->if_flags &= ~(IFF_RUNNING | IFF_OACTIVE); sc->axe_link = 0; - - crit_exit(); } /* diff --git a/sys/dev/netif/bfe/if_bfe.c b/sys/dev/netif/bfe/if_bfe.c index ae4e826e68..a319ab75b1 100644 --- a/sys/dev/netif/bfe/if_bfe.c +++ b/sys/dev/netif/bfe/if_bfe.c @@ -29,7 +29,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/dev/bfe/if_bfe.c 1.4.4.7 2004/03/02 08:41:33 julian Exp v - * $DragonFly: src/sys/dev/netif/bfe/if_bfe.c,v 1.26 2005/11/22 00:24:19 dillon Exp $ + * $DragonFly: src/sys/dev/netif/bfe/if_bfe.c,v 1.27 2005/11/28 17:13:41 dillon Exp $ */ #include @@ -414,13 +414,14 @@ bfe_attach(device_t dev) goto fail; } - ether_ifattach(ifp, sc->arpcom.ac_enaddr); + ether_ifattach(ifp, sc->arpcom.ac_enaddr, NULL); /* * Hook interrupt last to avoid having to lock softc */ - error = bus_setup_intr(dev, sc->bfe_irq, 0, - bfe_intr, sc, &sc->bfe_intrhand, NULL); + error = bus_setup_intr(dev, sc->bfe_irq, INTR_NETSAFE, + bfe_intr, sc, &sc->bfe_intrhand, + sc->arpcom.ac_if.if_serializer); if (error) { ether_ifdetach(ifp); @@ -439,7 +440,7 @@ bfe_detach(device_t dev) struct bfe_softc *sc = device_get_softc(dev); struct ifnet *ifp = &sc->arpcom.ac_if; - crit_enter(); + lwkt_serialize_enter(ifp->if_serializer); if (device_is_attached(dev)) { bfe_stop(sc); @@ -453,8 +454,6 @@ bfe_detach(device_t dev) if (sc->bfe_intrhand != NULL) bus_teardown_intr(dev, sc->bfe_irq, sc->bfe_intrhand); - crit_exit(); - if (sc->bfe_irq != NULL) bus_release_resource(dev, SYS_RES_IRQ, 0, sc->bfe_irq); @@ -462,8 +461,8 @@ bfe_detach(device_t dev) bus_release_resource(dev, SYS_RES_MEMORY, BFE_PCI_MEMLO, sc->bfe_res); } - bfe_dma_free(sc); + lwkt_serialize_exit(ifp->if_serializer); return(0); } @@ -475,12 +474,11 @@ static void bfe_shutdown(device_t dev) { struct bfe_softc *sc = device_get_softc(dev); + struct ifnet *ifp = &sc->arpcom.ac_if; - crit_enter(); - + lwkt_serialize_enter(ifp->if_serializer); bfe_stop(sc); - - crit_exit(); + lwkt_serialize_exit(ifp->if_serializer); } static int @@ -655,15 +653,11 @@ bfe_clear_stats(struct bfe_softc *sc) { u_long reg; - crit_enter(); - CSR_WRITE_4(sc, BFE_MIB_CTRL, BFE_MIB_CLR_ON_READ); for (reg = BFE_TX_GOOD_O; reg <= BFE_TX_PAUSE; reg += 4) CSR_READ_4(sc, reg); for (reg = BFE_RX_GOOD_O; reg <= BFE_RX_NPAUSE; reg += 4) CSR_READ_4(sc, reg); - - crit_exit(); } static int @@ -671,27 +665,20 @@ bfe_resetphy(struct bfe_softc *sc) { uint32_t val; - crit_enter(); - bfe_writephy(sc, 0, BMCR_RESET); DELAY(100); bfe_readphy(sc, 0, &val); if (val & BMCR_RESET) { - crit_exit(); if_printf(&sc->arpcom.ac_if, "PHY Reset would not complete.\n"); return(ENXIO); } - - crit_exit(); return(0); } static void bfe_chip_halt(struct bfe_softc *sc) { - crit_enter(); - /* disable interrupts - not that it actually does..*/ CSR_WRITE_4(sc, BFE_IMASK, 0); CSR_READ_4(sc, BFE_IMASK); @@ -702,8 +689,6 @@ bfe_chip_halt(struct bfe_softc *sc) CSR_WRITE_4(sc, BFE_DMARX_CTRL, 0); CSR_WRITE_4(sc, BFE_DMATX_CTRL, 0); DELAY(10); - - crit_exit(); } static void @@ -711,8 +696,6 @@ bfe_chip_reset(struct bfe_softc *sc) { uint32_t val; - crit_enter(); - /* Set the interrupt vector for the enet core */ bfe_pci_setup(sc, BFE_INTVEC_ENET0); @@ -787,8 +770,6 @@ bfe_chip_reset(struct bfe_softc *sc) bfe_resetphy(sc); bfe_setupphy(sc); - - crit_exit(); } static void @@ -1009,8 +990,6 @@ bfe_readphy(struct bfe_softc *sc, uint32_t reg, uint32_t *val) { int err; - crit_enter(); - /* Clear MII ISR */ CSR_WRITE_4(sc, BFE_EMAC_ISTAT, BFE_EMAC_INT_MII); CSR_WRITE_4(sc, BFE_MDIO_DATA, (BFE_MDIO_SB_START | @@ -1020,8 +999,6 @@ bfe_readphy(struct bfe_softc *sc, uint32_t reg, uint32_t *val) (BFE_MDIO_TA_VALID << BFE_MDIO_TA_SHIFT))); err = bfe_wait_bit(sc, BFE_EMAC_ISTAT, BFE_EMAC_INT_MII, 100, 0); *val = CSR_READ_4(sc, BFE_MDIO_DATA) & BFE_MDIO_DATA_DATA; - - crit_exit(); return(err); } @@ -1030,8 +1007,6 @@ bfe_writephy(struct bfe_softc *sc, uint32_t reg, uint32_t val) { int status; - crit_enter(); - CSR_WRITE_4(sc, BFE_EMAC_ISTAT, BFE_EMAC_INT_MII); CSR_WRITE_4(sc, BFE_MDIO_DATA, (BFE_MDIO_SB_START | (BFE_MDIO_OP_WRITE << BFE_MDIO_OP_SHIFT) | @@ -1041,8 +1016,6 @@ bfe_writephy(struct bfe_softc *sc, uint32_t reg, uint32_t val) (val & BFE_MDIO_DATA_DATA))); status = bfe_wait_bit(sc, BFE_EMAC_ISTAT, BFE_EMAC_INT_MII, 100, 0); - crit_exit(); - return status; } @@ -1055,8 +1028,6 @@ bfe_setupphy(struct bfe_softc *sc) { uint32_t val; - crit_enter(); - /* Enable activity LED */ bfe_readphy(sc, 26, &val); bfe_writephy(sc, 26, val & 0x7fff); @@ -1066,7 +1037,6 @@ bfe_setupphy(struct bfe_softc *sc) bfe_readphy(sc, 27, &val); bfe_writephy(sc, 27, val | (1 << 6)); - crit_exit(); return(0); } @@ -1090,8 +1060,6 @@ bfe_txeof(struct bfe_softc *sc) struct ifnet *ifp = &sc->arpcom.ac_if; uint32_t i, chipidx; - crit_enter(); - chipidx = CSR_READ_4(sc, BFE_DMATX_STAT) & BFE_STAT_CDMASK; chipidx /= sizeof(struct bfe_desc); @@ -1118,8 +1086,6 @@ bfe_txeof(struct bfe_softc *sc) ifp->if_timer = 0; else ifp->if_timer = 5; - - crit_exit(); } /* Pass a received packet up the stack */ @@ -1132,8 +1098,6 @@ bfe_rxeof(struct bfe_softc *sc) struct bfe_data *r; uint32_t cons, status, current, len, flags; - crit_enter(); - cons = sc->bfe_rx_cons; status = CSR_READ_4(sc, BFE_DMARX_STAT); current = (status & BFE_STAT_CDMASK) / sizeof(struct bfe_desc); @@ -1175,12 +1139,10 @@ bfe_rxeof(struct bfe_softc *sc) ifp->if_ipackets++; m->m_pkthdr.rcvif = ifp; - (*ifp->if_input)(ifp, m); + ifp->if_input(ifp, m); BFE_INC(cons, BFE_RX_LIST_CNT); } sc->bfe_rx_cons = cons; - - crit_exit(); } static void @@ -1190,8 +1152,6 @@ bfe_intr(void *xsc) struct ifnet *ifp = &sc->arpcom.ac_if; uint32_t istat, imask, flag; - crit_enter(); - istat = CSR_READ_4(sc, BFE_ISTAT); imask = CSR_READ_4(sc, BFE_IMASK); @@ -1206,7 +1166,6 @@ bfe_intr(void *xsc) /* not expecting this interrupt, disregard it */ if (istat == 0) { - crit_exit(); return; } @@ -1234,8 +1193,6 @@ bfe_intr(void *xsc) /* We have packets pending, fire them out */ if ((ifp->if_flags & IFF_RUNNING) && !ifq_is_empty(&ifp->if_snd)) bfe_start(ifp); - - crit_exit(); } static int @@ -1311,21 +1268,15 @@ bfe_start(struct ifnet *ifp) struct mbuf *m_head = NULL; int idx, need_trans; - crit_enter(); - /* * Not much point trying to send if the link is down * or we have nothing to send. */ - if (!sc->bfe_link) { - crit_exit(); + if (!sc->bfe_link) return; - } - if (ifp->if_flags & IFF_OACTIVE) { - crit_exit(); + if (ifp->if_flags & IFF_OACTIVE) return; - } idx = sc->bfe_tx_prod; @@ -1353,10 +1304,8 @@ bfe_start(struct ifnet *ifp) BPF_MTAP(ifp, m_head); } - if (!need_trans) { - crit_exit(); + if (!need_trans) return; - } sc->bfe_tx_prod = idx; /* Transmit - twice due to apparent hardware bug */ @@ -1367,8 +1316,6 @@ bfe_start(struct ifnet *ifp) * Set a timeout in case the chip goes out to lunch. */ ifp->if_timer = 5; - - crit_exit(); } static void @@ -1377,12 +1324,8 @@ bfe_init(void *xsc) struct bfe_softc *sc = (struct bfe_softc*)xsc; struct ifnet *ifp = &sc->arpcom.ac_if; - crit_enter(); - - if (ifp->if_flags & IFF_RUNNING) { - crit_exit(); + if (ifp->if_flags & IFF_RUNNING) return; - } bfe_stop(sc); bfe_chip_reset(sc); @@ -1391,7 +1334,6 @@ bfe_init(void *xsc) if_printf(ifp, "bfe_init failed. " " Not enough memory for list buffers\n"); bfe_stop(sc); - crit_exit(); return; } @@ -1407,7 +1349,6 @@ bfe_init(void *xsc) ifp->if_flags &= ~IFF_OACTIVE; callout_reset(&sc->bfe_stat_timer, hz, bfe_tick, sc); - crit_exit(); } /* @@ -1419,8 +1360,6 @@ bfe_ifmedia_upd(struct ifnet *ifp) struct bfe_softc *sc = ifp->if_softc; struct mii_data *mii; - crit_enter(); - mii = device_get_softc(sc->bfe_miibus); sc->bfe_link = 0; if (mii->mii_instance) { @@ -1431,7 +1370,6 @@ bfe_ifmedia_upd(struct ifnet *ifp) } mii_mediachg(mii); - crit_exit(); return(0); } @@ -1444,14 +1382,10 @@ bfe_ifmedia_sts(struct ifnet *ifp, struct ifmediareq *ifmr) struct bfe_softc *sc = ifp->if_softc; struct mii_data *mii; - crit_enter(); - mii = device_get_softc(sc->bfe_miibus); mii_pollstat(mii); ifmr->ifm_active = mii->mii_media_active; ifmr->ifm_status = mii->mii_media_status; - - crit_exit(); } static int @@ -1462,8 +1396,6 @@ bfe_ioctl(struct ifnet *ifp, u_long command, caddr_t data, struct ucred *cr) struct mii_data *mii; int error = 0; - crit_enter(); - switch (command) { case SIOCSIFFLAGS: if (ifp->if_flags & IFF_UP) @@ -1489,9 +1421,6 @@ bfe_ioctl(struct ifnet *ifp, u_long command, caddr_t data, struct ucred *cr) error = ether_ioctl(ifp, command, data); break; } - - crit_exit(); - return error; } @@ -1502,14 +1431,10 @@ bfe_watchdog(struct ifnet *ifp) if_printf(ifp, "watchdog timeout -- resetting\n"); - crit_enter(); - ifp->if_flags &= ~IFF_RUNNING; bfe_init(sc); ifp->if_oerrors++; - - crit_exit(); } static void @@ -1517,28 +1442,25 @@ bfe_tick(void *xsc) { struct bfe_softc *sc = xsc; struct mii_data *mii; - - crit_enter(); + struct ifnet *ifp = &sc->arpcom.ac_if; mii = device_get_softc(sc->bfe_miibus); + lwkt_serialize_enter(ifp->if_serializer); + bfe_stats_update(sc); callout_reset(&sc->bfe_stat_timer, hz, bfe_tick, sc); - if (sc->bfe_link) { - crit_exit(); - return; + if (sc->bfe_link == NULL) { + mii_tick(mii); + if (!sc->bfe_link && mii->mii_media_status & IFM_ACTIVE && + IFM_SUBTYPE(mii->mii_media_active) != IFM_NONE) { + sc->bfe_link++; + } + if (!sc->bfe_link) + sc->bfe_link++; } - - mii_tick(mii); - if (!sc->bfe_link && mii->mii_media_status & IFM_ACTIVE && - IFM_SUBTYPE(mii->mii_media_active) != IFM_NONE) - sc->bfe_link++; - - if (!sc->bfe_link) - sc->bfe_link++; - - crit_exit(); + lwkt_serialize_exit(ifp->if_serializer); } /* @@ -1550,8 +1472,6 @@ bfe_stop(struct bfe_softc *sc) { struct ifnet *ifp = &sc->arpcom.ac_if; - crit_enter(); - callout_stop(&sc->bfe_stat_timer); bfe_chip_halt(sc); @@ -1559,6 +1479,5 @@ bfe_stop(struct bfe_softc *sc) bfe_rx_ring_free(sc); ifp->if_flags &= ~(IFF_RUNNING | IFF_OACTIVE); - - crit_exit(); } + diff --git a/sys/dev/netif/bge/if_bge.c b/sys/dev/netif/bge/if_bge.c index c327c04ffd..fcc29daa40 100644 --- a/sys/dev/netif/bge/if_bge.c +++ b/sys/dev/netif/bge/if_bge.c @@ -31,7 +31,7 @@ * THE POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD: src/sys/dev/bge/if_bge.c,v 1.3.2.29 2003/12/01 21:06:59 ambrisko Exp $ - * $DragonFly: src/sys/dev/netif/bge/if_bge.c,v 1.49 2005/11/22 00:24:20 dillon Exp $ + * $DragonFly: src/sys/dev/netif/bge/if_bge.c,v 1.50 2005/11/28 17:13:41 dillon Exp $ * */ @@ -200,6 +200,7 @@ static void bge_txeof(struct bge_softc *); static void bge_rxeof(struct bge_softc *); static void bge_tick(void *); +static void bge_tick_serialized(void *); static void bge_stats_update(struct bge_softc *); static void bge_stats_update_regs(struct bge_softc *); static int bge_encap(struct bge_softc *, struct mbuf *, uint32_t *); @@ -1718,10 +1719,11 @@ bge_attach(device_t dev) /* * Call MI attach routine. */ - ether_ifattach(ifp, ether_addr); + ether_ifattach(ifp, ether_addr, NULL); - error = bus_setup_intr(dev, sc->bge_irq, 0, - bge_intr, sc, &sc->bge_intrhand, NULL); + error = bus_setup_intr(dev, sc->bge_irq, INTR_NETSAFE, + bge_intr, sc, &sc->bge_intrhand, + ifp->if_serializer); if (error) { ether_ifdetach(ifp); device_printf(dev, "couldn't set up irq\n"); @@ -1742,7 +1744,7 @@ bge_detach(device_t dev) struct bge_softc *sc = device_get_softc(dev); struct ifnet *ifp = &sc->arpcom.ac_if; - crit_enter(); + lwkt_serialize_enter(ifp->if_serializer); if (device_is_attached(dev)) { ether_ifdetach(ifp); @@ -1758,12 +1760,12 @@ bge_detach(device_t dev) bge_release_resources(sc); - crit_exit(); - if (sc->bge_asicrev != BGE_ASICREV_BCM5705 && sc->bge_asicrev != BGE_ASICREV_BCM5750) bge_free_jumbo_mem(sc); + lwkt_serialize_exit(ifp->if_serializer); + return(0); } @@ -2030,10 +2032,9 @@ bge_rxeof(struct bge_softc *sc) if (have_tag) { VLAN_INPUT_TAG(m, vlan_tag); have_tag = vlan_tag = 0; - continue; + } else { + ifp->if_input(ifp, m); } - - (*ifp->if_input)(ifp, m); } CSR_WRITE_4(sc, BGE_MBX_RX_CONS0_LO, sc->bge_rx_saved_considx); @@ -2112,7 +2113,7 @@ bge_intr(void *xsc) if (status & BGE_MACSTAT_MI_INTERRUPT) { sc->bge_link = 0; callout_stop(&sc->bge_stat_timer); - bge_tick(sc); + bge_tick_serialized(sc); /* Clear the interrupt */ CSR_WRITE_4(sc, BGE_MAC_EVT_ENB, BGE_EVTENB_MI_INTERRUPT); @@ -2148,11 +2149,11 @@ bge_intr(void *xsc) (!sc->bge_tbi && (mimode & BGE_MIMODE_AUTOPOLL))) { sc->bge_link = 0; callout_stop(&sc->bge_stat_timer); - bge_tick(sc); + bge_tick_serialized(sc); } sc->bge_link = 0; callout_stop(&sc->bge_stat_timer); - bge_tick(sc); + bge_tick_serialized(sc); /* Clear the interrupt */ CSR_WRITE_4(sc, BGE_MAC_STS, BGE_MACSTAT_SYNC_CHANGED| BGE_MACSTAT_CFG_CHANGED|BGE_MACSTAT_MI_COMPLETE| @@ -2182,14 +2183,23 @@ bge_intr(void *xsc) static void bge_tick(void *xsc) +{ + struct bge_softc *sc = xsc; + struct ifnet *ifp = &sc->arpcom.ac_if; + + lwkt_serialize_enter(ifp->if_serializer); + bge_tick_serialized(xsc); + lwkt_serialize_exit(ifp->if_serializer); +} + +static void +bge_tick_serialized(void *xsc) { struct bge_softc *sc = xsc; struct ifnet *ifp = &sc->arpcom.ac_if; struct mii_data *mii = NULL; struct ifmedia *ifm = NULL; - crit_enter(); - if (sc->bge_asicrev == BGE_ASICREV_BCM5705 || sc->bge_asicrev == BGE_ASICREV_BCM5750) bge_stats_update_regs(sc); @@ -2199,7 +2209,6 @@ bge_tick(void *xsc) callout_reset(&sc->bge_stat_timer, hz, bge_tick, sc); if (sc->bge_link) { - crit_exit(); return; } @@ -2217,7 +2226,6 @@ bge_tick(void *xsc) if (!ifq_is_empty(&ifp->if_snd)) (*ifp->if_start)(ifp); } - crit_exit(); return; } @@ -2236,8 +2244,6 @@ bge_tick(void *xsc) (*ifp->if_start)(ifp); } } - - crit_exit(); } static void @@ -2445,10 +2451,7 @@ bge_init(void *xsc) struct ifnet *ifp = &sc->arpcom.ac_if; uint16_t *m; - crit_enter(); - if (ifp->if_flags & IFF_RUNNING) { - crit_exit(); return; } @@ -2463,7 +2466,6 @@ bge_init(void *xsc) */ if (bge_blockinit(sc)) { if_printf(ifp, "initialization failure\n"); - crit_exit(); return; } @@ -2536,8 +2538,6 @@ bge_init(void *xsc) ifp->if_flags &= ~IFF_OACTIVE; callout_reset(&sc->bge_stat_timer, hz, bge_tick, sc); - - crit_exit(); } /* @@ -2642,8 +2642,6 @@ bge_ioctl(struct ifnet *ifp, u_long command, caddr_t data, struct ucred *cr) int mask, error = 0; struct mii_data *mii; - crit_enter(); - switch(command) { case SIOCSIFMTU: /* Disallow jumbo frames on 5705/5750. */ @@ -2719,9 +2717,6 @@ bge_ioctl(struct ifnet *ifp, u_long command, caddr_t data, struct ucred *cr) error = ether_ioctl(ifp, command, data); break; } - - crit_exit(); - return(error); } diff --git a/sys/dev/netif/cm/if_cm_isa.c b/sys/dev/netif/cm/if_cm_isa.c index 1e3b096dc0..46c9bc759b 100644 --- a/sys/dev/netif/cm/if_cm_isa.c +++ b/sys/dev/netif/cm/if_cm_isa.c @@ -1,6 +1,6 @@ /* $NetBSD: if_bah_zbus.c,v 1.6 2000/01/23 21:06:12 aymeric Exp $ */ /* $FreeBSD: src/sys/dev/cm/if_cm_isa.c,v 1.1.2.1 2002/02/13 22:33:41 fjoe Exp $ */ -/* $DragonFly: src/sys/dev/netif/cm/Attic/if_cm_isa.c,v 1.12 2005/10/12 17:35:51 dillon Exp $ */ +/* $DragonFly: src/sys/dev/netif/cm/Attic/if_cm_isa.c,v 1.13 2005/11/28 17:13:41 dillon Exp $ */ /*- * Copyright (c) 1994, 1995, 1998 The NetBSD Foundation, Inc. @@ -86,8 +86,9 @@ cm_isa_attach(dev) if (error) return error; - error = bus_setup_intr(dev, sc->irq_res, 0, - cmintr, sc, &sc->irq_handle, NULL); + error = bus_setup_intr(dev, sc->irq_res, INTR_NETSAFE, + cmintr, sc, &sc->irq_handle, + sc->sc_arccom.ac_if.if_serializer); if (error) { arc_ifdetach(&sc->sc_arccom.ac_if); cm_release_resources(dev); @@ -102,15 +103,12 @@ cm_isa_detach(device_t dev) { struct cm_softc *sc = device_get_softc(dev); - crit_enter(); - + lwkt_serialize_enter(sc->sc_arccom.ac_if.if_serializer); cm_stop(sc); arc_ifdetach(&sc->sc_arccom.ac_if); bus_teardown_intr(dev, sc->irq_res, sc->irq_handle); - - crit_exit(); - cm_release_resources(dev); + lwkt_serialize_exit(sc->sc_arccom.ac_if.if_serializer); return (0); } diff --git a/sys/dev/netif/cm/smc90cx6.c b/sys/dev/netif/cm/smc90cx6.c index c799696923..97d47c56f3 100644 --- a/sys/dev/netif/cm/smc90cx6.c +++ b/sys/dev/netif/cm/smc90cx6.c @@ -1,6 +1,6 @@ /* $NetBSD: smc90cx6.c,v 1.38 2001/07/07 15:57:53 thorpej Exp $ */ /* $FreeBSD: src/sys/dev/cm/smc90cx6.c,v 1.1.2.3 2003/02/05 18:42:14 fjoe Exp $ */ -/* $DragonFly: src/sys/dev/netif/cm/Attic/smc90cx6.c,v 1.19 2005/09/01 12:59:38 sephe Exp $ */ +/* $DragonFly: src/sys/dev/netif/cm/Attic/smc90cx6.c,v 1.20 2005/11/28 17:13:41 dillon Exp $ */ /*- * Copyright (c) 1994, 1995, 1998 The NetBSD Foundation, Inc. @@ -313,7 +313,7 @@ cm_attach(dev) ifp->if_timer = 0; ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX; - arc_ifattach(ifp, linkaddress); + arc_ifattach(ifp, linkaddress, NULL); return 0; } @@ -329,11 +329,9 @@ cm_init(xsc) struct ifnet *ifp = &sc->sc_arccom.ac_if; if ((ifp->if_flags & IFF_RUNNING) == 0) { - crit_enter(); ifp->if_flags |= IFF_RUNNING; cm_reset(sc); cm_start(ifp); - crit_exit(); } } @@ -461,23 +459,15 @@ cm_start(ifp) if_printf(ifp, "start(%p)\n", ifp); #endif - crit_enter(); - - if ((ifp->if_flags & IFF_RUNNING) == 0) { - crit_exit(); + if ((ifp->if_flags & IFF_RUNNING) == 0) return; - } - if (sc->sc_tx_fillcount >= 2) { - crit_exit(); + if (sc->sc_tx_fillcount >= 2) return; - } m = arc_frag_next(ifp); buffer = sc->sc_tx_act ^ 1; - crit_exit(); - if (m == 0) return; @@ -543,7 +533,6 @@ cm_start(ifp) sc->sc_retransmits[buffer] = (m->m_flags & M_BCAST) ? 1 : 5; /* actually transmit the packet */ - crit_enter(); if (++sc->sc_tx_fillcount > 1) { /* @@ -569,9 +558,6 @@ cm_start(ifp) sc->sc_arccom.ac_if.if_timer = ARCTIMEOUT; } - - crit_exit(); - m_freem(m); /* @@ -599,9 +585,7 @@ cm_srint(vsc) struct arc_header *ah; struct ifnet *ifp = &sc->sc_arccom.ac_if; - crit_enter(); buffer = sc->sc_rx_act ^ 1; - crit_exit(); /* * Align so that IP packet will be longword aligned. Here we @@ -651,7 +635,7 @@ cm_srint(vsc) rman_get_bustag(sc->mem_res), rman_get_bushandle(sc->mem_res), cm_ram_ptr + offset, mtod(m, u_char *) + 2, len); - (*ifp->if_input)(ifp, m); + ifp->if_input(ifp, m); m = NULL; ifp->if_ipackets++; @@ -664,8 +648,6 @@ cleanup: /* mark buffer as invalid by source id 0 */ PUTMEM(buffer << 9, 0); - crit_enter(); - if (--sc->sc_rx_fillcount == 2 - 1) { /* was off, restart it on buffer just emptied */ @@ -680,7 +662,6 @@ cleanup: if_printf(ifp, "srint: restarted rx on buf %d\n", buffer); #endif } - crit_exit(); } __inline static void @@ -901,12 +882,14 @@ cm_reconwatch(arg) struct cm_softc *sc = arg; struct ifnet *ifp = &sc->sc_arccom.ac_if; + lwkt_serialize_enter(ifp->if_serializer); if (sc->sc_reconcount >= ARC_EXCESSIVE_RECONS) { sc->sc_reconcount = 0; log(LOG_WARNING, "%s: token valid again.\n", ifp->if_xname); } sc->sc_reconcount = 0; + lwkt_serialize_exit(ifp->if_serializer); } @@ -927,8 +910,6 @@ cm_ioctl(struct ifnet *ifp, u_long command, caddr_t data, struct ucred *cr) ifa = (struct ifaddr *)data; ifr = (struct ifreq *)data; - crit_enter(); - #if defined(CM_DEBUG) && (CM_DEBUG > 2) if_printf(ifp, "ioctl() called, cmd = 0x%lx\n", command); #endif @@ -956,8 +937,6 @@ cm_ioctl(struct ifnet *ifp, u_long command, caddr_t data, struct ucred *cr) error = arc_ioctl(ifp, command, data); break; } - - crit_exit(); return (error); } diff --git a/sys/dev/netif/cs/if_cs.c b/sys/dev/netif/cs/if_cs.c index 3b25863c2d..e4d50edf48 100644 --- a/sys/dev/netif/cs/if_cs.c +++ b/sys/dev/netif/cs/if_cs.c @@ -25,7 +25,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/dev/cs/if_cs.c,v 1.19.2.1 2001/01/25 20:13:48 imp Exp $ - * $DragonFly: src/sys/dev/netif/cs/if_cs.c,v 1.22 2005/11/22 00:24:21 dillon Exp $ + * $DragonFly: src/sys/dev/netif/cs/if_cs.c,v 1.23 2005/11/28 17:13:41 dillon Exp $ */ /* @@ -587,7 +587,7 @@ cs_attach(device_t dev) { struct cs_softc *sc = device_get_softc(dev); int media = 0, error; - struct ifnet *ifp = &(sc->arpcom.ac_if); + struct ifnet *ifp = &sc->arpcom.ac_if; /* * Initialize the media structures. @@ -671,10 +671,11 @@ cs_attach(device_t dev) ifmedia_set(&sc->media, media); cs_mediaset(sc, media); - ether_ifattach(ifp, sc->arpcom.ac_enaddr); + ether_ifattach(ifp, sc->arpcom.ac_enaddr, NULL); - error = bus_setup_intr(dev, sc->irq_res, 0, - csintr, sc, &sc->irq_handle, NULL); + error = bus_setup_intr(dev, sc->irq_res, INTR_NETSAFE, + csintr, sc, &sc->irq_handle, + ifp->if_serializer); if (error) { device_printf(dev, "Couldn't set up irq"); ether_ifdetach(ifp); @@ -692,19 +693,17 @@ int cs_detach(device_t dev) { struct cs_softc *sc = device_get_softc(dev); + struct ifnet *ifp = &sc->arpcom.ac_if; - crit_enter(); + lwkt_serialize_enter(ifp->if_serializer); if (device_is_attached(dev)) { cs_stop(sc); ether_ifdetach(&sc->arpcom.ac_if); } - if (sc->irq_handle != NULL) bus_teardown_intr(dev, sc->irq_res, sc->irq_handle); - crit_exit(); - #if 0 /* * this code still in progress (DMA support) @@ -715,11 +714,10 @@ cs_detach(device_t dev) if (sc->buffer != NULL) free(sc->buffer, M_DEVBUF); - cs_release_resources(dev); - ifmedia_removeall(&sc->media); + lwkt_serialize_exit(ifp->if_serializer); return 0; } @@ -733,8 +731,6 @@ cs_init(void *xsc) struct ifnet *ifp = &sc->arpcom.ac_if; int i, rx_cfg; - crit_enter(); - /* * reset whatchdog timer */ @@ -801,8 +797,6 @@ cs_init(void *xsc) * Start sending process */ cs_start(ifp); - - crit_exit(); } /* @@ -863,7 +857,7 @@ cs_get_packet(struct cs_softc *sc) if (status & (RX_IA | RX_BROADCAST) || (ifp->if_flags & IFF_MULTICAST && status & RX_HASHED)) { - (*ifp->if_input)(ifp, m); + ifp->if_input(ifp, m); ifp->if_ipackets++; @@ -984,8 +978,6 @@ cs_start(struct ifnet *ifp) struct mbuf *m, *mp; struct cs_softc *sc = ifp->if_softc; - crit_enter(); - for (;;) { if (sc->buf_len) length = sc->buf_len; @@ -993,7 +985,6 @@ cs_start(struct ifnet *ifp) m = ifq_dequeue(&ifp->if_snd, NULL); if (m==NULL) { - crit_exit(); return; } @@ -1027,7 +1018,6 @@ cs_start(struct ifnet *ifp) if (!(cs_readreg(sc->nic_addr, PP_BusST) & READY_FOR_TX_NOW)) { ifp->if_timer = sc->buf_len; ifp->if_flags |= IFF_OACTIVE; - crit_exit(); return; } @@ -1040,7 +1030,6 @@ cs_start(struct ifnet *ifp) */ ifp->if_timer = length; - crit_exit(); ifp->if_flags |= IFF_OACTIVE; return; } @@ -1052,8 +1041,6 @@ cs_start(struct ifnet *ifp) static void cs_stop(struct cs_softc *sc) { - crit_enter(); - cs_writereg(sc->nic_addr, PP_RxCFG, 0); cs_writereg(sc->nic_addr, PP_TxCFG, 0); cs_writereg(sc->nic_addr, PP_BufCFG, 0); @@ -1061,8 +1048,6 @@ cs_stop(struct cs_softc *sc) sc->arpcom.ac_if.if_flags &= ~(IFF_RUNNING | IFF_OACTIVE); sc->arpcom.ac_if.if_timer = 0; - - crit_exit(); } /* @@ -1130,8 +1115,6 @@ cs_ioctl(register struct ifnet *ifp, u_long command, caddr_t data, if_printf(ifp, "ioctl(%lx)\n", command); #endif - crit_enter(); - switch (command) { case SIOCSIFFLAGS: /* @@ -1177,8 +1160,6 @@ cs_ioctl(register struct ifnet *ifp, u_long command, caddr_t data, break; } - crit_exit(); - return error; } diff --git a/sys/dev/netif/cue/if_cue.c b/sys/dev/netif/cue/if_cue.c index 52ce40fdae..b71970477e 100644 --- a/sys/dev/netif/cue/if_cue.c +++ b/sys/dev/netif/cue/if_cue.c @@ -30,7 +30,7 @@ * THE POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD: src/sys/dev/usb/if_cue.c,v 1.45 2003/12/08 07:54:14 obrien Exp $ - * $DragonFly: src/sys/dev/netif/cue/if_cue.c,v 1.23 2005/11/22 00:24:22 dillon Exp $ + * $DragonFly: src/sys/dev/netif/cue/if_cue.c,v 1.24 2005/11/28 17:13:41 dillon Exp $ */ /* @@ -492,7 +492,7 @@ USB_ATTACH(cue) /* * Call MI attach routine. */ - ether_ifattach(ifp, eaddr); + ether_ifattach(ifp, eaddr, NULL); usb_register_netisr(); sc->cue_dying = 0; diff --git a/sys/dev/netif/cx/if_cx.c b/sys/dev/netif/cx/if_cx.c index afbbf1176f..410c0c6b63 100644 --- a/sys/dev/netif/cx/if_cx.c +++ b/sys/dev/netif/cx/if_cx.c @@ -17,7 +17,7 @@ * Version 1.9, Wed Oct 4 18:58:15 MSK 1995 * * $FreeBSD: src/sys/i386/isa/if_cx.c,v 1.32 1999/11/18 08:36:42 peter Exp $ - * $DragonFly: src/sys/dev/netif/cx/if_cx.c,v 1.18 2005/10/13 08:50:33 sephe Exp $ + * $DragonFly: src/sys/dev/netif/cx/if_cx.c,v 1.19 2005/11/28 17:13:41 dillon Exp $ * */ #undef DEBUG @@ -281,7 +281,7 @@ cxattach (struct isa_device *id) c->ifp->if_watchdog = (watchdog_func_t) cxwatchdog; /* Init routine is never called by upper level? */ sppp_attach (c->ifp); - if_attach (c->ifp); + if_attach (c->ifp, NULL); sp = (struct sppp*) c->ifp; /* If BPF is in the kernel, call the attach for it. */ bpfattach (c->ifp, DLT_PPP, PPP_HEADER_LEN); diff --git a/sys/dev/netif/dc/if_dc.c b/sys/dev/netif/dc/if_dc.c index 4fcffdb882..28cfa63d3f 100644 --- a/sys/dev/netif/dc/if_dc.c +++ b/sys/dev/netif/dc/if_dc.c @@ -30,7 +30,7 @@ * THE POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD: src/sys/pci/if_dc.c,v 1.9.2.45 2003/06/08 14:31:53 mux Exp $ - * $DragonFly: src/sys/dev/netif/dc/if_dc.c,v 1.46 2005/11/22 00:24:25 dillon Exp $ + * $DragonFly: src/sys/dev/netif/dc/if_dc.c,v 1.47 2005/11/28 17:13:41 dillon Exp $ */ /* @@ -637,8 +637,6 @@ dc_mii_readreg(struct dc_softc *sc, struct dc_mii_frame *frame) { int ack, i; - crit_enter(); - /* * Set up frame for RX. */ @@ -692,8 +690,6 @@ fail: dc_mii_writebit(sc, 0); dc_mii_writebit(sc, 0); - crit_exit(); - if (ack) return(1); return(0); @@ -705,8 +701,6 @@ fail: static int dc_mii_writereg(struct dc_softc *sc, struct dc_mii_frame *frame) { - crit_enter(); - /* * Set up frame for TX. */ @@ -731,8 +725,6 @@ dc_mii_writereg(struct dc_softc *sc, struct dc_mii_frame *frame) dc_mii_writebit(sc, 0); dc_mii_writebit(sc, 0); - crit_exit(); - return(0); } @@ -2030,7 +2022,7 @@ dc_attach(device_t dev) /* * Call MI attach routine. */ - ether_ifattach(ifp, eaddr); + ether_ifattach(ifp, eaddr, NULL); if (DC_IS_ADMTEK(sc)) { /* @@ -2044,8 +2036,9 @@ dc_attach(device_t dev) */ ifp->if_data.ifi_hdrlen = sizeof(struct ether_vlan_header); - error = bus_setup_intr(dev, sc->dc_irq, 0, - dc_intr, sc, &sc->dc_intrhand, NULL); + error = bus_setup_intr(dev, sc->dc_irq, INTR_NETSAFE, + dc_intr, sc, &sc->dc_intrhand, + ifp->if_serializer); if (error) { ether_ifdetach(ifp); device_printf(dev, "couldn't set up irq\n"); @@ -2066,7 +2059,7 @@ dc_detach(device_t dev) struct ifnet *ifp = &sc->arpcom.ac_if; struct dc_mediainfo *m; - crit_enter(); + lwkt_serialize_enter(ifp->if_serializer); if (device_is_attached(dev)) { dc_stop(sc); @@ -2080,8 +2073,6 @@ dc_detach(device_t dev) if (sc->dc_intrhand) bus_teardown_intr(dev, sc->dc_irq, sc->dc_intrhand); - crit_exit(); - if (sc->dc_irq) bus_release_resource(dev, SYS_RES_IRQ, 0, sc->dc_irq); if (sc->dc_res) @@ -2101,6 +2092,7 @@ dc_detach(device_t dev) if (sc->dc_srom) free(sc->dc_srom, M_DEVBUF); + lwkt_serialize_exit(ifp->if_serializer); return(0); } @@ -2460,7 +2452,7 @@ dc_rxeof(struct dc_softc *sc) } ifp->if_ipackets++; - (*ifp->if_input)(ifp, m); + ifp->if_input(ifp, m); } sc->dc_cdata.dc_rx_prod = i; @@ -2580,7 +2572,7 @@ dc_tick(void *xsc) struct mii_data *mii; u_int32_t r; - crit_enter(); + lwkt_serialize_enter(ifp->if_serializer); mii = device_get_softc(sc->dc_miibus); @@ -2608,8 +2600,9 @@ dc_tick(void *xsc) sc->dc_link = 0; } } - } else + } else { mii_tick(mii); + } /* * When the init routine completes, we expect to be able to send @@ -2645,7 +2638,7 @@ dc_tick(void *xsc) else callout_reset(&sc->dc_stat_timer, hz, dc_tick, sc); - crit_exit(); + lwkt_serialize_exit(ifp->if_serializer); } /* @@ -3024,8 +3017,6 @@ dc_init(void *xsc) struct ifnet *ifp = &sc->arpcom.ac_if; struct mii_data *mii; - crit_enter(); - mii = device_get_softc(sc->dc_miibus); /* @@ -3107,7 +3098,6 @@ dc_init(void *xsc) if_printf(ifp, "initialization failed: no " "memory for rx buffers\n"); dc_stop(sc); - crit_exit(); return; } @@ -3170,8 +3160,6 @@ dc_init(void *xsc) ifp->if_flags |= IFF_RUNNING; ifp->if_flags &= ~IFF_OACTIVE; - crit_exit(); - /* Don't start the ticker if this is a homePNA link. */ if (IFM_SUBTYPE(mii->mii_media.ifm_media) == IFM_HPNA_1) sc->dc_link = 1; @@ -3244,8 +3232,6 @@ dc_ioctl(struct ifnet *ifp, u_long command, caddr_t data, struct ucred *cr) struct mii_data *mii; int error = 0; - crit_enter(); - switch(command) { case SIOCSIFFLAGS: if (ifp->if_flags & IFF_UP) { @@ -3280,8 +3266,6 @@ dc_ioctl(struct ifnet *ifp, u_long command, caddr_t data, struct ucred *cr) break; } - crit_exit(); - return(error); } @@ -3370,13 +3354,16 @@ dc_stop(struct dc_softc *sc) static void dc_shutdown(device_t dev) { - struct dc_softc *sc; + struct dc_softc *sc; + struct ifnet *ifp; sc = device_get_softc(dev); + ifp = &sc->arpcom.ac_if; + lwkt_serialize_enter(ifp->if_serializer); dc_stop(sc); - return; + lwkt_serialize_exit(ifp->if_serializer); } /* @@ -3388,12 +3375,11 @@ static int dc_suspend(device_t dev) { struct dc_softc *sc = device_get_softc(dev); + struct ifnet *ifp = &sc->arpcom.ac_if; int i; - - crit_enter(); + lwkt_serialize_enter(ifp->if_serializer); dc_stop(sc); - for (i = 0; i < 5; i++) sc->saved_maps[i] = pci_read_config(dev, PCIR_MAPS + i * 4, 4); sc->saved_biosaddr = pci_read_config(dev, PCIR_BIOS, 4); @@ -3403,7 +3389,7 @@ dc_suspend(device_t dev) sc->suspended = 1; - crit_exit(); + lwkt_serialize_exit(ifp->if_serializer); return (0); } @@ -3419,8 +3405,7 @@ dc_resume(device_t dev) struct ifnet *ifp = &sc->arpcom.ac_if; int i; - crit_enter(); - + lwkt_serialize_enter(ifp->if_serializer); dc_acpi(dev); /* better way to do this? */ @@ -3440,7 +3425,7 @@ dc_resume(device_t dev) dc_init(sc); sc->suspended = 0; + lwkt_serialize_exit(ifp->if_serializer); - crit_exit(); return (0); } diff --git a/sys/dev/netif/de/if_de.c b/sys/dev/netif/de/if_de.c index 894fbf20a1..938225d718 100644 --- a/sys/dev/netif/de/if_de.c +++ b/sys/dev/netif/de/if_de.c @@ -1,7 +1,7 @@ /* $NetBSD: if_de.c,v 1.86 1999/06/01 19:17:59 thorpej Exp $ */ /* $FreeBSD: src/sys/pci/if_de.c,v 1.123.2.4 2000/08/04 23:25:09 peter Exp $ */ -/* $DragonFly: src/sys/dev/netif/de/if_de.c,v 1.40 2005/10/12 17:35:51 dillon Exp $ */ +/* $DragonFly: src/sys/dev/netif/de/if_de.c,v 1.41 2005/11/28 17:13:42 dillon Exp $ */ /*- * Copyright (c) 1994-1997 Matt Thomas (matt@3am-software.com) @@ -129,13 +129,11 @@ tulip_timeout_callback(void *arg) { tulip_softc_t *sc = arg; - crit_enter(); - + lwkt_serialize_enter(&sc->tulip_serializer); sc->tulip_flags &= ~TULIP_TIMEOUTPENDING; sc->tulip_probe_timeout -= 1000 / TULIP_HZ; (sc->tulip_boardsw->bd_media_poll)(sc, TULIP_MEDIAPOLL_TIMER); - - crit_exit(); + lwkt_serialize_exit(&sc->tulip_serializer); } static void @@ -152,6 +150,7 @@ static int tulip_txprobe(tulip_softc_t *sc) { struct mbuf *m; + /* * Before we are sure this is the right media we need * to send a small packet to make sure there's carrier. @@ -3026,7 +3025,6 @@ tulip_rx_intr(tulip_softc_t *sc) int fillok = 1; for (;;) { - struct ether_header eh; tulip_desc_t *eop = ri->ri_nextin; int total_len = 0, last_offset = 0; struct mbuf *ms = NULL, *me = NULL; @@ -3106,7 +3104,6 @@ tulip_rx_intr(tulip_softc_t *sc) )) { me->m_len = total_len - last_offset; - eh = *mtod(ms, struct ether_header *); sc->tulip_flags |= TULIP_RXACT; accept = 1; } else { @@ -3163,9 +3160,7 @@ tulip_rx_intr(tulip_softc_t *sc) ) { #if !defined(TULIP_COPY_RXDATA) ms->m_pkthdr.len = total_len; - ms->m_pkthdr.rcvif = ifp; - m_adj(ms, sizeof(struct ether_header)); - ether_input(ifp, &eh, ms); + ifp->if_input(ifp, ms); #else #ifdef BIG_PACKET #error BIG_PACKET is incompatible with TULIP_COPY_RXDATA @@ -3174,8 +3169,7 @@ tulip_rx_intr(tulip_softc_t *sc) m_copydata(ms, 0, total_len, mtod(m0, caddr_t)); m0->m_len = m0->m_pkthdr.len = total_len; m0->m_pkthdr.rcvif = ifp; - m_adj(m0, sizeof(struct ether_header)); - ether_input(ifp, &eh, m0); + ifp->if_input(ifp, m0); m0 = ms; #endif /* ! TULIP_COPY_RXDATA */ } @@ -3723,8 +3717,6 @@ tulip_ifioctl(struct ifnet *ifp, u_long cmd, caddr_t data, struct ucred * cr) struct ifreq *ifr = (struct ifreq *)data; int error = 0; - crit_enter(); - switch (cmd) { case SIOCSIFADDR: { ifp->if_flags |= IFF_UP; @@ -3849,9 +3841,6 @@ tulip_ifioctl(struct ifnet *ifp, u_long cmd, caddr_t data, struct ucred * cr) break; } } - - crit_exit(); - return error; } @@ -3951,7 +3940,7 @@ tulip_attach(tulip_softc_t *sc) tulip_reset(sc); - ether_ifattach(&(sc)->tulip_if, sc->tulip_enaddr); + ether_ifattach(&(sc)->tulip_if, sc->tulip_enaddr, NULL); ifp->if_snd.ifq_maxlen = ifqmaxlen; } @@ -4041,10 +4030,13 @@ static int tulip_shutdown(device_t dev) { tulip_softc_t *sc = device_get_softc(dev); + + lwkt_serialize_enter(&sc->tulip_serializer); TULIP_CSR_WRITE(sc, csr_busmode, TULIP_BUSMODE_SWRESET); DELAY(10); /* Wait 10 microseconds (actually 50 PCI cycles but at 33MHz that comes to two microseconds but wait a bit longer anyways) */ + lwkt_serialize_exit(&sc->tulip_serializer); return 0; } @@ -4098,6 +4090,7 @@ tulip_pci_attach(device_t dev) } sc = device_get_softc(dev); + lwkt_serialize_init(&sc->tulip_serializer); sc->tulip_dev = dev; sc->tulip_pci_busno = pci_get_bus(dev); sc->tulip_pci_devno = pci_get_slot(dev); @@ -4163,6 +4156,7 @@ tulip_pci_attach(device_t dev) 33MHz that comes to two microseconds but wait a bit longer anyways) */ + lwkt_serialize_enter(&sc->tulip_serializer); if ((retval = tulip_read_macaddr(sc)) < 0) { device_printf(dev, "can't read ENET ROM (why=%d) (", retval); for (idx = 0; idx < 32; idx++) @@ -4184,18 +4178,18 @@ tulip_pci_attach(device_t dev) rid = 0; res = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid, RF_SHAREABLE | RF_ACTIVE); - if (res == 0 || bus_setup_intr(dev, res, 0, - intr_rtn, sc, &ih, NULL)) { + if (res == 0 || bus_setup_intr(dev, res, INTR_NETSAFE, + intr_rtn, sc, &ih, + &sc->tulip_serializer)) { + lwkt_serialize_exit(&sc->tulip_serializer); device_printf(dev, "couldn't map interrupt\n"); free((caddr_t) sc->tulip_rxdescs, M_DEVBUF); free((caddr_t) sc->tulip_txdescs, M_DEVBUF); return ENXIO; } } - - crit_enter(); tulip_attach(sc); - crit_exit(); + lwkt_serialize_exit(&sc->tulip_serializer); } return 0; } diff --git a/sys/dev/netif/de/if_devar.h b/sys/dev/netif/de/if_devar.h index 9b4a514d59..b4b4dbc4a8 100644 --- a/sys/dev/netif/de/if_devar.h +++ b/sys/dev/netif/de/if_devar.h @@ -1,7 +1,7 @@ /* $NetBSD: if_devar.h,v 1.32 1999/04/01 14:55:25 tsubai Exp $ */ /* $FreeBSD: src/sys/pci/if_devar.h,v 1.23.2.1 2000/08/04 23:25:10 peter Exp $ */ -/* $DragonFly: src/sys/dev/netif/de/if_devar.h,v 1.13 2005/05/11 20:58:35 joerg Exp $ */ +/* $DragonFly: src/sys/dev/netif/de/if_devar.h,v 1.14 2005/11/28 17:13:42 dillon Exp $ */ /*- * Copyright (c) 1994-1997 Matt Thomas (matt@3am-software.com) @@ -428,9 +428,11 @@ typedef struct { * come from??? No idea) for the tulip device. */ struct _tulip_softc_t { - struct ifmedia tulip_ifmedia; - struct callout tulip_timer, tulip_fast_timer; struct arpcom tulip_ac; + struct ifmedia tulip_ifmedia; + struct callout tulip_timer; + struct callout tulip_fast_timer; + struct lwkt_serialize tulip_serializer; bus_space_tag_t tulip_csrs_bst; bus_space_handle_t tulip_csrs_bsh; tulip_regfile_t tulip_csrs; diff --git a/sys/dev/netif/ed/if_ed.c b/sys/dev/netif/ed/if_ed.c index 6a07319d50..55981caec0 100644 --- a/sys/dev/netif/ed/if_ed.c +++ b/sys/dev/netif/ed/if_ed.c @@ -25,7 +25,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/dev/ed/if_ed.c,v 1.224 2003/12/08 07:54:12 obrien Exp $ - * $DragonFly: src/sys/dev/netif/ed/if_ed.c,v 1.27 2005/11/22 00:24:26 dillon Exp $ + * $DragonFly: src/sys/dev/netif/ed/if_ed.c,v 1.28 2005/11/28 17:13:42 dillon Exp $ */ /* @@ -1725,7 +1725,7 @@ ed_attach(device_t dev) /* * Attach the interface */ - ether_ifattach(ifp, sc->arpcom.ac_enaddr); + ether_ifattach(ifp, sc->arpcom.ac_enaddr, NULL); /* device attach does transition from UNCONFIGURED to IDLE state */ @@ -1822,8 +1822,10 @@ ed_tick(void *arg) { struct ed_softc *sc = arg; struct mii_data *mii; + struct ifnet *ifp; - crit_enter(); + ifp = &sc->arpcom.ac_if; + lwkt_serialize_enter(ifp->if_serializer); if (sc->gone) { crit_exit(); @@ -1836,8 +1838,7 @@ ed_tick(void *arg) } callout_reset(&sc->ed_timer, hz, ed_tick, sc); - - crit_exit(); + lwkt_serialize_exit(ifp->if_serializer); } #endif @@ -2786,7 +2787,7 @@ ed_get_packet(struct ed_softc *sc, char *buf, u_short len) m->m_pkthdr.len = m->m_len = len; - (*ifp->if_input)(ifp, m); + ifp->if_input(ifp, m); } /* diff --git a/sys/dev/netif/ed/if_ed_isa.c b/sys/dev/netif/ed/if_ed_isa.c index 329a14ed97..b3c93995f3 100644 --- a/sys/dev/netif/ed/if_ed_isa.c +++ b/sys/dev/netif/ed/if_ed_isa.c @@ -25,7 +25,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/dev/ed/if_ed_isa.c,v 1.15 2003/10/31 18:31:58 brooks Exp $ - * $DragonFly: src/sys/dev/netif/ed/if_ed_isa.c,v 1.12 2005/10/12 17:35:51 dillon Exp $ + * $DragonFly: src/sys/dev/netif/ed/if_ed_isa.c,v 1.13 2005/11/28 17:13:42 dillon Exp $ */ #include @@ -48,6 +48,7 @@ static int ed_isa_probe (device_t); static int ed_isa_attach (device_t); +static int ed_isa_detach (device_t); static struct isa_pnp_id ed_ids[] = { { 0x1684a34d, NULL }, /* SMC8416 */ @@ -129,20 +130,45 @@ ed_isa_attach(device_t dev) ed_alloc_irq(dev, sc->irq_rid, 0); - error = bus_setup_intr(dev, sc->irq_res, 0, - edintr, sc, &sc->irq_handle, NULL); - if (error) { + error = ed_attach(dev); + if (error == 0) { + error = bus_setup_intr(dev, sc->irq_res, INTR_NETSAFE, + edintr, sc, &sc->irq_handle, + sc->arpcom.ac_if.if_serializer); + if (error) + ed_isa_detach(dev); + } else { ed_release_resources(dev); - return (error); } + return (error); +} - return ed_attach(dev); +static int +ed_isa_detach(device_t dev) +{ + struct ed_softc *sc = device_get_softc(dev); + struct ifnet *ifp = &sc->arpcom.ac_if; + + lwkt_serialize_enter(ifp->if_serializer); + if (sc->gone) { + device_printf(dev, "already unloaded\n"); + return (0); + } + ed_stop(sc); + ifp->if_flags &= ~IFF_RUNNING; + ether_ifdetach(ifp); + sc->gone = 1; + bus_teardown_intr(dev, sc->irq_res, sc->irq_handle); + ed_release_resources(dev); + lwkt_serialize_exit(ifp->if_serializer); + return (0); } static device_method_t ed_isa_methods[] = { /* Device interface */ DEVMETHOD(device_probe, ed_isa_probe), DEVMETHOD(device_attach, ed_isa_attach), + DEVMETHOD(device_attach, ed_isa_detach), { 0, 0 } }; diff --git a/sys/dev/netif/ed/if_ed_pccard.c b/sys/dev/netif/ed/if_ed_pccard.c index bc23bb9e8b..04091dd0d4 100644 --- a/sys/dev/netif/ed/if_ed_pccard.c +++ b/sys/dev/netif/ed/if_ed_pccard.c @@ -25,7 +25,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/dev/ed/if_ed_pccard.c,v 1.55 2003/12/31 04:25:00 kato Exp $ - * $DragonFly: src/sys/dev/netif/ed/if_ed_pccard.c,v 1.13 2005/10/12 17:35:51 dillon Exp $ + * $DragonFly: src/sys/dev/netif/ed/if_ed_pccard.c,v 1.14 2005/11/28 17:13:42 dillon Exp $ */ #include "opt_ed.h" @@ -102,6 +102,7 @@ ed_pccard_detach(device_t dev) struct ed_softc *sc = device_get_softc(dev); struct ifnet *ifp = &sc->arpcom.ac_if; + lwkt_serialize_enter(ifp->if_serializer); if (sc->gone) { device_printf(dev, "already unloaded\n"); return (0); @@ -112,6 +113,7 @@ ed_pccard_detach(device_t dev) sc->gone = 1; bus_teardown_intr(dev, sc->irq_res, sc->irq_handle); ed_release_resources(dev); + lwkt_serialize_exit(ifp->if_serializer); return (0); } @@ -258,7 +260,7 @@ ed_pccard_attach(device_t dev) ed_alloc_memory(dev, sc->mem_rid, sc->mem_used); ed_alloc_irq(dev, sc->irq_rid, 0); - error = bus_setup_intr(dev, sc->irq_res, 0, + error = bus_setup_intr(dev, sc->irq_res, INTR_NETSAFE, edintr, sc, &sc->irq_handle, NULL); if (error) { printf("setup intr failed %d \n", error); diff --git a/sys/dev/netif/ed/if_ed_pci.c b/sys/dev/netif/ed/if_ed_pci.c index 52f0124b80..8c0a5d6f00 100644 --- a/sys/dev/netif/ed/if_ed_pci.c +++ b/sys/dev/netif/ed/if_ed_pci.c @@ -18,7 +18,7 @@ * are met. * * $FreeBSD: src/sys/dev/ed/if_ed_pci.c,v 1.34 2003/10/31 18:31:58 brooks Exp $ - * $DragonFly: src/sys/dev/netif/ed/if_ed_pci.c,v 1.9 2005/10/12 17:35:51 dillon Exp $ + * $DragonFly: src/sys/dev/netif/ed/if_ed_pci.c,v 1.10 2005/11/28 17:13:42 dillon Exp $ */ #include @@ -42,6 +42,8 @@ #include "if_edvar.h" +static int ed_pci_detach(device_t dev); + static struct _pcsid { u_int32_t type; @@ -95,22 +97,45 @@ ed_pci_attach(device_t dev) return (error); } - error = bus_setup_intr(dev, sc->irq_res, 0, - edintr, sc, &sc->irq_handle, NULL); - if (error) { + error = ed_attach(dev); + if (error == 0) { + error = bus_setup_intr(dev, sc->irq_res, INTR_NETSAFE, + edintr, sc, &sc->irq_handle, + sc->arpcom.ac_if.if_serializer); + if (error) + ed_pci_detach(dev); + } else { ed_release_resources(dev); - return (error); - } + } + return (error); +} - error = ed_attach(dev); +static int +ed_pci_detach(device_t dev) +{ + struct ed_softc *sc = device_get_softc(dev); + struct ifnet *ifp = &sc->arpcom.ac_if; - return (error); + lwkt_serialize_enter(ifp->if_serializer); + if (sc->gone) { + device_printf(dev, "already unloaded\n"); + return (0); + } + ed_stop(sc); + ifp->if_flags &= ~IFF_RUNNING; + ether_ifdetach(ifp); + sc->gone = 1; + bus_teardown_intr(dev, sc->irq_res, sc->irq_handle); + ed_release_resources(dev); + lwkt_serialize_exit(ifp->if_serializer); + return (0); } static device_method_t ed_pci_methods[] = { /* Device interface */ DEVMETHOD(device_probe, ed_pci_probe), DEVMETHOD(device_attach, ed_pci_attach), + DEVMETHOD(device_attach, ed_pci_detach), { 0, 0 } }; diff --git a/sys/dev/netif/el/if_el.c b/sys/dev/netif/el/if_el.c index d203eff389..a91fdecff9 100644 --- a/sys/dev/netif/el/if_el.c +++ b/sys/dev/netif/el/if_el.c @@ -7,7 +7,7 @@ * Questions, comments, bug reports and fixes to kimmel@cs.umass.edu. * * $FreeBSD: src/sys/i386/isa/if_el.c,v 1.47.2.2 2000/07/17 21:24:30 archie Exp $ - * $DragonFly: src/sys/dev/netif/el/if_el.c,v 1.19 2005/11/22 00:24:27 dillon Exp $ + * $DragonFly: src/sys/dev/netif/el/if_el.c,v 1.20 2005/11/28 17:13:42 dillon Exp $ */ /* Except of course for the portions of code lifted from other FreeBSD * drivers (mainly elread, elget and el_ioctl) @@ -32,6 +32,7 @@ #include #include #include +#include #include #include @@ -85,6 +86,8 @@ struct isa_driver eldriver = { el_probe, el_attach, "el" }; +static struct lwkt_serialize el_serializer; + /* Probe routine. See if the card is there and at the right place. */ static int el_probe(struct isa_device *idev) @@ -94,6 +97,8 @@ el_probe(struct isa_device *idev) u_char station_addr[ETHER_ADDR_LEN]; int i; + lwkt_serialize_init(&el_serializer); + /* Grab some info for our structure */ sc = &el_softc[idev->id_unit]; sc->el_base = idev->id_iobase; @@ -199,7 +204,7 @@ el_attach(struct isa_device *idev) /* Now we can attach the interface */ dprintf(("Attaching interface...\n")); - ether_ifattach(ifp, sc->arpcom.ac_enaddr); + ether_ifattach(ifp, sc->arpcom.ac_enaddr, &el_serializer); dprintf(("el_attach() finished.\n")); return(1); @@ -213,10 +218,8 @@ el_reset(xsc) struct el_softc *sc = xsc; dprintf(("elreset()\n")); - crit_enter(); el_stop(sc); el_init(sc); - crit_exit(); } static void el_stop(xsc) @@ -236,7 +239,6 @@ el_init(xsc) struct ifnet *ifp = &sc->arpcom.ac_if; u_short base = sc->el_base; - crit_enter(); /* First, reset the board. */ dprintf(("Resetting board...\n")); @@ -264,8 +266,6 @@ el_init(xsc) /* And start output. */ el_start(ifp); - - crit_exit(); } /* Start output on interface. Get datagrams from the queue and output @@ -285,7 +285,6 @@ el_start(struct ifnet *ifp) base = sc->el_base; dprintf(("el_start()...\n")); - crit_enter(); /* Don't do anything if output is active */ if (ifp->if_flags & IFF_OACTIVE) @@ -302,7 +301,6 @@ el_start(struct ifnet *ifp) /* If there's nothing to send, return. */ if(m0 == NULL) { sc->arpcom.ac_if.if_flags &= ~IFF_OACTIVE; - crit_exit(); return; } @@ -367,8 +365,6 @@ el_start(struct ifnet *ifp) */ (void)inb(base+EL_AS); outb(base+EL_AC,(EL_AC_IRQE|EL_AC_RX)); - crit_exit(); - crit_enter(); } } @@ -403,19 +399,14 @@ el_xmit(struct el_softc *sc,int len) static __inline void elread(struct el_softc *sc,caddr_t buf,int len) { - struct ether_header *eh; struct mbuf *m; - eh = (struct ether_header *)buf; - /* * Put packet into an mbuf chain */ m = elget(buf,len,&sc->arpcom.ac_if); - if(m == 0) - return; - - ether_input(&sc->arpcom.ac_if,eh,m); + if(m) + sc->arpcom.ac_if.if_input(&sc->arpcom.ac_if, m); } /* controller interrupt */ @@ -427,6 +418,8 @@ elintr(void *arg) int base; int stat, rxstat, len, done; + lwkt_serialize_enter(&el_serializer); + /* Get things pointing properly */ sc = &el_softc[unit]; base = sc->el_base; @@ -438,6 +431,7 @@ elintr(void *arg) if(stat & EL_AS_RXBUSY) { (void)inb(base+EL_RXC); outb(base+EL_AC,(EL_AC_IRQE|EL_AC_RX)); + lwkt_serialize_exit(&el_serializer); return; } @@ -447,6 +441,7 @@ elintr(void *arg) if(rxstat & EL_RXS_STALE) { (void)inb(base+EL_RXC); outb(base+EL_AC,(EL_AC_IRQE|EL_AC_RX)); + lwkt_serialize_exit(&el_serializer); return; } @@ -463,6 +458,7 @@ elintr(void *arg) outb(base+EL_RBC,0); (void)inb(base+EL_RXC); outb(base+EL_AC,(EL_AC_IRQE|EL_AC_RX)); + lwkt_serialize_exit(&el_serializer); return; } @@ -483,6 +479,7 @@ elintr(void *arg) outb(base+EL_RBC,0); (void)inb(base+EL_RXC); outb(base+EL_AC,(EL_AC_IRQE|EL_AC_RX)); + lwkt_serialize_exit(&el_serializer); return; } @@ -498,7 +495,6 @@ elintr(void *arg) dprintf(("%6D\n",sc->el_pktbuf,":")); /* Pass data up to upper levels */ - len -= sizeof(struct ether_header); elread(sc,(caddr_t)(sc->el_pktbuf),len); /* Is there another packet? */ @@ -513,7 +509,7 @@ elintr(void *arg) (void)inb(base+EL_RXC); outb(base+EL_AC,(EL_AC_IRQE|EL_AC_RX)); - return; + lwkt_serialize_exit(&el_serializer); } /* @@ -531,14 +527,12 @@ elget(buf, totlen, ifp) caddr_t cp; char *epkt; - buf += sizeof(struct ether_header); cp = buf; epkt = cp + totlen; MGETHDR(m, MB_DONTWAIT, MT_DATA); if (m == 0) return (0); - m->m_pkthdr.rcvif = ifp; m->m_pkthdr.len = totlen; m->m_len = MHLEN; top = 0; @@ -590,8 +584,6 @@ el_ioctl(struct ifnet *ifp, u_long command, caddr_t data, struct ucred *cr) { int error = 0; - crit_enter(); - switch (command) { case SIOCSIFFLAGS: /* @@ -614,9 +606,6 @@ el_ioctl(struct ifnet *ifp, u_long command, caddr_t data, struct ucred *cr) error = ether_ioctl(ifp, command, data); break; } - - crit_exit(); - return (error); } diff --git a/sys/dev/netif/em/if_em.c b/sys/dev/netif/em/if_em.c index 11eb935b33..e0670b96fc 100644 --- a/sys/dev/netif/em/if_em.c +++ b/sys/dev/netif/em/if_em.c @@ -1,40 +1,97 @@ -/************************************************************************** - -Copyright (c) 2004 Joerg Sonnenberger . All rights reserved. - -Copyright (c) 2001-2005, Intel Corporation -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - - 1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - 2. Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - 3. Neither the name of the Intel Corporation nor the names of its - contributors may be used to endorse or promote products derived from - this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE -LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -POSSIBILITY OF SUCH DAMAGE. - -***************************************************************************/ - -/*$FreeBSD: src/sys/dev/em/if_em.c,v 1.2.2.15 2003/06/09 22:10:15 pdeuskar Exp $*/ -/*$DragonFly: src/sys/dev/netif/em/if_em.c,v 1.43 2005/11/22 00:24:28 dillon Exp $*/ +/* + * + * Copyright (c) 2004 Joerg Sonnenberger . All rights reserved. + * + * Copyright (c) 2001-2005, Intel Corporation + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * 3. Neither the name of the Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * + * Copyright (c) 2005 The DragonFly Project. All rights reserved. + * + * This code is derived from software contributed to The DragonFly Project + * by Matthew Dillon + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name of The DragonFly Project nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific, prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $DragonFly: src/sys/dev/netif/em/if_em.c,v 1.44 2005/11/28 17:13:42 dillon Exp $ + * $FreeBSD$ + */ +/* + * SERIALIZATION API RULES: + * + * - If the driver uses the same serializer for the interrupt as for the + * ifnet, most of the serialization will be done automatically for the + * driver. + * + * - ifmedia entry points will be serialized by the ifmedia code using the + * ifnet serializer. + * + * - if_* entry points except for if_input will be serialized by the IF + * and protocol layers. + * + * - The device driver must be sure to serialize access from timeout code + * installed by the device driver. + * + * - The device driver typically holds the serializer at the time it wishes + * to call if_input. If so, it should pass the serializer to if_input and + * note that the serializer might be dropped temporarily by if_input + * (e.g. in case it has to bridge the packet to another interface). + * + * NOTE! Since callers into the device driver hold the ifnet serializer, + * the device driver may be holding a serializer at the time it calls + * if_input even if it is not serializer-aware. + */ #include "opt_polling.h" @@ -144,11 +201,9 @@ static int em_detach(device_t); static int em_shutdown(device_t); static void em_intr(void *); static void em_start(struct ifnet *); -static void em_start_serialized(struct ifnet *); static int em_ioctl(struct ifnet *, u_long, caddr_t, struct ucred *); static void em_watchdog(struct ifnet *); static void em_init(void *); -static void em_init_serialized(void *); static void em_stop(void *); static void em_media_status(struct ifnet *, struct ifmediareq *); static int em_media_change(struct ifnet *); @@ -317,8 +372,6 @@ em_attach(device_t dev) adapter = device_get_softc(dev); - lwkt_serialize_init(&adapter->serializer); - callout_init(&adapter->timer); callout_init(&adapter->tx_fifo_timer); @@ -535,9 +588,10 @@ em_attach(device_t dev) else adapter->pcix_82544 = FALSE; - error = bus_setup_intr(dev, adapter->res_interrupt, 0, + error = bus_setup_intr(dev, adapter->res_interrupt, INTR_NETSAFE, (void (*)(void *)) em_intr, adapter, - &adapter->int_handler_tag, &adapter->serializer); + &adapter->int_handler_tag, + adapter->interface_data.ac_if.if_serializer); if (error) { device_printf(dev, "Error registering interrupt handler!\n"); ether_ifdetach(&adapter->interface_data.ac_if); @@ -565,11 +619,11 @@ fail: static int em_detach(device_t dev) { - struct adapter * adapter = device_get_softc(dev); + struct adapter *adapter = device_get_softc(dev); INIT_DEBUGOUT("em_detach: begin"); - lwkt_serialize_enter(&adapter->serializer); + lwkt_serialize_enter(adapter->interface_data.ac_if.if_serializer); adapter->in_detach = 1; if (device_is_attached(dev)) { @@ -612,7 +666,7 @@ em_detach(device_t dev) adapter->sysctl_tree = NULL; sysctl_ctx_free(&adapter->sysctl_ctx); - lwkt_serialize_exit(&adapter->serializer); + lwkt_serialize_exit(adapter->interface_data.ac_if.if_serializer); return(0); } @@ -642,20 +696,12 @@ em_shutdown(device_t dev) static void em_start(struct ifnet *ifp) -{ - struct adapter *adapter = ifp->if_softc; - - lwkt_serialize_enter(&adapter->serializer); - em_start_serialized(ifp); - lwkt_serialize_exit(&adapter->serializer); -} - -static void -em_start_serialized(struct ifnet *ifp) { struct mbuf *m_head; struct adapter *adapter = ifp->if_softc; + ASSERT_SERIALIZED(adapter->interface_data.ac_if.if_serializer); + if (!adapter->link_active) return; while (!ifq_is_empty(&ifp->if_snd)) { @@ -694,7 +740,7 @@ em_ioctl(struct ifnet *ifp, u_long command, caddr_t data, struct ucred *cr) struct ifreq *ifr = (struct ifreq *) data; struct adapter *adapter = ifp->if_softc; - lwkt_serialize_enter(&adapter->serializer); + ASSERT_SERIALIZED(adapter->interface_data.ac_if.if_serializer); if (adapter->in_detach) goto out; @@ -703,9 +749,7 @@ em_ioctl(struct ifnet *ifp, u_long command, caddr_t data, struct ucred *cr) case SIOCSIFADDR: case SIOCGIFADDR: IOCTL_DEBUGOUT("ioctl rcv'd: SIOCxIFADDR (Get/Set Interface Addr)"); - lwkt_serialize_exit(&adapter->serializer); ether_ioctl(ifp, command, data); - lwkt_serialize_enter(&adapter->serializer); break; case SIOCSIFMTU: IOCTL_DEBUGOUT("ioctl rcv'd: SIOCSIFMTU (Set Interface MTU)"); @@ -729,14 +773,14 @@ em_ioctl(struct ifnet *ifp, u_long command, caddr_t data, struct ucred *cr) ifp->if_mtu = ifr->ifr_mtu; adapter->hw.max_frame_size = ifp->if_mtu + ETHER_HDR_LEN + ETHER_CRC_LEN; - em_init_serialized(adapter); + em_init(adapter); } break; case SIOCSIFFLAGS: IOCTL_DEBUGOUT("ioctl rcv'd: SIOCSIFFLAGS (Set Interface Flags)"); if (ifp->if_flags & IFF_UP) { if (!(ifp->if_flags & IFF_RUNNING)) - em_init_serialized(adapter); + em_init(adapter); em_disable_promisc(adapter); em_set_promisc(adapter); } else { @@ -769,7 +813,7 @@ em_ioctl(struct ifnet *ifp, u_long command, caddr_t data, struct ucred *cr) else ifp->if_capenable |= IFCAP_HWCSUM; if (ifp->if_flags & IFF_RUNNING) - em_init_serialized(adapter); + em_init(adapter); } break; default: @@ -778,7 +822,6 @@ em_ioctl(struct ifnet *ifp, u_long command, caddr_t data, struct ucred *cr) } out: - lwkt_serialize_exit(&adapter->serializer); return(error); } @@ -826,16 +869,6 @@ em_watchdog(struct ifnet *ifp) static void em_init(void *arg) -{ - struct adapter *adapter = arg; - - lwkt_serialize_enter(&adapter->serializer); - em_init_serialized(arg); - lwkt_serialize_exit(&adapter->serializer); -} - -static void -em_init_serialized(void *arg) { struct adapter *adapter = arg; uint32_t pba; @@ -942,7 +975,8 @@ em_poll(struct ifnet *ifp, enum poll_cmd cmd, int count) struct adapter *adapter = ifp->if_softc; uint32_t reg_icr; - lwkt_serialize_enter(&adapter->serializer); + ASSERT_SERIALIZED(ifp->if_serializer); + switch(cmd) { case POLL_REGISTER: em_disable_intr(adapter); @@ -968,11 +1002,10 @@ em_poll(struct ifnet *ifp, enum poll_cmd cmd, int count) } if (ifp->if_flags & IFF_RUNNING) { if (!ifq_is_empty(&ifp->if_snd)) - em_start_serialized(ifp); + em_start(ifp); } break; } - lwkt_serialize_exit(&adapter->serializer); } #endif /* DEVICE_POLLING */ @@ -991,6 +1024,8 @@ em_intr(void *arg) ifp = &adapter->interface_data.ac_if; + ASSERT_SERIALIZED(ifp->if_serializer); + reg_icr = E1000_READ_REG(&adapter->hw, ICR); if (!reg_icr) return; @@ -1015,7 +1050,7 @@ em_intr(void *arg) } if ((ifp->if_flags & IFF_RUNNING) && !ifq_is_empty(&ifp->if_snd)) - em_start_serialized(ifp); + em_start(ifp); } /********************************************************************* @@ -1033,6 +1068,8 @@ em_media_status(struct ifnet *ifp, struct ifmediareq *ifmr) INIT_DEBUGOUT("em_media_status: begin"); + ASSERT_SERIALIZED(ifp->if_serializer); + em_check_for_link(&adapter->hw); if (E1000_READ_REG(&adapter->hw, STATUS) & E1000_STATUS_LU) { if (adapter->link_active == 0) { @@ -1097,7 +1134,7 @@ em_media_change(struct ifnet *ifp) if (IFM_TYPE(ifm->ifm_media) != IFM_ETHER) return(EINVAL); - lwkt_serialize_enter(&adapter->serializer); + ASSERT_SERIALIZED(ifp->if_serializer); switch (IFM_SUBTYPE(ifm->ifm_media)) { case IFM_AUTO: @@ -1134,9 +1171,8 @@ em_media_change(struct ifnet *ifp) */ adapter->hw.phy_reset_disable = FALSE; - em_init_serialized(adapter); + em_init(adapter); - lwkt_serialize_exit(&adapter->serializer); return(0); } @@ -1338,9 +1374,9 @@ em_82547_move_tail(void *arg) { struct adapter *adapter = arg; - lwkt_serialize_enter(&adapter->serializer); + lwkt_serialize_enter(adapter->interface_data.ac_if.if_serializer); em_82547_move_tail_serialized(arg); - lwkt_serialize_exit(&adapter->serializer); + lwkt_serialize_exit(adapter->interface_data.ac_if.if_serializer); } static void @@ -1557,7 +1593,7 @@ em_local_timer(void *arg) struct adapter *adapter = arg; ifp = &adapter->interface_data.ac_if; - lwkt_serialize_enter(&adapter->serializer); + lwkt_serialize_enter(ifp->if_serializer); em_check_for_link(&adapter->hw); em_print_link_status(adapter); @@ -1568,7 +1604,7 @@ em_local_timer(void *arg) callout_reset(&adapter->timer, hz, em_local_timer, adapter); - lwkt_serialize_exit(&adapter->serializer); + lwkt_serialize_exit(ifp->if_serializer); } static void @@ -1772,7 +1808,7 @@ em_setup_interface(device_t dev, struct adapter *adapter) ifp->if_capenable = ifp->if_capabilities; - ether_ifattach(ifp, adapter->hw.mac_addr); + ether_ifattach(ifp, adapter->hw.mac_addr, NULL); /* * Tell the upper layer(s) we support long frames. @@ -2646,9 +2682,7 @@ em_process_receive_interrupts(struct adapter *adapter, int count) (current_desc->special & E1000_RXD_SPC_VLAN_MASK)); } else { - /* lwkt_serialize_exit() */ - (*ifp->if_input)(ifp, adapter->fmp); - /* lwkt_serialize_enter() */ + ifp->if_input(ifp, adapter->fmp); } adapter->fmp = NULL; adapter->lmp = NULL; @@ -2749,7 +2783,7 @@ em_enable_intr(struct adapter *adapter) struct ifnet *ifp = &adapter->interface_data.ac_if; if ((ifp->if_flags & IFF_POLLING) == 0) { - lwkt_serialize_handler_enable(&adapter->serializer); + lwkt_serialize_handler_enable(ifp->if_serializer); E1000_WRITE_REG(&adapter->hw, IMS, (IMS_ENABLE_MASK)); } } @@ -2772,7 +2806,7 @@ em_disable_intr(struct adapter *adapter) E1000_WRITE_REG(&adapter->hw, IMC, 0xffffffff); } - lwkt_serialize_handler_disable(&adapter->serializer); + lwkt_serialize_handler_disable(adapter->interface_data.ac_if.if_serializer); } static int @@ -3137,7 +3171,7 @@ em_sysctl_int_delay(SYSCTL_HANDLER_ARGS) info->value = usecs; ticks = E1000_USECS_TO_TICKS(usecs); - lwkt_serialize_enter(&adapter->serializer); + lwkt_serialize_enter(adapter->interface_data.ac_if.if_serializer); regval = E1000_READ_OFFSET(&adapter->hw, info->offset); regval = (regval & ~0xffff) | (ticks & 0xffff); /* Handle a few special cases. */ @@ -3157,7 +3191,7 @@ em_sysctl_int_delay(SYSCTL_HANDLER_ARGS) break; } E1000_WRITE_OFFSET(&adapter->hw, info->offset, regval); - lwkt_serialize_exit(&adapter->serializer); + lwkt_serialize_exit(adapter->interface_data.ac_if.if_serializer); return(0); } @@ -3194,15 +3228,15 @@ em_sysctl_int_throttle(SYSCTL_HANDLER_ARGS) * recalculate sysctl value assignment to get exact frequency. */ throttle = 1000000000 / 256 / throttle; - lwkt_serialize_enter(&adapter->serializer); + lwkt_serialize_enter(adapter->interface_data.ac_if.if_serializer); em_int_throttle_ceil = 1000000000 / 256 / throttle; E1000_WRITE_REG(&adapter->hw, ITR, throttle); - lwkt_serialize_exit(&adapter->serializer); + lwkt_serialize_exit(adapter->interface_data.ac_if.if_serializer); } else { - lwkt_serialize_enter(&adapter->serializer); + lwkt_serialize_enter(adapter->interface_data.ac_if.if_serializer); em_int_throttle_ceil = 0; E1000_WRITE_REG(&adapter->hw, ITR, 0); - lwkt_serialize_exit(&adapter->serializer); + lwkt_serialize_exit(adapter->interface_data.ac_if.if_serializer); } device_printf(adapter->dev, "Interrupt moderation set to %d/sec\n", em_int_throttle_ceil); diff --git a/sys/dev/netif/em/if_em.h b/sys/dev/netif/em/if_em.h index 6e208817c1..1a660f13bd 100644 --- a/sys/dev/netif/em/if_em.h +++ b/sys/dev/netif/em/if_em.h @@ -32,7 +32,7 @@ POSSIBILITY OF SUCH DAMAGE. ***************************************************************************/ /*$FreeBSD: src/sys/dev/em/if_em.h,v 1.1.2.13 2003/06/09 21:43:41 pdeuskar Exp $*/ -/*$DragonFly: src/sys/dev/netif/em/if_em.h,v 1.12 2005/11/08 12:48:18 sephe Exp $*/ +/*$DragonFly: src/sys/dev/netif/em/if_em.h,v 1.13 2005/11/28 17:13:42 dillon Exp $*/ #ifndef _EM_H_DEFINED_ #define _EM_H_DEFINED_ @@ -334,7 +334,6 @@ struct adapter { struct em_hw hw; /* Operating-system-specific structures */ - struct lwkt_serialize serializer; struct em_osdep osdep; struct device *dev; struct resource *res_memory; diff --git a/sys/dev/netif/ep/if_ep.c b/sys/dev/netif/ep/if_ep.c index b6b1cd3372..722aaf1901 100644 --- a/sys/dev/netif/ep/if_ep.c +++ b/sys/dev/netif/ep/if_ep.c @@ -39,7 +39,7 @@ /* * $FreeBSD: src/sys/dev/ep/if_ep.c,v 1.95.2.3 2002/03/06 07:26:35 imp Exp $ - * $DragonFly: src/sys/dev/netif/ep/if_ep.c,v 1.21 2005/11/22 00:24:29 dillon Exp $ + * $DragonFly: src/sys/dev/netif/ep/if_ep.c,v 1.22 2005/11/28 17:13:42 dillon Exp $ * * Promiscuous mode added and interrupt logic slightly changed * to reduce the number of adapter failures. Transceiver select @@ -316,7 +316,7 @@ ep_attach(sc) ep_ifmedia_upd(ifp); } - ether_ifattach(ifp, ether_addr); + ether_ifattach(ifp, ether_addr, NULL); #ifdef EP_LOCAL_STATS sc->rx_no_first = sc->rx_no_mbuf = sc->rx_bpf_disc = @@ -748,7 +748,7 @@ read_again: top->m_pkthdr.rcvif = &sc->arpcom.ac_if; top->m_pkthdr.len = sc->cur_len; - (*ifp->if_input)(ifp, top); + ifp->if_input(ifp, top); sc->top = 0; while (inw(BASE + EP_STATUS) & S_COMMAND_IN_PROGRESS); outw(BASE + EP_COMMAND, SET_RX_EARLY_THRESH | RX_INIT_EARLY_THRESH); diff --git a/sys/dev/netif/ep/if_ep_eisa.c b/sys/dev/netif/ep/if_ep_eisa.c index 1facc46cbf..4d2596071c 100644 --- a/sys/dev/netif/ep/if_ep_eisa.c +++ b/sys/dev/netif/ep/if_ep_eisa.c @@ -20,7 +20,7 @@ * are met. * * $FreeBSD: src/sys/dev/ep/if_ep_eisa.c,v 1.18 2000/01/14 07:14:00 peter Exp $ - * $DragonFly: src/sys/dev/netif/ep/if_ep_eisa.c,v 1.10 2005/10/12 17:35:51 dillon Exp $ + * $DragonFly: src/sys/dev/netif/ep/if_ep_eisa.c,v 1.11 2005/11/28 17:13:42 dillon Exp $ */ #include @@ -231,8 +231,10 @@ ep_eisa_attach(device_t dev) goto bad; } - if ((error = bus_setup_intr(dev, sc->irq, 0, ep_intr, - sc, &sc->ep_intrhand, NULL))) { + error = bus_setup_intr(dev, sc->irq, INTR_NETSAFE, + ep_intr, sc, &sc->ep_intrhand, + sc->arpcom.ac_if.if_serializer); + if (error) { device_printf(dev, "bus_setup_intr() failed! (%d)\n", error); goto bad; } diff --git a/sys/dev/netif/ep/if_ep_isa.c b/sys/dev/netif/ep/if_ep_isa.c index efad310a43..040ec9b7c8 100644 --- a/sys/dev/netif/ep/if_ep_isa.c +++ b/sys/dev/netif/ep/if_ep_isa.c @@ -28,7 +28,7 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD: src/sys/dev/ep/if_ep_isa.c,v 1.8.2.1 2000/12/16 03:47:57 nyan Exp $ - * $DragonFly: src/sys/dev/netif/ep/if_ep_isa.c,v 1.9 2005/10/30 04:41:15 dillon Exp $ + * $DragonFly: src/sys/dev/netif/ep/if_ep_isa.c,v 1.10 2005/11/28 17:13:42 dillon Exp $ */ #include @@ -327,8 +327,10 @@ ep_isa_attach (device_t dev) goto bad; } - if ((error = bus_setup_intr(dev, sc->irq, 0, ep_intr, - sc, &sc->ep_intrhand, NULL))) { + error = bus_setup_intr(dev, sc->irq, INTR_NETSAFE, ep_intr, + sc, &sc->ep_intrhand, + sc->arpcom.ac_if.if_serializer); + if (error) { device_printf(dev, "bus_setup_intr() failed! (%d)\n", error); goto bad; } diff --git a/sys/dev/netif/ep/if_ep_pccard.c b/sys/dev/netif/ep/if_ep_pccard.c index a8ac23d4cc..79121b6d7e 100644 --- a/sys/dev/netif/ep/if_ep_pccard.c +++ b/sys/dev/netif/ep/if_ep_pccard.c @@ -28,7 +28,7 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD: src/sys/dev/ep/if_ep_pccard.c,v 1.12.2.2 2000/08/08 23:55:02 peter Exp $ - * $DragonFly: src/sys/dev/netif/ep/if_ep_pccard.c,v 1.8 2005/10/12 17:35:51 dillon Exp $ + * $DragonFly: src/sys/dev/netif/ep/if_ep_pccard.c,v 1.9 2005/11/28 17:13:42 dillon Exp $ */ /* @@ -212,8 +212,10 @@ ep_pccard_attach(device_t dev) goto bad; } - if ((error = bus_setup_intr(dev, sc->irq, 0, ep_intr, - sc, &sc->ep_intrhand, NULL))) { + error = bus_setup_intr(dev, sc->irq, INTR_NETSAFE, ep_intr, + sc, &sc->ep_intrhand, + sc->arpcom.ac_if.if_serializer); + if (error) { device_printf(dev, "bus_setup_intr() failed! (%d)\n", error); goto bad; } diff --git a/sys/dev/netif/ex/if_ex.c b/sys/dev/netif/ex/if_ex.c index bc2b348f06..3514d74483 100644 --- a/sys/dev/netif/ex/if_ex.c +++ b/sys/dev/netif/ex/if_ex.c @@ -25,7 +25,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/dev/ex/if_ex.c,v 1.26.2.3 2001/03/05 05:33:20 imp Exp $ - * $DragonFly: src/sys/dev/netif/ex/if_ex.c,v 1.20 2005/11/22 00:24:30 dillon Exp $ + * $DragonFly: src/sys/dev/netif/ex/if_ex.c,v 1.21 2005/11/28 17:13:42 dillon Exp $ * * MAINTAINER: Matthew N. Dodd * @@ -49,6 +49,7 @@ #include #include +#include #include #include @@ -268,7 +269,7 @@ ex_attach(device_t dev) /* * Attach the interface. */ - ether_ifattach(ifp, sc->arpcom.ac_enaddr); + ether_ifattach(ifp, sc->arpcom.ac_enaddr, NULL); return(0); } @@ -284,8 +285,6 @@ ex_init(void *xsc) DODEBUG(Start_End, printf("ex_init%d: start\n", ifp->if_dunit);); - crit_enter(); - ifp->if_timer = 0; /* @@ -358,8 +357,6 @@ ex_init(void *xsc) ex_start(ifp); - crit_exit(); - DODEBUG(Start_End, printf("ex_init%d: finish\n", ifp->if_dunit);); } @@ -376,8 +373,6 @@ ex_start(struct ifnet *ifp) DODEBUG(Start_End, printf("ex_start%d: start\n", unit);); - crit_enter(); - /* * Main loop: send outgoing packets to network card until there are no * more packets left, or the card cannot accept any more yet. @@ -536,9 +531,6 @@ ex_start(struct ifnet *ifp) DODEBUG(Status, printf("OACTIVE start\n");); } } - - crit_exit(); - DODEBUG(Start_End, printf("ex_start%d: finish\n", unit);); } @@ -742,7 +734,7 @@ ex_rx_intr(struct ex_softc *sc) m->m_len = MLEN; } } - (*ifp->if_input)(ifp, ipkt); + ifp->if_input(ifp, ipkt); ifp->if_ipackets++; } } else { @@ -772,8 +764,6 @@ ex_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data, struct ucred *cr) DODEBUG(Start_End, printf("ex_ioctl%d: start ", ifp->if_dunit);); - crit_enter(); - switch(cmd) { case SIOCSIFFLAGS: DODEBUG(Start_End, printf("SIOCSIFFLAGS");); @@ -810,8 +800,6 @@ ex_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data, struct ucred *cr) break; } - crit_exit(); - DODEBUG(Start_End, printf("\nex_ioctl%d: finish\n", ifp->if_dunit);); return(error); @@ -822,14 +810,10 @@ static void ex_reset(struct ex_softc *sc) { DODEBUG(Start_End, printf("ex_reset%d: start\n", unit);); - - crit_enter(); ex_stop(sc); ex_init(sc); - crit_exit(); - DODEBUG(Start_End, printf("ex_reset%d: finish\n", unit);); } diff --git a/sys/dev/netif/ex/if_ex_isa.c b/sys/dev/netif/ex/if_ex_isa.c index 86fc2f819f..130ad9d8d2 100644 --- a/sys/dev/netif/ex/if_ex_isa.c +++ b/sys/dev/netif/ex/if_ex_isa.c @@ -24,7 +24,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/dev/ex/if_ex_isa.c,v 1.3.2.1 2001/03/05 05:33:20 imp Exp $ - * $DragonFly: src/sys/dev/netif/ex/if_ex_isa.c,v 1.10 2005/10/30 04:41:15 dillon Exp $ + * $DragonFly: src/sys/dev/netif/ex/if_ex_isa.c,v 1.11 2005/11/28 17:13:42 dillon Exp $ */ #include @@ -34,6 +34,7 @@ #include #include +#include #include #include @@ -312,9 +313,9 @@ ex_isa_attach(device_t dev) goto bad; } - error = bus_setup_intr(dev, sc->irq, 0, - ex_intr, (void *)sc, - &sc->ih, NULL); + error = bus_setup_intr(dev, sc->irq, INTR_NETSAFE, + ex_intr, (void *)sc, &sc->ih, + sc->arpcom.ac_if.if_serializer); if (error) { device_printf(dev, "bus_setup_intr() failed!\n"); goto bad; diff --git a/sys/dev/netif/ex/if_ex_pccard.c b/sys/dev/netif/ex/if_ex_pccard.c index c8be613203..563b022ec0 100644 --- a/sys/dev/netif/ex/if_ex_pccard.c +++ b/sys/dev/netif/ex/if_ex_pccard.c @@ -24,7 +24,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/dev/ex/if_ex_pccard.c,v 1.2.2.1 2001/03/05 05:33:20 imp Exp $ - * $DragonFly: src/sys/dev/netif/ex/if_ex_pccard.c,v 1.9 2005/10/12 17:35:51 dillon Exp $ + * $DragonFly: src/sys/dev/netif/ex/if_ex_pccard.c,v 1.10 2005/11/28 17:13:42 dillon Exp $ */ #include @@ -34,6 +34,7 @@ #include #include +#include #include #include @@ -162,8 +163,9 @@ ex_pccard_attach(device_t dev) goto bad; } - error = bus_setup_intr(dev, sc->irq, 0, - ex_intr, (void *)sc, &sc->ih, NULL); + error = bus_setup_intr(dev, sc->irq, INTR_NETSAFE, + ex_intr, (void *)sc, &sc->ih, + sc->arpcom.ac_if.if_serializer); if (error) { device_printf(dev, "bus_setup_intr() failed!\n"); goto bad; @@ -181,9 +183,11 @@ ex_pccard_detach(device_t dev) struct ex_softc *sc = device_get_softc(dev); struct ifnet *ifp = &sc->arpcom.ac_if; + lwkt_serialize_enter(sc->arpcom.ac_if.if_serializer); ex_stop(sc); ifp->if_flags &= ~IFF_RUNNING; if_detach(ifp); ex_release_resources(dev); + lwkt_serialize_exit(sc->arpcom.ac_if.if_serializer); return (0); } diff --git a/sys/dev/netif/fe/if_fe.c b/sys/dev/netif/fe/if_fe.c index 47f2605bae..7d1d59acdf 100644 --- a/sys/dev/netif/fe/if_fe.c +++ b/sys/dev/netif/fe/if_fe.c @@ -22,7 +22,7 @@ /* * $FreeBSD: src/sys/dev/fe/if_fe.c,v 1.65.2.1 2000/09/22 10:01:47 nyan Exp $ - * $DragonFly: src/sys/dev/netif/fe/if_fe.c,v 1.22 2005/11/22 00:24:31 dillon Exp $ + * $DragonFly: src/sys/dev/netif/fe/if_fe.c,v 1.23 2005/11/28 17:13:42 dillon Exp $ * * Device driver for Fujitsu MB86960A/MB86965A based Ethernet cards. * Contributed by M. Sekiguchi. @@ -744,13 +744,6 @@ fe_attach (device_t dev) int flags = device_get_flags(dev); int b, error; - error = bus_setup_intr(dev, sc->irq_res, 0, - fe_intr, sc, &sc->irq_handle, NULL); - if (error) { - fe_release_resource(dev); - return ENXIO; - } - /* * Initialize ifnet structure */ @@ -819,8 +812,18 @@ fe_attach (device_t dev) #endif /* Attach and stop the interface. */ - ether_ifattach(&sc->sc_if, sc->sc_enaddr); + ether_ifattach(&sc->sc_if, sc->sc_enaddr, NULL); fe_stop(sc); + + error = bus_setup_intr(dev, sc->irq_res, INTR_NETSAFE, + fe_intr, sc, &sc->irq_handle, + sc->sc_if.if_serializer); + if (error) { + if_detach(&sc->sc_if); + fe_release_resource(dev); + return ENXIO; + } + /* Print additional info when attached. */ device_printf(dev, "type %s%s\n", sc->typestr, @@ -943,8 +946,6 @@ fe_reset (struct fe_softc *sc) void fe_stop (struct fe_softc *sc) { - crit_enter(); - /* Disable interrupts. */ fe_outb(sc, FE_DLCR2, 0x00); fe_outb(sc, FE_DLCR3, 0x00); @@ -976,8 +977,6 @@ fe_stop (struct fe_softc *sc) /* Call a device-specific hook. */ if (sc->stop) sc->stop(sc); - - crit_exit(); } /* @@ -1007,8 +1006,6 @@ fe_init (void * xsc) struct fe_softc *sc = xsc; /* Start initializing 86960. */ - crit_enter(); - /* Call a hook before we start initializing the chip. */ if (sc->init) sc->init(sc); @@ -1116,8 +1113,6 @@ fe_init (void * xsc) delay. */ fe_start(&sc->sc_if); #endif - - crit_exit(); } /* @@ -1752,8 +1747,6 @@ fe_ioctl (struct ifnet * ifp, u_long command, caddr_t data, struct ucred *cr) struct ifreq *ifr = (struct ifreq *)data; int error = 0; - crit_enter(); - switch (command) { case SIOCSIFFLAGS: /* @@ -1797,9 +1790,6 @@ fe_ioctl (struct ifnet * ifp, u_long command, caddr_t data, struct ucred *cr) error = ether_ioctl(ifp, command, data); break; } - - crit_exit(); - return (error); } @@ -1885,7 +1875,7 @@ fe_get_packet (struct fe_softc * sc, u_short len) } /* Feed the packet to upper layer. */ - (*sc->sc_if.if_input)(&sc->sc_if, m); + sc->sc_if.if_input(&sc->sc_if, m); return 0; } diff --git a/sys/dev/netif/fe/if_fe_pccard.c b/sys/dev/netif/fe/if_fe_pccard.c index b0d4a373f7..79f709e7f1 100644 --- a/sys/dev/netif/fe/if_fe_pccard.c +++ b/sys/dev/netif/fe/if_fe_pccard.c @@ -20,7 +20,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/dev/fe/if_fe_pccard.c,v 1.2.2.1 2000/09/22 10:01:47 nyan Exp $ - * $DragonFly: src/sys/dev/netif/fe/if_fe_pccard.c,v 1.7 2004/03/14 15:36:50 joerg Exp $ + * $DragonFly: src/sys/dev/netif/fe/if_fe_pccard.c,v 1.8 2005/11/28 17:13:42 dillon Exp $ */ #include "opt_fe.h" @@ -186,10 +186,12 @@ fe_pccard_detach(device_t dev) struct fe_softc *sc = device_get_softc(dev); struct ifnet *ifp = &sc->arpcom.ac_if; + lwkt_serialize_enter(ifp->if_serializer); fe_stop(sc); ether_ifdetach(ifp); bus_teardown_intr(dev, sc->irq_res, sc->irq_handle); fe_release_resource(dev); + lwkt_serialize_exit(ifp->if_serializer); return 0; } diff --git a/sys/dev/netif/fea/if_fea.c b/sys/dev/netif/fea/if_fea.c index d517872f62..65ffb7bbba 100644 --- a/sys/dev/netif/fea/if_fea.c +++ b/sys/dev/netif/fea/if_fea.c @@ -22,7 +22,7 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD: src/sys/dev/pdq/if_fea.c,v 1.19 2000/01/14 07:14:03 peter Exp $ - * $DragonFly: src/sys/dev/netif/fea/Attic/if_fea.c,v 1.9 2005/10/12 17:35:52 dillon Exp $ + * $DragonFly: src/sys/dev/netif/fea/Attic/if_fea.c,v 1.10 2005/11/28 17:13:42 dillon Exp $ */ /* @@ -35,6 +35,7 @@ #include #include #include +#include #include #include @@ -217,12 +218,16 @@ pdq_eisa_attach (dev) goto bad; } - if (bus_setup_intr(dev, irq, 0, pdq_eisa_intr, dev, &ih, NULL)) { + pdq_ifattach(sc, NULL); + + if (bus_setup_intr(dev, irq, INTR_NETSAFE, + pdq_eisa_intr, dev, &ih, + sc->sc_if.if_serializer) + ) { goto bad; } bcopy((caddr_t) sc->sc_pdq->pdq_hwaddr.lanaddr_bytes, sc->sc_ac.ac_enaddr, 6); - pdq_ifattach(sc, NULL); return (0); @@ -242,8 +247,10 @@ pdq_eisa_shutdown(dev) device_t dev; { pdq_softc_t *sc = device_get_softc(dev); - + + lwkt_serialize_enter(sc->sc_if.if_serializer); pdq_hwreset(sc->sc_pdq); + lwkt_serialize_exit(sc->sc_if.if_serializer); return (0); } diff --git a/sys/dev/netif/fpa/if_fpa.c b/sys/dev/netif/fpa/if_fpa.c index 0a09ac96e3..b3dfa76d31 100644 --- a/sys/dev/netif/fpa/if_fpa.c +++ b/sys/dev/netif/fpa/if_fpa.c @@ -22,7 +22,7 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD: src/sys/dev/pdq/if_fpa.c,v 1.13 1999/08/28 00:50:50 peter Exp $ - * $DragonFly: src/sys/dev/netif/fpa/Attic/if_fpa.c,v 1.11 2005/11/02 08:33:15 dillon Exp $ + * $DragonFly: src/sys/dev/netif/fpa/Attic/if_fpa.c,v 1.12 2005/11/28 17:13:42 dillon Exp $ */ /* @@ -37,6 +37,7 @@ #if defined(__bsdi__) || defined(__NetBSD__) #include #endif +#include #include @@ -111,7 +112,11 @@ static void pdq_pci_ifintr( void *arg) { - (void) pdq_interrupt(((pdq_softc_t *) arg)->sc_pdq); + pdq_softc_t *sc = arg; + + lwkt_serialize_enter(sc->sc_if.if_serializer); + pdq_interrupt(sc->sc_pdq); + lwkt_serialize_exit(sc->sc_if.if_serializer); } #else static int @@ -198,7 +203,9 @@ pdq_pci_shutdown( void *sc, int howto) { + lwkt_serialize_enter(sc->sc_if.if_serializer); pdq_hwreset(((pdq_softc_t *)sc)->sc_pdq); + lwkt_serialize_exit(sc->sc_if.if_serializer); } static u_long pdq_pci_count; diff --git a/sys/dev/netif/fwe/if_fwe.c b/sys/dev/netif/fwe/if_fwe.c index 3a74322e1a..103c6609fb 100644 --- a/sys/dev/netif/fwe/if_fwe.c +++ b/sys/dev/netif/fwe/if_fwe.c @@ -32,7 +32,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/dev/firewire/if_fwe.c,v 1.27 2004/01/08 14:58:09 simokawa Exp $ - * $DragonFly: src/sys/dev/netif/fwe/if_fwe.c,v 1.22 2005/11/22 00:24:32 dillon Exp $ + * $DragonFly: src/sys/dev/netif/fwe/if_fwe.c,v 1.23 2005/11/28 17:13:42 dillon Exp $ */ #include "opt_inet.h" @@ -199,7 +199,7 @@ fwe_attach(device_t dev) ifq_set_maxlen(&ifp->if_snd, TX_MAX_QUEUE); ifq_set_ready(&ifp->if_snd); - ether_ifattach(ifp, eaddr); + ether_ifattach(ifp, eaddr, NULL); /* Tell the upper layer(s) we support long frames. */ ifp->if_data.ifi_hdrlen = sizeof(struct ether_vlan_header); @@ -253,12 +253,10 @@ fwe_detach(device_t dev) { struct fwe_softc *fwe = device_get_softc(dev); - crit_enter(); - + lwkt_serialize_enter(fwe->fwe_if.if_serializer); fwe_stop(fwe); ether_ifdetach(&fwe->fwe_if); - - crit_exit(); + lwkt_serialize_exit(fwe->fwe_if.if_serializer); return 0; } @@ -359,8 +357,6 @@ fwe_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data, struct ucred *cr) struct ifstat *ifs = NULL; int error = 0, len; - crit_enter(); - switch (cmd) { case SIOCSIFFLAGS: if (ifp->if_flags & IFF_UP) { @@ -390,9 +386,6 @@ fwe_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data, struct ucred *cr) error = ether_ioctl(ifp, cmd, data); break; } - - crit_exit(); - return (error); } @@ -404,6 +397,7 @@ fwe_output_callback(struct fw_xfer *xfer) fwe = (struct fwe_softc *)xfer->sc; ifp = &fwe->fwe_if; + lwkt_serialize_enter(ifp->if_serializer); /* XXX error check */ FWEDEBUG(ifp, "resp = %d\n", xfer->resp); if (xfer->resp != 0) @@ -412,15 +406,12 @@ fwe_output_callback(struct fw_xfer *xfer) m_freem(xfer->mbuf); fw_xfer_unload(xfer); - crit_enter(); - STAILQ_INSERT_TAIL(&fwe->xferlist, xfer, link); - crit_exit(); - /* for queue full */ if (!ifq_is_empty(&ifp->if_snd)) fwe_start(ifp); + lwkt_serialize_exit(ifp->if_serializer); } static void @@ -430,8 +421,6 @@ fwe_start(struct ifnet *ifp) FWEDEBUG(ifp, "starting\n"); - crit_enter(); - if (fwe->dma_ch < 0) { FWEDEBUG(ifp, "not ready\n"); @@ -444,8 +433,6 @@ fwe_start(struct ifnet *ifp) ifp->if_flags &= ~IFF_OACTIVE; } - - crit_exit(); } #define HDR_LEN 4 @@ -515,6 +502,7 @@ fwe_as_input(struct fw_xferq *xferq) fwe = (struct fwe_softc *)xferq->sc; ifp = &fwe->fwe_if; + lwkt_serialize_enter(ifp->if_serializer); while ((sxfer = STAILQ_FIRST(&xferq->stvalid)) != NULL) { STAILQ_REMOVE_HEAD(&xferq->stvalid, link); fp = mtod(sxfer->mbuf, struct fw_pkt *); @@ -558,11 +546,12 @@ fwe_as_input(struct fw_xferq *xferq) c[20], c[21], c[22], c[23] ); #endif - (*ifp->if_input)(ifp, m); + ifp->if_input(ifp, m); ifp->if_ipackets ++; } if (STAILQ_FIRST(&xferq->stfree) != NULL) fwe->fd.fc->irx_enable(fwe->fd.fc, fwe->dma_ch); + lwkt_serialize_exit(ifp->if_serializer); } diff --git a/sys/dev/netif/fxp/if_fxp.c b/sys/dev/netif/fxp/if_fxp.c index 1e5b36491e..dd5568e816 100644 --- a/sys/dev/netif/fxp/if_fxp.c +++ b/sys/dev/netif/fxp/if_fxp.c @@ -26,7 +26,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/dev/fxp/if_fxp.c,v 1.110.2.30 2003/06/12 16:47:05 mux Exp $ - * $DragonFly: src/sys/dev/netif/fxp/if_fxp.c,v 1.38 2005/11/22 00:24:32 dillon Exp $ + * $DragonFly: src/sys/dev/netif/fxp/if_fxp.c,v 1.39 2005/11/28 17:13:42 dillon Exp $ */ /* @@ -658,7 +658,7 @@ fxp_attach(device_t dev) /* * Attach the interface. */ - ether_ifattach(ifp, sc->arpcom.ac_enaddr); + ether_ifattach(ifp, sc->arpcom.ac_enaddr, NULL); /* * Tell the upper layer(s) we support long frames. @@ -672,8 +672,9 @@ fxp_attach(device_t dev) ifq_set_maxlen(&ifp->if_snd, FXP_NTXCB - 1); ifq_set_ready(&ifp->if_snd); - error = bus_setup_intr(dev, sc->irq, 0, - fxp_intr, sc, &sc->ih, NULL); + error = bus_setup_intr(dev, sc->irq, INTR_NETSAFE, + fxp_intr, sc, &sc->ih, + ifp->if_serializer); if (error) { ether_ifdetach(ifp); if (sc->flags & FXP_FLAG_SERIAL_MEDIA) @@ -732,7 +733,7 @@ fxp_detach(device_t dev) /* disable interrupts */ CSR_WRITE_1(sc, FXP_CSR_SCB_INTRCNTL, FXP_SCB_INTR_DISABLE); - crit_enter(); + lwkt_serialize_enter(sc->arpcom.ac_if.if_serializer); /* * Stop DMA and drop transmit queue. @@ -753,10 +754,9 @@ fxp_detach(device_t dev) if (sc->ih) bus_teardown_intr(dev, sc->irq, sc->ih); - crit_exit(); - /* Release our allocated resources. */ fxp_release(dev); + lwkt_serialize_exit(sc->arpcom.ac_if.if_serializer); return (0); } @@ -789,7 +789,7 @@ fxp_suspend(device_t dev) struct fxp_softc *sc = device_get_softc(dev); int i; - crit_enter(); + lwkt_serialize_enter(sc->arpcom.ac_if.if_serializer); fxp_stop(sc); @@ -802,7 +802,7 @@ fxp_suspend(device_t dev) sc->suspended = 1; - crit_exit(); + lwkt_serialize_exit(sc->arpcom.ac_if.if_serializer); return (0); } @@ -818,7 +818,7 @@ fxp_resume(device_t dev) struct ifnet *ifp = &sc->arpcom.ac_if; int i; - crit_enter(); + lwkt_serialize_enter(sc->arpcom.ac_if.if_serializer); fxp_powerstate_d0(dev); @@ -843,7 +843,7 @@ fxp_resume(device_t dev) sc->suspended = 0; - crit_exit(); + lwkt_serialize_exit(sc->arpcom.ac_if.if_serializer); return (0); } @@ -1348,7 +1348,7 @@ fxp_intr_body(struct fxp_softc *sc, u_int8_t statack, int count) continue; } m->m_pkthdr.len = m->m_len = total_len; - (*ifp->if_input)(ifp, m); + ifp->if_input(ifp, m); } } if (rnr) { @@ -1380,6 +1380,8 @@ fxp_tick(void *xsc) struct fxp_cb_tx *txp; struct mbuf *m; + lwkt_serialize_enter(sc->arpcom.ac_if.if_serializer); + ifp->if_opackets += sp->tx_good; ifp->if_collisions += sp->tx_total_collisions; if (sp->rx_good) { @@ -1406,8 +1408,6 @@ fxp_tick(void *xsc) tx_threshold += 64; } - crit_enter(); - /* * Release any xmit buffers that have completed DMA. This isn't * strictly necessary to do here, but it's advantagous for mbufs @@ -1473,7 +1473,7 @@ fxp_tick(void *xsc) */ callout_reset(&sc->fxp_stat_timer, hz, fxp_tick, sc); - crit_exit(); + lwkt_serialize_exit(sc->arpcom.ac_if.if_serializer); } /* @@ -1560,8 +1560,6 @@ fxp_init(void *xsc) struct fxp_cb_mcs *mcsp; int i, prm; - crit_enter(); - /* * Cancel any pending I/O */ @@ -1800,8 +1798,6 @@ fxp_init(void *xsc) * Start stats updater. */ callout_reset(&sc->fxp_stat_timer, hz, fxp_tick, sc); - - crit_exit(); } static int @@ -1968,8 +1964,6 @@ fxp_ioctl(struct ifnet *ifp, u_long command, caddr_t data, struct ucred *cr) struct mii_data *mii; int error = 0; - crit_enter(); - switch (command) { case SIOCSIFFLAGS: @@ -2028,9 +2022,6 @@ fxp_ioctl(struct ifnet *ifp, u_long command, caddr_t data, struct ucred *cr) error = ether_ioctl(ifp, command, data); break; } - - crit_exit(); - return (error); } diff --git a/sys/dev/netif/gx/if_gx.c b/sys/dev/netif/gx/if_gx.c index 1c08757d24..235f74d511 100644 --- a/sys/dev/netif/gx/if_gx.c +++ b/sys/dev/netif/gx/if_gx.c @@ -27,7 +27,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/dev/gx/if_gx.c,v 1.2.2.3 2001/12/14 19:51:39 jlemon Exp $ - * $DragonFly: src/sys/dev/netif/gx/Attic/if_gx.c,v 1.21 2005/11/22 00:24:32 dillon Exp $ + * $DragonFly: src/sys/dev/netif/gx/Attic/if_gx.c,v 1.22 2005/11/28 17:13:42 dillon Exp $ */ #include @@ -37,8 +37,10 @@ #include #include #include -#include #include +#include + +#include #include #include @@ -368,10 +370,11 @@ gx_attach(device_t dev) /* * Call MI attach routines. */ - ether_ifattach(ifp, gx->arpcom.ac_enaddr); + ether_ifattach(ifp, gx->arpcom.ac_enaddr, NULL); - error = bus_setup_intr(dev, gx->gx_irq, 0, - gx_intr, gx, &gx->gx_intrhand, NULL); + error = bus_setup_intr(dev, gx->gx_irq, INTR_NETSAFE, + gx_intr, gx, &gx->gx_intrhand, + ifp->if_serializer); if (error) { ether_ifdetach(ifp); device_printf(dev, "couldn't setup irq\n"); @@ -395,8 +398,6 @@ gx_init(void *xsc) u_int32_t ctrl; int i, tmp; - crit_enter(); - /* Disable host interrupts, halt chip. */ gx_reset(gx); @@ -547,8 +548,6 @@ printf("66mhz: %s 64bit: %s\n", CSR_READ_4(gx, GX_STATUS) & GX_STAT_PCI66 ? "yes" : "no", CSR_READ_4(gx, GX_STATUS) & GX_STAT_BUS64 ? "yes" : "no"); #endif - - crit_exit(); } /* @@ -571,6 +570,7 @@ gx_detach(device_t dev) struct gx_softc *gx = device_get_softc(dev); struct ifnet *ifp = &gx->arpcom.ac_if; + lwkt_serialize_enter(ifp->if_serializer); if (device_is_attached(dev)) { ether_ifdetach(ifp); gx_reset(gx); @@ -584,8 +584,6 @@ gx_detach(device_t dev) if (gx->gx_intrhand) bus_teardown_intr(gx->gx_dev, gx->gx_irq, gx->gx_intrhand); - crit_exit(); - if (gx->gx_irq) bus_release_resource(gx->gx_dev, SYS_RES_IRQ, 0, gx->gx_irq); if (gx->gx_res) @@ -599,6 +597,7 @@ gx_detach(device_t dev) if (gx->gx_tbimode) ifmedia_removeall(&gx->gx_media); + lwkt_serialize_exit(ifp->if_serializer); return (0); } @@ -862,8 +861,6 @@ gx_miibus_statchg(device_t dev) */ mii = device_get_softc(gx->gx_miibus); - crit_enter(); - reg = CSR_READ_4(gx, GX_CTRL); if (mii->mii_media_active & IFM_FLAG0) reg |= GX_CTRL_RX_FLOWCTRL; @@ -874,8 +871,6 @@ gx_miibus_statchg(device_t dev) else reg &= ~GX_CTRL_TX_FLOWCTRL; CSR_WRITE_4(gx, GX_CTRL, reg); - - crit_exit(); } static int @@ -886,8 +881,6 @@ gx_ioctl(struct ifnet *ifp, u_long command, caddr_t data, struct ucred *cr) struct mii_data *mii; int mask, error = 0; - crit_enter(); - switch (command) { case SIOCSIFMTU: if (ifr->ifr_mtu > GX_MAX_MTU) { @@ -942,9 +935,6 @@ gx_ioctl(struct ifnet *ifp, u_long command, caddr_t data, struct ucred *cr) error = ether_ioctl(ifp, command, data); break; } - - crit_exit(); - return (error); } @@ -1282,7 +1272,7 @@ gx_rxeof(struct gx_softc *gx) if (staterr & GX_RXSTAT_VLAN_PKT) VLAN_INPUT_TAG(m, rx->rx_special); else - (*ifp->if_input)(ifp, m); + ifp->if_input(ifp, m); continue; ierror: @@ -1368,8 +1358,6 @@ gx_intr(void *xsc) struct ifnet *ifp = &gx->arpcom.ac_if; u_int32_t intr; - crit_enter(); - gx->gx_interrupts++; /* Disable host interrupts. */ @@ -1412,8 +1400,6 @@ gx_intr(void *xsc) if (ifp->if_flags & IFF_RUNNING && !ifq_is_empty(&ifp->if_snd)) gx_start(ifp); - - crit_exit(); } /* @@ -1544,8 +1530,6 @@ gx_start(struct ifnet *ifp) struct gx_softc *gx = ifp->if_softc; struct mbuf *m_head; - crit_enter(); - for (;;) { m_head = ifq_poll(&ifp->if_snd); if (m_head == NULL) @@ -1569,6 +1553,4 @@ gx_start(struct ifnet *ifp) */ ifp->if_timer = 5; } - - crit_exit(); } diff --git a/sys/dev/netif/ic/if_ic.c b/sys/dev/netif/ic/if_ic.c index 2d41a82191..9c12d22ebd 100644 --- a/sys/dev/netif/ic/if_ic.c +++ b/sys/dev/netif/ic/if_ic.c @@ -24,7 +24,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/dev/iicbus/if_ic.c,v 1.8 1999/12/29 04:35:39 peter Exp $ - * $DragonFly: src/sys/dev/netif/ic/if_ic.c,v 1.13 2005/06/13 22:27:52 joerg Exp $ + * $DragonFly: src/sys/dev/netif/ic/if_ic.c,v 1.14 2005/11/28 17:13:42 dillon Exp $ */ /* @@ -147,7 +147,7 @@ icattach(device_t dev) ifp->if_addrlen = 0; ifq_set_maxlen(&ifp->if_snd, IFQ_MAXLEN); - if_attach(ifp); + if_attach(ifp, NULL); bpfattach(ifp, DLT_NULL, ICHDRLEN); diff --git a/sys/dev/netif/ie/if_ie.c b/sys/dev/netif/ie/if_ie.c index f0fa5ccd60..b5ef64e1eb 100644 --- a/sys/dev/netif/ie/if_ie.c +++ b/sys/dev/netif/ie/if_ie.c @@ -48,7 +48,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/dev/ie/if_ie.c,v 1.72.2.4 2003/03/27 21:01:49 mdodd Exp $ - * $DragonFly: src/sys/dev/netif/ie/if_ie.c,v 1.25 2005/11/22 00:24:32 dillon Exp $ + * $DragonFly: src/sys/dev/netif/ie/if_ie.c,v 1.26 2005/11/28 17:13:42 dillon Exp $ */ /* @@ -204,8 +204,7 @@ static int ierint(int unit, struct ie_softc * ie); static int ietint(int unit, struct ie_softc * ie); static int iernr(int unit, struct ie_softc * ie); static void start_receiver(int unit); -static __inline int ieget(int, struct ie_softc *, struct mbuf **, - struct ether_header *); +static __inline int ieget(int, struct ie_softc *, struct mbuf **); static v_caddr_t setup_rfa(v_caddr_t ptr, struct ie_softc * ie); static int mc_setup(int, v_caddr_t, volatile struct ie_sys_ctl_block *); static void ie_mc_reset(int unit); @@ -831,7 +830,7 @@ ieattach(struct isa_device *dvp) EVENTHANDLER_REGISTER(shutdown_post_sync, ee16_shutdown, ie, SHUTDOWN_PRI_DEFAULT); - ether_ifattach(ifp, ie->arpcom.ac_enaddr); + ether_ifattach(ifp, ie->arpcom.ac_enaddr, NULL); return (1); } @@ -845,6 +844,8 @@ ieintr(void *arg) struct ie_softc *ie = &ie_softc[unit]; u_short status; + lwkt_serialize_enter(ie->arpcom.ac_if.if_serializer); + /* Clear the interrupt latch on the 3C507. */ if (ie->hard_type == IE_3C507 && (inb(PORT + IE507_CTRL) & EL_CTRL_INTL)) @@ -907,6 +908,7 @@ loop: if (ie->hard_type == IE_EE16) outb(PORT + IEE16_IRQ, ie->irq_encoded | IEE16_IRQ_ENABLE); + lwkt_serialize_exit(ie->arpcom.ac_if.if_serializer); } /* @@ -1158,9 +1160,10 @@ ie_packet_len(int unit, struct ie_softc * ie) * operation considerably. (Provided that it works, of course.) */ static __inline int -ieget(int unit, struct ie_softc *ie, struct mbuf **mp, struct ether_header *ehp) +ieget(int unit, struct ie_softc *ie, struct mbuf **mp) { struct mbuf *m, *top, **mymp; + struct ether_header eh; int i; int offset; int totlen, resid; @@ -1176,7 +1179,7 @@ ieget(int unit, struct ie_softc *ie, struct mbuf **mp, struct ether_header *ehp) /* * Snarf the Ethernet header. */ - bcopy((v_caddr_t) ie->cbuffs[i], (caddr_t) ehp, sizeof *ehp); + bcopy((v_caddr_t) ie->cbuffs[i], (caddr_t) &eh, sizeof eh); /* ignore cast-qual warning here */ /* @@ -1185,14 +1188,14 @@ ieget(int unit, struct ie_softc *ie, struct mbuf **mp, struct ether_header *ehp) * This is only a consideration when FILTER is defined; i.e., when * we are either running BPF or doing multicasting. */ - if (!check_eh(ie, ehp)) { + if (!check_eh(ie, &eh)) { ie_drop_packet_buffer(unit, ie); ie->arpcom.ac_if.if_ierrors--; /* just this case, it's not an * error */ return (-1); } - totlen -= (offset = sizeof *ehp); + offset = 0; MGETHDR(*mp, MB_DONTWAIT, MT_DATA); if (!*mp) { @@ -1200,7 +1203,6 @@ ieget(int unit, struct ie_softc *ie, struct mbuf **mp, struct ether_header *ehp) return (-1); } m = *mp; - m->m_pkthdr.rcvif = &ie->arpcom.ac_if; m->m_len = MHLEN; resid = m->m_pkthdr.len = totlen; top = 0; @@ -1333,8 +1335,7 @@ static void ie_readframe(int unit, struct ie_softc *ie, int num/* frame number to read */) { struct ie_recv_frame_desc rfd; - struct mbuf *m = 0; - struct ether_header eh; + struct mbuf *m = NULL; bcopy((v_caddr_t) (ie->rframes[num]), &rfd, sizeof(struct ie_recv_frame_desc)); @@ -1350,21 +1351,12 @@ ie_readframe(int unit, struct ie_softc *ie, int num/* frame number to read */) ie->rfhead = (ie->rfhead + 1) % ie->nframes; if (rfd.ie_fd_status & IE_FD_OK) { - if (ieget(unit, ie, &m, &eh)) { + if (ieget(unit, ie, &m)) { ie->arpcom.ac_if.if_ierrors++; /* this counts as an * error */ return; } } -#ifdef DEBUG - if (ie_debug & IED_READFRAME) { - printf("ie%d: frame from ether %6D type %x\n", unit, - eh.ether_shost, ":", (unsigned) eh.ether_type); - } - if (ntohs(eh.ether_type) > ETHERTYPE_TRAIL - && ntohs(eh.ether_type) < (ETHERTYPE_TRAIL + ETHERTYPE_NTRAILER)) - printf("received trailer!\n"); -#endif if (!m) return; @@ -1372,7 +1364,7 @@ ie_readframe(int unit, struct ie_softc *ie, int num/* frame number to read */) /* * Finally pass this packet up to higher layers. */ - ether_input(&ie->arpcom.ac_if, &eh, m); + ie->arpcom.ac_if.if_input(&ie->arpcom.ac_if, m); } static void @@ -1497,8 +1489,6 @@ check_ie_present(int unit, caddr_t where, unsigned size) volatile struct ie_sys_ctl_block *scb; u_long realbase; - crit_exit(); - realbase = (uintptr_t) where + size - (1 << 24); scp = (volatile struct ie_sys_conf_ptr *) (uintptr_t) @@ -1530,7 +1520,6 @@ check_ie_present(int unit, caddr_t where, unsigned size) DELAY(100); /* wait a while... */ if (iscp->ie_busy) { - crit_exit(); return (0); } /* @@ -1554,7 +1543,6 @@ check_ie_present(int unit, caddr_t where, unsigned size) DELAY(100); if (iscp->ie_busy) { - crit_exit(); return (0); } ie_softc[unit].iosize = size; @@ -1568,8 +1556,6 @@ check_ie_present(int unit, caddr_t where, unsigned size) */ ie_ack(scb, IE_ST_WHENCE, unit, ie_softc[unit].ie_chan_attn); - crit_exit(); - return (1); } @@ -1732,10 +1718,7 @@ sl_read_ether(int unit, unsigned char addr[6]) static void iereset(int unit) { - crit_enter(); - if (unit >= NIE) { - crit_exit(); return; } printf("ie%d: reset\n", unit); @@ -1759,8 +1742,6 @@ iereset(int unit) ie_softc[unit].arpcom.ac_if.if_flags |= IFF_UP; ieioctl(&ie_softc[unit].arpcom.ac_if, SIOCSIFFLAGS, 0, (struct ucred *)NULL); - - crit_exit(); } /* @@ -1860,14 +1841,10 @@ run_tdr(int unit, volatile struct ie_tdr_cmd *cmd) static void start_receiver(int unit) { - crit_enter(); - ie_softc[unit].scb->ie_recv_list = MK_16(MEM, ie_softc[unit].rframes[0]); command_and_wait(unit, IE_RU_START, 0, 0); ie_ack(ie_softc[unit].scb, IE_ST_WHENCE, unit, ie_softc[unit].ie_chan_attn); - - crit_exit(); } /* @@ -1988,8 +1965,6 @@ ieinit(xsc) int i; int unit = ie->unit; - crit_enter(); - ptr = Alignvol((volatile char *) scb + sizeof *scb); /* @@ -2008,7 +1983,6 @@ ieinit(xsc) if (command_and_wait(unit, IE_CU_START, cmd, IE_STAT_COMPL) || !(cmd->com.ie_cmd_status & IE_STAT_OK)) { - crit_exit(); printf("ie%d: configure command failed\n", unit); return; } @@ -2028,7 +2002,6 @@ ieinit(xsc) scb->ie_command_list = MK_16(MEM, cmd); if (command_and_wait(unit, IE_CU_START, cmd, IE_STAT_COMPL) || !(cmd->com.ie_cmd_status & IE_STAT_OK)) { - crit_exit(); printf("ie%d: individual address " "setup command failed\n", unit); return; @@ -2098,8 +2071,6 @@ ieinit(xsc) ie->arpcom.ac_if.if_flags |= IFF_RUNNING; /* tell higher levels * we're here */ start_receiver(unit); - - crit_exit(); } static void @@ -2113,8 +2084,6 @@ ieioctl(struct ifnet *ifp, u_long command, caddr_t data, struct ucred *cr) { int error = 0; - crit_enter(); - switch (command) { case SIOCSIFFLAGS: /* @@ -2153,8 +2122,6 @@ ieioctl(struct ifnet *ifp, u_long command, caddr_t data, struct ucred *cr) error = ether_ioctl(ifp, command, data); break; } - - crit_exit(); return (error); } diff --git a/sys/dev/netif/kue/if_kue.c b/sys/dev/netif/kue/if_kue.c index 7d5551eb70..213b39f50b 100644 --- a/sys/dev/netif/kue/if_kue.c +++ b/sys/dev/netif/kue/if_kue.c @@ -30,7 +30,7 @@ * THE POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD: src/sys/dev/usb/if_kue.c,v 1.17.2.9 2003/04/13 02:39:25 murray Exp $ - * $DragonFly: src/sys/dev/netif/kue/if_kue.c,v 1.17 2005/11/22 00:24:33 dillon Exp $ + * $DragonFly: src/sys/dev/netif/kue/if_kue.c,v 1.18 2005/11/28 17:13:42 dillon Exp $ */ /* @@ -489,7 +489,7 @@ USB_ATTACH(kue) /* * Call MI attach routine. */ - ether_ifattach(ifp, sc->kue_desc.kue_macaddr); + ether_ifattach(ifp, sc->kue_desc.kue_macaddr, NULL); usb_register_netisr(); sc->kue_dying = 0; diff --git a/sys/dev/netif/le/if_le.c b/sys/dev/netif/le/if_le.c index c8743919c0..7b82b41eb1 100644 --- a/sys/dev/netif/le/if_le.c +++ b/sys/dev/netif/le/if_le.c @@ -22,7 +22,7 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD: src/sys/i386/isa/if_le.c,v 1.56.2.4 2002/06/05 23:24:10 paul Exp $ - * $DragonFly: src/sys/dev/netif/le/if_le.c,v 1.32 2005/11/22 00:24:33 dillon Exp $ + * $DragonFly: src/sys/dev/netif/le/if_le.c,v 1.33 2005/11/28 17:13:42 dillon Exp $ */ /* @@ -46,10 +46,12 @@ #include #include #include -#include #include #include #include +#include + +#include #include #include @@ -231,6 +233,8 @@ static const struct le_board le_boards[] = { { NULL } /* Must Be Last! */ }; +static struct lwkt_serialize le_serialize; + /* * This tells the autoconf code how to set us up. */ @@ -254,6 +258,8 @@ le_probe(struct isa_device *dvp) const struct le_board *bd; int iospace; + lwkt_serialize_init(&le_serialize); + if (dvp->id_unit >= NLE) { printf("%s%d not configured -- too many devices\n", ledriver.name, dvp->id_unit); @@ -300,7 +306,7 @@ le_attach(struct isa_device *dvp) ifq_set_maxlen(&ifp->if_snd, IFQ_MAXLEN); ifq_set_ready(&ifp->if_snd); - ether_ifattach(ifp, sc->le_ac.ac_enaddr); + ether_ifattach(ifp, sc->le_ac.ac_enaddr, &le_serialize); return 1; } @@ -310,8 +316,10 @@ le_intr(void *arg) { int unit = (int)arg; + lwkt_serialize_enter(&le_serialize); le_intrs[unit]++; (*le_intrvec[unit])(&le_softc[unit]); + lwkt_serialize_exit(&le_serialize); } #define LE_XTRA 0 @@ -320,33 +328,20 @@ static void le_input(struct le_softc *sc, caddr_t seg1, size_t total_len, size_t len1, caddr_t seg2) { - struct ether_header eh; struct mbuf *m; - if (total_len - sizeof(eh) > ETHERMTU - || total_len - sizeof(eh) < ETHERMIN) { - sc->le_if.if_ierrors++; - return; - } - bcopy(seg1, &eh, ETHER_HDR_LEN); - - seg1 += ETHER_HDR_LEN; - total_len -= ETHER_HDR_LEN; - len1 -= ETHER_HDR_LEN; - m = m_getl(total_len + LE_XTRA, MB_DONTWAIT, MT_DATA, M_PKTHDR, NULL); if (m == NULL) { sc->le_if.if_ierrors++; return; } - m->m_pkthdr.rcvif = &sc->le_if; m->m_data += LE_XTRA; m->m_len = m->m_pkthdr.len = total_len; bcopy(seg1, mtod(m, caddr_t), len1); if (seg2 != NULL) bcopy(seg2, mtod(m, caddr_t) + len1, total_len - len1); - ether_input(&sc->le_if, &eh, m); + sc->le_if.if_input(&sc->le_if, m); } static int @@ -358,8 +353,6 @@ le_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data, struct ucred *cr) if ((sc->le_flags & IFF_UP) == 0) return EIO; - crit_enter(); - switch (cmd) { case SIOCSIFFLAGS: { sc->if_init(sc); @@ -379,9 +372,6 @@ le_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data, struct ucred *cr) error = ether_ioctl(ifp, cmd, data); break; } - - crit_exit(); - return error; } @@ -679,8 +669,6 @@ lemac_init(void *xsc) if ((sc->le_flags & IFF_UP) == 0) return; - crit_enter(); - /* * If the interface has the up flag */ @@ -720,8 +708,6 @@ lemac_init(void *xsc) LEMAC_INTR_DISABLE(sc); sc->le_if.if_flags &= ~IFF_RUNNING; } - - crit_exit(); } /* diff --git a/sys/dev/netif/lge/if_lge.c b/sys/dev/netif/lge/if_lge.c index b8a5bf56e1..ec94bc1ed1 100644 --- a/sys/dev/netif/lge/if_lge.c +++ b/sys/dev/netif/lge/if_lge.c @@ -31,7 +31,7 @@ * THE POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD: src/sys/dev/lge/if_lge.c,v 1.5.2.2 2001/12/14 19:49:23 jlemon Exp $ - * $DragonFly: src/sys/dev/netif/lge/if_lge.c,v 1.32 2005/11/22 00:24:33 dillon Exp $ + * $DragonFly: src/sys/dev/netif/lge/if_lge.c,v 1.33 2005/11/28 17:13:43 dillon Exp $ */ /* @@ -81,6 +81,7 @@ #include #include #include +#include #include #include @@ -139,6 +140,7 @@ static void lge_rxeoc(struct lge_softc *); static void lge_txeof(struct lge_softc *); static void lge_intr(void *); static void lge_tick(void *); +static void lge_tick_serialized(void *); static void lge_start(struct ifnet *); static int lge_ioctl(struct ifnet *, u_long, caddr_t, struct ucred *); static void lge_init(void *); @@ -544,10 +546,11 @@ lge_attach(device_t dev) /* * Call MI attach routine. */ - ether_ifattach(ifp, eaddr); + ether_ifattach(ifp, eaddr, NULL); - error = bus_setup_intr(dev, sc->lge_irq, 0, - lge_intr, sc, &sc->lge_intrhand, NULL); + error = bus_setup_intr(dev, sc->lge_irq, INTR_NETSAFE, + lge_intr, sc, &sc->lge_intrhand, + ifp->if_serializer); if (error) { ether_ifdetach(ifp); printf("lge%d: couldn't set up irq\n", unit); @@ -567,8 +570,7 @@ lge_detach(device_t dev) struct lge_softc *sc= device_get_softc(dev); struct ifnet *ifp = &sc->arpcom.ac_if; - crit_enter(); - + lwkt_serialize_enter(ifp->if_serializer); if (device_is_attached(dev)) { lge_reset(sc); lge_stop(sc); @@ -582,8 +584,6 @@ lge_detach(device_t dev) if (sc->lge_intrhand) bus_teardown_intr(dev, sc->lge_irq, sc->lge_intrhand); - crit_exit(); - if (sc->lge_irq) bus_release_resource(dev, SYS_RES_IRQ, 0, sc->lge_irq); if (sc->lge_res) @@ -594,6 +594,7 @@ lge_detach(device_t dev) M_DEVBUF); lge_free_jumbo_mem(sc); + lwkt_serialize_exit(ifp->if_serializer); return(0); } @@ -909,7 +910,7 @@ lge_rxeof(struct lge_softc *sc, int cnt) m->m_pkthdr.csum_data = 0xffff; } - (*ifp->if_input)(ifp, m); + ifp->if_input(ifp, m); } sc->lge_cdata.lge_rx_cons = i; @@ -970,10 +971,19 @@ static void lge_tick(void *xsc) { struct lge_softc *sc = xsc; - struct mii_data *mii; struct ifnet *ifp = &sc->arpcom.ac_if; - crit_enter(); + lwkt_serialize_enter(ifp->if_serializer); + lge_tick_serialized(xsc); + lwkt_serialize_exit(ifp->if_serializer); +} + +static void +lge_tick_serialized(void *xsc) +{ + struct lge_softc *sc = xsc; + struct mii_data *mii; + struct ifnet *ifp = &sc->arpcom.ac_if; CSR_WRITE_4(sc, LGE_STATSIDX, LGE_STATS_SINGLE_COLL_PKTS); ifp->if_collisions += CSR_READ_4(sc, LGE_STATSVAL); @@ -997,8 +1007,6 @@ lge_tick(void *xsc) } callout_reset(&sc->lge_stat_timer, hz, lge_tick, sc); - - crit_exit(); } static void @@ -1037,7 +1045,7 @@ lge_intr(void *arg) if (status & LGE_ISR_PHY_INTR) { sc->lge_link = 0; callout_stop(&sc->lge_stat_timer); - lge_tick(sc); + lge_tick_serialized(sc); } } @@ -1153,12 +1161,8 @@ lge_init(void *xsc) struct ifnet *ifp = &sc->arpcom.ac_if; struct mii_data *mii; - crit_enter(); - - if (ifp->if_flags & IFF_RUNNING) { - crit_exit(); + if (ifp->if_flags & IFF_RUNNING) return; - } /* * Cancel pending I/O and free all RX/TX buffers. @@ -1177,7 +1181,6 @@ lge_init(void *xsc) printf("lge%d: initialization failed: no " "memory for rx buffers\n", sc->lge_unit); lge_stop(sc); - crit_exit(); return; } @@ -1275,8 +1278,6 @@ lge_init(void *xsc) ifp->if_flags &= ~IFF_OACTIVE; callout_reset(&sc->lge_stat_timer, hz, lge_tick, sc); - - crit_exit(); } /* @@ -1322,8 +1323,6 @@ lge_ioctl(struct ifnet *ifp, u_long command, caddr_t data, struct ucred *cr) struct mii_data *mii; int error = 0; - crit_enter(); - switch(command) { case SIOCSIFMTU: if (ifr->ifr_mtu > LGE_JUMBO_MTU) @@ -1370,8 +1369,6 @@ lge_ioctl(struct ifnet *ifp, u_long command, caddr_t data, struct ucred *cr) break; } - crit_exit(); - return(error); } diff --git a/sys/dev/netif/lnc/if_lnc.c b/sys/dev/netif/lnc/if_lnc.c index e8aa383521..611f884235 100644 --- a/sys/dev/netif/lnc/if_lnc.c +++ b/sys/dev/netif/lnc/if_lnc.c @@ -28,7 +28,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/dev/lnc/if_lnc.c,v 1.89 2001/07/04 13:00:19 nyan Exp $ - * $DragonFly: src/sys/dev/netif/lnc/Attic/if_lnc.c,v 1.23 2005/11/22 00:24:33 dillon Exp $ + * $DragonFly: src/sys/dev/netif/lnc/Attic/if_lnc.c,v 1.24 2005/11/28 17:13:43 dillon Exp $ */ /* @@ -71,6 +71,7 @@ #include #include #include +#include #include #include @@ -576,7 +577,7 @@ lnc_rint(struct lnc_softc *sc) sc->arpcom.ac_enaddr, ETHER_ADDR_LEN) == 0) { m_freem(head); } else { - (ifp->if_input)(ifp, head); + ifp->if_input(ifp, head); } } else { int unit = ifp->if_dunit; @@ -873,7 +874,7 @@ lnc_attach_common(device_t dev) * XXX -- should check return status of if_attach */ - ether_ifattach(&sc->arpcom.ac_if, sc->arpcom.ac_enaddr); + ether_ifattach(&sc->arpcom.ac_if, sc->arpcom.ac_enaddr, NULL); if (sc->nic.ic == LANCE || sc->nic.ic == C_LANCE) if_printf(ifp, "%s (%s)", nic_ident[sc->nic.ident], diff --git a/sys/dev/netif/lnc/if_lnc_isa.c b/sys/dev/netif/lnc/if_lnc_isa.c index 2a35a9bb59..69d01e9432 100644 --- a/sys/dev/netif/lnc/if_lnc_isa.c +++ b/sys/dev/netif/lnc/if_lnc_isa.c @@ -28,7 +28,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/dev/lnc/if_lnc_isa.c,v 1.12 2001/07/04 13:00:19 nyan Exp $ - * $DragonFly: src/sys/dev/netif/lnc/if_lnc_isa.c,v 1.6 2005/10/12 17:35:52 dillon Exp $ + * $DragonFly: src/sys/dev/netif/lnc/if_lnc_isa.c,v 1.7 2005/11/28 17:13:43 dillon Exp $ */ #include @@ -37,6 +37,7 @@ #include #include #include +#include #include #include @@ -243,8 +244,9 @@ lnc_isa_attach(device_t dev) goto fail; } - error = bus_setup_intr(dev, sc->irqres, 0, lncintr, - sc, &sc->intrhand, NULL); + error = bus_setup_intr(dev, sc->irqres, INTR_NETSAFE, lncintr, + sc, &sc->intrhand, + sc->arpcom.ac_if.if_serializer); if (error) { device_printf(dev, "Failed to setup irq handler\n"); ether_ifdetach(&sc->arpcom.ac_if); @@ -263,7 +265,7 @@ lnc_isa_detach(device_t dev) { lnc_softc_t *sc = device_get_softc(dev); - crit_enter(); + lwkt_serialize_enter(sc->arpcom.ac_if.if_serializer); if (device_is_attached(dev)) { ether_ifdetach(&sc->arpcom.ac_if); @@ -273,8 +275,6 @@ lnc_isa_detach(device_t dev) if (sc->intrhand) bus_teardown_intr(dev, sc->irqres, sc->intrhand); - crit_exit(); - if (sc->irqres) bus_release_resource(dev, SYS_RES_IRQ, sc->irqrid, sc->irqres); if (sc->portres) @@ -289,6 +289,7 @@ lnc_isa_detach(device_t dev) if (sc->dmat) bus_dma_tag_destroy(sc->dmat); + lwkt_serialize_exit(sc->arpcom.ac_if.if_serializer); return (0); } diff --git a/sys/dev/netif/lnc/if_lnc_pci.c b/sys/dev/netif/lnc/if_lnc_pci.c index b9aba0ef23..051455aaf4 100644 --- a/sys/dev/netif/lnc/if_lnc_pci.c +++ b/sys/dev/netif/lnc/if_lnc_pci.c @@ -28,7 +28,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/dev/lnc/if_lnc_pci.c,v 1.25 2001/07/04 13:00:19 nyan Exp $ - * $DragonFly: src/sys/dev/netif/lnc/if_lnc_pci.c,v 1.7 2005/10/12 17:35:52 dillon Exp $ + * $DragonFly: src/sys/dev/netif/lnc/if_lnc_pci.c,v 1.8 2005/11/28 17:13:43 dillon Exp $ */ #include @@ -36,13 +36,15 @@ #include #include #include -#include +#include #include #include #include #include +#include + #include #include #include @@ -186,8 +188,9 @@ lnc_pci_attach(device_t dev) goto fail; } - error = bus_setup_intr(dev, sc->irqres, 0, lncintr, - sc, &sc->intrhand, NULL); + error = bus_setup_intr(dev, sc->irqres, INTR_NETSAFE, lncintr, + sc, &sc->intrhand, + sc->arpcom.ac_if.if_serializer); if (error) { device_printf(dev, "Cannot setup irq handler\n"); ether_ifdetach(&sc->arpcom.ac_if); @@ -206,7 +209,7 @@ lnc_pci_detach(device_t dev) { lnc_softc_t *sc = device_get_softc(dev); - crit_enter(); + lwkt_serialize_enter(sc->arpcom.ac_if.if_serializer); if (device_is_attached(dev)) { ether_ifdetach(&sc->arpcom.ac_if); @@ -216,8 +219,6 @@ lnc_pci_detach(device_t dev) if (sc->intrhand) bus_teardown_intr(dev, sc->irqres, sc->intrhand); - crit_exit(); - if (sc->irqres) bus_release_resource(dev, SYS_RES_IRQ, 0, sc->irqres); if (sc->portres) @@ -231,6 +232,8 @@ lnc_pci_detach(device_t dev) if (sc->dmat) bus_dma_tag_destroy(sc->dmat); + lwkt_serialize_exit(sc->arpcom.ac_if.if_serializer); + return (0); } diff --git a/sys/dev/netif/mn/if_mn.c b/sys/dev/netif/mn/if_mn.c index 3f7546abab..43ae838888 100644 --- a/sys/dev/netif/mn/if_mn.c +++ b/sys/dev/netif/mn/if_mn.c @@ -22,7 +22,7 @@ * this gadget. * * $FreeBSD: src/sys/pci/if_mn.c,v 1.11.2.3 2001/01/23 12:47:09 phk Exp $ - * $DragonFly: src/sys/dev/netif/mn/if_mn.c,v 1.10 2005/10/12 17:35:52 dillon Exp $ + * $DragonFly: src/sys/dev/netif/mn/if_mn.c,v 1.11 2005/11/28 17:13:43 dillon Exp $ */ /* @@ -1348,7 +1348,7 @@ mn_attach (device_t self) return(ENXIO); } - error = bus_setup_intr(self, sc->irq, 0, mn_intr, sc, + error = bus_setup_intr(self, sc->irq, INTR_NETSAFE, mn_intr, sc, &sc->intrhand, NULL); if (error) { diff --git a/sys/dev/netif/my/if_my.c b/sys/dev/netif/my/if_my.c index 04bb4862f6..b78f981c39 100644 --- a/sys/dev/netif/my/if_my.c +++ b/sys/dev/netif/my/if_my.c @@ -26,7 +26,7 @@ * Written by: yen_cw@myson.com.tw available at: http://www.myson.com.tw/ * * $FreeBSD: src/sys/dev/my/if_my.c,v 1.2.2.4 2002/04/17 02:05:27 julian Exp $ - * $DragonFly: src/sys/dev/netif/my/if_my.c,v 1.22 2005/11/22 00:24:33 dillon Exp $ + * $DragonFly: src/sys/dev/netif/my/if_my.c,v 1.23 2005/11/28 17:13:43 dillon Exp $ * * Myson fast ethernet PCI NIC driver * @@ -40,9 +40,11 @@ #include #include #include -#include #include #include +#include + +#include #include #include @@ -861,7 +863,6 @@ my_attach(device_t dev) error = ENXIO; goto fail; } - callout_init(&sc->my_stat_ch); sc->my_info = t; @@ -962,10 +963,11 @@ my_attach(device_t dev) my_stop(sc); ifmedia_set(&sc->ifmedia, media); - ether_ifattach(ifp, eaddr); + ether_ifattach(ifp, eaddr, NULL); - error = bus_setup_intr(dev, sc->my_irq, 0, - my_intr, sc, &sc->my_intrhand, NULL); + error = bus_setup_intr(dev, sc->my_irq, INTR_NETSAFE, + my_intr, sc, &sc->my_intrhand, + ifp->if_serializer); if (error) { ether_ifdetach(ifp); printf("my%d: couldn't set up irq\n", unit); @@ -985,7 +987,7 @@ my_detach(device_t dev) struct my_softc *sc = device_get_softc(dev); struct ifnet *ifp = &sc->arpcom.ac_if; - crit_enter(); + lwkt_serialize_enter(ifp->if_serializer); if (device_is_attached(dev)) { ether_ifdetach(ifp); my_stop(sc); @@ -994,7 +996,7 @@ my_detach(device_t dev) if (sc->my_intrhand) bus_teardown_intr(dev, sc->my_irq, sc->my_intrhand); - crit_exit(); + lwkt_serialize_exit(ifp->if_serializer); if (sc->my_irq) bus_release_resource(dev, SYS_RES_IRQ, 0, sc->my_irq); @@ -1144,7 +1146,7 @@ my_rxeof(struct my_softc * sc) m->m_pkthdr.len = m->m_len = total_len; } ifp->if_ipackets++; - (*ifp->if_input)(ifp, m); + ifp->if_input(ifp, m); } } diff --git a/sys/dev/netif/my/if_myreg.h b/sys/dev/netif/my/if_myreg.h index 82d924c6ba..3893f3139d 100644 --- a/sys/dev/netif/my/if_myreg.h +++ b/sys/dev/netif/my/if_myreg.h @@ -26,7 +26,7 @@ * Written by: yen_cw@myson.com.tw available at: http://www.myson.com.tw/ * * $FreeBSD: src/sys/dev/my/if_myreg.h,v 1.1.2.2 2002/04/17 02:05:27 julian Exp $ - * $DragonFly: src/sys/dev/netif/my/if_myreg.h,v 1.4 2005/06/14 11:05:47 joerg Exp $ + * $DragonFly: src/sys/dev/netif/my/if_myreg.h,v 1.5 2005/11/28 17:13:43 dillon Exp $ * * Myson MTD80x register definitions. * @@ -371,7 +371,6 @@ struct my_softc { struct my_list_data *my_ldata; struct my_chain_data my_cdata; device_t my_miibus; - struct callout my_stat_ch; }; diff --git a/sys/dev/netif/ndis/if_ndis.c b/sys/dev/netif/ndis/if_ndis.c index 7a8928e906..90740a357c 100644 --- a/sys/dev/netif/ndis/if_ndis.c +++ b/sys/dev/netif/ndis/if_ndis.c @@ -30,7 +30,7 @@ * THE POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD: src/sys/dev/if_ndis/if_ndis.c,v 1.65 2004/07/07 17:46:30 wpaul Exp $ - * $DragonFly: src/sys/dev/netif/ndis/if_ndis.c,v 1.10 2005/11/22 00:24:33 dillon Exp $ + * $DragonFly: src/sys/dev/netif/ndis/if_ndis.c,v 1.11 2005/11/28 17:13:43 dillon Exp $ */ #include @@ -42,9 +42,8 @@ #include #include #include -#if __FreeBSD_version < 502113 #include -#endif +#include #include #include @@ -376,20 +375,6 @@ ndis_attach(dev) NDIS_LOCK_INIT(&sc->ndis_lock); NDIS_LOCK_INIT(&sc->ndis_intrlock); - /* - * Hook interrupt early, since calling the driver's - * init routine may trigger an interrupt. - */ - - error = bus_setup_intr(dev, sc->ndis_irq, INTR_MPSAFE, - ndis_intr, sc, - &sc->ndis_intrhand, NULL); - - if (error) { - device_printf(dev, "couldn't set up irq\n"); - goto fail; - } - sc->ndis_regvals = ndis_regvals; #if __FreeBSD_version < 502113 @@ -674,9 +659,21 @@ nonettypes: IFM_ETHER|IFM_100_TX|IFM_FDX, 0, NULL); ifmedia_add(&sc->ifmedia, IFM_ETHER|IFM_AUTO, 0, NULL); ifmedia_set(&sc->ifmedia, IFM_ETHER|IFM_AUTO); - ether_ifattach(ifp, eaddr); + ether_ifattach(ifp, eaddr, NULL); + } + + if (error == 0) { + error = bus_setup_intr(dev, sc->ndis_irq, INTR_NETSAFE, + ndis_intr, sc, + &sc->ndis_intrhand, + ifp->if_serializer); + if (error) { + device_printf(dev, "couldn't set up irq\n"); + goto fail; + } } + /* Override the status handler so we can detect link changes. */ sc->ndis_block.nmb_status_func = ndis_linksts; sc->ndis_block.nmb_statusdone_func = ndis_linksts_done; @@ -706,8 +703,10 @@ ndis_detach(dev) NDIS_LOCK_INFO; sc = device_get_softc(dev); - NDIS_LOCK(sc); ifp = &sc->arpcom.ac_if; + lwkt_serialize_enter(ifp->if_serializer); + + NDIS_LOCK(sc); ifp->if_flags &= ~IFF_UP; if (device_is_attached(dev)) { @@ -751,6 +750,7 @@ ndis_detach(dev) NDIS_LOCK_DESTROY(&sc->ndis_lock); NDIS_LOCK_DESTROY(&sc->ndis_intrlock); + lwkt_serialize_exit(ifp->if_serializer); return(0); } @@ -763,12 +763,13 @@ ndis_suspend(dev) sc = device_get_softc(dev); ifp = &sc->arpcom.ac_if; + lwkt_serialize_enter(ifp->if_serializer); #ifdef notdef if (NDIS_INITIALIZED(sc)) ndis_stop(sc); #endif - + lwkt_serialize_exit(ifp->if_serializer); return(0); } @@ -782,8 +783,10 @@ ndis_resume(dev) sc = device_get_softc(dev); ifp = &sc->arpcom.ac_if; + lwkt_serialize_enter(ifp->if_serializer); if (NDIS_INITIALIZED(sc)) ndis_init(sc); + lwkt_serialize_exit(ifp->if_serializer); return(0); } @@ -876,7 +879,7 @@ ndis_rxeof(adapter, packets, pktcnt) } } - (*ifp->if_input)(ifp, m0); + ifp->if_input(ifp, m0); } } @@ -988,12 +991,14 @@ ndis_intrtask(arg) sc = arg; ifp = &sc->arpcom.ac_if; + lwkt_serialize_enter(ifp->serializer); irql = FASTCALL1(hal_raise_irql, DISPATCH_LEVEL); ndis_intrhand(sc); FASTCALL1(hal_lower_irql, irql); NDIS_INTRLOCK(sc); ndis_enable_intr(sc); NDIS_INTRUNLOCK(sc); + lwkt_serialize_exit(ifp->serializer); return; } @@ -1047,6 +1052,7 @@ ndis_ticktask(xsc) void *xsc; { struct ndis_softc *sc; + struct ifnet *ifp; __stdcall ndis_checkforhang_handler hangfunc; uint8_t rval; ndis_media_state linkstate; @@ -1054,13 +1060,16 @@ ndis_ticktask(xsc) NDIS_LOCK_INFO; sc = xsc; + ifp = &sc->arpcom.ac_if; + lwkt_serialize_enter(ifp->serializer); hangfunc = sc->ndis_chars.nmc_checkhang_func; if (hangfunc != NULL) { rval = hangfunc(sc->ndis_block.nmb_miniportadapterctx); if (rval == TRUE) { ndis_reset_nic(sc); + lwkt_serialize_exit(ifp->serializer); return; } } @@ -1094,8 +1103,7 @@ ndis_ticktask(xsc) } NDIS_UNLOCK(sc); - - return; + lwkt_serialize_exit(ifp->serializer); } static void diff --git a/sys/dev/netif/nge/if_nge.c b/sys/dev/netif/nge/if_nge.c index e26a7f3429..56d6f11173 100644 --- a/sys/dev/netif/nge/if_nge.c +++ b/sys/dev/netif/nge/if_nge.c @@ -31,7 +31,7 @@ * THE POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD: src/sys/dev/nge/if_nge.c,v 1.13.2.13 2003/02/05 22:03:57 mbr Exp $ - * $DragonFly: src/sys/dev/netif/nge/if_nge.c,v 1.33 2005/11/22 00:24:33 dillon Exp $ + * $DragonFly: src/sys/dev/netif/nge/if_nge.c,v 1.34 2005/11/28 17:13:43 dillon Exp $ */ /* @@ -97,6 +97,8 @@ #include #include #include +#include + #include #include @@ -404,8 +406,6 @@ nge_mii_readreg(struct nge_softc *sc, struct nge_mii_frame *frame) { int ack, i; - crit_enter(); - /* * Set up frame for RX. */ @@ -478,8 +478,6 @@ fail: SIO_SET(NGE_MEAR_MII_CLK); DELAY(1); - crit_exit(); - if (ack) return(1); return(0); @@ -491,8 +489,6 @@ fail: static int nge_mii_writereg(struct nge_softc *sc, struct nge_mii_frame *frame) { - crit_enter(); - /* * Set up frame for TX. */ @@ -526,8 +522,6 @@ nge_mii_writereg(struct nge_softc *sc, struct nge_mii_frame *frame) */ SIO_CLR(NGE_MEAR_MII_DIR); - crit_exit(); - return(0); } @@ -903,10 +897,11 @@ nge_attach(device_t dev) /* * Call MI attach routine. */ - ether_ifattach(ifp, eaddr); + ether_ifattach(ifp, eaddr, NULL); - error = bus_setup_intr(dev, sc->nge_irq, 0, - nge_intr, sc, &sc->nge_intrhand, NULL); + error = bus_setup_intr(dev, sc->nge_irq, INTR_NETSAFE, + nge_intr, sc, &sc->nge_intrhand, + ifp->if_serializer); if (error) { ether_ifdetach(ifp); device_printf(dev, "couldn't set up irq\n"); @@ -925,7 +920,7 @@ nge_detach(device_t dev) struct nge_softc *sc = device_get_softc(dev); struct ifnet *ifp = &sc->arpcom.ac_if; - crit_enter(); + lwkt_serialize_enter(ifp->if_serializer); if (device_is_attached(dev)) { nge_reset(sc); @@ -940,8 +935,6 @@ nge_detach(device_t dev) if (sc->nge_intrhand) bus_teardown_intr(dev, sc->nge_irq, sc->nge_intrhand); - crit_exit(); - if (sc->nge_irq) bus_release_resource(dev, SYS_RES_IRQ, 0, sc->nge_irq); if (sc->nge_res) @@ -953,6 +946,7 @@ nge_detach(device_t dev) if (sc->nge_cdata.nge_jumbo_buf) contigfree(sc->nge_cdata.nge_jumbo_buf, NGE_JMEM, M_DEVBUF); + lwkt_serialize_exit(ifp->if_serializer); return(0); } @@ -1285,10 +1279,12 @@ nge_rxeof(struct nge_softc *sc) * If we received a packet with a vlan tag, pass it * to vlan_input() instead of ether_input(). */ + lwkt_serialize_enter(ifp->if_serializer); if (extsts & NGE_RXEXTSTS_VLANPKT) VLAN_INPUT_TAG(m, extsts & NGE_RXEXTSTS_VTCI); else - (*ifp->if_input)(ifp, m); + ifp->if_input(ifp, m); + lwkt_serialize_exit(ifp->if_serializer); } sc->nge_cdata.nge_rx_prod = i; @@ -1360,7 +1356,7 @@ nge_tick(void *xsc) struct ifnet *ifp = &sc->arpcom.ac_if; struct mii_data *mii; - crit_enter(); + lwkt_serialize_enter(ifp->if_serializer); if (sc->nge_tbi) { if (sc->nge_link == 0) { @@ -1393,7 +1389,7 @@ nge_tick(void *xsc) } callout_reset(&sc->nge_stat_timer, hz, nge_tick, sc); - crit_exit(); + lwkt_serialize_exit(ifp->if_serializer); } #ifdef DEVICE_POLLING @@ -1504,7 +1500,7 @@ nge_intr(void *arg) /* mii_tick should only be called once per second */ if (status & NGE_ISR_PHY_INTR) { sc->nge_link = 0; - nge_tick(sc); + nge_tick_serialized(sc); } #endif } @@ -1652,10 +1648,7 @@ nge_init(void *xsc) struct ifnet *ifp = &sc->arpcom.ac_if; struct mii_data *mii; - crit_enter(); - if (ifp->if_flags & IFF_RUNNING) { - crit_exit(); return; } @@ -1686,7 +1679,6 @@ nge_init(void *xsc) printf("nge%d: initialization failed: no " "memory for rx buffers\n", sc->nge_unit); nge_stop(sc); - crit_exit(); return; } @@ -1828,8 +1820,6 @@ nge_init(void *xsc) ifp->if_flags |= IFF_RUNNING; ifp->if_flags &= ~IFF_OACTIVE; - - crit_exit(); } /* @@ -1940,8 +1930,6 @@ nge_ioctl(struct ifnet *ifp, u_long command, caddr_t data, struct ucred *cr) struct mii_data *mii; int error = 0; - crit_enter(); - switch(command) { case SIOCSIFMTU: if (ifr->ifr_mtu > NGE_JUMBO_MTU) { @@ -2006,9 +1994,6 @@ nge_ioctl(struct ifnet *ifp, u_long command, caddr_t data, struct ucred *cr) error = ether_ioctl(ifp, command, data); break; } - - crit_exit(); - return(error); } @@ -2114,7 +2099,11 @@ static void nge_shutdown(device_t dev) { struct nge_softc *sc = device_get_softc(dev); + struct ifnet *ifp = &sc->arpcom.ac_if; + lwkt_serialize_enter(ifp->if_serializer); nge_reset(sc); nge_stop(sc); + lwkt_serialize_exit(ifp->if_serializer); } + diff --git a/sys/dev/netif/nv/if_nv.c b/sys/dev/netif/nv/if_nv.c index b879fb726c..98841a6aec 100644 --- a/sys/dev/netif/nv/if_nv.c +++ b/sys/dev/netif/nv/if_nv.c @@ -24,7 +24,7 @@ * SUCH DAMAGE. * * $Id: if_nv.c,v 1.20 2005/03/12 01:11:00 q Exp $ - * $DragonFly: src/sys/dev/netif/nv/Attic/if_nv.c,v 1.22 2005/11/22 00:24:33 dillon Exp $ + * $DragonFly: src/sys/dev/netif/nv/Attic/if_nv.c,v 1.23 2005/11/28 17:13:43 dillon Exp $ */ /* @@ -126,15 +126,12 @@ static int nv_probe(device_t); static int nv_attach(device_t); static int nv_detach(device_t); static void nv_init(void *); -static void nv_init_serialized(struct nv_softc *); static void nv_stop(struct nv_softc *); -static void nv_stop_serialized(struct nv_softc *); static void nv_shutdown(device_t); static int nv_init_rings(struct nv_softc *); static void nv_free_rings(struct nv_softc *); static void nv_ifstart(struct ifnet *); -static void nv_ifstart_serialized(struct ifnet *); static int nv_ioctl(struct ifnet *, u_long, caddr_t, struct ucred *); static void nv_intr(void *); static void nv_tick(void *); @@ -313,7 +310,6 @@ nv_attach(device_t dev) sc->dev = dev; sc->unit = unit; - lwkt_serialize_init(&sc->serializer); callout_init(&sc->nv_stat_timer); /* Preinitialize data structures */ @@ -529,11 +525,11 @@ nv_attach(device_t dev) ifq_set_ready(&ifp->if_snd); /* Attach to OS's managers. */ - ether_ifattach(ifp, sc->sc_macaddr); + ether_ifattach(ifp, sc->sc_macaddr, NULL); /* Activate our interrupt handler. - attach last to avoid lock */ - error = bus_setup_intr(sc->dev, sc->irq, 0, - nv_intr, sc, &sc->sc_ih, &sc->serializer); + error = bus_setup_intr(sc->dev, sc->irq, INTR_NETSAFE, + nv_intr, sc, &sc->sc_ih, ifp->if_serializer); if (error) { ether_ifdetach(ifp); device_printf(sc->dev, "couldn't set up interrupt handler\n"); @@ -555,17 +551,14 @@ nv_detach(device_t dev) struct nv_softc *sc = device_get_softc(dev); struct ifnet *ifp; - lwkt_serialize_enter(&sc->serializer); + ifp = &sc->arpcom.ac_if; + lwkt_serialize_enter(ifp->if_serializer); DEBUGOUT(NV_DEBUG_DEINIT, "nv: nv_detach - entry\n"); - ifp = &sc->arpcom.ac_if; - if (device_is_attached(dev)) { - nv_stop_serialized(sc); - lwkt_serialize_exit(&sc->serializer); + nv_stop(sc); ether_ifdetach(ifp); - lwkt_serialize_enter(&sc->serializer); } if (sc->miibus) @@ -602,27 +595,17 @@ nv_detach(device_t dev) if (sc->rtag) bus_dma_tag_destroy(sc->rtag); - lwkt_serialize_exit(&sc->serializer); + lwkt_serialize_exit(ifp->if_serializer); DEBUGOUT(NV_DEBUG_DEINIT, "nv: nv_detach - exit\n"); - return (0); } +/* Initialise interface and start it "RUNNING" */ static void nv_init(void *xsc) { struct nv_softc *sc = xsc; - - lwkt_serialize_enter(&sc->serializer); - nv_init_serialized(sc); - lwkt_serialize_exit(&sc->serializer); -} - -/* Initialise interface and start it "RUNNING" */ -static void -nv_init_serialized(struct nv_softc *sc) -{ struct ifnet *ifp; int error; @@ -634,7 +617,7 @@ nv_init_serialized(struct nv_softc *sc) if (ifp->if_flags & IFF_RUNNING) return; - nv_stop_serialized(sc); + nv_stop(sc); DEBUGOUT(NV_DEBUG_INIT, "nv: do pfnInit\n"); /* Setup Hardware interface and allocate memory structures */ @@ -670,11 +653,11 @@ nv_init_serialized(struct nv_softc *sc) * a reset, renegotiation, or timeout. */ #if 1 - lwkt_serialize_handler_enable(&sc->serializer); + lwkt_serialize_handler_enable(ifp->if_serializer); sc->hwapi->pfnEnableInterrupts(sc->hwapi->pADCX); #else if ((ifp->if_flags & IFF_POLLING) == 0) { - lwkt_serialize_handler_enable(&sc->serializer); + lwkt_serialize_handler_enable(ifp->if_serializer); sc->hwapi->pfnEnableInterrupts(sc->hwapi->pADCX); } #endif @@ -700,8 +683,6 @@ nv_poll(struct ifnet *ifp, enum poll_cmd cmd, int count) { struct nv_softc *sc = ifp->if_softc; - lwkt_serialize_enter(&sc->serializer); - switch(cmd) { case POLL_REGISTER: /* @@ -715,12 +696,12 @@ nv_poll(struct ifnet *ifp, enum poll_cmd cmd, int count) */ #if 0 sc->hwapi->pfnDisableInterrupts(sc->hwapi->pADCX); - lwkt_serialize_handler_disable(&sc->serializer); + lwkt_serialize_handler_disable(ifp->if_serializer); #endif break; case POLL_DEREGISTER: #if 0 - lwkt_serialize_handler_enable(&sc->serializer); + lwkt_serialize_handler_enable(ifp->if_serializer); sc->hwapi->pfnEnableInterrupts(sc->hwapi->pADCX); #endif break; @@ -732,26 +713,17 @@ nv_poll(struct ifnet *ifp, enum poll_cmd cmd, int count) } if (ifp->if_flags & IFF_RUNNING) { if (!ifq_is_empty(&ifp->if_snd)) - nv_ifstart_serialized(ifp); + nv_ifstart(ifp); } break; } - lwkt_serialize_exit(&sc->serializer); } #endif -static void -nv_stop(struct nv_softc *sc) -{ - lwkt_serialize_enter(&sc->serializer); - nv_stop_serialized(sc); - lwkt_serialize_exit(&sc->serializer); -} - /* Stop interface activity ie. not "RUNNING" */ static void -nv_stop_serialized(struct nv_softc *sc) +nv_stop(struct nv_softc *sc) { struct ifnet *ifp; @@ -769,7 +741,7 @@ nv_stop_serialized(struct nv_softc *sc) * the handler. */ sc->hwapi->pfnDisableInterrupts(sc->hwapi->pADCX); - lwkt_serialize_handler_disable(&sc->serializer); + lwkt_serialize_handler_disable(ifp->if_serializer); sc->hwapi->pfnStop(sc->hwapi->pADCX, 0); sc->hwapi->pfnClearTxDesc(sc->hwapi->pADCX); @@ -799,7 +771,9 @@ nv_shutdown(device_t dev) sc = device_get_softc(dev); /* Stop hardware activity */ + lwkt_serialize_enter(sc->sc_if.if_serializer); nv_stop(sc); + lwkt_serialize_exit(sc->sc_if.if_serializer); } /* Allocate TX ring buffers */ @@ -909,16 +883,6 @@ nv_free_rings(struct nv_softc *sc) static void nv_ifstart(struct ifnet *ifp) -{ - struct nv_softc *sc = ifp->if_softc; - - lwkt_serialize_enter(&sc->serializer); - nv_ifstart_serialized(ifp); - lwkt_serialize_exit(&sc->serializer); -} - -static void -nv_ifstart_serialized(struct ifnet *ifp) { struct nv_softc *sc = ifp->if_softc; struct nv_map_buffer *buf; @@ -1037,8 +1001,6 @@ nv_ioctl(struct ifnet *ifp, u_long command, caddr_t data, struct ucred *cr) struct mii_data *mii; int error = 0; - lwkt_serialize_enter(&sc->serializer); - DEBUGOUT(NV_DEBUG_IOCTL, "nv: nv_ioctl - entry\n"); switch (command) { @@ -1048,8 +1010,8 @@ nv_ioctl(struct ifnet *ifp, u_long command, caddr_t data, struct ucred *cr) break; if (ifr->ifr_mtu + ifp->if_hdrlen <= MAX_PACKET_SIZE_1518) { ifp->if_mtu = ifr->ifr_mtu; - nv_stop_serialized(sc); - nv_init_serialized(sc); + nv_stop(sc); + nv_init(sc); } else error = EINVAL; break; @@ -1058,12 +1020,12 @@ nv_ioctl(struct ifnet *ifp, u_long command, caddr_t data, struct ucred *cr) /* Setup interface flags */ if (ifp->if_flags & IFF_UP) { if ((ifp->if_flags & IFF_RUNNING) == 0) { - nv_init_serialized(sc); + nv_init(sc); break; } } else { if (ifp->if_flags & IFF_RUNNING) { - nv_stop_serialized(sc); + nv_stop(sc); break; } } @@ -1088,16 +1050,12 @@ nv_ioctl(struct ifnet *ifp, u_long command, caddr_t data, struct ucred *cr) default: /* Everything else we forward to generic ether ioctl */ - lwkt_serialize_exit(&sc->serializer); error = ether_ioctl(ifp, command, data); - lwkt_serialize_enter(&sc->serializer); break; } DEBUGOUT(NV_DEBUG_IOCTL, "nv: nv_ioctl - exit\n"); - lwkt_serialize_exit(&sc->serializer); - return (error); } @@ -1121,17 +1079,17 @@ nv_intr(void *arg) if (sc->hwapi->pfnQueryInterrupt(sc->hwapi->pADCX)) { sc->hwapi->pfnHandleInterrupt(sc->hwapi->pADCX); #if 1 - lwkt_serialize_handler_enable(&sc->serializer); + lwkt_serialize_handler_enable(ifp->if_serializer); sc->hwapi->pfnEnableInterrupts(sc->hwapi->pADCX); #else if ((ifp->if_flags & IFF_POLLING) == 0) { - lwkt_serialize_handler_enable(&sc->serializer); + lwkt_serialize_handler_enable(ifp->if_serializer); sc->hwapi->pfnEnableInterrupts(sc->hwapi->pADCX); } #endif } if (!ifq_is_empty(&ifp->if_snd)) - nv_ifstart_serialized(ifp); + nv_ifstart(ifp); /* If no pending packets we don't need a timeout */ if (sc->pending_txs == 0) @@ -1253,9 +1211,8 @@ nv_tick(void *xsc) struct mii_data *mii; struct ifnet *ifp; - lwkt_serialize_enter(&sc->serializer); - ifp = &sc->sc_if; + lwkt_serialize_enter(ifp->if_serializer); nv_update_stats(sc); mii = device_get_softc(sc->miibus); @@ -1264,10 +1221,10 @@ nv_tick(void *xsc) if ((mii->mii_media_status & IFM_ACTIVE) && IFM_SUBTYPE(mii->mii_media_active) != IFM_NONE) { if (!ifq_is_empty(&ifp->if_snd)) - nv_ifstart_serialized(ifp); + nv_ifstart(ifp); } callout_reset(&sc->nv_stat_timer, hz, nv_tick, sc); - lwkt_serialize_exit(&sc->serializer); + lwkt_serialize_exit(ifp->if_serializer); } /* Update ifnet data structure with collected interface stats from API */ @@ -1334,21 +1291,17 @@ nv_watchdog(struct ifnet *ifp) { struct nv_softc *sc = ifp->if_softc; - lwkt_serialize_enter(&sc->serializer); - device_printf(sc->dev, "device timeout (%d) flags %d\n", sc->pending_txs, ifp->if_flags & IFF_OACTIVE); sc->tx_errors++; - nv_stop_serialized(sc); + nv_stop(sc); ifp->if_flags &= ~IFF_RUNNING; - nv_init_serialized(sc); + nv_init(sc); if (!ifq_is_empty(&ifp->if_snd)) - nv_ifstart_serialized(ifp); - - lwkt_serialize_exit(&sc->serializer); + nv_ifstart(ifp); } /* --- Start of NVOSAPI interface --- */ @@ -1580,7 +1533,7 @@ nv_ospackettx(PNV_VOID ctx, PNV_VOID id, NV_UINT32 success) if (sc->pending_txs < TX_RING_SIZE) { ifp->if_flags &= ~IFF_OACTIVE; if (!ifq_is_empty(&ifp->if_snd)) - nv_ifstart_serialized(ifp); + nv_ifstart(ifp); } fail: return (1); @@ -1618,7 +1571,7 @@ nv_ospacketrx(PNV_VOID ctx, PNV_VOID data, NV_UINT32 success, bus_dmamap_unload(sc->mtag, buf->map); /* Give mbuf to OS. */ - (*ifp->if_input) (ifp, buf->mbuf); + ifp->if_input(ifp, buf->mbuf); if (readdata->ulFilterMatch & ADREADFL_MULTICAST_MATCH) ifp->if_imcasts++; @@ -1695,6 +1648,17 @@ nv_osinittimer(PNV_VOID ctx, PNV_VOID timer, PTIMER_FUNC func, PNV_VOID paramete return (1); } +static void +nv_ostimer_callback(void *data) +{ + struct nv_softc *sc = data; + struct ifnet *ifp = &sc->sc_if; + + lwkt_serialize_enter(ifp->if_serializer); + sc->ostimer_func(sc->ostimer_params); + lwkt_serialize_exit(ifp->if_serializer); +} + /* * Set the timer to go off * @@ -1708,8 +1672,7 @@ nv_ossettimer(PNV_VOID ctx, PNV_VOID timer, NV_UINT32 delay) DEBUGOUT(NV_DEBUG_BROKEN, "nv: nv_ossettimer\n"); printf("nv_ossettimer %d\n", (int)delay); - callout_reset(&sc->ostimer, delay, sc->ostimer_func, - sc->ostimer_params); + callout_reset(&sc->ostimer, delay, nv_ostimer_callback, sc); return (1); } diff --git a/sys/dev/netif/nv/if_nvreg.h b/sys/dev/netif/nv/if_nvreg.h index 1a1c5b95b8..ea52c1b0bd 100644 --- a/sys/dev/netif/nv/if_nvreg.h +++ b/sys/dev/netif/nv/if_nvreg.h @@ -24,7 +24,7 @@ * SUCH DAMAGE. * * $Id: if_nvreg.h,v 1.6 2004/08/12 14:00:05 q Exp $ - * $DragonFly: src/sys/dev/netif/nv/Attic/if_nvreg.h,v 1.9 2005/10/12 01:09:31 dillon Exp $ + * $DragonFly: src/sys/dev/netif/nv/Attic/if_nvreg.h,v 1.10 2005/11/28 17:13:43 dillon Exp $ */ #ifndef _IF_NVREG_H_ @@ -122,8 +122,6 @@ struct nv_softc { struct resource *res; struct resource *irq; - struct lwkt_serialize serializer; - ADAPTER_API *hwapi; OS_API osapi; diff --git a/sys/dev/netif/owi/if_owi.c b/sys/dev/netif/owi/if_owi.c index b7192bc7a4..5ee0255242 100644 --- a/sys/dev/netif/owi/if_owi.c +++ b/sys/dev/netif/owi/if_owi.c @@ -30,7 +30,7 @@ * THE POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD: src/sys/dev/wi/if_wi.c,v 1.103.2.2 2002/08/02 07:11:34 imp Exp $ - * $DragonFly: src/sys/dev/netif/owi/Attic/if_owi.c,v 1.12 2005/11/22 00:24:33 dillon Exp $ + * $DragonFly: src/sys/dev/netif/owi/Attic/if_owi.c,v 1.13 2005/11/28 17:13:43 dillon Exp $ */ /* @@ -75,6 +75,7 @@ #include #include #include +#include #include #include @@ -183,11 +184,11 @@ owi_generic_detach(dev) struct wi_softc *sc = device_get_softc(dev); struct ifnet *ifp = &sc->arpcom.ac_if; - crit_enter(); + lwkt_serialize_enter(ifp->if_serializer); if (sc->wi_gone) { device_printf(dev, "already unloaded\n"); - crit_exit(); + lwkt_serialize_exit(ifp->if_serializer); return(ENODEV); } @@ -195,15 +196,12 @@ owi_generic_detach(dev) /* Delete all remaining media. */ ifmedia_removeall(&sc->ifmedia); - ether_ifdetach(ifp); bus_teardown_intr(dev, sc->irq, sc->wi_intrhand); - - crit_exit(); - owi_free(dev); sc->wi_gone = 1; + lwkt_serialize_exit(ifp->if_serializer); return(0); } @@ -439,10 +437,11 @@ owi_generic_attach(device_t dev) /* * Call MI attach routine. */ - ether_ifattach(ifp, sc->arpcom.ac_enaddr); + ether_ifattach(ifp, sc->arpcom.ac_enaddr, NULL); - error = bus_setup_intr(dev, sc->irq, 0, - wi_intr, sc, &sc->wi_intrhand, NULL); + error = bus_setup_intr(dev, sc->irq, INTR_NETSAFE, + wi_intr, sc, &sc->wi_intrhand, + ifp->if_serializer); if (error) { ether_ifdetach(ifp); device_printf(dev, "bus_setup_intr() failed! (%d)\n", error); @@ -795,7 +794,7 @@ wi_rxeof(sc) #ifdef WICACHE wi_cache_store(sc, m, rx_frame.wi_q_info); #endif - (*ifp->if_input)(ifp, m); + ifp->if_input(ifp, m); } } @@ -826,19 +825,16 @@ wi_inquire(xsc) struct wi_softc *sc = xsc; struct ifnet *ifp = &sc->arpcom.ac_if; - crit_enter(); + lwkt_serialize_enter(ifp->if_serializer); callout_reset(&sc->wi_stat_timer, hz* 60, wi_inquire, sc); /* Don't do this while we're transmitting */ - if (ifp->if_flags & IFF_OACTIVE) { - crit_exit(); - return; + if ((ifp->if_flags & IFF_OACTIVE) == 0) { + wi_cmd(sc, WI_CMD_INQUIRE, WI_INFO_COUNTERS, 0, 0); } - wi_cmd(sc, WI_CMD_INQUIRE, WI_INFO_COUNTERS, 0, 0); - - crit_exit(); + lwkt_serialize_exit(ifp->if_serializer); } static void @@ -1608,8 +1604,6 @@ wi_ioctl(ifp, command, data, cr) ifr = (struct ifreq *)data; ireq = (struct ieee80211req *)data; - crit_enter(); - if (sc->wi_gone) { error = ENODEV; goto out; @@ -1974,8 +1968,6 @@ wi_ioctl(ifp, command, data, cr) break; } out: - crit_exit(); - return(error); } @@ -1988,12 +1980,8 @@ wi_init(xsc) struct wi_ltv_macaddr mac; int id = 0; - crit_enter(); - - if (sc->wi_gone) { - crit_exit(); + if (sc->wi_gone) return; - } if (ifp->if_flags & IFF_RUNNING) wi_stop(sc); @@ -2116,8 +2104,6 @@ wi_init(xsc) ifp->if_flags &= ~IFF_OACTIVE; callout_reset(&sc->wi_stat_timer, hz * 60, wi_inquire, sc); - - crit_exit(); } #define RC4STATE 256 @@ -2210,24 +2196,16 @@ wi_start(ifp) struct ether_header *eh; int id; - crit_enter(); - - if (sc->wi_gone) { - crit_exit(); + if (sc->wi_gone) return; - } - if (ifp->if_flags & IFF_OACTIVE) { - crit_exit(); + if (ifp->if_flags & IFF_OACTIVE) return; - } nextpkt: m0 = ifq_dequeue(&ifp->if_snd, NULL); - if (m0 == NULL) { - crit_exit(); + if (m0 == NULL) return; - } bzero((char *)&tx_frame, sizeof(tx_frame)); tx_frame.wi_frame_ctl = htole16(WI_FTYPE_DATA); @@ -2338,8 +2316,6 @@ nextpkt: * Set a timeout in case the chip goes out to lunch. */ ifp->if_timer = 5; - - crit_exit(); } int @@ -2387,12 +2363,8 @@ wi_stop(sc) { struct ifnet *ifp; - crit_enter(); - - if (sc->wi_gone) { - crit_exit(); + if (sc->wi_gone) return; - } owihap_shutdown(sc); @@ -2411,8 +2383,6 @@ wi_stop(sc) callout_stop(&sc->wi_stat_timer); ifp->if_flags &= ~(IFF_RUNNING|IFF_OACTIVE); - - crit_exit(); } static void @@ -2510,12 +2480,14 @@ void owi_shutdown(dev) device_t dev; { - struct wi_softc *sc; + struct wi_softc *sc; + struct ifnet *ifp; sc = device_get_softc(dev); + ifp = &sc->arpcom.ac_if; + lwkt_serialize_enter(ifp->if_serializer); wi_stop(sc); - - return; + lwkt_serialize_exit(ifp->if_serializer); } #ifdef WICACHE diff --git a/sys/dev/netif/pcn/if_pcn.c b/sys/dev/netif/pcn/if_pcn.c index e073aef5e7..86ec54ca89 100644 --- a/sys/dev/netif/pcn/if_pcn.c +++ b/sys/dev/netif/pcn/if_pcn.c @@ -31,7 +31,7 @@ * THE POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD: src/sys/pci/if_pcn.c,v 1.5.2.10 2003/03/05 18:42:33 njl Exp $ - * $DragonFly: src/sys/dev/netif/pcn/if_pcn.c,v 1.25 2005/11/22 00:24:33 dillon Exp $ + * $DragonFly: src/sys/dev/netif/pcn/if_pcn.c,v 1.26 2005/11/28 17:13:43 dillon Exp $ */ /* @@ -63,6 +63,7 @@ #include #include #include +#include #include #include @@ -129,8 +130,8 @@ static int pcn_ioctl (struct ifnet *, u_long, caddr_t, struct ucred *); static void pcn_init (void *); static void pcn_stop (struct pcn_softc *); -static void pcn_watchdog (struct ifnet *); -static void pcn_shutdown (device_t); +static void pcn_watchdog (struct ifnet *); +static void pcn_shutdown (device_t); static int pcn_ifmedia_upd (struct ifnet *); static void pcn_ifmedia_sts (struct ifnet *, struct ifmediareq *); @@ -619,10 +620,11 @@ static int pcn_attach(dev) /* * Call MI attach routine. */ - ether_ifattach(ifp, eaddr); + ether_ifattach(ifp, eaddr, NULL); - error = bus_setup_intr(dev, sc->pcn_irq, 0, - pcn_intr, sc, &sc->pcn_intrhand, NULL); + error = bus_setup_intr(dev, sc->pcn_irq, INTR_NETSAFE, + pcn_intr, sc, &sc->pcn_intrhand, + ifp->if_serializer); if (error) { ether_ifdetach(ifp); device_printf(dev, "couldn't set up irq\n"); @@ -640,7 +642,7 @@ static int pcn_detach(dev) struct pcn_softc *sc = device_get_softc(dev); struct ifnet *ifp = &sc->arpcom.ac_if; - crit_enter(); + lwkt_serialize_enter(ifp->if_serializer); if (device_is_attached(dev)) { pcn_reset(sc); @@ -655,8 +657,6 @@ static int pcn_detach(dev) if (sc->pcn_intrhand) bus_teardown_intr(dev, sc->pcn_irq, sc->pcn_intrhand); - crit_enter(); - if (sc->pcn_irq) bus_release_resource(dev, SYS_RES_IRQ, 0, sc->pcn_irq); if (sc->pcn_res) @@ -666,6 +666,7 @@ static int pcn_detach(dev) contigfree(sc->pcn_ldata, sizeof(struct pcn_list_data), M_DEVBUF); } + lwkt_serialize_exit(ifp->if_serializer); return(0); } @@ -809,7 +810,7 @@ static void pcn_rxeof(sc) cur_rx->pcn_rxlen - ETHER_CRC_LEN; m->m_pkthdr.rcvif = ifp; - (*ifp->if_input)(ifp, m); + ifp->if_input(ifp, m); } sc->pcn_cdata.pcn_rx_prod = i; @@ -886,7 +887,7 @@ static void pcn_tick(xsc) struct mii_data *mii; struct ifnet *ifp = &sc->arpcom.ac_if; - crit_enter(); + lwkt_serialize_enter(ifp->if_serializer); mii = device_get_softc(sc->pcn_miibus); mii_tick(mii); @@ -902,10 +903,9 @@ static void pcn_tick(xsc) if (!ifq_is_empty(&ifp->if_snd)) pcn_start(ifp); } - callout_reset(&sc->pcn_stat_timer, hz, pcn_tick, sc); - crit_exit(); + lwkt_serialize_exit(ifp->if_serializer); } static void pcn_intr(arg) @@ -1084,8 +1084,6 @@ static void pcn_init(xsc) struct ifnet *ifp = &sc->arpcom.ac_if; struct mii_data *mii = NULL; - crit_enter(); - /* * Cancel pending I/O and free all RX/TX buffers. */ @@ -1108,7 +1106,6 @@ static void pcn_init(xsc) "memory for rx buffers\n", sc->pcn_unit); pcn_stop(sc); - crit_exit(); return; } @@ -1180,8 +1177,6 @@ static void pcn_init(xsc) ifp->if_flags &= ~IFF_OACTIVE; callout_reset(&sc->pcn_stat_timer, hz, pcn_tick, sc); - - crit_exit(); } /* @@ -1239,8 +1234,6 @@ static int pcn_ioctl(ifp, command, data, cr) struct mii_data *mii = NULL; int error = 0; - crit_enter(); - switch(command) { case SIOCSIFFLAGS: if (ifp->if_flags & IFF_UP) { @@ -1287,9 +1280,6 @@ static int pcn_ioctl(ifp, command, data, cr) error = ether_ioctl(ifp, command, data); break; } - - crit_exit(); - return(error); } @@ -1367,12 +1357,12 @@ static void pcn_stop(sc) static void pcn_shutdown(dev) device_t dev; { - struct pcn_softc *sc; - - sc = device_get_softc(dev); + struct pcn_softc *sc = device_get_softc(dev); + struct ifnet *ifp = &sc->arpcom.ac_if; + lwkt_serialize_enter(ifp->if_serializer); pcn_reset(sc); pcn_stop(sc); - - return; + lwkt_serialize_exit(ifp->if_serializer); } + diff --git a/sys/dev/netif/pdq_layer/pdq_ifsubr.c b/sys/dev/netif/pdq_layer/pdq_ifsubr.c index 6bd817bf3e..22cee9fcfd 100644 --- a/sys/dev/netif/pdq_layer/pdq_ifsubr.c +++ b/sys/dev/netif/pdq_layer/pdq_ifsubr.c @@ -22,7 +22,7 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD: src/sys/dev/pdq/pdq_ifsubr.c,v 1.11.2.1 2000/08/02 22:39:30 peter Exp $ - * $DragonFly: src/sys/dev/netif/pdq_layer/Attic/pdq_ifsubr.c,v 1.13 2005/06/20 15:10:41 joerg Exp $ + * $DragonFly: src/sys/dev/netif/pdq_layer/Attic/pdq_ifsubr.c,v 1.14 2005/11/28 17:13:43 dillon Exp $ * */ @@ -185,7 +185,7 @@ pdq_os_receive_pdu( } m->m_pkthdr.len = pktlen; - (*sc->sc_if.if_input)(&sc->sc_if, m); + sc->sc_if.if_input(&sc->sc_if, m); } void @@ -361,5 +361,5 @@ pdq_ifattach( ifq_set_maxlen(&ifp->if_snd, IFQ_MAXLEN); ifq_set_ready(&ifp->if_snd); - fddi_ifattach(ifp); + fddi_ifattach(ifp, NULL); } diff --git a/sys/dev/netif/plip/if_plip.c b/sys/dev/netif/plip/if_plip.c index 6b9bb81d72..20602f3647 100644 --- a/sys/dev/netif/plip/if_plip.c +++ b/sys/dev/netif/plip/if_plip.c @@ -25,7 +25,7 @@ * * From Id: lpt.c,v 1.55.2.1 1996/11/12 09:08:38 phk Exp * $FreeBSD: src/sys/dev/ppbus/if_plip.c,v 1.19.2.1 2000/05/24 00:20:57 n_hibma Exp $ - * $DragonFly: src/sys/dev/netif/plip/if_plip.c,v 1.15 2005/10/28 03:25:54 dillon Exp $ + * $DragonFly: src/sys/dev/netif/plip/if_plip.c,v 1.16 2005/11/28 17:13:43 dillon Exp $ */ /* @@ -240,7 +240,7 @@ lp_attach (device_t dev) ifp->if_hdrlen = 0; ifp->if_addrlen = 0; ifq_set_maxlen(&ifp->if_snd, IFQ_MAXLEN); - if_attach(ifp); + if_attach(ifp, NULL); bpfattach(ifp, DLT_NULL, sizeof(u_int32_t)); diff --git a/sys/dev/netif/ray/if_ray.c b/sys/dev/netif/ray/if_ray.c index 4d7d9bd18e..b391889c31 100644 --- a/sys/dev/netif/ray/if_ray.c +++ b/sys/dev/netif/ray/if_ray.c @@ -29,7 +29,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/dev/ray/if_ray.c,v 1.47.2.4 2001/08/14 22:54:05 dmlb Exp $ - * $DragonFly: src/sys/dev/netif/ray/Attic/if_ray.c,v 1.25 2005/11/22 00:24:33 dillon Exp $ + * $DragonFly: src/sys/dev/netif/ray/Attic/if_ray.c,v 1.26 2005/11/28 17:13:43 dillon Exp $ * */ @@ -466,11 +466,6 @@ ray_attach(device_t dev) ray_res_release(sc); return (error); } - error = ray_res_alloc_irq(sc); - if (error) { - ray_res_release(sc); - return (error); - } /* * Reset any pending interrupts @@ -528,7 +523,13 @@ ray_attach(device_t dev) callout_init(&sc->tx_timer); TAILQ_INIT(&sc->sc_comq); - ether_ifattach(ifp, ep->e_station_addr); + ether_ifattach(ifp, ep->e_station_addr, NULL); + + error = ray_res_alloc_irq(sc); + if (error) { + ray_detach(dev); + return (error); + } /* * Print out some useful information @@ -579,7 +580,7 @@ ray_detach(device_t dev) struct ifnet *ifp = &sc->arpcom.ac_if; struct ray_comq_entry *com; - crit_enter(); + lwkt_serialize_enter(ifp->if_serializer); RAY_DPRINTF(sc, RAY_DBG_SUBR | RAY_DBG_STOP, ""); @@ -621,7 +622,7 @@ ray_detach(device_t dev) ray_res_release(sc); RAY_DPRINTF(sc, RAY_DBG_STOP, "unloading complete"); - crit_exit(); + lwkt_serialize_exit(ifp->if_serializer); return (0); } @@ -646,8 +647,6 @@ ray_ioctl(register struct ifnet *ifp, u_long command, caddr_t data, error = error2 = 0; - crit_enter(); - switch (command) { case SIOCSIFFLAGS: RAY_DPRINTF(sc, RAY_DBG_IOCTL, "SIFFLAGS 0x%0x", ifp->if_flags); @@ -734,8 +733,6 @@ ray_ioctl(register struct ifnet *ifp, u_long command, caddr_t data, break; } - crit_exit(); - return (error); } @@ -1609,11 +1606,11 @@ ray_tx_timo(void *xsc) RAY_DPRINTF(sc, RAY_DBG_SUBR, ""); + lwkt_serialize_enter(ifp->if_serializer); if ((ifp->if_flags & IFF_OACTIVE) == 0 && !ifq_is_empty(&ifp->if_snd)) { - crit_enter(); ray_tx(ifp); - crit_exit(); } + lwkt_serialize_exit(ifp->if_serializer); } /* @@ -2063,7 +2060,7 @@ ray_rx_data(struct ray_softc *sc, struct mbuf *m0, u_int8_t siglev, u_int8_t ant RAY_MBUF_DUMP(sc, RAY_DBG_RX, m0, "(3) packet after trimming"); ifp->if_ipackets++; ray_rx_update_cache(sc, header->i_addr2, siglev, antenna); - (*ifp->if_input)(ifp, m0); + ifp->if_input(ifp, m0); } /* @@ -3348,8 +3345,7 @@ ray_com_ecf_timo(void *xsc) struct ray_comq_entry *com; u_int8_t cmd, status; - crit_enter(); - + lwkt_serialize_enter(sc->arpcom.ac_if.if_serializer); RAY_DPRINTF(sc, RAY_DBG_SUBR | RAY_DBG_COM, ""); RAY_MAP_CM(sc); @@ -3380,8 +3376,7 @@ ray_com_ecf_timo(void *xsc) break; } - - crit_exit(); + lwkt_serialize_exit(sc->arpcom.ac_if.if_serializer); } /* @@ -3726,8 +3721,9 @@ ray_res_alloc_irq(struct ray_softc *sc) RAY_PRINTF(sc, "Cannot allocate irq"); return (ENOMEM); } - error = bus_setup_intr(sc->dev, sc->irq_res, 0, - ray_intr, sc, &sc->irq_handle, NULL); + error = bus_setup_intr(sc->dev, sc->irq_res, INTR_NETSAFE, + ray_intr, sc, &sc->irq_handle, + sc->arpcom.ac_if.if_serializer); if (error) { RAY_PRINTF(sc, "Failed to setup irq"); return (error); diff --git a/sys/dev/netif/rdp/if_rdp.c b/sys/dev/netif/rdp/if_rdp.c index 345b47e649..23ccd403f7 100644 --- a/sys/dev/netif/rdp/if_rdp.c +++ b/sys/dev/netif/rdp/if_rdp.c @@ -25,7 +25,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/i386/isa/if_rdp.c,v 1.6.2.2 2000/07/17 21:24:32 archie Exp $ - * $DragonFly: src/sys/dev/netif/rdp/if_rdp.c,v 1.20 2005/11/22 00:24:33 dillon Exp $ + * $DragonFly: src/sys/dev/netif/rdp/if_rdp.c,v 1.21 2005/11/28 17:13:43 dillon Exp $ */ /* @@ -75,6 +75,7 @@ #include #include #include +#include #include #include @@ -615,7 +616,7 @@ rdp_attach(struct isa_device *isa_dev) /* * Attach the interface */ - ether_ifattach(ifp, sc->arpcom.ac_enaddr); + ether_ifattach(ifp, sc->arpcom.ac_enaddr, NULL); /* * Print additional info when attached @@ -875,6 +876,8 @@ rdpintr(void *arg) struct ifnet *ifp = (struct ifnet *)sc; u_char isr, tsr, rsr, colls; + lwkt_serialize_enter(ifp->if_serializer); + /* disable interrupts, so SD3 can be routed to the pin */ sc->irqenbit = 0; outb(sc->baseaddr + lpt_control, Ctrl_SelData); @@ -993,6 +996,7 @@ rdpintr(void *arg) WrNib(sc, CMR2, CMR2_IRQOUT | CMR2_IRQINV); sc->irqenbit = Ctrl_IRQEN; outb(sc->baseaddr + lpt_control, Ctrl_SelData + sc->irqenbit); + lwkt_serialize_exit(ifp->if_serializer); } /* @@ -1137,7 +1141,7 @@ rdp_get_packet(struct rdp_softc *sc, unsigned len) outb(sc->baseaddr + lpt_control, Ctrl_SelData); WrNib(sc, CMR1, CMR1_RDPAC); - (*ifp->if_input)(ifp, m); + ifp->if_input(ifp, m); } /* diff --git a/sys/dev/netif/re/if_re.c b/sys/dev/netif/re/if_re.c index 6a45b2cf7b..4f5ae03e5b 100644 --- a/sys/dev/netif/re/if_re.c +++ b/sys/dev/netif/re/if_re.c @@ -33,7 +33,7 @@ * THE POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD: src/sys/dev/re/if_re.c,v 1.25 2004/06/09 14:34:01 naddy Exp $ - * $DragonFly: src/sys/dev/netif/re/if_re.c,v 1.18 2005/11/22 00:24:33 dillon Exp $ + * $DragonFly: src/sys/dev/netif/re/if_re.c,v 1.19 2005/11/28 17:13:43 dillon Exp $ */ /* @@ -122,6 +122,7 @@ #include #include #include +#include #include #include @@ -200,6 +201,7 @@ static void re_rxeof(struct re_softc *); static void re_txeof(struct re_softc *); static void re_intr(void *); static void re_tick(void *); +static void re_tick_serialized(void *); static void re_start(struct ifnet *); static int re_ioctl(struct ifnet *, u_long, caddr_t, struct ucred *); static void re_init(void *); @@ -1159,10 +1161,12 @@ re_attach(device_t dev) /* * Call MI attach routine. */ - ether_ifattach(ifp, eaddr); + ether_ifattach(ifp, eaddr, NULL); + lwkt_serialize_enter(ifp->if_serializer); /* Perform hardware diagnostic. */ error = re_diag(sc); + lwkt_serialize_exit(ifp->if_serializer); if (error) { device_printf(dev, "hardware diagnostic failure\n"); @@ -1171,8 +1175,8 @@ re_attach(device_t dev) } /* Hook interrupt last to avoid having to lock softc */ - error = bus_setup_intr(dev, sc->re_irq, 0, re_intr, sc, - &sc->re_intrhand, NULL); + error = bus_setup_intr(dev, sc->re_irq, INTR_NETSAFE, re_intr, sc, + &sc->re_intrhand, ifp->if_serializer); if (error) { device_printf(dev, "couldn't set up irq\n"); @@ -1201,7 +1205,7 @@ re_detach(device_t dev) struct ifnet *ifp = &sc->arpcom.ac_if; int i; - crit_enter(); + lwkt_serialize_enter(ifp->if_serializer); /* These should only be active if attach succeeded */ if (device_is_attached(dev)) { @@ -1215,8 +1219,6 @@ re_detach(device_t dev) if (sc->re_intrhand) bus_teardown_intr(dev, sc->re_irq, sc->re_intrhand); - crit_exit(); - if (sc->re_irq) bus_release_resource(dev, SYS_RES_IRQ, 0, sc->re_irq); if (sc->re_res) @@ -1271,6 +1273,7 @@ re_detach(device_t dev) if (sc->re_parent_tag) bus_dma_tag_destroy(sc->re_parent_tag); + lwkt_serialize_exit(ifp->if_serializer); return(0); } @@ -1504,11 +1507,12 @@ re_rxeof(struct re_softc *sc) } } - if (rxvlan & RE_RDESC_VLANCTL_TAG) + if (rxvlan & RE_RDESC_VLANCTL_TAG) { VLAN_INPUT_TAG(m, be16toh((rxvlan & RE_RDESC_VLANCTL_DATA))); - else - (*ifp->if_input)(ifp, m); + } else { + ifp->if_input(ifp, m); + } } /* Flush the RX DMA ring */ @@ -1582,16 +1586,22 @@ static void re_tick(void *xsc) { struct re_softc *sc = xsc; - struct mii_data *mii; - crit_enter(); + lwkt_serialize_enter(sc->arpcom.ac_if.if_serializer); + re_tick_serialized(xsc); + lwkt_serialize_exit(sc->arpcom.ac_if.if_serializer); +} + +static void +re_tick_serialized(void *xsc) +{ + struct re_softc *sc = xsc; + struct mii_data *mii; mii = device_get_softc(sc->re_miibus); mii_tick(mii); callout_reset(&sc->re_timer, hz, re_tick, sc); - - crit_exit(); } #ifdef DEVICE_POLLING @@ -1679,7 +1689,7 @@ re_intr(void *arg) } if (status & RE_ISR_LINKCHG) - re_tick(sc); + re_tick_serialized(sc); } if (!ifq_is_empty(&ifp->if_snd)) @@ -1813,8 +1823,6 @@ re_start(struct ifnet *ifp) struct mbuf *m_head2; int called_defrag, idx, need_trans; - crit_enter(); - idx = sc->re_ldata.re_tx_prodidx; need_trans = 0; @@ -1856,7 +1864,6 @@ re_start(struct ifnet *ifp) } if (!need_trans) { - crit_exit(); return; } @@ -1890,8 +1897,6 @@ re_start(struct ifnet *ifp) * Set a timeout in case the chip goes out to lunch. */ ifp->if_timer = 5; - - crit_exit(); } static void @@ -1902,8 +1907,6 @@ re_init(void *xsc) struct mii_data *mii; uint32_t rxcfg = 0; - crit_enter(); - mii = device_get_softc(sc->re_miibus); /* @@ -2049,7 +2052,6 @@ re_init(void *xsc) CSR_WRITE_2(sc, RE_MAXRXPKTLEN, 16383); if (sc->re_testmode) { - crit_exit(); return; } @@ -2061,8 +2063,6 @@ re_init(void *xsc) ifp->if_flags &= ~IFF_OACTIVE; callout_reset(&sc->re_timer, hz, re_tick, sc); - - crit_exit(); } /* @@ -2104,8 +2104,6 @@ re_ioctl(struct ifnet *ifp, u_long command, caddr_t data, struct ucred *cr) struct mii_data *mii; int error = 0; - crit_enter(); - switch(command) { case SIOCSIFMTU: if (ifr->ifr_mtu > RE_JUMBO_MTU) @@ -2144,9 +2142,6 @@ re_ioctl(struct ifnet *ifp, u_long command, caddr_t data, struct ucred *cr) error = ether_ioctl(ifp, command, data); break; } - - crit_exit(); - return(error); } @@ -2157,8 +2152,6 @@ re_watchdog(struct ifnet *ifp) if_printf(ifp, "watchdog timeout\n"); - crit_enter(); - ifp->if_oerrors++; re_txeof(sc); @@ -2168,8 +2161,6 @@ re_watchdog(struct ifnet *ifp) if (!ifq_is_empty(&ifp->if_snd)) ifp->if_start(ifp); - - crit_exit(); } /* @@ -2182,8 +2173,6 @@ re_stop(struct re_softc *sc) struct ifnet *ifp = &sc->arpcom.ac_if; int i; - crit_enter(); - ifp->if_timer = 0; callout_stop(&sc->re_timer); @@ -2216,8 +2205,6 @@ re_stop(struct re_softc *sc) sc->re_ldata.re_rx_mbuf[i] = NULL; } } - - crit_exit(); } /* diff --git a/sys/dev/netif/rl/if_rl.c b/sys/dev/netif/rl/if_rl.c index 0609d81d45..fe4fd63e45 100644 --- a/sys/dev/netif/rl/if_rl.c +++ b/sys/dev/netif/rl/if_rl.c @@ -30,7 +30,7 @@ * THE POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD: src/sys/pci/if_rl.c,v 1.38.2.16 2003/03/05 18:42:33 njl Exp $ - * $DragonFly: src/sys/dev/netif/rl/if_rl.c,v 1.28 2005/11/22 00:24:33 dillon Exp $ + * $DragonFly: src/sys/dev/netif/rl/if_rl.c,v 1.29 2005/11/28 17:13:43 dillon Exp $ */ /* @@ -95,6 +95,7 @@ #include #include #include +#include #include #include @@ -417,8 +418,6 @@ rl_mii_readreg(struct rl_softc *sc, struct rl_mii_frame *frame) { int ack, i; - crit_enter(); - /* * Set up frame for RX. */ @@ -490,8 +489,6 @@ rl_mii_readreg(struct rl_softc *sc, struct rl_mii_frame *frame) MII_SET(RL_MII_CLK); DELAY(1); - crit_exit(); - return(ack ? 1 : 0); } @@ -501,8 +498,6 @@ rl_mii_readreg(struct rl_softc *sc, struct rl_mii_frame *frame) static int rl_mii_writereg(struct rl_softc *sc, struct rl_mii_frame *frame) { - crit_enter(); - /* * Set up frame for TX. */ @@ -535,8 +530,6 @@ rl_mii_writereg(struct rl_softc *sc, struct rl_mii_frame *frame) */ MII_CLR(RL_MII_DIR); - crit_exit(); - return(0); } @@ -934,10 +927,10 @@ rl_attach(device_t dev) /* * Call MI attach routine. */ - ether_ifattach(ifp, eaddr); + ether_ifattach(ifp, eaddr, NULL); - error = bus_setup_intr(dev, sc->rl_irq, 0, rl_intr, - sc, &sc->rl_intrhand, NULL); + error = bus_setup_intr(dev, sc->rl_irq, INTR_NETSAFE, rl_intr, + sc, &sc->rl_intrhand, ifp->if_serializer); if (error) { device_printf(dev, "couldn't set up irq\n"); @@ -961,7 +954,7 @@ rl_detach(device_t dev) sc = device_get_softc(dev); ifp = &sc->arpcom.ac_if; - crit_enter(); + lwkt_serialize_enter(ifp->if_serializer); if (device_is_attached(dev)) { rl_stop(sc); @@ -975,8 +968,6 @@ rl_detach(device_t dev) if (sc->rl_intrhand) bus_teardown_intr(dev, sc->rl_irq, sc->rl_intrhand); - crit_exit(); - if (sc->rl_irq) bus_release_resource(dev, SYS_RES_IRQ, 0, sc->rl_irq); if (sc->rl_res) @@ -992,6 +983,8 @@ rl_detach(device_t dev) if (sc->rl_parent_tag) bus_dma_tag_destroy(sc->rl_parent_tag); + lwkt_serialize_exit(ifp->if_serializer); + return(0); } @@ -1161,7 +1154,7 @@ rl_rxeof(struct rl_softc *sc) ifp->if_ipackets++; - (*ifp->if_input)(ifp, m); + ifp->if_input(ifp, m); } } @@ -1225,14 +1218,14 @@ rl_tick(void *xsc) struct rl_softc *sc = xsc; struct mii_data *mii; - crit_enter(); + lwkt_serialize_enter(sc->arpcom.ac_if.if_serializer); mii = device_get_softc(sc->rl_miibus); mii_tick(mii); callout_reset(&sc->rl_stat_timer, hz, rl_tick, sc); - crit_exit(); + lwkt_serialize_exit(sc->arpcom.ac_if.if_serializer); } #ifdef DEVICE_POLLING @@ -1434,8 +1427,6 @@ rl_init(void *xsc) struct mii_data *mii; uint32_t rxcfg = 0; - crit_enter(); - mii = device_get_softc(sc->rl_miibus); /* @@ -1535,8 +1526,6 @@ rl_init(void *xsc) ifp->if_flags &= ~IFF_OACTIVE; callout_reset(&sc->rl_stat_timer, hz, rl_tick, sc); - - crit_exit(); } /* @@ -1577,8 +1566,6 @@ rl_ioctl(struct ifnet *ifp, u_long command, caddr_t data, struct ucred *cr) struct mii_data *mii; int error = 0; - crit_enter(); - switch (command) { case SIOCSIFFLAGS: if (ifp->if_flags & IFF_UP) { @@ -1606,8 +1593,6 @@ rl_ioctl(struct ifnet *ifp, u_long command, caddr_t data, struct ucred *cr) break; } - crit_exit(); - return(error); } @@ -1618,7 +1603,7 @@ rl_watchdog(struct ifnet *ifp) device_printf(sc->rl_dev, "watchdog timeout\n"); - crit_enter(); + lwkt_serialize_enter(ifp->if_serializer); ifp->if_oerrors++; @@ -1626,7 +1611,7 @@ rl_watchdog(struct ifnet *ifp) rl_rxeof(sc); rl_init(sc); - crit_exit(); + lwkt_serialize_exit(ifp->if_serializer); } /* @@ -1675,8 +1660,9 @@ rl_shutdown(device_t dev) struct rl_softc *sc; sc = device_get_softc(dev); - + lwkt_serialize_enter(sc->arpcom.ac_if.if_serializer); rl_stop(sc); + lwkt_serialize_exit(sc->arpcom.ac_if.if_serializer); } /* @@ -1690,6 +1676,7 @@ rl_suspend(device_t dev) struct rl_softc *sc = device_get_softc(dev); int i; + lwkt_serialize_enter(sc->arpcom.ac_if.if_serializer); rl_stop(sc); for (i = 0; i < 5; i++) @@ -1701,6 +1688,7 @@ rl_suspend(device_t dev) sc->suspended = 1; + lwkt_serialize_exit(sc->arpcom.ac_if.if_serializer); return (0); } @@ -1715,6 +1703,8 @@ static int rl_resume(device_t dev) struct ifnet *ifp = &sc->arpcom.ac_if; int i; + lwkt_serialize_enter(ifp->if_serializer); + /* better way to do this? */ for (i = 0; i < 5; i++) pci_write_config(dev, PCIR_BAR(i), sc->saved_maps[i], 4); @@ -1732,6 +1722,6 @@ static int rl_resume(device_t dev) rl_init(sc); sc->suspended = 0; - + lwkt_serialize_exit(ifp->if_serializer); return (0); } diff --git a/sys/dev/netif/rue/if_rue.c b/sys/dev/netif/rue/if_rue.c index 771fbeae6e..7cf9f1a330 100644 --- a/sys/dev/netif/rue/if_rue.c +++ b/sys/dev/netif/rue/if_rue.c @@ -55,7 +55,7 @@ * THE POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD: src/sys/dev/usb/if_rue.c,v 1.14 2004/06/09 14:34:03 naddy Exp $ - * $DragonFly: src/sys/dev/netif/rue/if_rue.c,v 1.4 2005/11/22 00:24:33 dillon Exp $ + * $DragonFly: src/sys/dev/netif/rue/if_rue.c,v 1.5 2005/11/28 17:13:43 dillon Exp $ */ /* @@ -615,7 +615,7 @@ USB_ATTACH(rue) } /* Call MI attach routine */ - ether_ifattach(ifp, eaddr); + ether_ifattach(ifp, eaddr, NULL); callout_init(&sc->rue_stat_ch); sc->rue_dying = 0; diff --git a/sys/dev/netif/sbni/Makefile b/sys/dev/netif/sbni/Makefile index 092fc0b5e2..a31b61eea4 100644 --- a/sys/dev/netif/sbni/Makefile +++ b/sys/dev/netif/sbni/Makefile @@ -1,9 +1,9 @@ # $FreeBSD: src/sys/modules/sbni/Makefile,v 1.1.2.1 2001/12/19 20:59:29 fjoe Exp $ -# $DragonFly: src/sys/dev/netif/sbni/Makefile,v 1.3 2005/07/28 00:06:10 joerg Exp $ +# $DragonFly: src/sys/dev/netif/sbni/Makefile,v 1.4 2005/11/28 17:13:43 dillon Exp $ KMOD= if_sbni SRCS= if_sbni.c if_sbni_pci.c -SRCS+= bus_if.h device_if.h isa_if.h pci_if.h +SRCS+= bus_if.h device_if.h pci_if.h .include diff --git a/sys/dev/netif/sbni/if_sbni.c b/sys/dev/netif/sbni/if_sbni.c index b1315d4c9e..6671485252 100644 --- a/sys/dev/netif/sbni/if_sbni.c +++ b/sys/dev/netif/sbni/if_sbni.c @@ -25,7 +25,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/dev/sbni/if_sbni.c,v 1.1.2.4 2002/08/11 09:32:00 fjoe Exp $ - * $DragonFly: src/sys/dev/netif/sbni/if_sbni.c,v 1.22 2005/11/22 00:24:33 dillon Exp $ + * $DragonFly: src/sys/dev/netif/sbni/if_sbni.c,v 1.23 2005/11/28 17:13:43 dillon Exp $ */ /* @@ -245,7 +245,7 @@ sbni_attach(struct sbni_softc *sc, int unit, struct sbni_flags flags) (csr0 & 0x01 ? 500000 : 2000000) / (1 << flags.rate); ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST; - ether_ifattach(ifp, sc->arpcom.ac_enaddr); + ether_ifattach(ifp, sc->arpcom.ac_enaddr, NULL); /* device attach does transition from UNCONFIGURED to IDLE state */ @@ -264,8 +264,6 @@ sbni_init(void *xsc) struct sbni_softc *sc =xsc; struct ifnet *ifp = &sc->arpcom.ac_if; - crit_enter(); - /* * kludge to avoid multiple initialization when more than once * protocols configured @@ -281,8 +279,6 @@ sbni_init(void *xsc) /* attempt to start output */ sbni_start(ifp); - - crit_exit(); } @@ -843,7 +839,7 @@ indicate_pkt(struct sbni_softc *sc) m->m_pkthdr.rcvif = ifp; m->m_pkthdr.len = m->m_len = sc->inppos; - (*ifp->if_input)(ifp, m); + ifp->if_input(ifp, m); sc->rx_buf_p = NULL; } @@ -860,7 +856,7 @@ sbni_timeout(void *xsc) struct sbni_softc *sc = xsc; u_char csr0; - crit_enter(); + lwkt_serialize_enter(sc->arpcom.ac_if.if_serializer); csr0 = sbni_inb(sc, CSR0); if (csr0 & RC_CHK) { @@ -882,7 +878,7 @@ sbni_timeout(void *xsc) sbni_outb(sc, CSR0, csr0 | RC_CHK); callout_reset(&sc->sbni_stat_timer, hz / SBNI_HZ, sbni_timeout, sc); - crit_exit(); + lwkt_serialize_exit(sc->arpcom.ac_if.if_serializer); } /* -------------------------------------------------------------------------- */ @@ -1039,8 +1035,6 @@ sbni_ioctl(struct ifnet *ifp, u_long command, caddr_t data, struct ucred *cr) ifr = (struct ifreq *)data; error = 0; - crit_enter(); - switch (command) { case SIOCSIFFLAGS: /* @@ -1127,9 +1121,6 @@ sbni_ioctl(struct ifnet *ifp, u_long command, caddr_t data, struct ucred *cr) error = ether_ioctl(ifp, command, data); break; } - - crit_exit(); - return (error); } diff --git a/sys/dev/netif/sbni/if_sbni_isa.c b/sys/dev/netif/sbni/if_sbni_isa.c deleted file mode 100644 index 5989f0f87c..0000000000 --- a/sys/dev/netif/sbni/if_sbni_isa.c +++ /dev/null @@ -1,168 +0,0 @@ -/* - * Copyright (c) 1997-2001 Granch, Ltd. All rights reserved. - * Author: Denis I.Timofeev - * - * Redistributon and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice unmodified, this list of conditions, and the following - * disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD: src/sys/dev/sbni/if_sbni_isa.c,v 1.1.2.5 2002/08/11 09:32:00 fjoe Exp $ - * $DragonFly: src/sys/dev/netif/sbni/Attic/if_sbni_isa.c,v 1.8 2005/10/12 17:35:52 dillon Exp $ - */ - - -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include - -#include - -#include "if_sbnireg.h" -#include "if_sbnivar.h" - -static int sbni_probe_isa(device_t); -static int sbni_attach_isa(device_t); - -static device_method_t sbni_isa_methods[] = { - /* Device interface */ - DEVMETHOD(device_probe, sbni_probe_isa), - DEVMETHOD(device_attach, sbni_attach_isa), - { 0, 0 } -}; - -static driver_t sbni_isa_driver = { - "sbni", - sbni_isa_methods, - sizeof(struct sbni_softc) -}; - -static devclass_t sbni_isa_devclass; -static struct isa_pnp_id sbni_ids[] = { - { 0, NULL } /* we have no pnp sbni cards atm. */ -}; - -DRIVER_MODULE(if_sbni, isa, sbni_isa_driver, sbni_isa_devclass, 0, 0); - - -static int -sbni_probe_isa(device_t dev) -{ - struct sbni_softc *sc; - int error; - - error = ISA_PNP_PROBE(device_get_parent(dev), dev, sbni_ids); - if (error && error != ENOENT) - return (error); - - sc = device_get_softc(dev); - - sc->io_res = bus_alloc_resource(dev, SYS_RES_IOPORT, &sc->io_rid, - 0ul, ~0ul, SBNI_PORTS, RF_ACTIVE); - if (!sc->io_res) { - printf("sbni: cannot allocate io ports!\n"); - return (ENOENT); - } - - if (sbni_probe(sc) != 0) { - bus_release_resource(dev, SYS_RES_IOPORT, - sc->io_rid, sc->io_res); - return (ENXIO); - } - - device_quiet(dev); - return (0); -} - - -static int -sbni_attach_isa(device_t dev) -{ - struct sbni_softc *sc; - struct sbni_flags flags; - int error; - - sc = device_get_softc(dev); - - printf("sbni%d: port 0x%lx", - next_sbni_unit, rman_get_start(sc->io_res)); - sc->irq_res = bus_alloc_resource_any(dev, SYS_RES_IRQ, &sc->irq_rid, - RF_ACTIVE); - - if (sc->irq_res) { - printf(" irq %ld\n", rman_get_start(sc->irq_res)); - error = bus_setup_intr(dev, sc->irq_res, 0, - sbni_intr, sc, - &sc->irq_handle, NULL); - if (error) { - printf("sbni%d: bus_setup_intr\n", next_sbni_unit); - bus_release_resource( - dev, SYS_RES_IOPORT, sc->io_rid, sc->io_res); - bus_release_resource( - dev, SYS_RES_IRQ, sc->irq_rid, sc->irq_res); - return (error); - } - -#ifndef SBNI_DUAL_COMPOUND - - } else { - printf("\nsbni%d: irq conflict!\n", next_sbni_unit); - bus_release_resource(dev, SYS_RES_IOPORT, - sc->io_rid, sc->io_res); - return (ENOENT); - } - -#else /* SBNI_DUAL_COMPOUND */ - - sc->link = sbni_headlist; - sbni_headlist = sc; - } else { - struct sbni_softc *master; - - if ((master = connect_to_master(sc)) == 0) { - printf("\nsbni%d: failed to alloc irq\n", - next_sbni_unit); - bus_release_resource( - dev, SYS_RES_IOPORT, sc->io_rid, sc->io_res); - return (ENXIO); - } else { - printf(" shared irq with %s\n", - master->arpcom.ac_if.if_xname); - } - } -#endif /* SBNI_DUAL_COMPOUND */ - - *(u_int32_t*)&flags = device_get_flags(dev); - - sbni_attach(sc, next_sbni_unit++, flags); - return (0); -} diff --git a/sys/dev/netif/sbni/if_sbni_pci.c b/sys/dev/netif/sbni/if_sbni_pci.c index 2badc79a22..7c43de7b6e 100644 --- a/sys/dev/netif/sbni/if_sbni_pci.c +++ b/sys/dev/netif/sbni/if_sbni_pci.c @@ -25,7 +25,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/dev/sbni/if_sbni_pci.c,v 1.1.2.4 2002/08/11 09:32:00 fjoe Exp $ - * $DragonFly: src/sys/dev/netif/sbni/if_sbni_pci.c,v 1.8 2005/10/12 17:35:53 dillon Exp $ + * $DragonFly: src/sys/dev/netif/sbni/if_sbni_pci.c,v 1.9 2005/11/28 17:13:43 dillon Exp $ */ @@ -135,29 +135,27 @@ sbni_pci_attach(device_t dev) sc->irq_res = bus_alloc_resource_any(dev, SYS_RES_IRQ, &sc->irq_rid, RF_SHAREABLE); + *(u_int32_t*)&flags = 0; + + sbni_attach(sc, next_sbni_unit++, flags); + if (sc->slave_sc) + sbni_attach(sc->slave_sc, next_sbni_unit++, flags); + if (sc->irq_res) { - printf(" irq %ld\n", rman_get_start(sc->irq_res)); - error = bus_setup_intr(dev, sc->irq_res, 0, + error = bus_setup_intr(dev, sc->irq_res, INTR_NETSAFE, sbni_intr, sc, - &sc->irq_handle, NULL); + &sc->irq_handle, + sc->arpcom.ac_if.if_serializer); if (error) { printf("sbni%d: bus_setup_intr\n", next_sbni_unit); - goto attach_failed; } } else { printf("\nsbni%d: cannot claim irq!\n", next_sbni_unit); - error = ENOENT; - goto attach_failed; } - *(u_int32_t*)&flags = 0; - - sbni_attach(sc, next_sbni_unit++, flags); - if (sc->slave_sc) - sbni_attach(sc->slave_sc, next_sbni_unit++, flags); return (0); -attach_failed: +#if 0 bus_release_resource(dev, SYS_RES_IOPORT, sc->io_rid, sc->io_res); if (sc->irq_res) { bus_release_resource( @@ -166,4 +164,5 @@ attach_failed: if (sc->slave_sc) free(sc->slave_sc, M_DEVBUF); return (error); +#endif } diff --git a/sys/dev/netif/sbsh/if_sbsh.c b/sys/dev/netif/sbsh/if_sbsh.c index 7daae188db..b3ec1a9e2e 100644 --- a/sys/dev/netif/sbsh/if_sbsh.c +++ b/sys/dev/netif/sbsh/if_sbsh.c @@ -24,7 +24,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/dev/sbsh/if_sbsh.c,v 1.3.2.1 2003/04/15 18:15:07 fjoe Exp $ - * $DragonFly: src/sys/dev/netif/sbsh/if_sbsh.c,v 1.21 2005/11/22 00:24:33 dillon Exp $ + * $DragonFly: src/sys/dev/netif/sbsh/if_sbsh.c,v 1.22 2005/11/28 17:13:44 dillon Exp $ */ #include @@ -36,6 +36,7 @@ #include #include #include +#include #include #include @@ -264,10 +265,11 @@ sbsh_attach(device_t dev) ifq_set_maxlen(&ifp->if_snd, IFQ_MAXLEN); ifq_set_ready(&ifp->if_snd); - ether_ifattach(ifp, sc->arpcom.ac_enaddr); + ether_ifattach(ifp, sc->arpcom.ac_enaddr, NULL); - error = bus_setup_intr(dev, sc->irq_res, 0, - sbsh_intr, sc, &sc->intr_hand, NULL); + error = bus_setup_intr(dev, sc->irq_res, INTR_NETSAFE, + sbsh_intr, sc, &sc->intr_hand, + ifp->if_serializer); if (error) { ether_ifdetach(ifp); printf("sbsh%d: couldn't set up irq\n", unit); @@ -287,7 +289,7 @@ sbsh_detach(device_t dev) struct sbsh_softc *sc = device_get_softc(dev); struct ifnet *ifp = &sc->arpcom.ac_if; - crit_enter(); + lwkt_serialize_enter(ifp->if_serializer); if (device_is_attached(dev)) { sbsh_stop(sc); @@ -297,14 +299,13 @@ sbsh_detach(device_t dev) if (sc->intr_hand) bus_teardown_intr(dev, sc->irq_res, sc->intr_hand); - crit_exit(); - if (sc->irq_res) bus_release_resource(dev, SYS_RES_IRQ, 0, sc->irq_res); if (sc->mem_res) bus_release_resource(dev, SYS_RES_MEMORY, PCIR_MAPS + 4, sc->mem_res); + lwkt_serialize_exit(ifp->if_serializer); return (0); } @@ -314,12 +315,8 @@ sbsh_start(struct ifnet *ifp) { struct sbsh_softc *sc = ifp->if_softc; - crit_enter(); - if (sc->state == ACTIVE) start_xmit_frames(ifp->if_softc); - - crit_exit(); } @@ -330,10 +327,7 @@ sbsh_init(void *xsc) struct ifnet *ifp = &sc->arpcom.ac_if; u_int8_t t; - crit_enter(); - if ((ifp->if_flags & IFF_RUNNING) || sc->state == NOT_LOADED) { - crit_exit(); return; } @@ -350,8 +344,6 @@ sbsh_init(void *xsc) ifp->if_flags |= IFF_RUNNING; ifp->if_flags &= ~IFF_OACTIVE; } - - crit_exit(); } @@ -360,8 +352,6 @@ sbsh_stop(struct sbsh_softc *sc) { u_int8_t t; - crit_enter(); - sc->regs->IMR = EXT; t = 0; @@ -377,8 +367,6 @@ sbsh_stop(struct sbsh_softc *sc) sc->regs->IMR = 0; sc->state = DOWN; - - crit_enter(); } @@ -407,8 +395,6 @@ sbsh_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data, struct ucred *cr) int error = 0; u_int8_t t; - crit_enter(); - switch(cmd) { case SIOCLOADFIRMW: if ((error = suser_cred(cr, NULL_CRED_OKAY)) != 0) @@ -497,9 +483,6 @@ sbsh_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data, struct ucred *cr) error = ether_ioctl(ifp, cmd, data); break; } - - crit_exit(); - return (error); } @@ -509,7 +492,9 @@ sbsh_shutdown(device_t dev) { struct sbsh_softc *sc = device_get_softc(dev); + lwkt_serialize_enter(sc->arpcom.ac_if.if_serializer); sbsh_stop(sc); + lwkt_serialize_exit(sc->arpcom.ac_if.if_serializer); } static int @@ -517,11 +502,9 @@ sbsh_suspend(device_t dev) { struct sbsh_softc *sc = device_get_softc(dev); - crit_enter(); - + lwkt_serialize_enter(sc->arpcom.ac_if.if_serializer); sbsh_stop(sc); - - crit_exit(); + lwkt_serialize_exit(sc->arpcom.ac_if.if_serializer); return (0); } @@ -532,13 +515,9 @@ sbsh_resume(device_t dev) struct sbsh_softc *sc = device_get_softc(dev); struct ifnet *ifp = &sc->arpcom.ac_if; - crit_enter(); - if (ifp->if_flags & IFF_UP) sbsh_init(sc); - crit_exit(); - return (0); } @@ -800,7 +779,7 @@ indicate_frames(struct sbsh_softc *sc) sc->rbd[sc->head_rdesc].length & 0x7ff; m->m_pkthdr.rcvif = ifp; - (*ifp->if_input)(ifp, m); + ifp->if_input(ifp, m); ++sc->in_stats.rcvd_pkts; ++ifp->if_ipackets; diff --git a/sys/dev/netif/sf/if_sf.c b/sys/dev/netif/sf/if_sf.c index 2228eccb1e..5cb5c0293c 100644 --- a/sys/dev/netif/sf/if_sf.c +++ b/sys/dev/netif/sf/if_sf.c @@ -30,7 +30,7 @@ * THE POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD: src/sys/pci/if_sf.c,v 1.18.2.8 2001/12/16 15:46:07 luigi Exp $ - * $DragonFly: src/sys/dev/netif/sf/if_sf.c,v 1.24 2005/11/22 00:24:34 dillon Exp $ + * $DragonFly: src/sys/dev/netif/sf/if_sf.c,v 1.25 2005/11/28 17:13:44 dillon Exp $ */ /* @@ -87,6 +87,8 @@ #include #include #include +#include + #include #include @@ -533,8 +535,6 @@ static int sf_ioctl(ifp, command, data, cr) struct mii_data *mii; int error = 0; - crit_enter(); - switch(command) { case SIOCSIFFLAGS: if (ifp->if_flags & IFF_UP) { @@ -570,8 +570,6 @@ static int sf_ioctl(ifp, command, data, cr) break; } - crit_exit(); - return(error); } @@ -797,10 +795,11 @@ static int sf_attach(dev) /* * Call MI attach routine. */ - ether_ifattach(ifp, sc->arpcom.ac_enaddr); + ether_ifattach(ifp, sc->arpcom.ac_enaddr, NULL); - error = bus_setup_intr(dev, sc->sf_irq, 0, - sf_intr, sc, &sc->sf_intrhand, NULL); + error = bus_setup_intr(dev, sc->sf_irq, INTR_NETSAFE, + sf_intr, sc, &sc->sf_intrhand, + ifp->if_serializer); if (error) { ether_ifdetach(ifp); @@ -821,7 +820,7 @@ static int sf_detach(dev) struct sf_softc *sc = device_get_softc(dev); struct ifnet *ifp = &sc->arpcom.ac_if; - crit_enter(); + lwkt_serialize_enter(ifp->if_serializer); if (device_is_attached(dev)) { ether_ifdetach(ifp); @@ -835,8 +834,6 @@ static int sf_detach(dev) if (sc->sf_intrhand) bus_teardown_intr(dev, sc->sf_irq, sc->sf_intrhand); - crit_exit(); - if (sc->sf_irq) bus_release_resource(dev, SYS_RES_IRQ, 0, sc->sf_irq); if(sc->sf_res) @@ -847,6 +844,7 @@ static int sf_detach(dev) M_DEVBUF); } + lwkt_serialize_exit(ifp->if_serializer); return(0); } @@ -992,7 +990,7 @@ static void sf_rxeof(sc) ifp->if_ipackets++; - (*ifp->if_input)(ifp, m); + ifp->if_input(ifp, m); } csr_write_4(sc, SF_CQ_CONSIDX, @@ -1139,8 +1137,6 @@ static void sf_init(xsc) struct ifnet *ifp = &sc->arpcom.ac_if; int i; - crit_enter(); - sf_stop(sc); sf_reset(sc); @@ -1162,7 +1158,6 @@ static void sf_init(xsc) if (sf_init_rx_ring(sc) == ENOBUFS) { printf("sf%d: initialization failed: no " "memory for rx buffers\n", sc->sf_unit); - crit_exit(); return; } @@ -1236,8 +1231,6 @@ static void sf_init(xsc) ifp->if_flags &= ~IFF_OACTIVE; callout_reset(&sc->sf_stat_timer, hz, sf_stats_update, sc); - - crit_exit(); } static int sf_encap(sc, c, m_head) @@ -1429,7 +1422,7 @@ static void sf_stats_update(xsc) u_int32_t *ptr; int i; - crit_enter(); + lwkt_serialize_enter(ifp->if_serializer); ptr = (u_int32_t *)&stats; for (i = 0; i < sizeof(stats)/sizeof(u_int32_t); i++) @@ -1455,7 +1448,7 @@ static void sf_stats_update(xsc) callout_reset(&sc->sf_stat_timer, hz, sf_stats_update, sc); - crit_exit(); + lwkt_serialize_exit(ifp->if_serializer); } static void sf_watchdog(ifp) @@ -1481,11 +1474,14 @@ static void sf_watchdog(ifp) static void sf_shutdown(dev) device_t dev; { - struct sf_softc *sc; + struct sf_softc *sc; + struct ifnet *ifp; sc = device_get_softc(dev); - + ifp = &sc->arpcom.ac_if; + lwkt_serialize_enter(ifp->if_serializer); sf_stop(sc); + lwkt_serialize_exit(ifp->if_serializer); return; } diff --git a/sys/dev/netif/sis/if_sis.c b/sys/dev/netif/sis/if_sis.c index 89d4ae3c80..3261fb00b0 100644 --- a/sys/dev/netif/sis/if_sis.c +++ b/sys/dev/netif/sis/if_sis.c @@ -30,7 +30,7 @@ * THE POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD: src/sys/pci/if_sis.c,v 1.13.4.24 2003/03/05 18:42:33 njl Exp $ - * $DragonFly: src/sys/dev/netif/sis/if_sis.c,v 1.29 2005/11/22 00:24:34 dillon Exp $ + * $DragonFly: src/sys/dev/netif/sis/if_sis.c,v 1.30 2005/11/28 17:13:44 dillon Exp $ */ /* @@ -68,6 +68,7 @@ #include #include #include +#include #include #include @@ -515,8 +516,6 @@ sis_mii_readreg(struct sis_softc *sc, struct sis_mii_frame *frame) { int i, ack; - crit_enter(); - /* * Set up frame for RX. */ @@ -589,8 +588,6 @@ fail: SIO_SET(SIS_MII_CLK); DELAY(1); - crit_exit(); - if (ack) return(1); return(0); @@ -602,8 +599,6 @@ fail: static int sis_mii_writereg(struct sis_softc *sc, struct sis_mii_frame *frame) { - crit_enter(); - /* * Set up frame for TX. */ @@ -637,8 +632,6 @@ sis_mii_writereg(struct sis_softc *sc, struct sis_mii_frame *frame) */ SIO_CLR(SIS_MII_DIR); - crit_exit(); - return(0); } @@ -1302,16 +1295,17 @@ sis_attach(device_t dev) /* * Call MI attach routine. */ - ether_ifattach(ifp, eaddr); + ether_ifattach(ifp, eaddr, NULL); /* * Tell the upper layer(s) we support long frames. */ ifp->if_data.ifi_hdrlen = sizeof(struct ether_vlan_header); - error = bus_setup_intr(dev, sc->sis_irq, 0, + error = bus_setup_intr(dev, sc->sis_irq, INTR_NETSAFE, sis_intr, sc, - &sc->sis_intrhand, NULL); + &sc->sis_intrhand, + ifp->if_serializer); if (error) { device_printf(dev, "couldn't set up irq\n"); @@ -1337,7 +1331,7 @@ sis_detach(device_t dev) struct sis_softc *sc = device_get_softc(dev); struct ifnet *ifp = &sc->arpcom.ac_if; - crit_enter(); + lwkt_serialize_enter(ifp->if_serializer); if (device_is_attached(dev)) { sis_reset(sc); @@ -1351,8 +1345,6 @@ sis_detach(device_t dev) if (sc->sis_intrhand) bus_teardown_intr(dev, sc->sis_irq, sc->sis_intrhand); - crit_exit(); - if (sc->sis_irq) bus_release_resource(dev, SYS_RES_IRQ, 0, sc->sis_irq); if (sc->sis_res) @@ -1380,6 +1372,7 @@ sis_detach(device_t dev) if (sc->sis_parent_tag) bus_dma_tag_destroy(sc->sis_parent_tag); + lwkt_serialize_exit(ifp->if_serializer); return(0); } @@ -1558,7 +1551,7 @@ sis_rxeof(struct sis_softc *sc) } ifp->if_ipackets++; - (*ifp->if_input)(ifp, m); + ifp->if_input(ifp, m); } sc->sis_cdata.sis_rx_prod = i; @@ -1635,7 +1628,7 @@ sis_tick(void *xsc) struct mii_data *mii; struct ifnet *ifp = &sc->arpcom.ac_if; - crit_enter(); + lwkt_serialize_enter(ifp->if_serializer); mii = device_get_softc(sc->sis_miibus); mii_tick(mii); @@ -1650,8 +1643,7 @@ sis_tick(void *xsc) } callout_reset(&sc->sis_timer, hz, sis_tick, sc); - - crit_exit(); + lwkt_serialize_exit(ifp->if_serializer); } #ifdef DEVICE_POLLING @@ -1883,8 +1875,6 @@ sis_init(void *xsc) struct ifnet *ifp = &sc->arpcom.ac_if; struct mii_data *mii; - crit_enter(); - /* * Cancel pending I/O and free all RX/TX buffers. */ @@ -1920,7 +1910,6 @@ sis_init(void *xsc) if_printf(ifp, "initialization failed: " "no memory for rx buffers\n"); sis_stop(sc); - crit_exit(); return; } @@ -2042,8 +2031,6 @@ sis_init(void *xsc) ifp->if_flags &= ~IFF_OACTIVE; callout_reset(&sc->sis_timer, hz, sis_tick, sc); - - crit_exit(); } /* @@ -2094,8 +2081,6 @@ sis_ioctl(struct ifnet *ifp, u_long command, caddr_t data, struct ucred *cr) struct mii_data *mii; int error = 0; - crit_enter(); - switch(command) { case SIOCSIFFLAGS: if (ifp->if_flags & IFF_UP) { @@ -2123,9 +2108,6 @@ sis_ioctl(struct ifnet *ifp, u_long command, caddr_t data, struct ucred *cr) error = ether_ioctl(ifp, command, data); break; } - - crit_exit(); - return(error); } @@ -2212,9 +2194,13 @@ static void sis_shutdown(device_t dev) { struct sis_softc *sc; + struct ifnet *ifp; sc = device_get_softc(dev); - + ifp = &sc->arpcom.ac_if; + lwkt_serialize_enter(ifp->if_serializer); sis_reset(sc); sis_stop(sc); + lwkt_serialize_exit(ifp->if_serializer); } + diff --git a/sys/dev/netif/sk/if_sk.c b/sys/dev/netif/sk/if_sk.c index 2dbba2be87..f4827c9c67 100644 --- a/sys/dev/netif/sk/if_sk.c +++ b/sys/dev/netif/sk/if_sk.c @@ -1,5 +1,3 @@ -/* $OpenBSD: if_sk.c,v 1.33 2003/08/12 05:23:06 nate Exp $ */ - /* * Copyright (c) 1997, 1998, 1999, 2000 * Bill Paul . All rights reserved. @@ -31,8 +29,9 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF * THE POSSIBILITY OF SUCH DAMAGE. * + * $OpenBSD: if_sk.c,v 1.33 2003/08/12 05:23:06 nate Exp $ * $FreeBSD: src/sys/pci/if_sk.c,v 1.19.2.9 2003/03/05 18:42:34 njl Exp $ - * $DragonFly: src/sys/dev/netif/sk/if_sk.c,v 1.39 2005/11/22 00:24:34 dillon Exp $ + * $DragonFly: src/sys/dev/netif/sk/if_sk.c,v 1.40 2005/11/28 17:13:44 dillon Exp $ */ /* @@ -94,8 +93,9 @@ #include #include #include -#include #include +#include +#include #include #include @@ -261,6 +261,7 @@ static device_method_t sk_methods[] = { static DEFINE_CLASS_0(sk, sk_driver, sk_methods, sizeof(struct sk_if_softc)); static devclass_t sk_devclass; +static struct lwkt_serialize sk_serializer; DECLARE_DUMMY_MODULE(if_sk); DRIVER_MODULE(if_sk, pci, skc_driver, skc_devclass, 0, 0); @@ -1072,6 +1073,7 @@ skc_probe(device_t dev) struct sk_type *t; uint16_t vendor, product; + lwkt_serialize_init(&sk_serializer); vendor = pci_get_vendor(dev); product = pci_get_device(dev); @@ -1304,7 +1306,7 @@ sk_attach(device_t dev) /* * Call MI attach routine. */ - ether_ifattach(ifp, sc_if->arpcom.ac_enaddr); + ether_ifattach(ifp, sc_if->arpcom.ac_enaddr, &sk_serializer); callout_init(&sc_if->sk_tick_timer); return(0); @@ -1411,9 +1413,9 @@ skc_attach(device_t dev) goto fail; } - error = bus_setup_intr(dev, sc->sk_irq, 0, + error = bus_setup_intr(dev, sc->sk_irq, INTR_NETSAFE, sk_intr, sc, - &sc->sk_intrhand, NULL); + &sc->sk_intrhand, &sk_serializer); if (error) { printf("skc%d: couldn't set up irq\n", unit); @@ -1523,7 +1525,7 @@ sk_detach(device_t dev) struct sk_if_softc *sc_if = device_get_softc(dev); struct ifnet *ifp = &sc_if->arpcom.ac_if; - crit_enter(); + lwkt_serialize_enter(&sk_serializer); sk_stop(sc_if); ether_ifdetach(ifp); @@ -1533,7 +1535,7 @@ sk_detach(device_t dev) contigfree(sc_if->sk_cdata.sk_jumbo_buf, SK_JMEM, M_DEVBUF); contigfree(sc_if->sk_rdata, sizeof(struct sk_ring_data), M_DEVBUF); - crit_exit(); + lwkt_serialize_exit(&sk_serializer); return(0); } @@ -1543,10 +1545,11 @@ skc_detach(device_t dev) { struct sk_softc *sc; - crit_enter(); - sc = device_get_softc(dev); + /* + * recursed from sk_detach ? don't need serializer + */ bus_generic_detach(dev); if (sc->sk_devs[SK_PORT_A] != NULL) device_delete_child(dev, sc->sk_devs[SK_PORT_A]); @@ -1557,8 +1560,6 @@ skc_detach(device_t dev) bus_release_resource(dev, SYS_RES_IRQ, 0, sc->sk_irq); bus_release_resource(dev, SK_RES, SK_RID, sc->sk_res); - crit_exit(); - return(0); } @@ -1672,6 +1673,8 @@ skc_shutdown(device_t dev) { struct sk_softc *sc = device_get_softc(dev); + lwkt_serialize_enter(&sk_serializer); + /* Turn off the 'driver is loaded' LED. */ CSR_WRITE_2(sc, SK_LED, SK_LED_GREEN_OFF); @@ -1680,6 +1683,7 @@ skc_shutdown(device_t dev) * assert the resets on the attached XMAC(s). */ sk_reset(sc); + lwkt_serialize_exit(&sk_serializer); } static void @@ -1735,7 +1739,7 @@ sk_rxeof(struct sk_if_softc *sc_if) } ifp->if_ipackets++; - (*ifp->if_input)(ifp, m); + ifp->if_input(ifp, m); } sc_if->sk_cdata.sk_rx_prod = i; @@ -1782,11 +1786,16 @@ sk_tick(void *xsc_if) struct mii_data *mii = device_get_softc(sc_if->sk_miibus); int i; - if ((ifp->if_flags & IFF_UP) == 0) + lwkt_serialize_enter(&sk_serializer); + + if ((ifp->if_flags & IFF_UP) == 0) { + lwkt_serialize_exit(&sk_serializer); return; + } if (sc_if->sk_phytype == SK_PHYTYPE_BCOM) { sk_intr_bcom(sc_if); + lwkt_serialize_exit(&sk_serializer); return; } @@ -1804,6 +1813,7 @@ sk_tick(void *xsc_if) if (i != 3) { callout_reset(&sc_if->sk_tick_timer, hz, sk_tick, sc_if); + lwkt_serialize_exit(&sk_serializer); return; } @@ -1813,6 +1823,7 @@ sk_tick(void *xsc_if) mii_tick(mii); mii_pollstat(mii); callout_stop(&sc_if->sk_tick_timer); + lwkt_serialize_exit(&sk_serializer); } static void diff --git a/sys/dev/netif/sn/if_sn.c b/sys/dev/netif/sn/if_sn.c index 2f7e45c8b9..2af1a0c7bf 100644 --- a/sys/dev/netif/sn/if_sn.c +++ b/sys/dev/netif/sn/if_sn.c @@ -29,7 +29,7 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD: src/sys/dev/sn/if_sn.c,v 1.7.2.3 2001/02/04 04:38:38 toshi Exp $ - * $DragonFly: src/sys/dev/netif/sn/if_sn.c,v 1.23 2005/11/22 00:24:34 dillon Exp $ + * $DragonFly: src/sys/dev/netif/sn/if_sn.c,v 1.24 2005/11/28 17:13:44 dillon Exp $ */ /* @@ -91,6 +91,7 @@ #include #include #include +#include #include #include @@ -175,6 +176,7 @@ sn_attach(device_t dev) int rev; u_short address; int j; + int error; sn_activate(dev); @@ -226,7 +228,16 @@ sn_attach(device_t dev) ifq_set_ready(&ifp->if_snd); ifp->if_timer = 0; - ether_ifattach(ifp, sc->arpcom.ac_enaddr); + ether_ifattach(ifp, sc->arpcom.ac_enaddr, NULL); + + error = bus_setup_intr(dev, sc->irq_res, INTR_NETSAFE, + sn_intr, sc, &sc->intrhand, + ifp->if_serializer); + if (error) { + ether_ifdetach(ifp); + sn_deactivate(dev); + return error; + } return 0; } @@ -243,8 +254,6 @@ sninit(void *xsc) int flags; int mask; - crit_enter(); - /* * This resets the registers mostly to defaults, but doesn't affect * EEPROM. After the reset cycle, we pause briefly for the chip to @@ -328,8 +337,6 @@ sninit(void *xsc) * Attempt to push out any waiting packets. */ snstart(ifp); - - crit_exit(); } @@ -347,14 +354,10 @@ snstart(struct ifnet *ifp) u_char packet_no; int time_out; - crit_enter(); - if (ifp->if_flags & IFF_OACTIVE) { - crit_exit(); return; } if (sc->pages_wanted != -1) { - crit_exit(); printf("%s: snstart() while memory allocation pending\n", ifp->if_xname); return; @@ -366,7 +369,6 @@ startagain: */ m = ifq_poll(&ifp->if_snd); if (m == 0) { - crit_exit(); return; } /* @@ -446,7 +448,6 @@ startagain: ifp->if_flags |= IFF_OACTIVE; sc->pages_wanted = numPages; - crit_exit(); return; } /* @@ -542,8 +543,6 @@ readcheck: */ if (inw(BASE + FIFO_PORTS_REG_W) & FIFO_REMPTY) goto startagain; - - crit_exit(); } @@ -758,8 +757,6 @@ sn_intr(void *arg) u_short tx_status; u_short card_stats; - crit_enter(); - /* * Clear the watchdog. */ @@ -963,8 +960,6 @@ out: mask |= inb(BASE + INTR_MASK_REG_B); outb(BASE + INTR_MASK_REG_B, mask); sc->intr_mask = mask; - - crit_exit(); } void @@ -1066,7 +1061,7 @@ read_another: m->m_pkthdr.len = m->m_len = packet_length; - (*ifp->if_input)(ifp, m); + ifp->if_input(ifp, m); out: @@ -1101,8 +1096,6 @@ snioctl(struct ifnet *ifp, u_long cmd, caddr_t data, struct ucred *cr) struct sn_softc *sc = ifp->if_softc; int error = 0; - crit_enter(); - switch (cmd) { case SIOCSIFFLAGS: if ((ifp->if_flags & IFF_UP) == 0 && ifp->if_flags & IFF_RUNNING) { @@ -1138,30 +1131,20 @@ snioctl(struct ifnet *ifp, u_long cmd, caddr_t data, struct ucred *cr) break; } - crit_exit(); - return (error); } void snreset(struct sn_softc *sc) { - crit_enter(); - snstop(sc); sninit(sc); - - crit_exit(); } void snwatchdog(struct ifnet *ifp) { - crit_enter(); - sn_intr(ifp->if_softc); - - crit_exit(); } @@ -1199,7 +1182,6 @@ int sn_activate(device_t dev) { struct sn_softc *sc = device_get_softc(dev); - int err; sc->port_rid = 0; sc->port_res = bus_alloc_resource(dev, SYS_RES_IOPORT, &sc->port_rid, @@ -1221,12 +1203,6 @@ sn_activate(device_t dev) sn_deactivate(dev); return ENOMEM; } - err = bus_setup_intr(dev, sc->irq_res, 0, sn_intr, sc, - &sc->intrhand, NULL); - if (err) { - sn_deactivate(dev); - return err; - } sc->sn_io_addr = rman_get_start(sc->port_res); return (0); diff --git a/sys/dev/netif/sr/if_sr.c b/sys/dev/netif/sr/if_sr.c index c89762e7ec..15734bf01a 100644 --- a/sys/dev/netif/sr/if_sr.c +++ b/sys/dev/netif/sr/if_sr.c @@ -28,7 +28,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/dev/sr/if_sr.c,v 1.48.2.1 2002/06/17 15:10:58 jhay Exp $ - * $DragonFly: src/sys/dev/netif/sr/if_sr.c,v 1.16 2005/10/12 17:35:53 dillon Exp $ + * $DragonFly: src/sys/dev/netif/sr/if_sr.c,v 1.17 2005/11/28 17:13:44 dillon Exp $ */ /* @@ -433,7 +433,7 @@ sr_attach(device_t device) sc->ifsppp.pp_flags = PP_KEEPALIVE; sppp_attach((struct ifnet *)&sc->ifsppp); - if_attach(ifp); + if_attach(ifp, NULL); bpfattach(ifp, DLT_PPP, PPP_HEADER_LEN); #else /* NETGRAPH */ diff --git a/sys/dev/netif/ste/if_ste.c b/sys/dev/netif/ste/if_ste.c index cc61413101..07e71b45ee 100644 --- a/sys/dev/netif/ste/if_ste.c +++ b/sys/dev/netif/ste/if_ste.c @@ -30,7 +30,7 @@ * THE POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD: src/sys/pci/if_ste.c,v 1.14.2.9 2003/02/05 22:03:57 mbr Exp $ - * $DragonFly: src/sys/dev/netif/ste/if_ste.c,v 1.30 2005/11/22 00:24:34 dillon Exp $ + * $DragonFly: src/sys/dev/netif/ste/if_ste.c,v 1.31 2005/11/28 17:13:44 dillon Exp $ */ #include @@ -40,6 +40,7 @@ #include #include #include +#include #include #include @@ -241,8 +242,6 @@ static int ste_mii_readreg(sc, frame) { int i, ack; - crit_enter(); - /* * Set up frame for RX. */ @@ -316,8 +315,6 @@ fail: MII_SET(STE_PHYCTL_MCLK); DELAY(1); - crit_exit(); - if (ack) return(1); return(0); @@ -331,8 +328,6 @@ static int ste_mii_writereg(sc, frame) struct ste_mii_frame *frame; { - - crit_enter(); /* * Set up frame for TX. */ @@ -366,8 +361,6 @@ static int ste_mii_writereg(sc, frame) */ MII_CLR(STE_PHYCTL_MDIR); - crit_exit(); - return(0); } @@ -716,7 +709,7 @@ static void ste_rxeof(sc) m->m_pkthdr.rcvif = ifp; m->m_pkthdr.len = m->m_len = total_len; - (*ifp->if_input)(ifp, m); + ifp->if_input(ifp, m); cur_rx->ste_ptr->ste_status = 0; count++; @@ -805,12 +798,12 @@ static void ste_stats_update(xsc) struct ifnet *ifp; struct mii_data *mii; - crit_enter(); - sc = xsc; ifp = &sc->arpcom.ac_if; mii = device_get_softc(sc->ste_miibus); + lwkt_serialize_enter(ifp->if_serializer); + ifp->if_collisions += CSR_READ_1(sc, STE_LATE_COLLS) + CSR_READ_1(sc, STE_MULTI_COLLS) + CSR_READ_1(sc, STE_SINGLE_COLLS); @@ -831,9 +824,7 @@ static void ste_stats_update(xsc) } callout_reset(&sc->ste_stat_timer, hz, ste_stats_update, sc); - crit_exit(); - - return; + lwkt_serialize_exit(ifp->if_serializer); } @@ -987,15 +978,16 @@ static int ste_attach(dev) /* * Call MI attach routine. */ - ether_ifattach(ifp, eaddr); + ether_ifattach(ifp, eaddr, NULL); /* * Tell the upper layer(s) we support long frames. */ ifp->if_data.ifi_hdrlen = sizeof(struct ether_vlan_header); - error = bus_setup_intr(dev, sc->ste_irq, 0, - ste_intr, sc, &sc->ste_intrhand, NULL); + error = bus_setup_intr(dev, sc->ste_irq, INTR_NETSAFE, + ste_intr, sc, &sc->ste_intrhand, + ifp->if_serializer); if (error) { device_printf(dev, "couldn't set up irq\n"); ether_ifdetach(ifp); @@ -1015,10 +1007,9 @@ static int ste_detach(dev) struct ste_softc *sc; struct ifnet *ifp; - crit_enter(); - sc = device_get_softc(dev); ifp = &sc->arpcom.ac_if; + lwkt_serialize_enter(ifp->if_serializer); if (device_is_attached(dev)) { if (bus_child_present(dev)) @@ -1032,8 +1023,6 @@ static int ste_detach(dev) if (sc->ste_intrhand != NULL) bus_teardown_intr(dev, sc->ste_irq, sc->ste_intrhand); - crit_exit(); - if (sc->ste_irq != NULL) bus_release_resource(dev, SYS_RES_IRQ, 0, sc->ste_irq); if (sc->ste_res != NULL) @@ -1042,6 +1031,7 @@ static int ste_detach(dev) contigfree(sc->ste_ldata, sizeof(struct ste_list_data), M_DEVBUF); } + lwkt_serialize_exit(ifp->if_serializer); return(0); } @@ -1155,8 +1145,6 @@ static void ste_init(xsc) struct ifnet *ifp; struct mii_data *mii; - crit_enter(); - sc = xsc; ifp = &sc->arpcom.ac_if; mii = device_get_softc(sc->ste_miibus); @@ -1173,7 +1161,6 @@ static void ste_init(xsc) if_printf(ifp, "initialization failed: no " "memory for RX buffers\n"); ste_stop(sc); - crit_exit(); return; } @@ -1252,11 +1239,7 @@ static void ste_init(xsc) ifp->if_flags |= IFF_RUNNING; ifp->if_flags &= ~IFF_OACTIVE; - crit_exit(); - callout_reset(&sc->ste_stat_timer, hz, ste_stats_update, sc); - - return; } static void ste_stop(sc) @@ -1341,8 +1324,6 @@ static int ste_ioctl(ifp, command, data, cr) struct mii_data *mii; int error = 0; - crit_enter(); - sc = ifp->if_softc; ifr = (struct ifreq *)data; @@ -1385,9 +1366,6 @@ static int ste_ioctl(ifp, command, data, cr) error = ether_ioctl(ifp, command, data); break; } - - crit_exit(); - return(error); } diff --git a/sys/dev/netif/ti/if_ti.c b/sys/dev/netif/ti/if_ti.c index 22ac4ea7b4..cebd8ce48b 100644 --- a/sys/dev/netif/ti/if_ti.c +++ b/sys/dev/netif/ti/if_ti.c @@ -30,7 +30,7 @@ * THE POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD: src/sys/pci/if_ti.c,v 1.25.2.14 2002/02/15 04:20:20 silby Exp $ - * $DragonFly: src/sys/dev/netif/ti/if_ti.c,v 1.37 2005/11/22 00:24:34 dillon Exp $ + * $DragonFly: src/sys/dev/netif/ti/if_ti.c,v 1.38 2005/11/28 17:13:44 dillon Exp $ */ /* @@ -87,6 +87,7 @@ #include #include #include +#include #include #include @@ -1553,10 +1554,11 @@ ti_attach(device_t dev) /* * Call MI attach routine. */ - ether_ifattach(ifp, eaddr); + ether_ifattach(ifp, eaddr, NULL); - error = bus_setup_intr(dev, sc->ti_irq, 0, - ti_intr, sc, &sc->ti_intrhand, NULL); + error = bus_setup_intr(dev, sc->ti_irq, INTR_NETSAFE, + ti_intr, sc, &sc->ti_intrhand, + ifp->if_serializer); if (error) { device_printf(dev, "couldn't set up irq\n"); ether_ifdetach(ifp); @@ -1575,7 +1577,7 @@ ti_detach(device_t dev) struct ti_softc *sc = device_get_softc(dev); struct ifnet *ifp = &sc->arpcom.ac_if; - crit_enter(); + lwkt_serialize_enter(ifp->if_serializer); if (device_is_attached(dev)) { if (bus_child_present(dev)) @@ -1586,8 +1588,6 @@ ti_detach(device_t dev) if (sc->ti_intrhand != NULL) bus_teardown_intr(dev, sc->ti_irq, sc->ti_intrhand); - crit_exit(); - if (sc->ti_irq != NULL) bus_release_resource(dev, SYS_RES_IRQ, 0, sc->ti_irq); if (sc->ti_res != NULL) { @@ -1600,6 +1600,8 @@ ti_detach(device_t dev) contigfree(sc->ti_rdata, sizeof(struct ti_ring_data), M_DEVBUF); ifmedia_removeall(&sc->ifmedia); + lwkt_serialize_exit(ifp->if_serializer); + return(0); } @@ -1696,10 +1698,12 @@ ti_rxeof(struct ti_softc *sc) * If we received a packet with a vlan tag, pass it * to vlan_input() instead of ether_input(). */ + lwkt_serialize_enter(ifp->if_serializer); if (have_tag) VLAN_INPUT_TAG(m, vlan_tag); else - (*ifp->if_input)(ifp, m); + ifp->if_input(ifp, m); + lwkt_serialize_exit(ifp->if_serializer); } /* Only necessary on the Tigon 1. */ @@ -1970,19 +1974,14 @@ ti_init(void *xsc) { struct ti_softc *sc = xsc; - crit_enter(); - /* Cancel pending I/O and flush buffers. */ ti_stop(sc); /* Init the gen info block, ring control blocks and firmware. */ if (ti_gibinit(sc)) { if_printf(&sc->arpcom.ac_if, "initialization failure\n"); - crit_exit(); return; } - - crit_exit(); } static void @@ -2176,8 +2175,6 @@ ti_ioctl(struct ifnet *ifp, u_long command, caddr_t data, struct ucred *cr) struct ti_cmd_desc cmd; int error = 0, mask; - crit_enter(); - switch(command) { case SIOCSIFMTU: if (ifr->ifr_mtu > TI_JUMBO_MTU) @@ -2242,9 +2239,6 @@ ti_ioctl(struct ifnet *ifp, u_long command, caddr_t data, struct ucred *cr) error = ether_ioctl(ifp, command, data); break; } - - crit_exit(); - return(error); } diff --git a/sys/dev/netif/tl/if_tl.c b/sys/dev/netif/tl/if_tl.c index 76690ee7d0..ce01f41712 100644 --- a/sys/dev/netif/tl/if_tl.c +++ b/sys/dev/netif/tl/if_tl.c @@ -30,7 +30,7 @@ * THE POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD: src/sys/pci/if_tl.c,v 1.51.2.5 2001/12/16 15:46:08 luigi Exp $ - * $DragonFly: src/sys/dev/netif/tl/if_tl.c,v 1.32 2005/11/22 00:24:34 dillon Exp $ + * $DragonFly: src/sys/dev/netif/tl/if_tl.c,v 1.33 2005/11/28 17:13:44 dillon Exp $ */ /* @@ -186,6 +186,7 @@ #include #include #include +#include #include #include @@ -273,6 +274,7 @@ static int tl_intvec_netsts (void *, u_int32_t); static int tl_newbuf (struct tl_softc *, struct tl_chain_onefrag *); static void tl_stats_update (void *); +static void tl_stats_update_serialized(void *); static int tl_encap (struct tl_softc *, struct tl_chain *, struct mbuf *); @@ -648,8 +650,6 @@ static int tl_mii_readreg(sc, frame) int i, ack; int minten = 0; - crit_enter(); - tl_mii_sync(sc); /* @@ -728,8 +728,6 @@ fail: tl_dio_setbit(sc, TL_NETSIO, TL_SIO_MINTEN); } - crit_exit(); - if (ack) return(1); return(0); @@ -744,7 +742,6 @@ static int tl_mii_writereg(sc, frame) tl_mii_sync(sc); - crit_enter(); /* * Set up frame for TX. */ @@ -785,8 +782,6 @@ static int tl_mii_writereg(sc, frame) if (minten) tl_dio_setbit(sc, TL_NETSIO, TL_SIO_MINTEN); - crit_exit(); - return(0); } @@ -1281,10 +1276,11 @@ static int tl_attach(dev) /* * Call MI attach routine. */ - ether_ifattach(ifp, eaddr); + ether_ifattach(ifp, eaddr, NULL); - error = bus_setup_intr(dev, sc->tl_irq, 0, - tl_intr, sc, &sc->tl_intrhand, NULL); + error = bus_setup_intr(dev, sc->tl_irq, INTR_NETSAFE, + tl_intr, sc, &sc->tl_intrhand, + ifp->if_serializer); if (error) { ether_ifdetach(ifp); @@ -1305,7 +1301,7 @@ static int tl_detach(dev) struct tl_softc *sc = device_get_softc(dev); struct ifnet *ifp = &sc->arpcom.ac_if; - crit_enter(); + lwkt_serialize_enter(ifp->if_serializer); if (device_is_attached(dev)) { tl_stop(sc); @@ -1316,8 +1312,6 @@ static int tl_detach(dev) device_delete_child(dev, sc->tl_miibus); bus_generic_detach(dev); - crit_exit(); - if (sc->tl_ldata) contigfree(sc->tl_ldata, sizeof(struct tl_list_data), M_DEVBUF); if (sc->tl_bitrate) @@ -1329,6 +1323,7 @@ static int tl_detach(dev) if (sc->tl_res) bus_release_resource(dev, TL_RES, TL_RID, sc->tl_res); + lwkt_serialize_exit(ifp->if_serializer); return(0); } @@ -1488,7 +1483,7 @@ static int tl_intvec_rxeof(xsc, type) continue; } - (*ifp->if_input)(ifp, m); + ifp->if_input(ifp, m); } return(r); @@ -1687,7 +1682,7 @@ static void tl_intr(xsc) r = tl_intvec_txeoc((void *)sc, type); break; case (TL_INTR_STATOFLOW): - tl_stats_update(sc); + tl_stats_update_serialized(sc); r = 1; break; case (TL_INTR_RXEOF): @@ -1722,8 +1717,21 @@ static void tl_intr(xsc) return; } -static void tl_stats_update(xsc) - void *xsc; +static +void +tl_stats_update(void *xsc) +{ + struct tl_softc *sc = xsc; + struct ifnet *ifp = &sc->arpcom.ac_if; + + lwkt_serialize_enter(ifp->if_serializer); + tl_stats_update_serialized(xsc); + lwkt_serialize_exit(ifp->if_serializer); +} + +static +void +tl_stats_update_serialized(void *xsc) { struct tl_softc *sc; struct ifnet *ifp; @@ -1731,8 +1739,6 @@ static void tl_stats_update(xsc) struct mii_data *mii; u_int32_t *p; - crit_enter(); - bzero((char *)&tl_stats, sizeof(struct tl_stats)); sc = xsc; @@ -1775,10 +1781,6 @@ static void tl_stats_update(xsc) mii = device_get_softc(sc->tl_miibus); mii_tick(mii); } - - crit_exit(); - - return; } /* @@ -1965,8 +1967,6 @@ static void tl_init(xsc) struct ifnet *ifp = &sc->arpcom.ac_if; struct mii_data *mii; - crit_enter(); - /* * Cancel pending I/O. */ @@ -2036,8 +2036,6 @@ static void tl_init(xsc) /* Start the stats update counter */ callout_reset(&sc->tl_stat_timer, hz, tl_stats_update, sc); - - crit_exit(); } /* @@ -2105,8 +2103,6 @@ static int tl_ioctl(ifp, command, data, cr) struct ifreq *ifr = (struct ifreq *) data; int error = 0; - crit_enter(); - switch(command) { case SIOCSIFFLAGS: if (ifp->if_flags & IFF_UP) { @@ -2150,9 +2146,6 @@ static int tl_ioctl(ifp, command, data, cr) error = ether_ioctl(ifp, command, data); break; } - - crit_exit(); - return(error); } diff --git a/sys/dev/netif/tx/if_tx.c b/sys/dev/netif/tx/if_tx.c index 826aa22e71..66a98df5da 100644 --- a/sys/dev/netif/tx/if_tx.c +++ b/sys/dev/netif/tx/if_tx.c @@ -24,7 +24,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/dev/tx/if_tx.c,v 1.61.2.1 2002/10/29 01:43:49 semenu Exp $ - * $DragonFly: src/sys/dev/netif/tx/if_tx.c,v 1.32 2005/11/22 00:24:34 dillon Exp $ + * $DragonFly: src/sys/dev/netif/tx/if_tx.c,v 1.33 2005/11/28 17:13:44 dillon Exp $ */ /* @@ -47,6 +47,7 @@ #include #include #include +#include #include #include @@ -270,11 +271,12 @@ epic_attach(device_t dev) printf("\n"); /* Attach to OS's managers */ - ether_ifattach(ifp, sc->sc_macaddr); + ether_ifattach(ifp, sc->sc_macaddr, NULL); ifp->if_hdrlen = sizeof(struct ether_vlan_header); - error = bus_setup_intr(dev, sc->irq, 0, - epic_intr, sc, &sc->sc_ih, NULL); + error = bus_setup_intr(dev, sc->irq, INTR_NETSAFE, + epic_intr, sc, &sc->sc_ih, + ifp->if_serializer); if (error) { device_printf(dev, "couldn't set up irq\n"); @@ -301,7 +303,7 @@ epic_detach(device_t dev) sc = device_get_softc(dev); ifp = &sc->arpcom.ac_if; - crit_enter(); + lwkt_serialize_enter(ifp->if_serializer); if (device_is_attached(dev)) { ether_ifdetach(ifp); @@ -315,8 +317,6 @@ epic_detach(device_t dev) if (sc->sc_ih) bus_teardown_intr(dev, sc->irq, sc->sc_ih); - crit_exit(); - if (sc->irq) bus_release_resource(dev, SYS_RES_IRQ, 0, sc->irq); if (sc->res) @@ -329,6 +329,7 @@ epic_detach(device_t dev) if (sc->rx_desc) free(sc->rx_desc, M_DEVBUF); + lwkt_serialize_exit(ifp->if_serializer); return(0); } @@ -343,12 +344,13 @@ static void epic_shutdown(device_t dev) { epic_softc_t *sc; + struct ifnet *ifp; sc = device_get_softc(dev); - + ifp = &sc->arpcom.ac_if; + lwkt_serialize_enter(ifp->if_serializer); epic_stop(sc); - - return; + lwkt_serialize_exit(ifp->if_serializer); } /* @@ -362,8 +364,6 @@ epic_ifioctl(struct ifnet *ifp, u_long command, caddr_t data, struct ucred *cr) struct ifreq *ifr = (struct ifreq *) data; int error = 0; - crit_enter(); - switch (command) { case SIOCSIFMTU: if (ifp->if_mtu == ifr->ifr_mtu) @@ -423,8 +423,6 @@ epic_ifioctl(struct ifnet *ifp, u_long command, caddr_t data, struct ucred *cr) error = ether_ioctl(ifp, command, data); break; } - crit_exit(); - return error; } @@ -608,7 +606,7 @@ epic_rx_done(epic_softc_t *sc) m->m_pkthdr.len = m->m_len = len; /* Give mbuf to OS */ - (*ifp->if_input)(ifp, m); + ifp->if_input(ifp, m); /* Successfuly received frame */ ifp->if_ipackets++; @@ -774,8 +772,6 @@ epic_ifwatchdog(struct ifnet *ifp) { epic_softc_t *sc = ifp->if_softc; - crit_enter(); - if_printf(ifp, "device timeout %d packets\n", sc->pending_txs); /* Try to finish queued packets */ @@ -797,8 +793,6 @@ epic_ifwatchdog(struct ifnet *ifp) /* Start output */ if (!ifq_is_empty(&ifp->if_snd)) epic_ifstart(ifp); - - crit_exit(); } /* @@ -809,16 +803,17 @@ static void epic_stats_update(void *xsc) { epic_softc_t *sc = xsc; + struct ifnet *ifp = &sc->sc_if; struct mii_data * mii; - crit_enter(); + lwkt_serialize_enter(ifp->if_serializer); mii = device_get_softc(sc->miibus); mii_tick(mii); callout_reset(&sc->tx_stat_timer, hz, epic_stats_update, sc); - crit_exit(); + lwkt_serialize_exit(ifp->if_serializer); } /* @@ -1065,11 +1060,8 @@ epic_init(epic_softc_t *sc) struct ifnet *ifp = &sc->sc_if; int i; - crit_enter(); - /* If interface is already running, then we need not do anything */ if (ifp->if_flags & IFF_RUNNING) { - crit_exit(); return 0; } @@ -1092,7 +1084,6 @@ epic_init(epic_softc_t *sc) /* Initialize rings */ if (epic_init_rings(sc)) { if_printf(ifp, "failed to init rings\n"); - crit_exit(); return -1; } @@ -1143,8 +1134,6 @@ epic_init(epic_softc_t *sc) callout_reset(&sc->tx_stat_timer, hz, epic_stats_update, sc); - crit_exit(); - return 0; } @@ -1355,9 +1344,6 @@ epic_queue_last_packet(epic_softc_t *sc) static void epic_stop(epic_softc_t *sc) { - - crit_enter(); - sc->sc_if.if_timer = 0; callout_stop(&sc->tx_stat_timer); @@ -1381,9 +1367,6 @@ epic_stop(epic_softc_t *sc) /* Mark as stoped */ sc->sc_if.if_flags &= ~IFF_RUNNING; - - crit_exit(); - return; } /* diff --git a/sys/dev/netif/txp/if_txp.c b/sys/dev/netif/txp/if_txp.c index 43eef8be70..53570f607b 100644 --- a/sys/dev/netif/txp/if_txp.c +++ b/sys/dev/netif/txp/if_txp.c @@ -1,6 +1,6 @@ /* $OpenBSD: if_txp.c,v 1.48 2001/06/27 06:34:50 kjc Exp $ */ /* $FreeBSD: src/sys/dev/txp/if_txp.c,v 1.4.2.4 2001/12/14 19:50:43 jlemon Exp $ */ -/* $DragonFly: src/sys/dev/netif/txp/if_txp.c,v 1.32 2005/11/22 00:24:34 dillon Exp $ */ +/* $DragonFly: src/sys/dev/netif/txp/if_txp.c,v 1.33 2005/11/28 17:13:44 dillon Exp $ */ /* * Copyright (c) 2001 @@ -47,6 +47,7 @@ #include #include #include +#include #include #include @@ -312,10 +313,11 @@ txp_attach(dev) ifp->if_hwassist = 0; txp_capabilities(sc); - ether_ifattach(ifp, enaddr); + ether_ifattach(ifp, enaddr, NULL); - error = bus_setup_intr(dev, sc->sc_irq, 0, - txp_intr, sc, &sc->sc_intrhand, NULL); + error = bus_setup_intr(dev, sc->sc_irq, INTR_NETSAFE, + txp_intr, sc, &sc->sc_intrhand, + ifp->if_serializer); if (error) { device_printf(dev, "couldn't set up irq\n"); ether_ifdetach(ifp); @@ -337,10 +339,9 @@ txp_detach(dev) struct ifnet *ifp; int i; - crit_enter(); - sc = device_get_softc(dev); ifp = &sc->sc_arpcom.ac_if; + lwkt_serialize_enter(ifp->if_serializer); txp_stop(sc); txp_shutdown(dev); @@ -352,8 +353,7 @@ txp_detach(dev) free(sc->sc_rxbufs[i].rb_sd, M_DEVBUF); txp_release_resources(dev); - - crit_exit(); + lwkt_serialize_exit(ifp->if_serializer); return(0); } @@ -738,10 +738,12 @@ txp_rx_reclaim(sc, r) m->m_pkthdr.csum_data = 0xffff; } + lwkt_serialize_enter(ifp->if_serializer); if (rxd->rx_stat & RX_STAT_VLAN) VLAN_INPUT_TAG(m, htons(rxd->rx_vlan >> 16)); else - (*ifp->if_input)(ifp, m); + ifp->if_input(ifp, m); + lwkt_serialize_exit(ifp->if_serializer); next: @@ -867,8 +869,11 @@ txp_shutdown(dev) device_t dev; { struct txp_softc *sc; + struct ifnet *ifp; sc = device_get_softc(dev); + ifp = &sc->sc_arpcom.ac_if; + lwkt_serialize_enter(ifp->if_serializer); /* mask all interrupts */ WRITE_REG(sc, TXP_IMR, @@ -880,6 +885,7 @@ txp_shutdown(dev) txp_command(sc, TXP_CMD_RX_DISABLE, 0, 0, 0, NULL, NULL, NULL, 0); txp_command(sc, TXP_CMD_HALT, 0, 0, 0, NULL, NULL, NULL, 0); + lwkt_serialize_exit(ifp->if_serializer); return(0); } @@ -1029,8 +1035,6 @@ txp_ioctl(ifp, command, data, cr) struct ifreq *ifr = (struct ifreq *)data; int error = 0; - crit_enter(); - switch(command) { case SIOCSIFFLAGS: if (ifp->if_flags & IFF_UP) { @@ -1057,9 +1061,6 @@ txp_ioctl(ifp, command, data, cr) error = ether_ioctl(ifp, command, data); break; } - - crit_exit(); - return(error); } @@ -1140,8 +1141,6 @@ txp_init(xsc) txp_stop(sc); - crit_enter(); - txp_command(sc, TXP_CMD_MAX_PKT_SIZE_WRITE, TXP_MAX_PKTLEN, 0, 0, NULL, NULL, NULL, 1); @@ -1174,8 +1173,6 @@ txp_init(xsc) ifp->if_timer = 0; callout_reset(&sc->txp_stat_timer, hz, txp_tick, sc); - - crit_exit(); } static void @@ -1187,7 +1184,7 @@ txp_tick(vsc) struct txp_rsp_desc *rsp = NULL; struct txp_ext_desc *ext; - crit_enter(); + lwkt_serialize_enter(ifp->if_serializer); txp_rxbuf_reclaim(sc); if (txp_command2(sc, TXP_CMD_READ_STATISTICS, 0, 0, 0, NULL, 0, @@ -1214,7 +1211,7 @@ out: free(rsp, M_DEVBUF); callout_reset(&sc->txp_stat_timer, hz, txp_tick, sc); - crit_exit(); + lwkt_serialize_exit(ifp->if_serializer); } static void diff --git a/sys/dev/netif/vr/if_vr.c b/sys/dev/netif/vr/if_vr.c index 962f57a2f7..13ec573e65 100644 --- a/sys/dev/netif/vr/if_vr.c +++ b/sys/dev/netif/vr/if_vr.c @@ -30,7 +30,7 @@ * THE POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD: src/sys/pci/if_vr.c,v 1.26.2.13 2003/02/06 04:46:20 silby Exp $ - * $DragonFly: src/sys/dev/netif/vr/if_vr.c,v 1.39 2005/11/22 00:24:34 dillon Exp $ + * $DragonFly: src/sys/dev/netif/vr/if_vr.c,v 1.40 2005/11/28 17:13:44 dillon Exp $ */ /* @@ -69,6 +69,7 @@ #include #include #include +#include #include #include @@ -289,8 +290,6 @@ vr_mii_readreg(struct vr_softc *sc, struct vr_mii_frame *frame) { int i, ack; - crit_enter(); - /* Set up frame for RX. */ frame->mii_stdelim = VR_MII_STARTDELIM; frame->mii_opcode = VR_MII_READOP; @@ -359,8 +358,6 @@ fail: SIO_SET(VR_MIICMD_CLK); DELAY(1); - crit_exit(); - if (ack) return(1); return(0); @@ -369,8 +366,6 @@ fail: { int i; - crit_enter(); - /* Set the PHY address. */ CSR_WRITE_1(sc, VR_PHYADDR, (CSR_READ_1(sc, VR_PHYADDR)& 0xe0)| frame->mii_phyaddr); @@ -386,8 +381,6 @@ fail: } frame->mii_data = CSR_READ_2(sc, VR_MIIDATA); - crit_exit(); - return(0); } #endif @@ -400,9 +393,6 @@ static int vr_mii_writereg(struct vr_softc *sc, struct vr_mii_frame *frame) #ifdef VR_USESWSHIFT { - - crit_enter(); - CSR_WRITE_1(sc, VR_MIICMD, 0); VR_SETBIT(sc, VR_MIICMD, VR_MIICMD_DIRECTPGM); @@ -432,16 +422,12 @@ vr_mii_writereg(struct vr_softc *sc, struct vr_mii_frame *frame) /* Turn off xmit. */ SIO_CLR(VR_MIICMD_DIR); - crit_exit(); - return(0); } #else { int i; - crit_enter(); - /* Set the PHY-adress */ CSR_WRITE_1(sc, VR_PHYADDR, (CSR_READ_1(sc, VR_PHYADDR)& 0xe0)| frame->mii_phyaddr); @@ -457,9 +443,6 @@ vr_mii_writereg(struct vr_softc *sc, struct vr_mii_frame *frame) break; DELAY(1); } - - crit_exit(); - return(0); } #endif @@ -806,10 +789,11 @@ vr_attach(device_t dev) } /* Call MI attach routine. */ - ether_ifattach(ifp, eaddr); + ether_ifattach(ifp, eaddr, NULL); - error = bus_setup_intr(dev, sc->vr_irq, 0, - vr_intr, sc, &sc->vr_intrhand, NULL); + error = bus_setup_intr(dev, sc->vr_irq, INTR_NETSAFE, + vr_intr, sc, &sc->vr_intrhand, + ifp->if_serializer); if (error) { device_printf(dev, "couldn't set up irq\n"); @@ -829,7 +813,7 @@ vr_detach(device_t dev) struct vr_softc *sc = device_get_softc(dev); struct ifnet *ifp = &sc->arpcom.ac_if; - crit_enter(); + lwkt_serialize_enter(ifp->if_serializer); if (device_is_attached(dev)) { vr_stop(sc); @@ -842,8 +826,6 @@ vr_detach(device_t dev) if (sc->vr_intrhand != NULL) bus_teardown_intr(dev, sc->vr_irq, sc->vr_intrhand); - crit_exit(); - if (sc->vr_irq != NULL) bus_release_resource(dev, SYS_RES_IRQ, 0, sc->vr_irq); if (sc->vr_res != NULL) @@ -853,6 +835,7 @@ vr_detach(device_t dev) if (sc->vr_cdata.vr_tx_buf != NULL) contigfree(sc->vr_cdata.vr_tx_buf, VR_TX_BUF_SIZE, M_DEVBUF); + lwkt_serialize_exit(ifp->if_serializer); return(0); } @@ -1037,7 +1020,7 @@ vr_rxeof(struct vr_softc *sc) m = m0; ifp->if_ipackets++; - (*ifp->if_input)(ifp, m); + ifp->if_input(ifp, m); } } @@ -1171,9 +1154,10 @@ static void vr_tick(void *xsc) { struct vr_softc *sc = xsc; + struct ifnet *ifp = &sc->arpcom.ac_if; struct mii_data *mii; - crit_enter(); + lwkt_serialize_enter(ifp->if_serializer); if (sc->vr_flags & VR_F_RESTART) { if_printf(&sc->arpcom.ac_if, "restarting\n"); @@ -1188,7 +1172,7 @@ vr_tick(void *xsc) callout_reset(&sc->vr_stat_timer, hz, vr_tick, sc); - crit_exit(); + lwkt_serialize_exit(ifp->if_serializer); } static void @@ -1415,8 +1399,6 @@ vr_init(void *xsc) mii = device_get_softc(sc->vr_miibus); - crit_enter(); - /* Cancel pending I/O and free all RX/TX buffers. */ vr_stop(sc); vr_reset(sc); @@ -1448,7 +1430,6 @@ vr_init(void *xsc) /* Init circular RX list. */ if (vr_list_rx_init(sc) == ENOBUFS) { vr_stop(sc); - crit_exit(); if_printf(ifp, "initialization failed: no memory for rx buffers\n"); return; } @@ -1497,8 +1478,6 @@ vr_init(void *xsc) ifp->if_flags |= IFF_RUNNING; ifp->if_flags &= ~IFF_OACTIVE; - crit_exit(); - callout_reset(&sc->vr_stat_timer, hz, vr_tick, sc); } @@ -1542,8 +1521,6 @@ vr_ioctl(struct ifnet *ifp, u_long command, caddr_t data, struct ucred *cr) struct mii_data *mii; int error = 0; - crit_enter(); - switch(command) { case SIOCSIFFLAGS: if (ifp->if_flags & IFF_UP) { @@ -1568,9 +1545,6 @@ vr_ioctl(struct ifnet *ifp, u_long command, caddr_t data, struct ucred *cr) error = ether_ioctl(ifp, command, data); break; } - - crit_exit(); - return(error); } diff --git a/sys/dev/netif/vx/if_vx.c b/sys/dev/netif/vx/if_vx.c index e8baa7594d..cd6650a55e 100644 --- a/sys/dev/netif/vx/if_vx.c +++ b/sys/dev/netif/vx/if_vx.c @@ -28,7 +28,7 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD: src/sys/dev/vx/if_vx.c,v 1.25.2.6 2002/02/13 00:43:10 dillon Exp $ - * $DragonFly: src/sys/dev/netif/vx/if_vx.c,v 1.24 2005/11/22 00:24:34 dillon Exp $ + * $DragonFly: src/sys/dev/netif/vx/if_vx.c,v 1.25 2005/11/28 17:13:44 dillon Exp $ * */ @@ -64,6 +64,7 @@ #include #include #include +#include #include #include @@ -114,6 +115,7 @@ static void vxreset (struct vx_softc *); static void vxread (struct vx_softc *); static struct mbuf *vxget (struct vx_softc *, u_int); static void vxmbuffill (void *); +static void vxmbuffill_serialized (void *); static void vxmbufempty (struct vx_softc *); static void vxsetfilter (struct vx_softc *); static void vxgetlink (struct vx_softc *); @@ -167,7 +169,7 @@ vxattach(device_t dev) ifp->if_watchdog = vxwatchdog; ifp->if_softc = sc; - ether_ifattach(ifp, eaddr); + ether_ifattach(ifp, eaddr, NULL); sc->tx_start_thresh = 20; /* probably a good starting point. */ @@ -225,7 +227,7 @@ vxinit(xsc) CSR_WRITE_2(sc, VX_COMMAND, RX_ENABLE); CSR_WRITE_2(sc, VX_COMMAND, TX_ENABLE); - vxmbuffill((caddr_t) sc); + vxmbuffill_serialized((caddr_t) sc); /* Interface is now `running', with no output active. */ ifp->if_flags |= IFF_RUNNING; @@ -700,7 +702,7 @@ again: return; } - (*ifp->if_input)(ifp, m); + ifp->if_input(ifp, m); /* * In periods of high traffic we can actually receive enough @@ -837,8 +839,6 @@ vxioctl(ifp, cmd, data, cr) struct ifreq *ifr = (struct ifreq *) data; int error = 0; - crit_enter(); - switch (cmd) { case SIOCSIFFLAGS: if ((ifp->if_flags & IFF_UP) == 0 && @@ -893,9 +893,6 @@ vxioctl(ifp, cmd, data, cr) ether_ioctl(ifp, cmd, data); break; } - - crit_exit(); - return (error); } @@ -903,12 +900,8 @@ static void vxreset(sc) struct vx_softc *sc; { - - crit_enter(); - vxstop(sc); vxinit(sc); - crit_exit(); } static void @@ -971,13 +964,22 @@ vxbusyeeprom(sc) } static void -vxmbuffill(sp) - void *sp; +vxmbuffill(void *sp) +{ + struct vx_softc *sc = (struct vx_softc *) sp; + struct ifnet *ifp = &sc->arpcom.ac_if; + + lwkt_serialize_enter(ifp->if_serializer); + vxmbuffill_serialized(sp); + lwkt_serialize_exit(ifp->if_serializer); +} + +static void +vxmbuffill_serialized(void *sp) { struct vx_softc *sc = (struct vx_softc *) sp; int i; - crit_enter(); i = sc->last_mb; do { if (sc->mb[i] == NULL) @@ -994,7 +996,6 @@ vxmbuffill(sp) } else { sc->buffill_pending = 0; } - crit_exit(); } static void @@ -1003,7 +1004,6 @@ vxmbufempty(sc) { int i; - crit_enter(); for (i = 0; i < MAX_MBS; i++) { if (sc->mb[i]) { m_freem(sc->mb[i]); @@ -1013,5 +1013,4 @@ vxmbufempty(sc) sc->last_mb = sc->next_mb = 0; if (sc->buffill_pending != 0) callout_stop(&sc->vx_timer); - crit_exit(); } diff --git a/sys/dev/netif/vx/if_vx_eisa.c b/sys/dev/netif/vx/if_vx_eisa.c index 86ca66374d..e46ae435e8 100644 --- a/sys/dev/netif/vx/if_vx_eisa.c +++ b/sys/dev/netif/vx/if_vx_eisa.c @@ -27,7 +27,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/dev/vx/if_vx_eisa.c,v 1.14 2000/01/29 14:50:31 peter Exp $ - * $DragonFly: src/sys/dev/netif/vx/if_vx_eisa.c,v 1.13 2005/10/12 17:35:53 dillon Exp $ + * $DragonFly: src/sys/dev/netif/vx/if_vx_eisa.c,v 1.14 2005/11/28 17:13:44 dillon Exp $ */ #include @@ -145,8 +145,10 @@ vx_eisa_attach(device_t dev) vxattach(dev); - if (bus_setup_intr(dev, sc->vx_irq, 0, vxintr, sc, - &sc->vx_intrhand, NULL)) { + if (bus_setup_intr(dev, sc->vx_irq, INTR_NETSAFE, + vxintr, sc, &sc->vx_intrhand, + sc->arpcom.ac_if.if_serializer) + ) { ether_ifdetach(&sc->arpcom.ac_if); goto bad; } diff --git a/sys/dev/netif/vx/if_vx_pci.c b/sys/dev/netif/vx/if_vx_pci.c index bbaedfc8b2..78ed017710 100644 --- a/sys/dev/netif/vx/if_vx_pci.c +++ b/sys/dev/netif/vx/if_vx_pci.c @@ -27,7 +27,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/dev/vx/if_vx_pci.c,v 1.21 2000/05/28 15:59:52 peter Exp $ - * $DragonFly: src/sys/dev/netif/vx/if_vx_pci.c,v 1.12 2005/10/12 17:35:53 dillon Exp $ + * $DragonFly: src/sys/dev/netif/vx/if_vx_pci.c,v 1.13 2005/11/28 17:13:44 dillon Exp $ */ #include @@ -111,7 +111,9 @@ vx_pci_shutdown(device_t dev) struct vx_softc *sc; sc = device_get_softc(dev); + lwkt_serialize_enter(sc->arpcom.ac_if.if_serializer); vxstop(sc); + lwkt_serialize_exit(sc->arpcom.ac_if.if_serializer); } static int @@ -174,8 +176,10 @@ vx_pci_attach(device_t dev) } } - if (bus_setup_intr(dev, sc->vx_irq, 0, - vxintr, sc, &sc->vx_intrhand, NULL)) { + if (bus_setup_intr(dev, sc->vx_irq, INTR_NETSAFE, + vxintr, sc, &sc->vx_intrhand, + sc->arpcom.ac_if.if_serializer) + ) { ether_ifdetach(&sc->arpcom.ac_if); goto bad; } diff --git a/sys/dev/netif/wb/if_wb.c b/sys/dev/netif/wb/if_wb.c index 835b03dce4..50c7a74195 100644 --- a/sys/dev/netif/wb/if_wb.c +++ b/sys/dev/netif/wb/if_wb.c @@ -30,7 +30,7 @@ * THE POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD: src/sys/pci/if_wb.c,v 1.26.2.6 2003/03/05 18:42:34 njl Exp $ - * $DragonFly: src/sys/dev/netif/wb/if_wb.c,v 1.32 2005/11/22 00:24:34 dillon Exp $ + * $DragonFly: src/sys/dev/netif/wb/if_wb.c,v 1.33 2005/11/28 17:13:44 dillon Exp $ */ /* @@ -94,6 +94,7 @@ #include #include #include +#include #include #include @@ -810,10 +811,11 @@ wb_attach(device_t dev) /* * Call MI attach routine. */ - ether_ifattach(ifp, eaddr); + ether_ifattach(ifp, eaddr, NULL); - error = bus_setup_intr(dev, sc->wb_irq, 0, - wb_intr, sc, &sc->wb_intrhand, NULL); + error = bus_setup_intr(dev, sc->wb_irq, INTR_NETSAFE, + wb_intr, sc, &sc->wb_intrhand, + ifp->if_serializer); if (error) { device_printf(dev, "couldn't set up irq\n"); @@ -834,7 +836,7 @@ wb_detach(device_t dev) struct wb_softc *sc = device_get_softc(dev); struct ifnet *ifp = &sc->arpcom.ac_if; - crit_enter(); + lwkt_serialize_enter(ifp->if_serializer); if (device_is_attached(dev)) { if (bus_child_present(dev)) @@ -857,6 +859,7 @@ wb_detach(device_t dev) contigfree(sc->wb_ldata_ptr, sizeof(struct wb_list_data) + 8, M_DEVBUF); } + lwkt_serialize_exit(ifp->if_serializer); return(0); } @@ -1023,7 +1026,7 @@ wb_rxeof(struct wb_softc *sc) m = m0; ifp->if_ipackets++; - (*ifp->if_input)(ifp, m); + ifp->if_input(ifp, m); } } @@ -1190,15 +1193,13 @@ static void wb_tick(void *xsc) { struct wb_softc *sc = xsc; + struct ifnet *ifp = &sc->arpcom.ac_if; struct mii_data *mii = device_get_softc(sc->wb_miibus); - crit_enter(); - + lwkt_serialize_enter(ifp->if_serializer); mii_tick(mii); - callout_reset(&sc->wb_stat_timer, hz, wb_tick, sc); - - crit_exit(); + lwkt_serialize_exit(ifp->if_serializer); } /* @@ -1627,6 +1628,10 @@ static void wb_shutdown(device_t dev) { struct wb_softc *sc = device_get_softc(dev); + struct ifnet *ifp = &sc->arpcom.ac_if; + lwkt_serialize_enter(ifp->if_serializer); wb_stop(sc); + lwkt_serialize_exit(ifp->if_serializer); } + diff --git a/sys/dev/netif/wl/if_wl.c b/sys/dev/netif/wl/if_wl.c index 75c448ae08..eae12e8983 100644 --- a/sys/dev/netif/wl/if_wl.c +++ b/sys/dev/netif/wl/if_wl.c @@ -1,5 +1,5 @@ /* $FreeBSD: src/sys/i386/isa/if_wl.c,v 1.27.2.2 2000/07/17 21:24:32 archie Exp $ */ -/* $DragonFly: src/sys/dev/netif/wl/if_wl.c,v 1.25 2005/11/22 00:24:34 dillon Exp $ */ +/* $DragonFly: src/sys/dev/netif/wl/if_wl.c,v 1.26 2005/11/28 17:13:44 dillon Exp $ */ /* * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -199,6 +199,7 @@ WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include #include +#include #include #include @@ -404,12 +405,10 @@ wlprobe(device_t dev) */ #define PCMD(base, hacr) outw((base), (hacr)) - crit_enter(); PCMD(base, HACR_RESET); /* reset the board */ DELAY(DELAYCONST); /* >> 4 clocks at 6MHz */ PCMD(base, HACR_RESET); /* reset the board */ DELAY(DELAYCONST); /* >> 4 clocks at 6MHz */ - crit_exit(); /* clear reset command and set PIO#1 in autoincrement mode */ PCMD(base, HACR_DEFAULT); @@ -549,14 +548,15 @@ wlattach(device_t dev) */ ifq_set_maxlen(&ifp->if_snd, IFQ_MAXLEN); ifq_set_ready(&ifp->if_snd); - ether_ifattach(ifp, sc->wl_ac.ac_enaddr); + ether_ifattach(ifp, sc->wl_ac.ac_enaddr, NULL); if (sc->freq24) printf(", Freq %d MHz",sc->freq24); /* 2.4 Gz */ printf("\n"); /* 2.4 Gz */ - error = bus_setup_intr(dev, sc->res_irq, 0, - wlintr, sc, &sc->intr_handle, NULL); + error = bus_setup_intr(dev, sc->res_irq, INTR_NETSAFE, + wlintr, sc, &sc->intr_handle, + ifp->if_serializer); if (error) { device_printf(dev, "setup irq fail!\n"); ether_ifdetach(ifp); @@ -576,7 +576,7 @@ wldetach(device_t dev) device_t parent = device_get_parent(dev); struct ifnet *ifp = &sc->wl_if; - crit_enter(); + lwkt_serialize_enter(ifp->if_serializer); ether_ifdetach(ifp); /* reset the board */ @@ -591,9 +591,9 @@ wldetach(device_t dev) } bus_generic_detach(dev); - crit_exit(); wl_free_resources(dev); + lwkt_serialize_exit(ifp->if_serializer); return (0); } @@ -794,7 +794,6 @@ wlinit(void *xsc) if (ifp->if_flags & IFF_DEBUG) if_printf(ifp, "entered wlinit()\n"); #endif - crit_enter(); if ((stat = wlhwrst(sc)) == TRUE) { ifp->if_flags |= IFF_RUNNING; /* same as DSF_RUNNING */ /* @@ -811,7 +810,6 @@ wlinit(void *xsc) } else { if_printf(ifp, "init(): trouble resetting board.\n"); } - crit_exit(); } /* @@ -1085,7 +1083,7 @@ wlread(struct wl_softc *sc, u_short fd_p) bytes_in_msg = rbd.status & RBD_SW_COUNT; MGETHDR(m, MB_DONTWAIT, MT_DATA); tm = m; - if (m == (struct mbuf *)0) { + if (m == NULL) { /* * not only do we want to return, we need to drop the packet on * the floor to clear the interrupt. @@ -1121,9 +1119,11 @@ wlread(struct wl_softc *sc, u_short fd_p) mlen = 0; clen = mlen; - bytes_in_mbuf = m->m_len; + bytes_in_mbuf = m->m_len - sizeof(eh); mb_p = mtod(tm, u_char *); bytes = min(bytes_in_mbuf, bytes_in_msg); + bcopy(&eh, mb_p, sizeof(eh)); + mb_p += sizeof(eh); for (;;) { if (bytes & 1) { len = bytes + 1; @@ -1217,7 +1217,7 @@ wlread(struct wl_softc *sc, u_short fd_p) * to pass the packet upwards. * */ - ether_input(ifp, &eh, m); + ifp->if_input(ifp, m); return 1; } @@ -1251,7 +1251,6 @@ wlioctl(struct ifnet *ifp, u_long cmd, caddr_t data, struct ucred *cred) if (ifp->if_flags & IFF_DEBUG) if_printf(ifp, "entered wlioctl()\n"); #endif - crit_enter(); switch (cmd) { case SIOCSIFFLAGS: if (ifp->if_flags & IFF_ALLMULTI) { @@ -1480,7 +1479,6 @@ wlioctl(struct ifnet *ifp, u_long cmd, caddr_t data, struct ucred *cred) error = ether_ioctl(ifp, cmd, data); break; } - crit_exit(); return (error); } @@ -1499,10 +1497,13 @@ static void wlwatchdog(void *vsc) { struct wl_softc *sc = vsc; + struct ifnet *ifp = &sc->wl_if; + lwkt_serialize_enter(ifp->if_serializer); log(LOG_ERR, "%s: wavelan device timeout on xmit\n", sc->wl_if.if_xname); sc->wl_if.if_oerrors++; wlinit(sc); + lwkt_serialize_exit(ifp->if_serializer); } /* @@ -2467,8 +2468,6 @@ wlsetpsa(struct wl_softc *sc) sc->psa[WLPSA_CRCHIGH] = (crc >> 8) & 0xff; sc->psa[WLPSA_CRCOK] = 0x55; /* default to 'bad' until programming complete */ - crit_enter(); /* ick, long pause */ - PCMD(base, HACR_DEFAULT & ~HACR_16BITS); PCMD(base, HACR_DEFAULT & ~HACR_16BITS); @@ -2487,8 +2486,6 @@ wlsetpsa(struct wl_softc *sc) PCMD(base, HACR_DEFAULT); PCMD(base, HACR_DEFAULT); - - crit_exit(); } /* diff --git a/sys/dev/netif/xe/if_xe.c b/sys/dev/netif/xe/if_xe.c index c829e233ca..ae3c50e41f 100644 --- a/sys/dev/netif/xe/if_xe.c +++ b/sys/dev/netif/xe/if_xe.c @@ -25,7 +25,7 @@ * * $Id: if_xe.c,v 1.20 1999/06/13 19:17:40 scott Exp $ * $FreeBSD: src/sys/dev/xe/if_xe.c,v 1.39 2003/10/14 22:51:35 rsm Exp $ - * $DragonFly: src/sys/dev/netif/xe/if_xe.c,v 1.29 2005/11/22 00:24:34 dillon Exp $ + * $DragonFly: src/sys/dev/netif/xe/if_xe.c,v 1.30 2005/11/28 17:13:44 dillon Exp $ */ /* @@ -105,6 +105,7 @@ #include #include #include +#include #include #include @@ -163,6 +164,7 @@ static void xe_watchdog (struct ifnet *ifp); static int xe_media_change (struct ifnet *ifp); static void xe_media_status (struct ifnet *ifp, struct ifmediareq *mrp); static timeout_t xe_setmedia; +static timeout_t xe_setmedia_serialized; static void xe_reset (struct xe_softc *scp); static void xe_stop (struct xe_softc *scp); static void xe_enable_intr (struct xe_softc *scp); @@ -326,10 +328,11 @@ xe_attach (device_t dev) } /* Attach the interface */ - ether_ifattach(scp->ifp, scp->arpcom.ac_enaddr); + ether_ifattach(scp->ifp, scp->arpcom.ac_enaddr, NULL); - err = bus_setup_intr(dev, scp->irq_res, 0, xe_intr, scp, - &scp->intrhand, NULL); + err = bus_setup_intr(dev, scp->irq_res, INTR_NETSAFE, + xe_intr, scp, &scp->intrhand, + scp->arpcom.ac_if.if_serializer); if (err) { device_printf(dev, "Setup intr failed\n"); ether_ifdetach(&scp->arpcom.ac_if); @@ -449,7 +452,7 @@ xe_init(void *xscp) { xe_enable_intr(scp); /* Start media selection */ - xe_setmedia(scp); + xe_setmedia_serialized(scp); /* Enable output */ scp->ifp->if_flags |= IFF_RUNNING; @@ -824,7 +827,7 @@ xe_intr(void *xscp) /* Deliver packet to upper layers */ mbp->m_pkthdr.rcvif = ifp; mbp->m_pkthdr.len = mbp->m_len = len; - (*ifp->if_input)(ifp, mbp); + ifp->if_input(ifp, mbp); ifp->if_ipackets++; } else if (rsr & XE_RSR_ALIGN_ERROR) { @@ -893,7 +896,7 @@ xe_media_change(struct ifnet *ifp) { IFM_SUBTYPE(scp->ifm->ifm_media) == IFM_100_TX) && !scp->phy_ok) return (EINVAL); - xe_setmedia(scp); + xe_setmedia_serialized(scp); return 0; } @@ -912,11 +915,24 @@ xe_media_status(struct ifnet *ifp, struct ifmediareq *mrp) { mrp->ifm_active = ((struct xe_softc *)ifp->if_softc)->media; } +static +void +xe_setmedia(void *xscp) +{ + struct xe_softc *scp = xscp; + + lwkt_serialize_enter(scp->arpcom.ac_if.if_serializer); + xe_setmedia_serialized(xscp); + lwkt_serialize_exit(scp->arpcom.ac_if.if_serializer); +} /* * Select active media. */ -static void xe_setmedia(void *xscp) { +static +void +xe_setmedia_serialized(void *xscp) +{ struct xe_softc *scp = xscp; u_int16_t bmcr, bmsr, anar, lpar; diff --git a/sys/dev/netif/xl/if_xl.c b/sys/dev/netif/xl/if_xl.c index 947ec8359b..2f2e973629 100644 --- a/sys/dev/netif/xl/if_xl.c +++ b/sys/dev/netif/xl/if_xl.c @@ -30,7 +30,7 @@ * THE POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD: src/sys/pci/if_xl.c,v 1.72.2.28 2003/10/08 06:01:57 murray Exp $ - * $DragonFly: src/sys/dev/netif/xl/if_xl.c,v 1.41 2005/11/22 00:24:34 dillon Exp $ + * $DragonFly: src/sys/dev/netif/xl/if_xl.c,v 1.42 2005/11/28 17:13:44 dillon Exp $ */ /* @@ -108,6 +108,7 @@ #include #include #include +#include #include #include @@ -207,6 +208,7 @@ static int xl_detach (device_t); static int xl_newbuf (struct xl_softc *, struct xl_chain_onefrag *); static void xl_stats_update (void *); +static void xl_stats_update_serialized(void *); static int xl_encap (struct xl_softc *, struct xl_chain *, struct mbuf *); static void xl_rxeof (struct xl_softc *, int); @@ -457,8 +459,6 @@ xl_mii_readreg(struct xl_softc *sc, struct xl_mii_frame *frame) { int i, ack; - crit_enter(); - /* * Set up frame for RX. */ @@ -527,8 +527,6 @@ fail: MII_CLR(XL_MII_CLK); MII_SET(XL_MII_CLK); - crit_exit(); - if (ack) return(1); return(0); @@ -540,8 +538,6 @@ fail: static int xl_mii_writereg(struct xl_softc *sc, struct xl_mii_frame *frame) { - crit_enter(); - /* * Set up frame for TX. */ @@ -578,8 +574,6 @@ xl_mii_writereg(struct xl_softc *sc, struct xl_mii_frame *frame) */ MII_CLR(XL_MII_DIR); - crit_exit(); - return(0); } @@ -1597,7 +1591,7 @@ done: /* * Call MI attach routine. */ - ether_ifattach(ifp, eaddr); + ether_ifattach(ifp, eaddr, NULL); /* * Tell the upper layer(s) we support long frames. @@ -1605,8 +1599,9 @@ done: ifp->if_data.ifi_hdrlen = sizeof(struct ether_vlan_header); /* Hook interrupt last to avoid having to lock softc */ - error = bus_setup_intr(dev, sc->xl_irq, 0, - xl_intr, sc, &sc->xl_intrhand, NULL); + error = bus_setup_intr(dev, sc->xl_irq, INTR_NETSAFE, + xl_intr, sc, &sc->xl_intrhand, + ifp->if_serializer); if (error) { if_printf(ifp, "couldn't set up irq\n"); ether_ifdetach(ifp); @@ -1637,6 +1632,8 @@ xl_detach(device_t dev) sc = device_get_softc(dev); ifp = &sc->arpcom.ac_if; + lwkt_serialize_enter(ifp->if_serializer); + if (sc->xl_flags & XL_FLAG_USE_MMIO) { rid = XL_PCI_LOMEM; res = SYS_RES_MEMORY; @@ -1645,8 +1642,6 @@ xl_detach(device_t dev) res = SYS_RES_IOPORT; } - crit_enter(); - if (device_is_attached(dev)) { xl_reset(sc); xl_stop(sc); @@ -1661,8 +1656,6 @@ xl_detach(device_t dev) if (sc->xl_intrhand) bus_teardown_intr(dev, sc->xl_irq, sc->xl_intrhand); - crit_exit(); - if (sc->xl_irq) bus_release_resource(dev, SYS_RES_IRQ, 0, sc->xl_irq); if (sc->xl_fres != NULL) @@ -1672,6 +1665,7 @@ xl_detach(device_t dev) bus_release_resource(dev, res, rid, sc->xl_res); xl_dma_free(dev); + lwkt_serialize_exit(ifp->if_serializer); return(0); } @@ -2138,7 +2132,7 @@ again: } } - (*ifp->if_input)(ifp, m); + ifp->if_input(ifp, m); } if (sc->xl_type != XL_TYPE_905B) { @@ -2384,7 +2378,7 @@ xl_poll(struct ifnet *ifp, enum poll_cmd cmd, int count) if (status & XL_STAT_STATSOFLOW) { sc->xl_stats_no_timeout = 1; - xl_stats_update(sc); + xl_stats_update_serialized(sc); sc->xl_stats_no_timeout = 0; } } @@ -2441,7 +2435,7 @@ xl_intr(void *arg) if (status & XL_STAT_STATSOFLOW) { sc->xl_stats_no_timeout = 1; - xl_stats_update(sc); + xl_stats_update_serialized(sc); sc->xl_stats_no_timeout = 0; } } @@ -2454,6 +2448,16 @@ xl_intr(void *arg) static void xl_stats_update(void *xsc) +{ + struct xl_softc *sc = xsc; + + lwkt_serialize_enter(sc->arpcom.ac_if.if_serializer); + xl_stats_update_serialized(xsc); + lwkt_serialize_exit(sc->arpcom.ac_if.if_serializer); +} + +static void +xl_stats_update_serialized(void *xsc) { struct xl_softc *sc; struct ifnet *ifp; @@ -2801,8 +2805,6 @@ xl_init(void *xsc) u_int16_t rxfilt = 0; struct mii_data *mii = NULL; - crit_enter(); - /* * Cancel pending I/O and free all RX/TX buffers. */ @@ -2842,7 +2844,6 @@ xl_init(void *xsc) if_printf(ifp, "initialization of the rx ring failed (%d)\n", error); xl_stop(sc); - crit_exit(); return; } @@ -2976,7 +2977,7 @@ xl_init(void *xsc) /* Clear out the stats counters. */ CSR_WRITE_2(sc, XL_COMMAND, XL_CMD_STATS_DISABLE); sc->xl_stats_no_timeout = 1; - xl_stats_update(sc); + xl_stats_update_serialized(sc); sc->xl_stats_no_timeout = 0; XL_SEL_WIN(4); CSR_WRITE_2(sc, XL_W4_NET_DIAG, XL_NETDIAG_UPPER_BYTES_ENABLE); @@ -3014,8 +3015,6 @@ xl_init(void *xsc) ifp->if_flags &= ~IFF_OACTIVE; callout_reset(&sc->xl_stat_timer, hz, xl_stats_update, sc); - - crit_exit(); } /* @@ -3133,8 +3132,6 @@ xl_ioctl(struct ifnet *ifp, u_long command, caddr_t data, struct ucred *cr) struct mii_data *mii = NULL; u_int8_t rxfilt; - crit_enter(); - switch(command) { case SIOCSIFFLAGS: XL_SEL_WIN(5); @@ -3193,9 +3190,6 @@ xl_ioctl(struct ifnet *ifp, u_long command, caddr_t data, struct ucred *cr) error = ether_ioctl(ifp, command, data); break; } - - crit_exit(); - return(error); } @@ -3298,14 +3292,12 @@ xl_stop(struct xl_softc *sc) static void xl_shutdown(device_t dev) { - struct xl_softc *sc; - - sc = device_get_softc(dev); + struct xl_softc *sc = device_get_softc(dev); + lwkt_serialize_enter(sc->arpcom.ac_if.if_serializer); xl_reset(sc); xl_stop(sc); - - return; + lwkt_serialize_exit(sc->arpcom.ac_if.if_serializer); } static int @@ -3313,11 +3305,9 @@ xl_suspend(device_t dev) { struct xl_softc *sc = device_get_softc(dev); - crit_enter(); - + lwkt_serialize_enter(sc->arpcom.ac_if.if_serializer); xl_stop(sc); - - crit_exit(); + lwkt_serialize_exit(sc->arpcom.ac_if.if_serializer); return(0); } @@ -3331,13 +3321,11 @@ xl_resume(device_t dev) sc = device_get_softc(dev); ifp = &sc->arpcom.ac_if; - crit_enter(); - + lwkt_serialize_enter(ifp->if_serializer); xl_reset(sc); if (ifp->if_flags & IFF_UP) xl_init(sc); - - crit_exit(); + lwkt_serialize_exit(ifp->if_serializer); return(0); } diff --git a/sys/kern/kern_poll.c b/sys/kern/kern_poll.c index eee5ebac34..296093a1dd 100644 --- a/sys/kern/kern_poll.c +++ b/sys/kern/kern_poll.c @@ -25,7 +25,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/kern/kern_poll.c,v 1.2.2.4 2002/06/27 23:26:33 luigi Exp $ - * $DragonFly: src/sys/kern/kern_poll.c,v 1.21 2005/10/24 08:06:16 sephe Exp $ + * $DragonFly: src/sys/kern/kern_poll.c,v 1.22 2005/11/28 17:13:45 dillon Exp $ */ #include "opt_polling.h" @@ -419,22 +419,27 @@ netisr_poll(struct netmsg *msg) for (i = 0 ; i < poll_handlers ; i++) { struct pollrec *p = &pr[i]; if ((p->ifp->if_flags & (IFF_UP|IFF_RUNNING|IFF_POLLING)) == (IFF_UP|IFF_RUNNING|IFF_POLLING)) { - p->ifp->if_poll(p->ifp, arg, cycles); + if (lwkt_serialize_try(p->ifp->if_serializer)) { + p->ifp->if_poll(p->ifp, arg, cycles); + lwkt_serialize_exit(p->ifp->if_serializer); + } } } } else { /* unregister */ for (i = 0 ; i < poll_handlers ; i++) { struct pollrec *p = &pr[i]; - if (p->ifp->if_flags & IFF_POLLING) { - p->ifp->if_flags &= ~IFF_POLLING; - /* - * Only call the interface deregistration - * function if the interface is still - * running. - */ - if (p->ifp->if_flags & IFF_RUNNING) - p->ifp->if_poll(p->ifp, POLL_DEREGISTER, 1); - } + if ((p->ifp->if_flags & IFF_POLLING) == 0) + continue; + /* + * Only call the interface deregistration + * function if the interface is still + * running. + */ + lwkt_serialize_enter(p->ifp->if_serializer); + p->ifp->if_flags &= ~IFF_POLLING; + if (p->ifp->if_flags & IFF_RUNNING) + p->ifp->if_poll(p->ifp, POLL_DEREGISTER, 1); + lwkt_serialize_exit(p->ifp->if_serializer); } residual_burst = 0; poll_handlers = 0; @@ -469,8 +474,10 @@ ether_poll_register(struct ifnet *ifp) * Attempt to register. Interlock with IFF_POLLING. */ crit_enter(); /* XXX MP - not mp safe */ + lwkt_serialize_enter(ifp->if_serializer); ifp->if_flags |= IFF_POLLING; ifp->if_poll(ifp, POLL_REGISTER, 0); + lwkt_serialize_exit(ifp->if_serializer); if ((ifp->if_flags & IFF_POLLING) == 0) { crit_exit(); return 0; @@ -494,7 +501,9 @@ ether_poll_register(struct ifnet *ifp) verbose--; } ifp->if_flags &= ~IFF_POLLING; + lwkt_serialize_enter(ifp->if_serializer); ifp->if_poll(ifp, POLL_DEREGISTER, 0); + lwkt_serialize_exit(ifp->if_serializer); rc = 0; } else { pr[poll_handlers].ifp = ifp; @@ -539,8 +548,11 @@ ether_poll_deregister(struct ifnet *ifp) * Only call the deregistration function if the interface is still * in a run state. */ - if (ifp->if_flags & IFF_RUNNING) + if (ifp->if_flags & IFF_RUNNING) { + lwkt_serialize_enter(ifp->if_serializer); ifp->if_poll(ifp, POLL_DEREGISTER, 1); + lwkt_serialize_exit(ifp->if_serializer); + } return (1); } diff --git a/sys/net/altq/altq_rmclass.c b/sys/net/altq/altq_rmclass.c index c0c9ba57d5..4baac65267 100644 --- a/sys/net/altq/altq_rmclass.c +++ b/sys/net/altq/altq_rmclass.c @@ -1,5 +1,5 @@ /* $KAME: altq_rmclass.c,v 1.18 2003/11/06 06:32:53 kjc Exp $ */ -/* $DragonFly: src/sys/net/altq/altq_rmclass.c,v 1.4 2005/06/03 18:20:36 swildner Exp $ */ +/* $DragonFly: src/sys/net/altq/altq_rmclass.c,v 1.5 2005/11/28 17:13:45 dillon Exp $ */ /* * Copyright (c) 1991-1997 Regents of the University of California. @@ -1501,6 +1501,10 @@ rmc_delay_action(struct rm_class *cl, struct rm_class *borrow) * by raising IPL to splimp so that's what's implemented here. On a * different system this would probably need to be changed. * + * Since this function is called from an independant timeout, we + * have to set up the lock conditions expected for the ALTQ operation. + * Note that the restart will probably fall through to an if_start. + * * Returns: NONE */ @@ -1510,7 +1514,7 @@ rmc_restart(void *arg) struct rm_class *cl = arg; struct rm_ifdat *ifd = cl->ifdat_; - crit_enter(); + lwkt_serialize_enter(ifd->ifq_->altq_ifp->if_serializer); if (cl->sleeping_) { cl->sleeping_ = 0; cl->undertime_.tv_sec = 0; @@ -1520,7 +1524,7 @@ rmc_restart(void *arg) (ifd->restart)(ifd->ifq_); } } - crit_exit(); + lwkt_serialize_exit(ifd->ifq_->altq_ifp->if_serializer); } /* diff --git a/sys/net/altq/altq_subr.c b/sys/net/altq/altq_subr.c index 078f90712a..ce049737ee 100644 --- a/sys/net/altq/altq_subr.c +++ b/sys/net/altq/altq_subr.c @@ -1,5 +1,5 @@ /* $KAME: altq_subr.c,v 1.23 2004/04/20 16:10:06 itojun Exp $ */ -/* $DragonFly: src/sys/net/altq/altq_subr.c,v 1.6 2005/11/22 00:24:35 dillon Exp $ */ +/* $DragonFly: src/sys/net/altq/altq_subr.c,v 1.7 2005/11/28 17:13:45 dillon Exp $ */ /* * Copyright (C) 1997-2003 @@ -299,8 +299,11 @@ tbr_timeout(void *arg) if (ifp->if_snd.altq_tbr == NULL) continue; active++; - if (!ifq_is_empty(&ifp->if_snd) && ifp->if_start != NULL) + if (!ifq_is_empty(&ifp->if_snd) && ifp->if_start != NULL) { + lwkt_serialize_enter(ifp->if_serializer); (*ifp->if_start)(ifp); + lwkt_serialize_exit(ifp->if_serializer); + } } crit_exit(); if (active > 0) diff --git a/sys/net/bpf.c b/sys/net/bpf.c index 34e457d577..6f72bc916d 100644 --- a/sys/net/bpf.c +++ b/sys/net/bpf.c @@ -38,7 +38,7 @@ * @(#)bpf.c 8.2 (Berkeley) 3/28/94 * * $FreeBSD: src/sys/net/bpf.c,v 1.59.2.12 2002/04/14 21:41:48 luigi Exp $ - * $DragonFly: src/sys/net/bpf.c,v 1.28 2005/07/08 18:19:39 dillon Exp $ + * $DragonFly: src/sys/net/bpf.c,v 1.29 2005/11/28 17:13:45 dillon Exp $ */ #include "use_bpf.h" @@ -480,7 +480,9 @@ bpf_wakeup(struct bpf_d *d) if (d->bd_async && d->bd_sig && d->bd_sigio) pgsigio(d->bd_sigio, d->bd_sig, 0); + get_mplock(); selwakeup(&d->bd_sel); + rel_mplock(); /* XXX */ d->bd_sel.si_pid = 0; } @@ -530,7 +532,9 @@ bpfwrite(dev_t dev, struct uio *uio, int ioflag) dst.sa_family = pseudo_AF_HDRCMPLT; crit_enter(); + lwkt_serialize_enter(ifp->if_serializer); error = (*ifp->if_output)(ifp, m, &dst, (struct rtentry *)NULL); + lwkt_serialize_exit(ifp->if_serializer); crit_exit(); /* * The driver frees the mbuf. @@ -620,8 +624,10 @@ bpfioctl(dev_t dev, u_long cmd, caddr_t addr, int flags, struct thread *td) error = EINVAL; else { ifp = d->bd_bif->bif_ifp; - error = (*ifp->if_ioctl)(ifp, cmd, addr, - td->td_proc->p_ucred); + lwkt_serialize_enter(ifp->if_serializer); + error = ifp->if_ioctl(ifp, cmd, addr, + td->td_proc->p_ucred); + lwkt_serialize_exit(ifp->if_serializer); } break; } diff --git a/sys/net/bridge/bridge.c b/sys/net/bridge/bridge.c index 4876617342..54b47a72b3 100644 --- a/sys/net/bridge/bridge.c +++ b/sys/net/bridge/bridge.c @@ -25,7 +25,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/net/bridge.c,v 1.16.2.25 2003/01/23 21:06:44 sam Exp $ - * $DragonFly: src/sys/net/bridge/Attic/bridge.c,v 1.18 2005/07/05 10:20:39 corecode Exp $ + * $DragonFly: src/sys/net/bridge/Attic/bridge.c,v 1.19 2005/11/28 17:13:45 dillon Exp $ */ /* @@ -1035,7 +1035,9 @@ forward: return m0; bcopy(&save_eh, mtod(m, struct ether_header *), ETHER_HDR_LEN); } + lwkt_serialize_enter(last->if_serializer); error = ifq_handoff(last, m, &pktattr); + lwkt_serialize_exit(last->if_serializer); if (error != 0) { #if 0 BDG_MUTE(last); /* should I also mute ? */ diff --git a/sys/net/disc/if_disc.c b/sys/net/disc/if_disc.c index 36bc87da9c..43c93b80f7 100644 --- a/sys/net/disc/if_disc.c +++ b/sys/net/disc/if_disc.c @@ -32,7 +32,7 @@ * * From: @(#)if_loop.c 8.1 (Berkeley) 6/10/93 * $FreeBSD: src/sys/net/if_disc.c,v 1.26.2.2 2001/12/20 10:30:16 ru Exp $ - * $DragonFly: src/sys/net/disc/if_disc.c,v 1.7 2005/01/26 00:37:39 joerg Exp $ + * $DragonFly: src/sys/net/disc/if_disc.c,v 1.8 2005/11/28 17:13:45 dillon Exp $ */ /* @@ -85,7 +85,7 @@ discattach() ifp->if_hdrlen = 0; ifp->if_addrlen = 0; ifp->if_snd.ifq_maxlen = 20; - if_attach(ifp); + if_attach(ifp, NULL); bpfattach(ifp, DLT_NULL, sizeof(u_int)); } diff --git a/sys/net/dummynet/ip_dummynet.c b/sys/net/dummynet/ip_dummynet.c index d13ce1a19f..9d4313e4b4 100644 --- a/sys/net/dummynet/ip_dummynet.c +++ b/sys/net/dummynet/ip_dummynet.c @@ -25,7 +25,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/netinet/ip_dummynet.c,v 1.24.2.22 2003/05/13 09:31:06 maxim Exp $ - * $DragonFly: src/sys/net/dummynet/ip_dummynet.c,v 1.13 2005/06/03 18:20:36 swildner Exp $ + * $DragonFly: src/sys/net/dummynet/ip_dummynet.c,v 1.14 2005/11/28 17:13:45 dillon Exp $ */ #if !defined(KLD_MODULE) @@ -464,8 +464,10 @@ transmit_event(struct dn_pipe *pipe) m = bdg_forward_ptr(m, eh, pkt->ifp); if (m) m_freem(m); - } else - ether_demux(NULL, eh, m); /* which consumes the mbuf */ + } else { + /* which consumes the mbuf */ + ether_demux(NULL, eh, m); + } } break ; case DN_TO_ETH_OUT: diff --git a/sys/net/ef/if_ef.c b/sys/net/ef/if_ef.c index cf91ea8f23..0b282454f4 100644 --- a/sys/net/ef/if_ef.c +++ b/sys/net/ef/if_ef.c @@ -24,7 +24,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/net/if_ef.c,v 1.2.2.4 2001/02/22 09:27:04 bp Exp $ - * $DragonFly: src/sys/net/ef/if_ef.c,v 1.17 2005/06/03 23:23:03 joerg Exp $ + * $DragonFly: src/sys/net/ef/if_ef.c,v 1.18 2005/11/28 17:13:45 dillon Exp $ */ #include "opt_inet.h" @@ -128,7 +128,7 @@ ef_attach(struct efnet *sc) /* * Attach the interface */ - ether_ifattach(ifp, IF_LLADDR(sc->ef_ifp)); + ether_ifattach(ifp, IF_LLADDR(sc->ef_ifp), NULL); ifp->if_resolvemulti = 0; ifp->if_type = IFT_XETHER; @@ -256,7 +256,7 @@ ef_inputEII(struct mbuf *m, struct ether_header *eh, struct llc* l, #endif #ifdef INET case ETHERTYPE_IP: - if (ipflow_fastforward(m)) + if (ipflow_fastforward(m, NULL)) return (0); isr = NETISR_IP; break; diff --git a/sys/net/faith/if_faith.c b/sys/net/faith/if_faith.c index aadee08b70..b09f6b3a44 100644 --- a/sys/net/faith/if_faith.c +++ b/sys/net/faith/if_faith.c @@ -33,7 +33,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/net/if_faith.c,v 1.3.2.6 2002/04/28 05:40:25 suz Exp $ - * $DragonFly: src/sys/net/faith/if_faith.c,v 1.12 2005/01/26 00:37:39 joerg Exp $ + * $DragonFly: src/sys/net/faith/if_faith.c,v 1.13 2005/11/28 17:13:45 dillon Exp $ */ /* * derived from @@ -177,7 +177,7 @@ faith_clone_create(ifc, unit) sc->sc_if.if_hdrlen = 0; sc->sc_if.if_addrlen = 0; sc->sc_if.if_snd.ifq_maxlen = ifqmaxlen; - if_attach(&sc->sc_if); + if_attach(&sc->sc_if, NULL); bpfattach(&sc->sc_if, DLT_NULL, sizeof(u_int)); LIST_INSERT_HEAD(&faith_softc_list, sc, sc_list); return (0); diff --git a/sys/net/gif/if_gif.c b/sys/net/gif/if_gif.c index 0714c93ca4..eb160f7b83 100644 --- a/sys/net/gif/if_gif.c +++ b/sys/net/gif/if_gif.c @@ -1,7 +1,3 @@ -/* $FreeBSD: src/sys/net/if_gif.c,v 1.4.2.15 2002/11/08 16:57:13 ume Exp $ */ -/* $DragonFly: src/sys/net/gif/if_gif.c,v 1.13 2005/06/03 18:20:36 swildner Exp $ */ -/* $KAME: if_gif.c,v 1.87 2001/10/19 08:50:27 itojun Exp $ */ - /* * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. * All rights reserved. @@ -29,6 +25,10 @@ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. + * + * $FreeBSD: src/sys/net/if_gif.c,v 1.4.2.15 2002/11/08 16:57:13 ume Exp $ + * $DragonFly: src/sys/net/gif/if_gif.c,v 1.14 2005/11/28 17:13:45 dillon Exp $ + * $KAME: if_gif.c,v 1.87 2001/10/19 08:50:27 itojun Exp $ */ #include "opt_inet.h" @@ -163,7 +163,7 @@ gifattach0(sc) sc->gif_if.if_output = gif_output; sc->gif_if.if_type = IFT_GIF; sc->gif_if.if_snd.ifq_maxlen = IFQ_MAXLEN; - if_attach(&sc->gif_if); + if_attach(&sc->gif_if, NULL); bpfattach(&sc->gif_if, DLT_NULL, sizeof(u_int)); } diff --git a/sys/net/gre/if_gre.c b/sys/net/gre/if_gre.c index 045c582bfa..9f391ad24a 100644 --- a/sys/net/gre/if_gre.c +++ b/sys/net/gre/if_gre.c @@ -1,6 +1,6 @@ /* $NetBSD: if_gre.c,v 1.42 2002/08/14 00:23:27 itojun Exp $ */ /* $FreeBSD: src/sys/net/if_gre.c,v 1.9.2.3 2003/01/23 21:06:44 sam Exp $ */ -/* $DragonFly: src/sys/net/gre/if_gre.c,v 1.13 2005/06/03 18:20:37 swildner Exp $ */ +/* $DragonFly: src/sys/net/gre/if_gre.c,v 1.14 2005/11/28 17:13:45 dillon Exp $ */ /* * Copyright (c) 1998 The NetBSD Foundation, Inc. @@ -182,7 +182,7 @@ gre_clone_create(ifc, unit) sc->sc_if.if_flags |= IFF_LINK0; sc->encap = NULL; sc->called = 0; - if_attach(&sc->sc_if); + if_attach(&sc->sc_if, NULL); bpfattach(&sc->sc_if, DLT_NULL, sizeof(u_int32_t)); LIST_INSERT_HEAD(&gre_softc_list, sc, sc_list); return (0); diff --git a/sys/net/i4b/driver/i4b_ipr.c b/sys/net/i4b/driver/i4b_ipr.c index 8df40c2e25..663686839d 100644 --- a/sys/net/i4b/driver/i4b_ipr.c +++ b/sys/net/i4b/driver/i4b_ipr.c @@ -28,7 +28,7 @@ * --------------------------------------------------------- * * $FreeBSD: src/sys/i4b/driver/i4b_ipr.c,v 1.8.2.3 2001/10/27 15:48:17 hm Exp $ - * $DragonFly: src/sys/net/i4b/driver/i4b_ipr.c,v 1.17 2005/06/14 21:19:18 joerg Exp $ + * $DragonFly: src/sys/net/i4b/driver/i4b_ipr.c,v 1.18 2005/11/28 17:13:45 dillon Exp $ * * last edit-date: [Fri Oct 26 19:32:38 2001] * @@ -286,7 +286,7 @@ i4biprattach(void *dummy) sc->sc_dialresp = DSTAT_NONE; /* no response */ sc->sc_lastdialresp = DSTAT_NONE; - if_attach(&sc->sc_if); + if_attach(&sc->sc_if, NULL); bpfattach(&sc->sc_if, DLT_NULL, sizeof(u_int)); } } diff --git a/sys/net/i4b/driver/i4b_isppp.c b/sys/net/i4b/driver/i4b_isppp.c index 27fee39c74..5ca76aca27 100644 --- a/sys/net/i4b/driver/i4b_isppp.c +++ b/sys/net/i4b/driver/i4b_isppp.c @@ -37,7 +37,7 @@ * $Id: i4b_isppp.c,v 1.44 2000/08/31 07:07:26 hm Exp $ * * $FreeBSD: src/sys/i4b/driver/i4b_isppp.c,v 1.7.2.3 2003/02/06 14:50:53 gj Exp $ - * $DragonFly: src/sys/net/i4b/driver/i4b_isppp.c,v 1.14 2005/06/15 11:56:03 joerg Exp $ + * $DragonFly: src/sys/net/i4b/driver/i4b_isppp.c,v 1.15 2005/11/28 17:13:45 dillon Exp $ * * last edit-date: [Thu Aug 31 09:02:27 2000] * @@ -235,7 +235,7 @@ i4bispppattach(void *dummy) sppp_attach(&sc->sc_if); /* XXX: validate / add proper code */ ether_ifattach_bpf(&sc->sc_if, ((struct arpcom*)sc)->ac_enaddr, - DLT_PPP, PPP_HDRLEN); + DLT_PPP, PPP_HDRLEN, NULL); callout_init(&sc->sc_timeout); } } diff --git a/sys/net/if.c b/sys/net/if.c index 89b3b47a35..dbde1d7bfc 100644 --- a/sys/net/if.c +++ b/sys/net/if.c @@ -32,7 +32,7 @@ * * @(#)if.c 8.3 (Berkeley) 1/4/94 * $FreeBSD: src/sys/net/if.c,v 1.185 2004/03/13 02:35:03 brooks Exp $ - * $DragonFly: src/sys/net/if.c,v 1.42 2005/11/22 00:24:34 dillon Exp $ + * $DragonFly: src/sys/net/if.c,v 1.43 2005/11/28 17:13:45 dillon Exp $ */ #include "opt_compat.h" @@ -56,6 +56,7 @@ #include #include #include +#include #include #include @@ -161,11 +162,13 @@ int if_index = 0; struct ifnet **ifindex2ifnet = NULL; /* - * Attach an interface to the - * list of "active" interfaces. + * Attach an interface to the list of "active" interfaces. + * + * The serializer is optional. If non-NULL access to the interface + * may be MPSAFE. */ void -if_attach(struct ifnet *ifp) +if_attach(struct ifnet *ifp, lwkt_serialize_t serializer) { unsigned socksize, ifasize; int namelen, masklen; @@ -181,6 +184,18 @@ if_attach(struct ifnet *ifp) inited = TRUE; } + /* + * The serializer can be passed in from the device, allowing the + * same serializer to be used for both the interrupt interlock and + * the device queue. If not specified, the netif structure will + * use an embedded serializer. + */ + if (serializer == NULL) { + serializer = &ifp->if_default_serializer; + lwkt_serialize_init(serializer); + } + ifp->if_serializer = serializer; + TAILQ_INSERT_TAIL(&ifnet, ifp, if_link); ifp->if_index = ++if_index; /* @@ -971,8 +986,15 @@ if_slowtimo(void *arg) TAILQ_FOREACH(ifp, &ifnet, if_link) { if (ifp->if_timer == 0 || --ifp->if_timer) continue; - if (ifp->if_watchdog) - (*ifp->if_watchdog)(ifp); + if (ifp->if_watchdog) { + if (lwkt_serialize_try(ifp->if_serializer)) { + (*ifp->if_watchdog)(ifp); + lwkt_serialize_exit(ifp->if_serializer); + } else { + /* try again next timeout */ + ++ifp->if_timer; + } + } } crit_exit(); @@ -1131,8 +1153,11 @@ ifioctl(struct socket *so, u_long cmd, caddr_t data, struct thread *td) } else if (ifp->if_pcount == 0) { ifp->if_flags &= ~IFF_PROMISC; } - if (ifp->if_ioctl) - (*ifp->if_ioctl)(ifp, cmd, data, td->td_proc->p_ucred); + if (ifp->if_ioctl) { + lwkt_serialize_enter(ifp->if_serializer); + ifp->if_ioctl(ifp, cmd, data, td->td_proc->p_ucred); + lwkt_serialize_exit(ifp->if_serializer); + } getmicrotime(&ifp->if_lastchange); break; @@ -1142,7 +1167,9 @@ ifioctl(struct socket *so, u_long cmd, caddr_t data, struct thread *td) return (error); if (ifr->ifr_reqcap & ~ifp->if_capabilities) return (EINVAL); - (*ifp->if_ioctl)(ifp, cmd, data, td->td_proc->p_ucred); + lwkt_serialize_enter(ifp->if_serializer); + ifp->if_ioctl(ifp, cmd, data, td->td_proc->p_ucred); + lwkt_serialize_exit(ifp->if_serializer); break; case SIOCSIFNAME: @@ -1205,7 +1232,9 @@ ifioctl(struct socket *so, u_long cmd, caddr_t data, struct thread *td) return error; if (!ifp->if_ioctl) return EOPNOTSUPP; - error = (*ifp->if_ioctl)(ifp, cmd, data, td->td_proc->p_ucred); + lwkt_serialize_enter(ifp->if_serializer); + error = ifp->if_ioctl(ifp, cmd, data, td->td_proc->p_ucred); + lwkt_serialize_exit(ifp->if_serializer); if (error == 0) getmicrotime(&ifp->if_lastchange); return (error); @@ -1221,7 +1250,9 @@ ifioctl(struct socket *so, u_long cmd, caddr_t data, struct thread *td) return (EOPNOTSUPP); if (ifr->ifr_mtu < IF_MINMTU || ifr->ifr_mtu > IF_MAXMTU) return (EINVAL); - error = (*ifp->if_ioctl)(ifp, cmd, data, td->td_proc->p_ucred); + lwkt_serialize_enter(ifp->if_serializer); + error = ifp->if_ioctl(ifp, cmd, data, td->td_proc->p_ucred); + lwkt_serialize_exit(ifp->if_serializer); if (error == 0) { getmicrotime(&ifp->if_lastchange); rt_ifmsg(ifp); @@ -1274,7 +1305,9 @@ ifioctl(struct socket *so, u_long cmd, caddr_t data, struct thread *td) return (error); if (ifp->if_ioctl == 0) return (EOPNOTSUPP); - error = (*ifp->if_ioctl)(ifp, cmd, data, td->td_proc->p_ucred); + lwkt_serialize_enter(ifp->if_serializer); + error = ifp->if_ioctl(ifp, cmd, data, td->td_proc->p_ucred); + lwkt_serialize_exit(ifp->if_serializer); if (error == 0) getmicrotime(&ifp->if_lastchange); return error; @@ -1288,9 +1321,12 @@ ifioctl(struct socket *so, u_long cmd, caddr_t data, struct thread *td) case SIOCGLIFPHYADDR: case SIOCGIFMEDIA: case SIOCGIFGENERIC: - if (ifp->if_ioctl == 0) + if (ifp->if_ioctl == NULL) return (EOPNOTSUPP); - return ((*ifp->if_ioctl)(ifp, cmd, data, td->td_proc->p_ucred)); + lwkt_serialize_enter(ifp->if_serializer); + error = ifp->if_ioctl(ifp, cmd, data, td->td_proc->p_ucred); + lwkt_serialize_exit(ifp->if_serializer); + return (error); case SIOCSIFLLADDR: error = suser(td); @@ -1411,8 +1447,10 @@ ifpromisc(struct ifnet *ifp, int pswitch) } ifr.ifr_flags = ifp->if_flags; ifr.ifr_flagshigh = ifp->if_flags >> 16; - error = (*ifp->if_ioctl)(ifp, SIOCSIFFLAGS, (caddr_t)&ifr, + lwkt_serialize_enter(ifp->if_serializer); + error = ifp->if_ioctl(ifp, SIOCSIFFLAGS, (caddr_t)&ifr, (struct ucred *)NULL); + lwkt_serialize_exit(ifp->if_serializer); if (error == 0) rt_ifmsg(ifp); else @@ -1525,8 +1563,10 @@ if_allmulti(struct ifnet *ifp, int onswitch) ifp->if_flags |= IFF_ALLMULTI; ifr.ifr_flags = ifp->if_flags; ifr.ifr_flagshigh = ifp->if_flags >> 16; + lwkt_serialize_enter(ifp->if_serializer); error = ifp->if_ioctl(ifp, SIOCSIFFLAGS, (caddr_t)&ifr, (struct ucred *)NULL); + lwkt_serialize_exit(ifp->if_serializer); } } else { if (ifp->if_amcount > 1) { @@ -1536,8 +1576,10 @@ if_allmulti(struct ifnet *ifp, int onswitch) ifp->if_flags &= ~IFF_ALLMULTI; ifr.ifr_flags = ifp->if_flags; ifr.ifr_flagshigh = ifp->if_flags >> 16; + lwkt_serialize_enter(ifp->if_serializer); error = ifp->if_ioctl(ifp, SIOCSIFFLAGS, (caddr_t)&ifr, (struct ucred *)NULL); + lwkt_serialize_exit(ifp->if_serializer); } } @@ -1581,8 +1623,11 @@ if_addmulti( * already. */ if (ifp->if_resolvemulti) { + lwkt_serialize_enter(ifp->if_serializer); error = ifp->if_resolvemulti(ifp, &llsa, sa); - if (error) return error; + lwkt_serialize_exit(ifp->if_serializer); + if (error) + return error; } else { llsa = 0; } @@ -1633,7 +1678,9 @@ if_addmulti( * interface to let them know about it. */ crit_enter(); + lwkt_serialize_enter(ifp->if_serializer); ifp->if_ioctl(ifp, SIOCADDMULTI, 0, (struct ucred *)NULL); + lwkt_serialize_exit(ifp->if_serializer); crit_exit(); return 0; @@ -1667,8 +1714,11 @@ if_delmulti(struct ifnet *ifp, struct sockaddr *sa) * Make sure the interface driver is notified * in the case of a link layer mcast group being left. */ - if (ifma->ifma_addr->sa_family == AF_LINK && sa == 0) + if (ifma->ifma_addr->sa_family == AF_LINK && sa == 0) { + lwkt_serialize_enter(ifp->if_serializer); ifp->if_ioctl(ifp, SIOCDELMULTI, 0, (struct ucred *)NULL); + lwkt_serialize_exit(ifp->if_serializer); + } crit_exit(); free(ifma->ifma_addr, M_IFMADDR); free(ifma, M_IFMADDR); @@ -1698,8 +1748,10 @@ if_delmulti(struct ifnet *ifp, struct sockaddr *sa) } crit_enter(); + lwkt_serialize_enter(ifp->if_serializer); LIST_REMOVE(ifma, ifma_link); ifp->if_ioctl(ifp, SIOCDELMULTI, 0, (struct ucred *)NULL); + lwkt_serialize_exit(ifp->if_serializer); crit_exit(); free(ifma->ifma_addr, M_IFMADDR); free(sa, M_IFMADDR); @@ -1745,16 +1797,17 @@ if_setlladdr(struct ifnet *ifp, const u_char *lladdr, int len) * to re-init it in order to reprogram its * address filter. */ + lwkt_serialize_enter(ifp->if_serializer); if ((ifp->if_flags & IFF_UP) != 0) { ifp->if_flags &= ~IFF_UP; ifr.ifr_flags = ifp->if_flags; ifr.ifr_flagshigh = ifp->if_flags >> 16; - (*ifp->if_ioctl)(ifp, SIOCSIFFLAGS, (caddr_t)&ifr, - (struct ucred *)NULL); + ifp->if_ioctl(ifp, SIOCSIFFLAGS, (caddr_t)&ifr, + (struct ucred *)NULL); ifp->if_flags |= IFF_UP; ifr.ifr_flags = ifp->if_flags; ifr.ifr_flagshigh = ifp->if_flags >> 16; - (*ifp->if_ioctl)(ifp, SIOCSIFFLAGS, (caddr_t)&ifr, + ifp->if_ioctl(ifp, SIOCSIFFLAGS, (caddr_t)&ifr, (struct ucred *)NULL); #ifdef INET /* @@ -1768,6 +1821,7 @@ if_setlladdr(struct ifnet *ifp, const u_char *lladdr, int len) } #endif } + lwkt_serialize_exit(ifp->if_serializer); return (0); } diff --git a/sys/net/if_arc.h b/sys/net/if_arc.h index 75e74efebf..fcd98cfa60 100644 --- a/sys/net/if_arc.h +++ b/sys/net/if_arc.h @@ -1,6 +1,6 @@ /* $NetBSD: if_arc.h,v 1.13 1999/11/19 20:41:19 thorpej Exp $ */ /* $FreeBSD: src/sys/net/if_arc.h,v 1.2.2.3 2003/01/28 11:19:05 fjoe Exp $ */ -/* $DragonFly: src/sys/net/Attic/if_arc.h,v 1.4 2004/07/23 07:16:30 joerg Exp $ */ +/* $DragonFly: src/sys/net/Attic/if_arc.h,v 1.5 2005/11/28 17:13:45 dillon Exp $ */ /* * Copyright (c) 1982, 1986, 1993 @@ -130,8 +130,9 @@ struct arccom { #ifdef _KERNEL extern int arc_ipmtu; /* XXX new ip only, no RFC 1051! */ +struct lwkt_serialize; -void arc_ifattach (struct ifnet *, u_int8_t); +void arc_ifattach (struct ifnet *, u_int8_t, struct lwkt_serialize *); void arc_ifdetach (struct ifnet *); void arc_storelladdr (struct ifnet *, u_int8_t); int arc_isphds (int); diff --git a/sys/net/if_arcsubr.c b/sys/net/if_arcsubr.c index 1cc7dc5977..1a35198d43 100644 --- a/sys/net/if_arcsubr.c +++ b/sys/net/if_arcsubr.c @@ -1,6 +1,6 @@ /* $NetBSD: if_arcsubr.c,v 1.36 2001/06/14 05:44:23 itojun Exp $ */ /* $FreeBSD: src/sys/net/if_arcsubr.c,v 1.1.2.5 2003/02/05 18:42:15 fjoe Exp $ */ -/* $DragonFly: src/sys/net/Attic/if_arcsubr.c,v 1.18 2005/09/01 12:59:38 sephe Exp $ */ +/* $DragonFly: src/sys/net/Attic/if_arcsubr.c,v 1.19 2005/11/28 17:13:45 dillon Exp $ */ /* * Copyright (c) 1994, 1995 Ignatios Souvatzis @@ -53,6 +53,7 @@ #include #include #include +#include #include @@ -501,6 +502,8 @@ arc_input(struct ifnet *ifp, struct mbuf *m) int isr; u_int8_t atype; + ASSERT_SERIALIZED(ifp->if_serializer); + if (!(ifp->if_flags & IFF_UP)) { m_freem(m); return; @@ -534,14 +537,14 @@ arc_input(struct ifnet *ifp, struct mbuf *m) #ifdef INET case ARCTYPE_IP: m_adj(m, ARC_HDRNEWLEN); - if (ipflow_fastforward(m)) + if (ipflow_fastforward(m, ifp->if_serializer)) return; isr = NETISR_IP; break; case ARCTYPE_IP_OLD: m_adj(m, ARC_HDRLEN); - if (ipflow_fastforward(m)) + if (ipflow_fastforward(m, ifp->if_serializer)) return; isr = NETISR_IP; break; @@ -607,16 +610,14 @@ arc_storelladdr(ifp, lla) * Perform common duties while attaching to interface list */ void -arc_ifattach(ifp, lla) - struct ifnet *ifp; - u_int8_t lla; +arc_ifattach(struct ifnet *ifp, u_int8_t lla, lwkt_serialize_t serializer) { struct sockaddr_dl *sdl; struct arccom *ac; ifp->if_input = arc_input; ifp->if_output = arc_output; - if_attach(ifp); + if_attach(ifp, serializer); ifp->if_type = IFT_ARCNET; ifp->if_addrlen = 1; ifp->if_broadcastaddr = arcbroadcastaddr; @@ -670,7 +671,9 @@ arc_ioctl(ifp, command, data) switch (ifa->ifa_addr->sa_family) { #ifdef INET case AF_INET: + lwkt_serialize_enter(ifp->if_serializer); ifp->if_init(ifp->if_softc); /* before arpwhohas */ + lwkt_serialize_exit(ifp->if_serializer); arp_ifinit(ifp, ifa); break; #endif @@ -690,12 +693,16 @@ arc_ioctl(ifp, command, data) /* * Set new address */ + lwkt_serialize_enter(ifp->if_serializer); ifp->if_init(ifp->if_softc); + lwkt_serialize_exit(ifp->if_serializer); break; } #endif default: + lwkt_serialize_enter(ifp->if_serializer); ifp->if_init(ifp->if_softc); + lwkt_serialize_exit(ifp->if_serializer); break; } break; diff --git a/sys/net/if_atm.h b/sys/net/if_atm.h index fb1a7f72e8..23c78c4064 100644 --- a/sys/net/if_atm.h +++ b/sys/net/if_atm.h @@ -1,6 +1,6 @@ /* $NetBSD: if_atm.h,v 1.7 1996/11/09 23:02:27 chuck Exp $ */ /* $FreeBSD: src/sys/net/if_atm.h,v 1.4 1999/12/29 04:38:34 peter Exp $ */ -/* $DragonFly: src/sys/net/if_atm.h,v 1.6 2005/01/06 17:59:32 hsu Exp $ */ +/* $DragonFly: src/sys/net/if_atm.h,v 1.7 2005/11/28 17:13:45 dillon Exp $ */ /* * @@ -101,7 +101,10 @@ struct atmllc { } #ifdef _KERNEL -void atm_ifattach (struct ifnet *); + +struct lwkt_serialize; + +void atm_ifattach (struct ifnet *, struct lwkt_serialize *); void atm_input (struct ifnet *, struct atm_pseudohdr *, struct mbuf *, void *); int atm_output (struct ifnet *, struct mbuf *, struct sockaddr *, diff --git a/sys/net/if_atmsubr.c b/sys/net/if_atmsubr.c index 07fbd6f861..7fdae4e031 100644 --- a/sys/net/if_atmsubr.c +++ b/sys/net/if_atmsubr.c @@ -32,7 +32,7 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD: src/sys/net/if_atmsubr.c,v 1.10.2.1 2001/03/06 00:29:26 obrien Exp $ - * $DragonFly: src/sys/net/if_atmsubr.c,v 1.14 2005/06/15 19:29:30 joerg Exp $ + * $DragonFly: src/sys/net/if_atmsubr.c,v 1.15 2005/11/28 17:13:45 dillon Exp $ */ /* @@ -48,8 +48,10 @@ #include #include #include -#include #include +#include + +#include #include #include @@ -234,6 +236,8 @@ atm_input(ifp, ah, m, rxhand) u_int16_t etype = ETHERTYPE_IP; /* default */ int isr; + ASSERT_SERIALIZED(ifp->if_serializer); + if (!(ifp->if_flags & IFF_UP)) { m_freem(m); return; @@ -302,8 +306,7 @@ atm_input(ifp, ah, m, rxhand) * Perform common duties while attaching to interface list */ void -atm_ifattach(ifp) - struct ifnet *ifp; +atm_ifattach(struct ifnet *ifp, lwkt_serialize_t serializer) { struct ifaddr *ifa; struct sockaddr_dl *sdl; @@ -317,7 +320,7 @@ atm_ifattach(ifp) #endif ifp->if_output = atm_output; ifq_set_maxlen(&ifp->if_snd, 50); - if_attach(ifp); + if_attach(ifp, serializer); #if defined(__NetBSD__) || defined(__OpenBSD__) for (ifa = TAILQ_FIRST(&ifp->if_addrlist); ifa != 0; diff --git a/sys/net/if_ethersubr.c b/sys/net/if_ethersubr.c index 6ab369ede8..5e7b60bdfd 100644 --- a/sys/net/if_ethersubr.c +++ b/sys/net/if_ethersubr.c @@ -32,7 +32,7 @@ * * @(#)if_ethersubr.c 8.1 (Berkeley) 6/10/93 * $FreeBSD: src/sys/net/if_ethersubr.c,v 1.70.2.33 2003/04/28 15:45:53 archie Exp $ - * $DragonFly: src/sys/net/if_ethersubr.c,v 1.32 2005/06/15 19:29:30 joerg Exp $ + * $DragonFly: src/sys/net/if_ethersubr.c,v 1.33 2005/11/28 17:13:45 dillon Exp $ */ #include "opt_atalk.h" @@ -163,6 +163,8 @@ ether_output(struct ifnet *ifp, struct mbuf *m, struct sockaddr *dst, struct arpcom *ac = IFP2AC(ifp); int error; + ASSERT_SERIALIZED(ifp->if_serializer); + if ((ifp->if_flags & (IFF_UP | IFF_RUNNING)) != (IFF_UP | IFF_RUNNING)) gotoerr(ENETDOWN); @@ -366,6 +368,8 @@ ether_output_frame(struct ifnet *ifp, struct mbuf *m) int error = 0; struct altq_pktattr pktattr; + ASSERT_SERIALIZED(ifp->if_serializer); + /* Extract info from dummynet tag, ignore others */ while (m->m_type == MT_TAG) { if (m->m_flags == PACKET_TAG_DUMMYNET) { @@ -383,7 +387,9 @@ ether_output_frame(struct ifnet *ifp, struct mbuf *m) m->m_pkthdr.rcvif = NULL; eh = mtod(m, struct ether_header *); m_adj(m, ETHER_HDR_LEN); + lwkt_serialize_exit(ifp->if_serializer); m = bdg_forward_ptr(m, eh, ifp); + lwkt_serialize_enter(ifp->if_serializer); m_freem(m); return (0); } @@ -422,13 +428,13 @@ no_bridge: ETHER_HDR_LEN); } } + crit_exit(); /* * Queue message on interface, update output statistics if * successful, and start output if interface not yet active. */ error = ifq_handoff(ifp, m, &pktattr); - crit_exit(); return (error); } @@ -559,6 +565,8 @@ ether_input(struct ifnet *ifp, struct ether_header *eh, struct mbuf *m) { struct ether_header save_eh; + ASSERT_SERIALIZED(ifp->if_serializer); + if (eh == NULL) { if (m->m_len < sizeof(struct ether_header)) { /* XXX error in the caller. */ @@ -579,7 +587,9 @@ ether_input(struct ifnet *ifp, struct ether_header *eh, struct mbuf *m) /* Handle ng_ether(4) processing, if any */ if (ng_ether_input_p != NULL) { + lwkt_serialize_exit(ifp->if_serializer); (*ng_ether_input_p)(ifp, &m, eh); + lwkt_serialize_enter(ifp->if_serializer); if (m == NULL) return; } @@ -595,7 +605,9 @@ ether_input(struct ifnet *ifp, struct ether_header *eh, struct mbuf *m) } if (bif != BDG_LOCAL) { save_eh = *eh ; /* because it might change */ + lwkt_serialize_exit(ifp->if_serializer); m = bdg_forward_ptr(m, eh, bif); /* needs forwarding */ + lwkt_serialize_enter(ifp->if_serializer); /* * Do not continue if bdg_forward_ptr() processed our * packet (and cleared the mbuf pointer m) or if @@ -687,7 +699,7 @@ post_stats: switch (ether_type) { #ifdef INET case ETHERTYPE_IP: - if (ipflow_fastforward(m)) + if (ipflow_fastforward(m, ifp->if_serializer)) return; isr = NETISR_IP; break; @@ -798,20 +810,22 @@ dropanyway: */ void -ether_ifattach(struct ifnet *ifp, uint8_t *lla) +ether_ifattach(struct ifnet *ifp, uint8_t *lla, lwkt_serialize_t serializer) { - ether_ifattach_bpf(ifp, lla, DLT_EN10MB, sizeof(struct ether_header)); + ether_ifattach_bpf(ifp, lla, DLT_EN10MB, sizeof(struct ether_header), + serializer); } void -ether_ifattach_bpf(struct ifnet *ifp, uint8_t *lla, u_int dlt, u_int hdrlen) +ether_ifattach_bpf(struct ifnet *ifp, uint8_t *lla, u_int dlt, u_int hdrlen, + lwkt_serialize_t serializer) { struct sockaddr_dl *sdl; ifp->if_type = IFT_ETHER; ifp->if_addrlen = ETHER_ADDR_LEN; ifp->if_hdrlen = ETHER_HDR_LEN; - if_attach(ifp); + if_attach(ifp, serializer); ifp->if_mtu = ETHERMTU; if (ifp->if_baudrate == 0) ifp->if_baudrate = 10000000; @@ -844,9 +858,7 @@ ether_ifattach_bpf(struct ifnet *ifp, uint8_t *lla, u_int dlt, u_int hdrlen) void ether_ifdetach(struct ifnet *ifp) { - crit_enter(); if_down(ifp); - crit_exit(); if (ng_ether_detach_p != NULL) (*ng_ether_detach_p)(ifp); @@ -863,6 +875,8 @@ ether_ioctl(struct ifnet *ifp, int command, caddr_t data) struct ifreq *ifr = (struct ifreq *) data; int error = 0; + ASSERT_SERIALIZED(ifp->if_serializer); + switch (command) { case SIOCSIFADDR: ifp->if_flags |= IFF_UP; diff --git a/sys/net/if_fddisubr.c b/sys/net/if_fddisubr.c index 178e7258e3..5fa4bd44e2 100644 --- a/sys/net/if_fddisubr.c +++ b/sys/net/if_fddisubr.c @@ -34,7 +34,7 @@ * * from: if_ethersubr.c,v 1.5 1994/12/13 22:31:45 wollman Exp * $FreeBSD: src/sys/net/if_fddisubr.c,v 1.41.2.8 2002/02/20 23:34:09 fjoe Exp $ - * $DragonFly: src/sys/net/Attic/if_fddisubr.c,v 1.18 2005/06/03 23:23:03 joerg Exp $ + * $DragonFly: src/sys/net/Attic/if_fddisubr.c,v 1.19 2005/11/28 17:13:45 dillon Exp $ */ #include "opt_atalk.h" @@ -47,6 +47,7 @@ #include #include #include +#include #include #include @@ -361,6 +362,8 @@ fddi_input(struct ifnet *ifp, struct mbuf *m) struct llc *l; struct fddi_header *fh = mtod(m, struct fddi_header *); + ASSERT_SERIALIZED(ifp->if_serializer); + if (m->m_len < sizeof(struct fddi_header)) { /* XXX error in the caller. */ m_freem(m); @@ -501,8 +504,7 @@ fddi_input(struct ifnet *ifp, struct mbuf *m) #endif void -fddi_ifattach(ifp) - struct ifnet *ifp; +fddi_ifattach(struct ifnet *ifp, lwkt_serialize_t serializer) { struct sockaddr_dl *sdl; @@ -518,7 +520,7 @@ fddi_ifattach(ifp) #ifdef IFF_NOTRAILERS ifp->if_flags |= IFF_NOTRAILERS; #endif - if_attach(ifp); + if_attach(ifp, serializer); #if defined(__DragonFly__) || defined(__FreeBSD__) sdl = IF_LLSOCKADDR(ifp); sdl->sdl_type = IFT_FDDI; diff --git a/sys/net/if_iso88025subr.c b/sys/net/if_iso88025subr.c index ccd6f5ff70..4fa765aab8 100644 --- a/sys/net/if_iso88025subr.c +++ b/sys/net/if_iso88025subr.c @@ -31,7 +31,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/net/if_iso88025subr.c,v 1.7.2.7 2002/06/18 00:15:31 kbyanc Exp $ - * $DragonFly: src/sys/net/Attic/if_iso88025subr.c,v 1.13 2005/06/15 19:29:30 joerg Exp $ + * $DragonFly: src/sys/net/Attic/if_iso88025subr.c,v 1.14 2005/11/28 17:13:45 dillon Exp $ * */ @@ -51,6 +51,7 @@ #include #include #include +#include #include #include @@ -88,13 +89,13 @@ static int iso88025_output(struct ifnet *, struct mbuf *, static void iso88025_input(struct ifnet *, struct mbuf *); void -iso88025_ifattach(struct ifnet *ifp) +iso88025_ifattach(struct ifnet *ifp, lwkt_serialize_t serializer) { struct sockaddr_dl *sdl; ifp->if_input = iso88025_input; ifp->if_output = iso88025_output; - if_attach(ifp); + if_attach(ifp, serializer); ifp->if_type = IFT_ISO88025; ifp->if_addrlen = ISO88025_ADDR_LEN; ifp->if_hdrlen = ISO88025_HDR_LEN; @@ -124,12 +125,16 @@ iso88025_ioctl(struct ifnet *ifp, int command, caddr_t data) switch (ifa->ifa_addr->sa_family) { #ifdef INET case AF_INET: + lwkt_serialize_enter(ifp->if_serializer); ifp->if_init(ifp->if_softc); /* before arpwhohas */ + lwkt_serialize_exit(ifp->if_serializer); arp_ifinit(ifp, ifa); break; #endif default: + lwkt_serialize_enter(ifp->if_serializer); ifp->if_init(ifp->if_softc); + lwkt_serialize_exit(ifp->if_serializer); break; } break; @@ -314,6 +319,8 @@ iso88025_input(struct ifnet *ifp, struct mbuf *m) int isr, hdr_len; u_short ether_type; + ASSERT_SERIALIZED(ifp->if_serializer); + if (!(ifp->if_flags & IFF_UP)) { m_freem(m); return; diff --git a/sys/net/if_loop.c b/sys/net/if_loop.c index bec326dffd..37cf4343cb 100644 --- a/sys/net/if_loop.c +++ b/sys/net/if_loop.c @@ -32,7 +32,7 @@ * * @(#)if_loop.c 8.1 (Berkeley) 6/10/93 * $FreeBSD: src/sys/net/if_loop.c,v 1.47.2.8 2003/06/01 01:46:11 silby Exp $ - * $DragonFly: src/sys/net/if_loop.c,v 1.18 2005/11/22 00:24:34 dillon Exp $ + * $DragonFly: src/sys/net/if_loop.c,v 1.19 2005/11/28 17:13:45 dillon Exp $ */ /* @@ -129,7 +129,7 @@ loopattach(void *dummy) #ifdef ALTQ ifp->if_start = lo_altqstart; #endif - if_attach(ifp); + if_attach(ifp, NULL); bpfattach(ifp, DLT_NULL, sizeof(u_int)); } } @@ -255,6 +255,11 @@ if_simloop(struct ifnet *ifp, struct mbuf *m, int af, int hlen) afp = mtod(m, int32_t *); *afp = (int32_t)af; + /* + * A critical section is needed for subsystems protected by + * the MP lock, and the serializer is assumed to already + * be held for MPSAFE subsystems. + */ crit_enter(); error = ifq_enqueue(&ifp->if_snd, m, &pktattr); (*ifp->if_start)(ifp); diff --git a/sys/net/if_media.c b/sys/net/if_media.c index 1364ea6479..d8880c192b 100644 --- a/sys/net/if_media.c +++ b/sys/net/if_media.c @@ -1,6 +1,6 @@ /* $NetBSD: if_media.c,v 1.1 1997/03/17 02:55:15 thorpej Exp $ */ /* $FreeBSD: src/sys/net/if_media.c,v 1.9.2.4 2001/07/04 00:12:38 brooks Exp $ */ -/* $DragonFly: src/sys/net/if_media.c,v 1.7 2004/12/21 02:54:14 hsu Exp $ */ +/* $DragonFly: src/sys/net/if_media.c,v 1.8 2005/11/28 17:13:45 dillon Exp $ */ /* * Copyright (c) 1997 @@ -187,7 +187,8 @@ ifmedia_set(ifm, target) } /* - * Device-independent media ioctl support function. + * Device-independent media ioctl support function, typically called + * from the device network ioctl procedure. */ int ifmedia_ioctl(ifp, ifr, ifm, cmd) @@ -203,8 +204,9 @@ ifmedia_ioctl(ifp, ifr, ifm, cmd) if (ifp == NULL || ifr == NULL || ifm == NULL) return (EINVAL); - switch (cmd) { + ASSERT_SERIALIZED(ifp->if_serializer); + switch (cmd) { /* * Set the current media. */ diff --git a/sys/net/if_var.h b/sys/net/if_var.h index e650f4dde1..6c99eb1bea 100644 --- a/sys/net/if_var.h +++ b/sys/net/if_var.h @@ -32,12 +32,16 @@ * * From: @(#)if.h 8.1 (Berkeley) 6/10/93 * $FreeBSD: src/sys/net/if_var.h,v 1.18.2.16 2003/04/15 18:11:19 fjoe Exp $ - * $DragonFly: src/sys/net/if_var.h,v 1.31 2005/10/24 08:06:16 sephe Exp $ + * $DragonFly: src/sys/net/if_var.h,v 1.32 2005/11/28 17:13:45 dillon Exp $ */ #ifndef _NET_IF_VAR_H_ #define _NET_IF_VAR_H_ +#ifndef _SYS_SERIALIZE_H_ +#include +#endif + /* * Structures defining a network interface, providing a packet * transport mechanism (ala level 0 of the PUP protocols). @@ -46,8 +50,8 @@ * length, and provides higher level routines with input datagrams * received from its medium. * - * Output occurs when the routine if_output is called, with three parameters: - * (*ifp->if_output)(ifp, m, dst, rt) + * Output occurs when the routine if_output is called, with four parameters: + * ifp->if_output(ifp, m, dst, rt) * Here m is the mbuf chain to be sent and dst is the destination address. * The output routine encapsulates the supplied datagram if necessary, * and then transmits it on its medium. @@ -56,7 +60,7 @@ * places it on the input queue of a internetwork datagram routine * and posts the associated software interrupt, or passes the datagram to * the routine if_input. It is called with the mbuf chain as parameter: - * (*ifp->if_input)(ifp, m) + * ifp->if_input(ifp, m) * The input routine removes the protocol dependent header if necessary. * * Routines exist for locating interfaces by their addresses @@ -75,6 +79,7 @@ struct rt_addrinfo; struct socket; struct ether_header; struct ucred; +struct lwkt_serialize; #include /* get TAILQ macros */ @@ -144,13 +149,23 @@ enum poll_cmd { POLL_ONLY, POLL_AND_CHECK_STATUS, POLL_DEREGISTER, * Unfortunately devices' softc are opaque, so we depend on this layout * to locate the struct ifnet from the softc in the generic code. * - * Note that not all fields are used by drivers in the FreeBSD source - * tree. However, who knows what third party software does with fields - * marked as "unused", such as if_ipending, if_done, and if_poll*, - * so any attemt to redefine their meaning might end up in binary - * compatibility problems, even if the size of struct ifnet, and - * the size and position of its fields do not change. - * We just have to live with that. + * MPSAFE NOTES: + * + * ifnet and its related packet queues are protected by if_serializer. + * Callers of if_output, if_ioctl, if_start, if_watchdog, if_init, + * if_resolvemulti, and if_poll hold if_serializer. Device drivers usually + * use the same serializer for their interrupt but this is not required. + * However, the device driver must be holding if_serializer when it + * calls if_input. Note that the serializer may be temporarily released + * within if_input to avoid a deadlock (e.g. when fast-forwarding or + * bridging packets between interfaces). + * + * If a device driver installs the same serializer for its interrupt + * as for ifnet, then the driver only really needs to worry about further + * serialization in timeout based entry points. All other entry points + * will already be serialized. Older ISA drivers still using the old + * interrupt infrastructure will have to obtain and release the serializer + * in their interrupt routine themselves. */ struct ifnet { void *if_softc; /* pointer to driver state */ @@ -198,6 +213,8 @@ struct ifnet { const uint8_t *if_broadcastaddr; void *if_afdata[AF_MAX]; struct ifaddr *if_lladdr; + struct lwkt_serialize *if_serializer; /* serializer or MP lock */ + struct lwkt_serialize if_default_serializer; /* if not supplied */ }; typedef void if_init_f_t (void *); @@ -279,6 +296,11 @@ typedef void if_init_f_t (void *); #ifdef _KERNEL +/* + * DEPRECATED - should not be used by any new driver. This code uses the + * old queueing interface and if_start ABI and does not use the ifp's + * serializer. + */ #define IF_HANDOFF(ifq, m, ifp) if_handoff(ifq, m, ifp, 0) #define IF_HANDOFF_ADJ(ifq, m, ifp, adj) if_handoff(ifq, m, ifp, adj) @@ -303,8 +325,9 @@ if_handoff(struct ifqueue *_ifq, struct mbuf *_m, struct ifnet *_ifp, _need_if_start = !(_ifp->if_flags & IFF_OACTIVE); } IF_ENQUEUE(_ifq, _m); - if (_need_if_start) + if (_need_if_start) { (*_ifp->if_start)(_ifp); + } crit_exit(); return (1); } @@ -418,8 +441,9 @@ extern int ifqmaxlen; extern struct ifnet loif[]; extern int if_index; -void ether_ifattach(struct ifnet *, uint8_t *); -void ether_ifattach_bpf(struct ifnet *, uint8_t *, u_int, u_int); +void ether_ifattach(struct ifnet *, uint8_t *, struct lwkt_serialize *); +void ether_ifattach_bpf(struct ifnet *, uint8_t *, u_int, u_int, + struct lwkt_serialize *); void ether_ifdetach(struct ifnet *); void ether_input(struct ifnet *, struct ether_header *, struct mbuf *); void ether_demux(struct ifnet *, struct ether_header *, struct mbuf *); @@ -430,7 +454,7 @@ uint32_t ether_crc32_be(const uint8_t *, size_t); int if_addmulti(struct ifnet *, struct sockaddr *, struct ifmultiaddr **); int if_allmulti(struct ifnet *, int); -void if_attach(struct ifnet *); +void if_attach(struct ifnet *, struct lwkt_serialize *); int if_delmulti(struct ifnet *, struct sockaddr *); void if_detach(struct ifnet *); void if_down(struct ifnet *); diff --git a/sys/net/ifq_var.h b/sys/net/ifq_var.h index 6b7f1ac6e1..1b5d852193 100644 --- a/sys/net/ifq_var.h +++ b/sys/net/ifq_var.h @@ -28,8 +28,16 @@ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $DragonFly: src/sys/net/ifq_var.h,v 1.5 2005/11/22 00:24:34 dillon Exp $ + * $DragonFly: src/sys/net/ifq_var.h,v 1.6 2005/11/28 17:13:45 dillon Exp $ */ +/* + * NOTE ON MPSAFE access. Routines which manipulate the packet queue must + * be called within a critical section to interlock subsystems based on + * the MP lock, and must be holding the interface serializer to interlock + * MPSAFE subsystems. Once all subsystems are made MPSAFE, the critical + * section will no longer be required. + */ + #ifndef _NET_IFQ_VAR_H #define _NET_IFQ_VAR_H @@ -61,24 +69,36 @@ ifq_is_attached(struct ifaltq *_ifq) } #endif +/* + * WARNING: Should only be called in an MPSAFE manner. + */ static __inline int ifq_is_ready(struct ifaltq *_ifq) { return(_ifq->altq_flags & ALTQF_READY); } +/* + * WARNING: Should only be called in an MPSAFE manner. + */ static __inline void ifq_set_ready(struct ifaltq *_ifq) { _ifq->altq_flags |= ALTQF_READY; } +/* + * WARNING: Should only be called in an MPSAFE manner. + */ static __inline int ifq_enqueue(struct ifaltq *_ifq, struct mbuf *_m, struct altq_pktattr *_pa) { return((*_ifq->altq_enqueue)(_ifq, _m, _pa)); } +/* + * WARNING: Should only be called in an MPSAFE manner. + */ static __inline struct mbuf * ifq_dequeue(struct ifaltq *_ifq, struct mbuf *_mpolled) { @@ -89,6 +109,9 @@ ifq_dequeue(struct ifaltq *_ifq, struct mbuf *_mpolled) return((*_ifq->altq_dequeue)(_ifq, _mpolled, ALTDQ_REMOVE)); } +/* + * WARNING: Should only be called in an MPSAFE manner. + */ static __inline struct mbuf * ifq_poll(struct ifaltq *_ifq) { @@ -99,12 +122,18 @@ ifq_poll(struct ifaltq *_ifq) return((*_ifq->altq_dequeue)(_ifq, NULL, ALTDQ_POLL)); } +/* + * WARNING: Should only be called in an MPSAFE manner. + */ static __inline void ifq_purge(struct ifaltq *_ifq) { (*_ifq->altq_request)(_ifq, ALTRQ_PURGE, NULL); } +/* + * WARNING: Should only be called in an MPSAFE manner. + */ static __inline void ifq_classify(struct ifaltq *_ifq, struct mbuf *_m, uint8_t _af, struct altq_pktattr *_pa) @@ -117,12 +146,21 @@ ifq_classify(struct ifaltq *_ifq, struct mbuf *_m, uint8_t _af, (*_ifq->altq_classify)(_ifq, _m, _pa); } +/* + * Hand a packet to an interface. + * + * For subsystems protected by the MP lock, access to the queue is protected + * by a critical section. + * + * For MPSAFE subsystems and drivers, access to the queue is protected by + * the ifnet serializer. + */ static __inline int ifq_handoff(struct ifnet *_ifp, struct mbuf *_m, struct altq_pktattr *_pa) { int _error; - crit_enter(); + ASSERT_SERIALIZED(_ifp->if_serializer); _error = ifq_enqueue(&_ifp->if_snd, _m, _pa); if (_error == 0) { _ifp->if_obytes += _m->m_pkthdr.len; @@ -131,7 +169,6 @@ ifq_handoff(struct ifnet *_ifp, struct mbuf *_m, struct altq_pktattr *_pa) if ((_ifp->if_flags & IFF_OACTIVE) == 0) (*_ifp->if_start)(_ifp); } - crit_exit(); return(_error); } diff --git a/sys/net/iso88025.h b/sys/net/iso88025.h index acf0b1208a..21334357de 100644 --- a/sys/net/iso88025.h +++ b/sys/net/iso88025.h @@ -31,7 +31,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/net/iso88025.h,v 1.3.2.2 2002/06/18 00:15:31 kbyanc Exp $ - * $DragonFly: src/sys/net/Attic/iso88025.h,v 1.4 2004/07/23 07:16:30 joerg Exp $ + * $DragonFly: src/sys/net/Attic/iso88025.h,v 1.5 2005/11/28 17:13:45 dillon Exp $ * * Information gathered from tokenring@freebsd, /sys/net/ethernet.h and * the Mach token ring driver. @@ -126,7 +126,9 @@ struct iso88025_addr { #define ISO88025_DEFAULT_MTU 1500 #define senderr(e) { error = (e); goto bad;} -void iso88025_ifattach (struct ifnet *); +struct lwkt_serialize; + +void iso88025_ifattach (struct ifnet *, struct lwkt_serialize *); int iso88025_ioctl (struct ifnet *, int , caddr_t ); #endif diff --git a/sys/net/oldbridge/bridge.c b/sys/net/oldbridge/bridge.c index cc6f949136..9b92f5c285 100644 --- a/sys/net/oldbridge/bridge.c +++ b/sys/net/oldbridge/bridge.c @@ -25,7 +25,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/net/bridge.c,v 1.16.2.25 2003/01/23 21:06:44 sam Exp $ - * $DragonFly: src/sys/net/oldbridge/Attic/bridge.c,v 1.18 2005/07/05 10:20:39 corecode Exp $ + * $DragonFly: src/sys/net/oldbridge/Attic/bridge.c,v 1.19 2005/11/28 17:13:45 dillon Exp $ */ /* @@ -1035,7 +1035,9 @@ forward: return m0; bcopy(&save_eh, mtod(m, struct ether_header *), ETHER_HDR_LEN); } + lwkt_serialize_enter(last->if_serializer); error = ifq_handoff(last, m, &pktattr); + lwkt_serialize_exit(last->if_serializer); if (error != 0) { #if 0 BDG_MUTE(last); /* should I also mute ? */ diff --git a/sys/net/pf/if_pflog.c b/sys/net/pf/if_pflog.c index 378457073f..4363513bd2 100644 --- a/sys/net/pf/if_pflog.c +++ b/sys/net/pf/if_pflog.c @@ -1,6 +1,6 @@ /* $FreeBSD: src/sys/contrib/pf/net/if_pflog.c,v 1.9 2004/06/22 20:13:24 brooks Exp $ */ /* $OpenBSD: if_pflog.c,v 1.11 2003/12/31 11:18:25 cedric Exp $ */ -/* $DragonFly: src/sys/net/pf/if_pflog.c,v 1.3 2005/06/15 16:32:58 joerg Exp $ */ +/* $DragonFly: src/sys/net/pf/if_pflog.c,v 1.4 2005/11/28 17:13:45 dillon Exp $ */ /* * The authors of this code are John Ioannidis (ji@tla.org), @@ -133,7 +133,7 @@ pflog_clone_create(struct if_clone *ifc, int unit) sc->sc_if.if_snd.ifq_maxlen = ifqmaxlen; sc->sc_if.if_hdrlen = PFLOG_HDRLEN; sc->sc_if.if_softc = sc; - if_attach(&sc->sc_if); + if_attach(&sc->sc_if, NULL); LIST_INSERT_HEAD(&pflog_list, sc, sc_next); bpfattach(&sc->sc_if, DLT_PFLOG, PFLOG_HDRLEN); diff --git a/sys/net/pf/if_pfsync.c b/sys/net/pf/if_pfsync.c index 05798ccd9e..678dcef219 100644 --- a/sys/net/pf/if_pfsync.c +++ b/sys/net/pf/if_pfsync.c @@ -1,6 +1,6 @@ /* $FreeBSD: src/sys/contrib/pf/net/if_pfsync.c,v 1.11 2004/08/14 15:32:40 dwmalone Exp $ */ /* $OpenBSD: if_pfsync.c,v 1.26 2004/03/28 18:14:20 mcbride Exp $ */ -/* $DragonFly: src/sys/net/pf/if_pfsync.c,v 1.2 2005/06/15 16:32:58 joerg Exp $ */ +/* $DragonFly: src/sys/net/pf/if_pfsync.c,v 1.3 2005/11/28 17:13:45 dillon Exp $ */ /* * Copyright (c) 2004 The DragonFly Project. All rights reserved. @@ -157,7 +157,7 @@ pfsync_clone_create(struct if_clone *ifc, int unit) callout_init(&sc->sc_tmo); callout_init(&sc->sc_bulk_tmo); callout_init(&sc->sc_bulkfail_tmo); - if_attach(&sc->sc_if); + if_attach(&sc->sc_if, NULL); LIST_INSERT_HEAD(&pfsync_list, sc, sc_next); bpfattach(&sc->sc_if, DLT_PFSYNC, PFSYNC_HDRLEN); diff --git a/sys/net/pf/pf.c b/sys/net/pf/pf.c index 9e0dc70abd..3dff0447c3 100644 --- a/sys/net/pf/pf.c +++ b/sys/net/pf/pf.c @@ -1,7 +1,7 @@ /* $FreeBSD: src/sys/contrib/pf/net/pf.c,v 1.19 2004/09/11 11:18:25 mlaier Exp $ */ /* $OpenBSD: pf.c,v 1.433.2.2 2004/07/17 03:22:34 brad Exp $ */ /* add $OpenBSD: pf.c,v 1.448 2004/05/11 07:34:11 dhartmei Exp $ */ -/* $DragonFly: src/sys/net/pf/pf.c,v 1.6 2005/10/28 16:01:04 liamfoy Exp $ */ +/* $DragonFly: src/sys/net/pf/pf.c,v 1.7 2005/11/28 17:13:45 dillon Exp $ */ /* * Copyright (c) 2004 The DragonFly Project. All rights reserved. @@ -4971,7 +4971,9 @@ pf_route(struct mbuf **m, struct pf_rule *r, int dir, struct ifnet *oifp, } } + lwkt_serialize_enter(ifp->if_serializer); error = (*ifp->if_output)(ifp, m0, sintosa(dst), ro->ro_rt); + lwkt_serialize_exit(ifp->if_serializer); goto done; } @@ -4997,11 +4999,14 @@ pf_route(struct mbuf **m, struct pf_rule *r, int dir, struct ifnet *oifp, for (m0 = m1; m0; m0 = m1) { m1 = m0->m_nextpkt; m0->m_nextpkt = 0; - if (error == 0) + if (error == 0) { + lwkt_serialize_enter(ifp->if_serializer); error = (*ifp->if_output)(ifp, m0, sintosa(dst), - NULL); - else + NULL); + lwkt_serialize_exit(ifp->if_serializer); + } else { m_freem(m0); + } } if (error == 0) diff --git a/sys/net/ppp/if_ppp.c b/sys/net/ppp/if_ppp.c index 247a008520..4ff3366761 100644 --- a/sys/net/ppp/if_ppp.c +++ b/sys/net/ppp/if_ppp.c @@ -70,7 +70,7 @@ */ /* $FreeBSD: src/sys/net/if_ppp.c,v 1.67.2.4 2002/04/14 21:41:48 luigi Exp $ */ -/* $DragonFly: src/sys/net/ppp/if_ppp.c,v 1.26 2005/11/22 00:24:35 dillon Exp $ */ +/* $DragonFly: src/sys/net/ppp/if_ppp.c,v 1.27 2005/11/28 17:13:45 dillon Exp $ */ /* from if_sl.c,v 1.11 84/10/04 12:54:47 rick Exp */ /* from NetBSD: if_ppp.c,v 1.15.2.2 1994/07/28 05:17:58 cgd Exp */ @@ -205,22 +205,19 @@ pppintr(struct netmsg *msg) sc = ppp_softc; for (i = 0; i < NPPP; ++i, ++sc) { - crit_enter(); + lwkt_serialize_enter(sc->sc_if.if_serializer); if (!(sc->sc_flags & SC_TBUSY) && (!ifq_is_empty(&sc->sc_if.if_snd) || !IF_QEMPTY(&sc->sc_fastq))) { sc->sc_flags |= SC_TBUSY; - crit_exit(); (*sc->sc_start)(sc); - } else - crit_exit(); + } for (;;) { - crit_enter(); IF_DEQUEUE(&sc->sc_rawq, m); - crit_exit(); if (m == NULL) break; ppp_inproc(sc, m); } + lwkt_serialize_exit(sc->sc_if.if_serializer); } lwkt_replymsg(&msg->nm_lmsg, 0); return(EASYNC); @@ -251,7 +248,7 @@ pppattach(dummy) sc->sc_fastq.ifq_maxlen = IFQ_MAXLEN; sc->sc_rawq.ifq_maxlen = IFQ_MAXLEN; callout_init(&sc->sc_timeout); - if_attach(&sc->sc_if); + if_attach(&sc->sc_if, NULL); bpfattach(&sc->sc_if, DLT_PPP, PPP_HDRLEN); } netisr_register(NETISR_PPP, cpu0_portfn, pppintr); @@ -879,7 +876,9 @@ pppoutput(ifp, m0, dst, rtp) error = 0; } } else { + lwkt_serialize_enter(sc->sc_if.if_serializer); error = ifq_enqueue(&sc->sc_if.if_snd, m0, &pktattr); + lwkt_serialize_exit(sc->sc_if.if_serializer); } if (error) { crit_exit(); @@ -941,7 +940,9 @@ ppp_requeue(sc) error = 0; } } else { + lwkt_serialize_enter(sc->sc_if.if_serializer); error = ifq_enqueue(&sc->sc_if.if_snd, m, NULL); + lwkt_serialize_exit(sc->sc_if.if_serializer); } if (error) { sc->sc_if.if_oerrors++; @@ -1268,6 +1269,8 @@ ppp_inproc(sc, m) u_char *iphdr; u_int hlen; + ASSERT_SERIALIZED(ifp->if_serializer); + sc->sc_stats.ppp_ipackets++; if (sc->sc_flags & SC_LOG_INPKT) { @@ -1491,7 +1494,7 @@ ppp_inproc(sc, m) m->m_pkthdr.len -= PPP_HDRLEN; m->m_data += PPP_HDRLEN; m->m_len -= PPP_HDRLEN; - if (ipflow_fastforward(m)) + if (ipflow_fastforward(m, ifp->if_serializer)) return; isr = NETISR_IP; break; diff --git a/sys/net/sl/if_sl.c b/sys/net/sl/if_sl.c index 6e9f3f9399..9d49ba92aa 100644 --- a/sys/net/sl/if_sl.c +++ b/sys/net/sl/if_sl.c @@ -32,7 +32,7 @@ * * @(#)if_sl.c 8.6 (Berkeley) 2/1/94 * $FreeBSD: src/sys/net/if_sl.c,v 1.84.2.2 2002/02/13 00:43:10 dillon Exp $ - * $DragonFly: src/sys/net/sl/if_sl.c,v 1.20 2005/11/22 00:24:35 dillon Exp $ + * $DragonFly: src/sys/net/sl/if_sl.c,v 1.21 2005/11/28 17:13:46 dillon Exp $ */ /* @@ -229,7 +229,7 @@ slattach(dummy) sc->sc_if.if_linkmiblen = sizeof *sc; callout_init(&sc->sc_oftimeout); callout_init(&sc->sc_katimeout); - if_attach(&sc->sc_if); + if_attach(&sc->sc_if, NULL); bpfattach(&sc->sc_if, DLT_SLIP, SLIP_HDRLEN); } } @@ -498,7 +498,9 @@ sloutput(ifp, m, dst, rtp) error = 0; } } else { + lwkt_serialize_enter(sc->sc_if.if_serializer); error = ifq_enqueue(&sc->sc_if.if_snd, m, &pktattr); + lwkt_serialize_enter(sc->sc_if.if_serializer); } if (error) { sc->sc_if.if_oerrors++; diff --git a/sys/net/sppp/if_spppsubr.c b/sys/net/sppp/if_spppsubr.c index 03c2dfd7f8..4dca01b4b5 100644 --- a/sys/net/sppp/if_spppsubr.c +++ b/sys/net/sppp/if_spppsubr.c @@ -18,7 +18,7 @@ * From: Version 2.4, Thu Apr 30 17:17:21 MSD 1997 * * $FreeBSD: src/sys/net/if_spppsubr.c,v 1.59.2.13 2002/07/03 15:44:41 joerg Exp $ - * $DragonFly: src/sys/net/sppp/if_spppsubr.c,v 1.21 2005/11/22 00:24:35 dillon Exp $ + * $DragonFly: src/sys/net/sppp/if_spppsubr.c,v 1.22 2005/11/28 17:13:46 dillon Exp $ */ #include @@ -968,7 +968,9 @@ sppp_output(struct ifnet *ifp, struct mbuf *m, rv = 0; } } else { + lwkt_serialize_enter(ifp->if_serializer); rv = ifq_enqueue(&ifp->if_snd, m, &pktattr); + lwkt_serialize_exit(ifp->if_serializer); } if (rv) { ++ifp->if_oerrors; @@ -4714,6 +4716,7 @@ sppp_keepalive(void *dummy) lcp.Up(sp); } } + lwkt_serialize_enter(ifp->if_serializer); if (sp->pp_alivecnt <= MAXALIVECNT) ++sp->pp_alivecnt; if (sp->pp_mode == IFF_CISCO) @@ -4725,6 +4728,7 @@ sppp_keepalive(void *dummy) sppp_cp_send (sp, PPP_LCP, ECHO_REQ, sp->lcp.echoid, 4, &nmagic); } + lwkt_serialize_exit(ifp->if_serializer); } callout_reset(&keepalive_timeout, hz * 10, sppp_keepalive, NULL); crit_exit(); diff --git a/sys/net/stf/if_stf.c b/sys/net/stf/if_stf.c index 15efd4bc8f..734ff15c32 100644 --- a/sys/net/stf/if_stf.c +++ b/sys/net/stf/if_stf.c @@ -1,5 +1,5 @@ /* $FreeBSD: src/sys/net/if_stf.c,v 1.1.2.11 2003/01/23 21:06:44 sam Exp $ */ -/* $DragonFly: src/sys/net/stf/if_stf.c,v 1.14 2005/01/26 00:37:39 joerg Exp $ */ +/* $DragonFly: src/sys/net/stf/if_stf.c,v 1.15 2005/11/28 17:13:46 dillon Exp $ */ /* $KAME: if_stf.c,v 1.73 2001/12/03 11:08:30 keiichi Exp $ */ /* @@ -191,7 +191,7 @@ stfmodevent(mod, type, data) sc->sc_if.if_flags |= IFF_LINK2; #endif sc->sc_if.if_snd.ifq_maxlen = IFQ_MAXLEN; - if_attach(&sc->sc_if); + if_attach(&sc->sc_if, NULL); bpfattach(&sc->sc_if, DLT_NULL, sizeof(u_int)); break; case MOD_UNLOAD: diff --git a/sys/net/tap/if_tap.c b/sys/net/tap/if_tap.c index 9d6e1cd197..8bf37100d5 100644 --- a/sys/net/tap/if_tap.c +++ b/sys/net/tap/if_tap.c @@ -32,7 +32,7 @@ /* * $FreeBSD: src/sys/net/if_tap.c,v 1.3.2.3 2002/04/14 21:41:48 luigi Exp $ - * $DragonFly: src/sys/net/tap/if_tap.c,v 1.21 2005/11/22 00:24:35 dillon Exp $ + * $DragonFly: src/sys/net/tap/if_tap.c,v 1.22 2005/11/28 17:13:46 dillon Exp $ * $Id: if_tap.c,v 0.21 2000/07/23 21:46:02 max Exp $ */ @@ -56,6 +56,7 @@ #include #include #include +#include #include #include @@ -159,13 +160,13 @@ tapmodevent(mod, type, data) /* XXX: maintain tap ifs in a local list */ unit = 0; while (unit <= taplastunit) { - crit_enter(); - TAILQ_FOREACH(ifp, &ifnet, if_link) + TAILQ_FOREACH(ifp, &ifnet, if_link) { if ((strcmp(ifp->if_dname, TAP) == 0) || - (strcmp(ifp->if_dname, VMNET) == 0)) + (strcmp(ifp->if_dname, VMNET) == 0)) { if (ifp->if_dunit == unit) break; - crit_exit(); + } + } if (ifp != NULL) { struct tap_softc *tp = ifp->if_softc; @@ -174,9 +175,9 @@ tapmodevent(mod, type, data) "taplastunit = %d\n", minor(tp->tap_dev), taplastunit); - crit_enter(); + lwkt_serialize_enter(ifp->if_serializer); ether_ifdetach(ifp); - crit_exit(); + lwkt_serialize_exit(ifp->if_serializer); destroy_dev(tp->tap_dev); free(tp, M_TAP); } @@ -252,7 +253,7 @@ tapcreate(dev) ifq_set_maxlen(&ifp->if_snd, ifqmaxlen); ifq_set_ready(&ifp->if_snd); - ether_ifattach(ifp, ether_addr); + ether_ifattach(ifp, ether_addr, NULL); tp->tap_flags |= TAP_INITED; @@ -310,9 +311,9 @@ tapclose(dev_t dev, int foo, int bar, d_thread_t *td) /* junk all pending output */ - crit_enter(); + lwkt_serialize_enter(ifp->if_serializer); ifq_purge(&ifp->if_snd); - crit_exit(); + lwkt_serialize_exit(ifp->if_serializer); /* * do not bring the interface down, and do not anything with @@ -320,8 +321,8 @@ tapclose(dev_t dev, int foo, int bar, d_thread_t *td) */ if (((tp->tap_flags & TAP_VMNET) == 0) && (ifp->if_flags & IFF_UP)) { - crit_enter(); if_down(ifp); + lwkt_serialize_enter(ifp->if_serializer); if (ifp->if_flags & IFF_RUNNING) { /* find internet addresses and delete routes */ struct ifaddr *ifa = NULL; @@ -342,7 +343,7 @@ tapclose(dev_t dev, int foo, int bar, d_thread_t *td) ifp->if_flags &= ~IFF_RUNNING; } - crit_exit(); + lwkt_serialize_exit(ifp->if_serializer); } funsetown(tp->tap_sigio); @@ -391,6 +392,8 @@ tapifinit(xtp) * tapifioctl * * Process an ioctl request on network interface + * + * MPSAFE */ int tapifioctl(ifp, cmd, data, cr) @@ -407,9 +410,7 @@ tapifioctl(ifp, cmd, data, cr) case SIOCSIFADDR: case SIOCGIFADDR: case SIOCSIFMTU: - crit_enter(); dummy = ether_ioctl(ifp, cmd, data); - crit_exit(); return (dummy); case SIOCSIFFLAGS: /* XXX -- just like vmnet does */ @@ -418,7 +419,6 @@ tapifioctl(ifp, cmd, data, cr) break; case SIOCGIFSTATUS: - crit_enter(); ifs = (struct ifstat *)data; dummy = strlen(ifs->ascii); if (tp->tap_td != NULL && dummy < sizeof(ifs->ascii)) { @@ -433,7 +433,6 @@ tapifioctl(ifp, cmd, data, cr) "\tOpened by td %p\n", tp->tap_td); } } - crit_exit(); break; default: @@ -467,14 +466,10 @@ tapifstart(ifp) TAPDEBUG(ifp, "not ready. minor = %#x, tap_flags = 0x%x\n", minor(tp->tap_dev), tp->tap_flags); - crit_enter(); ifq_purge(&ifp->if_snd); - crit_exit(); return; } - crit_enter(); - ifp->if_flags |= IFF_OACTIVE; if (!ifq_is_empty(&ifp->if_snd)) { @@ -486,13 +481,16 @@ tapifstart(ifp) if ((tp->tap_flags & TAP_ASYNC) && (tp->tap_sigio != NULL)) pgsigio(tp->tap_sigio, SIGIO, 0); + /* + * selwakeup is not MPSAFE. tapifstart is. + */ + get_mplock(); selwakeup(&tp->tap_rsel); + rel_mplock(); ifp->if_opackets ++; /* obytes are counted in ether_output */ } ifp->if_flags &= ~IFF_OACTIVE; - - crit_exit(); } /* tapifstart */ @@ -508,101 +506,100 @@ tapioctl(dev_t dev, u_long cmd, caddr_t data, int flag, d_thread_t *td) struct ifnet *ifp = &tp->tap_if; struct tapinfo *tapp = NULL; struct mbuf *mb; + short f; + int error; + + lwkt_serialize_enter(ifp->if_serializer); + error = 0; switch (cmd) { - case TAPSIFINFO: - crit_enter(); - tapp = (struct tapinfo *)data; - ifp->if_mtu = tapp->mtu; - ifp->if_type = tapp->type; - ifp->if_baudrate = tapp->baudrate; - crit_exit(); - break; - - case TAPGIFINFO: - tapp = (struct tapinfo *)data; - tapp->mtu = ifp->if_mtu; - tapp->type = ifp->if_type; - tapp->baudrate = ifp->if_baudrate; - break; - - case TAPSDEBUG: - tapdebug = *(int *)data; + case TAPSIFINFO: + tapp = (struct tapinfo *)data; + ifp->if_mtu = tapp->mtu; + ifp->if_type = tapp->type; + ifp->if_baudrate = tapp->baudrate; break; - case TAPGDEBUG: - *(int *)data = tapdebug; + case TAPGIFINFO: + tapp = (struct tapinfo *)data; + tapp->mtu = ifp->if_mtu; + tapp->type = ifp->if_type; + tapp->baudrate = ifp->if_baudrate; break; - case FIONBIO: + case TAPSDEBUG: + tapdebug = *(int *)data; break; - case FIOASYNC: - crit_enter(); - if (*(int *)data) - tp->tap_flags |= TAP_ASYNC; - else - tp->tap_flags &= ~TAP_ASYNC; - crit_exit(); + case TAPGDEBUG: + *(int *)data = tapdebug; break; - case FIONREAD: - crit_enter(); - *(int *)data = 0; - if ((mb = ifq_poll(&ifp->if_snd)) != NULL) { - for(; mb != NULL; mb = mb->m_next) - *(int *)data += mb->m_len; - } - crit_exit(); + case FIONBIO: break; - case FIOSETOWN: - return (fsetown(*(int *)data, &tp->tap_sigio)); + case FIOASYNC: + if (*(int *)data) + tp->tap_flags |= TAP_ASYNC; + else + tp->tap_flags &= ~TAP_ASYNC; + break; - case FIOGETOWN: - *(int *)data = fgetown(tp->tap_sigio); - return (0); + case FIONREAD: + *(int *)data = 0; + if ((mb = ifq_poll(&ifp->if_snd)) != NULL) { + for(; mb != NULL; mb = mb->m_next) + *(int *)data += mb->m_len; + } + break; - /* this is deprecated, FIOSETOWN should be used instead */ - case TIOCSPGRP: - return (fsetown(-(*(int *)data), &tp->tap_sigio)); + case FIOSETOWN: + error = fsetown(*(int *)data, &tp->tap_sigio); + break; - /* this is deprecated, FIOGETOWN should be used instead */ - case TIOCGPGRP: - *(int *)data = -fgetown(tp->tap_sigio); - return (0); + case FIOGETOWN: + *(int *)data = fgetown(tp->tap_sigio); + break; - /* VMware/VMnet port ioctl's */ + /* this is deprecated, FIOSETOWN should be used instead */ + case TIOCSPGRP: + error = fsetown(-(*(int *)data), &tp->tap_sigio); + break; - case SIOCGIFFLAGS: /* get ifnet flags */ - bcopy(&ifp->if_flags, data, sizeof(ifp->if_flags)); + /* this is deprecated, FIOGETOWN should be used instead */ + case TIOCGPGRP: + *(int *)data = -fgetown(tp->tap_sigio); break; - case VMIO_SIOCSIFFLAGS: { /* VMware/VMnet SIOCSIFFLAGS */ - short f = *(short *)data; + /* VMware/VMnet port ioctl's */ - f &= 0x0fff; - f &= ~IFF_CANTCHANGE; - f |= IFF_UP; + case SIOCGIFFLAGS: /* get ifnet flags */ + bcopy(&ifp->if_flags, data, sizeof(ifp->if_flags)); + break; - crit_enter(); - ifp->if_flags = f | (ifp->if_flags & IFF_CANTCHANGE); - crit_exit(); - } break; + case VMIO_SIOCSIFFLAGS: /* VMware/VMnet SIOCSIFFLAGS */ + f = *(short *)data; + f &= 0x0fff; + f &= ~IFF_CANTCHANGE; + f |= IFF_UP; + ifp->if_flags = f | (ifp->if_flags & IFF_CANTCHANGE); + break; - case OSIOCGIFADDR: /* get MAC address of the remote side */ - case SIOCGIFADDR: - bcopy(tp->ether_addr, data, sizeof(tp->ether_addr)); + case OSIOCGIFADDR: /* get MAC address of the remote side */ + case SIOCGIFADDR: + bcopy(tp->ether_addr, data, sizeof(tp->ether_addr)); break; - case SIOCSIFADDR: /* set MAC address of the remote side */ - bcopy(data, tp->ether_addr, sizeof(tp->ether_addr)); + case SIOCSIFADDR: /* set MAC address of the remote side */ + bcopy(data, tp->ether_addr, sizeof(tp->ether_addr)); break; - default: - return (ENOTTY); + default: + error = ENOTTY; + break; } - return (0); + lwkt_serialize_exit(ifp->if_serializer); + return (error); } /* tapioctl */ @@ -636,15 +633,19 @@ tapread(dev, uio, flag) /* sleep until we get a packet */ do { + lwkt_serialize_enter(ifp->if_serializer); m0 = ifq_dequeue(&ifp->if_snd, NULL); if (m0 == NULL) { + tp->tap_flags |= TAP_RWAIT; + tsleep_interlock(tp); + lwkt_serialize_exit(ifp->if_serializer); if (flag & IO_NDELAY) return (EWOULDBLOCK); - - tp->tap_flags |= TAP_RWAIT; - error = tsleep((caddr_t)tp, PCATCH, "taprd", 0); + error = tsleep(tp, PCATCH, "taprd", 0); if (error) return (error); + } else { + lwkt_serialize_exit(ifp->if_serializer); } } while (m0 == NULL); @@ -736,9 +737,10 @@ tapwrite(dev, uio, flag) * * adjust mbuf and give packet to the ether_input */ - - (*ifp->if_input)(ifp, top); + lwkt_serialize_enter(ifp->if_serializer); + ifp->if_input(ifp, top); ifp->if_ipackets ++; /* ibytes are counted in ether_input */ + lwkt_serialize_exit(ifp->if_serializer); return (0); } /* tapwrite */ @@ -760,8 +762,7 @@ tappoll(dev_t dev, int events, d_thread_t *td) TAPDEBUG(ifp, "polling, minor = %#x\n", minor(tp->tap_dev)); - crit_enter(); - + lwkt_serialize_enter(ifp->if_serializer); if (events & (POLLIN | POLLRDNORM)) { if (!ifq_is_empty(&ifp->if_snd)) { TAPDEBUG(ifp, @@ -777,10 +778,9 @@ tappoll(dev_t dev, int events, d_thread_t *td) selrecord(td, &tp->tap_rsel); } } + lwkt_serialize_exit(ifp->if_serializer); if (events & (POLLOUT | POLLWRNORM)) revents |= (events & (POLLOUT | POLLWRNORM)); - - crit_exit(); return (revents); } /* tappoll */ diff --git a/sys/net/tun/if_tun.c b/sys/net/tun/if_tun.c index 945e08bc53..d3900a5859 100644 --- a/sys/net/tun/if_tun.c +++ b/sys/net/tun/if_tun.c @@ -14,7 +14,7 @@ * operation though. * * $FreeBSD: src/sys/net/if_tun.c,v 1.74.2.8 2002/02/13 00:43:11 dillon Exp $ - * $DragonFly: src/sys/net/tun/if_tun.c,v 1.24 2005/11/22 00:24:35 dillon Exp $ + * $DragonFly: src/sys/net/tun/if_tun.c,v 1.25 2005/11/28 17:13:46 dillon Exp $ */ #include "opt_atalk.h" @@ -131,7 +131,7 @@ tuncreate(dev) ifq_set_maxlen(&ifp->if_snd, ifqmaxlen); ifq_set_ready(&ifp->if_snd); ifp->if_softc = sc; - if_attach(ifp); + if_attach(ifp, NULL); bpfattach(ifp, DLT_NULL, sizeof(u_int)); dev->si_drv1 = sc; } @@ -182,27 +182,29 @@ tunclose(dev_t dev, int foo, int bar, struct thread *td) tp->tun_pid = 0; /* Junk all pending output. */ - crit_enter(); + lwkt_serialize_enter(ifp->if_serializer); ifq_purge(&ifp->if_snd); - crit_exit(); + lwkt_serialize_exit(ifp->if_serializer); if (ifp->if_flags & IFF_UP) { - crit_enter(); + lwkt_serialize_enter(ifp->if_serializer); if_down(ifp); - crit_exit(); + lwkt_serialize_exit(ifp->if_serializer); } if (ifp->if_flags & IFF_RUNNING) { struct ifaddr *ifa; - crit_enter(); + lwkt_serialize_enter(ifp->if_serializer); /* find internet addresses and delete routes */ - TAILQ_FOREACH(ifa, &ifp->if_addrhead, ifa_link) - if (ifa->ifa_addr->sa_family == AF_INET) + TAILQ_FOREACH(ifa, &ifp->if_addrhead, ifa_link) { + if (ifa->ifa_addr->sa_family == AF_INET) { rtinit(ifa, (int)RTM_DELETE, tp->tun_flags & TUN_DSTADDR ? RTF_HOST : 0); + } + } ifp->if_flags &= ~IFF_RUNNING; - crit_exit(); + lwkt_serialize_exit(ifp->if_serializer); } funsetown(tp->tun_sigio); @@ -251,6 +253,8 @@ tuninit(ifp) /* * Process an ioctl request. + * + * MPSAFE */ int tunifioctl(ifp, cmd, data, cr) @@ -264,8 +268,6 @@ tunifioctl(ifp, cmd, data, cr) struct ifstat *ifs; int error = 0; - crit_enter(); - switch(cmd) { case SIOCGIFSTATUS: ifs = (struct ifstat *)data; @@ -292,13 +294,13 @@ tunifioctl(ifp, cmd, data, cr) default: error = EINVAL; } - - crit_exit(); return (error); } /* * tunoutput - queue packets from higher level ready to put out. + * + * MPSAFE */ int tunoutput(ifp, m0, dst, rt) @@ -350,9 +352,7 @@ tunoutput(ifp, m0, dst, rt) /* if allocation failed drop packet */ if (m0 == NULL){ - crit_enter(); IF_DROP(&ifp->if_snd); - crit_exit(); ifp->if_oerrors++; return (ENOBUFS); } else { @@ -366,9 +366,7 @@ tunoutput(ifp, m0, dst, rt) /* if allocation failed drop packet */ if (m0 == NULL){ - crit_enter(); IF_DROP(&ifp->if_snd); - crit_exit(); ifp->if_oerrors++; return ENOBUFS; } else @@ -390,11 +388,13 @@ tunoutput(ifp, m0, dst, rt) ifp->if_opackets++; if (tp->tun_flags & TUN_RWAIT) { tp->tun_flags &= ~TUN_RWAIT; - wakeup((caddr_t)tp); + wakeup((caddr_t)tp); } + get_mplock(); if (tp->tun_flags & TUN_ASYNC && tp->tun_sigio) pgsigio(tp->tun_sigio, SIGIO, 0); selwakeup(&tp->tun_rsel); + rel_mplock(); } return (error); } @@ -473,18 +473,17 @@ tunioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct thread *td) tp->tun_flags &= ~TUN_ASYNC; break; case FIONREAD: - crit_enter(); - + lwkt_serialize_enter(tp->tun_if.if_serializer); if (!ifq_is_empty(&tp->tun_if.if_snd)) { struct mbuf *mb; mb = ifq_poll(&tp->tun_if.if_snd); for( *(int *)data = 0; mb != 0; mb = mb->m_next) *(int *)data += mb->m_len; - } else + } else { *(int *)data = 0; - - crit_exit(); + } + lwkt_serialize_exit(tp->tun_if.if_serializer); break; case FIOSETOWN: return (fsetown(*(int *)data, &tp->tun_sigio)); @@ -531,21 +530,21 @@ tunread(dev, uio, flag) tp->tun_flags &= ~TUN_RWAIT; - crit_enter(); + lwkt_serialize_enter(ifp->if_serializer); while ((m0 = ifq_dequeue(&ifp->if_snd, NULL)) == NULL) { if (flag & IO_NDELAY) { - crit_exit(); + lwkt_serialize_exit(ifp->if_serializer); return EWOULDBLOCK; } tp->tun_flags |= TUN_RWAIT; if ((error = tsleep(tp, PCATCH, "tunread", 0)) != 0) { - crit_exit(); + lwkt_serialize_exit(ifp->if_serializer); return error; } } - crit_exit(); + lwkt_serialize_exit(ifp->if_serializer); while (m0 && uio->uio_resid > 0 && error == 0) { len = min(uio->uio_resid, m0->m_len); @@ -701,7 +700,7 @@ tunpoll(dev_t dev, int events, struct thread *td) TUNDEBUG(ifp, "tunpoll\n"); - crit_enter(); + lwkt_serialize_enter(ifp->if_serializer); if (events & (POLLIN | POLLRDNORM)) { if (!ifq_is_empty(&ifp->if_snd)) { @@ -715,7 +714,7 @@ tunpoll(dev_t dev, int events, struct thread *td) if (events & (POLLOUT | POLLWRNORM)) revents |= events & (POLLOUT | POLLWRNORM); - crit_exit(); + lwkt_serialize_exit(ifp->if_serializer); return (revents); } diff --git a/sys/net/vlan/if_vlan.c b/sys/net/vlan/if_vlan.c index f31219a530..e573124d35 100644 --- a/sys/net/vlan/if_vlan.c +++ b/sys/net/vlan/if_vlan.c @@ -27,7 +27,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/net/if_vlan.c,v 1.15.2.13 2003/02/14 22:25:58 fenner Exp $ - * $DragonFly: src/sys/net/vlan/if_vlan.c,v 1.17 2005/11/22 00:24:35 dillon Exp $ + * $DragonFly: src/sys/net/vlan/if_vlan.c,v 1.18 2005/11/28 17:13:46 dillon Exp $ */ /* @@ -232,7 +232,7 @@ vlan_clone_create(struct if_clone *ifc, int unit) ifp->if_ioctl = vlan_ioctl; ifq_set_maxlen(&ifp->if_snd, ifqmaxlen); ifq_set_ready(&ifp->if_snd); - ether_ifattach(ifp, ifv->ifv_ac.ac_enaddr); + ether_ifattach(ifp, ifv->ifv_ac.ac_enaddr, NULL); /* Now undo some of the damage... */ ifp->if_data.ifi_type = IFT_L2VLAN; ifp->if_data.ifi_hdrlen = EVL_ENCAPLEN; @@ -359,7 +359,11 @@ vlan_start(struct ifnet *ifp) * Send it, precisely as ether_output() would have. * We are already running at splimp. */ + lwkt_serialize_exit(ifp->if_serializer); + lwkt_serialize_enter(p->if_serializer); error = ifq_handoff(p, m, &pktattr); + lwkt_serialize_exit(p->if_serializer); + lwkt_serialize_enter(ifp->if_serializer); if (error) ifp->if_oerrors++; else @@ -376,14 +380,18 @@ vlan_input_tag( struct mbuf *m, uint16_t t) struct bpf_if *bif; struct ifvlan *ifv; struct ether_header *eh = mtod(m, struct ether_header *); + struct ifnet *rcvif; m_adj(m, ETHER_HDR_LEN); + rcvif = m->m_pkthdr.rcvif; + + ASSERT_SERIALIZED(rcvif->if_serializer); /* * Fake up a header and send the packet to the physical interface's * bpf tap if active. */ - if ((bif = m->m_pkthdr.rcvif->if_bpf) != NULL) { + if ((bif = rcvif->if_bpf) != NULL) { struct ether_vlan_header evh; bcopy(eh, &evh, 2*ETHER_ADDR_LEN); @@ -396,8 +404,7 @@ vlan_input_tag( struct mbuf *m, uint16_t t) for (ifv = LIST_FIRST(&ifv_list); ifv != NULL; ifv = LIST_NEXT(ifv, ifv_list)) { - if (m->m_pkthdr.rcvif == ifv->ifv_p - && ifv->ifv_tag == t) + if (rcvif == ifv->ifv_p && ifv->ifv_tag == t) break; } @@ -414,7 +421,11 @@ vlan_input_tag( struct mbuf *m, uint16_t t) m->m_pkthdr.rcvif = &ifv->ifv_if; ifv->ifv_if.if_ipackets++; + lwkt_serialize_exit(rcvif->if_serializer); + lwkt_serialize_enter(ifv->ifv_if.if_serializer); ether_input(&ifv->ifv_if, eh, m); + lwkt_serialize_exit(ifv->ifv_if.if_serializer); + lwkt_serialize_enter(rcvif->if_serializer); return 0; } @@ -422,17 +433,21 @@ static int vlan_input(struct ether_header *eh, struct mbuf *m) { struct ifvlan *ifv; + struct ifnet *rcvif; + + rcvif = m->m_pkthdr.rcvif; + ASSERT_SERIALIZED(rcvif->if_serializer); for (ifv = LIST_FIRST(&ifv_list); ifv != NULL; ifv = LIST_NEXT(ifv, ifv_list)) { - if (m->m_pkthdr.rcvif == ifv->ifv_p + if (rcvif == ifv->ifv_p && (EVL_VLANOFTAG(ntohs(*mtod(m, u_int16_t *))) == ifv->ifv_tag)) break; } if (ifv == NULL || (ifv->ifv_if.if_flags & IFF_UP) == 0) { - m->m_pkthdr.rcvif->if_noproto++; + rcvif->if_noproto++; m_freem(m); return -1; /* so ether_input can take note */ } @@ -451,7 +466,11 @@ vlan_input(struct ether_header *eh, struct mbuf *m) m->m_pkthdr.len -= EVL_ENCAPLEN; ifv->ifv_if.if_ipackets++; + lwkt_serialize_exit(rcvif->if_serializer); + lwkt_serialize_enter(ifv->ifv_if.if_serializer); ether_input(&ifv->ifv_if, eh, m); + lwkt_serialize_exit(ifv->ifv_if.if_serializer); + lwkt_serialize_enter(rcvif->if_serializer); return 0; } @@ -563,6 +582,7 @@ vlan_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data, struct ucred *cr) ifa = (struct ifaddr *)data; ifv = ifp->if_softc; + ASSERT_SERIALIZED(ifp->if_serializer); crit_enter(); switch (cmd) { @@ -592,8 +612,12 @@ vlan_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data, struct ucred *cr) case SIOCGIFMEDIA: if (ifv->ifv_p != NULL) { - error = (ifv->ifv_p->if_ioctl)(ifv->ifv_p, - SIOCGIFMEDIA, data, cr); + lwkt_serialize_exit(ifp->if_serializer); + lwkt_serialize_enter(ifv->ifv_p->if_serializer); + error = ifv->ifv_p->if_ioctl(ifv->ifv_p, + SIOCGIFMEDIA, data, cr); + lwkt_serialize_exit(ifv->ifv_p->if_serializer); + lwkt_serialize_enter(ifp->if_serializer); /* Limit the result to the parent's current config. */ if (error == 0) { struct ifmediareq *ifmr; diff --git a/sys/netgraph/eiface/ng_eiface.c b/sys/netgraph/eiface/ng_eiface.c index 2a795806f7..723e23d168 100644 --- a/sys/netgraph/eiface/ng_eiface.c +++ b/sys/netgraph/eiface/ng_eiface.c @@ -28,7 +28,7 @@ * * $Id: ng_eiface.c,v 1.14 2000/03/15 12:28:44 vitaly Exp $ * $FreeBSD: src/sys/netgraph/ng_eiface.c,v 1.4.2.5 2002/12/17 21:47:48 julian Exp $ - * $DragonFly: src/sys/netgraph/eiface/ng_eiface.c,v 1.8 2005/06/02 22:11:45 swildner Exp $ + * $DragonFly: src/sys/netgraph/eiface/ng_eiface.c,v 1.9 2005/11/28 17:13:46 dillon Exp $ */ #include @@ -41,6 +41,7 @@ #include #include #include +#include #include #include @@ -354,7 +355,7 @@ ng_eiface_constructor(node_p *nodep) */ /* Attach the interface */ - ether_ifattach(ifp, priv->arpcom.ac_enaddr); + ether_ifattach(ifp, priv->arpcom.ac_enaddr, NULL); /* Done */ return (0); @@ -504,7 +505,9 @@ ng_eiface_rcvdata(hook_p hook, struct mbuf *m, meta_p meta) return (EINVAL); } + lwkt_serialize_enter(ifp->if_serializer); if ( !(ifp->if_flags & IFF_UP) ) { + lwkt_serialize_exit(ifp->if_serializer); return (ENETDOWN); } @@ -516,7 +519,8 @@ ng_eiface_rcvdata(hook_p hook, struct mbuf *m, meta_p meta) BPF_MTAP(ifp, m); - (*ifp->if_input)(ifp, m); + ifp->if_input(ifp, m); + lwkt_serialize_exit(ifp->if_serializer); /* Done */ return (error); @@ -536,7 +540,9 @@ ng_eiface_rmnode(node_p node) ng_cutlinks(node); node->flags &= ~NG_INVALID; + lwkt_serialize_enter(ifp->if_serializer); ifp->if_flags &= ~(IFF_UP | IFF_RUNNING | IFF_OACTIVE); + lwkt_serialize_exit(ifp->if_serializer); return (0); } diff --git a/sys/netgraph/ether/ng_ether.c b/sys/netgraph/ether/ng_ether.c index 4ae887b6d4..15d37ab365 100644 --- a/sys/netgraph/ether/ng_ether.c +++ b/sys/netgraph/ether/ng_ether.c @@ -38,7 +38,7 @@ * Julian Elischer * * $FreeBSD: src/sys/netgraph/ng_ether.c,v 1.2.2.13 2002/07/02 20:10:25 archie Exp $ - * $DragonFly: src/sys/netgraph/ether/ng_ether.c,v 1.7 2005/06/02 22:11:45 swildner Exp $ + * $DragonFly: src/sys/netgraph/ether/ng_ether.c,v 1.8 2005/11/28 17:13:46 dillon Exp $ */ /* @@ -576,6 +576,7 @@ ng_ether_rcv_lower(node_p node, struct mbuf *m, meta_p meta) { const priv_p priv = node->private; struct ifnet *const ifp = priv->ifp; + int error; /* Discard meta info */ NG_FREE_META(meta); @@ -610,7 +611,11 @@ ng_ether_rcv_lower(node_p node, struct mbuf *m, meta_p meta) } /* Send it on its way */ - return ether_output_frame(ifp, m); + lwkt_serialize_enter(ifp->if_serializer); + error = ether_output_frame(ifp, m); + lwkt_serialize_exit(ifp->if_serializer); + + return (error); } /* @@ -639,7 +644,9 @@ ng_ether_rcv_upper(node_p node, struct mbuf *m, meta_p meta) m->m_pkthdr.rcvif = priv->ifp; /* Route packet back in */ + lwkt_serialize_enter(priv->ifp->if_serializer); ether_demux(priv->ifp, eh, m); + lwkt_serialize_exit(priv->ifp->if_serializer); return (0); } diff --git a/sys/netgraph/fec/ng_fec.c b/sys/netgraph/fec/ng_fec.c index b0e6af9ee5..d29ccda5e6 100644 --- a/sys/netgraph/fec/ng_fec.c +++ b/sys/netgraph/fec/ng_fec.c @@ -33,7 +33,7 @@ * THE POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD: src/sys/netgraph/ng_fec.c,v 1.1.2.1 2002/11/01 21:39:31 julian Exp $ - * $DragonFly: src/sys/netgraph/fec/ng_fec.c,v 1.15 2005/06/03 23:31:36 joerg Exp $ + * $DragonFly: src/sys/netgraph/fec/ng_fec.c,v 1.16 2005/11/28 17:13:46 dillon Exp $ */ /* * Copyright (c) 1996-1999 Whistle Communications, Inc. @@ -444,7 +444,7 @@ ng_fec_delport(struct ng_fec_private *priv, char *iface) /* Stop interface */ bifp->if_flags &= ~IFF_UP; - (*bifp->if_ioctl)(bifp, SIOCSIFFLAGS, NULL, NULL); + bifp->if_ioctl(bifp, SIOCSIFFLAGS, NULL, NULL); /* Restore MAC address. */ ac = (struct arpcom *)bifp; @@ -464,7 +464,6 @@ ng_fec_delport(struct ng_fec_private *priv, char *iface) * Pass an ioctl command down to all the underyling interfaces in a * bundle. Used for setting multicast filters and flags. */ - static int ng_fec_setport(struct ifnet *ifp, u_long command, caddr_t data) { @@ -476,11 +475,16 @@ ng_fec_setport(struct ifnet *ifp, u_long command, caddr_t data) priv = ifp->if_softc; b = &priv->fec_bundle; + lwkt_serialize_exit(ifp->if_serializer); /* XXX */ TAILQ_FOREACH(p, &b->ng_fec_ports, fec_list) { oifp = p->fec_if; - if (oifp != NULL) - (*oifp->if_ioctl)(oifp, command, data, NULL); + if (oifp != NULL) { + lwkt_serialize_enter(oifp->if_serializer); + oifp->if_ioctl(oifp, command, data, NULL); + lwkt_serialize_exit(oifp->if_serializer); + } } + lwkt_serialize_enter(ifp->if_serializer); return(0); } @@ -506,13 +510,17 @@ ng_fec_init(void *arg) ng_fec_stop(ifp); + lwkt_serialize_exit(ifp->if_serializer); /* XXX */ TAILQ_FOREACH(p, &b->ng_fec_ports, fec_list) { bifp = p->fec_if; + lwkt_serialize_enter(bifp->if_serializer); bifp->if_flags |= IFF_UP; - (*bifp->if_ioctl)(bifp, SIOCSIFFLAGS, NULL, NULL); + bifp->if_ioctl(bifp, SIOCSIFFLAGS, NULL, NULL); /* mark iface as up and let the monitor check it */ p->fec_ifstat = -1; + lwkt_serialize_exit(bifp->if_serializer); } + lwkt_serialize_enter(ifp->if_serializer); callout_reset(&priv->fec_timeout, hz, ng_fec_tick, priv); } @@ -528,13 +536,16 @@ ng_fec_stop(struct ifnet *ifp) priv = ifp->if_softc; b = &priv->fec_bundle; + lwkt_serialize_exit(ifp->if_serializer); /* XXX */ TAILQ_FOREACH(p, &b->ng_fec_ports, fec_list) { bifp = p->fec_if; + lwkt_serialize_enter(bifp->if_serializer); bifp->if_flags &= ~IFF_UP; - (*bifp->if_ioctl)(bifp, SIOCSIFFLAGS, NULL, NULL); + bifp->if_ioctl(bifp, SIOCSIFFLAGS, NULL, NULL); + lwkt_serialize_exit(bifp->if_serializer); } - callout_stop(&priv->fec_timeout); + lwkt_serialize_enter(ifp->if_serializer); /* XXX */ } static void @@ -550,14 +561,19 @@ ng_fec_tick(void *arg) priv = arg; b = &priv->fec_bundle; + /* + * Note: serializer for parent interface not held on entry, and + * cannot be held during the loop to avoid a deadlock. + */ TAILQ_FOREACH(p, &b->ng_fec_ports, fec_list) { bzero((char *)&ifmr, sizeof(ifmr)); ifp = p->fec_if; - error = (*ifp->if_ioctl)(ifp, SIOCGIFMEDIA, (caddr_t)&ifmr, - NULL); + lwkt_serialize_enter(ifp->if_serializer); + error = ifp->if_ioctl(ifp, SIOCGIFMEDIA, (caddr_t)&ifmr, NULL); if (error) { printf("fec%d: failed to check status " "of link %s\n", priv->unit, ifp->if_xname); + lwkt_serialize_exit(ifp->if_serializer); continue; } @@ -581,6 +597,7 @@ ng_fec_tick(void *arg) } } } + lwkt_serialize_exit(ifp->if_serializer); } ifp = &priv->arpcom.ac_if; @@ -972,7 +989,11 @@ ng_fec_start(struct ifnet *ifp) } ifp->if_opackets++; + lwkt_serialize_exit(ifp->if_serializer); + lwkt_serialize_enter(oifp->if_serializer); priv->if_error = ether_output_frame(oifp, m0); + lwkt_serialize_exit(oifp->if_serializer); + lwkt_serialize_enter(ifp->if_serializer); } #ifdef DEBUG @@ -1086,7 +1107,7 @@ ng_fec_constructor(node_p *nodep) ng_ether_input_p = ng_fec_input; /* Attach the interface */ - ether_ifattach(ifp, priv->arpcom.ac_enaddr); + ether_ifattach(ifp, priv->arpcom.ac_enaddr, NULL); priv->real_if_output = ifp->if_output; ifp->if_output = ng_fec_output; callout_init(&priv->fec_timeout); diff --git a/sys/netgraph/iface/ng_iface.c b/sys/netgraph/iface/ng_iface.c index 4c184ede30..4c982ae7fd 100644 --- a/sys/netgraph/iface/ng_iface.c +++ b/sys/netgraph/iface/ng_iface.c @@ -37,7 +37,7 @@ * Author: Archie Cobbs * * $FreeBSD: src/sys/netgraph/ng_iface.c,v 1.7.2.5 2002/07/02 23:44:02 archie Exp $ - * $DragonFly: src/sys/netgraph/iface/ng_iface.c,v 1.11 2005/06/02 22:11:45 swildner Exp $ + * $DragonFly: src/sys/netgraph/iface/ng_iface.c,v 1.12 2005/11/28 17:13:46 dillon Exp $ * $Whistle: ng_iface.c,v 1.33 1999/11/01 09:24:51 julian Exp $ */ @@ -591,7 +591,7 @@ ng_iface_constructor(node_p *nodep) log(LOG_WARNING, "%s: can't acquire netgraph name\n", ifname); /* Attach the interface */ - if_attach(ifp); + if_attach(ifp, NULL); bpfattach(ifp, DLT_NULL, sizeof(u_int)); /* Done */ diff --git a/sys/netinet/if_atm.c b/sys/netinet/if_atm.c index f8674d13d9..f341ce07fd 100644 --- a/sys/netinet/if_atm.c +++ b/sys/netinet/if_atm.c @@ -32,7 +32,7 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD: src/sys/netinet/if_atm.c,v 1.8.2.1 2001/12/20 10:30:18 ru Exp $ - * $DragonFly: src/sys/netinet/if_atm.c,v 1.6 2004/12/21 02:54:15 hsu Exp $ + * $DragonFly: src/sys/netinet/if_atm.c,v 1.7 2005/11/28 17:13:46 dillon Exp $ */ /* @@ -88,6 +88,7 @@ atm_rtrequest(req, rt, info) struct atm_pseudohdr *aph; #endif static struct sockaddr_dl null_sdl = {sizeof(null_sdl), AF_LINK}; + int error; if (rt->rt_flags & RTF_GATEWAY) /* link level requests only */ return; @@ -153,8 +154,11 @@ atm_rtrequest(req, rt, info) */ bcopy(LLADDR(SDL(gate)), &api.aph, sizeof(api.aph)); api.rxhand = NULL; - if (rt->rt_ifp->if_ioctl(rt->rt_ifp, SIOCATMENA, (caddr_t)&api, - (struct ucred *)NULL) != 0) { + lwkt_serialize_enter(rt->rt_ifp->if_serializer); + error = rt->rt_ifp->if_ioctl(rt->rt_ifp, SIOCATMENA, + (caddr_t)&api, NULL); + lwkt_serialize_exit(rt->rt_ifp->if_serializer); + if (error) { printf("atm: couldn't add VC\n"); goto failed; } @@ -195,9 +199,10 @@ failed: bcopy(LLADDR(SDL(gate)), &api.aph, sizeof(api.aph)); api.rxhand = NULL; + lwkt_serialize_enter(rt->rt_ifp->if_serializer); rt->rt_ifp->if_ioctl(rt->rt_ifp, SIOCATMDIS, (caddr_t)&api, (struct ucred *)NULL); - + lwkt_serialize_exit(rt->rt_ifp->if_serializer); break; } } diff --git a/sys/netinet/if_ether.c b/sys/netinet/if_ether.c index 5edd36bcfc..98d1f58488 100644 --- a/sys/netinet/if_ether.c +++ b/sys/netinet/if_ether.c @@ -82,7 +82,7 @@ * * @(#)if_ether.c 8.1 (Berkeley) 6/10/93 * $FreeBSD: src/sys/netinet/if_ether.c,v 1.64.2.23 2003/04/11 07:23:15 fjoe Exp $ - * $DragonFly: src/sys/netinet/if_ether.c,v 1.27 2005/06/02 23:52:42 dillon Exp $ + * $DragonFly: src/sys/netinet/if_ether.c,v 1.28 2005/11/28 17:13:46 dillon Exp $ */ /* @@ -775,7 +775,9 @@ match: la->la_preempt = arp_maxtries; if (la->la_hold != NULL) { m_adj(la->la_hold, sizeof(struct ether_header)); + lwkt_serialize_enter(ifp->if_serializer); (*ifp->if_output)(ifp, la->la_hold, rt_key(rt), rt); + lwkt_serialize_exit(ifp->if_serializer); la->la_hold = NULL; } } @@ -873,7 +875,9 @@ reply: } sa.sa_family = AF_UNSPEC; sa.sa_len = sizeof sa; + lwkt_serialize_enter(ifp->if_serializer); (*ifp->if_output)(ifp, m, &sa, (struct rtentry *)0); + lwkt_serialize_exit(ifp->if_serializer); return; } #endif diff --git a/sys/netinet/if_fddi.h b/sys/netinet/if_fddi.h index 0a5a158a5c..0bec395f1c 100644 --- a/sys/netinet/if_fddi.h +++ b/sys/netinet/if_fddi.h @@ -34,7 +34,7 @@ * * @(#)if_fddi.h 8.1 (Berkeley) 6/10/93 * $FreeBSD: src/sys/netinet/if_fddi.h,v 1.8 1999/12/29 04:40:58 peter Exp $ - * $DragonFly: src/sys/netinet/Attic/if_fddi.h,v 1.5 2004/12/21 02:54:15 hsu Exp $ + * $DragonFly: src/sys/netinet/Attic/if_fddi.h,v 1.6 2005/11/28 17:13:46 dillon Exp $ */ #ifndef _NETINET_IF_FDDI_H_ @@ -78,7 +78,9 @@ struct fddi_header { #define fddi_delmulti ether_delmulti #define fddi_sprintf ether_sprintf -void fddi_ifattach (struct ifnet *); +struct lwkt_serialize; + +void fddi_ifattach (struct ifnet *, struct lwkt_serialize *); #endif diff --git a/sys/netinet/in.c b/sys/netinet/in.c index 37a99408a5..083f4ed576 100644 --- a/sys/netinet/in.c +++ b/sys/netinet/in.c @@ -32,7 +32,7 @@ * * @(#)in.c 8.4 (Berkeley) 1/9/95 * $FreeBSD: src/sys/netinet/in.c,v 1.44.2.14 2002/11/08 00:45:50 suz Exp $ - * $DragonFly: src/sys/netinet/in.c,v 1.16 2005/06/04 14:41:57 joerg Exp $ + * $DragonFly: src/sys/netinet/in.c,v 1.17 2005/11/28 17:13:46 dillon Exp $ */ #include "opt_bootp.h" @@ -348,10 +348,12 @@ in_control(so, cmd, data, ifp, td) return (EINVAL); oldaddr = ia->ia_dstaddr; ia->ia_dstaddr = *(struct sockaddr_in *)&ifr->ifr_dstaddr; + lwkt_serialize_enter(ifp->if_serializer); if (ifp->if_ioctl && - (error = (*ifp->if_ioctl)(ifp, SIOCSIFDSTADDR, (caddr_t)ia, + (error = ifp->if_ioctl(ifp, SIOCSIFDSTADDR, (caddr_t)ia, td->td_proc->p_ucred))) { ia->ia_dstaddr = oldaddr; + lwkt_serialize_exit(ifp->if_serializer); return (error); } if (ia->ia_flags & IFA_ROUTE) { @@ -361,6 +363,7 @@ in_control(so, cmd, data, ifp, td) (struct sockaddr *)&ia->ia_dstaddr; rtinit(&ia->ia_ifa, RTM_ADD, RTF_HOST | RTF_UP); } + lwkt_serialize_exit(ifp->if_serializer); return (0); case SIOCSIFBRDADDR: @@ -442,19 +445,22 @@ in_control(so, cmd, data, ifp, td) default: if (ifp == NULL || ifp->if_ioctl == NULL) return (EOPNOTSUPP); - return ((*ifp->if_ioctl)(ifp, cmd, data, td->td_proc->p_ucred)); + lwkt_serialize_enter(ifp->if_serializer); + error = ifp->if_ioctl(ifp, cmd, data, td->td_proc->p_ucred); + lwkt_serialize_exit(ifp->if_serializer); + return (error); } /* * Protect from ipintr() traversing address list while we're modifying * it. */ - crit_enter(); + lwkt_serialize_enter(ifp->if_serializer); TAILQ_REMOVE(&ifp->if_addrhead, &ia->ia_ifa, ifa_link); TAILQ_REMOVE(&in_ifaddrhead, ia, ia_link); LIST_REMOVE(ia, ia_hash); IFAFREE(&ia->ia_ifa); - crit_exit(); + lwkt_serialize_exit(ifp->if_serializer); return (error); } @@ -671,7 +677,7 @@ in_ifinit(ifp, ia, sin, scrub) struct sockaddr_in oldaddr; int flags = RTF_UP, error = 0; - crit_enter(); + lwkt_serialize_enter(ifp->if_serializer); oldaddr = ia->ia_addr; if (oldaddr.sin_family == AF_INET) @@ -686,9 +692,8 @@ in_ifinit(ifp, ia, sin, scrub) * and to validate the address if necessary. */ if (ifp->if_ioctl && - (error = (*ifp->if_ioctl)(ifp, SIOCSIFADDR, (caddr_t)ia, - (struct ucred *)NULL))) { - crit_exit(); + (error = ifp->if_ioctl(ifp, SIOCSIFADDR, (caddr_t)ia, NULL))) { + lwkt_serialize_exit(ifp->if_serializer); /* LIST_REMOVE(ia, ia_hash) is done in in_control */ ia->ia_addr = oldaddr; if (ia->ia_addr.sin_family == AF_INET) @@ -696,7 +701,7 @@ in_ifinit(ifp, ia, sin, scrub) ia, ia_hash); return (error); } - crit_exit(); + lwkt_serialize_exit(ifp->if_serializer); if (scrub) { ia->ia_ifa.ifa_addr = (struct sockaddr *)&oldaddr; in_ifscrub(ifp, ia); diff --git a/sys/netinet/in_var.h b/sys/netinet/in_var.h index 9b1204647f..05760de045 100644 --- a/sys/netinet/in_var.h +++ b/sys/netinet/in_var.h @@ -32,7 +32,7 @@ * * @(#)in_var.h 8.2 (Berkeley) 1/9/95 * $FreeBSD: src/sys/netinet/in_var.h,v 1.33.2.3 2001/12/14 20:09:34 jlemon Exp $ - * $DragonFly: src/sys/netinet/in_var.h,v 1.9 2005/06/04 14:41:57 joerg Exp $ + * $DragonFly: src/sys/netinet/in_var.h,v 1.10 2005/11/28 17:13:46 dillon Exp $ */ #ifndef _NETINET_IN_VAR_H_ @@ -224,6 +224,7 @@ do { \ struct route; struct netmsg; +struct lwkt_serialize; void in_ifdetach(struct ifnet *ifp); struct in_multi *in_addmulti (struct in_addr *, struct ifnet *); @@ -234,7 +235,7 @@ void in_rtqdrain (void); void ip_input (struct mbuf *); int in_ifadown (struct ifaddr *ifa, int); void in_ifscrub (struct ifnet *, struct in_ifaddr *); -int ipflow_fastforward (struct mbuf *); +int ipflow_fastforward (struct mbuf *, struct lwkt_serialize *); void ipflow_create (const struct route *, struct mbuf *); void ipflow_slowtimo (void); diff --git a/sys/netinet/ip_flow.c b/sys/netinet/ip_flow.c index 80aea29921..0a9313d894 100644 --- a/sys/netinet/ip_flow.c +++ b/sys/netinet/ip_flow.c @@ -34,7 +34,7 @@ * POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD: src/sys/netinet/ip_flow.c,v 1.9.2.2 2001/11/04 17:35:31 luigi Exp $ - * $DragonFly: src/sys/netinet/ip_flow.c,v 1.8 2005/06/02 23:52:42 dillon Exp $ + * $DragonFly: src/sys/netinet/ip_flow.c,v 1.9 2005/11/28 17:13:46 dillon Exp $ */ #include @@ -104,7 +104,7 @@ ipflow_lookup(const struct ip *ip) } int -ipflow_fastforward(struct mbuf *m) +ipflow_fastforward(struct mbuf *m, lwkt_serialize_t serializer) { struct ip *ip; struct ipflow *ipf; @@ -163,12 +163,18 @@ ipflow_fastforward(struct mbuf *m) dst = rt->rt_gateway; else dst = &ipf->ipf_ro.ro_dst; + if (serializer) + lwkt_serialize_exit(serializer); + lwkt_serialize_enter(rt->rt_ifp->if_serializer); if ((error = (*rt->rt_ifp->if_output)(rt->rt_ifp, m, dst, rt)) != 0) { if (error == ENOBUFS) ipf->ipf_dropped++; else ipf->ipf_errors++; } + lwkt_serialize_exit(rt->rt_ifp->if_serializer); + if (serializer) + lwkt_serialize_enter(serializer); return 1; } diff --git a/sys/netinet/ip_output.c b/sys/netinet/ip_output.c index 1b03b353bd..45d9fbbcd5 100644 --- a/sys/netinet/ip_output.c +++ b/sys/netinet/ip_output.c @@ -28,7 +28,7 @@ * * @(#)ip_output.c 8.3 (Berkeley) 1/21/94 * $FreeBSD: src/sys/netinet/ip_output.c,v 1.99.2.37 2003/04/15 06:44:45 silby Exp $ - * $DragonFly: src/sys/netinet/ip_output.c,v 1.32 2005/08/15 16:46:21 dillon Exp $ + * $DragonFly: src/sys/netinet/ip_output.c,v 1.33 2005/11/28 17:13:46 dillon Exp $ */ #define _IP_VHL @@ -1002,8 +1002,10 @@ pass: m->m_pkthdr.len = tmp; } #endif + lwkt_serialize_enter(ifp->if_serializer); error = (*ifp->if_output)(ifp, m, (struct sockaddr *)dst, ro->ro_rt); + lwkt_serialize_exit(ifp->if_serializer); goto done; } @@ -1045,11 +1047,14 @@ pass: ia->ia_ifa.if_opackets++; ia->ia_ifa.if_obytes += m->m_pkthdr.len; } + lwkt_serialize_enter(ifp->if_serializer); error = (*ifp->if_output)(ifp, m, (struct sockaddr *)dst, ro->ro_rt); - } else + lwkt_serialize_exit(ifp->if_serializer); + } else { m_freem(m); + } } if (error == 0) diff --git a/sys/netinet6/in6.c b/sys/netinet6/in6.c index 3e1ae96295..97b5c70c81 100644 --- a/sys/netinet6/in6.c +++ b/sys/netinet6/in6.c @@ -1,5 +1,5 @@ /* $FreeBSD: src/sys/netinet6/in6.c,v 1.7.2.9 2002/04/28 05:40:26 suz Exp $ */ -/* $DragonFly: src/sys/netinet6/in6.c,v 1.15 2005/07/26 20:48:41 dillon Exp $ */ +/* $DragonFly: src/sys/netinet6/in6.c,v 1.16 2005/11/28 17:13:46 dillon Exp $ */ /* $KAME: in6.c,v 1.259 2002/01/21 11:37:50 keiichi Exp $ */ /* @@ -363,6 +363,7 @@ in6_control(struct socket *so, u_long cmd, caddr_t data, struct in6_ifaddr *ia = NULL; struct in6_aliasreq *ifra = (struct in6_aliasreq *)data; int privileged; + int error; privileged = 0; if (suser(td) == 0) @@ -744,7 +745,10 @@ in6_control(struct socket *so, u_long cmd, caddr_t data, default: if (ifp == NULL || ifp->if_ioctl == 0) return(EOPNOTSUPP); - return((*ifp->if_ioctl)(ifp, cmd, data, td->td_proc->p_ucred)); + lwkt_serialize_enter(ifp->if_serializer); + error = ifp->if_ioctl(ifp, cmd, data, td->td_proc->p_ucred); + lwkt_serialize_exit(ifp->if_serializer); + return (error); } return(0); @@ -1538,7 +1542,7 @@ in6_ifinit(struct ifnet *ifp, struct in6_ifaddr *ia, struct sockaddr_in6 *sin6, int error = 0, plen, ifacount = 0; struct ifaddr *ifa; - crit_enter(); + lwkt_serialize_enter(ifp->if_serializer); /* * Give the interface a chance to initialize @@ -1557,12 +1561,12 @@ in6_ifinit(struct ifnet *ifp, struct in6_ifaddr *ia, struct sockaddr_in6 *sin6, ia->ia_addr = *sin6; if (ifacount <= 1 && ifp->if_ioctl && - (error = (*ifp->if_ioctl)(ifp, SIOCSIFADDR, (caddr_t)ia, + (error = ifp->if_ioctl(ifp, SIOCSIFADDR, (caddr_t)ia, (struct ucred *)NULL))) { - crit_exit(); + lwkt_serialize_exit(ifp->if_serializer); return(error); } - crit_exit(); + lwkt_serialize_exit(ifp->if_serializer); ia->ia_ifa.ifa_metric = ifp->if_metric; diff --git a/sys/netinet6/ip6_mroute.c b/sys/netinet6/ip6_mroute.c index c969c67d3e..f52079a967 100644 --- a/sys/netinet6/ip6_mroute.c +++ b/sys/netinet6/ip6_mroute.c @@ -1,5 +1,5 @@ /* $FreeBSD: src/sys/netinet6/ip6_mroute.c,v 1.2.2.9 2003/01/23 21:06:47 sam Exp $ */ -/* $DragonFly: src/sys/netinet6/ip6_mroute.c,v 1.9 2005/06/03 19:56:08 eirikn Exp $ */ +/* $DragonFly: src/sys/netinet6/ip6_mroute.c,v 1.10 2005/11/28 17:13:46 dillon Exp $ */ /* $KAME: ip6_mroute.c,v 1.58 2001/12/18 02:36:31 itojun Exp $ */ /* @@ -425,8 +425,6 @@ ip6_mrouter_done(void) struct mf6c *rt; struct rtdetq *rte; - crit_enter(); - /* * For each phyint in use, disable promiscuous reception of all IPv6 * multicasts. @@ -449,9 +447,10 @@ ip6_mrouter_done(void) ifr.ifr_addr.sin6_family = AF_INET6; ifr.ifr_addr.sin6_addr= in6addr_any; ifp = mif6table[mifi].m6_ifp; - (*ifp->if_ioctl)(ifp, SIOCDELMULTI, - (caddr_t)&ifr, - (struct ucred *)NULL); + lwkt_serialize_enter(ifp->if_serializer); + ifp->if_ioctl(ifp, SIOCDELMULTI, + (caddr_t)&ifr, NULL); + lwkt_serialize_exit(ifp->if_serializer); } } } @@ -497,8 +496,6 @@ ip6_mrouter_done(void) ip6_mrouter = NULL; ip6_mrouter_ver = 0; - crit_exit(); - #ifdef MRT6DEBUG if (mrt6debug) log(LOG_DEBUG, "ip6_mrouter_done\n"); @@ -1449,8 +1446,10 @@ phyint_send(struct ip6_hdr *ip6, struct mif6 *mifp, struct mbuf *m) * We just call if_output instead of nd6_output here, since * we need no ND for a multicast forwarded packet...right? */ + lwkt_serialize_enter(ifp->if_serializer); error = (*ifp->if_output)(ifp, mb_copy, (struct sockaddr *)&ro.ro_dst, NULL); + lwkt_serialize_exit(ifp->if_serializer); #ifdef MRT6DEBUG if (mrt6debug & DEBUG_XMIT) log(LOG_DEBUG, "phyint_send on mif %d err %d\n", diff --git a/sys/netinet6/nd6.c b/sys/netinet6/nd6.c index cdd436d14d..7b47b1ca89 100644 --- a/sys/netinet6/nd6.c +++ b/sys/netinet6/nd6.c @@ -1,5 +1,5 @@ /* $FreeBSD: src/sys/netinet6/nd6.c,v 1.2.2.15 2003/05/06 06:46:58 suz Exp $ */ -/* $DragonFly: src/sys/netinet6/nd6.c,v 1.16 2005/06/03 19:56:08 eirikn Exp $ */ +/* $DragonFly: src/sys/netinet6/nd6.c,v 1.17 2005/11/28 17:13:46 dillon Exp $ */ /* $KAME: nd6.c,v 1.144 2001/05/24 07:44:00 itojun Exp $ */ /* @@ -1959,11 +1959,15 @@ lookup: rt->rt_gwroute = rtlookup(rt->rt_gateway); sendpkt: + lwkt_serialize_enter(ifp->if_serializer); if ((ifp->if_flags & IFF_LOOPBACK) != 0) { - return((*ifp->if_output)(origifp, m, (struct sockaddr *)dst, - rt)); + error = (*ifp->if_output)(origifp, m, (struct sockaddr *)dst, + rt); + } else { + error = (*ifp->if_output)(ifp, m, (struct sockaddr *)dst, rt); } - return((*ifp->if_output)(ifp, m, (struct sockaddr *)dst, rt)); + lwkt_serialize_exit(ifp->if_serializer); + return (error); bad: if (m) diff --git a/sys/netproto/802_11/ieee80211.c b/sys/netproto/802_11/ieee80211.c index a3ddfb9957..86b50705ba 100644 --- a/sys/netproto/802_11/ieee80211.c +++ b/sys/netproto/802_11/ieee80211.c @@ -30,7 +30,7 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD: src/sys/net80211/ieee80211.c,v 1.13 2004/05/30 17:57:45 phk Exp $ - * $DragonFly: src/sys/netproto/802_11/Attic/ieee80211.c,v 1.3 2005/01/26 00:37:40 joerg Exp $ + * $DragonFly: src/sys/netproto/802_11/Attic/ieee80211.c,v 1.4 2005/11/28 17:13:46 dillon Exp $ */ /* @@ -97,7 +97,7 @@ ieee80211_ifattach(struct ifnet *ifp) struct ieee80211_channel *c; int i; - ether_ifattach(ifp, ic->ic_myaddr); + ether_ifattach(ifp, ic->ic_myaddr, NULL); bpfattach_dlt(ifp, DLT_IEEE802_11, sizeof(struct ieee80211_frame_addr4), &ic->ic_rawbpf); ieee80211_crypto_attach(ifp); diff --git a/sys/netproto/802_11/ieee80211_input.c b/sys/netproto/802_11/ieee80211_input.c index c2c9dbcc36..88d09f653d 100644 --- a/sys/netproto/802_11/ieee80211_input.c +++ b/sys/netproto/802_11/ieee80211_input.c @@ -30,7 +30,7 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD: src/sys/net80211/ieee80211_input.c,v 1.21 2004/06/13 17:29:09 mlaier Exp $ - * $DragonFly: src/sys/netproto/802_11/Attic/ieee80211_input.c,v 1.2 2005/01/26 00:37:40 joerg Exp $ + * $DragonFly: src/sys/netproto/802_11/Attic/ieee80211_input.c,v 1.3 2005/11/28 17:13:46 dillon Exp $ */ #include "opt_inet.h" @@ -299,7 +299,7 @@ ieee80211_input(struct ifnet *ifp, struct mbuf *m, struct ieee80211_node *ni, } } if (m != NULL) - (*ifp->if_input)(ifp, m); + ifp->if_input(ifp, m); return; case IEEE80211_FC0_TYPE_MGT: diff --git a/sys/netproto/802_11/wlan/ieee80211.c b/sys/netproto/802_11/wlan/ieee80211.c index 8d6e0879c0..81f1dd17d6 100644 --- a/sys/netproto/802_11/wlan/ieee80211.c +++ b/sys/netproto/802_11/wlan/ieee80211.c @@ -30,7 +30,7 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD: src/sys/net80211/ieee80211.c,v 1.13 2004/05/30 17:57:45 phk Exp $ - * $DragonFly: src/sys/netproto/802_11/wlan/ieee80211.c,v 1.3 2005/01/26 00:37:40 joerg Exp $ + * $DragonFly: src/sys/netproto/802_11/wlan/ieee80211.c,v 1.4 2005/11/28 17:13:46 dillon Exp $ */ /* @@ -97,7 +97,7 @@ ieee80211_ifattach(struct ifnet *ifp) struct ieee80211_channel *c; int i; - ether_ifattach(ifp, ic->ic_myaddr); + ether_ifattach(ifp, ic->ic_myaddr, NULL); bpfattach_dlt(ifp, DLT_IEEE802_11, sizeof(struct ieee80211_frame_addr4), &ic->ic_rawbpf); ieee80211_crypto_attach(ifp); diff --git a/sys/netproto/802_11/wlan/ieee80211_input.c b/sys/netproto/802_11/wlan/ieee80211_input.c index e3ba098ddb..7c8307b091 100644 --- a/sys/netproto/802_11/wlan/ieee80211_input.c +++ b/sys/netproto/802_11/wlan/ieee80211_input.c @@ -30,7 +30,7 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD: src/sys/net80211/ieee80211_input.c,v 1.21 2004/06/13 17:29:09 mlaier Exp $ - * $DragonFly: src/sys/netproto/802_11/wlan/ieee80211_input.c,v 1.2 2005/01/26 00:37:40 joerg Exp $ + * $DragonFly: src/sys/netproto/802_11/wlan/ieee80211_input.c,v 1.3 2005/11/28 17:13:46 dillon Exp $ */ #include "opt_inet.h" @@ -299,7 +299,7 @@ ieee80211_input(struct ifnet *ifp, struct mbuf *m, struct ieee80211_node *ni, } } if (m != NULL) - (*ifp->if_input)(ifp, m); + ifp->if_input(ifp, m); return; case IEEE80211_FC0_TYPE_MGT: diff --git a/sys/netproto/atalk/aarp.c b/sys/netproto/atalk/aarp.c index b815a69744..947551afc7 100644 --- a/sys/netproto/atalk/aarp.c +++ b/sys/netproto/atalk/aarp.c @@ -3,7 +3,7 @@ * All Rights Reserved. * * $FreeBSD: src/sys/netatalk/aarp.c,v 1.12.2.2 2001/06/23 20:43:09 iedowse Exp $ - * $DragonFly: src/sys/netproto/atalk/aarp.c,v 1.16 2005/06/10 22:43:58 dillon Exp $ + * $DragonFly: src/sys/netproto/atalk/aarp.c,v 1.17 2005/11/28 17:13:46 dillon Exp $ */ #include "opt_atalk.h" @@ -190,8 +190,10 @@ aarpwhohas( struct arpcom *ac, struct sockaddr_at *sat ) sa.sa_len = sizeof( struct sockaddr ); sa.sa_family = AF_UNSPEC; + lwkt_serialize_enter(ac->ac_if.if_serializer); (*ac->ac_if.if_output)(&ac->ac_if, m, &sa, NULL); /* XXX NULL should be routing information */ + lwkt_serialize_exit(ac->ac_if.if_serializer); } int @@ -399,8 +401,10 @@ at_aarpinput( struct arpcom *ac, struct mbuf *m) sat.sat_len = sizeof(struct sockaddr_at); sat.sat_family = AF_APPLETALK; sat.sat_addr = spa; + lwkt_serialize_enter(ac->ac_if.if_serializer); (*ac->ac_if.if_output)( &ac->ac_if, mhold, (struct sockaddr *)&sat, NULL); /* XXX */ + lwkt_serialize_exit(ac->ac_if.if_serializer); } } else if ((tpa.s_net == ma.s_net) && (tpa.s_node == ma.s_node) @@ -456,7 +460,9 @@ at_aarpinput( struct arpcom *ac, struct mbuf *m) sa.sa_len = sizeof( struct sockaddr ); sa.sa_family = AF_UNSPEC; + lwkt_serialize_enter(ac->ac_if.if_serializer); (*ac->ac_if.if_output)( &ac->ac_if, m, &sa, NULL); /* XXX */ + lwkt_serialize_exit(ac->ac_if.if_serializer); return; } @@ -600,7 +606,9 @@ aarpprobe( void *arg ) sa.sa_len = sizeof( struct sockaddr ); sa.sa_family = AF_UNSPEC; + lwkt_serialize_enter(ac->ac_if.if_serializer); (*ac->ac_if.if_output)(&ac->ac_if, m, &sa, NULL); /* XXX */ + lwkt_serialize_exit(ac->ac_if.if_serializer); aa->aa_probcnt--; } diff --git a/sys/netproto/atalk/at_control.c b/sys/netproto/atalk/at_control.c index de372f7764..d46b13473a 100644 --- a/sys/netproto/atalk/at_control.c +++ b/sys/netproto/atalk/at_control.c @@ -2,7 +2,7 @@ * Copyright (c) 1990,1991 Regents of The University of Michigan. * All Rights Reserved. * - * $DragonFly: src/sys/netproto/atalk/at_control.c,v 1.8 2005/06/10 22:43:58 dillon Exp $ + * $DragonFly: src/sys/netproto/atalk/at_control.c,v 1.9 2005/11/28 17:13:46 dillon Exp $ */ #include @@ -54,6 +54,7 @@ at_control(struct socket *so, u_long cmd, caddr_t data, struct at_ifaddr *aa0; struct at_ifaddr *aa = 0; struct ifaddr *ifa, *ifa0; + int error; /* * If we have an ifp, then find the matching at_ifaddr if it exists @@ -324,7 +325,10 @@ at_control(struct socket *so, u_long cmd, caddr_t data, default: if ( ifp == 0 || ifp->if_ioctl == 0 ) return( EOPNOTSUPP ); - return( (*ifp->if_ioctl)( ifp, cmd, data, td->td_proc->p_ucred )); + lwkt_serialize_enter(ifp->if_serializer); + error = ifp->if_ioctl(ifp, cmd, data, td->td_proc->p_ucred); + lwkt_serialize_exit(ifp->if_serializer); + return (error); } return( 0 ); } @@ -577,9 +581,10 @@ at_ifinit( ifp, aa, sat ) * Now that we have selected an address, we need to tell the interface * about it, just in case it needs to adjust something. */ - if ( ifp->if_ioctl && - ( error = (*ifp->if_ioctl)( ifp, SIOCSIFADDR, (caddr_t)aa, - (struct ucred *)NULL ))) { + lwkt_serialize_enter(ifp->if_serializer); + if (ifp->if_ioctl && + (error = ifp->if_ioctl(ifp, SIOCSIFADDR, (caddr_t)aa, NULL)) + ) { /* * of course this could mean that it objects violently * so if it does, we back out again.. @@ -587,9 +592,11 @@ at_ifinit( ifp, aa, sat ) aa->aa_addr = oldaddr; aa->aa_firstnet = onr.nr_firstnet; aa->aa_lastnet = onr.nr_lastnet; + lwkt_serialize_exit(ifp->if_serializer); crit_exit(); return( error ); } + lwkt_serialize_exit(ifp->if_serializer); /* * set up the netmask part of the at_ifaddr diff --git a/sys/netproto/atalk/ddp_output.c b/sys/netproto/atalk/ddp_output.c index 30e092b320..8ca2793920 100644 --- a/sys/netproto/atalk/ddp_output.c +++ b/sys/netproto/atalk/ddp_output.c @@ -22,7 +22,7 @@ */ /* $FreeBSD: src/sys/netatalk/ddp_output.c,v 1.13.6.1 2000/06/02 22:39:07 archie Exp $ */ -/* $DragonFly: src/sys/netproto/atalk/ddp_output.c,v 1.7 2004/06/03 15:04:51 joerg Exp $ */ +/* $DragonFly: src/sys/netproto/atalk/ddp_output.c,v 1.8 2005/11/28 17:13:46 dillon Exp $ */ #include #include @@ -121,6 +121,7 @@ ddp_route( struct mbuf *m, struct route *ro) struct at_ifaddr *aa = NULL; struct ifnet *ifp = NULL; u_short net; + int error; #if 0 /* Check for net zero, node zero ("myself") */ @@ -228,6 +229,9 @@ ddp_route( struct mbuf *m, struct route *ro) return (if_simloop(ifp, m, gate.sat_family, 0)); } - return((*ifp->if_output)( ifp, - m, (struct sockaddr *)&gate, NULL)); /* XXX */ + /* XXX */ + lwkt_serialize_enter(ifp->if_serializer); + error = (*ifp->if_output)( ifp, m, (struct sockaddr *)&gate, NULL); + lwkt_serialize_exit(ifp->if_serializer); + return (error); } diff --git a/sys/netproto/atm/atm_if.c b/sys/netproto/atm/atm_if.c index 2a2776e40c..58bea34446 100644 --- a/sys/netproto/atm/atm_if.c +++ b/sys/netproto/atm/atm_if.c @@ -24,7 +24,7 @@ * notice must be reproduced on all copies. * * @(#) $FreeBSD: src/sys/netatm/atm_if.c,v 1.5 1999/08/28 00:48:35 peter Exp $ - * @(#) $DragonFly: src/sys/netproto/atm/atm_if.c,v 1.11 2005/06/03 23:23:03 joerg Exp $ + * @(#) $DragonFly: src/sys/netproto/atm/atm_if.c,v 1.12 2005/11/28 17:13:46 dillon Exp $ */ /* @@ -712,8 +712,7 @@ atm_netconv_deregister(ncp) * */ int -atm_nif_attach(nip) - struct atm_nif *nip; +atm_nif_attach(struct atm_nif *nip, lwkt_serialize_t serializer) { struct atm_pif *pip, *pip2; struct ifnet *ifp; @@ -739,7 +738,7 @@ atm_nif_attach(nip) /* * Add to system interface list */ - if_attach(ifp); + if_attach(ifp, serializer); /* * Add to physical interface list diff --git a/sys/netproto/atm/atm_var.h b/sys/netproto/atm/atm_var.h index 83ffc8116b..adb78ab3a0 100644 --- a/sys/netproto/atm/atm_var.h +++ b/sys/netproto/atm/atm_var.h @@ -24,7 +24,7 @@ * notice must be reproduced on all copies. * * @(#) $FreeBSD: src/sys/netatm/atm_var.h,v 1.2 1999/08/28 00:48:39 peter Exp $ - * @(#) $DragonFly: src/sys/netproto/atm/atm_var.h,v 1.9 2005/02/01 00:51:50 joerg Exp $ + * @(#) $DragonFly: src/sys/netproto/atm/atm_var.h,v 1.10 2005/11/28 17:13:46 dillon Exp $ * */ @@ -70,6 +70,8 @@ extern struct sp_info atm_attributes_pool; /* atm_usrreq.c */ extern struct pr_usrreqs atm_dgram_usrreqs; +struct lwkt_serialize; + /* * Global function declarations */ @@ -120,7 +122,7 @@ int atm_physif_deregister (Cmn_unit *); void atm_physif_freenifs (struct atm_pif *); int atm_netconv_register (struct atm_ncm *); int atm_netconv_deregister (struct atm_ncm *); -int atm_nif_attach (struct atm_nif *); +int atm_nif_attach (struct atm_nif *, struct lwkt_serialize *); void atm_nif_detach (struct atm_nif *); int atm_nif_setaddr (struct atm_nif *, struct ifaddr *); int atm_ifoutput (struct ifnet *, KBuffer *, diff --git a/sys/netproto/ipx/ipx.c b/sys/netproto/ipx/ipx.c index d4d62104c1..25482b1612 100644 --- a/sys/netproto/ipx/ipx.c +++ b/sys/netproto/ipx/ipx.c @@ -34,7 +34,7 @@ * @(#)ipx.c * * $FreeBSD: src/sys/netipx/ipx.c,v 1.17.2.3 2003/04/04 09:35:43 tjr Exp $ - * $DragonFly: src/sys/netproto/ipx/ipx.c,v 1.8 2005/06/10 22:34:49 dillon Exp $ + * $DragonFly: src/sys/netproto/ipx/ipx.c,v 1.9 2005/11/28 17:13:46 dillon Exp $ */ #include @@ -165,9 +165,10 @@ ipx_control(struct socket *so, u_long cmd, caddr_t data, ia->ia_flags &= ~IFA_ROUTE; } if (ifp->if_ioctl) { - error = (*ifp->if_ioctl)(ifp, SIOCSIFDSTADDR, - (void *)ia, - td->td_proc->p_ucred); + lwkt_serialize_enter(ifp->if_serializer); + error = ifp->if_ioctl(ifp, SIOCSIFDSTADDR, + (void *)ia, td->td_proc->p_ucred); + lwkt_serialize_exit(ifp->if_serializer); if (error) return (error); } @@ -223,7 +224,10 @@ ipx_control(struct socket *so, u_long cmd, caddr_t data, default: if (ifp->if_ioctl == NULL) return (EOPNOTSUPP); - return ((*ifp->if_ioctl)(ifp, cmd, data, td->td_proc->p_ucred)); + lwkt_serialize_enter(ifp->if_serializer); + error = ifp->if_ioctl(ifp, cmd, data, td->td_proc->p_ucred); + lwkt_serialize_exit(ifp->if_serializer); + return (error); } } @@ -257,8 +261,6 @@ ipx_ifinit(ifp, ia, sipx, scrub) struct sockaddr_ipx oldaddr; int error; - crit_enter(); - /* * Set up new addresses. */ @@ -276,14 +278,15 @@ ipx_ifinit(ifp, ia, sipx, scrub) * if this is its first address, * and to validate the address if necessary. */ + lwkt_serialize_enter(ifp->if_serializer); if (ifp->if_ioctl != NULL && - (error = (*ifp->if_ioctl)(ifp, SIOCSIFADDR, (void *)ia, + (error = ifp->if_ioctl(ifp, SIOCSIFADDR, (void *)ia, (struct ucred *)NULL))) { ia->ia_addr = oldaddr; - crit_exit(); + lwkt_serialize_exit(ifp->if_serializer); return (error); } - crit_exit(); + lwkt_serialize_exit(ifp->if_serializer); ia->ia_ifa.ifa_metric = ifp->if_metric; /* * Add route for the network. diff --git a/sys/netproto/ipx/ipx_ip.c b/sys/netproto/ipx/ipx_ip.c index 7854a098f5..cb67714af2 100644 --- a/sys/netproto/ipx/ipx_ip.c +++ b/sys/netproto/ipx/ipx_ip.c @@ -34,7 +34,7 @@ * @(#)ipx_ip.c * * $FreeBSD: src/sys/netipx/ipx_ip.c,v 1.24.2.2 2003/01/23 21:06:48 sam Exp $ - * $DragonFly: src/sys/netproto/ipx/ipx_ip.c,v 1.14 2005/06/09 02:03:39 hsu Exp $ + * $DragonFly: src/sys/netproto/ipx/ipx_ip.c,v 1.15 2005/11/28 17:13:46 dillon Exp $ */ /* @@ -115,7 +115,7 @@ ipxipattach() ifp->if_output = ipxipoutput; ifp->if_start = ipxipstart; ifp->if_flags = IFF_POINTOPOINT; - if_attach(ifp); + if_attach(ifp, NULL); return (m); } diff --git a/sys/netproto/ipx/ipx_outputfl.c b/sys/netproto/ipx/ipx_outputfl.c index 264491c473..849f93de85 100644 --- a/sys/netproto/ipx/ipx_outputfl.c +++ b/sys/netproto/ipx/ipx_outputfl.c @@ -34,7 +34,7 @@ * @(#)ipx_outputfl.c * * $FreeBSD: src/sys/netipx/ipx_outputfl.c,v 1.14.2.1 2000/05/01 01:10:24 bp Exp $ - * $DragonFly: src/sys/netproto/ipx/ipx_outputfl.c,v 1.6 2004/07/27 13:50:15 hmp Exp $ + * $DragonFly: src/sys/netproto/ipx/ipx_outputfl.c,v 1.7 2005/11/28 17:13:46 dillon Exp $ */ #include @@ -131,8 +131,10 @@ gotif: if (ipx_copy_output) { ipx_watch_output(m0, ifp); } + lwkt_serialize_enter(ifp->if_serializer); error = (*ifp->if_output)(ifp, m0, (struct sockaddr *)dst, ro->ro_rt); + lwkt_serialize_exit(ifp->if_serializer); goto done; } else { ipxstat.ipxs_mtutoosmall++; @@ -247,8 +249,10 @@ ipx_output_type20(m) m1 = m_copym(m, 0, M_COPYALL, MB_DONTWAIT); if(m1) { + lwkt_serialize_enter(ifp->if_serializer); error = (*ifp->if_output)(ifp, m1, (struct sockaddr *)&dst, NULL); + lwkt_serialize_exit(ifp->if_serializer); /* XXX ipxstat.ipxs_localout++; */ } skip_this: ; diff --git a/sys/netproto/natm/natm.c b/sys/netproto/natm/natm.c index fe31def9e3..18b0248041 100644 --- a/sys/netproto/natm/natm.c +++ b/sys/netproto/natm/natm.c @@ -1,6 +1,6 @@ /* $NetBSD: natm.c,v 1.5 1996/11/09 03:26:26 chuck Exp $ */ /* $FreeBSD: src/sys/netnatm/natm.c,v 1.12 2000/02/13 03:32:03 peter Exp $ */ -/* $DragonFly: src/sys/netproto/natm/natm.c,v 1.18 2005/06/10 22:34:51 dillon Exp $ */ +/* $DragonFly: src/sys/netproto/natm/natm.c,v 1.19 2005/11/28 17:13:47 dillon Exp $ */ /* * @@ -213,16 +213,16 @@ natm_usr_connect(struct socket *so, struct sockaddr *nam, struct thread *td) ATM_PH_VPI(&api.aph) = npcb->npcb_vpi; ATM_PH_SETVCI(&api.aph, npcb->npcb_vci); api.rxhand = npcb; - crit_enter(); + lwkt_serialize_enter(ifp->if_serializer); if (ifp->if_ioctl == NULL || ifp->if_ioctl(ifp, SIOCATMENA, (caddr_t) &api, td->td_proc->p_ucred) != 0) { - crit_exit(); + lwkt_serialize_exit(ifp->if_serializer); npcb_free(npcb, NPCB_REMOVE); error = EIO; goto out; } - crit_exit(); + lwkt_serialize_exit(ifp->if_serializer); soisconnected(so); @@ -261,10 +261,11 @@ natm_usr_disconnect(struct socket *so) ATM_PH_VPI(&api.aph) = npcb->npcb_vpi; ATM_PH_SETVCI(&api.aph, npcb->npcb_vci); api.rxhand = npcb; - crit_enter(); - if (ifp->if_ioctl != NULL) + if (ifp->if_ioctl != NULL) { + lwkt_serialize_enter(ifp->if_serializer); ifp->if_ioctl(ifp, SIOCATMDIS, (caddr_t) &api, (struct ucred *)NULL); - crit_exit(); + lwkt_serialize_exit(ifp->if_serializer); + } npcb_free(npcb, NPCB_REMOVE); soisdisconnected(so); @@ -363,8 +364,6 @@ natm_usr_control(struct socket *so, u_long cmd, caddr_t arg, struct atm_rawioctl ario; int error = 0; - crit_enter(); - npcb = (struct natmpcb *) so->so_pcb; if (npcb == NULL) { error = EINVAL; @@ -382,9 +381,11 @@ natm_usr_control(struct socket *so, u_long cmd, caddr_t arg, } ario.npcb = npcb; ario.rawvalue = *((int *)arg); + lwkt_serialize_enter(ifp->if_serializer); error = npcb->npcb_ifp->if_ioctl(npcb->npcb_ifp, SIOCXRAWATM, (caddr_t) &ario, td->td_proc->p_ucred); + lwkt_serialize_exit(ifp->if_serializer); if (!error) { if (ario.rawvalue) npcb->npcb_flags |= NPCB_RAW; @@ -394,9 +395,7 @@ natm_usr_control(struct socket *so, u_long cmd, caddr_t arg, } else error = EOPNOTSUPP; - out: - crit_exit(); return (error); } @@ -553,16 +552,16 @@ struct proc *p; ATM_PH_VPI(&api.aph) = npcb->npcb_vpi; ATM_PH_SETVCI(&api.aph, npcb->npcb_vci); api.rxhand = npcb; - crit_enter(); + lwkt_serialize_enter(ifp->if_serializer); if (ifp->if_ioctl == NULL || ifp->if_ioctl(ifp, SIOCATMENA, (caddr_t) &api, (struct ucred *)NULL) != 0) { - crit_exit(); + lwkt_serialize_exit(ifp->if_serializer); npcb_free(npcb, NPCB_REMOVE); error = EIO; break; } - crit_exit(); + lwkt_serialize_exit(ifp->if_serializer); soisconnected(so); @@ -585,10 +584,10 @@ struct proc *p; ATM_PH_VPI(&api.aph) = npcb->npcb_vpi; ATM_PH_SETVCI(&api.aph, npcb->npcb_vci); api.rxhand = npcb; - crit_enter(); + lwkt_serialize_enter(ifp->if_serializer); if (ifp->if_ioctl != NULL) ifp->if_ioctl(ifp, SIOCATMDIS, (caddr_t) &api, (struct ucred *)NULL); - crit_exit(); + lwkt_serialize_exit(ifp->if_serializer); npcb_free(npcb, NPCB_REMOVE); soisdisconnected(so); @@ -656,8 +655,10 @@ struct proc *p; } ario.npcb = npcb; ario.rawvalue = *((int *)nam); + lwkt_serialize_enter(npcb->npcb_ifp->if_serializer); error = npcb->npcb_ifp->if_ioctl(npcb->npcb_ifp, SIOCXRAWATM, (caddr_t) &ario, (struct ucred *)NULL); + lwkt_serialize_exit(npcb->npcb_ifp->if_serializer); if (!error) { if (ario.rawvalue) npcb->npcb_flags |= NPCB_RAW; diff --git a/sys/netproto/ns/ns.c b/sys/netproto/ns/ns.c index d3f076f628..f415b9872c 100644 --- a/sys/netproto/ns/ns.c +++ b/sys/netproto/ns/ns.c @@ -32,7 +32,7 @@ * * @(#)ns.c 8.2 (Berkeley) 11/15/93 * $FreeBSD: src/sys/netns/ns.c,v 1.9 1999/08/28 00:49:47 peter Exp $ - * $DragonFly: src/sys/netproto/ns/ns.c,v 1.10 2005/06/10 22:44:01 dillon Exp $ + * $DragonFly: src/sys/netproto/ns/ns.c,v 1.11 2005/11/28 17:13:47 dillon Exp $ */ #include @@ -174,9 +174,11 @@ ns_control(struct socket *so, u_long cmd, caddr_t data, struct ifnet *ifp, ia->ia_flags &= ~IFA_ROUTE; } if (ifp->if_ioctl) { - error = (*ifp->if_ioctl)(ifp, SIOCSIFDSTADDR, + lwkt_serialize_enter(ifp->if_serializer); + error = ifp->if_ioctl(ifp, SIOCSIFDSTADDR, (caddr_t)ia, (struct ucred *)NULL); + lwkt_serialize_exit(ifp->if_serializer); if (error) return (error); } @@ -238,7 +240,10 @@ ns_control(struct socket *so, u_long cmd, caddr_t data, struct ifnet *ifp, default: if (ifp->if_ioctl == 0) return (EOPNOTSUPP); - return ((*ifp->if_ioctl)(ifp, cmd, data, (struct ucred *)NULL)); + lwkt_serialize_enter(ifp->if_serializer); + error = ifp->if_ioctl(ifp, cmd, data, (struct ucred *)NULL); + lwkt_serialize_exit(ifp->if_serializer); + return (error); } } @@ -293,26 +298,32 @@ ns_ifinit(ifp, ia, sns, scrub) * and to validate the address if necessary. */ if (ns_hosteqnh(ns_thishost, ns_zerohost)) { + lwkt_serialize_enter(ifp->if_serializer); if (ifp->if_ioctl && - (error = (*ifp->if_ioctl)(ifp, SIOCSIFADDR, + (error = ifp->if_ioctl(ifp, SIOCSIFADDR, (caddr_t)ia, (struct ucred *)NULL))) { ia->ia_addr = oldaddr; + lwkt_serialize_exit(ifp->if_serializer); crit_exit(); return (error); } + lwkt_serialize_exit(ifp->if_serializer); ns_thishost = *h; } else if (ns_hosteqnh(sns->sns_addr.x_host, ns_zerohost) || ns_hosteqnh(sns->sns_addr.x_host, ns_thishost)) { *h = ns_thishost; + lwkt_serialize_enter(ifp->if_serializer); if (ifp->if_ioctl && - (error = (*ifp->if_ioctl)(ifp, SIOCSIFADDR, + (error = ifp->if_ioctl(ifp, SIOCSIFADDR, (caddr_t)ia, (struct ucred *)NULL))) { ia->ia_addr = oldaddr; + lwkt_serialize_exit(ifp->if_serializer); crit_exit(); return (error); } + lwkt_serialize_exit(ifp->if_serializer); if (!ns_hosteqnh(ns_thishost,*h)) { ia->ia_addr = oldaddr; crit_exit(); diff --git a/sys/netproto/ns/ns_ip.c b/sys/netproto/ns/ns_ip.c index 881ae990a4..b3be50bf10 100644 --- a/sys/netproto/ns/ns_ip.c +++ b/sys/netproto/ns/ns_ip.c @@ -32,7 +32,7 @@ * * @(#)ns_ip.c 8.1 (Berkeley) 6/10/93 * $FreeBSD: src/sys/netns/ns_ip.c,v 1.9 1999/08/28 00:49:50 peter Exp $ - * $DragonFly: src/sys/netproto/ns/ns_ip.c,v 1.12 2005/06/09 02:03:39 hsu Exp $ + * $DragonFly: src/sys/netproto/ns/ns_ip.c,v 1.13 2005/11/28 17:13:47 dillon Exp $ */ /* @@ -111,7 +111,7 @@ nsipattach() ifp->if_output = nsipoutput; ifp->if_start = nsipstart; ifp->if_flags = IFF_POINTOPOINT; - if_attach(ifp); + if_attach(ifp, NULL); return (m); } diff --git a/sys/netproto/ns/ns_output.c b/sys/netproto/ns/ns_output.c index 677c9f1a1c..43eef9fcf3 100644 --- a/sys/netproto/ns/ns_output.c +++ b/sys/netproto/ns/ns_output.c @@ -32,7 +32,7 @@ * * @(#)ns_output.c 8.1 (Berkeley) 6/10/93 * $FreeBSD: src/sys/netns/ns_output.c,v 1.7 1999/08/28 00:49:51 peter Exp $ - * $DragonFly: src/sys/netproto/ns/ns_output.c,v 1.6 2004/07/27 13:50:15 hmp Exp $ + * $DragonFly: src/sys/netproto/ns/ns_output.c,v 1.7 2005/11/28 17:13:47 dillon Exp $ */ #include @@ -139,8 +139,10 @@ gotif: if (ns_copy_output) { ns_watch_output(m0, ifp); } + lwkt_serialize_enter(ifp->if_serializer); error = (*ifp->if_output)(ifp, m0, (struct sockaddr *)dst, ro->ro_rt); + lwkt_serialize_exit(ifp->if_serializer); goto done; } else error = EMSGSIZE; diff --git a/sys/sys/bus.h b/sys/sys/bus.h index 73d297b86c..b6cbe289ad 100644 --- a/sys/sys/bus.h +++ b/sys/sys/bus.h @@ -24,7 +24,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/sys/bus.h,v 1.30.2.5 2004/03/17 17:54:25 njl Exp $ - * $DragonFly: src/sys/sys/bus.h,v 1.18 2005/10/30 04:41:15 dillon Exp $ + * $DragonFly: src/sys/sys/bus.h,v 1.19 2005/11/28 17:13:47 dillon Exp $ */ #ifndef _SYS_BUS_H_ @@ -56,6 +56,8 @@ typedef void driver_intr_t(void*); #define INTR_ENTROPY 0x0400 #define INTR_NOPOLL 0x0800 /* interrupt cannot be polled (e.g. ata) */ +#define INTR_NETSAFE INTR_MPSAFE + enum intr_trigger { INTR_TRIGGER_CONFORM = 0, INTR_TRIGGER_EDGE = 1, -- 2.41.0