3 * Ingo Assmus <ingo.assmus@keymile.com>
5 * based on - Driver for MV64460X ethernet ports
6 * Copyright (C) 2002 rabeeh@galileo.co.il
8 * See file CREDITS for list of people who contributed to this
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License as
13 * published by the Free Software Foundation; either version 2 of
14 * the License, or (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
28 * mv_eth.c - header file for the polled mode GT ethernet driver
36 /* enable Debug outputs */
47 #undef MV64460_CHECKSUM_OFFLOAD
48 /*************************************************************************
49 **************************************************************************
50 **************************************************************************
51 * The first part is the high level driver of the gigE ethernet ports. *
52 **************************************************************************
53 **************************************************************************
54 *************************************************************************/
56 /* Definition for configuring driver */
57 /* #define UPDATE_STATS_BY_SOFTWARE */
58 #undef MV64460_RX_QUEUE_FILL_ON_TASK
62 #define MAGIC_ETH_RUNNING 8031971
63 #define MV64460_INTERNAL_SRAM_SIZE _256K
64 #define EXTRA_BYTES 32
65 #define WRAP ETH_HLEN + 2 + 4 + 16
66 #define BUFFER_MTU dev->mtu + WRAP
67 #define INT_CAUSE_UNMASK_ALL 0x0007ffff
68 #define INT_CAUSE_UNMASK_ALL_EXT 0x0011ffff
69 #ifdef MV64460_RX_FILL_ON_TASK
70 #define INT_CAUSE_MASK_ALL 0x00000000
71 #define INT_CAUSE_CHECK_BITS INT_CAUSE_UNMASK_ALL
72 #define INT_CAUSE_CHECK_BITS_EXT INT_CAUSE_UNMASK_ALL_EXT
75 /* Read/Write to/from MV64460 internal registers */
76 #define MV_REG_READ(offset) my_le32_to_cpu(* (volatile unsigned int *) (INTERNAL_REG_BASE_ADDR + offset))
77 #define MV_REG_WRITE(offset,data) *(volatile unsigned int *) (INTERNAL_REG_BASE_ADDR + offset) = my_cpu_to_le32 (data)
78 #define MV_SET_REG_BITS(regOffset,bits) ((*((volatile unsigned int*)((INTERNAL_REG_BASE_ADDR) + (regOffset)))) |= ((unsigned int)my_cpu_to_le32(bits)))
79 #define MV_RESET_REG_BITS(regOffset,bits) ((*((volatile unsigned int*)((INTERNAL_REG_BASE_ADDR) + (regOffset)))) &= ~((unsigned int)my_cpu_to_le32(bits)))
81 /* Static function declarations */
82 static int mv64460_eth_real_open (struct eth_device *eth);
83 static int mv64460_eth_real_stop (struct eth_device *eth);
84 static struct net_device_stats *mv64460_eth_get_stats (struct eth_device
86 static void eth_port_init_mac_tables (ETH_PORT eth_port_num);
87 static void mv64460_eth_update_stat (struct eth_device *dev);
88 bool db64460_eth_start (struct eth_device *eth);
89 unsigned int eth_read_mib_counter (ETH_PORT eth_port_num,
90 unsigned int mib_offset);
91 int mv64460_eth_receive (struct eth_device *dev);
93 int mv64460_eth_xmit (struct eth_device *, volatile void *packet, int length);
95 #ifndef UPDATE_STATS_BY_SOFTWARE
96 static void mv64460_eth_print_stat (struct eth_device *dev);
98 /* Processes a received packet */
99 extern void NetReceive (volatile uchar *, int);
101 extern unsigned int INTERNAL_REG_BASE_ADDR;
103 /*************************************************
104 *Helper functions - used inside the driver only *
105 *************************************************/
107 void print_globals (struct eth_device *dev)
109 printf ("Ethernet PRINT_Globals-Debug function\n");
110 printf ("Base Address for ETH_PORT_INFO: %08x\n",
111 (unsigned int) dev->priv);
112 printf ("Base Address for mv64460_eth_priv: %08x\n",
113 (unsigned int) &(((ETH_PORT_INFO *) dev->priv)->
116 printf ("GT Internal Base Address: %08x\n",
117 INTERNAL_REG_BASE_ADDR);
118 printf ("Base Address for TX-DESCs: %08x Number of allocated Buffers %d\n", (unsigned int) ((ETH_PORT_INFO *) dev->priv)->p_tx_desc_area_base[0], MV64460_TX_QUEUE_SIZE);
119 printf ("Base Address for RX-DESCs: %08x Number of allocated Buffers %d\n", (unsigned int) ((ETH_PORT_INFO *) dev->priv)->p_rx_desc_area_base[0], MV64460_RX_QUEUE_SIZE);
120 printf ("Base Address for RX-Buffer: %08x allocated Bytes %d\n",
121 (unsigned int) ((ETH_PORT_INFO *) dev->priv)->
123 (MV64460_RX_QUEUE_SIZE * MV64460_RX_BUFFER_SIZE) + 32);
124 printf ("Base Address for TX-Buffer: %08x allocated Bytes %d\n",
125 (unsigned int) ((ETH_PORT_INFO *) dev->priv)->
127 (MV64460_TX_QUEUE_SIZE * MV64460_TX_BUFFER_SIZE) + 32);
131 #define my_cpu_to_le32(x) my_le32_to_cpu((x))
133 unsigned long my_le32_to_cpu (unsigned long x)
135 return (((x & 0x000000ffU) << 24) |
136 ((x & 0x0000ff00U) << 8) |
137 ((x & 0x00ff0000U) >> 8) | ((x & 0xff000000U) >> 24));
141 /**********************************************************************
142 * mv64460_eth_print_phy_status
144 * Prints gigabit ethenret phy status
146 * Input : pointer to ethernet interface network device structure
148 **********************************************************************/
150 static void mv64460_eth_print_phy_status (struct eth_device *dev)
152 struct mv64460_eth_priv *port_private;
153 unsigned int port_num;
154 ETH_PORT_INFO *ethernet_private = (ETH_PORT_INFO *) dev->priv;
155 unsigned int port_status, phy_reg_data;
158 (struct mv64460_eth_priv *) ethernet_private->port_private;
159 port_num = port_private->port_num;
161 /* Check Link status on phy */
162 eth_port_read_smi_reg (port_num, 1, &phy_reg_data);
163 if (!(phy_reg_data & 0x20)) {
164 printf ("Ethernet port changed link status to DOWN\n");
167 MV_REG_READ (MV64460_ETH_PORT_STATUS_REG (port_num));
168 printf ("Ethernet status port %d: Link up", port_num);
170 (port_status & BIT2) ? "Full Duplex" : "Half Duplex");
171 if (port_status & BIT4)
172 printf (", Speed 1 Gbps");
175 (port_status & BIT5) ? "Speed 100 Mbps" :
181 /**********************************************************************
182 * u-boot entry functions for mv64460_eth
184 **********************************************************************/
185 int db64460_eth_probe (struct eth_device *dev)
187 return ((int) db64460_eth_start (dev));
190 int db64460_eth_poll (struct eth_device *dev)
192 return mv64460_eth_receive (dev);
195 int db64460_eth_transmit (struct eth_device *dev, volatile void *packet,
198 mv64460_eth_xmit (dev, packet, length);
202 void db64460_eth_disable (struct eth_device *dev)
204 mv64460_eth_stop (dev);
208 void mv6446x_eth_initialize (bd_t * bis)
210 struct eth_device *dev;
211 ETH_PORT_INFO *ethernet_private;
212 struct mv64460_eth_priv *port_private;
214 char *s, *e, buf[64];
216 for (devnum = 0; devnum < MV_ETH_DEVS; devnum++) {
217 dev = calloc (sizeof (*dev), 1);
219 printf ("%s: mv_enet%d allocation failure, %s\n",
220 __FUNCTION__, devnum, "eth_device structure");
224 /* must be less than NAMESIZE (16) */
225 sprintf (dev->name, "mv_enet%d", devnum);
228 printf ("Initializing %s\n", dev->name);
231 /* Extract the MAC address from the environment */
245 default: /* this should never happen */
246 printf ("%s: Invalid device number %d\n",
247 __FUNCTION__, devnum);
251 temp = getenv_f(s, buf, sizeof (buf));
252 s = (temp > 0) ? buf : NULL;
255 printf ("Setting MAC %d to %s\n", devnum, s);
257 for (x = 0; x < 6; ++x) {
258 dev->enetaddr[x] = s ? simple_strtoul (s, &e, 16) : 0;
260 s = (*e) ? e + 1 : e;
262 /* ronen - set the MAC addr in the HW */
263 eth_port_uc_addr_set (devnum, dev->enetaddr, 0);
265 dev->init = (void *) db64460_eth_probe;
266 dev->halt = (void *) ethernet_phy_reset;
267 dev->send = (void *) db64460_eth_transmit;
268 dev->recv = (void *) db64460_eth_poll;
270 ethernet_private = calloc (sizeof (*ethernet_private), 1);
271 dev->priv = (void *)ethernet_private;
272 if (!ethernet_private) {
273 printf ("%s: %s allocation failure, %s\n",
274 __FUNCTION__, dev->name,
275 "Private Device Structure");
279 /* start with an zeroed ETH_PORT_INFO */
280 memset (ethernet_private, 0, sizeof (ETH_PORT_INFO));
281 memcpy (ethernet_private->port_mac_addr, dev->enetaddr, 6);
283 /* set pointer to memory for stats data structure etc... */
284 port_private = calloc (sizeof (*ethernet_private), 1);
285 ethernet_private->port_private = (void *)port_private;
287 printf ("%s: %s allocation failure, %s\n",
288 __FUNCTION__, dev->name,
289 "Port Private Device Structure");
291 free (ethernet_private);
296 port_private->stats =
297 calloc (sizeof (struct net_device_stats), 1);
298 if (!port_private->stats) {
299 printf ("%s: %s allocation failure, %s\n",
300 __FUNCTION__, dev->name,
301 "Net stat Structure");
304 free (ethernet_private);
308 memset (ethernet_private->port_private, 0,
309 sizeof (struct mv64460_eth_priv));
312 ethernet_private->port_num = ETH_0;
315 ethernet_private->port_num = ETH_1;
318 ethernet_private->port_num = ETH_2;
321 printf ("Invalid device number %d\n", devnum);
325 port_private->port_num = devnum;
327 * Read MIB counter on the GT in order to reset them,
328 * then zero all the stats fields in memory
330 mv64460_eth_update_stat (dev);
331 memset (port_private->stats, 0,
332 sizeof (struct net_device_stats));
333 /* Extract the MAC address from the environment */
347 default: /* this should never happen */
348 printf ("%s: Invalid device number %d\n",
349 __FUNCTION__, devnum);
353 temp = getenv_f(s, buf, sizeof (buf));
354 s = (temp > 0) ? buf : NULL;
357 printf ("Setting MAC %d to %s\n", devnum, s);
359 for (x = 0; x < 6; ++x) {
360 dev->enetaddr[x] = s ? simple_strtoul (s, &e, 16) : 0;
362 s = (*e) ? e + 1 : e;
365 DP (printf ("Allocating descriptor and buffer rings\n"));
367 ethernet_private->p_rx_desc_area_base[0] =
368 (ETH_RX_DESC *) memalign (16,
369 RX_DESC_ALIGNED_SIZE *
370 MV64460_RX_QUEUE_SIZE + 1);
371 ethernet_private->p_tx_desc_area_base[0] =
372 (ETH_TX_DESC *) memalign (16,
373 TX_DESC_ALIGNED_SIZE *
374 MV64460_TX_QUEUE_SIZE + 1);
376 ethernet_private->p_rx_buffer_base[0] =
377 (char *) memalign (16,
378 MV64460_RX_QUEUE_SIZE *
379 MV64460_TX_BUFFER_SIZE + 1);
380 ethernet_private->p_tx_buffer_base[0] =
381 (char *) memalign (16,
382 MV64460_RX_QUEUE_SIZE *
383 MV64460_TX_BUFFER_SIZE + 1);
386 /* DEBUG OUTPUT prints adresses of globals */
392 DP (printf ("%s: exit\n", __FUNCTION__));
396 /**********************************************************************
399 * This function is called when openning the network device. The function
400 * should initialize all the hardware, initialize cyclic Rx/Tx
401 * descriptors chain and buffers and allocate an IRQ to the network
404 * Input : a pointer to the network device structure
405 * / / ronen - changed the output to match net/eth.c needs
406 * Output : nonzero of success , zero if fails.
408 **********************************************************************/
410 int mv64460_eth_open (struct eth_device *dev)
412 return (mv64460_eth_real_open (dev));
415 /* Helper function for mv64460_eth_open */
416 static int mv64460_eth_real_open (struct eth_device *dev)
420 ETH_PORT_INFO *ethernet_private;
421 struct mv64460_eth_priv *port_private;
422 unsigned int port_num;
425 ethernet_private = (ETH_PORT_INFO *) dev->priv;
426 /* ronen - when we update the MAC env params we only update dev->enetaddr
427 see ./net/eth.c eth_set_enetaddr() */
428 memcpy (ethernet_private->port_mac_addr, dev->enetaddr, 6);
431 (struct mv64460_eth_priv *) ethernet_private->port_private;
432 port_num = port_private->port_num;
435 MV_REG_WRITE (MV64460_ETH_RECEIVE_QUEUE_COMMAND_REG (port_num),
438 /* Clear the ethernet port interrupts */
439 MV_REG_WRITE (MV64460_ETH_INTERRUPT_CAUSE_REG (port_num), 0);
440 MV_REG_WRITE (MV64460_ETH_INTERRUPT_CAUSE_EXTEND_REG (port_num), 0);
442 /* Unmask RX buffer and TX end interrupt */
443 MV_REG_WRITE (MV64460_ETH_INTERRUPT_MASK_REG (port_num),
444 INT_CAUSE_UNMASK_ALL);
446 /* Unmask phy and link status changes interrupts */
447 MV_REG_WRITE (MV64460_ETH_INTERRUPT_EXTEND_MASK_REG (port_num),
448 INT_CAUSE_UNMASK_ALL_EXT);
450 /* Set phy address of the port */
451 ethernet_private->port_phy_addr = 0x8 + port_num;
453 /* Activate the DMA channels etc */
454 eth_port_init (ethernet_private);
457 /* "Allocate" setup TX rings */
459 for (queue = 0; queue < MV64460_TX_QUEUE_NUM; queue++) {
462 port_private->tx_ring_size[queue] = MV64460_TX_QUEUE_SIZE;
463 size = (port_private->tx_ring_size[queue] * TX_DESC_ALIGNED_SIZE); /*size = no of DESCs times DESC-size */
464 ethernet_private->tx_desc_area_size[queue] = size;
466 /* first clear desc area completely */
467 memset ((void *) ethernet_private->p_tx_desc_area_base[queue],
468 0, ethernet_private->tx_desc_area_size[queue]);
470 /* initialize tx desc ring with low level driver */
471 if (ether_init_tx_desc_ring
472 (ethernet_private, ETH_Q0,
473 port_private->tx_ring_size[queue],
474 MV64460_TX_BUFFER_SIZE /* Each Buffer is 1600 Byte */ ,
475 (unsigned int) ethernet_private->
476 p_tx_desc_area_base[queue],
477 (unsigned int) ethernet_private->
478 p_tx_buffer_base[queue]) == false)
479 printf ("### Error initializing TX Ring\n");
482 /* "Allocate" setup RX rings */
483 for (queue = 0; queue < MV64460_RX_QUEUE_NUM; queue++) {
486 /* Meantime RX Ring are fixed - but must be configurable by user */
487 port_private->rx_ring_size[queue] = MV64460_RX_QUEUE_SIZE;
488 size = (port_private->rx_ring_size[queue] *
489 RX_DESC_ALIGNED_SIZE);
490 ethernet_private->rx_desc_area_size[queue] = size;
492 /* first clear desc area completely */
493 memset ((void *) ethernet_private->p_rx_desc_area_base[queue],
494 0, ethernet_private->rx_desc_area_size[queue]);
495 if ((ether_init_rx_desc_ring
496 (ethernet_private, ETH_Q0,
497 port_private->rx_ring_size[queue],
498 MV64460_RX_BUFFER_SIZE /* Each Buffer is 1600 Byte */ ,
499 (unsigned int) ethernet_private->
500 p_rx_desc_area_base[queue],
501 (unsigned int) ethernet_private->
502 p_rx_buffer_base[queue])) == false)
503 printf ("### Error initializing RX Ring\n");
506 eth_port_start (ethernet_private);
508 /* Set maximum receive buffer to 9700 bytes */
509 MV_REG_WRITE (MV64460_ETH_PORT_SERIAL_CONTROL_REG (port_num),
512 (MV64460_ETH_PORT_SERIAL_CONTROL_REG (port_num))
516 * Set ethernet MTU for leaky bucket mechanism to 0 - this will
517 * disable the leaky bucket mechanism .
520 MV_REG_WRITE (MV64460_ETH_MAXIMUM_TRANSMIT_UNIT (port_num), 0);
521 MV_REG_READ (MV64460_ETH_PORT_STATUS_REG (port_num));
523 /* Check Link status on phy */
524 eth_port_read_smi_reg (port_num, 1, &phy_reg_data);
525 if (!(phy_reg_data & 0x20)) {
527 if ((ethernet_phy_reset (port_num)) != true) {
528 printf ("$$ Warnning: No link on port %d \n",
532 eth_port_read_smi_reg (port_num, 1, &phy_reg_data);
533 if (!(phy_reg_data & 0x20)) {
534 printf ("### Error: Phy is not active\n");
539 mv64460_eth_print_phy_status (dev);
541 port_private->eth_running = MAGIC_ETH_RUNNING;
546 static int mv64460_eth_free_tx_rings (struct eth_device *dev)
549 ETH_PORT_INFO *ethernet_private;
550 struct mv64460_eth_priv *port_private;
551 unsigned int port_num;
552 volatile ETH_TX_DESC *p_tx_curr_desc;
554 ethernet_private = (ETH_PORT_INFO *) dev->priv;
556 (struct mv64460_eth_priv *) ethernet_private->port_private;
557 port_num = port_private->port_num;
560 MV_REG_WRITE (MV64460_ETH_TRANSMIT_QUEUE_COMMAND_REG (port_num),
564 DP (printf ("Clearing previously allocated TX queues... "));
565 for (queue = 0; queue < MV64460_TX_QUEUE_NUM; queue++) {
566 /* Free on TX rings */
567 for (p_tx_curr_desc =
568 ethernet_private->p_tx_desc_area_base[queue];
569 ((unsigned int) p_tx_curr_desc <= (unsigned int)
570 ethernet_private->p_tx_desc_area_base[queue] +
571 ethernet_private->tx_desc_area_size[queue]);
573 (ETH_TX_DESC *) ((unsigned int) p_tx_curr_desc +
574 TX_DESC_ALIGNED_SIZE)) {
575 /* this is inside for loop */
576 if (p_tx_curr_desc->return_info != 0) {
577 p_tx_curr_desc->return_info = 0;
578 DP (printf ("freed\n"));
581 DP (printf ("Done\n"));
586 static int mv64460_eth_free_rx_rings (struct eth_device *dev)
589 ETH_PORT_INFO *ethernet_private;
590 struct mv64460_eth_priv *port_private;
591 unsigned int port_num;
592 volatile ETH_RX_DESC *p_rx_curr_desc;
594 ethernet_private = (ETH_PORT_INFO *) dev->priv;
596 (struct mv64460_eth_priv *) ethernet_private->port_private;
597 port_num = port_private->port_num;
601 MV_REG_WRITE (MV64460_ETH_RECEIVE_QUEUE_COMMAND_REG (port_num),
605 DP (printf ("Clearing previously allocated RX queues... "));
606 for (queue = 0; queue < MV64460_RX_QUEUE_NUM; queue++) {
607 /* Free preallocated skb's on RX rings */
608 for (p_rx_curr_desc =
609 ethernet_private->p_rx_desc_area_base[queue];
610 (((unsigned int) p_rx_curr_desc <
611 ((unsigned int) ethernet_private->
612 p_rx_desc_area_base[queue] +
613 ethernet_private->rx_desc_area_size[queue])));
615 (ETH_RX_DESC *) ((unsigned int) p_rx_curr_desc +
616 RX_DESC_ALIGNED_SIZE)) {
617 if (p_rx_curr_desc->return_info != 0) {
618 p_rx_curr_desc->return_info = 0;
619 DP (printf ("freed\n"));
622 DP (printf ("Done\n"));
627 /**********************************************************************
630 * This function is used when closing the network device.
631 * It updates the hardware,
632 * release all memory that holds buffers and descriptors and release the IRQ.
633 * Input : a pointer to the device structure
634 * Output : zero if success , nonzero if fails
635 *********************************************************************/
637 int mv64460_eth_stop (struct eth_device *dev)
639 /* Disable all gigE address decoder */
640 MV_REG_WRITE (MV64460_ETH_BASE_ADDR_ENABLE_REG, 0x3f);
641 DP (printf ("%s Ethernet stop called ... \n", __FUNCTION__));
642 mv64460_eth_real_stop (dev);
647 /* Helper function for mv64460_eth_stop */
649 static int mv64460_eth_real_stop (struct eth_device *dev)
651 ETH_PORT_INFO *ethernet_private;
652 struct mv64460_eth_priv *port_private;
653 unsigned int port_num;
655 ethernet_private = (ETH_PORT_INFO *) dev->priv;
657 (struct mv64460_eth_priv *) ethernet_private->port_private;
658 port_num = port_private->port_num;
661 mv64460_eth_free_tx_rings (dev);
662 mv64460_eth_free_rx_rings (dev);
664 eth_port_reset (ethernet_private->port_num);
665 /* Disable ethernet port interrupts */
666 MV_REG_WRITE (MV64460_ETH_INTERRUPT_CAUSE_REG (port_num), 0);
667 MV_REG_WRITE (MV64460_ETH_INTERRUPT_CAUSE_EXTEND_REG (port_num), 0);
668 /* Mask RX buffer and TX end interrupt */
669 MV_REG_WRITE (MV64460_ETH_INTERRUPT_MASK_REG (port_num), 0);
670 /* Mask phy and link status changes interrupts */
671 MV_REG_WRITE (MV64460_ETH_INTERRUPT_EXTEND_MASK_REG (port_num), 0);
672 MV_RESET_REG_BITS (MV64460_CPU_INTERRUPT0_MASK_HIGH,
674 /* Print Network statistics */
675 #ifndef UPDATE_STATS_BY_SOFTWARE
677 * Print statistics (only if ethernet is running),
678 * then zero all the stats fields in memory
680 if (port_private->eth_running == MAGIC_ETH_RUNNING) {
681 port_private->eth_running = 0;
682 mv64460_eth_print_stat (dev);
684 memset (port_private->stats, 0, sizeof (struct net_device_stats));
686 DP (printf ("\nEthernet stopped ... \n"));
691 /**********************************************************************
692 * mv64460_eth_start_xmit
694 * This function is queues a packet in the Tx descriptor for
697 * Input : skb - a pointer to socket buffer
698 * dev - a pointer to the required port
700 * Output : zero upon success
701 **********************************************************************/
703 int mv64460_eth_xmit (struct eth_device *dev, volatile void *dataPtr,
706 ETH_PORT_INFO *ethernet_private;
707 struct mv64460_eth_priv *port_private;
709 ETH_FUNC_RET_STATUS status;
710 struct net_device_stats *stats;
711 ETH_FUNC_RET_STATUS release_result;
713 ethernet_private = (ETH_PORT_INFO *) dev->priv;
715 (struct mv64460_eth_priv *) ethernet_private->port_private;
717 stats = port_private->stats;
719 /* Update packet info data structure */
720 pkt_info.cmd_sts = ETH_TX_FIRST_DESC | ETH_TX_LAST_DESC; /* DMA owned, first last */
721 pkt_info.byte_cnt = dataSize;
722 pkt_info.buf_ptr = (unsigned int) dataPtr;
723 pkt_info.return_info = 0;
725 status = eth_port_send (ethernet_private, ETH_Q0, &pkt_info);
726 if ((status == ETH_ERROR) || (status == ETH_QUEUE_FULL)) {
727 printf ("Error on transmitting packet ..");
728 if (status == ETH_QUEUE_FULL)
729 printf ("ETH Queue is full. \n");
730 if (status == ETH_QUEUE_LAST_RESOURCE)
731 printf ("ETH Queue: using last available resource. \n");
735 /* Update statistics and start of transmittion time */
736 stats->tx_bytes += dataSize;
739 /* Check if packet(s) is(are) transmitted correctly (release everything) */
742 eth_tx_return_desc (ethernet_private, ETH_Q0,
744 switch (release_result) {
746 DP (printf ("descriptor released\n"));
747 if (pkt_info.cmd_sts & BIT0) {
748 printf ("Error in TX\n");
754 DP (printf ("transmission still in process\n"));
758 printf ("routine can not access Tx desc ring\n");
762 DP (printf ("the routine has nothing to release\n"));
764 default: /* should not happen */
767 } while (release_result == ETH_OK);
770 return 0; /* success */
772 return 1; /* Failed - higher layers will free the skb */
775 /**********************************************************************
776 * mv64460_eth_receive
778 * This function is forward packets that are received from the port's
779 * queues toward kernel core or FastRoute them to another interface.
781 * Input : dev - a pointer to the required interface
782 * max - maximum number to receive (0 means unlimted)
784 * Output : number of served packets
785 **********************************************************************/
787 int mv64460_eth_receive (struct eth_device *dev)
789 ETH_PORT_INFO *ethernet_private;
790 struct mv64460_eth_priv *port_private;
792 struct net_device_stats *stats;
794 ethernet_private = (ETH_PORT_INFO *) dev->priv;
796 (struct mv64460_eth_priv *) ethernet_private->port_private;
797 stats = port_private->stats;
799 while ((eth_port_receive (ethernet_private, ETH_Q0, &pkt_info) ==
803 if (pkt_info.byte_cnt != 0) {
804 printf ("%s: Received %d byte Packet @ 0x%x\n",
805 __FUNCTION__, pkt_info.byte_cnt,
809 /* Update statistics. Note byte count includes 4 byte CRC count */
811 stats->rx_bytes += pkt_info.byte_cnt;
814 * In case received a packet without first / last bits on OR the error
815 * summary bit is on, the packets needs to be dropeed.
818 cmd_sts & (ETH_RX_FIRST_DESC | ETH_RX_LAST_DESC)) !=
819 (ETH_RX_FIRST_DESC | ETH_RX_LAST_DESC))
820 || (pkt_info.cmd_sts & ETH_ERROR_SUMMARY)) {
823 printf ("Received packet spread on multiple descriptors\n");
825 /* Is this caused by an error ? */
826 if (pkt_info.cmd_sts & ETH_ERROR_SUMMARY) {
830 /* free these descriptors again without forwarding them to the higher layers */
831 pkt_info.buf_ptr &= ~0x7; /* realign buffer again */
832 pkt_info.byte_cnt = 0x0000; /* Reset Byte count */
834 if (eth_rx_return_buff
835 (ethernet_private, ETH_Q0, &pkt_info) != ETH_OK) {
836 printf ("Error while returning the RX Desc to Ring\n");
838 DP (printf ("RX Desc returned to Ring\n"));
840 /* /free these descriptors again */
843 /* !!! call higher layer processing */
845 printf ("\nNow send it to upper layer protocols (NetReceive) ...\n");
847 /* let the upper layer handle the packet */
848 NetReceive ((uchar *) pkt_info.buf_ptr,
849 (int) pkt_info.byte_cnt);
851 /* **************************************************************** */
852 /* free descriptor */
853 pkt_info.buf_ptr &= ~0x7; /* realign buffer again */
854 pkt_info.byte_cnt = 0x0000; /* Reset Byte count */
856 ("RX: pkt_info.buf_ptr = %x\n",
858 if (eth_rx_return_buff
859 (ethernet_private, ETH_Q0, &pkt_info) != ETH_OK) {
860 printf ("Error while returning the RX Desc to Ring\n");
862 DP (printf ("RX Desc returned to Ring\n"));
865 /* **************************************************************** */
869 mv64460_eth_get_stats (dev); /* update statistics */
873 /**********************************************************************
874 * mv64460_eth_get_stats
876 * Returns a pointer to the interface statistics.
878 * Input : dev - a pointer to the required interface
880 * Output : a pointer to the interface's statistics
881 **********************************************************************/
883 static struct net_device_stats *mv64460_eth_get_stats (struct eth_device *dev)
885 ETH_PORT_INFO *ethernet_private;
886 struct mv64460_eth_priv *port_private;
888 ethernet_private = (ETH_PORT_INFO *) dev->priv;
890 (struct mv64460_eth_priv *) ethernet_private->port_private;
892 mv64460_eth_update_stat (dev);
894 return port_private->stats;
898 /**********************************************************************
899 * mv64460_eth_update_stat
901 * Update the statistics structure in the private data structure
903 * Input : pointer to ethernet interface network device structure
905 **********************************************************************/
907 static void mv64460_eth_update_stat (struct eth_device *dev)
909 ETH_PORT_INFO *ethernet_private;
910 struct mv64460_eth_priv *port_private;
911 struct net_device_stats *stats;
913 ethernet_private = (ETH_PORT_INFO *) dev->priv;
915 (struct mv64460_eth_priv *) ethernet_private->port_private;
916 stats = port_private->stats;
918 /* These are false updates */
919 stats->rx_packets += (unsigned long)
920 eth_read_mib_counter (ethernet_private->port_num,
921 ETH_MIB_GOOD_FRAMES_RECEIVED);
922 stats->tx_packets += (unsigned long)
923 eth_read_mib_counter (ethernet_private->port_num,
924 ETH_MIB_GOOD_FRAMES_SENT);
925 stats->rx_bytes += (unsigned long)
926 eth_read_mib_counter (ethernet_private->port_num,
927 ETH_MIB_GOOD_OCTETS_RECEIVED_LOW);
929 * Ideally this should be as follows -
931 * stats->rx_bytes += stats->rx_bytes +
932 * ((unsigned long) ethReadMibCounter (ethernet_private->port_num ,
933 * ETH_MIB_GOOD_OCTETS_RECEIVED_HIGH) << 32);
935 * But the unsigned long in PowerPC and MIPS are 32bit. So the next read
936 * is just a dummy read for proper work of the GigE port
938 eth_read_mib_counter (ethernet_private->port_num,
939 ETH_MIB_GOOD_OCTETS_RECEIVED_HIGH);
940 stats->tx_bytes += (unsigned long)
941 eth_read_mib_counter (ethernet_private->port_num,
942 ETH_MIB_GOOD_OCTETS_SENT_LOW);
943 eth_read_mib_counter (ethernet_private->port_num,
944 ETH_MIB_GOOD_OCTETS_SENT_HIGH);
945 stats->rx_errors += (unsigned long)
946 eth_read_mib_counter (ethernet_private->port_num,
947 ETH_MIB_MAC_RECEIVE_ERROR);
949 /* Rx dropped is for received packet with CRC error */
951 (unsigned long) eth_read_mib_counter (ethernet_private->
953 ETH_MIB_BAD_CRC_EVENT);
954 stats->multicast += (unsigned long)
955 eth_read_mib_counter (ethernet_private->port_num,
956 ETH_MIB_MULTICAST_FRAMES_RECEIVED);
958 (unsigned long) eth_read_mib_counter (ethernet_private->
961 (unsigned long) eth_read_mib_counter (ethernet_private->
963 ETH_MIB_LATE_COLLISION);
964 /* detailed rx errors */
965 stats->rx_length_errors +=
966 (unsigned long) eth_read_mib_counter (ethernet_private->
968 ETH_MIB_UNDERSIZE_RECEIVED)
970 (unsigned long) eth_read_mib_counter (ethernet_private->
972 ETH_MIB_OVERSIZE_RECEIVED);
973 /* detailed tx errors */
976 #ifndef UPDATE_STATS_BY_SOFTWARE
977 /**********************************************************************
978 * mv64460_eth_print_stat
980 * Update the statistics structure in the private data structure
982 * Input : pointer to ethernet interface network device structure
984 **********************************************************************/
986 static void mv64460_eth_print_stat (struct eth_device *dev)
988 ETH_PORT_INFO *ethernet_private;
989 struct mv64460_eth_priv *port_private;
990 struct net_device_stats *stats;
992 ethernet_private = (ETH_PORT_INFO *) dev->priv;
994 (struct mv64460_eth_priv *) ethernet_private->port_private;
995 stats = port_private->stats;
997 /* These are false updates */
998 printf ("\n### Network statistics: ###\n");
999 printf ("--------------------------\n");
1000 printf (" Packets received: %ld\n", stats->rx_packets);
1001 printf (" Packets send: %ld\n", stats->tx_packets);
1002 printf (" Received bytes: %ld\n", stats->rx_bytes);
1003 printf (" Send bytes: %ld\n", stats->tx_bytes);
1004 if (stats->rx_errors != 0)
1005 printf (" Rx Errors: %ld\n",
1007 if (stats->rx_dropped != 0)
1008 printf (" Rx dropped (CRC Errors): %ld\n",
1010 if (stats->multicast != 0)
1011 printf (" Rx mulicast frames: %ld\n",
1013 if (stats->collisions != 0)
1014 printf (" No. of collisions: %ld\n",
1016 if (stats->rx_length_errors != 0)
1017 printf (" Rx length errors: %ld\n",
1018 stats->rx_length_errors);
1022 /**************************************************************************
1023 *network_start - Network Kick Off Routine UBoot
1026 **************************************************************************/
1028 bool db64460_eth_start (struct eth_device *dev)
1030 return (mv64460_eth_open (dev)); /* calls real open */
1033 /*************************************************************************
1034 **************************************************************************
1035 **************************************************************************
1036 * The second part is the low level driver of the gigE ethernet ports. *
1037 **************************************************************************
1038 **************************************************************************
1039 *************************************************************************/
1041 * based on Linux code
1042 * arch/powerpc/galileo/EVB64460/mv64460_eth.c - Driver for MV64460X ethernet ports
1043 * Copyright (C) 2002 rabeeh@galileo.co.il
1045 * This program is free software; you can redistribute it and/or
1046 * modify it under the terms of the GNU General Public License
1047 * as published by the Free Software Foundation; either version 2
1048 * of the License, or (at your option) any later version.
1050 * This program is distributed in the hope that it will be useful,
1051 * but WITHOUT ANY WARRANTY; without even the implied warranty of
1052 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1053 * GNU General Public License for more details.
1055 * You should have received a copy of the GNU General Public License
1056 * along with this program; if not, write to the Free Software
1057 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
1061 /********************************************************************************
1062 * Marvell's Gigabit Ethernet controller low level driver
1065 * This file introduce low level API to Marvell's Gigabit Ethernet
1066 * controller. This Gigabit Ethernet Controller driver API controls
1067 * 1) Operations (i.e. port init, start, reset etc').
1068 * 2) Data flow (i.e. port send, receive etc').
1069 * Each Gigabit Ethernet port is controlled via ETH_PORT_INFO
1071 * This struct includes user configuration information as well as
1072 * driver internal data needed for its operations.
1074 * Supported Features:
1075 * - This low level driver is OS independent. Allocating memory for
1076 * the descriptor rings and buffers are not within the scope of
1078 * - The user is free from Rx/Tx queue managing.
1079 * - This low level driver introduce functionality API that enable
1080 * the to operate Marvell's Gigabit Ethernet Controller in a
1082 * - Simple Gigabit Ethernet port operation API.
1083 * - Simple Gigabit Ethernet port data flow API.
1084 * - Data flow and operation API support per queue functionality.
1085 * - Support cached descriptors for better performance.
1086 * - Enable access to all four DRAM banks and internal SRAM memory
1088 * - PHY access and control API.
1089 * - Port control register configuration API.
1090 * - Full control over Unicast and Multicast MAC configurations.
1094 * Initialization phase
1095 * This phase complete the initialization of the ETH_PORT_INFO
1097 * User information regarding port configuration has to be set
1098 * prior to calling the port initialization routine. For example,
1099 * the user has to assign the port_phy_addr field which is board
1100 * depended parameter.
1101 * In this phase any port Tx/Rx activity is halted, MIB counters
1102 * are cleared, PHY address is set according to user parameter and
1103 * access to DRAM and internal SRAM memory spaces.
1105 * Driver ring initialization
1106 * Allocating memory for the descriptor rings and buffers is not
1107 * within the scope of this driver. Thus, the user is required to
1108 * allocate memory for the descriptors ring and buffers. Those
1109 * memory parameters are used by the Rx and Tx ring initialization
1110 * routines in order to curve the descriptor linked list in a form
1112 * Note: Pay special attention to alignment issues when using
1113 * cached descriptors/buffers. In this phase the driver store
1114 * information in the ETH_PORT_INFO struct regarding each queue
1118 * This phase prepares the Ethernet port for Rx and Tx activity.
1119 * It uses the information stored in the ETH_PORT_INFO struct to
1120 * initialize the various port registers.
1123 * All packet references to/from the driver are done using PKT_INFO
1125 * This struct is a unified struct used with Rx and Tx operations.
1126 * This way the user is not required to be familiar with neither
1127 * Tx nor Rx descriptors structures.
1128 * The driver's descriptors rings are management by indexes.
1129 * Those indexes controls the ring resources and used to indicate
1130 * a SW resource error:
1132 * This index points to the current available resource for use. For
1133 * example in Rx process this index will point to the descriptor
1134 * that will be passed to the user upon calling the receive routine.
1135 * In Tx process, this index will point to the descriptor
1136 * that will be assigned with the user packet info and transmitted.
1138 * This index points to the descriptor that need to restore its
1139 * resources. For example in Rx process, using the Rx buffer return
1140 * API will attach the buffer returned in packet info to the
1141 * descriptor pointed by 'used'. In Tx process, using the Tx
1142 * descriptor return will merely return the user packet info with
1143 * the command status of the transmitted buffer pointed by the
1144 * 'used' index. Nevertheless, it is essential to use this routine
1145 * to update the 'used' index.
1147 * This index supports Tx Scatter-Gather. It points to the first
1148 * descriptor of a packet assembled of multiple buffers. For example
1149 * when in middle of Such packet we have a Tx resource error the
1150 * 'curr' index get the value of 'first' to indicate that the ring
1151 * returned to its state before trying to transmit this packet.
1153 * Receive operation:
1154 * The eth_port_receive API set the packet information struct,
1155 * passed by the caller, with received information from the
1156 * 'current' SDMA descriptor.
1157 * It is the user responsibility to return this resource back
1158 * to the Rx descriptor ring to enable the reuse of this source.
1159 * Return Rx resource is done using the eth_rx_return_buff API.
1161 * Transmit operation:
1162 * The eth_port_send API supports Scatter-Gather which enables to
1163 * send a packet spanned over multiple buffers. This means that
1164 * for each packet info structure given by the user and put into
1165 * the Tx descriptors ring, will be transmitted only if the 'LAST'
1166 * bit will be set in the packet info command status field. This
1167 * API also consider restriction regarding buffer alignments and
1169 * The user must return a Tx resource after ensuring the buffer
1170 * has been transmitted to enable the Tx ring indexes to update.
1173 * This device is on-board. No jumper diagram is necessary.
1175 * EXTERNAL INTERFACE
1177 * Prior to calling the initialization routine eth_port_init() the user
1178 * must set the following fields under ETH_PORT_INFO struct:
1179 * port_num User Ethernet port number.
1180 * port_phy_addr User PHY address of Ethernet port.
1181 * port_mac_addr[6] User defined port MAC address.
1182 * port_config User port configuration value.
1183 * port_config_extend User port config extend value.
1184 * port_sdma_config User port SDMA config value.
1185 * port_serial_control User port serial control value.
1186 * *port_virt_to_phys () User function to cast virtual addr to CPU bus addr.
1187 * *port_private User scratch pad for user specific data structures.
1189 * This driver introduce a set of default values:
1190 * PORT_CONFIG_VALUE Default port configuration value
1191 * PORT_CONFIG_EXTEND_VALUE Default port extend configuration value
1192 * PORT_SDMA_CONFIG_VALUE Default sdma control value
1193 * PORT_SERIAL_CONTROL_VALUE Default port serial control value
1195 * This driver data flow is done using the PKT_INFO struct which is
1196 * a unified struct for Rx and Tx operations:
1197 * byte_cnt Tx/Rx descriptor buffer byte count.
1198 * l4i_chk CPU provided TCP Checksum. For Tx operation only.
1199 * cmd_sts Tx/Rx descriptor command status.
1200 * buf_ptr Tx/Rx descriptor buffer pointer.
1201 * return_info Tx/Rx user resource return information.
1204 * EXTERNAL SUPPORT REQUIREMENTS
1206 * This driver requires the following external support:
1208 * D_CACHE_FLUSH_LINE (address, address offset)
1210 * This macro applies assembly code to flush and invalidate cache
1212 * address - address base.
1213 * address offset - address offset
1218 * This macro applies assembly code to flush the CPU pipeline.
1220 *******************************************************************************/
1224 /* SDMA command macros */
1225 #define ETH_ENABLE_TX_QUEUE(tx_queue, eth_port) \
1226 MV_REG_WRITE(MV64460_ETH_TRANSMIT_QUEUE_COMMAND_REG(eth_port), (1 << tx_queue))
1228 #define ETH_DISABLE_TX_QUEUE(tx_queue, eth_port) \
1229 MV_REG_WRITE(MV64460_ETH_TRANSMIT_QUEUE_COMMAND_REG(eth_port),\
1230 (1 << (8 + tx_queue)))
1232 #define ETH_ENABLE_RX_QUEUE(rx_queue, eth_port) \
1233 MV_REG_WRITE(MV64460_ETH_RECEIVE_QUEUE_COMMAND_REG(eth_port), (1 << rx_queue))
1235 #define ETH_DISABLE_RX_QUEUE(rx_queue, eth_port) \
1236 MV_REG_WRITE(MV64460_ETH_RECEIVE_QUEUE_COMMAND_REG(eth_port), (1 << (8 + rx_queue)))
1238 #define CURR_RFD_GET(p_curr_desc, queue) \
1239 ((p_curr_desc) = p_eth_port_ctrl->p_rx_curr_desc_q[queue])
1241 #define CURR_RFD_SET(p_curr_desc, queue) \
1242 (p_eth_port_ctrl->p_rx_curr_desc_q[queue] = (p_curr_desc))
1244 #define USED_RFD_GET(p_used_desc, queue) \
1245 ((p_used_desc) = p_eth_port_ctrl->p_rx_used_desc_q[queue])
1247 #define USED_RFD_SET(p_used_desc, queue)\
1248 (p_eth_port_ctrl->p_rx_used_desc_q[queue] = (p_used_desc))
1251 #define CURR_TFD_GET(p_curr_desc, queue) \
1252 ((p_curr_desc) = p_eth_port_ctrl->p_tx_curr_desc_q[queue])
1254 #define CURR_TFD_SET(p_curr_desc, queue) \
1255 (p_eth_port_ctrl->p_tx_curr_desc_q[queue] = (p_curr_desc))
1257 #define USED_TFD_GET(p_used_desc, queue) \
1258 ((p_used_desc) = p_eth_port_ctrl->p_tx_used_desc_q[queue])
1260 #define USED_TFD_SET(p_used_desc, queue) \
1261 (p_eth_port_ctrl->p_tx_used_desc_q[queue] = (p_used_desc))
1263 #define FIRST_TFD_GET(p_first_desc, queue) \
1264 ((p_first_desc) = p_eth_port_ctrl->p_tx_first_desc_q[queue])
1266 #define FIRST_TFD_SET(p_first_desc, queue) \
1267 (p_eth_port_ctrl->p_tx_first_desc_q[queue] = (p_first_desc))
1270 /* Macros that save access to desc in order to find next desc pointer */
1271 #define RX_NEXT_DESC_PTR(p_rx_desc, queue) (ETH_RX_DESC*)(((((unsigned int)p_rx_desc - (unsigned int)p_eth_port_ctrl->p_rx_desc_area_base[queue]) + RX_DESC_ALIGNED_SIZE) % p_eth_port_ctrl->rx_desc_area_size[queue]) + (unsigned int)p_eth_port_ctrl->p_rx_desc_area_base[queue])
1273 #define TX_NEXT_DESC_PTR(p_tx_desc, queue) (ETH_TX_DESC*)(((((unsigned int)p_tx_desc - (unsigned int)p_eth_port_ctrl->p_tx_desc_area_base[queue]) + TX_DESC_ALIGNED_SIZE) % p_eth_port_ctrl->tx_desc_area_size[queue]) + (unsigned int)p_eth_port_ctrl->p_tx_desc_area_base[queue])
1275 #define LINK_UP_TIMEOUT 100000
1276 #define PHY_BUSY_TIMEOUT 10000000
1281 static void ethernet_phy_set (ETH_PORT eth_port_num, int phy_addr);
1282 static int ethernet_phy_get (ETH_PORT eth_port_num);
1284 /* Ethernet Port routines */
1285 static void eth_set_access_control (ETH_PORT eth_port_num,
1286 ETH_WIN_PARAM * param);
1287 static bool eth_port_uc_addr (ETH_PORT eth_port_num, unsigned char uc_nibble,
1288 ETH_QUEUE queue, int option);
1290 static bool eth_port_smc_addr (ETH_PORT eth_port_num,
1291 unsigned char mc_byte,
1292 ETH_QUEUE queue, int option);
1293 static bool eth_port_omc_addr (ETH_PORT eth_port_num,
1295 ETH_QUEUE queue, int option);
1298 static void eth_b_copy (unsigned int src_addr, unsigned int dst_addr,
1301 void eth_dbg (ETH_PORT_INFO * p_eth_port_ctrl);
1304 typedef enum _memory_bank { BANK0, BANK1, BANK2, BANK3 } MEMORY_BANK;
1305 u32 mv_get_dram_bank_base_addr (MEMORY_BANK bank)
1308 u32 enable = MV_REG_READ (MV64460_BASE_ADDR_ENABLE);
1310 if (enable & (1 << bank))
1313 result = MV_REG_READ (MV64460_CS_0_BASE_ADDR);
1315 result = MV_REG_READ (MV64460_CS_1_BASE_ADDR);
1317 result = MV_REG_READ (MV64460_CS_2_BASE_ADDR);
1319 result = MV_REG_READ (MV64460_CS_3_BASE_ADDR);
1320 result &= 0x0000ffff;
1321 result = result << 16;
1325 u32 mv_get_dram_bank_size (MEMORY_BANK bank)
1328 u32 enable = MV_REG_READ (MV64460_BASE_ADDR_ENABLE);
1330 if (enable & (1 << bank))
1333 result = MV_REG_READ (MV64460_CS_0_SIZE);
1335 result = MV_REG_READ (MV64460_CS_1_SIZE);
1337 result = MV_REG_READ (MV64460_CS_2_SIZE);
1339 result = MV_REG_READ (MV64460_CS_3_SIZE);
1341 result &= 0x0000ffff;
1342 result = result << 16;
1346 u32 mv_get_internal_sram_base (void)
1350 result = MV_REG_READ (MV64460_INTEGRATED_SRAM_BASE_ADDR);
1351 result &= 0x0000ffff;
1352 result = result << 16;
1356 /*******************************************************************************
1357 * eth_port_init - Initialize the Ethernet port driver
1360 * This function prepares the ethernet port to start its activity:
1361 * 1) Completes the ethernet port driver struct initialization toward port
1363 * 2) Resets the device to a quiescent state in case of warm reboot.
1364 * 3) Enable SDMA access to all four DRAM banks as well as internal SRAM.
1365 * 4) Clean MAC tables. The reset status of those tables is unknown.
1366 * 5) Set PHY address.
1367 * Note: Call this routine prior to eth_port_start routine and after setting
1368 * user values in the user fields of Ethernet port control struct (i.e.
1372 * ETH_PORT_INFO *p_eth_port_ctrl Ethernet port control struct
1380 *******************************************************************************/
1381 static void eth_port_init (ETH_PORT_INFO * p_eth_port_ctrl)
1384 ETH_WIN_PARAM win_param;
1386 p_eth_port_ctrl->port_config = PORT_CONFIG_VALUE;
1387 p_eth_port_ctrl->port_config_extend = PORT_CONFIG_EXTEND_VALUE;
1388 p_eth_port_ctrl->port_sdma_config = PORT_SDMA_CONFIG_VALUE;
1389 p_eth_port_ctrl->port_serial_control = PORT_SERIAL_CONTROL_VALUE;
1391 p_eth_port_ctrl->port_rx_queue_command = 0;
1392 p_eth_port_ctrl->port_tx_queue_command = 0;
1394 /* Zero out SW structs */
1395 for (queue = 0; queue < MAX_RX_QUEUE_NUM; queue++) {
1396 CURR_RFD_SET ((ETH_RX_DESC *) 0x00000000, queue);
1397 USED_RFD_SET ((ETH_RX_DESC *) 0x00000000, queue);
1398 p_eth_port_ctrl->rx_resource_err[queue] = false;
1401 for (queue = 0; queue < MAX_TX_QUEUE_NUM; queue++) {
1402 CURR_TFD_SET ((ETH_TX_DESC *) 0x00000000, queue);
1403 USED_TFD_SET ((ETH_TX_DESC *) 0x00000000, queue);
1404 FIRST_TFD_SET ((ETH_TX_DESC *) 0x00000000, queue);
1405 p_eth_port_ctrl->tx_resource_err[queue] = false;
1408 eth_port_reset (p_eth_port_ctrl->port_num);
1410 /* Set access parameters for DRAM bank 0 */
1411 win_param.win = ETH_WIN0; /* Use Ethernet window 0 */
1412 win_param.target = ETH_TARGET_DRAM; /* Window target - DDR */
1413 win_param.attributes = EBAR_ATTR_DRAM_CS0; /* Enable DRAM bank */
1414 #ifndef CONFIG_NOT_COHERENT_CACHE
1415 win_param.attributes |= EBAR_ATTR_DRAM_CACHE_COHERENCY_WB;
1417 win_param.high_addr = 0;
1419 win_param.base_addr = mv_get_dram_bank_base_addr (BANK0);
1420 win_param.size = mv_get_dram_bank_size (BANK0); /* Get bank size */
1421 if (win_param.size == 0)
1422 win_param.enable = 0;
1424 win_param.enable = 1; /* Enable the access */
1425 win_param.access_ctrl = EWIN_ACCESS_FULL; /* Enable full access */
1427 /* Set the access control for address window (EPAPR) READ & WRITE */
1428 eth_set_access_control (p_eth_port_ctrl->port_num, &win_param);
1430 /* Set access parameters for DRAM bank 1 */
1431 win_param.win = ETH_WIN1; /* Use Ethernet window 1 */
1432 win_param.target = ETH_TARGET_DRAM; /* Window target - DDR */
1433 win_param.attributes = EBAR_ATTR_DRAM_CS1; /* Enable DRAM bank */
1434 #ifndef CONFIG_NOT_COHERENT_CACHE
1435 win_param.attributes |= EBAR_ATTR_DRAM_CACHE_COHERENCY_WB;
1437 win_param.high_addr = 0;
1439 win_param.base_addr = mv_get_dram_bank_base_addr (BANK1);
1440 win_param.size = mv_get_dram_bank_size (BANK1); /* Get bank size */
1441 if (win_param.size == 0)
1442 win_param.enable = 0;
1444 win_param.enable = 1; /* Enable the access */
1445 win_param.access_ctrl = EWIN_ACCESS_FULL; /* Enable full access */
1447 /* Set the access control for address window (EPAPR) READ & WRITE */
1448 eth_set_access_control (p_eth_port_ctrl->port_num, &win_param);
1450 /* Set access parameters for DRAM bank 2 */
1451 win_param.win = ETH_WIN2; /* Use Ethernet window 2 */
1452 win_param.target = ETH_TARGET_DRAM; /* Window target - DDR */
1453 win_param.attributes = EBAR_ATTR_DRAM_CS2; /* Enable DRAM bank */
1454 #ifndef CONFIG_NOT_COHERENT_CACHE
1455 win_param.attributes |= EBAR_ATTR_DRAM_CACHE_COHERENCY_WB;
1457 win_param.high_addr = 0;
1459 win_param.base_addr = mv_get_dram_bank_base_addr (BANK2);
1460 win_param.size = mv_get_dram_bank_size (BANK2); /* Get bank size */
1461 if (win_param.size == 0)
1462 win_param.enable = 0;
1464 win_param.enable = 1; /* Enable the access */
1465 win_param.access_ctrl = EWIN_ACCESS_FULL; /* Enable full access */
1467 /* Set the access control for address window (EPAPR) READ & WRITE */
1468 eth_set_access_control (p_eth_port_ctrl->port_num, &win_param);
1470 /* Set access parameters for DRAM bank 3 */
1471 win_param.win = ETH_WIN3; /* Use Ethernet window 3 */
1472 win_param.target = ETH_TARGET_DRAM; /* Window target - DDR */
1473 win_param.attributes = EBAR_ATTR_DRAM_CS3; /* Enable DRAM bank */
1474 #ifndef CONFIG_NOT_COHERENT_CACHE
1475 win_param.attributes |= EBAR_ATTR_DRAM_CACHE_COHERENCY_WB;
1477 win_param.high_addr = 0;
1479 win_param.base_addr = mv_get_dram_bank_base_addr (BANK3);
1480 win_param.size = mv_get_dram_bank_size (BANK3); /* Get bank size */
1481 if (win_param.size == 0)
1482 win_param.enable = 0;
1484 win_param.enable = 1; /* Enable the access */
1485 win_param.access_ctrl = EWIN_ACCESS_FULL; /* Enable full access */
1487 /* Set the access control for address window (EPAPR) READ & WRITE */
1488 eth_set_access_control (p_eth_port_ctrl->port_num, &win_param);
1490 /* Set access parameters for Internal SRAM */
1491 win_param.win = ETH_WIN4; /* Use Ethernet window 0 */
1492 win_param.target = EBAR_TARGET_CBS; /* Target - Internal SRAM */
1493 win_param.attributes = EBAR_ATTR_CBS_SRAM | EBAR_ATTR_CBS_SRAM_BLOCK0;
1494 win_param.high_addr = 0;
1495 win_param.base_addr = mv_get_internal_sram_base (); /* Get base addr */
1496 win_param.size = MV64460_INTERNAL_SRAM_SIZE; /* Get bank size */
1497 win_param.enable = 1; /* Enable the access */
1498 win_param.access_ctrl = EWIN_ACCESS_FULL; /* Enable full access */
1500 /* Set the access control for address window (EPAPR) READ & WRITE */
1501 eth_set_access_control (p_eth_port_ctrl->port_num, &win_param);
1503 eth_port_init_mac_tables (p_eth_port_ctrl->port_num);
1505 ethernet_phy_set (p_eth_port_ctrl->port_num,
1506 p_eth_port_ctrl->port_phy_addr);
1512 /*******************************************************************************
1513 * eth_port_start - Start the Ethernet port activity.
1516 * This routine prepares the Ethernet port for Rx and Tx activity:
1517 * 1. Initialize Tx and Rx Current Descriptor Pointer for each queue that
1518 * has been initialized a descriptor's ring (using ether_init_tx_desc_ring
1519 * for Tx and ether_init_rx_desc_ring for Rx)
1520 * 2. Initialize and enable the Ethernet configuration port by writing to
1521 * the port's configuration and command registers.
1522 * 3. Initialize and enable the SDMA by writing to the SDMA's
1523 * configuration and command registers.
1524 * After completing these steps, the ethernet port SDMA can starts to
1525 * perform Rx and Tx activities.
1527 * Note: Each Rx and Tx queue descriptor's list must be initialized prior
1528 * to calling this function (use ether_init_tx_desc_ring for Tx queues and
1529 * ether_init_rx_desc_ring for Rx queues).
1532 * ETH_PORT_INFO *p_eth_port_ctrl Ethernet port control struct
1535 * Ethernet port is ready to receive and transmit.
1538 * false if the port PHY is not up.
1541 *******************************************************************************/
1542 static bool eth_port_start (ETH_PORT_INFO * p_eth_port_ctrl)
1545 volatile ETH_TX_DESC *p_tx_curr_desc;
1546 volatile ETH_RX_DESC *p_rx_curr_desc;
1547 unsigned int phy_reg_data;
1548 ETH_PORT eth_port_num = p_eth_port_ctrl->port_num;
1551 /* Assignment of Tx CTRP of given queue */
1552 for (queue = 0; queue < MAX_TX_QUEUE_NUM; queue++) {
1553 CURR_TFD_GET (p_tx_curr_desc, queue);
1554 MV_REG_WRITE ((MV64460_ETH_TX_CURRENT_QUEUE_DESC_PTR_0
1557 ((unsigned int) p_tx_curr_desc));
1561 /* Assignment of Rx CRDP of given queue */
1562 for (queue = 0; queue < MAX_RX_QUEUE_NUM; queue++) {
1563 CURR_RFD_GET (p_rx_curr_desc, queue);
1564 MV_REG_WRITE ((MV64460_ETH_RX_CURRENT_QUEUE_DESC_PTR_0
1567 ((unsigned int) p_rx_curr_desc));
1569 if (p_rx_curr_desc != NULL)
1570 /* Add the assigned Ethernet address to the port's address table */
1571 eth_port_uc_addr_set (p_eth_port_ctrl->port_num,
1572 p_eth_port_ctrl->port_mac_addr,
1576 /* Assign port configuration and command. */
1577 MV_REG_WRITE (MV64460_ETH_PORT_CONFIG_REG (eth_port_num),
1578 p_eth_port_ctrl->port_config);
1580 MV_REG_WRITE (MV64460_ETH_PORT_CONFIG_EXTEND_REG (eth_port_num),
1581 p_eth_port_ctrl->port_config_extend);
1583 MV_REG_WRITE (MV64460_ETH_PORT_SERIAL_CONTROL_REG (eth_port_num),
1584 p_eth_port_ctrl->port_serial_control);
1586 MV_SET_REG_BITS (MV64460_ETH_PORT_SERIAL_CONTROL_REG (eth_port_num),
1587 ETH_SERIAL_PORT_ENABLE);
1589 /* Assign port SDMA configuration */
1590 MV_REG_WRITE (MV64460_ETH_SDMA_CONFIG_REG (eth_port_num),
1591 p_eth_port_ctrl->port_sdma_config);
1593 MV_REG_WRITE (MV64460_ETH_TX_QUEUE_0_TOKEN_BUCKET_COUNT
1594 (eth_port_num), 0x3fffffff);
1595 MV_REG_WRITE (MV64460_ETH_TX_QUEUE_0_TOKEN_BUCKET_CONFIG
1596 (eth_port_num), 0x03fffcff);
1597 /* Turn off the port/queue bandwidth limitation */
1598 MV_REG_WRITE (MV64460_ETH_MAXIMUM_TRANSMIT_UNIT (eth_port_num), 0x0);
1600 /* Enable port Rx. */
1601 MV_REG_WRITE (MV64460_ETH_RECEIVE_QUEUE_COMMAND_REG (eth_port_num),
1602 p_eth_port_ctrl->port_rx_queue_command);
1604 /* Check if link is up */
1605 eth_port_read_smi_reg (eth_port_num, 1, &phy_reg_data);
1607 if (!(phy_reg_data & 0x20))
1613 /*******************************************************************************
1614 * eth_port_uc_addr_set - This function Set the port Unicast address.
1617 * This function Set the port Ethernet MAC address.
1620 * ETH_PORT eth_port_num Port number.
1621 * char * p_addr Address to be set
1622 * ETH_QUEUE queue Rx queue number for this MAC address.
1625 * Set MAC address low and high registers. also calls eth_port_uc_addr()
1626 * To set the unicast table with the proper information.
1631 *******************************************************************************/
1632 static void eth_port_uc_addr_set (ETH_PORT eth_port_num,
1633 unsigned char *p_addr, ETH_QUEUE queue)
1638 mac_l = (p_addr[4] << 8) | (p_addr[5]);
1639 mac_h = (p_addr[0] << 24) | (p_addr[1] << 16) |
1640 (p_addr[2] << 8) | (p_addr[3] << 0);
1642 MV_REG_WRITE (MV64460_ETH_MAC_ADDR_LOW (eth_port_num), mac_l);
1643 MV_REG_WRITE (MV64460_ETH_MAC_ADDR_HIGH (eth_port_num), mac_h);
1645 /* Accept frames of this address */
1646 eth_port_uc_addr (eth_port_num, p_addr[5], queue, ACCEPT_MAC_ADDR);
1651 /*******************************************************************************
1652 * eth_port_uc_addr - This function Set the port unicast address table
1655 * This function locates the proper entry in the Unicast table for the
1656 * specified MAC nibble and sets its properties according to function
1660 * ETH_PORT eth_port_num Port number.
1661 * unsigned char uc_nibble Unicast MAC Address last nibble.
1662 * ETH_QUEUE queue Rx queue number for this MAC address.
1663 * int option 0 = Add, 1 = remove address.
1666 * This function add/removes MAC addresses from the port unicast address
1670 * true is output succeeded.
1671 * false if option parameter is invalid.
1673 *******************************************************************************/
1674 static bool eth_port_uc_addr (ETH_PORT eth_port_num,
1675 unsigned char uc_nibble,
1676 ETH_QUEUE queue, int option)
1678 unsigned int unicast_reg;
1679 unsigned int tbl_offset;
1680 unsigned int reg_offset;
1682 /* Locate the Unicast table entry */
1683 uc_nibble = (0xf & uc_nibble);
1684 tbl_offset = (uc_nibble / 4) * 4; /* Register offset from unicast table base */
1685 reg_offset = uc_nibble % 4; /* Entry offset within the above register */
1688 case REJECT_MAC_ADDR:
1689 /* Clear accepts frame bit at specified unicast DA table entry */
1691 MV_REG_READ ((MV64460_ETH_DA_FILTER_UNICAST_TABLE_BASE
1695 unicast_reg &= (0x0E << (8 * reg_offset));
1697 MV_REG_WRITE ((MV64460_ETH_DA_FILTER_UNICAST_TABLE_BASE
1699 + tbl_offset), unicast_reg);
1702 case ACCEPT_MAC_ADDR:
1703 /* Set accepts frame bit at unicast DA filter table entry */
1705 MV_REG_READ ((MV64460_ETH_DA_FILTER_UNICAST_TABLE_BASE
1709 unicast_reg |= ((0x01 | queue) << (8 * reg_offset));
1711 MV_REG_WRITE ((MV64460_ETH_DA_FILTER_UNICAST_TABLE_BASE
1713 + tbl_offset), unicast_reg);
1724 /*******************************************************************************
1725 * eth_port_mc_addr - Multicast address settings.
1728 * This API controls the MV device MAC multicast support.
1729 * The MV device supports multicast using two tables:
1730 * 1) Special Multicast Table for MAC addresses of the form
1731 * 0x01-00-5E-00-00-XX (where XX is between 0x00 and 0x_fF).
1732 * The MAC DA[7:0] bits are used as a pointer to the Special Multicast
1733 * Table entries in the DA-Filter table.
1734 * In this case, the function calls eth_port_smc_addr() routine to set the
1735 * Special Multicast Table.
1736 * 2) Other Multicast Table for multicast of another type. A CRC-8bit
1737 * is used as an index to the Other Multicast Table entries in the
1739 * In this case, the function calculates the CRC-8bit value and calls
1740 * eth_port_omc_addr() routine to set the Other Multicast Table.
1742 * ETH_PORT eth_port_num Port number.
1743 * unsigned char *p_addr Unicast MAC Address.
1744 * ETH_QUEUE queue Rx queue number for this MAC address.
1745 * int option 0 = Add, 1 = remove address.
1751 * true is output succeeded.
1752 * false if add_address_table_entry( ) failed.
1754 *******************************************************************************/
1755 static void eth_port_mc_addr (ETH_PORT eth_port_num,
1756 unsigned char *p_addr,
1757 ETH_QUEUE queue, int option)
1761 unsigned char crc_result = 0;
1767 if ((p_addr[0] == 0x01) &&
1768 (p_addr[1] == 0x00) &&
1769 (p_addr[2] == 0x5E) && (p_addr[3] == 0x00) && (p_addr[4] == 0x00))
1771 eth_port_smc_addr (eth_port_num, p_addr[5], queue, option);
1773 /* Calculate CRC-8 out of the given address */
1774 mac_h = (p_addr[0] << 8) | (p_addr[1]);
1775 mac_l = (p_addr[2] << 24) | (p_addr[3] << 16) |
1776 (p_addr[4] << 8) | (p_addr[5] << 0);
1778 for (i = 0; i < 32; i++)
1779 mac_array[i] = (mac_l >> i) & 0x1;
1780 for (i = 32; i < 48; i++)
1781 mac_array[i] = (mac_h >> (i - 32)) & 0x1;
1784 crc[0] = mac_array[45] ^ mac_array[43] ^ mac_array[40] ^
1785 mac_array[39] ^ mac_array[35] ^ mac_array[34] ^
1786 mac_array[31] ^ mac_array[30] ^ mac_array[28] ^
1787 mac_array[23] ^ mac_array[21] ^ mac_array[19] ^
1788 mac_array[18] ^ mac_array[16] ^ mac_array[14] ^
1789 mac_array[12] ^ mac_array[8] ^ mac_array[7] ^
1790 mac_array[6] ^ mac_array[0];
1792 crc[1] = mac_array[46] ^ mac_array[45] ^ mac_array[44] ^
1793 mac_array[43] ^ mac_array[41] ^ mac_array[39] ^
1794 mac_array[36] ^ mac_array[34] ^ mac_array[32] ^
1795 mac_array[30] ^ mac_array[29] ^ mac_array[28] ^
1796 mac_array[24] ^ mac_array[23] ^ mac_array[22] ^
1797 mac_array[21] ^ mac_array[20] ^ mac_array[18] ^
1798 mac_array[17] ^ mac_array[16] ^ mac_array[15] ^
1799 mac_array[14] ^ mac_array[13] ^ mac_array[12] ^
1800 mac_array[9] ^ mac_array[6] ^ mac_array[1] ^
1803 crc[2] = mac_array[47] ^ mac_array[46] ^ mac_array[44] ^
1804 mac_array[43] ^ mac_array[42] ^ mac_array[39] ^
1805 mac_array[37] ^ mac_array[34] ^ mac_array[33] ^
1806 mac_array[29] ^ mac_array[28] ^ mac_array[25] ^
1807 mac_array[24] ^ mac_array[22] ^ mac_array[17] ^
1808 mac_array[15] ^ mac_array[13] ^ mac_array[12] ^
1809 mac_array[10] ^ mac_array[8] ^ mac_array[6] ^
1810 mac_array[2] ^ mac_array[1] ^ mac_array[0];
1812 crc[3] = mac_array[47] ^ mac_array[45] ^ mac_array[44] ^
1813 mac_array[43] ^ mac_array[40] ^ mac_array[38] ^
1814 mac_array[35] ^ mac_array[34] ^ mac_array[30] ^
1815 mac_array[29] ^ mac_array[26] ^ mac_array[25] ^
1816 mac_array[23] ^ mac_array[18] ^ mac_array[16] ^
1817 mac_array[14] ^ mac_array[13] ^ mac_array[11] ^
1818 mac_array[9] ^ mac_array[7] ^ mac_array[3] ^
1819 mac_array[2] ^ mac_array[1];
1821 crc[4] = mac_array[46] ^ mac_array[45] ^ mac_array[44] ^
1822 mac_array[41] ^ mac_array[39] ^ mac_array[36] ^
1823 mac_array[35] ^ mac_array[31] ^ mac_array[30] ^
1824 mac_array[27] ^ mac_array[26] ^ mac_array[24] ^
1825 mac_array[19] ^ mac_array[17] ^ mac_array[15] ^
1826 mac_array[14] ^ mac_array[12] ^ mac_array[10] ^
1827 mac_array[8] ^ mac_array[4] ^ mac_array[3] ^
1830 crc[5] = mac_array[47] ^ mac_array[46] ^ mac_array[45] ^
1831 mac_array[42] ^ mac_array[40] ^ mac_array[37] ^
1832 mac_array[36] ^ mac_array[32] ^ mac_array[31] ^
1833 mac_array[28] ^ mac_array[27] ^ mac_array[25] ^
1834 mac_array[20] ^ mac_array[18] ^ mac_array[16] ^
1835 mac_array[15] ^ mac_array[13] ^ mac_array[11] ^
1836 mac_array[9] ^ mac_array[5] ^ mac_array[4] ^
1839 crc[6] = mac_array[47] ^ mac_array[46] ^ mac_array[43] ^
1840 mac_array[41] ^ mac_array[38] ^ mac_array[37] ^
1841 mac_array[33] ^ mac_array[32] ^ mac_array[29] ^
1842 mac_array[28] ^ mac_array[26] ^ mac_array[21] ^
1843 mac_array[19] ^ mac_array[17] ^ mac_array[16] ^
1844 mac_array[14] ^ mac_array[12] ^ mac_array[10] ^
1845 mac_array[6] ^ mac_array[5] ^ mac_array[4];
1847 crc[7] = mac_array[47] ^ mac_array[44] ^ mac_array[42] ^
1848 mac_array[39] ^ mac_array[38] ^ mac_array[34] ^
1849 mac_array[33] ^ mac_array[30] ^ mac_array[29] ^
1850 mac_array[27] ^ mac_array[22] ^ mac_array[20] ^
1851 mac_array[18] ^ mac_array[17] ^ mac_array[15] ^
1852 mac_array[13] ^ mac_array[11] ^ mac_array[7] ^
1853 mac_array[6] ^ mac_array[5];
1855 for (i = 0; i < 8; i++)
1856 crc_result = crc_result | (crc[i] << i);
1858 eth_port_omc_addr (eth_port_num, crc_result, queue, option);
1863 /*******************************************************************************
1864 * eth_port_smc_addr - Special Multicast address settings.
1867 * This routine controls the MV device special MAC multicast support.
1868 * The Special Multicast Table for MAC addresses supports MAC of the form
1869 * 0x01-00-5E-00-00-XX (where XX is between 0x00 and 0x_fF).
1870 * The MAC DA[7:0] bits are used as a pointer to the Special Multicast
1871 * Table entries in the DA-Filter table.
1872 * This function set the Special Multicast Table appropriate entry
1873 * according to the argument given.
1876 * ETH_PORT eth_port_num Port number.
1877 * unsigned char mc_byte Multicast addr last byte (MAC DA[7:0] bits).
1878 * ETH_QUEUE queue Rx queue number for this MAC address.
1879 * int option 0 = Add, 1 = remove address.
1885 * true is output succeeded.
1886 * false if option parameter is invalid.
1888 *******************************************************************************/
1889 static bool eth_port_smc_addr (ETH_PORT eth_port_num,
1890 unsigned char mc_byte,
1891 ETH_QUEUE queue, int option)
1893 unsigned int smc_table_reg;
1894 unsigned int tbl_offset;
1895 unsigned int reg_offset;
1897 /* Locate the SMC table entry */
1898 tbl_offset = (mc_byte / 4) * 4; /* Register offset from SMC table base */
1899 reg_offset = mc_byte % 4; /* Entry offset within the above register */
1903 case REJECT_MAC_ADDR:
1904 /* Clear accepts frame bit at specified Special DA table entry */
1906 MV_REG_READ ((MV64460_ETH_DA_FILTER_SPECIAL_MULTICAST_TABLE_BASE (eth_port_num) + tbl_offset));
1907 smc_table_reg &= (0x0E << (8 * reg_offset));
1909 MV_REG_WRITE ((MV64460_ETH_DA_FILTER_SPECIAL_MULTICAST_TABLE_BASE (eth_port_num) + tbl_offset), smc_table_reg);
1912 case ACCEPT_MAC_ADDR:
1913 /* Set accepts frame bit at specified Special DA table entry */
1915 MV_REG_READ ((MV64460_ETH_DA_FILTER_SPECIAL_MULTICAST_TABLE_BASE (eth_port_num) + tbl_offset));
1916 smc_table_reg |= ((0x01 | queue) << (8 * reg_offset));
1918 MV_REG_WRITE ((MV64460_ETH_DA_FILTER_SPECIAL_MULTICAST_TABLE_BASE (eth_port_num) + tbl_offset), smc_table_reg);
1927 /*******************************************************************************
1928 * eth_port_omc_addr - Multicast address settings.
1931 * This routine controls the MV device Other MAC multicast support.
1932 * The Other Multicast Table is used for multicast of another type.
1933 * A CRC-8bit is used as an index to the Other Multicast Table entries
1934 * in the DA-Filter table.
1935 * The function gets the CRC-8bit value from the calling routine and
1936 * set the Other Multicast Table appropriate entry according to the
1937 * CRC-8 argument given.
1940 * ETH_PORT eth_port_num Port number.
1941 * unsigned char crc8 A CRC-8bit (Polynomial: x^8+x^2+x^1+1).
1942 * ETH_QUEUE queue Rx queue number for this MAC address.
1943 * int option 0 = Add, 1 = remove address.
1949 * true is output succeeded.
1950 * false if option parameter is invalid.
1952 *******************************************************************************/
1953 static bool eth_port_omc_addr (ETH_PORT eth_port_num,
1955 ETH_QUEUE queue, int option)
1957 unsigned int omc_table_reg;
1958 unsigned int tbl_offset;
1959 unsigned int reg_offset;
1961 /* Locate the OMC table entry */
1962 tbl_offset = (crc8 / 4) * 4; /* Register offset from OMC table base */
1963 reg_offset = crc8 % 4; /* Entry offset within the above register */
1967 case REJECT_MAC_ADDR:
1968 /* Clear accepts frame bit at specified Other DA table entry */
1970 MV_REG_READ ((MV64460_ETH_DA_FILTER_OTHER_MULTICAST_TABLE_BASE (eth_port_num) + tbl_offset));
1971 omc_table_reg &= (0x0E << (8 * reg_offset));
1973 MV_REG_WRITE ((MV64460_ETH_DA_FILTER_OTHER_MULTICAST_TABLE_BASE (eth_port_num) + tbl_offset), omc_table_reg);
1976 case ACCEPT_MAC_ADDR:
1977 /* Set accepts frame bit at specified Other DA table entry */
1979 MV_REG_READ ((MV64460_ETH_DA_FILTER_OTHER_MULTICAST_TABLE_BASE (eth_port_num) + tbl_offset));
1980 omc_table_reg |= ((0x01 | queue) << (8 * reg_offset));
1982 MV_REG_WRITE ((MV64460_ETH_DA_FILTER_OTHER_MULTICAST_TABLE_BASE (eth_port_num) + tbl_offset), omc_table_reg);
1992 /*******************************************************************************
1993 * eth_port_init_mac_tables - Clear all entrance in the UC, SMC and OMC tables
1996 * Go through all the DA filter tables (Unicast, Special Multicast & Other
1997 * Multicast) and set each entry to 0.
2000 * ETH_PORT eth_port_num Ethernet Port number. See ETH_PORT enum.
2003 * Multicast and Unicast packets are rejected.
2008 *******************************************************************************/
2009 static void eth_port_init_mac_tables (ETH_PORT eth_port_num)
2013 /* Clear DA filter unicast table (Ex_dFUT) */
2014 for (table_index = 0; table_index <= 0xC; table_index += 4)
2015 MV_REG_WRITE ((MV64460_ETH_DA_FILTER_UNICAST_TABLE_BASE
2016 (eth_port_num) + table_index), 0);
2018 for (table_index = 0; table_index <= 0xFC; table_index += 4) {
2019 /* Clear DA filter special multicast table (Ex_dFSMT) */
2020 MV_REG_WRITE ((MV64460_ETH_DA_FILTER_SPECIAL_MULTICAST_TABLE_BASE (eth_port_num) + table_index), 0);
2021 /* Clear DA filter other multicast table (Ex_dFOMT) */
2022 MV_REG_WRITE ((MV64460_ETH_DA_FILTER_OTHER_MULTICAST_TABLE_BASE (eth_port_num) + table_index), 0);
2026 /*******************************************************************************
2027 * eth_clear_mib_counters - Clear all MIB counters
2030 * This function clears all MIB counters of a specific ethernet port.
2031 * A read from the MIB counter will reset the counter.
2034 * ETH_PORT eth_port_num Ethernet Port number. See ETH_PORT enum.
2037 * After reading all MIB counters, the counters resets.
2040 * MIB counter value.
2042 *******************************************************************************/
2043 static void eth_clear_mib_counters (ETH_PORT eth_port_num)
2047 /* Perform dummy reads from MIB counters */
2048 for (i = ETH_MIB_GOOD_OCTETS_RECEIVED_LOW; i < ETH_MIB_LATE_COLLISION;
2050 MV_REG_READ((MV64460_ETH_MIB_COUNTERS_BASE(eth_port_num) + i));
2055 /*******************************************************************************
2056 * eth_read_mib_counter - Read a MIB counter
2059 * This function reads a MIB counter of a specific ethernet port.
2060 * NOTE - If read from ETH_MIB_GOOD_OCTETS_RECEIVED_LOW, then the
2061 * following read must be from ETH_MIB_GOOD_OCTETS_RECEIVED_HIGH
2062 * register. The same applies for ETH_MIB_GOOD_OCTETS_SENT_LOW and
2063 * ETH_MIB_GOOD_OCTETS_SENT_HIGH
2066 * ETH_PORT eth_port_num Ethernet Port number. See ETH_PORT enum.
2067 * unsigned int mib_offset MIB counter offset (use ETH_MIB_... macros).
2070 * After reading the MIB counter, the counter resets.
2073 * MIB counter value.
2075 *******************************************************************************/
2076 unsigned int eth_read_mib_counter (ETH_PORT eth_port_num,
2077 unsigned int mib_offset)
2079 return (MV_REG_READ (MV64460_ETH_MIB_COUNTERS_BASE (eth_port_num)
2083 /*******************************************************************************
2084 * ethernet_phy_set - Set the ethernet port PHY address.
2087 * This routine set the ethernet port PHY address according to given
2091 * ETH_PORT eth_port_num Ethernet Port number. See ETH_PORT enum.
2094 * Set PHY Address Register with given PHY address parameter.
2099 *******************************************************************************/
2100 static void ethernet_phy_set (ETH_PORT eth_port_num, int phy_addr)
2102 unsigned int reg_data;
2104 reg_data = MV_REG_READ (MV64460_ETH_PHY_ADDR_REG);
2106 reg_data &= ~(0x1F << (5 * eth_port_num));
2107 reg_data |= (phy_addr << (5 * eth_port_num));
2109 MV_REG_WRITE (MV64460_ETH_PHY_ADDR_REG, reg_data);
2114 /*******************************************************************************
2115 * ethernet_phy_get - Get the ethernet port PHY address.
2118 * This routine returns the given ethernet port PHY address.
2121 * ETH_PORT eth_port_num Ethernet Port number. See ETH_PORT enum.
2129 *******************************************************************************/
2130 static int ethernet_phy_get (ETH_PORT eth_port_num)
2132 unsigned int reg_data;
2134 reg_data = MV_REG_READ (MV64460_ETH_PHY_ADDR_REG);
2136 return ((reg_data >> (5 * eth_port_num)) & 0x1f);
2139 /*******************************************************************************
2140 * ethernet_phy_reset - Reset Ethernet port PHY.
2143 * This routine utilize the SMI interface to reset the ethernet port PHY.
2144 * The routine waits until the link is up again or link up is timeout.
2147 * ETH_PORT eth_port_num Ethernet Port number. See ETH_PORT enum.
2150 * The ethernet port PHY renew its link.
2155 *******************************************************************************/
2156 static bool ethernet_phy_reset (ETH_PORT eth_port_num)
2158 unsigned int time_out = 50;
2159 unsigned int phy_reg_data;
2162 eth_port_read_smi_reg (eth_port_num, 0, &phy_reg_data);
2163 phy_reg_data |= 0x8000; /* Set bit 15 to reset the PHY */
2164 eth_port_write_smi_reg (eth_port_num, 0, phy_reg_data);
2166 /* Poll on the PHY LINK */
2168 eth_port_read_smi_reg (eth_port_num, 1, &phy_reg_data);
2170 if (time_out-- == 0)
2173 while (!(phy_reg_data & 0x20));
2178 /*******************************************************************************
2179 * eth_port_reset - Reset Ethernet port
2182 * This routine resets the chip by aborting any SDMA engine activity and
2183 * clearing the MIB counters. The Receiver and the Transmit unit are in
2184 * idle state after this command is performed and the port is disabled.
2187 * ETH_PORT eth_port_num Ethernet Port number. See ETH_PORT enum.
2190 * Channel activity is halted.
2195 *******************************************************************************/
2196 static void eth_port_reset (ETH_PORT eth_port_num)
2198 unsigned int reg_data;
2200 /* Stop Tx port activity. Check port Tx activity. */
2202 MV_REG_READ (MV64460_ETH_TRANSMIT_QUEUE_COMMAND_REG
2205 if (reg_data & 0xFF) {
2206 /* Issue stop command for active channels only */
2207 MV_REG_WRITE (MV64460_ETH_TRANSMIT_QUEUE_COMMAND_REG
2208 (eth_port_num), (reg_data << 8));
2210 /* Wait for all Tx activity to terminate. */
2212 /* Check port cause register that all Tx queues are stopped */
2215 (MV64460_ETH_TRANSMIT_QUEUE_COMMAND_REG
2218 while (reg_data & 0xFF);
2221 /* Stop Rx port activity. Check port Rx activity. */
2223 MV_REG_READ (MV64460_ETH_RECEIVE_QUEUE_COMMAND_REG
2226 if (reg_data & 0xFF) {
2227 /* Issue stop command for active channels only */
2228 MV_REG_WRITE (MV64460_ETH_RECEIVE_QUEUE_COMMAND_REG
2229 (eth_port_num), (reg_data << 8));
2231 /* Wait for all Rx activity to terminate. */
2233 /* Check port cause register that all Rx queues are stopped */
2236 (MV64460_ETH_RECEIVE_QUEUE_COMMAND_REG
2239 while (reg_data & 0xFF);
2243 /* Clear all MIB counters */
2244 eth_clear_mib_counters (eth_port_num);
2246 /* Reset the Enable bit in the Configuration Register */
2248 MV_REG_READ (MV64460_ETH_PORT_SERIAL_CONTROL_REG
2250 reg_data &= ~ETH_SERIAL_PORT_ENABLE;
2251 MV_REG_WRITE (MV64460_ETH_PORT_SERIAL_CONTROL_REG (eth_port_num),
2257 #if 0 /* Not needed here */
2258 /*******************************************************************************
2259 * ethernet_set_config_reg - Set specified bits in configuration register.
2262 * This function sets specified bits in the given ethernet
2263 * configuration register.
2266 * ETH_PORT eth_port_num Ethernet Port number. See ETH_PORT enum.
2267 * unsigned int value 32 bit value.
2270 * The set bits in the value parameter are set in the configuration
2276 *******************************************************************************/
2277 static void ethernet_set_config_reg (ETH_PORT eth_port_num,
2280 unsigned int eth_config_reg;
2283 MV_REG_READ (MV64460_ETH_PORT_CONFIG_REG (eth_port_num));
2284 eth_config_reg |= value;
2285 MV_REG_WRITE (MV64460_ETH_PORT_CONFIG_REG (eth_port_num),
2293 /*******************************************************************************
2294 * ethernet_reset_config_reg - Reset specified bits in configuration register.
2297 * This function resets specified bits in the given Ethernet
2298 * configuration register.
2301 * ETH_PORT eth_port_num Ethernet Port number. See ETH_PORT enum.
2302 * unsigned int value 32 bit value.
2305 * The set bits in the value parameter are reset in the configuration
2311 *******************************************************************************/
2312 static void ethernet_reset_config_reg (ETH_PORT eth_port_num,
2315 unsigned int eth_config_reg;
2317 eth_config_reg = MV_REG_READ (MV64460_ETH_PORT_CONFIG_EXTEND_REG
2319 eth_config_reg &= ~value;
2320 MV_REG_WRITE (MV64460_ETH_PORT_CONFIG_EXTEND_REG (eth_port_num),
2327 #if 0 /* Not needed here */
2328 /*******************************************************************************
2329 * ethernet_get_config_reg - Get the port configuration register
2332 * This function returns the configuration register value of the given
2336 * ETH_PORT eth_port_num Ethernet Port number. See ETH_PORT enum.
2342 * Port configuration register value.
2344 *******************************************************************************/
2345 static unsigned int ethernet_get_config_reg (ETH_PORT eth_port_num)
2347 unsigned int eth_config_reg;
2349 eth_config_reg = MV_REG_READ (MV64460_ETH_PORT_CONFIG_EXTEND_REG
2351 return eth_config_reg;
2356 /*******************************************************************************
2357 * eth_port_read_smi_reg - Read PHY registers
2360 * This routine utilize the SMI interface to interact with the PHY in
2361 * order to perform PHY register read.
2364 * ETH_PORT eth_port_num Ethernet Port number. See ETH_PORT enum.
2365 * unsigned int phy_reg PHY register address offset.
2366 * unsigned int *value Register value buffer.
2369 * Write the value of a specified PHY register into given buffer.
2372 * false if the PHY is busy or read data is not in valid state.
2375 *******************************************************************************/
2376 static bool eth_port_read_smi_reg (ETH_PORT eth_port_num,
2377 unsigned int phy_reg, unsigned int *value)
2379 unsigned int reg_value;
2380 unsigned int time_out = PHY_BUSY_TIMEOUT;
2383 phy_addr = ethernet_phy_get (eth_port_num);
2384 /* printf(" Phy-Port %d has addess %d \n",eth_port_num, phy_addr );*/
2386 /* first check that it is not busy */
2388 reg_value = MV_REG_READ (MV64460_ETH_SMI_REG);
2389 if (time_out-- == 0) {
2393 while (reg_value & ETH_SMI_BUSY);
2397 MV_REG_WRITE (MV64460_ETH_SMI_REG,
2398 (phy_addr << 16) | (phy_reg << 21) |
2399 ETH_SMI_OPCODE_READ);
2401 time_out = PHY_BUSY_TIMEOUT; /* initialize the time out var again */
2404 reg_value = MV_REG_READ (MV64460_ETH_SMI_REG);
2405 if (time_out-- == 0) {
2409 while ((reg_value & ETH_SMI_READ_VALID) != ETH_SMI_READ_VALID); /* Bit set equ operation done */
2411 /* Wait for the data to update in the SMI register */
2412 #define PHY_UPDATE_TIMEOUT 10000
2413 for (time_out = 0; time_out < PHY_UPDATE_TIMEOUT; time_out++);
2415 reg_value = MV_REG_READ (MV64460_ETH_SMI_REG);
2417 *value = reg_value & 0xffff;
2422 /*******************************************************************************
2423 * eth_port_write_smi_reg - Write to PHY registers
2426 * This routine utilize the SMI interface to interact with the PHY in
2427 * order to perform writes to PHY registers.
2430 * ETH_PORT eth_port_num Ethernet Port number. See ETH_PORT enum.
2431 * unsigned int phy_reg PHY register address offset.
2432 * unsigned int value Register value.
2435 * Write the given value to the specified PHY register.
2438 * false if the PHY is busy.
2441 *******************************************************************************/
2442 static bool eth_port_write_smi_reg (ETH_PORT eth_port_num,
2443 unsigned int phy_reg, unsigned int value)
2445 unsigned int reg_value;
2446 unsigned int time_out = PHY_BUSY_TIMEOUT;
2449 phy_addr = ethernet_phy_get (eth_port_num);
2451 /* first check that it is not busy */
2453 reg_value = MV_REG_READ (MV64460_ETH_SMI_REG);
2454 if (time_out-- == 0) {
2458 while (reg_value & ETH_SMI_BUSY);
2461 MV_REG_WRITE (MV64460_ETH_SMI_REG,
2462 (phy_addr << 16) | (phy_reg << 21) |
2463 ETH_SMI_OPCODE_WRITE | (value & 0xffff));
2467 /*******************************************************************************
2468 * eth_set_access_control - Config address decode parameters for Ethernet unit
2471 * This function configures the address decode parameters for the Gigabit
2472 * Ethernet Controller according the given parameters struct.
2475 * ETH_PORT eth_port_num Ethernet Port number. See ETH_PORT enum.
2476 * ETH_WIN_PARAM *param Address decode parameter struct.
2479 * An access window is opened using the given access parameters.
2484 *******************************************************************************/
2485 static void eth_set_access_control (ETH_PORT eth_port_num,
2486 ETH_WIN_PARAM * param)
2488 unsigned int access_prot_reg;
2490 /* Set access control register */
2491 access_prot_reg = MV_REG_READ (MV64460_ETH_ACCESS_PROTECTION_REG
2493 access_prot_reg &= (~(3 << (param->win * 2))); /* clear window permission */
2494 access_prot_reg |= (param->access_ctrl << (param->win * 2));
2495 MV_REG_WRITE (MV64460_ETH_ACCESS_PROTECTION_REG (eth_port_num),
2498 /* Set window Size reg (SR) */
2499 MV_REG_WRITE ((MV64460_ETH_SIZE_REG_0 +
2500 (ETH_SIZE_REG_GAP * param->win)),
2501 (((param->size / 0x10000) - 1) << 16));
2503 /* Set window Base address reg (BA) */
2504 MV_REG_WRITE ((MV64460_ETH_BAR_0 + (ETH_BAR_GAP * param->win)),
2505 (param->target | param->attributes | param->base_addr));
2506 /* High address remap reg (HARR) */
2508 MV_REG_WRITE ((MV64460_ETH_HIGH_ADDR_REMAP_REG_0 +
2509 (ETH_HIGH_ADDR_REMAP_REG_GAP * param->win)),
2512 /* Base address enable reg (BARER) */
2513 if (param->enable == 1)
2514 MV_RESET_REG_BITS (MV64460_ETH_BASE_ADDR_ENABLE_REG,
2517 MV_SET_REG_BITS (MV64460_ETH_BASE_ADDR_ENABLE_REG,
2521 /*******************************************************************************
2522 * ether_init_rx_desc_ring - Curve a Rx chain desc list and buffer in memory.
2525 * This function prepares a Rx chained list of descriptors and packet
2526 * buffers in a form of a ring. The routine must be called after port
2527 * initialization routine and before port start routine.
2528 * The Ethernet SDMA engine uses CPU bus addresses to access the various
2529 * devices in the system (i.e. DRAM). This function uses the ethernet
2530 * struct 'virtual to physical' routine (set by the user) to set the ring
2531 * with physical addresses.
2534 * ETH_PORT_INFO *p_eth_port_ctrl Ethernet Port Control srtuct.
2535 * ETH_QUEUE rx_queue Number of Rx queue.
2536 * int rx_desc_num Number of Rx descriptors
2537 * int rx_buff_size Size of Rx buffer
2538 * unsigned int rx_desc_base_addr Rx descriptors memory area base addr.
2539 * unsigned int rx_buff_base_addr Rx buffer memory area base addr.
2542 * The routine updates the Ethernet port control struct with information
2543 * regarding the Rx descriptors and buffers.
2546 * false if the given descriptors memory area is not aligned according to
2547 * Ethernet SDMA specifications.
2550 *******************************************************************************/
2551 static bool ether_init_rx_desc_ring (ETH_PORT_INFO * p_eth_port_ctrl,
2555 unsigned int rx_desc_base_addr,
2556 unsigned int rx_buff_base_addr)
2558 ETH_RX_DESC *p_rx_desc;
2559 ETH_RX_DESC *p_rx_prev_desc; /* pointer to link with the last descriptor */
2560 unsigned int buffer_addr;
2561 int ix; /* a counter */
2564 p_rx_desc = (ETH_RX_DESC *) rx_desc_base_addr;
2565 p_rx_prev_desc = p_rx_desc;
2566 buffer_addr = rx_buff_base_addr;
2568 /* Rx desc Must be 4LW aligned (i.e. Descriptor_Address[3:0]=0000). */
2569 if (rx_buff_base_addr & 0xF)
2572 /* Rx buffers are limited to 64K bytes and Minimum size is 8 bytes */
2573 if ((rx_buff_size < 8) || (rx_buff_size > RX_BUFFER_MAX_SIZE))
2576 /* Rx buffers must be 64-bit aligned. */
2577 if ((rx_buff_base_addr + rx_buff_size) & 0x7)
2580 /* initialize the Rx descriptors ring */
2581 for (ix = 0; ix < rx_desc_num; ix++) {
2582 p_rx_desc->buf_size = rx_buff_size;
2583 p_rx_desc->byte_cnt = 0x0000;
2584 p_rx_desc->cmd_sts =
2585 ETH_BUFFER_OWNED_BY_DMA | ETH_RX_ENABLE_INTERRUPT;
2586 p_rx_desc->next_desc_ptr =
2587 ((unsigned int) p_rx_desc) + RX_DESC_ALIGNED_SIZE;
2588 p_rx_desc->buf_ptr = buffer_addr;
2589 p_rx_desc->return_info = 0x00000000;
2590 D_CACHE_FLUSH_LINE (p_rx_desc, 0);
2591 buffer_addr += rx_buff_size;
2592 p_rx_prev_desc = p_rx_desc;
2593 p_rx_desc = (ETH_RX_DESC *)
2594 ((unsigned int) p_rx_desc + RX_DESC_ALIGNED_SIZE);
2597 /* Closing Rx descriptors ring */
2598 p_rx_prev_desc->next_desc_ptr = (rx_desc_base_addr);
2599 D_CACHE_FLUSH_LINE (p_rx_prev_desc, 0);
2601 /* Save Rx desc pointer to driver struct. */
2602 CURR_RFD_SET ((ETH_RX_DESC *) rx_desc_base_addr, rx_queue);
2603 USED_RFD_SET ((ETH_RX_DESC *) rx_desc_base_addr, rx_queue);
2605 p_eth_port_ctrl->p_rx_desc_area_base[rx_queue] =
2606 (ETH_RX_DESC *) rx_desc_base_addr;
2607 p_eth_port_ctrl->rx_desc_area_size[rx_queue] =
2608 rx_desc_num * RX_DESC_ALIGNED_SIZE;
2610 p_eth_port_ctrl->port_rx_queue_command |= (1 << rx_queue);
2615 /*******************************************************************************
2616 * ether_init_tx_desc_ring - Curve a Tx chain desc list and buffer in memory.
2619 * This function prepares a Tx chained list of descriptors and packet
2620 * buffers in a form of a ring. The routine must be called after port
2621 * initialization routine and before port start routine.
2622 * The Ethernet SDMA engine uses CPU bus addresses to access the various
2623 * devices in the system (i.e. DRAM). This function uses the ethernet
2624 * struct 'virtual to physical' routine (set by the user) to set the ring
2625 * with physical addresses.
2628 * ETH_PORT_INFO *p_eth_port_ctrl Ethernet Port Control srtuct.
2629 * ETH_QUEUE tx_queue Number of Tx queue.
2630 * int tx_desc_num Number of Tx descriptors
2631 * int tx_buff_size Size of Tx buffer
2632 * unsigned int tx_desc_base_addr Tx descriptors memory area base addr.
2633 * unsigned int tx_buff_base_addr Tx buffer memory area base addr.
2636 * The routine updates the Ethernet port control struct with information
2637 * regarding the Tx descriptors and buffers.
2640 * false if the given descriptors memory area is not aligned according to
2641 * Ethernet SDMA specifications.
2644 *******************************************************************************/
2645 static bool ether_init_tx_desc_ring (ETH_PORT_INFO * p_eth_port_ctrl,
2649 unsigned int tx_desc_base_addr,
2650 unsigned int tx_buff_base_addr)
2653 ETH_TX_DESC *p_tx_desc;
2654 ETH_TX_DESC *p_tx_prev_desc;
2655 unsigned int buffer_addr;
2656 int ix; /* a counter */
2659 /* save the first desc pointer to link with the last descriptor */
2660 p_tx_desc = (ETH_TX_DESC *) tx_desc_base_addr;
2661 p_tx_prev_desc = p_tx_desc;
2662 buffer_addr = tx_buff_base_addr;
2664 /* Tx desc Must be 4LW aligned (i.e. Descriptor_Address[3:0]=0000). */
2665 if (tx_buff_base_addr & 0xF)
2668 /* Tx buffers are limited to 64K bytes and Minimum size is 8 bytes */
2669 if ((tx_buff_size > TX_BUFFER_MAX_SIZE)
2670 || (tx_buff_size < TX_BUFFER_MIN_SIZE))
2673 /* Initialize the Tx descriptors ring */
2674 for (ix = 0; ix < tx_desc_num; ix++) {
2675 p_tx_desc->byte_cnt = 0x0000;
2676 p_tx_desc->l4i_chk = 0x0000;
2677 p_tx_desc->cmd_sts = 0x00000000;
2678 p_tx_desc->next_desc_ptr =
2679 ((unsigned int) p_tx_desc) + TX_DESC_ALIGNED_SIZE;
2681 p_tx_desc->buf_ptr = buffer_addr;
2682 p_tx_desc->return_info = 0x00000000;
2683 D_CACHE_FLUSH_LINE (p_tx_desc, 0);
2684 buffer_addr += tx_buff_size;
2685 p_tx_prev_desc = p_tx_desc;
2686 p_tx_desc = (ETH_TX_DESC *)
2687 ((unsigned int) p_tx_desc + TX_DESC_ALIGNED_SIZE);
2690 /* Closing Tx descriptors ring */
2691 p_tx_prev_desc->next_desc_ptr = tx_desc_base_addr;
2692 D_CACHE_FLUSH_LINE (p_tx_prev_desc, 0);
2693 /* Set Tx desc pointer in driver struct. */
2694 CURR_TFD_SET ((ETH_TX_DESC *) tx_desc_base_addr, tx_queue);
2695 USED_TFD_SET ((ETH_TX_DESC *) tx_desc_base_addr, tx_queue);
2697 /* Init Tx ring base and size parameters */
2698 p_eth_port_ctrl->p_tx_desc_area_base[tx_queue] =
2699 (ETH_TX_DESC *) tx_desc_base_addr;
2700 p_eth_port_ctrl->tx_desc_area_size[tx_queue] =
2701 (tx_desc_num * TX_DESC_ALIGNED_SIZE);
2703 /* Add the queue to the list of Tx queues of this port */
2704 p_eth_port_ctrl->port_tx_queue_command |= (1 << tx_queue);
2709 /*******************************************************************************
2710 * eth_port_send - Send an Ethernet packet
2713 * This routine send a given packet described by p_pktinfo parameter. It
2714 * supports transmitting of a packet spaned over multiple buffers. The
2715 * routine updates 'curr' and 'first' indexes according to the packet
2716 * segment passed to the routine. In case the packet segment is first,
2717 * the 'first' index is update. In any case, the 'curr' index is updated.
2718 * If the routine get into Tx resource error it assigns 'curr' index as
2719 * 'first'. This way the function can abort Tx process of multiple
2720 * descriptors per packet.
2723 * ETH_PORT_INFO *p_eth_port_ctrl Ethernet Port Control srtuct.
2724 * ETH_QUEUE tx_queue Number of Tx queue.
2725 * PKT_INFO *p_pkt_info User packet buffer.
2728 * Tx ring 'curr' and 'first' indexes are updated.
2731 * ETH_QUEUE_FULL in case of Tx resource error.
2732 * ETH_ERROR in case the routine can not access Tx desc ring.
2733 * ETH_QUEUE_LAST_RESOURCE if the routine uses the last Tx resource.
2736 *******************************************************************************/
2737 static ETH_FUNC_RET_STATUS eth_port_send (ETH_PORT_INFO * p_eth_port_ctrl,
2739 PKT_INFO * p_pkt_info)
2741 volatile ETH_TX_DESC *p_tx_desc_first;
2742 volatile ETH_TX_DESC *p_tx_desc_curr;
2743 volatile ETH_TX_DESC *p_tx_next_desc_curr;
2744 volatile ETH_TX_DESC *p_tx_desc_used;
2745 unsigned int command_status;
2747 /* Do not process Tx ring in case of Tx ring resource error */
2748 if (p_eth_port_ctrl->tx_resource_err[tx_queue] == true)
2749 return ETH_QUEUE_FULL;
2751 /* Get the Tx Desc ring indexes */
2752 CURR_TFD_GET (p_tx_desc_curr, tx_queue);
2753 USED_TFD_GET (p_tx_desc_used, tx_queue);
2755 if (p_tx_desc_curr == NULL)
2758 /* The following parameters are used to save readings from memory */
2759 p_tx_next_desc_curr = TX_NEXT_DESC_PTR (p_tx_desc_curr, tx_queue);
2760 command_status = p_pkt_info->cmd_sts | ETH_ZERO_PADDING | ETH_GEN_CRC;
2762 if (command_status & (ETH_TX_FIRST_DESC)) {
2763 /* Update first desc */
2764 FIRST_TFD_SET (p_tx_desc_curr, tx_queue);
2765 p_tx_desc_first = p_tx_desc_curr;
2767 FIRST_TFD_GET (p_tx_desc_first, tx_queue);
2768 command_status |= ETH_BUFFER_OWNED_BY_DMA;
2771 /* Buffers with a payload smaller than 8 bytes must be aligned to 64-bit */
2772 /* boundary. We use the memory allocated for Tx descriptor. This memory */
2773 /* located in TX_BUF_OFFSET_IN_DESC offset within the Tx descriptor. */
2774 if (p_pkt_info->byte_cnt <= 8) {
2775 printf ("You have failed in the < 8 bytes errata - fixme\n"); /* RABEEH - TBD */
2778 p_tx_desc_curr->buf_ptr =
2779 (unsigned int) p_tx_desc_curr + TX_BUF_OFFSET_IN_DESC;
2780 eth_b_copy (p_pkt_info->buf_ptr, p_tx_desc_curr->buf_ptr,
2781 p_pkt_info->byte_cnt);
2783 p_tx_desc_curr->buf_ptr = p_pkt_info->buf_ptr;
2785 p_tx_desc_curr->byte_cnt = p_pkt_info->byte_cnt;
2786 p_tx_desc_curr->return_info = p_pkt_info->return_info;
2788 if (p_pkt_info->cmd_sts & (ETH_TX_LAST_DESC)) {
2789 /* Set last desc with DMA ownership and interrupt enable. */
2790 p_tx_desc_curr->cmd_sts = command_status |
2791 ETH_BUFFER_OWNED_BY_DMA | ETH_TX_ENABLE_INTERRUPT;
2793 if (p_tx_desc_curr != p_tx_desc_first)
2794 p_tx_desc_first->cmd_sts |= ETH_BUFFER_OWNED_BY_DMA;
2796 /* Flush CPU pipe */
2798 D_CACHE_FLUSH_LINE ((unsigned int) p_tx_desc_curr, 0);
2799 D_CACHE_FLUSH_LINE ((unsigned int) p_tx_desc_first, 0);
2802 /* Apply send command */
2803 ETH_ENABLE_TX_QUEUE (tx_queue, p_eth_port_ctrl->port_num);
2805 /* Finish Tx packet. Update first desc in case of Tx resource error */
2806 p_tx_desc_first = p_tx_next_desc_curr;
2807 FIRST_TFD_SET (p_tx_desc_first, tx_queue);
2810 p_tx_desc_curr->cmd_sts = command_status;
2811 D_CACHE_FLUSH_LINE ((unsigned int) p_tx_desc_curr, 0);
2814 /* Check for ring index overlap in the Tx desc ring */
2815 if (p_tx_next_desc_curr == p_tx_desc_used) {
2816 /* Update the current descriptor */
2817 CURR_TFD_SET (p_tx_desc_first, tx_queue);
2819 p_eth_port_ctrl->tx_resource_err[tx_queue] = true;
2820 return ETH_QUEUE_LAST_RESOURCE;
2822 /* Update the current descriptor */
2823 CURR_TFD_SET (p_tx_next_desc_curr, tx_queue);
2828 /*******************************************************************************
2829 * eth_tx_return_desc - Free all used Tx descriptors
2832 * This routine returns the transmitted packet information to the caller.
2833 * It uses the 'first' index to support Tx desc return in case a transmit
2834 * of a packet spanned over multiple buffer still in process.
2835 * In case the Tx queue was in "resource error" condition, where there are
2836 * no available Tx resources, the function resets the resource error flag.
2839 * ETH_PORT_INFO *p_eth_port_ctrl Ethernet Port Control srtuct.
2840 * ETH_QUEUE tx_queue Number of Tx queue.
2841 * PKT_INFO *p_pkt_info User packet buffer.
2844 * Tx ring 'first' and 'used' indexes are updated.
2847 * ETH_ERROR in case the routine can not access Tx desc ring.
2848 * ETH_RETRY in case there is transmission in process.
2849 * ETH_END_OF_JOB if the routine has nothing to release.
2852 *******************************************************************************/
2853 static ETH_FUNC_RET_STATUS eth_tx_return_desc (ETH_PORT_INFO *
2856 PKT_INFO * p_pkt_info)
2858 volatile ETH_TX_DESC *p_tx_desc_used = NULL;
2859 volatile ETH_TX_DESC *p_tx_desc_first = NULL;
2860 unsigned int command_status;
2863 /* Get the Tx Desc ring indexes */
2864 USED_TFD_GET (p_tx_desc_used, tx_queue);
2865 FIRST_TFD_GET (p_tx_desc_first, tx_queue);
2869 if (p_tx_desc_used == NULL)
2872 command_status = p_tx_desc_used->cmd_sts;
2874 /* Still transmitting... */
2875 if (command_status & (ETH_BUFFER_OWNED_BY_DMA)) {
2876 D_CACHE_FLUSH_LINE ((unsigned int) p_tx_desc_used, 0);
2880 /* Stop release. About to overlap the current available Tx descriptor */
2881 if ((p_tx_desc_used == p_tx_desc_first) &&
2882 (p_eth_port_ctrl->tx_resource_err[tx_queue] == false)) {
2883 D_CACHE_FLUSH_LINE ((unsigned int) p_tx_desc_used, 0);
2884 return ETH_END_OF_JOB;
2887 /* Pass the packet information to the caller */
2888 p_pkt_info->cmd_sts = command_status;
2889 p_pkt_info->return_info = p_tx_desc_used->return_info;
2890 p_tx_desc_used->return_info = 0;
2892 /* Update the next descriptor to release. */
2893 USED_TFD_SET (TX_NEXT_DESC_PTR (p_tx_desc_used, tx_queue), tx_queue);
2895 /* Any Tx return cancels the Tx resource error status */
2896 if (p_eth_port_ctrl->tx_resource_err[tx_queue] == true)
2897 p_eth_port_ctrl->tx_resource_err[tx_queue] = false;
2899 D_CACHE_FLUSH_LINE ((unsigned int) p_tx_desc_used, 0);
2905 /*******************************************************************************
2906 * eth_port_receive - Get received information from Rx ring.
2909 * This routine returns the received data to the caller. There is no
2910 * data copying during routine operation. All information is returned
2911 * using pointer to packet information struct passed from the caller.
2912 * If the routine exhausts Rx ring resources then the resource error flag
2916 * ETH_PORT_INFO *p_eth_port_ctrl Ethernet Port Control srtuct.
2917 * ETH_QUEUE rx_queue Number of Rx queue.
2918 * PKT_INFO *p_pkt_info User packet buffer.
2921 * Rx ring current and used indexes are updated.
2924 * ETH_ERROR in case the routine can not access Rx desc ring.
2925 * ETH_QUEUE_FULL if Rx ring resources are exhausted.
2926 * ETH_END_OF_JOB if there is no received data.
2929 *******************************************************************************/
2930 static ETH_FUNC_RET_STATUS eth_port_receive (ETH_PORT_INFO * p_eth_port_ctrl,
2932 PKT_INFO * p_pkt_info)
2934 volatile ETH_RX_DESC *p_rx_curr_desc;
2935 volatile ETH_RX_DESC *p_rx_next_curr_desc;
2936 volatile ETH_RX_DESC *p_rx_used_desc;
2937 unsigned int command_status;
2939 /* Do not process Rx ring in case of Rx ring resource error */
2940 if (p_eth_port_ctrl->rx_resource_err[rx_queue] == true) {
2941 printf ("\nRx Queue is full ...\n");
2942 return ETH_QUEUE_FULL;
2945 /* Get the Rx Desc ring 'curr and 'used' indexes */
2946 CURR_RFD_GET (p_rx_curr_desc, rx_queue);
2947 USED_RFD_GET (p_rx_used_desc, rx_queue);
2950 if (p_rx_curr_desc == NULL)
2953 /* The following parameters are used to save readings from memory */
2954 p_rx_next_curr_desc = RX_NEXT_DESC_PTR (p_rx_curr_desc, rx_queue);
2955 command_status = p_rx_curr_desc->cmd_sts;
2957 /* Nothing to receive... */
2958 if (command_status & (ETH_BUFFER_OWNED_BY_DMA)) {
2959 /* DP(printf("Rx: command_status: %08x\n", command_status)); */
2960 D_CACHE_FLUSH_LINE ((unsigned int) p_rx_curr_desc, 0);
2961 /* DP(printf("\nETH_END_OF_JOB ...\n"));*/
2962 return ETH_END_OF_JOB;
2965 p_pkt_info->byte_cnt = (p_rx_curr_desc->byte_cnt) - RX_BUF_OFFSET;
2966 p_pkt_info->cmd_sts = command_status;
2967 p_pkt_info->buf_ptr = (p_rx_curr_desc->buf_ptr) + RX_BUF_OFFSET;
2968 p_pkt_info->return_info = p_rx_curr_desc->return_info;
2969 p_pkt_info->l4i_chk = p_rx_curr_desc->buf_size; /* IP fragment indicator */
2971 /* Clean the return info field to indicate that the packet has been */
2972 /* moved to the upper layers */
2973 p_rx_curr_desc->return_info = 0;
2975 /* Update 'curr' in data structure */
2976 CURR_RFD_SET (p_rx_next_curr_desc, rx_queue);
2978 /* Rx descriptors resource exhausted. Set the Rx ring resource error flag */
2979 if (p_rx_next_curr_desc == p_rx_used_desc)
2980 p_eth_port_ctrl->rx_resource_err[rx_queue] = true;
2982 D_CACHE_FLUSH_LINE ((unsigned int) p_rx_curr_desc, 0);
2987 /*******************************************************************************
2988 * eth_rx_return_buff - Returns a Rx buffer back to the Rx ring.
2991 * This routine returns a Rx buffer back to the Rx ring. It retrieves the
2992 * next 'used' descriptor and attached the returned buffer to it.
2993 * In case the Rx ring was in "resource error" condition, where there are
2994 * no available Rx resources, the function resets the resource error flag.
2997 * ETH_PORT_INFO *p_eth_port_ctrl Ethernet Port Control srtuct.
2998 * ETH_QUEUE rx_queue Number of Rx queue.
2999 * PKT_INFO *p_pkt_info Information on the returned buffer.
3002 * New available Rx resource in Rx descriptor ring.
3005 * ETH_ERROR in case the routine can not access Rx desc ring.
3008 *******************************************************************************/
3009 static ETH_FUNC_RET_STATUS eth_rx_return_buff (ETH_PORT_INFO *
3012 PKT_INFO * p_pkt_info)
3014 volatile ETH_RX_DESC *p_used_rx_desc; /* Where to return Rx resource */
3016 /* Get 'used' Rx descriptor */
3017 USED_RFD_GET (p_used_rx_desc, rx_queue);
3020 if (p_used_rx_desc == NULL)
3023 p_used_rx_desc->buf_ptr = p_pkt_info->buf_ptr;
3024 p_used_rx_desc->return_info = p_pkt_info->return_info;
3025 p_used_rx_desc->byte_cnt = p_pkt_info->byte_cnt;
3026 p_used_rx_desc->buf_size = MV64460_RX_BUFFER_SIZE; /* Reset Buffer size */
3028 /* Flush the write pipe */
3031 /* Return the descriptor to DMA ownership */
3032 p_used_rx_desc->cmd_sts =
3033 ETH_BUFFER_OWNED_BY_DMA | ETH_RX_ENABLE_INTERRUPT;
3035 /* Flush descriptor and CPU pipe */
3036 D_CACHE_FLUSH_LINE ((unsigned int) p_used_rx_desc, 0);
3039 /* Move the used descriptor pointer to the next descriptor */
3040 USED_RFD_SET (RX_NEXT_DESC_PTR (p_used_rx_desc, rx_queue), rx_queue);
3042 /* Any Rx return cancels the Rx resource error status */
3043 if (p_eth_port_ctrl->rx_resource_err[rx_queue] == true)
3044 p_eth_port_ctrl->rx_resource_err[rx_queue] = false;
3049 /*******************************************************************************
3050 * eth_port_set_rx_coal - Sets coalescing interrupt mechanism on RX path
3053 * This routine sets the RX coalescing interrupt mechanism parameter.
3054 * This parameter is a timeout counter, that counts in 64 t_clk
3055 * chunks ; that when timeout event occurs a maskable interrupt
3057 * The parameter is calculated using the tClk of the MV-643xx chip
3058 * , and the required delay of the interrupt in usec.
3061 * ETH_PORT eth_port_num Ethernet port number
3062 * unsigned int t_clk t_clk of the MV-643xx chip in HZ units
3063 * unsigned int delay Delay in usec
3066 * Interrupt coalescing mechanism value is set in MV-643xx chip.
3069 * The interrupt coalescing value set in the gigE port.
3071 *******************************************************************************/
3073 static unsigned int eth_port_set_rx_coal (ETH_PORT eth_port_num,
3079 coal = ((t_clk / 1000000) * delay) / 64;
3080 /* Set RX Coalescing mechanism */
3081 MV_REG_WRITE (MV64460_ETH_SDMA_CONFIG_REG (eth_port_num),
3082 ((coal & 0x3fff) << 8) |
3084 (MV64460_ETH_SDMA_CONFIG_REG (eth_port_num))
3090 /*******************************************************************************
3091 * eth_port_set_tx_coal - Sets coalescing interrupt mechanism on TX path
3094 * This routine sets the TX coalescing interrupt mechanism parameter.
3095 * This parameter is a timeout counter, that counts in 64 t_clk
3096 * chunks ; that when timeout event occurs a maskable interrupt
3098 * The parameter is calculated using the t_cLK frequency of the
3099 * MV-643xx chip and the required delay in the interrupt in uSec
3102 * ETH_PORT eth_port_num Ethernet port number
3103 * unsigned int t_clk t_clk of the MV-643xx chip in HZ units
3104 * unsigned int delay Delay in uSeconds
3107 * Interrupt coalescing mechanism value is set in MV-643xx chip.
3110 * The interrupt coalescing value set in the gigE port.
3112 *******************************************************************************/
3114 static unsigned int eth_port_set_tx_coal (ETH_PORT eth_port_num,
3120 coal = ((t_clk / 1000000) * delay) / 64;
3121 /* Set TX Coalescing mechanism */
3122 MV_REG_WRITE (MV64460_ETH_TX_FIFO_URGENT_THRESHOLD_REG (eth_port_num),
3128 /*******************************************************************************
3129 * eth_b_copy - Copy bytes from source to destination
3132 * This function supports the eight bytes limitation on Tx buffer size.
3133 * The routine will zero eight bytes starting from the destination address
3134 * followed by copying bytes from the source address to the destination.
3137 * unsigned int src_addr 32 bit source address.
3138 * unsigned int dst_addr 32 bit destination address.
3139 * int byte_count Number of bytes to copy.
3147 *******************************************************************************/
3148 static void eth_b_copy (unsigned int src_addr, unsigned int dst_addr,
3151 /* Zero the dst_addr area */
3152 *(unsigned int *) dst_addr = 0x0;
3154 while (byte_count != 0) {
3155 *(char *) dst_addr = *(char *) src_addr;