add port vlan support via switch config ioctl
authorMugunthan V N <mugunthanvnm@ti.com>
Tue, 9 Dec 2014 08:21:36 +0000 (13:51 +0530)
committerMugunthan V N <mugunthanvnm@ti.com>
Mon, 5 Jan 2015 10:08:57 +0000 (15:38 +0530)
Signed-off-by: Mugunthan V N <mugunthanvnm@ti.com>
switch-config.c

index d49cac7b294127a80235d9d0868a444a49b17653..b2e1d84adea8ecdada5c62e3a182286b577b67a8 100644 (file)
  * GNU General Public License for more details.
  */
 
+#define true 1
+#define false 0
+typedef int bool;
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
@@ -235,7 +239,7 @@ int cpsw_dump_regs(struct ethtool_drvinfo *info, struct ethtool_regs *regs)
                return -1;                                      \
        }
 
-static char options[] = "?m:x:i:y:S:GUg:udn:V:sk:K:M:N:D:Y:z:Z:J:v";
+static char options[] = "?m:x:i:y:S:GUg:udn:V:sk:K:M:N:D:Y:z:Z:J:vPp:r:C";
 
 static struct option long_options[] =
        {
@@ -263,6 +267,9 @@ static struct option long_options[] =
 {"unknown-vlan-mem",           required_argument       , 0, 'J'},
 {"duplex",                     required_argument       , 0, 'D'},
 {"version",                    no_argument             , 0, 'v'},
+{"get-port-vlan",              no_argument             , 0, 'P'},
+{"set-port-vlan",              required_argument       , 0, 'p'},
+{"priority",                   required_argument       , 0, 'r'},
 {0, 0, 0, 0}
 };
 
@@ -511,6 +518,9 @@ void print_help(void)
                "switch-config -g,--get-port-state <disabled/blocked/learn/forward> "
                        "-n,--port <PortNo>\n"
                "switch-config -u,--set-port-state -n,--port <PortNo>\n"
+               "switch-config -P,--get-port-vlan -n,--port <Port No 0-2>\n"
+               "switch-config -p,--set-port-vlan <vid> -n,--port <Port No 0-2> "
+                       "[-r,--priority <priority 0-7>] [-C,--cfi]\n"
                "switch-config -d,--dump\n"
                "\n"
                );
@@ -619,6 +629,17 @@ int main(int argc, char **argv)
                                CONFIG_SWITCH_GET_PORT_STATE);
                break;
 
+               case 'P':
+                       SWITCH_CONFIG_COMMAND(cmd_struct.cmd,
+                               CONFIG_SWITCH_GET_PORT_VLAN_CONFIG);
+               break;
+
+               case 'p':
+                       SWITCH_CONFIG_COMMAND(cmd_struct.cmd,
+                               CONFIG_SWITCH_SET_PORT_VLAN_CONFIG);
+                       cmd_struct.vid = atoi(optarg);
+               break;
+
                /* Extended switch commands */
                case 'd':
                        extended_switch_config = EXTENDED_CONFIG_SWITCH_DUMP;
@@ -677,6 +698,14 @@ int main(int argc, char **argv)
                        cmd_struct.unknown_vlan_member = atoi(optarg);
                break;
 
+               case 'r':
+                       cmd_struct.prio = atoi(optarg);
+               break;
+
+               case 'C':
+                       cmd_struct.vlan_cfi = true;
+               break;
+
                default:
                        print_help();
                        return 0;
@@ -859,6 +888,41 @@ int main(int argc, char **argv)
                                return -1;
                        }
                break;
+
+               case CONFIG_SWITCH_GET_PORT_VLAN_CONFIG:
+                       if (port_num <= 2) {
+                               cmd_struct.port = port_num;
+                               if (ioctl(sockfd, SIOCSWITCHCONFIG, &ifr) < 0) {
+                                       printf("Get Port VLAN Failed\n");
+                                       close(sockfd);
+                                       return -1;
+                               } else {
+                                       printf("Get Port VLAN successful\n");
+                               }
+                               printf("Port VLAN id = %d\n", cmd_struct.vid);
+                               printf("Port VLAN Priority = %d\n", cmd_struct.prio);
+                               printf("Port VLAN CFI is %sset\n", cmd_struct.vlan_cfi ? "" : "not ");
+                       } else {
+                               printf("Invalid Arguments\n");
+                               return -1;
+                       }
+               break;
+
+               case CONFIG_SWITCH_SET_PORT_VLAN_CONFIG:
+                       if ((port_num <= 2) && (cmd_struct.prio <= 7)) {
+                               cmd_struct.port = port_num;
+                               if (ioctl(sockfd, SIOCSWITCHCONFIG, &ifr) < 0) {
+                                       printf("Set Port VLAN Failed\n");
+                                       close(sockfd);
+                                       return -1;
+                               } else {
+                                       printf("Set Port VLAN successful\nState is ");
+                               }
+                       } else {
+                               printf("Invalid Arguments\n");
+                               return -1;
+                       }
+               break;
        }
 
        close(sockfd);