3c52cec0b91593d91f85633345f4c41b2bc27cb1
[oweals/openwrt.git] / package / kernel / mac80211 / patches / brcm / 998-survey.patch
1 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c
2 +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c
3 @@ -2826,6 +2826,63 @@ done:
4  }
5  
6  static int
7 +brcmf_cfg80211_dump_survey(struct wiphy *wiphy, struct net_device *ndev,
8 +                          int idx, struct survey_info *survey)
9 +{
10 +       struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
11 +       struct brcmf_if *ifp = netdev_priv(ndev);
12 +       struct brcmu_chan ch;
13 +       enum nl80211_band band = 0;
14 +       s32 err = 0;
15 +       int noise;
16 +       u32 freq;
17 +       u32 chanspec;
18 +
19 +       memset(survey, 0, sizeof(struct survey_info));
20 +       if (idx != 0) {
21 +               if (idx >= cfg->pub->num_chan_stats || cfg->pub->chan_stats == NULL)
22 +                       return -ENOENT;
23 +               if (cfg->pub->chan_stats[idx].freq == 0)
24 +                       return -ENOENT;
25 +               survey->filled = SURVEY_INFO_NOISE_DBM;
26 +               survey->channel = ieee80211_get_channel(wiphy, cfg->pub->chan_stats[idx].freq);
27 +               survey->noise = cfg->pub->chan_stats[idx].noise;
28 +               return 0;
29 +       }
30 +
31 +       err = brcmf_fil_iovar_int_get(ifp, "chanspec", &chanspec);
32 +       if (err) {
33 +               brcmf_err("chanspec failed (%d)\n", err);
34 +               return err;
35 +       }
36 +
37 +       ch.chspec = chanspec;
38 +       cfg->d11inf.decchspec(&ch);
39 +
40 +       switch (ch.band) {
41 +       case BRCMU_CHAN_BAND_2G:
42 +               band = NL80211_BAND_2GHZ;
43 +               break;
44 +       case BRCMU_CHAN_BAND_5G:
45 +               band = NL80211_BAND_5GHZ;
46 +               break;
47 +       }
48 +
49 +       freq = ieee80211_channel_to_frequency(ch.control_ch_num, band);
50 +       survey->channel = ieee80211_get_channel(wiphy, freq);
51 +
52 +       err = brcmf_fil_cmd_int_get(ifp, BRCMF_C_GET_PHY_NOISE, &noise);
53 +       if (err) {
54 +               brcmf_err("Could not get noise (%d)\n", err);
55 +               return err;
56 +       }
57 +
58 +       survey->filled = SURVEY_INFO_NOISE_DBM | SURVEY_INFO_IN_USE;
59 +       survey->noise = le32_to_cpu(noise);
60 +       return 0;
61 +}
62 +
63 +static int
64  brcmf_cfg80211_dump_station(struct wiphy *wiphy, struct net_device *ndev,
65                             int idx, u8 *mac, struct station_info *sinfo)
66  {
67 @@ -2915,6 +2972,7 @@ static s32 brcmf_inform_single_bss(struc
68         struct brcmu_chan ch;
69         u16 channel;
70         u32 freq;
71 +       int i;
72         u16 notify_capability;
73         u16 notify_interval;
74         u8 *notify_ie;
75 @@ -2939,6 +2997,17 @@ static s32 brcmf_inform_single_bss(struc
76                 band = NL80211_BAND_5GHZ;
77  
78         freq = ieee80211_channel_to_frequency(channel, band);
79 +       for (i = 0;i < cfg->pub->num_chan_stats;i++) {
80 +               if (freq == cfg->pub->chan_stats[i].freq)
81 +                       break;
82 +               if (cfg->pub->chan_stats[i].freq == 0)
83 +                       break;
84 +       }
85 +       if (i < cfg->pub->num_chan_stats) {
86 +               cfg->pub->chan_stats[i].freq = freq;
87 +               cfg->pub->chan_stats[i].noise = bi->phy_noise;
88 +       }
89 +
90         bss_data.chan = ieee80211_get_channel(wiphy, freq);
91         bss_data.scan_width = NL80211_BSS_CHAN_WIDTH_20;
92         bss_data.boottime_ns = ktime_to_ns(ktime_get_boottime());
93 @@ -5356,6 +5425,7 @@ static struct cfg80211_ops brcmf_cfg8021
94         .leave_ibss = brcmf_cfg80211_leave_ibss,
95         .get_station = brcmf_cfg80211_get_station,
96         .dump_station = brcmf_cfg80211_dump_station,
97 +       .dump_survey = brcmf_cfg80211_dump_survey,
98         .set_tx_power = brcmf_cfg80211_set_tx_power,
99         .get_tx_power = brcmf_cfg80211_get_tx_power,
100         .add_key = brcmf_cfg80211_add_key,
101 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/core.c
102 +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/core.c
103 @@ -1352,6 +1352,8 @@ int brcmf_attach(struct device *dev)
104  
105         /* Link to bus module */
106         drvr->hdrlen = 0;
107 +       drvr->chan_stats = vzalloc(256 * sizeof(struct brcmf_chan_stats));
108 +       drvr->num_chan_stats = 256;
109  
110         /* Attach and link in the protocol */
111         ret = brcmf_proto_attach(drvr);
112 @@ -1434,6 +1436,12 @@ void brcmf_detach(struct device *dev)
113         if (drvr == NULL)
114                 return;
115  
116 +       drvr->num_chan_stats = 0;
117 +       if (drvr->chan_stats) {
118 +               vfree(drvr->chan_stats);
119 +               drvr->chan_stats = NULL;
120 +       }
121 +
122  #ifdef CONFIG_INET
123         unregister_inetaddr_notifier(&drvr->inetaddr_notifier);
124  #endif
125 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/core.h
126 +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/core.h
127 @@ -91,6 +91,11 @@ struct brcmf_rev_info {
128         u32 nvramrev;
129  };
130  
131 +struct brcmf_chan_stats {
132 +       u32 freq;
133 +       int noise;
134 +};
135 +
136  /* Common structure for module and instance linkage */
137  struct brcmf_pub {
138         /* Linkage ponters */
139 @@ -100,6 +105,9 @@ struct brcmf_pub {
140         struct cfg80211_ops *ops;
141         struct brcmf_cfg80211_info *config;
142  
143 +       int num_chan_stats;
144 +       struct brcmf_chan_stats *chan_stats;
145 +
146         /* Internal brcmf items */
147         uint hdrlen;            /* Total BRCMF header length (proto + bus) */
148