diff options
| author | Martin Braun <martin.braun@ettus.com> | 2017-05-17 00:20:55 -0700 | 
|---|---|---|
| committer | Martin Braun <martin.braun@ettus.com> | 2017-12-22 15:03:53 -0800 | 
| commit | 3102bf1cee9e62cf8f8c3656c664a6c9c4fa9644 (patch) | |
| tree | 237b5b03a9ed7936437d053ca0f2435c3eb5c838 /mpm/python | |
| parent | 82331cb97639515f0a5230efd154def3356c360a (diff) | |
| download | uhd-3102bf1cee9e62cf8f8c3656c664a6c9c4fa9644.tar.gz uhd-3102bf1cee9e62cf8f8c3656c664a6c9c4fa9644.tar.bz2 uhd-3102bf1cee9e62cf8f8c3656c664a6c9c4fa9644.zip  | |
mpm: periphs and n310 use eth table dispatcher now
Diffstat (limited to 'mpm/python')
| -rw-r--r-- | mpm/python/usrp_mpm/periph_manager/base.py | 41 | ||||
| -rw-r--r-- | mpm/python/usrp_mpm/periph_manager/n310.py | 43 | 
2 files changed, 46 insertions, 38 deletions
diff --git a/mpm/python/usrp_mpm/periph_manager/base.py b/mpm/python/usrp_mpm/periph_manager/base.py index df6ee8b4b..846797c20 100644 --- a/mpm/python/usrp_mpm/periph_manager/base.py +++ b/mpm/python/usrp_mpm/periph_manager/base.py @@ -24,6 +24,7 @@ from six import iteritems, itervalues  from ..mpmlog import get_logger  from .udev import get_eeprom_paths  from .udev import get_spidev_nodes +from usrp_mpm import net  EEPROM_DEFAULT_HEADER = struct.Struct("!I I") @@ -231,6 +232,11 @@ class PeriphManagerBase(object):      # dboards, but if it's shorter, it simply won't instantiate list SPI nodes      # for those dboards.      dboard_spimaster_addrs = [] +    # Lists the network interfaces which can theoretically support CHDR. These +    # do not have to exist, but these interfaces will be probed for +    # availability. If the list is empty, no CHDR traffic will be possible over +    # the network. Example: ['eth1', 'eth2'] +    chdr_interfaces = []      def __init__(self, args): @@ -243,6 +249,8 @@ class PeriphManagerBase(object):          self._init_mboard_with_eeprom()          self._init_dboards(args.override_db_pids)          self._available_endpoints = range(256) +        self._init_args = {} +        self._chdr_interfaces = []      def _init_mboard_with_eeprom(self):          """ @@ -264,7 +272,7 @@ class PeriphManagerBase(object):                  # In C++, we can only handle dicts if all the values are of the                  # same type. So we must convert them all to strings here:                  self.mboard_info[key] = str(self._eeprom_head.get(key, '')) -            if self._eeprom_head.has_key('pid') and not self._eeprom_head['pid'] in self.pids: +            if self._eeprom_head.has_key('pid') and self._eeprom_head['pid'] not in self.pids:                  self.log.error("Found invalid PID in EEPROM: 0x{:04X}. Valid PIDs are: {}".format(                      self._eeprom_head['pid'],                      ", ".join(["0x{:04X}".format(x) for x in self.pids]), @@ -294,7 +302,6 @@ class PeriphManagerBase(object):          if len(dboard_eeprom_paths) > self.max_num_dboards:              self.log.warning("Found more EEPROM paths than daughterboards. Ignoring some of them.")              dboard_eeprom_paths = dboard_eeprom_paths[:self.max_num_dboards] -        num_dboards = len(dboard_eeprom_paths)          self.dboards = []          for dboard_idx, dboard_eeprom_path in enumerate(dboard_eeprom_paths):              self.log.debug("Initializing dboard {}...".format(dboard_idx)) @@ -323,10 +330,10 @@ class PeriphManagerBase(object):                  spi_nodes = []                  self.log.warning("No SPI nodes for dboard {}.".format(dboard_idx))              dboard_info = { -                    'eeprom_md': dboard_eeprom_md, -                    'eeprom_rawdata': dboard_eeprom_rawdata, -                    'pid': db_pid, -                    'spi_nodes': spi_nodes, +                'eeprom_md': dboard_eeprom_md, +                'eeprom_rawdata': dboard_eeprom_rawdata, +                'pid': db_pid, +                'spi_nodes': spi_nodes,              }              # This will actually instantiate the dboard class:              db_class = get_dboard_class_from_pid(db_pid) @@ -338,6 +345,20 @@ class PeriphManagerBase(object):          # self.overlays = "" +    def _init_interfaces(self): +        """ +        Initialize the list of network interfaces +        """ +        self.log.trace("Testing available interfaces out of `{}'".format( +            self.chdr_interfaces +        )) +        valid_ifaces = net.get_valid_interfaces(self.chdr_interfaces) +        self.log.debug("Found CHDR interfaces: `{}'".format(valid_ifaces)) +        self._chdr_interfaces = { +            x: net.get_iface_info(x) +            for x in valid_ifaces +        } +      def init(self, args):          """          Run the mboard initialization. This is typically done at the beginning @@ -352,6 +373,9 @@ class PeriphManagerBase(object):          self.log.info("Mboard init() called with device args `{}'.".format(              ",".join(['{}={}'.format(x, args[x]) for x in args])          )) +        self._init_args = args +        self.log.info("Identifying available network interfaces...") +        self._init_interfaces()          self.log.debug("Initializing dboards...")          for dboard in self.dboards:              dboard.init(args) @@ -420,8 +444,3 @@ class PeriphManagerBase(object):          """          raise NotImplementedError("_allocate_sid() not implented") -    def get_interfaces(self): -        """ -        Overload this method in actual device implementation -        """ -        return [] diff --git a/mpm/python/usrp_mpm/periph_manager/n310.py b/mpm/python/usrp_mpm/periph_manager/n310.py index 7c52bbf30..618ab0b7e 100644 --- a/mpm/python/usrp_mpm/periph_manager/n310.py +++ b/mpm/python/usrp_mpm/periph_manager/n310.py @@ -28,6 +28,7 @@ from .net import get_mac_addr  from ..mpmtypes import SID  from ..uio import UIO  from ..sysfs_gpio import SysFSGPIO +from ..ethtable import EthDispatcherTable  from .. import libpyusrp_periphs as lib @@ -110,7 +111,9 @@ class n310(PeriphManagerBase):      dboard_eeprom_addr = "e0004000.i2c"      dboard_eeprom_max_len = 64      dboard_spimaster_addrs = ["e0006000.spi",] - +    chdr_interfaces = ['eth1', 'eth2'] +    # N310-specific settings +    eth_tables = {'eth1': 'misc-enet-regs0', 'eth2': 'misc-enet-regs1'}      def __init__(self, args):          # First initialize parent class - will populate self._eeprom_head and self._eeprom_rawdata @@ -130,19 +133,18 @@ class n310(PeriphManagerBase):          # if header.get("dataversion", 0) == 1:          self.log.info("mboard info: {}".format(self.mboard_info)) - -    def get_interfaces(self): -        """ -        returns available transport interfaces -        """ -        return [iface for iface in self.interfaces.keys() -                if iface.startswith("sfp")] - -    def get_interface_addrs(self, interface): +    def init(self, args):          """ -        returns discovered ipv4 addresses for a given interface +        Calls init() on the parent class, and then programs the Ethernet +        dispatchers accordingly.          """ -        return self.interfaces.get(interface, {}).get("addrs", []) +        super(n310, self).init(args) +        self._eth_dispatchers = { +            x: EthDispatcherTable(self.eth_tables.get(x)) +            for x in self._chdr_interfaces.keys() +        } +        for ifname, table in iteritems(self._eth_dispatchers): +            table.set_ipv4_addr(self._chdr_interfaces[ifname]['ip_addr'])      def _allocate_sid(self, sender_addr, port, sid, xbar_src_addr, xbar_src_port):          """ @@ -162,21 +164,8 @@ class n310(PeriphManagerBase):              sid.set_src_ep(new_ep)              my_xbar = lib.xbar.xbar.make("/dev/crossbar0") # TODO              my_xbar.set_route(xbar_src_addr, 0) # TODO -            self.log.debug("Getting UIO device for Ethernet configuration...") -            uio_obj = UIO(label="misc-enet-regs0", read_only=False) -            self.log.info("got my uio") -            self.log.info("ip_addr: %s", sender_addr) -            # self.log.info("mac_addr: %s", mac_addr) -            ip_addr = int(netaddr.IPAddress(sender_addr)) -            mac_addr = int(netaddr.EUI(mac_addr)) -            uio_obj.poke32(0x1000 + 4*new_ep, ip_addr) -            print("sid: %x" % (sid.get())) -            print("gonna poke: %x %x" % (0x1000+4*new_ep, ip_addr)) -            uio_obj.poke32(0x1800 + 4*new_ep, mac_addr & 0xFFFFFFFF) -            print("gonna poke: %x %x" % (0x1800+4*new_ep, mac_addr)) -            port = int(port) -            uio_obj.poke32(0x1400 + 4*new_ep, ((int(port) << 16) | (mac_addr >> 32))) -            print("gonna poke: %x %x" % (0x1400+4*new_ep, ((port << 16) | (mac_addr >> 32)))) +            eth_dispatcher = self._eth_dispatchers['eth1'] # TODO +            eth_dispatcher.set_route(sid.reversed(), sender_addr, port)          return sid.get()      def get_clock_sources(self):  | 
