Skip to content

Commit 8ce2ddd

Browse files
committed
Merge branch 'mlxsw-improvements'
Petr Machata says: ==================== mlxsw: Improvements This patchset contains assortments of improvements to the mlxsw driver. Please see individual patches for details. ==================== Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
2 parents 746d684 + 0970836 commit 8ce2ddd

File tree

3 files changed

+35
-26
lines changed

3 files changed

+35
-26
lines changed

drivers/net/ethernet/mellanox/mlxsw/core_thermal.c

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,12 @@ static const struct mlxsw_cooling_states default_cooling_states[] = {
100100

101101
struct mlxsw_thermal;
102102

103+
struct mlxsw_thermal_cooling_device {
104+
struct mlxsw_thermal *thermal;
105+
struct thermal_cooling_device *cdev;
106+
unsigned int idx;
107+
};
108+
103109
struct mlxsw_thermal_module {
104110
struct mlxsw_thermal *parent;
105111
struct thermal_zone_device *tzdev;
@@ -123,7 +129,7 @@ struct mlxsw_thermal {
123129
const struct mlxsw_bus_info *bus_info;
124130
struct thermal_zone_device *tzdev;
125131
int polling_delay;
126-
struct thermal_cooling_device *cdevs[MLXSW_MFCR_PWMS_MAX];
132+
struct mlxsw_thermal_cooling_device cdevs[MLXSW_MFCR_PWMS_MAX];
127133
struct thermal_trip trips[MLXSW_THERMAL_NUM_TRIPS];
128134
struct mlxsw_cooling_states cooling_states[MLXSW_THERMAL_NUM_TRIPS];
129135
struct mlxsw_thermal_area line_cards[];
@@ -147,7 +153,7 @@ static int mlxsw_get_cooling_device_idx(struct mlxsw_thermal *thermal,
147153
int i;
148154

149155
for (i = 0; i < MLXSW_MFCR_PWMS_MAX; i++)
150-
if (thermal->cdevs[i] == cdev)
156+
if (thermal->cdevs[i].cdev == cdev)
151157
return i;
152158

153159
/* Allow mlxsw thermal zone binding to an external cooling device */
@@ -352,17 +358,14 @@ static int mlxsw_thermal_get_cur_state(struct thermal_cooling_device *cdev,
352358
unsigned long *p_state)
353359

354360
{
355-
struct mlxsw_thermal *thermal = cdev->devdata;
361+
struct mlxsw_thermal_cooling_device *mlxsw_cdev = cdev->devdata;
362+
struct mlxsw_thermal *thermal = mlxsw_cdev->thermal;
356363
struct device *dev = thermal->bus_info->dev;
357364
char mfsc_pl[MLXSW_REG_MFSC_LEN];
358-
int err, idx;
359365
u8 duty;
366+
int err;
360367

361-
idx = mlxsw_get_cooling_device_idx(thermal, cdev);
362-
if (idx < 0)
363-
return idx;
364-
365-
mlxsw_reg_mfsc_pack(mfsc_pl, idx, 0);
368+
mlxsw_reg_mfsc_pack(mfsc_pl, mlxsw_cdev->idx, 0);
366369
err = mlxsw_reg_query(thermal->core, MLXSW_REG(mfsc), mfsc_pl);
367370
if (err) {
368371
dev_err(dev, "Failed to query PWM duty\n");
@@ -378,22 +381,19 @@ static int mlxsw_thermal_set_cur_state(struct thermal_cooling_device *cdev,
378381
unsigned long state)
379382

380383
{
381-
struct mlxsw_thermal *thermal = cdev->devdata;
384+
struct mlxsw_thermal_cooling_device *mlxsw_cdev = cdev->devdata;
385+
struct mlxsw_thermal *thermal = mlxsw_cdev->thermal;
382386
struct device *dev = thermal->bus_info->dev;
383387
char mfsc_pl[MLXSW_REG_MFSC_LEN];
384-
int idx;
385388
int err;
386389

387390
if (state > MLXSW_THERMAL_MAX_STATE)
388391
return -EINVAL;
389392

390-
idx = mlxsw_get_cooling_device_idx(thermal, cdev);
391-
if (idx < 0)
392-
return idx;
393-
394393
/* Normalize the state to the valid speed range. */
395394
state = max_t(unsigned long, MLXSW_THERMAL_MIN_STATE, state);
396-
mlxsw_reg_mfsc_pack(mfsc_pl, idx, mlxsw_state_to_duty(state));
395+
mlxsw_reg_mfsc_pack(mfsc_pl, mlxsw_cdev->idx,
396+
mlxsw_state_to_duty(state));
397397
err = mlxsw_reg_write(thermal->core, MLXSW_REG(mfsc), mfsc_pl);
398398
if (err) {
399399
dev_err(dev, "Failed to write PWM duty\n");
@@ -753,17 +753,21 @@ int mlxsw_thermal_init(struct mlxsw_core *core,
753753
}
754754
for (i = 0; i < MLXSW_MFCR_PWMS_MAX; i++) {
755755
if (pwm_active & BIT(i)) {
756+
struct mlxsw_thermal_cooling_device *mlxsw_cdev;
756757
struct thermal_cooling_device *cdev;
757758

759+
mlxsw_cdev = &thermal->cdevs[i];
760+
mlxsw_cdev->thermal = thermal;
761+
mlxsw_cdev->idx = i;
758762
cdev = thermal_cooling_device_register("mlxsw_fan",
759-
thermal,
763+
mlxsw_cdev,
760764
&mlxsw_cooling_ops);
761765
if (IS_ERR(cdev)) {
762766
err = PTR_ERR(cdev);
763767
dev_err(dev, "Failed to register cooling device\n");
764768
goto err_thermal_cooling_device_register;
765769
}
766-
thermal->cdevs[i] = cdev;
770+
mlxsw_cdev->cdev = cdev;
767771
}
768772
}
769773

@@ -824,8 +828,7 @@ int mlxsw_thermal_init(struct mlxsw_core *core,
824828
err_thermal_zone_device_register:
825829
err_thermal_cooling_device_register:
826830
for (i = 0; i < MLXSW_MFCR_PWMS_MAX; i++)
827-
if (thermal->cdevs[i])
828-
thermal_cooling_device_unregister(thermal->cdevs[i]);
831+
thermal_cooling_device_unregister(thermal->cdevs[i].cdev);
829832
err_reg_write:
830833
err_reg_query:
831834
kfree(thermal);
@@ -847,12 +850,8 @@ void mlxsw_thermal_fini(struct mlxsw_thermal *thermal)
847850
thermal->tzdev = NULL;
848851
}
849852

850-
for (i = 0; i < MLXSW_MFCR_PWMS_MAX; i++) {
851-
if (thermal->cdevs[i]) {
852-
thermal_cooling_device_unregister(thermal->cdevs[i]);
853-
thermal->cdevs[i] = NULL;
854-
}
855-
}
853+
for (i = 0; i < MLXSW_MFCR_PWMS_MAX; i++)
854+
thermal_cooling_device_unregister(thermal->cdevs[i].cdev);
856855

857856
kfree(thermal);
858857
}

drivers/net/ethernet/mellanox/mlxsw/item.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,10 @@ __mlxsw_item_bit_array_offset(const struct mlxsw_item *item,
218218
}
219219

220220
max_index = (item->size.bytes << 3) / item->element_size - 1;
221+
if (WARN_ONCE(index > max_index,
222+
"name=%s,index=%u,max_index=%u\n", item->name, index,
223+
max_index))
224+
index = 0;
221225
be_index = max_index - index;
222226
offset = be_index * item->element_size >> 3;
223227
in_byte_index = index % (BITS_PER_BYTE / item->element_size);

drivers/net/ethernet/mellanox/mlxsw/pci.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1784,6 +1784,7 @@ static int mlxsw_pci_reset_at_pci_disable(struct mlxsw_pci *mlxsw_pci,
17841784
{
17851785
struct pci_dev *pdev = mlxsw_pci->pdev;
17861786
char mrsr_pl[MLXSW_REG_MRSR_LEN];
1787+
struct pci_dev *bridge;
17871788
int err;
17881789

17891790
if (!pci_reset_sbr_supported) {
@@ -1800,6 +1801,9 @@ static int mlxsw_pci_reset_at_pci_disable(struct mlxsw_pci *mlxsw_pci,
18001801
sbr:
18011802
device_lock_assert(&pdev->dev);
18021803

1804+
bridge = pci_upstream_bridge(pdev);
1805+
if (bridge)
1806+
pci_cfg_access_lock(bridge);
18031807
pci_cfg_access_lock(pdev);
18041808
pci_save_state(pdev);
18051809

@@ -1809,6 +1813,8 @@ static int mlxsw_pci_reset_at_pci_disable(struct mlxsw_pci *mlxsw_pci,
18091813

18101814
pci_restore_state(pdev);
18111815
pci_cfg_access_unlock(pdev);
1816+
if (bridge)
1817+
pci_cfg_access_unlock(bridge);
18121818

18131819
return err;
18141820
}

0 commit comments

Comments
 (0)