diff --git a/Makefile b/Makefile index 6862527..e88202b 100644 --- a/Makefile +++ b/Makefile @@ -10,7 +10,7 @@ SUBDIRSCLEAN=$(addsuffix clean,$(SUBDIRS)) all: $(SUBDIRS) rtlplayground.bin -SRCS = rtlplayground.c rtl837x_flash.c rtl837x_phy.c rtl837x_port.c cmd_parser.c html_data.c +SRCS = rtlplayground.c rtl837x_flash.c rtl837x_phy.c rtl837x_port.c cmd_parser.c html_data.c rtl837x_igmp.c OBJS = ${SRCS:.c=.rel} OBJS += uip/timer.rel uip/uip-fw.rel uip/uip-neighbor.rel uip/uip-split.rel uip/uip.rel uip/uip_arp.rel uip/uiplib.rel httpd/httpd.rel httpd/page_impl.rel diff --git a/rtl837x_igmp.c b/rtl837x_igmp.c new file mode 100644 index 0000000..032efca --- /dev/null +++ b/rtl837x_igmp.c @@ -0,0 +1,57 @@ +/* + * This is a driver implementation for the IGMP features for the RTL827x platform + * This code is in the Public Domain + */ + +// #define REGDBG +// #define DEBUG + +#include +#include "rtl837x_common.h" +#include "rtl837x_sfr.h" +#include "rtl837x_regs.h" +#include "rtl837x_igmp.h" + +extern __xdata uint8_t minPort; +extern __xdata uint8_t maxPort; +extern __xdata uint8_t nSFPPorts; +extern __xdata uint8_t cpuPort; +extern __xdata uint8_t isRTL8373; + +void igmp_setup(void) __banked +{ + uint8_t i; + + // For now, forward all unkown MC pkts (2 bits per port. 00: flood via floodmask, 01: drop, 10: trap, 11: to rport) + REG_SET(RTL837X_MC_LOOKUPMISS_ACTIONS, 0x00000000); //0x4f78 + // Define ports where unknown MC addresses are flooded to: + if (isRTL8373) { + REG_SET(RTL837X_MC_FLOODMASK, PMASK_9); // R5368-000001f8 + } else { + REG_SET(RTL837X_MC_FLOODMASK, PMASK_6); + } + + // Enable lookup of IPv4 MC addresses in table + reg_bit_set(RTL837X_L2_CTRL, 3); // 0x5350 + + // Configure per-port IGMP configuration, bits 0-10 enable MC protocol snooping, + // bits 16-24 configure max MC group used by that port. For now all protocols are flooded (01) + for (i = minPort; i <= maxPort; i++) + REG_SET(RTL837X_IGMP_PORT_CFG + (i << 2), 0x00ff7c15); +} + + +void igmp_enable(void) __banked +{ + uint8_t i; + + REG_SET(0x50bc, 00010007); // Trap control? + + // Drop unknown MC messages + REG_SET(RTL837X_MC_LOOKUPMISS_ACTIONS, 0x00015540); //0x4f78 + + // Configure per-port IGMP configuration, bits 0-10 enable MC protocol snooping, + // bits 16-24 configure max MC group used by that port. Trap to CPU (10) + for (i = minPort; i <= maxPort; i++) + REG_SET(RTL837X_IGMP_PORT_CFG + (i << 2), 0x00ff7c2a); // 0x00ff7000: Handling by ASIC (00) +} diff --git a/rtl837x_igmp.h b/rtl837x_igmp.h new file mode 100644 index 0000000..9891634 --- /dev/null +++ b/rtl837x_igmp.h @@ -0,0 +1,9 @@ +#ifndef _RTL837X_IGMP_H_ +#define _RTL837X_IGMP_H_ + +#include + +void igmp_setup(void) __banked; +void igmp_enable(void) __banked; + +#endif diff --git a/rtl837x_regs.h b/rtl837x_regs.h index a1a0c62..23705fa 100644 --- a/rtl837x_regs.h +++ b/rtl837x_regs.h @@ -143,6 +143,7 @@ */ #define RTL837X_MC_LOOKUPMISS_ACTIONS 0x4f78 #define RTL837X_IGMP_PORT_CFG 0x52a0 +#define RTL837X_MC_FLOODMASK 0x5368 #ifdef REGDBG