components/open-fabrics/infiniband-diags/solaris_set_nodedesc.c
author shruthi.rr@oracle.com <shruthi.rr@oracle.com>
Mon, 13 Mar 2017 22:18:24 -0700
branchs11u3-sru
changeset 7743 9d9ea22360ed
parent 6322 c8b38df3868d
permissions -rw-r--r--
25109189 solaris_set_nodedesc doesn't handle node description >= 64 chars
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
369
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
     1
/*
7743
9d9ea22360ed 25109189 solaris_set_nodedesc doesn't handle node description >= 64 chars
shruthi.rr@oracle.com <shruthi.rr@oracle.com>
parents: 6322
diff changeset
     2
 * Copyright (c) 2010, 2017, Oracle and/or its affiliates. All rights reserved.
369
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
     3
 *
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
     4
 * This software is available to you under a choice of one of two
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
     5
 * licenses.  You may choose to be licensed under the terms of the GNU
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
     6
 * General Public License (GPL) Version 2, available from the file
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
     7
 * COPYING in the main directory of this source tree, or the
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
     8
 * OpenIB.org BSD license below:
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
     9
 *
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
    10
 *     Redistribution and use in source and binary forms, with or
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
    11
 *     without modification, are permitted provided that the following
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
    12
 *     conditions are met:
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
    13
 *
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
    14
 *      - Redistributions of source code must retain the above
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
    15
 *        copyright notice, this list of conditions and the following
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
    16
 *        disclaimer.
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
    17
 *
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
    18
 *      - Redistributions in binary form must reproduce the above
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
    19
 *        copyright notice, this list of conditions and the following
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
    20
 *        disclaimer in the documentation and/or other materials
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
    21
 *        provided with the distribution.
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
    22
 *
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
    23
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
    24
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
    25
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
    26
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
    27
 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
    28
 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
    29
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
    30
 * SOFTWARE.
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
    31
 */
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
    32
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
    33
/*
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
    34
 * OFED Solaris wrapper
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
    35
 */
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
    36
#if defined(__SVR4) && defined(__sun)
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
    37
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
    38
#include <stdio.h>
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
    39
#include <stdlib.h>
5950
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
    40
#include <errno.h>
369
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
    41
#include <unistd.h>
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
    42
#include <sys/types.h>
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
    43
#include <sys/stat.h>
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
    44
#include <fcntl.h>
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
    45
#include <ctype.h>
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
    46
#include <string.h>
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
    47
#include <strings.h>
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
    48
#include <getopt.h>
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
    49
#include <sys/utsname.h>
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
    50
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
    51
#include <infiniband/verbs.h>
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
    52
#include <infiniband/arch.h>
3679
c058dce9610f 18117487 saquery -m -t 50000 failed with multiple VFs created
boris.chiu@oracle.com
parents: 715
diff changeset
    53
#include <infiniband/umad.h>
5950
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
    54
#include "ibdiag_common.h"
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
    55
#include <sys/ib/clients/of/sol_uverbs/sol_uverbs_ioctl.h>
369
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
    56
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
    57
/*
5950
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
    58
 * Local defines for sol_uverbs IOCTLs, used while
369
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
    59
 * building on build system without the change in
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
    60
 * header files.
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
    61
 */
5950
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
    62
#ifndef	UVERBS_NODEDESC_UPDATE_STRING
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
    63
#define	UVERBS_IOCTL_GET_NODEDESC		('v' << 8) | 0x04
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
    64
#define	UVERBS_IOCTL_SET_NODEDESC		('v' << 8) | 0x05
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
    65
#define	UVERBS_NODEDESC_UPDATE_STRING		0x00000001
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
    66
#define	UVERBS_NODEDESC_UPDATE_HCA_STRING	0x00000002
7743
9d9ea22360ed 25109189 solaris_set_nodedesc doesn't handle node description >= 64 chars
shruthi.rr@oracle.com <shruthi.rr@oracle.com>
parents: 6322
diff changeset
    67
#define	UVERBS_NODEDESC_MAX			64
5950
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
    68
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
    69
typedef struct sol_uverbs_nodedesc_s {
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
    70
	int32_t		uverbs_solaris_abi_version;
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
    71
	char		node_desc_str[64];
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
    72
	uint32_t	node_desc_update_flag;
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
    73
} sol_uverbs_nodedesc_t;
369
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
    74
#endif
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
    75
5950
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
    76
/*
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
    77
 * Override verbs abi version.
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
    78
 * If the build system doesn't have the intended
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
    79
 * header file then override with the intended abi version.
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
    80
 * These changes can be deleted once the build system has
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
    81
 * the correct header file.
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
    82
 */
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
    83
#if	(IB_USER_VERBS_SOLARIS_ABI_VERSION == 2)
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
    84
#undef	IB_USER_VERBS_SOLARIS_ABI_VERSION
6322
c8b38df3868d PSARC/2016/109 Solaris OFED (OFUV) Version 3.18 and other updates
boris.chiu@oracle.com
parents: 5950
diff changeset
    85
#define	IB_USER_VERBS_SOLARIS_ABI_VERSION	4
5950
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
    86
#endif
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
    87
369
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
    88
#define	NODEDESC_READ			0x80000000
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
    89
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
    90
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
    91
char *argv0 = "solaris_set_nodedesc";
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
    92
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
    93
static struct nodedesc_read_info_s {
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
    94
	boolean_t	info_valid;
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
    95
	uint64_t	guid;
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
    96
	char		nd_string[64];
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
    97
	boolean_t	ofuv_name_valid;
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
    98
	char		ofuv_name[64];
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
    99
} nd_read_info_arr[MAX_HCAS];
5950
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   100
int	nd_read_info_cnt = 0;
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   101
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   102
static int
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   103
read_nodedesc_ioctl(struct ibv_context *context,
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   104
    sol_uverbs_nodedesc_t *nodedesc);
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   105
static int
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   106
write_nodedesc_ioctl(struct ibv_context *context,
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   107
    sol_uverbs_nodedesc_t *nodedesc);
