OpenCores
URL https://opencores.org/ocsvn/riscv_vhdl/riscv_vhdl/trunk

Subversion Repositories riscv_vhdl

[/] [riscv_vhdl/] [trunk/] [rtl/] [ethlib/] [types_eth.vhd] - Blame information for rev 5

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 5 sergeykhbr
------------------------------------------------------------------------------
2
--  This file is a part of the GRLIB VHDL IP LIBRARY
3
--  Copyright (C) 2003 - 2008, Gaisler Research
4
--  Copyright (C) 2008 - 2014, Aeroflex Gaisler
5
--  Copyright (C) 2015 - 2016, Cobham Gaisler
6
--
7
--  This program is free software; you can redistribute it and/or modify
8
--  it under the terms of the GNU General Public License as published by
9
--  the Free Software Foundation; either version 2 of the License, or
10
--  (at your option) any later version.
11
--
12
--  This program is distributed in the hope that it will be useful,
13
--  but WITHOUT ANY WARRANTY; without even the implied warranty of
14
--  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
--  GNU General Public License for more details.
16
--
17
--  You should have received a copy of the GNU General Public License
18
--  along with this program; if not, write to the Free Software
19
--  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
20
------------------------------------------------------------------------------
21
library ieee;
22
use ieee.std_logic_1164.all;
23
library commonlib;
24
use commonlib.types_common.all;
25
--! AMBA system bus specific library.
26
library ambalib;
27
--! AXI4 configuration constants.
28
use ambalib.types_amba4.all;
29
 
30
package types_eth is
31
  --gigabit sync types
32
  type data_sync_type is array (0 to 3) of std_logic_vector(31 downto 0);
33
  type ctrl_sync_type is array (0 to 3) of std_logic_vector(1 downto 0);
34
 
35
  constant HTRANS_IDLE:   std_logic_vector(1 downto 0) := "00";
36
  constant HTRANS_NONSEQ: std_logic_vector(1 downto 0) := "10";
37
  constant HTRANS_SEQ:    std_logic_vector(1 downto 0) := "11";
38
 
39
  constant HBURST_INCR:   std_logic_vector(2 downto 0) := "001";
40
 
41
  constant HSIZE_WORD:    std_logic_vector(2 downto 0) := "010";
42
 
43
  constant HRESP_OKAY:    std_logic_vector(1 downto 0) := "00";
44
  constant HRESP_ERROR:   std_logic_vector(1 downto 0) := "01";
45
  constant HRESP_RETRY:   std_logic_vector(1 downto 0) := "10";
46
  constant HRESP_SPLIT:   std_logic_vector(1 downto 0) := "11";
47
 
48
  --receiver constants
49
  constant maxsizerx : std_logic_vector(15 downto 0) :=
50
    conv_std_logic_vector(1500, 16);
51
  constant minpload  : std_logic_vector(10 downto 0) :=
52
    conv_std_logic_vector(60, 11);
53
 
54
  type ahb_fifo_in_type is record
55
    renable   : std_ulogic;
56
    raddress  : std_logic_vector(4 downto 0);
57
    write     : std_ulogic;
58
    data      : std_logic_vector(31 downto 0);
59
    waddress  : std_logic_vector(4 downto 0);
60
  end record;
61
 
62
  type ahb_fifo_out_type is record
63
    data      : std_logic_vector(31 downto 0);
64
  end record;
65
 
66
  type nchar_fifo_in_type is record
67
    renable   : std_ulogic;
68
    raddress  : std_logic_vector(5 downto 0);
69
    write     : std_ulogic;
70
    data      : std_logic_vector(8 downto 0);
71
    waddress  : std_logic_vector(5 downto 0);
72
  end record;
73
 
74
  type nchar_fifo_out_type is record
75
    data      : std_logic_vector(8 downto 0);
76
  end record;
77
 
78
  type rmapbuf_in_type is record
79
    renable   : std_ulogic;
80
    raddress  : std_logic_vector(7 downto 0);
81
    write     : std_ulogic;
82
    data      : std_logic_vector(7 downto 0);
83
    waddress  : std_logic_vector(7 downto 0);
84
  end record;
85
 
86
  type rmapbuf_out_type is record
87
    data      : std_logic_vector(7 downto 0);
88
  end record;
89
 
90
  type ahbc_mst_in_type is record
91
    hgrant      : std_ulogic;                           -- bus grant
92
    hready      : std_ulogic;                           -- transfer done
93
    hresp       : std_logic_vector(1 downto 0);  -- response type
94
    hrdata      : std_logic_vector(31 downto 0);         -- read data bus
95
  end record;
96
 
97
  type ahbc_mst_out_type is record
98
    hbusreq     : std_ulogic;                           -- bus request
99
    hlock       : std_ulogic;                           -- lock request
100
    htrans      : std_logic_vector(1 downto 0);  -- transfer type
101
    haddr       : std_logic_vector(31 downto 0);         -- address bus (byte)
102
    hwrite      : std_ulogic;                           -- read/write
103
    hsize       : std_logic_vector(2 downto 0);  -- transfer size
104
    hburst      : std_logic_vector(2 downto 0);  -- burst type
105
    hprot       : std_logic_vector(3 downto 0);  -- protection control
106
    hwdata      : std_logic_vector(31 downto 0);         -- write data bus
107
  end record;
108
 
109
  type apbc_slv_in_type is record
110
    psel        : std_ulogic;                           -- slave select
111
    penable     : std_ulogic;                           -- strobe
112
    paddr       : std_logic_vector(31 downto 0);         -- address bus (byte)
113
    pwrite      : std_ulogic;                           -- write
114
    pwdata      : std_logic_vector(31 downto 0);         -- write data bus
115
  end record;
116
 
117
  type apbc_slv_out_type is record
118
    prdata      : std_logic_vector(31 downto 0);         -- read data bus
119
  end record;
120
 
121
  type eth_tx_ahb_in_type is record
122
    req     : std_ulogic;
123
    write   : std_ulogic;
