Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions platform/mellanox/integration-scripts/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ def build_commit_description(changes):
content = content + f"* {key} : {value}\n"
return content


Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove the extra line

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was intentional, to have two line diff between two methods

def parse_id(id_):
if id_ and id_ != "N/A":
id_ = "https://github.com/torvalds/linux/commit/" + id_
Expand Down
53 changes: 45 additions & 8 deletions platform/mellanox/integration-scripts/hwmgmt_kernel_patches.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,18 @@
COMMIT_TITLE = "Intgerate HW-MGMT {} Changes"

PATCH_TABLE_LOC = "platform/mellanox/hw-management/hw-mgmt/recipes-kernel/linux/"
PATCHWORK_LOC = "linux-{}/patchwork"
PATCH_TABLE_NAME = "Patch_Status_Table.txt"
PATCH_TABLE_DELIMITER = "----------------------"
PATCH_NAME = "patch name"
COMMIT_ID = "Upstream commit id"

# Strips the subversion
def get_kver(k_version):
major, minor, subversion = k_version.split(".")
k_ver = "{}.{}".format(major, minor)
return k_ver

def trim_array_str(str_list):
ret = [elem.strip() for elem in str_list]
return ret
Expand All @@ -46,12 +53,8 @@ def get_line_elements(line):
columns = trim_array_str(columns_raw)
return columns

def load_patch_table(path, k_version):
def load_patch_table(path, k_ver):
patch_table_filename = os.path.join(path, PATCH_TABLE_NAME)

major, minor, subversion = k_version.split(".")
k_ver = "{}.{}".format(major, minor)

print("Loading patch table {} kver:{}".format(patch_table_filename, k_ver))

if not os.path.isfile(patch_table_filename):
Expand Down Expand Up @@ -140,6 +143,8 @@ class Data:
current_kcfg = list(tuple())
# current raw kconfig exclude data
kcfg_exclude = list()
# kernel version
k_ver = ""

class HwMgmtAction(Action):

Expand Down Expand Up @@ -247,6 +252,7 @@ def read_data(self):
print("-> FATAL: Patch {} not found either in upstream or non-upstream list".format(patch))
if not self.args.is_test:
sys.exit(1)
Data.k_ver = get_kver(self.args.kernel_version)

def find_mlnx_hw_mgmt_markers(self):
""" Find the indexes where the current mlnx patches sits in SLK_SERIES file """
Expand Down Expand Up @@ -386,13 +392,45 @@ def list_patches(self):
old_non_up_patches = [ptch.strip() for ptch in Data.old_non_up]
return old_up_patches, old_non_up_patches

def _get_patchwork(self, patch_name):
root_p = os.path.join(self.args.build_root, PATCH_TABLE_LOC)
patchwork_loc = PATCHWORK_LOC.format(Data.k_ver)
file_dir = os.path.join(root_p, patchwork_loc)
file_loc = os.path.join(file_dir, f"{patch_name}.txt")
if not os.path.exists(file_loc):
return ""
print(f"-> INFO: Patchwork file {file_loc} is present")
lines = FileHandler.read_strip(file_loc)
for line in lines:
if "patchwork_link" not in line:
continue
tokens = line.split(":")
if len(tokens) < 2:
print(f"-> WARN: Invalid entry {line}, did not follow <key>:<value>")
continue
key = tokens[0]
values = tokens[1:]
if key == "patchwork_link":
desc = ":".join(values)
desc = desc.strip()
print(f"-> INFO: Patch work link for patch {patch_name} : {desc}")
return desc
return ""

def _fetch_description(self, patch, id_):
desc = parse_id(id_)
if not desc:
# not an upstream patch, check if the patchwork link is present and fetch it
desc = self._get_patchwork(patch)
return desc

def create_commit_msg(self, table):
title = COMMIT_TITLE.format(self.args.hw_mgmt_ver)
changes_slk, changes_sb = {}, {}
old_up_patches, old_non_up_patches = self.list_patches()
for patch in table:
id_ = parse_id(patch.get(COMMIT_ID, ""))
patch_ = patch.get(PATCH_NAME)
id_ = self._fetch_description(patch_, patch.get(COMMIT_ID, ""))
if patch_ in Data.new_up and patch_ not in old_up_patches:
changes_slk[patch_] = id_
print(f"-> INFO: Patch: {patch_}, Commit: {id_}, added to linux-kernel description")
Expand Down Expand Up @@ -432,7 +470,7 @@ def perform(self):
self.write_series_diff()

path = os.path.join(self.args.build_root, PATCH_TABLE_LOC)
patch_table = load_patch_table(path, self.args.kernel_version)
patch_table = load_patch_table(path, Data.k_ver)

sb_msg, slk_msg = self.create_commit_msg(patch_table)

