Skip to content

Commit 0a43f7b

Browse files
mellanoxbmcandy-shev
authored andcommitted
platform/mellanox: mlxreg-hotplug: Use capability register for attribute creation
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 <[email protected]> Signed-off-by: Andy Shevchenko <[email protected]>
1 parent 5272d4e commit 0a43f7b

File tree

1 file changed

+41
-19
lines changed

1 file changed

+41
-19
lines changed

drivers/platform/mellanox/mlxreg-hotplug.c

Lines changed: 41 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -173,17 +173,49 @@ static int mlxreg_hotplug_attr_init(struct mlxreg_hotplug_priv_data *priv)
173173
struct mlxreg_core_hotplug_platform_data *pdata;
174174
struct mlxreg_core_item *item;
175175
struct mlxreg_core_data *data;
176-
int num_attrs = 0, id = 0, i, j;
176+
unsigned long mask;
177+
u32 regval;
178+
int num_attrs = 0, id = 0, i, j, k, ret;
177179

178180
pdata = dev_get_platdata(&priv->pdev->dev);
179181
item = pdata->items;
180182

181183
/* Go over all kinds of items - psu, pwr, fan. */
182184
for (i = 0; i < pdata->counter; i++, item++) {
183-
num_attrs += item->count;
185+
if (item->capability) {
186+
/*
187+
* Read group capability register to get actual number
188+
* of interrupt capable components and set group mask
189+
* accordingly.
190+
*/
191+
ret = regmap_read(priv->regmap, item->capability,
192+
&regval);
193+
if (ret)
194+
return ret;
195+
196+
item->mask = GENMASK((regval & item->mask) - 1, 0);
197+
}
198+
184199
data = item->data;
185-
/* Go over all units within the item. */
186-
for (j = 0; j < item->count; j++, data++, id++) {
200+
201+
/* Go over all unmasked units within item. */
202+
mask = item->mask;
203+
k = 0;
204+
for_each_set_bit(j, &mask, item->count) {
205+
if (data->capability) {
206+
/*
207+
* Read capability register and skip non
208+
* relevant attributes.
209+
*/
210+
ret = regmap_read(priv->regmap,
211+
data->capability, &regval);
212+
if (ret)
213+
return ret;
214+
if (!(regval & data->bit)) {
215+
data++;
216+
continue;
217+
}
218+
}
187219
PRIV_ATTR(id) = &PRIV_DEV_ATTR(id).dev_attr.attr;
188220
PRIV_ATTR(id)->name = devm_kasprintf(&priv->pdev->dev,
189221
GFP_KERNEL,
@@ -201,9 +233,13 @@ static int mlxreg_hotplug_attr_init(struct mlxreg_hotplug_priv_data *priv)
201233
PRIV_DEV_ATTR(id).dev_attr.show =
202234
mlxreg_hotplug_attr_show;
203235
PRIV_DEV_ATTR(id).nr = i;
204-
PRIV_DEV_ATTR(id).index = j;
236+
PRIV_DEV_ATTR(id).index = k;
205237
sysfs_attr_init(&PRIV_DEV_ATTR(id).dev_attr.attr);
238+
data++;
239+
id++;
240+
k++;
206241
}
242+
num_attrs += k;
207243
}
208244

209245
priv->group.attrs = devm_kcalloc(&priv->pdev->dev,
@@ -481,20 +517,6 @@ static int mlxreg_hotplug_set_irq(struct mlxreg_hotplug_priv_data *priv)
481517
item = pdata->items;
482518

483519
for (i = 0; i < pdata->counter; i++, item++) {
484-
if (item->capability) {
485-
/*
486-
* Read group capability register to get actual number
487-
* of interrupt capable components and set group mask
488-
* accordingly.
489-
*/
490-
ret = regmap_read(priv->regmap, item->capability,
491-
&regval);
492-
if (ret)
493-
goto out;
494-
495-
item->mask = GENMASK((regval & item->mask) - 1, 0);
496-
}
497-
498520
/* Clear group presense event. */
499521
ret = regmap_write(priv->regmap, item->reg +
500522
MLXREG_HOTPLUG_EVENT_OFF, 0);

0 commit comments

Comments
 (0)