From 162487b9db8bb8d64d9d950c63903f86568cb43b Mon Sep 17 00:00:00 2001 From: Ryan Thomas McBride Date: Tue, 1 Mar 2005 18:37:08 +0000 Subject: - make large packets work without hanging the interface - make tcpdump attach correctly by Alex Feldman prodded via Greg Mortensen ok deraadt@ --- sys/dev/pci/if_san_common.c | 80 +++++++++++++++++++++++++++++++------------- sys/dev/pci/if_san_common.h | 13 ++++++-- sys/dev/pci/if_san_obsd.c | 81 +++++++++++++++++++++++++++++---------------- sys/dev/pci/if_san_te1.c | 2 +- sys/dev/pci/if_san_xilinx.c | 12 ++++--- sys/dev/pci/if_sandrv.c | 6 ++-- 6 files changed, 132 insertions(+), 62 deletions(-) (limited to 'sys/dev') diff --git a/sys/dev/pci/if_san_common.c b/sys/dev/pci/if_san_common.c index bb4ee869f59..b02e06ad100 100644 --- a/sys/dev/pci/if_san_common.c +++ b/sys/dev/pci/if_san_common.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if_san_common.c,v 1.5 2004/12/07 08:44:38 jsg Exp $ */ +/* $OpenBSD: if_san_common.c,v 1.6 2005/03/01 18:37:06 mcbride Exp $ */ /*- * Copyright (c) 2001-2004 Sangoma Technologies (SAN) @@ -263,17 +263,8 @@ wan_ioctl(struct ifnet *ifp, int cmd, struct ifreq *ifr) wanpipe_common_t *common = WAN_IFP_TO_COMMON(ifp); int err = 0; - if (common == NULL) { - log(LOG_INFO, "%s: Invalid softc pointer (%s:%d)!\n", - ifp->if_xname, __FUNCTION__, __LINE__); - return (-EINVAL); - } - card = common->card; - if (card == NULL) { - log(LOG_INFO, "%s: Card private structure corrupted (%s:%d)!\n", - ifp->if_xname, __FUNCTION__, __LINE__); - return (-EINVAL); - } + SAN_ASSERT(common == NULL); + SAN_ASSERT(common->card == NULL); switch (cmd) { case SIOC_WANPIPE_HWPROBE: err = wan_ioctl_hwprobe(ifp, ifr->ifr_data); @@ -293,14 +284,21 @@ wan_ioctl(struct ifnet *ifp, int cmd, struct ifreq *ifr) static int wan_ioctl_hwprobe(struct ifnet *ifp, void *u_def) { - sdla_t *card = NULL; - wanlite_def_t def; - unsigned char *str; - int err; + sdla_t *card = NULL; + wanpipe_common_t *common = WAN_IFP_TO_COMMON(ifp); + wanlite_def_t def; + unsigned char *str; + int err; - card = ((wanpipe_common_t*)ifp->if_softc)->card; + SAN_ASSERT(common == NULL); + SAN_ASSERT(common->card == NULL); + card = common->card; memset(&def, 0, sizeof(wanlite_def_t)); - sdla_get_hwprobe(card->hw, (void**)&str); + /* Get protocol type */ + def.proto = common->protocol; + + /* Get hardware configuration */ + err = sdla_get_hwprobe(card->hw, (void**)&str); if (err) { return -EINVAL; } @@ -385,18 +383,54 @@ sdla_isr(void *pcard) return (1); } -struct mbuf * -wan_mbuf_alloc(void) +struct mbuf* +wan_mbuf_alloc(int len) { struct mbuf *m; - MGETHDR(m, M_DONTWAIT, MT_DATA); + if (len) { + MGETHDR(m, M_DONTWAIT, MT_DATA); + } else { + MGET(m, M_DONTWAIT, MT_DATA); + } if (m != NULL) { + if (m->m_flags & M_PKTHDR) { + m->m_pkthdr.len = 0; + } + m->m_len = 0; MCLGET(m, M_DONTWAIT); if ((m->m_flags & M_EXT) == 0) { m_freem(m); - m = NULL; + return NULL; } + m->m_data += 16; + return (m); } - return (m); + return NULL; } + +int +wan_mbuf_to_buffer(struct mbuf **m_org) +{ + struct mbuf *m = *m_org, *new = NULL; + + if (m == NULL){ + return -EINVAL; + } + new = wan_mbuf_alloc(0); + if (new){ + struct mbuf *tmp = m; + char *buffer = new->m_data; + + for( ; tmp; tmp = tmp->m_next) { + bcopy(mtod(tmp, caddr_t), buffer, tmp->m_len); + buffer += tmp->m_len; + new->m_len += tmp->m_len; + } + m_freem(m); + *m_org = new; + return 0; + } + return -EINVAL; +} + diff --git a/sys/dev/pci/if_san_common.h b/sys/dev/pci/if_san_common.h index 6ec6f6c9c1d..e40c6158f44 100644 --- a/sys/dev/pci/if_san_common.h +++ b/sys/dev/pci/if_san_common.h @@ -1,4 +1,4 @@ -/* $OpenBSD: if_san_common.h,v 1.5 2004/12/07 06:10:24 mcbride Exp $ */ +/* $OpenBSD: if_san_common.h,v 1.6 2005/03/01 18:37:06 mcbride Exp $ */ /*- * Copyright (c) 2001-2004 Sangoma Technologies (SAN) @@ -299,6 +299,14 @@ typedef struct wan_udp_hdr{ /* clear bit N of bitstring name */ #define bit_clear(name, bit) ((name)[_bit_byte(bit)] &= ~_bit_mask(bit)) +/* Sangoma assert macro */ +#define SAN_ASSERT(a) \ + if (a){ \ + log(LOG_INFO, "%s:%d: Critical Error!\n", \ + __FUNCTION__,__LINE__); \ + return (-EINVAL); \ + } + /****** Data Structures *****************************************************/ typedef struct wan_udp_pkt { @@ -410,7 +418,8 @@ typedef struct sdla { /****** Public Functions ****************************************************/ void* wan_xilinx_init(sdla_t*); /* Xilinx Hardware Support */ -struct mbuf* wan_mbuf_alloc(void); +struct mbuf* wan_mbuf_alloc(int); +int wan_mbuf_to_buffer(struct mbuf**); #endif /* __KERNEL__ */ #endif /* __IF_SAN_COMMON_H */ diff --git a/sys/dev/pci/if_san_obsd.c b/sys/dev/pci/if_san_obsd.c index 2355b69f62a..4e679f6b0fd 100644 --- a/sys/dev/pci/if_san_obsd.c +++ b/sys/dev/pci/if_san_obsd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if_san_obsd.c,v 1.6 2004/12/07 06:10:24 mcbride Exp $ */ +/* $OpenBSD: if_san_obsd.c,v 1.7 2005/03/01 18:37:07 mcbride Exp $ */ /*- * Copyright (c) 2001-2004 Sangoma Technologies (SAN) @@ -32,32 +32,36 @@ * THE POSSIBILITY OF SUCH DAMAGE. */ -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include - -# include -# include -# include -# include -# include -# include - -# include -# include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "bpfilter.h" +#if NBPFILTER > 0 +# include +#endif +#include +#include +#include +#include +#include +#include + +#include +#include #include #include @@ -129,7 +133,6 @@ wanpipe_generic_register(sdla_t *card, struct ifnet *ifp, char *ifname) common->protocol = IF_PROTO_CISCO; ((struct sppp *)ifp)->pp_flags |= PP_CISCO; ((struct sppp *)ifp)->pp_flags |= PP_KEEPALIVE; - ((struct sppp *)ifp)->pp_framebytes = 3; ifp->if_ioctl = wanpipe_generic_ioctl; /* Will set from new_if() */ ifp->if_start = wanpipe_generic_start; ifp->if_watchdog = wanpipe_generic_watchdog; @@ -160,8 +163,10 @@ wanpipe_generic_start(struct ifnet *ifp) struct mbuf *opkt; int err = 0; #if NBPFILTER > 0 +#if 0 struct mbuf m0; u_int32_t af = AF_INET; +#endif #endif /* NBPFILTER > 0 */ if ((card = wanpipe_generic_getcard(ifp)) == NULL) { @@ -184,13 +189,21 @@ wanpipe_generic_start(struct ifnet *ifp) /* report the packet to BPF if present and attached */ #if NBPFILTER > 0 if (ifp->if_bpf) { +#if 0 m0.m_next = opkt; m0.m_len = 4; m0.m_data = (char*)⁡ bpf_mtap(ifp->if_bpf, &m0); +#endif + bpf_mtap(ifp->if_bpf, opkt); } #endif /* NBPFILTER > 0 */ + if (wan_mbuf_to_buffer(&opkt)){ + m_freem(opkt); + break; + } + err = card->iface_send(opkt, ifp); if (err) { break; @@ -264,6 +277,9 @@ wanpipe_generic_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data) /* bring it down */ log(LOG_INFO, "%s: Bringing interface down.\n", ifp->if_xname); + if (!(((struct sppp *)ifp)->pp_flags & PP_CISCO)){ + ((struct sppp*)ifp)->pp_down((struct sppp*)ifp); + } if (card->iface_down) { card->iface_down(ifp); } @@ -273,8 +289,12 @@ wanpipe_generic_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data) if (card->iface_up) { card->iface_up(ifp); } + if (!(((struct sppp *)ifp)->pp_flags & PP_CISCO)){ + ((struct sppp*)ifp)->pp_up((struct sppp*)ifp); + } wanpipe_generic_start(ifp); } + err = 1; break; case SIOC_WANPIPE_DEVICE: @@ -354,8 +374,10 @@ wanpipe_generic_input(struct ifnet *ifp, struct mbuf *m) { sdla_t *card; #if NBPFILTER > 0 +#if 0 struct mbuf m0; u_int32_t af = AF_INET; +#endif #endif /* NBPFILTER > 0 */ if ((card = wanpipe_generic_getcard(ifp)) == NULL) { @@ -364,10 +386,13 @@ wanpipe_generic_input(struct ifnet *ifp, struct mbuf *m) m->m_pkthdr.rcvif = ifp; #if NBPFILTER > 0 if (ifp->if_bpf) { +#if 0 m0.m_next = m; m0.m_len = 4; m0.m_data = (char*)⁡ bpf_mtap(ifp->if_bpf, &m0); +#endif + bpf_mtap(ifp->if_bpf, m); } #endif /* NBPFILTER > 0 */ ifp->if_ipackets ++; diff --git a/sys/dev/pci/if_san_te1.c b/sys/dev/pci/if_san_te1.c index 5763f2f304f..8cc76449369 100644 --- a/sys/dev/pci/if_san_te1.c +++ b/sys/dev/pci/if_san_te1.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if_san_te1.c,v 1.6 2005/01/18 21:47:23 claudio Exp $ */ +/* $OpenBSD: if_san_te1.c,v 1.7 2005/03/01 18:37:07 mcbride Exp $ */ /*- * Copyright (c) 2001-2004 Sangoma Technologies (SAN) diff --git a/sys/dev/pci/if_san_xilinx.c b/sys/dev/pci/if_san_xilinx.c index b85b6326850..62896559742 100644 --- a/sys/dev/pci/if_san_xilinx.c +++ b/sys/dev/pci/if_san_xilinx.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if_san_xilinx.c,v 1.6 2004/12/07 06:10:24 mcbride Exp $ */ +/* $OpenBSD: if_san_xilinx.c,v 1.7 2005/03/01 18:37:07 mcbride Exp $ */ /*- * Copyright (c) 2001-2004 Sangoma Technologies (SAN) @@ -684,7 +684,7 @@ wan_xilinx_ioctl(struct ifnet *ifp, int cmd, struct ifreq *ifr) return (-EBUSY); } - m = wan_mbuf_alloc(); + m = wan_mbuf_alloc(sizeof(wan_udp_pkt_t)); if (m == NULL) { return (-ENOMEM); } @@ -1767,8 +1767,10 @@ xilinx_dma_tx(sdla_t *card, xilinx_softc_t *sc) #endif if (bit_test((u_int8_t *)&sc->dma_status, TX_BUSY)) { +#ifdef DEBUG_TX log(LOG_INFO, "%s: TX_BUSY set (%s:%d)!\n", sc->if_name, __FUNCTION__, __LINE__); +#endif return -EBUSY; } bit_set((u_int8_t *)&sc->dma_status, TX_BUSY); @@ -2315,9 +2317,9 @@ xilinx_rx_post_complete(sdla_t *card, xilinx_softc_t *sc, memset(&skb->cb[0], 0, sizeof(wp_rx_element_t)); #endif memset(mtod(m, caddr_t), 0, sizeof(wp_rx_element_t)); - m_adj(m, sizeof(wp_rx_element_t)); m->m_len += len; m->m_pkthdr.len = m->m_len; + m_adj(m, sizeof(wp_rx_element_t)); *new_m = m; aft_alloc_rx_dma_buff(card, sc, 1); @@ -2326,7 +2328,7 @@ xilinx_rx_post_complete(sdla_t *card, xilinx_softc_t *sc, /* The rx packet is very * small thus, allocate a new * buffer and pass it up */ - m0 = wan_mbuf_alloc(); + m0 = wan_mbuf_alloc(len); if (m0 == NULL) { log(LOG_INFO, "%s: Failed to allocate mbuf!\n", sc->if_name); @@ -2471,7 +2473,7 @@ aft_alloc_rx_dma_buff(sdla_t *card, xilinx_softc_t *sc, int num) struct mbuf *m; for (i = 0; i < num; i++) { - m = wan_mbuf_alloc(); + m = wan_mbuf_alloc(sc->dma_mtu); if (m == NULL) { log(LOG_INFO, "%s: %s no memory\n", sc->if_name, __FUNCTION__); diff --git a/sys/dev/pci/if_sandrv.c b/sys/dev/pci/if_sandrv.c index 3b03c3c0f44..6726177a191 100644 --- a/sys/dev/pci/if_sandrv.c +++ b/sys/dev/pci/if_sandrv.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if_sandrv.c,v 1.7 2005/02/13 03:37:14 jsg Exp $ */ +/* $OpenBSD: if_sandrv.c,v 1.8 2005/03/01 18:37:07 mcbride Exp $ */ /*- * Copyright (c) 2001-2004 Sangoma Technologies (SAN) @@ -186,8 +186,8 @@ static sdlahw_t* sdla_aft_hw_select (sdlahw_card_t *, int, int, static void sdla_save_hw_probe (sdlahw_t*, int); /* SDLA PCI device relative entry point */ -int san_match(struct device *, void *, void *); -void san_attach(struct device *, struct device *, void *); +int san_match __P((struct device *, void *, void *)); +void san_attach __P((struct device *, struct device *, void *)); struct cfdriver san_cd = { -- cgit v1.2.3