351-0005-brcmfmac-rework-function-picking-free-BSS-index.patch 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= <zajec5@gmail.com>
  2. Date: Thu, 26 May 2016 01:44:27 +0200
  3. Subject: [PATCH] brcmfmac: rework function picking free BSS index
  4. MIME-Version: 1.0
  5. Content-Type: text/plain; charset=UTF-8
  6. Content-Transfer-Encoding: 8bit
  7. The old implementation was overcomplicated and slightly bugged in some
  8. corner cases.
  9. Consider following state of BSS-es (limited to 6 for simplification):
  10. drvr->iflist[0]: { bsscfgidx:0, ndev->name:wlan1, }
  11. drvr->iflist[1]: (null)
  12. drvr->iflist[2]: { bsscfgidx:2, ndev->name:wlan1-1, }
  13. drvr->iflist[3]: { bsscfgidx:3, ndev->name:wlan1-2, }
  14. drvr->iflist[4]: (null)
  15. drvr->iflist[5]: (null)
  16. In such case the next AP interface should bsscfgidx 4 (we don't use 1 as
  17. it's reserved for P2P).
  18. With old code the loop iterations were following:
  19. [ifidx = 0] [bsscfgidx = 2] [highest = 2]
  20. [ifidx = 1] [bsscfgidx = 2] [highest = 2] available = true
  21. [ifidx = 2] [bsscfgidx = 2] [highest = 2] bsscfgidx = highest + 1
  22. [ifidx = 3] [bsscfgidx = 3] [highest = 2] bsscfgidx = highest + 1
  23. [ifidx = 4] [bsscfgidx = 3] [highest = 2] available = true
  24. [ifidx = 5] [bsscfgidx = 3] [highest = 2] available = true
  25. There were 2 obvious problems:
  26. 1) Having empty BSS at index 1 was resulting in available being always
  27. set to true, even if we would run out of BSS-es.
  28. 2) Calculated bsscfgidx was invalid (3 instead of 4) resulting in driver
  29. not being able to create the 4th AP interface.
  30. New code is simpler, placed in file where it's really used, handles
  31. running out of free BSS-es and allows using 4 interfaces at the same
  32. time. It also looks for the first free BSS instead of one after the last
  33. in use. It works well with current driver (which doesn't allow deleting
  34. interfaces) and should be future proof (if we ever allow deleting).
  35. Signed-off-by: Rafał Miłecki <zajec5@gmail.com>
  36. Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
  37. ---
  38. --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c
  39. +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c
  40. @@ -541,6 +541,21 @@ brcmf_cfg80211_update_proto_addr_mode(st
  41. ADDR_INDIRECT);
  42. }
  43. +static int brcmf_get_first_free_bsscfgidx(struct brcmf_pub *drvr)
  44. +{
  45. + int bsscfgidx;
  46. +
  47. + for (bsscfgidx = 0; bsscfgidx < BRCMF_MAX_IFS; bsscfgidx++) {
  48. + /* bsscfgidx 1 is reserved for legacy P2P */
  49. + if (bsscfgidx == 1)
  50. + continue;
  51. + if (!drvr->iflist[bsscfgidx])
  52. + return bsscfgidx;
  53. + }
  54. +
  55. + return -ENOMEM;
  56. +}
  57. +
  58. static int brcmf_cfg80211_request_ap_if(struct brcmf_if *ifp)
  59. {
  60. struct brcmf_mbss_ssid_le mbss_ssid_le;
  61. @@ -548,7 +563,7 @@ static int brcmf_cfg80211_request_ap_if(
  62. int err;
  63. memset(&mbss_ssid_le, 0, sizeof(mbss_ssid_le));
  64. - bsscfgidx = brcmf_get_next_free_bsscfgidx(ifp->drvr);
  65. + bsscfgidx = brcmf_get_first_free_bsscfgidx(ifp->drvr);
  66. if (bsscfgidx < 0)
  67. return bsscfgidx;
  68. --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/core.c
  69. +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/core.c
  70. @@ -753,30 +753,6 @@ void brcmf_remove_interface(struct brcmf
  71. brcmf_del_if(ifp->drvr, ifp->bsscfgidx);
  72. }
  73. -int brcmf_get_next_free_bsscfgidx(struct brcmf_pub *drvr)
  74. -{
  75. - int ifidx;
  76. - int bsscfgidx;
  77. - bool available;
  78. - int highest;
  79. -
  80. - available = false;
  81. - bsscfgidx = 2;
  82. - highest = 2;
  83. - for (ifidx = 0; ifidx < BRCMF_MAX_IFS; ifidx++) {
  84. - if (drvr->iflist[ifidx]) {
  85. - if (drvr->iflist[ifidx]->bsscfgidx == bsscfgidx)
  86. - bsscfgidx = highest + 1;
  87. - else if (drvr->iflist[ifidx]->bsscfgidx > highest)
  88. - highest = drvr->iflist[ifidx]->bsscfgidx;
  89. - } else {
  90. - available = true;
  91. - }
  92. - }
  93. -
  94. - return available ? bsscfgidx : -ENOMEM;
  95. -}
  96. -
  97. #ifdef CONFIG_INET
  98. #define ARPOL_MAX_ENTRIES 8
  99. static int brcmf_inetaddr_changed(struct notifier_block *nb,
  100. --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/core.h
  101. +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/core.h
  102. @@ -217,7 +217,6 @@ int brcmf_net_attach(struct brcmf_if *if
  103. struct brcmf_if *brcmf_add_if(struct brcmf_pub *drvr, s32 bsscfgidx, s32 ifidx,
  104. bool is_p2pdev, char *name, u8 *mac_addr);
  105. void brcmf_remove_interface(struct brcmf_if *ifp);
  106. -int brcmf_get_next_free_bsscfgidx(struct brcmf_pub *drvr);
  107. void brcmf_txflowblock_if(struct brcmf_if *ifp,
  108. enum brcmf_netif_stop_reason reason, bool state);
  109. void brcmf_txfinalize(struct brcmf_if *ifp, struct sk_buff *txp, bool success);