1 /* 2 * This file is provided under a CDDLv1 license. When using or 3 * redistributing this file, you may do so under this license. 4 * In redistributing this file this license must be included 5 * and no other modification of this header file is permitted. 6 * 7 * CDDL LICENSE SUMMARY 8 * 9 * Copyright(c) 1999 - 2007 Intel Corporation. All rights reserved. 10 * 11 * The contents of this file are subject to the terms of Version 12 * 1.0 of the Common Development and Distribution License (the "License"). 13 * 14 * You should have received a copy of the License with this software. 15 * You can obtain a copy of the License at 16 * http://www.opensolaris.org/os/licensing. 17 * See the License for the specific language governing permissions 18 * and limitations under the License. 19 */ 20 21 /* 22 * Copyright 2007 Sun Microsystems, Inc. All rights reserved. 23 * Use is subject to license terms of the CDDLv1. 24 */ 25 26 #ifndef _E1000G_SW_H 27 #define _E1000G_SW_H 28 29 #pragma ident "%Z%%M% %I% %E% SMI" 30 31 #ifdef __cplusplus 32 extern "C" { 33 #endif 34 35 /* 36 * ********************************************************************** 37 * Module Name: * 38 * e1000g_sw.h * 39 * * 40 * Abstract: * 41 * This header file contains Software-related data structures * 42 * definitions. * 43 * * 44 * ********************************************************************** 45 */ 46 47 #include <sys/types.h> 48 #include <sys/conf.h> 49 #include <sys/debug.h> 50 #include <sys/stropts.h> 51 #include <sys/stream.h> 52 #include <sys/strsun.h> 53 #include <sys/strlog.h> 54 #include <sys/kmem.h> 55 #include <sys/stat.h> 56 #include <sys/kstat.h> 57 #include <sys/modctl.h> 58 #include <sys/errno.h> 59 #include <sys/mac.h> 60 #include <sys/mac_ether.h> 61 #include <sys/vlan.h> 62 #include <sys/ddi.h> 63 #include <sys/sunddi.h> 64 #include <sys/pci.h> 65 #include <sys/sdt.h> 66 #include <sys/ethernet.h> 67 #include <sys/pattr.h> 68 #include <sys/strsubr.h> 69 #include <sys/netlb.h> 70 #include <inet/common.h> 71 #include <inet/ip.h> 72 #include <inet/mi.h> 73 #include <inet/nd.h> 74 #include "e1000_api.h" 75 76 77 #define JUMBO_FRAG_LENGTH 4096 78 79 #define LAST_RAR_ENTRY (E1000_RAR_ENTRIES - 1) 80 #define MAX_NUM_UNICAST_ADDRESSES E1000_RAR_ENTRIES 81 #define MAX_NUM_MULTICAST_ADDRESSES 256 82 83 #define MAX_TX_DESC_PER_PACKET 16 84 85 /* 86 * constants used in setting flow control thresholds 87 */ 88 #define E1000_PBA_MASK 0xffff 89 #define E1000_PBA_SHIFT 10 90 #define E1000_FC_HIGH_DIFF 0x1638 /* High: 5688 bytes below Rx FIFO size */ 91 #define E1000_FC_LOW_DIFF 0x1640 /* Low: 5696 bytes below Rx FIFO size */ 92 #define E1000_FC_PAUSE_TIME 0x0680 /* 858 usec */ 93 94 #define MAX_NUM_TX_DESCRIPTOR 4096 95 #define MAX_NUM_RX_DESCRIPTOR 4096 96 #define MAX_NUM_RX_FREELIST 4096 97 #define MAX_NUM_TX_FREELIST 4096 98 #define MAX_RX_LIMIT_ON_INTR 4096 99 #define MAX_RX_INTR_DELAY 65535 100 #define MAX_RX_INTR_ABS_DELAY 65535 101 #define MAX_TX_INTR_DELAY 65535 102 #define MAX_TX_INTR_ABS_DELAY 65535 103 #define MAX_INTR_THROTTLING 65535 104 #define MAX_RX_BCOPY_THRESHOLD E1000_RX_BUFFER_SIZE_2K 105 #define MAX_TX_BCOPY_THRESHOLD E1000_TX_BUFFER_SIZE_2K 106 107 #define MIN_NUM_TX_DESCRIPTOR 80 108 #define MIN_NUM_RX_DESCRIPTOR 80 109 #define MIN_NUM_RX_FREELIST 64 110 #define MIN_NUM_TX_FREELIST 80 111 #define MIN_RX_LIMIT_ON_INTR 16 112 #define MIN_RX_INTR_DELAY 0 113 #define MIN_RX_INTR_ABS_DELAY 0 114 #define MIN_TX_INTR_DELAY 0 115 #define MIN_TX_INTR_ABS_DELAY 0 116 #define MIN_INTR_THROTTLING 0 117 #define MIN_RX_BCOPY_THRESHOLD 0 118 #define MIN_TX_BCOPY_THRESHOLD MINIMUM_ETHERNET_PACKET_SIZE 119 120 #define DEFAULT_NUM_RX_DESCRIPTOR 2048 121 #define DEFAULT_NUM_TX_DESCRIPTOR 2048 122 #define DEFAULT_NUM_RX_FREELIST 4096 123 #define DEFAULT_NUM_TX_FREELIST 2048 124 #define DEFAULT_RX_LIMIT_ON_INTR 256 125 #define DEFAULT_RX_INTR_DELAY 0 126 #define DEFAULT_RX_INTR_ABS_DELAY 0 127 #define DEFAULT_TX_INTR_DELAY 300 128 #define DEFAULT_TX_INTR_ABS_DELAY 0 129 #define DEFAULT_INTR_THROTTLING 0x225 130 #define DEFAULT_RX_BCOPY_THRESHOLD 0 131 #define DEFAULT_TX_BCOPY_THRESHOLD 512 132 133 #define DEFAULT_TX_RECYCLE_LOW_WATER 64 134 #define DEFAULT_TX_RECYCLE_NUM 128 135 #define DEFAULT_TX_INTR_ENABLE 1 136 #define DEFAULT_FLOW_CONTROL 3 137 #define DEFAULT_MASTER_LATENCY_TIMER 0 /* BIOS should decide */ 138 /* which is normally 0x040 */ 139 #define DEFAULT_TBI_COMPAT_ENABLE 1 /* Enable SBP workaround */ 140 #define DEFAULT_MSI_ENABLE 1 /* MSI Enable */ 141 142 #define TX_DRAIN_TIME (200) /* # milliseconds xmit drain */ 143 144 /* 145 * The size of the receive/transmite buffers 146 */ 147 #define E1000_RX_BUFFER_SIZE_2K (2048) 148 #define E1000_RX_BUFFER_SIZE_4K (4096) 149 #define E1000_RX_BUFFER_SIZE_8K (8192) 150 #define E1000_RX_BUFFER_SIZE_16K (16384) 151 152 #define E1000_TX_BUFFER_SIZE_2K (2048) 153 #define E1000_TX_BUFFER_SIZE_4K (4096) 154 #define E1000_TX_BUFFER_SIZE_8K (8192) 155 #define E1000_TX_BUFFER_SIZE_16K (16384) 156 157 #define FORCE_BCOPY_EXCEED_FRAGS 0x1 158 #define FORCE_BCOPY_UNDER_SIZE 0x2 159 160 #define E1000G_RX_SW_FREE 0x0 161 #define E1000G_RX_SW_SENDUP 0x1 162 #define E1000G_RX_SW_STOP 0x2 163 #define E1000G_RX_SW_DETACH 0x3 164 165 /* 166 * definitions for smartspeed workaround 167 */ 168 #define E1000_SMARTSPEED_MAX 30 /* 30 watchdog iterations */ 169 /* or 30 seconds */ 170 #define E1000_SMARTSPEED_DOWNSHIFT 6 /* 6 watchdog iterations */ 171 /* or 6 seconds */ 172 173 /* 174 * Definitions for module_info. 175 */ 176 #define WSNAME "e1000g" /* module name */ 177 178 /* 179 * Defined for IP header alignment. We also need to preserve space for 180 * VLAN tag (4 bytes) 181 */ 182 #define E1000G_IPALIGNROOM 6 183 #define E1000G_IPALIGNPRESERVEROOM 64 184 185 #define E1000G_IMS_TX_INTR (E1000_IMS_TXDW | E1000_IMS_TXQE) 186 #define E1000G_ICR_TX_INTR (E1000_ICR_TXDW | E1000_ICR_TXQE) 187 188 /* 189 * bit flags for 'attach_progress' which is a member variable in struct e1000g 190 */ 191 #define ATTACH_PROGRESS_PCI_CONFIG 0x0001 /* PCI config setup */ 192 #define ATTACH_PROGRESS_REGS_MAP 0x0002 /* Registers mapped */ 193 #define ATTACH_PROGRESS_SETUP 0x0004 /* Setup driver parameters */ 194 #define ATTACH_PROGRESS_ADD_INTR 0x0008 /* Interrupt added */ 195 #define ATTACH_PROGRESS_LOCKS 0x0010 /* Locks initialized */ 196 #define ATTACH_PROGRESS_SOFT_INTR 0x0020 /* Soft interrupt added */ 197 #define ATTACH_PROGRESS_KSTATS 0x0040 /* Kstats created */ 198 #define ATTACH_PROGRESS_ALLOC 0x0080 /* DMA resources allocated */ 199 #define ATTACH_PROGRESS_INIT 0x0100 /* Driver initialization */ 200 #define ATTACH_PROGRESS_NDD 0x0200 /* NDD initialized */ 201 #define ATTACH_PROGRESS_MAC 0x0400 /* MAC registered */ 202 #define ATTACH_PROGRESS_ENABLE_INTR 0x0800 /* DDI interrupts enabled */ 203 204 /* 205 * Speed and Duplex Settings 206 */ 207 #define GDIAG_10_HALF 1 208 #define GDIAG_10_FULL 2 209 #define GDIAG_100_HALF 3 210 #define GDIAG_100_FULL 4 211 #define GDIAG_1000_FULL 6 212 #define GDIAG_ANY 7 213 214 /* 215 * Coexist Workaround RP: 07/04/03 216 * 82544 Workaround : Co-existence 217 */ 218 #define MAX_TX_BUF_SIZE (8 * 1024) 219 220 #define ROUNDOFF 0x1000 221 222 /* 223 * Defines for Jumbo Frame 224 */ 225 #define FRAME_SIZE_UPTO_2K 2048 226 #define FRAME_SIZE_UPTO_4K 4096 227 #define FRAME_SIZE_UPTO_8K 8192 228 #define FRAME_SIZE_UPTO_16K 16384 229 #define FRAME_SIZE_UPTO_9K 9234 230 231 /* The sizes (in bytes) of a ethernet packet */ 232 #define MAXIMUM_ETHERNET_FRAME_SIZE 1518 /* With FCS */ 233 #define MINIMUM_ETHERNET_FRAME_SIZE 64 /* With FCS */ 234 #define ETHERNET_FCS_SIZE 4 235 #define MAXIMUM_ETHERNET_PACKET_SIZE \ 236 (MAXIMUM_ETHERNET_FRAME_SIZE - ETHERNET_FCS_SIZE) 237 #define MINIMUM_ETHERNET_PACKET_SIZE \ 238 (MINIMUM_ETHERNET_FRAME_SIZE - ETHERNET_FCS_SIZE) 239 #define CRC_LENGTH ETHERNET_FCS_SIZE 240 241 /* Defines for Tx stall check */ 242 #define E1000G_STALL_WATCHDOG_COUNT 8 243 244 #define MAX_TX_LINK_DOWN_TIMEOUT 8 245 246 /* Defines for DVMA */ 247 #ifdef __sparc 248 #define E1000G_DEFAULT_DVMA_PAGE_NUM 2 249 #endif 250 251 /* 252 * Loopback definitions 253 */ 254 #define E1000G_LB_NONE 0 255 #define E1000G_LB_EXTERNAL_1000 1 256 #define E1000G_LB_EXTERNAL_100 2 257 #define E1000G_LB_EXTERNAL_10 3 258 #define E1000G_LB_INTERNAL_PHY 4 259 260 261 /* 262 * QUEUE_INIT_LIST -- Macro which will init ialize a queue to NULL. 263 */ 264 #define QUEUE_INIT_LIST(_LH) \ 265 (_LH)->Flink = (_LH)->Blink = (PSINGLE_LIST_LINK)0 266 267 /* 268 * IS_QUEUE_EMPTY -- Macro which checks to see if a queue is empty. 269 */ 270 #define IS_QUEUE_EMPTY(_LH) \ 271 ((_LH)->Flink == (PSINGLE_LIST_LINK)0) 272 273 /* 274 * QUEUE_GET_HEAD -- Macro which returns the head of the queue, but does 275 * not remove the head from the queue. 276 */ 277 #define QUEUE_GET_HEAD(_LH) ((PSINGLE_LIST_LINK)((_LH)->Flink)) 278 279 /* 280 * QUEUE_REMOVE_HEAD -- Macro which removes the head of the head of a queue. 281 */ 282 #define QUEUE_REMOVE_HEAD(_LH) \ 283 { \ 284 PSINGLE_LIST_LINK ListElem; \ 285 if (ListElem = (_LH)->Flink) \ 286 { \ 287 if (!((_LH)->Flink = ListElem->Flink)) \ 288 (_LH)->Blink = (PSINGLE_LIST_LINK) 0; \ 289 } \ 290 } 291 292 /* 293 * QUEUE_POP_HEAD -- Macro which will pop the head off of a queue (list), 294 * and return it (this differs from QUEUE_REMOVE_HEAD only in 295 * the 1st line). 296 */ 297 #define QUEUE_POP_HEAD(_LH) \ 298 (PSINGLE_LIST_LINK)(_LH)->Flink; \ 299 { \ 300 PSINGLE_LIST_LINK ListElem; \ 301 ListElem = (_LH)->Flink; \ 302 if (ListElem) \ 303 { \ 304 (_LH)->Flink = ListElem->Flink; \ 305 if (!(_LH)->Flink) \ 306 (_LH)->Blink = (PSINGLE_LIST_LINK)0; \ 307 } \ 308 } 309 310 /* 311 * QUEUE_GET_TAIL -- Macro which returns the tail of the queue, but does not 312 * remove the tail from the queue. 313 */ 314 #define QUEUE_GET_TAIL(_LH) ((PSINGLE_LIST_LINK)((_LH)->Blink)) 315 316 /* 317 * QUEUE_PUSH_TAIL -- Macro which puts an element at the tail (end) of the queue 318 */ 319 #define QUEUE_PUSH_TAIL(_LH, _E) \ 320 if ((_LH)->Blink) \ 321 { \ 322 ((PSINGLE_LIST_LINK)(_LH)->Blink)->Flink = \ 323 (PSINGLE_LIST_LINK)(_E); \ 324 (_LH)->Blink = (PSINGLE_LIST_LINK)(_E); \ 325 } else { \ 326 (_LH)->Flink = \ 327 (_LH)->Blink = (PSINGLE_LIST_LINK)(_E); \ 328 } \ 329 (_E)->Flink = (PSINGLE_LIST_LINK)0; 330 331 /* 332 * QUEUE_PUSH_HEAD -- Macro which puts an element at the head of the queue. 333 */ 334 #define QUEUE_PUSH_HEAD(_LH, _E) \ 335 if (!((_E)->Flink = (_LH)->Flink)) \ 336 { \ 337 (_LH)->Blink = (PSINGLE_LIST_LINK)(_E); \ 338 } \ 339 (_LH)->Flink = (PSINGLE_LIST_LINK)(_E); 340 341 /* 342 * QUEUE_GET_NEXT -- Macro which returns the next element linked to the 343 * current element. 344 */ 345 #define QUEUE_GET_NEXT(_LH, _E) \ 346 (PSINGLE_LIST_LINK)((((_LH)->Blink) == (_E)) ? \ 347 (0) : ((_E)->Flink)) 348 349 /* 350 * QUEUE_APPEND -- Macro which appends a queue to the tail of another queue 351 */ 352 #define QUEUE_APPEND(_LH1, _LH2) \ 353 if ((_LH2)->Flink) { \ 354 if ((_LH1)->Flink) { \ 355 ((PSINGLE_LIST_LINK)(_LH1)->Blink)->Flink = \ 356 ((PSINGLE_LIST_LINK)(_LH2)->Flink); \ 357 } else { \ 358 (_LH1)->Flink = \ 359 ((PSINGLE_LIST_LINK)(_LH2)->Flink); \ 360 } \ 361 (_LH1)->Blink = ((PSINGLE_LIST_LINK)(_LH2)->Blink); \ 362 } 363 364 /* 365 * Property lookups 366 */ 367 #define E1000G_PROP_EXISTS(d, n) ddi_prop_exists(DDI_DEV_T_ANY, (d), \ 368 DDI_PROP_DONTPASS, (n)) 369 #define E1000G_PROP_GET_INT(d, n) ddi_prop_get_int(DDI_DEV_T_ANY, (d), \ 370 DDI_PROP_DONTPASS, (n), -1) 371 372 /* 373 * Shorthand for the NDD parameters 374 */ 375 #define param_adv_autoneg nd_params[PARAM_ADV_AUTONEG_CAP].ndp_val 376 #define param_adv_pause nd_params[PARAM_ADV_PAUSE_CAP].ndp_val 377 #define param_adv_asym_pause nd_params[PARAM_ADV_ASYM_PAUSE_CAP].ndp_val 378 #define param_adv_1000fdx nd_params[PARAM_ADV_1000FDX_CAP].ndp_val 379 #define param_adv_1000hdx nd_params[PARAM_ADV_1000HDX_CAP].ndp_val 380 #define param_adv_100fdx nd_params[PARAM_ADV_100FDX_CAP].ndp_val 381 #define param_adv_100hdx nd_params[PARAM_ADV_100HDX_CAP].ndp_val 382 #define param_adv_10fdx nd_params[PARAM_ADV_10FDX_CAP].ndp_val 383 #define param_adv_10hdx nd_params[PARAM_ADV_10HDX_CAP].ndp_val 384 #define param_force_speed_duplex nd_params[PARAM_FORCE_SPEED_DUPLEX].ndp_val 385 386 #ifdef E1000G_DEBUG 387 /* 388 * E1000G-specific ioctls ... 389 */ 390 #define E1000G_IOC ((((((('E' << 4) + '1') << 4) \ 391 + 'K') << 4) + 'G') << 4) 392 393 /* 394 * These diagnostic IOCTLS are enabled only in DEBUG drivers 395 */ 396 #define E1000G_IOC_REG_PEEK (E1000G_IOC | 1) 397 #define E1000G_IOC_REG_POKE (E1000G_IOC | 2) 398 #define E1000G_IOC_CHIP_RESET (E1000G_IOC | 3) 399 400 #define E1000G_PP_SPACE_REG 0 /* PCI memory space */ 401 #define E1000G_PP_SPACE_E1000G 1 /* driver's soft state */ 402 403 typedef struct { 404 uint64_t pp_acc_size; /* It's 1, 2, 4 or 8 */ 405 uint64_t pp_acc_space; /* See #defines below */ 406 uint64_t pp_acc_offset; /* See regs definition */ 407 uint64_t pp_acc_data; /* output for peek */ 408 /* input for poke */ 409 } e1000g_peekpoke_t; 410 #endif /* E1000G_DEBUG */ 411 412 /* 413 * (Internal) return values from ioctl subroutines 414 */ 415 enum ioc_reply { 416 IOC_INVAL = -1, /* bad, NAK with EINVAL */ 417 IOC_DONE, /* OK, reply sent */ 418 IOC_ACK, /* OK, just send ACK */ 419 IOC_REPLY /* OK, just send reply */ 420 }; 421 422 /* 423 * Named Data (ND) Parameter Management Structure 424 */ 425 typedef struct { 426 uint32_t ndp_info; 427 uint32_t ndp_min; 428 uint32_t ndp_max; 429 uint32_t ndp_val; 430 struct e1000g *ndp_instance; 431 char *ndp_name; 432 } nd_param_t; 433 434 /* 435 * NDD parameter indexes, divided into: 436 * 437 * read-only parameters describing the hardware's capabilities 438 * read-write parameters controlling the advertised capabilities 439 * read-only parameters describing the partner's capabilities 440 * read-write parameters controlling the force speed and duplex 441 * read-only parameters describing the link state 442 * read-only parameters describing the driver properties 443 * read-write parameters controlling the driver properties 444 */ 445 enum { 446 PARAM_AUTONEG_CAP, 447 PARAM_PAUSE_CAP, 448 PARAM_ASYM_PAUSE_CAP, 449 PARAM_1000FDX_CAP, 450 PARAM_1000HDX_CAP, 451 PARAM_100T4_CAP, 452 PARAM_100FDX_CAP, 453 PARAM_100HDX_CAP, 454 PARAM_10FDX_CAP, 455 PARAM_10HDX_CAP, 456 457 PARAM_ADV_AUTONEG_CAP, 458 PARAM_ADV_PAUSE_CAP, 459 PARAM_ADV_ASYM_PAUSE_CAP, 460 PARAM_ADV_1000FDX_CAP, 461 PARAM_ADV_1000HDX_CAP, 462 PARAM_ADV_100T4_CAP, 463 PARAM_ADV_100FDX_CAP, 464 PARAM_ADV_100HDX_CAP, 465 PARAM_ADV_10FDX_CAP, 466 PARAM_ADV_10HDX_CAP, 467 468 PARAM_LP_AUTONEG_CAP, 469 PARAM_LP_PAUSE_CAP, 470 PARAM_LP_ASYM_PAUSE_CAP, 471 PARAM_LP_1000FDX_CAP, 472 PARAM_LP_1000HDX_CAP, 473 PARAM_LP_100T4_CAP, 474 PARAM_LP_100FDX_CAP, 475 PARAM_LP_100HDX_CAP, 476 PARAM_LP_10FDX_CAP, 477 PARAM_LP_10HDX_CAP, 478 479 PARAM_FORCE_SPEED_DUPLEX, 480 481 PARAM_LINK_STATUS, 482 PARAM_LINK_SPEED, 483 PARAM_LINK_DUPLEX, 484 PARAM_LINK_AUTONEG, 485 486 PARAM_MAX_FRAME_SIZE, 487 PARAM_LOOP_MODE, 488 PARAM_INTR_TYPE, 489 490 PARAM_TX_BCOPY_THRESHOLD, 491 PARAM_TX_INTR_ENABLE, 492 PARAM_TX_TIDV, 493 PARAM_TX_TADV, 494 PARAM_RX_BCOPY_THRESHOLD, 495 PARAM_RX_PKT_ON_INTR, 496 PARAM_RX_RDTR, 497 PARAM_RX_RADV, 498 499 PARAM_COUNT 500 }; 501 502 typedef struct _private_devi_list { 503 dev_info_t *dip; 504 dev_info_t *priv_dip; 505 struct _private_devi_list *next; 506 } private_devi_list_t; 507 508 /* 509 * A structure that points to the next entry in the queue. 510 */ 511 typedef struct _SINGLE_LIST_LINK { 512 struct _SINGLE_LIST_LINK *Flink; 513 } SINGLE_LIST_LINK, *PSINGLE_LIST_LINK; 514 515 /* 516 * A "ListHead" structure that points to the head and tail of a queue 517 */ 518 typedef struct _LIST_DESCRIBER { 519 struct _SINGLE_LIST_LINK *volatile Flink; 520 struct _SINGLE_LIST_LINK *volatile Blink; 521 } LIST_DESCRIBER, *PLIST_DESCRIBER; 522 523 /* 524 * Address-Length pair structure that stores descriptor info 525 */ 526 typedef struct _sw_desc { 527 uint64_t address; 528 uint32_t length; 529 } sw_desc_t, *p_sw_desc_t; 530 531 typedef struct _desc_array { 532 sw_desc_t descriptor[4]; 533 uint32_t elements; 534 } desc_array_t, *p_desc_array_t; 535 536 typedef enum { 537 USE_NONE, 538 USE_BCOPY, 539 USE_DVMA, 540 USE_DMA 541 } dma_type_t; 542 543 typedef struct _dma_buffer { 544 caddr_t address; 545 uint64_t dma_address; 546 ddi_acc_handle_t acc_handle; 547 ddi_dma_handle_t dma_handle; 548 size_t size; 549 size_t len; 550 } dma_buffer_t, *p_dma_buffer_t; 551 552 /* 553 * Transmit Control Block (TCB), Ndis equiv of SWPacket This 554 * structure stores the additional information that is 555 * associated with every packet to be transmitted. It stores the 556 * message block pointer and the TBD addresses associated with 557 * the m_blk and also the link to the next tcb in the chain 558 */ 559 typedef struct _tx_sw_packet { 560 /* Link to the next tx_sw_packet in the list */ 561 SINGLE_LIST_LINK Link; 562 mblk_t *mp; 563 uint32_t num_desc; 564 uint32_t num_mblk_frag; 565 dma_type_t dma_type; 566 dma_type_t data_transfer_type; 567 ddi_dma_handle_t tx_dma_handle; 568 dma_buffer_t tx_buf[1]; 569 sw_desc_t desc[MAX_TX_DESC_PER_PACKET]; 570 } tx_sw_packet_t, *p_tx_sw_packet_t; 571 572 /* 573 * This structure is similar to the rx_sw_packet structure used 574 * for Ndis. This structure stores information about the 2k 575 * aligned receive buffer into which the FX1000 DMA's frames. 576 * This structure is maintained as a linked list of many 577 * receiver buffer pointers. 578 */ 579 typedef struct _rx_sw_apcket { 580 /* Link to the next rx_sw_packet_t in the list */ 581 SINGLE_LIST_LINK Link; 582 struct _rx_sw_apcket *next; 583 uint16_t flag; 584 mblk_t *mp; 585 caddr_t rx_ring; 586 dma_type_t dma_type; 587 frtn_t free_rtn; 588 dma_buffer_t rx_buf[1]; 589 } rx_sw_packet_t, *p_rx_sw_packet_t; 590 591 typedef struct _mblk_list { 592 mblk_t *head; 593 mblk_t *tail; 594 } mblk_list_t, *p_mblk_list_t; 595 596 typedef struct _cksum_data { 597 uint32_t ether_header_size; 598 uint32_t cksum_flags; 599 uint32_t cksum_start; 600 uint32_t cksum_stuff; 601 } cksum_data_t; 602 603 typedef union _e1000g_ether_addr { 604 struct { 605 uint32_t high; 606 uint32_t low; 607 } reg; 608 struct { 609 uint8_t set; 610 uint8_t redundant; 611 uint8_t addr[ETHERADDRL]; 612 } mac; 613 } e1000g_ether_addr_t; 614 615 typedef struct _e1000g_stat { 616 617 kstat_named_t link_speed; /* Link Speed */ 618 kstat_named_t reset_count; /* Reset Count */ 619 620 kstat_named_t rx_error; /* Rx Error in Packet */ 621 kstat_named_t rx_exceed_pkt; /* Rx Exceed Max Pkt Count */ 622 kstat_named_t rx_esballoc_fail; /* Rx Desballoc Failure */ 623 kstat_named_t rx_allocb_fail; /* Rx Allocb Failure */ 624 625 kstat_named_t tx_no_desc; /* Tx No Desc */ 626 kstat_named_t tx_no_swpkt; /* Tx No Pkt Buffer */ 627 kstat_named_t tx_send_fail; /* Tx SendPkt Failure */ 628 kstat_named_t tx_over_size; /* Tx Pkt Too Long */ 629 kstat_named_t tx_reschedule; /* Tx Reschedule */ 630 631 #ifdef E1000G_DEBUG 632 kstat_named_t rx_none; /* Rx No Incoming Data */ 633 kstat_named_t rx_multi_desc; /* Rx Multi Spanned Pkt */ 634 kstat_named_t rx_no_freepkt; /* Rx No Free Pkt */ 635 kstat_named_t rx_avail_freepkt; /* Rx Freelist Avail Buffers */ 636 637 kstat_named_t tx_under_size; /* Tx Packet Under Size */ 638 kstat_named_t tx_empty_frags; /* Tx Empty Frags */ 639 kstat_named_t tx_exceed_frags; /* Tx Exceed Max Frags */ 640 kstat_named_t tx_recycle; /* Tx Recycle */ 641 kstat_named_t tx_recycle_intr; /* Tx Recycle in Intr */ 642 kstat_named_t tx_recycle_retry; /* Tx Recycle Retry */ 643 kstat_named_t tx_recycle_none; /* Tx No Desc Recycled */ 644 kstat_named_t tx_copy; /* Tx Send Copy */ 645 kstat_named_t tx_bind; /* Tx Send Bind */ 646 kstat_named_t tx_multi_copy; /* Tx Copy Multi Fragments */ 647 kstat_named_t tx_multi_cookie; /* Tx Pkt Span Multi Cookies */ 648 kstat_named_t tx_lack_desc; /* Tx Lack of Desc */ 649 #endif 650 651 kstat_named_t Crcerrs; /* CRC Error Count */ 652 kstat_named_t Symerrs; /* Symbol Error Count */ 653 kstat_named_t Mpc; /* Missed Packet Count */ 654 kstat_named_t Scc; /* Single Collision Count */ 655 kstat_named_t Ecol; /* Excessive Collision Count */ 656 kstat_named_t Mcc; /* Multiple Collision Count */ 657 kstat_named_t Latecol; /* Late Collision Count */ 658 kstat_named_t Colc; /* Collision Count */ 659 kstat_named_t Dc; /* Defer Count */ 660 kstat_named_t Sec; /* Sequence Error Count */ 661 kstat_named_t Rlec; /* Receive Length Error Count */ 662 kstat_named_t Xonrxc; /* XON Received Count */ 663 kstat_named_t Xontxc; /* XON Xmitted Count */ 664 kstat_named_t Xoffrxc; /* XOFF Received Count */ 665 kstat_named_t Xofftxc; /* Xoff Xmitted Count */ 666 kstat_named_t Fcruc; /* Unknown Flow Conrol Packet Rcvd Count */ 667 kstat_named_t Prc64; /* Packets Received - 64b */ 668 kstat_named_t Prc127; /* Packets Received - 65-127b */ 669 kstat_named_t Prc255; /* Packets Received - 127-255b */ 670 kstat_named_t Prc511; /* Packets Received - 256-511b */ 671 kstat_named_t Prc1023; /* Packets Received - 511-1023b */ 672 kstat_named_t Prc1522; /* Packets Received - 1024-1522b */ 673 kstat_named_t Gprc; /* Good Packets Received Count */ 674 kstat_named_t Bprc; /* Broadcasts Pkts Received Count */ 675 kstat_named_t Mprc; /* Multicast Pkts Received Count */ 676 kstat_named_t Gptc; /* Good Packets Xmitted Count */ 677 kstat_named_t Gorl; /* Good Octets Recvd Lo Count */ 678 kstat_named_t Gorh; /* Good Octets Recvd Hi Count */ 679 kstat_named_t Gotl; /* Good Octets Xmitd Lo Count */ 680 kstat_named_t Goth; /* Good Octets Xmitd Hi Count */ 681 kstat_named_t Rnbc; /* Receive No Buffers Count */ 682 kstat_named_t Ruc; /* Receive Undersize Count */ 683 kstat_named_t Rfc; /* Receive Frag Count */ 684 kstat_named_t Roc; /* Receive Oversize Count */ 685 kstat_named_t Rjc; /* Receive Jabber Count */ 686 kstat_named_t Torl; /* Total Octets Recvd Lo Count */ 687 kstat_named_t Torh; /* Total Octets Recvd Hi Count */ 688 kstat_named_t Totl; /* Total Octets Xmted Lo Count */ 689 kstat_named_t Toth; /* Total Octets Xmted Hi Count */ 690 kstat_named_t Tpr; /* Total Packets Received */ 691 kstat_named_t Tpt; /* Total Packets Xmitted */ 692 kstat_named_t Ptc64; /* Packets Xmitted (64b) */ 693 kstat_named_t Ptc127; /* Packets Xmitted (64-127b) */ 694 kstat_named_t Ptc255; /* Packets Xmitted (128-255b) */ 695 kstat_named_t Ptc511; /* Packets Xmitted (255-511b) */ 696 kstat_named_t Ptc1023; /* Packets Xmitted (512-1023b) */ 697 kstat_named_t Ptc1522; /* Packets Xmitted (1024-1522b */ 698 kstat_named_t Mptc; /* Multicast Packets Xmited Count */ 699 kstat_named_t Bptc; /* Broadcast Packets Xmited Count */ 700 kstat_named_t Algnerrc; /* Alignment Error count */ 701 kstat_named_t Tuc; /* Transmit Underrun count */ 702 kstat_named_t Rxerrc; /* Rx Error Count */ 703 kstat_named_t Tncrs; /* Transmit with no CRS */ 704 kstat_named_t Cexterr; /* Carrier Extension Error count */ 705 kstat_named_t Rutec; /* Receive DMA too Early count */ 706 kstat_named_t Tsctc; /* TCP seg contexts xmit count */ 707 kstat_named_t Tsctfc; /* TCP seg contexts xmit fail count */ 708 } e1000g_stat_t, *p_e1000g_stat_t; 709 710 typedef struct _e1000g_tx_ring { 711 kmutex_t tx_lock; 712 kmutex_t freelist_lock; 713 kmutex_t usedlist_lock; 714 kmutex_t mblks_lock; 715 /* 716 * Descriptor queue definitions 717 */ 718 ddi_dma_handle_t tbd_dma_handle; 719 ddi_acc_handle_t tbd_acc_handle; 720 struct e1000_tx_desc *tbd_area; 721 uint64_t tbd_dma_addr; 722 struct e1000_tx_desc *tbd_first; 723 struct e1000_tx_desc *tbd_last; 724 struct e1000_tx_desc *tbd_oldest; 725 struct e1000_tx_desc *tbd_next; 726 uint32_t tbd_avail; 727 /* 728 * Software packet structures definitions 729 */ 730 p_tx_sw_packet_t packet_area; 731 LIST_DESCRIBER used_list; 732 LIST_DESCRIBER free_list; 733 /* 734 * TCP/UDP checksum offload 735 */ 736 cksum_data_t cksum_data; 737 /* 738 * Timer definitions for 82547 739 */ 740 timeout_id_t timer_id_82547; 741 boolean_t timer_enable_82547; 742 /* 743 * reschedule when tx resource is available 744 */ 745 boolean_t resched_needed; 746 uint32_t recycle_low_water; 747 uint32_t recycle_num; 748 uint32_t frags_limit; 749 uint32_t stall_watchdog; 750 uint32_t recycle_fail; 751 mblk_list_t mblks; 752 /* 753 * Statistics 754 */ 755 uint32_t stat_no_swpkt; 756 uint32_t stat_no_desc; 757 uint32_t stat_send_fail; 758 uint32_t stat_reschedule; 759 uint32_t stat_over_size; 760 #ifdef E1000G_DEBUG 761 uint32_t stat_under_size; 762 uint32_t stat_exceed_frags; 763 uint32_t stat_empty_frags; 764 uint32_t stat_recycle; 765 uint32_t stat_recycle_intr; 766 uint32_t stat_recycle_retry; 767 uint32_t stat_recycle_none; 768 uint32_t stat_copy; 769 uint32_t stat_bind; 770 uint32_t stat_multi_copy; 771 uint32_t stat_multi_cookie; 772 uint32_t stat_lack_desc; 773 #endif 774 /* 775 * Pointer to the adapter 776 */ 777 struct e1000g *adapter; 778 } e1000g_tx_ring_t, *pe1000g_tx_ring_t; 779 780 typedef struct _e1000g_rx_ring { 781 kmutex_t rx_lock; 782 kmutex_t freelist_lock; 783 /* 784 * Descriptor queue definitions 785 */ 786 ddi_dma_handle_t rbd_dma_handle; 787 ddi_acc_handle_t rbd_acc_handle; 788 struct e1000_rx_desc *rbd_area; 789 uint64_t rbd_dma_addr; 790 struct e1000_rx_desc *rbd_first; 791 struct e1000_rx_desc *rbd_last; 792 struct e1000_rx_desc *rbd_next; 793 /* 794 * Software packet structures definitions 795 */ 796 p_rx_sw_packet_t packet_area; 797 LIST_DESCRIBER recv_list; 798 LIST_DESCRIBER free_list; 799 800 p_rx_sw_packet_t pending_list; 801 uint32_t pending_count; 802 uint32_t avail_freepkt; 803 uint32_t rx_mblk_len; 804 mblk_t *rx_mblk; 805 mblk_t *rx_mblk_tail; 806 /* 807 * Statistics 808 */ 809 uint32_t stat_error; 810 uint32_t stat_esballoc_fail; 811 uint32_t stat_allocb_fail; 812 uint32_t stat_exceed_pkt; 813 #ifdef E1000G_DEBUG 814 uint32_t stat_none; 815 uint32_t stat_multi_desc; 816 uint32_t stat_no_freepkt; 817 #endif 818 /* 819 * Pointer to the adapter 820 */ 821 struct e1000g *adapter; 822 } e1000g_rx_ring_t, *pe1000g_rx_ring_t; 823 824 typedef struct e1000g { 825 int instance; 826 dev_info_t *dip; 827 dev_info_t *priv_dip; 828 mac_handle_t mh; 829 mac_resource_handle_t mrh; 830 struct e1000_hw shared; 831 struct e1000g_osdep osdep; 832 833 boolean_t started; 834 boolean_t e1000g_promisc; 835 boolean_t strip_crc; 836 boolean_t rx_buffer_setup; 837 link_state_t link_state; 838 uint32_t link_speed; 839 uint32_t link_duplex; 840 uint32_t master_latency_timer; 841 uint32_t smartspeed; /* smartspeed w/a counter */ 842 uint32_t init_count; 843 uint32_t reset_count; 844 uint32_t attach_progress; /* attach tracking */ 845 uint32_t loopback_mode; 846 847 uint32_t tx_desc_num; 848 uint32_t tx_freelist_num; 849 uint32_t rx_desc_num; 850 uint32_t rx_freelist_num; 851 uint32_t tx_buffer_size; 852 uint32_t rx_buffer_size; 853 854 uint32_t tx_link_down_timeout; 855 uint32_t tx_bcopy_thresh; 856 uint32_t rx_limit_onintr; 857 uint32_t rx_bcopy_thresh; 858 #ifndef NO_82542_SUPPORT 859 uint32_t rx_buf_align; 860 #endif 861 862 boolean_t intr_adaptive; 863 boolean_t tx_intr_enable; 864 uint32_t tx_intr_delay; 865 uint32_t tx_intr_abs_delay; 866 uint32_t rx_intr_delay; 867 uint32_t rx_intr_abs_delay; 868 uint32_t intr_throttling_rate; 869 870 boolean_t watchdog_timer_enabled; 871 boolean_t watchdog_timer_started; 872 timeout_id_t watchdog_tid; 873 boolean_t link_complete; 874 timeout_id_t link_tid; 875 876 e1000g_rx_ring_t rx_ring[1]; 877 e1000g_tx_ring_t tx_ring[1]; 878 879 /* 880 * The watchdog_lock must be held when updateing the 881 * timeout fields in struct e1000g, that is, 882 * watchdog_tid, watchdog_timer_started. 883 */ 884 kmutex_t watchdog_lock; 885 /* 886 * The link_lock protects the link fields in struct e1000g, 887 * such as link_state, link_speed, link_duplex, link_complete, and 888 * link_tid. 889 */ 890 kmutex_t link_lock; 891 /* 892 * The chip_lock assures that the Rx/Tx process must be 893 * stopped while other functions change the hardware 894 * configuration of e1000g card, such as e1000g_reset(), 895 * e1000g_reset_hw() etc are executed. 896 */ 897 krwlock_t chip_lock; 898 899 uint32_t unicst_avail; 900 uint32_t unicst_total; 901 e1000g_ether_addr_t unicst_addr[MAX_NUM_UNICAST_ADDRESSES]; 902 903 uint32_t mcast_count; 904 struct ether_addr mcast_table[MAX_NUM_MULTICAST_ADDRESSES]; 905 906 #ifdef __sparc 907 ulong_t sys_page_sz; 908 uint_t dvma_page_num; 909 #endif 910 911 boolean_t msi_enabled; 912 int intr_type; 913 int intr_cnt; 914 int intr_cap; 915 size_t intr_size; 916 uint_t intr_pri; 917 ddi_intr_handle_t *htable; 918 919 int tx_softint_pri; 920 ddi_softint_handle_t tx_softint_handle; 921 922 kstat_t *e1000g_ksp; 923 924 /* 925 * NDD parameters 926 */ 927 caddr_t nd_data; 928 nd_param_t nd_params[PARAM_COUNT]; 929 930 } e1000g_t; 931 932 933 /* 934 * Function prototypes 935 */ 936 int e1000g_alloc_dma_resources(struct e1000g *Adapter); 937 void e1000g_release_dma_resources(struct e1000g *Adapter); 938 void e1000g_free_rx_sw_packet(p_rx_sw_packet_t packet); 939 void e1000g_tx_setup(struct e1000g *Adapter); 940 void e1000g_rx_setup(struct e1000g *Adapter); 941 void e1000g_setup_multicast(struct e1000g *Adapter); 942 boolean_t e1000g_reset(struct e1000g *Adapter); 943 944 int e1000g_recycle(e1000g_tx_ring_t *tx_ring); 945 void e1000g_free_tx_swpkt(p_tx_sw_packet_t packet); 946 void e1000g_tx_freemsg(e1000g_tx_ring_t *tx_ring); 947 uint_t e1000g_tx_softint_worker(caddr_t arg1, caddr_t arg2); 948 mblk_t *e1000g_m_tx(void *arg, mblk_t *mp); 949 mblk_t *e1000g_receive(struct e1000g *Adapter); 950 void e1000g_rxfree_func(p_rx_sw_packet_t packet); 951 952 int e1000g_m_stat(void *arg, uint_t stat, uint64_t *val); 953 int e1000g_init_stats(struct e1000g *Adapter); 954 void e1000_tbi_adjust_stats(struct e1000g *Adapter, 955 uint32_t frame_len, uint8_t *mac_addr); 956 enum ioc_reply e1000g_nd_ioctl(struct e1000g *Adapter, 957 queue_t *wq, mblk_t *mp, struct iocblk *iocp); 958 void e1000g_nd_cleanup(struct e1000g *Adapter); 959 int e1000g_nd_init(struct e1000g *Adapter); 960 961 void e1000g_clear_interrupt(struct e1000g *Adapter); 962 void e1000g_mask_interrupt(struct e1000g *Adapter); 963 void e1000g_clear_all_interrupts(struct e1000g *Adapter); 964 void e1000g_clear_tx_interrupt(struct e1000g *Adapter); 965 void e1000g_mask_tx_interrupt(struct e1000g *Adapter); 966 void phy_spd_state(struct e1000_hw *hw, boolean_t enable); 967 void e1000_enable_pciex_master(struct e1000_hw *hw); 968 969 #pragma inline(e1000_rar_set) 970 971 /* 972 * Global variables 973 */ 974 extern boolean_t e1000g_force_detach; 975 extern uint32_t e1000g_mblks_pending; 976 extern krwlock_t e1000g_rx_detach_lock; 977 978 979 #ifdef __cplusplus 980 } 981 #endif 982 983 #endif /* _E1000G_SW_H */ 984