diff mbox series

[net-next,2/4] net: ipa: introduce dma_addr_high32()

Message ID 20210317222946.118125-3-elder@linaro.org
State New
Headers show
Series net: ipa: support 32-bit targets | expand

Commit Message

Alex Elder March 17, 2021, 10:29 p.m. UTC
Create a new helper function to encapsulate extracting the
high-order 32 bits of a DMA address.  It returns 0 for builds
in which a DMA address is not 64 bits.

This avoids doing a 32-position shift on a DMA address if it
happens not to be 64 bits wide.

Signed-off-by: Alex Elder <elder@linaro.org>

---
 drivers/net/ipa/gsi.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

-- 
2.27.0

Comments

Florian Fainelli March 17, 2021, 10:47 p.m. UTC | #1
On 3/17/2021 3:29 PM, Alex Elder wrote:
> Create a new helper function to encapsulate extracting the

> high-order 32 bits of a DMA address.  It returns 0 for builds

> in which a DMA address is not 64 bits.

> 

> This avoids doing a 32-position shift on a DMA address if it

> happens not to be 64 bits wide.

> 

> Signed-off-by: Alex Elder <elder@linaro.org>

> ---

>  drivers/net/ipa/gsi.c | 14 ++++++++++++--

>  1 file changed, 12 insertions(+), 2 deletions(-)

> 

> diff --git a/drivers/net/ipa/gsi.c b/drivers/net/ipa/gsi.c

> index 2119367b93ea9..53698c64cf882 100644

> --- a/drivers/net/ipa/gsi.c

> +++ b/drivers/net/ipa/gsi.c

> @@ -688,6 +688,16 @@ static void gsi_evt_ring_doorbell(struct gsi *gsi, u32 evt_ring_id, u32 index)

>  	iowrite32(val, gsi->virt + GSI_EV_CH_E_DOORBELL_0_OFFSET(evt_ring_id));

>  }

>  

> +/* Encapsulate extracting high-order 32 bits of DMA address */

> +static u32 dma_addr_high32(dma_addr_t addr)

> +{

> +#ifdef CONFIG_ARCH_DMA_ADDR_T_64BIT

> +	return (u32)(addr >> 32);


You can probably use upper_32bits() here...

> +#else /* !CONFIG_ARCH_DMA_ADDR_T_64BIT */

> +	return 0;

> +#endif /* !CONFIG_ARCH_DMA_ADDR_T_64BIT */

> +}

> +

>  /* Program an event ring for use */

>  static void gsi_evt_ring_program(struct gsi *gsi, u32 evt_ring_id)