369
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   108
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   109
static void
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   110
print_read_info()
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   111
{
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   112
	int	j;
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   113
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   114
	for (j = 0; j < nd_read_info_cnt; j++) {
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   115
		if (nd_read_info_arr[j].info_valid == B_FALSE ||
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   116
		    nd_read_info_arr[j].ofuv_name_valid == B_FALSE)
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   117
			continue;
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   118
		printf("%s: %-16s\n",
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   119
		    nd_read_info_arr[j].ofuv_name,
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   120
		    nd_read_info_arr[j].nd_string);
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   121
	}
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   122
}
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   123
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   124
static void
5950
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   125
update_read_info_hwnames(struct ibv_device **dev_list, int num_devices)
369
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   126
{
5950
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   127
	int		i;
369
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   128
	uint64_t	dev_guid;
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   129
	char		*dev_name;
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   130
	size_t		dev_name_len;
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   131
5950
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   132
	for (i = 0; dev_list[i] != 0 && i < num_devices; ++i) {
369
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   133
		int	j;
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   134
5950
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   135
		dev_guid = (uint64_t)ntohll(
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   136
		    ibv_get_device_guid(dev_list[i]));
369
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   137
		dev_name = (char *)ibv_get_device_name(dev_list[i]);
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   138
		dev_name_len = strlen(dev_name) + 1;
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   139
		for (j = 0; j < nd_read_info_cnt; j++) {
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   140
			if (nd_read_info_arr[j].info_valid == B_TRUE &&
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   141
			    nd_read_info_arr[j].guid == dev_guid) {
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   142
				memcpy(nd_read_info_arr[j].ofuv_name,
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   143
				    dev_name, dev_name_len);
5950
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   144
				nd_read_info_arr[j].ofuv_name_valid =
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   145
				    B_TRUE;
369
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   146
				break;
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   147
			}
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   148
		}
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   149
	}
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   150
}
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   151
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   152
static void
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   153
add_read_info_arr(char *nd_str, uint64_t guid)
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   154
{
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   155
	size_t	nd_len;
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   156
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   157
	nd_len = strlen(nd_str) + 1;
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   158
	nd_read_info_arr[nd_read_info_cnt].info_valid = B_TRUE;
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   159
	nd_read_info_arr[nd_read_info_cnt].guid = guid;
5950
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   160
	memcpy(nd_read_info_arr[nd_read_info_cnt].nd_string,
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   161
	    nd_str, nd_len);
369
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   162
	nd_read_info_cnt++;
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   163
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   164
}
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   165
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   166
static void
5950
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   167
do_driver_read_ioctl(struct ibv_device *device)
369
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   168
{
5950
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   169
	int			rc;
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   170
	uint64_t		hca_guid;
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   171
	struct ibv_context	*context;
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   172
	sol_uverbs_nodedesc_t	*nodedescp;
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   173
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   174
	/* Get the context for the device */
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   175
	context = ibv_open_device(device);
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   176
	if (!context) {
6322
c8b38df3868d PSARC/2016/109 Solaris OFED (OFUV) Version 3.18 and other updates
boris.chiu@oracle.com
parents: 5950
diff changeset
   177
		IBEXIT("Unable to open the device.\n");
5950
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   178
		/* NOTREACHED */
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   179
	}
369
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   180
5950
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   181
	if (context->device != device) {
6322
c8b38df3868d PSARC/2016/109 Solaris OFED (OFUV) Version 3.18 and other updates
boris.chiu@oracle.com
parents: 5950
diff changeset
   182
		IBEXIT("Device not set.\n");
5950
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   183
		/* NOTREACHED */
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   184
	}
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   185
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   186
	/* Allocate the memory for node descriptor */
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   187
	nodedescp = (sol_uverbs_nodedesc_t *)malloc(
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   188
	    sizeof (sol_uverbs_nodedesc_t));
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   189
	if (nodedescp == NULL) {
6322
c8b38df3868d PSARC/2016/109 Solaris OFED (OFUV) Version 3.18 and other updates
boris.chiu@oracle.com
parents: 5950
diff changeset
   190
		IBEXIT("Memory allocation failed.\n");
5950
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   191
		/* NOTREACHED */
369
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   192
	}
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   193
5950
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   194
	nodedescp->uverbs_solaris_abi_version =
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   195
	    IB_USER_VERBS_SOLARIS_ABI_VERSION;
369
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   196
5950
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   197
	/* Get the guid for the device */
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   198
	hca_guid = (uint64_t)ntohll(ibv_get_device_guid(device));
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   199
	if (!hca_guid) {
6322
c8b38df3868d PSARC/2016/109 Solaris OFED (OFUV) Version 3.18 and other updates
boris.chiu@oracle.com
parents: 5950
diff changeset
   200
		IBEXIT("ibv_get_device_guid failed.\n");
5950
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   201
		/* NOTREACHED */
369
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   202
	}
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   203
5950
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   204
	/* Read node descriptor */
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   205
	rc = read_nodedesc_ioctl(context, nodedescp);
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   206
	if (rc != 0) {
6322
c8b38df3868d PSARC/2016/109 Solaris OFED (OFUV) Version 3.18 and other updates
boris.chiu@oracle.com
parents: 5950
diff changeset
   207
		IBEXIT("Failed to read node descriptor.\n");
5950
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   208
		/* NOTREACHED */
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   209
	}
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   210
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   211
	add_read_info_arr((char *)nodedescp->node_desc_str,
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   212
	    hca_guid);
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   213
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   214
read_nodedesc_exit_1:
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   215
	/* release the allocated memory */
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   216
	free(nodedescp);
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   217
read_nodedesc_exit_2:
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   218
	/* Close the device */
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   219
	ibv_close_device(context);
369
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   220
}
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   221
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   222
static int
5950
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   223
do_driver_update_ioctl(struct ibv_device *device, char *node_desc,
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   224
    char *hca_desc, uint32_t update_flag)
