Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
149 changes: 149 additions & 0 deletions drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,155 @@ brcmf_cfg80211_update_proto_addr_mode(struct wireless_dev *wdev)
*
* Return: pointer to new vif on success, ERR_PTR(-errno) if not
*/
/**
* brcmf_awdl_add_vif() - create an AWDL interface and give it a netdev.
*
* @wiphy: wiphy device of the new interface.
* @name: name of the new interface.
*
* AWDL is Apple Wireless Direct Link, the link layer AirDrop and AirPlay run
* over. BCM4387 firmware implements it and accepts BRCMF_INTERFACE_TYPE_AWDL
* through interface_create, but there is no nl80211 interface type for it, so
* this cannot go through add_virtual_intf(). It is driven from the vendor
* command instead.
*
* The vif is allocated as NL80211_IFTYPE_STATION because cfg80211 needs some
* valid type for its bookkeeping; the firmware side is what actually decides
* the interface behaviour, from the iftype passed to interface_create.
*
* Return: pointer to the new vif on success, ERR_PTR(-errno) on failure.
*/
int brcmf_awdl_add_vif(struct wiphy *wiphy, const char *name)
{
struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
struct brcmf_if *ifp = netdev_priv(cfg_to_ndev(cfg));
struct brcmf_cfg80211_vif *vif;
int err;

if (brcmf_cfg80211_vif_event_armed(cfg) || cfg->awdl_pending)
return -EBUSY;

vif = brcmf_alloc_vif(cfg, NL80211_IFTYPE_STATION);
if (IS_ERR(vif))
return PTR_ERR(vif);

/* Arm before asking firmware: the BRCMF_E_IF event is what links the
* brcmf_if to this vif (brcmf_notify_vif_event() bails with -EBADF if
* nothing is armed, leaving ndev->ieee80211_ptr unset).
*/
brcmf_cfg80211_arm_vif_event(cfg, vif);

/* Pass NULL rather than a derived address. Supplying a MAC address
* at interface_create time kills the firmware control channel about
* two seconds after create, so the address is set afterwards via
* cur_etheraddr instead.
*
*/
strscpy(cfg->awdl_ifname, name, sizeof(cfg->awdl_ifname));
cfg->awdl_pending = true;

err = brcmf_cfg80211_request_awdl_if(ifp, NULL);
if (err) {
cfg->awdl_pending = false;
brcmf_cfg80211_arm_vif_event(cfg, NULL);
brcmf_free_vif(vif);
return err;
}

/* Deliberately do NOT wait for the interface here, and do NOT attach
* the netdev. nl80211 calls vendor commands holding the wiphy mutex
* (NL80211_CMD_VENDOR sets NEED_WIPHY without NO_WIPHY_MTX), and
* register_netdev() re-enters that mutex via the netdev notifier
* chain -> cfg80211_netdev_notifier_call(). Doing it here self-
* deadlocks and wedges the RTNL for the whole system. The attach is
* done from brcmf_cfg80211_awdl_attach_pending(), which the fweh
* event worker calls while holding no locks at all.
*/
return 0;
}

/**
* brcmf_cfg80211_awdl_attach_pending() - finish AWDL interface creation.
*
* @ifp: interface the firmware just reported via BRCMF_E_IF_ADD.
*
* Called from the fweh event worker (brcmf_fweh_handle_if_event()), which
* runs on the system workqueue holding neither the RTNL nor the wiphy mutex.
* That is the only context in which register_netdev() is safe for an
* interface created outside cfg80211's own add_virtual_intf() path.
*/
void brcmf_cfg80211_awdl_attach_pending(struct brcmf_if *ifp)
{
struct brcmf_cfg80211_info *cfg = ifp->drvr->config;
struct brcmf_cfg80211_vif *vif;
int err;

if (!cfg || !cfg->awdl_pending)
return;
cfg->awdl_pending = false;
vif = ifp->vif;

if (!ifp->ndev || !vif) {
bphy_err(ifp->drvr, "AWDL if event without netdev/vif\n");
goto done;
}

/* Must be set before brcmf_net_attach(), which picks netdev_ops. */
ifp->is_awdl = true;
strscpy(ifp->ndev->name, cfg->awdl_ifname, sizeof(ifp->ndev->name));
err = brcmf_net_attach(ifp, false);
if (err) {
bphy_err(ifp->drvr, "registering AWDL netdevice failed\n");
free_netdev(ifp->ndev);
brcmf_free_vif(vif);
goto done;
}

brcmf_info("AWDL interface %s created (bsscfgidx %d)\n",
ifp->ndev->name, ifp->bsscfgidx);
done:
brcmf_cfg80211_arm_vif_event(cfg, NULL);
}

