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_r (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 dev->priv = (void *) ethernet_private =
271 calloc (sizeof (*ethernet_private), 1);
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 ethernet_private->port_private = (void *) port_private =
285 calloc (sizeof (*ethernet_private), 1);
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_r (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;
423 u32 port_status, phy_reg_data;
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 port_status = 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 ETH_PORT_INFO *ethernet_private;
640 struct mv64460_eth_priv *port_private;
641 unsigned int port_num;
643 ethernet_private = (ETH_PORT_INFO *) dev->priv;
645 (struct mv64460_eth_priv *) ethernet_private->port_private;
646 port_num = port_private->port_num;
648 /* Disable all gigE address decoder */
649 MV_REG_WRITE (MV64460_ETH_BASE_ADDR_ENABLE_REG, 0x3f);
650 DP (printf ("%s Ethernet stop called ... \n", __FUNCTION__));
651 mv64460_eth_real_stop (dev);
656 /* Helper function for mv64460_eth_stop */
658 static int mv64460_eth_real_stop (struct eth_device *dev)
660 ETH_PORT_INFO *ethernet_private;
661 struct mv64460_eth_priv *port_private;
662 unsigned int port_num;
664 ethernet_private = (ETH_PORT_INFO *) dev->priv;
666 (struct mv64460_eth_priv *) ethernet_private->port_private;
667 port_num = port_private->port_num;
670 mv64460_eth_free_tx_rings (dev);
671 mv64460_eth_free_rx_rings (dev);
673 eth_port_reset (ethernet_private->port_num);
674 /* Disable ethernet port interrupts */
675 MV_REG_WRITE (MV64460_ETH_INTERRUPT_CAUSE_REG (port_num), 0);
676 MV_REG_WRITE (MV64460_ETH_INTERRUPT_CAUSE_EXTEND_REG (port_num), 0);
677 /* Mask RX buffer and TX end interrupt */
678 MV_REG_WRITE (MV64460_ETH_INTERRUPT_MASK_REG (port_num), 0);
679 /* Mask phy and link status changes interrupts */
680 MV_REG_WRITE (MV64460_ETH_INTERRUPT_EXTEND_MASK_REG (port_num), 0);
681 MV_RESET_REG_BITS (MV64460_CPU_INTERRUPT0_MASK_HIGH,
683 /* Print Network statistics */
684 #ifndef UPDATE_STATS_BY_SOFTWARE
686 * Print statistics (only if ethernet is running),
687 * then zero all the stats fields in memory
689 if (port_private->eth_running == MAGIC_ETH_RUNNING) {
690 port_private->eth_running = 0;
691 mv64460_eth_print_stat (dev);
693 memset (port_private->stats, 0, sizeof (struct net_device_stats));
695 DP (printf ("\nEthernet stopped ... \n"));
700 /**********************************************************************
701 * mv64460_eth_start_xmit
703 * This function is queues a packet in the Tx descriptor for
706 * Input : skb - a pointer to socket buffer
707 * dev - a pointer to the required port
709 * Output : zero upon success
710 **********************************************************************/
712 int mv64460_eth_xmit (struct eth_device *dev, volatile void *dataPtr,
715 ETH_PORT_INFO *ethernet_private;
716 struct mv64460_eth_priv *port_private;
717 unsigned int port_num;
719 ETH_FUNC_RET_STATUS status;
720 struct net_device_stats *stats;
721 ETH_FUNC_RET_STATUS release_result;
723 ethernet_private = (ETH_PORT_INFO *) dev->priv;
725 (struct mv64460_eth_priv *) ethernet_private->port_private;
726 port_num = port_private->port_num;
728 stats = port_private->stats;
730 /* Update packet info data structure */
731 pkt_info.cmd_sts = ETH_TX_FIRST_DESC | ETH_TX_LAST_DESC; /* DMA owned, first last */
732 pkt_info.byte_cnt = dataSize;
733 pkt_info.buf_ptr = (unsigned int) dataPtr;
735 status = eth_port_send (ethernet_private, ETH_Q0, &pkt_info);
736 if ((status == ETH_ERROR) || (status == ETH_QUEUE_FULL)) {
737 printf ("Error on transmitting packet ..");
738 if (status == ETH_QUEUE_FULL)
739 printf ("ETH Queue is full. \n");
740 if (status == ETH_QUEUE_LAST_RESOURCE)
741 printf ("ETH Queue: using last available resource. \n");
745 /* Update statistics and start of transmittion time */
746 stats->tx_bytes += dataSize;
749 /* Check if packet(s) is(are) transmitted correctly (release everything) */
752 eth_tx_return_desc (ethernet_private, ETH_Q0,
754 switch (release_result) {
756 DP (printf ("descriptor released\n"));
757 if (pkt_info.cmd_sts & BIT0) {
758 printf ("Error in TX\n");
764 DP (printf ("transmission still in process\n"));
768 printf ("routine can not access Tx desc ring\n");
772 DP (printf ("the routine has nothing to release\n"));
774 default: /* should not happen */
777 } while (release_result == ETH_OK);
780 return 0; /* success */
782 return 1; /* Failed - higher layers will free the skb */
785 /**********************************************************************
786 * mv64460_eth_receive
788 * This function is forward packets that are received from the port's
789 * queues toward kernel core or FastRoute them to another interface.
791 * Input : dev - a pointer to the required interface
792 * max - maximum number to receive (0 means unlimted)
794 * Output : number of served packets
795 **********************************************************************/
797 int mv64460_eth_receive (struct eth_device *dev)
799 ETH_PORT_INFO *ethernet_private;
800 struct mv64460_eth_priv *port_private;
801 unsigned int port_num;
803 struct net_device_stats *stats;
806 ethernet_private = (ETH_PORT_INFO *) dev->priv;
808 (struct mv64460_eth_priv *) ethernet_private->port_private;
809 port_num = port_private->port_num;
810 stats = port_private->stats;
812 while ((eth_port_receive (ethernet_private, ETH_Q0, &pkt_info) ==
816 if (pkt_info.byte_cnt != 0) {
817 printf ("%s: Received %d byte Packet @ 0x%x\n",
818 __FUNCTION__, pkt_info.byte_cnt,
822 /* Update statistics. Note byte count includes 4 byte CRC count */
824 stats->rx_bytes += pkt_info.byte_cnt;
827 * In case received a packet without first / last bits on OR the error
828 * summary bit is on, the packets needs to be dropeed.
831 cmd_sts & (ETH_RX_FIRST_DESC | ETH_RX_LAST_DESC)) !=
832 (ETH_RX_FIRST_DESC | ETH_RX_LAST_DESC))
833 || (pkt_info.cmd_sts & ETH_ERROR_SUMMARY)) {
836 printf ("Received packet spread on multiple descriptors\n");
838 /* Is this caused by an error ? */
839 if (pkt_info.cmd_sts & ETH_ERROR_SUMMARY) {
843 /* free these descriptors again without forwarding them to the higher layers */
844 pkt_info.buf_ptr &= ~0x7; /* realign buffer again */
845 pkt_info.byte_cnt = 0x0000; /* Reset Byte count */
847 if (eth_rx_return_buff
848 (ethernet_private, ETH_Q0, &pkt_info) != ETH_OK) {
849 printf ("Error while returning the RX Desc to Ring\n");
851 DP (printf ("RX Desc returned to Ring\n"));
853 /* /free these descriptors again */
856 /* !!! call higher layer processing */
858 printf ("\nNow send it to upper layer protocols (NetReceive) ...\n");
860 /* let the upper layer handle the packet */
861 NetReceive ((uchar *) pkt_info.buf_ptr,
862 (int) pkt_info.byte_cnt);
864 /* **************************************************************** */
865 /* free descriptor */
866 pkt_info.buf_ptr &= ~0x7; /* realign buffer again */
867 pkt_info.byte_cnt = 0x0000; /* Reset Byte count */
869 ("RX: pkt_info.buf_ptr = %x\n",
871 if (eth_rx_return_buff
872 (ethernet_private, ETH_Q0, &pkt_info) != ETH_OK) {
873 printf ("Error while returning the RX Desc to Ring\n");
875 DP (printf ("RX Desc returned to Ring\n"));
878 /* **************************************************************** */
882 mv64460_eth_get_stats (dev); /* update statistics */
886 /**********************************************************************
887 * mv64460_eth_get_stats
889 * Returns a pointer to the interface statistics.
891 * Input : dev - a pointer to the required interface
893 * Output : a pointer to the interface's statistics
894 **********************************************************************/
896 static struct net_device_stats *mv64460_eth_get_stats (struct eth_device *dev)
898 ETH_PORT_INFO *ethernet_private;
899 struct mv64460_eth_priv *port_private;
900 unsigned int port_num;
902 ethernet_private = (ETH_PORT_INFO *) dev->priv;
904 (struct mv64460_eth_priv *) ethernet_private->port_private;
905 port_num = port_private->port_num;
907 mv64460_eth_update_stat (dev);
909 return port_private->stats;
913 /**********************************************************************
914 * mv64460_eth_update_stat
916 * Update the statistics structure in the private data structure
918 * Input : pointer to ethernet interface network device structure
920 **********************************************************************/
922 static void mv64460_eth_update_stat (struct eth_device *dev)
924 ETH_PORT_INFO *ethernet_private;
925 struct mv64460_eth_priv *port_private;
926 struct net_device_stats *stats;
927 unsigned int port_num;
928 volatile unsigned int dummy;
930 ethernet_private = (ETH_PORT_INFO *) dev->priv;
932 (struct mv64460_eth_priv *) ethernet_private->port_private;
933 port_num = port_private->port_num;
934 stats = port_private->stats;
936 /* These are false updates */
937 stats->rx_packets += (unsigned long)
938 eth_read_mib_counter (ethernet_private->port_num,
939 ETH_MIB_GOOD_FRAMES_RECEIVED);
940 stats->tx_packets += (unsigned long)
941 eth_read_mib_counter (ethernet_private->port_num,
942 ETH_MIB_GOOD_FRAMES_SENT);
943 stats->rx_bytes += (unsigned long)
944 eth_read_mib_counter (ethernet_private->port_num,
945 ETH_MIB_GOOD_OCTETS_RECEIVED_LOW);
947 * Ideally this should be as follows -
949 * stats->rx_bytes += stats->rx_bytes +
950 * ((unsigned long) ethReadMibCounter (ethernet_private->port_num ,
951 * ETH_MIB_GOOD_OCTETS_RECEIVED_HIGH) << 32);
953 * But the unsigned long in PowerPC and MIPS are 32bit. So the next read
954 * is just a dummy read for proper work of the GigE port
956 dummy = eth_read_mib_counter (ethernet_private->port_num,
957 ETH_MIB_GOOD_OCTETS_RECEIVED_HIGH);
958 stats->tx_bytes += (unsigned long)
959 eth_read_mib_counter (ethernet_private->port_num,
960 ETH_MIB_GOOD_OCTETS_SENT_LOW);
961 dummy = eth_read_mib_counter (ethernet_private->port_num,
962 ETH_MIB_GOOD_OCTETS_SENT_HIGH);
963 stats->rx_errors += (unsigned long)
964 eth_read_mib_counter (ethernet_private->port_num,
965 ETH_MIB_MAC_RECEIVE_ERROR);
967 /* Rx dropped is for received packet with CRC error */
969 (unsigned long) eth_read_mib_counter (ethernet_private->
971 ETH_MIB_BAD_CRC_EVENT);
972 stats->multicast += (unsigned long)
973 eth_read_mib_counter (ethernet_private->port_num,
974 ETH_MIB_MULTICAST_FRAMES_RECEIVED);
976 (unsigned long) eth_read_mib_counter (ethernet_private->
979 (unsigned long) eth_read_mib_counter (ethernet_private->
981 ETH_MIB_LATE_COLLISION);
982 /* detailed rx errors */
983 stats->rx_length_errors +=
984 (unsigned long) eth_read_mib_counter (ethernet_private->
986 ETH_MIB_UNDERSIZE_RECEIVED)
988 (unsigned long) eth_read_mib_counter (ethernet_private->
990 ETH_MIB_OVERSIZE_RECEIVED);
991 /* detailed tx errors */
994 #ifndef UPDATE_STATS_BY_SOFTWARE
995 /**********************************************************************
996 * mv64460_eth_print_stat
998 * Update the statistics structure in the private data structure
1000 * Input : pointer to ethernet interface network device structure
1002 **********************************************************************/
1004 static void mv64460_eth_print_stat (struct eth_device *dev)
1006 ETH_PORT_INFO *ethernet_private;
1007 struct mv64460_eth_priv *port_private;
1008 struct net_device_stats *stats;
1009 unsigned int port_num;
1011 ethernet_private = (ETH_PORT_INFO *) dev->priv;
1013 (struct mv64460_eth_priv *) ethernet_private->port_private;
1014 port_num = port_private->port_num;
1015 stats = port_private->stats;
1017 /* These are false updates */
1018 printf ("\n### Network statistics: ###\n");
1019 printf ("--------------------------\n");
1020 printf (" Packets received: %ld\n", stats->rx_packets);
1021 printf (" Packets send: %ld\n", stats->tx_packets);
1022 printf (" Received bytes: %ld\n", stats->rx_bytes);
1023 printf (" Send bytes: %ld\n", stats->tx_bytes);
1024 if (stats->rx_errors != 0)
1025 printf (" Rx Errors: %ld\n",
1027 if (stats->rx_dropped != 0)
1028 printf (" Rx dropped (CRC Errors): %ld\n",
1030 if (stats->multicast != 0)
1031 printf (" Rx mulicast frames: %ld\n",
1033 if (stats->collisions != 0)
1034 printf (" No. of collisions: %ld\n",
1036 if (stats->rx_length_errors != 0)
1037 printf (" Rx length errors: %ld\n",
1038 stats->rx_length_errors);
1042 /**************************************************************************
1043 *network_start - Network Kick Off Routine UBoot
1046 **************************************************************************/
1048 bool db64460_eth_start (struct eth_device *dev)
1050 return (mv64460_eth_open (dev)); /* calls real open */
1053 /*************************************************************************
1054 **************************************************************************
1055 **************************************************************************
1056 * The second part is the low level driver of the gigE ethernet ports. *
1057 **************************************************************************
1058 **************************************************************************
1059 *************************************************************************/
1061 * based on Linux code
1062 * arch/ppc/galileo/EVB64460/mv64460_eth.c - Driver for MV64460X ethernet ports
1063 * Copyright (C) 2002 rabeeh@galileo.co.il
1065 * This program is free software; you can redistribute it and/or
1066 * modify it under the terms of the GNU General Public License
1067 * as published by the Free Software Foundation; either version 2
1068 * of the License, or (at your option) any later version.
1070 * This program is distributed in the hope that it will be useful,
1071 * but WITHOUT ANY WARRANTY; without even the implied warranty of
1072 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1073 * GNU General Public License for more details.
1075 * You should have received a copy of the GNU General Public License
1076 * along with this program; if not, write to the Free Software
1077 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
1081 /********************************************************************************
1082 * Marvell's Gigabit Ethernet controller low level driver
1085 * This file introduce low level API to Marvell's Gigabit Ethernet
1086 * controller. This Gigabit Ethernet Controller driver API controls
1087 * 1) Operations (i.e. port init, start, reset etc').
1088 * 2) Data flow (i.e. port send, receive etc').
1089 * Each Gigabit Ethernet port is controlled via ETH_PORT_INFO
1091 * This struct includes user configuration information as well as
1092 * driver internal data needed for its operations.
1094 * Supported Features:
1095 * - This low level driver is OS independent. Allocating memory for
1096 * the descriptor rings and buffers are not within the scope of
1098 * - The user is free from Rx/Tx queue managing.
1099 * - This low level driver introduce functionality API that enable
1100 * the to operate Marvell's Gigabit Ethernet Controller in a
1102 * - Simple Gigabit Ethernet port operation API.
1103 * - Simple Gigabit Ethernet port data flow API.
1104 * - Data flow and operation API support per queue functionality.
1105 * - Support cached descriptors for better performance.
1106 * - Enable access to all four DRAM banks and internal SRAM memory
1108 * - PHY access and control API.
1109 * - Port control register configuration API.
1110 * - Full control over Unicast and Multicast MAC configurations.
1114 * Initialization phase
1115 * This phase complete the initialization of the ETH_PORT_INFO
1117 * User information regarding port configuration has to be set
1118 * prior to calling the port initialization routine. For example,
1119 * the user has to assign the port_phy_addr field which is board
1120 * depended parameter.
1121 * In this phase any port Tx/Rx activity is halted, MIB counters
1122 * are cleared, PHY address is set according to user parameter and
1123 * access to DRAM and internal SRAM memory spaces.
1125 * Driver ring initialization
1126 * Allocating memory for the descriptor rings and buffers is not
1127 * within the scope of this driver. Thus, the user is required to
1128 * allocate memory for the descriptors ring and buffers. Those
1129 * memory parameters are used by the Rx and Tx ring initialization
1130 * routines in order to curve the descriptor linked list in a form
1132 * Note: Pay special attention to alignment issues when using
1133 * cached descriptors/buffers. In this phase the driver store
1134 * information in the ETH_PORT_INFO struct regarding each queue
1138 * This phase prepares the Ethernet port for Rx and Tx activity.
1139 * It uses the information stored in the ETH_PORT_INFO struct to
1140 * initialize the various port registers.
1143 * All packet references to/from the driver are done using PKT_INFO
1145 * This struct is a unified struct used with Rx and Tx operations.
1146 * This way the user is not required to be familiar with neither
1147 * Tx nor Rx descriptors structures.
1148 * The driver's descriptors rings are management by indexes.
1149 * Those indexes controls the ring resources and used to indicate
1150 * a SW resource error:
1152 * This index points to the current available resource for use. For
1153 * example in Rx process this index will point to the descriptor
1154 * that will be passed to the user upon calling the receive routine.
1155 * In Tx process, this index will point to the descriptor
1156 * that will be assigned with the user packet info and transmitted.
1158 * This index points to the descriptor that need to restore its
1159 * resources. For example in Rx process, using the Rx buffer return
1160 * API will attach the buffer returned in packet info to the
1161 * descriptor pointed by 'used'. In Tx process, using the Tx
1162 * descriptor return will merely return the user packet info with
1163 * the command status of the transmitted buffer pointed by the
1164 * 'used' index. Nevertheless, it is essential to use this routine
1165 * to update the 'used' index.
1167 * This index supports Tx Scatter-Gather. It points to the first
1168 * descriptor of a packet assembled of multiple buffers. For example
1169 * when in middle of Such packet we have a Tx resource error the
1170 * 'curr' index get the value of 'first' to indicate that the ring
1171 * returned to its state before trying to transmit this packet.
1173 * Receive operation:
1174 * The eth_port_receive API set the packet information struct,
1175 * passed by the caller, with received information from the
1176 * 'current' SDMA descriptor.
1177 * It is the user responsibility to return this resource back
1178 * to the Rx descriptor ring to enable the reuse of this source.
1179 * Return Rx resource is done using the eth_rx_return_buff API.
1181 * Transmit operation:
1182 * The eth_port_send API supports Scatter-Gather which enables to
1183 * send a packet spanned over multiple buffers. This means that
1184 * for each packet info structure given by the user and put into
1185 * the Tx descriptors ring, will be transmitted only if the 'LAST'
1186 * bit will be set in the packet info command status field. This
1187 * API also consider restriction regarding buffer alignments and
1189 * The user must return a Tx resource after ensuring the buffer
1190 * has been transmitted to enable the Tx ring indexes to update.
1193 * This device is on-board. No jumper diagram is necessary.
1195 * EXTERNAL INTERFACE
1197 * Prior to calling the initialization routine eth_port_init() the user
1198 * must set the following fields under ETH_PORT_INFO struct:
1199 * port_num User Ethernet port number.
1200 * port_phy_addr User PHY address of Ethernet port.
1201 * port_mac_addr[6] User defined port MAC address.
1202 * port_config User port configuration value.
1203 * port_config_extend User port config extend value.
1204 * port_sdma_config User port SDMA config value.
1205 * port_serial_control User port serial control value.
1206 * *port_virt_to_phys () User function to cast virtual addr to CPU bus addr.
1207 * *port_private User scratch pad for user specific data structures.
1209 * This driver introduce a set of default values:
1210 * PORT_CONFIG_VALUE Default port configuration value
1211 * PORT_CONFIG_EXTEND_VALUE Default port extend configuration value
1212 * PORT_SDMA_CONFIG_VALUE Default sdma control value
1213 * PORT_SERIAL_CONTROL_VALUE Default port serial control value
1215 * This driver data flow is done using the PKT_INFO struct which is
1216 * a unified struct for Rx and Tx operations:
1217 * byte_cnt Tx/Rx descriptor buffer byte count.
1218 * l4i_chk CPU provided TCP Checksum. For Tx operation only.
1219 * cmd_sts Tx/Rx descriptor command status.
1220 * buf_ptr Tx/Rx descriptor buffer pointer.
1221 * return_info Tx/Rx user resource return information.
1224 * EXTERNAL SUPPORT REQUIREMENTS
1226 * This driver requires the following external support:
1228 * D_CACHE_FLUSH_LINE (address, address offset)
1230 * This macro applies assembly code to flush and invalidate cache
1232 * address - address base.
1233 * address offset - address offset
1238 * This macro applies assembly code to flush the CPU pipeline.
1240 *******************************************************************************/
1244 /* SDMA command macros */
1245 #define ETH_ENABLE_TX_QUEUE(tx_queue, eth_port) \
1246 MV_REG_WRITE(MV64460_ETH_TRANSMIT_QUEUE_COMMAND_REG(eth_port), (1 << tx_queue))
1248 #define ETH_DISABLE_TX_QUEUE(tx_queue, eth_port) \
1249 MV_REG_WRITE(MV64460_ETH_TRANSMIT_QUEUE_COMMAND_REG(eth_port),\
1250 (1 << (8 + tx_queue)))
1252 #define ETH_ENABLE_RX_QUEUE(rx_queue, eth_port) \
1253 MV_REG_WRITE(MV64460_ETH_RECEIVE_QUEUE_COMMAND_REG(eth_port), (1 << rx_queue))
1255 #define ETH_DISABLE_RX_QUEUE(rx_queue, eth_port) \
1256 MV_REG_WRITE(MV64460_ETH_RECEIVE_QUEUE_COMMAND_REG(eth_port), (1 << (8 + rx_queue)))
1258 #define CURR_RFD_GET(p_curr_desc, queue) \
1259 ((p_curr_desc) = p_eth_port_ctrl->p_rx_curr_desc_q[queue])
1261 #define CURR_RFD_SET(p_curr_desc, queue) \
1262 (p_eth_port_ctrl->p_rx_curr_desc_q[queue] = (p_curr_desc))
1264 #define USED_RFD_GET(p_used_desc, queue) \
1265 ((p_used_desc) = p_eth_port_ctrl->p_rx_used_desc_q[queue])
1267 #define USED_RFD_SET(p_used_desc, queue)\
1268 (p_eth_port_ctrl->p_rx_used_desc_q[queue] = (p_used_desc))
1271 #define CURR_TFD_GET(p_curr_desc, queue) \
1272 ((p_curr_desc) = p_eth_port_ctrl->p_tx_curr_desc_q[queue])
1274 #define CURR_TFD_SET(p_curr_desc, queue) \
1275 (p_eth_port_ctrl->p_tx_curr_desc_q[queue] = (p_curr_desc))
1277 #define USED_TFD_GET(p_used_desc, queue) \
1278 ((p_used_desc) = p_eth_port_ctrl->p_tx_used_desc_q[queue])
1280 #define USED_TFD_SET(p_used_desc, queue) \
1281 (p_eth_port_ctrl->p_tx_used_desc_q[queue] = (p_used_desc))
1283 #define FIRST_TFD_GET(p_first_desc, queue) \
1284 ((p_first_desc) = p_eth_port_ctrl->p_tx_first_desc_q[queue])
1286 #define FIRST_TFD_SET(p_first_desc, queue) \
1287 (p_eth_port_ctrl->p_tx_first_desc_q[queue] = (p_first_desc))
1290 /* Macros that save access to desc in order to find next desc pointer */
1291 #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])
1293 #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])
1295 #define LINK_UP_TIMEOUT 100000
1296 #define PHY_BUSY_TIMEOUT 10000000
1301 static void ethernet_phy_set (ETH_PORT eth_port_num, int phy_addr);
1302 static int ethernet_phy_get (ETH_PORT eth_port_num);
1304 /* Ethernet Port routines */
1305 static void eth_set_access_control (ETH_PORT eth_port_num,
1306 ETH_WIN_PARAM * param);
1307 static bool eth_port_uc_addr (ETH_PORT eth_port_num, unsigned char uc_nibble,
1308 ETH_QUEUE queue, int option);
1310 static bool eth_port_smc_addr (ETH_PORT eth_port_num,
1311 unsigned char mc_byte,
1312 ETH_QUEUE queue, int option);
1313 static bool eth_port_omc_addr (ETH_PORT eth_port_num,
1315 ETH_QUEUE queue, int option);
1318 static void eth_b_copy (unsigned int src_addr, unsigned int dst_addr,
1321 void eth_dbg (ETH_PORT_INFO * p_eth_port_ctrl);
1324 typedef enum _memory_bank { BANK0, BANK1, BANK2, BANK3 } MEMORY_BANK;
1325 u32 mv_get_dram_bank_base_addr (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_BASE_ADDR);
1335 result = MV_REG_READ (MV64460_CS_1_BASE_ADDR);
1337 result = MV_REG_READ (MV64460_CS_2_BASE_ADDR);
1339 result = MV_REG_READ (MV64460_CS_3_BASE_ADDR);
1340 result &= 0x0000ffff;
1341 result = result << 16;
1345 u32 mv_get_dram_bank_size (MEMORY_BANK bank)
1348 u32 enable = MV_REG_READ (MV64460_BASE_ADDR_ENABLE);
1350 if (enable & (1 << bank))
1353 result = MV_REG_READ (MV64460_CS_0_SIZE);
1355 result = MV_REG_READ (MV64460_CS_1_SIZE);
1357 result = MV_REG_READ (MV64460_CS_2_SIZE);
1359 result = MV_REG_READ (MV64460_CS_3_SIZE);
1361 result &= 0x0000ffff;
1362 result = result << 16;
1366 u32 mv_get_internal_sram_base (void)
1370 result = MV_REG_READ (MV64460_INTEGRATED_SRAM_BASE_ADDR);
1371 result &= 0x0000ffff;
1372 result = result << 16;
1376 /*******************************************************************************
1377 * eth_port_init - Initialize the Ethernet port driver
1380 * This function prepares the ethernet port to start its activity:
1381 * 1) Completes the ethernet port driver struct initialization toward port
1383 * 2) Resets the device to a quiescent state in case of warm reboot.
1384 * 3) Enable SDMA access to all four DRAM banks as well as internal SRAM.
1385 * 4) Clean MAC tables. The reset status of those tables is unknown.
1386 * 5) Set PHY address.
1387 * Note: Call this routine prior to eth_port_start routine and after setting
1388 * user values in the user fields of Ethernet port control struct (i.e.
1392 * ETH_PORT_INFO *p_eth_port_ctrl Ethernet port control struct
1400 *******************************************************************************/
1401 static void eth_port_init (ETH_PORT_INFO * p_eth_port_ctrl)
1404 ETH_WIN_PARAM win_param;
1406 p_eth_port_ctrl->port_config = PORT_CONFIG_VALUE;
1407 p_eth_port_ctrl->port_config_extend = PORT_CONFIG_EXTEND_VALUE;
1408 p_eth_port_ctrl->port_sdma_config = PORT_SDMA_CONFIG_VALUE;
1409 p_eth_port_ctrl->port_serial_control = PORT_SERIAL_CONTROL_VALUE;
1411 p_eth_port_ctrl->port_rx_queue_command = 0;
1412 p_eth_port_ctrl->port_tx_queue_command = 0;
1414 /* Zero out SW structs */
1415 for (queue = 0; queue < MAX_RX_QUEUE_NUM; queue++) {
1416 CURR_RFD_SET ((ETH_RX_DESC *) 0x00000000, queue);
1417 USED_RFD_SET ((ETH_RX_DESC *) 0x00000000, queue);
1418 p_eth_port_ctrl->rx_resource_err[queue] = false;
1421 for (queue = 0; queue < MAX_TX_QUEUE_NUM; queue++) {
1422 CURR_TFD_SET ((ETH_TX_DESC *) 0x00000000, queue);
1423 USED_TFD_SET ((ETH_TX_DESC *) 0x00000000, queue);
1424 FIRST_TFD_SET ((ETH_TX_DESC *) 0x00000000, queue);
1425 p_eth_port_ctrl->tx_resource_err[queue] = false;
1428 eth_port_reset (p_eth_port_ctrl->port_num);
1430 /* Set access parameters for DRAM bank 0 */
1431 win_param.win = ETH_WIN0; /* Use Ethernet window 0 */
1432 win_param.target = ETH_TARGET_DRAM; /* Window target - DDR */
1433 win_param.attributes = EBAR_ATTR_DRAM_CS0; /* 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 (BANK0);
1440 win_param.size = mv_get_dram_bank_size (BANK0); /* 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 1 */
1451 win_param.win = ETH_WIN1; /* Use Ethernet window 1 */
1452 win_param.target = ETH_TARGET_DRAM; /* Window target - DDR */
1453 win_param.attributes = EBAR_ATTR_DRAM_CS1; /* 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 (BANK1);
1460 win_param.size = mv_get_dram_bank_size (BANK1); /* 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 2 */
1471 win_param.win = ETH_WIN2; /* Use Ethernet window 2 */
1472 win_param.target = ETH_TARGET_DRAM; /* Window target - DDR */
1473 win_param.attributes = EBAR_ATTR_DRAM_CS2; /* 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 (BANK2);
1480 win_param.size = mv_get_dram_bank_size (BANK2); /* 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 DRAM bank 3 */
1491 win_param.win = ETH_WIN3; /* Use Ethernet window 3 */
1492 win_param.target = ETH_TARGET_DRAM; /* Window target - DDR */
1493 win_param.attributes = EBAR_ATTR_DRAM_CS3; /* Enable DRAM bank */
1494 #ifndef CONFIG_NOT_COHERENT_CACHE
1495 win_param.attributes |= EBAR_ATTR_DRAM_CACHE_COHERENCY_WB;
1497 win_param.high_addr = 0;
1499 win_param.base_addr = mv_get_dram_bank_base_addr (BANK3);
1500 win_param.size = mv_get_dram_bank_size (BANK3); /* Get bank size */
1501 if (win_param.size == 0)
1502 win_param.enable = 0;
1504 win_param.enable = 1; /* Enable the access */
1505 win_param.access_ctrl = EWIN_ACCESS_FULL; /* Enable full access */
1507 /* Set the access control for address window (EPAPR) READ & WRITE */
1508 eth_set_access_control (p_eth_port_ctrl->port_num, &win_param);
1510 /* Set access parameters for Internal SRAM */
1511 win_param.win = ETH_WIN4; /* Use Ethernet window 0 */
1512 win_param.target = EBAR_TARGET_CBS; /* Target - Internal SRAM */
1513 win_param.attributes = EBAR_ATTR_CBS_SRAM | EBAR_ATTR_CBS_SRAM_BLOCK0;
1514 win_param.high_addr = 0;
1515 win_param.base_addr = mv_get_internal_sram_base (); /* Get base addr */
1516 win_param.size = MV64460_INTERNAL_SRAM_SIZE; /* Get bank size */
1517 win_param.enable = 1; /* Enable the access */
1518 win_param.access_ctrl = EWIN_ACCESS_FULL; /* Enable full access */
1520 /* Set the access control for address window (EPAPR) READ & WRITE */
1521 eth_set_access_control (p_eth_port_ctrl->port_num, &win_param);
1523 eth_port_init_mac_tables (p_eth_port_ctrl->port_num);
1525 ethernet_phy_set (p_eth_port_ctrl->port_num,
1526 p_eth_port_ctrl->port_phy_addr);
1532 /*******************************************************************************
1533 * eth_port_start - Start the Ethernet port activity.
1536 * This routine prepares the Ethernet port for Rx and Tx activity:
1537 * 1. Initialize Tx and Rx Current Descriptor Pointer for each queue that
1538 * has been initialized a descriptor's ring (using ether_init_tx_desc_ring
1539 * for Tx and ether_init_rx_desc_ring for Rx)
1540 * 2. Initialize and enable the Ethernet configuration port by writing to
1541 * the port's configuration and command registers.
1542 * 3. Initialize and enable the SDMA by writing to the SDMA's
1543 * configuration and command registers.
1544 * After completing these steps, the ethernet port SDMA can starts to
1545 * perform Rx and Tx activities.
1547 * Note: Each Rx and Tx queue descriptor's list must be initialized prior
1548 * to calling this function (use ether_init_tx_desc_ring for Tx queues and
1549 * ether_init_rx_desc_ring for Rx queues).
1552 * ETH_PORT_INFO *p_eth_port_ctrl Ethernet port control struct
1555 * Ethernet port is ready to receive and transmit.
1558 * false if the port PHY is not up.
1561 *******************************************************************************/
1562 static bool eth_port_start (ETH_PORT_INFO * p_eth_port_ctrl)
1565 volatile ETH_TX_DESC *p_tx_curr_desc;
1566 volatile ETH_RX_DESC *p_rx_curr_desc;
1567 unsigned int phy_reg_data;
1568 ETH_PORT eth_port_num = p_eth_port_ctrl->port_num;
1571 /* Assignment of Tx CTRP of given queue */
1572 for (queue = 0; queue < MAX_TX_QUEUE_NUM; queue++) {
1573 CURR_TFD_GET (p_tx_curr_desc, queue);
1574 MV_REG_WRITE ((MV64460_ETH_TX_CURRENT_QUEUE_DESC_PTR_0
1577 ((unsigned int) p_tx_curr_desc));
1581 /* Assignment of Rx CRDP of given queue */
1582 for (queue = 0; queue < MAX_RX_QUEUE_NUM; queue++) {
1583 CURR_RFD_GET (p_rx_curr_desc, queue);
1584 MV_REG_WRITE ((MV64460_ETH_RX_CURRENT_QUEUE_DESC_PTR_0
1587 ((unsigned int) p_rx_curr_desc));
1589 if (p_rx_curr_desc != NULL)
1590 /* Add the assigned Ethernet address to the port's address table */
1591 eth_port_uc_addr_set (p_eth_port_ctrl->port_num,
1592 p_eth_port_ctrl->port_mac_addr,
1596 /* Assign port configuration and command. */
1597 MV_REG_WRITE (MV64460_ETH_PORT_CONFIG_REG (eth_port_num),
1598 p_eth_port_ctrl->port_config);
1600 MV_REG_WRITE (MV64460_ETH_PORT_CONFIG_EXTEND_REG (eth_port_num),
1601 p_eth_port_ctrl->port_config_extend);
1603 MV_REG_WRITE (MV64460_ETH_PORT_SERIAL_CONTROL_REG (eth_port_num),
1604 p_eth_port_ctrl->port_serial_control);
1606 MV_SET_REG_BITS (MV64460_ETH_PORT_SERIAL_CONTROL_REG (eth_port_num),
1607 ETH_SERIAL_PORT_ENABLE);
1609 /* Assign port SDMA configuration */
1610 MV_REG_WRITE (MV64460_ETH_SDMA_CONFIG_REG (eth_port_num),
1611 p_eth_port_ctrl->port_sdma_config);
1613 MV_REG_WRITE (MV64460_ETH_TX_QUEUE_0_TOKEN_BUCKET_COUNT
1614 (eth_port_num), 0x3fffffff);
1615 MV_REG_WRITE (MV64460_ETH_TX_QUEUE_0_TOKEN_BUCKET_CONFIG
1616 (eth_port_num), 0x03fffcff);
1617 /* Turn off the port/queue bandwidth limitation */
1618 MV_REG_WRITE (MV64460_ETH_MAXIMUM_TRANSMIT_UNIT (eth_port_num), 0x0);
1620 /* Enable port Rx. */
1621 MV_REG_WRITE (MV64460_ETH_RECEIVE_QUEUE_COMMAND_REG (eth_port_num),
1622 p_eth_port_ctrl->port_rx_queue_command);
1624 /* Check if link is up */
1625 eth_port_read_smi_reg (eth_port_num, 1, &phy_reg_data);
1627 if (!(phy_reg_data & 0x20))
1633 /*******************************************************************************
1634 * eth_port_uc_addr_set - This function Set the port Unicast address.
1637 * This function Set the port Ethernet MAC address.
1640 * ETH_PORT eth_port_num Port number.
1641 * char * p_addr Address to be set
1642 * ETH_QUEUE queue Rx queue number for this MAC address.
1645 * Set MAC address low and high registers. also calls eth_port_uc_addr()
1646 * To set the unicast table with the proper information.
1651 *******************************************************************************/
1652 static void eth_port_uc_addr_set (ETH_PORT eth_port_num,
1653 unsigned char *p_addr, ETH_QUEUE queue)
1658 mac_l = (p_addr[4] << 8) | (p_addr[5]);
1659 mac_h = (p_addr[0] << 24) | (p_addr[1] << 16) |
1660 (p_addr[2] << 8) | (p_addr[3] << 0);
1662 MV_REG_WRITE (MV64460_ETH_MAC_ADDR_LOW (eth_port_num), mac_l);
1663 MV_REG_WRITE (MV64460_ETH_MAC_ADDR_HIGH (eth_port_num), mac_h);
1665 /* Accept frames of this address */
1666 eth_port_uc_addr (eth_port_num, p_addr[5], queue, ACCEPT_MAC_ADDR);
1671 /*******************************************************************************
1672 * eth_port_uc_addr - This function Set the port unicast address table
1675 * This function locates the proper entry in the Unicast table for the
1676 * specified MAC nibble and sets its properties according to function
1680 * ETH_PORT eth_port_num Port number.
1681 * unsigned char uc_nibble Unicast MAC Address last nibble.
1682 * ETH_QUEUE queue Rx queue number for this MAC address.
1683 * int option 0 = Add, 1 = remove address.
1686 * This function add/removes MAC addresses from the port unicast address
1690 * true is output succeeded.
1691 * false if option parameter is invalid.
1693 *******************************************************************************/
1694 static bool eth_port_uc_addr (ETH_PORT eth_port_num,
1695 unsigned char uc_nibble,
1696 ETH_QUEUE queue, int option)
1698 unsigned int unicast_reg;
1699 unsigned int tbl_offset;
1700 unsigned int reg_offset;
1702 /* Locate the Unicast table entry */
1703 uc_nibble = (0xf & uc_nibble);
1704 tbl_offset = (uc_nibble / 4) * 4; /* Register offset from unicast table base */
1705 reg_offset = uc_nibble % 4; /* Entry offset within the above register */
1708 case REJECT_MAC_ADDR:
1709 /* Clear accepts frame bit at specified unicast DA table entry */
1711 MV_REG_READ ((MV64460_ETH_DA_FILTER_UNICAST_TABLE_BASE
1715 unicast_reg &= (0x0E << (8 * reg_offset));
1717 MV_REG_WRITE ((MV64460_ETH_DA_FILTER_UNICAST_TABLE_BASE
1719 + tbl_offset), unicast_reg);
1722 case ACCEPT_MAC_ADDR:
1723 /* Set accepts frame bit at unicast DA filter table entry */
1725 MV_REG_READ ((MV64460_ETH_DA_FILTER_UNICAST_TABLE_BASE
1729 unicast_reg |= ((0x01 | queue) << (8 * reg_offset));
1731 MV_REG_WRITE ((MV64460_ETH_DA_FILTER_UNICAST_TABLE_BASE
1733 + tbl_offset), unicast_reg);
1744 /*******************************************************************************
1745 * eth_port_mc_addr - Multicast address settings.
1748 * This API controls the MV device MAC multicast support.
1749 * The MV device supports multicast using two tables:
1750 * 1) Special Multicast Table for MAC addresses of the form
1751 * 0x01-00-5E-00-00-XX (where XX is between 0x00 and 0x_fF).
1752 * The MAC DA[7:0] bits are used as a pointer to the Special Multicast
1753 * Table entries in the DA-Filter table.
1754 * In this case, the function calls eth_port_smc_addr() routine to set the
1755 * Special Multicast Table.
1756 * 2) Other Multicast Table for multicast of another type. A CRC-8bit
1757 * is used as an index to the Other Multicast Table entries in the
1759 * In this case, the function calculates the CRC-8bit value and calls
1760 * eth_port_omc_addr() routine to set the Other Multicast Table.
1762 * ETH_PORT eth_port_num Port number.
1763 * unsigned char *p_addr Unicast MAC Address.
1764 * ETH_QUEUE queue Rx queue number for this MAC address.
1765 * int option 0 = Add, 1 = remove address.
1771 * true is output succeeded.
1772 * false if add_address_table_entry( ) failed.
1774 *******************************************************************************/
1775 static void eth_port_mc_addr (ETH_PORT eth_port_num,
1776 unsigned char *p_addr,
1777 ETH_QUEUE queue, int option)
1781 unsigned char crc_result = 0;
1787 if ((p_addr[0] == 0x01) &&
1788 (p_addr[1] == 0x00) &&
1789 (p_addr[2] == 0x5E) && (p_addr[3] == 0x00) && (p_addr[4] == 0x00))
1791 eth_port_smc_addr (eth_port_num, p_addr[5], queue, option);
1793 /* Calculate CRC-8 out of the given address */
1794 mac_h = (p_addr[0] << 8) | (p_addr[1]);
1795 mac_l = (p_addr[2] << 24) | (p_addr[3] << 16) |
1796 (p_addr[4] << 8) | (p_addr[5] << 0);
1798 for (i = 0; i < 32; i++)
1799 mac_array[i] = (mac_l >> i) & 0x1;
1800 for (i = 32; i < 48; i++)
1801 mac_array[i] = (mac_h >> (i - 32)) & 0x1;
1804 crc[0] = mac_array[45] ^ mac_array[43] ^ mac_array[40] ^
1805 mac_array[39] ^ mac_array[35] ^ mac_array[34] ^
1806 mac_array[31] ^ mac_array[30] ^ mac_array[28] ^
1807 mac_array[23] ^ mac_array[21] ^ mac_array[19] ^
1808 mac_array[18] ^ mac_array[16] ^ mac_array[14] ^
1809 mac_array[12] ^ mac_array[8] ^ mac_array[7] ^
1810 mac_array[6] ^ mac_array[0];
1812 crc[1] = mac_array[46] ^ mac_array[45] ^ mac_array[44] ^
1813 mac_array[43] ^ mac_array[41] ^ mac_array[39] ^
1814 mac_array[36] ^ mac_array[34] ^ mac_array[32] ^
1815 mac_array[30] ^ mac_array[29] ^ mac_array[28] ^
1816 mac_array[24] ^ mac_array[23] ^ mac_array[22] ^
1817 mac_array[21] ^ mac_array[20] ^ mac_array[18] ^
1818 mac_array[17] ^ mac_array[16] ^ mac_array[15] ^
1819 mac_array[14] ^ mac_array[13] ^ mac_array[12] ^
1820 mac_array[9] ^ mac_array[6] ^ mac_array[1] ^
1823 crc[2] = mac_array[47] ^ mac_array[46] ^ mac_array[44] ^
1824 mac_array[43] ^ mac_array[42] ^ mac_array[39] ^
1825 mac_array[37] ^ mac_array[34] ^ mac_array[33] ^
1826 mac_array[29] ^ mac_array[28] ^ mac_array[25] ^
1827 mac_array[24] ^ mac_array[22] ^ mac_array[17] ^
1828 mac_array[15] ^ mac_array[13] ^ mac_array[12] ^
1829 mac_array[10] ^ mac_array[8] ^ mac_array[6] ^
1830 mac_array[2] ^ mac_array[1] ^ mac_array[0];
1832 crc[3] = mac_array[47] ^ mac_array[45] ^ mac_array[44] ^
1833 mac_array[43] ^ mac_array[40] ^ mac_array[38] ^
1834 mac_array[35] ^ mac_array[34] ^ mac_array[30] ^
1835 mac_array[29] ^ mac_array[26] ^ mac_array[25] ^
1836 mac_array[23] ^ mac_array[18] ^ mac_array[16] ^
1837 mac_array[14] ^ mac_array[13] ^ mac_array[11] ^
1838 mac_array[9] ^ mac_array[7] ^ mac_array[3] ^
1839 mac_array[2] ^ mac_array[1];
1841 crc[4] = mac_array[46] ^ mac_array[45] ^ mac_array[44] ^
1842 mac_array[41] ^ mac_array[39] ^ mac_array[36] ^
1843 mac_array[35] ^ mac_array[31] ^ mac_array[30] ^
1844 mac_array[27] ^ mac_array[26] ^ mac_array[24] ^
1845 mac_array[19] ^ mac_array[17] ^ mac_array[15] ^
1846 mac_array[14] ^ mac_array[12] ^ mac_array[10] ^
1847 mac_array[8] ^ mac_array[4] ^ mac_array[3] ^
1850 crc[5] = mac_array[47] ^ mac_array[46] ^ mac_array[45] ^
1851 mac_array[42] ^ mac_array[40] ^ mac_array[37] ^
1852 mac_array[36] ^ mac_array[32] ^ mac_array[31] ^
1853 mac_array[28] ^ mac_array[27] ^ mac_array[25] ^
1854 mac_array[20] ^ mac_array[18] ^ mac_array[16] ^
1855 mac_array[15] ^ mac_array[13] ^ mac_array[11] ^
1856 mac_array[9] ^ mac_array[5] ^ mac_array[4] ^
1859 crc[6] = mac_array[47] ^ mac_array[46] ^ mac_array[43] ^
1860 mac_array[41] ^ mac_array[38] ^ mac_array[37] ^
1861 mac_array[33] ^ mac_array[32] ^ mac_array[29] ^
1862 mac_array[28] ^ mac_array[26] ^ mac_array[21] ^
1863 mac_array[19] ^ mac_array[17] ^ mac_array[16] ^
1864 mac_array[14] ^ mac_array[12] ^ mac_array[10] ^
1865 mac_array[6] ^ mac_array[5] ^ mac_array[4];
1867 crc[7] = mac_array[47] ^ mac_array[44] ^ mac_array[42] ^
1868 mac_array[39] ^ mac_array[38] ^ mac_array[34] ^
1869 mac_array[33] ^ mac_array[30] ^ mac_array[29] ^
1870 mac_array[27] ^ mac_array[22] ^ mac_array[20] ^
1871 mac_array[18] ^ mac_array[17] ^ mac_array[15] ^
1872 mac_array[13] ^ mac_array[11] ^ mac_array[7] ^
1873 mac_array[6] ^ mac_array[5];
1875 for (i = 0; i < 8; i++)
1876 crc_result = crc_result | (crc[i] << i);
1878 eth_port_omc_addr (eth_port_num, crc_result, queue, option);
1883 /*******************************************************************************
1884 * eth_port_smc_addr - Special Multicast address settings.
1887 * This routine controls the MV device special MAC multicast support.
1888 * The Special Multicast Table for MAC addresses supports MAC of the form
1889 * 0x01-00-5E-00-00-XX (where XX is between 0x00 and 0x_fF).
1890 * The MAC DA[7:0] bits are used as a pointer to the Special Multicast
1891 * Table entries in the DA-Filter table.
1892 * This function set the Special Multicast Table appropriate entry
1893 * according to the argument given.
1896 * ETH_PORT eth_port_num Port number.
1897 * unsigned char mc_byte Multicast addr last byte (MAC DA[7:0] bits).
1898 * ETH_QUEUE queue Rx queue number for this MAC address.
1899 * int option 0 = Add, 1 = remove address.
1905 * true is output succeeded.
1906 * false if option parameter is invalid.
1908 *******************************************************************************/
1909 static bool eth_port_smc_addr (ETH_PORT eth_port_num,
1910 unsigned char mc_byte,
1911 ETH_QUEUE queue, int option)
1913 unsigned int smc_table_reg;
1914 unsigned int tbl_offset;
1915 unsigned int reg_offset;
1917 /* Locate the SMC table entry */
1918 tbl_offset = (mc_byte / 4) * 4; /* Register offset from SMC table base */
1919 reg_offset = mc_byte % 4; /* Entry offset within the above register */
1923 case REJECT_MAC_ADDR:
1924 /* Clear accepts frame bit at specified Special DA table entry */
1926 MV_REG_READ ((MV64460_ETH_DA_FILTER_SPECIAL_MULTICAST_TABLE_BASE (eth_port_num) + tbl_offset));
1927 smc_table_reg &= (0x0E << (8 * reg_offset));
1929 MV_REG_WRITE ((MV64460_ETH_DA_FILTER_SPECIAL_MULTICAST_TABLE_BASE (eth_port_num) + tbl_offset), smc_table_reg);
1932 case ACCEPT_MAC_ADDR:
1933 /* Set accepts frame bit at specified Special DA table entry */
1935 MV_REG_READ ((MV64460_ETH_DA_FILTER_SPECIAL_MULTICAST_TABLE_BASE (eth_port_num) + tbl_offset));
1936 smc_table_reg |= ((0x01 | queue) << (8 * reg_offset));
1938 MV_REG_WRITE ((MV64460_ETH_DA_FILTER_SPECIAL_MULTICAST_TABLE_BASE (eth_port_num) + tbl_offset), smc_table_reg);
1947 /*******************************************************************************
1948 * eth_port_omc_addr - Multicast address settings.
1951 * This routine controls the MV device Other MAC multicast support.
1952 * The Other Multicast Table is used for multicast of another type.
1953 * A CRC-8bit is used as an index to the Other Multicast Table entries
1954 * in the DA-Filter table.
1955 * The function gets the CRC-8bit value from the calling routine and
1956 * set the Other Multicast Table appropriate entry according to the
1957 * CRC-8 argument given.
1960 * ETH_PORT eth_port_num Port number.
1961 * unsigned char crc8 A CRC-8bit (Polynomial: x^8+x^2+x^1+1).
1962 * ETH_QUEUE queue Rx queue number for this MAC address.
1963 * int option 0 = Add, 1 = remove address.
1969 * true is output succeeded.
1970 * false if option parameter is invalid.
1972 *******************************************************************************/
1973 static bool eth_port_omc_addr (ETH_PORT eth_port_num,
1975 ETH_QUEUE queue, int option)
1977 unsigned int omc_table_reg;
1978 unsigned int tbl_offset;
1979 unsigned int reg_offset;
1981 /* Locate the OMC table entry */
1982 tbl_offset = (crc8 / 4) * 4; /* Register offset from OMC table base */
1983 reg_offset = crc8 % 4; /* Entry offset within the above register */
1987 case REJECT_MAC_ADDR:
1988 /* Clear accepts frame bit at specified Other DA table entry */
1990 MV_REG_READ ((MV64460_ETH_DA_FILTER_OTHER_MULTICAST_TABLE_BASE (eth_port_num) + tbl_offset));
1991 omc_table_reg &= (0x0E << (8 * reg_offset));
1993 MV_REG_WRITE ((MV64460_ETH_DA_FILTER_OTHER_MULTICAST_TABLE_BASE (eth_port_num) + tbl_offset), omc_table_reg);
1996 case ACCEPT_MAC_ADDR:
1997 /* Set accepts frame bit at specified Other DA table entry */
1999 MV_REG_READ ((MV64460_ETH_DA_FILTER_OTHER_MULTICAST_TABLE_BASE (eth_port_num) + tbl_offset));
2000 omc_table_reg |= ((0x01 | queue) << (8 * reg_offset));
2002 MV_REG_WRITE ((MV64460_ETH_DA_FILTER_OTHER_MULTICAST_TABLE_BASE (eth_port_num) + tbl_offset), omc_table_reg);
2012 /*******************************************************************************
2013 * eth_port_init_mac_tables - Clear all entrance in the UC, SMC and OMC tables
2016 * Go through all the DA filter tables (Unicast, Special Multicast & Other
2017 * Multicast) and set each entry to 0.
2020 * ETH_PORT eth_port_num Ethernet Port number. See ETH_PORT enum.
2023 * Multicast and Unicast packets are rejected.
2028 *******************************************************************************/
2029 static void eth_port_init_mac_tables (ETH_PORT eth_port_num)
2033 /* Clear DA filter unicast table (Ex_dFUT) */
2034 for (table_index = 0; table_index <= 0xC; table_index += 4)
2035 MV_REG_WRITE ((MV64460_ETH_DA_FILTER_UNICAST_TABLE_BASE
2036 (eth_port_num) + table_index), 0);
2038 for (table_index = 0; table_index <= 0xFC; table_index += 4) {
2039 /* Clear DA filter special multicast table (Ex_dFSMT) */
2040 MV_REG_WRITE ((MV64460_ETH_DA_FILTER_SPECIAL_MULTICAST_TABLE_BASE (eth_port_num) + table_index), 0);
2041 /* Clear DA filter other multicast table (Ex_dFOMT) */
2042 MV_REG_WRITE ((MV64460_ETH_DA_FILTER_OTHER_MULTICAST_TABLE_BASE (eth_port_num) + table_index), 0);
2046 /*******************************************************************************
2047 * eth_clear_mib_counters - Clear all MIB counters
2050 * This function clears all MIB counters of a specific ethernet port.
2051 * A read from the MIB counter will reset the counter.
2054 * ETH_PORT eth_port_num Ethernet Port number. See ETH_PORT enum.
2057 * After reading all MIB counters, the counters resets.
2060 * MIB counter value.
2062 *******************************************************************************/
2063 static void eth_clear_mib_counters (ETH_PORT eth_port_num)
2068 /* Perform dummy reads from MIB counters */
2069 for (i = ETH_MIB_GOOD_OCTETS_RECEIVED_LOW; i < ETH_MIB_LATE_COLLISION;
2071 dummy = MV_REG_READ ((MV64460_ETH_MIB_COUNTERS_BASE
2072 (eth_port_num) + i));
2077 /*******************************************************************************
2078 * eth_read_mib_counter - Read a MIB counter
2081 * This function reads a MIB counter of a specific ethernet port.
2082 * NOTE - If read from ETH_MIB_GOOD_OCTETS_RECEIVED_LOW, then the
2083 * following read must be from ETH_MIB_GOOD_OCTETS_RECEIVED_HIGH
2084 * register. The same applies for ETH_MIB_GOOD_OCTETS_SENT_LOW and
2085 * ETH_MIB_GOOD_OCTETS_SENT_HIGH
2088 * ETH_PORT eth_port_num Ethernet Port number. See ETH_PORT enum.
2089 * unsigned int mib_offset MIB counter offset (use ETH_MIB_... macros).
2092 * After reading the MIB counter, the counter resets.
2095 * MIB counter value.
2097 *******************************************************************************/
2098 unsigned int eth_read_mib_counter (ETH_PORT eth_port_num,
2099 unsigned int mib_offset)
2101 return (MV_REG_READ (MV64460_ETH_MIB_COUNTERS_BASE (eth_port_num)
2105 /*******************************************************************************
2106 * ethernet_phy_set - Set the ethernet port PHY address.
2109 * This routine set the ethernet port PHY address according to given
2113 * ETH_PORT eth_port_num Ethernet Port number. See ETH_PORT enum.
2116 * Set PHY Address Register with given PHY address parameter.
2121 *******************************************************************************/
2122 static void ethernet_phy_set (ETH_PORT eth_port_num, int phy_addr)
2124 unsigned int reg_data;
2126 reg_data = MV_REG_READ (MV64460_ETH_PHY_ADDR_REG);
2128 reg_data &= ~(0x1F << (5 * eth_port_num));
2129 reg_data |= (phy_addr << (5 * eth_port_num));
2131 MV_REG_WRITE (MV64460_ETH_PHY_ADDR_REG, reg_data);
2136 /*******************************************************************************
2137 * ethernet_phy_get - Get the ethernet port PHY address.
2140 * This routine returns the given ethernet port PHY address.
2143 * ETH_PORT eth_port_num Ethernet Port number. See ETH_PORT enum.
2151 *******************************************************************************/
2152 static int ethernet_phy_get (ETH_PORT eth_port_num)
2154 unsigned int reg_data;
2156 reg_data = MV_REG_READ (MV64460_ETH_PHY_ADDR_REG);
2158 return ((reg_data >> (5 * eth_port_num)) & 0x1f);
2161 /*******************************************************************************
2162 * ethernet_phy_reset - Reset Ethernet port PHY.
2165 * This routine utilize the SMI interface to reset the ethernet port PHY.
2166 * The routine waits until the link is up again or link up is timeout.
2169 * ETH_PORT eth_port_num Ethernet Port number. See ETH_PORT enum.
2172 * The ethernet port PHY renew its link.
2177 *******************************************************************************/
2178 static bool ethernet_phy_reset (ETH_PORT eth_port_num)
2180 unsigned int time_out = 50;
2181 unsigned int phy_reg_data;
2184 eth_port_read_smi_reg (eth_port_num, 0, &phy_reg_data);
2185 phy_reg_data |= 0x8000; /* Set bit 15 to reset the PHY */
2186 eth_port_write_smi_reg (eth_port_num, 0, phy_reg_data);
2188 /* Poll on the PHY LINK */
2190 eth_port_read_smi_reg (eth_port_num, 1, &phy_reg_data);
2192 if (time_out-- == 0)
2195 while (!(phy_reg_data & 0x20));
2200 /*******************************************************************************
2201 * eth_port_reset - Reset Ethernet port
2204 * This routine resets the chip by aborting any SDMA engine activity and
2205 * clearing the MIB counters. The Receiver and the Transmit unit are in
2206 * idle state after this command is performed and the port is disabled.
2209 * ETH_PORT eth_port_num Ethernet Port number. See ETH_PORT enum.
2212 * Channel activity is halted.
2217 *******************************************************************************/
2218 static void eth_port_reset (ETH_PORT eth_port_num)
2220 unsigned int reg_data;
2222 /* Stop Tx port activity. Check port Tx activity. */
2224 MV_REG_READ (MV64460_ETH_TRANSMIT_QUEUE_COMMAND_REG
2227 if (reg_data & 0xFF) {
2228 /* Issue stop command for active channels only */
2229 MV_REG_WRITE (MV64460_ETH_TRANSMIT_QUEUE_COMMAND_REG
2230 (eth_port_num), (reg_data << 8));
2232 /* Wait for all Tx activity to terminate. */
2234 /* Check port cause register that all Tx queues are stopped */
2237 (MV64460_ETH_TRANSMIT_QUEUE_COMMAND_REG
2240 while (reg_data & 0xFF);
2243 /* Stop Rx port activity. Check port Rx activity. */
2245 MV_REG_READ (MV64460_ETH_RECEIVE_QUEUE_COMMAND_REG
2248 if (reg_data & 0xFF) {
2249 /* Issue stop command for active channels only */
2250 MV_REG_WRITE (MV64460_ETH_RECEIVE_QUEUE_COMMAND_REG
2251 (eth_port_num), (reg_data << 8));
2253 /* Wait for all Rx activity to terminate. */
2255 /* Check port cause register that all Rx queues are stopped */
2258 (MV64460_ETH_RECEIVE_QUEUE_COMMAND_REG
2261 while (reg_data & 0xFF);
2265 /* Clear all MIB counters */
2266 eth_clear_mib_counters (eth_port_num);
2268 /* Reset the Enable bit in the Configuration Register */
2270 MV_REG_READ (MV64460_ETH_PORT_SERIAL_CONTROL_REG
2272 reg_data &= ~ETH_SERIAL_PORT_ENABLE;
2273 MV_REG_WRITE (MV64460_ETH_PORT_SERIAL_CONTROL_REG (eth_port_num),
2279 #if 0 /* Not needed here */
2280 /*******************************************************************************
2281 * ethernet_set_config_reg - Set specified bits in configuration register.
2284 * This function sets specified bits in the given ethernet
2285 * configuration register.
2288 * ETH_PORT eth_port_num Ethernet Port number. See ETH_PORT enum.
2289 * unsigned int value 32 bit value.
2292 * The set bits in the value parameter are set in the configuration
2298 *******************************************************************************/
2299 static void ethernet_set_config_reg (ETH_PORT eth_port_num,
2302 unsigned int eth_config_reg;
2305 MV_REG_READ (MV64460_ETH_PORT_CONFIG_REG (eth_port_num));
2306 eth_config_reg |= value;
2307 MV_REG_WRITE (MV64460_ETH_PORT_CONFIG_REG (eth_port_num),
2315 /*******************************************************************************
2316 * ethernet_reset_config_reg - Reset specified bits in configuration register.
2319 * This function resets specified bits in the given Ethernet
2320 * configuration register.
2323 * ETH_PORT eth_port_num Ethernet Port number. See ETH_PORT enum.
2324 * unsigned int value 32 bit value.
2327 * The set bits in the value parameter are reset in the configuration
2333 *******************************************************************************/
2334 static void ethernet_reset_config_reg (ETH_PORT eth_port_num,
2337 unsigned int eth_config_reg;
2339 eth_config_reg = MV_REG_READ (MV64460_ETH_PORT_CONFIG_EXTEND_REG
2341 eth_config_reg &= ~value;
2342 MV_REG_WRITE (MV64460_ETH_PORT_CONFIG_EXTEND_REG (eth_port_num),
2349 #if 0 /* Not needed here */
2350 /*******************************************************************************
2351 * ethernet_get_config_reg - Get the port configuration register
2354 * This function returns the configuration register value of the given
2358 * ETH_PORT eth_port_num Ethernet Port number. See ETH_PORT enum.
2364 * Port configuration register value.
2366 *******************************************************************************/
2367 static unsigned int ethernet_get_config_reg (ETH_PORT eth_port_num)
2369 unsigned int eth_config_reg;
2371 eth_config_reg = MV_REG_READ (MV64460_ETH_PORT_CONFIG_EXTEND_REG
2373 return eth_config_reg;
2378 /*******************************************************************************
2379 * eth_port_read_smi_reg - Read PHY registers
2382 * This routine utilize the SMI interface to interact with the PHY in
2383 * order to perform PHY register read.
2386 * ETH_PORT eth_port_num Ethernet Port number. See ETH_PORT enum.
2387 * unsigned int phy_reg PHY register address offset.
2388 * unsigned int *value Register value buffer.
2391 * Write the value of a specified PHY register into given buffer.
2394 * false if the PHY is busy or read data is not in valid state.
2397 *******************************************************************************/
2398 static bool eth_port_read_smi_reg (ETH_PORT eth_port_num,
2399 unsigned int phy_reg, unsigned int *value)
2401 unsigned int reg_value;
2402 unsigned int time_out = PHY_BUSY_TIMEOUT;
2405 phy_addr = ethernet_phy_get (eth_port_num);
2406 /* printf(" Phy-Port %d has addess %d \n",eth_port_num, phy_addr );*/
2408 /* first check that it is not busy */
2410 reg_value = MV_REG_READ (MV64460_ETH_SMI_REG);
2411 if (time_out-- == 0) {
2415 while (reg_value & ETH_SMI_BUSY);
2419 MV_REG_WRITE (MV64460_ETH_SMI_REG,
2420 (phy_addr << 16) | (phy_reg << 21) |
2421 ETH_SMI_OPCODE_READ);
2423 time_out = PHY_BUSY_TIMEOUT; /* initialize the time out var again */
2426 reg_value = MV_REG_READ (MV64460_ETH_SMI_REG);
2427 if (time_out-- == 0) {
2431 while ((reg_value & ETH_SMI_READ_VALID) != ETH_SMI_READ_VALID); /* Bit set equ operation done */
2433 /* Wait for the data to update in the SMI register */
2434 #define PHY_UPDATE_TIMEOUT 10000
2435 for (time_out = 0; time_out < PHY_UPDATE_TIMEOUT; time_out++);
2437 reg_value = MV_REG_READ (MV64460_ETH_SMI_REG);
2439 *value = reg_value & 0xffff;
2444 /*******************************************************************************
2445 * eth_port_write_smi_reg - Write to PHY registers
2448 * This routine utilize the SMI interface to interact with the PHY in
2449 * order to perform writes to PHY registers.
2452 * ETH_PORT eth_port_num Ethernet Port number. See ETH_PORT enum.
2453 * unsigned int phy_reg PHY register address offset.
2454 * unsigned int value Register value.
2457 * Write the given value to the specified PHY register.
2460 * false if the PHY is busy.
2463 *******************************************************************************/
2464 static bool eth_port_write_smi_reg (ETH_PORT eth_port_num,
2465 unsigned int phy_reg, unsigned int value)
2467 unsigned int reg_value;
2468 unsigned int time_out = PHY_BUSY_TIMEOUT;
2471 phy_addr = ethernet_phy_get (eth_port_num);
2473 /* first check that it is not busy */
2475 reg_value = MV_REG_READ (MV64460_ETH_SMI_REG);
2476 if (time_out-- == 0) {
2480 while (reg_value & ETH_SMI_BUSY);
2483 MV_REG_WRITE (MV64460_ETH_SMI_REG,
2484 (phy_addr << 16) | (phy_reg << 21) |
2485 ETH_SMI_OPCODE_WRITE | (value & 0xffff));
2489 /*******************************************************************************
2490 * eth_set_access_control - Config address decode parameters for Ethernet unit
2493 * This function configures the address decode parameters for the Gigabit
2494 * Ethernet Controller according the given parameters struct.
2497 * ETH_PORT eth_port_num Ethernet Port number. See ETH_PORT enum.
2498 * ETH_WIN_PARAM *param Address decode parameter struct.
2501 * An access window is opened using the given access parameters.
2506 *******************************************************************************/
2507 static void eth_set_access_control (ETH_PORT eth_port_num,
2508 ETH_WIN_PARAM * param)
2510 unsigned int access_prot_reg;
2512 /* Set access control register */
2513 access_prot_reg = MV_REG_READ (MV64460_ETH_ACCESS_PROTECTION_REG
2515 access_prot_reg &= (~(3 << (param->win * 2))); /* clear window permission */
2516 access_prot_reg |= (param->access_ctrl << (param->win * 2));
2517 MV_REG_WRITE (MV64460_ETH_ACCESS_PROTECTION_REG (eth_port_num),
2520 /* Set window Size reg (SR) */
2521 MV_REG_WRITE ((MV64460_ETH_SIZE_REG_0 +
2522 (ETH_SIZE_REG_GAP * param->win)),
2523 (((param->size / 0x10000) - 1) << 16));
2525 /* Set window Base address reg (BA) */
2526 MV_REG_WRITE ((MV64460_ETH_BAR_0 + (ETH_BAR_GAP * param->win)),
2527 (param->target | param->attributes | param->base_addr));
2528 /* High address remap reg (HARR) */
2530 MV_REG_WRITE ((MV64460_ETH_HIGH_ADDR_REMAP_REG_0 +
2531 (ETH_HIGH_ADDR_REMAP_REG_GAP * param->win)),
2534 /* Base address enable reg (BARER) */
2535 if (param->enable == 1)
2536 MV_RESET_REG_BITS (MV64460_ETH_BASE_ADDR_ENABLE_REG,
2539 MV_SET_REG_BITS (MV64460_ETH_BASE_ADDR_ENABLE_REG,
2543 /*******************************************************************************
2544 * ether_init_rx_desc_ring - Curve a Rx chain desc list and buffer in memory.
2547 * This function prepares a Rx chained list of descriptors and packet
2548 * buffers in a form of a ring. The routine must be called after port
2549 * initialization routine and before port start routine.
2550 * The Ethernet SDMA engine uses CPU bus addresses to access the various
2551 * devices in the system (i.e. DRAM). This function uses the ethernet
2552 * struct 'virtual to physical' routine (set by the user) to set the ring
2553 * with physical addresses.
2556 * ETH_PORT_INFO *p_eth_port_ctrl Ethernet Port Control srtuct.
2557 * ETH_QUEUE rx_queue Number of Rx queue.
2558 * int rx_desc_num Number of Rx descriptors
2559 * int rx_buff_size Size of Rx buffer
2560 * unsigned int rx_desc_base_addr Rx descriptors memory area base addr.
2561 * unsigned int rx_buff_base_addr Rx buffer memory area base addr.
2564 * The routine updates the Ethernet port control struct with information
2565 * regarding the Rx descriptors and buffers.
2568 * false if the given descriptors memory area is not aligned according to
2569 * Ethernet SDMA specifications.
2572 *******************************************************************************/
2573 static bool ether_init_rx_desc_ring (ETH_PORT_INFO * p_eth_port_ctrl,
2577 unsigned int rx_desc_base_addr,
2578 unsigned int rx_buff_base_addr)
2580 ETH_RX_DESC *p_rx_desc;
2581 ETH_RX_DESC *p_rx_prev_desc; /* pointer to link with the last descriptor */
2582 unsigned int buffer_addr;
2583 int ix; /* a counter */
2586 p_rx_desc = (ETH_RX_DESC *) rx_desc_base_addr;
2587 p_rx_prev_desc = p_rx_desc;
2588 buffer_addr = rx_buff_base_addr;
2590 /* Rx desc Must be 4LW aligned (i.e. Descriptor_Address[3:0]=0000). */
2591 if (rx_buff_base_addr & 0xF)
2594 /* Rx buffers are limited to 64K bytes and Minimum size is 8 bytes */
2595 if ((rx_buff_size < 8) || (rx_buff_size > RX_BUFFER_MAX_SIZE))
2598 /* Rx buffers must be 64-bit aligned. */
2599 if ((rx_buff_base_addr + rx_buff_size) & 0x7)
2602 /* initialize the Rx descriptors ring */
2603 for (ix = 0; ix < rx_desc_num; ix++) {
2604 p_rx_desc->buf_size = rx_buff_size;
2605 p_rx_desc->byte_cnt = 0x0000;
2606 p_rx_desc->cmd_sts =
2607 ETH_BUFFER_OWNED_BY_DMA | ETH_RX_ENABLE_INTERRUPT;
2608 p_rx_desc->next_desc_ptr =
2609 ((unsigned int) p_rx_desc) + RX_DESC_ALIGNED_SIZE;
2610 p_rx_desc->buf_ptr = buffer_addr;
2611 p_rx_desc->return_info = 0x00000000;
2612 D_CACHE_FLUSH_LINE (p_rx_desc, 0);
2613 buffer_addr += rx_buff_size;
2614 p_rx_prev_desc = p_rx_desc;
2615 p_rx_desc = (ETH_RX_DESC *)
2616 ((unsigned int) p_rx_desc + RX_DESC_ALIGNED_SIZE);
2619 /* Closing Rx descriptors ring */
2620 p_rx_prev_desc->next_desc_ptr = (rx_desc_base_addr);
2621 D_CACHE_FLUSH_LINE (p_rx_prev_desc, 0);
2623 /* Save Rx desc pointer to driver struct. */
2624 CURR_RFD_SET ((ETH_RX_DESC *) rx_desc_base_addr, rx_queue);
2625 USED_RFD_SET ((ETH_RX_DESC *) rx_desc_base_addr, rx_queue);
2627 p_eth_port_ctrl->p_rx_desc_area_base[rx_queue] =
2628 (ETH_RX_DESC *) rx_desc_base_addr;
2629 p_eth_port_ctrl->rx_desc_area_size[rx_queue] =
2630 rx_desc_num * RX_DESC_ALIGNED_SIZE;
2632 p_eth_port_ctrl->port_rx_queue_command |= (1 << rx_queue);
2637 /*******************************************************************************
2638 * ether_init_tx_desc_ring - Curve a Tx chain desc list and buffer in memory.
2641 * This function prepares a Tx chained list of descriptors and packet
2642 * buffers in a form of a ring. The routine must be called after port
2643 * initialization routine and before port start routine.
2644 * The Ethernet SDMA engine uses CPU bus addresses to access the various
2645 * devices in the system (i.e. DRAM). This function uses the ethernet
2646 * struct 'virtual to physical' routine (set by the user) to set the ring
2647 * with physical addresses.
2650 * ETH_PORT_INFO *p_eth_port_ctrl Ethernet Port Control srtuct.
2651 * ETH_QUEUE tx_queue Number of Tx queue.
2652 * int tx_desc_num Number of Tx descriptors
2653 * int tx_buff_size Size of Tx buffer
2654 * unsigned int tx_desc_base_addr Tx descriptors memory area base addr.
2655 * unsigned int tx_buff_base_addr Tx buffer memory area base addr.
2658 * The routine updates the Ethernet port control struct with information
2659 * regarding the Tx descriptors and buffers.
2662 * false if the given descriptors memory area is not aligned according to
2663 * Ethernet SDMA specifications.
2666 *******************************************************************************/
2667 static bool ether_init_tx_desc_ring (ETH_PORT_INFO * p_eth_port_ctrl,
2671 unsigned int tx_desc_base_addr,
2672 unsigned int tx_buff_base_addr)
2675 ETH_TX_DESC *p_tx_desc;
2676 ETH_TX_DESC *p_tx_prev_desc;
2677 unsigned int buffer_addr;
2678 int ix; /* a counter */
2681 /* save the first desc pointer to link with the last descriptor */
2682 p_tx_desc = (ETH_TX_DESC *) tx_desc_base_addr;
2683 p_tx_prev_desc = p_tx_desc;
2684 buffer_addr = tx_buff_base_addr;
2686 /* Tx desc Must be 4LW aligned (i.e. Descriptor_Address[3:0]=0000). */
2687 if (tx_buff_base_addr & 0xF)
2690 /* Tx buffers are limited to 64K bytes and Minimum size is 8 bytes */
2691 if ((tx_buff_size > TX_BUFFER_MAX_SIZE)
2692 || (tx_buff_size < TX_BUFFER_MIN_SIZE))
2695 /* Initialize the Tx descriptors ring */
2696 for (ix = 0; ix < tx_desc_num; ix++) {
2697 p_tx_desc->byte_cnt = 0x0000;
2698 p_tx_desc->l4i_chk = 0x0000;
2699 p_tx_desc->cmd_sts = 0x00000000;
2700 p_tx_desc->next_desc_ptr =
2701 ((unsigned int) p_tx_desc) + TX_DESC_ALIGNED_SIZE;
2703 p_tx_desc->buf_ptr = buffer_addr;
2704 p_tx_desc->return_info = 0x00000000;
2705 D_CACHE_FLUSH_LINE (p_tx_desc, 0);
2706 buffer_addr += tx_buff_size;
2707 p_tx_prev_desc = p_tx_desc;
2708 p_tx_desc = (ETH_TX_DESC *)
2709 ((unsigned int) p_tx_desc + TX_DESC_ALIGNED_SIZE);
2712 /* Closing Tx descriptors ring */
2713 p_tx_prev_desc->next_desc_ptr = tx_desc_base_addr;
2714 D_CACHE_FLUSH_LINE (p_tx_prev_desc, 0);
2715 /* Set Tx desc pointer in driver struct. */
2716 CURR_TFD_SET ((ETH_TX_DESC *) tx_desc_base_addr, tx_queue);
2717 USED_TFD_SET ((ETH_TX_DESC *) tx_desc_base_addr, tx_queue);
2719 /* Init Tx ring base and size parameters */
2720 p_eth_port_ctrl->p_tx_desc_area_base[tx_queue] =
2721 (ETH_TX_DESC *) tx_desc_base_addr;
2722 p_eth_port_ctrl->tx_desc_area_size[tx_queue] =
2723 (tx_desc_num * TX_DESC_ALIGNED_SIZE);
2725 /* Add the queue to the list of Tx queues of this port */
2726 p_eth_port_ctrl->port_tx_queue_command |= (1 << tx_queue);
2731 /*******************************************************************************
2732 * eth_port_send - Send an Ethernet packet
2735 * This routine send a given packet described by p_pktinfo parameter. It
2736 * supports transmitting of a packet spaned over multiple buffers. The
2737 * routine updates 'curr' and 'first' indexes according to the packet
2738 * segment passed to the routine. In case the packet segment is first,
2739 * the 'first' index is update. In any case, the 'curr' index is updated.
2740 * If the routine get into Tx resource error it assigns 'curr' index as
2741 * 'first'. This way the function can abort Tx process of multiple
2742 * descriptors per packet.
2745 * ETH_PORT_INFO *p_eth_port_ctrl Ethernet Port Control srtuct.
2746 * ETH_QUEUE tx_queue Number of Tx queue.
2747 * PKT_INFO *p_pkt_info User packet buffer.
2750 * Tx ring 'curr' and 'first' indexes are updated.
2753 * ETH_QUEUE_FULL in case of Tx resource error.
2754 * ETH_ERROR in case the routine can not access Tx desc ring.
2755 * ETH_QUEUE_LAST_RESOURCE if the routine uses the last Tx resource.
2758 *******************************************************************************/
2759 static ETH_FUNC_RET_STATUS eth_port_send (ETH_PORT_INFO * p_eth_port_ctrl,
2761 PKT_INFO * p_pkt_info)
2763 volatile ETH_TX_DESC *p_tx_desc_first;
2764 volatile ETH_TX_DESC *p_tx_desc_curr;
2765 volatile ETH_TX_DESC *p_tx_next_desc_curr;
2766 volatile ETH_TX_DESC *p_tx_desc_used;
2767 unsigned int command_status;
2769 /* Do not process Tx ring in case of Tx ring resource error */
2770 if (p_eth_port_ctrl->tx_resource_err[tx_queue] == true)
2771 return ETH_QUEUE_FULL;
2773 /* Get the Tx Desc ring indexes */
2774 CURR_TFD_GET (p_tx_desc_curr, tx_queue);
2775 USED_TFD_GET (p_tx_desc_used, tx_queue);
2777 if (p_tx_desc_curr == NULL)
2780 /* The following parameters are used to save readings from memory */
2781 p_tx_next_desc_curr = TX_NEXT_DESC_PTR (p_tx_desc_curr, tx_queue);
2782 command_status = p_pkt_info->cmd_sts | ETH_ZERO_PADDING | ETH_GEN_CRC;
2784 if (command_status & (ETH_TX_FIRST_DESC)) {
2785 /* Update first desc */
2786 FIRST_TFD_SET (p_tx_desc_curr, tx_queue);
2787 p_tx_desc_first = p_tx_desc_curr;
2789 FIRST_TFD_GET (p_tx_desc_first, tx_queue);
2790 command_status |= ETH_BUFFER_OWNED_BY_DMA;
2793 /* Buffers with a payload smaller than 8 bytes must be aligned to 64-bit */
2794 /* boundary. We use the memory allocated for Tx descriptor. This memory */
2795 /* located in TX_BUF_OFFSET_IN_DESC offset within the Tx descriptor. */
2796 if (p_pkt_info->byte_cnt <= 8) {
2797 printf ("You have failed in the < 8 bytes errata - fixme\n"); /* RABEEH - TBD */
2800 p_tx_desc_curr->buf_ptr =
2801 (unsigned int) p_tx_desc_curr + TX_BUF_OFFSET_IN_DESC;
2802 eth_b_copy (p_pkt_info->buf_ptr, p_tx_desc_curr->buf_ptr,
2803 p_pkt_info->byte_cnt);
2805 p_tx_desc_curr->buf_ptr = p_pkt_info->buf_ptr;
2807 p_tx_desc_curr->byte_cnt = p_pkt_info->byte_cnt;
2808 p_tx_desc_curr->return_info = p_pkt_info->return_info;
2810 if (p_pkt_info->cmd_sts & (ETH_TX_LAST_DESC)) {
2811 /* Set last desc with DMA ownership and interrupt enable. */
2812 p_tx_desc_curr->cmd_sts = command_status |
2813 ETH_BUFFER_OWNED_BY_DMA | ETH_TX_ENABLE_INTERRUPT;
2815 if (p_tx_desc_curr != p_tx_desc_first)
2816 p_tx_desc_first->cmd_sts |= ETH_BUFFER_OWNED_BY_DMA;
2818 /* Flush CPU pipe */
2820 D_CACHE_FLUSH_LINE ((unsigned int) p_tx_desc_curr, 0);
2821 D_CACHE_FLUSH_LINE ((unsigned int) p_tx_desc_first, 0);
2824 /* Apply send command */
2825 ETH_ENABLE_TX_QUEUE (tx_queue, p_eth_port_ctrl->port_num);
2827 /* Finish Tx packet. Update first desc in case of Tx resource error */
2828 p_tx_desc_first = p_tx_next_desc_curr;
2829 FIRST_TFD_SET (p_tx_desc_first, tx_queue);
2832 p_tx_desc_curr->cmd_sts = command_status;
2833 D_CACHE_FLUSH_LINE ((unsigned int) p_tx_desc_curr, 0);
2836 /* Check for ring index overlap in the Tx desc ring */
2837 if (p_tx_next_desc_curr == p_tx_desc_used) {
2838 /* Update the current descriptor */
2839 CURR_TFD_SET (p_tx_desc_first, tx_queue);
2841 p_eth_port_ctrl->tx_resource_err[tx_queue] = true;
2842 return ETH_QUEUE_LAST_RESOURCE;
2844 /* Update the current descriptor */
2845 CURR_TFD_SET (p_tx_next_desc_curr, tx_queue);
2850 /*******************************************************************************
2851 * eth_tx_return_desc - Free all used Tx descriptors
2854 * This routine returns the transmitted packet information to the caller.
2855 * It uses the 'first' index to support Tx desc return in case a transmit
2856 * of a packet spanned over multiple buffer still in process.
2857 * In case the Tx queue was in "resource error" condition, where there are
2858 * no available Tx resources, the function resets the resource error flag.
2861 * ETH_PORT_INFO *p_eth_port_ctrl Ethernet Port Control srtuct.
2862 * ETH_QUEUE tx_queue Number of Tx queue.
2863 * PKT_INFO *p_pkt_info User packet buffer.
2866 * Tx ring 'first' and 'used' indexes are updated.
2869 * ETH_ERROR in case the routine can not access Tx desc ring.
2870 * ETH_RETRY in case there is transmission in process.
2871 * ETH_END_OF_JOB if the routine has nothing to release.
2874 *******************************************************************************/
2875 static ETH_FUNC_RET_STATUS eth_tx_return_desc (ETH_PORT_INFO *
2878 PKT_INFO * p_pkt_info)
2880 volatile ETH_TX_DESC *p_tx_desc_used = NULL;
2881 volatile ETH_TX_DESC *p_tx_desc_first = NULL;
2882 unsigned int command_status;
2885 /* Get the Tx Desc ring indexes */
2886 USED_TFD_GET (p_tx_desc_used, tx_queue);
2887 FIRST_TFD_GET (p_tx_desc_first, tx_queue);
2891 if (p_tx_desc_used == NULL)
2894 command_status = p_tx_desc_used->cmd_sts;
2896 /* Still transmitting... */
2897 if (command_status & (ETH_BUFFER_OWNED_BY_DMA)) {
2898 D_CACHE_FLUSH_LINE ((unsigned int) p_tx_desc_used, 0);
2902 /* Stop release. About to overlap the current available Tx descriptor */
2903 if ((p_tx_desc_used == p_tx_desc_first) &&
2904 (p_eth_port_ctrl->tx_resource_err[tx_queue] == false)) {
2905 D_CACHE_FLUSH_LINE ((unsigned int) p_tx_desc_used, 0);
2906 return ETH_END_OF_JOB;
2909 /* Pass the packet information to the caller */
2910 p_pkt_info->cmd_sts = command_status;
2911 p_pkt_info->return_info = p_tx_desc_used->return_info;
2912 p_tx_desc_used->return_info = 0;
2914 /* Update the next descriptor to release. */
2915 USED_TFD_SET (TX_NEXT_DESC_PTR (p_tx_desc_used, tx_queue), tx_queue);
2917 /* Any Tx return cancels the Tx resource error status */
2918 if (p_eth_port_ctrl->tx_resource_err[tx_queue] == true)
2919 p_eth_port_ctrl->tx_resource_err[tx_queue] = false;
2921 D_CACHE_FLUSH_LINE ((unsigned int) p_tx_desc_used, 0);
2927 /*******************************************************************************
2928 * eth_port_receive - Get received information from Rx ring.
2931 * This routine returns the received data to the caller. There is no
2932 * data copying during routine operation. All information is returned
2933 * using pointer to packet information struct passed from the caller.
2934 * If the routine exhausts Rx ring resources then the resource error flag
2938 * ETH_PORT_INFO *p_eth_port_ctrl Ethernet Port Control srtuct.
2939 * ETH_QUEUE rx_queue Number of Rx queue.
2940 * PKT_INFO *p_pkt_info User packet buffer.
2943 * Rx ring current and used indexes are updated.
2946 * ETH_ERROR in case the routine can not access Rx desc ring.
2947 * ETH_QUEUE_FULL if Rx ring resources are exhausted.
2948 * ETH_END_OF_JOB if there is no received data.
2951 *******************************************************************************/
2952 static ETH_FUNC_RET_STATUS eth_port_receive (ETH_PORT_INFO * p_eth_port_ctrl,
2954 PKT_INFO * p_pkt_info)
2956 volatile ETH_RX_DESC *p_rx_curr_desc;
2957 volatile ETH_RX_DESC *p_rx_next_curr_desc;
2958 volatile ETH_RX_DESC *p_rx_used_desc;
2959 unsigned int command_status;
2961 /* Do not process Rx ring in case of Rx ring resource error */
2962 if (p_eth_port_ctrl->rx_resource_err[rx_queue] == true) {
2963 printf ("\nRx Queue is full ...\n");
2964 return ETH_QUEUE_FULL;
2967 /* Get the Rx Desc ring 'curr and 'used' indexes */
2968 CURR_RFD_GET (p_rx_curr_desc, rx_queue);
2969 USED_RFD_GET (p_rx_used_desc, rx_queue);
2972 if (p_rx_curr_desc == NULL)
2975 /* The following parameters are used to save readings from memory */
2976 p_rx_next_curr_desc = RX_NEXT_DESC_PTR (p_rx_curr_desc, rx_queue);
2977 command_status = p_rx_curr_desc->cmd_sts;
2979 /* Nothing to receive... */
2980 if (command_status & (ETH_BUFFER_OWNED_BY_DMA)) {
2981 /* DP(printf("Rx: command_status: %08x\n", command_status)); */
2982 D_CACHE_FLUSH_LINE ((unsigned int) p_rx_curr_desc, 0);
2983 /* DP(printf("\nETH_END_OF_JOB ...\n"));*/
2984 return ETH_END_OF_JOB;
2987 p_pkt_info->byte_cnt = (p_rx_curr_desc->byte_cnt) - RX_BUF_OFFSET;
2988 p_pkt_info->cmd_sts = command_status;
2989 p_pkt_info->buf_ptr = (p_rx_curr_desc->buf_ptr) + RX_BUF_OFFSET;
2990 p_pkt_info->return_info = p_rx_curr_desc->return_info;
2991 p_pkt_info->l4i_chk = p_rx_curr_desc->buf_size; /* IP fragment indicator */
2993 /* Clean the return info field to indicate that the packet has been */
2994 /* moved to the upper layers */
2995 p_rx_curr_desc->return_info = 0;
2997 /* Update 'curr' in data structure */
2998 CURR_RFD_SET (p_rx_next_curr_desc, rx_queue);
3000 /* Rx descriptors resource exhausted. Set the Rx ring resource error flag */
3001 if (p_rx_next_curr_desc == p_rx_used_desc)
3002 p_eth_port_ctrl->rx_resource_err[rx_queue] = true;
3004 D_CACHE_FLUSH_LINE ((unsigned int) p_rx_curr_desc, 0);
3009 /*******************************************************************************
3010 * eth_rx_return_buff - Returns a Rx buffer back to the Rx ring.
3013 * This routine returns a Rx buffer back to the Rx ring. It retrieves the
3014 * next 'used' descriptor and attached the returned buffer to it.
3015 * In case the Rx ring was in "resource error" condition, where there are
3016 * no available Rx resources, the function resets the resource error flag.
3019 * ETH_PORT_INFO *p_eth_port_ctrl Ethernet Port Control srtuct.
3020 * ETH_QUEUE rx_queue Number of Rx queue.
3021 * PKT_INFO *p_pkt_info Information on the returned buffer.
3024 * New available Rx resource in Rx descriptor ring.
3027 * ETH_ERROR in case the routine can not access Rx desc ring.
3030 *******************************************************************************/
3031 static ETH_FUNC_RET_STATUS eth_rx_return_buff (ETH_PORT_INFO *
3034 PKT_INFO * p_pkt_info)
3036 volatile ETH_RX_DESC *p_used_rx_desc; /* Where to return Rx resource */
3038 /* Get 'used' Rx descriptor */
3039 USED_RFD_GET (p_used_rx_desc, rx_queue);
3042 if (p_used_rx_desc == NULL)
3045 p_used_rx_desc->buf_ptr = p_pkt_info->buf_ptr;
3046 p_used_rx_desc->return_info = p_pkt_info->return_info;
3047 p_used_rx_desc->byte_cnt = p_pkt_info->byte_cnt;
3048 p_used_rx_desc->buf_size = MV64460_RX_BUFFER_SIZE; /* Reset Buffer size */
3050 /* Flush the write pipe */
3053 /* Return the descriptor to DMA ownership */
3054 p_used_rx_desc->cmd_sts =
3055 ETH_BUFFER_OWNED_BY_DMA | ETH_RX_ENABLE_INTERRUPT;
3057 /* Flush descriptor and CPU pipe */
3058 D_CACHE_FLUSH_LINE ((unsigned int) p_used_rx_desc, 0);
3061 /* Move the used descriptor pointer to the next descriptor */
3062 USED_RFD_SET (RX_NEXT_DESC_PTR (p_used_rx_desc, rx_queue), rx_queue);
3064 /* Any Rx return cancels the Rx resource error status */
3065 if (p_eth_port_ctrl->rx_resource_err[rx_queue] == true)
3066 p_eth_port_ctrl->rx_resource_err[rx_queue] = false;
3071 /*******************************************************************************
3072 * eth_port_set_rx_coal - Sets coalescing interrupt mechanism on RX path
3075 * This routine sets the RX coalescing interrupt mechanism parameter.
3076 * This parameter is a timeout counter, that counts in 64 t_clk
3077 * chunks ; that when timeout event occurs a maskable interrupt
3079 * The parameter is calculated using the tClk of the MV-643xx chip
3080 * , and the required delay of the interrupt in usec.
3083 * ETH_PORT eth_port_num Ethernet port number
3084 * unsigned int t_clk t_clk of the MV-643xx chip in HZ units
3085 * unsigned int delay Delay in usec
3088 * Interrupt coalescing mechanism value is set in MV-643xx chip.
3091 * The interrupt coalescing value set in the gigE port.
3093 *******************************************************************************/
3095 static unsigned int eth_port_set_rx_coal (ETH_PORT eth_port_num,
3101 coal = ((t_clk / 1000000) * delay) / 64;
3102 /* Set RX Coalescing mechanism */
3103 MV_REG_WRITE (MV64460_ETH_SDMA_CONFIG_REG (eth_port_num),
3104 ((coal & 0x3fff) << 8) |
3106 (MV64460_ETH_SDMA_CONFIG_REG (eth_port_num))
3112 /*******************************************************************************
3113 * eth_port_set_tx_coal - Sets coalescing interrupt mechanism on TX path
3116 * This routine sets the TX coalescing interrupt mechanism parameter.
3117 * This parameter is a timeout counter, that counts in 64 t_clk
3118 * chunks ; that when timeout event occurs a maskable interrupt
3120 * The parameter is calculated using the t_cLK frequency of the
3121 * MV-643xx chip and the required delay in the interrupt in uSec
3124 * ETH_PORT eth_port_num Ethernet port number
3125 * unsigned int t_clk t_clk of the MV-643xx chip in HZ units
3126 * unsigned int delay Delay in uSeconds
3129 * Interrupt coalescing mechanism value is set in MV-643xx chip.
3132 * The interrupt coalescing value set in the gigE port.
3134 *******************************************************************************/
3136 static unsigned int eth_port_set_tx_coal (ETH_PORT eth_port_num,
3142 coal = ((t_clk / 1000000) * delay) / 64;
3143 /* Set TX Coalescing mechanism */
3144 MV_REG_WRITE (MV64460_ETH_TX_FIFO_URGENT_THRESHOLD_REG (eth_port_num),
3150 /*******************************************************************************
3151 * eth_b_copy - Copy bytes from source to destination
3154 * This function supports the eight bytes limitation on Tx buffer size.
3155 * The routine will zero eight bytes starting from the destination address
3156 * followed by copying bytes from the source address to the destination.
3159 * unsigned int src_addr 32 bit source address.
3160 * unsigned int dst_addr 32 bit destination address.
3161 * int byte_count Number of bytes to copy.
3169 *******************************************************************************/
3170 static void eth_b_copy (unsigned int src_addr, unsigned int dst_addr,
3173 /* Zero the dst_addr area */
3174 *(unsigned int *) dst_addr = 0x0;
3176 while (byte_count != 0) {
3177 *(char *) dst_addr = *(char *) src_addr;