[4696] | 1 | /** @file WARP_ip_udp_internal.h |
---|
| 2 | * @brief WARP IP/UDP Library (Internal Structures / Functions) |
---|
| 3 | * |
---|
| 4 | * @copyright Copyright 2015, Mango Communications. All rights reserved. |
---|
| 5 | * Distributed under the WARP license (http://warpproject.org/license) |
---|
| 6 | * |
---|
| 7 | * @author Chris Hunter (chunter [at] mangocomm.com) |
---|
| 8 | * @author Patrick Murphy (murphpo [at] mangocomm.com) |
---|
| 9 | * @author Erik Welsh (welsh [at] mangocomm.com) |
---|
| 10 | */ |
---|
| 11 | |
---|
| 12 | |
---|
| 13 | /***************************** Include Files *********************************/ |
---|
| 14 | |
---|
| 15 | // Xilinx / Standard library includes |
---|
| 16 | #include <xil_types.h> |
---|
| 17 | |
---|
| 18 | // WARP IP/UDP Library includes |
---|
| 19 | #include "WARP_ip_udp_config.h" |
---|
| 20 | #include "WARP_ip_udp_device.h" |
---|
| 21 | |
---|
| 22 | |
---|
| 23 | /*************************** Constant Definitions ****************************/ |
---|
| 24 | #ifndef WARP_IP_UDP_INTERNAL_H_ |
---|
| 25 | #define WARP_IP_UDP_INTERNAL_H_ |
---|
| 26 | |
---|
| 27 | |
---|
| 28 | // ********************************************************************** |
---|
| 29 | // WARP IP/UDP Library Common Defines |
---|
| 30 | // |
---|
| 31 | |
---|
| 32 | // WARP IP/UDP Library Buffer State defines |
---|
| 33 | #define WARP_IP_UDP_BUFFER_FREE 0 // Buffer is free to be used |
---|
| 34 | #define WARP_IP_UDP_BUFFER_IN_USE 1 // Buffer is currently in use |
---|
| 35 | |
---|
| 36 | |
---|
| 37 | // ********************************************************************** |
---|
| 38 | // WARP IP/UDP Library ARP Defines |
---|
| 39 | // |
---|
| 40 | |
---|
| 41 | // WARP IP/UDP Library ARP Table States |
---|
| 42 | #define ARP_TABLE_UNUSED 0 // ARP Table Entry is not in use |
---|
| 43 | #define ARP_TABLE_USED 1 // ARP Table Entry is in use |
---|
| 44 | |
---|
| 45 | |
---|
| 46 | // ********************************************************************** |
---|
| 47 | // WARP IP/UDP Library Socket Defines |
---|
| 48 | // |
---|
| 49 | |
---|
| 50 | // WARP IP/UDP Library Socket States |
---|
| 51 | #define SOCKET_CLOSED 0 // Socket cannot be used |
---|
| 52 | #define SOCKET_ALLOCATED 1 // Socket has been allocated but not bound |
---|
| 53 | #define SOCKET_OPEN 2 // Socket is bound and can be used |
---|
| 54 | |
---|
| 55 | |
---|
| 56 | /***************************** Macro Definitions *****************************/ |
---|
| 57 | |
---|
| 58 | |
---|
| 59 | /*********************** Global Structure Definitions ************************/ |
---|
| 60 | |
---|
| 61 | // ********************************************************************** |
---|
| 62 | // WARP IP/UDP Library Ethernet Structures |
---|
| 63 | // |
---|
| 64 | |
---|
| 65 | // NOTE: The reason that we use void pointers vs pointers to actual defined types is so that |
---|
| 66 | // downstream software doesn't have to have any hardware specific include files if they do |
---|
| 67 | // not need to deal with these pointers. |
---|
| 68 | // |
---|
| 69 | typedef struct { |
---|
| 70 | u32 initialized; // Is the Ethernet device initialized |
---|
| 71 | |
---|
| 72 | // Ethernet variables |
---|
| 73 | u32 eth_id; // XPAR ID for Ethernet device |
---|
| 74 | void * eth_ptr; // Pointer to Ethernet instance |
---|
| 75 | void * eth_cfg_ptr; // Pointer to Ethernet config instance |
---|
| 76 | |
---|
| 77 | // Ethernet DMA variables |
---|
| 78 | u32 dma_id; // XPAR ID for Ethernet DMA |
---|
| 79 | void * dma_ptr; // Pointer to Ethernet DMA instance |
---|
| 80 | void * dma_cfg_ptr; // Pointer to Ethernet DMA config instance |
---|
| 81 | |
---|
| 82 | void * dma_rx_ring_ptr; // Pointer to RX ring |
---|
| 83 | void * dma_rx_bd_ptr; // Pointer to RX buffer descriptor |
---|
| 84 | int dma_rx_bd_cnt; // Number of RX buffer descriptors |
---|
| 85 | |
---|
| 86 | void * dma_tx_ring_ptr; // Pointer to TX ring |
---|
| 87 | void * dma_tx_bd_ptr; // Pointer to TX buffer descriptor |
---|
| 88 | int dma_tx_bd_cnt; // Number of TX buffer descriptors |
---|
| 89 | |
---|
| 90 | // Ethernet device information |
---|
| 91 | u8 hw_addr[ETH_MAC_ADDR_LEN]; // Ethernet device MAC address |
---|
| 92 | u16 padding; // Padding to align hw_addr |
---|
| 93 | u8 ip_addr[IP_ADDR_LEN]; // Ethernet device IP address |
---|
| 94 | |
---|
| 95 | // Buffers for receiving data |
---|
| 96 | // NOTE: Buffers are allocated based on the configuration in the BSP. For DMA interfaces, it |
---|
| 97 | // is recommended to have at least 2 receive buffers so that the AXI DMA can use a |
---|
| 98 | // ping pong buffer scheme. |
---|
| 99 | // NOTE: Since buffers for sending data are not specific to an Ethernet device, there are a pool |
---|
| 100 | // that can be allocated in the library. |
---|
| 101 | // |
---|
| 102 | u32 num_recv_buffers; |
---|
| 103 | warp_ip_udp_buffer * recv_buffers; |
---|
| 104 | } ethernet_device; |
---|
| 105 | |
---|
| 106 | |
---|
| 107 | // ********************************************************************** |
---|
| 108 | // WARP IP/UDP Library ARP Structures |
---|
| 109 | // - NOTE: The WARP IP/UDP Library only support IPv4 ARP |
---|
| 110 | // |
---|
| 111 | |
---|
| 112 | // ARP Table entry |
---|
| 113 | typedef struct { |
---|
| 114 | u32 eth_dev_num; // Ethernet device |
---|
| 115 | u32 age; // Age of the entry |
---|
| 116 | u16 state; // State of the entry |
---|
| 117 | u8 haddr[ETH_MAC_ADDR_LEN]; // Hardware address |
---|
| 118 | u8 paddr[IP_ADDR_LEN]; // Protocol address |
---|
| 119 | } arp_cache_entry; |
---|
| 120 | |
---|
| 121 | |
---|
| 122 | |
---|
[5127] | 123 | // ********************************************************************** |
---|
| 124 | // Ethernet Function pointer |
---|
| 125 | // |
---|
| 126 | typedef int (*eth_int_disable_func_ptr_t)(); |
---|
| 127 | typedef int (*eth_int_enable_func_ptr_t)(int); |
---|
| 128 | |
---|
| 129 | |
---|
| 130 | |
---|
[4696] | 131 | /*********************** Global Variable Definitions *************************/ |
---|
| 132 | |
---|
| 133 | extern ethernet_device eth_device[WARP_IP_UDP_NUM_ETH_DEVICES]; |
---|
| 134 | extern u32 ETH_allocated_send_buffers; |
---|
| 135 | extern warp_ip_udp_buffer ETH_send_buffers[WARP_IP_UDP_ETH_NUM_SEND_BUF]; |
---|
| 136 | extern u8 ETH_dummy_frame[ETH_MIN_FRAME_LEN]; |
---|
| 137 | extern warp_ip_udp_socket ETH_sockets[WARP_IP_UDP_NUM_SOCKETS]; |
---|
| 138 | extern arp_cache_entry ETH_arp_cache[WARP_IP_UDP_NUM_ARP_ENTRIES]; |
---|
| 139 | |
---|
| 140 | |
---|
| 141 | /*************************** Function Prototypes *****************************/ |
---|
| 142 | |
---|
| 143 | // Ethernet Device functions |
---|
| 144 | void eth_init_header(ethernet_header * header, u8 * src_hw_addr); |
---|
| 145 | void eth_update_header(ethernet_header * header, u8 * dest_hw_addr, u16 ethertype); |
---|
| 146 | |
---|
| 147 | int eth_free_recv_buffers(u32 eth_dev_num, void * descriptors, u32 num_descriptors); |
---|
| 148 | |
---|
| 149 | int eth_recv_frame(u32 eth_dev_num, warp_ip_udp_buffer * eth_frame); |
---|
| 150 | int eth_send_frame(u32 eth_dev_num, warp_ip_udp_socket * socket, warp_ip_udp_buffer ** buffers, u32 num_buffers, u32 use_socket_header); |
---|
| 151 | |
---|
| 152 | // IP functions |
---|
| 153 | void ipv4_init(); |
---|
| 154 | |
---|
| 155 | int ipv4_process_packet(u32 eth_dev_num, warp_ip_udp_buffer * buffer); |
---|
| 156 | |
---|
| 157 | void ipv4_init_header(ipv4_header * header, u8 * src_ip_addr); |
---|
| 158 | // void ipv4_update_header(ipv4_header * header, u32 dest_ip_addr, u16 ip_length, u8 protocol); // Defined in WARP_ip_udp.h |
---|
| 159 | |
---|
| 160 | u16 ipv4_compute_checksum(u8 * data, u32 size); |
---|
| 161 | |
---|
| 162 | // UDP functions |
---|
| 163 | int udp_process_packet(u32 eth_dev_num, warp_ip_udp_buffer * packet); |
---|
| 164 | |
---|
| 165 | void udp_init_header(udp_header * header, u16 src_port); |
---|
| 166 | void udp_update_header(udp_header * header, u16 dest_port, u16 udp_length); |
---|
| 167 | |
---|
| 168 | // ARP functions |
---|
| 169 | int arp_process_packet(u32 eth_dev_num, warp_ip_udp_buffer * packet); |
---|
| 170 | |
---|
| 171 | void arp_send_reply(u32 eth_dev_num, warp_ip_udp_buffer * arp_request); |
---|
| 172 | |
---|
| 173 | // IMCP functions |
---|
| 174 | int imcp_process_packet(u32 eth_dev_num, warp_ip_udp_buffer * packet); |
---|
| 175 | |
---|
| 176 | void imcp_send_echo_reply(u32 eth_dev_num, warp_ip_udp_buffer * echo_request); |
---|
| 177 | |
---|
| 178 | // Socket functions |
---|
| 179 | int socket_find_index_by_eth(u32 eth_dev_num, u16 port); |
---|
| 180 | |
---|
| 181 | |
---|
| 182 | #endif // WARP_IP_UDP_INTERNAL_H_ |
---|