From efe9438c617d521fc3ee43421c02728627ef01c1 Mon Sep 17 00:00:00 2001 From: Roy Lee Date: Thu, 25 Jul 2019 03:14:43 +0800 Subject: [PATCH] [Accton] Correct port index and offer the default speed. (#3213) * [as5712-54x] Verified with index from 1. Add qsfp_event() for command "show interaface trancerver". Signed-off-by: roy_lee * [as6712-32x] Add default port speed. Verified with index from 1. Signed-off-by: roy_lee * [as7726-32x] Add default port speed. Verified with index from 1. Signed-off-by: roy_lee * [as7712-32x] Add default port speed. Verified with index from 1. Signed-off-by: roy_lee * [as5812-54x] Add default port speed. Verified with index from 1. Signed-off-by: roy_lee * [as5712-54x] Update port-config with 1-based index. Signed-off-by: roy_lee * [as5812-54x] Somehow the service may block, use type=simple to work-around. Add syslog function for monitor. Signed-off-by: roy_lee * [as7716-32x] Update port-config with 1-based index. Signed-off-by: roy_lee * [as7816-64x] Update port-config with 1-based index. Implement sfputil change_event. Signed-off-by: roy_lee * [as7326-56x] Update port-config with 1-based index. Implement sfputil change_event. Signed-off-by: roy_lee * Remove debug code. Signed-off-by: roy_lee * [as7312-54x] Update port-config with 1-based index and default port speed. Signed-off-by: roy_lee --- .../Accton-AS5712-54X/port_config.ini | 146 +++++----- .../plugins/sfputil.py | 255 ++++++++++-------- .../Accton-AS5812-54X/port_config.ini | 146 +++++----- .../plugins/sfputil.py | 221 ++++++++------- .../Accton-AS6712-32X/port_config.ini | 66 ++--- .../plugins/sfputil.py | 190 +++++++------ .../Accton-AS7312-54X/port_config.ini | 110 ++++---- .../plugins/sfputil.py | 160 +++++------ .../Accton-AS7326-56X/port_config.ini | 114 ++++---- .../plugins/sfputil.py | 251 +++++++++-------- .../Accton-AS7712-32X/port_config.ini | 66 ++--- .../plugins/sfputil.py | 88 ++++-- .../Accton-AS7716-32X/port_config.ini | 66 ++--- .../plugins/sfputil.py | 141 ++++++---- .../Accton-AS7726-32X/port_config.ini | 66 ++--- .../plugins/sfputil.py | 168 ++++++++---- .../Accton-AS7816-64X/port_config.ini | 130 ++++----- .../plugins/sfputil.py | 91 +++++-- .../as5812-54x/classes/fanutil.py | 47 ++-- .../as5812-54x/classes/thermalutil.py | 14 +- .../service/as5812-platform-monitor.service | 4 +- .../as5812-54x/utils/accton_as5812_monitor.py | 97 ++++--- .../as7326-56x/modules/accton_i2c_cpld.c | 37 ++- .../as7816-64x/utils/accton_as7816_util.py | 26 +- .../common/modules/accton_i2c_cpld.c | 15 +- 25 files changed, 1526 insertions(+), 1189 deletions(-) mode change 100644 => 100755 device/accton/x86_64-accton_as6712_32x-r0/Accton-AS6712-32X/port_config.ini diff --git a/device/accton/x86_64-accton_as5712_54x-r0/Accton-AS5712-54X/port_config.ini b/device/accton/x86_64-accton_as5712_54x-r0/Accton-AS5712-54X/port_config.ini index f41bf2ef64..ee60c52622 100755 --- a/device/accton/x86_64-accton_as5712_54x-r0/Accton-AS5712-54X/port_config.ini +++ b/device/accton/x86_64-accton_as5712_54x-r0/Accton-AS5712-54X/port_config.ini @@ -1,73 +1,73 @@ -# name lanes alias index -Ethernet0 13 tenGigE0 0 -Ethernet1 14 tenGigE1 1 -Ethernet2 15 tenGigE2 2 -Ethernet3 16 tenGigE3 3 -Ethernet4 21 tenGigE4 4 -Ethernet5 22 tenGigE5 5 -Ethernet6 23 tenGigE6 6 -Ethernet7 24 tenGigE7 7 -Ethernet8 25 tenGigE8 8 -Ethernet9 26 tenGigE9 9 -Ethernet10 27 tenGigE10 10 -Ethernet11 28 tenGigE11 11 -Ethernet12 29 tenGigE12 12 -Ethernet13 30 tenGigE13 13 -Ethernet14 31 tenGigE14 14 -Ethernet15 32 tenGigE15 15 -Ethernet16 45 tenGigE16 16 -Ethernet17 46 tenGigE17 17 -Ethernet18 47 tenGigE18 18 -Ethernet19 48 tenGigE19 19 -Ethernet20 49 tenGigE20 20 -Ethernet21 50 tenGigE21 21 -Ethernet22 51 tenGigE22 22 -Ethernet23 52 tenGigE23 23 -Ethernet24 53 tenGigE24 24 -Ethernet25 54 tenGigE25 25 -Ethernet26 55 tenGigE26 26 -Ethernet27 56 tenGigE27 27 -Ethernet28 57 tenGigE28 28 -Ethernet29 58 tenGigE29 29 -Ethernet30 59 tenGigE30 30 -Ethernet31 60 tenGigE31 31 -Ethernet32 61 tenGigE32 32 -Ethernet33 62 tenGigE33 33 -Ethernet34 63 tenGigE34 34 -Ethernet35 64 tenGigE35 35 -Ethernet36 65 tenGigE36 36 -Ethernet37 66 tenGigE37 37 -Ethernet38 67 tenGigE38 38 -Ethernet39 68 tenGigE39 39 -Ethernet40 69 tenGigE40 40 -Ethernet41 70 tenGigE41 41 -Ethernet42 71 tenGigE42 42 -Ethernet43 72 tenGigE43 43 -Ethernet44 73 tenGigE44 44 -Ethernet45 74 tenGigE45 45 -Ethernet46 75 tenGigE46 46 -Ethernet47 76 tenGigE47 47 -Ethernet48 97 tenGigE48 48 -Ethernet49 98 tenGigE49 49 -Ethernet50 99 tenGigE50 50 -Ethernet51 100 tenGigE51 51 -Ethernet52 101 tenGigE52 52 -Ethernet53 102 tenGigE53 53 -Ethernet54 103 tenGigE54 54 -Ethernet55 104 tenGigE55 55 -Ethernet56 81 tenGigE56 56 -Ethernet57 82 tenGigE57 57 -Ethernet58 83 tenGigE58 58 -Ethernet59 84 tenGigE59 59 -Ethernet60 105 tenGigE60 60 -Ethernet61 106 tenGigE61 61 -Ethernet62 107 tenGigE62 62 -Ethernet63 108 tenGigE63 63 -Ethernet64 109 tenGigE64 64 -Ethernet65 110 tenGigE65 65 -Ethernet66 111 tenGigE66 66 -Ethernet67 112 tenGigE67 67 -Ethernet68 77 tenGigE68 68 -Ethernet69 78 tenGigE69 69 -Ethernet70 79 tenGigE70 70 -Ethernet71 80 tenGigE71 71 +# name lanes alias index speed +Ethernet0 13 tenGigE0 1 10000 +Ethernet1 14 tenGigE1 2 10000 +Ethernet2 15 tenGigE2 3 10000 +Ethernet3 16 tenGigE3 4 10000 +Ethernet4 21 tenGigE4 5 10000 +Ethernet5 22 tenGigE5 6 10000 +Ethernet6 23 tenGigE6 7 10000 +Ethernet7 24 tenGigE7 8 10000 +Ethernet8 25 tenGigE8 9 10000 +Ethernet9 26 tenGigE9 10 10000 +Ethernet10 27 tenGigE10 11 10000 +Ethernet11 28 tenGigE11 12 10000 +Ethernet12 29 tenGigE12 13 10000 +Ethernet13 30 tenGigE13 14 10000 +Ethernet14 31 tenGigE14 15 10000 +Ethernet15 32 tenGigE15 16 10000 +Ethernet16 45 tenGigE16 17 10000 +Ethernet17 46 tenGigE17 18 10000 +Ethernet18 47 tenGigE18 19 10000 +Ethernet19 48 tenGigE19 20 10000 +Ethernet20 49 tenGigE20 21 10000 +Ethernet21 50 tenGigE21 22 10000 +Ethernet22 51 tenGigE22 23 10000 +Ethernet23 52 tenGigE23 24 10000 +Ethernet24 53 tenGigE24 25 10000 +Ethernet25 54 tenGigE25 26 10000 +Ethernet26 55 tenGigE26 27 10000 +Ethernet27 56 tenGigE27 28 10000 +Ethernet28 57 tenGigE28 29 10000 +Ethernet29 58 tenGigE29 30 10000 +Ethernet30 59 tenGigE30 31 10000 +Ethernet31 60 tenGigE31 32 10000 +Ethernet32 61 tenGigE32 33 10000 +Ethernet33 62 tenGigE33 34 10000 +Ethernet34 63 tenGigE34 35 10000 +Ethernet35 64 tenGigE35 36 10000 +Ethernet36 65 tenGigE36 37 10000 +Ethernet37 66 tenGigE37 38 10000 +Ethernet38 67 tenGigE38 39 10000 +Ethernet39 68 tenGigE39 40 10000 +Ethernet40 69 tenGigE40 41 10000 +Ethernet41 70 tenGigE41 42 10000 +Ethernet42 71 tenGigE42 43 10000 +Ethernet43 72 tenGigE43 44 10000 +Ethernet44 73 tenGigE44 45 10000 +Ethernet45 74 tenGigE45 46 10000 +Ethernet46 75 tenGigE46 47 10000 +Ethernet47 76 tenGigE47 48 10000 +Ethernet48 97 tenGigE48 49 10000 +Ethernet49 98 tenGigE49 49 10000 +Ethernet50 99 tenGigE50 49 10000 +Ethernet51 100 tenGigE51 49 10000 +Ethernet52 101 tenGigE52 50 10000 +Ethernet53 102 tenGigE53 50 10000 +Ethernet54 103 tenGigE54 50 10000 +Ethernet55 104 tenGigE55 50 10000 +Ethernet56 81 tenGigE56 51 10000 +Ethernet57 82 tenGigE57 51 10000 +Ethernet58 83 tenGigE58 51 10000 +Ethernet59 84 tenGigE59 51 10000 +Ethernet60 105 tenGigE60 52 10000 +Ethernet61 106 tenGigE61 52 10000 +Ethernet62 107 tenGigE62 52 10000 +Ethernet63 108 tenGigE63 52 10000 +Ethernet64 109 tenGigE64 53 10000 +Ethernet65 110 tenGigE65 53 10000 +Ethernet66 111 tenGigE66 53 10000 +Ethernet67 112 tenGigE67 53 10000 +Ethernet68 77 tenGigE68 54 10000 +Ethernet69 78 tenGigE69 54 10000 +Ethernet70 79 tenGigE70 54 10000 +Ethernet71 80 tenGigE71 54 10000 diff --git a/device/accton/x86_64-accton_as5712_54x-r0/plugins/sfputil.py b/device/accton/x86_64-accton_as5712_54x-r0/plugins/sfputil.py index f25a65a2f4..2ca1b8eec7 100755 --- a/device/accton/x86_64-accton_as5712_54x-r0/plugins/sfputil.py +++ b/device/accton/x86_64-accton_as5712_54x-r0/plugins/sfputil.py @@ -12,14 +12,19 @@ except ImportError as e: raise ImportError("%s - required module not found" % str(e)) +#from xcvrd +SFP_STATUS_INSERTED = '1' +SFP_STATUS_REMOVED = '0' + + class SfpUtil(SfpUtilBase): """Platform-specific SfpUtil class""" - PORT_START = 0 - PORT_END = 71 - PORTS_IN_BLOCK = 72 - QSFP_PORT_START = 48 - QSFP_PORT_END = 72 + PORT_START = 1 + PORT_END = 54 + PORTS_IN_BLOCK = 54 + QSFP_PORT_START = 49 + QSFP_PORT_END = 54 BASE_VAL_PATH = "/sys/class/i2c-adapter/i2c-{0}/{1}-0050/" BASE_OOM_PATH = "/sys/bus/i2c/devices/{0}-0050/" @@ -28,87 +33,67 @@ class SfpUtil(SfpUtilBase): I2C_BUS_ORDER = -1 #The sidebands of QSFP is different. - #present is in-order. - #But lp_mode and reset are not. - qsfp_sb_map = [1, 3, 5, 2, 4, 6] + qsfp_sb_map = [0, 2, 4, 1, 3, 5] _port_to_is_present = {} _port_to_lp_mode = {} _port_to_eeprom_mapping = {} _port_to_i2c_mapping = { - 0: [1, 2], - 1: [2, 3], - 2: [3, 4], - 3: [4, 5], - 4: [5, 6], - 5: [6, 7], - 6: [7, 8], - 7: [8, 9], - 8: [9, 10], - 9: [10, 11], - 10: [11, 12], - 11: [12, 13], - 12: [13, 14], - 13: [14, 15], - 14: [15, 16], - 15: [16, 17], - 16: [17, 18], - 17: [18, 19], - 18: [19, 20], - 19: [20, 21], - 20: [21, 22], - 21: [22, 23], - 22: [23, 24], - 23: [24, 25], - 24: [25, 26], - 25: [26, 27], - 26: [27, 28], - 27: [28, 29], - 28: [29, 30], - 29: [30, 31], - 30: [31, 32], - 31: [32, 33], - 32: [33, 34], - 33: [34, 35], - 34: [35, 36], - 35: [36, 37], - 36: [37, 38], - 37: [38, 39], - 38: [39, 40], - 39: [40, 41], - 40: [41, 42], - 41: [42, 43], - 42: [43, 44], - 43: [44, 45], - 44: [45, 46], - 45: [46, 47], - 46: [47, 48], - 47: [48, 49], - 48: [49, 50],#QSFP49 - 49: [49, 50], - 50: [49, 50], - 51: [49, 50], - 52: [50, 52],#QSFP50 - 53: [50, 52], - 54: [50, 52], - 55: [50, 52], - 56: [51, 54],#QSFP51 - 57: [51, 54], - 58: [51, 54], - 59: [51, 54], - 60: [52, 51],#QSFP52 - 61: [52, 51], - 62: [52, 51], - 63: [52, 51], - 64: [53, 53], #QSFP53 - 65: [53, 53], - 66: [53, 53], - 67: [53, 53], - 68: [54, 55],#QSFP54 - 69: [54, 55], - 70: [54, 55], - 71: [54, 55], + 1: [1, 2], + 2: [2, 3], + 3: [3, 4], + 4: [4, 5], + 5: [5, 6], + 6: [6, 7], + 7: [7, 8], + 8: [8, 9], + 9: [9, 10], + 10: [10, 11], + 11: [11, 12], + 12: [12, 13], + 13: [13, 14], + 14: [14, 15], + 15: [15, 16], + 16: [16, 17], + 17: [17, 18], + 18: [18, 19], + 19: [19, 20], + 20: [20, 21], + 21: [21, 22], + 22: [22, 23], + 23: [23, 24], + 24: [24, 25], + 25: [25, 26], + 26: [26, 27], + 27: [27, 28], + 28: [28, 29], + 29: [29, 30], + 30: [30, 31], + 31: [31, 32], + 32: [32, 33], + 33: [33, 34], + 34: [34, 35], + 35: [35, 36], + 36: [36, 37], + 37: [37, 38], + 38: [38, 39], + 39: [39, 40], + 40: [40, 41], + 41: [41, 42], + 42: [42, 43], + 43: [43, 44], + 44: [44, 45], + 45: [45, 46], + 46: [46, 47], + 47: [47, 48], + 48: [48, 49], + 49: [49, 50],#QSFP49 + 50: [51, 52], + 51: [53, 54], + 52: [50, 51], + 53: [52, 53], + 54: [54, 55],#QSFP54 } @property @@ -135,16 +120,6 @@ class SfpUtil(SfpUtilBase): def port_to_eeprom_mapping(self): return self._port_to_eeprom_mapping - def __init__(self): - eeprom_path = self.BASE_OOM_PATH + "eeprom" - - for x in range(0, self.port_end+1): - self.port_to_eeprom_mapping[x] = eeprom_path.format( - self._port_to_i2c_mapping[x][1] - ) - - SfpUtilBase.__init__(self) - #Two i2c buses might get flipped order, check them both. def update_i2c_order(self): if self.I2C_BUS_ORDER < 0: @@ -162,12 +137,11 @@ class SfpUtil(SfpUtilBase): return False order = self.update_i2c_order() - if port_num < 24: - present_path = self.BASE_CPLD2_PATH.format(order) + if port_num <= 24: + present_path = self.BASE_CPLD2_PATH.format(order) else: present_path = self.BASE_CPLD3_PATH.format(order) - - present_path = present_path + "module_present_" + str(self._port_to_i2c_mapping[port_num][0]) + present_path = present_path + "module_present_" + str(port_num) self.__port_to_is_present = present_path try: @@ -187,8 +161,8 @@ class SfpUtil(SfpUtilBase): def qsfp_sb_remap(self, port_num): qsfp_start = self.qsfp_port_start - qsfp_index = self._port_to_i2c_mapping[port_num][0] - qsfp_start - qsfp_index = self.qsfp_sb_map[qsfp_index-1] + qsfp_index = port_num - qsfp_start + qsfp_index = self.qsfp_sb_map[qsfp_index] return qsfp_start+qsfp_index def get_low_power_mode_cpld(self, port_num): @@ -282,9 +256,8 @@ class SfpUtil(SfpUtilBase): mod_rst_path = lp_mode_path + "module_reset_" q = self.qsfp_sb_remap(port_num) mod_rst_path = mod_rst_path + str(q) - try: - reg_file = open(mod_rst_path, 'r+') + reg_file = open(mod_rst_path, 'r+', buffering=0) except IOError as e: print "Error: unable to open file: %s" % str(e) return False @@ -297,12 +270,82 @@ class SfpUtil(SfpUtilBase): reg_file.write('1') reg_file.close() return True - - def get_transceiver_change_event(self): - """ - TODO: This function need to be implemented - when decide to support monitoring SFP(Xcvrd) - on this platform. - """ - raise NotImplementedError + + @property + def _get_presence_bitmap(self): + nodes = [] + order = self.update_i2c_order() + + present_path = self.BASE_CPLD2_PATH.format(order) + nodes.append(present_path + "module_present_all") + present_path = self.BASE_CPLD3_PATH.format(order) + nodes.append(present_path + "module_present_all") + + bitmap = "" + for node in nodes: + try: + reg_file = open(node) + + except IOError as e: + print "Error: unable to open file: %s" % str(e) + return False + bitmap += reg_file.readline().rstrip() + " " + reg_file.close() + + rev = bitmap.split(" ") + rev = "".join(rev[::-1]) + return int(rev,16) + + + data = {'valid':0, 'last':0, 'present':0} + def get_transceiver_change_event(self, timeout=2000): + now = time.time() + port_dict = {} + port = 0 + + if timeout < 1000: + timeout = 1000 + timeout = (timeout) / float(1000) # Convert to secs + + + if now < (self.data['last'] + timeout) and self.data['valid']: + return True, {} + + reg_value = self._get_presence_bitmap + changed_ports = self.data['present'] ^ reg_value + if changed_ports: + for port in range (self.port_start, self.port_end+1): + # Mask off the bit corresponding to our port + fp_port = self._port_to_i2c_mapping[port][0] + mask = (1 << (fp_port - 1)) + if changed_ports & mask: + + if (reg_value & mask) == 0: + port_dict[port] = SFP_STATUS_REMOVED + else: + port_dict[port] = SFP_STATUS_INSERTED + + # Update cache + self.data['present'] = reg_value + self.data['last'] = now + self.data['valid'] = 1 + + return True, port_dict + else: + return True, {} + return False, {} + + + def __init__(self): + eeprom_path = self.BASE_OOM_PATH + "eeprom" + + for x in range(self.port_start, self.port_end+1): + self.port_to_eeprom_mapping[x] = eeprom_path.format( + self._port_to_i2c_mapping[x][1] + ) + + SfpUtilBase.__init__(self) + + + diff --git a/device/accton/x86_64-accton_as5812_54x-r0/Accton-AS5812-54X/port_config.ini b/device/accton/x86_64-accton_as5812_54x-r0/Accton-AS5812-54X/port_config.ini index 315fd86981..ee60c52622 100755 --- a/device/accton/x86_64-accton_as5812_54x-r0/Accton-AS5812-54X/port_config.ini +++ b/device/accton/x86_64-accton_as5812_54x-r0/Accton-AS5812-54X/port_config.ini @@ -1,73 +1,73 @@ -# name lanes alias index -Ethernet0 13 tenGigE0 1 -Ethernet1 14 tenGigE1 2 -Ethernet2 15 tenGigE2 3 -Ethernet3 16 tenGigE3 4 -Ethernet4 21 tenGigE4 5 -Ethernet5 22 tenGigE5 6 -Ethernet6 23 tenGigE6 7 -Ethernet7 24 tenGigE7 8 -Ethernet8 25 tenGigE8 9 -Ethernet9 26 tenGigE9 10 -Ethernet10 27 tenGigE10 11 -Ethernet11 28 tenGigE11 12 -Ethernet12 29 tenGigE12 13 -Ethernet13 30 tenGigE13 14 -Ethernet14 31 tenGigE14 15 -Ethernet15 32 tenGigE15 16 -Ethernet16 45 tenGigE16 17 -Ethernet17 46 tenGigE17 18 -Ethernet18 47 tenGigE18 19 -Ethernet19 48 tenGigE19 20 -Ethernet20 49 tenGigE20 21 -Ethernet21 50 tenGigE21 22 -Ethernet22 51 tenGigE22 23 -Ethernet23 52 tenGigE23 24 -Ethernet24 53 tenGigE24 25 -Ethernet25 54 tenGigE25 26 -Ethernet26 55 tenGigE26 27 -Ethernet27 56 tenGigE27 28 -Ethernet28 57 tenGigE28 29 -Ethernet29 58 tenGigE29 30 -Ethernet30 59 tenGigE30 31 -Ethernet31 60 tenGigE31 32 -Ethernet32 61 tenGigE32 33 -Ethernet33 62 tenGigE33 34 -Ethernet34 63 tenGigE34 35 -Ethernet35 64 tenGigE35 36 -Ethernet36 65 tenGigE36 37 -Ethernet37 66 tenGigE37 38 -Ethernet38 67 tenGigE38 39 -Ethernet39 68 tenGigE39 40 -Ethernet40 69 tenGigE40 41 -Ethernet41 70 tenGigE41 42 -Ethernet42 71 tenGigE42 43 -Ethernet43 72 tenGigE43 44 -Ethernet44 73 tenGigE44 45 -Ethernet45 74 tenGigE45 46 -Ethernet46 75 tenGigE46 47 -Ethernet47 76 tenGigE47 48 -Ethernet48 97 tenGigE48 49 -Ethernet49 98 tenGigE49 50 -Ethernet50 99 tenGigE50 51 -Ethernet51 100 tenGigE51 52 -Ethernet52 101 tenGigE52 53 -Ethernet53 102 tenGigE53 54 -Ethernet54 103 tenGigE54 55 -Ethernet55 104 tenGigE55 56 -Ethernet56 81 tenGigE56 57 -Ethernet57 82 tenGigE57 58 -Ethernet58 83 tenGigE58 59 -Ethernet59 84 tenGigE59 60 -Ethernet60 105 tenGigE60 61 -Ethernet61 106 tenGigE61 62 -Ethernet62 107 tenGigE62 63 -Ethernet63 108 tenGigE63 64 -Ethernet64 109 tenGigE64 65 -Ethernet65 110 tenGigE65 66 -Ethernet66 111 tenGigE66 67 -Ethernet67 112 tenGigE67 68 -Ethernet68 77 tenGigE68 69 -Ethernet69 78 tenGigE69 70 -Ethernet70 79 tenGigE70 71 -EthernEt71 80 tenGigE71 72 +# name lanes alias index speed +Ethernet0 13 tenGigE0 1 10000 +Ethernet1 14 tenGigE1 2 10000 +Ethernet2 15 tenGigE2 3 10000 +Ethernet3 16 tenGigE3 4 10000 +Ethernet4 21 tenGigE4 5 10000 +Ethernet5 22 tenGigE5 6 10000 +Ethernet6 23 tenGigE6 7 10000 +Ethernet7 24 tenGigE7 8 10000 +Ethernet8 25 tenGigE8 9 10000 +Ethernet9 26 tenGigE9 10 10000 +Ethernet10 27 tenGigE10 11 10000 +Ethernet11 28 tenGigE11 12 10000 +Ethernet12 29 tenGigE12 13 10000 +Ethernet13 30 tenGigE13 14 10000 +Ethernet14 31 tenGigE14 15 10000 +Ethernet15 32 tenGigE15 16 10000 +Ethernet16 45 tenGigE16 17 10000 +Ethernet17 46 tenGigE17 18 10000 +Ethernet18 47 tenGigE18 19 10000 +Ethernet19 48 tenGigE19 20 10000 +Ethernet20 49 tenGigE20 21 10000 +Ethernet21 50 tenGigE21 22 10000 +Ethernet22 51 tenGigE22 23 10000 +Ethernet23 52 tenGigE23 24 10000 +Ethernet24 53 tenGigE24 25 10000 +Ethernet25 54 tenGigE25 26 10000 +Ethernet26 55 tenGigE26 27 10000 +Ethernet27 56 tenGigE27 28 10000 +Ethernet28 57 tenGigE28 29 10000 +Ethernet29 58 tenGigE29 30 10000 +Ethernet30 59 tenGigE30 31 10000 +Ethernet31 60 tenGigE31 32 10000 +Ethernet32 61 tenGigE32 33 10000 +Ethernet33 62 tenGigE33 34 10000 +Ethernet34 63 tenGigE34 35 10000 +Ethernet35 64 tenGigE35 36 10000 +Ethernet36 65 tenGigE36 37 10000 +Ethernet37 66 tenGigE37 38 10000 +Ethernet38 67 tenGigE38 39 10000 +Ethernet39 68 tenGigE39 40 10000 +Ethernet40 69 tenGigE40 41 10000 +Ethernet41 70 tenGigE41 42 10000 +Ethernet42 71 tenGigE42 43 10000 +Ethernet43 72 tenGigE43 44 10000 +Ethernet44 73 tenGigE44 45 10000 +Ethernet45 74 tenGigE45 46 10000 +Ethernet46 75 tenGigE46 47 10000 +Ethernet47 76 tenGigE47 48 10000 +Ethernet48 97 tenGigE48 49 10000 +Ethernet49 98 tenGigE49 49 10000 +Ethernet50 99 tenGigE50 49 10000 +Ethernet51 100 tenGigE51 49 10000 +Ethernet52 101 tenGigE52 50 10000 +Ethernet53 102 tenGigE53 50 10000 +Ethernet54 103 tenGigE54 50 10000 +Ethernet55 104 tenGigE55 50 10000 +Ethernet56 81 tenGigE56 51 10000 +Ethernet57 82 tenGigE57 51 10000 +Ethernet58 83 tenGigE58 51 10000 +Ethernet59 84 tenGigE59 51 10000 +Ethernet60 105 tenGigE60 52 10000 +Ethernet61 106 tenGigE61 52 10000 +Ethernet62 107 tenGigE62 52 10000 +Ethernet63 108 tenGigE63 52 10000 +Ethernet64 109 tenGigE64 53 10000 +Ethernet65 110 tenGigE65 53 10000 +Ethernet66 111 tenGigE66 53 10000 +Ethernet67 112 tenGigE67 53 10000 +Ethernet68 77 tenGigE68 54 10000 +Ethernet69 78 tenGigE69 54 10000 +Ethernet70 79 tenGigE70 54 10000 +Ethernet71 80 tenGigE71 54 10000 diff --git a/device/accton/x86_64-accton_as5812_54x-r0/plugins/sfputil.py b/device/accton/x86_64-accton_as5812_54x-r0/plugins/sfputil.py index 0200aa1449..88d8e536c4 100755 --- a/device/accton/x86_64-accton_as5812_54x-r0/plugins/sfputil.py +++ b/device/accton/x86_64-accton_as5812_54x-r0/plugins/sfputil.py @@ -11,15 +11,19 @@ try: except ImportError as e: raise ImportError("%s - required module not found" % str(e)) +#from xcvrd +SFP_STATUS_INSERTED = '1' +SFP_STATUS_REMOVED = '0' + class SfpUtil(SfpUtilBase): """Platform-specific SfpUtil class""" PORT_START = 1 - PORT_END = 72 - PORTS_IN_BLOCK = 72 - QSFP_PORT_START = 48 - QSFP_PORT_END = 72 + PORT_END = 54 + PORTS_IN_BLOCK = 54 + QSFP_PORT_START = 49 + QSFP_PORT_END = 54 BASE_VAL_PATH = "/sys/class/i2c-adapter/i2c-{0}/{1}-0050/" BASE_OOM_PATH = "/sys/bus/i2c/devices/{0}-0050/" @@ -30,85 +34,67 @@ class SfpUtil(SfpUtilBase): #The sidebands of QSFP is different. #present is in-order. #But lp_mode and reset are not. - qsfp_sb_map = [1, 3, 5, 2, 4, 6] + qsfp_sb_map = [0, 2, 4, 1, 3, 5] _port_to_is_present = {} _port_to_lp_mode = {} _port_to_eeprom_mapping = {} _port_to_i2c_mapping = { - 1: [1, 2], - 2: [2, 3], - 3: [3, 4], - 4: [4, 5], - 5: [5, 6], - 6: [6, 7], - 7: [7, 8], - 8: [8, 9], - 9: [9, 10], - 10: [10, 11], - 11: [11, 12], - 12: [12, 13], - 13: [13, 14], - 14: [14, 15], - 15: [15, 16], - 16: [16, 17], - 17: [17, 18], - 18: [18, 19], - 19: [19, 20], - 20: [20, 21], - 21: [21, 22], - 22: [22, 23], - 23: [23, 24], - 24: [24, 25], - 25: [25, 26], - 26: [26, 27], - 27: [27, 28], - 28: [28, 29], - 29: [29, 30], - 30: [30, 31], - 31: [31, 32], - 32: [32, 33], - 33: [33, 34], - 34: [34, 35], - 35: [35, 36], - 36: [36, 37], - 37: [37, 38], - 38: [38, 39], - 39: [39, 40], - 40: [40, 41], - 41: [41, 42], - 42: [42, 43], - 43: [43, 44], - 44: [44, 45], - 45: [45, 46], - 46: [46, 47], - 47: [47, 48], - 48: [48, 49], - 49: [49, 50],#QSFP49 - 50: [49, 50], - 51: [49, 50], - 52: [49, 50], - 53: [50, 52],#QSFP50 - 54: [50, 52], - 55: [50, 52], - 56: [50, 52], - 57: [51, 54],#QSFP51 - 58: [51, 54], - 59: [51, 54], - 60: [51, 54], - 61: [52, 51],#QSFP52 - 62: [52, 51], - 63: [52, 51], - 64: [52, 51], - 65: [53, 53],#QSFP53 - 66: [53, 53], - 67: [53, 53], - 68: [53, 53], - 69: [54, 55],#QSFP54 - 70: [54, 55], - 71: [54, 55], - 72: [54, 55], + 1: [1, 2], + 2: [2, 3], + 3: [3, 4], + 4: [4, 5], + 5: [5, 6], + 6: [6, 7], + 7: [7, 8], + 8: [8, 9], + 9: [9, 10], + 10: [10,11], + 11: [11,12], + 12: [12,13], + 13: [13,14], + 14: [14,15], + 15: [15,16], + 16: [16,17], + 17: [17,18], + 18: [18,19], + 19: [19,20], + 20: [20,21], + 21: [21,22], + 22: [22,23], + 23: [23,24], + 24: [24,25], + 25: [25,26], + 26: [26,27], + 27: [27,28], + 28: [28,29], + 29: [29,30], + 30: [30,31], + 31: [31,32], + 32: [32,33], + 33: [33,34], + 34: [34,35], + 35: [35,36], + 36: [36,37], + 37: [37,38], + 38: [38,39], + 39: [39,40], + 40: [40,41], + 41: [41,42], + 42: [42,43], + 43: [43,44], + 44: [44,45], + 45: [45,46], + 46: [46,47], + 47: [47,48], + 48: [48,49], + 49: [49,50],#QSFP_start + 50: [51,52], + 51: [53,54], + 52: [50,51], + 53: [52,53], + 54: [54,55], } @property @@ -142,7 +128,6 @@ class SfpUtil(SfpUtilBase): self.port_to_eeprom_mapping[x] = eeprom_path.format( self._port_to_i2c_mapping[x][1] ) - SfpUtilBase.__init__(self) #Two i2c buses might get flipped order, check them both. @@ -170,7 +155,7 @@ class SfpUtil(SfpUtilBase): else: present_path = self.BASE_CPLD3_PATH.format(order) - present_path = present_path + "module_present_" + str(self._port_to_i2c_mapping[port_num][0]) + present_path = present_path + "module_present_" + str(port_num) self.__port_to_is_present = present_path try: @@ -190,8 +175,8 @@ class SfpUtil(SfpUtilBase): def qsfp_sb_remap(self, port_num): qsfp_start = self.qsfp_port_start - qsfp_index = self._port_to_i2c_mapping[port_num][0] - qsfp_start - qsfp_index = self.qsfp_sb_map[qsfp_index-1] + qsfp_index = port_num - qsfp_start + qsfp_index = self.qsfp_sb_map[qsfp_index] return qsfp_start+qsfp_index def get_low_power_mode_cpld(self, port_num): @@ -287,7 +272,7 @@ class SfpUtil(SfpUtilBase): mod_rst_path = mod_rst_path + str(q) try: - reg_file = open(mod_rst_path, 'r+') + reg_file = open(mod_rst_path, 'r+', buffering=0) except IOError as e: print "Error: unable to open file: %s" % str(e) return False @@ -300,12 +285,68 @@ class SfpUtil(SfpUtilBase): reg_file.write('1') reg_file.close() return True - - def get_transceiver_change_event(self): - """ - TODO: This function need to be implemented - when decide to support monitoring SFP(Xcvrd) - on this platform. - """ - raise NotImplementedError + + @property + def _get_presence_bitmap(self): + nodes = [] + order = self.update_i2c_order() + + present_path = self.BASE_CPLD2_PATH.format(order) + nodes.append(present_path + "module_present_all") + present_path = self.BASE_CPLD3_PATH.format(order) + nodes.append(present_path + "module_present_all") + + bitmap = "" + for node in nodes: + try: + reg_file = open(node) + + except IOError as e: + print "Error: unable to open file: %s" % str(e) + return False + bitmap += reg_file.readline().rstrip() + " " + reg_file.close() + + rev = bitmap.split(" ") + rev = "".join(rev[::-1]) + return int(rev,16) + + + data = {'valid':0, 'last':0, 'present':0} + def get_transceiver_change_event(self, timeout=2000): + now = time.time() + port_dict = {} + port = 0 + + if timeout < 1000: + timeout = 1000 + timeout = (timeout) / float(1000) # Convert to secs + + + if now < (self.data['last'] + timeout) and self.data['valid']: + return True, {} + + reg_value = self._get_presence_bitmap + changed_ports = self.data['present'] ^ reg_value + if changed_ports: + for port in range (self.port_start, self.port_end+1): + # Mask off the bit corresponding to our port + fp_port = self._port_to_i2c_mapping[port][0] + mask = (1 << (fp_port - 1)) + if changed_ports & mask: + + if (reg_value & mask) == 0: + port_dict[port] = SFP_STATUS_REMOVED + else: + port_dict[port] = SFP_STATUS_INSERTED + + # Update cache + self.data['present'] = reg_value + self.data['last'] = now + self.data['valid'] = 1 + + return True, port_dict + else: + return True, {} + return False, {} diff --git a/device/accton/x86_64-accton_as6712_32x-r0/Accton-AS6712-32X/port_config.ini b/device/accton/x86_64-accton_as6712_32x-r0/Accton-AS6712-32X/port_config.ini old mode 100644 new mode 100755 index fd2022dc2c..36067bddc1 --- a/device/accton/x86_64-accton_as6712_32x-r0/Accton-AS6712-32X/port_config.ini +++ b/device/accton/x86_64-accton_as6712_32x-r0/Accton-AS6712-32X/port_config.ini @@ -1,33 +1,33 @@ -# name lanes alias -Ethernet0 49,50,51,52 fortyGigE1 -Ethernet4 53,54,55,56 fortyGigE2 -Ethernet8 57,58,59,60 fortyGigE3 -Ethernet12 61,62,63,64 fortyGigE4 -Ethernet16 65,66,67,68 fortyGigE5 -Ethernet20 69,70,71,72 fortyGigE6 -Ethernet24 73,74,75,76 fortyGigE7 -Ethernet28 77,78,79,80 fortyGigE8 -Ethernet32 33,34,35,36 fortyGigE9 -Ethernet36 37,38,39,40 fortyGigE10 -Ethernet40 41,42,43,44 fortyGigE11 -Ethernet44 45,46,47,48 fortyGigE12 -Ethernet48 81,82,83,84 fortyGigE13 -Ethernet52 85,86,87,88 fortyGigE14 -Ethernet56 89,90,91,92 fortyGigE15 -Ethernet60 93,94,95,96 fortyGigE16 -Ethernet64 97,98,99,100 fortyGigE17 -Ethernet68 101,102,103,104 fortyGigE18 -Ethernet72 105,106,107,108 fortyGigE19 -Ethernet76 109,110,111,112 fortyGigE20 -Ethernet80 17,18,19,20 fortyGigE21 -Ethernet84 21,22,23,24 fortyGigE22 -Ethernet88 25,26,27,28 fortyGigE23 -Ethernet92 29,30,31,32 fortyGigE24 -Ethernet96 113,114,115,116 fortyGigE25 -Ethernet100 117,118,119,120 fortyGigE26 -Ethernet104 121,122,123,124 fortyGigE27 -Ethernet108 125,126,127,128 fortyGigE28 -Ethernet112 1,2,3,4 fortyGigE29 -Ethernet116 5,6,7,8 fortyGigE30 -Ethernet120 9,10,11,12 fortyGigE31 -Ethernet124 13,14,15,16 fortyGigE32 +# name lanes alias index speed +Ethernet0 49,50,51,52 fortyGigE1 1 40000 +Ethernet4 53,54,55,56 fortyGigE2 2 40000 +Ethernet8 57,58,59,60 fortyGigE3 3 40000 +Ethernet12 61,62,63,64 fortyGigE4 4 40000 +Ethernet16 65,66,67,68 fortyGigE5 5 40000 +Ethernet20 69,70,71,72 fortyGigE6 6 40000 +Ethernet24 73,74,75,76 fortyGigE7 7 40000 +Ethernet28 77,78,79,80 fortyGigE8 8 40000 +Ethernet32 33,34,35,36 fortyGigE9 9 40000 +Ethernet36 37,38,39,40 fortyGigE10 10 40000 +Ethernet40 41,42,43,44 fortyGigE11 11 40000 +Ethernet44 45,46,47,48 fortyGigE12 12 40000 +Ethernet48 81,82,83,84 fortyGigE13 13 40000 +Ethernet52 85,86,87,88 fortyGigE14 14 40000 +Ethernet56 89,90,91,92 fortyGigE15 15 40000 +Ethernet60 93,94,95,96 fortyGigE16 16 40000 +Ethernet64 97,98,99,100 fortyGigE17 17 40000 +Ethernet68 101,102,103,104 fortyGigE18 18 40000 +Ethernet72 105,106,107,108 fortyGigE19 19 40000 +Ethernet76 109,110,111,112 fortyGigE20 20 40000 +Ethernet80 17,18,19,20 fortyGigE21 21 40000 +Ethernet84 21,22,23,24 fortyGigE22 22 40000 +Ethernet88 25,26,27,28 fortyGigE23 23 40000 +Ethernet92 29,30,31,32 fortyGigE24 24 40000 +Ethernet96 113,114,115,116 fortyGigE25 25 40000 +Ethernet100 117,118,119,120 fortyGigE26 26 40000 +Ethernet104 121,122,123,124 fortyGigE27 27 40000 +Ethernet108 125,126,127,128 fortyGigE28 28 40000 +Ethernet112 1,2,3,4 fortyGigE29 29 40000 +Ethernet116 5,6,7,8 fortyGigE30 30 40000 +Ethernet120 9,10,11,12 fortyGigE31 31 40000 +Ethernet124 13,14,15,16 fortyGigE32 32 40000 diff --git a/device/accton/x86_64-accton_as6712_32x-r0/plugins/sfputil.py b/device/accton/x86_64-accton_as6712_32x-r0/plugins/sfputil.py index 3a1d085396..661ecc7224 100644 --- a/device/accton/x86_64-accton_as6712_32x-r0/plugins/sfputil.py +++ b/device/accton/x86_64-accton_as6712_32x-r0/plugins/sfputil.py @@ -12,14 +12,18 @@ try: except ImportError as e: raise ImportError("%s - required module not found" % str(e)) +#from xcvrd +SFP_STATUS_INSERTED = '1' +SFP_STATUS_REMOVED = '0' + class SfpUtil(SfpUtilBase): """Platform-specific SfpUtil class""" - PORT_START = 0 - PORT_END = 31 + PORT_START = 1 + PORT_END = 32 PORTS_IN_BLOCK = 32 - QSFP_PORT_START = 0 + QSFP_PORT_START = 1 QSFP_PORT_END = 32 I2C_DEV_PATH = "/sys/bus/i2c/devices/" @@ -32,78 +36,38 @@ class SfpUtil(SfpUtilBase): _port_to_eeprom_mapping = {} _port_to_i2c_mapping = { - 0: [1, 2], - 1: [2, 3], - 2: [3, 4], - 3: [4, 5], - 4: [5, 6], - 5: [6, 7], - 6: [7, 8], - 7: [8, 9], - 8: [9, 10], - 9: [10, 11], - 10: [11, 12], - 11: [12, 13], - 12: [13, 14], - 13: [14, 15], - 14: [15, 16], - 15: [16, 17], - 16: [17, 18], - 17: [18, 19], - 18: [19, 20], - 19: [20, 21], - 20: [21, 22], - 21: [22, 23], - 22: [23, 24], - 23: [24, 25], - 24: [25, 26], - 25: [26, 27], - 26: [27, 28], - 27: [28, 29], - 28: [29, 30], - 29: [30, 31], - 30: [31, 32], - 31: [32, 33], - 32: [33, 34], - 33: [34, 35], - 34: [35, 36], - 35: [36, 37], - 36: [37, 38], - 37: [38, 39], - 38: [39, 40], - 39: [40, 41], - 40: [41, 42], - 41: [42, 43], - 42: [43, 44], - 43: [44, 45], - 44: [45, 46], - 45: [46, 47], - 46: [47, 48], - 47: [48, 49], - 48: [49, 50],#QSFP49 - 49: [49, 50], - 50: [49, 50], - 51: [49, 50], - 52: [50, 52],#QSFP50 - 53: [50, 52], - 54: [50, 52], - 55: [50, 52], - 56: [51, 54],#QSFP51 - 57: [51, 54], - 58: [51, 54], - 59: [51, 54], - 60: [52, 51],#QSFP52 - 61: [52, 51], - 62: [52, 51], - 63: [52, 51], - 64: [53, 53], #QSFP53 - 65: [53, 53], - 66: [53, 53], - 67: [53, 53], - 68: [54, 55],#QSFP54 - 69: [54, 55], - 70: [54, 55], - 71: [54, 55], + 1: [1, 2], + 2: [2, 3], + 3: [3, 4], + 4: [4, 5], + 5: [5, 6], + 6: [6, 7], + 7: [7, 8], + 8: [8, 9], + 9: [9, 10], + 10: [10, 11], + 11: [11, 12], + 12: [12, 13], + 13: [13, 14], + 14: [14, 15], + 15: [15, 16], + 16: [16, 17], + 17: [17, 18], + 18: [18, 19], + 19: [19, 20], + 20: [20, 21], + 21: [21, 22], + 22: [22, 23], + 23: [23, 24], + 24: [24, 25], + 25: [25, 26], + 26: [26, 27], + 27: [27, 28], + 28: [28, 29], + 29: [29, 30], + 30: [30, 31], + 31: [31, 32], + 32: [32, 33], } @property @@ -133,15 +97,14 @@ class SfpUtil(SfpUtilBase): def __init__(self): eeprom_path = self.BASE_OOM_PATH + "eeprom" - for x in range(0, self.port_end+1): + for x in range(self.port_start, self.port_end+1): self.port_to_eeprom_mapping[x] = eeprom_path.format( self._port_to_i2c_mapping[x][1] ) - SfpUtilBase.__init__(self) def get_cpld_dev_path(self, port_num): - if port_num < 16: + if port_num <= 16: cpld_num = 0 else: cpld_num = 1 @@ -157,6 +120,7 @@ class SfpUtil(SfpUtilBase): if port_num < self.port_start or port_num > self.port_end: return False + cpld_path = self.get_cpld_dev_path(port_num) present_path = cpld_path + "/module_present_" present_path += str(self._port_to_i2c_mapping[port_num][0]) @@ -281,11 +245,67 @@ class SfpUtil(SfpUtilBase): return True - def get_transceiver_change_event(self): - """ - TODO: This function need to be implemented - when decide to support monitoring SFP(Xcvrd) - on this platform. - """ - raise NotImplementedError + @property + def get_transceiver_status(self): + nodes = [] + + cpld_path = self.get_cpld_dev_path(self.port_start) + nodes.append(cpld_path + "/module_present_all") + cpld_path = self.get_cpld_dev_path(self.port_end) + nodes.append(cpld_path + "/module_present_all") + + bitmap = "" + for node in nodes: + try: + reg_file = open(node) + + except IOError as e: + print "Error: unable to open file: %s" % str(e) + return False + bitmap += reg_file.readline().rstrip() + " " + reg_file.close() + + rev = bitmap.split(" ") + rev = "".join(rev[::-1]) + return int(rev,16) + + + data = {'valid':0, 'last':0, 'present':0} + def get_transceiver_change_event(self, timeout=2000): + now = time.time() + port_dict = {} + port = 0 + + if timeout < 1000: + timeout = 1000 + timeout = (timeout) / float(1000) # Convert to secs + + + if now < (self.data['last'] + timeout) and self.data['valid']: + return True, {} + + reg_value = self.get_transceiver_status + changed_ports = self.data['present'] ^ reg_value + if changed_ports: + for port in range (self.port_start, self.port_end+1): + # Mask off the bit corresponding to our port + fp_port = self._port_to_i2c_mapping[port][0] + mask = (1 << (fp_port - 1)) + if changed_ports & mask: + + if (reg_value & mask) == 0: + port_dict[port] = SFP_STATUS_REMOVED + else: + port_dict[port] = SFP_STATUS_INSERTED + + # Update cache + self.data['present'] = reg_value + self.data['last'] = now + self.data['valid'] = 1 + + return True, port_dict + else: + return True, {} + return False, {} + diff --git a/device/accton/x86_64-accton_as7312_54x-r0/Accton-AS7312-54X/port_config.ini b/device/accton/x86_64-accton_as7312_54x-r0/Accton-AS7312-54X/port_config.ini index 2c4d0c0237..93160688d7 100644 --- a/device/accton/x86_64-accton_as7312_54x-r0/Accton-AS7312-54X/port_config.ini +++ b/device/accton/x86_64-accton_as7312_54x-r0/Accton-AS7312-54X/port_config.ini @@ -1,55 +1,55 @@ -# name lanes alias index -Ethernet0 41 twentyfiveGigE1 0 -Ethernet1 42 twentyfiveGigE2 1 -Ethernet2 43 twentyfiveGigE3 2 -Ethernet3 44 twentyfiveGigE4 3 -Ethernet4 49 twentyfiveGigE5 4 -Ethernet5 50 twentyfiveGigE6 5 -Ethernet6 51 twentyfiveGigE7 6 -Ethernet7 52 twentyfiveGigE8 7 -Ethernet8 53 twentyfiveGigE9 8 -Ethernet9 54 twentyfiveGigE10 9 -Ethernet10 55 twentyfiveGigE11 10 -Ethernet11 56 twentyfiveGigE12 11 -Ethernet12 65 twentyfiveGigE13 12 -Ethernet13 66 twentyfiveGigE14 13 -Ethernet14 67 twentyfiveGigE15 14 -Ethernet15 68 twentyfiveGigE16 15 -Ethernet16 33 twentyfiveGigE17 16 -Ethernet17 34 twentyfiveGigE18 17 -Ethernet18 35 twentyfiveGigE19 18 -Ethernet19 36 twentyfiveGigE20 19 -Ethernet20 37 twentyfiveGigE21 20 -Ethernet21 38 twentyfiveGigE22 21 -Ethernet22 39 twentyfiveGigE23 22 -Ethernet23 40 twentyfiveGigE24 23 -Ethernet24 69 twentyfiveGigE25 24 -Ethernet25 70 twentyfiveGigE26 25 -Ethernet26 71 twentyfiveGigE27 26 -Ethernet27 72 twentyfiveGigE28 27 -Ethernet28 81 twentyfiveGigE29 28 -Ethernet29 82 twentyfiveGigE30 29 -Ethernet30 83 twentyfiveGigE31 30 -Ethernet31 84 twentyfiveGigE32 31 -Ethernet32 85 twentyfiveGigE33 32 -Ethernet33 86 twentyfiveGigE34 33 -Ethernet34 87 twentyfiveGigE35 34 -Ethernet35 88 twentyfiveGigE36 35 -Ethernet36 97 twentyfiveGigE37 36 -Ethernet37 98 twentyfiveGigE38 37 -Ethernet38 99 twentyfiveGigE39 38 -Ethernet39 100 twentyfiveGigE40 39 -Ethernet40 101 twentyfiveGigE41 40 -Ethernet41 102 twentyfiveGigE42 41 -Ethernet42 103 twentyfiveGigE43 42 -Ethernet43 104 twentyfiveGigE44 43 -Ethernet44 105 twentyfiveGigE45 44 -Ethernet45 106 twentyfiveGigE46 45 -Ethernet46 107 twentyfiveGigE47 46 -Ethernet47 108 twentyfiveGigE48 47 -Ethernet48 5,6,7,8 hundredGigE49 48 -Ethernet52 1,2,3,4 hundredGigE50 52 -Ethernet56 109,110,111,112 hundredGigE51 56 -Ethernet60 21,22,23,24 hundredGigE52 60 -Ethernet64 9,10,11,12 hundredGigE53 64 -Ethernet68 117,118,119,120 hundredGigE54 68 +# name lanes alias index speed +Ethernet0 41 twentyfiveGigE1 1 25000 +Ethernet1 42 twentyfiveGigE2 2 25000 +Ethernet2 43 twentyfiveGigE3 3 25000 +Ethernet3 44 twentyfiveGigE4 4 25000 +Ethernet4 49 twentyfiveGigE5 5 25000 +Ethernet5 50 twentyfiveGigE6 6 25000 +Ethernet6 51 twentyfiveGigE7 7 25000 +Ethernet7 52 twentyfiveGigE8 8 25000 +Ethernet8 53 twentyfiveGigE9 9 25000 +Ethernet9 54 twentyfiveGigE10 10 25000 +Ethernet10 55 twentyfiveGigE11 11 25000 +Ethernet11 56 twentyfiveGigE12 12 25000 +Ethernet12 65 twentyfiveGigE13 13 25000 +Ethernet13 66 twentyfiveGigE14 14 25000 +Ethernet14 67 twentyfiveGigE15 15 25000 +Ethernet15 68 twentyfiveGigE16 16 25000 +Ethernet16 33 twentyfiveGigE17 17 25000 +Ethernet17 34 twentyfiveGigE18 18 25000 +Ethernet18 35 twentyfiveGigE19 19 25000 +Ethernet19 36 twentyfiveGigE20 20 25000 +Ethernet20 37 twentyfiveGigE21 21 25000 +Ethernet21 38 twentyfiveGigE22 22 25000 +Ethernet22 39 twentyfiveGigE23 23 25000 +Ethernet23 40 twentyfiveGigE24 24 25000 +Ethernet24 69 twentyfiveGigE25 25 25000 +Ethernet25 70 twentyfiveGigE26 26 25000 +Ethernet26 71 twentyfiveGigE27 27 25000 +Ethernet27 72 twentyfiveGigE28 28 25000 +Ethernet28 81 twentyfiveGigE29 29 25000 +Ethernet29 82 twentyfiveGigE30 30 25000 +Ethernet30 83 twentyfiveGigE31 31 25000 +Ethernet31 84 twentyfiveGigE32 32 25000 +Ethernet32 85 twentyfiveGigE33 33 25000 +Ethernet33 86 twentyfiveGigE34 34 25000 +Ethernet34 87 twentyfiveGigE35 35 25000 +Ethernet35 88 twentyfiveGigE36 36 25000 +Ethernet36 97 twentyfiveGigE37 37 25000 +Ethernet37 98 twentyfiveGigE38 38 25000 +Ethernet38 99 twentyfiveGigE39 39 25000 +Ethernet39 100 twentyfiveGigE40 40 25000 +Ethernet40 101 twentyfiveGigE41 41 25000 +Ethernet41 102 twentyfiveGigE42 42 25000 +Ethernet42 103 twentyfiveGigE43 43 25000 +Ethernet43 104 twentyfiveGigE44 44 25000 +Ethernet44 105 twentyfiveGigE45 45 25000 +Ethernet45 106 twentyfiveGigE46 46 25000 +Ethernet46 107 twentyfiveGigE47 47 25000 +Ethernet47 108 twentyfiveGigE48 48 25000 +Ethernet48 5,6,7,8 hundredGigE49 49 100000 +Ethernet52 1,2,3,4 hundredGigE50 50 100000 +Ethernet56 109,110,111,112 hundredGigE51 51 100000 +Ethernet60 21,22,23,24 hundredGigE52 52 100000 +Ethernet64 9,10,11,12 hundredGigE53 53 100000 +Ethernet68 117,118,119,120 hundredGigE54 54 100000 diff --git a/device/accton/x86_64-accton_as7312_54x-r0/plugins/sfputil.py b/device/accton/x86_64-accton_as7312_54x-r0/plugins/sfputil.py index b15eee579c..a1785fde55 100644 --- a/device/accton/x86_64-accton_as7312_54x-r0/plugins/sfputil.py +++ b/device/accton/x86_64-accton_as7312_54x-r0/plugins/sfputil.py @@ -15,11 +15,11 @@ except ImportError as e: class SfpUtil(SfpUtilBase): """Platform-specific SfpUtil class""" - PORT_START = 0 - PORT_END = 71 - PORTS_IN_BLOCK = 72 - QSFP_PORT_START = 48 - QSFP_PORT_END = 72 + PORT_START = 1 + PORT_END = 54 + PORTS_IN_BLOCK = 54 + QSFP_PORT_START = 49 + QSFP_PORT_END = 54 BASE_VAL_PATH = "/sys/class/i2c-adapter/i2c-{0}/{1}-0050/" @@ -33,78 +33,60 @@ class SfpUtil(SfpUtilBase): 2: "6-0064", } _port_to_i2c_mapping = { - 0: 18, - 1: 19, - 2: 20, - 3: 21, - 4: 22, - 5: 23, - 6: 24, - 7: 25, - 8: 26, - 9: 27, - 10: 28, - 11: 29, - 12: 30, - 13: 31, - 14: 32, - 15: 33, - 16: 34, - 17: 35, - 18: 36, - 19: 37, - 20: 38, - 21: 39, - 22: 40, - 23: 41, - 24: 42, - 25: 43, - 26: 44, - 27: 45, - 28: 46, - 29: 47, - 30: 48, - 31: 49, - 32: 50, - 33: 51, - 34: 52, - 35: 53, - 36: 54, - 37: 55, - 38: 56, - 39: 57, - 40: 58, - 41: 59, - 42: 60, - 43: 61, - 44: 62, - 45: 63, - 46: 64, - 47: 65, - 48: 66, #QSFP49 - 49: 66, - 50: 66, - 51: 66, - 52: 67, #QSFP50 - 53: 67, - 54: 67, - 55: 67, - 56: 68, #QSFP51 - 57: 68, - 58: 68, - 59: 68, - 60: 69, #QSFP52 - 61: 69, - 62: 69, - 63: 69, - 64: 70, #QSFP53 - 65: 70, - 66: 70, - 67: 70, - 68: 71, #QSFP54 - 69: 71, - 70: 71, - 71: 71, + 1: 18, + 2: 19, + 3: 20, + 4: 21, + 5: 22, + 6: 23, + 7: 24, + 8: 25, + 9: 26, + 10: 27, + 11: 28, + 12: 29, + 13: 30, + 14: 31, + 15: 32, + 16: 33, + 17: 34, + 18: 35, + 19: 36, + 20: 37, + 21: 38, + 22: 39, + 23: 40, + 24: 41, + 25: 42, + 26: 43, + 27: 44, + 28: 45, + 29: 46, + 30: 47, + 31: 48, + 32: 49, + 33: 50, + 34: 51, + 35: 52, + 36: 53, + 37: 54, + 38: 55, + 39: 56, + 40: 57, + 41: 58, + 42: 59, + 43: 60, + 44: 61, + 45: 62, + 46: 63, + 47: 64, + 48: 65, + 49: 66, #QSFP49 + 50: 67, + 51: 68, + 52: 69, + 53: 70, + 54: 71, #QSFP54 } @property @@ -133,30 +115,18 @@ class SfpUtil(SfpUtilBase): def __init__(self): eeprom_path = '/sys/bus/i2c/devices/{0}-0050/eeprom' - for x in range(0, self.port_end+1): + for x in range(self.port_start, self.port_end+1): self.port_to_eeprom_mapping[x] = eeprom_path.format( self._port_to_i2c_mapping[x]) SfpUtilBase.__init__(self) - - # For port 48~51 are QSFP, here presumed they're all split to 4 lanes. - def get_cage_num(self, port_num): - cage_num = port_num - if (port_num >= self.QSFP_PORT_START): - cage_num = (port_num - self.QSFP_PORT_START)/4 - cage_num = cage_num + self.QSFP_PORT_START - - return cage_num - - # For cage 0~23 and 48~51 are at cpld2, others are at cpld3. def get_cpld_num(self, port_num): cpld_i = 1 - cage_num = self.get_cage_num(port_num) - if (port_num > 23 and port_num < self.QSFP_PORT_START): + if (port_num > 24 and port_num < self.qsfp_port_start): cpld_i = 2 - if (cage_num >= 52): + if (port_num > 52): cpld_i = 2 return cpld_i @@ -166,12 +136,11 @@ class SfpUtil(SfpUtilBase): if port_num < self.port_start or port_num > self.port_end: return False - cage_num = self.get_cage_num(port_num) cpld_i = self.get_cpld_num(port_num) cpld_ps = self._cpld_mapping[cpld_i] path = "/sys/bus/i2c/devices/{0}/module_present_{1}" - port_ps = path.format(cpld_ps, cage_num+1) + port_ps = path.format(cpld_ps, port_num) try: val_file = open(port_ps) @@ -250,11 +219,10 @@ class SfpUtil(SfpUtilBase): if port_num < self.qsfp_port_start or port_num > self.qsfp_port_end: return False - cage_num = self.get_cage_num(port_num) cpld_i = self.get_cpld_num(port_num) cpld_ps = self._cpld_mapping[cpld_i] path = "/sys/bus/i2c/devices/{0}/module_reset_{1}" - port_ps = path.format(cpld_ps, cage_num+1) + port_ps = path.format(cpld_ps, port_num) try: reg_file = open(port_ps, 'w') except IOError as e: diff --git a/device/accton/x86_64-accton_as7326_56x-r0/Accton-AS7326-56X/port_config.ini b/device/accton/x86_64-accton_as7326_56x-r0/Accton-AS7326-56X/port_config.ini index ab13811298..10c55c5aee 100755 --- a/device/accton/x86_64-accton_as7326_56x-r0/Accton-AS7326-56X/port_config.ini +++ b/device/accton/x86_64-accton_as7326_56x-r0/Accton-AS7326-56X/port_config.ini @@ -1,57 +1,57 @@ -# name lanes alias index -Ethernet0 3 twentyfiveGigE1 0 -Ethernet1 2 twentyfiveGigE2 1 -Ethernet2 4 twentyfiveGigE3 2 -Ethernet3 8 twentyfiveGigE4 3 -Ethernet4 7 twentyfiveGigE5 4 -Ethernet5 1 twentyfiveGigE6 5 -Ethernet6 5 twentyfiveGigE7 6 -Ethernet7 16 twentyfiveGigE8 7 -Ethernet8 6 twentyfiveGigE9 8 -Ethernet9 14 twentyfiveGigE10 9 -Ethernet10 13 twentyfiveGigE11 10 -Ethernet11 15 twentyfiveGigE12 11 -Ethernet12 23 twentyfiveGigE13 12 -Ethernet13 22 twentyfiveGigE14 13 -Ethernet14 24 twentyfiveGigE15 14 -Ethernet15 32 twentyfiveGigE16 15 -Ethernet16 31 twentyfiveGigE17 16 -Ethernet17 21 twentyfiveGigE18 17 -Ethernet18 29 twentyfiveGigE19 18 -Ethernet19 36 twentyfiveGigE20 19 -Ethernet20 30 twentyfiveGigE21 20 -Ethernet21 34 twentyfiveGigE22 21 -Ethernet22 33 twentyfiveGigE23 22 -Ethernet23 35 twentyfiveGigE24 23 -Ethernet24 43 twentyfiveGigE25 24 -Ethernet25 42 twentyfiveGigE26 25 -Ethernet26 44 twentyfiveGigE27 26 -Ethernet27 52 twentyfiveGigE28 27 -Ethernet28 51 twentyfiveGigE29 28 -Ethernet29 41 twentyfiveGigE30 29 -Ethernet30 49 twentyfiveGigE31 30 -Ethernet31 60 twentyfiveGigE32 31 -Ethernet32 50 twentyfiveGigE33 32 -Ethernet33 58 twentyfiveGigE34 33 -Ethernet34 57 twentyfiveGigE35 34 -Ethernet35 59 twentyfiveGigE36 35 -Ethernet36 62 twentyfiveGigE37 36 -Ethernet37 63 twentyfiveGigE38 37 -Ethernet38 64 twentyfiveGigE39 38 -Ethernet39 65 twentyfiveGigE40 39 -Ethernet40 66 twentyfiveGigE41 40 -Ethernet41 61 twentyfiveGigE42 41 -Ethernet42 68 twentyfiveGigE43 42 -Ethernet43 69 twentyfiveGigE44 43 -Ethernet44 67 twentyfiveGigE45 44 -Ethernet45 71 twentyfiveGigE46 45 -Ethernet46 72 twentyfiveGigE47 46 -Ethernet47 70 twentyfiveGigE48 47 -Ethernet48 77,78,79,80 hundredGigE49 48 -Ethernet52 85,86,87,88 hundredGigE50 52 -Ethernet56 93,94,95,96 hundredGigE51 56 -Ethernet60 97,98,99,100 hundredGigE52 60 -Ethernet64 105,106,107,108 hundredGigE53 64 -Ethernet68 113,114,115,116 hundredGigE54 68 -Ethernet72 121,122,123,124 hundredGigE55 72 -Ethernet76 125,126,127,128 hundredGigE56 76 +# name lanes alias index speed +Ethernet0 3 twentyfiveGigE1 1 25000 +Ethernet1 2 twentyfiveGigE2 2 25000 +Ethernet2 4 twentyfiveGigE3 3 25000 +Ethernet3 8 twentyfiveGigE4 4 25000 +Ethernet4 7 twentyfiveGigE5 5 25000 +Ethernet5 1 twentyfiveGigE6 6 25000 +Ethernet6 5 twentyfiveGigE7 7 25000 +Ethernet7 16 twentyfiveGigE8 8 25000 +Ethernet8 6 twentyfiveGigE9 9 25000 +Ethernet9 14 twentyfiveGigE10 10 25000 +Ethernet10 13 twentyfiveGigE11 11 25000 +Ethernet11 15 twentyfiveGigE12 12 25000 +Ethernet12 23 twentyfiveGigE13 13 25000 +Ethernet13 22 twentyfiveGigE14 14 25000 +Ethernet14 24 twentyfiveGigE15 15 25000 +Ethernet15 32 twentyfiveGigE16 16 25000 +Ethernet16 31 twentyfiveGigE17 17 25000 +Ethernet17 21 twentyfiveGigE18 18 25000 +Ethernet18 29 twentyfiveGigE19 19 25000 +Ethernet19 36 twentyfiveGigE20 20 25000 +Ethernet20 30 twentyfiveGigE21 21 25000 +Ethernet21 34 twentyfiveGigE22 22 25000 +Ethernet22 33 twentyfiveGigE23 23 25000 +Ethernet23 35 twentyfiveGigE24 24 25000 +Ethernet24 43 twentyfiveGigE25 25 25000 +Ethernet25 42 twentyfiveGigE26 26 25000 +Ethernet26 44 twentyfiveGigE27 27 25000 +Ethernet27 52 twentyfiveGigE28 28 25000 +Ethernet28 51 twentyfiveGigE29 29 25000 +Ethernet29 41 twentyfiveGigE30 30 25000 +Ethernet30 49 twentyfiveGigE31 31 25000 +Ethernet31 60 twentyfiveGigE32 32 25000 +Ethernet32 50 twentyfiveGigE33 33 25000 +Ethernet33 58 twentyfiveGigE34 34 25000 +Ethernet34 57 twentyfiveGigE35 35 25000 +Ethernet35 59 twentyfiveGigE36 36 25000 +Ethernet36 62 twentyfiveGigE37 37 25000 +Ethernet37 63 twentyfiveGigE38 38 25000 +Ethernet38 64 twentyfiveGigE39 39 25000 +Ethernet39 65 twentyfiveGigE40 40 25000 +Ethernet40 66 twentyfiveGigE41 41 25000 +Ethernet41 61 twentyfiveGigE42 42 25000 +Ethernet42 68 twentyfiveGigE43 43 25000 +Ethernet43 69 twentyfiveGigE44 44 25000 +Ethernet44 67 twentyfiveGigE45 45 25000 +Ethernet45 71 twentyfiveGigE46 46 25000 +Ethernet46 72 twentyfiveGigE47 47 25000 +Ethernet47 70 twentyfiveGigE48 48 25000 +Ethernet48 77,78,79,80 hundredGigE49 49 100000 +Ethernet52 85,86,87,88 hundredGigE50 50 100000 +Ethernet56 93,94,95,96 hundredGigE51 51 100000 +Ethernet60 97,98,99,100 hundredGigE52 52 100000 +Ethernet64 105,106,107,108 hundredGigE53 53 100000 +Ethernet68 113,114,115,116 hundredGigE54 54 100000 +Ethernet72 121,122,123,124 hundredGigE55 55 100000 +Ethernet76 125,126,127,128 hundredGigE56 56 100000 diff --git a/device/accton/x86_64-accton_as7326_56x-r0/plugins/sfputil.py b/device/accton/x86_64-accton_as7326_56x-r0/plugins/sfputil.py index eca0abc39e..330d30b879 100644 --- a/device/accton/x86_64-accton_as7326_56x-r0/plugins/sfputil.py +++ b/device/accton/x86_64-accton_as7326_56x-r0/plugins/sfputil.py @@ -11,15 +11,18 @@ try: except ImportError as e: raise ImportError("%s - required module not found" % str(e)) +#from xcvrd +SFP_STATUS_REMOVED = '0' +SFP_STATUS_INSERTED = '1' class SfpUtil(SfpUtilBase): """Platform-specific SfpUtil class""" - PORT_START = 0 - PORT_END = 81 - PORTS_IN_BLOCK = 82 - QSFP_PORT_START = 48 - QSFP_PORT_END = 82 + PORT_START = 1 + PORT_END = 56 + PORTS_IN_BLOCK = 56 + QSFP_PORT_START = 49 + QSFP_PORT_END = 56 BASE_VAL_PATH = "/sys/class/i2c-adapter/i2c-{0}/{1}-0050/" @@ -34,88 +37,63 @@ class SfpUtil(SfpUtilBase): } _port_to_i2c_mapping = { - 0: 42, - 1: 41, - 2: 44, - 3: 43, - 4: 47, - 5: 45, - 6: 46, - 7: 50, - 8: 48, - 9: 49, - 10: 51, - 11: 52, - 12: 53, - 13: 56, - 14: 55, - 15: 54, - 16: 58, - 17: 57, - 18: 59, - 19: 60, - 20: 61, - 21: 63, - 22: 62, - 23: 64, - 24: 66, - 25: 68, - 26: 65, - 27: 67, - 28: 69, - 29: 71, - 30: 72, - 31: 70, - 32: 74, - 33: 73, - 34: 76, - 35: 75, - 36: 77, - 37: 79, - 38: 78, - 39: 80, - 40: 81, - 41: 82, - 42: 84, - 43: 85, - 44: 83, - 45: 87, - 46: 88, - 47: 86, - 48: 25, #QSFP49 - 49: 25, - 50: 25, - 51: 25, - 52: 26, #QSFP50 - 53: 26, - 54: 26, - 55: 26, - 56: 27, #QSFP51 - 57: 26, - 58: 26, - 59: 26, - 60: 28, #QSFP52 - 61: 26, - 62: 26, - 63: 26, - 64: 29, #QSFP53 - 65: 26, - 66: 26, - 67: 26, - 68: 30, #QSFP54 - 69: 26, - 70: 26, - 71: 26, - 72: 31, #QSFP55 - 73: 26, - 74: 26, - 75: 26, - 76: 32, #QSFP56 - 77: 26, - 78: 26, - 79: 26, - 80: 22, - 81: 23} + 1: 42, + 2: 41, + 3: 44, + 4: 43, + 5: 47, + 6: 45, + 7: 46, + 8: 50, + 9: 48, + 10: 49, + 11: 51, + 12: 52, + 13: 53, + 14: 56, + 15: 55, + 16: 54, + 17: 58, + 18: 57, + 19: 59, + 20: 60, + 21: 61, + 22: 63, + 23: 62, + 24: 64, + 25: 66, + 26: 68, + 27: 65, + 28: 67, + 29: 69, + 30: 71, + 31: 72, + 32: 70, + 33: 74, + 34: 73, + 35: 76, + 36: 75, + 37: 77, + 38: 79, + 39: 78, + 40: 80, + 41: 81, + 42: 82, + 43: 84, + 44: 85, + 45: 83, + 46: 87, + 47: 88, + 48: 86, + 49: 25,#QSFP49 + 50: 26, + 51: 27, + 52: 28, + 53: 29, + 54: 30, + 55: 31, + 56: 32,#QSFP56 + } @property def port_start(self): @@ -132,7 +110,7 @@ class SfpUtil(SfpUtilBase): @property def qsfp_port_end(self): return self.QSFP_PORT_END - + @property def qsfp_ports(self): return range(self.QSFP_PORT_START, self.PORTS_IN_BLOCK + 1) @@ -143,27 +121,16 @@ class SfpUtil(SfpUtilBase): def __init__(self): eeprom_path = '/sys/bus/i2c/devices/{0}-0050/eeprom' - for x in range(0, self.port_end+1): + for x in range(self.port_start, self.port_end+1): self.port_to_eeprom_mapping[x] = eeprom_path.format( self._port_to_i2c_mapping[x]) SfpUtilBase.__init__(self) - - # For port 48~51 are QSFP, here presumed they're all split to 4 lanes. - def get_cage_num(self, port_num): - cage_num = port_num - if (port_num >= self.QSFP_PORT_START): - cage_num = (port_num - self.QSFP_PORT_START)/4 - cage_num = cage_num + self.QSFP_PORT_START - - return cage_num - - # For cage 0~23 and 48~51 are at cpld2, others are at cpld3. - def get_cpld_num(self, port_num): + # For port 0~23 and 48~51 are at cpld2, others are at cpld3. + def get_cpld_num(self, port_num): cpld_i = 1 - cage_num = self.get_cage_num(port_num) - if (port_num > 29): + if (port_num > 30): cpld_i = 2 return cpld_i @@ -172,18 +139,16 @@ class SfpUtil(SfpUtilBase): if port_num < self.port_start or port_num > self.port_end: return False - cage_num = self.get_cage_num(port_num) cpld_i = self.get_cpld_num(port_num) - #print "[ROY] cpld:%d" % cpld_i cpld_ps = self._cpld_mapping[cpld_i] path = "/sys/bus/i2c/devices/{0}/module_present_{1}" - port_ps = path.format(cpld_ps, cage_num+1) + port_ps = path.format(cpld_ps, port_num) try: val_file = open(port_ps) except IOError as e: - print "Error: unable to open file: %s" % str(e) + print "Error: unable to open file: %s" % str(e) return False content = val_file.readline().rstrip() @@ -224,7 +189,7 @@ class SfpUtil(SfpUtilBase): eeprom.close() time.sleep(0.01) - def set_low_power_mode(self, port_num, lpmode): + def set_low_power_mode(self, port_num, lpmode): # Check for invalid port_num if port_num < self.qsfp_port_start or port_num > self.qsfp_port_end: return False @@ -256,10 +221,66 @@ class SfpUtil(SfpUtilBase): def reset(self, port_num): raise NotImplementedError - def get_transceiver_change_event(self): - """ - TODO: This function need to be implemented - when decide to support monitoring SFP(Xcvrd) - on this platform. - """ - raise NotImplementedError + @property + def _get_present_bitmap(self): + nodes = [] + rev = [] + port_num = [30,26] + + path = "/sys/bus/i2c/devices/{0}/module_present_all" + cpld_i = self.get_cpld_num(self.port_start) + cpld_ps = self._cpld_mapping[cpld_i] + nodes.append((path.format(cpld_ps), port_num[0])) + cpld_i = self.get_cpld_num(self.port_end) + cpld_ps = self._cpld_mapping[cpld_i] + nodes.append((path.format(cpld_ps), port_num[1])) + + bitmaps = "" + for node in nodes: + try: + reg_file = open(node[0]) + except IOError as e: + print "Error: unable to open file: %s" % str(e) + return False + bitmap = reg_file.readline().rstrip() + bitmap = bin(int(bitmap, 16))[2:].zfill(node[1]) + rev.append(bitmap) + reg_file.close() + + bitmaps = "".join(rev[::-1]) + bitmaps = hex(int(bitmaps, 2)) + return int(bitmaps, 0) + + data = {'valid':0, 'last':0, 'present':0} + def get_transceiver_change_event(self, timeout=2000): + now = time.time() + port_dict = {} + port = 0 + + if timeout < 1000: + timeout = 1000 + timeout = (timeout) / float(1000) # Convert to secs + + if now < (self.data['last'] + timeout) and self.data['valid']: + return True, {} + + reg_value = self._get_present_bitmap + changed_ports = self.data['present'] ^ reg_value + if changed_ports: + for port in range (self.port_start, self.port_end+1): + # Mask off the bit corresponding to our port + mask = (1 << (port - 1)) + if changed_ports & mask: + if (reg_value & mask) == 0: + port_dict[port] = SFP_STATUS_REMOVED + else: + port_dict[port] = SFP_STATUS_INSERTED + + # Update cache + self.data['present'] = reg_value + self.data['last'] = now + self.data['valid'] = 1 + return True, port_dict + else: + return True, {} + return False, {} diff --git a/device/accton/x86_64-accton_as7712_32x-r0/Accton-AS7712-32X/port_config.ini b/device/accton/x86_64-accton_as7712_32x-r0/Accton-AS7712-32X/port_config.ini index 1fa6d21d96..e101ec29d4 100644 --- a/device/accton/x86_64-accton_as7712_32x-r0/Accton-AS7712-32X/port_config.ini +++ b/device/accton/x86_64-accton_as7712_32x-r0/Accton-AS7712-32X/port_config.ini @@ -1,33 +1,33 @@ -# name lanes alias -Ethernet0 49,50,51,52 hundredGigE1 -Ethernet4 53,54,55,56 hundredGigE2 -Ethernet8 57,58,59,60 hundredGigE3 -Ethernet12 61,62,63,64 hundredGigE4 -Ethernet16 65,66,67,68 hundredGigE5 -Ethernet20 69,70,71,72 hundredGigE6 -Ethernet24 73,74,75,76 hundredGigE7 -Ethernet28 77,78,79,80 hundredGigE8 -Ethernet32 33,34,35,36 hundredGigE9 -Ethernet36 37,38,39,40 hundredGigE10 -Ethernet40 41,42,43,44 hundredGigE11 -Ethernet44 45,46,47,48 hundredGigE12 -Ethernet48 81,82,83,84 hundredGigE13 -Ethernet52 85,86,87,88 hundredGigE14 -Ethernet56 89,90,91,92 hundredGigE15 -Ethernet60 93,94,95,96 hundredGigE16 -Ethernet64 97,98,99,100 hundredGigE17 -Ethernet68 101,102,103,104 hundredGigE18 -Ethernet72 105,106,107,108 hundredGigE19 -Ethernet76 109,110,111,112 hundredGigE20 -Ethernet80 17,18,19,20 hundredGigE21 -Ethernet84 21,22,23,24 hundredGigE22 -Ethernet88 25,26,27,28 hundredGigE23 -Ethernet92 29,30,31,32 hundredGigE24 -Ethernet96 113,114,115,116 hundredGigE25 -Ethernet100 117,118,119,120 hundredGigE26 -Ethernet104 121,122,123,124 hundredGigE27 -Ethernet108 125,126,127,128 hundredGigE28 -Ethernet112 1,2,3,4 hundredGigE29 -Ethernet116 5,6,7,8 hundredGigE30 -Ethernet120 9,10,11,12 hundredGigE31 -Ethernet124 13,14,15,16 hundredGigE32 +# name lanes alias index speed +Ethernet0 49,50,51,52 hundredGigE1 1 100000 +Ethernet4 53,54,55,56 hundredGigE2 2 100000 +Ethernet8 57,58,59,60 hundredGigE3 3 100000 +Ethernet12 61,62,63,64 hundredGigE4 4 100000 +Ethernet16 65,66,67,68 hundredGigE5 5 100000 +Ethernet20 69,70,71,72 hundredGigE6 6 100000 +Ethernet24 73,74,75,76 hundredGigE7 7 100000 +Ethernet28 77,78,79,80 hundredGigE8 8 100000 +Ethernet32 33,34,35,36 hundredGigE9 9 100000 +Ethernet36 37,38,39,40 hundredGigE10 10 100000 +Ethernet40 41,42,43,44 hundredGigE11 11 100000 +Ethernet44 45,46,47,48 hundredGigE12 12 100000 +Ethernet48 81,82,83,84 hundredGigE13 13 100000 +Ethernet52 85,86,87,88 hundredGigE14 14 100000 +Ethernet56 89,90,91,92 hundredGigE15 15 100000 +Ethernet60 93,94,95,96 hundredGigE16 16 100000 +Ethernet64 97,98,99,100 hundredGigE17 17 100000 +Ethernet68 101,102,103,104 hundredGigE18 18 100000 +Ethernet72 105,106,107,108 hundredGigE19 19 100000 +Ethernet76 109,110,111,112 hundredGigE20 20 100000 +Ethernet80 17,18,19,20 hundredGigE21 21 100000 +Ethernet84 21,22,23,24 hundredGigE22 22 100000 +Ethernet88 25,26,27,28 hundredGigE23 23 100000 +Ethernet92 29,30,31,32 hundredGigE24 24 100000 +Ethernet96 113,114,115,116 hundredGigE25 25 100000 +Ethernet100 117,118,119,120 hundredGigE26 26 100000 +Ethernet104 121,122,123,124 hundredGigE27 27 100000 +Ethernet108 125,126,127,128 hundredGigE28 28 100000 +Ethernet112 1,2,3,4 hundredGigE29 29 100000 +Ethernet116 5,6,7,8 hundredGigE30 30 100000 +Ethernet120 9,10,11,12 hundredGigE31 31 100000 +Ethernet124 13,14,15,16 hundredGigE32 32 100000 diff --git a/device/accton/x86_64-accton_as7712_32x-r0/plugins/sfputil.py b/device/accton/x86_64-accton_as7712_32x-r0/plugins/sfputil.py index f70916ca43..2b8d61ef42 100644 --- a/device/accton/x86_64-accton_as7712_32x-r0/plugins/sfputil.py +++ b/device/accton/x86_64-accton_as7712_32x-r0/plugins/sfputil.py @@ -8,12 +8,16 @@ try: except ImportError, e: raise ImportError (str(e) + "- required module not found") +#from xcvrd +SFP_STATUS_INSERTED = '1' +SFP_STATUS_REMOVED = '0' + class SfpUtil(SfpUtilBase): """Platform specific SfpUtill class""" - _port_start = 0 - _port_end = 31 + _port_start = 1 + _port_end = 32 ports_in_block = 32 _port_to_eeprom_mapping = {} @@ -56,8 +60,8 @@ class SfpUtil(SfpUtilBase): def __init__(self): eeprom_path = '/sys/bus/i2c/devices/{0}-0050/eeprom' - for x in range(0, self._port_end + 1): - port_eeprom_path = eeprom_path.format(self.port_to_i2c_mapping[x+1]) + for x in range(self.port_start, self.port_end + 1): + port_eeprom_path = eeprom_path.format(self.port_to_i2c_mapping[x]) self._port_to_eeprom_mapping[x] = port_eeprom_path SfpUtilBase.__init__(self) @@ -67,10 +71,10 @@ class SfpUtil(SfpUtilBase): return False path = "/sys/bus/i2c/devices/4-0060/module_reset_{0}" - port_ps = path.format(port_num+1) + port_ps = path.format(port_num) try: - reg_file = open(port_ps, 'w') + reg_file = open(port_ps, 'w', buffering=0) except IOError as e: print "Error: unable to open file: %s" % str(e) return False @@ -90,9 +94,8 @@ class SfpUtil(SfpUtilBase): return False path = "/sys/bus/i2c/devices/4-0060/module_present_{0}" - port_ps = path.format(port_num+1) + port_ps = path.format(port_num) - try: reg_file = open(port_ps) except IOError as e: @@ -115,20 +118,12 @@ class SfpUtil(SfpUtilBase): @property def qsfp_ports(self): - return range(0, self.ports_in_block + 1) + return range(self.port_start, self.ports_in_block + 1) @property def port_to_eeprom_mapping(self): return self._port_to_eeprom_mapping - def get_transceiver_change_event(self): - """ - TODO: This function need to be implemented - when decide to support monitoring SFP(Xcvrd) - on this platform. - """ - raise NotImplementedError - def get_low_power_mode(self, port_num): # Check for invalid port_num if port_num < self._port_start or port_num > self._port_end: @@ -185,4 +180,61 @@ class SfpUtil(SfpUtilBase): finally: if eeprom is not None: eeprom.close() - time.sleep(0.01) \ No newline at end of file + time.sleep(0.01) + + @property + def _get_all_presence(self): + nodes = [] + + cpld_path = "/sys/bus/i2c/devices/4-0060/" + nodes.append(cpld_path + "module_present_all") + + bitmap = "" + for node in nodes: + try: + reg_file = open(node) + + except IOError as e: + print "Error: unable to open file: %s" % str(e) + return False + bitmap += reg_file.readline().rstrip() + " " + reg_file.close() + + rev = bitmap.split(" ") + rev = "".join(rev[::-1]) + return int(rev,16) + + data = {'valid':0, 'last':0, 'present':0} + def get_transceiver_change_event(self, timeout=2000): + now = time.time() + port_dict = {} + port = 0 + + if timeout < 1000: + timeout = 1000 + timeout = (timeout) / float(1000) # Convert to secs + + if now < (self.data['last'] + timeout) and self.data['valid']: + return True, {} + + reg_value = self._get_all_presence + changed_ports = self.data['present'] ^ reg_value + if changed_ports: + for port in range (self.port_start, self.port_end+1): + # Mask off the bit corresponding to our port + mask = (1 << (port - 1)) + if changed_ports & mask: + if (reg_value & mask) == 0: + port_dict[port] = SFP_STATUS_INSERTED + else: + port_dict[port] = SFP_STATUS_REMOVED + + # Update cache + self.data['present'] = reg_value + self.data['last'] = now + self.data['valid'] = 1 + return True, port_dict + else: + return True, {} + return False, {} + diff --git a/device/accton/x86_64-accton_as7716_32x-r0/Accton-AS7716-32X/port_config.ini b/device/accton/x86_64-accton_as7716_32x-r0/Accton-AS7716-32X/port_config.ini index 1fa6d21d96..0151b70d71 100644 --- a/device/accton/x86_64-accton_as7716_32x-r0/Accton-AS7716-32X/port_config.ini +++ b/device/accton/x86_64-accton_as7716_32x-r0/Accton-AS7716-32X/port_config.ini @@ -1,33 +1,33 @@ -# name lanes alias -Ethernet0 49,50,51,52 hundredGigE1 -Ethernet4 53,54,55,56 hundredGigE2 -Ethernet8 57,58,59,60 hundredGigE3 -Ethernet12 61,62,63,64 hundredGigE4 -Ethernet16 65,66,67,68 hundredGigE5 -Ethernet20 69,70,71,72 hundredGigE6 -Ethernet24 73,74,75,76 hundredGigE7 -Ethernet28 77,78,79,80 hundredGigE8 -Ethernet32 33,34,35,36 hundredGigE9 -Ethernet36 37,38,39,40 hundredGigE10 -Ethernet40 41,42,43,44 hundredGigE11 -Ethernet44 45,46,47,48 hundredGigE12 -Ethernet48 81,82,83,84 hundredGigE13 -Ethernet52 85,86,87,88 hundredGigE14 -Ethernet56 89,90,91,92 hundredGigE15 -Ethernet60 93,94,95,96 hundredGigE16 -Ethernet64 97,98,99,100 hundredGigE17 -Ethernet68 101,102,103,104 hundredGigE18 -Ethernet72 105,106,107,108 hundredGigE19 -Ethernet76 109,110,111,112 hundredGigE20 -Ethernet80 17,18,19,20 hundredGigE21 -Ethernet84 21,22,23,24 hundredGigE22 -Ethernet88 25,26,27,28 hundredGigE23 -Ethernet92 29,30,31,32 hundredGigE24 -Ethernet96 113,114,115,116 hundredGigE25 -Ethernet100 117,118,119,120 hundredGigE26 -Ethernet104 121,122,123,124 hundredGigE27 -Ethernet108 125,126,127,128 hundredGigE28 -Ethernet112 1,2,3,4 hundredGigE29 -Ethernet116 5,6,7,8 hundredGigE30 -Ethernet120 9,10,11,12 hundredGigE31 -Ethernet124 13,14,15,16 hundredGigE32 +# name lanes alias index speed +Ethernet0 49,50,51,52 hundredGigE1 1 100000 +Ethernet4 53,54,55,56 hundredGigE2 2 100000 +Ethernet8 57,58,59,60 hundredGigE3 3 100000 +Ethernet12 61,62,63,64 hundredGigE4 4 100000 +Ethernet16 65,66,67,68 hundredGigE5 5 100000 +Ethernet20 69,70,71,72 hundredGigE6 6 100000 +Ethernet24 73,74,75,76 hundredGigE7 7 100000 +Ethernet28 77,78,79,80 hundredGigE8 8 100000 +Ethernet32 33,34,35,36 hundredGigE9 9 100000 +Ethernet36 37,38,39,40 hundredGigE10 10 100000 +Ethernet40 41,42,43,44 hundredGigE11 11 100000 +Ethernet44 45,46,47,48 hundredGigE12 12 100000 +Ethernet48 81,82,83,84 hundredGigE13 13 100000 +Ethernet52 85,86,87,88 hundredGigE14 14 100000 +Ethernet56 89,90,91,92 hundredGigE15 15 100000 +Ethernet60 93,94,95,96 hundredGigE16 16 100000 +Ethernet64 97,98,99,100 hundredGigE17 17 100000 +Ethernet68 101,102,103,104 hundredGigE18 18 100000 +Ethernet72 105,106,107,108 hundredGigE19 19 100000 +Ethernet76 109,110,111,112 hundredGigE20 20 100000 +Ethernet80 17,18,19,20 hundredGigE21 21 100000 +Ethernet84 21,22,23,24 hundredGigE22 22 100000 +Ethernet88 25,26,27,28 hundredGigE23 23 100000 +Ethernet92 29,30,31,32 hundredGigE24 24 100000 +Ethernet96 113,114,115,116 hundredGigE25 25 100000 +Ethernet100 117,118,119,120 hundredGigE26 26 100000 +Ethernet104 121,122,123,124 hundredGigE27 27 100000 +Ethernet108 125,126,127,128 hundredGigE28 28 100000 +Ethernet112 1,2,3,4 hundredGigE29 29 100000 +Ethernet116 5,6,7,8 hundredGigE30 30 100000 +Ethernet120 9,10,11,12 hundredGigE31 31 100000 +Ethernet124 13,14,15,16 hundredGigE32 32 100000 diff --git a/device/accton/x86_64-accton_as7716_32x-r0/plugins/sfputil.py b/device/accton/x86_64-accton_as7716_32x-r0/plugins/sfputil.py index 9c84f1b7e1..96637e85a0 100755 --- a/device/accton/x86_64-accton_as7716_32x-r0/plugins/sfputil.py +++ b/device/accton/x86_64-accton_as7716_32x-r0/plugins/sfputil.py @@ -10,13 +10,16 @@ try: from sonic_sfp.sfputilbase import SfpUtilBase except ImportError as e: raise ImportError("%s - required module not found" % str(e)) +#from xcvrd +SFP_STATUS_REMOVED = '0' +SFP_STATUS_INSERTED = '1' class SfpUtil(SfpUtilBase): """Platform-specific SfpUtil class""" - PORT_START = 0 - PORT_END = 31 + PORT_START = 1 + PORT_END = 32 PORTS_IN_BLOCK = 32 BASE_OOM_PATH = "/sys/bus/i2c/devices/{0}-0050/" @@ -27,38 +30,38 @@ class SfpUtil(SfpUtilBase): _port_to_eeprom_mapping = {} _port_to_i2c_mapping = { - 0: [1, 29], - 1: [2, 30], - 2: [3, 31], - 3: [4, 32], - 4: [5, 34], - 5: [6, 33], - 6: [7, 36], - 7: [8, 35], - 8: [9, 25], - 9: [10, 26], - 10: [11, 27], - 11: [12, 28], - 12: [14, 37], - 13: [15, 38], - 14: [16, 39], - 15: [17, 40], - 16: [18, 41], - 17: [19, 42], - 18: [20, 43], - 19: [21, 44], - 20: [22, 53], - 21: [23, 54], - 22: [24, 55], - 23: [25, 56], - 24: [26, 45], - 25: [27, 46], - 26: [28, 47], - 27: [29, 48], - 28: [30, 49], - 29: [31, 50], - 30: [32, 51], - 31: [33, 52], + 1: 29, + 2: 30, + 3: 31, + 4: 32, + 5: 34, + 6: 33, + 7: 36, + 8: 35, + 9: 25, + 10: 26, + 11: 27, + 12: 28, + 13: 37, + 14: 38, + 15: 39, + 16: 40, + 17: 41, + 18: 42, + 19: 43, + 20: 44, + 21: 53, + 22: 54, + 23: 55, + 24: 56, + 25: 45, + 26: 46, + 27: 47, + 28: 48, + 29: 49, + 30: 50, + 31: 51, + 32: 52, } @property @@ -80,11 +83,10 @@ class SfpUtil(SfpUtilBase): def __init__(self): eeprom_path = self.BASE_OOM_PATH + "eeprom" - for x in range(0, self.port_end+1): + for x in range(self.port_start, self.port_end+1): self.port_to_eeprom_mapping[x] = eeprom_path.format( - self._port_to_i2c_mapping[x][1] + self._port_to_i2c_mapping[x] ) - SfpUtilBase.__init__(self) def get_presence(self, port_num): @@ -92,7 +94,7 @@ class SfpUtil(SfpUtilBase): if port_num < self.port_start or port_num > self.port_end: return False - present_path = self.BASE_CPLD_PATH + "module_present_" + str(port_num+1) + present_path = self.BASE_CPLD_PATH + "module_present_" + str(port_num) self.__port_to_is_present = present_path try: @@ -172,7 +174,7 @@ class SfpUtil(SfpUtilBase): if port_num < self.port_start or port_num > self.port_end: return False - mod_rst_path = self.BASE_CPLD_PATH + "module_reset_" + str(port_num+1) + mod_rst_path = self.BASE_CPLD_PATH + "module_reset_" + str(port_num) self.__port_to_mod_rst = mod_rst_path try: reg_file = open(self.__port_to_mod_rst, 'r+') @@ -187,10 +189,57 @@ class SfpUtil(SfpUtilBase): return True - def get_transceiver_change_event(self): - """ - TODO: This function need to be implemented - when decide to support monitoring SFP(Xcvrd) - on this platform. - """ - raise NotImplementedError + @property + def _get_present_bitmap(self): + nodes = [] + + nodes.append(self.BASE_CPLD_PATH + "module_present_all") + bitmap = "" + for node in nodes: + try: + reg_file = open(node) + + except IOError as e: + print "Error: unable to open file: %s" % str(e) + return False + bitmap += reg_file.readline().rstrip() + " " + reg_file.close() + + rev = bitmap.split(" ") + rev = "".join(rev[::-1]) + return int(rev,16) + + data = {'valid':0, 'last':0, 'present':0} + def get_transceiver_change_event(self, timeout=2000): + now = time.time() + port_dict = {} + port = 0 + + if timeout < 1000: + timeout = 1000 + timeout = (timeout) / float(1000) # Convert to secs + + if now < (self.data['last'] + timeout) and self.data['valid']: + return True, {} + + reg_value = self._get_present_bitmap + changed_ports = self.data['present'] ^ reg_value + if changed_ports: + for port in range (self.port_start, self.port_end+1): + # Mask off the bit corresponding to our port + mask = (1 << (port - 1)) + if changed_ports & mask: + if (reg_value & mask) == 0: + port_dict[port] = SFP_STATUS_REMOVED + else: + port_dict[port] = SFP_STATUS_INSERTED + + # Update cache + self.data['present'] = reg_value + self.data['last'] = now + self.data['valid'] = 1 + return True, port_dict + else: + return True, {} + return False, {} + diff --git a/device/accton/x86_64-accton_as7726_32x-r0/Accton-AS7726-32X/port_config.ini b/device/accton/x86_64-accton_as7726_32x-r0/Accton-AS7726-32X/port_config.ini index e40b8c26c0..c12f3b3ba2 100755 --- a/device/accton/x86_64-accton_as7726_32x-r0/Accton-AS7726-32X/port_config.ini +++ b/device/accton/x86_64-accton_as7726_32x-r0/Accton-AS7726-32X/port_config.ini @@ -1,33 +1,33 @@ -# name lanes alias -Ethernet0 1,2,3,4 hundredGigE1 -Ethernet4 5,6,7,8 hundredGigE2 -Ethernet8 9,10,11,12 hundredGigE3 -Ethernet12 13,14,15,16 hundredGigE4 -Ethernet16 17,18,19,20 hundredGigE5 -Ethernet20 21,22,23,24 hundredGigE6 -Ethernet24 25,26,27,28 hundredGigE7 -Ethernet28 29,30,31,32 hundredGigE8 -Ethernet32 33,34,35,36 hundredGigE9 -Ethernet36 37,38,39,40 hundredGigE10 -Ethernet40 41,42,43,44 hundredGigE11 -Ethernet44 45,46,47,48 hundredGigE12 -Ethernet48 49,50,51,52 hundredGigE13 -Ethernet52 53,54,55,56 hundredGigE14 -Ethernet56 57,58,59,60 hundredGigE15 -Ethernet60 61,62,63,64 hundredGigE16 -Ethernet64 65,66,67,68 hundredGigE17 -Ethernet68 69,70,71,72 hundredGigE18 -Ethernet72 73,74,75,76 hundredGigE19 -Ethernet76 77,78,79,80 hundredGigE20 -Ethernet80 81,82,83,84 hundredGigE21 -Ethernet84 85,86,87,88 hundredGigE22 -Ethernet88 89,90,91,92 hundredGigE23 -Ethernet92 93,94,95,96 hundredGigE24 -Ethernet96 97,98,99,100 hundredGigE25 -Ethernet100 101,102,103,104 hundredGigE26 -Ethernet104 105,106,107,108 hundredGigE27 -Ethernet108 109,110,111,112 hundredGigE28 -Ethernet112 113,114,115,116 hundredGigE29 -Ethernet116 117,118,119,120 hundredGigE30 -Ethernet120 121,122,123,124 hundredGigE31 -Ethernet124 125,126,127,128 hundredGigE32 +# name lanes alias index speed +Ethernet0 1,2,3,4 hundredGigE1 1 100000 +Ethernet4 5,6,7,8 hundredGigE2 2 100000 +Ethernet8 9,10,11,12 hundredGigE3 3 100000 +Ethernet12 13,14,15,16 hundredGigE4 4 100000 +Ethernet16 17,18,19,20 hundredGigE5 5 100000 +Ethernet20 21,22,23,24 hundredGigE6 6 100000 +Ethernet24 25,26,27,28 hundredGigE7 7 100000 +Ethernet28 29,30,31,32 hundredGigE8 8 100000 +Ethernet32 33,34,35,36 hundredGigE9 9 100000 +Ethernet36 37,38,39,40 hundredGigE10 10 100000 +Ethernet40 41,42,43,44 hundredGigE11 11 100000 +Ethernet44 45,46,47,48 hundredGigE12 12 100000 +Ethernet48 49,50,51,52 hundredGigE13 13 100000 +Ethernet52 53,54,55,56 hundredGigE14 14 100000 +Ethernet56 57,58,59,60 hundredGigE15 15 100000 +Ethernet60 61,62,63,64 hundredGigE16 16 100000 +Ethernet64 65,66,67,68 hundredGigE17 17 100000 +Ethernet68 69,70,71,72 hundredGigE18 18 100000 +Ethernet72 73,74,75,76 hundredGigE19 19 100000 +Ethernet76 77,78,79,80 hundredGigE20 20 100000 +Ethernet80 81,82,83,84 hundredGigE21 21 100000 +Ethernet84 85,86,87,88 hundredGigE22 22 100000 +Ethernet88 89,90,91,92 hundredGigE23 23 100000 +Ethernet92 93,94,95,96 hundredGigE24 24 100000 +Ethernet96 97,98,99,100 hundredGigE25 25 100000 +Ethernet100 101,102,103,104 hundredGigE26 26 100000 +Ethernet104 105,106,107,108 hundredGigE27 27 100000 +Ethernet108 109,110,111,112 hundredGigE28 28 100000 +Ethernet112 113,114,115,116 hundredGigE29 29 100000 +Ethernet116 117,118,119,120 hundredGigE30 30 100000 +Ethernet120 121,122,123,124 hundredGigE31 31 100000 +Ethernet124 125,126,127,128 hundredGigE32 32 100000 diff --git a/device/accton/x86_64-accton_as7726_32x-r0/plugins/sfputil.py b/device/accton/x86_64-accton_as7726_32x-r0/plugins/sfputil.py index 5eb4d77ee4..04a0388daa 100755 --- a/device/accton/x86_64-accton_as7726_32x-r0/plugins/sfputil.py +++ b/device/accton/x86_64-accton_as7726_32x-r0/plugins/sfputil.py @@ -11,13 +11,17 @@ try: except ImportError as e: raise ImportError("%s - required module not found" % str(e)) +#from xcvrd +SFP_STATUS_INSERTED = '1' +SFP_STATUS_REMOVED = '0' + class SfpUtil(SfpUtilBase): """Platform-specific SfpUtil class""" - PORT_START = 0 - PORT_END = 33 - PORTS_IN_BLOCK = 34 + PORT_START = 1 + PORT_END = 32 #34 cages actually, but last 2 are not at port_config.ini. + PORTS_IN_BLOCK = 32 BASE_OOM_PATH = "/sys/bus/i2c/devices/{0}-0050/" BASE_CPLD_PATH = "/sys/bus/i2c/devices/11-0060/" @@ -27,40 +31,40 @@ class SfpUtil(SfpUtilBase): _port_to_eeprom_mapping = {} _port_to_i2c_mapping = { - 0: [1, 21], - 1: [2, 22], - 2: [3, 23], - 3: [4, 24], - 4: [5, 26], - 5: [6, 25], - 6: [7, 28], - 7: [8, 27], - 8: [9, 17], - 9: [10, 18], - 10: [11, 19], - 11: [12, 20], - 12: [13, 29], - 13: [14, 30], - 14: [15, 31], - 15: [16, 32], - 16: [17, 33], - 17: [18, 34], - 18: [19, 35], - 19: [20, 36], - 20: [21, 45], - 21: [22, 46], - 22: [23, 47], - 23: [24, 48], - 24: [25, 37], - 25: [26, 38], - 26: [27, 39], - 27: [28, 40], - 28: [29, 41], - 29: [30, 42], - 30: [31, 43], - 31: [32, 44], - 32: [33, 15], - 33: [34, 16], + 1: 21, + 2: 22, + 3: 23, + 4: 24, + 5: 26, + 6: 25, + 7: 28, + 8: 27, + 9: 17, + 10: 18, + 11: 19, + 12: 20, + 13: 29, + 14: 30, + 15: 31, + 16: 32, + 17: 33, + 18: 34, + 19: 35, + 20: 36, + 21: 45, + 22: 46, + 23: 47, + 24: 48, + 25: 37, + 26: 38, + 27: 39, + 28: 40, + 29: 41, + 30: 42, + 31: 43, + 32: 44, + 33: 15, + 34: 16, } @property @@ -82,19 +86,18 @@ class SfpUtil(SfpUtilBase): def __init__(self): eeprom_path = self.BASE_OOM_PATH + "eeprom" - for x in range(0, self.port_end+1): + for x in range(self.port_start, self.port_end+1): self.port_to_eeprom_mapping[x] = eeprom_path.format( - self._port_to_i2c_mapping[x][1] + self._port_to_i2c_mapping[x] ) - SfpUtilBase.__init__(self) def get_presence(self, port_num): # Check for invalid port_num - if port_num < self.port_start or port_num > self.port_end: + if not port_num in range(self.port_start, self.port_end+1): return False - - present_path = self.BASE_CPLD_PATH + "module_present_" + str(port_num+1) + + present_path = self.BASE_CPLD_PATH + "module_present_" + str(port_num) self.__port_to_is_present = present_path try: @@ -174,26 +177,81 @@ class SfpUtil(SfpUtilBase): if port_num < self.port_start or port_num > self.port_end: return False - mod_rst_path = self.BASE_CPLD_PATH + "module_reset_" + str(port_num+1) + mod_rst_path = self.BASE_CPLD_PATH + "module_reset_" + str(port_num) self.__port_to_mod_rst = mod_rst_path try: - reg_file = open(self.__port_to_mod_rst, 'r+') + reg_file = open(self.__port_to_mod_rst, 'r+', buffering=0) except IOError as e: print "Error: unable to open file: %s" % str(e) return False - reg_value = '1' - - reg_file.write(reg_value) + #toggle reset + reg_file.seek(0) + reg_file.write('1') + time.sleep(1) + reg_file.seek(0) + reg_file.write('0') reg_file.close() return True - def get_transceiver_change_event(self): - """ - TODO: This function need to be implemented - when decide to support monitoring SFP(Xcvrd) - on this platform. - """ - raise NotImplementedError + @property + def get_transceiver_status(self): + nodes = [] + + cpld_path = self.BASE_CPLD_PATH + nodes.append(cpld_path + "module_present_all") + + bitmap = "" + for node in nodes: + try: + reg_file = open(node) + + except IOError as e: + print "Error: unable to open file: %s" % str(e) + return False + bitmap += reg_file.readline().rstrip() + " " + reg_file.close() + + rev = bitmap.split(" ") + rev = "".join(rev[::-1]) + return int(rev,16) + + data = {'valid':0, 'last':0, 'present':0} + def get_transceiver_change_event(self, timeout=2000): + now = time.time() + port_dict = {} + port = 0 + + if timeout < 1000: + timeout = 1000 + timeout = (timeout) / float(1000) # Convert to secs + + + if now < (self.data['last'] + timeout) and self.data['valid']: + return True, {} + + reg_value = self.get_transceiver_status + changed_ports = self.data['present'] ^ reg_value + if changed_ports: + for port in range (self.port_start, self.port_end+1): + # Mask off the bit corresponding to our port + fp_port = port + mask = (1 << (fp_port - 1)) + if changed_ports & mask: + if (reg_value & mask) == 0: + port_dict[port] = SFP_STATUS_REMOVED + else: + port_dict[port] = SFP_STATUS_INSERTED + + # Update cache + self.data['present'] = reg_value + self.data['last'] = now + self.data['valid'] = 1 + + return True, port_dict + else: + return True, {} + return False, {} + diff --git a/device/accton/x86_64-accton_as7816_64x-r0/Accton-AS7816-64X/port_config.ini b/device/accton/x86_64-accton_as7816_64x-r0/Accton-AS7816-64X/port_config.ini index 20d1b84edc..8ebbd52c55 100644 --- a/device/accton/x86_64-accton_as7816_64x-r0/Accton-AS7816-64X/port_config.ini +++ b/device/accton/x86_64-accton_as7816_64x-r0/Accton-AS7816-64X/port_config.ini @@ -1,65 +1,65 @@ -# name lanes alias -Ethernet0 73,74,75,76 hundredGigE1 -Ethernet4 65,66,67,68 hundredGigE2 -Ethernet8 81,82,83,84 hundredGigE3 -Ethernet12 89,90,91,92 hundredGigE4 -Ethernet16 105,106,107,108 hundredGigE5 -Ethernet20 97,98,99,100 hundredGigE6 -Ethernet24 113,114,115,116 hundredGigE7 -Ethernet28 121,122,123,124 hundredGigE8 -Ethernet32 41,42,43,44 hundredGigE9 -Ethernet36 33,34,35,36 hundredGigE10 -Ethernet40 49,50,51,52 hundredGigE11 -Ethernet44 57,58,59,60 hundredGigE12 -Ethernet48 137,138,139,140 hundredGigE13 -Ethernet52 129,130,131,132 hundredGigE14 -Ethernet56 145,146,147,148 hundredGigE15 -Ethernet60 153,154,155,156 hundredGigE16 -Ethernet64 173,174,175,176 hundredGigE17 -Ethernet68 165,166,167,168 hundredGigE18 -Ethernet72 181,182,183,184 hundredGigE19 -Ethernet76 189,190,191,192 hundredGigE20 -Ethernet80 13,14,15,16 hundredGigE21 -Ethernet84 5,6,7,8 hundredGigE22 -Ethernet88 29,30,31,32 hundredGigE23 -Ethernet92 21,22,23,24 hundredGigE24 -Ethernet96 205,206,207,208 hundredGigE25 -Ethernet100 197,198,199,200 hundredGigE26 -Ethernet104 213,214,215,216 hundredGigE27 -Ethernet108 221,222,223,224 hundredGigE28 -Ethernet112 229,230,231,232 hundredGigE29 -Ethernet116 237,238,239,240 hundredGigE30 -Ethernet120 245,246,247,248 hundredGigE31 -Ethernet124 253,254,255,256 hundredGigE32 -Ethernet128 69,70,71,72 hundredGigE33 -Ethernet132 77,78,79,80 hundredGigE34 -Ethernet136 93,94,95,96 hundredGigE35 -Ethernet140 85,86,87,88 hundredGigE36 -Ethernet144 101,102,103,104 hundredGigE37 -Ethernet148 109,110,111,112 hundredGigE38 -Ethernet152 125,126,127,128 hundredGigE39 -Ethernet156 117,118,119,120 hundredGigE40 -Ethernet160 37,38,39,40 hundredGigE41 -Ethernet164 45,46,47,48 hundredGigE42 -Ethernet168 61,62,63,64 hundredGigE43 -Ethernet172 53,54,55,56 hundredGigE44 -Ethernet176 133,134,135,136 hundredGigE45 -Ethernet180 141,142,143,144 hundredGigE46 -Ethernet184 157,158,159,160 hundredGigE47 -Ethernet188 149,150,151,152 hundredGigE48 -Ethernet192 161,162,163,164 hundredGigE49 -Ethernet196 169,170,171,172 hundredGigE50 -Ethernet200 185,186,187,188 hundredGigE51 -Ethernet204 177,178,179,180 hundredGigE52 -Ethernet208 1,2,3,4 hundredGigE53 -Ethernet212 9,10,11,12 hundredGigE54 -Ethernet216 25,26,27,28 hundredGigE55 -Ethernet220 17,18,19,20 hundredGigE56 -Ethernet224 193,194,195,196 hundredGigE57 -Ethernet228 201,202,203,204 hundredGigE58 -Ethernet232 217,218,219,220 hundredGigE59 -Ethernet236 209,210,211,212 hundredGigE60 -Ethernet240 225,226,227,228 hundredGigE61 -Ethernet244 233,234,235,236 hundredGigE62 -Ethernet248 249,250,251,252 hundredGigE63 -Ethernet252 241,242,243,244 hundredGigE64 +# name lanes alias index speed +Ethernet0 73,74,75,76 hundredGigE1 1 100000 +Ethernet4 65,66,67,68 hundredGigE2 2 100000 +Ethernet8 81,82,83,84 hundredGigE3 3 100000 +Ethernet12 89,90,91,92 hundredGigE4 4 100000 +Ethernet16 105,106,107,108 hundredGigE5 5 100000 +Ethernet20 97,98,99,100 hundredGigE6 6 100000 +Ethernet24 113,114,115,116 hundredGigE7 7 100000 +Ethernet28 121,122,123,124 hundredGigE8 8 100000 +Ethernet32 41,42,43,44 hundredGigE9 9 100000 +Ethernet36 33,34,35,36 hundredGigE10 10 100000 +Ethernet40 49,50,51,52 hundredGigE11 11 100000 +Ethernet44 57,58,59,60 hundredGigE12 12 100000 +Ethernet48 137,138,139,140 hundredGigE13 13 100000 +Ethernet52 129,130,131,132 hundredGigE14 14 100000 +Ethernet56 145,146,147,148 hundredGigE15 15 100000 +Ethernet60 153,154,155,156 hundredGigE16 16 100000 +Ethernet64 173,174,175,176 hundredGigE17 17 100000 +Ethernet68 165,166,167,168 hundredGigE18 18 100000 +Ethernet72 181,182,183,184 hundredGigE19 19 100000 +Ethernet76 189,190,191,192 hundredGigE20 20 100000 +Ethernet80 13,14,15,16 hundredGigE21 21 100000 +Ethernet84 5,6,7,8 hundredGigE22 22 100000 +Ethernet88 29,30,31,32 hundredGigE23 23 100000 +Ethernet92 21,22,23,24 hundredGigE24 24 100000 +Ethernet96 205,206,207,208 hundredGigE25 25 100000 +Ethernet100 197,198,199,200 hundredGigE26 26 100000 +Ethernet104 213,214,215,216 hundredGigE27 27 100000 +Ethernet108 221,222,223,224 hundredGigE28 28 100000 +Ethernet112 229,230,231,232 hundredGigE29 29 100000 +Ethernet116 237,238,239,240 hundredGigE30 30 100000 +Ethernet120 245,246,247,248 hundredGigE31 31 100000 +Ethernet124 253,254,255,256 hundredGigE32 32 100000 +Ethernet128 69,70,71,72 hundredGigE33 33 100000 +Ethernet132 77,78,79,80 hundredGigE34 34 100000 +Ethernet136 93,94,95,96 hundredGigE35 35 100000 +Ethernet140 85,86,87,88 hundredGigE36 36 100000 +Ethernet144 101,102,103,104 hundredGigE37 37 100000 +Ethernet148 109,110,111,112 hundredGigE38 38 100000 +Ethernet152 125,126,127,128 hundredGigE39 39 100000 +Ethernet156 117,118,119,120 hundredGigE40 40 100000 +Ethernet160 37,38,39,40 hundredGigE41 41 100000 +Ethernet164 45,46,47,48 hundredGigE42 42 100000 +Ethernet168 61,62,63,64 hundredGigE43 43 100000 +Ethernet172 53,54,55,56 hundredGigE44 44 100000 +Ethernet176 133,134,135,136 hundredGigE45 45 100000 +Ethernet180 141,142,143,144 hundredGigE46 46 100000 +Ethernet184 157,158,159,160 hundredGigE47 47 100000 +Ethernet188 149,150,151,152 hundredGigE48 48 100000 +Ethernet192 161,162,163,164 hundredGigE49 49 100000 +Ethernet196 169,170,171,172 hundredGigE50 50 100000 +Ethernet200 185,186,187,188 hundredGigE51 51 100000 +Ethernet204 177,178,179,180 hundredGigE52 52 100000 +Ethernet208 1,2,3,4 hundredGigE53 53 100000 +Ethernet212 9,10,11,12 hundredGigE54 54 100000 +Ethernet216 25,26,27,28 hundredGigE55 55 100000 +Ethernet220 17,18,19,20 hundredGigE56 56 100000 +Ethernet224 193,194,195,196 hundredGigE57 57 100000 +Ethernet228 201,202,203,204 hundredGigE58 58 100000 +Ethernet232 217,218,219,220 hundredGigE59 59 100000 +Ethernet236 209,210,211,212 hundredGigE60 60 100000 +Ethernet240 225,226,227,228 hundredGigE61 61 100000 +Ethernet244 233,234,235,236 hundredGigE62 62 100000 +Ethernet248 249,250,251,252 hundredGigE63 63 100000 +Ethernet252 241,242,243,244 hundredGigE64 64 100000 diff --git a/device/accton/x86_64-accton_as7816_64x-r0/plugins/sfputil.py b/device/accton/x86_64-accton_as7816_64x-r0/plugins/sfputil.py index b699347938..b5e76ec838 100644 --- a/device/accton/x86_64-accton_as7816_64x-r0/plugins/sfputil.py +++ b/device/accton/x86_64-accton_as7816_64x-r0/plugins/sfputil.py @@ -8,12 +8,15 @@ try: except ImportError, e: raise ImportError (str(e) + "- required module not found") +#from xcvrd +SFP_STATUS_INSERTED = '1' +SFP_STATUS_REMOVED = '0' class SfpUtil(SfpUtilBase): """Platform specific SfpUtill class""" - _port_start = 0 - _port_end = 63 + _port_start = 1 + _port_end = 64 ports_in_block = 64 _port_to_eeprom_mapping = {} @@ -86,18 +89,18 @@ class SfpUtil(SfpUtilBase): _qsfp_ports = range(0, ports_in_block + 1) def __init__(self): - eeprom_path = '/sys/bus/i2c/devices/{0}-0050/sfp_eeprom' - for x in range(0, self._port_end + 1): - port_eeprom_path = eeprom_path.format(self.port_to_i2c_mapping[x+1]) + eeprom_path = '/sys/bus/i2c/devices/{0}-0050/eeprom' + for x in range(self.port_start, self.port_end + 1): + port_eeprom_path = eeprom_path.format(self.port_to_i2c_mapping[x]) self._port_to_eeprom_mapping[x] = port_eeprom_path SfpUtilBase.__init__(self) def reset(self, port_num): # Check for invalid port_num - if port_num < self._port_start or port_num > self._port_end: + if port_num < self.port_start or port_num > self.port_end: return False path = "/sys/bus/i2c/devices/19-0060/module_reset_{0}" - port_ps = path.format(port_num+1) + port_ps = path.format(port_num) try: reg_file = open(port_ps, 'w') @@ -113,12 +116,11 @@ class SfpUtil(SfpUtilBase): def get_presence(self, port_num): # Check for invalid port_num - if port_num < self._port_start or port_num > self._port_end: + if port_num < self.port_start or port_num > self.port_end: return False - path = "/sys/bus/i2c/devices/{0}-0050/sfp_is_present" - port_ps = path.format(self.port_to_i2c_mapping[port_num+1]) - + path = "/sys/bus/i2c/devices/19-0060/module_present_{0}" + port_ps = path.format(port_num) try: reg_file = open(port_ps) @@ -148,14 +150,6 @@ class SfpUtil(SfpUtilBase): def port_to_eeprom_mapping(self): return self._port_to_eeprom_mapping - def get_transceiver_change_event(self): - """ - TODO: This function need to be implemented - when decide to support monitoring SFP(Xcvrd) - on this platform. - """ - raise NotImplementedError - def get_low_power_mode(self, port_num): # Check for invalid port_num if port_num < self._port_start or port_num > self._port_end: @@ -213,3 +207,62 @@ class SfpUtil(SfpUtilBase): if eeprom is not None: eeprom.close() time.sleep(0.01) + + @property + def _get_present_bitmap(self): + nodes = [] + + cpld_path = "/sys/bus/i2c/devices/19-0060/" + nodes.append(cpld_path + "module_present_all") + + bitmap = "" + for node in nodes: + try: + reg_file = open(node) + + except IOError as e: + print "Error: unable to open file: %s" % str(e) + return False + bitmap += reg_file.readline().rstrip() + " " + reg_file.close() + + rev = bitmap.split(" ") + rev = "".join(rev[::-1]) + return int(rev,16) + + + data = {'valid':0, 'last':0, 'present':0} + def get_transceiver_change_event(self, timeout=2000): + now = time.time() + port_dict = {} + port = 0 + + if timeout < 1000: + timeout = 1000 + timeout = (timeout) / float(1000) # Convert to secs + + if now < (self.data['last'] + timeout) and self.data['valid']: + return True, {} + + reg_value = self._get_present_bitmap + reg_value = ~reg_value + changed_ports = self.data['present'] ^ reg_value + if changed_ports: + for port in range (self.port_start, self.port_end+1): + # Mask off the bit corresponding to our port + mask = (1 << (port - 1)) + if changed_ports & mask: + if (reg_value & mask) == 0: + port_dict[port] = SFP_STATUS_REMOVED + else: + port_dict[port] = SFP_STATUS_INSERTED + + # Update cache + self.data['present'] = reg_value + self.data['last'] = now + self.data['valid'] = 1 + return True, port_dict + else: + return True, {} + return False, {} + diff --git a/platform/broadcom/sonic-platform-modules-accton/as5812-54x/classes/fanutil.py b/platform/broadcom/sonic-platform-modules-accton/as5812-54x/classes/fanutil.py index efb21b9a45..95a4558622 100755 --- a/platform/broadcom/sonic-platform-modules-accton/as5812-54x/classes/fanutil.py +++ b/platform/broadcom/sonic-platform-modules-accton/as5812-54x/classes/fanutil.py @@ -96,58 +96,71 @@ class FanUtil(object): (FAN_NUM_5_IDX, FANR_NODE_SPEED_IDX_OF_MAP): 'fanr5_speed_rpm', } + logger = logging.getLogger(__name__) + def __init__(self, log_level=logging.DEBUG): + ch = logging.StreamHandler() + ch.setLevel(log_level) + self.logger.addHandler(ch) + + fan_path = self.BASE_VAL_PATH + for fan_num in range(self.FAN_NUM_1_IDX, self.FAN_NUM_ON_MAIN_BROAD+1): + for node_num in range(self.FAN_NODE_FAULT_IDX_OF_MAP, self.FAN_NODE_NUM_OF_MAP+1): + self._fan_to_device_path_mapping[(fan_num, node_num)] = fan_path.format( + self._fan_to_device_node_mapping[(fan_num, node_num)]) + + def _get_fan_to_device_node(self, fan_num, node_num): return self._fan_to_device_node_mapping[(fan_num, node_num)] def _get_fan_node_val(self, fan_num, node_num): if fan_num < self.FAN_NUM_1_IDX or fan_num > self.FAN_NUM_ON_MAIN_BROAD: - logging.debug('GET. Parameter error. fan_num:%d', fan_num) + self.logger.debug('GET. Parameter error. fan_num:%d', fan_num) return None if node_num < self.FAN_NODE_FAULT_IDX_OF_MAP or node_num > self.FAN_NODE_NUM_OF_MAP: - logging.debug('GET. Parameter error. node_num:%d', node_num) + self.logger.debug('GET. Parameter error. node_num:%d', node_num) return None device_path = self.get_fan_to_device_path(fan_num, node_num) try: val_file = open(device_path, 'r') except IOError as e: - logging.error('GET. unable to open file: %s', str(e)) + self.logger.error('GET. unable to open file: %s', str(e)) return None content = val_file.readline().rstrip() if content == '': - logging.debug('GET. content is NULL. device_path:%s', device_path) + self.logger.debug('GET. content is NULL. device_path:%s', device_path) return None try: val_file.close() except: - logging.debug('GET. unable to close file. device_path:%s', device_path) + self.logger.debug('GET. unable to close file. device_path:%s', device_path) return None return int(content) def _set_fan_node_val(self, fan_num, node_num, val): if fan_num < self.FAN_NUM_1_IDX or fan_num > self.FAN_NUM_ON_MAIN_BROAD: - logging.debug('GET. Parameter error. fan_num:%d', fan_num) + self.logger.debug('GET. Parameter error. fan_num:%d', fan_num) return None if node_num < self.FAN_NODE_FAULT_IDX_OF_MAP or node_num > self.FAN_NODE_NUM_OF_MAP: - logging.debug('GET. Parameter error. node_num:%d', node_num) + self.logger.debug('GET. Parameter error. node_num:%d', node_num) return None content = str(val) if content == '': - logging.debug('GET. content is NULL. device_path:%s', device_path) + self.logger.debug('GET. content is NULL. device_path:%s', device_path) return None device_path = self.get_fan_to_device_path(fan_num, node_num) try: val_file = open(device_path, 'w') except IOError as e: - logging.error('GET. unable to open file: %s', str(e)) + self.logger.error('GET. unable to open file: %s', str(e)) return None val_file.write(content) @@ -155,19 +168,11 @@ class FanUtil(object): try: val_file.close() except: - logging.debug('GET. unable to close file. device_path:%s', device_path) + self.logger.debug('GET. unable to close file. device_path:%s', device_path) return None return True - def __init__(self): - fan_path = self.BASE_VAL_PATH - - for fan_num in range(self.FAN_NUM_1_IDX, self.FAN_NUM_ON_MAIN_BROAD+1): - for node_num in range(self.FAN_NODE_FAULT_IDX_OF_MAP, self.FAN_NODE_NUM_OF_MAP+1): - self._fan_to_device_path_mapping[(fan_num, node_num)] = fan_path.format( - self._fan_to_device_node_mapping[(fan_num, node_num)]) - def get_num_fans(self): return self.FAN_NUM_ON_MAIN_BROAD @@ -212,15 +217,15 @@ class FanUtil(object): def get_fan_status(self, fan_num): if fan_num < self.FAN_NUM_1_IDX or fan_num > self.FAN_NUM_ON_MAIN_BROAD: - logging.debug('GET. Parameter error. fan_num, %d', fan_num) + self.logger.debug('GET. Parameter error. fan_num, %d', fan_num) return None if self.get_fan_fault(fan_num) is not None and self.get_fan_fault(fan_num) > 0: - logging.debug('GET. FAN fault. fan_num, %d', fan_num) + self.logger.debug('GET. FAN fault. fan_num, %d', fan_num) return False if self.get_fanr_fault(fan_num) is not None and self.get_fanr_fault(fan_num) > 0: - logging.debug('GET. FANR fault. fan_num, %d', fan_num) + self.logger.debug('GET. FANR fault. fan_num, %d', fan_num) return False return True diff --git a/platform/broadcom/sonic-platform-modules-accton/as5812-54x/classes/thermalutil.py b/platform/broadcom/sonic-platform-modules-accton/as5812-54x/classes/thermalutil.py index 5b8f890e88..7799bb3d53 100755 --- a/platform/broadcom/sonic-platform-modules-accton/as5812-54x/classes/thermalutil.py +++ b/platform/broadcom/sonic-platform-modules-accton/as5812-54x/classes/thermalutil.py @@ -52,7 +52,11 @@ class ThermalUtil(object): THERMAL_NUM_3_IDX: ['63', '4a'], } - def __init__(self): + logger = logging.getLogger(__name__) + def __init__(self, log_level=logging.DEBUG): + ch = logging.StreamHandler() + ch.setLevel(log_level) + self.logger.addHandler(ch) thermal_path = self.BASE_VAL_PATH for x in range(self.THERMAL_NUM_1_IDX, self.THERMAL_NUM_ON_MAIN_BROAD+1): @@ -62,7 +66,7 @@ class ThermalUtil(object): def _get_thermal_node_val(self, thermal_num): if thermal_num < self.THERMAL_NUM_1_IDX or thermal_num > self.THERMAL_NUM_ON_MAIN_BROAD: - logging.debug('GET. Parameter error. thermal_num, %d', thermal_num) + self.logger.debug('GET. Parameter error. thermal_num, %d', thermal_num) return None device_path = self.get_thermal_to_device_path(thermal_num) @@ -70,19 +74,19 @@ class ThermalUtil(object): try: val_file = open(filename, 'r') except IOError as e: - logging.error('GET. unable to open file: %s', str(e)) + self.logger.error('GET. unable to open file: %s', str(e)) return None content = val_file.readline().rstrip() if content == '': - logging.debug('GET. content is NULL. device_path:%s', device_path) + self.logger.debug('GET. content is NULL. device_path:%s', device_path) return None try: val_file.close() except: - logging.debug('GET. unable to close file. device_path:%s', device_path) + self.logger.debug('GET. unable to close file. device_path:%s', device_path) return None return int(content) diff --git a/platform/broadcom/sonic-platform-modules-accton/as5812-54x/service/as5812-platform-monitor.service b/platform/broadcom/sonic-platform-modules-accton/as5812-54x/service/as5812-platform-monitor.service index e495bcba3a..91c9adb01c 100755 --- a/platform/broadcom/sonic-platform-modules-accton/as5812-54x/service/as5812-platform-monitor.service +++ b/platform/broadcom/sonic-platform-modules-accton/as5812-54x/service/as5812-platform-monitor.service @@ -5,10 +5,10 @@ After=sysinit.target DefaultDependencies=no [Service] -Type=oneshot +Type=simple ExecStartPre=/usr/local/bin/accton_as5812_util.py install ExecStart=/usr/local/bin/accton_as5812_monitor.py -RemainAfterExit=yes +#RemainAfterExit=yes # Resource Limitations LimitCORE=infinity diff --git a/platform/broadcom/sonic-platform-modules-accton/as5812-54x/utils/accton_as5812_monitor.py b/platform/broadcom/sonic-platform-modules-accton/as5812-54x/utils/accton_as5812_monitor.py index 78c06f4656..8c7303efaa 100755 --- a/platform/broadcom/sonic-platform-modules-accton/as5812-54x/utils/accton_as5812_monitor.py +++ b/platform/broadcom/sonic-platform-modules-accton/as5812-54x/utils/accton_as5812_monitor.py @@ -30,6 +30,7 @@ try: import imp import logging import logging.config + import logging.handlers import types import time # this is only being used as part of the example import traceback @@ -46,7 +47,7 @@ FUNCTION_NAME = 'accton_as5812_monitor' DUTY_MAX = 100 global log_file -global log_level +global log_console # Make a class we can use to capture stdout and sterr in the log class accton_as5812_monitor(object): @@ -54,26 +55,32 @@ class accton_as5812_monitor(object): _ori_temp = 0 _new_perc = 0 - def __init__(self, log_file, log_level): + llog = logging.getLogger("["+FUNCTION_NAME+"]") + def __init__(self, log_console, log_file): """Needs a logger and a logger level.""" - # set up logging to file - logging.basicConfig( - filename=log_file, - filemode='w', - level=log_level, - format= '[%(asctime)s] {%(pathname)s:%(lineno)d} %(levelname)s - %(message)s', - datefmt='%H:%M:%S' - ) + + formatter = logging.Formatter('%(name)s %(message)s') + sys_handler = logging.handlers.SysLogHandler(address = '/dev/log') + sys_handler.setFormatter(formatter) + sys_handler.ident = 'common' + sys_handler.setLevel(logging.WARNING) #only fatal for syslog + self.llog.addHandler(sys_handler) + self.llog.setLevel(logging.DEBUG) + + if log_file: + fh = logging.FileHandler(log_file) + fh.setLevel(logging.INFO) + formatter = logging.Formatter('%(asctime)-15s %(name)s %(message)s') + fh.setFormatter(formatter) + self.llog.addHandler(fh) # set up logging to console - if log_level == logging.DEBUG: + if log_console: console = logging.StreamHandler() - console.setLevel(log_level) - formatter = logging.Formatter('%(name)-12s: %(levelname)-8s %(message)s') + console.setLevel(logging.DEBUG) #For debugging + formatter = logging.Formatter('%(asctime)-15s %(name)s %(message)s') console.setFormatter(formatter) - logging.getLogger('').addHandler(console) - - logging.debug('SET. logfile:%s / loglevel:%d', log_file, log_level) + self.llog.addHandler(console) def manage_fans(self): FAN_LEV1_UP_TEMP = 57700 # temperature @@ -108,26 +115,25 @@ class accton_as5812_monitor(object): for x in range(fan.get_idx_fan_start(), fan.get_num_fans()+1): fan_stat = fan.get_fan_status(x) - if fan_stat is None: - return False - if fan_stat is False: + if fan_stat is None or fan_stat is False: self._new_perc = FAN_LEV1_SPEED_PERC - logging.debug('INFO. SET new_perc to %d (FAN fault. fan_num:%d)', self._new_perc, x) + self.llog.error('SET new_perc to %d (FAN fault. fan_num:%d)', self._new_perc, x) break - logging.debug('INFO. fan_stat is True (fan_num:%d)', x) + else: + self.llog.debug('fan_stat is True (fan_num:%d)', x) if fan_stat is not None and fan_stat is not False: diff = new_temp - self._ori_temp if diff == 0: - logging.debug('INFO. RETURN. THERMAL temp not changed. %d / %d (new_temp / ori_temp)', new_temp, self._ori_temp) + self.llog.debug('RETURN. THERMAL temp not changed. %d / %d (new_temp / ori_temp)', new_temp, self._ori_temp) return True else: if diff >= 0: is_up = True - logging.debug('INFO. THERMAL temp UP %d / %d (new_temp / ori_temp)', new_temp, self._ori_temp) + self.llog.debug('THERMAL temp UP %d / %d (new_temp / ori_temp)', new_temp, self._ori_temp) else: is_up = False - logging.debug('INFO. THERMAL temp DOWN %d / %d (new_temp / ori_temp)', new_temp, self._ori_temp) + self.llog.debug('THERMAL temp DOWN %d / %d (new_temp / ori_temp)', new_temp, self._ori_temp) if is_up is True: if new_temp >= FAN_LEV1_UP_TEMP: @@ -138,7 +144,7 @@ class accton_as5812_monitor(object): self._new_perc = FAN_LEV3_SPEED_PERC else: self._new_perc = FAN_LEV4_SPEED_PERC - logging.debug('INFO. SET. FAN_SPEED as %d (new THERMAL temp:%d)', self._new_perc, new_temp) + self.llog.debug('SET. FAN_SPEED as %d (new THERMAL temp:%d)', self._new_perc, new_temp) else: if new_temp <= FAN_LEV4_DOWN_TEMP: self._new_perc = FAN_LEV4_SPEED_PERC @@ -148,57 +154,60 @@ class accton_as5812_monitor(object): self._new_perc = FAN_LEV2_SPEED_PERC else: self._new_perc = FAN_LEV1_SPEED_PERC - logging.debug('INFO. SET. FAN_SPEED as %d (new THERMAL temp:%d)', self._new_perc, new_temp) + self.llog.debug('SET. FAN_SPEED as %d (new THERMAL temp:%d)', self._new_perc, new_temp) cur_perc = fan.get_fan_duty_cycle(fan.get_idx_fan_start()) if cur_perc == self._new_perc: - logging.debug('INFO. RETURN. FAN speed not changed. %d / %d (new_perc / ori_perc)', self._new_perc, cur_perc) + self.llog.debug('RETURN. FAN speed not changed. %d / %d (new_perc / ori_perc)', self._new_perc, cur_perc) return True set_stat = fan.set_fan_duty_cycle(fan.get_idx_fan_start(), self._new_perc) if set_stat is True: - logging.debug('INFO: PASS. set_fan_duty_cycle (%d)', self._new_perc) + self.llog.debug('PASS. set_fan_duty_cycle (%d)', self._new_perc) else: - logging.debug('INFO: FAIL. set_fan_duty_cycle (%d)', self._new_perc) + self.llog.error('FAIL. set_fan_duty_cycle (%d)', self._new_perc) - logging.debug('INFO: GET. ori_perc is %d. ori_temp is %d', cur_perc, self._ori_temp) + self.llog.debug('GET. ori_perc is %d. ori_temp is %d', cur_perc, self._ori_temp) self._ori_temp = new_temp - logging.debug('INFO: UPDATE. ori_perc to %d. ori_temp to %d', cur_perc, self._ori_temp) + self.llog.info('UPDATE. ori_perc to %d. ori_temp to %d', cur_perc, self._ori_temp) return True -def handler(signum, frame): +def sig_handler(signum, frame): fan = FanUtil() - logging.debug('INFO:Cause signal %d, set fan speed max.', signum) + logging.critical('Cause signal %d, set fan speed max.', signum) fan.set_fan_duty_cycle(fan.get_idx_fan_start(), DUTY_MAX) sys.exit(0) def main(argv): log_file = '%s.log' % FUNCTION_NAME - log_level = logging.INFO + log_console = 0 + log_file = "" if len(sys.argv) != 1: try: - opts, args = getopt.getopt(argv,'hdl:',['lfile=']) + opts, args = getopt.getopt(argv,'hdl') except getopt.GetoptError: - print 'Usage: %s [-d] [-l ]' % sys.argv[0] + print 'Usage: %s [-d] [-l]' % sys.argv[0] return 0 for opt, arg in opts: if opt == '-h': - print 'Usage: %s [-d] [-l ]' % sys.argv[0] + print 'Usage: %s [-d] [-l]' % sys.argv[0] return 0 - elif opt in ('-d', '--debug'): - log_level = logging.DEBUG - elif opt in ('-l', '--lfile'): - log_file = arg + elif opt in ('-d'): + log_console = 1 + elif opt in ('-l'): + log_file = '%s.log' % sys.argv[0] - signal.signal(signal.SIGINT, handler) - signal.signal(signal.SIGTERM, handler) - monitor = accton_as5812_monitor(log_file, log_level) + signal.signal(signal.SIGINT, sig_handler) + signal.signal(signal.SIGTERM, sig_handler) + monitor = accton_as5812_monitor(log_console, log_file) + #time.sleep(100) # Loop forever, doing something useful hopefully: while True: monitor.manage_fans() time.sleep(10) + if __name__ == '__main__': main(sys.argv[1:]) diff --git a/platform/broadcom/sonic-platform-modules-accton/as7326-56x/modules/accton_i2c_cpld.c b/platform/broadcom/sonic-platform-modules-accton/as7326-56x/modules/accton_i2c_cpld.c index 2274c4a934..a4ff19fea5 100644 --- a/platform/broadcom/sonic-platform-modules-accton/as7326-56x/modules/accton_i2c_cpld.c +++ b/platform/broadcom/sonic-platform-modules-accton/as7326-56x/modules/accton_i2c_cpld.c @@ -585,35 +585,46 @@ static ssize_t show_present_all(struct device *dev, struct device_attribute *da, char *buf) { int i, status; - u8 values[4] = {0}; - u8 regs[] = {0x9, 0xA, 0xB, 0x18}; + u32 values; + u8 *value = (u8*)&values; + u8 regs_h1[] = {0x0f, 0x10, 0x11, 0x12}; + u8 regs_h2[] = {0x10, 0x11, 0x12, 0x13}; + u8 *regs_p; struct i2c_client *client = to_i2c_client(dev); struct as7326_56x_cpld_data *data = i2c_get_clientdata(client); + if (data->type == as7326_56x_cpld2) { + regs_p = regs_h1; + } else { + regs_p = regs_h2; + } mutex_lock(&data->update_lock); - - for (i = 0; i < ARRAY_SIZE(regs); i++) { - status = as7326_56x_cpld_read_internal(client, regs[i]); + for (i = 0; i < sizeof(values); i++) { + status = as7326_56x_cpld_read_internal(client, regs_p[i]); if (status < 0) { goto exit; } - values[i] = ~(u8)status; + value[i] = ~(u8)status; } mutex_unlock(&data->update_lock); - /* Return values 1 -> 56 in order */ + values = cpu_to_le32(values); + /* For port 1 ~ 30 in order */ if (data->type == as7326_56x_cpld2) { - values[3] &= 0xF; - } - else { /* as7326_56x_cpld3 */ - values[3] &= 0x3; + values &= 0x3FFFFFFF; + } else { /* Port 31 ~ 56 */ + u8 tmp1 = (values >> 18) & 0x3; + u8 tmp2 = (values >> 24) ; + + values &= 0x3ffff; + values |= (tmp2 << 18); + values |= (tmp1 << 26); } - return sprintf(buf, "%.2x %.2x %.2x %.2x\n", - values[0], values[1], values[2], values[3]); + return sprintf(buf, "%x\n", values); exit: mutex_unlock(&data->update_lock); diff --git a/platform/broadcom/sonic-platform-modules-accton/as7816-64x/utils/accton_as7816_util.py b/platform/broadcom/sonic-platform-modules-accton/as7816-64x/utils/accton_as7816_util.py index fe39ef6269..8db2ecc485 100755 --- a/platform/broadcom/sonic-platform-modules-accton/as7816-64x/utils/accton_as7816_util.py +++ b/platform/broadcom/sonic-platform-modules-accton/as7816-64x/utils/accton_as7816_util.py @@ -121,7 +121,7 @@ def show_set_help(): print cmd +" [led|sfp|fan]" print " use \""+ cmd + " led 0-4 \" to set led color" print " use \""+ cmd + " fan 0-100\" to set fan duty percetage" - print " use \""+ cmd + " sfp 1-32 {0|1}\" to set sfp# tx_disable" + print " use \""+ cmd + " sfp 1-64 {0|1}\" to set sfp# tx_disable" sys.exit(0) def diss_i2c_ir3507a(addr): @@ -149,7 +149,7 @@ def ir3507_check(): def show_eeprom_help(): cmd = sys.argv[0].split("/")[-1]+ " " + args[0] - print " use \""+ cmd + " 1-32 \" to dump sfp# eeprom" + print " use \""+ cmd + " 1-64 \" to dump sfp# eeprom" sys.exit(0) def my_log(txt): @@ -180,10 +180,11 @@ def driver_check(): kos = [ 'modprobe i2c_dev', 'modprobe i2c_mux_pca954x force_deselect_on_exit=1', +'modprobe optoe', 'modprobe accton_i2c_cpld' , 'modprobe ym2651y' , 'modprobe x86-64-accton-as7816-64x-fan' , -'modprobe x86-64-accton-as7816-64x-sfp' , +#'modprobe x86-64-accton-as7816-64x-sfp' , 'modprobe x86-64-accton-as7816-64x-leds' , 'modprobe x86-64-accton-as7816-64x-psu' ] @@ -228,8 +229,8 @@ i2c_bus = {'fan': ['17-0068'] , 'sfp': ['-0050']} i2c_nodes = {'fan': ['present', 'front_speed_rpm', 'rear_speed_rpm'] , 'thermal': ['hwmon/hwmon*/temp1_input'] , - 'psu': ['psu_present ', 'psu_power_good'] , - 'sfp': ['sfp_is_present ', 'sfp_tx_disable']} + 'psu': ['psu_present', 'psu_power_good'] , + 'sfp': ['module_present']} sfp_map = [37,38,39,40,42,41,44,43,33,34,35,36,45,46,47,48,49,50,51,52, 61,62,63,64,53,54,55,56,57,58,59,60,69,70,71,72,77,78,79,80,65, @@ -283,7 +284,8 @@ def device_install(): return status for i in range(0,len(sfp_map)): - status, output =log_os_system("echo as7816_64x_port"+str(i+1)+" 0x50 > /sys/bus/i2c/devices/i2c-"+str(sfp_map[i])+"/new_device", 1) + path = "/sys/bus/i2c/devices/i2c-"+str(sfp_map[i])+"/new_device" + status, output =log_os_system("echo optoe1 0x50 > " + path, 1) if status: print output if FORCE == 0: @@ -393,7 +395,9 @@ def devices_info(): elif 'sfp' == key: for k in range(0,DEVICE_NO[key]): node = key+str(k+1) - path = i2c_prefix+ str(sfp_map[k])+ buses[i]+"/"+ nodes[j] + fmt = i2c_prefix+"19-0060/{0}_{1}" + path = fmt.format(nodes[j], k+1) + my_log(node+": "+ path) ALL_DEVICE[key][node].append(path) else: @@ -428,10 +432,8 @@ def show_eeprom(index): print("Please install first!") return - if len(ALL_DEVICE)==0: - devices_info() - node = ALL_DEVICE['sfp'] ['sfp'+str(index)][0] - node = node.replace(node.split("/")[-1], 'sfp_eeprom') + i = int(index)-1 + node = i2c_prefix+ str(sfp_map[i])+ i2c_bus['sfp'][0]+"/"+ 'eeprom' # check if got hexdump command in current environment ret, log = log_os_system("which hexdump", 0) ret, log2 = log_os_system("which busybox hexdump", 0) @@ -446,7 +448,7 @@ def show_eeprom(index): return 1 print node + ":" - ret, log = log_os_system("cat "+node+"| "+hex_cmd+" -C", 1) + ret, log = log_os_system(hex_cmd +" -C "+node, 1) if ret==0: print log else: diff --git a/platform/broadcom/sonic-platform-modules-accton/common/modules/accton_i2c_cpld.c b/platform/broadcom/sonic-platform-modules-accton/common/modules/accton_i2c_cpld.c index 3712d1a396..03e528ef8d 100755 --- a/platform/broadcom/sonic-platform-modules-accton/common/modules/accton_i2c_cpld.c +++ b/platform/broadcom/sonic-platform-modules-accton/common/modules/accton_i2c_cpld.c @@ -34,6 +34,7 @@ #include #include #include +#include #define MAX_PORT_NUM 64 @@ -180,7 +181,7 @@ struct attrs as7712_common[] = { struct attrs as7816_common[] = { [CMN_VERSION] = {0x01, false, &common_attrs[CMN_VERSION]}, [CMN_ACCESS] = {0x00, false, &common_attrs[CMN_ACCESS]}, - [CMN_PRESENT_ALL] = {0x30, false, &common_attrs[CMN_PRESENT_ALL]}, + [CMN_PRESENT_ALL] = {0x70, false, &common_attrs[CMN_PRESENT_ALL]}, }; struct attrs as7312_common[] = { [CMN_VERSION] = {0x01, false, &common_attrs[CMN_VERSION]}, @@ -282,7 +283,7 @@ static int get_sfp_spec(int model, u16 *num, u8 *types) return 0; } -static int get_present_reg(int model, u8 port, u8 *cpld_addr, u8 *reg, u8 *num) +static int get_present_reg_distinct(int model, u8 port, u8 *cpld_addr, u8 *reg, u8 *num) { u8 cpld_address[] = CPLD_ADDRS; @@ -388,7 +389,7 @@ static ssize_t show_presnet_all_distinct(struct device *dev, mutex_lock(&data->update_lock); while(i < data->sfp_num) { - get_present_reg(data->model, i, &cpld_addr, ®, &num); + get_present_reg_distinct(data->model, i, &cpld_addr, ®, &num); if(cpld_addr == client->addr) value = cpld_read_internal(client, reg); else @@ -416,14 +417,15 @@ static ssize_t show_presnet_all(struct device *dev, struct i2c_client *client = to_i2c_client(dev); struct cpld_data *data = i2c_get_clientdata(client); struct cpld_sensor *sensor = to_cpld_sensor(devattr); - u8 i, values[MAX_RESP_LENGTH/8]; + u8 i, values[MAX_PORT_NUM/8]; + /*In case, the registers out-of-order*/ if (sensor->reg < 0) { return show_presnet_all_distinct(dev, devattr, buf); } mutex_lock(&data->update_lock); - for (i = 0; i < ((data->sfp_num+7)/8); i++) { + for (i = 0; i < ((data->sfp_num + 7)/8); i++) { values[i] = cpld_read_internal(client, sensor->reg + i); if (unlikely(values[i] < 0)) { goto exit; @@ -683,12 +685,11 @@ static int add_attributes_portly(struct cpld_data *data, struct attrs **pa) for (i = 0; pa[i]; i++) { a = pa[i]; - - invert = a->invert; b = a->base; if (b == NULL) break; + invert = a->invert; for (j = 0; j < data->sfp_num; j++) { snprintf(name, NAME_SIZE, "%s_%d", b->name, j+1);