e0b2c7dd2124b24e7ccbf13923e6b8bee124a949
[oweals/openwrt.git] /
1 From 450914c39f88d1adada26256360dea7050ff4e83 Mon Sep 17 00:00:00 2001
2 From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= <rafal@milecki.pl>
3 Date: Tue, 3 Sep 2019 06:29:27 +0200
4 Subject: [PATCH 2/3] brcmfmac: split brcmf_attach() and brcmf_detach()
5  functions
6 MIME-Version: 1.0
7 Content-Type: text/plain; charset=UTF-8
8 Content-Transfer-Encoding: 8bit
9
10 Move code allocating/freeing wiphy out of above functions. This will
11 allow reinitializing the driver (e.g. on some error) without allocating
12 a new wiphy.
13
14 Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
15 Acked-by: Arend van Spriel <arend.vanspriel@broadcom.com>
16 Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
17 ---
18  .../broadcom/brcm80211/brcmfmac/bus.h         |  4 ++-
19  .../broadcom/brcm80211/brcmfmac/core.c        | 33 ++++++++++++++----
20  .../broadcom/brcm80211/brcmfmac/pcie.c        | 13 +++++--
21  .../broadcom/brcm80211/brcmfmac/sdio.c        | 15 ++++++--
22  .../broadcom/brcm80211/brcmfmac/usb.c         | 34 +++++++++++++++----
23  5 files changed, 80 insertions(+), 19 deletions(-)
24
25 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bus.h
26 +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bus.h
27 @@ -254,10 +254,12 @@ void brcmf_rx_frame(struct device *dev,
28  /* Receive async event packet from firmware. Callee disposes of rxp. */
29  void brcmf_rx_event(struct device *dev, struct sk_buff *rxp);
30  
31 +int brcmf_alloc(struct device *dev, struct brcmf_mp_device *settings);
32  /* Indication from bus module regarding presence/insertion of dongle. */
33 -int brcmf_attach(struct device *dev, struct brcmf_mp_device *settings);
34 +int brcmf_attach(struct device *dev);
35  /* Indication from bus module regarding removal/absence of dongle */
36  void brcmf_detach(struct device *dev);
37 +void brcmf_free(struct device *dev);
38  /* Indication from bus module that dongle should be reset */
39  void brcmf_dev_reset(struct device *dev);
40  /* Request from bus module to initiate a coredump */
41 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/core.c
42 +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/core.c
43 @@ -1230,13 +1230,11 @@ fail:
44         return ret;
45  }
46  
47 -int brcmf_attach(struct device *dev, struct brcmf_mp_device *settings)
48 +int brcmf_alloc(struct device *dev, struct brcmf_mp_device *settings)
49  {
50         struct wiphy *wiphy;
51         struct cfg80211_ops *ops;
52         struct brcmf_pub *drvr = NULL;
53 -       int ret = 0;
54 -       int i;
55  
56         brcmf_dbg(TRACE, "Enter\n");
57  
58 @@ -1254,6 +1252,21 @@ int brcmf_attach(struct device *dev, str
59         drvr = wiphy_priv(wiphy);
60         drvr->wiphy = wiphy;
61         drvr->ops = ops;
62 +       drvr->bus_if = dev_get_drvdata(dev);
63 +       drvr->bus_if->drvr = drvr;
64 +       drvr->settings = settings;
65 +
66 +       return 0;
67 +}
68 +
69 +int brcmf_attach(struct device *dev)
70 +{
71 +       struct brcmf_bus *bus_if = dev_get_drvdata(dev);
72 +       struct brcmf_pub *drvr = bus_if->drvr;
73 +       int ret = 0;
74 +       int i;
75 +
76 +       brcmf_dbg(TRACE, "Enter\n");
77  
78         for (i = 0; i < ARRAY_SIZE(drvr->if2bss); i++)
79                 drvr->if2bss[i] = BRCMF_BSSIDX_INVALID;
80 @@ -1262,9 +1275,6 @@ int brcmf_attach(struct device *dev, str
81  
82         /* Link to bus module */
83         drvr->hdrlen = 0;
84 -       drvr->bus_if = dev_get_drvdata(dev);
85 -       drvr->bus_if->drvr = drvr;
86 -       drvr->settings = settings;
87  
88         /* Attach and link in the protocol */
89         ret = brcmf_proto_attach(drvr);
90 @@ -1280,7 +1290,7 @@ int brcmf_attach(struct device *dev, str
91         /* attach firmware event handler */
92         brcmf_fweh_attach(drvr);
93  
94 -       ret = brcmf_bus_started(drvr, ops);
95 +       ret = brcmf_bus_started(drvr, drvr->ops);
96         if (ret != 0) {
97                 bphy_err(drvr, "dongle is not responding: err=%d\n", ret);
98                 goto fail;
99 @@ -1372,6 +1382,15 @@ void brcmf_detach(struct device *dev)
100                 brcmf_cfg80211_detach(drvr->config);
101                 drvr->config = NULL;
102         }
103 +}
104 +
105 +void brcmf_free(struct device *dev)
106 +{
107 +       struct brcmf_bus *bus_if = dev_get_drvdata(dev);
108 +       struct brcmf_pub *drvr = bus_if->drvr;
109 +
110 +       if (!drvr)
111 +               return;
112  
113         bus_if->drvr = NULL;
114  
115 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c
116 +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c
117 @@ -1430,6 +1430,7 @@ static int brcmf_pcie_reset(struct devic
118         brcmf_pcie_bus_console_read(devinfo, true);
119  
120         brcmf_detach(dev);
121 +       brcmf_free(dev);
122  
123         brcmf_pcie_release_irq(devinfo);
124         brcmf_pcie_release_scratchbuffers(devinfo);
125 @@ -1824,11 +1825,18 @@ static void brcmf_pcie_setup(struct devi
126  
127         brcmf_pcie_intr_enable(devinfo);
128         brcmf_pcie_hostready(devinfo);
129 -       if (brcmf_attach(&devinfo->pdev->dev, devinfo->settings) == 0)
130 -               return;
131 +
132 +       ret = brcmf_alloc(&devinfo->pdev->dev, devinfo->settings);
133 +       if (ret)
134 +               goto fail;
135 +       ret = brcmf_attach(&devinfo->pdev->dev);
136 +       if (ret)
137 +               goto fail;
138  
139         brcmf_pcie_bus_console_read(devinfo, false);
140  
141 +       return;
142 +
143  fail:
144         device_release_driver(dev);
145  }
146 @@ -1971,6 +1979,7 @@ brcmf_pcie_remove(struct pci_dev *pdev)
147                 brcmf_pcie_intr_disable(devinfo);
148  
149         brcmf_detach(&pdev->dev);
150 +       brcmf_free(&pdev->dev);
151  
152         kfree(bus->bus_priv.pcie);
153         kfree(bus->msgbuf->flowrings);
154 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.c
155 +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.c
156 @@ -4247,17 +4247,26 @@ static void brcmf_sdio_firmware_callback
157         sdiod->bus_if->chip = bus->ci->chip;
158         sdiod->bus_if->chiprev = bus->ci->chiprev;
159  
160 +       err = brcmf_alloc(sdiod->dev, sdiod->settings);
161 +       if (err) {
162 +               brcmf_err("brcmf_alloc failed\n");
163 +               goto claim;
164 +       }
165 +
166         /* Attach to the common layer, reserve hdr space */
167 -       err = brcmf_attach(sdiod->dev, sdiod->settings);
168 +       err = brcmf_attach(sdiod->dev);
169         if (err != 0) {
170                 brcmf_err("brcmf_attach failed\n");
171 -               sdio_claim_host(sdiod->func1);
172 -               goto checkdied;
173 +               goto free;
174         }
175  
176         /* ready */
177         return;
178  
179 +free:
180 +       brcmf_free(sdiod->dev);
181 +claim:
182 +       sdio_claim_host(sdiod->func1);
183  checkdied:
184         brcmf_sdio_checkdied(bus);
185  release:
186 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/usb.c
187 +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/usb.c
188 @@ -1178,8 +1178,12 @@ static void brcmf_usb_probe_phase2(struc
189         if (ret)
190                 goto error;
191  
192 +       ret = brcmf_alloc(devinfo->dev, devinfo->settings);
193 +       if (ret)
194 +               goto error;
195 +
196         /* Attach to the common driver interface */
197 -       ret = brcmf_attach(devinfo->dev, devinfo->settings);
198 +       ret = brcmf_attach(devinfo->dev);
199         if (ret)
200                 goto error;
201  
202 @@ -1251,7 +1255,10 @@ static int brcmf_usb_probe_cb(struct brc
203         }
204  
205         if (!brcmf_usb_dlneeded(devinfo)) {
206 -               ret = brcmf_attach(devinfo->dev, devinfo->settings);
207 +               ret = brcmf_alloc(devinfo->dev, devinfo->settings);
208 +               if (ret)
209 +                       goto fail;
210 +               ret = brcmf_attach(devinfo->dev);
211                 if (ret)
212                         goto fail;
213                 /* we are done */
214 @@ -1279,6 +1286,7 @@ static int brcmf_usb_probe_cb(struct brc
215  
216  fail:
217         /* Release resources in reverse order */
218 +       brcmf_free(devinfo->dev);
219         kfree(bus);
220         brcmf_usb_detach(devinfo);
221         return ret;
222 @@ -1292,6 +1300,7 @@ brcmf_usb_disconnect_cb(struct brcmf_usb
223         brcmf_dbg(USB, "Enter, bus_pub %p\n", devinfo);
224  
225         brcmf_detach(devinfo->dev);
226 +       brcmf_free(devinfo->dev);
227         kfree(devinfo->bus_pub.bus);
228         brcmf_usb_detach(devinfo);
229  }
230 @@ -1435,10 +1444,12 @@ static int brcmf_usb_suspend(struct usb_
231  
232         brcmf_dbg(USB, "Enter\n");
233         devinfo->bus_pub.state = BRCMFMAC_USB_STATE_SLEEP;
234 -       if (devinfo->wowl_enabled)
235 +       if (devinfo->wowl_enabled) {
236                 brcmf_cancel_all_urbs(devinfo);
237 -       else
238 +       } else {
239                 brcmf_detach(&usb->dev);
240 +               brcmf_free(&usb->dev);
241 +       }
242         return 0;
243  }
244  
245 @@ -1451,8 +1462,19 @@ static int brcmf_usb_resume(struct usb_i
246         struct brcmf_usbdev_info *devinfo = brcmf_usb_get_businfo(&usb->dev);
247  
248         brcmf_dbg(USB, "Enter\n");
249 -       if (!devinfo->wowl_enabled)
250 -               return brcmf_attach(devinfo->dev, devinfo->settings);
251 +       if (!devinfo->wowl_enabled) {
252 +               int err;
253 +
254 +               err = brcmf_alloc(&usb->dev, devinfo->settings);
255 +               if (err)
256 +                       return err;
257 +
258 +               err = brcmf_attach(devinfo->dev);
259 +               if (err) {
260 +                       brcmf_free(devinfo->dev);
261 +                       return err;
262 +               }
263 +       }
264  
265         devinfo->bus_pub.state = BRCMFMAC_USB_STATE_UP;
266         brcmf_usb_rx_fill_all(devinfo);