rtwn: add Rx descriptor structures for common code.

Remove any chipset specific usage of Rx descriptor structure / bits
from common code to prevent misuse of fields that may differ
between various chipsets.

Checked with: 	RTL8821AU in STA mode.
This commit is contained in:
Andriy Voskoboinyk 2017-07-06 07:37:33 +00:00
parent faef91fab6
commit c5ad99fc69
7 changed files with 88 additions and 48 deletions

View File

@ -53,7 +53,6 @@ __FBSDID("$FreeBSD$");
#include <dev/rtwn/if_rtwn_rx.h>
#include <dev/rtwn/rtl8192c/r92c_reg.h>
#include <dev/rtwn/rtl8192c/r92c_rx_desc.h>
void
@ -190,7 +189,8 @@ rtwn_get_tsf(struct rtwn_softc *sc, uint64_t *buf, int id)
}
static uint64_t
rtwn_extend_rx_tsf(struct rtwn_softc *sc, const struct r92c_rx_stat *stat)
rtwn_extend_rx_tsf(struct rtwn_softc *sc,
const struct rtwn_rx_stat_common *stat)
{
uint64_t tsft;
uint32_t rxdw3, tsfl, tsfl_curr;
@ -198,7 +198,7 @@ rtwn_extend_rx_tsf(struct rtwn_softc *sc, const struct r92c_rx_stat *stat)
rxdw3 = le32toh(stat->rxdw3);
tsfl = le32toh(stat->tsf_low);
id = MS(rxdw3, R92C_RXDW3_BSSID_FIT);
id = MS(rxdw3, RTWN_RXDW3_BSSID01_FIT);
switch (id) {
case 1:
@ -241,7 +241,7 @@ rtwn_rx_common(struct rtwn_softc *sc, struct mbuf *m, void *desc)
struct ieee80211_frame_min *wh;
struct ieee80211_rx_stats rxs;
struct rtwn_node *un;
struct r92c_rx_stat *stat;
struct rtwn_rx_stat_common *stat;
void *physt;
uint32_t rxdw0;
int8_t rssi;
@ -250,10 +250,10 @@ rtwn_rx_common(struct rtwn_softc *sc, struct mbuf *m, void *desc)
stat = desc;
rxdw0 = le32toh(stat->rxdw0);
cipher = MS(rxdw0, R92C_RXDW0_CIPHER);
infosz = MS(rxdw0, R92C_RXDW0_INFOSZ) * 8;
pktlen = MS(rxdw0, R92C_RXDW0_PKTLEN);
shift = MS(rxdw0, R92C_RXDW0_SHIFT);
cipher = MS(rxdw0, RTWN_RXDW0_CIPHER);
infosz = MS(rxdw0, RTWN_RXDW0_INFOSZ) * 8;
pktlen = MS(rxdw0, RTWN_RXDW0_PKTLEN);
shift = MS(rxdw0, RTWN_RXDW0_SHIFT);
wh = (struct ieee80211_frame_min *)(mtodo(m, shift + infosz));
if ((wh->i_fc[1] & IEEE80211_FC1_PROTECTED) &&
@ -268,7 +268,7 @@ rtwn_rx_common(struct rtwn_softc *sc, struct mbuf *m, void *desc)
ni = NULL;
un = RTWN_NODE(ni);
if (infosz != 0 && (rxdw0 & R92C_RXDW0_PHYST))
if (infosz != 0 && (rxdw0 & RTWN_RXDW0_PHYST))
physt = (void *)mtodo(m, shift);
else
physt = (un != NULL) ? &un->last_physt : &sc->last_physt;
@ -284,7 +284,7 @@ rtwn_rx_common(struct rtwn_softc *sc, struct mbuf *m, void *desc)
/* Add some common bits. */
/* NB: should not happen. */
if (rxdw0 & R92C_RXDW0_CRCERR)
if (rxdw0 & RTWN_RXDW0_CRCERR)
rxs.c_pktflags |= IEEE80211_RX_F_FAIL_FCSCRC;
rxs.r_flags |= IEEE80211_R_TSF_START; /* XXX undocumented */
@ -298,7 +298,7 @@ rtwn_rx_common(struct rtwn_softc *sc, struct mbuf *m, void *desc)
/* XXX TODO: we really need a rate-to-string method */
RTWN_DPRINTF(sc, RTWN_DEBUG_RSSI, "%s: rssi %d, rate %d\n",
__func__, rssi, rxs.c_rate);
if (un != NULL && infosz != 0 && (rxdw0 & R92C_RXDW0_PHYST)) {
if (un != NULL && infosz != 0 && (rxdw0 & RTWN_RXDW0_PHYST)) {
/* Update our average RSSI. */
rtwn_update_avgrssi(sc, un, rssi, is_cck);
}

View File

@ -48,6 +48,55 @@ struct rtwn_tx_desc_common {
} txdw7;
} __packed __attribute__((aligned(4)));
/* Common part of Rx descriptor. */
struct rtwn_rx_stat_common {
uint32_t rxdw0;
#define RTWN_RXDW0_PKTLEN_M 0x00003fff
#define RTWN_RXDW0_PKTLEN_S 0
#define RTWN_RXDW0_CRCERR 0x00004000
#define RTWN_RXDW0_ICVERR 0x00008000
#define RTWN_RXDW0_INFOSZ_M 0x000f0000
#define RTWN_RXDW0_INFOSZ_S 16
#define RTWN_RXDW0_CIPHER_M 0x00700000
#define RTWN_RXDW0_CIPHER_S 20
#define RTWN_RXDW0_QOS 0x00800000
#define RTWN_RXDW0_SHIFT_M 0x03000000
#define RTWN_RXDW0_SHIFT_S 24
#define RTWN_RXDW0_PHYST 0x04000000
#define RTWN_RXDW0_SWDEC 0x08000000
#define RTWN_RXDW0_LS 0x10000000
#define RTWN_RXDW0_FS 0x20000000
#define RTWN_RXDW0_EOR 0x40000000
#define RTWN_RXDW0_OWN 0x80000000
uint32_t rxdw1;
#define RTWN_RXDW1_AMSDU 0x00002000
#define RTWN_RXDW1_MC 0x40000000
#define RTWN_RXDW1_BC 0x80000000
uint32_t rxdw2;
uint32_t rxdw3;
#define RTWN_RXDW3_HTC 0x00000400
#define RTWN_RXDW3_BSSID01_FIT_M 0x00003000
#define RTWN_RXDW3_BSSID01_FIT_S 12
uint32_t rxdw4;
uint32_t tsf_low;
} __packed __attribute__((aligned(4)));
/* Rx descriptor for PCIe devices. */
struct rtwn_rx_stat_pci {
uint32_t rxdw0;
uint32_t rxdw1;
uint32_t rxdw2;
uint32_t rxdw3;
uint32_t rxdw4;
uint32_t tsf_low;
uint32_t rxbufaddr;
uint32_t rxbufaddr64;
} __packed __attribute__((aligned(4)));
/*
* Macros to access subfields in registers.
*/

View File

@ -62,7 +62,6 @@ __FBSDID("$FreeBSD$");
#include <dev/rtwn/pci/rtwn_pci_tx.h>
#include <dev/rtwn/rtl8192c/pci/r92ce_reg.h>
#include <dev/rtwn/rtl8192c/pci/r92ce_rx_desc.h>
static device_probe_t rtwn_pci_probe;
@ -133,7 +132,7 @@ rtwn_pci_alloc_rx_list(struct rtwn_softc *sc)
int i, error;
/* Allocate Rx descriptors. */
size = sizeof(struct r92ce_rx_stat) * RTWN_PCI_RX_LIST_COUNT;
size = sizeof(struct rtwn_rx_stat_pci) * RTWN_PCI_RX_LIST_COUNT;
error = bus_dma_tag_create(bus_get_dma_tag(sc->sc_dev), 1, 0,
BUS_SPACE_MAXADDR_32BIT, BUS_SPACE_MAXADDR, NULL, NULL,
size, 1, size, 0, NULL, NULL, &rx_ring->desc_dmat);

View File

@ -56,8 +56,6 @@ __FBSDID("$FreeBSD$");
#include <dev/rtwn/pci/rtwn_pci_var.h>
#include <dev/rtwn/pci/rtwn_pci_rx.h>
#include <dev/rtwn/rtl8192c/pci/r92ce_rx_desc.h>
void
rtwn_pci_dma_map_addr(void *arg, bus_dma_segment_t *segs, int nsegs,
@ -71,21 +69,21 @@ rtwn_pci_dma_map_addr(void *arg, bus_dma_segment_t *segs, int nsegs,
}
void
rtwn_pci_setup_rx_desc(struct rtwn_pci_softc *pc, struct r92ce_rx_stat *desc,
bus_addr_t addr, size_t len, int idx)
rtwn_pci_setup_rx_desc(struct rtwn_pci_softc *pc,
struct rtwn_rx_stat_pci *desc, bus_addr_t addr, size_t len, int idx)
{
memset(desc, 0, sizeof(*desc));
desc->rxdw0 = htole32(SM(R92C_RXDW0_PKTLEN, len) |
((idx == RTWN_PCI_RX_LIST_COUNT - 1) ? R92C_RXDW0_EOR : 0));
desc->rxdw0 = htole32(SM(RTWN_RXDW0_PKTLEN, len) |
((idx == RTWN_PCI_RX_LIST_COUNT - 1) ? RTWN_RXDW0_EOR : 0));
desc->rxbufaddr = htole32(addr);
bus_space_barrier(pc->pc_st, pc->pc_sh, 0, pc->pc_mapsize,
BUS_SPACE_BARRIER_WRITE);
desc->rxdw0 |= htole32(R92C_RXDW0_OWN);
desc->rxdw0 |= htole32(RTWN_RXDW0_OWN);
}
static void
rtwn_pci_rx_frame(struct rtwn_softc *sc, struct r92ce_rx_stat *rx_desc,
rtwn_pci_rx_frame(struct rtwn_softc *sc, struct rtwn_rx_stat_pci *rx_desc,
int desc_idx)
{
struct rtwn_pci_softc *pc = RTWN_PCI_SOFTC(sc);
@ -107,18 +105,18 @@ rtwn_pci_rx_frame(struct rtwn_softc *sc, struct r92ce_rx_stat *rx_desc,
le32toh(rx_desc->rxbufaddr), le32toh(rx_desc->rxbufaddr64));
rxdw0 = le32toh(rx_desc->rxdw0);
if (__predict_false(rxdw0 & (R92C_RXDW0_CRCERR | R92C_RXDW0_ICVERR))) {
if (__predict_false(rxdw0 & (RTWN_RXDW0_CRCERR | RTWN_RXDW0_ICVERR))) {
/*
* This should not happen since we setup our Rx filter
* to not receive these frames.
*/
RTWN_DPRINTF(sc, RTWN_DEBUG_RECV,
"%s: RX flags error (%s)\n", __func__,
rxdw0 & R92C_RXDW0_CRCERR ? "CRC" : "ICV");
rxdw0 & RTWN_RXDW0_CRCERR ? "CRC" : "ICV");
goto fail;
}
pktlen = MS(rxdw0, R92C_RXDW0_PKTLEN);
pktlen = MS(rxdw0, RTWN_RXDW0_PKTLEN);
if (__predict_false(pktlen < sizeof(struct ieee80211_frame_ack) ||
pktlen > MJUMPAGESIZE)) {
RTWN_DPRINTF(sc, RTWN_DEBUG_RECV,
@ -126,8 +124,8 @@ rtwn_pci_rx_frame(struct rtwn_softc *sc, struct r92ce_rx_stat *rx_desc,
goto fail;
}
infosz = MS(rxdw0, R92C_RXDW0_INFOSZ) * 8;
shift = MS(rxdw0, R92C_RXDW0_SHIFT);
infosz = MS(rxdw0, RTWN_RXDW0_INFOSZ) * 8;
shift = MS(rxdw0, RTWN_RXDW0_SHIFT);
m1 = m_getjcl(M_NOWAIT, MT_DATA, M_PKTHDR, MJUMPAGESIZE);
if (__predict_false(m1 == NULL)) {
@ -268,9 +266,9 @@ rtwn_pci_rx_done(struct rtwn_softc *sc)
bus_dmamap_sync(ring->desc_dmat, ring->desc_map, BUS_DMASYNC_POSTREAD);
for (;;) {
struct r92ce_rx_stat *rx_desc = &ring->desc[ring->cur];
struct rtwn_rx_stat_pci *rx_desc = &ring->desc[ring->cur];
if (le32toh(rx_desc->rxdw0) & R92C_RXDW0_OWN)
if (le32toh(rx_desc->rxdw0) & RTWN_RXDW0_OWN)
break;
rtwn_pci_rx_frame(sc, rx_desc, ring->cur);

View File

@ -21,7 +21,7 @@
void rtwn_pci_dma_map_addr(void *, bus_dma_segment_t *, int, int);
void rtwn_pci_setup_rx_desc(struct rtwn_pci_softc *,
struct r92ce_rx_stat *, bus_addr_t, size_t, int);
struct rtwn_rx_stat_pci *, bus_addr_t, size_t, int);
void rtwn_pci_intr(void *);
#endif /* RTWN_PCI_RX_H */

View File

@ -23,9 +23,6 @@
#ifndef RTWN_PCI_VAR_H
#define RTWN_PCI_VAR_H
#include <dev/rtwn/rtl8192c/pci/r92ce_rx_desc.h>
#define RTWN_PCI_RX_LIST_COUNT 256
#define RTWN_PCI_TX_LIST_COUNT 256
@ -36,7 +33,7 @@ struct rtwn_rx_data {
};
struct rtwn_rx_ring {
struct r92ce_rx_stat *desc;
struct rtwn_rx_stat_pci *desc;
bus_addr_t paddr;
bus_dma_tag_t desc_dmat;
bus_dmamap_t desc_map;

View File

@ -63,12 +63,9 @@ __FBSDID("$FreeBSD$");
#include <dev/rtwn/usb/rtwn_usb_var.h>
#include <dev/rtwn/usb/rtwn_usb_rx.h>
#include <dev/rtwn/rtl8192c/r92c_reg.h> /* for CAM_ALGO_NONE */
#include <dev/rtwn/rtl8192c/r92c_rx_desc.h>
static struct mbuf *
rtwn_rx_copy_to_mbuf(struct rtwn_softc *sc, struct r92c_rx_stat *stat,
rtwn_rx_copy_to_mbuf(struct rtwn_softc *sc, struct rtwn_rx_stat_common *stat,
int totlen)
{
struct ieee80211com *ic = &sc->sc_ic;
@ -93,18 +90,18 @@ rtwn_rx_copy_to_mbuf(struct rtwn_softc *sc, struct r92c_rx_stat *stat,
return (NULL);
rxdw0 = le32toh(stat->rxdw0);
if (__predict_false(rxdw0 & (R92C_RXDW0_CRCERR | R92C_RXDW0_ICVERR))) {
if (__predict_false(rxdw0 & (RTWN_RXDW0_CRCERR | RTWN_RXDW0_ICVERR))) {
/*
* This should not happen since we setup our Rx filter
* to not receive these frames.
*/
RTWN_DPRINTF(sc, RTWN_DEBUG_RECV,
"%s: RX flags error (%s)\n", __func__,
rxdw0 & R92C_RXDW0_CRCERR ? "CRC" : "ICV");
rxdw0 & RTWN_RXDW0_CRCERR ? "CRC" : "ICV");
goto fail;
}
pktlen = MS(rxdw0, R92C_RXDW0_PKTLEN);
pktlen = MS(rxdw0, RTWN_RXDW0_PKTLEN);
if (__predict_false(pktlen < sizeof(struct ieee80211_frame_ack))) {
/*
* Should not happen (because of Rx filter setup).
@ -140,21 +137,21 @@ static struct mbuf *
rtwn_rxeof(struct rtwn_softc *sc, uint8_t *buf, int len)
{
struct rtwn_usb_softc *uc = RTWN_USB_SOFTC(sc);
struct r92c_rx_stat *stat;
struct rtwn_rx_stat_common *stat;
struct mbuf *m, *m0 = NULL;
uint32_t rxdw0;
int totlen, pktlen, infosz;
/* Process packets. */
while (len >= sizeof(*stat)) {
stat = (struct r92c_rx_stat *)buf;
stat = (struct rtwn_rx_stat_common *)buf;
rxdw0 = le32toh(stat->rxdw0);
pktlen = MS(rxdw0, R92C_RXDW0_PKTLEN);
pktlen = MS(rxdw0, RTWN_RXDW0_PKTLEN);
if (__predict_false(pktlen == 0))
break;
infosz = MS(rxdw0, R92C_RXDW0_INFOSZ) * 8;
infosz = MS(rxdw0, RTWN_RXDW0_INFOSZ) * 8;
/* Make sure everything fits in xfer. */
totlen = sizeof(*stat) + infosz + pktlen;
@ -193,7 +190,7 @@ rtwn_report_intr(struct rtwn_usb_softc *uc, struct usb_xfer *xfer,
usbd_xfer_status(xfer, &len, NULL, NULL, NULL);
if (__predict_false(len < sizeof(struct r92c_rx_stat))) {
if (__predict_false(len < sizeof(struct rtwn_rx_stat_common))) {
counter_u64_add(ic->ic_ierrors, 1);
return (NULL);
}
@ -238,11 +235,11 @@ rtwn_report_intr(struct rtwn_usb_softc *uc, struct usb_xfer *xfer,
static struct ieee80211_node *
rtwn_rx_frame(struct rtwn_softc *sc, struct mbuf *m)
{
struct r92c_rx_stat stat;
struct rtwn_rx_stat_common stat;
/* Imitate PCIe layout. */
m_copydata(m, 0, sizeof(struct r92c_rx_stat), (caddr_t)&stat);
m_adj(m, sizeof(struct r92c_rx_stat));
m_copydata(m, 0, sizeof(stat), (caddr_t)&stat);
m_adj(m, sizeof(stat));
return (rtwn_rx_common(sc, m, &stat));
}