source: rtems/c/src/libchip/network/dwmac.h @ 602e395

4.115
Last change on this file since 602e395 was d5f5432, checked in by Christian Mauderer <Christian.Mauderer@…>, on 08/22/14 at 06:53:10

libchip/dwmac: Make PHY address user configurable

This patch allows the user to configure the PHY address for the DWMAC
driver by giving a pointer to a dwmac_user_cfg structure to network
stack via rtems_bsdnet_ifconfig::drv_ctrl.

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