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 2008 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
24 */
25
26 #ifndef _NPI_RX_RD32_H
27 #define _NPI_RX_RD32_H
28
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32
33 #include <npi.h>
34
35 static uint32_t RXDMA_REG_READ32(npi_handle_t, uint32_t, int);
36 #pragma inline(RXDMA_REG_READ32)
37
38 /*
39 * RXDMA_REG_READ32
40 *
41 * Read a 32-bit value from a DMC register.
42 *
43 * Arguments:
44 * handle The NPI handle to use.
45 * offset The offset into the DMA CSR (the register).
46 * channel The channel, which is used as a multiplicand.
47 *
48 * Notes:
49 * If handle.regp is a virtual address (the address of a VR),
50 * we have to subtract the value DMC right off the bat. DMC
51 * is defined as 0x600000, which works in a non-virtual address
52 * space, but not in a VR. In a VR, a DMA CSR's space begins
53 * at zero (0). So, since every call to RXMDA_REG_READ32 uses
54 * a register macro which adds in DMC, we have to subtract it.
55 *
56 * The rest of it is pretty straighforward. In a VR, a channel is
57 * logical, not absolute; and every DMA CSR is 512 bytes big;
58 * furthermore, a subpage of a VR is always ordered with the
59 * transmit CSRs first, followed by the receive CSRs. That is,
60 * a 512 byte space of Tx CSRs, followed by a 512 byte space of
61 * Rx CSRs. Hence this calculation:
62 *
63 * offset += ((channel << 1) + 1) << DMA_CSR_SLL;
64 *
65 * Here's an example:
66 *
67 * RXDMA_REG_READ32(handle, RX_DMA_CTL_STAT_REG, channel);
68 * Let's say channel is 3
69 * #define RX_DMA_CTL_STAT_REG (DMC + 0x00070)
70 * offset = 0x600070
71 * offset &= 0xff = 0x70
72 * offset += ((3 << 1) + 1) << 9
73 * 3 << 1 = 6
74 * 6 + 1 = 7
75 * 7 << 9 = 0xe00
76 * offset += 0xe00 = 0xe70
77 *
78 * Therefore, our register's (virtual) PIO address is 0xe70.
79 *
80 * cf. Table 10-6 on page 181 of the Neptune PRM, v 1.4:
81 *
82 * E00 - FFF CSRs for bound logical receive DMA channel 3.
83 *
84 * In a non-virtual environment, you simply multiply the absolute
85 * channel number by 512 bytes, and get the correct offset to
86 * the register you're looking for. That is, the RX_DMA_CTL_STAT CSR,
87 * is, as are all of these registers, in a table where each channel
88 * is offset 512 bytes from the previous channel (count 16 step 512).
89 *
90 * offset += (channel << DMA_CSR_SLL); // channel<<9 = channel*512
91 *
92 * Here's an example:
93 *
94 * RXDMA_REG_READ32(handle, RX_DMA_CTL_STAT_REG, channel);
95 * Let's say channel is 3
96 * #define RX_DMA_CTL_STAT_REG (DMC + 0x00070)
97 * offset = 0x600070
98 * offset += (3 << 9)
99 * 3 << 9 = 0x600
100 * offset += 0x600 = 0x600670
101 *
102 * Therefore, our register's PIO address is 0x600670.
103 *
104 * cf. Table 12-42 on page 234 of the Neptune PRM, v 1.4:
105 * RX_DMA_CTL_STAT (DMC + [0x]00070) (count 16 step [0x]200)
106 *
107 * Context:
108 * Guest domain
109 *
110 */
111 uint32_t
RXDMA_REG_READ32(npi_handle_t handle,uint32_t offset,int channel)112 RXDMA_REG_READ32(
113 npi_handle_t handle,
114 uint32_t offset,
115 int channel)
116 {
117 if (handle.is_vraddr) {
118 offset &= DMA_CSR_MASK;
119 offset += (((channel << 1) + 1) << DMA_CSR_SLL);
120 } else {
121 offset += (channel << DMA_CSR_SLL);
122 }
123
124 return (ddi_get32(handle.regh, (uint32_t *)(handle.regp + offset)));
125 }
126
127 #ifdef __cplusplus
128 }
129 #endif
130
131 #endif /* _NPI_RX_RD32_H */
132