| 1 |
/* |
| 2 |
* Copyright (c) 2013. Intel Corporation. All rights reserved. |
| 3 |
* Copyright (c) 2006-2012. QLogic Corporation. All rights reserved. |
| 4 |
* Copyright (c) 2003-2006, PathScale, Inc. All rights reserved. |
| 5 |
* |
| 6 |
* This software is available to you under a choice of one of two |
| 7 |
* licenses. You may choose to be licensed under the terms of the GNU |
| 8 |
* General Public License (GPL) Version 2, available from the file |
| 9 |
* COPYING in the main directory of this source tree, or the |
| 10 |
* OpenIB.org BSD license below: |
| 11 |
* |
| 12 |
* Redistribution and use in source and binary forms, with or |
| 13 |
* without modification, are permitted provided that the following |
| 14 |
* conditions are met: |
| 15 |
* |
| 16 |
* - Redistributions of source code must retain the above |
| 17 |
* copyright notice, this list of conditions and the following |
| 18 |
* disclaimer. |
| 19 |
* |
| 20 |
* - Redistributions in binary form must reproduce the above |
| 21 |
* copyright notice, this list of conditions and the following |
| 22 |
* disclaimer in the documentation and/or other materials |
| 23 |
* provided with the distribution. |
| 24 |
* |
| 25 |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 26 |
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 27 |
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 28 |
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS |
| 29 |
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN |
| 30 |
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| 31 |
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 32 |
* SOFTWARE. |
| 33 |
*/ |
| 34 |
|
| 35 |
#include <sys/types.h> |
| 36 |
#include <sys/stat.h> |
| 37 |
#include <fcntl.h> |
| 38 |
#include "psm_user.h" |
| 39 |
#include "ipserror.h" |
| 40 |
#include "ips_proto.h" |
| 41 |
#include "ips_proto_internal.h" |
| 42 |
|
| 43 |
static void |
| 44 |
ips_gen_ipd_table(struct ips_proto *proto) |
| 45 |
{ |
| 46 |
/* Based on our current link rate setup the IPD table */ |
| 47 |
switch(proto->epinfo.ep_link_rate) { |
| 48 |
case IBTA_RATE_10_GBPS: |
| 49 |
proto->ips_ipd_delay[IBTA_RATE_10_GBPS] = 0; |
| 50 |
proto->ips_ipd_delay[IBTA_RATE_5_GBPS] = 1; |
| 51 |
proto->ips_ipd_delay[IBTA_RATE_2_5_GBPS] = 3; |
| 52 |
break; |
| 53 |
case IBTA_RATE_20_GBPS: |
| 54 |
proto->ips_ipd_delay[IBTA_RATE_20_GBPS] = 0; |
| 55 |
proto->ips_ipd_delay[IBTA_RATE_10_GBPS] = 1; |
| 56 |
proto->ips_ipd_delay[IBTA_RATE_5_GBPS] = 3; |
| 57 |
proto->ips_ipd_delay[IBTA_RATE_2_5_GBPS] = 7; |
| 58 |
break; |
| 59 |
case IBTA_RATE_40_GBPS: |
| 60 |
default: |
| 61 |
proto->ips_ipd_delay[IBTA_RATE_40_GBPS] = 0; |
| 62 |
proto->ips_ipd_delay[IBTA_RATE_30_GBPS] = 1; |
| 63 |
proto->ips_ipd_delay[IBTA_RATE_20_GBPS] = 1; |
| 64 |
proto->ips_ipd_delay[IBTA_RATE_10_GBPS] = 3; |
| 65 |
proto->ips_ipd_delay[IBTA_RATE_5_GBPS] = 7; |
| 66 |
proto->ips_ipd_delay[IBTA_RATE_2_5_GBPS] = 15; |
| 67 |
break; |
| 68 |
} |
| 69 |
} |
| 70 |
|
| 71 |
static psm_error_t |
| 72 |
ips_gen_cct_table(struct ips_proto *proto) |
| 73 |
{ |
| 74 |
psm_error_t err = PSM_OK; |
| 75 |
uint32_t cca_divisor, ipdidx, ipdval = 1; |
| 76 |
uint16_t *cct_table; |
| 77 |
|
| 78 |
/* The CCT table is static currently. If it's already created then return */ |
| 79 |
if (proto->cct) |
| 80 |
goto fail; |
| 81 |
|
| 82 |
/* Allocate the CCT table */ |
| 83 |
cct_table = psmi_calloc(proto->ep, UNDEFINED, |
| 84 |
proto->ccti_size, sizeof(uint16_t)); |
| 85 |
if (!cct_table) { |
| 86 |
err = PSM_NO_MEMORY; |
| 87 |
goto fail; |
| 88 |
} |
| 89 |
|
| 90 |
/* The first table entry is always 0 i.e. no IPD delay */ |
| 91 |
cct_table[0] = 0; |
| 92 |
|
| 93 |
/* Generate the remaining CCT table entries */ |
| 94 |
for (ipdidx = 1; ipdidx < proto->ccti_size; ipdidx += 4,ipdval++) |
| 95 |
for (cca_divisor = 0; cca_divisor < 4; cca_divisor++) { |
| 96 |
if ((ipdidx+cca_divisor) == proto->ccti_size) break; |
| 97 |
cct_table[ipdidx+cca_divisor] = |
| 98 |
(((cca_divisor ^ 0x3) << CCA_DIVISOR_SHIFT) | (ipdval & 0x3FFF)); |
| 99 |
_IPATH_VDBG("CCT[%d] = %x. Divisor: %x, IPD: %x\n", ipdidx+cca_divisor, cct_table[ipdidx+cca_divisor], (cct_table[ipdidx+cca_divisor] >> CCA_DIVISOR_SHIFT), cct_table[ipdidx+cca_divisor] & CCA_IPD_MASK); |
| 100 |
} |
| 101 |
|
| 102 |
/* On link up/down CCT is re-generated. If CCT table is previously created |
| 103 |
* free it |
| 104 |
*/ |
| 105 |
if (proto->cct) { |
| 106 |
psmi_free(proto->cct); |
| 107 |
proto->cct = NULL; |
| 108 |
} |
| 109 |
|
| 110 |
/* Update to the new CCT table */ |
| 111 |
proto->cct = cct_table; |
| 112 |
|
| 113 |
fail: |
| 114 |
return err; |
| 115 |
} |
| 116 |
|
| 117 |
static ibta_rate |
| 118 |
ips_default_hca_rate(uint16_t hca_type) |
| 119 |
{ |
| 120 |
ibta_rate rate = IBTA_RATE_40_GBPS; |
| 121 |
|
| 122 |
switch(hca_type){ |
| 123 |
case PSMI_HCA_TYPE_QLE73XX: |
| 124 |
rate = IBTA_RATE_40_GBPS; |
| 125 |
break; |
| 126 |
case PSMI_HCA_TYPE_QLE72XX: |
| 127 |
rate = IBTA_RATE_20_GBPS; |
| 128 |
break; |
| 129 |
case PSMI_HCA_TYPE_QLE71XX: |
| 130 |
rate = IBTA_RATE_10_GBPS; |
| 131 |
break; |
| 132 |
} |
| 133 |
|
| 134 |
return rate; |
| 135 |
} |
| 136 |
|
| 137 |
static ibta_rate |
| 138 |
ips_rate_to_enum(int link_rate) |
| 139 |
{ |
| 140 |
ibta_rate rate; |
| 141 |
|
| 142 |
switch(link_rate) { |
| 143 |
case 40: |
| 144 |
rate = IBTA_RATE_40_GBPS; |
| 145 |
break; |
| 146 |
case 20: |
| 147 |
rate = IBTA_RATE_20_GBPS; |
| 148 |
break; |
| 149 |
case 10: |
| 150 |
rate = IBTA_RATE_10_GBPS; |
| 151 |
break; |
| 152 |
case 5: |
| 153 |
rate = IBTA_RATE_5_GBPS; |
| 154 |
break; |
| 155 |
case 2: |
| 156 |
rate = IBTA_RATE_2_5_GBPS; |
| 157 |
break; |
| 158 |
default: |
| 159 |
rate = IBTA_RATE_PORT_CURRENT; |
| 160 |
} |
| 161 |
|
| 162 |
return rate; |
| 163 |
} |
| 164 |
|
| 165 |
static psm_error_t |
| 166 |
ips_none_get_path_rec(struct ips_proto *proto, |
| 167 |
uint16_t slid, uint16_t dlid, uint16_t desthca_type, |
| 168 |
unsigned long timeout, ips_path_rec_t **prec) |
| 169 |
{ |
| 170 |
psm_error_t err = PSM_OK; |
| 171 |
ENTRY elid, *epath = NULL; |
| 172 |
char eplid[128]; |
| 173 |
ips_path_rec_t *path_rec; |
| 174 |
|
| 175 |
/* Query the path record cache */ |
| 176 |
snprintf(eplid, sizeof(eplid), "%x_%x", slid, dlid); |
| 177 |
elid.key = eplid; |
| 178 |
hsearch_r(elid, FIND, &epath, &proto->ips_path_rec_hash); |
| 179 |
|
| 180 |
if (!epath) { |
| 181 |
elid.key = psmi_calloc(proto->ep, UNDEFINED, 1, strlen(eplid) + 1); |
| 182 |
path_rec = (ips_path_rec_t*) |
| 183 |
psmi_calloc(proto->ep, UNDEFINED, 1, sizeof(ips_path_rec_t)); |
| 184 |
if (!elid.key || !path_rec) { |
| 185 |
if (elid.key) psmi_free(elid.key); |
| 186 |
if (path_rec) psmi_free(path_rec); |
| 187 |
return PSM_NO_MEMORY; |
| 188 |
} |
| 189 |
|
| 190 |
/* Create path record */ |
| 191 |
path_rec->epr_slid = slid; |
| 192 |
path_rec->epr_dlid = dlid; |
| 193 |
path_rec->epr_mtu = proto->epinfo.ep_mtu; |
| 194 |
path_rec->epr_pkey = proto->epinfo.ep_pkey; |
| 195 |
path_rec->epr_sl = proto->epinfo.ep_sl; |
| 196 |
|
| 197 |
/* Determine the IPD based on our local link rate and default link rate for |
| 198 |
* remote hca type. |
| 199 |
*/ |
| 200 |
path_rec->epr_static_rate = |
| 201 |
ips_default_hca_rate(desthca_type); |
| 202 |
path_rec->epr_static_ipd = |
| 203 |
proto->ips_ipd_delay[path_rec->epr_static_rate]; |
| 204 |
|
| 205 |
/* Setup CCA parameters for path */ |
| 206 |
if (path_rec->epr_sl > 15) { |
| 207 |
psmi_free(elid.key); |
| 208 |
psmi_free(path_rec); |
| 209 |
return PSM_INTERNAL_ERR; |
| 210 |
} |
| 211 |
if (!(proto->ccti_ctrlmap&(1<<path_rec->epr_sl))) { |
| 212 |
_IPATH_CCADBG("No CCA for sl %d, disable CCA\n", path_rec->epr_sl); |
| 213 |
proto->flags &= ~IPS_PROTO_FLAG_CCA; |
| 214 |
} |
| 215 |
path_rec->proto = proto; |
| 216 |
path_rec->epr_ccti_min = proto->cace[path_rec->epr_sl].ccti_min; |
| 217 |
path_rec->epr_ccti = path_rec->epr_ccti_min; |
| 218 |
psmi_timer_entry_init(&path_rec->epr_timer_cca, |
| 219 |
ips_cca_timer_callback, path_rec); |
| 220 |
|
| 221 |
/* Determine active IPD for path. Is max of static rate and CCT table */ |
| 222 |
if ((path_rec->epr_static_ipd) && |
| 223 |
((path_rec->epr_static_ipd + 1) > |
| 224 |
(proto->cct[path_rec->epr_ccti] & CCA_IPD_MASK))) { |
| 225 |
path_rec->epr_active_ipd = path_rec->epr_static_ipd + 1; |
| 226 |
path_rec->epr_cca_divisor = 0; |
| 227 |
} |
| 228 |
else { |
| 229 |
/* Pick it from the CCT table */ |
| 230 |
path_rec->epr_active_ipd = proto->cct[path_rec->epr_ccti] & CCA_IPD_MASK; |
| 231 |
path_rec->epr_cca_divisor = |
| 232 |
proto->cct[path_rec->epr_ccti] >> CCA_DIVISOR_SHIFT; |
| 233 |
} |
| 234 |
|
| 235 |
/* Setup default errorcheck timeout. */ |
| 236 |
path_rec->epr_timeout_ack = |
| 237 |
proto->epinfo.ep_timeout_ack; |
| 238 |
path_rec->epr_timeout_ack_max = |
| 239 |
proto->epinfo.ep_timeout_ack_max; |
| 240 |
path_rec->epr_timeout_ack_factor = |
| 241 |
proto->epinfo.ep_timeout_ack_factor; |
| 242 |
|
| 243 |
/* Add path record into cache */ |
| 244 |
strcpy(elid.key, eplid); |
| 245 |
elid.data = (void*) path_rec; |
| 246 |
hsearch_r(elid, ENTER, &epath, &proto->ips_path_rec_hash); |
| 247 |
} |
| 248 |
else |
| 249 |
path_rec = (ips_path_rec_t*) epath->data; |
| 250 |
|
| 251 |
/* Return IPS path record */ |
| 252 |
*prec = path_rec; |
| 253 |
|
| 254 |
return err; |
| 255 |
} |
| 256 |
|
| 257 |
static psm_error_t |
| 258 |
ips_none_path_rec(struct ips_proto *proto, |
| 259 |
uint16_t slid, uint16_t dlid, uint16_t desthca_type, |
| 260 |
unsigned long timeout, |
| 261 |
ips_epaddr_t *ipsaddr) |
| 262 |
{ |
| 263 |
psm_error_t err = PSM_OK; |
| 264 |
uint16_t pidx, num_path = (1 << proto->epinfo.ep_lmc); |
| 265 |
uint16_t base_slid, base_dlid; |
| 266 |
psmi_context_t *context = &proto->ep->context; |
| 267 |
|
| 268 |
/* For the "none" path record resolution all paths are assumed to be of equal |
| 269 |
* priority however since we want to isolate all control traffic (acks, naks) |
| 270 |
* to a separate path for non zero LMC subnets the "first path" between a |
| 271 |
* pair of endpoints is always the "higher" priority paths. The rest of the |
| 272 |
* paths are the normal (and low priority) paths. |
| 273 |
*/ |
| 274 |
|
| 275 |
/* If base lids are only used then reset num_path to 1 */ |
| 276 |
if (proto->flags & IPS_PROTO_FLAG_PPOLICY_STATIC_BASE) |
| 277 |
num_path = 1; |
| 278 |
|
| 279 |
if (num_path > 1) { |
| 280 |
/* One control path and (num_path - 1) norm and low priority paths */ |
| 281 |
ipsaddr->epr.epr_num_paths[IPS_PATH_HIGH_PRIORITY] = 1; |
| 282 |
ipsaddr->epr.epr_num_paths[IPS_PATH_NORMAL_PRIORITY] = num_path - 1; |
| 283 |
ipsaddr->epr.epr_num_paths[IPS_PATH_LOW_PRIORITY] = num_path - 1; |
| 284 |
} |
| 285 |
else { |
| 286 |
/* LMC of 0. Use the same path for all priorities */ |
| 287 |
ipsaddr->epr.epr_num_paths[IPS_PATH_HIGH_PRIORITY] = 1; |
| 288 |
ipsaddr->epr.epr_num_paths[IPS_PATH_NORMAL_PRIORITY] = 1; |
| 289 |
ipsaddr->epr.epr_num_paths[IPS_PATH_LOW_PRIORITY] = 1; |
| 290 |
} |
| 291 |
|
| 292 |
/* For "none" path record we just setup 2^lmc paths. To get better load |
| 293 |
* balance |
| 294 |
*/ |
| 295 |
for (pidx = 0; pidx < num_path; pidx++) { |
| 296 |
ips_path_rec_t *path; |
| 297 |
|
| 298 |
base_slid = __cpu_to_be16(__be16_to_cpu(slid) + pidx); |
| 299 |
base_dlid = __cpu_to_be16(__be16_to_cpu(dlid) + pidx); |
| 300 |
|
| 301 |
err = ips_none_get_path_rec(proto, base_slid, base_dlid, desthca_type, |
| 302 |
timeout, &path); |
| 303 |
if (err != PSM_OK) |
| 304 |
goto fail; |
| 305 |
|
| 306 |
if (num_path > 1) { |
| 307 |
if (pidx == 0) { |
| 308 |
/* First path is always the high priority path */ |
| 309 |
ipsaddr->epr.epr_path[IPS_PATH_HIGH_PRIORITY][0] = path; |
| 310 |
} |
| 311 |
else { |
| 312 |
ipsaddr->epr.epr_path[IPS_PATH_NORMAL_PRIORITY][pidx-1] = path; |
| 313 |
ipsaddr->epr.epr_path[IPS_PATH_LOW_PRIORITY][pidx-1] = path; |
| 314 |
} |
| 315 |
} |
| 316 |
else { |
| 317 |
ipsaddr->epr.epr_path[IPS_PATH_HIGH_PRIORITY][0] = path; |
| 318 |
ipsaddr->epr.epr_path[IPS_PATH_NORMAL_PRIORITY][0] = path; |
| 319 |
ipsaddr->epr.epr_path[IPS_PATH_LOW_PRIORITY][0] = path; |
| 320 |
} |
| 321 |
} |
| 322 |
|
| 323 |
if (proto->flags & IPS_PROTO_FLAG_PPOLICY_ADAPTIVE) { |
| 324 |
ipsaddr->epr.epr_hpp_index = 0; |
| 325 |
ipsaddr->epr.epr_next_path[IPS_PATH_NORMAL_PRIORITY] = |
| 326 |
context->base_info.spi_context % ipsaddr->epr.epr_num_paths[IPS_PATH_NORMAL_PRIORITY]; |
| 327 |
ipsaddr->epr.epr_next_path[IPS_PATH_LOW_PRIORITY] = |
| 328 |
context->base_info.spi_context % ipsaddr->epr.epr_num_paths[IPS_PATH_LOW_PRIORITY]; |
| 329 |
} |
| 330 |
else if (proto->flags & IPS_PROTO_FLAG_PPOLICY_STATIC_DST) |
| 331 |
ipsaddr->epr.epr_hpp_index = |
| 332 |
ipsaddr->epr.epr_context % ipsaddr->epr.epr_num_paths[IPS_PATH_HIGH_PRIORITY]; |
| 333 |
else if (proto->flags & IPS_PROTO_FLAG_PPOLICY_STATIC_SRC) |
| 334 |
ipsaddr->epr.epr_hpp_index = |
| 335 |
context->base_info.spi_context % ipsaddr->epr.epr_num_paths[IPS_PATH_HIGH_PRIORITY]; |
| 336 |
else /* Base LID */ |
| 337 |
ipsaddr->epr.epr_hpp_index = 0; |
| 338 |
|
| 339 |
fail: |
| 340 |
if (err != PSM_OK) |
| 341 |
_IPATH_PRDBG("Unable to get path record for LID %x <---> DLID %x.\n", slid, dlid); |
| 342 |
return err; |
| 343 |
} |
| 344 |
|
| 345 |
static psm_error_t ips_none_path_rec_init(struct ips_proto *proto) |
| 346 |
{ |
| 347 |
psm_error_t err = PSM_OK; |
| 348 |
union psmi_envvar_val psm_set_hca_pkey; |
| 349 |
|
| 350 |
/* Obtain the SL and PKEY to use from the environment (IPATH_SL & PSM_KEY) */ |
| 351 |
proto->epinfo.ep_sl = psmi_epid_sl(proto->ep->epid); |
| 352 |
proto->epinfo.ep_pkey = (uint16_t) proto->ep->network_pkey; |
| 353 |
|
| 354 |
/* |
| 355 |
* Parse the err_chk settings from the environment. |
| 356 |
* <min_timeout>:<max_timeout>:<timeout_factor> |
| 357 |
*/ |
| 358 |
{ |
| 359 |
union psmi_envvar_val env_to; |
| 360 |
char *errchk_to = PSM_TID_TIMEOUT_DEFAULT; |
| 361 |
int tvals[3] = { |
| 362 |
IPS_PROTO_ERRCHK_MS_MIN_DEFAULT, |
| 363 |
IPS_PROTO_ERRCHK_MS_MAX_DEFAULT, |
| 364 |
IPS_PROTO_ERRCHK_FACTOR_DEFAULT }; |
| 365 |
|
| 366 |
if (!psmi_getenv("PSM_ERRCHK_TIMEOUT", |
| 367 |
"Errchk timeouts in mS <min:max:factor>", |
| 368 |
PSMI_ENVVAR_LEVEL_HIDDEN, PSMI_ENVVAR_TYPE_STR, |
| 369 |
(union psmi_envvar_val) errchk_to, &env_to)) |
| 370 |
{ |
| 371 |
/* Not using default values, parse what we can */ |
| 372 |
errchk_to = env_to.e_str; |
| 373 |
psmi_parse_str_tuples(errchk_to, 3, tvals); |
| 374 |
/* Adjust for max smaller than min, things would break */ |
| 375 |
if (tvals[1] < tvals[0]) |
| 376 |
tvals[1] = tvals[0]; |
| 377 |
} |
| 378 |
proto->epinfo.ep_timeout_ack = ms_2_cycles(tvals[0]); |
| 379 |
proto->epinfo.ep_timeout_ack_max = ms_2_cycles(tvals[1]); |
| 380 |
proto->epinfo.ep_timeout_ack_factor = tvals[2]; |
| 381 |
} |
| 382 |
|
| 383 |
/* With no path records queries set pkey manually if PSM_SET_HCA_PKEY is |
| 384 |
* set. |
| 385 |
*/ |
| 386 |
psmi_getenv("PSM_SET_HCA_PKEY", |
| 387 |
"Force write of PKey to HCA (default is disabled)", |
| 388 |
PSMI_ENVVAR_LEVEL_HIDDEN, PSMI_ENVVAR_TYPE_UINT_FLAGS, |
| 389 |
(union psmi_envvar_val) 0, &psm_set_hca_pkey); |
| 390 |
|
| 391 |
if (psm_set_hca_pkey.e_uint) { |
| 392 |
if (ipath_set_pkey(proto->ep->context.ctrl, |
| 393 |
(uint16_t) proto->ep->network_pkey) != 0) { |
| 394 |
err = psmi_handle_error(proto->ep, PSM_EP_DEVICE_FAILURE, |
| 395 |
"Couldn't set device pkey %d: %s", |
| 396 |
(int) proto->ep->network_pkey, |
| 397 |
strerror(errno)); |
| 398 |
goto fail; |
| 399 |
} |
| 400 |
} |
| 401 |
|
| 402 |
proto->ibta.get_path_rec = ips_none_path_rec; |
| 403 |
proto->ibta.fini = NULL; |
| 404 |
|
| 405 |
fail: |
| 406 |
return err; |
| 407 |
} |
| 408 |
|
| 409 |
/* (Re)load the SL2VL table */ |
| 410 |
psm_error_t ips_ibta_init_sl2vl_table(struct ips_proto *proto) |
| 411 |
{ |
| 412 |
int ret, sli; |
| 413 |
|
| 414 |
/* Get SL2VL table for unit, port */ |
| 415 |
for (sli = 0; sli < 16; sli++) { |
| 416 |
if ((ret = ipath_get_port_sl2vl(proto->ep->context.base_info.spi_unit, |
| 417 |
proto->ep->context.base_info.spi_port, |
| 418 |
(uint8_t) sli)) < 0) { |
| 419 |
/* Unable to get SL2VL. Set it to default */ |
| 420 |
ret = PSMI_VL_DEFAULT; |
| 421 |
} |
| 422 |
|
| 423 |
proto->sl2vl[sli] = ret; |
| 424 |
} |
| 425 |
|
| 426 |
return PSM_OK; |
| 427 |
} |
| 428 |
|
| 429 |
/* On link up/down we need to update some state */ |
| 430 |
psm_error_t ips_ibta_link_updown_event(struct ips_proto *proto) |
| 431 |
{ |
| 432 |
psm_error_t err = PSM_OK; |
| 433 |
int ret; |
| 434 |
|
| 435 |
/* Get base lid, lmc and rate as these may have changed if the link bounced */ |
| 436 |
proto->epinfo.ep_base_lid = |
| 437 |
__cpu_to_be16((uint16_t) psm_epid_nid(proto->ep->context.epid)); |
| 438 |
if ((ret = ipath_get_port_lmc(proto->ep->context.base_info.spi_unit, |
| 439 |
proto->ep->context.base_info.spi_port)) < 0) { |
| 440 |
err = psmi_handle_error(proto->ep, PSM_EP_DEVICE_FAILURE, |
| 441 |
"Could obtain LMC for unit %u:%d. Error: %s", |
| 442 |
proto->ep->context.base_info.spi_unit, |
| 443 |
proto->ep->context.base_info.spi_port, |
| 444 |
strerror(errno)); |
| 445 |
goto fail; |
| 446 |
} |
| 447 |
proto->epinfo.ep_lmc = min(ret, IPS_MAX_PATH_LMC); |
| 448 |
|
| 449 |
if ((ret = ipath_get_port_rate(proto->ep->context.base_info.spi_unit, |
| 450 |
proto->ep->context.base_info.spi_port)) < 0) { |
| 451 |
err = psmi_handle_error(proto->ep, PSM_EP_DEVICE_FAILURE, |
| 452 |
"Could obtain link rate for unit %u:%d. Error: %s", |
| 453 |
proto->ep->context.base_info.spi_unit, |
| 454 |
proto->ep->context.base_info.spi_port, |
| 455 |
strerror(errno)); |
| 456 |
goto fail; |
| 457 |
} |
| 458 |
proto->epinfo.ep_link_rate = ips_rate_to_enum(ret); |
| 459 |
|
| 460 |
/* Load the SL2VL table */ |
| 461 |
ips_ibta_init_sl2vl_table(proto); |
| 462 |
|
| 463 |
/* Regenerate new IPD table for the updated link rate. */ |
| 464 |
ips_gen_ipd_table(proto); |
| 465 |
|
| 466 |
/* Generate the CCT table. */ |
| 467 |
err = ips_gen_cct_table(proto); |
| 468 |
|
| 469 |
fail: |
| 470 |
return err; |
| 471 |
} |
| 472 |
|
| 473 |
psm_error_t ips_ibta_init(struct ips_proto *proto) |
| 474 |
{ |
| 475 |
psm_error_t err = PSM_OK; |
| 476 |
union psmi_envvar_val psm_path_policy; |
| 477 |
union psmi_envvar_val disable_cca; |
| 478 |
|
| 479 |
/* Get the path selection policy */ |
| 480 |
psmi_getenv("PSM_PATH_SELECTION", |
| 481 |
"Policy to use if multiple paths are available between endpoints. Options are adaptive, static_src, static_dest, static_base. Default is adaptive.", |
| 482 |
PSMI_ENVVAR_LEVEL_USER, PSMI_ENVVAR_TYPE_STR, |
| 483 |
(union psmi_envvar_val) "adaptive", |
| 484 |
&psm_path_policy); |
| 485 |
|
| 486 |
if (!strcasecmp((const char*) psm_path_policy.e_str, "adaptive")) |
| 487 |
proto->flags |= IPS_PROTO_FLAG_PPOLICY_ADAPTIVE; |
| 488 |
else if (!strcasecmp((const char*) psm_path_policy.e_str, "static_src")) |
| 489 |
proto->flags |= IPS_PROTO_FLAG_PPOLICY_STATIC_SRC; |
| 490 |
else if (!strcasecmp((const char*) psm_path_policy.e_str, "static_dest")) |
| 491 |
proto->flags |= IPS_PROTO_FLAG_PPOLICY_STATIC_DST; |
| 492 |
else if (!strcasecmp((const char*) psm_path_policy.e_str, "static_base")) |
| 493 |
proto->flags |= IPS_PROTO_FLAG_PPOLICY_STATIC_BASE; |
| 494 |
|
| 495 |
if (proto->flags & IPS_PROTO_FLAG_PPOLICY_ADAPTIVE) |
| 496 |
_IPATH_PRDBG("Using adaptive path selection.\n"); |
| 497 |
if (proto->flags & IPS_PROTO_FLAG_PPOLICY_STATIC_SRC) |
| 498 |
_IPATH_PRDBG("Static path selection: Src Context\n"); |
| 499 |
if (proto->flags & IPS_PROTO_FLAG_PPOLICY_STATIC_DST) |
| 500 |
_IPATH_PRDBG("Static path selection: Dest Context\n"); |
| 501 |
if (proto->flags & IPS_PROTO_FLAG_PPOLICY_STATIC_BASE) |
| 502 |
_IPATH_PRDBG("Static path selection: Base LID \n"); |
| 503 |
|
| 504 |
psmi_getenv("PSM_DISABLE_CCA", |
| 505 |
"Disable use of Congestion Control Architecure (CCA) [enabled] ", |
| 506 |
PSMI_ENVVAR_LEVEL_USER, PSMI_ENVVAR_TYPE_UINT, |
| 507 |
(union psmi_envvar_val) 0, |
| 508 |
&disable_cca); |
| 509 |
if (disable_cca.e_uint) |
| 510 |
_IPATH_CCADBG("CCA is disabled for congestion control.\n"); |
| 511 |
else |
| 512 |
proto->flags |= IPS_PROTO_FLAG_CCA; |
| 513 |
|
| 514 |
{ |
| 515 |
/* Get CCA related parameters from the environment */ |
| 516 |
union psmi_envvar_val ccti_incr; |
| 517 |
union psmi_envvar_val ccti_timer; |
| 518 |
union psmi_envvar_val ccti_size; |
| 519 |
int i; |
| 520 |
char ccabuf[256]; |
| 521 |
uint8_t *p; |
| 522 |
|
| 523 |
/* |
| 524 |
* If user set any environment variable, use self CCA. |
| 525 |
*/ |
| 526 |
if (getenv("PSM_CCTI_INCREMENT") || getenv("PSM_CCTI_TIMER") || getenv("PSM_CCTI_TABLE_SIZE")) { |
| 527 |
goto selfcca; |
| 528 |
} |
| 529 |
|
| 530 |
/* |
| 531 |
* Check qib driver CCA setting, and try to use it if available. |
| 532 |
* Fall to self CCA setting if errors. |
| 533 |
*/ |
| 534 |
i = ipath_get_cc_settings_bin(proto->ep->context.base_info.spi_unit, |
| 535 |
proto->ep->context.base_info.spi_port, ccabuf); |
| 536 |
if (i <= 0) { |
| 537 |
goto selfcca; |
| 538 |
} |
| 539 |
p = (uint8_t *)ccabuf; |
| 540 |
memcpy(&proto->ccti_portctrl, p, 2); p += 2; |
| 541 |
memcpy(&proto->ccti_ctrlmap, p, 2); p += 2; |
| 542 |
for (i=0; i<16; i++) { |
| 543 |
proto->cace[i].ccti_increase = *p; p++; |
| 544 |
memcpy(&proto->cace[i].ccti_timer_cycles, p, 2); p += 2; |
| 545 |
proto->cace[i].ccti_timer_cycles = |
| 546 |
us_2_cycles(proto->cace[i].ccti_timer_cycles); |
| 547 |
proto->cace[i].ccti_threshold = *p; p++; |
| 548 |
proto->cace[i].ccti_min = *p; p++; |
| 549 |
} |
| 550 |
|
| 551 |
i = ipath_get_cc_table_bin(proto->ep->context.base_info.spi_unit, |
| 552 |
proto->ep->context.base_info.spi_port, &proto->cct); |
| 553 |
if (i < 0) { |
| 554 |
err = PSM_NO_MEMORY; |
| 555 |
goto fail; |
| 556 |
} else if (i == 0) { |
| 557 |
goto selfcca; |
| 558 |
} |
| 559 |
proto->ccti_limit = i; |
| 560 |
proto->ccti_size = proto->ccti_limit + 1; |
| 561 |
goto finishcca; |
| 562 |
|
| 563 |
/* |
| 564 |
* Since there is no qib driver CCA settings, use self built CCA. |
| 565 |
*/ |
| 566 |
selfcca: |
| 567 |
psmi_getenv("PSM_CCTI_INCREMENT", |
| 568 |
"IBTA_CCA: Index increment for CCT table on receipt of a BECN packet (less than table size, default 1)", |
| 569 |
PSMI_ENVVAR_LEVEL_USER, PSMI_ENVVAR_TYPE_UINT_FLAGS, |
| 570 |
(union psmi_envvar_val) 1, |
| 571 |
&ccti_incr); |
| 572 |
|
| 573 |
psmi_getenv("PSM_CCTI_TIMER", |
| 574 |
"IBTA_CCA: CCT table congestion timer (>0, default 1 us)", |
| 575 |
PSMI_ENVVAR_LEVEL_USER, PSMI_ENVVAR_TYPE_UINT_FLAGS, |
| 576 |
(union psmi_envvar_val) 1, |
| 577 |
&ccti_timer); |
| 578 |
|
| 579 |
psmi_getenv("PSM_CCTI_TABLE_SIZE", |
| 580 |
"IBTA_CCA: Number of entries in CCT table (multiple of 64, default 128)", |
| 581 |
PSMI_ENVVAR_LEVEL_USER, PSMI_ENVVAR_TYPE_UINT_FLAGS, |
| 582 |
(union psmi_envvar_val) DF_CCT_TABLE_SIZE, //128 |
| 583 |
&ccti_size); |
| 584 |
|
| 585 |
/* Check the invalid values. */ |
| 586 |
if (ccti_size.e_uint < 64 || ccti_size.e_uint%64) { |
| 587 |
_IPATH_INFO("Invalid PSM_CCTI_TABLE_SIZE=%d, at least 64 and multiple of 64, setting to default 128\n", |
| 588 |
ccti_size.e_uint); |
| 589 |
ccti_size.e_uint = 128; |
| 590 |
} |
| 591 |
proto->ccti_size = ccti_size.e_uint; |
| 592 |
/* For now the CCT limit is same as table size. |
| 593 |
* This does not have to be the case. */ |
| 594 |
proto->ccti_limit = proto->ccti_size - 1; |
| 595 |
|
| 596 |
if (ccti_timer.e_uint <= 0) { |
| 597 |
_IPATH_INFO("Invalid PSM_CCTI_TIMER=%d, should be bigger than 0, setting to default 1\n", |
| 598 |
ccti_timer.e_uint); |
| 599 |
ccti_timer.e_uint = 1; |
| 600 |
} |
| 601 |
if (ccti_incr.e_uint <= 0 || ccti_incr.e_uint >= ccti_size.e_uint) { |
| 602 |
_IPATH_INFO("Invalid PSM_CCTI_INCREMENT=%d, should be less than table size, setting to default 1\n", |
| 603 |
ccti_incr.e_uint); |
| 604 |
ccti_incr.e_uint = 1; |
| 605 |
} |
| 606 |
|
| 607 |
/* Setup CCA parameters for port */ |
| 608 |
proto->ccti_portctrl = 1; /* SL/Port based congestion control */ |
| 609 |
proto->ccti_ctrlmap = 0xFFFF; |
| 610 |
for (i=0; i<16; i++) { |
| 611 |
proto->cace[i].ccti_increase = ccti_incr.e_uint; |
| 612 |
proto->cace[i].ccti_timer_cycles = us_2_cycles(ccti_timer.e_uint); |
| 613 |
proto->cace[i].ccti_threshold = 8; |
| 614 |
proto->cace[i].ccti_min = 0; |
| 615 |
} |
| 616 |
} |
| 617 |
|
| 618 |
finishcca: |
| 619 |
/* Seed the random number generator with our pid */ |
| 620 |
srand(getpid()); |
| 621 |
|
| 622 |
/* Initialize path record hash table */ |
| 623 |
hcreate_r(DF_PATH_REC_HASH_SIZE, &proto->ips_path_rec_hash); |
| 624 |
|
| 625 |
/* On startup treat it as a link up/down event to setup state . */ |
| 626 |
if ((err = ips_ibta_link_updown_event(proto)) != PSM_OK) |
| 627 |
goto fail; |
| 628 |
|
| 629 |
/* Setup the appropriate query interface for the endpoint */ |
| 630 |
switch(proto->ep->path_res_type) { |
| 631 |
case PSM_PATH_RES_OPP: |
| 632 |
err = ips_opp_init(proto); |
| 633 |
if (err != PSM_OK) |
| 634 |
_IPATH_ERROR("Unable to use OFED Plus Plus for path record queries.\n"); |
| 635 |
break; |
| 636 |
case PSM_PATH_RES_UMAD: |
| 637 |
_IPATH_ERROR("Path record queries using UMAD is not supported in PSM version %d.%dx\n", PSM_VERNO_MAJOR, PSM_VERNO_MINOR); |
| 638 |
err = PSM_EPID_PATH_RESOLUTION; |
| 639 |
break; |
| 640 |
case PSM_PATH_RES_NONE: |
| 641 |
default: |
| 642 |
err = ips_none_path_rec_init(proto); |
| 643 |
} |
| 644 |
|
| 645 |
fail: |
| 646 |
return err; |
| 647 |
} |
| 648 |
|
| 649 |
psm_error_t ips_ibta_fini(struct ips_proto *proto) |
| 650 |
{ |
| 651 |
psm_error_t err = PSM_OK; |
| 652 |
|
| 653 |
if (proto->ibta.fini) |
| 654 |
err = proto->ibta.fini(proto); |
| 655 |
|
| 656 |
/* Destroy the path record hash */ |
| 657 |
hdestroy_r(&proto->ips_path_rec_hash); |
| 658 |
|
| 659 |
return err; |
| 660 |
} |