]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - processor-sdk/pdk.git/blob - packages/ti/drv/emac/firmware/icss_dualmac/src/rtu_v2.asm
Merge pull request #15 in PROCESSOR-SDK/pdk from review_PRSDK-7317 to master
[processor-sdk/pdk.git] / packages / ti / drv / emac / firmware / icss_dualmac / src / rtu_v2.asm
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"
86 loop_here .macro
87 here?:  jmp     here?
88         .endm
90 wait4pru_ready .macro
91         .newblock
92         ldi32   r1, PRU_READY
93         ldi32   r0, FW_CONFIG
94 $1:     add     r0, r0, 0
95         add     r0, r0, 0
96         add     r0, r0, 0
97         lbbo    &r9, r0, CFG_STATUS, 4
98         qbne    $1, r9, r1
100         ldi32   r2, RTU_READY
101         sbbo    &r2, r0, CFG_RTU_STATUS, 4
102  .endm
104 ; r8 - starting address, r12 - address of the 1st pull size
105 create_8_buff_pools .macro starting_slot
106         .newblock
107         ldi     r13, 0
108         ldi     r14, starting_slot
109 $1:     lbbo    &r9, r12, 0, 4
110         BUFP_CREATE     r14, r8, r9
111         add     r8, r8, r9
112         add     r8, r8, 128
113         add     r13, r13, 1
114         add     r14, r14, 1
115         add     r12, r12, 4
116         qbgt    $1, r13, 8
117  .endm
119 ;buffps for Ethernet pkts from wire
120 create_all_buff_pools .macro
121         mov     r8, r18 ; start from the beginning of the buffer memory
122 ;buffps for PSI pkts for this slice
123         ldi32   r12, FW_CONFIG + CFG_TX_BS_8
124         create_8_buff_pools     BP_SLOT0_RTU
125  .endm
127 create_port_queues .macro
128         .newblock
129 ;create portQs :: 8 for this slice and 8 shadow for other slice)
130         ldi     r13, 0
131         ldi     r14, MQ_SLOT0_RTU
132         ldi32   r0, MQBASE_START
133         ldi     r1, PQ_MAX_PKT_RTU
134 $1:     MQ_CREATE       r14, r0, r1
135         mov     r0, r5
136         add     r14, r14, 1
137         add     r13, r13, 1
138         qbge    $1, r13, 8
140  .endm
141  ; Code starts {{{1
142  .retain     ; Required for building .out with assembly file
143  .retainrefs ; Required for building .out with assembly file
144  .sect    ".text:Start"
145  .global  Start
147 Start:
148         TM_DISABLE
149         zero    &r0, 124
150         ldi     r11, 1
151          ;      rtu err counter: b0 = RXdropPsi (widget full), b1=RXdropErr, b2=TXstall, b3= txError
152         ldi     r30,0
153  .if $isdefed("WAIT_FOR_DEBUGGER")
154         mov     r11, 0
155  .endif
156 start_test:
157         qbeq    start_test, r11, 0
159 ;       SP_SHIFT_ENABLE
160 ;one time initialization
161         wait4pru_ready
162 ; r0 has FW_CONFIG from previouse macro
163         lbbo    &r5, r0, CFG_DEF_FLOW, 8 ; r5 - flow, r6 - flags
164         lbbo    &r3, r0, CFG_ADDR_LO, 8;
166 ;r3=addrlo, r4=addrhi (not used. todo check against #define and barf)
167 ;r5 = flow
168 ;r6 = flags
169 ;r7 = portstate (RX) VA - we don't have it anymore
170 ;save def flow & flags
171 ;port state conversion to something useful
173         ldi     r0, 0
174 ;default:   (3)= fwd plus learn
175         set     r0.t3 ;fwd
176         set     r0.t4 ;lrn
177 ;hostport tbd
179  .if $isdefed ("VLAN_ENABLED")
180         set     r6.t0
181  .endif
182         mov     r7, r0
183         RX_TASK_INIT_RTU        r6, r5, r7
185         add     r18, r3, 0x80   ;skip 128 bytes ..
186         mov     r19, r4
187         PAGE_SAVE       RTU_GSTATE
189         create_all_buff_pools
190         create_port_queues
192 ;set up PSI INFO, CONTROL, STATUS TEMPLATES
193  .if $isdefed("SLICE0")
194         PSI_SETUP_INFO  PSI_INFO_SLOT, 1
195  .else
196         PSI_SETUP_INFO  PSI_INFO_SLOT, 2
197  .endif
198         PSI_SETUP_MGR_INFO
199         PSI_SETUP_STATUS        PSI_STATUS_SLOT
201 ;initialize txrate limiters for each thread
202         ldi     r2, 0
203         TXRATE_INIT     0, r1, r2
204         TXRATE_INIT     1, r1, r2
205         TXRATE_INIT     2, r1, r2
206         TXRATE_INIT     3, r1, r2
208 ;setup taskmanager
209         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
210         TM_ENABLE
212 ;set up IEP - assume this only needs to get done once
213         SET_IEP_SYNC_MODE       IEP_CFG1_BASEx
214         ENABLE_IEP      IEP_BASEx
216 ;r2-r3 are scratch
217         ldi     r4, 400 ;every 400ns
218         SET_CMP8_15     IEP_BASEx, 56, r2, r3, r4
219         ENABLE_CMP      IEP_BASEx, 15, r2
221 ;we READY FOR NEW PACKET
222         zero    &Ctx, 20        ;now set ingress context
224 ;---------------start test------------ {{{1
225 ;init scheduler
226         zero    &GRrtu.pqmap, 4
227         ldi     GRrtu.qmask, NORM_QMASK ;look at all queues
229 ;intialize PS global state
230         ldi     GRrtu.StallMask, 0xf    ;no stalls
231         QLOCK_INIT      ;clear resource lock
232         ldi     GRrtu.ActThrdNum, 0     ;nothing active
233         ldi     GRrtu.StallReason, 0    ;no stall reason
235 ;-------------------------------
236 ; RTU BG LOOP   {{{1
237 ;-------------------------------
238 bg_loop:
240 ;start of psi host egress handler
241 ;-------------------------------------------------------------
242 ; psi is Idle, meaning we aren't actively bring in data from a
243 ; PSI thread.  But we may be stalled
244 ;-------------------------------------------------------------
245 psi_idle:
246         xin     XID_PSI_S, &r1, 8
247         and     r1.b0, r1.b0, GRrtu.StallMask
248         qbeq    no_psi, r1.b0, 0
250         qbbc    $1, r1, 0
251         ldi     GRrtu.ActThrdNum, 0x0
252         and     GRrtu.StallReason, GRrtu.StallReason, 0xfc
253         jmp     start_psi
255 $1:     qbbc    $2, r1, 1
256         ldi     GRrtu.ActThrdNum, 1
257         and     GRrtu.StallReason, GRrtu.StallReason, 0xf3
258         jmp     start_psi
260 $2:     qbbc    $3, r1, 2
261         ldi     GRrtu.ActThrdNum, 2
262         and     GRrtu.StallReason, GRrtu.StallReason, 0xcf
263         jmp     start_psi
265 $3:     qbbc    no_psi, r1, 3
266         ldi     GRrtu.ActThrdNum, 3
267         and     GRrtu.StallReason, GRrtu.StallReason, 0x3f
268         jmp     start_psi
270 no_psi: jmp psi_idle2
271 psi_idle3:
272         CALL_SUB        sstate_00, psi_idle
273         jmp     psi_idle
275 ;---------------------------------------
276 ;PSI is idle but we may have stalled threads
277 ;---------------------------------------
278 psi_idle2:
279 ;see if we can unstall anyone
280         qbeq    psi_idle3, GRrtu.StallMask, 0x0f
282 ;make sure r16, r17 dont get stomped on!!!
283         ldi     r16, 0
284         ldi     r17, PSI_CNTX0_SLOT
285 unstall_loop:
286         qbbs    skipu, GRrtu.StallMask, r16
287         TRY_UNSTALL     r16, r17, skipu
288 skipu:
289         add     r16, r16, 1
290         add     r17, r17, 1
291         qbgt    unstall_loop, r16, 4
292         jmp     psi_idle3
294 mgr_pkt:
295         RTU_POLL_SLOTx  GRrtu.ActThrdNum
296         PSI_READ        GRrtu.ActThrdNum, 20
297         ldi32   r0, MD_CONTROL0
298         qbeq    mgr_pkt, r1, r0
299         qbne    mgr_pkt01, r1.b2, 0x14;
300         ; we have 16 bytes of packet now
301         ; process mgr data
302         LEBE_GO r2, 16
303         qbne    mgr_pkt01, r2.b3, 0x81  ; not a management packet
304         mov     GRrtu.seq_num, r2.b1    ; save seq_num
305         qbne    mgr_pkt10, r2.b2, 0x01  ; shutdown command
306         MGR_SHUTDOWN
307         ldi32   r2, 0x81010001  ; response OK
308         mov     r2.b1, GRrtu.seq_num
309         TM_DISABLE
310         SEND_MGR_PKT
311         ldi32   r0, FW_CONFIG
312         ldi32   r1, RTU_STOPPED
313         sbbo    &r1, r0, CFG_RTU_STATUS, 4
314         loop_here
316 mgr_pkt10:
317         qbne    mgr_pkt20, r2.b2, 0x02  ; set port state
318         ; execute it here
319         jmp     mgr_unknown
320         jmp     mgr_pkt02
322 mgr_pkt20:
324 mgr_unknown:
325         ldi     r2.b0, 0x10
326         mov     r2.b1, GRrtu.seq_num
327         SEND_MGR_PKT
328         jmp     psi_idle
330 mgr_pkt01:
331         branch_if_eop   mgr_pkt02
332         WAIT_EOP
333 mgr_pkt02:
334         jmp     psi_idle
336 ;-------------------------
337 ; process active thread
338 ; GRrtu.ActThrdNum  = bit of active thread set
339 ; GRrtu.StallMask   = cleared bits => stalled threads
340 ; GRrtu.StallReason = reason for stalled threads
341 ; GRrtu.ResLock     = resource locks taken
342 ;------------------------
343 start_psi:
344 ;S0: read in INFO
345         RTU_PSI_IN_S0   err_exit00, stall_exit00, mgr_pkt
346 unstall00:
348 ;S1: wait for 1st DATA or control
349 wait_1stdata0:
350         RTU_POLL_SLOTx  GRrtu.ActThrdNum
351         RTU_PSI_IN_S1   err_exit01, wait_1stdata0
352         CALL_SUB        sstate_00, wait_fdb_done0
354 ;F0: wait for FDB result
355 ;todo: optimizaton: bring in next 2x16 while fdb in progress
356 wait_fdb_done0:
357 unstall01:
358         RTU_PSI_IN_F0_PART2     stall_exit01, stall_exit02
359 unstall02:
360 ;r2, 3, 4 wait for remaining 3x16B
361         qbeq    sr20, GRrtu.ActThrdNum, 0
362         qbeq    sr21, GRrtu.ActThrdNum, 1
363         qbeq    sr22, GRrtu.ActThrdNum, 2
364         RTU_PSI_READ_SR2_4      XID_PSI_R4, BS_SLOT_PSI3, loop_psi0_0, eop_exit00, eop_exit01
365 sr22:   RTU_PSI_READ_SR2_4      XID_PSI_R3, BS_SLOT_PSI2, loop_psi0_0, eop_exit00, eop_exit01
366 sr21:   RTU_PSI_READ_SR2_4      XID_PSI_R2, BS_SLOT_PSI1, loop_psi0_0, eop_exit00, eop_exit01
367 sr20:   RTU_PSI_READ_SR2_4      XID_PSI_R1, BS_SLOT_PSI0, loop_psi0_0, eop_exit00, eop_exit01
369 loop_psi0_0:
370         DO_WRITE64      XFR2VBUS_XID_WRITE1, 64
371         CALL_SUB        sstate_00, loop_psi1_0
373 ;r1, 2, 3, 4 wait for 4x 16Byte chunks;
374 loop_psi1_0:
375         qbeq    sr40, GRrtu.ActThrdNum, 0
376         qbeq    sr41, GRrtu.ActThrdNum, 1
377         qbeq    sr42, GRrtu.ActThrdNum, 2
378         RTU_PSI_READ_SR1_4      XID_PSI_R4, loop_psi2_0, eop_exit02
379 sr42:   RTU_PSI_READ_SR1_4      XID_PSI_R3, loop_psi2_0, eop_exit02
380 sr41:   RTU_PSI_READ_SR1_4      XID_PSI_R2, loop_psi2_0, eop_exit02
381 sr40:   RTU_PSI_READ_SR1_4      XID_PSI_R1, loop_psi2_0, eop_exit02
383 loop_psi2_0:
384         DO_WRITE64      XFR2VBUS_XID_WRITE1, 64
385         CALL_SUB        sstate_00, loop_psi1_0
386         jmp     loop_psi1_0
388 ;SPECIAL CASES FOR THREADs
389 ;stall cases.  Processing for this thread is stalled
390 ; park context, set b0 to ignore this thread
391 ; (when parking context, label where to restart thread is saved)
392 stall_exit03: ;stall due to no room in queue
393         STALL_N_PARK    SR_QUEUE, PARK_THREAD1, unstall03
394         add     r30.b2, r30.b2, 1
395         jmp     psi_idle2
397 stall_exit02: ;stall due to no buffer
398         STALL_N_PARK    SR_BUF, PARK_THREAD1, unstall02
399         add     r30.b2, r30.b2, 1
400         jmp     psi_idle2
402 stall_exit01: ; STALL on resource lock
403         STALL_N_PARK    SR_LOCK, PARK_THREAD0, unstall01
404         add     r30.b2, r30.b2, 1
405         jmp     psi_idle2
407 stall_exit00: ;stalled due to rate limiter
408         clr     GRrtu.StallMask, GRrtu.StallMask, GRrtu.ActThrdNum
409 ;stall reason is 0 (default)
410         add     r11, GRrtu.ActThrdNum, PSI_CNTX0_SLOT
411         PARK_THREAD0    r11, unstall00
412         add     r30.b2, r30.b2, 1
413         jmp     psi_idle2
415 ;--------------------
416 ;EOP exits
417 ;-------------------
418 ;less<64 pkt seen
419 ;special case: len=60, 61, 62, 63
420 eop_exit00:
421 eop_exit01:
422         qbbc    dow, r1, 1       ;r1.f_md_eop
423         set     Ctx.ippc_flags, Ctx.ippc_flags, f_eop
424 dow:
425         DO_WRITE64      XFR2VBUS_XID_WRITE1, r1.b3
426 ;todo clear crc included bit (cause it couldn't have been)
427         jmp     do_eop00
429 ;normal sized packet exit
430 eop_exit02:
431         qbbc    dow2, r1, 1      ;r1.f_md_eop
432         set     Ctx.ippc_flags, Ctx.ippc_flags, f_eop
433 dow2:
434 ;todo check if crc included or not. if it is then r1.b3 better be >=64
435         DO_WRITE64      XFR2VBUS_XID_WRITE1, r1.b3
437 ;do eop processing for pkt (i.e. post it to portQ and/or IPCQ) {{{2
438 do_eop00:
439 unstall03:
440         DO_EOP  stall_exit03
442 ;last thing to do is wait for EOP
443         qbbc    weop, Ctx.ippc_flags, f_eop
444         jmp     psi_idle2
445 weop:
446         WAIT_EOP
447         jmp     psi_idle2
449 err_exit01:     ;some kind of error..  for now just toss until EOP
450 err_exit00:     ;ERROR: Drop pkt. Note: won't service PSI unti we eop on this thread
451         WAIT_EOP
452         add     r30.b2, r30.b2, 1
453         jmp     psi_idle
454 ;end of psi host egress
456         loop_here
457 ;----------------TASK HANDLERS----------------------
458 ;--------------------------------------------------------------
459 ; RX TASK2 (SOF HELPER) - HIGHEST PRIORITY TASK and MUST HAPPEN {{{1
460 ;----------------------
461 rtu_rx_task2:
462         mov     GRrtu.save1, r0.b0
463         ldi     r0.b0, 0
464         flip_rtu_r0_r23
465         ldi     R_RX_STATE, 0x180
467 ;read filter. clobbers r10-12. copy r11, r2 into scratch3, 4
468         FILTER_GET_ALL  ;blasts into r10-r17
469         mov     R_BASIC_F, r11    ;move basic filter results to somewhere safe
470         ;see    if "to-host" classifier says take it
471         TOHOST_OK       R_CLASSI, try_to_host
472         ;use    classifiers to determine  psi flow
473         and     r0.b0, R_CLASSI.b2, CLASSI_FMASK
474         lmbd    R_PSI_FLAGS.w0, r0.b0, 1
475         ldi     R_RX_STATE.b0, 0x81 ;rx_flags
476 try_to_host:
477         qbbc    rx_task2_done, R_RX_STATE, f_tohost
478 ;PSI flow.  for mac we did earlier
479 send_info:
480         qblt    send_info1, R_PSI_FLAGS.w0, 15 ;
481         add     R_PSI_FLAGS.w0, R_PSI_FLAGS.w0, R_RX_STATE_INFO.w0
482         jmp     rx_task2_done
483 send_info1:
484         ldi     R_PSI_FLAGS.w0, 0x3fff ;
485 ;todo -> set from filter results (IPv4, v6, udp, tcp)
486 rx_task2_done:
488 ;send forwarding info to PRU. he will pick it up at start of RX_Block1
489 ; THIS MUST HAPPEN!! ELSE PKT DROPPED In RTU
490         mov     r5, R_RX_STATE
491         mov     r6, R_PSI_FLAGS ;send flow over
492         RTU_IPC_TX_CH1
493 ;read the rxtimestamp
494         qbbc    rx_task2_done2, R_RX_STATE, f_tohost
495         GET_PKT_RX_TS   R_TS_HI ;note classi clobbered here
496         ldi32   r5, FW_CONFIG + RX_TS_BASE
497         sbbo    &R_TS_HI, r5, 0, 8
499 rx_task2_done2:
500         ldi     r0.b0, 0
501         TM_YIELD
502 ;caution: 2 instr after yield are done in delayed-branch fashion
503         flip_rtu_r0_r23
504         mov     r0.b0, GRrtu.save1
505         loop_here
506 ;========END RX_TASK2==============
508 TX_EOF: TM_YIELD
509         set     GRrtu.flags, GRrtu.flags, f_tstx_ready
510         loop_here
512 TX_EOD_P: TM_YIELD
513         set     GRrtu.flags, GRrtu.flags, f_tx0_complete
514         loop_here
516 TX_EOD_E: TM_YIELD
517         set     GRrtu.flags, GRrtu.flags, f_tx1_complete
518         loop_here
520 TM_NOP: TM_YIELD
521         loop_here
522 ;-----------------------
523 ;sched co-routine
524 ;-----------------------
525 sstate_00:
526         STATE_00_EP
527         jmp     GRrtu.ret_addr
530  .include "resource_table.h"