124
    addr    : std_logic_vector(31 downto 0);
125
    data    : std_logic_vector(31 downto 0);
126
    burst_bytes : std_logic_vector(10 downto 0);
127
  end record;
128
 
129
  type eth_tx_ahb_out_type is record
130
    grant    : std_ulogic;
131
    data     : std_logic_vector(31 downto 0);
132
    ready    : std_ulogic;
133
    error    : std_ulogic;
134
    retry    : std_ulogic;
135
  end record;
136
 
137
  type eth_rx_ahb_in_type is record
138
    req     : std_ulogic;
139
    write   : std_ulogic;
140
    addr    : std_logic_vector(31 downto 0);
141
    data    : std_logic_vector(31 downto 0);
142
    burst_bytes : std_logic_vector(10 downto 0);
143
  end record;
144
 
145
  constant eth_rx_in_none : eth_rx_ahb_in_type := (
146
    '0', '0', (others => '0'), (others => '0'), (others => '0'));
147
 
148
  type eth_rx_ahb_out_type is record
149
    grant   : std_ulogic;
150
    ready   : std_ulogic;
151
    error   : std_ulogic;
152
    retry   : std_ulogic;
153
    data    : std_logic_vector(31 downto 0);
154
  end record;
155
 
156
  type eth_rx_gbit_ahb_in_type is record
157
    req     : std_ulogic;
158
    write   : std_ulogic;
159
    addr    : std_logic_vector(31 downto 0);
160
    data    : std_logic_vector(31 downto 0);
161
    size    : std_logic_vector(1 downto 0);
162
  end record;
163
 
164
  type gbit_host_tx_type is record
165
    full_duplex : std_ulogic;
166
    start       : std_ulogic;
167
    read_ack    : std_ulogic;
168
    data        : std_logic_vector(31 downto 0);
169
    datavalid   : std_ulogic;
170
    valid       : std_ulogic;
171
    len         : std_logic_vector(10 downto 0);
172
    rx_col      : std_ulogic;
173
    rx_crs      : std_ulogic;
174
  end record;
175
 
176
  type gbit_tx_host_type is record
177
    txd          : std_logic_vector(3 downto 0);
178
    tx_en        : std_ulogic;
179
    done         : std_ulogic;
180
    read         : std_ulogic;
181
    restart      : std_ulogic;
182
    status       : std_logic_vector(1 downto 0);
183
  end record;
184
 
185
  type gbit_rx_host_type is record
186
    sync_start   : std_ulogic;
187
    done         : std_ulogic;
188
    write        : std_logic_vector(3 downto 0);
189
    dataout      : data_sync_type;
190
    byte_count   : std_logic_vector(10 downto 0);
191
    status       : std_logic_vector(3 downto 0);
192
    gotframe     : std_ulogic;
193
    mcasthash    : std_logic_vector(5 downto 0);
194
  end record;
195
 
196
  type gbit_host_rx_type is record
197
    full_duplex  : std_ulogic;
198
    gbit         : std_ulogic;
199
    doneack      : std_ulogic;
200
    writeack     : std_logic_vector(3 downto 0);
201
    speed        : std_ulogic;
202
    writeok      : std_logic_vector(3 downto 0);
203
    rxenable     : std_ulogic;
204
    rxd          : std_logic_vector(7 downto 0);
205
    rx_dv        : std_ulogic;
206
    rx_er        : std_ulogic;
207
    rx_col       : std_ulogic;
208
    rx_crs       : std_ulogic;
209
    rx_en        : std_ulogic;
210
  end record;
211
 
212
  type gbit_gtx_host_type is record
213
    txd          : std_logic_vector(7 downto 0);
214
    tx_en        : std_ulogic;
215
    tx_er        : std_ulogic;
216
    done         : std_ulogic;
217
    restart      : std_ulogic;
218
    read         : std_logic_vector(3 downto 0);
219
    status       : std_logic_vector(2 downto 0);
220
  end record;
221
 
222
  type gbit_host_gtx_type is record
223
    rx_col        : std_ulogic;
224
    rx_crs        : std_ulogic;
225
    full_duplex   : std_ulogic;
226
    burstmode     : std_ulogic;
227
    txen          : std_ulogic;
228
    start_sync    : std_ulogic;
229
    readack       : std_logic_vector(3 downto 0);
230
    valid         : std_logic_vector(3 downto 0);
231
    data          : data_sync_type;
232
    len           : std_logic_vector(10 downto 0);
233
  end record;
234
 
235
  type host_tx_type is record
236
    rx_col      : std_ulogic;
237
    rx_crs      : std_ulogic;
238
    full_duplex : std_ulogic;
239
    start       : std_ulogic;
240
    readack     : std_ulogic;
241
    speed       : std_ulogic;
242
    data        : std_logic_vector(31 downto 0);
243
    datavalid   : std_ulogic;
244
    valid       : std_ulogic;
245
    len         : std_logic_vector(10 downto 0);
246
  end record;
247
 
248
  type tx_host_type is record
249
    txd         : std_logic_vector(3 downto 0);
250
    tx_en       : std_ulogic;
251
    tx_er       : std_ulogic;
252
    done        : std_ulogic;
253
    read        : std_ulogic;
254
    restart     : std_ulogic;
255
    status      : std_logic_vector(1 downto 0);
256
  end record;
257
 
258
  type rx_host_type is record
259
    dataout    : std_logic_vector(31 downto 0);
260
    start      : std_ulogic;
261
    done       : std_ulogic;
262
    write      : std_ulogic;
263
    status     : std_logic_vector(3 downto 0);
264
    gotframe   : std_ulogic;
265
    byte_count : std_logic_vector(10 downto 0);
266
    lentype    : std_logic_vector(15 downto 0);
267
    mcasthash  : std_logic_vector(5 downto 0);
268
  end record;
269
 
270
  type host_rx_type is record
271
    writeack : std_ulogic;
272
    doneack  : std_ulogic;
273
    speed    : std_ulogic;
