13859Sml29623 /* 23859Sml29623 * CDDL HEADER START 33859Sml29623 * 43859Sml29623 * The contents of this file are subject to the terms of the 53859Sml29623 * Common Development and Distribution License (the "License"). 63859Sml29623 * You may not use this file except in compliance with the License. 73859Sml29623 * 83859Sml29623 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 93859Sml29623 * or http://www.opensolaris.org/os/licensing. 103859Sml29623 * See the License for the specific language governing permissions 113859Sml29623 * and limitations under the License. 123859Sml29623 * 133859Sml29623 * When distributing Covered Code, include this CDDL HEADER in each 143859Sml29623 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 153859Sml29623 * If applicable, add the following below this CDDL HEADER, with the 163859Sml29623 * fields enclosed by brackets "[]" replaced with your own identifying 173859Sml29623 * information: Portions Copyright [yyyy] [name of copyright owner] 183859Sml29623 * 193859Sml29623 * CDDL HEADER END 203859Sml29623 */ 21*7812SMichael.Speer@Sun.COM 223859Sml29623 /* 236495Sspeer * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 243859Sml29623 * Use is subject to license terms. 253859Sml29623 */ 263859Sml29623 273859Sml29623 #ifndef _SYS_NXGE_NXGE_COMMON_IMPL_H 283859Sml29623 #define _SYS_NXGE_NXGE_COMMON_IMPL_H 293859Sml29623 303859Sml29623 #ifdef __cplusplus 313859Sml29623 extern "C" { 323859Sml29623 #endif 333859Sml29623 343859Sml29623 #define NPI_REGH(npi_handle) (npi_handle.regh) 353859Sml29623 #define NPI_REGP(npi_handle) (npi_handle.regp) 363859Sml29623 373859Sml29623 #if defined(NXGE_DEBUG_DMA) || defined(NXGE_DEBUG_TXC) 383859Sml29623 #define __NXGE_STATIC 393859Sml29623 #define __NXGE_INLINE 403859Sml29623 #else 413859Sml29623 #define __NXGE_STATIC static 423859Sml29623 #define __NXGE_INLINE inline 433859Sml29623 #endif 443859Sml29623 453859Sml29623 #ifdef AXIS_DEBUG 463859Sml29623 #define AXIS_WAIT (100000) 473859Sml29623 #define AXIS_LONG_WAIT (100000) 483859Sml29623 #define AXIS_WAIT_W (80000) 493859Sml29623 #define AXIS_WAIT_R (100000) 503859Sml29623 #define AXIS_WAIT_LOOP (4000) 513859Sml29623 #define AXIS_WAIT_PER_LOOP (AXIS_WAIT_R/AXIS_WAIT_LOOP) 523859Sml29623 #endif 533859Sml29623 543859Sml29623 #define NO_DEBUG 0x0000000000000000ULL 553859Sml29623 #define MDT_CTL 0x0000000000000001ULL 563859Sml29623 #define RX_CTL 0x0000000000000002ULL 573859Sml29623 #define TX_CTL 0x0000000000000004ULL 583859Sml29623 #define OBP_CTL 0x0000000000000008ULL 593859Sml29623 603859Sml29623 #define VPD_CTL 0x0000000000000010ULL 613859Sml29623 #define DDI_CTL 0x0000000000000020ULL 623859Sml29623 #define MEM_CTL 0x0000000000000040ULL 633859Sml29623 #define SAP_CTL 0x0000000000000080ULL 643859Sml29623 653859Sml29623 #define IOC_CTL 0x0000000000000100ULL 663859Sml29623 #define MOD_CTL 0x0000000000000200ULL 673859Sml29623 #define DMA_CTL 0x0000000000000400ULL 683859Sml29623 #define STR_CTL 0x0000000000000800ULL 693859Sml29623 703859Sml29623 #define INT_CTL 0x0000000000001000ULL 713859Sml29623 #define SYSERR_CTL 0x0000000000002000ULL 723859Sml29623 #define KST_CTL 0x0000000000004000ULL 733859Sml29623 #define PCS_CTL 0x0000000000008000ULL 743859Sml29623 753859Sml29623 #define MII_CTL 0x0000000000010000ULL 763859Sml29623 #define MIF_CTL 0x0000000000020000ULL 773859Sml29623 #define FCRAM_CTL 0x0000000000040000ULL 783859Sml29623 #define MAC_CTL 0x0000000000080000ULL 793859Sml29623 803859Sml29623 #define IPP_CTL 0x0000000000100000ULL 813859Sml29623 #define DMA2_CTL 0x0000000000200000ULL 823859Sml29623 #define RX2_CTL 0x0000000000400000ULL 833859Sml29623 #define TX2_CTL 0x0000000000800000ULL 843859Sml29623 853859Sml29623 #define MEM2_CTL 0x0000000001000000ULL 863859Sml29623 #define MEM3_CTL 0x0000000002000000ULL 873859Sml29623 #define NXGE_CTL 0x0000000004000000ULL 883859Sml29623 #define NDD_CTL 0x0000000008000000ULL 893859Sml29623 #define NDD2_CTL 0x0000000010000000ULL 903859Sml29623 913859Sml29623 #define TCAM_CTL 0x0000000020000000ULL 923859Sml29623 #define CFG_CTL 0x0000000040000000ULL 933859Sml29623 #define CFG2_CTL 0x0000000080000000ULL 943859Sml29623 953859Sml29623 #define FFLP_CTL TCAM_CTL | FCRAM_CTL 963859Sml29623 973859Sml29623 #define VIR_CTL 0x0000000100000000ULL 983859Sml29623 #define VIR2_CTL 0x0000000200000000ULL 993859Sml29623 1006495Sspeer #define HIO_CTL 0x0000000400000000ULL 1016495Sspeer 1023859Sml29623 #define NXGE_NOTE 0x0000001000000000ULL 1033859Sml29623 #define NXGE_ERR_CTL 0x0000002000000000ULL 1043859Sml29623 1053859Sml29623 #define DUMP_ALWAYS 0x2000000000000000ULL 1063859Sml29623 1073859Sml29623 /* NPI Debug and Error defines */ 1083859Sml29623 #define NPI_RDC_CTL 0x0000000000000001ULL 1093859Sml29623 #define NPI_TDC_CTL 0x0000000000000002ULL 1103859Sml29623 #define NPI_TXC_CTL 0x0000000000000004ULL 1113859Sml29623 #define NPI_IPP_CTL 0x0000000000000008ULL 1123859Sml29623 1133859Sml29623 #define NPI_XPCS_CTL 0x0000000000000010ULL 1143859Sml29623 #define NPI_PCS_CTL 0x0000000000000020ULL 1153859Sml29623 #define NPI_ESR_CTL 0x0000000000000040ULL 1163859Sml29623 #define NPI_BMAC_CTL 0x0000000000000080ULL 1173859Sml29623 #define NPI_XMAC_CTL 0x0000000000000100ULL 1183859Sml29623 #define NPI_MAC_CTL NPI_BMAC_CTL | NPI_XMAC_CTL 1193859Sml29623 1203859Sml29623 #define NPI_ZCP_CTL 0x0000000000000200ULL 1213859Sml29623 #define NPI_TCAM_CTL 0x0000000000000400ULL 1223859Sml29623 #define NPI_FCRAM_CTL 0x0000000000000800ULL 1233859Sml29623 #define NPI_FFLP_CTL NPI_TCAM_CTL | NPI_FCRAM_CTL 1243859Sml29623 1253859Sml29623 #define NPI_VIR_CTL 0x0000000000001000ULL 1263859Sml29623 #define NPI_PIO_CTL 0x0000000000002000ULL 1273859Sml29623 #define NPI_VIO_CTL 0x0000000000004000ULL 1283859Sml29623 1293859Sml29623 #define NPI_REG_CTL 0x0000000040000000ULL 1303859Sml29623 #define NPI_CTL 0x0000000080000000ULL 1313859Sml29623 #define NPI_ERR_CTL 0x0000000080000000ULL 1323859Sml29623 1333859Sml29623 #include <sys/types.h> 1343859Sml29623 #include <sys/ddi.h> 1353859Sml29623 #include <sys/sunddi.h> 1363859Sml29623 #include <sys/dditypes.h> 1373859Sml29623 #include <sys/ethernet.h> 1383859Sml29623 1393859Sml29623 #ifdef NXGE_DEBUG 1403859Sml29623 #define NXGE_DEBUG_MSG(params) nxge_debug_msg params 1413859Sml29623 #else 1423859Sml29623 #define NXGE_DEBUG_MSG(params) 1433859Sml29623 #endif 1443859Sml29623 1453859Sml29623 #define NXGE_ERROR_MSG(params) nxge_debug_msg params 1463859Sml29623 #define NXGE_WARN_MSG(params) nxge_debug_msg params 1473859Sml29623 1483859Sml29623 typedef kmutex_t nxge_os_mutex_t; 1493859Sml29623 typedef krwlock_t nxge_os_rwlock_t; 1503859Sml29623 1513859Sml29623 typedef dev_info_t nxge_dev_info_t; 1523859Sml29623 typedef ddi_iblock_cookie_t nxge_intr_cookie_t; 1533859Sml29623 1543859Sml29623 typedef ddi_acc_handle_t nxge_os_acc_handle_t; 1553859Sml29623 typedef nxge_os_acc_handle_t npi_reg_handle_t; 1565125Sjoycey #if defined(__i386) 1575125Sjoycey typedef uint32_t npi_reg_ptr_t; 1585125Sjoycey #else 1595125Sjoycey typedef uint64_t npi_reg_ptr_t; 1605125Sjoycey #endif 1613859Sml29623 1623859Sml29623 typedef ddi_dma_handle_t nxge_os_dma_handle_t; 1633859Sml29623 typedef struct _nxge_dma_common_t nxge_os_dma_common_t; 1643859Sml29623 typedef struct _nxge_block_mv_t nxge_os_block_mv_t; 1653859Sml29623 typedef frtn_t nxge_os_frtn_t; 1663859Sml29623 1673859Sml29623 #define NXGE_MUTEX_DRIVER MUTEX_DRIVER 1683859Sml29623 #define MUTEX_INIT(lock, name, type, arg) \ 1693859Sml29623 mutex_init(lock, name, type, arg) 1703859Sml29623 #define MUTEX_ENTER(lock) mutex_enter(lock) 1713859Sml29623 #define MUTEX_TRY_ENTER(lock) mutex_tryenter(lock) 1723859Sml29623 #define MUTEX_EXIT(lock) mutex_exit(lock) 1733859Sml29623 #define MUTEX_DESTROY(lock) mutex_destroy(lock) 1743859Sml29623 1753859Sml29623 #define RW_INIT(lock, name, type, arg) rw_init(lock, name, type, arg) 1763859Sml29623 #define RW_ENTER_WRITER(lock) rw_enter(lock, RW_WRITER) 1773859Sml29623 #define RW_ENTER_READER(lock) rw_enter(lock, RW_READER) 1783859Sml29623 #define RW_TRY_ENTER(lock, type) rw_tryenter(lock, type) 1793859Sml29623 #define RW_EXIT(lock) rw_exit(lock) 1803859Sml29623 #define RW_DESTROY(lock) rw_destroy(lock) 1813859Sml29623 #define KMEM_ALLOC(size, flag) kmem_alloc(size, flag) 1823859Sml29623 #define KMEM_ZALLOC(size, flag) kmem_zalloc(size, flag) 1833859Sml29623 #define KMEM_FREE(buf, size) kmem_free(buf, size) 1843859Sml29623 1853859Sml29623 #define NXGE_DELAY(microseconds) (drv_usecwait(microseconds)) 1863859Sml29623 1873859Sml29623 #define NXGE_PIO_READ8(handle, devaddr, offset) \ 1883859Sml29623 (ddi_get8(handle, (uint8_t *)((caddr_t)devaddr + offset))) 1893859Sml29623 1903859Sml29623 #define NXGE_PIO_READ16(handle, devaddr, offset) \ 1913859Sml29623 (ddi_get16(handle, (uint16_t *)((caddr_t)devaddr + offset))) 1923859Sml29623 1933859Sml29623 #define NXGE_PIO_READ32(handle, devaddr, offset) \ 1943859Sml29623 (ddi_get32(handle, (uint32_t *)((caddr_t)devaddr + offset))) 1953859Sml29623 1963859Sml29623 #define NXGE_PIO_READ64(handle, devaddr, offset) \ 1973859Sml29623 (ddi_get64(handle, (uint64_t *)((caddr_t)devaddr + offset))) 1983859Sml29623 1993859Sml29623 #define NXGE_PIO_WRITE8(handle, devaddr, offset, data) \ 2003859Sml29623 (ddi_put8(handle, (uint8_t *)((caddr_t)devaddr + offset), data)) 2013859Sml29623 2023859Sml29623 #define NXGE_PIO_WRITE16(handle, devaddr, offset, data) \ 2033859Sml29623 (ddi_get16(handle, (uint16_t *)((caddr_t)devaddr + offset), data)) 2043859Sml29623 2053859Sml29623 #define NXGE_PIO_WRITE32(handle, devaddr, offset, data) \ 2063859Sml29623 (ddi_put32(handle, (uint32_t *)((caddr_t)devaddr + offset), data)) 2073859Sml29623 2083859Sml29623 #define NXGE_PIO_WRITE64(handle, devaddr, offset, data) \ 2093859Sml29623 (ddi_put64(handle, (uint64_t *)((caddr_t)devaddr + offset), data)) 2103859Sml29623 2113859Sml29623 #define NXGE_NPI_PIO_READ8(npi_handle, offset) \ 2123859Sml29623 (ddi_get8(NPI_REGH(npi_handle), \ 2133859Sml29623 (uint8_t *)(NPI_REGP(npi_handle) + offset))) 2143859Sml29623 2153859Sml29623 #define NXGE_NPI_PIO_READ16(npi_handle, offset) \ 2163859Sml29623 (ddi_get16(NPI_REGH(npi_handle), \ 2173859Sml29623 (uint16_t *)(NPI_REGP(npi_handle) + offset))) 2183859Sml29623 2193859Sml29623 #define NXGE_NPI_PIO_READ32(npi_handle, offset) \ 2203859Sml29623 (ddi_get32(NPI_REGH(npi_handle), \ 2213859Sml29623 (uint32_t *)(NPI_REGP(npi_handle) + offset))) 2223859Sml29623 2235125Sjoycey #if defined(__i386) 2245125Sjoycey #define NXGE_NPI_PIO_READ64(npi_handle, offset) \ 2255125Sjoycey (ddi_get64(NPI_REGH(npi_handle), \ 2265125Sjoycey (uint64_t *)(NPI_REGP(npi_handle) + (uint32_t)offset))) 2275125Sjoycey #else 2283859Sml29623 #define NXGE_NPI_PIO_READ64(npi_handle, offset) \ 2293859Sml29623 (ddi_get64(NPI_REGH(npi_handle), \ 2303859Sml29623 (uint64_t *)(NPI_REGP(npi_handle) + offset))) 2315125Sjoycey #endif 2323859Sml29623 2333859Sml29623 #define NXGE_NPI_PIO_WRITE8(npi_handle, offset, data) \ 2343859Sml29623 (ddi_put8(NPI_REGH(npi_handle), \ 2353859Sml29623 (uint8_t *)(NPI_REGP(npi_handle) + offset), data)) 2363859Sml29623 2373859Sml29623 #define NXGE_NPI_PIO_WRITE16(npi_handle, offset, data) \ 2383859Sml29623 (ddi_put16(NPI_REGH(npi_handle), \ 2393859Sml29623 (uint16_t *)(NPI_REGP(npi_handle) + offset), data)) 2403859Sml29623 2413859Sml29623 #define NXGE_NPI_PIO_WRITE32(npi_handle, offset, data) \ 2423859Sml29623 (ddi_put32(NPI_REGH(npi_handle), \ 2433859Sml29623 (uint32_t *)(NPI_REGP(npi_handle) + offset), data)) 2443859Sml29623 2455125Sjoycey #if defined(__i386) 2465125Sjoycey #define NXGE_NPI_PIO_WRITE64(npi_handle, offset, data) \ 2475125Sjoycey (ddi_put64(NPI_REGH(npi_handle), \ 2485125Sjoycey (uint64_t *)(NPI_REGP(npi_handle) + (uint32_t)offset), data)) 2495125Sjoycey #else 2503859Sml29623 #define NXGE_NPI_PIO_WRITE64(npi_handle, offset, data) \ 2513859Sml29623 (ddi_put64(NPI_REGH(npi_handle), \ 2523859Sml29623 (uint64_t *)(NPI_REGP(npi_handle) + offset), data)) 2535125Sjoycey #endif 2543859Sml29623 2553859Sml29623 #define NXGE_MEM_PIO_READ8(npi_handle) \ 2563859Sml29623 (ddi_get8(NPI_REGH(npi_handle), (uint8_t *)NPI_REGP(npi_handle))) 2573859Sml29623 2583859Sml29623 #define NXGE_MEM_PIO_READ16(npi_handle) \ 2593859Sml29623 (ddi_get16(NPI_REGH(npi_handle), (uint16_t *)NPI_REGP(npi_handle))) 2603859Sml29623 2613859Sml29623 #define NXGE_MEM_PIO_READ32(npi_handle) \ 2623859Sml29623 (ddi_get32(NPI_REGH(npi_handle), (uint32_t *)NPI_REGP(npi_handle))) 2633859Sml29623 2643859Sml29623 #define NXGE_MEM_PIO_READ64(npi_handle) \ 2653859Sml29623 (ddi_get64(NPI_REGH(npi_handle), (uint64_t *)NPI_REGP(npi_handle))) 2663859Sml29623 2673859Sml29623 #define NXGE_MEM_PIO_WRITE8(npi_handle, data) \ 2683859Sml29623 (ddi_put8(NPI_REGH(npi_handle), (uint8_t *)NPI_REGP(npi_handle), data)) 2693859Sml29623 2703859Sml29623 #define NXGE_MEM_PIO_WRITE16(npi_handle, data) \ 2713859Sml29623 (ddi_put16(NPI_REGH(npi_handle), \ 2723859Sml29623 (uint16_t *)NPI_REGP(npi_handle), data)) 2733859Sml29623 2743859Sml29623 #define NXGE_MEM_PIO_WRITE32(npi_handle, data) \ 2753859Sml29623 (ddi_put32(NPI_REGH(npi_handle), \ 2763859Sml29623 (uint32_t *)NPI_REGP(npi_handle), data)) 2773859Sml29623 2783859Sml29623 #define NXGE_MEM_PIO_WRITE64(npi_handle, data) \ 2793859Sml29623 (ddi_put64(NPI_REGH(npi_handle), \ 2803859Sml29623 (uint64_t *)NPI_REGP(npi_handle), data)) 2813859Sml29623 2823859Sml29623 #define SERVICE_LOST DDI_SERVICE_LOST 2833859Sml29623 #define SERVICE_DEGRADED DDI_SERVICE_DEGRADED 2843859Sml29623 #define SERVICE_UNAFFECTED DDI_SERVICE_UNAFFECTED 2853859Sml29623 #define SERVICE_RESTORED DDI_SERVICE_RESTORED 2863859Sml29623 2873859Sml29623 #define DATAPATH_FAULT DDI_DATAPATH_FAULT 2883859Sml29623 #define DEVICE_FAULT DDI_DEVICE_FAULT 2893859Sml29623 #define EXTERNAL_FAULT DDI_EXTERNAL_FAULT 2903859Sml29623 2913859Sml29623 #define NOTE_LINK_UP DL_NOTE_LINK_UP 2923859Sml29623 #define NOTE_LINK_DOWN DL_NOTE_LINK_DOWN 2933859Sml29623 #define NOTE_SPEED DL_NOTE_SPEED 2943859Sml29623 #define NOTE_PHYS_ADDR DL_NOTE_PHYS_ADDR 2953859Sml29623 #define NOTE_AGGR_AVAIL DL_NOTE_AGGR_AVAIL 2963859Sml29623 #define NOTE_AGGR_UNAVAIL DL_NOTE_AGGR_UNAVAIL 2973859Sml29623 2983859Sml29623 #define FM_REPORT_FAULT(nxgep, impact, location, msg)\ 2993859Sml29623 ddi_dev_report_fault(nxgep->dip, impact, location, msg) 3003859Sml29623 #define FM_CHECK_DEV_HANDLE(nxgep)\ 3013859Sml29623 ddi_check_acc_handle(nxgep->dev_regs->nxge_regh) 3023859Sml29623 #define FM_GET_DEVSTATE(nxgep)\ 3033859Sml29623 ddi_get_devstate(nxgep->dip) 3043859Sml29623 #define FM_SERVICE_RESTORED(nxgep)\ 3053859Sml29623 ddi_fm_service_impact(nxgep->dip, DDI_SERVICE_RESTORED) 3063859Sml29623 #define NXGE_FM_REPORT_ERROR(nxgep, portn, chan, ereport_id)\ 3073859Sml29623 nxge_fm_report_error(nxgep, portn, chan, ereport_id) 3083859Sml29623 #define FM_CHECK_ACC_HANDLE(nxgep, handle)\ 3093859Sml29623 fm_check_acc_handle(handle) 3103859Sml29623 #define FM_CHECK_DMA_HANDLE(nxgep, handle)\ 3113859Sml29623 fm_check_dma_handle(handle) 3123859Sml29623 3133859Sml29623 #if defined(REG_TRACE) 3143859Sml29623 #define NXGE_REG_RD64(handle, offset, val_p) {\ 3153859Sml29623 *(val_p) = NXGE_NPI_PIO_READ64(handle, offset);\ 3163859Sml29623 npi_rtrace_update(handle, B_FALSE, &npi_rtracebuf, (uint32_t)offset, \ 3173859Sml29623 (uint64_t)(*(val_p)));\ 3183859Sml29623 } 3193859Sml29623 #elif defined(REG_SHOW) 3203859Sml29623 /* 3213859Sml29623 * Send 0xbadbad to tell rs_show_reg that we do not have 3223859Sml29623 * a valid RTBUF index to pass 3233859Sml29623 */ 3243859Sml29623 #define NXGE_REG_RD64(handle, offset, val_p) {\ 3253859Sml29623 *(val_p) = NXGE_NPI_PIO_READ64(handle, offset);\ 3263859Sml29623 rt_show_reg(0xbadbad, B_FALSE, (uint32_t)offset, (uint64_t)(*(val_p)));\ 3273859Sml29623 } 3283859Sml29623 #else 3293859Sml29623 #define NXGE_REG_RD64(handle, offset, val_p) {\ 3303859Sml29623 *(val_p) = NXGE_NPI_PIO_READ64(handle, offset);\ 3313859Sml29623 } 3323859Sml29623 #endif 3333859Sml29623 3343859Sml29623 #if defined(REG_TRACE) 3353859Sml29623 #define NXGE_REG_WR64(handle, offset, val) {\ 3363859Sml29623 NXGE_NPI_PIO_WRITE64(handle, (offset), (val));\ 3373859Sml29623 npi_rtrace_update(handle, B_TRUE, &npi_rtracebuf, (uint32_t)offset,\ 3383859Sml29623 (uint64_t)(val));\ 3393859Sml29623 } 3403859Sml29623 #elif defined(REG_SHOW) 3413859Sml29623 /* 3423859Sml29623 * Send 0xbadbad to tell rs_show_reg that we do not have 3433859Sml29623 * a valid RTBUF index to pass 3443859Sml29623 */ 3453859Sml29623 #define NXGE_REG_WR64(handle, offset, val) {\ 3463859Sml29623 NXGE_NPI_PIO_WRITE64(handle, offset, (val));\ 3473859Sml29623 rt_show_reg(0xbadbad, B_TRUE, (uint32_t)offset, (uint64_t)(val));\ 3483859Sml29623 } 3493859Sml29623 #else 3503859Sml29623 #define NXGE_REG_WR64(handle, offset, val) {\ 3513859Sml29623 NXGE_NPI_PIO_WRITE64(handle, (offset), (val));\ 3523859Sml29623 } 3533859Sml29623 #endif 3543859Sml29623 3553859Sml29623 #ifdef __cplusplus 3563859Sml29623 } 3573859Sml29623 #endif 3583859Sml29623 3593859Sml29623 #endif /* _SYS_NXGE_NXGE_COMMON_IMPL_H */ 360