lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [day] [month] [year] [list]
Message-ID: <d04814fb-1ee1-4987-b8a1-d7d6b834c360@ans.pl>
Date: Wed, 11 Sep 2024 23:42:10 -0700
From: Krzysztof Olędzki <ole@....pl>
To: Ido Schimmel <idosch@...dia.com>, Tariq Toukan <tariqt@...dia.com>,
        "David S. Miller" <davem@...emloft.net>,
        Eric Dumazet <edumazet@...gle.com>, Jakub Kicinski <kuba@...nel.org>,
        Paolo Abeni <pabeni@...hat.com>, Yishai Hadas <yishaih@...dia.com>
Cc: "netdev@...r.kernel.org" <netdev@...r.kernel.org>,
        linux-rdma@...r.kernel.org
Subject: [PATCH net-next 4/4] mlx4: mlx4_get_port_ib_caps() cleanup

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@....pl>
---
 drivers/net/ethernet/mellanox/mlx4/port.c | 26 ++++++++++++++---------
 include/linux/mlx4/device.h               |  2 +-
 2 files changed, 17 insertions(+), 11 deletions(-)

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 {
-- 
2.46.0

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