Skip to content

More testing and fix Qav + refactor #98

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 30 commits into from
Feb 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
587556b
WIP document MAC feature set
ed-xmos Jan 21, 2025
2f67ae0
Add text about queues and shaper
ed-xmos Jan 21, 2025
f9ca840
Add helper function example to set_egress_qav_idle_slope api
ed-xmos Jan 21, 2025
9ad88b1
Add VLAN stripping docs and some correctlons
ed-xmos Jan 22, 2025
15cfb29
Tidy tables
ed-xmos Jan 22, 2025
753e638
typo
ed-xmos Jan 22, 2025
cc5e573
typo2
ed-xmos Jan 22, 2025
5fa8321
typo3
ed-xmos Jan 22, 2025
e2d4873
typo4
ed-xmos Jan 22, 2025
b0c37ed
Review feedback
ed-xmos Jan 22, 2025
2c8e8fa
More detail for standard API
ed-xmos Jan 27, 2025
3d95087
Merge commit '2442e760fce18e533277e4804eb9206789f8eb48' into feature/…
ed-xmos Jan 27, 2025
96f3b01
Add MII_CREDIT_FRACTIONAL_BITS to API
ed-xmos Jan 27, 2025
fc2d2bd
Merge commit 'ea7273fefcef44f3f9e55dc41bc110cc6c58e78c' into feature/…
ed-xmos Jan 27, 2025
83a9cca
set_macaddr is const addr
ed-xmos Jan 27, 2025
bb6df87
Merge branch 'feature/docs_enhance' into feature/qav_update
ed-xmos Jan 27, 2025
5b7a2a2
Initial move shaper to helper file
ed-xmos Jan 28, 2025
b5adfeb
Initial test WIP
ed-xmos Jan 28, 2025
6c05cf5
Update shaper_do_idle_slope so it's ASM compatible. Failing test incl…
ed-xmos Jan 28, 2025
4fc208d
Major re-work of shaper
ed-xmos Jan 29, 2025
d4b45fa
Add passing regex for idle_slope unit
ed-xmos Jan 29, 2025
72514c3
Use new shaper in rmii
ed-xmos Jan 29, 2025
040303b
fix new shaper
ed-xmos Jan 30, 2025
e0d7d00
no-limit = 0, Qav test passing
ed-xmos Jan 30, 2025
1590b22
Add clipping for no limit case to avoid overflow
ed-xmos Jan 30, 2025
89964d4
enable debug for mii_master
ed-xmos Jan 31, 2025
f9a8e8d
Added new shaper API to RGMII + changelog
ed-xmos Jan 31, 2025
f433e4c
Changelog
ed-xmos Jan 31, 2025
6006d99
Index enable_shaper_t for easier debugging
ed-xmos Jan 31, 2025
5b91560
Ensure shaper_do_idle_slope is always called for RGMII even if packet…
ed-xmos Feb 3, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,24 @@ lib_ethernet change log
4.0.0
-----

* ADDED: Support for running MII sim tests for XS3 architecture
* ADDED: RMII Ethernet MAC support for XCORE-AI
* ADDED: Extended sim tests for testing RMII applications
* ADDED: Support for running MII sim tests for XS3 architecture
* ADDED: Support for XCommon CMake build system
* ADDED: Exit command to RMII RT MAC
* ADDED: Improved MAC feature documentation
* ADDED: Test for SMI
* CHANGED: SMI re-write. Single port version now functional
* ADDED: Tests for SMI
* ADDED: Optional credit limit for Qav shaper
* ADDED: Support for running MII sim tests for XS3 architecture
* CHANGED: SMI re-write. Single port version now functional and documented
* CHANGED: Moved example PHY drivers to lib_board_support
* REMOVED: Slicekit based examples because hardware is obsolete
* REMOVED: Support for waf build system
* REMOVED: Support for XS1 devices
* RESOLVED: Build warnings even when compile successful
* ADDED: Support for running MII sim tests for XS3 architecture
* CHANGED: Moved PHY support to separate head and source
* RESOLVED: Qav shaper credit overflow causing negative credit on idle
* RESOLVED: Packets might not be transmitted for 21 seconds if no transmit
activity for 21 seconds (IFG timer)

* Changes to dependencies:

Expand Down
48 changes: 31 additions & 17 deletions lib_ethernet/api/ethernet.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@
#include "doxygen.h" // Sphynx Documentation Workarounds


