Skip to content

Commit

Permalink
Merge tag 'ntb-3.15' of git://github.com/jonmason/ntb
Browse files Browse the repository at this point in the history
Pull PCIe non-transparent bridge fixes and features from Jon Mason:
 "NTB driver bug fixes to address issues in list traversal, skb leak in
  ntb_netdev, a typo, and a leak of msix entries in the error path.
  Clean ups of the event handling logic, as well as a overall style
  cleanup.  Finally, the driver was converted to use the new
  pci_enable_msix_range logic (and the refactoring to go along with it)"

* tag 'ntb-3.15' of git://github.com/jonmason/ntb:
  ntb: Use pci_enable_msix_range() instead of pci_enable_msix()
  ntb: Split ntb_setup_msix() into separate BWD/SNB routines
  ntb: Use pci_msix_vec_count() to obtain number of MSI-Xs
  NTB: Code Style Clean-up
  NTB: client event cleanup
  ntb: Fix leakage of ntb_device::msix_entries[] array
  NTB: Fix typo in setting one translation register
  ntb_netdev: Fix skb free issue in open
  ntb_netdev: Fix list_for_each_entry exit issue
  • Loading branch information
torvalds committed Apr 12, 2014
2 parents 96c57ad + f220baa commit 07f5fef
Show file tree
Hide file tree
Showing 5 changed files with 150 additions and 116 deletions.
27 changes: 20 additions & 7 deletions drivers/net/ntb_netdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,19 @@ static void ntb_netdev_event_handler(void *data, int status)
netdev_dbg(ndev, "Event %x, Link %x\n", status,
ntb_transport_link_query(dev->qp));

/* Currently, only link status event is supported */
if (status)
netif_carrier_on(ndev);
else
switch (status) {
case NTB_LINK_DOWN:
netif_carrier_off(ndev);
break;
case NTB_LINK_UP:
if (!ntb_transport_link_query(dev->qp))
return;

netif_carrier_on(ndev);
break;
default:
netdev_warn(ndev, "Unsupported event type %d\n", status);
}
}

static void ntb_netdev_rx_handler(struct ntb_transport_qp *qp, void *qp_data,
Expand Down Expand Up @@ -182,8 +190,10 @@ static int ntb_netdev_open(struct net_device *ndev)

rc = ntb_transport_rx_enqueue(dev->qp, skb, skb->data,
ndev->mtu + ETH_HLEN);
if (rc == -EINVAL)
if (rc == -EINVAL) {
dev_kfree_skb(skb);
goto err;
}
}

netif_carrier_off(ndev);
Expand Down Expand Up @@ -367,12 +377,15 @@ static void ntb_netdev_remove(struct pci_dev *pdev)
{
struct net_device *ndev;
struct ntb_netdev *dev;
bool found = false;

list_for_each_entry(dev, &dev_list, list) {
if (dev->pdev == pdev)
if (dev->pdev == pdev) {
found = true;
break;
}
}
if (dev == NULL)
if (!found)
return;

list_del(&dev->list);
Expand Down
192 changes: 107 additions & 85 deletions drivers/ntb/ntb_hw.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ static struct dentry *debugfs_dir;
/* Translate memory window 0,1 to BAR 2,4 */
#define MW_TO_BAR(mw) (mw * NTB_MAX_NUM_MW + 2)

static DEFINE_PCI_DEVICE_TABLE(ntb_pci_tbl) = {
static const struct pci_device_id ntb_pci_tbl[] = {
{PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_NTB_B2B_BWD)},
{PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_NTB_B2B_JSF)},
{PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_NTB_B2B_SNB)},
Expand Down Expand Up @@ -120,7 +120,8 @@ MODULE_DEVICE_TABLE(pci, ntb_pci_tbl);
* RETURNS: An appropriate -ERRNO error value on error, or zero for success.
*/
int ntb_register_event_callback(struct ntb_device *ndev,
void (*func)(void *handle, enum ntb_hw_event event))
void (*func)(void *handle,
enum ntb_hw_event event))
{
if (ndev->event_cb)
return -EINVAL;
Expand Down Expand Up @@ -715,9 +716,9 @@ static int ntb_xeon_setup(struct ntb_device *ndev)
SNB_PBAR4LMT_OFFSET);
/* HW errata on the Limit registers. They can only be
* written when the base register is 4GB aligned and
* < 32bit. This should already be the case based on the
* driver defaults, but write the Limit registers first
* just in case.
* < 32bit. This should already be the case based on
* the driver defaults, but write the Limit registers
* first just in case.
*/
} else {
ndev->limits.max_mw = SNB_MAX_MW;
Expand All @@ -739,9 +740,9 @@ static int ntb_xeon_setup(struct ntb_device *ndev)
writeq(0, ndev->reg_base + SNB_PBAR4LMT_OFFSET);
/* HW errata on the Limit registers. They can only be
* written when the base register is 4GB aligned and
* < 32bit. This should already be the case based on the
* driver defaults, but write the Limit registers first
* just in case.
* < 32bit. This should already be the case based on
* the driver defaults, but write the Limit registers
* first just in case.
*/
}

