Index: sys/dev/usb/wlan/if_urtwn.c =================================================================== --- sys/dev/usb/wlan/if_urtwn.c +++ sys/dev/usb/wlan/if_urtwn.c @@ -1737,6 +1737,26 @@ return (0); } +static __inline uint8_t +rate2ridx(uint8_t rate) +{ + switch (rate) { + case 12: return 4; + case 18: return 5; + case 24: return 6; + case 36: return 7; + case 48: return 8; + case 72: return 9; + case 96: return 10; + case 108: return 11; + case 2: return 0; + case 4: return 1; + case 11: return 2; + case 22: return 3; + default: return URTWN_RIDX_UNKNOWN; + } +} + /* * Initialize rate adaptation in firmware. */ @@ -1749,8 +1769,8 @@ struct ieee80211_rateset *rs; struct r92c_fw_cmd_macid_cfg cmd; uint32_t rates, basicrates; - uint8_t mode; - int maxrate, maxbasicrate, error, i, j; + uint8_t mode, ridx; + int maxrate, maxbasicrate, error, i; ni = ieee80211_ref_node(vap->iv_bss); rs = &ni->ni_rates; @@ -1760,19 +1780,16 @@ maxrate = maxbasicrate = 0; for (i = 0; i < rs->rs_nrates; i++) { /* Convert 802.11 rate to HW rate index. */ - for (j = 0; j < nitems(ridx2rate); j++) - if ((rs->rs_rates[i] & IEEE80211_RATE_VAL) == - ridx2rate[j]) - break; - if (j == nitems(ridx2rate)) /* Unknown rate, skip. */ + ridx = rate2ridx(IEEE80211_RV(rs->rs_rates[i])); + if (ridx == URTWN_RIDX_UNKNOWN) /* Unknown rate, skip. */ continue; - rates |= 1 << j; - if (j > maxrate) - maxrate = j; + rates |= 1 << ridx; + if (ridx > maxrate) + maxrate = ridx; if (rs->rs_rates[i] & IEEE80211_RATE_BASIC) { - basicrates |= 1 << j; - if (j > maxbasicrate) - maxbasicrate = j; + basicrates |= 1 << ridx; + if (ridx > maxbasicrate) + maxbasicrate = ridx; } } if (ic->ic_curmode == IEEE80211_MODE_11B) @@ -2539,26 +2556,6 @@ return (rssi); } -static __inline uint8_t -rate2ridx(uint8_t rate) -{ - switch (rate) { - case 12: return 4; - case 18: return 5; - case 24: return 6; - case 36: return 7; - case 48: return 8; - case 72: return 9; - case 96: return 10; - case 108: return 11; - case 2: return 0; - case 4: return 1; - case 11: return 2; - case 22: return 3; - default: return 0; - } -} - static int urtwn_tx_data(struct urtwn_softc *sc, struct ieee80211_node *ni, struct mbuf *m, struct urtwn_data *data) Index: sys/dev/usb/wlan/if_urtwnreg.h =================================================================== --- sys/dev/usb/wlan/if_urtwnreg.h +++ sys/dev/usb/wlan/if_urtwnreg.h @@ -1206,6 +1206,7 @@ #define URTWN_RIDX_OFDM54 11 #define URTWN_RIDX_COUNT 28 +#define URTWN_RIDX_UNKNOWN (uint8_t)-1 /*