diff options
author | Evan Lojewski <github@meklort.com> | 2019-06-01 10:57:29 -0600 |
---|---|---|
committer | Evan Lojewski <github@meklort.com> | 2019-06-01 10:57:29 -0600 |
commit | 3a5e8aba2ca066626ec4ec058153530c4591b1e5 (patch) | |
tree | 70a90e137b8fff2847175a91d58d34caefa565a5 /libs/Network | |
parent | a70db0191841f43b6453cc395a22e68f8cb365db (diff) | |
download | bcm5719-ortega-3a5e8aba2ca066626ec4ec058153530c4591b1e5.tar.gz bcm5719-ortega-3a5e8aba2ca066626ec4ec058153530c4591b1e5.zip |
Additional refactoring to ensure network tx/rx is enabled properly.
Diffstat (limited to 'libs/Network')
-rw-r--r-- | libs/Network/CMakeLists.txt | 4 | ||||
-rw-r--r-- | libs/Network/generic.c | 9 | ||||
-rw-r--r-- | libs/Network/include/Network.h | 31 | ||||
-rw-r--r-- | libs/Network/init.c | 87 | ||||
-rw-r--r-- | libs/Network/ports.c | 140 |
5 files changed, 172 insertions, 99 deletions
diff --git a/libs/Network/CMakeLists.txt b/libs/Network/CMakeLists.txt index a393172..6381686 100644 --- a/libs/Network/CMakeLists.txt +++ b/libs/Network/CMakeLists.txt @@ -46,13 +46,13 @@ project(Network) # Host Simulation library -simulator_add_library(${PROJECT_NAME} STATIC tx.c rx.c generic.c) +simulator_add_library(${PROJECT_NAME} STATIC ports.c tx.c rx.c generic.c) target_link_libraries(${PROJECT_NAME} PRIVATE simulator NCSI) target_include_directories(${PROJECT_NAME} PUBLIC ../../include) target_include_directories(${PROJECT_NAME} PUBLIC include) # ARM Library -arm_add_library(${PROJECT_NAME}-arm STATIC init.c tx.c rx.c generic.c) +arm_add_library(${PROJECT_NAME}-arm STATIC init.c ports.c tx.c rx.c generic.c) target_link_libraries(${PROJECT_NAME}-arm PRIVATE NCSI-arm) target_include_directories(${PROJECT_NAME}-arm PUBLIC ../../include) target_include_directories(${PROJECT_NAME}-arm PUBLIC include) diff --git a/libs/Network/generic.c b/libs/Network/generic.c index f15c58c..3530e9e 100644 --- a/libs/Network/generic.c +++ b/libs/Network/generic.c @@ -45,7 +45,7 @@ #include <APE_DEVICE.h> #include <Network.h> -void Network_SetMACAddr(uint16_t high, uint32_t low, uint32_t index, +void Network_SetMACAddr(NetworkPort_t *port, uint16_t high, uint32_t low, uint32_t index, bool enabled) { uint32_t match_high = (high << 16) | (low >> 16); @@ -68,6 +68,9 @@ void Network_SetMACAddr(uint16_t high, uint32_t low, uint32_t index, APE_PERI.BmcToNcSourceMacMatch7High.r32 = match_high; APE_PERI.BmcToNcSourceMacMatch7Low.r32 = match_low; - DEVICE.PerfectMatch1High.r32 = high; - DEVICE.PerfectMatch1Low.r32 = low; + if(port) + { + port->device->PerfectMatch1High.r32 = high; + port->device->PerfectMatch1Low.r32 = low; + } }
\ No newline at end of file diff --git a/libs/Network/include/Network.h b/libs/Network/include/Network.h index 25dab4b..82a5a7e 100644 --- a/libs/Network/include/Network.h +++ b/libs/Network/include/Network.h @@ -55,21 +55,31 @@ #include <APE_TX_PORT1.h> #include <APE_TX_PORT2.h> #include <APE_TX_PORT3.h> +#include <APE_DEVICE.h> #include <types.h> +#ifdef CXX_SIMULATOR +#define VOLATILE +#else +#define VOLATILE volatile +#endif + typedef struct { /* TX Registers */ - volatile RegAPETxToNetPoolModeStatus_t *tx_mode; - volatile TX_PORT_t *tx_port; - volatile RegAPETxToNetBufferAllocator_t *tx_allocator; - volatile RegAPETxToNetDoorbell_t *tx_doorbell; + VOLATILE RegAPETxToNetPoolModeStatus_t *tx_mode; + VOLATILE TX_PORT_t *tx_port; + VOLATILE RegAPETxToNetBufferAllocator_t *tx_allocator; + VOLATILE RegAPETxToNetDoorbell_t *tx_doorbell; /* RX Registers */ - volatile RegAPERxPoolModeStatus_t *rx_mode; - volatile RX_PORT_t *rx_port; - volatile RegAPERxbufoffset_t *rx_offset; - volatile RegAPERxPoolRetire_t *rx_retire; + VOLATILE RegAPERxPoolModeStatus_t *rx_mode; + VOLATILE RX_PORT_t *rx_port; + VOLATILE RegAPERxbufoffset_t *rx_offset; + VOLATILE RegAPERxPoolRetire_t *rx_retire; + + /* Port Registers */ + VOLATILE DEVICE_t *device; } NetworkPort_t; typedef union { @@ -89,6 +99,7 @@ extern NetworkPort_t gPort1; extern NetworkPort_t gPort2; extern NetworkPort_t gPort3; +void Network_InitPort(NetworkPort_t *port); void Network_InitTxRx(void); uint32_t Network_TX_numBlocksNeeded(uint32_t frame_size); @@ -108,7 +119,7 @@ bool Network_RxLePatcket(uint32_t *buffer, uint32_t *length, NetworkPort_t *port); bool Network_PassthroughRxPatcket(NetworkPort_t *port); -void Network_SetMACAddr(uint16_t high, uint32_t low, uint32_t index, - bool enabled); +void Network_SetMACAddr(NetworkPort_t *port, uint16_t high, uint32_t low, + uint32_t index, bool enabled); #endif /* NETWORK_H */
\ No newline at end of file diff --git a/libs/Network/init.c b/libs/Network/init.c index 5b3bf2d..c7d2309 100644 --- a/libs/Network/init.c +++ b/libs/Network/init.c @@ -45,6 +45,9 @@ #include <APE_FILTERS.h> #include <APE_APE.h> #include <APE_DEVICE.h> +#include <APE_DEVICE1.h> +#include <APE_DEVICE2.h> +#include <APE_DEVICE3.h> #include <Network.h> @@ -641,79 +644,6 @@ static const FilterRuleInit_t gRuleInit[32] = { }, }; -NetworkPort_t gPort0 = { - .tx_port = &TX_PORT0, - .tx_allocator = &APE.TxToNetBufferAllocator0, - .tx_doorbell = &APE.TxToNetDoorbellFunc0, - .tx_mode = &APE.TxToNetPoolModeStatus0, - - .rx_port = &RX_PORT0, - .rx_offset = &APE.RxbufoffsetFunc0, - .rx_retire = &APE.RxPoolRetire0, - .rx_mode = &APE.RxPoolModeStatus0, -}; - -NetworkPort_t gPort1 = { - .tx_port = &TX_PORT1, - .tx_allocator = &APE.TxToNetBufferAllocator1, - .tx_doorbell = &APE.TxToNetDoorbellFunc1, - .tx_mode = &APE.TxToNetPoolModeStatus1, - - .rx_port = &RX_PORT1, - .rx_offset = &APE.RxbufoffsetFunc1, - .rx_retire = &APE.RxPoolRetire1, - .rx_mode = &APE.RxPoolModeStatus1, -}; - -NetworkPort_t gPort2 = { - .tx_port = &TX_PORT2, - .tx_allocator = &APE.TxToNetBufferAllocator2, - .tx_doorbell = &APE.TxToNetDoorbellFunc2, - .tx_mode = &APE.TxToNetPoolModeStatus2, - - .rx_port = &RX_PORT2, - .rx_offset = &APE.RxbufoffsetFunc2, - .rx_retire = &APE.RxPoolRetire2, - .rx_mode = &APE.RxPoolModeStatus2, -}; - -NetworkPort_t gPort3 = { - .tx_port = &TX_PORT3, - .tx_allocator = &APE.TxToNetBufferAllocator3, - .tx_doorbell = &APE.TxToNetDoorbellFunc3, - .tx_mode = &APE.TxToNetPoolModeStatus3, - - .rx_port = &RX_PORT3, - .rx_offset = &APE.RxbufoffsetFunc3, - .rx_retire = &APE.RxPoolRetire3, - .rx_mode = &APE.RxPoolModeStatus3, -}; - - -void Network_InitPort(NetworkPort_t *port) -{ - // Enable RX - RegAPERxPoolModeStatus_t rxMode; - rxMode.r32 = 0; - rxMode.bits.Reset = 1; - *(port->rx_mode) = rxMode; - - rxMode.bits.Reset = 0; - rxMode.bits.Enable = 1; - *(port->rx_mode) = rxMode; - - // Enable TX - RegAPETxToNetPoolModeStatus_t txMode; - txMode.r32 = 0; - txMode.bits.Reset = 1; - *(port->tx_mode) = txMode; - - txMode.bits.Reset = 0; - txMode.bits.Enable = 1; - *(port->tx_mode) = txMode; - -} - void Network_InitTxRx(void) { for(int i = 0; i < 32; i++) @@ -742,17 +672,6 @@ void Network_InitTxRx(void) // for an example MAC AABB.CCDD.EEFF, set HIGH=0xAABBCCDD, LOW=0xEEFF0000. // *** NOTE: set to 0 in rmu.c *** - - // Ensure REG_RECEIVE_MAC_MODE has ENABLE set. - // I recommend also setting APE_PROMISCUOUS_MODE and PROMISCUOUS_MODE, - // as these will cause you less headaches during development. - RegDEVICEReceiveMacMode_t macMode; - macMode = DEVICE.ReceiveMacMode; - macMode.bits.Enable = 1; - macMode.bits.APEPromiscuousMode = 0; - DEVICE.ReceiveMacMode = macMode; - - // Ensure REG_EMAC_MODE__ENABLE_APE_{TX,RX}_PATH are set. // *** NOTE: Both bits are set in rmu.c ***/ diff --git a/libs/Network/ports.c b/libs/Network/ports.c new file mode 100644 index 0000000..3c02a7d --- /dev/null +++ b/libs/Network/ports.c @@ -0,0 +1,140 @@ +//////////////////////////////////////////////////////////////////////////////// +/// +/// @file ports.c +/// +/// @project +/// +/// @brief Port specific initialization and data structures. +/// +//////////////////////////////////////////////////////////////////////////////// +/// +//////////////////////////////////////////////////////////////////////////////// +/// +/// @copyright Copyright (c) 2018, Evan Lojewski +/// @cond +/// +/// All rights reserved. +/// +/// Redistribution and use in source and binary forms, with or without +/// modification, are permitted provided that the following conditions are met: +/// 1. Redistributions of source code must retain the above copyright notice, +/// this list of conditions and the following disclaimer. +/// 2. Redistributions in binary form must reproduce the above copyright notice, +/// this list of conditions and the following disclaimer in the documentation +/// and/or other materials provided with the distribution. +/// 3. Neither the name of the copyright holder nor the +/// names of its contributors may be used to endorse or promote products +/// derived from this software without specific prior written permission. +/// +//////////////////////////////////////////////////////////////////////////////// +/// +/// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +/// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +/// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +/// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +/// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +/// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +/// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +/// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +/// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +/// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +/// POSSIBILITY OF SUCH DAMAGE. +/// @endcond +//////////////////////////////////////////////////////////////////////////////// + +#include <Network.h> + +#include <APE_DEVICE1.h> +#include <APE_DEVICE2.h> +#include <APE_DEVICE3.h> + +NetworkPort_t gPort0 = { + .device = &DEVICE, + + .tx_port = &TX_PORT0, + .tx_allocator = &APE.TxToNetBufferAllocator0, + .tx_doorbell = &APE.TxToNetDoorbellFunc0, + .tx_mode = &APE.TxToNetPoolModeStatus0, + + .rx_port = &RX_PORT0, + .rx_offset = &APE.RxbufoffsetFunc0, + .rx_retire = &APE.RxPoolRetire0, + .rx_mode = &APE.RxPoolModeStatus0, +}; + +NetworkPort_t gPort1 = { + .device = &DEVICE1, + + .tx_port = &TX_PORT1, + .tx_allocator = &APE.TxToNetBufferAllocator1, + .tx_doorbell = &APE.TxToNetDoorbellFunc1, + .tx_mode = &APE.TxToNetPoolModeStatus1, + + .rx_port = &RX_PORT1, + .rx_offset = &APE.RxbufoffsetFunc1, + .rx_retire = &APE.RxPoolRetire1, + .rx_mode = &APE.RxPoolModeStatus1, +}; + +NetworkPort_t gPort2 = { + .device = &DEVICE2, + + .tx_port = &TX_PORT2, + .tx_allocator = &APE.TxToNetBufferAllocator2, + .tx_doorbell = &APE.TxToNetDoorbellFunc2, + .tx_mode = &APE.TxToNetPoolModeStatus2, + + .rx_port = &RX_PORT2, + .rx_offset = &APE.RxbufoffsetFunc2, + .rx_retire = &APE.RxPoolRetire2, + .rx_mode = &APE.RxPoolModeStatus2, +}; + +NetworkPort_t gPort3 = { + .device = &DEVICE3, + + .tx_port = &TX_PORT3, + .tx_allocator = &APE.TxToNetBufferAllocator3, + .tx_doorbell = &APE.TxToNetDoorbellFunc3, + .tx_mode = &APE.TxToNetPoolModeStatus3, + + .rx_port = &RX_PORT3, + .rx_offset = &APE.RxbufoffsetFunc3, + .rx_retire = &APE.RxPoolRetire3, + .rx_mode = &APE.RxPoolModeStatus3, +}; + + +void Network_InitPort(NetworkPort_t *port) +{ + // Enable RX + RegAPERxPoolModeStatus_t rxMode; + rxMode.r32 = 0; + rxMode.bits.Reset = 1; + *(port->rx_mode) = rxMode; + + rxMode.bits.Reset = 0; + rxMode.bits.Enable = 1; + *(port->rx_mode) = rxMode; + + // Enable TX + RegAPETxToNetPoolModeStatus_t txMode; + txMode.r32 = 0; + txMode.bits.Reset = 1; + *(port->tx_mode) = txMode; + + txMode.bits.Reset = 0; + txMode.bits.Enable = 1; + *(port->tx_mode) = txMode; + + // Ensure REG_RECEIVE_MAC_MODE has ENABLE set. + // I recommend also setting APE_PROMISCUOUS_MODE and PROMISCUOUS_MODE, + // as these will cause you less headaches during development. + RegDEVICEReceiveMacMode_t macMode; + macMode = port->device->ReceiveMacMode; + macMode.bits.Enable = 1; + macMode.bits.APEPromiscuousMode = 0; + port->device->ReceiveMacMode = macMode; + + Network_SetMACAddr(port, 0, 0, 1, true); +} |