/**
* brcmf_awdl_del_vif() - tear down an interface made by brcmf_awdl_add_vif().
*
* @wiphy: wiphy device of the interface.
* @wdev: wireless device to remove.
*
* Return: 0 on success, negative errno on failure.
*/
int brcmf_awdl_del_vif(struct wiphy *wiphy, struct wireless_dev *wdev)
{
struct brcmf_cfg80211_vif *vif = container_of(wdev,
struct brcmf_cfg80211_vif,
wdev);
struct brcmf_if *ifp = vif->ifp;
int err;

/* Asymmetric with the rest of brcmfmac on purpose, for the same reason
* brcmf_awdl_add_vif() does not call brcmf_net_attach(): nl80211 calls
* vendor commands holding the wiphy mutex and NOT the RTNL
* (NL80211_CMD_VENDOR sets NEED_WIPHY without NO_WIPHY_MTX). Tearing
* the netdev down here reaches cfg80211_close_dependents(), which
* asserts the RTNL, and then deadlocks the whole netdev layer against
* any concurrent RTNL holder. Do NOT call brcmf_remove_interface() or
* arm the vif event from this context.
*
* Just ask the firmware to drop the BSS and return. The BRCMF_E_IF_DEL
* event lands in brcmf_fweh_event_worker(), which is a plain work item
* holding neither lock, and brcmf_fweh_handle_if_event() removes the
* interface from there.
*/
err = brcmf_fil_iovar_data_set(ifp, "interface_remove", NULL, 0);
if (err)
err = brcmf_fil_bsscfg_data_set(ifp, "interface_remove", NULL, 0);
if (err)
bphy_err(ifp->drvr, "interface_remove failed %d\n", err);

return err;
}

