From e280ccd2f92d6e62f818e5604e8e718aa9229e0c Mon Sep 17 00:00:00 2001 From: logicog Date: Sun, 15 Mar 2026 13:09:55 +0100 Subject: [PATCH] Use RTL descriptor definition --- rtlplayground.c | 78 ++++++++++++++++++++++++------------------------- uip/uip_arp.c | 7 +++-- uip/uipopt.h | 2 +- 3 files changed, 43 insertions(+), 44 deletions(-) diff --git a/rtlplayground.c b/rtlplayground.c index 6f35f19..2be13b1 100644 --- a/rtlplayground.c +++ b/rtlplayground.c @@ -149,43 +149,40 @@ struct eth_in { u16_t ether_type; }; -struct rtl_dot1q_frame { - union { - struct { - uint8_t tx_seq; - uint8_t chksum_flags; // 0x7 enables Checksums for frame header, L2 and L3 - uint8_t reserved_1 [2]; - uint16_t len; // Length is Little Endian - uint8_t reserved_2 [2]; - struct uip_eth_addr dst; - struct uip_eth_addr src; - uint16_t tpid; - uint16_t tci; - } q_frame; - struct { - uint8_t padding[VLAN_TAG_SIZE]; // Pad to the size of a RTL-VLAN tag or dot1q-tag - uint8_t tx_seq; - uint8_t chksum_flags; // 0x7 enables Checksums for frame header, L2 and L3 - uint8_t reserved_1 [2]; - uint16_t len; // Length is Little Endian - uint8_t reserved_2 [2]; - struct uip_eth_addr dst; - struct uip_eth_addr src; - } nonq_frame; - }; -}; - // Dot 1Q tag size is the size of tpid + tci #define DOT_1Q_TAG_SIZE 4 +struct q_frame { + uint8_t tx_seq; + uint8_t chksum_flags; // 0x7 enables Checksums for frame header, L2 and L3 + uint8_t reserved_1 [2]; + uint16_t len; // Length is Little Endian + uint8_t reserved_2 [2]; + struct uip_eth_addr dst; + struct uip_eth_addr src; + uint16_t tpid; + uint16_t tci; +}; + +struct nonq_frame { + uint8_t padding[DOT_1Q_TAG_SIZE]; + uint8_t tx_seq; + uint8_t chksum_flags; // 0x7 enables Checksums for frame header, L2 and L3 + uint8_t reserved_1 [2]; + uint16_t len; // Length is Little Endian + uint8_t reserved_2 [2]; + struct uip_eth_addr dst; + struct uip_eth_addr src; +}; + #define ETH_IN ((__xdata struct eth_in *)&uip_buf[0]) #define ETHERTYPE_OFFSET (12 + VLAN_TAG_SIZE + RTL_TAG_SIZE) // The output frame structure with initial frame descriptor including padding -#define FRAME (((__xdata struct rtl_dot1q_frame *)&uip_buf[0])->nonq_frame) +#define FRAME ((__xdata struct nonq_frame *)&uip_buf[0]) // The output frame structure with 802.1Q field and the padding moved before the buffer-start -#define FRAME_Q (((__xdata struct rtl_dot1q_frame *)&uip_buf[-VLAN_TAG_SIZE])->q_frame) +#define FRAME_Q ((__xdata struct q_frame *)&uip_buf[0]) void isr_timer0(void) __interrupt(1) { @@ -613,13 +610,13 @@ void nic_tx_packet(uint16_t ring_ptr) */ if (management_vlan) { SFR_NIC_DATA_U16LE = (uint16_t) uip_buf; - len = FRAME_Q.len; + len = FRAME_Q->len; /* (__xdata struct rtl_dot1q_frame *)uip_buf #define FRAME (((__xdata struct rtl_dot1q_frame *)&uip_buf[0]).nonq_frame)*/ } else { SFR_NIC_DATA_U16LE = (uint16_t) uip_buf + VLAN_TAG_SIZE; - len = FRAME.len; + len = FRAME->len; } #ifdef RXTXDBG @@ -992,21 +989,21 @@ uint8_t sfp_read_reg(uint8_t slot, uint8_t reg) void tcpip_output(void) { // Add TX-TAG - FRAME.tx_seq = tx_seq++; - FRAME.chksum_flags = 0x07; // Enable all checksums - FRAME.reserved_1[0] = 0x00; FRAME.reserved_1[1] = 0x00; - FRAME.len = uip_len; - FRAME.reserved_2[0] = 0x00; FRAME.reserved_2[1] = 0x00; + FRAME->tx_seq = tx_seq++; + FRAME->chksum_flags = 0x07; // Enable all checksums + FRAME->reserved_1[0] = 0x00; FRAME->reserved_1[1] = 0x00; + FRAME->len = uip_len; + FRAME->reserved_2[0] = 0x00; FRAME->reserved_2[1] = 0x00; // For the management VLAN we insert an 802.1Q VLAN tag if (management_vlan) { // Shift the ethernet header before the HW type including the rtl_frame_desc to the beginning of uip_buf // to allow space to insert the dot 1Q tag - for (uint8_t i = 0; i < sizeof(struct rtl_dot1q_frame) - (VLAN_TAG_SIZE * 2); i++) + for (uint8_t i = 0; i < sizeof(struct q_frame) - DOT_1Q_TAG_SIZE; i++) uip_buf[i] = uip_buf[i + DOT_1Q_TAG_SIZE]; - FRAME_Q.len += DOT_1Q_TAG_SIZE; - FRAME_Q.tpid = HTONS(0x8100); // Change ether-type to Dot1Q - FRAME_Q.tci = HTONS(management_vlan); + FRAME_Q->len += DOT_1Q_TAG_SIZE; + FRAME_Q->tpid = HTONS(0x8100); // Change ether-type to Dot1Q + FRAME_Q->tci = HTONS(management_vlan); } reg_read_m(RTL837X_REG_CPU_TX_CURR_PKT); @@ -1062,6 +1059,7 @@ void handle_rx(void) print_string(" RX-VLAN: "); print_short(rx_packet_vlan); write_char('\n'); print_string(" RX dst: "); print_byte(uip_buf[0]); print_byte(uip_buf[1]); print_byte(uip_buf[2]); print_byte(uip_buf[3]); print_byte(uip_buf[4]); print_byte(uip_buf[5]); write_char('\n'); + print_string(" MGMT-VLAN: "); print_short(management_vlan); write_char('\n'); #endif if (stpEnabled && uip_buf[0] == 0x01 && uip_buf[1] == 0x80 && uip_buf[2] == 0xc2 // STP packet? && uip_buf[3] == 0x00 && uip_buf[4] == 0x00 && uip_buf[5] == 0x00) { @@ -2014,7 +2012,7 @@ void main(void) uip_arp_init(); httpd_init(); - management_vlan = 0; // Disabled + management_vlan = 1; // Default management VLAN is 1 setup_i2c(); setup_sfp_gpio(); diff --git a/uip/uip_arp.c b/uip/uip_arp.c index 8c9b2a8..8b8bd00 100644 --- a/uip/uip_arp.c +++ b/uip/uip_arp.c @@ -68,7 +68,8 @@ struct arp_hdr_i { struct uip_eth_hdr ethhdr; - uint8_t rtl_tag[RTL_TAG_SIZE + VLAN_TAG_SIZE]; + struct rtl_tag rtl_tag; + struct vlan_tag vlan_tag; u16_t hwtype; u16_t protocol; u8_t hwlen; @@ -131,8 +132,8 @@ static __xdata u8_t arptime; static __xdata u8_t tmpage; #define BUF ((__xdata struct arp_hdr_i *)&uip_buf[0]) -#define BUF_O ((__xdata struct arp_hdr_o *)&uip_buf[RTL_TAG_SIZE + VLAN_TAG_SIZE]) -#define IPBUF ((__xdata struct ethip_hdr *)&uip_buf[RTL_TAG_SIZE + VLAN_TAG_SIZE]) +#define BUF_O ((__xdata struct arp_hdr_o *)&uip_buf[RTL_FRAME_DESC_SIZE]) +#define IPBUF ((__xdata struct ethip_hdr *)&uip_buf[RTL_FRAME_DESC_SIZE]) /*-----------------------------------------------------------------------------------*/ /** * Initialize the ARP module. diff --git a/uip/uipopt.h b/uip/uipopt.h index b1b0604..16046cf 100644 --- a/uip/uipopt.h +++ b/uip/uipopt.h @@ -447,7 +447,7 @@ void uip_log(char *msg); #ifdef UIP_CONF_LLH_LEN #define UIP_LLH_LEN UIP_CONF_LLH_LEN #else /* UIP_CONF_LLH_LEN */ -#define UIP_LLH_LEN ETHER_HEADER_SIZE + RTL_TAG_SIZE + VLAN_TAG_SIZE +#define UIP_LLH_LEN ETHER_HEADER_SIZE + RTL_FRAME_DESC_SIZE #endif /* UIP_CONF_LLH_LEN */ /** @} */