blob: 615b3622ea67d07b39049a38f2261f74ce2ceb5c [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * drivers/net/mv643xx_eth.c - Driver for MV643XX ethernet ports
3 * Copyright (C) 2002 Matthew Dharm <mdharm@momenco.com>
4 *
5 * Based on the 64360 driver from:
6 * Copyright (C) 2002 rabeeh@galileo.co.il
7 *
8 * Copyright (C) 2003 PMC-Sierra, Inc.,
Olaf Hering3bb8a182006-01-05 22:45:45 -08009 * written by Manish Lachwani
Linus Torvalds1da177e2005-04-16 15:20:36 -070010 *
11 * Copyright (C) 2003 Ralf Baechle <ralf@linux-mips.org>
12 *
13 * Copyright (C) 2004-2005 MontaVista Software, Inc.
14 * Dale Farnsworth <dale@farnsworth.org>
15 *
16 * Copyright (C) 2004 Steven J. Hill <sjhill1@rockwellcollins.com>
17 * <sjhill@realitydiluted.com>
18 *
19 * This program is free software; you can redistribute it and/or
20 * modify it under the terms of the GNU General Public License
21 * as published by the Free Software Foundation; either version 2
22 * of the License, or (at your option) any later version.
23 *
24 * This program is distributed in the hope that it will be useful,
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27 * GNU General Public License for more details.
28 *
29 * You should have received a copy of the GNU General Public License
30 * along with this program; if not, write to the Free Software
31 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
32 */
33#include <linux/init.h>
34#include <linux/dma-mapping.h>
35#include <linux/tcp.h>
36#include <linux/udp.h>
37#include <linux/etherdevice.h>
Olaf Hering78a5e532006-01-16 16:47:00 -070038#include <linux/in.h>
39#include <linux/ip.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070040
41#include <linux/bitops.h>
42#include <linux/delay.h>
43#include <linux/ethtool.h>
Russell Kingd052d1b2005-10-29 19:07:23 +010044#include <linux/platform_device.h>
45
Linus Torvalds1da177e2005-04-16 15:20:36 -070046#include <asm/io.h>
47#include <asm/types.h>
48#include <asm/pgtable.h>
49#include <asm/system.h>
50#include <asm/delay.h>
51#include "mv643xx_eth.h"
52
53/*
54 * The first part is the high level driver of the gigE ethernet ports.
55 */
56
57/* Constants */
58#define VLAN_HLEN 4
59#define FCS_LEN 4
Dale Farnsworthb44cd572006-01-16 16:51:22 -070060#define DMA_ALIGN 8 /* hw requires 8-byte alignment */
61#define HW_IP_ALIGN 2 /* hw aligns IP header */
62#define WRAP HW_IP_ALIGN + ETH_HLEN + VLAN_HLEN + FCS_LEN
Linus Torvalds1da177e2005-04-16 15:20:36 -070063#define RX_SKB_SIZE ((dev->mtu + WRAP + 7) & ~0x7)
64
65#define INT_CAUSE_UNMASK_ALL 0x0007ffff
66#define INT_CAUSE_UNMASK_ALL_EXT 0x0011ffff
Linus Torvalds1da177e2005-04-16 15:20:36 -070067#define INT_CAUSE_MASK_ALL 0x00000000
Dale Farnsworth63c9e542005-09-02 13:49:10 -070068#define INT_CAUSE_MASK_ALL_EXT 0x00000000
Linus Torvalds1da177e2005-04-16 15:20:36 -070069#define INT_CAUSE_CHECK_BITS INT_CAUSE_UNMASK_ALL
70#define INT_CAUSE_CHECK_BITS_EXT INT_CAUSE_UNMASK_ALL_EXT
Linus Torvalds1da177e2005-04-16 15:20:36 -070071
72#ifdef MV643XX_CHECKSUM_OFFLOAD_TX
73#define MAX_DESCS_PER_SKB (MAX_SKB_FRAGS + 1)
74#else
75#define MAX_DESCS_PER_SKB 1
76#endif
77
78#define PHY_WAIT_ITERATIONS 1000 /* 1000 iterations * 10uS = 10mS max */
79#define PHY_WAIT_MICRO_SECONDS 10
80
81/* Static function declarations */
82static int eth_port_link_is_up(unsigned int eth_port_num);
83static void eth_port_uc_addr_get(struct net_device *dev,
84 unsigned char *MacAddr);
Dale Farnsworth16e03012006-01-16 16:50:02 -070085static void eth_port_set_multicast_list(struct net_device *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070086static int mv643xx_eth_real_open(struct net_device *);
87static int mv643xx_eth_real_stop(struct net_device *);
88static int mv643xx_eth_change_mtu(struct net_device *, int);
89static struct net_device_stats *mv643xx_eth_get_stats(struct net_device *);
90static void eth_port_init_mac_tables(unsigned int eth_port_num);
91#ifdef MV643XX_NAPI
92static int mv643xx_poll(struct net_device *dev, int *budget);
93#endif
94static void ethernet_phy_set(unsigned int eth_port_num, int phy_addr);
95static int ethernet_phy_detect(unsigned int eth_port_num);
96static struct ethtool_ops mv643xx_ethtool_ops;
97
98static char mv643xx_driver_name[] = "mv643xx_eth";
99static char mv643xx_driver_version[] = "1.0";
100
101static void __iomem *mv643xx_eth_shared_base;
102
103/* used to protect MV643XX_ETH_SMI_REG, which is shared across ports */
Ingo Molnara9f6a0d2005-09-09 13:10:41 -0700104static DEFINE_SPINLOCK(mv643xx_eth_phy_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105
106static inline u32 mv_read(int offset)
107{
Al Virodc074a82005-04-25 07:55:58 -0700108 void __iomem *reg_base;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109
110 reg_base = mv643xx_eth_shared_base - MV643XX_ETH_SHARED_REGS;
111
112 return readl(reg_base + offset);
113}
114
115static inline void mv_write(int offset, u32 data)
116{
Al Virodc074a82005-04-25 07:55:58 -0700117 void __iomem *reg_base;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118
119 reg_base = mv643xx_eth_shared_base - MV643XX_ETH_SHARED_REGS;
120 writel(data, reg_base + offset);
121}
122
123/*
124 * Changes MTU (maximum transfer unit) of the gigabit ethenret port
125 *
126 * Input : pointer to ethernet interface network device structure
127 * new mtu size
128 * Output : 0 upon success, -EINVAL upon failure
129 */
130static int mv643xx_eth_change_mtu(struct net_device *dev, int new_mtu)
131{
Dale Farnsworth8f518702006-01-16 16:56:30 -0700132 if ((new_mtu > 9500) || (new_mtu < 64))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134
135 dev->mtu = new_mtu;
136 /*
137 * Stop then re-open the interface. This will allocate RX skb's with
138 * the new MTU.
139 * There is a possible danger that the open will not successed, due
140 * to memory is full, which might fail the open function.
141 */
142 if (netif_running(dev)) {
143 if (mv643xx_eth_real_stop(dev))
144 printk(KERN_ERR
145 "%s: Fatal error on stopping device\n",
146 dev->name);
147 if (mv643xx_eth_real_open(dev))
148 printk(KERN_ERR
149 "%s: Fatal error on opening device\n",
150 dev->name);
151 }
152
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153 return 0;
154}
155
156/*
157 * mv643xx_eth_rx_task
158 *
159 * Fills / refills RX queue on a certain gigabit ethernet port
160 *
161 * Input : pointer to ethernet interface network device structure
162 * Output : N/A
163 */
164static void mv643xx_eth_rx_task(void *data)
165{
166 struct net_device *dev = (struct net_device *)data;
167 struct mv643xx_private *mp = netdev_priv(dev);
168 struct pkt_info pkt_info;
169 struct sk_buff *skb;
Dale Farnsworthb44cd572006-01-16 16:51:22 -0700170 int unaligned;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171
172 if (test_and_set_bit(0, &mp->rx_task_busy))
173 panic("%s: Error in test_set_bit / clear_bit", dev->name);
174
175 while (mp->rx_ring_skbs < (mp->rx_ring_size - 5)) {
Dale Farnsworthb44cd572006-01-16 16:51:22 -0700176 skb = dev_alloc_skb(RX_SKB_SIZE + DMA_ALIGN);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177 if (!skb)
178 break;
179 mp->rx_ring_skbs++;
Dale Farnsworthb44cd572006-01-16 16:51:22 -0700180 unaligned = (u32)skb->data & (DMA_ALIGN - 1);
181 if (unaligned)
182 skb_reserve(skb, DMA_ALIGN - unaligned);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183 pkt_info.cmd_sts = ETH_RX_ENABLE_INTERRUPT;
184 pkt_info.byte_cnt = RX_SKB_SIZE;
185 pkt_info.buf_ptr = dma_map_single(NULL, skb->data, RX_SKB_SIZE,
186 DMA_FROM_DEVICE);
187 pkt_info.return_info = skb;
188 if (eth_rx_return_buff(mp, &pkt_info) != ETH_OK) {
189 printk(KERN_ERR
190 "%s: Error allocating RX Ring\n", dev->name);
191 break;
192 }
Dale Farnsworthb44cd572006-01-16 16:51:22 -0700193 skb_reserve(skb, HW_IP_ALIGN);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194 }
195 clear_bit(0, &mp->rx_task_busy);
196 /*
197 * If RX ring is empty of SKB, set a timer to try allocating
198 * again in a later time .
199 */
200 if ((mp->rx_ring_skbs == 0) && (mp->rx_timer_flag == 0)) {
201 printk(KERN_INFO "%s: Rx ring is empty\n", dev->name);
202 /* After 100mSec */
203 mp->timeout.expires = jiffies + (HZ / 10);
204 add_timer(&mp->timeout);
205 mp->rx_timer_flag = 1;
206 }
207#ifdef MV643XX_RX_QUEUE_FILL_ON_TASK
208 else {
209 /* Return interrupts */
210 mv_write(MV643XX_ETH_INTERRUPT_MASK_REG(mp->port_num),
211 INT_CAUSE_UNMASK_ALL);
212 }
213#endif
214}
215
216/*
217 * mv643xx_eth_rx_task_timer_wrapper
218 *
219 * Timer routine to wake up RX queue filling task. This function is
220 * used only in case the RX queue is empty, and all alloc_skb has
221 * failed (due to out of memory event).
222 *
223 * Input : pointer to ethernet interface network device structure
224 * Output : N/A
225 */
226static void mv643xx_eth_rx_task_timer_wrapper(unsigned long data)
227{
228 struct net_device *dev = (struct net_device *)data;
229 struct mv643xx_private *mp = netdev_priv(dev);
230
231 mp->rx_timer_flag = 0;
232 mv643xx_eth_rx_task((void *)data);
233}
234
235/*
236 * mv643xx_eth_update_mac_address
237 *
238 * Update the MAC address of the port in the address table
239 *
240 * Input : pointer to ethernet interface network device structure
241 * Output : N/A
242 */
243static void mv643xx_eth_update_mac_address(struct net_device *dev)
244{
245 struct mv643xx_private *mp = netdev_priv(dev);
246 unsigned int port_num = mp->port_num;
247
248 eth_port_init_mac_tables(port_num);
249 memcpy(mp->port_mac_addr, dev->dev_addr, 6);
250 eth_port_uc_addr_set(port_num, mp->port_mac_addr);
251}
252
253/*
254 * mv643xx_eth_set_rx_mode
255 *
256 * Change from promiscuos to regular rx mode
257 *
258 * Input : pointer to ethernet interface network device structure
259 * Output : N/A
260 */
261static void mv643xx_eth_set_rx_mode(struct net_device *dev)
262{
263 struct mv643xx_private *mp = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265 if (dev->flags & IFF_PROMISC)
Dale Farnsworth7342cd82005-09-02 12:36:48 -0700266 mp->port_config |= (u32) MV643XX_ETH_UNICAST_PROMISCUOUS_MODE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267 else
Dale Farnsworth7342cd82005-09-02 12:36:48 -0700268 mp->port_config &= ~(u32) MV643XX_ETH_UNICAST_PROMISCUOUS_MODE;
269
270 mv_write(MV643XX_ETH_PORT_CONFIG_REG(mp->port_num), mp->port_config);
Dale Farnsworth16e03012006-01-16 16:50:02 -0700271
272 eth_port_set_multicast_list(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273}
274
275/*
276 * mv643xx_eth_set_mac_address
277 *
278 * Change the interface's mac address.
279 * No special hardware thing should be done because interface is always
280 * put in promiscuous mode.
281 *
282 * Input : pointer to ethernet interface network device structure and
283 * a pointer to the designated entry to be added to the cache.
284 * Output : zero upon success, negative upon failure
285 */
286static int mv643xx_eth_set_mac_address(struct net_device *dev, void *addr)
287{
288 int i;
289
290 for (i = 0; i < 6; i++)
291 /* +2 is for the offset of the HW addr type */
292 dev->dev_addr[i] = ((unsigned char *)addr)[i + 2];
293 mv643xx_eth_update_mac_address(dev);
294 return 0;
295}
296
297/*
298 * mv643xx_eth_tx_timeout
299 *
300 * Called upon a timeout on transmitting a packet
301 *
302 * Input : pointer to ethernet interface network device structure.
303 * Output : N/A
304 */
305static void mv643xx_eth_tx_timeout(struct net_device *dev)
306{
307 struct mv643xx_private *mp = netdev_priv(dev);
308
309 printk(KERN_INFO "%s: TX timeout ", dev->name);
310
311 /* Do the reset outside of interrupt context */
312 schedule_work(&mp->tx_timeout_task);
313}
314
315/*
316 * mv643xx_eth_tx_timeout_task
317 *
318 * Actual routine to reset the adapter when a timeout on Tx has occurred
319 */
320static void mv643xx_eth_tx_timeout_task(struct net_device *dev)
321{
322 struct mv643xx_private *mp = netdev_priv(dev);
323
324 netif_device_detach(dev);
325 eth_port_reset(mp->port_num);
326 eth_port_start(mp);
327 netif_device_attach(dev);
328}
329
330/*
331 * mv643xx_eth_free_tx_queue
332 *
333 * Input : dev - a pointer to the required interface
334 *
335 * Output : 0 if was able to release skb , nonzero otherwise
336 */
337static int mv643xx_eth_free_tx_queue(struct net_device *dev,
338 unsigned int eth_int_cause_ext)
339{
340 struct mv643xx_private *mp = netdev_priv(dev);
341 struct net_device_stats *stats = &mp->stats;
342 struct pkt_info pkt_info;
343 int released = 1;
344
345 if (!(eth_int_cause_ext & (BIT0 | BIT8)))
346 return released;
347
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348 /* Check only queue 0 */
349 while (eth_tx_return_desc(mp, &pkt_info) == ETH_OK) {
350 if (pkt_info.cmd_sts & BIT0) {
351 printk("%s: Error in TX\n", dev->name);
352 stats->tx_errors++;
353 }
354
Paolo Galtiericb415d32006-01-16 16:48:02 -0700355 if (pkt_info.cmd_sts & ETH_TX_FIRST_DESC)
356 dma_unmap_single(NULL, pkt_info.buf_ptr,
357 pkt_info.byte_cnt,
358 DMA_TO_DEVICE);
359 else
360 dma_unmap_page(NULL, pkt_info.buf_ptr,
361 pkt_info.byte_cnt,
362 DMA_TO_DEVICE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363
Paolo Galtiericb415d32006-01-16 16:48:02 -0700364 if (pkt_info.return_info) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365 dev_kfree_skb_irq(pkt_info.return_info);
366 released = 0;
Paolo Galtiericb415d32006-01-16 16:48:02 -0700367 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368 }
369
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370 return released;
371}
372
373/*
374 * mv643xx_eth_receive
375 *
376 * This function is forward packets that are received from the port's
377 * queues toward kernel core or FastRoute them to another interface.
378 *
379 * Input : dev - a pointer to the required interface
380 * max - maximum number to receive (0 means unlimted)
381 *
382 * Output : number of served packets
383 */
384#ifdef MV643XX_NAPI
385static int mv643xx_eth_receive_queue(struct net_device *dev, int budget)
386#else
387static int mv643xx_eth_receive_queue(struct net_device *dev)
388#endif
389{
390 struct mv643xx_private *mp = netdev_priv(dev);
391 struct net_device_stats *stats = &mp->stats;
392 unsigned int received_packets = 0;
393 struct sk_buff *skb;
394 struct pkt_info pkt_info;
395
396#ifdef MV643XX_NAPI
Dale Farnsworthb1dd9ca2005-09-01 09:59:23 -0700397 while (budget-- > 0 && eth_port_receive(mp, &pkt_info) == ETH_OK) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398#else
399 while (eth_port_receive(mp, &pkt_info) == ETH_OK) {
400#endif
401 mp->rx_ring_skbs--;
402 received_packets++;
Dale Farnsworthb1dd9ca2005-09-01 09:59:23 -0700403
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404 /* Update statistics. Note byte count includes 4 byte CRC count */
405 stats->rx_packets++;
406 stats->rx_bytes += pkt_info.byte_cnt;
407 skb = pkt_info.return_info;
408 /*
409 * In case received a packet without first / last bits on OR
410 * the error summary bit is on, the packets needs to be dropeed.
411 */
412 if (((pkt_info.cmd_sts
413 & (ETH_RX_FIRST_DESC | ETH_RX_LAST_DESC)) !=
414 (ETH_RX_FIRST_DESC | ETH_RX_LAST_DESC))
415 || (pkt_info.cmd_sts & ETH_ERROR_SUMMARY)) {
416 stats->rx_dropped++;
417 if ((pkt_info.cmd_sts & (ETH_RX_FIRST_DESC |
418 ETH_RX_LAST_DESC)) !=
419 (ETH_RX_FIRST_DESC | ETH_RX_LAST_DESC)) {
420 if (net_ratelimit())
421 printk(KERN_ERR
422 "%s: Received packet spread "
423 "on multiple descriptors\n",
424 dev->name);
425 }
426 if (pkt_info.cmd_sts & ETH_ERROR_SUMMARY)
427 stats->rx_errors++;
428
429 dev_kfree_skb_irq(skb);
430 } else {
431 /*
432 * The -4 is for the CRC in the trailer of the
433 * received packet
434 */
435 skb_put(skb, pkt_info.byte_cnt - 4);
436 skb->dev = dev;
437
438 if (pkt_info.cmd_sts & ETH_LAYER_4_CHECKSUM_OK) {
439 skb->ip_summed = CHECKSUM_UNNECESSARY;
440 skb->csum = htons(
441 (pkt_info.cmd_sts & 0x0007fff8) >> 3);
442 }
443 skb->protocol = eth_type_trans(skb, dev);
444#ifdef MV643XX_NAPI
445 netif_receive_skb(skb);
446#else
447 netif_rx(skb);
448#endif
449 }
450 }
451
452 return received_packets;
453}
454
455/*
456 * mv643xx_eth_int_handler
457 *
458 * Main interrupt handler for the gigbit ethernet ports
459 *
460 * Input : irq - irq number (not used)
461 * dev_id - a pointer to the required interface's data structure
462 * regs - not used
463 * Output : N/A
464 */
465
466static irqreturn_t mv643xx_eth_int_handler(int irq, void *dev_id,
467 struct pt_regs *regs)
468{
469 struct net_device *dev = (struct net_device *)dev_id;
470 struct mv643xx_private *mp = netdev_priv(dev);
471 u32 eth_int_cause, eth_int_cause_ext = 0;
472 unsigned int port_num = mp->port_num;
473
474 /* Read interrupt cause registers */
475 eth_int_cause = mv_read(MV643XX_ETH_INTERRUPT_CAUSE_REG(port_num)) &
476 INT_CAUSE_UNMASK_ALL;
477
478 if (eth_int_cause & BIT1)
479 eth_int_cause_ext = mv_read(
480 MV643XX_ETH_INTERRUPT_CAUSE_EXTEND_REG(port_num)) &
481 INT_CAUSE_UNMASK_ALL_EXT;
482
483#ifdef MV643XX_NAPI
484 if (!(eth_int_cause & 0x0007fffd)) {
485 /* Dont ack the Rx interrupt */
486#endif
487 /*
488 * Clear specific ethernet port intrerrupt registers by
489 * acknowleding relevant bits.
490 */
491 mv_write(MV643XX_ETH_INTERRUPT_CAUSE_REG(port_num),
492 ~eth_int_cause);
493 if (eth_int_cause_ext != 0x0)
494 mv_write(MV643XX_ETH_INTERRUPT_CAUSE_EXTEND_REG
495 (port_num), ~eth_int_cause_ext);
496
497 /* UDP change : We may need this */
498 if ((eth_int_cause_ext & 0x0000ffff) &&
499 (mv643xx_eth_free_tx_queue(dev, eth_int_cause_ext) == 0) &&
500 (mp->tx_ring_size > mp->tx_ring_skbs + MAX_DESCS_PER_SKB))
501 netif_wake_queue(dev);
502#ifdef MV643XX_NAPI
503 } else {
504 if (netif_rx_schedule_prep(dev)) {
505 /* Mask all the interrupts */
506 mv_write(MV643XX_ETH_INTERRUPT_MASK_REG(port_num), 0);
507 mv_write(MV643XX_ETH_INTERRUPT_EXTEND_MASK_REG
508 (port_num), 0);
Dale Farnsworth8f518702006-01-16 16:56:30 -0700509 /* ensure previous writes have taken effect */
510 mv_read(MV643XX_ETH_INTERRUPT_EXTEND_MASK_REG(port_num));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511 __netif_rx_schedule(dev);
512 }
513#else
514 if (eth_int_cause & (BIT2 | BIT11))
515 mv643xx_eth_receive_queue(dev, 0);
516
517 /*
518 * After forwarded received packets to upper layer, add a task
519 * in an interrupts enabled context that refills the RX ring
520 * with skb's.
521 */
522#ifdef MV643XX_RX_QUEUE_FILL_ON_TASK
523 /* Unmask all interrupts on ethernet port */
524 mv_write(MV643XX_ETH_INTERRUPT_MASK_REG(port_num),
525 INT_CAUSE_MASK_ALL);
Dale Farnsworth8f518702006-01-16 16:56:30 -0700526 /* wait for previous write to take effect */
527 mv_read(MV643XX_ETH_INTERRUPT_MASK_REG(port_num));
528
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529 queue_task(&mp->rx_task, &tq_immediate);
530 mark_bh(IMMEDIATE_BH);
531#else
532 mp->rx_task.func(dev);
533#endif
534#endif
535 }
536 /* PHY status changed */
537 if (eth_int_cause_ext & (BIT16 | BIT20)) {
538 if (eth_port_link_is_up(port_num)) {
539 netif_carrier_on(dev);
540 netif_wake_queue(dev);
541 /* Start TX queue */
542 mv_write(MV643XX_ETH_TRANSMIT_QUEUE_COMMAND_REG
543 (port_num), 1);
544 } else {
545 netif_carrier_off(dev);
546 netif_stop_queue(dev);
547 }
548 }
549
550 /*
551 * If no real interrupt occured, exit.
552 * This can happen when using gigE interrupt coalescing mechanism.
553 */
554 if ((eth_int_cause == 0x0) && (eth_int_cause_ext == 0x0))
555 return IRQ_NONE;
556
557 return IRQ_HANDLED;
558}
559
560#ifdef MV643XX_COAL
561
562/*
563 * eth_port_set_rx_coal - Sets coalescing interrupt mechanism on RX path
564 *
565 * DESCRIPTION:
566 * This routine sets the RX coalescing interrupt mechanism parameter.
567 * This parameter is a timeout counter, that counts in 64 t_clk
568 * chunks ; that when timeout event occurs a maskable interrupt
569 * occurs.
570 * The parameter is calculated using the tClk of the MV-643xx chip
571 * , and the required delay of the interrupt in usec.
572 *
573 * INPUT:
574 * unsigned int eth_port_num Ethernet port number
575 * unsigned int t_clk t_clk of the MV-643xx chip in HZ units
576 * unsigned int delay Delay in usec
577 *
578 * OUTPUT:
579 * Interrupt coalescing mechanism value is set in MV-643xx chip.
580 *
581 * RETURN:
582 * The interrupt coalescing value set in the gigE port.
583 *
584 */
585static unsigned int eth_port_set_rx_coal(unsigned int eth_port_num,
586 unsigned int t_clk, unsigned int delay)
587{
588 unsigned int coal = ((t_clk / 1000000) * delay) / 64;
589
590 /* Set RX Coalescing mechanism */
591 mv_write(MV643XX_ETH_SDMA_CONFIG_REG(eth_port_num),
592 ((coal & 0x3fff) << 8) |
593 (mv_read(MV643XX_ETH_SDMA_CONFIG_REG(eth_port_num))
594 & 0xffc000ff));
595
596 return coal;
597}
598#endif
599
600/*
601 * eth_port_set_tx_coal - Sets coalescing interrupt mechanism on TX path
602 *
603 * DESCRIPTION:
604 * This routine sets the TX coalescing interrupt mechanism parameter.
605 * This parameter is a timeout counter, that counts in 64 t_clk
606 * chunks ; that when timeout event occurs a maskable interrupt
607 * occurs.
608 * The parameter is calculated using the t_cLK frequency of the
609 * MV-643xx chip and the required delay in the interrupt in uSec
610 *
611 * INPUT:
612 * unsigned int eth_port_num Ethernet port number
613 * unsigned int t_clk t_clk of the MV-643xx chip in HZ units
614 * unsigned int delay Delay in uSeconds
615 *
616 * OUTPUT:
617 * Interrupt coalescing mechanism value is set in MV-643xx chip.
618 *
619 * RETURN:
620 * The interrupt coalescing value set in the gigE port.
621 *
622 */
623static unsigned int eth_port_set_tx_coal(unsigned int eth_port_num,
624 unsigned int t_clk, unsigned int delay)
625{
626 unsigned int coal;
627 coal = ((t_clk / 1000000) * delay) / 64;
628 /* Set TX Coalescing mechanism */
629 mv_write(MV643XX_ETH_TX_FIFO_URGENT_THRESHOLD_REG(eth_port_num),
630 coal << 4);
631 return coal;
632}
633
634/*
635 * mv643xx_eth_open
636 *
637 * This function is called when openning the network device. The function
638 * should initialize all the hardware, initialize cyclic Rx/Tx
639 * descriptors chain and buffers and allocate an IRQ to the network
640 * device.
641 *
642 * Input : a pointer to the network device structure
643 *
644 * Output : zero of success , nonzero if fails.
645 */
646
647static int mv643xx_eth_open(struct net_device *dev)
648{
649 struct mv643xx_private *mp = netdev_priv(dev);
650 unsigned int port_num = mp->port_num;
651 int err;
652
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653 err = request_irq(dev->irq, mv643xx_eth_int_handler,
Benjamin Herrenschmidt16b81752005-04-16 15:24:30 -0700654 SA_SHIRQ | SA_SAMPLE_RANDOM, dev->name, dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655 if (err) {
656 printk(KERN_ERR "Can not assign IRQ number to MV643XX_eth%d\n",
657 port_num);
Dale Farnsworth8f518702006-01-16 16:56:30 -0700658 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700659 }
660
661 if (mv643xx_eth_real_open(dev)) {
662 printk("%s: Error opening interface\n", dev->name);
Dale Farnsworth8f518702006-01-16 16:56:30 -0700663 free_irq(dev->irq, dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664 err = -EBUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700665 }
666
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667 return err;
668}
669
670/*
671 * ether_init_rx_desc_ring - Curve a Rx chain desc list and buffer in memory.
672 *
673 * DESCRIPTION:
674 * This function prepares a Rx chained list of descriptors and packet
675 * buffers in a form of a ring. The routine must be called after port
676 * initialization routine and before port start routine.
677 * The Ethernet SDMA engine uses CPU bus addresses to access the various
678 * devices in the system (i.e. DRAM). This function uses the ethernet
679 * struct 'virtual to physical' routine (set by the user) to set the ring
680 * with physical addresses.
681 *
682 * INPUT:
683 * struct mv643xx_private *mp Ethernet Port Control srtuct.
684 *
685 * OUTPUT:
686 * The routine updates the Ethernet port control struct with information
687 * regarding the Rx descriptors and buffers.
688 *
689 * RETURN:
690 * None.
691 */
692static void ether_init_rx_desc_ring(struct mv643xx_private *mp)
693{
694 volatile struct eth_rx_desc *p_rx_desc;
695 int rx_desc_num = mp->rx_ring_size;
696 int i;
697
698 /* initialize the next_desc_ptr links in the Rx descriptors ring */
699 p_rx_desc = (struct eth_rx_desc *)mp->p_rx_desc_area;
700 for (i = 0; i < rx_desc_num; i++) {
701 p_rx_desc[i].next_desc_ptr = mp->rx_desc_dma +
702 ((i + 1) % rx_desc_num) * sizeof(struct eth_rx_desc);
703 }
704
705 /* Save Rx desc pointer to driver struct. */
706 mp->rx_curr_desc_q = 0;
707 mp->rx_used_desc_q = 0;
708
709 mp->rx_desc_area_size = rx_desc_num * sizeof(struct eth_rx_desc);
710
711 /* Add the queue to the list of RX queues of this port */
712 mp->port_rx_queue_command |= 1;
713}
714
715/*
716 * ether_init_tx_desc_ring - Curve a Tx chain desc list and buffer in memory.
717 *
718 * DESCRIPTION:
719 * This function prepares a Tx chained list of descriptors and packet
720 * buffers in a form of a ring. The routine must be called after port
721 * initialization routine and before port start routine.
722 * The Ethernet SDMA engine uses CPU bus addresses to access the various
723 * devices in the system (i.e. DRAM). This function uses the ethernet
724 * struct 'virtual to physical' routine (set by the user) to set the ring
725 * with physical addresses.
726 *
727 * INPUT:
728 * struct mv643xx_private *mp Ethernet Port Control srtuct.
729 *
730 * OUTPUT:
731 * The routine updates the Ethernet port control struct with information
732 * regarding the Tx descriptors and buffers.
733 *
734 * RETURN:
735 * None.
736 */
737static void ether_init_tx_desc_ring(struct mv643xx_private *mp)
738{
739 int tx_desc_num = mp->tx_ring_size;
740 struct eth_tx_desc *p_tx_desc;
741 int i;
742
743 /* Initialize the next_desc_ptr links in the Tx descriptors ring */
744 p_tx_desc = (struct eth_tx_desc *)mp->p_tx_desc_area;
745 for (i = 0; i < tx_desc_num; i++) {
746 p_tx_desc[i].next_desc_ptr = mp->tx_desc_dma +
747 ((i + 1) % tx_desc_num) * sizeof(struct eth_tx_desc);
748 }
749
750 mp->tx_curr_desc_q = 0;
751 mp->tx_used_desc_q = 0;
752#ifdef MV643XX_CHECKSUM_OFFLOAD_TX
753 mp->tx_first_desc_q = 0;
754#endif
755
756 mp->tx_desc_area_size = tx_desc_num * sizeof(struct eth_tx_desc);
757
758 /* Add the queue to the list of Tx queues of this port */
759 mp->port_tx_queue_command |= 1;
760}
761
762/* Helper function for mv643xx_eth_open */
763static int mv643xx_eth_real_open(struct net_device *dev)
764{
765 struct mv643xx_private *mp = netdev_priv(dev);
766 unsigned int port_num = mp->port_num;
767 unsigned int size;
768
769 /* Stop RX Queues */
770 mv_write(MV643XX_ETH_RECEIVE_QUEUE_COMMAND_REG(port_num), 0x0000ff00);
771
Linus Torvalds1da177e2005-04-16 15:20:36 -0700772 /* Set the MAC Address */
773 memcpy(mp->port_mac_addr, dev->dev_addr, 6);
774
775 eth_port_init(mp);
776
777 INIT_WORK(&mp->rx_task, (void (*)(void *))mv643xx_eth_rx_task, dev);
778
779 memset(&mp->timeout, 0, sizeof(struct timer_list));
780 mp->timeout.function = mv643xx_eth_rx_task_timer_wrapper;
781 mp->timeout.data = (unsigned long)dev;
782
783 mp->rx_task_busy = 0;
784 mp->rx_timer_flag = 0;
785
786 /* Allocate RX and TX skb rings */
787 mp->rx_skb = kmalloc(sizeof(*mp->rx_skb) * mp->rx_ring_size,
788 GFP_KERNEL);
789 if (!mp->rx_skb) {
790 printk(KERN_ERR "%s: Cannot allocate Rx skb ring\n", dev->name);
791 return -ENOMEM;
792 }
793 mp->tx_skb = kmalloc(sizeof(*mp->tx_skb) * mp->tx_ring_size,
794 GFP_KERNEL);
795 if (!mp->tx_skb) {
796 printk(KERN_ERR "%s: Cannot allocate Tx skb ring\n", dev->name);
797 kfree(mp->rx_skb);
798 return -ENOMEM;
799 }
800
801 /* Allocate TX ring */
802 mp->tx_ring_skbs = 0;
803 size = mp->tx_ring_size * sizeof(struct eth_tx_desc);
804 mp->tx_desc_area_size = size;
805
806 if (mp->tx_sram_size) {
807 mp->p_tx_desc_area = ioremap(mp->tx_sram_addr,
808 mp->tx_sram_size);
809 mp->tx_desc_dma = mp->tx_sram_addr;
810 } else
811 mp->p_tx_desc_area = dma_alloc_coherent(NULL, size,
812 &mp->tx_desc_dma,
813 GFP_KERNEL);
814
815 if (!mp->p_tx_desc_area) {
816 printk(KERN_ERR "%s: Cannot allocate Tx Ring (size %d bytes)\n",
817 dev->name, size);
818 kfree(mp->rx_skb);
819 kfree(mp->tx_skb);
820 return -ENOMEM;
821 }
822 BUG_ON((u32) mp->p_tx_desc_area & 0xf); /* check 16-byte alignment */
823 memset((void *)mp->p_tx_desc_area, 0, mp->tx_desc_area_size);
824
825 ether_init_tx_desc_ring(mp);
826
827 /* Allocate RX ring */
828 mp->rx_ring_skbs = 0;
829 size = mp->rx_ring_size * sizeof(struct eth_rx_desc);
830 mp->rx_desc_area_size = size;
831
832 if (mp->rx_sram_size) {
833 mp->p_rx_desc_area = ioremap(mp->rx_sram_addr,
834 mp->rx_sram_size);
835 mp->rx_desc_dma = mp->rx_sram_addr;
836 } else
837 mp->p_rx_desc_area = dma_alloc_coherent(NULL, size,
838 &mp->rx_desc_dma,
839 GFP_KERNEL);
840
841 if (!mp->p_rx_desc_area) {
842 printk(KERN_ERR "%s: Cannot allocate Rx ring (size %d bytes)\n",
843 dev->name, size);
844 printk(KERN_ERR "%s: Freeing previously allocated TX queues...",
845 dev->name);
846 if (mp->rx_sram_size)
Dale Farnsworthdd09b1d2006-01-16 16:53:15 -0700847 iounmap(mp->p_tx_desc_area);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700848 else
849 dma_free_coherent(NULL, mp->tx_desc_area_size,
850 mp->p_tx_desc_area, mp->tx_desc_dma);
851 kfree(mp->rx_skb);
852 kfree(mp->tx_skb);
853 return -ENOMEM;
854 }
855 memset((void *)mp->p_rx_desc_area, 0, size);
856
857 ether_init_rx_desc_ring(mp);
858
859 mv643xx_eth_rx_task(dev); /* Fill RX ring with skb's */
860
861 eth_port_start(mp);
862
863 /* Interrupt Coalescing */
864
865#ifdef MV643XX_COAL
866 mp->rx_int_coal =
867 eth_port_set_rx_coal(port_num, 133000000, MV643XX_RX_COAL);
868#endif
869
870 mp->tx_int_coal =
871 eth_port_set_tx_coal(port_num, 133000000, MV643XX_TX_COAL);
872
Dale Farnsworth8f518702006-01-16 16:56:30 -0700873 /* Clear any pending ethernet port interrupts */
874 mv_write(MV643XX_ETH_INTERRUPT_CAUSE_REG(port_num), 0);
875 mv_write(MV643XX_ETH_INTERRUPT_CAUSE_EXTEND_REG(port_num), 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700876
Dale Farnsworth8f518702006-01-16 16:56:30 -0700877 /* Unmask phy and link status changes interrupts */
878 mv_write(MV643XX_ETH_INTERRUPT_EXTEND_MASK_REG(port_num),
879 INT_CAUSE_UNMASK_ALL_EXT);
880
881 /* Unmask RX buffer and TX end interrupt */
882 mv_write(MV643XX_ETH_INTERRUPT_MASK_REG(port_num),
883 INT_CAUSE_UNMASK_ALL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700884 return 0;
885}
886
887static void mv643xx_eth_free_tx_rings(struct net_device *dev)
888{
889 struct mv643xx_private *mp = netdev_priv(dev);
890 unsigned int port_num = mp->port_num;
891 unsigned int curr;
892
893 /* Stop Tx Queues */
894 mv_write(MV643XX_ETH_TRANSMIT_QUEUE_COMMAND_REG(port_num), 0x0000ff00);
895
896 /* Free outstanding skb's on TX rings */
897 for (curr = 0; mp->tx_ring_skbs && curr < mp->tx_ring_size; curr++) {
898 if (mp->tx_skb[curr]) {
899 dev_kfree_skb(mp->tx_skb[curr]);
900 mp->tx_ring_skbs--;
901 }
902 }
903 if (mp->tx_ring_skbs)
904 printk("%s: Error on Tx descriptor free - could not free %d"
905 " descriptors\n", dev->name, mp->tx_ring_skbs);
906
907 /* Free TX ring */
908 if (mp->tx_sram_size)
909 iounmap(mp->p_tx_desc_area);
910 else
911 dma_free_coherent(NULL, mp->tx_desc_area_size,
912 mp->p_tx_desc_area, mp->tx_desc_dma);
913}
914
915static void mv643xx_eth_free_rx_rings(struct net_device *dev)
916{
917 struct mv643xx_private *mp = netdev_priv(dev);
918 unsigned int port_num = mp->port_num;
919 int curr;
920
921 /* Stop RX Queues */
922 mv_write(MV643XX_ETH_RECEIVE_QUEUE_COMMAND_REG(port_num), 0x0000ff00);
923
924 /* Free preallocated skb's on RX rings */
925 for (curr = 0; mp->rx_ring_skbs && curr < mp->rx_ring_size; curr++) {
926 if (mp->rx_skb[curr]) {
927 dev_kfree_skb(mp->rx_skb[curr]);
928 mp->rx_ring_skbs--;
929 }
930 }
931
932 if (mp->rx_ring_skbs)
933 printk(KERN_ERR
934 "%s: Error in freeing Rx Ring. %d skb's still"
935 " stuck in RX Ring - ignoring them\n", dev->name,
936 mp->rx_ring_skbs);
937 /* Free RX ring */
938 if (mp->rx_sram_size)
939 iounmap(mp->p_rx_desc_area);
940 else
941 dma_free_coherent(NULL, mp->rx_desc_area_size,
942 mp->p_rx_desc_area, mp->rx_desc_dma);
943}
944
945/*
946 * mv643xx_eth_stop
947 *
948 * This function is used when closing the network device.
949 * It updates the hardware,
950 * release all memory that holds buffers and descriptors and release the IRQ.
951 * Input : a pointer to the device structure
952 * Output : zero if success , nonzero if fails
953 */
954
955/* Helper function for mv643xx_eth_stop */
956
957static int mv643xx_eth_real_stop(struct net_device *dev)
958{
959 struct mv643xx_private *mp = netdev_priv(dev);
960 unsigned int port_num = mp->port_num;
961
Linus Torvalds1da177e2005-04-16 15:20:36 -0700962 /* Mask RX buffer and TX end interrupt */
963 mv_write(MV643XX_ETH_INTERRUPT_MASK_REG(port_num), 0);
964
965 /* Mask phy and link status changes interrupts */
966 mv_write(MV643XX_ETH_INTERRUPT_EXTEND_MASK_REG(port_num), 0);
967
Dale Farnsworth8f518702006-01-16 16:56:30 -0700968 /* ensure previous writes have taken effect */
969 mv_read(MV643XX_ETH_INTERRUPT_MASK_REG(port_num));
970
971#ifdef MV643XX_NAPI
972 netif_poll_disable(dev);
973#endif
974 netif_carrier_off(dev);
975 netif_stop_queue(dev);
976
977 eth_port_reset(mp->port_num);
978
979 mv643xx_eth_free_tx_rings(dev);
980 mv643xx_eth_free_rx_rings(dev);
981
982#ifdef MV643XX_NAPI
983 netif_poll_enable(dev);
984#endif
985
Linus Torvalds1da177e2005-04-16 15:20:36 -0700986 return 0;
987}
988
989static int mv643xx_eth_stop(struct net_device *dev)
990{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700991 mv643xx_eth_real_stop(dev);
992
993 free_irq(dev->irq, dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700994
995 return 0;
996}
997
998#ifdef MV643XX_NAPI
999static void mv643xx_tx(struct net_device *dev)
1000{
1001 struct mv643xx_private *mp = netdev_priv(dev);
1002 struct pkt_info pkt_info;
1003
1004 while (eth_tx_return_desc(mp, &pkt_info) == ETH_OK) {
Paolo Galtiericb415d32006-01-16 16:48:02 -07001005 if (pkt_info.cmd_sts & ETH_TX_FIRST_DESC)
1006 dma_unmap_single(NULL, pkt_info.buf_ptr,
1007 pkt_info.byte_cnt,
1008 DMA_TO_DEVICE);
1009 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07001010 dma_unmap_page(NULL, pkt_info.buf_ptr,
Paolo Galtiericb415d32006-01-16 16:48:02 -07001011 pkt_info.byte_cnt,
1012 DMA_TO_DEVICE);
1013
1014 if (pkt_info.return_info)
1015 dev_kfree_skb_irq(pkt_info.return_info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001016 }
1017
1018 if (netif_queue_stopped(dev) &&
1019 mp->tx_ring_size > mp->tx_ring_skbs + MAX_DESCS_PER_SKB)
1020 netif_wake_queue(dev);
1021}
1022
1023/*
1024 * mv643xx_poll
1025 *
1026 * This function is used in case of NAPI
1027 */
1028static int mv643xx_poll(struct net_device *dev, int *budget)
1029{
1030 struct mv643xx_private *mp = netdev_priv(dev);
1031 int done = 1, orig_budget, work_done;
1032 unsigned int port_num = mp->port_num;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001033
1034#ifdef MV643XX_TX_FAST_REFILL
1035 if (++mp->tx_clean_threshold > 5) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001036 mv643xx_tx(dev);
1037 mp->tx_clean_threshold = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001038 }
1039#endif
1040
1041 if ((mv_read(MV643XX_ETH_RX_CURRENT_QUEUE_DESC_PTR_0(port_num)))
1042 != (u32) mp->rx_used_desc_q) {
1043 orig_budget = *budget;
1044 if (orig_budget > dev->quota)
1045 orig_budget = dev->quota;
1046 work_done = mv643xx_eth_receive_queue(dev, orig_budget);
1047 mp->rx_task.func(dev);
1048 *budget -= work_done;
1049 dev->quota -= work_done;
1050 if (work_done >= orig_budget)
1051 done = 0;
1052 }
1053
1054 if (done) {
Dale Farnsworth8f518702006-01-16 16:56:30 -07001055 netif_rx_complete(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001056 mv_write(MV643XX_ETH_INTERRUPT_CAUSE_REG(port_num), 0);
1057 mv_write(MV643XX_ETH_INTERRUPT_CAUSE_EXTEND_REG(port_num), 0);
1058 mv_write(MV643XX_ETH_INTERRUPT_MASK_REG(port_num),
1059 INT_CAUSE_UNMASK_ALL);
1060 mv_write(MV643XX_ETH_INTERRUPT_EXTEND_MASK_REG(port_num),
1061 INT_CAUSE_UNMASK_ALL_EXT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001062 }
1063
1064 return done ? 0 : 1;
1065}
1066#endif
1067
Paul Janzenf7ea3332006-01-16 16:52:13 -07001068/* Hardware can't handle unaligned fragments smaller than 9 bytes.
1069 * This helper function detects that case.
1070 */
1071
1072static inline unsigned int has_tiny_unaligned_frags(struct sk_buff *skb)
1073{
1074 unsigned int frag;
1075 skb_frag_t *fragp;
1076
1077 for (frag = 0; frag < skb_shinfo(skb)->nr_frags; frag++) {
1078 fragp = &skb_shinfo(skb)->frags[frag];
1079 if (fragp->size <= 8 && fragp->page_offset & 0x7)
1080 return 1;
1081
1082 }
1083 return 0;
1084}
1085
1086
Linus Torvalds1da177e2005-04-16 15:20:36 -07001087/*
1088 * mv643xx_eth_start_xmit
1089 *
1090 * This function is queues a packet in the Tx descriptor for
1091 * required port.
1092 *
1093 * Input : skb - a pointer to socket buffer
1094 * dev - a pointer to the required port
1095 *
1096 * Output : zero upon success
1097 */
1098static int mv643xx_eth_start_xmit(struct sk_buff *skb, struct net_device *dev)
1099{
1100 struct mv643xx_private *mp = netdev_priv(dev);
1101 struct net_device_stats *stats = &mp->stats;
1102 ETH_FUNC_RET_STATUS status;
1103 unsigned long flags;
1104 struct pkt_info pkt_info;
1105
1106 if (netif_queue_stopped(dev)) {
1107 printk(KERN_ERR
1108 "%s: Tried sending packet when interface is stopped\n",
1109 dev->name);
1110 return 1;
1111 }
1112
1113 /* This is a hard error, log it. */
1114 if ((mp->tx_ring_size - mp->tx_ring_skbs) <=
1115 (skb_shinfo(skb)->nr_frags + 1)) {
1116 netif_stop_queue(dev);
1117 printk(KERN_ERR
1118 "%s: Bug in mv643xx_eth - Trying to transmit when"
1119 " queue full !\n", dev->name);
1120 return 1;
1121 }
1122
1123 /* Paranoid check - this shouldn't happen */
1124 if (skb == NULL) {
1125 stats->tx_dropped++;
1126 printk(KERN_ERR "mv64320_eth paranoid check failed\n");
1127 return 1;
1128 }
1129
Paul Janzenf7ea3332006-01-16 16:52:13 -07001130#ifdef MV643XX_CHECKSUM_OFFLOAD_TX
1131 if (has_tiny_unaligned_frags(skb)) {
1132 if ((skb_linearize(skb, GFP_ATOMIC) != 0)) {
1133 stats->tx_dropped++;
1134 printk(KERN_DEBUG "%s: failed to linearize tiny "
1135 "unaligned fragment\n", dev->name);
1136 return 1;
1137 }
1138 }
1139
Linus Torvalds1da177e2005-04-16 15:20:36 -07001140 spin_lock_irqsave(&mp->lock, flags);
1141
Linus Torvalds1da177e2005-04-16 15:20:36 -07001142 if (!skb_shinfo(skb)->nr_frags) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001143 if (skb->ip_summed != CHECKSUM_HW) {
Dale Farnsworth26006362005-08-22 15:53:29 -07001144 /* Errata BTS #50, IHL must be 5 if no HW checksum */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001145 pkt_info.cmd_sts = ETH_TX_ENABLE_INTERRUPT |
Dale Farnsworth26006362005-08-22 15:53:29 -07001146 ETH_TX_FIRST_DESC |
1147 ETH_TX_LAST_DESC |
1148 5 << ETH_TX_IHL_SHIFT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001149 pkt_info.l4i_chk = 0;
1150 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001151 pkt_info.cmd_sts = ETH_TX_ENABLE_INTERRUPT |
Dale Farnsworth26006362005-08-22 15:53:29 -07001152 ETH_TX_FIRST_DESC |
1153 ETH_TX_LAST_DESC |
1154 ETH_GEN_TCP_UDP_CHECKSUM |
1155 ETH_GEN_IP_V_4_CHECKSUM |
1156 skb->nh.iph->ihl << ETH_TX_IHL_SHIFT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001157 /* CPU already calculated pseudo header checksum. */
Wolfram Joost63890572006-01-16 16:57:41 -07001158 if ((skb->protocol == ETH_P_IP) &&
1159 (skb->nh.iph->protocol == IPPROTO_UDP) ) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001160 pkt_info.cmd_sts |= ETH_UDP_FRAME;
1161 pkt_info.l4i_chk = skb->h.uh->check;
Wolfram Joost63890572006-01-16 16:57:41 -07001162 } else if ((skb->protocol == ETH_P_IP) &&
1163 (skb->nh.iph->protocol == IPPROTO_TCP))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001164 pkt_info.l4i_chk = skb->h.th->check;
1165 else {
1166 printk(KERN_ERR
Wolfram Joost63890572006-01-16 16:57:41 -07001167 "%s: chksum proto != IPv4 TCP or UDP\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001168 dev->name);
1169 spin_unlock_irqrestore(&mp->lock, flags);
1170 return 1;
1171 }
1172 }
1173 pkt_info.byte_cnt = skb->len;
1174 pkt_info.buf_ptr = dma_map_single(NULL, skb->data, skb->len,
1175 DMA_TO_DEVICE);
1176 pkt_info.return_info = skb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001177 status = eth_port_send(mp, &pkt_info);
1178 if ((status == ETH_ERROR) || (status == ETH_QUEUE_FULL))
1179 printk(KERN_ERR "%s: Error on transmitting packet\n",
1180 dev->name);
1181 stats->tx_bytes += pkt_info.byte_cnt;
1182 } else {
1183 unsigned int frag;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001184
Linus Torvalds1da177e2005-04-16 15:20:36 -07001185 /* first frag which is skb header */
1186 pkt_info.byte_cnt = skb_headlen(skb);
1187 pkt_info.buf_ptr = dma_map_single(NULL, skb->data,
1188 skb_headlen(skb),
1189 DMA_TO_DEVICE);
1190 pkt_info.l4i_chk = 0;
1191 pkt_info.return_info = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001192
Dale Farnsworth26006362005-08-22 15:53:29 -07001193 if (skb->ip_summed != CHECKSUM_HW)
1194 /* Errata BTS #50, IHL must be 5 if no HW checksum */
1195 pkt_info.cmd_sts = ETH_TX_FIRST_DESC |
1196 5 << ETH_TX_IHL_SHIFT;
1197 else {
1198 pkt_info.cmd_sts = ETH_TX_FIRST_DESC |
1199 ETH_GEN_TCP_UDP_CHECKSUM |
1200 ETH_GEN_IP_V_4_CHECKSUM |
1201 skb->nh.iph->ihl << ETH_TX_IHL_SHIFT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001202 /* CPU already calculated pseudo header checksum. */
Wolfram Joost63890572006-01-16 16:57:41 -07001203 if ((skb->protocol == ETH_P_IP) &&
1204 (skb->nh.iph->protocol == IPPROTO_UDP)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001205 pkt_info.cmd_sts |= ETH_UDP_FRAME;
1206 pkt_info.l4i_chk = skb->h.uh->check;
Wolfram Joost63890572006-01-16 16:57:41 -07001207 } else if ((skb->protocol == ETH_P_IP) &&
1208 (skb->nh.iph->protocol == IPPROTO_TCP))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001209 pkt_info.l4i_chk = skb->h.th->check;
1210 else {
1211 printk(KERN_ERR
Wolfram Joost63890572006-01-16 16:57:41 -07001212 "%s: chksum proto != IPv4 TCP or UDP\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001213 dev->name);
1214 spin_unlock_irqrestore(&mp->lock, flags);
1215 return 1;
1216 }
1217 }
1218
1219 status = eth_port_send(mp, &pkt_info);
1220 if (status != ETH_OK) {
1221 if ((status == ETH_ERROR))
1222 printk(KERN_ERR
1223 "%s: Error on transmitting packet\n",
1224 dev->name);
1225 if (status == ETH_QUEUE_FULL)
1226 printk("Error on Queue Full \n");
1227 if (status == ETH_QUEUE_LAST_RESOURCE)
1228 printk("Tx resource error \n");
1229 }
1230 stats->tx_bytes += pkt_info.byte_cnt;
1231
1232 /* Check for the remaining frags */
1233 for (frag = 0; frag < skb_shinfo(skb)->nr_frags; frag++) {
1234 skb_frag_t *this_frag = &skb_shinfo(skb)->frags[frag];
1235 pkt_info.l4i_chk = 0x0000;
1236 pkt_info.cmd_sts = 0x00000000;
1237
1238 /* Last Frag enables interrupt and frees the skb */
1239 if (frag == (skb_shinfo(skb)->nr_frags - 1)) {
1240 pkt_info.cmd_sts |= ETH_TX_ENABLE_INTERRUPT |
1241 ETH_TX_LAST_DESC;
1242 pkt_info.return_info = skb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001243 } else {
1244 pkt_info.return_info = 0;
1245 }
1246 pkt_info.l4i_chk = 0;
1247 pkt_info.byte_cnt = this_frag->size;
1248
1249 pkt_info.buf_ptr = dma_map_page(NULL, this_frag->page,
1250 this_frag->page_offset,
1251 this_frag->size,
1252 DMA_TO_DEVICE);
1253
1254 status = eth_port_send(mp, &pkt_info);
1255
1256 if (status != ETH_OK) {
1257 if ((status == ETH_ERROR))
1258 printk(KERN_ERR "%s: Error on "
1259 "transmitting packet\n",
1260 dev->name);
1261
1262 if (status == ETH_QUEUE_LAST_RESOURCE)
1263 printk("Tx resource error \n");
1264
1265 if (status == ETH_QUEUE_FULL)
1266 printk("Queue is full \n");
1267 }
1268 stats->tx_bytes += pkt_info.byte_cnt;
1269 }
1270 }
1271#else
Paul Janzenf7ea3332006-01-16 16:52:13 -07001272 spin_lock_irqsave(&mp->lock, flags);
1273
Linus Torvalds1da177e2005-04-16 15:20:36 -07001274 pkt_info.cmd_sts = ETH_TX_ENABLE_INTERRUPT | ETH_TX_FIRST_DESC |
1275 ETH_TX_LAST_DESC;
1276 pkt_info.l4i_chk = 0;
1277 pkt_info.byte_cnt = skb->len;
1278 pkt_info.buf_ptr = dma_map_single(NULL, skb->data, skb->len,
1279 DMA_TO_DEVICE);
1280 pkt_info.return_info = skb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001281 status = eth_port_send(mp, &pkt_info);
1282 if ((status == ETH_ERROR) || (status == ETH_QUEUE_FULL))
1283 printk(KERN_ERR "%s: Error on transmitting packet\n",
1284 dev->name);
1285 stats->tx_bytes += pkt_info.byte_cnt;
1286#endif
1287
1288 /* Check if TX queue can handle another skb. If not, then
1289 * signal higher layers to stop requesting TX
1290 */
1291 if (mp->tx_ring_size <= (mp->tx_ring_skbs + MAX_DESCS_PER_SKB))
1292 /*
1293 * Stop getting skb's from upper layers.
1294 * Getting skb's from upper layers will be enabled again after
1295 * packets are released.
1296 */
1297 netif_stop_queue(dev);
1298
1299 /* Update statistics and start of transmittion time */
1300 stats->tx_packets++;
1301 dev->trans_start = jiffies;
1302
1303 spin_unlock_irqrestore(&mp->lock, flags);
1304
1305 return 0; /* success */
1306}
1307
1308/*
1309 * mv643xx_eth_get_stats
1310 *
1311 * Returns a pointer to the interface statistics.
1312 *
1313 * Input : dev - a pointer to the required interface
1314 *
1315 * Output : a pointer to the interface's statistics
1316 */
1317
1318static struct net_device_stats *mv643xx_eth_get_stats(struct net_device *dev)
1319{
1320 struct mv643xx_private *mp = netdev_priv(dev);
1321
1322 return &mp->stats;
1323}
1324
Dale Farnsworth63c9e542005-09-02 13:49:10 -07001325#ifdef CONFIG_NET_POLL_CONTROLLER
1326static inline void mv643xx_enable_irq(struct mv643xx_private *mp)
1327{
1328 int port_num = mp->port_num;
1329 unsigned long flags;
1330
1331 spin_lock_irqsave(&mp->lock, flags);
1332 mv_write(MV643XX_ETH_INTERRUPT_MASK_REG(port_num),
1333 INT_CAUSE_UNMASK_ALL);
1334 mv_write(MV643XX_ETH_INTERRUPT_EXTEND_MASK_REG(port_num),
1335 INT_CAUSE_UNMASK_ALL_EXT);
1336 spin_unlock_irqrestore(&mp->lock, flags);
1337}
1338
1339static inline void mv643xx_disable_irq(struct mv643xx_private *mp)
1340{
1341 int port_num = mp->port_num;
1342 unsigned long flags;
1343
1344 spin_lock_irqsave(&mp->lock, flags);
1345 mv_write(MV643XX_ETH_INTERRUPT_MASK_REG(port_num),
1346 INT_CAUSE_MASK_ALL);
1347 mv_write(MV643XX_ETH_INTERRUPT_EXTEND_MASK_REG(port_num),
1348 INT_CAUSE_MASK_ALL_EXT);
1349 spin_unlock_irqrestore(&mp->lock, flags);
1350}
1351
1352static void mv643xx_netpoll(struct net_device *netdev)
1353{
1354 struct mv643xx_private *mp = netdev_priv(netdev);
1355
1356 mv643xx_disable_irq(mp);
1357 mv643xx_eth_int_handler(netdev->irq, netdev, NULL);
1358 mv643xx_enable_irq(mp);
1359}
1360#endif
1361
Linus Torvalds1da177e2005-04-16 15:20:36 -07001362/*/
1363 * mv643xx_eth_probe
1364 *
1365 * First function called after registering the network device.
1366 * It's purpose is to initialize the device as an ethernet device,
1367 * fill the ethernet device structure with pointers * to functions,
1368 * and set the MAC address of the interface
1369 *
1370 * Input : struct device *
1371 * Output : -ENOMEM if failed , 0 if success
1372 */
Russell King3ae5eae2005-11-09 22:32:44 +00001373static int mv643xx_eth_probe(struct platform_device *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001374{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001375 struct mv643xx_eth_platform_data *pd;
1376 int port_num = pdev->id;
1377 struct mv643xx_private *mp;
1378 struct net_device *dev;
1379 u8 *p;
1380 struct resource *res;
1381 int err;
1382
1383 dev = alloc_etherdev(sizeof(struct mv643xx_private));
1384 if (!dev)
1385 return -ENOMEM;
1386
Russell King3ae5eae2005-11-09 22:32:44 +00001387 platform_set_drvdata(pdev, dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001388
1389 mp = netdev_priv(dev);
1390
1391 res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
1392 BUG_ON(!res);
1393 dev->irq = res->start;
1394
1395 mp->port_num = port_num;
1396
1397 dev->open = mv643xx_eth_open;
1398 dev->stop = mv643xx_eth_stop;
1399 dev->hard_start_xmit = mv643xx_eth_start_xmit;
1400 dev->get_stats = mv643xx_eth_get_stats;
1401 dev->set_mac_address = mv643xx_eth_set_mac_address;
1402 dev->set_multicast_list = mv643xx_eth_set_rx_mode;
1403
1404 /* No need to Tx Timeout */
1405 dev->tx_timeout = mv643xx_eth_tx_timeout;
1406#ifdef MV643XX_NAPI
1407 dev->poll = mv643xx_poll;
1408 dev->weight = 64;
1409#endif
1410
Dale Farnsworth63c9e542005-09-02 13:49:10 -07001411#ifdef CONFIG_NET_POLL_CONTROLLER
1412 dev->poll_controller = mv643xx_netpoll;
1413#endif
1414
Linus Torvalds1da177e2005-04-16 15:20:36 -07001415 dev->watchdog_timeo = 2 * HZ;
1416 dev->tx_queue_len = mp->tx_ring_size;
1417 dev->base_addr = 0;
1418 dev->change_mtu = mv643xx_eth_change_mtu;
1419 SET_ETHTOOL_OPS(dev, &mv643xx_ethtool_ops);
1420
1421#ifdef MV643XX_CHECKSUM_OFFLOAD_TX
1422#ifdef MAX_SKB_FRAGS
1423 /*
1424 * Zero copy can only work if we use Discovery II memory. Else, we will
1425 * have to map the buffers to ISA memory which is only 16 MB
1426 */
Wolfram Joost63890572006-01-16 16:57:41 -07001427 dev->features = NETIF_F_SG | NETIF_F_IP_CSUM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001428#endif
1429#endif
1430
1431 /* Configure the timeout task */
1432 INIT_WORK(&mp->tx_timeout_task,
1433 (void (*)(void *))mv643xx_eth_tx_timeout_task, dev);
1434
1435 spin_lock_init(&mp->lock);
1436
1437 /* set default config values */
1438 eth_port_uc_addr_get(dev, dev->dev_addr);
1439 mp->port_config = MV643XX_ETH_PORT_CONFIG_DEFAULT_VALUE;
1440 mp->port_config_extend = MV643XX_ETH_PORT_CONFIG_EXTEND_DEFAULT_VALUE;
1441 mp->port_sdma_config = MV643XX_ETH_PORT_SDMA_CONFIG_DEFAULT_VALUE;
1442 mp->port_serial_control = MV643XX_ETH_PORT_SERIAL_CONTROL_DEFAULT_VALUE;
1443 mp->rx_ring_size = MV643XX_ETH_PORT_DEFAULT_RECEIVE_QUEUE_SIZE;
1444 mp->tx_ring_size = MV643XX_ETH_PORT_DEFAULT_TRANSMIT_QUEUE_SIZE;
1445
1446 pd = pdev->dev.platform_data;
1447 if (pd) {
1448 if (pd->mac_addr != NULL)
1449 memcpy(dev->dev_addr, pd->mac_addr, 6);
1450
1451 if (pd->phy_addr || pd->force_phy_addr)
1452 ethernet_phy_set(port_num, pd->phy_addr);
1453
1454 if (pd->port_config || pd->force_port_config)
1455 mp->port_config = pd->port_config;
1456
1457 if (pd->port_config_extend || pd->force_port_config_extend)
1458 mp->port_config_extend = pd->port_config_extend;
1459
1460 if (pd->port_sdma_config || pd->force_port_sdma_config)
1461 mp->port_sdma_config = pd->port_sdma_config;
1462
1463 if (pd->port_serial_control || pd->force_port_serial_control)
1464 mp->port_serial_control = pd->port_serial_control;
1465
1466 if (pd->rx_queue_size)
1467 mp->rx_ring_size = pd->rx_queue_size;
1468
1469 if (pd->tx_queue_size)
1470 mp->tx_ring_size = pd->tx_queue_size;
1471
1472 if (pd->tx_sram_size) {
1473 mp->tx_sram_size = pd->tx_sram_size;
1474 mp->tx_sram_addr = pd->tx_sram_addr;
1475 }
1476
1477 if (pd->rx_sram_size) {
1478 mp->rx_sram_size = pd->rx_sram_size;
1479 mp->rx_sram_addr = pd->rx_sram_addr;
1480 }
1481 }
1482
1483 err = ethernet_phy_detect(port_num);
1484 if (err) {
1485 pr_debug("MV643xx ethernet port %d: "
1486 "No PHY detected at addr %d\n",
1487 port_num, ethernet_phy_get(port_num));
1488 return err;
1489 }
1490
1491 err = register_netdev(dev);
1492 if (err)
1493 goto out;
1494
1495 p = dev->dev_addr;
1496 printk(KERN_NOTICE
1497 "%s: port %d with MAC address %02x:%02x:%02x:%02x:%02x:%02x\n",
1498 dev->name, port_num, p[0], p[1], p[2], p[3], p[4], p[5]);
1499
1500 if (dev->features & NETIF_F_SG)
1501 printk(KERN_NOTICE "%s: Scatter Gather Enabled\n", dev->name);
1502
1503 if (dev->features & NETIF_F_IP_CSUM)
1504 printk(KERN_NOTICE "%s: TX TCP/IP Checksumming Supported\n",
1505 dev->name);
1506
1507#ifdef MV643XX_CHECKSUM_OFFLOAD_TX
1508 printk(KERN_NOTICE "%s: RX TCP/UDP Checksum Offload ON \n", dev->name);
1509#endif
1510
1511#ifdef MV643XX_COAL
1512 printk(KERN_NOTICE "%s: TX and RX Interrupt Coalescing ON \n",
1513 dev->name);
1514#endif
1515
1516#ifdef MV643XX_NAPI
1517 printk(KERN_NOTICE "%s: RX NAPI Enabled \n", dev->name);
1518#endif
1519
Nicolas DETb1529872005-10-28 17:46:30 -07001520 if (mp->tx_sram_size > 0)
1521 printk(KERN_NOTICE "%s: Using SRAM\n", dev->name);
1522
Linus Torvalds1da177e2005-04-16 15:20:36 -07001523 return 0;
1524
1525out:
1526 free_netdev(dev);
1527
1528 return err;
1529}
1530
Russell King3ae5eae2005-11-09 22:32:44 +00001531static int mv643xx_eth_remove(struct platform_device *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001532{
Russell King3ae5eae2005-11-09 22:32:44 +00001533 struct net_device *dev = platform_get_drvdata(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001534
1535 unregister_netdev(dev);
1536 flush_scheduled_work();
1537
1538 free_netdev(dev);
Russell King3ae5eae2005-11-09 22:32:44 +00001539 platform_set_drvdata(pdev, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001540 return 0;
1541}
1542
Russell King3ae5eae2005-11-09 22:32:44 +00001543static int mv643xx_eth_shared_probe(struct platform_device *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001544{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001545 struct resource *res;
1546
1547 printk(KERN_NOTICE "MV-643xx 10/100/1000 Ethernet Driver\n");
1548
1549 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1550 if (res == NULL)
1551 return -ENODEV;
1552
1553 mv643xx_eth_shared_base = ioremap(res->start,
1554 MV643XX_ETH_SHARED_REGS_SIZE);
1555 if (mv643xx_eth_shared_base == NULL)
1556 return -ENOMEM;
1557
1558 return 0;
1559
1560}
1561
Russell King3ae5eae2005-11-09 22:32:44 +00001562static int mv643xx_eth_shared_remove(struct platform_device *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001563{
1564 iounmap(mv643xx_eth_shared_base);
1565 mv643xx_eth_shared_base = NULL;
1566
1567 return 0;
1568}
1569
Russell King3ae5eae2005-11-09 22:32:44 +00001570static struct platform_driver mv643xx_eth_driver = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001571 .probe = mv643xx_eth_probe,
1572 .remove = mv643xx_eth_remove,
Russell King3ae5eae2005-11-09 22:32:44 +00001573 .driver = {
1574 .name = MV643XX_ETH_NAME,
1575 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001576};
1577
Russell King3ae5eae2005-11-09 22:32:44 +00001578static struct platform_driver mv643xx_eth_shared_driver = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001579 .probe = mv643xx_eth_shared_probe,
1580 .remove = mv643xx_eth_shared_remove,
Russell King3ae5eae2005-11-09 22:32:44 +00001581 .driver = {
1582 .name = MV643XX_ETH_SHARED_NAME,
1583 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001584};
1585
1586/*
1587 * mv643xx_init_module
1588 *
1589 * Registers the network drivers into the Linux kernel
1590 *
1591 * Input : N/A
1592 *
1593 * Output : N/A
1594 */
1595static int __init mv643xx_init_module(void)
1596{
1597 int rc;
1598
Russell King3ae5eae2005-11-09 22:32:44 +00001599 rc = platform_driver_register(&mv643xx_eth_shared_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001600 if (!rc) {
Russell King3ae5eae2005-11-09 22:32:44 +00001601 rc = platform_driver_register(&mv643xx_eth_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001602 if (rc)
Russell King3ae5eae2005-11-09 22:32:44 +00001603 platform_driver_unregister(&mv643xx_eth_shared_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001604 }
1605 return rc;
1606}
1607
1608/*
1609 * mv643xx_cleanup_module
1610 *
1611 * Registers the network drivers into the Linux kernel
1612 *
1613 * Input : N/A
1614 *
1615 * Output : N/A
1616 */
1617static void __exit mv643xx_cleanup_module(void)
1618{
Russell King3ae5eae2005-11-09 22:32:44 +00001619 platform_driver_unregister(&mv643xx_eth_driver);
1620 platform_driver_unregister(&mv643xx_eth_shared_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001621}
1622
1623module_init(mv643xx_init_module);
1624module_exit(mv643xx_cleanup_module);
1625
1626MODULE_LICENSE("GPL");
1627MODULE_AUTHOR( "Rabeeh Khoury, Assaf Hoffman, Matthew Dharm, Manish Lachwani"
1628 " and Dale Farnsworth");
1629MODULE_DESCRIPTION("Ethernet driver for Marvell MV643XX");
1630
1631/*
1632 * The second part is the low level driver of the gigE ethernet ports.
1633 */
1634
1635/*
1636 * Marvell's Gigabit Ethernet controller low level driver
1637 *
1638 * DESCRIPTION:
1639 * This file introduce low level API to Marvell's Gigabit Ethernet
1640 * controller. This Gigabit Ethernet Controller driver API controls
1641 * 1) Operations (i.e. port init, start, reset etc').
1642 * 2) Data flow (i.e. port send, receive etc').
1643 * Each Gigabit Ethernet port is controlled via
1644 * struct mv643xx_private.
1645 * This struct includes user configuration information as well as
1646 * driver internal data needed for its operations.
1647 *
1648 * Supported Features:
1649 * - This low level driver is OS independent. Allocating memory for
1650 * the descriptor rings and buffers are not within the scope of
1651 * this driver.
1652 * - The user is free from Rx/Tx queue managing.
1653 * - This low level driver introduce functionality API that enable
1654 * the to operate Marvell's Gigabit Ethernet Controller in a
1655 * convenient way.
1656 * - Simple Gigabit Ethernet port operation API.
1657 * - Simple Gigabit Ethernet port data flow API.
1658 * - Data flow and operation API support per queue functionality.
1659 * - Support cached descriptors for better performance.
1660 * - Enable access to all four DRAM banks and internal SRAM memory
1661 * spaces.
1662 * - PHY access and control API.
1663 * - Port control register configuration API.
1664 * - Full control over Unicast and Multicast MAC configurations.
1665 *
1666 * Operation flow:
1667 *
1668 * Initialization phase
1669 * This phase complete the initialization of the the
1670 * mv643xx_private struct.
1671 * User information regarding port configuration has to be set
1672 * prior to calling the port initialization routine.
1673 *
1674 * In this phase any port Tx/Rx activity is halted, MIB counters
1675 * are cleared, PHY address is set according to user parameter and
1676 * access to DRAM and internal SRAM memory spaces.
1677 *
1678 * Driver ring initialization
1679 * Allocating memory for the descriptor rings and buffers is not
1680 * within the scope of this driver. Thus, the user is required to
1681 * allocate memory for the descriptors ring and buffers. Those
1682 * memory parameters are used by the Rx and Tx ring initialization
1683 * routines in order to curve the descriptor linked list in a form
1684 * of a ring.
1685 * Note: Pay special attention to alignment issues when using
1686 * cached descriptors/buffers. In this phase the driver store
1687 * information in the mv643xx_private struct regarding each queue
1688 * ring.
1689 *
1690 * Driver start
1691 * This phase prepares the Ethernet port for Rx and Tx activity.
1692 * It uses the information stored in the mv643xx_private struct to
1693 * initialize the various port registers.
1694 *
1695 * Data flow:
1696 * All packet references to/from the driver are done using
1697 * struct pkt_info.
1698 * This struct is a unified struct used with Rx and Tx operations.
1699 * This way the user is not required to be familiar with neither
1700 * Tx nor Rx descriptors structures.
1701 * The driver's descriptors rings are management by indexes.
1702 * Those indexes controls the ring resources and used to indicate
1703 * a SW resource error:
1704 * 'current'
1705 * This index points to the current available resource for use. For
1706 * example in Rx process this index will point to the descriptor
1707 * that will be passed to the user upon calling the receive
1708 * routine. In Tx process, this index will point to the descriptor
1709 * that will be assigned with the user packet info and transmitted.
1710 * 'used'
1711 * This index points to the descriptor that need to restore its
1712 * resources. For example in Rx process, using the Rx buffer return
1713 * API will attach the buffer returned in packet info to the
1714 * descriptor pointed by 'used'. In Tx process, using the Tx
1715 * descriptor return will merely return the user packet info with
1716 * the command status of the transmitted buffer pointed by the
1717 * 'used' index. Nevertheless, it is essential to use this routine
1718 * to update the 'used' index.
1719 * 'first'
1720 * This index supports Tx Scatter-Gather. It points to the first
1721 * descriptor of a packet assembled of multiple buffers. For
1722 * example when in middle of Such packet we have a Tx resource
1723 * error the 'curr' index get the value of 'first' to indicate
1724 * that the ring returned to its state before trying to transmit
1725 * this packet.
1726 *
1727 * Receive operation:
1728 * The eth_port_receive API set the packet information struct,
1729 * passed by the caller, with received information from the
1730 * 'current' SDMA descriptor.
1731 * It is the user responsibility to return this resource back
1732 * to the Rx descriptor ring to enable the reuse of this source.
1733 * Return Rx resource is done using the eth_rx_return_buff API.
1734 *
1735 * Transmit operation:
1736 * The eth_port_send API supports Scatter-Gather which enables to
1737 * send a packet spanned over multiple buffers. This means that
1738 * for each packet info structure given by the user and put into
1739 * the Tx descriptors ring, will be transmitted only if the 'LAST'
1740 * bit will be set in the packet info command status field. This
1741 * API also consider restriction regarding buffer alignments and
1742 * sizes.
1743 * The user must return a Tx resource after ensuring the buffer
1744 * has been transmitted to enable the Tx ring indexes to update.
1745 *
1746 * BOARD LAYOUT
1747 * This device is on-board. No jumper diagram is necessary.
1748 *
1749 * EXTERNAL INTERFACE
1750 *
1751 * Prior to calling the initialization routine eth_port_init() the user
1752 * must set the following fields under mv643xx_private struct:
1753 * port_num User Ethernet port number.
1754 * port_mac_addr[6] User defined port MAC address.
1755 * port_config User port configuration value.
1756 * port_config_extend User port config extend value.
1757 * port_sdma_config User port SDMA config value.
1758 * port_serial_control User port serial control value.
1759 *
1760 * This driver data flow is done using the struct pkt_info which
1761 * is a unified struct for Rx and Tx operations:
1762 *
1763 * byte_cnt Tx/Rx descriptor buffer byte count.
1764 * l4i_chk CPU provided TCP Checksum. For Tx operation
1765 * only.
1766 * cmd_sts Tx/Rx descriptor command status.
1767 * buf_ptr Tx/Rx descriptor buffer pointer.
1768 * return_info Tx/Rx user resource return information.
1769 */
1770
1771/* defines */
1772/* SDMA command macros */
1773#define ETH_ENABLE_TX_QUEUE(eth_port) \
1774 mv_write(MV643XX_ETH_TRANSMIT_QUEUE_COMMAND_REG(eth_port), 1)
1775
1776/* locals */
1777
1778/* PHY routines */
1779static int ethernet_phy_get(unsigned int eth_port_num);
1780static void ethernet_phy_set(unsigned int eth_port_num, int phy_addr);
1781
1782/* Ethernet Port routines */
1783static int eth_port_uc_addr(unsigned int eth_port_num, unsigned char uc_nibble,
1784 int option);
1785
1786/*
1787 * eth_port_init - Initialize the Ethernet port driver
1788 *
1789 * DESCRIPTION:
1790 * This function prepares the ethernet port to start its activity:
1791 * 1) Completes the ethernet port driver struct initialization toward port
1792 * start routine.
1793 * 2) Resets the device to a quiescent state in case of warm reboot.
1794 * 3) Enable SDMA access to all four DRAM banks as well as internal SRAM.
1795 * 4) Clean MAC tables. The reset status of those tables is unknown.
1796 * 5) Set PHY address.
1797 * Note: Call this routine prior to eth_port_start routine and after
1798 * setting user values in the user fields of Ethernet port control
1799 * struct.
1800 *
1801 * INPUT:
1802 * struct mv643xx_private *mp Ethernet port control struct
1803 *
1804 * OUTPUT:
1805 * See description.
1806 *
1807 * RETURN:
1808 * None.
1809 */
1810static void eth_port_init(struct mv643xx_private *mp)
1811{
1812 mp->port_rx_queue_command = 0;
1813 mp->port_tx_queue_command = 0;
1814
1815 mp->rx_resource_err = 0;
1816 mp->tx_resource_err = 0;
1817
1818 eth_port_reset(mp->port_num);
1819
1820 eth_port_init_mac_tables(mp->port_num);
1821
1822 ethernet_phy_reset(mp->port_num);
1823}
1824
1825/*
1826 * eth_port_start - Start the Ethernet port activity.
1827 *
1828 * DESCRIPTION:
1829 * This routine prepares the Ethernet port for Rx and Tx activity:
1830 * 1. Initialize Tx and Rx Current Descriptor Pointer for each queue that
1831 * has been initialized a descriptor's ring (using
1832 * ether_init_tx_desc_ring for Tx and ether_init_rx_desc_ring for Rx)
1833 * 2. Initialize and enable the Ethernet configuration port by writing to
1834 * the port's configuration and command registers.
1835 * 3. Initialize and enable the SDMA by writing to the SDMA's
1836 * configuration and command registers. After completing these steps,
1837 * the ethernet port SDMA can starts to perform Rx and Tx activities.
1838 *
1839 * Note: Each Rx and Tx queue descriptor's list must be initialized prior
1840 * to calling this function (use ether_init_tx_desc_ring for Tx queues
1841 * and ether_init_rx_desc_ring for Rx queues).
1842 *
1843 * INPUT:
1844 * struct mv643xx_private *mp Ethernet port control struct
1845 *
1846 * OUTPUT:
1847 * Ethernet port is ready to receive and transmit.
1848 *
1849 * RETURN:
1850 * None.
1851 */
1852static void eth_port_start(struct mv643xx_private *mp)
1853{
1854 unsigned int port_num = mp->port_num;
1855 int tx_curr_desc, rx_curr_desc;
1856
1857 /* Assignment of Tx CTRP of given queue */
1858 tx_curr_desc = mp->tx_curr_desc_q;
1859 mv_write(MV643XX_ETH_TX_CURRENT_QUEUE_DESC_PTR_0(port_num),
1860 (u32)((struct eth_tx_desc *)mp->tx_desc_dma + tx_curr_desc));
1861
1862 /* Assignment of Rx CRDP of given queue */
1863 rx_curr_desc = mp->rx_curr_desc_q;
1864 mv_write(MV643XX_ETH_RX_CURRENT_QUEUE_DESC_PTR_0(port_num),
1865 (u32)((struct eth_rx_desc *)mp->rx_desc_dma + rx_curr_desc));
1866
1867 /* Add the assigned Ethernet address to the port's address table */
1868 eth_port_uc_addr_set(port_num, mp->port_mac_addr);
1869
1870 /* Assign port configuration and command. */
1871 mv_write(MV643XX_ETH_PORT_CONFIG_REG(port_num), mp->port_config);
1872
1873 mv_write(MV643XX_ETH_PORT_CONFIG_EXTEND_REG(port_num),
1874 mp->port_config_extend);
1875
1876
1877 /* Increase the Rx side buffer size if supporting GigE */
1878 if (mp->port_serial_control & MV643XX_ETH_SET_GMII_SPEED_TO_1000)
1879 mv_write(MV643XX_ETH_PORT_SERIAL_CONTROL_REG(port_num),
1880 (mp->port_serial_control & 0xfff1ffff) | (0x5 << 17));
1881 else
1882 mv_write(MV643XX_ETH_PORT_SERIAL_CONTROL_REG(port_num),
1883 mp->port_serial_control);
1884
1885 mv_write(MV643XX_ETH_PORT_SERIAL_CONTROL_REG(port_num),
1886 mv_read(MV643XX_ETH_PORT_SERIAL_CONTROL_REG(port_num)) |
1887 MV643XX_ETH_SERIAL_PORT_ENABLE);
1888
1889 /* Assign port SDMA configuration */
1890 mv_write(MV643XX_ETH_SDMA_CONFIG_REG(port_num),
1891 mp->port_sdma_config);
1892
1893 /* Enable port Rx. */
1894 mv_write(MV643XX_ETH_RECEIVE_QUEUE_COMMAND_REG(port_num),
1895 mp->port_rx_queue_command);
Dale Farnsworth8f543712005-09-02 12:34:35 -07001896
1897 /* Disable port bandwidth limits by clearing MTU register */
1898 mv_write(MV643XX_ETH_MAXIMUM_TRANSMIT_UNIT(port_num), 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001899}
1900
1901/*
1902 * eth_port_uc_addr_set - This function Set the port Unicast address.
1903 *
1904 * DESCRIPTION:
1905 * This function Set the port Ethernet MAC address.
1906 *
1907 * INPUT:
1908 * unsigned int eth_port_num Port number.
1909 * char * p_addr Address to be set
1910 *
1911 * OUTPUT:
1912 * Set MAC address low and high registers. also calls eth_port_uc_addr()
1913 * To set the unicast table with the proper information.
1914 *
1915 * RETURN:
1916 * N/A.
1917 *
1918 */
1919static void eth_port_uc_addr_set(unsigned int eth_port_num,
1920 unsigned char *p_addr)
1921{
1922 unsigned int mac_h;
1923 unsigned int mac_l;
1924
1925 mac_l = (p_addr[4] << 8) | (p_addr[5]);
1926 mac_h = (p_addr[0] << 24) | (p_addr[1] << 16) | (p_addr[2] << 8) |
1927 (p_addr[3] << 0);
1928
1929 mv_write(MV643XX_ETH_MAC_ADDR_LOW(eth_port_num), mac_l);
1930 mv_write(MV643XX_ETH_MAC_ADDR_HIGH(eth_port_num), mac_h);
1931
1932 /* Accept frames of this address */
1933 eth_port_uc_addr(eth_port_num, p_addr[5], ACCEPT_MAC_ADDR);
1934
1935 return;
1936}
1937
1938/*
1939 * eth_port_uc_addr_get - This function retrieves the port Unicast address
1940 * (MAC address) from the ethernet hw registers.
1941 *
1942 * DESCRIPTION:
1943 * This function retrieves the port Ethernet MAC address.
1944 *
1945 * INPUT:
1946 * unsigned int eth_port_num Port number.
1947 * char *MacAddr pointer where the MAC address is stored
1948 *
1949 * OUTPUT:
1950 * Copy the MAC address to the location pointed to by MacAddr
1951 *
1952 * RETURN:
1953 * N/A.
1954 *
1955 */
1956static void eth_port_uc_addr_get(struct net_device *dev, unsigned char *p_addr)
1957{
1958 struct mv643xx_private *mp = netdev_priv(dev);
1959 unsigned int mac_h;
1960 unsigned int mac_l;
1961
1962 mac_h = mv_read(MV643XX_ETH_MAC_ADDR_HIGH(mp->port_num));
1963 mac_l = mv_read(MV643XX_ETH_MAC_ADDR_LOW(mp->port_num));
1964
1965 p_addr[0] = (mac_h >> 24) & 0xff;
1966 p_addr[1] = (mac_h >> 16) & 0xff;
1967 p_addr[2] = (mac_h >> 8) & 0xff;
1968 p_addr[3] = mac_h & 0xff;
1969 p_addr[4] = (mac_l >> 8) & 0xff;
1970 p_addr[5] = mac_l & 0xff;
1971}
1972
1973/*
1974 * eth_port_uc_addr - This function Set the port unicast address table
1975 *
1976 * DESCRIPTION:
1977 * This function locates the proper entry in the Unicast table for the
1978 * specified MAC nibble and sets its properties according to function
1979 * parameters.
1980 *
1981 * INPUT:
1982 * unsigned int eth_port_num Port number.
1983 * unsigned char uc_nibble Unicast MAC Address last nibble.
1984 * int option 0 = Add, 1 = remove address.
1985 *
1986 * OUTPUT:
1987 * This function add/removes MAC addresses from the port unicast address
1988 * table.
1989 *
1990 * RETURN:
1991 * true is output succeeded.
1992 * false if option parameter is invalid.
1993 *
1994 */
1995static int eth_port_uc_addr(unsigned int eth_port_num, unsigned char uc_nibble,
1996 int option)
1997{
1998 unsigned int unicast_reg;
1999 unsigned int tbl_offset;
2000 unsigned int reg_offset;
2001
2002 /* Locate the Unicast table entry */
2003 uc_nibble = (0xf & uc_nibble);
2004 tbl_offset = (uc_nibble / 4) * 4; /* Register offset from unicast table base */
2005 reg_offset = uc_nibble % 4; /* Entry offset within the above register */
2006
2007 switch (option) {
2008 case REJECT_MAC_ADDR:
2009 /* Clear accepts frame bit at given unicast DA table entry */
2010 unicast_reg = mv_read((MV643XX_ETH_DA_FILTER_UNICAST_TABLE_BASE
2011 (eth_port_num) + tbl_offset));
2012
2013 unicast_reg &= (0x0E << (8 * reg_offset));
2014
2015 mv_write((MV643XX_ETH_DA_FILTER_UNICAST_TABLE_BASE
2016 (eth_port_num) + tbl_offset), unicast_reg);
2017 break;
2018
2019 case ACCEPT_MAC_ADDR:
2020 /* Set accepts frame bit at unicast DA filter table entry */
2021 unicast_reg =
2022 mv_read((MV643XX_ETH_DA_FILTER_UNICAST_TABLE_BASE
2023 (eth_port_num) + tbl_offset));
2024
2025 unicast_reg |= (0x01 << (8 * reg_offset));
2026
2027 mv_write((MV643XX_ETH_DA_FILTER_UNICAST_TABLE_BASE
2028 (eth_port_num) + tbl_offset), unicast_reg);
2029
2030 break;
2031
2032 default:
2033 return 0;
2034 }
2035
2036 return 1;
2037}
2038
2039/*
Dale Farnsworth16e03012006-01-16 16:50:02 -07002040 * The entries in each table are indexed by a hash of a packet's MAC
2041 * address. One bit in each entry determines whether the packet is
2042 * accepted. There are 4 entries (each 8 bits wide) in each register
2043 * of the table. The bits in each entry are defined as follows:
2044 * 0 Accept=1, Drop=0
2045 * 3-1 Queue (ETH_Q0=0)
2046 * 7-4 Reserved = 0;
2047 */
2048static void eth_port_set_filter_table_entry(int table, unsigned char entry)
2049{
2050 unsigned int table_reg;
2051 unsigned int tbl_offset;
2052 unsigned int reg_offset;
2053
2054 tbl_offset = (entry / 4) * 4; /* Register offset of DA table entry */
2055 reg_offset = entry % 4; /* Entry offset within the register */
2056
2057 /* Set "accepts frame bit" at specified table entry */
2058 table_reg = mv_read(table + tbl_offset);
2059 table_reg |= 0x01 << (8 * reg_offset);
2060 mv_write(table + tbl_offset, table_reg);
2061}
2062
2063/*
2064 * eth_port_mc_addr - Multicast address settings.
2065 *
2066 * The MV device supports multicast using two tables:
2067 * 1) Special Multicast Table for MAC addresses of the form
2068 * 0x01-00-5E-00-00-XX (where XX is between 0x00 and 0x_FF).
2069 * The MAC DA[7:0] bits are used as a pointer to the Special Multicast
2070 * Table entries in the DA-Filter table.
2071 * 2) Other Multicast Table for multicast of another type. A CRC-8bit
2072 * is used as an index to the Other Multicast Table entries in the
2073 * DA-Filter table. This function calculates the CRC-8bit value.
2074 * In either case, eth_port_set_filter_table_entry() is then called
2075 * to set to set the actual table entry.
2076 */
2077static void eth_port_mc_addr(unsigned int eth_port_num, unsigned char *p_addr)
2078{
2079 unsigned int mac_h;
2080 unsigned int mac_l;
2081 unsigned char crc_result = 0;
2082 int table;
2083 int mac_array[48];
2084 int crc[8];
2085 int i;
2086
2087 if ((p_addr[0] == 0x01) && (p_addr[1] == 0x00) &&
2088 (p_addr[2] == 0x5E) && (p_addr[3] == 0x00) && (p_addr[4] == 0x00)) {
2089 table = MV643XX_ETH_DA_FILTER_SPECIAL_MULTICAST_TABLE_BASE
2090 (eth_port_num);
2091 eth_port_set_filter_table_entry(table, p_addr[5]);
2092 return;
2093 }
2094
2095 /* Calculate CRC-8 out of the given address */
2096 mac_h = (p_addr[0] << 8) | (p_addr[1]);
2097 mac_l = (p_addr[2] << 24) | (p_addr[3] << 16) |
2098 (p_addr[4] << 8) | (p_addr[5] << 0);
2099
2100 for (i = 0; i < 32; i++)
2101 mac_array[i] = (mac_l >> i) & 0x1;
2102 for (i = 32; i < 48; i++)
2103 mac_array[i] = (mac_h >> (i - 32)) & 0x1;
2104
2105 crc[0] = mac_array[45] ^ mac_array[43] ^ mac_array[40] ^ mac_array[39] ^
2106 mac_array[35] ^ mac_array[34] ^ mac_array[31] ^ mac_array[30] ^
2107 mac_array[28] ^ mac_array[23] ^ mac_array[21] ^ mac_array[19] ^
2108 mac_array[18] ^ mac_array[16] ^ mac_array[14] ^ mac_array[12] ^
2109 mac_array[8] ^ mac_array[7] ^ mac_array[6] ^ mac_array[0];
2110
2111 crc[1] = mac_array[46] ^ mac_array[45] ^ mac_array[44] ^ mac_array[43] ^
2112 mac_array[41] ^ mac_array[39] ^ mac_array[36] ^ mac_array[34] ^
2113 mac_array[32] ^ mac_array[30] ^ mac_array[29] ^ mac_array[28] ^
2114 mac_array[24] ^ mac_array[23] ^ mac_array[22] ^ mac_array[21] ^
2115 mac_array[20] ^ mac_array[18] ^ mac_array[17] ^ mac_array[16] ^
2116 mac_array[15] ^ mac_array[14] ^ mac_array[13] ^ mac_array[12] ^
2117 mac_array[9] ^ mac_array[6] ^ mac_array[1] ^ mac_array[0];
2118
2119 crc[2] = mac_array[47] ^ mac_array[46] ^ mac_array[44] ^ mac_array[43] ^
2120 mac_array[42] ^ mac_array[39] ^ mac_array[37] ^ mac_array[34] ^
2121 mac_array[33] ^ mac_array[29] ^ mac_array[28] ^ mac_array[25] ^
2122 mac_array[24] ^ mac_array[22] ^ mac_array[17] ^ mac_array[15] ^
2123 mac_array[13] ^ mac_array[12] ^ mac_array[10] ^ mac_array[8] ^
2124 mac_array[6] ^ mac_array[2] ^ mac_array[1] ^ mac_array[0];
2125
2126 crc[3] = mac_array[47] ^ mac_array[45] ^ mac_array[44] ^ mac_array[43] ^
2127 mac_array[40] ^ mac_array[38] ^ mac_array[35] ^ mac_array[34] ^
2128 mac_array[30] ^ mac_array[29] ^ mac_array[26] ^ mac_array[25] ^
2129 mac_array[23] ^ mac_array[18] ^ mac_array[16] ^ mac_array[14] ^
2130 mac_array[13] ^ mac_array[11] ^ mac_array[9] ^ mac_array[7] ^
2131 mac_array[3] ^ mac_array[2] ^ mac_array[1];
2132
2133 crc[4] = mac_array[46] ^ mac_array[45] ^ mac_array[44] ^ mac_array[41] ^
2134 mac_array[39] ^ mac_array[36] ^ mac_array[35] ^ mac_array[31] ^
2135 mac_array[30] ^ mac_array[27] ^ mac_array[26] ^ mac_array[24] ^
2136 mac_array[19] ^ mac_array[17] ^ mac_array[15] ^ mac_array[14] ^
2137 mac_array[12] ^ mac_array[10] ^ mac_array[8] ^ mac_array[4] ^
2138 mac_array[3] ^ mac_array[2];
2139
2140 crc[5] = mac_array[47] ^ mac_array[46] ^ mac_array[45] ^ mac_array[42] ^
2141 mac_array[40] ^ mac_array[37] ^ mac_array[36] ^ mac_array[32] ^
2142 mac_array[31] ^ mac_array[28] ^ mac_array[27] ^ mac_array[25] ^
2143 mac_array[20] ^ mac_array[18] ^ mac_array[16] ^ mac_array[15] ^
2144 mac_array[13] ^ mac_array[11] ^ mac_array[9] ^ mac_array[5] ^
2145 mac_array[4] ^ mac_array[3];
2146
2147 crc[6] = mac_array[47] ^ mac_array[46] ^ mac_array[43] ^ mac_array[41] ^
2148 mac_array[38] ^ mac_array[37] ^ mac_array[33] ^ mac_array[32] ^
2149 mac_array[29] ^ mac_array[28] ^ mac_array[26] ^ mac_array[21] ^
2150 mac_array[19] ^ mac_array[17] ^ mac_array[16] ^ mac_array[14] ^
2151 mac_array[12] ^ mac_array[10] ^ mac_array[6] ^ mac_array[5] ^
2152 mac_array[4];
2153
2154 crc[7] = mac_array[47] ^ mac_array[44] ^ mac_array[42] ^ mac_array[39] ^
2155 mac_array[38] ^ mac_array[34] ^ mac_array[33] ^ mac_array[30] ^
2156 mac_array[29] ^ mac_array[27] ^ mac_array[22] ^ mac_array[20] ^
2157 mac_array[18] ^ mac_array[17] ^ mac_array[15] ^ mac_array[13] ^
2158 mac_array[11] ^ mac_array[7] ^ mac_array[6] ^ mac_array[5];
2159
2160 for (i = 0; i < 8; i++)
2161 crc_result = crc_result | (crc[i] << i);
2162
2163 table = MV643XX_ETH_DA_FILTER_OTHER_MULTICAST_TABLE_BASE(eth_port_num);
2164 eth_port_set_filter_table_entry(table, crc_result);
2165}
2166
2167/*
2168 * Set the entire multicast list based on dev->mc_list.
2169 */
2170static void eth_port_set_multicast_list(struct net_device *dev)
2171{
2172
2173 struct dev_mc_list *mc_list;
2174 int i;
2175 int table_index;
2176 struct mv643xx_private *mp = netdev_priv(dev);
2177 unsigned int eth_port_num = mp->port_num;
2178
2179 /* If the device is in promiscuous mode or in all multicast mode,
2180 * we will fully populate both multicast tables with accept.
2181 * This is guaranteed to yield a match on all multicast addresses...
2182 */
2183 if ((dev->flags & IFF_PROMISC) || (dev->flags & IFF_ALLMULTI)) {
2184 for (table_index = 0; table_index <= 0xFC; table_index += 4) {
2185 /* Set all entries in DA filter special multicast
2186 * table (Ex_dFSMT)
2187 * Set for ETH_Q0 for now
2188 * Bits
2189 * 0 Accept=1, Drop=0
2190 * 3-1 Queue ETH_Q0=0
2191 * 7-4 Reserved = 0;
2192 */
2193 mv_write(MV643XX_ETH_DA_FILTER_SPECIAL_MULTICAST_TABLE_BASE(eth_port_num) + table_index, 0x01010101);
2194
2195 /* Set all entries in DA filter other multicast
2196 * table (Ex_dFOMT)
2197 * Set for ETH_Q0 for now
2198 * Bits
2199 * 0 Accept=1, Drop=0
2200 * 3-1 Queue ETH_Q0=0
2201 * 7-4 Reserved = 0;
2202 */
2203 mv_write(MV643XX_ETH_DA_FILTER_OTHER_MULTICAST_TABLE_BASE(eth_port_num) + table_index, 0x01010101);
2204 }
2205 return;
2206 }
2207
2208 /* We will clear out multicast tables every time we get the list.
2209 * Then add the entire new list...
2210 */
2211 for (table_index = 0; table_index <= 0xFC; table_index += 4) {
2212 /* Clear DA filter special multicast table (Ex_dFSMT) */
2213 mv_write(MV643XX_ETH_DA_FILTER_SPECIAL_MULTICAST_TABLE_BASE
2214 (eth_port_num) + table_index, 0);
2215
2216 /* Clear DA filter other multicast table (Ex_dFOMT) */
2217 mv_write(MV643XX_ETH_DA_FILTER_OTHER_MULTICAST_TABLE_BASE
2218 (eth_port_num) + table_index, 0);
2219 }
2220
2221 /* Get pointer to net_device multicast list and add each one... */
2222 for (i = 0, mc_list = dev->mc_list;
2223 (i < 256) && (mc_list != NULL) && (i < dev->mc_count);
2224 i++, mc_list = mc_list->next)
2225 if (mc_list->dmi_addrlen == 6)
2226 eth_port_mc_addr(eth_port_num, mc_list->dmi_addr);
2227}
2228
2229/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002230 * eth_port_init_mac_tables - Clear all entrance in the UC, SMC and OMC tables
2231 *
2232 * DESCRIPTION:
2233 * Go through all the DA filter tables (Unicast, Special Multicast &
2234 * Other Multicast) and set each entry to 0.
2235 *
2236 * INPUT:
2237 * unsigned int eth_port_num Ethernet Port number.
2238 *
2239 * OUTPUT:
2240 * Multicast and Unicast packets are rejected.
2241 *
2242 * RETURN:
2243 * None.
2244 */
2245static void eth_port_init_mac_tables(unsigned int eth_port_num)
2246{
2247 int table_index;
2248
2249 /* Clear DA filter unicast table (Ex_dFUT) */
2250 for (table_index = 0; table_index <= 0xC; table_index += 4)
2251 mv_write((MV643XX_ETH_DA_FILTER_UNICAST_TABLE_BASE
2252 (eth_port_num) + table_index), 0);
2253
2254 for (table_index = 0; table_index <= 0xFC; table_index += 4) {
2255 /* Clear DA filter special multicast table (Ex_dFSMT) */
Dale Farnsworth16e03012006-01-16 16:50:02 -07002256 mv_write(MV643XX_ETH_DA_FILTER_SPECIAL_MULTICAST_TABLE_BASE
2257 (eth_port_num) + table_index, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002258 /* Clear DA filter other multicast table (Ex_dFOMT) */
Dale Farnsworth16e03012006-01-16 16:50:02 -07002259 mv_write(MV643XX_ETH_DA_FILTER_OTHER_MULTICAST_TABLE_BASE
2260 (eth_port_num) + table_index, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002261 }
2262}
2263
2264/*
2265 * eth_clear_mib_counters - Clear all MIB counters
2266 *
2267 * DESCRIPTION:
2268 * This function clears all MIB counters of a specific ethernet port.
2269 * A read from the MIB counter will reset the counter.
2270 *
2271 * INPUT:
2272 * unsigned int eth_port_num Ethernet Port number.
2273 *
2274 * OUTPUT:
2275 * After reading all MIB counters, the counters resets.
2276 *
2277 * RETURN:
2278 * MIB counter value.
2279 *
2280 */
2281static void eth_clear_mib_counters(unsigned int eth_port_num)
2282{
2283 int i;
2284
2285 /* Perform dummy reads from MIB counters */
2286 for (i = ETH_MIB_GOOD_OCTETS_RECEIVED_LOW; i < ETH_MIB_LATE_COLLISION;
2287 i += 4)
2288 mv_read(MV643XX_ETH_MIB_COUNTERS_BASE(eth_port_num) + i);
2289}
2290
2291static inline u32 read_mib(struct mv643xx_private *mp, int offset)
2292{
2293 return mv_read(MV643XX_ETH_MIB_COUNTERS_BASE(mp->port_num) + offset);
2294}
2295
2296static void eth_update_mib_counters(struct mv643xx_private *mp)
2297{
2298 struct mv643xx_mib_counters *p = &mp->mib_counters;
2299 int offset;
2300
2301 p->good_octets_received +=
2302 read_mib(mp, ETH_MIB_GOOD_OCTETS_RECEIVED_LOW);
2303 p->good_octets_received +=
2304 (u64)read_mib(mp, ETH_MIB_GOOD_OCTETS_RECEIVED_HIGH) << 32;
2305
2306 for (offset = ETH_MIB_BAD_OCTETS_RECEIVED;
2307 offset <= ETH_MIB_FRAMES_1024_TO_MAX_OCTETS;
2308 offset += 4)
2309 *(u32 *)((char *)p + offset) = read_mib(mp, offset);
2310
2311 p->good_octets_sent += read_mib(mp, ETH_MIB_GOOD_OCTETS_SENT_LOW);
2312 p->good_octets_sent +=
2313 (u64)read_mib(mp, ETH_MIB_GOOD_OCTETS_SENT_HIGH) << 32;
2314
2315 for (offset = ETH_MIB_GOOD_FRAMES_SENT;
2316 offset <= ETH_MIB_LATE_COLLISION;
2317 offset += 4)
2318 *(u32 *)((char *)p + offset) = read_mib(mp, offset);
2319}
2320
2321/*
2322 * ethernet_phy_detect - Detect whether a phy is present
2323 *
2324 * DESCRIPTION:
2325 * This function tests whether there is a PHY present on
2326 * the specified port.
2327 *
2328 * INPUT:
2329 * unsigned int eth_port_num Ethernet Port number.
2330 *
2331 * OUTPUT:
2332 * None
2333 *
2334 * RETURN:
2335 * 0 on success
2336 * -ENODEV on failure
2337 *
2338 */
2339static int ethernet_phy_detect(unsigned int port_num)
2340{
2341 unsigned int phy_reg_data0;
2342 int auto_neg;
2343
2344 eth_port_read_smi_reg(port_num, 0, &phy_reg_data0);
2345 auto_neg = phy_reg_data0 & 0x1000;
2346 phy_reg_data0 ^= 0x1000; /* invert auto_neg */
2347 eth_port_write_smi_reg(port_num, 0, phy_reg_data0);
2348
2349 eth_port_read_smi_reg(port_num, 0, &phy_reg_data0);
2350 if ((phy_reg_data0 & 0x1000) == auto_neg)
2351 return -ENODEV; /* change didn't take */
2352
2353 phy_reg_data0 ^= 0x1000;
2354 eth_port_write_smi_reg(port_num, 0, phy_reg_data0);
2355 return 0;
2356}
2357
2358/*
2359 * ethernet_phy_get - Get the ethernet port PHY address.
2360 *
2361 * DESCRIPTION:
2362 * This routine returns the given ethernet port PHY address.
2363 *
2364 * INPUT:
2365 * unsigned int eth_port_num Ethernet Port number.
2366 *
2367 * OUTPUT:
2368 * None.
2369 *
2370 * RETURN:
2371 * PHY address.
2372 *
2373 */
2374static int ethernet_phy_get(unsigned int eth_port_num)
2375{
2376 unsigned int reg_data;
2377
2378 reg_data = mv_read(MV643XX_ETH_PHY_ADDR_REG);
2379
2380 return ((reg_data >> (5 * eth_port_num)) & 0x1f);
2381}
2382
2383/*
2384 * ethernet_phy_set - Set the ethernet port PHY address.
2385 *
2386 * DESCRIPTION:
2387 * This routine sets the given ethernet port PHY address.
2388 *
2389 * INPUT:
2390 * unsigned int eth_port_num Ethernet Port number.
2391 * int phy_addr PHY address.
2392 *
2393 * OUTPUT:
2394 * None.
2395 *
2396 * RETURN:
2397 * None.
2398 *
2399 */
2400static void ethernet_phy_set(unsigned int eth_port_num, int phy_addr)
2401{
2402 u32 reg_data;
2403 int addr_shift = 5 * eth_port_num;
2404
2405 reg_data = mv_read(MV643XX_ETH_PHY_ADDR_REG);
2406 reg_data &= ~(0x1f << addr_shift);
2407 reg_data |= (phy_addr & 0x1f) << addr_shift;
2408 mv_write(MV643XX_ETH_PHY_ADDR_REG, reg_data);
2409}
2410
2411/*
2412 * ethernet_phy_reset - Reset Ethernet port PHY.
2413 *
2414 * DESCRIPTION:
2415 * This routine utilizes the SMI interface to reset the ethernet port PHY.
2416 *
2417 * INPUT:
2418 * unsigned int eth_port_num Ethernet Port number.
2419 *
2420 * OUTPUT:
2421 * The PHY is reset.
2422 *
2423 * RETURN:
2424 * None.
2425 *
2426 */
2427static void ethernet_phy_reset(unsigned int eth_port_num)
2428{
2429 unsigned int phy_reg_data;
2430
2431 /* Reset the PHY */
2432 eth_port_read_smi_reg(eth_port_num, 0, &phy_reg_data);
2433 phy_reg_data |= 0x8000; /* Set bit 15 to reset the PHY */
2434 eth_port_write_smi_reg(eth_port_num, 0, phy_reg_data);
2435}
2436
2437/*
2438 * eth_port_reset - Reset Ethernet port
2439 *
2440 * DESCRIPTION:
2441 * This routine resets the chip by aborting any SDMA engine activity and
2442 * clearing the MIB counters. The Receiver and the Transmit unit are in
2443 * idle state after this command is performed and the port is disabled.
2444 *
2445 * INPUT:
2446 * unsigned int eth_port_num Ethernet Port number.
2447 *
2448 * OUTPUT:
2449 * Channel activity is halted.
2450 *
2451 * RETURN:
2452 * None.
2453 *
2454 */
2455static void eth_port_reset(unsigned int port_num)
2456{
2457 unsigned int reg_data;
2458
2459 /* Stop Tx port activity. Check port Tx activity. */
2460 reg_data = mv_read(MV643XX_ETH_TRANSMIT_QUEUE_COMMAND_REG(port_num));
2461
2462 if (reg_data & 0xFF) {
2463 /* Issue stop command for active channels only */
2464 mv_write(MV643XX_ETH_TRANSMIT_QUEUE_COMMAND_REG(port_num),
2465 (reg_data << 8));
2466
2467 /* Wait for all Tx activity to terminate. */
2468 /* Check port cause register that all Tx queues are stopped */
2469 while (mv_read(MV643XX_ETH_TRANSMIT_QUEUE_COMMAND_REG(port_num))
2470 & 0xFF)
2471 udelay(10);
2472 }
2473
2474 /* Stop Rx port activity. Check port Rx activity. */
2475 reg_data = mv_read(MV643XX_ETH_RECEIVE_QUEUE_COMMAND_REG(port_num));
2476
2477 if (reg_data & 0xFF) {
2478 /* Issue stop command for active channels only */
2479 mv_write(MV643XX_ETH_RECEIVE_QUEUE_COMMAND_REG(port_num),
2480 (reg_data << 8));
2481
2482 /* Wait for all Rx activity to terminate. */
2483 /* Check port cause register that all Rx queues are stopped */
2484 while (mv_read(MV643XX_ETH_RECEIVE_QUEUE_COMMAND_REG(port_num))
2485 & 0xFF)
2486 udelay(10);
2487 }
2488
2489 /* Clear all MIB counters */
2490 eth_clear_mib_counters(port_num);
2491
2492 /* Reset the Enable bit in the Configuration Register */
2493 reg_data = mv_read(MV643XX_ETH_PORT_SERIAL_CONTROL_REG(port_num));
2494 reg_data &= ~MV643XX_ETH_SERIAL_PORT_ENABLE;
2495 mv_write(MV643XX_ETH_PORT_SERIAL_CONTROL_REG(port_num), reg_data);
2496}
2497
Linus Torvalds1da177e2005-04-16 15:20:36 -07002498
2499static int eth_port_autoneg_supported(unsigned int eth_port_num)
2500{
2501 unsigned int phy_reg_data0;
2502
2503 eth_port_read_smi_reg(eth_port_num, 0, &phy_reg_data0);
2504
2505 return phy_reg_data0 & 0x1000;
2506}
2507
2508static int eth_port_link_is_up(unsigned int eth_port_num)
2509{
2510 unsigned int phy_reg_data1;
2511
2512 eth_port_read_smi_reg(eth_port_num, 1, &phy_reg_data1);
2513
2514 if (eth_port_autoneg_supported(eth_port_num)) {
2515 if (phy_reg_data1 & 0x20) /* auto-neg complete */
2516 return 1;
2517 } else if (phy_reg_data1 & 0x4) /* link up */
2518 return 1;
2519
2520 return 0;
2521}
2522
2523/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002524 * eth_port_read_smi_reg - Read PHY registers
2525 *
2526 * DESCRIPTION:
2527 * This routine utilize the SMI interface to interact with the PHY in
2528 * order to perform PHY register read.
2529 *
2530 * INPUT:
2531 * unsigned int port_num Ethernet Port number.
2532 * unsigned int phy_reg PHY register address offset.
2533 * unsigned int *value Register value buffer.
2534 *
2535 * OUTPUT:
2536 * Write the value of a specified PHY register into given buffer.
2537 *
2538 * RETURN:
2539 * false if the PHY is busy or read data is not in valid state.
2540 * true otherwise.
2541 *
2542 */
2543static void eth_port_read_smi_reg(unsigned int port_num,
2544 unsigned int phy_reg, unsigned int *value)
2545{
2546 int phy_addr = ethernet_phy_get(port_num);
2547 unsigned long flags;
2548 int i;
2549
2550 /* the SMI register is a shared resource */
2551 spin_lock_irqsave(&mv643xx_eth_phy_lock, flags);
2552
2553 /* wait for the SMI register to become available */
2554 for (i = 0; mv_read(MV643XX_ETH_SMI_REG) & ETH_SMI_BUSY; i++) {
2555 if (i == PHY_WAIT_ITERATIONS) {
2556 printk("mv643xx PHY busy timeout, port %d\n", port_num);
2557 goto out;
2558 }
2559 udelay(PHY_WAIT_MICRO_SECONDS);
2560 }
2561
2562 mv_write(MV643XX_ETH_SMI_REG,
2563 (phy_addr << 16) | (phy_reg << 21) | ETH_SMI_OPCODE_READ);
2564
2565 /* now wait for the data to be valid */
2566 for (i = 0; !(mv_read(MV643XX_ETH_SMI_REG) & ETH_SMI_READ_VALID); i++) {
2567 if (i == PHY_WAIT_ITERATIONS) {
2568 printk("mv643xx PHY read timeout, port %d\n", port_num);
2569 goto out;
2570 }
2571 udelay(PHY_WAIT_MICRO_SECONDS);
2572 }
2573
2574 *value = mv_read(MV643XX_ETH_SMI_REG) & 0xffff;
2575out:
2576 spin_unlock_irqrestore(&mv643xx_eth_phy_lock, flags);
2577}
2578
2579/*
2580 * eth_port_write_smi_reg - Write to PHY registers
2581 *
2582 * DESCRIPTION:
2583 * This routine utilize the SMI interface to interact with the PHY in
2584 * order to perform writes to PHY registers.
2585 *
2586 * INPUT:
2587 * unsigned int eth_port_num Ethernet Port number.
2588 * unsigned int phy_reg PHY register address offset.
2589 * unsigned int value Register value.
2590 *
2591 * OUTPUT:
2592 * Write the given value to the specified PHY register.
2593 *
2594 * RETURN:
2595 * false if the PHY is busy.
2596 * true otherwise.
2597 *
2598 */
2599static void eth_port_write_smi_reg(unsigned int eth_port_num,
2600 unsigned int phy_reg, unsigned int value)
2601{
2602 int phy_addr;
2603 int i;
2604 unsigned long flags;
2605
2606 phy_addr = ethernet_phy_get(eth_port_num);
2607
2608 /* the SMI register is a shared resource */
2609 spin_lock_irqsave(&mv643xx_eth_phy_lock, flags);
2610
2611 /* wait for the SMI register to become available */
2612 for (i = 0; mv_read(MV643XX_ETH_SMI_REG) & ETH_SMI_BUSY; i++) {
2613 if (i == PHY_WAIT_ITERATIONS) {
2614 printk("mv643xx PHY busy timeout, port %d\n",
2615 eth_port_num);
2616 goto out;
2617 }
2618 udelay(PHY_WAIT_MICRO_SECONDS);
2619 }
2620
2621 mv_write(MV643XX_ETH_SMI_REG, (phy_addr << 16) | (phy_reg << 21) |
2622 ETH_SMI_OPCODE_WRITE | (value & 0xffff));
2623out:
2624 spin_unlock_irqrestore(&mv643xx_eth_phy_lock, flags);
2625}
2626
2627/*
2628 * eth_port_send - Send an Ethernet packet
2629 *
2630 * DESCRIPTION:
2631 * This routine send a given packet described by p_pktinfo parameter. It
2632 * supports transmitting of a packet spaned over multiple buffers. The
2633 * routine updates 'curr' and 'first' indexes according to the packet
2634 * segment passed to the routine. In case the packet segment is first,
2635 * the 'first' index is update. In any case, the 'curr' index is updated.
2636 * If the routine get into Tx resource error it assigns 'curr' index as
2637 * 'first'. This way the function can abort Tx process of multiple
2638 * descriptors per packet.
2639 *
2640 * INPUT:
2641 * struct mv643xx_private *mp Ethernet Port Control srtuct.
2642 * struct pkt_info *p_pkt_info User packet buffer.
2643 *
2644 * OUTPUT:
2645 * Tx ring 'curr' and 'first' indexes are updated.
2646 *
2647 * RETURN:
2648 * ETH_QUEUE_FULL in case of Tx resource error.
2649 * ETH_ERROR in case the routine can not access Tx desc ring.
2650 * ETH_QUEUE_LAST_RESOURCE if the routine uses the last Tx resource.
2651 * ETH_OK otherwise.
2652 *
2653 */
2654#ifdef MV643XX_CHECKSUM_OFFLOAD_TX
2655/*
2656 * Modified to include the first descriptor pointer in case of SG
2657 */
2658static ETH_FUNC_RET_STATUS eth_port_send(struct mv643xx_private *mp,
2659 struct pkt_info *p_pkt_info)
2660{
2661 int tx_desc_curr, tx_desc_used, tx_first_desc, tx_next_desc;
2662 struct eth_tx_desc *current_descriptor;
2663 struct eth_tx_desc *first_descriptor;
2664 u32 command;
Dale Farnsworth8f518702006-01-16 16:56:30 -07002665 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002666
2667 /* Do not process Tx ring in case of Tx ring resource error */
2668 if (mp->tx_resource_err)
2669 return ETH_QUEUE_FULL;
2670
2671 /*
2672 * The hardware requires that each buffer that is <= 8 bytes
2673 * in length must be aligned on an 8 byte boundary.
2674 */
2675 if (p_pkt_info->byte_cnt <= 8 && p_pkt_info->buf_ptr & 0x7) {
2676 printk(KERN_ERR
2677 "mv643xx_eth port %d: packet size <= 8 problem\n",
2678 mp->port_num);
2679 return ETH_ERROR;
2680 }
2681
Dale Farnsworth8f518702006-01-16 16:56:30 -07002682 spin_lock_irqsave(&mp->lock, flags);
2683
Dale Farnsworthb111ceb2005-09-02 10:25:24 -07002684 mp->tx_ring_skbs++;
2685 BUG_ON(mp->tx_ring_skbs > mp->tx_ring_size);
2686
Linus Torvalds1da177e2005-04-16 15:20:36 -07002687 /* Get the Tx Desc ring indexes */
2688 tx_desc_curr = mp->tx_curr_desc_q;
2689 tx_desc_used = mp->tx_used_desc_q;
2690
2691 current_descriptor = &mp->p_tx_desc_area[tx_desc_curr];
2692
2693 tx_next_desc = (tx_desc_curr + 1) % mp->tx_ring_size;
2694
2695 current_descriptor->buf_ptr = p_pkt_info->buf_ptr;
2696 current_descriptor->byte_cnt = p_pkt_info->byte_cnt;
2697 current_descriptor->l4i_chk = p_pkt_info->l4i_chk;
2698 mp->tx_skb[tx_desc_curr] = p_pkt_info->return_info;
2699
2700 command = p_pkt_info->cmd_sts | ETH_ZERO_PADDING | ETH_GEN_CRC |
2701 ETH_BUFFER_OWNED_BY_DMA;
2702 if (command & ETH_TX_FIRST_DESC) {
2703 tx_first_desc = tx_desc_curr;
2704 mp->tx_first_desc_q = tx_first_desc;
2705 first_descriptor = current_descriptor;
2706 mp->tx_first_command = command;
2707 } else {
2708 tx_first_desc = mp->tx_first_desc_q;
2709 first_descriptor = &mp->p_tx_desc_area[tx_first_desc];
2710 BUG_ON(first_descriptor == NULL);
2711 current_descriptor->cmd_sts = command;
2712 }
2713
2714 if (command & ETH_TX_LAST_DESC) {
2715 wmb();
2716 first_descriptor->cmd_sts = mp->tx_first_command;
2717
2718 wmb();
2719 ETH_ENABLE_TX_QUEUE(mp->port_num);
2720
2721 /*
2722 * Finish Tx packet. Update first desc in case of Tx resource
2723 * error */
2724 tx_first_desc = tx_next_desc;
2725 mp->tx_first_desc_q = tx_first_desc;
2726 }
2727
2728 /* Check for ring index overlap in the Tx desc ring */
2729 if (tx_next_desc == tx_desc_used) {
2730 mp->tx_resource_err = 1;
2731 mp->tx_curr_desc_q = tx_first_desc;
2732
Dale Farnsworth8f518702006-01-16 16:56:30 -07002733 spin_unlock_irqrestore(&mp->lock, flags);
2734
Linus Torvalds1da177e2005-04-16 15:20:36 -07002735 return ETH_QUEUE_LAST_RESOURCE;
2736 }
2737
2738 mp->tx_curr_desc_q = tx_next_desc;
2739
Dale Farnsworth8f518702006-01-16 16:56:30 -07002740 spin_unlock_irqrestore(&mp->lock, flags);
2741
Linus Torvalds1da177e2005-04-16 15:20:36 -07002742 return ETH_OK;
2743}
2744#else
2745static ETH_FUNC_RET_STATUS eth_port_send(struct mv643xx_private *mp,
2746 struct pkt_info *p_pkt_info)
2747{
2748 int tx_desc_curr;
2749 int tx_desc_used;
2750 struct eth_tx_desc *current_descriptor;
2751 unsigned int command_status;
Dale Farnsworth8f518702006-01-16 16:56:30 -07002752 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002753
2754 /* Do not process Tx ring in case of Tx ring resource error */
2755 if (mp->tx_resource_err)
2756 return ETH_QUEUE_FULL;
2757
Dale Farnsworth8f518702006-01-16 16:56:30 -07002758 spin_lock_irqsave(&mp->lock, flags);
2759
Dale Farnsworthb111ceb2005-09-02 10:25:24 -07002760 mp->tx_ring_skbs++;
2761 BUG_ON(mp->tx_ring_skbs > mp->tx_ring_size);
2762
Linus Torvalds1da177e2005-04-16 15:20:36 -07002763 /* Get the Tx Desc ring indexes */
2764 tx_desc_curr = mp->tx_curr_desc_q;
2765 tx_desc_used = mp->tx_used_desc_q;
2766 current_descriptor = &mp->p_tx_desc_area[tx_desc_curr];
2767
2768 command_status = p_pkt_info->cmd_sts | ETH_ZERO_PADDING | ETH_GEN_CRC;
2769 current_descriptor->buf_ptr = p_pkt_info->buf_ptr;
2770 current_descriptor->byte_cnt = p_pkt_info->byte_cnt;
2771 mp->tx_skb[tx_desc_curr] = p_pkt_info->return_info;
2772
2773 /* Set last desc with DMA ownership and interrupt enable. */
2774 wmb();
2775 current_descriptor->cmd_sts = command_status |
2776 ETH_BUFFER_OWNED_BY_DMA | ETH_TX_ENABLE_INTERRUPT;
2777
2778 wmb();
2779 ETH_ENABLE_TX_QUEUE(mp->port_num);
2780
2781 /* Finish Tx packet. Update first desc in case of Tx resource error */
2782 tx_desc_curr = (tx_desc_curr + 1) % mp->tx_ring_size;
2783
2784 /* Update the current descriptor */
2785 mp->tx_curr_desc_q = tx_desc_curr;
2786
2787 /* Check for ring index overlap in the Tx desc ring */
2788 if (tx_desc_curr == tx_desc_used) {
2789 mp->tx_resource_err = 1;
Dale Farnsworth8f518702006-01-16 16:56:30 -07002790
2791 spin_unlock_irqrestore(&mp->lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002792 return ETH_QUEUE_LAST_RESOURCE;
2793 }
2794
Dale Farnsworth8f518702006-01-16 16:56:30 -07002795 spin_unlock_irqrestore(&mp->lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002796 return ETH_OK;
2797}
2798#endif
2799
2800/*
2801 * eth_tx_return_desc - Free all used Tx descriptors
2802 *
2803 * DESCRIPTION:
2804 * This routine returns the transmitted packet information to the caller.
2805 * It uses the 'first' index to support Tx desc return in case a transmit
2806 * of a packet spanned over multiple buffer still in process.
2807 * In case the Tx queue was in "resource error" condition, where there are
2808 * no available Tx resources, the function resets the resource error flag.
2809 *
2810 * INPUT:
2811 * struct mv643xx_private *mp Ethernet Port Control srtuct.
2812 * struct pkt_info *p_pkt_info User packet buffer.
2813 *
2814 * OUTPUT:
2815 * Tx ring 'first' and 'used' indexes are updated.
2816 *
2817 * RETURN:
Dale Farnsworth8f518702006-01-16 16:56:30 -07002818 * ETH_OK on success
2819 * ETH_ERROR otherwise.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002820 *
2821 */
2822static ETH_FUNC_RET_STATUS eth_tx_return_desc(struct mv643xx_private *mp,
2823 struct pkt_info *p_pkt_info)
2824{
2825 int tx_desc_used;
Dale Farnsworth8f518702006-01-16 16:56:30 -07002826 int tx_busy_desc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002827 struct eth_tx_desc *p_tx_desc_used;
2828 unsigned int command_status;
Dale Farnsworth8f518702006-01-16 16:56:30 -07002829 unsigned long flags;
2830 int err = ETH_OK;
2831
2832 spin_lock_irqsave(&mp->lock, flags);
2833
2834#ifdef MV643XX_CHECKSUM_OFFLOAD_TX
2835 tx_busy_desc = mp->tx_first_desc_q;
2836#else
2837 tx_busy_desc = mp->tx_curr_desc_q;
2838#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07002839
2840 /* Get the Tx Desc ring indexes */
2841 tx_desc_used = mp->tx_used_desc_q;
2842
2843 p_tx_desc_used = &mp->p_tx_desc_area[tx_desc_used];
2844
2845 /* Sanity check */
Dale Farnsworth8f518702006-01-16 16:56:30 -07002846 if (p_tx_desc_used == NULL) {
2847 err = ETH_ERROR;
2848 goto out;
2849 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002850
2851 /* Stop release. About to overlap the current available Tx descriptor */
Dale Farnsworth8f518702006-01-16 16:56:30 -07002852 if (tx_desc_used == tx_busy_desc && !mp->tx_resource_err) {
2853 err = ETH_ERROR;
2854 goto out;
2855 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002856
2857 command_status = p_tx_desc_used->cmd_sts;
2858
2859 /* Still transmitting... */
Dale Farnsworth8f518702006-01-16 16:56:30 -07002860 if (command_status & (ETH_BUFFER_OWNED_BY_DMA)) {
2861 err = ETH_ERROR;
2862 goto out;
2863 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002864
2865 /* Pass the packet information to the caller */
2866 p_pkt_info->cmd_sts = command_status;
2867 p_pkt_info->return_info = mp->tx_skb[tx_desc_used];
Paolo Galtieri4eaa3cb2006-01-16 16:48:58 -07002868 p_pkt_info->buf_ptr = p_tx_desc_used->buf_ptr;
2869 p_pkt_info->byte_cnt = p_tx_desc_used->byte_cnt;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002870 mp->tx_skb[tx_desc_used] = NULL;
2871
2872 /* Update the next descriptor to release. */
2873 mp->tx_used_desc_q = (tx_desc_used + 1) % mp->tx_ring_size;
2874
2875 /* Any Tx return cancels the Tx resource error status */
2876 mp->tx_resource_err = 0;
2877
Dale Farnsworthb111ceb2005-09-02 10:25:24 -07002878 BUG_ON(mp->tx_ring_skbs == 0);
2879 mp->tx_ring_skbs--;
2880
Dale Farnsworth8f518702006-01-16 16:56:30 -07002881out:
2882 spin_unlock_irqrestore(&mp->lock, flags);
2883
2884 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002885}
2886
2887/*
2888 * eth_port_receive - Get received information from Rx ring.
2889 *
2890 * DESCRIPTION:
2891 * This routine returns the received data to the caller. There is no
2892 * data copying during routine operation. All information is returned
2893 * using pointer to packet information struct passed from the caller.
2894 * If the routine exhausts Rx ring resources then the resource error flag
2895 * is set.
2896 *
2897 * INPUT:
2898 * struct mv643xx_private *mp Ethernet Port Control srtuct.
2899 * struct pkt_info *p_pkt_info User packet buffer.
2900 *
2901 * OUTPUT:
2902 * Rx ring current and used indexes are updated.
2903 *
2904 * RETURN:
2905 * ETH_ERROR in case the routine can not access Rx desc ring.
2906 * ETH_QUEUE_FULL if Rx ring resources are exhausted.
2907 * ETH_END_OF_JOB if there is no received data.
2908 * ETH_OK otherwise.
2909 */
2910static ETH_FUNC_RET_STATUS eth_port_receive(struct mv643xx_private *mp,
2911 struct pkt_info *p_pkt_info)
2912{
2913 int rx_next_curr_desc, rx_curr_desc, rx_used_desc;
2914 volatile struct eth_rx_desc *p_rx_desc;
2915 unsigned int command_status;
Dale Farnsworth8f518702006-01-16 16:56:30 -07002916 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002917
2918 /* Do not process Rx ring in case of Rx ring resource error */
2919 if (mp->rx_resource_err)
2920 return ETH_QUEUE_FULL;
2921
Dale Farnsworth8f518702006-01-16 16:56:30 -07002922 spin_lock_irqsave(&mp->lock, flags);
2923
Linus Torvalds1da177e2005-04-16 15:20:36 -07002924 /* Get the Rx Desc ring 'curr and 'used' indexes */
2925 rx_curr_desc = mp->rx_curr_desc_q;
2926 rx_used_desc = mp->rx_used_desc_q;
2927
2928 p_rx_desc = &mp->p_rx_desc_area[rx_curr_desc];
2929
2930 /* The following parameters are used to save readings from memory */
2931 command_status = p_rx_desc->cmd_sts;
2932 rmb();
2933
2934 /* Nothing to receive... */
Dale Farnsworth8f518702006-01-16 16:56:30 -07002935 if (command_status & (ETH_BUFFER_OWNED_BY_DMA)) {
2936 spin_unlock_irqrestore(&mp->lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002937 return ETH_END_OF_JOB;
Dale Farnsworth8f518702006-01-16 16:56:30 -07002938 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002939
2940 p_pkt_info->byte_cnt = (p_rx_desc->byte_cnt) - RX_BUF_OFFSET;
2941 p_pkt_info->cmd_sts = command_status;
2942 p_pkt_info->buf_ptr = (p_rx_desc->buf_ptr) + RX_BUF_OFFSET;
2943 p_pkt_info->return_info = mp->rx_skb[rx_curr_desc];
2944 p_pkt_info->l4i_chk = p_rx_desc->buf_size;
2945
2946 /* Clean the return info field to indicate that the packet has been */
2947 /* moved to the upper layers */
2948 mp->rx_skb[rx_curr_desc] = NULL;
2949
2950 /* Update current index in data structure */
2951 rx_next_curr_desc = (rx_curr_desc + 1) % mp->rx_ring_size;
2952 mp->rx_curr_desc_q = rx_next_curr_desc;
2953
2954 /* Rx descriptors exhausted. Set the Rx ring resource error flag */
2955 if (rx_next_curr_desc == rx_used_desc)
2956 mp->rx_resource_err = 1;
2957
Dale Farnsworth8f518702006-01-16 16:56:30 -07002958 spin_unlock_irqrestore(&mp->lock, flags);
2959
Linus Torvalds1da177e2005-04-16 15:20:36 -07002960 return ETH_OK;
2961}
2962
2963/*
2964 * eth_rx_return_buff - Returns a Rx buffer back to the Rx ring.
2965 *
2966 * DESCRIPTION:
2967 * This routine returns a Rx buffer back to the Rx ring. It retrieves the
2968 * next 'used' descriptor and attached the returned buffer to it.
2969 * In case the Rx ring was in "resource error" condition, where there are
2970 * no available Rx resources, the function resets the resource error flag.
2971 *
2972 * INPUT:
2973 * struct mv643xx_private *mp Ethernet Port Control srtuct.
2974 * struct pkt_info *p_pkt_info Information on returned buffer.
2975 *
2976 * OUTPUT:
2977 * New available Rx resource in Rx descriptor ring.
2978 *
2979 * RETURN:
2980 * ETH_ERROR in case the routine can not access Rx desc ring.
2981 * ETH_OK otherwise.
2982 */
2983static ETH_FUNC_RET_STATUS eth_rx_return_buff(struct mv643xx_private *mp,
2984 struct pkt_info *p_pkt_info)
2985{
2986 int used_rx_desc; /* Where to return Rx resource */
2987 volatile struct eth_rx_desc *p_used_rx_desc;
Dale Farnsworth8f518702006-01-16 16:56:30 -07002988 unsigned long flags;
2989
2990 spin_lock_irqsave(&mp->lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002991
2992 /* Get 'used' Rx descriptor */
2993 used_rx_desc = mp->rx_used_desc_q;
2994 p_used_rx_desc = &mp->p_rx_desc_area[used_rx_desc];
2995
2996 p_used_rx_desc->buf_ptr = p_pkt_info->buf_ptr;
2997 p_used_rx_desc->buf_size = p_pkt_info->byte_cnt;
2998 mp->rx_skb[used_rx_desc] = p_pkt_info->return_info;
2999
3000 /* Flush the write pipe */
3001
3002 /* Return the descriptor to DMA ownership */
3003 wmb();
3004 p_used_rx_desc->cmd_sts =
3005 ETH_BUFFER_OWNED_BY_DMA | ETH_RX_ENABLE_INTERRUPT;
3006 wmb();
3007
3008 /* Move the used descriptor pointer to the next descriptor */
3009 mp->rx_used_desc_q = (used_rx_desc + 1) % mp->rx_ring_size;
3010
3011 /* Any Rx return cancels the Rx resource error status */
3012 mp->rx_resource_err = 0;
3013
Dale Farnsworth8f518702006-01-16 16:56:30 -07003014 spin_unlock_irqrestore(&mp->lock, flags);
3015
Linus Torvalds1da177e2005-04-16 15:20:36 -07003016 return ETH_OK;
3017}
3018
3019/************* Begin ethtool support *************************/
3020
3021struct mv643xx_stats {
3022 char stat_string[ETH_GSTRING_LEN];
3023 int sizeof_stat;
3024 int stat_offset;
3025};
3026
3027#define MV643XX_STAT(m) sizeof(((struct mv643xx_private *)0)->m), \
3028 offsetof(struct mv643xx_private, m)
3029
3030static const struct mv643xx_stats mv643xx_gstrings_stats[] = {
3031 { "rx_packets", MV643XX_STAT(stats.rx_packets) },
3032 { "tx_packets", MV643XX_STAT(stats.tx_packets) },
3033 { "rx_bytes", MV643XX_STAT(stats.rx_bytes) },
3034 { "tx_bytes", MV643XX_STAT(stats.tx_bytes) },
3035 { "rx_errors", MV643XX_STAT(stats.rx_errors) },
3036 { "tx_errors", MV643XX_STAT(stats.tx_errors) },
3037 { "rx_dropped", MV643XX_STAT(stats.rx_dropped) },
3038 { "tx_dropped", MV643XX_STAT(stats.tx_dropped) },
3039 { "good_octets_received", MV643XX_STAT(mib_counters.good_octets_received) },
3040 { "bad_octets_received", MV643XX_STAT(mib_counters.bad_octets_received) },
3041 { "internal_mac_transmit_err", MV643XX_STAT(mib_counters.internal_mac_transmit_err) },
3042 { "good_frames_received", MV643XX_STAT(mib_counters.good_frames_received) },
3043 { "bad_frames_received", MV643XX_STAT(mib_counters.bad_frames_received) },
3044 { "broadcast_frames_received", MV643XX_STAT(mib_counters.broadcast_frames_received) },
3045 { "multicast_frames_received", MV643XX_STAT(mib_counters.multicast_frames_received) },
3046 { "frames_64_octets", MV643XX_STAT(mib_counters.frames_64_octets) },
3047 { "frames_65_to_127_octets", MV643XX_STAT(mib_counters.frames_65_to_127_octets) },
3048 { "frames_128_to_255_octets", MV643XX_STAT(mib_counters.frames_128_to_255_octets) },
3049 { "frames_256_to_511_octets", MV643XX_STAT(mib_counters.frames_256_to_511_octets) },
3050 { "frames_512_to_1023_octets", MV643XX_STAT(mib_counters.frames_512_to_1023_octets) },
3051 { "frames_1024_to_max_octets", MV643XX_STAT(mib_counters.frames_1024_to_max_octets) },
3052 { "good_octets_sent", MV643XX_STAT(mib_counters.good_octets_sent) },
3053 { "good_frames_sent", MV643XX_STAT(mib_counters.good_frames_sent) },
3054 { "excessive_collision", MV643XX_STAT(mib_counters.excessive_collision) },
3055 { "multicast_frames_sent", MV643XX_STAT(mib_counters.multicast_frames_sent) },
3056 { "broadcast_frames_sent", MV643XX_STAT(mib_counters.broadcast_frames_sent) },
3057 { "unrec_mac_control_received", MV643XX_STAT(mib_counters.unrec_mac_control_received) },
3058 { "fc_sent", MV643XX_STAT(mib_counters.fc_sent) },
3059 { "good_fc_received", MV643XX_STAT(mib_counters.good_fc_received) },
3060 { "bad_fc_received", MV643XX_STAT(mib_counters.bad_fc_received) },
3061 { "undersize_received", MV643XX_STAT(mib_counters.undersize_received) },
3062 { "fragments_received", MV643XX_STAT(mib_counters.fragments_received) },
3063 { "oversize_received", MV643XX_STAT(mib_counters.oversize_received) },
3064 { "jabber_received", MV643XX_STAT(mib_counters.jabber_received) },
3065 { "mac_receive_error", MV643XX_STAT(mib_counters.mac_receive_error) },
3066 { "bad_crc_event", MV643XX_STAT(mib_counters.bad_crc_event) },
3067 { "collision", MV643XX_STAT(mib_counters.collision) },
3068 { "late_collision", MV643XX_STAT(mib_counters.late_collision) },
3069};
3070
3071#define MV643XX_STATS_LEN \
3072 sizeof(mv643xx_gstrings_stats) / sizeof(struct mv643xx_stats)
3073
3074static int
3075mv643xx_get_settings(struct net_device *netdev, struct ethtool_cmd *ecmd)
3076{
3077 struct mv643xx_private *mp = netdev->priv;
3078 int port_num = mp->port_num;
3079 int autoneg = eth_port_autoneg_supported(port_num);
3080 int mode_10_bit;
3081 int auto_duplex;
3082 int half_duplex = 0;
3083 int full_duplex = 0;
3084 int auto_speed;
3085 int speed_10 = 0;
3086 int speed_100 = 0;
3087 int speed_1000 = 0;
3088
3089 u32 pcs = mv_read(MV643XX_ETH_PORT_SERIAL_CONTROL_REG(port_num));
3090 u32 psr = mv_read(MV643XX_ETH_PORT_STATUS_REG(port_num));
3091
3092 mode_10_bit = psr & MV643XX_ETH_PORT_STATUS_MODE_10_BIT;
3093
3094 if (mode_10_bit) {
3095 ecmd->supported = SUPPORTED_10baseT_Half;
3096 } else {
3097 ecmd->supported = (SUPPORTED_10baseT_Half |
3098 SUPPORTED_10baseT_Full |
3099 SUPPORTED_100baseT_Half |
3100 SUPPORTED_100baseT_Full |
3101 SUPPORTED_1000baseT_Full |
3102 (autoneg ? SUPPORTED_Autoneg : 0) |
3103 SUPPORTED_TP);
3104
3105 auto_duplex = !(pcs & MV643XX_ETH_DISABLE_AUTO_NEG_FOR_DUPLX);
3106 auto_speed = !(pcs & MV643XX_ETH_DISABLE_AUTO_NEG_SPEED_GMII);
3107
3108 ecmd->advertising = ADVERTISED_TP;
3109
3110 if (autoneg) {
3111 ecmd->advertising |= ADVERTISED_Autoneg;
3112
3113 if (auto_duplex) {
3114 half_duplex = 1;
3115 full_duplex = 1;
3116 } else {
3117 if (pcs & MV643XX_ETH_SET_FULL_DUPLEX_MODE)
3118 full_duplex = 1;
3119 else
3120 half_duplex = 1;
3121 }
3122
3123 if (auto_speed) {
3124 speed_10 = 1;
3125 speed_100 = 1;
3126 speed_1000 = 1;
3127 } else {
3128 if (pcs & MV643XX_ETH_SET_GMII_SPEED_TO_1000)
3129 speed_1000 = 1;
3130 else if (pcs & MV643XX_ETH_SET_MII_SPEED_TO_100)
3131 speed_100 = 1;
3132 else
3133 speed_10 = 1;
3134 }
3135
3136 if (speed_10 & half_duplex)
3137 ecmd->advertising |= ADVERTISED_10baseT_Half;
3138 if (speed_10 & full_duplex)
3139 ecmd->advertising |= ADVERTISED_10baseT_Full;
3140 if (speed_100 & half_duplex)
3141 ecmd->advertising |= ADVERTISED_100baseT_Half;
3142 if (speed_100 & full_duplex)
3143 ecmd->advertising |= ADVERTISED_100baseT_Full;
3144 if (speed_1000)
3145 ecmd->advertising |= ADVERTISED_1000baseT_Full;
3146 }
3147 }
3148
3149 ecmd->port = PORT_TP;
3150 ecmd->phy_address = ethernet_phy_get(port_num);
3151
3152 ecmd->transceiver = XCVR_EXTERNAL;
3153
3154 if (netif_carrier_ok(netdev)) {
3155 if (mode_10_bit)
3156 ecmd->speed = SPEED_10;
3157 else {
3158 if (psr & MV643XX_ETH_PORT_STATUS_GMII_1000)
3159 ecmd->speed = SPEED_1000;
3160 else if (psr & MV643XX_ETH_PORT_STATUS_MII_100)
3161 ecmd->speed = SPEED_100;
3162 else
3163 ecmd->speed = SPEED_10;
3164 }
3165
3166 if (psr & MV643XX_ETH_PORT_STATUS_FULL_DUPLEX)
3167 ecmd->duplex = DUPLEX_FULL;
3168 else
3169 ecmd->duplex = DUPLEX_HALF;
3170 } else {
3171 ecmd->speed = -1;
3172 ecmd->duplex = -1;
3173 }
3174
3175 ecmd->autoneg = autoneg ? AUTONEG_ENABLE : AUTONEG_DISABLE;
3176 return 0;
3177}
3178
3179static void
3180mv643xx_get_drvinfo(struct net_device *netdev,
3181 struct ethtool_drvinfo *drvinfo)
3182{
3183 strncpy(drvinfo->driver, mv643xx_driver_name, 32);
3184 strncpy(drvinfo->version, mv643xx_driver_version, 32);
3185 strncpy(drvinfo->fw_version, "N/A", 32);
3186 strncpy(drvinfo->bus_info, "mv643xx", 32);
3187 drvinfo->n_stats = MV643XX_STATS_LEN;
3188}
3189
3190static int
3191mv643xx_get_stats_count(struct net_device *netdev)
3192{
3193 return MV643XX_STATS_LEN;
3194}
3195
3196static void
3197mv643xx_get_ethtool_stats(struct net_device *netdev,
3198 struct ethtool_stats *stats, uint64_t *data)
3199{
3200 struct mv643xx_private *mp = netdev->priv;
3201 int i;
3202
3203 eth_update_mib_counters(mp);
3204
3205 for(i = 0; i < MV643XX_STATS_LEN; i++) {
3206 char *p = (char *)mp+mv643xx_gstrings_stats[i].stat_offset;
3207 data[i] = (mv643xx_gstrings_stats[i].sizeof_stat ==
3208 sizeof(uint64_t)) ? *(uint64_t *)p : *(uint32_t *)p;
3209 }
3210}
3211
3212static void
3213mv643xx_get_strings(struct net_device *netdev, uint32_t stringset, uint8_t *data)
3214{
3215 int i;
3216
3217 switch(stringset) {
3218 case ETH_SS_STATS:
3219 for (i=0; i < MV643XX_STATS_LEN; i++) {
3220 memcpy(data + i * ETH_GSTRING_LEN,
3221 mv643xx_gstrings_stats[i].stat_string,
3222 ETH_GSTRING_LEN);
3223 }
3224 break;
3225 }
3226}
3227
3228static struct ethtool_ops mv643xx_ethtool_ops = {
3229 .get_settings = mv643xx_get_settings,
3230 .get_drvinfo = mv643xx_get_drvinfo,
3231 .get_link = ethtool_op_get_link,
3232 .get_sg = ethtool_op_get_sg,
3233 .set_sg = ethtool_op_set_sg,
3234 .get_strings = mv643xx_get_strings,
3235 .get_stats_count = mv643xx_get_stats_count,
3236 .get_ethtool_stats = mv643xx_get_ethtool_stats,
3237};
3238
3239/************* End ethtool support *************************/