All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Li, Xiaoyun" <xiaoyun.li@intel.com>
To: "Xia, Chenbo" <chenbo.xia@intel.com>, "dev@dpdk.org" <dev@dpdk.org>
Subject: Re: [dpdk-dev] [PATCH 2/8] app/testpmd: use PCI memory resource access APIs
Date: Thu, 16 Sep 2021 06:10:23 +0000	[thread overview]
Message-ID: <DM4PR11MB55340583E99443679B8132C899DC9@DM4PR11MB5534.namprd11.prod.outlook.com> (raw)
In-Reply-To: <20210910022402.26620-3-chenbo.xia@intel.com>

Hi

> -----Original Message-----
> From: Xia, Chenbo <chenbo.xia@intel.com>
> Sent: Friday, September 10, 2021 10:24
> To: dev@dpdk.org
> Cc: Li, Xiaoyun <xiaoyun.li@intel.com>
> Subject: [PATCH 2/8] app/testpmd: use PCI memory resource access APIs
> 
> Currently testpmd uses struct rte_pci_device to access PCI memory resource.
> Since this structure will be internal later, this patch replaces use of
> rte_pci_device with new PCI memory resource access APIs to read/write BAR 0.
> 
> Signed-off-by: Chenbo Xia <chenbo.xia@intel.com>
> ---
>  app/test-pmd/config.c  | 38 +++++++++++-----------------------
>  app/test-pmd/testpmd.h | 46 +++++++++++++++++++++---------------------
>  2 files changed, 35 insertions(+), 49 deletions(-)
> 
<snip>
> 
> @@ -1081,7 +1063,9 @@ port_reg_bit_set(portid_t port_id, uint32_t reg_off,
> uint8_t bit_pos,
>  			(int) bit_v);
>  		return;
>  	}
> -	reg_v = port_id_pci_reg_read(port_id, reg_off);
> +	if (port_id_pci_reg_read(port_id, reg_off, &reg_v))
> +		return;
> +
>  	if (bit_v == 0)
>  		reg_v &= ~(1 << bit_pos);
>  	else
> @@ -1123,7 +1107,9 @@ port_reg_bit_field_set(portid_t port_id, uint32_t
> reg_off,
>  				(unsigned)max_v, (unsigned)max_v);
>  		return;
>  	}
> -	reg_v = port_id_pci_reg_read(port_id, reg_off);
> +	if (port_id_pci_reg_read(port_id, reg_off, &reg_v))
> +		return;
> +
>  	reg_v &= ~(max_v << l_bit); /* Keep unchanged bits */
>  	reg_v |= (value << l_bit); /* Set changed bits */
>  	port_id_pci_reg_write(port_id, reg_off, reg_v); diff --git a/app/test-

In your implementation, port_id_pci_reg_write() can fail. Then the following display shouldn't be called.
So change this function to have return value and check it before use it will be better.

