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