libibverbs: Update examples
PATCH 4/4 libibverbs: Update examples
Since RDMAoE requires usage of GRH, update ibv_*_pinpong examples to accept GIDs. GIDs are given as an index to the local port's table and are exchanged between the client and the server through the socket connection.
Signed-off-by Eli Cohen <eli-VPRAkNaXOzVS1MOuV/[email protected]>
--- examples/devinfo.c | 14 ++++++++ examples/pingpong.c | 31 ++++++++++++++++++ examples/pingpong.h | 4 ++ examples/rc_pingpong.c | 79 +++++++++++++++++++++++++++++++++++----------- examples/srq_pingpong.c | 72 ++++++++++++++++++++++++++++++++---------- examples/uc_pingpong.c | 70 ++++++++++++++++++++++++++++++++--------- examples/ud_pingpong.c | 69 ++++++++++++++++++++++++++++++----------- 7 files changed, 269 insertions(+), 70 deletions(-)
examples/devinfo.c +14 -0
@@ -184,6 +184,19 @@ static int print_all_port_gids(struct ibv_context *ctx, uint8_t port_num, int tbreturn rc; } +static const char *link_layer_str (uint8_t link_layer) +{ +switch (link_layer) { +case IBV_LINK_LAYER_UNSPECIFIED : +case IBV_LINK_LAYER_INFINIBAND : +return "IB" ; +case IBV_LINK_LAYER_ETHERNET : +return "Ethernet" ; +default : +return "Unknown" ; + } +} +static int print_hca_cap (struct ibv_device *ib_dev,uint8_t ib_port) {struct ibv_context *ctx;
@@ -284,6 +297,7 @@ static int print_hca_cap(struct ibv_device *ib_dev, uint8_t ib_port)printf ("\t\t\tsm_lid:\t\t\t%d\n" , port_attr.sm_lid);printf ("\t\t\tport_lid:\t\t%d\n" , port_attr.lid);printf ("\t\t\tport_lmc:\t\t0x%02x\n" , port_attr.lmc); +printf ("\t\t\tlink_layer:\t\t%s\n" ,link_layer_str (port_attr.link_layer));if (verbose) {printf ("\t\t\tmax_msg_sz:\t\t0x%x\n" , port_attr.max_msg_sz);
examples/pingpong.c +31 -0
@@ -31,6 +31,10 @@*/ #include "pingpong.h" +#include <arpa/inet.h> +#include <stdlib.h> +#include <stdio.h> +#include <string.h> enum ibv_mtu pp_mtu_to_enum (int mtu) {
@@ -53,3 +57,30 @@ uint16_t pp_get_local_lid(struct ibv_context *context, int port)return attr.lid; } + +int pp_get_port_info (struct ibv_context *context,int port, +struct ibv_port_attr *attr) +{ +return ibv_query_port (context, port, attr); +} + +void wire_gid_to_gid (const char *wgid,union ibv_gid *gid) +{ +char tmp[9 ]; +uint32_t v32; +int i; + +for (tmp[8 ] =0 , i =0 ; i <4 ; ++i) { +memcpy (tmp, wgid + i *8 ,8 ); +sscanf (tmp,"%x" , &v32); + *(uint32_t *)(&gid->raw[i *4 ]) =ntohl (v32); + } +} + +void gid_to_wire_gid (const union ibv_gid *gid,char wgid[]) +{ +int i; + +for (i =0 ; i <4 ; ++i) +sprintf (&wgid[i *8 ],"%08x" ,htonl (*(uint32_t *)(gid->raw + i *4 ))); +}
examples/pingpong.h +4 -0
@@ -37,5 +37,9 @@enum ibv_mtu pp_mtu_to_enum (int mtu);uint16_t pp_get_local_lid (struct ibv_context *context,int port); +int pp_get_port_info (struct ibv_context *context,int port, +struct ibv_port_attr *attr); +void wire_gid_to_gid (const char *wgid,union ibv_gid *gid); +void gid_to_wire_gid (const union ibv_gid *gid,char wgid[]);#endif /* IBV_PINGPONG_H */
examples/rc_pingpong.c +60 -19
209 lines not on this page · raw message
examples/srq_pingpong.c +55 -17
188 lines not on this page · raw message
examples/uc_pingpong.c +54 -16
179 lines not on this page · raw message
examples/ud_pingpong.c +51 -18
180 lines not on this page · raw message
Signature · 6 lines
1.6.6 -- To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html