1/*
2 * Copyright (c) 2008 Lawrence Livermore National Laboratory
3 *
4 * This software is available to you under a choice of one of two
5 * licenses.  You may choose to be licensed under the terms of the GNU
6 * General Public License (GPL) Version 2, available from the file
7 * COPYING in the main directory of this source tree, or the
8 * OpenIB.org BSD license below:
9 *
10 *     Redistribution and use in source and binary forms, with or
11 *     without modification, are permitted provided that the following
12 *     conditions are met:
13 *
14 *      - Redistributions of source code must retain the above
15 *        copyright notice, this list of conditions and the following
16 *        disclaimer.
17 *
18 *      - Redistributions in binary form must reproduce the above
19 *        copyright notice, this list of conditions and the following
20 *        disclaimer in the documentation and/or other materials
21 *        provided with the distribution.
22 *
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30 * SOFTWARE.
31 *
32 */
33
34/** =========================================================================
35 * Define the internal data structures.
36 */
37
38#ifndef _INTERNAL_H_
39#define _INTERNAL_H_
40
41#include <infiniband/ibnetdisc.h>
42#include <complib/cl_qmap.h>
43
44#define	IBND_DEBUG(fmt, ...) \
45	if (ibdebug) { \
46		printf("%s:%u; " fmt, __FILE__, __LINE__, ## __VA_ARGS__); \
47	}
48#define	IBND_ERROR(fmt, ...) \
49		fprintf(stderr, "%s:%u; " fmt, __FILE__, __LINE__, ## __VA_ARGS__)
50
51/* HASH table defines */
52#define HASHGUID(guid) ((uint32_t)(((uint32_t)(guid) * 101) ^ ((uint32_t)((guid) >> 32) * 103)))
53
54#define MAXHOPS         63
55
56#define DEFAULT_MAX_SMP_ON_WIRE 2
57#define DEFAULT_TIMEOUT 1000
58#define DEFAULT_RETRIES 3
59
60#define	GINT_TO_POINTER(x) ((void *)(uintptr_t)(x))
61
62typedef struct GHashTable GHashTable;
63
64#define	g_hash_table_new_full(...) GHashTableNew()
65#define	g_hash_table_destroy(...) GHashTableDestroy(__VA_ARGS__)
66#define	g_hash_table_insert(...) GHashTableInsert(__VA_ARGS__)
67#define	g_hash_table_lookup(...) GHashTableLookup(__VA_ARGS__)
68
69extern GHashTable *GHashTableNew(void);
70extern void GHashTableDestroy(GHashTable *);
71extern void GHashTableInsert(GHashTable *, void *key, void *value);
72extern void *GHashTableLookup(GHashTable *, void *key);
73
74typedef struct f_internal {
75	ibnd_fabric_t fabric;
76	GHashTable *lid2guid;
77} f_internal_t;
78f_internal_t *allocate_fabric_internal(void);
79void create_lid2guid(f_internal_t *f_int);
80void destroy_lid2guid(f_internal_t *f_int);
81void add_to_portlid_hash(ibnd_port_t * port, GHashTable *htable);
82
83typedef struct ibnd_scan {
84	ib_portid_t selfportid;
85	f_internal_t *f_int;
86	struct ibnd_config *cfg;
87	unsigned initial_hops;
88} ibnd_scan_t;
89
90typedef struct ibnd_smp ibnd_smp_t;
91typedef struct smp_engine smp_engine_t;
92typedef int (*smp_comp_cb_t) (smp_engine_t * engine, ibnd_smp_t * smp,
93			      uint8_t * mad_resp, void *cb_data);
94struct ibnd_smp {
95	cl_map_item_t on_wire;
96	struct ibnd_smp *qnext;
97	smp_comp_cb_t cb;
98	void *cb_data;
99	ib_portid_t path;
100	ib_rpc_t rpc;
101};
102
103struct smp_engine {
104	int umad_fd;
105	int smi_agent;
106	int smi_dir_agent;
107	ibnd_smp_t *smp_queue_head;
108	ibnd_smp_t *smp_queue_tail;
109	void *user_data;
110	cl_qmap_t smps_on_wire;
111	struct ibnd_config *cfg;
112	unsigned total_smps;
113};
114
115int smp_engine_init(smp_engine_t * engine, char * ca_name, int ca_port,
116		    void *user_data, ibnd_config_t *cfg);
117int issue_smp(smp_engine_t * engine, ib_portid_t * portid,
118	      unsigned attrid, unsigned mod, smp_comp_cb_t cb, void *cb_data);
119int process_mads(smp_engine_t * engine);
120void smp_engine_destroy(smp_engine_t * engine);
121
122int add_to_nodeguid_hash(ibnd_node_t * node, ibnd_node_t * hash[]);
123
124int add_to_portguid_hash(ibnd_port_t * port, ibnd_port_t * hash[]);
125
126void add_to_type_list(ibnd_node_t * node, f_internal_t * fabric);
127
128void destroy_node(ibnd_node_t * node);
129
130#endif				/* _INTERNAL_H_ */
131