![]() |
RA Flexible Software Package Documentation
Release v6.0.0
|
|
The LAYER3 SWITCH module (r_layer3_switch) provides an API for standard Ethernet communications applications that use the ESWM peripheral. It implements the Ethernet Switch Interface.
This module performs Ethernet frame transmission and reception using Ethernet Switch Module.
The layer3 switch module supports the following features:
Configuration | Options | Default | Description |
---|---|---|---|
Parameter Checking |
| Default (BSP) | If selected code for parameter checking is included in the build. |
Available queue num | Value must be an integer between 1 and 64 | 4 | available queue num. |
Configuration | Options | Default | Description |
---|---|---|---|
Interrupts | |||
Interrupt priority | MCU Specific Options | Select the layer3_switch interrupt priority. | |
Ports | |||
Port 0 Fowarding | MCU Specific Options | Destination ports for port 0 fowarding | |
Port 1 Fowarding | MCU Specific Options | Destination ports for port 1 fowarding | |
Port 0 MAC address | Must be a valid MAC address | 00:11:22:33:44:55 | MAC address of port 0. |
Port 1 MAC address | Must be a valid MAC address | 00:11:22:33:44:55 | MAC address of port 1. |
Name | Name must be a valid C symbol | g_layer3_switch0 | Module name. |
Channel | 0 | 0 | Select the layer3 switch controller channel number. |
Context | Name must be a valid C symbol | NULL | Placeholder for user data. Passed to the user callback in ether_switch_callback_args_t. |
Callback | Name must be a valid C symbol | NULL | Callback provided when an ISR occurs |
Number of Layer 3 routing entries | Value must be an integer between 1 and 256 | 10 | Maximum number of Layer 3 routing entries. |
This is a basic example of transmission use of the LAYER3 SWITCH.
This is a basic example of reception use of the LAYER3 SWITCH.
Data Structures | |
struct | layer3_switch_basic_descriptor_t |
struct | layer3_switch_descriptor_t |
struct | layer3_switch_descriptor_queue_cfg_t |
struct | layer3_switch_port_cfg_t |
struct | layer3_switch_descriptor_queue_status_t |
struct | layer3_switch_ipv6_filter_address_offset_t |
struct | layer3_switch_l3_stream_filter_cfg_t |
struct | layer3_switch_frame_vlan_tag_t |
struct | layer3_switch_frame_filter_t |
struct | layer3_switch_l3_filter_t |
struct | layer3_switch_l3_update_config_t |
struct | layer3_switch_table_entry_cfg_t |
struct | layer3_switch_table_entry_t |
struct | layer3_switch_forwarding_port_cfg_t |
struct | layer3_switch_table_t |
struct | layer3_switch_table_cfg_t |
struct | layer3_switch_extended_cfg_t |
struct | layer3_switch_instance_ctrl_t |
struct layer3_switch_basic_descriptor_t |
GWCA descriptor.
struct layer3_switch_descriptor_t |
GWCA extended descriptor.
struct layer3_switch_descriptor_queue_cfg_t |
Configuration of a descriptor queue.
Data Fields | ||
---|---|---|
layer3_switch_descriptor_format_t | descriptor_format | Enable or disable extended descriptors. |
layer3_switch_queue_type_t | type | Reception queue or transmission queue. |
layer3_switch_write_back_mode_t | write_back_mode | Configure write-back to descriptor fields. |
layer3_switch_descriptor_t * | p_descriptor_array | Descriptor array that use to create queue. |
uint32_t | array_length | Length of descriptor array. This length includes terminate descriptor at the end. |
uint32_t | ports | Bitmap of ports that use this queue. |
struct layer3_switch_port_cfg_t |
Configuration of each Ethernet port.
Data Fields | |
uint8_t * | p_mac_address |
Pointer to MAC address. | |
bool | forwarding_to_cpu_enable |
Enable or disable reception on CPU. | |
void(* | p_callback )(ether_switch_callback_args_t *p_args) |
Callback provided when an ISR occurs. | |
ether_switch_callback_args_t * | p_callback_memory |
Pointer to optional callback argument memory. | |
void * | p_context |
Pointer to context to be passed into callback function. | |
struct layer3_switch_descriptor_queue_status_t |
Status of a descriptor queue.
Data Fields | ||
---|---|---|
uint32_t | head | Index at the head of the queue. This used for GetDescriptor API. |
uint32_t | tail | Index at the tail of the queue. This used for SetDescriptor API. |
bool | created | This queue is already created. |
layer3_switch_descriptor_queue_cfg_t const * |
p_queue_cfg | Configuration of this queue. |
struct layer3_switch_ipv6_filter_address_offset_t |
IP address offset for creating IPv6 filter of Layer3 forwarding.
Data Fields | ||
---|---|---|
uint8_t | offset | Offset of IPv6 address. |
layer3_switch_ip_address_direction_t | direction | Select source or destination. |
struct layer3_switch_l3_stream_filter_cfg_t |
Configuration of stream filter in Layer3 forwarding.
Data Fields | ||
---|---|---|
uint16_t | filter_field_bitmask | Bitmask of which feilds is enabled in stream filter. Use layer3_switch_l3_filter_bitmask_t. |
layer3_switch_ipv6_filter_address_offset_t | ipv6_address0 | Offset of IPv6 address 0. |
layer3_switch_ipv6_filter_address_offset_t | ipv6_address1 | Offset of IPv6 address 1. |
struct layer3_switch_frame_vlan_tag_t |
struct layer3_switch_frame_filter_t |
Frame filter of a MAC/VLAN/Layer3 forwarding entry. Set values for members required for filtering.
Data Fields | ||
---|---|---|
layer3_switch_table_entry_type_t | entry_type | Type of this entry. Selcet MAC, VLAN or Layer3. |
uint8_t * | p_destination_mac_address | Destination MAC address. |
uint8_t * | p_source_mac_address | Source MAC address. |
layer3_switch_frame_vlan_tag_t | vlan_c_tag | VLAN C-TAG. |
layer3_switch_frame_vlan_tag_t | vlan_s_tag | VLAN S-TAG. |
layer3_switch_ip_version_t | ip_version | IP version. Select IPv4, IPv6, or not IP packet. |
uint8_t | protocol | IP protocol. |
uint8_t * | p_source_ip_address | Source IP address. |
uint8_t * | p_destination_ip_address | Destination IP address. |
uint16_t | layer4_source_port | TCP/UDP source port. |
uint16_t | layer4_destination_port | TCP/UDP destination port. |
struct layer3_switch_l3_filter_t |
Store filter information of Layer3 forwarding entry.
Data Fields | ||
---|---|---|
layer3_switch_frame_filter_t | frame | Target frame format that used to Layer3 forwarding. |
struct layer3_switch_l3_update_config_t |
Configuration of a L2/L3 update feature for output frames.
Data Fields | ||
---|---|---|
uint32_t | enable_destination_ports | Destination ports that this update config is enabled. |
uint32_t | update_field_bitmask | Bit mask of which fields will be updated. Use layer3_switch_l3_update_bitmask_t. |
uint8_t * | p_mac_destination_address | MAC Destination Address. |
layer3_switch_frame_vlan_tag_t | vlan_c_tag | VLAN C-tag. |
layer3_switch_frame_vlan_tag_t | vlan_s_tag | VLAN S-tag. |
layer3_switch_forwarding_r_tag_t | r_tag_update_mode | R-TAG update setting. |
struct layer3_switch_table_entry_cfg_t |
Table entry configuration of MAC/VLAN/Layer3 forwarding.
Data Fields | ||
---|---|---|
bool | entry_enable | Enable or disable entry. If this field is false, entry will be removed. |
bool | security_enable | Entry is secure or not. |
uint32_t | destination_ports | Destination ports of forwarding. |
uint32_t | source_ports | Source ports that enable forwarding of incoming frame. |
uint32_t | destination_queue_index | Destination queue. This fields is only used when a destination port is CPU. |
uint32_t | internal_priority_update_enable | Enable to update internal priority. |
uint32_t | internal_priority_update_value | Internal priority when updating is enabled. |
union layer3_switch_table_entry_cfg_t | __unnamed__ |
struct layer3_switch_table_entry_t |
Table entry of MAC/VLAN/Layer3 forwarding.
Data Fields | ||
---|---|---|
layer3_switch_frame_filter_t | target_frame | Target frame of forwarding by this entry. |
layer3_switch_table_entry_cfg_t | entry_cfg | Configuration of this entry. |
struct layer3_switch_forwarding_port_cfg_t |
Configuration of forwarding feature for each port.
Data Fields | ||
---|---|---|
bool | mac_table_enable | Enable MAC table and forwarding feature. |
bool | mac_reject_unknown | Reject frame with unknown MAC address. |
bool | mac_hardware_learning_enable | Enable hardware learning and migration. |
bool | vlan_table_enable | Enable VLAN table and forwarding feature. |
bool | vlan_reject_unknown | Reject frame with unknown VLAN ID. |
layer3_switch_vlan_ingress_mode_t | vlan_ingress_mode | Select Tag-based VLAN or Port-based VLAN for incoming frame. |
layer3_switch_vlan_egress_mode_t | vlan_egress_mode | Tagging/untagging mode for outgoing frame. |
layer3_switch_frame_vlan_tag_t | vlan_s_tag | S-TAG of this port. When egress mode is hardware SC-TAG, add this to outgoing frame. |
layer3_switch_frame_vlan_tag_t | vlan_c_tag | C-TAG of this port. When egress mode is hardware C-TAG, add this to outgoing frame. |
bool | layer3_table_enable | Enable Layer3 table and forwarding feature. |
bool | layer3_reject_unknown | Reject frame that not found in Layer3 table. |
bool | layer3_ipv4_filter_enable | Enable IPv4 stream filter. |
bool | layer3_ipv6_filter_enable | Enable IPv6 stream filter. |
bool | layer3_l2_filter_enable | Enable L2 stream filter. |
struct layer3_switch_table_t |
Forwarding table containing MAC/VLAN/Layer3 forwarding entries.
Data Fields | ||
---|---|---|
layer3_switch_table_entry_t * | p_mac_entry_list | List of MAC entries. |
uint32_t | mac_list_length | Length of the MAC entry list. |
layer3_switch_table_entry_t * | p_vlan_entry_list | List of VLAN entries. |
uint32_t | vlan_list_length | Length of the VLAN entry list. |
layer3_switch_table_entry_t * | p_l3_entry_list | List of Layer3 entries. |
uint32_t | l3_list_length | Length of the Layer3 entry list. |
struct layer3_switch_table_cfg_t |
Configuration of the forwarding table.
Data Fields | ||
---|---|---|
layer3_switch_table_t * | p_table | Pointer to forwarding table. |
layer3_switch_forwarding_port_cfg_t | port_cfg_list[BSP_FEATURE_ETHER_MAX_CHANNELS+1] | Forwarding configuration of each port. |
uint32_t | unsecure_entry_maximum_num | Maximum number of unsecure entries. |
bool | mac_entry_aging_enable | Enable aging feature of MAC table. |
uint32_t | mac_entry_aging_time_sec | Time[s] to delete an entry by aging. |
layer3_switch_vlan_mode_t | vlan_mode | VLAN mode options: NO VLAN, C-TAG, or SC-TAG. |
layer3_switch_l3_stream_filter_cfg_t | l3_stream_filter_cfg | Configuration of stream filter in Layer3 forwarding. |
struct layer3_switch_extended_cfg_t |
ESWM extension configures each Ethernet port and forwarding feature.
Data Fields | ||
---|---|---|
ether_phy_instance_t const * | p_ether_phy_instances[BSP_FEATURE_ETHER_MAX_CHANNELS] | List of pointers to ETHER_PHY instance. |
uint32_t | fowarding_target_port_masks[BSP_FEATURE_ETHER_MAX_CHANNELS] | List of ports to which incoming frames are forwarded. |
uint8_t * | p_mac_addresses[BSP_FEATURE_ETHER_MAX_CHANNELS] | MAC address of each port. |
layer3_switch_l3_filter_t * | l3_filter_list | Filter list of Layer3 routing. |
uint32_t | l3_filter_list_length | Length of Layer3 filter list. |
struct layer3_switch_instance_ctrl_t |
LAYER3_SWITCH control block. DO NOT INITIALIZE. Initialization occurs when ether_switch_api_t::open is called.
Data Fields | |
uint32_t | open |
Used to determine if the channel is configured. | |
ether_switch_cfg_t const * | p_cfg |
Pointer to initial configurations. | |
R_GWCA0_Type * | p_gwca_reg |
Pointer to GWCA register. | |
uint32_t | allocated_descriptor_queue_index |
Index of the descriptor pool. | |
layer3_switch_basic_descriptor_t | p_descriptor_queue_list [LAYER3_SWITCH_CFG_AVAILABLE_QUEUE_NUM] |
Descriptor queue lists used by hardware. | |
layer3_switch_descriptor_queue_status_t | p_queues_status [LAYER3_SWITCH_CFG_AVAILABLE_QUEUE_NUM] |
Status of each descriptor queues. | |
layer3_switch_port_cfg_t | p_port_cfg_list [BSP_FEATURE_ETHER_MAX_CHANNELS] |
Configuration for each port. | |
layer3_switch_table_status_t | table_status |
Forwarding table is initialized or not. | |
uint32_t | l3_entry_count |
Counts of valid LAYER3 entry. | |
uint8_t | l3_routing_number |
Routing number for L2/L3 update feature. | |
uint8_t | l3_remapping_number |
Remapping number for L2/L3 update feature. | |
void(* | p_callback )(ether_switch_callback_args_t *p_args) |
Callback provided when an ISR occurs. | |
ether_switch_callback_args_t * | p_callback_memory |
Pointer to optional callback argument memory. | |
void * | p_context |
Pointer to context to be passed into callback function. | |
GWCA descriptor type.
VLAN egress mode determines the VLAN tag that is added to output frames.
R-TAG filed update options.
Frame filters options for layer3 forwarding.
Enable L2/L3 update feature.
fsp_err_t R_LAYER3_SWITCH_Open | ( | ether_switch_ctrl_t *const | p_ctrl, |
ether_switch_cfg_t const *const | p_cfg | ||
) |
Initializes the switch module and applies configurations. Implements ether_switch_api_t::open.
FSP_SUCCESS | Channel opened successfully. |
FSP_ERR_ASSERTION | Pointer to control block, config structure or extended config structure is NULL. |
FSP_ERR_ALREADY_OPEN | Control block has already been opened or channel is being used by another instance. Call close() then open() to reconfigure. |
FSP_ERR_ETHER_ERROR_PHY_COMMUNICATION | Initialization of PHY-LSI failed. |
FSP_ERR_INVALID_ARGUMENT | Invalid configuration value. |
fsp_err_t R_LAYER3_SWITCH_Close | ( | ether_switch_ctrl_t *const | p_ctrl | ) |
Disables interrupts and stop module. Implements ether_switch_api_t::close.
FSP_SUCCESS | Channel successfully closed. |
FSP_ERR_ASSERTION | Pointer to control block is NULL. |
FSP_ERR_NOT_OPEN | Control block is not open. |
fsp_err_t R_LAYER3_SWITCH_CreateDescriptorQueue | ( | ether_switch_ctrl_t *const | p_ctrl, |
uint32_t *const | p_queue_index, | ||
const layer3_switch_descriptor_queue_cfg_t *const | p_queue_cfg | ||
) |
Create a new descriptor queue and set it to LINKFIX table. This function must be called before calling R_LAYER3_SWITCH_SetDescriptor and R_LAYER3_SWITCH_GetDescriptor.
FSP_SUCCESS | Descipritor created successfully. |
FSP_ERR_ASSERTION | Pointer to control block is NULL. |
FSP_ERR_NOT_OPEN | Control block is not open. |
FSP_ERR_INVALID_POINTER | Pointer to a argument is NULL. |
FSP_ERR_OUT_OF_MEMORY | Descriptor queue list is depleted. |
fsp_err_t R_LAYER3_SWITCH_SetDescriptor | ( | ether_switch_ctrl_t *const | p_ctrl, |
uint32_t | queue_index, | ||
const layer3_switch_descriptor_t *const | p_descriptor | ||
) |
Set descripotor data to a target descriptor.
FSP_SUCCESS | Descriptor set successfully. |
FSP_ERR_ASSERTION | Pointer to control block is NULL. |
FSP_ERR_NOT_OPEN | Control block is not open. |
FSP_ERR_INVALID_POINTER | Pointer to a argument is NULL. |
FSP_ERR_INVALID_ARGUMENT | Queue index is invalid. |
FSP_ERR_NOT_INITIALIZED | This descriptor queue is not created. |
FSP_ERR_IN_USE | Target descriptor is now running. |
FSP_ERR_OVERFLOW | Descriptor queue is full. |
fsp_err_t R_LAYER3_SWITCH_GetDescriptor | ( | ether_switch_ctrl_t *const | p_ctrl, |
uint32_t | queue_index, | ||
layer3_switch_descriptor_t *const | p_descriptor | ||
) |
Get descripotor data from a target descriptor.
FSP_SUCCESS | Descriptor got successfully. |
FSP_ERR_ASSERTION | Pointer to control block is NULL. |
FSP_ERR_NOT_OPEN | Control block is not open. |
FSP_ERR_INVALID_POINTER | Pointer to a argument is NULL. |
FSP_ERR_INVALID_ARGUMENT | Queue index is invalid. |
FSP_ERR_NOT_INITIALIZED | This descriptor queue is not created or target descriptor is not set. |
FSP_ERR_IN_USE | Target descriptor is now running. |
fsp_err_t R_LAYER3_SWITCH_StartDescriptorQueue | ( | ether_switch_ctrl_t *const | p_ctrl, |
uint32_t | queue_index | ||
) |
Reload and enable a descriptor queue. In a TX descriptor queue, the queue start transmission. In a RX descriptor queue, the queue start reception.
FSP_SUCCESS | Descriptor queue started successfully. |
FSP_ERR_ASSERTION | Pointer to control block is NULL. |
FSP_ERR_NOT_OPEN | Control block is not open. |
FSP_ERR_INVALID_ARGUMENT | Queue index is invalid. |
FSP_ERR_NOT_INITIALIZED | Target descriptor queue is not created. |
FSP_ERR_IN_USE | Target descriptor queue is already running. |
fsp_err_t R_LAYER3_SWITCH_CallbackSet | ( | ether_switch_ctrl_t *const | p_ctrl, |
void(*)(ether_switch_callback_args_t *) | p_callback, | ||
void *const | p_context, | ||
ether_switch_callback_args_t *const | p_callback_memory | ||
) |
Updates the user callback with the option to provide memory for the callback argument structure.
FSP_SUCCESS | Callback updated successfully. |
FSP_ERR_ASSERTION | Pointer to control block is NULL. |
FSP_ERR_NOT_OPEN | The control block has not been opened. |
FSP_ERR_NO_CALLBACK_MEMORY | p_callback is non-secure and p_callback_memory is either secure or NULL. |
fsp_err_t R_LAYER3_SWITCH_ConfigurePort | ( | ether_switch_ctrl_t *const | p_ctrl, |
uint8_t | port, | ||
layer3_switch_port_cfg_t * | p_port_cfg | ||
) |
Configure Ethernet port features, including callback function for each port.
FSP_SUCCESS | Port configured successfully. |
FSP_ERR_ASSERTION | Pointer to control block is NULL.. |
FSP_ERR_NOT_OPEN | The control block has not been opened. |
FSP_ERR_INVALID_POINTER | Pointer to a argument is NULL. |
FSP_ERR_INVALID_ARGUMENT | Port number is invalid. |
fsp_err_t R_LAYER3_SWITCH_AddTableEntry | ( | ether_switch_ctrl_t *const | p_ctrl, |
layer3_switch_frame_filter_t const *const | p_target_frame, | ||
layer3_switch_table_entry_cfg_t const *const | p_entry_cfg | ||
) |
Add or update an entry of the forwarding table.
FSP_SUCCESS | Successfully add/updated an entry into the table. |
FSP_ERR_ASSERTION | Pointer to control block is NULL. |
FSP_ERR_NOT_OPEN | The control block has not been opened. |
FSP_ERR_INVALID_POINTER | Pointer to a argument is NULL. |
FSP_ERR_OVERFLOW | The number of unsecure entries exceeded the configured value. |
FSP_ERR_WRITE_FAILED | A hardware error occurred while learning the entry. |
FSP_ERR_INVALID_ARGUMENT | Target frame or entry type is invalid. |
FSP_ERR_INVALID_MODE | VLAN feature is disabled and a VLAN entry is passed. |
fsp_err_t R_LAYER3_SWITCH_SearchTableEntry | ( | ether_switch_ctrl_t *const | p_ctrl, |
layer3_switch_frame_filter_t const *const | p_target_frame, | ||
layer3_switch_table_entry_cfg_t *const | p_entry_cfg | ||
) |
Search an entry from the forwarding table.
FSP_SUCCESS | The entry is found successfully. |
FSP_ERR_ASSERTION | Pointer to control block is NULL. |
FSP_ERR_NOT_OPEN | The control block has not been opened. |
FSP_ERR_INVALID_POINTER | Pointer to a argument is NULL. |
FSP_ERR_NOT_FOUND | The entry is not found in the table. |
FSP_ERR_INVALID_ARGUMENT | Target frame or entry type is invalid. |
FSP_ERR_INVALID_MODE | VLAN feature is disabled and a VLAN entry is passed. |
fsp_err_t R_LAYER3_SWITCH_ConfigureTable | ( | ether_switch_ctrl_t *const | p_ctrl, |
layer3_switch_table_cfg_t const *const | p_table_cfg | ||
) |
Configure and initailze an forwarding table.
FSP_SUCCESS | Table configured successfully. |
FSP_ERR_ASSERTION | Pointer to control block is NULL. |
FSP_ERR_NOT_OPEN | The control block has not been opened. |
FSP_ERR_INVALID_POINTER | Pointer to a argument is NULL. |
FSP_ERR_WRITE_FAILED | Failed to add entries. |
fsp_err_t R_LAYER3_SWITCH_GetTable | ( | ether_switch_ctrl_t *const | p_ctrl, |
layer3_switch_table_t *const | p_table | ||
) |
Get a pointer to the forwarding table.
FSP_SUCCESS | Table got successfully. |
FSP_ERR_ASSERTION | Pointer to control block is NULL. |
FSP_ERR_NOT_OPEN | The control block has not been opened. |
FSP_ERR_INVALID_POINTER | Pointer to a argument is NULL. |
FSP_ERR_INVALID_MODE | VLAN feature is disabled and a VLAN entry list is passed. |