1aa0a1e58SJeff Roberson /* 2aa0a1e58SJeff Roberson * Copyright (c) 2006 Cisco Systems. All rights reserved. 3aa0a1e58SJeff Roberson * 4aa0a1e58SJeff Roberson * This software is available to you under a choice of one of two 5aa0a1e58SJeff Roberson * licenses. You may choose to be licensed under the terms of the GNU 6aa0a1e58SJeff Roberson * General Public License (GPL) Version 2, available from the file 7aa0a1e58SJeff Roberson * COPYING in the main directory of this source tree, or the 8aa0a1e58SJeff Roberson * OpenIB.org BSD license below: 9aa0a1e58SJeff Roberson * 10aa0a1e58SJeff Roberson * Redistribution and use in source and binary forms, with or 11aa0a1e58SJeff Roberson * without modification, are permitted provided that the following 12aa0a1e58SJeff Roberson * conditions are met: 13aa0a1e58SJeff Roberson * 14aa0a1e58SJeff Roberson * - Redistributions of source code must retain the above 15aa0a1e58SJeff Roberson * copyright notice, this list of conditions and the following 16aa0a1e58SJeff Roberson * disclaimer. 17aa0a1e58SJeff Roberson * 18aa0a1e58SJeff Roberson * - Redistributions in binary form must reproduce the above 19aa0a1e58SJeff Roberson * copyright notice, this list of conditions and the following 20aa0a1e58SJeff Roberson * disclaimer in the documentation and/or other materials 21aa0a1e58SJeff Roberson * provided with the distribution. 22aa0a1e58SJeff Roberson * 23aa0a1e58SJeff Roberson * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 24aa0a1e58SJeff Roberson * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 25aa0a1e58SJeff Roberson * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 26aa0a1e58SJeff Roberson * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 27aa0a1e58SJeff Roberson * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 28aa0a1e58SJeff Roberson * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 29aa0a1e58SJeff Roberson * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 30aa0a1e58SJeff Roberson * SOFTWARE. 31aa0a1e58SJeff Roberson */ 32aa0a1e58SJeff Roberson 33aa0a1e58SJeff Roberson #include "pingpong.h" 34*d6b92ffaSHans Petter Selasky #include <infiniband/endian.h> 35aa0a1e58SJeff Roberson #include <stdlib.h> 36aa0a1e58SJeff Roberson #include <stdio.h> 37aa0a1e58SJeff Roberson #include <string.h> 38aa0a1e58SJeff Roberson 39aa0a1e58SJeff Roberson enum ibv_mtu pp_mtu_to_enum(int mtu) 40aa0a1e58SJeff Roberson { 41aa0a1e58SJeff Roberson switch (mtu) { 42aa0a1e58SJeff Roberson case 256: return IBV_MTU_256; 43aa0a1e58SJeff Roberson case 512: return IBV_MTU_512; 44aa0a1e58SJeff Roberson case 1024: return IBV_MTU_1024; 45aa0a1e58SJeff Roberson case 2048: return IBV_MTU_2048; 46aa0a1e58SJeff Roberson case 4096: return IBV_MTU_4096; 47*d6b92ffaSHans Petter Selasky default: return 0; 48aa0a1e58SJeff Roberson } 49aa0a1e58SJeff Roberson } 50aa0a1e58SJeff Roberson 51aa0a1e58SJeff Roberson int pp_get_port_info(struct ibv_context *context, int port, 52aa0a1e58SJeff Roberson struct ibv_port_attr *attr) 53aa0a1e58SJeff Roberson { 54aa0a1e58SJeff Roberson return ibv_query_port(context, port, attr); 55aa0a1e58SJeff Roberson } 56aa0a1e58SJeff Roberson 57aa0a1e58SJeff Roberson void wire_gid_to_gid(const char *wgid, union ibv_gid *gid) 58aa0a1e58SJeff Roberson { 59aa0a1e58SJeff Roberson char tmp[9]; 60*d6b92ffaSHans Petter Selasky __be32 v32; 61aa0a1e58SJeff Roberson int i; 62*d6b92ffaSHans Petter Selasky uint32_t tmp_gid[4]; 63aa0a1e58SJeff Roberson 64aa0a1e58SJeff Roberson for (tmp[8] = 0, i = 0; i < 4; ++i) { 65aa0a1e58SJeff Roberson memcpy(tmp, wgid + i * 8, 8); 66aa0a1e58SJeff Roberson sscanf(tmp, "%x", &v32); 67*d6b92ffaSHans Petter Selasky tmp_gid[i] = be32toh(v32); 68aa0a1e58SJeff Roberson } 69*d6b92ffaSHans Petter Selasky memcpy(gid, tmp_gid, sizeof(*gid)); 70aa0a1e58SJeff Roberson } 71aa0a1e58SJeff Roberson 72aa0a1e58SJeff Roberson void gid_to_wire_gid(const union ibv_gid *gid, char wgid[]) 73aa0a1e58SJeff Roberson { 74*d6b92ffaSHans Petter Selasky uint32_t tmp_gid[4]; 75aa0a1e58SJeff Roberson int i; 76aa0a1e58SJeff Roberson 77*d6b92ffaSHans Petter Selasky memcpy(tmp_gid, gid, sizeof(tmp_gid)); 78aa0a1e58SJeff Roberson for (i = 0; i < 4; ++i) 79*d6b92ffaSHans Petter Selasky sprintf(&wgid[i * 8], "%08x", htobe32(tmp_gid[i])); 80aa0a1e58SJeff Roberson } 81