ethernet driver changes for net+os v5.1. design changes resides in bsp\devices\ethernet directory....
TRANSCRIPT
Ethernet Driver Changes
for NET+OS V5.1
Design Changes
• Resides in bsp\devices\ethernet directory.
• Source code broken into more C files.
• Native driver code is separated from the TCP/IP stack and the operating system.
• Global variables are combined in one structure.
• Added a transmit task.
Hardware related Changes
• Added support for NS7520 chip.
• Added transmitter lockup detection and reset.
• The driver supports multiple receive DMA channels.
• Mii.c identifies PHY address dynamically.
• Both MAC and EFE run in half-duplex.
Driver Header Files
• h\efe_def.h - Ethernet driver public API, and statistics
• bsp\mii.h - MII public API
• In bsp\devices\ethernet directory:
• eth.h - Internal Ethernet definitions
Driver C Files
• eth_init.c - Initialization routines
• eth_reset.c - Hardware initialization
• eth_dma.c - DMA related routines
• eth_isr.c - Interrupt service routines
• eth_mcast.c - Multicast routines
Driver C Files
• eth_recv.c - Receive task and related routines
• eth_send.c - Transmit task and related routines
• eth_watchdog.c – Code to reset receiver and transmitter lockups
Driver C Files
• eth_os.c - Code dependant on the OS eth_stack.c - Code dependant on the
TCP/IP stack
• mii.c - MII routines
NS7520 Support
• NS7520 has a different MAC.
• Ethernet register addresses and layout have changed.
• Most of the chip revision support is in eth_reset.c and mii.c.
Transmitter Lockup Reset
• Reset function - eth_reset_tx
• The eth_tx_complete in the transmit thread detects the lockup condition.
• Lockup condition - transmit complete interrupt has not cleared the Full bit in the DMA buffer descriptor.
Half – Duplex operation
• Full duplex for EFE causes transmit under-runs, which cause transmitter lockups.
• MAC and EFE duplex is set to the same value.
• ETH_NEGOTIATE_100MB_FULLD is defined to 0 is mii.h.
Other MII changes
• MII tries to identify PHY on different addresses.
• After reading the status, mii.c clears the status bit in the MII Command Register, because NS7520 hardware does not do it.
Multiple receive DMA channels
#define ETH_RX_CHANNELS 1#define ETH_MAX_RXA_DESCRIPTORS 64#define ETH_MAX_RXB_DESCRIPTORS 1#define ETH_MAX_RXC_DESCRIPTORS 1#define ETH_MAX_RXD_DESCRIPTORS 1
Change ETH_RX_CHANNELS and number of buffer descriptors for channels B, C, and D to run more than one receive channel.
Multiple receive DMA channels
#define ETH_MAX_PACKET_LENGTH 1518
#define ETH_RX_PACKET_SIZEA 64
#define ETH_RX_PACKET_SIZEB 128
#define ETH_RX_PACKET_SIZEC 256
#define ETH_RX_PACKET_SIZED ETH_MAX_PACKET_LENGTH
• Last DMA channel always receives maximum size packets.
• BSP is compiled to use 1 receive DMA channel
DMA Buffer Descriptors
• They are made global for debug purposes.
• DMA buffer descriptors are defined in eth_dma.c.
• / * Transmit DMA Buffer descriptor ring */fb_buffer_desc_t
eth_tx_buffer_descriptors[ETH_MAX_TX_DESCRIPTORS];
DMA Buffer Descriptors
/ * Receive DMA Buffer descriptors rings for channels A, B, C, and D */
fb_buffer_desc_t eth_rxa_buffer_descriptors[ETH_MAX_RXA_DESCRIPTORS];
• fb_buffer_desc_t eth_rxb_buffer_descriptors[ETH_MAX_RXB_DESCRIPTORS];
• fb_buffer_desc_t eth_rxc_buffer_descriptors[ETH_MAX_RXC_DESCRIPTORS];
• fb_buffer_desc_t eth_rxd_buffer_descriptors[ETH_MAX_RXD_DESCRIPTORS];
DMA Buffer Descriptors
/* Array Pointers to Receive DMA Buffer descriptor rings for channels A, B, C, and D */
fb_buffer_desc_t *eth_rx_buffer_descriptors[] = • {• eth_rxa_buffer_descriptors, • eth_rxb_buffer_descriptors, • eth_rxc_buffer_descriptors, • eth_rxd_buffer_descriptors• };
Sending Packets
• Packets are transmitted from application threads and the Ethernet transmit thread.
• TCP/IP stack owns device transmit queues.
• TCP/IP stack calls driver’s transmit routines in critical section.
Transmit Task
• Transmit DMA ISR wakes up the transmit thread.
• The transmit thread calls eth_restart in a loop.
• eth_restart calls a stack function to free the transmitted packet, and send the next queued packet.
eth.h
• eth.h explains what definitions are BSP configurable.
• eth.h defines ethData structure.
• Driver modules use and a global pointer: ethData *eth_datap.
• typedef struct • { • void *pnetdev; /* pointer to TCP/IP stack device data */• unsigned int min_packet_len; /* minimum packet length */• unsigned int max_packet_len[ETH_RX_CHANNELS]; /*minimum packet length*/• char state; /* drive state */• char efe_mii_100; /* 1 = 100Mb, 0 = 10 Mb */• char mac_fulld; /* MAC is running full duplex */• char efe_fulld; /* EFE is running full duplex */• char pna_mode; /* TRUE = pNa mode is set */• char loopback; /* loopback mode */• char rx_reset_in_progress; /* receiver reset in progress */
int rx_bd_index[ETH_RX_CHANNELS]; /* Receive DMA software index */
• int tx_bd_head; /* Transmit DMA head index */
• int tx_bd_tail; /* Transmit DMA tail index */• char mac_addr[ETH_MAC_ADDR_SIZE]; /* MAC adddress */• ethFunction recv_task; /* receive task function pointer */• ethFunction xmit_task; /* transmit task function pointer */• ethFunction watchdog; /* watchdog function pointer */
• } ethData;
eth_os.c
• eth_init_os_services allocates memory and creates threads, timers, event flags, etc. without starting them.
• eth_start_os_services starts threads, timers. eth_stop_os_services stops threads, timers.
• eth_task_wake wakes up a driver thread.• eth_task_sleep suspends a driver thread
until it’s waken up by eth_task_wake.
eth_stack.c
• Provides a glue layer between the driver and TCP/IP stack.
• The only file to include stack headers.
• Handles everything about struct m.