Skip to content

Commit 856d5a0

Browse files
Arend Van SprielKalle Valo
authored andcommitted
brcmfmac: allocate struct brcmf_pub instance using wiphy_new()
Rework the driver so the wiphy instance holds the main driver information in its private buffer. Previously it held struct brcmf_cfg80211_info instance so a bit of reorg was needed. This was done so that the wiphy name or its parent device can be shown in debug output. Reviewed-by: Hante Meuleman <[email protected]> Reviewed-by: Pieter-Paul Giesberts <[email protected]> Reviewed-by: Franky Lin <[email protected]> Signed-off-by: Arend van Spriel <[email protected]> Signed-off-by: Kalle Valo <[email protected]>
1 parent c88cfa0 commit 856d5a0

File tree

7 files changed

+76
-61
lines changed

7 files changed

+76
-61
lines changed

drivers/net/wireless/broadcom/brcm80211/brcmfmac/btcoex.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ static void brcmf_btcoex_dhcp_end(struct brcmf_btcoex_info *btci)
462462
int brcmf_btcoex_set_mode(struct brcmf_cfg80211_vif *vif,
463463
enum brcmf_btcoex_mode mode, u16 duration)
464464
{
465-
struct brcmf_cfg80211_info *cfg = wiphy_priv(vif->wdev.wiphy);
465+
struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(vif->wdev.wiphy);
466466
struct brcmf_btcoex_info *btci = cfg->btcoex;
467467
struct brcmf_if *ifp = brcmf_get_ifp(cfg->pub, 0);
468468

drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c

Lines changed: 40 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -753,7 +753,7 @@ s32 brcmf_notify_escan_complete(struct brcmf_cfg80211_info *cfg,
753753
static int brcmf_cfg80211_del_ap_iface(struct wiphy *wiphy,
754754
struct wireless_dev *wdev)
755755
{
756-
struct brcmf_cfg80211_info *cfg = wiphy_priv(wiphy);
756+
struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
757757
struct net_device *ndev = wdev->netdev;
758758
struct brcmf_if *ifp = netdev_priv(ndev);
759759
int ret;
@@ -786,7 +786,7 @@ static int brcmf_cfg80211_del_ap_iface(struct wiphy *wiphy,
786786
static
787787
int brcmf_cfg80211_del_iface(struct wiphy *wiphy, struct wireless_dev *wdev)
788788
{
789-
struct brcmf_cfg80211_info *cfg = wiphy_priv(wiphy);
789+
struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
790790
struct net_device *ndev = wdev->netdev;
791791

792792
if (ndev && ndev == cfg_to_ndev(cfg))
@@ -831,7 +831,7 @@ brcmf_cfg80211_change_iface(struct wiphy *wiphy, struct net_device *ndev,
831831
enum nl80211_iftype type,
832832
struct vif_params *params)
833833
{
834-
struct brcmf_cfg80211_info *cfg = wiphy_priv(wiphy);
834+
struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
835835
struct brcmf_if *ifp = netdev_priv(ndev);
836836
struct brcmf_cfg80211_vif *vif = ifp->vif;
837837
s32 infra = 0;
@@ -2127,17 +2127,15 @@ static s32
21272127
brcmf_cfg80211_get_tx_power(struct wiphy *wiphy, struct wireless_dev *wdev,
21282128
s32 *dbm)
21292129
{
2130-
struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
2131-
struct net_device *ndev = cfg_to_ndev(cfg);
2132-
struct brcmf_if *ifp = netdev_priv(ndev);
2130+
struct brcmf_cfg80211_vif *vif = wdev_to_vif(wdev);
21332131
s32 qdbm = 0;
21342132
s32 err;
21352133

21362134
brcmf_dbg(TRACE, "Enter\n");
2137-
if (!check_vif_up(ifp->vif))
2135+
if (!check_vif_up(vif))
21382136
return -EIO;
21392137

2140-
err = brcmf_fil_iovar_int_get(ifp, "qtxpower", &qdbm);
2138+
err = brcmf_fil_iovar_int_get(vif->ifp, "qtxpower", &qdbm);
21412139
if (err) {
21422140
brcmf_err("error (%d)\n", err);
21432141
goto done;
@@ -3358,7 +3356,7 @@ brcmf_cfg80211_sched_scan_start(struct wiphy *wiphy,
33583356
struct cfg80211_sched_scan_request *req)
33593357
{
33603358
struct brcmf_if *ifp = netdev_priv(ndev);
3361-
struct brcmf_cfg80211_info *cfg = wiphy_priv(wiphy);
3359+
struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
33623360

33633361
brcmf_dbg(SCAN, "Enter: n_match_sets=%d n_ssids=%d\n",
33643362
req->n_match_sets, req->n_ssids);
@@ -5190,6 +5188,12 @@ static struct cfg80211_ops brcmf_cfg80211_ops = {
51905188
.del_pmk = brcmf_cfg80211_del_pmk,
51915189
};
51925190

5191+
struct cfg80211_ops *brcmf_cfg80211_get_ops(void)
5192+
{
5193+
return kmemdup(&brcmf_cfg80211_ops, sizeof(brcmf_cfg80211_ops),
5194+
GFP_KERNEL);
5195+
}
5196+
51935197
struct brcmf_cfg80211_vif *brcmf_alloc_vif(struct brcmf_cfg80211_info *cfg,
51945198
enum nl80211_iftype type)
51955199
{
@@ -5897,7 +5901,7 @@ static void brcmf_update_bw40_channel_flag(struct ieee80211_channel *channel,
58975901
static int brcmf_construct_chaninfo(struct brcmf_cfg80211_info *cfg,
58985902
u32 bw_cap[])
58995903
{
5900-
struct brcmf_if *ifp = netdev_priv(cfg_to_ndev(cfg));
5904+
struct brcmf_if *ifp = brcmf_get_ifp(cfg->pub, 0);
59015905
struct ieee80211_supported_band *band;
59025906
struct ieee80211_channel *channel;
59035907
struct wiphy *wiphy;
@@ -6012,7 +6016,7 @@ static int brcmf_construct_chaninfo(struct brcmf_cfg80211_info *cfg,
60126016

60136017
static int brcmf_enable_bw40_2g(struct brcmf_cfg80211_info *cfg)
60146018
{
6015-
struct brcmf_if *ifp = netdev_priv(cfg_to_ndev(cfg));
6019+
struct brcmf_if *ifp = brcmf_get_ifp(cfg->pub, 0);
60166020
struct ieee80211_supported_band *band;
60176021
struct brcmf_fil_bwcap_le band_bwcap;
60186022
struct brcmf_chanspec_list *list;
@@ -6197,10 +6201,10 @@ static void brcmf_update_vht_cap(struct ieee80211_supported_band *band,
61976201
}
61986202
}
61996203

6200-
static int brcmf_setup_wiphybands(struct wiphy *wiphy)
6204+
static int brcmf_setup_wiphybands(struct brcmf_cfg80211_info *cfg)
62016205
{
6202-
struct brcmf_cfg80211_info *cfg = wiphy_priv(wiphy);
6203-
struct brcmf_if *ifp = netdev_priv(cfg_to_ndev(cfg));
6206+
struct brcmf_if *ifp = brcmf_get_ifp(cfg->pub, 0);
6207+
struct wiphy *wiphy;
62046208
u32 nmode = 0;
62056209
u32 vhtmode = 0;
62066210
u32 bw_cap[2] = { WLC_BW_20MHZ_BIT, WLC_BW_20MHZ_BIT };
@@ -6794,8 +6798,8 @@ static s32 brcmf_translate_country_code(struct brcmf_pub *drvr, char alpha2[2],
67946798
static void brcmf_cfg80211_reg_notifier(struct wiphy *wiphy,
67956799
struct regulatory_request *req)
67966800
{
6797-
struct brcmf_cfg80211_info *cfg = wiphy_priv(wiphy);
6798-
struct brcmf_if *ifp = netdev_priv(cfg_to_ndev(cfg));
6801+
struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
6802+
struct brcmf_if *ifp = brcmf_get_ifp(cfg->pub, 0);
67996803
struct brcmf_fil_country_le ccreq;
68006804
s32 err;
68016805
int i;
@@ -6830,7 +6834,7 @@ static void brcmf_cfg80211_reg_notifier(struct wiphy *wiphy,
68306834
brcmf_err("Firmware rejected country setting\n");
68316835
return;
68326836
}
6833-
brcmf_setup_wiphybands(wiphy);
6837+
brcmf_setup_wiphybands(cfg);
68346838
}
68356839

68366840
static void brcmf_free_wiphy(struct wiphy *wiphy)
@@ -6857,17 +6861,15 @@ static void brcmf_free_wiphy(struct wiphy *wiphy)
68576861
if (wiphy->wowlan != &brcmf_wowlan_support)
68586862
kfree(wiphy->wowlan);
68596863
#endif
6860-
wiphy_free(wiphy);
68616864
}
68626865

68636866
struct brcmf_cfg80211_info *brcmf_cfg80211_attach(struct brcmf_pub *drvr,
6864-
struct device *busdev,
6867+
struct cfg80211_ops *ops,
68656868
bool p2pdev_forced)
68666869
{
6870+
struct wiphy *wiphy = drvr->wiphy;
68676871
struct net_device *ndev = brcmf_get_ifp(drvr, 0)->ndev;
68686872
struct brcmf_cfg80211_info *cfg;
6869-
struct wiphy *wiphy;
6870-
struct cfg80211_ops *ops;
68716873
struct brcmf_cfg80211_vif *vif;
68726874
struct brcmf_if *ifp;
68736875
s32 err = 0;
@@ -6879,26 +6881,13 @@ struct brcmf_cfg80211_info *brcmf_cfg80211_attach(struct brcmf_pub *drvr,
68796881
return NULL;
68806882
}
68816883

6882-
ops = kmemdup(&brcmf_cfg80211_ops, sizeof(*ops), GFP_KERNEL);
6883-
if (!ops)
6884-
return NULL;
6885-
6886-
ifp = netdev_priv(ndev);
6887-
#ifdef CONFIG_PM
6888-
if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_WOWL_GTK))
6889-
ops->set_rekey_data = brcmf_cfg80211_set_rekey_data;
6890-
#endif
6891-
wiphy = wiphy_new(ops, sizeof(struct brcmf_cfg80211_info));
6892-
if (!wiphy) {
6884+
cfg = kzalloc(sizeof(*cfg), GFP_KERNEL);
6885+
if (!cfg) {
68936886
brcmf_err("Could not allocate wiphy device\n");
6894-
goto ops_out;
6887+
return NULL;
68956888
}
6896-
memcpy(wiphy->perm_addr, drvr->mac, ETH_ALEN);
6897-
set_wiphy_dev(wiphy, busdev);
68986889

6899-
cfg = wiphy_priv(wiphy);
69006890
cfg->wiphy = wiphy;
6901-
cfg->ops = ops;
69026891
cfg->pub = drvr;
69036892
init_vif_event(&cfg->vif_event);
69046893
INIT_LIST_HEAD(&cfg->vif_list);
@@ -6907,6 +6896,7 @@ struct brcmf_cfg80211_info *brcmf_cfg80211_attach(struct brcmf_pub *drvr,
69076896
if (IS_ERR(vif))
69086897
goto wiphy_out;
69096898

6899+
ifp = netdev_priv(ndev);
69106900
vif->ifp = ifp;
69116901
vif->wdev.netdev = ndev;
69126902
ndev->ieee80211_ptr = &vif->wdev;
@@ -6933,6 +6923,11 @@ struct brcmf_cfg80211_info *brcmf_cfg80211_attach(struct brcmf_pub *drvr,
69336923
if (err < 0)
69346924
goto priv_out;
69356925

6926+
/* regulatory notifer below needs access to cfg so
6927+
* assign it now.
6928+
*/
6929+
drvr->config = cfg;
6930+
69366931
brcmf_dbg(INFO, "Registering custom regulatory\n");
69376932
wiphy->reg_notifier = brcmf_cfg80211_reg_notifier;
69386933
wiphy->regulatory_flags |= REGULATORY_CUSTOM_REG;
@@ -6946,13 +6941,17 @@ struct brcmf_cfg80211_info *brcmf_cfg80211_attach(struct brcmf_pub *drvr,
69466941
cap = &wiphy->bands[NL80211_BAND_2GHZ]->ht_cap.cap;
69476942
*cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
69486943
}
6944+
#ifdef CONFIG_PM
6945+
if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_WOWL_GTK))
6946+
ops->set_rekey_data = brcmf_cfg80211_set_rekey_data;
6947+
#endif
69496948
err = wiphy_register(wiphy);
69506949
if (err < 0) {
69516950
brcmf_err("Could not register wiphy device (%d)\n", err);
69526951
goto priv_out;
69536952
}
69546953

6955-
err = brcmf_setup_wiphybands(wiphy);
6954+
err = brcmf_setup_wiphybands(cfg);
69566955
if (err) {
69576956
brcmf_err("Setting wiphy bands failed (%d)\n", err);
69586957
goto wiphy_unreg_out;
@@ -6969,12 +6968,7 @@ struct brcmf_cfg80211_info *brcmf_cfg80211_attach(struct brcmf_pub *drvr,
69696968
else
69706969
*cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
69716970
}
6972-
/* p2p might require that "if-events" get processed by fweh. So
6973-
* activate the already registered event handlers now and activate
6974-
* the rest when initialization has completed. drvr->config needs to
6975-
* be assigned before activating events.
6976-
*/
6977-
drvr->config = cfg;
6971+
69786972
err = brcmf_fweh_activate_events(ifp);
69796973
if (err) {
69806974
brcmf_err("FWEH activation failed (%d)\n", err);
@@ -7042,8 +7036,7 @@ struct brcmf_cfg80211_info *brcmf_cfg80211_attach(struct brcmf_pub *drvr,
70427036
ifp->vif = NULL;
70437037
wiphy_out:
70447038
brcmf_free_wiphy(wiphy);
7045-
ops_out:
7046-
kfree(ops);
7039+
kfree(cfg);
70477040
return NULL;
70487041
}
70497042

@@ -7058,4 +7051,5 @@ void brcmf_cfg80211_detach(struct brcmf_cfg80211_info *cfg)
70587051
kfree(cfg->ops);
70597052
wl_deinit_priv(cfg);
70607053
brcmf_free_wiphy(cfg->wiphy);
7054+
kfree(cfg);
70617055
}

drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.h

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -355,20 +355,24 @@ static inline struct wiphy *cfg_to_wiphy(struct brcmf_cfg80211_info *cfg)
355355

356356
static inline struct brcmf_cfg80211_info *wiphy_to_cfg(struct wiphy *w)
357357
{
358-
return (struct brcmf_cfg80211_info *)(wiphy_priv(w));
358+
struct brcmf_pub *drvr = wiphy_priv(w);
359+
return drvr->config;
359360
}
360361

361362
static inline struct brcmf_cfg80211_info *wdev_to_cfg(struct wireless_dev *wd)
362363
{
363-
return (struct brcmf_cfg80211_info *)(wdev_priv(wd));
364+
return wiphy_to_cfg(wd->wiphy);
365+
}
366+
367+
static inline struct brcmf_cfg80211_vif *wdev_to_vif(struct wireless_dev *wdev)
368+
{
369+
return container_of(wdev, struct brcmf_cfg80211_vif, wdev);
364370
}
365371

366372
static inline
367373
struct net_device *cfg_to_ndev(struct brcmf_cfg80211_info *cfg)
368374
{
369-
struct brcmf_cfg80211_vif *vif;
370-
vif = list_first_entry(&cfg->vif_list, struct brcmf_cfg80211_vif, list);
371-
return vif->wdev.netdev;
375+
return brcmf_get_ifp(cfg->pub, 0)->ndev;
372376
}
373377

374378
static inline struct brcmf_cfg80211_info *ndev_to_cfg(struct net_device *ndev)
@@ -395,11 +399,12 @@ brcmf_cfg80211_connect_info *cfg_to_conn(struct brcmf_cfg80211_info *cfg)
395399
}
396400

397401
struct brcmf_cfg80211_info *brcmf_cfg80211_attach(struct brcmf_pub *drvr,
398-
struct device *busdev,
402+
struct cfg80211_ops *ops,
399403
bool p2pdev_forced);
400404
void brcmf_cfg80211_detach(struct brcmf_cfg80211_info *cfg);
401405
s32 brcmf_cfg80211_up(struct net_device *ndev);
402406
s32 brcmf_cfg80211_down(struct net_device *ndev);
407+
struct cfg80211_ops *brcmf_cfg80211_get_ops(void);
403408
enum nl80211_iftype brcmf_cfg80211_get_iftype(struct brcmf_if *ifp);
404409

405410
struct brcmf_cfg80211_vif *brcmf_alloc_vif(struct brcmf_cfg80211_info *cfg,

drivers/net/wireless/broadcom/brcm80211/brcmfmac/common.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,7 @@ int brcmf_c_preinit_dcmds(struct brcmf_if *ifp)
248248
brcmf_err("Retreiving cur_etheraddr failed, %d\n", err);
249249
goto done;
250250
}
251+
memcpy(ifp->drvr->wiphy->perm_addr, ifp->drvr->mac, ETH_ALEN);
251252
memcpy(ifp->drvr->mac, ifp->mac_addr, sizeof(ifp->drvr->mac));
252253

253254
bus = ifp->drvr->bus_if;
@@ -275,6 +276,7 @@ int brcmf_c_preinit_dcmds(struct brcmf_if *ifp)
275276
ri->chippkg = le32_to_cpu(revinfo.chippkg);
276277
ri->nvramrev = le32_to_cpu(revinfo.nvramrev);
277278

279+
/* use revinfo if not known yet */
278280
if (!bus->chip) {
279281
bus->chip = le32_to_cpu(revinfo.chipnum);
280282
bus->chiprev = le32_to_cpu(revinfo.chiprev);

drivers/net/wireless/broadcom/brcm80211/brcmfmac/core.c

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -943,7 +943,7 @@ static int brcmf_revinfo_read(struct seq_file *s, void *data)
943943
return 0;
944944
}
945945

946-
static int brcmf_bus_started(struct brcmf_pub *drvr)
946+
static int brcmf_bus_started(struct brcmf_pub *drvr, struct cfg80211_ops *ops)
947947
{
948948
int ret = -1;
949949
struct brcmf_bus *bus_if = drvr->bus_if;
@@ -982,7 +982,7 @@ static int brcmf_bus_started(struct brcmf_pub *drvr)
982982

983983
brcmf_proto_add_if(drvr, ifp);
984984

985-
drvr->config = brcmf_cfg80211_attach(drvr, bus_if->dev,
985+
drvr->config = brcmf_cfg80211_attach(drvr, ops,
986986
drvr->settings->p2p_enable);
987987
if (drvr->config == NULL) {
988988
ret = -ENOMEM;
@@ -1037,17 +1037,26 @@ static int brcmf_bus_started(struct brcmf_pub *drvr)
10371037

10381038
int brcmf_attach(struct device *dev, struct brcmf_mp_device *settings)
10391039
{
1040+
struct wiphy *wiphy;
1041+
struct cfg80211_ops *ops;
10401042
struct brcmf_pub *drvr = NULL;
10411043
int ret = 0;
10421044
int i;
10431045

10441046
brcmf_dbg(TRACE, "Enter\n");
10451047

1046-
/* Allocate primary brcmf_info */
1047-
drvr = kzalloc(sizeof(*drvr), GFP_ATOMIC);
1048-
if (!drvr)
1048+
ops = brcmf_cfg80211_get_ops();
1049+
if (!ops)
10491050
return -ENOMEM;
10501051

1052+
wiphy = wiphy_new(ops, sizeof(*drvr));
1053+
if (!wiphy)
1054+
return -ENOMEM;
1055+
1056+
set_wiphy_dev(wiphy, dev);
1057+
drvr = wiphy_priv(wiphy);
1058+
drvr->wiphy = wiphy;
1059+
10511060
for (i = 0; i < ARRAY_SIZE(drvr->if2bss); i++)
10521061
drvr->if2bss[i] = BRCMF_BSSIDX_INVALID;
10531062

@@ -1076,15 +1085,18 @@ int brcmf_attach(struct device *dev, struct brcmf_mp_device *settings)
10761085
/* attach firmware event handler */
10771086
brcmf_fweh_attach(drvr);
10781087

1079-
ret = brcmf_bus_started(drvr);
1088+
ret = brcmf_bus_started(drvr, ops);
10801089
if (ret != 0) {
10811090
brcmf_err("dongle is not responding: err=%d\n", ret);
10821091
goto fail;
10831092
}
1093+
1094+
drvr->config->ops = ops;
10841095
return 0;
10851096

10861097
fail:
10871098
brcmf_detach(dev);
1099+
kfree(ops);
10881100

10891101
return ret;
10901102
}
@@ -1142,14 +1154,15 @@ void brcmf_detach(struct device *dev)
11421154
brcmf_remove_interface(drvr->iflist[i], false);
11431155

11441156
brcmf_cfg80211_detach(drvr->config);
1157+
drvr->config = NULL;
11451158

11461159
brcmf_bus_stop(drvr->bus_if);
11471160

11481161
brcmf_proto_detach(drvr);
11491162

11501163
brcmf_debug_detach(drvr);
11511164
bus_if->drvr = NULL;
1152-
kfree(drvr);
1165+
wiphy_free(drvr->wiphy);
11531166
}
11541167

11551168
s32 brcmf_iovar_data_set(struct device *dev, char *name, void *data, u32 len)

0 commit comments

Comments
 (0)