1219820Sjeff/*
2219820Sjeff * Copyright (c) 2004-2006 Voltaire, Inc. All rights reserved.
3219820Sjeff * Copyright (c) 2002-2005 Mellanox Technologies LTD. All rights reserved.
4219820Sjeff * Copyright (c) 1996-2003 Intel Corporation. All rights reserved.
5219820Sjeff *
6219820Sjeff * This software is available to you under a choice of one of two
7219820Sjeff * licenses.  You may choose to be licensed under the terms of the GNU
8219820Sjeff * General Public License (GPL) Version 2, available from the file
9219820Sjeff * COPYING in the main directory of this source tree, or the
10219820Sjeff * OpenIB.org BSD license below:
11219820Sjeff *
12219820Sjeff *     Redistribution and use in source and binary forms, with or
13219820Sjeff *     without modification, are permitted provided that the following
14219820Sjeff *     conditions are met:
15219820Sjeff *
16219820Sjeff *      - Redistributions of source code must retain the above
17219820Sjeff *        copyright notice, this list of conditions and the following
18219820Sjeff *        disclaimer.
19219820Sjeff *
20219820Sjeff *      - Redistributions in binary form must reproduce the above
21219820Sjeff *        copyright notice, this list of conditions and the following
22219820Sjeff *        disclaimer in the documentation and/or other materials
23219820Sjeff *        provided with the distribution.
24219820Sjeff *
25219820Sjeff * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
26219820Sjeff * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27219820Sjeff * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
28219820Sjeff * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
29219820Sjeff * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
30219820Sjeff * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
31219820Sjeff * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
32219820Sjeff * SOFTWARE.
33219820Sjeff *
34219820Sjeff */
35219820Sjeff
36219820Sjeff#if HAVE_CONFIG_H
37219820Sjeff#  include <config.h>
38219820Sjeff#endif				/* HAVE_CONFIG_H */
39219820Sjeff
40219820Sjeff#if defined(OSM_VENDOR_INTF_ANAFA)
41219820Sjeff#undef IN
42219820Sjeff#undef OUT
43219820Sjeff
44219820Sjeff#include <stdlib.h>
45219820Sjeff#include <stddef.h>
46219820Sjeff#include <string.h>
47219820Sjeff
48219820Sjeff#include <vendor/osm_vendor_api.h>
49219820Sjeff#include <opensm/osm_log.h>
50219820Sjeff#include <sys/ioctl.h>
51219820Sjeff
52219820Sjeff#include <vendor/osm_vendor_mlx_transport_anafa.h>
53219820Sjeff#include <vendor/osm_ts_useraccess.h>
54219820Sjeff
55219820Sjeff/********************************************************************************
56219820Sjeff *
57219820Sjeff * Provide the functionality for selecting an HCA Port and Obtaining it's guid.
58219820Sjeff *
59219820Sjeff ********************************************************************************/
60219820Sjeff
61219820Sjefftypedef struct _osm_ca_info {
62219820Sjeff	/* ib_net64_t guid; ?? */
63219820Sjeff	/* size_t attr_size; ?? */
64219820Sjeff	ib_ca_attr_t attr;
65219820Sjeff} osm_ca_info_t;
66219820Sjeff
67219820Sjeff/**********************************************************************
68219820Sjeff * Convert the given GID to GUID by copy of it's upper 8 bytes
69219820Sjeff **********************************************************************/
70219820Sjeffib_api_status_t
71219820Sjeff__osm_vendor_gid_to_guid(IN tTS_IB_GID gid, OUT ib_net64_t * p_guid)
72219820Sjeff{
73219820Sjeff	memcpy(p_guid, gid + 8, 8);
74219820Sjeff	return (IB_SUCCESS);
75219820Sjeff}
76219820Sjeff
77219820Sjeff/**********************************************************************
78219820Sjeff * Initialize an Info Struct for the Given HCA by its Id
79219820Sjeff **********************************************************************/
80219820Sjeffstatic ib_api_status_t
81219820Sjeff__osm_ca_info_init(IN osm_vendor_t * const p_vend,
82219820Sjeff		   OUT osm_ca_info_t * const p_ca_info)
83219820Sjeff{
84219820Sjeff	ib_api_status_t status = IB_ERROR;
85219820Sjeff	int ioctl_ret = 0;
86219820Sjeff	osmv_TOPSPIN_ANAFA_transport_info_t *p_tpot_info =
87219820Sjeff	    p_vend->p_transport_info;
88219820Sjeff	osm_ts_gid_entry_ioctl gid_ioctl;
89219820Sjeff	osm_ts_get_port_info_ioctl port_info;
90219820Sjeff	struct ib_get_dev_info_ioctl dev_info;
91219820Sjeff
92219820Sjeff	OSM_LOG_ENTER(p_vend->p_log);
93219820Sjeff
94219820Sjeff	/* query HCA guid */
95219820Sjeff	ioctl_ret = ioctl(p_tpot_info->device_fd, TS_IB_IOCGDEVINFO, &dev_info);
96219820Sjeff	if (ioctl_ret != 0) {
97219820Sjeff		osm_log(p_vend->p_log, OSM_LOG_ERROR,
98219820Sjeff			"__osm_ca_info_init: ERR 7001: "
99219820Sjeff			"Fail to get HCA Capabilities (%d).\n", ioctl_ret);
100219820Sjeff		goto Exit;
101219820Sjeff	}
102219820Sjeff
103219820Sjeff	memcpy(&(p_ca_info->attr.ca_guid), dev_info.dev_info.node_guid,
104219820Sjeff	       8 * sizeof(uint8_t));
105219820Sjeff
106219820Sjeff/* now obtain the attributes of the ports - on our case port 1*/
107219820Sjeff
108219820Sjeff	p_ca_info->attr.num_ports = 1;
109219820Sjeff	p_ca_info->attr.p_port_attr =
110219820Sjeff	    (ib_port_attr_t *) malloc(1 * sizeof(ib_port_attr_t));
111219820Sjeff
112219820Sjeff	port_info.port = 1;
113219820Sjeff	ioctl_ret =
114219820Sjeff	    ioctl(p_tpot_info->device_fd, TS_IB_IOCGPORTINFO, &port_info);
115219820Sjeff	if (ioctl_ret) {
116219820Sjeff		osm_log(p_vend->p_log, OSM_LOG_ERROR,
117219820Sjeff			"__osm_ca_info_init: ERR 7002: "
118219820Sjeff			"Fail to get HCA Port Attributes (%d).\n", ioctl_ret);
119219820Sjeff		goto Exit;
120219820Sjeff	}
121219820Sjeff
122219820Sjeff	gid_ioctl.port = 1;
123219820Sjeff	gid_ioctl.index = 0;
124219820Sjeff	ioctl_ret =
125219820Sjeff	    ioctl(p_tpot_info->device_fd, TS_IB_IOCGGIDENTRY, &gid_ioctl);
126219820Sjeff	if (ioctl_ret) {
127219820Sjeff		osm_log(p_vend->p_log, OSM_LOG_ERROR,
128219820Sjeff			"__osm_ca_info_init: ERR 7003: "
129219820Sjeff			"Fail to get HCA Port GID (%d).\n", ioctl_ret);
130219820Sjeff		goto Exit;
131219820Sjeff	}
132219820Sjeff
133219820Sjeff	__osm_vendor_gid_to_guid(gid_ioctl.gid_entry,
134219820Sjeff				 &(p_ca_info->attr.p_port_attr[0].port_guid));
135219820Sjeff	p_ca_info->attr.p_port_attr[0].lid = port_info.port_info.lid;
136219820Sjeff	p_ca_info->attr.p_port_attr[0].link_state =
137219820Sjeff	    port_info.port_info.port_state;
138219820Sjeff	p_ca_info->attr.p_port_attr[0].sm_lid = port_info.port_info.sm_lid;
139219820Sjeff
140219820Sjeff	status = IB_SUCCESS;
141219820SjeffExit:
142219820Sjeff	OSM_LOG_EXIT(p_vend->p_log);
143219820Sjeff	return (status);
144219820Sjeff}
145219820Sjeff
146219820Sjeff/**********************************************************************
147219820Sjeff **********************************************************************/
148219820Sjeff/**********************************************************************
149219820Sjeff * Fill in port_attr
150219820Sjeff * ALSO -
151219820Sjeff * Update the vendor object list of ca_info structs
152219820Sjeff **********************************************************************/
153219820Sjeffib_api_status_t
154219820Sjeffosm_vendor_get_all_port_attr(IN osm_vendor_t * const p_vend,
155219820Sjeff			     IN ib_port_attr_t * const p_attr_array,
156219820Sjeff			     IN uint32_t * const p_num_ports)
157219820Sjeff{
158219820Sjeff	ib_api_status_t status;
159219820Sjeff	osm_ca_info_t ca_info;
160219820Sjeff	uint32_t attr_array_sz = *p_num_ports;
161219820Sjeff
162219820Sjeff	OSM_LOG_ENTER(p_vend->p_log);
163219820Sjeff	CL_ASSERT(p_vend);
164219820Sjeff
165219820Sjeff	/* anafa has one port - the user didnt supply enough storage space */
166219820Sjeff	if (attr_array_sz < 1) {
167219820Sjeff		status = IB_INSUFFICIENT_MEMORY;
168219820Sjeff		goto Exit;
169219820Sjeff	}
170219820Sjeff
171219820Sjeff	/*
172219820Sjeff	 * retrieve the CA info attributes
173219820Sjeff	 */
174219820Sjeff	status = __osm_ca_info_init(p_vend, &ca_info);
175219820Sjeff	if (status != IB_SUCCESS) {
176219820Sjeff		osm_log(p_vend->p_log, OSM_LOG_ERROR,
177219820Sjeff			"osm_vendor_get_all_port_attr: ERR 7004: "
178219820Sjeff			"Unable to initialize CA Info object (%s).\n",
179219820Sjeff			ib_get_err_str(status));
180219820Sjeff		goto Exit;
181219820Sjeff	}
182219820Sjeff
183219820Sjeff	*p_num_ports = 1;
184219820Sjeff
185219820Sjeff	p_attr_array[0] = ca_info.attr.p_port_attr[0];	/* anafa has only one port */
186219820Sjeff	status = IB_SUCCESS;
187219820Sjeff
188219820SjeffExit:
189219820Sjeff
190219820Sjeff	OSM_LOG_EXIT(p_vend->p_log);
191219820Sjeff	return (status);
192219820Sjeff}
193219820Sjeff
194219820Sjeff#endif
195