Skip to content

Commit 69a2bac

Browse files
juhosglinvjw
authored andcommitted
rt2x00: rt2x00pci: fix build error on Ralink RT3x5x SoCs
The rt2800pci driver supports the built-in wireless MAC of the Ralink RT3x5x SoCs. However building the driver for these SoCs leads to the following error: LD init/built-in.o drivers/built-in.o: In function `rt2800pci_rxdone_tasklet': <...>/drivers/net/wireless/rt2x00/rt2800pci.c:1012: undefined reference to `rt2x00pci_rxdone' drivers/built-in.o:(.rodata+0x4780): undefined reference to `rt2x00pci_initialize' drivers/built-in.o:(.rodata+0x4784): undefined reference to `rt2x00pci_uninitialize' drivers/built-in.o:(.rodata+0x47bc): undefined reference to `rt2x00pci_flush_queue' drivers/built-in.o:(.rodata+0x4818): undefined reference to `rt2x00pci_regbusy_read' make[5]: *** [vmlinux] Error 1 The missing functions are provided by the rt2x00pci module. This module is only selected by the rt2800pci driver if PCI support is enabled in the kernel, because some parts of the rt2x00pci code depends on PCI support. PCI support is not available on the RT3x5x SoCs because those have no PCI host controller at all. Move the non PCI specific code from rt2x00pci into a separate module. This makes it possible to use that code even if PCI support is disabled. The affected functions are used by all of the rt2x00 PCI drivers so select the new module for those drivers. Signed-off-by: Gabor Juhos <juhosg@openwrt.org> Signed-off-by: John W. Linville <linville@tuxdriver.com>
1 parent 83589b3 commit 69a2bac

10 files changed

Lines changed: 347 additions & 264 deletions

File tree

‎drivers/net/wireless/rt2x00/Kconfig‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ if RT2X00
2020
config RT2400PCI
2121
tristate "Ralink rt2400 (PCI/PCMCIA) support"
2222
depends on PCI
23+
select RT2X00_LIB_MMIO
2324
select RT2X00_LIB_PCI
2425
select EEPROM_93CX6
2526
---help---
@@ -31,6 +32,7 @@ config RT2400PCI
3132
config RT2500PCI
3233
tristate "Ralink rt2500 (PCI/PCMCIA) support"
3334
depends on PCI
35+
select RT2X00_LIB_MMIO
3436
select RT2X00_LIB_PCI
3537
select EEPROM_93CX6
3638
---help---
@@ -43,6 +45,7 @@ config RT61PCI
4345
tristate "Ralink rt2501/rt61 (PCI/PCMCIA) support"
4446
depends on PCI
4547
select RT2X00_LIB_PCI
48+
select RT2X00_LIB_MMIO
4649
select RT2X00_LIB_FIRMWARE
4750
select RT2X00_LIB_CRYPTO
4851
select CRC_ITU_T
@@ -57,6 +60,7 @@ config RT2800PCI
5760
tristate "Ralink rt27xx/rt28xx/rt30xx (PCI/PCIe/PCMCIA) support"
5861
depends on PCI || SOC_RT288X || SOC_RT305X
5962
select RT2800_LIB
63+
select RT2X00_LIB_MMIO
6064
select RT2X00_LIB_PCI if PCI
6165
select RT2X00_LIB_SOC if SOC_RT288X || SOC_RT305X
6266
select RT2X00_LIB_FIRMWARE
@@ -185,6 +189,9 @@ endif
185189
config RT2800_LIB
186190
tristate
187191

192+
config RT2X00_LIB_MMIO
193+
tristate
194+
188195
config RT2X00_LIB_PCI
189196
tristate
190197
select RT2X00_LIB

‎drivers/net/wireless/rt2x00/Makefile‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ rt2x00lib-$(CONFIG_RT2X00_LIB_FIRMWARE) += rt2x00firmware.o
99
rt2x00lib-$(CONFIG_RT2X00_LIB_LEDS) += rt2x00leds.o
1010

1111
obj-$(CONFIG_RT2X00_LIB) += rt2x00lib.o
12+
obj-$(CONFIG_RT2X00_LIB_MMIO) += rt2x00mmio.o
1213
obj-$(CONFIG_RT2X00_LIB_PCI) += rt2x00pci.o
1314
obj-$(CONFIG_RT2X00_LIB_SOC) += rt2x00soc.o
1415
obj-$(CONFIG_RT2X00_LIB_USB) += rt2x00usb.o

