9cde7d8d75c68b974469455719edd46d9bde5929
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 "hd_helper.h"
79 .include "scheduler.h"
80 .include "ipc.h"
81 .include "filter.h"
82 .include "classi.h"
83 .include "txrate.h"
84 .include "rtu_psi.h"
85 .include "iep.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 READ_RGMII_CFG r1, GRrtu.speed_f
274 CALL_SUB sstate_00, psi_idle
275 jmp psi_idle
277 ;---------------------------------------
278 ;PSI is idle but we may have stalled threads
279 ;---------------------------------------
280 psi_idle2:
281 ;see if we can unstall anyone
282 qbeq psi_idle3, GRrtu.StallMask, 0x0f
284 ;make sure r16, r17 dont get stomped on!!!
285 ldi r16, 0
286 ldi r17, PSI_CNTX0_SLOT
287 unstall_loop:
288 qbbs skipu, GRrtu.StallMask, r16
289 TRY_UNSTALL r16, r17, skipu
290 skipu:
291 add r16, r16, 1
292 add r17, r17, 1
293 qbgt unstall_loop, r16, 4
294 jmp psi_idle3
296 mgr_pkt:
297 RTU_POLL_SLOTx GRrtu.ActThrdNum
298 PSI_READ GRrtu.ActThrdNum, 20
299 ldi32 r0, MD_CONTROL0
300 qbeq mgr_pkt, r1, r0
301 qbne mgr_pkt01, r1.b2, 0x14;
302 ; we have 16 bytes of packet now
303 ; process mgr data
304 LEBE_GO r2, 16
305 qbne mgr_pkt01, r2.b3, 0x81 ; not a management packet
306 mov GRrtu.seq_num, r2.b1 ; save seq_num
307 qbne mgr_pkt10, r2.b2, 0x01 ; shutdown command
308 MGR_SHUTDOWN
309 ldi32 r2, 0x81010001 ; response OK
310 mov r2.b1, GRrtu.seq_num
311 TM_DISABLE
312 SEND_MGR_PKT
313 ldi32 r0, FW_CONFIG
314 ldi32 r1, RTU_STOPPED
315 sbbo &r1, r0, CFG_RTU_STATUS, 4
316 loop_here
318 mgr_pkt10:
319 qbne mgr_pkt20, r2.b2, 0x02 ; set port state
320 ; execute it here
321 jmp mgr_unknown
322 jmp mgr_pkt02
324 mgr_pkt20:
326 mgr_unknown:
327 ldi r2.b0, 0x10
328 mov r2.b1, GRrtu.seq_num
329 SEND_MGR_PKT
330 jmp psi_idle
332 mgr_pkt01:
333 branch_if_eop mgr_pkt02
334 WAIT_EOP
335 mgr_pkt02:
336 jmp psi_idle
338 ;-------------------------
339 ; process active thread
340 ; GRrtu.ActThrdNum = bit of active thread set
341 ; GRrtu.StallMask = cleared bits => stalled threads
342 ; GRrtu.StallReason = reason for stalled threads
343 ; GRrtu.ResLock = resource locks taken
344 ;------------------------
345 start_psi:
346 ;S0: read in INFO
347 RTU_PSI_IN_S0 err_exit00, stall_exit00, mgr_pkt
348 unstall00:
350 ;S1: wait for 1st DATA or control
351 wait_1stdata0:
352 RTU_POLL_SLOTx GRrtu.ActThrdNum
353 RTU_PSI_IN_S1 err_exit01, wait_1stdata0
354 CALL_SUB sstate_00, wait_fdb_done0
356 ;F0: wait for FDB result
357 ;todo: optimizaton: bring in next 2x16 while fdb in progress
358 wait_fdb_done0:
359 unstall01:
360 RTU_PSI_IN_F0_PART2 stall_exit01, stall_exit02
361 unstall02:
362 ;r2, 3, 4 wait for remaining 3x16B
363 qbeq sr20, GRrtu.ActThrdNum, 0
364 qbeq sr21, GRrtu.ActThrdNum, 1
365 qbeq sr22, GRrtu.ActThrdNum, 2
366 RTU_PSI_READ_SR2_4 XID_PSI_R4, BS_SLOT_PSI3, loop_psi0_0, eop_exit00, eop_exit01
367 sr22: RTU_PSI_READ_SR2_4 XID_PSI_R3, BS_SLOT_PSI2, loop_psi0_0, eop_exit00, eop_exit01
368 sr21: RTU_PSI_READ_SR2_4 XID_PSI_R2, BS_SLOT_PSI1, loop_psi0_0, eop_exit00, eop_exit01
369 sr20: RTU_PSI_READ_SR2_4 XID_PSI_R1, BS_SLOT_PSI0, loop_psi0_0, eop_exit00, eop_exit01
371 loop_psi0_0:
372 DO_WRITE64 XFR2VBUS_XID_WRITE1, 64
373 CALL_SUB sstate_00, loop_psi1_0
375 ;r1, 2, 3, 4 wait for 4x 16Byte chunks;
376 loop_psi1_0:
377 qbeq sr40, GRrtu.ActThrdNum, 0
378 qbeq sr41, GRrtu.ActThrdNum, 1
379 qbeq sr42, GRrtu.ActThrdNum, 2
380 RTU_PSI_READ_SR1_4 XID_PSI_R4, loop_psi2_0, eop_exit02
381 sr42: RTU_PSI_READ_SR1_4 XID_PSI_R3, loop_psi2_0, eop_exit02
382 sr41: RTU_PSI_READ_SR1_4 XID_PSI_R2, loop_psi2_0, eop_exit02
383 sr40: RTU_PSI_READ_SR1_4 XID_PSI_R1, loop_psi2_0, eop_exit02
385 loop_psi2_0:
386 DO_WRITE64 XFR2VBUS_XID_WRITE1, 64
387 CALL_SUB sstate_00, loop_psi1_0
388 jmp loop_psi1_0
390 ;SPECIAL CASES FOR THREADs
391 ;stall cases. Processing for this thread is stalled
392 ; park context, set b0 to ignore this thread
393 ; (when parking context, label where to restart thread is saved)
394 stall_exit03: ;stall due to no room in queue
395 STALL_N_PARK SR_QUEUE, PARK_THREAD1, unstall03
396 add r30.b2, r30.b2, 1
397 jmp psi_idle2
399 stall_exit02: ;stall due to no buffer
400 STALL_N_PARK SR_BUF, PARK_THREAD1, unstall02
401 add r30.b2, r30.b2, 1
402 jmp psi_idle2
404 stall_exit01: ; STALL on resource lock
405 STALL_N_PARK SR_LOCK, PARK_THREAD0, unstall01
406 add r30.b2, r30.b2, 1
407 jmp psi_idle2
409 stall_exit00: ;stalled due to rate limiter
410 clr GRrtu.StallMask, GRrtu.StallMask, GRrtu.ActThrdNum
411 ;stall reason is 0 (default)
412 add r11, GRrtu.ActThrdNum, PSI_CNTX0_SLOT
413 PARK_THREAD0 r11, unstall00
414 add r30.b2, r30.b2, 1
415 jmp psi_idle2
417 ;--------------------
418 ;EOP exits
419 ;-------------------
420 ;less<64 pkt seen
421 ;special case: len=60, 61, 62, 63
422 eop_exit00:
423 eop_exit01:
424 qbbc dow, r1, 1 ;r1.f_md_eop
425 set Ctx.ippc_flags, Ctx.ippc_flags, f_eop
426 dow:
427 DO_WRITE64 XFR2VBUS_XID_WRITE1, r1.b3
428 ;todo clear crc included bit (cause it couldn't have been)
429 jmp do_eop00
431 ;normal sized packet exit
432 eop_exit02:
433 qbbc dow2, r1, 1 ;r1.f_md_eop
434 set Ctx.ippc_flags, Ctx.ippc_flags, f_eop
435 dow2:
436 ;todo check if crc included or not. if it is then r1.b3 better be >=64
437 DO_WRITE64 XFR2VBUS_XID_WRITE1, r1.b3
439 ;do eop processing for pkt (i.e. post it to portQ and/or IPCQ) {{{2
440 do_eop00:
441 unstall03:
442 DO_EOP stall_exit03
444 ;last thing to do is wait for EOP
445 qbbc weop, Ctx.ippc_flags, f_eop
446 jmp psi_idle2
447 weop:
448 WAIT_EOP
449 jmp psi_idle2
451 err_exit01: ;some kind of error.. for now just toss until EOP
452 err_exit00: ;ERROR: Drop pkt. Note: won't service PSI unti we eop on this thread
453 WAIT_EOP
454 add r30.b2, r30.b2, 1
455 jmp psi_idle
456 ;end of psi host egress
458 loop_here
459 ;----------------TASK HANDLERS----------------------
460 ;--------------------------------------------------------------
461 ; RX TASK2 (SOF HELPER) - HIGHEST PRIORITY TASK and MUST HAPPEN {{{1
462 ;----------------------
463 rtu_rx_task2:
464 mov GRrtu.save1, r0.b0
465 ldi r0.b0, 0
466 flip_rtu_r0_r23
467 ldi R_RX_STATE, 0x180
469 ;read filter. clobbers r10-12. copy r11, r2 into scratch3, 4
470 FILTER_GET_ALL ;blasts into r10-r17
471 mov R_BASIC_F, r11 ;move basic filter results to somewhere safe
472 ;see if "to-host" classifier says take it
473 TOHOST_OK R_CLASSI, try_to_host
474 ;use classifiers to determine psi flow
475 and r0.b0, R_CLASSI.b2, CLASSI_FMASK
476 lmbd R_PSI_FLAGS.w0, r0.b0, 1
477 ldi R_RX_STATE.b0, 0x81 ;rx_flags
478 try_to_host:
479 qbbc rx_task2_done, R_RX_STATE, f_tohost
480 ;PSI flow. for mac we did earlier
481 send_info:
482 qblt send_info1, R_PSI_FLAGS.w0, 15 ;
483 add R_PSI_FLAGS.w0, R_PSI_FLAGS.w0, R_RX_STATE_INFO.w0
484 jmp rx_task2_done
485 send_info1:
486 ldi R_PSI_FLAGS.w0, 0x3fff ;
487 ;todo -> set from filter results (IPv4, v6, udp, tcp)
488 rx_task2_done:
490 ;send forwarding info to PRU. he will pick it up at start of RX_Block1
491 ; THIS MUST HAPPEN!! ELSE PKT DROPPED In RTU
492 mov r5, R_RX_STATE
493 mov r6, R_PSI_FLAGS ;send flow over
494 RTU_IPC_TX_CH1
495 ;read the rxtimestamp
496 qbbc rx_task2_done2, R_RX_STATE, f_tohost
497 GET_PKT_RX_TS R_TS_HI ;note classi clobbered here
498 ldi32 r5, FW_CONFIG + RX_TS_BASE
499 sbbo &R_TS_HI, r5, 0, 8
501 rx_task2_done2:
502 ldi r0.b0, 0
503 TM_YIELD
504 ;caution: 2 instr after yield are done in delayed-branch fashion
505 flip_rtu_r0_r23
506 mov r0.b0, GRrtu.save1
507 loop_here
508 ;========END RX_TASK2==============
510 TX_EOF: TM_YIELD
511 set GRrtu.flags, GRrtu.flags, f_tstx_ready
512 loop_here
514 TX_EOD_P: TM_YIELD
515 set GRrtu.flags, GRrtu.flags, f_tx0_complete
516 loop_here
518 TX_EOD_E: TM_YIELD
519 set GRrtu.flags, GRrtu.flags, f_tx1_complete
520 loop_here
522 TM_NOP: TM_YIELD
523 loop_here
524 ;-----------------------
525 ;sched co-routine
526 ;-----------------------
527 sstate_00:
528 STATE_00_EP
529 jmp GRrtu.ret_addr
532 .include "resource_table.h"