PCI: rework pci_enable_ari for support disable ari forwarding
PATCH v2 1/3 PCI: rework pci_enable_ari for support disable ari forwarding
pci_enable_ari will be called if an ARI pci device found, set its bridge ARI Forwarding Enable bit in Device Control 2 Register. But the bridge ARI Forwarding Enable bit will never be cleared when an ARI device hot removed.
1. Hot add an ARI pci device;
2. Hot remove the ARI pci device;
3. Hot add an non ARI pci device;
In this case, we could only find fun 0 of non ARI pci device because of its bridge ARI Forwarding Enable bit set.
As PCIe Spec 2.0(6.13/441) recommends:
"Following a hot-plug event below a Downstream Port, it is strongly recommended that software Clear the ARI Forwarding Enable bit in the Downstream Port until software determines that a newly added component is in fact an ARI Device"
So, this patch rework pci_enable_ari to support enable/disable ARI when a new device hot add.
--- drivers/pci/pci.c | 21 +++++++++++++-------- drivers/pci/pci.h | 2 +- drivers/pci/probe.c | 2 +- 3 files changed, 15 insertions(+), 10 deletions(-)
drivers/pci/pci.c +13 -8
@@ -2010,10 +2010,10 @@ void pci_free_cap_save_buffers(struct pci_dev *dev) }/** -* pci_enable_ari - enable ARI forwarding if hardware support it +* pci_configure_ari - enable or disable ARI forwarding if hardware support it * @dev: the PCI device */ -void pci_enable_ari (struct pci_dev *dev) +void pci_configure_ari (struct pci_dev *dev) {u32 cap;struct pci_dev *bridge;
@@ -2021,9 +2021,6 @@ void pci_enable_ari(struct pci_dev *dev)if (pcie_ari_disabled || !pci_is_pcie (dev) || dev->devfn)return ; -if (!pci_find_ext_capability (dev,PCI_EXT_CAP_ID_ARI )) -return ; - bridge = dev->bus->self;if (!bridge)return ;
@@ -2031,10 +2028,18 @@ void pci_enable_ari(struct pci_dev *dev)pcie_capability_read_dword (bridge,PCI_EXP_DEVCAP2 , &cap);if (!(cap &PCI_EXP_DEVCAP2_ARI ))return ; - -pcie_capability_set_word (bridge,PCI_EXP_DEVCTL2 ,PCI_EXP_DEVCTL2_ARI ); - bridge->ari_enabled =1 ; + +if (pci_find_ext_capability (dev,PCI_EXT_CAP_ID_ARI )) { +pcie_capability_set_word (bridge,PCI_EXP_DEVCTL2 , +PCI_EXP_DEVCTL2_ARI ); + bridge->ari_enabled =1 ; + }else { +pcie_capability_clear_word (bridge,PCI_EXP_DEVCTL2 , +PCI_EXP_DEVCTL2_ARI ); + bridge->ari_enabled =0 ; + } } +EXPORT_SYMBOL (pci_configure_ari);/** * pci_enable_ido - enable ID-based Ordering on a device
drivers/pci/pci.h +1 -1
@@ -211,7 +211,7 @@ extern int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,extern int pci_resource_bar (struct pci_dev *dev,int resno,enum pci_bar_type *type);extern int pci_bus_add_child (struct pci_bus *bus); -extern void pci_enable_ari (struct pci_dev *dev); +extern void pci_configure_ari (struct pci_dev *dev);/** * pci_ari_enabled - query ARI forwarding status * @bus: the PCI bus
drivers/pci/probe.c +1 -1
@@ -1282,7 +1282,7 @@ static void pci_init_capabilities(struct pci_dev *dev)pci_vpd_pci22_init (dev);/* Alternative Routing-ID Forwarding */ -pci_enable_ari (dev); +pci_configure_ari (dev);/* Single Root I/O Virtualization */ pci_iov_init (dev);
Signature · 1 line
1.7.1
PATCH v2 2/3 PCI: introduce pci_next_fn to get next func number
Introduce pci_next_fn function to get next fn number.Since this function maybe used by PCI module(eg. pciehp),so export it.
--- drivers/pci/pci.h | 1 + drivers/pci/probe.c | 67 +++++++++++++++++++++++++++++--------------------- 2 files changed, 40 insertions(+), 28 deletions(-)
drivers/pci/pci.h +1 -0
@@ -212,6 +212,7 @@ extern int pci_resource_bar(struct pci_dev *dev, int resno, enum pci_bar_type *type);extern int pci_bus_add_child (struct pci_bus *bus);extern void pci_configure_ari (struct pci_dev *dev); +extern int pci_next_fn (struct pci_bus *parent,int devfn);/** * pci_ari_enabled - query ARI forwarding status * @bus: the PCI bus
drivers/pci/probe.c +39 -28
91 lines not on this page · raw message
Signature · 1 line
1.7.1
PATCH v2 3/3 PCI, pciehp: ARI device hotplug support
In reply to Yijing WangARI device supports up to 256 Functions, pciehp now only scan and configure Functions from 0 to 7, this patch fix this problem for ARI device hotplug.
--- drivers/pci/hotplug/pciehp_pci.c | 40 ++++++++++++++++++++++++++----------- 1 files changed, 28 insertions(+), 12 deletions(-)
drivers/pci/hotplug/pciehp_pci.c +28 -12
@@ -39,7 +39,7 @@ int pciehp_configure_device(struct slot *p_slot)struct pci_dev *dev;struct pci_dev *bridge = p_slot->ctrl->pcie->port;struct pci_bus *parent = bridge->subordinate; -int num, fn; +int num, fn =0 ;struct controller *ctrl = p_slot->ctrl; dev =pci_get_slot (parent,PCI_DEVFN (0 ,0 ));
@@ -56,21 +56,31 @@ int pciehp_configure_device(struct slot *p_slot)ctrl_err (ctrl,"No new device found\n" );return -ENODEV ; } - -for (fn =0 ; fn <8 ; fn++) { - dev =pci_get_slot (parent,PCI_DEVFN (0 , fn)); + +do { +if (pci_ari_enabled (parent)) + dev =pci_get_slot (parent, fn); +else + dev =pci_get_slot (parent,PCI_DEVFN (0 , fn)); + + fn =pci_next_fn (parent,PCI_DEVFN (0 , fn));if (!dev)continue ;if ((dev->hdr_type ==PCI_HEADER_TYPE_BRIDGE ) || (dev->hdr_type ==PCI_HEADER_TYPE_CARDBUS ))pci_hp_add_bridge (dev);pci_dev_put (dev); - } + }while (fn);pci_assign_unassigned_bridge_resources (bridge); -for (fn =0 ; fn <8 ; fn++) { - dev =pci_get_slot (parent,PCI_DEVFN (0 , fn)); + do { + if (pci_ari_enabled(parent)) + dev = pci_get_slot(parent, fn); + else + dev = pci_get_slot(parent, PCI_DEVFN(0, fn)); + + fn = pci_next_fn(parent, PCI_DEVFN(0, fn)); if (!dev) continue; if ((dev->class >> 16) == PCI_BASE_CLASS_DISPLAY) {
@@ -79,7 +89,7 @@ int pciehp_configure_device(struct slot *p_slot) }pci_configure_slot (dev);pci_dev_put (dev); - } + }while (fn);pci_bus_add_devices (parent);
@@ -89,21 +99,27 @@ int pciehp_configure_device(struct slot *p_slot)int pciehp_unconfigure_device (struct slot *p_slot) {int ret, rc =0 ; -int j; +int fn =0 ;u8 bctl =0 ;u8 presence =0 ;struct pci_bus *parent = p_slot->ctrl->pcie->port->subordinate;u16 command;struct controller *ctrl = p_slot->ctrl; +struct pci_dev *temp;ctrl_dbg (ctrl,"%s: domain:bus:dev = %04x:%02x:00\n" , __func__,pci_domain_nr (parent), parent->number); ret =pciehp_get_adapter_status (p_slot, &presence);if (ret) presence =0 ; + + do { + if (pci_ari_enabled(parent)) + temp = pci_get_slot(parent, fn); + else + temp = pci_get_slot(parent, PCI_DEVFN(0, fn)); -for (j =0 ; j <8 ; j++) { -struct pci_dev *temp =pci_get_slot (parent,PCI_DEVFN (0 , j)); + fn = pci_next_fn(parent, PCI_DEVFN(0, fn)); if (!temp) continue; if (temp->hdr_type == PCI_HEADER_TYPE_BRIDGE && presence) {
@@ -129,7 +145,7 @@ int pciehp_unconfigure_device(struct slot *p_slot)pci_write_config_word (temp,PCI_COMMAND , command); }pci_dev_put (temp); - } + }while (fn);return rc; }
Signature · 1 line
1.7.1
Bjorn Helgaas
maintainerRe: [PATCH v2 3/3] PCI, pciehp: ARI device hotplug support
[+cc Kenji]
Quoted 26 lines · Yijing Wang
ARI device supports up to 256 Functions, pciehp now only scan and configure Functions from 0 to 7, this patch fix this problem for ARI device hotplug.
Signed-off-by Yijing Wang <[email protected]>--- drivers/pci/hotplug/pciehp_pci.c | 40 ++++++++++++++++++++++++++----------- 1 files changed, 28 insertions(+), 12 deletions(-)drivers/pci/hotplug/pciehp_pci.c +1
-2@@ -39,7 +39,7 @@ int pciehp_configure_device(struct slot *p_slot)struct pci_dev *dev;struct pci_dev *bridge = p_slot->ctrl->pcie->port;struct pci_bus *parent = bridge->subordinate; -int num, fn; +int num, fn =0 ;struct controller *ctrl = p_slot->ctrl; dev =pci_get_slot (parent,PCI_DEVFN (0 ,0 ));@@ -56,21 +56,31 @@ int pciehp_configure_device(struct slot *p_slot)ctrl_err (ctrl,"No new device found\n" );return -ENODEV ; } -
drivers/pci/hotplug/pciehp_pci.c int pciehp_configure_device(struct slot *p_slot) · line 66
Quoted 10 lines
drivers/pci/hotplug/pciehp_pci.c +8
-2-for (fn =0 ; fn <8 ; fn++) { - dev =pci_get_slot (parent,PCI_DEVFN (0 , fn)); + + do { + if (pci_ari_enabled(parent)) + dev = pci_get_slot(parent, fn); + else + dev = pci_get_slot(parent, PCI_DEVFN(0, fn)); + + fn = pci_next_fn(parent, PCI_DEVFN(0, fn));
This doesn't make sense to me. We just called pci_scan_slot(), which already used pci_next_fn() to find all the functions. We shouldn't have to have the ARI knowledge and pci_next_fn() looping here again (and yet again after pci_assign_unassigned_bridge_resources()).
According to the pci_scan_slot() function comment, all the newly-discovered devices should be on the bus->devices list. And in fact, the similar code in acpiphp (enable_device()) *does* use the bus->devices list.
I think cpci_configure_slot(), pciehp_configure_device(), enable_slot() in sgi_hotplug.c, and shpchp_configure_device() should be changed to use the bus->devices list. In addition, I think the refcount management (pci_get_slot()/pci_dev_put()) should be removed.
Quoted 76 lines
drivers/pci/hotplug/pciehp_pci.c +19
-9if (!dev)continue ;if ((dev->hdr_type ==PCI_HEADER_TYPE_BRIDGE ) || (dev->hdr_type ==PCI_HEADER_TYPE_CARDBUS ))pci_hp_add_bridge (dev);pci_dev_put (dev); - } + }while (fn);pci_assign_unassigned_bridge_resources (bridge); -for (fn =0 ; fn <8 ; fn++) { - dev =pci_get_slot (parent,PCI_DEVFN (0 , fn)); + do { + if (pci_ari_enabled(parent)) + dev = pci_get_slot(parent, fn); + else + dev = pci_get_slot(parent, PCI_DEVFN(0, fn)); + + fn = pci_next_fn(parent, PCI_DEVFN(0, fn)); if (!dev) continue; if ((dev->class >> 16) == PCI_BASE_CLASS_DISPLAY) {@@ -79,7 +89,7 @@ int pciehp_configure_device(struct slot *p_slot) }pci_configure_slot (dev);pci_dev_put (dev); - } + }while (fn);pci_bus_add_devices (parent);@@ -89,21 +99,27 @@ int pciehp_configure_device(struct slot *p_slot)int pciehp_unconfigure_device (struct slot *p_slot) {int ret, rc =0 ; -int j; +int fn =0 ;u8 bctl =0 ;u8 presence =0 ;struct pci_bus *parent = p_slot->ctrl->pcie->port->subordinate;u16 command;struct controller *ctrl = p_slot->ctrl; +struct pci_dev *temp;ctrl_dbg (ctrl,"%s: domain:bus:dev = %04x:%02x:00\n" , __func__,pci_domain_nr (parent), parent->number); ret =pciehp_get_adapter_status (p_slot, &presence);if (ret) presence =0 ; + + do { + if (pci_ari_enabled(parent)) + temp = pci_get_slot(parent, fn); + else + temp = pci_get_slot(parent, PCI_DEVFN(0, fn)); -for (j =0 ; j <8 ; j++) { -struct pci_dev *temp =pci_get_slot (parent,PCI_DEVFN (0 , j)); + fn = pci_next_fn(parent, PCI_DEVFN(0, fn)); if (!temp) continue; if (temp->hdr_type == PCI_HEADER_TYPE_BRIDGE && presence) {@@ -129,7 +145,7 @@ int pciehp_unconfigure_device(struct slot *p_slot)pci_write_config_word (temp,PCI_COMMAND , command); }pci_dev_put (temp); - } + }while (fn);return rc; } --1.7.1
Re: [PATCH v2 3/3] PCI, pciehp: ARI device hotplug support
Quoted 45 lines · Bjorn Helgaas
[+cc Kenji]
Quoted 26 lines · Yijing Wang
ARI device supports up to 256 Functions, pciehp now only scan and configure Functions from 0 to 7, this patch fix this problem for ARI device hotplug.
Signed-off-by Yijing Wang <[email protected]>--- drivers/pci/hotplug/pciehp_pci.c | 40 ++++++++++++++++++++++++++----------- 1 files changed, 28 insertions(+), 12 deletions(-)drivers/pci/hotplug/pciehp_pci.c +1
-2@@ -39,7 +39,7 @@ int pciehp_configure_device(struct slot *p_slot)struct pci_dev *dev;struct pci_dev *bridge = p_slot->ctrl->pcie->port;struct pci_bus *parent = bridge->subordinate; -int num, fn; +int num, fn =0 ;struct controller *ctrl = p_slot->ctrl; dev =pci_get_slot (parent,PCI_DEVFN (0 ,0 ));@@ -56,21 +56,31 @@ int pciehp_configure_device(struct slot *p_slot)ctrl_err (ctrl,"No new device found\n" );return -ENODEV ; } -drivers/pci/hotplug/pciehp_pci.c int pciehp_configure_device(struct slot *p_slot) · line 66
Quoted 10 lines
drivers/pci/hotplug/pciehp_pci.c +8
-2-for (fn =0 ; fn <8 ; fn++) { - dev =pci_get_slot (parent,PCI_DEVFN (0 , fn)); + + do { + if (pci_ari_enabled(parent)) + dev = pci_get_slot(parent, fn); + else + dev = pci_get_slot(parent, PCI_DEVFN(0, fn)); + + fn = pci_next_fn(parent, PCI_DEVFN(0, fn));This doesn't make sense to me. We just called
pci_scan_slot(), which already usedpci_next_fn()to find all the functions. We shouldn't have to have the ARI knowledge andpci_next_fn()looping here again (and yet again afterpci_assign_unassigned_bridge_resources()).
Quoted 5 lines
According to the
pci_scan_slot()function comment, all the newly-discovered devices should be on thebus->deviceslist. And in fact, the similar code in acpiphp (enable_device()) *does* use thebus->deviceslist.
Hi Bjorn,
Thanks for your review and comment! You are right, use bus->devices list is a better solution.
I will update my ARI device hotplug support patchset and send out again.
Quoted 4 lines
I think
cpci_configure_slot(),pciehp_configure_device(),enable_slot()insgi_hotplug.c, andshpchp_configure_device()should be changed to use thebus->deviceslist. In addition, I think the refcount management (pci_get_slot()/pci_dev_put()) should be removed.
Remove pci_get_slot()/pci_dev_put() here looks good to me, Because refcount increment when pci_scan_slot, here remove the refcount management is safe.
I will change this and test in my machine, and send out this patch if test result is ok.
Thanks very much!
Yijing.
Quoted 80 lines
Quoted 74 lines
drivers/pci/hotplug/pciehp_pci.c +19
-9if (!dev)continue ;if ((dev->hdr_type ==PCI_HEADER_TYPE_BRIDGE ) || (dev->hdr_type ==PCI_HEADER_TYPE_CARDBUS ))pci_hp_add_bridge (dev);pci_dev_put (dev); - } + }while (fn);pci_assign_unassigned_bridge_resources (bridge); -for (fn =0 ; fn <8 ; fn++) { - dev =pci_get_slot (parent,PCI_DEVFN (0 , fn)); + do { + if (pci_ari_enabled(parent)) + dev = pci_get_slot(parent, fn); + else + dev = pci_get_slot(parent, PCI_DEVFN(0, fn)); + + fn = pci_next_fn(parent, PCI_DEVFN(0, fn)); if (!dev) continue; if ((dev->class >> 16) == PCI_BASE_CLASS_DISPLAY) {@@ -79,7 +89,7 @@ int pciehp_configure_device(struct slot *p_slot) }pci_configure_slot (dev);pci_dev_put (dev); - } + }while (fn);pci_bus_add_devices (parent);@@ -89,21 +99,27 @@ int pciehp_configure_device(struct slot *p_slot)int pciehp_unconfigure_device (struct slot *p_slot) {int ret, rc =0 ; -int j; +int fn =0 ;u8 bctl =0 ;u8 presence =0 ;struct pci_bus *parent = p_slot->ctrl->pcie->port->subordinate;u16 command;struct controller *ctrl = p_slot->ctrl; +struct pci_dev *temp;ctrl_dbg (ctrl,"%s: domain:bus:dev = %04x:%02x:00\n" , __func__,pci_domain_nr (parent), parent->number); ret =pciehp_get_adapter_status (p_slot, &presence);if (ret) presence =0 ; + + do { + if (pci_ari_enabled(parent)) + temp = pci_get_slot(parent, fn); + else + temp = pci_get_slot(parent, PCI_DEVFN(0, fn)); -for (j =0 ; j <8 ; j++) { -struct pci_dev *temp =pci_get_slot (parent,PCI_DEVFN (0 , j)); + fn = pci_next_fn(parent, PCI_DEVFN(0, fn)); if (!temp) continue; if (temp->hdr_type == PCI_HEADER_TYPE_BRIDGE && presence) {@@ -129,7 +145,7 @@ int pciehp_unconfigure_device(struct slot *p_slot)pci_write_config_word (temp,PCI_COMMAND , command); }pci_dev_put (temp); - } + }while (fn);return rc; } --Quoted 3 lines
1.7.1
.
Signature · 2 lines
Thanks! Yijing