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 (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved. 24 */ 25 26 #ifndef _SYS_IB_ADAPTERS_HERMON_H 27 #define _SYS_IB_ADAPTERS_HERMON_H 28 29 /* 30 * hermon.h 31 * Contains the #defines and typedefs necessary for the Hermon softstate 32 * structure and for proper attach() and detach() processing. Also 33 * includes all the other Hermon header files (and so is the only header 34 * file that is directly included by the Hermon source files). 35 * Lastly, this file includes everything necessary for implementing the 36 * devmap interface and for maintaining the "mapped resource database". 37 */ 38 39 #include <sys/types.h> 40 #include <sys/conf.h> 41 #include <sys/ddi.h> 42 #include <sys/sunddi.h> 43 #include <sys/tnf_probe.h> 44 #include <sys/taskq.h> 45 #include <sys/atomic.h> 46 #ifdef FMA_TEST 47 #include <sys/modhash.h> 48 #endif 49 50 #include <sys/ib/ibtl/ibci.h> 51 #include <sys/ib/ibtl/impl/ibtl_util.h> 52 #include <sys/ib/adapters/mlnx_umap.h> 53 54 /* 55 * First include all the Hermon typedefs, then include all the other Hermon 56 * specific headers (many of which depend on the typedefs having already 57 * been defined). 58 */ 59 #include <sys/ib/adapters/hermon/hermon_typedef.h> 60 #include <sys/ib/adapters/hermon/hermon_hw.h> 61 62 #include <sys/ib/adapters/hermon/hermon_agents.h> 63 #include <sys/ib/adapters/hermon/hermon_cfg.h> 64 #include <sys/ib/adapters/hermon/hermon_cmd.h> 65 #include <sys/ib/adapters/hermon/hermon_cq.h> 66 #include <sys/ib/adapters/hermon/hermon_event.h> 67 #include <sys/ib/adapters/hermon/hermon_fcoib.h> 68 #include <sys/ib/adapters/hermon/hermon_ioctl.h> 69 #include <sys/ib/adapters/hermon/hermon_misc.h> 70 #include <sys/ib/adapters/hermon/hermon_mr.h> 71 #include <sys/ib/adapters/hermon/hermon_wr.h> 72 #include <sys/ib/adapters/hermon/hermon_qp.h> 73 #include <sys/ib/adapters/hermon/hermon_srq.h> 74 #include <sys/ib/adapters/hermon/hermon_rsrc.h> 75 #include <sys/ib/adapters/hermon/hermon_fm.h> 76 77 #ifdef __cplusplus 78 extern "C" { 79 #endif 80 81 /* 82 * Number of initial states to setup. Used in call to ddi_soft_state_init() 83 */ 84 #define HERMON_INITIAL_STATES 3 85 86 /* 87 * Macro and defines used to calculate device instance number from minor 88 * number (and vice versa). 89 */ 90 #define HERMON_MINORNUM_SHIFT 3 91 #define HERMON_DEV_INSTANCE(dev) (getminor((dev)) & \ 92 ((1 << HERMON_MINORNUM_SHIFT) - 1)) 93 94 /* 95 * Locations for the various Hermon hardware CMD,UAR & MSIx PCIe BARs 96 */ 97 #define HERMON_CMD_BAR 1 /* device config space */ 98 #define HERMON_UAR_BAR 2 /* UAR Region */ 99 #define HERMON_MSIX_BAR 3 /* MSI-X Table */ 100 101 #define HERMON_ONCLOSE_FLASH_INPROGRESS (1 << 0) 102 103 #define HERMON_MSIX_MAX 256 /* max # of interrupt vectors */ 104 105 /* 106 * VPD header size - or more rightfully, the area of interest for fwflash 107 * There's more, but we don't need it for our use so we don't read it 108 */ 109 #define HERMON_VPD_HDR_DWSIZE 0x10 /* 16 Dwords */ 110 #define HERMON_VPD_HDR_BSIZE 0x40 /* 64 Bytes */ 111 112 /* 113 * Offsets to be used w/ reset to save/restore PCI capability stuff 114 */ 115 #define HERMON_PCI_CAP_DEV_OFFS 0x08 116 #define HERMON_PCI_CAP_LNK_OFFS 0x10 117 118 119 /* 120 * Some defines for the software reset. These define the value that should 121 * be written to begin the reset (HERMON_SW_RESET_START), the delay before 122 * beginning to poll for completion (HERMON_SW_RESET_DELAY), the in-between 123 * polling delay (HERMON_SW_RESET_POLL_DELAY), and the value that indicates 124 * that the reset has not completed (HERMON_SW_RESET_NOTDONE). 125 */ 126 #define HERMON_SW_RESET_START 0x00000001 127 #define HERMON_SW_RESET_DELAY 1000000 /* 1000 ms, per 0.36 PRM */ 128 #define HERMON_SW_RESET_POLL_DELAY 100 /* 100 us */ 129 #define HERMON_SW_RESET_NOTDONE 0xFFFFFFFF 130 131 /* 132 * These defines are used in the Hermon software reset operation. They define 133 * the total number PCI registers to read/restore during the reset. And they 134 * also specify two config registers which should not be read or restored. 135 */ 136 #define HERMON_SW_RESET_NUMREGS 0x40 137 #define HERMON_SW_RESET_REG22_RSVD 0x16 /* 22 dec */ 138 #define HERMON_SW_RESET_REG23_RSVD 0x17 /* 23 dec */ 139 140 /* 141 * Macro used to output HCA warning messages. Note: HCA warning messages 142 * are only generated when an unexpected condition has been detected. This 143 * can be the result of a software bug or some other problem. Previously 144 * this was used for hardware errors, but those now use HERMON_FMANOTE 145 * instead, indicating that the driver state is more likely in an 146 * unpredictable state, and that shutdown/restart is suggested. 147 * 148 * HERMON_WARNING messages are not considered important enough to print 149 * to the console, just to the message log. 150 */ 151 #define HERMON_WARNING(state, string) \ 152 cmn_err(CE_CONT, "!hermon%d: %s\n", (state)->hs_instance, string) 153 154 /* 155 * Macro used to set attach failure messages. Also, the attach message buf 156 * size is set here. 157 */ 158 #define HERMON_ATTACH_MSGSIZE 80 159 #define HERMON_ATTACH_MSG(attach_buf, attach_msg) \ 160 (void) snprintf((attach_buf), HERMON_ATTACH_MSGSIZE, (attach_msg)); 161 #define HERMON_ATTACH_MSG_INIT(attach_buf) \ 162 (attach_buf)[0] = '\0'; 163 164 /* 165 * Macros used for controlling whether or not event callbacks will be forwarded 166 * to the IBTF. This is necessary because there are certain race conditions 167 * that can occur (e.g. calling IBTF with an asynch event before the IBTF 168 * registration has successfully completed or handling an event after we've 169 * detached from the IBTF.) 170 * 171 * HERMON_ENABLE_IBTF_CALLB() initializes the "hs_ibtfpriv" field in the Hermon 172 * softstate. When "hs_ibtfpriv" is non-NULL, it is OK to forward asynch 173 * and CQ events to the IBTF. 174 * 175 * HERMON_DO_IBTF_ASYNC_CALLB() and HERMON_DO_IBTF_CQ_CALLB() both set and clear 176 * the "hs_in_evcallb" flag, as necessary, to indicate that an IBTF 177 * callback is currently in progress. This is necessary so that we can 178 * block on this condition in hermon_detach(). 179 * 180 * HERMON_QUIESCE_IBTF_CALLB() is used in hermon_detach() to set the 181 * "hs_ibtfpriv" to NULL (thereby disabling any further IBTF callbacks) 182 * and to poll on the "hs_in_evcallb" flag. When this flag is zero, all 183 * IBTF callbacks have quiesced and it is safe to continue with detach 184 * (i.e. continue detaching from IBTF). 185 */ 186 #define HERMON_ENABLE_IBTF_CALLB(state, tmp_ibtfpriv) \ 187 (state)->hs_ibtfpriv = (tmp_ibtfpriv); 188 189 #define HERMON_DO_IBTF_ASYNC_CALLB(state, type, event) \ 190 _NOTE(NOW_INVISIBLE_TO_OTHER_THREADS((state)->hs_in_evcallb)) \ 191 (state)->hs_in_evcallb = 1; \ 192 ibc_async_handler((state)->hs_ibtfpriv, (type), (event)); \ 193 (state)->hs_in_evcallb = 0; 194 195 #define HERMON_DO_IBTF_CQ_CALLB(state, cq) \ 196 _NOTE(NOW_INVISIBLE_TO_OTHER_THREADS((state)->hs_in_evcallb)) \ 197 (state)->hs_in_evcallb = 1; \ 198 ibc_cq_handler((state)->hs_ibtfpriv, (cq)->cq_hdlrarg); \ 199 (state)->hs_in_evcallb = 0; 200 201 #define HERMON_QUIESCE_IBTF_CALLB(state) \ 202 { \ 203 uint_t count = 0; \ 204 \ 205 state->hs_ibtfpriv = NULL; \ 206 while (((state)->hs_in_evcallb != 0) && \ 207 (count++ < HERMON_QUIESCE_IBTF_CALLB_POLL_MAX)) { \ 208 drv_usecwait(HERMON_QUIESCE_IBTF_CALLB_POLL_DELAY); \ 209 } \ 210 } 211 212 /* 213 * Defines used by the HERMON_QUIESCE_IBTF_CALLB() macro to determine the 214 * duration and number of times (at maximum) to poll while waiting for IBTF 215 * callbacks to quiesce. 216 */ 217 #define HERMON_QUIESCE_IBTF_CALLB_POLL_DELAY 1 218 #define HERMON_QUIESCE_IBTF_CALLB_POLL_MAX 1000000 219 220 /* 221 * Macros to retrieve PCI id's of the device 222 */ 223 #define HERMON_DDI_PROP_GET(dip, property) \ 224 (ddi_prop_get_int(DDI_DEV_T_ANY, dip, DDI_PROP_DONTPASS, \ 225 property, -1)) 226 227 #define HERMON_GET_VENDOR_ID(dip) HERMON_DDI_PROP_GET(dip, "vendor-id") 228 #define HERMON_GET_DEVICE_ID(dip) HERMON_DDI_PROP_GET(dip, "device-id") 229 #define HERMON_GET_REVISION_ID(dip) HERMON_DDI_PROP_GET(dip, "revision-id") 230 231 /* 232 * Defines used to record the device mode to which Hermon driver has been 233 * attached. HERMON_MAINTENANCE_MODE is used when the device has 234 * come up in the "maintenance mode". In this mode, no InfiniBand interfaces 235 * are enabled, but the device's firmware can be updated/flashed (and 236 * test/debug interfaces should be useable). 237 * HERMON_HCA_MODE isused when the device has come up in the 238 * normal HCA mode. In this mode, all necessary InfiniBand interfaces are 239 * enabled (and, if necessary, HERMON firmware can be updated/flashed). 240 */ 241 #define HERMON_MAINTENANCE_MODE 1 242 #define HERMON_HCA_MODE 2 243 244 /* 245 * Used to determine if the device is operational, or not in maintenance mode. 246 * This means either the driver has attached successfully against an hermon 247 * device in hermon compatibility mode, or against a hermon device in full HCA 248 * mode. 249 */ 250 #define HERMON_IS_OPERATIONAL(mode) \ 251 (mode == HERMON_HCA_MODE) 252 253 /* 254 * The following define is used (in hermon_umap_db_set_onclose_cb()) to 255 * indicate that a cleanup callback is needed to undo initialization done 256 * by the firmware flash burn code. 257 */ 258 #define HERMON_ONCLOSE_FLASH_INPROGRESS (1 << 0) 259 260 /* 261 * The following enumerated type and structures are used during driver 262 * initialization. Note: The HERMON_DRV_CLEANUP_ALL type is used as a marker 263 * for end of the cleanup steps. No cleanup steps should be added after 264 * HERMON_DRV_CLEANUP_ALL. Any addition steps should be added before it. 265 */ 266 typedef enum { 267 HERMON_DRV_CLEANUP_LEVEL0, 268 HERMON_DRV_CLEANUP_LEVEL1, 269 HERMON_DRV_CLEANUP_LEVEL2, 270 HERMON_DRV_CLEANUP_LEVEL3, 271 HERMON_DRV_CLEANUP_LEVEL4, 272 HERMON_DRV_CLEANUP_LEVEL5, 273 HERMON_DRV_CLEANUP_LEVEL6, 274 HERMON_DRV_CLEANUP_LEVEL7, 275 HERMON_DRV_CLEANUP_LEVEL8, 276 HERMON_DRV_CLEANUP_LEVEL9, 277 HERMON_DRV_CLEANUP_LEVEL10, 278 HERMON_DRV_CLEANUP_LEVEL11, 279 HERMON_DRV_CLEANUP_LEVEL12, 280 HERMON_DRV_CLEANUP_LEVEL13, 281 HERMON_DRV_CLEANUP_LEVEL14, 282 HERMON_DRV_CLEANUP_LEVEL15, 283 HERMON_DRV_CLEANUP_LEVEL16, 284 HERMON_DRV_CLEANUP_LEVEL17, 285 HERMON_DRV_CLEANUP_LEVEL18, 286 HERMON_DRV_CLEANUP_LEVEL19, 287 /* No more driver cleanup steps below this point! */ 288 HERMON_DRV_CLEANUP_ALL 289 } hermon_drv_cleanup_level_t; 290 291 /* 292 * The hermon_dma_info_t structure is used to store information related to 293 * the various ICM resources' DMA allocations. The related ICM table and 294 * virtual address are stored here. The DMA and Access handles are stored 295 * here. Also, the allocation length and virtual (host) address. 296 */ 297 struct hermon_dma_info_s { 298 ddi_dma_handle_t dma_hdl; 299 ddi_acc_handle_t acc_hdl; 300 uint64_t icmaddr; /* ICM virtual address */ 301 uint64_t vaddr; /* host virtual address */ 302 uint_t length; /* length requested */ 303 uint_t icm_refcnt; /* refcnt */ 304 }; 305 _NOTE(SCHEME_PROTECTS_DATA("safe sharing", 306 hermon_dma_info_s::icm_refcnt)) 307 308 309 /* 310 * The hermon_cmd_reg_t structure is used to hold the address of the each of 311 * the most frequently accessed hardware registers. Specifically, it holds 312 * the HCA Command Registers (HCR, used to pass command and mailbox 313 * information back and forth to Hermon firmware) and the lock used to guarantee 314 * mutually exclusive access to the registers. 315 * Related to this, is the "clr_int" register which is used to clear the 316 * interrupt once all EQs have been serviced. 317 * Finally, there is the software reset register which is used to reinitialize 318 * the Hermon device and to put it into a known state at driver startup time. 319 * Below we also have the offsets (into the CMD register space) for each of 320 * the various registers. 321 */ 322 typedef struct hermon_cmd_reg_s { 323 hermon_hw_hcr_t *hcr; 324 kmutex_t hcr_lock; 325 uint64_t *clr_intr; 326 uint64_t *eq_arm; 327 uint64_t *eq_set_ci; 328 uint32_t *sw_reset; 329 uint32_t *sw_semaphore; 330 uint32_t *fw_err_buf; 331 } hermon_cmd_reg_t; 332 _NOTE(MUTEX_PROTECTS_DATA(hermon_cmd_reg_t::hcr_lock, 333 hermon_cmd_reg_t::hcr)) 334 335 /* SOME TEMPORARY PRINTING THINGS */ 336 #define HERMON_PRINT_CI (0x01 << 0) 337 #define HERMON_PRINT_MEM (0x01 << 1) 338 #define HERMON_PRINT_CQ (0x01 << 2) 339 340 341 #define HD_PRINT(state, mask) \ 342 if (state->hs_debug_lev & mask) 343 344 /* END PRINTING THINGS */ 345 346 /* 347 * The hermon_state_t structure is the HCA software state structure. It 348 * contains all the pointers and placeholder for everything that the HCA 349 * driver needs to properly operate. One of these structures exists for 350 * every instance of the HCA driver. 351 */ 352 struct hermon_state_s { 353 dev_info_t *hs_dip; 354 int hs_instance; 355 356 /* PCI device, vendor, and revision IDs */ 357 uint16_t hs_vendor_id; 358 uint16_t hs_device_id; 359 uint8_t hs_revision_id; 360 361 /* 362 * DMA information for the InfiniHost Context Memory (ICM), 363 * ICM Auxiliary allocation and the firmware. Also, record 364 * of ICM and ICMA sizes, in bytes. 365 */ 366 367 uint64_t hs_icm_sz; 368 hermon_icm_table_t *hs_icm; 369 uint64_t hs_icma_sz; 370 hermon_dma_info_t hs_icma_dma; 371 hermon_dma_info_t hs_fw_dma; 372 373 /* Hermon interrupt/MSI information */ 374 int hs_intr_types_avail; 375 uint_t hs_intr_type_chosen; 376 int hs_intrmsi_count; 377 int hs_intrmsi_avail; 378 int hs_intrmsi_allocd; 379 ddi_intr_handle_t hs_intrmsi_hdl[HERMON_MSIX_MAX]; 380 uint_t hs_intrmsi_pri; 381 int hs_intrmsi_cap; 382 ddi_cb_handle_t hs_intr_cb_hdl; 383 384 /* Do not use reserved EQs */ 385 uint_t hs_rsvd_eqs; 386 uint_t hs_cq_erreqnum; 387 388 /* cq_sched data */ 389 kmutex_t hs_cq_sched_lock; 390 hermon_cq_sched_t *hs_cq_sched_array; 391 hermon_cq_sched_t hs_cq_sched_default; 392 uint_t hs_cq_sched_array_size; 393 394 /* hermon HCA name and HCA part number */ 395 char hs_hca_name[64]; 396 char hs_hca_pn[64]; 397 int hs_hca_pn_len; 398 399 /* Hermon device operational mode */ 400 int hs_operational_mode; 401 402 /* Attach buffer saved per state to store detailed attach errors */ 403 char hs_attach_buf[HERMON_ATTACH_MSGSIZE]; 404 405 /* Hermon NodeGUID, SystemImageGUID, and NodeDescription */ 406 uint64_t hs_nodeguid; 407 uint64_t hs_sysimgguid; 408 char hs_nodedesc[64]; 409 410 /* Info passed to IBTF during registration */ 411 ibc_hca_info_t hs_ibtfinfo; 412 ibc_clnt_hdl_t hs_ibtfpriv; 413 414 /* 415 * Hermon register mapping. Holds the device access attributes, 416 * kernel mapped addresses, and DDI access handles for both 417 * Hermon's CMD and UAR BARs. 418 */ 419 ddi_device_acc_attr_t hs_reg_accattr; 420 caddr_t hs_reg_cmd_baseaddr; /* Hermon CMD BAR */ 421 ddi_acc_handle_t hs_reg_cmdhdl; 422 caddr_t hs_reg_uar_baseaddr; /* Hermon UAR BAR */ 423 ddi_acc_handle_t hs_reg_uarhdl; 424 caddr_t hs_reg_msi_baseaddr; /* Hermon MSIx BAR */ 425 ddi_acc_handle_t hs_reg_msihdl; 426 427 /* 428 * Some additional things for UAR Pages 429 */ 430 uint64_t hs_kernel_uar_index; /* kernel UAR index */ 431 uint64_t hs_bf_offset; /* offset from UAR */ 432 /* Bar to Blueflame */ 433 caddr_t hs_reg_bf_baseaddr; /* blueflame base */ 434 ddi_acc_handle_t hs_reg_bfhdl; /* blueflame handle */ 435 436 437 /* 438 * Hermon PCI config space registers. This array is used to 439 * save and restore the PCI config registers before and after a 440 * software reset. 441 */ 442 uint32_t hs_cfg_data[HERMON_SW_RESET_NUMREGS]; 443 /* for reset per Linux driver */ 444 uint32_t hs_pci_cap_offset; 445 uint32_t hs_pci_cap_devctl; 446 uint32_t hs_pci_cap_lnkctl; 447 448 /* 449 * Hermon UAR page resources. Holds the resource pointers for 450 * UAR page #0 (reserved) and for UAR page #1 (used for kernel 451 * driver doorbells). In addition, we save a pointer to the 452 * UAR page #1 doorbells which will be used throughout the driver 453 * whenever it is necessary to ring one of them. And, in case we 454 * are unable to do 64-bit writes to the page (because of system 455 * architecture), we include a lock (to ensure atomic 64-bit access). 456 */ 457 hermon_rsrc_t *hs_uarpg0_rsrc_rsrvd; 458 hermon_rsrc_t *hs_uarkpg_rsrc; 459 hermon_hw_uar_t *hs_uar; 460 kmutex_t hs_uar_lock; 461 462 /* 463 * Used during a call to open() if we are in maintenance mode, this 464 * field serves as a semi-unique rolling count index value, used only 465 * in the setup of umap_db entries. This is primarily needed to 466 * firmware device access ioctl operations can still be guaranteed to 467 * close in the event of an unplanned process exit, even in maintenance 468 * mode. 469 */ 470 uint_t hs_open_ar_indx; 471 472 /* 473 * Hermon command registers. This structure contains the addresses 474 * for each of the most frequently accessed CMD registers. Since 475 * almost all accesses to the Hermon hardware are through the Hermon 476 * command interface (i.e. the HCR), we save away the pointer to 477 * the HCR, as well as pointers to the ECR and INT registers (as 478 * well as their corresponding "clear" registers) for interrupt 479 * processing. And we also save away a pointer to the software 480 * reset register (see above). 481 */ 482 hermon_cmd_reg_t hs_cmd_regs; 483 uint32_t hs_cmd_toggle; 484 485 /* 486 * Hermon resource pointers. The following are pointers to the 487 * kmem cache (from which the Hermon resource handles are allocated), 488 * and the array of "resource pools" (which store all the pertinent 489 * information necessary to manage each of the various types of 490 * resources that are used by the driver. See hermon_rsrc.h for 491 * more detail. 492 */ 493 kmem_cache_t *hs_rsrc_cache; 494 hermon_rsrc_pool_info_t *hs_rsrc_hdl; 495 496 /* 497 * Hermon mailbox lists. These hold the information necessary to 498 * manage the pools of pre-allocated Hermon mailboxes (both "In" and 499 * "Out" type). See hermon_cmd.h for more detail. 500 */ 501 hermon_mboxlist_t hs_in_mblist; 502 hermon_mboxlist_t hs_out_mblist; 503 504 /* 505 * Hermon interrupt mailbox lists. We allocate both an "In" mailbox 506 * and an "Out" type mailbox for the interrupt context. This is in 507 * order to guarantee that a mailbox entry will always be available in 508 * the interrupt context, and we can NOSLEEP without having to worry 509 * about possible failure allocating the mbox. We create this as an 510 * mboxlist so that we have the potential for having multiple mboxes 511 * available based on the number of interrupts we can receive at once. 512 */ 513 hermon_mboxlist_t hs_in_intr_mblist; 514 hermon_mboxlist_t hs_out_intr_mblist; 515 516 /* 517 * Hermon outstanding command list. Used to hold all the information 518 * necessary to manage the Hermon "outstanding command list". See 519 * hermon_cmd.h for more detail. 520 */ 521 hermon_cmdlist_t hs_cmd_list; 522 523 /* 524 * This structure contains the Hermon driver's "configuration profile". 525 * This is the collected set of configuration information, such as 526 * number of QPs, CQs, mailboxes and other resources, sizes of 527 * individual resources, other system level configuration information, 528 * etc. See hermon_cfg.h for more detail. 529 */ 530 hermon_cfg_profile_t *hs_cfg_profile; 531 532 /* 533 * This flag contains the profile setting, selecting which profile the 534 * driver would use. This is needed in the case where we have to 535 * fallback to a smaller profile based on some DDR conditions. If we 536 * don't fallback, then it is set to the size of DDR in the system. 537 */ 538 uint32_t hs_cfg_profile_setting; 539 540 /* 541 * The following are a collection of resource handles used by the 542 * Hermon driver (internally). First is the protection domain (PD) 543 * handle that is used when mapping all kernel memory (work queues, 544 * completion queues, etc). Next is an array of EQ handles. This 545 * array is indexed by EQ number and allows the Hermon driver to quickly 546 * convert an EQ number into the software structure associated with the 547 * given EQ. Likewise, we have three arrays for CQ, QP and SRQ 548 * handles. These arrays are also indexed by CQ, QP or SRQ number and 549 * allow the driver to quickly find the corresponding CQ, QP or SRQ 550 * software structure. Note: while the EQ table is of fixed size 551 * (because there are a maximum of 64 EQs), each of the CQ, QP and SRQ 552 * handle lists must be allocated at driver startup. 553 */ 554 hermon_pdhdl_t hs_pdhdl_internal; 555 hermon_eqhdl_t hs_eqhdl[HERMON_NUM_EQ]; 556 kmutex_t hs_dbr_lock; /* lock for dbr mgmt */ 557 558 /* linked list of kernel dbr resources */ 559 hermon_dbr_info_t *hs_kern_dbr; 560 561 /* linked list of non-kernel dbr resources */ 562 hermon_user_dbr_t *hs_user_dbr; 563 564 /* 565 * The AVL tree is used to store information regarding QP number 566 * allocations. The lock protects access to the AVL tree. 567 */ 568 avl_tree_t hs_qpn_avl; 569 kmutex_t hs_qpn_avl_lock; 570 571 /* 572 * This field is used to indicate whether or not the Hermon driver is 573 * currently in an IBTF event callback elsewhere in the system. Note: 574 * It is "volatile" because we intend to poll on this value - in 575 * hermon_detach() - until we are assured that no further IBTF callbacks 576 * are currently being processed. 577 */ 578 volatile uint32_t hs_in_evcallb; 579 580 /* 581 * The following structures are used to store the results of several 582 * device query commands passed to the Hermon hardware at startup. 583 * Specifically, we have hung onto the results of QUERY_DDR (which 584 * gives information about how much DDR memory is present and where 585 * it is located), QUERY_FW (which gives information about firmware 586 * version numbers and the location and extent of firmware's footprint 587 * in DDR, QUERY_DEVLIM (which gives the device limitations/resource 588 * maximums) and QUERY_PORT (where some of the specs from DEVLIM moved), 589 * QUERY_ADAPTER (which gives additional miscellaneous 590 * information), and INIT/QUERY_HCA (which serves the purpose of 591 * recording what configuration information was passed to the firmware 592 * when the HCA was initialized). 593 */ 594 struct hermon_hw_queryfw_s hs_fw; 595 struct hermon_hw_querydevlim_s hs_devlim; 596 struct hermon_hw_query_port_s hs_queryport; 597 struct hermon_hw_set_port_s *hs_initport; 598 struct hermon_hw_queryadapter_s hs_adapter; 599 struct hermon_hw_initqueryhca_s hs_hcaparams; 600 601 /* 602 * The following are used for managing special QP resources. 603 * Specifically, we have a lock, a set of flags (in "hs_spec_qpflags") 604 * used to track the special QP resources, and two Hermon resource 605 * handle pointers. Each resource handle actually corresponds to two 606 * consecutive QP contexts (one per port) for each special QP type. 607 */ 608 kmutex_t hs_spec_qplock; 609 uint_t hs_spec_qpflags; 610 hermon_rsrc_t *hs_spec_qp0; 611 hermon_rsrc_t *hs_spec_qp1; 612 /* 613 * For Hermon, you have to alloc 8 qp's total, but the last 4 are 614 * unused/reserved. The following represents the handle for those 615 * last 4 qp's 616 */ 617 hermon_rsrc_t *hs_spec_qp_unused; 618 619 /* 620 * Related in some ways to the special QP handling above are these 621 * resources which are used specifically for implementing the Hermon 622 * agents (SMA, PMA, and BMA). Although, each of these agents does 623 * little more that intercept the appropriate incoming MAD and forward 624 * it along to the firmware (see hermon_agents.c for more details), we 625 * do still use a task queue to queue them up. We can also configure 626 * the driver to force firmware handling for certain classes of MAD, 627 * and, therefore, we require the agent list and number of agents 628 * in order to know what needs to be torn down at detach() time. 629 */ 630 hermon_agent_list_t *hs_agents; 631 ddi_taskq_t *hs_taskq_agents; 632 uint_t hs_num_agents; 633 634 /* 635 * Multicast group lists. These are used to track the "shadow" MCG 636 * lists that speed up the processing of attach and detach multicast 637 * group operations. See hermon_misc.h for more details. Note: we 638 * need the pointer to the "temporary" MCG entry here primarily 639 * because the size of a given MCG entry is configurable. Therefore, 640 * it is impossible to put this variable on the stack. And rather 641 * than allocate and deallocate the entry multiple times, we choose 642 * instead to preallocate it once and reuse it over and over again. 643 */ 644 kmutex_t hs_mcglock; 645 hermon_mcghdl_t hs_mcghdl; 646 hermon_hw_mcg_t *hs_mcgtmp; 647 648 /* 649 * Cache of the pkey table, sgid (guid-only) tables, and 650 * sgid (subnet) prefix. These arrays are set 651 * during port_query, and mainly used for generating MLX GSI wqes. 652 */ 653 ib_pkey_t *hs_pkey[HERMON_MAX_PORTS]; 654 ib_sn_prefix_t hs_sn_prefix[HERMON_MAX_PORTS]; 655 ib_guid_t *hs_guid[HERMON_MAX_PORTS]; 656 657 /* 658 * Used for tracking Hermon kstat information 659 */ 660 hermon_ks_info_t *hs_ks_info; 661 662 /* 663 * Used for Hermon info ioctl used by VTS 664 */ 665 kmutex_t hs_info_lock; 666 667 /* 668 * Used for Hermon FW flash burning. They are used exclusively 669 * within the ioctl calls for use when accessing the hermon 670 * flash device. 671 */ 672 kmutex_t hs_fw_flashlock; 673 int hs_fw_flashstarted; 674 dev_t hs_fw_flashdev; 675 uint32_t hs_fw_log_sector_sz; 676 uint32_t hs_fw_device_sz; 677 uint32_t hs_fw_flashbank; 678 uint32_t *hs_fw_sector; 679 uint32_t hs_fw_gpio[4]; 680 int hs_fw_cmdset; 681 682 /* 683 * Used for Hermon FM. They are basically used to manage 684 * the toggle switch to enable/disable Hermon FM. 685 * Please see the comment in hermon_fm.c. 686 */ 687 int hs_fm_capabilities; /* FM capabilities */ 688 int hs_fm_disable; /* Hermon FM disable flag */ 689 int hs_fm_state; /* Hermon FM state */ 690 boolean_t hs_fm_async_fatal; /* async internal error */ 691 uint32_t hs_fm_async_errcnt; /* async error count */ 692 boolean_t hs_fm_poll_suspend; /* poll thread suspend */ 693 kmutex_t hs_fm_lock; /* mutex for state */ 694 hermon_hca_fm_t *hs_fm_hca_fm; /* HCA FM pointer */ 695 ddi_acc_handle_t hs_fm_cmdhdl; /* fm-protected CMD hdl */ 696 ddi_acc_handle_t hs_fm_uarhdl; /* fm-protected UAR hdl */ 697 ddi_device_acc_attr_t hs_fm_accattr; /* fm-protected acc attr */ 698 ddi_periodic_t hs_fm_poll_thread; /* fma poll thread */ 699 int32_t hs_fm_degraded_reason; /* degradation cause */ 700 #ifdef FMA_TEST 701 mod_hash_t *hs_fm_test_hash; /* testset */ 702 mod_hash_t *hs_fm_id_hash; /* testid */ 703 #endif 704 /* FCoIB data */ 705 hermon_fcoib_t hs_fcoib; 706 boolean_t hs_fcoib_may_be_running; /* cq_poll test */ 707 708 /* 709 * Hermon fastreboot support. To sw-reset Hermon HCA, the driver 710 * needs to save/restore MSI-X tables and PBA. Those members are 711 * used for the purpose. 712 */ 713 /* Access handle for PCI config space */ 714 ddi_acc_handle_t hs_reg_pcihdl; /* PCI cfg handle */ 715 ddi_acc_handle_t hs_fm_pcihdl; /* fm handle */ 716 ushort_t hs_caps_ptr; /* MSI-X caps */ 717 ushort_t hs_msix_ctrl; /* MSI-X ctrl */ 718 719 /* members to handle MSI-X tables */ 720 ddi_acc_handle_t hs_reg_msix_tblhdl; /* MSI-X table handle */ 721 ddi_acc_handle_t hs_fm_msix_tblhdl; /* fm handle */ 722 char *hs_msix_tbl_addr; /* MSI-X table addr */ 723 char *hs_msix_tbl_entries; /* MSI-X table entry */ 724 size_t hs_msix_tbl_size; /* MSI-X table size */ 725 uint32_t hs_msix_tbl_offset; /* MSI-X table offset */ 726 uint32_t hs_msix_tbl_rnumber; /* MSI-X table reg# */ 727 728 /* members to handle MSI-X PBA */ 729 ddi_acc_handle_t hs_reg_msix_pbahdl; /* MSI-X PBA handle */ 730 ddi_acc_handle_t hs_fm_msix_pbahdl; /* fm handle */ 731 char *hs_msix_pba_addr; /* MSI-X PBA addr */ 732 char *hs_msix_pba_entries; /* MSI-X PBA entry */ 733 size_t hs_msix_pba_size; /* MSI-X PBA size */ 734 uint32_t hs_msix_pba_offset; /* MSI-X PBA offset */ 735 uint32_t hs_msix_pba_rnumber; /* MSI-X PBA reg# */ 736 737 boolean_t hs_quiescing; /* in fastreboot */ 738 }; 739 _NOTE(MUTEX_PROTECTS_DATA(hermon_state_s::hs_fw_flashlock, 740 hermon_state_s::hs_fw_flashstarted 741 hermon_state_s::hs_fw_flashdev 742 hermon_state_s::hs_fw_log_sector_sz 743 hermon_state_s::hs_fw_device_sz)) 744 _NOTE(MUTEX_PROTECTS_DATA(hermon_state_s::hs_spec_qplock, 745 hermon_state_s::hs_spec_qpflags 746 hermon_state_s::hs_spec_qp0 747 hermon_state_s::hs_spec_qp1)) 748 _NOTE(MUTEX_PROTECTS_DATA(hermon_state_s::hs_mcglock, 749 hermon_state_s::hs_mcghdl 750 hermon_state_s::hs_mcgtmp)) 751 _NOTE(DATA_READABLE_WITHOUT_LOCK(hermon_state_s::hs_in_evcallb 752 hermon_state_s::hs_fw_log_sector_sz 753 hermon_state_s::hs_fw_device_sz 754 hermon_state_s::hs_spec_qpflags 755 hermon_state_s::hs_spec_qp0 756 hermon_state_s::hs_spec_qp1)) 757 _NOTE(MUTEX_PROTECTS_DATA(hermon_state_s::hs_qpn_avl_lock, 758 hermon_state_s::hs_qpn_avl)) 759 _NOTE(SCHEME_PROTECTS_DATA("safe sharing", 760 hermon_state_s::hs_fm_async_fatal 761 hermon_state_s::hs_fw_sector)) 762 763 /* 764 * HERMON_IN_FASTREBOOT() shows if Hermon driver is at fastreboot. 765 * This macro should be used to check if the mutex lock can be used 766 * since the lock cannot be used if the driver is in the quiesce mode. 767 */ 768 #define HERMON_IN_FASTREBOOT(state) (state->hs_quiescing == B_TRUE) 769 770 /* 771 * Bit positions in the "hs_spec_qpflags" field above. The flags are (from 772 * least significant to most): (QP0,Port1), (QP0,Port2), (QP1,Port1), and 773 * (QP1,Port2). The masks are there to help with some specific allocation 774 * and freeing operations 775 */ 776 #define HERMON_SPECIAL_QP0_RSRC 0 777 #define HERMON_SPECIAL_QP0_RSRC_MASK 0x3 778 #define HERMON_SPECIAL_QP1_RSRC 2 779 #define HERMON_SPECIAL_QP1_RSRC_MASK 0xC 780 781 782 /* 783 * These flags specifies additional behaviors on database access. 784 * HERMON_UMAP_DB_REMOVE, for example, specifies that (if found) the database 785 * entry should be removed from the database. HERMON_UMAP_DB_IGNORE_INSTANCE 786 * specifies that a particular database query should ignore value in the 787 * "tdb_instance" field as a criterion for the search. 788 */ 789 #define HERMON_UMAP_DB_REMOVE (1 << 0) 790 #define HERMON_UMAP_DB_IGNORE_INSTANCE (1 << 1) 791 792 /* 793 * The hermon_umap_db_t structure contains what is referred to throughout the 794 * driver code as the "userland resources database". This structure contains 795 * all the necessary information to track resources that have been prepared 796 * for direct-from-userland access. There is an AVL tree ("hdl_umapdb_avl") 797 * which consists of the "hermon_umap_db_entry_t" (below) and a lock to ensure 798 * atomic access when adding or removing entries from the database. 799 */ 800 typedef struct hermon_umap_db_s { 801 kmutex_t hdl_umapdb_lock; 802 avl_tree_t hdl_umapdb_avl; 803 } hermon_umap_db_t; 804 805 /* 806 * The hermon_umap_db_priv_t structure currently contains information necessary 807 * to provide the "on close" callback to the firmware flash interfaces. It 808 * is intended that this structure could be extended to enable other "on 809 * close" callbacks as well. 810 */ 811 typedef struct hermon_umap_db_priv_s { 812 int (*hdp_cb)(void *); 813 void *hdp_arg; 814 } hermon_umap_db_priv_t; 815 816 /* 817 * The hermon_umap_db_common_t structure contains fields which are common 818 * between the database entries ("hermon_umap_db_entry_t") and the structure 819 * used to contain the search criteria ("hermon_umap_db_query_t"). This 820 * structure contains a key, a resource type (described above), an instance 821 * (corresponding to the driver instance which inserted the database entry), 822 * and a "value" field. Typically, "hdb_value" is a pointer to a Hermon 823 * resource object. Although for memory regions, the value field corresponds 824 * to the ddi_umem_cookie_t for the pinned userland memory. 825 * The structure also includes a placeholder for private data ("hdb_priv"). 826 * Currently this data is being used for holding "on close" callback 827 * information to allow certain kinds of cleanup even if a userland process 828 * prematurely exits. 829 */ 830 typedef struct hermon_umap_db_common_s { 831 uint64_t hdb_key; 832 uint64_t hdb_value; 833 uint_t hdb_type; 834 uint_t hdb_instance; 835 void *hdb_priv; 836 } hermon_umap_db_common_t; 837 838 /* 839 * The hermon_umap_db_entry_t structure is the entry in "userland resources 840 * database". As required by the AVL framework, each entry contains an 841 * "avl_node_t". Then, as required to implement the database, each entry 842 * contains a "hermon_umap_db_common_t" structure used to contain all of the 843 * relevant entries. 844 */ 845 typedef struct hermon_umap_db_entry_s { 846 avl_node_t hdbe_avlnode; 847 hermon_umap_db_common_t hdbe_common; 848 } hermon_umap_db_entry_t; 849 850 /* 851 * The hermon_umap_db_query_t structure is used in queries to the "userland 852 * resources database". In addition to the "hermon_umap_db_common_t" structure 853 * used to contain the various search criteria, this structure also contains 854 * a flags field "hqdb_flags" which can be used to specify additional behaviors 855 * (as described above). Specifically, the flags field can be used to specify 856 * that an entry should be removed from the database, if found, and to 857 * specify whether the database lookup should consider "tdb_instance" in the 858 * search. 859 */ 860 typedef struct hermon_umap_db_query_s { 861 uint_t hqdb_flags; 862 hermon_umap_db_common_t hqdb_common; 863 } hermon_umap_db_query_t; 864 _NOTE(MUTEX_PROTECTS_DATA(hermon_umap_db_s::hdl_umapdb_lock, 865 hermon_umap_db_entry_s::hdbe_avlnode 866 hermon_umap_db_entry_s::hdbe_common.hdb_key 867 hermon_umap_db_entry_s::hdbe_common.hdb_value 868 hermon_umap_db_entry_s::hdbe_common.hdb_type 869 hermon_umap_db_entry_s::hdbe_common.hdb_instance)) 870 871 /* 872 * The hermon_devmap_track_t structure contains all the necessary information 873 * to track resources that have been mapped through devmap. There is a 874 * back-pointer to the Hermon softstate, the logical offset corresponding with 875 * the mapped resource, the size of the mapped resource (zero indicates an 876 * "invalid mapping"), and a reference count and lock used to determine when 877 * to free the structure (specifically, this is necessary to handle partial 878 * unmappings). 879 */ 880 typedef struct hermon_devmap_track_s { 881 hermon_state_t *hdt_state; 882 uint64_t hdt_offset; 883 uint_t hdt_size; 884 int hdt_refcnt; 885 kmutex_t hdt_lock; 886 } hermon_devmap_track_t; 887 888 #define HERMON_ICM_SPLIT 64 889 #define HERMON_ICM_SPAN 4096 890 891 #define hermon_bitmap(bitmap, dma_info, icm_table, split_index, num_to_hdl) \ 892 bitmap = (icm_table)->icm_bitmap[split_index]; \ 893 if (bitmap == NULL) { \ 894 _NOTE(NOW_INVISIBLE_TO_OTHER_THREADS(*(icm_table))) \ 895 int num_spans = (icm_table)->num_spans; \ 896 bitmap = \ 897 (icm_table)->icm_bitmap[split_index] = \ 898 kmem_zalloc((num_spans + 7) / 8, KM_SLEEP); \ 899 ASSERT((icm_table)->icm_dma[split_index] == NULL); \ 900 (icm_table)->icm_dma[split_index] = \ 901 kmem_zalloc(num_spans * sizeof (hermon_dma_info_t), \ 902 KM_SLEEP); \ 903 if (num_to_hdl) { \ 904 ASSERT((icm_table)->num_to_hdl[split_index] == NULL); \ 905 (icm_table)->num_to_hdl[split_index] = \ 906 kmem_zalloc(num_spans * \ 907 sizeof (void **), KM_SLEEP); \ 908 } \ 909 } \ 910 dma_info = (icm_table)->icm_dma[split_index] 911 912 /* 913 * The hermon_icm_table_t encodes data pertaining to a given ICM table, and 914 * holds an array of hermon_dma_info_t's related to its backing memory. Each 915 * ICM table is sized during initialization, but real memory is allocated 916 * and mapped into and out of ICM in the device throughout the life of the 917 * instance. We use a bitmap to determine whether or not a given ICM object 918 * has memory backing it or not, and an array of hermon_dma_info_t's to house 919 * the actual allocations. Memory is allocated in chunks of span_size, stored 920 * in the icm_dma array, and can later be looked up by using the bitmap index. 921 * The total number of ICM spans is equal to table_size / span_size. We also 922 * keep track of the ICM characteristics, such as ICM object size and the 923 * number of entries in the ICM area. 924 */ 925 struct hermon_icm_table_s { 926 kmutex_t icm_table_lock; 927 kcondvar_t icm_table_cv; 928 uint8_t icm_busy; 929 hermon_rsrc_type_t icm_type; 930 uint64_t icm_baseaddr; 931 uint64_t table_size; 932 uint64_t num_entries; /* maximum #entries */ 933 uint32_t object_size; 934 uint32_t span; /* #rsrc's per span */ 935 uint32_t num_spans; /* #dmainfos in icm_dma */ 936 uint32_t split_shift; 937 uint32_t span_mask; 938 uint32_t span_shift; 939 uint32_t rsrc_mask; 940 uint16_t log_num_entries; 941 uint16_t log_object_size; 942 /* three arrays of pointers, each pointer points to arrays */ 943 uint8_t *icm_bitmap[HERMON_ICM_SPLIT]; 944 hermon_dma_info_t *icm_dma[HERMON_ICM_SPLIT]; 945 void ***num_to_hdl[HERMON_ICM_SPLIT]; /* qp/cq/srq */ 946 }; 947 /* 948 * Split the rsrc index into three pieces: 949 * 950 * index1 - icm_bitmap[HERMON_ICM_SPLIT], icm_dma[HERMON_ICM_SPLIT] 951 * index2 - bitmap[], dma[] 952 * offset - rsrc within the icm mapping 953 */ 954 #define hermon_index(index1, index2, rindx, table, offset) \ 955 index1 = (rindx) >> table->split_shift; \ 956 index2 = ((rindx) & table->span_mask) >> table->span_shift; \ 957 offset = (rindx) & table->rsrc_mask 958 959 /* Defined in hermon.c */ 960 int hermon_dma_alloc(hermon_state_t *state, hermon_dma_info_t *dma_info, 961 uint16_t opcode); 962 void hermon_dma_attr_init(hermon_state_t *state, ddi_dma_attr_t *dma_attr); 963 void hermon_dma_free(hermon_dma_info_t *info); 964 int hermon_icm_alloc(hermon_state_t *state, hermon_rsrc_type_t type, 965 uint32_t icm_index1, uint32_t icm_index2); 966 void hermon_icm_free(hermon_state_t *state, hermon_rsrc_type_t type, 967 uint32_t icm_index1, uint32_t icm_index2); 968 void *hermon_icm_num_to_hdl(hermon_state_t *state, hermon_rsrc_type_t type, 969 uint32_t idx); 970 void hermon_icm_set_num_to_hdl(hermon_state_t *state, hermon_rsrc_type_t type, 971 uint32_t idx, void *hdl); 972 int hermon_device_mode(hermon_state_t *state); 973 974 /* Defined in hermon_umap.c */ 975 int hermon_devmap(dev_t dev, devmap_cookie_t dhp, offset_t off, size_t len, 976 size_t *maplen, uint_t model); 977 ibt_status_t hermon_umap_ci_data_in(hermon_state_t *state, 978 ibt_ci_data_flags_t flags, ibt_object_type_t object, void *hdl, 979 void *data_p, size_t data_sz); 980 ibt_status_t hermon_umap_ci_data_out(hermon_state_t *state, 981 ibt_ci_data_flags_t flags, ibt_object_type_t object, void *hdl, 982 void *data_p, size_t data_sz); 983 void hermon_umap_db_init(void); 984 void hermon_umap_db_fini(void); 985 hermon_umap_db_entry_t *hermon_umap_db_alloc(uint_t instance, uint64_t key, 986 uint_t type, uint64_t value); 987 void hermon_umap_db_free(hermon_umap_db_entry_t *umapdb); 988 void hermon_umap_db_add(hermon_umap_db_entry_t *umapdb); 989 void hermon_umap_db_add_nolock(hermon_umap_db_entry_t *umapdb); 990 int hermon_umap_db_find(uint_t instance, uint64_t key, uint_t type, 991 uint64_t *value, uint_t flags, hermon_umap_db_entry_t **umapdb); 992 int hermon_umap_db_find_nolock(uint_t instance, uint64_t key, uint_t type, 993 uint64_t *value, uint_t flags, hermon_umap_db_entry_t **umapdb); 994 void hermon_umap_umemlock_cb(ddi_umem_cookie_t *umem_cookie); 995 int hermon_umap_db_set_onclose_cb(dev_t dev, uint64_t flag, 996 int (*callback)(void *), void *arg); 997 int hermon_umap_db_clear_onclose_cb(dev_t dev, uint64_t flag); 998 int hermon_umap_db_handle_onclose_cb(hermon_umap_db_priv_t *priv); 999 int hermon_rsrc_hw_entries_init(hermon_state_t *state, 1000 hermon_rsrc_hw_entry_info_t *info); 1001 void hermon_rsrc_hw_entries_fini(hermon_state_t *state, 1002 hermon_rsrc_hw_entry_info_t *info); 1003 1004 #ifdef __cplusplus 1005 } 1006 #endif 1007 1008 #endif /* _SYS_IB_ADAPTERS_HERMON_H */ 1009