mac80211: add pending brcmfmac patches fixing multiple interfaces
[openwrt.git] / package / kernel / mac80211 / patches / 319-brcmfmac-consolidate-ifp-lookup-in-driver-core.patch
1 From: Arend van Spriel <arend@broadcom.com>
2 Date: Wed, 26 Aug 2015 22:14:53 +0200
3 Subject: [PATCH] brcmfmac: consolidate ifp lookup in driver core
4
5 In rx path the firmware provide an interface index which is used to
6 map to a struct brcmf_if instance. However, this involves some trick
7 that is done in two places. This is changed by having driver core
8 providing brcmf_get_ifp() function.
9
10 Reviewed-by: Hante Meuleman <meuleman@broadcom.com>
11 Reviewed-by: Franky (Zhenhui) Lin <frankyl@broadcom.com>
12 Reviewed-by: Pieter-Paul Giesberts <pieterpg@broadcom.com>
13 Signed-off-by: Arend van Spriel <arend@broadcom.com>
14 ---
15
16 --- a/drivers/net/wireless/brcm80211/brcmfmac/bcdc.c
17 +++ b/drivers/net/wireless/brcm80211/brcmfmac/bcdc.c
18 @@ -276,6 +276,7 @@ brcmf_proto_bcdc_hdrpull(struct brcmf_pu
19                          struct sk_buff *pktbuf)
20  {
21         struct brcmf_proto_bcdc_header *h;
22 +       struct brcmf_if *ifp;
23  
24         brcmf_dbg(BCDC, "Enter\n");
25  
26 @@ -289,30 +290,21 @@ brcmf_proto_bcdc_hdrpull(struct brcmf_pu
27         trace_brcmf_bcdchdr(pktbuf->data);
28         h = (struct brcmf_proto_bcdc_header *)(pktbuf->data);
29  
30 -       *ifidx = BCDC_GET_IF_IDX(h);
31 -       if (*ifidx >= BRCMF_MAX_IFS) {
32 -               brcmf_err("rx data ifnum out of range (%d)\n", *ifidx);
33 +       ifp = brcmf_get_ifp(drvr, BCDC_GET_IF_IDX(h));
34 +       if (IS_ERR_OR_NULL(ifp)) {
35 +               brcmf_dbg(INFO, "no matching ifp found\n");
36                 return -EBADE;
37         }
38 -       /* The ifidx is the idx to map to matching netdev/ifp. When receiving
39 -        * events this is easy because it contains the bssidx which maps
40 -        * 1-on-1 to the netdev/ifp. But for data frames the ifidx is rcvd.
41 -        * bssidx 1 is used for p2p0 and no data can be received or
42 -        * transmitted on it. Therefor bssidx is ifidx + 1 if ifidx > 0
43 -        */
44 -       if (*ifidx)
45 -               (*ifidx)++;
46 -
47         if (((h->flags & BCDC_FLAG_VER_MASK) >> BCDC_FLAG_VER_SHIFT) !=
48             BCDC_PROTO_VER) {
49                 brcmf_err("%s: non-BCDC packet received, flags 0x%x\n",
50 -                         brcmf_ifname(drvr, *ifidx), h->flags);
51 +                         brcmf_ifname(drvr, ifp->ifidx), h->flags);
52                 return -EBADE;
53         }
54  
55         if (h->flags & BCDC_FLAG_SUM_GOOD) {
56                 brcmf_dbg(BCDC, "%s: BDC rcv, good checksum, flags 0x%x\n",
57 -                         brcmf_ifname(drvr, *ifidx), h->flags);
58 +                         brcmf_ifname(drvr, ifp->ifidx), h->flags);
59                 pktbuf->ip_summed = CHECKSUM_UNNECESSARY;
60         }
61  
62 @@ -320,12 +312,15 @@ brcmf_proto_bcdc_hdrpull(struct brcmf_pu
63  
64         skb_pull(pktbuf, BCDC_HEADER_LEN);
65         if (do_fws)
66 -               brcmf_fws_hdrpull(drvr, *ifidx, h->data_offset << 2, pktbuf);
67 +               brcmf_fws_hdrpull(drvr, ifp->ifidx, h->data_offset << 2,
68 +                                 pktbuf);
69         else
70                 skb_pull(pktbuf, h->data_offset << 2);
71  
72         if (pktbuf->len == 0)
73                 return -ENODATA;
74 +
75 +       *ifidx = ifp->ifidx;
76         return 0;
77  }
78  
79 --- a/drivers/net/wireless/brcm80211/brcmfmac/core.c
80 +++ b/drivers/net/wireless/brcm80211/brcmfmac/core.c
81 @@ -83,6 +83,25 @@ char *brcmf_ifname(struct brcmf_pub *drv
82         return "<if_none>";
83  }
84  
85 +struct brcmf_if *brcmf_get_ifp(struct brcmf_pub *drvr, int ifidx)
86 +{
87 +       if (ifidx < 0 || ifidx >= BRCMF_MAX_IFS) {
88 +               brcmf_err("ifidx %d out of range\n", ifidx);
89 +               return ERR_PTR(-ERANGE);
90 +       }
91 +
92 +       /* The ifidx is the idx to map to matching netdev/ifp. When receiving
93 +        * events this is easy because it contains the bssidx which maps
94 +        * 1-on-1 to the netdev/ifp. But for data frames the ifidx is rcvd.
95 +        * bssidx 1 is used for p2p0 and no data can be received or
96 +        * transmitted on it. Therefor bssidx is ifidx + 1 if ifidx > 0
97 +        */
98 +       if (ifidx)
99 +               ifidx++;
100 +
101 +       return drvr->iflist[ifidx];
102 +}
103 +
104  static void _brcmf_set_multicast_list(struct work_struct *work)
105  {
106         struct brcmf_if *ifp;
107 --- a/drivers/net/wireless/brcm80211/brcmfmac/core.h
108 +++ b/drivers/net/wireless/brcm80211/brcmfmac/core.h
109 @@ -202,7 +202,7 @@ int brcmf_netdev_wait_pend8021x(struct b
110  
111  /* Return pointer to interface name */
112  char *brcmf_ifname(struct brcmf_pub *drvr, int idx);
113 -
114 +struct brcmf_if *brcmf_get_ifp(struct brcmf_pub *drvr, int ifidx);
115  int brcmf_net_attach(struct brcmf_if *ifp, bool rtnl_locked);
116  struct brcmf_if *brcmf_add_if(struct brcmf_pub *drvr, s32 bssidx, s32 ifidx,
117                               char *name, u8 *mac_addr);
118 --- a/drivers/net/wireless/brcm80211/brcmfmac/msgbuf.c
119 +++ b/drivers/net/wireless/brcm80211/brcmfmac/msgbuf.c
120 @@ -1081,16 +1081,8 @@ brcmf_msgbuf_rx_skb(struct brcmf_msgbuf
121  {
122         struct brcmf_if *ifp;
123  
124 -       /* The ifidx is the idx to map to matching netdev/ifp. When receiving
125 -        * events this is easy because it contains the bssidx which maps
126 -        * 1-on-1 to the netdev/ifp. But for data frames the ifidx is rcvd.
127 -        * bssidx 1 is used for p2p0 and no data can be received or
128 -        * transmitted on it. Therefor bssidx is ifidx + 1 if ifidx > 0
129 -        */
130 -       if (ifidx)
131 -               (ifidx)++;
132 -       ifp = msgbuf->drvr->iflist[ifidx];
133 -       if (!ifp || !ifp->ndev) {
134 +       ifp = brcmf_get_ifp(msgbuf->drvr, ifidx);
135 +       if (IS_ERR_OR_NULL(ifp) || !ifp->ndev) {
136                 brcmf_err("Received pkt for invalid ifidx %d\n", ifidx);
137                 brcmu_pkt_buf_free_skb(skb);
138                 return;