[dpdk-dev,26/28] net/virtio: use eal I/O device memory read/write API

Message ID 1481680558-4003-27-git-send-email-jerin.jacob@caviumnetworks.com (mailing list archive)
State Superseded, archived
Delegated to: Thomas Monjalon
Headers

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel compilation success Compilation OK

Commit Message

Jerin Jacob Dec. 14, 2016, 1:55 a.m. UTC
  From: Santosh Shukla <santosh.shukla@caviumnetworks.com>

Replace the raw I/O device memory read/write access with eal
abstraction for I/O device memory read/write access to fix
portability issues across different architectures.

Signed-off-by: Santosh Shukla <santosh.shukla@caviumnetworks.com>
Signed-off-by: Jerin Jacob <jerin.jacob@caviumnetworks.com>
CC: Huawei Xie <huawei.xie@intel.com>
CC: Yuanhan Liu <yuanhan.liu@linux.intel.com>
---
 drivers/net/virtio/virtio_pci.c | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)
  

Comments

Yuanhan Liu Dec. 14, 2016, 2:46 a.m. UTC | #1
On Wed, Dec 14, 2016 at 07:25:56AM +0530, Jerin Jacob wrote:
> From: Santosh Shukla <santosh.shukla@caviumnetworks.com>
> 
> Replace the raw I/O device memory read/write access with eal
> abstraction for I/O device memory read/write access to fix
> portability issues across different architectures.

I think these APIs are good:

Acked-by: Yuanhan Liu <yuanhan.liu@linux.intel.com>

> Signed-off-by: Santosh Shukla <santosh.shukla@caviumnetworks.com>
> Signed-off-by: Jerin Jacob <jerin.jacob@caviumnetworks.com>
> CC: Huawei Xie <huawei.xie@intel.com>
> CC: Yuanhan Liu <yuanhan.liu@linux.intel.com>

Not a big deal, but I think we normally put the 'Cc' above the SoB.

	--yliu
  