274
    writeok  : std_ulogic;
275
    rxd      : std_logic_vector(3 downto 0);
276
    rx_dv    : std_ulogic;
277
    rx_crs   : std_ulogic;
278
    rx_er    : std_ulogic;
279
    enable   : std_ulogic;
280
    rx_en    : std_ulogic;
281
  end record;
282
 
283
 
284
  component greth_rx is
285
    generic(
286
      nsync          : integer range 1 to 2 := 2;
287
      rmii           : integer range 0 to 1 := 0;
288
      multicast      : integer range 0 to 1 := 0;
289
      maxsize        : integer;
290
      gmiimode       : integer range 0 to 1 := 0
291
      );
292
    port(
293
      rst            : in  std_ulogic;
294
      clk            : in  std_ulogic;
295
      rxi            : in  host_rx_type;
296
      rxo            : out rx_host_type
297
    );
298
  end component;
299
 
300
  component greth_tx is
301
    generic(
302
      ifg_gap        : integer := 24;
303
      attempt_limit  : integer := 16;
304
      backoff_limit  : integer := 10;
305
      nsync          : integer range 1 to 2 := 2;
306
      rmii           : integer range 0 to 1  := 0;
307
      gmiimode       : integer range 0 to 1 := 0
308
      );
309
    port(
310
      rst            : in  std_ulogic;
311
      clk            : in  std_ulogic;
312
      txi            : in  host_tx_type;
313
      txo            : out tx_host_type
314
    );
315
  end component;
316
 
317
  component eth_rstgen is
318
    generic(acthigh : integer := 0);
319
    port (
320
      rstin     : in  std_ulogic;
321
      clk       : in  std_ulogic;
322
      clklock   : in  std_ulogic;
323
      rstout    : out std_ulogic;
324
      rstoutraw : out std_ulogic
325
    );
326
  end component;
327
 
328
  component greth_gbit_tx is
329
    generic(
330
      ifg_gap        : integer := 24;
331
      attempt_limit  : integer := 16;
332
      backoff_limit  : integer := 10;
333
      nsync          : integer range 1 to 2 := 2;
334
      gmiimode       : integer range 0 to 1 := 0
335
      );
336
    port(
337
      rst            : in  std_ulogic;
338
      clk            : in  std_ulogic;
339
      txi            : in  gbit_host_tx_type;
340
      txo            : out gbit_tx_host_type);
341
  end component;
342
 
343
  component greth_gbit_gtx is
344
    generic(
345
      ifg_gap        : integer := 24;
346
      attempt_limit  : integer := 16;
347
      backoff_limit  : integer := 10;
348
      nsync          : integer range 1 to 2 := 2;
349
      iotest         : integer := 0);
350
    port(
351
      rst            : in   std_ulogic;
352
      clk            : in   std_ulogic;
353
      gtxi           : in   gbit_host_gtx_type;
354
      gtxo           : out  gbit_gtx_host_type;
355
      iotmact        : in   std_ulogic;
356
      iotdata        : in   std_logic_vector(9 downto 0)
357
    );
358
  end component;
359
 
360
  component greth_gbit_rx is
361
    generic(
362
      multicast      : integer range 0 to 1 := 0;
363
      nsync          : integer range 1 to 2 := 2;
364
      gmiimode       : integer range 0 to 1 := 0
365
      );
366
    port(
367
      rst            : in  std_ulogic;
368
      clk            : in  std_ulogic;
369
      rxi            : in  gbit_host_rx_type;
370
      rxo            : out gbit_rx_host_type;
371
      iotdata        : out std_logic_vector(9 downto 0));
372
  end component;
373
 
374
  component eth_ahb_mst is
375
    port(
376
      rst     : in  std_ulogic;
377
      clk     : in  std_ulogic;
378
      ahbmi   : in  ahbc_mst_in_type;
379
      ahbmo   : out ahbc_mst_out_type;
380
      tmsti   : in  eth_tx_ahb_in_type;
381
      tmsto   : out eth_tx_ahb_out_type;
382
      rmsti   : in  eth_rx_ahb_in_type;
383
      rmsto   : out eth_rx_ahb_out_type
384
    );
385
  end component;
386
 
387
  component eth_ahb_mst_gbit is
388
    port(
389
      rst         : in  std_ulogic;
390
      clk         : in  std_ulogic;
391
      ahbmi       : in  ahbc_mst_in_type;
392
      ahbmo       : out ahbc_mst_out_type;
393
      tmsti       : in  eth_tx_ahb_in_type;
394
      tmsto       : out eth_tx_ahb_out_type;
395
      rmsti       : in  eth_rx_gbit_ahb_in_type;
396
      rmsto       : out eth_rx_ahb_out_type);
397
  end component;
398
 
399
  component eth_edcl_ahb_mst is
400
  port(
401
    rst         : in  std_ulogic;
402
    clk         : in  std_ulogic;
403
    ahbmi       : in  ahbc_mst_in_type;
404
    ahbmo       : out ahbc_mst_out_type;
405
    tmsti       : in  eth_tx_ahb_in_type;
406
    tmsto       : out eth_tx_ahb_out_type
407
  );
408
  end component;
409
 
410
  component eth_axi_mst is
411
  port(
412
    rst     : in  std_ulogic;
413
    clk     : in  std_ulogic;
414
    aximi   : in  nasti_master_in_type;
415
    aximo   : out nasti_master_out_type;
416
    tmsti   : in  eth_tx_ahb_in_type;
417
    tmsto   : out eth_tx_ahb_out_type;
418
    rmsti   : in  eth_rx_ahb_in_type;
419
    rmsto   : out eth_rx_ahb_out_type
420
  );
421
  end component;
422
 
423
 
424
  function mirror(din : in std_logic_vector) return std_logic_vector;
425
 
426
  function crc32_4(d   : in std_logic_vector(3 downto 0);
427
                   crc : in std_logic_vector(31 downto 0))
428
                         return std_logic_vector;