‎drivers/net/wireless/rt2x00/rt2400pci.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include <linux/slab.h>
3535

3636
#include "rt2x00.h"
37+
#include "rt2x00mmio.h"
3738
#include "rt2x00pci.h"
3839
#include "rt2400pci.h"
3940

‎drivers/net/wireless/rt2x00/rt2500pci.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include <linux/slab.h>
3535

3636
#include "rt2x00.h"
37+
#include "rt2x00mmio.h"
3738
#include "rt2x00pci.h"
3839
#include "rt2500pci.h"
3940

‎drivers/net/wireless/rt2x00/rt2800pci.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
#include <linux/eeprom_93cx6.h>
4242

4343
#include "rt2x00.h"
44+
#include "rt2x00mmio.h"
4445
#include "rt2x00pci.h"
4546
#include "rt2x00soc.h"
4647
#include "rt2800lib.h"
Lines changed: 216 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,216 @@
1+
/*
2+
Copyright (C) 2004 - 2009 Ivo van Doorn <IvDoorn@gmail.com>
3+
<http://rt2x00.serialmonkey.com>
4+
5+
This program is free software; you can redistribute it and/or modify
6+
it under the terms of the GNU General Public License as published by
7+
the Free Software Foundation; either version 2 of the License, or
8+
(at your option) any later version.
9+
10+
This program is distributed in the hope that it will be useful,
11+
but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
GNU General Public License for more details.
14+
15+
You should have received a copy of the GNU General Public License
16+
along with this program; if not, write to the
17+
Free Software Foundation, Inc.,
18+
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19+
*/
20+
21+
/*
22+
Module: rt2x00mmio
23+
Abstract: rt2x00 generic mmio device routines.
24+
*/
25+
26+
#include <linux/dma-mapping.h>
27+
#include <linux/kernel.h>
28+
#include <linux/module.h>
29+
#include <linux/slab.h>
30+
31+
#include "rt2x00.h"
32+
#include "rt2x00mmio.h"
33+
34+
/*
35+
* Register access.
36+
*/
37+
int rt2x00pci_regbusy_read(struct rt2x00_dev *rt2x00dev,
38+
const unsigned int offset,
39+
const struct rt2x00_field32 field,
40+
u32 *reg)
41+
{
42+
unsigned int i;
43+
44+
if (!test_bit(DEVICE_STATE_PRESENT, &rt2x00dev->flags))
45+
return 0;
46+
47+
for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
48+
rt2x00pci_register_read(rt2x00dev, offset, reg);
49+
if (!rt2x00_get_field32(*reg, field))
50+
return 1;
51+
udelay(REGISTER_BUSY_DELAY);
52+
}
53+
54+
printk_once(KERN_ERR "%s() Indirect register access failed: "
55+
"offset=0x%.08x, value=0x%.08x\n", __func__, offset, *reg);
56+
*reg = ~0;
57+
58+
return 0;
59+
}
60+
EXPORT_SYMBOL_GPL(rt2x00pci_regbusy_read);
61+
62+
bool rt2x00pci_rxdone(struct rt2x00_dev *rt2x00dev)
63+
{
64+
struct data_queue *queue = rt2x00dev->rx;
65+
struct queue_entry *entry;
66+
struct queue_entry_priv_pci *entry_priv;
67+
struct skb_frame_desc *skbdesc;
68+
int max_rx = 16;
69+
70+
while (--max_rx) {
71+
entry = rt2x00queue_get_entry(queue, Q_INDEX);
72+
entry_priv = entry->priv_data;
73+
74+
if (rt2x00dev->ops->lib->get_entry_state(entry))
75+
break;
76+
77+
/*
78+
* Fill in desc fields of the skb descriptor
79+
*/
80+
skbdesc = get_skb_frame_desc(entry->skb);
81+
skbdesc->desc = entry_priv->desc;
82+
skbdesc->desc_len = entry->queue->desc_size;
83+
84+
/*
85+
* DMA is already done, notify rt2x00lib that
86+
* it finished successfully.
87+
*/
88+
rt2x00lib_dmastart(entry);
89+
rt2x00lib_dmadone(entry);
90+
91+
/*
92+
* Send the frame to rt2x00lib for further processing.
93+
*/
94+
rt2x00lib_rxdone(entry, GFP_ATOMIC);
95+
}
96+
97+
return !max_rx;
98+
}
99+
EXPORT_SYMBOL_GPL(rt2x00pci_rxdone);
100+
101+
void rt2x00pci_flush_queue(struct data_queue *queue, bool drop)
102+
{
103+
unsigned int i;
104+
105+
for (i = 0; !rt2x00queue_empty(queue) && i < 10; i++)
106+
msleep(10);
107+
}
108+
EXPORT_SYMBOL_GPL(rt2x00pci_flush_queue);
109+
110+
/*
111+
* Device initialization handlers.
112+
*/
113+
static int rt2x00pci_alloc_queue_dma(struct rt2x00_dev *rt2x00dev,
114+
struct data_queue *queue)
115+
{
116+
struct queue_entry_priv_pci *entry_priv;
117+
void *addr;
118+
dma_addr_t dma;
119+
unsigned int i;
120+
121+
/*
122+
* Allocate DMA memory for descriptor and buffer.
123+
*/
124+
addr = dma_alloc_coherent(rt2x00dev->dev,
125+
queue->limit * queue->desc_size,
126+
&dma, GFP_KERNEL);
127+
if (!addr)
128+
return -ENOMEM;
129+
130+
memset(addr, 0, queue->limit * queue->desc_size);
131+
132+
/*
133+
* Initialize all queue entries to contain valid addresses.
134+
*/
135+
for (i = 0; i < queue->limit; i++) {
136+
entry_priv = queue->entries[i].priv_data;
137+
entry_priv->desc = addr + i * queue->desc_size;
138+
entry_priv->desc_dma = dma + i * queue->desc_size;
139+
}
140+
141+
return 0;
142+
}
143+
144+
static void rt2x00pci_free_queue_dma(struct rt2x00_dev *rt2x00dev,
145+
struct data_queue *queue)
146+
{
147+
struct queue_entry_priv_pci *entry_priv =
148+
queue->entries[0].priv_data;
149+
150+
if (entry_priv->desc)
151+
dma_free_coherent(rt2x00dev->dev,
152+
queue->limit * queue->desc_size,
153+
entry_priv->desc, entry_priv->desc_dma);
154+
entry_priv->desc = NULL;
155+
}
156+
157+
int rt2x00pci_initialize(struct rt2x00_dev *rt2x00dev)
158+
{
159+
struct data_queue *queue;
160+
int status;
161+
162+
/*
163+
* Allocate DMA
164+
*/
165+
queue_for_each(rt2x00dev, queue) {
166+
status = rt2x00pci_alloc_queue_dma(rt2x00dev, queue);
167+
if (status)
168+
goto exit;
169+
}
170+
171+
/*
172+
* Register interrupt handler.
173+
*/
174+
status = request_irq(rt2x00dev->irq,
175+
rt2x00dev->ops->lib->irq_handler,
176+
IRQF_SHARED, rt2x00dev->name, rt2x00dev);
177+
if (status) {
178+
ERROR(rt2x00dev, "IRQ %d allocation failed (error %d).\n",
179+
rt2x00dev->irq, status);
180+
goto exit;
181+
}
182+
183+
return 0;
184+
185+
exit:
186+
queue_for_each(rt2x00dev, queue)
187+
rt2x00pci_free_queue_dma(rt2x00dev, queue);
188+
189+
return status;
190+
}
191+
EXPORT_SYMBOL_GPL(rt2x00pci_initialize);
192+
193+
void rt2x00pci_uninitialize(struct rt2x00_dev *rt2x00dev)
194+
{
195+
struct data_queue *queue;
196+
197+
/*
198+
* Free irq line.
199+
*/
200+
free_irq(rt2x00dev->irq, rt2x00dev);
201+
202+
/*
203+
* Free DMA
204+
*/
205+
queue_for_each(rt2x00dev, queue)
206+
rt2x00pci_free_queue_dma(rt2x00dev, queue);
207+
}
208+
EXPORT_SYMBOL_GPL(rt2x00pci_uninitialize);
209+
210+
/*
211+
* rt2x00mmio module information.
212+
*/
213+
MODULE_AUTHOR(DRV_PROJECT);
214+
MODULE_VERSION(DRV_VERSION);
215+
MODULE_DESCRIPTION("rt2x00 mmio library");
216+
MODULE_LICENSE("GPL");

0 commit comments

Comments
 (0)