Yuanhan Liu Dec. 14, 2016, 3:02 a.m. UTC | #2
On Wed, Dec 14, 2016 at 07:25:56AM +0530, Jerin Jacob wrote:
>   * Following macros are derived from linux/pci_regs.h, however,
>   * we can't simply include that header here, as there is no such
> @@ -320,37 +322,37 @@ static const struct virtio_pci_ops legacy_ops = {
>  static inline uint8_t
>  io_read8(uint8_t *addr)
>  {
> -	return *(volatile uint8_t *)addr;
> +	return rte_readb(addr);
>  }

Oh, one more comments: why not replacing io_read8 with rte_readb(),
and do similar for others? Then we don't have to define those wrappers.

I think you can also do something similar for other patches?

	--yliu
>  
>  static inline void
>  io_write8(uint8_t val, uint8_t *addr)
>  {
> -	*(volatile uint8_t *)addr = val;
> +	rte_writeb(val, addr);
>  }
>  
>  static inline uint16_t
>  io_read16(uint16_t *addr)
>  {
> -	return *(volatile uint16_t *)addr;
> +	return rte_readw(addr);
>  }
>  
>  static inline void
>  io_write16(uint16_t val, uint16_t *addr)
>  {
> -	*(volatile uint16_t *)addr = val;
> +	rte_writew(val, addr);
>  }
>  
>  static inline uint32_t
>  io_read32(uint32_t *addr)
>  {
> -	return *(volatile uint32_t *)addr;
> +	return rte_readl(addr);
>  }
>  
>  static inline void
>  io_write32(uint32_t val, uint32_t *addr)
>  {
> -	*(volatile uint32_t *)addr = val;
> +	rte_writel(val, addr);
>  }
>  
>  static inline void
> -- 
> 2.5.5
  
Santosh Shukla Dec. 15, 2016, 5:45 a.m. UTC | #3
On Wed, Dec 14, 2016 at 11:02:23AM +0800, Yuanhan Liu wrote:
> On Wed, Dec 14, 2016 at 07:25:56AM +0530, Jerin Jacob wrote:
> >   * Following macros are derived from linux/pci_regs.h, however,
> >   * we can't simply include that header here, as there is no such
> > @@ -320,37 +322,37 @@ static const struct virtio_pci_ops legacy_ops = {
> >  static inline uint8_t
> >  io_read8(uint8_t *addr)
> >  {
> > -	return *(volatile uint8_t *)addr;
> > +	return rte_readb(addr);
> >  }
> 
> Oh, one more comments: why not replacing io_read8 with rte_readb(),
> and do similar for others? Then we don't have to define those wrappers.
> 
> I think you can also do something similar for other patches?

Make sense for the virtio-pci case where API name io_read/write as good as
rte_read/write. However, IMO for other drivers for example ADF_CSR_RD/WR
improves code readability compared to plain rte_read/write.

Also IMO replacing code incident like below 
 
static inline void writel(unsigned int val, volatile void __iomem *addr)
{
-    *(volatile unsigned int *)addr = val;
+    rte_writel(val, addr);
}

with direct rte_read/write more appropriate. does above said make sense
to you?
If so then I will take care for all such driver in V2.

--Santosh.

> 	--yliu
> >  
> >  static inline void
> >  io_write8(uint8_t val, uint8_t *addr)
> >  {
> > -	*(volatile uint8_t *)addr = val;
> > +	rte_writeb(val, addr);
> >  }
> >  
> >  static inline uint16_t
> >  io_read16(uint16_t *addr)
> >  {
> > -	return *(volatile uint16_t *)addr;
> > +	return rte_readw(addr);
> >  }
> >  
> >  static inline void
> >  io_write16(uint16_t val, uint16_t *addr)
> >  {
> > -	*(volatile uint16_t *)addr = val;
> > +	rte_writew(val, addr);
> >  }
> >  
> >  static inline uint32_t
> >  io_read32(uint32_t *addr)
> >  {
> > -	return *(volatile uint32_t *)addr;
> > +	return rte_readl(addr);
> >  }
> >  
> >  static inline void
> >  io_write32(uint32_t val, uint32_t *addr)
> >  {
> > -	*(volatile uint32_t *)addr = val;
> > +	rte_writel(val, addr);
> >  }
> >  
> >  static inline void
> > -- 
> > 2.5.5
  
Yuanhan Liu Dec. 16, 2016, 2:12 a.m. UTC | #4
On Wed, Dec 14, 2016 at 09:45:34PM -0800, Santosh Shukla wrote:
> On Wed, Dec 14, 2016 at 11:02:23AM +0800, Yuanhan Liu wrote:
> > On Wed, Dec 14, 2016 at 07:25:56AM +0530, Jerin Jacob wrote:
> > >   * Following macros are derived from linux/pci_regs.h, however,
> > >   * we can't simply include that header here, as there is no such
> > > @@ -320,37 +322,37 @@ static const struct virtio_pci_ops legacy_ops = {
> > >  static inline uint8_t
> > >  io_read8(uint8_t *addr)
> > >  {
> > > -	return *(volatile uint8_t *)addr;
> > > +	return rte_readb(addr);
> > >  }
> > 
> > Oh, one more comments: why not replacing io_read8 with rte_readb(),
> > and do similar for others? Then we don't have to define those wrappers.
> > 
> > I think you can also do something similar for other patches?
> 
> Make sense for the virtio-pci case where API name io_read/write as good as
> rte_read/write.

Yes, and I think there are few others like this in your example.

> However, IMO for other drivers for example ADF_CSR_RD/WR
> improves code readability compared to plain rte_read/write.

Sure, for such case, we should not replace the macro.

	--yliu
  

Patch

diff --git a/drivers/net/virtio/virtio_pci.c b/drivers/net/virtio/virtio_pci.c
index 9b47165..47c5a2e 100644
--- a/drivers/net/virtio/virtio_pci.c
+++ b/drivers/net/virtio/virtio_pci.c
@@ -41,6 +41,8 @@ 
 #include "virtio_logs.h"
 #include "virtqueue.h"
 
+#include <rte_io.h>
+
 /*
  * Following macros are derived from linux/pci_regs.h, however,
  * we can't simply include that header here, as there is no such
@@ -320,37 +322,37 @@  static const struct virtio_pci_ops legacy_ops = {
 static inline uint8_t
 io_read8(uint8_t *addr)
 {
-	return *(volatile uint8_t *)addr;
+	return rte_readb(addr);
 }
 
 static inline void
 io_write8(uint8_t val, uint8_t *addr)
 {
-	*(volatile uint8_t *)addr = val;
+	rte_writeb(val, addr);
 }
 
 static inline uint16_t
 io_read16(uint16_t *addr)
 {
-	return *(volatile uint16_t *)addr;
+	return rte_readw(addr);
 }
 
 static inline void
 io_write16(uint16_t val, uint16_t *addr)
 {
-	*(volatile uint16_t *)addr = val;
+	rte_writew(val, addr);
 }
 
 static inline uint32_t
 io_read32(uint32_t *addr)
 {
-	return *(volatile uint32_t *)addr;
+	return rte_readl(addr);
 }
 
 static inline void
 io_write32(uint32_t val, uint32_t *addr)
 {
-	*(volatile uint32_t *)addr = val;
+	rte_writel(val, addr);
 }
 
 static inline void