* RE: [PATCH v2 2/9] NTB: Add indexed ports NTB API
@ 2016-12-13 4:11 Allen Hubbe
0 siblings, 0 replies; 2+ messages in thread
From: Allen Hubbe @ 2016-12-13 4:11 UTC (permalink / raw)
To: 'Serge Semin', jdmason, dave.jiang, Xiangliang.Yu
Cc: Sergey.Semin, linux-ntb, linux-kernel
From: Serge Semin
> There are some NTB hardware, which can combine more than just two domains
> over NTB. For instance, some IDT PCIe-switches can have NTB-functions
> activated on more than two-ports. The different domains are distinguished
> by ports they are connected to. So the new port-related methods are added to
> the NTB API:
> ntb_port_number() - return local port
> ntb_peer_port_count() - return number of peers local port can connect to
> ntb_peer_port_number(pdix) - return port number by it index
> ntb_peer_port_idx(port) - return port index by it number
>
> Current test-drivers aren't changed much. They still support two-ports devices
> for the time being while multi-ports hardware drivers aren't added.
>
The port methods are the same for PRI/SEC drivers. Rather than duplicating the code, multiport could be made optional in the api, and default implementations provided by ntb common code.
Some comments below.
> Signed-off-by: Serge Semin <fancer.lancer@gmail.com>
>
> ---
> drivers/ntb/hw/amd/ntb_hw_amd.c | 47 ++++++++++++++++++++++++
> drivers/ntb/hw/amd/ntb_hw_amd.h | 9 +++++
> drivers/ntb/hw/intel/ntb_hw_intel.c | 52 ++++++++++++++++++++++++++-
> drivers/ntb/hw/intel/ntb_hw_intel.h | 9 +++++
> drivers/ntb/ntb_transport.c | 6 ++++
> drivers/ntb/test/ntb_perf.c | 4 +++
> drivers/ntb/test/ntb_pingpong.c | 6 ++++
> drivers/ntb/test/ntb_tool.c | 5 +++
> include/linux/ntb.h | 71 +++++++++++++++++++++++++++++++++++++
> 9 files changed, 208 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/ntb/hw/amd/ntb_hw_amd.c b/drivers/ntb/hw/amd/ntb_hw_amd.c
> index 6704327..0b767ef 100644
> --- a/drivers/ntb/hw/amd/ntb_hw_amd.c
> +++ b/drivers/ntb/hw/amd/ntb_hw_amd.c
> @@ -71,6 +71,49 @@ MODULE_AUTHOR("AMD Inc.");
> static const struct file_operations amd_ntb_debugfs_info;
> static struct dentry *debugfs_dir;
>
> +static int amd_ntb_port_number(struct ntb_dev *ntb)
> +{
> + switch (ntb->topo) {
> + case NTB_TOPO_PRI:
> + case NTB_TOPO_B2B_USD:
> + return NTB_PORT_PRI_USD;
> + case NTB_TOPO_SEC:
> + case NTB_TOPO_B2B_DSD:
> + return NTB_PORT_SEC_DSD;
> + default:
> + break;
> + }
> +
> + return -EINVAL;
> +}
> +
> +static int amd_ntb_peer_port_count(struct ntb_dev *ntb)
> +{
> + return NTB_PEER_CNT;
> +}
> +
> +static int amd_ntb_peer_port_number(struct ntb_dev *ntb, int pidx)
> +{
> + int local_port = amd_ntb_port_number(ntb);
> +
> + if (pidx > NTB_PIDX_MAX)
> + return -EINVAL;
pidx may be negative.
> +
> + return (local_port == NTB_PORT_PRI_USD ?
> + NTB_PORT_SEC_DSD : NTB_PORT_PRI_USD);
local_port may be -EINVAL.
It may be simpler to have the same switch statement here as in amd_ntb_port_number(), with the return statements swapped.
> +}
> +
> +static int amd_ntb_peer_port_idx(struct ntb_dev *ntb, int port)
> +{
> + int local_port = amd_ntb_port_number(ntb);
> +
> + if ((local_port == NTB_PORT_PRI_USD && port != NTB_PORT_SEC_DSD) ||
> + (local_port == NTB_PORT_SEC_DSD && port != NTB_PORT_PRI_USD))
> + return -EINVAL;
> +
How about:
peer_port = amd_ntb_peer_port_number(ntb, 0);
if (peer_port == -EINVAL || port != peer_port)
return -EINVAL;
return 0;
> + return 0;
> +}
> +
> static int amd_link_is_up(struct amd_ntb_dev *ndev)
> {
> if (!ndev->peer_sta)
> @@ -431,6 +474,10 @@ static int amd_ntb_peer_spad_write(struct ntb_dev *ntb,
> }
>
> static const struct ntb_dev_ops amd_ntb_ops = {
> + .port_number = amd_ntb_port_number,
> + .peer_port_count = amd_ntb_peer_port_count,
> + .peer_port_number = amd_ntb_peer_port_number,
> + .peer_port_idx = amd_ntb_peer_port_idx,
> .link_is_up = amd_ntb_link_is_up,
> .link_enable = amd_ntb_link_enable,
> .link_disable = amd_ntb_link_disable,
> diff --git a/drivers/ntb/hw/amd/ntb_hw_amd.h b/drivers/ntb/hw/amd/ntb_hw_amd.h
> index 2eac3cd..1aeb08f 100644
> --- a/drivers/ntb/hw/amd/ntb_hw_amd.h
> +++ b/drivers/ntb/hw/amd/ntb_hw_amd.h
> @@ -62,6 +62,10 @@
> #define NTB_LNK_STA_SPEED(x) (((x) & NTB_LNK_STA_SPEED_MASK) >> 16)
> #define NTB_LNK_STA_WIDTH(x) (((x) & NTB_LNK_STA_WIDTH_MASK) >> 20)
>
> +/* port related constants */
> +#define NTB_PEER_CNT (1)
> +#define NTB_PIDX_MAX (0)
Just NTB_PEER_CNT is sufficient. Anything that checks if (pidx > NTB_PIDX_MAX) could check if (pidx >= NTB_PEER_CNT).
> +
> #ifndef read64
> #ifdef readq
> #define read64 readq
> @@ -91,6 +95,11 @@ static inline void _write64(u64 val, void __iomem *mmio)
> #endif
> #endif
>
> +enum amd_ntb_port {
> + NTB_PORT_PRI_USD,
> + NTB_PORT_SEC_DSD
> +};
This could be part of ntb.h, since it will likely be the same for any of the PRI/SEC variety of NTB devices. Making it a part of the api will encourage other PRI/SEC drivers to assign port numbers the same way using these values. Or, drivers may be made consistent by sharing common code.
> +
> enum {
> /* AMD NTB Capability */
> AMD_MW_CNT = 3,
> diff --git a/drivers/ntb/hw/intel/ntb_hw_intel.c b/drivers/ntb/hw/intel/ntb_hw_intel.c
> index 68d9908..7e44dc3 100644
> --- a/drivers/ntb/hw/intel/ntb_hw_intel.c
> +++ b/drivers/ntb/hw/intel/ntb_hw_intel.c
> @@ -1035,6 +1035,49 @@ static void ndev_deinit_debugfs(struct intel_ntb_dev *ndev)
> debugfs_remove_recursive(ndev->debugfs_dir);
> }
Apply same comments above to Intel driver.
>
> +static int intel_ntb_port_number(struct ntb_dev *ntb)
> +{
> + switch (ntb->topo) {
> + case NTB_TOPO_PRI:
> + case NTB_TOPO_B2B_USD:
> + return NTB_PORT_PRI_USD;
> + case NTB_TOPO_SEC:
> + case NTB_TOPO_B2B_DSD:
> + return NTB_PORT_SEC_DSD;
> + default:
> + break;
> + }
> +
> + return -EINVAL;
> +}
> +
> +static int intel_ntb_peer_port_count(struct ntb_dev *ntb)
> +{
> + return NTB_PEER_CNT;
> +}
> +
> +static int intel_ntb_peer_port_number(struct ntb_dev *ntb, int pidx)
> +{
> + int local_port = intel_ntb_port_number(ntb);
> +
> + if (pidx > NTB_PIDX_MAX)
> + return -EINVAL;
> +
> + return (local_port == NTB_PORT_PRI_USD ?
> + NTB_PORT_SEC_DSD : NTB_PORT_PRI_USD);
> +}
> +
> +static int intel_ntb_peer_port_idx(struct ntb_dev *ntb, int port)
> +{
> + int local_port = intel_ntb_port_number(ntb);
> +
> + if ((local_port == NTB_PORT_PRI_USD && port != NTB_PORT_SEC_DSD) ||
> + (local_port == NTB_PORT_SEC_DSD && port != NTB_PORT_PRI_USD))
> + return -EINVAL;
> +
> + return 0;
> +}
> +
> static int intel_ntb_link_is_up(struct ntb_dev *ntb,
> enum ntb_speed *speed,
> enum ntb_width *width)
> @@ -1775,7 +1818,6 @@ static int skx_init_ntb(struct intel_ntb_dev *ndev)
> {
> int rc;
>
> -
> ndev->mw_count = XEON_MW_COUNT;
> ndev->spad_count = SKX_SPAD_COUNT;
> ndev->db_count = SKX_DB_COUNT;
> @@ -2883,6 +2925,10 @@ static const struct intel_ntb_xlat_reg skx_sec_xlat = {
>
> /* operations for primary side of local ntb */
> static const struct ntb_dev_ops intel_ntb_ops = {
> + .port_number = intel_ntb_port_number,
> + .peer_port_count = intel_ntb_peer_port_count,
> + .peer_port_number = intel_ntb_peer_port_number,
> + .peer_port_idx = intel_ntb_peer_port_idx,
> .link_is_up = intel_ntb_link_is_up,
> .link_enable = intel_ntb_link_enable,
> .link_disable = intel_ntb_link_disable,
> @@ -2909,6 +2955,10 @@ static const struct ntb_dev_ops intel_ntb_ops = {
> };
>
> static const struct ntb_dev_ops intel_ntb3_ops = {
> + .port_number = intel_ntb_port_number,
> + .peer_port_count = intel_ntb_peer_port_count,
> + .peer_port_number = intel_ntb_peer_port_number,
> + .peer_port_idx = intel_ntb_peer_port_idx,
> .link_is_up = intel_ntb_link_is_up,
> .link_enable = intel_ntb3_link_enable,
> .link_disable = intel_ntb_link_disable,
> diff --git a/drivers/ntb/hw/intel/ntb_hw_intel.h b/drivers/ntb/hw/intel/ntb_hw_intel.h
> index 6e8c182..f12c960 100644
> --- a/drivers/ntb/hw/intel/ntb_hw_intel.h
> +++ b/drivers/ntb/hw/intel/ntb_hw_intel.h
> @@ -295,6 +295,15 @@
> #define NTB_BAR_MASK_64 ~(0xfull)
> #define NTB_BAR_MASK_32 ~(0xfu)
>
> +/* port related constants */
> +#define NTB_PEER_CNT (1)
> +#define NTB_PIDX_MAX (0)
> +
> +enum intel_ntb_port {
> + NTB_PORT_PRI_USD,
> + NTB_PORT_SEC_DSD
> +};
> +
> struct intel_ntb_dev;
>
> struct intel_ntb_reg {
> diff --git a/drivers/ntb/ntb_transport.c b/drivers/ntb/ntb_transport.c
> index 4eb8adb..37d428d 100644
> --- a/drivers/ntb/ntb_transport.c
> +++ b/drivers/ntb/ntb_transport.c
> @@ -94,6 +94,9 @@ MODULE_PARM_DESC(use_dma, "Use DMA engine to perform large data copy");
>
> static struct dentry *nt_debugfs_dir;
>
> +/* Only two-ports NTB devices are supported */
> +#define PIDX 0
> +
> struct ntb_queue_entry {
> /* ntb_queue list reference */
> struct list_head entry;
> @@ -1083,6 +1086,9 @@ static int ntb_transport_probe(struct ntb_client *self, struct
> ntb_dev *ndev)
> dev_dbg(&ndev->dev,
> "scratchpad is unsafe, proceed anyway...\n");
>
> + if (ntb_peer_port_count(ndev) != 1)
> + dev_warn(&ndev->dev, "Multi-port NTB devices unsupported\n");
> +
> node = dev_to_node(&ndev->dev);
>
> nt = kzalloc_node(sizeof(*nt), GFP_KERNEL, node);
> diff --git a/drivers/ntb/test/ntb_perf.c b/drivers/ntb/test/ntb_perf.c
> index e75d4fd..481827a 100644
> --- a/drivers/ntb/test/ntb_perf.c
> +++ b/drivers/ntb/test/ntb_perf.c
> @@ -76,6 +76,7 @@
> #define DMA_RETRIES 20
> #define SZ_4G (1ULL << 32)
> #define MAX_SEG_ORDER 20 /* no larger than 1M for kmalloc buffer */
> +#define PIDX 0
>
> MODULE_LICENSE(DRIVER_LICENSE);
> MODULE_VERSION(DRIVER_VERSION);
> @@ -764,6 +765,9 @@ static int perf_probe(struct ntb_client *client, struct ntb_dev *ntb)
> return -EIO;
> }
>
> + if (ntb_peer_port_count(ntb) != 1)
> + dev_warn(&ntb->dev, "Multi-port NTB devices unsupported\n");
> +
> node = dev_to_node(&pdev->dev);
>
> perf = kzalloc_node(sizeof(*perf), GFP_KERNEL, node);
> diff --git a/drivers/ntb/test/ntb_pingpong.c b/drivers/ntb/test/ntb_pingpong.c
> index 4358611..6dd7582 100644
> --- a/drivers/ntb/test/ntb_pingpong.c
> +++ b/drivers/ntb/test/ntb_pingpong.c
> @@ -90,6 +90,9 @@ static unsigned long db_init = 0x7;
> module_param(db_init, ulong, 0644);
> MODULE_PARM_DESC(db_init, "Initial doorbell bits to ring on the peer");
>
> +/* Only two-ports NTB devices are supported */
> +#define PIDX 0
> +
> struct pp_ctx {
> struct ntb_dev *ntb;
> u64 db_bits;
> @@ -230,6 +233,9 @@ static int pp_probe(struct ntb_client *client,
> }
> }
>
> + if (ntb_peer_port_count(ntb) != 1)
> + dev_warn(&ntb->dev, "multi-port NTB is unsupported\n");
> +
> pp = kmalloc(sizeof(*pp), GFP_KERNEL);
> if (!pp) {
> rc = -ENOMEM;
> diff --git a/drivers/ntb/test/ntb_tool.c b/drivers/ntb/test/ntb_tool.c
> index 61bf2ef..85b6417 100644
> --- a/drivers/ntb/test/ntb_tool.c
> +++ b/drivers/ntb/test/ntb_tool.c
> @@ -120,6 +120,8 @@ MODULE_AUTHOR(DRIVER_AUTHOR);
> MODULE_DESCRIPTION(DRIVER_DESCRIPTION);
>
> #define MAX_MWS 16
> +/* Only two-ports devices are supported */
> +#define PIDX 0
>
> static struct dentry *tool_dbgfs;
>
> @@ -919,6 +921,9 @@ static int tool_probe(struct ntb_client *self, struct ntb_dev *ntb)
> if (ntb_spad_is_unsafe(ntb))
> dev_dbg(&ntb->dev, "scratchpad is unsafe\n");
>
> + if (ntb_peer_port_count(ntb) != 1)
> + dev_warn(&ntb->dev, "multi-port NTB is unsupported\n");
> +
> tc = kzalloc(sizeof(*tc), GFP_KERNEL);
> if (!tc) {
> rc = -ENOMEM;
> diff --git a/include/linux/ntb.h b/include/linux/ntb.h
> index 5d1f260..3216689 100644
> --- a/include/linux/ntb.h
> +++ b/include/linux/ntb.h
> @@ -179,6 +179,10 @@ static inline int ntb_ctx_ops_is_valid(const struct ntb_ctx_ops *ops)
>
> /**
> * struct ntb_ctx_ops - ntb device operations
> + * @port_number: See ntb_port_number().
> + * @peer_port_count: See ntb_peer_port_count().
> + * @peer_port_number: See ntb_peer_port_number().
> + * @peer_port_idx: See ntb_peer_port_idx().
> * @link_is_up: See ntb_link_is_up().
> * @link_enable: See ntb_link_enable().
> * @link_disable: See ntb_link_disable().
> @@ -212,6 +216,11 @@ static inline int ntb_ctx_ops_is_valid(const struct ntb_ctx_ops *ops)
> * @peer_spad_write: See ntb_peer_spad_write().
> */
> struct ntb_dev_ops {
> + int (*port_number)(struct ntb_dev *ntb);
> + int (*peer_port_count)(struct ntb_dev *ntb);
> + int (*peer_port_number)(struct ntb_dev *ntb, int pidx);
> + int (*peer_port_idx)(struct ntb_dev *ntb, int port);
> +
> int (*link_is_up)(struct ntb_dev *ntb,
> enum ntb_speed *speed, enum ntb_width *width);
> int (*link_enable)(struct ntb_dev *ntb,
> @@ -265,6 +274,10 @@ static inline int ntb_dev_ops_is_valid(const struct ntb_dev_ops *ops)
> {
> /* commented callbacks are not required: */
> return
> + ops->port_number &&
> + ops->peer_port_count &&
> + ops->peer_port_number &&
> + ops->peer_port_idx &&
If these are made optional, then:
!ops->peer_port_count == !ops->port_number &&
!ops->peer_port_number == !ops->port_number &&
!ops->peer_port_idx == !ops->port_number &&
> ops->link_is_up &&
> ops->link_enable &&
> ops->link_disable &&
> @@ -442,6 +455,64 @@ void ntb_link_event(struct ntb_dev *ntb);
> void ntb_db_event(struct ntb_dev *ntb, int vector);
>
> /**
> + * ntb_port_number() - get the local port number
> + * @ntb: NTB device context.
> + *
> + * Hardware must support at least simple two-ports ntb connection
> + *
> + * Return: the local port number
> + */
> +static inline int ntb_port_number(struct ntb_dev *ntb)
> +{
If these are made optional, then:
if (!ntb->ops->port_number)
return ntb_default_port_number(ntb);
> + return ntb->ops->port_number(ntb);
> +}
> +
> +/**
> + * ntb_peer_port_count() - get the number of peer device ports
> + * @ntb: NTB device context.
> + *
> + * Hardware may support an access to memory of several remote domains
> + * over multi-port NTB devices. This method returns the number of peers,
> + * local device can have shared memory with.
> + *
> + * Return: the number of peer ports
> + */
> +static inline int ntb_peer_port_count(struct ntb_dev *ntb)
> +{
> + return ntb->ops->peer_port_count(ntb);
> +}
> +
> +/**
> + * ntb_peer_port_number() - get the peer port by given index
> + * @ntb: NTB device context.
> + * @pidx: Peer port index.
> + *
> + * Peer ports are continuously enumerated by NTB API logic, so this methods
> + * lets to retrieve port real number by its index.
> + *
> + * Return: the peer device port or negative value indicating an error
> + */
> +static inline int ntb_peer_port_number(struct ntb_dev *ntb, int pidx)
> +{
> + return ntb->ops->peer_port_number(ntb, pidx);
> +}
> +
> +/**
> + * ntb_peer_port_idx() - get the peer device port index by given port number
> + * @ntb: NTB device context.
> + * @port: Peer port number.
> + *
> + * Inverse operation of ntb_peer_port_number(), so one can get port index
> + * by specified port number.
> + *
> + * Return: the peer port index or negative value indicating an error
> + */
> +static inline int ntb_peer_port_idx(struct ntb_dev *ntb, int port)
> +{
> + return ntb->ops->peer_port_idx(ntb, port);
> +}
> +
> +/**
> * ntb_link_is_up() - get the current ntb link state
> * @ntb: NTB device context.
> * @speed: OUT - The link speed expressed as PCIe generation number.
> --
> 2.6.6
^ permalink raw reply [flat|nested] 2+ messages in thread
* [PATCH 00/22] NTB: Alter kernel API to support multi-port devices
@ 2016-11-29 17:15 Serge Semin
2016-12-12 21:08 ` [PATCH v2 0/9] " Serge Semin
0 siblings, 1 reply; 2+ messages in thread
From: Serge Semin @ 2016-11-29 17:15 UTC (permalink / raw)
To: jdmason, dave.jiang, Allen.Hubbe, Xiangliang.Yu
Cc: Sergey.Semin, linux-ntb, linux-kernel, Serge Semin
There are devices, like IDT PCIe-switches, which have more than just two ports.
Particularly one device can have up to eight ports with NTB-function activated.
In order to support such devices, NTB kernel API should be altered since
currently it's optimized to work with two-ports devices only.
Here are the changes I made to conform the design we discussed a few months ago:
1) Port-index-related methods are added to KAPI
ntb_port_number();
ntb_peer_port_count();
ntb_peer_port_number(pdix);
ntb_peer_port_idx(port);
2) Link state method returns bitfield of link states for each reachable port
u64 ntb_link_is_up();
3) Link enable/disable methods work with local link side of NTB
ntb_link_enable()/ntb_link_disable();
4) NTB memory window related interface does the following things
ntb_mw_count(pidx); - number of inbound memory windows, which can be allocated
for shared buffer with specified peer device.
ntb_mw_get_align(pidx, widx); - get alignment and size restrition parameters
to properly allocate inbound memory region.
ntb_peer_mw_count(); - get number of outbound memory windows.
ntb_peer_mw_get_addr(widx); - get mapping address of an outbound memory window
Inbound MW based hardware:
ntb_mw_set_trans(pidx, widx); - set translation address of allocated inbound
memory window so a peer device could access it.
ntb_mw_clear_trans(pidx, widx); - clear the translation address of an inbound
memory window.
Outbound MW based hardware:
ntb_peer_mw_set_trans(pidx, widx); - set translation address of a memory
window retrieved from a peer device
ntb_peer_mw_clear_trans(pidx, widx); - clear the translation address of an
outbound memory window
5) Scratchpad interface needs to support multi-port devices as well
ntb_spad_count() - return number of Scratchpad per each port
ntb_peer_spad_addr(pidx, sidx) - address of Scratchpad register of the
peer device with pidx-index
ntb_peer_spad_read(pidx, sidx) - read specified Scratchpad register of the
peer with pidx-index
ntb_peer_spad_write(pidx, sidx) - write data to Scratchpad register of the
peer with pidx-index
6) Introduce new messaging interface of NTB KAPI
ntb_msg_count(); - get number of message registers
ntb_msg_inbits(); - get bitfield of inbound message registers status
ntb_msg_outbits(); - get bitfield of outbound message registers status
ntb_msg_read_sts(); - read the inbound and outbound message registers status
ntb_msg_clear_sts(); - clear status bits of message registers
ntb_msg_set_mask(); - mask interrupts raised by status bits of message
registers.
ntb_msg_clear_mask(); - clear interrupts mask bits of message registers
ntb_msg_recv(midx, *pidx); - read message register with specified index,
additionally getting peer port index which data received from
ntb_msg_send(midx, pidx); - write data to the specified message register
sending it to the passed peer device connected over a pidx port
ntb_msg_event(); - notify driver context of a new message event
7) Topology reduced to be either P2P (port-to-port) or B2B (bridge-to-bridge).
Since there is port number introduced to be part of ntb_dev structure, real
port number can be used to determine Primary and Secondary sides. Intel and AMD
driver are altered to support this novation.
8) Standard test drivers: PingPong, Debugging tool and Raw Perf as well as NTB
Transport drivers don't support multi-port devices at the moment.
Since we haven't got any real multi-port hadrware driver, it's dangerous to
make any serious alterations in the debugging tools. So I have made those
drivers to work the way they wokred before, but using the new NTB API.
The situation will change when I finish porting my current IDT NTB driver to
support new API. Then I'll be able to refactor the tools and test them using
real multi-port hardware.
The changes are made on top of the NTB-fork of the kernel:
https://github.com/jonmason/ntb
of "ntb"-branch with last commit:
9c763584b7c8911106bb77af7e648bef09af9d80 Linux 4.9-rc6
Signed-off-by: Serge Semin <fancer.lancer@gmail.com>
Serge Semin (22):
NTB: Move link state API being first in sources
NTB: Add peer indexed ports NTB API
NTB: Alter NTB API to support both inbound and outbound MW based
interfaces
NTB: Add messaging NTB API
NTB: Alter Scratchpads NTB API to support multi-ports interface
NTB: Slightly alter link state NTB API
NTB: Fix a few ntb.h issues
NTB: Add T-Platforms copyrights to NTB API
NTB Intel: Move link-related methods being first in the driver
NTB Intel: Add port-related NTB API callback methods
NTB Intel: Alter MW interface to fit new NTB API
NTB Intel: Alter Scratchpads interface to fit new NTB API
NTB Intel: Add T-Platforms copyrights to Intel NTB driver
NTB AMD: Move link-related methods being first in the driver
NTB AMD: Add port-related NTB API callback methods
NTB AMD: Alter MW interface to fit new NTB API
NTB AMD: Alter Scratchpads interface to fit new NTB API
NTB AMD: Add T-Platforms copyrights to AMD NTB driver
NTB PingPong: Alter driver to work with two-ports NTB API
NTB Tool: Alter driver to work with two-ports NTB API
NTB Perf: Alter driver to work with two-ports NTB API
NTB Transport: Alter driver to work with two-ports NTB API
drivers/ntb/hw/amd/ntb_hw_amd.c | 310 +++++++++------
drivers/ntb/hw/amd/ntb_hw_amd.h | 12 +
drivers/ntb/hw/intel/ntb_hw_intel.c | 420 ++++++++++++--------
drivers/ntb/hw/intel/ntb_hw_intel.h | 12 +
drivers/ntb/ntb.c | 15 +
drivers/ntb/ntb_transport.c | 43 +-
drivers/ntb/test/ntb_perf.c | 27 +-
drivers/ntb/test/ntb_pingpong.c | 11 +-
drivers/ntb/test/ntb_tool.c | 87 +++--
include/linux/ntb.h | 753 +++++++++++++++++++++++++++++-------
10 files changed, 1221 insertions(+), 469 deletions(-)
--
2.6.6
^ permalink raw reply [flat|nested] 2+ messages in thread
* [PATCH v2 0/9] NTB: Alter kernel API to support multi-port devices
2016-11-29 17:15 [PATCH 00/22] NTB: Alter kernel API to support multi-port devices Serge Semin
@ 2016-12-12 21:08 ` Serge Semin
2016-12-12 21:08 ` [PATCH v2 2/9] NTB: Add indexed ports NTB API Serge Semin
0 siblings, 1 reply; 2+ messages in thread
From: Serge Semin @ 2016-12-12 21:08 UTC (permalink / raw)
To: jdmason, dave.jiang, Allen.Hubbe, Xiangliang.Yu
Cc: Sergey.Semin, linux-ntb, linux-kernel, Serge Semin
There are devices, like IDT PCIe-switches, which have more than just two ports.
Particularly one device can have up to eight ports with NTB-function activated.
In order to support such devices, NTB kernel API should be altered since
currently it's optimized to work with two-ports devices only.
Changelog v2:
- Move comments from cover letter to individual patches
- Combine patches to make code buildable
- Alter patchset to support Intel SKX driver
- Make sure all the API uses the same midx/widx/pidx/sidx arguments notation
- Move new MW API usage description into Documention
- Alter Spad/Msg API checking valid function to make spad and msg interfaces optional
- Alter comments in ntb.h
- Split: add NTB_SPEED_GEN4 and ntb.h comments into separate patches
- Put copyrights into some of the existing patches
- Get rid of TOPO updates
Signed-off-by: Serge Semin <fancer.lancer@gmail.com>
Serge Semin (9):
NTB: Make link-state API being declared first
NTB: Add indexed ports NTB API
NTB: Alter link-state API to support multi-port devices
NTB: Alter MW API to support multi-ports devices
NTB: Alter Scratchpads API to support multi-ports devices
NTB: Add Messaging NTB API
NTB: Add new Memory Windows API documentation
NTB: Add PCIe Gen4 link speed
NTB: Add ntb.h comments
Documentation/ntb.txt | 99 +++++-
drivers/ntb/hw/amd/ntb_hw_amd.c | 291 ++++++++++------
drivers/ntb/hw/amd/ntb_hw_amd.h | 11 +
drivers/ntb/hw/intel/ntb_hw_intel.c | 296 +++++++++++------
drivers/ntb/hw/intel/ntb_hw_intel.h | 11 +
drivers/ntb/ntb.c | 15 +
drivers/ntb/ntb_transport.c | 44 ++-
drivers/ntb/test/ntb_perf.c | 27 +-
drivers/ntb/test/ntb_pingpong.c | 14 +-
drivers/ntb/test/ntb_tool.c | 93 ++++--
include/linux/ntb.h | 639 ++++++++++++++++++++++++++++++------
11 files changed, 1173 insertions(+), 367 deletions(-)
--
2.6.6
^ permalink raw reply [flat|nested] 2+ messages in thread
* [PATCH v2 2/9] NTB: Add indexed ports NTB API
2016-12-12 21:08 ` [PATCH v2 0/9] " Serge Semin
@ 2016-12-12 21:08 ` Serge Semin
0 siblings, 0 replies; 2+ messages in thread
From: Serge Semin @ 2016-12-12 21:08 UTC (permalink / raw)
To: jdmason, dave.jiang, Allen.Hubbe, Xiangliang.Yu
Cc: Sergey.Semin, linux-ntb, linux-kernel, Serge Semin
There are some NTB hardware, which can combine more than just two domains
over NTB. For instance, some IDT PCIe-switches can have NTB-functions
activated on more than two-ports. The different domains are distinguished
by ports they are connected to. So the new port-related methods are added to
the NTB API:
ntb_port_number() - return local port
ntb_peer_port_count() - return number of peers local port can connect to
ntb_peer_port_number(pdix) - return port number by it index
ntb_peer_port_idx(port) - return port index by it number
Current test-drivers aren't changed much. They still support two-ports devices
for the time being while multi-ports hardware drivers aren't added.
Signed-off-by: Serge Semin <fancer.lancer@gmail.com>
---
drivers/ntb/hw/amd/ntb_hw_amd.c | 47 ++++++++++++++++++++++++
drivers/ntb/hw/amd/ntb_hw_amd.h | 9 +++++
drivers/ntb/hw/intel/ntb_hw_intel.c | 52 ++++++++++++++++++++++++++-
drivers/ntb/hw/intel/ntb_hw_intel.h | 9 +++++
drivers/ntb/ntb_transport.c | 6 ++++
drivers/ntb/test/ntb_perf.c | 4 +++
drivers/ntb/test/ntb_pingpong.c | 6 ++++
drivers/ntb/test/ntb_tool.c | 5 +++
include/linux/ntb.h | 71 +++++++++++++++++++++++++++++++++++++
9 files changed, 208 insertions(+), 1 deletion(-)
diff --git a/drivers/ntb/hw/amd/ntb_hw_amd.c b/drivers/ntb/hw/amd/ntb_hw_amd.c
index 6704327..0b767ef 100644
--- a/drivers/ntb/hw/amd/ntb_hw_amd.c
+++ b/drivers/ntb/hw/amd/ntb_hw_amd.c
@@ -71,6 +71,49 @@ MODULE_AUTHOR("AMD Inc.");
static const struct file_operations amd_ntb_debugfs_info;
static struct dentry *debugfs_dir;
+static int amd_ntb_port_number(struct ntb_dev *ntb)
+{
+ switch (ntb->topo) {
+ case NTB_TOPO_PRI:
+ case NTB_TOPO_B2B_USD:
+ return NTB_PORT_PRI_USD;
+ case NTB_TOPO_SEC:
+ case NTB_TOPO_B2B_DSD:
+ return NTB_PORT_SEC_DSD;
+ default:
+ break;
+ }
+
+ return -EINVAL;
+}
+
+static int amd_ntb_peer_port_count(struct ntb_dev *ntb)
+{
+ return NTB_PEER_CNT;
+}
+
+static int amd_ntb_peer_port_number(struct ntb_dev *ntb, int pidx)
+{
+ int local_port = amd_ntb_port_number(ntb);
+
+ if (pidx > NTB_PIDX_MAX)
+ return -EINVAL;
+
+ return (local_port == NTB_PORT_PRI_USD ?
+ NTB_PORT_SEC_DSD : NTB_PORT_PRI_USD);
+}
+
+static int amd_ntb_peer_port_idx(struct ntb_dev *ntb, int port)
+{
+ int local_port = amd_ntb_port_number(ntb);
+
+ if ((local_port == NTB_PORT_PRI_USD && port != NTB_PORT_SEC_DSD) ||
+ (local_port == NTB_PORT_SEC_DSD && port != NTB_PORT_PRI_USD))
+ return -EINVAL;
+
+ return 0;
+}
+
static int amd_link_is_up(struct amd_ntb_dev *ndev)
{
if (!ndev->peer_sta)
@@ -431,6 +474,10 @@ static int amd_ntb_peer_spad_write(struct ntb_dev *ntb,
}
static const struct ntb_dev_ops amd_ntb_ops = {
+ .port_number = amd_ntb_port_number,
+ .peer_port_count = amd_ntb_peer_port_count,
+ .peer_port_number = amd_ntb_peer_port_number,
+ .peer_port_idx = amd_ntb_peer_port_idx,
.link_is_up = amd_ntb_link_is_up,
.link_enable = amd_ntb_link_enable,
.link_disable = amd_ntb_link_disable,
diff --git a/drivers/ntb/hw/amd/ntb_hw_amd.h b/drivers/ntb/hw/amd/ntb_hw_amd.h
index 2eac3cd..1aeb08f 100644
--- a/drivers/ntb/hw/amd/ntb_hw_amd.h
+++ b/drivers/ntb/hw/amd/ntb_hw_amd.h
@@ -62,6 +62,10 @@
#define NTB_LNK_STA_SPEED(x) (((x) & NTB_LNK_STA_SPEED_MASK) >> 16)
#define NTB_LNK_STA_WIDTH(x) (((x) & NTB_LNK_STA_WIDTH_MASK) >> 20)
+/* port related constants */
+#define NTB_PEER_CNT (1)
+#define NTB_PIDX_MAX (0)
+
#ifndef read64
#ifdef readq
#define read64 readq
@@ -91,6 +95,11 @@ static inline void _write64(u64 val, void __iomem *mmio)
#endif
#endif
+enum amd_ntb_port {
+ NTB_PORT_PRI_USD,
+ NTB_PORT_SEC_DSD
+};
+
enum {
/* AMD NTB Capability */
AMD_MW_CNT = 3,
diff --git a/drivers/ntb/hw/intel/ntb_hw_intel.c b/drivers/ntb/hw/intel/ntb_hw_intel.c
index 68d9908..7e44dc3 100644
--- a/drivers/ntb/hw/intel/ntb_hw_intel.c
+++ b/drivers/ntb/hw/intel/ntb_hw_intel.c
@@ -1035,6 +1035,49 @@ static void ndev_deinit_debugfs(struct intel_ntb_dev *ndev)
debugfs_remove_recursive(ndev->debugfs_dir);
}
+static int intel_ntb_port_number(struct ntb_dev *ntb)
+{
+ switch (ntb->topo) {
+ case NTB_TOPO_PRI:
+ case NTB_TOPO_B2B_USD:
+ return NTB_PORT_PRI_USD;
+ case NTB_TOPO_SEC:
+ case NTB_TOPO_B2B_DSD:
+ return NTB_PORT_SEC_DSD;
+ default:
+ break;
+ }
+
+ return -EINVAL;
+}
+
+static int intel_ntb_peer_port_count(struct ntb_dev *ntb)
+{
+ return NTB_PEER_CNT;
+}
+
+static int intel_ntb_peer_port_number(struct ntb_dev *ntb, int pidx)
+{
+ int local_port = intel_ntb_port_number(ntb);
+
+ if (pidx > NTB_PIDX_MAX)
+ return -EINVAL;
+
+ return (local_port == NTB_PORT_PRI_USD ?
+ NTB_PORT_SEC_DSD : NTB_PORT_PRI_USD);
+}
+
+static int intel_ntb_peer_port_idx(struct ntb_dev *ntb, int port)
+{
+ int local_port = intel_ntb_port_number(ntb);
+
+ if ((local_port == NTB_PORT_PRI_USD && port != NTB_PORT_SEC_DSD) ||
+ (local_port == NTB_PORT_SEC_DSD && port != NTB_PORT_PRI_USD))
+ return -EINVAL;
+
+ return 0;
+}
+
static int intel_ntb_link_is_up(struct ntb_dev *ntb,
enum ntb_speed *speed,
enum ntb_width *width)
@@ -1775,7 +1818,6 @@ static int skx_init_ntb(struct intel_ntb_dev *ndev)
{
int rc;
-
ndev->mw_count = XEON_MW_COUNT;
ndev->spad_count = SKX_SPAD_COUNT;
ndev->db_count = SKX_DB_COUNT;
@@ -2883,6 +2925,10 @@ static const struct intel_ntb_xlat_reg skx_sec_xlat = {
/* operations for primary side of local ntb */
static const struct ntb_dev_ops intel_ntb_ops = {
+ .port_number = intel_ntb_port_number,
+ .peer_port_count = intel_ntb_peer_port_count,
+ .peer_port_number = intel_ntb_peer_port_number,
+ .peer_port_idx = intel_ntb_peer_port_idx,
.link_is_up = intel_ntb_link_is_up,
.link_enable = intel_ntb_link_enable,
.link_disable = intel_ntb_link_disable,
@@ -2909,6 +2955,10 @@ static const struct ntb_dev_ops intel_ntb_ops = {
};
static const struct ntb_dev_ops intel_ntb3_ops = {
+ .port_number = intel_ntb_port_number,
+ .peer_port_count = intel_ntb_peer_port_count,
+ .peer_port_number = intel_ntb_peer_port_number,
+ .peer_port_idx = intel_ntb_peer_port_idx,
.link_is_up = intel_ntb_link_is_up,
.link_enable = intel_ntb3_link_enable,
.link_disable = intel_ntb_link_disable,
diff --git a/drivers/ntb/hw/intel/ntb_hw_intel.h b/drivers/ntb/hw/intel/ntb_hw_intel.h
index 6e8c182..f12c960 100644
--- a/drivers/ntb/hw/intel/ntb_hw_intel.h
+++ b/drivers/ntb/hw/intel/ntb_hw_intel.h
@@ -295,6 +295,15 @@
#define NTB_BAR_MASK_64 ~(0xfull)
#define NTB_BAR_MASK_32 ~(0xfu)
+/* port related constants */
+#define NTB_PEER_CNT (1)
+#define NTB_PIDX_MAX (0)
+
+enum intel_ntb_port {
+ NTB_PORT_PRI_USD,
+ NTB_PORT_SEC_DSD
+};
+
struct intel_ntb_dev;
struct intel_ntb_reg {
diff --git a/drivers/ntb/ntb_transport.c b/drivers/ntb/ntb_transport.c
index 4eb8adb..37d428d 100644
--- a/drivers/ntb/ntb_transport.c
+++ b/drivers/ntb/ntb_transport.c
@@ -94,6 +94,9 @@ MODULE_PARM_DESC(use_dma, "Use DMA engine to perform large data copy");
static struct dentry *nt_debugfs_dir;
+/* Only two-ports NTB devices are supported */
+#define PIDX 0
+
struct ntb_queue_entry {
/* ntb_queue list reference */
struct list_head entry;
@@ -1083,6 +1086,9 @@ static int ntb_transport_probe(struct ntb_client *self, struct ntb_dev *ndev)
dev_dbg(&ndev->dev,
"scratchpad is unsafe, proceed anyway...\n");
+ if (ntb_peer_port_count(ndev) != 1)
+ dev_warn(&ndev->dev, "Multi-port NTB devices unsupported\n");
+
node = dev_to_node(&ndev->dev);
nt = kzalloc_node(sizeof(*nt), GFP_KERNEL, node);
diff --git a/drivers/ntb/test/ntb_perf.c b/drivers/ntb/test/ntb_perf.c
index e75d4fd..481827a 100644
--- a/drivers/ntb/test/ntb_perf.c
+++ b/drivers/ntb/test/ntb_perf.c
@@ -76,6 +76,7 @@
#define DMA_RETRIES 20
#define SZ_4G (1ULL << 32)
#define MAX_SEG_ORDER 20 /* no larger than 1M for kmalloc buffer */
+#define PIDX 0
MODULE_LICENSE(DRIVER_LICENSE);
MODULE_VERSION(DRIVER_VERSION);
@@ -764,6 +765,9 @@ static int perf_probe(struct ntb_client *client, struct ntb_dev *ntb)
return -EIO;
}
+ if (ntb_peer_port_count(ntb) != 1)
+ dev_warn(&ntb->dev, "Multi-port NTB devices unsupported\n");
+
node = dev_to_node(&pdev->dev);
perf = kzalloc_node(sizeof(*perf), GFP_KERNEL, node);
diff --git a/drivers/ntb/test/ntb_pingpong.c b/drivers/ntb/test/ntb_pingpong.c
index 4358611..6dd7582 100644
--- a/drivers/ntb/test/ntb_pingpong.c
+++ b/drivers/ntb/test/ntb_pingpong.c
@@ -90,6 +90,9 @@ static unsigned long db_init = 0x7;
module_param(db_init, ulong, 0644);
MODULE_PARM_DESC(db_init, "Initial doorbell bits to ring on the peer");
+/* Only two-ports NTB devices are supported */
+#define PIDX 0
+
struct pp_ctx {
struct ntb_dev *ntb;
u64 db_bits;
@@ -230,6 +233,9 @@ static int pp_probe(struct ntb_client *client,
}
}
+ if (ntb_peer_port_count(ntb) != 1)
+ dev_warn(&ntb->dev, "multi-port NTB is unsupported\n");
+
pp = kmalloc(sizeof(*pp), GFP_KERNEL);
if (!pp) {
rc = -ENOMEM;
diff --git a/drivers/ntb/test/ntb_tool.c b/drivers/ntb/test/ntb_tool.c
index 61bf2ef..85b6417 100644
--- a/drivers/ntb/test/ntb_tool.c
+++ b/drivers/ntb/test/ntb_tool.c
@@ -120,6 +120,8 @@ MODULE_AUTHOR(DRIVER_AUTHOR);
MODULE_DESCRIPTION(DRIVER_DESCRIPTION);
#define MAX_MWS 16
+/* Only two-ports devices are supported */
+#define PIDX 0
static struct dentry *tool_dbgfs;
@@ -919,6 +921,9 @@ static int tool_probe(struct ntb_client *self, struct ntb_dev *ntb)
if (ntb_spad_is_unsafe(ntb))
dev_dbg(&ntb->dev, "scratchpad is unsafe\n");
+ if (ntb_peer_port_count(ntb) != 1)
+ dev_warn(&ntb->dev, "multi-port NTB is unsupported\n");
+
tc = kzalloc(sizeof(*tc), GFP_KERNEL);
if (!tc) {
rc = -ENOMEM;
diff --git a/include/linux/ntb.h b/include/linux/ntb.h
index 5d1f260..3216689 100644
--- a/include/linux/ntb.h
+++ b/include/linux/ntb.h
@@ -179,6 +179,10 @@ static inline int ntb_ctx_ops_is_valid(const struct ntb_ctx_ops *ops)
/**
* struct ntb_ctx_ops - ntb device operations
+ * @port_number: See ntb_port_number().
+ * @peer_port_count: See ntb_peer_port_count().
+ * @peer_port_number: See ntb_peer_port_number().
+ * @peer_port_idx: See ntb_peer_port_idx().
* @link_is_up: See ntb_link_is_up().
* @link_enable: See ntb_link_enable().
* @link_disable: See ntb_link_disable().
@@ -212,6 +216,11 @@ static inline int ntb_ctx_ops_is_valid(const struct ntb_ctx_ops *ops)
* @peer_spad_write: See ntb_peer_spad_write().
*/
struct ntb_dev_ops {
+ int (*port_number)(struct ntb_dev *ntb);
+ int (*peer_port_count)(struct ntb_dev *ntb);
+ int (*peer_port_number)(struct ntb_dev *ntb, int pidx);
+ int (*peer_port_idx)(struct ntb_dev *ntb, int port);
+
int (*link_is_up)(struct ntb_dev *ntb,
enum ntb_speed *speed, enum ntb_width *width);
int (*link_enable)(struct ntb_dev *ntb,
@@ -265,6 +274,10 @@ static inline int ntb_dev_ops_is_valid(const struct ntb_dev_ops *ops)
{
/* commented callbacks are not required: */
return
+ ops->port_number &&
+ ops->peer_port_count &&
+ ops->peer_port_number &&
+ ops->peer_port_idx &&
ops->link_is_up &&
ops->link_enable &&
ops->link_disable &&
@@ -442,6 +455,64 @@ void ntb_link_event(struct ntb_dev *ntb);
void ntb_db_event(struct ntb_dev *ntb, int vector);
/**
+ * ntb_port_number() - get the local port number
+ * @ntb: NTB device context.
+ *
+ * Hardware must support at least simple two-ports ntb connection
+ *
+ * Return: the local port number
+ */
+static inline int ntb_port_number(struct ntb_dev *ntb)
+{
+ return ntb->ops->port_number(ntb);
+}
+
+/**
+ * ntb_peer_port_count() - get the number of peer device ports
+ * @ntb: NTB device context.
+ *
+ * Hardware may support an access to memory of several remote domains
+ * over multi-port NTB devices. This method returns the number of peers,
+ * local device can have shared memory with.
+ *
+ * Return: the number of peer ports
+ */
+static inline int ntb_peer_port_count(struct ntb_dev *ntb)
+{
+ return ntb->ops->peer_port_count(ntb);
+}
+
+/**
+ * ntb_peer_port_number() - get the peer port by given index
+ * @ntb: NTB device context.
+ * @pidx: Peer port index.
+ *
+ * Peer ports are continuously enumerated by NTB API logic, so this methods
+ * lets to retrieve port real number by its index.
+ *
+ * Return: the peer device port or negative value indicating an error
+ */
+static inline int ntb_peer_port_number(struct ntb_dev *ntb, int pidx)
+{
+ return ntb->ops->peer_port_number(ntb, pidx);
+}
+
+/**
+ * ntb_peer_port_idx() - get the peer device port index by given port number
+ * @ntb: NTB device context.
+ * @port: Peer port number.
+ *
+ * Inverse operation of ntb_peer_port_number(), so one can get port index
+ * by specified port number.
+ *
+ * Return: the peer port index or negative value indicating an error
+ */
+static inline int ntb_peer_port_idx(struct ntb_dev *ntb, int port)
+{
+ return ntb->ops->peer_port_idx(ntb, port);
+}
+
+/**
* ntb_link_is_up() - get the current ntb link state
* @ntb: NTB device context.
* @speed: OUT - The link speed expressed as PCIe generation number.
--
2.6.6
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2016-12-13 4:12 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-12-13 4:11 [PATCH v2 2/9] NTB: Add indexed ports NTB API Allen Hubbe
-- strict thread matches above, loose matches on Subject: below --
2016-11-29 17:15 [PATCH 00/22] NTB: Alter kernel API to support multi-port devices Serge Semin
2016-12-12 21:08 ` [PATCH v2 0/9] " Serge Semin
2016-12-12 21:08 ` [PATCH v2 2/9] NTB: Add indexed ports NTB API Serge Semin
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).