* [PATCH net-next 4/7] tg3: Determine PCI function number in one place
@ 2011-07-13 19:27 Matt Carlson
2011-07-13 20:13 ` Ben Hutchings
0 siblings, 1 reply; 2+ messages in thread
From: Matt Carlson @ 2011-07-13 19:27 UTC (permalink / raw)
To: davem; +Cc: netdev, mcarlson
tg3 devices will need to know exactly what function number they are so
that they can communicate their status to the other functions. In a KVM
environment, the function number of a device presented by the kernel
might not be the true function number, so an alternative method to
determine the function number is needed.
This patch used to contain an implementation for the alternative method,
but recently we discovered a hardware bug that renders it incorrect.
While new method is not yet known, it is still useful to consolidate the
code that determines the PCI function to one location and use the
results throughout the code.
Signed-off-by: Matt Carlson <mcarlson@broadcom.com>
---
drivers/net/tg3.c | 14 +++++++++++---
drivers/net/tg3.h | 1 +
2 files changed, 12 insertions(+), 3 deletions(-)
diff --git a/drivers/net/tg3.c b/drivers/net/tg3.c
index 5d4283e..6f1f36c 100644
--- a/drivers/net/tg3.c
+++ b/drivers/net/tg3.c
@@ -1170,7 +1170,7 @@ static int tg3_mdio_init(struct tg3 *tp)
if (tg3_flag(tp, 5717_PLUS)) {
u32 is_serdes;
- tp->phy_addr = PCI_FUNC(tp->pdev->devfn) + 1;
+ tp->phy_addr = tp->pci_fn + 1;
if (tp->pci_chip_rev_id != CHIPREV_ID_5717_A0)
is_serdes = tr32(SG_DIG_STATUS) & SG_DIG_IS_SERDES;
@@ -13951,6 +13951,14 @@ static int __devinit tg3_get_invariants(struct tg3 *tp)
val = tr32(MEMARB_MODE);
tw32(MEMARB_MODE, val | MEMARB_MODE_ENABLE);
+ if (tg3_flag(tp, PCIX_MODE)) {
+ pci_read_config_dword(tp->pdev,
+ tp->pcix_cap + PCI_X_STATUS, &val);
+ tp->pci_fn = val & 0x7;
+ } else {
+ tp->pci_fn = PCI_FUNC(tp->pdev->devfn) & 3;
+ }
+
/* Get eeprom hw config before calling tg3_set_power_state().
* In particular, the TG3_FLAG_IS_NIC flag must be
* determined before calling tg3_set_power_state() so that
@@ -14316,9 +14324,9 @@ static int __devinit tg3_get_device_address(struct tg3 *tp)
else
tg3_nvram_unlock(tp);
} else if (tg3_flag(tp, 5717_PLUS)) {
- if (PCI_FUNC(tp->pdev->devfn) & 1)
+ if (tp->pci_fn & 1)
mac_offset = 0xcc;
- if (PCI_FUNC(tp->pdev->devfn) > 1)
+ if (tp->pci_fn > 1)
mac_offset += 0x18c;
} else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906)
mac_offset = 0x10;
diff --git a/drivers/net/tg3.h b/drivers/net/tg3.h
index 5f250ae..b4c003d 100644
--- a/drivers/net/tg3.h
+++ b/drivers/net/tg3.h
@@ -3020,6 +3020,7 @@ struct tg3 {
u8 pci_cacheline_sz;
u8 pci_lat_timer;
+ int pci_fn;
int pm_cap;
int msi_cap;
int pcix_cap;
--
1.7.3.4
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH net-next 4/7] tg3: Determine PCI function number in one place
2011-07-13 19:27 [PATCH net-next 4/7] tg3: Determine PCI function number in one place Matt Carlson
@ 2011-07-13 20:13 ` Ben Hutchings
0 siblings, 0 replies; 2+ messages in thread
From: Ben Hutchings @ 2011-07-13 20:13 UTC (permalink / raw)
To: Matt Carlson; +Cc: davem, netdev
On Wed, 2011-07-13 at 12:27 -0700, Matt Carlson wrote:
> tg3 devices will need to know exactly what function number they are so
> that they can communicate their status to the other functions. In a KVM
> environment, the function number of a device presented by the kernel
> might not be the true function number, so an alternative method to
> determine the function number is needed.
>
> This patch used to contain an implementation for the alternative method,
> but recently we discovered a hardware bug that renders it incorrect.
> While new method is not yet known, it is still useful to consolidate the
> code that determines the PCI function to one location and use the
> results throughout the code.
[...]
Having run into (and thankfully fixed) a similar problem in sfc, I
wonder whether it would always be worthwhile to ask the hypervisor
maintainers to keep function numbers stable when passing-through
physical functions. Any driver using PCI_FUNC() is likely to be broken
by function number changes, and 'git grep' shows there are quite a few
of them.
Ben.
--
Ben Hutchings, Senior Software Engineer, Solarflare
Not speaking for my employer; that's the marketing department's job.
They asked us to note that Solarflare product names are trademarked.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2011-07-13 20:13 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-07-13 19:27 [PATCH net-next 4/7] tg3: Determine PCI function number in one place Matt Carlson
2011-07-13 20:13 ` Ben Hutchings
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).