]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - processor-sdk/pdk.git/blob - packages/ti/drv/emac/firmware/icss_dualmac/src/scheduler.h
Merge pull request #17 in PROCESSOR-SDK/pdk from PRSDK-7323 to master
[processor-sdk/pdk.git] / packages / ti / drv / emac / firmware / icss_dualmac / src / scheduler.h
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 ;----------------------------------------------------------
56 ; scheduler.h:  defines and macros for ICSS-G port scheduler
57 ;   v0.1
58 ;   Notes: runs on RTU
59 ;-----------------------------------------------------------
61 ;----------------------
62 ; utility: cleanup tx
63 ;----------------------
64 CLEANUP_TX      .macro   slot ; {{{1
65         TM_DISABLE
66         PAGE_RESTORE2 slot, 32
67 ;r7-r8 = descriptor
68         add     r0.b0, r8.b3, BP_SLOT0_PRU
69         CEIL64  r18.w0,r8.w0
70         BUFP_PUSH r0, r18.w0
71         TM_ENABLE
72  .endm
74 ;==============================
75 ;  STATE 00 state entry point ;STATE_00_EP {{{1
76 ;=============================
77 ; use r2-r9
78 ; step on r18-r20
79 ; preserve r20 in r0 temp
80 STATE_00_EP     .macro
81         .newblock
82         SCHED_CHECK_DMA ;see if we can complete previous dma(s)
83 ;(1) preemption not allowed, so we can ping pong dmas
84 ;see if ok to start DMA
85         qbbs    $1, GRrtu.flags, f_dmau
86         qbbs    done?, GRrtu.flags, f_dma0
87         jmp     $2
88 $1:     qbbs    done?, GRrtu.flags, f_dma1
89 $2:
90 ;check if we need to send TX_TS here
91         qbbc    $4, GRrtu.flags,  f_tstx_ready
92         ldi32   r10, FW_CONFIG + TX_TS_BASE
93         lbbo    &r2, r10, 0, 16
94         set     r4.t0
95         SEND_TXTS_PKT
96         clr     GRrtu.flags, GRrtu.flags, f_tstx_ready
97 ;ok to start
98 $4:
99         and     GRrtu.spare, GRrtu.qmask, GRrtu.pqmap
100         lmbd    GRrtu.spare, GRrtu.spare,1
101         qbeq    done?, GRrtu.spare, 32
102 ;GRrtu.spare  holds portq #   7-0
103         add     r9, GRrtu.spare, MQ_SLOT0_RTU
104         TM_DISABLE
105         MQ_POP  r9, qempty_exit?
106         qbne    $3, MQ_CNT, 0
107         clr     GRrtu.pqmap, GRrtu.pqmap, GRrtu.spare
108 $3:     ; non_empty00
109         TM_ENABLE
110 ;r7-r8 = descriptor
111         mov     r0, r20
113 ;popped packet, decide which dma to use
114         qbbs    use_dma1?, GRrtu.flags, f_dmau
115 ;use dma0 (unit0)
116         set     GRrtu.flags, GRrtu.flags, f_dmau
117         set     GRrtu.flags, GRrtu.flags, f_dma0
118         XFR2VBUS_ISSUE_READ_AUTO_64_CMD XFR2VBUS_XID_READ0, r7, ADDR_HI
119         clr     r8.t20
120         mov     r20, r0
121         mov     r2, r8
122         RTU_IPC_TX_CH0_PPKT
124 ;PSILOOPBACK ..
125  .if $isdefed("PSILOOP")
126 ;read iep for 'rx timestamp' (raw iep counter)
127         GET_FW_TS r2
128         clr     GRrtu.flags, GRrtu.flags, f_dmau  ;!! in PSI loopback we use just 1 dma !!
129  .endif
130         PAGE_SAVE2 SCHED_MAIN
131  .if $isdefed("PSILOOP")
132         PAGE_RESTORE2_REG RTU_GSTATE, 32
133         mov r11.w0, GS_DEF_FLOW
134         PSI_GET_INFO2 PSI_INFO_SLOT, r11.w0
135         PSI_WRITEG
136  .endif
137         jmp     done?
139 use_dma1?:
140 ;use dma1 (unit1)
141         clr     GRrtu.flags, GRrtu.flags, f_dmau
142         XFR2VBUS_ISSUE_READ_AUTO_64_CMD XFR2VBUS_XID_READ1, r7, ADDR_HI
143         set     r8.t20
144         set     GRrtu.flags, GRrtu.flags, f_dma1
145         mov     r20, r0
146         mov     r3, r8
147         RTU_IPC_TX_CH0_EPKT
148         PAGE_SAVE2 SCHED_MAIN2
149         jmp     done?
151 qempty_exit?:  ;shouldn't get here if our bitmap is always consistent..
152         TM_ENABLE
153         clr     GRrtu.pqmap, GRrtu.pqmap, GRrtu.spare
154 done?:
155  .endm
157 ;=====================================
158 ; SCHED_CHECK_DMA {{{1
159 ; utility -> check for dma completion
160 ;=====================================
161 SCHED_CHECK_DMA .macro
162 ; we need to decide which dma we want to check first if the both
163 ; packer are completed together
164         qbbs    $2, GRrtu.flags, f_dmau
166         ; dma0 was used first, so let's see if we need to clean it first
167         qbbc    $1, GRrtu.flags, f_tx0_complete
168         ; clean DMA0
169         clr     GRrtu.flags, GRrtu.flags, f_tx0_complete
170         clr     GRrtu.flags, GRrtu.flags, f_dma0
171         CLEANUP_TX SCHED_MAIN
172 $1:
173         qbbc    done?, GRrtu.flags, f_tx1_complete
174         ; clean DMA1
175         clr     GRrtu.flags, GRrtu.flags, f_tx1_complete
176         clr     GRrtu.flags, GRrtu.flags, f_dma1
177         CLEANUP_TX SCHED_MAIN2
178         qba     done?
179 $2:
180         ; dma0 was used first, so let's see if we need to clean it first
181         qbbc    $3, GRrtu.flags, f_tx1_complete
182         ; clean DMA1
183         clr     GRrtu.flags, GRrtu.flags, f_tx1_complete
184         clr     GRrtu.flags, GRrtu.flags, f_dma1
185         CLEANUP_TX SCHED_MAIN2
186 $3:
187         qbbc    done?, GRrtu.flags, f_tx0_complete
188         ; clean DMA0
189         clr     GRrtu.flags, GRrtu.flags, f_tx0_complete
190         clr     GRrtu.flags, GRrtu.flags, f_dma0
191         CLEANUP_TX SCHED_MAIN
193 done?:
194  .endm