429
  function crc16_2(d1   : in std_logic_vector(15 downto 0);
430
                   d2   : in std_logic_vector(25 downto 0))
431
                          return std_logic_vector;
432
  function crc16(d1   : in std_logic_vector(15 downto 0);
433
                 d2   : in std_logic_vector(15 downto 0))
434
                        return std_logic_vector;
435
 
436
  function validlen(len   : in std_logic_vector(10 downto 0);
437
                    bcnt  : in std_logic_vector(10 downto 0);
438
                    usesz : in std_ulogic)
439
                            return std_ulogic;
440
 
441
  function getfifosize(edcl, fifosize, ebufsize : in integer) return integer;
442
 
443
  function setburstlength(fifosize : in integer) return integer;
444
 
445
  function calccrc(d   : in std_logic_vector(3 downto 0);
446
                   crc : in std_logic_vector(31 downto 0))
447
                         return std_logic_vector;
448
 
449
  --16-bit one's complement adder
450
  function crcadder(d1   : in std_logic_vector(15 downto 0);
451
                    d2   : in std_logic_vector(17 downto 0))
452
                         return std_logic_vector;
453
 
454
 
455
  -- ETH registers
456
 
457
  type eth_mdio_command_type is record
458
    valid    : std_ulogic;
459
    regadr   : std_logic_vector(4 downto 0);
460
    write    : std_ulogic;
461
    read     : std_ulogic;
462
    data     : std_logic_vector(15 downto 0);
463
  end record;
464
  constant eth_mdio_command_none : eth_mdio_command_type :=  (
465
    '0', (others => '0'), '0', '0', (others => '0')
466
  );
467
 
468
  type eth_mdio_status_type is record
469
    cmd      : eth_mdio_command_type;
470
    busy     : std_ulogic;
471
    linkfail : std_ulogic;
472
  end record;
473
 
474
  type eth_mac_status_type is record
475
    txdsel      : std_logic_vector(9 downto 3);
476
    rxdsel      : std_logic_vector(9 downto 3);
477
    txen        : std_ulogic;
478
    rxen        : std_ulogic;
479
    tx_int      : std_ulogic;
480
    rx_int      : std_ulogic;
481
    tx_err      : std_ulogic;
482
    rx_err      : std_ulogic;
483
    edcltx_idle : std_ulogic;
484
    edclrx_idle : std_ulogic;
485
    txahberr    : std_ulogic;
486
    rxahberr    : std_ulogic;
487
    toosmall    : std_ulogic;
488
    invaddr     : std_ulogic;
489
    phystat     : std_ulogic;
490
    full_duplex : std_ulogic;
491
    speed       : std_ulogic;
492
    reset       : std_ulogic;
493
    mdio        : eth_mdio_status_type;
494
  end record;
495
 
496
  --! Latched values set via external Bus Interface
497
  type eth_control_type is record
498
    tx_irqen    : std_ulogic;
499
    rx_irqen    : std_ulogic;
500
    prom        : std_ulogic;
501
    pstatirqen  : std_ulogic;
502
    mcasten     : std_ulogic;
503
    --! Enable access to the internal FIFOs via system BUS (disabled default)
504
    ramdebugen  : std_ulogic;
505
    --! Disable EDCL access
506
    edcldis     : std_ulogic;
507
    disableduplex : std_ulogic;
508
    --! Physical address.
509
    --! Can be changed in a runtime, but become actual only after system reset.
510
    mdio_phyadr   : std_logic_vector(4 downto 0);
511
 
512
    mac_addr : std_logic_vector(47 downto 0);
513
    --! Tx descriptor
514
    txdesc : std_logic_vector(31 downto 10);
515
    --! Rx descriptor
516
    rxdesc : std_logic_vector(31 downto 10);
517
    --! EDCL IP
518
    edclip : std_logic_vector(31 downto 0);
519
    --! Multicast enabling hash value
520
    hash : std_logic_vector(63 downto 0);
521
    emacaddr : std_logic_vector(47 downto 0);
522
  end record;
523
 
524
  --! @name   DBG access unique IDs to the internal FIFOs blocks.
525
  --! @{
526
  constant DBG_ACCESS_NONE : std_logic_vector(1 downto 0) := "00";
527
  constant DBG_ACCESS_TX_BUFFER : std_logic_vector(1 downto 0) := "01";
528
  constant DBG_ACCESS_RX_BUFFER : std_logic_vector(1 downto 0) := "10";
529
  constant DBG_ACCESS_EDCL_BUFFER : std_logic_vector(1 downto 0) := "11";
530
  --! @}
531
 
532
  --! Bus interface read/write actions transforming into these commands.
533
  type eth_command_type is record
534
    --! Tx/Rx can be enabled externally but they're cleared inside of MAC
535
    --! in a case of disabled Descriptor or in a case of BUS error.
536
    set_txena : std_ulogic;
537
    clr_txena : std_ulogic;
538
    set_rxena : std_ulogic;
539
    clr_rxena : std_ulogic;
540
    --! Set new descriptor index in the array of descriptors table
541
    set_txdsel : std_ulogic;
542
    set_rxdsel : std_ulogic;
543
    txdsel     : std_logic_vector(9 downto 3);
544
    rxdsel     : std_logic_vector(9 downto 3);
545
    --! The following values can be changed during initialization stage.
546
    set_full_duplex : std_ulogic;
547
    clr_full_duplex : std_ulogic;
548
    set_speed       : std_ulogic;
549
    clr_speed       : std_ulogic;
550
    set_reset       : std_ulogic;
551
    clr_reset       : std_ulogic;
552
    --! Clear status bits commands:
553
    clr_status_tx_int      : std_ulogic;
554
    clr_status_rx_int      : std_ulogic;
555
    clr_status_tx_err      : std_ulogic;
556
    clr_status_rx_err      : std_ulogic;
557
    clr_status_txahberr    : std_ulogic;
558
    clr_status_rxahberr    : std_ulogic;
559
    clr_status_toosmall    : std_ulogic;
