Commit 5f1b1f06 authored by Logan Gunthorpe's avatar Logan Gunthorpe Committed by Jon Mason

NTB: Introduce functions to calculate multi-port resource index

When using multi-ports each port uses resources (dbs, msgs, mws, etc)
on every other port. Creating a mapping for these resources such that
each port has a corresponding resource on every other port is a bit
tricky.

Introduce the ntb_peer_resource_idx() function for this purpose.
It returns the peer resource number that will correspond with the
local peer index on the remote peer.

Also, introduce ntb_peer_highest_mw_idx() which will use
ntb_peer_resource_idx() but return the MW index starting with the
highest index and working down.
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 246a42c5
......@@ -1557,4 +1557,74 @@ static inline int ntb_peer_msg_write(struct ntb_dev *ntb, int pidx, int midx,
return ntb->ops->peer_msg_write(ntb, pidx, midx, msg);
}
/**
* ntb_peer_resource_idx() - get a resource index for a given peer idx
* @ntb: NTB device context.
* @pidx: Peer port index.
*
* When constructing a graph of peers, each remote peer must use a different
* resource index (mw, doorbell, etc) to communicate with each other
* peer.
*
* In a two peer system, this function should always return 0 such that
* resource 0 points to the remote peer on both ports.
*
* In a 5 peer system, this function will return the following matrix
*
* pidx \ port 0 1 2 3 4
* 0 0 0 1 2 3
* 1 0 1 1 2 3
* 2 0 1 2 2 3
* 3 0 1 2 3 3
*
* For example, if this function is used to program peer's memory
* windows, port 0 will program MW 0 on all it's peers to point to itself.
* port 1 will program MW 0 in port 0 to point to itself and MW 1 on all
* other ports. etc.
*
* For the legacy two host case, ntb_port_number() and ntb_peer_port_number()
* both return zero and therefore this function will always return zero.
* So MW 0 on each host would be programmed to point to the other host.
*
* Return: the resource index to use for that peer.
*/
static inline int ntb_peer_resource_idx(struct ntb_dev *ntb, int pidx)
{
int local_port, peer_port;
if (pidx >= ntb_peer_port_count(ntb))
return -EINVAL;
local_port = ntb_logical_port_number(ntb);
peer_port = ntb_peer_logical_port_number(ntb, pidx);
if (peer_port < local_port)
return local_port - 1;
else
return local_port;
}
/**
* ntb_peer_highest_mw_idx() - get a memory window index for a given peer idx
* using the highest index memory windows first
*
* @ntb: NTB device context.
* @pidx: Peer port index.
*
* Like ntb_peer_resource_idx(), except it returns indexes starting with
* last memory window index.
*
* Return: the resource index to use for that peer.
*/
static inline int ntb_peer_highest_mw_idx(struct ntb_dev *ntb, int pidx)
{
int ret;
ret = ntb_peer_resource_idx(ntb, pidx);
if (ret < 0)
return ret;
return ntb_mw_count(ntb, pidx) - ret - 1;
}
#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