Expand Down Expand Up @@ -470,4 +508,3 @@ def create_parser():
parser = create_parser()
action = HwMgmtAction.get(parser.parse_args())
action.perform()

Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ Kernel-5.10
|0044-platform-mellanox-mlxreg-io-Fix-read-access-of-n-byt.patch | 5fd56f11838d | Bugfix upstream | 5.10.75 | |
|0045-i2c-mlxcpld-Fix-criteria-for-frequency-setting.patch | 52f57396c75a | Feature upstream | | |
|0046-i2c-mlxcpld-Reduce-polling-time-for-performance-impr.patch | 669b2e4aa1a8 | Feature upstream | | (5.16) |
|0047-i2c-mlxcpld-Allow-flexible-polling-time-setting-for-.patch | 712d6617d0a2 | Feature upstream | | (5.16) |
|0048-hwmon-pmbus-mp2975-Add-missed-POUT-attribute-for-pag.patch | 2292e2f685cd | Bugfix upstream | 5.10.71 | |
|0049-leds-mlxreg-Provide-conversion-for-hardware-LED-colo.patch | | Rejected; take[ALL] | |Need to check patch apply. Can break patch apply|
|0050-leds-mlxreg-Skip-setting-LED-color-during-initializa.patch | | Downstream | | |
|0051-leds-mlxreg-Allow-multi-instantiation-of-same-name-L.patch | | Downstream | | Modular SN4800 |
|0188-i2c-mux-Add-register-map-based-mux-driver.patch | | Feature pending | | BF3-COME |
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
0105-mlxsw-reg-Extend-MTBR-register-with-new-slot-number-.patch
0106-mlxsw-reg-Extend-MCIA-register-with-new-slot-number-.patch
0107-mlxsw-reg-Extend-MCION-register-with-new-slot-number.patch
0188-i2c-mux-Add-register-map-based-mux-driver.patch
###-> mellanox_hw_mgmt-end

# Cisco patches for 5.10 kernel
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
+0169-TMP-mlxsw-i2c-Prevent-transaction-execution-for-spec.patch
+0172-DS-platform-mlx-platform-Add-SPI-path-for-rack-switc.patch
+0174-DS-mlxsw-core_linecards-Skip-devlink-and-provisionin.patch
0188-i2c-mux-Add-register-map-based-mux-driver.patch
###-> mellanox_hw_mgmt-end

# Cisco patches for 5.10 kernel
28 changes: 14 additions & 14 deletions platform/mellanox/integration-scripts/tests/test_hwmgmtaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import sys
import shutil
from unittest import mock, TestCase
from pyfakefs.fake_filesystem_unittest import Patcher
sys.path.append('../')
from hwmgmt_kernel_patches import *

Expand Down Expand Up @@ -49,6 +50,7 @@
0105-mlxsw-reg-Extend-MTBR-register-with-new-slot-number-.patch
0106-mlxsw-reg-Extend-MCIA-register-with-new-slot-number-.patch
0107-mlxsw-reg-Extend-MCION-register-with-new-slot-number.patch
0188-i2c-mux-Add-register-map-based-mux-driver.patch
"""

TEST_SLK_COMMIT = """\
Expand All @@ -63,10 +65,9 @@
* 0009-i2c-mux-mlxcpld-Extend-driver-to-support-word-addres.patch : https://github.com/torvalds/linux/commit/c52a1c5f5db5
* 0010-i2c-mux-mlxcpld-Extend-supported-mux-number.patch : https://github.com/torvalds/linux/commit/699c0506543e
* 0011-i2c-mux-mlxcpld-Add-callback-to-notify-mux-creation-.patch : https://github.com/torvalds/linux/commit/a39bd92e92b9

* 0188-i2c-mux-Add-register-map-based-mux-driver.patch : https://patchwork.ozlabs.org/project/linux-i2c/patch/[email protected]/
"""


TEST_SB_COMMIT = """\
Intgerate HW-MGMT 7.0030.0937 Changes

Expand Down Expand Up @@ -128,12 +129,6 @@ def setUp(self):
Data.current_kcfg = KCFG.parse_opts_strs(Data.current_kcfg)
Data.kcfg_exclude = FileHandler.read_raw(MOCK_INPUTS_DIR+"/kconfig-exclusions")

def tearDown(self):
try:
os.remove(MOCK_WRITE_FILE)
except:
pass

def test_find_mlnx_hw_mgmt_markers(self):
self.action.find_mlnx_hw_mgmt_markers()
print(Data.i_mlnx_start, Data.i_mlnx_end)
Expand Down Expand Up @@ -186,10 +181,15 @@ def test_write_series_diff(self, mock_write_lines):
assert check_file_content(MOCK_INPUTS_DIR+"expected_data/series.patch")

def test_commit_msg(self):
table = load_patch_table(MOCK_INPUTS_DIR, "5.10.140")
sb, slk = self.action.create_commit_msg(table)
print(slk)
print(TEST_SLK_COMMIT)
assert slk.split() == TEST_SLK_COMMIT.split()
assert sb.split() == TEST_SB_COMMIT.split()
root_dir = "/sonic/" + PATCH_TABLE_LOC + PATCHWORK_LOC.format("5.10")
content = "patchwork_link: https://patchwork.ozlabs.org/project/linux-i2c/patch/[email protected]/\n"
file = "0188-i2c-mux-Add-register-map-based-mux-driver.patch.txt"
table = load_patch_table(MOCK_INPUTS_DIR, "5.10")
with Patcher() as patcher:
patcher.fs.create_file(os.path.join(root_dir, file), contents=content)
sb, slk = self.action.create_commit_msg(table)
print(slk)
print(TEST_SLK_COMMIT)
assert slk.split() == TEST_SLK_COMMIT.split()
assert sb.split() == TEST_SB_COMMIT.split()