]> CyberLeo.Net >> Repos - FreeBSD/releng/9.2.git/blob - sys/dev/bxe/bxe_include.h
- Copy stable/9 to releng/9.2 as part of the 9.2-RELEASE cycle.
[FreeBSD/releng/9.2.git] / sys / dev / bxe / bxe_include.h
1 /*-
2  * Copyright (c) 2007-2011 Broadcom Corporation. All rights reserved.
3  *
4  *    Gary Zambrano <zambrano@broadcom.com>
5  *    David Christensen <davidch@broadcom.com>
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  * 3. Neither the name of Broadcom Corporation nor the name of its contributors
17  *    may be used to endorse or promote products derived from this software
18  *    without specific prior written consent.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS'
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23  * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
24  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
30  * THE POSSIBILITY OF SUCH DAMAGE.
31  */
32
33  /*$FreeBSD$*/
34
35 #ifndef _BXE_INCLUDE_H
36 #define _BXE_INCLUDE_H
37
38 #include <sys/param.h>
39 #include <sys/types.h>
40 #include <sys/endian.h>
41
42 #include <machine/bus.h>
43
44 /*
45  * Convert FreeBSD byte order to match generated code usage.
46  */
47 #if BYTE_ORDER == BIG_ENDIAN
48 #define __BIG_ENDIAN 1
49 #undef  __LITTLE_ENDIAN
50 #else
51 #undef  __BIG_ENDIAN
52 #define __LITTLE_ENDIAN 1
53 #endif
54
55 #include "bxe_debug.h"
56 #include "bxe_reg.h"
57 #include "bxe_fw_defs.h"
58 #include "bxe_hsi.h"
59 #include "bxe_link.h"
60
61 /*
62  * Convenience definitions used in multiple files.
63  */
64 #define BXE_PRINTF(fmt, args...)                                        \
65         do {                                                            \
66                 device_printf(sc->dev, fmt, ##args);                    \
67         }while(0)
68
69
70 #ifdef BXE_DEBUG
71
72 #define REG_WR(sc, offset, val)                 \
73         bxe_reg_write32(sc, offset, val)
74 #define REG_WR8(sc, offset, val)                \
75         bxe_reg_write8(sc, offset, val)
76 #define REG_WR16(sc, offset, val)               \
77         bxe_reg_write16(sc, offset, val)
78 #define REG_WR32(sc, offset, val)               \
79         bxe_reg_write32(sc, offset, val)
80
81 #define REG_RD(sc, offset)                      \
82         bxe_reg_read32(sc, offset)
83 #define REG_RD8(sc, offset)                     \
84         bxe_reg_read8(sc, offset)
85 #define REG_RD16(sc, offset)                    \
86         bxe_reg_read16(sc, offset)
87 #define REG_RD32(sc, offset)                    \
88         bxe_reg_read32(sc, offset)
89
90 #define REG_RD_IND(sc, offset)                  \
91         bxe_reg_rd_ind(sc, offset)
92 #define REG_WR_IND(sc, offset, val)             \
93         bxe_reg_wr_ind(sc, offset, val)
94
95 #else
96
97 #define REG_WR(sc, offset, val)                                         \
98         bus_space_write_4(sc->bxe_btag, sc->bxe_bhandle, offset, val)
99 #define REG_WR8(sc, offset, val)                                        \
100         bus_space_write_1(sc->bxe_btag, sc->bxe_bhandle, offset, val)
101 #define REG_WR16(sc, offset, val)                                       \
102         bus_space_write_2(sc->bxe_btag, sc->bxe_bhandle, offset, val)
103 #define REG_WR32(sc, offset, val)                                       \
104         bus_space_write_4(sc->bxe_btag, sc->bxe_bhandle, offset, val)
105
106 #define REG_RD(sc, offset)                                              \
107         bus_space_read_4(sc->bxe_btag, sc->bxe_bhandle, offset)
108 #define REG_RD8(sc, offset)                                             \
109         bus_space_read_1(sc->bxe_btag, sc->bxe_bhandle, offset)
110 #define REG_RD16(sc, offset)                                            \
111         bus_space_read_2(sc->bxe_btag, sc->bxe_bhandle, offset)
112 #define REG_RD32(sc, offset)                                            \
113         bus_space_read_4(sc->bxe_btag, sc->bxe_bhandle, offset)
114
115 #define REG_RD_IND(sc, offset)                                          \
116         bxe_reg_rd_ind(sc, offset)
117 #define REG_WR_IND(sc, offset, val)                                     \
118         bxe_reg_wr_ind(sc, offset, val)
119
120 #endif /* BXE_DEBUG */
121
122
123 #define REG_RD_DMAE(sc, offset, val, len32)                             \
124         do {                                                            \
125                 bxe_read_dmae(sc, offset, len32);                       \
126                 memcpy(val, BXE_SP(sc, wb_data[0]), len32 * 4);         \
127         } while (0)
128
129
130 #define REG_WR_DMAE(sc, offset, val, len32)                             \
131         do {                                                            \
132                 memcpy(BXE_SP(sc, wb_data[0]), val, len32 * 4);         \
133                 bxe_write_dmae(sc, BXE_SP_MAPPING(sc, wb_data),         \
134                         offset, len32);                                 \
135         } while (0)
136
137
138 #define SHMEM_ADDR(sc, field)   (sc->common.shmem_base +                \
139         offsetof(struct shmem_region, field))
140
141 #define SHMEM_RD(sc, field)                                             \
142         REG_RD(sc, SHMEM_ADDR(sc, field))
143 #define SHMEM_RD16(sc, field)                                           \
144         REG_RD16(sc, SHMEM_ADDR(sc, field))
145
146 #define SHMEM_WR(sc, field, val)                                        \
147         REG_WR(sc, SHMEM_ADDR(sc, field), val)
148
149 #define SHMEM2_ADDR(sc, field)          (sc->common.shmem2_base +       \
150         offsetof(struct shmem2_region, field))
151 #define SHMEM2_RD(sc, field)            REG_RD(sc, SHMEM2_ADDR(sc, field))
152 #define SHMEM2_WR(sc, field, val)       REG_WR(sc, SHMEM2_ADDR(sc, field), val)
153
154
155 #define EMAC_RD(sc, reg)                                                \
156         REG_RD(sc, emac_base + (uint32_t) reg)
157 #define EMAC_WR(sc, reg, val)                                           \
158         REG_WR(sc, emac_base + (uint32_t) reg, val)
159
160 #define BMAC_WR(sc, reg, val)                                           \
161         REG_WR(sc, GRCBASE_NIG + bmac_addr + reg, val)
162
163 #endif /* _BXE_INCLUDE_H */