2
* RX ucode for the Intel IXP2400 in POS-PHY mode.
3
* Copyright (C) 2004, 2005 Lennert Buytenhek
4
* Dedicated to Marija Kulikova.
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 2 of the License, or
9
* (at your option) any later version.
11
* Assumptions made in this code:
12
* - The IXP2400 MSF is configured for POS-PHY mode, in a mode where
13
* only one full element list is used. This includes, for example,
14
* 1x32 SPHY and 1x32 MPHY32, but not 4x8 SPHY or 1x32 MPHY4. (This
15
* is not an exhaustive list.)
16
* - The RBUF uses 64-byte mpackets.
17
* - RX descriptors reside in SRAM, and have the following format:
28
* - Packet data resides in DRAM.
29
* - Packet buffer addresses are 8-byte aligned.
30
* - Scratch ring 0 is rx_pending.
31
* - Scratch ring 1 is rx_done, and has status condition 'full'.
32
* - The host triggers rx_done flush and rx_pending refill on seeing INTA.
33
* - This code is run on all eight threads of the microengine it runs on.
35
* Local memory is used for per-channel RX state.
38
#define RX_THREAD_FREELIST_0 0x0030
39
#define RBUF_ELEMENT_DONE 0x0044
41
#define CHANNEL_FLAGS *l$index0[0]
42
#define CHANNEL_FLAG_RECEIVING 1
43
#define PACKET_LENGTH *l$index0[1]
44
#define PACKET_CHECKSUM *l$index0[2]
45
#define BUFFER_HANDLE *l$index0[3]
46
#define BUFFER_START *l$index0[4]
47
#define BUFFER_LENGTH *l$index0[5]
49
#define CHANNEL_STATE_SIZE 24 // in bytes
50
#define CHANNEL_STATE_SHIFT 5 // ceil(log2(state size))
58
.reg add_to_rx_freelist
59
.reg read $rsw0, $rsw1
60
.xfer_order $rsw0 $rsw1
65
* Initialise add_to_rx_freelist.
71
immed[add_to_rx_freelist, RX_THREAD_FREELIST_0]
72
immed_w1[add_to_rx_freelist, (&$rsw0 | (&mpacket_arrived << 12))]
74
local_csr_rd[ACTIVE_CTX_STS]
76
alu[temp2, temp, and, 0x1f]
77
alu_shf[add_to_rx_freelist, add_to_rx_freelist, or, temp2, <<20]
78
alu[temp2, temp, and, 0x80]
79
alu_shf[add_to_rx_freelist, add_to_rx_freelist, or, temp2, <<18]
85
* Skip context 0 initialisation?
88
br!=ctx[0, mpacket_receive_loop#]
92
* Initialise local memory.
100
alu_shf[addr, --, b, temp, <<CHANNEL_STATE_SHIFT]
101
local_csr_wr[ACTIVE_LM_ADDR_0, addr]
106
immed[CHANNEL_FLAGS, 0]
108
alu[temp, temp, +, 1]
109
alu[--, temp, and, 0x20]
110
beq[init_local_mem_loop#]
114
* Initialise signal pipeline.
117
local_csr_wr[SAME_ME_SIGNAL, (&sig1 << 3)]
120
local_csr_wr[SAME_ME_SIGNAL, (&sig2 << 3)]
123
local_csr_wr[SAME_ME_SIGNAL, (&sig3 << 3)]
127
mpacket_receive_loop#:
129
* Synchronise and wait for mpacket.
133
local_csr_wr[SAME_ME_SIGNAL, (0x80 | (&sig1 << 3))]
135
msf[fast_wr, --, add_to_rx_freelist, 0]
136
.set_sig mpacket_arrived
137
ctx_arb[mpacket_arrived]
142
* We halt if we see {inbparerr,parerr,null,soperror}.
145
alu_shf[--, 0x1b, and, $rsw0, >>8]
150
* Point local memory pointer to this channel's state area.
155
alu[chanaddr, $rsw0, and, 0x1f]
156
alu_shf[chanaddr, --, b, chanaddr, <<CHANNEL_STATE_SHIFT]
157
local_csr_wr[ACTIVE_LM_ADDR_0, chanaddr]
164
* Check whether we received a SOP mpacket while we were already
165
* working on a packet, or a non-SOP mpacket while there was no
166
* packet pending. (SOP == RECEIVING -> abort) If everything's
167
* okay, update the RECEIVING flag to reflect our new state.
173
#if CHANNEL_FLAG_RECEIVING != 1
174
#error CHANNEL_FLAG_RECEIVING is not 1
177
alu_shf[temp, 1, and, $rsw0, >>15]
178
alu[temp, temp, xor, CHANNEL_FLAGS]
179
alu[--, temp, and, CHANNEL_FLAG_RECEIVING]
182
alu_shf[eop, 1, and, $rsw0, >>14]
183
alu[CHANNEL_FLAGS, temp, xor, eop]
187
* Copy the mpacket into the right spot, and in case of EOP,
188
* write back the descriptor and pass the packet on.
193
.reg _packet_checksum
199
* Determine buffer_offset, _packet_length and
205
alu[--, 1, and, $rsw0, >>15]
208
immed[PACKET_LENGTH, 0]
209
immed[PACKET_CHECKSUM, 0]
212
alu[buffer_offset, --, b, PACKET_LENGTH]
213
alu_shf[temp, 0xff, and, $rsw0, >>16]
214
alu[_packet_length, buffer_offset, +, temp]
215
alu[PACKET_LENGTH, --, b, _packet_length]
218
alu[temp, $rsw1, and, temp]
219
alu[_packet_checksum, PACKET_CHECKSUM, +, temp]
220
alu[PACKET_CHECKSUM, --, b, _packet_checksum]
224
* Allocate buffer in case of SOP.
229
alu[temp, 1, and, $rsw0, >>15]
230
beq[skip_buffer_alloc#]
234
.reg read $stemp $stemp2
235
.xfer_order $stemp $stemp2
238
scratch[get, $stemp, zero, 0, 1], ctx_swap[zzz]
239
alu[_buffer_handle, --, b, $stemp]
242
sram[read, $stemp, _buffer_handle, 0, 2],
244
alu[_buffer_start, --, b, $stemp]
245
alu[_buffer_length, --, b, $stemp2]
256
local_csr_wr[SAME_ME_SIGNAL, (0x80 | (&sig2 << 3))]
260
* Synchronise buffer state.
265
alu[temp, 1, and, $rsw0, >>15]
266
beq[copy_from_local_mem#]
268
alu[BUFFER_HANDLE, --, b, _buffer_handle]
269
alu[BUFFER_START, --, b, _buffer_start]
270
alu[BUFFER_LENGTH, --, b, _buffer_length]
273
copy_from_local_mem#:
274
alu[_buffer_handle, --, b, BUFFER_HANDLE]
275
alu[_buffer_start, --, b, BUFFER_START]
276
alu[_buffer_length, --, b, BUFFER_LENGTH]
283
* Debug buffer state management.
288
alu[temp, 1, and, $rsw0, >>14]
290
immed[BUFFER_HANDLE, 0xdead]
291
immed[BUFFER_START, 0xdead]
292
immed[BUFFER_LENGTH, 0xdead]
296
alu[--, _buffer_handle, -, temp]
297
beq[state_corrupted#]
298
alu[--, _buffer_start, -, temp]
299
beq[state_corrupted#]
300
alu[--, _buffer_length, -, temp]
301
beq[state_corrupted#]
306
* Check buffer length.
309
alu[--, _buffer_length, -, _packet_length]
310
blo[buffer_overflow#]
314
* Copy the mpacket and give back the RBUF element.
322
alu_shf[element, 0x7f, and, $rsw0, >>24]
323
alu_shf[xfer_size, 0xff, and, $rsw0, >>16]
325
alu[xfer_size, xfer_size, -, 1]
326
alu_shf[xfer_size, 0x10, or, xfer_size, >>3]
327
alu_shf[temp, 0x10, or, xfer_size, <<21]
328
alu_shf[temp, temp, or, element, <<11]
329
alu_shf[--, temp, or, 1, <<18]
331
dram[rbuf_rd, --, _buffer_start, buffer_offset, max_8],
332
indirect_ref, sig_done[copy_sig]
335
alu[temp, RBUF_ELEMENT_DONE, or, element, <<16]
336
msf[fast_wr, --, temp, 0]
340
* If EOP, write back the packet descriptor.
343
.reg write $stemp $stemp2
344
.xfer_order $stemp $stemp2
347
alu_shf[--, 1, and, $rsw0, >>14]
350
alu[$stemp, $rsw0, and, 0x1f]
351
alu[$stemp2, --, b, _packet_length]
352
sram[write, $stemp, _buffer_handle, 8, 2], ctx_swap[zzz]
362
local_csr_wr[SAME_ME_SIGNAL, (0x80 | (&sig3 << 3))]
366
* If EOP, put the buffer back onto the scratch ring.
372
br_inp_state[SCR_Ring1_Status, rx_done_ring_overflow#]
374
alu_shf[--, 1, and, $rsw0, >>14]
375
beq[mpacket_receive_loop#]
377
alu[--, 1, and, $rsw0, >>10]
380
alu[$stemp, --, b, _buffer_handle]
381
scratch[put, $stemp, zero, 4, 1], ctx_swap[zzz]
382
cap[fast_wr, 0, XSCALE_INT_A]
383
br[mpacket_receive_loop#]
386
alu[$stemp, --, b, _buffer_handle]
387
scratch[put, $stemp, zero, 0, 1], ctx_swap[zzz]
388
br[mpacket_receive_loop#]
405
rx_done_ring_overflow#: