Deleted Added
full compact
msgring.h (211994) msgring.h (211996)
1/*-
2 * Copyright (c) 2003-2009 RMI Corporation
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of RMI Corporation, nor the names of its contributors,
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 *
29 * RMI_BSD
1/*-
2 * Copyright (c) 2003-2009 RMI Corporation
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of RMI Corporation, nor the names of its contributors,
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 *
29 * RMI_BSD
30 * $FreeBSD: head/sys/mips/rmi/msgring.h 211994 2010-08-30 13:05:21Z jchandra $
30 * $FreeBSD: head/sys/mips/rmi/msgring.h 211996 2010-08-30 13:26:07Z jchandra $
31 */
32#ifndef _RMI_MSGRING_H_
33#define _RMI_MSGRING_H_
34
35#include <sys/types.h>
36#include <mips/rmi/rmi_mips_exts.h>
37
38#define MSGRNG_TX_BUF_REG 0
39#define MSGRNG_RX_BUF_REG 1
40
41#define MSGRNG_MSG_STATUS_REG 2
42#define MSGRNG_MSG_CONFIG_REG 3
43
44#define MSGRNG_MSG_BUCKSIZE_REG 4
45
46#define MSGRNG_CC_0_REG 16
47#define MSGRNG_CC_1_REG 17
48#define MSGRNG_CC_2_REG 18
49#define MSGRNG_CC_3_REG 19
50#define MSGRNG_CC_4_REG 20
51#define MSGRNG_CC_5_REG 21
52#define MSGRNG_CC_6_REG 22
53#define MSGRNG_CC_7_REG 23
54#define MSGRNG_CC_8_REG 24
55#define MSGRNG_CC_9_REG 25
56#define MSGRNG_CC_10_REG 26
57#define MSGRNG_CC_11_REG 27
58#define MSGRNG_CC_12_REG 28
59#define MSGRNG_CC_13_REG 29
60#define MSGRNG_CC_14_REG 30
61#define MSGRNG_CC_15_REG 31
62
63#define msgrng_read_status() read_c2_register32(MSGRNG_MSG_STATUS_REG, 0)
64
65#define msgrng_read_config() read_c2_register32(MSGRNG_MSG_CONFIG_REG, 0)
66#define msgrng_write_config(value) write_c2_register32(MSGRNG_MSG_CONFIG_REG, 0, value)
67
68#define msgrng_read_bucksize(bucket) read_c2_register32(MSGRNG_MSG_BUCKSIZE_REG, bucket)
69#define msgrng_write_bucksize(bucket, value) write_c2_register32(MSGRNG_MSG_BUCKSIZE_REG, bucket, value)
70
71#define msgrng_read_cc(reg, pri) read_c2_register32(reg, pri)
72#define msgrng_write_cc(reg, value, pri) write_c2_register32(reg, pri, value)
73
74#define msgrng_load_rx_msg0() read_c2_register64(MSGRNG_RX_BUF_REG, 0)
75#define msgrng_load_rx_msg1() read_c2_register64(MSGRNG_RX_BUF_REG, 1)
76#define msgrng_load_rx_msg2() read_c2_register64(MSGRNG_RX_BUF_REG, 2)
77#define msgrng_load_rx_msg3() read_c2_register64(MSGRNG_RX_BUF_REG, 3)
78
79#define msgrng_load_tx_msg0(value) write_c2_register64(MSGRNG_TX_BUF_REG, 0, value)
80#define msgrng_load_tx_msg1(value) write_c2_register64(MSGRNG_TX_BUF_REG, 1, value)
81#define msgrng_load_tx_msg2(value) write_c2_register64(MSGRNG_TX_BUF_REG, 2, value)
82#define msgrng_load_tx_msg3(value) write_c2_register64(MSGRNG_TX_BUF_REG, 3, value)
83
84/* Station IDs */
85#define MSGRNG_STNID_CPU0 0x00
86#define MSGRNG_STNID_CPU1 0x08
87#define MSGRNG_STNID_CPU2 0x10
88#define MSGRNG_STNID_CPU3 0x18
89#define MSGRNG_STNID_CPU4 0x20
90#define MSGRNG_STNID_CPU5 0x28
91#define MSGRNG_STNID_CPU6 0x30
92#define MSGRNG_STNID_CPU7 0x38
93#define MSGRNG_STNID_XGS0_TX 64
94#define MSGRNG_STNID_XMAC0_00_TX 64
95#define MSGRNG_STNID_XMAC0_01_TX 65
96#define MSGRNG_STNID_XMAC0_02_TX 66
97#define MSGRNG_STNID_XMAC0_03_TX 67
98#define MSGRNG_STNID_XMAC0_04_TX 68
99#define MSGRNG_STNID_XMAC0_05_TX 69
100#define MSGRNG_STNID_XMAC0_06_TX 70
101#define MSGRNG_STNID_XMAC0_07_TX 71
102#define MSGRNG_STNID_XMAC0_08_TX 72
103#define MSGRNG_STNID_XMAC0_09_TX 73
104#define MSGRNG_STNID_XMAC0_10_TX 74
105#define MSGRNG_STNID_XMAC0_11_TX 75
106#define MSGRNG_STNID_XMAC0_12_TX 76
107#define MSGRNG_STNID_XMAC0_13_TX 77
108#define MSGRNG_STNID_XMAC0_14_TX 78
109#define MSGRNG_STNID_XMAC0_15_TX 79
110
111#define MSGRNG_STNID_XGS1_TX 80
112#define MSGRNG_STNID_XMAC1_00_TX 80
113#define MSGRNG_STNID_XMAC1_01_TX 81
114#define MSGRNG_STNID_XMAC1_02_TX 82
115#define MSGRNG_STNID_XMAC1_03_TX 83
116#define MSGRNG_STNID_XMAC1_04_TX 84
117#define MSGRNG_STNID_XMAC1_05_TX 85
118#define MSGRNG_STNID_XMAC1_06_TX 86
119#define MSGRNG_STNID_XMAC1_07_TX 87
120#define MSGRNG_STNID_XMAC1_08_TX 88
121#define MSGRNG_STNID_XMAC1_09_TX 89
122#define MSGRNG_STNID_XMAC1_10_TX 90
123#define MSGRNG_STNID_XMAC1_11_TX 91
124#define MSGRNG_STNID_XMAC1_12_TX 92
125#define MSGRNG_STNID_XMAC1_13_TX 93
126#define MSGRNG_STNID_XMAC1_14_TX 94
127#define MSGRNG_STNID_XMAC1_15_TX 95
128
129#define MSGRNG_STNID_GMAC 96
130#define MSGRNG_STNID_GMACJFR_0 96
131#define MSGRNG_STNID_GMACRFR_0 97
132#define MSGRNG_STNID_GMACTX0 98
133#define MSGRNG_STNID_GMACTX1 99
134#define MSGRNG_STNID_GMACTX2 100
135#define MSGRNG_STNID_GMACTX3 101
136#define MSGRNG_STNID_GMACJFR_1 102
137#define MSGRNG_STNID_GMACRFR_1 103
138
139#define MSGRNG_STNID_DMA 104
140#define MSGRNG_STNID_DMA_0 104
141#define MSGRNG_STNID_DMA_1 105
142#define MSGRNG_STNID_DMA_2 106
143#define MSGRNG_STNID_DMA_3 107
144
145#define MSGRNG_STNID_XGS0FR 112
146#define MSGRNG_STNID_XMAC0JFR 112
147#define MSGRNG_STNID_XMAC0RFR 113
148
149#define MSGRNG_STNID_XGS1FR 114
150#define MSGRNG_STNID_XMAC1JFR 114
151#define MSGRNG_STNID_XMAC1RFR 115
152#define MSGRNG_STNID_SEC 120
153#define MSGRNG_STNID_SEC0 120
154#define MSGRNG_STNID_SEC1 121
155#define MSGRNG_STNID_SEC2 122
156#define MSGRNG_STNID_SEC3 123
157#define MSGRNG_STNID_PK0 124
158#define MSGRNG_STNID_SEC_RSA 124
159#define MSGRNG_STNID_SEC_RSVD0 125
160#define MSGRNG_STNID_SEC_RSVD1 126
161#define MSGRNG_STNID_SEC_RSVD2 127
162
163#define MSGRNG_STNID_GMAC1 80
164#define MSGRNG_STNID_GMAC1_FR_0 81
165#define MSGRNG_STNID_GMAC1_TX0 82
166#define MSGRNG_STNID_GMAC1_TX1 83
167#define MSGRNG_STNID_GMAC1_TX2 84
168#define MSGRNG_STNID_GMAC1_TX3 85
169#define MSGRNG_STNID_GMAC1_FR_1 87
170#define MSGRNG_STNID_GMAC0 96
171#define MSGRNG_STNID_GMAC0_FR_0 97
172#define MSGRNG_STNID_GMAC0_TX0 98
173#define MSGRNG_STNID_GMAC0_TX1 99
174#define MSGRNG_STNID_GMAC0_TX2 100
175#define MSGRNG_STNID_GMAC0_TX3 101
176#define MSGRNG_STNID_GMAC0_FR_1 103
177#define MSGRNG_STNID_CMP_0 108
178#define MSGRNG_STNID_CMP_1 109
179#define MSGRNG_STNID_CMP_2 110
180#define MSGRNG_STNID_CMP_3 111
181#define MSGRNG_STNID_PCIE_0 116
182#define MSGRNG_STNID_PCIE_1 117
183#define MSGRNG_STNID_PCIE_2 118
184#define MSGRNG_STNID_PCIE_3 119
185#define MSGRNG_STNID_XLS_PK0 121
186
187#define MSGRNG_CODE_MAC 0
188#define MSGRNG_CODE_XGMAC 2
189#define MSGRNG_CODE_SEC 0
190#define MSGRNG_CODE_BOOT_WAKEUP 200
191#define MSGRNG_CODE_SPI4 3
192
193static inline int
194msgrng_xgmac_stid_rfr(int id)
195{
196 return !id ? MSGRNG_STNID_XMAC0RFR : MSGRNG_STNID_XMAC1RFR;
197}
198
199static inline int
200msgrng_xgmac_stid_jfr(int id)
201{
202 return !id ? MSGRNG_STNID_XMAC0JFR : MSGRNG_STNID_XMAC1JFR;
203}
204
205static inline int
206msgrng_xgmac_stid_tx(int id)
207{
208 return !id ? MSGRNG_STNID_XMAC0_00_TX : MSGRNG_STNID_XMAC1_00_TX;
209}
210
211static inline int
212msgrng_gmac_stid_rfr(int id)
213{
214 return (MSGRNG_STNID_GMACRFR_0);
215}
216
217static inline int
218msgrng_gmac_stid_rfr_split_mode(int id)
219{
220 return ((id >> 1) ? MSGRNG_STNID_GMACRFR_1 : MSGRNG_STNID_GMACRFR_0);
221}
222
223static inline int
224msgrng_gmac_stid_jfr(int id)
225{
226 return MSGRNG_STNID_GMACJFR_0;
227}
228
229static inline int
230msgrng_gmac_stid_jfr_split_mode(int id)
231{
232 return ((id >> 1) ? MSGRNG_STNID_GMACJFR_1 : MSGRNG_STNID_GMACJFR_0);
233}
234
235static inline int
236msgrng_gmac_stid_tx(int id)
237{
238 return (MSGRNG_STNID_GMACTX0 + id);
239}
240
241static inline void
242msgrng_send(unsigned int stid)
243{
244 __asm__ volatile (
245 ".set push\n"
246 ".set noreorder\n"
247 "sync\n"
248 // "msgsnd %0\n"
249 "move $8, %0\n"
250 "c2 0x80001\n"
251 ".set pop\n"
252 :: "r" (stid):"$8"
253 );
254}
255
256static inline void
257msgrng_receive(unsigned int pri)
258{
259 __asm__ volatile (
260 ".set push\n"
261 ".set noreorder\n"
262 // "msgld %0\n"
263 "move $8, %0\n"
264 "c2 0x80002\n"
265 ".set pop\n"
266 :: "r" (pri):"$8"
267 );
268}
269static inline void
270msgrng_wait(unsigned int mask)
271{
272 __asm__ volatile (
273 ".set push\n"
274 ".set noreorder\n"
275 // "msgwait %0\n"
276 "move $8, %0\n"
277 "c2 0x80003\n"
278 ".set pop\n"
279 :: "r" (mask):"$8"
280 );
281}
282
283#define msgrng_enable(flags) \
284do { \
285 __asm__ volatile ( \
286 ".set push\n\t" \
287 ".set reorder\n\t" \
288 ".set noat\n\t" \
289 "mfc0 %0, $12\n\t" \
290 "li $8, 0x40000001\n\t" \
291 "or $1, %0, $8\n\t" \
292 "xori $1, 1\n\t" \
293 ".set noreorder\n\t" \
294 "mtc0 $1, $12\n\t" \
295 ".set\tpop\n\t" \
296 : "=r" (flags) \
297 : \
298 : "$8" \
299 ); \
300} while (0)
301
302#define msgrng_disable(flags) __asm__ volatile ( \
303 "mtc0 %0, $12" : : "r" (flags))
304
305#define msgrng_flags_save(flags) msgrng_enable(flags)
306#define msgrng_flags_restore(flags) msgrng_disable(flags)
307
308struct msgrng_msg {
309 __uint64_t msg0;
310 __uint64_t msg1;
311 __uint64_t msg2;
312 __uint64_t msg3;
313};
314
315static inline void
316message_send_block_fast(int size, unsigned int code, unsigned int stid,
317 unsigned long long msg0, unsigned long long msg1,
318 unsigned long long msg2, unsigned long long msg3)
319{
320 __asm__ __volatile__(".set push\n"
321 ".set noreorder\n"
322 ".set mips64\n"
323 "dmtc2 %1, $0, 0\n"
324 "dmtc2 %2, $0, 1\n"
325 "dmtc2 %3, $0, 2\n"
326 "dmtc2 %4, $0, 3\n"
327 "move $8, %0\n"
328 "1: c2 0x80001\n"
329 "mfc2 $8, $2\n"
330 "andi $8, $8, 0x6\n"
331 "bnez $8, 1b\n"
332 "move $8, %0\n"
333 ".set pop\n"
334 :
335 : "r"(((size - 1) << 16) | (code << 8) | stid), "r"(msg0), "r"(msg1), "r"(msg2), "r"(msg3)
336 : "$8"
337 );
338}
339
340#define message_receive_fast(bucket, size, code, stid, msg0, msg1, msg2, msg3) \
341 ( { unsigned int _status=0, _tmp=0; \
342 msgrng_receive(bucket); \
343 while ( (_status=msgrng_read_status()) & 0x08) ; \
344 _tmp = _status & 0x30; \
345 if (__builtin_expect((!_tmp), 1)) { \
346 (size)=((_status & 0xc0)>>6)+1; \
347 (code)=(_status & 0xff00)>>8; \
348 (stid)=(_status & 0x7f0000)>>16; \
349 (msg0)=msgrng_load_rx_msg0(); \
350 (msg1)=msgrng_load_rx_msg1(); \
351 (msg2)=msgrng_load_rx_msg2(); \
352 (msg3)=msgrng_load_rx_msg3(); \
353 _tmp=0; \
354 } \
355 _tmp; \
356 } )
357
358static __inline__ int
359message_send(unsigned int size, unsigned int code,
360 unsigned int stid, struct msgrng_msg *msg)
361{
362 unsigned int dest = 0;
363 unsigned long long status = 0;
364 int i = 0;
365
366 msgrng_load_tx_msg0(msg->msg0);
367 msgrng_load_tx_msg1(msg->msg1);
368 msgrng_load_tx_msg2(msg->msg2);
369 msgrng_load_tx_msg3(msg->msg3);
370
371 dest = ((size - 1) << 16) | (code << 8) | (stid);
372
373 msgrng_send(dest);
374
375 for (i = 0; i < 16; i++) {
376 status = msgrng_read_status();
31 */
32#ifndef _RMI_MSGRING_H_
33#define _RMI_MSGRING_H_
34
35#include <sys/types.h>
36#include <mips/rmi/rmi_mips_exts.h>
37
38#define MSGRNG_TX_BUF_REG 0
39#define MSGRNG_RX_BUF_REG 1
40
41#define MSGRNG_MSG_STATUS_REG 2
42#define MSGRNG_MSG_CONFIG_REG 3
43
44#define MSGRNG_MSG_BUCKSIZE_REG 4
45
46#define MSGRNG_CC_0_REG 16
47#define MSGRNG_CC_1_REG 17
48#define MSGRNG_CC_2_REG 18
49#define MSGRNG_CC_3_REG 19
50#define MSGRNG_CC_4_REG 20
51#define MSGRNG_CC_5_REG 21
52#define MSGRNG_CC_6_REG 22
53#define MSGRNG_CC_7_REG 23
54#define MSGRNG_CC_8_REG 24
55#define MSGRNG_CC_9_REG 25
56#define MSGRNG_CC_10_REG 26
57#define MSGRNG_CC_11_REG 27
58#define MSGRNG_CC_12_REG 28
59#define MSGRNG_CC_13_REG 29
60#define MSGRNG_CC_14_REG 30
61#define MSGRNG_CC_15_REG 31
62
63#define msgrng_read_status() read_c2_register32(MSGRNG_MSG_STATUS_REG, 0)
64
65#define msgrng_read_config() read_c2_register32(MSGRNG_MSG_CONFIG_REG, 0)
66#define msgrng_write_config(value) write_c2_register32(MSGRNG_MSG_CONFIG_REG, 0, value)
67
68#define msgrng_read_bucksize(bucket) read_c2_register32(MSGRNG_MSG_BUCKSIZE_REG, bucket)
69#define msgrng_write_bucksize(bucket, value) write_c2_register32(MSGRNG_MSG_BUCKSIZE_REG, bucket, value)
70
71#define msgrng_read_cc(reg, pri) read_c2_register32(reg, pri)
72#define msgrng_write_cc(reg, value, pri) write_c2_register32(reg, pri, value)
73
74#define msgrng_load_rx_msg0() read_c2_register64(MSGRNG_RX_BUF_REG, 0)
75#define msgrng_load_rx_msg1() read_c2_register64(MSGRNG_RX_BUF_REG, 1)
76#define msgrng_load_rx_msg2() read_c2_register64(MSGRNG_RX_BUF_REG, 2)
77#define msgrng_load_rx_msg3() read_c2_register64(MSGRNG_RX_BUF_REG, 3)
78
79#define msgrng_load_tx_msg0(value) write_c2_register64(MSGRNG_TX_BUF_REG, 0, value)
80#define msgrng_load_tx_msg1(value) write_c2_register64(MSGRNG_TX_BUF_REG, 1, value)
81#define msgrng_load_tx_msg2(value) write_c2_register64(MSGRNG_TX_BUF_REG, 2, value)
82#define msgrng_load_tx_msg3(value) write_c2_register64(MSGRNG_TX_BUF_REG, 3, value)
83
84/* Station IDs */
85#define MSGRNG_STNID_CPU0 0x00
86#define MSGRNG_STNID_CPU1 0x08
87#define MSGRNG_STNID_CPU2 0x10
88#define MSGRNG_STNID_CPU3 0x18
89#define MSGRNG_STNID_CPU4 0x20
90#define MSGRNG_STNID_CPU5 0x28
91#define MSGRNG_STNID_CPU6 0x30
92#define MSGRNG_STNID_CPU7 0x38
93#define MSGRNG_STNID_XGS0_TX 64
94#define MSGRNG_STNID_XMAC0_00_TX 64
95#define MSGRNG_STNID_XMAC0_01_TX 65
96#define MSGRNG_STNID_XMAC0_02_TX 66
97#define MSGRNG_STNID_XMAC0_03_TX 67
98#define MSGRNG_STNID_XMAC0_04_TX 68
99#define MSGRNG_STNID_XMAC0_05_TX 69
100#define MSGRNG_STNID_XMAC0_06_TX 70
101#define MSGRNG_STNID_XMAC0_07_TX 71
102#define MSGRNG_STNID_XMAC0_08_TX 72
103#define MSGRNG_STNID_XMAC0_09_TX 73
104#define MSGRNG_STNID_XMAC0_10_TX 74
105#define MSGRNG_STNID_XMAC0_11_TX 75
106#define MSGRNG_STNID_XMAC0_12_TX 76
107#define MSGRNG_STNID_XMAC0_13_TX 77
108#define MSGRNG_STNID_XMAC0_14_TX 78
109#define MSGRNG_STNID_XMAC0_15_TX 79
110
111#define MSGRNG_STNID_XGS1_TX 80
112#define MSGRNG_STNID_XMAC1_00_TX 80
113#define MSGRNG_STNID_XMAC1_01_TX 81
114#define MSGRNG_STNID_XMAC1_02_TX 82
115#define MSGRNG_STNID_XMAC1_03_TX 83
116#define MSGRNG_STNID_XMAC1_04_TX 84
117#define MSGRNG_STNID_XMAC1_05_TX 85
118#define MSGRNG_STNID_XMAC1_06_TX 86
119#define MSGRNG_STNID_XMAC1_07_TX 87
120#define MSGRNG_STNID_XMAC1_08_TX 88
121#define MSGRNG_STNID_XMAC1_09_TX 89
122#define MSGRNG_STNID_XMAC1_10_TX 90
123#define MSGRNG_STNID_XMAC1_11_TX 91
124#define MSGRNG_STNID_XMAC1_12_TX 92
125#define MSGRNG_STNID_XMAC1_13_TX 93
126#define MSGRNG_STNID_XMAC1_14_TX 94
127#define MSGRNG_STNID_XMAC1_15_TX 95
128
129#define MSGRNG_STNID_GMAC 96
130#define MSGRNG_STNID_GMACJFR_0 96
131#define MSGRNG_STNID_GMACRFR_0 97
132#define MSGRNG_STNID_GMACTX0 98
133#define MSGRNG_STNID_GMACTX1 99
134#define MSGRNG_STNID_GMACTX2 100
135#define MSGRNG_STNID_GMACTX3 101
136#define MSGRNG_STNID_GMACJFR_1 102
137#define MSGRNG_STNID_GMACRFR_1 103
138
139#define MSGRNG_STNID_DMA 104
140#define MSGRNG_STNID_DMA_0 104
141#define MSGRNG_STNID_DMA_1 105
142#define MSGRNG_STNID_DMA_2 106
143#define MSGRNG_STNID_DMA_3 107
144
145#define MSGRNG_STNID_XGS0FR 112
146#define MSGRNG_STNID_XMAC0JFR 112
147#define MSGRNG_STNID_XMAC0RFR 113
148
149#define MSGRNG_STNID_XGS1FR 114
150#define MSGRNG_STNID_XMAC1JFR 114
151#define MSGRNG_STNID_XMAC1RFR 115
152#define MSGRNG_STNID_SEC 120
153#define MSGRNG_STNID_SEC0 120
154#define MSGRNG_STNID_SEC1 121
155#define MSGRNG_STNID_SEC2 122
156#define MSGRNG_STNID_SEC3 123
157#define MSGRNG_STNID_PK0 124
158#define MSGRNG_STNID_SEC_RSA 124
159#define MSGRNG_STNID_SEC_RSVD0 125
160#define MSGRNG_STNID_SEC_RSVD1 126
161#define MSGRNG_STNID_SEC_RSVD2 127
162
163#define MSGRNG_STNID_GMAC1 80
164#define MSGRNG_STNID_GMAC1_FR_0 81
165#define MSGRNG_STNID_GMAC1_TX0 82
166#define MSGRNG_STNID_GMAC1_TX1 83
167#define MSGRNG_STNID_GMAC1_TX2 84
168#define MSGRNG_STNID_GMAC1_TX3 85
169#define MSGRNG_STNID_GMAC1_FR_1 87
170#define MSGRNG_STNID_GMAC0 96
171#define MSGRNG_STNID_GMAC0_FR_0 97
172#define MSGRNG_STNID_GMAC0_TX0 98
173#define MSGRNG_STNID_GMAC0_TX1 99
174#define MSGRNG_STNID_GMAC0_TX2 100
175#define MSGRNG_STNID_GMAC0_TX3 101
176#define MSGRNG_STNID_GMAC0_FR_1 103
177#define MSGRNG_STNID_CMP_0 108
178#define MSGRNG_STNID_CMP_1 109
179#define MSGRNG_STNID_CMP_2 110
180#define MSGRNG_STNID_CMP_3 111
181#define MSGRNG_STNID_PCIE_0 116
182#define MSGRNG_STNID_PCIE_1 117
183#define MSGRNG_STNID_PCIE_2 118
184#define MSGRNG_STNID_PCIE_3 119
185#define MSGRNG_STNID_XLS_PK0 121
186
187#define MSGRNG_CODE_MAC 0
188#define MSGRNG_CODE_XGMAC 2
189#define MSGRNG_CODE_SEC 0
190#define MSGRNG_CODE_BOOT_WAKEUP 200
191#define MSGRNG_CODE_SPI4 3
192
193static inline int
194msgrng_xgmac_stid_rfr(int id)
195{
196 return !id ? MSGRNG_STNID_XMAC0RFR : MSGRNG_STNID_XMAC1RFR;
197}
198
199static inline int
200msgrng_xgmac_stid_jfr(int id)
201{
202 return !id ? MSGRNG_STNID_XMAC0JFR : MSGRNG_STNID_XMAC1JFR;
203}
204
205static inline int
206msgrng_xgmac_stid_tx(int id)
207{
208 return !id ? MSGRNG_STNID_XMAC0_00_TX : MSGRNG_STNID_XMAC1_00_TX;
209}
210
211static inline int
212msgrng_gmac_stid_rfr(int id)
213{
214 return (MSGRNG_STNID_GMACRFR_0);
215}
216
217static inline int
218msgrng_gmac_stid_rfr_split_mode(int id)
219{
220 return ((id >> 1) ? MSGRNG_STNID_GMACRFR_1 : MSGRNG_STNID_GMACRFR_0);
221}
222
223static inline int
224msgrng_gmac_stid_jfr(int id)
225{
226 return MSGRNG_STNID_GMACJFR_0;
227}
228
229static inline int
230msgrng_gmac_stid_jfr_split_mode(int id)
231{
232 return ((id >> 1) ? MSGRNG_STNID_GMACJFR_1 : MSGRNG_STNID_GMACJFR_0);
233}
234
235static inline int
236msgrng_gmac_stid_tx(int id)
237{
238 return (MSGRNG_STNID_GMACTX0 + id);
239}
240
241static inline void
242msgrng_send(unsigned int stid)
243{
244 __asm__ volatile (
245 ".set push\n"
246 ".set noreorder\n"
247 "sync\n"
248 // "msgsnd %0\n"
249 "move $8, %0\n"
250 "c2 0x80001\n"
251 ".set pop\n"
252 :: "r" (stid):"$8"
253 );
254}
255
256static inline void
257msgrng_receive(unsigned int pri)
258{
259 __asm__ volatile (
260 ".set push\n"
261 ".set noreorder\n"
262 // "msgld %0\n"
263 "move $8, %0\n"
264 "c2 0x80002\n"
265 ".set pop\n"
266 :: "r" (pri):"$8"
267 );
268}
269static inline void
270msgrng_wait(unsigned int mask)
271{
272 __asm__ volatile (
273 ".set push\n"
274 ".set noreorder\n"
275 // "msgwait %0\n"
276 "move $8, %0\n"
277 "c2 0x80003\n"
278 ".set pop\n"
279 :: "r" (mask):"$8"
280 );
281}
282
283#define msgrng_enable(flags) \
284do { \
285 __asm__ volatile ( \
286 ".set push\n\t" \
287 ".set reorder\n\t" \
288 ".set noat\n\t" \
289 "mfc0 %0, $12\n\t" \
290 "li $8, 0x40000001\n\t" \
291 "or $1, %0, $8\n\t" \
292 "xori $1, 1\n\t" \
293 ".set noreorder\n\t" \
294 "mtc0 $1, $12\n\t" \
295 ".set\tpop\n\t" \
296 : "=r" (flags) \
297 : \
298 : "$8" \
299 ); \
300} while (0)
301
302#define msgrng_disable(flags) __asm__ volatile ( \
303 "mtc0 %0, $12" : : "r" (flags))
304
305#define msgrng_flags_save(flags) msgrng_enable(flags)
306#define msgrng_flags_restore(flags) msgrng_disable(flags)
307
308struct msgrng_msg {
309 __uint64_t msg0;
310 __uint64_t msg1;
311 __uint64_t msg2;
312 __uint64_t msg3;
313};
314
315static inline void
316message_send_block_fast(int size, unsigned int code, unsigned int stid,
317 unsigned long long msg0, unsigned long long msg1,
318 unsigned long long msg2, unsigned long long msg3)
319{
320 __asm__ __volatile__(".set push\n"
321 ".set noreorder\n"
322 ".set mips64\n"
323 "dmtc2 %1, $0, 0\n"
324 "dmtc2 %2, $0, 1\n"
325 "dmtc2 %3, $0, 2\n"
326 "dmtc2 %4, $0, 3\n"
327 "move $8, %0\n"
328 "1: c2 0x80001\n"
329 "mfc2 $8, $2\n"
330 "andi $8, $8, 0x6\n"
331 "bnez $8, 1b\n"
332 "move $8, %0\n"
333 ".set pop\n"
334 :
335 : "r"(((size - 1) << 16) | (code << 8) | stid), "r"(msg0), "r"(msg1), "r"(msg2), "r"(msg3)
336 : "$8"
337 );
338}
339
340#define message_receive_fast(bucket, size, code, stid, msg0, msg1, msg2, msg3) \
341 ( { unsigned int _status=0, _tmp=0; \
342 msgrng_receive(bucket); \
343 while ( (_status=msgrng_read_status()) & 0x08) ; \
344 _tmp = _status & 0x30; \
345 if (__builtin_expect((!_tmp), 1)) { \
346 (size)=((_status & 0xc0)>>6)+1; \
347 (code)=(_status & 0xff00)>>8; \
348 (stid)=(_status & 0x7f0000)>>16; \
349 (msg0)=msgrng_load_rx_msg0(); \
350 (msg1)=msgrng_load_rx_msg1(); \
351 (msg2)=msgrng_load_rx_msg2(); \
352 (msg3)=msgrng_load_rx_msg3(); \
353 _tmp=0; \
354 } \
355 _tmp; \
356 } )
357
358static __inline__ int
359message_send(unsigned int size, unsigned int code,
360 unsigned int stid, struct msgrng_msg *msg)
361{
362 unsigned int dest = 0;
363 unsigned long long status = 0;
364 int i = 0;
365
366 msgrng_load_tx_msg0(msg->msg0);
367 msgrng_load_tx_msg1(msg->msg1);
368 msgrng_load_tx_msg2(msg->msg2);
369 msgrng_load_tx_msg3(msg->msg3);
370
371 dest = ((size - 1) << 16) | (code << 8) | (stid);
372
373 msgrng_send(dest);
374
375 for (i = 0; i < 16; i++) {
376 status = msgrng_read_status();
377 //dbg_msg("status = %Lx\n", status);
378
379 if (status & 0x6) {
380 continue;
381 } else
382 break;
383 }
377
378 if (status & 0x6) {
379 continue;
380 } else
381 break;
382 }
384 if (i == 16) {
385 if (dest == 0x61)
386 //dbg_msg("Processor %x: Unable to send msg to %llx\n", processor_id(), dest);
387 return status & 0x6;
388 }
389 return msgrng_read_status() & 0x06;
390}
391
392static __inline__ int
393message_send_retry(unsigned int size, unsigned int code,
394 unsigned int stid, struct msgrng_msg *msg)
395{
396 int res = 0;
397 int retry = 0;
398
399 for (;;) {
400 res = message_send(size, code, stid, msg);
401 /* retry a pending fail */
402 if (res & 0x02)
403 continue;
404 /* credit fail */
405 if (res & 0x04)
406 retry++;
407 else
408 break;
409 if (retry == 4)
410 return res & 0x06;
411 }
412
413 return 0;
414}
415
416static __inline__ int
417message_receive(int pri, int *size, int *code, int *src_id,
418 struct msgrng_msg *msg)
419{
383 return msgrng_read_status() & 0x06;
384}
385
386static __inline__ int
387message_send_retry(unsigned int size, unsigned int code,
388 unsigned int stid, struct msgrng_msg *msg)
389{
390 int res = 0;
391 int retry = 0;
392
393 for (;;) {
394 res = message_send(size, code, stid, msg);
395 /* retry a pending fail */
396 if (res & 0x02)
397 continue;
398 /* credit fail */
399 if (res & 0x04)
400 retry++;
401 else
402 break;
403 if (retry == 4)
404 return res & 0x06;
405 }
406
407 return 0;
408}
409
410static __inline__ int
411message_receive(int pri, int *size, int *code, int *src_id,
412 struct msgrng_msg *msg)
413{
420 int res = message_receive_fast(pri, *size, *code, *src_id, msg->msg0, msg->msg1, msg->msg2, msg->msg3);
421
422#ifdef MSGRING_DUMP_MESSAGES
423 if (!res) {
424 dbg_msg("Received msg <%llx, %llx, %llx, %llx> <%d,%d,%d>\n",
425 msg->msg0, msg->msg1, msg->msg2, msg->msg3,
426 *size, *code, *src_id);
427 }
428#endif
429
414 int res;
415
416 res = message_receive_fast(pri, *size, *code, *src_id,
417 msg->msg0, msg->msg1, msg->msg2, msg->msg3);
430 return res;
431}
432
433#define MSGRNG_STN_RX_QSIZE 256
434
435struct stn_cc {
436 unsigned short counters[16][8];
437};
438
439struct bucket_size {
440 unsigned short bucket[128];
441};
442
443extern struct bucket_size bucket_sizes;
444
445extern struct stn_cc cc_table_cpu_0;
446extern struct stn_cc cc_table_cpu_1;
447extern struct stn_cc cc_table_cpu_2;
448extern struct stn_cc cc_table_cpu_3;
449extern struct stn_cc cc_table_cpu_4;
450extern struct stn_cc cc_table_cpu_5;
451extern struct stn_cc cc_table_cpu_6;
452extern struct stn_cc cc_table_cpu_7;
453extern struct stn_cc cc_table_xgs_0;
454extern struct stn_cc cc_table_xgs_1;
455extern struct stn_cc cc_table_gmac;
456extern struct stn_cc cc_table_dma;
457extern struct stn_cc cc_table_sec;
458
459extern struct bucket_size xls_bucket_sizes;
460
461extern struct stn_cc xls_cc_table_cpu_0;
462extern struct stn_cc xls_cc_table_cpu_1;
463extern struct stn_cc xls_cc_table_cpu_2;
464extern struct stn_cc xls_cc_table_cpu_3;
465extern struct stn_cc xls_cc_table_gmac0;
466extern struct stn_cc xls_cc_table_gmac1;
467extern struct stn_cc xls_cc_table_cmp;
468extern struct stn_cc xls_cc_table_pcie;
469extern struct stn_cc xls_cc_table_dma;
470extern struct stn_cc xls_cc_table_sec;
471
472
473#define msgrng_access_save(lock, mflags) do { \
474 mtx_lock_spin(lock); \
475 msgrng_flags_save(mflags); \
476 }while(0)
477
478#define msgrng_access_restore(lock, mflags) do { \
479 msgrng_flags_restore(mflags); \
480 mtx_unlock_spin(lock); \
481 }while(0)
482
483#define msgrng_access_enable(mflags) do { \
484 critical_enter(); \
485 msgrng_flags_save(mflags); \
486} while(0)
487
488#define msgrng_access_disable(mflags) do { \
489 msgrng_flags_restore(mflags); \
490 critical_exit(); \
491} while(0)
492
493/*
494 * NOTE: this is not stationid/8, ie the station numbers below are just
495 * for internal use
496 */
497enum {
498 TX_STN_CPU_0,
499 TX_STN_CPU_1,
500 TX_STN_CPU_2,
501 TX_STN_CPU_3,
502 TX_STN_CPU_4,
503 TX_STN_CPU_5,
504 TX_STN_CPU_6,
505 TX_STN_CPU_7,
506 TX_STN_GMAC,
507 TX_STN_DMA,
508 TX_STN_XGS_0,
509 TX_STN_XGS_1,
510 TX_STN_SAE,
511 TX_STN_GMAC0,
512 TX_STN_GMAC1,
513 TX_STN_CDE,
514 TX_STN_PCIE,
515 TX_STN_INVALID,
516 MAX_TX_STNS
517};
518
519extern int
520register_msgring_handler(int major,
521 void (*action) (int, int, int, int, struct msgrng_msg *, void *),
522 void *dev_id);
523 extern void xlr_msgring_cpu_init(void);
524
525 extern void xlr_msgring_config(void);
526
527#define cpu_to_msgring_bucket(cpu) ((((cpu) >> 2)<<3)|((cpu) & 0x03))
528
529#endif
418 return res;
419}
420
421#define MSGRNG_STN_RX_QSIZE 256
422
423struct stn_cc {
424 unsigned short counters[16][8];
425};
426
427struct bucket_size {
428 unsigned short bucket[128];
429};
430
431extern struct bucket_size bucket_sizes;
432
433extern struct stn_cc cc_table_cpu_0;
434extern struct stn_cc cc_table_cpu_1;
435extern struct stn_cc cc_table_cpu_2;
436extern struct stn_cc cc_table_cpu_3;
437extern struct stn_cc cc_table_cpu_4;
438extern struct stn_cc cc_table_cpu_5;
439extern struct stn_cc cc_table_cpu_6;
440extern struct stn_cc cc_table_cpu_7;
441extern struct stn_cc cc_table_xgs_0;
442extern struct stn_cc cc_table_xgs_1;
443extern struct stn_cc cc_table_gmac;
444extern struct stn_cc cc_table_dma;
445extern struct stn_cc cc_table_sec;
446
447extern struct bucket_size xls_bucket_sizes;
448
449extern struct stn_cc xls_cc_table_cpu_0;
450extern struct stn_cc xls_cc_table_cpu_1;
451extern struct stn_cc xls_cc_table_cpu_2;
452extern struct stn_cc xls_cc_table_cpu_3;
453extern struct stn_cc xls_cc_table_gmac0;
454extern struct stn_cc xls_cc_table_gmac1;
455extern struct stn_cc xls_cc_table_cmp;
456extern struct stn_cc xls_cc_table_pcie;
457extern struct stn_cc xls_cc_table_dma;
458extern struct stn_cc xls_cc_table_sec;
459
460
461#define msgrng_access_save(lock, mflags) do { \
462 mtx_lock_spin(lock); \
463 msgrng_flags_save(mflags); \
464 }while(0)
465
466#define msgrng_access_restore(lock, mflags) do { \
467 msgrng_flags_restore(mflags); \
468 mtx_unlock_spin(lock); \
469 }while(0)
470
471#define msgrng_access_enable(mflags) do { \
472 critical_enter(); \
473 msgrng_flags_save(mflags); \
474} while(0)
475
476#define msgrng_access_disable(mflags) do { \
477 msgrng_flags_restore(mflags); \
478 critical_exit(); \
479} while(0)
480
481/*
482 * NOTE: this is not stationid/8, ie the station numbers below are just
483 * for internal use
484 */
485enum {
486 TX_STN_CPU_0,
487 TX_STN_CPU_1,
488 TX_STN_CPU_2,
489 TX_STN_CPU_3,
490 TX_STN_CPU_4,
491 TX_STN_CPU_5,
492 TX_STN_CPU_6,
493 TX_STN_CPU_7,
494 TX_STN_GMAC,
495 TX_STN_DMA,
496 TX_STN_XGS_0,
497 TX_STN_XGS_1,
498 TX_STN_SAE,
499 TX_STN_GMAC0,
500 TX_STN_GMAC1,
501 TX_STN_CDE,
502 TX_STN_PCIE,
503 TX_STN_INVALID,
504 MAX_TX_STNS
505};
506
507extern int
508register_msgring_handler(int major,
509 void (*action) (int, int, int, int, struct msgrng_msg *, void *),
510 void *dev_id);
511 extern void xlr_msgring_cpu_init(void);
512
513 extern void xlr_msgring_config(void);
514
515#define cpu_to_msgring_bucket(cpu) ((((cpu) >> 2)<<3)|((cpu) & 0x03))
516
517#endif