369
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   225
{
5950
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   226
	int			rc;
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   227
	struct ibv_context	*context;
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   228
	sol_uverbs_nodedesc_t	*nodedescp;
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   229
	char			*desc_str;
369
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   230
5950
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   231
	desc_str = (node_desc ? node_desc : hca_desc);
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   232
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   233
	/* Get context for the device */
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   234
	context = ibv_open_device(device);
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   235
	if (!context) {
6322
c8b38df3868d PSARC/2016/109 Solaris OFED (OFUV) Version 3.18 and other updates
boris.chiu@oracle.com
parents: 5950
diff changeset
   236
		IBEXIT("Unable to open the device.\n");
5950
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   237
		/* NOTREACHED */
369
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   238
	}
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   239
5950
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   240
	if (context->device != device) {
6322
c8b38df3868d PSARC/2016/109 Solaris OFED (OFUV) Version 3.18 and other updates
boris.chiu@oracle.com
parents: 5950
diff changeset
   241
		IBEXIT("Device not set.\n");
5950
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   242
		/* NOTREACHED */
369
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   243
	}
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   244
5950
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   245
	/* Allocate the memory for node descriptor */
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   246
	nodedescp = (sol_uverbs_nodedesc_t *)malloc(
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   247
	    sizeof (sol_uverbs_nodedesc_t));
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   248
	if (nodedescp == NULL) {
6322
c8b38df3868d PSARC/2016/109 Solaris OFED (OFUV) Version 3.18 and other updates
boris.chiu@oracle.com
parents: 5950
diff changeset
   249
		IBEXIT("Memory allocation failed.\n");
5950
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   250
		/* NOTREACHED */
369
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   251
	}
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   252
5950
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   253
	strncpy(nodedescp->node_desc_str, desc_str, 64);
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   254
	nodedescp->node_desc_update_flag = update_flag;
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   255
	nodedescp->uverbs_solaris_abi_version =
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   256
	    IB_USER_VERBS_SOLARIS_ABI_VERSION;
369
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   257
5950
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   258
	rc = write_nodedesc_ioctl(context, nodedescp);
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   259
	if (rc != 0)
6322
c8b38df3868d PSARC/2016/109 Solaris OFED (OFUV) Version 3.18 and other updates
boris.chiu@oracle.com
parents: 5950
diff changeset
   260
		IBEXIT("Failed to set node descriptor.\n");
369
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   261
5950
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   262
	free(nodedescp);
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   263
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   264
write_nodedesc_exit:
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   265
	ibv_close_device(context);
369
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   266
	return (rc);
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   267
}
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   268
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   269
static void
5950
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   270
read_nodedesc(struct ibv_device **device_list, int num_devices)
369
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   271
{
5950
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   272
	int i;
369
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   273
5950
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   274
	for (i = 0; device_list[i] != 0 && i < num_devices; i++)
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   275
		do_driver_read_ioctl(device_list[i]);
369
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   276
}
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   277
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   278
static int
5950
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   279
update_nodedesc(struct ibv_device **device_list, int num_devices,
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   280
    char *cmn_nodedesc, char *hca_nodedesc, uint64_t guid,
369
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   281
    uint32_t update_flag)
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   282
{
5950
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   283
	int		i, rc = -1;
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   284
	uint64_t	dev_guid;
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   285
	boolean_t	matched = B_FALSE;
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   286
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   287
	if (cmn_nodedesc && hca_nodedesc == NULL) {
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   288
		for (i = 0; i < num_devices; i++) {
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   289
			rc = do_driver_update_ioctl(device_list[i],
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   290
			    cmn_nodedesc, hca_nodedesc, update_flag);
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   291
			if (rc != 0)
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   292
				continue;
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   293
			else
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   294
				break;
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   295
		}
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   296
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   297
		if (rc != 0 && i == num_devices)
6322
c8b38df3868d PSARC/2016/109 Solaris OFED (OFUV) Version 3.18 and other updates
boris.chiu@oracle.com
parents: 5950
diff changeset
   298
			IBEXIT("Failed to set the node descriptor.\n");
5950
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   299
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   300
		return (rc);
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   301
	}
369
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   302
5950
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   303
	if (hca_nodedesc && guid) {
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   304
		for (i = 0; i < num_devices; i++) {
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   305
			dev_guid = (uint64_t)ntohll(ibv_get_device_guid(
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   306
			    device_list[i]));
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   307
			if (!dev_guid) {
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   308
				continue;
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   309
			}
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   310
			if (dev_guid == guid) {
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   311
				matched = B_TRUE;
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   312
				rc = do_driver_update_ioctl(device_list[i],
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   313
				    cmn_nodedesc, hca_nodedesc, update_flag);
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   314
				break;
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   315
			} else {
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   316
				continue;
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   317
			}
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   318
		}
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   319
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   320
		if (matched == B_FALSE) {
6322
c8b38df3868d PSARC/2016/109 Solaris OFED (OFUV) Version 3.18 and other updates
boris.chiu@oracle.com
parents: 5950
diff changeset
   321
			IBEXIT("No guid matched.\n");
5950
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   322
			/* NOTREACHED */
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   323
		}
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   324
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   325
		if (rc != 0) {
6322
c8b38df3868d PSARC/2016/109 Solaris OFED (OFUV) Version 3.18 and other updates
boris.chiu@oracle.com
parents: 5950
diff changeset
   326
			IBEXIT("Failed to set the node descriptor.\n");
5950
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   327
			/* NOTREACHED */
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   328
		}
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   329
	}
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   330
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   331
	return (rc);
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   332
}
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   333
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   334
static int
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   335
read_nodedesc_ioctl(struct ibv_context *context,
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   336
    sol_uverbs_nodedesc_t *nodedesc)
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   337
{
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   338
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   339
	int	ret;
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   340
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   341
	/*
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   342
	 * Use ioctl call to sol_uverbs module.
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   343
	 */
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   344
	if (!context || !nodedesc) {
369
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   345
		return (-1);
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   346
	}
5950
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   347
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   348
	ret = ioctl(context->cmd_fd, UVERBS_IOCTL_GET_NODEDESC, nodedesc);
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   349
	if (ret != 0) {
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   350
		if (ret == EINVAL)
6322
c8b38df3868d PSARC/2016/109 Solaris OFED (OFUV) Version 3.18 and other updates
boris.chiu@oracle.com
parents: 5950
diff changeset
   351
			IBEXIT("ABI version check failed.\n");
5950
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   352
		else
6322
c8b38df3868d PSARC/2016/109 Solaris OFED (OFUV) Version 3.18 and other updates
boris.chiu@oracle.com
parents: 5950
diff changeset
   353
			IBEXIT("UVERBS_IOCTL_GET_NODEDESC ioctl failed.\n");
5950
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   354
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   355
		/* NOTREACHED */
369
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   356
	}
5950
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   357
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   358
	return (0);
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   359
}
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   360
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   361
static int
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   362
write_nodedesc_ioctl(struct ibv_context *context,
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   363
    sol_uverbs_nodedesc_t *nodedesc)
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   364
{
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   365
	int	ret;
369
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   366
5950
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   367
	/*
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   368
	 * Use ioctl call to sol_uverbs module.
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   369
	 */
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   370
	if (!context || !nodedesc)
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   371
		return (-1);
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   372
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   373
	ret = ioctl(context->cmd_fd, UVERBS_IOCTL_SET_NODEDESC, nodedesc);
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   374
	if (ret != 0) {
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   375
		if (ret == EINVAL)
6322
c8b38df3868d PSARC/2016/109 Solaris OFED (OFUV) Version 3.18 and other updates
boris.chiu@oracle.com
parents: 5950
diff changeset
   376
			IBEXIT("ABI version check failed.\n");
5950
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   377
		else
6322
c8b38df3868d PSARC/2016/109 Solaris OFED (OFUV) Version 3.18 and other updates
boris.chiu@oracle.com
parents: 5950
diff changeset
   378
			IBEXIT("UVERBS_IOCTL_SET_NODEDESC ioctl failed.\n");
5950
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   379
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   380
		/* NOTREACHED */
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   381
	}
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   382
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   383
	return (0);
369
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   384
}
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   385
5950
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   386
369
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   387
static void
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   388
usage(void)
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   389
{
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   390
	char *basename;
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   391
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   392
	if (!(basename = strrchr(argv0, '/')))
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   393
		basename = argv0;
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   394
	else
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   395
		basename++;
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   396
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   397
	fprintf(stderr, "Usage: %s \n", basename);
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   398
	fprintf(stderr, "\t\t %s [-N(ode_Descriptor) CmnString]\n",
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   399
	    basename);
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   400
	fprintf(stderr, "\t\t %s [-H(CA_Description) HCAString "
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   401
	    "-G(UID) HCA_GUID]\n", basename);
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   402
	fprintf(stderr, "\t\t %s [-H(CA_Description) HCAString "
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   403
	    "-G(UID) HCA_GUID -N(ode_Descriptor) CmnString]\n",
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   404
	    basename);
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   405
	fprintf(stderr, "\t\t %s [-v]\n", basename);
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   406
}
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   407
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   408
/*
7743
9d9ea22360ed 25109189 solaris_set_nodedesc doesn't handle node description >= 64 chars
shruthi.rr@oracle.com <shruthi.rr@oracle.com>
parents: 6322
diff changeset
   409
 * Name		: nodedesc_substr_cat
9d9ea22360ed 25109189 solaris_set_nodedesc doesn't handle node description >= 64 chars
shruthi.rr@oracle.com <shruthi.rr@oracle.com>
parents: 6322
diff changeset
   410
 *
9d9ea22360ed 25109189 solaris_set_nodedesc doesn't handle node description >= 64 chars
shruthi.rr@oracle.com <shruthi.rr@oracle.com>
parents: 6322
diff changeset
   411
 * Function	:
9d9ea22360ed 25109189 solaris_set_nodedesc doesn't handle node description >= 64 chars
shruthi.rr@oracle.com <shruthi.rr@oracle.com>
parents: 6322
diff changeset
   412
 * 	This fuction returns the node descriptor string
9d9ea22360ed 25109189 solaris_set_nodedesc doesn't handle node description >= 64 chars
shruthi.rr@oracle.com <shruthi.rr@oracle.com>
parents: 6322
diff changeset
   413
 * 	extracted from the command line arguments.
369
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   414
 *
7743
9d9ea22360ed 25109189 solaris_set_nodedesc doesn't handle node description >= 64 chars
shruthi.rr@oracle.com <shruthi.rr@oracle.com>
parents: 6322
diff changeset
   415
 * Inputs	:
9d9ea22360ed 25109189 solaris_set_nodedesc doesn't handle node description >= 64 chars
shruthi.rr@oracle.com <shruthi.rr@oracle.com>
parents: 6322
diff changeset
   416
 * 	Parameters
9d9ea22360ed 25109189 solaris_set_nodedesc doesn't handle node description >= 64 chars
shruthi.rr@oracle.com <shruthi.rr@oracle.com>
parents: 6322
diff changeset
   417
 * 	----------
9d9ea22360ed 25109189 solaris_set_nodedesc doesn't handle node description >= 64 chars
shruthi.rr@oracle.com <shruthi.rr@oracle.com>
parents: 6322
diff changeset
   418
 * 	argv, argc  - Command line arguments to main()
9d9ea22360ed 25109189 solaris_set_nodedesc doesn't handle node description >= 64 chars
shruthi.rr@oracle.com <shruthi.rr@oracle.com>
parents: 6322
diff changeset
   419
 * 	space_at_end- Indicates if a space should be
9d9ea22360ed 25109189 solaris_set_nodedesc doesn't handle node description >= 64 chars
shruthi.rr@oracle.com <shruthi.rr@oracle.com>
parents: 6322
diff changeset
   420
 * 		added at the end of returned string
9d9ea22360ed 25109189 solaris_set_nodedesc doesn't handle node description >= 64 chars
shruthi.rr@oracle.com <shruthi.rr@oracle.com>
parents: 6322
diff changeset
   421
 *	Externs
9d9ea22360ed 25109189 solaris_set_nodedesc doesn't handle node description >= 64 chars
shruthi.rr@oracle.com <shruthi.rr@oracle.com>
parents: 6322
diff changeset
   422
 *	-------
9d9ea22360ed 25109189 solaris_set_nodedesc doesn't handle node description >= 64 chars
shruthi.rr@oracle.com <shruthi.rr@oracle.com>
parents: 6322
diff changeset
   423
 *	optarg - string after option (-N / -H)
9d9ea22360ed 25109189 solaris_set_nodedesc doesn't handle node description >= 64 chars
shruthi.rr@oracle.com <shruthi.rr@oracle.com>
parents: 6322
diff changeset
   424
 *	optind - 1 based index to argv array for the
9d9ea22360ed 25109189 solaris_set_nodedesc doesn't handle node description >= 64 chars
shruthi.rr@oracle.com <shruthi.rr@oracle.com>
parents: 6322
diff changeset
   425
 *		string after option name
9d9ea22360ed 25109189 solaris_set_nodedesc doesn't handle node description >= 64 chars
shruthi.rr@oracle.com <shruthi.rr@oracle.com>
parents: 6322
diff changeset
   426
 *	See getopt_long(3C) for more information.
9d9ea22360ed 25109189 solaris_set_nodedesc doesn't handle node description >= 64 chars
shruthi.rr@oracle.com <shruthi.rr@oracle.com>
parents: 6322
diff changeset
   427
 *
9d9ea22360ed 25109189 solaris_set_nodedesc doesn't handle node description >= 64 chars
shruthi.rr@oracle.com <shruthi.rr@oracle.com>
parents: 6322
diff changeset
   428
 * Return	:
9d9ea22360ed 25109189 solaris_set_nodedesc doesn't handle node description >= 64 chars
shruthi.rr@oracle.com <shruthi.rr@oracle.com>
parents: 6322
diff changeset
   429
 * 	Node description string. The memory allocated
9d9ea22360ed 25109189 solaris_set_nodedesc doesn't handle node description >= 64 chars
shruthi.rr@oracle.com <shruthi.rr@oracle.com>
parents: 6322
diff changeset
   430
 * 	for the returned node descriptor string should
9d9ea22360ed 25109189 solaris_set_nodedesc doesn't handle node description >= 64 chars
shruthi.rr@oracle.com <shruthi.rr@oracle.com>
parents: 6322
diff changeset
   431
 * 	be freed by the caller.
9d9ea22360ed 25109189 solaris_set_nodedesc doesn't handle node description >= 64 chars
shruthi.rr@oracle.com <shruthi.rr@oracle.com>
parents: 6322
diff changeset
   432
 *
9d9ea22360ed 25109189 solaris_set_nodedesc doesn't handle node description >= 64 chars
shruthi.rr@oracle.com <shruthi.rr@oracle.com>
parents: 6322
diff changeset
   433
 * Notes	:
9d9ea22360ed 25109189 solaris_set_nodedesc doesn't handle node description >= 64 chars
shruthi.rr@oracle.com <shruthi.rr@oracle.com>
parents: 6322
diff changeset
   434
 * 	The node descriptor string can contain multiple
9d9ea22360ed 25109189 solaris_set_nodedesc doesn't handle node description >= 64 chars
shruthi.rr@oracle.com <shruthi.rr@oracle.com>
parents: 6322
diff changeset
   435
 * 	sub-strings, for example
9d9ea22360ed 25109189 solaris_set_nodedesc doesn't handle node description >= 64 chars
shruthi.rr@oracle.com <shruthi.rr@oracle.com>
parents: 6322
diff changeset
   436
 * 		-N s1 s2 s3
9d9ea22360ed 25109189 solaris_set_nodedesc doesn't handle node description >= 64 chars
shruthi.rr@oracle.com <shruthi.rr@oracle.com>
parents: 6322
diff changeset
   437
 * 	This function concatenates these sub-strings with
9d9ea22360ed 25109189 solaris_set_nodedesc doesn't handle node description >= 64 chars
shruthi.rr@oracle.com <shruthi.rr@oracle.com>
parents: 6322
diff changeset
   438
 * 	a space between the substring. An additional space
9d9ea22360ed 25109189 solaris_set_nodedesc doesn't handle node description >= 64 chars
shruthi.rr@oracle.com <shruthi.rr@oracle.com>
parents: 6322
diff changeset
   439
 * 	is added at the end, if "space_at_end" parameter
9d9ea22360ed 25109189 solaris_set_nodedesc doesn't handle node description >= 64 chars
shruthi.rr@oracle.com <shruthi.rr@oracle.com>
parents: 6322
diff changeset
   440
 * 	is TRUE.
9d9ea22360ed 25109189 solaris_set_nodedesc doesn't handle node description >= 64 chars
shruthi.rr@oracle.com <shruthi.rr@oracle.com>
parents: 6322
diff changeset
   441
 *
9d9ea22360ed 25109189 solaris_set_nodedesc doesn't handle node description >= 64 chars
shruthi.rr@oracle.com <shruthi.rr@oracle.com>
parents: 6322
diff changeset
   442
 * 	This function always returns a string of length
9d9ea22360ed 25109189 solaris_set_nodedesc doesn't handle node description >= 64 chars
shruthi.rr@oracle.com <shruthi.rr@oracle.com>
parents: 6322
diff changeset
   443
 * 	less than UVERBS_NODEDESC_MAX.
369
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   444
 */
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   445
static char *
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   446
nodedesc_substr_cat(char **argv, int argc, boolean_t space_at_end)
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   447
{
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   448
	int	i, start_opt, end_opt;
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   449
	char	*nodedesc_str;
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   450
7743
9d9ea22360ed 25109189 solaris_set_nodedesc doesn't handle node description >= 64 chars
shruthi.rr@oracle.com <shruthi.rr@oracle.com>
parents: 6322
diff changeset
   451
	/*
9d9ea22360ed 25109189 solaris_set_nodedesc doesn't handle node description >= 64 chars
shruthi.rr@oracle.com <shruthi.rr@oracle.com>
parents: 6322
diff changeset
   452
	 * Set start_opt to the 0 based index to the starting
9d9ea22360ed 25109189 solaris_set_nodedesc doesn't handle node description >= 64 chars
shruthi.rr@oracle.com <shruthi.rr@oracle.com>
parents: 6322
diff changeset
   453
	 * string after the option. As optind is 1 based,
9d9ea22360ed 25109189 solaris_set_nodedesc doesn't handle node description >= 64 chars
shruthi.rr@oracle.com <shruthi.rr@oracle.com>
parents: 6322
diff changeset
   454
	 * decrement 1.
9d9ea22360ed 25109189 solaris_set_nodedesc doesn't handle node description >= 64 chars
shruthi.rr@oracle.com <shruthi.rr@oracle.com>
parents: 6322
diff changeset
   455
	 */
9d9ea22360ed 25109189 solaris_set_nodedesc doesn't handle node description >= 64 chars
shruthi.rr@oracle.com <shruthi.rr@oracle.com>
parents: 6322
diff changeset
   456
	start_opt = optind - 1;
369
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   457
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   458
	/* Get the index for last sub-string */
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   459
	for (end_opt = 0, i = optind; i <= argc; i++) {
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   460
		if (i == argc || argv[i][0] == '-') {
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   461
			end_opt = i - 1;
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   462
			break;
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   463
		}
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   464
	}
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   465
	if (end_opt == 0)
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   466
		return (NULL);
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   467
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   468
	nodedesc_str = malloc(64);
7743
9d9ea22360ed 25109189 solaris_set_nodedesc doesn't handle node description >= 64 chars
shruthi.rr@oracle.com <shruthi.rr@oracle.com>
parents: 6322
diff changeset
   469
	/* copy the first string after the option. */
9d9ea22360ed 25109189 solaris_set_nodedesc doesn't handle node description >= 64 chars
shruthi.rr@oracle.com <shruthi.rr@oracle.com>
parents: 6322
diff changeset
   470
	strncpy(nodedesc_str, optarg, UVERBS_NODEDESC_MAX);
9d9ea22360ed 25109189 solaris_set_nodedesc doesn't handle node description >= 64 chars
shruthi.rr@oracle.com <shruthi.rr@oracle.com>
parents: 6322
diff changeset
   471
	nodedesc_str[UVERBS_NODEDESC_MAX - 1] = '\0';
369
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   472
	start_opt++;
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   473
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   474
	/*
7743
9d9ea22360ed 25109189 solaris_set_nodedesc doesn't handle node description >= 64 chars
shruthi.rr@oracle.com <shruthi.rr@oracle.com>
parents: 6322
diff changeset
   475
	 * concatenate subsequent strings after the option
9d9ea22360ed 25109189 solaris_set_nodedesc doesn't handle node description >= 64 chars
shruthi.rr@oracle.com <shruthi.rr@oracle.com>
parents: 6322
diff changeset
   476
	 * (if any). Add a space between the strings.
369
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   477
	 */
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   478
	for (i = start_opt; i <= end_opt; i++) {
7743
9d9ea22360ed 25109189 solaris_set_nodedesc doesn't handle node description >= 64 chars
shruthi.rr@oracle.com <shruthi.rr@oracle.com>
parents: 6322
diff changeset
   479
		/*
9d9ea22360ed 25109189 solaris_set_nodedesc doesn't handle node description >= 64 chars
shruthi.rr@oracle.com <shruthi.rr@oracle.com>
parents: 6322
diff changeset
   480
		 * Check if concatenated string would go out of
9d9ea22360ed 25109189 solaris_set_nodedesc doesn't handle node description >= 64 chars
shruthi.rr@oracle.com <shruthi.rr@oracle.com>
parents: 6322
diff changeset
   481
		 * bounds, if so skip the rest of the strings.
9d9ea22360ed 25109189 solaris_set_nodedesc doesn't handle node description >= 64 chars
shruthi.rr@oracle.com <shruthi.rr@oracle.com>
parents: 6322
diff changeset
   482
		 */
9d9ea22360ed 25109189 solaris_set_nodedesc doesn't handle node description >= 64 chars
shruthi.rr@oracle.com <shruthi.rr@oracle.com>
parents: 6322
diff changeset
   483
		if ((strlen(nodedesc_str) + strlen(argv[i]) + 1)
9d9ea22360ed 25109189 solaris_set_nodedesc doesn't handle node description >= 64 chars
shruthi.rr@oracle.com <shruthi.rr@oracle.com>
parents: 6322
diff changeset
   484
		    >= UVERBS_NODEDESC_MAX) {
9d9ea22360ed 25109189 solaris_set_nodedesc doesn't handle node description >= 64 chars
shruthi.rr@oracle.com <shruthi.rr@oracle.com>
parents: 6322
diff changeset
   485
			break;
9d9ea22360ed 25109189 solaris_set_nodedesc doesn't handle node description >= 64 chars
shruthi.rr@oracle.com <shruthi.rr@oracle.com>
parents: 6322
diff changeset
   486
		}
9d9ea22360ed 25109189 solaris_set_nodedesc doesn't handle node description >= 64 chars
shruthi.rr@oracle.com <shruthi.rr@oracle.com>
parents: 6322
diff changeset
   487
		/* concatenate a space and the next string. */
9d9ea22360ed 25109189 solaris_set_nodedesc doesn't handle node description >= 64 chars
shruthi.rr@oracle.com <shruthi.rr@oracle.com>
parents: 6322
diff changeset
   488
		strncat(nodedesc_str, " ", UVERBS_NODEDESC_MAX - 1);
9d9ea22360ed 25109189 solaris_set_nodedesc doesn't handle node description >= 64 chars
shruthi.rr@oracle.com <shruthi.rr@oracle.com>
parents: 6322
diff changeset
   489
		strncat(nodedesc_str, argv[i],
9d9ea22360ed 25109189 solaris_set_nodedesc doesn't handle node description >= 64 chars
shruthi.rr@oracle.com <shruthi.rr@oracle.com>
parents: 6322
diff changeset
   490
		    UVERBS_NODEDESC_MAX - strlen(nodedesc_str));
369
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   491
	}
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   492
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   493
	/*
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   494
	 * Add a space at the end, if the caller has set
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   495
	 * space_at_end and the nodedesc string doesn't
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   496
	 * contain a space at the end.
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   497
	 */
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   498
	if (space_at_end == B_TRUE &&
7743
9d9ea22360ed 25109189 solaris_set_nodedesc doesn't handle node description >= 64 chars
shruthi.rr@oracle.com <shruthi.rr@oracle.com>
parents: 6322
diff changeset
   499
	    nodedesc_str[strlen(nodedesc_str)] != ' ') {
9d9ea22360ed 25109189 solaris_set_nodedesc doesn't handle node description >= 64 chars
shruthi.rr@oracle.com <shruthi.rr@oracle.com>
parents: 6322
diff changeset
   500
		/*
9d9ea22360ed 25109189 solaris_set_nodedesc doesn't handle node description >= 64 chars
shruthi.rr@oracle.com <shruthi.rr@oracle.com>
parents: 6322
diff changeset
   501
		 * If the return string has already reached the
9d9ea22360ed 25109189 solaris_set_nodedesc doesn't handle node description >= 64 chars
shruthi.rr@oracle.com <shruthi.rr@oracle.com>
parents: 6322
diff changeset
   502
		 * maximum length, just overwrite the last char
9d9ea22360ed 25109189 solaris_set_nodedesc doesn't handle node description >= 64 chars
shruthi.rr@oracle.com <shruthi.rr@oracle.com>
parents: 6322
diff changeset
   503
		 * in the string with space.
9d9ea22360ed 25109189 solaris_set_nodedesc doesn't handle node description >= 64 chars
shruthi.rr@oracle.com <shruthi.rr@oracle.com>
parents: 6322
diff changeset
   504
		 *
9d9ea22360ed 25109189 solaris_set_nodedesc doesn't handle node description >= 64 chars
shruthi.rr@oracle.com <shruthi.rr@oracle.com>
parents: 6322
diff changeset
   505
		 * else strcat a space at the end.
9d9ea22360ed 25109189 solaris_set_nodedesc doesn't handle node description >= 64 chars
shruthi.rr@oracle.com <shruthi.rr@oracle.com>
parents: 6322
diff changeset
   506
		 */
9d9ea22360ed 25109189 solaris_set_nodedesc doesn't handle node description >= 64 chars
shruthi.rr@oracle.com <shruthi.rr@oracle.com>
parents: 6322
diff changeset
   507
		if (strlen(nodedesc_str) == (UVERBS_NODEDESC_MAX - 1))
9d9ea22360ed 25109189 solaris_set_nodedesc doesn't handle node description >= 64 chars
shruthi.rr@oracle.com <shruthi.rr@oracle.com>
parents: 6322
diff changeset
   508
			nodedesc_str[UVERBS_NODEDESC_MAX - 2] = ' ';
9d9ea22360ed 25109189 solaris_set_nodedesc doesn't handle node description >= 64 chars
shruthi.rr@oracle.com <shruthi.rr@oracle.com>
parents: 6322
diff changeset
   509
		else
9d9ea22360ed 25109189 solaris_set_nodedesc doesn't handle node description >= 64 chars
shruthi.rr@oracle.com <shruthi.rr@oracle.com>
parents: 6322
diff changeset
   510
			strncat(nodedesc_str, " ", 64);
9d9ea22360ed 25109189 solaris_set_nodedesc doesn't handle node description >= 64 chars
shruthi.rr@oracle.com <shruthi.rr@oracle.com>
parents: 6322
diff changeset
   511
	}
369
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   512
	return (nodedesc_str);
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   513
}
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   514
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   515
int
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   516
main(int argc, char **argv)
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   517
{
5950
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   518
	int			rc;
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   519
	char			*nodedesc = NULL;
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   520
	char			*hcadesc = NULL;
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   521
	uint32_t		update_flag = 0;
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   522
	struct utsname		uts_name;
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   523
	uint64_t		hca_guid;
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   524
	boolean_t		guid_inited = B_FALSE;
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   525
	extern int 		ibdebug;
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   526
	char			nodename[64];
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   527
	struct ibv_device	**device_list = NULL;
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   528
	int			num_devices = 0;
369
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   529
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   530
	static char const str_opts[] = "N:H:G:vd";
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   531
	static const struct option long_opts[] = {
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   532
		{ "Node_Descriptor", 1, 0, 'N'},
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   533
		{ "HCA_Description", 1, 0, 'H'},
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   534
		{ "GUID", 1, 0, 'G'},
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   535
		{ "verbose", 0, 0, 'v'},
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   536
		{ "debug", 0, 0, 'd'},
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   537
		{ }
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   538
	};
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   539
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   540
	argv0 = argv[0];
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   541
	while (1) {
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   542
		int ch = getopt_long(argc, argv, str_opts,
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   543
		    long_opts, NULL);
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   544
		if (ch == -1)
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   545
			break;
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   546
		switch (ch) {
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   547
		case 'N':
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   548
			nodedesc = nodedesc_substr_cat(argv, argc, B_TRUE);
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   549
			if (!nodedesc) {
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   550
				usage();
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   551
				rc = -1;
5950
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   552
				goto free_and_ret_2;
369
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   553
			}
5950
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   554
			update_flag |= UVERBS_NODEDESC_UPDATE_STRING;
369
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   555
			break;
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   556
		case 'H':
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   557
			hcadesc = nodedesc_substr_cat(argv, argc, B_FALSE);
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   558
			if (!hcadesc) {
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   559
				usage();
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   560
				rc = -1;
5950
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   561
				goto free_and_ret_2;
369
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   562
			}
5950
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   563
			update_flag |= UVERBS_NODEDESC_UPDATE_HCA_STRING;
369
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   564
			break;
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   565
		case 'G':
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   566
			guid_inited = B_TRUE;
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   567
			hca_guid = (uint64_t)strtoull(optarg, 0, 0);
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   568
			break;
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   569
		case 'v' :
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   570
			update_flag |= NODEDESC_READ;
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   571
			break;
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   572
		case 'd':
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   573
			ibdebug++;
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   574
			break;
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   575
		default:
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   576
			usage();
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   577
			rc = -1;
5950
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   578
			goto free_and_ret_2;
369
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   579
		}
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   580
	}
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   581
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   582
	if (update_flag & NODEDESC_READ) {
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   583
		if (nodedesc || hcadesc || guid_inited == B_TRUE) {
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   584
			usage();
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   585
			rc = -1;
5950
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   586
			goto free_and_ret_2;
369
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   587
		}
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   588
5950
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   589
		device_list = ibv_get_device_list(&num_devices);
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   590
		if (!device_list) {
6322
c8b38df3868d PSARC/2016/109 Solaris OFED (OFUV) Version 3.18 and other updates
boris.chiu@oracle.com
parents: 5950
diff changeset
   591
			IBEXIT("ibv_get_device_list failed.\n");
5950
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   592
			/* NOTREACHED */
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   593
		}
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   594
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   595
		read_nodedesc(device_list, num_devices);
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   596
		update_read_info_hwnames(device_list, num_devices);
369
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   597
		print_read_info();
5950
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   598
		rc = 0;
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   599
		goto free_and_ret_1;
369
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   600
	}
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   601
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   602
	if (hcadesc && guid_inited == B_FALSE) {
6322
c8b38df3868d PSARC/2016/109 Solaris OFED (OFUV) Version 3.18 and other updates
boris.chiu@oracle.com
parents: 5950
diff changeset
   603
		IBEXIT("No GUID specified for HCA Node descriptor");
5950
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   604
		/* NOTREACHED */
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   605
	}
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   606
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   607
	device_list = ibv_get_device_list(&num_devices);
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   608
	if (!device_list) {
6322
c8b38df3868d PSARC/2016/109 Solaris OFED (OFUV) Version 3.18 and other updates
boris.chiu@oracle.com
parents: 5950
diff changeset
   609
		IBEXIT("ibv_get_device_list failed.\n");
5950
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   610
		/* NOTREACHED */
369
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   611
	}
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   612
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   613
	if (nodedesc) {
5950
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   614
		rc = update_nodedesc(device_list, num_devices,
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   615
		    nodedesc, NULL, 0, UVERBS_NODEDESC_UPDATE_STRING);
369
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   616
		if (rc) {
6322
c8b38df3868d PSARC/2016/109 Solaris OFED (OFUV) Version 3.18 and other updates
boris.chiu@oracle.com
parents: 5950
diff changeset
   617
			IBEXIT("write common node descriptor "
369
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   618
			    "failed");
5950
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   619
			/* NOTREACHED */
369
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   620
		}
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   621
	}
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   622
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   623
	if (hcadesc) {
5950
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   624
		rc = update_nodedesc(device_list, num_devices,
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   625
		    NULL, hcadesc, hca_guid,
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   626
		    UVERBS_NODEDESC_UPDATE_HCA_STRING);
369
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   627
		if (rc) {
6322
c8b38df3868d PSARC/2016/109 Solaris OFED (OFUV) Version 3.18 and other updates
boris.chiu@oracle.com
parents: 5950
diff changeset
   628
			IBEXIT("update_hca_noddesc failed");
5950
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   629
			/* NOTREACHED */
369
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   630
		}
5950
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   631
		rc = 0;
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   632
		goto free_and_ret_1;
369
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   633
	}
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   634
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   635
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   636
	if (nodedesc == NULL) {
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   637
		if (uname(&uts_name) < 0) {
6322
c8b38df3868d PSARC/2016/109 Solaris OFED (OFUV) Version 3.18 and other updates
boris.chiu@oracle.com
parents: 5950
diff changeset
   638
			IBEXIT("Node descriptor unspecified"
369
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   639
			    "& uts_name failed");
5950
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   640
			/* NOTREACHED */
369
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   641
		}
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   642
715
eed3ed08f692 6926434 ib_read_bw, ib_read_lat: OFED utilities sometimes hang when using "-e" (event) flag
Boris Chiu <Boris.Chiu@oracle.COM>
parents: 636
diff changeset
   643
		/*
7743
9d9ea22360ed 25109189 solaris_set_nodedesc doesn't handle node description >= 64 chars
shruthi.rr@oracle.com <shruthi.rr@oracle.com>
parents: 6322
diff changeset
   644
		 * The common nodedesc string can have max
9d9ea22360ed 25109189 solaris_set_nodedesc doesn't handle node description >= 64 chars
shruthi.rr@oracle.com <shruthi.rr@oracle.com>
parents: 6322
diff changeset
   645
		 * UVERBS_NODEDESC_MAX chars. From the nodename,
9d9ea22360ed 25109189 solaris_set_nodedesc doesn't handle node description >= 64 chars
shruthi.rr@oracle.com <shruthi.rr@oracle.com>
parents: 6322
diff changeset
   646
		 * UVERBS_NODEDESC_MAX - 2 can be accommodated.
9d9ea22360ed 25109189 solaris_set_nodedesc doesn't handle node description >= 64 chars
shruthi.rr@oracle.com <shruthi.rr@oracle.com>
parents: 6322
diff changeset
   647
		 * A space is appended at the end, just like
9d9ea22360ed 25109189 solaris_set_nodedesc doesn't handle node description >= 64 chars
shruthi.rr@oracle.com <shruthi.rr@oracle.com>
parents: 6322
diff changeset
   648
		 * common node specified using the "-N" option.
715
eed3ed08f692 6926434 ib_read_bw, ib_read_lat: OFED utilities sometimes hang when using "-e" (event) flag
Boris Chiu <Boris.Chiu@oracle.COM>
parents: 636
diff changeset
   649
		 */
7743
9d9ea22360ed 25109189 solaris_set_nodedesc doesn't handle node description >= 64 chars
shruthi.rr@oracle.com <shruthi.rr@oracle.com>
parents: 6322
diff changeset
   650
		(void) strncpy(nodename, uts_name.nodename,
9d9ea22360ed 25109189 solaris_set_nodedesc doesn't handle node description >= 64 chars
shruthi.rr@oracle.com <shruthi.rr@oracle.com>
parents: 6322
diff changeset
   651
		    UVERBS_NODEDESC_MAX - 2);
9d9ea22360ed 25109189 solaris_set_nodedesc doesn't handle node description >= 64 chars
shruthi.rr@oracle.com <shruthi.rr@oracle.com>
parents: 6322
diff changeset
   652
		nodename[UVERBS_NODEDESC_MAX - 1] = '\0';
9d9ea22360ed 25109189 solaris_set_nodedesc doesn't handle node description >= 64 chars
shruthi.rr@oracle.com <shruthi.rr@oracle.com>
parents: 6322
diff changeset
   653
		if (nodename[strlen(nodename)] != ' ') {
9d9ea22360ed 25109189 solaris_set_nodedesc doesn't handle node description >= 64 chars
shruthi.rr@oracle.com <shruthi.rr@oracle.com>
parents: 6322
diff changeset
   654
			if (strlen(nodename) == UVERBS_NODEDESC_MAX - 1)
9d9ea22360ed 25109189 solaris_set_nodedesc doesn't handle node description >= 64 chars
shruthi.rr@oracle.com <shruthi.rr@oracle.com>
parents: 6322
diff changeset
   655
				nodename[UVERBS_NODEDESC_MAX - 2] = ' ';
9d9ea22360ed 25109189 solaris_set_nodedesc doesn't handle node description >= 64 chars
shruthi.rr@oracle.com <shruthi.rr@oracle.com>
parents: 6322
diff changeset
   656
			else
9d9ea22360ed 25109189 solaris_set_nodedesc doesn't handle node description >= 64 chars
shruthi.rr@oracle.com <shruthi.rr@oracle.com>
parents: 6322
diff changeset
   657
				(void) strncat(nodename, " ",
9d9ea22360ed 25109189 solaris_set_nodedesc doesn't handle node description >= 64 chars
shruthi.rr@oracle.com <shruthi.rr@oracle.com>
parents: 6322
diff changeset
   658
				    UVERBS_NODEDESC_MAX - 2);
9d9ea22360ed 25109189 solaris_set_nodedesc doesn't handle node description >= 64 chars
shruthi.rr@oracle.com <shruthi.rr@oracle.com>
parents: 6322
diff changeset
   659
		}
715
eed3ed08f692 6926434 ib_read_bw, ib_read_lat: OFED utilities sometimes hang when using "-e" (event) flag
Boris Chiu <Boris.Chiu@oracle.COM>
parents: 636
diff changeset
   660
5950
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   661
		rc = update_nodedesc(device_list, num_devices,
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   662
		    nodename, NULL, 0,
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   663
		    UVERBS_NODEDESC_UPDATE_STRING);
715
eed3ed08f692 6926434 ib_read_bw, ib_read_lat: OFED utilities sometimes hang when using "-e" (event) flag
Boris Chiu <Boris.Chiu@oracle.COM>
parents: 636
diff changeset
   664
		if (rc) {
6322
c8b38df3868d PSARC/2016/109 Solaris OFED (OFUV) Version 3.18 and other updates
boris.chiu@oracle.com
parents: 5950
diff changeset
   665
			IBEXIT("write common node descriptor failed");
5950
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   666
			/* NOTREACHED */
715
eed3ed08f692 6926434 ib_read_bw, ib_read_lat: OFED utilities sometimes hang when using "-e" (event) flag
Boris Chiu <Boris.Chiu@oracle.COM>
parents: 636
diff changeset
   667
		}
eed3ed08f692 6926434 ib_read_bw, ib_read_lat: OFED utilities sometimes hang when using "-e" (event) flag
Boris Chiu <Boris.Chiu@oracle.COM>
parents: 636
diff changeset
   668
	}
369
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   669
5950
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   670
free_and_ret_1:
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   671
	ibv_free_device_list(device_list);
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   672
9032c8d91972 PSARC/2016/182 IB HCA driver interface and other updates
boris.chiu@oracle.com
parents: 3679
diff changeset
   673
free_and_ret_2:
369
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   674
	if (nodedesc)
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   675
		free(nodedesc);
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   676
	if (hcadesc)
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   677
		free(hcadesc);
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   678
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   679
	return (rc);
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   680
}
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   681
cc8c00719da9 PSARC 2011/165 OFUV update of existing components
Boris Chiu <Boris.Chiu@Sun.COM>
parents:
diff changeset
   682
#endif