1 ;
2 ; TEXAS INSTRUMENTS TEXT FILE LICENSE
3 ;
4 ; Copyright (c) 2018-2019 Texas Instruments Incorporated
5 ;
6 ; All rights reserved not granted herein.
7 ;
8 ; Limited License.
9 ;
10 ; Texas Instruments Incorporated grants a world-wide, royalty-free, non-exclusive
11 ; license under copyrights and patents it now or hereafter owns or controls to
12 ; make, have made, use, import, offer to sell and sell ("Utilize") this software
13 ; subject to the terms herein. With respect to the foregoing patent license,
14 ; such license is granted solely to the extent that any such patent is necessary
15 ; to Utilize the software alone. The patent license shall not apply to any
16 ; combinations which include this software, other than combinations with devices
17 ; manufactured by or for TI (“TI Devices”). No hardware patent is licensed hereunder.
18 ;
19 ; Redistributions must preserve existing copyright notices and reproduce this license
20 ; (including the above copyright notice and the disclaimer and (if applicable) source
21 ; code license limitations below) in the documentation and/or other materials provided
22 ; with the distribution.
23 ;
24 ; Redistribution and use in binary form, without modification, are permitted provided
25 ; that the following conditions are met:
26 ; No reverse engineering, decompilation, or disassembly of this software is
27 ; permitted with respect to any software provided in binary form.
28 ; Any redistribution and use are licensed by TI for use only with TI Devices.
29 ; Nothing shall obligate TI to provide you with source code for the software
30 ; licensed and provided to you in object code.
31 ;
32 ; If software source code is provided to you, modification and redistribution of the
33 ; source code are permitted provided that the following conditions are met:
34 ; Any redistribution and use of the source code, including any resulting derivative
35 ; works, are licensed by TI for use only with TI Devices.
36 ; Any redistribution and use of any object code compiled from the source code
37 ; and any resulting derivative works, are licensed by TI for use only with TI Devices.
38 ;
39 ; Neither the name of Texas Instruments Incorporated nor the names of its suppliers
40 ; may be used to endorse or promote products derived from this software without
41 ; specific prior written permission.
42 ;
43 ; DISCLAIMER.
44 ;
45 ; THIS SOFTWARE IS PROVIDED BY TI AND TI’S LICENSORS "AS IS" AND ANY EXPRESS OR IMPLIED
46 ; WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
47 ; AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL TI AND TI’S
48 ; LICENSORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
49 ; CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
50 ; GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
51 ; CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
52 ; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
53 ; EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
55 ;Test Code for RTU {{{1
56 ; 2nd version
57 ; functions:
58 ; TM2 tasks: mirror rx tasks on pRU
59 ; TM1 tasks: scheduler tick, ipc from PRU, ipc from other RTU, txl2 events
60 ; BG task: spin on PSI READ Status, and pull in packet from PSI and send to PORTQ in external memory
61 ; add descriptor to portQ or push descriptor to other RTU
62 ; scheduler: run mostly in sched_tick
63 RX_RAW .set 1
64 ; includes {{{1
65 .include "regs.h"
66 .include "smem.h"
67 .include "spin.h"
68 .include "xfr2vbus_widget.h"
69 .include "xfr2psi_widget.h"
70 .include "tm.h"
71 .include "bsram_rtu.h"
72 .include "reg_alias.h"
73 .include "rx.h"
74 .include "tx.h"
75 .include "portq.h"
76 .include "lebe.h"
77 .include "bpool.h"
78 .include "scheduler.h"
79 .include "ipc.h"
80 .include "filter.h"
81 .include "classi.h"
82 .include "txrate.h"
83 .include "rtu_psi.h"
84 .include "iep.h"
85 .include "psiloop.h"
87 loop_here .macro
88 here?: jmp here?
89 .endm
91 wait4pru_ready .macro
92 .newblock
93 ldi32 r1, PRU_READY
94 ldi32 r0, FW_CONFIG
95 $1: add r0, r0, 0
96 add r0, r0, 0
97 add r0, r0, 0
98 lbbo &r9, r0, CFG_STATUS, 4
99 qbne $1, r9, r1
101 ldi32 r2, RTU_READY
102 sbbo &r2, r0, CFG_RTU_STATUS, 4
103 .endm
105 ; r8 - starting address, r12 - address of the 1st pull size
106 create_8_buff_pools .macro starting_slot
107 .newblock
108 ldi r13, 0
109 ldi r14, starting_slot
110 $1: lbbo &r9, r12, 0, 4
111 BUFP_CREATE r14, r8, r9
112 add r8, r8, r9
113 add r8, r8, 128
114 add r13, r13, 1
115 add r14, r14, 1
116 add r12, r12, 4
117 qbgt $1, r13, 8
118 .endm
120 ;buffps for Ethernet pkts from wire
121 create_all_buff_pools .macro
122 mov r8, r18 ; start from the beginning of the buffer memory
123 ;buffps for PSI pkts for this slice
124 ldi32 r12, FW_CONFIG + CFG_TX_BS_8
125 create_8_buff_pools BP_SLOT0_RTU
126 .endm
128 create_port_queues .macro
129 .newblock
130 ;create portQs :: 8 for this slice and 8 shadow for other slice)
131 ldi r13, 0
132 ldi r14, MQ_SLOT0_RTU
133 ldi32 r0, MQBASE_START
134 ldi r1, PQ_MAX_PKT_RTU
135 $1: MQ_CREATE r14, r0, r1
136 mov r0, r5
137 add r14, r14, 1
138 add r13, r13, 1
139 qbge $1, r13, 8
141 .endm
142 ; Code starts {{{1
143 .retain ; Required for building .out with assembly file
144 .retainrefs ; Required for building .out with assembly file
145 .sect ".text:Start"
146 .global Start
148 Start:
149 TM_DISABLE
150 zero &r0, 124
151 ldi r11, 1
152 ; rtu err counter: b0 = RXdropPsi (widget full), b1=RXdropErr, b2=TXstall, b3= txError
153 ldi r30,0
154 .if $isdefed("WAIT_FOR_DEBUGGER")
155 mov r11, 0
156 .endif
157 start_test:
158 qbeq start_test, r11, 0
160 ; SP_SHIFT_ENABLE
161 ;one time initialization
162 wait4pru_ready
163 ; r0 has FW_CONFIG from previouse macro
164 lbbo &r5, r0, CFG_DEF_FLOW, 8 ; r5 - flow, r6 - flags
165 lbbo &r3, r0, CFG_ADDR_LO, 8;
167 ;r3=addrlo, r4=addrhi (not used. todo check against #define and barf)
168 ;r5 = flow
169 ;r6 = flags
170 ;r7 = portstate (RX) VA - we don't have it anymore
171 ;save def flow & flags
172 ;port state conversion to something useful
174 ldi r0, 0
175 ;default: (3)= fwd plus learn
176 set r0.t3 ;fwd
177 set r0.t4 ;lrn
178 ;hostport tbd
180 .if $isdefed ("VLAN_ENABLED")
181 set r6.t0
182 .endif
183 mov r7, r0
184 RX_TASK_INIT_RTU r6, r5, r7
186 add r18, r3, 0x80 ;skip 128 bytes ..
187 mov r19, r4
188 PAGE_SAVE RTU_GSTATE
190 create_all_buff_pools
191 create_port_queues
193 ;set up PSI INFO, CONTROL, STATUS TEMPLATES
194 .if $isdefed("SLICE0")
195 PSI_SETUP_INFO PSI_INFO_SLOT, 1
196 .else
197 PSI_SETUP_INFO PSI_INFO_SLOT, 2
198 .endif
199 PSI_SETUP_MGR_INFO
200 PSI_SETUP_STATUS PSI_STATUS_SLOT
202 ;initialize txrate limiters for each thread
203 ldi r2, 0
204 TXRATE_INIT 0, r1, r2
205 TXRATE_INIT 1, r1, r2
206 TXRATE_INIT 2, r1, r2
207 TXRATE_INIT 3, r1, r2
209 ;setup taskmanager
210 TM_RTU_CONFIG TX_EOD_P, TX_EOD_E, TM_NOP, TX_EOF, TM_NOP, TM_NOP, rtu_rx_task2, TM_NOP, TM_NOP, TM_NOP
211 TM_ENABLE
213 ;set up IEP - assume this only needs to get done once
214 SET_IEP_SYNC_MODE IEP_CFG1_BASEx
215 ENABLE_IEP IEP_BASEx
217 ;r2-r3 are scratch
218 ldi r4, 400 ;every 400ns
219 SET_CMP8_15 IEP_BASEx, 56, r2, r3, r4
220 ENABLE_CMP IEP_BASEx, 15, r2
222 ;we READY FOR NEW PACKET
223 zero &Ctx, 20 ;now set ingress context
225 ;---------------start test------------ {{{1
226 ;init scheduler
227 zero &GRrtu.pqmap, 4
228 ldi GRrtu.qmask, NORM_QMASK ;look at all queues
230 ;intialize PS global state
231 ldi GRrtu.StallMask, 0xf ;no stalls
232 QLOCK_INIT ;clear resource lock
233 ldi GRrtu.ActThrdNum, 0 ;nothing active
234 ldi GRrtu.StallReason, 0 ;no stall reason
236 ;-------------------------------
237 ; RTU BG LOOP {{{1
238 ;-------------------------------
239 bg_loop:
241 ;start of psi host egress handler
242 ;-------------------------------------------------------------
243 ; psi is Idle, meaning we aren't actively bring in data from a
244 ; PSI thread. But we may be stalled
245 ;-------------------------------------------------------------
246 psi_idle:
247 xin XID_PSI_S, &r1, 8
248 and r1.b0, r1.b0, GRrtu.StallMask
249 qbeq no_psi, r1.b0, 0
251 qbbc $1, r1, 0
252 ldi GRrtu.ActThrdNum, 0x0
253 and GRrtu.StallReason, GRrtu.StallReason, 0xfc
254 jmp start_psi
256 $1: qbbc $2, r1, 1
257 ldi GRrtu.ActThrdNum, 1
258 and GRrtu.StallReason, GRrtu.StallReason, 0xf3
259 jmp start_psi
261 $2: qbbc $3, r1, 2
262 ldi GRrtu.ActThrdNum, 2
263 and GRrtu.StallReason, GRrtu.StallReason, 0xcf
264 jmp start_psi
266 $3: qbbc no_psi, r1, 3
267 ldi GRrtu.ActThrdNum, 3
268 and GRrtu.StallReason, GRrtu.StallReason, 0x3f
269 jmp start_psi
271 no_psi: jmp psi_idle2
272 psi_idle3:
273 CALL_SUB sstate_00, psi_idle
274 jmp psi_idle
276 ;---------------------------------------
277 ;PSI is idle but we may have stalled threads
278 ;---------------------------------------
279 psi_idle2:
280 ;see if we can unstall anyone
281 qbeq psi_idle3, GRrtu.StallMask, 0x0f
283 ;make sure r16, r17 dont get stomped on!!!
284 ldi r16, 0
285 ldi r17, PSI_CNTX0_SLOT
286 unstall_loop:
287 qbbs skipu, GRrtu.StallMask, r16
288 TRY_UNSTALL r16, r17, skipu
289 skipu:
290 add r16, r16, 1
291 add r17, r17, 1
292 qbgt unstall_loop, r16, 4
293 jmp psi_idle3
295 mgr_pkt:
296 RTU_POLL_SLOTx GRrtu.ActThrdNum
297 PSI_READ GRrtu.ActThrdNum, 20
298 ldi32 r0, MD_CONTROL0
299 qbeq mgr_pkt, r1, r0
300 qbne mgr_pkt01, r1.b2, 0x14;
301 ; we have 16 bytes of packet now
302 ; process mgr data
303 LEBE_GO r2, 16
304 qbne mgr_pkt01, r2.b3, 0x81 ; not a management packet
305 mov GRrtu.seq_num, r2.b1 ; save seq_num
306 qbne mgr_pkt10, r2.b2, 0x01 ; shutdown command
307 MGR_SHUTDOWN
308 ldi32 r2, 0x81010001 ; response OK
309 mov r2.b1, GRrtu.seq_num
310 TM_DISABLE
311 SEND_MGR_PKT
312 ldi32 r0, FW_CONFIG
313 ldi32 r1, RTU_STOPPED
314 sbbo &r1, r0, CFG_RTU_STATUS, 4
315 loop_here
317 mgr_pkt10:
318 qbne mgr_pkt20, r2.b2, 0x02 ; set port state
319 ; execute it here
320 jmp mgr_unknown
321 jmp mgr_pkt02
323 mgr_pkt20:
325 mgr_unknown:
326 ldi r2.b0, 0x10
327 mov r2.b1, GRrtu.seq_num
328 SEND_MGR_PKT
329 jmp psi_idle
331 mgr_pkt01:
332 branch_if_eop mgr_pkt02
333 WAIT_EOP
334 mgr_pkt02:
335 jmp psi_idle
337 ;-------------------------
338 ; process active thread
339 ; GRrtu.ActThrdNum = bit of active thread set
340 ; GRrtu.StallMask = cleared bits => stalled threads
341 ; GRrtu.StallReason = reason for stalled threads
342 ; GRrtu.ResLock = resource locks taken
343 ;------------------------
344 start_psi:
345 ;S0: read in INFO
346 RTU_PSI_IN_S0 err_exit00, stall_exit00, mgr_pkt
347 unstall00:
349 ;S1: wait for 1st DATA or control
350 wait_1stdata0:
351 RTU_POLL_SLOTx GRrtu.ActThrdNum
352 RTU_PSI_IN_S1 err_exit01, wait_1stdata0
353 CALL_SUB sstate_00, wait_fdb_done0
355 ;F0: wait for FDB result
356 ;todo: optimizaton: bring in next 2x16 while fdb in progress
357 wait_fdb_done0:
358 unstall01:
359 RTU_PSI_IN_F0_PART2 stall_exit01, stall_exit02
360 unstall02:
361 ;r2, 3, 4 wait for remaining 3x16B
362 qbeq sr20, GRrtu.ActThrdNum, 0
363 qbeq sr21, GRrtu.ActThrdNum, 1
364 qbeq sr22, GRrtu.ActThrdNum, 2
365 RTU_PSI_READ_SR2_4 XID_PSI_R4, BS_SLOT_PSI3, loop_psi0_0, eop_exit00, eop_exit01
366 sr22: RTU_PSI_READ_SR2_4 XID_PSI_R3, BS_SLOT_PSI2, loop_psi0_0, eop_exit00, eop_exit01
367 sr21: RTU_PSI_READ_SR2_4 XID_PSI_R2, BS_SLOT_PSI1, loop_psi0_0, eop_exit00, eop_exit01
368 sr20: RTU_PSI_READ_SR2_4 XID_PSI_R1, BS_SLOT_PSI0, loop_psi0_0, eop_exit00, eop_exit01
370 loop_psi0_0:
371 DO_WRITE64 XFR2VBUS_XID_WRITE1, 64
372 CALL_SUB sstate_00, loop_psi1_0
374 ;r1, 2, 3, 4 wait for 4x 16Byte chunks;
375 loop_psi1_0:
376 qbeq sr40, GRrtu.ActThrdNum, 0
377 qbeq sr41, GRrtu.ActThrdNum, 1
378 qbeq sr42, GRrtu.ActThrdNum, 2
379 RTU_PSI_READ_SR1_4 XID_PSI_R4, loop_psi2_0, eop_exit02
380 sr42: RTU_PSI_READ_SR1_4 XID_PSI_R3, loop_psi2_0, eop_exit02
381 sr41: RTU_PSI_READ_SR1_4 XID_PSI_R2, loop_psi2_0, eop_exit02
382 sr40: RTU_PSI_READ_SR1_4 XID_PSI_R1, loop_psi2_0, eop_exit02
384 loop_psi2_0:
385 DO_WRITE64 XFR2VBUS_XID_WRITE1, 64
386 CALL_SUB sstate_00, loop_psi1_0
387 jmp loop_psi1_0
389 ;SPECIAL CASES FOR THREADs
390 ;stall cases. Processing for this thread is stalled
391 ; park context, set b0 to ignore this thread
392 ; (when parking context, label where to restart thread is saved)
393 stall_exit03: ;stall due to no room in queue
394 STALL_N_PARK SR_QUEUE, PARK_THREAD1, unstall03
395 add r30.b2, r30.b2, 1
396 jmp psi_idle2
398 stall_exit02: ;stall due to no buffer
399 STALL_N_PARK SR_BUF, PARK_THREAD1, unstall02
400 add r30.b2, r30.b2, 1
401 jmp psi_idle2
403 stall_exit01: ; STALL on resource lock
404 STALL_N_PARK SR_LOCK, PARK_THREAD0, unstall01
405 add r30.b2, r30.b2, 1
406 jmp psi_idle2
408 stall_exit00: ;stalled due to rate limiter
409 clr GRrtu.StallMask, GRrtu.StallMask, GRrtu.ActThrdNum
410 ;stall reason is 0 (default)
411 add r11, GRrtu.ActThrdNum, PSI_CNTX0_SLOT
412 PARK_THREAD0 r11, unstall00
413 add r30.b2, r30.b2, 1
414 jmp psi_idle2
416 ;--------------------
417 ;EOP exits
418 ;-------------------
419 ;less<64 pkt seen
420 ;special case: len=60, 61, 62, 63
421 eop_exit00:
422 eop_exit01:
423 qbbc dow, r1, 1 ;r1.f_md_eop
424 set Ctx.ippc_flags, Ctx.ippc_flags, f_eop
425 dow:
426 DO_WRITE64 XFR2VBUS_XID_WRITE1, r1.b3
427 ;todo clear crc included bit (cause it couldn't have been)
428 jmp do_eop00
430 ;normal sized packet exit
431 eop_exit02:
432 qbbc dow2, r1, 1 ;r1.f_md_eop
433 set Ctx.ippc_flags, Ctx.ippc_flags, f_eop
434 dow2:
435 ;todo check if crc included or not. if it is then r1.b3 better be >=64
436 DO_WRITE64 XFR2VBUS_XID_WRITE1, r1.b3
438 ;do eop processing for pkt (i.e. post it to portQ and/or IPCQ) {{{2
439 do_eop00:
440 unstall03:
441 DO_EOP stall_exit03
443 ;last thing to do is wait for EOP
444 qbbc weop, Ctx.ippc_flags, f_eop
445 jmp psi_idle2
446 weop:
447 WAIT_EOP
448 jmp psi_idle2
450 err_exit01: ;some kind of error.. for now just toss until EOP
451 err_exit00: ;ERROR: Drop pkt. Note: won't service PSI unti we eop on this thread
452 WAIT_EOP
453 add r30.b2, r30.b2, 1
454 jmp psi_idle
455 ;end of psi host egress
457 loop_here
458 ;----------------TASK HANDLERS----------------------
459 ;--------------------------------------------------------------
460 ; RX TASK2 (SOF HELPER) - HIGHEST PRIORITY TASK and MUST HAPPEN {{{1
461 ;----------------------
462 rtu_rx_task2:
463 mov GRrtu.save1, r0.b0
464 ldi r0.b0, 0
465 flip_rtu_r0_r23
466 ldi R_RX_STATE, 0x180
468 ;read filter. clobbers r10-12. copy r11, r2 into scratch3, 4
469 FILTER_GET_ALL ;blasts into r10-r17
470 mov R_BASIC_F, r11 ;move basic filter results to somewhere safe
471 ;see if "to-host" classifier says take it
472 TOHOST_OK R_CLASSI, try_to_host
473 ;use classifiers to determine psi flow
474 and r0.b0, R_CLASSI.b2, CLASSI_FMASK
475 lmbd R_PSI_FLAGS.w0, r0.b0, 1
476 ldi R_RX_STATE.b0, 0x81 ;rx_flags
477 try_to_host:
478 qbbc rx_task2_done, R_RX_STATE, f_tohost
479 ;PSI flow. for mac we did earlier
480 send_info:
481 qblt send_info1, R_PSI_FLAGS.w0, 15 ;
482 add R_PSI_FLAGS.w0, R_PSI_FLAGS.w0, R_RX_STATE_INFO.w0
483 jmp rx_task2_done
484 send_info1:
485 ldi R_PSI_FLAGS.w0, 0x3fff ;
486 ;todo -> set from filter results (IPv4, v6, udp, tcp)
487 rx_task2_done:
489 ;send forwarding info to PRU. he will pick it up at start of RX_Block1
490 ; THIS MUST HAPPEN!! ELSE PKT DROPPED In RTU
491 mov r5, R_RX_STATE
492 mov r6, R_PSI_FLAGS ;send flow over
493 RTU_IPC_TX_CH1
494 ;read the rxtimestamp
495 qbbc rx_task2_done2, R_RX_STATE, f_tohost
496 GET_PKT_RX_TS R_TS_HI ;note classi clobbered here
497 ldi32 r5, FW_CONFIG + RX_TS_BASE
498 sbbo &R_TS_HI, r5, 0, 8
500 rx_task2_done2:
501 ldi r0.b0, 0
502 TM_YIELD
503 ;caution: 2 instr after yield are done in delayed-branch fashion
504 flip_rtu_r0_r23
505 mov r0.b0, GRrtu.save1
506 loop_here
507 ;========END RX_TASK2==============
509 TX_EOF: TM_YIELD
510 set GRrtu.flags, GRrtu.flags, f_tstx_ready
511 loop_here
513 TX_EOD_P: TM_YIELD
514 set GRrtu.flags, GRrtu.flags, f_tx0_complete
515 loop_here
517 TX_EOD_E: TM_YIELD
518 set GRrtu.flags, GRrtu.flags, f_tx1_complete
519 loop_here
521 TM_NOP: TM_YIELD
522 loop_here
523 ;-----------------------
524 ;sched co-routine
525 ;-----------------------
526 sstate_00:
527 STATE_00_EP
528 jmp GRrtu.ret_addr
531 .include "resource_table.h"