1 /***************************************************************************//**
\r
3 * SmartFusion MSS Ethernet MAC header file.
\r
5 * (c) Copyright 2007 Actel Corporation
\r
7 * SVN $Revision: 2364 $
\r
8 * SVN $Date: 2010-03-01 17:58:41 +0000 (Mon, 01 Mar 2010) $
\r
10 *******************************************************************************/
\r
12 #ifndef __MSS_ETHERNET_MAC_H
\r
13 #define __MSS_ETHERNET_MAC_H 1
\r
21 /******************************** DEFINES *************************************/
\r
23 /*******************************************************************************
\r
28 * When set, all incoming frames are received, regardless of their destination address.
\r
29 * An address check is performed, and the result of the check is written into the receive
\r
32 #define MSS_MAC_CFG_RECEIVE_ALL 0x00000001u
\r
35 * Transmit threshold mode.
\r
36 * 1 - Transmit FIFO threshold set for 100 Mbps mode
\r
37 * 0 - Transmit FIFO threshold set for 10 Mbps mode
\r
38 * This bit can be changed only when a transmit process is in a stopped state.
\r
40 #define MSS_MAC_CFG_TRANSMIT_THRESHOLD_MODE 0x00000002u
\r
43 * Store and forward.
\r
44 * When set, the transmission starts after a full packet is written into the transmit
\r
45 * FIFO, regardless of the current FIFO threshold level.
\r
46 * This bit can be changed only when the transmit process is in the stopped state.
\r
48 #define MSS_MAC_CFG_STORE_AND_FORWARD 0x00000004u
\r
51 * Threshold control bits.
\r
52 * These bits, together with TTM, SF, and PS, control the threshold level for the
\r
55 #define MSS_MAC_CFG_THRESHOLD_CONTROL_00 0x00000000u
\r
56 #define MSS_MAC_CFG_THRESHOLD_CONTROL_01 0x00000008u
\r
57 #define MSS_MAC_CFG_THRESHOLD_CONTROL_10 0x00000010u
\r
58 #define MSS_MAC_CFG_THRESHOLD_CONTROL_11 0x00000018u
\r
62 * 0 - Half-duplex mode <br>
\r
63 * 1 - Forcing full-duplex mode <br>
\r
64 * Changing of this bit is allowed only when both the transmitter and receiver processes
\r
65 * are in the stopped state.
\r
67 #define MSS_MAC_CFG_FULL_DUPLEX_MODE 0x00000020u
\r
70 * Pass all multicast.
\r
71 * When set, all frames with multicast destination addresses will be received, regardless
\r
72 * of the address check result.
\r
74 #define MSS_MAC_CFG_PASS_ALL_MULTICAST 0x00000040u
\r
78 * When set, all frames will be received regardless of the address check result. An
\r
79 * address check is not performed.
\r
81 #define MSS_MAC_CFG_PROMISCUOUS_MODE 0x00000080u
\r
84 * Inverse filtering (read-only).
\r
85 * If this bit is set when working in a perfect filtering mode, the receiver performs an
\r
86 * inverse filtering during the address check process.
\r
87 * The 'filtering type' bits of the setup frame determine the state of this bit.
\r
89 #define MSS_MAC_CFG_INVERSE_FILTERING 0x00000100u
\r
93 * When set, Core10/100 transfers all frames into the data buffers, regardless of the
\r
94 * receive errors. This allows the runt frames, collided fragments, and truncated frames
\r
97 #define MSS_MAC_CFG_PASS_BAD_FRAMES 0x00000200u
\r
100 * Hash-only filtering mode (read-only).
\r
101 * When set, Core10/100 performs an imperfect filtering over both the multicast and
\r
102 * physical addresses.
\r
103 * The 'filtering type' bits of the setup frame determine the state of this bit.
\r
105 #define MSS_MAC_CFG_HASH_ONLY_FILTERING_MODE 0x00000400u
\r
108 * Hash/perfect receive filtering mode (read-only).
\r
109 * 0 - Perfect filtering of the incoming frames is performed according to the physical
\r
110 * addresses specified in a setup frame. <br>
\r
111 * 1 - Imperfect filtering over the frames with the multicast addresses is performed
\r
112 * according to the hash table specified in a setup frame. <br>
\r
113 * A physical address check is performed according to the CSR6.2 (HO, hash-only) bit.
\r
114 * When both the HO and HP bits are set, an imperfect filtering is performed on all of
\r
116 * The 'filtering type' bits of the setup frame determine the state of this bit.
\r
118 #define MSS_MAC_CFG_HASH_PERFECT_RECEIVE_FILTERING_MODE 0x00000800u
\r
121 /*******************************************************************************
\r
122 * Link status values.
\r
124 #define MSS_MAC_LINK_STATUS_LINK 0x0001u /**< Link up/down */
\r
125 #define MSS_MAC_LINK_STATUS_100MB 0x0002u /**< Connection is 100Mb/10Mb */
\r
126 #define MSS_MAC_LINK_STATUS_FDX 0x0004u /**< Connection is full/half duplex */
\r
130 * Size of the max packet that can be received/transmited.
\r
132 #define MSS_MAX_PACKET_SIZE 1514uL
\r
135 * Size of a receive/transmit buffer.
\r
136 * Buffer size must be enough big to hold a full frame and must be multiple of
\r
137 * four. For rx buffer +4 bytes allocated for crc values. These bytes doesn't
\r
138 * copied to the user buffer.
\r
140 #define MSS_TX_BUFF_SIZE ((MSS_MAX_PACKET_SIZE + 3u) & (~(uint32_t)3))
\r
141 #define MSS_RX_BUFF_SIZE ((MSS_MAX_PACKET_SIZE + 7u) & (~(uint32_t)3))
\r
143 /*******************************************************************************
\r
146 #define MSS_MAC_NONBLOCKING 0u
\r
147 #define MSS_MAC_BLOCKING 0xFFFFFFFFUL
\r
149 /***************************************************************************//**
\r
152 #define MSS_MAC_EVENT_PACKET_SEND 1u
\r
153 #define MSS_MAC_EVENT_PACKET_RECEIVED 2u
\r
155 /***************************************************************************//**
\r
158 #define MSS_PHY_ADDRESS_MIN 0u
\r
159 #define MSS_PHY_ADDRESS_MAX 31u
\r
160 #define MSS_PHY_ADDRESS_AUTO_DETECT 255u
\r
162 /***************************************************************************//**
\r
163 * Listener function type defines the function prototype that might be followed
\r
164 * by MAC_isr which is triggered with each receive and transmit related interrupts.
\r
165 * Listener functions should follow the following prototype:
\r
166 * void MAC_Listener( uint32_t events );
\r
167 * The parameter is used to inform the listener function about the triggering event
\r
168 * or events. Events input to the system are:
\r
169 * #define MSS_MAC_EVENT_PACKET_SEND 1
\r
170 * #define MSS_MAC_EVENT_PACKET_RECEIVED 2
\r
171 * Listener function should be defined by the application using this driver if
\r
172 * needed. This function may be assigned to the driver using MAC_set_callback
\r
173 * routine and may be un assigned again by using the same routine with a NULL pointer
\r
174 * as the event listener function. It is recommended to use this property for interrupt
\r
175 * triggered systems and it is not recommended for polling mechanisms.
\r
177 typedef void (*MSS_MAC_callback_t)(uint32_t events);
\r
179 /***************************************************************************//**
\r
180 * Statistics counter identifiers are used with MAC_get_statistics routine to
\r
181 * receive the count of the requested errors/interrupts occurrences.
\r
183 * MSS_MAC_RX_INTERRUPTS
\r
184 * Used to receive the number of receive interrupts occurred.
\r
186 * MSS_MAC_RX_FILTERING_FAIL
\r
187 * Used to receive the number of received frames which did not pass the
\r
188 * address recognition process.
\r
190 * MSS_MAC_RX_DESCRIPTOR_ERROR
\r
191 * Used to receive the number of occurrences of; no receive buffer was
\r
192 * available when trying to store the received data.
\r
194 * MSS_MAC_RX_RUNT_FRAME
\r
195 * Used to receive the number of occurrences of; the frame is damaged by a
\r
196 * collision or by a premature termination before the end of a collision
\r
199 * MSS_MAC_RX_NOT_FIRST
\r
200 * Used to receive the number of occurrences of; start of the frame is not
\r
201 * the first descriptor of a frame.
\r
203 * MSS_MAC_RX_NOT_LAST
\r
204 * Used to receive the number of occurrences of; end of the frame is not
\r
205 * the first descriptor of a frame.
\r
207 * MSS_MAC_RX_FRAME_TOO_LONG
\r
208 * Used to receive the number of occurrences of; a current frame is longer
\r
209 * than maximum size of 1,518 bytes, as specified by 802.3.
\r
211 * MSS_MAC_RX_COLLISION_SEEN
\r
212 * Used to receive the number of occurrences of; a late collision was seen
\r
213 * (collision after 64 bytes following SFD).
\r
215 * MSS_MAC_RX_CRC_ERROR
\r
216 * Used to receive the number of occurrences of; a CRC error has occurred
\r
217 * in the received frame.
\r
219 * MSS_MAC_RX_FIFO_OVERFLOW
\r
220 * Used to receive the number of frames not accepted due to the receive
\r
223 * MSS_MAC_RX_MISSED_FRAME
\r
224 * Used to receive the number of frames not accepted due to the
\r
225 * unavailability of the receive descriptor.
\r
227 * MSS_MAC_TX_INTERRUPTS
\r
228 * Used to receive the number of transmit interrupts occurred.
\r
230 * MSS_MAC_TX_LOSS_OF_CARRIER
\r
231 * Used to receive the number of occurrences of; a loss of the carrier
\r
232 * during a transmission.
\r
234 * MSS_MAC_TX_NO_CARRIER
\r
235 * Used to receive the number of occurrences of; the carrier was not asserted
\r
236 * by an external transceiver during the transmission.
\r
238 * MSS_MAC_TX_LATE_COLLISION
\r
239 * Used to receive the number of occurrences of; a collision was detected
\r
240 * after transmitting 64 bytes.
\r
242 * MSS_MAC_TX_EXCESSIVE_COLLISION
\r
243 * Used to receive the number of occurrences of; the transmission was aborted
\r
244 * after 16 retries.
\r
246 * MSS_MAC_TX_COLLISION_COUNT
\r
247 * Used to receive the number of collisions occurred.
\r
249 * MSS_MAC_TX_UNDERFLOW_ERROR
\r
250 * Used to receive the number of occurrences of; the FIFO was empty during
\r
251 * the frame transmission.
\r
254 MSS_MAC_RX_INTERRUPTS,
\r
255 MSS_MAC_RX_FILTERING_FAIL,
\r
256 MSS_MAC_RX_DESCRIPTOR_ERROR,
\r
257 MSS_MAC_RX_RUNT_FRAME,
\r
258 MSS_MAC_RX_NOT_FIRST,
\r
259 MSS_MAC_RX_NOT_LAST,
\r
260 MSS_MAC_RX_FRAME_TOO_LONG,
\r
261 MSS_MAC_RX_COLLISION_SEEN,
\r
262 MSS_MAC_RX_CRC_ERROR,
\r
263 MSS_MAC_RX_FIFO_OVERFLOW,
\r
264 MSS_MAC_RX_MISSED_FRAME,
\r
266 MSS_MAC_TX_INTERRUPTS,
\r
267 MSS_MAC_TX_LOSS_OF_CARRIER,
\r
268 MSS_MAC_TX_NO_CARRIER,
\r
269 MSS_MAC_TX_LATE_COLLISION,
\r
270 MSS_MAC_TX_EXCESSIVE_COLLISION,
\r
271 MSS_MAC_TX_COLLISION_COUNT,
\r
272 MSS_MAC_TX_UNDERFLOW_ERROR
\r
273 } mss_mac_statistics_id_t;
\r
275 /******************************* FUNCTIONS ************************************/
\r
277 /***************************************************************************//**
\r
278 * Initializes an Ethernet MAC controller and data structures.
\r
279 * This function will prepare the Ethernet Controller for first time use in a
\r
280 * given hardware/software configuration. This function should be called before
\r
281 * any other Ethernet API functions are called.
\r
283 * Initialization of registers - config registers, enable Tx/Rx interrupts,
\r
284 * enable Tx/Rx, initialize MAC addr, init PHY, autonegotiation, MAC address
\r
285 * filter table (unicast/multicast)/hash init
\r
291 uint8_t phy_address
\r
295 /***************************************************************************//**
\r
296 * Sets the configuration of the Ethernet Controller.
\r
297 * After the MAC_init function has been called, this API function can be
\r
298 * used to configure the various features of the Ethernet Controller.
\r
300 * @param configuration The logical OR of the following values:
\r
301 * - #MSS_MAC_CFG_RECEIVE_ALL
\r
302 * - #MSS_MAC_CFG_TRANSMIT_THRESHOLD_MODE
\r
303 * - #MSS_MAC_CFG_STORE_AND_FORWARD
\r
304 * - #MSS_MAC_CFG_THRESHOLD_CONTROL_[00,01,10,11]
\r
305 * - #MSS_MAC_CFG_FULL_DUPLEX_MODE
\r
306 * - #MSS_MAC_CFG_PASS_ALL_MULTICAST
\r
307 * - #MSS_MAC_CFG_PROMISCUOUS_MODE
\r
308 * - #MSS_MAC_CFG_PASS_BAD_FRAMES
\r
309 * @see MAC_get_configuration()
\r
314 uint32_t configuration
\r
318 /***************************************************************************//**
\r
319 * Returns the configuration of the Ethernet Controller.
\r
320 * After the MAC_init function has been called, this API function can be used to
\r
321 * get the configuration of the Ethernet Controller.
\r
323 * @return The logical OR of the following values:
\r
324 * - #MSS_MAC_CFG_RECEIVE_ALL
\r
325 * - #MSS_MAC_CFG_TRANSMIT_THRESHOLD_MODE
\r
326 * - #MSS_MAC_CFG_STORE_AND_FORWARD
\r
327 * - #MSS_MAC_CFG_THRESHOLD_CONTROL_[00,01,10,11]
\r
328 * - #MSS_MAC_CFG_FULL_DUPLEX_MODE
\r
329 * - #MSS_MAC_CFG_PASS_ALL_MULTICAST
\r
330 * - #MSS_MAC_CFG_PROMISCUOUS_MODE
\r
331 * - #MSS_MAC_CFG_INVERSE_FILTERING
\r
332 * - #MSS_MAC_CFG_PASS_BAD_FRAMES
\r
333 * - #MSS_MAC_CFG_HASH_ONLY_FILTERING_MODE
\r
334 * - #MSS_MAC_CFG_HASH_PERFECT_RECEIVE_FILTERING_MODE
\r
335 * @see MAC_configure()
\r
338 MSS_MAC_get_configuration
\r
344 /***************************************************************************//**
\r
345 * Sends a packet to the Ethernet Controller.
\r
346 * This function writes pacLen bytes of the packet contained in pacData into the
\r
347 * transmit FIFO of the controller and then activates the transmitter for this
\r
348 * packet. If space is available in FIFO, the function will return once lBufLen
\r
349 * bytes of the packet have been placed into the FIFO and the transmitter has been
\r
350 * started. The function will not wait for the transmission to complete. If space
\r
351 * is not available in FIFO, the function will keep trying till time_out expires,
\r
352 * if MSS_MAC_BLOCKING value is given as time_out, function will wait for the
\r
353 * transmission to complete.
\r
355 * @param pacData the pointer to the packet data to be transmitted.
\r
356 * @param pacLen number of bytes in the packet to be transmitted.
\r
357 * @param time_out Time out value for transmision.
\r
358 * If value is #MSS_MAC_BLOCKING, there will be no time out.
\r
359 * If value is #MSS_MAC_NONBLOCKING, function will return immediately
\r
360 * on buffer full case.
\r
361 * Otherwise value must be greater than 0 and smaller than
\r
363 * @return Returns 0 if time out occurs otherwise returns size
\r
365 * @see MAC_rx_packet()
\r
370 const uint8_t *pacData,
\r
376 /***************************************************************************//**
\r
377 * Returns available packet's size.
\r
379 * @return Size of packet, bigger than 0, if a packet is available,
\r
380 * if not, returns 0.
\r
381 * @see MAC_rx_packet()
\r
384 MSS_MAC_rx_pckt_size
\r
391 /***************************************************************************//**
\r
392 * Prepares the RX descriptor for receiving packets.
\r
395 * @see MAC_rx_packet()
\r
398 MSS_MAC_prepare_rx_descriptor
\r
403 /***************************************************************************//**
\r
404 * Receives a packet from the Ethernet Controller.
\r
405 * This function reads a packet from the receive FIFO of the controller and
\r
406 * places it into pacData. If time_out parameter is zero the function will return
\r
407 * immediately (after the copy operation if data is available. Otherwise the function
\r
408 * will keep trying to read till time_out expires or data is read, if MSS_MAC_BLOCKING
\r
409 * value is given as time_out, function will wait for the reception to complete.
\r
411 * @param pacData The pointer to the buffer where received packet data will
\r
412 * be copied. Memory for the buffer should be allocated prior
\r
413 * to calling this function.
\r
414 * @param pacLen Size of the buffer, which the received data will be copied in,
\r
415 * given in number of bytes.
\r
416 * @param time_out Time out value in milli seconds for receiving.
\r
417 * if value is #MSS_MAC_BLOCKING, there will be no time out.
\r
418 * if value is #MSS_MAC_NONBLOCKING, function will return immediately
\r
419 * if there is no packet waiting.
\r
420 * Otherwise value must be greater than 0 and smaller than
\r
422 * @return Size of packet if packet fits in pacData.
\r
423 * 0 if there is no received packet.
\r
424 * @see MAC_rx_pckt_size()
\r
425 * @see MAC_tx_packet()
\r
436 /***************************************************************************//**
\r
437 Receives a packet from the Ethernet Controller.
\r
438 The MSS_MAC_rx_packet_ptrset() function is very similar to the MSS_MAC_rx_packet()
\r
439 function, in that it receives data from the MSS Ethernet MAC. The difference
\r
440 is that it sets pacData to point to the memory buffer where the MSS Ethernet
\r
441 MAC copied the received packet instead of copying the received packet into a
\r
442 buffer provided by the application. After this function is called and data is
\r
443 used by the user application or copied to another buffer, the
\r
444 MSS_MAC_prepare_rx_descriptor() function must be called to free up the receive
\r
445 memory buffer used by the MSS Ethernet MAC
\r
448 The pacData parameter is a pointer to a memory buffer pointer. The uint8_t
\r
449 pointer pointed to by the pacData parameter will contain the address of the
\r
450 memory buffer containing the received packet after this function returns. The
\r
451 value of pacData is only valid if the return value is larger than zero,
\r
452 indicating that a packet was received.
\r
455 The time_out parameter is the timeout value for the transmission in milliseconds.
\r
456 The time_out parameter value can be one of the following values:
\r
457 \95 Unsigned integer greater than 0 and less than 0x01000000
\r
458 \95 MSS_MAC_BLOCKING
\96 there will be no timeout.
\r
459 \95 MSS_MAC_NONBLOCKING
\96 the function will return immediately if no packets
\r
460 have been received.
\r
463 The function returns the size of the packet if the packet fits in pacData.
\r
464 Returns zero if there is no received packet.
\r
466 @see MAC_rx_pckt_size()
\r
467 @see MAC_tx_packet()
\r
470 MSS_MAC_rx_packet_ptrset
\r
476 /***************************************************************************//**
\r
477 * Returns the status of connection by reading it from the PHY.
\r
479 * @return the logical OR of the following values:
\r
480 * #MSS_MAC_LINK_STATUS_LINK - Link up/down
\r
481 * #MSS_MAC_LINK_STATUS_100MB - Connection is 100Mb/10Mb
\r
482 * #MSS_MAC_LINK_STATUS_FDX - Connection is full/half duplex
\r
483 * @see MAC_auto_setup_link()
\r
486 MSS_MAC_link_status
\r
492 /***************************************************************************//**
\r
493 * Setups the link between PHY and MAC and returns the status of connection.
\r
495 * @return the logical OR of the following values:
\r
496 * #MSS_MAC_LINK_STATUS_LINK - Link up/down
\r
497 * #MSS_MAC_LINK_STATUS_100MB - Connection is 100Mb/10Mb
\r
498 * #MSS_MAC_LINK_STATUS_FDX - Connection is full/half duplex
\r
499 * @see MAC_link_status()
\r
502 MSS_MAC_auto_setup_link
\r
508 /***************************************************************************//**
\r
509 * Sets mac address.
\r
511 * @param new_address Pointer to then new address value (6 bytes of data)
\r
512 * @see MAC_get_mac_address()
\r
515 MSS_MAC_set_mac_address
\r
517 const uint8_t *new_address
\r
521 /***************************************************************************//**
\r
522 * Returns mac address.
\r
524 * @param address Pointer to the parameter to receive the MAC address.
\r
525 * @see MAC_set_mac_address()
\r
528 MSS_MAC_get_mac_address
\r
534 /***************************************************************************//**
\r
535 * Sets mac address filters.
\r
536 * If less than 15 addresses are subscribed, system works on perfect filtering mode
\r
537 * else system works in hash table mode
\r
539 * @param filter_count number of addresses
\r
540 * @param filters Pointer to addresses to be filtered
\r
543 MSS_MAC_set_mac_filters
\r
545 uint16_t filter_count,
\r
546 const uint8_t *filters
\r
549 /***************************************************************************//**
\r
550 * Sets MAC event listener.
\r
551 * Sets the given event listener function to be triggered inside MAC_isr().
\r
552 * Assigning NULL pointer as the listener function will disable it.
\r
554 * @param listener function pointer to a MSS_MAC_callback_t function
\r
558 MSS_MAC_set_callback
\r
560 MSS_MAC_callback_t listener
\r
564 /***************************************************************************//**
\r
565 * Returns description of latest error happened.
\r
567 * @return A string describing the error. This string must not be
\r
568 * modified by the application.
\r
577 /***************************************************************************//**
\r
578 * Returns statistics counter of stat_id identifier.
\r
580 * @param stat_id Identifier of statistics counter.
\r
581 * @return Statistics counter of stat_id identifier.
\r
582 * On error returns 0.
\r
585 MSS_MAC_get_statistics
\r
587 mss_mac_statistics_id_t stat_id
\r
594 #endif /* __MSS_ETHERNET_MAC_H */
\r