diff mbox series

[net-next,4/4] mlx4: mlx4_get_port_ib_caps() cleanup

Message ID d04814fb-1ee1-4987-b8a1-d7d6b834c360@ans.pl (mailing list archive)
State Changes Requested
Delegated to: Netdev Maintainers
Headers show
Series [net-next,1/4] mlx4/mlx5: {mlx4,mlx5e}_en_get_module_info cleanup | expand

Checks

Context Check Description
netdev/series_format warning Series does not have a cover letter
netdev/tree_selection success Clearly marked for net-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit fail Errors and warnings before: 16 this patch: 16
netdev/build_tools success Errors and warnings before: 0 this patch: 0
netdev/cc_maintainers success CCed 7 of 7 maintainers
netdev/build_clang fail Errors and warnings before: 17 this patch: 17
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn fail Errors and warnings before: 16 this patch: 16
netdev/checkpatch warning WARNING: From:/Signed-off-by: email name mismatch: 'From: "Krzysztof Olędzki" <ole@ans.pl>' != 'Signed-off-by: Krzysztof Piotr Oledzki <ole@ans.pl>'
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 1 this patch: 1
netdev/source_inline success Was 0 now: 0

Commit Message

Krzysztof Olędzki Sept. 12, 2024, 6:42 a.m. UTC
Remove magic values and casts from mlx4_get_port_ib_caps() and use
proper structures instead.

Replace 0x0015 with MLX4_ATTR_PORT_INFO that is named after a similar
const from ib_smi.h and because "GetPortInfo MAD" name is also mentioned
in the Firmware Release Notes.

Use cap_mask name after "struct ib_port_info" given the offset (64 + 20)
matches.

Signed-off-by: Krzysztof Piotr Oledzki <ole@ans.pl>
---
 drivers/net/ethernet/mellanox/mlx4/port.c | 26 ++++++++++++++---------
 include/linux/mlx4/device.h               |  2 +-
 2 files changed, 17 insertions(+), 11 deletions(-)
diff mbox series

Patch

diff --git a/drivers/net/ethernet/mellanox/mlx4/port.c b/drivers/net/ethernet/mellanox/mlx4/port.c
index 8c2a384404f9..d5109e38cbd5 100644
--- a/drivers/net/ethernet/mellanox/mlx4/port.c
+++ b/drivers/net/ethernet/mellanox/mlx4/port.c
@@ -1054,10 +1054,15 @@  int mlx4_unbond_vlan_table(struct mlx4_dev *dev)
 	return ret;
 }
 
+struct mlx4_mad_port_info {
+	u8 reserved[20];
+	__be32 cap_mask;
+};
+
 int mlx4_get_port_ib_caps(struct mlx4_dev *dev, u8 port, __be32 *caps)
 {
 	struct mlx4_cmd_mailbox *inmailbox, *outmailbox;
-	u8 *inbuf, *outbuf;
+	struct mlx4_mad_ifc *inmad, *outmad;
 	int err;
 
 	inmailbox = mlx4_alloc_cmd_mailbox(dev);
@@ -1070,20 +1075,21 @@  int mlx4_get_port_ib_caps(struct mlx4_dev *dev, u8 port, __be32 *caps)
 		return PTR_ERR(outmailbox);
 	}
 
-	inbuf = inmailbox->buf;
-	outbuf = outmailbox->buf;
-	inbuf[0] = 1;
-	inbuf[1] = 1;
-	inbuf[2] = 1;
-	inbuf[3] = 1;
-	*(__be16 *) (&inbuf[16]) = cpu_to_be16(0x0015);
-	*(__be32 *) (&inbuf[20]) = cpu_to_be32(port);
+	inmad = (struct mlx4_mad_ifc *)(inmailbox->buf);
+	outmad = (struct mlx4_mad_ifc *)(outmailbox->buf);
+
+	inmad->method = 0x1; /* Get */
+	inmad->class_version = 0x1;
+	inmad->mgmt_class = 0x1;
+	inmad->base_version = 0x1;
+	inmad->attr_id = cpu_to_be16(MLX4_ATTR_PORT_INFO);
+	inmad->attr_mod = cpu_to_be32(port);
 
 	err = mlx4_cmd_box(dev, inmailbox->dma, outmailbox->dma, port, 3,
 			   MLX4_CMD_MAD_IFC, MLX4_CMD_TIME_CLASS_C,
 			   MLX4_CMD_NATIVE);
 	if (!err)
-		*caps = *(__be32 *) (outbuf + 84);
+		*caps = ((struct mlx4_mad_port_info *)outmad->data)->cap_mask;
 	mlx4_free_cmd_mailbox(dev, inmailbox);
 	mlx4_free_cmd_mailbox(dev, outmailbox);
 	return err;
diff --git a/include/linux/mlx4/device.h b/include/linux/mlx4/device.h
index 4f2ff466b459..e64fc35c80b6 100644
--- a/include/linux/mlx4/device.h
+++ b/include/linux/mlx4/device.h
@@ -264,7 +264,7 @@  enum {
 	MLX4_FUNC_CAP_DMFS_A0_STATIC	= 1L << 2
 };
 
-
+#define MLX4_ATTR_PORT_INFO		0x0015
 #define MLX4_ATTR_CABLE_INFO		0xff60
 
 enum {