Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp326604ybg; Mon, 1 Jun 2020 02:22:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyoatP8hmZYhOHvSGKO4u1DAH/4NCVj5A2gXBPbk5fw/NGg79McBGp19/MbA7S7YEGFJqFV X-Received: by 2002:a17:906:d043:: with SMTP id bo3mr17946663ejb.409.1591003335589; Mon, 01 Jun 2020 02:22:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591003335; cv=none; d=google.com; s=arc-20160816; b=LVPhnCtZplpbYeiY76qhfE1afMiFSBTwN4poD4qTdn14pVA9HJxOzRxwIhvxWlv/T7 jflAeIzawV+iEaShsyqpD880O19UVAKMHr+tccJfsB4imcWNwqKt12hHXYK9GvD1DBfc 6zp2blXQKsXZbW+2V2bKdxm3Rs9pIpCFuQ6fgsv1Cq5FludA18ObELcQ8Q32mcDG+s+u /0PlriHTTkeRPiy8hboqLnJmB9xhUwqfWz1kSfDi7yPdBhoVSD2Dap35ICVulp04WMQJ 4Rg2EhgvfgQipyHGI32fmKdd1ZRP0LrQOP5vXLaM7ITbnONpJsDhgoN5ny8AbbcbpFzv tdJw== 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=zyAKvUVowlu3RQBCpmkV1YWZupwErQ3XMX8Ew2KT1Jo=; b=NLrq9Kb2/quQpW7RCd6iTOFMo9LXHLxb+Q2rp/h7D2TT5NIJEKamOnXqK7qfgxms8N MX2G1O38iQtKuEZO73eaj/cgq9s/GVgIaFllx8H3yaIQ9mHO0HGsRPeCwdn+9y2vEhwe Ppsh3cB/zamn4srW74V282NlUhgVjuVYOlHKfTZuc9IQFTzrnk9WjGRPe8JTbUP/zTBc PCTruKHDV5jrN24SeTK9AxQXtlejgft4HIOJ4Wen6ThHVur0A7GIbAs4ER2I4a3nTr5J 44vQ+PNit8o1Ipc34W8fUq/L2dgN2e27YtNJNYEJw0d0GpWV0zOBCScPVpltH5tkVwTR yUZg== 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 y19si3409796edm.534.2020.06.01.02.21.53; Mon, 01 Jun 2020 02:22: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 S1726201AbgFAJTF (ORCPT + 99 others); Mon, 1 Jun 2020 05:19:05 -0400 Received: from mail-il-dmz.mellanox.com ([193.47.165.129]:51530 "EHLO mellanox.co.il" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725976AbgFAJTC (ORCPT ); Mon, 1 Jun 2020 05:19:02 -0400 Received: from Internal Mail-Server by MTLPINE2 (envelope-from vadimp@mellanox.com) with ESMTPS (AES256-SHA encrypted); 1 Jun 2020 12:18:57 +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 0519IsSp003135; Mon, 1 Jun 2020 12:18:57 +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 v1 1/8] platform/mellanox: mlxreg-hotplug: Use capability register for attribute creation Date: Mon, 1 Jun 2020 12:18:44 +0300 Message-Id: <20200601091851.5491-2-vadimp@mellanox.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20200601091851.5491-1-vadimp@mellanox.com> References: <20200601091851.5491-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 supported different number of the components like power supplies, FANs, ASICs, line cards. Signed-off-by: Vadim Pasternak --- drivers/platform/mellanox/mlxreg-hotplug.c | 54 ++++++++++++++++++++---------- 1 file changed, 36 insertions(+), 18 deletions(-) diff --git a/drivers/platform/mellanox/mlxreg-hotplug.c b/drivers/platform/mellanox/mlxreg-hotplug.c index 77be37a1fbcf..832fcf282d45 100644 --- a/drivers/platform/mellanox/mlxreg-hotplug.c +++ b/drivers/platform/mellanox/mlxreg-hotplug.c @@ -196,17 +196,46 @@ 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; + 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++) { + for (j = 0, k = 0; j < item->count; j++, data++) { + /* Skip if bit in mask is not set. */ + if (!(item->mask & BIT(j))) + continue; + 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)) + continue; + } PRIV_ATTR(id) = &PRIV_DEV_ATTR(id).dev_attr.attr; PRIV_ATTR(id)->name = devm_kasprintf(&priv->pdev->dev, GFP_KERNEL, @@ -224,9 +253,12 @@ 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); + id++; + k++; } + num_attrs += k; } priv->group.attrs = devm_kcalloc(&priv->pdev->dev, @@ -504,20 +536,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