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 2008 Emulex. All rights reserved. 24 * Use is subject to License terms. 25 */ 26 27 28 #ifndef _EMLXS_OS_H 29 #define _EMLXS_OS_H 30 31 #ifdef __cplusplus 32 extern "C" { 33 #endif 34 35 #define EMLXS_MODREV2 2 /* Old Solaris 8 & 9 interface */ 36 #define EMLXS_MODREV3 3 /* New Solaris 10 & 11 interface */ 37 #define EMLXS_MODREV4 4 /* Sun FC packet change */ 38 /* Symbolic Node Name interface */ 39 #define EMLXS_MODREV5 5 /* New Sun NPIV Interface */ 40 41 #define EMLXS_MODREV2X 2 /* Old Solaris 8 & 9 x86 interface */ 42 #define EMLXS_MODREV3X 3 /* New Solaris 10 & 11 x86 interface */ 43 44 45 /* 46 * DRIVER LEVEL FEATURES 47 */ 48 #define DFC_SUPPORT /* 2.20 driver */ 49 #define DHCHAP_SUPPORT /* 2.21 driver */ 50 51 #define SATURN_MSI_SUPPORT /* 2.30 driver */ 52 53 #define MENLO_SUPPORT /* 2.30 driver */ 54 #define MENLO_TEST /* 2.30 driver - Supports hornet test params */ 55 56 #define MBOX_EXT_SUPPORT /* 2.30 driver */ 57 #define SLI3_SUPPORT /* 2.30 driver - Required for NPIV */ 58 59 /* #define IDLE_TIMER Not yet - untested */ 60 61 62 /* 63 * OS LEVEL FEATURES 64 */ 65 66 #ifdef S8 67 #define EMLXS_MODREV EMLXS_MODREV2 68 69 #ifdef EMLXS_I386 70 #define EMLXS_MODREVXEMLXS_MODREV2X 71 #endif /* EMLXS_I386 */ 72 #endif /* S8 */ 73 74 75 #ifdef S9 76 #define EMLXS_MODREV EMLXS_MODREV2 77 #define MSI_SUPPORT 78 79 #ifdef EMLXS_I386 80 #define EMLXS_MODREVX EMLXS_MODREV2X 81 #endif /* EMLXS_I386 */ 82 #endif /* S9 */ 83 84 85 #ifdef S10 86 #define EMLXS_MODREV EMLXS_MODREV3 87 #define MSI_SUPPORT 88 89 #ifdef SLI3_SUPPORT 90 #define NPIV_SUPPORT 91 #endif /* SLI3_SUPPORT */ 92 93 #ifdef EMLXS_I386 94 #define EMLXS_MODREVX EMLXS_MODREV2X 95 #endif /* EMLXS_I386 */ 96 #endif /* S10 */ 97 98 99 #ifdef S11 100 #define MSI_SUPPORT 101 #define SFCT_SUPPORT /* COMSTAR Support */ 102 103 #ifdef SLI3_SUPPORT 104 #define NPIV_SUPPORT 105 106 #ifdef NPIV_SUPPORT 107 #define SUN_NPIV_SUPPORT /* Nevada Build 91+ */ 108 #endif /* NPIV_SUPPORT */ 109 #endif /* SLI3_SUPPORT */ 110 111 #ifdef SUN_NPIV_SUPPORT 112 #define EMLXS_MODREV EMLXS_MODREV5 /* Sun NPIV Enhancement */ 113 #else 114 #define EMLXS_MODREV EMLXS_MODREV4 115 #endif /* SUN_NPIV_SUPPORT */ 116 117 #ifdef EMLXS_I386 118 #define EMLXS_MODREVX EMLXS_MODREV2X 119 #endif /* EMLXS_I386 */ 120 #endif /* S11 */ 121 122 /* 123 * SUBFEATURES 124 */ 125 #ifdef SFCT_SUPPORT 126 #define MODSYM_SUPPORT /* Dynamic Module Loading Support */ 127 #define FCIO_SUPPORT /* FCIO IOCTL support */ 128 #endif /* SFCT_SUPPORT */ 129 130 131 #ifndef EMLXS_MODREV 132 #define EMLXS_MODREV 0 133 #endif /* EMLXS_MODREV */ 134 135 #ifndef EMLXS_MODREVX 136 #define EMLXS_MODREVX 0 137 #endif /* EMLXS_MODREVX */ 138 139 /* Create combined definition */ 140 #if defined(S10) || defined(S11) 141 #define S10S11 142 #endif /* S10 or S11 */ 143 144 #if defined(S8) || defined(S9) 145 #define S8S9 146 #endif /* S8 or S9 */ 147 148 149 #define DRIVER_NAME "emlxs" 150 151 #include <sys/types.h> 152 #include <sys/varargs.h> 153 #include <sys/devops.h> 154 #include <sys/param.h> 155 #include <sys/user.h> 156 #include <sys/buf.h> 157 #include <sys/ioctl.h> 158 #include <sys/uio.h> 159 #include <sys/fcntl.h> 160 161 #include <sys/cmn_err.h> 162 #include <sys/stropts.h> 163 #include <sys/kmem.h> 164 165 #include <sys/errno.h> 166 #include <sys/open.h> 167 #include <sys/kmem.h> 168 #include <sys/poll.h> 169 #include <sys/thread.h> 170 #include <sys/taskq.h> 171 #include <sys/debug.h> 172 #include <sys/cpu.h> 173 #include <sys/autoconf.h> 174 #include <sys/conf.h> 175 #include <sys/stat.h> 176 #include <sys/var.h> 177 178 #include <sys/map.h> 179 #include <sys/file.h> 180 #include <sys/syslog.h> 181 #include <sys/disp.h> 182 #include <sys/taskq.h> 183 184 #include <sys/ddi.h> 185 #include <sys/sunddi.h> 186 #include <sys/promif.h> 187 #include <sys/ethernet.h> 188 #include <vm/seg_kmem.h> 189 #include <sys/utsname.h> 190 #include <sys/modctl.h> 191 #include <sys/scsi/scsi.h> 192 #include <sys/varargs.h> 193 #include <sys/atomic.h> 194 195 #include <emlxs_hbaapi.h> 196 197 198 #ifdef S11 199 200 /* ULP header files */ 201 #include <sys/fibre-channel/fc.h> 202 #include <sys/fibre-channel/impl/fc_fcaif.h> 203 204 #else /* !S11 */ 205 206 /* ULP header files */ 207 #include <sys/fibre-channel/fcio.h> 208 #include <sys/fibre-channel/fc.h> 209 #include <sys/fibre-channel/fc_appif.h> 210 #include <sys/fibre-channel/fc_types.h> 211 #include <sys/fibre-channel/impl/fc_error.h> 212 #include <sys/fibre-channel/impl/fc_fla.h> 213 #include <sys/fibre-channel/impl/fc_linkapp.h> 214 #include <sys/fibre-channel/impl/fcal.h> 215 #include <sys/fibre-channel/impl/fcgs2.h> 216 #include <sys/fibre-channel/impl/fcph.h> 217 #include <sys/fibre-channel/impl/fc_ulpif.h> 218 #include <sys/fibre-channel/impl/fc_fcaif.h> 219 #include <sys/fibre-channel/impl/fctl.h> 220 #include <sys/fibre-channel/impl/fctl_private.h> 221 #include <sys/fibre-channel/ulp/fcp.h> 222 #include <sys/fibre-channel/ulp/fcp_util.h> 223 224 #endif /* S11 */ 225 226 227 #ifndef FC_HBA_PORTSPEED_8GBIT 228 #define FC_HBA_PORTSPEED_8GBIT 16 229 #endif /* FC_HBA_PORTSPEED_8GBIT */ 230 231 #ifndef FP_DEFAULT_SID 232 #define FP_DEFAULT_SID (0x000AE) 233 #endif /* FP_DEFAULT_SID */ 234 235 #ifndef FP_DEFAULT_DID 236 #define FP_DEFAULT_DID (0x000EA) 237 #endif /* FP_DEFAULT_DID */ 238 239 #ifdef MSI_SUPPORT 240 #pragma weak ddi_intr_get_supported_types 241 #pragma weak ddi_intr_get_nintrs 242 #pragma weak ddi_intr_add_handler 243 #pragma weak ddi_intr_remove_handler 244 #pragma weak ddi_intr_get_hilevel_pri 245 #pragma weak ddi_intr_enable 246 #pragma weak ddi_intr_disable 247 #pragma weak ddi_intr_get_cap 248 #pragma weak ddi_intr_get_pri 249 #pragma weak ddi_intr_alloc 250 #pragma weak ddi_intr_free 251 #pragma weak ddi_intr_block_enable 252 #pragma weak ddi_intr_block_disable 253 extern int ddi_intr_get_supported_types(); 254 255 #ifdef S9 256 /* Obtained from /usr/include/sys/ddi_intr.h */ 257 #ifndef ddi_intr_handle_t 258 typedef void *ddi_intr_handle_t; 259 #endif /* ddi_intr_handle_t */ 260 261 #ifndef DDI_INTR_TYPE_FIXED 262 #define DDI_INTR_TYPE_FIXED 0x1 263 #endif 264 265 #ifndef DDI_INTR_TYPE_MSI 266 #define DDI_INTR_TYPE_MSI 0x2 267 #endif 268 269 #ifndef DDI_INTR_TYPE_MSIX 270 #define DDI_INTR_TYPE_MSIX 0x4 271 #endif 272 273 #ifndef DDI_INTR_ALLOC_NORMAL 274 #define DDI_INTR_ALLOC_NORMAL 0 /* Non-strict alloc */ 275 #endif 276 277 #ifndef DDI_INTR_FLAG_BLOCK 278 #define DDI_INTR_FLAG_BLOCK 0x0100 /* (RO) requires block enable */ 279 #endif 280 #endif /* S9 */ 281 282 #endif /* MSI_SUPPORT */ 283 284 #ifndef MODSYM_SUPPORT 285 #pragma weak fc_fca_init 286 #pragma weak fc_fca_attach 287 #pragma weak fc_fca_detach 288 #endif /* MODSYM_SUPPORT */ 289 290 /* S11 flag for dma_attr_flags for ddi_dma_attr_t */ 291 #ifndef DDI_DMA_RELAXED_ORDERING 292 #define DDI_DMA_RELAXED_ORDERING 0x400 293 #endif /* DDI_DMA_RELAXED_ORDERING */ 294 295 296 #ifdef EMLXS_SPARC 297 #define EMLXS_BIG_ENDIAN 298 #endif /* EMLXS_SPARC */ 299 300 #ifdef EMLXS_I386 301 #define EMLXS_LITTLE_ENDIAN 302 #endif /* EMLXS_I386 */ 303 304 305 /* Solaris 8 does not define this */ 306 #ifndef TASKQ_DYNAMIC 307 #define TASKQ_DYNAMIC 0x0004 308 #endif /* TASKQ_DYNAMIC */ 309 310 #ifdef _LP64 311 #define DEAD_PTR 0xdeadbeefdeadbeef 312 #else 313 #define DEAD_PTR 0xdeadbeef 314 #endif /* _LP64 */ 315 316 #ifndef FC_STATE_8GBIT_SPEED 317 /* This was obtained from OpenSolaris */ 318 #define FC_STATE_8GBIT_SPEED 0x0700 /* 8 Gbit/sec */ 319 #endif /* FC_STATE_8GBIT_SPEED */ 320 321 #define FC_STATE_QUAD_SPEED 0x0500 322 323 #ifndef BURSTSIZE 324 #define BURSTSIZE 325 #define BURST1 0x01 326 #define BURST2 0x02 327 #define BURST4 0x04 328 #define BURST8 0x08 329 #define BURST16 0x10 330 #define BURST32 0x20 331 #define BURST64 0x40 332 #ifdef _LP64 333 #define BURSTSIZE_MASK 0x7f 334 #else 335 #define BURSTSIZE_MASK 0x3f 336 #endif /* _LP64 */ 337 #define DEFAULT_BURSTSIZE (BURSTSIZE_MASK) /* all burst sizes */ 338 #endif /* BURSTSIZE */ 339 340 #define putPaddrLow(addr) ((uint32_t)((uint64_t)(addr) & 0xffffffff)) 341 #define putPaddrHigh(addr) ((uint32_t)((uint64_t)(addr) >> 32)) 342 #define getPaddr(high, low) ((uint64_t)(((uint64_t)(high) << 32) | \ 343 ((uint64_t)(low) & 0xffffffff))) 344 345 #ifndef TRUE 346 #define TRUE 1 347 #endif /* TRUE */ 348 349 #ifndef FALSE 350 #define FALSE 0 351 #endif /* FALSE */ 352 353 #define DMA_READ_WRITE 0 354 #define DMA_READ_ONLY 1 355 #define DMA_WRITE_ONLY 2 356 357 #define DMA_SUCC 1 358 359 #define MAX_FC_BRDS 256 /* Maximum # boards per system */ 360 361 #define DELAYMS(ms) drv_usecwait((ms*1000)) 362 #define DELAYUS(us) drv_usecwait(us) 363 364 #define emlxs_mpdata_sync(h, a, b, c) \ 365 if (h) {\ 366 (void) ddi_dma_sync((ddi_dma_handle_t)(h),\ 367 (off_t)(a), (size_t)(b), (uint_t)c);\ 368 } 369 370 371 372 #define PKT2PRIV(pkt) ((emlxs_buf_t *)(pkt)->pkt_fca_private) 373 #define PRIV2PKT(sbp) sbp->pkt 374 375 #define EMLXS_INUMBER 0 376 #define EMLXS_MSI_INUMBER 0 377 378 #define EMLXS_DMA_ALIGN BURST16 379 380 /* 381 * Register indices in PCI configuration space. 382 */ 383 #define SBUS_FLASH_RD 0 /* FCODE-Flash Read only index */ 384 #define SBUS_FLASH_RDWR 1 /* FCODE-Flash Read/Write index */ 385 #define SBUS_DFLY_SLIM_RINDEX 2 /* DragonFly SLIM regs index */ 386 #define SBUS_DFLY_CSR_RINDEX 3 /* DragonFly I/O regs index */ 387 #define SBUS_TITAN_CORE_RINDEX 4 /* TITAN Core register index */ 388 #define SBUS_DFLY_PCI_CFG_RINDEX 5 /* DragonFly PCI ConfigSpace regs */ 389 /* index */ 390 #define SBUS_TITAN_PCI_CFG_RINDEX 6 /* TITAN PCI ConfigSpace regs index */ 391 #define SBUS_TITAN_CSR_RINDEX 7 /* TITAN Control/Status regs index */ 392 393 #define PCI_CFG_RINDEX 0 394 #define PCI_SLIM_RINDEX 1 395 #define PCI_CSR_RINDEX 2 396 397 #define EMLXS_MAX_UBUFS 65535 398 399 /* Tokens < EMLXS_UB_TOKEN_OFFSET are reserved for ELS response oxids */ 400 #define EMLXS_UB_TOKEN_OFFSET 0x100 401 402 typedef struct emlxs_ub_priv { 403 fc_unsol_buf_t *ubp; 404 void *port; 405 406 uint32_t bpl_size; 407 uint8_t *bpl_virt; /* virtual address ptr */ 408 uint64_t bpl_phys; /* mapped address */ 409 void *bpl_data_handle; 410 void *bpl_dma_handle; 411 412 uint32_t ip_ub_size; 413 uint8_t *ip_ub_virt; /* virtual address ptr */ 414 ddi_dma_cookie_t ip_ub_dma_cookies[64]; 415 ddi_acc_handle_t ip_ub_data_handle; 416 ddi_dma_handle_t ip_ub_dma_handle; 417 uint32_t ip_ub_cookie_cnt; 418 uint32_t FC4type; 419 420 uint16_t flags; 421 #define EMLXS_UB_FREE 0x0000 422 #define EMLXS_UB_IN_USE 0x0001 423 #define EMLXS_UB_REPLY 0x0002 424 #define EMLXS_UB_RESV 0x0004 425 #define EMLXS_UB_TIMEOUT 0x0008 426 #define EMLXS_UB_INTERCEPT 0x0010 427 428 uint16_t available; 429 430 uint32_t timeout; /* Timeout period in seconds */ 431 uint32_t time; /* EMLXS_UB_IN_USE timestamp */ 432 uint32_t cmd; 433 uint32_t token; 434 435 struct emlxs_unsol_buf *pool; 436 437 struct emlxs_ub_priv *next; 438 439 } emlxs_ub_priv_t; 440 441 442 typedef struct emlxs_unsol_buf { 443 struct emlxs_unsol_buf *pool_prev; /* ptr to prev type of */ 444 /* unsol_buf_header */ 445 struct emlxs_unsol_buf *pool_next; /* ptr to next type of */ 446 /* unsol_buf_header */ 447 448 uint32_t pool_type; /* FC-4 type */ 449 uint32_t pool_buf_size; /* buffer size for this pool */ 450 451 uint32_t pool_nentries; /* no.of bufs in pool */ 452 uint32_t pool_available; /* no.of bufs avail in pool */ 453 454 uint32_t pool_flags; 455 #define POOL_DESTROY 0x00000001 /* Pool is marked for destruction */ 456 457 uint32_t pool_free; /* Number of free buffers */ 458 uint32_t pool_free_resv; /* Number of free reserved buffers */ 459 460 uint32_t pool_first_token; /* First ub_priv->token in pool */ 461 uint32_t pool_last_token; /* Last ub_priv->token in pool */ 462 463 fc_unsol_buf_t *fc_ubufs; /* array of unsol buf structs */ 464 465 } emlxs_unsol_buf_t; 466 467 468 #ifndef FC_REASON_NONE 469 #define FC_REASON_NONE 0 470 #endif /* FC_REASON_NONE */ 471 472 #ifndef FC_ACTION_NONE 473 #define FC_ACTION_NONE 0 474 #endif /* FC_ACTION_NONE */ 475 476 /* 477 * emlx status translation table 478 */ 479 typedef struct emlxs_xlat_err { 480 uint32_t emlxs_status; 481 uint32_t pkt_state; 482 uint32_t pkt_reason; 483 uint32_t pkt_expln; 484 uint32_t pkt_action; 485 } emlxs_xlat_err_t; 486 487 488 typedef struct emlxs_table { 489 uint32_t code; 490 char string[32]; 491 492 } emlxs_table_t; 493 494 #ifdef __cplusplus 495 } 496 #endif 497 498 #endif /* _EMLXS_OS_H */ 499