1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 * or http://www.opensolaris.org/os/licensing. 10 * See the License for the specific language governing permissions 11 * and limitations under the License. 12 * 13 * When distributing Covered Code, include this CDDL HEADER in each 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 * If applicable, add the following below this CDDL HEADER, with the 16 * fields enclosed by brackets "[]" replaced with your own identifying 17 * information: Portions Copyright [yyyy] [name of copyright owner] 18 * 19 * CDDL HEADER END 20 */ 21 /* 22 * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 23 * Use is subject to license terms. 24 */ 25 26 #ifndef _SYS_NXGE_NXGE_COMMON_IMPL_H 27 #define _SYS_NXGE_NXGE_COMMON_IMPL_H 28 29 #pragma ident "%Z%%M% %I% %E% SMI" 30 31 #ifdef __cplusplus 32 extern "C" { 33 #endif 34 35 #define NPI_REGH(npi_handle) (npi_handle.regh) 36 #define NPI_REGP(npi_handle) (npi_handle.regp) 37 38 #if defined(NXGE_DEBUG_DMA) || defined(NXGE_DEBUG_TXC) 39 #define __NXGE_STATIC 40 #define __NXGE_INLINE 41 #else 42 #define __NXGE_STATIC static 43 #define __NXGE_INLINE inline 44 #endif 45 46 #ifdef AXIS_DEBUG 47 #define AXIS_WAIT (100000) 48 #define AXIS_LONG_WAIT (100000) 49 #define AXIS_WAIT_W (80000) 50 #define AXIS_WAIT_R (100000) 51 #define AXIS_WAIT_LOOP (4000) 52 #define AXIS_WAIT_PER_LOOP (AXIS_WAIT_R/AXIS_WAIT_LOOP) 53 #endif 54 55 #define NO_DEBUG 0x0000000000000000ULL 56 #define MDT_CTL 0x0000000000000001ULL 57 #define RX_CTL 0x0000000000000002ULL 58 #define TX_CTL 0x0000000000000004ULL 59 #define OBP_CTL 0x0000000000000008ULL 60 61 #define VPD_CTL 0x0000000000000010ULL 62 #define DDI_CTL 0x0000000000000020ULL 63 #define MEM_CTL 0x0000000000000040ULL 64 #define SAP_CTL 0x0000000000000080ULL 65 66 #define IOC_CTL 0x0000000000000100ULL 67 #define MOD_CTL 0x0000000000000200ULL 68 #define DMA_CTL 0x0000000000000400ULL 69 #define STR_CTL 0x0000000000000800ULL 70 71 #define INT_CTL 0x0000000000001000ULL 72 #define SYSERR_CTL 0x0000000000002000ULL 73 #define KST_CTL 0x0000000000004000ULL 74 #define PCS_CTL 0x0000000000008000ULL 75 76 #define MII_CTL 0x0000000000010000ULL 77 #define MIF_CTL 0x0000000000020000ULL 78 #define FCRAM_CTL 0x0000000000040000ULL 79 #define MAC_CTL 0x0000000000080000ULL 80 81 #define IPP_CTL 0x0000000000100000ULL 82 #define DMA2_CTL 0x0000000000200000ULL 83 #define RX2_CTL 0x0000000000400000ULL 84 #define TX2_CTL 0x0000000000800000ULL 85 86 #define MEM2_CTL 0x0000000001000000ULL 87 #define MEM3_CTL 0x0000000002000000ULL 88 #define NXGE_CTL 0x0000000004000000ULL 89 #define NDD_CTL 0x0000000008000000ULL 90 #define NDD2_CTL 0x0000000010000000ULL 91 92 #define TCAM_CTL 0x0000000020000000ULL 93 #define CFG_CTL 0x0000000040000000ULL 94 #define CFG2_CTL 0x0000000080000000ULL 95 96 #define FFLP_CTL TCAM_CTL | FCRAM_CTL 97 98 #define VIR_CTL 0x0000000100000000ULL 99 #define VIR2_CTL 0x0000000200000000ULL 100 101 #define NXGE_NOTE 0x0000001000000000ULL 102 #define NXGE_ERR_CTL 0x0000002000000000ULL 103 104 #define DUMP_ALWAYS 0x2000000000000000ULL 105 106 /* NPI Debug and Error defines */ 107 #define NPI_RDC_CTL 0x0000000000000001ULL 108 #define NPI_TDC_CTL 0x0000000000000002ULL 109 #define NPI_TXC_CTL 0x0000000000000004ULL 110 #define NPI_IPP_CTL 0x0000000000000008ULL 111 112 #define NPI_XPCS_CTL 0x0000000000000010ULL 113 #define NPI_PCS_CTL 0x0000000000000020ULL 114 #define NPI_ESR_CTL 0x0000000000000040ULL 115 #define NPI_BMAC_CTL 0x0000000000000080ULL 116 #define NPI_XMAC_CTL 0x0000000000000100ULL 117 #define NPI_MAC_CTL NPI_BMAC_CTL | NPI_XMAC_CTL 118 119 #define NPI_ZCP_CTL 0x0000000000000200ULL 120 #define NPI_TCAM_CTL 0x0000000000000400ULL 121 #define NPI_FCRAM_CTL 0x0000000000000800ULL 122 #define NPI_FFLP_CTL NPI_TCAM_CTL | NPI_FCRAM_CTL 123 124 #define NPI_VIR_CTL 0x0000000000001000ULL 125 #define NPI_PIO_CTL 0x0000000000002000ULL 126 #define NPI_VIO_CTL 0x0000000000004000ULL 127 128 #define NPI_REG_CTL 0x0000000040000000ULL 129 #define NPI_CTL 0x0000000080000000ULL 130 #define NPI_ERR_CTL 0x0000000080000000ULL 131 132 #if defined(SOLARIS) && defined(_KERNEL) 133 134 #include <sys/types.h> 135 #include <sys/ddi.h> 136 #include <sys/sunddi.h> 137 #include <sys/dditypes.h> 138 #include <sys/ethernet.h> 139 140 #ifdef NXGE_DEBUG 141 #define NXGE_DEBUG_MSG(params) nxge_debug_msg params 142 #else 143 #define NXGE_DEBUG_MSG(params) 144 #endif 145 146 #if 1 147 #define NXGE_ERROR_MSG(params) nxge_debug_msg params 148 #define NXGE_WARN_MSG(params) nxge_debug_msg params 149 #else 150 #define NXGE_ERROR_MSG(params) 151 #define NXGE_WARN_MSG(params) 152 #endif 153 154 typedef kmutex_t nxge_os_mutex_t; 155 typedef krwlock_t nxge_os_rwlock_t; 156 157 typedef dev_info_t nxge_dev_info_t; 158 typedef ddi_iblock_cookie_t nxge_intr_cookie_t; 159 160 typedef ddi_acc_handle_t nxge_os_acc_handle_t; 161 typedef nxge_os_acc_handle_t npi_reg_handle_t; 162 typedef uint64_t npi_reg_ptr_t; 163 164 typedef ddi_dma_handle_t nxge_os_dma_handle_t; 165 typedef struct _nxge_dma_common_t nxge_os_dma_common_t; 166 typedef struct _nxge_block_mv_t nxge_os_block_mv_t; 167 typedef frtn_t nxge_os_frtn_t; 168 169 #define NXGE_MUTEX_DRIVER MUTEX_DRIVER 170 #define MUTEX_INIT(lock, name, type, arg) \ 171 mutex_init(lock, name, type, arg) 172 #define MUTEX_ENTER(lock) mutex_enter(lock) 173 #define MUTEX_TRY_ENTER(lock) mutex_tryenter(lock) 174 #define MUTEX_EXIT(lock) mutex_exit(lock) 175 #define MUTEX_DESTROY(lock) mutex_destroy(lock) 176 177 #define RW_INIT(lock, name, type, arg) rw_init(lock, name, type, arg) 178 #define RW_ENTER_WRITER(lock) rw_enter(lock, RW_WRITER) 179 #define RW_ENTER_READER(lock) rw_enter(lock, RW_READER) 180 #define RW_TRY_ENTER(lock, type) rw_tryenter(lock, type) 181 #define RW_EXIT(lock) rw_exit(lock) 182 #define RW_DESTROY(lock) rw_destroy(lock) 183 #define KMEM_ALLOC(size, flag) kmem_alloc(size, flag) 184 #define KMEM_ZALLOC(size, flag) kmem_zalloc(size, flag) 185 #define KMEM_FREE(buf, size) kmem_free(buf, size) 186 187 #define NXGE_DELAY(microseconds) (drv_usecwait(microseconds)) 188 189 #define NXGE_PIO_READ8(handle, devaddr, offset) \ 190 (ddi_get8(handle, (uint8_t *)((caddr_t)devaddr + offset))) 191 192 #define NXGE_PIO_READ16(handle, devaddr, offset) \ 193 (ddi_get16(handle, (uint16_t *)((caddr_t)devaddr + offset))) 194 195 #define NXGE_PIO_READ32(handle, devaddr, offset) \ 196 (ddi_get32(handle, (uint32_t *)((caddr_t)devaddr + offset))) 197 198 #define NXGE_PIO_READ64(handle, devaddr, offset) \ 199 (ddi_get64(handle, (uint64_t *)((caddr_t)devaddr + offset))) 200 201 #define NXGE_PIO_WRITE8(handle, devaddr, offset, data) \ 202 (ddi_put8(handle, (uint8_t *)((caddr_t)devaddr + offset), data)) 203 204 #define NXGE_PIO_WRITE16(handle, devaddr, offset, data) \ 205 (ddi_get16(handle, (uint16_t *)((caddr_t)devaddr + offset), data)) 206 207 #define NXGE_PIO_WRITE32(handle, devaddr, offset, data) \ 208 (ddi_put32(handle, (uint32_t *)((caddr_t)devaddr + offset), data)) 209 210 #define NXGE_PIO_WRITE64(handle, devaddr, offset, data) \ 211 (ddi_put64(handle, (uint64_t *)((caddr_t)devaddr + offset), data)) 212 213 #define NXGE_NPI_PIO_READ8(npi_handle, offset) \ 214 (ddi_get8(NPI_REGH(npi_handle), \ 215 (uint8_t *)(NPI_REGP(npi_handle) + offset))) 216 217 #define NXGE_NPI_PIO_READ16(npi_handle, offset) \ 218 (ddi_get16(NPI_REGH(npi_handle), \ 219 (uint16_t *)(NPI_REGP(npi_handle) + offset))) 220 221 #define NXGE_NPI_PIO_READ32(npi_handle, offset) \ 222 (ddi_get32(NPI_REGH(npi_handle), \ 223 (uint32_t *)(NPI_REGP(npi_handle) + offset))) 224 225 #define NXGE_NPI_PIO_READ64(npi_handle, offset) \ 226 (ddi_get64(NPI_REGH(npi_handle), \ 227 (uint64_t *)(NPI_REGP(npi_handle) + offset))) 228 229 #define NXGE_NPI_PIO_WRITE8(npi_handle, offset, data) \ 230 (ddi_put8(NPI_REGH(npi_handle), \ 231 (uint8_t *)(NPI_REGP(npi_handle) + offset), data)) 232 233 #define NXGE_NPI_PIO_WRITE16(npi_handle, offset, data) \ 234 (ddi_put16(NPI_REGH(npi_handle), \ 235 (uint16_t *)(NPI_REGP(npi_handle) + offset), data)) 236 237 #define NXGE_NPI_PIO_WRITE32(npi_handle, offset, data) \ 238 (ddi_put32(NPI_REGH(npi_handle), \ 239 (uint32_t *)(NPI_REGP(npi_handle) + offset), data)) 240 241 #define NXGE_NPI_PIO_WRITE64(npi_handle, offset, data) \ 242 (ddi_put64(NPI_REGH(npi_handle), \ 243 (uint64_t *)(NPI_REGP(npi_handle) + offset), data)) 244 245 #define NXGE_MEM_PIO_READ8(npi_handle) \ 246 (ddi_get8(NPI_REGH(npi_handle), (uint8_t *)NPI_REGP(npi_handle))) 247 248 #define NXGE_MEM_PIO_READ16(npi_handle) \ 249 (ddi_get16(NPI_REGH(npi_handle), (uint16_t *)NPI_REGP(npi_handle))) 250 251 #define NXGE_MEM_PIO_READ32(npi_handle) \ 252 (ddi_get32(NPI_REGH(npi_handle), (uint32_t *)NPI_REGP(npi_handle))) 253 254 #define NXGE_MEM_PIO_READ64(npi_handle) \ 255 (ddi_get64(NPI_REGH(npi_handle), (uint64_t *)NPI_REGP(npi_handle))) 256 257 #define NXGE_MEM_PIO_WRITE8(npi_handle, data) \ 258 (ddi_put8(NPI_REGH(npi_handle), (uint8_t *)NPI_REGP(npi_handle), data)) 259 260 #define NXGE_MEM_PIO_WRITE16(npi_handle, data) \ 261 (ddi_put16(NPI_REGH(npi_handle), \ 262 (uint16_t *)NPI_REGP(npi_handle), data)) 263 264 #define NXGE_MEM_PIO_WRITE32(npi_handle, data) \ 265 (ddi_put32(NPI_REGH(npi_handle), \ 266 (uint32_t *)NPI_REGP(npi_handle), data)) 267 268 #define NXGE_MEM_PIO_WRITE64(npi_handle, data) \ 269 (ddi_put64(NPI_REGH(npi_handle), \ 270 (uint64_t *)NPI_REGP(npi_handle), data)) 271 272 #define SERVICE_LOST DDI_SERVICE_LOST 273 #define SERVICE_DEGRADED DDI_SERVICE_DEGRADED 274 #define SERVICE_UNAFFECTED DDI_SERVICE_UNAFFECTED 275 #define SERVICE_RESTORED DDI_SERVICE_RESTORED 276 277 #define DATAPATH_FAULT DDI_DATAPATH_FAULT 278 #define DEVICE_FAULT DDI_DEVICE_FAULT 279 #define EXTERNAL_FAULT DDI_EXTERNAL_FAULT 280 281 #define NOTE_LINK_UP DL_NOTE_LINK_UP 282 #define NOTE_LINK_DOWN DL_NOTE_LINK_DOWN 283 #define NOTE_SPEED DL_NOTE_SPEED 284 #define NOTE_PHYS_ADDR DL_NOTE_PHYS_ADDR 285 #define NOTE_AGGR_AVAIL DL_NOTE_AGGR_AVAIL 286 #define NOTE_AGGR_UNAVAIL DL_NOTE_AGGR_UNAVAIL 287 288 #define FM_REPORT_FAULT(nxgep, impact, location, msg)\ 289 ddi_dev_report_fault(nxgep->dip, impact, location, msg) 290 #define FM_CHECK_DEV_HANDLE(nxgep)\ 291 ddi_check_acc_handle(nxgep->dev_regs->nxge_regh) 292 #define FM_GET_DEVSTATE(nxgep)\ 293 ddi_get_devstate(nxgep->dip) 294 #define FM_SERVICE_RESTORED(nxgep)\ 295 ddi_fm_service_impact(nxgep->dip, DDI_SERVICE_RESTORED) 296 #define NXGE_FM_REPORT_ERROR(nxgep, portn, chan, ereport_id)\ 297 nxge_fm_report_error(nxgep, portn, chan, ereport_id) 298 #define FM_CHECK_ACC_HANDLE(nxgep, handle)\ 299 fm_check_acc_handle(handle) 300 #define FM_CHECK_DMA_HANDLE(nxgep, handle)\ 301 fm_check_dma_handle(handle) 302 303 #endif 304 305 #if defined(REG_TRACE) 306 #define NXGE_REG_RD64(handle, offset, val_p) {\ 307 *(val_p) = NXGE_NPI_PIO_READ64(handle, offset);\ 308 npi_rtrace_update(handle, B_FALSE, &npi_rtracebuf, (uint32_t)offset, \ 309 (uint64_t)(*(val_p)));\ 310 } 311 #elif defined(REG_SHOW) 312 /* 313 * Send 0xbadbad to tell rs_show_reg that we do not have 314 * a valid RTBUF index to pass 315 */ 316 #define NXGE_REG_RD64(handle, offset, val_p) {\ 317 *(val_p) = NXGE_NPI_PIO_READ64(handle, offset);\ 318 rt_show_reg(0xbadbad, B_FALSE, (uint32_t)offset, (uint64_t)(*(val_p)));\ 319 } 320 #elif defined(AXIS_DEBUG) && !defined(LEGION) 321 #define NXGE_REG_RD64(handle, offset, val_p) {\ 322 int n; \ 323 for (n = 0; n < AXIS_WAIT_LOOP; n++) { \ 324 *(val_p) = 0; \ 325 *(val_p) = NXGE_NPI_PIO_READ64(handle, offset);\ 326 if (*(val_p) != (~0)) { \ 327 break; \ 328 } \ 329 drv_usecwait(AXIS_WAIT_PER_LOOP); \ 330 if (n < 20) { \ 331 cmn_err(CE_WARN, "NXGE_REG_RD64: loop %d " \ 332 "REG 0x%x(0x%llx)", \ 333 n, offset, *val_p);\ 334 } \ 335 } \ 336 if (n >= AXIS_WAIT_LOOP) { \ 337 cmn_err(CE_WARN, "(FATAL)NXGE_REG_RD64 on offset 0x%x " \ 338 "with -1!!!", offset); \ 339 } \ 340 } 341 #else 342 343 #define NXGE_REG_RD64(handle, offset, val_p) {\ 344 *(val_p) = NXGE_NPI_PIO_READ64(handle, offset);\ 345 } 346 #endif 347 348 /* 349 * In COSIM mode, we could loop for very long time when polling 350 * for the completion of a Clause45 frame MDIO operations. Display 351 * one rtrace line for each poll can result in messy screen. Add 352 * this MACRO for no rtrace show. 353 */ 354 #define NXGE_REG_RD64_NO_SHOW(handle, offset, val_p) {\ 355 *(val_p) = NXGE_NPI_PIO_READ64(handle, offset);\ 356 } 357 358 359 #if defined(REG_TRACE) 360 #define NXGE_REG_WR64(handle, offset, val) {\ 361 NXGE_NPI_PIO_WRITE64(handle, (offset), (val));\ 362 npi_rtrace_update(handle, B_TRUE, &npi_rtracebuf, (uint32_t)offset,\ 363 (uint64_t)(val));\ 364 } 365 #elif defined(REG_SHOW) 366 /* 367 * Send 0xbadbad to tell rs_show_reg that we do not have 368 * a valid RTBUF index to pass 369 */ 370 #define NXGE_REG_WR64(handle, offset, val) {\ 371 NXGE_NPI_PIO_WRITE64(handle, offset, (val));\ 372 rt_show_reg(0xbadbad, B_TRUE, (uint32_t)offset, (uint64_t)(val));\ 373 } 374 #else 375 #define NXGE_REG_WR64(handle, offset, val) {\ 376 NXGE_NPI_PIO_WRITE64(handle, (offset), (val));\ 377 } 378 #endif 379 380 #ifdef __cplusplus 381 } 382 #endif 383 384 #endif /* _SYS_NXGE_NXGE_COMMON_IMPL_H */ 385