📄 mv_eth.c
字号:
}/********************************************************************** * mv64460_eth_start_xmit * * This function is queues a packet in the Tx descriptor for * required port. * * Input : skb - a pointer to socket buffer * dev - a pointer to the required port * * Output : zero upon success **********************************************************************/int mv64460_eth_xmit (struct eth_device *dev, volatile void *dataPtr, int dataSize){ ETH_PORT_INFO *ethernet_private; struct mv64460_eth_priv *port_private; unsigned int port_num; PKT_INFO pkt_info; ETH_FUNC_RET_STATUS status; struct net_device_stats *stats; ETH_FUNC_RET_STATUS release_result; ethernet_private = (ETH_PORT_INFO *) dev->priv; port_private = (struct mv64460_eth_priv *) ethernet_private->port_private; port_num = port_private->port_num; stats = port_private->stats; /* Update packet info data structure */ pkt_info.cmd_sts = ETH_TX_FIRST_DESC | ETH_TX_LAST_DESC; /* DMA owned, first last */ pkt_info.byte_cnt = dataSize; pkt_info.buf_ptr = (unsigned int) dataPtr; pkt_info.return_info = 0; status = eth_port_send (ethernet_private, ETH_Q0, &pkt_info); if ((status == ETH_ERROR) || (status == ETH_QUEUE_FULL)) { printf ("Error on transmitting packet .."); if (status == ETH_QUEUE_FULL) printf ("ETH Queue is full. \n"); if (status == ETH_QUEUE_LAST_RESOURCE) printf ("ETH Queue: using last available resource. \n"); return 1; } /* Update statistics and start of transmittion time */ stats->tx_bytes += dataSize; stats->tx_packets++; /* Check if packet(s) is(are) transmitted correctly (release everything) */ do { release_result = eth_tx_return_desc (ethernet_private, ETH_Q0, &pkt_info); switch (release_result) { case ETH_OK: DP (printf ("descriptor released\n")); if (pkt_info.cmd_sts & BIT0) { printf ("Error in TX\n"); stats->tx_errors++; } break; case ETH_RETRY: DP (printf ("transmission still in process\n")); break; case ETH_ERROR: printf ("routine can not access Tx desc ring\n"); break; case ETH_END_OF_JOB: DP (printf ("the routine has nothing to release\n")); break; default: /* should not happen */ break; } } while (release_result == ETH_OK); return 0; /* success */}/********************************************************************** * mv64460_eth_receive * * This function is forward packets that are received from the port's * queues toward kernel core or FastRoute them to another interface. * * Input : dev - a pointer to the required interface * max - maximum number to receive (0 means unlimted) * * Output : number of served packets **********************************************************************/int mv64460_eth_receive (struct eth_device *dev){ ETH_PORT_INFO *ethernet_private; struct mv64460_eth_priv *port_private; unsigned int port_num; PKT_INFO pkt_info; struct net_device_stats *stats; ethernet_private = (ETH_PORT_INFO *) dev->priv; port_private = (struct mv64460_eth_priv *) ethernet_private->port_private; port_num = port_private->port_num; stats = port_private->stats; while ((eth_port_receive (ethernet_private, ETH_Q0, &pkt_info) == ETH_OK)) {#ifdef DEBUG_MV_ETH if (pkt_info.byte_cnt != 0) { printf ("%s: Received %d byte Packet @ 0x%x\n", __FUNCTION__, pkt_info.byte_cnt, pkt_info.buf_ptr); if(pkt_info.buf_ptr != 0){ for(i=0; i < pkt_info.byte_cnt; i++){ if((i % 4) == 0){ printf("\n0x"); } printf("%02x", ((char*)pkt_info.buf_ptr)[i]); } printf("\n"); } }#endif /* Update statistics. Note byte count includes 4 byte CRC count */ stats->rx_packets++; stats->rx_bytes += pkt_info.byte_cnt; /* * In case received a packet without first / last bits on OR the error * summary bit is on, the packets needs to be dropeed. */ if (((pkt_info. cmd_sts & (ETH_RX_FIRST_DESC | ETH_RX_LAST_DESC)) != (ETH_RX_FIRST_DESC | ETH_RX_LAST_DESC)) || (pkt_info.cmd_sts & ETH_ERROR_SUMMARY)) { stats->rx_dropped++; printf ("Received packet spread on multiple descriptors\n"); /* Is this caused by an error ? */ if (pkt_info.cmd_sts & ETH_ERROR_SUMMARY) { stats->rx_errors++; } /* free these descriptors again without forwarding them to the higher layers */ pkt_info.buf_ptr &= ~0x7; /* realign buffer again */ pkt_info.byte_cnt = 0x0000; /* Reset Byte count */ if (eth_rx_return_buff (ethernet_private, ETH_Q0, &pkt_info) != ETH_OK) { printf ("Error while returning the RX Desc to Ring\n"); } else { DP (printf ("RX Desc returned to Ring\n")); } /* /free these descriptors again */ } else {/* !!! call higher layer processing */#ifdef DEBUG_MV_ETH printf ("\nNow send it to upper layer protocols (NetReceive) ...\n");#endif /* let the upper layer handle the packet */ NetReceive ((uchar *) pkt_info.buf_ptr, (int) pkt_info.byte_cnt);/* **************************************************************** *//* free descriptor */ pkt_info.buf_ptr &= ~0x7; /* realign buffer again */ pkt_info.byte_cnt = 0x0000; /* Reset Byte count */ DP (printf ("RX: pkt_info.buf_ptr = %x\n", pkt_info.buf_ptr)); if (eth_rx_return_buff (ethernet_private, ETH_Q0, &pkt_info) != ETH_OK) { printf ("Error while returning the RX Desc to Ring\n"); } else { DP (printf ("RX: Desc returned to Ring\n")); }/* **************************************************************** */ } } mv64460_eth_get_stats (dev); /* update statistics */ return 1;}/********************************************************************** * mv64460_eth_get_stats * * Returns a pointer to the interface statistics. * * Input : dev - a pointer to the required interface * * Output : a pointer to the interface's statistics **********************************************************************/static struct net_device_stats *mv64460_eth_get_stats (struct eth_device *dev){ ETH_PORT_INFO *ethernet_private; struct mv64460_eth_priv *port_private; unsigned int port_num; ethernet_private = (ETH_PORT_INFO *) dev->priv; port_private = (struct mv64460_eth_priv *) ethernet_private->port_private; port_num = port_private->port_num; mv64460_eth_update_stat (dev); return port_private->stats;}/********************************************************************** * mv64460_eth_update_stat * * Update the statistics structure in the private data structure * * Input : pointer to ethernet interface network device structure * Output : N/A **********************************************************************/static void mv64460_eth_update_stat (struct eth_device *dev){ ETH_PORT_INFO *ethernet_private; struct mv64460_eth_priv *port_private; struct net_device_stats *stats; unsigned int port_num; volatile unsigned int dummy; ethernet_private = (ETH_PORT_INFO *) dev->priv; port_private = (struct mv64460_eth_priv *) ethernet_private->port_private; port_num = port_private->port_num; stats = port_private->stats; /* These are false updates */ stats->rx_packets += (unsigned long) eth_read_mib_counter (ethernet_private->port_num, ETH_MIB_GOOD_FRAMES_RECEIVED); stats->tx_packets += (unsigned long) eth_read_mib_counter (ethernet_private->port_num, ETH_MIB_GOOD_FRAMES_SENT); stats->rx_bytes += (unsigned long) eth_read_mib_counter (ethernet_private->port_num, ETH_MIB_GOOD_OCTETS_RECEIVED_LOW); /* * Ideally this should be as follows - * * stats->rx_bytes += stats->rx_bytes + * ((unsigned long) ethReadMibCounter (ethernet_private->port_num , * ETH_MIB_GOOD_OCTETS_RECEIVED_HIGH) << 32); * * But the unsigned long in PowerPC and MIPS are 32bit. So the next read * is just a dummy read for proper work of the GigE port */ dummy = eth_read_mib_counter (ethernet_private->port_num, ETH_MIB_GOOD_OCTETS_RECEIVED_HIGH); stats->tx_bytes += (unsigned long) eth_read_mib_counter (ethernet_private->port_num, ETH_MIB_GOOD_OCTETS_SENT_LOW); dummy = eth_read_mib_counter (ethernet_private->port_num, ETH_MIB_GOOD_OCTETS_SENT_HIGH); stats->rx_errors += (unsigned long) eth_read_mib_counter (ethernet_private->port_num, ETH_MIB_MAC_RECEIVE_ERROR); /* Rx dropped is for received packet with CRC error */ stats->rx_dropped += (unsigned long) eth_read_mib_counter (ethernet_private-> port_num, ETH_MIB_BAD_CRC_EVENT); stats->multicast += (unsigned long) eth_read_mib_counter (ethernet_private->port_num, ETH_MIB_MULTICAST_FRAMES_RECEIVED); stats->collisions += (unsigned long) eth_read_mib_counter (ethernet_private-> port_num, ETH_MIB_COLLISION) + (unsigned long) eth_read_mib_counter (ethernet_private-> port_num, ETH_MIB_LATE_COLLISION); /* detailed rx errors */ stats->rx_length_errors += (unsigned long) eth_read_mib_counter (ethernet_private-> port_num, ETH_MIB_UNDERSIZE_RECEIVED) + (unsigned long) eth_read_mib_counter (ethernet_private-> port_num, ETH_MIB_OVERSIZE_RECEIVED); /* detailed tx errors */}#ifndef UPDATE_STATS_BY_SOFTWARE/********************************************************************** * mv64460_eth_print_stat * * Update the statistics structure in the private data structure * * Input : pointer to ethernet interface network device structure * Output : N/A **********************************************************************/static void mv64460_eth_print_stat (struct eth_device *dev){ ETH_PORT_INFO *ethernet_private; struct mv64460_eth_priv *port_private; struct net_device_stats *stats; unsigned int port_num; ethernet_private = (ETH_PORT_INFO *) dev->priv; port_private = (struct mv64460_eth_priv *) ethernet_private->port_private; port_num = port_private->port_num; stats = port_private->stats; /* These are false updates */ printf ("\n### Network statistics: ###\n"); printf ("--------------------------\n"); printf (" Packets received: %ld\n", stats->rx_packets); printf (" Packets send: %ld\n", stats->tx_packets); printf (" Received bytes: %ld\n", stats->rx_bytes); printf (" Send bytes: %ld\n", stats->tx_bytes); if (stats->rx_errors != 0) printf (" Rx Errors: %ld\n", stats->rx_errors); if (stats->rx_dropped != 0) printf (" Rx dropped (CRC Errors): %ld\n", stats->rx_dropped); if (stats->multicast != 0) printf (" Rx mulicast frames: %ld\n", stats->multicast); if (stats->collisions != 0) printf (" No. of collisions: %ld\n", stats->collisions); if (stats->rx_length_errors != 0) printf (" Rx length errors: %ld\n", stats->rx_length_errors);}#endif/************************************************************************** *network_start - Network Kick Off Routine UBoot *Inputs : *Outputs : **************************************************************************/bool db64460_eth_start (struct eth_device *dev){ return (mv64460_eth_open (dev)); /* calls real open */}/****************************************************************************************************************************************************************************************************************************** The second part is the low level driver of the gigE ethernet ports. ******************************************************************************************************************************************************************************************************************************//* * based on Linux code * arch/ppc/galileo/EVB64460/mv64460_eth.c - Driver for MV64460X ethernet ports * Copyright (C) 2002 rabeeh@galileo.co.il * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * *//******************************************************************************** * Marvell's Gigabit Ethernet controller low level driver * * DESCRIPTION: * This file introduce low level API to Marvell's Gigabit Ethernet * controller. This Gigabit Ethernet Controller driver API controls
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -