wil6210: fix race between disconnect and Tx NAPI
[deliverable/linux.git] / drivers / net / wireless / ath / wil6210 / pcie_bus.c
CommitLineData
2be7d22f
VK
1/*
2 * Copyright (c) 2012 Qualcomm Atheros, Inc.
3 *
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
16
2be7d22f 17#include <linux/module.h>
2be7d22f
VK
18#include <linux/debugfs.h>
19#include <linux/pci.h>
20#include <linux/moduleparam.h>
21
22#include "wil6210.h"
23
24static int use_msi = 1;
25module_param(use_msi, int, S_IRUGO);
26MODULE_PARM_DESC(use_msi,
27 " Use MSI interrupt: "
28 "0 - don't, 1 - (default) - single, or 3");
29
30/* Bus ops */
31static int wil_if_pcie_enable(struct wil6210_priv *wil)
32{
33 struct pci_dev *pdev = wil->pdev;
34 int rc;
35
36 pci_set_master(pdev);
37
38 /*
39 * how many MSI interrupts to request?
40 */
41 switch (use_msi) {
42 case 3:
43 case 1:
44 case 0:
45 break;
46 default:
47 wil_err(wil, "Invalid use_msi=%d, default to 1\n",
48 use_msi);
49 use_msi = 1;
50 }
51 wil->n_msi = use_msi;
52 if (wil->n_msi) {
7743882d 53 wil_dbg_misc(wil, "Setup %d MSI interrupts\n", use_msi);
2be7d22f
VK
54 rc = pci_enable_msi_block(pdev, wil->n_msi);
55 if (rc && (wil->n_msi == 3)) {
56 wil_err(wil, "3 MSI mode failed, try 1 MSI\n");
57 wil->n_msi = 1;
58 rc = pci_enable_msi_block(pdev, wil->n_msi);
59 }
60 if (rc) {
61 wil_err(wil, "pci_enable_msi failed, use INTx\n");
62 wil->n_msi = 0;
63 }
64 } else {
7743882d 65 wil_dbg_misc(wil, "MSI interrupts disabled, use INTx\n");
2be7d22f
VK
66 }
67
68 rc = wil6210_init_irq(wil, pdev->irq);
69 if (rc)
70 goto stop_master;
71
72 /* need reset here to obtain MAC */
097638a0 73 mutex_lock(&wil->mutex);
2be7d22f 74 rc = wil_reset(wil);
097638a0 75 mutex_unlock(&wil->mutex);
2be7d22f
VK
76 if (rc)
77 goto release_irq;
78
36b10a72
VK
79 wil_info(wil, "HW version: 0x%08x\n", wil->hw_version);
80
2be7d22f
VK
81 return 0;
82
83 release_irq:
84 wil6210_fini_irq(wil, pdev->irq);
85 /* safe to call if no MSI */
86 pci_disable_msi(pdev);
87 stop_master:
88 pci_clear_master(pdev);
89 return rc;
90}
91
92static int wil_if_pcie_disable(struct wil6210_priv *wil)
93{
94 struct pci_dev *pdev = wil->pdev;
95
96 pci_clear_master(pdev);
97 /* disable and release IRQ */
98 wil6210_fini_irq(wil, pdev->irq);
99 /* safe to call if no MSI */
100 pci_disable_msi(pdev);
101 /* TODO: disable HW */
102
103 return 0;
104}
105
106static int wil_pcie_probe(struct pci_dev *pdev, const struct pci_device_id *id)
107{
108 struct wil6210_priv *wil;
109 struct device *dev = &pdev->dev;
110 void __iomem *csr;
111 int rc;
112
113 /* check HW */
114 dev_info(&pdev->dev, WIL_NAME " device found [%04x:%04x] (rev %x)\n",
115 (int)pdev->vendor, (int)pdev->device, (int)pdev->revision);
116
117 if (pci_resource_len(pdev, 0) != WIL6210_MEM_SIZE) {
118 dev_err(&pdev->dev, "Not " WIL_NAME "? "
119 "BAR0 size is %lu while expecting %lu\n",
120 (ulong)pci_resource_len(pdev, 0), WIL6210_MEM_SIZE);
121 return -ENODEV;
122 }
123
124 rc = pci_enable_device(pdev);
125 if (rc) {
126 dev_err(&pdev->dev, "pci_enable_device failed\n");
127 return -ENODEV;
128 }
129 /* rollback to err_disable_pdev */
130
131 rc = pci_request_region(pdev, 0, WIL_NAME);
132 if (rc) {
133 dev_err(&pdev->dev, "pci_request_region failed\n");
134 goto err_disable_pdev;
135 }
136 /* rollback to err_release_reg */
137
138 csr = pci_ioremap_bar(pdev, 0);
139 if (!csr) {
140 dev_err(&pdev->dev, "pci_ioremap_bar failed\n");
141 rc = -ENODEV;
142 goto err_release_reg;
143 }
144 /* rollback to err_iounmap */
145 dev_info(&pdev->dev, "CSR at %pR -> %p\n", &pdev->resource[0], csr);
146
147 wil = wil_if_alloc(dev, csr);
148 if (IS_ERR(wil)) {
149 rc = (int)PTR_ERR(wil);
150 dev_err(dev, "wil_if_alloc failed: %d\n", rc);
151 goto err_iounmap;
152 }
153 /* rollback to if_free */
154
155 pci_set_drvdata(pdev, wil);
156 wil->pdev = pdev;
157
f4b5a803 158 wil6210_clear_irq(wil);
2be7d22f
VK
159 /* FW should raise IRQ when ready */
160 rc = wil_if_pcie_enable(wil);
161 if (rc) {
162 wil_err(wil, "Enable device failed\n");
163 goto if_free;
164 }
165 /* rollback to bus_disable */
166
167 rc = wil_if_add(wil);
168 if (rc) {
169 wil_err(wil, "wil_if_add failed: %d\n", rc);
170 goto bus_disable;
171 }
172
173 wil6210_debugfs_init(wil);
174
175 /* check FW is alive */
176 wmi_echo(wil);
177
178 return 0;
179
180 bus_disable:
181 wil_if_pcie_disable(wil);
182 if_free:
183 wil_if_free(wil);
184 err_iounmap:
185 pci_iounmap(pdev, csr);
186 err_release_reg:
187 pci_release_region(pdev, 0);
188 err_disable_pdev:
189 pci_disable_device(pdev);
190
191 return rc;
192}
193
194static void wil_pcie_remove(struct pci_dev *pdev)
195{
196 struct wil6210_priv *wil = pci_get_drvdata(pdev);
197
198 wil6210_debugfs_remove(wil);
199 wil_if_pcie_disable(wil);
200 wil_if_remove(wil);
201 wil_if_free(wil);
202 pci_iounmap(pdev, wil->csr);
203 pci_release_region(pdev, 0);
204 pci_disable_device(pdev);
2be7d22f
VK
205}
206
207static DEFINE_PCI_DEVICE_TABLE(wil6210_pcie_ids) = {
208 { PCI_DEVICE(0x1ae9, 0x0301) },
209 { /* end: all zeroes */ },
210};
211MODULE_DEVICE_TABLE(pci, wil6210_pcie_ids);
212
213static struct pci_driver wil6210_driver = {
214 .probe = wil_pcie_probe,
215 .remove = wil_pcie_remove,
216 .id_table = wil6210_pcie_ids,
217 .name = WIL_NAME,
218};
219
220module_pci_driver(wil6210_driver);
221
222MODULE_LICENSE("Dual BSD/GPL");
223MODULE_AUTHOR("Qualcomm Atheros <wil6210@qca.qualcomm.com>");
224MODULE_DESCRIPTION("Driver for 60g WiFi WIL6210 card");
This page took 0.119653 seconds and 5 git commands to generate.