1219820Sjeff/* 2219820Sjeff * Copyright (c) 2004-2008 Voltaire Inc. 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#ifndef _UMAD_H 34219820Sjeff#define _UMAD_H 35219820Sjeff 36219820Sjeff#include <stdint.h> 37219820Sjeff#include <infiniband/common.h> 38219820Sjeff 39219820Sjeff#ifdef __cplusplus 40219820Sjeff# define BEGIN_C_DECLS extern "C" { 41219820Sjeff# define END_C_DECLS } 42219820Sjeff#else /* !__cplusplus */ 43219820Sjeff# define BEGIN_C_DECLS 44219820Sjeff# define END_C_DECLS 45219820Sjeff#endif /* __cplusplus */ 46219820Sjeff 47219820SjeffBEGIN_C_DECLS 48219820Sjeff 49219820Sjeff#define UMAD_MAX_DEVICES 20 50219820Sjeff#define UMAD_ANY_PORT 0 51219820Sjeff 52219820Sjefftypedef struct ib_mad_addr { 53219820Sjeff uint32_t qpn; 54219820Sjeff uint32_t qkey; 55219820Sjeff uint16_t lid; 56219820Sjeff uint8_t sl; 57219820Sjeff uint8_t path_bits; 58219820Sjeff uint8_t grh_present; 59219820Sjeff uint8_t gid_index; 60219820Sjeff uint8_t hop_limit; 61219820Sjeff uint8_t traffic_class; 62219820Sjeff uint8_t gid[16]; 63219820Sjeff uint32_t flow_label; 64219820Sjeff uint16_t pkey_index; 65219820Sjeff uint8_t reserved[6]; 66219820Sjeff} ib_mad_addr_t; 67219820Sjeff 68219820Sjefftypedef struct ib_user_mad { 69219820Sjeff uint32_t agent_id; 70219820Sjeff uint32_t status; 71219820Sjeff uint32_t timeout_ms; 72219820Sjeff uint32_t retries; 73219820Sjeff uint32_t length; 74219820Sjeff ib_mad_addr_t addr; 75219820Sjeff uint8_t data[0]; 76219820Sjeff} ib_user_mad_t; 77219820Sjeff 78219820Sjeff#define IB_UMAD_ABI_VERSION 5 79219820Sjeff#define IB_UMAD_ABI_DIR "/sys/class/infiniband_mad" 80219820Sjeff#define IB_UMAD_ABI_FILE "abi_version" 81219820Sjeff 82219820Sjeff#define IB_IOCTL_MAGIC 0x1b 83219820Sjeff 84219820Sjeff#define IB_USER_MAD_REGISTER_AGENT _IO(IB_IOCTL_MAGIC, 1) 85219820Sjeff#define IB_USER_MAD_UNREGISTER_AGENT _IO(IB_IOCTL_MAGIC, 2) 86219820Sjeff#define IB_USER_MAD_ENABLE_PKEY _IO(IB_IOCTL_MAGIC, 3) 87219820Sjeff 88219820Sjeff#define UMAD_CA_NAME_LEN 20 89219820Sjeff#define UMAD_CA_MAX_PORTS 10 /* 0 - 9 */ 90219820Sjeff#define UMAD_CA_MAX_AGENTS 32 91219820Sjeff 92219820Sjeff#define SYS_INFINIBAND "/sys/class/infiniband" 93219820Sjeff 94219820Sjeff#define SYS_INFINIBAND_MAD "/sys/class/infiniband_mad" 95219820Sjeff#define SYS_IB_MAD_PORT "port" 96219820Sjeff#define SYS_IB_MAD_DEV "ibdev" 97219820Sjeff 98219820Sjeff#define UMAD_MAX_PORTS 64 99219820Sjeff 100219820Sjeff#define UMAD_DEV_DIR "/dev" 101219820Sjeff 102219820Sjeff#define SYS_CA_PORTS_DIR "ports" 103219820Sjeff 104219820Sjeff#define SYS_NODE_TYPE "node_type" 105219820Sjeff#define SYS_CA_FW_VERS "fw_ver" 106219820Sjeff#define SYS_CA_HW_VERS "hw_rev" 107219820Sjeff#define SYS_CA_TYPE "hca_type" 108219820Sjeff#define SYS_CA_NODE_GUID "node_guid" 109219820Sjeff#define SYS_CA_SYS_GUID "sys_image_guid" 110219820Sjeff 111219820Sjeff#define SYS_PORT_LMC "lid_mask_count" 112219820Sjeff#define SYS_PORT_SMLID "sm_lid" 113219820Sjeff#define SYS_PORT_SMSL "sm_sl" 114219820Sjeff#define SYS_PORT_LID "lid" 115219820Sjeff#define SYS_PORT_STATE "state" 116219820Sjeff#define SYS_PORT_PHY_STATE "phys_state" 117219820Sjeff#define SYS_PORT_CAPMASK "cap_mask" 118219820Sjeff#define SYS_PORT_RATE "rate" 119219820Sjeff#define SYS_PORT_GUID "port_guid" 120219820Sjeff#define SYS_PORT_GID "gids/0" 121219820Sjeff 122219820Sjefftypedef struct umad_port { 123219820Sjeff char ca_name[UMAD_CA_NAME_LEN]; 124219820Sjeff int portnum; 125219820Sjeff unsigned base_lid; 126219820Sjeff unsigned lmc; 127219820Sjeff unsigned sm_lid; 128219820Sjeff unsigned sm_sl; 129219820Sjeff unsigned state; 130219820Sjeff unsigned phys_state; 131219820Sjeff unsigned rate; 132219820Sjeff uint64_t capmask; 133219820Sjeff uint64_t gid_prefix; 134219820Sjeff uint64_t port_guid; 135219820Sjeff unsigned pkeys_size; 136219820Sjeff uint16_t *pkeys; 137219820Sjeff} umad_port_t; 138219820Sjeff 139219820Sjefftypedef struct umad_ca { 140219820Sjeff char ca_name[UMAD_CA_NAME_LEN]; 141219820Sjeff unsigned node_type; 142219820Sjeff int numports; 143219820Sjeff char fw_ver[20]; 144219820Sjeff char ca_type[40]; 145219820Sjeff char hw_ver[20]; 146219820Sjeff uint64_t node_guid; 147219820Sjeff uint64_t system_guid; 148219820Sjeff umad_port_t *ports[UMAD_CA_MAX_PORTS]; 149219820Sjeff} umad_ca_t; 150219820Sjeff 151219820Sjeffint umad_init(void); 152219820Sjeffint umad_done(void); 153219820Sjeff 154219820Sjeffint umad_get_cas_names(char cas[][UMAD_CA_NAME_LEN], int max); 155219820Sjeffint umad_get_ca_portguids(char *ca_name, uint64_t *portguids, int max); 156219820Sjeff 157219820Sjeffint umad_get_ca(char *ca_name, umad_ca_t *ca); 158219820Sjeffint umad_release_ca(umad_ca_t *ca); 159219820Sjeffint umad_get_port(char *ca_name, int portnum, umad_port_t *port); 160219820Sjeffint umad_release_port(umad_port_t *port); 161219820Sjeff 162219820Sjeffint umad_get_issm_path(char *ca_name, int portnum, char path[], int max); 163219820Sjeff 164219820Sjeffint umad_open_port(char *ca_name, int portnum); 165219820Sjeffint umad_close_port(int portid); 166219820Sjeff 167219820Sjeffvoid * umad_get_mad(void *umad); 168219820Sjeffsize_t umad_size(void); 169219820Sjeffint umad_status(void *umad); 170219820Sjeff 171219820Sjeffib_mad_addr_t *umad_get_mad_addr(void *umad); 172219820Sjeffint umad_set_grh_net(void *umad, void *mad_addr); 173219820Sjeffint umad_set_grh(void *umad, void *mad_addr); 174219820Sjeffint umad_set_addr_net(void *umad, int dlid, int dqp, int sl, int qkey); 175219820Sjeffint umad_set_addr(void *umad, int dlid, int dqp, int sl, int qkey); 176219820Sjeffint umad_set_pkey(void *umad, int pkey_index); 177219820Sjeffint umad_get_pkey(void *umad); 178219820Sjeff 179219820Sjeffint umad_send(int portid, int agentid, void *umad, int length, 180219820Sjeff int timeout_ms, int retries); 181219820Sjeffint umad_recv(int portid, void *umad, int *length, int timeout_ms); 182219820Sjeffint umad_poll(int portid, int timeout_ms); 183219820Sjeffint umad_get_fd(int portid); 184219820Sjeff 185219820Sjeffint umad_register(int portid, int mgmt_class, int mgmt_version, 186219820Sjeff uint8_t rmpp_version, long method_mask[16/sizeof(long)]); 187219820Sjeffint umad_register_oui(int portid, int mgmt_class, uint8_t rmpp_version, 188219820Sjeff uint8_t oui[3], long method_mask[16/sizeof(long)]); 189219820Sjeffint umad_unregister(int portid, int agentid); 190219820Sjeff 191219820Sjeffint umad_debug(int level); 192219820Sjeffvoid umad_addr_dump(ib_mad_addr_t *addr); 193219820Sjeffvoid umad_dump(void *umad); 194219820Sjeff 195219820Sjeff#include <stdlib.h> 196219820Sjeff 197219820Sjeffstatic inline void * 198219820Sjeffumad_alloc(int num, size_t size) /* alloc array of umad buffers */ 199219820Sjeff{ 200219820Sjeff return calloc(num, size); 201219820Sjeff} 202219820Sjeff 203219820Sjeffstatic inline void 204219820Sjeffumad_free(void *umad) 205219820Sjeff{ 206219820Sjeff free(umad); 207219820Sjeff} 208219820Sjeff 209219820SjeffEND_C_DECLS 210219820Sjeff 211219820Sjeff#endif /* _UMAD_H */ 212