wil6210: Workaround for Sparrow with bad device id
[deliverable/linux.git] / drivers / net / wireless / ath / wil6210 / pcie_bus.c
CommitLineData
2be7d22f 1/*
02525a79 2 * Copyright (c) 2012-2014 Qualcomm Atheros, Inc.
2be7d22f
VK
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/pci.h>
19#include <linux/moduleparam.h>
20
21#include "wil6210.h"
22
23static int use_msi = 1;
24module_param(use_msi, int, S_IRUGO);
25MODULE_PARM_DESC(use_msi,
26 " Use MSI interrupt: "
27 "0 - don't, 1 - (default) - single, or 3");
28
94b7b64c
VK
29static bool debug_fw; /* = false; */
30module_param(debug_fw, bool, S_IRUGO);
31MODULE_PARM_DESC(debug_fw, " load driver if FW not ready. For FW debug");
32
2be7d22f
VK
33/* Bus ops */
34static int wil_if_pcie_enable(struct wil6210_priv *wil)
35{
36 struct pci_dev *pdev = wil->pdev;
37 int rc;
2bdc0700
VK
38 /* on platforms with buggy ACPI, pdev->msi_enabled may be set to
39 * allow pci_enable_device to work. This indicates INTx was not routed
40 * and only MSI should be used
41 */
42 int msi_only = pdev->msi_enabled;
43
44 pdev->msi_enabled = 0;
2be7d22f
VK
45
46 pci_set_master(pdev);
47
48 /*
49 * how many MSI interrupts to request?
50 */
51 switch (use_msi) {
52 case 3:
53 case 1:
b4b39061
AG
54 wil_dbg_misc(wil, "Setup %d MSI interrupts\n", use_msi);
55 break;
2be7d22f 56 case 0:
b4b39061 57 wil_dbg_misc(wil, "MSI interrupts disabled, use INTx\n");
2be7d22f
VK
58 break;
59 default:
b4b39061 60 wil_err(wil, "Invalid use_msi=%d, default to 1\n", use_msi);
2be7d22f
VK
61 use_msi = 1;
62 }
b4b39061
AG
63
64 if (use_msi == 3 && pci_enable_msi_range(pdev, 3, 3) < 0) {
65 wil_err(wil, "3 MSI mode failed, try 1 MSI\n");
66 use_msi = 1;
67 }
68
69 if (use_msi == 1 && pci_enable_msi(pdev)) {
70 wil_err(wil, "pci_enable_msi failed, use INTx\n");
71 use_msi = 0;
2be7d22f
VK
72 }
73
b4b39061
AG
74 wil->n_msi = use_msi;
75
2bdc0700
VK
76 if ((wil->n_msi == 0) && msi_only) {
77 wil_err(wil, "Interrupt pin not routed, unable to use INTx\n");
78 rc = -ENODEV;
79 goto stop_master;
80 }
81
2be7d22f
VK
82 rc = wil6210_init_irq(wil, pdev->irq);
83 if (rc)
84 goto stop_master;
85
86 /* need reset here to obtain MAC */
097638a0 87 mutex_lock(&wil->mutex);
2be7d22f 88 rc = wil_reset(wil);
097638a0 89 mutex_unlock(&wil->mutex);
94b7b64c
VK
90 if (debug_fw)
91 rc = 0;
2be7d22f
VK
92 if (rc)
93 goto release_irq;
94
95 return 0;
96
97 release_irq:
98 wil6210_fini_irq(wil, pdev->irq);
99 /* safe to call if no MSI */
100 pci_disable_msi(pdev);
101 stop_master:
102 pci_clear_master(pdev);
103 return rc;
104}
105
106static int wil_if_pcie_disable(struct wil6210_priv *wil)
107{
108 struct pci_dev *pdev = wil->pdev;
109
110 pci_clear_master(pdev);
111 /* disable and release IRQ */
112 wil6210_fini_irq(wil, pdev->irq);
113 /* safe to call if no MSI */
114 pci_disable_msi(pdev);
115 /* TODO: disable HW */
116
117 return 0;
118}
119
120static int wil_pcie_probe(struct pci_dev *pdev, const struct pci_device_id *id)
121{
122 struct wil6210_priv *wil;
123 struct device *dev = &pdev->dev;
124 void __iomem *csr;
6508281b 125 struct wil_board *board = (struct wil_board *)id->driver_data;
2be7d22f
VK
126 int rc;
127
128 /* check HW */
6508281b
VK
129 dev_info(&pdev->dev, WIL_NAME
130 " \"%s\" device found [%04x:%04x] (rev %x)\n", board->name,
2be7d22f
VK
131 (int)pdev->vendor, (int)pdev->device, (int)pdev->revision);
132
133 if (pci_resource_len(pdev, 0) != WIL6210_MEM_SIZE) {
134 dev_err(&pdev->dev, "Not " WIL_NAME "? "
135 "BAR0 size is %lu while expecting %lu\n",
136 (ulong)pci_resource_len(pdev, 0), WIL6210_MEM_SIZE);
137 return -ENODEV;
138 }
139
140 rc = pci_enable_device(pdev);
141 if (rc) {
2bdc0700
VK
142 dev_err(&pdev->dev,
143 "pci_enable_device failed, retry with MSI only\n");
144 /* Work around for platforms that can't allocate IRQ:
145 * retry with MSI only
146 */
147 pdev->msi_enabled = 1;
148 rc = pci_enable_device(pdev);
2be7d22f 149 }
2bdc0700
VK
150 if (rc)
151 return -ENODEV;
2be7d22f
VK
152 /* rollback to err_disable_pdev */
153
154 rc = pci_request_region(pdev, 0, WIL_NAME);
155 if (rc) {
156 dev_err(&pdev->dev, "pci_request_region failed\n");
157 goto err_disable_pdev;
158 }
159 /* rollback to err_release_reg */
160
161 csr = pci_ioremap_bar(pdev, 0);
162 if (!csr) {
163 dev_err(&pdev->dev, "pci_ioremap_bar failed\n");
164 rc = -ENODEV;
165 goto err_release_reg;
166 }
167 /* rollback to err_iounmap */
39c52ee8 168 dev_info(&pdev->dev, "CSR at %pR -> 0x%p\n", &pdev->resource[0], csr);
2be7d22f
VK
169
170 wil = wil_if_alloc(dev, csr);
171 if (IS_ERR(wil)) {
172 rc = (int)PTR_ERR(wil);
173 dev_err(dev, "wil_if_alloc failed: %d\n", rc);
174 goto err_iounmap;
175 }
176 /* rollback to if_free */
177
178 pci_set_drvdata(pdev, wil);
179 wil->pdev = pdev;
6508281b 180 wil->board = board;
2be7d22f 181
f4b5a803 182 wil6210_clear_irq(wil);
2be7d22f
VK
183 /* FW should raise IRQ when ready */
184 rc = wil_if_pcie_enable(wil);
185 if (rc) {
186 wil_err(wil, "Enable device failed\n");
187 goto if_free;
188 }
189 /* rollback to bus_disable */
190
191 rc = wil_if_add(wil);
192 if (rc) {
193 wil_err(wil, "wil_if_add failed: %d\n", rc);
194 goto bus_disable;
195 }
196
197 wil6210_debugfs_init(wil);
198
199 /* check FW is alive */
200 wmi_echo(wil);
201
202 return 0;
203
204 bus_disable:
205 wil_if_pcie_disable(wil);
206 if_free:
207 wil_if_free(wil);
208 err_iounmap:
209 pci_iounmap(pdev, csr);
210 err_release_reg:
211 pci_release_region(pdev, 0);
212 err_disable_pdev:
213 pci_disable_device(pdev);
214
215 return rc;
216}
217
218static void wil_pcie_remove(struct pci_dev *pdev)
219{
220 struct wil6210_priv *wil = pci_get_drvdata(pdev);
221
222 wil6210_debugfs_remove(wil);
223 wil_if_pcie_disable(wil);
224 wil_if_remove(wil);
225 wil_if_free(wil);
226 pci_iounmap(pdev, wil->csr);
227 pci_release_region(pdev, 0);
228 pci_disable_device(pdev);
2be7d22f
VK
229}
230
6508281b
VK
231static const struct wil_board wil_board_marlon = {
232 .board = WIL_BOARD_MARLON,
233 .name = "marlon",
234};
235
236static const struct wil_board wil_board_sparrow = {
237 .board = WIL_BOARD_SPARROW,
238 .name = "sparrow",
239};
240
241static const struct pci_device_id wil6210_pcie_ids[] = {
242 { PCI_DEVICE(0x1ae9, 0x0301),
243 .driver_data = (kernel_ulong_t)&wil_board_marlon },
244 { PCI_DEVICE(0x1ae9, 0x0310),
245 .driver_data = (kernel_ulong_t)&wil_board_sparrow },
6afd6005
VK
246 { PCI_DEVICE(0x1ae9, 0x0302), /* same as above, firmware broken */
247 .driver_data = (kernel_ulong_t)&wil_board_sparrow },
2be7d22f
VK
248 { /* end: all zeroes */ },
249};
250MODULE_DEVICE_TABLE(pci, wil6210_pcie_ids);
251
252static struct pci_driver wil6210_driver = {
253 .probe = wil_pcie_probe,
254 .remove = wil_pcie_remove,
255 .id_table = wil6210_pcie_ids,
256 .name = WIL_NAME,
257};
258
259module_pci_driver(wil6210_driver);
260
261MODULE_LICENSE("Dual BSD/GPL");
262MODULE_AUTHOR("Qualcomm Atheros <wil6210@qca.qualcomm.com>");
263MODULE_DESCRIPTION("Driver for 60g WiFi WIL6210 card");
This page took 0.172243 seconds and 5 git commands to generate.