diff options
Diffstat (limited to 'drivers/ntb')
| -rw-r--r-- | drivers/ntb/ntb_hw.c | 293 | ||||
| -rw-r--r-- | drivers/ntb/ntb_hw.h | 15 | ||||
| -rw-r--r-- | drivers/ntb/ntb_regs.h | 16 | ||||
| -rw-r--r-- | drivers/ntb/ntb_transport.c | 183 | 
4 files changed, 320 insertions, 187 deletions
diff --git a/drivers/ntb/ntb_hw.c b/drivers/ntb/ntb_hw.c index 1cb6e51e6bd..372e08c4ffe 100644 --- a/drivers/ntb/ntb_hw.c +++ b/drivers/ntb/ntb_hw.c @@ -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)}, @@ -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; @@ -141,6 +142,24 @@ void ntb_unregister_event_callback(struct ntb_device *ndev)  	ndev->event_cb = NULL;  } +static void ntb_irq_work(unsigned long data) +{ +	struct ntb_db_cb *db_cb = (struct ntb_db_cb *)data; +	int rc; + +	rc = db_cb->callback(db_cb->data, db_cb->db_num); +	if (rc) +		tasklet_schedule(&db_cb->irq_work); +	else { +		struct ntb_device *ndev = db_cb->ndev; +		unsigned long mask; + +		mask = readw(ndev->reg_ofs.ldb_mask); +		clear_bit(db_cb->db_num * ndev->bits_per_vector, &mask); +		writew(mask, ndev->reg_ofs.ldb_mask); +	} +} +  /**   * ntb_register_db_callback() - register a callback for doorbell interrupt   * @ndev: pointer to ntb_device instance @@ -155,7 +174,7 @@ void ntb_unregister_event_callback(struct ntb_device *ndev)   * RETURNS: An appropriate -ERRNO error value on error, or zero for success.   */  int ntb_register_db_callback(struct ntb_device *ndev, unsigned int idx, -			     void *data, void (*func)(void *data, int db_num)) +			     void *data, int (*func)(void *data, int db_num))  {  	unsigned long mask; @@ -166,6 +185,10 @@ int ntb_register_db_callback(struct ntb_device *ndev, unsigned int idx,  	ndev->db_cb[idx].callback = func;  	ndev->db_cb[idx].data = data; +	ndev->db_cb[idx].ndev = ndev; + +	tasklet_init(&ndev->db_cb[idx].irq_work, ntb_irq_work, +		     (unsigned long) &ndev->db_cb[idx]);  	/* unmask interrupt */  	mask = readw(ndev->reg_ofs.ldb_mask); @@ -194,6 +217,8 @@ void ntb_unregister_db_callback(struct ntb_device *ndev, unsigned int idx)  	set_bit(idx * ndev->bits_per_vector, &mask);  	writew(mask, ndev->reg_ofs.ldb_mask); +	tasklet_disable(&ndev->db_cb[idx].irq_work); +  	ndev->db_cb[idx].callback = NULL;  } @@ -678,6 +703,7 @@ static int ntb_xeon_setup(struct ntb_device *ndev)  				return -EINVAL;  			ndev->limits.max_mw = SNB_ERRATA_MAX_MW; +			ndev->limits.max_db_bits = SNB_MAX_DB_BITS;  			ndev->reg_ofs.spad_write = ndev->mw[1].vbase +  						   SNB_SPAD_OFFSET;  			ndev->reg_ofs.rdb = ndev->mw[1].vbase + @@ -688,8 +714,21 @@ static int ntb_xeon_setup(struct ntb_device *ndev)  			 */  			writeq(ndev->mw[1].bar_sz + 0x1000, 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. +			 */  		} else {  			ndev->limits.max_mw = SNB_MAX_MW; + +			/* HW Errata on bit 14 of b2bdoorbell register.  Writes +			 * will not be mirrored to the remote system.  Shrink +			 * the number of bits by one, since bit 14 is the last +			 * bit. +			 */ +			ndev->limits.max_db_bits = SNB_MAX_DB_BITS - 1;  			ndev->reg_ofs.spad_write = ndev->reg_base +  						   SNB_B2B_SPAD_OFFSET;  			ndev->reg_ofs.rdb = ndev->reg_base + @@ -699,6 +738,12 @@ static int ntb_xeon_setup(struct ntb_device *ndev)  			 * something silly  			 */  			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. +			 */  		}  		/* The Xeon errata workaround requires setting SBAR Base @@ -741,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); @@ -759,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;  		} @@ -769,6 +814,7 @@ static int ntb_xeon_setup(struct ntb_device *ndev)  		 * have an equal amount.  		 */  		ndev->limits.max_spads = SNB_MAX_COMPAT_SPADS / 2; +		ndev->limits.max_db_bits = SNB_MAX_DB_BITS;  		/* Note: The SDOORBELL is the cause of the errata.  You REALLY  		 * don't want to touch it.  		 */ @@ -793,6 +839,7 @@ static int ntb_xeon_setup(struct ntb_device *ndev)  		 * have an equal amount.  		 */  		ndev->limits.max_spads = SNB_MAX_COMPAT_SPADS / 2; +		ndev->limits.max_db_bits = SNB_MAX_DB_BITS;  		ndev->reg_ofs.rdb = ndev->reg_base + SNB_PDOORBELL_OFFSET;  		ndev->reg_ofs.ldb = ndev->reg_base + SNB_SDOORBELL_OFFSET;  		ndev->reg_ofs.ldb_mask = ndev->reg_base + SNB_SDBMSK_OFFSET; @@ -819,7 +866,6 @@ static int ntb_xeon_setup(struct ntb_device *ndev)  	ndev->reg_ofs.lnk_stat = ndev->reg_base + SNB_SLINK_STATUS_OFFSET;  	ndev->reg_ofs.spci_cmd = ndev->reg_base + SNB_PCICMD_OFFSET; -	ndev->limits.max_db_bits = SNB_MAX_DB_BITS;  	ndev->limits.msix_cnt = SNB_MSIX_CNT;  	ndev->bits_per_vector = SNB_DB_BITS_PER_VEC; @@ -934,12 +980,16 @@ static irqreturn_t bwd_callback_msix_irq(int irq, void *data)  {  	struct ntb_db_cb *db_cb = data;  	struct ntb_device *ndev = db_cb->ndev; +	unsigned long mask;  	dev_dbg(&ndev->pdev->dev, "MSI-X irq %d received for DB %d\n", irq,  		db_cb->db_num); -	if (db_cb->callback) -		db_cb->callback(db_cb->data, db_cb->db_num); +	mask = readw(ndev->reg_ofs.ldb_mask); +	set_bit(db_cb->db_num * ndev->bits_per_vector, &mask); +	writew(mask, ndev->reg_ofs.ldb_mask); + +	tasklet_schedule(&db_cb->irq_work);  	/* No need to check for the specific HB irq, any interrupt means  	 * we're connected. @@ -955,12 +1005,16 @@ static irqreturn_t xeon_callback_msix_irq(int irq, void *data)  {  	struct ntb_db_cb *db_cb = data;  	struct ntb_device *ndev = db_cb->ndev; +	unsigned long mask;  	dev_dbg(&ndev->pdev->dev, "MSI-X irq %d received for DB %d\n", irq,  		db_cb->db_num); -	if (db_cb->callback) -		db_cb->callback(db_cb->data, db_cb->db_num); +	mask = readw(ndev->reg_ofs.ldb_mask); +	set_bit(db_cb->db_num * ndev->bits_per_vector, &mask); +	writew(mask, ndev->reg_ofs.ldb_mask); + +	tasklet_schedule(&db_cb->irq_work);  	/* On Sandybridge, there are 16 bits in the interrupt register  	 * but only 4 vectors.  So, 5 bits are assigned to the first 3 @@ -986,7 +1040,7 @@ static irqreturn_t xeon_event_msix_irq(int irq, void *dev)  		dev_err(&ndev->pdev->dev, "Error determining link status\n");  	/* bit 15 is always the link bit */ -	writew(1 << ndev->limits.max_db_bits, ndev->reg_ofs.ldb); +	writew(1 << SNB_LINK_DB, ndev->reg_ofs.ldb);  	return IRQ_HANDLED;  } @@ -1026,25 +1080,104 @@ 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_enable_msix_exact(pdev, ndev->msix_entries, msix_entries); +	if (rc < 0) +		return rc; + +	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; +		}  	} -	rc = pci_read_config_word(pdev, pdev->msix_cap + PCI_MSIX_FLAGS, &val); -	if (rc) -		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]); +	} -	msix_entries = msix_table_size(val); -	if (msix_entries > ndev->limits.msix_cnt) { +	pci_disable_msix(pdev); +	ndev->num_msix = 0; + +	return 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; + +	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); + +		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;  	} @@ -1059,74 +1192,19 @@ static int ntb_setup_msix(struct ntb_device *ndev)  	for (i = 0; i < msix_entries; i++)  		ndev->msix_entries[i].entry = i; -	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; -		} - -		dev_warn(&pdev->dev, -			 "Only %d MSI-X vectors.  Limiting the number of queues to that number.\n", -			 rc); -		msix_entries = rc; -	} - -	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; -			} -		} -	} - -	ndev->num_msix = msix_entries;  	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;  } @@ -1176,9 +1254,10 @@ static int ntb_setup_interrupts(struct ntb_device *ndev)  	 */  	if (ndev->hw_type == BWD_HW)  		writeq(~0, ndev->reg_ofs.ldb_mask); -	else -		writew(~(1 << ndev->limits.max_db_bits), -		       ndev->reg_ofs.ldb_mask); +	else { +		u16 var = 1 << SNB_LINK_DB; +		writew(~var, ndev->reg_ofs.ldb_mask); +	}  	rc = ntb_setup_msix(ndev);  	if (!rc) @@ -1223,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); @@ -1286,6 +1366,39 @@ static void ntb_free_debugfs(struct ntb_device *ndev)  	}  } +static void ntb_hw_link_up(struct ntb_device *ndev) +{ +	if (ndev->conn_type == NTB_CONN_TRANSPARENT) +		ntb_link_event(ndev, NTB_LINK_UP); +	else { +		u32 ntb_cntl; + +		/* Let's bring the NTB link up */ +		ntb_cntl = readl(ndev->reg_ofs.lnk_cntl); +		ntb_cntl &= ~(NTB_CNTL_LINK_DISABLE | NTB_CNTL_CFG_LOCK); +		ntb_cntl |= NTB_CNTL_P2S_BAR23_SNOOP | NTB_CNTL_S2P_BAR23_SNOOP; +		ntb_cntl |= NTB_CNTL_P2S_BAR45_SNOOP | NTB_CNTL_S2P_BAR45_SNOOP; +		writel(ntb_cntl, ndev->reg_ofs.lnk_cntl); +	} +} + +static void ntb_hw_link_down(struct ntb_device *ndev) +{ +	u32 ntb_cntl; + +	if (ndev->conn_type == NTB_CONN_TRANSPARENT) { +		ntb_link_event(ndev, NTB_LINK_DOWN); +		return; +	} + +	/* Bring NTB link down */ +	ntb_cntl = readl(ndev->reg_ofs.lnk_cntl); +	ntb_cntl &= ~(NTB_CNTL_P2S_BAR23_SNOOP | NTB_CNTL_S2P_BAR23_SNOOP); +	ntb_cntl &= ~(NTB_CNTL_P2S_BAR45_SNOOP | NTB_CNTL_S2P_BAR45_SNOOP); +	ntb_cntl |= NTB_CNTL_LINK_DISABLE | NTB_CNTL_CFG_LOCK; +	writel(ntb_cntl, ndev->reg_ofs.lnk_cntl); +} +  static int ntb_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)  {  	struct ntb_device *ndev; @@ -1374,9 +1487,7 @@ static int ntb_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)  	if (rc)  		goto err6; -	/* Let's bring the NTB link up */ -	writel(NTB_CNTL_BAR23_SNOOP | NTB_CNTL_BAR45_SNOOP, -	       ndev->reg_ofs.lnk_cntl); +	ntb_hw_link_up(ndev);  	return 0; @@ -1406,12 +1517,8 @@ static void ntb_pci_remove(struct pci_dev *pdev)  {  	struct ntb_device *ndev = pci_get_drvdata(pdev);  	int i; -	u32 ntb_cntl; -	/* Bring NTB link down */ -	ntb_cntl = readl(ndev->reg_ofs.lnk_cntl); -	ntb_cntl |= NTB_CNTL_LINK_DISABLE; -	writel(ntb_cntl, ndev->reg_ofs.lnk_cntl); +	ntb_hw_link_down(ndev);  	ntb_transport_free(ndev->ntb_transport); diff --git a/drivers/ntb/ntb_hw.h b/drivers/ntb/ntb_hw.h index 0a31cedae7d..465517b7393 100644 --- a/drivers/ntb/ntb_hw.h +++ b/drivers/ntb/ntb_hw.h @@ -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 @@ -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)  { @@ -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 @@ -106,10 +102,11 @@ struct ntb_mw {  };  struct ntb_db_cb { -	void (*callback) (void *data, int db_num); +	int (*callback)(void *data, int db_num);  	unsigned int db_num;  	void *data;  	struct ntb_device *ndev; +	struct tasklet_struct irq_work;  };  struct ntb_device { @@ -228,11 +225,11 @@ struct ntb_device *ntb_register_transport(struct pci_dev *pdev,  void ntb_unregister_transport(struct ntb_device *ndev);  void ntb_set_mw_addr(struct ntb_device *ndev, unsigned int mw, u64 addr);  int ntb_register_db_callback(struct ntb_device *ndev, unsigned int idx, -			     void *data, void (*db_cb_func) (void *data, -							     int db_num)); +			     void *data, int (*db_cb_func)(void *data, +							   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); diff --git a/drivers/ntb/ntb_regs.h b/drivers/ntb/ntb_regs.h index aa4bdd393c5..9774506419d 100644 --- a/drivers/ntb/ntb_regs.h +++ b/drivers/ntb/ntb_regs.h @@ -55,6 +55,7 @@  #define SNB_MAX_COMPAT_SPADS	16  /* Reserve the uppermost bit for link interrupt */  #define SNB_MAX_DB_BITS		15 +#define SNB_LINK_DB		15  #define SNB_DB_BITS_PER_VEC	5  #define SNB_MAX_MW		2  #define SNB_ERRATA_MAX_MW	1 @@ -75,9 +76,6 @@  #define SNB_SBAR2XLAT_OFFSET	0x0030  #define SNB_SBAR4XLAT_OFFSET	0x0038  #define SNB_SBAR0BASE_OFFSET	0x0040 -#define SNB_SBAR0BASE_OFFSET	0x0040 -#define SNB_SBAR2BASE_OFFSET	0x0048 -#define SNB_SBAR4BASE_OFFSET	0x0050  #define SNB_SBAR2BASE_OFFSET	0x0048  #define SNB_SBAR4BASE_OFFSET	0x0050  #define SNB_NTBCNTL_OFFSET	0x0058 @@ -145,11 +143,13 @@  #define BWD_LTSSMSTATEJMP_FORCEDETECT	(1 << 2)  #define BWD_IBIST_ERR_OFLOW	0x7FFF7FFF -#define NTB_CNTL_CFG_LOCK	(1 << 0) -#define NTB_CNTL_LINK_DISABLE	(1 << 1) -#define NTB_CNTL_BAR23_SNOOP	(1 << 2) -#define NTB_CNTL_BAR45_SNOOP	(1 << 6) -#define BWD_CNTL_LINK_DOWN	(1 << 16) +#define NTB_CNTL_CFG_LOCK		(1 << 0) +#define NTB_CNTL_LINK_DISABLE		(1 << 1) +#define NTB_CNTL_S2P_BAR23_SNOOP	(1 << 2) +#define NTB_CNTL_P2S_BAR23_SNOOP	(1 << 4) +#define NTB_CNTL_S2P_BAR45_SNOOP	(1 << 6) +#define NTB_CNTL_P2S_BAR45_SNOOP	(1 << 8) +#define BWD_CNTL_LINK_DOWN		(1 << 16)  #define NTB_PPD_OFFSET		0x00D4  #define SNB_PPD_CONN_TYPE	0x0003 diff --git a/drivers/ntb/ntb_transport.c b/drivers/ntb/ntb_transport.c index 12a9e83c008..9dd63b82202 100644 --- a/drivers/ntb/ntb_transport.c +++ b/drivers/ntb/ntb_transport.c @@ -56,7 +56,6 @@  #include <linux/pci.h>  #include <linux/slab.h>  #include <linux/types.h> -#include <linux/ntb.h>  #include "ntb_hw.h"  #define NTB_TRANSPORT_VERSION	3 @@ -107,8 +106,8 @@ struct ntb_transport_qp {  	struct ntb_rx_info __iomem *rx_info;  	struct ntb_rx_info *remote_rx_info; -	void (*tx_handler) (struct ntb_transport_qp *qp, void *qp_data, -			    void *data, int len); +	void (*tx_handler)(struct ntb_transport_qp *qp, void *qp_data, +			   void *data, int len);  	struct list_head tx_free_q;  	spinlock_t ntb_tx_free_q_lock;  	void __iomem *tx_mw; @@ -117,9 +116,8 @@ struct ntb_transport_qp {  	unsigned int tx_max_entry;  	unsigned int tx_max_frame; -	void (*rx_handler) (struct ntb_transport_qp *qp, void *qp_data, -			    void *data, int len); -	struct tasklet_struct rx_work; +	void (*rx_handler)(struct ntb_transport_qp *qp, void *qp_data, +			   void *data, int len);  	struct list_head rx_pend_q;  	struct list_head rx_free_q;  	spinlock_t ntb_rx_pend_q_lock; @@ -130,7 +128,7 @@ struct ntb_transport_qp {  	unsigned int rx_max_frame;  	dma_cookie_t last_cookie; -	void (*event_handler) (void *data, int status); +	void (*event_handler)(void *data, int status);  	struct delayed_work link_work;  	struct work_struct link_cleanup; @@ -481,7 +479,7 @@ static void ntb_list_add(spinlock_t *lock, struct list_head *entry,  }  static struct ntb_queue_entry *ntb_list_rm(spinlock_t *lock, -						struct list_head *list) +					   struct list_head *list)  {  	struct ntb_queue_entry *entry;  	unsigned long flags; @@ -584,11 +582,8 @@ static int ntb_set_mw(struct ntb_transport *nt, int num_mw, unsigned int size)  	return 0;  } -static void ntb_qp_link_cleanup(struct work_struct *work) +static void ntb_qp_link_cleanup(struct ntb_transport_qp *qp)  { -	struct ntb_transport_qp *qp = container_of(work, -						   struct ntb_transport_qp, -						   link_cleanup);  	struct ntb_transport *nt = qp->transport;  	struct pci_dev *pdev = ntb_query_pdev(nt->ndev); @@ -602,6 +597,16 @@ static void ntb_qp_link_cleanup(struct work_struct *work)  	dev_info(&pdev->dev, "qp %d: Link Down\n", qp->qp_num);  	qp->qp_link = NTB_LINK_DOWN; +} + +static void ntb_qp_link_cleanup_work(struct work_struct *work) +{ +	struct ntb_transport_qp *qp = container_of(work, +						   struct ntb_transport_qp, +						   link_cleanup); +	struct ntb_transport *nt = qp->transport; + +	ntb_qp_link_cleanup(qp);  	if (nt->transport_link == NTB_LINK_UP)  		schedule_delayed_work(&qp->link_work, @@ -613,22 +618,20 @@ static void ntb_qp_link_down(struct ntb_transport_qp *qp)  	schedule_work(&qp->link_cleanup);  } -static void ntb_transport_link_cleanup(struct work_struct *work) +static void ntb_transport_link_cleanup(struct ntb_transport *nt)  { -	struct ntb_transport *nt = container_of(work, struct ntb_transport, -						link_cleanup);  	int i; +	/* Pass along the info to any clients */ +	for (i = 0; i < nt->max_qps; i++) +		if (!test_bit(i, &nt->qp_bitmap)) +			ntb_qp_link_cleanup(&nt->qps[i]); +  	if (nt->transport_link == NTB_LINK_DOWN)  		cancel_delayed_work_sync(&nt->link_work);  	else  		nt->transport_link = NTB_LINK_DOWN; -	/* Pass along the info to any clients */ -	for (i = 0; i < nt->max_qps; i++) -		if (!test_bit(i, &nt->qp_bitmap)) -			ntb_qp_link_down(&nt->qps[i]); -  	/* The scratchpad registers keep the values if the remote side  	 * goes down, blast them now to give them a sane value the next  	 * time they are accessed @@ -637,6 +640,14 @@ static void ntb_transport_link_cleanup(struct work_struct *work)  		ntb_write_local_spad(nt->ndev, i, 0);  } +static void ntb_transport_link_cleanup_work(struct work_struct *work) +{ +	struct ntb_transport *nt = container_of(work, struct ntb_transport, +						link_cleanup); + +	ntb_transport_link_cleanup(nt); +} +  static void ntb_transport_event_callback(void *data, enum ntb_hw_event event)  {  	struct ntb_transport *nt = data; @@ -827,7 +838,7 @@ static void ntb_qp_link_work(struct work_struct *work)  }  static int ntb_transport_init_queue(struct ntb_transport *nt, -				     unsigned int qp_num) +				    unsigned int qp_num)  {  	struct ntb_transport_qp *qp;  	unsigned int num_qps_mw, tx_size; @@ -880,7 +891,7 @@ static int ntb_transport_init_queue(struct ntb_transport *nt,  	}  	INIT_DELAYED_WORK(&qp->link_work, ntb_qp_link_work); -	INIT_WORK(&qp->link_cleanup, ntb_qp_link_cleanup); +	INIT_WORK(&qp->link_cleanup, ntb_qp_link_cleanup_work);  	spin_lock_init(&qp->ntb_rx_pend_q_lock);  	spin_lock_init(&qp->ntb_rx_free_q_lock); @@ -936,7 +947,7 @@ int ntb_transport_init(struct pci_dev *pdev)  	}  	INIT_DELAYED_WORK(&nt->link_work, ntb_transport_link_work); -	INIT_WORK(&nt->link_cleanup, ntb_transport_link_cleanup); +	INIT_WORK(&nt->link_cleanup, ntb_transport_link_cleanup_work);  	rc = ntb_register_event_callback(nt->ndev,  					 ntb_transport_event_callback); @@ -972,7 +983,7 @@ void ntb_transport_free(void *transport)  	struct ntb_device *ndev = nt->ndev;  	int i; -	nt->transport_link = NTB_LINK_DOWN; +	ntb_transport_link_cleanup(nt);  	/* verify that all the qp's are freed */  	for (i = 0; i < nt->max_qps; i++) { @@ -1034,46 +1045,59 @@ static void ntb_async_rx(struct ntb_queue_entry *entry, void *offset,  	struct dma_chan *chan = qp->dma_chan;  	struct dma_device *device;  	size_t pay_off, buff_off; -	dma_addr_t src, dest; +	struct dmaengine_unmap_data *unmap;  	dma_cookie_t cookie;  	void *buf = entry->buf; -	unsigned long flags;  	entry->len = len;  	if (!chan)  		goto err; -	if (len < copy_bytes)  -		goto err1; +	if (len < copy_bytes) +		goto err_wait;  	device = chan->device;  	pay_off = (size_t) offset & ~PAGE_MASK;  	buff_off = (size_t) buf & ~PAGE_MASK;  	if (!is_dma_copy_aligned(device, pay_off, buff_off, len)) -		goto err1; +		goto err_wait; -	dest = dma_map_single(device->dev, buf, len, DMA_FROM_DEVICE); -	if (dma_mapping_error(device->dev, dest)) -		goto err1; +	unmap = dmaengine_get_unmap_data(device->dev, 2, GFP_NOWAIT); +	if (!unmap) +		goto err_wait; -	src = dma_map_single(device->dev, offset, len, DMA_TO_DEVICE); -	if (dma_mapping_error(device->dev, src)) -		goto err2; +	unmap->len = len; +	unmap->addr[0] = dma_map_page(device->dev, virt_to_page(offset), +				      pay_off, len, DMA_TO_DEVICE); +	if (dma_mapping_error(device->dev, unmap->addr[0])) +		goto err_get_unmap; + +	unmap->to_cnt = 1; + +	unmap->addr[1] = dma_map_page(device->dev, virt_to_page(buf), +				      buff_off, len, DMA_FROM_DEVICE); +	if (dma_mapping_error(device->dev, unmap->addr[1])) +		goto err_get_unmap; + +	unmap->from_cnt = 1; -	flags = DMA_COMPL_DEST_UNMAP_SINGLE | DMA_COMPL_SRC_UNMAP_SINGLE | -		DMA_PREP_INTERRUPT; -	txd = device->device_prep_dma_memcpy(chan, dest, src, len, flags); +	txd = device->device_prep_dma_memcpy(chan, unmap->addr[1], +					     unmap->addr[0], len, +					     DMA_PREP_INTERRUPT);  	if (!txd) -		goto err3; +		goto err_get_unmap;  	txd->callback = ntb_rx_copy_callback;  	txd->callback_param = entry; +	dma_set_unmap(txd, unmap);  	cookie = dmaengine_submit(txd);  	if (dma_submit_error(cookie)) -		goto err3; +		goto err_set_unmap; + +	dmaengine_unmap_put(unmap);  	qp->last_cookie = cookie; @@ -1081,11 +1105,11 @@ static void ntb_async_rx(struct ntb_queue_entry *entry, void *offset,  	return; -err3: -	dma_unmap_single(device->dev, src, len, DMA_TO_DEVICE); -err2: -	dma_unmap_single(device->dev, dest, len, DMA_FROM_DEVICE); -err1: +err_set_unmap: +	dmaengine_unmap_put(unmap); +err_get_unmap: +	dmaengine_unmap_put(unmap); +err_wait:  	/* If the callbacks come out of order, the writing of the index to the  	 * last completed will be out of order.  This may result in the  	 * receive stalling forever. @@ -1165,8 +1189,7 @@ out:  	return 0;  err: -	ntb_list_add(&qp->ntb_rx_pend_q_lock, &entry->entry, -		     &qp->rx_pend_q); +	ntb_list_add(&qp->ntb_rx_pend_q_lock, &entry->entry, &qp->rx_pend_q);  	/* Ensure that the data is fully copied out before clearing the flag */  	wmb();  	hdr->flags = 0; @@ -1175,11 +1198,14 @@ err:  	goto out;  } -static void ntb_transport_rx(unsigned long data) +static int ntb_transport_rxc_db(void *data, int db_num)  { -	struct ntb_transport_qp *qp = (struct ntb_transport_qp *)data; +	struct ntb_transport_qp *qp = data;  	int rc, i; +	dev_dbg(&ntb_query_pdev(qp->ndev)->dev, "%s: doorbell %d received\n", +		__func__, db_num); +  	/* Limit the number of packets processed in a single interrupt to  	 * provide fairness to others  	 */ @@ -1191,16 +1217,8 @@ static void ntb_transport_rx(unsigned long data)  	if (qp->dma_chan)  		dma_async_issue_pending(qp->dma_chan); -} - -static void ntb_transport_rxc_db(void *data, int db_num) -{ -	struct ntb_transport_qp *qp = data; - -	dev_dbg(&ntb_query_pdev(qp->ndev)->dev, "%s: doorbell %d received\n", -		__func__, db_num); -	tasklet_schedule(&qp->rx_work); +	return i;  }  static void ntb_tx_copy_callback(void *data) @@ -1245,12 +1263,12 @@ static void ntb_async_tx(struct ntb_transport_qp *qp,  	struct dma_chan *chan = qp->dma_chan;  	struct dma_device *device;  	size_t dest_off, buff_off; -	dma_addr_t src, dest; +	struct dmaengine_unmap_data *unmap; +	dma_addr_t dest;  	dma_cookie_t cookie;  	void __iomem *offset;  	size_t len = entry->len;  	void *buf = entry->buf; -	unsigned long flags;  	offset = qp->tx_mw + qp->tx_max_frame * qp->tx_index;  	hdr = offset + qp->tx_max_frame - sizeof(struct ntb_payload_header); @@ -1273,28 +1291,41 @@ static void ntb_async_tx(struct ntb_transport_qp *qp,  	if (!is_dma_copy_aligned(device, buff_off, dest_off, len))  		goto err; -	src = dma_map_single(device->dev, buf, len, DMA_TO_DEVICE); -	if (dma_mapping_error(device->dev, src)) +	unmap = dmaengine_get_unmap_data(device->dev, 1, GFP_NOWAIT); +	if (!unmap)  		goto err; -	flags = DMA_COMPL_SRC_UNMAP_SINGLE | DMA_PREP_INTERRUPT; -	txd = device->device_prep_dma_memcpy(chan, dest, src, len, flags); +	unmap->len = len; +	unmap->addr[0] = dma_map_page(device->dev, virt_to_page(buf), +				      buff_off, len, DMA_TO_DEVICE); +	if (dma_mapping_error(device->dev, unmap->addr[0])) +		goto err_get_unmap; + +	unmap->to_cnt = 1; + +	txd = device->device_prep_dma_memcpy(chan, dest, unmap->addr[0], len, +					     DMA_PREP_INTERRUPT);  	if (!txd) -		goto err1; +		goto err_get_unmap;  	txd->callback = ntb_tx_copy_callback;  	txd->callback_param = entry; +	dma_set_unmap(txd, unmap);  	cookie = dmaengine_submit(txd);  	if (dma_submit_error(cookie)) -		goto err1; +		goto err_set_unmap; + +	dmaengine_unmap_put(unmap);  	dma_async_issue_pending(chan);  	qp->tx_async++;  	return; -err1: -	dma_unmap_single(device->dev, src, len, DMA_TO_DEVICE); +err_set_unmap: +	dmaengine_unmap_put(unmap); +err_get_unmap: +	dmaengine_unmap_put(unmap);  err:  	ntb_memcpy_tx(entry, offset);  	qp->tx_memcpy++; @@ -1406,11 +1437,12 @@ ntb_transport_create_queue(void *data, struct pci_dev *pdev,  	qp->tx_handler = handlers->tx_handler;  	qp->event_handler = handlers->event_handler; +	dmaengine_get();  	qp->dma_chan = dma_find_channel(DMA_MEMCPY); -	if (!qp->dma_chan) +	if (!qp->dma_chan) { +		dmaengine_put();  		dev_info(&pdev->dev, "Unable to allocate DMA channel, using CPU instead\n"); -	else -		dmaengine_get(); +	}  	for (i = 0; i < NTB_QP_DEF_NUM_ENTRIES; i++) {  		entry = kzalloc(sizeof(struct ntb_queue_entry), GFP_ATOMIC); @@ -1432,25 +1464,23 @@ ntb_transport_create_queue(void *data, struct pci_dev *pdev,  			     &qp->tx_free_q);  	} -	tasklet_init(&qp->rx_work, ntb_transport_rx, (unsigned long) qp); -  	rc = ntb_register_db_callback(qp->ndev, free_queue, qp,  				      ntb_transport_rxc_db);  	if (rc) -		goto err3; +		goto err2;  	dev_info(&pdev->dev, "NTB Transport QP %d created\n", qp->qp_num);  	return qp; -err3: -	tasklet_disable(&qp->rx_work);  err2:  	while ((entry = ntb_list_rm(&qp->ntb_tx_free_q_lock, &qp->tx_free_q)))  		kfree(entry);  err1:  	while ((entry = ntb_list_rm(&qp->ntb_rx_free_q_lock, &qp->rx_free_q)))  		kfree(entry); +	if (qp->dma_chan) +		dmaengine_put();  	set_bit(free_queue, &nt->qp_bitmap);  err:  	return NULL; @@ -1489,7 +1519,6 @@ void ntb_transport_free_queue(struct ntb_transport_qp *qp)  	}  	ntb_unregister_db_callback(qp->ndev, qp->qp_num); -	tasklet_disable(&qp->rx_work);  	cancel_delayed_work_sync(&qp->link_work);  | 
