summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLogan Gunthorpe <logang@deltatee.com>2019-05-23 18:30:53 -0400
committerJon Mason <jdmason@kudzu.us>2019-06-13 08:59:47 -0400
commit246a42c51bc5dd247629f86c87d5e1b7628343c4 (patch)
tree92be49c08271bb83b9f5fc653192dc131b8f8301
parentfcdf8e95fa3b97097bd4e200f0ee04df85b04d99 (diff)
NTB: Introduce helper functions to calculate logical port number
This patch introduces the "Logical Port Number" which is similar to the "Port Number" in that it enumerates the ports in the system. The original (or Physical) "Port Number" can be any number used by the hardware to uniquely identify a port in the system. The "Logical Port Number" enumerates all ports in the system from 0 to the number of ports minus one. For example a system with 5 ports might have the following port numbers which would be enumerated thusly: Port Number: 1 2 5 7 116 Logical Port Number: 0 1 2 3 4 The logical port number is useful when calculating which resources to use for which peers. So we thus define two helper functions: ntb_logical_port_number() and ntb_peer_logical_port_number() which provide the "Logical Port Number" for the local port and any peer respectively. Signed-off-by: Logan Gunthorpe <logang@deltatee.com> Cc: Dave Jiang <dave.jiang@intel.com> Cc: Allen Hubbe <allenbh@gmail.com> Cc: Serge Semin <fancer.lancer@gmail.com> Signed-off-by: Jon Mason <jdmason@kudzu.us>
-rw-r--r--include/linux/ntb.h53
1 files changed, 52 insertions, 1 deletions
diff --git a/include/linux/ntb.h b/include/linux/ntb.h
index 604abc883741..2fadd0352683 100644
--- a/include/linux/ntb.h
+++ b/include/linux/ntb.h
@@ -616,7 +616,6 @@ static inline int ntb_port_number(struct ntb_dev *ntb)
616 616
617 return ntb->ops->port_number(ntb); 617 return ntb->ops->port_number(ntb);
618} 618}
619
620/** 619/**
621 * ntb_peer_port_count() - get the number of peer device ports 620 * ntb_peer_port_count() - get the number of peer device ports
622 * @ntb: NTB device context. 621 * @ntb: NTB device context.
@@ -654,6 +653,58 @@ static inline int ntb_peer_port_number(struct ntb_dev *ntb, int pidx)
654} 653}
655 654
656/** 655/**
656 * ntb_logical_port_number() - get the logical port number of the local port
657 * @ntb: NTB device context.
658 *
659 * The Logical Port Number is defined to be a unique number for each
660 * port starting from zero through to the number of ports minus one.
661 * This is in contrast to the Port Number where each port can be assigned
662 * any unique physical number by the hardware.
663 *
664 * The logical port number is useful for calculating the resource indexes
665 * used by peers.
666 *
667 * Return: the logical port number or negative value indicating an error
668 */
669static inline int ntb_logical_port_number(struct ntb_dev *ntb)
670{
671 int lport = ntb_port_number(ntb);
672 int pidx;
673
674 if (lport < 0)
675 return lport;
676
677 for (pidx = 0; pidx < ntb_peer_port_count(ntb); pidx++)
678 if (lport <= ntb_peer_port_number(ntb, pidx))
679 return pidx;
680
681 return pidx;
682}
683
684/**
685 * ntb_peer_logical_port_number() - get the logical peer port by given index
686 * @ntb: NTB device context.
687 * @pidx: Peer port index.
688 *
689 * The Logical Port Number is defined to be a unique number for each
690 * port starting from zero through to the number of ports minus one.
691 * This is in contrast to the Port Number where each port can be assigned
692 * any unique physical number by the hardware.
693 *
694 * The logical port number is useful for calculating the resource indexes
695 * used by peers.
696 *
697 * Return: the peer's logical port number or negative value indicating an error
698 */
699static inline int ntb_peer_logical_port_number(struct ntb_dev *ntb, int pidx)
700{
701 if (ntb_peer_port_number(ntb, pidx) < ntb_port_number(ntb))
702 return pidx;
703 else
704 return pidx + 1;
705}
706
707/**
657 * ntb_peer_port_idx() - get the peer device port index by given port number 708 * ntb_peer_port_idx() - get the peer device port index by given port number
658 * @ntb: NTB device context. 709 * @ntb: NTB device context.
659 * @port: Peer port number. 710 * @port: Peer port number.