Expand Down Expand Up @@ -785,7 +786,7 @@ static int ntb_xeon_setup(struct ntb_device *ndev)
/* B2B_XLAT_OFFSET is a 64bit register, but can
* only take 32bit writes
*/
writel(SNB_MBAR01_DSD_ADDR & 0xffffffff,
writel(SNB_MBAR01_USD_ADDR & 0xffffffff,
ndev->reg_base + SNB_B2B_XLAT_OFFSETL);
writel(SNB_MBAR01_USD_ADDR >> 32,
ndev->reg_base + SNB_B2B_XLAT_OFFSETU);
Expand All @@ -803,7 +804,7 @@ static int ntb_xeon_setup(struct ntb_device *ndev)
ndev->conn_type = NTB_CONN_RP;

if (xeon_errata_workaround) {
dev_err(&ndev->pdev->dev,
dev_err(&ndev->pdev->dev,
"NTB-RP disabled due to hardware errata. To disregard this warning and potentially lock-up the system, add the parameter 'xeon_errata_workaround=0'.\n");
return -EINVAL;
}
Expand Down Expand Up @@ -1079,111 +1080,131 @@ static irqreturn_t ntb_interrupt(int irq, void *dev)
return IRQ_HANDLED;
}

static int ntb_setup_msix(struct ntb_device *ndev)
static int ntb_setup_snb_msix(struct ntb_device *ndev, int msix_entries)
{
struct pci_dev *pdev = ndev->pdev;
struct msix_entry *msix;
int msix_entries;
int rc, i;
u16 val;

if (!pdev->msix_cap) {
rc = -EIO;
goto err;
}
if (msix_entries < ndev->limits.msix_cnt)
return -ENOSPC;

rc = pci_read_config_word(pdev, pdev->msix_cap + PCI_MSIX_FLAGS, &val);
if (rc)
goto err;
rc = pci_enable_msix_exact(pdev, ndev->msix_entries, msix_entries);
if (rc < 0)
return rc;

msix_entries = msix_table_size(val);
if (msix_entries > ndev->limits.msix_cnt) {
rc = -EINVAL;
goto err;
for (i = 0; i < msix_entries; i++) {
msix = &ndev->msix_entries[i];
WARN_ON(!msix->vector);

if (i == msix_entries - 1) {
rc = request_irq(msix->vector,
xeon_event_msix_irq, 0,
"ntb-event-msix", ndev);
if (rc)
goto err;
} else {
rc = request_irq(msix->vector,
xeon_callback_msix_irq, 0,
"ntb-callback-msix",
&ndev->db_cb[i]);
if (rc)
goto err;
}
}

ndev->msix_entries = kmalloc(sizeof(struct msix_entry) * msix_entries,
GFP_KERNEL);
if (!ndev->msix_entries) {
rc = -ENOMEM;
goto err;
ndev->num_msix = msix_entries;
ndev->max_cbs = msix_entries - 1;

return 0;

err:
while (--i >= 0) {
/* Code never reaches here for entry nr 'ndev->num_msix - 1' */
msix = &ndev->msix_entries[i];
free_irq(msix->vector, &ndev->db_cb[i]);
}

for (i = 0; i < msix_entries; i++)
ndev->msix_entries[i].entry = i;
pci_disable_msix(pdev);
ndev->num_msix = 0;

rc = pci_enable_msix(pdev, ndev->msix_entries, msix_entries);
if (rc < 0)
goto err1;
if (rc > 0) {
/* On SNB, the link interrupt is always tied to 4th vector. If
* we can't get all 4, then we can't use MSI-X.
*/
if (ndev->hw_type != BWD_HW) {
rc = -EIO;
goto err1;
}
return rc;
}

dev_warn(&pdev->dev,
"Only %d MSI-X vectors. Limiting the number of queues to that number.\n",
rc);
msix_entries = rc;
static int ntb_setup_bwd_msix(struct ntb_device *ndev, int msix_entries)
{
struct pci_dev *pdev = ndev->pdev;
struct msix_entry *msix;
int rc, i;

rc = pci_enable_msix(pdev, ndev->msix_entries, msix_entries);
if (rc)
goto err1;
}
msix_entries = pci_enable_msix_range(pdev, ndev->msix_entries,
1, msix_entries);
if (msix_entries < 0)
return msix_entries;

for (i = 0; i < msix_entries; i++) {
msix = &ndev->msix_entries[i];
WARN_ON(!msix->vector);

/* Use the last MSI-X vector for Link status */
if (ndev->hw_type == BWD_HW) {
rc = request_irq(msix->vector, bwd_callback_msix_irq, 0,
"ntb-callback-msix", &ndev->db_cb[i]);
if (rc)
goto err2;
} else {
if (i == msix_entries - 1) {
rc = request_irq(msix->vector,
xeon_event_msix_irq, 0,
"ntb-event-msix", ndev);
if (rc)
goto err2;
} else {
rc = request_irq(msix->vector,
xeon_callback_msix_irq, 0,
"ntb-callback-msix",
&ndev->db_cb[i]);
if (rc)
goto err2;
}
}
rc = request_irq(msix->vector, bwd_callback_msix_irq, 0,
"ntb-callback-msix", &ndev->db_cb[i]);
if (rc)
goto err;
}

ndev->num_msix = msix_entries;
ndev->max_cbs = msix_entries;

return 0;

err:
while (--i >= 0)
free_irq(msix->vector, &ndev->db_cb[i]);

pci_disable_msix(pdev);
ndev->num_msix = 0;

return rc;
}

static int ntb_setup_msix(struct ntb_device *ndev)
{
struct pci_dev *pdev = ndev->pdev;
int msix_entries;
int rc, i;

msix_entries = pci_msix_vec_count(pdev);
if (msix_entries < 0) {
rc = msix_entries;
goto err;
} else if (msix_entries > ndev->limits.msix_cnt) {
rc = -EINVAL;
goto err;
}

ndev->msix_entries = kmalloc(sizeof(struct msix_entry) * msix_entries,
GFP_KERNEL);
if (!ndev->msix_entries) {
rc = -ENOMEM;
goto err;
}

for (i = 0; i < msix_entries; i++)
ndev->msix_entries[i].entry = i;

if (ndev->hw_type == BWD_HW)
ndev->max_cbs = msix_entries;
rc = ntb_setup_bwd_msix(ndev, msix_entries);
else
ndev->max_cbs = msix_entries - 1;
rc = ntb_setup_snb_msix(ndev, msix_entries);
if (rc)
goto err1;

return 0;

err2:
while (--i >= 0) {
msix = &ndev->msix_entries[i];
if (ndev->hw_type != BWD_HW && i == ndev->num_msix - 1)
free_irq(msix->vector, ndev);
else
free_irq(msix->vector, &ndev->db_cb[i]);
}
pci_disable_msix(pdev);
err1:
kfree(ndev->msix_entries);
dev_err(&pdev->dev, "Error allocating MSI-X interrupt\n");
err:
ndev->num_msix = 0;
dev_err(&pdev->dev, "Error allocating MSI-X interrupt\n");
return rc;
}

Expand Down Expand Up @@ -1281,6 +1302,7 @@ static void ntb_free_interrupts(struct ntb_device *ndev)
free_irq(msix->vector, &ndev->db_cb[i]);
}
pci_disable_msix(pdev);
kfree(ndev->msix_entries);
} else {
free_irq(pdev->irq, ndev);

Expand Down
8 changes: 2 additions & 6 deletions drivers/ntb/ntb_hw.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
* Contact Information:
* Jon Mason <jon.mason@intel.com>
*/
#include <linux/ntb.h>

#define PCI_DEVICE_ID_INTEL_NTB_B2B_JSF 0x3725
#define PCI_DEVICE_ID_INTEL_NTB_PS_JSF 0x3726
Expand All @@ -60,8 +61,6 @@
#define PCI_DEVICE_ID_INTEL_NTB_SS_HSX 0x2F0F
#define PCI_DEVICE_ID_INTEL_NTB_B2B_BWD 0x0C4E

#define msix_table_size(control) ((control & PCI_MSIX_FLAGS_QSIZE)+1)

#ifndef readq
static inline u64 readq(void __iomem *addr)
{
Expand All @@ -83,9 +82,6 @@ static inline void writeq(u64 val, void __iomem *addr)
#define NTB_BAR_MASK ((1 << NTB_BAR_MMIO) | (1 << NTB_BAR_23) |\
(1 << NTB_BAR_45))

#define NTB_LINK_DOWN 0
#define NTB_LINK_UP 1

#define NTB_HB_TIMEOUT msecs_to_jiffies(1000)

#define NTB_MAX_NUM_MW 2
Expand Down Expand Up @@ -233,7 +229,7 @@ int ntb_register_db_callback(struct ntb_device *ndev, unsigned int idx,
int db_num));
void ntb_unregister_db_callback(struct ntb_device *ndev, unsigned int idx);
int ntb_register_event_callback(struct ntb_device *ndev,
void (*event_cb_func) (void *handle,
void (*event_cb_func)(void *handle,
enum ntb_hw_event event));
void ntb_unregister_event_callback(struct ntb_device *ndev);
int ntb_get_max_spads(struct ntb_device *ndev);
Expand Down
Loading

0 comments on commit 07f5fef

Please sign in to comment.