Initial commit of OpenSPARC T2 design and verification files.
[OpenSPARC-T2-DV] / verif / model / pcie / dll / tl_consumer.cpp
CommitLineData
86530b38
AT
1// ========== Copyright Header Begin ==========================================
2//
3// OpenSPARC T2 Processor File: tl_consumer.cpp
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#ifndef DLL_tl_consumer_h
36#define DLL_tl_consumer_h
37
38#include "dll_top.hpp"
39
40namespace pcie {
41
42 /** This function processes packets from TL **/
43 void dll_top::tl_consumer()
44 {
45 LOG_DEBUG<<"DLL: tl_consumer begins...";
46 try{
47 RefPciePacket receive_packet;
48 int i,packet_size;
49 sc_uint<32> lcrc_mapped;
50
51 while (true) {
52
53 if ( ltssm_L0s ) // || replay_buffer_size <= 0 )
54 {
55 // Cease accepting TLPs from TL until the equation is not satisfied
56 }
57 else
58 {
59 // Receive packet from TL
60 tl_dll_in.get_packet(receive_packet);
61 // Display packet
62 LOG_DEBUG << " _DLL_: Received packet from TL with PktId= " << receive_packet->getPacketId() << " Size= " << receive_packet->get_size();
63 //cout << sc_time_stamp() << "\t\t\t\t\t| DLL: Received TLP " << receive_packet->getPacketId() << " from ETL." << endl;
64 // Apply NEXT_TRANSMIT_SEQ to TLP
65 prepend_byte0.range(7,4) = 0;
66 prepend_byte0.range(3,0) = NEXT_TRANSMIT_SEQ.range(11,8);
67
68 prepend_byte1 = NEXT_TRANSMIT_SEQ.range(7,0);
69
70 receive_packet->modify_byte(1,prepend_byte0);
71 receive_packet->modify_byte(2,prepend_byte1);
72
73 lcrc_mapped=calculate_lcrc(receive_packet,1,receive_packet->get_size() - 4);
74
75 packet_size=receive_packet->get_size();
76
77 if(receive_packet->get_control() != 0x12){
78 receive_packet->set_control(0xa);
79 receive_packet->modify_byte(packet_size-4,lcrc_mapped.range(31,24));
80 receive_packet->modify_byte(packet_size-3,lcrc_mapped.range(23,16));
81 receive_packet->modify_byte(packet_size-2,lcrc_mapped.range(15,8));
82 receive_packet->modify_byte(packet_size-1,lcrc_mapped.range(7,0));
83 }
84 else{
85 LOG_DEBUG << "NULLifying PACKET";
86 receive_packet->modify_byte(packet_size-4,~lcrc_mapped.range(31,24));
87 receive_packet->modify_byte(packet_size-3,~lcrc_mapped.range(23,16));
88 receive_packet->modify_byte(packet_size-2,~lcrc_mapped.range(15,8));
89 receive_packet->modify_byte(packet_size-1,~lcrc_mapped.range(7,0));
90 }
91
92 queue_TLP.push(receive_packet);
93 eventPlPktRdy.notify();
94 // Update registers
95 NEXT_TRANSMIT_SEQ++;
96
97 // Do FC init checks
98 if ( Flag_FC1 && !Flag_FC2 &&
99 (receive_packet->get_byte(0) == STP ) )
100 {
101 Flag_FC2=1;
102 LOG_DEBUG << "_DLL_:FI1 and FI2 flags are set! ";
103 }// if
104 }// else
105 }// while
106 }
107 catch(sc_exception &e){
108 LOG_DEBUG<<"DLL: Out of tl_consumer";
109 }
110 } // tl_consumer
111
112
113 /** This function polls LTSSM state **/
114 void dll_top::ltssm_state_check()
115 {
116 LOG_DEBUG<<"DLL: ltssm_state_check begins...";
117 try{
118
119 while ( true)
120 {
121 WAIT(csr_core_status_ev);
122 ltssm_state_reg = csr_port.read_csr(PEU_CSR_A_CORE_STATUS_HW_ADDR);
123 if ( ltssm_state_reg.range(48,44) == 17 ) // ILUPEU_LTSSM_L0S
124 ltssm_L0s = 1;
125 else
126 ltssm_L0s = 0;
127 } // while
128 }
129 catch(sc_exception &e){
130 LOG_DEBUG<<"DLL: Out of ltss_state_check";
131 }
132 } // ltssm_state_check
133}
134#endif