Skip to content

Commit 5f1b1f0

Browse files
lsgunthjonmason
authored andcommitted
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: Logan Gunthorpe <[email protected]> Cc: Dave Jiang <[email protected]> Cc: Allen Hubbe <[email protected]> Signed-off-by: Jon Mason <[email protected]>
1 parent 246a42c commit 5f1b1f0

File tree

1 file changed

+70
-0
lines changed

1 file changed

+70
-0
lines changed

include/linux/ntb.h

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1557,4 +1557,74 @@ static inline int ntb_peer_msg_write(struct ntb_dev *ntb, int pidx, int midx,
15571557
return ntb->ops->peer_msg_write(ntb, pidx, midx, msg);
15581558
}
15591559

1560+
/**
1561+
* ntb_peer_resource_idx() - get a resource index for a given peer idx
1562+
* @ntb: NTB device context.
1563+
* @pidx: Peer port index.
1564+
*
1565+
* When constructing a graph of peers, each remote peer must use a different
1566+
* resource index (mw, doorbell, etc) to communicate with each other
1567+
* peer.
1568+
*
1569+
* In a two peer system, this function should always return 0 such that
1570+
* resource 0 points to the remote peer on both ports.
1571+
*
1572+
* In a 5 peer system, this function will return the following matrix
1573+
*
1574+
* pidx \ port 0 1 2 3 4
1575+
* 0 0 0 1 2 3
1576+
* 1 0 1 1 2 3
1577+
* 2 0 1 2 2 3
1578+
* 3 0 1 2 3 3
1579+
*
1580+
* For example, if this function is used to program peer's memory
1581+
* windows, port 0 will program MW 0 on all it's peers to point to itself.
1582+
* port 1 will program MW 0 in port 0 to point to itself and MW 1 on all
1583+
* other ports. etc.
1584+
*
1585+
* For the legacy two host case, ntb_port_number() and ntb_peer_port_number()
1586+
* both return zero and therefore this function will always return zero.
1587+
* So MW 0 on each host would be programmed to point to the other host.
1588+
*
1589+
* Return: the resource index to use for that peer.
1590+
*/
1591+
static inline int ntb_peer_resource_idx(struct ntb_dev *ntb, int pidx)
1592+
{
1593+
int local_port, peer_port;
1594+
1595+
if (pidx >= ntb_peer_port_count(ntb))
1596+
return -EINVAL;
1597+
1598+
local_port = ntb_logical_port_number(ntb);
1599+
peer_port = ntb_peer_logical_port_number(ntb, pidx);
1600+
1601+
if (peer_port < local_port)
1602+
return local_port - 1;
1603+
else
1604+
return local_port;
1605+
}
1606+
1607+
/**
1608+
* ntb_peer_highest_mw_idx() - get a memory window index for a given peer idx
1609+
* using the highest index memory windows first
1610+
*
1611+
* @ntb: NTB device context.
1612+
* @pidx: Peer port index.
1613+
*
1614+
* Like ntb_peer_resource_idx(), except it returns indexes starting with
1615+
* last memory window index.
1616+
*
1617+
* Return: the resource index to use for that peer.
1618+
*/
1619+
static inline int ntb_peer_highest_mw_idx(struct ntb_dev *ntb, int pidx)
1620+
{
1621+
int ret;
1622+
1623+
ret = ntb_peer_resource_idx(ntb, pidx);
1624+
if (ret < 0)
1625+
return ret;
1626+
1627+
return ntb_mw_count(ntb, pidx) - ret - 1;
1628+
}
1629+
15601630
#endif

0 commit comments

Comments
 (0)