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 - 2008 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 2008 Sun Microsystems, Inc. All rights reserved. 23 * Use is subject to license terms. 24 */ 25 26 /* 27 * ********************************************************************** 28 * * 29 * Module Name: * 30 * e1000g_main.c * 31 * * 32 * Abstract: * 33 * This file contains the interface routines for the solaris OS. * 34 * It has all DDI entry point routines and GLD entry point routines. * 35 * * 36 * This file also contains routines that take care of initialization * 37 * uninit routine and interrupt routine. * 38 * * 39 * ********************************************************************** 40 */ 41 42 #include <sys/dlpi.h> 43 #include <sys/mac.h> 44 #include "e1000g_sw.h" 45 #include "e1000g_debug.h" 46 47 static char ident[] = "Intel PRO/1000 Ethernet"; 48 static char e1000g_string[] = "Intel(R) PRO/1000 Network Connection"; 49 static char e1000g_version[] = "Driver Ver. 5.2.13"; 50 51 /* 52 * Proto types for DDI entry points 53 */ 54 static int e1000g_attach(dev_info_t *, ddi_attach_cmd_t); 55 static int e1000g_detach(dev_info_t *, ddi_detach_cmd_t); 56 static int e1000g_quiesce(dev_info_t *); 57 58 /* 59 * init and intr routines prototype 60 */ 61 static int e1000g_resume(dev_info_t *); 62 static int e1000g_suspend(dev_info_t *); 63 static uint_t e1000g_intr_pciexpress(caddr_t); 64 static uint_t e1000g_intr(caddr_t); 65 static void e1000g_intr_work(struct e1000g *, uint32_t); 66 #pragma inline(e1000g_intr_work) 67 static uint32_t e1000g_get_itr(uint32_t, uint32_t, uint32_t); 68 #pragma inline(e1000g_get_itr) 69 static int e1000g_init(struct e1000g *); 70 static int e1000g_start(struct e1000g *, boolean_t); 71 static void e1000g_stop(struct e1000g *, boolean_t); 72 static int e1000g_m_start(void *); 73 static void e1000g_m_stop(void *); 74 static int e1000g_m_promisc(void *, boolean_t); 75 static boolean_t e1000g_m_getcapab(void *, mac_capab_t, void *); 76 static int e1000g_m_unicst(void *, const uint8_t *); 77 static int e1000g_m_unicst_add(void *, mac_multi_addr_t *); 78 static int e1000g_m_unicst_remove(void *, mac_addr_slot_t); 79 static int e1000g_m_unicst_modify(void *, mac_multi_addr_t *); 80 static int e1000g_m_unicst_get(void *, mac_multi_addr_t *); 81 static int e1000g_m_multicst(void *, boolean_t, const uint8_t *); 82 static void e1000g_m_ioctl(void *, queue_t *, mblk_t *); 83 static int e1000g_m_setprop(void *, const char *, mac_prop_id_t, 84 uint_t, const void *); 85 static int e1000g_m_getprop(void *, const char *, mac_prop_id_t, 86 uint_t, uint_t, void *, uint_t *); 87 static int e1000g_set_priv_prop(struct e1000g *, const char *, uint_t, 88 const void *); 89 static int e1000g_get_priv_prop(struct e1000g *, const char *, uint_t, 90 uint_t, void *, uint_t *); 91 static void e1000g_init_locks(struct e1000g *); 92 static void e1000g_destroy_locks(struct e1000g *); 93 static int e1000g_identify_hardware(struct e1000g *); 94 static int e1000g_regs_map(struct e1000g *); 95 static int e1000g_set_driver_params(struct e1000g *); 96 static void e1000g_set_bufsize(struct e1000g *); 97 static int e1000g_register_mac(struct e1000g *); 98 static boolean_t e1000g_rx_drain(struct e1000g *); 99 static boolean_t e1000g_tx_drain(struct e1000g *); 100 static void e1000g_init_unicst(struct e1000g *); 101 static int e1000g_unicst_set(struct e1000g *, const uint8_t *, mac_addr_slot_t); 102 103 /* 104 * Local routines 105 */ 106 static boolean_t e1000g_reset_adapter(struct e1000g *); 107 static void e1000g_tx_clean(struct e1000g *); 108 static void e1000g_rx_clean(struct e1000g *); 109 static void e1000g_link_timer(void *); 110 static void e1000g_local_timer(void *); 111 static boolean_t e1000g_link_check(struct e1000g *); 112 static boolean_t e1000g_stall_check(struct e1000g *); 113 static void e1000g_smartspeed(struct e1000g *); 114 static void e1000g_get_conf(struct e1000g *); 115 static int e1000g_get_prop(struct e1000g *, char *, int, int, int); 116 static void enable_watchdog_timer(struct e1000g *); 117 static void disable_watchdog_timer(struct e1000g *); 118 static void start_watchdog_timer(struct e1000g *); 119 static void restart_watchdog_timer(struct e1000g *); 120 static void stop_watchdog_timer(struct e1000g *); 121 static void stop_link_timer(struct e1000g *); 122 static void stop_82547_timer(e1000g_tx_ring_t *); 123 static void e1000g_force_speed_duplex(struct e1000g *); 124 static void e1000g_get_max_frame_size(struct e1000g *); 125 static boolean_t is_valid_mac_addr(uint8_t *); 126 static void e1000g_unattach(dev_info_t *, struct e1000g *); 127 #ifdef E1000G_DEBUG 128 static void e1000g_ioc_peek_reg(struct e1000g *, e1000g_peekpoke_t *); 129 static void e1000g_ioc_poke_reg(struct e1000g *, e1000g_peekpoke_t *); 130 static void e1000g_ioc_peek_mem(struct e1000g *, e1000g_peekpoke_t *); 131 static void e1000g_ioc_poke_mem(struct e1000g *, e1000g_peekpoke_t *); 132 static enum ioc_reply e1000g_pp_ioctl(struct e1000g *, 133 struct iocblk *, mblk_t *); 134 #endif 135 static enum ioc_reply e1000g_loopback_ioctl(struct e1000g *, 136 struct iocblk *, mblk_t *); 137 static boolean_t e1000g_check_loopback_support(struct e1000_hw *); 138 static boolean_t e1000g_set_loopback_mode(struct e1000g *, uint32_t); 139 static void e1000g_set_internal_loopback(struct e1000g *); 140 static void e1000g_set_external_loopback_1000(struct e1000g *); 141 static void e1000g_set_external_loopback_100(struct e1000g *); 142 static void e1000g_set_external_loopback_10(struct e1000g *); 143 static int e1000g_add_intrs(struct e1000g *); 144 static int e1000g_intr_add(struct e1000g *, int); 145 static int e1000g_rem_intrs(struct e1000g *); 146 static int e1000g_enable_intrs(struct e1000g *); 147 static int e1000g_disable_intrs(struct e1000g *); 148 static boolean_t e1000g_link_up(struct e1000g *); 149 #ifdef __sparc 150 static boolean_t e1000g_find_mac_address(struct e1000g *); 151 #endif 152 static void e1000g_get_phy_state(struct e1000g *); 153 static void e1000g_free_priv_devi_node(struct e1000g *, boolean_t); 154 static int e1000g_fm_error_cb(dev_info_t *dip, ddi_fm_error_t *err, 155 const void *impl_data); 156 static void e1000g_fm_init(struct e1000g *Adapter); 157 static void e1000g_fm_fini(struct e1000g *Adapter); 158 static int e1000g_get_def_val(struct e1000g *, mac_prop_id_t, uint_t, void *); 159 static void e1000g_param_sync(struct e1000g *); 160 static void e1000g_get_driver_control(struct e1000_hw *); 161 static void e1000g_release_driver_control(struct e1000_hw *); 162 static void e1000g_restore_promisc(struct e1000g *Adapter); 163 164 mac_priv_prop_t e1000g_priv_props[] = { 165 {"_tx_bcopy_threshold", MAC_PROP_PERM_RW}, 166 {"_tx_interrupt_enable", MAC_PROP_PERM_RW}, 167 {"_tx_intr_delay", MAC_PROP_PERM_RW}, 168 {"_tx_intr_abs_delay", MAC_PROP_PERM_RW}, 169 {"_rx_bcopy_threshold", MAC_PROP_PERM_RW}, 170 {"_max_num_rcv_packets", MAC_PROP_PERM_RW}, 171 {"_rx_intr_delay", MAC_PROP_PERM_RW}, 172 {"_rx_intr_abs_delay", MAC_PROP_PERM_RW}, 173 {"_intr_throttling_rate", MAC_PROP_PERM_RW}, 174 {"_intr_adaptive", MAC_PROP_PERM_RW}, 175 {"_tx_recycle_thresh", MAC_PROP_PERM_RW}, 176 {"_adv_pause_cap", MAC_PROP_PERM_READ}, 177 {"_adv_asym_pause_cap", MAC_PROP_PERM_READ}, 178 {"_tx_recycle_num", MAC_PROP_PERM_RW} 179 }; 180 #define E1000G_MAX_PRIV_PROPS \ 181 (sizeof (e1000g_priv_props)/sizeof (mac_priv_prop_t)) 182 183 184 static struct cb_ops cb_ws_ops = { 185 nulldev, /* cb_open */ 186 nulldev, /* cb_close */ 187 nodev, /* cb_strategy */ 188 nodev, /* cb_print */ 189 nodev, /* cb_dump */ 190 nodev, /* cb_read */ 191 nodev, /* cb_write */ 192 nodev, /* cb_ioctl */ 193 nodev, /* cb_devmap */ 194 nodev, /* cb_mmap */ 195 nodev, /* cb_segmap */ 196 nochpoll, /* cb_chpoll */ 197 ddi_prop_op, /* cb_prop_op */ 198 NULL, /* cb_stream */ 199 D_MP | D_HOTPLUG, /* cb_flag */ 200 CB_REV, /* cb_rev */ 201 nodev, /* cb_aread */ 202 nodev /* cb_awrite */ 203 }; 204 205 static struct dev_ops ws_ops = { 206 DEVO_REV, /* devo_rev */ 207 0, /* devo_refcnt */ 208 NULL, /* devo_getinfo */ 209 nulldev, /* devo_identify */ 210 nulldev, /* devo_probe */ 211 e1000g_attach, /* devo_attach */ 212 e1000g_detach, /* devo_detach */ 213 nodev, /* devo_reset */ 214 &cb_ws_ops, /* devo_cb_ops */ 215 NULL, /* devo_bus_ops */ 216 ddi_power, /* devo_power */ 217 e1000g_quiesce /* devo_quiesce */ 218 }; 219 220 static struct modldrv modldrv = { 221 &mod_driverops, /* Type of module. This one is a driver */ 222 ident, /* Discription string */ 223 &ws_ops, /* driver ops */ 224 }; 225 226 static struct modlinkage modlinkage = { 227 MODREV_1, &modldrv, NULL 228 }; 229 230 /* Access attributes for register mapping */ 231 static ddi_device_acc_attr_t e1000g_regs_acc_attr = { 232 DDI_DEVICE_ATTR_V0, 233 DDI_STRUCTURE_LE_ACC, 234 DDI_STRICTORDER_ACC, 235 DDI_FLAGERR_ACC 236 }; 237 238 #define E1000G_M_CALLBACK_FLAGS \ 239 (MC_IOCTL | MC_GETCAPAB | MC_SETPROP | MC_GETPROP) 240 241 static mac_callbacks_t e1000g_m_callbacks = { 242 E1000G_M_CALLBACK_FLAGS, 243 e1000g_m_stat, 244 e1000g_m_start, 245 e1000g_m_stop, 246 e1000g_m_promisc, 247 e1000g_m_multicst, 248 e1000g_m_unicst, 249 e1000g_m_tx, 250 NULL, 251 e1000g_m_ioctl, 252 e1000g_m_getcapab, 253 NULL, 254 NULL, 255 e1000g_m_setprop, 256 e1000g_m_getprop 257 }; 258 259 /* 260 * Global variables 261 */ 262 uint32_t e1000g_mblks_pending = 0; 263 /* 264 * Workaround for Dynamic Reconfiguration support, for x86 platform only. 265 * Here we maintain a private dev_info list if e1000g_force_detach is 266 * enabled. If we force the driver to detach while there are still some 267 * rx buffers retained in the upper layer, we have to keep a copy of the 268 * dev_info. In some cases (Dynamic Reconfiguration), the dev_info data 269 * structure will be freed after the driver is detached. However when we 270 * finally free those rx buffers released by the upper layer, we need to 271 * refer to the dev_info to free the dma buffers. So we save a copy of 272 * the dev_info for this purpose. On x86 platform, we assume this copy 273 * of dev_info is always valid, but on SPARC platform, it could be invalid 274 * after the system board level DR operation. For this reason, the global 275 * variable e1000g_force_detach must be B_FALSE on SPARC platform. 276 */ 277 #ifdef __sparc 278 boolean_t e1000g_force_detach = B_FALSE; 279 #else 280 boolean_t e1000g_force_detach = B_TRUE; 281 #endif 282 private_devi_list_t *e1000g_private_devi_list = NULL; 283 284 /* 285 * The rwlock is defined to protect the whole processing of rx recycling 286 * and the rx packets release in detach processing to make them mutually 287 * exclusive. 288 * The rx recycling processes different rx packets in different threads, 289 * so it will be protected with RW_READER and it won't block any other rx 290 * recycling threads. 291 * While the detach processing will be protected with RW_WRITER to make 292 * it mutually exclusive with the rx recycling. 293 */ 294 krwlock_t e1000g_rx_detach_lock; 295 /* 296 * The rwlock e1000g_dma_type_lock is defined to protect the global flag 297 * e1000g_dma_type. For SPARC, the initial value of the flag is "USE_DVMA". 298 * If there are many e1000g instances, the system may run out of DVMA 299 * resources during the initialization of the instances, then the flag will 300 * be changed to "USE_DMA". Because different e1000g instances are initialized 301 * in parallel, we need to use this lock to protect the flag. 302 */ 303 krwlock_t e1000g_dma_type_lock; 304 305 /* 306 * The 82546 chipset is a dual-port device, both the ports share one eeprom. 307 * Based on the information from Intel, the 82546 chipset has some hardware 308 * problem. When one port is being reset and the other port is trying to 309 * access the eeprom, it could cause system hang or panic. To workaround this 310 * hardware problem, we use a global mutex to prevent such operations from 311 * happening simultaneously on different instances. This workaround is applied 312 * to all the devices supported by this driver. 313 */ 314 kmutex_t e1000g_nvm_lock; 315 316 /* 317 * Loadable module configuration entry points for the driver 318 */ 319 320 /* 321 * _init - module initialization 322 */ 323 int 324 _init(void) 325 { 326 int status; 327 328 mac_init_ops(&ws_ops, WSNAME); 329 status = mod_install(&modlinkage); 330 if (status != DDI_SUCCESS) 331 mac_fini_ops(&ws_ops); 332 else { 333 rw_init(&e1000g_rx_detach_lock, NULL, RW_DRIVER, NULL); 334 rw_init(&e1000g_dma_type_lock, NULL, RW_DRIVER, NULL); 335 mutex_init(&e1000g_nvm_lock, NULL, MUTEX_DRIVER, NULL); 336 } 337 338 return (status); 339 } 340 341 /* 342 * _fini - module finalization 343 */ 344 int 345 _fini(void) 346 { 347 int status; 348 349 rw_enter(&e1000g_rx_detach_lock, RW_READER); 350 if (e1000g_mblks_pending != 0) { 351 rw_exit(&e1000g_rx_detach_lock); 352 return (EBUSY); 353 } 354 rw_exit(&e1000g_rx_detach_lock); 355 356 status = mod_remove(&modlinkage); 357 if (status == DDI_SUCCESS) { 358 mac_fini_ops(&ws_ops); 359 360 if (e1000g_force_detach) { 361 private_devi_list_t *devi_node; 362 363 rw_enter(&e1000g_rx_detach_lock, RW_WRITER); 364 while (e1000g_private_devi_list != NULL) { 365 devi_node = e1000g_private_devi_list; 366 e1000g_private_devi_list = 367 e1000g_private_devi_list->next; 368 369 kmem_free(devi_node->priv_dip, 370 sizeof (struct dev_info)); 371 kmem_free(devi_node, 372 sizeof (private_devi_list_t)); 373 } 374 rw_exit(&e1000g_rx_detach_lock); 375 } 376 377 rw_destroy(&e1000g_rx_detach_lock); 378 rw_destroy(&e1000g_dma_type_lock); 379 mutex_destroy(&e1000g_nvm_lock); 380 } 381 382 return (status); 383 } 384 385 /* 386 * _info - module information 387 */ 388 int 389 _info(struct modinfo *modinfop) 390 { 391 return (mod_info(&modlinkage, modinfop)); 392 } 393 394 /* 395 * e1000g_attach - driver attach 396 * 397 * This function is the device-specific initialization entry 398 * point. This entry point is required and must be written. 399 * The DDI_ATTACH command must be provided in the attach entry 400 * point. When attach() is called with cmd set to DDI_ATTACH, 401 * all normal kernel services (such as kmem_alloc(9F)) are 402 * available for use by the driver. 403 * 404 * The attach() function will be called once for each instance 405 * of the device on the system with cmd set to DDI_ATTACH. 406 * Until attach() succeeds, the only driver entry points which 407 * may be called are open(9E) and getinfo(9E). 408 */ 409 static int 410 e1000g_attach(dev_info_t *devinfo, ddi_attach_cmd_t cmd) 411 { 412 struct e1000g *Adapter; 413 struct e1000_hw *hw; 414 struct e1000g_osdep *osdep; 415 int instance; 416 417 switch (cmd) { 418 default: 419 e1000g_log(NULL, CE_WARN, 420 "Unsupported command send to e1000g_attach... "); 421 return (DDI_FAILURE); 422 423 case DDI_RESUME: 424 return (e1000g_resume(devinfo)); 425 426 case DDI_ATTACH: 427 break; 428 } 429 430 /* 431 * get device instance number 432 */ 433 instance = ddi_get_instance(devinfo); 434 435 /* 436 * Allocate soft data structure 437 */ 438 Adapter = 439 (struct e1000g *)kmem_zalloc(sizeof (*Adapter), KM_SLEEP); 440 441 Adapter->dip = devinfo; 442 Adapter->instance = instance; 443 Adapter->tx_ring->adapter = Adapter; 444 Adapter->rx_ring->adapter = Adapter; 445 446 hw = &Adapter->shared; 447 osdep = &Adapter->osdep; 448 hw->back = osdep; 449 osdep->adapter = Adapter; 450 451 ddi_set_driver_private(devinfo, (caddr_t)Adapter); 452 453 /* 454 * Initialize for fma support 455 */ 456 Adapter->fm_capabilities = e1000g_get_prop(Adapter, "fm-capable", 457 0, 0x0f, 458 DDI_FM_EREPORT_CAPABLE | DDI_FM_ACCCHK_CAPABLE | 459 DDI_FM_DMACHK_CAPABLE | DDI_FM_ERRCB_CAPABLE); 460 e1000g_fm_init(Adapter); 461 Adapter->attach_progress |= ATTACH_PROGRESS_FMINIT; 462 463 /* 464 * PCI Configure 465 */ 466 if (pci_config_setup(devinfo, &osdep->cfg_handle) != DDI_SUCCESS) { 467 e1000g_log(Adapter, CE_WARN, "PCI configuration failed"); 468 goto attach_fail; 469 } 470 Adapter->attach_progress |= ATTACH_PROGRESS_PCI_CONFIG; 471 472 /* 473 * Setup hardware 474 */ 475 if (e1000g_identify_hardware(Adapter) != DDI_SUCCESS) { 476 e1000g_log(Adapter, CE_WARN, "Identify hardware failed"); 477 goto attach_fail; 478 } 479 480 /* 481 * Map in the device registers. 482 */ 483 if (e1000g_regs_map(Adapter) != DDI_SUCCESS) { 484 e1000g_log(Adapter, CE_WARN, "Mapping registers failed"); 485 goto attach_fail; 486 } 487 Adapter->attach_progress |= ATTACH_PROGRESS_REGS_MAP; 488 489 /* 490 * Initialize driver parameters 491 */ 492 if (e1000g_set_driver_params(Adapter) != DDI_SUCCESS) { 493 goto attach_fail; 494 } 495 Adapter->attach_progress |= ATTACH_PROGRESS_SETUP; 496 497 if (e1000g_check_acc_handle(Adapter->osdep.cfg_handle) != DDI_FM_OK) { 498 ddi_fm_service_impact(Adapter->dip, DDI_SERVICE_LOST); 499 goto attach_fail; 500 } 501 502 /* 503 * Initialize interrupts 504 */ 505 if (e1000g_add_intrs(Adapter) != DDI_SUCCESS) { 506 e1000g_log(Adapter, CE_WARN, "Add interrupts failed"); 507 goto attach_fail; 508 } 509 Adapter->attach_progress |= ATTACH_PROGRESS_ADD_INTR; 510 511 /* 512 * Initialize mutex's for this device. 513 * Do this before enabling the interrupt handler and 514 * register the softint to avoid the condition where 515 * interrupt handler can try using uninitialized mutex 516 */ 517 e1000g_init_locks(Adapter); 518 Adapter->attach_progress |= ATTACH_PROGRESS_LOCKS; 519 520 /* 521 * Initialize Driver Counters 522 */ 523 if (e1000g_init_stats(Adapter) != DDI_SUCCESS) { 524 e1000g_log(Adapter, CE_WARN, "Init stats failed"); 525 goto attach_fail; 526 } 527 Adapter->attach_progress |= ATTACH_PROGRESS_KSTATS; 528 529 /* 530 * Initialize chip hardware and software structures 531 */ 532 if (e1000g_init(Adapter) != DDI_SUCCESS) { 533 e1000g_log(Adapter, CE_WARN, "Adapter initialization failed"); 534 goto attach_fail; 535 } 536 Adapter->attach_progress |= ATTACH_PROGRESS_INIT; 537 538 /* 539 * Register the driver to the MAC 540 */ 541 if (e1000g_register_mac(Adapter) != DDI_SUCCESS) { 542 e1000g_log(Adapter, CE_WARN, "Register MAC failed"); 543 goto attach_fail; 544 } 545 Adapter->attach_progress |= ATTACH_PROGRESS_MAC; 546 547 /* 548 * Now that mutex locks are initialized, and the chip is also 549 * initialized, enable interrupts. 550 */ 551 if (e1000g_enable_intrs(Adapter) != DDI_SUCCESS) { 552 e1000g_log(Adapter, CE_WARN, "Enable DDI interrupts failed"); 553 goto attach_fail; 554 } 555 Adapter->attach_progress |= ATTACH_PROGRESS_ENABLE_INTR; 556 557 /* 558 * If e1000g_force_detach is enabled, in global private dip list, 559 * we will create a new entry, which maintains the priv_dip for DR 560 * supports after driver detached. 561 */ 562 if (e1000g_force_detach) { 563 private_devi_list_t *devi_node; 564 565 Adapter->priv_dip = 566 kmem_zalloc(sizeof (struct dev_info), KM_SLEEP); 567 bcopy(DEVI(devinfo), DEVI(Adapter->priv_dip), 568 sizeof (struct dev_info)); 569 570 devi_node = 571 kmem_zalloc(sizeof (private_devi_list_t), KM_SLEEP); 572 573 rw_enter(&e1000g_rx_detach_lock, RW_WRITER); 574 devi_node->priv_dip = Adapter->priv_dip; 575 devi_node->flag = E1000G_PRIV_DEVI_ATTACH; 576 devi_node->next = e1000g_private_devi_list; 577 e1000g_private_devi_list = devi_node; 578 rw_exit(&e1000g_rx_detach_lock); 579 } 580 581 cmn_err(CE_CONT, "!%s, %s\n", e1000g_string, e1000g_version); 582 583 return (DDI_SUCCESS); 584 585 attach_fail: 586 e1000g_unattach(devinfo, Adapter); 587 return (DDI_FAILURE); 588 } 589 590 static int 591 e1000g_register_mac(struct e1000g *Adapter) 592 { 593 struct e1000_hw *hw = &Adapter->shared; 594 mac_register_t *mac; 595 int err; 596 597 if ((mac = mac_alloc(MAC_VERSION)) == NULL) 598 return (DDI_FAILURE); 599 600 mac->m_type_ident = MAC_PLUGIN_IDENT_ETHER; 601 mac->m_driver = Adapter; 602 mac->m_dip = Adapter->dip; 603 mac->m_src_addr = hw->mac.addr; 604 mac->m_callbacks = &e1000g_m_callbacks; 605 mac->m_min_sdu = 0; 606 mac->m_max_sdu = Adapter->default_mtu; 607 mac->m_margin = VLAN_TAGSZ; 608 mac->m_priv_props = e1000g_priv_props; 609 mac->m_priv_prop_count = E1000G_MAX_PRIV_PROPS; 610 611 err = mac_register(mac, &Adapter->mh); 612 mac_free(mac); 613 614 return (err == 0 ? DDI_SUCCESS : DDI_FAILURE); 615 } 616 617 static int 618 e1000g_identify_hardware(struct e1000g *Adapter) 619 { 620 struct e1000_hw *hw = &Adapter->shared; 621 struct e1000g_osdep *osdep = &Adapter->osdep; 622 623 /* Get the device id */ 624 hw->vendor_id = 625 pci_config_get16(osdep->cfg_handle, PCI_CONF_VENID); 626 hw->device_id = 627 pci_config_get16(osdep->cfg_handle, PCI_CONF_DEVID); 628 hw->revision_id = 629 pci_config_get8(osdep->cfg_handle, PCI_CONF_REVID); 630 hw->subsystem_device_id = 631 pci_config_get16(osdep->cfg_handle, PCI_CONF_SUBSYSID); 632 hw->subsystem_vendor_id = 633 pci_config_get16(osdep->cfg_handle, PCI_CONF_SUBVENID); 634 635 if (e1000_set_mac_type(hw) != E1000_SUCCESS) { 636 E1000G_DEBUGLOG_0(Adapter, E1000G_INFO_LEVEL, 637 "MAC type could not be set properly."); 638 return (DDI_FAILURE); 639 } 640 641 return (DDI_SUCCESS); 642 } 643 644 static int 645 e1000g_regs_map(struct e1000g *Adapter) 646 { 647 dev_info_t *devinfo = Adapter->dip; 648 struct e1000_hw *hw = &Adapter->shared; 649 struct e1000g_osdep *osdep = &Adapter->osdep; 650 off_t mem_size; 651 652 /* Get size of adapter register memory */ 653 if (ddi_dev_regsize(devinfo, ADAPTER_REG_SET, &mem_size) != 654 DDI_SUCCESS) { 655 E1000G_DEBUGLOG_0(Adapter, CE_WARN, 656 "ddi_dev_regsize for registers failed"); 657 return (DDI_FAILURE); 658 } 659 660 /* Map adapter register memory */ 661 if ((ddi_regs_map_setup(devinfo, ADAPTER_REG_SET, 662 (caddr_t *)&hw->hw_addr, 0, mem_size, &e1000g_regs_acc_attr, 663 &osdep->reg_handle)) != DDI_SUCCESS) { 664 E1000G_DEBUGLOG_0(Adapter, CE_WARN, 665 "ddi_regs_map_setup for registers failed"); 666 goto regs_map_fail; 667 } 668 669 /* ICH needs to map flash memory */ 670 if (hw->mac.type == e1000_ich8lan || 671 hw->mac.type == e1000_ich9lan || 672 hw->mac.type == e1000_ich10lan) { 673 /* get flash size */ 674 if (ddi_dev_regsize(devinfo, ICH_FLASH_REG_SET, 675 &mem_size) != DDI_SUCCESS) { 676 E1000G_DEBUGLOG_0(Adapter, CE_WARN, 677 "ddi_dev_regsize for ICH flash failed"); 678 goto regs_map_fail; 679 } 680 681 /* map flash in */ 682 if (ddi_regs_map_setup(devinfo, ICH_FLASH_REG_SET, 683 (caddr_t *)&hw->flash_address, 0, 684 mem_size, &e1000g_regs_acc_attr, 685 &osdep->ich_flash_handle) != DDI_SUCCESS) { 686 E1000G_DEBUGLOG_0(Adapter, CE_WARN, 687 "ddi_regs_map_setup for ICH flash failed"); 688 goto regs_map_fail; 689 } 690 } 691 692 return (DDI_SUCCESS); 693 694 regs_map_fail: 695 if (osdep->reg_handle != NULL) 696 ddi_regs_map_free(&osdep->reg_handle); 697 698 return (DDI_FAILURE); 699 } 700 701 static int 702 e1000g_set_driver_params(struct e1000g *Adapter) 703 { 704 struct e1000_hw *hw; 705 uint32_t mem_bar, io_bar, bar64; 706 707 hw = &Adapter->shared; 708 709 /* Set MAC type and initialize hardware functions */ 710 if (e1000_setup_init_funcs(hw, B_TRUE) != E1000_SUCCESS) { 711 E1000G_DEBUGLOG_0(Adapter, CE_WARN, 712 "Could not setup hardware functions"); 713 return (DDI_FAILURE); 714 } 715 716 /* Get bus information */ 717 if (e1000_get_bus_info(hw) != E1000_SUCCESS) { 718 E1000G_DEBUGLOG_0(Adapter, CE_WARN, 719 "Could not get bus information"); 720 return (DDI_FAILURE); 721 } 722 723 /* get mem_base addr */ 724 mem_bar = pci_config_get32(Adapter->osdep.cfg_handle, PCI_CONF_BASE0); 725 bar64 = mem_bar & PCI_BASE_TYPE_ALL; 726 727 /* get io_base addr */ 728 if (hw->mac.type >= e1000_82544) { 729 if (bar64) { 730 /* IO BAR is different for 64 bit BAR mode */ 731 io_bar = pci_config_get32(Adapter->osdep.cfg_handle, 732 PCI_CONF_BASE4); 733 } else { 734 /* normal 32-bit BAR mode */ 735 io_bar = pci_config_get32(Adapter->osdep.cfg_handle, 736 PCI_CONF_BASE2); 737 } 738 hw->io_base = io_bar & PCI_BASE_IO_ADDR_M; 739 } else { 740 /* no I/O access for adapters prior to 82544 */ 741 hw->io_base = 0x0; 742 } 743 744 e1000_read_pci_cfg(hw, PCI_COMMAND_REGISTER, &hw->bus.pci_cmd_word); 745 746 hw->mac.autoneg_failed = B_TRUE; 747 748 /* Set the autoneg_wait_to_complete flag to B_FALSE */ 749 hw->phy.autoneg_wait_to_complete = B_FALSE; 750 751 /* Adaptive IFS related changes */ 752 hw->mac.adaptive_ifs = B_TRUE; 753 754 /* Enable phy init script for IGP phy of 82541/82547 */ 755 if ((hw->mac.type == e1000_82547) || 756 (hw->mac.type == e1000_82541) || 757 (hw->mac.type == e1000_82547_rev_2) || 758 (hw->mac.type == e1000_82541_rev_2)) 759 e1000_init_script_state_82541(hw, B_TRUE); 760 761 /* Enable the TTL workaround for 82541/82547 */ 762 e1000_set_ttl_workaround_state_82541(hw, B_TRUE); 763 764 #ifdef __sparc 765 Adapter->strip_crc = B_TRUE; 766 #else 767 Adapter->strip_crc = B_FALSE; 768 #endif 769 770 /* Get conf file properties */ 771 e1000g_get_conf(Adapter); 772 773 /* Get speed/duplex settings in conf file */ 774 hw->mac.forced_speed_duplex = ADVERTISE_100_FULL; 775 hw->phy.autoneg_advertised = AUTONEG_ADVERTISE_SPEED_DEFAULT; 776 e1000g_force_speed_duplex(Adapter); 777 778 /* Get Jumbo Frames settings in conf file */ 779 e1000g_get_max_frame_size(Adapter); 780 781 /* Set Rx/Tx buffer size */ 782 e1000g_set_bufsize(Adapter); 783 784 /* Master Latency Timer */ 785 Adapter->master_latency_timer = DEFAULT_MASTER_LATENCY_TIMER; 786 787 /* copper options */ 788 if (hw->phy.media_type == e1000_media_type_copper) { 789 hw->phy.mdix = 0; /* AUTO_ALL_MODES */ 790 hw->phy.disable_polarity_correction = B_FALSE; 791 hw->phy.ms_type = e1000_ms_hw_default; /* E1000_MASTER_SLAVE */ 792 } 793 794 /* The initial link state should be "unknown" */ 795 Adapter->link_state = LINK_STATE_UNKNOWN; 796 797 /* Initialize rx parameters */ 798 Adapter->rx_intr_delay = DEFAULT_RX_INTR_DELAY; 799 Adapter->rx_intr_abs_delay = DEFAULT_RX_INTR_ABS_DELAY; 800 801 /* Initialize tx parameters */ 802 Adapter->tx_intr_enable = DEFAULT_TX_INTR_ENABLE; 803 Adapter->tx_bcopy_thresh = DEFAULT_TX_BCOPY_THRESHOLD; 804 Adapter->tx_intr_delay = DEFAULT_TX_INTR_DELAY; 805 Adapter->tx_intr_abs_delay = DEFAULT_TX_INTR_ABS_DELAY; 806 807 /* Initialize rx parameters */ 808 Adapter->rx_bcopy_thresh = DEFAULT_RX_BCOPY_THRESHOLD; 809 810 return (DDI_SUCCESS); 811 } 812 813 static void 814 e1000g_set_bufsize(struct e1000g *Adapter) 815 { 816 struct e1000_mac_info *mac = &Adapter->shared.mac; 817 uint64_t rx_size; 818 uint64_t tx_size; 819 820 dev_info_t *devinfo = Adapter->dip; 821 #ifdef __sparc 822 ulong_t iommu_pagesize; 823 #endif 824 /* Get the system page size */ 825 Adapter->sys_page_sz = ddi_ptob(devinfo, (ulong_t)1); 826 827 #ifdef __sparc 828 iommu_pagesize = dvma_pagesize(devinfo); 829 if (iommu_pagesize != 0) { 830 if (Adapter->sys_page_sz == iommu_pagesize) { 831 if (iommu_pagesize > 0x4000) 832 Adapter->sys_page_sz = 0x4000; 833 } else { 834 if (Adapter->sys_page_sz > iommu_pagesize) 835 Adapter->sys_page_sz = iommu_pagesize; 836 } 837 } 838 if (Adapter->lso_enable) { 839 Adapter->dvma_page_num = E1000_LSO_MAXLEN / 840 Adapter->sys_page_sz + E1000G_DEFAULT_DVMA_PAGE_NUM; 841 } else { 842 Adapter->dvma_page_num = Adapter->max_frame_size / 843 Adapter->sys_page_sz + E1000G_DEFAULT_DVMA_PAGE_NUM; 844 } 845 ASSERT(Adapter->dvma_page_num >= E1000G_DEFAULT_DVMA_PAGE_NUM); 846 #endif 847 848 Adapter->min_frame_size = ETHERMIN + ETHERFCSL; 849 850 rx_size = Adapter->max_frame_size + E1000G_IPALIGNPRESERVEROOM; 851 if ((rx_size > FRAME_SIZE_UPTO_2K) && (rx_size <= FRAME_SIZE_UPTO_4K)) 852 Adapter->rx_buffer_size = E1000_RX_BUFFER_SIZE_4K; 853 else if ((rx_size > FRAME_SIZE_UPTO_4K) && 854 (rx_size <= FRAME_SIZE_UPTO_8K)) 855 Adapter->rx_buffer_size = E1000_RX_BUFFER_SIZE_8K; 856 else if ((rx_size > FRAME_SIZE_UPTO_8K) && 857 (rx_size <= FRAME_SIZE_UPTO_16K)) 858 Adapter->rx_buffer_size = E1000_RX_BUFFER_SIZE_16K; 859 else 860 Adapter->rx_buffer_size = E1000_RX_BUFFER_SIZE_2K; 861 862 tx_size = Adapter->max_frame_size; 863 if ((tx_size > FRAME_SIZE_UPTO_2K) && (tx_size <= FRAME_SIZE_UPTO_4K)) 864 Adapter->tx_buffer_size = E1000_TX_BUFFER_SIZE_4K; 865 else if ((tx_size > FRAME_SIZE_UPTO_4K) && 866 (tx_size <= FRAME_SIZE_UPTO_8K)) 867 Adapter->tx_buffer_size = E1000_TX_BUFFER_SIZE_8K; 868 else if ((tx_size > FRAME_SIZE_UPTO_8K) && 869 (tx_size <= FRAME_SIZE_UPTO_16K)) 870 Adapter->tx_buffer_size = E1000_TX_BUFFER_SIZE_16K; 871 else 872 Adapter->tx_buffer_size = E1000_TX_BUFFER_SIZE_2K; 873 874 /* 875 * For Wiseman adapters we have an requirement of having receive 876 * buffers aligned at 256 byte boundary. Since Livengood does not 877 * require this and forcing it for all hardwares will have 878 * performance implications, I am making it applicable only for 879 * Wiseman and for Jumbo frames enabled mode as rest of the time, 880 * it is okay to have normal frames...but it does involve a 881 * potential risk where we may loose data if buffer is not 882 * aligned...so all wiseman boards to have 256 byte aligned 883 * buffers 884 */ 885 if (mac->type < e1000_82543) 886 Adapter->rx_buf_align = RECEIVE_BUFFER_ALIGN_SIZE; 887 else 888 Adapter->rx_buf_align = 1; 889 } 890 891 /* 892 * e1000g_detach - driver detach 893 * 894 * The detach() function is the complement of the attach routine. 895 * If cmd is set to DDI_DETACH, detach() is used to remove the 896 * state associated with a given instance of a device node 897 * prior to the removal of that instance from the system. 898 * 899 * The detach() function will be called once for each instance 900 * of the device for which there has been a successful attach() 901 * once there are no longer any opens on the device. 902 * 903 * Interrupts routine are disabled, All memory allocated by this 904 * driver are freed. 905 */ 906 static int 907 e1000g_detach(dev_info_t *devinfo, ddi_detach_cmd_t cmd) 908 { 909 struct e1000g *Adapter; 910 boolean_t rx_drain; 911 912 switch (cmd) { 913 default: 914 return (DDI_FAILURE); 915 916 case DDI_SUSPEND: 917 return (e1000g_suspend(devinfo)); 918 919 case DDI_DETACH: 920 break; 921 } 922 923 Adapter = (struct e1000g *)ddi_get_driver_private(devinfo); 924 if (Adapter == NULL) 925 return (DDI_FAILURE); 926 927 if (mac_unregister(Adapter->mh) != 0) { 928 e1000g_log(Adapter, CE_WARN, "Unregister MAC failed"); 929 return (DDI_FAILURE); 930 } 931 Adapter->attach_progress &= ~ATTACH_PROGRESS_MAC; 932 933 934 if (Adapter->chip_state != E1000G_STOP) 935 e1000g_stop(Adapter, B_TRUE); 936 937 rx_drain = e1000g_rx_drain(Adapter); 938 939 /* 940 * If e1000g_force_detach is enabled, driver detach is safe. 941 * We will let e1000g_free_priv_devi_node routine determine 942 * whether we need to free the priv_dip entry for current 943 * driver instance. 944 */ 945 if (e1000g_force_detach) { 946 e1000g_free_priv_devi_node(Adapter, rx_drain); 947 } else { 948 if (!rx_drain) 949 return (DDI_FAILURE); 950 } 951 952 e1000g_unattach(devinfo, Adapter); 953 954 return (DDI_SUCCESS); 955 } 956 957 /* 958 * e1000g_free_priv_devi_node - free a priv_dip entry for driver instance 959 * 960 * If free_flag is true, that indicates the upper layer is not holding 961 * the rx buffers, we could free the priv_dip entry safely. 962 * 963 * Otherwise, we have to keep this entry even after driver detached, 964 * and we also need to mark this entry with E1000G_PRIV_DEVI_DETACH flag, 965 * so that driver could free it while all of rx buffers are returned 966 * by upper layer later. 967 */ 968 static void 969 e1000g_free_priv_devi_node(struct e1000g *Adapter, boolean_t free_flag) 970 { 971 private_devi_list_t *devi_node, *devi_del; 972 973 rw_enter(&e1000g_rx_detach_lock, RW_WRITER); 974 ASSERT(e1000g_private_devi_list != NULL); 975 ASSERT(Adapter->priv_dip != NULL); 976 977 devi_node = e1000g_private_devi_list; 978 if (devi_node->priv_dip == Adapter->priv_dip) { 979 if (free_flag) { 980 e1000g_private_devi_list = 981 devi_node->next; 982 kmem_free(devi_node->priv_dip, 983 sizeof (struct dev_info)); 984 kmem_free(devi_node, 985 sizeof (private_devi_list_t)); 986 } else { 987 ASSERT(e1000g_mblks_pending != 0); 988 devi_node->flag = 989 E1000G_PRIV_DEVI_DETACH; 990 } 991 rw_exit(&e1000g_rx_detach_lock); 992 return; 993 } 994 995 devi_node = e1000g_private_devi_list; 996 while (devi_node->next != NULL) { 997 if (devi_node->next->priv_dip == Adapter->priv_dip) { 998 if (free_flag) { 999 devi_del = devi_node->next; 1000 devi_node->next = devi_del->next; 1001 kmem_free(devi_del->priv_dip, 1002 sizeof (struct dev_info)); 1003 kmem_free(devi_del, 1004 sizeof (private_devi_list_t)); 1005 } else { 1006 ASSERT(e1000g_mblks_pending != 0); 1007 devi_node->next->flag = 1008 E1000G_PRIV_DEVI_DETACH; 1009 } 1010 break; 1011 } 1012 devi_node = devi_node->next; 1013 } 1014 rw_exit(&e1000g_rx_detach_lock); 1015 } 1016 1017 static void 1018 e1000g_unattach(dev_info_t *devinfo, struct e1000g *Adapter) 1019 { 1020 int result; 1021 1022 if (Adapter->attach_progress & ATTACH_PROGRESS_ENABLE_INTR) { 1023 (void) e1000g_disable_intrs(Adapter); 1024 } 1025 1026 if (Adapter->attach_progress & ATTACH_PROGRESS_MAC) { 1027 (void) mac_unregister(Adapter->mh); 1028 } 1029 1030 if (Adapter->attach_progress & ATTACH_PROGRESS_ADD_INTR) { 1031 (void) e1000g_rem_intrs(Adapter); 1032 } 1033 1034 if (Adapter->attach_progress & ATTACH_PROGRESS_SETUP) { 1035 (void) ddi_prop_remove_all(devinfo); 1036 } 1037 1038 if (Adapter->attach_progress & ATTACH_PROGRESS_KSTATS) { 1039 kstat_delete((kstat_t *)Adapter->e1000g_ksp); 1040 } 1041 1042 if (Adapter->attach_progress & ATTACH_PROGRESS_INIT) { 1043 stop_link_timer(Adapter); 1044 1045 mutex_enter(&e1000g_nvm_lock); 1046 result = e1000_reset_hw(&Adapter->shared); 1047 mutex_exit(&e1000g_nvm_lock); 1048 1049 if (result != E1000_SUCCESS) { 1050 e1000g_fm_ereport(Adapter, DDI_FM_DEVICE_INVAL_STATE); 1051 ddi_fm_service_impact(Adapter->dip, DDI_SERVICE_LOST); 1052 } 1053 } 1054 1055 if (Adapter->attach_progress & ATTACH_PROGRESS_REGS_MAP) { 1056 if (Adapter->osdep.reg_handle != NULL) 1057 ddi_regs_map_free(&Adapter->osdep.reg_handle); 1058 if (Adapter->osdep.ich_flash_handle != NULL) 1059 ddi_regs_map_free(&Adapter->osdep.ich_flash_handle); 1060 } 1061 1062 if (Adapter->attach_progress & ATTACH_PROGRESS_PCI_CONFIG) { 1063 if (Adapter->osdep.cfg_handle != NULL) 1064 pci_config_teardown(&Adapter->osdep.cfg_handle); 1065 } 1066 1067 if (Adapter->attach_progress & ATTACH_PROGRESS_LOCKS) { 1068 e1000g_destroy_locks(Adapter); 1069 } 1070 1071 if (Adapter->attach_progress & ATTACH_PROGRESS_FMINIT) { 1072 e1000g_fm_fini(Adapter); 1073 } 1074 1075 e1000_remove_device(&Adapter->shared); 1076 1077 kmem_free((caddr_t)Adapter, sizeof (struct e1000g)); 1078 1079 /* 1080 * Another hotplug spec requirement, 1081 * run ddi_set_driver_private(devinfo, null); 1082 */ 1083 ddi_set_driver_private(devinfo, NULL); 1084 } 1085 1086 static void 1087 e1000g_init_locks(struct e1000g *Adapter) 1088 { 1089 e1000g_tx_ring_t *tx_ring; 1090 e1000g_rx_ring_t *rx_ring; 1091 1092 rw_init(&Adapter->chip_lock, NULL, 1093 RW_DRIVER, DDI_INTR_PRI(Adapter->intr_pri)); 1094 mutex_init(&Adapter->link_lock, NULL, 1095 MUTEX_DRIVER, DDI_INTR_PRI(Adapter->intr_pri)); 1096 mutex_init(&Adapter->watchdog_lock, NULL, 1097 MUTEX_DRIVER, DDI_INTR_PRI(Adapter->intr_pri)); 1098 1099 tx_ring = Adapter->tx_ring; 1100 1101 mutex_init(&tx_ring->tx_lock, NULL, 1102 MUTEX_DRIVER, DDI_INTR_PRI(Adapter->intr_pri)); 1103 mutex_init(&tx_ring->usedlist_lock, NULL, 1104 MUTEX_DRIVER, DDI_INTR_PRI(Adapter->intr_pri)); 1105 mutex_init(&tx_ring->freelist_lock, NULL, 1106 MUTEX_DRIVER, DDI_INTR_PRI(Adapter->intr_pri)); 1107 1108 rx_ring = Adapter->rx_ring; 1109 1110 mutex_init(&rx_ring->rx_lock, NULL, 1111 MUTEX_DRIVER, DDI_INTR_PRI(Adapter->intr_pri)); 1112 mutex_init(&rx_ring->freelist_lock, NULL, 1113 MUTEX_DRIVER, DDI_INTR_PRI(Adapter->intr_pri)); 1114 } 1115 1116 static void 1117 e1000g_destroy_locks(struct e1000g *Adapter) 1118 { 1119 e1000g_tx_ring_t *tx_ring; 1120 e1000g_rx_ring_t *rx_ring; 1121 1122 tx_ring = Adapter->tx_ring; 1123 mutex_destroy(&tx_ring->tx_lock); 1124 mutex_destroy(&tx_ring->usedlist_lock); 1125 mutex_destroy(&tx_ring->freelist_lock); 1126 1127 rx_ring = Adapter->rx_ring; 1128 mutex_destroy(&rx_ring->rx_lock); 1129 mutex_destroy(&rx_ring->freelist_lock); 1130 1131 mutex_destroy(&Adapter->link_lock); 1132 mutex_destroy(&Adapter->watchdog_lock); 1133 rw_destroy(&Adapter->chip_lock); 1134 } 1135 1136 static int 1137 e1000g_resume(dev_info_t *devinfo) 1138 { 1139 struct e1000g *Adapter; 1140 1141 Adapter = (struct e1000g *)ddi_get_driver_private(devinfo); 1142 if (Adapter == NULL) 1143 return (DDI_FAILURE); 1144 1145 if (e1000g_start(Adapter, B_TRUE)) 1146 return (DDI_FAILURE); 1147 1148 return (DDI_SUCCESS); 1149 } 1150 1151 static int 1152 e1000g_suspend(dev_info_t *devinfo) 1153 { 1154 struct e1000g *Adapter; 1155 1156 Adapter = (struct e1000g *)ddi_get_driver_private(devinfo); 1157 if (Adapter == NULL) 1158 return (DDI_FAILURE); 1159 1160 e1000g_stop(Adapter, B_TRUE); 1161 1162 return (DDI_SUCCESS); 1163 } 1164 1165 static int 1166 e1000g_init(struct e1000g *Adapter) 1167 { 1168 uint32_t pba; 1169 uint32_t high_water; 1170 struct e1000_hw *hw; 1171 clock_t link_timeout; 1172 int result; 1173 1174 hw = &Adapter->shared; 1175 1176 rw_enter(&Adapter->chip_lock, RW_WRITER); 1177 1178 /* 1179 * reset to put the hardware in a known state 1180 * before we try to do anything with the eeprom 1181 */ 1182 mutex_enter(&e1000g_nvm_lock); 1183 result = e1000_reset_hw(hw); 1184 mutex_exit(&e1000g_nvm_lock); 1185 1186 if (result != E1000_SUCCESS) { 1187 e1000g_fm_ereport(Adapter, DDI_FM_DEVICE_INVAL_STATE); 1188 goto init_fail; 1189 } 1190 1191 mutex_enter(&e1000g_nvm_lock); 1192 result = e1000_validate_nvm_checksum(hw); 1193 if (result < E1000_SUCCESS) { 1194 /* 1195 * Some PCI-E parts fail the first check due to 1196 * the link being in sleep state. Call it again, 1197 * if it fails a second time its a real issue. 1198 */ 1199 result = e1000_validate_nvm_checksum(hw); 1200 } 1201 mutex_exit(&e1000g_nvm_lock); 1202 1203 if (result < E1000_SUCCESS) { 1204 e1000g_log(Adapter, CE_WARN, 1205 "Invalid NVM checksum. Please contact " 1206 "the vendor to update the NVM."); 1207 e1000g_fm_ereport(Adapter, DDI_FM_DEVICE_INVAL_STATE); 1208 goto init_fail; 1209 } 1210 1211 result = 0; 1212 #ifdef __sparc 1213 /* 1214 * First, we try to get the local ethernet address from OBP. If 1215 * failed, then we get it from the EEPROM of NIC card. 1216 */ 1217 result = e1000g_find_mac_address(Adapter); 1218 #endif 1219 /* Get the local ethernet address. */ 1220 if (!result) { 1221 mutex_enter(&e1000g_nvm_lock); 1222 result = e1000_read_mac_addr(hw); 1223 mutex_exit(&e1000g_nvm_lock); 1224 } 1225 1226 if (result < E1000_SUCCESS) { 1227 e1000g_log(Adapter, CE_WARN, "Read mac addr failed"); 1228 e1000g_fm_ereport(Adapter, DDI_FM_DEVICE_INVAL_STATE); 1229 goto init_fail; 1230 } 1231 1232 /* check for valid mac address */ 1233 if (!is_valid_mac_addr(hw->mac.addr)) { 1234 e1000g_log(Adapter, CE_WARN, "Invalid mac addr"); 1235 e1000g_fm_ereport(Adapter, DDI_FM_DEVICE_INVAL_STATE); 1236 goto init_fail; 1237 } 1238 1239 /* Set LAA state for 82571 chipset */ 1240 e1000_set_laa_state_82571(hw, B_TRUE); 1241 1242 /* Master Latency Timer implementation */ 1243 if (Adapter->master_latency_timer) { 1244 pci_config_put8(Adapter->osdep.cfg_handle, 1245 PCI_CONF_LATENCY_TIMER, Adapter->master_latency_timer); 1246 } 1247 1248 if (hw->mac.type < e1000_82547) { 1249 /* 1250 * Total FIFO is 64K 1251 */ 1252 if (Adapter->max_frame_size > FRAME_SIZE_UPTO_8K) 1253 pba = E1000_PBA_40K; /* 40K for Rx, 24K for Tx */ 1254 else 1255 pba = E1000_PBA_48K; /* 48K for Rx, 16K for Tx */ 1256 } else if ((hw->mac.type == e1000_82571) || 1257 (hw->mac.type == e1000_82572) || 1258 (hw->mac.type == e1000_80003es2lan)) { 1259 /* 1260 * Total FIFO is 48K 1261 */ 1262 if (Adapter->max_frame_size > FRAME_SIZE_UPTO_8K) 1263 pba = E1000_PBA_30K; /* 30K for Rx, 18K for Tx */ 1264 else 1265 pba = E1000_PBA_38K; /* 38K for Rx, 10K for Tx */ 1266 } else if (hw->mac.type == e1000_82573) { 1267 pba = E1000_PBA_20K; /* 20K for Rx, 12K for Tx */ 1268 } else if (hw->mac.type == e1000_82574) { 1269 /* Keep adapter default: 20K for Rx, 20K for Tx */ 1270 pba = E1000_READ_REG(hw, E1000_PBA); 1271 } else if (hw->mac.type == e1000_ich8lan) { 1272 pba = E1000_PBA_8K; /* 8K for Rx, 12K for Tx */ 1273 } else if (hw->mac.type == e1000_ich9lan) { 1274 pba = E1000_PBA_10K; 1275 } else if (hw->mac.type == e1000_ich10lan) { 1276 pba = E1000_PBA_10K; 1277 } else { 1278 /* 1279 * Total FIFO is 40K 1280 */ 1281 if (Adapter->max_frame_size > FRAME_SIZE_UPTO_8K) 1282 pba = E1000_PBA_22K; /* 22K for Rx, 18K for Tx */ 1283 else 1284 pba = E1000_PBA_30K; /* 30K for Rx, 10K for Tx */ 1285 } 1286 E1000_WRITE_REG(hw, E1000_PBA, pba); 1287 1288 /* 1289 * These parameters set thresholds for the adapter's generation(Tx) 1290 * and response(Rx) to Ethernet PAUSE frames. These are just threshold 1291 * settings. Flow control is enabled or disabled in the configuration 1292 * file. 1293 * High-water mark is set down from the top of the rx fifo (not 1294 * sensitive to max_frame_size) and low-water is set just below 1295 * high-water mark. 1296 * The high water mark must be low enough to fit one full frame above 1297 * it in the rx FIFO. Should be the lower of: 1298 * 90% of the Rx FIFO size and the full Rx FIFO size minus the early 1299 * receive size (assuming ERT set to E1000_ERT_2048), or the full 1300 * Rx FIFO size minus one full frame. 1301 */ 1302 high_water = min(((pba << 10) * 9 / 10), 1303 ((hw->mac.type == e1000_82573 || hw->mac.type == e1000_ich9lan || 1304 hw->mac.type == e1000_ich10lan) ? 1305 ((pba << 10) - (E1000_ERT_2048 << 3)) : 1306 ((pba << 10) - Adapter->max_frame_size))); 1307 1308 hw->fc.high_water = high_water & 0xFFF8; 1309 hw->fc.low_water = hw->fc.high_water - 8; 1310 1311 if (hw->mac.type == e1000_80003es2lan) 1312 hw->fc.pause_time = 0xFFFF; 1313 else 1314 hw->fc.pause_time = E1000_FC_PAUSE_TIME; 1315 hw->fc.send_xon = B_TRUE; 1316 1317 /* 1318 * Reset the adapter hardware the second time. 1319 */ 1320 mutex_enter(&e1000g_nvm_lock); 1321 result = e1000_reset_hw(hw); 1322 mutex_exit(&e1000g_nvm_lock); 1323 1324 if (result != E1000_SUCCESS) { 1325 e1000g_fm_ereport(Adapter, DDI_FM_DEVICE_INVAL_STATE); 1326 goto init_fail; 1327 } 1328 1329 /* disable wakeup control by default */ 1330 if (hw->mac.type >= e1000_82544) 1331 E1000_WRITE_REG(hw, E1000_WUC, 0); 1332 1333 /* MWI setup */ 1334 e1000_pci_set_mwi(hw); 1335 1336 /* 1337 * Configure/Initialize hardware 1338 */ 1339 mutex_enter(&e1000g_nvm_lock); 1340 result = e1000_init_hw(hw); 1341 mutex_exit(&e1000g_nvm_lock); 1342 1343 if (result < E1000_SUCCESS) { 1344 e1000g_log(Adapter, CE_WARN, "Initialize hw failed"); 1345 e1000g_fm_ereport(Adapter, DDI_FM_DEVICE_INVAL_STATE); 1346 goto init_fail; 1347 } 1348 1349 /* 1350 * Restore LED settings to the default from EEPROM 1351 * to meet the standard for Sun platforms. 1352 */ 1353 (void) e1000_cleanup_led(hw); 1354 1355 /* Disable Smart Power Down */ 1356 phy_spd_state(hw, B_FALSE); 1357 1358 /* Make sure driver has control */ 1359 e1000g_get_driver_control(hw); 1360 1361 /* 1362 * Initialize unicast addresses. 1363 */ 1364 e1000g_init_unicst(Adapter); 1365 1366 /* 1367 * Setup and initialize the mctable structures. After this routine 1368 * completes Multicast table will be set 1369 */ 1370 e1000g_setup_multicast(Adapter); 1371 msec_delay(5); 1372 1373 /* 1374 * Implement Adaptive IFS 1375 */ 1376 e1000_reset_adaptive(hw); 1377 1378 /* Setup Interrupt Throttling Register */ 1379 if (hw->mac.type >= e1000_82540) { 1380 E1000_WRITE_REG(hw, E1000_ITR, Adapter->intr_throttling_rate); 1381 } else 1382 Adapter->intr_adaptive = B_FALSE; 1383 1384 /* Start the timer for link setup */ 1385 if (hw->mac.autoneg) 1386 link_timeout = PHY_AUTO_NEG_LIMIT * drv_usectohz(100000); 1387 else 1388 link_timeout = PHY_FORCE_LIMIT * drv_usectohz(100000); 1389 1390 mutex_enter(&Adapter->link_lock); 1391 if (hw->phy.autoneg_wait_to_complete) { 1392 Adapter->link_complete = B_TRUE; 1393 } else { 1394 Adapter->link_complete = B_FALSE; 1395 Adapter->link_tid = timeout(e1000g_link_timer, 1396 (void *)Adapter, link_timeout); 1397 } 1398 mutex_exit(&Adapter->link_lock); 1399 1400 /* Enable PCI-Ex master */ 1401 if (hw->bus.type == e1000_bus_type_pci_express) { 1402 e1000_enable_pciex_master(hw); 1403 } 1404 1405 /* Save the state of the phy */ 1406 e1000g_get_phy_state(Adapter); 1407 1408 e1000g_param_sync(Adapter); 1409 1410 Adapter->init_count++; 1411 1412 if (e1000g_check_acc_handle(Adapter->osdep.cfg_handle) != DDI_FM_OK) { 1413 goto init_fail; 1414 } 1415 if (e1000g_check_acc_handle(Adapter->osdep.reg_handle) != DDI_FM_OK) { 1416 goto init_fail; 1417 } 1418 1419 rw_exit(&Adapter->chip_lock); 1420 1421 return (DDI_SUCCESS); 1422 1423 init_fail: 1424 rw_exit(&Adapter->chip_lock); 1425 ddi_fm_service_impact(Adapter->dip, DDI_SERVICE_LOST); 1426 return (DDI_FAILURE); 1427 } 1428 1429 /* 1430 * Check if the link is up 1431 */ 1432 static boolean_t 1433 e1000g_link_up(struct e1000g *Adapter) 1434 { 1435 struct e1000_hw *hw; 1436 boolean_t link_up; 1437 1438 hw = &Adapter->shared; 1439 1440 (void) e1000_check_for_link(hw); 1441 1442 if ((E1000_READ_REG(hw, E1000_STATUS) & E1000_STATUS_LU) || 1443 ((!hw->mac.get_link_status) && (hw->mac.type == e1000_82543)) || 1444 ((hw->phy.media_type == e1000_media_type_internal_serdes) && 1445 (hw->mac.serdes_has_link))) { 1446 link_up = B_TRUE; 1447 } else { 1448 link_up = B_FALSE; 1449 } 1450 1451 return (link_up); 1452 } 1453 1454 static void 1455 e1000g_m_ioctl(void *arg, queue_t *q, mblk_t *mp) 1456 { 1457 struct iocblk *iocp; 1458 struct e1000g *e1000gp; 1459 enum ioc_reply status; 1460 1461 iocp = (struct iocblk *)(uintptr_t)mp->b_rptr; 1462 iocp->ioc_error = 0; 1463 e1000gp = (struct e1000g *)arg; 1464 1465 ASSERT(e1000gp); 1466 if (e1000gp == NULL) { 1467 miocnak(q, mp, 0, EINVAL); 1468 return; 1469 } 1470 1471 switch (iocp->ioc_cmd) { 1472 1473 case LB_GET_INFO_SIZE: 1474 case LB_GET_INFO: 1475 case LB_GET_MODE: 1476 case LB_SET_MODE: 1477 status = e1000g_loopback_ioctl(e1000gp, iocp, mp); 1478 break; 1479 1480 1481 #ifdef E1000G_DEBUG 1482 case E1000G_IOC_REG_PEEK: 1483 case E1000G_IOC_REG_POKE: 1484 status = e1000g_pp_ioctl(e1000gp, iocp, mp); 1485 break; 1486 case E1000G_IOC_CHIP_RESET: 1487 e1000gp->reset_count++; 1488 if (e1000g_reset_adapter(e1000gp)) 1489 status = IOC_ACK; 1490 else 1491 status = IOC_INVAL; 1492 break; 1493 #endif 1494 default: 1495 status = IOC_INVAL; 1496 break; 1497 } 1498 1499 /* 1500 * Decide how to reply 1501 */ 1502 switch (status) { 1503 default: 1504 case IOC_INVAL: 1505 /* 1506 * Error, reply with a NAK and EINVAL or the specified error 1507 */ 1508 miocnak(q, mp, 0, iocp->ioc_error == 0 ? 1509 EINVAL : iocp->ioc_error); 1510 break; 1511 1512 case IOC_DONE: 1513 /* 1514 * OK, reply already sent 1515 */ 1516 break; 1517 1518 case IOC_ACK: 1519 /* 1520 * OK, reply with an ACK 1521 */ 1522 miocack(q, mp, 0, 0); 1523 break; 1524 1525 case IOC_REPLY: 1526 /* 1527 * OK, send prepared reply as ACK or NAK 1528 */ 1529 mp->b_datap->db_type = iocp->ioc_error == 0 ? 1530 M_IOCACK : M_IOCNAK; 1531 qreply(q, mp); 1532 break; 1533 } 1534 } 1535 1536 static int 1537 e1000g_m_start(void *arg) 1538 { 1539 struct e1000g *Adapter = (struct e1000g *)arg; 1540 1541 return (e1000g_start(Adapter, B_TRUE)); 1542 } 1543 1544 static int 1545 e1000g_start(struct e1000g *Adapter, boolean_t global) 1546 { 1547 if (global) { 1548 /* Allocate dma resources for descriptors and buffers */ 1549 if (e1000g_alloc_dma_resources(Adapter) != DDI_SUCCESS) { 1550 e1000g_log(Adapter, CE_WARN, 1551 "Alloc DMA resources failed"); 1552 return (ENOTACTIVE); 1553 } 1554 Adapter->rx_buffer_setup = B_FALSE; 1555 } 1556 1557 if (!(Adapter->attach_progress & ATTACH_PROGRESS_INIT)) { 1558 if (e1000g_init(Adapter) != DDI_SUCCESS) { 1559 e1000g_log(Adapter, CE_WARN, 1560 "Adapter initialization failed"); 1561 if (global) 1562 e1000g_release_dma_resources(Adapter); 1563 return (ENOTACTIVE); 1564 } 1565 } 1566 1567 rw_enter(&Adapter->chip_lock, RW_WRITER); 1568 1569 /* Setup and initialize the transmit structures */ 1570 e1000g_tx_setup(Adapter); 1571 msec_delay(5); 1572 1573 /* Setup and initialize the receive structures */ 1574 e1000g_rx_setup(Adapter); 1575 msec_delay(5); 1576 1577 /* Restore the e1000g promiscuous mode */ 1578 e1000g_restore_promisc(Adapter); 1579 1580 e1000g_mask_interrupt(Adapter); 1581 1582 if (e1000g_check_acc_handle(Adapter->osdep.reg_handle) != DDI_FM_OK) { 1583 rw_exit(&Adapter->chip_lock); 1584 ddi_fm_service_impact(Adapter->dip, DDI_SERVICE_LOST); 1585 return (ENOTACTIVE); 1586 } 1587 1588 Adapter->chip_state = E1000G_START; 1589 Adapter->attach_progress |= ATTACH_PROGRESS_INIT; 1590 1591 rw_exit(&Adapter->chip_lock); 1592 1593 /* Enable and start the watchdog timer */ 1594 enable_watchdog_timer(Adapter); 1595 1596 return (0); 1597 } 1598 1599 static void 1600 e1000g_m_stop(void *arg) 1601 { 1602 struct e1000g *Adapter = (struct e1000g *)arg; 1603 1604 e1000g_stop(Adapter, B_TRUE); 1605 } 1606 1607 static void 1608 e1000g_stop(struct e1000g *Adapter, boolean_t global) 1609 { 1610 int result; 1611 1612 /* Set stop flags */ 1613 rw_enter(&Adapter->chip_lock, RW_WRITER); 1614 1615 Adapter->chip_state = E1000G_STOP; 1616 Adapter->attach_progress &= ~ATTACH_PROGRESS_INIT; 1617 1618 rw_exit(&Adapter->chip_lock); 1619 1620 /* Drain tx sessions */ 1621 (void) e1000g_tx_drain(Adapter); 1622 1623 /* Disable and stop all the timers */ 1624 disable_watchdog_timer(Adapter); 1625 stop_link_timer(Adapter); 1626 stop_82547_timer(Adapter->tx_ring); 1627 1628 /* Stop the chip and release pending resources */ 1629 rw_enter(&Adapter->chip_lock, RW_WRITER); 1630 1631 /* Tell firmware driver is no longer in control */ 1632 e1000g_release_driver_control(&Adapter->shared); 1633 1634 e1000g_clear_all_interrupts(Adapter); 1635 1636 mutex_enter(&e1000g_nvm_lock); 1637 result = e1000_reset_hw(&Adapter->shared); 1638 mutex_exit(&e1000g_nvm_lock); 1639 1640 if (result != E1000_SUCCESS) { 1641 e1000g_fm_ereport(Adapter, DDI_FM_DEVICE_INVAL_STATE); 1642 ddi_fm_service_impact(Adapter->dip, DDI_SERVICE_LOST); 1643 } 1644 1645 /* Release resources still held by the TX descriptors */ 1646 e1000g_tx_clean(Adapter); 1647 1648 if (e1000g_check_acc_handle(Adapter->osdep.reg_handle) != DDI_FM_OK) 1649 ddi_fm_service_impact(Adapter->dip, DDI_SERVICE_LOST); 1650 1651 /* Clean the pending rx jumbo packet fragment */ 1652 e1000g_rx_clean(Adapter); 1653 1654 rw_exit(&Adapter->chip_lock); 1655 1656 if (global) 1657 e1000g_release_dma_resources(Adapter); 1658 } 1659 1660 static void 1661 e1000g_rx_clean(struct e1000g *Adapter) 1662 { 1663 e1000g_rx_ring_t *rx_ring = Adapter->rx_ring; 1664 1665 if (rx_ring->rx_mblk != NULL) { 1666 freemsg(rx_ring->rx_mblk); 1667 rx_ring->rx_mblk = NULL; 1668 rx_ring->rx_mblk_tail = NULL; 1669 rx_ring->rx_mblk_len = 0; 1670 } 1671 } 1672 1673 static void 1674 e1000g_tx_clean(struct e1000g *Adapter) 1675 { 1676 e1000g_tx_ring_t *tx_ring; 1677 p_tx_sw_packet_t packet; 1678 mblk_t *mp; 1679 mblk_t *nmp; 1680 uint32_t packet_count; 1681 1682 tx_ring = Adapter->tx_ring; 1683 1684 /* 1685 * Here we don't need to protect the lists using 1686 * the usedlist_lock and freelist_lock, for they 1687 * have been protected by the chip_lock. 1688 */ 1689 mp = NULL; 1690 nmp = NULL; 1691 packet_count = 0; 1692 packet = (p_tx_sw_packet_t)QUEUE_GET_HEAD(&tx_ring->used_list); 1693 while (packet != NULL) { 1694 if (packet->mp != NULL) { 1695 /* Assemble the message chain */ 1696 if (mp == NULL) { 1697 mp = packet->mp; 1698 nmp = packet->mp; 1699 } else { 1700 nmp->b_next = packet->mp; 1701 nmp = packet->mp; 1702 } 1703 /* Disconnect the message from the sw packet */ 1704 packet->mp = NULL; 1705 } 1706 1707 e1000g_free_tx_swpkt(packet); 1708 packet_count++; 1709 1710 packet = (p_tx_sw_packet_t) 1711 QUEUE_GET_NEXT(&tx_ring->used_list, &packet->Link); 1712 } 1713 1714 if (mp != NULL) 1715 freemsgchain(mp); 1716 1717 if (packet_count > 0) { 1718 QUEUE_APPEND(&tx_ring->free_list, &tx_ring->used_list); 1719 QUEUE_INIT_LIST(&tx_ring->used_list); 1720 1721 /* Setup TX descriptor pointers */ 1722 tx_ring->tbd_next = tx_ring->tbd_first; 1723 tx_ring->tbd_oldest = tx_ring->tbd_first; 1724 1725 /* Setup our HW Tx Head & Tail descriptor pointers */ 1726 E1000_WRITE_REG(&Adapter->shared, E1000_TDH(0), 0); 1727 E1000_WRITE_REG(&Adapter->shared, E1000_TDT(0), 0); 1728 } 1729 } 1730 1731 static boolean_t 1732 e1000g_tx_drain(struct e1000g *Adapter) 1733 { 1734 int i; 1735 boolean_t done; 1736 e1000g_tx_ring_t *tx_ring; 1737 1738 tx_ring = Adapter->tx_ring; 1739 1740 /* Allow up to 'wsdraintime' for pending xmit's to complete. */ 1741 for (i = 0; i < TX_DRAIN_TIME; i++) { 1742 mutex_enter(&tx_ring->usedlist_lock); 1743 done = IS_QUEUE_EMPTY(&tx_ring->used_list); 1744 mutex_exit(&tx_ring->usedlist_lock); 1745 1746 if (done) 1747 break; 1748 1749 msec_delay(1); 1750 } 1751 1752 return (done); 1753 } 1754 1755 static boolean_t 1756 e1000g_rx_drain(struct e1000g *Adapter) 1757 { 1758 e1000g_rx_ring_t *rx_ring; 1759 p_rx_sw_packet_t packet; 1760 boolean_t done; 1761 1762 rx_ring = Adapter->rx_ring; 1763 done = B_TRUE; 1764 1765 rw_enter(&e1000g_rx_detach_lock, RW_WRITER); 1766 1767 while (rx_ring->pending_list != NULL) { 1768 packet = rx_ring->pending_list; 1769 rx_ring->pending_list = 1770 rx_ring->pending_list->next; 1771 1772 if (packet->flag == E1000G_RX_SW_STOP) { 1773 packet->flag = E1000G_RX_SW_DETACH; 1774 done = B_FALSE; 1775 } else { 1776 ASSERT(packet->flag == E1000G_RX_SW_FREE); 1777 ASSERT(packet->mp == NULL); 1778 e1000g_free_rx_sw_packet(packet); 1779 } 1780 } 1781 1782 rw_exit(&e1000g_rx_detach_lock); 1783 1784 return (done); 1785 } 1786 1787 static boolean_t 1788 e1000g_reset_adapter(struct e1000g *Adapter) 1789 { 1790 e1000g_stop(Adapter, B_FALSE); 1791 1792 if (e1000g_start(Adapter, B_FALSE)) { 1793 e1000g_log(Adapter, CE_WARN, "Reset failed"); 1794 return (B_FALSE); 1795 } 1796 1797 return (B_TRUE); 1798 } 1799 1800 boolean_t 1801 e1000g_global_reset(struct e1000g *Adapter) 1802 { 1803 e1000g_stop(Adapter, B_TRUE); 1804 1805 Adapter->init_count = 0; 1806 1807 if (e1000g_start(Adapter, B_TRUE)) { 1808 e1000g_log(Adapter, CE_WARN, "Reset failed"); 1809 return (B_FALSE); 1810 } 1811 1812 return (B_TRUE); 1813 } 1814 1815 /* 1816 * e1000g_intr_pciexpress - ISR for PCI Express chipsets 1817 * 1818 * This interrupt service routine is for PCI-Express adapters. 1819 * The ICR contents is valid only when the E1000_ICR_INT_ASSERTED 1820 * bit is set. 1821 */ 1822 static uint_t 1823 e1000g_intr_pciexpress(caddr_t arg) 1824 { 1825 struct e1000g *Adapter; 1826 uint32_t icr; 1827 1828 Adapter = (struct e1000g *)(uintptr_t)arg; 1829 icr = E1000_READ_REG(&Adapter->shared, E1000_ICR); 1830 1831 if (e1000g_check_acc_handle(Adapter->osdep.reg_handle) != DDI_FM_OK) 1832 ddi_fm_service_impact(Adapter->dip, DDI_SERVICE_DEGRADED); 1833 1834 if (icr & E1000_ICR_INT_ASSERTED) { 1835 /* 1836 * E1000_ICR_INT_ASSERTED bit was set: 1837 * Read(Clear) the ICR, claim this interrupt, 1838 * look for work to do. 1839 */ 1840 e1000g_intr_work(Adapter, icr); 1841 return (DDI_INTR_CLAIMED); 1842 } else { 1843 /* 1844 * E1000_ICR_INT_ASSERTED bit was not set: 1845 * Don't claim this interrupt, return immediately. 1846 */ 1847 return (DDI_INTR_UNCLAIMED); 1848 } 1849 } 1850 1851 /* 1852 * e1000g_intr - ISR for PCI/PCI-X chipsets 1853 * 1854 * This interrupt service routine is for PCI/PCI-X adapters. 1855 * We check the ICR contents no matter the E1000_ICR_INT_ASSERTED 1856 * bit is set or not. 1857 */ 1858 static uint_t 1859 e1000g_intr(caddr_t arg) 1860 { 1861 struct e1000g *Adapter; 1862 uint32_t icr; 1863 1864 Adapter = (struct e1000g *)(uintptr_t)arg; 1865 icr = E1000_READ_REG(&Adapter->shared, E1000_ICR); 1866 1867 if (e1000g_check_acc_handle(Adapter->osdep.reg_handle) != DDI_FM_OK) 1868 ddi_fm_service_impact(Adapter->dip, DDI_SERVICE_DEGRADED); 1869 1870 if (icr) { 1871 /* 1872 * Any bit was set in ICR: 1873 * Read(Clear) the ICR, claim this interrupt, 1874 * look for work to do. 1875 */ 1876 e1000g_intr_work(Adapter, icr); 1877 return (DDI_INTR_CLAIMED); 1878 } else { 1879 /* 1880 * No bit was set in ICR: 1881 * Don't claim this interrupt, return immediately. 1882 */ 1883 return (DDI_INTR_UNCLAIMED); 1884 } 1885 } 1886 1887 /* 1888 * e1000g_intr_work - actual processing of ISR 1889 * 1890 * Read(clear) the ICR contents and call appropriate interrupt 1891 * processing routines. 1892 */ 1893 static void 1894 e1000g_intr_work(struct e1000g *Adapter, uint32_t icr) 1895 { 1896 struct e1000_hw *hw; 1897 hw = &Adapter->shared; 1898 e1000g_tx_ring_t *tx_ring = Adapter->tx_ring; 1899 uint32_t itr; 1900 1901 Adapter->rx_pkt_cnt = 0; 1902 Adapter->tx_pkt_cnt = 0; 1903 1904 rw_enter(&Adapter->chip_lock, RW_READER); 1905 /* 1906 * Here we need to check the "chip_state" flag within the chip_lock to 1907 * ensure the receive routine will not execute when the adapter is 1908 * being reset. 1909 */ 1910 if (Adapter->chip_state != E1000G_START) { 1911 rw_exit(&Adapter->chip_lock); 1912 return; 1913 } 1914 1915 if (icr & E1000_ICR_RXT0) { 1916 mblk_t *mp; 1917 1918 mutex_enter(&Adapter->rx_ring->rx_lock); 1919 mp = e1000g_receive(Adapter); 1920 mutex_exit(&Adapter->rx_ring->rx_lock); 1921 1922 rw_exit(&Adapter->chip_lock); 1923 1924 if (mp != NULL) 1925 mac_rx(Adapter->mh, Adapter->mrh, mp); 1926 } else 1927 rw_exit(&Adapter->chip_lock); 1928 1929 if (icr & E1000_ICR_TXDW) { 1930 if (!Adapter->tx_intr_enable) 1931 e1000g_clear_tx_interrupt(Adapter); 1932 1933 /* Recycle the tx descriptors */ 1934 rw_enter(&Adapter->chip_lock, RW_READER); 1935 (void) e1000g_recycle(tx_ring); 1936 E1000G_DEBUG_STAT(tx_ring->stat_recycle_intr); 1937 rw_exit(&Adapter->chip_lock); 1938 1939 /* Schedule the re-transmit */ 1940 if (tx_ring->resched_needed && 1941 (tx_ring->tbd_avail > DEFAULT_TX_UPDATE_THRESHOLD)) { 1942 tx_ring->resched_needed = B_FALSE; 1943 mac_tx_update(Adapter->mh); 1944 E1000G_STAT(tx_ring->stat_reschedule); 1945 } 1946 } 1947 1948 if (Adapter->intr_adaptive) { 1949 itr = e1000g_get_itr(Adapter->rx_pkt_cnt, Adapter->tx_pkt_cnt, 1950 Adapter->intr_throttling_rate); 1951 if (itr) { 1952 E1000_WRITE_REG(hw, E1000_ITR, itr); 1953 Adapter->intr_throttling_rate = itr; 1954 } 1955 } 1956 1957 /* 1958 * The Receive Sequence errors RXSEQ and the link status change LSC 1959 * are checked to detect that the cable has been pulled out. For 1960 * the Wiseman 2.0 silicon, the receive sequence errors interrupt 1961 * are an indication that cable is not connected. 1962 */ 1963 if ((icr & E1000_ICR_RXSEQ) || 1964 (icr & E1000_ICR_LSC) || 1965 (icr & E1000_ICR_GPI_EN1)) { 1966 boolean_t link_changed; 1967 timeout_id_t tid = 0; 1968 1969 stop_watchdog_timer(Adapter); 1970 1971 rw_enter(&Adapter->chip_lock, RW_WRITER); 1972 1973 /* 1974 * Because we got a link-status-change interrupt, force 1975 * e1000_check_for_link() to look at phy 1976 */ 1977 Adapter->shared.mac.get_link_status = B_TRUE; 1978 1979 /* e1000g_link_check takes care of link status change */ 1980 link_changed = e1000g_link_check(Adapter); 1981 1982 /* Get new phy state */ 1983 e1000g_get_phy_state(Adapter); 1984 1985 /* 1986 * If the link timer has not timed out, we'll not notify 1987 * the upper layer with any link state until the link is up. 1988 */ 1989 if (link_changed && !Adapter->link_complete) { 1990 if (Adapter->link_state == LINK_STATE_UP) { 1991 mutex_enter(&Adapter->link_lock); 1992 Adapter->link_complete = B_TRUE; 1993 tid = Adapter->link_tid; 1994 Adapter->link_tid = 0; 1995 mutex_exit(&Adapter->link_lock); 1996 } else { 1997 link_changed = B_FALSE; 1998 } 1999 } 2000 rw_exit(&Adapter->chip_lock); 2001 2002 if (link_changed) { 2003 if (tid != 0) 2004 (void) untimeout(tid); 2005 2006 /* 2007 * Workaround for esb2. Data stuck in fifo on a link 2008 * down event. Stop receiver here and reset in watchdog. 2009 */ 2010 if ((Adapter->link_state == LINK_STATE_DOWN) && 2011 (Adapter->shared.mac.type == e1000_80003es2lan)) { 2012 uint32_t rctl = E1000_READ_REG(hw, E1000_RCTL); 2013 E1000_WRITE_REG(hw, E1000_RCTL, 2014 rctl & ~E1000_RCTL_EN); 2015 e1000g_log(Adapter, CE_WARN, 2016 "ESB2 receiver disabled"); 2017 Adapter->esb2_workaround = B_TRUE; 2018 } 2019 2020 mac_link_update(Adapter->mh, Adapter->link_state); 2021 } 2022 2023 start_watchdog_timer(Adapter); 2024 } 2025 } 2026 2027 static uint32_t 2028 e1000g_get_itr(uint32_t rx_packet, uint32_t tx_packet, uint32_t cur_itr) 2029 { 2030 uint32_t new_itr; 2031 2032 /* 2033 * Determine a propper itr according to rx/tx packet count 2034 * per interrupt, the value of itr are based on document 2035 * and testing. 2036 */ 2037 if ((rx_packet < DEFAULT_INTR_PACKET_LOW) || 2038 (tx_packet < DEFAULT_INTR_PACKET_LOW)) { 2039 new_itr = DEFAULT_INTR_THROTTLING_LOW; 2040 goto itr_done; 2041 } 2042 if ((rx_packet > DEFAULT_INTR_PACKET_HIGH) || 2043 (tx_packet > DEFAULT_INTR_PACKET_HIGH)) { 2044 new_itr = DEFAULT_INTR_THROTTLING_LOW; 2045 goto itr_done; 2046 } 2047 if (cur_itr < DEFAULT_INTR_THROTTLING_HIGH) { 2048 new_itr = cur_itr + (DEFAULT_INTR_THROTTLING_HIGH >> 2); 2049 if (new_itr > DEFAULT_INTR_THROTTLING_HIGH) 2050 new_itr = DEFAULT_INTR_THROTTLING_HIGH; 2051 } else 2052 new_itr = DEFAULT_INTR_THROTTLING_HIGH; 2053 2054 itr_done: 2055 if (cur_itr == new_itr) 2056 return (0); 2057 else 2058 return (new_itr); 2059 } 2060 2061 static void 2062 e1000g_init_unicst(struct e1000g *Adapter) 2063 { 2064 struct e1000_hw *hw; 2065 int slot; 2066 2067 hw = &Adapter->shared; 2068 2069 if (!Adapter->unicst_init) { 2070 /* Initialize the multiple unicast addresses */ 2071 Adapter->unicst_total = MAX_NUM_UNICAST_ADDRESSES; 2072 2073 if ((hw->mac.type == e1000_82571) && 2074 (e1000_get_laa_state_82571(hw) == B_TRUE)) 2075 Adapter->unicst_total--; 2076 2077 Adapter->unicst_avail = Adapter->unicst_total - 1; 2078 2079 /* Store the default mac address */ 2080 e1000_rar_set(hw, hw->mac.addr, 0); 2081 if ((hw->mac.type == e1000_82571) && 2082 (e1000_get_laa_state_82571(hw) == B_TRUE)) 2083 e1000_rar_set(hw, hw->mac.addr, LAST_RAR_ENTRY); 2084 2085 bcopy(hw->mac.addr, Adapter->unicst_addr[0].mac.addr, 2086 ETHERADDRL); 2087 Adapter->unicst_addr[0].mac.set = 1; 2088 2089 for (slot = 1; slot < Adapter->unicst_total; slot++) 2090 Adapter->unicst_addr[slot].mac.set = 0; 2091 2092 Adapter->unicst_init = B_TRUE; 2093 } else { 2094 /* Recover the default mac address */ 2095 bcopy(Adapter->unicst_addr[0].mac.addr, hw->mac.addr, 2096 ETHERADDRL); 2097 2098 /* Store the default mac address */ 2099 e1000_rar_set(hw, hw->mac.addr, 0); 2100 if ((hw->mac.type == e1000_82571) && 2101 (e1000_get_laa_state_82571(hw) == B_TRUE)) 2102 e1000_rar_set(hw, hw->mac.addr, LAST_RAR_ENTRY); 2103 2104 /* Re-configure the RAR registers */ 2105 for (slot = 1; slot < Adapter->unicst_total; slot++) 2106 e1000_rar_set(hw, 2107 Adapter->unicst_addr[slot].mac.addr, slot); 2108 } 2109 2110 if (e1000g_check_acc_handle(Adapter->osdep.reg_handle) != DDI_FM_OK) 2111 ddi_fm_service_impact(Adapter->dip, DDI_SERVICE_DEGRADED); 2112 } 2113 2114 static int 2115 e1000g_m_unicst(void *arg, const uint8_t *mac_addr) 2116 { 2117 struct e1000g *Adapter; 2118 2119 Adapter = (struct e1000g *)arg; 2120 2121 /* Store the default MAC address */ 2122 bcopy(mac_addr, Adapter->shared.mac.addr, ETHERADDRL); 2123 2124 /* Set MAC address in address slot 0, which is the default address */ 2125 return (e1000g_unicst_set(Adapter, mac_addr, 0)); 2126 } 2127 2128 static int 2129 e1000g_unicst_set(struct e1000g *Adapter, const uint8_t *mac_addr, 2130 mac_addr_slot_t slot) 2131 { 2132 struct e1000_hw *hw; 2133 2134 hw = &Adapter->shared; 2135 2136 rw_enter(&Adapter->chip_lock, RW_WRITER); 2137 2138 /* 2139 * The first revision of Wiseman silicon (rev 2.0) has an errata 2140 * that requires the receiver to be in reset when any of the 2141 * receive address registers (RAR regs) are accessed. The first 2142 * rev of Wiseman silicon also requires MWI to be disabled when 2143 * a global reset or a receive reset is issued. So before we 2144 * initialize the RARs, we check the rev of the Wiseman controller 2145 * and work around any necessary HW errata. 2146 */ 2147 if ((hw->mac.type == e1000_82542) && 2148 (hw->revision_id == E1000_REVISION_2)) { 2149 e1000_pci_clear_mwi(hw); 2150 E1000_WRITE_REG(hw, E1000_RCTL, E1000_RCTL_RST); 2151 msec_delay(5); 2152 } 2153 2154 bcopy(mac_addr, Adapter->unicst_addr[slot].mac.addr, ETHERADDRL); 2155 e1000_rar_set(hw, (uint8_t *)mac_addr, slot); 2156 2157 if (slot == 0) { 2158 if ((hw->mac.type == e1000_82571) && 2159 (e1000_get_laa_state_82571(hw) == B_TRUE)) 2160 e1000_rar_set(hw, (uint8_t *)mac_addr, LAST_RAR_ENTRY); 2161 } 2162 2163 /* 2164 * If we are using Wiseman rev 2.0 silicon, we will have previously 2165 * put the receive in reset, and disabled MWI, to work around some 2166 * HW errata. Now we should take the receiver out of reset, and 2167 * re-enabled if MWI if it was previously enabled by the PCI BIOS. 2168 */ 2169 if ((hw->mac.type == e1000_82542) && 2170 (hw->revision_id == E1000_REVISION_2)) { 2171 E1000_WRITE_REG(hw, E1000_RCTL, 0); 2172 msec_delay(1); 2173 if (hw->bus.pci_cmd_word & CMD_MEM_WRT_INVALIDATE) 2174 e1000_pci_set_mwi(hw); 2175 e1000g_rx_setup(Adapter); 2176 } 2177 2178 rw_exit(&Adapter->chip_lock); 2179 2180 if (e1000g_check_acc_handle(Adapter->osdep.reg_handle) != DDI_FM_OK) { 2181 ddi_fm_service_impact(Adapter->dip, DDI_SERVICE_DEGRADED); 2182 return (EIO); 2183 } 2184 2185 return (0); 2186 } 2187 2188 /* 2189 * e1000g_m_unicst_add() - will find an unused address slot, set the 2190 * address value to the one specified, reserve that slot and enable 2191 * the NIC to start filtering on the new MAC address. 2192 * Returns 0 on success. 2193 */ 2194 static int 2195 e1000g_m_unicst_add(void *arg, mac_multi_addr_t *maddr) 2196 { 2197 struct e1000g *Adapter = (struct e1000g *)arg; 2198 mac_addr_slot_t slot; 2199 int err; 2200 2201 if (mac_unicst_verify(Adapter->mh, 2202 maddr->mma_addr, maddr->mma_addrlen) == B_FALSE) 2203 return (EINVAL); 2204 2205 rw_enter(&Adapter->chip_lock, RW_WRITER); 2206 if (Adapter->unicst_avail == 0) { 2207 /* no slots available */ 2208 rw_exit(&Adapter->chip_lock); 2209 return (ENOSPC); 2210 } 2211 2212 /* 2213 * Primary/default address is in slot 0. The next addresses 2214 * are the multiple MAC addresses. So multiple MAC address 0 2215 * is in slot 1, 1 in slot 2, and so on. So the first multiple 2216 * MAC address resides in slot 1. 2217 */ 2218 for (slot = 1; slot < Adapter->unicst_total; slot++) { 2219 if (Adapter->unicst_addr[slot].mac.set == 0) { 2220 Adapter->unicst_addr[slot].mac.set = 1; 2221 break; 2222 } 2223 } 2224 2225 ASSERT((slot > 0) && (slot < Adapter->unicst_total)); 2226 2227 Adapter->unicst_avail--; 2228 rw_exit(&Adapter->chip_lock); 2229 2230 maddr->mma_slot = slot; 2231 2232 if ((err = e1000g_unicst_set(Adapter, maddr->mma_addr, slot)) != 0) { 2233 rw_enter(&Adapter->chip_lock, RW_WRITER); 2234 Adapter->unicst_addr[slot].mac.set = 0; 2235 Adapter->unicst_avail++; 2236 rw_exit(&Adapter->chip_lock); 2237 } 2238 2239 return (err); 2240 } 2241 2242 /* 2243 * e1000g_m_unicst_remove() - removes a MAC address that was added by a 2244 * call to e1000g_m_unicst_add(). The slot number that was returned in 2245 * e1000g_m_unicst_add() is passed in the call to remove the address. 2246 * Returns 0 on success. 2247 */ 2248 static int 2249 e1000g_m_unicst_remove(void *arg, mac_addr_slot_t slot) 2250 { 2251 struct e1000g *Adapter = (struct e1000g *)arg; 2252 int err; 2253 2254 if ((slot <= 0) || (slot >= Adapter->unicst_total)) 2255 return (EINVAL); 2256 2257 rw_enter(&Adapter->chip_lock, RW_WRITER); 2258 if (Adapter->unicst_addr[slot].mac.set == 1) { 2259 Adapter->unicst_addr[slot].mac.set = 0; 2260 Adapter->unicst_avail++; 2261 rw_exit(&Adapter->chip_lock); 2262 2263 /* Copy the default address to the passed slot */ 2264 if ((err = e1000g_unicst_set(Adapter, 2265 Adapter->unicst_addr[0].mac.addr, slot)) != 0) { 2266 rw_enter(&Adapter->chip_lock, RW_WRITER); 2267 Adapter->unicst_addr[slot].mac.set = 1; 2268 Adapter->unicst_avail--; 2269 rw_exit(&Adapter->chip_lock); 2270 } 2271 return (err); 2272 } 2273 rw_exit(&Adapter->chip_lock); 2274 2275 return (EINVAL); 2276 } 2277 2278 /* 2279 * e1000g_m_unicst_modify() - modifies the value of an address that 2280 * has been added by e1000g_m_unicst_add(). The new address, address 2281 * length and the slot number that was returned in the call to add 2282 * should be passed to e1000g_m_unicst_modify(). mma_flags should be 2283 * set to 0. Returns 0 on success. 2284 */ 2285 static int 2286 e1000g_m_unicst_modify(void *arg, mac_multi_addr_t *maddr) 2287 { 2288 struct e1000g *Adapter = (struct e1000g *)arg; 2289 mac_addr_slot_t slot; 2290 2291 if (mac_unicst_verify(Adapter->mh, 2292 maddr->mma_addr, maddr->mma_addrlen) == B_FALSE) 2293 return (EINVAL); 2294 2295 slot = maddr->mma_slot; 2296 2297 if ((slot <= 0) || (slot >= Adapter->unicst_total)) 2298 return (EINVAL); 2299 2300 rw_enter(&Adapter->chip_lock, RW_WRITER); 2301 if (Adapter->unicst_addr[slot].mac.set == 1) { 2302 rw_exit(&Adapter->chip_lock); 2303 2304 return (e1000g_unicst_set(Adapter, maddr->mma_addr, slot)); 2305 } 2306 rw_exit(&Adapter->chip_lock); 2307 2308 return (EINVAL); 2309 } 2310 2311 /* 2312 * e1000g_m_unicst_get() - will get the MAC address and all other 2313 * information related to the address slot passed in mac_multi_addr_t. 2314 * mma_flags should be set to 0 in the call. 2315 * On return, mma_flags can take the following values: 2316 * 1) MMAC_SLOT_UNUSED 2317 * 2) MMAC_SLOT_USED | MMAC_VENDOR_ADDR 2318 * 3) MMAC_SLOT_UNUSED | MMAC_VENDOR_ADDR 2319 * 4) MMAC_SLOT_USED 2320 */ 2321 static int 2322 e1000g_m_unicst_get(void *arg, mac_multi_addr_t *maddr) 2323 { 2324 struct e1000g *Adapter = (struct e1000g *)arg; 2325 mac_addr_slot_t slot; 2326 2327 slot = maddr->mma_slot; 2328 2329 if ((slot <= 0) || (slot >= Adapter->unicst_total)) 2330 return (EINVAL); 2331 2332 rw_enter(&Adapter->chip_lock, RW_WRITER); 2333 if (Adapter->unicst_addr[slot].mac.set == 1) { 2334 bcopy(Adapter->unicst_addr[slot].mac.addr, 2335 maddr->mma_addr, ETHERADDRL); 2336 maddr->mma_flags = MMAC_SLOT_USED; 2337 } else { 2338 maddr->mma_flags = MMAC_SLOT_UNUSED; 2339 } 2340 rw_exit(&Adapter->chip_lock); 2341 2342 return (0); 2343 } 2344 2345 static int 2346 multicst_add(struct e1000g *Adapter, const uint8_t *multiaddr) 2347 { 2348 struct e1000_hw *hw = &Adapter->shared; 2349 int res = 0; 2350 2351 rw_enter(&Adapter->chip_lock, RW_WRITER); 2352 2353 if ((multiaddr[0] & 01) == 0) { 2354 res = EINVAL; 2355 goto done; 2356 } 2357 2358 if (Adapter->mcast_count >= MAX_NUM_MULTICAST_ADDRESSES) { 2359 res = ENOENT; 2360 goto done; 2361 } 2362 2363 bcopy(multiaddr, 2364 &Adapter->mcast_table[Adapter->mcast_count], ETHERADDRL); 2365 Adapter->mcast_count++; 2366 2367 /* 2368 * Update the MC table in the hardware 2369 */ 2370 e1000g_clear_interrupt(Adapter); 2371 2372 e1000g_setup_multicast(Adapter); 2373 2374 if ((hw->mac.type == e1000_82542) && 2375 (hw->revision_id == E1000_REVISION_2)) 2376 e1000g_rx_setup(Adapter); 2377 2378 e1000g_mask_interrupt(Adapter); 2379 2380 done: 2381 rw_exit(&Adapter->chip_lock); 2382 if (e1000g_check_acc_handle(Adapter->osdep.reg_handle) != DDI_FM_OK) { 2383 ddi_fm_service_impact(Adapter->dip, DDI_SERVICE_DEGRADED); 2384 res = EIO; 2385 } 2386 2387 return (res); 2388 } 2389 2390 static int 2391 multicst_remove(struct e1000g *Adapter, const uint8_t *multiaddr) 2392 { 2393 struct e1000_hw *hw = &Adapter->shared; 2394 unsigned i; 2395 2396 rw_enter(&Adapter->chip_lock, RW_WRITER); 2397 2398 for (i = 0; i < Adapter->mcast_count; i++) { 2399 if (bcmp(multiaddr, &Adapter->mcast_table[i], 2400 ETHERADDRL) == 0) { 2401 for (i++; i < Adapter->mcast_count; i++) { 2402 Adapter->mcast_table[i - 1] = 2403 Adapter->mcast_table[i]; 2404 } 2405 Adapter->mcast_count--; 2406 break; 2407 } 2408 } 2409 2410 /* 2411 * Update the MC table in the hardware 2412 */ 2413 e1000g_clear_interrupt(Adapter); 2414 2415 e1000g_setup_multicast(Adapter); 2416 2417 if ((hw->mac.type == e1000_82542) && 2418 (hw->revision_id == E1000_REVISION_2)) 2419 e1000g_rx_setup(Adapter); 2420 2421 e1000g_mask_interrupt(Adapter); 2422 2423 done: 2424 rw_exit(&Adapter->chip_lock); 2425 if (e1000g_check_acc_handle(Adapter->osdep.reg_handle) != DDI_FM_OK) { 2426 ddi_fm_service_impact(Adapter->dip, DDI_SERVICE_DEGRADED); 2427 return (EIO); 2428 } 2429 2430 return (0); 2431 } 2432 2433 /* 2434 * e1000g_setup_multicast - setup multicast data structures 2435 * 2436 * This routine initializes all of the multicast related structures. 2437 */ 2438 void 2439 e1000g_setup_multicast(struct e1000g *Adapter) 2440 { 2441 uint8_t *mc_addr_list; 2442 uint32_t mc_addr_count; 2443 uint32_t rctl; 2444 struct e1000_hw *hw; 2445 2446 hw = &Adapter->shared; 2447 2448 /* 2449 * The e1000g has the ability to do perfect filtering of 16 2450 * addresses. The driver uses one of the e1000g's 16 receive 2451 * address registers for its node/network/mac/individual address. 2452 * So, we have room for up to 15 multicast addresses in the CAM, 2453 * additional MC addresses are handled by the MTA (Multicast Table 2454 * Array) 2455 */ 2456 2457 rctl = E1000_READ_REG(hw, E1000_RCTL); 2458 2459 mc_addr_list = (uint8_t *)Adapter->mcast_table; 2460 2461 if (Adapter->mcast_count > MAX_NUM_MULTICAST_ADDRESSES) { 2462 E1000G_DEBUGLOG_1(Adapter, CE_WARN, 2463 "Adapter requested more than %d MC Addresses.\n", 2464 MAX_NUM_MULTICAST_ADDRESSES); 2465 mc_addr_count = MAX_NUM_MULTICAST_ADDRESSES; 2466 } else { 2467 /* 2468 * Set the number of MC addresses that we are being 2469 * requested to use 2470 */ 2471 mc_addr_count = Adapter->mcast_count; 2472 } 2473 /* 2474 * The Wiseman 2.0 silicon has an errata by which the receiver will 2475 * hang while writing to the receive address registers if the receiver 2476 * is not in reset before writing to the registers. Updating the RAR 2477 * is done during the setting up of the multicast table, hence the 2478 * receiver has to be put in reset before updating the multicast table 2479 * and then taken out of reset at the end 2480 */ 2481 /* 2482 * if WMI was enabled then dis able it before issueing the global 2483 * reset to the hardware. 2484 */ 2485 /* 2486 * Only required for WISEMAN_2_0 2487 */ 2488 if ((hw->mac.type == e1000_82542) && 2489 (hw->revision_id == E1000_REVISION_2)) { 2490 e1000_pci_clear_mwi(hw); 2491 /* 2492 * The e1000g must be in reset before changing any RA 2493 * registers. Reset receive unit. The chip will remain in 2494 * the reset state until software explicitly restarts it. 2495 */ 2496 E1000_WRITE_REG(hw, E1000_RCTL, E1000_RCTL_RST); 2497 /* Allow receiver time to go in to reset */ 2498 msec_delay(5); 2499 } 2500 2501 e1000_update_mc_addr_list(hw, mc_addr_list, mc_addr_count, 2502 Adapter->unicst_total, hw->mac.rar_entry_count); 2503 2504 /* 2505 * Only for Wiseman_2_0 2506 * If MWI was enabled then re-enable it after issueing (as we 2507 * disabled it up there) the receive reset command. 2508 * Wainwright does not have a receive reset command and only thing 2509 * close to it is global reset which will require tx setup also 2510 */ 2511 if ((hw->mac.type == e1000_82542) && 2512 (hw->revision_id == E1000_REVISION_2)) { 2513 /* 2514 * if WMI was enabled then reenable it after issueing the 2515 * global or receive reset to the hardware. 2516 */ 2517 2518 /* 2519 * Take receiver out of reset 2520 * clear E1000_RCTL_RST bit (and all others) 2521 */ 2522 E1000_WRITE_REG(hw, E1000_RCTL, 0); 2523 msec_delay(5); 2524 if (hw->bus.pci_cmd_word & CMD_MEM_WRT_INVALIDATE) 2525 e1000_pci_set_mwi(hw); 2526 } 2527 2528 /* 2529 * Restore original value 2530 */ 2531 E1000_WRITE_REG(hw, E1000_RCTL, rctl); 2532 } 2533 2534 int 2535 e1000g_m_multicst(void *arg, boolean_t add, const uint8_t *addr) 2536 { 2537 struct e1000g *Adapter = (struct e1000g *)arg; 2538 2539 return ((add) ? multicst_add(Adapter, addr) 2540 : multicst_remove(Adapter, addr)); 2541 } 2542 2543 int 2544 e1000g_m_promisc(void *arg, boolean_t on) 2545 { 2546 struct e1000g *Adapter = (struct e1000g *)arg; 2547 uint32_t rctl; 2548 2549 rw_enter(&Adapter->chip_lock, RW_WRITER); 2550 2551 rctl = E1000_READ_REG(&Adapter->shared, E1000_RCTL); 2552 2553 if (on) 2554 rctl |= 2555 (E1000_RCTL_UPE | E1000_RCTL_MPE | E1000_RCTL_BAM); 2556 else 2557 rctl &= (~(E1000_RCTL_UPE | E1000_RCTL_MPE)); 2558 2559 E1000_WRITE_REG(&Adapter->shared, E1000_RCTL, rctl); 2560 2561 Adapter->e1000g_promisc = on; 2562 2563 rw_exit(&Adapter->chip_lock); 2564 2565 if (e1000g_check_acc_handle(Adapter->osdep.reg_handle) != DDI_FM_OK) { 2566 ddi_fm_service_impact(Adapter->dip, DDI_SERVICE_DEGRADED); 2567 return (EIO); 2568 } 2569 2570 return (0); 2571 } 2572 2573 static boolean_t 2574 e1000g_m_getcapab(void *arg, mac_capab_t cap, void *cap_data) 2575 { 2576 struct e1000g *Adapter = (struct e1000g *)arg; 2577 2578 switch (cap) { 2579 case MAC_CAPAB_HCKSUM: { 2580 uint32_t *txflags = cap_data; 2581 2582 if (Adapter->tx_hcksum_enable) 2583 *txflags = HCKSUM_IPHDRCKSUM | 2584 HCKSUM_INET_PARTIAL; 2585 else 2586 return (B_FALSE); 2587 break; 2588 } 2589 case MAC_CAPAB_POLL: 2590 /* 2591 * There's nothing for us to fill in, simply returning 2592 * B_TRUE stating that we support polling is sufficient. 2593 */ 2594 break; 2595 2596 case MAC_CAPAB_MULTIADDRESS: { 2597 multiaddress_capab_t *mmacp = cap_data; 2598 2599 /* 2600 * The number of MAC addresses made available by 2601 * this capability is one less than the total as 2602 * the primary address in slot 0 is counted in 2603 * the total. 2604 */ 2605 mmacp->maddr_naddr = Adapter->unicst_total - 1; 2606 mmacp->maddr_naddrfree = Adapter->unicst_avail; 2607 /* No multiple factory addresses, set mma_flag to 0 */ 2608 mmacp->maddr_flag = 0; 2609 mmacp->maddr_handle = Adapter; 2610 mmacp->maddr_add = e1000g_m_unicst_add; 2611 mmacp->maddr_remove = e1000g_m_unicst_remove; 2612 mmacp->maddr_modify = e1000g_m_unicst_modify; 2613 mmacp->maddr_get = e1000g_m_unicst_get; 2614 mmacp->maddr_reserve = NULL; 2615 break; 2616 } 2617 2618 case MAC_CAPAB_LSO: { 2619 mac_capab_lso_t *cap_lso = cap_data; 2620 2621 if (Adapter->lso_enable) { 2622 cap_lso->lso_flags = LSO_TX_BASIC_TCP_IPV4; 2623 cap_lso->lso_basic_tcp_ipv4.lso_max = 2624 E1000_LSO_MAXLEN; 2625 } else 2626 return (B_FALSE); 2627 break; 2628 } 2629 2630 default: 2631 return (B_FALSE); 2632 } 2633 return (B_TRUE); 2634 } 2635 2636 static boolean_t 2637 e1000g_param_locked(mac_prop_id_t pr_num) 2638 { 2639 /* 2640 * All en_* parameters are locked (read-only) while 2641 * the device is in any sort of loopback mode ... 2642 */ 2643 switch (pr_num) { 2644 case MAC_PROP_EN_1000FDX_CAP: 2645 case MAC_PROP_EN_1000HDX_CAP: 2646 case MAC_PROP_EN_100FDX_CAP: 2647 case MAC_PROP_EN_100HDX_CAP: 2648 case MAC_PROP_EN_10FDX_CAP: 2649 case MAC_PROP_EN_10HDX_CAP: 2650 case MAC_PROP_AUTONEG: 2651 case MAC_PROP_FLOWCTRL: 2652 return (B_TRUE); 2653 } 2654 return (B_FALSE); 2655 } 2656 2657 /* 2658 * callback function for set/get of properties 2659 */ 2660 static int 2661 e1000g_m_setprop(void *arg, const char *pr_name, mac_prop_id_t pr_num, 2662 uint_t pr_valsize, const void *pr_val) 2663 { 2664 struct e1000g *Adapter = arg; 2665 struct e1000_mac_info *mac = &Adapter->shared.mac; 2666 struct e1000_phy_info *phy = &Adapter->shared.phy; 2667 struct e1000_fc_info *fc = &Adapter->shared.fc; 2668 int err = 0; 2669 link_flowctrl_t flowctrl; 2670 uint32_t cur_mtu, new_mtu; 2671 uint64_t tmp = 0; 2672 2673 rw_enter(&Adapter->chip_lock, RW_WRITER); 2674 if (Adapter->loopback_mode != E1000G_LB_NONE && 2675 e1000g_param_locked(pr_num)) { 2676 /* 2677 * All en_* parameters are locked (read-only) 2678 * while the device is in any sort of loopback mode. 2679 */ 2680 rw_exit(&Adapter->chip_lock); 2681 return (EBUSY); 2682 } 2683 2684 switch (pr_num) { 2685 case MAC_PROP_EN_1000FDX_CAP: 2686 Adapter->param_en_1000fdx = *(uint8_t *)pr_val; 2687 Adapter->param_adv_1000fdx = *(uint8_t *)pr_val; 2688 goto reset; 2689 case MAC_PROP_EN_100FDX_CAP: 2690 Adapter->param_en_100fdx = *(uint8_t *)pr_val; 2691 Adapter->param_adv_100fdx = *(uint8_t *)pr_val; 2692 goto reset; 2693 case MAC_PROP_EN_100HDX_CAP: 2694 Adapter->param_en_100hdx = *(uint8_t *)pr_val; 2695 Adapter->param_adv_100hdx = *(uint8_t *)pr_val; 2696 goto reset; 2697 case MAC_PROP_EN_10FDX_CAP: 2698 Adapter->param_en_10fdx = *(uint8_t *)pr_val; 2699 Adapter->param_adv_10fdx = *(uint8_t *)pr_val; 2700 goto reset; 2701 case MAC_PROP_EN_10HDX_CAP: 2702 Adapter->param_en_10hdx = *(uint8_t *)pr_val; 2703 Adapter->param_adv_10hdx = *(uint8_t *)pr_val; 2704 goto reset; 2705 case MAC_PROP_AUTONEG: 2706 Adapter->param_adv_autoneg = *(uint8_t *)pr_val; 2707 goto reset; 2708 case MAC_PROP_FLOWCTRL: 2709 fc->send_xon = B_TRUE; 2710 bcopy(pr_val, &flowctrl, sizeof (flowctrl)); 2711 2712 switch (flowctrl) { 2713 default: 2714 err = EINVAL; 2715 break; 2716 case LINK_FLOWCTRL_NONE: 2717 fc->type = e1000_fc_none; 2718 break; 2719 case LINK_FLOWCTRL_RX: 2720 fc->type = e1000_fc_rx_pause; 2721 break; 2722 case LINK_FLOWCTRL_TX: 2723 fc->type = e1000_fc_tx_pause; 2724 break; 2725 case LINK_FLOWCTRL_BI: 2726 fc->type = e1000_fc_full; 2727 break; 2728 } 2729 reset: 2730 if (err == 0) { 2731 if (e1000g_reset_link(Adapter) != DDI_SUCCESS) 2732 err = EINVAL; 2733 } 2734 break; 2735 case MAC_PROP_ADV_1000FDX_CAP: 2736 case MAC_PROP_ADV_1000HDX_CAP: 2737 case MAC_PROP_ADV_100FDX_CAP: 2738 case MAC_PROP_ADV_100HDX_CAP: 2739 case MAC_PROP_ADV_10FDX_CAP: 2740 case MAC_PROP_ADV_10HDX_CAP: 2741 case MAC_PROP_EN_1000HDX_CAP: 2742 case MAC_PROP_STATUS: 2743 case MAC_PROP_SPEED: 2744 case MAC_PROP_DUPLEX: 2745 err = ENOTSUP; /* read-only prop. Can't set this. */ 2746 break; 2747 case MAC_PROP_MTU: 2748 cur_mtu = Adapter->default_mtu; 2749 bcopy(pr_val, &new_mtu, sizeof (new_mtu)); 2750 if (new_mtu == cur_mtu) { 2751 err = 0; 2752 break; 2753 } 2754 2755 tmp = new_mtu + sizeof (struct ether_vlan_header) + 2756 ETHERFCSL; 2757 if ((tmp < DEFAULT_FRAME_SIZE) || 2758 (tmp > MAXIMUM_FRAME_SIZE)) { 2759 err = EINVAL; 2760 break; 2761 } 2762 2763 /* ich8 does not support jumbo frames */ 2764 if ((mac->type == e1000_ich8lan) && 2765 (tmp > DEFAULT_FRAME_SIZE)) { 2766 err = EINVAL; 2767 break; 2768 } 2769 /* ich9 does not do jumbo frames on one phy type */ 2770 if ((mac->type == e1000_ich9lan) && 2771 (phy->type == e1000_phy_ife) && 2772 (tmp > DEFAULT_FRAME_SIZE)) { 2773 err = EINVAL; 2774 break; 2775 } 2776 if (Adapter->chip_state != E1000G_STOP) { 2777 err = EBUSY; 2778 break; 2779 } 2780 2781 err = mac_maxsdu_update(Adapter->mh, new_mtu); 2782 if (err == 0) { 2783 Adapter->max_frame_size = (uint32_t)tmp; 2784 Adapter->default_mtu = new_mtu; 2785 e1000g_set_bufsize(Adapter); 2786 } 2787 break; 2788 case MAC_PROP_PRIVATE: 2789 err = e1000g_set_priv_prop(Adapter, pr_name, 2790 pr_valsize, pr_val); 2791 break; 2792 default: 2793 err = ENOTSUP; 2794 break; 2795 } 2796 rw_exit(&Adapter->chip_lock); 2797 return (err); 2798 } 2799 2800 static int 2801 e1000g_m_getprop(void *arg, const char *pr_name, mac_prop_id_t pr_num, 2802 uint_t pr_flags, uint_t pr_valsize, void *pr_val, uint_t *perm) 2803 { 2804 struct e1000g *Adapter = arg; 2805 struct e1000_fc_info *fc = &Adapter->shared.fc; 2806 int err = 0; 2807 link_flowctrl_t flowctrl; 2808 uint64_t tmp = 0; 2809 2810 if (pr_valsize == 0) 2811 return (EINVAL); 2812 2813 *perm = MAC_PROP_PERM_RW; 2814 2815 bzero(pr_val, pr_valsize); 2816 if ((pr_flags & MAC_PROP_DEFAULT) && (pr_num != MAC_PROP_PRIVATE)) { 2817 return (e1000g_get_def_val(Adapter, pr_num, 2818 pr_valsize, pr_val)); 2819 } 2820 2821 switch (pr_num) { 2822 case MAC_PROP_DUPLEX: 2823 *perm = MAC_PROP_PERM_READ; 2824 if (pr_valsize >= sizeof (link_duplex_t)) { 2825 bcopy(&Adapter->link_duplex, pr_val, 2826 sizeof (link_duplex_t)); 2827 } else 2828 err = EINVAL; 2829 break; 2830 case MAC_PROP_SPEED: 2831 *perm = MAC_PROP_PERM_READ; 2832 if (pr_valsize >= sizeof (uint64_t)) { 2833 tmp = Adapter->link_speed * 1000000ull; 2834 bcopy(&tmp, pr_val, sizeof (tmp)); 2835 } else 2836 err = EINVAL; 2837 break; 2838 case MAC_PROP_AUTONEG: 2839 *(uint8_t *)pr_val = Adapter->param_adv_autoneg; 2840 break; 2841 case MAC_PROP_FLOWCTRL: 2842 if (pr_valsize >= sizeof (link_flowctrl_t)) { 2843 switch (fc->type) { 2844 case e1000_fc_none: 2845 flowctrl = LINK_FLOWCTRL_NONE; 2846 break; 2847 case e1000_fc_rx_pause: 2848 flowctrl = LINK_FLOWCTRL_RX; 2849 break; 2850 case e1000_fc_tx_pause: 2851 flowctrl = LINK_FLOWCTRL_TX; 2852 break; 2853 case e1000_fc_full: 2854 flowctrl = LINK_FLOWCTRL_BI; 2855 break; 2856 } 2857 bcopy(&flowctrl, pr_val, sizeof (flowctrl)); 2858 } else 2859 err = EINVAL; 2860 break; 2861 case MAC_PROP_ADV_1000FDX_CAP: 2862 *perm = MAC_PROP_PERM_READ; 2863 *(uint8_t *)pr_val = Adapter->param_adv_1000fdx; 2864 break; 2865 case MAC_PROP_EN_1000FDX_CAP: 2866 *(uint8_t *)pr_val = Adapter->param_en_1000fdx; 2867 break; 2868 case MAC_PROP_ADV_1000HDX_CAP: 2869 *perm = MAC_PROP_PERM_READ; 2870 *(uint8_t *)pr_val = Adapter->param_adv_1000hdx; 2871 break; 2872 case MAC_PROP_EN_1000HDX_CAP: 2873 *perm = MAC_PROP_PERM_READ; 2874 *(uint8_t *)pr_val = Adapter->param_en_1000hdx; 2875 break; 2876 case MAC_PROP_ADV_100FDX_CAP: 2877 *perm = MAC_PROP_PERM_READ; 2878 *(uint8_t *)pr_val = Adapter->param_adv_100fdx; 2879 break; 2880 case MAC_PROP_EN_100FDX_CAP: 2881 *(uint8_t *)pr_val = Adapter->param_en_100fdx; 2882 break; 2883 case MAC_PROP_ADV_100HDX_CAP: 2884 *perm = MAC_PROP_PERM_READ; 2885 *(uint8_t *)pr_val = Adapter->param_adv_100hdx; 2886 break; 2887 case MAC_PROP_EN_100HDX_CAP: 2888 *(uint8_t *)pr_val = Adapter->param_en_100hdx; 2889 break; 2890 case MAC_PROP_ADV_10FDX_CAP: 2891 *perm = MAC_PROP_PERM_READ; 2892 *(uint8_t *)pr_val = Adapter->param_adv_10fdx; 2893 break; 2894 case MAC_PROP_EN_10FDX_CAP: 2895 *(uint8_t *)pr_val = Adapter->param_en_10fdx; 2896 break; 2897 case MAC_PROP_ADV_10HDX_CAP: 2898 *perm = MAC_PROP_PERM_READ; 2899 *(uint8_t *)pr_val = Adapter->param_adv_10hdx; 2900 break; 2901 case MAC_PROP_EN_10HDX_CAP: 2902 *(uint8_t *)pr_val = Adapter->param_en_10hdx; 2903 break; 2904 case MAC_PROP_ADV_100T4_CAP: 2905 case MAC_PROP_EN_100T4_CAP: 2906 *perm = MAC_PROP_PERM_READ; 2907 *(uint8_t *)pr_val = Adapter->param_adv_100t4; 2908 break; 2909 case MAC_PROP_PRIVATE: 2910 err = e1000g_get_priv_prop(Adapter, pr_name, 2911 pr_flags, pr_valsize, pr_val, perm); 2912 break; 2913 default: 2914 err = ENOTSUP; 2915 break; 2916 } 2917 return (err); 2918 } 2919 2920 /* ARGSUSED2 */ 2921 static int 2922 e1000g_set_priv_prop(struct e1000g *Adapter, const char *pr_name, 2923 uint_t pr_valsize, const void *pr_val) 2924 { 2925 int err = 0; 2926 long result; 2927 struct e1000_hw *hw = &Adapter->shared; 2928 2929 if (strcmp(pr_name, "_tx_bcopy_threshold") == 0) { 2930 if (pr_val == NULL) { 2931 err = EINVAL; 2932 return (err); 2933 } 2934 (void) ddi_strtol(pr_val, (char **)NULL, 0, &result); 2935 if (result < MIN_TX_BCOPY_THRESHOLD || 2936 result > MAX_TX_BCOPY_THRESHOLD) 2937 err = EINVAL; 2938 else { 2939 Adapter->tx_bcopy_thresh = (uint32_t)result; 2940 } 2941 return (err); 2942 } 2943 if (strcmp(pr_name, "_tx_interrupt_enable") == 0) { 2944 if (pr_val == NULL) { 2945 err = EINVAL; 2946 return (err); 2947 } 2948 (void) ddi_strtol(pr_val, (char **)NULL, 0, &result); 2949 if (result < 0 || result > 1) 2950 err = EINVAL; 2951 else { 2952 Adapter->tx_intr_enable = (result == 1) ? 2953 B_TRUE: B_FALSE; 2954 if (Adapter->tx_intr_enable) 2955 e1000g_mask_tx_interrupt(Adapter); 2956 else 2957 e1000g_clear_tx_interrupt(Adapter); 2958 if (e1000g_check_acc_handle( 2959 Adapter->osdep.reg_handle) != DDI_FM_OK) 2960 ddi_fm_service_impact(Adapter->dip, 2961 DDI_SERVICE_DEGRADED); 2962 } 2963 return (err); 2964 } 2965 if (strcmp(pr_name, "_tx_intr_delay") == 0) { 2966 if (pr_val == NULL) { 2967 err = EINVAL; 2968 return (err); 2969 } 2970 (void) ddi_strtol(pr_val, (char **)NULL, 0, &result); 2971 if (result < MIN_TX_INTR_DELAY || 2972 result > MAX_TX_INTR_DELAY) 2973 err = EINVAL; 2974 else { 2975 Adapter->tx_intr_delay = (uint32_t)result; 2976 E1000_WRITE_REG(hw, E1000_TIDV, Adapter->tx_intr_delay); 2977 if (e1000g_check_acc_handle( 2978 Adapter->osdep.reg_handle) != DDI_FM_OK) 2979 ddi_fm_service_impact(Adapter->dip, 2980 DDI_SERVICE_DEGRADED); 2981 } 2982 return (err); 2983 } 2984 if (strcmp(pr_name, "_tx_intr_abs_delay") == 0) { 2985 if (pr_val == NULL) { 2986 err = EINVAL; 2987 return (err); 2988 } 2989 (void) ddi_strtol(pr_val, (char **)NULL, 0, &result); 2990 if (result < MIN_TX_INTR_ABS_DELAY || 2991 result > MAX_TX_INTR_ABS_DELAY) 2992 err = EINVAL; 2993 else { 2994 Adapter->tx_intr_abs_delay = (uint32_t)result; 2995 E1000_WRITE_REG(hw, E1000_TADV, 2996 Adapter->tx_intr_abs_delay); 2997 if (e1000g_check_acc_handle( 2998 Adapter->osdep.reg_handle) != DDI_FM_OK) 2999 ddi_fm_service_impact(Adapter->dip, 3000 DDI_SERVICE_DEGRADED); 3001 } 3002 return (err); 3003 } 3004 if (strcmp(pr_name, "_rx_bcopy_threshold") == 0) { 3005 if (pr_val == NULL) { 3006 err = EINVAL; 3007 return (err); 3008 } 3009 (void) ddi_strtol(pr_val, (char **)NULL, 0, &result); 3010 if (result < MIN_RX_BCOPY_THRESHOLD || 3011 result > MAX_RX_BCOPY_THRESHOLD) 3012 err = EINVAL; 3013 else 3014 Adapter->rx_bcopy_thresh = (uint32_t)result; 3015 return (err); 3016 } 3017 if (strcmp(pr_name, "_max_num_rcv_packets") == 0) { 3018 if (pr_val == NULL) { 3019 err = EINVAL; 3020 return (err); 3021 } 3022 (void) ddi_strtol(pr_val, (char **)NULL, 0, &result); 3023 if (result < MIN_RX_LIMIT_ON_INTR || 3024 result > MAX_RX_LIMIT_ON_INTR) 3025 err = EINVAL; 3026 else 3027 Adapter->rx_limit_onintr = (uint32_t)result; 3028 return (err); 3029 } 3030 if (strcmp(pr_name, "_rx_intr_delay") == 0) { 3031 if (pr_val == NULL) { 3032 err = EINVAL; 3033 return (err); 3034 } 3035 (void) ddi_strtol(pr_val, (char **)NULL, 0, &result); 3036 if (result < MIN_RX_INTR_DELAY || 3037 result > MAX_RX_INTR_DELAY) 3038 err = EINVAL; 3039 else { 3040 Adapter->rx_intr_delay = (uint32_t)result; 3041 E1000_WRITE_REG(hw, E1000_RDTR, Adapter->rx_intr_delay); 3042 if (e1000g_check_acc_handle( 3043 Adapter->osdep.reg_handle) != DDI_FM_OK) 3044 ddi_fm_service_impact(Adapter->dip, 3045 DDI_SERVICE_DEGRADED); 3046 } 3047 return (err); 3048 } 3049 if (strcmp(pr_name, "_rx_intr_abs_delay") == 0) { 3050 if (pr_val == NULL) { 3051 err = EINVAL; 3052 return (err); 3053 } 3054 (void) ddi_strtol(pr_val, (char **)NULL, 0, &result); 3055 if (result < MIN_RX_INTR_ABS_DELAY || 3056 result > MAX_RX_INTR_ABS_DELAY) 3057 err = EINVAL; 3058 else { 3059 Adapter->rx_intr_abs_delay = (uint32_t)result; 3060 E1000_WRITE_REG(hw, E1000_RADV, 3061 Adapter->rx_intr_abs_delay); 3062 if (e1000g_check_acc_handle( 3063 Adapter->osdep.reg_handle) != DDI_FM_OK) 3064 ddi_fm_service_impact(Adapter->dip, 3065 DDI_SERVICE_DEGRADED); 3066 } 3067 return (err); 3068 } 3069 if (strcmp(pr_name, "_intr_throttling_rate") == 0) { 3070 if (pr_val == NULL) { 3071 err = EINVAL; 3072 return (err); 3073 } 3074 (void) ddi_strtol(pr_val, (char **)NULL, 0, &result); 3075 if (result < MIN_INTR_THROTTLING || 3076 result > MAX_INTR_THROTTLING) 3077 err = EINVAL; 3078 else { 3079 if (hw->mac.type >= e1000_82540) { 3080 Adapter->intr_throttling_rate = 3081 (uint32_t)result; 3082 E1000_WRITE_REG(hw, E1000_ITR, 3083 Adapter->intr_throttling_rate); 3084 if (e1000g_check_acc_handle( 3085 Adapter->osdep.reg_handle) != DDI_FM_OK) 3086 ddi_fm_service_impact(Adapter->dip, 3087 DDI_SERVICE_DEGRADED); 3088 } else 3089 err = EINVAL; 3090 } 3091 return (err); 3092 } 3093 if (strcmp(pr_name, "_intr_adaptive") == 0) { 3094 if (pr_val == NULL) { 3095 err = EINVAL; 3096 return (err); 3097 } 3098 (void) ddi_strtol(pr_val, (char **)NULL, 0, &result); 3099 if (result < 0 || result > 1) 3100 err = EINVAL; 3101 else { 3102 if (hw->mac.type >= e1000_82540) { 3103 Adapter->intr_adaptive = (result == 1) ? 3104 B_TRUE : B_FALSE; 3105 } else { 3106 err = EINVAL; 3107 } 3108 } 3109 return (err); 3110 } 3111 if (strcmp(pr_name, "_tx_recycle_thresh") == 0) { 3112 if (pr_val == NULL) { 3113 err = EINVAL; 3114 return (err); 3115 } 3116 (void) ddi_strtol(pr_val, (char **)NULL, 0, &result); 3117 if (result < MIN_TX_RECYCLE_THRESHOLD || 3118 result > MAX_TX_RECYCLE_THRESHOLD) 3119 err = EINVAL; 3120 else 3121 Adapter->tx_recycle_thresh = (uint32_t)result; 3122 return (err); 3123 } 3124 if (strcmp(pr_name, "_tx_recycle_num") == 0) { 3125 if (pr_val == NULL) { 3126 err = EINVAL; 3127 return (err); 3128 } 3129 (void) ddi_strtol(pr_val, (char **)NULL, 0, &result); 3130 if (result < MIN_TX_RECYCLE_NUM || 3131 result > MAX_TX_RECYCLE_NUM) 3132 err = EINVAL; 3133 else 3134 Adapter->tx_recycle_num = (uint32_t)result; 3135 return (err); 3136 } 3137 return (ENOTSUP); 3138 } 3139 3140 static int 3141 e1000g_get_priv_prop(struct e1000g *Adapter, const char *pr_name, 3142 uint_t pr_flags, uint_t pr_valsize, void *pr_val, uint_t *perm) 3143 { 3144 int err = ENOTSUP; 3145 boolean_t is_default = (pr_flags & MAC_PROP_DEFAULT); 3146 int value; 3147 3148 if (strcmp(pr_name, "_adv_pause_cap") == 0) { 3149 *perm = MAC_PROP_PERM_READ; 3150 if (is_default) 3151 goto done; 3152 value = Adapter->param_adv_pause; 3153 err = 0; 3154 goto done; 3155 } 3156 if (strcmp(pr_name, "_adv_asym_pause_cap") == 0) { 3157 *perm = MAC_PROP_PERM_READ; 3158 if (is_default) 3159 goto done; 3160 value = Adapter->param_adv_asym_pause; 3161 err = 0; 3162 goto done; 3163 } 3164 if (strcmp(pr_name, "_tx_bcopy_threshold") == 0) { 3165 value = (is_default ? DEFAULT_TX_BCOPY_THRESHOLD : 3166 Adapter->tx_bcopy_thresh); 3167 err = 0; 3168 goto done; 3169 } 3170 if (strcmp(pr_name, "_tx_interrupt_enable") == 0) { 3171 value = (is_default ? DEFAULT_TX_INTR_ENABLE : 3172 Adapter->tx_intr_enable); 3173 err = 0; 3174 goto done; 3175 } 3176 if (strcmp(pr_name, "_tx_intr_delay") == 0) { 3177 value = (is_default ? DEFAULT_TX_INTR_DELAY : 3178 Adapter->tx_intr_delay); 3179 err = 0; 3180 goto done; 3181 } 3182 if (strcmp(pr_name, "_tx_intr_abs_delay") == 0) { 3183 value = (is_default ? DEFAULT_TX_INTR_ABS_DELAY : 3184 Adapter->tx_intr_abs_delay); 3185 err = 0; 3186 goto done; 3187 } 3188 if (strcmp(pr_name, "_rx_bcopy_threshold") == 0) { 3189 value = (is_default ? DEFAULT_RX_BCOPY_THRESHOLD : 3190 Adapter->rx_bcopy_thresh); 3191 err = 0; 3192 goto done; 3193 } 3194 if (strcmp(pr_name, "_max_num_rcv_packets") == 0) { 3195 value = (is_default ? DEFAULT_RX_LIMIT_ON_INTR : 3196 Adapter->rx_limit_onintr); 3197 err = 0; 3198 goto done; 3199 } 3200 if (strcmp(pr_name, "_rx_intr_delay") == 0) { 3201 value = (is_default ? DEFAULT_RX_INTR_DELAY : 3202 Adapter->rx_intr_delay); 3203 err = 0; 3204 goto done; 3205 } 3206 if (strcmp(pr_name, "_rx_intr_abs_delay") == 0) { 3207 value = (is_default ? DEFAULT_RX_INTR_ABS_DELAY : 3208 Adapter->rx_intr_abs_delay); 3209 err = 0; 3210 goto done; 3211 } 3212 if (strcmp(pr_name, "_intr_throttling_rate") == 0) { 3213 value = (is_default ? DEFAULT_INTR_THROTTLING : 3214 Adapter->intr_throttling_rate); 3215 err = 0; 3216 goto done; 3217 } 3218 if (strcmp(pr_name, "_intr_adaptive") == 0) { 3219 value = (is_default ? 1 : Adapter->intr_adaptive); 3220 err = 0; 3221 goto done; 3222 } 3223 if (strcmp(pr_name, "_tx_recycle_thresh") == 0) { 3224 value = (is_default ? DEFAULT_TX_RECYCLE_THRESHOLD : 3225 Adapter->tx_recycle_thresh); 3226 err = 0; 3227 goto done; 3228 } 3229 if (strcmp(pr_name, "_tx_recycle_num") == 0) { 3230 value = (is_default ? DEFAULT_TX_RECYCLE_NUM : 3231 Adapter->tx_recycle_num); 3232 err = 0; 3233 goto done; 3234 } 3235 done: 3236 if (err == 0) { 3237 (void) snprintf(pr_val, pr_valsize, "%d", value); 3238 } 3239 return (err); 3240 } 3241 3242 /* 3243 * e1000g_get_conf - get configurations set in e1000g.conf 3244 * This routine gets user-configured values out of the configuration 3245 * file e1000g.conf. 3246 * 3247 * For each configurable value, there is a minimum, a maximum, and a 3248 * default. 3249 * If user does not configure a value, use the default. 3250 * If user configures below the minimum, use the minumum. 3251 * If user configures above the maximum, use the maxumum. 3252 */ 3253 static void 3254 e1000g_get_conf(struct e1000g *Adapter) 3255 { 3256 struct e1000_hw *hw = &Adapter->shared; 3257 boolean_t tbi_compatibility = B_FALSE; 3258 3259 /* 3260 * get each configurable property from e1000g.conf 3261 */ 3262 3263 /* 3264 * NumTxDescriptors 3265 */ 3266 Adapter->tx_desc_num = 3267 e1000g_get_prop(Adapter, "NumTxDescriptors", 3268 MIN_NUM_TX_DESCRIPTOR, MAX_NUM_TX_DESCRIPTOR, 3269 DEFAULT_NUM_TX_DESCRIPTOR); 3270 3271 /* 3272 * NumRxDescriptors 3273 */ 3274 Adapter->rx_desc_num = 3275 e1000g_get_prop(Adapter, "NumRxDescriptors", 3276 MIN_NUM_RX_DESCRIPTOR, MAX_NUM_RX_DESCRIPTOR, 3277 DEFAULT_NUM_RX_DESCRIPTOR); 3278 3279 /* 3280 * NumRxFreeList 3281 */ 3282 Adapter->rx_freelist_num = 3283 e1000g_get_prop(Adapter, "NumRxFreeList", 3284 MIN_NUM_RX_FREELIST, MAX_NUM_RX_FREELIST, 3285 DEFAULT_NUM_RX_FREELIST); 3286 3287 /* 3288 * NumTxPacketList 3289 */ 3290 Adapter->tx_freelist_num = 3291 e1000g_get_prop(Adapter, "NumTxPacketList", 3292 MIN_NUM_TX_FREELIST, MAX_NUM_TX_FREELIST, 3293 DEFAULT_NUM_TX_FREELIST); 3294 3295 /* 3296 * FlowControl 3297 */ 3298 hw->fc.send_xon = B_TRUE; 3299 hw->fc.type = 3300 e1000g_get_prop(Adapter, "FlowControl", 3301 e1000_fc_none, 4, DEFAULT_FLOW_CONTROL); 3302 /* 4 is the setting that says "let the eeprom decide" */ 3303 if (hw->fc.type == 4) 3304 hw->fc.type = e1000_fc_default; 3305 3306 /* 3307 * Max Num Receive Packets on Interrupt 3308 */ 3309 Adapter->rx_limit_onintr = 3310 e1000g_get_prop(Adapter, "MaxNumReceivePackets", 3311 MIN_RX_LIMIT_ON_INTR, MAX_RX_LIMIT_ON_INTR, 3312 DEFAULT_RX_LIMIT_ON_INTR); 3313 3314 /* 3315 * PHY master slave setting 3316 */ 3317 hw->phy.ms_type = 3318 e1000g_get_prop(Adapter, "SetMasterSlave", 3319 e1000_ms_hw_default, e1000_ms_auto, 3320 e1000_ms_hw_default); 3321 3322 /* 3323 * Parameter which controls TBI mode workaround, which is only 3324 * needed on certain switches such as Cisco 6500/Foundry 3325 */ 3326 tbi_compatibility = 3327 e1000g_get_prop(Adapter, "TbiCompatibilityEnable", 3328 0, 1, DEFAULT_TBI_COMPAT_ENABLE); 3329 e1000_set_tbi_compatibility_82543(hw, tbi_compatibility); 3330 3331 /* 3332 * MSI Enable 3333 */ 3334 Adapter->msi_enable = 3335 e1000g_get_prop(Adapter, "MSIEnable", 3336 0, 1, DEFAULT_MSI_ENABLE); 3337 3338 /* 3339 * Interrupt Throttling Rate 3340 */ 3341 Adapter->intr_throttling_rate = 3342 e1000g_get_prop(Adapter, "intr_throttling_rate", 3343 MIN_INTR_THROTTLING, MAX_INTR_THROTTLING, 3344 DEFAULT_INTR_THROTTLING); 3345 3346 /* 3347 * Adaptive Interrupt Blanking Enable/Disable 3348 * It is enabled by default 3349 */ 3350 Adapter->intr_adaptive = 3351 (e1000g_get_prop(Adapter, "intr_adaptive", 0, 1, 1) == 1) ? 3352 B_TRUE : B_FALSE; 3353 3354 /* 3355 * Tx recycle threshold 3356 */ 3357 Adapter->tx_recycle_thresh = 3358 e1000g_get_prop(Adapter, "tx_recycle_thresh", 3359 MIN_TX_RECYCLE_THRESHOLD, MAX_TX_RECYCLE_THRESHOLD, 3360 DEFAULT_TX_RECYCLE_THRESHOLD); 3361 3362 /* 3363 * Tx recycle descriptor number 3364 */ 3365 Adapter->tx_recycle_num = 3366 e1000g_get_prop(Adapter, "tx_recycle_num", 3367 MIN_TX_RECYCLE_NUM, MAX_TX_RECYCLE_NUM, 3368 DEFAULT_TX_RECYCLE_NUM); 3369 3370 /* 3371 * Hardware checksum enable/disable parameter 3372 */ 3373 Adapter->tx_hcksum_enable = 3374 e1000g_get_prop(Adapter, "tx_hcksum_enable", 3375 0, 1, DEFAULT_TX_HCKSUM_ENABLE); 3376 /* 3377 * Checksum on/off selection via global parameters. 3378 * 3379 * If the chip is flagged as not capable of (correctly) 3380 * handling checksumming, we don't enable it on either 3381 * Rx or Tx side. Otherwise, we take this chip's settings 3382 * from the patchable global defaults. 3383 * 3384 * We advertise our capabilities only if TX offload is 3385 * enabled. On receive, the stack will accept checksummed 3386 * packets anyway, even if we haven't said we can deliver 3387 * them. 3388 */ 3389 switch (hw->mac.type) { 3390 case e1000_82540: 3391 case e1000_82544: 3392 case e1000_82545: 3393 case e1000_82545_rev_3: 3394 case e1000_82546: 3395 case e1000_82546_rev_3: 3396 case e1000_82571: 3397 case e1000_82572: 3398 case e1000_82573: 3399 case e1000_80003es2lan: 3400 break; 3401 /* 3402 * For the following Intel PRO/1000 chipsets, we have not 3403 * tested the hardware checksum offload capability, so we 3404 * disable the capability for them. 3405 * e1000_82542, 3406 * e1000_82543, 3407 * e1000_82541, 3408 * e1000_82541_rev_2, 3409 * e1000_82547, 3410 * e1000_82547_rev_2, 3411 */ 3412 default: 3413 Adapter->tx_hcksum_enable = B_FALSE; 3414 } 3415 3416 /* 3417 * Large Send Offloading(LSO) Enable/Disable 3418 * If the tx hardware checksum is not enabled, LSO should be 3419 * disabled. 3420 */ 3421 Adapter->lso_enable = 3422 e1000g_get_prop(Adapter, "lso_enable", 3423 0, 1, DEFAULT_LSO_ENABLE); 3424 3425 switch (hw->mac.type) { 3426 case e1000_82546: 3427 case e1000_82546_rev_3: 3428 if (Adapter->lso_enable) 3429 Adapter->lso_premature_issue = B_TRUE; 3430 /* FALLTHRU */ 3431 case e1000_82571: 3432 case e1000_82572: 3433 case e1000_82573: 3434 case e1000_80003es2lan: 3435 break; 3436 default: 3437 Adapter->lso_enable = B_FALSE; 3438 } 3439 3440 if (!Adapter->tx_hcksum_enable) { 3441 Adapter->lso_premature_issue = B_FALSE; 3442 Adapter->lso_enable = B_FALSE; 3443 } 3444 } 3445 3446 /* 3447 * e1000g_get_prop - routine to read properties 3448 * 3449 * Get a user-configure property value out of the configuration 3450 * file e1000g.conf. 3451 * 3452 * Caller provides name of the property, a default value, a minimum 3453 * value, and a maximum value. 3454 * 3455 * Return configured value of the property, with default, minimum and 3456 * maximum properly applied. 3457 */ 3458 static int 3459 e1000g_get_prop(struct e1000g *Adapter, /* point to per-adapter structure */ 3460 char *propname, /* name of the property */ 3461 int minval, /* minimum acceptable value */ 3462 int maxval, /* maximim acceptable value */ 3463 int defval) /* default value */ 3464 { 3465 int propval; /* value returned for requested property */ 3466 int *props; /* point to array of properties returned */ 3467 uint_t nprops; /* number of property value returned */ 3468 3469 /* 3470 * get the array of properties from the config file 3471 */ 3472 if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, Adapter->dip, 3473 DDI_PROP_DONTPASS, propname, &props, &nprops) == DDI_PROP_SUCCESS) { 3474 /* got some properties, test if we got enough */ 3475 if (Adapter->instance < nprops) { 3476 propval = props[Adapter->instance]; 3477 } else { 3478 /* not enough properties configured */ 3479 propval = defval; 3480 E1000G_DEBUGLOG_2(Adapter, E1000G_INFO_LEVEL, 3481 "Not Enough %s values found in e1000g.conf" 3482 " - set to %d\n", 3483 propname, propval); 3484 } 3485 3486 /* free memory allocated for properties */ 3487 ddi_prop_free(props); 3488 3489 } else { 3490 propval = defval; 3491 } 3492 3493 /* 3494 * enforce limits 3495 */ 3496 if (propval > maxval) { 3497 propval = maxval; 3498 E1000G_DEBUGLOG_2(Adapter, E1000G_INFO_LEVEL, 3499 "Too High %s value in e1000g.conf - set to %d\n", 3500 propname, propval); 3501 } 3502 3503 if (propval < minval) { 3504 propval = minval; 3505 E1000G_DEBUGLOG_2(Adapter, E1000G_INFO_LEVEL, 3506 "Too Low %s value in e1000g.conf - set to %d\n", 3507 propname, propval); 3508 } 3509 3510 return (propval); 3511 } 3512 3513 static boolean_t 3514 e1000g_link_check(struct e1000g *Adapter) 3515 { 3516 uint16_t speed, duplex, phydata; 3517 boolean_t link_changed = B_FALSE; 3518 struct e1000_hw *hw; 3519 uint32_t reg_tarc; 3520 3521 hw = &Adapter->shared; 3522 3523 if (e1000g_link_up(Adapter)) { 3524 /* 3525 * The Link is up, check whether it was marked as down earlier 3526 */ 3527 if (Adapter->link_state != LINK_STATE_UP) { 3528 (void) e1000_get_speed_and_duplex(hw, &speed, &duplex); 3529 Adapter->link_speed = speed; 3530 Adapter->link_duplex = duplex; 3531 Adapter->link_state = LINK_STATE_UP; 3532 link_changed = B_TRUE; 3533 3534 Adapter->tx_link_down_timeout = 0; 3535 3536 if ((hw->mac.type == e1000_82571) || 3537 (hw->mac.type == e1000_82572)) { 3538 reg_tarc = E1000_READ_REG(hw, E1000_TARC(0)); 3539 if (speed == SPEED_1000) 3540 reg_tarc |= (1 << 21); 3541 else 3542 reg_tarc &= ~(1 << 21); 3543 E1000_WRITE_REG(hw, E1000_TARC(0), reg_tarc); 3544 } 3545 } 3546 Adapter->smartspeed = 0; 3547 } else { 3548 if (Adapter->link_state != LINK_STATE_DOWN) { 3549 Adapter->link_speed = 0; 3550 Adapter->link_duplex = 0; 3551 Adapter->link_state = LINK_STATE_DOWN; 3552 link_changed = B_TRUE; 3553 3554 /* 3555 * SmartSpeed workaround for Tabor/TanaX, When the 3556 * driver loses link disable auto master/slave 3557 * resolution. 3558 */ 3559 if (hw->phy.type == e1000_phy_igp) { 3560 (void) e1000_read_phy_reg(hw, 3561 PHY_1000T_CTRL, &phydata); 3562 phydata |= CR_1000T_MS_ENABLE; 3563 (void) e1000_write_phy_reg(hw, 3564 PHY_1000T_CTRL, phydata); 3565 } 3566 } else { 3567 e1000g_smartspeed(Adapter); 3568 } 3569 3570 if (Adapter->chip_state == E1000G_START) { 3571 if (Adapter->tx_link_down_timeout < 3572 MAX_TX_LINK_DOWN_TIMEOUT) { 3573 Adapter->tx_link_down_timeout++; 3574 } else if (Adapter->tx_link_down_timeout == 3575 MAX_TX_LINK_DOWN_TIMEOUT) { 3576 e1000g_tx_clean(Adapter); 3577 Adapter->tx_link_down_timeout++; 3578 } 3579 } 3580 } 3581 3582 if (e1000g_check_acc_handle(Adapter->osdep.reg_handle) != DDI_FM_OK) 3583 ddi_fm_service_impact(Adapter->dip, DDI_SERVICE_DEGRADED); 3584 3585 return (link_changed); 3586 } 3587 3588 /* 3589 * e1000g_reset_link - Using the link properties to setup the link 3590 */ 3591 int 3592 e1000g_reset_link(struct e1000g *Adapter) 3593 { 3594 struct e1000_mac_info *mac; 3595 struct e1000_phy_info *phy; 3596 boolean_t invalid; 3597 3598 mac = &Adapter->shared.mac; 3599 phy = &Adapter->shared.phy; 3600 invalid = B_FALSE; 3601 3602 if (Adapter->param_adv_autoneg == 1) { 3603 mac->autoneg = B_TRUE; 3604 phy->autoneg_advertised = 0; 3605 3606 /* 3607 * 1000hdx is not supported for autonegotiation 3608 */ 3609 if (Adapter->param_adv_1000fdx == 1) 3610 phy->autoneg_advertised |= ADVERTISE_1000_FULL; 3611 3612 if (Adapter->param_adv_100fdx == 1) 3613 phy->autoneg_advertised |= ADVERTISE_100_FULL; 3614 3615 if (Adapter->param_adv_100hdx == 1) 3616 phy->autoneg_advertised |= ADVERTISE_100_HALF; 3617 3618 if (Adapter->param_adv_10fdx == 1) 3619 phy->autoneg_advertised |= ADVERTISE_10_FULL; 3620 3621 if (Adapter->param_adv_10hdx == 1) 3622 phy->autoneg_advertised |= ADVERTISE_10_HALF; 3623 3624 if (phy->autoneg_advertised == 0) 3625 invalid = B_TRUE; 3626 } else { 3627 mac->autoneg = B_FALSE; 3628 3629 /* 3630 * 1000fdx and 1000hdx are not supported for forced link 3631 */ 3632 if (Adapter->param_adv_100fdx == 1) 3633 mac->forced_speed_duplex = ADVERTISE_100_FULL; 3634 else if (Adapter->param_adv_100hdx == 1) 3635 mac->forced_speed_duplex = ADVERTISE_100_HALF; 3636 else if (Adapter->param_adv_10fdx == 1) 3637 mac->forced_speed_duplex = ADVERTISE_10_FULL; 3638 else if (Adapter->param_adv_10hdx == 1) 3639 mac->forced_speed_duplex = ADVERTISE_10_HALF; 3640 else 3641 invalid = B_TRUE; 3642 3643 } 3644 3645 if (invalid) { 3646 e1000g_log(Adapter, CE_WARN, 3647 "Invalid link sets. Setup link to" 3648 "support autonegotiation with all link capabilities."); 3649 mac->autoneg = B_TRUE; 3650 phy->autoneg_advertised = ADVERTISE_1000_FULL | 3651 ADVERTISE_100_FULL | ADVERTISE_100_HALF | 3652 ADVERTISE_10_FULL | ADVERTISE_10_HALF; 3653 } 3654 3655 return (e1000_setup_link(&Adapter->shared)); 3656 } 3657 3658 static void 3659 e1000g_local_timer(void *ws) 3660 { 3661 struct e1000g *Adapter = (struct e1000g *)ws; 3662 struct e1000_hw *hw; 3663 e1000g_ether_addr_t ether_addr; 3664 boolean_t link_changed; 3665 3666 hw = &Adapter->shared; 3667 3668 if (Adapter->chip_state == E1000G_ERROR) { 3669 Adapter->reset_count++; 3670 if (e1000g_global_reset(Adapter)) 3671 ddi_fm_service_impact(Adapter->dip, 3672 DDI_SERVICE_RESTORED); 3673 else 3674 ddi_fm_service_impact(Adapter->dip, 3675 DDI_SERVICE_LOST); 3676 return; 3677 } 3678 3679 if (e1000g_stall_check(Adapter)) { 3680 E1000G_DEBUGLOG_0(Adapter, E1000G_INFO_LEVEL, 3681 "Tx stall detected. Activate automatic recovery.\n"); 3682 e1000g_fm_ereport(Adapter, DDI_FM_DEVICE_STALL); 3683 Adapter->reset_count++; 3684 if (e1000g_reset_adapter(Adapter)) 3685 ddi_fm_service_impact(Adapter->dip, 3686 DDI_SERVICE_RESTORED); 3687 else 3688 ddi_fm_service_impact(Adapter->dip, 3689 DDI_SERVICE_LOST); 3690 return; 3691 } 3692 3693 link_changed = B_FALSE; 3694 rw_enter(&Adapter->chip_lock, RW_READER); 3695 if (Adapter->link_complete) 3696 link_changed = e1000g_link_check(Adapter); 3697 rw_exit(&Adapter->chip_lock); 3698 3699 if (link_changed) 3700 mac_link_update(Adapter->mh, Adapter->link_state); 3701 3702 /* 3703 * Workaround for esb2. Data stuck in fifo on a link 3704 * down event. Reset the adapter to recover it. 3705 */ 3706 if (Adapter->esb2_workaround) { 3707 Adapter->esb2_workaround = B_FALSE; 3708 (void) e1000g_reset_adapter(Adapter); 3709 } 3710 3711 /* 3712 * With 82571 controllers, any locally administered address will 3713 * be overwritten when there is a reset on the other port. 3714 * Detect this circumstance and correct it. 3715 */ 3716 if ((hw->mac.type == e1000_82571) && 3717 (e1000_get_laa_state_82571(hw) == B_TRUE)) { 3718 ether_addr.reg.low = E1000_READ_REG_ARRAY(hw, E1000_RA, 0); 3719 ether_addr.reg.high = E1000_READ_REG_ARRAY(hw, E1000_RA, 1); 3720 3721 ether_addr.reg.low = ntohl(ether_addr.reg.low); 3722 ether_addr.reg.high = ntohl(ether_addr.reg.high); 3723 3724 if ((ether_addr.mac.addr[5] != hw->mac.addr[0]) || 3725 (ether_addr.mac.addr[4] != hw->mac.addr[1]) || 3726 (ether_addr.mac.addr[3] != hw->mac.addr[2]) || 3727 (ether_addr.mac.addr[2] != hw->mac.addr[3]) || 3728 (ether_addr.mac.addr[1] != hw->mac.addr[4]) || 3729 (ether_addr.mac.addr[0] != hw->mac.addr[5])) { 3730 e1000_rar_set(hw, hw->mac.addr, 0); 3731 } 3732 } 3733 3734 /* 3735 * Long TTL workaround for 82541/82547 3736 */ 3737 (void) e1000_igp_ttl_workaround_82547(hw); 3738 3739 /* 3740 * Check for Adaptive IFS settings If there are lots of collisions 3741 * change the value in steps... 3742 * These properties should only be set for 10/100 3743 */ 3744 if ((hw->phy.media_type == e1000_media_type_copper) && 3745 ((Adapter->link_speed == SPEED_100) || 3746 (Adapter->link_speed == SPEED_10))) { 3747 e1000_update_adaptive(hw); 3748 } 3749 /* 3750 * Set Timer Interrupts 3751 */ 3752 E1000_WRITE_REG(hw, E1000_ICS, E1000_IMS_RXT0); 3753 3754 if (e1000g_check_acc_handle(Adapter->osdep.reg_handle) != DDI_FM_OK) 3755 ddi_fm_service_impact(Adapter->dip, DDI_SERVICE_DEGRADED); 3756 3757 restart_watchdog_timer(Adapter); 3758 } 3759 3760 /* 3761 * The function e1000g_link_timer() is called when the timer for link setup 3762 * is expired, which indicates the completion of the link setup. The link 3763 * state will not be updated until the link setup is completed. And the 3764 * link state will not be sent to the upper layer through mac_link_update() 3765 * in this function. It will be updated in the local timer routine or the 3766 * interrupt service routine after the interface is started (plumbed). 3767 */ 3768 static void 3769 e1000g_link_timer(void *arg) 3770 { 3771 struct e1000g *Adapter = (struct e1000g *)arg; 3772 3773 mutex_enter(&Adapter->link_lock); 3774 Adapter->link_complete = B_TRUE; 3775 Adapter->link_tid = 0; 3776 mutex_exit(&Adapter->link_lock); 3777 } 3778 3779 /* 3780 * e1000g_force_speed_duplex - read forced speed/duplex out of e1000g.conf 3781 * 3782 * This function read the forced speed and duplex for 10/100 Mbps speeds 3783 * and also for 1000 Mbps speeds from the e1000g.conf file 3784 */ 3785 static void 3786 e1000g_force_speed_duplex(struct e1000g *Adapter) 3787 { 3788 int forced; 3789 struct e1000_mac_info *mac = &Adapter->shared.mac; 3790 struct e1000_phy_info *phy = &Adapter->shared.phy; 3791 3792 /* 3793 * get value out of config file 3794 */ 3795 forced = e1000g_get_prop(Adapter, "ForceSpeedDuplex", 3796 GDIAG_10_HALF, GDIAG_ANY, GDIAG_ANY); 3797 3798 switch (forced) { 3799 case GDIAG_10_HALF: 3800 /* 3801 * Disable Auto Negotiation 3802 */ 3803 mac->autoneg = B_FALSE; 3804 mac->forced_speed_duplex = ADVERTISE_10_HALF; 3805 break; 3806 case GDIAG_10_FULL: 3807 /* 3808 * Disable Auto Negotiation 3809 */ 3810 mac->autoneg = B_FALSE; 3811 mac->forced_speed_duplex = ADVERTISE_10_FULL; 3812 break; 3813 case GDIAG_100_HALF: 3814 /* 3815 * Disable Auto Negotiation 3816 */ 3817 mac->autoneg = B_FALSE; 3818 mac->forced_speed_duplex = ADVERTISE_100_HALF; 3819 break; 3820 case GDIAG_100_FULL: 3821 /* 3822 * Disable Auto Negotiation 3823 */ 3824 mac->autoneg = B_FALSE; 3825 mac->forced_speed_duplex = ADVERTISE_100_FULL; 3826 break; 3827 case GDIAG_1000_FULL: 3828 /* 3829 * The gigabit spec requires autonegotiation. Therefore, 3830 * when the user wants to force the speed to 1000Mbps, we 3831 * enable AutoNeg, but only allow the harware to advertise 3832 * 1000Mbps. This is different from 10/100 operation, where 3833 * we are allowed to link without any negotiation. 3834 */ 3835 mac->autoneg = B_TRUE; 3836 phy->autoneg_advertised = ADVERTISE_1000_FULL; 3837 break; 3838 default: /* obey the setting of AutoNegAdvertised */ 3839 mac->autoneg = B_TRUE; 3840 phy->autoneg_advertised = 3841 (uint16_t)e1000g_get_prop(Adapter, "AutoNegAdvertised", 3842 0, AUTONEG_ADVERTISE_SPEED_DEFAULT, 3843 AUTONEG_ADVERTISE_SPEED_DEFAULT); 3844 break; 3845 } /* switch */ 3846 } 3847 3848 /* 3849 * e1000g_get_max_frame_size - get jumbo frame setting from e1000g.conf 3850 * 3851 * This function reads MaxFrameSize from e1000g.conf 3852 */ 3853 static void 3854 e1000g_get_max_frame_size(struct e1000g *Adapter) 3855 { 3856 int max_frame; 3857 struct e1000_mac_info *mac = &Adapter->shared.mac; 3858 struct e1000_phy_info *phy = &Adapter->shared.phy; 3859 3860 /* 3861 * get value out of config file 3862 */ 3863 max_frame = e1000g_get_prop(Adapter, "MaxFrameSize", 0, 3, 0); 3864 3865 switch (max_frame) { 3866 case 0: 3867 Adapter->default_mtu = ETHERMTU; 3868 break; 3869 /* 3870 * To avoid excessive memory allocation for rx buffers, 3871 * the bytes of E1000G_IPALIGNPRESERVEROOM are reserved. 3872 */ 3873 case 1: 3874 Adapter->default_mtu = FRAME_SIZE_UPTO_4K - 3875 sizeof (struct ether_vlan_header) - ETHERFCSL - 3876 E1000G_IPALIGNPRESERVEROOM; 3877 break; 3878 case 2: 3879 Adapter->default_mtu = FRAME_SIZE_UPTO_8K - 3880 sizeof (struct ether_vlan_header) - ETHERFCSL - 3881 E1000G_IPALIGNPRESERVEROOM; 3882 break; 3883 case 3: 3884 if (mac->type >= e1000_82571) 3885 Adapter->default_mtu = MAXIMUM_MTU; 3886 else 3887 Adapter->default_mtu = FRAME_SIZE_UPTO_16K - 3888 sizeof (struct ether_vlan_header) - ETHERFCSL - 3889 E1000G_IPALIGNPRESERVEROOM; 3890 break; 3891 default: 3892 Adapter->default_mtu = ETHERMTU; 3893 break; 3894 } /* switch */ 3895 3896 Adapter->max_frame_size = Adapter->default_mtu + 3897 sizeof (struct ether_vlan_header) + ETHERFCSL; 3898 3899 /* ich8 does not do jumbo frames */ 3900 if (mac->type == e1000_ich8lan) { 3901 Adapter->max_frame_size = ETHERMTU + 3902 sizeof (struct ether_vlan_header) + ETHERFCSL; 3903 } 3904 3905 /* ich9 does not do jumbo frames on one phy type */ 3906 if ((mac->type == e1000_ich9lan) && 3907 (phy->type == e1000_phy_ife)) { 3908 Adapter->max_frame_size = ETHERMTU + 3909 sizeof (struct ether_vlan_header) + ETHERFCSL; 3910 } 3911 } 3912 3913 static void 3914 arm_watchdog_timer(struct e1000g *Adapter) 3915 { 3916 Adapter->watchdog_tid = 3917 timeout(e1000g_local_timer, 3918 (void *)Adapter, 1 * drv_usectohz(1000000)); 3919 } 3920 #pragma inline(arm_watchdog_timer) 3921 3922 static void 3923 enable_watchdog_timer(struct e1000g *Adapter) 3924 { 3925 mutex_enter(&Adapter->watchdog_lock); 3926 3927 if (!Adapter->watchdog_timer_enabled) { 3928 Adapter->watchdog_timer_enabled = B_TRUE; 3929 Adapter->watchdog_timer_started = B_TRUE; 3930 arm_watchdog_timer(Adapter); 3931 } 3932 3933 mutex_exit(&Adapter->watchdog_lock); 3934 } 3935 3936 static void 3937 disable_watchdog_timer(struct e1000g *Adapter) 3938 { 3939 timeout_id_t tid; 3940 3941 mutex_enter(&Adapter->watchdog_lock); 3942 3943 Adapter->watchdog_timer_enabled = B_FALSE; 3944 Adapter->watchdog_timer_started = B_FALSE; 3945 tid = Adapter->watchdog_tid; 3946 Adapter->watchdog_tid = 0; 3947 3948 mutex_exit(&Adapter->watchdog_lock); 3949 3950 if (tid != 0) 3951 (void) untimeout(tid); 3952 } 3953 3954 static void 3955 start_watchdog_timer(struct e1000g *Adapter) 3956 { 3957 mutex_enter(&Adapter->watchdog_lock); 3958 3959 if (Adapter->watchdog_timer_enabled) { 3960 if (!Adapter->watchdog_timer_started) { 3961 Adapter->watchdog_timer_started = B_TRUE; 3962 arm_watchdog_timer(Adapter); 3963 } 3964 } 3965 3966 mutex_exit(&Adapter->watchdog_lock); 3967 } 3968 3969 static void 3970 restart_watchdog_timer(struct e1000g *Adapter) 3971 { 3972 mutex_enter(&Adapter->watchdog_lock); 3973 3974 if (Adapter->watchdog_timer_started) 3975 arm_watchdog_timer(Adapter); 3976 3977 mutex_exit(&Adapter->watchdog_lock); 3978 } 3979 3980 static void 3981 stop_watchdog_timer(struct e1000g *Adapter) 3982 { 3983 timeout_id_t tid; 3984 3985 mutex_enter(&Adapter->watchdog_lock); 3986 3987 Adapter->watchdog_timer_started = B_FALSE; 3988 tid = Adapter->watchdog_tid; 3989 Adapter->watchdog_tid = 0; 3990 3991 mutex_exit(&Adapter->watchdog_lock); 3992 3993 if (tid != 0) 3994 (void) untimeout(tid); 3995 } 3996 3997 static void 3998 stop_link_timer(struct e1000g *Adapter) 3999 { 4000 timeout_id_t tid; 4001 4002 /* Disable the link timer */ 4003 mutex_enter(&Adapter->link_lock); 4004 4005 tid = Adapter->link_tid; 4006 Adapter->link_tid = 0; 4007 4008 mutex_exit(&Adapter->link_lock); 4009 4010 if (tid != 0) 4011 (void) untimeout(tid); 4012 } 4013 4014 static void 4015 stop_82547_timer(e1000g_tx_ring_t *tx_ring) 4016 { 4017 timeout_id_t tid; 4018 4019 /* Disable the tx timer for 82547 chipset */ 4020 mutex_enter(&tx_ring->tx_lock); 4021 4022 tx_ring->timer_enable_82547 = B_FALSE; 4023 tid = tx_ring->timer_id_82547; 4024 tx_ring->timer_id_82547 = 0; 4025 4026 mutex_exit(&tx_ring->tx_lock); 4027 4028 if (tid != 0) 4029 (void) untimeout(tid); 4030 } 4031 4032 void 4033 e1000g_clear_interrupt(struct e1000g *Adapter) 4034 { 4035 E1000_WRITE_REG(&Adapter->shared, E1000_IMC, 4036 0xffffffff & ~E1000_IMS_RXSEQ); 4037 } 4038 4039 void 4040 e1000g_mask_interrupt(struct e1000g *Adapter) 4041 { 4042 E1000_WRITE_REG(&Adapter->shared, E1000_IMS, 4043 IMS_ENABLE_MASK & ~E1000_IMS_TXDW); 4044 4045 if (Adapter->tx_intr_enable) 4046 e1000g_mask_tx_interrupt(Adapter); 4047 } 4048 4049 /* 4050 * This routine is called by e1000g_quiesce(), therefore must not block. 4051 */ 4052 void 4053 e1000g_clear_all_interrupts(struct e1000g *Adapter) 4054 { 4055 E1000_WRITE_REG(&Adapter->shared, E1000_IMC, 0xffffffff); 4056 } 4057 4058 void 4059 e1000g_mask_tx_interrupt(struct e1000g *Adapter) 4060 { 4061 E1000_WRITE_REG(&Adapter->shared, E1000_IMS, E1000_IMS_TXDW); 4062 } 4063 4064 void 4065 e1000g_clear_tx_interrupt(struct e1000g *Adapter) 4066 { 4067 E1000_WRITE_REG(&Adapter->shared, E1000_IMC, E1000_IMS_TXDW); 4068 } 4069 4070 static void 4071 e1000g_smartspeed(struct e1000g *Adapter) 4072 { 4073 struct e1000_hw *hw = &Adapter->shared; 4074 uint16_t phy_status; 4075 uint16_t phy_ctrl; 4076 4077 /* 4078 * If we're not T-or-T, or we're not autoneg'ing, or we're not 4079 * advertising 1000Full, we don't even use the workaround 4080 */ 4081 if ((hw->phy.type != e1000_phy_igp) || 4082 !hw->mac.autoneg || 4083 !(hw->phy.autoneg_advertised & ADVERTISE_1000_FULL)) 4084 return; 4085 4086 /* 4087 * True if this is the first call of this function or after every 4088 * 30 seconds of not having link 4089 */ 4090 if (Adapter->smartspeed == 0) { 4091 /* 4092 * If Master/Slave config fault is asserted twice, we 4093 * assume back-to-back 4094 */ 4095 (void) e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_status); 4096 if (!(phy_status & SR_1000T_MS_CONFIG_FAULT)) 4097 return; 4098 4099 (void) e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_status); 4100 if (!(phy_status & SR_1000T_MS_CONFIG_FAULT)) 4101 return; 4102 /* 4103 * We're assuming back-2-back because our status register 4104 * insists! there's a fault in the master/slave 4105 * relationship that was "negotiated" 4106 */ 4107 (void) e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_ctrl); 4108 /* 4109 * Is the phy configured for manual configuration of 4110 * master/slave? 4111 */ 4112 if (phy_ctrl & CR_1000T_MS_ENABLE) { 4113 /* 4114 * Yes. Then disable manual configuration (enable 4115 * auto configuration) of master/slave 4116 */ 4117 phy_ctrl &= ~CR_1000T_MS_ENABLE; 4118 (void) e1000_write_phy_reg(hw, 4119 PHY_1000T_CTRL, phy_ctrl); 4120 /* 4121 * Effectively starting the clock 4122 */ 4123 Adapter->smartspeed++; 4124 /* 4125 * Restart autonegotiation 4126 */ 4127 if (!e1000_phy_setup_autoneg(hw) && 4128 !e1000_read_phy_reg(hw, PHY_CONTROL, &phy_ctrl)) { 4129 phy_ctrl |= (MII_CR_AUTO_NEG_EN | 4130 MII_CR_RESTART_AUTO_NEG); 4131 (void) e1000_write_phy_reg(hw, 4132 PHY_CONTROL, phy_ctrl); 4133 } 4134 } 4135 return; 4136 /* 4137 * Has 6 seconds transpired still without link? Remember, 4138 * you should reset the smartspeed counter once you obtain 4139 * link 4140 */ 4141 } else if (Adapter->smartspeed == E1000_SMARTSPEED_DOWNSHIFT) { 4142 /* 4143 * Yes. Remember, we did at the start determine that 4144 * there's a master/slave configuration fault, so we're 4145 * still assuming there's someone on the other end, but we 4146 * just haven't yet been able to talk to it. We then 4147 * re-enable auto configuration of master/slave to see if 4148 * we're running 2/3 pair cables. 4149 */ 4150 /* 4151 * If still no link, perhaps using 2/3 pair cable 4152 */ 4153 (void) e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_ctrl); 4154 phy_ctrl |= CR_1000T_MS_ENABLE; 4155 (void) e1000_write_phy_reg(hw, PHY_1000T_CTRL, phy_ctrl); 4156 /* 4157 * Restart autoneg with phy enabled for manual 4158 * configuration of master/slave 4159 */ 4160 if (!e1000_phy_setup_autoneg(hw) && 4161 !e1000_read_phy_reg(hw, PHY_CONTROL, &phy_ctrl)) { 4162 phy_ctrl |= 4163 (MII_CR_AUTO_NEG_EN | MII_CR_RESTART_AUTO_NEG); 4164 (void) e1000_write_phy_reg(hw, PHY_CONTROL, phy_ctrl); 4165 } 4166 /* 4167 * Hopefully, there are no more faults and we've obtained 4168 * link as a result. 4169 */ 4170 } 4171 /* 4172 * Restart process after E1000_SMARTSPEED_MAX iterations (30 4173 * seconds) 4174 */ 4175 if (Adapter->smartspeed++ == E1000_SMARTSPEED_MAX) 4176 Adapter->smartspeed = 0; 4177 } 4178 4179 static boolean_t 4180 is_valid_mac_addr(uint8_t *mac_addr) 4181 { 4182 const uint8_t addr_test1[6] = { 0, 0, 0, 0, 0, 0 }; 4183 const uint8_t addr_test2[6] = 4184 { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }; 4185 4186 if (!(bcmp(addr_test1, mac_addr, ETHERADDRL)) || 4187 !(bcmp(addr_test2, mac_addr, ETHERADDRL))) 4188 return (B_FALSE); 4189 4190 return (B_TRUE); 4191 } 4192 4193 /* 4194 * e1000g_stall_check - check for tx stall 4195 * 4196 * This function checks if the adapter is stalled (in transmit). 4197 * 4198 * It is called each time the watchdog timeout is invoked. 4199 * If the transmit descriptor reclaim continuously fails, 4200 * the watchdog value will increment by 1. If the watchdog 4201 * value exceeds the threshold, the adapter is assumed to 4202 * have stalled and need to be reset. 4203 */ 4204 static boolean_t 4205 e1000g_stall_check(struct e1000g *Adapter) 4206 { 4207 e1000g_tx_ring_t *tx_ring; 4208 4209 tx_ring = Adapter->tx_ring; 4210 4211 if (Adapter->link_state != LINK_STATE_UP) 4212 return (B_FALSE); 4213 4214 if (tx_ring->recycle_fail > 0) 4215 tx_ring->stall_watchdog++; 4216 else 4217 tx_ring->stall_watchdog = 0; 4218 4219 if (tx_ring->stall_watchdog < E1000G_STALL_WATCHDOG_COUNT) 4220 return (B_FALSE); 4221 4222 tx_ring->stall_watchdog = 0; 4223 tx_ring->recycle_fail = 0; 4224 4225 return (B_TRUE); 4226 } 4227 4228 #ifdef E1000G_DEBUG 4229 static enum ioc_reply 4230 e1000g_pp_ioctl(struct e1000g *e1000gp, struct iocblk *iocp, mblk_t *mp) 4231 { 4232 void (*ppfn)(struct e1000g *e1000gp, e1000g_peekpoke_t *ppd); 4233 e1000g_peekpoke_t *ppd; 4234 uint64_t mem_va; 4235 uint64_t maxoff; 4236 boolean_t peek; 4237 4238 switch (iocp->ioc_cmd) { 4239 4240 case E1000G_IOC_REG_PEEK: 4241 peek = B_TRUE; 4242 break; 4243 4244 case E1000G_IOC_REG_POKE: 4245 peek = B_FALSE; 4246 break; 4247 4248 deault: 4249 E1000G_DEBUGLOG_1(e1000gp, E1000G_INFO_LEVEL, 4250 "e1000g_diag_ioctl: invalid ioctl command 0x%X\n", 4251 iocp->ioc_cmd); 4252 return (IOC_INVAL); 4253 } 4254 4255 /* 4256 * Validate format of ioctl 4257 */ 4258 if (iocp->ioc_count != sizeof (e1000g_peekpoke_t)) 4259 return (IOC_INVAL); 4260 if (mp->b_cont == NULL) 4261 return (IOC_INVAL); 4262 4263 ppd = (e1000g_peekpoke_t *)(uintptr_t)mp->b_cont->b_rptr; 4264 4265 /* 4266 * Validate request parameters 4267 */ 4268 switch (ppd->pp_acc_space) { 4269 4270 default: 4271 E1000G_DEBUGLOG_1(e1000gp, E1000G_INFO_LEVEL, 4272 "e1000g_diag_ioctl: invalid access space 0x%X\n", 4273 ppd->pp_acc_space); 4274 return (IOC_INVAL); 4275 4276 case E1000G_PP_SPACE_REG: 4277 /* 4278 * Memory-mapped I/O space 4279 */ 4280 ASSERT(ppd->pp_acc_size == 4); 4281 if (ppd->pp_acc_size != 4) 4282 return (IOC_INVAL); 4283 4284 if ((ppd->pp_acc_offset % ppd->pp_acc_size) != 0) 4285 return (IOC_INVAL); 4286 4287 mem_va = 0; 4288 maxoff = 0x10000; 4289 ppfn = peek ? e1000g_ioc_peek_reg : e1000g_ioc_poke_reg; 4290 break; 4291 4292 case E1000G_PP_SPACE_E1000G: 4293 /* 4294 * E1000g data structure! 4295 */ 4296 mem_va = (uintptr_t)e1000gp; 4297 maxoff = sizeof (struct e1000g); 4298 ppfn = peek ? e1000g_ioc_peek_mem : e1000g_ioc_poke_mem; 4299 break; 4300 4301 } 4302 4303 if (ppd->pp_acc_offset >= maxoff) 4304 return (IOC_INVAL); 4305 4306 if (ppd->pp_acc_offset + ppd->pp_acc_size > maxoff) 4307 return (IOC_INVAL); 4308 4309 /* 4310 * All OK - go! 4311 */ 4312 ppd->pp_acc_offset += mem_va; 4313 (*ppfn)(e1000gp, ppd); 4314 return (peek ? IOC_REPLY : IOC_ACK); 4315 } 4316 4317 static void 4318 e1000g_ioc_peek_reg(struct e1000g *e1000gp, e1000g_peekpoke_t *ppd) 4319 { 4320 ddi_acc_handle_t handle; 4321 uint32_t *regaddr; 4322 4323 handle = e1000gp->osdep.reg_handle; 4324 regaddr = (uint32_t *)((uintptr_t)e1000gp->shared.hw_addr + 4325 (uintptr_t)ppd->pp_acc_offset); 4326 4327 ppd->pp_acc_data = ddi_get32(handle, regaddr); 4328 } 4329 4330 static void 4331 e1000g_ioc_poke_reg(struct e1000g *e1000gp, e1000g_peekpoke_t *ppd) 4332 { 4333 ddi_acc_handle_t handle; 4334 uint32_t *regaddr; 4335 uint32_t value; 4336 4337 handle = e1000gp->osdep.reg_handle; 4338 regaddr = (uint32_t *)((uintptr_t)e1000gp->shared.hw_addr + 4339 (uintptr_t)ppd->pp_acc_offset); 4340 value = (uint32_t)ppd->pp_acc_data; 4341 4342 ddi_put32(handle, regaddr, value); 4343 } 4344 4345 static void 4346 e1000g_ioc_peek_mem(struct e1000g *e1000gp, e1000g_peekpoke_t *ppd) 4347 { 4348 uint64_t value; 4349 void *vaddr; 4350 4351 vaddr = (void *)(uintptr_t)ppd->pp_acc_offset; 4352 4353 switch (ppd->pp_acc_size) { 4354 case 1: 4355 value = *(uint8_t *)vaddr; 4356 break; 4357 4358 case 2: 4359 value = *(uint16_t *)vaddr; 4360 break; 4361 4362 case 4: 4363 value = *(uint32_t *)vaddr; 4364 break; 4365 4366 case 8: 4367 value = *(uint64_t *)vaddr; 4368 break; 4369 } 4370 4371 E1000G_DEBUGLOG_4(e1000gp, E1000G_INFO_LEVEL, 4372 "e1000g_ioc_peek_mem($%p, $%p) peeked 0x%llx from $%p\n", 4373 (void *)e1000gp, (void *)ppd, value, vaddr); 4374 4375 ppd->pp_acc_data = value; 4376 } 4377 4378 static void 4379 e1000g_ioc_poke_mem(struct e1000g *e1000gp, e1000g_peekpoke_t *ppd) 4380 { 4381 uint64_t value; 4382 void *vaddr; 4383 4384 vaddr = (void *)(uintptr_t)ppd->pp_acc_offset; 4385 value = ppd->pp_acc_data; 4386 4387 E1000G_DEBUGLOG_4(e1000gp, E1000G_INFO_LEVEL, 4388 "e1000g_ioc_poke_mem($%p, $%p) poking 0x%llx at $%p\n", 4389 (void *)e1000gp, (void *)ppd, value, vaddr); 4390 4391 switch (ppd->pp_acc_size) { 4392 case 1: 4393 *(uint8_t *)vaddr = (uint8_t)value; 4394 break; 4395 4396 case 2: 4397 *(uint16_t *)vaddr = (uint16_t)value; 4398 break; 4399 4400 case 4: 4401 *(uint32_t *)vaddr = (uint32_t)value; 4402 break; 4403 4404 case 8: 4405 *(uint64_t *)vaddr = (uint64_t)value; 4406 break; 4407 } 4408 } 4409 #endif 4410 4411 /* 4412 * Loopback Support 4413 */ 4414 static lb_property_t lb_normal = 4415 { normal, "normal", E1000G_LB_NONE }; 4416 static lb_property_t lb_external1000 = 4417 { external, "1000Mbps", E1000G_LB_EXTERNAL_1000 }; 4418 static lb_property_t lb_external100 = 4419 { external, "100Mbps", E1000G_LB_EXTERNAL_100 }; 4420 static lb_property_t lb_external10 = 4421 { external, "10Mbps", E1000G_LB_EXTERNAL_10 }; 4422 static lb_property_t lb_phy = 4423 { internal, "PHY", E1000G_LB_INTERNAL_PHY }; 4424 4425 static enum ioc_reply 4426 e1000g_loopback_ioctl(struct e1000g *Adapter, struct iocblk *iocp, mblk_t *mp) 4427 { 4428 lb_info_sz_t *lbsp; 4429 lb_property_t *lbpp; 4430 struct e1000_hw *hw; 4431 uint32_t *lbmp; 4432 uint32_t size; 4433 uint32_t value; 4434 4435 hw = &Adapter->shared; 4436 4437 if (mp->b_cont == NULL) 4438 return (IOC_INVAL); 4439 4440 if (!e1000g_check_loopback_support(hw)) { 4441 e1000g_log(NULL, CE_WARN, 4442 "Loopback is not supported on e1000g%d", Adapter->instance); 4443 return (IOC_INVAL); 4444 } 4445 4446 switch (iocp->ioc_cmd) { 4447 default: 4448 return (IOC_INVAL); 4449 4450 case LB_GET_INFO_SIZE: 4451 size = sizeof (lb_info_sz_t); 4452 if (iocp->ioc_count != size) 4453 return (IOC_INVAL); 4454 4455 rw_enter(&Adapter->chip_lock, RW_WRITER); 4456 e1000g_get_phy_state(Adapter); 4457 4458 /* 4459 * Workaround for hardware faults. In order to get a stable 4460 * state of phy, we will wait for a specific interval and 4461 * try again. The time delay is an experiential value based 4462 * on our testing. 4463 */ 4464 msec_delay(100); 4465 e1000g_get_phy_state(Adapter); 4466 rw_exit(&Adapter->chip_lock); 4467 4468 value = sizeof (lb_normal); 4469 if ((Adapter->phy_ext_status & IEEE_ESR_1000T_FD_CAPS) || 4470 (Adapter->phy_ext_status & IEEE_ESR_1000X_FD_CAPS) || 4471 (hw->phy.media_type == e1000_media_type_fiber) || 4472 (hw->phy.media_type == e1000_media_type_internal_serdes)) { 4473 value += sizeof (lb_phy); 4474 switch (hw->mac.type) { 4475 case e1000_82571: 4476 case e1000_82572: 4477 case e1000_80003es2lan: 4478 value += sizeof (lb_external1000); 4479 break; 4480 } 4481 } 4482 if ((Adapter->phy_status & MII_SR_100X_FD_CAPS) || 4483 (Adapter->phy_status & MII_SR_100T2_FD_CAPS)) 4484 value += sizeof (lb_external100); 4485 if (Adapter->phy_status & MII_SR_10T_FD_CAPS) 4486 value += sizeof (lb_external10); 4487 4488 lbsp = (lb_info_sz_t *)(uintptr_t)mp->b_cont->b_rptr; 4489 *lbsp = value; 4490 break; 4491 4492 case LB_GET_INFO: 4493 value = sizeof (lb_normal); 4494 if ((Adapter->phy_ext_status & IEEE_ESR_1000T_FD_CAPS) || 4495 (Adapter->phy_ext_status & IEEE_ESR_1000X_FD_CAPS) || 4496 (hw->phy.media_type == e1000_media_type_fiber) || 4497 (hw->phy.media_type == e1000_media_type_internal_serdes)) { 4498 value += sizeof (lb_phy); 4499 switch (hw->mac.type) { 4500 case e1000_82571: 4501 case e1000_82572: 4502 case e1000_80003es2lan: 4503 value += sizeof (lb_external1000); 4504 break; 4505 } 4506 } 4507 if ((Adapter->phy_status & MII_SR_100X_FD_CAPS) || 4508 (Adapter->phy_status & MII_SR_100T2_FD_CAPS)) 4509 value += sizeof (lb_external100); 4510 if (Adapter->phy_status & MII_SR_10T_FD_CAPS) 4511 value += sizeof (lb_external10); 4512 4513 size = value; 4514 if (iocp->ioc_count != size) 4515 return (IOC_INVAL); 4516 4517 value = 0; 4518 lbpp = (lb_property_t *)(uintptr_t)mp->b_cont->b_rptr; 4519 lbpp[value++] = lb_normal; 4520 if ((Adapter->phy_ext_status & IEEE_ESR_1000T_FD_CAPS) || 4521 (Adapter->phy_ext_status & IEEE_ESR_1000X_FD_CAPS) || 4522 (hw->phy.media_type == e1000_media_type_fiber) || 4523 (hw->phy.media_type == e1000_media_type_internal_serdes)) { 4524 lbpp[value++] = lb_phy; 4525 switch (hw->mac.type) { 4526 case e1000_82571: 4527 case e1000_82572: 4528 case e1000_80003es2lan: 4529 lbpp[value++] = lb_external1000; 4530 break; 4531 } 4532 } 4533 if ((Adapter->phy_status & MII_SR_100X_FD_CAPS) || 4534 (Adapter->phy_status & MII_SR_100T2_FD_CAPS)) 4535 lbpp[value++] = lb_external100; 4536 if (Adapter->phy_status & MII_SR_10T_FD_CAPS) 4537 lbpp[value++] = lb_external10; 4538 break; 4539 4540 case LB_GET_MODE: 4541 size = sizeof (uint32_t); 4542 if (iocp->ioc_count != size) 4543 return (IOC_INVAL); 4544 4545 lbmp = (uint32_t *)(uintptr_t)mp->b_cont->b_rptr; 4546 *lbmp = Adapter->loopback_mode; 4547 break; 4548 4549 case LB_SET_MODE: 4550 size = 0; 4551 if (iocp->ioc_count != sizeof (uint32_t)) 4552 return (IOC_INVAL); 4553 4554 lbmp = (uint32_t *)(uintptr_t)mp->b_cont->b_rptr; 4555 if (!e1000g_set_loopback_mode(Adapter, *lbmp)) 4556 return (IOC_INVAL); 4557 break; 4558 } 4559 4560 iocp->ioc_count = size; 4561 iocp->ioc_error = 0; 4562 4563 if (e1000g_check_acc_handle(Adapter->osdep.reg_handle) != DDI_FM_OK) { 4564 ddi_fm_service_impact(Adapter->dip, DDI_SERVICE_DEGRADED); 4565 return (IOC_INVAL); 4566 } 4567 4568 return (IOC_REPLY); 4569 } 4570 4571 static boolean_t 4572 e1000g_check_loopback_support(struct e1000_hw *hw) 4573 { 4574 switch (hw->mac.type) { 4575 case e1000_82540: 4576 case e1000_82545: 4577 case e1000_82545_rev_3: 4578 case e1000_82546: 4579 case e1000_82546_rev_3: 4580 case e1000_82541: 4581 case e1000_82541_rev_2: 4582 case e1000_82547: 4583 case e1000_82547_rev_2: 4584 case e1000_82571: 4585 case e1000_82572: 4586 case e1000_82573: 4587 case e1000_80003es2lan: 4588 return (B_TRUE); 4589 } 4590 return (B_FALSE); 4591 } 4592 4593 static boolean_t 4594 e1000g_set_loopback_mode(struct e1000g *Adapter, uint32_t mode) 4595 { 4596 struct e1000_hw *hw; 4597 int i, times; 4598 boolean_t link_up; 4599 4600 if (mode == Adapter->loopback_mode) 4601 return (B_TRUE); 4602 4603 hw = &Adapter->shared; 4604 times = 0; 4605 4606 Adapter->loopback_mode = mode; 4607 4608 if (mode == E1000G_LB_NONE) { 4609 /* Reset the chip */ 4610 hw->phy.autoneg_wait_to_complete = B_TRUE; 4611 (void) e1000g_reset_adapter(Adapter); 4612 hw->phy.autoneg_wait_to_complete = B_FALSE; 4613 return (B_TRUE); 4614 } 4615 4616 again: 4617 4618 rw_enter(&Adapter->chip_lock, RW_WRITER); 4619 4620 switch (mode) { 4621 default: 4622 rw_exit(&Adapter->chip_lock); 4623 return (B_FALSE); 4624 4625 case E1000G_LB_EXTERNAL_1000: 4626 e1000g_set_external_loopback_1000(Adapter); 4627 break; 4628 4629 case E1000G_LB_EXTERNAL_100: 4630 e1000g_set_external_loopback_100(Adapter); 4631 break; 4632 4633 case E1000G_LB_EXTERNAL_10: 4634 e1000g_set_external_loopback_10(Adapter); 4635 break; 4636 4637 case E1000G_LB_INTERNAL_PHY: 4638 e1000g_set_internal_loopback(Adapter); 4639 break; 4640 } 4641 4642 times++; 4643 4644 rw_exit(&Adapter->chip_lock); 4645 4646 /* Wait for link up */ 4647 for (i = (PHY_FORCE_LIMIT * 2); i > 0; i--) 4648 msec_delay(100); 4649 4650 rw_enter(&Adapter->chip_lock, RW_WRITER); 4651 4652 link_up = e1000g_link_up(Adapter); 4653 4654 rw_exit(&Adapter->chip_lock); 4655 4656 if (!link_up) { 4657 E1000G_DEBUGLOG_0(Adapter, E1000G_INFO_LEVEL, 4658 "Failed to get the link up"); 4659 if (times < 2) { 4660 /* Reset the link */ 4661 E1000G_DEBUGLOG_0(Adapter, E1000G_INFO_LEVEL, 4662 "Reset the link ..."); 4663 (void) e1000g_reset_adapter(Adapter); 4664 goto again; 4665 } 4666 } 4667 4668 return (B_TRUE); 4669 } 4670 4671 /* 4672 * The following loopback settings are from Intel's technical 4673 * document - "How To Loopback". All the register settings and 4674 * time delay values are directly inherited from the document 4675 * without more explanations available. 4676 */ 4677 static void 4678 e1000g_set_internal_loopback(struct e1000g *Adapter) 4679 { 4680 struct e1000_hw *hw; 4681 uint32_t ctrl; 4682 uint32_t status; 4683 uint16_t phy_ctrl; 4684 uint32_t txcw; 4685 4686 hw = &Adapter->shared; 4687 4688 /* Disable Smart Power Down */ 4689 phy_spd_state(hw, B_FALSE); 4690 4691 (void) e1000_read_phy_reg(hw, PHY_CONTROL, &phy_ctrl); 4692 phy_ctrl &= ~(MII_CR_AUTO_NEG_EN | MII_CR_SPEED_100 | MII_CR_SPEED_10); 4693 phy_ctrl |= MII_CR_FULL_DUPLEX | MII_CR_SPEED_1000; 4694 4695 switch (hw->mac.type) { 4696 case e1000_82540: 4697 case e1000_82545: 4698 case e1000_82545_rev_3: 4699 case e1000_82546: 4700 case e1000_82546_rev_3: 4701 case e1000_82573: 4702 /* Auto-MDI/MDIX off */ 4703 (void) e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, 0x0808); 4704 /* Reset PHY to update Auto-MDI/MDIX */ 4705 (void) e1000_write_phy_reg(hw, PHY_CONTROL, 4706 phy_ctrl | MII_CR_RESET | MII_CR_AUTO_NEG_EN); 4707 /* Reset PHY to auto-neg off and force 1000 */ 4708 (void) e1000_write_phy_reg(hw, PHY_CONTROL, 4709 phy_ctrl | MII_CR_RESET); 4710 /* 4711 * Disable PHY receiver for 82540/545/546 and 82573 Family. 4712 * See comments above e1000g_set_internal_loopback() for the 4713 * background. 4714 */ 4715 (void) e1000_write_phy_reg(hw, 29, 0x001F); 4716 (void) e1000_write_phy_reg(hw, 30, 0x8FFC); 4717 (void) e1000_write_phy_reg(hw, 29, 0x001A); 4718 (void) e1000_write_phy_reg(hw, 30, 0x8FF0); 4719 break; 4720 case e1000_80003es2lan: 4721 /* Force Link Up */ 4722 (void) e1000_write_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL, 4723 0x1CC); 4724 /* Sets PCS loopback at 1Gbs */ 4725 (void) e1000_write_phy_reg(hw, GG82563_PHY_MAC_SPEC_CTRL, 4726 0x1046); 4727 break; 4728 } 4729 4730 /* Set loopback */ 4731 (void) e1000_write_phy_reg(hw, PHY_CONTROL, phy_ctrl | MII_CR_LOOPBACK); 4732 4733 msec_delay(250); 4734 4735 /* Now set up the MAC to the same speed/duplex as the PHY. */ 4736 ctrl = E1000_READ_REG(hw, E1000_CTRL); 4737 ctrl &= ~E1000_CTRL_SPD_SEL; /* Clear the speed sel bits */ 4738 ctrl |= (E1000_CTRL_FRCSPD | /* Set the Force Speed Bit */ 4739 E1000_CTRL_FRCDPX | /* Set the Force Duplex Bit */ 4740 E1000_CTRL_SPD_1000 | /* Force Speed to 1000 */ 4741 E1000_CTRL_FD); /* Force Duplex to FULL */ 4742 4743 switch (hw->mac.type) { 4744 case e1000_82540: 4745 case e1000_82545: 4746 case e1000_82545_rev_3: 4747 case e1000_82546: 4748 case e1000_82546_rev_3: 4749 /* 4750 * For some serdes we'll need to commit the writes now 4751 * so that the status is updated on link 4752 */ 4753 if (hw->phy.media_type == e1000_media_type_internal_serdes) { 4754 E1000_WRITE_REG(hw, E1000_CTRL, ctrl); 4755 msec_delay(100); 4756 ctrl = E1000_READ_REG(hw, E1000_CTRL); 4757 } 4758 4759 if (hw->phy.media_type == e1000_media_type_copper) { 4760 /* Invert Loss of Signal */ 4761 ctrl |= E1000_CTRL_ILOS; 4762 } else { 4763 /* Set ILOS on fiber nic if half duplex is detected */ 4764 status = E1000_READ_REG(hw, E1000_STATUS); 4765 if ((status & E1000_STATUS_FD) == 0) 4766 ctrl |= E1000_CTRL_ILOS | E1000_CTRL_SLU; 4767 } 4768 E1000_WRITE_REG(hw, E1000_CTRL, ctrl); 4769 break; 4770 4771 case e1000_82571: 4772 case e1000_82572: 4773 /* 4774 * The fiber/SerDes versions of this adapter do not contain an 4775 * accessible PHY. Therefore, loopback beyond MAC must be done 4776 * using SerDes analog loopback. 4777 */ 4778 if (hw->phy.media_type != e1000_media_type_copper) { 4779 status = E1000_READ_REG(hw, E1000_STATUS); 4780 /* Set ILOS on fiber nic if half duplex is detected */ 4781 if (((status & E1000_STATUS_LU) == 0) || 4782 ((status & E1000_STATUS_FD) == 0) || 4783 (hw->phy.media_type == 4784 e1000_media_type_internal_serdes)) 4785 ctrl |= E1000_CTRL_ILOS | E1000_CTRL_SLU; 4786 4787 /* Disable autoneg by setting bit 31 of TXCW to zero */ 4788 txcw = E1000_READ_REG(hw, E1000_TXCW); 4789 txcw &= ~((uint32_t)1 << 31); 4790 E1000_WRITE_REG(hw, E1000_TXCW, txcw); 4791 4792 /* 4793 * Write 0x410 to Serdes Control register 4794 * to enable Serdes analog loopback 4795 */ 4796 E1000_WRITE_REG(hw, E1000_SCTL, 0x0410); 4797 msec_delay(10); 4798 } 4799 E1000_WRITE_REG(hw, E1000_CTRL, ctrl); 4800 break; 4801 4802 case e1000_82573: 4803 ctrl |= E1000_CTRL_ILOS; 4804 E1000_WRITE_REG(hw, E1000_CTRL, ctrl); 4805 break; 4806 } 4807 } 4808 4809 static void 4810 e1000g_set_external_loopback_1000(struct e1000g *Adapter) 4811 { 4812 struct e1000_hw *hw; 4813 uint32_t rctl; 4814 uint32_t ctrl_ext; 4815 uint32_t ctrl; 4816 uint32_t status; 4817 uint32_t txcw; 4818 uint16_t phydata; 4819 4820 hw = &Adapter->shared; 4821 4822 /* Disable Smart Power Down */ 4823 phy_spd_state(hw, B_FALSE); 4824 4825 switch (hw->mac.type) { 4826 case e1000_82571: 4827 case e1000_82572: 4828 switch (hw->phy.media_type) { 4829 case e1000_media_type_copper: 4830 /* Force link up (Must be done before the PHY writes) */ 4831 ctrl = E1000_READ_REG(hw, E1000_CTRL); 4832 ctrl |= E1000_CTRL_SLU; /* Force Link Up */ 4833 E1000_WRITE_REG(hw, E1000_CTRL, ctrl); 4834 4835 rctl = E1000_READ_REG(hw, E1000_RCTL); 4836 rctl |= (E1000_RCTL_EN | 4837 E1000_RCTL_SBP | 4838 E1000_RCTL_UPE | 4839 E1000_RCTL_MPE | 4840 E1000_RCTL_LPE | 4841 E1000_RCTL_BAM); /* 0x803E */ 4842 E1000_WRITE_REG(hw, E1000_RCTL, rctl); 4843 4844 ctrl_ext = E1000_READ_REG(hw, E1000_CTRL_EXT); 4845 ctrl_ext |= (E1000_CTRL_EXT_SDP4_DATA | 4846 E1000_CTRL_EXT_SDP6_DATA | 4847 E1000_CTRL_EXT_SDP7_DATA | 4848 E1000_CTRL_EXT_SDP4_DIR | 4849 E1000_CTRL_EXT_SDP6_DIR | 4850 E1000_CTRL_EXT_SDP7_DIR); /* 0x0DD0 */ 4851 E1000_WRITE_REG(hw, E1000_CTRL_EXT, ctrl_ext); 4852 4853 /* 4854 * This sequence tunes the PHY's SDP and no customer 4855 * settable values. For background, see comments above 4856 * e1000g_set_internal_loopback(). 4857 */ 4858 (void) e1000_write_phy_reg(hw, 0x0, 0x140); 4859 msec_delay(10); 4860 (void) e1000_write_phy_reg(hw, 0x9, 0x1A00); 4861 (void) e1000_write_phy_reg(hw, 0x12, 0xC10); 4862 (void) e1000_write_phy_reg(hw, 0x12, 0x1C10); 4863 (void) e1000_write_phy_reg(hw, 0x1F37, 0x76); 4864 (void) e1000_write_phy_reg(hw, 0x1F33, 0x1); 4865 (void) e1000_write_phy_reg(hw, 0x1F33, 0x0); 4866 4867 (void) e1000_write_phy_reg(hw, 0x1F35, 0x65); 4868 (void) e1000_write_phy_reg(hw, 0x1837, 0x3F7C); 4869 (void) e1000_write_phy_reg(hw, 0x1437, 0x3FDC); 4870 (void) e1000_write_phy_reg(hw, 0x1237, 0x3F7C); 4871 (void) e1000_write_phy_reg(hw, 0x1137, 0x3FDC); 4872 4873 msec_delay(50); 4874 break; 4875 case e1000_media_type_fiber: 4876 case e1000_media_type_internal_serdes: 4877 status = E1000_READ_REG(hw, E1000_STATUS); 4878 if (((status & E1000_STATUS_LU) == 0) || 4879 (hw->phy.media_type == 4880 e1000_media_type_internal_serdes)) { 4881 ctrl = E1000_READ_REG(hw, E1000_CTRL); 4882 ctrl |= E1000_CTRL_ILOS | E1000_CTRL_SLU; 4883 E1000_WRITE_REG(hw, E1000_CTRL, ctrl); 4884 } 4885 4886 /* Disable autoneg by setting bit 31 of TXCW to zero */ 4887 txcw = E1000_READ_REG(hw, E1000_TXCW); 4888 txcw &= ~((uint32_t)1 << 31); 4889 E1000_WRITE_REG(hw, E1000_TXCW, txcw); 4890 4891 /* 4892 * Write 0x410 to Serdes Control register 4893 * to enable Serdes analog loopback 4894 */ 4895 E1000_WRITE_REG(hw, E1000_SCTL, 0x0410); 4896 msec_delay(10); 4897 break; 4898 default: 4899 break; 4900 } 4901 break; 4902 case e1000_80003es2lan: 4903 (void) e1000_read_phy_reg(hw, GG82563_REG(6, 16), &phydata); 4904 (void) e1000_write_phy_reg(hw, GG82563_REG(6, 16), 4905 phydata | (1 << 5)); 4906 Adapter->param_adv_autoneg = 1; 4907 Adapter->param_adv_1000fdx = 1; 4908 (void) e1000g_reset_link(Adapter); 4909 break; 4910 } 4911 } 4912 4913 static void 4914 e1000g_set_external_loopback_100(struct e1000g *Adapter) 4915 { 4916 struct e1000_hw *hw; 4917 uint32_t ctrl; 4918 uint16_t phy_ctrl; 4919 4920 hw = &Adapter->shared; 4921 4922 /* Disable Smart Power Down */ 4923 phy_spd_state(hw, B_FALSE); 4924 4925 phy_ctrl = (MII_CR_FULL_DUPLEX | 4926 MII_CR_SPEED_100); 4927 4928 /* Force 100/FD, reset PHY */ 4929 (void) e1000_write_phy_reg(hw, PHY_CONTROL, 4930 phy_ctrl | MII_CR_RESET); /* 0xA100 */ 4931 msec_delay(10); 4932 4933 /* Force 100/FD */ 4934 (void) e1000_write_phy_reg(hw, PHY_CONTROL, 4935 phy_ctrl); /* 0x2100 */ 4936 msec_delay(10); 4937 4938 /* Now setup the MAC to the same speed/duplex as the PHY. */ 4939 ctrl = E1000_READ_REG(hw, E1000_CTRL); 4940 ctrl &= ~E1000_CTRL_SPD_SEL; /* Clear the speed sel bits */ 4941 ctrl |= (E1000_CTRL_SLU | /* Force Link Up */ 4942 E1000_CTRL_FRCSPD | /* Set the Force Speed Bit */ 4943 E1000_CTRL_FRCDPX | /* Set the Force Duplex Bit */ 4944 E1000_CTRL_SPD_100 | /* Force Speed to 100 */ 4945 E1000_CTRL_FD); /* Force Duplex to FULL */ 4946 4947 E1000_WRITE_REG(hw, E1000_CTRL, ctrl); 4948 } 4949 4950 static void 4951 e1000g_set_external_loopback_10(struct e1000g *Adapter) 4952 { 4953 struct e1000_hw *hw; 4954 uint32_t ctrl; 4955 uint16_t phy_ctrl; 4956 4957 hw = &Adapter->shared; 4958 4959 /* Disable Smart Power Down */ 4960 phy_spd_state(hw, B_FALSE); 4961 4962 phy_ctrl = (MII_CR_FULL_DUPLEX | 4963 MII_CR_SPEED_10); 4964 4965 /* Force 10/FD, reset PHY */ 4966 (void) e1000_write_phy_reg(hw, PHY_CONTROL, 4967 phy_ctrl | MII_CR_RESET); /* 0x8100 */ 4968 msec_delay(10); 4969 4970 /* Force 10/FD */ 4971 (void) e1000_write_phy_reg(hw, PHY_CONTROL, 4972 phy_ctrl); /* 0x0100 */ 4973 msec_delay(10); 4974 4975 /* Now setup the MAC to the same speed/duplex as the PHY. */ 4976 ctrl = E1000_READ_REG(hw, E1000_CTRL); 4977 ctrl &= ~E1000_CTRL_SPD_SEL; /* Clear the speed sel bits */ 4978 ctrl |= (E1000_CTRL_SLU | /* Force Link Up */ 4979 E1000_CTRL_FRCSPD | /* Set the Force Speed Bit */ 4980 E1000_CTRL_FRCDPX | /* Set the Force Duplex Bit */ 4981 E1000_CTRL_SPD_10 | /* Force Speed to 10 */ 4982 E1000_CTRL_FD); /* Force Duplex to FULL */ 4983 4984 E1000_WRITE_REG(hw, E1000_CTRL, ctrl); 4985 } 4986 4987 #ifdef __sparc 4988 static boolean_t 4989 e1000g_find_mac_address(struct e1000g *Adapter) 4990 { 4991 struct e1000_hw *hw = &Adapter->shared; 4992 uchar_t *bytes; 4993 struct ether_addr sysaddr; 4994 uint_t nelts; 4995 int err; 4996 boolean_t found = B_FALSE; 4997 4998 /* 4999 * The "vendor's factory-set address" may already have 5000 * been extracted from the chip, but if the property 5001 * "local-mac-address" is set we use that instead. 5002 * 5003 * We check whether it looks like an array of 6 5004 * bytes (which it should, if OBP set it). If we can't 5005 * make sense of it this way, we'll ignore it. 5006 */ 5007 err = ddi_prop_lookup_byte_array(DDI_DEV_T_ANY, Adapter->dip, 5008 DDI_PROP_DONTPASS, "local-mac-address", &bytes, &nelts); 5009 if (err == DDI_PROP_SUCCESS) { 5010 if (nelts == ETHERADDRL) { 5011 while (nelts--) 5012 hw->mac.addr[nelts] = bytes[nelts]; 5013 found = B_TRUE; 5014 } 5015 ddi_prop_free(bytes); 5016 } 5017 5018 /* 5019 * Look up the OBP property "local-mac-address?". If the user has set 5020 * 'local-mac-address? = false', use "the system address" instead. 5021 */ 5022 if (ddi_prop_lookup_byte_array(DDI_DEV_T_ANY, Adapter->dip, 0, 5023 "local-mac-address?", &bytes, &nelts) == DDI_PROP_SUCCESS) { 5024 if (strncmp("false", (caddr_t)bytes, (size_t)nelts) == 0) { 5025 if (localetheraddr(NULL, &sysaddr) != 0) { 5026 bcopy(&sysaddr, hw->mac.addr, ETHERADDRL); 5027 found = B_TRUE; 5028 } 5029 } 5030 ddi_prop_free(bytes); 5031 } 5032 5033 /* 5034 * Finally(!), if there's a valid "mac-address" property (created 5035 * if we netbooted from this interface), we must use this instead 5036 * of any of the above to ensure that the NFS/install server doesn't 5037 * get confused by the address changing as Solaris takes over! 5038 */ 5039 err = ddi_prop_lookup_byte_array(DDI_DEV_T_ANY, Adapter->dip, 5040 DDI_PROP_DONTPASS, "mac-address", &bytes, &nelts); 5041 if (err == DDI_PROP_SUCCESS) { 5042 if (nelts == ETHERADDRL) { 5043 while (nelts--) 5044 hw->mac.addr[nelts] = bytes[nelts]; 5045 found = B_TRUE; 5046 } 5047 ddi_prop_free(bytes); 5048 } 5049 5050 if (found) { 5051 bcopy(hw->mac.addr, hw->mac.perm_addr, 5052 ETHERADDRL); 5053 } 5054 5055 return (found); 5056 } 5057 #endif 5058 5059 static int 5060 e1000g_add_intrs(struct e1000g *Adapter) 5061 { 5062 dev_info_t *devinfo; 5063 int intr_types; 5064 int rc; 5065 5066 devinfo = Adapter->dip; 5067 5068 /* Get supported interrupt types */ 5069 rc = ddi_intr_get_supported_types(devinfo, &intr_types); 5070 5071 if (rc != DDI_SUCCESS) { 5072 E1000G_DEBUGLOG_1(Adapter, E1000G_WARN_LEVEL, 5073 "Get supported interrupt types failed: %d\n", rc); 5074 return (DDI_FAILURE); 5075 } 5076 5077 /* 5078 * Based on Intel Technical Advisory document (TA-160), there are some 5079 * cases where some older Intel PCI-X NICs may "advertise" to the OS 5080 * that it supports MSI, but in fact has problems. 5081 * So we should only enable MSI for PCI-E NICs and disable MSI for old 5082 * PCI/PCI-X NICs. 5083 */ 5084 if (Adapter->shared.mac.type < e1000_82571) 5085 Adapter->msi_enable = B_FALSE; 5086 5087 if ((intr_types & DDI_INTR_TYPE_MSI) && Adapter->msi_enable) { 5088 rc = e1000g_intr_add(Adapter, DDI_INTR_TYPE_MSI); 5089 5090 if (rc != DDI_SUCCESS) { 5091 E1000G_DEBUGLOG_0(Adapter, E1000G_WARN_LEVEL, 5092 "Add MSI failed, trying Legacy interrupts\n"); 5093 } else { 5094 Adapter->intr_type = DDI_INTR_TYPE_MSI; 5095 } 5096 } 5097 5098 if ((Adapter->intr_type == 0) && 5099 (intr_types & DDI_INTR_TYPE_FIXED)) { 5100 rc = e1000g_intr_add(Adapter, DDI_INTR_TYPE_FIXED); 5101 5102 if (rc != DDI_SUCCESS) { 5103 E1000G_DEBUGLOG_0(Adapter, E1000G_WARN_LEVEL, 5104 "Add Legacy interrupts failed\n"); 5105 return (DDI_FAILURE); 5106 } 5107 5108 Adapter->intr_type = DDI_INTR_TYPE_FIXED; 5109 } 5110 5111 if (Adapter->intr_type == 0) { 5112 E1000G_DEBUGLOG_0(Adapter, E1000G_WARN_LEVEL, 5113 "No interrupts registered\n"); 5114 return (DDI_FAILURE); 5115 } 5116 5117 return (DDI_SUCCESS); 5118 } 5119 5120 /* 5121 * e1000g_intr_add() handles MSI/Legacy interrupts 5122 */ 5123 static int 5124 e1000g_intr_add(struct e1000g *Adapter, int intr_type) 5125 { 5126 dev_info_t *devinfo; 5127 int count, avail, actual; 5128 int x, y, rc, inum = 0; 5129 int flag; 5130 ddi_intr_handler_t *intr_handler; 5131 5132 devinfo = Adapter->dip; 5133 5134 /* get number of interrupts */ 5135 rc = ddi_intr_get_nintrs(devinfo, intr_type, &count); 5136 if ((rc != DDI_SUCCESS) || (count == 0)) { 5137 E1000G_DEBUGLOG_2(Adapter, E1000G_WARN_LEVEL, 5138 "Get interrupt number failed. Return: %d, count: %d\n", 5139 rc, count); 5140 return (DDI_FAILURE); 5141 } 5142 5143 /* get number of available interrupts */ 5144 rc = ddi_intr_get_navail(devinfo, intr_type, &avail); 5145 if ((rc != DDI_SUCCESS) || (avail == 0)) { 5146 E1000G_DEBUGLOG_2(Adapter, E1000G_WARN_LEVEL, 5147 "Get interrupt available number failed. " 5148 "Return: %d, available: %d\n", rc, avail); 5149 return (DDI_FAILURE); 5150 } 5151 5152 if (avail < count) { 5153 E1000G_DEBUGLOG_2(Adapter, E1000G_WARN_LEVEL, 5154 "Interrupts count: %d, available: %d\n", 5155 count, avail); 5156 } 5157 5158 /* Allocate an array of interrupt handles */ 5159 Adapter->intr_size = count * sizeof (ddi_intr_handle_t); 5160 Adapter->htable = kmem_alloc(Adapter->intr_size, KM_SLEEP); 5161 5162 /* Set NORMAL behavior for both MSI and FIXED interrupt */ 5163 flag = DDI_INTR_ALLOC_NORMAL; 5164 5165 /* call ddi_intr_alloc() */ 5166 rc = ddi_intr_alloc(devinfo, Adapter->htable, intr_type, inum, 5167 count, &actual, flag); 5168 5169 if ((rc != DDI_SUCCESS) || (actual == 0)) { 5170 E1000G_DEBUGLOG_1(Adapter, E1000G_WARN_LEVEL, 5171 "Allocate interrupts failed: %d\n", rc); 5172 5173 kmem_free(Adapter->htable, Adapter->intr_size); 5174 return (DDI_FAILURE); 5175 } 5176 5177 if (actual < count) { 5178 E1000G_DEBUGLOG_2(Adapter, E1000G_WARN_LEVEL, 5179 "Interrupts requested: %d, received: %d\n", 5180 count, actual); 5181 } 5182 5183 Adapter->intr_cnt = actual; 5184 5185 /* Get priority for first msi, assume remaining are all the same */ 5186 rc = ddi_intr_get_pri(Adapter->htable[0], &Adapter->intr_pri); 5187 5188 if (rc != DDI_SUCCESS) { 5189 E1000G_DEBUGLOG_1(Adapter, E1000G_WARN_LEVEL, 5190 "Get interrupt priority failed: %d\n", rc); 5191 5192 /* Free already allocated intr */ 5193 for (y = 0; y < actual; y++) 5194 (void) ddi_intr_free(Adapter->htable[y]); 5195 5196 kmem_free(Adapter->htable, Adapter->intr_size); 5197 return (DDI_FAILURE); 5198 } 5199 5200 /* 5201 * In Legacy Interrupt mode, for PCI-Express adapters, we should 5202 * use the interrupt service routine e1000g_intr_pciexpress() 5203 * to avoid interrupt stealing when sharing interrupt with other 5204 * devices. 5205 */ 5206 if (Adapter->shared.mac.type < e1000_82571) 5207 intr_handler = (ddi_intr_handler_t *)e1000g_intr; 5208 else 5209 intr_handler = (ddi_intr_handler_t *)e1000g_intr_pciexpress; 5210 5211 /* Call ddi_intr_add_handler() */ 5212 for (x = 0; x < actual; x++) { 5213 rc = ddi_intr_add_handler(Adapter->htable[x], 5214 intr_handler, (caddr_t)Adapter, NULL); 5215 5216 if (rc != DDI_SUCCESS) { 5217 E1000G_DEBUGLOG_1(Adapter, E1000G_WARN_LEVEL, 5218 "Add interrupt handler failed: %d\n", rc); 5219 5220 /* Remove already added handler */ 5221 for (y = 0; y < x; y++) 5222 (void) ddi_intr_remove_handler( 5223 Adapter->htable[y]); 5224 5225 /* Free already allocated intr */ 5226 for (y = 0; y < actual; y++) 5227 (void) ddi_intr_free(Adapter->htable[y]); 5228 5229 kmem_free(Adapter->htable, Adapter->intr_size); 5230 return (DDI_FAILURE); 5231 } 5232 } 5233 5234 rc = ddi_intr_get_cap(Adapter->htable[0], &Adapter->intr_cap); 5235 5236 if (rc != DDI_SUCCESS) { 5237 E1000G_DEBUGLOG_1(Adapter, E1000G_WARN_LEVEL, 5238 "Get interrupt cap failed: %d\n", rc); 5239 5240 /* Free already allocated intr */ 5241 for (y = 0; y < actual; y++) { 5242 (void) ddi_intr_remove_handler(Adapter->htable[y]); 5243 (void) ddi_intr_free(Adapter->htable[y]); 5244 } 5245 5246 kmem_free(Adapter->htable, Adapter->intr_size); 5247 return (DDI_FAILURE); 5248 } 5249 5250 return (DDI_SUCCESS); 5251 } 5252 5253 static int 5254 e1000g_rem_intrs(struct e1000g *Adapter) 5255 { 5256 int x; 5257 int rc; 5258 5259 for (x = 0; x < Adapter->intr_cnt; x++) { 5260 rc = ddi_intr_remove_handler(Adapter->htable[x]); 5261 if (rc != DDI_SUCCESS) { 5262 E1000G_DEBUGLOG_1(Adapter, E1000G_WARN_LEVEL, 5263 "Remove intr handler failed: %d\n", rc); 5264 return (DDI_FAILURE); 5265 } 5266 5267 rc = ddi_intr_free(Adapter->htable[x]); 5268 if (rc != DDI_SUCCESS) { 5269 E1000G_DEBUGLOG_1(Adapter, E1000G_WARN_LEVEL, 5270 "Free intr failed: %d\n", rc); 5271 return (DDI_FAILURE); 5272 } 5273 } 5274 5275 kmem_free(Adapter->htable, Adapter->intr_size); 5276 5277 return (DDI_SUCCESS); 5278 } 5279 5280 static int 5281 e1000g_enable_intrs(struct e1000g *Adapter) 5282 { 5283 int x; 5284 int rc; 5285 5286 /* Enable interrupts */ 5287 if (Adapter->intr_cap & DDI_INTR_FLAG_BLOCK) { 5288 /* Call ddi_intr_block_enable() for MSI */ 5289 rc = ddi_intr_block_enable(Adapter->htable, 5290 Adapter->intr_cnt); 5291 if (rc != DDI_SUCCESS) { 5292 E1000G_DEBUGLOG_1(Adapter, E1000G_WARN_LEVEL, 5293 "Enable block intr failed: %d\n", rc); 5294 return (DDI_FAILURE); 5295 } 5296 } else { 5297 /* Call ddi_intr_enable() for Legacy/MSI non block enable */ 5298 for (x = 0; x < Adapter->intr_cnt; x++) { 5299 rc = ddi_intr_enable(Adapter->htable[x]); 5300 if (rc != DDI_SUCCESS) { 5301 E1000G_DEBUGLOG_1(Adapter, E1000G_WARN_LEVEL, 5302 "Enable intr failed: %d\n", rc); 5303 return (DDI_FAILURE); 5304 } 5305 } 5306 } 5307 5308 return (DDI_SUCCESS); 5309 } 5310 5311 static int 5312 e1000g_disable_intrs(struct e1000g *Adapter) 5313 { 5314 int x; 5315 int rc; 5316 5317 /* Disable all interrupts */ 5318 if (Adapter->intr_cap & DDI_INTR_FLAG_BLOCK) { 5319 rc = ddi_intr_block_disable(Adapter->htable, 5320 Adapter->intr_cnt); 5321 if (rc != DDI_SUCCESS) { 5322 E1000G_DEBUGLOG_1(Adapter, E1000G_WARN_LEVEL, 5323 "Disable block intr failed: %d\n", rc); 5324 return (DDI_FAILURE); 5325 } 5326 } else { 5327 for (x = 0; x < Adapter->intr_cnt; x++) { 5328 rc = ddi_intr_disable(Adapter->htable[x]); 5329 if (rc != DDI_SUCCESS) { 5330 E1000G_DEBUGLOG_1(Adapter, E1000G_WARN_LEVEL, 5331 "Disable intr failed: %d\n", rc); 5332 return (DDI_FAILURE); 5333 } 5334 } 5335 } 5336 5337 return (DDI_SUCCESS); 5338 } 5339 5340 /* 5341 * e1000g_get_phy_state - get the state of PHY registers, save in the adapter 5342 */ 5343 static void 5344 e1000g_get_phy_state(struct e1000g *Adapter) 5345 { 5346 struct e1000_hw *hw = &Adapter->shared; 5347 5348 (void) e1000_read_phy_reg(hw, PHY_CONTROL, &Adapter->phy_ctrl); 5349 (void) e1000_read_phy_reg(hw, PHY_STATUS, &Adapter->phy_status); 5350 (void) e1000_read_phy_reg(hw, PHY_AUTONEG_ADV, &Adapter->phy_an_adv); 5351 (void) e1000_read_phy_reg(hw, PHY_AUTONEG_EXP, &Adapter->phy_an_exp); 5352 (void) e1000_read_phy_reg(hw, PHY_EXT_STATUS, &Adapter->phy_ext_status); 5353 (void) e1000_read_phy_reg(hw, PHY_1000T_CTRL, &Adapter->phy_1000t_ctrl); 5354 (void) e1000_read_phy_reg(hw, PHY_1000T_STATUS, 5355 &Adapter->phy_1000t_status); 5356 (void) e1000_read_phy_reg(hw, PHY_LP_ABILITY, &Adapter->phy_lp_able); 5357 5358 Adapter->param_autoneg_cap = 5359 (Adapter->phy_status & MII_SR_AUTONEG_CAPS) ? 1 : 0; 5360 Adapter->param_pause_cap = 5361 (Adapter->phy_an_adv & NWAY_AR_PAUSE) ? 1 : 0; 5362 Adapter->param_asym_pause_cap = 5363 (Adapter->phy_an_adv & NWAY_AR_ASM_DIR) ? 1 : 0; 5364 Adapter->param_1000fdx_cap = 5365 ((Adapter->phy_ext_status & IEEE_ESR_1000T_FD_CAPS) || 5366 (Adapter->phy_ext_status & IEEE_ESR_1000X_FD_CAPS)) ? 1 : 0; 5367 Adapter->param_1000hdx_cap = 5368 ((Adapter->phy_ext_status & IEEE_ESR_1000T_HD_CAPS) || 5369 (Adapter->phy_ext_status & IEEE_ESR_1000X_HD_CAPS)) ? 1 : 0; 5370 Adapter->param_100t4_cap = 5371 (Adapter->phy_status & MII_SR_100T4_CAPS) ? 1 : 0; 5372 Adapter->param_100fdx_cap = 5373 ((Adapter->phy_status & MII_SR_100X_FD_CAPS) || 5374 (Adapter->phy_status & MII_SR_100T2_FD_CAPS)) ? 1 : 0; 5375 Adapter->param_100hdx_cap = 5376 ((Adapter->phy_status & MII_SR_100X_HD_CAPS) || 5377 (Adapter->phy_status & MII_SR_100T2_HD_CAPS)) ? 1 : 0; 5378 Adapter->param_10fdx_cap = 5379 (Adapter->phy_status & MII_SR_10T_FD_CAPS) ? 1 : 0; 5380 Adapter->param_10hdx_cap = 5381 (Adapter->phy_status & MII_SR_10T_HD_CAPS) ? 1 : 0; 5382 5383 Adapter->param_adv_autoneg = hw->mac.autoneg; 5384 Adapter->param_adv_pause = 5385 (Adapter->phy_an_adv & NWAY_AR_PAUSE) ? 1 : 0; 5386 Adapter->param_adv_asym_pause = 5387 (Adapter->phy_an_adv & NWAY_AR_ASM_DIR) ? 1 : 0; 5388 Adapter->param_adv_1000hdx = 5389 (Adapter->phy_1000t_ctrl & CR_1000T_HD_CAPS) ? 1 : 0; 5390 Adapter->param_adv_100t4 = 5391 (Adapter->phy_an_adv & NWAY_AR_100T4_CAPS) ? 1 : 0; 5392 if (Adapter->param_adv_autoneg == 1) { 5393 Adapter->param_adv_1000fdx = 5394 (Adapter->phy_1000t_ctrl & CR_1000T_FD_CAPS) ? 1 : 0; 5395 Adapter->param_adv_100fdx = 5396 (Adapter->phy_an_adv & NWAY_AR_100TX_FD_CAPS) ? 1 : 0; 5397 Adapter->param_adv_100hdx = 5398 (Adapter->phy_an_adv & NWAY_AR_100TX_HD_CAPS) ? 1 : 0; 5399 Adapter->param_adv_10fdx = 5400 (Adapter->phy_an_adv & NWAY_AR_10T_FD_CAPS) ? 1 : 0; 5401 Adapter->param_adv_10hdx = 5402 (Adapter->phy_an_adv & NWAY_AR_10T_HD_CAPS) ? 1 : 0; 5403 } 5404 5405 Adapter->param_lp_autoneg = 5406 (Adapter->phy_an_exp & NWAY_ER_LP_NWAY_CAPS) ? 1 : 0; 5407 Adapter->param_lp_pause = 5408 (Adapter->phy_lp_able & NWAY_LPAR_PAUSE) ? 1 : 0; 5409 Adapter->param_lp_asym_pause = 5410 (Adapter->phy_lp_able & NWAY_LPAR_ASM_DIR) ? 1 : 0; 5411 Adapter->param_lp_1000fdx = 5412 (Adapter->phy_1000t_status & SR_1000T_LP_FD_CAPS) ? 1 : 0; 5413 Adapter->param_lp_1000hdx = 5414 (Adapter->phy_1000t_status & SR_1000T_LP_HD_CAPS) ? 1 : 0; 5415 Adapter->param_lp_100t4 = 5416 (Adapter->phy_lp_able & NWAY_LPAR_100T4_CAPS) ? 1 : 0; 5417 Adapter->param_lp_100fdx = 5418 (Adapter->phy_lp_able & NWAY_LPAR_100TX_FD_CAPS) ? 1 : 0; 5419 Adapter->param_lp_100hdx = 5420 (Adapter->phy_lp_able & NWAY_LPAR_100TX_HD_CAPS) ? 1 : 0; 5421 Adapter->param_lp_10fdx = 5422 (Adapter->phy_lp_able & NWAY_LPAR_10T_FD_CAPS) ? 1 : 0; 5423 Adapter->param_lp_10hdx = 5424 (Adapter->phy_lp_able & NWAY_LPAR_10T_HD_CAPS) ? 1 : 0; 5425 } 5426 5427 /* 5428 * FMA support 5429 */ 5430 5431 int 5432 e1000g_check_acc_handle(ddi_acc_handle_t handle) 5433 { 5434 ddi_fm_error_t de; 5435 5436 ddi_fm_acc_err_get(handle, &de, DDI_FME_VERSION); 5437 ddi_fm_acc_err_clear(handle, DDI_FME_VERSION); 5438 return (de.fme_status); 5439 } 5440 5441 int 5442 e1000g_check_dma_handle(ddi_dma_handle_t handle) 5443 { 5444 ddi_fm_error_t de; 5445 5446 ddi_fm_dma_err_get(handle, &de, DDI_FME_VERSION); 5447 return (de.fme_status); 5448 } 5449 5450 /* 5451 * The IO fault service error handling callback function 5452 */ 5453 /* ARGSUSED2 */ 5454 static int 5455 e1000g_fm_error_cb(dev_info_t *dip, ddi_fm_error_t *err, const void *impl_data) 5456 { 5457 /* 5458 * as the driver can always deal with an error in any dma or 5459 * access handle, we can just return the fme_status value. 5460 */ 5461 pci_ereport_post(dip, err, NULL); 5462 return (err->fme_status); 5463 } 5464 5465 static void 5466 e1000g_fm_init(struct e1000g *Adapter) 5467 { 5468 ddi_iblock_cookie_t iblk; 5469 int fma_acc_flag, fma_dma_flag; 5470 5471 /* Only register with IO Fault Services if we have some capability */ 5472 if (Adapter->fm_capabilities & DDI_FM_ACCCHK_CAPABLE) { 5473 e1000g_regs_acc_attr.devacc_attr_access = DDI_FLAGERR_ACC; 5474 fma_acc_flag = 1; 5475 } else { 5476 e1000g_regs_acc_attr.devacc_attr_access = DDI_DEFAULT_ACC; 5477 fma_acc_flag = 0; 5478 } 5479 5480 if (Adapter->fm_capabilities & DDI_FM_DMACHK_CAPABLE) { 5481 fma_dma_flag = 1; 5482 } else { 5483 fma_dma_flag = 0; 5484 } 5485 5486 (void) e1000g_set_fma_flags(Adapter, fma_acc_flag, fma_dma_flag); 5487 5488 if (Adapter->fm_capabilities) { 5489 5490 /* Register capabilities with IO Fault Services */ 5491 ddi_fm_init(Adapter->dip, &Adapter->fm_capabilities, &iblk); 5492 5493 /* 5494 * Initialize pci ereport capabilities if ereport capable 5495 */ 5496 if (DDI_FM_EREPORT_CAP(Adapter->fm_capabilities) || 5497 DDI_FM_ERRCB_CAP(Adapter->fm_capabilities)) 5498 pci_ereport_setup(Adapter->dip); 5499 5500 /* 5501 * Register error callback if error callback capable 5502 */ 5503 if (DDI_FM_ERRCB_CAP(Adapter->fm_capabilities)) 5504 ddi_fm_handler_register(Adapter->dip, 5505 e1000g_fm_error_cb, (void*) Adapter); 5506 } 5507 } 5508 5509 static void 5510 e1000g_fm_fini(struct e1000g *Adapter) 5511 { 5512 /* Only unregister FMA capabilities if we registered some */ 5513 if (Adapter->fm_capabilities) { 5514 5515 /* 5516 * Release any resources allocated by pci_ereport_setup() 5517 */ 5518 if (DDI_FM_EREPORT_CAP(Adapter->fm_capabilities) || 5519 DDI_FM_ERRCB_CAP(Adapter->fm_capabilities)) 5520 pci_ereport_teardown(Adapter->dip); 5521 5522 /* 5523 * Un-register error callback if error callback capable 5524 */ 5525 if (DDI_FM_ERRCB_CAP(Adapter->fm_capabilities)) 5526 ddi_fm_handler_unregister(Adapter->dip); 5527 5528 /* Unregister from IO Fault Services */ 5529 ddi_fm_fini(Adapter->dip); 5530 } 5531 } 5532 5533 void 5534 e1000g_fm_ereport(struct e1000g *Adapter, char *detail) 5535 { 5536 uint64_t ena; 5537 char buf[FM_MAX_CLASS]; 5538 5539 (void) snprintf(buf, FM_MAX_CLASS, "%s.%s", DDI_FM_DEVICE, detail); 5540 ena = fm_ena_generate(0, FM_ENA_FMT1); 5541 if (DDI_FM_EREPORT_CAP(Adapter->fm_capabilities)) { 5542 ddi_fm_ereport_post(Adapter->dip, buf, ena, DDI_NOSLEEP, 5543 FM_VERSION, DATA_TYPE_UINT8, FM_EREPORT_VERS0, NULL); 5544 } 5545 } 5546 5547 /* 5548 * quiesce(9E) entry point. 5549 * 5550 * This function is called when the system is single-threaded at high 5551 * PIL with preemption disabled. Therefore, this function must not be 5552 * blocked. 5553 * 5554 * This function returns DDI_SUCCESS on success, or DDI_FAILURE on failure. 5555 * DDI_FAILURE indicates an error condition and should almost never happen. 5556 */ 5557 static int 5558 e1000g_quiesce(dev_info_t *devinfo) 5559 { 5560 struct e1000g *Adapter; 5561 5562 Adapter = (struct e1000g *)ddi_get_driver_private(devinfo); 5563 5564 if (Adapter == NULL) 5565 return (DDI_FAILURE); 5566 5567 e1000g_clear_all_interrupts(Adapter); 5568 5569 (void) e1000_reset_hw(&Adapter->shared); 5570 5571 /* Setup our HW Tx Head & Tail descriptor pointers */ 5572 E1000_WRITE_REG(&Adapter->shared, E1000_TDH(0), 0); 5573 E1000_WRITE_REG(&Adapter->shared, E1000_TDT(0), 0); 5574 5575 /* Setup our HW Rx Head & Tail descriptor pointers */ 5576 E1000_WRITE_REG(&Adapter->shared, E1000_RDH(0), 0); 5577 E1000_WRITE_REG(&Adapter->shared, E1000_RDT(0), 0); 5578 5579 return (DDI_SUCCESS); 5580 } 5581 5582 static int 5583 e1000g_get_def_val(struct e1000g *Adapter, mac_prop_id_t pr_num, 5584 uint_t pr_valsize, void *pr_val) 5585 { 5586 link_flowctrl_t fl; 5587 int err = 0; 5588 5589 ASSERT(pr_valsize > 0); 5590 switch (pr_num) { 5591 case MAC_PROP_AUTONEG: 5592 *(uint8_t *)pr_val = 5593 ((Adapter->phy_status & MII_SR_AUTONEG_CAPS) ? 1 : 0); 5594 break; 5595 case MAC_PROP_FLOWCTRL: 5596 if (pr_valsize < sizeof (link_flowctrl_t)) 5597 return (EINVAL); 5598 fl = LINK_FLOWCTRL_BI; 5599 bcopy(&fl, pr_val, sizeof (fl)); 5600 break; 5601 case MAC_PROP_ADV_1000FDX_CAP: 5602 case MAC_PROP_EN_1000FDX_CAP: 5603 *(uint8_t *)pr_val = 5604 ((Adapter->phy_ext_status & IEEE_ESR_1000T_FD_CAPS) || 5605 (Adapter->phy_ext_status & IEEE_ESR_1000X_FD_CAPS)) ? 1 : 0; 5606 break; 5607 case MAC_PROP_ADV_1000HDX_CAP: 5608 case MAC_PROP_EN_1000HDX_CAP: 5609 *(uint8_t *)pr_val = 5610 ((Adapter->phy_ext_status & IEEE_ESR_1000T_HD_CAPS) || 5611 (Adapter->phy_ext_status & IEEE_ESR_1000X_HD_CAPS)) ? 1 : 0; 5612 break; 5613 case MAC_PROP_ADV_100FDX_CAP: 5614 case MAC_PROP_EN_100FDX_CAP: 5615 *(uint8_t *)pr_val = 5616 ((Adapter->phy_status & MII_SR_100X_FD_CAPS) || 5617 (Adapter->phy_status & MII_SR_100T2_FD_CAPS)) ? 1 : 0; 5618 break; 5619 case MAC_PROP_ADV_100HDX_CAP: 5620 case MAC_PROP_EN_100HDX_CAP: 5621 *(uint8_t *)pr_val = 5622 ((Adapter->phy_status & MII_SR_100X_HD_CAPS) || 5623 (Adapter->phy_status & MII_SR_100T2_HD_CAPS)) ? 1 : 0; 5624 break; 5625 case MAC_PROP_ADV_10FDX_CAP: 5626 case MAC_PROP_EN_10FDX_CAP: 5627 *(uint8_t *)pr_val = 5628 (Adapter->phy_status & MII_SR_10T_FD_CAPS) ? 1 : 0; 5629 break; 5630 case MAC_PROP_ADV_10HDX_CAP: 5631 case MAC_PROP_EN_10HDX_CAP: 5632 *(uint8_t *)pr_val = 5633 (Adapter->phy_status & MII_SR_10T_HD_CAPS) ? 1 : 0; 5634 break; 5635 default: 5636 err = ENOTSUP; 5637 break; 5638 } 5639 return (err); 5640 } 5641 5642 /* 5643 * synchronize the adv* and en* parameters. 5644 * 5645 * See comments in <sys/dld.h> for details of the *_en_* 5646 * parameters. The usage of ndd for setting adv parameters will 5647 * synchronize all the en parameters with the e1000g parameters, 5648 * implicitly disabling any settings made via dladm. 5649 */ 5650 static void 5651 e1000g_param_sync(struct e1000g *Adapter) 5652 { 5653 Adapter->param_en_1000fdx = Adapter->param_adv_1000fdx; 5654 Adapter->param_en_1000hdx = Adapter->param_adv_1000hdx; 5655 Adapter->param_en_100fdx = Adapter->param_adv_100fdx; 5656 Adapter->param_en_100hdx = Adapter->param_adv_100hdx; 5657 Adapter->param_en_10fdx = Adapter->param_adv_10fdx; 5658 Adapter->param_en_10hdx = Adapter->param_adv_10hdx; 5659 } 5660 5661 /* 5662 * e1000g_get_driver_control - tell manageability firmware that the driver 5663 * has control. 5664 */ 5665 static void 5666 e1000g_get_driver_control(struct e1000_hw *hw) 5667 { 5668 uint32_t ctrl_ext; 5669 uint32_t swsm; 5670 5671 /* tell manageability firmware the driver has taken over */ 5672 switch (hw->mac.type) { 5673 case e1000_82573: 5674 swsm = E1000_READ_REG(hw, E1000_SWSM); 5675 E1000_WRITE_REG(hw, E1000_SWSM, swsm | E1000_SWSM_DRV_LOAD); 5676 break; 5677 case e1000_82571: 5678 case e1000_82572: 5679 case e1000_82574: 5680 case e1000_80003es2lan: 5681 case e1000_ich8lan: 5682 case e1000_ich9lan: 5683 case e1000_ich10lan: 5684 ctrl_ext = E1000_READ_REG(hw, E1000_CTRL_EXT); 5685 E1000_WRITE_REG(hw, E1000_CTRL_EXT, 5686 ctrl_ext | E1000_CTRL_EXT_DRV_LOAD); 5687 break; 5688 default: 5689 /* no manageability firmware: do nothing */ 5690 break; 5691 } 5692 } 5693 5694 /* 5695 * e1000g_release_driver_control - tell manageability firmware that the driver 5696 * has released control. 5697 */ 5698 static void 5699 e1000g_release_driver_control(struct e1000_hw *hw) 5700 { 5701 uint32_t ctrl_ext; 5702 uint32_t swsm; 5703 5704 /* tell manageability firmware the driver has released control */ 5705 switch (hw->mac.type) { 5706 case e1000_82573: 5707 swsm = E1000_READ_REG(hw, E1000_SWSM); 5708 E1000_WRITE_REG(hw, E1000_SWSM, swsm & ~E1000_SWSM_DRV_LOAD); 5709 break; 5710 case e1000_82571: 5711 case e1000_82572: 5712 case e1000_82574: 5713 case e1000_80003es2lan: 5714 case e1000_ich8lan: 5715 case e1000_ich9lan: 5716 case e1000_ich10lan: 5717 ctrl_ext = E1000_READ_REG(hw, E1000_CTRL_EXT); 5718 E1000_WRITE_REG(hw, E1000_CTRL_EXT, 5719 ctrl_ext & ~E1000_CTRL_EXT_DRV_LOAD); 5720 break; 5721 default: 5722 /* no manageability firmware: do nothing */ 5723 break; 5724 } 5725 } 5726 5727 /* 5728 * Restore e1000g promiscuous mode. 5729 */ 5730 static void 5731 e1000g_restore_promisc(struct e1000g *Adapter) 5732 { 5733 if (Adapter->e1000g_promisc) { 5734 uint32_t rctl; 5735 5736 rctl = E1000_READ_REG(&Adapter->shared, E1000_RCTL); 5737 rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE | E1000_RCTL_BAM); 5738 E1000_WRITE_REG(&Adapter->shared, E1000_RCTL, rctl); 5739 } 5740 } 5741