1219820Sjeff/* 2219820Sjeff * Copyright (c) 2006 Cisco Systems. All rights reserved. 3219820Sjeff * 4219820Sjeff * This software is available to you under a choice of one of two 5219820Sjeff * licenses. You may choose to be licensed under the terms of the GNU 6219820Sjeff * General Public License (GPL) Version 2, available from the file 7219820Sjeff * COPYING in the main directory of this source tree, or the 8219820Sjeff * OpenIB.org BSD license below: 9219820Sjeff * 10219820Sjeff * Redistribution and use in source and binary forms, with or 11219820Sjeff * without modification, are permitted provided that the following 12219820Sjeff * conditions are met: 13219820Sjeff * 14219820Sjeff * - Redistributions of source code must retain the above 15219820Sjeff * copyright notice, this list of conditions and the following 16219820Sjeff * disclaimer. 17219820Sjeff * 18219820Sjeff * - Redistributions in binary form must reproduce the above 19219820Sjeff * copyright notice, this list of conditions and the following 20219820Sjeff * disclaimer in the documentation and/or other materials 21219820Sjeff * provided with the distribution. 22219820Sjeff * 23219820Sjeff * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 24219820Sjeff * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 25219820Sjeff * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 26219820Sjeff * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 27219820Sjeff * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 28219820Sjeff * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 29219820Sjeff * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 30219820Sjeff * SOFTWARE. 31219820Sjeff */ 32219820Sjeff 33219820Sjeff#include "pingpong.h" 34219820Sjeff#include <arpa/inet.h> 35219820Sjeff#include <stdlib.h> 36219820Sjeff#include <stdio.h> 37219820Sjeff#include <string.h> 38219820Sjeff 39219820Sjeffenum ibv_mtu pp_mtu_to_enum(int mtu) 40219820Sjeff{ 41219820Sjeff switch (mtu) { 42219820Sjeff case 256: return IBV_MTU_256; 43219820Sjeff case 512: return IBV_MTU_512; 44219820Sjeff case 1024: return IBV_MTU_1024; 45219820Sjeff case 2048: return IBV_MTU_2048; 46219820Sjeff case 4096: return IBV_MTU_4096; 47219820Sjeff default: return -1; 48219820Sjeff } 49219820Sjeff} 50219820Sjeff 51219820Sjeffuint16_t pp_get_local_lid(struct ibv_context *context, int port) 52219820Sjeff{ 53219820Sjeff struct ibv_port_attr attr; 54219820Sjeff 55219820Sjeff if (ibv_query_port(context, port, &attr)) 56219820Sjeff return 0; 57219820Sjeff 58219820Sjeff return attr.lid; 59219820Sjeff} 60219820Sjeff 61219820Sjeffint pp_get_port_info(struct ibv_context *context, int port, 62219820Sjeff struct ibv_port_attr *attr) 63219820Sjeff{ 64219820Sjeff return ibv_query_port(context, port, attr); 65219820Sjeff} 66219820Sjeff 67219820Sjeffvoid wire_gid_to_gid(const char *wgid, union ibv_gid *gid) 68219820Sjeff{ 69219820Sjeff char tmp[9]; 70219820Sjeff uint32_t v32; 71219820Sjeff int i; 72219820Sjeff 73219820Sjeff for (tmp[8] = 0, i = 0; i < 4; ++i) { 74219820Sjeff memcpy(tmp, wgid + i * 8, 8); 75219820Sjeff sscanf(tmp, "%x", &v32); 76219820Sjeff *(uint32_t *)(&gid->raw[i * 4]) = ntohl(v32); 77219820Sjeff } 78219820Sjeff} 79219820Sjeff 80219820Sjeffvoid gid_to_wire_gid(const union ibv_gid *gid, char wgid[]) 81219820Sjeff{ 82219820Sjeff int i; 83219820Sjeff 84219820Sjeff for (i = 0; i < 4; ++i) 85219820Sjeff sprintf(&wgid[i * 8], "%08x", htonl(*(uint32_t *)(gid->raw + i * 4))); 86219820Sjeff} 87