560
    clr_status_invaddr     : std_ulogic;
561
    clr_status_phystat     : std_ulogic;
562
    --! mdi interface command
563
    mdio_cmd               : eth_mdio_command_type;
564
    --! Request ID values:
565
    dbg_access_id : std_logic_vector(1 downto 0);
566
    dbg_wr_ena : std_logic;
567
    dbg_rd_ena : std_logic;
568
    dbg_addr   : std_logic_vector(13 downto 0);
569
    dbg_wdata  : std_logic_vector(31 downto 0);
570
  end record;
571
 
572
  constant eth_command_none : eth_command_type := (
573
    '0', '0', '0', '0', '0', '0', (others => '0'), (others => '0'),
574
    '0', '0', '0', '0', '0', '0',
575
    '0', '0', '0', '0', '0', '0', '0', '0', '0', eth_mdio_command_none,
576
    DBG_ACCESS_NONE, '0', '0', (others => '0'), (others => '0')
577
  );
578
 
579
  type eth_in_type is record
580
    gtx_clk        : std_ulogic;
581
    rmii_clk       : std_ulogic;
582
    tx_clk         : std_ulogic;
583
    tx_clk_90  : std_ulogic;
584
    rx_clk         : std_ulogic;
585
    tx_dv          : std_ulogic;
586
    rxd            : std_logic_vector(3 downto 0);
587
    rx_dv          : std_ulogic;
588
    rx_er          : std_ulogic;
589
    rx_col         : std_ulogic;
590
    rx_en          : std_ulogic;
591
    rx_crs         : std_ulogic;
592
    mdio_i         : std_ulogic;
593
    mdint          : std_ulogic;
594
    phyrstaddr     : std_logic_vector(4 downto 0);
595
    edcladdr       : std_logic_vector(3 downto 0);
596
    edclsepahb     : std_ulogic;
597
    edcldisable    : std_ulogic;
598
  end record;
599
 
600
  constant eth_in_none : eth_in_type := (
601
    '0', '0', '0', '0', '0', '0', (others => '0'), '0', '0', '0', '0', '0',
602
     '0', '0', (others => '0'), (others => '0'), '0', '0');
603
 
604
 
605
  type eth_out_type is record
606
    reset          : std_ulogic;
607
    txd            : std_logic_vector(3 downto 0);
608
    tx_en          : std_ulogic;
609
    tx_er          : std_ulogic;
610
    tx_clk         : std_ulogic;
611
    mdc            : std_ulogic;
612
    mdio_o         : std_ulogic;
613
    mdio_oe        : std_ulogic;
614
    gbit          : std_ulogic;
615
    speed          : std_ulogic;
616
  end record;
617
 
618
  constant eth_out_none : eth_out_type := (
619
    '0', (others => '0'), '0', '0', '0', '0', '0', '1', '0', '0');
620
 
621
  component grethc64 is
622
  generic(
623
    memtech        : integer := 0;
624
    ifg_gap        : integer := 24;
625
    attempt_limit  : integer := 16;
626
    backoff_limit  : integer := 10;
627
    mdcscaler      : integer range 0 to 255 := 25;
628
    enable_mdio    : integer range 0 to 1 := 0;
629
    fifosize       : integer range 4 to 512 := 8;
630
    nsync          : integer range 1 to 2 := 2;
631
    edcl           : integer range 0 to 3 := 0;
632
    edclbufsz      : integer range 1 to 64 := 1;
633
    macaddrh       : integer := 16#00005E#;
634
    macaddrl       : integer := 16#000000#;
635
    ipaddrh        : integer := 16#c0a8#;
636
    ipaddrl        : integer := 16#0035#;
637
    phyrstadr      : integer range 0 to 32 := 0;
638
    rmii           : integer range 0 to 1  := 0;
639
    oepol          : integer range 0 to 1  := 0;
640
    scanen         : integer range 0 to 1  := 0;
641
    mdint_pol      : integer range 0 to 1  := 0;
642
    enable_mdint   : integer range 0 to 1  := 0;
643
    multicast      : integer range 0 to 1  := 0;
644
    edclsepahbg    : integer range 0 to 1  := 0;
645
    ramdebug       : integer range 0 to 2  := 0;
646
    mdiohold       : integer := 1;
647
    maxsize        : integer := 1500;
648
    gmiimode       : integer range 0 to 1 := 0
649
    );
650
  port(
651
    rst           : in  std_ulogic;
652
    clk           : in  std_ulogic;
653
    ctrli         : in eth_control_type;
654
    cmdi          : in eth_command_type;
655
    statuso       : out eth_mac_status_type;
656
    --! Debug value read from internal buffers suing external bus interface
657
    rdbgdatao     : out  std_logic_vector(31 downto 0);
658
    --irq
659
    irq            : out  std_logic;
660
    --ethernet input signals
661
    rmii_clk       : in   std_ulogic;
662
    tx_clk         : in   std_ulogic;
663
    rx_clk         : in   std_ulogic;
664
    tx_dv          : in   std_ulogic;
665
    rxd            : in   std_logic_vector(3 downto 0);
666
    rx_dv          : in   std_ulogic;
667
    rx_er          : in   std_ulogic;
668
    rx_col         : in   std_ulogic;
669
    rx_en          : in   std_ulogic;
670
    rx_crs         : in   std_ulogic;
671
    mdio_i         : in   std_ulogic;
672
    phyrstaddr     : in   std_logic_vector(4 downto 0);
673
    mdint          : in   std_ulogic;
674
    --ethernet output signals
675
    reset          : out  std_ulogic;
676
    txd            : out  std_logic_vector(3 downto 0);
677
    tx_en          : out  std_ulogic;
678
    tx_er          : out  std_ulogic;
679
    mdc            : out  std_ulogic;
680
    mdio_o         : out  std_ulogic;
681
    mdio_oe        : out  std_ulogic;
682
    --scantest
683
    testrst        : in   std_ulogic;
684
    testen         : in   std_ulogic;
685
    testoen        : in   std_ulogic;
686
    edcladdr       : in   std_logic_vector(3 downto 0) := "0000";
687
    edclsepahb     : in   std_ulogic;
688
    edcldisable    : in   std_ulogic;
689
    speed          : out  std_ulogic;
690
    tmsto          : out eth_tx_ahb_in_type;
691
    tmsti          : in eth_tx_ahb_out_type;
692
    tmsto2         : out eth_tx_ahb_in_type;
693
    tmsti2         : in eth_tx_ahb_out_type;
694
    rmsto          : out eth_rx_ahb_in_type;
695
    rmsti          : in eth_rx_ahb_out_type
696
  );
