Blame SOURCES/rxe_cfg

6f52e5
#!/usr/bin/perl
6f52e5
6f52e5
# * Copyright (c) 2009-2011 Mellanox Technologies Ltd. All rights reserved.
6f52e5
# * Copyright (c) 2009-2011 System Fabric Works, Inc. All rights reserved.
6f52e5
# *
6f52e5
# * This software is available to you under a choice of one of two
6f52e5
# * licenses.  You may choose to be licensed under the terms of the GNU
6f52e5
# * General Public License (GPL) Version 2, available from the file
6f52e5
# * COPYING in the main directory of this source tree, or the
6f52e5
# * OpenIB.org BSD license below:
6f52e5
# *
6f52e5
# *     Redistribution and use in source and binary forms, with or
6f52e5
# *     without modification, are permitted provided that the following
6f52e5
# *     conditions are met:
6f52e5
# *
6f52e5
# *	- Redistributions of source code must retain the above
6f52e5
# *	  copyright notice, this list of conditions and the following
6f52e5
# *	  disclaimer.
6f52e5
# *
6f52e5
# *	- Redistributions in binary form must reproduce the above
6f52e5
# *	  copyright notice, this list of conditions and the following
6f52e5
# *	  disclaimer in the documentation and/or other materials
6f52e5
# *	  provided with the distribution.
6f52e5
# *
6f52e5
# * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
6f52e5
# * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
6f52e5
# * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
6f52e5
# * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
6f52e5
# * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
6f52e5
# * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
6f52e5
# * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
6f52e5
# * SOFTWARE.
6f52e5
#
6f52e5
6f52e5
use warnings;
6f52e5
use strict;
6f52e5
6f52e5
use File::Basename;
6f52e5
use File::Path qw(make_path);
6f52e5
use Getopt::Long;
6f52e5
6f52e5
my $help = 0;
6f52e5
my $no_persist = 0;
6f52e5
my $debug = 0;
6f52e5
my $force = 0;
6f52e5
my $linkonly = 0;
6f52e5
my $parms = "/sys/module/rdma_rxe/parameters";
6f52e5
my $modprobe_opt = "";
6f52e5
my $modprobe_checked = "0";
6f52e5
my $persistence_path = "/var/lib/rxe";
6f52e5
my $persistence_file = "${persistence_path}/rxe";
6f52e5
my $num_persistent = 0;
6f52e5
my $sys = "/sys/module/rdma_rxe/parameters";
6f52e5
my %rxe_names;
6f52e5
my @rxe_array;
6f52e5
my %eth_names;
6f52e5
my @eth_list;
6f52e5
my %eth_driver;
6f52e5
my %link_state;
6f52e5
my %link_speed;
6f52e5
my %eth_mtu;
6f52e5
my %ipv4_addr;
6f52e5
my %rxe_mtu;
6f52e5
my @persistence_array;
6f52e5
my %persistence_hash;
6f52e5
my @mlx4_port;
6f52e5
my @mlx4_ether;
6f52e5
my @roce_list;
6f52e5
6f52e5
# Read a file and return its contents as a string.
6f52e5
sub read_file {
6f52e5
    my $filename = shift;
6f52e5
    my $result = "";
6f52e5
6f52e5
    if (open(FILE, $filename)) {
6f52e5
	$result = <FILE>;
6f52e5
	close FILE;
6f52e5
    }
6f52e5
    return $result;
6f52e5
}
6f52e5
6f52e5
#get mapping between rxe and eth devices
6f52e5
sub get_names {
6f52e5
    my $i = 0;
6f52e5
    
6f52e5
    foreach my $rxe (glob("/sys/class/infiniband/rxe*")) {
6f52e5
	$rxe = basename($rxe);
6f52e5
	my $eth = read_file("/sys/class/infiniband/$rxe/parent");
6f52e5
	chomp($eth);
6f52e5
	
6f52e5
	if (($eth =~ /[\w]+[\d]/)
6f52e5
	    && ($rxe =~ /rxe[0123456789]/)) {
6f52e5
	    
6f52e5
	    # hash ethername to rxename
6f52e5
	    $rxe_names{$eth} = $rxe;
6f52e5
	    $rxe_array[$i++] = $rxe;
6f52e5
	    
6f52e5
	    # hash rxename to ethername
6f52e5
	    $eth_names{$rxe} = $eth;
6f52e5
	}
6f52e5
    }
6f52e5
}
6f52e5
6f52e5
# get list of Mellanox RoCE ports
6f52e5
sub get_mlx4_list {
6f52e5
    my $i = 0;
6f52e5
6f52e5
    foreach my $mlx4 (glob("/sys/class/infiniband/mlx4_*")) {
6f52e5
	$mlx4 = basename($mlx4);
6f52e5
	foreach my $port (glob("/sys/class/infiniband/$mlx4/ports/*")) {
6f52e5
	    $port = basename($port);
6f52e5
	    my $link = read_file("$port/link_layer");
6f52e5
	    chomp($link);
6f52e5
6f52e5
	    if ($link =~ "Ethernet") {
6f52e5
		$roce_list[$i++] = "$mlx4:$port";
6f52e5
	    }
6f52e5
	}
6f52e5
    }
6f52e5
}
6f52e5
6f52e5
#collect per device information
6f52e5
sub get_dev_info {
6f52e5
    my @list;
6f52e5
    my @fields;
6f52e5
    my @lines;
6f52e5
    my $line;
6f52e5
    my $eth;
6f52e5
    my $drv;
6f52e5
    my $np;
6f52e5
    my $i = 0;
6f52e5
    my $j = 0;
6f52e5
6f52e5
    get_mlx4_list();
6f52e5
6f52e5
    my @my_eth_list = ();
6f52e5
    foreach my $my_eth_dev (glob("/sys/class/net/*")) {
6f52e5
       $my_eth_dev = basename($my_eth_dev);
6f52e5
          if ($my_eth_dev ne "bonding_masters"){
6f52e5
             my $my_dev_type = read_file("/sys/class/net/${my_eth_dev}/type");
6f52e5
             chomp($my_dev_type);
6f52e5
             if ($my_dev_type == "1") {
6f52e5
                push(@my_eth_list, "$my_eth_dev");
6f52e5
             }
6f52e5
          }
6f52e5
    }
6f52e5
6f52e5
    @list = @my_eth_list;
6f52e5
    foreach $eth (@list) {
6f52e5
	chomp($eth);
6f52e5
6f52e5
	$eth_list[$i++] = $eth;
6f52e5
6f52e5
	@lines = `ethtool -i $eth`;
6f52e5
	foreach $line (@lines) {
6f52e5
	    chomp($line);
6f52e5
6f52e5
	    @fields = split(/\s+/, $line);
6f52e5
	    chomp($fields[0]);
6f52e5
6f52e5
	    if ($fields[0] =~ /driver:/) {
6f52e5
		$drv = $fields[1];
6f52e5
		$eth_driver{$eth} = $drv;
6f52e5
6f52e5
		if ($drv =~ /mlx4_en/ && scalar(@roce_list) > 0 ) {
6f52e5
		    $eth_names{$roce_list[$j++]} = $eth;
6f52e5
		}
6f52e5
	    }
6f52e5
	}
6f52e5
6f52e5
	# get link status
6f52e5
	$link_state{$eth} = "";
6f52e5
	$link_speed{$eth} = "";
6f52e5
6f52e5
	@lines = `ethtool $eth`;
6f52e5
	foreach $line (@lines) {
6f52e5
	    chomp($line);
6f52e5
6f52e5
	    @fields = split(/:/, $line);
6f52e5
	    if (defined($fields[1])) {
6f52e5
		    $fields[1] =~ s/^\s+//g;
6f52e5
		    if ($fields[0] =~ "Link detected") {
6f52e5
			$link_state{$eth} = $fields[1];
6f52e5
		    }
6f52e5
	    }
6f52e5
	    elsif ($line =~ "10000baseT") {
6f52e5
		$link_speed{$eth} = "10GigE";
6f52e5
	    }
6f52e5
	}
6f52e5
6f52e5
	$ipv4_addr{$eth} = "            ";
6f52e5
	$eth_mtu{$eth} = "";
6f52e5
6f52e5
	@lines = `ip addr show $eth`;
6f52e5
	foreach $line (@lines) {
6f52e5
		# get IP address
6f52e5
		if ($line =~ /inet /) {
6f52e5
			$line =~ s/^\s+inet ([0-9.]+)\//$1 /g;
6f52e5
			@fields = split(/\s+/, $line);
6f52e5
			$ipv4_addr{$eth} = $fields[0];
6f52e5
		}
6f52e5
6f52e5
		# get ethernet mtu
6f52e5
		if ($line =~ /mtu /) {
6f52e5
			$line =~ s/^.*mtu //g;
6f52e5
			@fields = split(/\s+/, $line);
6f52e5
			$eth_mtu{$eth} = $fields[0];
6f52e5
		}
6f52e5
    }
6f52e5
    }
6f52e5
6f52e5
    # get rxe mtu
6f52e5
    foreach my $rxe (@rxe_array) {
6f52e5
	
6f52e5
	@lines = `ibv_devinfo -d $rxe`;
6f52e5
	foreach $line (@lines) {
6f52e5
	    if ($line =~ "active_mtu") {
6f52e5
		$line =~ s/^\s+active_mtu:\s+//g;
6f52e5
		chomp($line);
6f52e5
6f52e5
		$rxe_mtu{$rxe} = $line;
6f52e5
	    }
6f52e5
	}
6f52e5
	$rxe_mtu{$rxe} = "(?)" if (!$rxe_mtu{$rxe});
6f52e5
    }
6f52e5
}
6f52e5
6f52e5
# return string or the string "###" if string is all whitespace
6f52e5
sub set_field {
6f52e5
    my $fld = $_[0];
6f52e5
6f52e5
    if (defined($fld) && $fld =~ /\S/) {
6f52e5
        return $fld;
6f52e5
    } else {
6f52e5
        return "###";
6f52e5
    }
6f52e5
}
6f52e5
6f52e5
# format status output into fixed width columns
6f52e5
sub status_print {
6f52e5
    my @fields;
6f52e5
    my $field;
6f52e5
    my @flen = ();
6f52e5
    my $num_fields = 0;
6f52e5
    my $i;
6f52e5
    my $pad;
6f52e5
    my $line;
6f52e5
6f52e5
    # one pass to size the columns
6f52e5
    foreach $line (@_) {
6f52e5
	@fields = split(/\s+/, $line);
6f52e5
	$i = 0;
6f52e5
	foreach $field (@fields) {
6f52e5
	    if (!defined($flen[$i])) {
6f52e5
		$flen[$i] = length($field);
6f52e5
	    }
6f52e5
	    else {
6f52e5
		$flen[$i] = max($flen[$i], length($field));
6f52e5
	    }
6f52e5
	    $i++;
6f52e5
	}
6f52e5
6f52e5
	if ($i > $num_fields) {
6f52e5
	    $num_fields = $i;
6f52e5
	}
6f52e5
    }
6f52e5
6f52e5
    # one pass to print
6f52e5
    foreach $line (@_) {
6f52e5
	print "  ";
6f52e5
	@fields = split(/\s+/, $line);
6f52e5
	for ($i = 0; $i < $num_fields; $i++) {
6f52e5
	    if (defined($fields[$i])) {
6f52e5
	        $pad = $flen[$i] - length($fields[$i]) + 2;
6f52e5
	    }
6f52e5
	    else {
6f52e5
	        $pad = $flen[$i] + 2;
6f52e5
	    }
6f52e5
	    if (defined($fields[$i]) && ($fields[$i] ne "###")) {
6f52e5
		print "$fields[$i]";
6f52e5
	    }
6f52e5
	    else {
6f52e5
		print "   ";
6f52e5
	    }
6f52e5
	    printf("%*s", $pad, "");
6f52e5
	}
6f52e5
	print "\n";
6f52e5
    }
6f52e5
}
6f52e5
6f52e5
# check driver load status
6f52e5
sub check_module_status {
6f52e5
    if (-e $sys) {
6f52e5
	return 0;
6f52e5
    } else {
6f52e5
	return 1;
6f52e5
    }
6f52e5
}
6f52e5
6f52e5
# print driver load status and ethertype for rdma_rxe and rdma_rxe_net
6f52e5
sub show_module_status {
6f52e5
    print "rdma_rxe module not loaded\n" if (!(-e $sys));
6f52e5
}
6f52e5
6f52e5
# print rxe status
6f52e5
sub do_status {
6f52e5
    my $instance = $_[0];
6f52e5
    my $ln = 0;
6f52e5
    my @outp;
6f52e5
    my $rxe;
6f52e5
    my $rmtu;
6f52e5
6f52e5
    get_names();
6f52e5
    get_dev_info();
6f52e5
    show_module_status();
6f52e5
6f52e5
    $outp[$ln++] = "Name\tLink\tDriver\t\tSpeed\tNMTU\tIPv4_addr\tRDEV\tRMTU";
6f52e5
6f52e5
    foreach my $eth (@eth_list) {
6f52e5
6f52e5
	# handle case where rxe_drivers are not loaded
6f52e5
	if (defined($rxe_names{$eth})) {
6f52e5
		$rxe = $rxe_names{$eth};
6f52e5
		$rmtu = $rxe_mtu{$rxe};
6f52e5
	}
6f52e5
	else {
6f52e5
		$rxe = "";
6f52e5
		$rmtu = "";
6f52e5
	}
6f52e5
6f52e5
	if ((!defined($instance) 
6f52e5
	     && (($linkonly == 0) || ($link_state{$eth} =~ "yes")))
6f52e5
	    || (defined($instance) && ($rxe =~ "$instance"))) {
6f52e5
	    $outp[$ln] =  set_field("$eth");
6f52e5
	    $outp[$ln] .= "\t";
6f52e5
	    $outp[$ln] .= set_field("$link_state{$eth}");
6f52e5
	    $outp[$ln] .= "\t";
6f52e5
	    $outp[$ln] .= set_field(exists($eth_driver{$eth}) ? $eth_driver{$eth} : "");
6f52e5
	    $outp[$ln] .= "\t";
6f52e5
	    $outp[$ln] .= set_field("$link_speed{$eth}");
6f52e5
	    $outp[$ln] .= "\t";
6f52e5
	    $outp[$ln] .= set_field("$eth_mtu{$eth}");
6f52e5
	    $outp[$ln] .= "\t";
6f52e5
	    $outp[$ln] .= set_field("$ipv4_addr{$eth}");
6f52e5
	    $outp[$ln] .= "\t";
6f52e5
	    $outp[$ln] .= set_field("$rxe");
6f52e5
	    $outp[$ln] .= "\t";
6f52e5
	    $outp[$ln] .= set_field("$rmtu");
6f52e5
	    $ln++;
6f52e5
	}
6f52e5
    }
6f52e5
6f52e5
    status_print(@outp);
6f52e5
}
6f52e5
6f52e5
# read file containing list of ethernet devices into a list
6f52e5
sub populate_persistence {
6f52e5
    my $i = 0;
6f52e5
    
6f52e5
    open FILE, $persistence_file;
6f52e5
    while(<FILE>) {
6f52e5
	my $line = $_;
6f52e5
	chomp($line);
6f52e5
	$line =~ s/^\s+//g;
6f52e5
	if ($line =~ /[\w]+[\d]/) {
6f52e5
	    # in case we add fields later
6f52e5
	    my ($eth, $cruft) = split(/\s+/, $line, 2);
6f52e5
	    if ($eth =~ /^[\w]+[\d]/) {
6f52e5
		$persistence_array[$i] = $eth;
6f52e5
		$persistence_hash{$eth} = $i++;
6f52e5
	    }
6f52e5
	}
6f52e5
    }
6f52e5
    close FILE;
6f52e5
6f52e5
    $num_persistent = $i;
6f52e5
}
6f52e5
6f52e5
# print out list of ethernet devices to file
6f52e5
sub commit_persistent {
6f52e5
    my $i;
6f52e5
    my $eth;
6f52e5
6f52e5
    open(PF, ">$persistence_file");
6f52e5
    
6f52e5
    for ($i = 0; $i < $num_persistent; $i++) {
6f52e5
	$eth = $persistence_array[$i];
6f52e5
	if ($eth =~ /[\w]+[\d]/) {
6f52e5
	    print(PF "$persistence_array[$i]\n");
6f52e5
	}
6f52e5
    }
6f52e5
6f52e5
    close(PF);
6f52e5
}
6f52e5
6f52e5
sub delete_persistent {
6f52e5
    my $eth = $_[0];
6f52e5
    
6f52e5
    if (defined($persistence_hash{$eth})) {
6f52e5
	$persistence_array[$persistence_hash{$eth}] = "";
6f52e5
    }
6f52e5
}
6f52e5
6f52e5
sub add_persistent {
6f52e5
    my $eth = $_[0];
6f52e5
6f52e5
    # Is this one already in the persistence list?
6f52e5
    if (!defined($persistence_hash{$eth})) {
6f52e5
	$persistence_array[$num_persistent] = $eth;
6f52e5
	$persistence_hash{$eth} = $num_persistent;
6f52e5
	$num_persistent++;
6f52e5
    }
6f52e5
}
6f52e5
6f52e5
# add new rxe device to eth if not already up
6f52e5
sub rxe_add {
6f52e5
    my $eth = $_[0];
6f52e5
6f52e5
    if (!($eth =~ /[\w]+[\d]/)) {
6f52e5
	print "eth_name ($eth) looks bogus\n";
6f52e5
	return;
6f52e5
    }
6f52e5
6f52e5
    if (!defined($rxe_names{$eth})) {
6f52e5
	system("echo '$eth' > $parms/add");
6f52e5
    }
6f52e5
    if (!$no_persist) {
6f52e5
	add_persistent($eth);
6f52e5
	commit_persistent();
6f52e5
    }
6f52e5
}
6f52e5
6f52e5
sub rxe_remove {
6f52e5
    my $arg2 = $_[0];
6f52e5
    my $rxe;
6f52e5
    my $eth;
6f52e5
6f52e5
    print "remove $arg2\n"  if ($debug > 0);
6f52e5
6f52e5
    if ($arg2 =~ /[\w]+[\d]/) {
6f52e5
	$eth = $arg2;
6f52e5
	$rxe = $rxe_names{$eth};
6f52e5
    }
6f52e5
    elsif ($arg2 =~ /rxe[0123456789]/) {
6f52e5
	$rxe = $arg2;
6f52e5
	$eth = $eth_names{$rxe};
6f52e5
    }
6f52e5
    elsif ($arg2 eq "all") {
6f52e5
	$rxe = "all";
6f52e5
    }
6f52e5
6f52e5
    if (($rxe eq "all") || ($rxe =~ /^rxe[0123456789]/)) {
6f52e5
	my $cmd = "echo '$rxe' > $parms/remove";
6f52e5
	#print "$cmd\n";
6f52e5
	system($cmd);
6f52e5
	if (!$no_persist) {
6f52e5
	    if ($rxe eq "all") {
6f52e5
		unlink($persistence_file);
6f52e5
	    }
6f52e5
	    elsif ($eth =~/[\w]+[\d]/) {
6f52e5
		delete_persistent($eth);
6f52e5
		commit_persistent();
6f52e5
	    }
6f52e5
	    else {
6f52e5
		print "Warning: Unable to resolve ethname; "
6f52e5
		    . "instance may persist on restart\n";
6f52e5
	    }
6f52e5
	}
6f52e5
    }
6f52e5
    else {
6f52e5
	print "rxe instance $rxe not found\n";
6f52e5
    }
6f52e5
}
6f52e5
6f52e5
sub get_devinfo {
6f52e5
    my $rxe = $_[0];
6f52e5
6f52e5
    my $cmd = "ibv_devinfo -d $rxe";
6f52e5
    return `$cmd`;
6f52e5
}
6f52e5
6f52e5
# allow unsupported modules to load in SLES11 if allowed
6f52e5
sub modprobe {
6f52e5
    my $module = $_[0];
6f52e5
    my $opts = $_[1];
6f52e5
    my @lines;
6f52e5
    my $line;
6f52e5
6f52e5
    if ($modprobe_checked == "0") {
6f52e5
	@lines = `modprobe -c`;
6f52e5
	foreach $line (@lines) {
6f52e5
	    if ($line =~ /^allow_unsupported_modules  *0/) {
6f52e5
		$modprobe_opt = " --allow-unsupported-modules ";
6f52e5
		last;
6f52e5
	    }
6f52e5
	}
6f52e5
	$modprobe_checked = "1";
6f52e5
    }
6f52e5
6f52e5
    if (!defined($opts)) {
6f52e5
	$opts = "";
6f52e5
    }
6f52e5
6f52e5
    system("modprobe $modprobe_opt $module $opts");
6f52e5
}
6f52e5
6f52e5
# bring up rxe
6f52e5
sub do_start {
6f52e5
    my $proto_str = "";
6f52e5
6f52e5
    system("mkdir -p $persistence_path");
6f52e5
    system("touch $persistence_file");
6f52e5
6f52e5
    modprobe("ib_core");
6f52e5
    modprobe("ib_uverbs");
6f52e5
    modprobe("rdma_ucm");
6f52e5
    modprobe("rdma_rxe");
6f52e5
6f52e5
    populate_persistence();
6f52e5
    system("udevadm control --reload");
6f52e5
6f52e5
    foreach my $eth (@persistence_array) {
6f52e5
	rxe_add($eth);
6f52e5
    }
6f52e5
6f52e5
    get_names();
6f52e5
6f52e5
    foreach my $rxe (@rxe_array) {
6f52e5
	my $stat = get_devinfo($rxe);
6f52e5
	if ($stat =~ "PORT_DOWN") {
6f52e5
		my $cmd = "ip link set $eth_names{$rxe} up";
6f52e5
		system($cmd);
6f52e5
	}
6f52e5
    }
6f52e5
6f52e5
}
6f52e5
6f52e5
# check if argument is an integer
6f52e5
sub is_integer {
6f52e5
    defined $_[0] && $_[0] =~ /^[+-]?\d+$/;
6f52e5
}
6f52e5
6f52e5
# remove all rxe devices and unload drivers
6f52e5
sub do_stop {
6f52e5
    my $rxe;
6f52e5
6f52e5
    foreach $rxe (@rxe_array) {
6f52e5
	system("echo '$rxe' > $sys/remove");
6f52e5
    }
6f52e5
6f52e5
    if (-e $sys) {
6f52e5
	system("rmmod rdma_rxe");
6f52e5
    }
6f52e5
6f52e5
    if (-e $sys) {
6f52e5
	print "unable to unload drivers, reboot required\n";
6f52e5
    }
6f52e5
}
6f52e5
6f52e5
sub do_debug {
6f52e5
    my $arg2 = $_[0];
6f52e5
    my $debugfile = "$parms/debug";
6f52e5
    chomp($arg2);
6f52e5
6f52e5
    if (!(-e "$debugfile")) {
6f52e5
	print "Error: debug is compiled out of this rxe driver\n";
6f52e5
	return;
6f52e5
    }
6f52e5
6f52e5
    if    ($arg2 eq "on")  { system("echo '31' > $debugfile"); }
6f52e5
    elsif ($arg2 eq "off") { system("echo '0'  > $debugfile"); }
6f52e5
    elsif ($arg2 eq "0")   { system("echo '0'  > $debugfile"); }
6f52e5
    elsif ($arg2 eq "")    { }
6f52e5
	elsif ($arg2 ge "0" && $arg2 le "31") {
6f52e5
	    system("echo '$arg2' > $debugfile");
6f52e5
	}
6f52e5
	else {
6f52e5
	    print "unrecognized debug cmd ($arg2)\n";
6f52e5
	}
6f52e5
6f52e5
    my $current = read_file($debugfile);
6f52e5
    chomp($current);
6f52e5
    if ($current > 0) {
6f52e5
	print "Debug is ON ($current)\n";
6f52e5
    }
6f52e5
    elsif ($current == 0) {
6f52e5
	print "Debug is OFF\n";
6f52e5
    }
6f52e5
    else {
6f52e5
	print "Unrecognized debug value\n";
6f52e5
    }
6f52e5
}
6f52e5
6f52e5
sub max {
6f52e5
    my $a = $_[0];
6f52e5
    my $b = $_[1];
6f52e5
    return $a if ($a > $b);
6f52e5
    return $b;
6f52e5
}
6f52e5
6f52e5
# show usage for rxe_cfg
6f52e5
sub usage {
6f52e5
    print "  Usage:\n";
6f52e5
    print "    rxe_cfg [options] start|stop|status|persistent\n";
6f52e5
    print "    rxe_cfg debug on|off|<num>\n";
6f52e5
    print "    rxe_cfg [-n] add <ndev>\n";
6f52e5
    print "    rxe_cfg [-n] remove <ndev>|<rdev>\n";
6f52e5
    print "\n";
6f52e5
    print "    <ndev> = network device e.g. eth3\n";
6f52e5
    print "    <rdev> = rdma device e.g. rxe1\n";
6f52e5
    print "\n";
6f52e5
    print "  Options:\n";
6f52e5
    print "    -h: print this usage information\n";
6f52e5
    print "    -n: do not make the configuration action persistent\n";
6f52e5
    print "    -v: print additional debug output\n";
6f52e5
    print "    -l: show status for interfaces with link up\n";
6f52e5
    print "    -p <num>: (start command only) - set ethertype\n";
6f52e5
}
6f52e5
6f52e5
sub main {
6f52e5
    GetOptions(
6f52e5
	   "-h"          => \$help,
6f52e5
	   "--help"      => \$help,
6f52e5
	   "-n"          => \$no_persist,
6f52e5
	   "-v:+"        => \$debug,
6f52e5
	   "-f"          => \$force,
6f52e5
	   "-l"          => \$linkonly,
6f52e5
	   );
6f52e5
6f52e5
    my $arg1 = $ARGV[0];
6f52e5
    my $arg2 = $ARGV[1];
6f52e5
    my $arg3 = $ARGV[2];
6f52e5
6f52e5
    # status is the default
6f52e5
    if (!defined($arg1) || ($arg1 =~ /status/)) {
6f52e5
        do_status($arg2);
6f52e5
        exit;
6f52e5
    }
6f52e5
6f52e5
    if ($help) {
6f52e5
        usage();
6f52e5
        exit;
6f52e5
    }
6f52e5
6f52e5
    # stuff that does not require modules to be loaded
6f52e5
    if    ($arg1 eq "help")       { usage(); exit; }
6f52e5
    elsif ($arg1 eq "start")      { do_start(); do_status(); exit; }
6f52e5
    elsif ($arg1 eq "persistent") { system("cat $persistence_file"); exit; }
6f52e5
6f52e5
6f52e5
    # can't do much else, bail if modules aren't loaded
6f52e5
    if (check_module_status()) {
6f52e5
	exit;
6f52e5
    }
6f52e5
6f52e5
    # create persistence file if necessary
6f52e5
    make_path($persistence_path);
6f52e5
    if (!(-e $persistence_file)) {
6f52e5
        `touch $persistence_file`;
6f52e5
    }
6f52e5
6f52e5
    # Get full context of the configuration
6f52e5
    populate_persistence();
6f52e5
    get_names();
6f52e5
    get_dev_info();
6f52e5
6f52e5
    # Stuff that requires the rdma_rxe module to be loaded
6f52e5
    if    ($arg1 eq "stop")   { do_stop(); 	   exit; }
6f52e5
    elsif ($arg1 eq "debug")  { do_debug($arg2);   exit; }
6f52e5
    elsif ($arg1 eq "add")    { rxe_add($arg2);    exit; }
6f52e5
    elsif ($arg1 eq "remove") { rxe_remove($arg2); exit; }
6f52e5
    elsif ($arg1 eq "help")   { usage();	   exit; }
6f52e5
}
6f52e5
6f52e5
main();
6f52e5
6f52e5
exit;