>  {

> @@ -711,7 +721,7 @@ static void gsi_evt_ring_program(struct gsi *gsi, u32 evt_ring_id)

>  	val = evt_ring->ring.addr & GENMASK(31, 0);


...and you can use lower_32bits() here.

>  	iowrite32(val, gsi->virt + GSI_EV_CH_E_CNTXT_2_OFFSET(evt_ring_id));

>  

> -	val = evt_ring->ring.addr >> 32;

> +	val = dma_addr_high32(evt_ring->ring.addr);


Does the compiler do a good job at eliminating the assignment when
CONFIG_ARCH_DMA_ADDR_T_64BIT is not defined?

>  	iowrite32(val, gsi->virt + GSI_EV_CH_E_CNTXT_3_OFFSET(evt_ring_id));

>  

>  	/* Enable interrupt moderation by setting the moderation delay */

> @@ -819,7 +829,7 @@ static void gsi_channel_program(struct gsi_channel *channel, bool doorbell)

>  	val = channel->tre_ring.addr & GENMASK(31, 0);

>  	iowrite32(val, gsi->virt + GSI_CH_C_CNTXT_2_OFFSET(channel_id));

>  

> -	val = channel->tre_ring.addr >> 32;

> +	val = dma_addr_high32(channel->tre_ring.addr);

>  	iowrite32(val, gsi->virt + GSI_CH_C_CNTXT_3_OFFSET(channel_id));

>  

>  	/* Command channel gets low weighted round-robin priority */

> 


-- 
Florian
Alex Elder March 17, 2021, 10:49 p.m. UTC | #2
On 3/17/21 5:47 PM, Florian Fainelli wrote:
>> +/* Encapsulate extracting high-order 32 bits of DMA address */

>> +static u32 dma_addr_high32(dma_addr_t addr)

>> +{

>> +#ifdef CONFIG_ARCH_DMA_ADDR_T_64BIT

>> +	return (u32)(addr >> 32);

> You can probably use upper_32bits() here...


Where is that defined?  I'd be glad to use it.	-Alex
Florian Fainelli March 17, 2021, 11 p.m. UTC | #3
On 3/17/2021 3:49 PM, Alex Elder wrote:
> On 3/17/21 5:47 PM, Florian Fainelli wrote:

>>> +/* Encapsulate extracting high-order 32 bits of DMA address */

>>> +static u32 dma_addr_high32(dma_addr_t addr)

>>> +{

>>> +#ifdef CONFIG_ARCH_DMA_ADDR_T_64BIT

>>> +    return (u32)(addr >> 32);

>> You can probably use upper_32bits() here...

> 

> Where is that defined?  I'd be glad to use it.    -Alex


include/linux/kernel.h, and it is upper_32_bits() and lower_32_bits()
sorry about the missing space.
-- 
Florian
Alex Elder March 18, 2021, 1:33 p.m. UTC | #4
On 3/17/21 6:00 PM, Florian Fainelli wrote:
> 

> 

> On 3/17/2021 3:49 PM, Alex Elder wrote:

>> On 3/17/21 5:47 PM, Florian Fainelli wrote:

>>>> +/* Encapsulate extracting high-order 32 bits of DMA address */

>>>> +static u32 dma_addr_high32(dma_addr_t addr)

>>>> +{

>>>> +#ifdef CONFIG_ARCH_DMA_ADDR_T_64BIT

>>>> +    return (u32)(addr >> 32);

>>> You can probably use upper_32bits() here...

>>

>> Where is that defined?  I'd be glad to use it.    -Alex

> 

> include/linux/kernel.h, and it is upper_32_bits() and lower_32_bits()

> sorry about the missing space.


That's nice.  I'll still use a separate commit (and will
credit you with the suggestion) but it will be much smaller.

Thanks.  I'll post v2 shortly.

					-Alex
diff mbox series

Patch

diff --git a/drivers/net/ipa/gsi.c b/drivers/net/ipa/gsi.c
index 2119367b93ea9..53698c64cf882 100644
--- a/drivers/net/ipa/gsi.c
+++ b/drivers/net/ipa/gsi.c
@@ -688,6 +688,16 @@  static void gsi_evt_ring_doorbell(struct gsi *gsi, u32 evt_ring_id, u32 index)
 	iowrite32(val, gsi->virt + GSI_EV_CH_E_DOORBELL_0_OFFSET(evt_ring_id));
 }
 
+/* Encapsulate extracting high-order 32 bits of DMA address */
+static u32 dma_addr_high32(dma_addr_t addr)
+{
+#ifdef CONFIG_ARCH_DMA_ADDR_T_64BIT
+	return (u32)(addr >> 32);
+#else /* !CONFIG_ARCH_DMA_ADDR_T_64BIT */
+	return 0;
+#endif /* !CONFIG_ARCH_DMA_ADDR_T_64BIT */
+}
+
 /* Program an event ring for use */
 static void gsi_evt_ring_program(struct gsi *gsi, u32 evt_ring_id)
 {
@@ -711,7 +721,7 @@  static void gsi_evt_ring_program(struct gsi *gsi, u32 evt_ring_id)
 	val = evt_ring->ring.addr & GENMASK(31, 0);
 	iowrite32(val, gsi->virt + GSI_EV_CH_E_CNTXT_2_OFFSET(evt_ring_id));
 
-	val = evt_ring->ring.addr >> 32;
+	val = dma_addr_high32(evt_ring->ring.addr);
 	iowrite32(val, gsi->virt + GSI_EV_CH_E_CNTXT_3_OFFSET(evt_ring_id));
 
 	/* Enable interrupt moderation by setting the moderation delay */
@@ -819,7 +829,7 @@  static void gsi_channel_program(struct gsi_channel *channel, bool doorbell)
 	val = channel->tre_ring.addr & GENMASK(31, 0);
 	iowrite32(val, gsi->virt + GSI_CH_C_CNTXT_2_OFFSET(channel_id));
 
-	val = channel->tre_ring.addr >> 32;
+	val = dma_addr_high32(channel->tre_ring.addr);
 	iowrite32(val, gsi->virt + GSI_CH_C_CNTXT_3_OFFSET(channel_id));
 
 	/* Command channel gets low weighted round-robin priority */