diff options
author | Hoang-Nam Nguyen <HNGUYEN@de.ibm.com> | 2006-04-11 20:40:26 +0000 |
---|---|---|
committer | Roland Dreier <rolandd@cisco.com> | 2006-11-09 11:36:00 -0800 |
commit | f44747dc96aba1664f5eeadc463662bd5561c85c (patch) | |
tree | 9892780e7640de007b4e760f77c00d48c1da9a34 | |
parent | a7a021117b1059ffa9c9df624e0b3f3eb37b111f (diff) | |
download | libibverbs-f44747dc96aba1664f5eeadc463662bd5561c85c.tar.gz |
Add ibv_rate_to_mult() and mult_to_ibv_rate() functions
Signed-off-by: Roland Dreier <rolandd@cisco.com>
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | include/infiniband/verbs.h | 14 | ||||
-rw-r--r-- | src/libibverbs.map | 2 | ||||
-rw-r--r-- | src/verbs.c | 32 |
4 files changed, 54 insertions, 0 deletions
@@ -1,3 +1,9 @@ +2006-04-11 Hoang-Nam Nguyen <HNGUYEN@de.ibm.com> + + * src/verbs.c (ibv_rate_to_mult, mult_to_ibv_rate): Add new + functions to convert between IB rate enums and multiples of the + base 2.5 Gb/sec rate. + 2006-04-11 Roland Dreier <rdreier@cisco.com> * include/infiniband/verbs.h: Add __attribute_const macro to diff --git a/include/infiniband/verbs.h b/include/infiniband/verbs.h index b8ff8a7..2d1801c 100644 --- a/include/infiniband/verbs.h +++ b/include/infiniband/verbs.h @@ -312,6 +312,20 @@ enum ibv_rate { IBV_RATE_120_GBPS = 10 }; +/** + * ibv_rate_to_mult - Convert the IB rate enum to a multiple of the + * base rate of 2.5 Gbit/sec. For example, IBV_RATE_5_GBPS will be + * converted to 2, since 5 Gbit/sec is 2 * 2.5 Gbit/sec. + * @rate: rate to convert. + */ +int ibv_rate_to_mult(enum ibv_rate rate) __attribute_const; + +/** + * mult_to_ibv_rate - Convert a multiple of 2.5 Gbit/sec to an IB rate enum. + * @mult: multiple to convert. + */ +enum ibv_rate mult_to_ibv_rate(int mult) __attribute_const; + struct ibv_ah_attr { struct ibv_global_route grh; uint16_t dlid; diff --git a/src/libibverbs.map b/src/libibverbs.map index 2bebc5d..807a9d6 100644 --- a/src/libibverbs.map +++ b/src/libibverbs.map @@ -67,5 +67,7 @@ IBVERBS_1.0 { ib_copy_qp_attr_from_kern; ib_copy_path_rec_from_kern; ib_copy_path_rec_to_kern; + ibv_rate_to_mult; + mult_to_ibv_rate; local: *; }; diff --git a/src/verbs.c b/src/verbs.c index 7fe15e2..0397710 100644 --- a/src/verbs.c +++ b/src/verbs.c @@ -45,6 +45,38 @@ #include "ibverbs.h" +int ibv_rate_to_mult(enum ibv_rate rate) +{ + switch (rate) { + case IBV_RATE_2_5_GBPS: return 1; + case IBV_RATE_5_GBPS: return 2; + case IBV_RATE_10_GBPS: return 4; + case IBV_RATE_20_GBPS: return 8; + case IBV_RATE_30_GBPS: return 12; + case IBV_RATE_40_GBPS: return 16; + case IBV_RATE_60_GBPS: return 24; + case IBV_RATE_80_GBPS: return 32; + case IBV_RATE_120_GBPS: return 48; + default: return -1; + } +} + +enum ibv_rate mult_to_ibv_rate(int mult) +{ + switch (mult) { + case 1: return IBV_RATE_2_5_GBPS; + case 2: return IBV_RATE_5_GBPS; + case 4: return IBV_RATE_10_GBPS; + case 8: return IBV_RATE_20_GBPS; + case 12: return IBV_RATE_30_GBPS; + case 16: return IBV_RATE_40_GBPS; + case 24: return IBV_RATE_60_GBPS; + case 32: return IBV_RATE_80_GBPS; + case 48: return IBV_RATE_120_GBPS; + default: return IBV_RATE_MAX; + } +} + int ibv_query_device(struct ibv_context *context, struct ibv_device_attr *device_attr) { |