rc80211_minstrel.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633
  1. /*
  2. * Copyright (C) 2008 Felix Fietkau <nbd@openwrt.org>
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License version 2 as
  6. * published by the Free Software Foundation.
  7. *
  8. * Based on minstrel.c:
  9. * Copyright (C) 2005-2007 Derek Smithies <derek@indranet.co.nz>
  10. * Sponsored by Indranet Technologies Ltd
  11. *
  12. * Based on sample.c:
  13. * Copyright (c) 2005 John Bicket
  14. * All rights reserved.
  15. *
  16. * Redistribution and use in source and binary forms, with or without
  17. * modification, are permitted provided that the following conditions
  18. * are met:
  19. * 1. Redistributions of source code must retain the above copyright
  20. * notice, this list of conditions and the following disclaimer,
  21. * without modification.
  22. * 2. Redistributions in binary form must reproduce at minimum a disclaimer
  23. * similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any
  24. * redistribution must be conditioned upon including a substantially
  25. * similar Disclaimer requirement for further binary redistribution.
  26. * 3. Neither the names of the above-listed copyright holders nor the names
  27. * of any contributors may be used to endorse or promote products derived
  28. * from this software without specific prior written permission.
  29. *
  30. * Alternatively, this software may be distributed under the terms of the
  31. * GNU General Public License ("GPL") version 2 as published by the Free
  32. * Software Foundation.
  33. *
  34. * NO WARRANTY
  35. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  36. * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  37. * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY
  38. * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
  39. * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY,
  40. * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  41. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  42. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
  43. * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  44. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  45. * THE POSSIBILITY OF SUCH DAMAGES.
  46. */
  47. #include <linux/netdevice.h>
  48. #include <linux/types.h>
  49. #include <linux/skbuff.h>
  50. #include <linux/debugfs.h>
  51. #include <linux/random.h>
  52. #include <linux/ieee80211.h>
  53. #include <linux/slab.h>
  54. #include <net/mac80211.h>
  55. #include "rate.h"
  56. #include "rc80211_minstrel.h"
  57. #define SAMPLE_TBL(_mi, _idx, _col) \
  58. _mi->sample_table[(_idx * SAMPLE_COLUMNS) + _col]
  59. /* convert mac80211 rate index to local array index */
  60. static inline int
  61. rix_to_ndx(struct minstrel_sta_info *mi, int rix)
  62. {
  63. int i = rix;
  64. for (i = rix; i >= 0; i--)
  65. if (mi->r[i].rix == rix)
  66. break;
  67. return i;
  68. }
  69. /* find & sort topmost throughput rates */
  70. static inline void
  71. minstrel_sort_best_tp_rates(struct minstrel_sta_info *mi, int i, u8 *tp_list)
  72. {
  73. int j = MAX_THR_RATES;
  74. while (j > 0 && mi->r[i].cur_tp > mi->r[tp_list[j - 1]].cur_tp)
  75. j--;
  76. if (j < MAX_THR_RATES - 1)
  77. memmove(&tp_list[j + 1], &tp_list[j], MAX_THR_RATES - (j + 1));
  78. if (j < MAX_THR_RATES)
  79. tp_list[j] = i;
  80. }
  81. static void
  82. minstrel_update_stats(struct minstrel_priv *mp, struct minstrel_sta_info *mi)
  83. {
  84. u8 tmp_tp_rate[MAX_THR_RATES];
  85. u8 tmp_prob_rate = 0;
  86. u32 usecs;
  87. int i;
  88. for (i=0; i < MAX_THR_RATES; i++)
  89. tmp_tp_rate[i] = 0;
  90. for (i = 0; i < mi->n_rates; i++) {
  91. struct minstrel_rate *mr = &mi->r[i];
  92. usecs = mr->perfect_tx_time;
  93. if (!usecs)
  94. usecs = 1000000;
  95. if (unlikely(mr->attempts > 0)) {
  96. mr->sample_skipped = 0;
  97. mr->cur_prob = MINSTREL_FRAC(mr->success, mr->attempts);
  98. mr->succ_hist += mr->success;
  99. mr->att_hist += mr->attempts;
  100. mr->probability = minstrel_ewma(mr->probability,
  101. mr->cur_prob,
  102. EWMA_LEVEL);
  103. } else
  104. mr->sample_skipped++;
  105. mr->last_success = mr->success;
  106. mr->last_attempts = mr->attempts;
  107. mr->success = 0;
  108. mr->attempts = 0;
  109. /* Update throughput per rate, reset thr. below 10% success */
  110. if (mr->probability < MINSTREL_FRAC(10, 100))
  111. mr->cur_tp = 0;
  112. else
  113. mr->cur_tp = mr->probability * (1000000 / usecs);
  114. /* Sample less often below the 10% chance of success.
  115. * Sample less often above the 95% chance of success. */
  116. if (mr->probability > MINSTREL_FRAC(95, 100) ||
  117. mr->probability < MINSTREL_FRAC(10, 100)) {
  118. mr->adjusted_retry_count = mr->retry_count >> 1;
  119. if (mr->adjusted_retry_count > 2)
  120. mr->adjusted_retry_count = 2;
  121. mr->sample_limit = 4;
  122. } else {
  123. mr->sample_limit = -1;
  124. mr->adjusted_retry_count = mr->retry_count;
  125. }
  126. if (!mr->adjusted_retry_count)
  127. mr->adjusted_retry_count = 2;
  128. minstrel_sort_best_tp_rates(mi, i, tmp_tp_rate);
  129. /* To determine the most robust rate (max_prob_rate) used at
  130. * 3rd mmr stage we distinct between two cases:
  131. * (1) if any success probabilitiy >= 95%, out of those rates
  132. * choose the maximum throughput rate as max_prob_rate
  133. * (2) if all success probabilities < 95%, the rate with
  134. * highest success probability is choosen as max_prob_rate */
  135. if (mr->probability >= MINSTREL_FRAC(95,100)) {
  136. if (mr->cur_tp >= mi->r[tmp_prob_rate].cur_tp)
  137. tmp_prob_rate = i;
  138. } else {
  139. if (mr->probability >= mi->r[tmp_prob_rate].probability)
  140. tmp_prob_rate = i;
  141. }
  142. }
  143. /* Assign the new rate set */
  144. memcpy(mi->max_tp_rate, tmp_tp_rate, sizeof(mi->max_tp_rate));
  145. mi->max_prob_rate = tmp_prob_rate;
  146. /* Reset update timer */
  147. mi->stats_update = jiffies;
  148. }
  149. static void
  150. minstrel_tx_status(void *priv, struct ieee80211_supported_band *sband,
  151. struct ieee80211_sta *sta, void *priv_sta,
  152. struct sk_buff *skb)
  153. {
  154. struct minstrel_priv *mp = priv;
  155. struct minstrel_sta_info *mi = priv_sta;
  156. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
  157. struct ieee80211_tx_rate *ar = info->status.rates;
  158. int i, ndx;
  159. int success;
  160. success = !!(info->flags & IEEE80211_TX_STAT_ACK);
  161. for (i = 0; i < IEEE80211_TX_MAX_RATES; i++) {
  162. if (ar[i].idx < 0)
  163. break;
  164. ndx = rix_to_ndx(mi, ar[i].idx);
  165. if (ndx < 0)
  166. continue;
  167. mi->r[ndx].attempts += ar[i].count;
  168. if ((i != IEEE80211_TX_MAX_RATES - 1) && (ar[i + 1].idx < 0))
  169. mi->r[ndx].success += success;
  170. }
  171. if ((info->flags & IEEE80211_TX_CTL_RATE_CTRL_PROBE) && (i >= 0))
  172. mi->sample_count++;
  173. if (mi->sample_deferred > 0)
  174. mi->sample_deferred--;
  175. if (time_after(jiffies, mi->stats_update +
  176. (mp->update_interval * HZ) / 1000))
  177. minstrel_update_stats(mp, mi);
  178. }
  179. static inline unsigned int
  180. minstrel_get_retry_count(struct minstrel_rate *mr,
  181. struct ieee80211_tx_info *info)
  182. {
  183. unsigned int retry = mr->adjusted_retry_count;
  184. if (info->control.rates[0].flags & IEEE80211_TX_RC_USE_RTS_CTS)
  185. retry = max(2U, min(mr->retry_count_rtscts, retry));
  186. else if (info->control.rates[0].flags & IEEE80211_TX_RC_USE_CTS_PROTECT)
  187. retry = max(2U, min(mr->retry_count_cts, retry));
  188. return retry;
  189. }
  190. static int
  191. minstrel_get_next_sample(struct minstrel_sta_info *mi)
  192. {
  193. unsigned int sample_ndx;
  194. sample_ndx = SAMPLE_TBL(mi, mi->sample_row, mi->sample_column);
  195. mi->sample_row++;
  196. if ((int) mi->sample_row >= mi->n_rates) {
  197. mi->sample_row = 0;
  198. mi->sample_column++;
  199. if (mi->sample_column >= SAMPLE_COLUMNS)
  200. mi->sample_column = 0;
  201. }
  202. return sample_ndx;
  203. }
  204. static void
  205. minstrel_get_rate(void *priv, struct ieee80211_sta *sta,
  206. void *priv_sta, struct ieee80211_tx_rate_control *txrc)
  207. {
  208. struct sk_buff *skb = txrc->skb;
  209. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
  210. struct minstrel_sta_info *mi = priv_sta;
  211. struct minstrel_priv *mp = priv;
  212. struct ieee80211_tx_rate *ar = info->control.rates;
  213. unsigned int ndx, sample_ndx = 0;
  214. bool mrr_capable;
  215. bool indirect_rate_sampling = false;
  216. bool rate_sampling = false;
  217. int i, delta;
  218. int mrr_ndx[3];
  219. int sampling_ratio;
  220. /* management/no-ack frames do not use rate control */
  221. if (rate_control_send_low(sta, priv_sta, txrc))
  222. return;
  223. /* check multi-rate-retry capabilities & adjust lookaround_rate */
  224. mrr_capable = mp->has_mrr &&
  225. !txrc->rts &&
  226. !txrc->bss_conf->use_cts_prot;
  227. if (mrr_capable)
  228. sampling_ratio = mp->lookaround_rate_mrr;
  229. else
  230. sampling_ratio = mp->lookaround_rate;
  231. /* init rateindex [ndx] with max throughput rate */
  232. ndx = mi->max_tp_rate[0];
  233. /* increase sum packet counter */
  234. mi->packet_count++;
  235. delta = (mi->packet_count * sampling_ratio / 100) -
  236. (mi->sample_count + mi->sample_deferred / 2);
  237. /* delta > 0: sampling required */
  238. if ((delta > 0) && (mrr_capable || !mi->prev_sample)) {
  239. struct minstrel_rate *msr;
  240. if (mi->packet_count >= 10000) {
  241. mi->sample_deferred = 0;
  242. mi->sample_count = 0;
  243. mi->packet_count = 0;
  244. } else if (delta > mi->n_rates * 2) {
  245. /* With multi-rate retry, not every planned sample
  246. * attempt actually gets used, due to the way the retry
  247. * chain is set up - [max_tp,sample,prob,lowest] for
  248. * sample_rate < max_tp.
  249. *
  250. * If there's too much sampling backlog and the link
  251. * starts getting worse, minstrel would start bursting
  252. * out lots of sampling frames, which would result
  253. * in a large throughput loss. */
  254. mi->sample_count += (delta - mi->n_rates * 2);
  255. }
  256. /* get next random rate sample */
  257. sample_ndx = minstrel_get_next_sample(mi);
  258. msr = &mi->r[sample_ndx];
  259. rate_sampling = true;
  260. /* Decide if direct ( 1st mrr stage) or indirect (2nd mrr stage)
  261. * rate sampling method should be used.
  262. * Respect such rates that are not sampled for 20 interations.
  263. */
  264. if (mrr_capable &&
  265. msr->perfect_tx_time > mi->r[ndx].perfect_tx_time &&
  266. msr->sample_skipped < 20)
  267. indirect_rate_sampling = true;
  268. if (!indirect_rate_sampling) {
  269. if (msr->sample_limit != 0) {
  270. ndx = sample_ndx;
  271. mi->sample_count++;
  272. if (msr->sample_limit > 0)
  273. msr->sample_limit--;
  274. } else
  275. rate_sampling = false;
  276. } else {
  277. /* Only use IEEE80211_TX_CTL_RATE_CTRL_PROBE to mark
  278. * packets that have the sampling rate deferred to the
  279. * second MRR stage. Increase the sample counter only
  280. * if the deferred sample rate was actually used.
  281. * Use the sample_deferred counter to make sure that
  282. * the sampling is not done in large bursts */
  283. info->flags |= IEEE80211_TX_CTL_RATE_CTRL_PROBE;
  284. mi->sample_deferred++;
  285. }
  286. }
  287. mi->prev_sample = rate_sampling;
  288. /* If we're not using MRR and the sampling rate already
  289. * has a probability of >95%, we shouldn't be attempting
  290. * to use it, as this only wastes precious airtime */
  291. if (!mrr_capable && rate_sampling &&
  292. (mi->r[ndx].probability > MINSTREL_FRAC(95, 100)))
  293. ndx = mi->max_tp_rate[0];
  294. /* mrr setup for 1st stage */
  295. ar[0].idx = mi->r[ndx].rix;
  296. ar[0].count = minstrel_get_retry_count(&mi->r[ndx], info);
  297. /* non mrr setup for 2nd stage */
  298. if (!mrr_capable) {
  299. if (!rate_sampling)
  300. ar[0].count = mp->max_retry;
  301. ar[1].idx = mi->lowest_rix;
  302. ar[1].count = mp->max_retry;
  303. return;
  304. }
  305. /* mrr setup for 2nd stage */
  306. if (rate_sampling) {
  307. if (indirect_rate_sampling)
  308. mrr_ndx[0] = sample_ndx;
  309. else
  310. mrr_ndx[0] = mi->max_tp_rate[0];
  311. } else {
  312. mrr_ndx[0] = mi->max_tp_rate[1];
  313. }
  314. /* mrr setup for 3rd & 4th stage */
  315. mrr_ndx[1] = mi->max_prob_rate;
  316. mrr_ndx[2] = 0;
  317. for (i = 1; i < 4; i++) {
  318. ar[i].idx = mi->r[mrr_ndx[i - 1]].rix;
  319. ar[i].count = mi->r[mrr_ndx[i - 1]].adjusted_retry_count;
  320. }
  321. }
  322. static void
  323. calc_rate_durations(enum ieee80211_band band,
  324. struct minstrel_rate *d,
  325. struct ieee80211_rate *rate)
  326. {
  327. int erp = !!(rate->flags & IEEE80211_RATE_ERP_G);
  328. d->perfect_tx_time = ieee80211_frame_duration(band, 1200,
  329. rate->bitrate, erp, 1);
  330. d->ack_time = ieee80211_frame_duration(band, 10,
  331. rate->bitrate, erp, 1);
  332. }
  333. static void
  334. init_sample_table(struct minstrel_sta_info *mi)
  335. {
  336. unsigned int i, col, new_idx;
  337. u8 rnd[8];
  338. mi->sample_column = 0;
  339. mi->sample_row = 0;
  340. memset(mi->sample_table, 0xff, SAMPLE_COLUMNS * mi->n_rates);
  341. for (col = 0; col < SAMPLE_COLUMNS; col++) {
  342. for (i = 0; i < mi->n_rates; i++) {
  343. get_random_bytes(rnd, sizeof(rnd));
  344. new_idx = (i + rnd[i & 7]) % mi->n_rates;
  345. while (SAMPLE_TBL(mi, new_idx, col) != 0xff)
  346. new_idx = (new_idx + 1) % mi->n_rates;
  347. SAMPLE_TBL(mi, new_idx, col) = i;
  348. }
  349. }
  350. }
  351. static void
  352. minstrel_rate_init(void *priv, struct ieee80211_supported_band *sband,
  353. struct ieee80211_sta *sta, void *priv_sta)
  354. {
  355. struct minstrel_sta_info *mi = priv_sta;
  356. struct minstrel_priv *mp = priv;
  357. struct ieee80211_rate *ctl_rate;
  358. unsigned int i, n = 0;
  359. unsigned int t_slot = 9; /* FIXME: get real slot time */
  360. mi->lowest_rix = rate_lowest_index(sband, sta);
  361. ctl_rate = &sband->bitrates[mi->lowest_rix];
  362. mi->sp_ack_dur = ieee80211_frame_duration(sband->band, 10,
  363. ctl_rate->bitrate,
  364. !!(ctl_rate->flags & IEEE80211_RATE_ERP_G), 1);
  365. for (i = 0; i < sband->n_bitrates; i++) {
  366. struct minstrel_rate *mr = &mi->r[n];
  367. unsigned int tx_time = 0, tx_time_cts = 0, tx_time_rtscts = 0;
  368. unsigned int tx_time_single;
  369. unsigned int cw = mp->cw_min;
  370. if (!rate_supported(sta, sband->band, i))
  371. continue;
  372. n++;
  373. memset(mr, 0, sizeof(*mr));
  374. mr->rix = i;
  375. mr->bitrate = sband->bitrates[i].bitrate / 5;
  376. calc_rate_durations(sband->band, mr, &sband->bitrates[i]);
  377. /* calculate maximum number of retransmissions before
  378. * fallback (based on maximum segment size) */
  379. mr->sample_limit = -1;
  380. mr->retry_count = 1;
  381. mr->retry_count_cts = 1;
  382. mr->retry_count_rtscts = 1;
  383. tx_time = mr->perfect_tx_time + mi->sp_ack_dur;
  384. do {
  385. /* add one retransmission */
  386. tx_time_single = mr->ack_time + mr->perfect_tx_time;
  387. /* contention window */
  388. tx_time_single += (t_slot * cw) >> 1;
  389. cw = min((cw << 1) | 1, mp->cw_max);
  390. tx_time += tx_time_single;
  391. tx_time_cts += tx_time_single + mi->sp_ack_dur;
  392. tx_time_rtscts += tx_time_single + 2 * mi->sp_ack_dur;
  393. if ((tx_time_cts < mp->segment_size) &&
  394. (mr->retry_count_cts < mp->max_retry))
  395. mr->retry_count_cts++;
  396. if ((tx_time_rtscts < mp->segment_size) &&
  397. (mr->retry_count_rtscts < mp->max_retry))
  398. mr->retry_count_rtscts++;
  399. } while ((tx_time < mp->segment_size) &&
  400. (++mr->retry_count < mp->max_retry));
  401. mr->adjusted_retry_count = mr->retry_count;
  402. }
  403. for (i = n; i < sband->n_bitrates; i++) {
  404. struct minstrel_rate *mr = &mi->r[i];
  405. mr->rix = -1;
  406. }
  407. mi->n_rates = n;
  408. mi->stats_update = jiffies;
  409. init_sample_table(mi);
  410. }
  411. static void *
  412. minstrel_alloc_sta(void *priv, struct ieee80211_sta *sta, gfp_t gfp)
  413. {
  414. struct ieee80211_supported_band *sband;
  415. struct minstrel_sta_info *mi;
  416. struct minstrel_priv *mp = priv;
  417. struct ieee80211_hw *hw = mp->hw;
  418. int max_rates = 0;
  419. int i;
  420. mi = kzalloc(sizeof(struct minstrel_sta_info), gfp);
  421. if (!mi)
  422. return NULL;
  423. for (i = 0; i < IEEE80211_NUM_BANDS; i++) {
  424. sband = hw->wiphy->bands[i];
  425. if (sband && sband->n_bitrates > max_rates)
  426. max_rates = sband->n_bitrates;
  427. }
  428. mi->r = kzalloc(sizeof(struct minstrel_rate) * max_rates, gfp);
  429. if (!mi->r)
  430. goto error;
  431. mi->sample_table = kmalloc(SAMPLE_COLUMNS * max_rates, gfp);
  432. if (!mi->sample_table)
  433. goto error1;
  434. mi->stats_update = jiffies;
  435. return mi;
  436. error1:
  437. kfree(mi->r);
  438. error:
  439. kfree(mi);
  440. return NULL;
  441. }
  442. static void
  443. minstrel_free_sta(void *priv, struct ieee80211_sta *sta, void *priv_sta)
  444. {
  445. struct minstrel_sta_info *mi = priv_sta;
  446. kfree(mi->sample_table);
  447. kfree(mi->r);
  448. kfree(mi);
  449. }
  450. static void
  451. minstrel_init_cck_rates(struct minstrel_priv *mp)
  452. {
  453. static const int bitrates[4] = { 10, 20, 55, 110 };
  454. struct ieee80211_supported_band *sband;
  455. int i, j;
  456. sband = mp->hw->wiphy->bands[IEEE80211_BAND_2GHZ];
  457. if (!sband)
  458. return;
  459. for (i = 0, j = 0; i < sband->n_bitrates; i++) {
  460. struct ieee80211_rate *rate = &sband->bitrates[i];
  461. if (rate->flags & IEEE80211_RATE_ERP_G)
  462. continue;
  463. for (j = 0; j < ARRAY_SIZE(bitrates); j++) {
  464. if (rate->bitrate != bitrates[j])
  465. continue;
  466. mp->cck_rates[j] = i;
  467. break;
  468. }
  469. }
  470. }
  471. static void *
  472. minstrel_alloc(struct ieee80211_hw *hw, struct dentry *debugfsdir)
  473. {
  474. struct minstrel_priv *mp;
  475. mp = kzalloc(sizeof(struct minstrel_priv), GFP_ATOMIC);
  476. if (!mp)
  477. return NULL;
  478. /* contention window settings
  479. * Just an approximation. Using the per-queue values would complicate
  480. * the calculations and is probably unnecessary */
  481. mp->cw_min = 15;
  482. mp->cw_max = 1023;
  483. /* number of packets (in %) to use for sampling other rates
  484. * sample less often for non-mrr packets, because the overhead
  485. * is much higher than with mrr */
  486. mp->lookaround_rate = 5;
  487. mp->lookaround_rate_mrr = 10;
  488. /* maximum time that the hw is allowed to stay in one MRR segment */
  489. mp->segment_size = 6000;
  490. if (hw->max_rate_tries > 0)
  491. mp->max_retry = hw->max_rate_tries;
  492. else
  493. /* safe default, does not necessarily have to match hw properties */
  494. mp->max_retry = 7;
  495. if (hw->max_rates >= 4)
  496. mp->has_mrr = true;
  497. mp->hw = hw;
  498. mp->update_interval = 100;
  499. #ifdef CONFIG_MAC80211_DEBUGFS
  500. mp->fixed_rate_idx = (u32) -1;
  501. mp->dbg_fixed_rate = debugfs_create_u32("fixed_rate_idx",
  502. S_IRUGO | S_IWUGO, debugfsdir, &mp->fixed_rate_idx);
  503. #endif
  504. minstrel_init_cck_rates(mp);
  505. return mp;
  506. }
  507. static void
  508. minstrel_free(void *priv)
  509. {
  510. #ifdef CONFIG_MAC80211_DEBUGFS
  511. debugfs_remove(((struct minstrel_priv *)priv)->dbg_fixed_rate);
  512. #endif
  513. kfree(priv);
  514. }
  515. struct rate_control_ops mac80211_minstrel = {
  516. .name = "minstrel",
  517. .tx_status = minstrel_tx_status,
  518. .get_rate = minstrel_get_rate,
  519. .rate_init = minstrel_rate_init,
  520. .alloc = minstrel_alloc,
  521. .free = minstrel_free,
  522. .alloc_sta = minstrel_alloc_sta,
  523. .free_sta = minstrel_free_sta,
  524. #ifdef CONFIG_MAC80211_DEBUGFS
  525. .add_sta_debugfs = minstrel_add_sta_debugfs,
  526. .remove_sta_debugfs = minstrel_remove_sta_debugfs,
  527. #endif
  528. };
  529. int __init
  530. rc80211_minstrel_init(void)
  531. {
  532. return ieee80211_rate_control_register(&mac80211_minstrel);
  533. }
  534. void
  535. rc80211_minstrel_exit(void)
  536. {
  537. ieee80211_rate_control_unregister(&mac80211_minstrel);
  538. }