2 * Copyright (c) 2012-2014 Qualcomm Atheros, Inc.
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.
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.
17 #include <linux/module.h>
18 #include <linux/pci.h>
19 #include <linux/moduleparam.h>
23 static int use_msi
= 1;
24 module_param(use_msi
, int, S_IRUGO
);
25 MODULE_PARM_DESC(use_msi
,
26 " Use MSI interrupt: "
27 "0 - don't, 1 - (default) - single, or 3");
29 static bool debug_fw
; /* = false; */
30 module_param(debug_fw
, bool, S_IRUGO
);
31 MODULE_PARM_DESC(debug_fw
, " load driver if FW not ready. For FW debug");
34 static int wil_if_pcie_enable(struct wil6210_priv
*wil
)
36 struct pci_dev
*pdev
= wil
->pdev
;
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
42 int msi_only
= pdev
->msi_enabled
;
44 wil_dbg_misc(wil
, "%s()\n", __func__
);
46 pdev
->msi_enabled
= 0;
51 * how many MSI interrupts to request?
56 wil_dbg_misc(wil
, "Setup %d MSI interrupts\n", use_msi
);
59 wil_dbg_misc(wil
, "MSI interrupts disabled, use INTx\n");
62 wil_err(wil
, "Invalid use_msi=%d, default to 1\n", use_msi
);
66 if (use_msi
== 3 && pci_enable_msi_range(pdev
, 3, 3) < 0) {
67 wil_err(wil
, "3 MSI mode failed, try 1 MSI\n");
71 if (use_msi
== 1 && pci_enable_msi(pdev
)) {
72 wil_err(wil
, "pci_enable_msi failed, use INTx\n");
78 if ((wil
->n_msi
== 0) && msi_only
) {
79 wil_err(wil
, "Interrupt pin not routed, unable to use INTx\n");
84 rc
= wil6210_init_irq(wil
, pdev
->irq
);
88 /* need reset here to obtain MAC */
89 mutex_lock(&wil
->mutex
);
91 mutex_unlock(&wil
->mutex
);
100 wil6210_fini_irq(wil
, pdev
->irq
);
101 /* safe to call if no MSI */
102 pci_disable_msi(pdev
);
104 pci_clear_master(pdev
);
108 static int wil_if_pcie_disable(struct wil6210_priv
*wil
)
110 struct pci_dev
*pdev
= wil
->pdev
;
112 wil_dbg_misc(wil
, "%s()\n", __func__
);
114 pci_clear_master(pdev
);
115 /* disable and release IRQ */
116 wil6210_fini_irq(wil
, pdev
->irq
);
117 /* safe to call if no MSI */
118 pci_disable_msi(pdev
);
119 /* TODO: disable HW */
124 static int wil_pcie_probe(struct pci_dev
*pdev
, const struct pci_device_id
*id
)
126 struct wil6210_priv
*wil
;
127 struct device
*dev
= &pdev
->dev
;
129 struct wil_board
*board
= (struct wil_board
*)id
->driver_data
;
133 dev_info(&pdev
->dev
, WIL_NAME
134 " \"%s\" device found [%04x:%04x] (rev %x)\n", board
->name
,
135 (int)pdev
->vendor
, (int)pdev
->device
, (int)pdev
->revision
);
137 if (pci_resource_len(pdev
, 0) != WIL6210_MEM_SIZE
) {
138 dev_err(&pdev
->dev
, "Not " WIL_NAME
"? "
139 "BAR0 size is %lu while expecting %lu\n",
140 (ulong
)pci_resource_len(pdev
, 0), WIL6210_MEM_SIZE
);
144 rc
= pci_enable_device(pdev
);
147 "pci_enable_device failed, retry with MSI only\n");
148 /* Work around for platforms that can't allocate IRQ:
149 * retry with MSI only
151 pdev
->msi_enabled
= 1;
152 rc
= pci_enable_device(pdev
);
156 /* rollback to err_disable_pdev */
158 rc
= pci_request_region(pdev
, 0, WIL_NAME
);
160 dev_err(&pdev
->dev
, "pci_request_region failed\n");
161 goto err_disable_pdev
;
163 /* rollback to err_release_reg */
165 csr
= pci_ioremap_bar(pdev
, 0);
167 dev_err(&pdev
->dev
, "pci_ioremap_bar failed\n");
169 goto err_release_reg
;
171 /* rollback to err_iounmap */
172 dev_info(&pdev
->dev
, "CSR at %pR -> 0x%p\n", &pdev
->resource
[0], csr
);
174 wil
= wil_if_alloc(dev
, csr
);
176 rc
= (int)PTR_ERR(wil
);
177 dev_err(dev
, "wil_if_alloc failed: %d\n", rc
);
180 /* rollback to if_free */
182 pci_set_drvdata(pdev
, wil
);
186 wil6210_clear_irq(wil
);
188 wil
->platform_handle
=
189 wil_platform_init(&pdev
->dev
, &wil
->platform_ops
);
191 /* FW should raise IRQ when ready */
192 rc
= wil_if_pcie_enable(wil
);
194 wil_err(wil
, "Enable device failed\n");
197 /* rollback to bus_disable */
199 rc
= wil_if_add(wil
);
201 wil_err(wil
, "wil_if_add failed: %d\n", rc
);
205 wil6210_debugfs_init(wil
);
207 /* check FW is alive */
213 wil_if_pcie_disable(wil
);
215 if (wil
->platform_ops
.uninit
)
216 wil
->platform_ops
.uninit(wil
->platform_handle
);
219 pci_iounmap(pdev
, csr
);
221 pci_release_region(pdev
, 0);
223 pci_disable_device(pdev
);
228 static void wil_pcie_remove(struct pci_dev
*pdev
)
230 struct wil6210_priv
*wil
= pci_get_drvdata(pdev
);
231 void __iomem
*csr
= wil
->csr
;
233 wil_dbg_misc(wil
, "%s()\n", __func__
);
235 wil6210_debugfs_remove(wil
);
237 wil_if_pcie_disable(wil
);
238 if (wil
->platform_ops
.uninit
)
239 wil
->platform_ops
.uninit(wil
->platform_handle
);
241 pci_iounmap(pdev
, csr
);
242 pci_release_region(pdev
, 0);
243 pci_disable_device(pdev
);
246 static const struct wil_board wil_board_marlon
= {
247 .board
= WIL_BOARD_MARLON
,
251 static const struct wil_board wil_board_sparrow
= {
252 .board
= WIL_BOARD_SPARROW
,
256 static const struct pci_device_id wil6210_pcie_ids
[] = {
257 { PCI_DEVICE(0x1ae9, 0x0301),
258 .driver_data
= (kernel_ulong_t
)&wil_board_marlon
},
259 { PCI_DEVICE(0x1ae9, 0x0310),
260 .driver_data
= (kernel_ulong_t
)&wil_board_sparrow
},
261 { PCI_DEVICE(0x1ae9, 0x0302), /* same as above, firmware broken */
262 .driver_data
= (kernel_ulong_t
)&wil_board_sparrow
},
263 { /* end: all zeroes */ },
265 MODULE_DEVICE_TABLE(pci
, wil6210_pcie_ids
);
267 static struct pci_driver wil6210_driver
= {
268 .probe
= wil_pcie_probe
,
269 .remove
= wil_pcie_remove
,
270 .id_table
= wil6210_pcie_ids
,
274 module_pci_driver(wil6210_driver
);
276 MODULE_LICENSE("Dual BSD/GPL");
277 MODULE_AUTHOR("Qualcomm Atheros <wil6210@qca.qualcomm.com>");
278 MODULE_DESCRIPTION("Driver for 60g WiFi WIL6210 card");