> pmd/testpmd.h b/app/test-pmd/testpmd.h index 16a3598e48..7922807a6e
> 100644
> --- a/app/test-pmd/testpmd.h
> +++ b/app/test-pmd/testpmd.h
<snip>
>  static inline void
> -port_pci_reg_write(struct rte_port *port, uint32_t reg_off, uint32_t reg_v)
> +port_id_pci_reg_write(portid_t pt_id, uint32_t reg_off, uint32_t reg_v)
>  {
> -	const struct rte_pci_device *pci_dev;
> +	struct rte_port *port = &ports[(pt_id)];
> +	char name[RTE_ETH_NAME_MAX_LEN];
>  	const struct rte_bus *bus;
> -	void *reg_addr;
> 
>  	if (!port->dev_info.device) {
>  		fprintf(stderr, "Invalid device\n");
> @@ -721,19 +721,19 @@ port_pci_reg_write(struct rte_port *port, uint32_t
> reg_off, uint32_t reg_v)
> 
>  	bus = rte_bus_find_by_device(port->dev_info.device);
>  	if (bus && !strcmp(bus->name, "pci")) {
> -		pci_dev = RTE_DEV_TO_PCI(port->dev_info.device);
> +		rte_eth_dev_get_name_by_port(pt_id, name);
>  	} else {
>  		fprintf(stderr, "Not a PCI device\n");
>  		return;
>  	}
> 
> -	reg_addr = ((char *)pci_dev->mem_resource[0].addr + reg_off);
> -	*((volatile uint32_t *)reg_addr) = rte_cpu_to_le_32(reg_v);
> +	reg_v = rte_cpu_to_le_32(reg_v);
> +	if (rte_pci_mem_wr32(name, 0, &reg_v, reg_off)) {
> +		fprintf(stderr, "Failed to write register\n");
> +		return;
> +	}
>  }
> 
> -#define port_id_pci_reg_write(pt_id, reg_off, reg_value) \
> -	port_pci_reg_write(&ports[(pt_id)], (reg_off), (reg_value))
> -
>  static inline void
>  get_start_cycles(uint64_t *start_tsc)
>  {
> --
> 2.17.1


  reply	other threads:[~2021-09-16  6:10 UTC|newest]

Thread overview: 59+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-10  2:23 [dpdk-dev] [PATCH 0/8] Removal of PCI bus ABIs Chenbo Xia
2021-09-10  2:23 ` [dpdk-dev] [PATCH 1/8] bus/pci: add new memory resource access APIs Chenbo Xia
2021-09-13 11:59   ` Kinsella, Ray
2021-09-10  2:23 ` [dpdk-dev] [PATCH 2/8] app/testpmd: use PCI " Chenbo Xia
2021-09-16  6:10   ` Li, Xiaoyun [this message]
2021-09-16  6:38     ` Xia, Chenbo
2021-09-10  2:23 ` [dpdk-dev] [PATCH 3/8] examples/ethtool: use PCI library API to get PCI address Chenbo Xia
2021-09-10  2:23 ` [dpdk-dev] [PATCH 4/8] examples/kni: remove unused PCI bus header Chenbo Xia
2021-09-17 15:38   ` Ferruh Yigit
2021-09-10  2:23 ` [dpdk-dev] [PATCH 5/8] test/kni: remove setting of PCI ID and address Chenbo Xia
2021-09-10  7:12   ` David Marchand
2021-09-17 15:38   ` Ferruh Yigit
2021-09-10  2:24 ` [dpdk-dev] [PATCH 6/8] examples/ip_pipeline: " Chenbo Xia
2021-09-10  7:18   ` David Marchand
2021-09-10  8:21     ` Xia, Chenbo
2021-09-17  3:09     ` Xia, Chenbo
2021-09-17 11:55       ` David Marchand
2021-09-17 15:37         ` Ferruh Yigit
2021-09-10  2:24 ` [dpdk-dev] [PATCH 7/8] kni: replace unused variable definition with reserved bytes Chenbo Xia
2021-09-10  2:24 ` [dpdk-dev] [PATCH 8/8] bus/pci: remove ABIs in PCI bus Chenbo Xia
2021-09-13 12:06   ` Kinsella, Ray
2021-09-14  8:15   ` Xu, Rosen
2021-09-18  2:24 ` [dpdk-dev] [PATCH v2 0/7] Removal of PCI bus ABIs Chenbo Xia
2021-09-18  2:24   ` [dpdk-dev] [PATCH v2 1/7] bus/pci: add new memory resource access APIs Chenbo Xia
2021-09-18  2:24   ` [dpdk-dev] [PATCH v2 2/7] app/testpmd: use PCI " Chenbo Xia
2021-09-18  2:44     ` Li, Xiaoyun
2021-09-18  2:24   ` [dpdk-dev] [PATCH v2 3/7] examples/ethtool: use PCI library API to get PCI address Chenbo Xia
2021-09-18  2:24   ` [dpdk-dev] [PATCH v2 4/7] examples/kni: remove unused PCI bus header Chenbo Xia
2021-09-18  2:24   ` [dpdk-dev] [PATCH v2 5/7] kni: remove unused PCI info from test and example Chenbo Xia
2021-09-18  2:24   ` [dpdk-dev] [PATCH v2 6/7] kni: replace unused variable definition with reserved bytes Chenbo Xia
2021-09-18  2:24   ` [dpdk-dev] [PATCH v2 7/7] bus/pci: remove ABIs in PCI bus Chenbo Xia
2021-09-29  7:38   ` [dpdk-dev] [PATCH v2 0/7] Removal of PCI bus ABIs Xia, Chenbo
2021-09-30  8:45     ` David Marchand
2021-10-04 13:37       ` David Marchand
2021-10-04 15:56         ` Harris, James R
2021-10-06  4:25           ` Xia, Chenbo
2021-10-08  6:15             ` Liu, Changpeng
2021-10-08  7:08               ` David Marchand
2021-10-08  7:44                 ` Liu, Changpeng
2021-10-11  6:58                   ` Xia, Chenbo
2021-10-11 12:55                     ` Thomas Monjalon
2021-10-12  0:35                       ` Harris, James R
2021-10-12  7:04                         ` Thomas Monjalon
2021-10-12 16:59                           ` Walker, Benjamin
2021-10-12 18:43                             ` Thomas Monjalon
2021-10-12 19:26                               ` Walker, Benjamin
2021-10-12 21:50                                 ` Thomas Monjalon
2021-10-13 17:56                                   ` Walker, Benjamin
2021-10-13 18:59                                     ` Thomas Monjalon
2021-10-13 22:48                                       ` Walker, Benjamin
2021-10-14  6:41                                         ` Thomas Monjalon
2022-07-11 12:11                                           ` Thomas Monjalon
2021-10-14  2:21                                       ` Xia, Chenbo
2021-10-14  6:41                                         ` Thomas Monjalon
2021-10-14  7:00                                           ` Xia, Chenbo
2021-10-14  7:07                                             ` Thomas Monjalon
2021-10-14  8:07                                               ` Xia, Chenbo
2021-10-14  8:25                                                 ` Thomas Monjalon
2021-10-27 12:03                                                   ` Xia, Chenbo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=DM4PR11MB55340583E99443679B8132C899DC9@DM4PR11MB5534.namprd11.prod.outlook.com \
    --to=xiaoyun.li@intel.com \
    --cc=chenbo.xia@intel.com \
    --cc=dev@dpdk.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.