697
  end component;
698
 
699
  component grethaxi is
700
  generic(
701
    xaddr          : integer := 0;
702
    xmask          : integer := 16#FFFFF#;
703
    xirq           : integer := 0;
704
    memtech        : integer := 0;
705
    ifg_gap        : integer := 24;
706
    attempt_limit  : integer := 16;
707
    backoff_limit  : integer := 10;
708
    slot_time      : integer := 128;
709
    mdcscaler      : integer range 0 to 255 := 25;
710
    enable_mdio    : integer range 0 to 1 := 0;
711
    fifosize       : integer range 4 to 512 := 8;
712
    nsync          : integer range 1 to 2 := 2;
713
    edcl           : integer range 0 to 3 := 0;
714
    edclbufsz      : integer range 1 to 64 := 1;
715
    macaddrh       : integer := 16#00005E#;
716
    macaddrl       : integer := 16#000000#;
717
    ipaddrh        : integer := 16#c0a8#;
718
    ipaddrl        : integer := 16#0035#;
719
    phyrstadr      : integer range 0 to 32 := 0;
720
    rmii           : integer range 0 to 1  := 0;
721
    oepol          : integer range 0 to 1  := 0;
722
    scanen         : integer range 0 to 1  := 0;
723
    ft             : integer range 0 to 2  := 0;
724
    edclft         : integer range 0 to 2  := 0;
725
    mdint_pol      : integer range 0 to 1  := 0;
726
    enable_mdint   : integer range 0 to 1  := 0;
727
    multicast      : integer range 0 to 1  := 0;
728
    edclsepahbg    : integer range 0 to 1  := 0;
729
    ramdebug       : integer range 0 to 2  := 0;
730
    mdiohold       : integer := 1;
731
    maxsize        : integer := 1500;
732
    gmiimode       : integer range 0 to 1 := 0
733
    );
734
  port(
735
    rst            : in  std_ulogic;
736
    clk            : in  std_ulogic;
737
    msti           : in nasti_master_in_type;
738
    msto           : out nasti_master_out_type;
739
    mstcfg         : out nasti_master_config_type;
740
    msto2          : out nasti_master_out_type;
741
    mstcfg2        : out nasti_master_config_type;
742
    slvi           : in nasti_slave_in_type;
743
    slvo           : out nasti_slave_out_type;
744
    slvcfg         : out nasti_slave_config_type;
745
    ethi           : in eth_in_type;
746
    etho           : out eth_out_type;
747
    irq            : out  std_logic
748
  );
749
  end component;
750
 
751
end package;
752
 
753
package body types_eth is
754
 
755
  function mirror(din : in std_logic_vector)
756
                        return std_logic_vector is
