xemac.h 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673
  1. /******************************************************************************
  2. *
  3. * Author: Xilinx, Inc.
  4. *
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms of the GNU General Public License as published by the
  8. * Free Software Foundation; either version 2 of the License, or (at your
  9. * option) any later version.
  10. *
  11. *
  12. * XILINX IS PROVIDING THIS DESIGN, CODE, OR INFORMATION "AS IS" AS A
  13. * COURTESY TO YOU. BY PROVIDING THIS DESIGN, CODE, OR INFORMATION AS
  14. * ONE POSSIBLE IMPLEMENTATION OF THIS FEATURE, APPLICATION OR STANDARD,
  15. * XILINX IS MAKING NO REPRESENTATION THAT THIS IMPLEMENTATION IS FREE
  16. * FROM ANY CLAIMS OF INFRINGEMENT, AND YOU ARE RESPONSIBLE FOR OBTAINING
  17. * ANY THIRD PARTY RIGHTS YOU MAY REQUIRE FOR YOUR IMPLEMENTATION.
  18. * XILINX EXPRESSLY DISCLAIMS ANY WARRANTY WHATSOEVER WITH RESPECT TO
  19. * THE ADEQUACY OF THE IMPLEMENTATION, INCLUDING BUT NOT LIMITED TO ANY
  20. * WARRANTIES OR REPRESENTATIONS THAT THIS IMPLEMENTATION IS FREE FROM
  21. * CLAIMS OF INFRINGEMENT, IMPLIED WARRANTIES OF MERCHANTABILITY AND
  22. * FITNESS FOR A PARTICULAR PURPOSE.
  23. *
  24. *
  25. * Xilinx hardware products are not intended for use in life support
  26. * appliances, devices, or systems. Use in such applications is
  27. * expressly prohibited.
  28. *
  29. *
  30. * (c) Copyright 2002-2004 Xilinx Inc.
  31. * All rights reserved.
  32. *
  33. *
  34. * You should have received a copy of the GNU General Public License along
  35. * with this program; if not, write to the Free Software Foundation, Inc.,
  36. * 675 Mass Ave, Cambridge, MA 02139, USA.
  37. *
  38. ******************************************************************************/
  39. /*****************************************************************************/
  40. /**
  41. *
  42. * @file xemac.h
  43. *
  44. * The Xilinx Ethernet driver component. This component supports the Xilinx
  45. * Ethernet 10/100 MAC (EMAC).
  46. *
  47. * The Xilinx Ethernet 10/100 MAC supports the following features:
  48. * - Simple and scatter-gather DMA operations, as well as simple memory
  49. * mapped direct I/O interface (FIFOs).
  50. * - Media Independent Interface (MII) for connection to external
  51. * 10/100 Mbps PHY transceivers.
  52. * - MII management control reads and writes with MII PHYs
  53. * - Independent internal transmit and receive FIFOs
  54. * - CSMA/CD compliant operations for half-duplex modes
  55. * - Programmable PHY reset signal
  56. * - Unicast, broadcast, and promiscuous address filtering (no multicast yet)
  57. * - Internal loopback
  58. * - Automatic source address insertion or overwrite (programmable)
  59. * - Automatic FCS insertion and stripping (programmable)
  60. * - Automatic pad insertion and stripping (programmable)
  61. * - Pause frame (flow control) detection in full-duplex mode
  62. * - Programmable interframe gap
  63. * - VLAN frame support.
  64. * - Pause frame support
  65. *
  66. * The device driver supports all the features listed above.
  67. *
  68. * <b>Driver Description</b>
  69. *
  70. * The device driver enables higher layer software (e.g., an application) to
  71. * communicate to the EMAC. The driver handles transmission and reception of
  72. * Ethernet frames, as well as configuration of the controller. It does not
  73. * handle protocol stack functionality such as Link Layer Control (LLC) or the
  74. * Address Resolution Protocol (ARP). The protocol stack that makes use of the
  75. * driver handles this functionality. This implies that the driver is simply a
  76. * pass-through mechanism between a protocol stack and the EMAC. A single device
  77. * driver can support multiple EMACs.
  78. *
  79. * The driver is designed for a zero-copy buffer scheme. That is, the driver will
  80. * not copy buffers. This avoids potential throughput bottlenecks within the
  81. * driver.
  82. *
  83. * Since the driver is a simple pass-through mechanism between a protocol stack
  84. * and the EMAC, no assembly or disassembly of Ethernet frames is done at the
  85. * driver-level. This assumes that the protocol stack passes a correctly
  86. * formatted Ethernet frame to the driver for transmission, and that the driver
  87. * does not validate the contents of an incoming frame
  88. *
  89. * <b>PHY Communication</b>
  90. *
  91. * The driver provides rudimentary read and write functions to allow the higher
  92. * layer software to access the PHY. The EMAC provides MII registers for the
  93. * driver to access. This management interface can be parameterized away in the
  94. * FPGA implementation process. If this is the case, the PHY read and write
  95. * functions of the driver return XST_NO_FEATURE.
  96. *
  97. * External loopback is usually supported at the PHY. It is up to the user to
  98. * turn external loopback on or off at the PHY. The driver simply provides pass-
  99. * through functions for configuring the PHY. The driver does not read, write,
  100. * or reset the PHY on its own. All control of the PHY must be done by the user.
  101. *
  102. * <b>Asynchronous Callbacks</b>
  103. *
  104. * The driver services interrupts and passes Ethernet frames to the higher layer
  105. * software through asynchronous callback functions. When using the driver
  106. * directly (i.e., not with the RTOS protocol stack), the higher layer
  107. * software must register its callback functions during initialization. The
  108. * driver requires callback functions for received frames, for confirmation of
  109. * transmitted frames, and for asynchronous errors.
  110. *
  111. * <b>Interrupts</b>
  112. *
  113. * The driver has no dependencies on the interrupt controller. The driver
  114. * provides two interrupt handlers. XEmac_IntrHandlerDma() handles interrupts
  115. * when the EMAC is configured with scatter-gather DMA. XEmac_IntrHandlerFifo()
  116. * handles interrupts when the EMAC is configured for direct FIFO I/O or simple
  117. * DMA. Either of these routines can be connected to the system interrupt
  118. * controller by the user.
  119. *
  120. * <b>Interrupt Frequency</b>
  121. *
  122. * When the EMAC is configured with scatter-gather DMA, the frequency of
  123. * interrupts can be controlled with the interrupt coalescing features of the
  124. * scatter-gather DMA engine. The frequency of interrupts can be adjusted using
  125. * the driver API functions for setting the packet count threshold and the packet
  126. * wait bound values.
  127. *
  128. * The scatter-gather DMA engine only interrupts when the packet count threshold
  129. * is reached, instead of interrupting for each packet. A packet is a generic
  130. * term used by the scatter-gather DMA engine, and is equivalent to an Ethernet
  131. * frame in our case.
  132. *
  133. * The packet wait bound is a timer value used during interrupt coalescing to
  134. * trigger an interrupt when not enough packets have been received to reach the
  135. * packet count threshold.
  136. *
  137. * These values can be tuned by the user to meet their needs. If there appear to
  138. * be interrupt latency problems or delays in packet arrival that are longer than
  139. * might be expected, the user should verify that the packet count threshold is
  140. * set low enough to receive interrupts before the wait bound timer goes off.
  141. *
  142. * <b>Device Reset</b>
  143. *
  144. * Some errors that can occur in the device require a device reset. These errors
  145. * are listed in the XEmac_SetErrorHandler() function header. The user's error
  146. * handler is responsible for resetting the device and re-configuring it based on
  147. * its needs (the driver does not save the current configuration). When
  148. * integrating into an RTOS, these reset and re-configure obligations are
  149. * taken care of by the Xilinx adapter software if it exists for that RTOS.
  150. *
  151. * <b>Device Configuration</b>
  152. *
  153. * The device can be configured in various ways during the FPGA implementation
  154. * process. Configuration parameters are stored in the xemac_g.c files.
  155. * A table is defined where each entry contains configuration information
  156. * for an EMAC device. This information includes such things as the base address
  157. * of the memory-mapped device, the base addresses of IPIF, DMA, and FIFO modules
  158. * within the device, and whether the device has DMA, counter registers,
  159. * multicast support, MII support, and flow control.
  160. *
  161. * The driver tries to use the features built into the device. So if, for
  162. * example, the hardware is configured with scatter-gather DMA, the driver
  163. * expects to start the scatter-gather channels and expects that the user has set
  164. * up the buffer descriptor lists already. If the user expects to use the driver
  165. * in a mode different than how the hardware is configured, the user should
  166. * modify the configuration table to reflect the mode to be used. Modifying the
  167. * configuration table is a workaround for now until we get some experience with
  168. * how users are intending to use the hardware in its different configurations.
  169. * For example, if the hardware is built with scatter-gather DMA but the user is
  170. * intending to use only simple DMA, the user either needs to modify the config
  171. * table as a workaround or rebuild the hardware with only simple DMA. The
  172. * recommendation at this point is to build the hardware with the features you
  173. * intend to use. If you're inclined to modify the table, do so before the call
  174. * to XEmac_Initialize(). Here is a snippet of code that changes a device to
  175. * simple DMA (the hardware needs to have DMA for this to work of course):
  176. * <pre>
  177. * XEmac_Config *ConfigPtr;
  178. *
  179. * ConfigPtr = XEmac_LookupConfig(DeviceId);
  180. * ConfigPtr->IpIfDmaConfig = XEM_CFG_SIMPLE_DMA;
  181. * </pre>
  182. *
  183. * <b>Simple DMA</b>
  184. *
  185. * Simple DMA is supported through the FIFO functions, FifoSend and FifoRecv, of
  186. * the driver (i.e., there is no separate interface for it). The driver makes use
  187. * of the DMA engine for a simple DMA transfer if the device is configured with
  188. * DMA, otherwise it uses the FIFOs directly. While the simple DMA interface is
  189. * therefore transparent to the user, the caching of network buffers is not.
  190. * If the device is configured with DMA and the FIFO interface is used, the user
  191. * must ensure that the network buffers are not cached or are cache coherent,
  192. * since DMA will be used to transfer to and from the Emac device. If the device
  193. * is configured with DMA and the user really wants to use the FIFOs directly,
  194. * the user should rebuild the hardware without DMA. If unable to do this, there
  195. * is a workaround (described above in Device Configuration) to modify the
  196. * configuration table of the driver to fake the driver into thinking the device
  197. * has no DMA. A code snippet follows:
  198. * <pre>
  199. * XEmac_Config *ConfigPtr;
  200. *
  201. * ConfigPtr = XEmac_LookupConfig(DeviceId);
  202. * ConfigPtr->IpIfDmaConfig = XEM_CFG_NO_DMA;
  203. * </pre>
  204. *
  205. * <b>Asserts</b>
  206. *
  207. * Asserts are used within all Xilinx drivers to enforce constraints on argument
  208. * values. Asserts can be turned off on a system-wide basis by defining, at
  209. * compile time, the NDEBUG identifier. By default, asserts are turned on and it
  210. * is recommended that users leave asserts on during development.
  211. *
  212. * <b>Building the driver</b>
  213. *
  214. * The XEmac driver is composed of several source files. Why so many? This
  215. * allows the user to build and link only those parts of the driver that are
  216. * necessary. Since the EMAC hardware can be configured in various ways (e.g.,
  217. * with or without DMA), the driver too can be built with varying features.
  218. * For the most part, this means that besides always linking in xemac.c, you
  219. * link in only the driver functionality you want. Some of the choices you have
  220. * are polled vs. interrupt, interrupt with FIFOs only vs. interrupt with DMA,
  221. * self-test diagnostics, and driver statistics. Note that currently the DMA code
  222. * must be linked in, even if you don't have DMA in the device.
  223. *
  224. * @note
  225. *
  226. * Xilinx drivers are typically composed of two components, one is the driver
  227. * and the other is the adapter. The driver is independent of OS and processor
  228. * and is intended to be highly portable. The adapter is OS-specific and
  229. * facilitates communication between the driver and an OS.
  230. * <br><br>
  231. * This driver is intended to be RTOS and processor independent. It works
  232. * with physical addresses only. Any needs for dynamic memory management,
  233. * threads or thread mutual exclusion, virtual memory, or cache control must
  234. * be satisfied by the layer above this driver.
  235. *
  236. * <pre>
  237. * MODIFICATION HISTORY:
  238. *
  239. * Ver Who Date Changes
  240. * ----- ---- -------- -------------------------------------------------------
  241. * 1.00a rpm 07/31/01 First release
  242. * 1.00b rpm 02/20/02 Repartitioned files and functions
  243. * 1.00b rpm 10/08/02 Replaced HasSgDma boolean with IpifDmaConfig enumerated
  244. * configuration parameter
  245. * 1.00c rpm 12/05/02 New version includes support for simple DMA and the delay
  246. * argument to SgSend
  247. * 1.00c rpm 02/03/03 The XST_DMA_SG_COUNT_EXCEEDED return code was removed
  248. * from SetPktThreshold in the internal DMA driver. Also
  249. * avoided compiler warnings by initializing Result in the
  250. * DMA interrupt service routines.
  251. * </pre>
  252. *
  253. ******************************************************************************/
  254. #ifndef XEMAC_H /* prevent circular inclusions */
  255. #define XEMAC_H /* by using protection macros */
  256. /***************************** Include Files *********************************/
  257. #include "xbasic_types.h"
  258. #include "xstatus.h"
  259. #include "xparameters.h"
  260. #include "xpacket_fifo_v1_00_b.h" /* Uses v1.00b of Packet Fifo */
  261. #include "xdma_channel.h"
  262. /************************** Constant Definitions *****************************/
  263. /*
  264. * Device information
  265. */
  266. #define XEM_DEVICE_NAME "xemac"
  267. #define XEM_DEVICE_DESC "Xilinx Ethernet 10/100 MAC"
  268. /** @name Configuration options
  269. *
  270. * Device configuration options (see the XEmac_SetOptions() and
  271. * XEmac_GetOptions() for information on how to use these options)
  272. * @{
  273. */
  274. /**
  275. * <pre>
  276. * XEM_BROADCAST_OPTION Broadcast addressing on or off (default is on)
  277. * XEM_UNICAST_OPTION Unicast addressing on or off (default is on)
  278. * XEM_PROMISC_OPTION Promiscuous addressing on or off (default is off)
  279. * XEM_FDUPLEX_OPTION Full duplex on or off (default is off)
  280. * XEM_POLLED_OPTION Polled mode on or off (default is off)
  281. * XEM_LOOPBACK_OPTION Internal loopback on or off (default is off)
  282. * XEM_FLOW_CONTROL_OPTION Interpret pause frames in full duplex mode
  283. * (default is off)
  284. * XEM_INSERT_PAD_OPTION Pad short frames on transmit (default is on)
  285. * XEM_INSERT_FCS_OPTION Insert FCS (CRC) on transmit (default is on)
  286. * XEM_INSERT_ADDR_OPTION Insert source address on transmit (default is on)
  287. * XEM_OVWRT_ADDR_OPTION Overwrite source address on transmit. This is
  288. * only used if source address insertion is on.
  289. * (default is on)
  290. * XEM_STRIP_PAD_FCS_OPTION Strip FCS and padding from received frames
  291. * (default is off)
  292. * </pre>
  293. */
  294. #define XEM_UNICAST_OPTION 0x00000001UL
  295. #define XEM_BROADCAST_OPTION 0x00000002UL
  296. #define XEM_PROMISC_OPTION 0x00000004UL
  297. #define XEM_FDUPLEX_OPTION 0x00000008UL
  298. #define XEM_POLLED_OPTION 0x00000010UL
  299. #define XEM_LOOPBACK_OPTION 0x00000020UL
  300. #define XEM_FLOW_CONTROL_OPTION 0x00000080UL
  301. #define XEM_INSERT_PAD_OPTION 0x00000100UL
  302. #define XEM_INSERT_FCS_OPTION 0x00000200UL
  303. #define XEM_INSERT_ADDR_OPTION 0x00000400UL
  304. #define XEM_OVWRT_ADDR_OPTION 0x00000800UL
  305. #define XEM_STRIP_PAD_FCS_OPTION 0x00002000UL
  306. /*@}*/
  307. /*
  308. * Not supported yet:
  309. * XEM_MULTICAST_OPTION Multicast addressing on or off (default is off)
  310. */
  311. /* NOT SUPPORTED YET... */
  312. #define XEM_MULTICAST_OPTION 0x00000040UL
  313. /*
  314. * Some default values for interrupt coalescing within the scatter-gather
  315. * DMA engine.
  316. */
  317. #define XEM_SGDMA_DFT_THRESHOLD 1 /* Default pkt threshold */
  318. #define XEM_SGDMA_MAX_THRESHOLD 255 /* Maximum pkt theshold */
  319. #define XEM_SGDMA_DFT_WAITBOUND 5 /* Default pkt wait bound (msec) */
  320. #define XEM_SGDMA_MAX_WAITBOUND 1023 /* Maximum pkt wait bound (msec) */
  321. /*
  322. * Direction identifiers. These are used for setting values like packet
  323. * thresholds and wait bound for specific channels
  324. */
  325. #define XEM_SEND 1
  326. #define XEM_RECV 2
  327. /*
  328. * Arguments to SgSend function to indicate whether to hold off starting
  329. * the scatter-gather engine.
  330. */
  331. #define XEM_SGDMA_NODELAY 0 /* start SG DMA immediately */
  332. #define XEM_SGDMA_DELAY 1 /* do not start SG DMA */
  333. /*
  334. * Constants to determine the configuration of the hardware device. They are
  335. * used to allow the driver to verify it can operate with the hardware.
  336. */
  337. #define XEM_CFG_NO_IPIF 0 /* Not supported by the driver */
  338. #define XEM_CFG_NO_DMA 1 /* No DMA */
  339. #define XEM_CFG_SIMPLE_DMA 2 /* Simple DMA */
  340. #define XEM_CFG_DMA_SG 3 /* DMA scatter gather */
  341. /*
  342. * The next few constants help upper layers determine the size of memory
  343. * pools used for Ethernet buffers and descriptor lists.
  344. */
  345. #define XEM_MAC_ADDR_SIZE 6 /* six-byte MAC address */
  346. #define XEM_MTU 1500 /* max size of Ethernet frame */
  347. #define XEM_HDR_SIZE 14 /* size of Ethernet header */
  348. #define XEM_HDR_VLAN_SIZE 18 /* size of Ethernet header with VLAN */
  349. #define XEM_TRL_SIZE 4 /* size of Ethernet trailer (FCS) */
  350. #define XEM_MAX_FRAME_SIZE (XEM_MTU + XEM_HDR_SIZE + XEM_TRL_SIZE)
  351. #define XEM_MAX_VLAN_FRAME_SIZE (XEM_MTU + XEM_HDR_VLAN_SIZE + XEM_TRL_SIZE)
  352. /*
  353. * Define a default number of send and receive buffers
  354. */
  355. #define XEM_MIN_RECV_BUFS 32 /* minimum # of recv buffers */
  356. #define XEM_DFT_RECV_BUFS 64 /* default # of recv buffers */
  357. #define XEM_MIN_SEND_BUFS 16 /* minimum # of send buffers */
  358. #define XEM_DFT_SEND_BUFS 32 /* default # of send buffers */
  359. #define XEM_MIN_BUFFERS (XEM_MIN_RECV_BUFS + XEM_MIN_SEND_BUFS)
  360. #define XEM_DFT_BUFFERS (XEM_DFT_RECV_BUFS + XEM_DFT_SEND_BUFS)
  361. /*
  362. * Define the number of send and receive buffer descriptors, used for
  363. * scatter-gather DMA
  364. */
  365. #define XEM_MIN_RECV_DESC 16 /* minimum # of recv descriptors */
  366. #define XEM_DFT_RECV_DESC 32 /* default # of recv descriptors */
  367. #define XEM_MIN_SEND_DESC 8 /* minimum # of send descriptors */
  368. #define XEM_DFT_SEND_DESC 16 /* default # of send descriptors */
  369. /**************************** Type Definitions *******************************/
  370. /**
  371. * Ethernet statistics (see XEmac_GetStats() and XEmac_ClearStats())
  372. */
  373. typedef struct {
  374. u32 XmitFrames; /**< Number of frames transmitted */
  375. u32 XmitBytes; /**< Number of bytes transmitted */
  376. u32 XmitLateCollisionErrors;
  377. /**< Number of transmission failures
  378. due to late collisions */
  379. u32 XmitExcessDeferral; /**< Number of transmission failures
  380. due o excess collision deferrals */
  381. u32 XmitOverrunErrors; /**< Number of transmit overrun errors */
  382. u32 XmitUnderrunErrors; /**< Number of transmit underrun errors */
  383. u32 RecvFrames; /**< Number of frames received */
  384. u32 RecvBytes; /**< Number of bytes received */
  385. u32 RecvFcsErrors; /**< Number of frames discarded due
  386. to FCS errors */
  387. u32 RecvAlignmentErrors; /**< Number of frames received with
  388. alignment errors */
  389. u32 RecvOverrunErrors; /**< Number of frames discarded due
  390. to overrun errors */
  391. u32 RecvUnderrunErrors; /**< Number of recv underrun errors */
  392. u32 RecvMissedFrameErrors;
  393. /**< Number of frames missed by MAC */
  394. u32 RecvCollisionErrors; /**< Number of frames discarded due
  395. to collisions */
  396. u32 RecvLengthFieldErrors;
  397. /**< Number of frames discarded with
  398. invalid length field */
  399. u32 RecvShortErrors; /**< Number of short frames discarded */
  400. u32 RecvLongErrors; /**< Number of long frames discarded */
  401. u32 DmaErrors; /**< Number of DMA errors since init */
  402. u32 FifoErrors; /**< Number of FIFO errors since init */
  403. u32 RecvInterrupts; /**< Number of receive interrupts */
  404. u32 XmitInterrupts; /**< Number of transmit interrupts */
  405. u32 EmacInterrupts; /**< Number of MAC (device) interrupts */
  406. u32 TotalIntrs; /**< Total interrupts */
  407. } XEmac_Stats;
  408. /**
  409. * This typedef contains configuration information for a device.
  410. */
  411. typedef struct {
  412. u16 DeviceId; /**< Unique ID of device */
  413. u32 BaseAddress; /**< Register base address */
  414. u32 HasCounters; /**< Does device have counters? */
  415. u8 IpIfDmaConfig; /**< IPIF/DMA hardware configuration */
  416. u32 HasMii; /**< Does device support MII? */
  417. } XEmac_Config;
  418. /** @name Typedefs for callbacks
  419. * Callback functions.
  420. * @{
  421. */
  422. /**
  423. * Callback when data is sent or received with scatter-gather DMA.
  424. *
  425. * @param CallBackRef is a callback reference passed in by the upper layer
  426. * when setting the callback functions, and passed back to the upper
  427. * layer when the callback is invoked.
  428. * @param BdPtr is a pointer to the first buffer descriptor in a list of
  429. * buffer descriptors.
  430. * @param NumBds is the number of buffer descriptors in the list pointed
  431. * to by BdPtr.
  432. */
  433. typedef void (*XEmac_SgHandler) (void *CallBackRef, XBufDescriptor * BdPtr,
  434. u32 NumBds);
  435. /**
  436. * Callback when data is sent or received with direct FIFO communication or
  437. * simple DMA. The user typically defines two callacks, one for send and one
  438. * for receive.
  439. *
  440. * @param CallBackRef is a callback reference passed in by the upper layer
  441. * when setting the callback functions, and passed back to the upper
  442. * layer when the callback is invoked.
  443. */
  444. typedef void (*XEmac_FifoHandler) (void *CallBackRef);
  445. /**
  446. * Callback when an asynchronous error occurs.
  447. *
  448. * @param CallBackRef is a callback reference passed in by the upper layer
  449. * when setting the callback functions, and passed back to the upper
  450. * layer when the callback is invoked.
  451. * @param ErrorCode is a Xilinx error code defined in xstatus.h. Also see
  452. * XEmac_SetErrorHandler() for a description of possible errors.
  453. */
  454. typedef void (*XEmac_ErrorHandler) (void *CallBackRef, XStatus ErrorCode);
  455. /*@}*/
  456. /**
  457. * The XEmac driver instance data. The user is required to allocate a
  458. * variable of this type for every EMAC device in the system. A pointer
  459. * to a variable of this type is then passed to the driver API functions.
  460. */
  461. typedef struct {
  462. u32 BaseAddress; /* Base address (of IPIF) */
  463. u32 IsStarted; /* Device is currently started */
  464. u32 IsReady; /* Device is initialized and ready */
  465. u32 IsPolled; /* Device is in polled mode */
  466. u8 IpIfDmaConfig; /* IPIF/DMA hardware configuration */
  467. u32 HasMii; /* Does device support MII? */
  468. u32 HasMulticastHash; /* Does device support multicast hash table? */
  469. XEmac_Stats Stats;
  470. XPacketFifoV100b RecvFifo; /* FIFO used to receive frames */
  471. XPacketFifoV100b SendFifo; /* FIFO used to send frames */
  472. /*
  473. * Callbacks
  474. */
  475. XEmac_FifoHandler FifoRecvHandler; /* for non-DMA/simple DMA interrupts */
  476. void *FifoRecvRef;
  477. XEmac_FifoHandler FifoSendHandler; /* for non-DMA/simple DMA interrupts */
  478. void *FifoSendRef;
  479. XEmac_ErrorHandler ErrorHandler; /* for asynchronous errors */
  480. void *ErrorRef;
  481. XDmaChannel RecvChannel; /* DMA receive channel driver */
  482. XDmaChannel SendChannel; /* DMA send channel driver */
  483. XEmac_SgHandler SgRecvHandler; /* callback for scatter-gather DMA */
  484. void *SgRecvRef;
  485. XEmac_SgHandler SgSendHandler; /* callback for scatter-gather DMA */
  486. void *SgSendRef;
  487. } XEmac;
  488. /***************** Macros (Inline Functions) Definitions *********************/
  489. /*****************************************************************************/
  490. /**
  491. *
  492. * This macro determines if the device is currently configured for
  493. * scatter-gather DMA.
  494. *
  495. * @param InstancePtr is a pointer to the XEmac instance to be worked on.
  496. *
  497. * @return
  498. *
  499. * Boolean TRUE if the device is configured for scatter-gather DMA, or FALSE
  500. * if it is not.
  501. *
  502. * @note
  503. *
  504. * Signature: u32 XEmac_mIsSgDma(XEmac *InstancePtr)
  505. *
  506. ******************************************************************************/
  507. #define XEmac_mIsSgDma(InstancePtr) \
  508. ((InstancePtr)->IpIfDmaConfig == XEM_CFG_DMA_SG)
  509. /*****************************************************************************/
  510. /**
  511. *
  512. * This macro determines if the device is currently configured for simple DMA.
  513. *
  514. * @param InstancePtr is a pointer to the XEmac instance to be worked on.
  515. *
  516. * @return
  517. *
  518. * Boolean TRUE if the device is configured for simple DMA, or FALSE otherwise
  519. *
  520. * @note
  521. *
  522. * Signature: u32 XEmac_mIsSimpleDma(XEmac *InstancePtr)
  523. *
  524. ******************************************************************************/
  525. #define XEmac_mIsSimpleDma(InstancePtr) \
  526. ((InstancePtr)->IpIfDmaConfig == XEM_CFG_SIMPLE_DMA)
  527. /*****************************************************************************/
  528. /**
  529. *
  530. * This macro determines if the device is currently configured with DMA (either
  531. * simple DMA or scatter-gather DMA)
  532. *
  533. * @param InstancePtr is a pointer to the XEmac instance to be worked on.
  534. *
  535. * @return
  536. *
  537. * Boolean TRUE if the device is configured with DMA, or FALSE otherwise
  538. *
  539. * @note
  540. *
  541. * Signature: u32 XEmac_mIsDma(XEmac *InstancePtr)
  542. *
  543. ******************************************************************************/
  544. #define XEmac_mIsDma(InstancePtr) \
  545. (XEmac_mIsSimpleDma(InstancePtr) || XEmac_mIsSgDma(InstancePtr))
  546. /************************** Function Prototypes ******************************/
  547. /*
  548. * Initialization functions in xemac.c
  549. */
  550. XStatus XEmac_Initialize(XEmac * InstancePtr, u16 DeviceId);
  551. XStatus XEmac_Start(XEmac * InstancePtr);
  552. XStatus XEmac_Stop(XEmac * InstancePtr);
  553. void XEmac_Reset(XEmac * InstancePtr);
  554. XEmac_Config *XEmac_LookupConfig(u16 DeviceId);
  555. /*
  556. * Diagnostic functions in xemac_selftest.c
  557. */
  558. XStatus XEmac_SelfTest(XEmac * InstancePtr);
  559. /*
  560. * Polled functions in xemac_polled.c
  561. */
  562. XStatus XEmac_PollSend(XEmac * InstancePtr, u8 * BufPtr, u32 ByteCount);
  563. XStatus XEmac_PollRecv(XEmac * InstancePtr, u8 * BufPtr, u32 * ByteCountPtr);
  564. /*
  565. * Interrupts with scatter-gather DMA functions in xemac_intr_dma.c
  566. */
  567. XStatus XEmac_SgSend(XEmac * InstancePtr, XBufDescriptor * BdPtr, int Delay);
  568. XStatus XEmac_SgRecv(XEmac * InstancePtr, XBufDescriptor * BdPtr);
  569. XStatus XEmac_SetPktThreshold(XEmac * InstancePtr, u32 Direction, u8 Threshold);
  570. XStatus XEmac_GetPktThreshold(XEmac * InstancePtr, u32 Direction,
  571. u8 * ThreshPtr);
  572. XStatus XEmac_SetPktWaitBound(XEmac * InstancePtr, u32 Direction,
  573. u32 TimerValue);
  574. XStatus XEmac_GetPktWaitBound(XEmac * InstancePtr, u32 Direction,
  575. u32 * WaitPtr);
  576. XStatus XEmac_SetSgRecvSpace(XEmac * InstancePtr, u32 * MemoryPtr,
  577. u32 ByteCount);
  578. XStatus XEmac_SetSgSendSpace(XEmac * InstancePtr, u32 * MemoryPtr,
  579. u32 ByteCount);
  580. void XEmac_SetSgRecvHandler(XEmac * InstancePtr, void *CallBackRef,
  581. XEmac_SgHandler FuncPtr);
  582. void XEmac_SetSgSendHandler(XEmac * InstancePtr, void *CallBackRef,
  583. XEmac_SgHandler FuncPtr);
  584. void XEmac_IntrHandlerDma(void *InstancePtr); /* interrupt handler */
  585. /*
  586. * Interrupts with direct FIFO functions in xemac_intr_fifo.c. Also used
  587. * for simple DMA.
  588. */
  589. XStatus XEmac_FifoSend(XEmac * InstancePtr, u8 * BufPtr, u32 ByteCount);
  590. XStatus XEmac_FifoRecv(XEmac * InstancePtr, u8 * BufPtr, u32 * ByteCountPtr);
  591. void XEmac_SetFifoRecvHandler(XEmac * InstancePtr, void *CallBackRef,
  592. XEmac_FifoHandler FuncPtr);
  593. void XEmac_SetFifoSendHandler(XEmac * InstancePtr, void *CallBackRef,
  594. XEmac_FifoHandler FuncPtr);
  595. void XEmac_IntrHandlerFifo(void *InstancePtr); /* interrupt handler */
  596. /*
  597. * General interrupt-related functions in xemac_intr.c
  598. */
  599. void XEmac_SetErrorHandler(XEmac * InstancePtr, void *CallBackRef,
  600. XEmac_ErrorHandler FuncPtr);
  601. /*
  602. * MAC configuration in xemac_options.c
  603. */
  604. XStatus XEmac_SetOptions(XEmac * InstancePtr, u32 OptionFlag);
  605. u32 XEmac_GetOptions(XEmac * InstancePtr);
  606. XStatus XEmac_SetMacAddress(XEmac * InstancePtr, u8 * AddressPtr);
  607. void XEmac_GetMacAddress(XEmac * InstancePtr, u8 * BufferPtr);
  608. XStatus XEmac_SetInterframeGap(XEmac * InstancePtr, u8 Part1, u8 Part2);
  609. void XEmac_GetInterframeGap(XEmac * InstancePtr, u8 * Part1Ptr, u8 * Part2Ptr);
  610. /*
  611. * Multicast functions in xemac_multicast.c (not supported by EMAC yet)
  612. */
  613. XStatus XEmac_MulticastAdd(XEmac * InstancePtr, u8 * AddressPtr);
  614. XStatus XEmac_MulticastClear(XEmac * InstancePtr);
  615. /*
  616. * PHY configuration in xemac_phy.c
  617. */
  618. XStatus XEmac_PhyRead(XEmac * InstancePtr, u32 PhyAddress,
  619. u32 RegisterNum, u16 * PhyDataPtr);
  620. XStatus XEmac_PhyWrite(XEmac * InstancePtr, u32 PhyAddress,
  621. u32 RegisterNum, u16 PhyData);
  622. /*
  623. * Statistics in xemac_stats.c
  624. */
  625. void XEmac_GetStats(XEmac * InstancePtr, XEmac_Stats * StatsPtr);
  626. void XEmac_ClearStats(XEmac * InstancePtr);
  627. #endif /* end of protection macro */