| 1 | // ========== Copyright Header Begin ========================================== |
| 2 | // |
| 3 | // OpenSPARC T2 Processor File: mac_pio_class.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 "bmac_memory_map.vri" |
| 37 | #include "xmac_memory_map.vri" |
| 38 | #include "pcs_memory_map.vri" |
| 39 | #include "mac_shadow_class.vrh" |
| 40 | #include "xmac_shadow_class.vrh" |
| 41 | #include "pio_driver.vrh" |
| 42 | #include "cMesg.vrh" |
| 43 | |
| 44 | //extern pio_drv pio_driver_class; |
| 45 | extern Mesg be_msg; |
| 46 | extern niu_gen_pio gen_pio_drv; |
| 47 | |
| 48 | class mac_pio_cl { |
| 49 | mac_shadow_cl mac_shadow_class[4]; |
| 50 | xmac_shadow_cl xmac_shadow_class[4]; |
| 51 | pio_drv pio_drv_mac; |
| 52 | |
| 53 | task new ( ) ; |
| 54 | //task mac_init () ; |
| 55 | task mac_pio_rd (bit [39:0] addr, var bit [31:0] read_data) ; |
| 56 | task mac_pio_wr (bit [39:0] addr, bit [31:0] write_data) ; |
| 57 | task xmac_pio_rd(bit[39:0] addr,var bit[31:0] read_data, \ |
| 58 | bit compare_en,(bit expect_pio_err = 1'b0)); |
| 59 | task bmac_pio_rd(bit[39:0] addr,var bit[31:0] read_data, \ |
| 60 | bit compare_en, (bit expect_pio_err = 1'b0)); |
| 61 | task xmac_pio_wr(bit[39:0] addr,bit[31:0] write_data, \ |
| 62 | (bit expect_pio_err = 1'b0) ); |
| 63 | task bmac_pio_wr(bit[39:0] addr,bit[31:0] write_data, (bit expect_pio_err = 1'b0) ); |
| 64 | function bit isMACPromisBitSet ( integer port_id, bit [47:0] pkt_mac_da); |
| 65 | local function integer getPortID(bit [39:0] addr) { |
| 66 | case(addr[19:12]) |
| 67 | { |
| 68 | 8'h80:getPortID = 0; |
| 69 | 8'h82:getPortID = 0; |
| 70 | 8'h84:getPortID = 0; |
| 71 | 8'h86:getPortID = 1; |
| 72 | 8'h88:getPortID = 1; |
| 73 | 8'h8a:getPortID = 1; |
| 74 | 8'h8c:getPortID = 2; |
| 75 | 8'h8e:getPortID = 2; |
| 76 | 8'h90:getPortID = 3; |
| 77 | 8'h92:getPortID = 3; |
| 78 | } |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | task mac_pio_cl::new( ) { |
| 83 | |
| 84 | integer i; |
| 85 | pio_drv_mac = new (); |
| 86 | for(i = 0;i<2;i++) |
| 87 | { |
| 88 | xmac_shadow_class[i] = new(i); |
| 89 | } |
| 90 | } |
| 91 | |
| 92 | |
| 93 | function bit mac_pio_cl::isMACPromisBitSet ( integer port_id, bit [47:0] pkt_mac_da) { |
| 94 | bit [31:0] data; |
| 95 | bit [32:0] addr; |
| 96 | bit [31:0] data_mask; |
| 97 | bit data_valid; |
| 98 | bit promisc_bit; |
| 99 | bit da_match; |
| 100 | |
| 101 | printf ("mac_pio_cl::isMACPromisBitSet port_id=%0d, pkt_mac_da=%0h\n", port_id, pkt_mac_da); |
| 102 | if(port_id>1) { |
| 103 | mac_shadow_class[port_id].get_data(RxMAC_CONFIG,data, data_mask, data_valid); |
| 104 | addr = RxMAC_CONFIG; |
| 105 | if(data[3] == 1) { |
| 106 | promisc_bit = 1; |
| 107 | } |
| 108 | else |
| 109 | promisc_bit = 0; |
| 110 | } |
| 111 | else { |
| 112 | xmac_shadow_class[port_id].get_data(XMAC_CONFIG,data, data_mask, data_valid); |
| 113 | if(data[9] == 1) |
| 114 | promisc_bit = 1; |
| 115 | else |
| 116 | promisc_bit = 0; |
| 117 | } |
| 118 | |
| 119 | da_match = 0; |
| 120 | // Now, see if the given pkt_DA matches with any of the programmed DAs for this port |
| 121 | if (port_id==0 | port_id==1) { // XMAC |
| 122 | if (({xmac_shadow_class[port_id].xmac_addr5[15:0], \ |
| 123 | xmac_shadow_class[port_id].xmac_addr4[15:0], \ |
| 124 | xmac_shadow_class[port_id].xmac_addr3[15:0]}===pkt_mac_da) && \ |
| 125 | xmac_shadow_class[port_id].xmac_addr_cmpen_lsb[0]) // DA0 |
| 126 | da_match = 1; |
| 127 | |
| 128 | else if (({xmac_shadow_class[port_id].xmac_addr8[15:0], \ |
| 129 | xmac_shadow_class[port_id].xmac_addr7[15:0], \ |
| 130 | xmac_shadow_class[port_id].xmac_addr6[15:0]}===pkt_mac_da) && \ |
| 131 | xmac_shadow_class[port_id].xmac_addr_cmpen_lsb[1]) // DA1 |
| 132 | da_match = 1; |
| 133 | |
| 134 | else if (({xmac_shadow_class[port_id].xmac_addr11[15:0], \ |
| 135 | xmac_shadow_class[port_id].xmac_addr10[15:0], \ |
| 136 | xmac_shadow_class[port_id].xmac_addr9[15:0]}===pkt_mac_da) && \ |
| 137 | xmac_shadow_class[port_id].xmac_addr_cmpen_lsb[2]) // DA2 |
| 138 | da_match = 1; |
| 139 | |
| 140 | else if (({xmac_shadow_class[port_id].xmac_addr14[15:0], \ |
| 141 | xmac_shadow_class[port_id].xmac_addr13[15:0], \ |
| 142 | xmac_shadow_class[port_id].xmac_addr12[15:0]}===pkt_mac_da) && \ |
| 143 | xmac_shadow_class[port_id].xmac_addr_cmpen_lsb[3]) // DA3 |
| 144 | da_match = 1; |
| 145 | |
| 146 | else if (({xmac_shadow_class[port_id].xmac_addr17[15:0], \ |
| 147 | xmac_shadow_class[port_id].xmac_addr16[15:0], \ |
| 148 | xmac_shadow_class[port_id].xmac_addr15[15:0]}===pkt_mac_da) && \ |
| 149 | xmac_shadow_class[port_id].xmac_addr_cmpen_lsb[4]) // DA4 |
| 150 | da_match = 1; |
| 151 | |
| 152 | else if (({xmac_shadow_class[port_id].xmac_addr20[15:0], \ |
| 153 | xmac_shadow_class[port_id].xmac_addr19[15:0], \ |
| 154 | xmac_shadow_class[port_id].xmac_addr18[15:0]}===pkt_mac_da) && \ |
| 155 | xmac_shadow_class[port_id].xmac_addr_cmpen_lsb[5]) // DA5 |
| 156 | da_match = 1; |
| 157 | else if (({xmac_shadow_class[port_id].xmac_addr23[15:0], \ |
| 158 | xmac_shadow_class[port_id].xmac_addr22[15:0], \ |
| 159 | xmac_shadow_class[port_id].xmac_addr21[15:0]}===pkt_mac_da) && \ |
| 160 | xmac_shadow_class[port_id].xmac_addr_cmpen_lsb[6]) // DA6 |
| 161 | da_match = 1; |
| 162 | else if (({xmac_shadow_class[port_id].xmac_addr26[15:0], \ |
| 163 | xmac_shadow_class[port_id].xmac_addr25[15:0], \ |
| 164 | xmac_shadow_class[port_id].xmac_addr24[15:0]}===pkt_mac_da) && \ |
| 165 | xmac_shadow_class[port_id].xmac_addr_cmpen_lsb[7]) // DA7 |
| 166 | da_match = 1; |
| 167 | else if (({xmac_shadow_class[port_id].xmac_addr29[15:0], \ |
| 168 | xmac_shadow_class[port_id].xmac_addr28[15:0], \ |
| 169 | xmac_shadow_class[port_id].xmac_addr27[15:0]}===pkt_mac_da) && \ |
| 170 | xmac_shadow_class[port_id].xmac_addr_cmpen_lsb[8]) // DA8 |
| 171 | da_match = 1; |
| 172 | else if (({xmac_shadow_class[port_id].xmac_addr32[15:0], \ |
| 173 | xmac_shadow_class[port_id].xmac_addr31[15:0], \ |
| 174 | xmac_shadow_class[port_id].xmac_addr30[15:0]}===pkt_mac_da) && \ |
| 175 | xmac_shadow_class[port_id].xmac_addr_cmpen_lsb[9]) // DA9 |
| 176 | da_match = 1; |
| 177 | else if (({xmac_shadow_class[port_id].xmac_addr35[15:0], \ |
| 178 | xmac_shadow_class[port_id].xmac_addr34[15:0], \ |
| 179 | xmac_shadow_class[port_id].xmac_addr33[15:0]}===pkt_mac_da) && \ |
| 180 | xmac_shadow_class[port_id].xmac_addr_cmpen_lsb[10]) // DA10 |
| 181 | da_match = 1; |
| 182 | else if (({xmac_shadow_class[port_id].xmac_addr38[15:0], \ |
| 183 | xmac_shadow_class[port_id].xmac_addr37[15:0], \ |
| 184 | xmac_shadow_class[port_id].xmac_addr36[15:0]}===pkt_mac_da) && \ |
| 185 | xmac_shadow_class[port_id].xmac_addr_cmpen_lsb[11]) // DA11 |
| 186 | da_match = 1; |
| 187 | else if (({xmac_shadow_class[port_id].xmac_addr41[15:0], \ |
| 188 | xmac_shadow_class[port_id].xmac_addr40[15:0], \ |
| 189 | xmac_shadow_class[port_id].xmac_addr39[15:0]}===pkt_mac_da) && \ |
| 190 | xmac_shadow_class[port_id].xmac_addr_cmpen_lsb[12]) // DA12 |
| 191 | da_match = 1; |
| 192 | else if (({xmac_shadow_class[port_id].xmac_addr44[15:0], \ |
| 193 | xmac_shadow_class[port_id].xmac_addr43[15:0], \ |
| 194 | xmac_shadow_class[port_id].xmac_addr42[15:0]}===pkt_mac_da) && \ |
| 195 | xmac_shadow_class[port_id].xmac_addr_cmpen_lsb[13]) // DA13 |
| 196 | da_match = 1; |
| 197 | else if (({xmac_shadow_class[port_id].xmac_addr47[15:0], \ |
| 198 | xmac_shadow_class[port_id].xmac_addr46[15:0], \ |
| 199 | xmac_shadow_class[port_id].xmac_addr45[15:0]}===pkt_mac_da) && \ |
| 200 | xmac_shadow_class[port_id].xmac_addr_cmpen_lsb[14]) // DA14 |
| 201 | da_match = 1; |
| 202 | else if (({xmac_shadow_class[port_id].xmac_addr50[15:0], \ |
| 203 | xmac_shadow_class[port_id].xmac_addr49[15:0], \ |
| 204 | xmac_shadow_class[port_id].xmac_addr48[15:0]}===pkt_mac_da) && \ |
| 205 | xmac_shadow_class[port_id].xmac_addr_cmpen_lsb[15]) // DA15 |
| 206 | da_match = 1; |
| 207 | else |
| 208 | da_match = 0; |
| 209 | } |
| 210 | else if (port_id==2 | port_id==3) { // BMAC |
| 211 | |
| 212 | printf("pkt_mac_da for port_id %0d is %0h\n", pkt_mac_da, port_id); |
| 213 | |
| 214 | if (({mac_shadow_class[port_id].mac_addr5[15:0], \ |
| 215 | mac_shadow_class[port_id].mac_addr4[15:0], \ |
| 216 | mac_shadow_class[port_id].mac_addr3[15:0]}===pkt_mac_da) && \ |
| 217 | mac_shadow_class[port_id].bmac_altad_cmpen[1]) // DA0 // bit 0 is for unique address |
| 218 | da_match = 1; |
| 219 | else if (({mac_shadow_class[port_id].mac_addr8[15:0], \ |
| 220 | mac_shadow_class[port_id].mac_addr7[15:0], \ |
| 221 | mac_shadow_class[port_id].mac_addr6[15:0]}===pkt_mac_da) && \ |
| 222 | mac_shadow_class[port_id].bmac_altad_cmpen[2]) // DA1 |
| 223 | da_match = 1; |
| 224 | else if (({mac_shadow_class[port_id].mac_addr11[15:0], \ |
| 225 | mac_shadow_class[port_id].mac_addr10[15:0], \ |
| 226 | mac_shadow_class[port_id].mac_addr9[15:0]}===pkt_mac_da) && \ |
| 227 | mac_shadow_class[port_id].bmac_altad_cmpen[3]) // DA2 |
| 228 | da_match = 1; |
| 229 | else if (({mac_shadow_class[port_id].mac_addr14[15:0], \ |
| 230 | mac_shadow_class[port_id].mac_addr13[15:0], \ |
| 231 | mac_shadow_class[port_id].mac_addr12[15:0]}===pkt_mac_da) && \ |
| 232 | mac_shadow_class[port_id].bmac_altad_cmpen[4]) // DA3 |
| 233 | da_match = 1; |
| 234 | else if (({mac_shadow_class[port_id].mac_addr17[15:0], \ |
| 235 | mac_shadow_class[port_id].mac_addr16[15:0], \ |
| 236 | mac_shadow_class[port_id].mac_addr15[15:0]}===pkt_mac_da) && \ |
| 237 | mac_shadow_class[port_id].bmac_altad_cmpen[5]) // DA4 |
| 238 | da_match = 1; |
| 239 | else if (({mac_shadow_class[port_id].mac_addr20[15:0], \ |
| 240 | mac_shadow_class[port_id].mac_addr19[15:0], \ |
| 241 | mac_shadow_class[port_id].mac_addr18[15:0]}===pkt_mac_da) && \ |
| 242 | mac_shadow_class[port_id].bmac_altad_cmpen[6]) // DA5 |
| 243 | da_match = 1; |
| 244 | else if (({mac_shadow_class[port_id].mac_addr23[15:0], \ |
| 245 | mac_shadow_class[port_id].mac_addr22[15:0], \ |
| 246 | mac_shadow_class[port_id].mac_addr21[15:0]}===pkt_mac_da) && \ |
| 247 | mac_shadow_class[port_id].bmac_altad_cmpen[7]) // DA6 |
| 248 | da_match = 1; |
| 249 | else |
| 250 | da_match = 0; |
| 251 | } |
| 252 | |
| 253 | |
| 254 | // Now, set the actual promisc_bit_set result |
| 255 | if (da_match) // DA MATCHED |
| 256 | isMACPromisBitSet = 0; |
| 257 | else { // NO DA MATCH |
| 258 | if (promisc_bit) { |
| 259 | isMACPromisBitSet = 1; |
| 260 | printf("isMACPromisBitSet:prom bit is set\n"); } |
| 261 | else { |
| 262 | isMACPromisBitSet = 0; |
| 263 | printf("isMACPromisBitSet: prom bit is not set\n"); } |
| 264 | } |
| 265 | } |
| 266 | |
| 267 | task mac_pio_cl::xmac_pio_rd(bit[39:0] addr,var bit[31:0] read_data, |
| 268 | bit compare_en, (bit expect_pio_err = 1'b0)) |
| 269 | { |
| 270 | bit[31:0] exp_data = 0; |
| 271 | |
| 272 | bit [31:0] exp_data_mask = 0; |
| 273 | bit exp_data_valid = 0; |
| 274 | bit [63:0] gen_read_data; |
| 275 | integer port_id; |
| 276 | |
| 277 | |
| 278 | port_id = getPortID(addr); |
| 279 | |
| 280 | if(port_id <2){ |
| 281 | xmac_shadow_class[port_id].get_data(addr,exp_data,exp_data_mask,exp_data_valid); |
| 282 | } |
| 283 | |
| 284 | |
| 285 | // if (addr[32] != 1) { |
| 286 | gen_pio_drv.pio_rd(addr,gen_read_data,exp_data, exp_data_mask, \ |
| 287 | compare_en, expect_pio_err ); |
| 288 | read_data[31:0] = gen_read_data[31:0]; |
| 289 | // } |
| 290 | |
| 291 | |
| 292 | } |
| 293 | |
| 294 | task mac_pio_cl::bmac_pio_rd(bit[39:0] addr,var bit[31:0] read_data, \ |
| 295 | bit compare_en, (bit expect_pio_err = 1'b0)) |
| 296 | { |
| 297 | bit[31:0] exp_data,exp_data_mask; |
| 298 | bit exp_data_valid,compare_en; |
| 299 | bit [63:0] gen_read_data; |
| 300 | integer port_id; |
| 301 | port_id = getPortID(addr); |
| 302 | if(port_id>1) { |
| 303 | mac_shadow_class[port_id].get_data(addr,exp_data,exp_data_mask,exp_data_valid); |
| 304 | } |
| 305 | //if (addr[32] != 1) { |
| 306 | gen_pio_drv.pio_rd(addr,gen_read_data,exp_data,exp_data_mask,compare_en,expect_pio_err); |
| 307 | read_data[31:0] = gen_read_data[31:0]; |
| 308 | //} |
| 309 | |
| 310 | |
| 311 | } |
| 312 | |
| 313 | task mac_pio_cl::mac_pio_rd(bit [39:0] addr, var bit [31:0] read_data) { |
| 314 | |
| 315 | bit [31:0] exp_data = 0; |
| 316 | bit [31:0] exp_data_mask = 0; |
| 317 | bit exp_data_valid = 0; |
| 318 | bit compare_en = 0; |
| 319 | bit [63:0] gen_read_data; |
| 320 | // Add code here to see if the register address is valid within PC. |
| 321 | integer port_id; |
| 322 | port_id = getPortID(addr); |
| 323 | |
| 324 | if(port_id>1) { |
| 325 | |
| 326 | mac_shadow_class[port_id].get_data(addr, exp_data, exp_data_mask, exp_data_valid); |
| 327 | } else |
| 328 | xmac_shadow_class[port_id].get_data(addr, exp_data, exp_data_mask, exp_data_valid); |
| 329 | |
| 330 | // pio_driver_class.pio_rd(addr, read_data, exp_data, exp_data_mask, compare_en); |
| 331 | gen_pio_drv.pio_rd(addr, gen_read_data, compare_en); |
| 332 | read_data[31:0] = gen_read_data[31:0]; |
| 333 | } |
| 334 | |
| 335 | // |
| 336 | // pc_pio_wr Task |
| 337 | // |
| 338 | task mac_pio_cl::xmac_pio_wr(bit[39:0] addr,bit[31:0] write_data, \ |
| 339 | (bit expect_pio_err = 1'b0)) |
| 340 | { |
| 341 | integer port_id; |
| 342 | port_id = getPortID(addr); |
| 343 | |
| 344 | if(port_id < 2) |
| 345 | xmac_shadow_class[port_id].put_data(addr,write_data); |
| 346 | |
| 347 | pio_drv_mac.pio_wr(addr, write_data, expect_pio_err); |
| 348 | //} |
| 349 | } |
| 350 | task mac_pio_cl::bmac_pio_wr(bit[39:0] addr,bit[31:0] write_data, \ |
| 351 | (bit expect_pio_err = 1'b0)) |
| 352 | { |
| 353 | integer port_id; |
| 354 | port_id = getPortID(addr); |
| 355 | if(port_id>1) { |
| 356 | mac_shadow_class[port_id].put_data(addr ,write_data); |
| 357 | } |
| 358 | pio_drv_mac.pio_wr(addr, write_data,expect_pio_err); |
| 359 | //} |
| 360 | } |
| 361 | |
| 362 | task mac_pio_cl::mac_pio_wr(bit [39:0] addr, bit [31:0] write_data) { |
| 363 | |
| 364 | pio_drv_mac.pio_wr(addr, write_data ); |
| 365 | |
| 366 | } |
| 367 | |