Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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/cover.1720447210.git.petrm@nvidia.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

+35 -26
+25 -26
drivers/net/ethernet/mellanox/mlxsw/core_thermal.c
··· 100 100 101 101 struct mlxsw_thermal; 102 102 103 + struct mlxsw_thermal_cooling_device { 104 + struct mlxsw_thermal *thermal; 105 + struct thermal_cooling_device *cdev; 106 + unsigned int idx; 107 + }; 108 + 103 109 struct mlxsw_thermal_module { 104 110 struct mlxsw_thermal *parent; 105 111 struct thermal_zone_device *tzdev; ··· 129 123 const struct mlxsw_bus_info *bus_info; 130 124 struct thermal_zone_device *tzdev; 131 125 int polling_delay; 132 - struct thermal_cooling_device *cdevs[MLXSW_MFCR_PWMS_MAX]; 126 + struct mlxsw_thermal_cooling_device cdevs[MLXSW_MFCR_PWMS_MAX]; 133 127 struct thermal_trip trips[MLXSW_THERMAL_NUM_TRIPS]; 134 128 struct mlxsw_cooling_states cooling_states[MLXSW_THERMAL_NUM_TRIPS]; 135 129 struct mlxsw_thermal_area line_cards[]; ··· 153 147 int i; 154 148 155 149 for (i = 0; i < MLXSW_MFCR_PWMS_MAX; i++) 156 - if (thermal->cdevs[i] == cdev) 150 + if (thermal->cdevs[i].cdev == cdev) 157 151 return i; 158 152 159 153 /* Allow mlxsw thermal zone binding to an external cooling device */ ··· 358 352 unsigned long *p_state) 359 353 360 354 { 361 - struct mlxsw_thermal *thermal = cdev->devdata; 355 + struct mlxsw_thermal_cooling_device *mlxsw_cdev = cdev->devdata; 356 + struct mlxsw_thermal *thermal = mlxsw_cdev->thermal; 362 357 struct device *dev = thermal->bus_info->dev; 363 358 char mfsc_pl[MLXSW_REG_MFSC_LEN]; 364 - int err, idx; 365 359 u8 duty; 360 + int err; 366 361 367 - idx = mlxsw_get_cooling_device_idx(thermal, cdev); 368 - if (idx < 0) 369 - return idx; 370 - 371 - mlxsw_reg_mfsc_pack(mfsc_pl, idx, 0); 362 + mlxsw_reg_mfsc_pack(mfsc_pl, mlxsw_cdev->idx, 0); 372 363 err = mlxsw_reg_query(thermal->core, MLXSW_REG(mfsc), mfsc_pl); 373 364 if (err) { 374 365 dev_err(dev, "Failed to query PWM duty\n"); ··· 381 378 unsigned long state) 382 379 383 380 { 384 - struct mlxsw_thermal *thermal = cdev->devdata; 381 + struct mlxsw_thermal_cooling_device *mlxsw_cdev = cdev->devdata; 382 + struct mlxsw_thermal *thermal = mlxsw_cdev->thermal; 385 383 struct device *dev = thermal->bus_info->dev; 386 384 char mfsc_pl[MLXSW_REG_MFSC_LEN]; 387 - int idx; 388 385 int err; 389 386 390 387 if (state > MLXSW_THERMAL_MAX_STATE) 391 388 return -EINVAL; 392 389 393 - idx = mlxsw_get_cooling_device_idx(thermal, cdev); 394 - if (idx < 0) 395 - return idx; 396 - 397 390 /* Normalize the state to the valid speed range. */ 398 391 state = max_t(unsigned long, MLXSW_THERMAL_MIN_STATE, state); 399 - mlxsw_reg_mfsc_pack(mfsc_pl, idx, mlxsw_state_to_duty(state)); 392 + mlxsw_reg_mfsc_pack(mfsc_pl, mlxsw_cdev->idx, 393 + mlxsw_state_to_duty(state)); 400 394 err = mlxsw_reg_write(thermal->core, MLXSW_REG(mfsc), mfsc_pl); 401 395 if (err) { 402 396 dev_err(dev, "Failed to write PWM duty\n"); ··· 753 753 } 754 754 for (i = 0; i < MLXSW_MFCR_PWMS_MAX; i++) { 755 755 if (pwm_active & BIT(i)) { 756 + struct mlxsw_thermal_cooling_device *mlxsw_cdev; 756 757 struct thermal_cooling_device *cdev; 757 758 759 + mlxsw_cdev = &thermal->cdevs[i]; 760 + mlxsw_cdev->thermal = thermal; 761 + mlxsw_cdev->idx = i; 758 762 cdev = thermal_cooling_device_register("mlxsw_fan", 759 - thermal, 763 + mlxsw_cdev, 760 764 &mlxsw_cooling_ops); 761 765 if (IS_ERR(cdev)) { 762 766 err = PTR_ERR(cdev); 763 767 dev_err(dev, "Failed to register cooling device\n"); 764 768 goto err_thermal_cooling_device_register; 765 769 } 766 - thermal->cdevs[i] = cdev; 770 + mlxsw_cdev->cdev = cdev; 767 771 } 768 772 } 769 773 ··· 828 824 err_thermal_zone_device_register: 829 825 err_thermal_cooling_device_register: 830 826 for (i = 0; i < MLXSW_MFCR_PWMS_MAX; i++) 831 - if (thermal->cdevs[i]) 832 - thermal_cooling_device_unregister(thermal->cdevs[i]); 827 + thermal_cooling_device_unregister(thermal->cdevs[i].cdev); 833 828 err_reg_write: 834 829 err_reg_query: 835 830 kfree(thermal); ··· 850 847 thermal->tzdev = NULL; 851 848 } 852 849 853 - for (i = 0; i < MLXSW_MFCR_PWMS_MAX; i++) { 854 - if (thermal->cdevs[i]) { 855 - thermal_cooling_device_unregister(thermal->cdevs[i]); 856 - thermal->cdevs[i] = NULL; 857 - } 858 - } 850 + for (i = 0; i < MLXSW_MFCR_PWMS_MAX; i++) 851 + thermal_cooling_device_unregister(thermal->cdevs[i].cdev); 859 852 860 853 kfree(thermal); 861 854 }
+4
drivers/net/ethernet/mellanox/mlxsw/item.h
··· 218 218 } 219 219 220 220 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; 221 225 be_index = max_index - index; 222 226 offset = be_index * item->element_size >> 3; 223 227 in_byte_index = index % (BITS_PER_BYTE / item->element_size);
+6
drivers/net/ethernet/mellanox/mlxsw/pci.c
··· 1784 1784 { 1785 1785 struct pci_dev *pdev = mlxsw_pci->pdev; 1786 1786 char mrsr_pl[MLXSW_REG_MRSR_LEN]; 1787 + struct pci_dev *bridge; 1787 1788 int err; 1788 1789 1789 1790 if (!pci_reset_sbr_supported) { ··· 1801 1800 sbr: 1802 1801 device_lock_assert(&pdev->dev); 1803 1802 1803 + bridge = pci_upstream_bridge(pdev); 1804 + if (bridge) 1805 + pci_cfg_access_lock(bridge); 1804 1806 pci_cfg_access_lock(pdev); 1805 1807 pci_save_state(pdev); 1806 1808 ··· 1813 1809 1814 1810 pci_restore_state(pdev); 1815 1811 pci_cfg_access_unlock(pdev); 1812 + if (bridge) 1813 + pci_cfg_access_unlock(bridge); 1816 1814 1817 1815 return err; 1818 1816 }