solaris_compatibility.c revision 4833
/*
*
* This software is available to you under a choice of one of two
* licenses. You may choose to be licensed under the terms of the GNU
* General Public License (GPL) Version 2, available from the file
* COPYING in the main directory of this source tree, or the
* OpenIB.org BSD license below:
*
* Redistribution and use in source and binary forms, with or
* without modification, are permitted provided that the following
* conditions are met:
*
* - Redistributions of source code must retain the above
* copyright notice, this list of conditions and the following
* disclaimer.
*
* - Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* provided with the distribution.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#if HAVE_CONFIG_H
#include <config.h>
#endif /* HAVE_CONFIG_H */
/*
* OFED Solaris wrapper
*/
#include <stdarg.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/processor.h>
#include <stdio.h>
#include <stdlib.h>
#include <strings.h>
#include <alloca.h>
#include "../include/infiniband/arch.h"
#include "../include/infiniband/verbs.h"
#include "../include/infiniband/kern-abi.h"
#include "../include/infiniband/driver.h"
#include <errno.h>
#include <pthread.h>
#include <kstat.h>
#define min(a, b) ((a) < (b) ? (a) : (b))
/*
* duplicate ABI definitions for HCAs as the HCA abi headers are not
* installed in proto.
*/
/*
* Some useful definitions.
*/
#define HW_DRIVER_MAX_NAME_LEN 20
#define UVERBS_KERNEL_SYSFS_NAME_BASE "uverbs"
#define UMAD_KERNEL_SYSFS_NAME_BASE "umad"
#define IB_HCA_DEVPATH_PREFIX "/dev/infiniband/hca"
#define IB_OFS_DEVPATH_PREFIX "/dev/infiniband/ofs"
#define IB_HCA_DEVPATH_SZ 64
#define MAX_OFS_DEVPATH_LEN 64
/*
* sol_uverbs_drv_status is the status of what libibverbs knows
* about the status of sol_uverbs driver.
*/
#define SOL_UVERBS_DRV_STATUS_UNKNOWN 0x0
#define SOL_UVERBS_DRV_STATUS_LOADED 0x1
#define SOL_UVERBS_DRV_STATUS_UNLOADED 0x02
static int sol_uverbs_drv_status = SOL_UVERBS_DRV_STATUS_UNKNOWN;
static int sol_uverbs_minor_dev = -1;
/*
* Some useful definitions.
*/
#define SIZEOF_UVERBS_INFO (sizeof (sol_uverbs_info_t))
#define SIZEOF_HCA_INFO (sizeof (sol_uverbs_hca_info_t))
#define UVERBS_INFO(x) ((sol_uverbs_info_t *)x)
/*
* check_path() prefixs
*/
typedef enum cp_prefix_e {
CP_SOL_UVERBS = 1,
CP_DEVICE = 2,
CP_D = 3,
CP_GIDS = 4,
CP_PKEYS = 5,
CP_PORTS = 6,
CP_UMAD = 7,
CP_SLASH = 8,
CP_SYS = 9,
CP_CLASS = 10,
CP_INFINIBAND_VERBS = 11,
CP_INFINIBAND = 12,
CP_INFINIBAND_MAD = 13,
CP_MISC = 14,
CP_RDMA_CM = 15
} cp_prefix_t;
/*
* Some temporary cache code, until things are cleaned up as part of DR
* work. This will speed up the sysfs emulation.
*/
typedef struct ibdev_cache_info_s {
char ibd_hca_path[IB_HCA_DEVPATH_SZ];
char ibd_node_guid_str[20];
char ibd_node_guid_external_str[20];
char ibd_sys_image_guid[20];
char ibd_fw_ver[16];
char ibd_name[IBDEV_NAME_SZ];
char ibd_boardid_string[PSID_STR_SZ];
char ibd_devid_string[DEVID_STR_SZ];
/* IB device info cache */
static int uverbs_abi_version = -1;
typedef struct umad_cache_info_s {
int umc_port;
char umc_ib_dev[16];
static int umad_abi_version = -1;
static int umad_cache_cnt = 0;
struct ibv_device_attr *device_attr);
void
solaris_init(void)
{
else
}
}
void
solaris_fini(void)
{
(void) kstat_close(kc);
}
/*
* Given a device name of the form <driver-prefix><instance>,
* get the device number. Device name is of the form
* for example:- mlx4_0, mlx4_2 etc. Function will return the device instance
* extracted from the name.
* for example:- mlx4_0 will return 0 and mlx4_2 will return 2.
*/
static int
get_device_num(const char *device_name)
{
const char *temp;
const char *end;
const char *start = device_name;
int len;
int devnum;
if (!start)
return (-1);
/* Null body */;
/*
* Check if the device number is invalid.
*/
return (-1);
return (-1);
return (devnum);
}
/*
* For usages where ibdev cache needs to be read based on the IB device
* name instead of uverbs device name a simple compare against the cache
* entries is used to retrieve the corresponding ibdev cache entry.
*/
static ibdev_cache_info_t *
ibdev_cache_read_by_devname(const char *devname)
{
int idx;
if (!devname)
return (NULL);
break;
}
/*
* If we failed to find an entry return NULL.
*/
return (cache);
}
/*
* Helper function to update the ibdev cache entries with the values obtained
* from the uverbs HCA info ioctl.
*/
static int
{
char *buf;
/*
* using the first sol_uverbs minor node that can be opened to get
* all the HCA information
*/
return (-1);
}
if (!buf) {
return (-1);
}
goto error_exit1;
}
"IB_USER_VERBS_SOLARIS_ABI_VERSION : %d\n",
goto error_exit1;
}
goto error_exit1;
}
if (uverbs_abi_version == -1)
/*
* Update the cache.
*/
(unsigned)(guid >> 0) & 0xffff);
(unsigned)(guid >> 0) & 0xffff);
(unsigned)(guid >> 0) & 0xffff);
"%s/%s%d", IB_HCA_DEVPATH_PREFIX,
}
return (0);
return (-1);
}
static int
{
return (1);
}
return (0);
}
static int
{
int save_errno = 0;
minor);
break;
save_errno = errno;
}
if (! save_errno)
save_errno = errno;
return (-1);
}
bufsize = sizeof (sol_umad_ioctl_info_t) +
(sizeof (sol_umad_ioctl_port_info_t) * MAX_PORTS);
goto error_exit;
}
if (umad_infop->umad_solaris_abi_version !=
"IB_USER_MAD_SOLARIS_ABI_VERSION : %d\n",
goto error_exit;
}
/*
* set port_cnt to the number of total ports for all HCAs returned
*/
if (umad_abi_version == -1)
for (i = 0; i < port_cnt; i++, port_infop++) {
goto error_exit;
}
}
return (0);
return (-1);
}
void
initialize(void)
{
/*
* find the first sol_uverbs minor node that can be opened successfully
* and set sol_uverbs_mino_dev to that minor no.
*/
minor);
continue;
} else {
break;
}
}
/*
* All minor nodes failed to open, so set sol_uverbs_drv_status to
* SOL_UVERBS_DRV_STATUS_UNLOADED to reflect that
*/
return;
}
memset(&umad_dev_cache, 0,
(sizeof (umad_cache_info_t) * MAX_PORTS));
}
/*
* Some sysfs emulation software
*/
/*
* Extract the HCA dev name from the path and remove it from the path.
* Given a path extract the HCA dev name of the form <dev-prefix><dev-instance>
* During parsing the device instance number is validated to make sure it is
* within MAX_HCAS limit, the routine also skips over the duplicate slashes.
*/
static int
{
int pos = 0;
int len;
pos++;
return (0);
if (get_device_num(device_name) < 0)
return (0);
pos++;
return (1);
}
/*
* Check whether a path starts with prefix, and if it does, remove it
* from the string. The prefix can also contain one %d scan argument.
*/
static int
{
switch (prefix) {
case CP_SOL_UVERBS:
&pos);
break;
case CP_DEVICE:
break;
case CP_D:
break;
case CP_GIDS:
break;
case CP_PKEYS:
break;
case CP_PORTS:
break;
case CP_UMAD:
break;
case CP_SLASH:
break;
case CP_SYS:
break;
case CP_CLASS:
break;
case CP_INFINIBAND_VERBS:
break;
case CP_INFINIBAND:
break;
case CP_INFINIBAND_MAD:
break;
case CP_MISC:
break;
case CP_RDMA_CM:
break;
default:
/* Unkown prefix */
return (0);
}
/* Some requests have several consecutive slashes. */
pos ++;
return (1);
}
return (0);
}
static ibdev_cache_info_t *
get_device_info(const char *devname)
{
if (pthread_mutex_lock(&ibdev_cache_mutex) != 0) {
return (NULL);
}
if (ibdev_cache_initialized == B_FALSE) {
if (ibdev_cache_init() != 0) {
(void) pthread_mutex_unlock(&ibdev_cache_mutex);
return (NULL);
}
}
(void) pthread_mutex_unlock(&ibdev_cache_mutex);
return (info);
}
/*
* If the address of a gid pointer is passed for "gid_table", the memory
* will be allocated and the ports gid table and returned as well. The caller
* must free this memory on successful completion. If the address of a
* pkey pointer is passed for "pkey_table", the memory will be allocated
* and the ports pkey table returned as well. The caller must free this
* memory on successful completion.
*/
static int
{
struct ibv_context ctx;
if (!dev_list) {
goto error_exit1;
}
break;
}
}
if (i == num_dev) {
goto error_exit2;
}
goto error_exit2;
goto error_exit3;
}
if (gid_table) {
if (!gids)
goto error_exit3;
/*
* set high bit of port_num to get all gids in one shot.
*/
port_num |= 0x80;
gids);
if (rv != 0)
goto error_exit4;
}
if (pkey_table) {
*pkey_table = NULL;
if (!pkeys)
goto error_exit4;
/*
* set high bit of port_num to get all pkeys in one shot.
*/
port_num |= 0x80;
pkeys);
if (rv != 0)
goto error_exit5;
*pkey_table = pkeys;
}
ret = 0;
/*
* clean up and Return
*/
if (pkeys)
if (gids)
if (root_dev_list)
return (ret);
}
/*
* In Solaris environments, the underlying hardware driver is opened to
* perform the memory mapping operations of kernel allocated memory
* into the users address space.
*/
int
ibv_open_mmap_driver(char *dev_name)
{
int fd;
#ifndef _LP64
int tmpfd;
#endif
int indx;
/*
* Map the user verbs device (uverbs) to the associated
* hca device. ibdev_cache is indexed by uverbs device minor number
* so extracting the index here to refer to the ibdev_cache value,
*/
NULL, 0);
goto err_dev;
}
goto err_dev;
}
if (fd < 0) {
goto err_dev;
}
#ifndef _LP64
/*
* libc can't handle fd's greater than 255, in order to
* ensure that these values remain available make fd > 255.
* Note: not needed for LP64
*/
if (tmpfd >= 0) {
}
#endif /* _LP64 */
goto err_close;
}
return (fd);
return (-1);
}
static int
{
unsigned int device_num;
int len = -1;
if (pthread_mutex_lock(&ibdev_cache_mutex) != 0) {
goto exit;
}
if (ibdev_cache_initialized == B_FALSE) {
if (ibdev_cache_init() == 0)
else {
(void) pthread_mutex_unlock(&ibdev_cache_mutex);
#ifdef DEBUG
#endif
goto exit;
}
}
(void) pthread_mutex_unlock(&ibdev_cache_mutex);
if (device_num >= MAX_HCAS) {
goto exit;
}
goto exit;
/*
* Under Linux, this is a link to the PCI device entry
*/
}
}
if (uverbs_abi_version == -1) {
goto exit;
}
} else {
}
exit:
return (len);
}
static int
{
int len = -1;
unsigned int port_num;
unsigned int gid_num;
unsigned int pkey_num;
struct ibv_port_attr port_attr;
float rate;
goto exit;
goto exit;
"%04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x",
(unsigned)(subnet_prefix >> 0) & 0xffff,
(unsigned)(interface_id >> 0) & 0xffff);
}
if (gids)
goto exit;
if (pkeys)
} else {
goto exit;
case IBV_PORT_NOP:
break;
case IBV_PORT_DOWN:
break;
case IBV_PORT_INIT:
break;
case IBV_PORT_ARMED:
break;
case IBV_PORT_ACTIVE:
break;
case IBV_PORT_ACTIVE_DEFER:
"%d: ACTIVE_DEFER",
break;
default:
break;
}
switch (port_attr.phys_state) {
case 1:
break;
case 2:
break;
case 3:
break;
case 4:
"%d: PortConfigurationTraining",
break;
case 5:
break;
case 6:
"%d: LinkErrorRecovery",
break;
case 7:
"%d: Phy Test",
break;
default:
break;
}
/* rate = speed * width */
switch (port_attr.active_speed) {
case 1:
rate = 2.5;
break;
case 2:
rate = 5;
break;
case 4:
/* FALLTHROUGH */
case 8:
rate = 10;
break;
case 16:
rate = 14.0625;
break;
case 32:
rate = 25.78125;
break;
default:
rate = 0;
}
switch (port_attr.active_width) {
case 1:
break;
case 2:
break;
case 4:
break;
case 8:
break;
default:
rate = 0;
}
switch (port_attr.link_layer) {
break;
case IBV_LINK_LAYER_ETHERNET:
len =
break;
default:
}
}
}
exit:
return (len);
}
static int
{
int len = -1;
char dev_name[MAXNAMELEN];
goto exit;
} else {
goto exit;
}
}
exit:
return (len);
}
static int
{
int len = -1;
unsigned int dev_num;
if (pthread_mutex_lock(&umad_cache_mutex) != 0) {
goto exit;
}
if (umad_cache_initialized == B_FALSE) {
if (umad_cache_init() == 0)
else {
(void) pthread_mutex_unlock(&umad_cache_mutex);
#ifdef DEBUG
#endif
goto exit;
}
}
(void) pthread_mutex_unlock(&umad_cache_mutex);
goto exit;
}
goto exit;
}
size) + 1;
}
if (umad_abi_version == -1) {
goto exit;
}
len =
}
exit:
return (len);
}
/*
* Return -1 on error, or the length of the data (buf) on success.
*/
int
{
int len = -1;
if (!initialized) {
goto exit;
}
if (!initialized)
/*
* There was a problem in initialize()
*/
goto exit;
}
goto exit;
goto exit;
goto exit;
}
}
}
exit:
return (len);
}
int
{
if (ncpus <= 0)
return (0);
return (-1);
for (i = 0; i < ncpus; i++) {
if (i >= ncpus)
goto err_exit;
else
continue;
}
if (i >= ncpus)
goto err_exit;
else
continue;
}
== NULL) {
if (i >= ncpus)
goto err_exit;
else
continue;
}
== NULL) {
if (i >= ncpus)
goto err_exit;
else
continue;
}
info[i].cpu_number = i;
}
return (ncpus);
return (-1);
}
int
{
/* Aggregate the value of all CPUs */
for (i = 0; i < nr_cpus; i++) {
/*
* In case of some cpu_id doesn't have kstat info.,
* skip it and continue if it isn't the last one.
*/
if (i >= nr_cpus)
return (-1);
else
continue;
}
if (i >= nr_cpus)
return (-1);
else
continue;
}
if ((knp = (kstat_named_t *)
if (i >= nr_cpus)
return (-1);
else
continue;
}
if ((knp = (kstat_named_t *)
return (-1);
else
continue;
}
if ((knp = (kstat_named_t *)
if (i >= nr_cpus)
return (-1);
else
continue;
}
if ((knp = (kstat_named_t *)
if (i >= nr_cpus)
return (-1);
else
continue;
}
if ((knp = (kstat_named_t *)
if (i >= nr_cpus)
return (-1);
else
continue;
}
}
return (0);
}
int
{
/*
* Not exported via sysfs, use ioctl.
*/
return (-1);
if (port_num & 0x80) {
start = 0;
} else {
count = 1;
}
sizeof (union ibv_gid) + sizeof (sol_uverbs_gid_t));
if (uverbs_gidp == NULL) {
return (-1);
}
#ifdef DEBUG
#endif
goto gid_error_exit;
}
#ifdef DEBUG
"IB_USER_VERBS_SOLARIS_ABI_VERSION : %d\n",
#endif
goto gid_error_exit;
}
return (0);
return (-1);
}
int
{
/*
* Not exported via sysfs, use ioctl.
*/
return (-1);
return (-1);
if (port_num & 0x80) {
start = 0;
} else {
count = 1;
}
sizeof (uint16_t) + sizeof (sol_uverbs_pkey_t));
if (uverbs_pkeyp == NULL) {
return (-1);
}
#ifdef DEBUG
#endif
goto pkey_error_exit;
}
#ifdef DEBUG
"IB_USER_VERBS_SOLARIS_ABI_VERSION : %d\n",
#endif
goto pkey_error_exit;
}
return (0);
return (-1);
}
int
{
struct ibv_query_device cmd;
struct ibv_context context;
int ret;
return (-1);
return (-1);
sizeof (cmd));
if (ret)
return (ret);
return (0);
}
int
struct ibv_port_attr *attr)
{
struct ibv_query_port cmd;
}
#endif