[4696] | 1 | /** @file WARP_ip_udp_init.c |
---|
| 2 | * @brief WARP IP/UDP Library (Initialization) |
---|
| 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 | // NOTE: Many data structures in the WARP IP/UDP Library must be accessible to DMAs |
---|
| 13 | // and other system level masters. Therefore, we have put those variables in their |
---|
| 14 | // own linker section, ".eth_data", so that it is easy to put that section into an |
---|
| 15 | // appropriate memory within the system. |
---|
| 16 | // |
---|
| 17 | // This will require custom modification of the linker script since the Xilinx SDK |
---|
| 18 | // can not detect these section headers ahead of time so that they can be placed as |
---|
| 19 | // part of the GUI section placement. |
---|
| 20 | // |
---|
| 21 | |
---|
| 22 | /***************************** Include Files *********************************/ |
---|
| 23 | |
---|
| 24 | // Xilinx / Standard library includes |
---|
| 25 | #include <xparameters.h> |
---|
| 26 | #include <xstatus.h> |
---|
| 27 | #include <stdlib.h> |
---|
| 28 | #include <stdio.h> |
---|
| 29 | #include <string.h> |
---|
| 30 | |
---|
| 31 | // WARP IP/UDP Library includes |
---|
| 32 | #include "WARP_ip_udp.h" |
---|
| 33 | #include "WARP_ip_udp_internal.h" |
---|
| 34 | |
---|
| 35 | |
---|
| 36 | /*************************** Constant Definitions ****************************/ |
---|
| 37 | |
---|
| 38 | |
---|
| 39 | /*********************** Global Variable Definitions *************************/ |
---|
| 40 | |
---|
| 41 | |
---|
| 42 | /*************************** Variable Definitions ****************************/ |
---|
| 43 | |
---|
| 44 | // Send buffers for all Ethernet devices |
---|
| 45 | u32 ETH_allocated_send_buffers; |
---|
| 46 | u32 ETH_send_buffer[WARP_IP_UDP_ETH_NUM_SEND_BUF * (WARP_IP_UDP_ETH_BUF_SIZE >> 2)] __attribute__ ((aligned(WARP_IP_UDP_BUFFER_ALIGNMENT))) __attribute__ ((section (".eth_data"))); |
---|
| 47 | warp_ip_udp_buffer ETH_send_buffers[WARP_IP_UDP_ETH_NUM_SEND_BUF]; |
---|
| 48 | |
---|
| 49 | // Memory for minimum length dummy Ethernet Frame |
---|
| 50 | // NOTE: Memory for the frame must be accessible by the DMA |
---|
| 51 | // |
---|
| 52 | u8 ETH_dummy_frame[ETH_MIN_FRAME_LEN] __attribute__ ((aligned(WARP_IP_UDP_BUFFER_ALIGNMENT))) __attribute__ ((section (".eth_data"))); |
---|
| 53 | |
---|
| 54 | // Socket data structures |
---|
| 55 | // NOTE: Memory for the IP/UDP headers must be accessible by the DMA |
---|
| 56 | // |
---|
| 57 | warp_ip_udp_header ETH_headers[WARP_IP_UDP_NUM_SOCKETS] __attribute__ ((aligned(WARP_IP_UDP_BUFFER_ALIGNMENT))) __attribute__ ((section (".eth_data"))); |
---|
| 58 | warp_ip_udp_socket ETH_sockets[WARP_IP_UDP_NUM_SOCKETS]; |
---|
| 59 | |
---|
| 60 | // ARP Table data structures |
---|
| 61 | // NOTE: There is only a single ARP table for all Ethernet devices. |
---|
| 62 | // |
---|
| 63 | arp_cache_entry ETH_arp_cache[WARP_IP_UDP_NUM_ARP_ENTRIES]; |
---|
| 64 | |
---|
| 65 | |
---|
| 66 | /*************************** Function Prototypes *****************************/ |
---|
| 67 | |
---|
| 68 | |
---|
| 69 | /******************************** Functions **********************************/ |
---|
| 70 | |
---|
| 71 | |
---|
| 72 | /*****************************************************************************/ |
---|
| 73 | /** |
---|
| 74 | * Initialize the global Ethernet structures |
---|
| 75 | * |
---|
| 76 | * @param None |
---|
| 77 | * |
---|
| 78 | * @return None |
---|
| 79 | * |
---|
| 80 | ******************************************************************************/ |
---|
| 81 | void eth_init_global_structures() { |
---|
| 82 | u32 i; |
---|
| 83 | u32 temp; |
---|
| 84 | |
---|
| 85 | // Initialize dummy Ethernet frame |
---|
| 86 | bzero(ETH_dummy_frame, ETH_MIN_FRAME_LEN); |
---|
| 87 | |
---|
| 88 | // Initialize the send buffer pool |
---|
| 89 | ETH_allocated_send_buffers = 0; |
---|
| 90 | |
---|
| 91 | // Initialize each IP/UDP buffer in the send buffer pool |
---|
| 92 | for (i = 0; i < WARP_IP_UDP_ETH_NUM_SEND_BUF; i++) { |
---|
| 93 | temp = ((u32)(Ð_send_buffer) + (i * (WARP_IP_UDP_ETH_BUF_SIZE >> 2)) + WARP_IP_UDP_ETH_TX_BUF_ALIGNMENT); |
---|
| 94 | |
---|
| 95 | ETH_send_buffers[i].state = WARP_IP_UDP_BUFFER_FREE; |
---|
| 96 | ETH_send_buffers[i].max_size = WARP_IP_UDP_ETH_BUF_SIZE; |
---|
| 97 | ETH_send_buffers[i].size = 0; |
---|
| 98 | ETH_send_buffers[i].data = (u8 *) temp; |
---|
| 99 | ETH_send_buffers[i].offset = (u8 *) temp; |
---|
| 100 | ETH_send_buffers[i].length = 0; |
---|
| 101 | ETH_send_buffers[i].descriptor = NULL; |
---|
| 102 | } |
---|
| 103 | } |
---|
| 104 | |
---|
| 105 | |
---|
| 106 | |
---|
| 107 | /*****************************************************************************/ |
---|
| 108 | /** |
---|
| 109 | * Initialize the Socket structures |
---|
| 110 | * |
---|
| 111 | * @param None |
---|
| 112 | * |
---|
| 113 | * @return None |
---|
| 114 | * |
---|
| 115 | ******************************************************************************/ |
---|
| 116 | void socket_init_sockets() { |
---|
| 117 | u32 i; |
---|
| 118 | |
---|
| 119 | // Initialize all the sockets |
---|
| 120 | for (i = 0; i < WARP_IP_UDP_NUM_SOCKETS; i++) { |
---|
| 121 | ETH_sockets[i].index = i; |
---|
| 122 | ETH_sockets[i].state = SOCKET_CLOSED; |
---|
| 123 | ETH_sockets[i].eth_dev_num = WARP_IP_UDP_INVALID_ETH_DEVICE; |
---|
| 124 | ETH_sockets[i].hdr = &(ETH_headers[i]); |
---|
| 125 | } |
---|
| 126 | } |
---|
| 127 | |
---|
| 128 | |
---|
| 129 | |
---|
| 130 | /*****************************************************************************/ |
---|
| 131 | /** |
---|
| 132 | * Initialize the ARP cache structure |
---|
| 133 | * |
---|
| 134 | * @param None |
---|
| 135 | * |
---|
| 136 | * @return None |
---|
| 137 | * |
---|
| 138 | ******************************************************************************/ |
---|
| 139 | void arp_init_cache() { |
---|
| 140 | u32 i; |
---|
| 141 | |
---|
| 142 | // Initialize ARP table |
---|
| 143 | for (i = 0; i < WARP_IP_UDP_NUM_ARP_ENTRIES; i++) { |
---|
| 144 | // Zero out the entry |
---|
| 145 | bzero((void *)&(ETH_arp_cache[i]), sizeof(arp_cache_entry)); |
---|
| 146 | |
---|
| 147 | // Set the Ethernet device to the invalid Ethernet device |
---|
| 148 | ETH_arp_cache[i].eth_dev_num = WARP_IP_UDP_INVALID_ETH_DEVICE; |
---|
| 149 | } |
---|
| 150 | } |
---|
| 151 | |
---|
| 152 | |
---|
| 153 | |
---|
| 154 | /*****************************************************************************/ |
---|
| 155 | /** |
---|
| 156 | * Initialize the IP/UDP Library |
---|
| 157 | * |
---|
| 158 | * This function will initialize all subsystems within the library: |
---|
| 159 | * - Global Ethernet structures |
---|
| 160 | * - Socket data structures |
---|
| 161 | * - ARP cache |
---|
| 162 | * - IP V4 global structures (ie ID counter) |
---|
| 163 | * |
---|
| 164 | * @param None |
---|
| 165 | * |
---|
| 166 | * @return int - Status of the command: |
---|
| 167 | * XST_SUCCESS - Command completed successfully |
---|
| 168 | * XST_FAILURE - There was an error in the command |
---|
| 169 | * |
---|
| 170 | ******************************************************************************/ |
---|
| 171 | int warp_ip_udp_init() { |
---|
| 172 | |
---|
| 173 | // Initialize the global ethernet structures |
---|
| 174 | eth_init_global_structures(); |
---|
| 175 | |
---|
| 176 | // Initialize the sockets |
---|
| 177 | socket_init_sockets(); |
---|
| 178 | |
---|
| 179 | // Initialize the ARP cache |
---|
| 180 | arp_init_cache(); |
---|
| 181 | |
---|
| 182 | // Initialize the IP v4 global structures |
---|
| 183 | ipv4_init(); |
---|
| 184 | |
---|
| 185 | // Return success |
---|
| 186 | return XST_SUCCESS; |
---|
| 187 | } |
---|