RE: [PATCH rdma-core] Add Red Hat's ibdev2netdev helper

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




> -----Original Message-----
> From: linux-rdma-owner@xxxxxxxxxxxxxxx <linux-rdma-
> owner@xxxxxxxxxxxxxxx> On Behalf Of Mark Bloch
> Sent: Tuesday, December 11, 2018 1:57 PM
> To: Jarod Wilson <jarod@xxxxxxxxxx>; linux-rdma@xxxxxxxxxxxxxxx
> Cc: Doug Ledford <dledford@xxxxxxxxxx>; Honggang Li <honli@xxxxxxxxxx>
> Subject: Re: [PATCH rdma-core] Add Red Hat's ibdev2netdev helper
> 
> 
> 
> On 12/11/18 11:46 AM, Jarod Wilson wrote:
> > This is a helper script that Red Hat had previously been including in
> > it's ibutils package, which is no more, with the retirement of ibutils
> > and
> > ibutils2 being proprietary to Mellanox now. This script still has use,
> > and needs a better home, so we'd like to add it to rdma-core's redhat/
> > directory -- if not somewhere more generic, should other distros wish
> > to make use of it as well.
> 
> Why not tell users to use rdma tool (iproute2)?
> 
Because rdma tool currently doesn’t show corresponding IPoIB upper netdevice(s) of for the IB device.
For a given rdma device there can be multiple netdevices exist for RoCE ports.
Rdma tool (and ibdev2netdev) doesn't show them.
The scope of ibdev2netdev currently is wider than what rdma tool shows.
So yes, its good recommendation to RoCE and representor users.

