Commit 26b3a37b authored by Logan Gunthorpe's avatar Logan Gunthorpe Committed by Jon Mason

NTB: Introduce MSI library

The NTB MSI library allows passing MSI interrupts across a memory
window. This offers similar functionality to doorbells or messages
except will often have much better latency and the client can
potentially use significantly more remote interrupts than typical hardware
provides for doorbells. (Which can be important in high-multiport
setups.)

The library utilizes one memory window per peer and uses the highest
index memory windows. Before any ntb_msi function may be used, the user
must call ntb_msi_init(). It may then setup and tear down the memory
windows when the link state changes using ntb_msi_setup_mws() and
ntb_msi_clear_mws().

The peer which receives the interrupt must call ntb_msim_request_irq()
to assign the interrupt handler (this function is functionally
similar to devm_request_irq()) and the returned descriptor must be
transferred to the peer which can use it to trigger the interrupt.
The triggering peer, once having received the descriptor, can
trigger the interrupt by calling ntb_msi_peer_trigger().
Signed-off-by: default avatarLogan Gunthorpe <logang@deltatee.com>
Cc: Dave Jiang <dave.jiang@intel.com>
Cc: Allen Hubbe <allenbh@gmail.com>
Signed-off-by: default avatarJon Mason <jdmason@kudzu.us>
parent d217e07b
...@@ -12,6 +12,17 @@ menuconfig NTB ...@@ -12,6 +12,17 @@ menuconfig NTB
if NTB if NTB
config NTB_MSI
bool "MSI Interrupt Support"
depends on PCI_MSI
help
Support using MSI interrupt forwarding instead of (or in addition to)
hardware doorbells. MSI interrupts typically offer lower latency
than doorbells and more MSI interrupts can be made available to
clients. However this requires an extra memory window and support
in the hardware driver for creating the MSI interrupts.
If unsure, say N.
source "drivers/ntb/hw/Kconfig" source "drivers/ntb/hw/Kconfig"
source "drivers/ntb/test/Kconfig" source "drivers/ntb/test/Kconfig"
......
...@@ -2,3 +2,4 @@ obj-$(CONFIG_NTB) += ntb.o hw/ test/ ...@@ -2,3 +2,4 @@ obj-$(CONFIG_NTB) += ntb.o hw/ test/
obj-$(CONFIG_NTB_TRANSPORT) += ntb_transport.o obj-$(CONFIG_NTB_TRANSPORT) += ntb_transport.o
ntb-y := core.o ntb-y := core.o
ntb-$(CONFIG_NTB_MSI) += msi.o
This diff is collapsed.
...@@ -58,9 +58,11 @@ ...@@ -58,9 +58,11 @@
#include <linux/completion.h> #include <linux/completion.h>
#include <linux/device.h> #include <linux/device.h>
#include <linux/interrupt.h>
struct ntb_client; struct ntb_client;
struct ntb_dev; struct ntb_dev;
struct ntb_msi;
struct pci_dev; struct pci_dev;
/** /**
...@@ -426,6 +428,10 @@ struct ntb_dev { ...@@ -426,6 +428,10 @@ struct ntb_dev {
spinlock_t ctx_lock; spinlock_t ctx_lock;
/* block unregister until device is fully released */ /* block unregister until device is fully released */
struct completion released; struct completion released;
#ifdef CONFIG_NTB_MSI
struct ntb_msi *msi;
#endif
}; };
#define dev_ntb(__dev) container_of((__dev), struct ntb_dev, dev) #define dev_ntb(__dev) container_of((__dev), struct ntb_dev, dev)
...@@ -1627,4 +1633,71 @@ static inline int ntb_peer_highest_mw_idx(struct ntb_dev *ntb, int pidx) ...@@ -1627,4 +1633,71 @@ static inline int ntb_peer_highest_mw_idx(struct ntb_dev *ntb, int pidx)
return ntb_mw_count(ntb, pidx) - ret - 1; return ntb_mw_count(ntb, pidx) - ret - 1;
} }
struct ntb_msi_desc {
u32 addr_offset;
u32 data;
};
#ifdef CONFIG_NTB_MSI
int ntb_msi_init(struct ntb_dev *ntb, void (*desc_changed)(void *ctx));
int ntb_msi_setup_mws(struct ntb_dev *ntb);
void ntb_msi_clear_mws(struct ntb_dev *ntb);
int ntbm_msi_request_threaded_irq(struct ntb_dev *ntb, irq_handler_t handler,
irq_handler_t thread_fn,
const char *name, void *dev_id,
struct ntb_msi_desc *msi_desc);
void ntbm_msi_free_irq(struct ntb_dev *ntb, unsigned int irq, void *dev_id);
int ntb_msi_peer_trigger(struct ntb_dev *ntb, int peer,
struct ntb_msi_desc *desc);
int ntb_msi_peer_addr(struct ntb_dev *ntb, int peer,
struct ntb_msi_desc *desc,
phys_addr_t *msi_addr);
#else /* not CONFIG_NTB_MSI */
static inline int ntb_msi_init(struct ntb_dev *ntb,
void (*desc_changed)(void *ctx))
{
return -EOPNOTSUPP;
}
static inline int ntb_msi_setup_mws(struct ntb_dev *ntb)
{
return -EOPNOTSUPP;
}
static inline void ntb_msi_clear_mws(struct ntb_dev *ntb) {}
static inline int ntbm_msi_request_threaded_irq(struct ntb_dev *ntb,
irq_handler_t handler,
irq_handler_t thread_fn,
const char *name, void *dev_id,
struct ntb_msi_desc *msi_desc)
{
return -EOPNOTSUPP;
}
static inline void ntbm_msi_free_irq(struct ntb_dev *ntb, unsigned int irq,
void *dev_id) {}
static inline int ntb_msi_peer_trigger(struct ntb_dev *ntb, int peer,
struct ntb_msi_desc *desc)
{
return -EOPNOTSUPP;
}
static inline int ntb_msi_peer_addr(struct ntb_dev *ntb, int peer,
struct ntb_msi_desc *desc,
phys_addr_t *msi_addr)
{
return -EOPNOTSUPP;
}
#endif /* CONFIG_NTB_MSI */
static inline int ntbm_msi_request_irq(struct ntb_dev *ntb,
irq_handler_t handler,
const char *name, void *dev_id,
struct ntb_msi_desc *msi_desc)
{
return ntbm_msi_request_threaded_irq(ntb, handler, NULL, name,
dev_id, msi_desc);
}
#endif #endif
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment