From: patrick Date: Wed, 7 Feb 2018 22:01:04 +0000 (+0000) Subject: Move parsing the BCDC header on RX into a protocol specific RX X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=7dfc0b73007432a9ddd33160aac0526c0f25b6d7;p=openbsd Move parsing the BCDC header on RX into a protocol specific RX function so it can be shared with the SDIO attachment driver. --- diff --git a/sys/dev/ic/bwfm.c b/sys/dev/ic/bwfm.c index 8a52b3aa90d..eaf1aece02e 100644 --- a/sys/dev/ic/bwfm.c +++ b/sys/dev/ic/bwfm.c @@ -1,4 +1,4 @@ -/* $OpenBSD: bwfm.c,v 1.37 2018/02/07 21:36:34 patrick Exp $ */ +/* $OpenBSD: bwfm.c,v 1.38 2018/02/07 22:01:04 patrick Exp $ */ /* * Copyright (c) 2010-2016 Broadcom Corporation * Copyright (c) 2016,2017 Patrick Wildt @@ -89,6 +89,7 @@ int bwfm_proto_bcdc_query_dcmd(struct bwfm_softc *, int, int, char *, size_t *); int bwfm_proto_bcdc_set_dcmd(struct bwfm_softc *, int, int, char *, size_t); +void bwfm_proto_bcdc_rx(struct bwfm_softc *, struct mbuf *); int bwfm_fwvar_cmd_get_data(struct bwfm_softc *, int, void *, size_t); int bwfm_fwvar_cmd_set_data(struct bwfm_softc *, int, void *, size_t); @@ -153,6 +154,7 @@ uint8_t bwfm_5ghz_channels[] = { struct bwfm_proto_ops bwfm_proto_bcdc_ops = { .proto_query_dcmd = bwfm_proto_bcdc_query_dcmd, .proto_set_dcmd = bwfm_proto_bcdc_set_dcmd, + .proto_rx = bwfm_proto_bcdc_rx, }; struct cfdriver bwfm_cd = { @@ -1331,6 +1333,24 @@ err: return ret; } +void +bwfm_proto_bcdc_rx(struct bwfm_softc *sc, struct mbuf *m) +{ + struct bwfm_proto_bcdc_hdr *hdr; + + hdr = mtod(m, struct bwfm_proto_bcdc_hdr *); + if (m->m_len < sizeof(*hdr)) { + m_freem(m); + return; + } + if (m->m_len < sizeof(*hdr) + (hdr->data_offset << 2)) { + m_freem(m); + return; + } + m_adj(m, sizeof(*hdr) + (hdr->data_offset << 2)); + bwfm_rx(sc, m); +} + /* FW Variable code */ int bwfm_fwvar_cmd_get_data(struct bwfm_softc *sc, int cmd, void *data, size_t len) diff --git a/sys/dev/ic/bwfmvar.h b/sys/dev/ic/bwfmvar.h index 6ac4bd24a54..cd74e40b720 100644 --- a/sys/dev/ic/bwfmvar.h +++ b/sys/dev/ic/bwfmvar.h @@ -1,4 +1,4 @@ -/* $OpenBSD: bwfmvar.h,v 1.10 2018/02/07 21:36:34 patrick Exp $ */ +/* $OpenBSD: bwfmvar.h,v 1.11 2018/02/07 22:01:04 patrick Exp $ */ /* * Copyright (c) 2010-2016 Broadcom Corporation * Copyright (c) 2016,2017 Patrick Wildt @@ -106,6 +106,7 @@ struct bwfm_proto_ops { char *, size_t *); int (*proto_set_dcmd)(struct bwfm_softc *, int, int, char *, size_t); + void (*proto_rx)(struct bwfm_softc *, struct mbuf *); }; extern struct bwfm_proto_ops bwfm_proto_bcdc_ops; diff --git a/sys/dev/usb/if_bwfm_usb.c b/sys/dev/usb/if_bwfm_usb.c index e2986e6a2df..e4e3061151b 100644 --- a/sys/dev/usb/if_bwfm_usb.c +++ b/sys/dev/usb/if_bwfm_usb.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if_bwfm_usb.c,v 1.8 2018/01/24 13:10:20 patrick Exp $ */ +/* $OpenBSD: if_bwfm_usb.c,v 1.9 2018/02/07 22:01:04 patrick Exp $ */ /* * Copyright (c) 2010-2016 Broadcom Corporation * Copyright (c) 2016,2017 Patrick Wildt @@ -430,10 +430,9 @@ bwfm_usb_rxeof(struct usbd_xfer *xfer, void *priv, usbd_status status) { struct bwfm_usb_rx_data *data = priv; struct bwfm_usb_softc *sc = data->sc; - struct bwfm_proto_bcdc_hdr *hdr; usbd_status error; - uint32_t len, off; struct mbuf *m; + uint32_t len; DPRINTFN(2, ("%s: %s status %s\n", DEVNAME(sc), __func__, usbd_errstr(status))); @@ -449,23 +448,13 @@ bwfm_usb_rxeof(struct usbd_xfer *xfer, void *priv, usbd_status status) } usbd_get_xfer_status(xfer, NULL, NULL, &len, NULL); - hdr = (void *)data->buf; - if (len < sizeof(*hdr)) - goto resubmit; - len -= sizeof(*hdr); - off += sizeof(*hdr); - if (len < hdr->data_offset << 2) - goto resubmit; - len -= hdr->data_offset << 2; - off += hdr->data_offset << 2; - m = bwfm_usb_newbuf(); if (m == NULL) goto resubmit; - memcpy(mtod(m, char *), data->buf + off, len); + memcpy(mtod(m, char *), data->buf, len); m->m_len = m->m_pkthdr.len = len; - bwfm_rx(&sc->sc_sc, m); + sc->sc_sc.sc_proto_ops->proto_rx(&sc->sc_sc, m); resubmit: usbd_setup_xfer(data->xfer, sc->sc_rx_pipeh, data, data->buf,