author | Cyril Plisko <cyril.plisko@grigale.com> |
Thu, 16 Dec 2010 05:01:21 -0800 | |
changeset 58 | 2605957be88f |
parent 56 | 5c4fb282c1e7 |
child 62 | aa9ba7d986b5 |
permissions | -rw-r--r-- |
56 | 1 |
/* |
2 |
* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. |
|
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 |
#if HAVE_CONFIG_H |
|
58
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
33 |
#include <config.h> |
56 | 34 |
#endif /* HAVE_CONFIG_H */ |
35 |
||
36 |
/* |
|
37 |
* OFED Solaris wrapper |
|
38 |
*/ |
|
39 |
#if defined(__SVR4) && defined(__sun) |
|
40 |
||
41 |
#include <stdarg.h> |
|
42 |
#include <fcntl.h> |
|
43 |
#include <unistd.h> |
|
44 |
#include <sys/types.h> |
|
45 |
#include <sys/processor.h> |
|
46 |
#include <stdio.h> |
|
47 |
#include <stdlib.h> |
|
48 |
#include <strings.h> |
|
49 |
||
50 |
#include <alloca.h> |
|
51 |
#include "../include/infiniband/arch.h" |
|
52 |
#include "../include/infiniband/verbs.h" |
|
53 |
#include "../../libmthca-1.0.4/src/mthca-abi.h" |
|
54 |
#include "../../libmlx4-1.0/src/mlx4-abi.h" |
|
55 |
#include "../../librdmacm-1.0.6/include/rdma/rdma_cma_abi.h" |
|
56 |
#include <libdevinfo.h> |
|
58
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
57 |
#include <pthread.h> |
56 | 58 |
|
58
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
59 |
#define MLX4 0 |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
60 |
#define MTHCA 1 |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
61 |
#define MAX_HCAS 16 |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
62 |
#define MAX_HCA_PORTS 16 |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
63 |
#define HW_DRIVER_MAX_NAME_LEN 20 |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
64 |
#define UVERBS_KERNEL_SYSFS_NAME "sol_uverbs@0:uverbs0" |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
65 |
#define UVERBS "sol_uverbs" |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
66 |
#define UMAD "sol_umad" |
56 | 67 |
#define UVERBS_IB_DEVPATH_PREFIX "/devices/ib" |
58
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
68 |
#define CONNECTX_NAME "mlx4_" |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
69 |
#define INFINIHOST_NAME "mthca" |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
70 |
#define MAX_HCA_DEVCTRL_PATH_LEN MAXPATHLEN/4 |
56 | 71 |
|
72 |
#define MELLANOX_VENDOR_ID 0x15b3 |
|
58
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
73 |
#define PCI_DEVICE_ID_MELLANOX_TAVOR 0x5a44 |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
74 |
#define PCI_DEVICE_ID_MELLANOX_ARBEL 0x6282 |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
75 |
#define PCI_DEVICE_ID_MELLANOX_ARBEL_COMPAT 0x6278 |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
76 |
#define PCI_DEVICE_ID_MELLANOX_HERMON_SDR 0x6340 |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
77 |
#define PCI_DEVICE_ID_MELLANOX_HERMON_DDR 0x634a |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
78 |
#define PCI_DEVICE_ID_MELLANOX_HERMON_QDR 0x6354 |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
79 |
#define PCI_DEVICE_ID_MELLANOX_HERMON_DDR_PCIE2 0x6732 |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
80 |
#define PCI_DEVICE_ID_MELLANOX_HERMON_QDR_PCIE2 0x673c |
56 | 81 |
#define INFINIHOST_DEVICE_ID_2 0x5a45 |
82 |
#define INFINIHOST_DEVICE_ID_4 0x6279 |
|
83 |
||
84 |
/* |
|
85 |
* sol_uverbs_drv_status is the status of what libibverbs knows |
|
86 |
* about the status of sol_uverbs driver. |
|
87 |
*/ |
|
88 |
#define SOL_UVERBS_DRV_STATUS_UNKNOWN 0x0 |
|
89 |
#define SOL_UVERBS_DRV_STATUS_LOADED 0x1 |
|
90 |
#define SOL_UVERBS_DRV_STATUS_UNLOADED 0x02 |
|
91 |
||
58
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
92 |
|
56 | 93 |
static int sol_uverbs_drv_status = SOL_UVERBS_DRV_STATUS_UNKNOWN; |
94 |
||
95 |
/* |
|
96 |
* check_path() prefixs |
|
97 |
*/ |
|
98 |
typedef enum cp_prefix_e { |
|
99 |
CP_SOL_UVERBS = 1, |
|
58
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
100 |
CP_DEVICE = 2, |
56 | 101 |
CP_D = 3, |
102 |
CP_GIDS = 4, |
|
103 |
CP_PKEYS = 5, |
|
104 |
CP_MTHCA = 6, |
|
105 |
CP_MLX4 = 7, |
|
106 |
CP_PORTS = 8, |
|
107 |
CP_UMAD = 9, |
|
108 |
CP_SLASH = 10, |
|
109 |
CP_SYS = 11, |
|
110 |
CP_CLASS = 12, |
|
111 |
CP_INFINIBAND_VERBS = 13, |
|
112 |
CP_INFINIBAND = 14, |
|
113 |
CP_INFINIBAND_MAD = 15, |
|
114 |
CP_MISC = 16, |
|
115 |
CP_RDMA_CM = 17 |
|
116 |
} cp_prefix_t; |
|
117 |
||
118 |
/* |
|
58
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
119 |
* Some temporary cache code, until things are cleaned up as part of DR |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
120 |
* work. This will speed up the sysfs emulation. |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
121 |
*/ |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
122 |
typedef struct ibdev_cache_info_s { |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
123 |
uint_t ibd_valid; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
124 |
uint_t ibd_hw_rev; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
125 |
char ibd_node_guid_str[20]; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
126 |
char ibd_sys_image_guid[20]; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
127 |
char ibd_fw_ver[16]; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
128 |
char ibd_name[8]; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
129 |
} ibdev_cache_info_t; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
130 |
|
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
131 |
/* tavor and hermon - hence 2 */ |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
132 |
static ibdev_cache_info_t ibdev_cache[2][MAX_HCAS]; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
133 |
|
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
134 |
typedef struct uverbs_cache_info_s { |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
135 |
uint_t uvc_valid; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
136 |
uint_t uvc_abi_version; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
137 |
uint_t uvc_ibdev_abi_version; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
138 |
uint_t uvc_vendor_id; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
139 |
uint_t uvc_device_id; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
140 |
int uvc_hca_instance; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
141 |
char uvc_ibdev_name[8]; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
142 |
char uvc_ibdev_hca_path[MAX_HCA_DEVCTRL_PATH_LEN]; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
143 |
} uverbs_cache_info_t; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
144 |
static uverbs_cache_info_t uverbs_dev_cache[MAX_HCAS]; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
145 |
|
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
146 |
typedef struct umad_cache_info_s { |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
147 |
uint_t umc_valid; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
148 |
int umc_port; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
149 |
int umc_abi_version; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
150 |
char umc_ib_dev[16]; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
151 |
} umad_cache_info_t; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
152 |
static umad_cache_info_t umad_dev_cache[MAX_HCAS * MAX_HCA_PORTS]; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
153 |
|
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
154 |
pthread_once_t oneTimeInit = PTHREAD_ONCE_INIT; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
155 |
static int umad_cache_cnt = 0; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
156 |
static int ibdev_cache_cnt = 0; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
157 |
static int uverbs_cache_cnt = 0; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
158 |
static boolean_t initialized = B_FALSE; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
159 |
static boolean_t umad_cache_initialized = B_FALSE; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
160 |
static boolean_t ibdev_cache_initialized = B_FALSE; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
161 |
static boolean_t uverbs_cache_initialized = B_FALSE; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
162 |
static pthread_mutex_t umad_cache_mutex = PTHREAD_MUTEX_INITIALIZER; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
163 |
static pthread_mutex_t ibdev_cache_mutex = PTHREAD_MUTEX_INITIALIZER; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
164 |
static pthread_mutex_t uverbs_cache_mutex = PTHREAD_MUTEX_INITIALIZER; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
165 |
|
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
166 |
static di_node_t root_node; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
167 |
|
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
168 |
void __attribute__ ((constructor)) solaris_init(void); |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
169 |
void __attribute__ ((destructor)) solaris_fini(void); |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
170 |
|
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
171 |
void |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
172 |
solaris_init(void) |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
173 |
{ |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
174 |
root_node = di_init("/", DINFOCPYALL); |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
175 |
if (root_node == DI_NODE_NIL) { |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
176 |
fprintf(stderr, "di_init failed: %s\n", strerror(errno)); |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
177 |
exit(1); |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
178 |
} |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
179 |
} |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
180 |
|
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
181 |
void |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
182 |
solaris_fini(void) |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
183 |
{ |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
184 |
di_fini(root_node); |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
185 |
} |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
186 |
|
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
187 |
static void |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
188 |
vendor_device_id_to_name(int vendor, int device, char *name) |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
189 |
{ |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
190 |
char *hca_name = "<unknown>"; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
191 |
|
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
192 |
if (vendor == MELLANOX_VENDOR_ID) { |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
193 |
switch (device) { |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
194 |
case PCI_DEVICE_ID_MELLANOX_HERMON_SDR: |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
195 |
case PCI_DEVICE_ID_MELLANOX_HERMON_DDR: |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
196 |
case PCI_DEVICE_ID_MELLANOX_HERMON_QDR: |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
197 |
case PCI_DEVICE_ID_MELLANOX_HERMON_DDR_PCIE2: |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
198 |
case PCI_DEVICE_ID_MELLANOX_HERMON_QDR_PCIE2: |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
199 |
hca_name = CONNECTX_NAME; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
200 |
break; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
201 |
case PCI_DEVICE_ID_MELLANOX_TAVOR: |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
202 |
case PCI_DEVICE_ID_MELLANOX_ARBEL_COMPAT: |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
203 |
case INFINIHOST_DEVICE_ID_2: |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
204 |
case INFINIHOST_DEVICE_ID_4: |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
205 |
hca_name = INFINIHOST_NAME; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
206 |
break; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
207 |
} |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
208 |
} |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
209 |
(void) strcpy(name, hca_name); |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
210 |
} |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
211 |
|
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
212 |
static int |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
213 |
umad_cache_add(uint_t dev_num, int port, char *ibdev, int abi_version) |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
214 |
{ |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
215 |
if ((dev_num >= (MAX_HCAS * MAX_HCA_PORTS)) || |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
216 |
(umad_cache_cnt >= (MAX_HCAS * MAX_HCA_PORTS))) { |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
217 |
fprintf(stderr, "dev %d: exceeds umad cache size\n", dev_num); |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
218 |
return (1); |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
219 |
} |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
220 |
|
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
221 |
umad_dev_cache[dev_num].umc_port = port; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
222 |
umad_dev_cache[dev_num].umc_abi_version = abi_version; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
223 |
strcpy(umad_dev_cache[dev_num].umc_ib_dev, ibdev); |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
224 |
umad_dev_cache[dev_num].umc_valid = 1; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
225 |
umad_cache_cnt++; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
226 |
return (0); |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
227 |
} |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
228 |
|
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
229 |
static int |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
230 |
ibdev_cache_add(uint_t dev_num, ibdev_cache_info_t *info_p) |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
231 |
{ |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
232 |
if ((dev_num >= MAX_HCAS) || (ibdev_cache_cnt >= (MAX_HCAS * 2))) { |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
233 |
fprintf(stderr, "dev %d: exceeds hca cache size\n", dev_num); |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
234 |
return (1); |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
235 |
} |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
236 |
|
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
237 |
if (!(strncmp(info_p->ibd_name, "mlx4", 4))) { |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
238 |
memcpy(&(ibdev_cache[MLX4][dev_num]), info_p, |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
239 |
sizeof (ibdev_cache_info_t)); |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
240 |
ibdev_cache[MLX4][dev_num].ibd_valid = 1; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
241 |
} else { |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
242 |
memcpy(&(ibdev_cache[MTHCA][dev_num]), info_p, |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
243 |
sizeof (ibdev_cache_info_t)); |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
244 |
ibdev_cache[MTHCA][dev_num].ibd_valid = 1; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
245 |
} |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
246 |
|
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
247 |
ibdev_cache_cnt++; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
248 |
return (0); |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
249 |
} |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
250 |
|
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
251 |
static int |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
252 |
uverbs_cache_add(uint_t dev_num, uverbs_cache_info_t *info_p) |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
253 |
{ |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
254 |
if ((dev_num >= MAX_HCAS) || (uverbs_cache_cnt >= MAX_HCAS)) { |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
255 |
fprintf(stderr, "dev %d: exceeds uverbs cache size\n", dev_num); |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
256 |
return (1); |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
257 |
} |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
258 |
|
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
259 |
memcpy(&(uverbs_dev_cache[dev_num]), info_p, |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
260 |
sizeof (uverbs_cache_info_t)); |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
261 |
|
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
262 |
uverbs_dev_cache[dev_num].uvc_valid = 1; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
263 |
uverbs_cache_cnt++; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
264 |
return (0); |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
265 |
} |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
266 |
|
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
267 |
static int |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
268 |
ibdev_cache_init() |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
269 |
{ |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
270 |
ibdev_cache_info_t info; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
271 |
struct ibv_device **root_dev_list, **dev_list = NULL; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
272 |
struct ibv_context *ctx = NULL; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
273 |
struct ibv_device_attr device_attr; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
274 |
int i, num_dev, dev_num, ret = 1; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
275 |
uint64_t guid; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
276 |
const char *p, *ibdev; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
277 |
|
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
278 |
|
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
279 |
root_dev_list = dev_list = ibv_get_device_list(&num_dev); |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
280 |
if (!dev_list) { |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
281 |
fprintf(stderr, "No HCA devices found"); |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
282 |
goto error_exit1; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
283 |
} |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
284 |
|
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
285 |
for (i = 0; i < num_dev; i++, dev_list++) { |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
286 |
|
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
287 |
if (!(ctx = ibv_open_device(*dev_list))) { |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
288 |
fprintf(stderr, "failed to open device %p\n", |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
289 |
*dev_list); |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
290 |
goto error_exit2; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
291 |
} |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
292 |
|
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
293 |
if (ibv_query_device(ctx, &device_attr)) { |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
294 |
fprintf(stderr, "failed to query device %p\n", ctx); |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
295 |
goto error_exit3; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
296 |
} |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
297 |
|
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
298 |
guid = ntohll(device_attr.node_guid); |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
299 |
sprintf(info.ibd_node_guid_str, "%04x:%04x:%04x:%04x", |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
300 |
(unsigned) (guid >> 48) & 0xffff, |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
301 |
(unsigned) (guid >> 32) & 0xffff, |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
302 |
(unsigned) (guid >> 16) & 0xffff, |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
303 |
(unsigned) (guid >> 0) & 0xffff); |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
304 |
|
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
305 |
guid = ntohll(device_attr.sys_image_guid); |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
306 |
sprintf(info.ibd_sys_image_guid, "%04x:%04x:%04x:%04x", |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
307 |
(unsigned) (guid >> 48) & 0xffff, |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
308 |
(unsigned) (guid >> 32) & 0xffff, |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
309 |
(unsigned) (guid >> 16) & 0xffff, |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
310 |
(unsigned) (guid >> 0) & 0xffff); |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
311 |
|
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
312 |
(void) strcpy(info.ibd_fw_ver, device_attr.fw_ver); |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
313 |
info.ibd_hw_rev = device_attr.hw_ver; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
314 |
|
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
315 |
ibdev = ibv_get_device_name(*dev_list); |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
316 |
p = ibdev + (strlen(ibdev)-1); |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
317 |
dev_num = atoi(p); |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
318 |
(void) strcpy(info.ibd_name, ibdev); |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
319 |
|
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
320 |
if (ibdev_cache_add(dev_num, &info)) { |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
321 |
fprintf(stderr, "failed to add dev %d to ibdev cache\n", |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
322 |
dev_num); |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
323 |
goto error_exit3; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
324 |
} |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
325 |
} |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
326 |
|
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
327 |
ret = 0; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
328 |
|
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
329 |
/* clean up and Return */ |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
330 |
error_exit3: |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
331 |
if (ctx) |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
332 |
ibv_close_device(ctx); |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
333 |
error_exit2: |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
334 |
if (root_dev_list) |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
335 |
ibv_free_device_list(root_dev_list); |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
336 |
error_exit1: |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
337 |
return (ret); |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
338 |
} |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
339 |
|
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
340 |
static void |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
341 |
uverbs_cache_init() |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
342 |
{ |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
343 |
uverbs_cache_info_t info; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
344 |
di_node_t node, node_child, hca_node; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
345 |
di_minor_t node_minor; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
346 |
dev_t devt; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
347 |
int64_t *guid, *hca_guid; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
348 |
int *intv; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
349 |
int minor_num, dev_num, hca_type; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
350 |
int mlx4_devs = 0; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
351 |
int mthca_devs = 0; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
352 |
char *p, *minor_str, *path; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
353 |
char ibdev[8]; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
354 |
|
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
355 |
|
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
356 |
if (sol_uverbs_drv_status != SOL_UVERBS_DRV_STATUS_LOADED) { |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
357 |
fprintf(stderr, "sol_uverbs not loaded\n"); |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
358 |
goto error_exit1; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
359 |
} |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
360 |
|
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
361 |
node = di_drv_first_node(UVERBS, root_node); |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
362 |
if (node == DI_NODE_NIL) { |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
363 |
fprintf(stderr, "no sol_verbs device node\n"); |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
364 |
goto error_exit1; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
365 |
} |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
366 |
|
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
367 |
node_minor = di_minor_next(node, DI_MINOR_NIL); |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
368 |
while (node_minor != DI_MINOR_NIL) { |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
369 |
devt = di_minor_devt(node_minor); |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
370 |
minor_num = (devt & 0x0000FFFF); |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
371 |
|
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
372 |
minor_str = di_minor_name(node_minor); |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
373 |
p = minor_str; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
374 |
p = p + (strlen(p)-1); |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
375 |
dev_num = atoi(p); |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
376 |
|
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
377 |
/* minor_num should match uverbs num */ |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
378 |
if (minor_num != dev_num) { |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
379 |
node_minor = di_minor_next(node, node_minor); |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
380 |
continue; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
381 |
} |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
382 |
|
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
383 |
if (di_prop_lookup_ints(devt, node, "vendor-id", &intv) != 1) { |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
384 |
goto error_exit1; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
385 |
} |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
386 |
info.uvc_vendor_id = *intv; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
387 |
|
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
388 |
if (di_prop_lookup_ints(devt, node, "device-id", &intv) != 1) { |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
389 |
goto error_exit1; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
390 |
} |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
391 |
info.uvc_device_id = *intv; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
392 |
|
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
393 |
if (di_prop_lookup_int64(devt, node, "guid", &guid) != 1) { |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
394 |
goto error_exit1; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
395 |
} |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
396 |
|
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
397 |
/* abi version only on minor node 0 */ |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
398 |
if (minor_num == 0) { |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
399 |
if (di_prop_lookup_ints(devt, node, "abi-version", |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
400 |
&intv) != 1) { |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
401 |
goto error_exit1; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
402 |
} |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
403 |
info.uvc_abi_version = *intv; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
404 |
} |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
405 |
|
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
406 |
/* |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
407 |
* Find the HCA device instance that has an ibport child |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
408 |
* with the same GUID as our ibdev. |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
409 |
*/ |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
410 |
vendor_device_id_to_name(info.uvc_vendor_id, info.uvc_device_id, |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
411 |
ibdev); |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
412 |
|
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
413 |
if (!(strncmp(ibdev, "mlx4_", 5))) { |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
414 |
info.uvc_ibdev_abi_version = |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
415 |
MLX4_UVERBS_MAX_ABI_VERSION; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
416 |
sprintf(info.uvc_ibdev_name, "mlx4_%d", mlx4_devs); |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
417 |
mlx4_devs++; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
418 |
hca_type = MLX4; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
419 |
hca_node = di_drv_first_node("hermon", root_node); |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
420 |
} else if (!(strncmp(ibdev, "mthca", 5))) { |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
421 |
sprintf(info.uvc_ibdev_name, "mthca%d", mthca_devs); |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
422 |
mthca_devs++; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
423 |
hca_type = MTHCA; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
424 |
info.uvc_ibdev_abi_version = MTHCA_UVERBS_ABI_VERSION; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
425 |
hca_node = di_drv_first_node("tavor", root_node); |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
426 |
} else { |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
427 |
fprintf(stderr, "Unsupported driver, device %s\n", |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
428 |
ibdev); |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
429 |
goto error_exit1; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
430 |
} |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
431 |
|
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
432 |
while (hca_node != DI_NODE_NIL) { |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
433 |
node_child = di_child_node(hca_node); |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
434 |
|
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
435 |
while (node_child != DI_MINOR_NIL) { |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
436 |
|
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
437 |
if (di_prop_lookup_int64(DDI_DEV_T_ANY, |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
438 |
node_child, "hca-guid", &hca_guid) != 1) { |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
439 |
node_child = |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
440 |
di_sibling_node(node_child); |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
441 |
} else { |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
442 |
break; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
443 |
} |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
444 |
} |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
445 |
|
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
446 |
if (*hca_guid == *guid) { |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
447 |
break; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
448 |
} |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
449 |
hca_node = di_drv_next_node(hca_node); |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
450 |
} |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
451 |
|
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
452 |
if (hca_node == DI_NODE_NIL) { |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
453 |
fprintf(stderr, "Could not find hca hardware driver"); |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
454 |
goto error_exit1; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
455 |
} |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
456 |
|
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
457 |
path = di_devfs_path(hca_node); |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
458 |
strcpy(info.uvc_ibdev_hca_path, path); |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
459 |
di_devfs_path_free(path); |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
460 |
info.uvc_hca_instance = di_instance(hca_node); |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
461 |
|
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
462 |
if (uverbs_cache_add(dev_num, &info)) { |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
463 |
fprintf(stderr, "failed to add dev %d to uverbs " |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
464 |
"cache\n", dev_num); |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
465 |
goto error_exit1; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
466 |
} |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
467 |
|
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
468 |
node_minor = di_minor_next(node, node_minor); |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
469 |
} |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
470 |
|
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
471 |
return; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
472 |
|
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
473 |
error_exit1: |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
474 |
exit(1); |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
475 |
} |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
476 |
|
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
477 |
static void |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
478 |
umad_cache_init() |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
479 |
{ |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
480 |
di_node_t umad_node; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
481 |
di_minor_t minor_node; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
482 |
di_prop_t prop, next; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
483 |
char *minor_str; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
484 |
dev_t dev; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
485 |
int *vendorids, *deviceids, *ports; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
486 |
int *abi_version, *hcas; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
487 |
int dev_num, type, i; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
488 |
char *p, *name; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
489 |
|
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
490 |
|
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
491 |
umad_node = di_drv_first_node("sol_umad", root_node); |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
492 |
if (umad_node == DI_NODE_NIL) { |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
493 |
fprintf(stderr, "no sol_umad device node\n"); |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
494 |
goto error_exit1; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
495 |
} |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
496 |
|
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
497 |
/* |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
498 |
* get sol_umad abi_version property which is a major node proprty. |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
499 |
*/ |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
500 |
if ((next = di_prop_next(umad_node, DI_PROP_NIL)) == DI_PROP_NIL) { |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
501 |
fprintf(stderr, "failed to find sol_umad properties\n"); |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
502 |
goto error_exit1; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
503 |
} |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
504 |
|
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
505 |
while (next != DI_PROP_NIL) { |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
506 |
prop = next; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
507 |
type = di_prop_type(prop); |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
508 |
name = di_prop_name(prop); |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
509 |
|
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
510 |
if (!((type == DI_PROP_TYPE_INT) && |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
511 |
(strcmp(name, "abi_version") == 0))) { |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
512 |
next = di_prop_next(umad_node, prop); |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
513 |
continue; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
514 |
} |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
515 |
if (di_prop_ints(prop, &abi_version) == -1) { |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
516 |
fprintf(stderr, "failed to get sol_umad abi_version\n"); |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
517 |
goto error_exit1; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
518 |
} |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
519 |
break; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
520 |
} |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
521 |
|
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
522 |
minor_node = di_minor_next(umad_node, DI_MINOR_NIL); |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
523 |
while (minor_node != DI_MINOR_NIL) { |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
524 |
minor_str = di_minor_name(minor_node); |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
525 |
|
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
526 |
/* just interested in the umad minors not the issm ones */ |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
527 |
if (strncmp(minor_str, "umad", 4)) { |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
528 |
minor_node = di_minor_next(umad_node, minor_node); |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
529 |
continue; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
530 |
} |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
531 |
dev = di_minor_devt(minor_node); |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
532 |
|
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
533 |
p = minor_str; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
534 |
p = p + (strlen(p)-1); |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
535 |
dev_num = atoi(p); |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
536 |
|
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
537 |
if (di_prop_lookup_ints(dev, umad_node, "vendor-id", |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
538 |
&vendorids) != 1) |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
539 |
goto error_exit1; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
540 |
|
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
541 |
if (di_prop_lookup_ints(dev, umad_node, "device-id", |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
542 |
&deviceids) != 1) |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
543 |
goto error_exit1; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
544 |
|
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
545 |
if (di_prop_lookup_ints(dev, umad_node, "port", &ports) != 1) |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
546 |
goto error_exit1; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
547 |
|
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
548 |
/* |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
549 |
* The uverbs cache entries have a hca instance to ibdev |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
550 |
* name mapping, use that to find the ibdev name |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
551 |
* associated with this hca instance. |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
552 |
*/ |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
553 |
if (di_prop_lookup_ints(dev, umad_node, "hca-instance", |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
554 |
&hcas) != 1) |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
555 |
goto error_exit1; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
556 |
|
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
557 |
if (pthread_mutex_lock(&uverbs_cache_mutex) != 0) { |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
558 |
fprintf(stderr, "failed: to acquire " |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
559 |
"uverbs_cache_mutex %s\n", |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
560 |
strerror(errno)); |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
561 |
goto error_exit1; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
562 |
} |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
563 |
|
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
564 |
if (!uverbs_cache_initialized) { |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
565 |
uverbs_cache_init(); |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
566 |
uverbs_cache_initialized = B_TRUE; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
567 |
} |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
568 |
(void) pthread_mutex_unlock(&uverbs_cache_mutex); |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
569 |
|
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
570 |
for (i = 0; i < MAX_HCAS; i++) { |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
571 |
if (uverbs_dev_cache[i].uvc_valid && |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
572 |
(uverbs_dev_cache[i].uvc_hca_instance == *hcas)) { |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
573 |
break; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
574 |
} |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
575 |
} |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
576 |
|
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
577 |
if (i == MAX_HCAS) { |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
578 |
fprintf(stderr, "failed to find ibdev for %s\n", |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
579 |
minor_str); |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
580 |
goto error_exit1; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
581 |
} |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
582 |
|
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
583 |
if (umad_cache_add(dev_num, *ports, |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
584 |
uverbs_dev_cache[i].uvc_ibdev_name, *abi_version)) { |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
585 |
fprintf(stderr, "failed to add dev %d to umad cache", |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
586 |
dev_num); |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
587 |
goto error_exit1; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
588 |
} |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
589 |
minor_node = di_minor_next(umad_node, minor_node); |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
590 |
} |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
591 |
|
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
592 |
return; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
593 |
error_exit1: |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
594 |
exit(1); |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
595 |
} |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
596 |
|
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
597 |
|
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
598 |
void |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
599 |
initialize(void) |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
600 |
{ |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
601 |
int fd; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
602 |
char uverbs_devpath[MAXPATHLEN]; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
603 |
|
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
604 |
snprintf(uverbs_devpath, MAXPATHLEN, "%s/%s", |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
605 |
UVERBS_IB_DEVPATH_PREFIX, UVERBS_KERNEL_SYSFS_NAME); |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
606 |
|
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
607 |
if ((fd = open(uverbs_devpath, O_RDWR)) < 0) { |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
608 |
fprintf(stderr, "sol_uverbs not loaded: %s\n", strerror(errno)); |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
609 |
sol_uverbs_drv_status = SOL_UVERBS_DRV_STATUS_UNLOADED; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
610 |
exit(1); |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
611 |
} else { |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
612 |
sol_uverbs_drv_status = SOL_UVERBS_DRV_STATUS_LOADED; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
613 |
close(fd); |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
614 |
} |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
615 |
|
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
616 |
memset(&uverbs_dev_cache, 0, (sizeof (uverbs_cache_info_t) * MAX_HCAS)); |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
617 |
memset(&ibdev_cache, 0, (sizeof (ibdev_cache_info_t) * MAX_HCAS * 2)); |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
618 |
memset(&umad_dev_cache, 0, |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
619 |
(sizeof (umad_cache_info_t) * MAX_HCAS * MAX_HCA_PORTS)); |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
620 |
|
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
621 |
initialized = B_TRUE; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
622 |
} |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
623 |
|
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
624 |
/* |
56 | 625 |
* Some sysfs emulation software |
626 |
*/ |
|
627 |
||
628 |
||
58
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
629 |
/* |
56 | 630 |
* Check whether a path starts with prefix, and if it does, remove it |
58
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
631 |
* from the string. The prefix can also contain one %d scan argument. |
56 | 632 |
*/ |
58
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
633 |
static int |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
634 |
check_path(char *path, cp_prefix_t prefix, unsigned int *arg) |
56 | 635 |
{ |
636 |
int ret, pos = 0; |
|
637 |
||
638 |
switch (prefix) { |
|
639 |
case CP_SOL_UVERBS: |
|
640 |
ret = sscanf(path, "sol_uverbs@0:uverbs%d%n/", arg, |
|
58
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
641 |
&pos); |
56 | 642 |
break; |
643 |
case CP_DEVICE: |
|
644 |
ret = sscanf(path, "device%n/", &pos); |
|
645 |
break; |
|
646 |
case CP_D: |
|
647 |
ret = sscanf(path, "%d%n/", arg, &pos); |
|
648 |
break; |
|
649 |
case CP_GIDS: |
|
650 |
ret = sscanf(path, "gids%n/", &pos); |
|
651 |
break; |
|
652 |
case CP_PKEYS: |
|
653 |
ret = sscanf(path, "pkeys%n/", &pos); |
|
654 |
break; |
|
655 |
case CP_MTHCA: |
|
58
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
656 |
ret = sscanf(path, "mthca%d%n/", arg, &pos); |
56 | 657 |
break; |
658 |
case CP_MLX4: |
|
58
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
659 |
ret = sscanf(path, "mlx4_%d%n/", arg, &pos); |
56 | 660 |
break; |
661 |
case CP_PORTS: |
|
662 |
ret = sscanf(path, "ports%n/", &pos); |
|
663 |
break; |
|
664 |
case CP_UMAD: |
|
58
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
665 |
ret = sscanf(path, "umad%d%n/", arg, &pos); |
56 | 666 |
break; |
667 |
case CP_SLASH: |
|
668 |
ret = sscanf(path, "%n/", &pos); |
|
669 |
break; |
|
670 |
case CP_SYS: |
|
671 |
ret = sscanf(path, "sys%n/", &pos); |
|
672 |
break; |
|
673 |
case CP_CLASS: |
|
674 |
ret = sscanf(path, "class%n/", &pos); |
|
675 |
break; |
|
676 |
case CP_INFINIBAND_VERBS: |
|
677 |
ret = sscanf(path, "infiniband_verbs%n/", &pos); |
|
678 |
break; |
|
679 |
case CP_INFINIBAND: |
|
680 |
ret = sscanf(path, "infiniband%n/", &pos); |
|
681 |
break; |
|
682 |
case CP_INFINIBAND_MAD: |
|
683 |
ret = sscanf(path, "infiniband_mad%n/", &pos); |
|
684 |
break; |
|
685 |
case CP_MISC: |
|
686 |
ret = sscanf(path, "misc%n/", &pos); |
|
687 |
break; |
|
688 |
case CP_RDMA_CM: |
|
689 |
ret = sscanf(path, "rdma_cm%n/", &pos); |
|
690 |
break; |
|
691 |
default: |
|
692 |
/* Unkown prefix */ |
|
58
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
693 |
return (0); |
56 | 694 |
} |
695 |
||
696 |
if (path[pos] == '/') { |
|
697 |
/* Some requests have several consecutive slashes. */ |
|
698 |
while (path[pos] == '/') |
|
699 |
pos ++; |
|
700 |
||
701 |
memmove(path, &path[pos], strlen(path)-pos+1); |
|
58
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
702 |
return (1); |
56 | 703 |
} |
704 |
||
58
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
705 |
return (0); |
56 | 706 |
} |
707 |
||
58
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
708 |
static ibdev_cache_info_t * |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
709 |
get_device_info(const char *devname) |
56 | 710 |
{ |
58
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
711 |
ibdev_cache_info_t *info; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
712 |
const char *p = devname; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
713 |
int dev_num; |
56 | 714 |
|
58
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
715 |
if (pthread_mutex_lock(&ibdev_cache_mutex) != 0) { |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
716 |
fprintf(stderr, "failed: to acquire ibdev_cache_mutex %s\n", |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
717 |
strerror(errno)); |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
718 |
exit(1); |
56 | 719 |
} |
720 |
||
58
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
721 |
if (!ibdev_cache_initialized) { |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
722 |
if (ibdev_cache_init()) { |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
723 |
(void) pthread_mutex_unlock(&ibdev_cache_mutex); |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
724 |
fprintf(stderr, "failed to init ibdev_cache\n"); |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
725 |
exit(1); |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
726 |
} else { |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
727 |
ibdev_cache_initialized = B_TRUE; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
728 |
} |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
729 |
} |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
730 |
(void) pthread_mutex_unlock(&ibdev_cache_mutex); |
56 | 731 |
|
58
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
732 |
p = p+(strlen(p)-1); |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
733 |
dev_num = atoi(p); |
56 | 734 |
|
58
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
735 |
if (dev_num >= MAX_HCAS) { |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
736 |
fprintf(stderr, "Invalid device %s\n", devname); |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
737 |
return (NULL); |
56 | 738 |
} |
739 |
||
58
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
740 |
if (strncmp(devname, "mlx4", 4) == 0) { |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
741 |
if (ibdev_cache[MLX4][dev_num].ibd_valid) |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
742 |
info = &(ibdev_cache[MLX4][dev_num]); |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
743 |
else |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
744 |
info = NULL; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
745 |
} else { |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
746 |
if (ibdev_cache[MTHCA][dev_num].ibd_valid) |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
747 |
info = &(ibdev_cache[MTHCA][dev_num]); |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
748 |
else |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
749 |
info = NULL; |
56 | 750 |
} |
751 |
||
58
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
752 |
return (info); |
56 | 753 |
} |
754 |
||
755 |
/* |
|
756 |
* Get the IB user verbs port info attributes for the specified device/port. |
|
757 |
* If the address of a gid pointer is passed for "gid_table", the memory |
|
58
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
758 |
* will be allocated and the ports gid table and returned as well. The caller |
56 | 759 |
* must free this memory on successful completion. If the address of a |
760 |
* pkey pointer is passed for "pkey_table", the memory will be allocated |
|
761 |
* and the ports pkey table returned as well. The caller must free this |
|
762 |
* memory on successful completion. |
|
763 |
*/ |
|
58
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
764 |
static int |
56 | 765 |
get_port_info(const char *devname, uint8_t port_num, |
58
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
766 |
struct ibv_port_attr *port_attr, union ibv_gid **gid_table, |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
767 |
uint16_t **pkey_table) |
56 | 768 |
{ |
58
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
769 |
struct ibv_device **root_dev_list, **dev_list = NULL; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
770 |
struct ibv_context *ctx = NULL; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
771 |
union ibv_gid *gids = NULL; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
772 |
uint16_t *pkeys = NULL; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
773 |
int i, num_dev, rv, ret = 1; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
774 |
|
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
775 |
root_dev_list = dev_list = ibv_get_device_list(&num_dev); |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
776 |
if (!dev_list) { |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
777 |
fprintf(stderr, "No HCA devices found\n"); |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
778 |
goto error_exit1; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
779 |
} |
56 | 780 |
|
58
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
781 |
for (i = 0; i < num_dev; i++, dev_list++) { |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
782 |
if (strcmp(ibv_get_device_name(*dev_list), devname) == 0) { |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
783 |
break; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
784 |
} |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
785 |
} |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
786 |
|
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
787 |
if (i == num_dev) { |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
788 |
fprintf(stderr, "failed to find %s\n", devname); |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
789 |
goto error_exit2; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
790 |
} |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
791 |
|
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
792 |
if (!(ctx = ibv_open_device(*dev_list))) { |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
793 |
fprintf(stderr, "failed to open device %p\n", *dev_list); |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
794 |
goto error_exit2; |
56 | 795 |
} |
796 |
||
797 |
if (ibv_query_port(ctx, port_num, port_attr)) { |
|
58
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
798 |
fprintf(stderr, "failed to query dev %p, port %d\n", |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
799 |
ctx, port_num); |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
800 |
goto error_exit3; |
56 | 801 |
} |
802 |
||
803 |
if (gid_table) { |
|
804 |
*gid_table = NULL; |
|
58
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
805 |
gids = malloc(sizeof (union ibv_gid) * port_attr->gid_tbl_len); |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
806 |
if (!gids) |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
807 |
goto error_exit3; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
808 |
/* |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
809 |
* set high bit of port_num, and try get all gids in one go. |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
810 |
*/ |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
811 |
port_num |= 0x80; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
812 |
rv = ibv_query_gid(ctx, port_num, port_attr->gid_tbl_len, gids); |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
813 |
|
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
814 |
if (rv != 0) { |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
815 |
/* |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
816 |
* Quering all gids didn't work try one at a time. |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
817 |
*/ |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
818 |
port_num &= 0x7f; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
819 |
|
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
820 |
for (i = 0; i < port_attr->gid_tbl_len; i++) { |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
821 |
if (ibv_query_gid(ctx, port_num, i, &gids[i])) |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
822 |
goto error_exit4; |
56 | 823 |
} |
824 |
} |
|
825 |
*gid_table = gids; |
|
826 |
gids = NULL; |
|
827 |
} |
|
828 |
||
829 |
if (pkey_table) { |
|
830 |
*pkey_table = NULL; |
|
58
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
831 |
pkeys = malloc(sizeof (uint16_t) * port_attr->pkey_tbl_len); |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
832 |
if (!pkeys) |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
833 |
goto error_exit4; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
834 |
|
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
835 |
port_num |= 0x80; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
836 |
|
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
837 |
rv = ibv_query_pkey(ctx, port_num, port_attr->pkey_tbl_len, |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
838 |
pkeys); |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
839 |
|
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
840 |
if (rv != 0) { |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
841 |
/* |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
842 |
* Quering all gids didn't work try one at a time. |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
843 |
*/ |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
844 |
port_num &= 0x7f; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
845 |
|
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
846 |
for (i = 0; i < port_attr->pkey_tbl_len; i++) { |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
847 |
if (ibv_query_pkey(ctx, port_num, i, &pkeys[i])) |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
848 |
goto error_exit5; |
56 | 849 |
} |
850 |
} |
|
851 |
*pkey_table = pkeys; |
|
852 |
pkeys = NULL; |
|
853 |
} |
|
854 |
||
855 |
ret = 0; |
|
856 |
||
58
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
857 |
/* |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
858 |
* clean up and Return |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
859 |
*/ |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
860 |
error_exit5: |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
861 |
if (pkeys) |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
862 |
free(pkeys); |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
863 |
error_exit4: |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
864 |
if (gids) |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
865 |
free(gids); |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
866 |
error_exit3: |
56 | 867 |
if (ctx) |
868 |
ibv_close_device(ctx); |
|
58
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
869 |
error_exit2: |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
870 |
if (root_dev_list) |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
871 |
ibv_free_device_list(root_dev_list); |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
872 |
error_exit1: |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
873 |
return (ret); |
56 | 874 |
} |
875 |
||
876 |
/* |
|
877 |
* In Solaris environments, the underlying hardware driver is opened to |
|
878 |
* perform the memory mapping operations of kernel allocated memory |
|
879 |
* into the users address space. |
|
880 |
*/ |
|
58
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
881 |
int |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
882 |
ibv_open_mmap_driver(char *dev_name) |
56 | 883 |
{ |
58
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
884 |
int fd; |
56 | 885 |
#ifndef _LP64 |
58
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
886 |
int tmpfd; |
56 | 887 |
#endif |
58
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
888 |
char *dev_path; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
889 |
char path_buf[MAXPATHLEN]; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
890 |
int uverbs_minor; |
56 | 891 |
|
58
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
892 |
/* |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
893 |
* Map the user verbs device (uverbs) to the associated IBD interface |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
894 |
* to determine the hardware driver. To avoid ordering issues, we use |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
895 |
* associated GUID to perform the mapping. |
56 | 896 |
*/ |
58
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
897 |
uverbs_minor = strtol(dev_name + strlen(UVERBS_KERNEL_SYSFS_NAME) - 1, |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
898 |
NULL, 0); |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
899 |
if (uverbs_minor >= MAX_HCAS) { |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
900 |
fprintf(stderr, "Invalid device %s\n", dev_name); |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
901 |
goto err_dev; |
56 | 902 |
} |
903 |
||
58
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
904 |
if (!uverbs_dev_cache[uverbs_minor].uvc_valid) { |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
905 |
fprintf(stderr, "Invalid Device %s\n", dev_name); |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
906 |
goto err_dev; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
907 |
} |
56 | 908 |
|
58
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
909 |
dev_path = uverbs_dev_cache[uverbs_minor].uvc_ibdev_hca_path; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
910 |
strncpy(path_buf, "/devices", sizeof (path_buf)); |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
911 |
strncat(path_buf, dev_path, sizeof (path_buf)); |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
912 |
strncat(path_buf, ":devctl", sizeof (path_buf)); |
56 | 913 |
|
58
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
914 |
fd = open(path_buf, O_RDWR); |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
915 |
if (fd < 0) { |
56 | 916 |
goto err_dev; |
917 |
} |
|
918 |
||
58
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
919 |
#ifndef _LP64 |
56 | 920 |
/* |
58
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
921 |
* libc can't handle fd's greater than 255, in order to |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
922 |
* ensure that these values remain available make fd > 255. |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
923 |
* Note: not needed for LP64 |
56 | 924 |
*/ |
58
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
925 |
tmpfd = fcntl(fd, F_DUPFD, 256); |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
926 |
if (tmpfd >= 0) { |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
927 |
(void) close(fd); |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
928 |
fd = tmpfd; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
929 |
} |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
930 |
#endif /* _LP64 */ |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
931 |
|
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
932 |
if (fcntl(fd, F_SETFD, FD_CLOEXEC) < 0) { |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
933 |
fprintf(stderr, "FD_CLOEXEC failed: %s\n", strerror(errno)); |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
934 |
goto err_close; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
935 |
} |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
936 |
return (fd); |
56 | 937 |
|
58
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
938 |
err_close: |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
939 |
close(fd); |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
940 |
err_dev: |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
941 |
return (-1); |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
942 |
} |
56 | 943 |
|
58
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
944 |
static int |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
945 |
infiniband_verbs(char *path, char *buf, size_t size) |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
946 |
{ |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
947 |
unsigned int device_num; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
948 |
int len = -1; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
949 |
uverbs_cache_info_t *info_p; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
950 |
|
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
951 |
if (pthread_mutex_lock(&uverbs_cache_mutex) != 0) { |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
952 |
fprintf(stderr, "failed: to acquire uverbs_cache_mutex %s\n", |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
953 |
strerror(errno)); |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
954 |
exit(1); |
56 | 955 |
} |
956 |
||
58
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
957 |
if (!uverbs_cache_initialized) { |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
958 |
uverbs_cache_init(); |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
959 |
uverbs_cache_initialized = B_TRUE; |
56 | 960 |
} |
58
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
961 |
(void) pthread_mutex_unlock(&uverbs_cache_mutex); |
56 | 962 |
|
963 |
if (check_path(path, CP_SOL_UVERBS, &device_num)) { |
|
964 |
||
58
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
965 |
if (device_num >= MAX_HCAS) { |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
966 |
fprintf(stderr, "Invalid path%s\n", path); |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
967 |
goto exit; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
968 |
} |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
969 |
|
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
970 |
if (!uverbs_dev_cache[device_num].uvc_valid) { |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
971 |
fprintf(stderr, "Invalid Device %s\n", path); |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
972 |
goto exit; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
973 |
} |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
974 |
|
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
975 |
info_p = &uverbs_dev_cache[device_num]; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
976 |
|
56 | 977 |
if (check_path(path, CP_DEVICE, NULL)) { |
978 |
/* |
|
979 |
* Under Linux, this is a link to the PCI device entry |
|
58
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
980 |
* in /sys/devices/pci...../.... |
56 | 981 |
*/ |
982 |
if (strcmp(path, "vendor") == 0) { |
|
983 |
len = 1 + sprintf(buf, "0x%x", |
|
58
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
984 |
info_p->uvc_vendor_id); |
56 | 985 |
} else if (strcmp(path, "device") == 0) { |
986 |
len = 1 + sprintf(buf, "0x%x", |
|
58
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
987 |
info_p->uvc_device_id); |
56 | 988 |
} |
58
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
989 |
} else if (strcmp(path, "ibdev") == 0) { |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
990 |
len = 1 + sprintf(buf, "%s", |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
991 |
info_p->uvc_ibdev_name); |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
992 |
} else if (strcmp(path, "abi_version") == 0) { |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
993 |
len = 1 + sprintf(buf, "%d", |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
994 |
info_p->uvc_ibdev_abi_version); |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
995 |
} |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
996 |
} else if (strcmp(path, "abi_version") == 0) { |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
997 |
|
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
998 |
if (!uverbs_dev_cache[0].uvc_valid) { |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
999 |
fprintf(stderr, "Invalid Device %s\n", path); |
56 | 1000 |
goto exit; |
1001 |
} |
|
1002 |
||
58
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
1003 |
info_p = &uverbs_dev_cache[0]; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
1004 |
len = 1 + sprintf(buf, "%d", info_p->uvc_abi_version); |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
1005 |
} else { |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
1006 |
fprintf(stderr, "Unsupported read: %s\n", path); |
56 | 1007 |
} |
1008 |
exit: |
|
58
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
1009 |
return (len); |
56 | 1010 |
} |
1011 |
||
58
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
1012 |
static int |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
1013 |
infiniband_ports(char *path, char *buf, size_t size, char *dev_name) |
56 | 1014 |
{ |
1015 |
int len = -1; |
|
1016 |
unsigned int port_num; |
|
1017 |
unsigned int gid_num; |
|
1018 |
union ibv_gid *gids; |
|
1019 |
uint64_t subnet_prefix; |
|
1020 |
uint64_t interface_id; |
|
1021 |
uint16_t *pkeys; |
|
1022 |
unsigned int pkey_num; |
|
1023 |
struct ibv_port_attr port_attr; |
|
1024 |
float rate; |
|
1025 |
||
1026 |
if (!(check_path(path, CP_D, &port_num))) |
|
1027 |
goto exit; |
|
1028 |
||
1029 |
if (check_path(path, CP_GIDS, NULL)) { |
|
1030 |
if (get_port_info(dev_name, port_num, &port_attr, &gids, NULL)) |
|
1031 |
goto exit; |
|
58
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
1032 |
|
56 | 1033 |
gid_num = atoi(path); |
1034 |
||
1035 |
if (gid_num < port_attr.gid_tbl_len) { |
|
1036 |
||
1037 |
subnet_prefix = |
|
1038 |
htonll(gids[gid_num].global.subnet_prefix); |
|
1039 |
interface_id = |
|
1040 |
htonll(gids[gid_num].global.interface_id); |
|
1041 |
len = 1 + sprintf(buf, |
|
58
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
1042 |
"%04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x", |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
1043 |
(unsigned) (subnet_prefix >> 48) & 0xffff, |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
1044 |
(unsigned) (subnet_prefix >> 32) & 0xffff, |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
1045 |
(unsigned) (subnet_prefix >> 16) & 0xffff, |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
1046 |
(unsigned) (subnet_prefix >> 0) & 0xffff, |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
1047 |
(unsigned) (interface_id >> 48) & 0xffff, |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
1048 |
(unsigned) (interface_id >> 32) & 0xffff, |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
1049 |
(unsigned) (interface_id >> 16) & 0xffff, |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
1050 |
(unsigned) (interface_id >> 0) & 0xffff); |
56 | 1051 |
} |
1052 |
if (gids) |
|
1053 |
free(gids); |
|
58
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
1054 |
|
56 | 1055 |
} else if (check_path(path, CP_PKEYS, NULL)) { |
1056 |
if (get_port_info(dev_name, port_num, &port_attr, NULL, &pkeys)) |
|
1057 |
goto exit; |
|
1058 |
||
1059 |
pkey_num = atoi(path); |
|
58
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
1060 |
if (pkey_num < port_attr.pkey_tbl_len) |
56 | 1061 |
len = 1 + sprintf(buf, "0x%04x", pkeys[pkey_num]); |
58
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
1062 |
|
56 | 1063 |
if (pkeys) |
1064 |
free(pkeys); |
|
1065 |
} else { |
|
1066 |
||
1067 |
if (get_port_info(dev_name, port_num, &port_attr, NULL, NULL)) |
|
1068 |
goto exit; |
|
58
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
1069 |
|
56 | 1070 |
if (strcmp(path, "lid_mask_count") == 0) { |
1071 |
len = 1 + sprintf(buf, "%d", port_attr.lmc); |
|
1072 |
} else if (strcmp(path, "sm_lid") == 0) { |
|
1073 |
len = 1 + sprintf(buf, "0x%x", port_attr.sm_lid); |
|
1074 |
} else if (strcmp(path, "sm_sl") == 0) { |
|
1075 |
len = 1 + sprintf(buf, "%d", port_attr.sm_sl); |
|
1076 |
} else if (strcmp(path, "lid") == 0) { |
|
1077 |
len = 1 + sprintf(buf, "0x%x", port_attr.lid); |
|
1078 |
} else if (strcmp(path, "state") == 0) { |
|
58
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
1079 |
switch (port_attr.state) { |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
1080 |
case IBV_PORT_NOP: |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
1081 |
len = 1 + sprintf(buf, "%d: NOP", |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
1082 |
port_attr.state); |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
1083 |
break; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
1084 |
case IBV_PORT_DOWN: |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
1085 |
len = 1 + sprintf(buf, "%d: DOWN", |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
1086 |
port_attr.state); |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
1087 |
break; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
1088 |
case IBV_PORT_INIT: |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
1089 |
len = 1 + sprintf(buf, "%d: INIT", |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
1090 |
port_attr.state); |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
1091 |
break; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
1092 |
case IBV_PORT_ARMED: |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
1093 |
len = 1 + sprintf(buf, "%d: ARMED", |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
1094 |
port_attr.state); |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
1095 |
break; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
1096 |
case IBV_PORT_ACTIVE: |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
1097 |
len = 1 + sprintf(buf, "%d: ACTIVE", |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
1098 |
port_attr.state); |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
1099 |
break; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
1100 |
case IBV_PORT_ACTIVE_DEFER: |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
1101 |
len = 1 + sprintf(buf, |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
1102 |
"%d: ACTIVE_DEFER", |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
1103 |
port_attr.state); |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
1104 |
break; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
1105 |
default: |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
1106 |
len = 1 + sprintf(buf, "%d: INVALID", |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
1107 |
port_attr.state); |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
1108 |
break; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
1109 |
} |
56 | 1110 |
} else if (strcmp(path, "phys_state") == 0) { |
58
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
1111 |
switch (port_attr.phys_state) { |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
1112 |
case 1: |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
1113 |
len = 1 + sprintf(buf, "%d: Sleep", |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
1114 |
port_attr.phys_state); |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
1115 |
break; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
1116 |
case 2: |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
1117 |
len = 1 + sprintf(buf, "%d: Polling", |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
1118 |
port_attr.phys_state); |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
1119 |
break; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
1120 |
case 3: |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
1121 |
len = 1 + sprintf(buf, "%d: Disabled", |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
1122 |
port_attr.phys_state); |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
1123 |
break; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
1124 |
case 4: |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
1125 |
len = 1 + sprintf(buf, |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
1126 |
"%d: PortConfigurationTraining", |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
1127 |
port_attr.phys_state); |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
1128 |
break; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
1129 |
case 5: |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
1130 |
len = 1 + sprintf(buf, "%d: LinkUp", |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
1131 |
port_attr.phys_state); |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
1132 |
break; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
1133 |
case 6: |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
1134 |
len = 1 + sprintf(buf, |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
1135 |
"%d: LinkErrorRecovery", |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
1136 |
port_attr.phys_state); |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
1137 |
break; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
1138 |
case 7: |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
1139 |
len = 1 + sprintf(buf, |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
1140 |
"%d: Phy Test", |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
1141 |
port_attr.phys_state); |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
1142 |
break; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
1143 |
default: |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
1144 |
len = 1 + sprintf(buf, "%d: <unknown>", |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
1145 |
port_attr.phys_state); |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
1146 |
break; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
1147 |
} |
56 | 1148 |
} else if (strcmp(path, "rate") == 0) { |
1149 |
/* rate = speed * width */ |
|
1150 |
switch (port_attr.active_speed) { |
|
1151 |
case 1: |
|
1152 |
rate = 2.5; |
|
1153 |
break; |
|
1154 |
case 2: |
|
1155 |
rate = 5; |
|
1156 |
break; |
|
1157 |
case 4: |
|
1158 |
rate = 10; |
|
1159 |
break; |
|
1160 |
default: |
|
1161 |
rate = 0; |
|
1162 |
} |
|
1163 |
switch (port_attr.active_width) { |
|
1164 |
case 1: |
|
1165 |
break; |
|
1166 |
case 2: |
|
1167 |
rate = 4 * rate; |
|
1168 |
break; |
|
1169 |
case 4: |
|
1170 |
rate = 8 * rate; |
|
1171 |
break; |
|
1172 |
case 8: |
|
1173 |
rate = 12 * rate; |
|
1174 |
break; |
|
1175 |
default: |
|
1176 |
rate = 0; |
|
1177 |
} |
|
1178 |
len = 1 + sprintf(buf, "%f", rate); |
|
1179 |
} else if (strcmp(path, "cap_mask") == 0) { |
|
1180 |
len = 1 + sprintf(buf, "0x%08x", |
|
1181 |
port_attr.port_cap_flags); |
|
1182 |
} |
|
1183 |
} |
|
1184 |
exit: |
|
1185 |
return (len); |
|
1186 |
} |
|
1187 |
||
58
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
1188 |
static int |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
1189 |
infiniband(char *path, char *buf, size_t size) |
56 | 1190 |
{ |
1191 |
int len = -1; |
|
1192 |
unsigned int device_num; |
|
1193 |
char dev_name[10]; |
|
58
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
1194 |
ibdev_cache_info_t *info; |
56 | 1195 |
|
1196 |
memset(dev_name, 0, 10); |
|
58
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
1197 |
|
56 | 1198 |
if (check_path(path, CP_MTHCA, &device_num)) { |
1199 |
sprintf(dev_name, "mthca%d", device_num); |
|
1200 |
} else if (check_path(path, CP_MLX4, &device_num)) { |
|
1201 |
sprintf(dev_name, "mlx4_%d", device_num); |
|
1202 |
} else { |
|
1203 |
goto exit; |
|
1204 |
} |
|
1205 |
||
1206 |
if (check_path(path, CP_PORTS, NULL)) { |
|
1207 |
len = infiniband_ports(path, buf, size, dev_name); |
|
1208 |
} else if (strcmp(path, "node_type") == 0) { |
|
1209 |
len = 1 + sprintf(buf, "%d", IBV_NODE_CA); |
|
1210 |
} else if (strcmp(path, "board_id") == 0) { |
|
1211 |
len = 1 + sprintf(buf, "unknown"); |
|
1212 |
} else { |
|
58
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
1213 |
if (!(info = get_device_info(dev_name))) |
56 | 1214 |
goto exit; |
1215 |
||
1216 |
if (strcmp(path, "node_guid") == 0) { |
|
58
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
1217 |
len = 1 + sprintf(buf, "%s", info->ibd_node_guid_str); |
56 | 1218 |
} else if (strcmp(path, "sys_image_guid") == 0) { |
58
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
1219 |
len = 1 + sprintf(buf, "%s", info->ibd_sys_image_guid); |
56 | 1220 |
} else if (strcmp(path, "fw_ver") == 0) { |
58
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
1221 |
len = 1 + sprintf(buf, "%s", info->ibd_fw_ver); |
56 | 1222 |
} else if (strcmp(path, "hw_rev") == 0) { |
58
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
1223 |
len = 1 + sprintf(buf, "%d", info->ibd_hw_rev); |
56 | 1224 |
} else if (strcmp(path, "hca_type") == 0) { |
58
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
1225 |
if (!(strncmp(info->ibd_name, "mlx4", 4))) |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
1226 |
len = 1 + sprintf(buf, "%d", 0); |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
1227 |
else |
56 | 1228 |
len = 1 + sprintf(buf, "unavailable"); |
1229 |
} |
|
1230 |
} |
|
1231 |
exit: |
|
1232 |
return (len); |
|
1233 |
} |
|
1234 |
||
58
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
1235 |
static int |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
1236 |
infiniband_mad(char *path, char *buf, size_t size) |
56 | 1237 |
{ |
1238 |
int len = -1; |
|
58
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
1239 |
unsigned int dev_num; |
56 | 1240 |
|
58
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
1241 |
if (pthread_mutex_lock(&umad_cache_mutex) != 0) { |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
1242 |
fprintf(stderr, "failed: to acquire umad_cache_mutex %s\n", |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
1243 |
strerror(errno)); |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
1244 |
exit(1); |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
1245 |
} |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
1246 |
if (!umad_cache_initialized) { |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
1247 |
umad_cache_init(); |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
1248 |
umad_cache_initialized = B_TRUE; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
1249 |
} |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
1250 |
(void) pthread_mutex_unlock(&umad_cache_mutex); |
56 | 1251 |
|
58
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
1252 |
if (check_path(path, CP_UMAD, &dev_num)) { |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
1253 |
if (dev_num >= MAX_HCAS * MAX_HCA_PORTS) { |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
1254 |
fprintf(stderr, "Invalid Path: %s\n", path); |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
1255 |
goto exit; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
1256 |
} |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
1257 |
if (!umad_dev_cache[dev_num].umc_valid) { |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
1258 |
fprintf(stderr, "Invalid Device: %s\n", path); |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
1259 |
goto exit; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
1260 |
} |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
1261 |
if (strcmp(path, "ibdev") == 0) { |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
1262 |
len = strlcpy(buf, umad_dev_cache[dev_num].umc_ib_dev, |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
1263 |
size) + 1; |
56 | 1264 |
} else if (strcmp(path, "port") == 0) { |
58
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
1265 |
len = 1 + sprintf(buf, "%d", |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
1266 |
umad_dev_cache[dev_num].umc_port); |
56 | 1267 |
} |
1268 |
} else if (strcmp(path, "abi_version") == 0) { |
|
58
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
1269 |
if (!umad_dev_cache[0].umc_valid) { |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
1270 |
fprintf(stderr, "Invalid Device: %s\n", path); |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
1271 |
goto exit; |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
1272 |
} |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
1273 |
len = |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
1274 |
1 + sprintf(buf, "%d", umad_dev_cache[0].umc_abi_version); |
56 | 1275 |
} |
58
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
1276 |
exit: |
56 | 1277 |
return (len); |
1278 |
} |
|
1279 |
||
58
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
1280 |
/* |
56 | 1281 |
* Return -1 on error, or the length of the data (buf) on success. |
1282 |
*/ |
|
58
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
1283 |
int |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
1284 |
sol_read_sysfs_file(char *path, char *buf, size_t size) |
56 | 1285 |
{ |
1286 |
int len = -1; |
|
1287 |
||
58
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
1288 |
if (!initialized) |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
1289 |
if (pthread_once(&oneTimeInit, initialize)) { |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
1290 |
fprintf(stderr, "failed to initialize: %s\n", |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
1291 |
strerror(errno)); |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
1292 |
exit(1); |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
1293 |
} |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
1294 |
|
56 | 1295 |
if (!check_path(path, CP_SLASH, NULL)) |
1296 |
goto exit; |
|
1297 |
||
1298 |
if (!check_path(path, CP_SYS, NULL)) |
|
1299 |
goto exit; |
|
1300 |
||
1301 |
if (!check_path(path, CP_CLASS, NULL)) |
|
1302 |
goto exit; |
|
1303 |
||
1304 |
if (check_path(path, CP_INFINIBAND_VERBS, NULL)) { |
|
1305 |
len = infiniband_verbs(path, buf, size); |
|
1306 |
} else if (check_path(path, CP_INFINIBAND, NULL)) { |
|
1307 |
len = infiniband(path, buf, size); |
|
1308 |
} else if (check_path(path, CP_INFINIBAND_MAD, NULL)) { |
|
1309 |
len = infiniband_mad(path, buf, size); |
|
1310 |
} else if (check_path(path, CP_MISC, NULL)) { |
|
1311 |
if (check_path(path, CP_RDMA_CM, NULL)) { |
|
1312 |
if (strcmp(path, "abi_version") == 0) { |
|
1313 |
len = 1 + sprintf(buf, "%d", |
|
1314 |
RDMA_USER_CM_MAX_ABI_VERSION); |
|
1315 |
} |
|
58
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
1316 |
} |
56 | 1317 |
} |
58
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
1318 |
exit: |
2605957be88f
Import sfw build 155
Cyril Plisko <cyril.plisko@grigale.com>
parents:
56
diff
changeset
|
1319 |
return (len); |
56 | 1320 |
} |
1321 |
#endif |