1*6495Sspeer /*
2*6495Sspeer * CDDL HEADER START
3*6495Sspeer *
4*6495Sspeer * The contents of this file are subject to the terms of the
5*6495Sspeer * Common Development and Distribution License (the "License").
6*6495Sspeer * You may not use this file except in compliance with the License.
7*6495Sspeer *
8*6495Sspeer * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*6495Sspeer * or http://www.opensolaris.org/os/licensing.
10*6495Sspeer * See the License for the specific language governing permissions
11*6495Sspeer * and limitations under the License.
12*6495Sspeer *
13*6495Sspeer * When distributing Covered Code, include this CDDL HEADER in each
14*6495Sspeer * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*6495Sspeer * If applicable, add the following below this CDDL HEADER, with the
16*6495Sspeer * fields enclosed by brackets "[]" replaced with your own identifying
17*6495Sspeer * information: Portions Copyright [yyyy] [name of copyright owner]
18*6495Sspeer *
19*6495Sspeer * CDDL HEADER END
20*6495Sspeer */
21*6495Sspeer /*
22*6495Sspeer * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
23*6495Sspeer * Use is subject to license terms.
24*6495Sspeer */
25*6495Sspeer
26*6495Sspeer #ifndef _NPI_TX_RD64_H
27*6495Sspeer #define _NPI_TX_RD64_H
28*6495Sspeer
29*6495Sspeer #pragma ident "%Z%%M% %I% %E% SMI"
30*6495Sspeer
31*6495Sspeer #ifdef __cplusplus
32*6495Sspeer extern "C" {
33*6495Sspeer #endif
34*6495Sspeer
35*6495Sspeer #include <npi.h>
36*6495Sspeer
37*6495Sspeer static void TXDMA_REG_READ64(npi_handle_t, uint64_t, int, uint64_t *);
38*6495Sspeer #pragma inline(TXDMA_REG_READ64)
39*6495Sspeer
40*6495Sspeer /*
41*6495Sspeer * TXDMA_REG_READ64
42*6495Sspeer *
43*6495Sspeer * Read a 64-bit value from a DMC register.
44*6495Sspeer *
45*6495Sspeer * Arguments:
46*6495Sspeer * handle The NPI handle to use.
47*6495Sspeer * offset The offset into the DMA CSR (the register).
48*6495Sspeer * channel The channel, which is used as a multiplicand.
49*6495Sspeer * value Where to put the 64-bit value to be read.
50*6495Sspeer *
51*6495Sspeer * Notes:
52*6495Sspeer * For reference, here is the old macro:
53*6495Sspeer *
54*6495Sspeer * #define TXDMA_REG_READ64(handle, reg, channel, val_p) \
55*6495Sspeer * NXGE_REG_RD64(handle, \
56*6495Sspeer * (NXGE_TXDMA_OFFSET(reg, handle.is_vraddr, channel)), val_p)
57*6495Sspeer *
58*6495Sspeer * If handle.regp is a virtual address (the address of a VR),
59*6495Sspeer * we have to subtract the value DMC right off the bat. DMC
60*6495Sspeer * is defined as 0x600000, which works in a non-virtual address
61*6495Sspeer * space, but not in a VR. In a VR, a DMA CSR's space begins
62*6495Sspeer * at zero (0). So, since every call to RXMDA_REG_READ64 uses
63*6495Sspeer * a register macro which adds in DMC, we have to subtract it.
64*6495Sspeer *
65*6495Sspeer * The rest of it is pretty straighforward. In a VR, a channel is
66*6495Sspeer * logical, not absolute; and every DMA CSR is 512 bytes big;
67*6495Sspeer * furthermore, a subpage of a VR is always ordered with the
68*6495Sspeer * transmit CSRs first, followed by the receive CSRs. That is,
69*6495Sspeer * a 512 byte space of Tx CSRs, followed by a 512 byte space of
70*6495Sspeer * Rx CSRs. Hence this calculation:
71*6495Sspeer *
72*6495Sspeer * offset += ((channel << 1) << DMA_CSR_SLL);
73*6495Sspeer *
74*6495Sspeer * Here's an example:
75*6495Sspeer *
76*6495Sspeer * TXDMA_REG_READ64(handle, TX_CS_REG, channel, &value);
77*6495Sspeer * Let's say channel is 3
78*6495Sspeer * #define TX_CS_REG (DMC + 0x40028)
79*6495Sspeer * offset = 0x640028
80*6495Sspeer * offset &= 0xff = 0x28
81*6495Sspeer * offset += ((3 << 1) << 9)
82*6495Sspeer * 3 << 1 = 6
83*6495Sspeer * 6 << 9 = 0xc00
84*6495Sspeer * offset += 0xc00 = 0xc28
85*6495Sspeer *
86*6495Sspeer * Therefore, our register's (virtual) PIO address is 0xc28.
87*6495Sspeer *
88*6495Sspeer * cf. Table 10-6 on page 181 of the Neptune PRM, v 1.4:
89*6495Sspeer *
90*6495Sspeer * C00 - dFF CSRs for bound logical transmit DMA channel 3.
91*6495Sspeer *
92*6495Sspeer * In a non-virtual environment, you simply multiply the absolute
93*6495Sspeer * channel number by 512 bytes, and get the correct offset to
94*6495Sspeer * the register you're looking for. That is, the RX_DMA_CTL_STAT CSR,
95*6495Sspeer * is, as are all of these registers, in a table where each channel
96*6495Sspeer * is offset 512 bytes from the previous channel (count 16 step 512).
97*6495Sspeer *
98*6495Sspeer * offset += (channel << DMA_CSR_SLL); // channel<<9 = channel*512
99*6495Sspeer *
100*6495Sspeer * Here's an example:
101*6495Sspeer *
102*6495Sspeer * TXDMA_REG_READ64(handle, TX_CS_REG, channel, &value);
103*6495Sspeer * Let's say channel is 3
104*6495Sspeer * #define TX_CS_REG (DMC + 0x40028)
105*6495Sspeer * offset = 0x640028
106*6495Sspeer * offset += (3 << 9)
107*6495Sspeer * 3 << 9 = 0x600
108*6495Sspeer * offset += 0x600 = 0x640628
109*6495Sspeer *
110*6495Sspeer * Therefore, our register's PIO address is 0x640628.
111*6495Sspeer *
112*6495Sspeer * cf. Table 13-15 on page 265 of the Neptune PRM, v 1.4:
113*6495Sspeer * TX_CS (DMC + 4002816) (count 24 step 0x200)
114*6495Sspeer *
115*6495Sspeer * Context:
116*6495Sspeer * Any domain
117*6495Sspeer *
118*6495Sspeer */
119*6495Sspeer extern const char *nxge_tx2str(int);
120*6495Sspeer
121*6495Sspeer void
TXDMA_REG_READ64(npi_handle_t handle,uint64_t offset,int channel,uint64_t * value)122*6495Sspeer TXDMA_REG_READ64(
123*6495Sspeer npi_handle_t handle,
124*6495Sspeer uint64_t offset,
125*6495Sspeer int channel,
126*6495Sspeer uint64_t *value)
127*6495Sspeer {
128*6495Sspeer #if defined(NPI_REG_TRACE)
129*6495Sspeer const char *name = nxge_tx2str((int)offset);
130*6495Sspeer #endif
131*6495Sspeer if (handle.is_vraddr) {
132*6495Sspeer offset &= DMA_CSR_MASK;
133*6495Sspeer offset += ((channel << 1) << DMA_CSR_SLL);
134*6495Sspeer } else {
135*6495Sspeer offset += (channel << DMA_CSR_SLL);
136*6495Sspeer }
137*6495Sspeer
138*6495Sspeer #if defined(__i386)
139*6495Sspeer *value = ddi_get64(handle.regh,
140*6495Sspeer (uint64_t *)(handle.regp + (uint32_t)offset));
141*6495Sspeer #else
142*6495Sspeer *value = ddi_get64(handle.regh, (uint64_t *)(handle.regp + offset));
143*6495Sspeer #endif
144*6495Sspeer
145*6495Sspeer #if defined(NPI_REG_TRACE)
146*6495Sspeer npi_trace_update(handle, B_FALSE, &npi_rtracebuf,
147*6495Sspeer name, (uint32_t)offset, *value);
148*6495Sspeer #elif defined(REG_SHOW)
149*6495Sspeer /*
150*6495Sspeer * Since we don't have a valid RTBUF index to show, send 0xBADBAD.
151*6495Sspeer */
152*6495Sspeer rt_show_reg(0xbadbad, B_FALSE, (uint32_t)offset, *value);
153*6495Sspeer #endif
154*6495Sspeer }
155*6495Sspeer
156*6495Sspeer #ifdef __cplusplus
157*6495Sspeer }
158*6495Sspeer #endif
159*6495Sspeer
160*6495Sspeer #endif /* _NPI_TX_RD64_H */
161