X86 platform drivers
 help / color / mirror / Atom feed
From: Vadim Pasternak <vadimp@nvidia.com>
To: <hdegoede@redhat.com>
Cc: <platform-driver-x86@vger.kernel.org>,
	Vadim Pasternak <vadimp@nvidia.com>
Subject: [PATCH platform-next 09/13] platform/mellanox: mlxreg-hotplug: Allow more flexible hotplug events configuration
Date: Wed, 8 Feb 2023 08:33:26 +0200	[thread overview]
Message-ID: <20230208063331.15560-10-vadimp@nvidia.com> (raw)
In-Reply-To: <20230208063331.15560-1-vadimp@nvidia.com>

Currently hotplug configuration in logic device assumes that all items
are provided with no holes.
Thus, any group of hotplug events, associated with the specific
status/event/mask registers is configured in those registers
successively from bit zero to bit #n (#n < 8).

This logic is changed int order to allow non-successive definition to
support configuration with the skipped bits – for example bits 3, 5, 7
in status/event/mask registers can be associated with hotplug events,
while others can be skipped.

Signed-off-by: Vadim Pasternak <vadimp@nvidia.com>
Reviewed-by: Michael Shych <michaelsh@nvidia.com>
---
 drivers/platform/mellanox/mlxreg-hotplug.c | 28 ++++++++++++++++++----
 1 file changed, 23 insertions(+), 5 deletions(-)

diff --git a/drivers/platform/mellanox/mlxreg-hotplug.c b/drivers/platform/mellanox/mlxreg-hotplug.c
index 117bc3f395fd..b7dcc64cd238 100644
--- a/drivers/platform/mellanox/mlxreg-hotplug.c
+++ b/drivers/platform/mellanox/mlxreg-hotplug.c
@@ -239,6 +239,17 @@ static ssize_t mlxreg_hotplug_attr_show(struct device *dev,
 #define PRIV_ATTR(i) priv->mlxreg_hotplug_attr[i]
 #define PRIV_DEV_ATTR(i) priv->mlxreg_hotplug_dev_attr[i]
 
+static int mlxreg_hotplug_item_label_index_get(u32 mask, u32 bit)
+{
+	int i, j;
+
+	for (i = 0, j = -1; i <= bit; i++) {
+		if (mask & BIT(i))
+			j++;
+	}
+	return j;
+}
+
 static int mlxreg_hotplug_attr_init(struct mlxreg_hotplug_priv_data *priv)
 {
 	struct mlxreg_core_hotplug_platform_data *pdata;
@@ -246,7 +257,7 @@ static int mlxreg_hotplug_attr_init(struct mlxreg_hotplug_priv_data *priv)
 	struct mlxreg_core_data *data;
 	unsigned long mask;
 	u32 regval;
-	int num_attrs = 0, id = 0, i, j, k, ret;
+	int num_attrs = 0, id = 0, i, j, k, count, ret;
 
 	pdata = dev_get_platdata(&priv->pdev->dev);
 	item = pdata->items;
@@ -272,7 +283,8 @@ static int mlxreg_hotplug_attr_init(struct mlxreg_hotplug_priv_data *priv)
 		/* Go over all unmasked units within item. */
 		mask = item->mask;
 		k = 0;
-		for_each_set_bit(j, &mask, item->count) {
+		count = item->ind ? item->ind : item->count;
+		for_each_set_bit(j, &mask, count) {
 			if (data->capability) {
 				/*
 				 * Read capability register and skip non
@@ -282,16 +294,17 @@ static int mlxreg_hotplug_attr_init(struct mlxreg_hotplug_priv_data *priv)
 						  data->capability, &regval);
 				if (ret)
 					return ret;
+
 				if (!(regval & data->bit)) {
 					data++;
 					continue;
 				}
 			}
+
 			PRIV_ATTR(id) = &PRIV_DEV_ATTR(id).dev_attr.attr;
 			PRIV_ATTR(id)->name = devm_kasprintf(&priv->pdev->dev,
 							     GFP_KERNEL,
 							     data->label);
-
 			if (!PRIV_ATTR(id)->name) {
 				dev_err(priv->dev, "Memory allocation failed for attr %d.\n",
 					id);
@@ -365,9 +378,14 @@ mlxreg_hotplug_work_helper(struct mlxreg_hotplug_priv_data *priv,
 	regval &= item->mask;
 	asserted = item->cache ^ regval;
 	item->cache = regval;
-
 	for_each_set_bit(bit, &asserted, 8) {
-		data = item->data + bit;
+		int pos;
+
+		pos = mlxreg_hotplug_item_label_index_get(item->mask, bit);
+		if (pos < 0)
+			goto out;
+
+		data = item->data + pos;
 		if (regval & BIT(bit)) {
 			if (item->inversed)
 				mlxreg_hotplug_device_destroy(priv, data, item->kind);
-- 
2.20.1


  parent reply	other threads:[~2023-02-08  6:35 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-08  6:33 [PATCH platform-next 00/13] platform/x86: Add new systems and features for Nvidia systems Vadim Pasternak
2023-02-08  6:33 ` [PATCH platform-next 01/13] platform: mellanox: Introduce support for rack manager switch Vadim Pasternak
2023-02-08  6:33 ` [PATCH platform-next 02/13] platform: mellanox: Change "reset_pwr_converter_fail" attribute Vadim Pasternak
2023-02-08  6:33 ` [PATCH platform-next 03/13] platform: mellanox: Cosmetic changes - rename to more common name Vadim Pasternak
2023-02-08  6:33 ` [PATCH platform-next 04/13] platform: mellanox: Introduce support for next-generation 800GB/s switch Vadim Pasternak
2023-02-08  6:33 ` [PATCH platform-next 05/13] platform: mellanox: Introduce support of new Nvidia L1 switch Vadim Pasternak
2023-02-08  6:33 ` [PATCH platform-next 06/13] platform: mellanox: Split initialization procedure Vadim Pasternak
2023-02-08  6:33 ` [PATCH platform-next 07/13] platform: mellanox: Split logic in init and exit flow Vadim Pasternak
2023-02-08  6:33 ` [PATCH platform-next 08/13] platform: mellanox: Extend all systems with I2C notification callback Vadim Pasternak
2023-02-08  6:33 ` Vadim Pasternak [this message]
2023-02-08  6:33 ` [PATCH platform-next 10/13] platform_data/mlxreg: Add field with mapped resource address Vadim Pasternak
2023-02-08  6:33 ` [PATCH platform-next 11/13] platform: mellanox: mlx-platform: Add mux selection register to regmap Vadim Pasternak
2023-02-08  6:33 ` [PATCH platform-next 12/13] platform: mellanox: mlx-platform: Move bus shift assignment out of the loop Vadim Pasternak
2023-02-08  6:33 ` [PATCH platform-next 13/13] Documentation/ABI: Add new attribute for mlxreg-io sysfs interfaces Vadim Pasternak
2023-02-10 17:46 ` [PATCH platform-next 00/13] platform/x86: Add new systems and features for Nvidia systems Hans de Goede

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230208063331.15560-10-vadimp@nvidia.com \
    --to=vadimp@nvidia.com \
    --cc=hdegoede@redhat.com \
    --cc=platform-driver-x86@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox