source: trunk/modules/vci_ethernet_tsar/caba/source/include/vci_ethernet.h

Last change on this file was 528, checked in by lambert, 11 years ago

Introduicing VciEthernetTsar?
This component is modified version of VciEthernet? from soclib
Main differences are :

  • DMA access avoid overlapinging cache line boundaries
  • Pktid is now 0x4 in write cmd
  • IRQ can be reset with the status register
File size: 3.9 KB
Line 
1/* -*- c++ -*-
2 *
3 * SOCLIB_LGPL_HEADER_BEGIN
4 *
5 * This file is part of SoCLib, GNU LGPLv2.1.
6 *
7 * SoCLib is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU Lesser General Public License as published
9 * by the Free Software Foundation; version 2.1 of the License.
10 *
11 * SoCLib is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with SoCLib; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 * 02110-1301 USA
20 *
21 * SOCLIB_LGPL_HEADER_END
22 *
23 * Copyright (c) Telecom ParisTech
24 *         Alexandre Becoulet <alexandre.becoulet@enst.fr>, 2012
25 *
26 * Maintainers: becoulet
27 *
28 * Maintainers: nipo
29 */
30
31#ifndef SOCLIB_VCI_ETHERNET_H
32#define SOCLIB_VCI_ETHERNET_H
33
34#include <stdint.h>
35#include <systemc>
36
37#include <linux/if_tun.h>
38#include <sys/ioctl.h>
39#include <sys/socket.h>
40#include <net/if.h>
41#include <netinet/in.h>
42
43#include "vci_target_fsm.h"
44#include "vci_initiator_fsm.h"
45#include "caba_base_module.h"
46#include "mapping_table.h"
47
48#define VCI_ETHERNET_FIFO_SIZE 8
49#define VCI_ETHERNET_MAX_PKT_SIZE 1500
50
51namespace soclib {
52namespace caba {
53
54using namespace sc_core;
55
56template<typename vci_param>
57class VciEthernet
58        : public caba::BaseModule
59{
60private:
61    soclib::caba::VciTargetFsm<vci_param, true> m_vci_target_fsm;
62    soclib::caba::VciInitiatorFsm<vci_param> m_vci_init_fsm;
63    typedef typename soclib::caba::VciInitiatorReq<vci_param> req_t;
64
65    bool on_write(int seg, typename vci_param::addr_t addr, typename vci_param::data_t data, int be);
66    bool on_read(int seg, typename vci_param::addr_t addr, typename vci_param::data_t &data);
67    void read_finish( req_t *req );
68    void write_finish( req_t *req );
69    void transition();
70    void genMoore();
71    void cleanup_fifos();
72
73    struct fifo_entry_t
74    {
75        uint32_t addr;
76        uint32_t size;
77        uint32_t status;
78        uint8_t *data;
79        int dma_offset;
80        union {
81            VciInitSimpleReadReq<vci_param> *rd_req;
82            VciInitSimpleWriteReq<vci_param> *wr_req;
83        };
84    };
85
86    int _rx_start;    //< index of first available rx buffer
87    int _rx_free;     //< number of yet unused rx buffers
88    int _rx_done;     //< number of rx buffers ready to pop
89    int _rx_count;    //< total number of rx buffers
90
91    int _tx_start;    //< index of first tx buffer
92    int _tx_waiting;  //< number of yet unprocessed tx buffers
93    int _tx_done;     //< number of tx buffers ready to pop
94    int _tx_count;    //< total number of tx buffers
95
96    int _link_check_counter;
97
98    bool _dma_busy;
99    bool _link_up;
100    bool _link_changed;
101
102    fifo_entry_t _tx_fifo[VCI_ETHERNET_FIFO_SIZE];
103    fifo_entry_t _rx_fifo[VCI_ETHERNET_FIFO_SIZE];
104
105    uint32_t _tx_size; //< next tx buffer size
106    uint32_t _rx_size; //< next rx buffer size
107
108    bool _rx_irq_en;
109    bool _tx_irq_en;
110    bool _link_irq_en;
111    bool _soft_reset;
112
113        int _fd;
114    uint8_t _mac[6];
115
116    struct ifreq _tap_ifr;
117
118        inline void ended(int status);
119
120protected:
121    SC_HAS_PROCESS(VciEthernet);
122
123public:
124    sc_in<bool> p_clk;
125    sc_in<bool> p_resetn;
126    soclib::caba::VciTarget<vci_param> p_vci_target;
127    soclib::caba::VciInitiator<vci_param> p_vci_initiator;
128    sc_out<bool> p_irq;
129
130        VciEthernet(sc_module_name name, const soclib::common::MappingTable &mt,
131                const soclib::common::IntTab &srcid, const soclib::common::IntTab &tgtid,
132                const std::string &if_name = "soclib0");
133
134        ~VciEthernet();
135};
136
137}}
138
139#endif /* SOCLIB_VCI_ETHERNET_H */
140
141// Local Variables:
142// tab-width: 4
143// c-basic-offset: 4
144// c-file-offsets:((innamespace . 0)(inline-open . 0))
145// indent-tabs-mode: nil
146// End:
147
148// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
149
Note: See TracBrowser for help on using the repository browser.