summaryrefslogtreecommitdiffstatsabout
diff options
context:
space:
mode:
authorJiaojinxing <jiaojinxing1987@gmail.com>2015-09-20 10:21:48 (GMT)
committer Jiaojinxing <jiaojinxing1987@gmail.com>2015-09-20 10:21:48 (GMT)
commit9cc830ef6383932e0e93882ca7edf70c8c1362ba (patch)
tree930526b9946f66d1f58d00afbb52da6989e1b5be
parent9543360e69d4e54d082eb27306d9c65d83decf3f (diff)
downloadbspam335x-9cc830ef6383932e0e93882ca7edf70c8c1362ba.zip
bspam335x-9cc830ef6383932e0e93882ca7edf70c8c1362ba.tar.gz
bspam335x-9cc830ef6383932e0e93882ca7edf70c8c1362ba.tar.bz2
Add net interface parameter config file read.
-rw-r--r--SylixOS/bsp/beaglebone/bspBeaglebone.c31
-rw-r--r--SylixOS/bsp/forlinx/bspForlinx.c64
-rw-r--r--SylixOS/driver/netif/am335x_cpsw.c15
-rw-r--r--SylixOS/driver/netif/am335x_cpsw.h7
4 files changed, 91 insertions, 26 deletions
diff --git a/SylixOS/bsp/beaglebone/bspBeaglebone.c b/SylixOS/bsp/beaglebone/bspBeaglebone.c
index 809e4bc..8b564bb 100644
--- a/SylixOS/bsp/beaglebone/bspBeaglebone.c
+++ b/SylixOS/bsp/beaglebone/bspBeaglebone.c
@@ -34,6 +34,7 @@
#include "netif/aodvif.h" /* aodv 多跳自组网网络接口 */
#include <linux/mtd/mtd.h>
#include "sys/ioccom.h"
+#include "net/if_param.h" /* 网络接口参数获取 */
/*********************************************************************************************************
BSP 及 驱动程序
*********************************************************************************************************/
@@ -211,6 +212,10 @@ VOID bspDevInit (VOID)
VOID bspNetifAttch (VOID)
{
AM335X_NETIF_CFG netIfCfg;
+ ip_addr_t ip, submask, gateway;
+ void *ifparam;
+ int enable = 1;
+ int def = 1;
arm335xCpswInit();
@@ -226,10 +231,28 @@ VOID bspNetifAttch (VOID)
netIfCfg.NETIFCFG_uiInstNum = 0;
netIfCfg.NETIFCFG_uiSlavePortNum = 1;
- netIfCfg.NETIFCFG_uiIpAddr = ntohl(ipaddr_addr(BSP_CFG_EN1_IPADDR));
- netIfCfg.NETIFCFG_uiNetMask = ntohl(ipaddr_addr(BSP_CFG_EN1_NETMASK));
- netIfCfg.NETIFCFG_uiGwAddr = ntohl(ipaddr_addr(BSP_CFG_EN1_GATEWAY));
- netIfCfg.NETIFCFG_bIsDefault = LW_TRUE;
+ ifparam = if_param_load("cpsw0");
+ if (ifparam) {
+ if_param_getenable(ifparam, &enable);
+ if_param_getdefault(ifparam, &def);
+ if_param_getipaddr(ifparam, &ip);
+ if_param_getnetmask(ifparam, &submask);
+ if_param_getgw(ifparam, &gateway);
+ if_param_syncdns();
+ if_param_unload(ifparam);
+
+ netIfCfg.NETIFCFG_ipAddr = ip;
+ netIfCfg.NETIFCFG_netMask = submask;
+ netIfCfg.NETIFCFG_gwAddr = gateway;
+ netIfCfg.NETIFCFG_bIsDefault = def;
+ netIfCfg.NETIFCFG_bIsEnable = enable;
+ } else {
+ netIfCfg.NETIFCFG_ipAddr.addr = ipaddr_addr(BSP_CFG_EN1_IPADDR);
+ netIfCfg.NETIFCFG_netMask.addr = ipaddr_addr(BSP_CFG_EN1_NETMASK);
+ netIfCfg.NETIFCFG_gwAddr.addr = ipaddr_addr(BSP_CFG_EN1_GATEWAY);
+ netIfCfg.NETIFCFG_bIsDefault = LW_TRUE;
+ netIfCfg.NETIFCFG_bIsEnable = LW_TRUE;
+ }
netIfCfg.NETIFCFG_uiInterfaceMode = NETIF_GMII_MII_MODE;
netIfCfg.NETIFCFG_bInternalDelay = LW_TRUE;
diff --git a/SylixOS/bsp/forlinx/bspForlinx.c b/SylixOS/bsp/forlinx/bspForlinx.c
index b4b6af6..e9406d5 100644
--- a/SylixOS/bsp/forlinx/bspForlinx.c
+++ b/SylixOS/bsp/forlinx/bspForlinx.c
@@ -34,6 +34,7 @@
#include "netif/aodvif.h" /* aodv 多跳自组网网络接口 */
#include <linux/mtd/mtd.h>
#include "sys/ioccom.h"
+#include "net/if_param.h" /* 网络接口参数获取 */
/*********************************************************************************************************
BSP 及 驱动程序
*********************************************************************************************************/
@@ -977,6 +978,10 @@ INT mtdDevCreateEx (CHAR *pcDevName)
VOID bspNetifAttch (VOID)
{
AM335X_NETIF_CFG netIfCfg;
+ ip_addr_t ip, submask, gateway;
+ void *ifparam;
+ int enable = 1;
+ int def = 1;
arm335xCpswInit();
@@ -992,10 +997,29 @@ VOID bspNetifAttch (VOID)
netIfCfg.NETIFCFG_uiInstNum = 0;
netIfCfg.NETIFCFG_uiSlavePortNum = 1;
- netIfCfg.NETIFCFG_uiIpAddr = ntohl(ipaddr_addr(BSP_CFG_EN1_IPADDR));
- netIfCfg.NETIFCFG_uiNetMask = ntohl(ipaddr_addr(BSP_CFG_EN1_NETMASK));
- netIfCfg.NETIFCFG_uiGwAddr = ntohl(ipaddr_addr(BSP_CFG_EN1_GATEWAY));
- netIfCfg.NETIFCFG_bIsDefault = LW_TRUE;
+
+ ifparam = if_param_load("cpsw0");
+ if (ifparam) {
+ if_param_getenable(ifparam, &enable);
+ if_param_getdefault(ifparam, &def);
+ if_param_getipaddr(ifparam, &ip);
+ if_param_getnetmask(ifparam, &submask);
+ if_param_getgw(ifparam, &gateway);
+ if_param_syncdns();
+ if_param_unload(ifparam);
+
+ netIfCfg.NETIFCFG_ipAddr = ip;
+ netIfCfg.NETIFCFG_netMask = submask;
+ netIfCfg.NETIFCFG_gwAddr = gateway;
+ netIfCfg.NETIFCFG_bIsDefault = def;
+ netIfCfg.NETIFCFG_bIsEnable = enable;
+ } else {
+ netIfCfg.NETIFCFG_ipAddr.addr = ipaddr_addr(BSP_CFG_EN1_IPADDR);
+ netIfCfg.NETIFCFG_netMask.addr = ipaddr_addr(BSP_CFG_EN1_NETMASK);
+ netIfCfg.NETIFCFG_gwAddr.addr = ipaddr_addr(BSP_CFG_EN1_GATEWAY);
+ netIfCfg.NETIFCFG_bIsDefault = LW_TRUE;
+ netIfCfg.NETIFCFG_bIsEnable = LW_TRUE;
+ }
#if defined(ok335xd) || defined(ok335xs)
netIfCfg.NETIFCFG_uiInterfaceMode = NETIF_RGMII_MODE;
@@ -1017,12 +1041,32 @@ VOID bspNetifAttch (VOID)
netIfCfg.NETIFCFG_uiInstNum = 0;
netIfCfg.NETIFCFG_uiSlavePortNum = 2;
- netIfCfg.NETIFCFG_uiIpAddr = ntohl(ipaddr_addr(BSP_CFG_EN2_IPADDR));
- netIfCfg.NETIFCFG_uiNetMask = ntohl(ipaddr_addr(BSP_CFG_EN2_NETMASK));
- netIfCfg.NETIFCFG_uiGwAddr = ntohl(ipaddr_addr(BSP_CFG_EN2_GATEWAY));
- netIfCfg.NETIFCFG_bInternalDelay = LW_FALSE;
- netIfCfg.NETIFCFG_uiInterfaceMode = NETIF_RGMII_MODE;
- netIfCfg.NETIFCFG_bIsDefault = LW_FALSE;
+
+ ifparam = if_param_load("cpsw1");
+ if (ifparam) {
+ if_param_getenable(ifparam, &enable);
+ if_param_getdefault(ifparam, &def);
+ if_param_getipaddr(ifparam, &ip);
+ if_param_getnetmask(ifparam, &submask);
+ if_param_getgw(ifparam, &gateway);
+ if_param_syncdns();
+ if_param_unload(ifparam);
+
+ netIfCfg.NETIFCFG_ipAddr = ip;
+ netIfCfg.NETIFCFG_netMask = submask;
+ netIfCfg.NETIFCFG_gwAddr = gateway;
+ netIfCfg.NETIFCFG_bIsDefault = def;
+ netIfCfg.NETIFCFG_bIsEnable = enable;
+ } else {
+ netIfCfg.NETIFCFG_ipAddr.addr = ipaddr_addr(BSP_CFG_EN2_IPADDR);
+ netIfCfg.NETIFCFG_netMask.addr = ipaddr_addr(BSP_CFG_EN2_NETMASK);
+ netIfCfg.NETIFCFG_gwAddr.addr = ipaddr_addr(BSP_CFG_EN2_GATEWAY);
+ netIfCfg.NETIFCFG_bIsDefault = LW_FALSE;
+ netIfCfg.NETIFCFG_bIsEnable = LW_TRUE;
+ }
+
+ netIfCfg.NETIFCFG_bInternalDelay = LW_FALSE;
+ netIfCfg.NETIFCFG_uiInterfaceMode = NETIF_RGMII_MODE;
arm335xCpswNetIfAdd(&netIfCfg, rgmii2_pin_mux);
#elif defined(CPSW_SWITCH_CONFIG)
diff --git a/SylixOS/driver/netif/am335x_cpsw.c b/SylixOS/driver/netif/am335x_cpsw.c
index 364794b..72c49ad 100644
--- a/SylixOS/driver/netif/am335x_cpsw.c
+++ b/SylixOS/driver/netif/am335x_cpsw.c
@@ -353,9 +353,6 @@ INT arm335xCpswNetIfAdd (AM335X_NETIF_CFG *pNetIfCfg, PAM335X_PINMUX pPinMux)
{
__PAM335X_CPSW_PORTIF pCpswPortIf;
struct netif *pNetIf;
- struct ip_addr ipAddr;
- struct ip_addr netMask;
- struct ip_addr gwAddr;
UINT uiNetIfNum;
INT i;
UINT32 uiValue;
@@ -388,10 +385,6 @@ INT arm335xCpswNetIfAdd (AM335X_NETIF_CFG *pNetIfCfg, PAM335X_PINMUX pPinMux)
write32(uiValue, SOC_CONTROL_REGS + CONTROL_GMII_SEL);
- ipAddr.addr = htonl(pNetIfCfg->NETIFCFG_uiIpAddr);
- netMask.addr = htonl(pNetIfCfg->NETIFCFG_uiNetMask);
- gwAddr.addr = htonl(pNetIfCfg->NETIFCFG_uiGwAddr);
-
#ifdef CPSW_DUAL_MAC_MODE
uiNetIfNum = (pNetIfCfg->NETIFCFG_uiInstNum * MAX_SLAVEPORT_PER_INST) +
pNetIfCfg->NETIFCFG_uiSlavePortNum - 1;
@@ -411,7 +404,9 @@ INT arm335xCpswNetIfAdd (AM335X_NETIF_CFG *pNetIfCfg, PAM335X_PINMUX pPinMux)
}
if (netif_add(pNetIf,
- &ipAddr, &netMask, &gwAddr,
+ &pNetIfCfg->NETIFCFG_ipAddr,
+ &pNetIfCfg->NETIFCFG_netMask,
+ &pNetIfCfg->NETIFCFG_gwAddr,
pCpswPortIf,
cpswif_init, tcpip_input) == LW_NULL) {
printk(KERN_ERR "arm335xCpswNetIfAdd(): failed to add network interface %d!\n", uiNetIfNum);
@@ -426,7 +421,9 @@ INT arm335xCpswNetIfAdd (AM335X_NETIF_CFG *pNetIfCfg, PAM335X_PINMUX pPinMux)
netif_set_default(pNetIf);
}
- netif_set_up(pNetIf);
+ if (pNetIfCfg->NETIFCFG_bIsEnable) {
+ netif_set_up(pNetIf);
+ }
threadAttr = API_ThreadAttrGetDefault();
diff --git a/SylixOS/driver/netif/am335x_cpsw.h b/SylixOS/driver/netif/am335x_cpsw.h
index e763322..0415bd8 100644
--- a/SylixOS/driver/netif/am335x_cpsw.h
+++ b/SylixOS/driver/netif/am335x_cpsw.h
@@ -33,12 +33,13 @@
typedef struct {
UINT NETIFCFG_uiInstNum; /* Instance Number */
UINT NETIFCFG_uiSlavePortNum; /* CPSW Slave Port Number */
- UINT NETIFCFG_uiIpAddr; /* IP Address */
- UINT NETIFCFG_uiNetMask; /* Net Mask */
- UINT NETIFCFG_uiGwAddr; /* Gate Way Address */
+ ip_addr_t NETIFCFG_ipAddr; /* IP Address */
+ ip_addr_t NETIFCFG_netMask; /* Net Mask */
+ ip_addr_t NETIFCFG_gwAddr; /* Gate Way Address */
#define __CPSW_MAC_LEN (6)
UINT8 NETIFCFG_ucMacArray[__CPSW_MAC_LEN]; /* MAC Address to be used */
BOOL NETIFCFG_bIsDefault;
+ BOOL NETIFCFG_bIsEnable;
BOOL NETIFCFG_bInternalDelay;
UINT NETIFCFG_uiInterfaceMode;
} AM335X_NETIF_CFG;