]>
Commit | Line | Data |
---|---|---|
1da177e4 | 1 | /* |
9c1bbdfe | 2 | * Driver for Marvell Discovery (MV643XX) and Marvell Orion ethernet ports |
1da177e4 LT |
3 | * Copyright (C) 2002 Matthew Dharm <mdharm@momenco.com> |
4 | * | |
5 | * Based on the 64360 driver from: | |
4547fa61 LB |
6 | * Copyright (C) 2002 Rabeeh Khoury <rabeeh@galileo.co.il> |
7 | * Rabeeh Khoury <rabeeh@marvell.com> | |
1da177e4 LT |
8 | * |
9 | * Copyright (C) 2003 PMC-Sierra, Inc., | |
3bb8a18a | 10 | * written by Manish Lachwani |
1da177e4 LT |
11 | * |
12 | * Copyright (C) 2003 Ralf Baechle <ralf@linux-mips.org> | |
13 | * | |
c8aaea25 | 14 | * Copyright (C) 2004-2006 MontaVista Software, Inc. |
1da177e4 LT |
15 | * Dale Farnsworth <dale@farnsworth.org> |
16 | * | |
17 | * Copyright (C) 2004 Steven J. Hill <sjhill1@rockwellcollins.com> | |
18 | * <sjhill@realitydiluted.com> | |
19 | * | |
4547fa61 LB |
20 | * Copyright (C) 2007-2008 Marvell Semiconductor |
21 | * Lennert Buytenhek <buytenh@marvell.com> | |
22 | * | |
1da177e4 LT |
23 | * This program is free software; you can redistribute it and/or |
24 | * modify it under the terms of the GNU General Public License | |
25 | * as published by the Free Software Foundation; either version 2 | |
26 | * of the License, or (at your option) any later version. | |
27 | * | |
28 | * This program is distributed in the hope that it will be useful, | |
29 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
30 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
31 | * GNU General Public License for more details. | |
32 | * | |
33 | * You should have received a copy of the GNU General Public License | |
34 | * along with this program; if not, write to the Free Software | |
35 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | |
36 | */ | |
37 | #include <linux/init.h> | |
38 | #include <linux/dma-mapping.h> | |
b6298c22 AV |
39 | #include <linux/in.h> |
40 | #include <linux/ip.h> | |
1da177e4 LT |
41 | #include <linux/tcp.h> |
42 | #include <linux/udp.h> | |
43 | #include <linux/etherdevice.h> | |
44 | ||
45 | #include <linux/bitops.h> | |
46 | #include <linux/delay.h> | |
47 | #include <linux/ethtool.h> | |
d052d1be RK |
48 | #include <linux/platform_device.h> |
49 | ||
fbd6a754 LB |
50 | #include <linux/module.h> |
51 | #include <linux/kernel.h> | |
52 | #include <linux/spinlock.h> | |
53 | #include <linux/workqueue.h> | |
54 | #include <linux/mii.h> | |
55 | ||
56 | #include <linux/mv643xx_eth.h> | |
57 | ||
1da177e4 LT |
58 | #include <asm/io.h> |
59 | #include <asm/types.h> | |
60 | #include <asm/pgtable.h> | |
61 | #include <asm/system.h> | |
62 | #include <asm/delay.h> | |
fbd6a754 LB |
63 | #include <asm/dma-mapping.h> |
64 | ||
fbd6a754 LB |
65 | #define MV643XX_CHECKSUM_OFFLOAD_TX |
66 | #define MV643XX_NAPI | |
67 | #define MV643XX_TX_FAST_REFILL | |
68 | #undef MV643XX_COAL | |
69 | ||
fbd6a754 LB |
70 | #define MV643XX_TX_COAL 100 |
71 | #ifdef MV643XX_COAL | |
72 | #define MV643XX_RX_COAL 100 | |
73 | #endif | |
74 | ||
75 | #ifdef MV643XX_CHECKSUM_OFFLOAD_TX | |
76 | #define MAX_DESCS_PER_SKB (MAX_SKB_FRAGS + 1) | |
77 | #else | |
78 | #define MAX_DESCS_PER_SKB 1 | |
79 | #endif | |
80 | ||
81 | #define ETH_VLAN_HLEN 4 | |
82 | #define ETH_FCS_LEN 4 | |
83 | #define ETH_HW_IP_ALIGN 2 /* hw aligns IP header */ | |
84 | #define ETH_WRAPPER_LEN (ETH_HW_IP_ALIGN + ETH_HLEN + \ | |
85 | ETH_VLAN_HLEN + ETH_FCS_LEN) | |
86 | #define ETH_RX_SKB_SIZE (dev->mtu + ETH_WRAPPER_LEN + \ | |
87 | dma_get_cache_alignment()) | |
88 | ||
89 | /* | |
90 | * Registers shared between all ports. | |
91 | */ | |
92 | #define PHY_ADDR_REG 0x0000 | |
93 | #define SMI_REG 0x0004 | |
94 | ||
95 | /* | |
96 | * Per-port registers. | |
97 | */ | |
98 | #define PORT_CONFIG_REG(p) (0x0400 + ((p) << 10)) | |
99 | #define PORT_CONFIG_EXTEND_REG(p) (0x0404 + ((p) << 10)) | |
100 | #define MAC_ADDR_LOW(p) (0x0414 + ((p) << 10)) | |
101 | #define MAC_ADDR_HIGH(p) (0x0418 + ((p) << 10)) | |
102 | #define SDMA_CONFIG_REG(p) (0x041c + ((p) << 10)) | |
103 | #define PORT_SERIAL_CONTROL_REG(p) (0x043c + ((p) << 10)) | |
104 | #define PORT_STATUS_REG(p) (0x0444 + ((p) << 10)) | |
105 | #define TRANSMIT_QUEUE_COMMAND_REG(p) (0x0448 + ((p) << 10)) | |
106 | #define MAXIMUM_TRANSMIT_UNIT(p) (0x0458 + ((p) << 10)) | |
107 | #define INTERRUPT_CAUSE_REG(p) (0x0460 + ((p) << 10)) | |
108 | #define INTERRUPT_CAUSE_EXTEND_REG(p) (0x0464 + ((p) << 10)) | |
109 | #define INTERRUPT_MASK_REG(p) (0x0468 + ((p) << 10)) | |
110 | #define INTERRUPT_EXTEND_MASK_REG(p) (0x046c + ((p) << 10)) | |
111 | #define TX_FIFO_URGENT_THRESHOLD_REG(p) (0x0474 + ((p) << 10)) | |
112 | #define RX_CURRENT_QUEUE_DESC_PTR_0(p) (0x060c + ((p) << 10)) | |
113 | #define RECEIVE_QUEUE_COMMAND_REG(p) (0x0680 + ((p) << 10)) | |
114 | #define TX_CURRENT_QUEUE_DESC_PTR_0(p) (0x06c0 + ((p) << 10)) | |
115 | #define MIB_COUNTERS_BASE(p) (0x1000 + ((p) << 7)) | |
116 | #define DA_FILTER_SPECIAL_MULTICAST_TABLE_BASE(p) (0x1400 + ((p) << 10)) | |
117 | #define DA_FILTER_OTHER_MULTICAST_TABLE_BASE(p) (0x1500 + ((p) << 10)) | |
118 | #define DA_FILTER_UNICAST_TABLE_BASE(p) (0x1600 + ((p) << 10)) | |
119 | ||
120 | /* These macros describe Ethernet Port configuration reg (Px_cR) bits */ | |
121 | #define UNICAST_NORMAL_MODE (0 << 0) | |
122 | #define UNICAST_PROMISCUOUS_MODE (1 << 0) | |
123 | #define DEFAULT_RX_QUEUE(queue) ((queue) << 1) | |
124 | #define DEFAULT_RX_ARP_QUEUE(queue) ((queue) << 4) | |
125 | #define RECEIVE_BC_IF_NOT_IP_OR_ARP (0 << 7) | |
126 | #define REJECT_BC_IF_NOT_IP_OR_ARP (1 << 7) | |
127 | #define RECEIVE_BC_IF_IP (0 << 8) | |
128 | #define REJECT_BC_IF_IP (1 << 8) | |
129 | #define RECEIVE_BC_IF_ARP (0 << 9) | |
130 | #define REJECT_BC_IF_ARP (1 << 9) | |
131 | #define TX_AM_NO_UPDATE_ERROR_SUMMARY (1 << 12) | |
132 | #define CAPTURE_TCP_FRAMES_DIS (0 << 14) | |
133 | #define CAPTURE_TCP_FRAMES_EN (1 << 14) | |
134 | #define CAPTURE_UDP_FRAMES_DIS (0 << 15) | |
135 | #define CAPTURE_UDP_FRAMES_EN (1 << 15) | |
136 | #define DEFAULT_RX_TCP_QUEUE(queue) ((queue) << 16) | |
137 | #define DEFAULT_RX_UDP_QUEUE(queue) ((queue) << 19) | |
138 | #define DEFAULT_RX_BPDU_QUEUE(queue) ((queue) << 22) | |
139 | ||
140 | #define PORT_CONFIG_DEFAULT_VALUE \ | |
141 | UNICAST_NORMAL_MODE | \ | |
142 | DEFAULT_RX_QUEUE(0) | \ | |
143 | DEFAULT_RX_ARP_QUEUE(0) | \ | |
144 | RECEIVE_BC_IF_NOT_IP_OR_ARP | \ | |
145 | RECEIVE_BC_IF_IP | \ | |
146 | RECEIVE_BC_IF_ARP | \ | |
147 | CAPTURE_TCP_FRAMES_DIS | \ | |
148 | CAPTURE_UDP_FRAMES_DIS | \ | |
149 | DEFAULT_RX_TCP_QUEUE(0) | \ | |
150 | DEFAULT_RX_UDP_QUEUE(0) | \ | |
151 | DEFAULT_RX_BPDU_QUEUE(0) | |
152 | ||
153 | /* These macros describe Ethernet Port configuration extend reg (Px_cXR) bits*/ | |
154 | #define CLASSIFY_EN (1 << 0) | |
155 | #define SPAN_BPDU_PACKETS_AS_NORMAL (0 << 1) | |
156 | #define SPAN_BPDU_PACKETS_TO_RX_QUEUE_7 (1 << 1) | |
157 | #define PARTITION_DISABLE (0 << 2) | |
158 | #define PARTITION_ENABLE (1 << 2) | |
159 | ||
160 | #define PORT_CONFIG_EXTEND_DEFAULT_VALUE \ | |
161 | SPAN_BPDU_PACKETS_AS_NORMAL | \ | |
162 | PARTITION_DISABLE | |
163 | ||
164 | /* These macros describe Ethernet Port Sdma configuration reg (SDCR) bits */ | |
165 | #define RIFB (1 << 0) | |
166 | #define RX_BURST_SIZE_1_64BIT (0 << 1) | |
167 | #define RX_BURST_SIZE_2_64BIT (1 << 1) | |
168 | #define RX_BURST_SIZE_4_64BIT (2 << 1) | |
169 | #define RX_BURST_SIZE_8_64BIT (3 << 1) | |
170 | #define RX_BURST_SIZE_16_64BIT (4 << 1) | |
171 | #define BLM_RX_NO_SWAP (1 << 4) | |
172 | #define BLM_RX_BYTE_SWAP (0 << 4) | |
173 | #define BLM_TX_NO_SWAP (1 << 5) | |
174 | #define BLM_TX_BYTE_SWAP (0 << 5) | |
175 | #define DESCRIPTORS_BYTE_SWAP (1 << 6) | |
176 | #define DESCRIPTORS_NO_SWAP (0 << 6) | |
177 | #define IPG_INT_RX(value) (((value) & 0x3fff) << 8) | |
178 | #define TX_BURST_SIZE_1_64BIT (0 << 22) | |
179 | #define TX_BURST_SIZE_2_64BIT (1 << 22) | |
180 | #define TX_BURST_SIZE_4_64BIT (2 << 22) | |
181 | #define TX_BURST_SIZE_8_64BIT (3 << 22) | |
182 | #define TX_BURST_SIZE_16_64BIT (4 << 22) | |
183 | ||
184 | #if defined(__BIG_ENDIAN) | |
185 | #define PORT_SDMA_CONFIG_DEFAULT_VALUE \ | |
186 | RX_BURST_SIZE_4_64BIT | \ | |
187 | IPG_INT_RX(0) | \ | |
188 | TX_BURST_SIZE_4_64BIT | |
189 | #elif defined(__LITTLE_ENDIAN) | |
190 | #define PORT_SDMA_CONFIG_DEFAULT_VALUE \ | |
191 | RX_BURST_SIZE_4_64BIT | \ | |
192 | BLM_RX_NO_SWAP | \ | |
193 | BLM_TX_NO_SWAP | \ | |
194 | IPG_INT_RX(0) | \ | |
195 | TX_BURST_SIZE_4_64BIT | |
196 | #else | |
197 | #error One of __BIG_ENDIAN or __LITTLE_ENDIAN must be defined | |
198 | #endif | |
199 | ||
200 | /* These macros describe Ethernet Port serial control reg (PSCR) bits */ | |
201 | #define SERIAL_PORT_DISABLE (0 << 0) | |
202 | #define SERIAL_PORT_ENABLE (1 << 0) | |
203 | #define DO_NOT_FORCE_LINK_PASS (0 << 1) | |
204 | #define FORCE_LINK_PASS (1 << 1) | |
205 | #define ENABLE_AUTO_NEG_FOR_DUPLX (0 << 2) | |
206 | #define DISABLE_AUTO_NEG_FOR_DUPLX (1 << 2) | |
207 | #define ENABLE_AUTO_NEG_FOR_FLOW_CTRL (0 << 3) | |
208 | #define DISABLE_AUTO_NEG_FOR_FLOW_CTRL (1 << 3) | |
209 | #define ADV_NO_FLOW_CTRL (0 << 4) | |
210 | #define ADV_SYMMETRIC_FLOW_CTRL (1 << 4) | |
211 | #define FORCE_FC_MODE_NO_PAUSE_DIS_TX (0 << 5) | |
212 | #define FORCE_FC_MODE_TX_PAUSE_DIS (1 << 5) | |
213 | #define FORCE_BP_MODE_NO_JAM (0 << 7) | |
214 | #define FORCE_BP_MODE_JAM_TX (1 << 7) | |
215 | #define FORCE_BP_MODE_JAM_TX_ON_RX_ERR (2 << 7) | |
216 | #define SERIAL_PORT_CONTROL_RESERVED (1 << 9) | |
217 | #define FORCE_LINK_FAIL (0 << 10) | |
218 | #define DO_NOT_FORCE_LINK_FAIL (1 << 10) | |
219 | #define RETRANSMIT_16_ATTEMPTS (0 << 11) | |
220 | #define RETRANSMIT_FOREVER (1 << 11) | |
221 | #define ENABLE_AUTO_NEG_SPEED_GMII (0 << 13) | |
222 | #define DISABLE_AUTO_NEG_SPEED_GMII (1 << 13) | |
223 | #define DTE_ADV_0 (0 << 14) | |
224 | #define DTE_ADV_1 (1 << 14) | |
225 | #define DISABLE_AUTO_NEG_BYPASS (0 << 15) | |
226 | #define ENABLE_AUTO_NEG_BYPASS (1 << 15) | |
227 | #define AUTO_NEG_NO_CHANGE (0 << 16) | |
228 | #define RESTART_AUTO_NEG (1 << 16) | |
229 | #define MAX_RX_PACKET_1518BYTE (0 << 17) | |
230 | #define MAX_RX_PACKET_1522BYTE (1 << 17) | |
231 | #define MAX_RX_PACKET_1552BYTE (2 << 17) | |
232 | #define MAX_RX_PACKET_9022BYTE (3 << 17) | |
233 | #define MAX_RX_PACKET_9192BYTE (4 << 17) | |
234 | #define MAX_RX_PACKET_9700BYTE (5 << 17) | |
235 | #define MAX_RX_PACKET_MASK (7 << 17) | |
236 | #define CLR_EXT_LOOPBACK (0 << 20) | |
237 | #define SET_EXT_LOOPBACK (1 << 20) | |
238 | #define SET_HALF_DUPLEX_MODE (0 << 21) | |
239 | #define SET_FULL_DUPLEX_MODE (1 << 21) | |
240 | #define DISABLE_FLOW_CTRL_TX_RX_IN_FULL_DUPLEX (0 << 22) | |
241 | #define ENABLE_FLOW_CTRL_TX_RX_IN_FULL_DUPLEX (1 << 22) | |
242 | #define SET_GMII_SPEED_TO_10_100 (0 << 23) | |
243 | #define SET_GMII_SPEED_TO_1000 (1 << 23) | |
244 | #define SET_MII_SPEED_TO_10 (0 << 24) | |
245 | #define SET_MII_SPEED_TO_100 (1 << 24) | |
246 | ||
247 | #define PORT_SERIAL_CONTROL_DEFAULT_VALUE \ | |
248 | DO_NOT_FORCE_LINK_PASS | \ | |
249 | ENABLE_AUTO_NEG_FOR_DUPLX | \ | |
250 | DISABLE_AUTO_NEG_FOR_FLOW_CTRL | \ | |
251 | ADV_SYMMETRIC_FLOW_CTRL | \ | |
252 | FORCE_FC_MODE_NO_PAUSE_DIS_TX | \ | |
253 | FORCE_BP_MODE_NO_JAM | \ | |
254 | (1 << 9) /* reserved */ | \ | |
255 | DO_NOT_FORCE_LINK_FAIL | \ | |
256 | RETRANSMIT_16_ATTEMPTS | \ | |
257 | ENABLE_AUTO_NEG_SPEED_GMII | \ | |
258 | DTE_ADV_0 | \ | |
259 | DISABLE_AUTO_NEG_BYPASS | \ | |
260 | AUTO_NEG_NO_CHANGE | \ | |
261 | MAX_RX_PACKET_9700BYTE | \ | |
262 | CLR_EXT_LOOPBACK | \ | |
263 | SET_FULL_DUPLEX_MODE | \ | |
264 | ENABLE_FLOW_CTRL_TX_RX_IN_FULL_DUPLEX | |
265 | ||
266 | /* These macros describe Ethernet Serial Status reg (PSR) bits */ | |
267 | #define PORT_STATUS_MODE_10_BIT (1 << 0) | |
268 | #define PORT_STATUS_LINK_UP (1 << 1) | |
269 | #define PORT_STATUS_FULL_DUPLEX (1 << 2) | |
270 | #define PORT_STATUS_FLOW_CONTROL (1 << 3) | |
271 | #define PORT_STATUS_GMII_1000 (1 << 4) | |
272 | #define PORT_STATUS_MII_100 (1 << 5) | |
273 | /* PSR bit 6 is undocumented */ | |
274 | #define PORT_STATUS_TX_IN_PROGRESS (1 << 7) | |
275 | #define PORT_STATUS_AUTONEG_BYPASSED (1 << 8) | |
276 | #define PORT_STATUS_PARTITION (1 << 9) | |
277 | #define PORT_STATUS_TX_FIFO_EMPTY (1 << 10) | |
278 | /* PSR bits 11-31 are reserved */ | |
279 | ||
280 | #define PORT_DEFAULT_TRANSMIT_QUEUE_SIZE 800 | |
281 | #define PORT_DEFAULT_RECEIVE_QUEUE_SIZE 400 | |
282 | ||
283 | #define DESC_SIZE 64 | |
284 | ||
285 | #define ETH_RX_QUEUES_ENABLED (1 << 0) /* use only Q0 for receive */ | |
286 | #define ETH_TX_QUEUES_ENABLED (1 << 0) /* use only Q0 for transmit */ | |
287 | ||
288 | #define ETH_INT_CAUSE_RX_DONE (ETH_RX_QUEUES_ENABLED << 2) | |
289 | #define ETH_INT_CAUSE_RX_ERROR (ETH_RX_QUEUES_ENABLED << 9) | |
290 | #define ETH_INT_CAUSE_RX (ETH_INT_CAUSE_RX_DONE | ETH_INT_CAUSE_RX_ERROR) | |
291 | #define ETH_INT_CAUSE_EXT 0x00000002 | |
292 | #define ETH_INT_UNMASK_ALL (ETH_INT_CAUSE_RX | ETH_INT_CAUSE_EXT) | |
293 | ||
294 | #define ETH_INT_CAUSE_TX_DONE (ETH_TX_QUEUES_ENABLED << 0) | |
295 | #define ETH_INT_CAUSE_TX_ERROR (ETH_TX_QUEUES_ENABLED << 8) | |
296 | #define ETH_INT_CAUSE_TX (ETH_INT_CAUSE_TX_DONE | ETH_INT_CAUSE_TX_ERROR) | |
297 | #define ETH_INT_CAUSE_PHY 0x00010000 | |
298 | #define ETH_INT_CAUSE_STATE 0x00100000 | |
299 | #define ETH_INT_UNMASK_ALL_EXT (ETH_INT_CAUSE_TX | ETH_INT_CAUSE_PHY | \ | |
300 | ETH_INT_CAUSE_STATE) | |
301 | ||
302 | #define ETH_INT_MASK_ALL 0x00000000 | |
303 | #define ETH_INT_MASK_ALL_EXT 0x00000000 | |
304 | ||
305 | #define PHY_WAIT_ITERATIONS 1000 /* 1000 iterations * 10uS = 10mS max */ | |
306 | #define PHY_WAIT_MICRO_SECONDS 10 | |
307 | ||
308 | /* Buffer offset from buffer pointer */ | |
309 | #define RX_BUF_OFFSET 0x2 | |
310 | ||
311 | /* Gigabit Ethernet Unit Global Registers */ | |
312 | ||
313 | /* MIB Counters register definitions */ | |
314 | #define ETH_MIB_GOOD_OCTETS_RECEIVED_LOW 0x0 | |
315 | #define ETH_MIB_GOOD_OCTETS_RECEIVED_HIGH 0x4 | |
316 | #define ETH_MIB_BAD_OCTETS_RECEIVED 0x8 | |
317 | #define ETH_MIB_INTERNAL_MAC_TRANSMIT_ERR 0xc | |
318 | #define ETH_MIB_GOOD_FRAMES_RECEIVED 0x10 | |
319 | #define ETH_MIB_BAD_FRAMES_RECEIVED 0x14 | |
320 | #define ETH_MIB_BROADCAST_FRAMES_RECEIVED 0x18 | |
321 | #define ETH_MIB_MULTICAST_FRAMES_RECEIVED 0x1c | |
322 | #define ETH_MIB_FRAMES_64_OCTETS 0x20 | |
323 | #define ETH_MIB_FRAMES_65_TO_127_OCTETS 0x24 | |
324 | #define ETH_MIB_FRAMES_128_TO_255_OCTETS 0x28 | |
325 | #define ETH_MIB_FRAMES_256_TO_511_OCTETS 0x2c | |
326 | #define ETH_MIB_FRAMES_512_TO_1023_OCTETS 0x30 | |
327 | #define ETH_MIB_FRAMES_1024_TO_MAX_OCTETS 0x34 | |
328 | #define ETH_MIB_GOOD_OCTETS_SENT_LOW 0x38 | |
329 | #define ETH_MIB_GOOD_OCTETS_SENT_HIGH 0x3c | |
330 | #define ETH_MIB_GOOD_FRAMES_SENT 0x40 | |
331 | #define ETH_MIB_EXCESSIVE_COLLISION 0x44 | |
332 | #define ETH_MIB_MULTICAST_FRAMES_SENT 0x48 | |
333 | #define ETH_MIB_BROADCAST_FRAMES_SENT 0x4c | |
334 | #define ETH_MIB_UNREC_MAC_CONTROL_RECEIVED 0x50 | |
335 | #define ETH_MIB_FC_SENT 0x54 | |
336 | #define ETH_MIB_GOOD_FC_RECEIVED 0x58 | |
337 | #define ETH_MIB_BAD_FC_RECEIVED 0x5c | |
338 | #define ETH_MIB_UNDERSIZE_RECEIVED 0x60 | |
339 | #define ETH_MIB_FRAGMENTS_RECEIVED 0x64 | |
340 | #define ETH_MIB_OVERSIZE_RECEIVED 0x68 | |
341 | #define ETH_MIB_JABBER_RECEIVED 0x6c | |
342 | #define ETH_MIB_MAC_RECEIVE_ERROR 0x70 | |
343 | #define ETH_MIB_BAD_CRC_EVENT 0x74 | |
344 | #define ETH_MIB_COLLISION 0x78 | |
345 | #define ETH_MIB_LATE_COLLISION 0x7c | |
346 | ||
347 | /* Port serial status reg (PSR) */ | |
348 | #define ETH_INTERFACE_PCM 0x00000001 | |
349 | #define ETH_LINK_IS_UP 0x00000002 | |
350 | #define ETH_PORT_AT_FULL_DUPLEX 0x00000004 | |
351 | #define ETH_RX_FLOW_CTRL_ENABLED 0x00000008 | |
352 | #define ETH_GMII_SPEED_1000 0x00000010 | |
353 | #define ETH_MII_SPEED_100 0x00000020 | |
354 | #define ETH_TX_IN_PROGRESS 0x00000080 | |
355 | #define ETH_BYPASS_ACTIVE 0x00000100 | |
356 | #define ETH_PORT_AT_PARTITION_STATE 0x00000200 | |
357 | #define ETH_PORT_TX_FIFO_EMPTY 0x00000400 | |
358 | ||
359 | /* SMI reg */ | |
360 | #define ETH_SMI_BUSY 0x10000000 /* 0 - Write, 1 - Read */ | |
361 | #define ETH_SMI_READ_VALID 0x08000000 /* 0 - Write, 1 - Read */ | |
362 | #define ETH_SMI_OPCODE_WRITE 0 /* Completion of Read */ | |
363 | #define ETH_SMI_OPCODE_READ 0x04000000 /* Operation is in progress */ | |
364 | ||
365 | /* Interrupt Cause Register Bit Definitions */ | |
366 | ||
367 | /* SDMA command status fields macros */ | |
368 | ||
369 | /* Tx & Rx descriptors status */ | |
370 | #define ETH_ERROR_SUMMARY 0x00000001 | |
371 | ||
372 | /* Tx & Rx descriptors command */ | |
373 | #define ETH_BUFFER_OWNED_BY_DMA 0x80000000 | |
374 | ||
375 | /* Tx descriptors status */ | |
376 | #define ETH_LC_ERROR 0 | |
377 | #define ETH_UR_ERROR 0x00000002 | |
378 | #define ETH_RL_ERROR 0x00000004 | |
379 | #define ETH_LLC_SNAP_FORMAT 0x00000200 | |
380 | ||
381 | /* Rx descriptors status */ | |
382 | #define ETH_OVERRUN_ERROR 0x00000002 | |
383 | #define ETH_MAX_FRAME_LENGTH_ERROR 0x00000004 | |
384 | #define ETH_RESOURCE_ERROR 0x00000006 | |
385 | #define ETH_VLAN_TAGGED 0x00080000 | |
386 | #define ETH_BPDU_FRAME 0x00100000 | |
387 | #define ETH_UDP_FRAME_OVER_IP_V_4 0x00200000 | |
388 | #define ETH_OTHER_FRAME_TYPE 0x00400000 | |
389 | #define ETH_LAYER_2_IS_ETH_V_2 0x00800000 | |
390 | #define ETH_FRAME_TYPE_IP_V_4 0x01000000 | |
391 | #define ETH_FRAME_HEADER_OK 0x02000000 | |
392 | #define ETH_RX_LAST_DESC 0x04000000 | |
393 | #define ETH_RX_FIRST_DESC 0x08000000 | |
394 | #define ETH_UNKNOWN_DESTINATION_ADDR 0x10000000 | |
395 | #define ETH_RX_ENABLE_INTERRUPT 0x20000000 | |
396 | #define ETH_LAYER_4_CHECKSUM_OK 0x40000000 | |
397 | ||
398 | /* Rx descriptors byte count */ | |
399 | #define ETH_FRAME_FRAGMENTED 0x00000004 | |
400 | ||
401 | /* Tx descriptors command */ | |
402 | #define ETH_LAYER_4_CHECKSUM_FIRST_DESC 0x00000400 | |
403 | #define ETH_FRAME_SET_TO_VLAN 0x00008000 | |
404 | #define ETH_UDP_FRAME 0x00010000 | |
405 | #define ETH_GEN_TCP_UDP_CHECKSUM 0x00020000 | |
406 | #define ETH_GEN_IP_V_4_CHECKSUM 0x00040000 | |
407 | #define ETH_ZERO_PADDING 0x00080000 | |
408 | #define ETH_TX_LAST_DESC 0x00100000 | |
409 | #define ETH_TX_FIRST_DESC 0x00200000 | |
410 | #define ETH_GEN_CRC 0x00400000 | |
411 | #define ETH_TX_ENABLE_INTERRUPT 0x00800000 | |
412 | #define ETH_AUTO_MODE 0x40000000 | |
413 | ||
414 | #define ETH_TX_IHL_SHIFT 11 | |
415 | ||
416 | /* typedefs */ | |
417 | ||
418 | typedef enum _eth_func_ret_status { | |
419 | ETH_OK, /* Returned as expected. */ | |
420 | ETH_ERROR, /* Fundamental error. */ | |
421 | ETH_RETRY, /* Could not process request. Try later.*/ | |
422 | ETH_END_OF_JOB, /* Ring has nothing to process. */ | |
423 | ETH_QUEUE_FULL, /* Ring resource error. */ | |
424 | ETH_QUEUE_LAST_RESOURCE /* Ring resources about to exhaust. */ | |
425 | } ETH_FUNC_RET_STATUS; | |
426 | ||
fbd6a754 LB |
427 | /* These are for big-endian machines. Little endian needs different |
428 | * definitions. | |
429 | */ | |
430 | #if defined(__BIG_ENDIAN) | |
431 | struct eth_rx_desc { | |
432 | u16 byte_cnt; /* Descriptor buffer byte count */ | |
433 | u16 buf_size; /* Buffer size */ | |
434 | u32 cmd_sts; /* Descriptor command status */ | |
435 | u32 next_desc_ptr; /* Next descriptor pointer */ | |
436 | u32 buf_ptr; /* Descriptor buffer pointer */ | |
437 | }; | |
438 | ||
439 | struct eth_tx_desc { | |
440 | u16 byte_cnt; /* buffer byte count */ | |
441 | u16 l4i_chk; /* CPU provided TCP checksum */ | |
442 | u32 cmd_sts; /* Command/status field */ | |
443 | u32 next_desc_ptr; /* Pointer to next descriptor */ | |
444 | u32 buf_ptr; /* pointer to buffer for this descriptor*/ | |
445 | }; | |
446 | #elif defined(__LITTLE_ENDIAN) | |
447 | struct eth_rx_desc { | |
448 | u32 cmd_sts; /* Descriptor command status */ | |
449 | u16 buf_size; /* Buffer size */ | |
450 | u16 byte_cnt; /* Descriptor buffer byte count */ | |
451 | u32 buf_ptr; /* Descriptor buffer pointer */ | |
452 | u32 next_desc_ptr; /* Next descriptor pointer */ | |
453 | }; | |
454 | ||
455 | struct eth_tx_desc { | |
456 | u32 cmd_sts; /* Command/status field */ | |
457 | u16 l4i_chk; /* CPU provided TCP checksum */ | |
458 | u16 byte_cnt; /* buffer byte count */ | |
459 | u32 buf_ptr; /* pointer to buffer for this descriptor*/ | |
460 | u32 next_desc_ptr; /* Pointer to next descriptor */ | |
461 | }; | |
462 | #else | |
463 | #error One of __BIG_ENDIAN or __LITTLE_ENDIAN must be defined | |
464 | #endif | |
465 | ||
466 | /* Unified struct for Rx and Tx operations. The user is not required to */ | |
467 | /* be familier with neither Tx nor Rx descriptors. */ | |
468 | struct pkt_info { | |
469 | unsigned short byte_cnt; /* Descriptor buffer byte count */ | |
470 | unsigned short l4i_chk; /* Tx CPU provided TCP Checksum */ | |
471 | unsigned int cmd_sts; /* Descriptor command status */ | |
472 | dma_addr_t buf_ptr; /* Descriptor buffer pointer */ | |
473 | struct sk_buff *return_info; /* User resource return information */ | |
474 | }; | |
475 | ||
476 | /* Ethernet port specific information */ | |
477 | struct mv643xx_mib_counters { | |
478 | u64 good_octets_received; | |
479 | u32 bad_octets_received; | |
480 | u32 internal_mac_transmit_err; | |
481 | u32 good_frames_received; | |
482 | u32 bad_frames_received; | |
483 | u32 broadcast_frames_received; | |
484 | u32 multicast_frames_received; | |
485 | u32 frames_64_octets; | |
486 | u32 frames_65_to_127_octets; | |
487 | u32 frames_128_to_255_octets; | |
488 | u32 frames_256_to_511_octets; | |
489 | u32 frames_512_to_1023_octets; | |
490 | u32 frames_1024_to_max_octets; | |
491 | u64 good_octets_sent; | |
492 | u32 good_frames_sent; | |
493 | u32 excessive_collision; | |
494 | u32 multicast_frames_sent; | |
495 | u32 broadcast_frames_sent; | |
496 | u32 unrec_mac_control_received; | |
497 | u32 fc_sent; | |
498 | u32 good_fc_received; | |
499 | u32 bad_fc_received; | |
500 | u32 undersize_received; | |
501 | u32 fragments_received; | |
502 | u32 oversize_received; | |
503 | u32 jabber_received; | |
504 | u32 mac_receive_error; | |
505 | u32 bad_crc_event; | |
506 | u32 collision; | |
507 | u32 late_collision; | |
508 | }; | |
509 | ||
510 | struct mv643xx_private { | |
511 | int port_num; /* User Ethernet port number */ | |
512 | ||
513 | u32 rx_sram_addr; /* Base address of rx sram area */ | |
514 | u32 rx_sram_size; /* Size of rx sram area */ | |
515 | u32 tx_sram_addr; /* Base address of tx sram area */ | |
516 | u32 tx_sram_size; /* Size of tx sram area */ | |
517 | ||
518 | int rx_resource_err; /* Rx ring resource error flag */ | |
519 | ||
520 | /* Tx/Rx rings managment indexes fields. For driver use */ | |
521 | ||
522 | /* Next available and first returning Rx resource */ | |
523 | int rx_curr_desc_q, rx_used_desc_q; | |
524 | ||
525 | /* Next available and first returning Tx resource */ | |
526 | int tx_curr_desc_q, tx_used_desc_q; | |
527 | ||
528 | #ifdef MV643XX_TX_FAST_REFILL | |
529 | u32 tx_clean_threshold; | |
530 | #endif | |
531 | ||
532 | struct eth_rx_desc *p_rx_desc_area; | |
533 | dma_addr_t rx_desc_dma; | |
534 | int rx_desc_area_size; | |
535 | struct sk_buff **rx_skb; | |
536 | ||
537 | struct eth_tx_desc *p_tx_desc_area; | |
538 | dma_addr_t tx_desc_dma; | |
539 | int tx_desc_area_size; | |
540 | struct sk_buff **tx_skb; | |
541 | ||
542 | struct work_struct tx_timeout_task; | |
543 | ||
544 | struct net_device *dev; | |
545 | struct napi_struct napi; | |
546 | struct net_device_stats stats; | |
547 | struct mv643xx_mib_counters mib_counters; | |
548 | spinlock_t lock; | |
549 | /* Size of Tx Ring per queue */ | |
550 | int tx_ring_size; | |
551 | /* Number of tx descriptors in use */ | |
552 | int tx_desc_count; | |
553 | /* Size of Rx Ring per queue */ | |
554 | int rx_ring_size; | |
555 | /* Number of rx descriptors in use */ | |
556 | int rx_desc_count; | |
557 | ||
558 | /* | |
559 | * Used in case RX Ring is empty, which can be caused when | |
560 | * system does not have resources (skb's) | |
561 | */ | |
562 | struct timer_list timeout; | |
563 | ||
564 | u32 rx_int_coal; | |
565 | u32 tx_int_coal; | |
566 | struct mii_if_info mii; | |
567 | }; | |
1da177e4 | 568 | |
1da177e4 | 569 | /* Static function declarations */ |
fbd6a754 | 570 | static void eth_port_init(struct mv643xx_private *mp); |
afdb57a2 | 571 | static void eth_port_reset(struct mv643xx_private *mp); |
fbd6a754 LB |
572 | static void eth_port_start(struct net_device *dev); |
573 | ||
afdb57a2 | 574 | static void ethernet_phy_reset(struct mv643xx_private *mp); |
fbd6a754 | 575 | |
afdb57a2 | 576 | static void eth_port_write_smi_reg(struct mv643xx_private *mp, |
fbd6a754 LB |
577 | unsigned int phy_reg, unsigned int value); |
578 | ||
afdb57a2 | 579 | static void eth_port_read_smi_reg(struct mv643xx_private *mp, |
fbd6a754 LB |
580 | unsigned int phy_reg, unsigned int *value); |
581 | ||
afdb57a2 | 582 | static void eth_clear_mib_counters(struct mv643xx_private *mp); |
fbd6a754 LB |
583 | |
584 | static ETH_FUNC_RET_STATUS eth_port_receive(struct mv643xx_private *mp, | |
585 | struct pkt_info *p_pkt_info); | |
586 | static ETH_FUNC_RET_STATUS eth_rx_return_buff(struct mv643xx_private *mp, | |
587 | struct pkt_info *p_pkt_info); | |
588 | ||
afdb57a2 LB |
589 | static void eth_port_uc_addr_get(struct mv643xx_private *mp, |
590 | unsigned char *p_addr); | |
591 | static void eth_port_uc_addr_set(struct mv643xx_private *mp, | |
592 | unsigned char *p_addr); | |
16e03018 | 593 | static void eth_port_set_multicast_list(struct net_device *); |
afdb57a2 | 594 | static void mv643xx_eth_port_enable_tx(struct mv643xx_private *mp, |
12a87c64 | 595 | unsigned int queues); |
afdb57a2 | 596 | static void mv643xx_eth_port_enable_rx(struct mv643xx_private *mp, |
12a87c64 | 597 | unsigned int queues); |
afdb57a2 LB |
598 | static unsigned int mv643xx_eth_port_disable_tx(struct mv643xx_private *mp); |
599 | static unsigned int mv643xx_eth_port_disable_rx(struct mv643xx_private *mp); | |
ab4384a6 DF |
600 | static int mv643xx_eth_open(struct net_device *); |
601 | static int mv643xx_eth_stop(struct net_device *); | |
afdb57a2 | 602 | static void eth_port_init_mac_tables(struct mv643xx_private *mp); |
1da177e4 | 603 | #ifdef MV643XX_NAPI |
bea3348e | 604 | static int mv643xx_poll(struct napi_struct *napi, int budget); |
1da177e4 | 605 | #endif |
afdb57a2 LB |
606 | static int ethernet_phy_get(struct mv643xx_private *mp); |
607 | static void ethernet_phy_set(struct mv643xx_private *mp, int phy_addr); | |
608 | static int ethernet_phy_detect(struct mv643xx_private *mp); | |
c28a4f89 JC |
609 | static int mv643xx_mdio_read(struct net_device *dev, int phy_id, int location); |
610 | static void mv643xx_mdio_write(struct net_device *dev, int phy_id, int location, int val); | |
d0412d96 | 611 | static int mv643xx_eth_do_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd); |
7282d491 | 612 | static const struct ethtool_ops mv643xx_ethtool_ops; |
1da177e4 LT |
613 | |
614 | static char mv643xx_driver_name[] = "mv643xx_eth"; | |
615 | static char mv643xx_driver_version[] = "1.0"; | |
616 | ||
f9fbbc18 | 617 | static void __iomem *mv643xx_eth_base; |
1da177e4 | 618 | |
e4d00fa9 | 619 | /* used to protect SMI_REG, which is shared across ports */ |
a9f6a0dd | 620 | static DEFINE_SPINLOCK(mv643xx_eth_phy_lock); |
1da177e4 | 621 | |
ec69d651 | 622 | static inline u32 rdl(struct mv643xx_private *mp, int offset) |
1da177e4 | 623 | { |
f9fbbc18 | 624 | return readl(mv643xx_eth_base + offset); |
1da177e4 LT |
625 | } |
626 | ||
ec69d651 | 627 | static inline void wrl(struct mv643xx_private *mp, int offset, u32 data) |
1da177e4 | 628 | { |
f9fbbc18 | 629 | writel(data, mv643xx_eth_base + offset); |
1da177e4 LT |
630 | } |
631 | ||
632 | /* | |
633 | * Changes MTU (maximum transfer unit) of the gigabit ethenret port | |
634 | * | |
635 | * Input : pointer to ethernet interface network device structure | |
636 | * new mtu size | |
637 | * Output : 0 upon success, -EINVAL upon failure | |
638 | */ | |
639 | static int mv643xx_eth_change_mtu(struct net_device *dev, int new_mtu) | |
640 | { | |
8f518703 | 641 | if ((new_mtu > 9500) || (new_mtu < 64)) |
1da177e4 | 642 | return -EINVAL; |
1da177e4 LT |
643 | |
644 | dev->mtu = new_mtu; | |
c0d0f2ca LB |
645 | if (!netif_running(dev)) |
646 | return 0; | |
647 | ||
1da177e4 | 648 | /* |
c0d0f2ca LB |
649 | * Stop and then re-open the interface. This will allocate RX |
650 | * skbs of the new MTU. | |
651 | * There is a possible danger that the open will not succeed, | |
652 | * due to memory being full, which might fail the open function. | |
1da177e4 | 653 | */ |
c0d0f2ca LB |
654 | mv643xx_eth_stop(dev); |
655 | if (mv643xx_eth_open(dev)) { | |
656 | printk(KERN_ERR "%s: Fatal error on opening device\n", | |
657 | dev->name); | |
1da177e4 LT |
658 | } |
659 | ||
1da177e4 LT |
660 | return 0; |
661 | } | |
662 | ||
663 | /* | |
f78fb474 | 664 | * mv643xx_eth_rx_refill_descs |
1da177e4 LT |
665 | * |
666 | * Fills / refills RX queue on a certain gigabit ethernet port | |
667 | * | |
668 | * Input : pointer to ethernet interface network device structure | |
669 | * Output : N/A | |
670 | */ | |
f78fb474 | 671 | static void mv643xx_eth_rx_refill_descs(struct net_device *dev) |
1da177e4 | 672 | { |
1da177e4 LT |
673 | struct mv643xx_private *mp = netdev_priv(dev); |
674 | struct pkt_info pkt_info; | |
675 | struct sk_buff *skb; | |
b44cd572 | 676 | int unaligned; |
1da177e4 | 677 | |
f78fb474 | 678 | while (mp->rx_desc_count < mp->rx_ring_size) { |
908b637f | 679 | skb = dev_alloc_skb(ETH_RX_SKB_SIZE + dma_get_cache_alignment()); |
1da177e4 LT |
680 | if (!skb) |
681 | break; | |
f98e36f1 | 682 | mp->rx_desc_count++; |
908b637f | 683 | unaligned = (u32)skb->data & (dma_get_cache_alignment() - 1); |
b44cd572 | 684 | if (unaligned) |
908b637f | 685 | skb_reserve(skb, dma_get_cache_alignment() - unaligned); |
1da177e4 | 686 | pkt_info.cmd_sts = ETH_RX_ENABLE_INTERRUPT; |
7303fde8 DF |
687 | pkt_info.byte_cnt = ETH_RX_SKB_SIZE; |
688 | pkt_info.buf_ptr = dma_map_single(NULL, skb->data, | |
689 | ETH_RX_SKB_SIZE, DMA_FROM_DEVICE); | |
1da177e4 LT |
690 | pkt_info.return_info = skb; |
691 | if (eth_rx_return_buff(mp, &pkt_info) != ETH_OK) { | |
692 | printk(KERN_ERR | |
693 | "%s: Error allocating RX Ring\n", dev->name); | |
694 | break; | |
695 | } | |
7303fde8 | 696 | skb_reserve(skb, ETH_HW_IP_ALIGN); |
1da177e4 | 697 | } |
1da177e4 LT |
698 | /* |
699 | * If RX ring is empty of SKB, set a timer to try allocating | |
f78fb474 | 700 | * again at a later time. |
1da177e4 | 701 | */ |
f78fb474 | 702 | if (mp->rx_desc_count == 0) { |
1da177e4 | 703 | printk(KERN_INFO "%s: Rx ring is empty\n", dev->name); |
f78fb474 | 704 | mp->timeout.expires = jiffies + (HZ / 10); /* 100 mSec */ |
1da177e4 | 705 | add_timer(&mp->timeout); |
1da177e4 | 706 | } |
1da177e4 LT |
707 | } |
708 | ||
709 | /* | |
f78fb474 | 710 | * mv643xx_eth_rx_refill_descs_timer_wrapper |
1da177e4 LT |
711 | * |
712 | * Timer routine to wake up RX queue filling task. This function is | |
713 | * used only in case the RX queue is empty, and all alloc_skb has | |
714 | * failed (due to out of memory event). | |
715 | * | |
716 | * Input : pointer to ethernet interface network device structure | |
717 | * Output : N/A | |
718 | */ | |
f78fb474 | 719 | static inline void mv643xx_eth_rx_refill_descs_timer_wrapper(unsigned long data) |
1da177e4 | 720 | { |
f78fb474 | 721 | mv643xx_eth_rx_refill_descs((struct net_device *)data); |
1da177e4 LT |
722 | } |
723 | ||
724 | /* | |
725 | * mv643xx_eth_update_mac_address | |
726 | * | |
727 | * Update the MAC address of the port in the address table | |
728 | * | |
729 | * Input : pointer to ethernet interface network device structure | |
730 | * Output : N/A | |
731 | */ | |
732 | static void mv643xx_eth_update_mac_address(struct net_device *dev) | |
733 | { | |
734 | struct mv643xx_private *mp = netdev_priv(dev); | |
1da177e4 | 735 | |
afdb57a2 LB |
736 | eth_port_init_mac_tables(mp); |
737 | eth_port_uc_addr_set(mp, dev->dev_addr); | |
1da177e4 LT |
738 | } |
739 | ||
740 | /* | |
741 | * mv643xx_eth_set_rx_mode | |
742 | * | |
743 | * Change from promiscuos to regular rx mode | |
744 | * | |
745 | * Input : pointer to ethernet interface network device structure | |
746 | * Output : N/A | |
747 | */ | |
748 | static void mv643xx_eth_set_rx_mode(struct net_device *dev) | |
749 | { | |
750 | struct mv643xx_private *mp = netdev_priv(dev); | |
01999873 | 751 | u32 config_reg; |
1da177e4 | 752 | |
ec69d651 | 753 | config_reg = rdl(mp, PORT_CONFIG_REG(mp->port_num)); |
1da177e4 | 754 | if (dev->flags & IFF_PROMISC) |
e4d00fa9 | 755 | config_reg |= (u32) UNICAST_PROMISCUOUS_MODE; |
1da177e4 | 756 | else |
e4d00fa9 | 757 | config_reg &= ~(u32) UNICAST_PROMISCUOUS_MODE; |
ec69d651 | 758 | wrl(mp, PORT_CONFIG_REG(mp->port_num), config_reg); |
16e03018 DF |
759 | |
760 | eth_port_set_multicast_list(dev); | |
1da177e4 LT |
761 | } |
762 | ||
763 | /* | |
764 | * mv643xx_eth_set_mac_address | |
765 | * | |
766 | * Change the interface's mac address. | |
767 | * No special hardware thing should be done because interface is always | |
768 | * put in promiscuous mode. | |
769 | * | |
770 | * Input : pointer to ethernet interface network device structure and | |
771 | * a pointer to the designated entry to be added to the cache. | |
772 | * Output : zero upon success, negative upon failure | |
773 | */ | |
774 | static int mv643xx_eth_set_mac_address(struct net_device *dev, void *addr) | |
775 | { | |
776 | int i; | |
777 | ||
778 | for (i = 0; i < 6; i++) | |
779 | /* +2 is for the offset of the HW addr type */ | |
780 | dev->dev_addr[i] = ((unsigned char *)addr)[i + 2]; | |
781 | mv643xx_eth_update_mac_address(dev); | |
782 | return 0; | |
783 | } | |
784 | ||
785 | /* | |
786 | * mv643xx_eth_tx_timeout | |
787 | * | |
788 | * Called upon a timeout on transmitting a packet | |
789 | * | |
790 | * Input : pointer to ethernet interface network device structure. | |
791 | * Output : N/A | |
792 | */ | |
793 | static void mv643xx_eth_tx_timeout(struct net_device *dev) | |
794 | { | |
795 | struct mv643xx_private *mp = netdev_priv(dev); | |
796 | ||
797 | printk(KERN_INFO "%s: TX timeout ", dev->name); | |
798 | ||
799 | /* Do the reset outside of interrupt context */ | |
800 | schedule_work(&mp->tx_timeout_task); | |
801 | } | |
802 | ||
803 | /* | |
804 | * mv643xx_eth_tx_timeout_task | |
805 | * | |
806 | * Actual routine to reset the adapter when a timeout on Tx has occurred | |
807 | */ | |
91c7c568 | 808 | static void mv643xx_eth_tx_timeout_task(struct work_struct *ugly) |
1da177e4 | 809 | { |
91c7c568 AV |
810 | struct mv643xx_private *mp = container_of(ugly, struct mv643xx_private, |
811 | tx_timeout_task); | |
c0d0f2ca | 812 | struct net_device *dev = mp->dev; |
1da177e4 | 813 | |
94843566 DF |
814 | if (!netif_running(dev)) |
815 | return; | |
816 | ||
817 | netif_stop_queue(dev); | |
818 | ||
afdb57a2 | 819 | eth_port_reset(mp); |
ed9b5d45 | 820 | eth_port_start(dev); |
94843566 DF |
821 | |
822 | if (mp->tx_ring_size - mp->tx_desc_count >= MAX_DESCS_PER_SKB) | |
823 | netif_wake_queue(dev); | |
1da177e4 LT |
824 | } |
825 | ||
ff561eef DF |
826 | /** |
827 | * mv643xx_eth_free_tx_descs - Free the tx desc data for completed descriptors | |
1da177e4 | 828 | * |
ff561eef | 829 | * If force is non-zero, frees uncompleted descriptors as well |
1da177e4 | 830 | */ |
c0d0f2ca | 831 | static int mv643xx_eth_free_tx_descs(struct net_device *dev, int force) |
1da177e4 LT |
832 | { |
833 | struct mv643xx_private *mp = netdev_priv(dev); | |
ff561eef DF |
834 | struct eth_tx_desc *desc; |
835 | u32 cmd_sts; | |
836 | struct sk_buff *skb; | |
837 | unsigned long flags; | |
838 | int tx_index; | |
839 | dma_addr_t addr; | |
840 | int count; | |
841 | int released = 0; | |
1da177e4 | 842 | |
ff561eef DF |
843 | while (mp->tx_desc_count > 0) { |
844 | spin_lock_irqsave(&mp->lock, flags); | |
d344bff9 DF |
845 | |
846 | /* tx_desc_count might have changed before acquiring the lock */ | |
847 | if (mp->tx_desc_count <= 0) { | |
848 | spin_unlock_irqrestore(&mp->lock, flags); | |
849 | return released; | |
850 | } | |
851 | ||
ff561eef DF |
852 | tx_index = mp->tx_used_desc_q; |
853 | desc = &mp->p_tx_desc_area[tx_index]; | |
854 | cmd_sts = desc->cmd_sts; | |
855 | ||
856 | if (!force && (cmd_sts & ETH_BUFFER_OWNED_BY_DMA)) { | |
857 | spin_unlock_irqrestore(&mp->lock, flags); | |
858 | return released; | |
859 | } | |
860 | ||
861 | mp->tx_used_desc_q = (tx_index + 1) % mp->tx_ring_size; | |
862 | mp->tx_desc_count--; | |
863 | ||
864 | addr = desc->buf_ptr; | |
865 | count = desc->byte_cnt; | |
866 | skb = mp->tx_skb[tx_index]; | |
867 | if (skb) | |
868 | mp->tx_skb[tx_index] = NULL; | |
869 | ||
7303fde8 | 870 | if (cmd_sts & ETH_ERROR_SUMMARY) { |
1da177e4 | 871 | printk("%s: Error in TX\n", dev->name); |
09f75cd7 | 872 | dev->stats.tx_errors++; |
1da177e4 LT |
873 | } |
874 | ||
d344bff9 DF |
875 | spin_unlock_irqrestore(&mp->lock, flags); |
876 | ||
ff561eef DF |
877 | if (cmd_sts & ETH_TX_FIRST_DESC) |
878 | dma_unmap_single(NULL, addr, count, DMA_TO_DEVICE); | |
cb415d30 | 879 | else |
ff561eef | 880 | dma_unmap_page(NULL, addr, count, DMA_TO_DEVICE); |
1da177e4 | 881 | |
ff561eef DF |
882 | if (skb) |
883 | dev_kfree_skb_irq(skb); | |
884 | ||
885 | released = 1; | |
1da177e4 LT |
886 | } |
887 | ||
1da177e4 LT |
888 | return released; |
889 | } | |
890 | ||
ff561eef DF |
891 | static void mv643xx_eth_free_completed_tx_descs(struct net_device *dev) |
892 | { | |
893 | struct mv643xx_private *mp = netdev_priv(dev); | |
894 | ||
895 | if (mv643xx_eth_free_tx_descs(dev, 0) && | |
896 | mp->tx_ring_size - mp->tx_desc_count >= MAX_DESCS_PER_SKB) | |
897 | netif_wake_queue(dev); | |
898 | } | |
899 | ||
900 | static void mv643xx_eth_free_all_tx_descs(struct net_device *dev) | |
901 | { | |
902 | mv643xx_eth_free_tx_descs(dev, 1); | |
903 | } | |
904 | ||
1da177e4 LT |
905 | /* |
906 | * mv643xx_eth_receive | |
907 | * | |
908 | * This function is forward packets that are received from the port's | |
909 | * queues toward kernel core or FastRoute them to another interface. | |
910 | * | |
911 | * Input : dev - a pointer to the required interface | |
912 | * max - maximum number to receive (0 means unlimted) | |
913 | * | |
914 | * Output : number of served packets | |
915 | */ | |
1da177e4 | 916 | static int mv643xx_eth_receive_queue(struct net_device *dev, int budget) |
1da177e4 LT |
917 | { |
918 | struct mv643xx_private *mp = netdev_priv(dev); | |
09f75cd7 | 919 | struct net_device_stats *stats = &dev->stats; |
1da177e4 LT |
920 | unsigned int received_packets = 0; |
921 | struct sk_buff *skb; | |
922 | struct pkt_info pkt_info; | |
923 | ||
b1dd9ca1 | 924 | while (budget-- > 0 && eth_port_receive(mp, &pkt_info) == ETH_OK) { |
54caf44d | 925 | dma_unmap_single(NULL, pkt_info.buf_ptr, ETH_RX_SKB_SIZE, |
71d28725 | 926 | DMA_FROM_DEVICE); |
f98e36f1 | 927 | mp->rx_desc_count--; |
1da177e4 | 928 | received_packets++; |
b1dd9ca1 | 929 | |
468d09f8 DF |
930 | /* |
931 | * Update statistics. | |
932 | * Note byte count includes 4 byte CRC count | |
933 | */ | |
1da177e4 LT |
934 | stats->rx_packets++; |
935 | stats->rx_bytes += pkt_info.byte_cnt; | |
936 | skb = pkt_info.return_info; | |
937 | /* | |
938 | * In case received a packet without first / last bits on OR | |
939 | * the error summary bit is on, the packets needs to be dropeed. | |
940 | */ | |
941 | if (((pkt_info.cmd_sts | |
942 | & (ETH_RX_FIRST_DESC | ETH_RX_LAST_DESC)) != | |
943 | (ETH_RX_FIRST_DESC | ETH_RX_LAST_DESC)) | |
944 | || (pkt_info.cmd_sts & ETH_ERROR_SUMMARY)) { | |
945 | stats->rx_dropped++; | |
946 | if ((pkt_info.cmd_sts & (ETH_RX_FIRST_DESC | | |
947 | ETH_RX_LAST_DESC)) != | |
948 | (ETH_RX_FIRST_DESC | ETH_RX_LAST_DESC)) { | |
949 | if (net_ratelimit()) | |
950 | printk(KERN_ERR | |
951 | "%s: Received packet spread " | |
952 | "on multiple descriptors\n", | |
953 | dev->name); | |
954 | } | |
955 | if (pkt_info.cmd_sts & ETH_ERROR_SUMMARY) | |
956 | stats->rx_errors++; | |
957 | ||
958 | dev_kfree_skb_irq(skb); | |
959 | } else { | |
960 | /* | |
961 | * The -4 is for the CRC in the trailer of the | |
962 | * received packet | |
963 | */ | |
964 | skb_put(skb, pkt_info.byte_cnt - 4); | |
1da177e4 LT |
965 | |
966 | if (pkt_info.cmd_sts & ETH_LAYER_4_CHECKSUM_OK) { | |
967 | skb->ip_summed = CHECKSUM_UNNECESSARY; | |
968 | skb->csum = htons( | |
969 | (pkt_info.cmd_sts & 0x0007fff8) >> 3); | |
970 | } | |
971 | skb->protocol = eth_type_trans(skb, dev); | |
972 | #ifdef MV643XX_NAPI | |
973 | netif_receive_skb(skb); | |
974 | #else | |
975 | netif_rx(skb); | |
976 | #endif | |
977 | } | |
12ad74f8 | 978 | dev->last_rx = jiffies; |
1da177e4 | 979 | } |
f78fb474 | 980 | mv643xx_eth_rx_refill_descs(dev); /* Fill RX ring with skb's */ |
1da177e4 LT |
981 | |
982 | return received_packets; | |
983 | } | |
984 | ||
d0412d96 JC |
985 | /* Set the mv643xx port configuration register for the speed/duplex mode. */ |
986 | static void mv643xx_eth_update_pscr(struct net_device *dev, | |
987 | struct ethtool_cmd *ecmd) | |
988 | { | |
989 | struct mv643xx_private *mp = netdev_priv(dev); | |
990 | int port_num = mp->port_num; | |
991 | u32 o_pscr, n_pscr; | |
12a87c64 | 992 | unsigned int queues; |
d0412d96 | 993 | |
ec69d651 | 994 | o_pscr = rdl(mp, PORT_SERIAL_CONTROL_REG(port_num)); |
d0412d96 JC |
995 | n_pscr = o_pscr; |
996 | ||
997 | /* clear speed, duplex and rx buffer size fields */ | |
e4d00fa9 LB |
998 | n_pscr &= ~(SET_MII_SPEED_TO_100 | |
999 | SET_GMII_SPEED_TO_1000 | | |
1000 | SET_FULL_DUPLEX_MODE | | |
1001 | MAX_RX_PACKET_MASK); | |
d0412d96 JC |
1002 | |
1003 | if (ecmd->duplex == DUPLEX_FULL) | |
e4d00fa9 | 1004 | n_pscr |= SET_FULL_DUPLEX_MODE; |
d0412d96 JC |
1005 | |
1006 | if (ecmd->speed == SPEED_1000) | |
e4d00fa9 LB |
1007 | n_pscr |= SET_GMII_SPEED_TO_1000 | |
1008 | MAX_RX_PACKET_9700BYTE; | |
d0412d96 JC |
1009 | else { |
1010 | if (ecmd->speed == SPEED_100) | |
e4d00fa9 LB |
1011 | n_pscr |= SET_MII_SPEED_TO_100; |
1012 | n_pscr |= MAX_RX_PACKET_1522BYTE; | |
d0412d96 JC |
1013 | } |
1014 | ||
1015 | if (n_pscr != o_pscr) { | |
e4d00fa9 | 1016 | if ((o_pscr & SERIAL_PORT_ENABLE) == 0) |
ec69d651 | 1017 | wrl(mp, PORT_SERIAL_CONTROL_REG(port_num), n_pscr); |
d0412d96 | 1018 | else { |
afdb57a2 | 1019 | queues = mv643xx_eth_port_disable_tx(mp); |
d0412d96 | 1020 | |
e4d00fa9 | 1021 | o_pscr &= ~SERIAL_PORT_ENABLE; |
ec69d651 LB |
1022 | wrl(mp, PORT_SERIAL_CONTROL_REG(port_num), o_pscr); |
1023 | wrl(mp, PORT_SERIAL_CONTROL_REG(port_num), n_pscr); | |
1024 | wrl(mp, PORT_SERIAL_CONTROL_REG(port_num), n_pscr); | |
12a87c64 | 1025 | if (queues) |
afdb57a2 | 1026 | mv643xx_eth_port_enable_tx(mp, queues); |
d0412d96 JC |
1027 | } |
1028 | } | |
1029 | } | |
1030 | ||
1da177e4 LT |
1031 | /* |
1032 | * mv643xx_eth_int_handler | |
1033 | * | |
1034 | * Main interrupt handler for the gigbit ethernet ports | |
1035 | * | |
1036 | * Input : irq - irq number (not used) | |
1037 | * dev_id - a pointer to the required interface's data structure | |
1038 | * regs - not used | |
1039 | * Output : N/A | |
1040 | */ | |
1041 | ||
7d12e780 | 1042 | static irqreturn_t mv643xx_eth_int_handler(int irq, void *dev_id) |
1da177e4 LT |
1043 | { |
1044 | struct net_device *dev = (struct net_device *)dev_id; | |
1045 | struct mv643xx_private *mp = netdev_priv(dev); | |
1046 | u32 eth_int_cause, eth_int_cause_ext = 0; | |
1047 | unsigned int port_num = mp->port_num; | |
1048 | ||
1049 | /* Read interrupt cause registers */ | |
ec69d651 | 1050 | eth_int_cause = rdl(mp, INTERRUPT_CAUSE_REG(port_num)) & |
7303fde8 | 1051 | ETH_INT_UNMASK_ALL; |
468d09f8 | 1052 | if (eth_int_cause & ETH_INT_CAUSE_EXT) { |
ec69d651 | 1053 | eth_int_cause_ext = rdl(mp, |
e4d00fa9 | 1054 | INTERRUPT_CAUSE_EXTEND_REG(port_num)) & |
7303fde8 | 1055 | ETH_INT_UNMASK_ALL_EXT; |
ec69d651 | 1056 | wrl(mp, INTERRUPT_CAUSE_EXTEND_REG(port_num), |
468d09f8 | 1057 | ~eth_int_cause_ext); |
1da177e4 | 1058 | } |
7303fde8 | 1059 | |
1da177e4 | 1060 | /* PHY status changed */ |
2bcff60f | 1061 | if (eth_int_cause_ext & (ETH_INT_CAUSE_PHY | ETH_INT_CAUSE_STATE)) { |
d0412d96 JC |
1062 | struct ethtool_cmd cmd; |
1063 | ||
c28a4f89 | 1064 | if (mii_link_ok(&mp->mii)) { |
d0412d96 JC |
1065 | mii_ethtool_gset(&mp->mii, &cmd); |
1066 | mv643xx_eth_update_pscr(dev, &cmd); | |
afdb57a2 | 1067 | mv643xx_eth_port_enable_tx(mp, ETH_TX_QUEUES_ENABLED); |
c28a4f89 JC |
1068 | if (!netif_carrier_ok(dev)) { |
1069 | netif_carrier_on(dev); | |
ff561eef DF |
1070 | if (mp->tx_ring_size - mp->tx_desc_count >= |
1071 | MAX_DESCS_PER_SKB) | |
d0412d96 | 1072 | netif_wake_queue(dev); |
c28a4f89 JC |
1073 | } |
1074 | } else if (netif_carrier_ok(dev)) { | |
1da177e4 | 1075 | netif_stop_queue(dev); |
c28a4f89 | 1076 | netif_carrier_off(dev); |
1da177e4 LT |
1077 | } |
1078 | } | |
1079 | ||
468d09f8 DF |
1080 | #ifdef MV643XX_NAPI |
1081 | if (eth_int_cause & ETH_INT_CAUSE_RX) { | |
1082 | /* schedule the NAPI poll routine to maintain port */ | |
ec69d651 | 1083 | wrl(mp, INTERRUPT_MASK_REG(port_num), ETH_INT_MASK_ALL); |
e4d00fa9 | 1084 | |
468d09f8 | 1085 | /* wait for previous write to complete */ |
ec69d651 | 1086 | rdl(mp, INTERRUPT_MASK_REG(port_num)); |
468d09f8 | 1087 | |
bea3348e | 1088 | netif_rx_schedule(dev, &mp->napi); |
468d09f8 DF |
1089 | } |
1090 | #else | |
1091 | if (eth_int_cause & ETH_INT_CAUSE_RX) | |
1092 | mv643xx_eth_receive_queue(dev, INT_MAX); | |
5c537408 | 1093 | #endif |
468d09f8 DF |
1094 | if (eth_int_cause_ext & ETH_INT_CAUSE_TX) |
1095 | mv643xx_eth_free_completed_tx_descs(dev); | |
468d09f8 | 1096 | |
1da177e4 LT |
1097 | /* |
1098 | * If no real interrupt occured, exit. | |
1099 | * This can happen when using gigE interrupt coalescing mechanism. | |
1100 | */ | |
1101 | if ((eth_int_cause == 0x0) && (eth_int_cause_ext == 0x0)) | |
1102 | return IRQ_NONE; | |
1103 | ||
1104 | return IRQ_HANDLED; | |
1105 | } | |
1106 | ||
1107 | #ifdef MV643XX_COAL | |
1108 | ||
1109 | /* | |
1110 | * eth_port_set_rx_coal - Sets coalescing interrupt mechanism on RX path | |
1111 | * | |
1112 | * DESCRIPTION: | |
1113 | * This routine sets the RX coalescing interrupt mechanism parameter. | |
1114 | * This parameter is a timeout counter, that counts in 64 t_clk | |
1115 | * chunks ; that when timeout event occurs a maskable interrupt | |
1116 | * occurs. | |
1117 | * The parameter is calculated using the tClk of the MV-643xx chip | |
1118 | * , and the required delay of the interrupt in usec. | |
1119 | * | |
1120 | * INPUT: | |
afdb57a2 | 1121 | * struct mv643xx_private *mp Ethernet port |
1da177e4 LT |
1122 | * unsigned int t_clk t_clk of the MV-643xx chip in HZ units |
1123 | * unsigned int delay Delay in usec | |
1124 | * | |
1125 | * OUTPUT: | |
1126 | * Interrupt coalescing mechanism value is set in MV-643xx chip. | |
1127 | * | |
1128 | * RETURN: | |
1129 | * The interrupt coalescing value set in the gigE port. | |
1130 | * | |
1131 | */ | |
afdb57a2 | 1132 | static unsigned int eth_port_set_rx_coal(struct mv643xx_private *mp, |
1da177e4 LT |
1133 | unsigned int t_clk, unsigned int delay) |
1134 | { | |
afdb57a2 | 1135 | unsigned int port_num = mp->port_num; |
1da177e4 LT |
1136 | unsigned int coal = ((t_clk / 1000000) * delay) / 64; |
1137 | ||
1138 | /* Set RX Coalescing mechanism */ | |
ec69d651 | 1139 | wrl(mp, SDMA_CONFIG_REG(port_num), |
1da177e4 | 1140 | ((coal & 0x3fff) << 8) | |
ec69d651 | 1141 | (rdl(mp, SDMA_CONFIG_REG(port_num)) |
1da177e4 LT |
1142 | & 0xffc000ff)); |
1143 | ||
1144 | return coal; | |
1145 | } | |
1146 | #endif | |
1147 | ||
1148 | /* | |
1149 | * eth_port_set_tx_coal - Sets coalescing interrupt mechanism on TX path | |
1150 | * | |
1151 | * DESCRIPTION: | |
1152 | * This routine sets the TX coalescing interrupt mechanism parameter. | |
1153 | * This parameter is a timeout counter, that counts in 64 t_clk | |
1154 | * chunks ; that when timeout event occurs a maskable interrupt | |
1155 | * occurs. | |
1156 | * The parameter is calculated using the t_cLK frequency of the | |
1157 | * MV-643xx chip and the required delay in the interrupt in uSec | |
1158 | * | |
1159 | * INPUT: | |
afdb57a2 | 1160 | * struct mv643xx_private *mp Ethernet port |
1da177e4 LT |
1161 | * unsigned int t_clk t_clk of the MV-643xx chip in HZ units |
1162 | * unsigned int delay Delay in uSeconds | |
1163 | * | |
1164 | * OUTPUT: | |
1165 | * Interrupt coalescing mechanism value is set in MV-643xx chip. | |
1166 | * | |
1167 | * RETURN: | |
1168 | * The interrupt coalescing value set in the gigE port. | |
1169 | * | |
1170 | */ | |
afdb57a2 | 1171 | static unsigned int eth_port_set_tx_coal(struct mv643xx_private *mp, |
1da177e4 LT |
1172 | unsigned int t_clk, unsigned int delay) |
1173 | { | |
afdb57a2 LB |
1174 | unsigned int coal = ((t_clk / 1000000) * delay) / 64; |
1175 | ||
1da177e4 | 1176 | /* Set TX Coalescing mechanism */ |
ec69d651 | 1177 | wrl(mp, TX_FIFO_URGENT_THRESHOLD_REG(mp->port_num), coal << 4); |
afdb57a2 | 1178 | |
1da177e4 LT |
1179 | return coal; |
1180 | } | |
1181 | ||
1da177e4 LT |
1182 | /* |
1183 | * ether_init_rx_desc_ring - Curve a Rx chain desc list and buffer in memory. | |
1184 | * | |
1185 | * DESCRIPTION: | |
1186 | * This function prepares a Rx chained list of descriptors and packet | |
1187 | * buffers in a form of a ring. The routine must be called after port | |
1188 | * initialization routine and before port start routine. | |
1189 | * The Ethernet SDMA engine uses CPU bus addresses to access the various | |
1190 | * devices in the system (i.e. DRAM). This function uses the ethernet | |
1191 | * struct 'virtual to physical' routine (set by the user) to set the ring | |
1192 | * with physical addresses. | |
1193 | * | |
1194 | * INPUT: | |
1195 | * struct mv643xx_private *mp Ethernet Port Control srtuct. | |
1196 | * | |
1197 | * OUTPUT: | |
1198 | * The routine updates the Ethernet port control struct with information | |
1199 | * regarding the Rx descriptors and buffers. | |
1200 | * | |
1201 | * RETURN: | |
1202 | * None. | |
1203 | */ | |
1204 | static void ether_init_rx_desc_ring(struct mv643xx_private *mp) | |
1205 | { | |
1206 | volatile struct eth_rx_desc *p_rx_desc; | |
1207 | int rx_desc_num = mp->rx_ring_size; | |
1208 | int i; | |
1209 | ||
1210 | /* initialize the next_desc_ptr links in the Rx descriptors ring */ | |
1211 | p_rx_desc = (struct eth_rx_desc *)mp->p_rx_desc_area; | |
1212 | for (i = 0; i < rx_desc_num; i++) { | |
1213 | p_rx_desc[i].next_desc_ptr = mp->rx_desc_dma + | |
1214 | ((i + 1) % rx_desc_num) * sizeof(struct eth_rx_desc); | |
1215 | } | |
1216 | ||
1217 | /* Save Rx desc pointer to driver struct. */ | |
1218 | mp->rx_curr_desc_q = 0; | |
1219 | mp->rx_used_desc_q = 0; | |
1220 | ||
1221 | mp->rx_desc_area_size = rx_desc_num * sizeof(struct eth_rx_desc); | |
1da177e4 LT |
1222 | } |
1223 | ||
1224 | /* | |
1225 | * ether_init_tx_desc_ring - Curve a Tx chain desc list and buffer in memory. | |
1226 | * | |
1227 | * DESCRIPTION: | |
1228 | * This function prepares a Tx chained list of descriptors and packet | |
1229 | * buffers in a form of a ring. The routine must be called after port | |
1230 | * initialization routine and before port start routine. | |
1231 | * The Ethernet SDMA engine uses CPU bus addresses to access the various | |
1232 | * devices in the system (i.e. DRAM). This function uses the ethernet | |
1233 | * struct 'virtual to physical' routine (set by the user) to set the ring | |
1234 | * with physical addresses. | |
1235 | * | |
1236 | * INPUT: | |
1237 | * struct mv643xx_private *mp Ethernet Port Control srtuct. | |
1238 | * | |
1239 | * OUTPUT: | |
1240 | * The routine updates the Ethernet port control struct with information | |
1241 | * regarding the Tx descriptors and buffers. | |
1242 | * | |
1243 | * RETURN: | |
1244 | * None. | |
1245 | */ | |
1246 | static void ether_init_tx_desc_ring(struct mv643xx_private *mp) | |
1247 | { | |
1248 | int tx_desc_num = mp->tx_ring_size; | |
1249 | struct eth_tx_desc *p_tx_desc; | |
1250 | int i; | |
1251 | ||
1252 | /* Initialize the next_desc_ptr links in the Tx descriptors ring */ | |
1253 | p_tx_desc = (struct eth_tx_desc *)mp->p_tx_desc_area; | |
1254 | for (i = 0; i < tx_desc_num; i++) { | |
1255 | p_tx_desc[i].next_desc_ptr = mp->tx_desc_dma + | |
1256 | ((i + 1) % tx_desc_num) * sizeof(struct eth_tx_desc); | |
1257 | } | |
1258 | ||
1259 | mp->tx_curr_desc_q = 0; | |
1260 | mp->tx_used_desc_q = 0; | |
1da177e4 LT |
1261 | |
1262 | mp->tx_desc_area_size = tx_desc_num * sizeof(struct eth_tx_desc); | |
1da177e4 LT |
1263 | } |
1264 | ||
d0412d96 JC |
1265 | static int mv643xx_set_settings(struct net_device *dev, struct ethtool_cmd *cmd) |
1266 | { | |
1267 | struct mv643xx_private *mp = netdev_priv(dev); | |
1268 | int err; | |
1269 | ||
1270 | spin_lock_irq(&mp->lock); | |
1271 | err = mii_ethtool_sset(&mp->mii, cmd); | |
1272 | spin_unlock_irq(&mp->lock); | |
1273 | ||
1274 | return err; | |
1275 | } | |
1276 | ||
1277 | static int mv643xx_get_settings(struct net_device *dev, struct ethtool_cmd *cmd) | |
1278 | { | |
1279 | struct mv643xx_private *mp = netdev_priv(dev); | |
1280 | int err; | |
1281 | ||
1282 | spin_lock_irq(&mp->lock); | |
1283 | err = mii_ethtool_gset(&mp->mii, cmd); | |
1284 | spin_unlock_irq(&mp->lock); | |
1285 | ||
1286 | /* The PHY may support 1000baseT_Half, but the mv643xx does not */ | |
1287 | cmd->supported &= ~SUPPORTED_1000baseT_Half; | |
1288 | cmd->advertising &= ~ADVERTISED_1000baseT_Half; | |
1289 | ||
1290 | return err; | |
1291 | } | |
1292 | ||
ab4384a6 DF |
1293 | /* |
1294 | * mv643xx_eth_open | |
1295 | * | |
1296 | * This function is called when openning the network device. The function | |
1297 | * should initialize all the hardware, initialize cyclic Rx/Tx | |
1298 | * descriptors chain and buffers and allocate an IRQ to the network | |
1299 | * device. | |
1300 | * | |
1301 | * Input : a pointer to the network device structure | |
1302 | * | |
1303 | * Output : zero of success , nonzero if fails. | |
1304 | */ | |
1305 | ||
1306 | static int mv643xx_eth_open(struct net_device *dev) | |
1da177e4 LT |
1307 | { |
1308 | struct mv643xx_private *mp = netdev_priv(dev); | |
1309 | unsigned int port_num = mp->port_num; | |
1310 | unsigned int size; | |
ab4384a6 DF |
1311 | int err; |
1312 | ||
85cf572c | 1313 | /* Clear any pending ethernet port interrupts */ |
ec69d651 LB |
1314 | wrl(mp, INTERRUPT_CAUSE_REG(port_num), 0); |
1315 | wrl(mp, INTERRUPT_CAUSE_EXTEND_REG(port_num), 0); | |
85cf572c | 1316 | /* wait for previous write to complete */ |
ec69d651 | 1317 | rdl(mp, INTERRUPT_CAUSE_EXTEND_REG(port_num)); |
85cf572c | 1318 | |
ab4384a6 | 1319 | err = request_irq(dev->irq, mv643xx_eth_int_handler, |
1fb9df5d | 1320 | IRQF_SHARED | IRQF_SAMPLE_RANDOM, dev->name, dev); |
ab4384a6 | 1321 | if (err) { |
c1b35a28 | 1322 | printk(KERN_ERR "%s: Can not assign IRQ\n", dev->name); |
ab4384a6 DF |
1323 | return -EAGAIN; |
1324 | } | |
1da177e4 | 1325 | |
1da177e4 LT |
1326 | eth_port_init(mp); |
1327 | ||
1da177e4 | 1328 | memset(&mp->timeout, 0, sizeof(struct timer_list)); |
f78fb474 | 1329 | mp->timeout.function = mv643xx_eth_rx_refill_descs_timer_wrapper; |
1da177e4 LT |
1330 | mp->timeout.data = (unsigned long)dev; |
1331 | ||
1da177e4 LT |
1332 | /* Allocate RX and TX skb rings */ |
1333 | mp->rx_skb = kmalloc(sizeof(*mp->rx_skb) * mp->rx_ring_size, | |
1334 | GFP_KERNEL); | |
1335 | if (!mp->rx_skb) { | |
1336 | printk(KERN_ERR "%s: Cannot allocate Rx skb ring\n", dev->name); | |
ab4384a6 DF |
1337 | err = -ENOMEM; |
1338 | goto out_free_irq; | |
1da177e4 LT |
1339 | } |
1340 | mp->tx_skb = kmalloc(sizeof(*mp->tx_skb) * mp->tx_ring_size, | |
1341 | GFP_KERNEL); | |
1342 | if (!mp->tx_skb) { | |
1343 | printk(KERN_ERR "%s: Cannot allocate Tx skb ring\n", dev->name); | |
ab4384a6 DF |
1344 | err = -ENOMEM; |
1345 | goto out_free_rx_skb; | |
1da177e4 LT |
1346 | } |
1347 | ||
1348 | /* Allocate TX ring */ | |
f98e36f1 | 1349 | mp->tx_desc_count = 0; |
1da177e4 LT |
1350 | size = mp->tx_ring_size * sizeof(struct eth_tx_desc); |
1351 | mp->tx_desc_area_size = size; | |
1352 | ||
1353 | if (mp->tx_sram_size) { | |
1354 | mp->p_tx_desc_area = ioremap(mp->tx_sram_addr, | |
1355 | mp->tx_sram_size); | |
1356 | mp->tx_desc_dma = mp->tx_sram_addr; | |
1357 | } else | |
1358 | mp->p_tx_desc_area = dma_alloc_coherent(NULL, size, | |
1359 | &mp->tx_desc_dma, | |
1360 | GFP_KERNEL); | |
1361 | ||
1362 | if (!mp->p_tx_desc_area) { | |
1363 | printk(KERN_ERR "%s: Cannot allocate Tx Ring (size %d bytes)\n", | |
1364 | dev->name, size); | |
ab4384a6 DF |
1365 | err = -ENOMEM; |
1366 | goto out_free_tx_skb; | |
1da177e4 LT |
1367 | } |
1368 | BUG_ON((u32) mp->p_tx_desc_area & 0xf); /* check 16-byte alignment */ | |
1369 | memset((void *)mp->p_tx_desc_area, 0, mp->tx_desc_area_size); | |
1370 | ||
1371 | ether_init_tx_desc_ring(mp); | |
1372 | ||
1373 | /* Allocate RX ring */ | |
f98e36f1 | 1374 | mp->rx_desc_count = 0; |
1da177e4 LT |
1375 | size = mp->rx_ring_size * sizeof(struct eth_rx_desc); |
1376 | mp->rx_desc_area_size = size; | |
1377 | ||
1378 | if (mp->rx_sram_size) { | |
1379 | mp->p_rx_desc_area = ioremap(mp->rx_sram_addr, | |
1380 | mp->rx_sram_size); | |
1381 | mp->rx_desc_dma = mp->rx_sram_addr; | |
1382 | } else | |
1383 | mp->p_rx_desc_area = dma_alloc_coherent(NULL, size, | |
1384 | &mp->rx_desc_dma, | |
1385 | GFP_KERNEL); | |
1386 | ||
1387 | if (!mp->p_rx_desc_area) { | |
1388 | printk(KERN_ERR "%s: Cannot allocate Rx ring (size %d bytes)\n", | |
1389 | dev->name, size); | |
1390 | printk(KERN_ERR "%s: Freeing previously allocated TX queues...", | |
1391 | dev->name); | |
1392 | if (mp->rx_sram_size) | |
dd09b1de | 1393 | iounmap(mp->p_tx_desc_area); |
1da177e4 LT |
1394 | else |
1395 | dma_free_coherent(NULL, mp->tx_desc_area_size, | |
1396 | mp->p_tx_desc_area, mp->tx_desc_dma); | |
ab4384a6 DF |
1397 | err = -ENOMEM; |
1398 | goto out_free_tx_skb; | |
1da177e4 LT |
1399 | } |
1400 | memset((void *)mp->p_rx_desc_area, 0, size); | |
1401 | ||
1402 | ether_init_rx_desc_ring(mp); | |
1403 | ||
f78fb474 | 1404 | mv643xx_eth_rx_refill_descs(dev); /* Fill RX ring with skb's */ |
1da177e4 | 1405 | |
bea3348e SH |
1406 | #ifdef MV643XX_NAPI |
1407 | napi_enable(&mp->napi); | |
1408 | #endif | |
1409 | ||
ed9b5d45 | 1410 | eth_port_start(dev); |
1da177e4 LT |
1411 | |
1412 | /* Interrupt Coalescing */ | |
1413 | ||
1414 | #ifdef MV643XX_COAL | |
1415 | mp->rx_int_coal = | |
afdb57a2 | 1416 | eth_port_set_rx_coal(mp, 133000000, MV643XX_RX_COAL); |
1da177e4 LT |
1417 | #endif |
1418 | ||
1419 | mp->tx_int_coal = | |
afdb57a2 | 1420 | eth_port_set_tx_coal(mp, 133000000, MV643XX_TX_COAL); |
1da177e4 | 1421 | |
8f518703 | 1422 | /* Unmask phy and link status changes interrupts */ |
ec69d651 | 1423 | wrl(mp, INTERRUPT_EXTEND_MASK_REG(port_num), ETH_INT_UNMASK_ALL_EXT); |
1da177e4 | 1424 | |
8f518703 | 1425 | /* Unmask RX buffer and TX end interrupt */ |
ec69d651 | 1426 | wrl(mp, INTERRUPT_MASK_REG(port_num), ETH_INT_UNMASK_ALL); |
d0412d96 | 1427 | |
1da177e4 | 1428 | return 0; |
ab4384a6 DF |
1429 | |
1430 | out_free_tx_skb: | |
1431 | kfree(mp->tx_skb); | |
1432 | out_free_rx_skb: | |
1433 | kfree(mp->rx_skb); | |
1434 | out_free_irq: | |
1435 | free_irq(dev->irq, dev); | |
1436 | ||
1437 | return err; | |
1da177e4 LT |
1438 | } |
1439 | ||
1440 | static void mv643xx_eth_free_tx_rings(struct net_device *dev) | |
1441 | { | |
1442 | struct mv643xx_private *mp = netdev_priv(dev); | |
1da177e4 LT |
1443 | |
1444 | /* Stop Tx Queues */ | |
afdb57a2 | 1445 | mv643xx_eth_port_disable_tx(mp); |
1da177e4 | 1446 | |
ff561eef DF |
1447 | /* Free outstanding skb's on TX ring */ |
1448 | mv643xx_eth_free_all_tx_descs(dev); | |
1449 | ||
1450 | BUG_ON(mp->tx_used_desc_q != mp->tx_curr_desc_q); | |
1da177e4 LT |
1451 | |
1452 | /* Free TX ring */ | |
1453 | if (mp->tx_sram_size) | |
1454 | iounmap(mp->p_tx_desc_area); | |
1455 | else | |
1456 | dma_free_coherent(NULL, mp->tx_desc_area_size, | |
1457 | mp->p_tx_desc_area, mp->tx_desc_dma); | |
1458 | } | |
1459 | ||
1460 | static void mv643xx_eth_free_rx_rings(struct net_device *dev) | |
1461 | { | |
1462 | struct mv643xx_private *mp = netdev_priv(dev); | |
1da177e4 LT |
1463 | int curr; |
1464 | ||
1465 | /* Stop RX Queues */ | |
afdb57a2 | 1466 | mv643xx_eth_port_disable_rx(mp); |
1da177e4 LT |
1467 | |
1468 | /* Free preallocated skb's on RX rings */ | |
f98e36f1 | 1469 | for (curr = 0; mp->rx_desc_count && curr < mp->rx_ring_size; curr++) { |
1da177e4 LT |
1470 | if (mp->rx_skb[curr]) { |
1471 | dev_kfree_skb(mp->rx_skb[curr]); | |
f98e36f1 | 1472 | mp->rx_desc_count--; |
1da177e4 LT |
1473 | } |
1474 | } | |
1475 | ||
f98e36f1 | 1476 | if (mp->rx_desc_count) |
1da177e4 LT |
1477 | printk(KERN_ERR |
1478 | "%s: Error in freeing Rx Ring. %d skb's still" | |
1479 | " stuck in RX Ring - ignoring them\n", dev->name, | |
f98e36f1 | 1480 | mp->rx_desc_count); |
1da177e4 LT |
1481 | /* Free RX ring */ |
1482 | if (mp->rx_sram_size) | |
1483 | iounmap(mp->p_rx_desc_area); | |
1484 | else | |
1485 | dma_free_coherent(NULL, mp->rx_desc_area_size, | |
1486 | mp->p_rx_desc_area, mp->rx_desc_dma); | |
1487 | } | |
1488 | ||
1489 | /* | |
1490 | * mv643xx_eth_stop | |
1491 | * | |
1492 | * This function is used when closing the network device. | |
1493 | * It updates the hardware, | |
1494 | * release all memory that holds buffers and descriptors and release the IRQ. | |
1495 | * Input : a pointer to the device structure | |
1496 | * Output : zero if success , nonzero if fails | |
1497 | */ | |
1498 | ||
ab4384a6 | 1499 | static int mv643xx_eth_stop(struct net_device *dev) |
1da177e4 LT |
1500 | { |
1501 | struct mv643xx_private *mp = netdev_priv(dev); | |
1502 | unsigned int port_num = mp->port_num; | |
1503 | ||
c2e5b352 | 1504 | /* Mask all interrupts on ethernet port */ |
ec69d651 | 1505 | wrl(mp, INTERRUPT_MASK_REG(port_num), ETH_INT_MASK_ALL); |
c2e5b352 | 1506 | /* wait for previous write to complete */ |
ec69d651 | 1507 | rdl(mp, INTERRUPT_MASK_REG(port_num)); |
8f518703 DF |
1508 | |
1509 | #ifdef MV643XX_NAPI | |
bea3348e | 1510 | napi_disable(&mp->napi); |
8f518703 | 1511 | #endif |
1da177e4 LT |
1512 | netif_carrier_off(dev); |
1513 | netif_stop_queue(dev); | |
1514 | ||
afdb57a2 | 1515 | eth_port_reset(mp); |
1da177e4 | 1516 | |
8f518703 DF |
1517 | mv643xx_eth_free_tx_rings(dev); |
1518 | mv643xx_eth_free_rx_rings(dev); | |
1da177e4 | 1519 | |
1da177e4 | 1520 | free_irq(dev->irq, dev); |
1da177e4 LT |
1521 | |
1522 | return 0; | |
1523 | } | |
1524 | ||
1525 | #ifdef MV643XX_NAPI | |
1da177e4 LT |
1526 | /* |
1527 | * mv643xx_poll | |
1528 | * | |
1529 | * This function is used in case of NAPI | |
1530 | */ | |
bea3348e | 1531 | static int mv643xx_poll(struct napi_struct *napi, int budget) |
1da177e4 | 1532 | { |
bea3348e SH |
1533 | struct mv643xx_private *mp = container_of(napi, struct mv643xx_private, napi); |
1534 | struct net_device *dev = mp->dev; | |
1da177e4 | 1535 | unsigned int port_num = mp->port_num; |
bea3348e | 1536 | int work_done; |
1da177e4 LT |
1537 | |
1538 | #ifdef MV643XX_TX_FAST_REFILL | |
1539 | if (++mp->tx_clean_threshold > 5) { | |
ff561eef | 1540 | mv643xx_eth_free_completed_tx_descs(dev); |
1da177e4 | 1541 | mp->tx_clean_threshold = 0; |
1da177e4 LT |
1542 | } |
1543 | #endif | |
1544 | ||
bea3348e | 1545 | work_done = 0; |
ec69d651 | 1546 | if ((rdl(mp, RX_CURRENT_QUEUE_DESC_PTR_0(port_num))) |
bea3348e SH |
1547 | != (u32) mp->rx_used_desc_q) |
1548 | work_done = mv643xx_eth_receive_queue(dev, budget); | |
1da177e4 | 1549 | |
bea3348e SH |
1550 | if (work_done < budget) { |
1551 | netif_rx_complete(dev, napi); | |
ec69d651 LB |
1552 | wrl(mp, INTERRUPT_CAUSE_REG(port_num), 0); |
1553 | wrl(mp, INTERRUPT_CAUSE_EXTEND_REG(port_num), 0); | |
1554 | wrl(mp, INTERRUPT_MASK_REG(port_num), ETH_INT_UNMASK_ALL); | |
1da177e4 LT |
1555 | } |
1556 | ||
bea3348e | 1557 | return work_done; |
1da177e4 LT |
1558 | } |
1559 | #endif | |
1560 | ||
c8aaea25 DF |
1561 | /** |
1562 | * has_tiny_unaligned_frags - check if skb has any small, unaligned fragments | |
1563 | * | |
1564 | * Hardware can't handle unaligned fragments smaller than 9 bytes. | |
f7ea3337 PJ |
1565 | * This helper function detects that case. |
1566 | */ | |
1567 | ||
1568 | static inline unsigned int has_tiny_unaligned_frags(struct sk_buff *skb) | |
1569 | { | |
b4de9051 DF |
1570 | unsigned int frag; |
1571 | skb_frag_t *fragp; | |
f7ea3337 | 1572 | |
b4de9051 DF |
1573 | for (frag = 0; frag < skb_shinfo(skb)->nr_frags; frag++) { |
1574 | fragp = &skb_shinfo(skb)->frags[frag]; | |
1575 | if (fragp->size <= 8 && fragp->page_offset & 0x7) | |
1576 | return 1; | |
1577 | } | |
1578 | return 0; | |
f7ea3337 PJ |
1579 | } |
1580 | ||
c8aaea25 DF |
1581 | /** |
1582 | * eth_alloc_tx_desc_index - return the index of the next available tx desc | |
1583 | */ | |
1584 | static int eth_alloc_tx_desc_index(struct mv643xx_private *mp) | |
1585 | { | |
1586 | int tx_desc_curr; | |
1587 | ||
c8aaea25 | 1588 | BUG_ON(mp->tx_desc_count >= mp->tx_ring_size); |
c8aaea25 | 1589 | |
ff561eef | 1590 | tx_desc_curr = mp->tx_curr_desc_q; |
c8aaea25 DF |
1591 | mp->tx_curr_desc_q = (tx_desc_curr + 1) % mp->tx_ring_size; |
1592 | ||
1593 | BUG_ON(mp->tx_curr_desc_q == mp->tx_used_desc_q); | |
1594 | ||
1595 | return tx_desc_curr; | |
1596 | } | |
1597 | ||
1598 | /** | |
1599 | * eth_tx_fill_frag_descs - fill tx hw descriptors for an skb's fragments. | |
1da177e4 | 1600 | * |
c8aaea25 DF |
1601 | * Ensure the data for each fragment to be transmitted is mapped properly, |
1602 | * then fill in descriptors in the tx hw queue. | |
1da177e4 | 1603 | */ |
c8aaea25 DF |
1604 | static void eth_tx_fill_frag_descs(struct mv643xx_private *mp, |
1605 | struct sk_buff *skb) | |
1da177e4 | 1606 | { |
c8aaea25 DF |
1607 | int frag; |
1608 | int tx_index; | |
1609 | struct eth_tx_desc *desc; | |
1da177e4 | 1610 | |
c8aaea25 DF |
1611 | for (frag = 0; frag < skb_shinfo(skb)->nr_frags; frag++) { |
1612 | skb_frag_t *this_frag = &skb_shinfo(skb)->frags[frag]; | |
1613 | ||
1614 | tx_index = eth_alloc_tx_desc_index(mp); | |
1615 | desc = &mp->p_tx_desc_area[tx_index]; | |
1616 | ||
1617 | desc->cmd_sts = ETH_BUFFER_OWNED_BY_DMA; | |
1618 | /* Last Frag enables interrupt and frees the skb */ | |
1619 | if (frag == (skb_shinfo(skb)->nr_frags - 1)) { | |
1620 | desc->cmd_sts |= ETH_ZERO_PADDING | | |
1621 | ETH_TX_LAST_DESC | | |
1622 | ETH_TX_ENABLE_INTERRUPT; | |
1623 | mp->tx_skb[tx_index] = skb; | |
1624 | } else | |
05980775 | 1625 | mp->tx_skb[tx_index] = NULL; |
c8aaea25 DF |
1626 | |
1627 | desc = &mp->p_tx_desc_area[tx_index]; | |
1628 | desc->l4i_chk = 0; | |
1629 | desc->byte_cnt = this_frag->size; | |
1630 | desc->buf_ptr = dma_map_page(NULL, this_frag->page, | |
1631 | this_frag->page_offset, | |
1632 | this_frag->size, | |
1633 | DMA_TO_DEVICE); | |
1da177e4 | 1634 | } |
c8aaea25 | 1635 | } |
1da177e4 | 1636 | |
324ff2c1 BB |
1637 | static inline __be16 sum16_as_be(__sum16 sum) |
1638 | { | |
1639 | return (__force __be16)sum; | |
1640 | } | |
1641 | ||
c8aaea25 DF |
1642 | /** |
1643 | * eth_tx_submit_descs_for_skb - submit data from an skb to the tx hw | |
1644 | * | |
1645 | * Ensure the data for an skb to be transmitted is mapped properly, | |
1646 | * then fill in descriptors in the tx hw queue and start the hardware. | |
1647 | */ | |
ff561eef DF |
1648 | static void eth_tx_submit_descs_for_skb(struct mv643xx_private *mp, |
1649 | struct sk_buff *skb) | |
c8aaea25 DF |
1650 | { |
1651 | int tx_index; | |
1652 | struct eth_tx_desc *desc; | |
1653 | u32 cmd_sts; | |
1654 | int length; | |
ff561eef | 1655 | int nr_frags = skb_shinfo(skb)->nr_frags; |
1da177e4 | 1656 | |
c8aaea25 | 1657 | cmd_sts = ETH_TX_FIRST_DESC | ETH_GEN_CRC | ETH_BUFFER_OWNED_BY_DMA; |
1da177e4 | 1658 | |
c8aaea25 DF |
1659 | tx_index = eth_alloc_tx_desc_index(mp); |
1660 | desc = &mp->p_tx_desc_area[tx_index]; | |
1661 | ||
ff561eef | 1662 | if (nr_frags) { |
c8aaea25 DF |
1663 | eth_tx_fill_frag_descs(mp, skb); |
1664 | ||
1665 | length = skb_headlen(skb); | |
05980775 | 1666 | mp->tx_skb[tx_index] = NULL; |
c8aaea25 DF |
1667 | } else { |
1668 | cmd_sts |= ETH_ZERO_PADDING | | |
1669 | ETH_TX_LAST_DESC | | |
1670 | ETH_TX_ENABLE_INTERRUPT; | |
1671 | length = skb->len; | |
1672 | mp->tx_skb[tx_index] = skb; | |
f7ea3337 PJ |
1673 | } |
1674 | ||
c8aaea25 DF |
1675 | desc->byte_cnt = length; |
1676 | desc->buf_ptr = dma_map_single(NULL, skb->data, length, DMA_TO_DEVICE); | |
1da177e4 | 1677 | |
84fa7933 | 1678 | if (skb->ip_summed == CHECKSUM_PARTIAL) { |
324ff2c1 | 1679 | BUG_ON(skb->protocol != htons(ETH_P_IP)); |
c8aaea25 DF |
1680 | |
1681 | cmd_sts |= ETH_GEN_TCP_UDP_CHECKSUM | | |
1682 | ETH_GEN_IP_V_4_CHECKSUM | | |
eddc9ec5 | 1683 | ip_hdr(skb)->ihl << ETH_TX_IHL_SHIFT; |
c8aaea25 | 1684 | |
eddc9ec5 | 1685 | switch (ip_hdr(skb)->protocol) { |
c8aaea25 DF |
1686 | case IPPROTO_UDP: |
1687 | cmd_sts |= ETH_UDP_FRAME; | |
324ff2c1 | 1688 | desc->l4i_chk = ntohs(sum16_as_be(udp_hdr(skb)->check)); |
c8aaea25 DF |
1689 | break; |
1690 | case IPPROTO_TCP: | |
324ff2c1 | 1691 | desc->l4i_chk = ntohs(sum16_as_be(tcp_hdr(skb)->check)); |
c8aaea25 DF |
1692 | break; |
1693 | default: | |
1694 | BUG(); | |
1da177e4 | 1695 | } |
1da177e4 | 1696 | } else { |
c8aaea25 DF |
1697 | /* Errata BTS #50, IHL must be 5 if no HW checksum */ |
1698 | cmd_sts |= 5 << ETH_TX_IHL_SHIFT; | |
1699 | desc->l4i_chk = 0; | |
1700 | } | |
1da177e4 | 1701 | |
c8aaea25 DF |
1702 | /* ensure all other descriptors are written before first cmd_sts */ |
1703 | wmb(); | |
1704 | desc->cmd_sts = cmd_sts; | |
1da177e4 | 1705 | |
c8aaea25 DF |
1706 | /* ensure all descriptors are written before poking hardware */ |
1707 | wmb(); | |
afdb57a2 | 1708 | mv643xx_eth_port_enable_tx(mp, ETH_TX_QUEUES_ENABLED); |
1da177e4 | 1709 | |
ff561eef | 1710 | mp->tx_desc_count += nr_frags + 1; |
c8aaea25 | 1711 | } |
1da177e4 | 1712 | |
c8aaea25 DF |
1713 | /** |
1714 | * mv643xx_eth_start_xmit - queue an skb to the hardware for transmission | |
1715 | * | |
1716 | */ | |
1717 | static int mv643xx_eth_start_xmit(struct sk_buff *skb, struct net_device *dev) | |
1718 | { | |
1719 | struct mv643xx_private *mp = netdev_priv(dev); | |
09f75cd7 | 1720 | struct net_device_stats *stats = &dev->stats; |
c8aaea25 | 1721 | unsigned long flags; |
1da177e4 | 1722 | |
c8aaea25 | 1723 | BUG_ON(netif_queue_stopped(dev)); |
94843566 | 1724 | |
4d64e718 LB |
1725 | if (has_tiny_unaligned_frags(skb) && __skb_linearize(skb)) { |
1726 | stats->tx_dropped++; | |
1727 | printk(KERN_DEBUG "%s: failed to linearize tiny " | |
1728 | "unaligned fragment\n", dev->name); | |
c0d0f2ca | 1729 | return NETDEV_TX_BUSY; |
4d64e718 LB |
1730 | } |
1731 | ||
1732 | spin_lock_irqsave(&mp->lock, flags); | |
1733 | ||
94843566 DF |
1734 | if (mp->tx_ring_size - mp->tx_desc_count < MAX_DESCS_PER_SKB) { |
1735 | printk(KERN_ERR "%s: transmit with queue full\n", dev->name); | |
1736 | netif_stop_queue(dev); | |
4d64e718 | 1737 | spin_unlock_irqrestore(&mp->lock, flags); |
c0d0f2ca | 1738 | return NETDEV_TX_BUSY; |
94843566 | 1739 | } |
1da177e4 | 1740 | |
ff561eef | 1741 | eth_tx_submit_descs_for_skb(mp, skb); |
e7e381f6 | 1742 | stats->tx_bytes += skb->len; |
1da177e4 LT |
1743 | stats->tx_packets++; |
1744 | dev->trans_start = jiffies; | |
1745 | ||
c8aaea25 DF |
1746 | if (mp->tx_ring_size - mp->tx_desc_count < MAX_DESCS_PER_SKB) |
1747 | netif_stop_queue(dev); | |
1748 | ||
1da177e4 LT |
1749 | spin_unlock_irqrestore(&mp->lock, flags); |
1750 | ||
c0d0f2ca | 1751 | return NETDEV_TX_OK; |
1da177e4 LT |
1752 | } |
1753 | ||
63c9e549 | 1754 | #ifdef CONFIG_NET_POLL_CONTROLLER |
63c9e549 DF |
1755 | static void mv643xx_netpoll(struct net_device *netdev) |
1756 | { | |
1757 | struct mv643xx_private *mp = netdev_priv(netdev); | |
c2e5b352 DF |
1758 | int port_num = mp->port_num; |
1759 | ||
ec69d651 | 1760 | wrl(mp, INTERRUPT_MASK_REG(port_num), ETH_INT_MASK_ALL); |
c2e5b352 | 1761 | /* wait for previous write to complete */ |
ec69d651 | 1762 | rdl(mp, INTERRUPT_MASK_REG(port_num)); |
63c9e549 | 1763 | |
9da3b1ad | 1764 | mv643xx_eth_int_handler(netdev->irq, netdev); |
c2e5b352 | 1765 | |
ec69d651 | 1766 | wrl(mp, INTERRUPT_MASK_REG(port_num), ETH_INT_UNMASK_ALL); |
63c9e549 DF |
1767 | } |
1768 | #endif | |
1769 | ||
d0412d96 JC |
1770 | static void mv643xx_init_ethtool_cmd(struct net_device *dev, int phy_address, |
1771 | int speed, int duplex, | |
1772 | struct ethtool_cmd *cmd) | |
1773 | { | |
1774 | struct mv643xx_private *mp = netdev_priv(dev); | |
1775 | ||
1776 | memset(cmd, 0, sizeof(*cmd)); | |
1777 | ||
1778 | cmd->port = PORT_MII; | |
1779 | cmd->transceiver = XCVR_INTERNAL; | |
1780 | cmd->phy_address = phy_address; | |
1781 | ||
1782 | if (speed == 0) { | |
1783 | cmd->autoneg = AUTONEG_ENABLE; | |
1784 | /* mii lib checks, but doesn't use speed on AUTONEG_ENABLE */ | |
1785 | cmd->speed = SPEED_100; | |
1786 | cmd->advertising = ADVERTISED_10baseT_Half | | |
1787 | ADVERTISED_10baseT_Full | | |
1788 | ADVERTISED_100baseT_Half | | |
1789 | ADVERTISED_100baseT_Full; | |
1790 | if (mp->mii.supports_gmii) | |
1791 | cmd->advertising |= ADVERTISED_1000baseT_Full; | |
1792 | } else { | |
1793 | cmd->autoneg = AUTONEG_DISABLE; | |
1794 | cmd->speed = speed; | |
1795 | cmd->duplex = duplex; | |
1796 | } | |
1797 | } | |
1798 | ||
1da177e4 LT |
1799 | /*/ |
1800 | * mv643xx_eth_probe | |
1801 | * | |
1802 | * First function called after registering the network device. | |
1803 | * It's purpose is to initialize the device as an ethernet device, | |
1804 | * fill the ethernet device structure with pointers * to functions, | |
1805 | * and set the MAC address of the interface | |
1806 | * | |
1807 | * Input : struct device * | |
1808 | * Output : -ENOMEM if failed , 0 if success | |
1809 | */ | |
3ae5eaec | 1810 | static int mv643xx_eth_probe(struct platform_device *pdev) |
1da177e4 | 1811 | { |
1da177e4 | 1812 | struct mv643xx_eth_platform_data *pd; |
84dd619e | 1813 | int port_num; |
1da177e4 LT |
1814 | struct mv643xx_private *mp; |
1815 | struct net_device *dev; | |
1816 | u8 *p; | |
1817 | struct resource *res; | |
1818 | int err; | |
d0412d96 | 1819 | struct ethtool_cmd cmd; |
01999873 DF |
1820 | int duplex = DUPLEX_HALF; |
1821 | int speed = 0; /* default to auto-negotiation */ | |
c5d6471f | 1822 | DECLARE_MAC_BUF(mac); |
1da177e4 | 1823 | |
84dd619e DF |
1824 | pd = pdev->dev.platform_data; |
1825 | if (pd == NULL) { | |
1826 | printk(KERN_ERR "No mv643xx_eth_platform_data\n"); | |
1827 | return -ENODEV; | |
1828 | } | |
1829 | ||
1da177e4 LT |
1830 | dev = alloc_etherdev(sizeof(struct mv643xx_private)); |
1831 | if (!dev) | |
1832 | return -ENOMEM; | |
1833 | ||
3ae5eaec | 1834 | platform_set_drvdata(pdev, dev); |
1da177e4 LT |
1835 | |
1836 | mp = netdev_priv(dev); | |
bea3348e SH |
1837 | mp->dev = dev; |
1838 | #ifdef MV643XX_NAPI | |
1839 | netif_napi_add(dev, &mp->napi, mv643xx_poll, 64); | |
1840 | #endif | |
1da177e4 LT |
1841 | |
1842 | res = platform_get_resource(pdev, IORESOURCE_IRQ, 0); | |
1843 | BUG_ON(!res); | |
1844 | dev->irq = res->start; | |
1845 | ||
1da177e4 LT |
1846 | dev->open = mv643xx_eth_open; |
1847 | dev->stop = mv643xx_eth_stop; | |
1848 | dev->hard_start_xmit = mv643xx_eth_start_xmit; | |
1da177e4 LT |
1849 | dev->set_mac_address = mv643xx_eth_set_mac_address; |
1850 | dev->set_multicast_list = mv643xx_eth_set_rx_mode; | |
1851 | ||
1852 | /* No need to Tx Timeout */ | |
1853 | dev->tx_timeout = mv643xx_eth_tx_timeout; | |
1da177e4 | 1854 | |
63c9e549 DF |
1855 | #ifdef CONFIG_NET_POLL_CONTROLLER |
1856 | dev->poll_controller = mv643xx_netpoll; | |
1857 | #endif | |
1858 | ||
1da177e4 | 1859 | dev->watchdog_timeo = 2 * HZ; |
1da177e4 LT |
1860 | dev->base_addr = 0; |
1861 | dev->change_mtu = mv643xx_eth_change_mtu; | |
d0412d96 | 1862 | dev->do_ioctl = mv643xx_eth_do_ioctl; |
1da177e4 LT |
1863 | SET_ETHTOOL_OPS(dev, &mv643xx_ethtool_ops); |
1864 | ||
1865 | #ifdef MV643XX_CHECKSUM_OFFLOAD_TX | |
1866 | #ifdef MAX_SKB_FRAGS | |
1867 | /* | |
1868 | * Zero copy can only work if we use Discovery II memory. Else, we will | |
1869 | * have to map the buffers to ISA memory which is only 16 MB | |
1870 | */ | |
63890576 | 1871 | dev->features = NETIF_F_SG | NETIF_F_IP_CSUM; |
1da177e4 LT |
1872 | #endif |
1873 | #endif | |
1874 | ||
1875 | /* Configure the timeout task */ | |
91c7c568 | 1876 | INIT_WORK(&mp->tx_timeout_task, mv643xx_eth_tx_timeout_task); |
1da177e4 LT |
1877 | |
1878 | spin_lock_init(&mp->lock); | |
1879 | ||
fadac406 | 1880 | port_num = mp->port_num = pd->port_number; |
84dd619e | 1881 | |
1da177e4 | 1882 | /* set default config values */ |
afdb57a2 | 1883 | eth_port_uc_addr_get(mp, dev->dev_addr); |
e4d00fa9 LB |
1884 | mp->rx_ring_size = PORT_DEFAULT_RECEIVE_QUEUE_SIZE; |
1885 | mp->tx_ring_size = PORT_DEFAULT_TRANSMIT_QUEUE_SIZE; | |
1da177e4 | 1886 | |
84dd619e DF |
1887 | if (is_valid_ether_addr(pd->mac_addr)) |
1888 | memcpy(dev->dev_addr, pd->mac_addr, 6); | |
1da177e4 | 1889 | |
84dd619e | 1890 | if (pd->phy_addr || pd->force_phy_addr) |
afdb57a2 | 1891 | ethernet_phy_set(mp, pd->phy_addr); |
1da177e4 | 1892 | |
84dd619e DF |
1893 | if (pd->rx_queue_size) |
1894 | mp->rx_ring_size = pd->rx_queue_size; | |
1da177e4 | 1895 | |
84dd619e DF |
1896 | if (pd->tx_queue_size) |
1897 | mp->tx_ring_size = pd->tx_queue_size; | |
1da177e4 | 1898 | |
84dd619e DF |
1899 | if (pd->tx_sram_size) { |
1900 | mp->tx_sram_size = pd->tx_sram_size; | |
1901 | mp->tx_sram_addr = pd->tx_sram_addr; | |
1902 | } | |
01999873 | 1903 | |
84dd619e DF |
1904 | if (pd->rx_sram_size) { |
1905 | mp->rx_sram_size = pd->rx_sram_size; | |
1906 | mp->rx_sram_addr = pd->rx_sram_addr; | |
1da177e4 LT |
1907 | } |
1908 | ||
84dd619e DF |
1909 | duplex = pd->duplex; |
1910 | speed = pd->speed; | |
1911 | ||
c28a4f89 JC |
1912 | /* Hook up MII support for ethtool */ |
1913 | mp->mii.dev = dev; | |
1914 | mp->mii.mdio_read = mv643xx_mdio_read; | |
1915 | mp->mii.mdio_write = mv643xx_mdio_write; | |
afdb57a2 | 1916 | mp->mii.phy_id = ethernet_phy_get(mp); |
c28a4f89 JC |
1917 | mp->mii.phy_id_mask = 0x3f; |
1918 | mp->mii.reg_num_mask = 0x1f; | |
1919 | ||
afdb57a2 | 1920 | err = ethernet_phy_detect(mp); |
1da177e4 | 1921 | if (err) { |
c1b35a28 LB |
1922 | pr_debug("%s: No PHY detected at addr %d\n", |
1923 | dev->name, ethernet_phy_get(mp)); | |
d0412d96 | 1924 | goto out; |
1da177e4 LT |
1925 | } |
1926 | ||
afdb57a2 | 1927 | ethernet_phy_reset(mp); |
c28a4f89 | 1928 | mp->mii.supports_gmii = mii_check_gmii_support(&mp->mii); |
d0412d96 JC |
1929 | mv643xx_init_ethtool_cmd(dev, mp->mii.phy_id, speed, duplex, &cmd); |
1930 | mv643xx_eth_update_pscr(dev, &cmd); | |
1931 | mv643xx_set_settings(dev, &cmd); | |
c28a4f89 | 1932 | |
b0b8dab2 | 1933 | SET_NETDEV_DEV(dev, &pdev->dev); |
1da177e4 LT |
1934 | err = register_netdev(dev); |
1935 | if (err) | |
1936 | goto out; | |
1937 | ||
1938 | p = dev->dev_addr; | |
1939 | printk(KERN_NOTICE | |
0795af57 JP |
1940 | "%s: port %d with MAC address %s\n", |
1941 | dev->name, port_num, print_mac(mac, p)); | |
1da177e4 LT |
1942 | |
1943 | if (dev->features & NETIF_F_SG) | |
1944 | printk(KERN_NOTICE "%s: Scatter Gather Enabled\n", dev->name); | |
1945 | ||
1946 | if (dev->features & NETIF_F_IP_CSUM) | |
1947 | printk(KERN_NOTICE "%s: TX TCP/IP Checksumming Supported\n", | |
1948 | dev->name); | |
1949 | ||
1950 | #ifdef MV643XX_CHECKSUM_OFFLOAD_TX | |
1951 | printk(KERN_NOTICE "%s: RX TCP/UDP Checksum Offload ON \n", dev->name); | |
1952 | #endif | |
1953 | ||
1954 | #ifdef MV643XX_COAL | |
1955 | printk(KERN_NOTICE "%s: TX and RX Interrupt Coalescing ON \n", | |
1956 | dev->name); | |
1957 | #endif | |
1958 | ||
1959 | #ifdef MV643XX_NAPI | |
1960 | printk(KERN_NOTICE "%s: RX NAPI Enabled \n", dev->name); | |
1961 | #endif | |
1962 | ||
b1529871 ND |
1963 | if (mp->tx_sram_size > 0) |
1964 | printk(KERN_NOTICE "%s: Using SRAM\n", dev->name); | |
1965 | ||
1da177e4 LT |
1966 | return 0; |
1967 | ||
1968 | out: | |
1969 | free_netdev(dev); | |
1970 | ||
1971 | return err; | |
1972 | } | |
1973 | ||
3ae5eaec | 1974 | static int mv643xx_eth_remove(struct platform_device *pdev) |
1da177e4 | 1975 | { |
3ae5eaec | 1976 | struct net_device *dev = platform_get_drvdata(pdev); |
1da177e4 LT |
1977 | |
1978 | unregister_netdev(dev); | |
1979 | flush_scheduled_work(); | |
1980 | ||
1981 | free_netdev(dev); | |
3ae5eaec | 1982 | platform_set_drvdata(pdev, NULL); |
1da177e4 LT |
1983 | return 0; |
1984 | } | |
1985 | ||
3ae5eaec | 1986 | static int mv643xx_eth_shared_probe(struct platform_device *pdev) |
1da177e4 | 1987 | { |
e519abb6 | 1988 | static int mv643xx_version_printed = 0; |
1da177e4 LT |
1989 | struct resource *res; |
1990 | ||
e519abb6 LB |
1991 | if (!mv643xx_version_printed++) |
1992 | printk(KERN_NOTICE "MV-643xx 10/100/1000 Ethernet Driver\n"); | |
1da177e4 LT |
1993 | |
1994 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | |
1995 | if (res == NULL) | |
1996 | return -ENODEV; | |
1997 | ||
f9fbbc18 LB |
1998 | mv643xx_eth_base = ioremap(res->start, res->end - res->start + 1); |
1999 | if (mv643xx_eth_base == NULL) | |
1da177e4 LT |
2000 | return -ENOMEM; |
2001 | ||
2002 | return 0; | |
2003 | ||
2004 | } | |
2005 | ||
3ae5eaec | 2006 | static int mv643xx_eth_shared_remove(struct platform_device *pdev) |
1da177e4 | 2007 | { |
f9fbbc18 LB |
2008 | iounmap(mv643xx_eth_base); |
2009 | mv643xx_eth_base = NULL; | |
1da177e4 LT |
2010 | |
2011 | return 0; | |
2012 | } | |
2013 | ||
d57ab6fd DF |
2014 | static void mv643xx_eth_shutdown(struct platform_device *pdev) |
2015 | { | |
2016 | struct net_device *dev = platform_get_drvdata(pdev); | |
2017 | struct mv643xx_private *mp = netdev_priv(dev); | |
2018 | unsigned int port_num = mp->port_num; | |
2019 | ||
2020 | /* Mask all interrupts on ethernet port */ | |
ec69d651 LB |
2021 | wrl(mp, INTERRUPT_MASK_REG(port_num), 0); |
2022 | rdl(mp, INTERRUPT_MASK_REG(port_num)); | |
d57ab6fd | 2023 | |
afdb57a2 | 2024 | eth_port_reset(mp); |
d57ab6fd DF |
2025 | } |
2026 | ||
3ae5eaec | 2027 | static struct platform_driver mv643xx_eth_driver = { |
1da177e4 LT |
2028 | .probe = mv643xx_eth_probe, |
2029 | .remove = mv643xx_eth_remove, | |
d57ab6fd | 2030 | .shutdown = mv643xx_eth_shutdown, |
3ae5eaec RK |
2031 | .driver = { |
2032 | .name = MV643XX_ETH_NAME, | |
2033 | }, | |
1da177e4 LT |
2034 | }; |
2035 | ||
3ae5eaec | 2036 | static struct platform_driver mv643xx_eth_shared_driver = { |
1da177e4 LT |
2037 | .probe = mv643xx_eth_shared_probe, |
2038 | .remove = mv643xx_eth_shared_remove, | |
3ae5eaec RK |
2039 | .driver = { |
2040 | .name = MV643XX_ETH_SHARED_NAME, | |
2041 | }, | |
1da177e4 LT |
2042 | }; |
2043 | ||
2044 | /* | |
2045 | * mv643xx_init_module | |
2046 | * | |
2047 | * Registers the network drivers into the Linux kernel | |
2048 | * | |
2049 | * Input : N/A | |
2050 | * | |
2051 | * Output : N/A | |
2052 | */ | |
2053 | static int __init mv643xx_init_module(void) | |
2054 | { | |
2055 | int rc; | |
2056 | ||
3ae5eaec | 2057 | rc = platform_driver_register(&mv643xx_eth_shared_driver); |
1da177e4 | 2058 | if (!rc) { |
3ae5eaec | 2059 | rc = platform_driver_register(&mv643xx_eth_driver); |
1da177e4 | 2060 | if (rc) |
3ae5eaec | 2061 | platform_driver_unregister(&mv643xx_eth_shared_driver); |
1da177e4 LT |
2062 | } |
2063 | return rc; | |
2064 | } | |
2065 | ||
2066 | /* | |
2067 | * mv643xx_cleanup_module | |
2068 | * | |
2069 | * Registers the network drivers into the Linux kernel | |
2070 | * | |
2071 | * Input : N/A | |
2072 | * | |
2073 | * Output : N/A | |
2074 | */ | |
2075 | static void __exit mv643xx_cleanup_module(void) | |
2076 | { | |
3ae5eaec RK |
2077 | platform_driver_unregister(&mv643xx_eth_driver); |
2078 | platform_driver_unregister(&mv643xx_eth_shared_driver); | |
1da177e4 LT |
2079 | } |
2080 | ||
2081 | module_init(mv643xx_init_module); | |
2082 | module_exit(mv643xx_cleanup_module); | |
2083 | ||
2084 | MODULE_LICENSE("GPL"); | |
2085 | MODULE_AUTHOR( "Rabeeh Khoury, Assaf Hoffman, Matthew Dharm, Manish Lachwani" | |
2086 | " and Dale Farnsworth"); | |
2087 | MODULE_DESCRIPTION("Ethernet driver for Marvell MV643XX"); | |
27c8bc2c | 2088 | MODULE_ALIAS("platform:mv643xx_eth"); |
1da177e4 LT |
2089 | |
2090 | /* | |
2091 | * The second part is the low level driver of the gigE ethernet ports. | |
2092 | */ | |
2093 | ||
2094 | /* | |
2095 | * Marvell's Gigabit Ethernet controller low level driver | |
2096 | * | |
2097 | * DESCRIPTION: | |
2098 | * This file introduce low level API to Marvell's Gigabit Ethernet | |
2099 | * controller. This Gigabit Ethernet Controller driver API controls | |
2100 | * 1) Operations (i.e. port init, start, reset etc'). | |
2101 | * 2) Data flow (i.e. port send, receive etc'). | |
2102 | * Each Gigabit Ethernet port is controlled via | |
2103 | * struct mv643xx_private. | |
2104 | * This struct includes user configuration information as well as | |
2105 | * driver internal data needed for its operations. | |
2106 | * | |
2107 | * Supported Features: | |
2108 | * - This low level driver is OS independent. Allocating memory for | |
2109 | * the descriptor rings and buffers are not within the scope of | |
2110 | * this driver. | |
2111 | * - The user is free from Rx/Tx queue managing. | |
2112 | * - This low level driver introduce functionality API that enable | |
2113 | * the to operate Marvell's Gigabit Ethernet Controller in a | |
2114 | * convenient way. | |
2115 | * - Simple Gigabit Ethernet port operation API. | |
2116 | * - Simple Gigabit Ethernet port data flow API. | |
2117 | * - Data flow and operation API support per queue functionality. | |
2118 | * - Support cached descriptors for better performance. | |
2119 | * - Enable access to all four DRAM banks and internal SRAM memory | |
2120 | * spaces. | |
2121 | * - PHY access and control API. | |
2122 | * - Port control register configuration API. | |
2123 | * - Full control over Unicast and Multicast MAC configurations. | |
2124 | * | |
2125 | * Operation flow: | |
2126 | * | |
2127 | * Initialization phase | |
2128 | * This phase complete the initialization of the the | |
2129 | * mv643xx_private struct. | |
2130 | * User information regarding port configuration has to be set | |
2131 | * prior to calling the port initialization routine. | |
2132 | * | |
2133 | * In this phase any port Tx/Rx activity is halted, MIB counters | |
2134 | * are cleared, PHY address is set according to user parameter and | |
2135 | * access to DRAM and internal SRAM memory spaces. | |
2136 | * | |
2137 | * Driver ring initialization | |
2138 | * Allocating memory for the descriptor rings and buffers is not | |
2139 | * within the scope of this driver. Thus, the user is required to | |
2140 | * allocate memory for the descriptors ring and buffers. Those | |
2141 | * memory parameters are used by the Rx and Tx ring initialization | |
2142 | * routines in order to curve the descriptor linked list in a form | |
2143 | * of a ring. | |
2144 | * Note: Pay special attention to alignment issues when using | |
2145 | * cached descriptors/buffers. In this phase the driver store | |
2146 | * information in the mv643xx_private struct regarding each queue | |
2147 | * ring. | |
2148 | * | |
2149 | * Driver start | |
2150 | * This phase prepares the Ethernet port for Rx and Tx activity. | |
2151 | * It uses the information stored in the mv643xx_private struct to | |
2152 | * initialize the various port registers. | |
2153 | * | |
2154 | * Data flow: | |
2155 | * All packet references to/from the driver are done using | |
2156 | * struct pkt_info. | |
2157 | * This struct is a unified struct used with Rx and Tx operations. | |
2158 | * This way the user is not required to be familiar with neither | |
2159 | * Tx nor Rx descriptors structures. | |
2160 | * The driver's descriptors rings are management by indexes. | |
2161 | * Those indexes controls the ring resources and used to indicate | |
2162 | * a SW resource error: | |
2163 | * 'current' | |
2164 | * This index points to the current available resource for use. For | |
2165 | * example in Rx process this index will point to the descriptor | |
2166 | * that will be passed to the user upon calling the receive | |
2167 | * routine. In Tx process, this index will point to the descriptor | |
2168 | * that will be assigned with the user packet info and transmitted. | |
2169 | * 'used' | |
2170 | * This index points to the descriptor that need to restore its | |
2171 | * resources. For example in Rx process, using the Rx buffer return | |
2172 | * API will attach the buffer returned in packet info to the | |
2173 | * descriptor pointed by 'used'. In Tx process, using the Tx | |
2174 | * descriptor return will merely return the user packet info with | |
2175 | * the command status of the transmitted buffer pointed by the | |
2176 | * 'used' index. Nevertheless, it is essential to use this routine | |
2177 | * to update the 'used' index. | |
2178 | * 'first' | |
2179 | * This index supports Tx Scatter-Gather. It points to the first | |
2180 | * descriptor of a packet assembled of multiple buffers. For | |
2181 | * example when in middle of Such packet we have a Tx resource | |
2182 | * error the 'curr' index get the value of 'first' to indicate | |
2183 | * that the ring returned to its state before trying to transmit | |
2184 | * this packet. | |
2185 | * | |
2186 | * Receive operation: | |
2187 | * The eth_port_receive API set the packet information struct, | |
2188 | * passed by the caller, with received information from the | |
2189 | * 'current' SDMA descriptor. | |
2190 | * It is the user responsibility to return this resource back | |
2191 | * to the Rx descriptor ring to enable the reuse of this source. | |
2192 | * Return Rx resource is done using the eth_rx_return_buff API. | |
2193 | * | |
1da177e4 LT |
2194 | * Prior to calling the initialization routine eth_port_init() the user |
2195 | * must set the following fields under mv643xx_private struct: | |
2196 | * port_num User Ethernet port number. | |
1da177e4 LT |
2197 | * port_config User port configuration value. |
2198 | * port_config_extend User port config extend value. | |
2199 | * port_sdma_config User port SDMA config value. | |
2200 | * port_serial_control User port serial control value. | |
2201 | * | |
2202 | * This driver data flow is done using the struct pkt_info which | |
2203 | * is a unified struct for Rx and Tx operations: | |
2204 | * | |
2205 | * byte_cnt Tx/Rx descriptor buffer byte count. | |
2206 | * l4i_chk CPU provided TCP Checksum. For Tx operation | |
2207 | * only. | |
2208 | * cmd_sts Tx/Rx descriptor command status. | |
2209 | * buf_ptr Tx/Rx descriptor buffer pointer. | |
2210 | * return_info Tx/Rx user resource return information. | |
2211 | */ | |
2212 | ||
1da177e4 | 2213 | /* Ethernet Port routines */ |
afdb57a2 LB |
2214 | static void eth_port_set_filter_table_entry(struct mv643xx_private *mp, |
2215 | int table, unsigned char entry); | |
1da177e4 LT |
2216 | |
2217 | /* | |
2218 | * eth_port_init - Initialize the Ethernet port driver | |
2219 | * | |
2220 | * DESCRIPTION: | |
2221 | * This function prepares the ethernet port to start its activity: | |
2222 | * 1) Completes the ethernet port driver struct initialization toward port | |
2223 | * start routine. | |
2224 | * 2) Resets the device to a quiescent state in case of warm reboot. | |
2225 | * 3) Enable SDMA access to all four DRAM banks as well as internal SRAM. | |
2226 | * 4) Clean MAC tables. The reset status of those tables is unknown. | |
2227 | * 5) Set PHY address. | |
2228 | * Note: Call this routine prior to eth_port_start routine and after | |
2229 | * setting user values in the user fields of Ethernet port control | |
2230 | * struct. | |
2231 | * | |
2232 | * INPUT: | |
2233 | * struct mv643xx_private *mp Ethernet port control struct | |
2234 | * | |
2235 | * OUTPUT: | |
2236 | * See description. | |
2237 | * | |
2238 | * RETURN: | |
2239 | * None. | |
2240 | */ | |
2241 | static void eth_port_init(struct mv643xx_private *mp) | |
2242 | { | |
1da177e4 | 2243 | mp->rx_resource_err = 0; |
1da177e4 | 2244 | |
afdb57a2 | 2245 | eth_port_reset(mp); |
1da177e4 | 2246 | |
afdb57a2 | 2247 | eth_port_init_mac_tables(mp); |
1da177e4 LT |
2248 | } |
2249 | ||
2250 | /* | |
2251 | * eth_port_start - Start the Ethernet port activity. | |
2252 | * | |
2253 | * DESCRIPTION: | |
2254 | * This routine prepares the Ethernet port for Rx and Tx activity: | |
2255 | * 1. Initialize Tx and Rx Current Descriptor Pointer for each queue that | |
2256 | * has been initialized a descriptor's ring (using | |
2257 | * ether_init_tx_desc_ring for Tx and ether_init_rx_desc_ring for Rx) | |
2258 | * 2. Initialize and enable the Ethernet configuration port by writing to | |
2259 | * the port's configuration and command registers. | |
2260 | * 3. Initialize and enable the SDMA by writing to the SDMA's | |
2261 | * configuration and command registers. After completing these steps, | |
2262 | * the ethernet port SDMA can starts to perform Rx and Tx activities. | |
2263 | * | |
2264 | * Note: Each Rx and Tx queue descriptor's list must be initialized prior | |
2265 | * to calling this function (use ether_init_tx_desc_ring for Tx queues | |
2266 | * and ether_init_rx_desc_ring for Rx queues). | |
2267 | * | |
2268 | * INPUT: | |
ed9b5d45 | 2269 | * dev - a pointer to the required interface |
1da177e4 LT |
2270 | * |
2271 | * OUTPUT: | |
2272 | * Ethernet port is ready to receive and transmit. | |
2273 | * | |
2274 | * RETURN: | |
2275 | * None. | |
2276 | */ | |
ed9b5d45 | 2277 | static void eth_port_start(struct net_device *dev) |
1da177e4 | 2278 | { |
ed9b5d45 | 2279 | struct mv643xx_private *mp = netdev_priv(dev); |
1da177e4 LT |
2280 | unsigned int port_num = mp->port_num; |
2281 | int tx_curr_desc, rx_curr_desc; | |
d0412d96 JC |
2282 | u32 pscr; |
2283 | struct ethtool_cmd ethtool_cmd; | |
1da177e4 LT |
2284 | |
2285 | /* Assignment of Tx CTRP of given queue */ | |
2286 | tx_curr_desc = mp->tx_curr_desc_q; | |
ec69d651 | 2287 | wrl(mp, TX_CURRENT_QUEUE_DESC_PTR_0(port_num), |
1da177e4 LT |
2288 | (u32)((struct eth_tx_desc *)mp->tx_desc_dma + tx_curr_desc)); |
2289 | ||
2290 | /* Assignment of Rx CRDP of given queue */ | |
2291 | rx_curr_desc = mp->rx_curr_desc_q; | |
ec69d651 | 2292 | wrl(mp, RX_CURRENT_QUEUE_DESC_PTR_0(port_num), |
1da177e4 LT |
2293 | (u32)((struct eth_rx_desc *)mp->rx_desc_dma + rx_curr_desc)); |
2294 | ||
2295 | /* Add the assigned Ethernet address to the port's address table */ | |
afdb57a2 | 2296 | eth_port_uc_addr_set(mp, dev->dev_addr); |
1da177e4 LT |
2297 | |
2298 | /* Assign port configuration and command. */ | |
ec69d651 | 2299 | wrl(mp, PORT_CONFIG_REG(port_num), |
e4d00fa9 | 2300 | PORT_CONFIG_DEFAULT_VALUE); |
01999873 | 2301 | |
ec69d651 | 2302 | wrl(mp, PORT_CONFIG_EXTEND_REG(port_num), |
e4d00fa9 | 2303 | PORT_CONFIG_EXTEND_DEFAULT_VALUE); |
1da177e4 | 2304 | |
ec69d651 | 2305 | pscr = rdl(mp, PORT_SERIAL_CONTROL_REG(port_num)); |
01999873 | 2306 | |
e4d00fa9 | 2307 | pscr &= ~(SERIAL_PORT_ENABLE | FORCE_LINK_PASS); |
ec69d651 | 2308 | wrl(mp, PORT_SERIAL_CONTROL_REG(port_num), pscr); |
1da177e4 | 2309 | |
e4d00fa9 LB |
2310 | pscr |= DISABLE_AUTO_NEG_FOR_FLOW_CTRL | |
2311 | DISABLE_AUTO_NEG_SPEED_GMII | | |
2312 | DISABLE_AUTO_NEG_FOR_DUPLX | | |
2313 | DO_NOT_FORCE_LINK_FAIL | | |
2314 | SERIAL_PORT_CONTROL_RESERVED; | |
1da177e4 | 2315 | |
ec69d651 | 2316 | wrl(mp, PORT_SERIAL_CONTROL_REG(port_num), pscr); |
1da177e4 | 2317 | |
e4d00fa9 | 2318 | pscr |= SERIAL_PORT_ENABLE; |
ec69d651 | 2319 | wrl(mp, PORT_SERIAL_CONTROL_REG(port_num), pscr); |
1da177e4 LT |
2320 | |
2321 | /* Assign port SDMA configuration */ | |
ec69d651 | 2322 | wrl(mp, SDMA_CONFIG_REG(port_num), |
e4d00fa9 | 2323 | PORT_SDMA_CONFIG_DEFAULT_VALUE); |
1da177e4 LT |
2324 | |
2325 | /* Enable port Rx. */ | |
afdb57a2 | 2326 | mv643xx_eth_port_enable_rx(mp, ETH_RX_QUEUES_ENABLED); |
8f543718 DF |
2327 | |
2328 | /* Disable port bandwidth limits by clearing MTU register */ | |
ec69d651 | 2329 | wrl(mp, MAXIMUM_TRANSMIT_UNIT(port_num), 0); |
d0412d96 JC |
2330 | |
2331 | /* save phy settings across reset */ | |
2332 | mv643xx_get_settings(dev, ðtool_cmd); | |
afdb57a2 | 2333 | ethernet_phy_reset(mp); |
d0412d96 | 2334 | mv643xx_set_settings(dev, ðtool_cmd); |
1da177e4 LT |
2335 | } |
2336 | ||
2337 | /* | |
144213d7 | 2338 | * eth_port_uc_addr_set - Write a MAC address into the port's hw registers |
1da177e4 | 2339 | */ |
afdb57a2 LB |
2340 | static void eth_port_uc_addr_set(struct mv643xx_private *mp, |
2341 | unsigned char *p_addr) | |
1da177e4 | 2342 | { |
afdb57a2 | 2343 | unsigned int port_num = mp->port_num; |
1da177e4 LT |
2344 | unsigned int mac_h; |
2345 | unsigned int mac_l; | |
cf4086c7 | 2346 | int table; |
1da177e4 LT |
2347 | |
2348 | mac_l = (p_addr[4] << 8) | (p_addr[5]); | |
2349 | mac_h = (p_addr[0] << 24) | (p_addr[1] << 16) | (p_addr[2] << 8) | | |
2350 | (p_addr[3] << 0); | |
2351 | ||
ec69d651 LB |
2352 | wrl(mp, MAC_ADDR_LOW(port_num), mac_l); |
2353 | wrl(mp, MAC_ADDR_HIGH(port_num), mac_h); | |
1da177e4 | 2354 | |
144213d7 | 2355 | /* Accept frames with this address */ |
e4d00fa9 | 2356 | table = DA_FILTER_UNICAST_TABLE_BASE(port_num); |
afdb57a2 | 2357 | eth_port_set_filter_table_entry(mp, table, p_addr[5] & 0x0f); |
1da177e4 LT |
2358 | } |
2359 | ||
2360 | /* | |
144213d7 | 2361 | * eth_port_uc_addr_get - Read the MAC address from the port's hw registers |
1da177e4 | 2362 | */ |
afdb57a2 LB |
2363 | static void eth_port_uc_addr_get(struct mv643xx_private *mp, |
2364 | unsigned char *p_addr) | |
1da177e4 | 2365 | { |
afdb57a2 | 2366 | unsigned int port_num = mp->port_num; |
1da177e4 LT |
2367 | unsigned int mac_h; |
2368 | unsigned int mac_l; | |
2369 | ||
ec69d651 LB |
2370 | mac_h = rdl(mp, MAC_ADDR_HIGH(port_num)); |
2371 | mac_l = rdl(mp, MAC_ADDR_LOW(port_num)); | |
1da177e4 LT |
2372 | |
2373 | p_addr[0] = (mac_h >> 24) & 0xff; | |
2374 | p_addr[1] = (mac_h >> 16) & 0xff; | |
2375 | p_addr[2] = (mac_h >> 8) & 0xff; | |
2376 | p_addr[3] = mac_h & 0xff; | |
2377 | p_addr[4] = (mac_l >> 8) & 0xff; | |
2378 | p_addr[5] = mac_l & 0xff; | |
2379 | } | |
2380 | ||
16e03018 DF |
2381 | /* |
2382 | * The entries in each table are indexed by a hash of a packet's MAC | |
2383 | * address. One bit in each entry determines whether the packet is | |
2384 | * accepted. There are 4 entries (each 8 bits wide) in each register | |
2385 | * of the table. The bits in each entry are defined as follows: | |
2386 | * 0 Accept=1, Drop=0 | |
2387 | * 3-1 Queue (ETH_Q0=0) | |
2388 | * 7-4 Reserved = 0; | |
2389 | */ | |
afdb57a2 LB |
2390 | static void eth_port_set_filter_table_entry(struct mv643xx_private *mp, |
2391 | int table, unsigned char entry) | |
16e03018 DF |
2392 | { |
2393 | unsigned int table_reg; | |
2394 | unsigned int tbl_offset; | |
2395 | unsigned int reg_offset; | |
2396 | ||
2397 | tbl_offset = (entry / 4) * 4; /* Register offset of DA table entry */ | |
2398 | reg_offset = entry % 4; /* Entry offset within the register */ | |
2399 | ||
2400 | /* Set "accepts frame bit" at specified table entry */ | |
ec69d651 | 2401 | table_reg = rdl(mp, table + tbl_offset); |
16e03018 | 2402 | table_reg |= 0x01 << (8 * reg_offset); |
ec69d651 | 2403 | wrl(mp, table + tbl_offset, table_reg); |
16e03018 DF |
2404 | } |
2405 | ||
2406 | /* | |
2407 | * eth_port_mc_addr - Multicast address settings. | |
2408 | * | |
2409 | * The MV device supports multicast using two tables: | |
2410 | * 1) Special Multicast Table for MAC addresses of the form | |
2411 | * 0x01-00-5E-00-00-XX (where XX is between 0x00 and 0x_FF). | |
2412 | * The MAC DA[7:0] bits are used as a pointer to the Special Multicast | |
2413 | * Table entries in the DA-Filter table. | |
2414 | * 2) Other Multicast Table for multicast of another type. A CRC-8bit | |
2415 | * is used as an index to the Other Multicast Table entries in the | |
2416 | * DA-Filter table. This function calculates the CRC-8bit value. | |
2417 | * In either case, eth_port_set_filter_table_entry() is then called | |
2418 | * to set to set the actual table entry. | |
2419 | */ | |
afdb57a2 | 2420 | static void eth_port_mc_addr(struct mv643xx_private *mp, unsigned char *p_addr) |
16e03018 | 2421 | { |
afdb57a2 | 2422 | unsigned int port_num = mp->port_num; |
16e03018 DF |
2423 | unsigned int mac_h; |
2424 | unsigned int mac_l; | |
2425 | unsigned char crc_result = 0; | |
2426 | int table; | |
2427 | int mac_array[48]; | |
2428 | int crc[8]; | |
2429 | int i; | |
2430 | ||
2431 | if ((p_addr[0] == 0x01) && (p_addr[1] == 0x00) && | |
2432 | (p_addr[2] == 0x5E) && (p_addr[3] == 0x00) && (p_addr[4] == 0x00)) { | |
afdb57a2 LB |
2433 | table = DA_FILTER_SPECIAL_MULTICAST_TABLE_BASE(port_num); |
2434 | eth_port_set_filter_table_entry(mp, table, p_addr[5]); | |
16e03018 DF |
2435 | return; |
2436 | } | |
2437 | ||
2438 | /* Calculate CRC-8 out of the given address */ | |
2439 | mac_h = (p_addr[0] << 8) | (p_addr[1]); | |
2440 | mac_l = (p_addr[2] << 24) | (p_addr[3] << 16) | | |
2441 | (p_addr[4] << 8) | (p_addr[5] << 0); | |
2442 | ||
2443 | for (i = 0; i < 32; i++) | |
2444 | mac_array[i] = (mac_l >> i) & 0x1; | |
2445 | for (i = 32; i < 48; i++) | |
2446 | mac_array[i] = (mac_h >> (i - 32)) & 0x1; | |
2447 | ||
2448 | crc[0] = mac_array[45] ^ mac_array[43] ^ mac_array[40] ^ mac_array[39] ^ | |
2449 | mac_array[35] ^ mac_array[34] ^ mac_array[31] ^ mac_array[30] ^ | |
2450 | mac_array[28] ^ mac_array[23] ^ mac_array[21] ^ mac_array[19] ^ | |
2451 | mac_array[18] ^ mac_array[16] ^ mac_array[14] ^ mac_array[12] ^ | |
2452 | mac_array[8] ^ mac_array[7] ^ mac_array[6] ^ mac_array[0]; | |
2453 | ||
2454 | crc[1] = mac_array[46] ^ mac_array[45] ^ mac_array[44] ^ mac_array[43] ^ | |
2455 | mac_array[41] ^ mac_array[39] ^ mac_array[36] ^ mac_array[34] ^ | |
2456 | mac_array[32] ^ mac_array[30] ^ mac_array[29] ^ mac_array[28] ^ | |
2457 | mac_array[24] ^ mac_array[23] ^ mac_array[22] ^ mac_array[21] ^ | |
2458 | mac_array[20] ^ mac_array[18] ^ mac_array[17] ^ mac_array[16] ^ | |
2459 | mac_array[15] ^ mac_array[14] ^ mac_array[13] ^ mac_array[12] ^ | |
2460 | mac_array[9] ^ mac_array[6] ^ mac_array[1] ^ mac_array[0]; | |
2461 | ||
2462 | crc[2] = mac_array[47] ^ mac_array[46] ^ mac_array[44] ^ mac_array[43] ^ | |
2463 | mac_array[42] ^ mac_array[39] ^ mac_array[37] ^ mac_array[34] ^ | |
2464 | mac_array[33] ^ mac_array[29] ^ mac_array[28] ^ mac_array[25] ^ | |
2465 | mac_array[24] ^ mac_array[22] ^ mac_array[17] ^ mac_array[15] ^ | |
2466 | mac_array[13] ^ mac_array[12] ^ mac_array[10] ^ mac_array[8] ^ | |
2467 | mac_array[6] ^ mac_array[2] ^ mac_array[1] ^ mac_array[0]; | |
2468 | ||
2469 | crc[3] = mac_array[47] ^ mac_array[45] ^ mac_array[44] ^ mac_array[43] ^ | |
2470 | mac_array[40] ^ mac_array[38] ^ mac_array[35] ^ mac_array[34] ^ | |
2471 | mac_array[30] ^ mac_array[29] ^ mac_array[26] ^ mac_array[25] ^ | |
2472 | mac_array[23] ^ mac_array[18] ^ mac_array[16] ^ mac_array[14] ^ | |
2473 | mac_array[13] ^ mac_array[11] ^ mac_array[9] ^ mac_array[7] ^ | |
2474 | mac_array[3] ^ mac_array[2] ^ mac_array[1]; | |
2475 | ||
2476 | crc[4] = mac_array[46] ^ mac_array[45] ^ mac_array[44] ^ mac_array[41] ^ | |
2477 | mac_array[39] ^ mac_array[36] ^ mac_array[35] ^ mac_array[31] ^ | |
2478 | mac_array[30] ^ mac_array[27] ^ mac_array[26] ^ mac_array[24] ^ | |
2479 | mac_array[19] ^ mac_array[17] ^ mac_array[15] ^ mac_array[14] ^ | |
2480 | mac_array[12] ^ mac_array[10] ^ mac_array[8] ^ mac_array[4] ^ | |
2481 | mac_array[3] ^ mac_array[2]; | |
2482 | ||
2483 | crc[5] = mac_array[47] ^ mac_array[46] ^ mac_array[45] ^ mac_array[42] ^ | |
2484 | mac_array[40] ^ mac_array[37] ^ mac_array[36] ^ mac_array[32] ^ | |
2485 | mac_array[31] ^ mac_array[28] ^ mac_array[27] ^ mac_array[25] ^ | |
2486 | mac_array[20] ^ mac_array[18] ^ mac_array[16] ^ mac_array[15] ^ | |
2487 | mac_array[13] ^ mac_array[11] ^ mac_array[9] ^ mac_array[5] ^ | |
2488 | mac_array[4] ^ mac_array[3]; | |
2489 | ||
2490 | crc[6] = mac_array[47] ^ mac_array[46] ^ mac_array[43] ^ mac_array[41] ^ | |
2491 | mac_array[38] ^ mac_array[37] ^ mac_array[33] ^ mac_array[32] ^ | |
2492 | mac_array[29] ^ mac_array[28] ^ mac_array[26] ^ mac_array[21] ^ | |
2493 | mac_array[19] ^ mac_array[17] ^ mac_array[16] ^ mac_array[14] ^ | |
2494 | mac_array[12] ^ mac_array[10] ^ mac_array[6] ^ mac_array[5] ^ | |
2495 | mac_array[4]; | |
2496 | ||
2497 | crc[7] = mac_array[47] ^ mac_array[44] ^ mac_array[42] ^ mac_array[39] ^ | |
2498 | mac_array[38] ^ mac_array[34] ^ mac_array[33] ^ mac_array[30] ^ | |
2499 | mac_array[29] ^ mac_array[27] ^ mac_array[22] ^ mac_array[20] ^ | |
2500 | mac_array[18] ^ mac_array[17] ^ mac_array[15] ^ mac_array[13] ^ | |
2501 | mac_array[11] ^ mac_array[7] ^ mac_array[6] ^ mac_array[5]; | |
2502 | ||
2503 | for (i = 0; i < 8; i++) | |
2504 | crc_result = crc_result | (crc[i] << i); | |
2505 | ||
afdb57a2 LB |
2506 | table = DA_FILTER_OTHER_MULTICAST_TABLE_BASE(port_num); |
2507 | eth_port_set_filter_table_entry(mp, table, crc_result); | |
16e03018 DF |
2508 | } |
2509 | ||
2510 | /* | |
2511 | * Set the entire multicast list based on dev->mc_list. | |
2512 | */ | |
2513 | static void eth_port_set_multicast_list(struct net_device *dev) | |
2514 | { | |
2515 | ||
2516 | struct dev_mc_list *mc_list; | |
2517 | int i; | |
2518 | int table_index; | |
2519 | struct mv643xx_private *mp = netdev_priv(dev); | |
2520 | unsigned int eth_port_num = mp->port_num; | |
2521 | ||
2522 | /* If the device is in promiscuous mode or in all multicast mode, | |
2523 | * we will fully populate both multicast tables with accept. | |
2524 | * This is guaranteed to yield a match on all multicast addresses... | |
2525 | */ | |
2526 | if ((dev->flags & IFF_PROMISC) || (dev->flags & IFF_ALLMULTI)) { | |
2527 | for (table_index = 0; table_index <= 0xFC; table_index += 4) { | |
b4de9051 DF |
2528 | /* Set all entries in DA filter special multicast |
2529 | * table (Ex_dFSMT) | |
2530 | * Set for ETH_Q0 for now | |
2531 | * Bits | |
2532 | * 0 Accept=1, Drop=0 | |
2533 | * 3-1 Queue ETH_Q0=0 | |
2534 | * 7-4 Reserved = 0; | |
2535 | */ | |
ec69d651 | 2536 | wrl(mp, DA_FILTER_SPECIAL_MULTICAST_TABLE_BASE(eth_port_num) + table_index, 0x01010101); |
b4de9051 DF |
2537 | |
2538 | /* Set all entries in DA filter other multicast | |
2539 | * table (Ex_dFOMT) | |
2540 | * Set for ETH_Q0 for now | |
2541 | * Bits | |
2542 | * 0 Accept=1, Drop=0 | |
2543 | * 3-1 Queue ETH_Q0=0 | |
2544 | * 7-4 Reserved = 0; | |
2545 | */ | |
ec69d651 | 2546 | wrl(mp, DA_FILTER_OTHER_MULTICAST_TABLE_BASE(eth_port_num) + table_index, 0x01010101); |
b4de9051 | 2547 | } |
16e03018 DF |
2548 | return; |
2549 | } | |
2550 | ||
2551 | /* We will clear out multicast tables every time we get the list. | |
2552 | * Then add the entire new list... | |
2553 | */ | |
2554 | for (table_index = 0; table_index <= 0xFC; table_index += 4) { | |
2555 | /* Clear DA filter special multicast table (Ex_dFSMT) */ | |
ec69d651 | 2556 | wrl(mp, DA_FILTER_SPECIAL_MULTICAST_TABLE_BASE |
16e03018 DF |
2557 | (eth_port_num) + table_index, 0); |
2558 | ||
2559 | /* Clear DA filter other multicast table (Ex_dFOMT) */ | |
ec69d651 | 2560 | wrl(mp, DA_FILTER_OTHER_MULTICAST_TABLE_BASE |
16e03018 DF |
2561 | (eth_port_num) + table_index, 0); |
2562 | } | |
2563 | ||
2564 | /* Get pointer to net_device multicast list and add each one... */ | |
2565 | for (i = 0, mc_list = dev->mc_list; | |
2566 | (i < 256) && (mc_list != NULL) && (i < dev->mc_count); | |
2567 | i++, mc_list = mc_list->next) | |
2568 | if (mc_list->dmi_addrlen == 6) | |
afdb57a2 | 2569 | eth_port_mc_addr(mp, mc_list->dmi_addr); |
16e03018 DF |
2570 | } |
2571 | ||
1da177e4 LT |
2572 | /* |
2573 | * eth_port_init_mac_tables - Clear all entrance in the UC, SMC and OMC tables | |
2574 | * | |
2575 | * DESCRIPTION: | |
2576 | * Go through all the DA filter tables (Unicast, Special Multicast & | |
2577 | * Other Multicast) and set each entry to 0. | |
2578 | * | |
2579 | * INPUT: | |
afdb57a2 | 2580 | * struct mv643xx_private *mp Ethernet Port. |
1da177e4 LT |
2581 | * |
2582 | * OUTPUT: | |
2583 | * Multicast and Unicast packets are rejected. | |
2584 | * | |
2585 | * RETURN: | |
2586 | * None. | |
2587 | */ | |
afdb57a2 | 2588 | static void eth_port_init_mac_tables(struct mv643xx_private *mp) |
1da177e4 | 2589 | { |
afdb57a2 | 2590 | unsigned int port_num = mp->port_num; |
1da177e4 LT |
2591 | int table_index; |
2592 | ||
2593 | /* Clear DA filter unicast table (Ex_dFUT) */ | |
2594 | for (table_index = 0; table_index <= 0xC; table_index += 4) | |
ec69d651 | 2595 | wrl(mp, DA_FILTER_UNICAST_TABLE_BASE(port_num) + |
afdb57a2 | 2596 | table_index, 0); |
1da177e4 LT |
2597 | |
2598 | for (table_index = 0; table_index <= 0xFC; table_index += 4) { | |
2599 | /* Clear DA filter special multicast table (Ex_dFSMT) */ | |
ec69d651 | 2600 | wrl(mp, DA_FILTER_SPECIAL_MULTICAST_TABLE_BASE(port_num) + |
afdb57a2 | 2601 | table_index, 0); |
1da177e4 | 2602 | /* Clear DA filter other multicast table (Ex_dFOMT) */ |
ec69d651 | 2603 | wrl(mp, DA_FILTER_OTHER_MULTICAST_TABLE_BASE(port_num) + |
afdb57a2 | 2604 | table_index, 0); |
1da177e4 LT |
2605 | } |
2606 | } | |
2607 | ||
2608 | /* | |
2609 | * eth_clear_mib_counters - Clear all MIB counters | |
2610 | * | |
2611 | * DESCRIPTION: | |
2612 | * This function clears all MIB counters of a specific ethernet port. | |
2613 | * A read from the MIB counter will reset the counter. | |
2614 | * | |
2615 | * INPUT: | |
afdb57a2 | 2616 | * struct mv643xx_private *mp Ethernet Port. |
1da177e4 LT |
2617 | * |
2618 | * OUTPUT: | |
2619 | * After reading all MIB counters, the counters resets. | |
2620 | * | |
2621 | * RETURN: | |
2622 | * MIB counter value. | |
2623 | * | |
2624 | */ | |
afdb57a2 | 2625 | static void eth_clear_mib_counters(struct mv643xx_private *mp) |
1da177e4 | 2626 | { |
afdb57a2 | 2627 | unsigned int port_num = mp->port_num; |
1da177e4 LT |
2628 | int i; |
2629 | ||
2630 | /* Perform dummy reads from MIB counters */ | |
2631 | for (i = ETH_MIB_GOOD_OCTETS_RECEIVED_LOW; i < ETH_MIB_LATE_COLLISION; | |
2632 | i += 4) | |
ec69d651 | 2633 | rdl(mp, MIB_COUNTERS_BASE(port_num) + i); |
1da177e4 LT |
2634 | } |
2635 | ||
2636 | static inline u32 read_mib(struct mv643xx_private *mp, int offset) | |
2637 | { | |
ec69d651 | 2638 | return rdl(mp, MIB_COUNTERS_BASE(mp->port_num) + offset); |
1da177e4 LT |
2639 | } |
2640 | ||
2641 | static void eth_update_mib_counters(struct mv643xx_private *mp) | |
2642 | { | |
2643 | struct mv643xx_mib_counters *p = &mp->mib_counters; | |
2644 | int offset; | |
2645 | ||
2646 | p->good_octets_received += | |
2647 | read_mib(mp, ETH_MIB_GOOD_OCTETS_RECEIVED_LOW); | |
2648 | p->good_octets_received += | |
2649 | (u64)read_mib(mp, ETH_MIB_GOOD_OCTETS_RECEIVED_HIGH) << 32; | |
2650 | ||
2651 | for (offset = ETH_MIB_BAD_OCTETS_RECEIVED; | |
2652 | offset <= ETH_MIB_FRAMES_1024_TO_MAX_OCTETS; | |
2653 | offset += 4) | |
70fbf327 | 2654 | *(u32 *)((char *)p + offset) += read_mib(mp, offset); |
1da177e4 LT |
2655 | |
2656 | p->good_octets_sent += read_mib(mp, ETH_MIB_GOOD_OCTETS_SENT_LOW); | |
2657 | p->good_octets_sent += | |
2658 | (u64)read_mib(mp, ETH_MIB_GOOD_OCTETS_SENT_HIGH) << 32; | |
2659 | ||
2660 | for (offset = ETH_MIB_GOOD_FRAMES_SENT; | |
2661 | offset <= ETH_MIB_LATE_COLLISION; | |
2662 | offset += 4) | |
70fbf327 | 2663 | *(u32 *)((char *)p + offset) += read_mib(mp, offset); |
1da177e4 LT |
2664 | } |
2665 | ||
2666 | /* | |
2667 | * ethernet_phy_detect - Detect whether a phy is present | |
2668 | * | |
2669 | * DESCRIPTION: | |
2670 | * This function tests whether there is a PHY present on | |
2671 | * the specified port. | |
2672 | * | |
2673 | * INPUT: | |
afdb57a2 | 2674 | * struct mv643xx_private *mp Ethernet Port. |
1da177e4 LT |
2675 | * |
2676 | * OUTPUT: | |
2677 | * None | |
2678 | * | |
2679 | * RETURN: | |
2680 | * 0 on success | |
2681 | * -ENODEV on failure | |
2682 | * | |
2683 | */ | |
afdb57a2 | 2684 | static int ethernet_phy_detect(struct mv643xx_private *mp) |
1da177e4 LT |
2685 | { |
2686 | unsigned int phy_reg_data0; | |
2687 | int auto_neg; | |
2688 | ||
afdb57a2 | 2689 | eth_port_read_smi_reg(mp, 0, &phy_reg_data0); |
1da177e4 LT |
2690 | auto_neg = phy_reg_data0 & 0x1000; |
2691 | phy_reg_data0 ^= 0x1000; /* invert auto_neg */ | |
afdb57a2 | 2692 | eth_port_write_smi_reg(mp, 0, phy_reg_data0); |
1da177e4 | 2693 | |
afdb57a2 | 2694 | eth_port_read_smi_reg(mp, 0, &phy_reg_data0); |
1da177e4 LT |
2695 | if ((phy_reg_data0 & 0x1000) == auto_neg) |
2696 | return -ENODEV; /* change didn't take */ | |
2697 | ||
2698 | phy_reg_data0 ^= 0x1000; | |
afdb57a2 | 2699 | eth_port_write_smi_reg(mp, 0, phy_reg_data0); |
1da177e4 LT |
2700 | return 0; |
2701 | } | |
2702 | ||
2703 | /* | |
2704 | * ethernet_phy_get - Get the ethernet port PHY address. | |
2705 | * | |
2706 | * DESCRIPTION: | |
2707 | * This routine returns the given ethernet port PHY address. | |
2708 | * | |
2709 | * INPUT: | |
afdb57a2 | 2710 | * struct mv643xx_private *mp Ethernet Port. |
1da177e4 LT |
2711 | * |
2712 | * OUTPUT: | |
2713 | * None. | |
2714 | * | |
2715 | * RETURN: | |
2716 | * PHY address. | |
2717 | * | |
2718 | */ | |
afdb57a2 | 2719 | static int ethernet_phy_get(struct mv643xx_private *mp) |
1da177e4 LT |
2720 | { |
2721 | unsigned int reg_data; | |
2722 | ||
ec69d651 | 2723 | reg_data = rdl(mp, PHY_ADDR_REG); |
1da177e4 | 2724 | |
afdb57a2 | 2725 | return ((reg_data >> (5 * mp->port_num)) & 0x1f); |
1da177e4 LT |
2726 | } |
2727 | ||
2728 | /* | |
2729 | * ethernet_phy_set - Set the ethernet port PHY address. | |
2730 | * | |
2731 | * DESCRIPTION: | |
2732 | * This routine sets the given ethernet port PHY address. | |
2733 | * | |
2734 | * INPUT: | |
afdb57a2 | 2735 | * struct mv643xx_private *mp Ethernet Port. |
1da177e4 LT |
2736 | * int phy_addr PHY address. |
2737 | * | |
2738 | * OUTPUT: | |
2739 | * None. | |
2740 | * | |
2741 | * RETURN: | |
2742 | * None. | |
2743 | * | |
2744 | */ | |
afdb57a2 | 2745 | static void ethernet_phy_set(struct mv643xx_private *mp, int phy_addr) |
1da177e4 LT |
2746 | { |
2747 | u32 reg_data; | |
afdb57a2 | 2748 | int addr_shift = 5 * mp->port_num; |
1da177e4 | 2749 | |
ec69d651 | 2750 | reg_data = rdl(mp, PHY_ADDR_REG); |
1da177e4 LT |
2751 | reg_data &= ~(0x1f << addr_shift); |
2752 | reg_data |= (phy_addr & 0x1f) << addr_shift; | |
ec69d651 | 2753 | wrl(mp, PHY_ADDR_REG, reg_data); |
1da177e4 LT |
2754 | } |
2755 | ||
2756 | /* | |
2757 | * ethernet_phy_reset - Reset Ethernet port PHY. | |
2758 | * | |
2759 | * DESCRIPTION: | |
2760 | * This routine utilizes the SMI interface to reset the ethernet port PHY. | |
2761 | * | |
2762 | * INPUT: | |
afdb57a2 | 2763 | * struct mv643xx_private *mp Ethernet Port. |
1da177e4 LT |
2764 | * |
2765 | * OUTPUT: | |
2766 | * The PHY is reset. | |
2767 | * | |
2768 | * RETURN: | |
2769 | * None. | |
2770 | * | |
2771 | */ | |
afdb57a2 | 2772 | static void ethernet_phy_reset(struct mv643xx_private *mp) |
1da177e4 LT |
2773 | { |
2774 | unsigned int phy_reg_data; | |
2775 | ||
2776 | /* Reset the PHY */ | |
afdb57a2 | 2777 | eth_port_read_smi_reg(mp, 0, &phy_reg_data); |
1da177e4 | 2778 | phy_reg_data |= 0x8000; /* Set bit 15 to reset the PHY */ |
afdb57a2 | 2779 | eth_port_write_smi_reg(mp, 0, phy_reg_data); |
d0412d96 JC |
2780 | |
2781 | /* wait for PHY to come out of reset */ | |
2782 | do { | |
2783 | udelay(1); | |
afdb57a2 | 2784 | eth_port_read_smi_reg(mp, 0, &phy_reg_data); |
d0412d96 | 2785 | } while (phy_reg_data & 0x8000); |
1da177e4 LT |
2786 | } |
2787 | ||
afdb57a2 | 2788 | static void mv643xx_eth_port_enable_tx(struct mv643xx_private *mp, |
12a87c64 | 2789 | unsigned int queues) |
9f8dd319 | 2790 | { |
ec69d651 | 2791 | wrl(mp, TRANSMIT_QUEUE_COMMAND_REG(mp->port_num), queues); |
9f8dd319 DF |
2792 | } |
2793 | ||
afdb57a2 | 2794 | static void mv643xx_eth_port_enable_rx(struct mv643xx_private *mp, |
12a87c64 | 2795 | unsigned int queues) |
9f8dd319 | 2796 | { |
ec69d651 | 2797 | wrl(mp, RECEIVE_QUEUE_COMMAND_REG(mp->port_num), queues); |
9f8dd319 DF |
2798 | } |
2799 | ||
afdb57a2 | 2800 | static unsigned int mv643xx_eth_port_disable_tx(struct mv643xx_private *mp) |
9f8dd319 | 2801 | { |
afdb57a2 | 2802 | unsigned int port_num = mp->port_num; |
12a87c64 | 2803 | u32 queues; |
9f8dd319 DF |
2804 | |
2805 | /* Stop Tx port activity. Check port Tx activity. */ | |
ec69d651 | 2806 | queues = rdl(mp, TRANSMIT_QUEUE_COMMAND_REG(port_num)) & 0xFF; |
12a87c64 DF |
2807 | if (queues) { |
2808 | /* Issue stop command for active queues only */ | |
ec69d651 | 2809 | wrl(mp, TRANSMIT_QUEUE_COMMAND_REG(port_num), (queues << 8)); |
9f8dd319 DF |
2810 | |
2811 | /* Wait for all Tx activity to terminate. */ | |
2812 | /* Check port cause register that all Tx queues are stopped */ | |
ec69d651 | 2813 | while (rdl(mp, TRANSMIT_QUEUE_COMMAND_REG(port_num)) & 0xFF) |
9f8dd319 DF |
2814 | udelay(PHY_WAIT_MICRO_SECONDS); |
2815 | ||
2816 | /* Wait for Tx FIFO to empty */ | |
ec69d651 | 2817 | while (rdl(mp, PORT_STATUS_REG(port_num)) & |
9f8dd319 DF |
2818 | ETH_PORT_TX_FIFO_EMPTY) |
2819 | udelay(PHY_WAIT_MICRO_SECONDS); | |
2820 | } | |
2821 | ||
12a87c64 | 2822 | return queues; |
9f8dd319 DF |
2823 | } |
2824 | ||
afdb57a2 | 2825 | static unsigned int mv643xx_eth_port_disable_rx(struct mv643xx_private *mp) |
9f8dd319 | 2826 | { |
afdb57a2 | 2827 | unsigned int port_num = mp->port_num; |
12a87c64 | 2828 | u32 queues; |
9f8dd319 DF |
2829 | |
2830 | /* Stop Rx port activity. Check port Rx activity. */ | |
ec69d651 | 2831 | queues = rdl(mp, RECEIVE_QUEUE_COMMAND_REG(port_num)) & 0xFF; |
12a87c64 DF |
2832 | if (queues) { |
2833 | /* Issue stop command for active queues only */ | |
ec69d651 | 2834 | wrl(mp, RECEIVE_QUEUE_COMMAND_REG(port_num), (queues << 8)); |
9f8dd319 DF |
2835 | |
2836 | /* Wait for all Rx activity to terminate. */ | |
2837 | /* Check port cause register that all Rx queues are stopped */ | |
ec69d651 | 2838 | while (rdl(mp, RECEIVE_QUEUE_COMMAND_REG(port_num)) & 0xFF) |
9f8dd319 DF |
2839 | udelay(PHY_WAIT_MICRO_SECONDS); |
2840 | } | |
2841 | ||
12a87c64 | 2842 | return queues; |
9f8dd319 DF |
2843 | } |
2844 | ||
1da177e4 LT |
2845 | /* |
2846 | * eth_port_reset - Reset Ethernet port | |
2847 | * | |
2848 | * DESCRIPTION: | |
2849 | * This routine resets the chip by aborting any SDMA engine activity and | |
2850 | * clearing the MIB counters. The Receiver and the Transmit unit are in | |
2851 | * idle state after this command is performed and the port is disabled. | |
2852 | * | |
2853 | * INPUT: | |
afdb57a2 | 2854 | * struct mv643xx_private *mp Ethernet Port. |
1da177e4 LT |
2855 | * |
2856 | * OUTPUT: | |
2857 | * Channel activity is halted. | |
2858 | * | |
2859 | * RETURN: | |
2860 | * None. | |
2861 | * | |
2862 | */ | |
afdb57a2 | 2863 | static void eth_port_reset(struct mv643xx_private *mp) |
1da177e4 | 2864 | { |
afdb57a2 | 2865 | unsigned int port_num = mp->port_num; |
1da177e4 LT |
2866 | unsigned int reg_data; |
2867 | ||
afdb57a2 LB |
2868 | mv643xx_eth_port_disable_tx(mp); |
2869 | mv643xx_eth_port_disable_rx(mp); | |
1da177e4 LT |
2870 | |
2871 | /* Clear all MIB counters */ | |
afdb57a2 | 2872 | eth_clear_mib_counters(mp); |
1da177e4 LT |
2873 | |
2874 | /* Reset the Enable bit in the Configuration Register */ | |
ec69d651 | 2875 | reg_data = rdl(mp, PORT_SERIAL_CONTROL_REG(port_num)); |
e4d00fa9 LB |
2876 | reg_data &= ~(SERIAL_PORT_ENABLE | |
2877 | DO_NOT_FORCE_LINK_FAIL | | |
2878 | FORCE_LINK_PASS); | |
ec69d651 | 2879 | wrl(mp, PORT_SERIAL_CONTROL_REG(port_num), reg_data); |
1da177e4 LT |
2880 | } |
2881 | ||
1da177e4 | 2882 | |
1da177e4 LT |
2883 | /* |
2884 | * eth_port_read_smi_reg - Read PHY registers | |
2885 | * | |
2886 | * DESCRIPTION: | |
2887 | * This routine utilize the SMI interface to interact with the PHY in | |
2888 | * order to perform PHY register read. | |
2889 | * | |
2890 | * INPUT: | |
afdb57a2 | 2891 | * struct mv643xx_private *mp Ethernet Port. |
1da177e4 LT |
2892 | * unsigned int phy_reg PHY register address offset. |
2893 | * unsigned int *value Register value buffer. | |
2894 | * | |
2895 | * OUTPUT: | |
2896 | * Write the value of a specified PHY register into given buffer. | |
2897 | * | |
2898 | * RETURN: | |
2899 | * false if the PHY is busy or read data is not in valid state. | |
2900 | * true otherwise. | |
2901 | * | |
2902 | */ | |
afdb57a2 | 2903 | static void eth_port_read_smi_reg(struct mv643xx_private *mp, |
1da177e4 LT |
2904 | unsigned int phy_reg, unsigned int *value) |
2905 | { | |
afdb57a2 | 2906 | int phy_addr = ethernet_phy_get(mp); |
1da177e4 LT |
2907 | unsigned long flags; |
2908 | int i; | |
2909 | ||
2910 | /* the SMI register is a shared resource */ | |
2911 | spin_lock_irqsave(&mv643xx_eth_phy_lock, flags); | |
2912 | ||
2913 | /* wait for the SMI register to become available */ | |
ec69d651 | 2914 | for (i = 0; rdl(mp, SMI_REG) & ETH_SMI_BUSY; i++) { |
1da177e4 | 2915 | if (i == PHY_WAIT_ITERATIONS) { |
c1b35a28 | 2916 | printk("%s: PHY busy timeout\n", mp->dev->name); |
1da177e4 LT |
2917 | goto out; |
2918 | } | |
2919 | udelay(PHY_WAIT_MICRO_SECONDS); | |
2920 | } | |
2921 | ||
ec69d651 | 2922 | wrl(mp, SMI_REG, |
1da177e4 LT |
2923 | (phy_addr << 16) | (phy_reg << 21) | ETH_SMI_OPCODE_READ); |
2924 | ||
2925 | /* now wait for the data to be valid */ | |
ec69d651 | 2926 | for (i = 0; !(rdl(mp, SMI_REG) & ETH_SMI_READ_VALID); i++) { |
1da177e4 | 2927 | if (i == PHY_WAIT_ITERATIONS) { |
c1b35a28 | 2928 | printk("%s: PHY read timeout\n", mp->dev->name); |
1da177e4 LT |
2929 | goto out; |
2930 | } | |
2931 | udelay(PHY_WAIT_MICRO_SECONDS); | |
2932 | } | |
2933 | ||
ec69d651 | 2934 | *value = rdl(mp, SMI_REG) & 0xffff; |
1da177e4 LT |
2935 | out: |
2936 | spin_unlock_irqrestore(&mv643xx_eth_phy_lock, flags); | |
2937 | } | |
2938 | ||
2939 | /* | |
2940 | * eth_port_write_smi_reg - Write to PHY registers | |
2941 | * | |
2942 | * DESCRIPTION: | |
2943 | * This routine utilize the SMI interface to interact with the PHY in | |
2944 | * order to perform writes to PHY registers. | |
2945 | * | |
2946 | * INPUT: | |
afdb57a2 | 2947 | * struct mv643xx_private *mp Ethernet Port. |
1da177e4 LT |
2948 | * unsigned int phy_reg PHY register address offset. |
2949 | * unsigned int value Register value. | |
2950 | * | |
2951 | * OUTPUT: | |
2952 | * Write the given value to the specified PHY register. | |
2953 | * | |
2954 | * RETURN: | |
2955 | * false if the PHY is busy. | |
2956 | * true otherwise. | |
2957 | * | |
2958 | */ | |
afdb57a2 | 2959 | static void eth_port_write_smi_reg(struct mv643xx_private *mp, |
1da177e4 LT |
2960 | unsigned int phy_reg, unsigned int value) |
2961 | { | |
2962 | int phy_addr; | |
2963 | int i; | |
2964 | unsigned long flags; | |
2965 | ||
afdb57a2 | 2966 | phy_addr = ethernet_phy_get(mp); |
1da177e4 LT |
2967 | |
2968 | /* the SMI register is a shared resource */ | |
2969 | spin_lock_irqsave(&mv643xx_eth_phy_lock, flags); | |
2970 | ||
2971 | /* wait for the SMI register to become available */ | |
ec69d651 | 2972 | for (i = 0; rdl(mp, SMI_REG) & ETH_SMI_BUSY; i++) { |
1da177e4 | 2973 | if (i == PHY_WAIT_ITERATIONS) { |
c1b35a28 | 2974 | printk("%s: PHY busy timeout\n", mp->dev->name); |
1da177e4 LT |
2975 | goto out; |
2976 | } | |
2977 | udelay(PHY_WAIT_MICRO_SECONDS); | |
2978 | } | |
2979 | ||
ec69d651 | 2980 | wrl(mp, SMI_REG, (phy_addr << 16) | (phy_reg << 21) | |
1da177e4 LT |
2981 | ETH_SMI_OPCODE_WRITE | (value & 0xffff)); |
2982 | out: | |
2983 | spin_unlock_irqrestore(&mv643xx_eth_phy_lock, flags); | |
2984 | } | |
2985 | ||
c28a4f89 JC |
2986 | /* |
2987 | * Wrappers for MII support library. | |
2988 | */ | |
2989 | static int mv643xx_mdio_read(struct net_device *dev, int phy_id, int location) | |
2990 | { | |
c28a4f89 | 2991 | struct mv643xx_private *mp = netdev_priv(dev); |
afdb57a2 | 2992 | int val; |
c28a4f89 | 2993 | |
afdb57a2 | 2994 | eth_port_read_smi_reg(mp, location, &val); |
c28a4f89 JC |
2995 | return val; |
2996 | } | |
2997 | ||
2998 | static void mv643xx_mdio_write(struct net_device *dev, int phy_id, int location, int val) | |
2999 | { | |
3000 | struct mv643xx_private *mp = netdev_priv(dev); | |
afdb57a2 | 3001 | eth_port_write_smi_reg(mp, location, val); |
c28a4f89 JC |
3002 | } |
3003 | ||
1da177e4 LT |
3004 | /* |
3005 | * eth_port_receive - Get received information from Rx ring. | |
3006 | * | |
3007 | * DESCRIPTION: | |
3008 | * This routine returns the received data to the caller. There is no | |
3009 | * data copying during routine operation. All information is returned | |
3010 | * using pointer to packet information struct passed from the caller. | |
3011 | * If the routine exhausts Rx ring resources then the resource error flag | |
3012 | * is set. | |
3013 | * | |
3014 | * INPUT: | |
3015 | * struct mv643xx_private *mp Ethernet Port Control srtuct. | |
3016 | * struct pkt_info *p_pkt_info User packet buffer. | |
3017 | * | |
3018 | * OUTPUT: | |
3019 | * Rx ring current and used indexes are updated. | |
3020 | * | |
3021 | * RETURN: | |
3022 | * ETH_ERROR in case the routine can not access Rx desc ring. | |
3023 | * ETH_QUEUE_FULL if Rx ring resources are exhausted. | |
3024 | * ETH_END_OF_JOB if there is no received data. | |
3025 | * ETH_OK otherwise. | |
3026 | */ | |
3027 | static ETH_FUNC_RET_STATUS eth_port_receive(struct mv643xx_private *mp, | |
3028 | struct pkt_info *p_pkt_info) | |
3029 | { | |
3030 | int rx_next_curr_desc, rx_curr_desc, rx_used_desc; | |
3031 | volatile struct eth_rx_desc *p_rx_desc; | |
3032 | unsigned int command_status; | |
8f518703 | 3033 | unsigned long flags; |
1da177e4 LT |
3034 | |
3035 | /* Do not process Rx ring in case of Rx ring resource error */ | |
3036 | if (mp->rx_resource_err) | |
3037 | return ETH_QUEUE_FULL; | |
3038 | ||
8f518703 DF |
3039 | spin_lock_irqsave(&mp->lock, flags); |
3040 | ||
1da177e4 LT |
3041 | /* Get the Rx Desc ring 'curr and 'used' indexes */ |
3042 | rx_curr_desc = mp->rx_curr_desc_q; | |
3043 | rx_used_desc = mp->rx_used_desc_q; | |
3044 | ||
3045 | p_rx_desc = &mp->p_rx_desc_area[rx_curr_desc]; | |
3046 | ||
3047 | /* The following parameters are used to save readings from memory */ | |
3048 | command_status = p_rx_desc->cmd_sts; | |
3049 | rmb(); | |
3050 | ||
3051 | /* Nothing to receive... */ | |
8f518703 DF |
3052 | if (command_status & (ETH_BUFFER_OWNED_BY_DMA)) { |
3053 | spin_unlock_irqrestore(&mp->lock, flags); | |
1da177e4 | 3054 | return ETH_END_OF_JOB; |
8f518703 | 3055 | } |
1da177e4 LT |
3056 | |
3057 | p_pkt_info->byte_cnt = (p_rx_desc->byte_cnt) - RX_BUF_OFFSET; | |
3058 | p_pkt_info->cmd_sts = command_status; | |
3059 | p_pkt_info->buf_ptr = (p_rx_desc->buf_ptr) + RX_BUF_OFFSET; | |
3060 | p_pkt_info->return_info = mp->rx_skb[rx_curr_desc]; | |
3061 | p_pkt_info->l4i_chk = p_rx_desc->buf_size; | |
3062 | ||
b4de9051 DF |
3063 | /* |
3064 | * Clean the return info field to indicate that the | |
3065 | * packet has been moved to the upper layers | |
3066 | */ | |
1da177e4 LT |
3067 | mp->rx_skb[rx_curr_desc] = NULL; |
3068 | ||
3069 | /* Update current index in data structure */ | |
3070 | rx_next_curr_desc = (rx_curr_desc + 1) % mp->rx_ring_size; | |
3071 | mp->rx_curr_desc_q = rx_next_curr_desc; | |
3072 | ||
3073 | /* Rx descriptors exhausted. Set the Rx ring resource error flag */ | |
3074 | if (rx_next_curr_desc == rx_used_desc) | |
3075 | mp->rx_resource_err = 1; | |
3076 | ||
8f518703 DF |
3077 | spin_unlock_irqrestore(&mp->lock, flags); |
3078 | ||
1da177e4 LT |
3079 | return ETH_OK; |
3080 | } | |
3081 | ||
3082 | /* | |
3083 | * eth_rx_return_buff - Returns a Rx buffer back to the Rx ring. | |
3084 | * | |
3085 | * DESCRIPTION: | |
3086 | * This routine returns a Rx buffer back to the Rx ring. It retrieves the | |
3087 | * next 'used' descriptor and attached the returned buffer to it. | |
3088 | * In case the Rx ring was in "resource error" condition, where there are | |
3089 | * no available Rx resources, the function resets the resource error flag. | |
3090 | * | |
3091 | * INPUT: | |
3092 | * struct mv643xx_private *mp Ethernet Port Control srtuct. | |
3093 | * struct pkt_info *p_pkt_info Information on returned buffer. | |
3094 | * | |
3095 | * OUTPUT: | |
3096 | * New available Rx resource in Rx descriptor ring. | |
3097 | * | |
3098 | * RETURN: | |
3099 | * ETH_ERROR in case the routine can not access Rx desc ring. | |
3100 | * ETH_OK otherwise. | |
3101 | */ | |
3102 | static ETH_FUNC_RET_STATUS eth_rx_return_buff(struct mv643xx_private *mp, | |
3103 | struct pkt_info *p_pkt_info) | |
3104 | { | |
3105 | int used_rx_desc; /* Where to return Rx resource */ | |
3106 | volatile struct eth_rx_desc *p_used_rx_desc; | |
8f518703 DF |
3107 | unsigned long flags; |
3108 | ||
3109 | spin_lock_irqsave(&mp->lock, flags); | |
1da177e4 LT |
3110 | |
3111 | /* Get 'used' Rx descriptor */ | |
3112 | used_rx_desc = mp->rx_used_desc_q; | |
3113 | p_used_rx_desc = &mp->p_rx_desc_area[used_rx_desc]; | |
3114 | ||
3115 | p_used_rx_desc->buf_ptr = p_pkt_info->buf_ptr; | |
3116 | p_used_rx_desc->buf_size = p_pkt_info->byte_cnt; | |
3117 | mp->rx_skb[used_rx_desc] = p_pkt_info->return_info; | |
3118 | ||
3119 | /* Flush the write pipe */ | |
3120 | ||
3121 | /* Return the descriptor to DMA ownership */ | |
3122 | wmb(); | |
3123 | p_used_rx_desc->cmd_sts = | |
3124 | ETH_BUFFER_OWNED_BY_DMA | ETH_RX_ENABLE_INTERRUPT; | |
3125 | wmb(); | |
3126 | ||
3127 | /* Move the used descriptor pointer to the next descriptor */ | |
3128 | mp->rx_used_desc_q = (used_rx_desc + 1) % mp->rx_ring_size; | |
3129 | ||
3130 | /* Any Rx return cancels the Rx resource error status */ | |
3131 | mp->rx_resource_err = 0; | |
3132 | ||
8f518703 DF |
3133 | spin_unlock_irqrestore(&mp->lock, flags); |
3134 | ||
1da177e4 LT |
3135 | return ETH_OK; |
3136 | } | |
3137 | ||
3138 | /************* Begin ethtool support *************************/ | |
3139 | ||
3140 | struct mv643xx_stats { | |
3141 | char stat_string[ETH_GSTRING_LEN]; | |
3142 | int sizeof_stat; | |
3143 | int stat_offset; | |
3144 | }; | |
3145 | ||
7a6d84c1 | 3146 | #define MV643XX_STAT(m) FIELD_SIZEOF(struct mv643xx_private, m), \ |
b4de9051 | 3147 | offsetof(struct mv643xx_private, m) |
1da177e4 LT |
3148 | |
3149 | static const struct mv643xx_stats mv643xx_gstrings_stats[] = { | |
3150 | { "rx_packets", MV643XX_STAT(stats.rx_packets) }, | |
3151 | { "tx_packets", MV643XX_STAT(stats.tx_packets) }, | |
3152 | { "rx_bytes", MV643XX_STAT(stats.rx_bytes) }, | |
3153 | { "tx_bytes", MV643XX_STAT(stats.tx_bytes) }, | |
3154 | { "rx_errors", MV643XX_STAT(stats.rx_errors) }, | |
3155 | { "tx_errors", MV643XX_STAT(stats.tx_errors) }, | |
3156 | { "rx_dropped", MV643XX_STAT(stats.rx_dropped) }, | |
3157 | { "tx_dropped", MV643XX_STAT(stats.tx_dropped) }, | |
3158 | { "good_octets_received", MV643XX_STAT(mib_counters.good_octets_received) }, | |
3159 | { "bad_octets_received", MV643XX_STAT(mib_counters.bad_octets_received) }, | |
3160 | { "internal_mac_transmit_err", MV643XX_STAT(mib_counters.internal_mac_transmit_err) }, | |
3161 | { "good_frames_received", MV643XX_STAT(mib_counters.good_frames_received) }, | |
3162 | { "bad_frames_received", MV643XX_STAT(mib_counters.bad_frames_received) }, | |
3163 | { "broadcast_frames_received", MV643XX_STAT(mib_counters.broadcast_frames_received) }, | |
3164 | { "multicast_frames_received", MV643XX_STAT(mib_counters.multicast_frames_received) }, | |
3165 | { "frames_64_octets", MV643XX_STAT(mib_counters.frames_64_octets) }, | |
3166 | { "frames_65_to_127_octets", MV643XX_STAT(mib_counters.frames_65_to_127_octets) }, | |
3167 | { "frames_128_to_255_octets", MV643XX_STAT(mib_counters.frames_128_to_255_octets) }, | |
3168 | { "frames_256_to_511_octets", MV643XX_STAT(mib_counters.frames_256_to_511_octets) }, | |
3169 | { "frames_512_to_1023_octets", MV643XX_STAT(mib_counters.frames_512_to_1023_octets) }, | |
3170 | { "frames_1024_to_max_octets", MV643XX_STAT(mib_counters.frames_1024_to_max_octets) }, | |
3171 | { "good_octets_sent", MV643XX_STAT(mib_counters.good_octets_sent) }, | |
3172 | { "good_frames_sent", MV643XX_STAT(mib_counters.good_frames_sent) }, | |
3173 | { "excessive_collision", MV643XX_STAT(mib_counters.excessive_collision) }, | |
3174 | { "multicast_frames_sent", MV643XX_STAT(mib_counters.multicast_frames_sent) }, | |
3175 | { "broadcast_frames_sent", MV643XX_STAT(mib_counters.broadcast_frames_sent) }, | |
3176 | { "unrec_mac_control_received", MV643XX_STAT(mib_counters.unrec_mac_control_received) }, | |
3177 | { "fc_sent", MV643XX_STAT(mib_counters.fc_sent) }, | |
3178 | { "good_fc_received", MV643XX_STAT(mib_counters.good_fc_received) }, | |
3179 | { "bad_fc_received", MV643XX_STAT(mib_counters.bad_fc_received) }, | |
3180 | { "undersize_received", MV643XX_STAT(mib_counters.undersize_received) }, | |
3181 | { "fragments_received", MV643XX_STAT(mib_counters.fragments_received) }, | |
3182 | { "oversize_received", MV643XX_STAT(mib_counters.oversize_received) }, | |
3183 | { "jabber_received", MV643XX_STAT(mib_counters.jabber_received) }, | |
3184 | { "mac_receive_error", MV643XX_STAT(mib_counters.mac_receive_error) }, | |
3185 | { "bad_crc_event", MV643XX_STAT(mib_counters.bad_crc_event) }, | |
3186 | { "collision", MV643XX_STAT(mib_counters.collision) }, | |
3187 | { "late_collision", MV643XX_STAT(mib_counters.late_collision) }, | |
3188 | }; | |
3189 | ||
ff8ac609 | 3190 | #define MV643XX_STATS_LEN ARRAY_SIZE(mv643xx_gstrings_stats) |
1da177e4 | 3191 | |
b4de9051 DF |
3192 | static void mv643xx_get_drvinfo(struct net_device *netdev, |
3193 | struct ethtool_drvinfo *drvinfo) | |
1da177e4 LT |
3194 | { |
3195 | strncpy(drvinfo->driver, mv643xx_driver_name, 32); | |
3196 | strncpy(drvinfo->version, mv643xx_driver_version, 32); | |
3197 | strncpy(drvinfo->fw_version, "N/A", 32); | |
3198 | strncpy(drvinfo->bus_info, "mv643xx", 32); | |
3199 | drvinfo->n_stats = MV643XX_STATS_LEN; | |
3200 | } | |
3201 | ||
b9f2c044 | 3202 | static int mv643xx_get_sset_count(struct net_device *netdev, int sset) |
1da177e4 | 3203 | { |
b9f2c044 JG |
3204 | switch (sset) { |
3205 | case ETH_SS_STATS: | |
3206 | return MV643XX_STATS_LEN; | |
3207 | default: | |
3208 | return -EOPNOTSUPP; | |
3209 | } | |
1da177e4 LT |
3210 | } |
3211 | ||
b4de9051 DF |
3212 | static void mv643xx_get_ethtool_stats(struct net_device *netdev, |
3213 | struct ethtool_stats *stats, uint64_t *data) | |
1da177e4 LT |
3214 | { |
3215 | struct mv643xx_private *mp = netdev->priv; | |
3216 | int i; | |
3217 | ||
3218 | eth_update_mib_counters(mp); | |
3219 | ||
b4de9051 | 3220 | for (i = 0; i < MV643XX_STATS_LEN; i++) { |
6aa20a22 | 3221 | char *p = (char *)mp+mv643xx_gstrings_stats[i].stat_offset; |
b4de9051 | 3222 | data[i] = (mv643xx_gstrings_stats[i].sizeof_stat == |
1da177e4 LT |
3223 | sizeof(uint64_t)) ? *(uint64_t *)p : *(uint32_t *)p; |
3224 | } | |
3225 | } | |
3226 | ||
b4de9051 DF |
3227 | static void mv643xx_get_strings(struct net_device *netdev, uint32_t stringset, |
3228 | uint8_t *data) | |
1da177e4 LT |
3229 | { |
3230 | int i; | |
3231 | ||
3232 | switch(stringset) { | |
3233 | case ETH_SS_STATS: | |
3234 | for (i=0; i < MV643XX_STATS_LEN; i++) { | |
b4de9051 DF |
3235 | memcpy(data + i * ETH_GSTRING_LEN, |
3236 | mv643xx_gstrings_stats[i].stat_string, | |
3237 | ETH_GSTRING_LEN); | |
1da177e4 LT |
3238 | } |
3239 | break; | |
3240 | } | |
3241 | } | |
3242 | ||
d0412d96 JC |
3243 | static u32 mv643xx_eth_get_link(struct net_device *dev) |
3244 | { | |
3245 | struct mv643xx_private *mp = netdev_priv(dev); | |
3246 | ||
3247 | return mii_link_ok(&mp->mii); | |
3248 | } | |
3249 | ||
3250 | static int mv643xx_eth_nway_restart(struct net_device *dev) | |
3251 | { | |
3252 | struct mv643xx_private *mp = netdev_priv(dev); | |
3253 | ||
3254 | return mii_nway_restart(&mp->mii); | |
3255 | } | |
3256 | ||
3257 | static int mv643xx_eth_do_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) | |
3258 | { | |
3259 | struct mv643xx_private *mp = netdev_priv(dev); | |
3260 | ||
3261 | return generic_mii_ioctl(&mp->mii, if_mii(ifr), cmd, NULL); | |
3262 | } | |
3263 | ||
7282d491 | 3264 | static const struct ethtool_ops mv643xx_ethtool_ops = { |
1da177e4 | 3265 | .get_settings = mv643xx_get_settings, |
d0412d96 | 3266 | .set_settings = mv643xx_set_settings, |
1da177e4 | 3267 | .get_drvinfo = mv643xx_get_drvinfo, |
d0412d96 | 3268 | .get_link = mv643xx_eth_get_link, |
1da177e4 | 3269 | .set_sg = ethtool_op_set_sg, |
194b2d0e | 3270 | .get_sset_count = mv643xx_get_sset_count, |
1da177e4 | 3271 | .get_ethtool_stats = mv643xx_get_ethtool_stats, |
d0412d96 | 3272 | .get_strings = mv643xx_get_strings, |
d0412d96 | 3273 | .nway_reset = mv643xx_eth_nway_restart, |
1da177e4 LT |
3274 | }; |
3275 | ||
3276 | /************* End ethtool support *************************/ |