> $ rdma link
> 1/1: mlx5_0/1: state ACTIVE physical_state LINK_UP netdev ens1f0
> 2/1: mlx5_1/1: state ACTIVE physical_state LINK_UP netdev ens1f1
> 4/1: mlx5_3/1: state ACTIVE physical_state LINK_UP netdev ens4f1
> 5/1: mlx5_4/1: state DOWN physical_state DISABLED netdev ens5f0
> 6/1: mlx5_5/1: state DOWN physical_state DISABLED netdev ens5f1
> 11/1: mlx5_2/1: state DOWN physical_state DISABLED netdev eth0_65534
> 12/1: mlx5_6/1: state DOWN physical_state DISABLED netdev eth1
> 13/1: mlx5_7/1: state DOWN physical_state DISABLED netdev ens4f2
> 
> Mark
> >
> > CC: Doug Ledford <dledford@xxxxxxxxxx>
> > CC: Honggang Li <honli@xxxxxxxxxx>
> > Signed-off-by: Jarod Wilson <jarod@xxxxxxxxxx>
> > ---
> > (Note: this version is somewhat reorganized and reformatted vs. what
> > Red Hat has been shipping in it's old ibutils package, due to a strong
> > distaste I have for 8-space-wide tab indents for shell scripts with
> > several levels of indenting required.)
> >
> >  redhat/ibdev2netdev | 197
> > ++++++++++++++++++++++++++++++++++++++++++++++++++++
> >  1 file changed, 197 insertions(+)
> >  create mode 100644 redhat/ibdev2netdev
> >
> > diff --git a/redhat/ibdev2netdev b/redhat/ibdev2netdev new file mode
> > 100644 index 00000000..3fbc04cb
> > --- /dev/null
> > +++ b/redhat/ibdev2netdev
> > @@ -0,0 +1,197 @@
> > +#! /bin/bash
> > +
> > +usage()
> > +{
> > +  echo "$(basename $0) <options>"
> > +  echo "-h, --help                print help message"
> > +  echo "-v, --verbose             print more info"
> > +}
> > +
> > +case $1 in
> > +  "-h" | "--help")
> > +    usage
> > +    exit 0
> > +    ;;
> > +esac
> > +
> > +if (( $# > 1 )); then
> > +  usage
> > +  exit -1
> > +fi
> > +
> > +if (( $# == 1 )) && [ "$1" != "-v" ]; then
> > +  usage
> > +  exit -1
> > +fi
> > +
> > +ibdevs=$(ls /sys/class/infiniband/)
> > +
> > +devs=$(ls /sys/class/net/ | grep ^[ei]) if [ "x$devs" == "x" ]; then
> > +  # no relevant devices - quit immediately
> > +  exit
> > +fi
> > +
> > +for d in $devs; do
> > +  if [ -f /sys/class/net/$d/dev_id ]; then
> > +    oldstyle=n
> > +    break
> > +  fi
> > +done
> > +
> > +function print_line()
> > +{
> > +  echo "$1 port $2 <===> $3"
> > +}
> > +
> > +function find_guid()
> > +{
> > +  ibdevs=$(ls /sys/class/infiniband/)
> > +  for ibdev in $ibdevs; do
> > +    ports=$(ls /sys/class/infiniband/$ibdev/ports/)
> > +    for port in $ports; do
> > +      gids=$(ls /sys/class/infiniband/$ibdev/ports/$port/gids)
> > +      for gid in $gids; do
> > +        pguid=$(cat /sys/class/infiniband/$ibdev/ports/$port/gids/$gid | cut
> -b 21- | sed -e 's/://g')
> > +        if [ x$pguid == x$1 ]; then
> > +          print_line $ibdev $port $2
> > +        fi
> > +      done
> > +    done
> > +  done
> > +}
> > +
> > +function find_mac()
> > +{
> > +  ibdevs=$(ls /sys/class/infiniband/)
> > +  for ibdev in $ibdevs; do
> > +    type=$(cat /sys/class/infiniband/$ibdev/node_type|cut -d ' ' -f 2)
> > +    ports=$(ls /sys/class/infiniband/$ibdev/ports/)
> > +    for port in $ports; do
> > +      gids=$(ls /sys/class/infiniband/$ibdev/ports/$port/gids)
> > +      for gid in $gids; do
> > +        if [[ "$type" = "RNIC" ]]; then
> > +          pmac=$(cat /sys/class/infiniband/$ibdev/ports/$port/gids/$gid |
> cut -b 1-14|sed -e 's/://g')
> > +        else
> > +          first=$(cat /sys/class/infiniband/$ibdev/ports/$port/gids/$gid | cut
> -b 21-22)
> > +          first=$(( first ^ 2 ))
> > +          first=$(printf "%02x" $first)
> > +          second=$(cat /sys/class/infiniband/$ibdev/ports/$port/gids/$gid |
> cut -b 21- | sed -e 's/://g' | cut -b 3-6)
> > +          third=$(cat /sys/class/infiniband/$ibdev/ports/$port/gids/$gid | cut
> -b 21- | sed -e 's/://g' | cut -b 11-)
> > +          pmac=$first$second$third
> > +        fi
> > +        if [ x$pmac == x$1 ]; then
> > +          print_line $ibdev $port $2
> > +        fi
> > +      done
> > +    done
> > +  done
> > +}
> > +
> > +if [ "x$oldstyle" == "xn" ]; then
> > +  for d in $ibdevs; do
> > +    ibrsc=$(cat /sys/class/infiniband/$d/device/resource)
> > +    eths=$(ls /sys/class/net/)
> > +    for eth in $eths; do
> > +      filepath_resource=/sys/class/net/$eth/device/resource
> > +
> > +      if [ -f $filepath_resource ]; then
> > +        ethrsc=$(cat $filepath_resource)
> > +        if [ "x$ethrsc" == "x$ibrsc" ]; then
> > +          filepath_devid=/sys/class/net/$eth/dev_id
> > +          filepath_devport=/sys/class/net/$eth/dev_port
> > +          if [ -f $filepath_devid ]; then
> > +            port1=0
> > +            if [ -f $filepath_devport ]; then
> > +              port1=$(cat $filepath_devport)
> > +              port1=$(printf "%d" $port1)
> > +            fi
> > +
> > +            port=$(cat $filepath_devid)
> > +            port=$(printf "%d" $port)
> > +            if [ $port1 -gt $port ]; then
> > +              port=$port1
> > +            fi
> > +
> > +            port=$(( port + 1 ))
> > +
> > +            filepath_carrier=/sys/class/net/$eth/carrier
> > +
> > +            if [ -f $filepath_carrier ]; then
> > +              link_state=$(cat $filepath_carrier 2> /dev/null)
> > +              if (( link_state == 1 )); then
> > +                link_state="Up"
> > +              else
> > +                link_state="Down"
> > +              fi
> > +            else
> > +              link_state="NA"
> > +            fi
> > +
> > +            if [ "$1" == "-v" ]; then
> > +              filepath_portstate=/sys/class/infiniband/$d/ports/$port/state
> > +              filepath_deviceid=/sys/class/infiniband/$d/device/device
> > +              filepath_fwver=/sys/class/infiniband/$d/fw_ver
> > +              filepath_vpd=/sys/class/infiniband/$d/device/vpd
> > +
> > +              # read port state
> > +              if [ -f $filepath_portstate ]; then
> > +                ibstate=$(printf "%-6s" $(cat $filepath_portstate | gawk '{print
> $2}'))
> > +              else
> > +                ibstate="na"
> > +              fi
> > +
> > +              # read device
> > +              if [ -f $filepath_deviceid ]; then
> > +                devid=$(printf "mt%d" $(cat $filepath_deviceid))
> > +              else
> > +                devid="na"
> > +              fi
> > +
> > +              # read fw version
> > +              if [ -f $filepath_fwver ]; then
> > +                fwver=$(cat $filepath_fwver)
> > +              else
> > +                fwver="na"
> > +              fi
> > +
> > +              # read device description and part id from the vpd
> > +              if [ -f $filepath_vpd ]; then
> > +                tmp=$ifs
> > +                ifs=":"
> > +                vpd_content=`cat $filepath_vpd`
> > +                devdesc=$(printf "%-15s" $(echo $vpd_content | strings | head -
> 1))
> > +                partid=$(printf "%-11s" $(echo $vpd_content | strings | head -4
> | tail -1 | gawk '{print $1}'))
> > +                ifs=$tmp
> > +              else
> > +                devdesc=""
> > +                partid="na"
> > +              fi
> > +
> > +              echo "$d ($devid - $partid) $devdesc fw $fwver port $port
> ($ibstate) ==> $eth ($link_state)"
> > +            else
> > +              echo "$d port $port ==> $eth ($link_state)"
> > +            fi
> > +          fi
> > +        fi
> > +      fi
> > +    done
> > +  done
> > +else
> > +##########################
> > +### old style
> > +##########################
> > +  ifcs=$(ifconfig -a | egrep '^eth|^ib' | gawk '{print $1}')
> > +
> > +  for ifc in $ifcs; do
> > +    len=$(cat /sys/class/net/$ifc/addr_len)
> > +    if (( len == 20 )); then
> > +      guid=$(cat /sys/class/net/$ifc/address | cut -b 37- | sed -e 's/://g')
> > +      find_guid $guid $ifc
> > +    elif (( len == 6)); then
> > +      mac=$(cat /sys/class/net/$ifc/address | sed -e 's/://g')
> > +      find_mac $mac $ifc
> > +    fi
> > +  done
> > +fi
> > +
> >




[Index of Archives]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Photo]     [Yosemite News]     [Yosemite Photos]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux