Commit 65f6092517466fa18ad77743d39723787e8fa051
Committed by
David S. Miller
1 parent
32a6d90bb3
Exists in
smarc-l5.0.0_1.0.0-ga
and in
5 other branches
drivers/net: add missing __devexit_p() annotations
Drivers that refer to a __devexit function in an operations structure need to annotate that pointer with __devexit_p so replace it with a NULL pointer when the section gets discarded. Signed-off-by: Arnd Bergmann <arnd@arndb.de> Signed-off-by: Mathieu Poirier <mathieu.poirier@linaro.org> Signed-off-by: David S. Miller <davem@davemloft.net>
Showing 3 changed files with 3 additions and 3 deletions Inline Diff
drivers/net/ethernet/micrel/ks8842.c
1 | /* | 1 | /* |
2 | * ks8842.c timberdale KS8842 ethernet driver | 2 | * ks8842.c timberdale KS8842 ethernet driver |
3 | * Copyright (c) 2009 Intel Corporation | 3 | * Copyright (c) 2009 Intel Corporation |
4 | * | 4 | * |
5 | * This program is free software; you can redistribute it and/or modify | 5 | * This program is free software; you can redistribute it and/or modify |
6 | * it under the terms of the GNU General Public License version 2 as | 6 | * it under the terms of the GNU General Public License version 2 as |
7 | * published by the Free Software Foundation. | 7 | * published by the Free Software Foundation. |
8 | * | 8 | * |
9 | * This program is distributed in the hope that it will be useful, | 9 | * This program is distributed in the hope that it will be useful, |
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 | * GNU General Public License for more details. | 12 | * GNU General Public License for more details. |
13 | * | 13 | * |
14 | * You should have received a copy of the GNU General Public License | 14 | * You should have received a copy of the GNU General Public License |
15 | * along with this program; if not, write to the Free Software | 15 | * along with this program; if not, write to the Free Software |
16 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | 16 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
17 | */ | 17 | */ |
18 | 18 | ||
19 | /* Supports: | 19 | /* Supports: |
20 | * The Micrel KS8842 behind the timberdale FPGA | 20 | * The Micrel KS8842 behind the timberdale FPGA |
21 | * The genuine Micrel KS8841/42 device with ISA 16/32bit bus interface | 21 | * The genuine Micrel KS8841/42 device with ISA 16/32bit bus interface |
22 | */ | 22 | */ |
23 | 23 | ||
24 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt | 24 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
25 | 25 | ||
26 | #include <linux/interrupt.h> | 26 | #include <linux/interrupt.h> |
27 | #include <linux/kernel.h> | 27 | #include <linux/kernel.h> |
28 | #include <linux/module.h> | 28 | #include <linux/module.h> |
29 | #include <linux/platform_device.h> | 29 | #include <linux/platform_device.h> |
30 | #include <linux/netdevice.h> | 30 | #include <linux/netdevice.h> |
31 | #include <linux/etherdevice.h> | 31 | #include <linux/etherdevice.h> |
32 | #include <linux/ethtool.h> | 32 | #include <linux/ethtool.h> |
33 | #include <linux/ks8842.h> | 33 | #include <linux/ks8842.h> |
34 | #include <linux/dmaengine.h> | 34 | #include <linux/dmaengine.h> |
35 | #include <linux/dma-mapping.h> | 35 | #include <linux/dma-mapping.h> |
36 | #include <linux/scatterlist.h> | 36 | #include <linux/scatterlist.h> |
37 | 37 | ||
38 | #define DRV_NAME "ks8842" | 38 | #define DRV_NAME "ks8842" |
39 | 39 | ||
40 | /* Timberdale specific Registers */ | 40 | /* Timberdale specific Registers */ |
41 | #define REG_TIMB_RST 0x1c | 41 | #define REG_TIMB_RST 0x1c |
42 | #define REG_TIMB_FIFO 0x20 | 42 | #define REG_TIMB_FIFO 0x20 |
43 | #define REG_TIMB_ISR 0x24 | 43 | #define REG_TIMB_ISR 0x24 |
44 | #define REG_TIMB_IER 0x28 | 44 | #define REG_TIMB_IER 0x28 |
45 | #define REG_TIMB_IAR 0x2C | 45 | #define REG_TIMB_IAR 0x2C |
46 | #define REQ_TIMB_DMA_RESUME 0x30 | 46 | #define REQ_TIMB_DMA_RESUME 0x30 |
47 | 47 | ||
48 | /* KS8842 registers */ | 48 | /* KS8842 registers */ |
49 | 49 | ||
50 | #define REG_SELECT_BANK 0x0e | 50 | #define REG_SELECT_BANK 0x0e |
51 | 51 | ||
52 | /* bank 0 registers */ | 52 | /* bank 0 registers */ |
53 | #define REG_QRFCR 0x04 | 53 | #define REG_QRFCR 0x04 |
54 | 54 | ||
55 | /* bank 2 registers */ | 55 | /* bank 2 registers */ |
56 | #define REG_MARL 0x00 | 56 | #define REG_MARL 0x00 |
57 | #define REG_MARM 0x02 | 57 | #define REG_MARM 0x02 |
58 | #define REG_MARH 0x04 | 58 | #define REG_MARH 0x04 |
59 | 59 | ||
60 | /* bank 3 registers */ | 60 | /* bank 3 registers */ |
61 | #define REG_GRR 0x06 | 61 | #define REG_GRR 0x06 |
62 | 62 | ||
63 | /* bank 16 registers */ | 63 | /* bank 16 registers */ |
64 | #define REG_TXCR 0x00 | 64 | #define REG_TXCR 0x00 |
65 | #define REG_TXSR 0x02 | 65 | #define REG_TXSR 0x02 |
66 | #define REG_RXCR 0x04 | 66 | #define REG_RXCR 0x04 |
67 | #define REG_TXMIR 0x08 | 67 | #define REG_TXMIR 0x08 |
68 | #define REG_RXMIR 0x0A | 68 | #define REG_RXMIR 0x0A |
69 | 69 | ||
70 | /* bank 17 registers */ | 70 | /* bank 17 registers */ |
71 | #define REG_TXQCR 0x00 | 71 | #define REG_TXQCR 0x00 |
72 | #define REG_RXQCR 0x02 | 72 | #define REG_RXQCR 0x02 |
73 | #define REG_TXFDPR 0x04 | 73 | #define REG_TXFDPR 0x04 |
74 | #define REG_RXFDPR 0x06 | 74 | #define REG_RXFDPR 0x06 |
75 | #define REG_QMU_DATA_LO 0x08 | 75 | #define REG_QMU_DATA_LO 0x08 |
76 | #define REG_QMU_DATA_HI 0x0A | 76 | #define REG_QMU_DATA_HI 0x0A |
77 | 77 | ||
78 | /* bank 18 registers */ | 78 | /* bank 18 registers */ |
79 | #define REG_IER 0x00 | 79 | #define REG_IER 0x00 |
80 | #define IRQ_LINK_CHANGE 0x8000 | 80 | #define IRQ_LINK_CHANGE 0x8000 |
81 | #define IRQ_TX 0x4000 | 81 | #define IRQ_TX 0x4000 |
82 | #define IRQ_RX 0x2000 | 82 | #define IRQ_RX 0x2000 |
83 | #define IRQ_RX_OVERRUN 0x0800 | 83 | #define IRQ_RX_OVERRUN 0x0800 |
84 | #define IRQ_TX_STOPPED 0x0200 | 84 | #define IRQ_TX_STOPPED 0x0200 |
85 | #define IRQ_RX_STOPPED 0x0100 | 85 | #define IRQ_RX_STOPPED 0x0100 |
86 | #define IRQ_RX_ERROR 0x0080 | 86 | #define IRQ_RX_ERROR 0x0080 |
87 | #define ENABLED_IRQS (IRQ_LINK_CHANGE | IRQ_TX | IRQ_RX | IRQ_RX_STOPPED | \ | 87 | #define ENABLED_IRQS (IRQ_LINK_CHANGE | IRQ_TX | IRQ_RX | IRQ_RX_STOPPED | \ |
88 | IRQ_TX_STOPPED | IRQ_RX_OVERRUN | IRQ_RX_ERROR) | 88 | IRQ_TX_STOPPED | IRQ_RX_OVERRUN | IRQ_RX_ERROR) |
89 | /* When running via timberdale in DMA mode, the RX interrupt should be | 89 | /* When running via timberdale in DMA mode, the RX interrupt should be |
90 | enabled in the KS8842, but not in the FPGA IP, since the IP handles | 90 | enabled in the KS8842, but not in the FPGA IP, since the IP handles |
91 | RX DMA internally. | 91 | RX DMA internally. |
92 | TX interrupts are not needed it is handled by the FPGA the driver is | 92 | TX interrupts are not needed it is handled by the FPGA the driver is |
93 | notified via DMA callbacks. | 93 | notified via DMA callbacks. |
94 | */ | 94 | */ |
95 | #define ENABLED_IRQS_DMA_IP (IRQ_LINK_CHANGE | IRQ_RX_STOPPED | \ | 95 | #define ENABLED_IRQS_DMA_IP (IRQ_LINK_CHANGE | IRQ_RX_STOPPED | \ |
96 | IRQ_TX_STOPPED | IRQ_RX_OVERRUN | IRQ_RX_ERROR) | 96 | IRQ_TX_STOPPED | IRQ_RX_OVERRUN | IRQ_RX_ERROR) |
97 | #define ENABLED_IRQS_DMA (ENABLED_IRQS_DMA_IP | IRQ_RX) | 97 | #define ENABLED_IRQS_DMA (ENABLED_IRQS_DMA_IP | IRQ_RX) |
98 | #define REG_ISR 0x02 | 98 | #define REG_ISR 0x02 |
99 | #define REG_RXSR 0x04 | 99 | #define REG_RXSR 0x04 |
100 | #define RXSR_VALID 0x8000 | 100 | #define RXSR_VALID 0x8000 |
101 | #define RXSR_BROADCAST 0x80 | 101 | #define RXSR_BROADCAST 0x80 |
102 | #define RXSR_MULTICAST 0x40 | 102 | #define RXSR_MULTICAST 0x40 |
103 | #define RXSR_UNICAST 0x20 | 103 | #define RXSR_UNICAST 0x20 |
104 | #define RXSR_FRAMETYPE 0x08 | 104 | #define RXSR_FRAMETYPE 0x08 |
105 | #define RXSR_TOO_LONG 0x04 | 105 | #define RXSR_TOO_LONG 0x04 |
106 | #define RXSR_RUNT 0x02 | 106 | #define RXSR_RUNT 0x02 |
107 | #define RXSR_CRC_ERROR 0x01 | 107 | #define RXSR_CRC_ERROR 0x01 |
108 | #define RXSR_ERROR (RXSR_TOO_LONG | RXSR_RUNT | RXSR_CRC_ERROR) | 108 | #define RXSR_ERROR (RXSR_TOO_LONG | RXSR_RUNT | RXSR_CRC_ERROR) |
109 | 109 | ||
110 | /* bank 32 registers */ | 110 | /* bank 32 registers */ |
111 | #define REG_SW_ID_AND_ENABLE 0x00 | 111 | #define REG_SW_ID_AND_ENABLE 0x00 |
112 | #define REG_SGCR1 0x02 | 112 | #define REG_SGCR1 0x02 |
113 | #define REG_SGCR2 0x04 | 113 | #define REG_SGCR2 0x04 |
114 | #define REG_SGCR3 0x06 | 114 | #define REG_SGCR3 0x06 |
115 | 115 | ||
116 | /* bank 39 registers */ | 116 | /* bank 39 registers */ |
117 | #define REG_MACAR1 0x00 | 117 | #define REG_MACAR1 0x00 |
118 | #define REG_MACAR2 0x02 | 118 | #define REG_MACAR2 0x02 |
119 | #define REG_MACAR3 0x04 | 119 | #define REG_MACAR3 0x04 |
120 | 120 | ||
121 | /* bank 45 registers */ | 121 | /* bank 45 registers */ |
122 | #define REG_P1MBCR 0x00 | 122 | #define REG_P1MBCR 0x00 |
123 | #define REG_P1MBSR 0x02 | 123 | #define REG_P1MBSR 0x02 |
124 | 124 | ||
125 | /* bank 46 registers */ | 125 | /* bank 46 registers */ |
126 | #define REG_P2MBCR 0x00 | 126 | #define REG_P2MBCR 0x00 |
127 | #define REG_P2MBSR 0x02 | 127 | #define REG_P2MBSR 0x02 |
128 | 128 | ||
129 | /* bank 48 registers */ | 129 | /* bank 48 registers */ |
130 | #define REG_P1CR2 0x02 | 130 | #define REG_P1CR2 0x02 |
131 | 131 | ||
132 | /* bank 49 registers */ | 132 | /* bank 49 registers */ |
133 | #define REG_P1CR4 0x02 | 133 | #define REG_P1CR4 0x02 |
134 | #define REG_P1SR 0x04 | 134 | #define REG_P1SR 0x04 |
135 | 135 | ||
136 | /* flags passed by platform_device for configuration */ | 136 | /* flags passed by platform_device for configuration */ |
137 | #define MICREL_KS884X 0x01 /* 0=Timeberdale(FPGA), 1=Micrel */ | 137 | #define MICREL_KS884X 0x01 /* 0=Timeberdale(FPGA), 1=Micrel */ |
138 | #define KS884X_16BIT 0x02 /* 1=16bit, 0=32bit */ | 138 | #define KS884X_16BIT 0x02 /* 1=16bit, 0=32bit */ |
139 | 139 | ||
140 | #define DMA_BUFFER_SIZE 2048 | 140 | #define DMA_BUFFER_SIZE 2048 |
141 | 141 | ||
142 | struct ks8842_tx_dma_ctl { | 142 | struct ks8842_tx_dma_ctl { |
143 | struct dma_chan *chan; | 143 | struct dma_chan *chan; |
144 | struct dma_async_tx_descriptor *adesc; | 144 | struct dma_async_tx_descriptor *adesc; |
145 | void *buf; | 145 | void *buf; |
146 | struct scatterlist sg; | 146 | struct scatterlist sg; |
147 | int channel; | 147 | int channel; |
148 | }; | 148 | }; |
149 | 149 | ||
150 | struct ks8842_rx_dma_ctl { | 150 | struct ks8842_rx_dma_ctl { |
151 | struct dma_chan *chan; | 151 | struct dma_chan *chan; |
152 | struct dma_async_tx_descriptor *adesc; | 152 | struct dma_async_tx_descriptor *adesc; |
153 | struct sk_buff *skb; | 153 | struct sk_buff *skb; |
154 | struct scatterlist sg; | 154 | struct scatterlist sg; |
155 | struct tasklet_struct tasklet; | 155 | struct tasklet_struct tasklet; |
156 | int channel; | 156 | int channel; |
157 | }; | 157 | }; |
158 | 158 | ||
159 | #define KS8842_USE_DMA(adapter) (((adapter)->dma_tx.channel != -1) && \ | 159 | #define KS8842_USE_DMA(adapter) (((adapter)->dma_tx.channel != -1) && \ |
160 | ((adapter)->dma_rx.channel != -1)) | 160 | ((adapter)->dma_rx.channel != -1)) |
161 | 161 | ||
162 | struct ks8842_adapter { | 162 | struct ks8842_adapter { |
163 | void __iomem *hw_addr; | 163 | void __iomem *hw_addr; |
164 | int irq; | 164 | int irq; |
165 | unsigned long conf_flags; /* copy of platform_device config */ | 165 | unsigned long conf_flags; /* copy of platform_device config */ |
166 | struct tasklet_struct tasklet; | 166 | struct tasklet_struct tasklet; |
167 | spinlock_t lock; /* spinlock to be interrupt safe */ | 167 | spinlock_t lock; /* spinlock to be interrupt safe */ |
168 | struct work_struct timeout_work; | 168 | struct work_struct timeout_work; |
169 | struct net_device *netdev; | 169 | struct net_device *netdev; |
170 | struct device *dev; | 170 | struct device *dev; |
171 | struct ks8842_tx_dma_ctl dma_tx; | 171 | struct ks8842_tx_dma_ctl dma_tx; |
172 | struct ks8842_rx_dma_ctl dma_rx; | 172 | struct ks8842_rx_dma_ctl dma_rx; |
173 | }; | 173 | }; |
174 | 174 | ||
175 | static void ks8842_dma_rx_cb(void *data); | 175 | static void ks8842_dma_rx_cb(void *data); |
176 | static void ks8842_dma_tx_cb(void *data); | 176 | static void ks8842_dma_tx_cb(void *data); |
177 | 177 | ||
178 | static inline void ks8842_resume_dma(struct ks8842_adapter *adapter) | 178 | static inline void ks8842_resume_dma(struct ks8842_adapter *adapter) |
179 | { | 179 | { |
180 | iowrite32(1, adapter->hw_addr + REQ_TIMB_DMA_RESUME); | 180 | iowrite32(1, adapter->hw_addr + REQ_TIMB_DMA_RESUME); |
181 | } | 181 | } |
182 | 182 | ||
183 | static inline void ks8842_select_bank(struct ks8842_adapter *adapter, u16 bank) | 183 | static inline void ks8842_select_bank(struct ks8842_adapter *adapter, u16 bank) |
184 | { | 184 | { |
185 | iowrite16(bank, adapter->hw_addr + REG_SELECT_BANK); | 185 | iowrite16(bank, adapter->hw_addr + REG_SELECT_BANK); |
186 | } | 186 | } |
187 | 187 | ||
188 | static inline void ks8842_write8(struct ks8842_adapter *adapter, u16 bank, | 188 | static inline void ks8842_write8(struct ks8842_adapter *adapter, u16 bank, |
189 | u8 value, int offset) | 189 | u8 value, int offset) |
190 | { | 190 | { |
191 | ks8842_select_bank(adapter, bank); | 191 | ks8842_select_bank(adapter, bank); |
192 | iowrite8(value, adapter->hw_addr + offset); | 192 | iowrite8(value, adapter->hw_addr + offset); |
193 | } | 193 | } |
194 | 194 | ||
195 | static inline void ks8842_write16(struct ks8842_adapter *adapter, u16 bank, | 195 | static inline void ks8842_write16(struct ks8842_adapter *adapter, u16 bank, |
196 | u16 value, int offset) | 196 | u16 value, int offset) |
197 | { | 197 | { |
198 | ks8842_select_bank(adapter, bank); | 198 | ks8842_select_bank(adapter, bank); |
199 | iowrite16(value, adapter->hw_addr + offset); | 199 | iowrite16(value, adapter->hw_addr + offset); |
200 | } | 200 | } |
201 | 201 | ||
202 | static inline void ks8842_enable_bits(struct ks8842_adapter *adapter, u16 bank, | 202 | static inline void ks8842_enable_bits(struct ks8842_adapter *adapter, u16 bank, |
203 | u16 bits, int offset) | 203 | u16 bits, int offset) |
204 | { | 204 | { |
205 | u16 reg; | 205 | u16 reg; |
206 | ks8842_select_bank(adapter, bank); | 206 | ks8842_select_bank(adapter, bank); |
207 | reg = ioread16(adapter->hw_addr + offset); | 207 | reg = ioread16(adapter->hw_addr + offset); |
208 | reg |= bits; | 208 | reg |= bits; |
209 | iowrite16(reg, adapter->hw_addr + offset); | 209 | iowrite16(reg, adapter->hw_addr + offset); |
210 | } | 210 | } |
211 | 211 | ||
212 | static inline void ks8842_clear_bits(struct ks8842_adapter *adapter, u16 bank, | 212 | static inline void ks8842_clear_bits(struct ks8842_adapter *adapter, u16 bank, |
213 | u16 bits, int offset) | 213 | u16 bits, int offset) |
214 | { | 214 | { |
215 | u16 reg; | 215 | u16 reg; |
216 | ks8842_select_bank(adapter, bank); | 216 | ks8842_select_bank(adapter, bank); |
217 | reg = ioread16(adapter->hw_addr + offset); | 217 | reg = ioread16(adapter->hw_addr + offset); |
218 | reg &= ~bits; | 218 | reg &= ~bits; |
219 | iowrite16(reg, adapter->hw_addr + offset); | 219 | iowrite16(reg, adapter->hw_addr + offset); |
220 | } | 220 | } |
221 | 221 | ||
222 | static inline void ks8842_write32(struct ks8842_adapter *adapter, u16 bank, | 222 | static inline void ks8842_write32(struct ks8842_adapter *adapter, u16 bank, |
223 | u32 value, int offset) | 223 | u32 value, int offset) |
224 | { | 224 | { |
225 | ks8842_select_bank(adapter, bank); | 225 | ks8842_select_bank(adapter, bank); |
226 | iowrite32(value, adapter->hw_addr + offset); | 226 | iowrite32(value, adapter->hw_addr + offset); |
227 | } | 227 | } |
228 | 228 | ||
229 | static inline u8 ks8842_read8(struct ks8842_adapter *adapter, u16 bank, | 229 | static inline u8 ks8842_read8(struct ks8842_adapter *adapter, u16 bank, |
230 | int offset) | 230 | int offset) |
231 | { | 231 | { |
232 | ks8842_select_bank(adapter, bank); | 232 | ks8842_select_bank(adapter, bank); |
233 | return ioread8(adapter->hw_addr + offset); | 233 | return ioread8(adapter->hw_addr + offset); |
234 | } | 234 | } |
235 | 235 | ||
236 | static inline u16 ks8842_read16(struct ks8842_adapter *adapter, u16 bank, | 236 | static inline u16 ks8842_read16(struct ks8842_adapter *adapter, u16 bank, |
237 | int offset) | 237 | int offset) |
238 | { | 238 | { |
239 | ks8842_select_bank(adapter, bank); | 239 | ks8842_select_bank(adapter, bank); |
240 | return ioread16(adapter->hw_addr + offset); | 240 | return ioread16(adapter->hw_addr + offset); |
241 | } | 241 | } |
242 | 242 | ||
243 | static inline u32 ks8842_read32(struct ks8842_adapter *adapter, u16 bank, | 243 | static inline u32 ks8842_read32(struct ks8842_adapter *adapter, u16 bank, |
244 | int offset) | 244 | int offset) |
245 | { | 245 | { |
246 | ks8842_select_bank(adapter, bank); | 246 | ks8842_select_bank(adapter, bank); |
247 | return ioread32(adapter->hw_addr + offset); | 247 | return ioread32(adapter->hw_addr + offset); |
248 | } | 248 | } |
249 | 249 | ||
250 | static void ks8842_reset(struct ks8842_adapter *adapter) | 250 | static void ks8842_reset(struct ks8842_adapter *adapter) |
251 | { | 251 | { |
252 | if (adapter->conf_flags & MICREL_KS884X) { | 252 | if (adapter->conf_flags & MICREL_KS884X) { |
253 | ks8842_write16(adapter, 3, 1, REG_GRR); | 253 | ks8842_write16(adapter, 3, 1, REG_GRR); |
254 | msleep(10); | 254 | msleep(10); |
255 | iowrite16(0, adapter->hw_addr + REG_GRR); | 255 | iowrite16(0, adapter->hw_addr + REG_GRR); |
256 | } else { | 256 | } else { |
257 | /* The KS8842 goes haywire when doing softare reset | 257 | /* The KS8842 goes haywire when doing softare reset |
258 | * a work around in the timberdale IP is implemented to | 258 | * a work around in the timberdale IP is implemented to |
259 | * do a hardware reset instead | 259 | * do a hardware reset instead |
260 | ks8842_write16(adapter, 3, 1, REG_GRR); | 260 | ks8842_write16(adapter, 3, 1, REG_GRR); |
261 | msleep(10); | 261 | msleep(10); |
262 | iowrite16(0, adapter->hw_addr + REG_GRR); | 262 | iowrite16(0, adapter->hw_addr + REG_GRR); |
263 | */ | 263 | */ |
264 | iowrite32(0x1, adapter->hw_addr + REG_TIMB_RST); | 264 | iowrite32(0x1, adapter->hw_addr + REG_TIMB_RST); |
265 | msleep(20); | 265 | msleep(20); |
266 | } | 266 | } |
267 | } | 267 | } |
268 | 268 | ||
269 | static void ks8842_update_link_status(struct net_device *netdev, | 269 | static void ks8842_update_link_status(struct net_device *netdev, |
270 | struct ks8842_adapter *adapter) | 270 | struct ks8842_adapter *adapter) |
271 | { | 271 | { |
272 | /* check the status of the link */ | 272 | /* check the status of the link */ |
273 | if (ks8842_read16(adapter, 45, REG_P1MBSR) & 0x4) { | 273 | if (ks8842_read16(adapter, 45, REG_P1MBSR) & 0x4) { |
274 | netif_carrier_on(netdev); | 274 | netif_carrier_on(netdev); |
275 | netif_wake_queue(netdev); | 275 | netif_wake_queue(netdev); |
276 | } else { | 276 | } else { |
277 | netif_stop_queue(netdev); | 277 | netif_stop_queue(netdev); |
278 | netif_carrier_off(netdev); | 278 | netif_carrier_off(netdev); |
279 | } | 279 | } |
280 | } | 280 | } |
281 | 281 | ||
282 | static void ks8842_enable_tx(struct ks8842_adapter *adapter) | 282 | static void ks8842_enable_tx(struct ks8842_adapter *adapter) |
283 | { | 283 | { |
284 | ks8842_enable_bits(adapter, 16, 0x01, REG_TXCR); | 284 | ks8842_enable_bits(adapter, 16, 0x01, REG_TXCR); |
285 | } | 285 | } |
286 | 286 | ||
287 | static void ks8842_disable_tx(struct ks8842_adapter *adapter) | 287 | static void ks8842_disable_tx(struct ks8842_adapter *adapter) |
288 | { | 288 | { |
289 | ks8842_clear_bits(adapter, 16, 0x01, REG_TXCR); | 289 | ks8842_clear_bits(adapter, 16, 0x01, REG_TXCR); |
290 | } | 290 | } |
291 | 291 | ||
292 | static void ks8842_enable_rx(struct ks8842_adapter *adapter) | 292 | static void ks8842_enable_rx(struct ks8842_adapter *adapter) |
293 | { | 293 | { |
294 | ks8842_enable_bits(adapter, 16, 0x01, REG_RXCR); | 294 | ks8842_enable_bits(adapter, 16, 0x01, REG_RXCR); |
295 | } | 295 | } |
296 | 296 | ||
297 | static void ks8842_disable_rx(struct ks8842_adapter *adapter) | 297 | static void ks8842_disable_rx(struct ks8842_adapter *adapter) |
298 | { | 298 | { |
299 | ks8842_clear_bits(adapter, 16, 0x01, REG_RXCR); | 299 | ks8842_clear_bits(adapter, 16, 0x01, REG_RXCR); |
300 | } | 300 | } |
301 | 301 | ||
302 | static void ks8842_reset_hw(struct ks8842_adapter *adapter) | 302 | static void ks8842_reset_hw(struct ks8842_adapter *adapter) |
303 | { | 303 | { |
304 | /* reset the HW */ | 304 | /* reset the HW */ |
305 | ks8842_reset(adapter); | 305 | ks8842_reset(adapter); |
306 | 306 | ||
307 | /* Enable QMU Transmit flow control / transmit padding / Transmit CRC */ | 307 | /* Enable QMU Transmit flow control / transmit padding / Transmit CRC */ |
308 | ks8842_write16(adapter, 16, 0x000E, REG_TXCR); | 308 | ks8842_write16(adapter, 16, 0x000E, REG_TXCR); |
309 | 309 | ||
310 | /* enable the receiver, uni + multi + broadcast + flow ctrl | 310 | /* enable the receiver, uni + multi + broadcast + flow ctrl |
311 | + crc strip */ | 311 | + crc strip */ |
312 | ks8842_write16(adapter, 16, 0x8 | 0x20 | 0x40 | 0x80 | 0x400, | 312 | ks8842_write16(adapter, 16, 0x8 | 0x20 | 0x40 | 0x80 | 0x400, |
313 | REG_RXCR); | 313 | REG_RXCR); |
314 | 314 | ||
315 | /* TX frame pointer autoincrement */ | 315 | /* TX frame pointer autoincrement */ |
316 | ks8842_write16(adapter, 17, 0x4000, REG_TXFDPR); | 316 | ks8842_write16(adapter, 17, 0x4000, REG_TXFDPR); |
317 | 317 | ||
318 | /* RX frame pointer autoincrement */ | 318 | /* RX frame pointer autoincrement */ |
319 | ks8842_write16(adapter, 17, 0x4000, REG_RXFDPR); | 319 | ks8842_write16(adapter, 17, 0x4000, REG_RXFDPR); |
320 | 320 | ||
321 | /* RX 2 kb high watermark */ | 321 | /* RX 2 kb high watermark */ |
322 | ks8842_write16(adapter, 0, 0x1000, REG_QRFCR); | 322 | ks8842_write16(adapter, 0, 0x1000, REG_QRFCR); |
323 | 323 | ||
324 | /* aggressive back off in half duplex */ | 324 | /* aggressive back off in half duplex */ |
325 | ks8842_enable_bits(adapter, 32, 1 << 8, REG_SGCR1); | 325 | ks8842_enable_bits(adapter, 32, 1 << 8, REG_SGCR1); |
326 | 326 | ||
327 | /* enable no excessive collison drop */ | 327 | /* enable no excessive collison drop */ |
328 | ks8842_enable_bits(adapter, 32, 1 << 3, REG_SGCR2); | 328 | ks8842_enable_bits(adapter, 32, 1 << 3, REG_SGCR2); |
329 | 329 | ||
330 | /* Enable port 1 force flow control / back pressure / transmit / recv */ | 330 | /* Enable port 1 force flow control / back pressure / transmit / recv */ |
331 | ks8842_write16(adapter, 48, 0x1E07, REG_P1CR2); | 331 | ks8842_write16(adapter, 48, 0x1E07, REG_P1CR2); |
332 | 332 | ||
333 | /* restart port auto-negotiation */ | 333 | /* restart port auto-negotiation */ |
334 | ks8842_enable_bits(adapter, 49, 1 << 13, REG_P1CR4); | 334 | ks8842_enable_bits(adapter, 49, 1 << 13, REG_P1CR4); |
335 | 335 | ||
336 | /* Enable the transmitter */ | 336 | /* Enable the transmitter */ |
337 | ks8842_enable_tx(adapter); | 337 | ks8842_enable_tx(adapter); |
338 | 338 | ||
339 | /* Enable the receiver */ | 339 | /* Enable the receiver */ |
340 | ks8842_enable_rx(adapter); | 340 | ks8842_enable_rx(adapter); |
341 | 341 | ||
342 | /* clear all interrupts */ | 342 | /* clear all interrupts */ |
343 | ks8842_write16(adapter, 18, 0xffff, REG_ISR); | 343 | ks8842_write16(adapter, 18, 0xffff, REG_ISR); |
344 | 344 | ||
345 | /* enable interrupts */ | 345 | /* enable interrupts */ |
346 | if (KS8842_USE_DMA(adapter)) { | 346 | if (KS8842_USE_DMA(adapter)) { |
347 | /* When running in DMA Mode the RX interrupt is not enabled in | 347 | /* When running in DMA Mode the RX interrupt is not enabled in |
348 | timberdale because RX data is received by DMA callbacks | 348 | timberdale because RX data is received by DMA callbacks |
349 | it must still be enabled in the KS8842 because it indicates | 349 | it must still be enabled in the KS8842 because it indicates |
350 | to timberdale when there is RX data for it's DMA FIFOs */ | 350 | to timberdale when there is RX data for it's DMA FIFOs */ |
351 | iowrite16(ENABLED_IRQS_DMA_IP, adapter->hw_addr + REG_TIMB_IER); | 351 | iowrite16(ENABLED_IRQS_DMA_IP, adapter->hw_addr + REG_TIMB_IER); |
352 | ks8842_write16(adapter, 18, ENABLED_IRQS_DMA, REG_IER); | 352 | ks8842_write16(adapter, 18, ENABLED_IRQS_DMA, REG_IER); |
353 | } else { | 353 | } else { |
354 | if (!(adapter->conf_flags & MICREL_KS884X)) | 354 | if (!(adapter->conf_flags & MICREL_KS884X)) |
355 | iowrite16(ENABLED_IRQS, | 355 | iowrite16(ENABLED_IRQS, |
356 | adapter->hw_addr + REG_TIMB_IER); | 356 | adapter->hw_addr + REG_TIMB_IER); |
357 | ks8842_write16(adapter, 18, ENABLED_IRQS, REG_IER); | 357 | ks8842_write16(adapter, 18, ENABLED_IRQS, REG_IER); |
358 | } | 358 | } |
359 | /* enable the switch */ | 359 | /* enable the switch */ |
360 | ks8842_write16(adapter, 32, 0x1, REG_SW_ID_AND_ENABLE); | 360 | ks8842_write16(adapter, 32, 0x1, REG_SW_ID_AND_ENABLE); |
361 | } | 361 | } |
362 | 362 | ||
363 | static void ks8842_read_mac_addr(struct ks8842_adapter *adapter, u8 *dest) | 363 | static void ks8842_read_mac_addr(struct ks8842_adapter *adapter, u8 *dest) |
364 | { | 364 | { |
365 | int i; | 365 | int i; |
366 | u16 mac; | 366 | u16 mac; |
367 | 367 | ||
368 | for (i = 0; i < ETH_ALEN; i++) | 368 | for (i = 0; i < ETH_ALEN; i++) |
369 | dest[ETH_ALEN - i - 1] = ks8842_read8(adapter, 2, REG_MARL + i); | 369 | dest[ETH_ALEN - i - 1] = ks8842_read8(adapter, 2, REG_MARL + i); |
370 | 370 | ||
371 | if (adapter->conf_flags & MICREL_KS884X) { | 371 | if (adapter->conf_flags & MICREL_KS884X) { |
372 | /* | 372 | /* |
373 | the sequence of saving mac addr between MAC and Switch is | 373 | the sequence of saving mac addr between MAC and Switch is |
374 | different. | 374 | different. |
375 | */ | 375 | */ |
376 | 376 | ||
377 | mac = ks8842_read16(adapter, 2, REG_MARL); | 377 | mac = ks8842_read16(adapter, 2, REG_MARL); |
378 | ks8842_write16(adapter, 39, mac, REG_MACAR3); | 378 | ks8842_write16(adapter, 39, mac, REG_MACAR3); |
379 | mac = ks8842_read16(adapter, 2, REG_MARM); | 379 | mac = ks8842_read16(adapter, 2, REG_MARM); |
380 | ks8842_write16(adapter, 39, mac, REG_MACAR2); | 380 | ks8842_write16(adapter, 39, mac, REG_MACAR2); |
381 | mac = ks8842_read16(adapter, 2, REG_MARH); | 381 | mac = ks8842_read16(adapter, 2, REG_MARH); |
382 | ks8842_write16(adapter, 39, mac, REG_MACAR1); | 382 | ks8842_write16(adapter, 39, mac, REG_MACAR1); |
383 | } else { | 383 | } else { |
384 | 384 | ||
385 | /* make sure the switch port uses the same MAC as the QMU */ | 385 | /* make sure the switch port uses the same MAC as the QMU */ |
386 | mac = ks8842_read16(adapter, 2, REG_MARL); | 386 | mac = ks8842_read16(adapter, 2, REG_MARL); |
387 | ks8842_write16(adapter, 39, mac, REG_MACAR1); | 387 | ks8842_write16(adapter, 39, mac, REG_MACAR1); |
388 | mac = ks8842_read16(adapter, 2, REG_MARM); | 388 | mac = ks8842_read16(adapter, 2, REG_MARM); |
389 | ks8842_write16(adapter, 39, mac, REG_MACAR2); | 389 | ks8842_write16(adapter, 39, mac, REG_MACAR2); |
390 | mac = ks8842_read16(adapter, 2, REG_MARH); | 390 | mac = ks8842_read16(adapter, 2, REG_MARH); |
391 | ks8842_write16(adapter, 39, mac, REG_MACAR3); | 391 | ks8842_write16(adapter, 39, mac, REG_MACAR3); |
392 | } | 392 | } |
393 | } | 393 | } |
394 | 394 | ||
395 | static void ks8842_write_mac_addr(struct ks8842_adapter *adapter, u8 *mac) | 395 | static void ks8842_write_mac_addr(struct ks8842_adapter *adapter, u8 *mac) |
396 | { | 396 | { |
397 | unsigned long flags; | 397 | unsigned long flags; |
398 | unsigned i; | 398 | unsigned i; |
399 | 399 | ||
400 | spin_lock_irqsave(&adapter->lock, flags); | 400 | spin_lock_irqsave(&adapter->lock, flags); |
401 | for (i = 0; i < ETH_ALEN; i++) { | 401 | for (i = 0; i < ETH_ALEN; i++) { |
402 | ks8842_write8(adapter, 2, mac[ETH_ALEN - i - 1], REG_MARL + i); | 402 | ks8842_write8(adapter, 2, mac[ETH_ALEN - i - 1], REG_MARL + i); |
403 | if (!(adapter->conf_flags & MICREL_KS884X)) | 403 | if (!(adapter->conf_flags & MICREL_KS884X)) |
404 | ks8842_write8(adapter, 39, mac[ETH_ALEN - i - 1], | 404 | ks8842_write8(adapter, 39, mac[ETH_ALEN - i - 1], |
405 | REG_MACAR1 + i); | 405 | REG_MACAR1 + i); |
406 | } | 406 | } |
407 | 407 | ||
408 | if (adapter->conf_flags & MICREL_KS884X) { | 408 | if (adapter->conf_flags & MICREL_KS884X) { |
409 | /* | 409 | /* |
410 | the sequence of saving mac addr between MAC and Switch is | 410 | the sequence of saving mac addr between MAC and Switch is |
411 | different. | 411 | different. |
412 | */ | 412 | */ |
413 | 413 | ||
414 | u16 mac; | 414 | u16 mac; |
415 | 415 | ||
416 | mac = ks8842_read16(adapter, 2, REG_MARL); | 416 | mac = ks8842_read16(adapter, 2, REG_MARL); |
417 | ks8842_write16(adapter, 39, mac, REG_MACAR3); | 417 | ks8842_write16(adapter, 39, mac, REG_MACAR3); |
418 | mac = ks8842_read16(adapter, 2, REG_MARM); | 418 | mac = ks8842_read16(adapter, 2, REG_MARM); |
419 | ks8842_write16(adapter, 39, mac, REG_MACAR2); | 419 | ks8842_write16(adapter, 39, mac, REG_MACAR2); |
420 | mac = ks8842_read16(adapter, 2, REG_MARH); | 420 | mac = ks8842_read16(adapter, 2, REG_MARH); |
421 | ks8842_write16(adapter, 39, mac, REG_MACAR1); | 421 | ks8842_write16(adapter, 39, mac, REG_MACAR1); |
422 | } | 422 | } |
423 | spin_unlock_irqrestore(&adapter->lock, flags); | 423 | spin_unlock_irqrestore(&adapter->lock, flags); |
424 | } | 424 | } |
425 | 425 | ||
426 | static inline u16 ks8842_tx_fifo_space(struct ks8842_adapter *adapter) | 426 | static inline u16 ks8842_tx_fifo_space(struct ks8842_adapter *adapter) |
427 | { | 427 | { |
428 | return ks8842_read16(adapter, 16, REG_TXMIR) & 0x1fff; | 428 | return ks8842_read16(adapter, 16, REG_TXMIR) & 0x1fff; |
429 | } | 429 | } |
430 | 430 | ||
431 | static int ks8842_tx_frame_dma(struct sk_buff *skb, struct net_device *netdev) | 431 | static int ks8842_tx_frame_dma(struct sk_buff *skb, struct net_device *netdev) |
432 | { | 432 | { |
433 | struct ks8842_adapter *adapter = netdev_priv(netdev); | 433 | struct ks8842_adapter *adapter = netdev_priv(netdev); |
434 | struct ks8842_tx_dma_ctl *ctl = &adapter->dma_tx; | 434 | struct ks8842_tx_dma_ctl *ctl = &adapter->dma_tx; |
435 | u8 *buf = ctl->buf; | 435 | u8 *buf = ctl->buf; |
436 | 436 | ||
437 | if (ctl->adesc) { | 437 | if (ctl->adesc) { |
438 | netdev_dbg(netdev, "%s: TX ongoing\n", __func__); | 438 | netdev_dbg(netdev, "%s: TX ongoing\n", __func__); |
439 | /* transfer ongoing */ | 439 | /* transfer ongoing */ |
440 | return NETDEV_TX_BUSY; | 440 | return NETDEV_TX_BUSY; |
441 | } | 441 | } |
442 | 442 | ||
443 | sg_dma_len(&ctl->sg) = skb->len + sizeof(u32); | 443 | sg_dma_len(&ctl->sg) = skb->len + sizeof(u32); |
444 | 444 | ||
445 | /* copy data to the TX buffer */ | 445 | /* copy data to the TX buffer */ |
446 | /* the control word, enable IRQ, port 1 and the length */ | 446 | /* the control word, enable IRQ, port 1 and the length */ |
447 | *buf++ = 0x00; | 447 | *buf++ = 0x00; |
448 | *buf++ = 0x01; /* Port 1 */ | 448 | *buf++ = 0x01; /* Port 1 */ |
449 | *buf++ = skb->len & 0xff; | 449 | *buf++ = skb->len & 0xff; |
450 | *buf++ = (skb->len >> 8) & 0xff; | 450 | *buf++ = (skb->len >> 8) & 0xff; |
451 | skb_copy_from_linear_data(skb, buf, skb->len); | 451 | skb_copy_from_linear_data(skb, buf, skb->len); |
452 | 452 | ||
453 | dma_sync_single_range_for_device(adapter->dev, | 453 | dma_sync_single_range_for_device(adapter->dev, |
454 | sg_dma_address(&ctl->sg), 0, sg_dma_len(&ctl->sg), | 454 | sg_dma_address(&ctl->sg), 0, sg_dma_len(&ctl->sg), |
455 | DMA_TO_DEVICE); | 455 | DMA_TO_DEVICE); |
456 | 456 | ||
457 | /* make sure the length is a multiple of 4 */ | 457 | /* make sure the length is a multiple of 4 */ |
458 | if (sg_dma_len(&ctl->sg) % 4) | 458 | if (sg_dma_len(&ctl->sg) % 4) |
459 | sg_dma_len(&ctl->sg) += 4 - sg_dma_len(&ctl->sg) % 4; | 459 | sg_dma_len(&ctl->sg) += 4 - sg_dma_len(&ctl->sg) % 4; |
460 | 460 | ||
461 | ctl->adesc = dmaengine_prep_slave_sg(ctl->chan, | 461 | ctl->adesc = dmaengine_prep_slave_sg(ctl->chan, |
462 | &ctl->sg, 1, DMA_MEM_TO_DEV, | 462 | &ctl->sg, 1, DMA_MEM_TO_DEV, |
463 | DMA_PREP_INTERRUPT | DMA_COMPL_SKIP_SRC_UNMAP); | 463 | DMA_PREP_INTERRUPT | DMA_COMPL_SKIP_SRC_UNMAP); |
464 | if (!ctl->adesc) | 464 | if (!ctl->adesc) |
465 | return NETDEV_TX_BUSY; | 465 | return NETDEV_TX_BUSY; |
466 | 466 | ||
467 | ctl->adesc->callback_param = netdev; | 467 | ctl->adesc->callback_param = netdev; |
468 | ctl->adesc->callback = ks8842_dma_tx_cb; | 468 | ctl->adesc->callback = ks8842_dma_tx_cb; |
469 | ctl->adesc->tx_submit(ctl->adesc); | 469 | ctl->adesc->tx_submit(ctl->adesc); |
470 | 470 | ||
471 | netdev->stats.tx_bytes += skb->len; | 471 | netdev->stats.tx_bytes += skb->len; |
472 | 472 | ||
473 | dev_kfree_skb(skb); | 473 | dev_kfree_skb(skb); |
474 | 474 | ||
475 | return NETDEV_TX_OK; | 475 | return NETDEV_TX_OK; |
476 | } | 476 | } |
477 | 477 | ||
478 | static int ks8842_tx_frame(struct sk_buff *skb, struct net_device *netdev) | 478 | static int ks8842_tx_frame(struct sk_buff *skb, struct net_device *netdev) |
479 | { | 479 | { |
480 | struct ks8842_adapter *adapter = netdev_priv(netdev); | 480 | struct ks8842_adapter *adapter = netdev_priv(netdev); |
481 | int len = skb->len; | 481 | int len = skb->len; |
482 | 482 | ||
483 | netdev_dbg(netdev, "%s: len %u head %p data %p tail %p end %p\n", | 483 | netdev_dbg(netdev, "%s: len %u head %p data %p tail %p end %p\n", |
484 | __func__, skb->len, skb->head, skb->data, | 484 | __func__, skb->len, skb->head, skb->data, |
485 | skb_tail_pointer(skb), skb_end_pointer(skb)); | 485 | skb_tail_pointer(skb), skb_end_pointer(skb)); |
486 | 486 | ||
487 | /* check FIFO buffer space, we need space for CRC and command bits */ | 487 | /* check FIFO buffer space, we need space for CRC and command bits */ |
488 | if (ks8842_tx_fifo_space(adapter) < len + 8) | 488 | if (ks8842_tx_fifo_space(adapter) < len + 8) |
489 | return NETDEV_TX_BUSY; | 489 | return NETDEV_TX_BUSY; |
490 | 490 | ||
491 | if (adapter->conf_flags & KS884X_16BIT) { | 491 | if (adapter->conf_flags & KS884X_16BIT) { |
492 | u16 *ptr16 = (u16 *)skb->data; | 492 | u16 *ptr16 = (u16 *)skb->data; |
493 | ks8842_write16(adapter, 17, 0x8000 | 0x100, REG_QMU_DATA_LO); | 493 | ks8842_write16(adapter, 17, 0x8000 | 0x100, REG_QMU_DATA_LO); |
494 | ks8842_write16(adapter, 17, (u16)len, REG_QMU_DATA_HI); | 494 | ks8842_write16(adapter, 17, (u16)len, REG_QMU_DATA_HI); |
495 | netdev->stats.tx_bytes += len; | 495 | netdev->stats.tx_bytes += len; |
496 | 496 | ||
497 | /* copy buffer */ | 497 | /* copy buffer */ |
498 | while (len > 0) { | 498 | while (len > 0) { |
499 | iowrite16(*ptr16++, adapter->hw_addr + REG_QMU_DATA_LO); | 499 | iowrite16(*ptr16++, adapter->hw_addr + REG_QMU_DATA_LO); |
500 | iowrite16(*ptr16++, adapter->hw_addr + REG_QMU_DATA_HI); | 500 | iowrite16(*ptr16++, adapter->hw_addr + REG_QMU_DATA_HI); |
501 | len -= sizeof(u32); | 501 | len -= sizeof(u32); |
502 | } | 502 | } |
503 | } else { | 503 | } else { |
504 | 504 | ||
505 | u32 *ptr = (u32 *)skb->data; | 505 | u32 *ptr = (u32 *)skb->data; |
506 | u32 ctrl; | 506 | u32 ctrl; |
507 | /* the control word, enable IRQ, port 1 and the length */ | 507 | /* the control word, enable IRQ, port 1 and the length */ |
508 | ctrl = 0x8000 | 0x100 | (len << 16); | 508 | ctrl = 0x8000 | 0x100 | (len << 16); |
509 | ks8842_write32(adapter, 17, ctrl, REG_QMU_DATA_LO); | 509 | ks8842_write32(adapter, 17, ctrl, REG_QMU_DATA_LO); |
510 | 510 | ||
511 | netdev->stats.tx_bytes += len; | 511 | netdev->stats.tx_bytes += len; |
512 | 512 | ||
513 | /* copy buffer */ | 513 | /* copy buffer */ |
514 | while (len > 0) { | 514 | while (len > 0) { |
515 | iowrite32(*ptr, adapter->hw_addr + REG_QMU_DATA_LO); | 515 | iowrite32(*ptr, adapter->hw_addr + REG_QMU_DATA_LO); |
516 | len -= sizeof(u32); | 516 | len -= sizeof(u32); |
517 | ptr++; | 517 | ptr++; |
518 | } | 518 | } |
519 | } | 519 | } |
520 | 520 | ||
521 | /* enqueue packet */ | 521 | /* enqueue packet */ |
522 | ks8842_write16(adapter, 17, 1, REG_TXQCR); | 522 | ks8842_write16(adapter, 17, 1, REG_TXQCR); |
523 | 523 | ||
524 | dev_kfree_skb(skb); | 524 | dev_kfree_skb(skb); |
525 | 525 | ||
526 | return NETDEV_TX_OK; | 526 | return NETDEV_TX_OK; |
527 | } | 527 | } |
528 | 528 | ||
529 | static void ks8842_update_rx_err_counters(struct net_device *netdev, u32 status) | 529 | static void ks8842_update_rx_err_counters(struct net_device *netdev, u32 status) |
530 | { | 530 | { |
531 | netdev_dbg(netdev, "RX error, status: %x\n", status); | 531 | netdev_dbg(netdev, "RX error, status: %x\n", status); |
532 | 532 | ||
533 | netdev->stats.rx_errors++; | 533 | netdev->stats.rx_errors++; |
534 | if (status & RXSR_TOO_LONG) | 534 | if (status & RXSR_TOO_LONG) |
535 | netdev->stats.rx_length_errors++; | 535 | netdev->stats.rx_length_errors++; |
536 | if (status & RXSR_CRC_ERROR) | 536 | if (status & RXSR_CRC_ERROR) |
537 | netdev->stats.rx_crc_errors++; | 537 | netdev->stats.rx_crc_errors++; |
538 | if (status & RXSR_RUNT) | 538 | if (status & RXSR_RUNT) |
539 | netdev->stats.rx_frame_errors++; | 539 | netdev->stats.rx_frame_errors++; |
540 | } | 540 | } |
541 | 541 | ||
542 | static void ks8842_update_rx_counters(struct net_device *netdev, u32 status, | 542 | static void ks8842_update_rx_counters(struct net_device *netdev, u32 status, |
543 | int len) | 543 | int len) |
544 | { | 544 | { |
545 | netdev_dbg(netdev, "RX packet, len: %d\n", len); | 545 | netdev_dbg(netdev, "RX packet, len: %d\n", len); |
546 | 546 | ||
547 | netdev->stats.rx_packets++; | 547 | netdev->stats.rx_packets++; |
548 | netdev->stats.rx_bytes += len; | 548 | netdev->stats.rx_bytes += len; |
549 | if (status & RXSR_MULTICAST) | 549 | if (status & RXSR_MULTICAST) |
550 | netdev->stats.multicast++; | 550 | netdev->stats.multicast++; |
551 | } | 551 | } |
552 | 552 | ||
553 | static int __ks8842_start_new_rx_dma(struct net_device *netdev) | 553 | static int __ks8842_start_new_rx_dma(struct net_device *netdev) |
554 | { | 554 | { |
555 | struct ks8842_adapter *adapter = netdev_priv(netdev); | 555 | struct ks8842_adapter *adapter = netdev_priv(netdev); |
556 | struct ks8842_rx_dma_ctl *ctl = &adapter->dma_rx; | 556 | struct ks8842_rx_dma_ctl *ctl = &adapter->dma_rx; |
557 | struct scatterlist *sg = &ctl->sg; | 557 | struct scatterlist *sg = &ctl->sg; |
558 | int err; | 558 | int err; |
559 | 559 | ||
560 | ctl->skb = netdev_alloc_skb(netdev, DMA_BUFFER_SIZE); | 560 | ctl->skb = netdev_alloc_skb(netdev, DMA_BUFFER_SIZE); |
561 | if (ctl->skb) { | 561 | if (ctl->skb) { |
562 | sg_init_table(sg, 1); | 562 | sg_init_table(sg, 1); |
563 | sg_dma_address(sg) = dma_map_single(adapter->dev, | 563 | sg_dma_address(sg) = dma_map_single(adapter->dev, |
564 | ctl->skb->data, DMA_BUFFER_SIZE, DMA_FROM_DEVICE); | 564 | ctl->skb->data, DMA_BUFFER_SIZE, DMA_FROM_DEVICE); |
565 | err = dma_mapping_error(adapter->dev, sg_dma_address(sg)); | 565 | err = dma_mapping_error(adapter->dev, sg_dma_address(sg)); |
566 | if (unlikely(err)) { | 566 | if (unlikely(err)) { |
567 | sg_dma_address(sg) = 0; | 567 | sg_dma_address(sg) = 0; |
568 | goto out; | 568 | goto out; |
569 | } | 569 | } |
570 | 570 | ||
571 | sg_dma_len(sg) = DMA_BUFFER_SIZE; | 571 | sg_dma_len(sg) = DMA_BUFFER_SIZE; |
572 | 572 | ||
573 | ctl->adesc = dmaengine_prep_slave_sg(ctl->chan, | 573 | ctl->adesc = dmaengine_prep_slave_sg(ctl->chan, |
574 | sg, 1, DMA_DEV_TO_MEM, | 574 | sg, 1, DMA_DEV_TO_MEM, |
575 | DMA_PREP_INTERRUPT | DMA_COMPL_SKIP_SRC_UNMAP); | 575 | DMA_PREP_INTERRUPT | DMA_COMPL_SKIP_SRC_UNMAP); |
576 | 576 | ||
577 | if (!ctl->adesc) | 577 | if (!ctl->adesc) |
578 | goto out; | 578 | goto out; |
579 | 579 | ||
580 | ctl->adesc->callback_param = netdev; | 580 | ctl->adesc->callback_param = netdev; |
581 | ctl->adesc->callback = ks8842_dma_rx_cb; | 581 | ctl->adesc->callback = ks8842_dma_rx_cb; |
582 | ctl->adesc->tx_submit(ctl->adesc); | 582 | ctl->adesc->tx_submit(ctl->adesc); |
583 | } else { | 583 | } else { |
584 | err = -ENOMEM; | 584 | err = -ENOMEM; |
585 | sg_dma_address(sg) = 0; | 585 | sg_dma_address(sg) = 0; |
586 | goto out; | 586 | goto out; |
587 | } | 587 | } |
588 | 588 | ||
589 | return err; | 589 | return err; |
590 | out: | 590 | out: |
591 | if (sg_dma_address(sg)) | 591 | if (sg_dma_address(sg)) |
592 | dma_unmap_single(adapter->dev, sg_dma_address(sg), | 592 | dma_unmap_single(adapter->dev, sg_dma_address(sg), |
593 | DMA_BUFFER_SIZE, DMA_FROM_DEVICE); | 593 | DMA_BUFFER_SIZE, DMA_FROM_DEVICE); |
594 | sg_dma_address(sg) = 0; | 594 | sg_dma_address(sg) = 0; |
595 | if (ctl->skb) | 595 | if (ctl->skb) |
596 | dev_kfree_skb(ctl->skb); | 596 | dev_kfree_skb(ctl->skb); |
597 | 597 | ||
598 | ctl->skb = NULL; | 598 | ctl->skb = NULL; |
599 | 599 | ||
600 | printk(KERN_ERR DRV_NAME": Failed to start RX DMA: %d\n", err); | 600 | printk(KERN_ERR DRV_NAME": Failed to start RX DMA: %d\n", err); |
601 | return err; | 601 | return err; |
602 | } | 602 | } |
603 | 603 | ||
604 | static void ks8842_rx_frame_dma_tasklet(unsigned long arg) | 604 | static void ks8842_rx_frame_dma_tasklet(unsigned long arg) |
605 | { | 605 | { |
606 | struct net_device *netdev = (struct net_device *)arg; | 606 | struct net_device *netdev = (struct net_device *)arg; |
607 | struct ks8842_adapter *adapter = netdev_priv(netdev); | 607 | struct ks8842_adapter *adapter = netdev_priv(netdev); |
608 | struct ks8842_rx_dma_ctl *ctl = &adapter->dma_rx; | 608 | struct ks8842_rx_dma_ctl *ctl = &adapter->dma_rx; |
609 | struct sk_buff *skb = ctl->skb; | 609 | struct sk_buff *skb = ctl->skb; |
610 | dma_addr_t addr = sg_dma_address(&ctl->sg); | 610 | dma_addr_t addr = sg_dma_address(&ctl->sg); |
611 | u32 status; | 611 | u32 status; |
612 | 612 | ||
613 | ctl->adesc = NULL; | 613 | ctl->adesc = NULL; |
614 | 614 | ||
615 | /* kick next transfer going */ | 615 | /* kick next transfer going */ |
616 | __ks8842_start_new_rx_dma(netdev); | 616 | __ks8842_start_new_rx_dma(netdev); |
617 | 617 | ||
618 | /* now handle the data we got */ | 618 | /* now handle the data we got */ |
619 | dma_unmap_single(adapter->dev, addr, DMA_BUFFER_SIZE, DMA_FROM_DEVICE); | 619 | dma_unmap_single(adapter->dev, addr, DMA_BUFFER_SIZE, DMA_FROM_DEVICE); |
620 | 620 | ||
621 | status = *((u32 *)skb->data); | 621 | status = *((u32 *)skb->data); |
622 | 622 | ||
623 | netdev_dbg(netdev, "%s - rx_data: status: %x\n", | 623 | netdev_dbg(netdev, "%s - rx_data: status: %x\n", |
624 | __func__, status & 0xffff); | 624 | __func__, status & 0xffff); |
625 | 625 | ||
626 | /* check the status */ | 626 | /* check the status */ |
627 | if ((status & RXSR_VALID) && !(status & RXSR_ERROR)) { | 627 | if ((status & RXSR_VALID) && !(status & RXSR_ERROR)) { |
628 | int len = (status >> 16) & 0x7ff; | 628 | int len = (status >> 16) & 0x7ff; |
629 | 629 | ||
630 | ks8842_update_rx_counters(netdev, status, len); | 630 | ks8842_update_rx_counters(netdev, status, len); |
631 | 631 | ||
632 | /* reserve 4 bytes which is the status word */ | 632 | /* reserve 4 bytes which is the status word */ |
633 | skb_reserve(skb, 4); | 633 | skb_reserve(skb, 4); |
634 | skb_put(skb, len); | 634 | skb_put(skb, len); |
635 | 635 | ||
636 | skb->protocol = eth_type_trans(skb, netdev); | 636 | skb->protocol = eth_type_trans(skb, netdev); |
637 | netif_rx(skb); | 637 | netif_rx(skb); |
638 | } else { | 638 | } else { |
639 | ks8842_update_rx_err_counters(netdev, status); | 639 | ks8842_update_rx_err_counters(netdev, status); |
640 | dev_kfree_skb(skb); | 640 | dev_kfree_skb(skb); |
641 | } | 641 | } |
642 | } | 642 | } |
643 | 643 | ||
644 | static void ks8842_rx_frame(struct net_device *netdev, | 644 | static void ks8842_rx_frame(struct net_device *netdev, |
645 | struct ks8842_adapter *adapter) | 645 | struct ks8842_adapter *adapter) |
646 | { | 646 | { |
647 | u32 status; | 647 | u32 status; |
648 | int len; | 648 | int len; |
649 | 649 | ||
650 | if (adapter->conf_flags & KS884X_16BIT) { | 650 | if (adapter->conf_flags & KS884X_16BIT) { |
651 | status = ks8842_read16(adapter, 17, REG_QMU_DATA_LO); | 651 | status = ks8842_read16(adapter, 17, REG_QMU_DATA_LO); |
652 | len = ks8842_read16(adapter, 17, REG_QMU_DATA_HI); | 652 | len = ks8842_read16(adapter, 17, REG_QMU_DATA_HI); |
653 | netdev_dbg(netdev, "%s - rx_data: status: %x\n", | 653 | netdev_dbg(netdev, "%s - rx_data: status: %x\n", |
654 | __func__, status); | 654 | __func__, status); |
655 | } else { | 655 | } else { |
656 | status = ks8842_read32(adapter, 17, REG_QMU_DATA_LO); | 656 | status = ks8842_read32(adapter, 17, REG_QMU_DATA_LO); |
657 | len = (status >> 16) & 0x7ff; | 657 | len = (status >> 16) & 0x7ff; |
658 | status &= 0xffff; | 658 | status &= 0xffff; |
659 | netdev_dbg(netdev, "%s - rx_data: status: %x\n", | 659 | netdev_dbg(netdev, "%s - rx_data: status: %x\n", |
660 | __func__, status); | 660 | __func__, status); |
661 | } | 661 | } |
662 | 662 | ||
663 | /* check the status */ | 663 | /* check the status */ |
664 | if ((status & RXSR_VALID) && !(status & RXSR_ERROR)) { | 664 | if ((status & RXSR_VALID) && !(status & RXSR_ERROR)) { |
665 | struct sk_buff *skb = netdev_alloc_skb_ip_align(netdev, len + 3); | 665 | struct sk_buff *skb = netdev_alloc_skb_ip_align(netdev, len + 3); |
666 | 666 | ||
667 | if (skb) { | 667 | if (skb) { |
668 | 668 | ||
669 | ks8842_update_rx_counters(netdev, status, len); | 669 | ks8842_update_rx_counters(netdev, status, len); |
670 | 670 | ||
671 | if (adapter->conf_flags & KS884X_16BIT) { | 671 | if (adapter->conf_flags & KS884X_16BIT) { |
672 | u16 *data16 = (u16 *)skb_put(skb, len); | 672 | u16 *data16 = (u16 *)skb_put(skb, len); |
673 | ks8842_select_bank(adapter, 17); | 673 | ks8842_select_bank(adapter, 17); |
674 | while (len > 0) { | 674 | while (len > 0) { |
675 | *data16++ = ioread16(adapter->hw_addr + | 675 | *data16++ = ioread16(adapter->hw_addr + |
676 | REG_QMU_DATA_LO); | 676 | REG_QMU_DATA_LO); |
677 | *data16++ = ioread16(adapter->hw_addr + | 677 | *data16++ = ioread16(adapter->hw_addr + |
678 | REG_QMU_DATA_HI); | 678 | REG_QMU_DATA_HI); |
679 | len -= sizeof(u32); | 679 | len -= sizeof(u32); |
680 | } | 680 | } |
681 | } else { | 681 | } else { |
682 | u32 *data = (u32 *)skb_put(skb, len); | 682 | u32 *data = (u32 *)skb_put(skb, len); |
683 | 683 | ||
684 | ks8842_select_bank(adapter, 17); | 684 | ks8842_select_bank(adapter, 17); |
685 | while (len > 0) { | 685 | while (len > 0) { |
686 | *data++ = ioread32(adapter->hw_addr + | 686 | *data++ = ioread32(adapter->hw_addr + |
687 | REG_QMU_DATA_LO); | 687 | REG_QMU_DATA_LO); |
688 | len -= sizeof(u32); | 688 | len -= sizeof(u32); |
689 | } | 689 | } |
690 | } | 690 | } |
691 | skb->protocol = eth_type_trans(skb, netdev); | 691 | skb->protocol = eth_type_trans(skb, netdev); |
692 | netif_rx(skb); | 692 | netif_rx(skb); |
693 | } else | 693 | } else |
694 | netdev->stats.rx_dropped++; | 694 | netdev->stats.rx_dropped++; |
695 | } else | 695 | } else |
696 | ks8842_update_rx_err_counters(netdev, status); | 696 | ks8842_update_rx_err_counters(netdev, status); |
697 | 697 | ||
698 | /* set high watermark to 3K */ | 698 | /* set high watermark to 3K */ |
699 | ks8842_clear_bits(adapter, 0, 1 << 12, REG_QRFCR); | 699 | ks8842_clear_bits(adapter, 0, 1 << 12, REG_QRFCR); |
700 | 700 | ||
701 | /* release the frame */ | 701 | /* release the frame */ |
702 | ks8842_write16(adapter, 17, 0x01, REG_RXQCR); | 702 | ks8842_write16(adapter, 17, 0x01, REG_RXQCR); |
703 | 703 | ||
704 | /* set high watermark to 2K */ | 704 | /* set high watermark to 2K */ |
705 | ks8842_enable_bits(adapter, 0, 1 << 12, REG_QRFCR); | 705 | ks8842_enable_bits(adapter, 0, 1 << 12, REG_QRFCR); |
706 | } | 706 | } |
707 | 707 | ||
708 | void ks8842_handle_rx(struct net_device *netdev, struct ks8842_adapter *adapter) | 708 | void ks8842_handle_rx(struct net_device *netdev, struct ks8842_adapter *adapter) |
709 | { | 709 | { |
710 | u16 rx_data = ks8842_read16(adapter, 16, REG_RXMIR) & 0x1fff; | 710 | u16 rx_data = ks8842_read16(adapter, 16, REG_RXMIR) & 0x1fff; |
711 | netdev_dbg(netdev, "%s Entry - rx_data: %d\n", __func__, rx_data); | 711 | netdev_dbg(netdev, "%s Entry - rx_data: %d\n", __func__, rx_data); |
712 | while (rx_data) { | 712 | while (rx_data) { |
713 | ks8842_rx_frame(netdev, adapter); | 713 | ks8842_rx_frame(netdev, adapter); |
714 | rx_data = ks8842_read16(adapter, 16, REG_RXMIR) & 0x1fff; | 714 | rx_data = ks8842_read16(adapter, 16, REG_RXMIR) & 0x1fff; |
715 | } | 715 | } |
716 | } | 716 | } |
717 | 717 | ||
718 | void ks8842_handle_tx(struct net_device *netdev, struct ks8842_adapter *adapter) | 718 | void ks8842_handle_tx(struct net_device *netdev, struct ks8842_adapter *adapter) |
719 | { | 719 | { |
720 | u16 sr = ks8842_read16(adapter, 16, REG_TXSR); | 720 | u16 sr = ks8842_read16(adapter, 16, REG_TXSR); |
721 | netdev_dbg(netdev, "%s - entry, sr: %x\n", __func__, sr); | 721 | netdev_dbg(netdev, "%s - entry, sr: %x\n", __func__, sr); |
722 | netdev->stats.tx_packets++; | 722 | netdev->stats.tx_packets++; |
723 | if (netif_queue_stopped(netdev)) | 723 | if (netif_queue_stopped(netdev)) |
724 | netif_wake_queue(netdev); | 724 | netif_wake_queue(netdev); |
725 | } | 725 | } |
726 | 726 | ||
727 | void ks8842_handle_rx_overrun(struct net_device *netdev, | 727 | void ks8842_handle_rx_overrun(struct net_device *netdev, |
728 | struct ks8842_adapter *adapter) | 728 | struct ks8842_adapter *adapter) |
729 | { | 729 | { |
730 | netdev_dbg(netdev, "%s: entry\n", __func__); | 730 | netdev_dbg(netdev, "%s: entry\n", __func__); |
731 | netdev->stats.rx_errors++; | 731 | netdev->stats.rx_errors++; |
732 | netdev->stats.rx_fifo_errors++; | 732 | netdev->stats.rx_fifo_errors++; |
733 | } | 733 | } |
734 | 734 | ||
735 | void ks8842_tasklet(unsigned long arg) | 735 | void ks8842_tasklet(unsigned long arg) |
736 | { | 736 | { |
737 | struct net_device *netdev = (struct net_device *)arg; | 737 | struct net_device *netdev = (struct net_device *)arg; |
738 | struct ks8842_adapter *adapter = netdev_priv(netdev); | 738 | struct ks8842_adapter *adapter = netdev_priv(netdev); |
739 | u16 isr; | 739 | u16 isr; |
740 | unsigned long flags; | 740 | unsigned long flags; |
741 | u16 entry_bank; | 741 | u16 entry_bank; |
742 | 742 | ||
743 | /* read current bank to be able to set it back */ | 743 | /* read current bank to be able to set it back */ |
744 | spin_lock_irqsave(&adapter->lock, flags); | 744 | spin_lock_irqsave(&adapter->lock, flags); |
745 | entry_bank = ioread16(adapter->hw_addr + REG_SELECT_BANK); | 745 | entry_bank = ioread16(adapter->hw_addr + REG_SELECT_BANK); |
746 | spin_unlock_irqrestore(&adapter->lock, flags); | 746 | spin_unlock_irqrestore(&adapter->lock, flags); |
747 | 747 | ||
748 | isr = ks8842_read16(adapter, 18, REG_ISR); | 748 | isr = ks8842_read16(adapter, 18, REG_ISR); |
749 | netdev_dbg(netdev, "%s - ISR: 0x%x\n", __func__, isr); | 749 | netdev_dbg(netdev, "%s - ISR: 0x%x\n", __func__, isr); |
750 | 750 | ||
751 | /* when running in DMA mode, do not ack RX interrupts, it is handled | 751 | /* when running in DMA mode, do not ack RX interrupts, it is handled |
752 | internally by timberdale, otherwise it's DMA FIFO:s would stop | 752 | internally by timberdale, otherwise it's DMA FIFO:s would stop |
753 | */ | 753 | */ |
754 | if (KS8842_USE_DMA(adapter)) | 754 | if (KS8842_USE_DMA(adapter)) |
755 | isr &= ~IRQ_RX; | 755 | isr &= ~IRQ_RX; |
756 | 756 | ||
757 | /* Ack */ | 757 | /* Ack */ |
758 | ks8842_write16(adapter, 18, isr, REG_ISR); | 758 | ks8842_write16(adapter, 18, isr, REG_ISR); |
759 | 759 | ||
760 | if (!(adapter->conf_flags & MICREL_KS884X)) | 760 | if (!(adapter->conf_flags & MICREL_KS884X)) |
761 | /* Ack in the timberdale IP as well */ | 761 | /* Ack in the timberdale IP as well */ |
762 | iowrite32(0x1, adapter->hw_addr + REG_TIMB_IAR); | 762 | iowrite32(0x1, adapter->hw_addr + REG_TIMB_IAR); |
763 | 763 | ||
764 | if (!netif_running(netdev)) | 764 | if (!netif_running(netdev)) |
765 | return; | 765 | return; |
766 | 766 | ||
767 | if (isr & IRQ_LINK_CHANGE) | 767 | if (isr & IRQ_LINK_CHANGE) |
768 | ks8842_update_link_status(netdev, adapter); | 768 | ks8842_update_link_status(netdev, adapter); |
769 | 769 | ||
770 | /* should not get IRQ_RX when running DMA mode */ | 770 | /* should not get IRQ_RX when running DMA mode */ |
771 | if (isr & (IRQ_RX | IRQ_RX_ERROR) && !KS8842_USE_DMA(adapter)) | 771 | if (isr & (IRQ_RX | IRQ_RX_ERROR) && !KS8842_USE_DMA(adapter)) |
772 | ks8842_handle_rx(netdev, adapter); | 772 | ks8842_handle_rx(netdev, adapter); |
773 | 773 | ||
774 | /* should only happen when in PIO mode */ | 774 | /* should only happen when in PIO mode */ |
775 | if (isr & IRQ_TX) | 775 | if (isr & IRQ_TX) |
776 | ks8842_handle_tx(netdev, adapter); | 776 | ks8842_handle_tx(netdev, adapter); |
777 | 777 | ||
778 | if (isr & IRQ_RX_OVERRUN) | 778 | if (isr & IRQ_RX_OVERRUN) |
779 | ks8842_handle_rx_overrun(netdev, adapter); | 779 | ks8842_handle_rx_overrun(netdev, adapter); |
780 | 780 | ||
781 | if (isr & IRQ_TX_STOPPED) { | 781 | if (isr & IRQ_TX_STOPPED) { |
782 | ks8842_disable_tx(adapter); | 782 | ks8842_disable_tx(adapter); |
783 | ks8842_enable_tx(adapter); | 783 | ks8842_enable_tx(adapter); |
784 | } | 784 | } |
785 | 785 | ||
786 | if (isr & IRQ_RX_STOPPED) { | 786 | if (isr & IRQ_RX_STOPPED) { |
787 | ks8842_disable_rx(adapter); | 787 | ks8842_disable_rx(adapter); |
788 | ks8842_enable_rx(adapter); | 788 | ks8842_enable_rx(adapter); |
789 | } | 789 | } |
790 | 790 | ||
791 | /* re-enable interrupts, put back the bank selection register */ | 791 | /* re-enable interrupts, put back the bank selection register */ |
792 | spin_lock_irqsave(&adapter->lock, flags); | 792 | spin_lock_irqsave(&adapter->lock, flags); |
793 | if (KS8842_USE_DMA(adapter)) | 793 | if (KS8842_USE_DMA(adapter)) |
794 | ks8842_write16(adapter, 18, ENABLED_IRQS_DMA, REG_IER); | 794 | ks8842_write16(adapter, 18, ENABLED_IRQS_DMA, REG_IER); |
795 | else | 795 | else |
796 | ks8842_write16(adapter, 18, ENABLED_IRQS, REG_IER); | 796 | ks8842_write16(adapter, 18, ENABLED_IRQS, REG_IER); |
797 | iowrite16(entry_bank, adapter->hw_addr + REG_SELECT_BANK); | 797 | iowrite16(entry_bank, adapter->hw_addr + REG_SELECT_BANK); |
798 | 798 | ||
799 | /* Make sure timberdale continues DMA operations, they are stopped while | 799 | /* Make sure timberdale continues DMA operations, they are stopped while |
800 | we are handling the ks8842 because we might change bank */ | 800 | we are handling the ks8842 because we might change bank */ |
801 | if (KS8842_USE_DMA(adapter)) | 801 | if (KS8842_USE_DMA(adapter)) |
802 | ks8842_resume_dma(adapter); | 802 | ks8842_resume_dma(adapter); |
803 | 803 | ||
804 | spin_unlock_irqrestore(&adapter->lock, flags); | 804 | spin_unlock_irqrestore(&adapter->lock, flags); |
805 | } | 805 | } |
806 | 806 | ||
807 | static irqreturn_t ks8842_irq(int irq, void *devid) | 807 | static irqreturn_t ks8842_irq(int irq, void *devid) |
808 | { | 808 | { |
809 | struct net_device *netdev = devid; | 809 | struct net_device *netdev = devid; |
810 | struct ks8842_adapter *adapter = netdev_priv(netdev); | 810 | struct ks8842_adapter *adapter = netdev_priv(netdev); |
811 | u16 isr; | 811 | u16 isr; |
812 | u16 entry_bank = ioread16(adapter->hw_addr + REG_SELECT_BANK); | 812 | u16 entry_bank = ioread16(adapter->hw_addr + REG_SELECT_BANK); |
813 | irqreturn_t ret = IRQ_NONE; | 813 | irqreturn_t ret = IRQ_NONE; |
814 | 814 | ||
815 | isr = ks8842_read16(adapter, 18, REG_ISR); | 815 | isr = ks8842_read16(adapter, 18, REG_ISR); |
816 | netdev_dbg(netdev, "%s - ISR: 0x%x\n", __func__, isr); | 816 | netdev_dbg(netdev, "%s - ISR: 0x%x\n", __func__, isr); |
817 | 817 | ||
818 | if (isr) { | 818 | if (isr) { |
819 | if (KS8842_USE_DMA(adapter)) | 819 | if (KS8842_USE_DMA(adapter)) |
820 | /* disable all but RX IRQ, since the FPGA relies on it*/ | 820 | /* disable all but RX IRQ, since the FPGA relies on it*/ |
821 | ks8842_write16(adapter, 18, IRQ_RX, REG_IER); | 821 | ks8842_write16(adapter, 18, IRQ_RX, REG_IER); |
822 | else | 822 | else |
823 | /* disable IRQ */ | 823 | /* disable IRQ */ |
824 | ks8842_write16(adapter, 18, 0x00, REG_IER); | 824 | ks8842_write16(adapter, 18, 0x00, REG_IER); |
825 | 825 | ||
826 | /* schedule tasklet */ | 826 | /* schedule tasklet */ |
827 | tasklet_schedule(&adapter->tasklet); | 827 | tasklet_schedule(&adapter->tasklet); |
828 | 828 | ||
829 | ret = IRQ_HANDLED; | 829 | ret = IRQ_HANDLED; |
830 | } | 830 | } |
831 | 831 | ||
832 | iowrite16(entry_bank, adapter->hw_addr + REG_SELECT_BANK); | 832 | iowrite16(entry_bank, adapter->hw_addr + REG_SELECT_BANK); |
833 | 833 | ||
834 | /* After an interrupt, tell timberdale to continue DMA operations. | 834 | /* After an interrupt, tell timberdale to continue DMA operations. |
835 | DMA is disabled while we are handling the ks8842 because we might | 835 | DMA is disabled while we are handling the ks8842 because we might |
836 | change bank */ | 836 | change bank */ |
837 | ks8842_resume_dma(adapter); | 837 | ks8842_resume_dma(adapter); |
838 | 838 | ||
839 | return ret; | 839 | return ret; |
840 | } | 840 | } |
841 | 841 | ||
842 | static void ks8842_dma_rx_cb(void *data) | 842 | static void ks8842_dma_rx_cb(void *data) |
843 | { | 843 | { |
844 | struct net_device *netdev = data; | 844 | struct net_device *netdev = data; |
845 | struct ks8842_adapter *adapter = netdev_priv(netdev); | 845 | struct ks8842_adapter *adapter = netdev_priv(netdev); |
846 | 846 | ||
847 | netdev_dbg(netdev, "RX DMA finished\n"); | 847 | netdev_dbg(netdev, "RX DMA finished\n"); |
848 | /* schedule tasklet */ | 848 | /* schedule tasklet */ |
849 | if (adapter->dma_rx.adesc) | 849 | if (adapter->dma_rx.adesc) |
850 | tasklet_schedule(&adapter->dma_rx.tasklet); | 850 | tasklet_schedule(&adapter->dma_rx.tasklet); |
851 | } | 851 | } |
852 | 852 | ||
853 | static void ks8842_dma_tx_cb(void *data) | 853 | static void ks8842_dma_tx_cb(void *data) |
854 | { | 854 | { |
855 | struct net_device *netdev = data; | 855 | struct net_device *netdev = data; |
856 | struct ks8842_adapter *adapter = netdev_priv(netdev); | 856 | struct ks8842_adapter *adapter = netdev_priv(netdev); |
857 | struct ks8842_tx_dma_ctl *ctl = &adapter->dma_tx; | 857 | struct ks8842_tx_dma_ctl *ctl = &adapter->dma_tx; |
858 | 858 | ||
859 | netdev_dbg(netdev, "TX DMA finished\n"); | 859 | netdev_dbg(netdev, "TX DMA finished\n"); |
860 | 860 | ||
861 | if (!ctl->adesc) | 861 | if (!ctl->adesc) |
862 | return; | 862 | return; |
863 | 863 | ||
864 | netdev->stats.tx_packets++; | 864 | netdev->stats.tx_packets++; |
865 | ctl->adesc = NULL; | 865 | ctl->adesc = NULL; |
866 | 866 | ||
867 | if (netif_queue_stopped(netdev)) | 867 | if (netif_queue_stopped(netdev)) |
868 | netif_wake_queue(netdev); | 868 | netif_wake_queue(netdev); |
869 | } | 869 | } |
870 | 870 | ||
871 | static void ks8842_stop_dma(struct ks8842_adapter *adapter) | 871 | static void ks8842_stop_dma(struct ks8842_adapter *adapter) |
872 | { | 872 | { |
873 | struct ks8842_tx_dma_ctl *tx_ctl = &adapter->dma_tx; | 873 | struct ks8842_tx_dma_ctl *tx_ctl = &adapter->dma_tx; |
874 | struct ks8842_rx_dma_ctl *rx_ctl = &adapter->dma_rx; | 874 | struct ks8842_rx_dma_ctl *rx_ctl = &adapter->dma_rx; |
875 | 875 | ||
876 | tx_ctl->adesc = NULL; | 876 | tx_ctl->adesc = NULL; |
877 | if (tx_ctl->chan) | 877 | if (tx_ctl->chan) |
878 | tx_ctl->chan->device->device_control(tx_ctl->chan, | 878 | tx_ctl->chan->device->device_control(tx_ctl->chan, |
879 | DMA_TERMINATE_ALL, 0); | 879 | DMA_TERMINATE_ALL, 0); |
880 | 880 | ||
881 | rx_ctl->adesc = NULL; | 881 | rx_ctl->adesc = NULL; |
882 | if (rx_ctl->chan) | 882 | if (rx_ctl->chan) |
883 | rx_ctl->chan->device->device_control(rx_ctl->chan, | 883 | rx_ctl->chan->device->device_control(rx_ctl->chan, |
884 | DMA_TERMINATE_ALL, 0); | 884 | DMA_TERMINATE_ALL, 0); |
885 | 885 | ||
886 | if (sg_dma_address(&rx_ctl->sg)) | 886 | if (sg_dma_address(&rx_ctl->sg)) |
887 | dma_unmap_single(adapter->dev, sg_dma_address(&rx_ctl->sg), | 887 | dma_unmap_single(adapter->dev, sg_dma_address(&rx_ctl->sg), |
888 | DMA_BUFFER_SIZE, DMA_FROM_DEVICE); | 888 | DMA_BUFFER_SIZE, DMA_FROM_DEVICE); |
889 | sg_dma_address(&rx_ctl->sg) = 0; | 889 | sg_dma_address(&rx_ctl->sg) = 0; |
890 | 890 | ||
891 | dev_kfree_skb(rx_ctl->skb); | 891 | dev_kfree_skb(rx_ctl->skb); |
892 | rx_ctl->skb = NULL; | 892 | rx_ctl->skb = NULL; |
893 | } | 893 | } |
894 | 894 | ||
895 | static void ks8842_dealloc_dma_bufs(struct ks8842_adapter *adapter) | 895 | static void ks8842_dealloc_dma_bufs(struct ks8842_adapter *adapter) |
896 | { | 896 | { |
897 | struct ks8842_tx_dma_ctl *tx_ctl = &adapter->dma_tx; | 897 | struct ks8842_tx_dma_ctl *tx_ctl = &adapter->dma_tx; |
898 | struct ks8842_rx_dma_ctl *rx_ctl = &adapter->dma_rx; | 898 | struct ks8842_rx_dma_ctl *rx_ctl = &adapter->dma_rx; |
899 | 899 | ||
900 | ks8842_stop_dma(adapter); | 900 | ks8842_stop_dma(adapter); |
901 | 901 | ||
902 | if (tx_ctl->chan) | 902 | if (tx_ctl->chan) |
903 | dma_release_channel(tx_ctl->chan); | 903 | dma_release_channel(tx_ctl->chan); |
904 | tx_ctl->chan = NULL; | 904 | tx_ctl->chan = NULL; |
905 | 905 | ||
906 | if (rx_ctl->chan) | 906 | if (rx_ctl->chan) |
907 | dma_release_channel(rx_ctl->chan); | 907 | dma_release_channel(rx_ctl->chan); |
908 | rx_ctl->chan = NULL; | 908 | rx_ctl->chan = NULL; |
909 | 909 | ||
910 | tasklet_kill(&rx_ctl->tasklet); | 910 | tasklet_kill(&rx_ctl->tasklet); |
911 | 911 | ||
912 | if (sg_dma_address(&tx_ctl->sg)) | 912 | if (sg_dma_address(&tx_ctl->sg)) |
913 | dma_unmap_single(adapter->dev, sg_dma_address(&tx_ctl->sg), | 913 | dma_unmap_single(adapter->dev, sg_dma_address(&tx_ctl->sg), |
914 | DMA_BUFFER_SIZE, DMA_TO_DEVICE); | 914 | DMA_BUFFER_SIZE, DMA_TO_DEVICE); |
915 | sg_dma_address(&tx_ctl->sg) = 0; | 915 | sg_dma_address(&tx_ctl->sg) = 0; |
916 | 916 | ||
917 | kfree(tx_ctl->buf); | 917 | kfree(tx_ctl->buf); |
918 | tx_ctl->buf = NULL; | 918 | tx_ctl->buf = NULL; |
919 | } | 919 | } |
920 | 920 | ||
921 | static bool ks8842_dma_filter_fn(struct dma_chan *chan, void *filter_param) | 921 | static bool ks8842_dma_filter_fn(struct dma_chan *chan, void *filter_param) |
922 | { | 922 | { |
923 | return chan->chan_id == (long)filter_param; | 923 | return chan->chan_id == (long)filter_param; |
924 | } | 924 | } |
925 | 925 | ||
926 | static int ks8842_alloc_dma_bufs(struct net_device *netdev) | 926 | static int ks8842_alloc_dma_bufs(struct net_device *netdev) |
927 | { | 927 | { |
928 | struct ks8842_adapter *adapter = netdev_priv(netdev); | 928 | struct ks8842_adapter *adapter = netdev_priv(netdev); |
929 | struct ks8842_tx_dma_ctl *tx_ctl = &adapter->dma_tx; | 929 | struct ks8842_tx_dma_ctl *tx_ctl = &adapter->dma_tx; |
930 | struct ks8842_rx_dma_ctl *rx_ctl = &adapter->dma_rx; | 930 | struct ks8842_rx_dma_ctl *rx_ctl = &adapter->dma_rx; |
931 | int err; | 931 | int err; |
932 | 932 | ||
933 | dma_cap_mask_t mask; | 933 | dma_cap_mask_t mask; |
934 | 934 | ||
935 | dma_cap_zero(mask); | 935 | dma_cap_zero(mask); |
936 | dma_cap_set(DMA_SLAVE, mask); | 936 | dma_cap_set(DMA_SLAVE, mask); |
937 | dma_cap_set(DMA_PRIVATE, mask); | 937 | dma_cap_set(DMA_PRIVATE, mask); |
938 | 938 | ||
939 | sg_init_table(&tx_ctl->sg, 1); | 939 | sg_init_table(&tx_ctl->sg, 1); |
940 | 940 | ||
941 | tx_ctl->chan = dma_request_channel(mask, ks8842_dma_filter_fn, | 941 | tx_ctl->chan = dma_request_channel(mask, ks8842_dma_filter_fn, |
942 | (void *)(long)tx_ctl->channel); | 942 | (void *)(long)tx_ctl->channel); |
943 | if (!tx_ctl->chan) { | 943 | if (!tx_ctl->chan) { |
944 | err = -ENODEV; | 944 | err = -ENODEV; |
945 | goto err; | 945 | goto err; |
946 | } | 946 | } |
947 | 947 | ||
948 | /* allocate DMA buffer */ | 948 | /* allocate DMA buffer */ |
949 | tx_ctl->buf = kmalloc(DMA_BUFFER_SIZE, GFP_KERNEL); | 949 | tx_ctl->buf = kmalloc(DMA_BUFFER_SIZE, GFP_KERNEL); |
950 | if (!tx_ctl->buf) { | 950 | if (!tx_ctl->buf) { |
951 | err = -ENOMEM; | 951 | err = -ENOMEM; |
952 | goto err; | 952 | goto err; |
953 | } | 953 | } |
954 | 954 | ||
955 | sg_dma_address(&tx_ctl->sg) = dma_map_single(adapter->dev, | 955 | sg_dma_address(&tx_ctl->sg) = dma_map_single(adapter->dev, |
956 | tx_ctl->buf, DMA_BUFFER_SIZE, DMA_TO_DEVICE); | 956 | tx_ctl->buf, DMA_BUFFER_SIZE, DMA_TO_DEVICE); |
957 | err = dma_mapping_error(adapter->dev, | 957 | err = dma_mapping_error(adapter->dev, |
958 | sg_dma_address(&tx_ctl->sg)); | 958 | sg_dma_address(&tx_ctl->sg)); |
959 | if (err) { | 959 | if (err) { |
960 | sg_dma_address(&tx_ctl->sg) = 0; | 960 | sg_dma_address(&tx_ctl->sg) = 0; |
961 | goto err; | 961 | goto err; |
962 | } | 962 | } |
963 | 963 | ||
964 | rx_ctl->chan = dma_request_channel(mask, ks8842_dma_filter_fn, | 964 | rx_ctl->chan = dma_request_channel(mask, ks8842_dma_filter_fn, |
965 | (void *)(long)rx_ctl->channel); | 965 | (void *)(long)rx_ctl->channel); |
966 | if (!rx_ctl->chan) { | 966 | if (!rx_ctl->chan) { |
967 | err = -ENODEV; | 967 | err = -ENODEV; |
968 | goto err; | 968 | goto err; |
969 | } | 969 | } |
970 | 970 | ||
971 | tasklet_init(&rx_ctl->tasklet, ks8842_rx_frame_dma_tasklet, | 971 | tasklet_init(&rx_ctl->tasklet, ks8842_rx_frame_dma_tasklet, |
972 | (unsigned long)netdev); | 972 | (unsigned long)netdev); |
973 | 973 | ||
974 | return 0; | 974 | return 0; |
975 | err: | 975 | err: |
976 | ks8842_dealloc_dma_bufs(adapter); | 976 | ks8842_dealloc_dma_bufs(adapter); |
977 | return err; | 977 | return err; |
978 | } | 978 | } |
979 | 979 | ||
980 | /* Netdevice operations */ | 980 | /* Netdevice operations */ |
981 | 981 | ||
982 | static int ks8842_open(struct net_device *netdev) | 982 | static int ks8842_open(struct net_device *netdev) |
983 | { | 983 | { |
984 | struct ks8842_adapter *adapter = netdev_priv(netdev); | 984 | struct ks8842_adapter *adapter = netdev_priv(netdev); |
985 | int err; | 985 | int err; |
986 | 986 | ||
987 | netdev_dbg(netdev, "%s - entry\n", __func__); | 987 | netdev_dbg(netdev, "%s - entry\n", __func__); |
988 | 988 | ||
989 | if (KS8842_USE_DMA(adapter)) { | 989 | if (KS8842_USE_DMA(adapter)) { |
990 | err = ks8842_alloc_dma_bufs(netdev); | 990 | err = ks8842_alloc_dma_bufs(netdev); |
991 | 991 | ||
992 | if (!err) { | 992 | if (!err) { |
993 | /* start RX dma */ | 993 | /* start RX dma */ |
994 | err = __ks8842_start_new_rx_dma(netdev); | 994 | err = __ks8842_start_new_rx_dma(netdev); |
995 | if (err) | 995 | if (err) |
996 | ks8842_dealloc_dma_bufs(adapter); | 996 | ks8842_dealloc_dma_bufs(adapter); |
997 | } | 997 | } |
998 | 998 | ||
999 | if (err) { | 999 | if (err) { |
1000 | printk(KERN_WARNING DRV_NAME | 1000 | printk(KERN_WARNING DRV_NAME |
1001 | ": Failed to initiate DMA, running PIO\n"); | 1001 | ": Failed to initiate DMA, running PIO\n"); |
1002 | ks8842_dealloc_dma_bufs(adapter); | 1002 | ks8842_dealloc_dma_bufs(adapter); |
1003 | adapter->dma_rx.channel = -1; | 1003 | adapter->dma_rx.channel = -1; |
1004 | adapter->dma_tx.channel = -1; | 1004 | adapter->dma_tx.channel = -1; |
1005 | } | 1005 | } |
1006 | } | 1006 | } |
1007 | 1007 | ||
1008 | /* reset the HW */ | 1008 | /* reset the HW */ |
1009 | ks8842_reset_hw(adapter); | 1009 | ks8842_reset_hw(adapter); |
1010 | 1010 | ||
1011 | ks8842_write_mac_addr(adapter, netdev->dev_addr); | 1011 | ks8842_write_mac_addr(adapter, netdev->dev_addr); |
1012 | 1012 | ||
1013 | ks8842_update_link_status(netdev, adapter); | 1013 | ks8842_update_link_status(netdev, adapter); |
1014 | 1014 | ||
1015 | err = request_irq(adapter->irq, ks8842_irq, IRQF_SHARED, DRV_NAME, | 1015 | err = request_irq(adapter->irq, ks8842_irq, IRQF_SHARED, DRV_NAME, |
1016 | netdev); | 1016 | netdev); |
1017 | if (err) { | 1017 | if (err) { |
1018 | pr_err("Failed to request IRQ: %d: %d\n", adapter->irq, err); | 1018 | pr_err("Failed to request IRQ: %d: %d\n", adapter->irq, err); |
1019 | return err; | 1019 | return err; |
1020 | } | 1020 | } |
1021 | 1021 | ||
1022 | return 0; | 1022 | return 0; |
1023 | } | 1023 | } |
1024 | 1024 | ||
1025 | static int ks8842_close(struct net_device *netdev) | 1025 | static int ks8842_close(struct net_device *netdev) |
1026 | { | 1026 | { |
1027 | struct ks8842_adapter *adapter = netdev_priv(netdev); | 1027 | struct ks8842_adapter *adapter = netdev_priv(netdev); |
1028 | 1028 | ||
1029 | netdev_dbg(netdev, "%s - entry\n", __func__); | 1029 | netdev_dbg(netdev, "%s - entry\n", __func__); |
1030 | 1030 | ||
1031 | cancel_work_sync(&adapter->timeout_work); | 1031 | cancel_work_sync(&adapter->timeout_work); |
1032 | 1032 | ||
1033 | if (KS8842_USE_DMA(adapter)) | 1033 | if (KS8842_USE_DMA(adapter)) |
1034 | ks8842_dealloc_dma_bufs(adapter); | 1034 | ks8842_dealloc_dma_bufs(adapter); |
1035 | 1035 | ||
1036 | /* free the irq */ | 1036 | /* free the irq */ |
1037 | free_irq(adapter->irq, netdev); | 1037 | free_irq(adapter->irq, netdev); |
1038 | 1038 | ||
1039 | /* disable the switch */ | 1039 | /* disable the switch */ |
1040 | ks8842_write16(adapter, 32, 0x0, REG_SW_ID_AND_ENABLE); | 1040 | ks8842_write16(adapter, 32, 0x0, REG_SW_ID_AND_ENABLE); |
1041 | 1041 | ||
1042 | return 0; | 1042 | return 0; |
1043 | } | 1043 | } |
1044 | 1044 | ||
1045 | static netdev_tx_t ks8842_xmit_frame(struct sk_buff *skb, | 1045 | static netdev_tx_t ks8842_xmit_frame(struct sk_buff *skb, |
1046 | struct net_device *netdev) | 1046 | struct net_device *netdev) |
1047 | { | 1047 | { |
1048 | int ret; | 1048 | int ret; |
1049 | struct ks8842_adapter *adapter = netdev_priv(netdev); | 1049 | struct ks8842_adapter *adapter = netdev_priv(netdev); |
1050 | 1050 | ||
1051 | netdev_dbg(netdev, "%s: entry\n", __func__); | 1051 | netdev_dbg(netdev, "%s: entry\n", __func__); |
1052 | 1052 | ||
1053 | if (KS8842_USE_DMA(adapter)) { | 1053 | if (KS8842_USE_DMA(adapter)) { |
1054 | unsigned long flags; | 1054 | unsigned long flags; |
1055 | ret = ks8842_tx_frame_dma(skb, netdev); | 1055 | ret = ks8842_tx_frame_dma(skb, netdev); |
1056 | /* for now only allow one transfer at the time */ | 1056 | /* for now only allow one transfer at the time */ |
1057 | spin_lock_irqsave(&adapter->lock, flags); | 1057 | spin_lock_irqsave(&adapter->lock, flags); |
1058 | if (adapter->dma_tx.adesc) | 1058 | if (adapter->dma_tx.adesc) |
1059 | netif_stop_queue(netdev); | 1059 | netif_stop_queue(netdev); |
1060 | spin_unlock_irqrestore(&adapter->lock, flags); | 1060 | spin_unlock_irqrestore(&adapter->lock, flags); |
1061 | return ret; | 1061 | return ret; |
1062 | } | 1062 | } |
1063 | 1063 | ||
1064 | ret = ks8842_tx_frame(skb, netdev); | 1064 | ret = ks8842_tx_frame(skb, netdev); |
1065 | 1065 | ||
1066 | if (ks8842_tx_fifo_space(adapter) < netdev->mtu + 8) | 1066 | if (ks8842_tx_fifo_space(adapter) < netdev->mtu + 8) |
1067 | netif_stop_queue(netdev); | 1067 | netif_stop_queue(netdev); |
1068 | 1068 | ||
1069 | return ret; | 1069 | return ret; |
1070 | } | 1070 | } |
1071 | 1071 | ||
1072 | static int ks8842_set_mac(struct net_device *netdev, void *p) | 1072 | static int ks8842_set_mac(struct net_device *netdev, void *p) |
1073 | { | 1073 | { |
1074 | struct ks8842_adapter *adapter = netdev_priv(netdev); | 1074 | struct ks8842_adapter *adapter = netdev_priv(netdev); |
1075 | struct sockaddr *addr = p; | 1075 | struct sockaddr *addr = p; |
1076 | char *mac = (u8 *)addr->sa_data; | 1076 | char *mac = (u8 *)addr->sa_data; |
1077 | 1077 | ||
1078 | netdev_dbg(netdev, "%s: entry\n", __func__); | 1078 | netdev_dbg(netdev, "%s: entry\n", __func__); |
1079 | 1079 | ||
1080 | if (!is_valid_ether_addr(addr->sa_data)) | 1080 | if (!is_valid_ether_addr(addr->sa_data)) |
1081 | return -EADDRNOTAVAIL; | 1081 | return -EADDRNOTAVAIL; |
1082 | 1082 | ||
1083 | netdev->addr_assign_type &= ~NET_ADDR_RANDOM; | 1083 | netdev->addr_assign_type &= ~NET_ADDR_RANDOM; |
1084 | memcpy(netdev->dev_addr, mac, netdev->addr_len); | 1084 | memcpy(netdev->dev_addr, mac, netdev->addr_len); |
1085 | 1085 | ||
1086 | ks8842_write_mac_addr(adapter, mac); | 1086 | ks8842_write_mac_addr(adapter, mac); |
1087 | return 0; | 1087 | return 0; |
1088 | } | 1088 | } |
1089 | 1089 | ||
1090 | static void ks8842_tx_timeout_work(struct work_struct *work) | 1090 | static void ks8842_tx_timeout_work(struct work_struct *work) |
1091 | { | 1091 | { |
1092 | struct ks8842_adapter *adapter = | 1092 | struct ks8842_adapter *adapter = |
1093 | container_of(work, struct ks8842_adapter, timeout_work); | 1093 | container_of(work, struct ks8842_adapter, timeout_work); |
1094 | struct net_device *netdev = adapter->netdev; | 1094 | struct net_device *netdev = adapter->netdev; |
1095 | unsigned long flags; | 1095 | unsigned long flags; |
1096 | 1096 | ||
1097 | netdev_dbg(netdev, "%s: entry\n", __func__); | 1097 | netdev_dbg(netdev, "%s: entry\n", __func__); |
1098 | 1098 | ||
1099 | spin_lock_irqsave(&adapter->lock, flags); | 1099 | spin_lock_irqsave(&adapter->lock, flags); |
1100 | 1100 | ||
1101 | if (KS8842_USE_DMA(adapter)) | 1101 | if (KS8842_USE_DMA(adapter)) |
1102 | ks8842_stop_dma(adapter); | 1102 | ks8842_stop_dma(adapter); |
1103 | 1103 | ||
1104 | /* disable interrupts */ | 1104 | /* disable interrupts */ |
1105 | ks8842_write16(adapter, 18, 0, REG_IER); | 1105 | ks8842_write16(adapter, 18, 0, REG_IER); |
1106 | ks8842_write16(adapter, 18, 0xFFFF, REG_ISR); | 1106 | ks8842_write16(adapter, 18, 0xFFFF, REG_ISR); |
1107 | 1107 | ||
1108 | netif_stop_queue(netdev); | 1108 | netif_stop_queue(netdev); |
1109 | 1109 | ||
1110 | spin_unlock_irqrestore(&adapter->lock, flags); | 1110 | spin_unlock_irqrestore(&adapter->lock, flags); |
1111 | 1111 | ||
1112 | ks8842_reset_hw(adapter); | 1112 | ks8842_reset_hw(adapter); |
1113 | 1113 | ||
1114 | ks8842_write_mac_addr(adapter, netdev->dev_addr); | 1114 | ks8842_write_mac_addr(adapter, netdev->dev_addr); |
1115 | 1115 | ||
1116 | ks8842_update_link_status(netdev, adapter); | 1116 | ks8842_update_link_status(netdev, adapter); |
1117 | 1117 | ||
1118 | if (KS8842_USE_DMA(adapter)) | 1118 | if (KS8842_USE_DMA(adapter)) |
1119 | __ks8842_start_new_rx_dma(netdev); | 1119 | __ks8842_start_new_rx_dma(netdev); |
1120 | } | 1120 | } |
1121 | 1121 | ||
1122 | static void ks8842_tx_timeout(struct net_device *netdev) | 1122 | static void ks8842_tx_timeout(struct net_device *netdev) |
1123 | { | 1123 | { |
1124 | struct ks8842_adapter *adapter = netdev_priv(netdev); | 1124 | struct ks8842_adapter *adapter = netdev_priv(netdev); |
1125 | 1125 | ||
1126 | netdev_dbg(netdev, "%s: entry\n", __func__); | 1126 | netdev_dbg(netdev, "%s: entry\n", __func__); |
1127 | 1127 | ||
1128 | schedule_work(&adapter->timeout_work); | 1128 | schedule_work(&adapter->timeout_work); |
1129 | } | 1129 | } |
1130 | 1130 | ||
1131 | static const struct net_device_ops ks8842_netdev_ops = { | 1131 | static const struct net_device_ops ks8842_netdev_ops = { |
1132 | .ndo_open = ks8842_open, | 1132 | .ndo_open = ks8842_open, |
1133 | .ndo_stop = ks8842_close, | 1133 | .ndo_stop = ks8842_close, |
1134 | .ndo_start_xmit = ks8842_xmit_frame, | 1134 | .ndo_start_xmit = ks8842_xmit_frame, |
1135 | .ndo_set_mac_address = ks8842_set_mac, | 1135 | .ndo_set_mac_address = ks8842_set_mac, |
1136 | .ndo_tx_timeout = ks8842_tx_timeout, | 1136 | .ndo_tx_timeout = ks8842_tx_timeout, |
1137 | .ndo_validate_addr = eth_validate_addr | 1137 | .ndo_validate_addr = eth_validate_addr |
1138 | }; | 1138 | }; |
1139 | 1139 | ||
1140 | static const struct ethtool_ops ks8842_ethtool_ops = { | 1140 | static const struct ethtool_ops ks8842_ethtool_ops = { |
1141 | .get_link = ethtool_op_get_link, | 1141 | .get_link = ethtool_op_get_link, |
1142 | }; | 1142 | }; |
1143 | 1143 | ||
1144 | static int __devinit ks8842_probe(struct platform_device *pdev) | 1144 | static int __devinit ks8842_probe(struct platform_device *pdev) |
1145 | { | 1145 | { |
1146 | int err = -ENOMEM; | 1146 | int err = -ENOMEM; |
1147 | struct resource *iomem; | 1147 | struct resource *iomem; |
1148 | struct net_device *netdev; | 1148 | struct net_device *netdev; |
1149 | struct ks8842_adapter *adapter; | 1149 | struct ks8842_adapter *adapter; |
1150 | struct ks8842_platform_data *pdata = pdev->dev.platform_data; | 1150 | struct ks8842_platform_data *pdata = pdev->dev.platform_data; |
1151 | u16 id; | 1151 | u16 id; |
1152 | unsigned i; | 1152 | unsigned i; |
1153 | 1153 | ||
1154 | iomem = platform_get_resource(pdev, IORESOURCE_MEM, 0); | 1154 | iomem = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
1155 | if (!request_mem_region(iomem->start, resource_size(iomem), DRV_NAME)) | 1155 | if (!request_mem_region(iomem->start, resource_size(iomem), DRV_NAME)) |
1156 | goto err_mem_region; | 1156 | goto err_mem_region; |
1157 | 1157 | ||
1158 | netdev = alloc_etherdev(sizeof(struct ks8842_adapter)); | 1158 | netdev = alloc_etherdev(sizeof(struct ks8842_adapter)); |
1159 | if (!netdev) | 1159 | if (!netdev) |
1160 | goto err_alloc_etherdev; | 1160 | goto err_alloc_etherdev; |
1161 | 1161 | ||
1162 | SET_NETDEV_DEV(netdev, &pdev->dev); | 1162 | SET_NETDEV_DEV(netdev, &pdev->dev); |
1163 | 1163 | ||
1164 | adapter = netdev_priv(netdev); | 1164 | adapter = netdev_priv(netdev); |
1165 | adapter->netdev = netdev; | 1165 | adapter->netdev = netdev; |
1166 | INIT_WORK(&adapter->timeout_work, ks8842_tx_timeout_work); | 1166 | INIT_WORK(&adapter->timeout_work, ks8842_tx_timeout_work); |
1167 | adapter->hw_addr = ioremap(iomem->start, resource_size(iomem)); | 1167 | adapter->hw_addr = ioremap(iomem->start, resource_size(iomem)); |
1168 | adapter->conf_flags = iomem->flags; | 1168 | adapter->conf_flags = iomem->flags; |
1169 | 1169 | ||
1170 | if (!adapter->hw_addr) | 1170 | if (!adapter->hw_addr) |
1171 | goto err_ioremap; | 1171 | goto err_ioremap; |
1172 | 1172 | ||
1173 | adapter->irq = platform_get_irq(pdev, 0); | 1173 | adapter->irq = platform_get_irq(pdev, 0); |
1174 | if (adapter->irq < 0) { | 1174 | if (adapter->irq < 0) { |
1175 | err = adapter->irq; | 1175 | err = adapter->irq; |
1176 | goto err_get_irq; | 1176 | goto err_get_irq; |
1177 | } | 1177 | } |
1178 | 1178 | ||
1179 | adapter->dev = (pdev->dev.parent) ? pdev->dev.parent : &pdev->dev; | 1179 | adapter->dev = (pdev->dev.parent) ? pdev->dev.parent : &pdev->dev; |
1180 | 1180 | ||
1181 | /* DMA is only supported when accessed via timberdale */ | 1181 | /* DMA is only supported when accessed via timberdale */ |
1182 | if (!(adapter->conf_flags & MICREL_KS884X) && pdata && | 1182 | if (!(adapter->conf_flags & MICREL_KS884X) && pdata && |
1183 | (pdata->tx_dma_channel != -1) && | 1183 | (pdata->tx_dma_channel != -1) && |
1184 | (pdata->rx_dma_channel != -1)) { | 1184 | (pdata->rx_dma_channel != -1)) { |
1185 | adapter->dma_rx.channel = pdata->rx_dma_channel; | 1185 | adapter->dma_rx.channel = pdata->rx_dma_channel; |
1186 | adapter->dma_tx.channel = pdata->tx_dma_channel; | 1186 | adapter->dma_tx.channel = pdata->tx_dma_channel; |
1187 | } else { | 1187 | } else { |
1188 | adapter->dma_rx.channel = -1; | 1188 | adapter->dma_rx.channel = -1; |
1189 | adapter->dma_tx.channel = -1; | 1189 | adapter->dma_tx.channel = -1; |
1190 | } | 1190 | } |
1191 | 1191 | ||
1192 | tasklet_init(&adapter->tasklet, ks8842_tasklet, (unsigned long)netdev); | 1192 | tasklet_init(&adapter->tasklet, ks8842_tasklet, (unsigned long)netdev); |
1193 | spin_lock_init(&adapter->lock); | 1193 | spin_lock_init(&adapter->lock); |
1194 | 1194 | ||
1195 | netdev->netdev_ops = &ks8842_netdev_ops; | 1195 | netdev->netdev_ops = &ks8842_netdev_ops; |
1196 | netdev->ethtool_ops = &ks8842_ethtool_ops; | 1196 | netdev->ethtool_ops = &ks8842_ethtool_ops; |
1197 | 1197 | ||
1198 | /* Check if a mac address was given */ | 1198 | /* Check if a mac address was given */ |
1199 | i = netdev->addr_len; | 1199 | i = netdev->addr_len; |
1200 | if (pdata) { | 1200 | if (pdata) { |
1201 | for (i = 0; i < netdev->addr_len; i++) | 1201 | for (i = 0; i < netdev->addr_len; i++) |
1202 | if (pdata->macaddr[i] != 0) | 1202 | if (pdata->macaddr[i] != 0) |
1203 | break; | 1203 | break; |
1204 | 1204 | ||
1205 | if (i < netdev->addr_len) | 1205 | if (i < netdev->addr_len) |
1206 | /* an address was passed, use it */ | 1206 | /* an address was passed, use it */ |
1207 | memcpy(netdev->dev_addr, pdata->macaddr, | 1207 | memcpy(netdev->dev_addr, pdata->macaddr, |
1208 | netdev->addr_len); | 1208 | netdev->addr_len); |
1209 | } | 1209 | } |
1210 | 1210 | ||
1211 | if (i == netdev->addr_len) { | 1211 | if (i == netdev->addr_len) { |
1212 | ks8842_read_mac_addr(adapter, netdev->dev_addr); | 1212 | ks8842_read_mac_addr(adapter, netdev->dev_addr); |
1213 | 1213 | ||
1214 | if (!is_valid_ether_addr(netdev->dev_addr)) | 1214 | if (!is_valid_ether_addr(netdev->dev_addr)) |
1215 | eth_hw_addr_random(netdev); | 1215 | eth_hw_addr_random(netdev); |
1216 | } | 1216 | } |
1217 | 1217 | ||
1218 | id = ks8842_read16(adapter, 32, REG_SW_ID_AND_ENABLE); | 1218 | id = ks8842_read16(adapter, 32, REG_SW_ID_AND_ENABLE); |
1219 | 1219 | ||
1220 | strcpy(netdev->name, "eth%d"); | 1220 | strcpy(netdev->name, "eth%d"); |
1221 | err = register_netdev(netdev); | 1221 | err = register_netdev(netdev); |
1222 | if (err) | 1222 | if (err) |
1223 | goto err_register; | 1223 | goto err_register; |
1224 | 1224 | ||
1225 | platform_set_drvdata(pdev, netdev); | 1225 | platform_set_drvdata(pdev, netdev); |
1226 | 1226 | ||
1227 | pr_info("Found chip, family: 0x%x, id: 0x%x, rev: 0x%x\n", | 1227 | pr_info("Found chip, family: 0x%x, id: 0x%x, rev: 0x%x\n", |
1228 | (id >> 8) & 0xff, (id >> 4) & 0xf, (id >> 1) & 0x7); | 1228 | (id >> 8) & 0xff, (id >> 4) & 0xf, (id >> 1) & 0x7); |
1229 | 1229 | ||
1230 | return 0; | 1230 | return 0; |
1231 | 1231 | ||
1232 | err_register: | 1232 | err_register: |
1233 | err_get_irq: | 1233 | err_get_irq: |
1234 | iounmap(adapter->hw_addr); | 1234 | iounmap(adapter->hw_addr); |
1235 | err_ioremap: | 1235 | err_ioremap: |
1236 | free_netdev(netdev); | 1236 | free_netdev(netdev); |
1237 | err_alloc_etherdev: | 1237 | err_alloc_etherdev: |
1238 | release_mem_region(iomem->start, resource_size(iomem)); | 1238 | release_mem_region(iomem->start, resource_size(iomem)); |
1239 | err_mem_region: | 1239 | err_mem_region: |
1240 | return err; | 1240 | return err; |
1241 | } | 1241 | } |
1242 | 1242 | ||
1243 | static int __devexit ks8842_remove(struct platform_device *pdev) | 1243 | static int __devexit ks8842_remove(struct platform_device *pdev) |
1244 | { | 1244 | { |
1245 | struct net_device *netdev = platform_get_drvdata(pdev); | 1245 | struct net_device *netdev = platform_get_drvdata(pdev); |
1246 | struct ks8842_adapter *adapter = netdev_priv(netdev); | 1246 | struct ks8842_adapter *adapter = netdev_priv(netdev); |
1247 | struct resource *iomem = platform_get_resource(pdev, IORESOURCE_MEM, 0); | 1247 | struct resource *iomem = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
1248 | 1248 | ||
1249 | unregister_netdev(netdev); | 1249 | unregister_netdev(netdev); |
1250 | tasklet_kill(&adapter->tasklet); | 1250 | tasklet_kill(&adapter->tasklet); |
1251 | iounmap(adapter->hw_addr); | 1251 | iounmap(adapter->hw_addr); |
1252 | free_netdev(netdev); | 1252 | free_netdev(netdev); |
1253 | release_mem_region(iomem->start, resource_size(iomem)); | 1253 | release_mem_region(iomem->start, resource_size(iomem)); |
1254 | platform_set_drvdata(pdev, NULL); | 1254 | platform_set_drvdata(pdev, NULL); |
1255 | return 0; | 1255 | return 0; |
1256 | } | 1256 | } |
1257 | 1257 | ||
1258 | 1258 | ||
1259 | static struct platform_driver ks8842_platform_driver = { | 1259 | static struct platform_driver ks8842_platform_driver = { |
1260 | .driver = { | 1260 | .driver = { |
1261 | .name = DRV_NAME, | 1261 | .name = DRV_NAME, |
1262 | .owner = THIS_MODULE, | 1262 | .owner = THIS_MODULE, |
1263 | }, | 1263 | }, |
1264 | .probe = ks8842_probe, | 1264 | .probe = ks8842_probe, |
1265 | .remove = ks8842_remove, | 1265 | .remove = __devexit_p(ks8842_remove), |
1266 | }; | 1266 | }; |
1267 | 1267 | ||
1268 | module_platform_driver(ks8842_platform_driver); | 1268 | module_platform_driver(ks8842_platform_driver); |
1269 | 1269 | ||
1270 | MODULE_DESCRIPTION("Timberdale KS8842 ethernet driver"); | 1270 | MODULE_DESCRIPTION("Timberdale KS8842 ethernet driver"); |
1271 | MODULE_AUTHOR("Mocean Laboratories <info@mocean-labs.com>"); | 1271 | MODULE_AUTHOR("Mocean Laboratories <info@mocean-labs.com>"); |
1272 | MODULE_LICENSE("GPL v2"); | 1272 | MODULE_LICENSE("GPL v2"); |
1273 | MODULE_ALIAS("platform:ks8842"); | 1273 | MODULE_ALIAS("platform:ks8842"); |
1274 | 1274 | ||
1275 | 1275 |
drivers/net/wireless/b43/sdio.c
1 | /* | 1 | /* |
2 | * Broadcom B43 wireless driver | 2 | * Broadcom B43 wireless driver |
3 | * | 3 | * |
4 | * SDIO over Sonics Silicon Backplane bus glue for b43. | 4 | * SDIO over Sonics Silicon Backplane bus glue for b43. |
5 | * | 5 | * |
6 | * Copyright (C) 2009 Albert Herranz | 6 | * Copyright (C) 2009 Albert Herranz |
7 | * Copyright (C) 2009 Michael Buesch <m@bues.ch> | 7 | * Copyright (C) 2009 Michael Buesch <m@bues.ch> |
8 | * | 8 | * |
9 | * This program is free software; you can redistribute it and/or modify | 9 | * This program is free software; you can redistribute it and/or modify |
10 | * it under the terms of the GNU General Public License as published by | 10 | * it under the terms of the GNU General Public License as published by |
11 | * the Free Software Foundation; either version 2 of the License, or (at | 11 | * the Free Software Foundation; either version 2 of the License, or (at |
12 | * your option) any later version. | 12 | * your option) any later version. |
13 | */ | 13 | */ |
14 | 14 | ||
15 | #include <linux/kernel.h> | 15 | #include <linux/kernel.h> |
16 | #include <linux/mmc/card.h> | 16 | #include <linux/mmc/card.h> |
17 | #include <linux/mmc/sdio_func.h> | 17 | #include <linux/mmc/sdio_func.h> |
18 | #include <linux/mmc/sdio_ids.h> | 18 | #include <linux/mmc/sdio_ids.h> |
19 | #include <linux/slab.h> | 19 | #include <linux/slab.h> |
20 | #include <linux/ssb/ssb.h> | 20 | #include <linux/ssb/ssb.h> |
21 | 21 | ||
22 | #include "sdio.h" | 22 | #include "sdio.h" |
23 | #include "b43.h" | 23 | #include "b43.h" |
24 | 24 | ||
25 | 25 | ||
26 | #define HNBU_CHIPID 0x01 /* vendor & device id */ | 26 | #define HNBU_CHIPID 0x01 /* vendor & device id */ |
27 | 27 | ||
28 | #define B43_SDIO_BLOCK_SIZE 64 /* rx fifo max size in bytes */ | 28 | #define B43_SDIO_BLOCK_SIZE 64 /* rx fifo max size in bytes */ |
29 | 29 | ||
30 | 30 | ||
31 | static const struct b43_sdio_quirk { | 31 | static const struct b43_sdio_quirk { |
32 | u16 vendor; | 32 | u16 vendor; |
33 | u16 device; | 33 | u16 device; |
34 | unsigned int quirks; | 34 | unsigned int quirks; |
35 | } b43_sdio_quirks[] = { | 35 | } b43_sdio_quirks[] = { |
36 | { 0x14E4, 0x4318, SSB_QUIRK_SDIO_READ_AFTER_WRITE32, }, | 36 | { 0x14E4, 0x4318, SSB_QUIRK_SDIO_READ_AFTER_WRITE32, }, |
37 | { }, | 37 | { }, |
38 | }; | 38 | }; |
39 | 39 | ||
40 | 40 | ||
41 | static unsigned int b43_sdio_get_quirks(u16 vendor, u16 device) | 41 | static unsigned int b43_sdio_get_quirks(u16 vendor, u16 device) |
42 | { | 42 | { |
43 | const struct b43_sdio_quirk *q; | 43 | const struct b43_sdio_quirk *q; |
44 | 44 | ||
45 | for (q = b43_sdio_quirks; q->quirks; q++) { | 45 | for (q = b43_sdio_quirks; q->quirks; q++) { |
46 | if (vendor == q->vendor && device == q->device) | 46 | if (vendor == q->vendor && device == q->device) |
47 | return q->quirks; | 47 | return q->quirks; |
48 | } | 48 | } |
49 | 49 | ||
50 | return 0; | 50 | return 0; |
51 | } | 51 | } |
52 | 52 | ||
53 | static void b43_sdio_interrupt_dispatcher(struct sdio_func *func) | 53 | static void b43_sdio_interrupt_dispatcher(struct sdio_func *func) |
54 | { | 54 | { |
55 | struct b43_sdio *sdio = sdio_get_drvdata(func); | 55 | struct b43_sdio *sdio = sdio_get_drvdata(func); |
56 | struct b43_wldev *dev = sdio->irq_handler_opaque; | 56 | struct b43_wldev *dev = sdio->irq_handler_opaque; |
57 | 57 | ||
58 | if (unlikely(b43_status(dev) < B43_STAT_STARTED)) | 58 | if (unlikely(b43_status(dev) < B43_STAT_STARTED)) |
59 | return; | 59 | return; |
60 | 60 | ||
61 | sdio_release_host(func); | 61 | sdio_release_host(func); |
62 | sdio->irq_handler(dev); | 62 | sdio->irq_handler(dev); |
63 | sdio_claim_host(func); | 63 | sdio_claim_host(func); |
64 | } | 64 | } |
65 | 65 | ||
66 | int b43_sdio_request_irq(struct b43_wldev *dev, | 66 | int b43_sdio_request_irq(struct b43_wldev *dev, |
67 | void (*handler)(struct b43_wldev *dev)) | 67 | void (*handler)(struct b43_wldev *dev)) |
68 | { | 68 | { |
69 | struct ssb_bus *bus = dev->dev->sdev->bus; | 69 | struct ssb_bus *bus = dev->dev->sdev->bus; |
70 | struct sdio_func *func = bus->host_sdio; | 70 | struct sdio_func *func = bus->host_sdio; |
71 | struct b43_sdio *sdio = sdio_get_drvdata(func); | 71 | struct b43_sdio *sdio = sdio_get_drvdata(func); |
72 | int err; | 72 | int err; |
73 | 73 | ||
74 | sdio->irq_handler_opaque = dev; | 74 | sdio->irq_handler_opaque = dev; |
75 | sdio->irq_handler = handler; | 75 | sdio->irq_handler = handler; |
76 | sdio_claim_host(func); | 76 | sdio_claim_host(func); |
77 | err = sdio_claim_irq(func, b43_sdio_interrupt_dispatcher); | 77 | err = sdio_claim_irq(func, b43_sdio_interrupt_dispatcher); |
78 | sdio_release_host(func); | 78 | sdio_release_host(func); |
79 | 79 | ||
80 | return err; | 80 | return err; |
81 | } | 81 | } |
82 | 82 | ||
83 | void b43_sdio_free_irq(struct b43_wldev *dev) | 83 | void b43_sdio_free_irq(struct b43_wldev *dev) |
84 | { | 84 | { |
85 | struct ssb_bus *bus = dev->dev->sdev->bus; | 85 | struct ssb_bus *bus = dev->dev->sdev->bus; |
86 | struct sdio_func *func = bus->host_sdio; | 86 | struct sdio_func *func = bus->host_sdio; |
87 | struct b43_sdio *sdio = sdio_get_drvdata(func); | 87 | struct b43_sdio *sdio = sdio_get_drvdata(func); |
88 | 88 | ||
89 | sdio_claim_host(func); | 89 | sdio_claim_host(func); |
90 | sdio_release_irq(func); | 90 | sdio_release_irq(func); |
91 | sdio_release_host(func); | 91 | sdio_release_host(func); |
92 | sdio->irq_handler_opaque = NULL; | 92 | sdio->irq_handler_opaque = NULL; |
93 | sdio->irq_handler = NULL; | 93 | sdio->irq_handler = NULL; |
94 | } | 94 | } |
95 | 95 | ||
96 | static int __devinit b43_sdio_probe(struct sdio_func *func, | 96 | static int __devinit b43_sdio_probe(struct sdio_func *func, |
97 | const struct sdio_device_id *id) | 97 | const struct sdio_device_id *id) |
98 | { | 98 | { |
99 | struct b43_sdio *sdio; | 99 | struct b43_sdio *sdio; |
100 | struct sdio_func_tuple *tuple; | 100 | struct sdio_func_tuple *tuple; |
101 | u16 vendor = 0, device = 0; | 101 | u16 vendor = 0, device = 0; |
102 | int error; | 102 | int error; |
103 | 103 | ||
104 | /* Look for the card chip identifier. */ | 104 | /* Look for the card chip identifier. */ |
105 | tuple = func->tuples; | 105 | tuple = func->tuples; |
106 | while (tuple) { | 106 | while (tuple) { |
107 | switch (tuple->code) { | 107 | switch (tuple->code) { |
108 | case 0x80: | 108 | case 0x80: |
109 | switch (tuple->data[0]) { | 109 | switch (tuple->data[0]) { |
110 | case HNBU_CHIPID: | 110 | case HNBU_CHIPID: |
111 | if (tuple->size != 5) | 111 | if (tuple->size != 5) |
112 | break; | 112 | break; |
113 | vendor = tuple->data[1] | (tuple->data[2]<<8); | 113 | vendor = tuple->data[1] | (tuple->data[2]<<8); |
114 | device = tuple->data[3] | (tuple->data[4]<<8); | 114 | device = tuple->data[3] | (tuple->data[4]<<8); |
115 | dev_info(&func->dev, "Chip ID %04x:%04x\n", | 115 | dev_info(&func->dev, "Chip ID %04x:%04x\n", |
116 | vendor, device); | 116 | vendor, device); |
117 | break; | 117 | break; |
118 | default: | 118 | default: |
119 | break; | 119 | break; |
120 | } | 120 | } |
121 | break; | 121 | break; |
122 | default: | 122 | default: |
123 | break; | 123 | break; |
124 | } | 124 | } |
125 | tuple = tuple->next; | 125 | tuple = tuple->next; |
126 | } | 126 | } |
127 | if (!vendor || !device) { | 127 | if (!vendor || !device) { |
128 | error = -ENODEV; | 128 | error = -ENODEV; |
129 | goto out; | 129 | goto out; |
130 | } | 130 | } |
131 | 131 | ||
132 | sdio_claim_host(func); | 132 | sdio_claim_host(func); |
133 | error = sdio_set_block_size(func, B43_SDIO_BLOCK_SIZE); | 133 | error = sdio_set_block_size(func, B43_SDIO_BLOCK_SIZE); |
134 | if (error) { | 134 | if (error) { |
135 | dev_err(&func->dev, "failed to set block size to %u bytes," | 135 | dev_err(&func->dev, "failed to set block size to %u bytes," |
136 | " error %d\n", B43_SDIO_BLOCK_SIZE, error); | 136 | " error %d\n", B43_SDIO_BLOCK_SIZE, error); |
137 | goto err_release_host; | 137 | goto err_release_host; |
138 | } | 138 | } |
139 | error = sdio_enable_func(func); | 139 | error = sdio_enable_func(func); |
140 | if (error) { | 140 | if (error) { |
141 | dev_err(&func->dev, "failed to enable func, error %d\n", error); | 141 | dev_err(&func->dev, "failed to enable func, error %d\n", error); |
142 | goto err_release_host; | 142 | goto err_release_host; |
143 | } | 143 | } |
144 | sdio_release_host(func); | 144 | sdio_release_host(func); |
145 | 145 | ||
146 | sdio = kzalloc(sizeof(*sdio), GFP_KERNEL); | 146 | sdio = kzalloc(sizeof(*sdio), GFP_KERNEL); |
147 | if (!sdio) { | 147 | if (!sdio) { |
148 | error = -ENOMEM; | 148 | error = -ENOMEM; |
149 | dev_err(&func->dev, "failed to allocate ssb bus\n"); | 149 | dev_err(&func->dev, "failed to allocate ssb bus\n"); |
150 | goto err_disable_func; | 150 | goto err_disable_func; |
151 | } | 151 | } |
152 | error = ssb_bus_sdiobus_register(&sdio->ssb, func, | 152 | error = ssb_bus_sdiobus_register(&sdio->ssb, func, |
153 | b43_sdio_get_quirks(vendor, device)); | 153 | b43_sdio_get_quirks(vendor, device)); |
154 | if (error) { | 154 | if (error) { |
155 | dev_err(&func->dev, "failed to register ssb sdio bus," | 155 | dev_err(&func->dev, "failed to register ssb sdio bus," |
156 | " error %d\n", error); | 156 | " error %d\n", error); |
157 | goto err_free_ssb; | 157 | goto err_free_ssb; |
158 | } | 158 | } |
159 | sdio_set_drvdata(func, sdio); | 159 | sdio_set_drvdata(func, sdio); |
160 | 160 | ||
161 | return 0; | 161 | return 0; |
162 | 162 | ||
163 | err_free_ssb: | 163 | err_free_ssb: |
164 | kfree(sdio); | 164 | kfree(sdio); |
165 | err_disable_func: | 165 | err_disable_func: |
166 | sdio_claim_host(func); | 166 | sdio_claim_host(func); |
167 | sdio_disable_func(func); | 167 | sdio_disable_func(func); |
168 | err_release_host: | 168 | err_release_host: |
169 | sdio_release_host(func); | 169 | sdio_release_host(func); |
170 | out: | 170 | out: |
171 | return error; | 171 | return error; |
172 | } | 172 | } |
173 | 173 | ||
174 | static void __devexit b43_sdio_remove(struct sdio_func *func) | 174 | static void __devexit b43_sdio_remove(struct sdio_func *func) |
175 | { | 175 | { |
176 | struct b43_sdio *sdio = sdio_get_drvdata(func); | 176 | struct b43_sdio *sdio = sdio_get_drvdata(func); |
177 | 177 | ||
178 | ssb_bus_unregister(&sdio->ssb); | 178 | ssb_bus_unregister(&sdio->ssb); |
179 | sdio_claim_host(func); | 179 | sdio_claim_host(func); |
180 | sdio_disable_func(func); | 180 | sdio_disable_func(func); |
181 | sdio_release_host(func); | 181 | sdio_release_host(func); |
182 | kfree(sdio); | 182 | kfree(sdio); |
183 | sdio_set_drvdata(func, NULL); | 183 | sdio_set_drvdata(func, NULL); |
184 | } | 184 | } |
185 | 185 | ||
186 | static const struct sdio_device_id b43_sdio_ids[] = { | 186 | static const struct sdio_device_id b43_sdio_ids[] = { |
187 | { SDIO_DEVICE(0x02d0, 0x044b) }, /* Nintendo Wii WLAN daughter card */ | 187 | { SDIO_DEVICE(0x02d0, 0x044b) }, /* Nintendo Wii WLAN daughter card */ |
188 | { SDIO_DEVICE(0x0092, 0x0004) }, /* C-guys, Inc. EW-CG1102GC */ | 188 | { SDIO_DEVICE(0x0092, 0x0004) }, /* C-guys, Inc. EW-CG1102GC */ |
189 | { }, | 189 | { }, |
190 | }; | 190 | }; |
191 | 191 | ||
192 | static struct sdio_driver b43_sdio_driver = { | 192 | static struct sdio_driver b43_sdio_driver = { |
193 | .name = "b43-sdio", | 193 | .name = "b43-sdio", |
194 | .id_table = b43_sdio_ids, | 194 | .id_table = b43_sdio_ids, |
195 | .probe = b43_sdio_probe, | 195 | .probe = b43_sdio_probe, |
196 | .remove = b43_sdio_remove, | 196 | .remove = __devexit_p(b43_sdio_remove), |
197 | }; | 197 | }; |
198 | 198 | ||
199 | int b43_sdio_init(void) | 199 | int b43_sdio_init(void) |
200 | { | 200 | { |
201 | return sdio_register_driver(&b43_sdio_driver); | 201 | return sdio_register_driver(&b43_sdio_driver); |
202 | } | 202 | } |
203 | 203 | ||
204 | void b43_sdio_exit(void) | 204 | void b43_sdio_exit(void) |
205 | { | 205 | { |
206 | sdio_unregister_driver(&b43_sdio_driver); | 206 | sdio_unregister_driver(&b43_sdio_driver); |
207 | } | 207 | } |
208 | 208 |
drivers/net/wireless/p54/p54usb.c
1 | 1 | ||
2 | /* | 2 | /* |
3 | * Linux device driver for USB based Prism54 | 3 | * Linux device driver for USB based Prism54 |
4 | * | 4 | * |
5 | * Copyright (c) 2006, Michael Wu <flamingice@sourmilk.net> | 5 | * Copyright (c) 2006, Michael Wu <flamingice@sourmilk.net> |
6 | * | 6 | * |
7 | * Based on the islsm (softmac prism54) driver, which is: | 7 | * Based on the islsm (softmac prism54) driver, which is: |
8 | * Copyright 2004-2006 Jean-Baptiste Note <jbnote@gmail.com>, et al. | 8 | * Copyright 2004-2006 Jean-Baptiste Note <jbnote@gmail.com>, et al. |
9 | * | 9 | * |
10 | * This program is free software; you can redistribute it and/or modify | 10 | * This program is free software; you can redistribute it and/or modify |
11 | * it under the terms of the GNU General Public License version 2 as | 11 | * it under the terms of the GNU General Public License version 2 as |
12 | * published by the Free Software Foundation. | 12 | * published by the Free Software Foundation. |
13 | */ | 13 | */ |
14 | 14 | ||
15 | #include <linux/init.h> | 15 | #include <linux/init.h> |
16 | #include <linux/usb.h> | 16 | #include <linux/usb.h> |
17 | #include <linux/pci.h> | 17 | #include <linux/pci.h> |
18 | #include <linux/slab.h> | 18 | #include <linux/slab.h> |
19 | #include <linux/firmware.h> | 19 | #include <linux/firmware.h> |
20 | #include <linux/etherdevice.h> | 20 | #include <linux/etherdevice.h> |
21 | #include <linux/delay.h> | 21 | #include <linux/delay.h> |
22 | #include <linux/crc32.h> | 22 | #include <linux/crc32.h> |
23 | #include <linux/module.h> | 23 | #include <linux/module.h> |
24 | #include <net/mac80211.h> | 24 | #include <net/mac80211.h> |
25 | 25 | ||
26 | #include "p54.h" | 26 | #include "p54.h" |
27 | #include "lmac.h" | 27 | #include "lmac.h" |
28 | #include "p54usb.h" | 28 | #include "p54usb.h" |
29 | 29 | ||
30 | MODULE_AUTHOR("Michael Wu <flamingice@sourmilk.net>"); | 30 | MODULE_AUTHOR("Michael Wu <flamingice@sourmilk.net>"); |
31 | MODULE_DESCRIPTION("Prism54 USB wireless driver"); | 31 | MODULE_DESCRIPTION("Prism54 USB wireless driver"); |
32 | MODULE_LICENSE("GPL"); | 32 | MODULE_LICENSE("GPL"); |
33 | MODULE_ALIAS("prism54usb"); | 33 | MODULE_ALIAS("prism54usb"); |
34 | MODULE_FIRMWARE("isl3886usb"); | 34 | MODULE_FIRMWARE("isl3886usb"); |
35 | MODULE_FIRMWARE("isl3887usb"); | 35 | MODULE_FIRMWARE("isl3887usb"); |
36 | 36 | ||
37 | /* | 37 | /* |
38 | * Note: | 38 | * Note: |
39 | * | 39 | * |
40 | * Always update our wiki's device list (located at: | 40 | * Always update our wiki's device list (located at: |
41 | * http://wireless.kernel.org/en/users/Drivers/p54/devices ), | 41 | * http://wireless.kernel.org/en/users/Drivers/p54/devices ), |
42 | * whenever you add a new device. | 42 | * whenever you add a new device. |
43 | */ | 43 | */ |
44 | 44 | ||
45 | static struct usb_device_id p54u_table[] __devinitdata = { | 45 | static struct usb_device_id p54u_table[] __devinitdata = { |
46 | /* Version 1 devices (pci chip + net2280) */ | 46 | /* Version 1 devices (pci chip + net2280) */ |
47 | {USB_DEVICE(0x0411, 0x0050)}, /* Buffalo WLI2-USB2-G54 */ | 47 | {USB_DEVICE(0x0411, 0x0050)}, /* Buffalo WLI2-USB2-G54 */ |
48 | {USB_DEVICE(0x045e, 0x00c2)}, /* Microsoft MN-710 */ | 48 | {USB_DEVICE(0x045e, 0x00c2)}, /* Microsoft MN-710 */ |
49 | {USB_DEVICE(0x0506, 0x0a11)}, /* 3COM 3CRWE254G72 */ | 49 | {USB_DEVICE(0x0506, 0x0a11)}, /* 3COM 3CRWE254G72 */ |
50 | {USB_DEVICE(0x06b9, 0x0120)}, /* Thomson SpeedTouch 120g */ | 50 | {USB_DEVICE(0x06b9, 0x0120)}, /* Thomson SpeedTouch 120g */ |
51 | {USB_DEVICE(0x0707, 0xee06)}, /* SMC 2862W-G */ | 51 | {USB_DEVICE(0x0707, 0xee06)}, /* SMC 2862W-G */ |
52 | {USB_DEVICE(0x07aa, 0x001c)}, /* Corega CG-WLUSB2GT */ | 52 | {USB_DEVICE(0x07aa, 0x001c)}, /* Corega CG-WLUSB2GT */ |
53 | {USB_DEVICE(0x083a, 0x4501)}, /* Accton 802.11g WN4501 USB */ | 53 | {USB_DEVICE(0x083a, 0x4501)}, /* Accton 802.11g WN4501 USB */ |
54 | {USB_DEVICE(0x083a, 0x4502)}, /* Siemens Gigaset USB Adapter */ | 54 | {USB_DEVICE(0x083a, 0x4502)}, /* Siemens Gigaset USB Adapter */ |
55 | {USB_DEVICE(0x083a, 0x5501)}, /* Phillips CPWUA054 */ | 55 | {USB_DEVICE(0x083a, 0x5501)}, /* Phillips CPWUA054 */ |
56 | {USB_DEVICE(0x0846, 0x4200)}, /* Netgear WG121 */ | 56 | {USB_DEVICE(0x0846, 0x4200)}, /* Netgear WG121 */ |
57 | {USB_DEVICE(0x0846, 0x4210)}, /* Netgear WG121 the second ? */ | 57 | {USB_DEVICE(0x0846, 0x4210)}, /* Netgear WG121 the second ? */ |
58 | {USB_DEVICE(0x0846, 0x4220)}, /* Netgear WG111 */ | 58 | {USB_DEVICE(0x0846, 0x4220)}, /* Netgear WG111 */ |
59 | {USB_DEVICE(0x09aa, 0x1000)}, /* Spinnaker Proto board */ | 59 | {USB_DEVICE(0x09aa, 0x1000)}, /* Spinnaker Proto board */ |
60 | {USB_DEVICE(0x0bf8, 0x1007)}, /* Fujitsu E-5400 USB */ | 60 | {USB_DEVICE(0x0bf8, 0x1007)}, /* Fujitsu E-5400 USB */ |
61 | {USB_DEVICE(0x0cde, 0x0006)}, /* Medion 40900, Roper Europe */ | 61 | {USB_DEVICE(0x0cde, 0x0006)}, /* Medion 40900, Roper Europe */ |
62 | {USB_DEVICE(0x0db0, 0x6826)}, /* MSI UB54G (MS-6826) */ | 62 | {USB_DEVICE(0x0db0, 0x6826)}, /* MSI UB54G (MS-6826) */ |
63 | {USB_DEVICE(0x107b, 0x55f2)}, /* Gateway WGU-210 (Gemtek) */ | 63 | {USB_DEVICE(0x107b, 0x55f2)}, /* Gateway WGU-210 (Gemtek) */ |
64 | {USB_DEVICE(0x124a, 0x4023)}, /* Shuttle PN15, Airvast WM168g, IOGear GWU513 */ | 64 | {USB_DEVICE(0x124a, 0x4023)}, /* Shuttle PN15, Airvast WM168g, IOGear GWU513 */ |
65 | {USB_DEVICE(0x1435, 0x0210)}, /* Inventel UR054G */ | 65 | {USB_DEVICE(0x1435, 0x0210)}, /* Inventel UR054G */ |
66 | {USB_DEVICE(0x15a9, 0x0002)}, /* Gemtek WUBI-100GW 802.11g */ | 66 | {USB_DEVICE(0x15a9, 0x0002)}, /* Gemtek WUBI-100GW 802.11g */ |
67 | {USB_DEVICE(0x1630, 0x0005)}, /* 2Wire 802.11g USB (v1) / Z-Com */ | 67 | {USB_DEVICE(0x1630, 0x0005)}, /* 2Wire 802.11g USB (v1) / Z-Com */ |
68 | {USB_DEVICE(0x182d, 0x096b)}, /* Sitecom WL-107 */ | 68 | {USB_DEVICE(0x182d, 0x096b)}, /* Sitecom WL-107 */ |
69 | {USB_DEVICE(0x1915, 0x2234)}, /* Linksys WUSB54G OEM */ | 69 | {USB_DEVICE(0x1915, 0x2234)}, /* Linksys WUSB54G OEM */ |
70 | {USB_DEVICE(0x1915, 0x2235)}, /* Linksys WUSB54G Portable OEM */ | 70 | {USB_DEVICE(0x1915, 0x2235)}, /* Linksys WUSB54G Portable OEM */ |
71 | {USB_DEVICE(0x2001, 0x3701)}, /* DLink DWL-G120 Spinnaker */ | 71 | {USB_DEVICE(0x2001, 0x3701)}, /* DLink DWL-G120 Spinnaker */ |
72 | {USB_DEVICE(0x2001, 0x3703)}, /* DLink DWL-G122 */ | 72 | {USB_DEVICE(0x2001, 0x3703)}, /* DLink DWL-G122 */ |
73 | {USB_DEVICE(0x2001, 0x3762)}, /* Conceptronic C54U */ | 73 | {USB_DEVICE(0x2001, 0x3762)}, /* Conceptronic C54U */ |
74 | {USB_DEVICE(0x5041, 0x2234)}, /* Linksys WUSB54G */ | 74 | {USB_DEVICE(0x5041, 0x2234)}, /* Linksys WUSB54G */ |
75 | {USB_DEVICE(0x5041, 0x2235)}, /* Linksys WUSB54G Portable */ | 75 | {USB_DEVICE(0x5041, 0x2235)}, /* Linksys WUSB54G Portable */ |
76 | 76 | ||
77 | /* Version 2 devices (3887) */ | 77 | /* Version 2 devices (3887) */ |
78 | {USB_DEVICE(0x0471, 0x1230)}, /* Philips CPWUA054/00 */ | 78 | {USB_DEVICE(0x0471, 0x1230)}, /* Philips CPWUA054/00 */ |
79 | {USB_DEVICE(0x050d, 0x7050)}, /* Belkin F5D7050 ver 1000 */ | 79 | {USB_DEVICE(0x050d, 0x7050)}, /* Belkin F5D7050 ver 1000 */ |
80 | {USB_DEVICE(0x0572, 0x2000)}, /* Cohiba Proto board */ | 80 | {USB_DEVICE(0x0572, 0x2000)}, /* Cohiba Proto board */ |
81 | {USB_DEVICE(0x0572, 0x2002)}, /* Cohiba Proto board */ | 81 | {USB_DEVICE(0x0572, 0x2002)}, /* Cohiba Proto board */ |
82 | {USB_DEVICE(0x06a9, 0x000e)}, /* Westell 802.11g USB (A90-211WG-01) */ | 82 | {USB_DEVICE(0x06a9, 0x000e)}, /* Westell 802.11g USB (A90-211WG-01) */ |
83 | {USB_DEVICE(0x06b9, 0x0121)}, /* Thomson SpeedTouch 121g */ | 83 | {USB_DEVICE(0x06b9, 0x0121)}, /* Thomson SpeedTouch 121g */ |
84 | {USB_DEVICE(0x0707, 0xee13)}, /* SMC 2862W-G version 2 */ | 84 | {USB_DEVICE(0x0707, 0xee13)}, /* SMC 2862W-G version 2 */ |
85 | {USB_DEVICE(0x083a, 0x4521)}, /* Siemens Gigaset USB Adapter 54 version 2 */ | 85 | {USB_DEVICE(0x083a, 0x4521)}, /* Siemens Gigaset USB Adapter 54 version 2 */ |
86 | {USB_DEVICE(0x083a, 0xc501)}, /* Zoom Wireless-G 4410 */ | 86 | {USB_DEVICE(0x083a, 0xc501)}, /* Zoom Wireless-G 4410 */ |
87 | {USB_DEVICE(0x083a, 0xf503)}, /* Accton FD7050E ver 1010ec */ | 87 | {USB_DEVICE(0x083a, 0xf503)}, /* Accton FD7050E ver 1010ec */ |
88 | {USB_DEVICE(0x0846, 0x4240)}, /* Netgear WG111 (v2) */ | 88 | {USB_DEVICE(0x0846, 0x4240)}, /* Netgear WG111 (v2) */ |
89 | {USB_DEVICE(0x0915, 0x2000)}, /* Cohiba Proto board */ | 89 | {USB_DEVICE(0x0915, 0x2000)}, /* Cohiba Proto board */ |
90 | {USB_DEVICE(0x0915, 0x2002)}, /* Cohiba Proto board */ | 90 | {USB_DEVICE(0x0915, 0x2002)}, /* Cohiba Proto board */ |
91 | {USB_DEVICE(0x0baf, 0x0118)}, /* U.S. Robotics U5 802.11g Adapter*/ | 91 | {USB_DEVICE(0x0baf, 0x0118)}, /* U.S. Robotics U5 802.11g Adapter*/ |
92 | {USB_DEVICE(0x0bf8, 0x1009)}, /* FUJITSU E-5400 USB D1700*/ | 92 | {USB_DEVICE(0x0bf8, 0x1009)}, /* FUJITSU E-5400 USB D1700*/ |
93 | /* {USB_DEVICE(0x0cde, 0x0006)}, * Medion MD40900 already listed above, | 93 | /* {USB_DEVICE(0x0cde, 0x0006)}, * Medion MD40900 already listed above, |
94 | * just noting it here for clarity */ | 94 | * just noting it here for clarity */ |
95 | {USB_DEVICE(0x0cde, 0x0008)}, /* Sagem XG703A */ | 95 | {USB_DEVICE(0x0cde, 0x0008)}, /* Sagem XG703A */ |
96 | {USB_DEVICE(0x0cde, 0x0015)}, /* Zcomax XG-705A */ | 96 | {USB_DEVICE(0x0cde, 0x0015)}, /* Zcomax XG-705A */ |
97 | {USB_DEVICE(0x0d8e, 0x3762)}, /* DLink DWL-G120 Cohiba */ | 97 | {USB_DEVICE(0x0d8e, 0x3762)}, /* DLink DWL-G120 Cohiba */ |
98 | {USB_DEVICE(0x124a, 0x4025)}, /* IOGear GWU513 (GW3887IK chip) */ | 98 | {USB_DEVICE(0x124a, 0x4025)}, /* IOGear GWU513 (GW3887IK chip) */ |
99 | {USB_DEVICE(0x1260, 0xee22)}, /* SMC 2862W-G version 2 */ | 99 | {USB_DEVICE(0x1260, 0xee22)}, /* SMC 2862W-G version 2 */ |
100 | {USB_DEVICE(0x13b1, 0x000a)}, /* Linksys WUSB54G ver 2 */ | 100 | {USB_DEVICE(0x13b1, 0x000a)}, /* Linksys WUSB54G ver 2 */ |
101 | {USB_DEVICE(0x13B1, 0x000C)}, /* Linksys WUSB54AG */ | 101 | {USB_DEVICE(0x13B1, 0x000C)}, /* Linksys WUSB54AG */ |
102 | {USB_DEVICE(0x1413, 0x5400)}, /* Telsey 802.11g USB2.0 Adapter */ | 102 | {USB_DEVICE(0x1413, 0x5400)}, /* Telsey 802.11g USB2.0 Adapter */ |
103 | {USB_DEVICE(0x1435, 0x0427)}, /* Inventel UR054G */ | 103 | {USB_DEVICE(0x1435, 0x0427)}, /* Inventel UR054G */ |
104 | {USB_DEVICE(0x1668, 0x1050)}, /* Actiontec 802UIG-1 */ | 104 | {USB_DEVICE(0x1668, 0x1050)}, /* Actiontec 802UIG-1 */ |
105 | {USB_DEVICE(0x1740, 0x1000)}, /* Senao NUB-350 */ | 105 | {USB_DEVICE(0x1740, 0x1000)}, /* Senao NUB-350 */ |
106 | {USB_DEVICE(0x2001, 0x3704)}, /* DLink DWL-G122 rev A2 */ | 106 | {USB_DEVICE(0x2001, 0x3704)}, /* DLink DWL-G122 rev A2 */ |
107 | {USB_DEVICE(0x2001, 0x3705)}, /* D-Link DWL-G120 rev C1 */ | 107 | {USB_DEVICE(0x2001, 0x3705)}, /* D-Link DWL-G120 rev C1 */ |
108 | {USB_DEVICE(0x413c, 0x5513)}, /* Dell WLA3310 USB Wireless Adapter */ | 108 | {USB_DEVICE(0x413c, 0x5513)}, /* Dell WLA3310 USB Wireless Adapter */ |
109 | {USB_DEVICE(0x413c, 0x8102)}, /* Spinnaker DUT */ | 109 | {USB_DEVICE(0x413c, 0x8102)}, /* Spinnaker DUT */ |
110 | {USB_DEVICE(0x413c, 0x8104)}, /* Cohiba Proto board */ | 110 | {USB_DEVICE(0x413c, 0x8104)}, /* Cohiba Proto board */ |
111 | {} | 111 | {} |
112 | }; | 112 | }; |
113 | 113 | ||
114 | MODULE_DEVICE_TABLE(usb, p54u_table); | 114 | MODULE_DEVICE_TABLE(usb, p54u_table); |
115 | 115 | ||
116 | static const struct { | 116 | static const struct { |
117 | u32 intf; | 117 | u32 intf; |
118 | enum p54u_hw_type type; | 118 | enum p54u_hw_type type; |
119 | const char *fw; | 119 | const char *fw; |
120 | char hw[20]; | 120 | char hw[20]; |
121 | } p54u_fwlist[__NUM_P54U_HWTYPES] = { | 121 | } p54u_fwlist[__NUM_P54U_HWTYPES] = { |
122 | { | 122 | { |
123 | .type = P54U_NET2280, | 123 | .type = P54U_NET2280, |
124 | .intf = FW_LM86, | 124 | .intf = FW_LM86, |
125 | .fw = "isl3886usb", | 125 | .fw = "isl3886usb", |
126 | .hw = "ISL3886 + net2280", | 126 | .hw = "ISL3886 + net2280", |
127 | }, | 127 | }, |
128 | { | 128 | { |
129 | .type = P54U_3887, | 129 | .type = P54U_3887, |
130 | .intf = FW_LM87, | 130 | .intf = FW_LM87, |
131 | .fw = "isl3887usb", | 131 | .fw = "isl3887usb", |
132 | .hw = "ISL3887", | 132 | .hw = "ISL3887", |
133 | }, | 133 | }, |
134 | }; | 134 | }; |
135 | 135 | ||
136 | static void p54u_rx_cb(struct urb *urb) | 136 | static void p54u_rx_cb(struct urb *urb) |
137 | { | 137 | { |
138 | struct sk_buff *skb = (struct sk_buff *) urb->context; | 138 | struct sk_buff *skb = (struct sk_buff *) urb->context; |
139 | struct p54u_rx_info *info = (struct p54u_rx_info *)skb->cb; | 139 | struct p54u_rx_info *info = (struct p54u_rx_info *)skb->cb; |
140 | struct ieee80211_hw *dev = info->dev; | 140 | struct ieee80211_hw *dev = info->dev; |
141 | struct p54u_priv *priv = dev->priv; | 141 | struct p54u_priv *priv = dev->priv; |
142 | 142 | ||
143 | skb_unlink(skb, &priv->rx_queue); | 143 | skb_unlink(skb, &priv->rx_queue); |
144 | 144 | ||
145 | if (unlikely(urb->status)) { | 145 | if (unlikely(urb->status)) { |
146 | dev_kfree_skb_irq(skb); | 146 | dev_kfree_skb_irq(skb); |
147 | return; | 147 | return; |
148 | } | 148 | } |
149 | 149 | ||
150 | skb_put(skb, urb->actual_length); | 150 | skb_put(skb, urb->actual_length); |
151 | 151 | ||
152 | if (priv->hw_type == P54U_NET2280) | 152 | if (priv->hw_type == P54U_NET2280) |
153 | skb_pull(skb, priv->common.tx_hdr_len); | 153 | skb_pull(skb, priv->common.tx_hdr_len); |
154 | if (priv->common.fw_interface == FW_LM87) { | 154 | if (priv->common.fw_interface == FW_LM87) { |
155 | skb_pull(skb, 4); | 155 | skb_pull(skb, 4); |
156 | skb_put(skb, 4); | 156 | skb_put(skb, 4); |
157 | } | 157 | } |
158 | 158 | ||
159 | if (p54_rx(dev, skb)) { | 159 | if (p54_rx(dev, skb)) { |
160 | skb = dev_alloc_skb(priv->common.rx_mtu + 32); | 160 | skb = dev_alloc_skb(priv->common.rx_mtu + 32); |
161 | if (unlikely(!skb)) { | 161 | if (unlikely(!skb)) { |
162 | /* TODO check rx queue length and refill *somewhere* */ | 162 | /* TODO check rx queue length and refill *somewhere* */ |
163 | return; | 163 | return; |
164 | } | 164 | } |
165 | 165 | ||
166 | info = (struct p54u_rx_info *) skb->cb; | 166 | info = (struct p54u_rx_info *) skb->cb; |
167 | info->urb = urb; | 167 | info->urb = urb; |
168 | info->dev = dev; | 168 | info->dev = dev; |
169 | urb->transfer_buffer = skb_tail_pointer(skb); | 169 | urb->transfer_buffer = skb_tail_pointer(skb); |
170 | urb->context = skb; | 170 | urb->context = skb; |
171 | } else { | 171 | } else { |
172 | if (priv->hw_type == P54U_NET2280) | 172 | if (priv->hw_type == P54U_NET2280) |
173 | skb_push(skb, priv->common.tx_hdr_len); | 173 | skb_push(skb, priv->common.tx_hdr_len); |
174 | if (priv->common.fw_interface == FW_LM87) { | 174 | if (priv->common.fw_interface == FW_LM87) { |
175 | skb_push(skb, 4); | 175 | skb_push(skb, 4); |
176 | skb_put(skb, 4); | 176 | skb_put(skb, 4); |
177 | } | 177 | } |
178 | skb_reset_tail_pointer(skb); | 178 | skb_reset_tail_pointer(skb); |
179 | skb_trim(skb, 0); | 179 | skb_trim(skb, 0); |
180 | urb->transfer_buffer = skb_tail_pointer(skb); | 180 | urb->transfer_buffer = skb_tail_pointer(skb); |
181 | } | 181 | } |
182 | skb_queue_tail(&priv->rx_queue, skb); | 182 | skb_queue_tail(&priv->rx_queue, skb); |
183 | usb_anchor_urb(urb, &priv->submitted); | 183 | usb_anchor_urb(urb, &priv->submitted); |
184 | if (usb_submit_urb(urb, GFP_ATOMIC)) { | 184 | if (usb_submit_urb(urb, GFP_ATOMIC)) { |
185 | skb_unlink(skb, &priv->rx_queue); | 185 | skb_unlink(skb, &priv->rx_queue); |
186 | usb_unanchor_urb(urb); | 186 | usb_unanchor_urb(urb); |
187 | dev_kfree_skb_irq(skb); | 187 | dev_kfree_skb_irq(skb); |
188 | } | 188 | } |
189 | } | 189 | } |
190 | 190 | ||
191 | static void p54u_tx_cb(struct urb *urb) | 191 | static void p54u_tx_cb(struct urb *urb) |
192 | { | 192 | { |
193 | struct sk_buff *skb = urb->context; | 193 | struct sk_buff *skb = urb->context; |
194 | struct ieee80211_hw *dev = | 194 | struct ieee80211_hw *dev = |
195 | usb_get_intfdata(usb_ifnum_to_if(urb->dev, 0)); | 195 | usb_get_intfdata(usb_ifnum_to_if(urb->dev, 0)); |
196 | 196 | ||
197 | p54_free_skb(dev, skb); | 197 | p54_free_skb(dev, skb); |
198 | } | 198 | } |
199 | 199 | ||
200 | static void p54u_tx_dummy_cb(struct urb *urb) { } | 200 | static void p54u_tx_dummy_cb(struct urb *urb) { } |
201 | 201 | ||
202 | static void p54u_free_urbs(struct ieee80211_hw *dev) | 202 | static void p54u_free_urbs(struct ieee80211_hw *dev) |
203 | { | 203 | { |
204 | struct p54u_priv *priv = dev->priv; | 204 | struct p54u_priv *priv = dev->priv; |
205 | usb_kill_anchored_urbs(&priv->submitted); | 205 | usb_kill_anchored_urbs(&priv->submitted); |
206 | } | 206 | } |
207 | 207 | ||
208 | static void p54u_stop(struct ieee80211_hw *dev) | 208 | static void p54u_stop(struct ieee80211_hw *dev) |
209 | { | 209 | { |
210 | /* | 210 | /* |
211 | * TODO: figure out how to reliably stop the 3887 and net2280 so | 211 | * TODO: figure out how to reliably stop the 3887 and net2280 so |
212 | * the hardware is still usable next time we want to start it. | 212 | * the hardware is still usable next time we want to start it. |
213 | * until then, we just stop listening to the hardware.. | 213 | * until then, we just stop listening to the hardware.. |
214 | */ | 214 | */ |
215 | p54u_free_urbs(dev); | 215 | p54u_free_urbs(dev); |
216 | } | 216 | } |
217 | 217 | ||
218 | static int p54u_init_urbs(struct ieee80211_hw *dev) | 218 | static int p54u_init_urbs(struct ieee80211_hw *dev) |
219 | { | 219 | { |
220 | struct p54u_priv *priv = dev->priv; | 220 | struct p54u_priv *priv = dev->priv; |
221 | struct urb *entry = NULL; | 221 | struct urb *entry = NULL; |
222 | struct sk_buff *skb; | 222 | struct sk_buff *skb; |
223 | struct p54u_rx_info *info; | 223 | struct p54u_rx_info *info; |
224 | int ret = 0; | 224 | int ret = 0; |
225 | 225 | ||
226 | while (skb_queue_len(&priv->rx_queue) < 32) { | 226 | while (skb_queue_len(&priv->rx_queue) < 32) { |
227 | skb = __dev_alloc_skb(priv->common.rx_mtu + 32, GFP_KERNEL); | 227 | skb = __dev_alloc_skb(priv->common.rx_mtu + 32, GFP_KERNEL); |
228 | if (!skb) { | 228 | if (!skb) { |
229 | ret = -ENOMEM; | 229 | ret = -ENOMEM; |
230 | goto err; | 230 | goto err; |
231 | } | 231 | } |
232 | entry = usb_alloc_urb(0, GFP_KERNEL); | 232 | entry = usb_alloc_urb(0, GFP_KERNEL); |
233 | if (!entry) { | 233 | if (!entry) { |
234 | ret = -ENOMEM; | 234 | ret = -ENOMEM; |
235 | goto err; | 235 | goto err; |
236 | } | 236 | } |
237 | 237 | ||
238 | usb_fill_bulk_urb(entry, priv->udev, | 238 | usb_fill_bulk_urb(entry, priv->udev, |
239 | usb_rcvbulkpipe(priv->udev, P54U_PIPE_DATA), | 239 | usb_rcvbulkpipe(priv->udev, P54U_PIPE_DATA), |
240 | skb_tail_pointer(skb), | 240 | skb_tail_pointer(skb), |
241 | priv->common.rx_mtu + 32, p54u_rx_cb, skb); | 241 | priv->common.rx_mtu + 32, p54u_rx_cb, skb); |
242 | info = (struct p54u_rx_info *) skb->cb; | 242 | info = (struct p54u_rx_info *) skb->cb; |
243 | info->urb = entry; | 243 | info->urb = entry; |
244 | info->dev = dev; | 244 | info->dev = dev; |
245 | skb_queue_tail(&priv->rx_queue, skb); | 245 | skb_queue_tail(&priv->rx_queue, skb); |
246 | 246 | ||
247 | usb_anchor_urb(entry, &priv->submitted); | 247 | usb_anchor_urb(entry, &priv->submitted); |
248 | ret = usb_submit_urb(entry, GFP_KERNEL); | 248 | ret = usb_submit_urb(entry, GFP_KERNEL); |
249 | if (ret) { | 249 | if (ret) { |
250 | skb_unlink(skb, &priv->rx_queue); | 250 | skb_unlink(skb, &priv->rx_queue); |
251 | usb_unanchor_urb(entry); | 251 | usb_unanchor_urb(entry); |
252 | goto err; | 252 | goto err; |
253 | } | 253 | } |
254 | usb_free_urb(entry); | 254 | usb_free_urb(entry); |
255 | entry = NULL; | 255 | entry = NULL; |
256 | } | 256 | } |
257 | 257 | ||
258 | return 0; | 258 | return 0; |
259 | 259 | ||
260 | err: | 260 | err: |
261 | usb_free_urb(entry); | 261 | usb_free_urb(entry); |
262 | kfree_skb(skb); | 262 | kfree_skb(skb); |
263 | p54u_free_urbs(dev); | 263 | p54u_free_urbs(dev); |
264 | return ret; | 264 | return ret; |
265 | } | 265 | } |
266 | 266 | ||
267 | static int p54u_open(struct ieee80211_hw *dev) | 267 | static int p54u_open(struct ieee80211_hw *dev) |
268 | { | 268 | { |
269 | /* | 269 | /* |
270 | * TODO: Because we don't know how to reliably stop the 3887 and | 270 | * TODO: Because we don't know how to reliably stop the 3887 and |
271 | * the isl3886+net2280, other than brutally cut off all | 271 | * the isl3886+net2280, other than brutally cut off all |
272 | * communications. We have to reinitialize the urbs on every start. | 272 | * communications. We have to reinitialize the urbs on every start. |
273 | */ | 273 | */ |
274 | return p54u_init_urbs(dev); | 274 | return p54u_init_urbs(dev); |
275 | } | 275 | } |
276 | 276 | ||
277 | static __le32 p54u_lm87_chksum(const __le32 *data, size_t length) | 277 | static __le32 p54u_lm87_chksum(const __le32 *data, size_t length) |
278 | { | 278 | { |
279 | u32 chk = 0; | 279 | u32 chk = 0; |
280 | 280 | ||
281 | length >>= 2; | 281 | length >>= 2; |
282 | while (length--) { | 282 | while (length--) { |
283 | chk ^= le32_to_cpu(*data++); | 283 | chk ^= le32_to_cpu(*data++); |
284 | chk = (chk >> 5) ^ (chk << 3); | 284 | chk = (chk >> 5) ^ (chk << 3); |
285 | } | 285 | } |
286 | 286 | ||
287 | return cpu_to_le32(chk); | 287 | return cpu_to_le32(chk); |
288 | } | 288 | } |
289 | 289 | ||
290 | static void p54u_tx_lm87(struct ieee80211_hw *dev, struct sk_buff *skb) | 290 | static void p54u_tx_lm87(struct ieee80211_hw *dev, struct sk_buff *skb) |
291 | { | 291 | { |
292 | struct p54u_priv *priv = dev->priv; | 292 | struct p54u_priv *priv = dev->priv; |
293 | struct urb *data_urb; | 293 | struct urb *data_urb; |
294 | struct lm87_tx_hdr *hdr = (void *)skb->data - sizeof(*hdr); | 294 | struct lm87_tx_hdr *hdr = (void *)skb->data - sizeof(*hdr); |
295 | 295 | ||
296 | data_urb = usb_alloc_urb(0, GFP_ATOMIC); | 296 | data_urb = usb_alloc_urb(0, GFP_ATOMIC); |
297 | if (!data_urb) { | 297 | if (!data_urb) { |
298 | p54_free_skb(dev, skb); | 298 | p54_free_skb(dev, skb); |
299 | return; | 299 | return; |
300 | } | 300 | } |
301 | 301 | ||
302 | hdr->chksum = p54u_lm87_chksum((__le32 *)skb->data, skb->len); | 302 | hdr->chksum = p54u_lm87_chksum((__le32 *)skb->data, skb->len); |
303 | hdr->device_addr = ((struct p54_hdr *)skb->data)->req_id; | 303 | hdr->device_addr = ((struct p54_hdr *)skb->data)->req_id; |
304 | 304 | ||
305 | usb_fill_bulk_urb(data_urb, priv->udev, | 305 | usb_fill_bulk_urb(data_urb, priv->udev, |
306 | usb_sndbulkpipe(priv->udev, P54U_PIPE_DATA), | 306 | usb_sndbulkpipe(priv->udev, P54U_PIPE_DATA), |
307 | hdr, skb->len + sizeof(*hdr), FREE_AFTER_TX(skb) ? | 307 | hdr, skb->len + sizeof(*hdr), FREE_AFTER_TX(skb) ? |
308 | p54u_tx_cb : p54u_tx_dummy_cb, skb); | 308 | p54u_tx_cb : p54u_tx_dummy_cb, skb); |
309 | data_urb->transfer_flags |= URB_ZERO_PACKET; | 309 | data_urb->transfer_flags |= URB_ZERO_PACKET; |
310 | 310 | ||
311 | usb_anchor_urb(data_urb, &priv->submitted); | 311 | usb_anchor_urb(data_urb, &priv->submitted); |
312 | if (usb_submit_urb(data_urb, GFP_ATOMIC)) { | 312 | if (usb_submit_urb(data_urb, GFP_ATOMIC)) { |
313 | usb_unanchor_urb(data_urb); | 313 | usb_unanchor_urb(data_urb); |
314 | p54_free_skb(dev, skb); | 314 | p54_free_skb(dev, skb); |
315 | } | 315 | } |
316 | usb_free_urb(data_urb); | 316 | usb_free_urb(data_urb); |
317 | } | 317 | } |
318 | 318 | ||
319 | static void p54u_tx_net2280(struct ieee80211_hw *dev, struct sk_buff *skb) | 319 | static void p54u_tx_net2280(struct ieee80211_hw *dev, struct sk_buff *skb) |
320 | { | 320 | { |
321 | struct p54u_priv *priv = dev->priv; | 321 | struct p54u_priv *priv = dev->priv; |
322 | struct urb *int_urb = NULL, *data_urb = NULL; | 322 | struct urb *int_urb = NULL, *data_urb = NULL; |
323 | struct net2280_tx_hdr *hdr = (void *)skb->data - sizeof(*hdr); | 323 | struct net2280_tx_hdr *hdr = (void *)skb->data - sizeof(*hdr); |
324 | struct net2280_reg_write *reg = NULL; | 324 | struct net2280_reg_write *reg = NULL; |
325 | int err = -ENOMEM; | 325 | int err = -ENOMEM; |
326 | 326 | ||
327 | reg = kmalloc(sizeof(*reg), GFP_ATOMIC); | 327 | reg = kmalloc(sizeof(*reg), GFP_ATOMIC); |
328 | if (!reg) | 328 | if (!reg) |
329 | goto out; | 329 | goto out; |
330 | 330 | ||
331 | int_urb = usb_alloc_urb(0, GFP_ATOMIC); | 331 | int_urb = usb_alloc_urb(0, GFP_ATOMIC); |
332 | if (!int_urb) | 332 | if (!int_urb) |
333 | goto out; | 333 | goto out; |
334 | 334 | ||
335 | data_urb = usb_alloc_urb(0, GFP_ATOMIC); | 335 | data_urb = usb_alloc_urb(0, GFP_ATOMIC); |
336 | if (!data_urb) | 336 | if (!data_urb) |
337 | goto out; | 337 | goto out; |
338 | 338 | ||
339 | reg->port = cpu_to_le16(NET2280_DEV_U32); | 339 | reg->port = cpu_to_le16(NET2280_DEV_U32); |
340 | reg->addr = cpu_to_le32(P54U_DEV_BASE); | 340 | reg->addr = cpu_to_le32(P54U_DEV_BASE); |
341 | reg->val = cpu_to_le32(ISL38XX_DEV_INT_DATA); | 341 | reg->val = cpu_to_le32(ISL38XX_DEV_INT_DATA); |
342 | 342 | ||
343 | memset(hdr, 0, sizeof(*hdr)); | 343 | memset(hdr, 0, sizeof(*hdr)); |
344 | hdr->len = cpu_to_le16(skb->len); | 344 | hdr->len = cpu_to_le16(skb->len); |
345 | hdr->device_addr = ((struct p54_hdr *) skb->data)->req_id; | 345 | hdr->device_addr = ((struct p54_hdr *) skb->data)->req_id; |
346 | 346 | ||
347 | usb_fill_bulk_urb(int_urb, priv->udev, | 347 | usb_fill_bulk_urb(int_urb, priv->udev, |
348 | usb_sndbulkpipe(priv->udev, P54U_PIPE_DEV), reg, sizeof(*reg), | 348 | usb_sndbulkpipe(priv->udev, P54U_PIPE_DEV), reg, sizeof(*reg), |
349 | p54u_tx_dummy_cb, dev); | 349 | p54u_tx_dummy_cb, dev); |
350 | 350 | ||
351 | /* | 351 | /* |
352 | * URB_FREE_BUFFER triggers a code path in the USB subsystem that will | 352 | * URB_FREE_BUFFER triggers a code path in the USB subsystem that will |
353 | * free what is inside the transfer_buffer after the last reference to | 353 | * free what is inside the transfer_buffer after the last reference to |
354 | * the int_urb is dropped. | 354 | * the int_urb is dropped. |
355 | */ | 355 | */ |
356 | int_urb->transfer_flags |= URB_FREE_BUFFER | URB_ZERO_PACKET; | 356 | int_urb->transfer_flags |= URB_FREE_BUFFER | URB_ZERO_PACKET; |
357 | reg = NULL; | 357 | reg = NULL; |
358 | 358 | ||
359 | usb_fill_bulk_urb(data_urb, priv->udev, | 359 | usb_fill_bulk_urb(data_urb, priv->udev, |
360 | usb_sndbulkpipe(priv->udev, P54U_PIPE_DATA), | 360 | usb_sndbulkpipe(priv->udev, P54U_PIPE_DATA), |
361 | hdr, skb->len + sizeof(*hdr), FREE_AFTER_TX(skb) ? | 361 | hdr, skb->len + sizeof(*hdr), FREE_AFTER_TX(skb) ? |
362 | p54u_tx_cb : p54u_tx_dummy_cb, skb); | 362 | p54u_tx_cb : p54u_tx_dummy_cb, skb); |
363 | data_urb->transfer_flags |= URB_ZERO_PACKET; | 363 | data_urb->transfer_flags |= URB_ZERO_PACKET; |
364 | 364 | ||
365 | usb_anchor_urb(int_urb, &priv->submitted); | 365 | usb_anchor_urb(int_urb, &priv->submitted); |
366 | err = usb_submit_urb(int_urb, GFP_ATOMIC); | 366 | err = usb_submit_urb(int_urb, GFP_ATOMIC); |
367 | if (err) { | 367 | if (err) { |
368 | usb_unanchor_urb(int_urb); | 368 | usb_unanchor_urb(int_urb); |
369 | goto out; | 369 | goto out; |
370 | } | 370 | } |
371 | 371 | ||
372 | usb_anchor_urb(data_urb, &priv->submitted); | 372 | usb_anchor_urb(data_urb, &priv->submitted); |
373 | err = usb_submit_urb(data_urb, GFP_ATOMIC); | 373 | err = usb_submit_urb(data_urb, GFP_ATOMIC); |
374 | if (err) { | 374 | if (err) { |
375 | usb_unanchor_urb(data_urb); | 375 | usb_unanchor_urb(data_urb); |
376 | goto out; | 376 | goto out; |
377 | } | 377 | } |
378 | out: | 378 | out: |
379 | usb_free_urb(int_urb); | 379 | usb_free_urb(int_urb); |
380 | usb_free_urb(data_urb); | 380 | usb_free_urb(data_urb); |
381 | 381 | ||
382 | if (err) { | 382 | if (err) { |
383 | kfree(reg); | 383 | kfree(reg); |
384 | p54_free_skb(dev, skb); | 384 | p54_free_skb(dev, skb); |
385 | } | 385 | } |
386 | } | 386 | } |
387 | 387 | ||
388 | static int p54u_write(struct p54u_priv *priv, | 388 | static int p54u_write(struct p54u_priv *priv, |
389 | struct net2280_reg_write *buf, | 389 | struct net2280_reg_write *buf, |
390 | enum net2280_op_type type, | 390 | enum net2280_op_type type, |
391 | __le32 addr, __le32 val) | 391 | __le32 addr, __le32 val) |
392 | { | 392 | { |
393 | unsigned int ep; | 393 | unsigned int ep; |
394 | int alen; | 394 | int alen; |
395 | 395 | ||
396 | if (type & 0x0800) | 396 | if (type & 0x0800) |
397 | ep = usb_sndbulkpipe(priv->udev, P54U_PIPE_DEV); | 397 | ep = usb_sndbulkpipe(priv->udev, P54U_PIPE_DEV); |
398 | else | 398 | else |
399 | ep = usb_sndbulkpipe(priv->udev, P54U_PIPE_BRG); | 399 | ep = usb_sndbulkpipe(priv->udev, P54U_PIPE_BRG); |
400 | 400 | ||
401 | buf->port = cpu_to_le16(type); | 401 | buf->port = cpu_to_le16(type); |
402 | buf->addr = addr; | 402 | buf->addr = addr; |
403 | buf->val = val; | 403 | buf->val = val; |
404 | 404 | ||
405 | return usb_bulk_msg(priv->udev, ep, buf, sizeof(*buf), &alen, 1000); | 405 | return usb_bulk_msg(priv->udev, ep, buf, sizeof(*buf), &alen, 1000); |
406 | } | 406 | } |
407 | 407 | ||
408 | static int p54u_read(struct p54u_priv *priv, void *buf, | 408 | static int p54u_read(struct p54u_priv *priv, void *buf, |
409 | enum net2280_op_type type, | 409 | enum net2280_op_type type, |
410 | __le32 addr, __le32 *val) | 410 | __le32 addr, __le32 *val) |
411 | { | 411 | { |
412 | struct net2280_reg_read *read = buf; | 412 | struct net2280_reg_read *read = buf; |
413 | __le32 *reg = buf; | 413 | __le32 *reg = buf; |
414 | unsigned int ep; | 414 | unsigned int ep; |
415 | int alen, err; | 415 | int alen, err; |
416 | 416 | ||
417 | if (type & 0x0800) | 417 | if (type & 0x0800) |
418 | ep = P54U_PIPE_DEV; | 418 | ep = P54U_PIPE_DEV; |
419 | else | 419 | else |
420 | ep = P54U_PIPE_BRG; | 420 | ep = P54U_PIPE_BRG; |
421 | 421 | ||
422 | read->port = cpu_to_le16(type); | 422 | read->port = cpu_to_le16(type); |
423 | read->addr = addr; | 423 | read->addr = addr; |
424 | 424 | ||
425 | err = usb_bulk_msg(priv->udev, usb_sndbulkpipe(priv->udev, ep), | 425 | err = usb_bulk_msg(priv->udev, usb_sndbulkpipe(priv->udev, ep), |
426 | read, sizeof(*read), &alen, 1000); | 426 | read, sizeof(*read), &alen, 1000); |
427 | if (err) | 427 | if (err) |
428 | return err; | 428 | return err; |
429 | 429 | ||
430 | err = usb_bulk_msg(priv->udev, usb_rcvbulkpipe(priv->udev, ep), | 430 | err = usb_bulk_msg(priv->udev, usb_rcvbulkpipe(priv->udev, ep), |
431 | reg, sizeof(*reg), &alen, 1000); | 431 | reg, sizeof(*reg), &alen, 1000); |
432 | if (err) | 432 | if (err) |
433 | return err; | 433 | return err; |
434 | 434 | ||
435 | *val = *reg; | 435 | *val = *reg; |
436 | return 0; | 436 | return 0; |
437 | } | 437 | } |
438 | 438 | ||
439 | static int p54u_bulk_msg(struct p54u_priv *priv, unsigned int ep, | 439 | static int p54u_bulk_msg(struct p54u_priv *priv, unsigned int ep, |
440 | void *data, size_t len) | 440 | void *data, size_t len) |
441 | { | 441 | { |
442 | int alen; | 442 | int alen; |
443 | return usb_bulk_msg(priv->udev, usb_sndbulkpipe(priv->udev, ep), | 443 | return usb_bulk_msg(priv->udev, usb_sndbulkpipe(priv->udev, ep), |
444 | data, len, &alen, 2000); | 444 | data, len, &alen, 2000); |
445 | } | 445 | } |
446 | 446 | ||
447 | static int p54u_device_reset(struct ieee80211_hw *dev) | 447 | static int p54u_device_reset(struct ieee80211_hw *dev) |
448 | { | 448 | { |
449 | struct p54u_priv *priv = dev->priv; | 449 | struct p54u_priv *priv = dev->priv; |
450 | int ret, lock = (priv->intf->condition != USB_INTERFACE_BINDING); | 450 | int ret, lock = (priv->intf->condition != USB_INTERFACE_BINDING); |
451 | 451 | ||
452 | if (lock) { | 452 | if (lock) { |
453 | ret = usb_lock_device_for_reset(priv->udev, priv->intf); | 453 | ret = usb_lock_device_for_reset(priv->udev, priv->intf); |
454 | if (ret < 0) { | 454 | if (ret < 0) { |
455 | dev_err(&priv->udev->dev, "(p54usb) unable to lock " | 455 | dev_err(&priv->udev->dev, "(p54usb) unable to lock " |
456 | "device for reset (%d)!\n", ret); | 456 | "device for reset (%d)!\n", ret); |
457 | return ret; | 457 | return ret; |
458 | } | 458 | } |
459 | } | 459 | } |
460 | 460 | ||
461 | ret = usb_reset_device(priv->udev); | 461 | ret = usb_reset_device(priv->udev); |
462 | if (lock) | 462 | if (lock) |
463 | usb_unlock_device(priv->udev); | 463 | usb_unlock_device(priv->udev); |
464 | 464 | ||
465 | if (ret) | 465 | if (ret) |
466 | dev_err(&priv->udev->dev, "(p54usb) unable to reset " | 466 | dev_err(&priv->udev->dev, "(p54usb) unable to reset " |
467 | "device (%d)!\n", ret); | 467 | "device (%d)!\n", ret); |
468 | 468 | ||
469 | return ret; | 469 | return ret; |
470 | } | 470 | } |
471 | 471 | ||
472 | static const char p54u_romboot_3887[] = "~~~~"; | 472 | static const char p54u_romboot_3887[] = "~~~~"; |
473 | static int p54u_firmware_reset_3887(struct ieee80211_hw *dev) | 473 | static int p54u_firmware_reset_3887(struct ieee80211_hw *dev) |
474 | { | 474 | { |
475 | struct p54u_priv *priv = dev->priv; | 475 | struct p54u_priv *priv = dev->priv; |
476 | u8 *buf; | 476 | u8 *buf; |
477 | int ret; | 477 | int ret; |
478 | 478 | ||
479 | buf = kmemdup(p54u_romboot_3887, 4, GFP_KERNEL); | 479 | buf = kmemdup(p54u_romboot_3887, 4, GFP_KERNEL); |
480 | if (!buf) | 480 | if (!buf) |
481 | return -ENOMEM; | 481 | return -ENOMEM; |
482 | ret = p54u_bulk_msg(priv, P54U_PIPE_DATA, | 482 | ret = p54u_bulk_msg(priv, P54U_PIPE_DATA, |
483 | buf, 4); | 483 | buf, 4); |
484 | kfree(buf); | 484 | kfree(buf); |
485 | if (ret) | 485 | if (ret) |
486 | dev_err(&priv->udev->dev, "(p54usb) unable to jump to " | 486 | dev_err(&priv->udev->dev, "(p54usb) unable to jump to " |
487 | "boot ROM (%d)!\n", ret); | 487 | "boot ROM (%d)!\n", ret); |
488 | 488 | ||
489 | return ret; | 489 | return ret; |
490 | } | 490 | } |
491 | 491 | ||
492 | static const char p54u_firmware_upload_3887[] = "<\r"; | 492 | static const char p54u_firmware_upload_3887[] = "<\r"; |
493 | static int p54u_upload_firmware_3887(struct ieee80211_hw *dev) | 493 | static int p54u_upload_firmware_3887(struct ieee80211_hw *dev) |
494 | { | 494 | { |
495 | struct p54u_priv *priv = dev->priv; | 495 | struct p54u_priv *priv = dev->priv; |
496 | int err, alen; | 496 | int err, alen; |
497 | u8 carry = 0; | 497 | u8 carry = 0; |
498 | u8 *buf, *tmp; | 498 | u8 *buf, *tmp; |
499 | const u8 *data; | 499 | const u8 *data; |
500 | unsigned int left, remains, block_size; | 500 | unsigned int left, remains, block_size; |
501 | struct x2_header *hdr; | 501 | struct x2_header *hdr; |
502 | unsigned long timeout; | 502 | unsigned long timeout; |
503 | 503 | ||
504 | err = p54u_firmware_reset_3887(dev); | 504 | err = p54u_firmware_reset_3887(dev); |
505 | if (err) | 505 | if (err) |
506 | return err; | 506 | return err; |
507 | 507 | ||
508 | tmp = buf = kmalloc(P54U_FW_BLOCK, GFP_KERNEL); | 508 | tmp = buf = kmalloc(P54U_FW_BLOCK, GFP_KERNEL); |
509 | if (!buf) { | 509 | if (!buf) { |
510 | dev_err(&priv->udev->dev, "(p54usb) cannot allocate firmware" | 510 | dev_err(&priv->udev->dev, "(p54usb) cannot allocate firmware" |
511 | "upload buffer!\n"); | 511 | "upload buffer!\n"); |
512 | return -ENOMEM; | 512 | return -ENOMEM; |
513 | } | 513 | } |
514 | 514 | ||
515 | left = block_size = min((size_t)P54U_FW_BLOCK, priv->fw->size); | 515 | left = block_size = min((size_t)P54U_FW_BLOCK, priv->fw->size); |
516 | strcpy(buf, p54u_firmware_upload_3887); | 516 | strcpy(buf, p54u_firmware_upload_3887); |
517 | left -= strlen(p54u_firmware_upload_3887); | 517 | left -= strlen(p54u_firmware_upload_3887); |
518 | tmp += strlen(p54u_firmware_upload_3887); | 518 | tmp += strlen(p54u_firmware_upload_3887); |
519 | 519 | ||
520 | data = priv->fw->data; | 520 | data = priv->fw->data; |
521 | remains = priv->fw->size; | 521 | remains = priv->fw->size; |
522 | 522 | ||
523 | hdr = (struct x2_header *)(buf + strlen(p54u_firmware_upload_3887)); | 523 | hdr = (struct x2_header *)(buf + strlen(p54u_firmware_upload_3887)); |
524 | memcpy(hdr->signature, X2_SIGNATURE, X2_SIGNATURE_SIZE); | 524 | memcpy(hdr->signature, X2_SIGNATURE, X2_SIGNATURE_SIZE); |
525 | hdr->fw_load_addr = cpu_to_le32(ISL38XX_DEV_FIRMWARE_ADDR); | 525 | hdr->fw_load_addr = cpu_to_le32(ISL38XX_DEV_FIRMWARE_ADDR); |
526 | hdr->fw_length = cpu_to_le32(priv->fw->size); | 526 | hdr->fw_length = cpu_to_le32(priv->fw->size); |
527 | hdr->crc = cpu_to_le32(~crc32_le(~0, (void *)&hdr->fw_load_addr, | 527 | hdr->crc = cpu_to_le32(~crc32_le(~0, (void *)&hdr->fw_load_addr, |
528 | sizeof(u32)*2)); | 528 | sizeof(u32)*2)); |
529 | left -= sizeof(*hdr); | 529 | left -= sizeof(*hdr); |
530 | tmp += sizeof(*hdr); | 530 | tmp += sizeof(*hdr); |
531 | 531 | ||
532 | while (remains) { | 532 | while (remains) { |
533 | while (left--) { | 533 | while (left--) { |
534 | if (carry) { | 534 | if (carry) { |
535 | *tmp++ = carry; | 535 | *tmp++ = carry; |
536 | carry = 0; | 536 | carry = 0; |
537 | remains--; | 537 | remains--; |
538 | continue; | 538 | continue; |
539 | } | 539 | } |
540 | switch (*data) { | 540 | switch (*data) { |
541 | case '~': | 541 | case '~': |
542 | *tmp++ = '}'; | 542 | *tmp++ = '}'; |
543 | carry = '^'; | 543 | carry = '^'; |
544 | break; | 544 | break; |
545 | case '}': | 545 | case '}': |
546 | *tmp++ = '}'; | 546 | *tmp++ = '}'; |
547 | carry = ']'; | 547 | carry = ']'; |
548 | break; | 548 | break; |
549 | default: | 549 | default: |
550 | *tmp++ = *data; | 550 | *tmp++ = *data; |
551 | remains--; | 551 | remains--; |
552 | break; | 552 | break; |
553 | } | 553 | } |
554 | data++; | 554 | data++; |
555 | } | 555 | } |
556 | 556 | ||
557 | err = p54u_bulk_msg(priv, P54U_PIPE_DATA, buf, block_size); | 557 | err = p54u_bulk_msg(priv, P54U_PIPE_DATA, buf, block_size); |
558 | if (err) { | 558 | if (err) { |
559 | dev_err(&priv->udev->dev, "(p54usb) firmware " | 559 | dev_err(&priv->udev->dev, "(p54usb) firmware " |
560 | "upload failed!\n"); | 560 | "upload failed!\n"); |
561 | goto err_upload_failed; | 561 | goto err_upload_failed; |
562 | } | 562 | } |
563 | 563 | ||
564 | tmp = buf; | 564 | tmp = buf; |
565 | left = block_size = min((unsigned int)P54U_FW_BLOCK, remains); | 565 | left = block_size = min((unsigned int)P54U_FW_BLOCK, remains); |
566 | } | 566 | } |
567 | 567 | ||
568 | *((__le32 *)buf) = cpu_to_le32(~crc32_le(~0, priv->fw->data, | 568 | *((__le32 *)buf) = cpu_to_le32(~crc32_le(~0, priv->fw->data, |
569 | priv->fw->size)); | 569 | priv->fw->size)); |
570 | err = p54u_bulk_msg(priv, P54U_PIPE_DATA, buf, sizeof(u32)); | 570 | err = p54u_bulk_msg(priv, P54U_PIPE_DATA, buf, sizeof(u32)); |
571 | if (err) { | 571 | if (err) { |
572 | dev_err(&priv->udev->dev, "(p54usb) firmware upload failed!\n"); | 572 | dev_err(&priv->udev->dev, "(p54usb) firmware upload failed!\n"); |
573 | goto err_upload_failed; | 573 | goto err_upload_failed; |
574 | } | 574 | } |
575 | timeout = jiffies + msecs_to_jiffies(1000); | 575 | timeout = jiffies + msecs_to_jiffies(1000); |
576 | while (!(err = usb_bulk_msg(priv->udev, | 576 | while (!(err = usb_bulk_msg(priv->udev, |
577 | usb_rcvbulkpipe(priv->udev, P54U_PIPE_DATA), buf, 128, &alen, 1000))) { | 577 | usb_rcvbulkpipe(priv->udev, P54U_PIPE_DATA), buf, 128, &alen, 1000))) { |
578 | if (alen > 2 && !memcmp(buf, "OK", 2)) | 578 | if (alen > 2 && !memcmp(buf, "OK", 2)) |
579 | break; | 579 | break; |
580 | 580 | ||
581 | if (alen > 5 && !memcmp(buf, "ERROR", 5)) { | 581 | if (alen > 5 && !memcmp(buf, "ERROR", 5)) { |
582 | err = -EINVAL; | 582 | err = -EINVAL; |
583 | break; | 583 | break; |
584 | } | 584 | } |
585 | 585 | ||
586 | if (time_after(jiffies, timeout)) { | 586 | if (time_after(jiffies, timeout)) { |
587 | dev_err(&priv->udev->dev, "(p54usb) firmware boot " | 587 | dev_err(&priv->udev->dev, "(p54usb) firmware boot " |
588 | "timed out!\n"); | 588 | "timed out!\n"); |
589 | err = -ETIMEDOUT; | 589 | err = -ETIMEDOUT; |
590 | break; | 590 | break; |
591 | } | 591 | } |
592 | } | 592 | } |
593 | if (err) { | 593 | if (err) { |
594 | dev_err(&priv->udev->dev, "(p54usb) firmware upload failed!\n"); | 594 | dev_err(&priv->udev->dev, "(p54usb) firmware upload failed!\n"); |
595 | goto err_upload_failed; | 595 | goto err_upload_failed; |
596 | } | 596 | } |
597 | 597 | ||
598 | buf[0] = 'g'; | 598 | buf[0] = 'g'; |
599 | buf[1] = '\r'; | 599 | buf[1] = '\r'; |
600 | err = p54u_bulk_msg(priv, P54U_PIPE_DATA, buf, 2); | 600 | err = p54u_bulk_msg(priv, P54U_PIPE_DATA, buf, 2); |
601 | if (err) { | 601 | if (err) { |
602 | dev_err(&priv->udev->dev, "(p54usb) firmware boot failed!\n"); | 602 | dev_err(&priv->udev->dev, "(p54usb) firmware boot failed!\n"); |
603 | goto err_upload_failed; | 603 | goto err_upload_failed; |
604 | } | 604 | } |
605 | 605 | ||
606 | timeout = jiffies + msecs_to_jiffies(1000); | 606 | timeout = jiffies + msecs_to_jiffies(1000); |
607 | while (!(err = usb_bulk_msg(priv->udev, | 607 | while (!(err = usb_bulk_msg(priv->udev, |
608 | usb_rcvbulkpipe(priv->udev, P54U_PIPE_DATA), buf, 128, &alen, 1000))) { | 608 | usb_rcvbulkpipe(priv->udev, P54U_PIPE_DATA), buf, 128, &alen, 1000))) { |
609 | if (alen > 0 && buf[0] == 'g') | 609 | if (alen > 0 && buf[0] == 'g') |
610 | break; | 610 | break; |
611 | 611 | ||
612 | if (time_after(jiffies, timeout)) { | 612 | if (time_after(jiffies, timeout)) { |
613 | err = -ETIMEDOUT; | 613 | err = -ETIMEDOUT; |
614 | break; | 614 | break; |
615 | } | 615 | } |
616 | } | 616 | } |
617 | if (err) | 617 | if (err) |
618 | goto err_upload_failed; | 618 | goto err_upload_failed; |
619 | 619 | ||
620 | err_upload_failed: | 620 | err_upload_failed: |
621 | kfree(buf); | 621 | kfree(buf); |
622 | return err; | 622 | return err; |
623 | } | 623 | } |
624 | 624 | ||
625 | static int p54u_upload_firmware_net2280(struct ieee80211_hw *dev) | 625 | static int p54u_upload_firmware_net2280(struct ieee80211_hw *dev) |
626 | { | 626 | { |
627 | struct p54u_priv *priv = dev->priv; | 627 | struct p54u_priv *priv = dev->priv; |
628 | const struct p54p_csr *devreg = (const struct p54p_csr *) P54U_DEV_BASE; | 628 | const struct p54p_csr *devreg = (const struct p54p_csr *) P54U_DEV_BASE; |
629 | int err, alen; | 629 | int err, alen; |
630 | void *buf; | 630 | void *buf; |
631 | __le32 reg; | 631 | __le32 reg; |
632 | unsigned int remains, offset; | 632 | unsigned int remains, offset; |
633 | const u8 *data; | 633 | const u8 *data; |
634 | 634 | ||
635 | buf = kmalloc(512, GFP_KERNEL); | 635 | buf = kmalloc(512, GFP_KERNEL); |
636 | if (!buf) { | 636 | if (!buf) { |
637 | dev_err(&priv->udev->dev, "(p54usb) firmware buffer " | 637 | dev_err(&priv->udev->dev, "(p54usb) firmware buffer " |
638 | "alloc failed!\n"); | 638 | "alloc failed!\n"); |
639 | return -ENOMEM; | 639 | return -ENOMEM; |
640 | } | 640 | } |
641 | 641 | ||
642 | #define P54U_WRITE(type, addr, data) \ | 642 | #define P54U_WRITE(type, addr, data) \ |
643 | do {\ | 643 | do {\ |
644 | err = p54u_write(priv, buf, type,\ | 644 | err = p54u_write(priv, buf, type,\ |
645 | cpu_to_le32((u32)(unsigned long)addr), data);\ | 645 | cpu_to_le32((u32)(unsigned long)addr), data);\ |
646 | if (err) \ | 646 | if (err) \ |
647 | goto fail;\ | 647 | goto fail;\ |
648 | } while (0) | 648 | } while (0) |
649 | 649 | ||
650 | #define P54U_READ(type, addr) \ | 650 | #define P54U_READ(type, addr) \ |
651 | do {\ | 651 | do {\ |
652 | err = p54u_read(priv, buf, type,\ | 652 | err = p54u_read(priv, buf, type,\ |
653 | cpu_to_le32((u32)(unsigned long)addr), ®);\ | 653 | cpu_to_le32((u32)(unsigned long)addr), ®);\ |
654 | if (err)\ | 654 | if (err)\ |
655 | goto fail;\ | 655 | goto fail;\ |
656 | } while (0) | 656 | } while (0) |
657 | 657 | ||
658 | /* power down net2280 bridge */ | 658 | /* power down net2280 bridge */ |
659 | P54U_READ(NET2280_BRG_U32, NET2280_GPIOCTL); | 659 | P54U_READ(NET2280_BRG_U32, NET2280_GPIOCTL); |
660 | reg |= cpu_to_le32(P54U_BRG_POWER_DOWN); | 660 | reg |= cpu_to_le32(P54U_BRG_POWER_DOWN); |
661 | reg &= cpu_to_le32(~P54U_BRG_POWER_UP); | 661 | reg &= cpu_to_le32(~P54U_BRG_POWER_UP); |
662 | P54U_WRITE(NET2280_BRG_U32, NET2280_GPIOCTL, reg); | 662 | P54U_WRITE(NET2280_BRG_U32, NET2280_GPIOCTL, reg); |
663 | 663 | ||
664 | mdelay(100); | 664 | mdelay(100); |
665 | 665 | ||
666 | /* power up bridge */ | 666 | /* power up bridge */ |
667 | reg |= cpu_to_le32(P54U_BRG_POWER_UP); | 667 | reg |= cpu_to_le32(P54U_BRG_POWER_UP); |
668 | reg &= cpu_to_le32(~P54U_BRG_POWER_DOWN); | 668 | reg &= cpu_to_le32(~P54U_BRG_POWER_DOWN); |
669 | P54U_WRITE(NET2280_BRG_U32, NET2280_GPIOCTL, reg); | 669 | P54U_WRITE(NET2280_BRG_U32, NET2280_GPIOCTL, reg); |
670 | 670 | ||
671 | mdelay(100); | 671 | mdelay(100); |
672 | 672 | ||
673 | P54U_WRITE(NET2280_BRG_U32, NET2280_DEVINIT, | 673 | P54U_WRITE(NET2280_BRG_U32, NET2280_DEVINIT, |
674 | cpu_to_le32(NET2280_CLK_30Mhz | | 674 | cpu_to_le32(NET2280_CLK_30Mhz | |
675 | NET2280_PCI_ENABLE | | 675 | NET2280_PCI_ENABLE | |
676 | NET2280_PCI_SOFT_RESET)); | 676 | NET2280_PCI_SOFT_RESET)); |
677 | 677 | ||
678 | mdelay(20); | 678 | mdelay(20); |
679 | 679 | ||
680 | P54U_WRITE(NET2280_BRG_CFG_U16, PCI_COMMAND, | 680 | P54U_WRITE(NET2280_BRG_CFG_U16, PCI_COMMAND, |
681 | cpu_to_le32(PCI_COMMAND_MEMORY | | 681 | cpu_to_le32(PCI_COMMAND_MEMORY | |
682 | PCI_COMMAND_MASTER)); | 682 | PCI_COMMAND_MASTER)); |
683 | 683 | ||
684 | P54U_WRITE(NET2280_BRG_CFG_U32, PCI_BASE_ADDRESS_0, | 684 | P54U_WRITE(NET2280_BRG_CFG_U32, PCI_BASE_ADDRESS_0, |
685 | cpu_to_le32(NET2280_BASE)); | 685 | cpu_to_le32(NET2280_BASE)); |
686 | 686 | ||
687 | P54U_READ(NET2280_BRG_CFG_U16, PCI_STATUS); | 687 | P54U_READ(NET2280_BRG_CFG_U16, PCI_STATUS); |
688 | reg |= cpu_to_le32(PCI_STATUS_REC_MASTER_ABORT); | 688 | reg |= cpu_to_le32(PCI_STATUS_REC_MASTER_ABORT); |
689 | P54U_WRITE(NET2280_BRG_CFG_U16, PCI_STATUS, reg); | 689 | P54U_WRITE(NET2280_BRG_CFG_U16, PCI_STATUS, reg); |
690 | 690 | ||
691 | // TODO: we really need this? | 691 | // TODO: we really need this? |
692 | P54U_READ(NET2280_BRG_U32, NET2280_RELNUM); | 692 | P54U_READ(NET2280_BRG_U32, NET2280_RELNUM); |
693 | 693 | ||
694 | P54U_WRITE(NET2280_BRG_U32, NET2280_EPA_RSP, | 694 | P54U_WRITE(NET2280_BRG_U32, NET2280_EPA_RSP, |
695 | cpu_to_le32(NET2280_CLEAR_NAK_OUT_PACKETS_MODE)); | 695 | cpu_to_le32(NET2280_CLEAR_NAK_OUT_PACKETS_MODE)); |
696 | P54U_WRITE(NET2280_BRG_U32, NET2280_EPC_RSP, | 696 | P54U_WRITE(NET2280_BRG_U32, NET2280_EPC_RSP, |
697 | cpu_to_le32(NET2280_CLEAR_NAK_OUT_PACKETS_MODE)); | 697 | cpu_to_le32(NET2280_CLEAR_NAK_OUT_PACKETS_MODE)); |
698 | 698 | ||
699 | P54U_WRITE(NET2280_BRG_CFG_U32, PCI_BASE_ADDRESS_2, | 699 | P54U_WRITE(NET2280_BRG_CFG_U32, PCI_BASE_ADDRESS_2, |
700 | cpu_to_le32(NET2280_BASE2)); | 700 | cpu_to_le32(NET2280_BASE2)); |
701 | 701 | ||
702 | /* finally done setting up the bridge */ | 702 | /* finally done setting up the bridge */ |
703 | 703 | ||
704 | P54U_WRITE(NET2280_DEV_CFG_U16, 0x10000 | PCI_COMMAND, | 704 | P54U_WRITE(NET2280_DEV_CFG_U16, 0x10000 | PCI_COMMAND, |
705 | cpu_to_le32(PCI_COMMAND_MEMORY | | 705 | cpu_to_le32(PCI_COMMAND_MEMORY | |
706 | PCI_COMMAND_MASTER)); | 706 | PCI_COMMAND_MASTER)); |
707 | 707 | ||
708 | P54U_WRITE(NET2280_DEV_CFG_U16, 0x10000 | 0x40 /* TRDY timeout */, 0); | 708 | P54U_WRITE(NET2280_DEV_CFG_U16, 0x10000 | 0x40 /* TRDY timeout */, 0); |
709 | P54U_WRITE(NET2280_DEV_CFG_U32, 0x10000 | PCI_BASE_ADDRESS_0, | 709 | P54U_WRITE(NET2280_DEV_CFG_U32, 0x10000 | PCI_BASE_ADDRESS_0, |
710 | cpu_to_le32(P54U_DEV_BASE)); | 710 | cpu_to_le32(P54U_DEV_BASE)); |
711 | 711 | ||
712 | P54U_WRITE(NET2280_BRG_U32, NET2280_USBIRQENB1, 0); | 712 | P54U_WRITE(NET2280_BRG_U32, NET2280_USBIRQENB1, 0); |
713 | P54U_WRITE(NET2280_BRG_U32, NET2280_IRQSTAT1, | 713 | P54U_WRITE(NET2280_BRG_U32, NET2280_IRQSTAT1, |
714 | cpu_to_le32(NET2280_PCI_INTA_INTERRUPT)); | 714 | cpu_to_le32(NET2280_PCI_INTA_INTERRUPT)); |
715 | 715 | ||
716 | /* do romboot */ | 716 | /* do romboot */ |
717 | P54U_WRITE(NET2280_DEV_U32, &devreg->int_enable, 0); | 717 | P54U_WRITE(NET2280_DEV_U32, &devreg->int_enable, 0); |
718 | 718 | ||
719 | P54U_READ(NET2280_DEV_U32, &devreg->ctrl_stat); | 719 | P54U_READ(NET2280_DEV_U32, &devreg->ctrl_stat); |
720 | reg &= cpu_to_le32(~ISL38XX_CTRL_STAT_RESET); | 720 | reg &= cpu_to_le32(~ISL38XX_CTRL_STAT_RESET); |
721 | reg &= cpu_to_le32(~ISL38XX_CTRL_STAT_RAMBOOT); | 721 | reg &= cpu_to_le32(~ISL38XX_CTRL_STAT_RAMBOOT); |
722 | reg &= cpu_to_le32(~ISL38XX_CTRL_STAT_CLKRUN); | 722 | reg &= cpu_to_le32(~ISL38XX_CTRL_STAT_CLKRUN); |
723 | P54U_WRITE(NET2280_DEV_U32, &devreg->ctrl_stat, reg); | 723 | P54U_WRITE(NET2280_DEV_U32, &devreg->ctrl_stat, reg); |
724 | 724 | ||
725 | mdelay(20); | 725 | mdelay(20); |
726 | 726 | ||
727 | reg |= cpu_to_le32(ISL38XX_CTRL_STAT_RESET); | 727 | reg |= cpu_to_le32(ISL38XX_CTRL_STAT_RESET); |
728 | P54U_WRITE(NET2280_DEV_U32, &devreg->ctrl_stat, reg); | 728 | P54U_WRITE(NET2280_DEV_U32, &devreg->ctrl_stat, reg); |
729 | 729 | ||
730 | mdelay(20); | 730 | mdelay(20); |
731 | 731 | ||
732 | reg &= cpu_to_le32(~ISL38XX_CTRL_STAT_RESET); | 732 | reg &= cpu_to_le32(~ISL38XX_CTRL_STAT_RESET); |
733 | P54U_WRITE(NET2280_DEV_U32, &devreg->ctrl_stat, reg); | 733 | P54U_WRITE(NET2280_DEV_U32, &devreg->ctrl_stat, reg); |
734 | 734 | ||
735 | mdelay(100); | 735 | mdelay(100); |
736 | 736 | ||
737 | P54U_READ(NET2280_DEV_U32, &devreg->int_ident); | 737 | P54U_READ(NET2280_DEV_U32, &devreg->int_ident); |
738 | P54U_WRITE(NET2280_DEV_U32, &devreg->int_ack, reg); | 738 | P54U_WRITE(NET2280_DEV_U32, &devreg->int_ack, reg); |
739 | 739 | ||
740 | /* finally, we can upload firmware now! */ | 740 | /* finally, we can upload firmware now! */ |
741 | remains = priv->fw->size; | 741 | remains = priv->fw->size; |
742 | data = priv->fw->data; | 742 | data = priv->fw->data; |
743 | offset = ISL38XX_DEV_FIRMWARE_ADDR; | 743 | offset = ISL38XX_DEV_FIRMWARE_ADDR; |
744 | 744 | ||
745 | while (remains) { | 745 | while (remains) { |
746 | unsigned int block_len = min(remains, (unsigned int)512); | 746 | unsigned int block_len = min(remains, (unsigned int)512); |
747 | memcpy(buf, data, block_len); | 747 | memcpy(buf, data, block_len); |
748 | 748 | ||
749 | err = p54u_bulk_msg(priv, P54U_PIPE_DATA, buf, block_len); | 749 | err = p54u_bulk_msg(priv, P54U_PIPE_DATA, buf, block_len); |
750 | if (err) { | 750 | if (err) { |
751 | dev_err(&priv->udev->dev, "(p54usb) firmware block " | 751 | dev_err(&priv->udev->dev, "(p54usb) firmware block " |
752 | "upload failed\n"); | 752 | "upload failed\n"); |
753 | goto fail; | 753 | goto fail; |
754 | } | 754 | } |
755 | 755 | ||
756 | P54U_WRITE(NET2280_DEV_U32, &devreg->direct_mem_base, | 756 | P54U_WRITE(NET2280_DEV_U32, &devreg->direct_mem_base, |
757 | cpu_to_le32(0xc0000f00)); | 757 | cpu_to_le32(0xc0000f00)); |
758 | 758 | ||
759 | P54U_WRITE(NET2280_DEV_U32, | 759 | P54U_WRITE(NET2280_DEV_U32, |
760 | 0x0020 | (unsigned long)&devreg->direct_mem_win, 0); | 760 | 0x0020 | (unsigned long)&devreg->direct_mem_win, 0); |
761 | P54U_WRITE(NET2280_DEV_U32, | 761 | P54U_WRITE(NET2280_DEV_U32, |
762 | 0x0020 | (unsigned long)&devreg->direct_mem_win, | 762 | 0x0020 | (unsigned long)&devreg->direct_mem_win, |
763 | cpu_to_le32(1)); | 763 | cpu_to_le32(1)); |
764 | 764 | ||
765 | P54U_WRITE(NET2280_DEV_U32, | 765 | P54U_WRITE(NET2280_DEV_U32, |
766 | 0x0024 | (unsigned long)&devreg->direct_mem_win, | 766 | 0x0024 | (unsigned long)&devreg->direct_mem_win, |
767 | cpu_to_le32(block_len)); | 767 | cpu_to_le32(block_len)); |
768 | P54U_WRITE(NET2280_DEV_U32, | 768 | P54U_WRITE(NET2280_DEV_U32, |
769 | 0x0028 | (unsigned long)&devreg->direct_mem_win, | 769 | 0x0028 | (unsigned long)&devreg->direct_mem_win, |
770 | cpu_to_le32(offset)); | 770 | cpu_to_le32(offset)); |
771 | 771 | ||
772 | P54U_WRITE(NET2280_DEV_U32, &devreg->dma_addr, | 772 | P54U_WRITE(NET2280_DEV_U32, &devreg->dma_addr, |
773 | cpu_to_le32(NET2280_EPA_FIFO_PCI_ADDR)); | 773 | cpu_to_le32(NET2280_EPA_FIFO_PCI_ADDR)); |
774 | P54U_WRITE(NET2280_DEV_U32, &devreg->dma_len, | 774 | P54U_WRITE(NET2280_DEV_U32, &devreg->dma_len, |
775 | cpu_to_le32(block_len >> 2)); | 775 | cpu_to_le32(block_len >> 2)); |
776 | P54U_WRITE(NET2280_DEV_U32, &devreg->dma_ctrl, | 776 | P54U_WRITE(NET2280_DEV_U32, &devreg->dma_ctrl, |
777 | cpu_to_le32(ISL38XX_DMA_MASTER_CONTROL_TRIGGER)); | 777 | cpu_to_le32(ISL38XX_DMA_MASTER_CONTROL_TRIGGER)); |
778 | 778 | ||
779 | mdelay(10); | 779 | mdelay(10); |
780 | 780 | ||
781 | P54U_READ(NET2280_DEV_U32, | 781 | P54U_READ(NET2280_DEV_U32, |
782 | 0x002C | (unsigned long)&devreg->direct_mem_win); | 782 | 0x002C | (unsigned long)&devreg->direct_mem_win); |
783 | if (!(reg & cpu_to_le32(ISL38XX_DMA_STATUS_DONE)) || | 783 | if (!(reg & cpu_to_le32(ISL38XX_DMA_STATUS_DONE)) || |
784 | !(reg & cpu_to_le32(ISL38XX_DMA_STATUS_READY))) { | 784 | !(reg & cpu_to_le32(ISL38XX_DMA_STATUS_READY))) { |
785 | dev_err(&priv->udev->dev, "(p54usb) firmware DMA " | 785 | dev_err(&priv->udev->dev, "(p54usb) firmware DMA " |
786 | "transfer failed\n"); | 786 | "transfer failed\n"); |
787 | goto fail; | 787 | goto fail; |
788 | } | 788 | } |
789 | 789 | ||
790 | P54U_WRITE(NET2280_BRG_U32, NET2280_EPA_STAT, | 790 | P54U_WRITE(NET2280_BRG_U32, NET2280_EPA_STAT, |
791 | cpu_to_le32(NET2280_FIFO_FLUSH)); | 791 | cpu_to_le32(NET2280_FIFO_FLUSH)); |
792 | 792 | ||
793 | remains -= block_len; | 793 | remains -= block_len; |
794 | data += block_len; | 794 | data += block_len; |
795 | offset += block_len; | 795 | offset += block_len; |
796 | } | 796 | } |
797 | 797 | ||
798 | /* do ramboot */ | 798 | /* do ramboot */ |
799 | P54U_READ(NET2280_DEV_U32, &devreg->ctrl_stat); | 799 | P54U_READ(NET2280_DEV_U32, &devreg->ctrl_stat); |
800 | reg &= cpu_to_le32(~ISL38XX_CTRL_STAT_RESET); | 800 | reg &= cpu_to_le32(~ISL38XX_CTRL_STAT_RESET); |
801 | reg &= cpu_to_le32(~ISL38XX_CTRL_STAT_CLKRUN); | 801 | reg &= cpu_to_le32(~ISL38XX_CTRL_STAT_CLKRUN); |
802 | reg |= cpu_to_le32(ISL38XX_CTRL_STAT_RAMBOOT); | 802 | reg |= cpu_to_le32(ISL38XX_CTRL_STAT_RAMBOOT); |
803 | P54U_WRITE(NET2280_DEV_U32, &devreg->ctrl_stat, reg); | 803 | P54U_WRITE(NET2280_DEV_U32, &devreg->ctrl_stat, reg); |
804 | 804 | ||
805 | mdelay(20); | 805 | mdelay(20); |
806 | 806 | ||
807 | reg |= cpu_to_le32(ISL38XX_CTRL_STAT_RESET); | 807 | reg |= cpu_to_le32(ISL38XX_CTRL_STAT_RESET); |
808 | P54U_WRITE(NET2280_DEV_U32, &devreg->ctrl_stat, reg); | 808 | P54U_WRITE(NET2280_DEV_U32, &devreg->ctrl_stat, reg); |
809 | 809 | ||
810 | reg &= cpu_to_le32(~ISL38XX_CTRL_STAT_RESET); | 810 | reg &= cpu_to_le32(~ISL38XX_CTRL_STAT_RESET); |
811 | P54U_WRITE(NET2280_DEV_U32, &devreg->ctrl_stat, reg); | 811 | P54U_WRITE(NET2280_DEV_U32, &devreg->ctrl_stat, reg); |
812 | 812 | ||
813 | mdelay(100); | 813 | mdelay(100); |
814 | 814 | ||
815 | P54U_READ(NET2280_DEV_U32, &devreg->int_ident); | 815 | P54U_READ(NET2280_DEV_U32, &devreg->int_ident); |
816 | P54U_WRITE(NET2280_DEV_U32, &devreg->int_ack, reg); | 816 | P54U_WRITE(NET2280_DEV_U32, &devreg->int_ack, reg); |
817 | 817 | ||
818 | /* start up the firmware */ | 818 | /* start up the firmware */ |
819 | P54U_WRITE(NET2280_DEV_U32, &devreg->int_enable, | 819 | P54U_WRITE(NET2280_DEV_U32, &devreg->int_enable, |
820 | cpu_to_le32(ISL38XX_INT_IDENT_INIT)); | 820 | cpu_to_le32(ISL38XX_INT_IDENT_INIT)); |
821 | 821 | ||
822 | P54U_WRITE(NET2280_BRG_U32, NET2280_IRQSTAT1, | 822 | P54U_WRITE(NET2280_BRG_U32, NET2280_IRQSTAT1, |
823 | cpu_to_le32(NET2280_PCI_INTA_INTERRUPT)); | 823 | cpu_to_le32(NET2280_PCI_INTA_INTERRUPT)); |
824 | 824 | ||
825 | P54U_WRITE(NET2280_BRG_U32, NET2280_USBIRQENB1, | 825 | P54U_WRITE(NET2280_BRG_U32, NET2280_USBIRQENB1, |
826 | cpu_to_le32(NET2280_PCI_INTA_INTERRUPT_ENABLE | | 826 | cpu_to_le32(NET2280_PCI_INTA_INTERRUPT_ENABLE | |
827 | NET2280_USB_INTERRUPT_ENABLE)); | 827 | NET2280_USB_INTERRUPT_ENABLE)); |
828 | 828 | ||
829 | P54U_WRITE(NET2280_DEV_U32, &devreg->dev_int, | 829 | P54U_WRITE(NET2280_DEV_U32, &devreg->dev_int, |
830 | cpu_to_le32(ISL38XX_DEV_INT_RESET)); | 830 | cpu_to_le32(ISL38XX_DEV_INT_RESET)); |
831 | 831 | ||
832 | err = usb_interrupt_msg(priv->udev, | 832 | err = usb_interrupt_msg(priv->udev, |
833 | usb_rcvbulkpipe(priv->udev, P54U_PIPE_INT), | 833 | usb_rcvbulkpipe(priv->udev, P54U_PIPE_INT), |
834 | buf, sizeof(__le32), &alen, 1000); | 834 | buf, sizeof(__le32), &alen, 1000); |
835 | if (err || alen != sizeof(__le32)) | 835 | if (err || alen != sizeof(__le32)) |
836 | goto fail; | 836 | goto fail; |
837 | 837 | ||
838 | P54U_READ(NET2280_DEV_U32, &devreg->int_ident); | 838 | P54U_READ(NET2280_DEV_U32, &devreg->int_ident); |
839 | P54U_WRITE(NET2280_DEV_U32, &devreg->int_ack, reg); | 839 | P54U_WRITE(NET2280_DEV_U32, &devreg->int_ack, reg); |
840 | 840 | ||
841 | if (!(reg & cpu_to_le32(ISL38XX_INT_IDENT_INIT))) | 841 | if (!(reg & cpu_to_le32(ISL38XX_INT_IDENT_INIT))) |
842 | err = -EINVAL; | 842 | err = -EINVAL; |
843 | 843 | ||
844 | P54U_WRITE(NET2280_BRG_U32, NET2280_USBIRQENB1, 0); | 844 | P54U_WRITE(NET2280_BRG_U32, NET2280_USBIRQENB1, 0); |
845 | P54U_WRITE(NET2280_BRG_U32, NET2280_IRQSTAT1, | 845 | P54U_WRITE(NET2280_BRG_U32, NET2280_IRQSTAT1, |
846 | cpu_to_le32(NET2280_PCI_INTA_INTERRUPT)); | 846 | cpu_to_le32(NET2280_PCI_INTA_INTERRUPT)); |
847 | 847 | ||
848 | #undef P54U_WRITE | 848 | #undef P54U_WRITE |
849 | #undef P54U_READ | 849 | #undef P54U_READ |
850 | 850 | ||
851 | fail: | 851 | fail: |
852 | kfree(buf); | 852 | kfree(buf); |
853 | return err; | 853 | return err; |
854 | } | 854 | } |
855 | 855 | ||
856 | static int p54_find_type(struct p54u_priv *priv) | 856 | static int p54_find_type(struct p54u_priv *priv) |
857 | { | 857 | { |
858 | int i; | 858 | int i; |
859 | 859 | ||
860 | for (i = 0; i < __NUM_P54U_HWTYPES; i++) | 860 | for (i = 0; i < __NUM_P54U_HWTYPES; i++) |
861 | if (p54u_fwlist[i].type == priv->hw_type) | 861 | if (p54u_fwlist[i].type == priv->hw_type) |
862 | break; | 862 | break; |
863 | if (i == __NUM_P54U_HWTYPES) | 863 | if (i == __NUM_P54U_HWTYPES) |
864 | return -EOPNOTSUPP; | 864 | return -EOPNOTSUPP; |
865 | 865 | ||
866 | return i; | 866 | return i; |
867 | } | 867 | } |
868 | 868 | ||
869 | static int p54u_start_ops(struct p54u_priv *priv) | 869 | static int p54u_start_ops(struct p54u_priv *priv) |
870 | { | 870 | { |
871 | struct ieee80211_hw *dev = priv->common.hw; | 871 | struct ieee80211_hw *dev = priv->common.hw; |
872 | int ret; | 872 | int ret; |
873 | 873 | ||
874 | ret = p54_parse_firmware(dev, priv->fw); | 874 | ret = p54_parse_firmware(dev, priv->fw); |
875 | if (ret) | 875 | if (ret) |
876 | goto err_out; | 876 | goto err_out; |
877 | 877 | ||
878 | ret = p54_find_type(priv); | 878 | ret = p54_find_type(priv); |
879 | if (ret < 0) | 879 | if (ret < 0) |
880 | goto err_out; | 880 | goto err_out; |
881 | 881 | ||
882 | if (priv->common.fw_interface != p54u_fwlist[ret].intf) { | 882 | if (priv->common.fw_interface != p54u_fwlist[ret].intf) { |
883 | dev_err(&priv->udev->dev, "wrong firmware, please get " | 883 | dev_err(&priv->udev->dev, "wrong firmware, please get " |
884 | "a firmware for \"%s\" and try again.\n", | 884 | "a firmware for \"%s\" and try again.\n", |
885 | p54u_fwlist[ret].hw); | 885 | p54u_fwlist[ret].hw); |
886 | ret = -ENODEV; | 886 | ret = -ENODEV; |
887 | goto err_out; | 887 | goto err_out; |
888 | } | 888 | } |
889 | 889 | ||
890 | ret = priv->upload_fw(dev); | 890 | ret = priv->upload_fw(dev); |
891 | if (ret) | 891 | if (ret) |
892 | goto err_out; | 892 | goto err_out; |
893 | 893 | ||
894 | ret = p54u_open(dev); | 894 | ret = p54u_open(dev); |
895 | if (ret) | 895 | if (ret) |
896 | goto err_out; | 896 | goto err_out; |
897 | 897 | ||
898 | ret = p54_read_eeprom(dev); | 898 | ret = p54_read_eeprom(dev); |
899 | if (ret) | 899 | if (ret) |
900 | goto err_stop; | 900 | goto err_stop; |
901 | 901 | ||
902 | p54u_stop(dev); | 902 | p54u_stop(dev); |
903 | 903 | ||
904 | ret = p54_register_common(dev, &priv->udev->dev); | 904 | ret = p54_register_common(dev, &priv->udev->dev); |
905 | if (ret) | 905 | if (ret) |
906 | goto err_stop; | 906 | goto err_stop; |
907 | 907 | ||
908 | return 0; | 908 | return 0; |
909 | 909 | ||
910 | err_stop: | 910 | err_stop: |
911 | p54u_stop(dev); | 911 | p54u_stop(dev); |
912 | 912 | ||
913 | err_out: | 913 | err_out: |
914 | /* | 914 | /* |
915 | * p54u_disconnect will do the rest of the | 915 | * p54u_disconnect will do the rest of the |
916 | * cleanup | 916 | * cleanup |
917 | */ | 917 | */ |
918 | return ret; | 918 | return ret; |
919 | } | 919 | } |
920 | 920 | ||
921 | static void p54u_load_firmware_cb(const struct firmware *firmware, | 921 | static void p54u_load_firmware_cb(const struct firmware *firmware, |
922 | void *context) | 922 | void *context) |
923 | { | 923 | { |
924 | struct p54u_priv *priv = context; | 924 | struct p54u_priv *priv = context; |
925 | struct usb_device *udev = priv->udev; | 925 | struct usb_device *udev = priv->udev; |
926 | int err; | 926 | int err; |
927 | 927 | ||
928 | complete(&priv->fw_wait_load); | 928 | complete(&priv->fw_wait_load); |
929 | if (firmware) { | 929 | if (firmware) { |
930 | priv->fw = firmware; | 930 | priv->fw = firmware; |
931 | err = p54u_start_ops(priv); | 931 | err = p54u_start_ops(priv); |
932 | } else { | 932 | } else { |
933 | err = -ENOENT; | 933 | err = -ENOENT; |
934 | dev_err(&udev->dev, "Firmware not found.\n"); | 934 | dev_err(&udev->dev, "Firmware not found.\n"); |
935 | } | 935 | } |
936 | 936 | ||
937 | if (err) { | 937 | if (err) { |
938 | struct device *parent = priv->udev->dev.parent; | 938 | struct device *parent = priv->udev->dev.parent; |
939 | 939 | ||
940 | dev_err(&udev->dev, "failed to initialize device (%d)\n", err); | 940 | dev_err(&udev->dev, "failed to initialize device (%d)\n", err); |
941 | 941 | ||
942 | if (parent) | 942 | if (parent) |
943 | device_lock(parent); | 943 | device_lock(parent); |
944 | 944 | ||
945 | device_release_driver(&udev->dev); | 945 | device_release_driver(&udev->dev); |
946 | /* | 946 | /* |
947 | * At this point p54u_disconnect has already freed | 947 | * At this point p54u_disconnect has already freed |
948 | * the "priv" context. Do not use it anymore! | 948 | * the "priv" context. Do not use it anymore! |
949 | */ | 949 | */ |
950 | priv = NULL; | 950 | priv = NULL; |
951 | 951 | ||
952 | if (parent) | 952 | if (parent) |
953 | device_unlock(parent); | 953 | device_unlock(parent); |
954 | } | 954 | } |
955 | 955 | ||
956 | usb_put_dev(udev); | 956 | usb_put_dev(udev); |
957 | } | 957 | } |
958 | 958 | ||
959 | static int p54u_load_firmware(struct ieee80211_hw *dev, | 959 | static int p54u_load_firmware(struct ieee80211_hw *dev, |
960 | struct usb_interface *intf) | 960 | struct usb_interface *intf) |
961 | { | 961 | { |
962 | struct usb_device *udev = interface_to_usbdev(intf); | 962 | struct usb_device *udev = interface_to_usbdev(intf); |
963 | struct p54u_priv *priv = dev->priv; | 963 | struct p54u_priv *priv = dev->priv; |
964 | struct device *device = &udev->dev; | 964 | struct device *device = &udev->dev; |
965 | int err, i; | 965 | int err, i; |
966 | 966 | ||
967 | BUILD_BUG_ON(ARRAY_SIZE(p54u_fwlist) != __NUM_P54U_HWTYPES); | 967 | BUILD_BUG_ON(ARRAY_SIZE(p54u_fwlist) != __NUM_P54U_HWTYPES); |
968 | 968 | ||
969 | init_completion(&priv->fw_wait_load); | 969 | init_completion(&priv->fw_wait_load); |
970 | i = p54_find_type(priv); | 970 | i = p54_find_type(priv); |
971 | if (i < 0) | 971 | if (i < 0) |
972 | return i; | 972 | return i; |
973 | 973 | ||
974 | dev_info(&priv->udev->dev, "Loading firmware file %s\n", | 974 | dev_info(&priv->udev->dev, "Loading firmware file %s\n", |
975 | p54u_fwlist[i].fw); | 975 | p54u_fwlist[i].fw); |
976 | 976 | ||
977 | usb_get_dev(udev); | 977 | usb_get_dev(udev); |
978 | err = request_firmware_nowait(THIS_MODULE, 1, p54u_fwlist[i].fw, | 978 | err = request_firmware_nowait(THIS_MODULE, 1, p54u_fwlist[i].fw, |
979 | device, GFP_KERNEL, priv, | 979 | device, GFP_KERNEL, priv, |
980 | p54u_load_firmware_cb); | 980 | p54u_load_firmware_cb); |
981 | if (err) { | 981 | if (err) { |
982 | dev_err(&priv->udev->dev, "(p54usb) cannot load firmware %s " | 982 | dev_err(&priv->udev->dev, "(p54usb) cannot load firmware %s " |
983 | "(%d)!\n", p54u_fwlist[i].fw, err); | 983 | "(%d)!\n", p54u_fwlist[i].fw, err); |
984 | } | 984 | } |
985 | 985 | ||
986 | return err; | 986 | return err; |
987 | } | 987 | } |
988 | 988 | ||
989 | static int __devinit p54u_probe(struct usb_interface *intf, | 989 | static int __devinit p54u_probe(struct usb_interface *intf, |
990 | const struct usb_device_id *id) | 990 | const struct usb_device_id *id) |
991 | { | 991 | { |
992 | struct usb_device *udev = interface_to_usbdev(intf); | 992 | struct usb_device *udev = interface_to_usbdev(intf); |
993 | struct ieee80211_hw *dev; | 993 | struct ieee80211_hw *dev; |
994 | struct p54u_priv *priv; | 994 | struct p54u_priv *priv; |
995 | int err; | 995 | int err; |
996 | unsigned int i, recognized_pipes; | 996 | unsigned int i, recognized_pipes; |
997 | 997 | ||
998 | dev = p54_init_common(sizeof(*priv)); | 998 | dev = p54_init_common(sizeof(*priv)); |
999 | 999 | ||
1000 | if (!dev) { | 1000 | if (!dev) { |
1001 | dev_err(&udev->dev, "(p54usb) ieee80211 alloc failed\n"); | 1001 | dev_err(&udev->dev, "(p54usb) ieee80211 alloc failed\n"); |
1002 | return -ENOMEM; | 1002 | return -ENOMEM; |
1003 | } | 1003 | } |
1004 | 1004 | ||
1005 | priv = dev->priv; | 1005 | priv = dev->priv; |
1006 | priv->hw_type = P54U_INVALID_HW; | 1006 | priv->hw_type = P54U_INVALID_HW; |
1007 | 1007 | ||
1008 | SET_IEEE80211_DEV(dev, &intf->dev); | 1008 | SET_IEEE80211_DEV(dev, &intf->dev); |
1009 | usb_set_intfdata(intf, dev); | 1009 | usb_set_intfdata(intf, dev); |
1010 | priv->udev = udev; | 1010 | priv->udev = udev; |
1011 | priv->intf = intf; | 1011 | priv->intf = intf; |
1012 | skb_queue_head_init(&priv->rx_queue); | 1012 | skb_queue_head_init(&priv->rx_queue); |
1013 | init_usb_anchor(&priv->submitted); | 1013 | init_usb_anchor(&priv->submitted); |
1014 | 1014 | ||
1015 | usb_get_dev(udev); | 1015 | usb_get_dev(udev); |
1016 | 1016 | ||
1017 | /* really lazy and simple way of figuring out if we're a 3887 */ | 1017 | /* really lazy and simple way of figuring out if we're a 3887 */ |
1018 | /* TODO: should just stick the identification in the device table */ | 1018 | /* TODO: should just stick the identification in the device table */ |
1019 | i = intf->altsetting->desc.bNumEndpoints; | 1019 | i = intf->altsetting->desc.bNumEndpoints; |
1020 | recognized_pipes = 0; | 1020 | recognized_pipes = 0; |
1021 | while (i--) { | 1021 | while (i--) { |
1022 | switch (intf->altsetting->endpoint[i].desc.bEndpointAddress) { | 1022 | switch (intf->altsetting->endpoint[i].desc.bEndpointAddress) { |
1023 | case P54U_PIPE_DATA: | 1023 | case P54U_PIPE_DATA: |
1024 | case P54U_PIPE_MGMT: | 1024 | case P54U_PIPE_MGMT: |
1025 | case P54U_PIPE_BRG: | 1025 | case P54U_PIPE_BRG: |
1026 | case P54U_PIPE_DEV: | 1026 | case P54U_PIPE_DEV: |
1027 | case P54U_PIPE_DATA | USB_DIR_IN: | 1027 | case P54U_PIPE_DATA | USB_DIR_IN: |
1028 | case P54U_PIPE_MGMT | USB_DIR_IN: | 1028 | case P54U_PIPE_MGMT | USB_DIR_IN: |
1029 | case P54U_PIPE_BRG | USB_DIR_IN: | 1029 | case P54U_PIPE_BRG | USB_DIR_IN: |
1030 | case P54U_PIPE_DEV | USB_DIR_IN: | 1030 | case P54U_PIPE_DEV | USB_DIR_IN: |
1031 | case P54U_PIPE_INT | USB_DIR_IN: | 1031 | case P54U_PIPE_INT | USB_DIR_IN: |
1032 | recognized_pipes++; | 1032 | recognized_pipes++; |
1033 | } | 1033 | } |
1034 | } | 1034 | } |
1035 | priv->common.open = p54u_open; | 1035 | priv->common.open = p54u_open; |
1036 | priv->common.stop = p54u_stop; | 1036 | priv->common.stop = p54u_stop; |
1037 | if (recognized_pipes < P54U_PIPE_NUMBER) { | 1037 | if (recognized_pipes < P54U_PIPE_NUMBER) { |
1038 | #ifdef CONFIG_PM | 1038 | #ifdef CONFIG_PM |
1039 | /* ISL3887 needs a full reset on resume */ | 1039 | /* ISL3887 needs a full reset on resume */ |
1040 | udev->reset_resume = 1; | 1040 | udev->reset_resume = 1; |
1041 | #endif /* CONFIG_PM */ | 1041 | #endif /* CONFIG_PM */ |
1042 | err = p54u_device_reset(dev); | 1042 | err = p54u_device_reset(dev); |
1043 | 1043 | ||
1044 | priv->hw_type = P54U_3887; | 1044 | priv->hw_type = P54U_3887; |
1045 | dev->extra_tx_headroom += sizeof(struct lm87_tx_hdr); | 1045 | dev->extra_tx_headroom += sizeof(struct lm87_tx_hdr); |
1046 | priv->common.tx_hdr_len = sizeof(struct lm87_tx_hdr); | 1046 | priv->common.tx_hdr_len = sizeof(struct lm87_tx_hdr); |
1047 | priv->common.tx = p54u_tx_lm87; | 1047 | priv->common.tx = p54u_tx_lm87; |
1048 | priv->upload_fw = p54u_upload_firmware_3887; | 1048 | priv->upload_fw = p54u_upload_firmware_3887; |
1049 | } else { | 1049 | } else { |
1050 | priv->hw_type = P54U_NET2280; | 1050 | priv->hw_type = P54U_NET2280; |
1051 | dev->extra_tx_headroom += sizeof(struct net2280_tx_hdr); | 1051 | dev->extra_tx_headroom += sizeof(struct net2280_tx_hdr); |
1052 | priv->common.tx_hdr_len = sizeof(struct net2280_tx_hdr); | 1052 | priv->common.tx_hdr_len = sizeof(struct net2280_tx_hdr); |
1053 | priv->common.tx = p54u_tx_net2280; | 1053 | priv->common.tx = p54u_tx_net2280; |
1054 | priv->upload_fw = p54u_upload_firmware_net2280; | 1054 | priv->upload_fw = p54u_upload_firmware_net2280; |
1055 | } | 1055 | } |
1056 | err = p54u_load_firmware(dev, intf); | 1056 | err = p54u_load_firmware(dev, intf); |
1057 | return err; | 1057 | return err; |
1058 | } | 1058 | } |
1059 | 1059 | ||
1060 | static void __devexit p54u_disconnect(struct usb_interface *intf) | 1060 | static void __devexit p54u_disconnect(struct usb_interface *intf) |
1061 | { | 1061 | { |
1062 | struct ieee80211_hw *dev = usb_get_intfdata(intf); | 1062 | struct ieee80211_hw *dev = usb_get_intfdata(intf); |
1063 | struct p54u_priv *priv; | 1063 | struct p54u_priv *priv; |
1064 | 1064 | ||
1065 | if (!dev) | 1065 | if (!dev) |
1066 | return; | 1066 | return; |
1067 | 1067 | ||
1068 | priv = dev->priv; | 1068 | priv = dev->priv; |
1069 | wait_for_completion(&priv->fw_wait_load); | 1069 | wait_for_completion(&priv->fw_wait_load); |
1070 | p54_unregister_common(dev); | 1070 | p54_unregister_common(dev); |
1071 | 1071 | ||
1072 | usb_put_dev(interface_to_usbdev(intf)); | 1072 | usb_put_dev(interface_to_usbdev(intf)); |
1073 | release_firmware(priv->fw); | 1073 | release_firmware(priv->fw); |
1074 | p54_free_common(dev); | 1074 | p54_free_common(dev); |
1075 | } | 1075 | } |
1076 | 1076 | ||
1077 | static int p54u_pre_reset(struct usb_interface *intf) | 1077 | static int p54u_pre_reset(struct usb_interface *intf) |
1078 | { | 1078 | { |
1079 | struct ieee80211_hw *dev = usb_get_intfdata(intf); | 1079 | struct ieee80211_hw *dev = usb_get_intfdata(intf); |
1080 | 1080 | ||
1081 | if (!dev) | 1081 | if (!dev) |
1082 | return -ENODEV; | 1082 | return -ENODEV; |
1083 | 1083 | ||
1084 | p54u_stop(dev); | 1084 | p54u_stop(dev); |
1085 | return 0; | 1085 | return 0; |
1086 | } | 1086 | } |
1087 | 1087 | ||
1088 | static int p54u_resume(struct usb_interface *intf) | 1088 | static int p54u_resume(struct usb_interface *intf) |
1089 | { | 1089 | { |
1090 | struct ieee80211_hw *dev = usb_get_intfdata(intf); | 1090 | struct ieee80211_hw *dev = usb_get_intfdata(intf); |
1091 | struct p54u_priv *priv; | 1091 | struct p54u_priv *priv; |
1092 | 1092 | ||
1093 | if (!dev) | 1093 | if (!dev) |
1094 | return -ENODEV; | 1094 | return -ENODEV; |
1095 | 1095 | ||
1096 | priv = dev->priv; | 1096 | priv = dev->priv; |
1097 | if (unlikely(!(priv->upload_fw && priv->fw))) | 1097 | if (unlikely(!(priv->upload_fw && priv->fw))) |
1098 | return 0; | 1098 | return 0; |
1099 | 1099 | ||
1100 | return priv->upload_fw(dev); | 1100 | return priv->upload_fw(dev); |
1101 | } | 1101 | } |
1102 | 1102 | ||
1103 | static int p54u_post_reset(struct usb_interface *intf) | 1103 | static int p54u_post_reset(struct usb_interface *intf) |
1104 | { | 1104 | { |
1105 | struct ieee80211_hw *dev = usb_get_intfdata(intf); | 1105 | struct ieee80211_hw *dev = usb_get_intfdata(intf); |
1106 | struct p54u_priv *priv; | 1106 | struct p54u_priv *priv; |
1107 | int err; | 1107 | int err; |
1108 | 1108 | ||
1109 | err = p54u_resume(intf); | 1109 | err = p54u_resume(intf); |
1110 | if (err) | 1110 | if (err) |
1111 | return err; | 1111 | return err; |
1112 | 1112 | ||
1113 | /* reinitialize old device state */ | 1113 | /* reinitialize old device state */ |
1114 | priv = dev->priv; | 1114 | priv = dev->priv; |
1115 | if (priv->common.mode != NL80211_IFTYPE_UNSPECIFIED) | 1115 | if (priv->common.mode != NL80211_IFTYPE_UNSPECIFIED) |
1116 | ieee80211_restart_hw(dev); | 1116 | ieee80211_restart_hw(dev); |
1117 | 1117 | ||
1118 | return 0; | 1118 | return 0; |
1119 | } | 1119 | } |
1120 | 1120 | ||
1121 | #ifdef CONFIG_PM | 1121 | #ifdef CONFIG_PM |
1122 | 1122 | ||
1123 | static int p54u_suspend(struct usb_interface *intf, pm_message_t message) | 1123 | static int p54u_suspend(struct usb_interface *intf, pm_message_t message) |
1124 | { | 1124 | { |
1125 | return p54u_pre_reset(intf); | 1125 | return p54u_pre_reset(intf); |
1126 | } | 1126 | } |
1127 | 1127 | ||
1128 | #endif /* CONFIG_PM */ | 1128 | #endif /* CONFIG_PM */ |
1129 | 1129 | ||
1130 | static struct usb_driver p54u_driver = { | 1130 | static struct usb_driver p54u_driver = { |
1131 | .name = "p54usb", | 1131 | .name = "p54usb", |
1132 | .id_table = p54u_table, | 1132 | .id_table = p54u_table, |
1133 | .probe = p54u_probe, | 1133 | .probe = p54u_probe, |
1134 | .disconnect = p54u_disconnect, | 1134 | .disconnect = __devexit_p(p54u_disconnect), |
1135 | .pre_reset = p54u_pre_reset, | 1135 | .pre_reset = p54u_pre_reset, |
1136 | .post_reset = p54u_post_reset, | 1136 | .post_reset = p54u_post_reset, |
1137 | #ifdef CONFIG_PM | 1137 | #ifdef CONFIG_PM |
1138 | .suspend = p54u_suspend, | 1138 | .suspend = p54u_suspend, |
1139 | .resume = p54u_resume, | 1139 | .resume = p54u_resume, |
1140 | .reset_resume = p54u_resume, | 1140 | .reset_resume = p54u_resume, |
1141 | #endif /* CONFIG_PM */ | 1141 | #endif /* CONFIG_PM */ |
1142 | .soft_unbind = 1, | 1142 | .soft_unbind = 1, |
1143 | }; | 1143 | }; |
1144 | 1144 | ||
1145 | module_usb_driver(p54u_driver); | 1145 | module_usb_driver(p54u_driver); |
1146 | 1146 |