Raspberry Pi 4 PCIe support
Subsystems (36)
v4 cover Raspberry Pi 4 PCIe support
This series aims at providing support for Raspberry Pi 4's PCIe controller, which is also shared with the Broadcom STB family of devices.
There was a previous attempt to upstream this some years ago[1] but was blocked as most STB PCIe integrations have a sparse DMA mapping[2] which is something currently not supported by the kernel. Luckily this is not the case for the Raspberry Pi 4.
Note that the driver code is to be based on top of Rob Herring's series simplifying inbound and outbound range parsing.
[1] https://patchwork.kernel.org/cover/10605933/
[2] https://patchwork.kernel.org/patch/10605957/
---
Changes since v3:
- Moved all the log2.h related changes at the end of the series, as I presume they will be contentious and I don't want the PCIe patches to depend on them. Ultimately I think I'll respin them on their own series but wanted to keep them in for this submission just for the sake of continuity.
- Addressed small nits here and there.
Changes since v2:
- Redo register access in driver avoiding indirection while keeping the naming intact
- Add patch editing ARM64's config
- Last MSI cleanups, notably removing MSIX flag
- Got rid of all _RB writes
- Got rid of all of_data
- Overall churn removal
- Address the rest of Andrew's comments
Changes since v1:
- add generic rounddown/roundup_pow_two64() patch
- Add MAINTAINERS patch
- Fix Kconfig
- Cleanup probe, use up to date APIs, exit on MSI failure
- Get rid of linux,pci-domain and other unused constructs
- Use edge triggered setup for MSI
- Cleanup MSI implementation
- Fix multiple cosmetic issues
- Remove supend/resume code
Jim Quinlan (3):
dt-bindings: PCI: Add bindings for brcmstb's PCIe device
PCI: brcmstb: Add Broadcom STB PCIe host controller driver
PCI: brcmstb: Add MSI support
Nicolas Saenz Julienne (5):
ARM: dts: bcm2711: Enable PCIe controller
MAINTAINERS: Add brcmstb PCIe controller
arm64: defconfig: Enable Broadcom's STB PCIe controller linux/log2.h: Fix 64bit calculations in roundup/down_pow_two() linux/log2.h: Use roundup/dow_pow_two() on 64bit calculations
.../bindings/pci/brcm,stb-pcie.yaml | 97 ++ MAINTAINERS | 4 + arch/arm/boot/dts/bcm2711.dtsi | 37 + arch/arm64/configs/defconfig | 1 + drivers/acpi/arm64/iort.c | 2 +- drivers/clk/clk-divider.c | 8 +- drivers/clk/sunxi/clk-sunxi.c | 2 +- drivers/infiniband/hw/hfi1/chip.c | 4 +- drivers/infiniband/hw/hfi1/init.c | 4 +- drivers/infiniband/hw/mlx4/srq.c | 2 +- drivers/infiniband/hw/mthca/mthca_srq.c | 2 +- drivers/infiniband/sw/rxe/rxe_qp.c | 4 +- drivers/iommu/intel-iommu.c | 4 +- drivers/iommu/intel-svm.c | 4 +- drivers/iommu/intel_irq_remapping.c | 2 +- drivers/net/ethernet/amd/xgbe/xgbe-ethtool.c | 4 +- drivers/net/ethernet/marvell/sky2.c | 2 +- drivers/net/ethernet/mellanox/mlx4/en_clock.c | 3 +- drivers/net/ethernet/rocker/rocker_hw.h | 4 +- drivers/net/ethernet/sfc/ef10.c | 2 +- drivers/net/ethernet/sfc/efx.h | 2 +- drivers/net/ethernet/sfc/falcon/efx.h | 2 +- drivers/of/device.c | 3 +- drivers/pci/controller/Kconfig | 9 + drivers/pci/controller/Makefile | 1 + .../pci/controller/cadence/pcie-cadence-ep.c | 3 +- drivers/pci/controller/cadence/pcie-cadence.c | 3 +- drivers/pci/controller/pcie-brcmstb.c | 1008 +++++++++++++++++ drivers/pci/controller/pcie-rockchip-ep.c | 5 +- drivers/pci/msi.c | 2 +- include/linux/log2.h | 44 +- kernel/dma/direct.c | 2 +- kernel/kexec_core.c | 3 +- lib/rhashtable.c | 2 +- net/sunrpc/xprtrdma/verbs.c | 2 +- 35 files changed, 1211 insertions(+), 72 deletions(-) create mode 100644 Documentation/devicetree/bindings/pci/brcm,stb-pcie.yaml create mode 100644 drivers/pci/controller/pcie-brcmstb.c
Signature · 7 lines
2.24.0 _______________________________________________ kexec mailing list [email protected] http://lists.infradead.org/mailman/listinfo/kexec
PATCH v4 1/8 dt-bindings: PCI: Add bindings for brcmstb's PCIe device
From: Jim Quinlan <[email protected]>
The DT bindings description of the brcmstb PCIe device is described. This node can only be used for now on the Raspberry Pi 4.
---
Changes since v2:
- Add pci reference schema
- Drop all default properties
- Assume msi-controller and msi-parent are properly defined
- Add num entries on multiple properties
- use unevaluatedProperties
- Update required properties
- Fix license
Changes since v1:
- Fix commit Subject
- Remove linux,pci-domain
This was based on Jim's original submission[1], converted to yaml and adapted to the RPi4 case.
[1] https://patchwork.kernel.org/patch/10605937/
.../bindings/pci/brcm,stb-pcie.yaml | 97 +++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 Documentation/devicetree/bindings/pci/brcm,stb-pcie.yaml
Documentation/devicetree/bindings/pci/brcm,stb-pcie.yaml new file +97 -0
@@ -0,0 +1,97 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/pci/brcm,stb-pcie.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Brcmstb PCIe Host Controller Device Tree Bindings + +maintainers: + - Nicolas Saenz Julienne <[email protected]> + +allOf: + - $ref: /schemas/pci/pci-bus.yaml# + +properties: + compatible: + const: brcm,bcm2711-pcie # The Raspberry Pi 4 + + reg: + maxItems: 1 + + interrupts: + minItems: 1 + maxItems: 2 + items: + - description: PCIe host controller + - description: builtin MSI controller + + interrupt-names: + minItems: 1 + maxItems: 2 + items: + - const: pcie + - const: msi + + ranges: + maxItems: 1 + + dma-ranges: + maxItems: 1 + + clocks: + maxItems: 1 + + clock-names: + items: + - const: sw_pcie + + msi-controller: + description: Identifies the node as an MSI controller. + + msi-parent: + description: MSI controller the device is capable of using. + + brcm,enable-ssc: + description: Indicates usage of spread-spectrum clocking. + type: boolean + +required: + - reg + - dma-ranges + - "#interrupt-cells" + - interrupts + - interrupt-names + - interrupt-map-mask + - interrupt-map + - msi-controller + +unevaluatedProperties: false + +examples: + - | + #include <dt-bindings/interrupt-controller/irq.h> + #include <dt-bindings/interrupt-controller/arm-gic.h> + + scb { + #address-cells = <2>; + #size-cells = <1>; + pcie0: pcie@7d500000 { + compatible = "brcm,bcm2711-pcie"; + reg = <0x0 0x7d500000 0x9310>; + device_type = "pci"; + #address-cells = <3>; + #size-cells = <2>; + #interrupt-cells = <1>; + interrupts = <GIC_SPI 148 IRQ_TYPE_LEVEL_HIGH>, + <GIC_SPI 148 IRQ_TYPE_LEVEL_HIGH>; + interrupt-names = "pcie", "msi"; + interrupt-map-mask = <0x0 0x0 0x0 0x7>; + interrupt-map = <0 0 0 1 &gicv2 GIC_SPI 143 IRQ_TYPE_LEVEL_HIGH>; + msi-parent = <&pcie0>; + msi-controller; + ranges = <0x02000000 0x0 0xf8000000 0x6 0x00000000 0x0 0x04000000>; + dma-ranges = <0x02000000 0x0 0x00000000 0x0 0x00000000 0x0 0x80000000>; + brcm,enable-ssc; + }; + };
Signature · 7 lines
2.24.0 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Re: [PATCH v4 1/8] dt-bindings: PCI: Add bindings for brcmstb's PCIe device
Quoted 11 lines · Nicolas Saenz Julienne
From: Jim Quinlan <[email protected]>
The DT bindings description of the brcmstb PCIe device is described. This node can only be used for now on the Raspberry Pi 4.
Signed-off-by Jim Quinlan <[email protected]>Co-developed-by Nicolas Saenz Julienne <[email protected]>Signed-off-by Nicolas Saenz Julienne <[email protected]>Reviewed-by Rob Herring <[email protected]>---
Quoted 129 lines
Changes since v2:
- Add pci reference schema
- Drop all default properties
- Assume msi-controller and msi-parent are properly defined
- Add num entries on multiple properties
- use unevaluatedProperties
- Update required properties
- Fix licenseChanges since v1:
- Fix commit Subject
- Remove linux,pci-domainThis was based on Jim's original submission[1], converted to yaml and adapted to the RPi4 case.
[1] https://patchwork.kernel.org/patch/10605937/
.../bindings/pci/brcm,stb-pcie.yaml | 97 +++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 Documentation/devicetree/bindings/pci/brcm,stb-pcie.yamlDocumentation/devicetree/bindings/pci/brcm,stb-pcie.yaml new file +97
-0@@ -0,0 +1,97 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/pci/brcm,stb-pcie.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Brcmstb PCIe Host Controller Device Tree Bindings + +maintainers: + - Nicolas Saenz Julienne <[email protected]> + +allOf: + - $ref: /schemas/pci/pci-bus.yaml# + +properties: + compatible: + const: brcm,bcm2711-pcie # The Raspberry Pi 4 + + reg: + maxItems: 1 + + interrupts: + minItems: 1 + maxItems: 2 + items: + - description: PCIe host controller + - description: builtin MSI controller + + interrupt-names: + minItems: 1 + maxItems: 2 + items: + - const: pcie + - const: msi + + ranges: + maxItems: 1 + + dma-ranges: + maxItems: 1 + + clocks: + maxItems: 1 + + clock-names: + items: + - const: sw_pcie + + msi-controller: + description: Identifies the node as an MSI controller. + + msi-parent: + description: MSI controller the device is capable of using. + + brcm,enable-ssc: + description: Indicates usage of spread-spectrum clocking. + type: boolean + +required: + - reg + - dma-ranges + - "#interrupt-cells" + - interrupts + - interrupt-names + - interrupt-map-mask + - interrupt-map + - msi-controller + +unevaluatedProperties: false + +examples: + - | + #include <dt-bindings/interrupt-controller/irq.h> + #include <dt-bindings/interrupt-controller/arm-gic.h> + + scb { + #address-cells = <2>; + #size-cells = <1>; + pcie0: pcie@7d500000 { + compatible = "brcm,bcm2711-pcie"; + reg = <0x0 0x7d500000 0x9310>; + device_type = "pci"; + #address-cells = <3>; + #size-cells = <2>; + #interrupt-cells = <1>; + interrupts = <GIC_SPI 148 IRQ_TYPE_LEVEL_HIGH>, + <GIC_SPI 148 IRQ_TYPE_LEVEL_HIGH>; + interrupt-names = "pcie", "msi"; + interrupt-map-mask = <0x0 0x0 0x0 0x7>; + interrupt-map = <0 0 0 1 &gicv2 GIC_SPI 143 IRQ_TYPE_LEVEL_HIGH>; + msi-parent = <&pcie0>; + msi-controller; + ranges = <0x02000000 0x0 0xf8000000 0x6 0x00000000 0x0 0x04000000>; + dma-ranges = <0x02000000 0x0 0x00000000 0x0 0x00000000 0x0 0x80000000>; + brcm,enable-ssc; + }; + };Signature · 1 line
2.24.0
PATCH v4 2/8 ARM: dts: bcm2711: Enable PCIe controller
In reply to Nicolas Saenz JulienneThis enables bcm2711's PCIe bus, which is hardwired to a VIA Technologies XHCI USB 3.0 controller.
---
Changes since v3:
- Remove unwarranted comment
Changes since v2:
- Remove unused interrupt-map
- correct dma-ranges to it's full size, non power of 2 bus DMA constraints now supported in linux-next[1]
- add device_type
- rename alias from pcie_0 to pcie0
Changes since v1:
- remove linux,pci-domain
arch/arm/boot/dts/bcm2711.dtsi | 37 ++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+)
arch/arm/boot/dts/bcm2711.dtsi +37 -0
@@ -288,6 +288,43 @@ IRQ_TYPE_LEVEL_LOW)>, arm,cpu-registers-not-fw-configured; }; + scb { + compatible = "simple-bus"; + #address-cells = <2>; + #size-cells = <1>; + + ranges = <0x0 0x7c000000 0x0 0xfc000000 0x03800000>, + <0x6 0x00000000 0x6 0x00000000 0x40000000>; + + pcie0: pcie@7d500000 { + compatible = "brcm,bcm2711-pcie"; + reg = <0x0 0x7d500000 0x9310>; + device_type = "pci"; + #address-cells = <3>; + #interrupt-cells = <1>; + #size-cells = <2>; + interrupts = <GIC_SPI 148 IRQ_TYPE_LEVEL_HIGH>, + <GIC_SPI 148 IRQ_TYPE_LEVEL_HIGH>; + interrupt-names = "pcie", "msi"; + interrupt-map-mask = <0x0 0x0 0x0 0x7>; + interrupt-map = <0 0 0 1 &gicv2 GIC_SPI 143 + IRQ_TYPE_LEVEL_HIGH>; + msi-controller; + msi-parent = <&pcie0>; + + ranges = <0x02000000 0x0 0xf8000000 0x6 0x00000000 + 0x0 0x04000000>; + /* + * The wrapper around the PCIe block has a bug + * preventing it from accessing beyond the first 3GB of + * memory. + */ + dma-ranges = <0x02000000 0x0 0x00000000 0x0 0x00000000 + 0x0 0xc0000000>; + brcm,enable-ssc; + }; + }; + cpus: cpus { #address-cells = <1>; #size-cells = <0>;
Signature · 1 line
2.24.0
Re: [PATCH v4 2/8] ARM: dts: bcm2711: Enable PCIe controller
Thanks for your effort! System can have USB with this patch series, if the device tree is modified properly.
Here is the question: Will not the device tree "scb/ranges" in this patch conflict with commit be8af7a9e3cc ("ARM: dts: bcm2711-rpi-4: Enable GENET support")?
Jian-Hong Pan
Re: [PATCH v4 2/8] ARM: dts: bcm2711: Enable PCIe controller
Hi Jian-Hong,
Quoted 1 line · Jian-Hong Pan
Thanks for your effort! System can have USB with this patch series, if the
:)
Quoted 4 lines
device tree is modified properly.
Here is the question: Will not the device tree "scb/ranges" in this patch conflict with commitbe8af7a9e3cc("ARM: dts: bcm2711-rpi-4: Enable GENET support")?
You're right, the patch needs to be refreshed.
I'm going to send a v5 of the series factoring out all the log2.h changes, and addressing this.
Regards,
Nicolas
PATCH v4 3/8 PCI: brcmstb: Add Broadcom STB PCIe host controller driver
In reply to Nicolas Saenz JulienneFrom: Jim Quinlan <[email protected]>
This adds a basic driver for Broadcom's STB PCIe controller, for now aimed at Raspberry Pi 4's SoC, bcm2711.
---
Changes since v3:
- Update commit message
- rollback roundup_pow_two usage, it'll be updated later down the line
- Remove comment in register definition
Changes since v2:
- Correct rc_bar2_offset sign
- Invert IRQ clear and masking in setup code
- Use bitfield.h, redo all register ops while keeping the register names intact
- Remove all SHIFT register definitions
- Get rid of all _RB writes
- Get rid of of_data
- Don't iterate over inexisting dma-ranges
- Add comment regarding dma-ranges validation
- Small cosmetic cleanups
- Fix license mismatch
- Set driver Kconfig tristate
- Didn't add any comment about the controller not being I/O coherent for now as I wait for Jeremy's reply
Changes since v1:
- Fix Kconfig
- Remove pci domain check
- Remove all MSI related code
- Remove supend/resume code
- Simplify link state wait routine
- Prefix all functions
- Use of_device_get_match_data()
- Use devm_clk_get_optional()
- Get rid of irq variable
- Use STB all over the driver
- Simplify map_bus() function
- Fix license mismatch
- Remove unused register definitions
- Small cleanups, spell errors
This is based on Jim's original submission[1] but adapted and tailored specifically to bcm2711's needs (that's the Raspberry Pi 4). Support for the rest of the brcmstb family will soon follow once we get support for multiple dma-ranges in dma/direct.
[1] https://patchwork.kernel.org/patch/10605959/
drivers/pci/controller/Kconfig | 8 + drivers/pci/controller/Makefile | 1 + drivers/pci/controller/pcie-brcmstb.c | 748 ++++++++++++++++++++++++++ 3 files changed, 757 insertions(+) create mode 100644 drivers/pci/controller/pcie-brcmstb.c
drivers/pci/controller/Kconfig +8 -0
@@ -253,6 +253,14 @@ config VMD To compile this driver as a module, choose M here: the module will be called vmd. +config PCIE_BRCMSTB + tristate "Broadcom Brcmstb PCIe host controller" + depends on ARCH_BCM2835 || COMPILE_TEST + depends on OF + help + Say Y here to enable PCIe host controller support for + Broadcom STB based SoCs, like the Raspberry Pi 4. + config PCI_HYPERV_INTERFACE tristate "Hyper-V PCI Interface" depends on X86 && HYPERV && PCI_MSI && PCI_MSI_IRQ_DOMAIN && X86_64
drivers/pci/controller/Makefile +1 -0
@@ -28,6 +28,7 @@ obj-$(CONFIG_PCIE_MEDIATEK) += pcie-mediatek.o obj-$(CONFIG_PCIE_MOBIVEIL) += pcie-mobiveil.o obj-$(CONFIG_PCIE_TANGO_SMP8759) += pcie-tango.o obj-$(CONFIG_VMD) += vmd.o +obj-$(CONFIG_PCIE_BRCMSTB) += pcie-brcmstb.o # pcie-hisi.o quirks are needed even without CONFIG_PCIE_DW obj-y += dwc/
drivers/pci/controller/pcie-brcmstb.c new file +748 -0
748 lines not on this page · raw message
Signature · 1 line
2.24.0
PATCH v4 4/8 PCI: brcmstb: Add MSI support
In reply to Nicolas Saenz JulienneFrom: Jim Quinlan <[email protected]>
This adds MSI support to the Broadcom STB PCIe host controller. The MSI controller is physically located within the PCIe block, however, there is no reason why the MSI controller could not be moved elsewhere in the future. MSIX is not supported by the HW.
Since the internal Brcmstb MSI controller is intertwined with the PCIe controller, it is not its own platform device but rather part of the PCIe platform device.
---
Changes since v3 (kept Marc's reviewed by as changes seem small enough):
- Use define to access MSI_DATA_CONFIG_VAL
- Update commit message
Changes since v2:
- Use standard APIs on register operations
- Get rid of revision code
- Update rules to msi_target_addr selection
- Remove unwarranted MSI_FLAG_PCI_MSIX
- Small cosmetic changes
Changes since v1:
- Move revision code and some registers to this patch
- Use PCIE_MSI_IRQ_DOMAIN in Kconfig
- Remove redundant register read from ISR
- Fail probe on MSI init error
- Get rid of msi_internal
- Use bitmap family of functions
- Use edge triggered setup
- Add comment regarding MultiMSI
- Simplify compose_msi_msg to avoid reg read
This is based on Jim's original submission[1] with some slight changes regarding how pcie->msi_target_addr is decided.
[1] https://patchwork.kernel.org/patch/10605955/
drivers/pci/controller/Kconfig | 1 + drivers/pci/controller/pcie-brcmstb.c | 261 +++++++++++++++++++++++++- 2 files changed, 261 insertions(+), 1 deletion(-)
drivers/pci/controller/Kconfig +1 -0
@@ -257,6 +257,7 @@ config PCIE_BRCMSTB tristate "Broadcom Brcmstb PCIe host controller" depends on ARCH_BCM2835 || COMPILE_TEST depends on OF + depends on PCI_MSI_IRQ_DOMAIN help Say Y here to enable PCIe host controller support for Broadcom STB based SoCs, like the Raspberry Pi 4.
drivers/pci/controller/pcie-brcmstb.c +260 -1
332 lines not on this page · raw message
Signature · 1 line
2.24.0
PATCH v4 5/8 MAINTAINERS: Add brcmstb PCIe controller
In reply to Nicolas Saenz JulienneThe controller serves both the Raspberry Pi 4 (bcm2711) and brcmstb platforms.
--- MAINTAINERS | 4 ++++ 1 file changed, 4 insertions(+)
MAINTAINERS +4 -0
@@ -3238,6 +3238,8 @@ S: Maintained N: bcm2711 N: bcm2835 F: drivers/staging/vc04_services +F: Documentation/devicetree/bindings/pci/brcm,stb-pcie.yaml +F: drivers/pci/controller/pcie-brcmstb.c BROADCOM BCM47XX MIPS ARCHITECTURE M: Hauke Mehrtens <[email protected]>
@@ -3293,6 +3295,8 @@ F: drivers/bus/brcmstb_gisb.c F: arch/arm/mm/cache-b15-rac.c F: arch/arm/include/asm/hardware/cache-b15-rac.h N: brcmstb +F: Documentation/devicetree/bindings/pci/brcm,stb-pcie.yaml +F: drivers/pci/controller/pcie-brcmstb.c BROADCOM BMIPS CPUFREQ DRIVER M: Markus Mayer <[email protected]>
Signature · 1 line
2.24.0
PATCH v4 6/8 arm64: defconfig: Enable Broadcom's STB PCIe controller
In reply to Nicolas Saenz JulienneFor now mainly used in the Raspberry Pi 4.
--- arch/arm64/configs/defconfig | 1 + 1 file changed, 1 insertion(+)
arch/arm64/configs/defconfig +1 -0
@@ -198,6 +198,7 @@ CONFIG_PCIE_ALTERA_MSI=y CONFIG_PCI_HOST_THUNDER_PEM=y CONFIG_PCI_HOST_THUNDER_ECAM=y CONFIG_PCIE_ROCKCHIP_HOST=m +CONFIG_PCIE_BRCMSTB=m CONFIG_PCI_LAYERSCAPE=y CONFIG_PCI_HISI=y CONFIG_PCIE_QCOM=y
Signature · 1 line
2.24.0
PATCH v4 7/8 linux/log2.h: Fix 64bit calculations in roundup/down_pow_two()
In reply to Nicolas Saenz JulienneSome users need to make sure their rounding function accepts and returns 64bit long variables regardless of the architecture. Sadly roundup/rounddown_pow_two() takes and returns unsigned longs. It turns out ilog2() already handles 32/64bit calculations properly, and being the building block to the round functions we can rework them as a wrapper around it.
--- drivers/clk/clk-divider.c | 8 ++-- drivers/clk/sunxi/clk-sunxi.c | 2 +- drivers/infiniband/hw/hfi1/chip.c | 4 +- drivers/infiniband/hw/hfi1/init.c | 4 +- drivers/infiniband/hw/mlx4/srq.c | 2 +- drivers/infiniband/hw/mthca/mthca_srq.c | 2 +- drivers/infiniband/sw/rxe/rxe_qp.c | 4 +- drivers/iommu/intel-iommu.c | 4 +- drivers/iommu/intel-svm.c | 4 +- drivers/iommu/intel_irq_remapping.c | 2 +- drivers/net/ethernet/amd/xgbe/xgbe-ethtool.c | 4 +- drivers/net/ethernet/marvell/sky2.c | 2 +- drivers/net/ethernet/rocker/rocker_hw.h | 4 +- drivers/net/ethernet/sfc/ef10.c | 2 +- drivers/net/ethernet/sfc/efx.h | 2 +- drivers/net/ethernet/sfc/falcon/efx.h | 2 +- drivers/pci/msi.c | 2 +- include/linux/log2.h | 44 +++++--------------- kernel/kexec_core.c | 3 +- lib/rhashtable.c | 2 +- net/sunrpc/xprtrdma/verbs.c | 2 +- 21 files changed, 41 insertions(+), 64 deletions(-)
drivers/clk/clk-divider.c +4 -4
@@ -222,7 +222,7 @@ static int _div_round_up(const struct clk_div_table *table,int div =DIV_ROUND_UP_ULL ((u64 )parent_rate, rate);if (flags &CLK_DIVIDER_POWER_OF_TWO ) - div =__roundup_pow_of_two (div); + div =roundup_pow_of_two (div);if (table) div =_round_up_table (table, div);
@@ -240,8 +240,8 @@ static int _div_round_closest(const struct clk_div_table *table, down = parent_rate / rate;if (flags &CLK_DIVIDER_POWER_OF_TWO ) { - up =__roundup_pow_of_two (up); - down =__rounddown_pow_of_two (down); + up =roundup_pow_of_two (up); + down =rounddown_pow_of_two (down); }else if (table) { up =_round_up_table (table, up); down =_round_down_table (table, down);
@@ -278,7 +278,7 @@ static int _next_div(const struct clk_div_table *table, int div, div++;if (flags &CLK_DIVIDER_POWER_OF_TWO ) -return __roundup_pow_of_two (div); +return roundup_pow_of_two (div);if (table)return _round_up_table (table, div);
drivers/clk/sunxi/clk-sunxi.c +1 -1
@@ -311,7 +311,7 @@ static void sun6i_get_ahb1_factors(struct factors_request *req) calcm =DIV_ROUND_UP (div,1 << calcp); }else { - calcp =__roundup_pow_of_two (div); + calcp =roundup_pow_of_two (div); calcp = calcp >3 ?3 : calcp; }
drivers/infiniband/hw/hfi1/chip.c +2 -2
@@ -14199,10 +14199,10 @@ static int qos_rmt_entries(struct hfi1_devdata *dd, unsigned int *mp, max_by_vl = krcvqs[i];if (max_by_vl >32 ) goto no_qos; - m =ilog2 (__roundup_pow_of_two (max_by_vl)); + m =ilog2 (roundup_pow_of_two (max_by_vl));/* determine bits for vl */ - n =ilog2 (__roundup_pow_of_two (num_vls)); + n =ilog2 (roundup_pow_of_two (num_vls));/* reject if too much is used */ if ((m + n) >7 )
drivers/infiniband/hw/hfi1/init.c +2 -2
@@ -467,7 +467,7 @@ int hfi1_create_ctxtdata(struct hfi1_pportdata *ppd, int numa,* MTU supported. */ if (rcd->egrbufs.size < hfi1_max_mtu) { - rcd->egrbufs.size =__roundup_pow_of_two (hfi1_max_mtu); + rcd->egrbufs.size =roundup_pow_of_two (hfi1_max_mtu);hfi1_cdbg (PROC ,"ctxt%u: eager bufs size too small. Adjusting to %u\n" , rcd->ctxt, rcd->egrbufs.size);
@@ -1959,7 +1959,7 @@ int hfi1_setup_eagerbufs(struct hfi1_ctxtdata *rcd)* to satisfy the "multiple of 8 RcvArray entries" requirement. */ if (rcd->egrbufs.size <= (1 <<20 )) - rcd->egrbufs.rcvtid_size =max ((unsigned long )round_mtu, + rcd->egrbufs.rcvtid_size =max ((unsigned long long )round_mtu,rounddown_pow_of_two (rcd->egrbufs.size /8 )); while (alloced_bytes < rcd->egrbufs.size &&
drivers/infiniband/hw/mlx4/srq.c +1 -1
@@ -96,7 +96,7 @@ int mlx4_ib_create_srq(struct ib_srq *ib_srq, srq->msrq.max =roundup_pow_of_two (init_attr->attr.max_wr +1 ); srq->msrq.max_gs = init_attr->attr.max_sge; - desc_size =max (32UL , + desc_size =max (32ULL ,roundup_pow_of_two (sizeof (struct mlx4_wqe_srq_next_seg ) + srq->msrq.max_gs *sizeof (struct mlx4_wqe_data_seg )));
drivers/infiniband/hw/mthca/mthca_srq.c +1 -1
@@ -225,7 +225,7 @@ int mthca_alloc_srq(struct mthca_dev *dev, struct mthca_pd *pd,else srq->max = srq->max +1 ; - ds =max (64UL , + ds =max (64ULL ,roundup_pow_of_two (sizeof (struct mthca_next_seg ) + srq->max_gs *sizeof (struct mthca_data_seg )));
drivers/infiniband/sw/rxe/rxe_qp.c +2 -2
@@ -592,7 +592,7 @@ int rxe_qp_from_attr(struct rxe_qp *qp, struct ib_qp_attr *attr, int mask,int err;if (mask &IB_QP_MAX_QP_RD_ATOMIC ) { -int max_rd_atomic =__roundup_pow_of_two (attr->max_rd_atomic); +int max_rd_atomic =roundup_pow_of_two (attr->max_rd_atomic); qp->attr.max_rd_atomic = max_rd_atomic;atomic_set (&qp->req.rd_atomic, max_rd_atomic);
@@ -600,7 +600,7 @@ int rxe_qp_from_attr(struct rxe_qp *qp, struct ib_qp_attr *attr, int mask,if (mask &IB_QP_MAX_DEST_RD_ATOMIC ) {int max_dest_rd_atomic = -__roundup_pow_of_two (attr->max_dest_rd_atomic); +roundup_pow_of_two (attr->max_dest_rd_atomic); qp->attr.max_dest_rd_atomic = max_dest_rd_atomic;
drivers/iommu/intel-iommu.c +2 -2
@@ -1488,7 +1488,7 @@ static void iommu_flush_iotlb_psi(struct intel_iommu *iommu, unsigned long pfn, unsigned int pages, int ih, int map) { - unsigned int mask = ilog2(__roundup_pow_of_two(pages)); + unsigned int mask = ilog2(roundup_pow_of_two(pages));uint64_t addr = (uint64_t )pfn <<VTD_PAGE_SHIFT ;u16 did = domain->iommu_did[iommu->seq_id];
@@ -3390,7 +3390,7 @@ static unsigned long intel_alloc_iova(struct device *dev,/* Restrict dma_mask to the width that the iommu can handle */ dma_mask =min_t (uint64_t,DOMAIN_MAX_ADDR (domain->gaw), dma_mask);/* Ensure we reserve the whole size-aligned region */ - nrpages =__roundup_pow_of_two (nrpages); + nrpages =roundup_pow_of_two (nrpages);if (!dmar_forcedac && dma_mask >DMA_BIT_MASK (32 )) {/*
drivers/iommu/intel-svm.c +2 -2
@@ -115,7 +115,7 @@ static void intel_flush_svm_range_dev (struct intel_svm *svm, struct intel_svm_dQI_EIOTLB_TYPE ; desc.qw1 =0 ; }else { -int mask =ilog2 (__roundup_pow_of_two (pages)); +int mask =ilog2 (roundup_pow_of_two (pages)); desc.qw0 =QI_EIOTLB_PASID (svm->pasid) | QI_EIOTLB_DID(sdev->did) |
@@ -142,7 +142,7 @@ static void intel_flush_svm_range_dev (struct intel_svm *svm, struct intel_svm_d* for example, an "address" value of 0x12345f000 will * flush from 0x123440000 to 0x12347ffff (256KiB). */ unsigned long last = address + ((unsigned long )(pages -1 ) <<VTD_PAGE_SHIFT ); -unsigned long mask =__rounddown_pow_of_two (address ^ last); +unsigned long mask =rounddown_pow_of_two (address ^ last); desc.qw1 =QI_DEV_EIOTLB_ADDR ((address & ~mask) | (mask -1 )) |QI_DEV_EIOTLB_SIZE ;
drivers/iommu/intel_irq_remapping.c +1 -1
@@ -113,7 +113,7 @@ static int alloc_irte(struct intel_iommu *iommu,return -1 ;if (count >1 ) { - count =__roundup_pow_of_two (count); + count =roundup_pow_of_two (count); mask =ilog2 (count); }
drivers/net/ethernet/amd/xgbe/xgbe-ethtool.c +2 -2
@@ -680,13 +680,13 @@ static int xgbe_set_ringparam(struct net_device *netdev,return -EINVAL ; } - rx =__rounddown_pow_of_two (ringparam->rx_pending); + rx =rounddown_pow_of_two (ringparam->rx_pending);if (rx != ringparam->rx_pending)netdev_notice (netdev,"rx ring parameter rounded to power of two: %u\n" , rx); - tx =__rounddown_pow_of_two (ringparam->tx_pending); + tx =rounddown_pow_of_two (ringparam->tx_pending);if (tx != ringparam->tx_pending) netdev_notice(netdev, "tx ring parameter rounded to power of two: %u\n",
drivers/net/ethernet/marvell/sky2.c +1 -1
@@ -4139,7 +4139,7 @@ static int sky2_set_coalesce(struct net_device *dev,*/ static unsigned long roundup_ring_size (unsigned long pending) { -return max (128ul ,roundup_pow_of_two (pending+1 )); +return max (128ull ,roundup_pow_of_two (pending+1 )); } static void sky2_get_ringparam(struct net_device *dev,
drivers/net/ethernet/rocker/rocker_hw.h +2 -2
@@ -88,8 +88,8 @@ enum rocker_dma_type { };/* Rocker DMA ring size limits and default sizes */ -#define ROCKER_DMA_SIZE_MIN 2ul -#define ROCKER_DMA_SIZE_MAX 65536ul +#define ROCKER_DMA_SIZE_MIN 2ull +#define ROCKER_DMA_SIZE_MAX 65536ull#define ROCKER_DMA_CMD_DEFAULT_SIZE 32ul#define ROCKER_DMA_EVENT_DEFAULT_SIZE 32ul#define ROCKER_DMA_TX_DEFAULT_SIZE 64ul
drivers/net/ethernet/sfc/ef10.c +1 -1
@@ -27,7 +27,7 @@ enum { };/* The maximum size of a shared RSS context */ /* TODO: this should really be from the mcdi protocol export */ -#define EFX_EF10_MAX_SHARED_RSS_CONTEXT_SIZE 64UL +#define EFX_EF10_MAX_SHARED_RSS_CONTEXT_SIZE 64ULL/* The filter table(s) are managed by firmware and we have write-only * access. When removing filters we must identify them to the
drivers/net/ethernet/sfc/efx.h +1 -1
@@ -52,7 +52,7 @@ void efx_schedule_slow_fill(struct efx_rx_queue *rx_queue);#define EFX_MAX_DMAQ_SIZE 4096UL#define EFX_DEFAULT_DMAQ_SIZE 1024UL -#define EFX_MIN_DMAQ_SIZE 512UL +#define EFX_MIN_DMAQ_SIZE 512ULL#define EFX_MAX_EVQ_SIZE 16384UL#define EFX_MIN_EVQ_SIZE 512UL
drivers/net/ethernet/sfc/falcon/efx.h +1 -1
@@ -55,7 +55,7 @@ void ef4_schedule_slow_fill(struct ef4_rx_queue *rx_queue);#define EF4_MAX_DMAQ_SIZE 4096UL#define EF4_DEFAULT_DMAQ_SIZE 1024UL -#define EF4_MIN_DMAQ_SIZE 512UL +#define EF4_MIN_DMAQ_SIZE 512ULL#define EF4_MAX_EVQ_SIZE 16384UL#define EF4_MIN_EVQ_SIZE 512UL
drivers/pci/msi.c +1 -1
@@ -578,7 +578,7 @@ msi_setup_entry(struct pci_dev *dev, int nvec, struct irq_affinity *affd) entry->msi_attrib.maskbit = !!(control &PCI_MSI_FLAGS_MASKBIT ); entry->msi_attrib.default_irq = dev->irq;/* Save IOAPIC IRQ */ entry->msi_attrib.multi_cap = (control &PCI_MSI_FLAGS_QMASK ) >>1 ; - entry->msi_attrib.multiple =ilog2 (__roundup_pow_of_two (nvec)); + entry->msi_attrib.multiple =ilog2 (roundup_pow_of_two (nvec));if (control &PCI_MSI_FLAGS_64BIT ) entry->mask_pos = dev->msi_cap +PCI_MSI_MASK_64 ;
include/linux/log2.h +10 -34
62 lines not on this page · raw message
kernel/kexec_core.c +2 -1
@@ -1094,7 +1094,8 @@ static int __init crash_notes_memory_init(void)* crash_notes is allocated inside one physical page. */ size =sizeof (note_buf_t); - align =min (roundup_pow_of_two (sizeof (note_buf_t)),PAGE_SIZE ); + align =min (roundup_pow_of_two (sizeof (note_buf_t)), + (unsigned long long )PAGE_SIZE );/* * Break compile if size is bigger than PAGE_SIZE since crash_notes
lib/rhashtable.c +1 -1
@@ -950,7 +950,7 @@ static size_t rounded_hashtable_size(const struct rhashtable_params *params)if (params->nelem_hint) retsize =max (roundup_pow_of_two (params->nelem_hint *4 /3 ), - (unsigned long )params->min_size); + (unsigned long long )params->min_size);else retsize =max (HASH_DEFAULT_SIZE , (unsigned long )params->min_size);
net/sunrpc/xprtrdma/verbs.c +1 -1
@@ -1015,7 +1015,7 @@ struct rpcrdma_req *rpcrdma_req_create(struct rpcrdma_xprt *r_xprt, size_t size, maxhdrsize = rpcrdma_fixed_maxsz +3 + r_xprt->rx_ia.ri_max_segs * rpcrdma_readchunk_maxsz; maxhdrsize *=sizeof (__be32); - rb =rpcrdma_regbuf_alloc (__roundup_pow_of_two (maxhdrsize), + rb =rpcrdma_regbuf_alloc (roundup_pow_of_two (maxhdrsize),DMA_TO_DEVICE , flags);if (!rb) goto out2;
Signature · 7 lines
2.24.0 _______________________________________________ kexec mailing list [email protected] http://lists.infradead.org/mailman/listinfo/kexec
Re: [PATCH v4 7/8] linux/log2.h: Fix 64bit calculations in roundup/down_pow_two()
Quoted 428 lines · Nicolas Saenz Julienne
Some users need to make sure their rounding function accepts and returns 64bit long variables regardless of the architecture. Sadly roundup/rounddown_pow_two() takes and returns unsigned longs. It turns out
ilog2()already handles 32/64bit calculations properly, and being the building block to the round functions we can rework them as a wrapper around it.Suggested-by Robin Murphy <[email protected]>Signed-off-by Nicolas Saenz Julienne <[email protected]>---
drivers/clk/clk-divider.c | 8 ++-- drivers/clk/sunxi/clk-sunxi.c | 2 +- drivers/infiniband/hw/hfi1/chip.c | 4 +- drivers/infiniband/hw/hfi1/init.c | 4 +- drivers/infiniband/hw/mlx4/srq.c | 2 +- drivers/infiniband/hw/mthca/mthca_srq.c | 2 +- drivers/infiniband/sw/rxe/rxe_qp.c | 4 +- drivers/iommu/intel-iommu.c | 4 +- drivers/iommu/intel-svm.c | 4 +- drivers/iommu/intel_irq_remapping.c | 2 +- drivers/net/ethernet/amd/xgbe/xgbe-ethtool.c | 4 +- drivers/net/ethernet/marvell/sky2.c | 2 +- drivers/net/ethernet/rocker/rocker_hw.h | 4 +- drivers/net/ethernet/sfc/ef10.c | 2 +- drivers/net/ethernet/sfc/efx.h | 2 +- drivers/net/ethernet/sfc/falcon/efx.h | 2 +- drivers/pci/msi.c | 2 +- include/linux/log2.h | 44 +++++--------------- kernel/kexec_core.c | 3 +- lib/rhashtable.c | 2 +- net/sunrpc/xprtrdma/verbs.c | 2 +- 21 files changed, 41 insertions(+), 64 deletions(-)drivers/clk/clk-divider.c +4
-4@@ -222,7 +222,7 @@ static int _div_round_up(const struct clk_div_table *table,int div =DIV_ROUND_UP_ULL ((u64 )parent_rate, rate);if (flags &CLK_DIVIDER_POWER_OF_TWO ) - div =__roundup_pow_of_two (div); + div =roundup_pow_of_two (div);if (table) div =_round_up_table (table, div);@@ -240,8 +240,8 @@ static int _div_round_closest(const struct clk_div_table *table, down = parent_rate / rate;if (flags &CLK_DIVIDER_POWER_OF_TWO ) { - up =__roundup_pow_of_two (up); - down =__rounddown_pow_of_two (down); + up =roundup_pow_of_two (up); + down =rounddown_pow_of_two (down); }else if (table) { up =_round_up_table (table, up); down =_round_down_table (table, down);@@ -278,7 +278,7 @@ static int _next_div(const struct clk_div_table *table, int div, div++;if (flags &CLK_DIVIDER_POWER_OF_TWO ) -return __roundup_pow_of_two (div); +return roundup_pow_of_two (div);if (table)return _round_up_table (table, div);drivers/clk/sunxi/clk-sunxi.c +1
-1@@ -311,7 +311,7 @@ static void sun6i_get_ahb1_factors(struct factors_request *req) calcm =DIV_ROUND_UP (div,1 << calcp); }else { - calcp =__roundup_pow_of_two (div); + calcp =roundup_pow_of_two (div); calcp = calcp >3 ?3 : calcp; }drivers/infiniband/hw/hfi1/chip.c +2
-2@@ -14199,10 +14199,10 @@ static int qos_rmt_entries(struct hfi1_devdata *dd, unsigned int *mp, max_by_vl = krcvqs[i];if (max_by_vl >32 ) goto no_qos; - m =ilog2 (__roundup_pow_of_two (max_by_vl)); + m =ilog2 (roundup_pow_of_two (max_by_vl));/* determine bits for vl */ - n =ilog2 (__roundup_pow_of_two (num_vls)); + n =ilog2 (roundup_pow_of_two (num_vls));/* reject if too much is used */ if ((m + n) >7 )drivers/infiniband/hw/hfi1/init.c +2
-2@@ -467,7 +467,7 @@ int hfi1_create_ctxtdata(struct hfi1_pportdata *ppd, int numa,* MTU supported. */ if (rcd->egrbufs.size < hfi1_max_mtu) { - rcd->egrbufs.size =__roundup_pow_of_two (hfi1_max_mtu); + rcd->egrbufs.size =roundup_pow_of_two (hfi1_max_mtu);hfi1_cdbg (PROC ,"ctxt%u: eager bufs size too small. Adjusting to %u\n" , rcd->ctxt, rcd->egrbufs.size);@@ -1959,7 +1959,7 @@ int hfi1_setup_eagerbufs(struct hfi1_ctxtdata *rcd)* to satisfy the "multiple of 8 RcvArray entries" requirement. */ if (rcd->egrbufs.size <= (1 <<20 )) - rcd->egrbufs.rcvtid_size =max ((unsigned long )round_mtu, + rcd->egrbufs.rcvtid_size =max ((unsigned long long )round_mtu,rounddown_pow_of_two (rcd->egrbufs.size /8 )); while (alloced_bytes < rcd->egrbufs.size &&drivers/infiniband/hw/mlx4/srq.c +1
-1@@ -96,7 +96,7 @@ int mlx4_ib_create_srq(struct ib_srq *ib_srq, srq->msrq.max =roundup_pow_of_two (init_attr->attr.max_wr +1 ); srq->msrq.max_gs = init_attr->attr.max_sge; - desc_size =max (32UL , + desc_size =max (32ULL ,roundup_pow_of_two (sizeof (struct mlx4_wqe_srq_next_seg ) + srq->msrq.max_gs *sizeof (struct mlx4_wqe_data_seg )));drivers/infiniband/hw/mthca/mthca_srq.c +1
-1@@ -225,7 +225,7 @@ int mthca_alloc_srq(struct mthca_dev *dev, struct mthca_pd *pd,else srq->max = srq->max +1 ; - ds =max (64UL , + ds =max (64ULL ,roundup_pow_of_two (sizeof (struct mthca_next_seg ) + srq->max_gs *sizeof (struct mthca_data_seg )));drivers/infiniband/sw/rxe/rxe_qp.c +2
-2@@ -592,7 +592,7 @@ int rxe_qp_from_attr(struct rxe_qp *qp, struct ib_qp_attr *attr, int mask,int err;if (mask &IB_QP_MAX_QP_RD_ATOMIC ) { -int max_rd_atomic =__roundup_pow_of_two (attr->max_rd_atomic); +int max_rd_atomic =roundup_pow_of_two (attr->max_rd_atomic); qp->attr.max_rd_atomic = max_rd_atomic;atomic_set (&qp->req.rd_atomic, max_rd_atomic);@@ -600,7 +600,7 @@ int rxe_qp_from_attr(struct rxe_qp *qp, struct ib_qp_attr *attr, int mask,if (mask &IB_QP_MAX_DEST_RD_ATOMIC ) {int max_dest_rd_atomic = -__roundup_pow_of_two (attr->max_dest_rd_atomic); +roundup_pow_of_two (attr->max_dest_rd_atomic); qp->attr.max_dest_rd_atomic = max_dest_rd_atomic;drivers/iommu/intel-iommu.c +2
-2@@ -1488,7 +1488,7 @@ static void iommu_flush_iotlb_psi(struct intel_iommu *iommu, unsigned long pfn, unsigned int pages, int ih, int map) { - unsigned int mask = ilog2(__roundup_pow_of_two(pages)); + unsigned int mask = ilog2(roundup_pow_of_two(pages));uint64_t addr = (uint64_t )pfn <<VTD_PAGE_SHIFT ;u16 did = domain->iommu_did[iommu->seq_id];@@ -3390,7 +3390,7 @@ static unsigned long intel_alloc_iova(struct device *dev,/* Restrict dma_mask to the width that the iommu can handle */ dma_mask =min_t (uint64_t,DOMAIN_MAX_ADDR (domain->gaw), dma_mask);/* Ensure we reserve the whole size-aligned region */ - nrpages =__roundup_pow_of_two (nrpages); + nrpages =roundup_pow_of_two (nrpages);if (!dmar_forcedac && dma_mask >DMA_BIT_MASK (32 )) {/* drivers/iommu/intel-svm.c +2
-2@@ -115,7 +115,7 @@ static void intel_flush_svm_range_dev (struct intel_svm *svm, struct intel_svm_dQI_EIOTLB_TYPE ; desc.qw1 =0 ; }else { -int mask =ilog2 (__roundup_pow_of_two (pages)); +int mask =ilog2 (roundup_pow_of_two (pages)); desc.qw0 =QI_EIOTLB_PASID (svm->pasid) | QI_EIOTLB_DID(sdev->did) |@@ -142,7 +142,7 @@ static void intel_flush_svm_range_dev (struct intel_svm *svm, struct intel_svm_d* for example, an "address" value of 0x12345f000 will * flush from 0x123440000 to 0x12347ffff (256KiB). */ unsigned long last = address + ((unsigned long )(pages -1 ) <<VTD_PAGE_SHIFT ); -unsigned long mask =__rounddown_pow_of_two (address ^ last); +unsigned long mask =rounddown_pow_of_two (address ^ last); desc.qw1 =QI_DEV_EIOTLB_ADDR ((address & ~mask) | (mask -1 )) |QI_DEV_EIOTLB_SIZE ;drivers/iommu/intel_irq_remapping.c +1
-1@@ -113,7 +113,7 @@ static int alloc_irte(struct intel_iommu *iommu,return -1 ;if (count >1 ) { - count =__roundup_pow_of_two (count); + count =roundup_pow_of_two (count); mask =ilog2 (count); }drivers/net/ethernet/amd/xgbe/xgbe-ethtool.c +2
-2@@ -680,13 +680,13 @@ static int xgbe_set_ringparam(struct net_device *netdev,return -EINVAL ; } - rx =__rounddown_pow_of_two (ringparam->rx_pending); + rx =rounddown_pow_of_two (ringparam->rx_pending);if (rx != ringparam->rx_pending)netdev_notice (netdev,"rx ring parameter rounded to power of two: %u\n" , rx); - tx =__rounddown_pow_of_two (ringparam->tx_pending); + tx =rounddown_pow_of_two (ringparam->tx_pending);if (tx != ringparam->tx_pending) netdev_notice(netdev, "tx ring parameter rounded to power of two: %u\n",drivers/net/ethernet/marvell/sky2.c +1
-1@@ -4139,7 +4139,7 @@ static int sky2_set_coalesce(struct net_device *dev,*/ static unsigned long roundup_ring_size (unsigned long pending) { -return max (128ul ,roundup_pow_of_two (pending+1 )); +return max (128ull ,roundup_pow_of_two (pending+1 )); } static void sky2_get_ringparam(struct net_device *dev,drivers/net/ethernet/rocker/rocker_hw.h +2
-2@@ -88,8 +88,8 @@ enum rocker_dma_type { };/* Rocker DMA ring size limits and default sizes */ -#define ROCKER_DMA_SIZE_MIN 2ul -#define ROCKER_DMA_SIZE_MAX 65536ul +#define ROCKER_DMA_SIZE_MIN 2ull +#define ROCKER_DMA_SIZE_MAX 65536ull#define ROCKER_DMA_CMD_DEFAULT_SIZE 32ul#define ROCKER_DMA_EVENT_DEFAULT_SIZE 32ul#define ROCKER_DMA_TX_DEFAULT_SIZE 64uldrivers/net/ethernet/sfc/ef10.c +1
-1@@ -27,7 +27,7 @@ enum { };/* The maximum size of a shared RSS context */ /* TODO: this should really be from the mcdi protocol export */ -#define EFX_EF10_MAX_SHARED_RSS_CONTEXT_SIZE 64UL +#define EFX_EF10_MAX_SHARED_RSS_CONTEXT_SIZE 64ULL/* The filter table(s) are managed by firmware and we have write-only * access. When removing filters we must identify them to the drivers/net/ethernet/sfc/efx.h +1
-1@@ -52,7 +52,7 @@ void efx_schedule_slow_fill(struct efx_rx_queue *rx_queue);#define EFX_MAX_DMAQ_SIZE 4096UL#define EFX_DEFAULT_DMAQ_SIZE 1024UL -#define EFX_MIN_DMAQ_SIZE 512UL +#define EFX_MIN_DMAQ_SIZE 512ULL#define EFX_MAX_EVQ_SIZE 16384UL#define EFX_MIN_EVQ_SIZE 512ULdrivers/net/ethernet/sfc/falcon/efx.h +1
-1@@ -55,7 +55,7 @@ void ef4_schedule_slow_fill(struct ef4_rx_queue *rx_queue);#define EF4_MAX_DMAQ_SIZE 4096UL#define EF4_DEFAULT_DMAQ_SIZE 1024UL -#define EF4_MIN_DMAQ_SIZE 512UL +#define EF4_MIN_DMAQ_SIZE 512ULL#define EF4_MAX_EVQ_SIZE 16384UL#define EF4_MIN_EVQ_SIZE 512ULdrivers/pci/msi.c +1
-1@@ -578,7 +578,7 @@ msi_setup_entry(struct pci_dev *dev, int nvec, struct irq_affinity *affd) entry->msi_attrib.maskbit = !!(control &PCI_MSI_FLAGS_MASKBIT ); entry->msi_attrib.default_irq = dev->irq;/* Save IOAPIC IRQ */ entry->msi_attrib.multi_cap = (control &PCI_MSI_FLAGS_QMASK ) >>1 ; - entry->msi_attrib.multiple =ilog2 (__roundup_pow_of_two (nvec)); + entry->msi_attrib.multiple =ilog2 (roundup_pow_of_two (nvec));if (control &PCI_MSI_FLAGS_64BIT ) entry->mask_pos = dev->msi_cap +PCI_MSI_MASK_64 ;include/linux/log2.h +10
-34@@ -47,26 +47,6 @@ bool is_power_of_2(unsigned long n)return (n !=0 && ((n & (n -1 )) ==0 )); } -/** -* __roundup_pow_of_two() - round up to nearest power of two -* @n: value to round up -*/ -static inline __attribute__((const)) -unsigned long __roundup_pow_of_two (unsigned long n) -{ -return 1UL <<fls_long (n -1 ); -} - -/** -* __rounddown_pow_of_two() - round down to nearest power of two -* @n: value to round down -*/ -static inline __attribute__((const)) -unsigned long __rounddown_pow_of_two (unsigned long n) -{ -return 1UL << (fls_long (n) -1 ); -} -/** * const_ilog2 - log base 2 of 32-bit or a 64-bit constant unsigned value * @n: parameter @@ -170,14 +150,11 @@ unsigned long __rounddown_pow_of_two(unsigned long n)* - the result is undefined when n == 0 * - this can be used to initialise global variables from constant data */ -#define roundup_pow_of_two (n) \ -( \ - __builtin_constant_p(n) ? ( \ - (n == 1) ? 1 : \ - (1UL << (ilog2((n) - 1) + 1)) \ - ) : \ - __roundup_pow_of_two(n) \ - ) +#define roundup_pow_of_two (n) \ +( \ + (__builtin_constant_p(n) && ((n) == 1)) ? \ + 1 : (1ULL << (ilog2((n) - 1) + 1)) \ +)/** * rounddown_pow_of_two - round the given value down to nearest power of two @@ -187,12 +164,11 @@ unsigned long __rounddown_pow_of_two(unsigned long n)* - the result is undefined when n == 0 * - this can be used to initialise global variables from constant data */ -#define rounddown_pow_of_two (n) \ -( \ - __builtin_constant_p(n) ? ( \ - (1UL << ilog2(n))) : \ - __rounddown_pow_of_two(n) \ - ) +#define rounddown_pow_of_two (n) \ +( \ + (__builtin_constant_p(n) && ((n) == 1)) ? \ + 1 : (1ULL << (ilog2(n))) \ +)static inline
__attribute_const__
int__order_base_2(unsigned long n)kernel/kexec_core.c +2
-1@@ -1094,7 +1094,8 @@ static int __init crash_notes_memory_init(void)* crash_notes is allocated inside one physical page. */ size =sizeof (note_buf_t); - align =min (roundup_pow_of_two (sizeof (note_buf_t)),PAGE_SIZE ); + align =min (roundup_pow_of_two (sizeof (note_buf_t)), + (unsigned long long )PAGE_SIZE );/* * Break compile if size is bigger than PAGE_SIZE since crash_notes lib/rhashtable.c +1
-1@@ -950,7 +950,7 @@ static size_t rounded_hashtable_size(const struct rhashtable_params *params)if (params->nelem_hint) retsize =max (roundup_pow_of_two (params->nelem_hint *4 /3 ), - (unsigned long )params->min_size); + (unsigned long long )params->min_size);else retsize =max (HASH_DEFAULT_SIZE , (unsigned long )params->min_size);net/sunrpc/xprtrdma/verbs.c +0
-0
net/sunrpc/xprtrdma/verbs.c struct rpcrdma_req *rpcrdma_req_create(struct rpcrdma_xprt *r_xprt, size_t size, · line 1021
Quoted 8 lines
net/sunrpc/xprtrdma/verbs.c +1
-1@@ -1015,7 +1015,7 @@ struct rpcrdma_req *rpcrdma_req_create(struct rpcrdma_xprt *r_xprt, size_t size, maxhdrsize = rpcrdma_fixed_maxsz +3 + r_xprt->rx_ia.ri_max_segs * rpcrdma_readchunk_maxsz; maxhdrsize *=sizeof (__be32); - rb =rpcrdma_regbuf_alloc (__roundup_pow_of_two (maxhdrsize), + rb =rpcrdma_regbuf_alloc (roundup_pow_of_two (maxhdrsize),DMA_TO_DEVICE , flags);if (!rb) goto out2;
For the xprtrdma chunk:
--
Chuck Lever
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
Re: [PATCH v4 7/8] linux/log2.h: Fix 64bit calculations in roundup/down_pow_two()
In reply to Nicolas Saenz JulienneFor the changes under drivers/net/ethernet/sfc:
Quoted 425 lines · Nicolas Saenz Julienne
Some users need to make sure their rounding function accepts and returns 64bit long variables regardless of the architecture. Sadly roundup/rounddown_pow_two() takes and returns unsigned longs. It turns out
ilog2()already handles 32/64bit calculations properly, and being the building block to the round functions we can rework them as a wrapper around it.Suggested-by Robin Murphy <[email protected]>Signed-off-by Nicolas Saenz Julienne <[email protected]>--- drivers/clk/clk-divider.c | 8 ++-- drivers/clk/sunxi/clk-sunxi.c | 2 +- drivers/infiniband/hw/hfi1/chip.c | 4 +- drivers/infiniband/hw/hfi1/init.c | 4 +- drivers/infiniband/hw/mlx4/srq.c | 2 +- drivers/infiniband/hw/mthca/mthca_srq.c | 2 +- drivers/infiniband/sw/rxe/rxe_qp.c | 4 +- drivers/iommu/intel-iommu.c | 4 +- drivers/iommu/intel-svm.c | 4 +- drivers/iommu/intel_irq_remapping.c | 2 +- drivers/net/ethernet/amd/xgbe/xgbe-ethtool.c | 4 +- drivers/net/ethernet/marvell/sky2.c | 2 +- drivers/net/ethernet/rocker/rocker_hw.h | 4 +- drivers/net/ethernet/sfc/ef10.c | 2 +- drivers/net/ethernet/sfc/efx.h | 2 +- drivers/net/ethernet/sfc/falcon/efx.h | 2 +- drivers/pci/msi.c | 2 +- include/linux/log2.h | 44 +++++--------------- kernel/kexec_core.c | 3 +- lib/rhashtable.c | 2 +- net/sunrpc/xprtrdma/verbs.c | 2 +- 21 files changed, 41 insertions(+), 64 deletions(-)drivers/clk/clk-divider.c +4
-4@@ -222,7 +222,7 @@ static int _div_round_up(const struct clk_div_table *table,int div =DIV_ROUND_UP_ULL ((u64 )parent_rate, rate);if (flags &CLK_DIVIDER_POWER_OF_TWO ) - div =__roundup_pow_of_two (div); + div =roundup_pow_of_two (div);if (table) div =_round_up_table (table, div);@@ -240,8 +240,8 @@ static int _div_round_closest(const struct clk_div_table *table, down = parent_rate / rate;if (flags &CLK_DIVIDER_POWER_OF_TWO ) { - up =__roundup_pow_of_two (up); - down =__rounddown_pow_of_two (down); + up =roundup_pow_of_two (up); + down =rounddown_pow_of_two (down); }else if (table) { up =_round_up_table (table, up); down =_round_down_table (table, down);@@ -278,7 +278,7 @@ static int _next_div(const struct clk_div_table *table, int div, div++;if (flags &CLK_DIVIDER_POWER_OF_TWO ) -return __roundup_pow_of_two (div); +return roundup_pow_of_two (div);if (table)return _round_up_table (table, div);drivers/clk/sunxi/clk-sunxi.c +1
-1@@ -311,7 +311,7 @@ static void sun6i_get_ahb1_factors(struct factors_request *req) calcm =DIV_ROUND_UP (div,1 << calcp); }else { - calcp =__roundup_pow_of_two (div); + calcp =roundup_pow_of_two (div); calcp = calcp >3 ?3 : calcp; }drivers/infiniband/hw/hfi1/chip.c +2
-2@@ -14199,10 +14199,10 @@ static int qos_rmt_entries(struct hfi1_devdata *dd, unsigned int *mp, max_by_vl = krcvqs[i];if (max_by_vl >32 ) goto no_qos; - m =ilog2 (__roundup_pow_of_two (max_by_vl)); + m =ilog2 (roundup_pow_of_two (max_by_vl));/* determine bits for vl */ - n =ilog2 (__roundup_pow_of_two (num_vls)); + n =ilog2 (roundup_pow_of_two (num_vls));/* reject if too much is used */ if ((m + n) >7 )drivers/infiniband/hw/hfi1/init.c +2
-2@@ -467,7 +467,7 @@ int hfi1_create_ctxtdata(struct hfi1_pportdata *ppd, int numa,* MTU supported. */ if (rcd->egrbufs.size < hfi1_max_mtu) { - rcd->egrbufs.size =__roundup_pow_of_two (hfi1_max_mtu); + rcd->egrbufs.size =roundup_pow_of_two (hfi1_max_mtu);hfi1_cdbg (PROC ,"ctxt%u: eager bufs size too small. Adjusting to %u\n" , rcd->ctxt, rcd->egrbufs.size);@@ -1959,7 +1959,7 @@ int hfi1_setup_eagerbufs(struct hfi1_ctxtdata *rcd)* to satisfy the "multiple of 8 RcvArray entries" requirement. */ if (rcd->egrbufs.size <= (1 <<20 )) - rcd->egrbufs.rcvtid_size =max ((unsigned long )round_mtu, + rcd->egrbufs.rcvtid_size =max ((unsigned long long )round_mtu,rounddown_pow_of_two (rcd->egrbufs.size /8 )); while (alloced_bytes < rcd->egrbufs.size &&drivers/infiniband/hw/mlx4/srq.c +1
-1@@ -96,7 +96,7 @@ int mlx4_ib_create_srq(struct ib_srq *ib_srq, srq->msrq.max =roundup_pow_of_two (init_attr->attr.max_wr +1 ); srq->msrq.max_gs = init_attr->attr.max_sge; - desc_size =max (32UL , + desc_size =max (32ULL ,roundup_pow_of_two (sizeof (struct mlx4_wqe_srq_next_seg ) + srq->msrq.max_gs *sizeof (struct mlx4_wqe_data_seg )));drivers/infiniband/hw/mthca/mthca_srq.c +1
-1@@ -225,7 +225,7 @@ int mthca_alloc_srq(struct mthca_dev *dev, struct mthca_pd *pd,else srq->max = srq->max +1 ; - ds =max (64UL , + ds =max (64ULL ,roundup_pow_of_two (sizeof (struct mthca_next_seg ) + srq->max_gs *sizeof (struct mthca_data_seg )));drivers/infiniband/sw/rxe/rxe_qp.c +2
-2@@ -592,7 +592,7 @@ int rxe_qp_from_attr(struct rxe_qp *qp, struct ib_qp_attr *attr, int mask,int err;if (mask &IB_QP_MAX_QP_RD_ATOMIC ) { -int max_rd_atomic =__roundup_pow_of_two (attr->max_rd_atomic); +int max_rd_atomic =roundup_pow_of_two (attr->max_rd_atomic); qp->attr.max_rd_atomic = max_rd_atomic;atomic_set (&qp->req.rd_atomic, max_rd_atomic);@@ -600,7 +600,7 @@ int rxe_qp_from_attr(struct rxe_qp *qp, struct ib_qp_attr *attr, int mask,if (mask &IB_QP_MAX_DEST_RD_ATOMIC ) {int max_dest_rd_atomic = -__roundup_pow_of_two (attr->max_dest_rd_atomic); +roundup_pow_of_two (attr->max_dest_rd_atomic); qp->attr.max_dest_rd_atomic = max_dest_rd_atomic;drivers/iommu/intel-iommu.c +2
-2@@ -1488,7 +1488,7 @@ static void iommu_flush_iotlb_psi(struct intel_iommu *iommu, unsigned long pfn, unsigned int pages, int ih, int map) { - unsigned int mask = ilog2(__roundup_pow_of_two(pages)); + unsigned int mask = ilog2(roundup_pow_of_two(pages));uint64_t addr = (uint64_t )pfn <<VTD_PAGE_SHIFT ;u16 did = domain->iommu_did[iommu->seq_id];@@ -3390,7 +3390,7 @@ static unsigned long intel_alloc_iova(struct device *dev,/* Restrict dma_mask to the width that the iommu can handle */ dma_mask =min_t (uint64_t,DOMAIN_MAX_ADDR (domain->gaw), dma_mask);/* Ensure we reserve the whole size-aligned region */ - nrpages =__roundup_pow_of_two (nrpages); + nrpages =roundup_pow_of_two (nrpages);if (!dmar_forcedac && dma_mask >DMA_BIT_MASK (32 )) {/* drivers/iommu/intel-svm.c +2
-2@@ -115,7 +115,7 @@ static void intel_flush_svm_range_dev (struct intel_svm *svm, struct intel_svm_dQI_EIOTLB_TYPE ; desc.qw1 =0 ; }else { -int mask =ilog2 (__roundup_pow_of_two (pages)); +int mask =ilog2 (roundup_pow_of_two (pages)); desc.qw0 =QI_EIOTLB_PASID (svm->pasid) | QI_EIOTLB_DID(sdev->did) |@@ -142,7 +142,7 @@ static void intel_flush_svm_range_dev (struct intel_svm *svm, struct intel_svm_d* for example, an "address" value of 0x12345f000 will * flush from 0x123440000 to 0x12347ffff (256KiB). */ unsigned long last = address + ((unsigned long )(pages -1 ) <<VTD_PAGE_SHIFT ); -unsigned long mask =__rounddown_pow_of_two (address ^ last); +unsigned long mask =rounddown_pow_of_two (address ^ last); desc.qw1 =QI_DEV_EIOTLB_ADDR ((address & ~mask) | (mask -1 )) |QI_DEV_EIOTLB_SIZE ;drivers/iommu/intel_irq_remapping.c +1
-1@@ -113,7 +113,7 @@ static int alloc_irte(struct intel_iommu *iommu,return -1 ;if (count >1 ) { - count =__roundup_pow_of_two (count); + count =roundup_pow_of_two (count); mask =ilog2 (count); }drivers/net/ethernet/amd/xgbe/xgbe-ethtool.c +2
-2@@ -680,13 +680,13 @@ static int xgbe_set_ringparam(struct net_device *netdev,return -EINVAL ; } - rx =__rounddown_pow_of_two (ringparam->rx_pending); + rx =rounddown_pow_of_two (ringparam->rx_pending);if (rx != ringparam->rx_pending)netdev_notice (netdev,"rx ring parameter rounded to power of two: %u\n" , rx); - tx =__rounddown_pow_of_two (ringparam->tx_pending); + tx =rounddown_pow_of_two (ringparam->tx_pending);if (tx != ringparam->tx_pending) netdev_notice(netdev, "tx ring parameter rounded to power of two: %u\n",drivers/net/ethernet/marvell/sky2.c +1
-1@@ -4139,7 +4139,7 @@ static int sky2_set_coalesce(struct net_device *dev,*/ static unsigned long roundup_ring_size (unsigned long pending) { -return max (128ul ,roundup_pow_of_two (pending+1 )); +return max (128ull ,roundup_pow_of_two (pending+1 )); } static void sky2_get_ringparam(struct net_device *dev,drivers/net/ethernet/rocker/rocker_hw.h +2
-2@@ -88,8 +88,8 @@ enum rocker_dma_type { };/* Rocker DMA ring size limits and default sizes */ -#define ROCKER_DMA_SIZE_MIN 2ul -#define ROCKER_DMA_SIZE_MAX 65536ul +#define ROCKER_DMA_SIZE_MIN 2ull +#define ROCKER_DMA_SIZE_MAX 65536ull#define ROCKER_DMA_CMD_DEFAULT_SIZE 32ul#define ROCKER_DMA_EVENT_DEFAULT_SIZE 32ul#define ROCKER_DMA_TX_DEFAULT_SIZE 64uldrivers/net/ethernet/sfc/ef10.c +1
-1@@ -27,7 +27,7 @@ enum { };/* The maximum size of a shared RSS context */ /* TODO: this should really be from the mcdi protocol export */ -#define EFX_EF10_MAX_SHARED_RSS_CONTEXT_SIZE 64UL +#define EFX_EF10_MAX_SHARED_RSS_CONTEXT_SIZE 64ULL/* The filter table(s) are managed by firmware and we have write-only * access. When removing filters we must identify them to the drivers/net/ethernet/sfc/efx.h +1
-1@@ -52,7 +52,7 @@ void efx_schedule_slow_fill(struct efx_rx_queue *rx_queue);#define EFX_MAX_DMAQ_SIZE 4096UL#define EFX_DEFAULT_DMAQ_SIZE 1024UL -#define EFX_MIN_DMAQ_SIZE 512UL +#define EFX_MIN_DMAQ_SIZE 512ULL#define EFX_MAX_EVQ_SIZE 16384UL#define EFX_MIN_EVQ_SIZE 512ULdrivers/net/ethernet/sfc/falcon/efx.h +1
-1@@ -55,7 +55,7 @@ void ef4_schedule_slow_fill(struct ef4_rx_queue *rx_queue);#define EF4_MAX_DMAQ_SIZE 4096UL#define EF4_DEFAULT_DMAQ_SIZE 1024UL -#define EF4_MIN_DMAQ_SIZE 512UL +#define EF4_MIN_DMAQ_SIZE 512ULL#define EF4_MAX_EVQ_SIZE 16384UL#define EF4_MIN_EVQ_SIZE 512ULdrivers/pci/msi.c +1
-1@@ -578,7 +578,7 @@ msi_setup_entry(struct pci_dev *dev, int nvec, struct irq_affinity *affd) entry->msi_attrib.maskbit = !!(control &PCI_MSI_FLAGS_MASKBIT ); entry->msi_attrib.default_irq = dev->irq;/* Save IOAPIC IRQ */ entry->msi_attrib.multi_cap = (control &PCI_MSI_FLAGS_QMASK ) >>1 ; - entry->msi_attrib.multiple =ilog2 (__roundup_pow_of_two (nvec)); + entry->msi_attrib.multiple =ilog2 (roundup_pow_of_two (nvec));if (control &PCI_MSI_FLAGS_64BIT ) entry->mask_pos = dev->msi_cap +PCI_MSI_MASK_64 ;include/linux/log2.h +10
-34@@ -47,26 +47,6 @@ bool is_power_of_2(unsigned long n)return (n !=0 && ((n & (n -1 )) ==0 )); } -/** -* __roundup_pow_of_two() - round up to nearest power of two -* @n: value to round up -*/ -static inline __attribute__((const)) -unsigned long __roundup_pow_of_two (unsigned long n) -{ -return 1UL <<fls_long (n -1 ); -} - -/** -* __rounddown_pow_of_two() - round down to nearest power of two -* @n: value to round down -*/ -static inline __attribute__((const)) -unsigned long __rounddown_pow_of_two (unsigned long n) -{ -return 1UL << (fls_long (n) -1 ); -} -/** * const_ilog2 - log base 2 of 32-bit or a 64-bit constant unsigned value * @n: parameter @@ -170,14 +150,11 @@ unsigned long __rounddown_pow_of_two(unsigned long n)* - the result is undefined when n == 0 * - this can be used to initialise global variables from constant data */ -#define roundup_pow_of_two (n) \ -( \ - __builtin_constant_p(n) ? ( \ - (n == 1) ? 1 : \ - (1UL << (ilog2((n) - 1) + 1)) \ - ) : \ - __roundup_pow_of_two(n) \ - ) +#define roundup_pow_of_two (n) \ +( \ + (__builtin_constant_p(n) && ((n) == 1)) ? \ + 1 : (1ULL << (ilog2((n) - 1) + 1)) \ +)/** * rounddown_pow_of_two - round the given value down to nearest power of two @@ -187,12 +164,11 @@ unsigned long __rounddown_pow_of_two(unsigned long n)* - the result is undefined when n == 0 * - this can be used to initialise global variables from constant data */ -#define rounddown_pow_of_two (n) \ -( \ - __builtin_constant_p(n) ? ( \ - (1UL << ilog2(n))) : \ - __rounddown_pow_of_two(n) \ - ) +#define rounddown_pow_of_two (n) \ +( \ + (__builtin_constant_p(n) && ((n) == 1)) ? \ + 1 : (1ULL << (ilog2(n))) \ +)static inline __attribute_const__ int __order_base_2(unsigned long n)kernel/kexec_core.c +2
-1@@ -1094,7 +1094,8 @@ static int __init crash_notes_memory_init(void)* crash_notes is allocated inside one physical page. */ size =sizeof (note_buf_t); - align =min (roundup_pow_of_two (sizeof (note_buf_t)),PAGE_SIZE ); + align =min (roundup_pow_of_two (sizeof (note_buf_t)), + (unsigned long long )PAGE_SIZE );/* * Break compile if size is bigger than PAGE_SIZE since crash_notes lib/rhashtable.c +1
-1@@ -950,7 +950,7 @@ static size_t rounded_hashtable_size(const struct rhashtable_params *params)if (params->nelem_hint) retsize =max (roundup_pow_of_two (params->nelem_hint *4 /3 ), - (unsigned long )params->min_size); + (unsigned long long )params->min_size);else retsize =max (HASH_DEFAULT_SIZE , (unsigned long )params->min_size);net/sunrpc/xprtrdma/verbs.c +0
-0
net/sunrpc/xprtrdma/verbs.c struct rpcrdma_req *rpcrdma_req_create(struct rpcrdma_xprt *r_xprt, size_t size, · line 1021
Quoted 8 lines
net/sunrpc/xprtrdma/verbs.c +1
-1@@ -1015,7 +1015,7 @@ struct rpcrdma_req *rpcrdma_req_create(struct rpcrdma_xprt *r_xprt, size_t size, maxhdrsize = rpcrdma_fixed_maxsz +3 + r_xprt->rx_ia.ri_max_segs * rpcrdma_readchunk_maxsz; maxhdrsize *=sizeof (__be32); - rb =rpcrdma_regbuf_alloc (__roundup_pow_of_two (maxhdrsize), + rb =rpcrdma_regbuf_alloc (roundup_pow_of_two (maxhdrsize),DMA_TO_DEVICE , flags);if (!rb) goto out2;
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
Re: [PATCH v4 7/8] linux/log2.h: Fix 64bit calculations in roundup/down_pow_two()
In reply to Nicolas Saenz JulienneQuoted 9 lines · Nicolas Saenz Julienne
Some users need to make sure their rounding function accepts and returns 64bit long variables regardless of the architecture. Sadly roundup/rounddown_pow_two() takes and returns unsigned longs. It turns out
ilog2()already handles 32/64bit calculations properly, and being the building block to the round functions we can rework them as a wrapper around it.Suggested-by Robin Murphy <[email protected]>Signed-off-by Nicolas Saenz Julienne <[email protected]>
Quoted 8 lines
--- drivers/clk/clk-divider.c | 8 ++-- drivers/clk/sunxi/clk-sunxi.c | 2 +- drivers/infiniband/hw/hfi1/chip.c | 4 +- drivers/infiniband/hw/hfi1/init.c | 4 +- drivers/infiniband/hw/mlx4/srq.c | 2 +- drivers/infiniband/hw/mthca/mthca_srq.c | 2 +- drivers/infiniband/sw/rxe/rxe_qp.c | 4 +-
Thanks, for infiniband.
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
Re: [PATCH v4 7/8] linux/log2.h: Fix 64bit calculations in roundup/down_pow_two()
In reply to Nicolas Saenz JulienneHi,
Quoted 9 lines · Nicolas Saenz Julienne
Some users need to make sure their rounding function accepts and returns 64bit long variables regardless of the architecture. Sadly roundup/rounddown_pow_two() takes and returns unsigned longs. It turns out
ilog2()already handles 32/64bit calculations properly, and being the building block to the round functions we can rework them as a wrapper around it.Suggested-by Robin Murphy <[email protected]>Signed-off-by Nicolas Saenz Julienne <[email protected]>
Quoted 11 lines
--- drivers/clk/clk-divider.c | 8 ++-- drivers/clk/sunxi/clk-sunxi.c | 2 +- drivers/infiniband/hw/hfi1/chip.c | 4 +- drivers/infiniband/hw/hfi1/init.c | 4 +- drivers/infiniband/hw/mlx4/srq.c | 2 +- drivers/infiniband/hw/mthca/mthca_srq.c | 2 +- drivers/infiniband/sw/rxe/rxe_qp.c | 4 +- drivers/iommu/intel-iommu.c | 4 +- drivers/iommu/intel-svm.c | 4 +- drivers/iommu/intel_irq_remapping.c | 2 +-
For changes in drivers/iommu/intel*.c,
Best regards,
baolu
Quoted 405 lines
drivers/net/ethernet/amd/xgbe/xgbe-ethtool.c | 4 +- drivers/net/ethernet/marvell/sky2.c | 2 +- drivers/net/ethernet/rocker/rocker_hw.h | 4 +- drivers/net/ethernet/sfc/ef10.c | 2 +- drivers/net/ethernet/sfc/efx.h | 2 +- drivers/net/ethernet/sfc/falcon/efx.h | 2 +- drivers/pci/msi.c | 2 +- include/linux/log2.h | 44 +++++--------------- kernel/kexec_core.c | 3 +- lib/rhashtable.c | 2 +- net/sunrpc/xprtrdma/verbs.c | 2 +- 21 files changed, 41 insertions(+), 64 deletions(-)drivers/clk/clk-divider.c +4
-4@@ -222,7 +222,7 @@ static int _div_round_up(const struct clk_div_table *table,int div =DIV_ROUND_UP_ULL ((u64 )parent_rate, rate);if (flags &CLK_DIVIDER_POWER_OF_TWO ) - div =__roundup_pow_of_two (div); + div =roundup_pow_of_two (div);if (table) div =_round_up_table (table, div);@@ -240,8 +240,8 @@ static int _div_round_closest(const struct clk_div_table *table, down = parent_rate / rate;if (flags &CLK_DIVIDER_POWER_OF_TWO ) { - up =__roundup_pow_of_two (up); - down =__rounddown_pow_of_two (down); + up =roundup_pow_of_two (up); + down =rounddown_pow_of_two (down); }else if (table) { up =_round_up_table (table, up); down =_round_down_table (table, down);@@ -278,7 +278,7 @@ static int _next_div(const struct clk_div_table *table, int div, div++;if (flags &CLK_DIVIDER_POWER_OF_TWO ) -return __roundup_pow_of_two (div); +return roundup_pow_of_two (div);if (table)return _round_up_table (table, div);drivers/clk/sunxi/clk-sunxi.c +1
-1@@ -311,7 +311,7 @@ static void sun6i_get_ahb1_factors(struct factors_request *req) calcm =DIV_ROUND_UP (div,1 << calcp); }else { - calcp =__roundup_pow_of_two (div); + calcp =roundup_pow_of_two (div); calcp = calcp >3 ?3 : calcp; }drivers/infiniband/hw/hfi1/chip.c +2
-2@@ -14199,10 +14199,10 @@ static int qos_rmt_entries(struct hfi1_devdata *dd, unsigned int *mp, max_by_vl = krcvqs[i];if (max_by_vl >32 ) goto no_qos; - m =ilog2 (__roundup_pow_of_two (max_by_vl)); + m =ilog2 (roundup_pow_of_two (max_by_vl));/* determine bits for vl */ - n =ilog2 (__roundup_pow_of_two (num_vls)); + n =ilog2 (roundup_pow_of_two (num_vls));/* reject if too much is used */ if ((m + n) >7 )drivers/infiniband/hw/hfi1/init.c +2
-2@@ -467,7 +467,7 @@ int hfi1_create_ctxtdata(struct hfi1_pportdata *ppd, int numa,* MTU supported. */ if (rcd->egrbufs.size < hfi1_max_mtu) { - rcd->egrbufs.size =__roundup_pow_of_two (hfi1_max_mtu); + rcd->egrbufs.size =roundup_pow_of_two (hfi1_max_mtu);hfi1_cdbg (PROC ,"ctxt%u: eager bufs size too small. Adjusting to %u\n" , rcd->ctxt, rcd->egrbufs.size);@@ -1959,7 +1959,7 @@ int hfi1_setup_eagerbufs(struct hfi1_ctxtdata *rcd)* to satisfy the "multiple of 8 RcvArray entries" requirement. */ if (rcd->egrbufs.size <= (1 <<20 )) - rcd->egrbufs.rcvtid_size =max ((unsigned long )round_mtu, + rcd->egrbufs.rcvtid_size =max ((unsigned long long )round_mtu,rounddown_pow_of_two (rcd->egrbufs.size /8 )); while (alloced_bytes < rcd->egrbufs.size &&drivers/infiniband/hw/mlx4/srq.c +1
-1@@ -96,7 +96,7 @@ int mlx4_ib_create_srq(struct ib_srq *ib_srq, srq->msrq.max =roundup_pow_of_two (init_attr->attr.max_wr +1 ); srq->msrq.max_gs = init_attr->attr.max_sge; - desc_size =max (32UL , + desc_size =max (32ULL ,roundup_pow_of_two (sizeof (struct mlx4_wqe_srq_next_seg ) + srq->msrq.max_gs *sizeof (struct mlx4_wqe_data_seg )));drivers/infiniband/hw/mthca/mthca_srq.c +1
-1@@ -225,7 +225,7 @@ int mthca_alloc_srq(struct mthca_dev *dev, struct mthca_pd *pd,else srq->max = srq->max +1 ; - ds =max (64UL , + ds =max (64ULL ,roundup_pow_of_two (sizeof (struct mthca_next_seg ) + srq->max_gs *sizeof (struct mthca_data_seg )));drivers/infiniband/sw/rxe/rxe_qp.c +2
-2@@ -592,7 +592,7 @@ int rxe_qp_from_attr(struct rxe_qp *qp, struct ib_qp_attr *attr, int mask,int err;if (mask &IB_QP_MAX_QP_RD_ATOMIC ) { -int max_rd_atomic =__roundup_pow_of_two (attr->max_rd_atomic); +int max_rd_atomic =roundup_pow_of_two (attr->max_rd_atomic); qp->attr.max_rd_atomic = max_rd_atomic;atomic_set (&qp->req.rd_atomic, max_rd_atomic);@@ -600,7 +600,7 @@ int rxe_qp_from_attr(struct rxe_qp *qp, struct ib_qp_attr *attr, int mask,if (mask &IB_QP_MAX_DEST_RD_ATOMIC ) {int max_dest_rd_atomic = -__roundup_pow_of_two (attr->max_dest_rd_atomic); +roundup_pow_of_two (attr->max_dest_rd_atomic); qp->attr.max_dest_rd_atomic = max_dest_rd_atomic;drivers/iommu/intel-iommu.c +2
-2@@ -1488,7 +1488,7 @@ static void iommu_flush_iotlb_psi(struct intel_iommu *iommu, unsigned long pfn, unsigned int pages, int ih, int map) { - unsigned int mask = ilog2(__roundup_pow_of_two(pages)); + unsigned int mask = ilog2(roundup_pow_of_two(pages));uint64_t addr = (uint64_t )pfn <<VTD_PAGE_SHIFT ;u16 did = domain->iommu_did[iommu->seq_id];@@ -3390,7 +3390,7 @@ static unsigned long intel_alloc_iova(struct device *dev,/* Restrict dma_mask to the width that the iommu can handle */ dma_mask =min_t (uint64_t,DOMAIN_MAX_ADDR (domain->gaw), dma_mask);/* Ensure we reserve the whole size-aligned region */ - nrpages =__roundup_pow_of_two (nrpages); + nrpages =roundup_pow_of_two (nrpages);if (!dmar_forcedac && dma_mask >DMA_BIT_MASK (32 )) {/* drivers/iommu/intel-svm.c +2
-2@@ -115,7 +115,7 @@ static void intel_flush_svm_range_dev (struct intel_svm *svm, struct intel_svm_dQI_EIOTLB_TYPE ; desc.qw1 =0 ; }else { -int mask =ilog2 (__roundup_pow_of_two (pages)); +int mask =ilog2 (roundup_pow_of_two (pages)); desc.qw0 =QI_EIOTLB_PASID (svm->pasid) | QI_EIOTLB_DID(sdev->did) |@@ -142,7 +142,7 @@ static void intel_flush_svm_range_dev (struct intel_svm *svm, struct intel_svm_d* for example, an "address" value of 0x12345f000 will * flush from 0x123440000 to 0x12347ffff (256KiB). */ unsigned long last = address + ((unsigned long )(pages -1 ) <<VTD_PAGE_SHIFT ); -unsigned long mask =__rounddown_pow_of_two (address ^ last); +unsigned long mask =rounddown_pow_of_two (address ^ last); desc.qw1 =QI_DEV_EIOTLB_ADDR ((address & ~mask) | (mask -1 )) |QI_DEV_EIOTLB_SIZE ;drivers/iommu/intel_irq_remapping.c +1
-1@@ -113,7 +113,7 @@ static int alloc_irte(struct intel_iommu *iommu,return -1 ;if (count >1 ) { - count =__roundup_pow_of_two (count); + count =roundup_pow_of_two (count); mask =ilog2 (count); }drivers/net/ethernet/amd/xgbe/xgbe-ethtool.c +2
-2@@ -680,13 +680,13 @@ static int xgbe_set_ringparam(struct net_device *netdev,return -EINVAL ; } - rx =__rounddown_pow_of_two (ringparam->rx_pending); + rx =rounddown_pow_of_two (ringparam->rx_pending);if (rx != ringparam->rx_pending)netdev_notice (netdev,"rx ring parameter rounded to power of two: %u\n" , rx); - tx =__rounddown_pow_of_two (ringparam->tx_pending); + tx =rounddown_pow_of_two (ringparam->tx_pending);if (tx != ringparam->tx_pending) netdev_notice(netdev, "tx ring parameter rounded to power of two: %u\n",drivers/net/ethernet/marvell/sky2.c +1
-1@@ -4139,7 +4139,7 @@ static int sky2_set_coalesce(struct net_device *dev,*/ static unsigned long roundup_ring_size (unsigned long pending) { -return max (128ul ,roundup_pow_of_two (pending+1 )); +return max (128ull ,roundup_pow_of_two (pending+1 )); } static void sky2_get_ringparam(struct net_device *dev,drivers/net/ethernet/rocker/rocker_hw.h +2
-2@@ -88,8 +88,8 @@ enum rocker_dma_type { };/* Rocker DMA ring size limits and default sizes */ -#define ROCKER_DMA_SIZE_MIN 2ul -#define ROCKER_DMA_SIZE_MAX 65536ul +#define ROCKER_DMA_SIZE_MIN 2ull +#define ROCKER_DMA_SIZE_MAX 65536ull#define ROCKER_DMA_CMD_DEFAULT_SIZE 32ul#define ROCKER_DMA_EVENT_DEFAULT_SIZE 32ul#define ROCKER_DMA_TX_DEFAULT_SIZE 64uldrivers/net/ethernet/sfc/ef10.c +1
-1@@ -27,7 +27,7 @@ enum { };/* The maximum size of a shared RSS context */ /* TODO: this should really be from the mcdi protocol export */ -#define EFX_EF10_MAX_SHARED_RSS_CONTEXT_SIZE 64UL +#define EFX_EF10_MAX_SHARED_RSS_CONTEXT_SIZE 64ULL/* The filter table(s) are managed by firmware and we have write-only * access. When removing filters we must identify them to the drivers/net/ethernet/sfc/efx.h +1
-1@@ -52,7 +52,7 @@ void efx_schedule_slow_fill(struct efx_rx_queue *rx_queue);#define EFX_MAX_DMAQ_SIZE 4096UL#define EFX_DEFAULT_DMAQ_SIZE 1024UL -#define EFX_MIN_DMAQ_SIZE 512UL +#define EFX_MIN_DMAQ_SIZE 512ULL#define EFX_MAX_EVQ_SIZE 16384UL#define EFX_MIN_EVQ_SIZE 512ULdrivers/net/ethernet/sfc/falcon/efx.h +1
-1@@ -55,7 +55,7 @@ void ef4_schedule_slow_fill(struct ef4_rx_queue *rx_queue);#define EF4_MAX_DMAQ_SIZE 4096UL#define EF4_DEFAULT_DMAQ_SIZE 1024UL -#define EF4_MIN_DMAQ_SIZE 512UL +#define EF4_MIN_DMAQ_SIZE 512ULL#define EF4_MAX_EVQ_SIZE 16384UL#define EF4_MIN_EVQ_SIZE 512ULdrivers/pci/msi.c +1
-1@@ -578,7 +578,7 @@ msi_setup_entry(struct pci_dev *dev, int nvec, struct irq_affinity *affd) entry->msi_attrib.maskbit = !!(control &PCI_MSI_FLAGS_MASKBIT ); entry->msi_attrib.default_irq = dev->irq;/* Save IOAPIC IRQ */ entry->msi_attrib.multi_cap = (control &PCI_MSI_FLAGS_QMASK ) >>1 ; - entry->msi_attrib.multiple =ilog2 (__roundup_pow_of_two (nvec)); + entry->msi_attrib.multiple =ilog2 (roundup_pow_of_two (nvec));if (control &PCI_MSI_FLAGS_64BIT ) entry->mask_pos = dev->msi_cap +PCI_MSI_MASK_64 ;include/linux/log2.h +10
-34@@ -47,26 +47,6 @@ bool is_power_of_2(unsigned long n)return (n !=0 && ((n & (n -1 )) ==0 )); } -/** -* __roundup_pow_of_two() - round up to nearest power of two -* @n: value to round up -*/ -static inline __attribute__((const)) -unsigned long __roundup_pow_of_two (unsigned long n) -{ -return 1UL <<fls_long (n -1 ); -} - -/** -* __rounddown_pow_of_two() - round down to nearest power of two -* @n: value to round down -*/ -static inline __attribute__((const)) -unsigned long __rounddown_pow_of_two (unsigned long n) -{ -return 1UL << (fls_long (n) -1 ); -} -/** * const_ilog2 - log base 2 of 32-bit or a 64-bit constant unsigned value * @n: parameter @@ -170,14 +150,11 @@ unsigned long __rounddown_pow_of_two(unsigned long n)* - the result is undefined when n == 0 * - this can be used to initialise global variables from constant data */ -#define roundup_pow_of_two (n) \ -( \ - __builtin_constant_p(n) ? ( \ - (n == 1) ? 1 : \ - (1UL << (ilog2((n) - 1) + 1)) \ - ) : \ - __roundup_pow_of_two(n) \ - ) +#define roundup_pow_of_two (n) \ +( \ + (__builtin_constant_p(n) && ((n) == 1)) ? \ + 1 : (1ULL << (ilog2((n) - 1) + 1)) \ +)/** * rounddown_pow_of_two - round the given value down to nearest power of two @@ -187,12 +164,11 @@ unsigned long __rounddown_pow_of_two(unsigned long n)* - the result is undefined when n == 0 * - this can be used to initialise global variables from constant data */ -#define rounddown_pow_of_two (n) \ -( \ - __builtin_constant_p(n) ? ( \ - (1UL << ilog2(n))) : \ - __rounddown_pow_of_two(n) \ - ) +#define rounddown_pow_of_two (n) \ +( \ + (__builtin_constant_p(n) && ((n) == 1)) ? \ + 1 : (1ULL << (ilog2(n))) \ +)static inline __attribute_const__ int __order_base_2(unsigned long n)kernel/kexec_core.c +2
-1@@ -1094,7 +1094,8 @@ static int __init crash_notes_memory_init(void)* crash_notes is allocated inside one physical page. */ size =sizeof (note_buf_t); - align =min (roundup_pow_of_two (sizeof (note_buf_t)),PAGE_SIZE ); + align =min (roundup_pow_of_two (sizeof (note_buf_t)), + (unsigned long long )PAGE_SIZE );/* * Break compile if size is bigger than PAGE_SIZE since crash_notes lib/rhashtable.c +1
-1@@ -950,7 +950,7 @@ static size_t rounded_hashtable_size(const struct rhashtable_params *params)if (params->nelem_hint) retsize =max (roundup_pow_of_two (params->nelem_hint *4 /3 ), - (unsigned long )params->min_size); + (unsigned long long )params->min_size);else retsize =max (HASH_DEFAULT_SIZE , (unsigned long )params->min_size);net/sunrpc/xprtrdma/verbs.c +0
-0
net/sunrpc/xprtrdma/verbs.c struct rpcrdma_req *rpcrdma_req_create(struct rpcrdma_xprt *r_xprt, size_t size, · line 1021
Quoted 8 lines
net/sunrpc/xprtrdma/verbs.c +1
-1@@ -1015,7 +1015,7 @@ struct rpcrdma_req *rpcrdma_req_create(struct rpcrdma_xprt *r_xprt, size_t size, maxhdrsize = rpcrdma_fixed_maxsz +3 + r_xprt->rx_ia.ri_max_segs * rpcrdma_readchunk_maxsz; maxhdrsize *=sizeof (__be32); - rb =rpcrdma_regbuf_alloc (__roundup_pow_of_two (maxhdrsize), + rb =rpcrdma_regbuf_alloc (roundup_pow_of_two (maxhdrsize),DMA_TO_DEVICE , flags);if (!rb) goto out2;
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
Robin Murphy
reviewerRe: [PATCH v4 7/8] linux/log2.h: Fix 64bit calculations in roundup/down_pow_two()
In reply to Nicolas Saenz JulienneQuoted 6 lines · Nicolas Saenz Julienne
Some users need to make sure their rounding function accepts and returns 64bit long variables regardless of the architecture. Sadly roundup/rounddown_pow_two() takes and returns unsigned longs. It turns out
ilog2()already handles 32/64bit calculations properly, and being the building block to the round functions we can rework them as a wrapper around it.
Neat! Although all the additional ULL casts this introduces seem somewhat unwelcome - I suppose the (1ULL << (ilog2(n))) makes it effectively always return unsigned long long now. Might it make sense to cast the return value to typeof(n) to avoid this slightly non-obvious behaviour (and the associated churn)?
Robin.
Quoted 418 lines
Suggested-by Robin Murphy <[email protected]>Signed-off-by Nicolas Saenz Julienne <[email protected]>--- drivers/clk/clk-divider.c | 8 ++-- drivers/clk/sunxi/clk-sunxi.c | 2 +- drivers/infiniband/hw/hfi1/chip.c | 4 +- drivers/infiniband/hw/hfi1/init.c | 4 +- drivers/infiniband/hw/mlx4/srq.c | 2 +- drivers/infiniband/hw/mthca/mthca_srq.c | 2 +- drivers/infiniband/sw/rxe/rxe_qp.c | 4 +- drivers/iommu/intel-iommu.c | 4 +- drivers/iommu/intel-svm.c | 4 +- drivers/iommu/intel_irq_remapping.c | 2 +- drivers/net/ethernet/amd/xgbe/xgbe-ethtool.c | 4 +- drivers/net/ethernet/marvell/sky2.c | 2 +- drivers/net/ethernet/rocker/rocker_hw.h | 4 +- drivers/net/ethernet/sfc/ef10.c | 2 +- drivers/net/ethernet/sfc/efx.h | 2 +- drivers/net/ethernet/sfc/falcon/efx.h | 2 +- drivers/pci/msi.c | 2 +- include/linux/log2.h | 44 +++++--------------- kernel/kexec_core.c | 3 +- lib/rhashtable.c | 2 +- net/sunrpc/xprtrdma/verbs.c | 2 +- 21 files changed, 41 insertions(+), 64 deletions(-)drivers/clk/clk-divider.c +4
-4@@ -222,7 +222,7 @@ static int _div_round_up(const struct clk_div_table *table,int div =DIV_ROUND_UP_ULL ((u64 )parent_rate, rate);if (flags &CLK_DIVIDER_POWER_OF_TWO ) - div =__roundup_pow_of_two (div); + div =roundup_pow_of_two (div);if (table) div =_round_up_table (table, div);@@ -240,8 +240,8 @@ static int _div_round_closest(const struct clk_div_table *table, down = parent_rate / rate;if (flags &CLK_DIVIDER_POWER_OF_TWO ) { - up =__roundup_pow_of_two (up); - down =__rounddown_pow_of_two (down); + up =roundup_pow_of_two (up); + down =rounddown_pow_of_two (down); }else if (table) { up =_round_up_table (table, up); down =_round_down_table (table, down);@@ -278,7 +278,7 @@ static int _next_div(const struct clk_div_table *table, int div, div++;if (flags &CLK_DIVIDER_POWER_OF_TWO ) -return __roundup_pow_of_two (div); +return roundup_pow_of_two (div);if (table)return _round_up_table (table, div);drivers/clk/sunxi/clk-sunxi.c +1
-1@@ -311,7 +311,7 @@ static void sun6i_get_ahb1_factors(struct factors_request *req) calcm =DIV_ROUND_UP (div,1 << calcp); }else { - calcp =__roundup_pow_of_two (div); + calcp =roundup_pow_of_two (div); calcp = calcp >3 ?3 : calcp; }drivers/infiniband/hw/hfi1/chip.c +2
-2@@ -14199,10 +14199,10 @@ static int qos_rmt_entries(struct hfi1_devdata *dd, unsigned int *mp, max_by_vl = krcvqs[i];if (max_by_vl >32 ) goto no_qos; - m =ilog2 (__roundup_pow_of_two (max_by_vl)); + m =ilog2 (roundup_pow_of_two (max_by_vl));/* determine bits for vl */ - n =ilog2 (__roundup_pow_of_two (num_vls)); + n =ilog2 (roundup_pow_of_two (num_vls));/* reject if too much is used */ if ((m + n) >7 )drivers/infiniband/hw/hfi1/init.c +2
-2@@ -467,7 +467,7 @@ int hfi1_create_ctxtdata(struct hfi1_pportdata *ppd, int numa,* MTU supported. */ if (rcd->egrbufs.size < hfi1_max_mtu) { - rcd->egrbufs.size =__roundup_pow_of_two (hfi1_max_mtu); + rcd->egrbufs.size =roundup_pow_of_two (hfi1_max_mtu);hfi1_cdbg (PROC ,"ctxt%u: eager bufs size too small. Adjusting to %u\n" , rcd->ctxt, rcd->egrbufs.size);@@ -1959,7 +1959,7 @@ int hfi1_setup_eagerbufs(struct hfi1_ctxtdata *rcd)* to satisfy the "multiple of 8 RcvArray entries" requirement. */ if (rcd->egrbufs.size <= (1 <<20 )) - rcd->egrbufs.rcvtid_size =max ((unsigned long )round_mtu, + rcd->egrbufs.rcvtid_size =max ((unsigned long long )round_mtu,rounddown_pow_of_two (rcd->egrbufs.size /8 )); while (alloced_bytes < rcd->egrbufs.size &&drivers/infiniband/hw/mlx4/srq.c +1
-1@@ -96,7 +96,7 @@ int mlx4_ib_create_srq(struct ib_srq *ib_srq, srq->msrq.max =roundup_pow_of_two (init_attr->attr.max_wr +1 ); srq->msrq.max_gs = init_attr->attr.max_sge; - desc_size =max (32UL , + desc_size =max (32ULL ,roundup_pow_of_two (sizeof (struct mlx4_wqe_srq_next_seg ) + srq->msrq.max_gs *sizeof (struct mlx4_wqe_data_seg )));drivers/infiniband/hw/mthca/mthca_srq.c +1
-1@@ -225,7 +225,7 @@ int mthca_alloc_srq(struct mthca_dev *dev, struct mthca_pd *pd,else srq->max = srq->max +1 ; - ds =max (64UL , + ds =max (64ULL ,roundup_pow_of_two (sizeof (struct mthca_next_seg ) + srq->max_gs *sizeof (struct mthca_data_seg )));drivers/infiniband/sw/rxe/rxe_qp.c +2
-2@@ -592,7 +592,7 @@ int rxe_qp_from_attr(struct rxe_qp *qp, struct ib_qp_attr *attr, int mask,int err;if (mask &IB_QP_MAX_QP_RD_ATOMIC ) { -int max_rd_atomic =__roundup_pow_of_two (attr->max_rd_atomic); +int max_rd_atomic =roundup_pow_of_two (attr->max_rd_atomic); qp->attr.max_rd_atomic = max_rd_atomic;atomic_set (&qp->req.rd_atomic, max_rd_atomic);@@ -600,7 +600,7 @@ int rxe_qp_from_attr(struct rxe_qp *qp, struct ib_qp_attr *attr, int mask,if (mask &IB_QP_MAX_DEST_RD_ATOMIC ) {int max_dest_rd_atomic = -__roundup_pow_of_two (attr->max_dest_rd_atomic); +roundup_pow_of_two (attr->max_dest_rd_atomic); qp->attr.max_dest_rd_atomic = max_dest_rd_atomic;drivers/iommu/intel-iommu.c +2
-2@@ -1488,7 +1488,7 @@ static void iommu_flush_iotlb_psi(struct intel_iommu *iommu, unsigned long pfn, unsigned int pages, int ih, int map) { - unsigned int mask = ilog2(__roundup_pow_of_two(pages)); + unsigned int mask = ilog2(roundup_pow_of_two(pages));uint64_t addr = (uint64_t )pfn <<VTD_PAGE_SHIFT ;u16 did = domain->iommu_did[iommu->seq_id];@@ -3390,7 +3390,7 @@ static unsigned long intel_alloc_iova(struct device *dev,/* Restrict dma_mask to the width that the iommu can handle */ dma_mask =min_t (uint64_t,DOMAIN_MAX_ADDR (domain->gaw), dma_mask);/* Ensure we reserve the whole size-aligned region */ - nrpages =__roundup_pow_of_two (nrpages); + nrpages =roundup_pow_of_two (nrpages);if (!dmar_forcedac && dma_mask >DMA_BIT_MASK (32 )) {/* drivers/iommu/intel-svm.c +2
-2@@ -115,7 +115,7 @@ static void intel_flush_svm_range_dev (struct intel_svm *svm, struct intel_svm_dQI_EIOTLB_TYPE ; desc.qw1 =0 ; }else { -int mask =ilog2 (__roundup_pow_of_two (pages)); +int mask =ilog2 (roundup_pow_of_two (pages)); desc.qw0 =QI_EIOTLB_PASID (svm->pasid) | QI_EIOTLB_DID(sdev->did) |@@ -142,7 +142,7 @@ static void intel_flush_svm_range_dev (struct intel_svm *svm, struct intel_svm_d* for example, an "address" value of 0x12345f000 will * flush from 0x123440000 to 0x12347ffff (256KiB). */ unsigned long last = address + ((unsigned long )(pages -1 ) <<VTD_PAGE_SHIFT ); -unsigned long mask =__rounddown_pow_of_two (address ^ last); +unsigned long mask =rounddown_pow_of_two (address ^ last); desc.qw1 =QI_DEV_EIOTLB_ADDR ((address & ~mask) | (mask -1 )) |QI_DEV_EIOTLB_SIZE ;drivers/iommu/intel_irq_remapping.c +1
-1@@ -113,7 +113,7 @@ static int alloc_irte(struct intel_iommu *iommu,return -1 ;if (count >1 ) { - count =__roundup_pow_of_two (count); + count =roundup_pow_of_two (count); mask =ilog2 (count); }drivers/net/ethernet/amd/xgbe/xgbe-ethtool.c +2
-2@@ -680,13 +680,13 @@ static int xgbe_set_ringparam(struct net_device *netdev,return -EINVAL ; } - rx =__rounddown_pow_of_two (ringparam->rx_pending); + rx =rounddown_pow_of_two (ringparam->rx_pending);if (rx != ringparam->rx_pending)netdev_notice (netdev,"rx ring parameter rounded to power of two: %u\n" , rx); - tx =__rounddown_pow_of_two (ringparam->tx_pending); + tx =rounddown_pow_of_two (ringparam->tx_pending);if (tx != ringparam->tx_pending) netdev_notice(netdev, "tx ring parameter rounded to power of two: %u\n",drivers/net/ethernet/marvell/sky2.c +1
-1@@ -4139,7 +4139,7 @@ static int sky2_set_coalesce(struct net_device *dev,*/ static unsigned long roundup_ring_size (unsigned long pending) { -return max (128ul ,roundup_pow_of_two (pending+1 )); +return max (128ull ,roundup_pow_of_two (pending+1 )); } static void sky2_get_ringparam(struct net_device *dev,drivers/net/ethernet/rocker/rocker_hw.h +2
-2@@ -88,8 +88,8 @@ enum rocker_dma_type { };/* Rocker DMA ring size limits and default sizes */ -#define ROCKER_DMA_SIZE_MIN 2ul -#define ROCKER_DMA_SIZE_MAX 65536ul +#define ROCKER_DMA_SIZE_MIN 2ull +#define ROCKER_DMA_SIZE_MAX 65536ull#define ROCKER_DMA_CMD_DEFAULT_SIZE 32ul#define ROCKER_DMA_EVENT_DEFAULT_SIZE 32ul#define ROCKER_DMA_TX_DEFAULT_SIZE 64uldrivers/net/ethernet/sfc/ef10.c +1
-1@@ -27,7 +27,7 @@ enum { };/* The maximum size of a shared RSS context */ /* TODO: this should really be from the mcdi protocol export */ -#define EFX_EF10_MAX_SHARED_RSS_CONTEXT_SIZE 64UL +#define EFX_EF10_MAX_SHARED_RSS_CONTEXT_SIZE 64ULL/* The filter table(s) are managed by firmware and we have write-only * access. When removing filters we must identify them to the drivers/net/ethernet/sfc/efx.h +1
-1@@ -52,7 +52,7 @@ void efx_schedule_slow_fill(struct efx_rx_queue *rx_queue);#define EFX_MAX_DMAQ_SIZE 4096UL#define EFX_DEFAULT_DMAQ_SIZE 1024UL -#define EFX_MIN_DMAQ_SIZE 512UL +#define EFX_MIN_DMAQ_SIZE 512ULL#define EFX_MAX_EVQ_SIZE 16384UL#define EFX_MIN_EVQ_SIZE 512ULdrivers/net/ethernet/sfc/falcon/efx.h +1
-1@@ -55,7 +55,7 @@ void ef4_schedule_slow_fill(struct ef4_rx_queue *rx_queue);#define EF4_MAX_DMAQ_SIZE 4096UL#define EF4_DEFAULT_DMAQ_SIZE 1024UL -#define EF4_MIN_DMAQ_SIZE 512UL +#define EF4_MIN_DMAQ_SIZE 512ULL#define EF4_MAX_EVQ_SIZE 16384UL#define EF4_MIN_EVQ_SIZE 512ULdrivers/pci/msi.c +1
-1@@ -578,7 +578,7 @@ msi_setup_entry(struct pci_dev *dev, int nvec, struct irq_affinity *affd) entry->msi_attrib.maskbit = !!(control &PCI_MSI_FLAGS_MASKBIT ); entry->msi_attrib.default_irq = dev->irq;/* Save IOAPIC IRQ */ entry->msi_attrib.multi_cap = (control &PCI_MSI_FLAGS_QMASK ) >>1 ; - entry->msi_attrib.multiple =ilog2 (__roundup_pow_of_two (nvec)); + entry->msi_attrib.multiple =ilog2 (roundup_pow_of_two (nvec));if (control &PCI_MSI_FLAGS_64BIT ) entry->mask_pos = dev->msi_cap +PCI_MSI_MASK_64 ;include/linux/log2.h +10
-34@@ -47,26 +47,6 @@ bool is_power_of_2(unsigned long n)return (n !=0 && ((n & (n -1 )) ==0 )); } -/** -* __roundup_pow_of_two() - round up to nearest power of two -* @n: value to round up -*/ -static inline __attribute__((const)) -unsigned long __roundup_pow_of_two (unsigned long n) -{ -return 1UL <<fls_long (n -1 ); -} - -/** -* __rounddown_pow_of_two() - round down to nearest power of two -* @n: value to round down -*/ -static inline __attribute__((const)) -unsigned long __rounddown_pow_of_two (unsigned long n) -{ -return 1UL << (fls_long (n) -1 ); -} -/** * const_ilog2 - log base 2 of 32-bit or a 64-bit constant unsigned value * @n: parameter @@ -170,14 +150,11 @@ unsigned long __rounddown_pow_of_two(unsigned long n)* - the result is undefined when n == 0 * - this can be used to initialise global variables from constant data */ -#define roundup_pow_of_two (n) \ -( \ - __builtin_constant_p(n) ? ( \ - (n == 1) ? 1 : \ - (1UL << (ilog2((n) - 1) + 1)) \ - ) : \ - __roundup_pow_of_two(n) \ - ) +#define roundup_pow_of_two (n) \ +( \ + (__builtin_constant_p(n) && ((n) == 1)) ? \ + 1 : (1ULL << (ilog2((n) - 1) + 1)) \ +)/** * rounddown_pow_of_two - round the given value down to nearest power of two @@ -187,12 +164,11 @@ unsigned long __rounddown_pow_of_two(unsigned long n)* - the result is undefined when n == 0 * - this can be used to initialise global variables from constant data */ -#define rounddown_pow_of_two (n) \ -( \ - __builtin_constant_p(n) ? ( \ - (1UL << ilog2(n))) : \ - __rounddown_pow_of_two(n) \ - ) +#define rounddown_pow_of_two (n) \ +( \ + (__builtin_constant_p(n) && ((n) == 1)) ? \ + 1 : (1ULL << (ilog2(n))) \ +)static inline __attribute_const__ int __order_base_2(unsigned long n)kernel/kexec_core.c +2
-1@@ -1094,7 +1094,8 @@ static int __init crash_notes_memory_init(void)* crash_notes is allocated inside one physical page. */ size =sizeof (note_buf_t); - align =min (roundup_pow_of_two (sizeof (note_buf_t)),PAGE_SIZE ); + align =min (roundup_pow_of_two (sizeof (note_buf_t)), + (unsigned long long )PAGE_SIZE );/* * Break compile if size is bigger than PAGE_SIZE since crash_notes lib/rhashtable.c +1
-1@@ -950,7 +950,7 @@ static size_t rounded_hashtable_size(const struct rhashtable_params *params)if (params->nelem_hint) retsize =max (roundup_pow_of_two (params->nelem_hint *4 /3 ), - (unsigned long )params->min_size); + (unsigned long long )params->min_size);else retsize =max (HASH_DEFAULT_SIZE , (unsigned long )params->min_size);net/sunrpc/xprtrdma/verbs.c +0
-0
net/sunrpc/xprtrdma/verbs.c struct rpcrdma_req *rpcrdma_req_create(struct rpcrdma_xprt *r_xprt, size_t size, · line 1021
Quoted 8 lines
net/sunrpc/xprtrdma/verbs.c +1
-1@@ -1015,7 +1015,7 @@ struct rpcrdma_req *rpcrdma_req_create(struct rpcrdma_xprt *r_xprt, size_t size, maxhdrsize = rpcrdma_fixed_maxsz +3 + r_xprt->rx_ia.ri_max_segs * rpcrdma_readchunk_maxsz; maxhdrsize *=sizeof (__be32); - rb =rpcrdma_regbuf_alloc (__roundup_pow_of_two (maxhdrsize), + rb =rpcrdma_regbuf_alloc (roundup_pow_of_two (maxhdrsize),DMA_TO_DEVICE , flags);if (!rb) goto out2;
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
Re: [PATCH v4 7/8] linux/log2.h: Fix 64bit calculations in roundup/down_pow_two()
Hi Robin,
Quoted 8 lines · Robin Murphy
Quoted 6 lines · Nicolas Saenz Julienne
Some users need to make sure their rounding function accepts and returns 64bit long variables regardless of the architecture. Sadly roundup/rounddown_pow_two() takes and returns unsigned longs. It turns out
ilog2()already handles 32/64bit calculations properly, and being the building block to the round functions we can rework them as a wrapper around it.
Quoted 5 lines
Neat! Although all the additional ULL casts this introduces seem somewhat unwelcome - I suppose the (1ULL << (ilog2(n))) makes it effectively always return unsigned long long now. Might it make sense to cast the return value to typeof(n) to avoid this slightly non-obvious behaviour (and the associated churn)?
It might alleviate some of the churn alright but I don't think a cast is really going to make the behaviour more obvious. Say your expression is a big mess, you'll have to analyze it to infer the output type, keeping in mind things like integer promotion. See this example, 'params->nelem_hint' and 'params->min_size' are u16:
diff --git a/lib/rhashtable.c b/lib/rhashtable.c index bdb7e4cadf05..70908678c7a8 100644 --- a/lib/rhashtable.c +++ b/lib/rhashtable.c @@ -950,7 +950,7 @@ static size_t rounded_hashtable_size(const struct rhashtable_params *params) if (params->nelem_hint) retsize = max(roundup_pow_of_two(params->nelem_hint * 4 / 3), - (unsigned long)params->min_size); + (unsigned long long)params->min_size); else retsize = max(HASH_DEFAULT_SIZE, (unsigned long)params->min_size);
With a cast the patch will look like this:
diff --git a/lib/rhashtable.c b/lib/rhashtable.c index bdb7e4cadf05..70908678c7a8 100644 --- a/lib/rhashtable.c +++ b/lib/rhashtable.c @@ -950,7 +950,7 @@ static size_t rounded_hashtable_size(const struct rhashtable_params *params) if (params->nelem_hint) retsize = max(roundup_pow_of_two(params->nelem_hint * 4 / 3), - (unsigned long)params->min_size); + (int)params->min_size); else retsize = max(HASH_DEFAULT_SIZE, (unsigned long)params->min_size);
To me it's even less obvious than with a fixed ULL.
My intuition tells me to keep it as similar as the old behaviour, at the expense of the extra churn (which is not that different from the current status quo anyway). That said, I'll be happy to change it.
Regards,
Nicolas
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
Re: [PATCH v4 7/8] linux/log2.h: Fix 64bit calculations in roundup/down_pow_two()
In reply to Nicolas Saenz JulienneYou got the "n" on "down" in the subject, but still missing "of" ;)
Quoted 6 lines · Nicolas Saenz Julienne
Some users need to make sure their rounding function accepts and returns 64bit long variables regardless of the architecture. Sadly roundup/rounddown_pow_two() takes and returns unsigned longs. It turns out
ilog2()already handles 32/64bit calculations properly, and being the building block to the round functions we can rework them as a wrapper around it.
Missing "of" in the function names here.
s/a wrapper/wrappers/
IIUC the point of this is that roundup_pow_of_two() returned "unsigned long", which can be either 32 or 64 bits (worth pointing out, I think), and many callers need something that returns "unsigned long long" (always 64 bits).
It's a nice simplification to remove the "__" variants. Just as a casual reader of this commit message, I'd like to know why we had both the roundup and the __roundup versions in the first place, and why we no longer need both.
include/linux/log2.h unsigned long __rounddown_pow_of_two(unsigned long n) · line 157
Quoted 13 lines
include/linux/log2.h +5
-8-#define roundup_pow_of_two (n) \ -( \ - __builtin_constant_p(n) ? ( \ - (n == 1) ? 1 : \ - (1UL << (ilog2((n) - 1) + 1)) \ - ) : \ - __roundup_pow_of_two(n) \ - ) +#define roundup_pow_of_two (n) \ +( \ + (__builtin_constant_p(n) && ((n) == 1)) ? \ + 1 : (1ULL << (ilog2((n) - 1) + 1)) \ +)
Should the resulting type of this expression always be a ULL, even when n==1, i.e., should it be this?
1ULL : (1ULL << (ilog2((n) - 1) + 1)) \
Or maybe there's no case where that makes a difference?
Bjorn
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
Re: [PATCH v4 7/8] linux/log2.h: Fix 64bit calculations in roundup/down_pow_two()
Quoted 1 line · Bjorn Helgaas
You got the "n" on "down" in the subject, but still missing "of" ;)
Yes, sorry about that, I tend to re-read what I meant to say instead of what it's actually written.
Quoted 10 lines · Nicolas Saenz Julienne
Quoted 6 lines
Some users need to make sure their rounding function accepts and returns 64bit long variables regardless of the architecture. Sadly roundup/rounddown_pow_two() takes and returns unsigned longs. It turns out
ilog2()already handles 32/64bit calculations properly, and being the building block to the round functions we can rework them as a wrapper around it.Missing "of" in the function names here.
s/a wrapper/wrappers/
Noted
Quoted 4 lines
IIUC the point of this is that
roundup_pow_of_two()returned "unsigned long", which can be either 32 or 64 bits (worth pointing out, I think), and many callers need something that returns "unsigned long long" (always 64 bits).
I'll update the commit message to be a more explicit.
Quoted 4 lines
It's a nice simplification to remove the "__" variants. Just as a casual reader of this commit message, I'd like to know why we had both the roundup and the
__roundupversions in the first place, and why we no longer need both.
So, the commit that introduced it (312a0c170945b) meant to use the '__' variant as a helper, but, due to the fact this is a header file, some found it and made use of it. I went over some if the commits introducing '__' usages and none of them seem to acknowledge its use as opposed to the macro version. I think it's fair to say it's a case of cargo-culting.
Quoted 17 lines
include/linux/log2.h unsigned long __rounddown_pow_of_two(unsigned long n) · line 157
Quoted 13 lines
include/linux/log2.h +5
-8-#define roundup_pow_of_two (n) \ -( \ - __builtin_constant_p(n) ? ( \ - (n == 1) ? 1 : \ - (1UL << (ilog2((n) - 1) + 1)) \ - ) : \ - __roundup_pow_of_two(n) \ - ) +#define roundup_pow_of_two (n) \ +( \ + (__builtin_constant_p(n) && ((n) == 1)) ? \ + 1 : (1ULL << (ilog2((n) - 1) + 1)) \ +)Should the resulting type of this expression always be a ULL, even when n==1, i.e., should it be this?
Quoted 3 lines
1ULL : (1ULL << (ilog2((n) - 1) + 1)) \Or maybe there's no case where that makes a difference?
It should be 1ULL on either case.
Regards,
Nicolas
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
PATCH v4 8/8 linux/log2.h: Use roundup/dow_pow_two() on 64bit calculations
In reply to Nicolas Saenz JulienneThe function now is safe to use while expecting a 64bit value. Use it where relevant.
--- drivers/acpi/arm64/iort.c | 2 +- drivers/net/ethernet/mellanox/mlx4/en_clock.c | 3 ++- drivers/of/device.c | 3 ++- drivers/pci/controller/cadence/pcie-cadence-ep.c | 3 ++- drivers/pci/controller/cadence/pcie-cadence.c | 3 ++- drivers/pci/controller/pcie-brcmstb.c | 3 ++- drivers/pci/controller/pcie-rockchip-ep.c | 5 +++-- kernel/dma/direct.c | 2 +- 8 files changed, 15 insertions(+), 9 deletions(-)
drivers/acpi/arm64/iort.c +1 -1
@@ -1090,7 +1090,7 @@ void iort_dma_setup(struct device *dev, u64 *dma_addr, u64 *dma_size)* firmware. */ end = dmaaddr + size -1 ; - mask =DMA_BIT_MASK (ilog2 (end) +1 ); + mask =roundup_pow_of_two (end) -1 ; dev->bus_dma_limit = end; dev->coherent_dma_mask = mask; *dev->dma_mask = mask;
drivers/net/ethernet/mellanox/mlx4/en_clock.c +2 -1
@@ -33,6 +33,7 @@#include <linux/mlx4/device.h> #include <linux/clocksource.h> +#include <linux/log2.h> #include "mlx4_en.h"
@@ -252,7 +253,7 @@ static u32 freq_to_shift(u16 freq) {u32 freq_khz = freq *1000 ;u64 max_val_cycles = freq_khz *1000 *MLX4_EN_WRAP_AROUND_SEC ; -u64 max_val_cycles_rounded =1ULL <<fls64 (max_val_cycles -1 ); +u64 max_val_cycles_rounded =roundup_pow_of_two (max_val_cycles);/* calculate max possible multiplier in order to fit in 64bit */ u64 max_mul =div64_u64 (ULLONG_MAX , max_val_cycles_rounded);
drivers/of/device.c +2 -1
@@ -11,6 +11,7 @@#include <linux/mod_devicetable.h> #include <linux/slab.h> #include <linux/platform_device.h> +#include <linux/log2.h> #include <asm/errno.h> #include "of_private.h"
@@ -149,7 +150,7 @@ int of_dma_configure(struct device *dev, struct device_node *np, bool force_dma)* set by the driver. */ end = dma_addr + size -1 ; - mask =DMA_BIT_MASK (ilog2 (end) +1 ); + mask =roundup_pow_of_two (end) -1 ; dev->coherent_dma_mask &= mask; *dev->dma_mask &= mask;/* ...but only set bus limit if we found valid dma-ranges earlier */
drivers/pci/controller/cadence/pcie-cadence-ep.c +2 -1
@@ -10,6 +10,7 @@#include <linux/platform_device.h> #include <linux/pm_runtime.h> #include <linux/sizes.h> +#include <linux/log2.h> #include "pcie-cadence.h"
@@ -65,7 +66,7 @@ static int cdns_pcie_ep_set_bar(struct pci_epc *epc, u8 fn,* roundup_pow_of_two() returns an unsigned long, which is not suited * for 64bit values. */ - sz =1ULL <<fls64 (sz -1 ); + sz =roundup_pow_of_two (sz); aperture =ilog2 (sz) -7 ;/* 128B -> 0, 256B -> 1, 512B -> 2, ... */ if ((flags &PCI_BASE_ADDRESS_SPACE ) ==PCI_BASE_ADDRESS_SPACE_IO ) {
drivers/pci/controller/cadence/pcie-cadence.c +2 -1
@@ -4,6 +4,7 @@// Author: Cyrille Pitchen <[email protected]> #include <linux/kernel.h> +#include <linux/log2.h> #include "pcie-cadence.h"
@@ -15,7 +16,7 @@ void cdns_pcie_set_outbound_region(struct cdns_pcie *pcie, u8 fn,* roundup_pow_of_two() returns an unsigned long, which is not suited * for 64bit values. */ -u64 sz =1ULL <<fls64 (size -1 ); +u64 sz =roundup_pow_of_two (size);int nbits =ilog2 (sz);u32 addr0, addr1, desc0, desc1;
drivers/pci/controller/pcie-brcmstb.c +2 -1
@@ -627,7 +627,8 @@ static inline int brcm_pcie_get_rc_bar2_size_and_offset(struct brcm_pcie *pcie,return -ENODEV ; *rc_bar2_offset = -entry->offset; - *rc_bar2_size =1ULL <<fls64 (entry->res->end - entry->res->start); + *rc_bar2_size =roundup_pow_of_two (entry->res->end - + entry->res->start +1 );/* * We validate the inbound memory view even though we should trust
drivers/pci/controller/pcie-rockchip-ep.c +3 -2
@@ -16,6 +16,7 @@#include <linux/platform_device.h> #include <linux/pci-epf.h> #include <linux/sizes.h> +#include <linux/log2.h> #include "pcie-rockchip.h"
@@ -70,7 +71,7 @@ static void rockchip_pcie_prog_ep_ob_atu(struct rockchip_pcie *rockchip, u8 fn, u32 r, u32 type, u64 cpu_addr, u64 pci_addr, size_t size) { - u64 sz = 1ULL << fls64(size - 1); + u64 sz = roundup_pow_of_two(size);int num_pass_bits =ilog2 (sz);u32 addr0, addr1, desc0, desc1;bool is_nor_msg = (type ==AXI_WRAPPER_NOR_MSG );
@@ -176,7 +177,7 @@ static int rockchip_pcie_ep_set_bar(struct pci_epc *epc, u8 fn,* roundup_pow_of_two() returns an unsigned long, which is not suited * for 64bit values. */ - sz =1ULL <<fls64 (sz -1 ); + sz =roundup_pow_of_two (sz); aperture =ilog2 (sz) -7 ;/* 128B -> 0, 256B -> 1, 512B -> 2, ... */ if ((flags &PCI_BASE_ADDRESS_SPACE ) ==PCI_BASE_ADDRESS_SPACE_IO ) {
kernel/dma/direct.c +1 -1
@@ -53,7 +53,7 @@ u64 dma_direct_get_required_mask(struct device *dev) {u64 max_dma =phys_to_dma_direct (dev, (max_pfn -1 ) <<PAGE_SHIFT ); -return (1ULL << (fls64 (max_dma) -1 )) *2 -1 ; +return rounddown_pow_of_two (max_dma) *2 -1 ; } static gfp_t __dma_direct_optimal_gfp_mask(struct device *dev, u64 dma_mask,
Signature · 1 line
2.24.0
Re: [PATCH v4 8/8] linux/log2.h: Use roundup/dow_pow_two() on 64bit calculations
Quoted 3 lines · Nicolas Saenz Julienne
The function now is safe to use while expecting a 64bit value. Use it where relevant.
What was wrong with the existing code? This is missing some context.
Quoted 5 lines
Signed-off-by Nicolas Saenz Julienne <[email protected]>--- drivers/acpi/arm64/iort.c | 2 +- drivers/net/ethernet/mellanox/mlx4/en_clock.c | 3 ++- drivers/of/device.c | 3 ++-
In any case,
Quoted 6 lines
drivers/pci/controller/cadence/pcie-cadence-ep.c | 3 ++- drivers/pci/controller/cadence/pcie-cadence.c | 3 ++- drivers/pci/controller/pcie-brcmstb.c | 3 ++- drivers/pci/controller/pcie-rockchip-ep.c | 5 +++-- kernel/dma/direct.c | 2 +- 8 files changed, 15 insertions(+), 9 deletions(-)
Re: [PATCH v4 8/8] linux/log2.h: Use roundup/dow_pow_two() on 64bit calculations
Hi Rob,
Quoted 6 lines · Rob Herring
Quoted 2 lines · Nicolas Saenz Julienne
The function now is safe to use while expecting a 64bit value. Use it where relevant.
What was wrong with the existing code? This is missing some context.
You're right, I'll update it.
For most of files changed the benefit here is factoring out a common pattern using the standard function roundup/down_pow_two() which now provides correct 64bit results.
As for of/device.c and arm64/iort.c it's more of a readability enhancement. I consider it's easier to understand than the current calculation as it abstracts the math.
Quoted 10 lines
Quoted 5 lines
Signed-off-by Nicolas Saenz Julienne <[email protected]>--- drivers/acpi/arm64/iort.c | 2 +- drivers/net/ethernet/mellanox/mlx4/en_clock.c | 3 ++- drivers/of/device.c | 3 ++-In any case,
Acked-by Rob Herring <[email protected]>
Thanks!
Regards,
Nicolas
Re: [PATCH v4 8/8] linux/log2.h: Use roundup/dow_pow_two() on 64bit calculations
In reply to Nicolas Saenz JulienneThe subject contains a couple typos: it's missing "of" and it's missing the "n" on "down".
Quoted 2 lines · Nicolas Saenz Julienne
The function now is safe to use while expecting a 64bit value. Use it where relevant.
Please include the function names ("roundup_pow_of_two()", "rounddown_pow_of_two()") in the changelog so it is self-contained and doesn't depend on the subject.
Quoted 1 line
Signed-off-by Nicolas Saenz Julienne <[email protected]>
With the nits above and below addressed,
Quoted 22 lines
--- drivers/acpi/arm64/iort.c | 2 +- drivers/net/ethernet/mellanox/mlx4/en_clock.c | 3 ++- drivers/of/device.c | 3 ++- drivers/pci/controller/cadence/pcie-cadence-ep.c | 3 ++- drivers/pci/controller/cadence/pcie-cadence.c | 3 ++- drivers/pci/controller/pcie-brcmstb.c | 3 ++- drivers/pci/controller/pcie-rockchip-ep.c | 5 +++-- kernel/dma/direct.c | 2 +- 8 files changed, 15 insertions(+), 9 deletions(-)drivers/pci/controller/cadence/pcie-cadence-ep.c +1
-0@@ -10,6 +10,7 @@#include <linux/platform_device.h> #include <linux/pm_runtime.h> #include <linux/sizes.h> +#include <linux/log2.h> #include "pcie-cadence.h"
drivers/pci/controller/cadence/pcie-cadence-ep.c static int cdns_pcie_ep_set_bar(struct pci_epc *epc, u8 fn, · line 68
Quoted 3 lines
drivers/pci/controller/cadence/pcie-cadence-ep.c +0
-0@@ -65,7 +66,7 @@ static int cdns_pcie_ep_set_bar(struct pci_epc *epc, u8 fn,* roundup_pow_of_two() returns an unsigned long, which is not suited * for 64bit values. */
Please remove the comment above since it no longer applies.
Quoted 18 lines
drivers/pci/controller/cadence/pcie-cadence-ep.c +1
-1- sz =1ULL <<fls64 (sz -1 ); + sz =roundup_pow_of_two (sz); aperture =ilog2 (sz) -7 ;/* 128B -> 0, 256B -> 1, 512B -> 2, ... */ if ((flags &PCI_BASE_ADDRESS_SPACE ) ==PCI_BASE_ADDRESS_SPACE_IO ) {drivers/pci/controller/cadence/pcie-cadence.c +1
-0@@ -4,6 +4,7 @@// Author: Cyrille Pitchen <[email protected]> #include <linux/kernel.h> +#include <linux/log2.h> #include "pcie-cadence.h"
drivers/pci/controller/cadence/pcie-cadence.c void cdns_pcie_set_outbound_region(struct cdns_pcie *pcie, u8 fn, · line 18
Quoted 3 lines
drivers/pci/controller/cadence/pcie-cadence.c +0
-0@@ -15,7 +16,7 @@ void cdns_pcie_set_outbound_region(struct cdns_pcie *pcie, u8 fn,* roundup_pow_of_two() returns an unsigned long, which is not suited * for 64bit values. */
Same here.
Quoted 25 lines
drivers/pci/controller/cadence/pcie-cadence.c +1
-1-u64 sz =1ULL <<fls64 (size -1 ); +u64 sz =roundup_pow_of_two (size);int nbits =ilog2 (sz);u32 addr0, addr1, desc0, desc1;drivers/pci/controller/pcie-rockchip-ep.c +2
-1@@ -16,6 +16,7 @@#include <linux/platform_device.h> #include <linux/pci-epf.h> #include <linux/sizes.h> +#include <linux/log2.h> #include "pcie-rockchip.h" @@ -70,7 +71,7 @@ static void rockchip_pcie_prog_ep_ob_atu(struct rockchip_pcie *rockchip, u8 fn, u32 r, u32 type, u64 cpu_addr, u64 pci_addr, size_t size) { - u64 sz = 1ULL << fls64(size - 1); + u64 sz = roundup_pow_of_two(size);int num_pass_bits =ilog2 (sz);u32 addr0, addr1, desc0, desc1;bool is_nor_msg = (type ==AXI_WRAPPER_NOR_MSG );
drivers/pci/controller/pcie-rockchip-ep.c static int rockchip_pcie_ep_set_bar(struct pci_epc *epc, u8 fn, · line 179
Quoted 3 lines
drivers/pci/controller/pcie-rockchip-ep.c +0
-0@@ -176,7 +177,7 @@ static int rockchip_pcie_ep_set_bar(struct pci_epc *epc, u8 fn,* roundup_pow_of_two() returns an unsigned long, which is not suited * for 64bit values. */
And here.
Quoted 10 lines
drivers/pci/controller/pcie-rockchip-ep.c +1
-1- sz =1ULL <<fls64 (sz -1 ); + sz =roundup_pow_of_two (sz); aperture =ilog2 (sz) -7 ;/* 128B -> 0, 256B -> 1, 512B -> 2, ... */ if ((flags &PCI_BASE_ADDRESS_SPACE ) ==PCI_BASE_ADDRESS_SPACE_IO ) {kernel/dma/direct.c +0
-0
kernel/dma/direct.c u64 dma_direct_get_required_mask(struct device *dev) · line 56
Quoted 5 lines
kernel/dma/direct.c +1
-1@@ -53,7 +53,7 @@ u64 dma_direct_get_required_mask(struct device *dev) {u64 max_dma =phys_to_dma_direct (dev, (max_pfn -1 ) <<PAGE_SHIFT ); -return (1ULL << (fls64 (max_dma) -1 )) *2 -1 ; +return rounddown_pow_of_two (max_dma) *2 -1 ;
Personally I would probably make this one a separate patch since it's qualitatively different than the others and it would avoid the slight awkwardness of the non-greppable "roundup/down_pow_of_two()" construction in the commit subject.
But it's fine either way.
Quoted 6 lines
kernel/dma/direct.c +0
-0} static gfp_t __dma_direct_optimal_gfp_mask(struct device *dev, u64 dma_mask,Signature · 1 line
2.24.0
Re: [PATCH v4 8/8] linux/log2.h: Use roundup/dow_pow_two() on 64bit calculations
Quoted 2 lines · Bjorn Helgaas
The subject contains a couple typos: it's missing "of" and it's missing the "n" on "down".
Noted >
Quoted 7 lines · Nicolas Saenz Julienne
Quoted 2 lines
The function now is safe to use while expecting a 64bit value. Use it where relevant.
Please include the function names ("
roundup_pow_of_two()", "rounddown_pow_of_two()") in the changelog so it is self-contained and doesn't depend on the subject.
Noted
Quoted 5 lines
Quoted 1 line
Signed-off-by Nicolas Saenz Julienne <[email protected]>With the nits above and below addressed,
Thanks!
Quoted 20 lines
Quoted 20 lines
--- drivers/acpi/arm64/iort.c | 2 +- drivers/net/ethernet/mellanox/mlx4/en_clock.c | 3 ++- drivers/of/device.c | 3 ++- drivers/pci/controller/cadence/pcie-cadence-ep.c | 3 ++- drivers/pci/controller/cadence/pcie-cadence.c | 3 ++- drivers/pci/controller/pcie-brcmstb.c | 3 ++- drivers/pci/controller/pcie-rockchip-ep.c | 5 +++-- kernel/dma/direct.c | 2 +- 8 files changed, 15 insertions(+), 9 deletions(-)drivers/pci/controller/cadence/pcie-cadence-ep.c +1
-0@@ -10,6 +10,7 @@#include <linux/platform_device.h> #include <linux/pm_runtime.h> #include <linux/sizes.h> +#include <linux/log2.h> #include "pcie-cadence.h"
Quoted 7 lines
drivers/pci/controller/cadence/pcie-cadence-ep.c static int cdns_pcie_ep_set_bar(struct pci_epc *epc, u8 · line 69
Quoted 5 lines
drivers/pci/controller/cadence/pcie-cadence-ep.c +0
-0@@ -65,7 +66,7 @@ static int cdns_pcie_ep_set_bar(struct pci_epc *epc, u8fn, * roundup_pow_of_two() returns an unsigned long, which is not suited * for 64bit values. */ Please remove the comment above since it no longer applies.
Noted
[...]
Quoted 16 lines
kernel/dma/direct.c u64 dma_direct_get_required_mask(struct device *dev) · line 56
Quoted 10 lines
kernel/dma/direct.c +1
-1@@ -53,7 +53,7 @@ u64 dma_direct_get_required_mask(struct device *dev) {u64 max_dma =phys_to_dma_direct (dev, (max_pfn -1 ) <<PAGE_SHIFT ); -return (1ULL << (fls64 (max_dma) -1 )) *2 -1 ; +return rounddown_pow_of_two (max_dma) *2 -1 ;Personally I would probably make this one a separate patch since it's qualitatively different than the others and it would avoid the slight awkwardness of the non-greppable "roundup/down_pow_of_two()" construction in the commit subject.
Quoted 1 line
But it's fine either way.
I'll split it into two parts, as RobH made a similar complaint.
Regards,
Nicolas