| 1 | // ========== Copyright Header Begin ========================================== |
| 2 | // |
| 3 | // OpenSPARC T2 Processor File: niu_rxcbmgr.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 "niu_mem.vrh" |
| 37 | #include "niu_rx_descp.vrh" |
| 38 | #include "niu_rxtoken.vrh" |
| 39 | #include "niu_cbclass.vrh" |
| 40 | |
| 41 | |
| 42 | |
| 43 | // this class is to manage the callbacks to the memory based upon the |
| 44 | // token content |
| 45 | |
| 46 | |
| 47 | class CcbRxWriteMgr { |
| 48 | |
| 49 | integer max_cbs; |
| 50 | integer max_goodcbs; |
| 51 | integer max_dropcbs; |
| 52 | integer startSemId; |
| 53 | integer dropSemId; |
| 54 | integer good_packetactive_cbs; |
| 55 | integer drop_packetactive_cbs; |
| 56 | integer GoodsemIdTab[]; |
| 57 | integer DropsemIdTab[]; |
| 58 | |
| 59 | bit [63:0] address[]; |
| 60 | |
| 61 | task new( (integer i =0 )) { |
| 62 | integer j; |
| 63 | max_cbs = i; |
| 64 | |
| 65 | if(i!=0) { |
| 66 | max_dropcbs = 2; // TMP? |
| 67 | max_goodcbs = max_cbs - max_dropcbs; |
| 68 | } else { |
| 69 | max_dropcbs = 0; |
| 70 | max_goodcbs = 0; |
| 71 | } |
| 72 | |
| 73 | good_packetactive_cbs = 0; |
| 74 | drop_packetactive_cbs = 0; |
| 75 | for( j=0;j<max_cbs; j ++) { |
| 76 | GoodsemIdTab[j] = 0; |
| 77 | DropsemIdTab[j] = 0; |
| 78 | } |
| 79 | |
| 80 | |
| 81 | |
| 82 | startSemId = alloc(SEMAPHORE,0,max_cbs,0); |
| 83 | dropSemId = alloc(SEMAPHORE,0,1,0); |
| 84 | |
| 85 | } |
| 86 | function integer isAvailable() ; |
| 87 | function integer getgoodpktSemId( bit [63:0] a, ( integer MAX_TIMEOUT = 5000) ) ; |
| 88 | task releaseSemId(integer semId); |
| 89 | function integer getdroppktSemId(); |
| 90 | |
| 91 | } |
| 92 | |
| 93 | |
| 94 | function integer CcbRxWriteMgr::isAvailable() { |
| 95 | |
| 96 | if( ( good_packetactive_cbs + drop_packetactive_cbs) == max_cbs) |
| 97 | isAvailable = 0; |
| 98 | else isAvailable = ( max_cbs - good_packetactive_cbs - drop_packetactive_cbs); |
| 99 | |
| 100 | printf(" CcbRxWriteMgr::isAvailable - %d \n",isAvailable); |
| 101 | |
| 102 | } |
| 103 | function integer CcbRxWriteMgr::getdroppktSemId() { |
| 104 | getdroppktSemId = dropSemId; |
| 105 | } |
| 106 | |
| 107 | |
| 108 | function integer CcbRxWriteMgr::getgoodpktSemId( bit [63:0] a, (integer MAX_TIMEOUT = 5000)) { |
| 109 | |
| 110 | integer i; |
| 111 | integer id; |
| 112 | integer done; |
| 113 | i = 0; |
| 114 | done = 0; |
| 115 | id = 0; |
| 116 | while( (i<max_cbs) & (done==0)) { |
| 117 | printf(" in getgoodpktSemId i = %d , GoodsemIdTab - %d \n",i,GoodsemIdTab[i ]); |
| 118 | if(GoodsemIdTab[i ] ==0) { // ie free |
| 119 | getgoodpktSemId = startSemId + i; |
| 120 | id = startSemId + i; |
| 121 | good_packetactive_cbs++; |
| 122 | GoodsemIdTab[i ] = 1; // Used |
| 123 | done = 1; |
| 124 | } |
| 125 | i++; |
| 126 | } |
| 127 | |
| 128 | // error |
| 129 | if((i== max_cbs) & (done==0)) { |
| 130 | printf(" No more SemIds available i= %d !! ERROR \n",i); |
| 131 | getgoodpktSemId = -1; |
| 132 | } else { |
| 133 | address[id] = a; |
| 134 | printf("CcbRxWriteMgr:: Allocated id - %d Address = %x \n",id,a); |
| 135 | //timeout(SEMAPHORE,MAX_TIMEOUT,id); //temp |
| 136 | } |
| 137 | |
| 138 | } |
| 139 | |
| 140 | task CcbRxWriteMgr::releaseSemId(integer semId){ |
| 141 | |
| 142 | integer i; |
| 143 | i = semId - startSemId ; |
| 144 | printf("CcbRxWriteMgr:: Releasing SemId - %d Address = %x \n",semId,address[semId]); |
| 145 | GoodsemIdTab[i] = 0; |
| 146 | good_packetactive_cbs--; |
| 147 | |
| 148 | } |
| 149 | |