1 /* ----------------------------------------------------------------------------
\r
2 * SAM Software Package License
\r
3 * ----------------------------------------------------------------------------
\r
4 * Copyright (c) 2015, Atmel Corporation
\r
6 * All rights reserved.
\r
8 * Redistribution and use in source and binary forms, with or without
\r
9 * modification, are permitted provided that the following conditions are met:
\r
11 * - Redistributions of source code must retain the above copyright notice,
\r
12 * this list of conditions and the disclaimer below.
\r
14 * Atmel's name may not be used to endorse or promote products derived from
\r
15 * this software without specific prior written permission.
\r
17 * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
\r
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
\r
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
\r
20 * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
\r
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
\r
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
\r
23 * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
\r
24 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
\r
25 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
\r
26 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
\r
27 * ----------------------------------------------------------------------------
\r
32 /** \addtogroup gmac_module
\r
34 * Provides the interface to configure and use the GMAC peripheral.
\r
36 * \section gmac_usage Usage
\r
37 * - Configure Gmac::GMAC_NCFG with gmac_configure(), some of related controls
\r
38 * are also available, such as:
\r
39 * - gmac_set_link_speed(): Setup GMAC working clock.
\r
40 * - gmac_full_duplex_enable(): Working in full duplex or not.
\r
41 * - gmac_cpy_all_enable(): Copying all valid frames (\ref GMAC_NCFG_CAF).
\r
43 * - Setup Gmac::GMAC_NCR with gmac_network_control(), more related controls
\r
45 * - gmac_receive_enable(): Enable/Disable Rx.
\r
46 * - gmac_transmit_enable(): Enable/Disable Tx.
\r
47 * - gmac_broadcast_disable(): Enable/Disable broadcast receiving.
\r
49 * - Manage GMAC interrupts with GMAC_EnableIt(), gmac_disable_it(),
\r
50 * gmac_get_it_mask() and gmac_get_it_status().
\r
51 * - Manage GMAC Tx/Rx status with gmac_get_tx_status(), gmac_get_rx_status()
\r
52 * gmac_clear_tx_status() and gmac_clear_rx_status().
\r
53 * - Manage GMAC Queue with gmac_set_tx_queue(), GMAC_GetTxQueue(),
\r
54 * gmac_set_rx_queue() and GMAC_GetRxQueue(), the queue descriptor can define
\r
55 * by \ref _gmac_rx_descriptor and \ref _gmac_tx_descriptor.
\r
56 * - Manage PHY through GMAC is performed by
\r
57 * - gmac_management_enable(): Enable/Disable PHY management.
\r
58 * - gmac_phy_maintain(): Execute PHY management commands.
\r
59 * - gmac_phy_data(): Return PHY management data.
\r
60 * - gmac_is_idle(): Check if PHY is idle.
\r
61 * - Setup GMAC parameters with following functions:
\r
62 * - gmac_set_hash(): Set Hash value.
\r
63 * - gmac_set_address(): Set MAC address.
\r
64 * - Enable/Disable GMAC transceiver clock via GMAC_TransceiverClockEnable()
\r
65 * - Switch GMAC MII/RMII mode through gmac_enable_rgmii()
\r
67 * For more accurate information, please look at the GMAC section of the
\r
70 * \sa \ref gmacd_module
\r
76 * \defgroup gmac_defines GMAC Defines
\r
77 * \defgroup gmac_structs GMAC Data Structs
\r
78 * \defgroup gmac_functions GMAC Functions
\r
85 /*----------------------------------------------------------------------------
\r
87 *----------------------------------------------------------------------------*/
\r
91 #include <stdbool.h>
\r
94 /*----------------------------------------------------------------------------
\r
96 *----------------------------------------------------------------------------*/
\r
98 /** \addtogroup gmac_defines
\r
101 #ifdef CONFIG_HAVE_GMAC_QUEUES
\r
102 #define GMAC_NUM_QUEUES 3
\r
104 #define GMAC_NUM_QUEUES 1
\r
107 #define GMAC_MAX_FRAME_LENGTH 1536
\r
108 #define GMAC_MAX_JUMBO_FRAME_LENGTH 10240
\r
110 enum _gmac_duplex {
\r
111 GMAC_DUPLEX_HALF = 0,
\r
112 GMAC_DUPLEX_FULL = 1,
\r
116 GMAC_SPEED_10M = 0,
\r
117 GMAC_SPEED_100M = 1,
\r
120 /* Bits contained in struct _gmac_desc addr when used for RX*/
\r
121 #define GMAC_RX_ADDR_OWN (1u << 0)
\r
122 #define GMAC_RX_ADDR_WRAP (1u << 1)
\r
123 #define GMAC_RX_ADDR_MASK 0xfffffffcu
\r
125 /* Bits contained in struct _gmac_desc status when used for RX */
\r
126 #define GMAC_RX_STATUS_LENGTH_MASK 0x3fffu
\r
127 #define GMAC_RX_STATUS_SOF (1u << 14)
\r
128 #define GMAC_RX_STATUS_EOF (1u << 15)
\r
130 /* Bits contained in struct _gmac_desc status when used for TX */
\r
131 #define GMAC_TX_STATUS_LASTBUF (1u << 15)
\r
132 #define GMAC_TX_STATUS_WRAP (1u << 30)
\r
133 #define GMAC_TX_STATUS_USED (1u << 31)
\r
137 /*----------------------------------------------------------------------------
\r
139 *----------------------------------------------------------------------------*/
\r
141 /** \addtogroup gmac_structs
\r
144 /** Transmit/Receive buffer descriptor struct */
\r
145 struct _gmac_desc {
\r
152 /*----------------------------------------------------------------------------
\r
153 * Exported functions
\r
154 *----------------------------------------------------------------------------*/
\r
163 extern bool gmac_configure(Gmac *gmac);
\r
166 * \brief Write NCR register value
\r
168 extern void gmac_set_network_control_register(Gmac * gmac, uint32_t ncr);
\r
171 * \brief Get NCR register value
\r
173 extern uint32_t gmac_get_network_control_register(Gmac * gmac);
\r
176 * \brief Set network configuration register
\r
178 extern void gmac_set_network_config_register(Gmac* gmac, uint32_t ncfgr);
\r
181 * \brief Get network configuration register
\r
184 extern uint32_t gmac_get_network_config_register(Gmac* gmac);
\r
187 * \brief Enable MDI with PHY
\r
188 * \param gmac Pointer to an Gmac instance.
\r
190 extern void gmac_enable_mdio(Gmac* gmac);
\r
193 * \brief Disable MDI with PHY
\r
194 * \param gmac Pointer to an Gmac instance.
\r
196 extern void gmac_disable_mdio(Gmac* gmac);
\r
199 * \brief Execute PHY read command
\r
201 extern bool gmac_phy_read(Gmac* gmac, uint8_t phy_addr, uint8_t reg_addr,
\r
202 uint16_t* data, uint32_t retries);
\r
205 * \brief Execute PHY write command
\r
207 extern bool gmac_phy_write(Gmac* gmac, uint8_t phy_addr, uint8_t reg_addr,
\r
208 uint16_t data, uint32_t retries);
\r
211 * \brief Enable MII mode for GMAC, called once after autonegotiate
\r
212 * \param gmac Pointer to an Gmac instance.
\r
214 extern void gmac_enable_mii(Gmac* gmac);
\r
217 * \brief Enable RMII mode for GMAC, called once after autonegotiate
\r
218 * \param gmac Pointer to an Gmac instance.
\r
219 * \param duplex: 1 full duplex 0 half duplex
\r
220 * \param speed: 0 10M 1 100M
\r
222 extern void gmac_enable_rmii(Gmac* gmac, enum _gmac_speed speed,
\r
223 enum _gmac_duplex duplex);
\r
226 * \brief Setup the GMAC for the link : speed 100M/10M and Full/Half duplex
\r
227 * \param gmac Pointer to an Gmac instance.
\r
228 * \param speed Link speed, 0 for 10M, 1 for 100M
\r
229 * \param fullduplex 1 for Full Duplex mode
\r
231 extern void gmac_set_link_speed(Gmac* gmac, enum _gmac_speed speed,
\r
232 enum _gmac_duplex duplex);
\r
235 * \brief Enable local loop back
\r
236 * \param gmac Pointer to an Gmac instance.
\r
238 extern void gmac_enable_local_loopback(Gmac* gmac);
\r
241 * \brief Disable local loop back
\r
242 * \param gmac Pointer to an Gmac instance.
\r
244 extern void gmac_disable_local_loopback(Gmac* gmac);
\r
247 * \brief Return transmit status
\r
249 extern uint32_t gmac_get_tx_status(Gmac* gmac);
\r
252 * \brief Clear transmit status
\r
254 extern void gmac_clear_tx_status(Gmac* gmac, uint32_t mask);
\r
257 * \brief Return receive status
\r
259 extern uint32_t gmac_get_rx_status(Gmac* gmac);
\r
262 * \brief Clear receive status
\r
264 extern void gmac_clear_rx_status(Gmac* gmac, uint32_t mask);
\r
267 * \brief Enable/Disable GMAC receive.
\r
269 extern void gmac_receive_enable(Gmac* gmac, bool enable);
\r
272 * \brief Enable/Disable GMAC transmit.
\r
274 extern void gmac_transmit_enable(Gmac* gmac, bool enable);
\r
277 * \brief Set RX descriptor address
\r
279 void gmac_set_rx_desc(Gmac* gmac, uint8_t queue, struct _gmac_desc* desc);
\r
282 * \brief Get RX descriptor address
\r
284 struct _gmac_desc* gmac_get_rx_desc(Gmac* gmac, uint8_t queue);
\r
287 * \brief Set TX descriptor address
\r
289 void gmac_set_tx_desc(Gmac* gmac, uint8_t queue, struct _gmac_desc* desc);
\r
292 * \brief Get TX descriptor address
\r
294 struct _gmac_desc* gmac_get_tx_desc(Gmac* gmac, uint8_t queue);
\r
297 * \brief Return interrupt mask.
\r
299 extern uint32_t gmac_get_it_mask(Gmac* gmac, uint8_t queue);
\r
302 * \brief Enable interrupt(s).
\r
304 extern void gmac_enable_it(Gmac* gmac, uint8_t queue, uint32_t mask);
\r
307 * \brief Disable interrupt(s).
\r
309 extern void gmac_disable_it(Gmac * gmac, uint8_t queue, uint32_t mask);
\r
312 * \brief Return interrupt status mask.
\r
314 extern uint32_t gmac_get_it_status(Gmac* gmac, uint8_t queue);
\r
317 * \brief Set MAC Address
\r
319 extern void gmac_set_mac_addr(Gmac* gmac, uint8_t sa_idx, uint8_t* mac);
\r
322 * \brief Set MAC Address using two 32-bit integers
\r
324 extern void gmac_set_mac_addr32(Gmac* gmac, uint8_t sa_idx,
\r
325 uint32_t mac_top, uint32_t mac_bottom);
\r
328 * \brief Set MAC Address using a 64-bit integer
\r
330 extern void gmac_set_mac_addr64(Gmac* gmac, uint8_t sa_idx, uint64_t mac);
\r
333 * \brief Clear all statistics registers
\r
335 extern void gmac_clear_statistics(Gmac* gmac);
\r
338 * \brief Increase all statistics registers
\r
340 extern void gmac_increase_statistics(Gmac* gmac);
\r
343 * \brief Enable/Disable statistics registers writing.
\r
345 extern void gmac_enable_statistics_write(Gmac* gmac, bool enable);
\r
348 * \brief Start transmission
\r
350 extern void gmac_start_transmission(Gmac* gmac);
\r
353 * \brief Halt transmission
\r
355 extern void gmac_halt_transmission(Gmac* gmac);
\r
361 #endif /* _GMAC_H_ */
\r