Updated MSI Patches
Subsystems (3)
Hi,
Here is an updated version of the MSI patch I posted for comments several weeks ago. The patches below are based on kernel version 2.6.0-test2. The changes from the original patch include:
- Separate the original patch into two patches - a vector base patch and MSI patch based on the vector base. The vector base patch replaces irq index scheme with vector-base index scheme. MSI patch requires the vector base patch to allocate new vectors on the fly.
- Change the interface name from msi_alloc_vectors to msix_alloc_vectors since
this interface is used for MSI-X device drivers, which request for additional
messages.
- Change the interface name from msi_free_vectors to msix_free_vectors since
this interface is used for MSI-X device drivers, which request for releasing
the number of vector back to the PCI subsystem.
- Change the function name from remove_hotplug_vectors tomsi_remove_pci_irq_vectors to have a close match with function namemsi_get_pci_irq_vector.
- Fix a bug in function which processes boot parameter "device_nomsi="
- Add MSI support to PCI hotplug by making MSI support transparent to hotplug
controller drivers. The original patch required the hotplug controller drivers
to explicitly call msi_get_pci_irq_vector and msi_remove_pci_irq_vectors
functions during hot-add/hot-remove operations. This approach is not a good
idea since it requires changes in the hot plug controller drivers. This patch
makes MSI support transparent to any hotplug controller drivers.
- Add Documentation/MSI-HOWTO.txt to describe the basics of MSI, the
advantages of using MSI over traditional interrupt mechanism, and how to
enable the device drivers to use MSI or MSI-X. Also included is a description
of debugging features available and Frequently Asked Questions.
I'd appreciate any feedback you have on the patch.
Thanks,
Tom
arch/i386/Kconfig +11 -0
@@ -1072,6 +1072,17 @@ depends on PCI && ((PCI_GODIRECT || PCI_GOANY) || X86_VISWS) default y +config PCI_USE_VECTOR + bool "PCI_USE_VECTOR" + default n + help + This replaces the current existing IRQ-based index interrupt scheme + with the vector-base index scheme. The advantages of vector base over IRQ base are listed below: + 1) Support MSI implementation. + 2) Support future IOxAPIC hotplug + + If you don't know what to do here, say N. + source "drivers/pci/Kconfig" config ISA
arch/i386/kernel/i8259.c +3 -1
@@ -419,8 +419,10 @@* us. (some of these will be overridden and become * 'special' SMP interrupts) */ -for (i =0 ; i <NR_IRQS ; i++) { +for (i =0 ; i < (NR_VECTORS -FIRST_EXTERNAL_VECTOR ); i++) {int vector =FIRST_EXTERNAL_VECTOR + i; +if (i >=NR_IRQS ) +break ;if (vector !=SYSCALL_VECTOR )set_intr_gate (vector, interrupt[i]); }
arch/i386/kernel/io_apic.c +72 -17
170 lines not on this page · raw message
arch/i386/kernel/mpparse.c +10 -0
@@ -1124,6 +1124,11 @@if ((1 <<bit) & mp_ioapic_routing[ioapic].pin_programmed[idx]) {printk (KERN_DEBUG "Pin %d-%d already programmed\n" , mp_ioapic_routing[ioapic].apic_id, ioapic_pin); +#ifdef CONFIG_PCI_USE_VECTOR +if (!platform_legacy_irq (irq)) + entry->irq =IO_APIC_VECTOR (irq); + else +#endif entry->irq = irq;continue ; }
@@ -1131,6 +1136,11 @@ mp_ioapic_routing[ioapic].pin_programmed[idx] |= (1 <<bit); if (!io_apic_set_pci_routing(ioapic, ioapic_pin, irq)) +#ifdef CONFIG_PCI_USE_VECTOR +if (!platform_legacy_irq (irq)) + entry->irq =IO_APIC_VECTOR (irq); + else +#endif entry->irq = irq; printk(KERN_DEBUG "%02x:%02x:%02x[%c] -> %d-%d -> IRQ %d\n",
arch/i386/pci/irq.c +5 -0
@@ -743,6 +743,11 @@ bridge->bus->number, PCI_SLOT(bridge->devfn), pin, irq); }if (irq >=0 ) { +#ifdef CONFIG_PCI_USE_VECTOR +if (!platform_legacy_irq (irq)) + irq =IO_APIC_VECTOR (irq); +#endif +printk (KERN_INFO "PCI->APIC IRQ transform: (B%d,I%d,P%d) -> %d\n" , dev->bus->number,PCI_SLOT (dev->devfn), pin, irq); dev->irq = irq;
include/asm-i386/hw_irq.h +1 -0
@@ -41,6 +41,7 @@ extern asmlinkage void error_interrupt(void); extern asmlinkage void spurious_interrupt(void); extern asmlinkage void thermal_interrupt(struct pt_regs); +#define platform_legacy_irq (irq) ((irq) < 16)#endif extern void mask_irq (unsigned int irq);
include/asm-i386/mach-default/irq_vectors.h +5 -0
@@ -76,9 +76,14 @@* Since vectors 0x00-0x1f are used/reserved for the CPU, * the usable vector space is 0x20-0xff (224 vectors) */ +#define NR_VECTORS 256#ifdef CONFIG_X86_IO_APIC +#ifndef CONFIG_PCI_USE_VECTOR #define NR_IRQS 224#else +#define NR_IRQS FIRST_SYSTEM_VECTOR +#endif +#else #define NR_IRQS 16#endif
arch/i386/Kconfig +32 -0
@@ -1083,6 +1083,38 @@ If you don't know what to do here, say N. +config PCI_MSI + bool "ENABLE PCI MSI" + depends on PCI_USE_VECTOR + default n + help + MSI means Message Signaled Interrupt, which allows any MSI-capable + hardware device to send an inbound Memory Write on its PCI bus + instead of asserting IRQ signal on device IRQ pin. + + This provides PCI MSI support. Enabling PCI MSI support requires + users set CONFIG_PCI_USE_VECTOR and this parameter since MSI support + requires vector base indexing support. + + If you don't know what MSI is or enabling MSI does not serve you + any goods, say N. + +config PCI_MSI_ON_SPECIFIC_DEVICES + bool "ENABLE MSI ON SPECIFIC DEVICES (DEBUG)" + depends on PCI_MSI + default y + help + This provides users with an option, which enables MSI on specific + devices instead of all (the default of the configuration parameter + CONFIG_PCI_MSI). This, if set, prohibits the PCI subsystem from + enabling MSI on all MSI capable devices except ones listed in the + boot parameter "device_msi=". + + Since some devices, which may have bugs in MSI, may break once MSI + support is invoked in the kernel, this option serves to enable + specific MSI capable devices, which are fully validated with the + corresponding software drivers. + source "drivers/pci/Kconfig" config ISA
arch/i386/kernel/i386_ksyms.c +5 -0
@@ -166,6 +166,11 @@EXPORT_SYMBOL (IO_APIC_get_PCI_irq_vector);#endif +#ifdef CONFIG_PCI_MSI +EXPORT_SYMBOL (msix_alloc_vectors); +EXPORT_SYMBOL (msix_free_vectors); +#endif +#ifdef CONFIG_MCA EXPORT_SYMBOL (machine_id);#endif
arch/i386/kernel/io_apic.c +19 -0
@@ -427,6 +427,11 @@/* Is this an active IRQ? */ if (!irq_desc[j].action)continue ; +#ifdef CONFIG_PCI_MSI +/* Is this an active MSI? */ +if (msi_desc[j]) +continue ; +#endif if ( package_index == i )IRQ_DELTA (package_index,j) =0 ;/* Determine the total count per processor per IRQ */
@@ -1151,6 +1156,7 @@int irq_vector[NR_IRQS ] = {FIRST_DEVICE_VECTOR ,0 }; +#ifndef CONFIG_PCI_MSI static int __init assign_irq_vector (int irq) {static int current_vector =FIRST_DEVICE_VECTOR , offset =0 ;
@@ -1175,6 +1181,9 @@ return current_vector; } +#else +extern int assign_irq_vector (int irq); +#endif static struct hw_interrupt_type ioapic_level_irq_type;static struct hw_interrupt_type ioapic_edge_irq_type;
@@ -2267,6 +2276,16 @@print_IO_APIC (); } +void restore_ioapic_irq_handler (int irq) +{ +spin_lock (&irq_desc[irq].lock); +if (IO_APIC_irq_trigger (irq)) + irq_desc[irq].handler = &ioapic_level_irq_type; +else + irq_desc[irq].handler = &ioapic_edge_irq_type; +spin_unlock (&irq_desc[irq].lock); +} +/* * Called after all the initialization is done. If we didnt find any * APIC bugs then we can allow the modify fast path
arch/i386/kernel/Makefile +1 -0
@@ -24,6 +24,7 @@ obj-$(CONFIG_X86_MPPARSE) += mpparse.o obj-$(CONFIG_X86_LOCAL_APIC) += apic.o nmi.o obj-$(CONFIG_X86_IO_APIC) += io_apic.o +obj-$(CONFIG_PCI_MSI) += pci_msi.o obj-$(CONFIG_SOFTWARE_SUSPEND) += suspend.o suspend_asm.o obj-$(CONFIG_X86_NUMAQ) += numaq.o obj-$(CONFIG_X86_SUMMIT) += summit.o
arch/i386/kernel/pci_msi.c +896 -0
896 lines not on this page · raw message
arch/i386/pci/irq.c +24 -2
@@ -714,6 +714,18 @@ dev =NULL ;while ((dev =pci_find_device (PCI_ANY_ID ,PCI_ANY_ID , dev)) !=NULL ) { +int irq; + +#ifdef CONFIG_PCI_MSI +if ((irq =msi_get_pci_irq_vector (dev)) >0 ) { + dev->irq = irq; +printk (KERN_INFO "PCI->MSI vector:(B%d,S%d,F%d)->%d\n" , + dev->bus->number,PCI_SLOT (dev->devfn), +PCI_FUNC (dev->devfn), irq); +continue ; + } +#endif +pci_read_config_byte (dev,PCI_INTERRUPT_PIN , &pin);#ifdef CONFIG_X86_IO_APIC /*
@@ -721,8 +733,6 @@*/ if (io_apic_assign_pci_irqs) { -int irq; -if (pin) { pin--;/* interrupt pins are numbered starting from 1 */ irq =IO_APIC_get_PCI_irq_vector (dev->bus->number,PCI_SLOT (dev->devfn), pin);
@@ -812,6 +822,18 @@ {u8 pin;extern int interrupt_line_quirk; + +#ifdef CONFIG_PCI_MSI +int irq; +if ((irq =msi_get_pci_irq_vector (dev)) >0 ) { + dev->irq = irq; +printk (KERN_INFO "PCI->MSI vector:(B%d,S%d,F%d)->%d\n" , + dev->bus->number,PCI_SLOT (dev->devfn), +PCI_FUNC (dev->devfn), irq); +return 0 ; + } +#endif +pci_read_config_byte (dev,PCI_INTERRUPT_PIN , &pin);if (pin && !pcibios_lookup_irq (dev,1 ) && !dev->irq) {char *msg;
Documentation/kernel-parameters.txt +21 -0
@@ -261,6 +261,22 @@ Format: <area>[,<node>] See also Documentation/networking/decnet.txt. + device_nomsi= [HW,HW,...] + Format: HW = DeviceIDVendorID in hex format with prefix + 0x to select a list of specific MSI-capable functions + requesting no MSI support at function-wide. This + option is ignored if either a configured parameter + CONFIG_PCI_MSI is set to 'N' or a configured parameter + CONFIG_PCI_MSI_ON_SPECIFIC_DEVICES is set to 'Y'. + + device_msi= [HW,HW,...] + Format: HW = DeviceIDVendorID in hex format with prefix + 0x to select a list of specific MSI-capable functions + requesting MSI support at function-wide. This + option is ignored if either a configured parameter + CONFIG_PCI_MSI is set to 'N' or a configured parameter + CONFIG_PCI_MSI_ON_SPECIFIC_DEVICES is set to 'N'. + devfs= [DEVFS] See Documentation/filesystems/devfs/boot-options.
@@ -694,6 +710,11 @@ See header of drivers/block/paride/pcd.c. See also Documentation/paride.txt. + pci_nomsi If user sets a configured parameter CONFIG_PCI_MSI + during kernel built, then he/she can use this append + option to disable MSI system-wide support from PCI + subsystem during boot. + pci=option[,option...] [PCI] various PCI subsystem options: off [IA-32] don't probe for the PCI bus bios [IA-32] force use of PCI BIOS, don't access
Documentation/MSI-HOWTO.txt +330 -0
330 lines not on this page · raw message
drivers/acpi/pci_irq.c +13 -1
@@ -49,6 +49,9 @@extern void eisa_set_level_irq (unsigned int irq);#endif +#ifdef CONFIG_PCI_MSI +extern int msi_get_pci_irq_vector (struct pci_dev *dev); +#endif /* -------------------------------------------------------------------------- PCI IRQ Routing Table (PRT) Support
@@ -229,7 +232,7 @@PCI Interrupt Routing Support -------------------------------------------------------------------------- */ -static int +int acpi_pci_irq_lookup (struct pci_bus *bus,int device,int pin) {struct acpi_prt_entry *entry =NULL ;
@@ -326,6 +329,15 @@return_VALUE (-ENODEV ); } +#ifdef CONFIG_PCI_MSI +if ((irq =msi_get_pci_irq_vector (dev)) >0 ) { + dev->irq = irq; +printk (KERN_INFO "PCI->MSI VEC transform:(B%d,I%d,P%d)->%d\n" , + dev->bus->number,PCI_SLOT (dev->devfn), pin, irq); +return_VALUE (dev->irq); + } +#endif +/* * First we check the PCI IRQ routing table (PRT) for an IRQ. PRT * values override any BIOS-assigned IRQs set during boot.
drivers/pci/remove.c +4 -0
@@ -14,6 +14,10 @@ {int i; +#ifdef CONFIG_PCI_MSI +msi_remove_pci_irq_vectors (dev); +#endif +for (i =0 ; i <PCI_NUM_RESOURCES ; i++) {struct resource *res = dev->resource + i;if (res->parent)
include/asm-i386/hw_irq.h +9 -0
@@ -60,6 +60,15 @@extern void send_IPI (int dest,int vector);extern void setup_ioapic_dest (unsigned long mask); +#ifdef CONFIG_PCI_MSI +#include <linux/pci_msi.h> +extern struct msi_desc * msi_desc[NR_IRQS ]; +extern int msi_get_pci_irq_vector (struct pci_dev *dev); +extern int msix_alloc_vectors (struct pci_dev *dev,int *vector,int nvec); +extern int msix_free_vectors (struct pci_dev *dev,int *vector,int nvec); +extern void msi_remove_pci_irq_vectors (struct pci_dev *dev); +#endif +extern unsigned long io_apic_irqs;extern atomic_t irq_err_count;
include/linux/pci.h +5 -0
@@ -36,6 +36,7 @@#define PCI_COMMAND_WAIT 0x80/* Enable address/data stepping */ #define PCI_COMMAND_SERR 0x100/* Enable SERR */ #define PCI_COMMAND_FAST_BACK 0x200/* Enable back-to-back writes */ +#define PCI_COMMAND_INTX_DISABLE 0x400/* INTx Emulation Disable */ #define PCI_STATUS 0x06/* 16 bits */ #define PCI_STATUS_CAP_LIST 0x10/* Support Capability List */
@@ -198,6 +199,8 @@#define PCI_CAP_ID_MSI 0x05/* Message Signalled Interrupts */ #define PCI_CAP_ID_CHSWP 0x06/* CompactPCI HotSwap */ #define PCI_CAP_ID_PCIX 0x07/* PCI-X */ +#define PCI_CAP_ID_PCI_EXPRESS 0x10 +#define PCI_CAP_ID_MSIX 0x11/* MSI-X */ #define PCI_CAP_LIST_NEXT 1/* Next capability in the list */ #define PCI_CAP_FLAGS 2/* Capability defined flags (16 bits) */ #define PCI_CAP_SIZEOF 4
@@ -275,11 +278,13 @@#define PCI_MSI_FLAGS_QSIZE 0x70/* Message queue size configured */ #define PCI_MSI_FLAGS_QMASK 0x0e/* Maximum queue size available */ #define PCI_MSI_FLAGS_ENABLE 0x01/* MSI feature enabled */ +#define PCI_MSI_FLAGS_MASKBIT 0x100/* 64-bit mask bits allowed */ #define PCI_MSI_RFU 3/* Rest of capability flags */ #define PCI_MSI_ADDRESS_LO 4/* Lower 32 bits */ #define PCI_MSI_ADDRESS_HI 8/* Upper 32 bits (if PCI_MSI_FLAGS_64BIT set) */ #define PCI_MSI_DATA_32 8/* 16 bits of data for 32-bit devices */ #define PCI_MSI_DATA_64 12/* 16 bits of data for 64-bit devices */ +#define PCI_MSI_MASK_BIT 16/* Mask bits register */ /* CompactPCI Hotswap Register */
include/linux/pci_msi.h +142 -0
142 lines not on this page · raw message
pcihpd-discuss? Don't you mean the linux-pci mailing list instead?
A few initial comments on your patch:
- Is there any way to dynamically detect if hardware can support MSI?
- If you enable this option, will boxes that do not support it stop working?
A driver has to be modified to use this option, right? Do you have any drivers that have been modified? Without that, I don't think we can test this patch out, right?
arch/i386/kernel/io_apic.c
Quoted 3 lines
diff -X excludes -urN
linux-2.6.0-test2/arch/i386/kernel/io_apic.clinux-2.6.0-test2-create-vectorbase/arch/i386/kernel/io_apic.carch/i386/kernel/io_apic.c +0
-0
You are cluttering up this file with a lot of #ifdefs. Is there any way you can not do this?
Does this break the summit and/or NUMA builds?
include/asm-i386/mach-default/irq_vectors.h line 79
Quoted 8 lines
diff -X excludes -urN
linux-2.6.0-test2/include/asm-i386/mach-default/irq_vectors.hlinux-2.6.0-test2-create-vectorbase/include/asm-i386/mach-default/irq_vectors.hinclude/asm-i386/mach-default/irq_vectors.h +1
-0@@ -76,9 +76,14 @@* Since vectors 0x00-0x1f are used/reserved for the CPU, * the usable vector space is 0x20-0xff (224 vectors) */ +#define NR_VECTORS 256
Will this _always_ be the value? Can boxes have bigger numbers (I haven't seen the spec, so I don't know...)
Care to add a comment about this value?
Quoted 5 lines
diff -X excludes -urN
linux-2.6.0-test2-create-vectorbase/arch/i386/kernel/i386_ksyms.clinux-2.6.0-test2-create-msi/arch/i386/kernel/i386_ksyms.carch/i386/kernel/i386_ksyms.c +0
-0@@ -166,6 +166,11 @@EXPORT_SYMBOL (IO_APIC_get_PCI_irq_vector);
arch/i386/kernel/i386_ksyms.c line 176
Quoted 10 lines
arch/i386/kernel/i386_ksyms.c +5
-0#endif +#ifdef CONFIG_PCI_MSI +EXPORT_SYMBOL (msix_alloc_vectors); +EXPORT_SYMBOL (msix_free_vectors); +#endif +#ifdef CONFIG_MCA EXPORT_SYMBOL (machine_id);#endif
Put the EXPORT_SYMBOL in the files that have the functions. Don't clutter up the ksyms.c files anymore.
Quoted 1 line
+u32 device_nomsi_list[DRIVER_NOMSI_MAX] = {0, };
Shouldn't this be static?
Quoted 1 line
+u32 device_msi_list[DRIVER_NOMSI_MAX] = {0, };
Same with this one?
Quoted 4 lines
arch/i386/kernel/i386_ksyms.c +4
-0+ base = (u32 *)ioremap_nocache (phys_addr, + dev_msi_cap*PCI_MSIX_ENTRY_SIZE *sizeof (u32)); +if (base ==NULL ) + goto free_region;
...
arch/i386/kernel/i386_ksyms.c
Quoted 3 lines
arch/i386/kernel/i386_ksyms.c +3
-0+ *base = address.lo_address.value; + *(base +1 ) = address.hi_address; + *(base +2 ) = *((u32 *)&data);
Don't do direct writes to memory, use the proper function calls. You do this in a few other places too.
That's enough to get the conversation started :)
thanks,
greg k-h
arch/i386/kernel/pci_msi.c
Quoted 3 lines · long
diff -X excludes -urN
linux-2.6.0-test2-create-vectorbase/arch/i386/kernel/pci_msi.clinux-2.6.0-test2-create-msi/arch/i386/kernel/pci_msi.carch/i386/kernel/pci_msi.c +0
-0
Seems like a lot of this file could go into a new file, drivers/pci/msi.c. We'll want to share as much code as possible across all Linux architectures.
Jeff
Quoted 10 lines · Jeff Garzik
arch/i386/kernel/pci_msi.c
Quoted 3 lines · long
diff -X excludes -urN
linux-2.6.0-test2-create-vectorbase/arch/i386/kernel/pci_msi.clinux-2.6.0-test2-create-msi/arch/i386/kernel/pci_msi.carch/i386/kernel/pci_msi.c +0
-0Seems like a lot of this file could go into a new file,
drivers/pci/msi.c. We'll want to share as much code as possible across all Linux architectures.
Yes. The on-chip PCI-X host bridge on PPC44x parts has MSI support, so I can make use of this if it goes in the right place.
--
Matt Porter
[email protected]
Quoted 6 lines · long
- Change the interface name from
msi_free_vectorstomsix_free_vectorssince this interface is used for MSI-X device drivers, which request for releasing the number of vector back to the PCI subsystem.
- Change the function name fromremove_hotplug_vectorstomsi_remove_pci_irq_vectorsto have a close match with function namemsi_get_pci_irq_vector.
I think the vector allocator code can all be arch specific generic, there is no particular reason as to why it has to be MSI specific.
Quoted 10 lines
diff -X excludes -urN
linux-2.6.0-test2/arch/i386/kernel/io_apic.clinux-2.6.0-test2-create-vectorbase/arch/i386/kernel/io_apic.carch/i386/kernel/io_apic.c +3
-0@@ -76,6 +76,20 @@int apic, pin, next; } irq_2_pin[PIN_MAP_SIZE ]; +#ifdef CONFIG_PCI_USE_VECTOR +int vector_irq[NR_IRQS ] = { [0 ...NR_IRQS -1 ] =-1 }; +
arch/i386/kernel/io_apic.c line 91
Quoted 10 lines
arch/i386/kernel/io_apic.c +10
-0+static int platform_irq (int irq) +{ +if (platform_legacy_irq (irq)) +return irq; +else +return vector_irq[irq]; +} +#else +#define platform_irq (irq) (irq) +#endif
I wish you wouldn't mix up vector and irq like this :( This is really beginning to look like IPF. When is an irq an irq and when is a vector a vector? This can get very confusing very quickly. I spent a fair amount of time debugging this last time due to the confusion in the common_interrupt -> do_IRQ path, i'd hate for this to be a permanent fixture. If you're going to change things just change everything (including variable names) instead of making it conditional.
arch/i386/kernel/io_apic.c line 434
Quoted 12 lines
diff -X excludes -urN
linux-2.6.0-test2-create-vectorbase/arch/i386/kernel/io_apic.clinux-2.6.0-test2-create-msi/arch/i386/kernel/io_apic.carch/i386/kernel/io_apic.c +5
-0@@ -427,6 +427,11 @@/* Is this an active IRQ? */ if (!irq_desc[j].action)continue ; +#ifdef CONFIG_PCI_MSI +/* Is this an active MSI? */ +if (msi_desc[j]) +continue ; +#endif
Is there any locking for msi_desc? Or are you relying on something else?
arch/i386/kernel/io_apic.c line 436
Quoted 2 lines
arch/i386/kernel/io_apic.c +2
-0+static int nr_alloc_vectors =0 ; +static int nr_released_vectors =0 ;
No need to initialise to 0 it'll be done for you when .bss gets zeroed.
arch/i386/kernel/io_apic.c
Quoted 2 lines
arch/i386/kernel/io_apic.c +2
-0+if (current_vector ==FIRST_SYSTEM_VECTOR ) +panic ("ran out of interrupt sources!" );
Please just fail and return -ENOSPC or something like that.
Besides my whining thanks for cranking this out.
Zwane