public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Niklas Cassel <cassel@kernel.org>
To: Frank Li <Frank.Li@nxp.com>
Cc: "Manivannan Sadhasivam" <manivannan.sadhasivam@linaro.org>,
	"Krzysztof Wilczyński" <kw@linux.com>,
	"Kishon Vijay Abraham I" <kishon@kernel.org>,
	"Bjorn Helgaas" <bhelgaas@google.com>,
	"Arnd Bergmann" <arnd@arndb.de>,
	"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
	linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org,
	imx@lists.linux.dev, dlemoal@kernel.org, maz@kernel.org,
	tglx@linutronix.de, jdmason@kudzu.us
Subject: Re: [PATCH v5 3/5] PCI: endpoint: pci-epf-test: Add doorbell test support
Date: Mon, 11 Nov 2024 15:43:12 +0100	[thread overview]
Message-ID: <ZzIYAIGjHQJqR5Qt@ryzen> (raw)
In-Reply-To: <20241108-ep-msi-v5-3-a14951c0d007@nxp.com>

On Fri, Nov 08, 2024 at 02:43:30PM -0500, Frank Li wrote:

(snip)

> +static void pci_epf_enable_doorbell(struct pci_epf_test *epf_test, struct pci_epf_test_reg *reg)
> +{
> +	enum pci_barno bar = reg->doorbell_bar;
> +	struct pci_epf *epf = epf_test->epf;
> +	struct pci_epc *epc = epf->epc;
> +	struct pci_epf_bar db_bar;
> +	struct msi_msg *msg;
> +	u64 doorbell_addr;
> +	u32 align;
> +	int ret;
> +
> +	align = epf_test->epc_features->align;
> +	align = align ? align : 128;
> +
> +	if (epf_test->epc_features->bar[bar].type == BAR_FIXED)
> +		align = max(epf_test->epc_features->bar[bar].fixed_size, align);
> +
> +	if (bar < BAR_0 || bar == epf_test->test_reg_bar || !epf->db_msg) {
> +		reg->status |= STATUS_DOORBELL_ENABLE_FAIL;
> +		return;
> +	}
> +
> +	msg = &epf->db_msg[0].msg;
> +	doorbell_addr = msg->address_hi;
> +	doorbell_addr <<= 32;
> +	doorbell_addr |= msg->address_lo;
> +
> +	db_bar.phys_addr = round_down(doorbell_addr, align);
> +	db_bar.barno = bar;
> +	db_bar.size = epf->bar[bar].size;
> +	db_bar.flags = epf->bar[bar].flags;
> +	db_bar.addr = NULL;

Some of the code above ...

> +
> +	ret = pci_epc_set_bar(epc, epf->func_no, epf->vfunc_no, &db_bar);
> +	if (!ret)
> +		reg->status |= STATUS_DOORBELL_ENABLE_SUCCESS;
> +}
> +



> @@ -909,12 +998,46 @@ static int pci_epf_test_bind(struct pci_epf *epf)
>  	if (ret)
>  		return ret;
>  
> +	ret = pci_epf_alloc_doorbell(epf, 1);
> +	if (!ret) {
> +		struct pci_epf_test_reg *reg = epf_test->reg[test_reg_bar];
> +		struct msi_msg *msg = &epf->db_msg[0].msg;
> +		u32 align = epc_features->align;
> +		u64 doorbell_addr;
> +		enum pci_barno bar;
> +
> +		bar = pci_epc_get_next_free_bar(epc_features, test_reg_bar + 1);
> +
> +		ret = request_irq(epf->db_msg[0].virq, pci_epf_test_doorbell_handler, 0,
> +				  "pci-test-doorbell", epf_test);
> +		if (ret) {
> +			dev_err(&epf->dev,
> +				"Failed to request irq %d, doorbell feature is not supported\n",
> +				epf->db_msg[0].virq);
> +			return 0;
> +		}
> +
> +		align = align ? align : 128;
> +
> +		if (epf_test->epc_features->bar[bar].type == BAR_FIXED)
> +			align = max(epf_test->epc_features->bar[bar].fixed_size, align);
> +
> +		doorbell_addr = msg->address_hi;
> +		doorbell_addr <<= 32;
> +		doorbell_addr |= msg->address_lo;
> +
> +		reg->doorbell_addr = doorbell_addr & (align - 1);
> +		reg->doorbell_data = msg->data;
> +		reg->doorbell_bar = bar;

... seems to be duplicated in this function.

Perhaps create a helper function so that you don't need to duplicate it.

Also one function is doing:
reg->doorbell_addr = doorbell_addr & (align - 1);

to align, the other one is doing:
round_down(doorbell_addr, align);

Which seems to be a bit inconsistent.
Anyway, if you move this to a helper, they will both use the same
way to align the address.
(May I suggest that you use ALIGN_DOWN() in the helper.)


Kind regards,
Niklas

  reply	other threads:[~2024-11-11 14:43 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-11-08 19:43 [PATCH v5 0/5] PCI: EP: Add RC-to-EP doorbell with platform MSI controller Frank Li
2024-11-08 19:43 ` [PATCH v5 1/5] PCI: endpoint: Add pci_epc_get_fn() API for customizable filtering Frank Li
2024-11-08 19:43 ` [PATCH v5 2/5] PCI: endpoint: Add RC-to-EP doorbell support using platform MSI controller Frank Li
2024-11-08 19:43 ` [PATCH v5 3/5] PCI: endpoint: pci-epf-test: Add doorbell test support Frank Li
2024-11-11 14:43   ` Niklas Cassel [this message]
2024-11-12 10:25     ` Niklas Cassel
2024-11-08 19:43 ` [PATCH v5 4/5] misc: pci_endpoint_test: Add doorbell test case Frank Li
2024-11-08 19:43 ` [PATCH v5 5/5] tools: PCI: Add 'B' option for test doorbell Frank Li
2024-11-11 14:33 ` [PATCH v5 0/5] PCI: EP: Add RC-to-EP doorbell with platform MSI controller Niklas Cassel

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=ZzIYAIGjHQJqR5Qt@ryzen \
    --to=cassel@kernel.org \
    --cc=Frank.Li@nxp.com \
    --cc=arnd@arndb.de \
    --cc=bhelgaas@google.com \
    --cc=dlemoal@kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=imx@lists.linux.dev \
    --cc=jdmason@kudzu.us \
    --cc=kishon@kernel.org \
    --cc=kw@linux.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=manivannan.sadhasivam@linaro.org \
    --cc=maz@kernel.org \
    --cc=tglx@linutronix.de \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox