public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* Question on using MSI in PCI driver
@ 2004-06-22  2:22 Roland Dreier
  2004-06-22  3:50 ` Jeff Garzik
  2004-06-22  4:03 ` [PATCH] Export msi_remove_pci_irq_vectors Roland Dreier
  0 siblings, 2 replies; 12+ messages in thread
From: Roland Dreier @ 2004-06-22  2:22 UTC (permalink / raw)
  To: tom.l.nguyen, linux-kernel

I'm looking at implementing MSI/MSI-X support in a PCI device driver
I'm working on.  However, I've run into an issue with the MSI API that
I would like some clarification on.

When I call pci_enable_msi, since my device is MSI-X capable, the
kernel calls msix_capability_init, which works out the memory region
where vectors should be written and then calls request_region.  (In
fact it calls

             request_mem_region(phys_addr,
		dev_msi_cap * PCI_MSIX_ENTRY_SIZE,
		"MSI-X iomap Failure"))

which leads to a bizarre entry in /proc/iomem with the name "MSI-X
iomap Failure")

The problem is that if I follow the standard route in my driver and
call pci_request_regions() during init (since I want to claim my whole
device), the request_mem_region in msix_capability_init will fail.
Now, for my device, the MSI-X table happens to fall in the middle of a
BAR, and I need to access stuff on both sides of it in that BAR.  To
make things even worse for me, my device has two more BARs I want to claim.

So it seems I am forced to turn my nice clean pci_request_regions()
call into two calls to request_mem_region() (to get the beginning and
end of the BAR with the MSI-X table in it) and two more calls to
pci_request_region() (to get the other two BARs).

This isn't the end of the world but it feels suboptimal to me.  Anyone
have an idea for a better way to do this?  (I'm happy to write a patch
to the kernel if someone suggests how to change the MSI API)

Thanks,
  Roland

^ permalink raw reply	[flat|nested] 12+ messages in thread
* RE: [PATCH] Fix MSI-X setup
@ 2004-06-22 16:21 Nguyen, Tom L
  0 siblings, 0 replies; 12+ messages in thread
From: Nguyen, Tom L @ 2004-06-22 16:21 UTC (permalink / raw)
  To: Roland Dreier, linux-kernel, greg, akpm; +Cc: Nguyen, Tom L

On Monday, June 21, 2004 Roland Dreier wrote: 

>msix_capability_init() puts the offset of the MSI-X capability into
>pos, then uses pos as a loop index to clear the MSI-X vector table,
>and then tries to use pos as the offset again, which results in
>writing the MSI-X enable bit off into space.
>
>This patch fixes that by adding a new loop index variable and using
>that to clear the vector table.

Thanks for detecting this bug and providing a fix with your patch below.

Thanks,
Long

Index: linux-2.6.7/drivers/pci/msi.c
===================================================================
--- linux-2.6.7.orig/drivers/pci/msi.c	2004-06-21 20:51:33.000000000
-0700
+++ linux-2.6.7/drivers/pci/msi.c	2004-06-21 21:30:05.000000000
-0700
@@ -569,7 +569,7 @@
 	struct msi_desc *entry;
 	struct msg_address address;
 	struct msg_data data;
-	int vector = 0, pos, dev_msi_cap;
+	int vector = 0, pos, dev_msi_cap, i;
 	u32 phys_addr, table_offset;
 	u32 control;
 	u8 bir;
@@ -629,12 +629,12 @@
 	writel(address.hi_address, base +
PCI_MSIX_ENTRY_UPPER_ADDR_OFFSET);
 	writel(*(u32*)&data, base + PCI_MSIX_ENTRY_DATA_OFFSET);
 	/* Initialize all entries from 1 up to 0 */
-	for (pos = 1; pos < dev_msi_cap; pos++) {
-		writel(0, base + pos * PCI_MSIX_ENTRY_SIZE +
+	for (i = 1; i < dev_msi_cap; i++) {
+		writel(0, base + i * PCI_MSIX_ENTRY_SIZE +
 			PCI_MSIX_ENTRY_LOWER_ADDR_OFFSET);
-		writel(0, base + pos * PCI_MSIX_ENTRY_SIZE +
+		writel(0, base + i * PCI_MSIX_ENTRY_SIZE +
 			PCI_MSIX_ENTRY_UPPER_ADDR_OFFSET);
-		writel(0, base + pos * PCI_MSIX_ENTRY_SIZE +
+		writel(0, base + i * PCI_MSIX_ENTRY_SIZE +
 			PCI_MSIX_ENTRY_DATA_OFFSET);
 	}
 	attach_msi_entry(entry, vector);


^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2004-06-23 15:28 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-06-22  2:22 Question on using MSI in PCI driver Roland Dreier
2004-06-22  3:50 ` Jeff Garzik
2004-06-22  3:54   ` Roland Dreier
2004-06-22  4:01     ` Jeff Garzik
2004-06-22  4:04       ` Roland Dreier
2004-06-22  4:03 ` [PATCH] Export msi_remove_pci_irq_vectors Roland Dreier
2004-06-22  4:35   ` [PATCH] Fix MSI-X setup Roland Dreier
2004-06-22 23:23     ` Greg KH
2004-06-22 23:57       ` Roland Dreier
2004-06-23  0:04         ` Greg KH
2004-06-22  8:45   ` [PATCH] Export msi_remove_pci_irq_vectors Christoph Hellwig
  -- strict thread matches above, loose matches on Subject: below --
2004-06-22 16:21 [PATCH] Fix MSI-X setup Nguyen, Tom L

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox