]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - processor-sdk/pdk.git/blob - packages/ti/drv/emac/firmware/icss_dualmac/src/hd_helper.h
J7200 Port for UDMA
[processor-sdk/pdk.git] / packages / ti / drv / emac / firmware / icss_dualmac / src / hd_helper.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 READ_RGMII_CFG  .macro rtmp, speed_flags
56         TM_DISABLE
57         lbco    &rtmp, c9, 0x4, 4
58         and     rtmp.b0, rtmp.b0, f_mask_o ; takes only speed/duplex related bits
59         and     speed_flags, speed_flags, f_mask_a ; clean old status
60         or      speed_flags, speed_flags, rtmp.b0
61         TM_ENABLE
62         .endm
64 ; most likely IPG and backoff is the same timer
65 ; so, we will need only one macro 
66 if_ipg_not_expired      .macro then_go
67         ; TODO check IPG
68         ; if not expired jmp then_go
69         ldi32   r2, FW_CONFIG
70         lbbo    &r3, r2, TX_IPG, 4 ;
71         lbco    &r4, c11, 0x0c, 4  ; read cycle counte
72         qbgt    then_go, r4, r3    ; not expired yet
73         clr     GRegs.speed_f, GRegs.speed_f, f_wait_ipg
74         .endm
76 ; touch r2, r3, r4
77 reset_cycle_cnt .macro
78         lbco    &r2, c11, 0x0, 4 ; disable cycle counter
79         clr     r2.t3
80         sbco    &r2, c11, 0x0, 4
81         zero    &r3, 4           ; reset cycle counter
82         sbco    &r3, c11, 0xc, 4
83         set     r2.t3            ; enable cycle counter
84         sbco    &r2, c11, 0x0, 4
85         .endm
87 IPG_10MBPS      .set 2400 ; (12 * 8 * 100) nsec / 4
88 IPG_10MBPS7     .set 3800 ; ((12 + 7) * 8 * 100) nsec / 4
89 IPG_10MBPS_ADJ  .set 600  ; (3 * 8 * 100) / 4
90 IPG_100MBPS_ADJ .set 60   ; (3 * 8 * 10) / 4
92 start_backoff_timer .macro num
93         reset_cycle_cnt
94         mov     r2, num
95         qbge    $3, r2, 9
96         ldi     r2, 9
97 $3:     ldi     r3, 1           ; create mask
98         not     r3, r3          ;
99         lsl     r3, r3, r2      ;
100         not     r3, r3          ;
101         GET_IEP_CNT     r4      ;
102         xor     r4.w0, r4.w0, r4.w2
103         ldi32   r2, FW_CONFIG      ; read value from SEED
104         lbbo    &r5, r2, CFG_SEED, 4    ; get seed
105         xor     r4, r4, r5      ; xor time with seed 
106         and     r4, r4, r3      ; mask with backoff interval
107         qbbc    $1, GRegs.speed_f, f_100mbps
108         ; for 100 mbps multiply on 5.12 usec (r4 << 7) 
109         lsl     r3, r4, 7
110         ldi     r5, IPG_100MBPS_ADJ ;
111         qba     $2
112 $1:     ; for 10 mbps multiply on 51.2 usec (r4 << 10) + (r4 << 8)
113         lsl     r3, r4, 10
114         lsl     r4, r4, 8
115         add     r3, r3, r4
116         ; for 10 MBPS we need to maintain IPG manually
117         ; so if r3 is 0 then set it to 9.6 usec
118         qbne    $2, r3, 0
119         ldi     r3, IPG_10MBPS
120         ldi     r5, IPG_10MBPS_ADJ ;
121 $2:     add     r3, r3, r5
122         sbbo    &r3, r2, TX_IPG, 4 ; store it to TX_IPG
123         set     GRegs.speed_f, GRegs.speed_f, f_wait_ipg
124         .endm
126 start_ipg_timer .macro
127         reset_cycle_cnt
128         ldi32   r2, FW_CONFIG      ;
129         ldi     r4, IPG_10MBPS7
130         sbbo    &r4, r2, TX_IPG, 4 ; store it to TX_IPG
131         set     GRegs.speed_f, GRegs.speed_f, f_wait_ipg
132         .endm
135 ; read 8bytes from smem offset to reg and reg+1
136 ; we use r0
137 read_bd_from_smem .macro reg, offset
138         ldi32   r0, FW_CONFIG + offset
139         lbbo    &reg, r0, 0, 8
140         .endm
142 write_bd_to_smem .macro reg, offset
143         ldi32   r0, FW_CONFIG + offset
144         sbbo    &reg, r0, 0, 8
145         .endm
147 update_col_status .macro
148  .if $defined("SLICE0")
149         lbco    &r2, c27, 0x38, 4
150  .else
151         lbco    &r2, c27, 0x3c, 4
152  .endif
153         qbbc    $1, r2, 1
154         set     GRegs.speed_f, GRegs.speed_f, f_col_detected
155 $1:
156         .endm
158 read_col_status .macro  reg
159  .if $defined("SLICE0")
160         lbco    &reg, c27, 0x38, 4
161  .else
162         lbco    &reg, c27, 0x3c, 4
163  .endif
164         .endm