]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_A53_64-bit_UltraScale_MPSoC/RTOSDemo_A53_bsp/psu_cortexa53_0/libsrc/emacps_v3_2/src/xemacps.h
Update the Xilinx UltraScale+ 64-bit demo to use the hardware definition and BSP...
[freertos] / FreeRTOS / Demo / CORTEX_A53_64-bit_UltraScale_MPSoC / RTOSDemo_A53_bsp / psu_cortexa53_0 / libsrc / emacps_v3_2 / src / xemacps.h
1 /******************************************************************************
2 *
3 * Copyright (C) 2010 - 2016 Xilinx, Inc.  All rights reserved.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a copy
6 * of this software and associated documentation files (the "Software"), to deal
7 * in the Software without restriction, including without limitation the rights
8 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 * copies of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
14 *
15 * Use of the Software is limited solely to applications:
16 * (a) running on a Xilinx device, or
17 * (b) that interact with a Xilinx device through a bus or interconnect.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * XILINX  BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
23 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
24 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 * SOFTWARE.
26 *
27 * Except as contained in this notice, the name of the Xilinx shall not be used
28 * in advertising or otherwise to promote the sale, use or other dealings in
29 * this Software without prior written authorization from Xilinx.
30 *
31 ******************************************************************************/
32 /****************************************************************************/
33 /**
34  *
35  * @file xemacps.h
36 * @addtogroup emacps_v3_1
37 * @{
38 * @details
39  *
40  * The Xilinx Embedded Processor Block Ethernet driver.
41  *
42  * For a full description of XEMACPS features, please see the hardware spec.
43  * This driver supports the following features:
44  *   - Memory mapped access to host interface registers
45  *   - Statistics counter registers for RMON/MIB
46  *   - API for interrupt driven frame transfers for hardware configured DMA
47  *   - Virtual memory support
48  *   - Unicast, broadcast, and multicast receive address filtering
49  *   - Full and half duplex operation
50  *   - Automatic PAD & FCS insertion and stripping
51  *   - Flow control
52  *   - Support up to four 48bit addresses
53  *   - Address checking for four specific 48bit addresses
54  *   - VLAN frame support
55  *   - Pause frame support
56  *   - Large frame support up to 1536 bytes
57  *   - Checksum offload
58  *
59  * <b>Driver Description</b>
60  *
61  * The device driver enables higher layer software (e.g., an application) to
62  * communicate to the XEmacPs. The driver handles transmission and reception
63  * of Ethernet frames, as well as configuration and control. No pre or post
64  * processing of frame data is performed. The driver does not validate the
65  * contents of an incoming frame in addition to what has already occurred in
66  * hardware.
67  * A single device driver can support multiple devices even when those devices
68  * have significantly different configurations.
69  *
70  * <b>Initialization & Configuration</b>
71  *
72  * The XEmacPs_Config structure is used by the driver to configure itself.
73  * This configuration structure is typically created by the tool-chain based
74  * on hardware build properties.
75  *
76  * The driver instance can be initialized in
77  *
78  *   - XEmacPs_CfgInitialize(InstancePtr, CfgPtr, EffectiveAddress):  Uses a
79  *     configuration structure provided by the caller. If running in a system
80  *     with address translation, the provided virtual memory base address
81  *     replaces the physical address present in the configuration structure.
82  *
83  * The device supports DMA only as current development plan. No FIFO mode is
84  * supported. The driver expects to start the DMA channels and expects that
85  * the user has set up the buffer descriptor lists.
86  *
87  * <b>Interrupts and Asynchronous Callbacks</b>
88  *
89  * The driver has no dependencies on the interrupt controller. When an
90  * interrupt occurs, the handler will perform a small amount of
91  * housekeeping work, determine the source of the interrupt, and call the
92  * appropriate callback function. All callbacks are registered by the user
93  * level application.
94  *
95  * <b>Virtual Memory</b>
96  *
97  * All virtual to physical memory mappings must occur prior to accessing the
98  * driver API.
99  *
100  * For DMA transactions, user buffers supplied to the driver must be in terms
101  * of their physical address.
102  *
103  * <b>DMA</b>
104  *
105  * The DMA engine uses buffer descriptors (BDs) to describe Ethernet frames.
106  * These BDs are typically chained together into a list the hardware follows
107  * when transferring data in and out of the packet buffers. Each BD describes
108  * a memory region containing either a full or partial Ethernet packet.
109  *
110  * Interrupt coalescing is not suppoted from this built-in DMA engine.
111  *
112  * This API requires the user to understand how the DMA operates. The
113  * following paragraphs provide some explanation, but the user is encouraged
114  * to read documentation in xemacps_bdring.h as well as study example code
115  * that accompanies this driver.
116  *
117  * The API is designed to get BDs to and from the DMA engine in the most
118  * efficient means possible. The first step is to establish a  memory region
119  * to contain all BDs for a specific channel. This is done with
120  * XEmacPs_BdRingCreate(). This function sets up a BD ring that hardware will
121  * follow as BDs are processed. The ring will consist of a user defined number
122  * of BDs which will all be partially initialized. For example on the transmit
123  * channel, the driver will initialize all BDs' so that they are configured
124  * for transmit. The more fields that can be permanently setup at
125  * initialization, then the fewer accesses will be needed to each BD while
126  * the DMA engine is in operation resulting in better throughput and CPU
127  * utilization. The best case initialization would require the user to set
128  * only a frame buffer address and length prior to submitting the BD to the
129  * engine.
130  *
131  * BDs move through the engine with the help of functions
132  * XEmacPs_BdRingAlloc(), XEmacPs_BdRingToHw(), XEmacPs_BdRingFromHw(),
133  * and XEmacPs_BdRingFree().
134  * All these functions handle BDs that are in place. That is, there are no
135  * copies of BDs kept anywhere and any BD the user interacts with is an actual
136  * BD from the same ring hardware accesses.
137  *
138  * BDs in the ring go through a series of states as follows:
139  *   1. Idle. The driver controls BDs in this state.
140  *   2. The user has data to transfer. XEmacPs_BdRingAlloc() is called to
141  *      reserve BD(s). Once allocated, the user may setup the BD(s) with
142  *      frame buffer address, length, and other attributes. The user controls
143  *      BDs in this state.
144  *   3. The user submits BDs to the DMA engine with XEmacPs_BdRingToHw. BDs
145  *      in this state are either waiting to be processed by hardware, are in
146  *      process, or have been processed. The DMA engine controls BDs in this
147  *      state.
148  *   4. Processed BDs are retrieved with XEmacEpv_BdRingFromHw() by the
149  *      user. Once retrieved, the user can examine each BD for the outcome of
150  *      the DMA transfer. The user controls BDs in this state. After examining
151  *      the BDs the user calls XEmacPs_BdRingFree() which places the BDs back
152  *      into state 1.
153  *
154  * Each of the four BD accessor functions operate on a set of BDs. A set is
155  * defined as a segment of the BD ring consisting of one or more BDs. The user
156  * views the set as a pointer to the first BD along with the number of BDs for
157  * that set. The set can be navigated by using macros XEmacPs_BdNext(). The
158  * user must exercise extreme caution when changing BDs in a set as there is
159  * nothing to prevent doing a mBdNext past the end of the set and modifying a
160  * BD out of bounds.
161  *
162  * XEmacPs_BdRingAlloc() + XEmacPs_BdRingToHw(), as well as
163  * XEmacPs_BdRingFromHw() + XEmacPs_BdRingFree() are designed to be used in
164  * tandem. The same BD set retrieved with BdRingAlloc should be the same one
165  * provided to hardware with BdRingToHw. Same goes with BdRingFromHw and
166  * BdRIngFree.
167  *
168  * <b>Alignment & Data Cache Restrictions</b>
169  *
170  * Due to the design of the hardware, all RX buffers, BDs need to be 4-byte
171  * aligned. Please reference xemacps_bd.h for cache related macros.
172  *
173  * DMA Tx:
174  *
175  *   - If frame buffers exist in cached memory, then they must be flushed
176  *     prior to committing them to hardware.
177  *
178  * DMA Rx:
179  *
180  *   - If frame buffers exist in cached memory, then the cache must be
181  *     invalidated for the memory region containing the frame prior to data
182  *     access
183  *
184  * Both cache invalidate/flush are taken care of in driver code.
185  *
186  * <b>Buffer Copying</b>
187  *
188  * The driver is designed for a zero-copy buffer scheme. That is, the driver
189  * will not copy buffers. This avoids potential throughput bottlenecks within
190  * the driver. If byte copying is required, then the transfer will take longer
191  * to complete.
192  *
193  * <b>Checksum Offloading</b>
194  *
195  * The Embedded Processor Block Ethernet can be configured to perform IP, TCP
196  * and UDP checksum offloading in both receive and transmit directions.
197  *
198  * IP packets contain a 16-bit checksum field, which is the 16-bit 1s
199  * complement of the 1s complement sum of all 16-bit words in the header.
200  * TCP and UDP packets contain a 16-bit checksum field, which is the 16-bit
201  * 1s complement of the 1s complement sum of all 16-bit words in the header,
202  * the data and a conceptual pseudo header.
203  *
204  * To calculate these checksums in software requires each byte of the packet
205  * to be read. For TCP and UDP this can use a large amount of processing power.
206  * Offloading the checksum calculation to hardware can result in significant
207  * performance improvements.
208  *
209  * The transmit checksum offload is only available to use DMA in packet buffer
210  * mode. This is because the complete frame to be transmitted must be read
211  * into the packet buffer memory before the checksum can be calculated and
212  * written to the header at the beginning of the frame.
213  *
214  * For IP, TCP or UDP receive checksum offload to be useful, the operating
215  * system containing the protocol stack must be aware that this offload is
216  * available so that it can make use of the fact that the hardware has verified
217  * the checksum.
218  *
219  * When receive checksum offloading is enabled in the hardware, the IP header
220  * checksum is checked, where the packet meets the following criteria:
221  *
222  * 1. If present, the VLAN header must be four octets long and the CFI bit
223  *    must not be set.
224  * 2. Encapsulation must be RFC 894 Ethernet Type Encoding or RFC 1042 SNAP
225  *    encoding.
226  * 3. IP v4 packet.
227  * 4. IP header is of a valid length.
228  * 5. Good IP header checksum.
229  * 6. No IP fragmentation.
230  * 7. TCP or UDP packet.
231  *
232  * When an IP, TCP or UDP frame is received, the receive buffer descriptor
233  * gives an indication if the hardware was able to verify the checksums.
234  * There is also an indication if the frame had SNAP encapsulation. These
235  * indication bits will replace the type ID match indication bits when the
236  * receive checksum offload is enabled.
237  *
238  * If any of the checksums are verified incorrect by the hardware, the packet
239  * is discarded and the appropriate statistics counter incremented.
240  *
241  * <b>PHY Interfaces</b>
242  *
243  * RGMII 1.3 is the only interface supported.
244  *
245  * <b>Asserts</b>
246  *
247  * Asserts are used within all Xilinx drivers to enforce constraints on
248  * parameters. Asserts can be turned off on a system-wide basis by defining,
249  * at compile time, the NDEBUG identifier. By default, asserts are turned on
250  * and it is recommended that users leave asserts on during development. For
251  * deployment use -DNDEBUG compiler switch to remove assert code.
252  *
253  * @note
254  *
255  * Xilinx drivers are typically composed of two parts, one is the driver
256  * and the other is the adapter.  The driver is independent of OS and processor
257  * and is intended to be highly portable.  The adapter is OS-specific and
258  * facilitates communication between the driver and an OS.
259  * This driver is intended to be RTOS and processor independent. Any needs for
260  * dynamic memory management, threads or thread mutual exclusion, or cache
261  * control must be satisfied bythe layer above this driver.
262  *
263  * <pre>
264  * MODIFICATION HISTORY:
265  *
266  * Ver   Who  Date     Changes
267  * ----- ---- -------- -------------------------------------------------------
268  * 1.00a wsy  01/10/10 First release
269  * 1.00a asa  11/21/11 The function XEmacPs_BdRingFromHwTx in file
270  *                     xemacps_bdring.c is modified. Earlier it was checking for
271  *                     "BdLimit"(passed argument) number of BDs for finding out
272  *                     which BDs are successfully processed. Now one more check
273  *                     is added. It looks for BDs till the current BD pointer
274  *                     reaches HwTail. By doing this processing time is saved.
275  * 1.00a asa  01/24/12 The function XEmacPs_BdRingFromHwTx in file
276  *                     xemacps_bdring.c is modified. Now start of packet is
277  *                     searched for returning the number of BDs processed.
278  * 1.02a asa  11/05/12 Added a new API for deleting an entry from the HASH
279  *                     registers. Added a new API to set the bust length.
280  *                     Added some new hash-defines.
281  * 1.03a asa  01/23/12 Fix for CR #692702 which updates error handling for
282  *                     Rx errors. Under heavy Rx traffic, there will be a large
283  *                     number of errors related to receive buffer not available.
284  *                     Because of a HW bug (SI #692601), under such heavy errors,
285  *                     the Rx data path can become unresponsive. To reduce the
286  *                     probabilities for hitting this HW bug, the SW writes to
287  *                     bit 18 to flush a packet from Rx DPRAM immediately. The
288  *                     changes for it are done in the function
289  *                     XEmacPs_IntrHandler.
290  * 1.05a asa  09/23/13 Cache operations on BDs are not required and hence
291  *                     removed. It is expected that all BDs are allocated in
292  *                     from uncached area.
293  * 1.06a asa  11/02/13 Changed the value for XEMACPS_RXBUF_LEN_MASK from 0x3fff
294  *                              to 0x1fff. This fixes the CR#744902.
295  *                        Made changes in example file xemacps_example.h to fix compilation
296  *                        issues with iarcc compiler.
297  * 2.0   adk  10/12/13 Updated as per the New Tcl API's
298  * 2.1   adk  11/08/14 Fixed the CR#811288. Changes are made in the driver tcl file.
299  * 2.1   bss  09/08/14 Modified driver tcl to fix CR#820349 to export phy
300  *                     address in xparameters.h when GMII to RGMII converter
301  *                     is present in hw.
302  * 2.1   srt  07/15/14 Add support for Zynq Ultrascale Mp GEM specification and 64-bit
303  *                     changes.
304  * 2.2   adk  29/10/14 Fixed CR#827686 when PCS/PMA core is configured with
305  *                    1000BASE-X mode export proper values to the xparameters.h
306  *                    file. Changes are made in the driver tcl file.
307  * 3.0   adk  08/1/15  Don't include gem in peripheral test when gem is
308  *                    configured with PCS/PMA Core. Changes are made in the
309  *                     test app tcl(CR:827686).
310  * 3.0   kvn  02/13/15 Modified code for MISRA-C:2012 compliance.
311  * 3.0   hk   03/18/15 Added support for jumbo frames. Increase AHB burst.
312  *                     Disable extended mode. Perform all 64 bit changes under
313  *                     check for arch64.
314  *                     Remove "used bit set" from TX error interrupt masks.
315  * 3.1   hk   07/27/15 Do not call error handler with '0' error code when
316  *                     there is no error. CR# 869403
317  *            08/10/15 Update upper 32 bit tx and rx queue ptr registers.
318  * 3.2   hk   02/22/16 Added SGMII support for Zynq Ultrascale+ MPSoC.
319  * </pre>
320  *
321  ****************************************************************************/
322
323 #ifndef XEMACPS_H               /* prevent circular inclusions */
324 #define XEMACPS_H               /* by using protection macros */
325
326 #ifdef __cplusplus
327 extern "C" {
328 #endif
329
330 /***************************** Include Files ********************************/
331
332 #include "xil_types.h"
333 #include "xil_assert.h"
334 #include "xstatus.h"
335 #include "xemacps_hw.h"
336 #include "xemacps_bd.h"
337 #include "xemacps_bdring.h"
338
339 /************************** Constant Definitions ****************************/
340
341 /*
342  * Device information
343  */
344 #define XEMACPS_DEVICE_NAME     "xemacps"
345 #define XEMACPS_DEVICE_DESC     "Xilinx PS 10/100/1000 MAC"
346
347
348 /** @name Configuration options
349  *
350  * Device configuration options. See the XEmacPs_SetOptions(),
351  * XEmacPs_ClearOptions() and XEmacPs_GetOptions() for information on how to
352  * use options.
353  *
354  * The default state of the options are noted and are what the device and
355  * driver will be set to after calling XEmacPs_Reset() or
356  * XEmacPs_Initialize().
357  *
358  * @{
359  */
360
361 #define XEMACPS_PROMISC_OPTION               0x00000001U
362 /**< Accept all incoming packets.
363  *   This option defaults to disabled (cleared) */
364
365 #define XEMACPS_FRAME1536_OPTION             0x00000002U
366 /**< Frame larger than 1516 support for Tx & Rx.
367  *   This option defaults to disabled (cleared) */
368
369 #define XEMACPS_VLAN_OPTION                  0x00000004U
370 /**< VLAN Rx & Tx frame support.
371  *   This option defaults to disabled (cleared) */
372
373 #define XEMACPS_FLOW_CONTROL_OPTION          0x00000010U
374 /**< Enable recognition of flow control frames on Rx
375  *   This option defaults to enabled (set) */
376
377 #define XEMACPS_FCS_STRIP_OPTION             0x00000020U
378 /**< Strip FCS and PAD from incoming frames. Note: PAD from VLAN frames is not
379  *   stripped.
380  *   This option defaults to enabled (set) */
381
382 #define XEMACPS_FCS_INSERT_OPTION            0x00000040U
383 /**< Generate FCS field and add PAD automatically for outgoing frames.
384  *   This option defaults to disabled (cleared) */
385
386 #define XEMACPS_LENTYPE_ERR_OPTION           0x00000080U
387 /**< Enable Length/Type error checking for incoming frames. When this option is
388  *   set, the MAC will filter frames that have a mismatched type/length field
389  *   and if XEMACPS_REPORT_RXERR_OPTION is set, the user is notified when these
390  *   types of frames are encountered. When this option is cleared, the MAC will
391  *   allow these types of frames to be received.
392  *
393  *   This option defaults to disabled (cleared) */
394
395 #define XEMACPS_TRANSMITTER_ENABLE_OPTION    0x00000100U
396 /**< Enable the transmitter.
397  *   This option defaults to enabled (set) */
398
399 #define XEMACPS_RECEIVER_ENABLE_OPTION       0x00000200U
400 /**< Enable the receiver
401  *   This option defaults to enabled (set) */
402
403 #define XEMACPS_BROADCAST_OPTION             0x00000400U
404 /**< Allow reception of the broadcast address
405  *   This option defaults to enabled (set) */
406
407 #define XEMACPS_MULTICAST_OPTION             0x00000800U
408 /**< Allows reception of multicast addresses programmed into hash
409  *   This option defaults to disabled (clear) */
410
411 #define XEMACPS_RX_CHKSUM_ENABLE_OPTION      0x00001000U
412 /**< Enable the RX checksum offload
413  *   This option defaults to enabled (set) */
414
415 #define XEMACPS_TX_CHKSUM_ENABLE_OPTION      0x00002000U
416 /**< Enable the TX checksum offload
417  *   This option defaults to enabled (set) */
418
419 #define XEMACPS_JUMBO_ENABLE_OPTION     0x00004000U
420 #define XEMACPS_SGMII_ENABLE_OPTION     0x00008000U
421
422 #define XEMACPS_DEFAULT_OPTIONS                     \
423     ((u32)XEMACPS_FLOW_CONTROL_OPTION |                  \
424      (u32)XEMACPS_FCS_INSERT_OPTION |                    \
425      (u32)XEMACPS_FCS_STRIP_OPTION |                     \
426      (u32)XEMACPS_BROADCAST_OPTION |                     \
427      (u32)XEMACPS_LENTYPE_ERR_OPTION |                   \
428      (u32)XEMACPS_TRANSMITTER_ENABLE_OPTION |            \
429      (u32)XEMACPS_RECEIVER_ENABLE_OPTION |               \
430      (u32)XEMACPS_RX_CHKSUM_ENABLE_OPTION |              \
431      (u32)XEMACPS_TX_CHKSUM_ENABLE_OPTION)
432
433 /**< Default options set when device is initialized or reset */
434 /*@}*/
435
436 /** @name Callback identifiers
437  *
438  * These constants are used as parameters to XEmacPs_SetHandler()
439  * @{
440  */
441 #define XEMACPS_HANDLER_DMASEND 1U
442 #define XEMACPS_HANDLER_DMARECV 2U
443 #define XEMACPS_HANDLER_ERROR   3U
444 /*@}*/
445
446 /* Constants to determine the configuration of the hardware device. They are
447  * used to allow the driver to verify it can operate with the hardware.
448  */
449 #define XEMACPS_MDIO_DIV_DFT    MDC_DIV_32 /**< Default MDIO clock divisor */
450
451 /* The next few constants help upper layers determine the size of memory
452  * pools used for Ethernet buffers and descriptor lists.
453  */
454 #define XEMACPS_MAC_ADDR_SIZE   6U      /* size of Ethernet header */
455
456 #define XEMACPS_MTU             1500U   /* max MTU size of Ethernet frame */
457 #define XEMACPS_MTU_JUMBO       10240U  /* max MTU size of jumbo frame */
458 #define XEMACPS_HDR_SIZE        14U     /* size of Ethernet header */
459 #define XEMACPS_HDR_VLAN_SIZE   18U     /* size of Ethernet header with VLAN */
460 #define XEMACPS_TRL_SIZE        4U      /* size of Ethernet trailer (FCS) */
461 #define XEMACPS_MAX_FRAME_SIZE       (XEMACPS_MTU + XEMACPS_HDR_SIZE + \
462         XEMACPS_TRL_SIZE)
463 #define XEMACPS_MAX_VLAN_FRAME_SIZE  (XEMACPS_MTU + XEMACPS_HDR_SIZE + \
464         XEMACPS_HDR_VLAN_SIZE + XEMACPS_TRL_SIZE)
465 #define XEMACPS_MAX_VLAN_FRAME_SIZE_JUMBO  (XEMACPS_MTU_JUMBO + XEMACPS_HDR_SIZE + \
466         XEMACPS_HDR_VLAN_SIZE + XEMACPS_TRL_SIZE)
467
468 /* DMACR Bust length hash defines */
469
470 #define XEMACPS_SINGLE_BURST    0x00000001
471 #define XEMACPS_4BYTE_BURST             0x00000004
472 #define XEMACPS_8BYTE_BURST             0x00000008
473 #define XEMACPS_16BYTE_BURST    0x00000010
474
475
476 /**************************** Type Definitions ******************************/
477 /** @name Typedefs for callback functions
478  *
479  * These callbacks are invoked in interrupt context.
480  * @{
481  */
482 /**
483  * Callback invoked when frame(s) have been sent or received in interrupt
484  * driven DMA mode. To set the send callback, invoke XEmacPs_SetHandler().
485  *
486  * @param CallBackRef is user data assigned when the callback was set.
487  *
488  * @note
489  * See xemacps_hw.h for bitmasks definitions and the device hardware spec for
490  * further information on their meaning.
491  *
492  */
493 typedef void (*XEmacPs_Handler) (void *CallBackRef);
494
495 /**
496  * Callback when an asynchronous error occurs. To set this callback, invoke
497  * XEmacPs_SetHandler() with XEMACPS_HANDLER_ERROR in the HandlerType
498  * paramter.
499  *
500  * @param CallBackRef is user data assigned when the callback was set.
501  * @param Direction defines either receive or transmit error(s) has occurred.
502  * @param ErrorWord definition varies with Direction
503  *
504  */
505 typedef void (*XEmacPs_ErrHandler) (void *CallBackRef, u8 Direction,
506                                      u32 ErrorWord);
507
508 /*@}*/
509
510 /**
511  * This typedef contains configuration information for a device.
512  */
513 typedef struct {
514         u16 DeviceId;   /**< Unique ID  of device */
515         UINTPTR BaseAddress;/**< Physical base address of IPIF registers */
516 } XEmacPs_Config;
517
518
519 /**
520  * The XEmacPs driver instance data. The user is required to allocate a
521  * structure of this type for every XEmacPs device in the system. A pointer
522  * to a structure of this type is then passed to the driver API functions.
523  */
524 typedef struct XEmacPs_Instance {
525         XEmacPs_Config Config;  /* Hardware configuration */
526         u32 IsStarted;          /* Device is currently started */
527         u32 IsReady;            /* Device is initialized and ready */
528         u32 Options;            /* Current options word */
529
530         XEmacPs_BdRing TxBdRing;        /* Transmit BD ring */
531         XEmacPs_BdRing RxBdRing;        /* Receive BD ring */
532
533         XEmacPs_Handler SendHandler;
534         XEmacPs_Handler RecvHandler;
535         void *SendRef;
536         void *RecvRef;
537
538         XEmacPs_ErrHandler ErrorHandler;
539         void *ErrorRef;
540         u32 Version;
541         u32 RxBufMask;
542         u32 MaxMtuSize;
543         u32 MaxFrameSize;
544         u32 MaxVlanFrameSize;
545
546 } XEmacPs;
547
548
549 /***************** Macros (Inline Functions) Definitions ********************/
550
551 /****************************************************************************/
552 /**
553 * Retrieve the Tx ring object. This object can be used in the various Ring
554 * API functions.
555 *
556 * @param  InstancePtr is the DMA channel to operate on.
557 *
558 * @return TxBdRing attribute
559 *
560 * @note
561 * C-style signature:
562 *    XEmacPs_BdRing XEmacPs_GetTxRing(XEmacPs *InstancePtr)
563 *
564 *****************************************************************************/
565 #define XEmacPs_GetTxRing(InstancePtr) ((InstancePtr)->TxBdRing)
566
567 /****************************************************************************/
568 /**
569 * Retrieve the Rx ring object. This object can be used in the various Ring
570 * API functions.
571 *
572 * @param  InstancePtr is the DMA channel to operate on.
573 *
574 * @return RxBdRing attribute
575 *
576 * @note
577 * C-style signature:
578 *    XEmacPs_BdRing XEmacPs_GetRxRing(XEmacPs *InstancePtr)
579 *
580 *****************************************************************************/
581 #define XEmacPs_GetRxRing(InstancePtr) ((InstancePtr)->RxBdRing)
582
583 /****************************************************************************/
584 /**
585 *
586 * Enable interrupts specified in <i>Mask</i>. The corresponding interrupt for
587 * each bit set to 1 in <i>Mask</i>, will be enabled.
588 *
589 * @param InstancePtr is a pointer to the instance to be worked on.
590 * @param Mask contains a bit mask of interrupts to enable. The mask can
591 *        be formed using a set of bitwise or'd values.
592 *
593 * @note
594 * The state of the transmitter and receiver are not modified by this function.
595 * C-style signature
596 *     void XEmacPs_IntEnable(XEmacPs *InstancePtr, u32 Mask)
597 *
598 *****************************************************************************/
599 #define XEmacPs_IntEnable(InstancePtr, Mask)                            \
600         XEmacPs_WriteReg((InstancePtr)->Config.BaseAddress,             \
601                 XEMACPS_IER_OFFSET,                                     \
602                 ((Mask) & XEMACPS_IXR_ALL_MASK));
603
604 /****************************************************************************/
605 /**
606 *
607 * Disable interrupts specified in <i>Mask</i>. The corresponding interrupt for
608 * each bit set to 1 in <i>Mask</i>, will be enabled.
609 *
610 * @param InstancePtr is a pointer to the instance to be worked on.
611 * @param Mask contains a bit mask of interrupts to disable. The mask can
612 *        be formed using a set of bitwise or'd values.
613 *
614 * @note
615 * The state of the transmitter and receiver are not modified by this function.
616 * C-style signature
617 *     void XEmacPs_IntDisable(XEmacPs *InstancePtr, u32 Mask)
618 *
619 *****************************************************************************/
620 #define XEmacPs_IntDisable(InstancePtr, Mask)                           \
621         XEmacPs_WriteReg((InstancePtr)->Config.BaseAddress,             \
622                 XEMACPS_IDR_OFFSET,                                     \
623                 ((Mask) & XEMACPS_IXR_ALL_MASK));
624
625 /****************************************************************************/
626 /**
627 *
628 * Enable interrupts specified in <i>Mask</i>. The corresponding interrupt for
629 * each bit set to 1 in <i>Mask</i>, will be enabled.
630 *
631 * @param InstancePtr is a pointer to the instance to be worked on.
632 * @param Mask contains a bit mask of interrupts to enable. The mask can
633 *        be formed using a set of bitwise or'd values.
634 *
635 * @note
636 * The state of the transmitter and receiver are not modified by this function.
637 * C-style signature
638 *     void XEmacPs_IntQ1Enable(XEmacPs *InstancePtr, u32 Mask)
639 *
640 *****************************************************************************/
641 #define XEmacPs_IntQ1Enable(InstancePtr, Mask)                            \
642         XEmacPs_WriteReg((InstancePtr)->Config.BaseAddress,             \
643                 XEMACPS_INTQ1_IER_OFFSET,                                \
644                 ((Mask) & XEMACPS_INTQ1_IXR_ALL_MASK));
645
646 /****************************************************************************/
647 /**
648 *
649 * Disable interrupts specified in <i>Mask</i>. The corresponding interrupt for
650 * each bit set to 1 in <i>Mask</i>, will be enabled.
651 *
652 * @param InstancePtr is a pointer to the instance to be worked on.
653 * @param Mask contains a bit mask of interrupts to disable. The mask can
654 *        be formed using a set of bitwise or'd values.
655 *
656 * @note
657 * The state of the transmitter and receiver are not modified by this function.
658 * C-style signature
659 *     void XEmacPs_IntDisable(XEmacPs *InstancePtr, u32 Mask)
660 *
661 *****************************************************************************/
662 #define XEmacPs_IntQ1Disable(InstancePtr, Mask)                           \
663         XEmacPs_WriteReg((InstancePtr)->Config.BaseAddress,             \
664                 XEMACPS_INTQ1_IDR_OFFSET,                               \
665                 ((Mask) & XEMACPS_INTQ1_IXR_ALL_MASK));
666
667 /****************************************************************************/
668 /**
669 *
670 * This macro triggers trasmit circuit to send data currently in TX buffer(s).
671 *
672 * @param InstancePtr is a pointer to the XEmacPs instance to be worked on.
673 *
674 * @return
675 *
676 * @note
677 *
678 * Signature: void XEmacPs_Transmit(XEmacPs *InstancePtr)
679 *
680 *****************************************************************************/
681 #define XEmacPs_Transmit(InstancePtr)                              \
682         XEmacPs_WriteReg((InstancePtr)->Config.BaseAddress,          \
683         XEMACPS_NWCTRL_OFFSET,                                     \
684         (XEmacPs_ReadReg((InstancePtr)->Config.BaseAddress,          \
685         XEMACPS_NWCTRL_OFFSET) | XEMACPS_NWCTRL_STARTTX_MASK))
686
687 /****************************************************************************/
688 /**
689 *
690 * This macro determines if the device is configured with checksum offloading
691 * on the receive channel
692 *
693 * @param InstancePtr is a pointer to the XEmacPs instance to be worked on.
694 *
695 * @return
696 *
697 * Boolean TRUE if the device is configured with checksum offloading, or
698 * FALSE otherwise.
699 *
700 * @note
701 *
702 * Signature: u32 XEmacPs_IsRxCsum(XEmacPs *InstancePtr)
703 *
704 *****************************************************************************/
705 #define XEmacPs_IsRxCsum(InstancePtr)                                     \
706         ((XEmacPs_ReadReg((InstancePtr)->Config.BaseAddress,             \
707           XEMACPS_NWCFG_OFFSET) & XEMACPS_NWCFG_RXCHKSUMEN_MASK) != 0U     \
708           ? TRUE : FALSE)
709
710 /****************************************************************************/
711 /**
712 *
713 * This macro determines if the device is configured with checksum offloading
714 * on the transmit channel
715 *
716 * @param InstancePtr is a pointer to the XEmacPs instance to be worked on.
717 *
718 * @return
719 *
720 * Boolean TRUE if the device is configured with checksum offloading, or
721 * FALSE otherwise.
722 *
723 * @note
724 *
725 * Signature: u32 XEmacPs_IsTxCsum(XEmacPs *InstancePtr)
726 *
727 *****************************************************************************/
728 #define XEmacPs_IsTxCsum(InstancePtr)                                     \
729         ((XEmacPs_ReadReg((InstancePtr)->Config.BaseAddress,              \
730           XEMACPS_DMACR_OFFSET) & XEMACPS_DMACR_TCPCKSUM_MASK) != 0U       \
731           ? TRUE : FALSE)
732
733 /************************** Function Prototypes *****************************/
734
735 /*
736  * Initialization functions in xemacps.c
737  */
738 LONG XEmacPs_CfgInitialize(XEmacPs *InstancePtr, XEmacPs_Config *CfgPtr,
739                            UINTPTR EffectiveAddress);
740 void XEmacPs_Start(XEmacPs *InstancePtr);
741 void XEmacPs_Stop(XEmacPs *InstancePtr);
742 void XEmacPs_Reset(XEmacPs *InstancePtr);
743 void XEmacPs_SetQueuePtr(XEmacPs *InstancePtr, UINTPTR QPtr, u8 QueueNum,
744                          u16 Direction);
745
746 /*
747  * Lookup configuration in xemacps_sinit.c
748  */
749 XEmacPs_Config *XEmacPs_LookupConfig(u16 DeviceId);
750
751 /*
752  * Interrupt-related functions in xemacps_intr.c
753  * DMA only and FIFO is not supported. This DMA does not support coalescing.
754  */
755 LONG XEmacPs_SetHandler(XEmacPs *InstancePtr, u32 HandlerType,
756                         void *FuncPointer, void *CallBackRef);
757 void XEmacPs_IntrHandler(void *XEmacPsPtr);
758
759 /*
760  * MAC configuration/control functions in XEmacPs_control.c
761  */
762 LONG XEmacPs_SetOptions(XEmacPs *InstancePtr, u32 Options);
763 LONG XEmacPs_ClearOptions(XEmacPs *InstancePtr, u32 Options);
764 u32 XEmacPs_GetOptions(XEmacPs *InstancePtr);
765
766 LONG XEmacPs_SetMacAddress(XEmacPs *InstancePtr, void *AddressPtr, u8 Index);
767 LONG XEmacPs_DeleteHash(XEmacPs *InstancePtr, void *AddressPtr);
768 void XEmacPs_GetMacAddress(XEmacPs *InstancePtr, void *AddressPtr, u8 Index);
769
770 LONG XEmacPs_SetHash(XEmacPs *InstancePtr, void *AddressPtr);
771 void XEmacPs_ClearHash(XEmacPs *InstancePtr);
772 void XEmacPs_GetHash(XEmacPs *InstancePtr, void *AddressPtr);
773
774 void XEmacPs_SetMdioDivisor(XEmacPs *InstancePtr,
775                                 XEmacPs_MdcDiv Divisor);
776 void XEmacPs_SetOperatingSpeed(XEmacPs *InstancePtr, u16 Speed);
777 u16 XEmacPs_GetOperatingSpeed(XEmacPs *InstancePtr);
778 LONG XEmacPs_PhyRead(XEmacPs *InstancePtr, u32 PhyAddress,
779                      u32 RegisterNum, u16 *PhyDataPtr);
780 LONG XEmacPs_PhyWrite(XEmacPs *InstancePtr, u32 PhyAddress,
781                       u32 RegisterNum, u16 PhyData);
782 LONG XEmacPs_SetTypeIdCheck(XEmacPs *InstancePtr, u32 Id_Check, u8 Index);
783
784 LONG XEmacPs_SendPausePacket(XEmacPs *InstancePtr);
785 void XEmacPs_DMABLengthUpdate(XEmacPs *InstancePtr, s32 BLength);
786
787 #ifdef __cplusplus
788 }
789 #endif
790
791 #endif /* end of protection macro */
792 /** @} */