757
    variable do : std_logic_vector(din'range);
758
  begin
759
    for i in 0 to din'length-1 loop
760
      do(din'high-i) := din(i+din'low);
761
    end loop;
762
    return do;
763
  end function;
764
 
765
  function crc32_4(d   : in std_logic_vector(3 downto 0);
766
                   crc : in std_logic_vector(31 downto 0))
767
                         return std_logic_vector is
768
    variable ncrc : std_logic_vector(31 downto 0);
769
    variable tc   : std_logic_vector(3 downto 0);
770
  begin
771
    tc(0) := d(0) xor crc(31); tc(1) := d(1) xor crc(30);
772
    tc(2) := d(2) xor crc(29); tc(3) := d(3) xor crc(28);
773
    ncrc(31) := crc(27);
774
    ncrc(30) := crc(26);
775
    ncrc(29) := tc(0) xor crc(25);
776
    ncrc(28) := tc(1) xor crc(24);
777
    ncrc(27) := tc(2) xor crc(23);
778
    ncrc(26) := tc(0) xor tc(3) xor crc(22);
779
    ncrc(25) := tc(0) xor tc(1) xor crc(21);
780
    ncrc(24) := tc(1) xor tc(2) xor crc(20);
781
    ncrc(23) := tc(2) xor tc(3) xor crc(19);
782
    ncrc(22) := tc(3) xor crc(18);
783
    ncrc(21) := crc(17);
784
    ncrc(20) := crc(16);
785
    ncrc(19) := tc(0) xor crc(15);
786
    ncrc(18) := tc(1) xor crc(14);
787
    ncrc(17) := tc(2) xor crc(13);
788
    ncrc(16) := tc(3) xor crc(12);
789
    ncrc(15) := tc(0) xor crc(11);
790
    ncrc(14) := tc(0) xor tc(1) xor crc(10);
791
    ncrc(13) := tc(0) xor tc(1) xor tc(2) xor crc(9);
792
    ncrc(12) := tc(1) xor tc(2) xor tc(3) xor crc(8);
793
    ncrc(11) := tc(0) xor tc(2) xor tc(3) xor crc(7);
794
    ncrc(10) := tc(0) xor tc(1) xor tc(3) xor crc(6);
795
    ncrc(9)  := tc(1) xor tc(2) xor crc(5);
796
    ncrc(8)  := tc(0) xor tc(2) xor tc(3) xor crc(4);
797
    ncrc(7)  := tc(0) xor tc(1) xor tc(3) xor crc(3);
798
    ncrc(6)  := tc(1) xor tc(2) xor crc(2);
799
    ncrc(5)  := tc(0) xor tc(2) xor tc(3) xor crc(1);
800
    ncrc(4)  := tc(0) xor tc(1) xor tc(3) xor crc(0);
801
    ncrc(3)  := tc(0) xor tc(1) xor tc(2);
802
    ncrc(2)  := tc(1) xor tc(2) xor tc(3);
803
    ncrc(1)  := tc(2) xor tc(3);
804
    ncrc(0)  := tc(3);
805
    return ncrc;
806
  end function;
807
 
808
  --16-bit one's complement adder
809
  function crc16(d1   : in std_logic_vector(15 downto 0);
810
                 d2   : in std_logic_vector(15 downto 0))
811
                        return std_logic_vector is
812
    variable vd1  : std_logic_vector(16 downto 0);
813
    variable vd2  : std_logic_vector(16 downto 0);
814
    variable sum  : std_logic_vector(16 downto 0);
815
  begin
816
    vd1 := '0' & d1; vd2 := '0' & d2;
817
    sum := vd1 + vd2;
818
    sum(15 downto 0) := sum(15 downto 0) + sum(16);
819
    return sum(15 downto 0);
820
  end function;
821
 
822
  --16-bit one's complement adder for ip/tcp checksum detection
823
  function crc16_2(d1   : in std_logic_vector(15 downto 0);
824
                   d2   : in std_logic_vector(25 downto 0))
825
                          return std_logic_vector is
826
    variable vd1  : std_logic_vector(25 downto 0);
827
    variable vd2  : std_logic_vector(25 downto 0);
828
    variable sum  : std_logic_vector(25 downto 0);
829
  begin
830
    vd1 := "0000000000" & d1; vd2 := d2;
831
    sum := vd1 + vd2;
832
    return sum;
833
  end function;
834
 
835
  function validlen(len   : in std_logic_vector(10 downto 0);
836
                    bcnt  : in std_logic_vector(10 downto 0);
837
                    usesz : in std_ulogic)
838
                            return std_ulogic is
839
    variable valid : std_ulogic;
840
  begin
841
    valid := '1';
842
    if usesz = '1' then
843
      if len > minpload then
844
        if bcnt /= len then
845
          valid := '0';
846
        end if;
847
      else
848
        if bcnt /= minpload then
849
          valid := '0';
850
        end if;
851
      end if;
852
    end if;
853
    return valid;
854
  end function;
855
 
856
  function setburstlength(fifosize : in integer) return integer is
857
  begin
858
    if fifosize <= 64 then
859
      return fifosize/2;
860
    else
861
      return 32;
862
    end if;
863
  end function;
864
 
865
  function getfifosize(edcl, fifosize, ebufsize : in integer) return integer is
866
  begin
867
    if (edcl /= 0) and (ebufsize > fifosize) then
868
      return ebufsize;
869
    else
870
      return fifosize;
871
    end if;
872
  end function;
873
 
874
  function calccrc(d   : in std_logic_vector(3 downto 0);
875
                   crc : in std_logic_vector(31 downto 0))
876
                         return std_logic_vector is
877
    variable ncrc : std_logic_vector(31 downto 0);
878
    variable tc   : std_logic_vector(3 downto 0);
879
  begin
880
    tc(0) := d(0) xor crc(31); tc(1) := d(1) xor crc(30);
881
    tc(2) := d(2) xor crc(29); tc(3) := d(3) xor crc(28);
882
    ncrc(31) := crc(27);
883
    ncrc(30) := crc(26);
884
    ncrc(29) := tc(0) xor crc(25);
885
    ncrc(28) := tc(1) xor crc(24);
886
    ncrc(27) := tc(2) xor crc(23);
887
    ncrc(26) := tc(0) xor tc(3) xor crc(22);
888
    ncrc(25) := tc(0) xor tc(1) xor crc(21);
889
    ncrc(24) := tc(1) xor tc(2) xor crc(20);
890
    ncrc(23) := tc(2) xor tc(3) xor crc(19);
891
    ncrc(22) := tc(3) xor crc(18);
892
    ncrc(21) := crc(17);
893
    ncrc(20) := crc(16);
894
    ncrc(19) := tc(0) xor crc(15);
895
    ncrc(18) := tc(1) xor crc(14);
896
    ncrc(17) := tc(2) xor crc(13);
897
    ncrc(16) := tc(3) xor crc(12);
898
    ncrc(15) := tc(0) xor crc(11);
899
    ncrc(14) := tc(0) xor tc(1) xor crc(10);
900
    ncrc(13) := tc(0) xor tc(1) xor tc(2) xor crc(9);
901
    ncrc(12) := tc(1) xor tc(2) xor tc(3) xor crc(8);
902
    ncrc(11) := tc(0) xor tc(2) xor tc(3) xor crc(7);
903
    ncrc(10) := tc(0) xor tc(1) xor tc(3) xor crc(6);
904
    ncrc(9)  := tc(1) xor tc(2) xor crc(5);
905
    ncrc(8)  := tc(0) xor tc(2) xor tc(3) xor crc(4);
906
    ncrc(7)  := tc(0) xor tc(1) xor tc(3) xor crc(3);
907
    ncrc(6)  := tc(1) xor tc(2) xor crc(2);
908
    ncrc(5)  := tc(0) xor tc(2) xor tc(3) xor crc(1);
909
    ncrc(4)  := tc(0) xor tc(1) xor tc(3) xor crc(0);
910
    ncrc(3)  := tc(0) xor tc(1) xor tc(2);
911
    ncrc(2)  := tc(1) xor tc(2) xor tc(3);
912
    ncrc(1)  := tc(2) xor tc(3);
913
    ncrc(0)  := tc(3);
914
    return ncrc;
915
  end function;
916
 
917
 
918
  --function calccrc_8(data : in std_logic_vector( 7 downto 0);
919
  --                   crc  : in std_logic_vector(31 downto 0))
920
  --                         return std_logic_vector is
921
  --  variable ncrc : std_logic_vector(31 downto 0);
922
  --  variable d    : std_logic_vector(7 downto 0);
923
  --begin
924
  --  d(7) := data(0); d(6) := data(1); d(5) := data(2); d(4) := data(3);
925
  --  d(3) := data(4); d(2) := data(5); d(1) := data(6); d(0) := data(7);
926
  --  ncrc(0) := d(6) xor d(0) xor crc(24) xor crc(30);
927
  --  ncrc(1) := d(7) xor d(6) xor d(1) xor d(0) xor crc(24) xor crc(25) xor crc(30) xor crc(31);
928
  --  ncrc(2) := d(7) xor d(6) xor d(2) xor d(1) xor d(0) xor crc(24) xor crc(25) xor crc(26) xor crc(30) xor crc(31);
929
  --  ncrc(3) := d(7) xor d(3) xor d(2) xor d(1) xor crc(25) xor crc(26) xor crc(27) xor crc(31);
930
  --  ncrc(4) := d(6) xor d(4) xor d(3) xor d(2) xor d(0) xor crc(24) xor crc(26) xor crc(27) xor crc(28) xor crc(30);
931
  --  ncrc(5) := d(7) xor d(6) xor d(5) xor d(4) xor d(3) xor d(1) xor d(0) xor crc(24) xor crc(25) xor crc(27) xor crc(28) xor crc(29) xor crc(30) xor crc(31);
932
  --  ncrc(6) := d(7) xor d(6) xor d(5) xor d(4) xor d(2) xor d(1) xor crc(25) xor crc(26) xor crc(28) xor crc(29) xor crc(30) xor crc(31);
933
  --  ncrc(7) := d(7) xor d(5) xor d(3) xor d(2) xor d(0) xor crc(24) xor crc(26) xor crc(27) xor crc(29) xor crc(31);
934
  --  ncrc(8) := d(4) xor d(3) xor d(1) xor d(0) xor crc(0) xor crc(24) xor crc(25) xor crc(27) xor crc(28);
935
  --  ncrc(9) := d(5) xor d(4) xor d(2) xor d(1) xor crc(1) xor crc(25) xor crc(26) xor crc(28) xor crc(29);
936
  --  ncrc(10) := d(5) xor d(3) xor d(2) xor d(0) xor crc(2) xor crc(24) xor crc(26) xor crc(27) xor crc(29);
937
  --  ncrc(11) := d(4) xor d(3) xor d(1) xor d(0) xor crc(3) xor crc(24) xor crc(25) xor crc(27) xor crc(28);
938
  --  ncrc(12) := d(6) xor d(5) xor d(4) xor d(2) xor d(1) xor d(0) xor crc(4) xor crc(24) xor crc(25) xor crc(26) xor crc(28) xor crc(29) xor crc(30);
939
  --  ncrc(13) := d(7) xor d(6) xor d(5) xor d(3) xor d(2) xor d(1) xor crc(5) xor crc(25) xor crc(26) xor crc(27) xor crc(29) xor crc(30) xor crc(31);
940
  --  ncrc(14) := d(7) xor d(6) xor d(4) xor d(3) xor d(2) xor crc(6) xor crc(26) xor crc(27) xor crc(28) xor crc(30) xor crc(31);
941
  --  ncrc(15) := d(7) xor d(5) xor d(4) xor d(3) xor crc(7) xor crc(27) xor crc(28) xor crc(29) xor crc(31);
942
  --  ncrc(16) := d(5) xor d(4) xor d(0) xor crc(8) xor crc(24) xor crc(28) xor crc(29);
943
  --  ncrc(17) := d(6) xor d(5) xor d(1) xor crc(9) xor crc(25) xor crc(29) xor crc(30);
944
  --  ncrc(18) := d(7) xor d(6) xor d(2) xor crc(10) xor crc(26) xor crc(30) xor crc(31);
945
  --  ncrc(19) := d(7) xor d(3) xor crc(11) xor crc(27) xor crc(31);
946
  --  ncrc(20) := d(4) xor crc(12) xor crc(28);
947
  --  ncrc(21) := d(5) xor crc(13) xor crc(29);
948
  --  ncrc(22) := d(0) xor crc(14) xor crc(24);
949
  --  ncrc(23) := d(6) xor d(1) xor d(0) xor crc(15) xor crc(24) xor crc(25) xor crc(30);
950
  --  ncrc(24) := d(7) xor d(2) xor d(1) xor crc(16) xor crc(25) xor crc(26) xor crc(31);
951
  --  ncrc(25) := d(3) xor d(2) xor crc(17) xor crc(26) xor crc(27);
952
  --  ncrc(26) := d(6) xor d(4) xor d(3) xor d(0) xor crc(18) xor crc(24) xor crc(27) xor crc(28) xor crc(30);
953
  --  ncrc(27) := d(7) xor d(5) xor d(4) xor d(1) xor crc(19) xor crc(25) xor crc(28) xor crc(29) xor crc(31);
954
  --  ncrc(28) := d(6) xor d(5) xor d(2) xor crc(20) xor crc(26) xor crc(29) xor crc(30);
955
  --  ncrc(29) := d(7) xor d(6) xor d(3) xor crc(21) xor crc(27) xor crc(30) xor crc(31);
956
  --  ncrc(30) := d(7) xor d(4) xor crc(22) xor crc(28) xor crc(31);
957
  --  ncrc(31) := d(5) xor crc(23) xor crc(29);
958
  --  return ncrc;
959
  --end function;
960
 
961
  --16-bit one's complement adder
962
  function crcadder(d1   : in std_logic_vector(15 downto 0);
963
                    d2   : in std_logic_vector(17 downto 0))
964
                         return std_logic_vector is
965
    variable vd1  : std_logic_vector(17 downto 0);
966
    variable vd2  : std_logic_vector(17 downto 0);
967
    variable sum  : std_logic_vector(17 downto 0);
968
  begin
969
    vd1 := "00" & d1; vd2 := d2;
970
    sum := vd1 + vd2;
971
    return sum;
972
  end function;
973
 
974
end package body;
975
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.