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