Skip to content

Commit

Permalink
[Mellanox] Adopt single way to get fan direction for all ASIC types (#…
Browse files Browse the repository at this point in the history
…7386)

#### Why I did it
Adopt a single way to get fan direction for all ASIC types.
It depends on hw-mgmt V.7.0010.2000.2303. Depends on #7419

#### How I did it
Originally, the get_direction was implemented by fetching and parsing `/var/run/hw-management/system/fan_dir` on the Spectrum-2 and the Spectrum-3 systems. It isn't supported on the Spectrum system.
Now, it is implemented by fetching `/var/run/hw-management/thermal/fanX_dir` for all the platforms.

Signed-off-by: Stephen Sun <stephens@nvidia.com>
  • Loading branch information
stephenxs authored May 4, 2021
1 parent 853c214 commit b2286a2
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
'drawer_num': 4,
'drawer_type': 'real',
'fan_num_per_drawer': 2,
'support_fan_direction': False,
'support_fan_direction': True,
'hot_swappable': True
},
'psus': {
Expand All @@ -31,7 +31,7 @@
'drawer_num': 4,
'drawer_type': 'real',
'fan_num_per_drawer': 1,
'support_fan_direction': False,
'support_fan_direction': True,
'hot_swappable': True
},
'psus': {
Expand All @@ -52,7 +52,7 @@
'drawer_num': 1,
'drawer_type': 'virtual',
'fan_num_per_drawer': 4,
'support_fan_direction': False,
'support_fan_direction': True,
'hot_swappable': False
},
'psus': {
Expand All @@ -73,7 +73,7 @@
'drawer_num': 4,
'drawer_type': 'real',
'fan_num_per_drawer': 2,
'support_fan_direction': False,
'support_fan_direction': True,
'hot_swappable': True
},
'psus': {
Expand All @@ -94,7 +94,7 @@
'drawer_num': 1,
'drawer_type': 'virtual',
'fan_num_per_drawer': 4,
'support_fan_direction': False,
'support_fan_direction': True,
'hot_swappable': False
},
'psus': {
Expand Down
6 changes: 4 additions & 2 deletions platform/mellanox/mlnx-platform-api/sonic_platform/fan.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@

FAN_PATH = "/var/run/hw-management/thermal/"
CONFIG_PATH = "/var/run/hw-management/config"
# fan_dir isn't supported on Spectrum 1. It is supported on Spectrum 2 and later switches
FAN_DIR = "/var/run/hw-management/system/fan_dir"

FAN_DIR = "/var/run/hw-management/thermal/fan{}_dir"
FAN_DIR_VALUE_EXHAUST = 0
FAN_DIR_VALUE_INTAKE = 1
COOLING_STATE_PATH = "/var/run/hw-management/thermal/cooling_cur_state"

class Fan(FanBase):
Expand Down
17 changes: 9 additions & 8 deletions platform/mellanox/mlnx-platform-api/sonic_platform/fan_drawer.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from sonic_platform_base.fan_drawer_base import FanDrawerBase
from sonic_platform_base.fan_base import FanBase
from .led import FanLed, SharedLed
from .utils import read_int_from_file
except ImportError as e:
raise ImportError (str(e) + "- required module not found")

Expand Down Expand Up @@ -51,14 +52,14 @@ def get_direction(self):
return FanBase.FAN_DIRECTION_NOT_APPLICABLE

try:
from .fan import FAN_DIR
with open(FAN_DIR, 'r') as fan_dir:
fan_dir_bits = int(fan_dir.read())
fan_mask = 1 << self._index - 1
if fan_dir_bits & fan_mask:
return FanBase.FAN_DIRECTION_INTAKE
else:
return FanBase.FAN_DIRECTION_EXHAUST
from .fan import FAN_DIR, FAN_DIR_VALUE_INTAKE, FAN_DIR_VALUE_EXHAUST
fan_dir = read_int_from_file(FAN_DIR.format(self._index), raise_exception=True)
if fan_dir == FAN_DIR_VALUE_INTAKE:
return FanBase.FAN_DIRECTION_INTAKE
elif fan_dir == FAN_DIR_VALUE_EXHAUST:
return FanBase.FAN_DIRECTION_EXHAUST
else:
raise RuntimeError("Got wrong value {} for fan direction {}".format(fan_dir, self._index))
except (ValueError, IOError) as e:
raise RuntimeError("Failed to read fan direction status to {}".format(repr(e)))

Expand Down

0 comments on commit b2286a2

Please sign in to comment.