mirror of
https://github.com/logicog/RTLPlayground.git
synced 2026-08-30 14:52:51 +08:00
De-magic NIC rx and tx registers, cleanup
This commit is contained in:
+15
-11
@@ -36,8 +36,21 @@
|
||||
// the RTL_FRAME_TAG_ID is used as part of an 8-byte tag. When VLAN is activated,
|
||||
// the VLAN tag is inserted after the RTL tag
|
||||
// See here for the RTL tag: https://github.com/torvalds/linux/commit/1521d5adfc2b557e15f97283c8b7ad688c3ebc40
|
||||
#define RTL_TAG_SIZE 8
|
||||
#define VLAN_TAG_SIZE 4
|
||||
struct rtl_tag {
|
||||
uint16_t tag; // This is 0x8899 for the RTL837X
|
||||
uint8_t version; // Version is 4
|
||||
uint8_t reason;
|
||||
uint16_t flags;
|
||||
uint16_t pmask; // A bit mask for a TX pkt, 4-bit port-number for RX
|
||||
};
|
||||
|
||||
struct vlan_tag {
|
||||
uint16_t svlan; // Service VLAN
|
||||
uint16_t vlan;
|
||||
};
|
||||
|
||||
#define RTL_TAG_SIZE (sizeof (struct rtl_tag))
|
||||
#define VLAN_TAG_SIZE (sizeof (struct vlan_tag))
|
||||
#define RTL_FRAME_TAG_ID 0x8899
|
||||
|
||||
// For RX and TX, an 8 byte header describing the frame to be moved to the Asic
|
||||
@@ -70,15 +83,6 @@ struct flash_region_t {
|
||||
|
||||
extern __xdata uint8_t uip_buf[UIP_CONF_BUFFER_SIZE+2];
|
||||
|
||||
// 8899 04 0000 20 0004
|
||||
struct rtl_tag {
|
||||
uint16_t tag;
|
||||
uint8_t version;
|
||||
uint8_t reason;
|
||||
uint16_t flags;
|
||||
uint16_t pmask; // A bit mask for a TX pkt, 4-bit port-number for RX
|
||||
};
|
||||
|
||||
// Headers for calls in the common code area (HOME/BANK0)
|
||||
void print_string(__code char *p);
|
||||
void print_long(__xdata uint32_t a);
|
||||
|
||||
+6
-3
@@ -93,11 +93,14 @@
|
||||
*/
|
||||
#define RTL837X_REG_NIC_BUFFSIZE_TX 0x7844
|
||||
#define RTL837X_REG_NIC_RXBUFF_RX 0x7848
|
||||
#define RTL837X_REG_NIC_RXCMD 0x784c
|
||||
#define RTL837X_REG_NIC_TXCMD 0x7850
|
||||
#define RTL837X_REG_RX_CTRL 0x785c
|
||||
#define RTL837X_REG_TX_CTRL 0x7860
|
||||
#define RTL837X_REG_RX_AVAIL 0x7874
|
||||
#define RTL837X_REG_RX_RINGPTR 0x787c
|
||||
#define RTL837X_REG_RX_DONE 0x784c
|
||||
#define RTL837X_REG_NIC_RX_BUFF_DATA 0x7874
|
||||
#define RTL837X_REG_CPU_RX_CURR_PKT 0x787c
|
||||
#define RTL837X_REG_NIC_TX_CURR_PKT 0x7884
|
||||
#define RTL837X_REG_CPU_TX_CURR_PKT 0x7890
|
||||
#define RTL837X_REG_CPU_TAG 0x6720
|
||||
#define RTL837X_REG_CPU_TAG_AWARE_PMASK 0x603C
|
||||
#define RTL837X_REG_MAC_FORCE_MODE 0x6344
|
||||
|
||||
+12
-15
@@ -819,7 +819,7 @@ void tcpip_output(void)
|
||||
uip_buf[VLAN_TAG_SIZE + 2] = uip_buf[VLAN_TAG_SIZE + 3] = 0;
|
||||
uip_buf[VLAN_TAG_SIZE + 6] = uip_buf[VLAN_TAG_SIZE + 7] = 0;
|
||||
|
||||
reg_read_m(0x7890);
|
||||
reg_read_m(RTL837X_REG_CPU_TX_CURR_PKT);
|
||||
uint16_t ring_ptr = ((uint16_t)sfr_data[2]) << 8;
|
||||
ring_ptr |= sfr_data[3];
|
||||
|
||||
@@ -835,20 +835,20 @@ void tcpip_output(void)
|
||||
// Move data over from xmem buffer to ASIC side using DMA
|
||||
nic_tx_packet(ring_ptr);
|
||||
|
||||
reg_read_m(0x7884); // actual bytes sent, for now we assume everything worked
|
||||
// New position of the ring-pointer on the NIC-side indicates number of bytes transmitted
|
||||
reg_read_m(RTL837X_REG_NIC_TX_CURR_PKT);
|
||||
|
||||
// Do actual TX of data on ASIC side
|
||||
sfr_data[0] = sfr_data[1] = sfr_data[2] = 0;
|
||||
sfr_data[3] = 0x1;
|
||||
reg_write_m(0x7850);
|
||||
REG_SET(RTL837X_REG_NIC_TXCMD, 1);
|
||||
}
|
||||
|
||||
|
||||
void handle_rx(void)
|
||||
{
|
||||
reg_read_m(RTL837X_REG_RX_AVAIL);
|
||||
// Check the amount of data available on the NIC/ASIC side
|
||||
reg_read_m(RTL837X_REG_NIC_RX_BUFF_DATA);
|
||||
if (sfr_data[2] != 0 || sfr_data[3] != 0) {
|
||||
reg_read_m(RTL837X_REG_RX_RINGPTR);
|
||||
reg_read_m(RTL837X_REG_CPU_RX_CURR_PKT);
|
||||
uint16_t ring_ptr = ((uint16_t)sfr_data[2]) << 8;
|
||||
ring_ptr |= sfr_data[3];
|
||||
ring_ptr <<= 3;
|
||||
@@ -872,16 +872,13 @@ void handle_rx(void)
|
||||
write_char(' ');
|
||||
}
|
||||
#endif
|
||||
sfr_data[0] = sfr_data[1] = sfr_data[2] = 0;
|
||||
sfr_data[3] = 0x1;
|
||||
reg_write_m(RTL837X_REG_RX_DONE);
|
||||
REG_SET(RTL837X_REG_NIC_RXCMD, 1);
|
||||
uip_len = (((uint16_t)rx_headers[5]) << 8) | rx_headers[4];
|
||||
// write_char('>'); print_byte(uip_buf[ETHERTYPE_OFFSET]); write_char('<');
|
||||
// write_char('>'); print_byte(uip_buf[ETHERTYPE_OFFSET + 1]); write_char('<');
|
||||
// Check for ARP packet
|
||||
rx_packet_vlan = uip_buf[12 + RTL_TAG_SIZE + 2] & 0xf;
|
||||
|
||||
// Retrieve VLAN from VLAN-tag
|
||||
rx_packet_vlan = uip_buf[2 * sizeof (struct uip_eth_addr) + RTL_TAG_SIZE + 2] & 0xf;
|
||||
rx_packet_vlan <<= 8;
|
||||
rx_packet_vlan |= uip_buf[12 + RTL_TAG_SIZE + 3];
|
||||
rx_packet_vlan |= uip_buf[2 * sizeof (struct uip_eth_addr) + RTL_TAG_SIZE + 3];
|
||||
#ifdef RXTXDBG
|
||||
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]);
|
||||
|
||||
Reference in New Issue
Block a user