Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp1695461ybh; Tue, 14 Jul 2020 05:04:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxhZcXX5W8ru4qow7EzcuvTPlLcPvXjmEMphf9wt8e4sZkTmWOiO+cYmmIorblecKCWab8y X-Received: by 2002:a05:6402:b1a:: with SMTP id bm26mr4069609edb.144.1594728255820; Tue, 14 Jul 2020 05:04:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594728255; cv=none; d=google.com; s=arc-20160816; b=lDS+GriMhU5efipVTqpiJNwigiYpeXyp5WEPqFcHTOmpY7Q+M1gcJAVth2Az9V0bUe bJdIF1U1kBveQ0peL226FRKM1UEKRC/mNoGZid4IZSLcfa5lyLunPXw/9RZIjMlhcbVM gwdoG1SIpg6V1GYTD5hZevi4baDjDM5r1gC8K3LQSa5tFsyqvZ+6NcUyh/fnJHtLoxa6 zXlY4+7fG7O0WGZ5PIGpaHPMP5oq2bE10Ud+xdT5kOrHqA7deUJSJBtvCu8pmRLCQC81 Wn27pG5D6aFkNeQFvcryXnWE9rVKsE3x7sUsiAOsDxeBQ63WM4WEV3zKpbD6Piis1zMy fztA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=bXr7y1cgzYytFP17Xfe4FRfAFGY0ghnd+7ZDGYyrPx0=; b=OZrniLXQ3o9Gc9A+t9T+MYyYhrcdlNpjByjG9wXxLE9bOQ+Z1+oO3qxDs28xzGluAg Irb8uRzYNFmlKTy6DQA3WrEZFUJN9Gu2qYxqj/gJWnpUwp6Q/mm7yHRZP3vVS3GCFNO8 MXryU0QqevEl+40u5t09G564pNlgEabxat5MfSeONpNnv908e8r2i/2e+t+3zrBwqoAV vPbwqkS61+9nU6n6t376vqNnoWjlyUcMStyDkdZuQy/IILsvIq45P807LlGOf/9Fs2xf noXDxIWz4xmH3WCcL/RGdPGuePEXLNGKBWeUyvxgurOXvXHbv6StGE3E2EBp1QU2p2vs dCNQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mellanox.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id co19si11033207edb.605.2020.07.14.05.03.50; Tue, 14 Jul 2020 05:04:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mellanox.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728131AbgGNMCU (ORCPT + 99 others); Tue, 14 Jul 2020 08:02:20 -0400 Received: from mail-il-dmz.mellanox.com ([193.47.165.129]:52586 "EHLO mellanox.co.il" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728087AbgGNMCO (ORCPT ); Tue, 14 Jul 2020 08:02:14 -0400 Received: from Internal Mail-Server by MTLPINE1 (envelope-from vadimp@mellanox.com) with SMTP; 14 Jul 2020 15:02:11 +0300 Received: from r-build-lowlevel.mtr.labs.mlnx. (r-build-lowlevel.mtr.labs.mlnx [10.209.0.190]) by labmailer.mlnx (8.13.8/8.13.8) with ESMTP id 06EC25dh004353; Tue, 14 Jul 2020 15:02:11 +0300 From: Vadim Pasternak To: andy@infradead.org, dvhart@infradead.org Cc: platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org, Vadim Pasternak Subject: [PATCH platform-next v2 04/11] platform/mellanox: mlxreg-hotplug: Use capability register for attribute creation Date: Tue, 14 Jul 2020 15:01:56 +0300 Message-Id: <20200714120203.10352-5-vadimp@mellanox.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20200714120203.10352-1-vadimp@mellanox.com> References: <20200714120203.10352-1-vadimp@mellanox.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Create the 'sysfs' attributes according to configuration provided through the capability register, which purpose is to indicate the actual number of the components within the particular group. Such components could be, for example the FAN or power supply units. The motivation is to avoid adding a new code in the future in order to distinct between the systems types supporting a different number of the components like power supplies, FANs, ASICs, line cards. Signed-off-by: Vadim Pasternak --- v1->v2: Comments pointed out by Andy: - Fix commit text. - Modify loop over unmasked units - use for_each_set_bit(). --- drivers/platform/mellanox/mlxreg-hotplug.c | 60 ++++++++++++++++++++---------- 1 file changed, 41 insertions(+), 19 deletions(-) diff --git a/drivers/platform/mellanox/mlxreg-hotplug.c b/drivers/platform/mellanox/mlxreg-hotplug.c index 19af2897ef75..d9863e7fd491 100644 --- a/drivers/platform/mellanox/mlxreg-hotplug.c +++ b/drivers/platform/mellanox/mlxreg-hotplug.c @@ -173,17 +173,49 @@ static int mlxreg_hotplug_attr_init(struct mlxreg_hotplug_priv_data *priv) struct mlxreg_core_hotplug_platform_data *pdata; struct mlxreg_core_item *item; struct mlxreg_core_data *data; - int num_attrs = 0, id = 0, i, j; + unsigned long mask; + u32 regval; + int num_attrs = 0, id = 0, i, j, k, ret; pdata = dev_get_platdata(&priv->pdev->dev); item = pdata->items; /* Go over all kinds of items - psu, pwr, fan. */ for (i = 0; i < pdata->counter; i++, item++) { - num_attrs += item->count; + if (item->capability) { + /* + * Read group capability register to get actual number + * of interrupt capable components and set group mask + * accordingly. + */ + ret = regmap_read(priv->regmap, item->capability, + ®val); + if (ret) + return ret; + + item->mask = GENMASK((regval & item->mask) - 1, 0); + } + data = item->data; - /* Go over all units within the item. */ - for (j = 0; j < item->count; j++, data++, id++) { + + /* Go over all unmasked units within item. */ + mask = item->mask; + k = 0; + for_each_set_bit(j, &mask, item->count) { + if (data->capability) { + /* + * Read capability register and skip non + * relevant attributes. + */ + ret = regmap_read(priv->regmap, + data->capability, ®val); + 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, @@ -201,9 +233,13 @@ static int mlxreg_hotplug_attr_init(struct mlxreg_hotplug_priv_data *priv) PRIV_DEV_ATTR(id).dev_attr.show = mlxreg_hotplug_attr_show; PRIV_DEV_ATTR(id).nr = i; - PRIV_DEV_ATTR(id).index = j; + PRIV_DEV_ATTR(id).index = k; sysfs_attr_init(&PRIV_DEV_ATTR(id).dev_attr.attr); + data++; + id++; + k++; } + num_attrs += k; } priv->group.attrs = devm_kcalloc(&priv->pdev->dev, @@ -481,20 +517,6 @@ static int mlxreg_hotplug_set_irq(struct mlxreg_hotplug_priv_data *priv) item = pdata->items; for (i = 0; i < pdata->counter; i++, item++) { - if (item->capability) { - /* - * Read group capability register to get actual number - * of interrupt capable components and set group mask - * accordingly. - */ - ret = regmap_read(priv->regmap, item->capability, - ®val); - if (ret) - goto out; - - item->mask = GENMASK((regval & item->mask) - 1, 0); - } - /* Clear group presense event. */ ret = regmap_write(priv->regmap, item->reg + MLXREG_HOTPLUG_EVENT_OFF, 0); -- 2.11.0