Commit d98ef03f authored by li hongming's avatar li hongming

optimize the tcpip_config module.

  Now it works as below:
    1. default udp tx dst mac is the gateway of node's ip.
    2. It will send arp request after getting the udp tx dst ip.
    3. It stops sending arp request after getting the udp tx dst mac addr.
parent 58e67b61
......@@ -12,7 +12,8 @@ obj-$(CONFIG_EMBEDDED_NODE) += \
dev/sfp.o \
dev/devicelist.o \
dev/rxts_calibrator.o \
dev/flash.o
dev/flash.o \
dev/tcpip_config.o
obj-$(CONFIG_WR_NODE) += \
dev/temperature.o \
......
......@@ -7,29 +7,35 @@
#include "hw/tcpip-config.h"
#include "tcpip_config.h"
enum tcpip_status tcpip_status;
uint8_t arp_count=0;
enum tcpip_status tcpip_status = TCPIP_OK;
void tcpip_init(uint8_t mac_addr[])
void tcpip_init(void)
{
volatile unsigned int *tcpip_tmp;
uint32_t tmp=0;
uint8_t tcpip_mac_addr[6];
uint8_t tmp_ip_addr[4];
uint32_t tmp_mac_addr=0;
tcpip_tmp = (unsigned int *)(BASE_TCPIP_CFG + TCPIP_MAC_HIGH16);
tmp = ((uint32_t) mac_addr[0] << 8)
| ((uint32_t) mac_addr[1]);
*tcpip_tmp = tmp;
tcpip_tmp = (unsigned int *)(BASE_TCPIP_CFG + TCPIP_MAC_LOW32);
tmp = ((uint32_t) mac_addr[2] << 24)
| ((uint32_t) mac_addr[3] << 16)
| ((uint32_t) mac_addr[4] << 8)
| ((uint32_t) mac_addr[5]);
*tcpip_tmp = tmp;
get_mac_addr(tcpip_mac_addr);
pp_printf("mac is %x:%x\n",tcpip_mac_addr[0],tcpip_mac_addr[1]);
memcpy((uint8_t *)(BASE_TCPIP_CFG + TCPIP_MAC_HIGH16 + 2), (uint8_t *)tcpip_mac_addr, 2);
memcpy((uint8_t *)(BASE_TCPIP_CFG + TCPIP_MAC_LOW32), (uint8_t *)tcpip_mac_addr+2, 4);
// default udp tx dst/src port
tcpip_tx_dst_port(2000);
tcpip_tx_src_port(2000);
tcpip_tx_dst_port(60000);
tcpip_tx_src_port(60000);
getIP(tmp_ip_addr);
// tcpip module, default IP
tcpip_ip_addr(tmp_ip_addr);
// tcpip module, default gateway & tx ip addr
tmp_ip_addr[3]=0x01;
tcpip_gateway_addr(tmp_ip_addr);
tcpip_set_hisIP(tmp_ip_addr);
// tcpip module, default subnet mask
tmp_ip_addr[0]=0xff;tmp_ip_addr[1]=0xff;tmp_ip_addr[2]=0xff;tmp_ip_addr[3]=0x00;
tcpip_subnet_addr(tmp_ip_addr);
}
void tcpip_ip_addr(uint8_t *ip)
......@@ -72,7 +78,6 @@ void tcpip_set_hisIP(uint8_t *ip)
{
memcpy((uint8_t *)(BASE_TCPIP_CFG + TCPIP_UDP_TX_DST_IP), ip, 4);
tcpip_status = TCPIP_ARP;
arp_count = 0;
}
void tcpip_get_hisIP(uint8_t *ip)
......@@ -82,25 +87,14 @@ void tcpip_get_hisIP(uint8_t *ip)
void tcpip_set_hisMAC(uint8_t mac_addr[])
{
volatile unsigned int *tcpip_tmp;
uint32_t tmp=0;
tcpip_tmp = (unsigned int *)(BASE_TCPIP_CFG + TCPIP_MAC_HIGH16);
tmp = ((uint32_t) mac_addr[0] << 8)
| ((uint32_t) mac_addr[1]);
*tcpip_tmp = tmp;
tcpip_tmp = (unsigned int *)(BASE_TCPIP_CFG + TCPIP_MAC_LOW32);
tmp = ((uint32_t) mac_addr[2] << 24)
| ((uint32_t) mac_addr[3] << 16)
| ((uint32_t) mac_addr[4] << 8)
| ((uint32_t) mac_addr[5]);
*tcpip_tmp = tmp;
memcpy((uint8_t *)(BASE_TCPIP_CFG + TCPIP_UDP_TX_DST_MAC_HIGH16 + 2), (uint8_t *)mac_addr, 2);
memcpy((uint8_t *)(BASE_TCPIP_CFG + TCPIP_UDP_TX_DST_MAC_LOW32), (uint8_t *)mac_addr+2, 4);
}
void tcpip_get_hisMAC(uint8_t mac_addr[])
{
memcpy(mac_addr, (uint8_t *)(BASE_TCPIP_CFG + TCPIP_MAC_HIGH16+2), 2);
memcpy(mac_addr+2, (uint8_t *)(BASE_TCPIP_CFG + TCPIP_MAC_LOW32), 4);
memcpy(mac_addr, (uint8_t *)(BASE_TCPIP_CFG + TCPIP_UDP_TX_DST_MAC_HIGH16+2), 2);
memcpy(mac_addr+2, (uint8_t *)(BASE_TCPIP_CFG + TCPIP_UDP_TX_DST_MAC_LOW32), 4);
}
void tcpip_rx_tcp_port(uint16_t port)
......@@ -110,9 +104,30 @@ void tcpip_rx_tcp_port(uint16_t port)
*rtp = (uint32_t)port;
}
void tcpip_arp()
void tcpip_poll()
{
uint8_t * ip;
static uint16_t arp_count = 0;
if (tcpip_status == TCPIP_OK)
return 0;
if (tcpip_status == TCPIP_ARP)
arp_count++;
if (arp_count<65530)
return 0;
tcpip_get_hisIP(ip);
send_arp(ip);
arp_count=0;
}
DEFINE_WRC_TASK(tcpip) = {
.name = "tcpip",
.enable = &link_status,
.init = tcpip_init,
.job = tcpip_poll,
};
......@@ -3,7 +3,6 @@
#include <stdint.h>
void tcpip_init(uint8_t mac_addr[]);
void tcpip_ip_addr(uint8_t *ip);
void tcpip_gateway_addr(uint8_t *gw);
void tcpip_subnet_addr(uint8_t *sn);
......@@ -14,13 +13,11 @@ void tcpip_set_hisIP(uint8_t *ip);
void tcpip_get_hisIP(uint8_t *ip);
void tcpip_set_hisMAC(uint8_t mac_addr[]);
void tcpip_rx_tcp_port(uint16_t port);
void tcpip_arp();
enum tcpip_status {
TCPIP_ARP,
TCPIP_OK,
};
extern enum tcpip_status tcpip_status;
extern uint8_t arp_count;
#endif
......@@ -14,6 +14,7 @@
#include "ipv4.h"
#include "ptpd_netif.h"
#include "arp.h"
#include "tcpip_config.h"
static uint8_t __arp_queue[128];
static struct wrpc_socket __static_arp_socket = {
......@@ -76,6 +77,14 @@ static int process_arp(uint8_t * buf, int len)
return ARP_END;
}
tcpip_get_hisIP(hisIP);
if ( ((buf[ARP_OPER + 1] != 2)||memcmp(buf + ARP_SPA, hisIP, 4)) == 0 )
{
memcpy(hisMAC, buf + ARP_SHA, 6);
tcpip_set_hisMAC(hisMAC);
tcpip_status = TCPIP_OK;
}
return 0;
}
......
......@@ -17,6 +17,7 @@
#include "hw/memlayout.h"
#include "hw/etherbone-config.h"
#include "flash.h"
#include "tcpip_config.h"
enum ip_status ip_status = IP_TRAINING;
static uint8_t myIP[4];
......
......@@ -220,6 +220,7 @@ enum pf_symbolic_regs {
FRAME_TYPE_ARP,
FRAME_ICMP,
FRAME_UDP,
FRAME_TCP,
PORT_UDP_HOST,
PORT_UDP_ETHERBONE,
R_TMP,
......@@ -395,10 +396,6 @@ void pfilter_init_novlan(char *fname)
pfilter_logic3(FRAME_MAC_OK, FRAME_MAC_PTP, AND, R_TMP, OR, FRAME_MAC_OK);
/* Tagged is dropped. We'll invert the check in the vlan rule-set */
pfilter_cmp(6, 0x8100, 0xffff, MOV, R_TMP);
pfilter_logic2(R_DROP, R_TMP, MOV, R_ZERO);
/* Identify some Ethertypes used later -- type latency is 0xcafe */
pfilter_cmp(6, 0x88f7, 0xffff, MOV, FRAME_TYPE_PTP2);
pfilter_cmp(6, 0xcafe, 0xffff, OR, FRAME_TYPE_PTP2);
......@@ -412,6 +409,8 @@ void pfilter_init_novlan(char *fname)
pfilter_cmp(11, 0x0001, 0x00ff, MOV, FRAME_ICMP);
pfilter_cmp(11, 0x0011, 0x00ff, MOV, FRAME_UDP);
pfilter_logic2(FRAME_UDP, FRAME_UDP, AND, FRAME_IP_OK);
pfilter_cmp(11, 0x0006, 0x00ff, MOV, FRAME_TCP);
pfilter_logic2(FRAME_UDP, FRAME_TCP, AND, FRAME_IP_OK);
/* For CPU: arp or icmp unicast or ptp (or latency) */
pfilter_logic2(FRAME_FOR_CPU, FRAME_TYPE_ARP, OR, FRAME_TYPE_PTP2);
......@@ -429,7 +428,7 @@ void pfilter_init_novlan(char *fname)
/* and now copy out fabric selections: 7 etherbone, 6 for anything else */
pfilter_logic2(R_CLASS(7), FRAME_UDP, AND, PORT_UDP_ETHERBONE);
pfilter_logic2(R_CLASS(6), FRAME_UDP, NAND, PORT_UDP_ETHERBONE);
pfilter_logic3(R_CLASS(6), FRAME_UDP, NAND, PORT_UDP_ETHERBONE, OR, FRAME_TCP);
/*
* Note that earlier we used to be more strict in ptp ethtype (only proper multicast),
......
......@@ -30,7 +30,6 @@
#include "lib/ipv4.h"
#include "rxts_calibrator.h"
#include "flash.h"
#include "tcpip_config.h"
#include "wrc_ptp.h"
#include "system_checks.h"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment