solaris_compatibility.c revision 1998
/*
*
* 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/MELLANOX.h"
#include <errno.h>
#include <pthread.h>
#include <kstat.h>
#define min(a, b) ((a) < (b) ? (a) : (b))
/*
* The followings will be removed when changes in hermon_ioctl.h
* are delivered through ON.
*/
#ifndef HERMON_GET_HWINFO_IOCTL_SUP
#pragma pack(1)
/* Structure used for getting HW info */
typedef struct hermon_hw_info_ioctl_s {
/* 64 byte boundary */
char af_hwpn[64];
/* 64 byte boundary */
char af_psid[16];
/* 64 byte boundary */
#pragma pack()
#endif
/*
* duplicate ABI definitions for HCAs as the HCA abi headers are not
* installed in proto.
*/
#define MLX4 0
#define MAX_HCAS 260
#define MAX_HCA_PORTS 16
#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 CONNECTX_NAME "mlx4_"
#define MELLANOX_VENDOR_ID 0x15b3
#define PCI_DEVICE_ID_MELLANOX_HERMON_SDR 0x6340
#define PCI_DEVICE_ID_MELLANOX_HERMON_DDR 0x634a
#define PCI_DEVICE_ID_MELLANOX_HERMON_QDR 0x6354
#define PCI_DEVICE_ID_MELLANOX_HERMON_DDR_PCIE2 0x6732
#define PCI_DEVICE_ID_MELLANOX_HERMON_QDR_PCIE2 0x673c
#define INFINIHOST_DEVICE_ID_2 0x5a45
#define INFINIHOST_DEVICE_ID_4 0x6279
/*
* 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;
/*
* 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_MLX4 = 6,
CP_PORTS = 7,
CP_UMAD = 8,
CP_SLASH = 9,
CP_SYS = 10,
CP_CLASS = 11,
CP_INFINIBAND_VERBS = 12,
CP_INFINIBAND = 13,
CP_INFINIBAND_MAD = 14,
CP_MISC = 15,
CP_RDMA_CM = 16
} 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_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[8];
int ibd_boardid_index;
/* hermon - hence 2 */
typedef struct uverbs_cache_info_s {
int uvc_hca_instance;
char uvc_ibdev_name[8];
char uvc_ibdev_hca_path[MAXPATHLEN];
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;
static int ibdev_cache_cnt = 0;
static int uverbs_cache_cnt = 0;
void
solaris_init(void)
{
else
}
}
void
solaris_fini(void)
{
(void) kstat_close(kc);
}
static int
{
return (1);
}
return (0);
}
static int
{
return (1);
}
sizeof (ibdev_cache_info_t));
} else {
return (1);
}
return (0);
}
static int
{
return (1);
}
sizeof (uverbs_cache_info_t));
return (0);
}
static int
{
struct ibv_device_attr device_attr;
const char *p, *ibdev;
if (!dev_list) {
goto error_exit1;
}
*dev_list);
goto error_exit2;
}
goto error_exit3;
}
(unsigned)(guid >> 0) & 0xffff);
(unsigned)(guid >> 0) & 0xffff);
(unsigned)(guid >> 0) & 0xffff);
} else {
goto error_exit3;
}
dev_num);
goto error_exit3;
}
}
ret = 0;
/* clean up and Return */
if (ctx)
if (root_dev_list)
return (ret);
}
static int
{
char uverbs_devpath[MAXPATHLEN];
#ifndef IB_USER_VERBS_V2_IN_V1
#else
#endif
char *buf;
/*
* using the first sol_uverbs minor node that can be opened to get
* all the HCA information
*/
goto error_exit1;
}
#ifndef IB_USER_VERBS_V2_IN_V1
#else
bufsize = sizeof (sol_uverbs_info_v2_t) +
sizeof (sol_uverbs_hca_info_v2_t) * MAX_HCAS;
#endif
#ifndef IB_USER_VERBS_V2_IN_V1
#else
#endif
goto error_exit2;
}
"IB_USER_VERBS_SOLARIS_ABI_VERSION : %d\n",
goto error_exit2;
}
if (uverbs_abi_version == -1)
sizeof (info.uvc_ibdev_hca_path),
"%s/%s%d", IB_HCA_DEVPATH_PREFIX,
else {
goto error_exit2;
}
"cache\n", dev_num);
goto error_exit2;
}
}
return (1);
return (0);
}
static int
{
int save_errno = 0;
minor);
break;
save_errno = errno;
}
if (! save_errno)
save_errno = errno;
return (0);
}
bufsize = sizeof (sol_umad_ioctl_info_t) +
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 (1);
return (0);
}
void
initialize(void)
{
char uverbs_devpath[MAXPATHLEN];
/*
* 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,
}
/*
* Some sysfs emulation software
*/
/*
* 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_MLX4:
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)
{
const char *p = devname;
int dev_num;
if (pthread_mutex_lock(&ibdev_cache_mutex) != 0) {
return (NULL);
}
if (!ibdev_cache_initialized) {
if (ibdev_cache_init()) {
(void) pthread_mutex_unlock(&ibdev_cache_mutex);
return (NULL);
} else {
}
}
(void) pthread_mutex_unlock(&ibdev_cache_mutex);
p = p+(strlen("mlx4_"));
} else {
"device: %s\n", p);
return (NULL);
}
return (NULL);
}
else
} else {
"device: %s\n", devname);
}
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
{
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 (ctx)
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 uverbs_indx;
/*
* Map the user verbs device (uverbs) to the associated
* hca device.
*/
NULL, 0);
if (uverbs_indx >= MAX_HCAS) {
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(&uverbs_cache_mutex) != 0) {
goto exit;
}
if (!uverbs_cache_initialized) {
if (uverbs_cache_init())
else {
(void) pthread_mutex_unlock(&uverbs_cache_mutex);
#ifdef DEBUG
#endif
goto exit;
}
}
(void) pthread_mutex_unlock(&uverbs_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:
rate = 10;
break;
default:
rate = 0;
}
switch (port_attr.active_width) {
case 1:
break;
case 2:
break;
case 4:
break;
case 8:
break;
default:
rate = 0;
}
}
}
exit:
return (len);
}
/*
* This function passes the HW PSID / HWPN string obtained from
* driver HERMON_IOCTL_GET_HWINFO IOCTL. The memory for "hca_hwpsid"
* & "hca_hwpn" argument has to be passed by the caller and has to
* be at least 16 bytes & 64 bytes in size.
*/
static int
char *hca_hwpn)
{
int rc;
&hermon_hw_info)) != 0)
return (rc);
} else {
"device: %s\n", ibd_name);
return (1);
}
return (0);
}
/*
* This function passes the HW Part number string obtained from driver
* IOCTL. The memory for "hca_hwpn" argument has to be passed by the
* caller and has to be at least 64 bytes in size.
*/
static int
{
int rc;
&hermon_flash_info)) != 0)
return (rc);
} else {
"device: %s\n", ibd_name);
return (1);
}
return (0);
}
static void
{
int i;
int fd;
char hca_hwpsid[16];
char hca_hwpn[64];
char *pn_psidp;
if (pthread_mutex_lock(&uverbs_cache_mutex) != 0) {
"uverbs_cache_mutex %s\n",
goto boardid_err;
}
if (!uverbs_cache_initialized) {
if (uverbs_cache_init())
else {
(void) pthread_mutex_unlock(&uverbs_cache_mutex);
#ifdef DEBUG
#endif
goto boardid_err;
}
}
(void) pthread_mutex_unlock(&uverbs_cache_mutex);
for (i = 0; i < MAX_HCAS; i++) {
if (uverbs_dev_cache[i].uvc_valid &&
break;
}
}
if (i == MAX_HCAS) {
goto boardid_err;
}
if (fd < 0) {
goto boardid_err;
}
hca_hwpsid, hca_hwpn)) {
goto boardid_err;
} else {
if (hca_hwpn[0]) {
*pn_psidp = '\0';
}
}
} else {
if (hca_hwpsid[0]) {
*pn_psidp = '\0';
psid_valid = B_TRUE;
} else if (hca_hwpn[0]) {
*pn_psidp = '\0';
}
}
goto boardid_err;
for (i = 0; i < MLX_MAX_ID; i++) {
/*
* Find PSID number, set the boardid_index,
* Skip index 0, as it is for failure "unknown"
* case
*/
if ((psid_valid == B_TRUE &&
(const char *)hca_hwpsid,
(const char *)hca_hwpn,
/* Set boardid_index */
ibd_info->ibd_boardid_index = i;
return;
}
}
/* Failure case, default to "unknown" */
}
static int
{
int len = -1;
unsigned int device_num;
char dev_name[10];
} else {
goto exit;
}
} else {
goto exit;
else
if (info->ibd_boardid_index >= 0) {
} else {
"unknown");
}
}
}
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) {
if (umad_cache_init())
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
{
char uverbs_devpath[MAXPATHLEN];
int uverbs_fd;
/*
* Not exported via sysfs, use ioctl.
*/
return (-1);
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
{
char uverbs_devpath[MAXPATHLEN];
int uverbs_fd;
/*
* 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);
}
#endif