1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 * or http://www.opensolaris.org/os/licensing. 10 * See the License for the specific language governing permissions 11 * and limitations under the License. 12 * 13 * When distributing Covered Code, include this CDDL HEADER in each 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 * If applicable, add the following below this CDDL HEADER, with the 16 * fields enclosed by brackets "[]" replaced with your own identifying 17 * information: Portions Copyright [yyyy] [name of copyright owner] 18 * 19 * CDDL HEADER END 20 */ 21 22 /* 23 * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 24 * Use is subject to license terms. 25 */ 26 27 #ifndef _SYS_IB_ADAPTERS_HERMON_CMD_H 28 #define _SYS_IB_ADAPTERS_HERMON_CMD_H 29 30 /* 31 * hermon_cmd.h 32 * Contains all of the prototypes, #defines, and structures necessary 33 * for the Hermon Firmware Command routines. 34 * Specifically it contains the command types, command statuses and flags, 35 * structures used for managing Hermon mailboxes and outstanding commands, 36 * and prototypes for most of the functions consumed by other parts of 37 * the Hermon driver. 38 */ 39 40 #include <sys/types.h> 41 #include <sys/conf.h> 42 #include <sys/ddi.h> 43 #include <sys/sunddi.h> 44 45 #include <sys/ib/mgt/sm_attr.h> 46 47 #ifdef __cplusplus 48 extern "C" { 49 #endif 50 51 52 /* 53 * Defines used hermon_write_hcr() to determine the duration and number of 54 * times (at maximum) to poll while waiting for a Hermon firmware command to 55 * release the HCR resource (i.e. waiting for the command to complete) 56 */ 57 #define HERMON_CMD_POLL_DELAY 1 58 #define HERMON_CMD_POLL_MAX 3000000 59 60 /* 61 * The following defines specify the default number of mailboxes (log 2) of 62 * each type and their size and alignment restrictions. By default the number 63 * of both "In" and "Out" mailboxes is set to 1024 (with each mailbox being 64 * 4KB in size), but both the number and sizes of each are controllable 65 * through the "hermon_log_num_inmbox", "hermon_log_num_outmbox", 66 * "hermon_log_inmbox_size" and "hermon_log_outmbox_size" configuration 67 * variables. Also, we have a define that is used to allocate interrupt 68 * mailboxes (1 in, 1 out). 69 */ 70 #define HERMON_NUM_MAILBOXES_SHIFT 0xA 71 #define HERMON_NUM_INTR_MAILBOXES_SHIFT 0 72 #define HERMON_MBOX_SIZE_SHIFT 0xC 73 #define HERMON_MBOX_SIZE (1 << HERMON_MBOX_SIZE_SHIFT) 74 #define HERMON_MBOX_ALIGN HERMON_MBOX_SIZE 75 76 /* 77 * These are the defines for the Hermon command type (opcodes). They are 78 * specified by the Hermon PRM 79 */ 80 81 /* Init Commands */ 82 #define QUERY_DEV_LIM 0x3 83 #define QUERY_DEV_CAP 0x3 84 #define QUERY_FW 0x4 85 #define QUERY_ADAPTER 0x6 86 #define INIT_HCA 0x7 87 #define CLOSE_HCA 0x8 88 #define INIT_IB 0x9 89 #define INIT_PORT 0x9 90 #define CLOSE_IB 0xA 91 #define CLOSE_PORT 0xA 92 #define QUERY_HCA 0xB 93 #define SET_IB 0xC 94 #define SET_PORT 0xC 95 /* added late in tavor for SRQ support */ 96 #define MOD_STAT_CFG 0x34 97 /* added late in Hermon (PRM 0.35) */ 98 #define QUERY_PORT 0x43 99 100 101 /* TPT Commands */ 102 #define SW2HW_MPT 0xD 103 #define QUERY_MPT 0xE 104 #define HW2SW_MPT 0xF 105 #define READ_MTT 0x10 106 #define WRITE_MTT 0x11 107 #define SYNC_TPT 0x2F 108 #define MODIFY_MPT 0x39 109 110 /* EQ Commands */ 111 #define MAP_EQ 0x12 112 #define SW2HW_EQ 0x13 113 #define HW2SW_EQ 0x14 114 #define QUERY_EQ 0x15 115 116 /* CQ Commands */ 117 #define SW2HW_CQ 0x16 118 #define HW2SW_CQ 0x17 119 #define QUERY_CQ 0x18 120 #define MODIFY_CQ 0x2C 121 122 /* Modify CQ Command - opcode modifiers */ 123 #define RESIZE_CQ 0x0 124 #define MODIFY_MODERATION_CQ 0x1 125 #define MODIFY_EQN 0x2 126 127 /* QP Commands */ 128 #define RST2INIT_QP 0x19 129 #define INIT2INIT_QP 0x2D 130 #define INIT2RTR_QP 0x1A 131 #define RTR2RTS_QP 0x1B 132 #define RTS2RTS_QP 0x1C 133 #define SQERR2RTS_QP 0x1D 134 #define TOERR_QP 0x1E 135 #define RTS2SQD_QP 0x1F 136 #define SQD2SQD_QP 0x38 137 #define SQD2RTS_QP 0x20 138 #define TORST_QP 0x21 139 #define QUERY_QP 0x22 140 #define SUSPEND_QP 0x32 /* new w/ hermon driver */ 141 #define UNSUSPEND_QP 0x33 /* new w/ hermon driver */ 142 143 /* SPECIAL QPs Commands */ 144 #define CONF_SPECIAL_QP 0x23 145 #define MAD_IFC 0x24 146 147 /* added late in tavor for SRQ support */ 148 /* SRQ Commands */ 149 #define SW2HW_SRQ 0x35 150 #define HW2SW_SRQ 0x36 151 #define QUERY_SRQ 0x37 152 /* new in hermon, replaces part of modifyMPT */ 153 #define RESIZE_SRQ 0X44 154 /* new in hermon, set limit water mark */ 155 #define ARM_RQ 0X40 156 157 /* Multicast Group Commands */ 158 #define READ_MGM 0x25 159 #define READ_MCG 0x25 160 #define WRITE_MGM 0x26 161 #define WRITE_MCG 0x26 162 #define MGID_HASH 0x27 163 164 /* Debug/Diagnostic Commands */ 165 #define QUERY_DEBUG_MSG 0x2A 166 #define SET_DEBUG_MSG 0x2B 167 #define DIAG_RPRT 0x30 168 #define CMD_NOP 0x31 169 170 171 /* ICM and related commands - w/out LAM commands from Arbel */ 172 #define RUN_FW 0xFF6 173 #define UNMAP_ICM 0xFF9 174 #define MAP_ICM 0xFFA 175 #define UNMAP_ICM_AUX 0xFFB 176 #define MAP_ICM_AUX 0xFFC 177 #define SET_ICM_SIZE 0xFFD 178 #define UNMAP_FA 0xFFE 179 #define MAP_FA 0xFFF 180 181 /* 182 * Commands mentioned but not defined in PRM v35 183 * REL_ICM_AUX 184 * INIT_VM 185 * HEART_BEAT_RQ 186 */ 187 188 /* 189 * These are the defines for the Hermon command completion statuses. They are 190 * also specified (in part) by the Hermon PRM. However, 191 * the HERMON_CMD_INSUFF_RSRC, HERMON_CMD_TIMEOUT and HERMON_CMD_INVALID_STATUS 192 * codes were added for this driver specifically to indicate the conditions 193 * when insufficient resources are available for a command, when a command has 194 * timed out (failure in the Hermon firmware) or when some other invalid result 195 * was received. 196 */ 197 #define HERMON_CMD_TIMEOUT_TOGGLE 0xFFFC /* -4 */ 198 #define HERMON_CMD_INSUFF_RSRC 0xFFFD /* -3 */ 199 #define HERMON_CMD_TIMEOUT_GOBIT 0xFFFE /* -2 */ 200 #define HERMON_CMD_INVALID_STATUS 0xFFFF /* -1 */ 201 #define HERMON_CMD_SUCCESS 0x00 202 #define HERMON_CMD_INTERNAL_ERR 0x01 203 #define HERMON_CMD_BAD_OP 0x02 204 #define HERMON_CMD_BAD_PARAM 0x03 205 #define HERMON_CMD_BAD_SYS_STATE 0x04 206 #define HERMON_CMD_BAD_RESOURCE 0x05 207 #define HERMON_CMD_RESOURCE_BUSY 0x06 208 #define HERMON_CMD_EXCEED_LIM 0x08 209 #define HERMON_CMD_BAD_RES_STATE 0x09 210 #define HERMON_CMD_BAD_INDEX 0x0A 211 #define HERMON_CMD_BAD_NVMEM 0x0B 212 #define HERMON_CMD_ICM_ERROR 0x0C 213 #define HERMON_CMD_BAD_QP_STATE 0x10 214 #define HERMON_CMD_BAD_SEG_PARAM 0x20 215 #define HERMON_CMD_REG_BOUND 0x21 216 #define HERMON_CMD_BAD_PKT 0x30 217 #define HERMON_CMD_BAD_SIZE 0x40 218 219 /* 220 * These defines are used in the "special QP" allocation to indicate the type 221 * of special QP (SMI, GSI, or one of the raw types). These values are 222 * specified by the Hermon PRM 223 */ 224 #define HERMON_CMD_QP_SMI 0 225 #define HERMON_CMD_QP_GSI 1 226 #define HERMON_CMD_QP_RAW_IPV6 2 227 #define HERMON_CMD_QP_RAW_ETH 3 228 229 #define HERMON_CMD_SPEC_QP_OPMOD(smi, gsi) \ 230 ((smi & 0x01) | ((gsi & 0x01) << 1)) 231 232 /* 233 * For certain Hermon QP state transition commands some optional flags are 234 * allowed. These "opmask" flags are defined by the Hermon PRM 235 * as a bitmask. 236 */ 237 238 #define HERMON_CMD_OP_ALT_PATH (1 << 0) 239 #define HERMON_CMD_OP_RRE (1 << 1) 240 #define HERMON_CMD_OP_RAE (1 << 2) 241 #define HERMON_CMD_OP_RWE (1 << 3) 242 #define HERMON_CMD_OP_PKEYINDX (1 << 4) /* primary path */ 243 #define HERMON_CMD_OP_QKEY (1 << 5) 244 #define HERMON_CMD_OP_MINRNRNAK (1 << 6) 245 #define HERMON_CMD_OP_PRIM_PATH (1 << 7) 246 #define HERMON_CMD_OP_SRA_SET (1 << 8) 247 #define HERMON_CMD_OP_RRA_SET (1 << 9) 248 #define HERMON_CMD_OP_PM_STATE (1 << 10) /* migration */ 249 /* HERMON_CMD_OP_PRIM_PORT is obsolete, instead use HERMON_CMD_OP_SCHEDQUEUE */ 250 #define HERMON_CMD_OP_PRIM_PORT (1 << 11) 251 #define HERMON_CMD_OP_RETRYCNT (1 << 12) /* Global */ 252 #define HERMON_CMD_OP_ALT_RNRRETRY (1 << 13) 253 #define HERMON_CMD_OP_ACKTIMEOUT (1 << 14) /* primary path */ 254 #define HERMON_CMD_OP_PRIM_RNRRETRY (1 << 15) /* reserved in HERMON */ 255 #define HERMON_CMD_OP_SCHEDQUEUE (1 << 16) 256 #define HERMON_CMD_OP_RSSCONTEXT (1 << 17) 257 #define HERMON_CMD_OP_SRQN (1 << 18) /* for rss balancing */ 258 #define HERMON_CMD_OP_CQN_RCV (1 << 19) /* for rss balancing */ 259 /* Bits 20 - 31 RESERVED - per PRM 0.35c */ 260 261 262 263 /* 264 * The Hermon RTS2SQD command can take the following flag as part of its 265 * input modifier to request the Send Queue Drained event 266 */ 267 #define HERMON_CMD_REQ_SQD_EVENT 0x80000000 268 269 /* 270 * The Hermon TORST command can take the following flag (as part of a bitmask) 271 * in its opcode modifier to request that the transition to reset should 272 * not go through the Error state (and, hence, should not generate "flushed- 273 * in-error" completions 274 */ 275 #define HERMON_CMD_DIRECT_TO_RESET (1 << 1) 276 277 /* 278 * Some Hermon commands write an OUT mailbox entry, depending on the value of 279 * the 'opmod' parameter. These defines provide the correct opmod value to 280 * write depending on whether to write an entry or not. 281 */ 282 #define HERMON_CMD_DO_OUTMBOX (0) 283 #define HERMON_CMD_NO_OUTMBOX (1 << 0) 284 285 286 /* 287 * The Hermon MAP_EQ command can take the following flags (and use the 288 * HERMON_CMD_UNMAP_EQ_MASK input modifier) to indicate whether the given 289 * event queue should mapped to or unmapped from the given event type. 290 */ 291 292 293 #define HERMON_CMD_MAP_EQ_EVT_MAP 0 294 #define HERMON_CMD_MAP_EQ_EVT_UNMAP 1 295 #define HERMON_CMD_UNMAP_EQ_MASK 0x80000000 296 297 /* 298 * The following defines are used by the MAD_IFC command and the helper 299 * routines that get PortInfo, NodeInfo, GUIDInfo, and PKeyTable entries. 300 * 301 * The first indicates whether of not MKey checking should be enforced. 302 * This is passed in the opcode modifier field for MAD_IFC commands. 303 * 304 * The next set are used to define certain hardcoded management datagram (MAD) 305 * sizes, offsets, and header formats for each of the helper operations. 306 */ 307 #define HERMON_CMD_MKEY_CHECK 0 308 #define HERMON_CMD_MKEY_DONTCHECK 1 309 310 #define HERMON_CMD_MAD_IFC_SIZE 0x100 311 #define HERMON_CMD_MADDATA_OFFSET 0x40 312 #define HERMON_CMD_MADHDR0 0x01010101 313 #define HERMON_CMD_MADHDR1 0x00000000 314 #define HERMON_CMD_MADHDR2 0x00000000 315 #define HERMON_CMD_MADHDR3 0x00000000 316 317 #define HERMON_CMD_PORTINFO 0x00150000 318 #define HERMON_CMD_NODEINFO 0x00110000 319 #define HERMON_CMD_NODEDESC 0x00100000 320 #define HERMON_CMD_GUIDINFO 0x00140000 321 #define HERMON_CMD_PKEYTBLE 0x00160000 322 323 #define HERMON_CMD_PERF_GET 0x01040101 324 #define HERMON_CMD_PERF_SET 0x01040102 325 #define HERMON_CMD_PERFCNTRS 0x00120000 326 #define HERMON_CMD_PERFATTR 0x00000000 327 328 329 /* 330 * The next few defines are used to indicate the size of the "reserved" area 331 * in the WRITE_MTT command, and the respective sizes of the SET_PORT and 332 * MGID_HASH commands 333 */ 334 #define HERMON_CMD_WRITEMTT_RSVD_SZ 0x10 335 #define HERMON_CMD_SETPORT_SZ 0x8 336 #define HERMON_CMD_MGIDHASH_SZ 0x10 337 338 /* 339 * This last define is used by hermon_cmn_ownership_cmd_post() to keep track 340 * of the direction (from hardware ownership to software, or vice versa) of 341 * the requested operation 342 */ 343 #define HERMON_CMD_RSRC_HW2SW 0 344 #define HERMON_CMD_RSRC_SW2HW 1 345 346 /* 347 * The following macros are used for handling any endianness related issues 348 * that might arise from the Hermon driver's internal use of MADs. 349 * 350 * HERMON_GETPORTINFO_SWAP - All the necessary swapping to handle the 351 * response to a GetPortInfo MAD 352 * HERMON_GETNODEINFO_SWAP - All the necessary swapping to handle the 353 * response to a GetNodeInfo MAD 354 * HERMON_GETGUIDINFO_SWAP - All the necessary swapping to handle the 355 * response to a GetGUIDInfo MAD 356 * HERMON_GETPKEYTABLE_SWAP - All the necessary swapping to handle the 357 * response to a GetPKeyTable MAD 358 */ 359 360 361 #ifdef _LITTLE_ENDIAN 362 #define HERMON_GETPORTINFO_SWAP(portinfo) \ 363 { \ 364 (portinfo)->M_Key = ddi_swap64((portinfo)->M_Key); \ 365 (portinfo)->GidPrefix = ddi_swap64((portinfo)->GidPrefix); \ 366 (portinfo)->LID = ddi_swap16((portinfo)->LID); \ 367 (portinfo)->MasterSMLID = ddi_swap16((portinfo)->MasterSMLID); \ 368 (portinfo)->CapabilityMask = \ 369 ddi_swap32((portinfo)->CapabilityMask); \ 370 (portinfo)->DiagCode = ddi_swap16((portinfo)->DiagCode); \ 371 (portinfo)->M_KeyLeasePeriod = \ 372 ddi_swap16((portinfo)->M_KeyLeasePeriod); \ 373 (portinfo)->M_KeyViolations = \ 374 ddi_swap16((portinfo)->M_KeyViolations); \ 375 (portinfo)->P_KeyViolations = \ 376 ddi_swap16((portinfo)->P_KeyViolations); \ 377 (portinfo)->Q_KeyViolations = \ 378 ddi_swap16((portinfo)->Q_KeyViolations); \ 379 } 380 #else 381 #define HERMON_GETPORTINFO_SWAP(portinfo) 382 #endif 383 384 #ifdef _LITTLE_ENDIAN 385 #define HERMON_GETNODEINFO_SWAP(nodeinfo) \ 386 { \ 387 uint32_t tmp; \ 388 \ 389 tmp = ddi_swap32(((uint32_t *)nodeinfo)[9]); \ 390 (nodeinfo)->VendorID = tmp & 0xFFFFFF; \ 391 (nodeinfo)->LocalPortNum = tmp >> 24; \ 392 (nodeinfo)->Revision = \ 393 ddi_swap32(((uint32_t *)nodeinfo)[8]); \ 394 tmp = ddi_swap32(((uint32_t *)nodeinfo)[7]); \ 395 (nodeinfo)->PartitionCap = tmp >> 16; \ 396 (nodeinfo)->DeviceID = tmp & 0xFFFF; \ 397 (nodeinfo)->PortGUID = ddi_swap64((((uint64_t) \ 398 (((uint32_t *)nodeinfo)[6]) << 32) | \ 399 ((uint32_t *)nodeinfo)[5])); \ 400 (nodeinfo)->NodeGUID = ddi_swap64((((uint64_t) \ 401 (((uint32_t *)nodeinfo)[4]) << 32) | \ 402 ((uint32_t *)nodeinfo)[3])); \ 403 (nodeinfo)->SystemImageGUID = ddi_swap64((((uint64_t) \ 404 (((uint32_t *)nodeinfo)[2]) << 32) | \ 405 ((uint32_t *)nodeinfo)[1])); \ 406 } 407 #else 408 #define HERMON_GETNODEINFO_SWAP(nodeinfo) \ 409 { \ 410 uint32_t tmp; \ 411 \ 412 tmp = ((uint32_t *)nodeinfo)[9]; \ 413 (nodeinfo)->VendorID = tmp & 0xFFFFFF; \ 414 (nodeinfo)->LocalPortNum = tmp >> 24; \ 415 (nodeinfo)->Revision = ((uint32_t *)nodeinfo)[8]; \ 416 tmp = ((uint32_t *)nodeinfo)[7]; \ 417 (nodeinfo)->PartitionCap = tmp >> 16; \ 418 (nodeinfo)->DeviceID = tmp & 0xFFFF; \ 419 (nodeinfo)->PortGUID = (((uint64_t) \ 420 (((uint32_t *)nodeinfo)[5]) << 32) | \ 421 ((uint32_t *)nodeinfo)[6]); \ 422 (nodeinfo)->NodeGUID = (((uint64_t) \ 423 (((uint32_t *)nodeinfo)[3]) << 32) | \ 424 ((uint32_t *)nodeinfo)[4]); \ 425 (nodeinfo)->SystemImageGUID = (((uint64_t) \ 426 (((uint32_t *)nodeinfo)[1]) << 32) | \ 427 ((uint32_t *)nodeinfo)[2]); \ 428 } 429 #endif 430 431 #ifdef _LITTLE_ENDIAN 432 #define HERMON_GETGUIDINFO_SWAP(guidinfo) \ 433 { \ 434 int i; \ 435 \ 436 for (i = 0; i < 8; i++) { \ 437 (guidinfo)->GUIDBlocks[i] = \ 438 ddi_swap64((guidinfo)->GUIDBlocks[i]); \ 439 } \ 440 } 441 #else 442 #define HERMON_GETGUIDINFO_SWAP(guidinfo) 443 #endif 444 445 #ifdef _LITTLE_ENDIAN 446 #define HERMON_GETPKEYTABLE_SWAP(pkeytable) \ 447 { \ 448 int i; \ 449 \ 450 for (i = 0; i < 32; i++) { \ 451 (pkeytable)->P_KeyTableBlocks[i] = \ 452 ddi_swap16((pkeytable)->P_KeyTableBlocks[i]); \ 453 } \ 454 } 455 #else 456 #define HERMON_GETPKEYTABLE_SWAP(pkeytable) 457 #endif 458 459 /* 460 * The Hermon MODIFY_MPT command can take the following opcode modifier 461 * options to specify whether to modify for ResizeSRQ() or to swap the 462 * full MPT entry. 463 */ 464 #define HERMON_CMD_MODIFY_MPT_RESIZESRQ 3 465 #define HERMON_CMD_MODIFY_MPT_SWAPFULL 5 466 467 /* 468 * Hermon MOD_STAT_CFG Opcode Modifier 469 */ 470 #define HERMON_MOD_STAT_CFG_PTR 0x0 471 #define HERMON_MOD_STAT_CFG_INLINE 0x1 472 #define HERMON_MOD_STAT_CFG_DEFAULTS 0xF 473 474 475 /* 476 * The hermon_mbox_t structure is used internally by the Hermon driver to track 477 * all the information necessary to manage mailboxes for the Hermon command 478 * interface. Specifically, by containing a pointer to the buffer, the 479 * PCI mapped address, the access handle, and a back pointer to the 480 * hermon_rsrc_t structure used to track this resource, it provides enough 481 * information allocate, use, and free any type of mailbox. 482 * 483 * The mb_indx, mb_next, and mb_prev fields are used only by the mailbox 484 * alloc/free routines (see hermon_impl_mbox_alloc/free() for more details) 485 * and are not read or modified by any mailbox consumers. They are used 486 * to implement a fast allocation mechanism. 487 */ 488 typedef struct hermon_mbox_s { 489 void *mb_addr; 490 uint64_t mb_mapaddr; 491 ddi_acc_handle_t mb_acchdl; 492 hermon_rsrc_t *mb_rsrcptr; 493 uint_t mb_indx; 494 uint_t mb_next; 495 uint_t mb_prev; 496 } hermon_mbox_t; 497 498 /* 499 * The hermon_mboxlist_t structure is used to track all the information 500 * relevant to the pools of Hermon mailboxes. Specifically, it has a pointer 501 * to an array of hermon_mbox_t structures, a lock and cv used for blocking 502 * on alloc when mailboxes are not available, and a head, tail, and entries 503 * free counter to keep track of which (if any) mailboxes are currently free. 504 * This is used (along with the mb_indx, mb_next, and mb_prev fields in the 505 * hermon_mbox_t) to implement the fast allocation mechanism. 506 */ 507 typedef struct hermon_mboxlist_s { 508 kmutex_t mbl_lock; 509 kcondvar_t mbl_cv; 510 hermon_mbox_t *mbl_mbox; 511 uint_t mbl_list_sz; 512 uint_t mbl_num_alloc; 513 uint_t mbl_head_indx; 514 uint_t mbl_tail_indx; 515 uint_t mbl_entries_free; 516 uint_t mbl_waiters; 517 uint_t mbl_pollers; 518 uint_t mbl_signal; 519 } hermon_mboxlist_t; 520 _NOTE(MUTEX_PROTECTS_DATA(hermon_mboxlist_t::mbl_lock, 521 hermon_mboxlist_t::mbl_mbox 522 hermon_mboxlist_t::mbl_list_sz 523 hermon_mboxlist_t::mbl_num_alloc 524 hermon_mboxlist_t::mbl_cv 525 hermon_mboxlist_t::mbl_head_indx 526 hermon_mboxlist_t::mbl_tail_indx 527 hermon_mboxlist_t::mbl_entries_free 528 hermon_mboxlist_t::mbl_waiters 529 hermon_mboxlist_t::mbl_pollers 530 hermon_mboxlist_t::mbl_signal 531 hermon_mbox_t::mb_next 532 hermon_mbox_t::mb_prev)) 533 534 /* 535 * The hermon_mbox_info_t structure is used by mailbox allocators to specify 536 * the type of mailbox(es) being requested. On a call to hermon_mbox_alloc() 537 * the mbi_alloc_flags may be set to HERMON_ALLOC_INMBOX, HERMON_ALLOC_OUTMBOX, 538 * or both. If it is able to allocate the request type(s) of mailboxes, 539 * hermon_mbox_alloc() will fill in the "mbi_in" and/or "mbi_out" pointers 540 * to point to valid hermon_mbox_t structures from the appropriate 541 * hermon_mboxlist_t (see above). 542 * This same structure is also passed to hermon_mbox_free(). It is the 543 * responsibility of the caller to hermon_mbox_alloc() to return this exact 544 * structure (unmodified) to hermon_mbox_free(). 545 * 546 * Note: If both "In" and "Out" mailboxes are requested, it is assured that 547 * no deadlock can result (from holding one mailbox while attempting to get 548 * the other). This is assured by the fact that the "In" mailbox will always 549 * be allocated first before attempting to allocate the "Out" 550 */ 551 typedef struct hermon_mbox_info_s { 552 uint_t mbi_alloc_flags; 553 uint_t mbi_sleep_context; 554 hermon_mbox_t *mbi_in; 555 hermon_mbox_t *mbi_out; 556 } hermon_mbox_info_t; 557 #define HERMON_ALLOC_INMBOX (1 << 0) 558 #define HERMON_ALLOC_OUTMBOX (1 << 1) 559 560 561 /* 562 * The hermon_cmd_t structure is used internally by the Hermon driver to track 563 * all the information necessary to manage outstanding firmware commands on 564 * the Hermon command interface. 565 * 566 * Each hermon_cmd_t structure contains a cv and lock which are used by the 567 * posting thread to block for completion (with cmd_status being overloaded 568 * to indicate the condition variable). The cmd_outparam field is used to 569 * return additional status from those Hermon commands that specifically 570 * require it. 571 * 572 * The cmd_indx, cmd_next, and cmd_prev fields are used by the outstanding 573 * command alloc/free routines (see hermon_outstanding_cmd_alloc/free() for 574 * more details). They are used (in much the same way as the mb_indx, 575 * mb_next, and mb_prev fields in hermon_mbox_t above) to implement a fast 576 * allocation mechanism. 577 */ 578 typedef struct hermon_cmd_s { 579 kmutex_t cmd_comp_lock; 580 kcondvar_t cmd_comp_cv; 581 uint64_t cmd_outparm; 582 uint_t cmd_status; 583 uint_t cmd_indx; 584 uint_t cmd_next; 585 uint_t cmd_prev; 586 } hermon_cmd_t; 587 _NOTE(MUTEX_PROTECTS_DATA(hermon_cmd_t::cmd_comp_lock, 588 hermon_cmd_t::cmd_comp_cv 589 hermon_cmd_t::cmd_status)) 590 591 /* 592 * The hermon_cmdlist_t structure is used in almost exactly the same way as 593 * the hermon_mboxlist_t above, but instead to track all the information 594 * relevant to the pool of outstanding Hermon commands. Specifically, it has 595 * a pointer to an array of hermon_cmd_t structures, a lock and cv used for 596 * blocking on alloc when outstanding command slots are not available, and a 597 * head, tail, and entries free counter to keep track of which (if any) 598 * command slots are currently free. This is used (along with the cmd_indx, 599 * cmd_next, and cmd_prev fields in the hermon_cmd_t) to implement the fast 600 * allocation mechanism. 601 */ 602 typedef struct hermon_cmdlist_s { 603 kmutex_t cml_lock; 604 kcondvar_t cml_cv; 605 hermon_cmd_t *cml_cmd; 606 uint_t cml_list_sz; 607 uint_t cml_num_alloc; 608 uint_t cml_head_indx; 609 uint_t cml_tail_indx; 610 uint_t cml_entries_free; 611 uint_t cml_waiters; 612 } hermon_cmdlist_t; 613 _NOTE(MUTEX_PROTECTS_DATA(hermon_cmdlist_t::cml_lock, 614 hermon_cmdlist_t::cml_cv 615 hermon_cmdlist_t::cml_cmd 616 hermon_cmdlist_t::cml_list_sz 617 hermon_cmdlist_t::cml_num_alloc 618 hermon_cmdlist_t::cml_head_indx 619 hermon_cmdlist_t::cml_tail_indx 620 hermon_cmdlist_t::cml_entries_free 621 hermon_cmdlist_t::cml_waiters 622 hermon_cmd_t::cmd_next 623 hermon_cmd_t::cmd_prev)) 624 _NOTE(LOCK_ORDER(hermon_cmdlist_t::cml_lock 625 hermon_cmd_t::cmd_comp_lock)) 626 627 /* 628 * The hermon_cmd_post_t structure is used by all the Hermon Firmware Command 629 * routines to post to Hermon firmware. The fields almost exactly mimic 630 * the fields in the Hermon HCR registers. The notable exception is the 631 * addition of the "cp_flags" field (which can be set to HERMON_CMD_SPIN or 632 * HERMON_CMD_NOSPIN). This flag really controls the value of the "e" bit 633 * in the HCR (i.e. the bit to indicate whether command should complete 634 * "in place" - in the HCR - or whether they should have their completions 635 * written to the command completion event queue. HERMON_CMD_SPIN means 636 * to allow commands to complete "in place" and to poll the "go" bit in 637 * the HCR to determine completion. 638 * 639 * We use HERMON_SLEEP and HERMON_NOSLEEP for our HERMON_CMD_ #defines. This is 640 * to maintain consistency with the rest of the SLEEP flags. Additionally, 641 * because HERMON_SLEEPFLAG_FOR_CONTEXT() in hermon_rsrc.h returns HERMON_SLEEP 642 * or NOSLEEP we must be compatible with this macro. 643 */ 644 typedef struct hermon_cmd_post_s { 645 uint64_t cp_inparm; 646 uint64_t cp_outparm; 647 uint32_t cp_inmod; 648 uint16_t cp_opcode; 649 uint16_t cp_opmod; 650 uint32_t cp_flags; 651 } hermon_cmd_post_t; 652 #define HERMON_CMD_SLEEP_NOSPIN HERMON_SLEEP 653 #define HERMON_CMD_NOSLEEP_SPIN HERMON_NOSLEEP 654 655 656 /* 657 * The following are the Hermon Firmware Command routines that accessible 658 * externally (i.e. throughout the rest of the Hermon driver software). 659 * These include the all the alloc/free routines, some initialization 660 * and cleanup routines, and the various specific Hermon firmware commands. 661 */ 662 int hermon_cmd_post(hermon_state_t *state, hermon_cmd_post_t *cmdpost); 663 int hermon_mbox_alloc(hermon_state_t *state, hermon_mbox_info_t *mbox_info, 664 uint_t mbox_wait); 665 void hermon_mbox_free(hermon_state_t *state, hermon_mbox_info_t *mbox_info); 666 int hermon_cmd_complete_handler(hermon_state_t *state, hermon_eqhdl_t eq, 667 hermon_hw_eqe_t *eqe); 668 int hermon_inmbox_list_init(hermon_state_t *state); 669 int hermon_intr_inmbox_list_init(hermon_state_t *state); 670 int hermon_outmbox_list_init(hermon_state_t *state); 671 int hermon_intr_outmbox_list_init(hermon_state_t *state); 672 void hermon_inmbox_list_fini(hermon_state_t *state); 673 void hermon_intr_inmbox_list_fini(hermon_state_t *state); 674 void hermon_outmbox_list_fini(hermon_state_t *state); 675 void hermon_intr_outmbox_list_fini(hermon_state_t *state); 676 int hermon_outstanding_cmdlist_init(hermon_state_t *state); 677 void hermon_outstanding_cmdlist_fini(hermon_state_t *state); 678 679 /* Added for MemFree */ 680 int hermon_map_cmd_post(hermon_state_t *state, hermon_dma_info_t *dinfo, 681 uint16_t opcode, ddi_dma_cookie_t cookie, uint_t ccount); 682 int hermon_map_fa_cmd_post(hermon_state_t *state); 683 int hermon_run_fw_cmd_post(hermon_state_t *state); 684 int hermon_set_icm_size_cmd_post(hermon_state_t *state); 685 int hermon_map_icm_aux_cmd_post(hermon_state_t *state); 686 int hermon_map_icm_cmd_post(hermon_state_t *state); 687 int hermon_disable_lam_cmd_post(hermon_state_t *state); 688 int hermon_unmap_icm_cmd_post(hermon_state_t *state, 689 hermon_dma_info_t *dma_info); 690 int hermon_unmap_icm_aux_cmd_post(hermon_state_t *state); 691 int hermon_unmap_fa_cmd_post(hermon_state_t *state); 692 693 /* 694 * INIT_HCA and CLOSE_HCA - used for initialization and teardown of Hermon 695 * device configuration 696 */ 697 int hermon_init_hca_cmd_post(hermon_state_t *state, 698 hermon_hw_initqueryhca_t *inithca, uint_t sleepflag); 699 int hermon_close_hca_cmd_post(hermon_state_t *state, uint_t sleepflag); 700 701 /* 702 * INIT_PORT, CLOSE_PORT, and SET_PORT - used for bring Hermon ports up and 703 * down, and to set properties of each port (e.g. PortInfo capability mask) 704 * NOTE: New names for the commands in Hermon (previously init_ close_ and 705 * set_ib 706 */ 707 int hermon_set_port_cmd_post(hermon_state_t *state, 708 hermon_hw_set_port_t *initport, uint_t port, uint_t sleepflag); 709 int hermon_init_port_cmd_post(hermon_state_t *state, uint_t port, 710 uint_t sleepflag); 711 int hermon_close_port_cmd_post(hermon_state_t *state, uint_t port, 712 uint_t sleepflag); 713 714 /* 715 * This common function is used to post the following Hermon QP state 716 * transition firmware commands: 717 * RTS2SQD, TOERR, TORST, RST2INIT, INIT2INIT, INIT2RTR, RTR2RTS, RTS2RTS, 718 * SQD2SQD, SQD2RTS, and SQERR2RTS. 719 */ 720 int hermon_cmn_qp_cmd_post(hermon_state_t *state, uint_t opcode, 721 hermon_hw_qpc_t *qp, uint_t qpindx, uint32_t opmask, uint_t sleepflag); 722 723 /* 724 * This common function is used to post the following Hermon query firmware 725 * commands: 726 * QUERY_DEV_LIM/CAP, QUERY_FW, QUERY_ADAPTER, QUERY_HCA, QUERY_MPT, 727 * QUERY_EQ, QUERY_CQ, and QUERY_QP. 728 */ 729 int hermon_cmn_query_cmd_post(hermon_state_t *state, uint_t opcode, 730 uint_t opmod, uint_t queryindx, void *query, uint_t size, uint_t sleepflag); 731 732 /* 733 * This common function is used to post the following Hermon resource ownership 734 * firmware commands: 735 * HW2SW_MPT, HW2SW_EQ, HW2SW_CQ, SW2HW_MPT, SW2HW_EQ, and SW2HW_CQ 736 */ 737 int hermon_cmn_ownership_cmd_post(hermon_state_t *state, uint_t opcode, 738 void *hwrsrc, uint_t size, uint_t hwrsrcindx, uint_t sleepflag); 739 740 /* 741 * MAD_IFC and helper functions - used for posting IB MADs to Hermon firmware. 742 * The helper functions are for the MADs most frequently used by the Hermon 743 * driver (internally). 744 */ 745 int hermon_mad_ifc_cmd_post(hermon_state_t *state, uint_t port, 746 uint_t sleepflag, uint32_t *mad, uint32_t *resp); 747 int hermon_getportinfo_cmd_post(hermon_state_t *state, uint_t port, 748 uint_t sleepflag, sm_portinfo_t *portinfo); 749 int hermon_getnodeinfo_cmd_post(hermon_state_t *state, uint_t sleepflag, 750 sm_nodeinfo_t *nodeinfo); 751 int hermon_getnodedesc_cmd_post(hermon_state_t *state, uint_t sleepflag, 752 sm_nodedesc_t *nodedesc); 753 int hermon_getguidinfo_cmd_post(hermon_state_t *state, uint_t port, 754 uint_t guidblock, uint_t sleepflag, sm_guidinfo_t *guidinfo); 755 int hermon_getpkeytable_cmd_post(hermon_state_t *state, uint_t port, 756 uint_t pkeyblock, uint_t sleepflag, sm_pkey_table_t *pkeytable); 757 int hermon_getperfcntr_cmd_post(hermon_state_t *state, uint_t port, 758 uint_t sleepflag, hermon_hw_sm_perfcntr_t *perfinfo, int reset); 759 /* 760 * WRITE_MTT - used for write MTT entries to the Hermon MTT table 761 */ 762 int hermon_write_mtt_cmd_post(hermon_state_t *state, hermon_rsrc_t *mtt, 763 uint64_t start_addr, uint_t nummtt, uint_t sleepflag); 764 765 /* 766 * SYNC_TPT - used to sync Hermon TPT caches 767 */ 768 int hermon_sync_tpt_cmd_post(hermon_state_t *state, uint_t sleepflag); 769 770 /* 771 * MAP_EQ - used for map classes of events to Hermon event queues (EQ) 772 */ 773 int hermon_map_eq_cmd_post(hermon_state_t *state, uint_t map, 774 uint_t eqcindx, uint64_t eqmapmask, uint_t sleepflag); 775 776 /* 777 * RESIZE_CQ - used for resize completion queue (CQ) 778 * opmod 0 is resize cq. opmod 1 is modify interrupt moderation. 779 */ 780 int hermon_resize_cq_cmd_post(hermon_state_t *state, hermon_hw_cqc_t *cqc, 781 uint_t cqcindx, uint32_t *prod_indx, uint_t sleepflag); 782 int hermon_modify_cq_cmd_post(hermon_state_t *state, hermon_hw_cqc_t *cqc, 783 uint_t cqcindx, uint_t opmod, uint_t sleepflag); 784 785 /* 786 * CONF_SPECIAL_QP - used to configure a pair of queue pairs for use as 787 * special QP. Necessary to enable full QP0 and/or QP1 operation. 788 */ 789 int hermon_conf_special_qp_cmd_post(hermon_state_t *state, uint_t qpindx, 790 uint_t qptype, uint_t sleepflag, uint_t opmod); 791 792 /* 793 * MGID_HASH, READ_MGM, and WRITE_MGM - used for manipulation of the 794 * hardware resource tables for multicast groups. 795 * NOTE: for intial implementation these functions retain their original 796 * names, though the proper hermon terminology is READ_MCG and 797 * WRITE_MCG - MGID_HASH retains its original name 798 */ 799 int hermon_mgid_hash_cmd_post(hermon_state_t *state, uint64_t mgid_h, 800 uint64_t mgid_l, uint64_t *mgid_hash, uint_t sleepflag); 801 int hermon_read_mgm_cmd_post(hermon_state_t *state, hermon_hw_mcg_t *mcg, 802 uint_t mcgindx, uint_t sleepflag); 803 int hermon_write_mgm_cmd_post(hermon_state_t *state, hermon_hw_mcg_t *mcg, 804 uint_t mcgindx, uint_t sleepflag); 805 806 /* 807 * MOD_STAT_CFG - used to configure (override) settings set in NVRAM before 808 * a call to QUERY_DEV_LIM. This is primarily used for SRQ settings in 809 * the firmware. 810 */ 811 int hermon_mod_stat_cfg_cmd_post(hermon_state_t *state); 812 813 /* 814 * MODIFY_MPT - used to change MPT attributes of a memory region. This 815 * was (Tavor/Arbel) primarily used for Resizing SRQs -- now may be used 816 * to modify MPT paramters 817 */ 818 int hermon_modify_mpt_cmd_post(hermon_state_t *state, hermon_hw_dmpt_t *mpt, 819 uint_t mptindx, uint_t flags, uint_t sleepflag); 820 821 /* 822 * RESIZE_SRQ is new in hermon, replacing opcodes in modify_mpt. It is used 823 * to resize the SRQ, by passing the new information in the same format as 824 * the original srqc, which the HCA will update appropriately 825 */ 826 827 int hermon_resize_srq_cmd_post(hermon_state_t *state, hermon_hw_srqc_t *srq, 828 uint_t srqnum, uint_t sleepflag); 829 830 /* 831 * CMD_NOP - used to test the interrupt/Event Queue mechanism. 832 */ 833 int hermon_nop_post(hermon_state_t *state, uint_t interval, uint_t sleep); 834 int hermon_setdebug_post(hermon_state_t *state); 835 /* 836 * READ_MTT - used to read an mtt entry at address. 837 */ 838 int hermon_read_mtt_cmd_post(hermon_state_t *state, uint64_t mtt_addr, 839 hermon_hw_mtt_t *mtt); 840 841 #ifdef __cplusplus 842 } 843 #endif 844 845 #endif /* _SYS_IB_ADAPTERS_HERMON_CMD_H */ 846