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()
7 Content-Type: text/plain; charset=UTF-8
8 Content-Transfer-Encoding: 8bit
10 Move code allocating/freeing wiphy out of above functions. This will
11 allow reinitializing the driver (e.g. on some error) without allocating
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>
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(-)
25 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bus.h
26 +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bus.h
27 @@ -253,10 +253,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);
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:
47 -int brcmf_attach(struct device *dev, struct brcmf_mp_device *settings)
48 +int brcmf_alloc(struct device *dev, struct brcmf_mp_device *settings)
51 struct cfg80211_ops *ops;
52 struct brcmf_pub *drvr = NULL;
56 brcmf_dbg(TRACE, "Enter\n");
58 @@ -1254,6 +1252,21 @@ int brcmf_attach(struct device *dev, str
59 drvr = wiphy_priv(wiphy);
62 + drvr->bus_if = dev_get_drvdata(dev);
63 + drvr->bus_if->drvr = drvr;
64 + drvr->settings = settings;
69 +int brcmf_attach(struct device *dev)
71 + struct brcmf_bus *bus_if = dev_get_drvdata(dev);
72 + struct brcmf_pub *drvr = bus_if->drvr;
76 + brcmf_dbg(TRACE, "Enter\n");
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
82 /* Link to bus module */
84 - drvr->bus_if = dev_get_drvdata(dev);
85 - drvr->bus_if->drvr = drvr;
86 - drvr->settings = settings;
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);
94 - ret = brcmf_bus_started(drvr, ops);
95 + ret = brcmf_bus_started(drvr, drvr->ops);
97 bphy_err(drvr, "dongle is not responding: err=%d\n", ret);
99 @@ -1377,6 +1387,15 @@ void brcmf_detach(struct device *dev)
100 brcmf_cfg80211_detach(drvr->config);
105 +void brcmf_free(struct device *dev)
107 + struct brcmf_bus *bus_if = dev_get_drvdata(dev);
108 + struct brcmf_pub *drvr = bus_if->drvr;
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);
123 brcmf_pcie_release_irq(devinfo);
124 brcmf_pcie_release_scratchbuffers(devinfo);
125 @@ -1824,11 +1825,18 @@ static void brcmf_pcie_setup(struct devi
127 brcmf_pcie_intr_enable(devinfo);
128 brcmf_pcie_hostready(devinfo);
129 - if (brcmf_attach(&devinfo->pdev->dev, devinfo->settings) == 0)
132 + ret = brcmf_alloc(&devinfo->pdev->dev, devinfo->settings);
135 + ret = brcmf_attach(&devinfo->pdev->dev);
139 brcmf_pcie_bus_console_read(devinfo, false);
144 device_release_driver(dev);
146 @@ -1971,6 +1979,7 @@ brcmf_pcie_remove(struct pci_dev *pdev)
147 brcmf_pcie_intr_disable(devinfo);
149 brcmf_detach(&pdev->dev);
150 + brcmf_free(&pdev->dev);
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 @@ -4251,17 +4251,26 @@ static void brcmf_sdio_firmware_callback
157 sdiod->bus_if->chip = bus->ci->chip;
158 sdiod->bus_if->chiprev = bus->ci->chiprev;
160 + err = brcmf_alloc(sdiod->dev, sdiod->settings);
162 + brcmf_err("brcmf_alloc failed\n");
166 /* Attach to the common layer, reserve hdr space */
167 - err = brcmf_attach(sdiod->dev, sdiod->settings);
168 + err = brcmf_attach(sdiod->dev);
170 brcmf_err("brcmf_attach failed\n");
171 - sdio_claim_host(sdiod->func1);
180 + brcmf_free(sdiod->dev);
182 + sdio_claim_host(sdiod->func1);
184 brcmf_sdio_checkdied(bus);
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
192 + ret = brcmf_alloc(devinfo->dev, devinfo->settings);
196 /* Attach to the common driver interface */
197 - ret = brcmf_attach(devinfo->dev, devinfo->settings);
198 + ret = brcmf_attach(devinfo->dev);
202 @@ -1251,7 +1255,10 @@ static int brcmf_usb_probe_cb(struct brc
205 if (!brcmf_usb_dlneeded(devinfo)) {
206 - ret = brcmf_attach(devinfo->dev, devinfo->settings);
207 + ret = brcmf_alloc(devinfo->dev, devinfo->settings);
210 + ret = brcmf_attach(devinfo->dev);
214 @@ -1279,6 +1286,7 @@ static int brcmf_usb_probe_cb(struct brc
217 /* Release resources in reverse order */
218 + brcmf_free(devinfo->dev);
220 brcmf_usb_detach(devinfo);
222 @@ -1292,6 +1300,7 @@ brcmf_usb_disconnect_cb(struct brcmf_usb
223 brcmf_dbg(USB, "Enter, bus_pub %p\n", devinfo);
225 brcmf_detach(devinfo->dev);
226 + brcmf_free(devinfo->dev);
227 kfree(devinfo->bus_pub.bus);
228 brcmf_usb_detach(devinfo);
230 @@ -1435,10 +1444,12 @@ static int brcmf_usb_suspend(struct usb_
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);
239 brcmf_detach(&usb->dev);
240 + brcmf_free(&usb->dev);
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);
248 brcmf_dbg(USB, "Enter\n");
249 - if (!devinfo->wowl_enabled)
250 - return brcmf_attach(devinfo->dev, devinfo->settings);
251 + if (!devinfo->wowl_enabled) {
254 + err = brcmf_alloc(&usb->dev, devinfo->settings);
258 + err = brcmf_attach(devinfo->dev);
260 + brcmf_free(devinfo->dev);
265 devinfo->bus_pub.state = BRCMFMAC_USB_STATE_UP;
266 brcmf_usb_rx_fill_all(devinfo);