mirror of
https://github.com/logicog/RTLPlayground.git
synced 2026-08-30 14:52:51 +08:00
Add Bandwidth control for ingress/egreess at port
This commit is contained in:
@@ -25,7 +25,8 @@ all: create_build_dir $(VERSION_HEADER) $(SUBDIRS) $(BUILDDIR)rtlplayground.bin
|
||||
create_build_dir:
|
||||
mkdir -p $(BUILDDIR)
|
||||
|
||||
SRCS = rtlplayground.c rtl837x_flash.c rtl837x_leds.c rtl837x_phy.c rtl837x_port.c cmd_parser.c html_data.c rtl837x_igmp.c rtl837x_stp.c rtl837x_pins.c dhcp.c machine.c cmd_editor.c
|
||||
SRCS = rtlplayground.c rtl837x_flash.c rtl837x_leds.c rtl837x_phy.c rtl837x_port.c cmd_parser.c html_data.c rtl837x_igmp.c \
|
||||
rtl837x_stp.c rtl837x_pins.c dhcp.c machine.c cmd_editor.c rtl837x_bandwidth.c
|
||||
OBJS = ${SRCS:%.c=$(BUILDDIR)%.rel}
|
||||
OBJS += uip/$(BUILDDIR)/timer.rel uip/$(BUILDDIR)/uip-fw.rel uip/$(BUILDDIR)/uip-neighbor.rel uip/$(BUILDDIR)/uip-split.rel uip/$(BUILDDIR)/uip.rel uip/$(BUILDDIR)/uip_arp.rel uip/$(BUILDDIR)/uiplib.rel httpd/$(BUILDDIR)/httpd.rel httpd/$(BUILDDIR)/page_impl.rel
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
#include "rtl837x_sfr.h"
|
||||
#include "rtl837x_stp.h"
|
||||
#include "rtl837x_igmp.h"
|
||||
#include "rtl837x_bandwidth.h"
|
||||
#include "dhcp.h"
|
||||
#include "uip/uip.h"
|
||||
#include "version.h"
|
||||
@@ -697,6 +698,79 @@ void parse_eee(void)
|
||||
}
|
||||
|
||||
|
||||
void parse_bw(void)
|
||||
{
|
||||
__xdata uint8_t port;
|
||||
__xdata uint32_t bw = 0;
|
||||
|
||||
if (cmd_words_b[3] < 0) // Check for at least 2 arguments
|
||||
goto err;
|
||||
|
||||
port = cmd_buffer[cmd_words_b[2]] - '1';
|
||||
if (port < 0 || port > 9)
|
||||
goto err;
|
||||
|
||||
port = machine.phys_to_log_port[port];
|
||||
|
||||
if (cmd_compare(1, "status")) {
|
||||
bandwidth_status(port);
|
||||
return;
|
||||
}
|
||||
|
||||
if (cmd_words_b[4] < 0) // Check for at least 3 arguments
|
||||
goto err;
|
||||
|
||||
if (cmd_compare(3, "drop")) {
|
||||
if (cmd_compare(1, "in")) {
|
||||
bandwidth_ingress_drop(port);
|
||||
return;
|
||||
}
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (cmd_compare(3, "fc")) {
|
||||
if (cmd_compare(1, "in")) {
|
||||
bandwidth_ingress_fc(port);
|
||||
return;
|
||||
}
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (cmd_compare(3, "off")) {
|
||||
if (cmd_compare(1, "in")) {
|
||||
bandwidth_ingress_disable(port);
|
||||
return;
|
||||
} else if (cmd_compare(1, "out")) {
|
||||
bandwidth_egress_disable(port);
|
||||
return;
|
||||
}
|
||||
goto err;
|
||||
}
|
||||
|
||||
uint8_t hex_size = atoi_hex(cmd_words_b[3]);
|
||||
if (hex_size == 0 || hex_size > 4) {
|
||||
goto err;
|
||||
}
|
||||
uint8_t i = 0;
|
||||
while (hex_size) {
|
||||
hex_size--;
|
||||
*(((uint8_t *) &bw) + hex_size) = hexvalue[i++];
|
||||
}
|
||||
|
||||
if (cmd_compare(1, "in")) {
|
||||
bandwidth_ingress_set(port, bw);
|
||||
} else if (cmd_compare(1, "out")) {
|
||||
bandwidth_egress_set(port, bw);
|
||||
} else {
|
||||
goto err;
|
||||
}
|
||||
|
||||
return;
|
||||
|
||||
err:
|
||||
print_string("usage: bw [in|out|status] <port> [<hexvalue>|off|drop|fc]\n");
|
||||
}
|
||||
|
||||
// Parse command into words
|
||||
uint8_t cmd_tokenize(void) __banked
|
||||
{
|
||||
@@ -939,6 +1013,8 @@ void cmd_parser(void) __banked
|
||||
parse_passwd();
|
||||
} else if (cmd_compare(0, "eee")) {
|
||||
parse_eee();
|
||||
} else if (cmd_compare(0, "bw")) {
|
||||
parse_bw();
|
||||
} else if (cmd_compare(0, "version")) {
|
||||
print_sw_version();
|
||||
} else if (cmd_compare(0, "time")) {
|
||||
|
||||
+17
-3
@@ -44,7 +44,6 @@ void bandwidth_ingress_set(uint8_t port, __xdata uint32_t bw) __banked
|
||||
|
||||
// We enable Flow Control instead of just dropping packets
|
||||
reg_bit_set(RTL837X_IGBW_PORT_FC_CTRL, port);
|
||||
print_string("RTL837X_IGBW_PORT_FC_CTRL:"); print_reg(RTL837X_IGBW_PORT_FC_CTRL); write_char('\n');
|
||||
}
|
||||
|
||||
|
||||
@@ -55,6 +54,13 @@ void bandwidth_ingress_drop(uint8_t port) __banked
|
||||
}
|
||||
|
||||
|
||||
void bandwidth_ingress_fc(uint8_t port) __banked
|
||||
{
|
||||
reg_bit_set(RTL837X_IGBW_PORT_FC_CTRL, port);
|
||||
print_string("RTL837X_IGBW_PORT_FC_CTRL:"); print_reg(RTL837X_IGBW_PORT_FC_CTRL); write_char('\n');
|
||||
}
|
||||
|
||||
|
||||
void bandwidth_ingress_disable(uint8_t port) __banked
|
||||
{
|
||||
print_string("Ingress bandwidth limit disabled, port "); print_byte(port); write_char('\n');
|
||||
@@ -89,7 +95,11 @@ void bandwidth_status(uint8_t port) __banked
|
||||
if (sfr_data[1] & 0x10) {
|
||||
print_string("enabled: ");
|
||||
sfr_data[1] &= 0xef;
|
||||
print_sfr_data();
|
||||
print_string("0x");
|
||||
print_byte(sfr_data[1]);
|
||||
print_byte(sfr_data[2]);
|
||||
print_byte(sfr_data[3]);
|
||||
write_char('0');
|
||||
write_char('\n');
|
||||
} else {
|
||||
print_string("disabled\n");
|
||||
@@ -100,7 +110,11 @@ void bandwidth_status(uint8_t port) __banked
|
||||
if (sfr_data[1] & 0x10) {
|
||||
print_string("enabled: ");
|
||||
sfr_data[1] &= 0xef;
|
||||
print_sfr_data();
|
||||
print_string("0x");
|
||||
print_byte(sfr_data[1]);
|
||||
print_byte(sfr_data[2]);
|
||||
print_byte(sfr_data[3]);
|
||||
write_char('0');
|
||||
write_char('\n');
|
||||
} else {
|
||||
print_string("disabled\n");
|
||||
|
||||
@@ -7,6 +7,7 @@ void bandwidth_setup(void) __banked;
|
||||
void bandwidth_ingress_set(uint8_t port, __xdata uint32_t bw) __banked;
|
||||
void bandwidth_ingress_disable(uint8_t port) __banked;
|
||||
void bandwidth_ingress_drop(uint8_t port) __banked;
|
||||
void bandwidth_ingress_fc(uint8_t port) __banked;
|
||||
void bandwidth_egress_set(uint8_t port, __xdata uint32_t bw) __banked;
|
||||
void bandwidth_egress_disable(uint8_t port) __banked;
|
||||
void bandwidth_status(uint8_t port) __banked;
|
||||
|
||||
@@ -285,6 +285,25 @@
|
||||
#define RTL837X_RAND_NUM0 0x107C
|
||||
#define RTL837X_RAND_NUM1 0x1080
|
||||
|
||||
/*
|
||||
* Bandwidth control
|
||||
*/
|
||||
#define RTL837X_IGBW_CTRL 0x4c10
|
||||
#define IGBW_INC_BYPASS_PKT 0x100
|
||||
#define IGBW_INC_IFG 0x80
|
||||
#define IGBW_ADM_DHCP 0x20
|
||||
#define IGBW_ADM_ARPREQ 0x10
|
||||
#define IGBW_ADM_RMA 0x08
|
||||
#define IGBW_ADM_BPDU 0x04
|
||||
#define IGBW_ADM_RTKPKT 0x02
|
||||
#define IGBW_ADM_IGMP 0x01
|
||||
#define RTL837X_IGBW_PORT_CTRL 0x4C18
|
||||
#define RTL837X_IGBW_PORT_FC_CTRL 0x4C8C
|
||||
#define RTL837X_EGBW_PORT_CTRL 0x1c34
|
||||
#define RTL837X_EGBW_CTRL 0x447c
|
||||
#define EGBW_INC_IFG 0x02
|
||||
#define EGBW_CPUMODE 0x01
|
||||
|
||||
#ifdef REGDBG
|
||||
|
||||
#define REG_SET(r, v) SFR_DATA_24 = (((uint32_t)v) >> 24) & 0xff; \
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
#include "rtl837x_stp.h"
|
||||
#include "rtl837x_igmp.h"
|
||||
#include "rtl837x_leds.h"
|
||||
#include "rtl837x_bandwidth.h"
|
||||
#include "dhcp.h"
|
||||
#include "cmd_parser.h"
|
||||
#include "cmd_editor.h"
|
||||
@@ -2090,6 +2091,7 @@ void main(void)
|
||||
vlan_setup();
|
||||
port_l2_setup();
|
||||
igmp_setup();
|
||||
bandwidth_setup();
|
||||
uip_init();
|
||||
uip_arp_init();
|
||||
httpd_init();
|
||||
|
||||
Reference in New Issue
Block a user