static
struct wireless_dev *brcmf_apsta_add_vif(struct wiphy *wiphy, const char *name,
struct vif_params *params,
Expand Down
5 changes: 5 additions & 0 deletions drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.h
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,8 @@ struct brcmf_cfg80211_info {
struct work_struct escan_timeout_work;
struct list_head vif_list;
struct brcmf_cfg80211_vif_event vif_event;
bool awdl_pending;
char awdl_ifname[IFNAMSIZ];
struct completion vif_disabled;
struct brcmu_d11inf d11inf;
struct brcmf_assoclist_le assoclist;
Expand Down Expand Up @@ -508,6 +510,9 @@ bool brcmf_get_vif_state_any(struct brcmf_cfg80211_info *cfg,
void brcmf_cfg80211_arm_vif_event(struct brcmf_cfg80211_info *cfg,
struct brcmf_cfg80211_vif *vif);
bool brcmf_cfg80211_vif_event_armed(struct brcmf_cfg80211_info *cfg);
int brcmf_awdl_add_vif(struct wiphy *wiphy, const char *name);
void brcmf_cfg80211_awdl_attach_pending(struct brcmf_if *ifp);
int brcmf_awdl_del_vif(struct wiphy *wiphy, struct wireless_dev *wdev);
int brcmf_cfg80211_wait_vif_event(struct brcmf_cfg80211_info *cfg,
u8 action, ulong timeout);
s32 brcmf_notify_escan_complete(struct brcmf_cfg80211_info *cfg,
Expand Down
128 changes: 124 additions & 4 deletions drivers/net/wireless/broadcom/brcm80211/brcmfmac/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <linux/module.h>
#include <linux/inetdevice.h>
#include <linux/property.h>
#include <linux/unaligned.h>
#include <net/cfg80211.h>
#include <net/rtnetlink.h>
#include <net/addrconf.h>
Expand Down Expand Up @@ -38,6 +39,17 @@

#define D11_PHY_HDR_LEN 6

/* AWDL data frames on the air are 802.3 + LLC/SNAP (OUI 00:17:f2, protocol
* 0x0800) + a 4-byte data header, then the real ethertype. The kernel only
* speaks Ethernet II, so the driver translates at the awdl0 boundary in
* both directions.
*/
#define BRCMF_AWDL_ENCAP_LEN 16
#define BRCMF_AWDL_DATA_MIN_LEN (ETH_HLEN + BRCMF_AWDL_ENCAP_LEN)

static const u8 brcmf_awdl_snap[] = { 0xaa, 0xaa, 0x03, 0x00, 0x17, 0xf2,
0x08, 0x00, 0x03, 0x04 };

struct d11rxhdr_le {
__le16 RxFrameSize;
u16 PAD;
Expand Down Expand Up @@ -290,6 +302,55 @@ static bool brcmf_skb_is_iapp(struct sk_buff *skb)
#endif
}

/* Unwrap SNAP + AWDL data header into Ethernet II, in place. skb->data is
* the 802.3 header. Frames that are not AWDL-encapsulated pass unchanged.
*/
static void brcmf_awdl_decap(struct sk_buff *skb)
{
const struct ethhdr *eh = (const struct ethhdr *)skb->data;

if (skb->len < BRCMF_AWDL_DATA_MIN_LEN ||
ntohs(eh->h_proto) > ETH_DATA_LEN ||
memcmp(skb->data + ETH_HLEN, brcmf_awdl_snap,
sizeof(brcmf_awdl_snap)))
return;

memmove(skb->data + BRCMF_AWDL_ENCAP_LEN, skb->data, 2 * ETH_ALEN);
skb_pull(skb, BRCMF_AWDL_ENCAP_LEN);
}

/* Every received data frame passes through here, on the BCDC and the msgbuf
* (PCIe) paths alike, before the kernel classifies it.
*/
__be16 brcmf_rx_eth_type_trans(struct brcmf_if *ifp, struct sk_buff *skb)
{
if (ifp->is_awdl)
brcmf_awdl_decap(skb);
return eth_type_trans(skb, ifp->ndev);
}

/* Wrap Ethernet II into 802.3 + SNAP + AWDL data header, in place. Frames
* already carrying a length field (raw AF_PACKET senders that build the
* encapsulation themselves) pass unchanged. Caller guarantees headroom.
*/
static void brcmf_awdl_encap(struct brcmf_if *ifp, struct sk_buff *skb)
{
const struct ethhdr *eh = (const struct ethhdr *)skb->data;
u8 *hdr;

if (ntohs(eh->h_proto) < ETH_P_802_3_MIN)
return;

hdr = skb_push(skb, BRCMF_AWDL_ENCAP_LEN);
memmove(hdr, hdr + BRCMF_AWDL_ENCAP_LEN, 2 * ETH_ALEN);
put_unaligned_be16(skb->len - ETH_HLEN, hdr + 2 * ETH_ALEN);
memcpy(hdr + ETH_HLEN, brcmf_awdl_snap, sizeof(brcmf_awdl_snap));
put_unaligned_le16(ifp->awdl_tx_seq++,
hdr + ETH_HLEN + sizeof(brcmf_awdl_snap));
hdr[ETH_HLEN + sizeof(brcmf_awdl_snap) + 2] = 0;
hdr[ETH_HLEN + sizeof(brcmf_awdl_snap) + 3] = 0;
}

static netdev_tx_t brcmf_netdev_start_xmit(struct sk_buff *skb,
struct net_device *ndev)
{
Expand All @@ -298,6 +359,7 @@ static netdev_tx_t brcmf_netdev_start_xmit(struct sk_buff *skb,
struct brcmf_pub *drvr = ifp->drvr;
struct ethhdr *eh;
int head_delta;
unsigned int hdrlen = drvr->hdrlen;
unsigned int tx_bytes = skb->len;

brcmf_dbg(DATA, "Enter, bsscfgidx=%d\n", ifp->bsscfgidx);
Expand Down Expand Up @@ -328,9 +390,12 @@ static netdev_tx_t brcmf_netdev_start_xmit(struct sk_buff *skb,
goto done;
}

if (ifp->is_awdl)
hdrlen += BRCMF_AWDL_ENCAP_LEN;

/* Make sure there's enough writeable headroom */
if (skb_headroom(skb) < drvr->hdrlen || skb_header_cloned(skb)) {
head_delta = max_t(int, drvr->hdrlen - skb_headroom(skb), 0);
if (skb_headroom(skb) < hdrlen || skb_header_cloned(skb)) {
head_delta = max_t(int, hdrlen - skb_headroom(skb), 0);

brcmf_dbg(INFO, "%s: %s headroom\n", brcmf_ifname(ifp),
head_delta ? "insufficient" : "unmodifiable");
Expand Down Expand Up @@ -365,6 +430,9 @@ static netdev_tx_t brcmf_netdev_start_xmit(struct sk_buff *skb,
/* set pacing shift for packet aggregation */
sk_pacing_shift_update(skb->sk, 8);

if (ifp->is_awdl)
brcmf_awdl_encap(ifp, skb);

ret = brcmf_proto_tx_queue_data(drvr, ifp->ifidx, skb);
if (ret < 0)
brcmf_txfinalize(ifp, skb, false);
Expand Down Expand Up @@ -495,7 +563,7 @@ static int brcmf_rx_hdrpull(struct brcmf_pub *drvr, struct sk_buff *skb,
return -ENODATA;
}

skb->protocol = eth_type_trans(skb, (*ifp)->ndev);
skb->protocol = brcmf_rx_eth_type_trans(*ifp, skb);
return 0;
}

Expand Down Expand Up @@ -632,6 +700,55 @@ static int brcmf_netdev_open(struct net_device *ndev)
return 0;
}

/* AWDL interfaces are not STAs. brcmf_netdev_open() runs the standard station
* bring-up -- a toe_ol query, brcmf_cfg80211_up(), then the multicast and
* promisc configuration driven by ndo_set_rx_mode -- and issuing those against
* an AWDL bsscfg stops the firmware answering dcmds at all: every subsequent
* command times out and only a brcmfmac reload recovers it. Bring the netdev
* up without touching firmware, and deliberately omit ndo_set_rx_mode so the
* multicast worker never runs for these interfaces.
*/
static int brcmf_netdev_open_awdl(struct net_device *ndev)
{
struct brcmf_if *ifp = netdev_priv(ndev);
struct brcmf_pub *drvr = ifp->drvr;
struct brcmf_bus *bus_if = drvr->bus_if;

brcmf_dbg(TRACE, "Enter, bsscfgidx=%d (AWDL)\n", ifp->bsscfgidx);

if (bus_if->state != BRCMF_BUS_UP) {
bphy_err(drvr, "failed bus is not ready\n");
return -EAGAIN;
}

atomic_set(&ifp->pend_8021x_cnt, 0);

/* Carrier stays off until AWDL is actually running. */
netif_carrier_off(ndev);
return 0;
}

static int brcmf_netdev_stop_awdl(struct net_device *ndev)
{
struct brcmf_if *ifp = netdev_priv(ndev);

brcmf_dbg(TRACE, "Enter, bsscfgidx=%d (AWDL)\n", ifp->bsscfgidx);

/* No brcmf_cfg80211_down(): this vif was never brought up through
* cfg80211, and tearing down the STA state would hit the same
* unresponsive-firmware path as the bring-up.
*/
brcmf_net_setcarrier(ifp, false);
return 0;
}

static const struct net_device_ops brcmf_netdev_ops_awdl = {
.ndo_open = brcmf_netdev_open_awdl,
.ndo_stop = brcmf_netdev_stop_awdl,
.ndo_start_xmit = brcmf_netdev_start_xmit,
.ndo_set_mac_address = brcmf_netdev_set_mac_address,
};

static const struct net_device_ops brcmf_netdev_ops_pri = {
.ndo_open = brcmf_netdev_open,
.ndo_stop = brcmf_netdev_stop,
Expand All @@ -651,9 +768,12 @@ int brcmf_net_attach(struct brcmf_if *ifp, bool locked)
ndev = ifp->ndev;

/* set appropriate operations */
ndev->netdev_ops = &brcmf_netdev_ops_pri;
ndev->netdev_ops = ifp->is_awdl ? &brcmf_netdev_ops_awdl
: &brcmf_netdev_ops_pri;

ndev->needed_headroom += drvr->hdrlen;
if (ifp->is_awdl)
ndev->needed_headroom += BRCMF_AWDL_ENCAP_LEN;
ndev->ethtool_ops = &brcmf_ethtool_ops;

/* set the mac address & netns */
Expand Down
5 changes: 5 additions & 0 deletions drivers/net/wireless/broadcom/brcm80211/brcmfmac/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,8 @@ enum brcmf_netif_stop_reason {
* @pend_8021x_cnt: tracks outstanding number of 802.1x frames.
* @pend_8021x_wait: used for signalling change in count.
* @fwil_fwerr: flag indicating fwil layer should return firmware error codes.
* @is_awdl: interface carries AWDL data frames (SNAP + AWDL data header).
* @awdl_tx_seq: sequence number written into the AWDL data header on TX.
*/
struct brcmf_if {
struct brcmf_pub *drvr;
Expand All @@ -268,6 +270,8 @@ struct brcmf_if {
struct in6_addr ipv6_addr_tbl[NDOL_MAX_ENTRIES];
u8 ipv6addr_idx;
bool fwil_fwerr;
bool is_awdl;
u16 awdl_tx_seq;
};

int brcmf_netdev_wait_pend8021x(struct brcmf_if *ifp);
Expand All @@ -284,6 +288,7 @@ void brcmf_txflowblock_if(struct brcmf_if *ifp,
enum brcmf_netif_stop_reason reason, bool state);
void brcmf_txfinalize(struct brcmf_if *ifp, struct sk_buff *txp, bool success);
void brcmf_netif_rx(struct brcmf_if *ifp, struct sk_buff *skb);
__be16 brcmf_rx_eth_type_trans(struct brcmf_if *ifp, struct sk_buff *skb);
void brcmf_netif_mon_rx(struct brcmf_if *ifp, struct sk_buff *skb);
void brcmf_net_detach(struct net_device *ndev, bool locked);
int brcmf_net_mon_attach(struct brcmf_if *ifp);
Expand Down
Loading