1 |
31 |
dgisselq |
////////////////////////////////////////////////////////////////////////////////
|
2 |
|
|
//
|
3 |
|
|
// Filename: rxehwmac.v
|
4 |
|
|
//
|
5 |
|
|
// Project: OpenArty, an entirely open SoC based upon the Arty platform
|
6 |
|
|
//
|
7 |
|
|
// Purpose: To remove MACs that aren't our own. The input is a nibble
|
8 |
|
|
// stream, where the first nibble is the first nibble of the
|
9 |
|
|
// destination MAC (our MAC). If enabled, this MAC is removed from the
|
10 |
|
|
// stream. If the MAC matches, the stream is allowed to continue. If
|
11 |
|
|
// the MAC doesn't match, the packet is thrown away.
|
12 |
|
|
//
|
13 |
|
|
// Creator: Dan Gisselquist, Ph.D.
|
14 |
|
|
// Gisselquist Technology, LLC
|
15 |
|
|
//
|
16 |
|
|
////////////////////////////////////////////////////////////////////////////////
|
17 |
|
|
//
|
18 |
|
|
// Copyright (C) 2016, Gisselquist Technology, LLC
|
19 |
|
|
//
|
20 |
|
|
// This program is free software (firmware): you can redistribute it and/or
|
21 |
|
|
// modify it under the terms of the GNU General Public License as published
|
22 |
|
|
// by the Free Software Foundation, either version 3 of the License, or (at
|
23 |
|
|
// your option) any later version.
|
24 |
|
|
//
|
25 |
|
|
// This program is distributed in the hope that it will be useful, but WITHOUT
|
26 |
|
|
// ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
|
27 |
|
|
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
28 |
|
|
// for more details.
|
29 |
|
|
//
|
30 |
|
|
// You should have received a copy of the GNU General Public License along
|
31 |
|
|
// with this program. (It's in the $(ROOT)/doc directory, run make with no
|
32 |
|
|
// target there if the PDF file isn't present.) If not, see
|
33 |
|
|
// <http://www.gnu.org/licenses/> for a copy.
|
34 |
|
|
//
|
35 |
|
|
// License: GPL, v3, as defined and found on www.gnu.org,
|
36 |
|
|
// http://www.gnu.org/licenses/gpl.html
|
37 |
|
|
//
|
38 |
|
|
//
|
39 |
|
|
////////////////////////////////////////////////////////////////////////////////
|
40 |
|
|
//
|
41 |
|
|
//
|
42 |
|
|
module rxehwmac(i_clk, i_ce, i_en, i_cancel, i_hwmac, i_v, i_d, o_v, o_d, o_err, o_broadcast);
|
43 |
|
|
input i_clk, i_ce, i_en, i_cancel;
|
44 |
|
|
input [47:0] i_hwmac;
|
45 |
|
|
input i_v;
|
46 |
|
|
input [3:0] i_d;
|
47 |
|
|
output reg o_v;
|
48 |
|
|
output reg [3:0] o_d;
|
49 |
|
|
output wire o_err;
|
50 |
|
|
output reg o_broadcast;
|
51 |
|
|
|
52 |
33 |
dgisselq |
wire [47:0] mac_remapped;
|
53 |
|
|
|
54 |
|
|
assign mac_remapped[47:44] = i_hwmac[43:40];
|
55 |
|
|
assign mac_remapped[43:40] = i_hwmac[47:44];
|
56 |
|
|
assign mac_remapped[39:36] = i_hwmac[35:32];
|
57 |
|
|
assign mac_remapped[35:32] = i_hwmac[39:36];
|
58 |
|
|
assign mac_remapped[31:28] = i_hwmac[27:24];
|
59 |
|
|
assign mac_remapped[27:24] = i_hwmac[31:28];
|
60 |
|
|
assign mac_remapped[23:20] = i_hwmac[19:16];
|
61 |
|
|
assign mac_remapped[19:16] = i_hwmac[23:20];
|
62 |
|
|
assign mac_remapped[15:12] = i_hwmac[11: 8];
|
63 |
|
|
assign mac_remapped[11: 8] = i_hwmac[15:12];
|
64 |
|
|
assign mac_remapped[ 7: 4] = i_hwmac[ 3: 0];
|
65 |
|
|
assign mac_remapped[ 3: 0] = i_hwmac[ 7: 4];
|
66 |
|
|
|
67 |
31 |
dgisselq |
reg [47:0] r_hwmac;
|
68 |
|
|
reg r_cancel, r_err, r_hwmatch, r_broadcast;
|
69 |
|
|
reg [19:0] r_buf;
|
70 |
|
|
reg [29:0] r_p;
|
71 |
|
|
|
72 |
|
|
always @(posedge i_clk)
|
73 |
|
|
if (i_ce)
|
74 |
|
|
begin
|
75 |
|
|
if (i_cancel)
|
76 |
|
|
r_cancel <= 1'b1;
|
77 |
|
|
else if ((!i_v)&&(!o_v))
|
78 |
|
|
r_cancel <= 1'b0;
|
79 |
|
|
|
80 |
|
|
if ((i_en)&&(i_v)&&(r_p[11]))
|
81 |
|
|
begin
|
82 |
|
|
if (r_hwmac[47:44] != i_d)
|
83 |
|
|
r_hwmatch <= 1'b0;
|
84 |
|
|
if (4'hf != i_d)
|
85 |
|
|
r_broadcast<= 1'b0;
|
86 |
|
|
end
|
87 |
|
|
|
88 |
33 |
dgisselq |
if ((i_v)&&(r_p[11]))
|
89 |
|
|
r_hwmac <= { r_hwmac[43:0], 4'h0 };
|
90 |
|
|
|
91 |
31 |
dgisselq |
r_err <= (i_en)&&(!r_hwmatch)&&(!r_broadcast)&&(i_v);
|
92 |
|
|
o_broadcast <= (r_broadcast)&&(!r_p[11])&&(i_v);
|
93 |
|
|
|
94 |
|
|
r_buf <= { r_buf[14:0], i_v, i_d };
|
95 |
|
|
if (((!i_v)&&(!o_v))||(i_cancel))
|
96 |
|
|
begin
|
97 |
|
|
r_p <= 30'h3fff_ffff;
|
98 |
33 |
dgisselq |
r_hwmac <= mac_remapped;
|
99 |
31 |
dgisselq |
r_hwmatch <= 1'b1;
|
100 |
|
|
r_broadcast <= 1'b1;
|
101 |
|
|
r_buf[ 4] <= 1'b0;
|
102 |
|
|
r_buf[ 9] <= 1'b0;
|
103 |
|
|
r_buf[14] <= 1'b0;
|
104 |
|
|
r_buf[19] <= 1'b0;
|
105 |
|
|
o_v <= 1'b0;
|
106 |
|
|
o_d <= i_d;
|
107 |
|
|
end else begin
|
108 |
|
|
r_p <= { r_p[28:0], 1'b0 };
|
109 |
|
|
if (i_en)
|
110 |
|
|
begin
|
111 |
|
|
// Skip the first 6 bytes, and everything
|
112 |
|
|
// following if the MAC doesn't match
|
113 |
|
|
o_v <= (!r_p[11])&&(!r_cancel)&&(i_v);
|
114 |
|
|
o_d <= i_d;
|
115 |
|
|
end else begin
|
116 |
|
|
// In this case, we wish to ignore everything,
|
117 |
|
|
// but still duplicate the EtherType words
|
118 |
|
|
if (r_p[27])
|
119 |
|
|
{ o_v, o_d } <= { (i_v)&&(!r_cancel), i_d };
|
120 |
|
|
else
|
121 |
|
|
{ o_v, o_d } <= { (r_buf[19])&&(!r_cancel), r_buf[18:15] };
|
122 |
|
|
end
|
123 |
|
|
end
|
124 |
|
|
|
125 |
|
|
if ((!i_en)&&(r_p[27]))
|
126 |
|
|
begin // Clear out the top half of the EtherType word
|
127 |
|
|
r_buf[18:15] <= 4'h0;
|
128 |
|
|
r_buf[13:10] <= 4'h0;
|
129 |
|
|
end
|
130 |
|
|
end
|
131 |
|
|
|
132 |
|
|
assign o_err = r_err;
|
133 |
|
|
|
134 |
|
|
endmodule
|