#define ETHERNET_ALL_INTERFACES (-1)
#define ETHERNET_MAX_PACKET_SIZE (1518) /**< MAX packet size in bytes */
#define ETHERNET_ALL_INTERFACES (-1)
#define ETHERNET_MAX_PACKET_SIZE (1518) /**< MAX packet size in bytes including src, dst, ether/tags but NOT preamble or CRC*/

#define MACADDR_NUM_BYTES (6) /**< Number of octets in MAC address */

#define MII_CREDIT_FRACTIONAL_BITS (16) /** Fractional bits for Qav credit based shaper setting */

#define MACADDR_NUM_BYTES 6

/** Type representing the type of packet from the MAC */
typedef enum eth_packet_type_t {
Expand Down Expand Up @@ -77,7 +80,7 @@ typedef interface ethernet_cfg_if {
* \param ifnum The index of the MAC interface to set
* \param mac_address The six-octet MAC address to set
*/
void set_macaddr(size_t ifnum, uint8_t mac_address[MACADDR_NUM_BYTES]);
void set_macaddr(size_t ifnum, const uint8_t mac_address[MACADDR_NUM_BYTES]);

/** Gets the source MAC address of the Ethernet MAC
*
Expand Down Expand Up @@ -166,25 +169,36 @@ typedef interface ethernet_cfg_if {
*/
void get_tile_id_and_timer_value(REFERENCE_PARAM(unsigned, tile_id), REFERENCE_PARAM(unsigned, time_on_tile));

/** Set the high-priority TX queue's credit based shaper idle slope.
/** Set the high-priority TX queue's credit based shaper idle slope value.
* See also set_egress_qav_idle_slope_bps() where the argument is bits per second.
* This function is only available in the 10/100 Mb/s real-time and 10/100/1000 Mb/s MACs.
*
* \param ifnum The index of the MAC interface to set the slope
* \param ifnum The index of the MAC interface to set the slope (always 0)
* \param slope The slope value in bits per 100 MHz ref timer tick in MII_CREDIT_FRACTIONAL_BITS Q format.
*
* To convert from bits-per-second to the MII_CREDIT_FRACTIONAL_BITS format for the parameter 'slope', the
* following helper function may be used:
*
* unsigned calc_idle_slope(unsigned bits_per_second)
* {
* unsigned long long slope = ((unsigned long long) bits_per_second) << (MII_CREDIT_FRACTIONAL_BITS);
* slope = slope / XS1_TIMER_HZ; // bits that should be sent per ref timer tick
*/
void set_egress_qav_idle_slope(size_t ifnum, unsigned slope);

/** Set the high-priority TX queue's credit based shaper idle slope in bits per second.
* This function is only available in the 10/100 Mb/s real-time and 10/100/1000 Mb/s MACs.
*
* \param ifnum The index of the MAC interface to set the slope (always 0)
* \param slope The maximum number of bits per second to be set
*
* return (unsigned) slope;
* }
*
*/
void set_egress_qav_idle_slope(size_t ifnum, unsigned slope);
void set_egress_qav_idle_slope_bps(size_t ifnum, unsigned bits_per_second);


/** Sets the the high-priority TX queue's Qav credit limit in units of frame size bytes
*
* \param ifnum The index of the MAC interface to set the slope (always 0)
* \param limit_bytes The credit limit in units of payload size in bytes to set as a credit limit,
* not including preamble, CRC and IFG. Set to 0 for no limit (default)
*
*/
void set_egress_qav_credit_limit(size_t ifnum, int payload_limit_bytes);

/** Set the ingress latency to correct for the offset between the timestamp
* measurement plane relative to the reference plane. See 802.1AS 8.4.3.
Expand Down Expand Up @@ -433,8 +447,8 @@ inline void ethernet_send_hp_packet(streaming_chanend_t c_tx_hp,
* on the egress MAC port.
*/
enum ethernet_enable_shaper_t {
ETHERNET_ENABLE_SHAPER, /**< Enable the credit based shaper */
ETHERNET_DISABLE_SHAPER /**< Disable the credit based shaper */
ETHERNET_DISABLE_SHAPER = 0, /**< Disable the credit based shaper */
ETHERNET_ENABLE_SHAPER /**< Enable the credit based shaper */
};

/** Structure representing the port and clock resources required by RGMII
Expand Down
2 changes: 1 addition & 1 deletion lib_ethernet/lib_build_info.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ set(LIB_COMPILER_FLAGS -g

set(LIB_OPTIONAL_HEADERS ethernet_conf.h)

set(LIB_COMPILER_FLAGS_mii_master.xc ${LIB_COMPILER_FLAGS} -O3 -fschedule -g0 -mno-dual-issue)
set(LIB_COMPILER_FLAGS_mii_master.xc ${LIB_COMPILER_FLAGS} -O3 -fschedule -g -mno-dual-issue)
set(LIB_COMPILER_FLAGS_macaddr_filter.xc ${LIB_COMPILER_FLAGS} -Wno-reinterpret-alignment)
set(LIB_COMPILER_FLAGS_mii.xc ${LIB_COMPILER_FLAGS} -Wno-cast-align -Wno-unusual-code)
set(LIB_COMPILER_FLAGS_mii_ethernet_mac.xc ${LIB_COMPILER_FLAGS} -Wno-cast-align -Wno-unusual-code)
Expand Down
2 changes: 1 addition & 1 deletion lib_ethernet/module_build_info
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ OPTIONAL_HEADERS += ethernet_conf.h

MODULE_XCC_FLAGS = $(XCC_FLAGS) -g -O3 -mno-dual-issue

XCC_FLAGS_mii_master.xc = $(XCC_FLAGS) -O3 -fschedule -g0 -mno-dual-issue
XCC_FLAGS_mii_master.xc = $(XCC_FLAGS) -O3 -fschedule -g -mno-dual-issue
XCC_FLAGS_macaddr_filter.xc = $(MODULE_XCC_FLAGS) -Wno-reinterpret-alignment
XCC_FLAGS_mii.xc = $(MODULE_XCC_FLAGS) -Wno-cast-align -Wno-unusual-code
XCC_FLAGS_mii_ethernet_mac.xc = $(MODULE_XCC_FLAGS) -Wno-cast-align -Wno-unusual-code
Expand Down
12 changes: 11 additions & 1 deletion lib_ethernet/src/mii_ethernet_mac.xc
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ static void mii_ethernet_aux(client mii_if i_mii,
memcpy(r_mac_address, mac_address, sizeof mac_address);
break;

case i_cfg[int i].set_macaddr(size_t ifnum, uint8_t r_mac_address[MACADDR_NUM_BYTES]):
case i_cfg[int i].set_macaddr(size_t ifnum, const uint8_t r_mac_address[MACADDR_NUM_BYTES]):
memcpy(mac_address, r_mac_address, sizeof r_mac_address);
break;

Expand Down Expand Up @@ -221,6 +221,16 @@ static void mii_ethernet_aux(client mii_if i_mii,
fail("Shaper not supported in standard MII Ethernet MAC");
break;

case i_cfg[int i].set_egress_qav_idle_slope_bps(size_t ifnum, unsigned bits_per_second): {
fail("Shaper not supported in standard MII Ethernet MAC");
break;
}

case i_cfg[int i].set_egress_qav_credit_limit(size_t ifnum, int payload_limit_bytes): {
fail("Shaper not supported in standard MII Ethernet MAC");
break;
}

case i_cfg[int i].set_ingress_timestamp_latency(size_t ifnum, ethernet_speed_t speed, unsigned value): {
fail("Timestamp correction not supported in standard MII Ethernet MAC");
break;
Expand Down
15 changes: 13 additions & 2 deletions lib_ethernet/src/mii_ethernet_rt_mac.xc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "print.h"
#include "server_state.h"
#include "rmii_rx_pins_exit.h"
#include "shaper.h"


static inline unsigned int get_tile_id_from_chanend(chanend c) {
Expand Down Expand Up @@ -322,7 +323,7 @@ unsafe void mii_ethernet_server(mii_mempool_t rx_mem,
memcpy(r_mac_address, mac_address, sizeof mac_address);
break;

case i_cfg[int i].set_macaddr(size_t ifnum, uint8_t r_mac_address[MACADDR_NUM_BYTES]):
case i_cfg[int i].set_macaddr(size_t ifnum, const uint8_t r_mac_address[MACADDR_NUM_BYTES]):
memcpy(mac_address, r_mac_address, sizeof r_mac_address);
break;

Expand Down Expand Up @@ -404,11 +405,21 @@ unsafe void mii_ethernet_server(mii_mempool_t rx_mem,
break;
}

case i_cfg[int i].set_egress_qav_idle_slope_bps(size_t ifnum, unsigned bits_per_second): {
set_qav_idle_slope(p_port_state, bits_per_second);
break;
}

case i_cfg[int i].set_egress_qav_credit_limit(size_t ifnum, int payload_limit_bytes): {
set_qav_credit_limit(p_port_state, payload_limit_bytes);
break;
}

case i_cfg[int i].set_ingress_timestamp_latency(size_t ifnum, ethernet_speed_t speed, unsigned value): {
if (speed < 0 || speed >= NUM_ETHERNET_SPEEDS) {
fail("Invalid Ethernet speed, must be a valid ethernet_speed_t enum value");
}
p_port_state->ingress_ts_latency[speed] = value / 10;
p_port_state->ingress_ts_latency[speed] = value / 10; // div by 10 to get to timer ticks from nanonseconds
break;
}

Expand Down
44 changes: 15 additions & 29 deletions lib_ethernet/src/mii_master.xc
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "mii_common_lld.h"
#include "string.h"
#include "check_ifg_wait.h"
#include "shaper.h"

#define QUOTEAUX(x) #x
#define QUOTE(x) QUOTEAUX(x)
Expand Down Expand Up @@ -471,9 +472,9 @@ unsafe void mii_master_tx_pins(mii_mempool_t tx_mem_lp,
out buffered port:32 p_mii_txd,
volatile ethernet_port_state_t * unsafe p_port_state)
{
int credit = 0; // No. of bits allowed to send
int credit_time;
// Need one timer to be able to read at any time for the shaper
qav_state_t qav_state = {0, 0, 0}; // Set times and credit to zero so it can tx first frame

// Need a timer to be able to read at any time for the shaper
timer credit_tmr;
// And a second timer to be enforcing the IFG gap
hwtimer_t ifg_tmr;
Expand All @@ -485,7 +486,8 @@ unsafe void mii_master_tx_pins(mii_mempool_t tx_mem_lp,
enable_shaper = 0;

if (ETHERNET_SUPPORT_HP_QUEUES && enable_shaper) {
credit_tmr :> credit_time;
credit_tmr :> qav_state.current_time;
qav_state.prev_time = qav_state.current_time;
}

ifg_tmr :> ifg_time;
Expand All @@ -496,27 +498,15 @@ unsafe void mii_master_tx_pins(mii_mempool_t tx_mem_lp,
mii_ts_queue_t *p_ts_queue = null;
mii_mempool_t tx_mem = tx_mem_hp;

if (ETHERNET_SUPPORT_HP_QUEUES)
if (ETHERNET_SUPPORT_HP_QUEUES) {
buf = mii_get_next_buf(packets_hp);
}

if (enable_shaper) {
int prev_credit_time = credit_time;
credit_tmr :> credit_time;

int elapsed = credit_time - prev_credit_time;
credit += elapsed * p_port_state->qav_idle_slope; // add bit budget since last transmission to credit. ticks * bits/tick = bits

if (buf) {
if (credit < 0) {
buf = 0; // if out of credit drop this HP packet
}
}
else {
if (credit > 0)
credit = 0;
}
credit_tmr :> qav_state.current_time;
buf = shaper_do_idle_slope(buf, &qav_state, p_port_state);
}

if (!buf) {
buf = mii_get_next_buf(packets_lp);
p_ts_queue = &ts_queue;
Expand All @@ -530,19 +520,15 @@ unsafe void mii_master_tx_pins(mii_mempool_t tx_mem_lp,

unsigned time = mii_transmit_packet(tx_mem, buf, p_mii_txd, ifg_tmr, ifg_time, eof_time);

eof_time = ifg_time;
// Setup the hardware timer to enforce the IFG
eof_time = ifg_time;
ifg_time += MII_ETHERNET_IFS_AS_REF_CLOCK_COUNT;
ifg_time += (buf->length & 0x3) * 8;

// Calculate the send slope (decrement credit) if enabled and was HP
const int packet_is_high_priority = (p_ts_queue == null);
if (enable_shaper && packet_is_high_priority) {
const int preamble_bytes = 8;
const int ifg_bytes = 96/8;
const int crc_bytes = 4;
int len = buf->length + preamble_bytes + ifg_bytes + crc_bytes;
// decrease credit by no. of bits transmitted
credit = credit - (len << (MII_CREDIT_FRACTIONAL_BITS+3)); // MII_CREDIT_FRACTIONAL_BITS+3 to convert from bytes to bits
shaper_do_send_slope(buf->length, &qav_state);
}

if (mii_get_and_dec_transmit_count(buf) == 0) {
Expand All @@ -559,6 +545,6 @@ unsafe void mii_master_tx_pins(mii_mempool_t tx_mem_lp,
mii_free_current(packets_hp);
}
}
}
} // while(1)
}

Loading