source: rtems/c/src/libchip/network/dwmac.h @ 4953b724

4.115
Last change on this file since 4953b724 was 4953b724, checked in by Ralf Kirchner <ralf.kirchner@…>, on 02/17/14 at 14:43:53

libchip: Add dwmac 10/100/1000 network driver

  • Property mode set to 100644
File size: 32.1 KB
Line 
1/**
2 * @file
3 *
4 * @brief API header for the DWMAC 10/100/1000 Network Interface Controllers
5 *
6 * DWMAC 10/100/1000 on-chip Ethernet controllers are a Synopsys IP Core.
7 */
8
9/*
10 * Copyright (c) 2013 embedded brains GmbH.  All rights reserved.
11 *
12 *  embedded brains GmbH
13 *  Dornierstr. 4
14 *  82178 Puchheim
15 *  Germany
16 *  <rtems@embedded-brains.de>
17 *
18 * The license and distribution terms for this file may be
19 * found in the file LICENSE in this distribution or at
20 * http://www.rtems.org/license/LICENSE.
21 */
22
23#ifndef DWMAC_H_
24#define DWMAC_H_
25
26#include <stddef.h>
27#include <stdint.h>
28#include <rtems/rtems_bsdnet.h>
29
30#ifdef __cplusplus
31extern "C" {
32#endif /* __cplusplus */
33
34/** @brief PHY event.
35 *
36 * Data type to be used for PHY events and event sets.
37 */
38typedef uint8_t dwmac_phy_event;
39
40/** @brief PHY event Jabber. */
41extern const dwmac_phy_event PHY_EVENT_JABBER;
42
43/** @brief PHY event Receive Error. */
44extern const dwmac_phy_event PHY_EVENT_RECEIVE_ERROR;
45
46/** @brief PHY event Page Receive. */
47extern const dwmac_phy_event PHY_EVENT_PAGE_RECEIVE;
48
49/** @brief PHY event Parallel Detect Fault. */
50extern const dwmac_phy_event PHY_EVENT_PARALLEL_DETECT_FAULT;
51
52/** @brief PHY event Link Partner Acknowledge. */
53extern const dwmac_phy_event PHY_EVENT_LINK_PARTNER_ACK;
54
55/** @brief PHY event Link Down. */
56extern const dwmac_phy_event PHY_EVENT_LINK_DOWN;
57
58/** @brief PHY event Remote Fault. */
59extern const dwmac_phy_event PHY_EVENT_REMOTE_FAULT;
60
61/** @brief PHY event Link Up. */
62extern const dwmac_phy_event PHY_EVENT_LINK_UP;
63
64/** @brief NIC enable
65 *
66 * Enables (e.g. powers up) the network interface card.
67 * @param[in,out] arg     The void pointer argument passed to the attach_detach
68 *                        method.
69 * @returns 0 on success, error code from errno.h on failure.
70 * @see dwmac_network_if_attach_detach for the attach_detach method.
71 */
72typedef int
73(*dwmac_if_nic_enable)( void *arg );
74
75/** @brief NIC disable.
76 *
77 * Disables (e.g. powers down) the network interface card.
78 * @param[in,out] arg     The void pointer argument passed to the attach_detach
79 *                        method
80 * @returns 0 on success, error code from errno.h on failure.
81 * @see dwmac_network_if_attach_detach for the attach_detach method.
82 */
83typedef int
84(*dwmac_if_nic_disable)( void *arg );
85
86/** @brief PHY enable.
87 *
88 * Enables (e.g. powers up) the network PHY.
89 * @param[in,out] arg    The void pointer argument passed to the attach_detach
90 *                       method.
91 * @returns 0 on success, error code from errno.h on failure.
92 * @see dwmac_network_if_attach_detach for the attach_detach method.
93 */
94typedef int
95(*dwmac_if_phy_enable)( void *arg );
96
97/** @brief PHY disable.
98 *
99 * Disables (e.g. powers down) the network PHY.
100 * @param[in,out] arg     The void pointer argument passed to the attach_detach
101 *                        method.
102 * @returns 0 on success, error code from errno.h on failure.
103 * @see dwmac_network_if_attach_detach for the attach_detach method.
104 */
105typedef int
106(*dwmac_if_phy_disable)( void *arg );
107
108/** @brief PHY event enable.
109 *
110 * Enables generation of events for an event set.
111 * @param[in,out] arg     The void pointer argument passed to the attach_detach
112 *                        method.
113 * @param[in] event_set   Set of events. For these events shall get generated
114 *                        upon PHY status change.
115 * @returns 0 on success, error code from errno.h on failure.
116 * @see dwmac_network_if_attach_detach for the attach_detach method.
117 */
118typedef int
119(*dwmac_if_phy_event_enable)(
120  void                 *arg,
121  const dwmac_phy_event event_set );
122
123/** @brief Clear phy event status.
124 *
125 * Clears all PHY event statuses.
126 * @param[in,out] arg     The void pointer argument passed to the attach_detach
127 *                        method.
128 * @returns 0 on success, error code from errno.h on failure.
129 * @see dwmac_network_if_attach_detach for the attach_detach method.
130 */
131typedef int
132(*dwmac_if_phy_event_status_clear)( void *arg );
133
134/**
135 * @brief Get the PHY event status.
136 *
137 * Reports status on PHY events (e.g. PHY interrupts).
138 * @param[in,out] arg       The void pointer argument passed to the
139 *                          attach_detach method.
140 * @param[out]    event_set Pointer to a buffer for a set of events for which a
141 *                          PHY status change was detected.
142 * @returns 0 on success, error code from errno.h on failure.
143 * @see dwmac_network_if_attach_detach for the attach_detach method.
144 * @see dwmac_phy_event for events.
145 */
146typedef int
147(*dwmac_if_phy_events_status_get)(
148  void            *arg,
149  dwmac_phy_event *event_set );
150
151/**
152 * @brief Start the network PHY.
153 *
154 * Do anything necessary to start the network PHY (start generating
155 * events, ...).
156 * @param[in,out] arg     The void pointer argument passed to the attach_detach
157 *                        method.
158 * @returns 0 on success, error code from errno.h on failure.
159 * @see dwmac_network_if_attach_detach for the attach_detach method.
160 */
161typedef int
162(*dwcmac_if_phy_start)( void *arg );
163
164/**
165 * @brief Stop the network PHY.
166 *
167 * Do anything necessary to stop the network PHY (stop generating events, ...).
168 * @param[in,out] arg     The void pointer argument passed to the attach_detach
169 *                        method.
170 * @returns 0 on success, error code from errno.h on failure.
171 * @see dwmac_network_if_attach_detach for the attach_detach method.
172 */
173typedef int
174(*dwcmac_if_phy_stop)( void *arg );
175
176/**
177 * @brief Allocate nocache RAM.
178 *
179 * Allocate uncached RAM.
180 * @param[in,out] arg     The void pointer argument passed to the attach_detach
181 *                        method.
182 * @param[out]    memory  Pointer of a buffer to write the address of the
183 *                        allocated memory to.
184 * @param[in]     size    Number of bytes to be allocated
185 * @returns 0 on success, error code from errno.h on failure.
186 * @see dwmac_network_if_attach_detach for the attach_detach method.
187 */
188typedef int
189(*dwmac_if_mem_alloc_nocache)(
190  void        *arg,
191  void       **memory,
192  const size_t size );
193
194/**
195 * @brief Free nocache RAM.
196 *
197 * Release uncached RAM.
198 * @param[in,out] arg     The void pointer argument passed to the attach_detach
199 *                        method.
200 * @param[in]     memory  Pointer to the memory to be freed.
201 * @returns 0 on success, error code from errno.h on failure.
202 * @see dwmac_network_if_attach_detach for the attach_detach method.
203 */
204typedef int
205(*dwmac_if_mem_free_nocache)(
206  void *arg,
207  void *memory );
208
209/**
210 * @brief Bus setup.
211 *
212 * Callback method for setting up the system bus for the network driver.
213 * @param[in,out] arg     The void pointer argument passed to the attach_detach
214 *                        method.
215 * @returns 0 on success, error code from errno.h on failure.
216 * @see dwmac_network_if_attach_detach for the attach_detach method.
217 */
218typedef int
219(*dwmac_if_bus_setup)( void *arg );
220
221/**
222 * @brief Callback methods.
223 *
224 * The address of an instance of such a callback struct must get passed
225 * to the attach_detach method of the network driver.
226 * Via these callback methods, those parts of the network driver which
227 * are micro controller specific or PCB specific will get handled.
228 * @see dwmac_network_if_attach_detach() for the drivers attach_detach method.
229 */
230typedef struct {
231  /** @brief Enable the network interface controller. */
232  dwmac_if_nic_enable nic_enable;
233
234  /** @brief Disable the network interface controller. */
235  dwmac_if_nic_disable nic_disable;
236
237  /** @brief Enable (power up, ... ) the network PHY. */
238  dwmac_if_phy_enable phy_enable;
239
240  /** @brief Disable (power down, ... ) the network PHY. */
241  dwmac_if_phy_disable phy_disable;
242
243  /** @brief Enable a set of PHY events for generation upon status change. */
244  dwmac_if_phy_event_enable phy_event_enable;
245
246  /** @brief Clear the event status (e.g. interrupt staus) of the PHY. */
247  dwmac_if_phy_event_status_clear phy_event_clear;
248
249  /** @brief Get set of tripped events from PHY. */
250  dwmac_if_phy_events_status_get phy_events_get;
251
252  /** @brief Start the phy (start generating events, ...). */
253  dwcmac_if_phy_start phy_start;
254
255  /** @brief Stop the phy (stop generating events, ...). */
256  dwcmac_if_phy_stop phy_stop;
257
258  /** @brief Allocate uncached memory. */
259  dwmac_if_mem_alloc_nocache mem_alloc_nocache;
260
261  /** @brief Free uncached memory. */
262  dwmac_if_mem_free_nocache mem_free_nocache;
263
264  /** @brief Setup handling for bus upon device startup. */
265  dwmac_if_bus_setup bus_setup;
266} dwmac_callback_cfg;
267
268/** @brief Initializer for callback methods.
269 *
270 * Initializes a struct which contains pointers to the callback methods
271 * required by the driver.
272 * @see dwmac_callback_cfg for the struct.
273 * @param[in] nic_enable              Callback method for for enabling the
274 *                                    network interface controller.
275 * @param[in] nic_disable             Callback method for disabling the
276 *                                    network interface controller.
277 * @param[in] phy_enable              Callback method for enabling the
278 *                                    network PHY.
279 * @param[in] phy_disable             Callback method for disabling the
280 *                                    network PHY.
281 * @param[in] phy_event_enable        Callback method for enabling PHY status
282 *                                    changes for event generation.
283 * @param[in] phy_event_clear         Callback method for
284 *                                    clearing/acknowledging PHY events.
285 * @param[in] phy_events_get          Callback method for reading the status of
286 *                                    PHY events.
287 * @param[in] phy_start               Callback method for starting event
288 *                                    generation by the network PHY.
289 * @param[in] phy_stop                Callback method for stoping event
290 *                                    generation by the network PHY.
291 * @param[in] mem_alloc_nocache       Callback method for allocating uncached
292 *                                    RAM.
293 * @param[in] mem_free_nocache        Callback method for releasing uncached
294 *                                    RAM.
295 * @param[in] bus_setup               Callback method for setting up the system
296 *                                    bus.
297 * @returns An initialized struct of pointers to callback methods.
298 * @see dwmac_if_nic_enable for the NIC enable methods.
299 * @see dwmac_if_nic_disable for NIC disable methods.
300 * @see dwmac_if_phy_enable for PHY enable methods.
301 * @see dwmac_if_phy_disable for PHY disable methods.
302 * @see dwmac_if_phy_event_enable for PHY envent enable methods.
303 * @see dwmac_if_phy_event_status_clear for PHY event status clear methods.
304 * @see dwmac_if_phy_events_status_get for PHY event status get methods.
305 * @see dwcmac_if_phy_start for PHY start methods.
306 * @see dwcmac_if_phy_stop for PHY stop methods.
307 * @see dwmac_if_mem_alloc_nocache for nocache mem alloc methods.
308 * @see dwmac_if_mem_free_nocache for nocache mem free methods.
309 * @see dwmac_if_bus_setup for bus setup methods.
310 */
311#define DWMAC_CALLBACK_CFG_INITIALIZER( \
312    nic_enable, \
313    nic_disable, \
314    phy_enable, \
315    phy_disable, \
316    phy_event_enable, \
317    phy_event_clear, \
318    phy_events_get, \
319    phy_start, \
320    phy_stop, \
321    mem_alloc_nocache, \
322    mem_free_nocache, \
323    bus_setup \
324    ) \
325  { \
326    nic_enable, \
327    nic_disable, \
328    phy_enable, \
329    phy_disable, \
330    phy_event_enable, \
331    phy_event_clear, \
332    phy_events_get, \
333    phy_start, \
334    phy_stop, \
335    mem_alloc_nocache, \
336    mem_free_nocache, \
337    bus_setup \
338  }
339
340/** @brief Ethernet MAC operations.
341 *
342 * Actually this is a mere wrapper which contains void ponters to the core
343 * operations and DMA operations to be used by the driver (void pointer
344 * for the purpose of information hiding).
345 * There will be two instances of such a struct:
346 * One for DWMAC 10/100 ethernet operations and one for DWMAC 1000 ethernet
347 * operations.
348 * The address of either of these must get passed to the initializer of the
349 * driver configuration  for configuring the driver.
350 * @see DWMAC_100_ETHERNET_MAC_OPS for DWMAC 10/100 ethernet operations.
351 * @see DWMAC_1000_ETHERNET_MAC_OPS for DWMAC 1000 ethernet operations.
352 * @see DWMAC_CFG_INITIALIZER driver configuration initializer.
353 * @see DWMAC_ETHERNET_MAC_OPS_INITIALIZER for an initializer for the MAC
354 * operations
355 */
356typedef struct {
357  const void *core;
358  const void *dma;
359} dwmac_ethernet_mac_ops;
360
361/** @brief Ethernet MAC operations initializer.
362 *
363 * Initializes a structure of ethernet MAC operations.
364 * @see dwmac_ethernet_mac_ops for the struct.
365 * @param[in] core_ops_addr Address of the core operations to be used by the
366 *                          driver.
367 * @param[in] dma_ops_addr  Address of the DMA operations to be used by the
368 *                          driver.
369 * @returns An initialized struct of ethernet mac operations.
370 */
371#define DWMAC_ETHERNET_MAC_OPS_INITIALIZER( \
372    core_ops_addr, \
373    dma_ops_addr \
374    ) \
375  { \
376    core_ops_addr, \
377    dma_ops_addr \
378  }
379
380/** @brief Descriptor operations.
381 *
382 * Actually this is a mere wrapper which contains a void pointer to a
383 * descriptor operations struct which can be used by the driver (void pointer
384 * for the purpose of information hiding).
385 * There will be two instances of such a struct:
386 * One for normal DMA descriptors and one for enhanced DMA descriptors.
387 * The address of either of these must get passed to the configuration
388 * initializer for configuring the driver.
389 * @see DWMAC_DESCRIPTOR_OPS_NORMAL for normal DMA descriptor operations.
390 * @see DWMAC_DESCRIPTOR_OPS_ENHANCED for enhanced DMA descriptor operations.
391 * @see DWMAC_CFG_INITIALIZER for the configuration initializer.
392 * @see DWMAC_DESCRIPTOR_OPS_INITIALIZER for an initializer an initializer
393 * for descriptor operations.
394 */
395typedef struct {
396  /** @brief Address of the descriptor operations to be used by the driver */
397  const void *ops;
398} dwmac_descriptor_ops;
399
400/** @brief Initializer for descriptor operations.
401 *
402 * Initializes a struct which simply makes up a wrapper for DMA descriptor
403 * operations.
404 * @param[in] desc_ops_addr Address of the descriptor operations.
405 * @returns an initialized descriptor operations struct.
406 * @see dwmac_descriptor_ops for the struct.
407 */
408#define DWMAC_DESCRIPTOR_OPS_INITIALIZER( \
409    desc_ops_addr \
410    ) \
411  { \
412    desc_ops_addr \
413  }
414
415/** @brief Ethernet MAC operations for DWMAC 1000.
416 *
417 * Pass the address of DWMAC_1000_ETHERNET_MAC_OPS to the configuration
418 * initializer if the driver is supposed to control a DWMAC 1000.
419 * @see DWMAC_CFG_INITIALIZER for the configuration initializer.
420 */
421extern const dwmac_ethernet_mac_ops DWMAC_1000_ETHERNET_MAC_OPS;
422
423/** @brief Ethernet MAC operations for DWMAC 10/100.
424 *
425 * Pass the address of DWMAC_100_ETHERNET_MAC_OPS to the configuration
426 * initializer if the driver is supposed to control a DWMAC 10/100.
427 * NOTE: Currently the DWMAC_100_ETHERNET_MAC_OPS are not yet implemented.
428 * @see DWMAC_CFG_INITIALIZER for the configuration initializer.
429 */
430extern const dwmac_ethernet_mac_ops DWMAC_100_ETHERNET_MAC_OPS;
431
432/** @brief DMA descriptor operations for normal descriptors.
433 *
434 * Pass the address of DWMAC_DESCRIPTOR_OPS_NORMAL to the configuration
435 * initializer if you intend to use the normal DMA descriptors.
436 * NOTE: Currently the DWMAC_DESCRIPTOR_OPS_NORMAL are not yet implmented.
437 * @see DWMAC_CFG_INITIALIZER for the configuration initializer.
438 */
439extern const dwmac_descriptor_ops   DWMAC_DESCRIPTOR_OPS_NORMAL;
440
441/** @brief DMA descriptor operations for enhanced descriptors.
442 *
443 * Pass the address of DWMAC_DESCRIPTOR_OPS_ENHANCED to the configuration
444 * initializer if you intend to use the enhanced DMA descriptors.
445 * @see DWMAC_CFG_INITIALIZER for the configuration initializer.
446 */
447extern const dwmac_descriptor_ops DWMAC_DESCRIPTOR_OPS_ENHANCED;
448
449/** @brief Burst size. */
450typedef enum {
451  /** @brief Burst size = 1. */
452  DWMAC_DMA_CFG_BUS_MODE_BURST_LENGTH_1 = 0,
453
454  /** @brief Burst size = 2. */
455  DWMAC_DMA_CFG_BUS_MODE_BURST_LENGTH_2 = 1,
456
457  /** @brief Burst size = 4. */
458  DWMAC_DMA_CFG_BUS_MODE_BURST_LENGTH_4 = 3,
459
460  /** @brief Burst size = 8. */
461  DWMAC_DMA_CFG_BUS_MODE_BURST_LENGTH_8 = 7,
462
463  /** @brief Burst size = 16. */
464  DWMAC_DMA_CFG_BUS_MODE_BURST_LENGTH_16 = 15,
465
466  /** @brief Burst size = 32. */
467  DWMAC_DMA_CFG_BUS_MODE_BURST_LENGTH_32 = 31,
468
469  /** @brief Burst size = 64. */
470  DWMAC_DMA_CFG_BUS_MODE_BURST_LENGTH_64 = 63,
471
472  /** @brief Burst size = 128. */
473  DWMAC_DMA_CFG_BUS_MODE_BURST_LENGTH_128 = 127,
474
475  /** @brief Burst size = 256. */
476  DWMAC_DMA_CFG_BUS_MODE_BURST_LENGTH_256 = 255
477} dwmac_dma_cfg_bus_mode_burst_length;
478
479/** @brief Burst mode. */
480typedef enum {
481  /** @brief Single burst or incrment bursts. */
482  DWMAC_DMA_CFG_BUS_MODE_BURST_MODE_SINGLE_OR_INCR,
483
484  /** @brief Fixed burst size. */
485  DWMAC_DMA_CFG_BUS_MODE_BURST_MODE_FIXED
486} dwmac_dma_cfg_bus_mode_burst_mode;
487
488/** @brief Mixed burst mode support. */
489typedef enum {
490  /** @brief Mixed burst mode is not supported. */
491  DWMAC_DMA_CFG_BUS_MODE_BURST_NOT_MIXED,
492  /** @brief Mixed burst mode is supported. */
493  DWMAC_DMA_CFG_BUS_MODE_BURST_MIXED
494} dwmac_dma_cfg_bus_mode_burst_mixed;
495
496/** @brief Burst length 4 support. */
497typedef enum {
498  /** @brief Bursts of length 4 are not supported. */
499  DWMAC_DMA_CFG_AXI_BURST_LENGTH_4_NOT_SUPPORTED,
500
501  /** @brief Bursts of length 4 are supported. */
502  DWMAC_DMA_CFG_AXI_BURST_LENGTH_4_SUPPORTED
503} dwmac_dma_cfg_axi_burst_length_4_support;
504
505/** @brief Burst length 8 support. */
506typedef enum {
507  /** @brief Bursts of length 8 are not supported. */
508  DWMAC_DMA_CFG_AXI_BURST_LENGTH_8_NOT_SUPPORTED,
509
510  /** @brief Bursts of length 8 are supported. */
511  DWMAC_DMA_CFG_AXI_BURST_LENGTH_8_SUPPORTED
512} dwmac_dma_cfg_axi_burst_length_8_support;
513
514/** @brief Burst length 16 support. */
515typedef enum {
516  /** @brief Bursts of length 16 are not supported. */
517  DWMAC_DMA_CFG_AXI_BURST_LENGTH_16_NOT_SUPPORTED,
518
519  /** @brief Bursts of length 16 are supported. */
520  DWMAC_DMA_CFG_AXI_BURST_LENGTH_16_SUPPORTED
521} dwmac_dma_cfg_axi_burst_length_16_support;
522
523/** @brief DMA Burst Boundary parameters. */
524typedef enum {
525  /** @brief Transfers do not cross 4 kB boundary. */
526  DWMAC_DMA_CFG_AXI_BURST_BOUNDARY_4_KB,
527
528  /** @brief Transfers do not cross 1 kB boundary. */
529  DWMAC_DMA_CFG_AXI_BURST_BOUNDARY_1_KB
530} dwmac_dma_cfg_axi_burst_boundary;
531
532/**
533 * @brief DMA configuration.
534 *
535 * Configuration data for the DMA of the network driver.
536 * @see DWMAC_DMA_CFG_INITIALIZER for an inititializer.
537 */
538typedef union {
539  uint16_t raw;
540  struct {
541    /** @brief Maximum number of beats to be transferred in one DMA transaction.
542     *
543     * This is the maximum value that is used in a single block Read or Write.
544     * The DMA always attempts to burst as specified in bus_mode_burst_length
545     * each time it starts a Burst transfer on the host bus.
546     * Any non-permissible value results in undefined behavior.
547     * The bus_mode_burst_length values have the following limitation:
548     * The maximum number of possible beats (bus_mode_burst_length) is limited
549     * by the size of the Tx FIFO and Rx FIFO in the MTL layer and the data bus
550     * width on the DMA.
551     * The FIFO has a constraint that the maximum beat supported is half the
552     * depth of the FIFO, except when specified.
553     * @see dwmac_dma_cfg_bus_mode_burst_length for permissible values */
554    uint16_t bus_mode_burst_length       : 6;
555
556    /** @brief Controls whether the AXI Master performs fixed bursts or not.
557     *
558     * When set to DWMAC_DMA_CFG_BUS_MODE_BURST_MODE_FIXED, the AXI interface
559     * uses FIXED bursts during the start of the normal burst transfers.
560     * When set to DWMAC_DMA_CFG_BUS_MODE_BURST_MODE_SINGLE_OR_INCR, the AXI
561     * interface uses SINGLE and INCR burst transfer operations.
562     * @see dwmac_dma_cfg_bus_mode_burst_mode for valid parameters. */
563    uint16_t bus_mode_burst_mode         : 1;
564
565    /** @brief Controls whether mixed bursts will be used or not.
566     *
567     * Mixed burst has no effect when if DWMAC_DMA_CFG_BUS_MODE_BURST_MODE_FIXED is set.
568     * @see dwmac_dma_cfg_bus_mode_burst_mixed for valid parameters. */
569    uint16_t bus_mode_burst_mixed        : 1;
570
571    /** @brief Controls support of burst length 4.
572     *
573     * When set to DWMAC_DMA_CFG_AXI_BURST_LENGTH_4_SUPPORTED, the GMAC-AXI is
574     * allowed to select a burst length of 4 on the AXI Master interface.
575     * @see dwmac_dma_cfg_axi_burst_length_4_support for valid parameters see. */
576    uint16_t axi_burst_length_4_support  : 1;
577
578    /** @brief Controls support of burst length 8.
579     *
580     * When set to DWMAC_DMA_CFG_AXI_BURST_LENGTH_8_SUPPORTED, the GMAC-AXI is
581     * allowed to select a burst length of 8 on the AXI Master interface.
582     * @see dwmac_dma_cfg_axi_burst_length_8_support For valid parameters. */
583    uint16_t axi_burst_length_8_support  : 1;
584
585    /** @brief Controls support of burst length 16.
586     *
587     * When set to DWMAC_DMA_CFG_AXI_BURST_LENGTH_16_SUPPORTED fixed bust is
588     * not selected, the GMAC-AXI is allowed to select a burst length of 16 on
589     * the AXI Master interface.
590     * @see dwmac_dma_cfg_axi_burst_length_16_support for valid parameters see. */
591    uint16_t axi_burst_length_16_support : 1;
592
593    /** @brief Select Burst Boundary.
594     *
595     * When set to DWMAC_DMA_CFG_AXI_BURST_BOUNDARY_1_KB, the GMAC-AXI Master
596     * performs burst transfers that do not cross 1 KB boundary.
597     * When set to DWMAC_DMA_CFG_AXI_BURST_BOUNDARY_4_KB, the GMAC-AXI Master
598     * performs burst transfers that do not cross 4 KB boundary.
599     * @see dwmac_dma_cfg_axi_burst_boundary for valid parameters see. */
600    uint16_t axi_burst_boundary          : 1;
601
602    uint16_t unused                      : 4;
603  };
604} dwmac_dma_cfg;
605
606/** @brief DMA Configuration initializer.
607 *
608 * Initializer for a DMA configuration struct.
609 *
610 * @param[in] bus_mode_burst_length       Number of bytes to be sent in one
611 *                                        burst within a DMA transfer on the
612 *                                        bus .
613 * @param[in] bus_mode_burst_mode         Mode to be used for burst transfers.
614 * @param[in] bus_mode_burst_mixed        Use mixed bursts or not. Fixed bursts
615 *                                        have priority over mixed bursts.
616 * @param[in] axi_burst_length_4_support  Support or don't support burst
617 *                                        lengths of 4.
618 * @param[in] axi_burst_length_8_support  Support or don't support burst
619 *                                        lengths of 8.
620 * @param[in] axi_burst_length_16_support Support or don't support burst
621 *                                        lengths of 16.
622 * @param[in] axi_burst_boundary          Select the burst boundary.
623 * @returns An initialized struct of DMA configuration parameters.
624 * @see dwmac_dma_cfg_bus_mode_burst_length for burst lengths.
625 * @see dwmac_dma_cfg_bus_mode_burst_mode for burst modes
626 * @see dwmac_dma_cfg_bus_mode_burst_mixed for burst mixing.
627 * @see dwmac_dma_cfg_axi_burst_length_4_support for burst length 4 support.
628 * @see dwmac_dma_cfg_axi_burst_length_8_support for burst length 8 support.
629 * @see dwmac_dma_cfg_axi_burst_length_16_support for burst length 16 support.
630 * @see dwmac_dma_cfg_axi_burst_boundary for burst boundaries.
631 */
632#define DWMAC_DMA_CFG_INITIALIZER( \
633    bus_mode_burst_length, \
634    bus_mode_burst_mode, \
635    bus_mode_burst_mixed, \
636    axi_burst_length_4_support, \
637    axi_burst_length_8_support, \
638    axi_burst_length_16_support, \
639    axi_burst_boundary \
640    ) \
641  { \
642    BSP_FLD16( bus_mode_burst_length, 0, 5 ) \
643    | BSP_FLD16( bus_mode_burst_mode, 6, 6 ) \
644    | BSP_FLD16( bus_mode_burst_mixed, 7, 7 ) \
645    | BSP_FLD16( axi_burst_length_4_support, 8, 8 ) \
646    | BSP_FLD16( axi_burst_length_8_support, 9, 9 ) \
647    | BSP_FLD16( axi_burst_length_16_support, 10, 10 ) \
648    | BSP_FLD16( axi_burst_boundary, 11, 11 ) \
649  }
650
651/**
652 * @brief Driver configuration.
653 *
654 * Configuration data for the network driver.
655 * See @see DWMAC_CFG_INITIALIZER for an initializer.
656 */
657typedef struct {
658  /** @brief The clock to be used for the gmii interface in Hz. */
659  const uint32_t GMII_CLK_RATE;
660
661  /** @brief Start address of the MAC group registers. */
662  volatile void *addr_gmac_regs;
663
664  /** @brief Start address of the DMA group registers. */
665  volatile void *addr_dma_regs;
666
667  /** @brief Address of the PHY on the mdio bus (5 bit). */
668  const uint8_t MDIO_BUS_ADDR;
669
670  /** @brief Bytes per L1 cache line. */
671  const uint8_t L1_CACHE_LINE_SIZE;
672
673  /** @brief Interrupt vector number for EMAC IRQs. */
674  const rtems_vector_number IRQ_EMAC;
675
676  /** @brief Optional configuration for bus mode and axi bus mode. */
677  const dwmac_dma_cfg *DMA_CFG;
678
679  /** @brief Methods which must get provided to the by the micro controller. */
680  const dwmac_callback_cfg CALLBACK;
681
682  /** @brief Operations which are specific to the ethernet MAC. */
683  const dwmac_ethernet_mac_ops *MAC_OPS;
684
685  /** @brief DMA descriptor operations. */
686  const dwmac_descriptor_ops *DESC_OPS;
687} dwmac_cfg;
688
689/**
690 * @brief Configuration initializer.
691 *
692 * Initializes the configuration data to be passed to
693 * the initialization method.
694 * @see dwmac_network_if_attach_detach().
695 *
696 * @param[in] mdio_clk_rate           The clock to be used for the gmii
697 *                                    interface in Hz.
698 * @param[in] macgrp_regs_addr        Base address of the MAC group registers.
699 * @param[in] dmagrp_regs_addr        Base address of the DMA group registers.
700 * @param[in] mdio_bus_addr           Address of the network PHY on the
701 *                                    mdio bus.
702 * @param[in] l1_cache_line_size      Size of a cache line in the level 1 cache.
703 * @param[in] irq_emac                Number of the EMAC interrupt.
704 * @param[in] arch_has_prefetch       True if architecture supports.
705 *                                    prefetching, false if not.
706 * @param[in] dma_cfg_addr            Address of the optional DMA configuration.
707 *                                    Set to NULL for defaults.
708 * @param[in] nic_enable              Callback method for for enabling the
709 *                                    network interface controller.
710 * @param[in] nic_disable             Callback method for disabling the
711 *                                    network interface controller.
712 * @param[in] phy_enable              Callback method for enabling the
713 *                                    network PHY.
714 * @param[in] phy_disable             Callback method for disabling the
715 *                                    network PHY.
716 * @param[in] phy_event_enable        Callback method for enabling PHY status
717 *                                    changes for event generation.
718 * @param[in] phy_event_clear         Callback method for
719 *                                    clearing/acknowledging PHY events.
720 * @param[in] phy_events_get          Callback method for reading the status of
721 *                                    PHY events.
722 * @param[in] phy_start               Callback method for starting event
723 *                                    generation by the network PHY.
724 * @param[in] phy_stop                Callback method for stoping event
725 *                                    generation by the network PHY.
726 * @param[in] mem_alloc_nocache       Callback method for allocating uncached
727 *                                    RAM.
728 * @param[in] mem_free_nocache        Callback method for releasing uncached
729 *                                    RAM.
730 * @param[in] bus_setup               Callback method for setting up the system
731 *                                    bus.
732 * @param[in] ethernet_mac_ops_addr   Address of a struct encapsulating
733 *                                    ethernet MAC operations for DWMAC 1000 or
734 *                                    DWMAC 10/100.
735 * @param[in] descriptor_ops_addr     Address of a struct encasulating DMA
736 *                                    descriptor operations for either normal
737 *                                    descriptors or enhanced descriptors.
738 * @returns An initialized struct of configuration parameters.
739 * @see dwmac_cfg for the struct returned.
740 * @see dwmac_dma_cfg for DMA configurations.
741 * @see dwmac_if_nic_enable for NIC enable methods.
742 * @see dwmac_if_nic_disable for NIC disable methods.
743 * @see dwmac_if_phy_enable for PHY enable methods.
744 * @see dwmac_if_phy_disable for PHY disable methods.
745 * @see dwmac_if_phy_event_enable for PHY event enble methods.
746 * @see dwmac_if_phy_event_status_clear for PHY status clear methods.
747 * @see dwmac_if_phy_events_status_get for PHY status get mehods.
748 * @see dwcmac_if_phy_start for PHY start methods.
749 * @see dwcmac_if_phy_stop for PHY stop methods.
750 * @see dwmac_if_mem_alloc_nocache for nocache memory allocate methods.
751 * @see dwmac_if_mem_free_nocache for nocache memory release methods.
752 * @see dwmac_if_bus_setup for bus setup methods.
753 * @see DWMAC_1000_ETHERNET_MAC_OPS for DWMAC 1000 MAC operations.
754 * @see DWMAC_100_ETHERNET_MAC_OPS for DWMAC 10/100 MAC operations.
755 * @see DWMAC_DESCRIPTOR_OPS_NORMAL for normal DMA descriptor operations.
756 * @see DWMAC_DESCRIPTOR_OPS_ENHANCED for enhanced DMA descriptor operations.
757 */
758#define DWMAC_CFG_INITIALIZER( \
759    mdio_clk_rate, \
760    macgrp_regs_addr, \
761    dmagrp_regs_addr, \
762    mdio_bus_addr, \
763    l1_cache_line_size, \
764    irq_emac, \
765    dma_cfg_addr, \
766    nic_enable, \
767    nic_disable, \
768    phy_enable, \
769    phy_disable, \
770    phy_event_enable, \
771    phy_event_clear, \
772    phy_events_get, \
773    phy_start, \
774    phy_stop, \
775    mem_alloc_nocache, \
776    mem_free_nocache, \
777    bus_setup, \
778    ethernet_mac_ops_addr, \
779    descriptor_ops_addr \
780    ) \
781  { \
782    mdio_clk_rate, \
783    macgrp_regs_addr, \
784    dmagrp_regs_addr, \
785    mdio_bus_addr, \
786    l1_cache_line_size, \
787    irq_emac, \
788    dma_cfg_addr, \
789    DWMAC_CALLBACK_CFG_INITIALIZER( \
790      nic_enable, \
791      nic_disable, \
792      phy_enable, \
793      phy_disable, \
794      phy_event_enable, \
795      phy_event_clear, \
796      phy_events_get, \
797      phy_start, \
798      phy_stop, \
799      mem_alloc_nocache, \
800      mem_free_nocache, \
801      bus_setup \
802      ), \
803    ethernet_mac_ops_addr, \
804    descriptor_ops_addr \
805  }
806
807/**
808 * @brief Initialization method.
809 *
810 * Initializes the network driver and "links" it to the network stack.
811 *
812 * @param[in]  bsd_config     The BSD configuation passed to all
813 *                            network_if_attach_detach() methods.
814 * @param[in]  driver_config  Address of of a struct containing driver
815 *                            specific configuration data.
816 * @param[in]  arg            An optional argument which will get passed to all
817 *                            callback methods.
818 * @param[in]  attaching      1 for attching and 0 for detaching.
819 *                            NOTE: Detaching is not supported!
820 * @returns Address of the drivers context if successful or NULL if not
821 *          successful.
822 * @see dwmac_cfg for the driver configuration struct
823 * @see DWMAC_CFG_INITIALIZER() for an initializer for the driver configuration
824 */
825void *dwmac_network_if_attach_detach(
826  struct rtems_bsdnet_ifconfig *bsd_config,
827  const dwmac_cfg              *driver_config,
828  void                         *arg,
829  int                           attaching );
830
831/**
832 * @brief Read from PHY
833 *
834 * Read a value from a register of the network PHY.
835 *
836 * @param[in,out] arg     Pointer returned from the attach_detach method.
837 * @param[in]     phy_reg The PHY register to be read from.
838 * @param[out]    val     Buffer address for the value to be read.
839 * @returns 0 on success, error code from errno.h on failure.
840 * @see dwmac_network_if_attach_detach() for the attach detach method.
841 */
842int dwmac_if_read_from_phy(
843  void          *arg,
844  const unsigned phy_reg,
845  uint16_t      *val );
846
847/**
848 * @brief Write to PHY.
849 *
850 * Write a value to a register of the network PHY.
851 *
852 * @param[in,out] arg     Pointer returned from the attach_detach method.
853 * @param[in]     phy_reg The PHY register to be written to.
854 * @param[in]     val     The value to be written.
855 * @returns 0 on success, error code from errno.h on failure.
856 * @see dwmac_network_if_attach_detach() for the attach_detach method.
857 */
858int dwmac_if_write_to_phy(
859  void          *arg,
860  const unsigned phy_reg,
861  const uint16_t val );
862
863/**
864 * @brief Handle PHY event.
865 *
866 * Handle an event from the network PHY.
867 *
868 * @param[in,out] arg Pointer returned from the attach_detach method.
869 * @returns 0 on success, error code from errno.h on failure.
870 * @see dwmac_network_if_attach_detach() for the attach_detach method.
871 */
872int dwmac_if_handle_phy_event( void *arg );
873
874#ifdef __cplusplus
875}
876#endif /* __cplusplus */
877
878#endif /* DWMAC_H_ */
Note: See TracBrowser for help on using the repository browser.