[][Fix switch command support jaguar embedded switch]
[Description]
Fix switch command support jaguar embedded switch
[Release-log]
N/A
Change-Id: I92f07c54d10a859ba83536fe6c35e140a760ca62
Reviewed-on: https://gerrit.mediatek.inc/c/openwrt/feeds/mtk_openwrt_feeds/+/6189993
diff --git a/feed/switch/src/switch_753x.c b/feed/switch/src/switch_753x.c
index 4775516..95a6a0d 100644
--- a/feed/switch/src/switch_753x.c
+++ b/feed/switch/src/switch_753x.c
@@ -241,6 +241,9 @@
static int get_chip_name()
{
unsigned int temp;
+ FILE *fp = NULL;
+ char buff[255];
+
/*judge 7530*/
reg_read((0x7ffc), &temp);
temp = temp >> 16;
@@ -251,6 +254,18 @@
temp = temp >> 16;
if (temp == 0x7531)
return temp;
+
+ /*judge jaguar embedded switch*/
+ fp = fopen("/sys/bus/platform/devices/15020000.gsw/of_node/mediatek,model", "r");
+ if (fp != NULL) {
+ fgets(buff, 255, (FILE *)fp);
+ fclose(fp);
+ if (!strcmp(buff, "mediatek,mt7988")) {
+ temp = 0x7988;
+ return temp;
+ }
+ }
+
return -1;
}
@@ -320,30 +335,29 @@
attres->dev_id = -1;
attres->port_num = -1;
attres->phy_dev = -1;
- nl_init_flag = false;
+ nl_init_flag = true;
- err = switch_ioctl_init();
+ /* dsa netlink family might not be enabled. Try gsw netlink family. */
+ err = mt753x_netlink_init(MT753X_DSA_GENL_NAME);
if (!err)
chip_name = get_chip_name();
- /* dsa netlink family might not be enabled. Try gsw netlink family. */
- if (err < 0 || chip_name < 0) {
- nl_init_flag = true;
-
- err = mt753x_netlink_init(MT753X_DSA_GENL_NAME);
+ if (err < 0) {
+ err = mt753x_netlink_init(MT753X_GENL_NAME);
if (!err)
chip_name = get_chip_name();
}
-
- if (err < 0 || chip_name < 0) {
- err = mt753x_netlink_init(MT753X_GENL_NAME);
- if (!err)
+
+ if (err < 0) {
+ err = switch_ioctl_init();
+ if (!err) {
chip_name = get_chip_name();
-
- if (chip_name < 0) {
- printf("no chip unsupport or chip id is invalid!\n");
- exit_free();
- exit(0);
+ nl_init_flag = false;
+ if (chip_name < 0) {
+ printf("no chip unsupport or chip id is invalid!\n");
+ exit_free();
+ exit(0);
+ }
}
}
diff --git a/feed/switch/src/switch_fun.c b/feed/switch/src/switch_fun.c
index 92f0e12..ce9d2bb 100755
--- a/feed/switch/src/switch_fun.c
+++ b/feed/switch/src/switch_fun.c
@@ -327,7 +327,7 @@
unsigned int value, reg;
unsigned int max_index;
- if (chip_name == 0x7531)
+ if (chip_name == 0x7531 || chip_name == 0x7988)
max_index = 256;
else
max_index = 64;
@@ -380,7 +380,7 @@
unsigned int value, reg;
unsigned int max_index;
- if (chip_name == 0x7531)
+ if (chip_name == 0x7531 || chip_name == 0x7988)
max_index = 128;
else
max_index = 32;
@@ -430,7 +430,7 @@
unsigned int value, reg;
unsigned int max_index;
- if (chip_name == 0x7531)
+ if (chip_name == 0x7531 || chip_name == 0x7988)
max_index = 128;
else
max_index = 32;
@@ -671,11 +671,12 @@
//set action
meter = strtoul(argv[6], NULL, 0);
if (((chip_name == 0x7530) && (meter > 1000000)) ||
- ((chip_name == 0x7531) && (meter > 2500000))) {
- printf("\n**Illegal meter input, and 7530: 0~1000000Kpbs, 7531: 0~2500000Kpbs**\n");
+ ((chip_name == 0x7531) && (meter > 2500000)) ||
+ ((chip_name == 0x7988) && (meter > 4000000))) {
+ printf("\n**Illegal meter input, and 7530: 0~1000000Kpbs, 7531: 0~2500000Kpbs, 7988: 0~4000000Kpbs**\n");
return;
}
- if (((chip_name == 0x7531) && (meter > 1000000))) {
+ if (((chip_name == 0x7531 || chip_name == 0x7988) && (meter > 1000000))) {
reg_read(0xc,&value);
value |= 0x1 << 30;
reg_write(0xC,value);
@@ -2228,8 +2229,11 @@
printf("config igmpsnoop off.\n");
}
-void switch_reset(int argc, char *argv[])
+int switch_reset(int argc, char *argv[])
{
+ if (chip_name == 0x7988)
+ return -1;
+
unsigned int value = 0;
/*Software Register Reset and Software System Reset */
reg_write(0x7000, 0x3);
@@ -2241,6 +2245,7 @@
printf("GPIO Mode (0x7c0c) select value =0x%x \n", value);
}
printf("Switch Software Reset !!! \n");
+ return 0;
}
int phy_set_fc(int argc, char *argv[])
@@ -2305,7 +2310,7 @@
printf("Illegal parameter (port:0~6, enable|diable:0|1) \n");
return -1;
}
- if (chip_name == 0x7531) {
+ if (chip_name == 0x7531 || chip_name == 0x7988) {
reg_read(REG_PFC_CTRL_ADDR, &value);
value &= ~(1 << port);
value |= (enable << port);
@@ -2481,7 +2486,7 @@
reg_write(0x44, value);
printf("reg: 0x44, value: 0x%x\n", value);
- } else if (chip_name == 0x7531) {
+ } else if (chip_name == 0x7531 || chip_name == 0x7988) {
reg_read(GSW_UPW(port), &value);
get_upw(&value, base);
@@ -2605,7 +2610,7 @@
}
reg_write(reg, value);
printf("write reg: %x, value: %x\n", reg, value);
- } else if (chip_name == 0x7531) {
+ } else if (chip_name == 0x7531 || chip_name == 0x7988) {
pem_n = prio / 2;
reg = GSW_PEM(pem_n) + 0x100 * port;
reg_read(reg, &value);
@@ -3111,16 +3116,22 @@
return -1;
}
value = ((bw / 32) << 16) + (1 << 15) + (7 << 8) + (1 << 7) + 0x0f;
- } else if (chip_name == 0x7531) {
- if (bw > 2500000) {
+ } else if (chip_name == 0x7531 || chip_name == 0x7988) {
+ if ((chip_name == 0x7531) && (bw > 2500000)) {
printf("\n**Charge rate(%d) is larger than line rate(2500000kbps)**\n",bw);
return -1;
}
- if (bw/32 >= 65536) //supoort 2.5G case
- value = ((bw / 32) << 16) + (1 << 15) + (1 << 14) + (1 << 12) + (7 << 8) + 0xf;
- else
- value = ((bw / 32) << 16) + (1 << 15) + (1 << 14) + (7 << 8) + 0xf;
+
+ if ((chip_name == 0x7988) && (bw > 4000000)) {
+ printf("\n**Charge rate(%d) is larger than line rate(4000000kbps)**\n",bw);
+ return -1;
}
+
+ if (bw/32 >= 65536) //supoort 2.5G case
+ value = ((bw / 32) << 16) + (1 << 15) + (1 << 14) + (1 << 12) + (7 << 8) + 0xf;
+ else
+ value = ((bw / 32) << 16) + (1 << 15) + (1 << 14) + (7 << 8) + 0xf;
+ }
else
printf("unknow chip\n");
}
@@ -3172,15 +3183,20 @@
return -1;
}
value = ((bw / 32) << 16) + (1 << 15) + (7 << 8) + (1 << 7) + 0xf;
- } else if (chip_name == 0x7531) {
- if (bw < 0 || bw > 2500000) {
+ } else if (chip_name == 0x7531 || chip_name == 0x7988) {
+ if ((chip_name == 0x7531) && (bw < 0 || bw > 2500000)) {
printf("\n**Charge rate(%d) is larger than line rate(2500000kbps)**\n",bw);
return -1;
}
- if (bw/32 >= 65536) //support 2.5G cases
- value = ((bw / 32) << 16) + (1 << 15) + (1 << 14) + (1 << 12) + (7 << 8) + 0xf;
- else
- value = ((bw / 32) << 16) + (1 << 15) + (1 << 14) + (7 << 8) + 0xf;
+ if ((chip_name == 0x7988) && (bw < 0 || bw > 4000000)) {
+ printf("\n**Charge rate(%d) is larger than line rate(4000000kbps)**\n",bw);
+ return -1;
+ }
+
+ if (bw/32 >= 65536) //support 2.5G cases
+ value = ((bw / 32) << 16) + (1 << 15) + (1 << 14) + (1 << 12) + (7 << 8) + 0xf;
+ else
+ value = ((bw / 32) << 16) + (1 << 15) + (1 << 14) + (7 << 8) + 0xf;
}
else
printf("unknow chip\n");
@@ -3232,7 +3248,7 @@
return -1;
}
- if (chip_name == 0x7531) {
+ if (chip_name == 0x7531 || chip_name == 0x7988) {
reg = REG_CPGC_ADDR;
if(enable == 1) {
/* active reset */
@@ -3298,7 +3314,7 @@
{
unsigned int value, reg;
- if (chip_name == 0x7531) {
+ if (chip_name == 0x7531 || chip_name == 0x7988) {
reg = REG_CPGC_ADDR;
reg_read(reg, &value);
if(value & REG_CPCG_COL_EN_MASK)
@@ -3314,7 +3330,7 @@
{
unsigned int value, reg;
- if (chip_name == 0x7531) {
+ if (chip_name == 0x7531 || chip_name == 0x7988) {
reg = REG_CPGC_ADDR;
reg_read(reg, &value);
if(value & REG_CPCG_COL_EN_MASK)
@@ -3332,7 +3348,7 @@
{
unsigned int value, reg;
- if (chip_name == 0x7531) {
+ if (chip_name == 0x7531 || chip_name == 0x7988) {
reg = REG_CPGC_ADDR;
reg_read(reg, &value);
if(value & REG_CPCG_COL_EN_MASK)
@@ -3358,7 +3374,7 @@
return;
}
- if (chip_name == 0x7531) {
+ if (chip_name == 0x7531 || chip_name == 0x7988) {
reg= PFC_RX_COUNTER_L(port);
reg_read(reg, &value);
user_pri = value & 0xff;
@@ -3402,7 +3418,7 @@
return;
}
- if (chip_name == 0x7531) {
+ if (chip_name == 0x7531 || chip_name == 0x7988) {
reg= PFC_TX_COUNTER_L(port);
reg_read(reg, &value);
user_pri = value & 0xff;
@@ -3478,7 +3494,7 @@
unsigned int fc_port_blk_thd,fc_port_blk_hi_thd;
unsigned int queue[8]={0};
- if (chip_name == 0x7531) {
+ if (chip_name == 0x7531 || chip_name == 0x7988) {
/* get system free page link counter*/
reg_read(0x1fc0, &value);
free_page = value & 0xFFF;
@@ -3615,7 +3631,7 @@
}
/* Turn on/off global EEE switch */
- if (chip_name == 0x7531) {
+ if (chip_name == 0x7531 || chip_name == 0x7988) {
mii_mgr_c45_read(0, 0x1f, 0x403, &value);
if (eee_en_bitmap)
value |= (1 << 6);
diff --git a/feed/switch/src/switch_fun.h b/feed/switch/src/switch_fun.h
index 95ff4b3..70e4d18 100644
--- a/feed/switch/src/switch_fun.h
+++ b/feed/switch/src/switch_fun.h
@@ -128,7 +128,7 @@
void pfc_get_tx_counter(int argc, char *argv[]);
/*switch reset*/
-void switch_reset(int argc, char *argv[]);
+int switch_reset(int argc, char *argv[]);
/* EEE(802.3az) function */
void eee_enable(int argc, char *argv[]);
diff --git a/feed/switch/src/switch_ioctl.c b/feed/switch/src/switch_ioctl.c
index 32d46c9..f6b97d4 100644
--- a/feed/switch/src/switch_ioctl.c
+++ b/feed/switch/src/switch_ioctl.c
@@ -413,7 +413,7 @@
int mii_mgr_cl45_read_ioctl(unsigned int port_num, unsigned int dev,
unsigned int reg, unsigned int *value)
{
- if (chip_name == 0x7531)
+ if (chip_name == 0x7531 || chip_name == 0x7988)
return mii_mgr_cl45_read(port_num, dev, reg, value);
else if (chip_name == 0x7530)
return mii_mgr_cl45_read_indirect(port_num, dev, reg, value);
@@ -424,7 +424,7 @@
int mii_mgr_cl45_write_ioctl(unsigned int port_num, unsigned int dev,
unsigned int reg, unsigned int value)
{
- if (chip_name == 0x7531)
+ if (chip_name == 0x7531 || chip_name == 0x7988)
return mii_mgr_cl45_write(port_num, dev, reg, value);
else if (chip_name == 0x7530)
return mii_mgr_cl45_write_indirect(port_num, dev, reg, value);