FreeBSD/sys/dev/rtwn/if_rtwn.c
/*
 * Initialize rate adaptation in firmware.
 */
Initialize rate adaptation in firmware.
Initialize rate adaptation in firmware .
static int
rtwn_ra_init(struct rtwn_softc *sc)
{
	struct ieee80211com *ic = &sc->sc_ic;
	struct ieee80211vap *vap = TAILQ_FIRST(&ic->ic_vaps);
	struct ieee80211_node *ni = ieee80211_ref_node(vap->iv_bss);
	struct ieee80211_rateset *rs = &ni->ni_rates;
	struct r92c_fw_cmd_macid_cfg cmd;
	uint32_t rates, basicrates;
	uint8_t maxrate, maxbasicrate, mode, ridx;
	int error, i;
	rates = basicrates = 0;
	maxrate = maxbasicrate = 0;
	for (i = 0; i < rs->rs_nrates; i++) {
		ridx = rate2ridx(IEEE80211_RV(rs->rs_rates[i]));
		if (ridx == RTWN_RIDX_UNKNOWN)	
			continue;
		rates |= 1 << ridx;
		if (ridx > maxrate)
			maxrate = ridx;
		if (rs->rs_rates[i] & IEEE80211_RATE_BASIC) {
			basicrates |= 1 << ridx;
			if (ridx > maxbasicrate)
				maxbasicrate = ridx;
		}
	}
	if (ic->ic_curmode == IEEE80211_MODE_11B)
		mode = R92C_RAID_11B;
	else
		mode = R92C_RAID_11BG;
	DPRINTF(("mode=0x%x rates=0x%08x, basicrates=0x%08x\n",
	    mode, rates, basicrates));
	cmd.macid = RTWN_MACID_BC | RTWN_MACID_VALID;
	cmd.mask = htole32(mode << 28 | basicrates);
	error = rtwn_fw_cmd(sc, R92C_CMD_MACID_CONFIG, &cmd, sizeof(cmd));
	if (error != 0) {
		device_printf(sc->sc_dev,
		    "could not add broadcast station\n");
		return (error);
	}
	DPRINTF(("maxbasicrate=%d\n", maxbasicrate));
	rtwn_write_1(sc, R92C_INIDATA_RATE_SEL(RTWN_MACID_BC),
	    maxbasicrate);
	cmd.macid = RTWN_MACID_BSS | RTWN_MACID_VALID;
	cmd.mask = htole32(mode << 28 | rates);
	error = rtwn_fw_cmd(sc, R92C_CMD_MACID_CONFIG, &cmd, sizeof(cmd));
	if (error != 0) {
		device_printf(sc->sc_dev, "could not add BSS station\n");
		return (error);
	}
	DPRINTF(("maxrate=%d\n", maxrate));
	rtwn_write_1(sc, R92C_INIDATA_RATE_SEL(RTWN_MACID_BSS),
	    maxrate);
	if (ic->ic_curmode == IEEE80211_MODE_11B) {
		if (rates & 0x0c)
			rtwn_write_4(sc, R92C_ARFR(0), htole32(rates & 0x0d));
		else
			rtwn_write_4(sc, R92C_ARFR(0), htole32(rates & 0x0f));
	} else
		rtwn_write_4(sc, R92C_ARFR(0), htole32(rates & 0x0ff5));
	ni->ni_txrate = rs->rs_rates[rs->rs_nrates - 1];
	return (0);
}
static int rtwn_ra_init ( struct rtwn_softc * sc ) { struct ieee80211com * ic = & sc -> sc_ic ; struct ieee80211vap * vap = TAILQ_FIRST ( & ic -> ic_vaps ) ; struct ieee80211_node * ni = ieee80211_ref_node ( vap -> iv_bss ) ; struct ieee80211_rateset * rs = & ni -> ni_rates ; struct r92c_fw_cmd_macid_cfg cmd ; uint32_t rates , basicrates ; uint8_t maxrate , maxbasicrate , mode , ridx ; int error , i ; rates = basicrates = 0 ; maxrate = maxbasicrate = 0 ; for ( i = 0 ; i < rs -> rs_nrates ; i ++ ) { ridx = rate2ridx ( IEEE80211_RV ( rs -> rs_rates [ i ] ) ) ; if ( ridx == RTWN_RIDX_UNKNOWN ) continue ; rates |= 1 << ridx ; if ( ridx > maxrate ) maxrate = ridx ; if ( rs -> rs_rates [ i ] & IEEE80211_RATE_BASIC ) { basicrates |= 1 << ridx ; if ( ridx > maxbasicrate ) maxbasicrate = ridx ; } } if ( ic -> ic_curmode == IEEE80211_MODE_11B ) mode = R92C_RAID_11B ; else mode = R92C_RAID_11BG ; DPRINTF ( ( " \n " , mode , rates , basicrates ) ) ; cmd . macid = RTWN_MACID_BC | RTWN_MACID_VALID ; cmd . mask = htole32 ( mode << 28 | basicrates ) ; error = rtwn_fw_cmd ( sc , R92C_CMD_MACID_CONFIG , & cmd , sizeof ( cmd ) ) ; if ( error != 0 ) { device_printf ( sc -> sc_dev , " \n " ) ; return ( error ) ; } DPRINTF ( ( " \n " , maxbasicrate ) ) ; rtwn_write_1 ( sc , R92C_INIDATA_RATE_SEL ( RTWN_MACID_BC ) , maxbasicrate ) ; cmd . macid = RTWN_MACID_BSS | RTWN_MACID_VALID ; cmd . mask = htole32 ( mode << 28 | rates ) ; error = rtwn_fw_cmd ( sc , R92C_CMD_MACID_CONFIG , & cmd , sizeof ( cmd ) ) ; if ( error != 0 ) { device_printf ( sc -> sc_dev , " \n " ) ; return ( error ) ; } DPRINTF ( ( " \n " , maxrate ) ) ; rtwn_write_1 ( sc , R92C_INIDATA_RATE_SEL ( RTWN_MACID_BSS ) , maxrate ) ; if ( ic -> ic_curmode == IEEE80211_MODE_11B ) { if ( rates & 0x0c ) rtwn_write_4 ( sc , R92C_ARFR ( 0 ) , htole32 ( rates & 0x0d ) ) ; else rtwn_write_4 ( sc , R92C_ARFR ( 0 ) , htole32 ( rates & 0x0f ) ) ; } else rtwn_write_4 ( sc , R92C_ARFR ( 0 ) , htole32 ( rates & 0x0ff5 ) ) ; ni -> ni_txrate = rs -> rs_rates [ rs -> rs_nrates - 1 ] ; return ( 0 ) ; }
Initialize rate adaptation in firmware.
Initialize rate adaptation in firmware .
/* Get normal and basic rates mask. */ /* Convert 802.11 rate to HW rate index. */ /* Unknown rate, skip. */ /* Set rates mask for group addressed frames. */ /* Set initial MRR rate. */ /* Set rates mask for unicast frames. */ /* Set initial MRR rate. */ /* Configure Automatic Rate Fallback Register. */ /* Indicate highest supported rate. */