1 #ifndef __INS_ETH_OCM_H__
2 #define __INS_ETH_OCM_H__
4 #include <io.h> //Altera IOWR, IORD macros
5 #include <errno.h> //Error return codes
6 #include "alt_types.h" //Altera variable types
7 #include <sys/alt_cache.h> //For cache bypassing
8 #include <sys/alt_irq.h> //for ISR registering
11 #include "alt_iniche_dev.h" //For alt_iniche_dev struct
12 #include "ether.h" //For ethhdr struct
20 //Opencores MAC includes
22 #include "eth_ocm_regs.h"
23 #include "eth_ocm_desc.h"
25 #include "system.h" //Macro defs for your system
27 //****************************************************************************
28 //************************** Compilation options *****************************
30 // Set debug print statement level.
31 // Level 0 - No debugging)
32 // Level 1 - Harmless debugging (initialization) will not harm performance.
33 // Level 2 - Runtime debugging Transmit errors. High level of
34 // errors may impact performance due to excessive printing.
35 // Level 3 - Runtimine debugging transmit and receive errors. High level of TX
36 // or RX errors may impact performance due to excessive printing.
37 // Level 4 - Low level debugging. Will impact performance.
38 #ifndef ETH_OCM_DBG_LVL
39 #define ETH_OCM_DBG_LVL 0
42 // Define ETH_OCM_SYNC_TX to enable synchronous transmit operations
43 // Whether or not this makes sense depends on your system. With syncronous
44 // transmits, all transmits block until the frame as been transmitted. This
45 // obviously implies a performance hit as nothing else can be done until the
46 // frame has been tranferred.
47 // On the other hand, asynchronous transfers incurr a performance hit
48 // due to increased interrupt activity. Try both to see which gives you higher
50 // #define ETH_OCM_SYNC_TX
52 // Total number of available descriptors
53 #define ETH_OCM_TOTAL_DESC_COUNT 128
55 // Define the number of descriptors used for Transmit
56 #ifndef ETH_OCM_TX_DESC_COUNT
57 #define ETH_OCM_TX_DESC_COUNT 1
58 #endif //ifndef ETH_OCM_TX_DESC_COUNT
60 // Validate Transmit descriptor count
61 #if (ETH_OCM_TX_DESC_COUNT >= ETH_OCM_TOTAL_DESC_COUNT)
62 #error [ins_eth_ocm.h] Defined TX descriptor count not supported
65 // Define the number of descriptors used for Receive
66 #ifndef ETH_OCM_RX_DESC_COUNT
67 #define ETH_OCM_RX_DESC_COUNT 1 //Requires sufficient Iniche Buffers
68 #endif //ifndef ETH_OCM_TX_DESC_COUNT
70 // Validate Receive descriptor count
71 #if (ETH_OCM_RX_DESC_COUNT > (128 - ETH_OCM_TX_DESC_COUNT))
72 #error [ins_eth_ocm.h] Defined RX descriptor count not supported
75 //************************ End Compilation options ***************************
76 //****************************************************************************
77 // Define the size of Buffers the driver will request for RX.
78 #define ETH_OCM_BUF_ALLOC_SIZE 1536
80 // Define the flags that will trigger an interrupt.
81 #ifdef ETH_OCM_TX_SYNC
82 #define ETH_OCM_DEFAULT_INTERRUPT_MASK \
83 (ETH_OCM_INT_MASK_BUSY_MSK | \
84 ETH_OCM_INT_MASK_RXE_MSK | \
85 ETH_OCM_INT_MASK_RXB_MSK )
89 #define ETH_OCM_DEFAULT_INTERRUPT_MASK \
90 (ETH_OCM_INT_MASK_BUSY_MSK | \
91 ETH_OCM_INT_MASK_TXE_MSK | \
92 ETH_OCM_INT_MASK_TXB_MSK | \
93 ETH_OCM_INT_MASK_RXE_MSK | \
94 ETH_OCM_INT_MASK_RXB_MSK )
96 #endif // !defined ETH_OCM_TX_SYNC
99 // Define the number of times to poll the Transmit descriptor to determine if
100 // a synchronous transmit has finished (Not used in regular asynchronous mode)
101 #define ETH_OCM_TRANSMIT_TIMEOUT 1000000
104 * eth_ocm_regs struct is used to enumerate the registers within
105 * the Opencores MAC. It is custom tuned for the number of TX and RX
130 alt_u32 reserved
[235];
131 eth_ocm_desc txdescs
[ETH_OCM_TX_DESC_COUNT
];
132 eth_ocm_desc rxdescs
[ETH_OCM_RX_DESC_COUNT
];
133 } volatile eth_ocm_regs
;
136 * eth_ocm_info contains information needed for runtime operation of the MAC in
137 * conjunction with the InterNiche Stack. It is created and initialized if and
138 * when the InterNiche Stack calls the MAC driver's "prep" function.
141 unsigned char mac_addr
[6]; //MAC address
142 NET netp
; //Pointer to associated interface
143 alt_u8 sem
; //semaphore
144 alt_u8 cur_tx_desc
; //Current TX descriptor (currently transferring)
145 alt_u8 cur_rx_desc
; //Current RX descriptor
146 PACKET
*rx_pkts
; //To be alloced and used as array
147 #ifndef ETH_OCM_SYNC_TX
148 queue tosend
; //Packets to be sent queue
149 queue sending
; //Packets being sent queue
150 alt_u8 next_tx_desc
; //Next TX descriptor (to schedule a transfer)
151 alt_u8 next_tx_desc_rdy
; //Next TX descriptor can be used
156 * eth_ocm_dev contains information aquired at initialization time that is
157 * required for further access to the device. This struct is initialized
158 * by the alt_sys_init routine for each instance of the OpenCores MAC in the
162 alt_iniche_dev ins_dev
;
174 #endif // __cplusplus
176 error_t
eth_ocm_prep(alt_iniche_dev
*ins_dev
);
177 int eth_ocm_init(int iface
);
178 int eth_ocm_close(int iface
);
179 void eth_ocm_stats(void *pio
, int iface
);
183 #endif // __cplusplus
185 //Information that can't be obtained later
186 #define ETH_OCM_INSTANCE(name, dev) \
195 (eth_ocm_regs*)(name##_BASE | 0x80000000), \
201 //Opencores ethernet mac init function
202 #define ETH_OCM_INIT(name, dev_inst) \
203 alt_iniche_dev_reg(&(dev_inst.ins_dev))
205 #endif //__INS_ETH_OCM_H__