Initial commit of OpenSPARC T2 design and verification files.
[OpenSPARC-T2-DV] / verif / env / niu / vera / niu_pio / xpcs_util.vr
CommitLineData
86530b38
AT
1// ========== Copyright Header Begin ==========================================
2//
3// OpenSPARC T2 Processor File: xpcs_util.vr
4// Copyright (C) 1995-2007 Sun Microsystems, Inc. All Rights Reserved
5// 4150 Network Circle, Santa Clara, California 95054, U.S.A.
6//
7// * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8//
9// This program is free software; you can redistribute it and/or modify
10// it under the terms of the GNU General Public License as published by
11// the Free Software Foundation; version 2 of the License.
12//
13// This program is distributed in the hope that it will be useful,
14// but WITHOUT ANY WARRANTY; without even the implied warranty of
15// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16// GNU General Public License for more details.
17//
18// You should have received a copy of the GNU General Public License
19// along with this program; if not, write to the Free Software
20// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21//
22// For the avoidance of doubt, and except that if any non-GPL license
23// choice is available it will apply instead, Sun elects to use only
24// the General Public License version 2 (GPLv2) at this time for any
25// software where a choice of GPL license versions is made
26// available with the language indicating that GPLv2 or any later version
27// may be used, or where a choice of which version of the GPL is applied is
28// otherwise unspecified.
29//
30// Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
31// CA 95054 USA or visit www.sun.com if you need additional information or
32// have any questions.
33//
34// ========== Copyright Header End ============================================
35#include <vera_defines.vrh>
36#include "mac_defines.vri"
37#include "xpcs_memory_map.vri"
38#include "pio_driver.vrh"
39#include "mac_pio_class.vrh"
40#include "pcs_memory_map.vri"
41#include "pcs_util.vrh"
42
43extern mac_pio_cl mac_pio_class;
44
45class xpcs_util_class {
46
47 pcs_util_class pcs_util_cl;
48
49 task new();
50 task xpcs_init ( integer iport);
51 function bit[39:0] get_xpcs_reg_base(integer iport);
52 task link_up_rdy (integer iport);
53
54}
55
56task xpcs_util_class :: new(){
57
58 pcs_util_cl = new();
59}
60
61
62task xpcs_util_class :: xpcs_init ( integer iport ) {
63
64 bit [39:0] base_addr;
65 bit [31:0] rd_data;
66 integer count = 0;
67
68 base_addr = get_xpcs_reg_base(iport);
69
70
71 mac_pio_class.mac_pio_wr(base_addr + XPCS_CONTROL1, 32'h0000_8000);
72 printf("The address is %0h\n",base_addr + XPCS_CONTROL1);
73
74 while (rd_data[15] != 1'b0) {
75 mac_pio_class.mac_pio_rd(base_addr + XPCS_CONTROL1, rd_data);
76 count++;
77 if(count > 100) {
78 printf("ERROR : XPCS SW_RESET FAILED\n");
79 }
80 repeat(20) @(CLOCK);
81 }
82 repeat(4) @(CLOCK);
83
84 printf("XPCS Reseted successfully\n");
85
86}
87
88task xpcs_util_class :: link_up_rdy(integer iport){
89 integer count = 0;
90 integer link_up = 0;
91 bit [31:0] r_data;
92 bit [39:0] base_addr;
93 integer mac_speed0,mac_speed1;
94
95 if ( get_plus_arg(CHECK, "MAC_SPEED0=") )
96 {
97 mac_speed0 = get_plus_arg(NUM, "MAC_SPEED0") ;
98 }
99 if ( get_plus_arg(CHECK, "MAC_SPEED1=") )
100 {
101 mac_speed1 = get_plus_arg(NUM, "MAC_SPEED1") ;
102 }
103
104 if(iport == 0){
105 if(mac_speed0 == 10000){
106 base_addr = get_xpcs_reg_base(0);
107 while (!link_up) {
108 if(count != 0)
109 repeat (100) @(posedge CLOCK);
110 mac_pio_class.mac_pio_rd(base_addr + XPCS_STATUS1, r_data);
111 if(r_data[2]) {
112 count = 0;
113 link_up = 1;
114 printf("INFO : link is up\n");
115 } else {
116 count++;
117 if(count > 500) {
118 printf("ERROR : link_up didn't go high after 50000 clocks\n");
119 link_up = 1;
120 } else link_up = 0;
121 }
122 }
123 }
124 else if(mac_speed0 == 1000){
125 base_addr = pcs_util_cl.get_pcs_reg_base(0);
126 mac_pio_class.mac_pio_rd(base_addr + PCS_DATAPATH_MODE, r_data);
127 if(r_data[1] == 0) {
128 while (!link_up) {
129 if(count != 0)
130 repeat (100) @(posedge CLOCK);
131 mac_pio_class.mac_pio_rd(base_addr + PCS_MII_STATUS, r_data);
132 if(r_data[2] == 1'b1) {
133 count = 0;
134 link_up = 1;
135 printf("INFO : link is up\n");
136 } else {
137 count++;
138 if(count > 500) {
139 printf("ERROR : link_up didn't go high after 50000 clocks\n");
140 link_up = 1;
141 } else link_up = 0;
142 }
143 }
144 }
145 else
146 printf("not checking for link since in RGMII mode");
147 }
148 }
149 if(iport == 1){
150 if(mac_speed1 == 10000){
151 base_addr = get_xpcs_reg_base(1);
152 while (!link_up) {
153 if(count != 0)
154 repeat (100) @(posedge CLOCK);
155 mac_pio_class.mac_pio_rd(base_addr + XPCS_STATUS1, r_data);
156 if(r_data[2]) {
157 count = 0;
158 link_up = 1;
159 printf("INFO : link is up\n");
160 } else {
161 count++;
162 if(count > 500) {
163 printf("ERROR : link_up didn't go high after 50000 clocks\n");
164 link_up = 1;
165 } else link_up = 0;
166 }
167 }
168 }
169 else if(mac_speed1 == 1000){
170 base_addr = pcs_util_cl.get_pcs_reg_base(1);
171 mac_pio_class.mac_pio_rd(base_addr + PCS_DATAPATH_MODE, r_data);
172 if(r_data[1] == 0) {
173 while (!link_up) {
174 if(count != 0)
175 repeat (100) @(posedge CLOCK);
176 mac_pio_class.mac_pio_rd(base_addr + PCS_MII_STATUS, r_data);
177 if(r_data[2] == 1'b1) {
178 count = 0;
179 link_up = 1;
180 printf("INFO : link is up\n");
181 } else {
182 count++;
183 if(count > 500) {
184 printf("ERROR : link_up didn't go high after 50000 clocks\n");
185 link_up = 1;
186 } else link_up = 0;
187 }
188 }
189 }
190 else
191 printf("not checking for link since in RGMII mode");
192 }
193 }
194
195}
196
197function bit[39:0] xpcs_util_class :: get_xpcs_reg_base(integer iport){
198
199 case(iport) {
200 0: get_xpcs_reg_base = XPCS0_BASE;
201 1: get_xpcs_reg_base = XPCS1_BASE;
202 default: error("Error: Invalid PORT (%0d) for get_xpcs_reg_base task\n",iport);
203 }
204
205}
206