source: rtems/c/src/lib/libbsp/powerpc/beatnik/network/if_mve/if_mve_pub.h @ 183af89

4.115
Last change on this file since 183af89 was b7a6d23a, checked in by Till Straumann <strauman@…>, on 12/03/09 at 16:56:50
  • importing 'beatnik' BSP from SLAC repository.
  • Property mode set to 100644
File size: 14.6 KB
Line 
1/* $Id$ */
2#ifndef RTEMS_BSDNET_IF_MVE_PUBLIC_SYMBOLS_H
3#define RTEMS_BSDNET_IF_MVE_PUBLIC_SYMBOLS_H
4
5/*
6 * Authorship
7 * ----------
8 * This software ('beatnik' RTEMS BSP for MVME6100 and MVME5500) was
9 *     created by Till Straumann <strauman@slac.stanford.edu>, 2005-2007,
10 *         Stanford Linear Accelerator Center, Stanford University.
11 *
12 * Acknowledgement of sponsorship
13 * ------------------------------
14 * The 'beatnik' BSP was produced by
15 *     the Stanford Linear Accelerator Center, Stanford University,
16 *         under Contract DE-AC03-76SFO0515 with the Department of Energy.
17 *
18 * Government disclaimer of liability
19 * ----------------------------------
20 * Neither the United States nor the United States Department of Energy,
21 * nor any of their employees, makes any warranty, express or implied, or
22 * assumes any legal liability or responsibility for the accuracy,
23 * completeness, or usefulness of any data, apparatus, product, or process
24 * disclosed, or represents that its use would not infringe privately owned
25 * rights.
26 *
27 * Stanford disclaimer of liability
28 * --------------------------------
29 * Stanford University makes no representations or warranties, express or
30 * implied, nor assumes any liability for the use of this software.
31 *
32 * Stanford disclaimer of copyright
33 * --------------------------------
34 * Stanford University, owner of the copyright, hereby disclaims its
35 * copyright and all other rights in this software.  Hence, anyone may
36 * freely use it for any purpose without restriction. 
37 *
38 * Maintenance of notices
39 * ----------------------
40 * In the interest of clarity regarding the origin and status of this
41 * SLAC software, this and all the preceding Stanford University notices
42 * are to remain affixed to any copy or derivative of this software made
43 * or distributed by the recipient and are to be affixed to any copy of
44 * software made or distributed by the recipient that contains a copy or
45 * derivative of this software.
46 *
47 * ------------------ SLAC Software Notices, Set 4 OTT.002a, 2004 FEB 03
48 */
49#include <rtems.h>
50#include <rtems/rtems_bsdnet.h>
51#include <bsp/early_enet_link_status.h>
52#include <stdint.h>
53
54#ifdef __cplusplus
55  extern "C" {
56#endif
57
58extern int                               rtems_mve_attach(struct rtems_bsdnet_ifconfig *, int);
59extern rtems_bsdnet_early_link_check_ops rtems_mve_early_link_check_ops;
60
61/* Low-level Driver API.
62 * This provides driver access to applications that want to use e.g., the second
63 * ethernet interface w/o running the BSD TCP/IP stack.
64 */
65
66/* Opaque handle */
67struct mveth_private;
68
69/* Direct assignment of MVE flags to user API relies on irqs and x-irqs not overlapping */
70#define BSP_MVE_IRQ_RX          (1<<2)
71#define BSP_MVE_IRQ_TX          (1<<0)
72#define BSP_MVE_IRQ_LINK        (1<<16)
73
74/* Setup an interface.
75 * Allocates resources for descriptor rings and sets up the driver software structure.
76 *
77 * Arguments:
78 *      unit:
79 *              interface # (1..2). The interface must not be attached to BSD.
80 *
81 *  driver_tid:
82 *              ISR posts RTEMS event # ('unit' - 1) to task with ID 'driver_tid' and disables interrupts
83 *              from this interface.
84 *
85 *      void (*cleanup_txbuf)(void *user_buf, void *cleanup_txbuf_arg, int error_on_tx_occurred):
86 *              Pointer to user-supplied callback to release a buffer that had been sent
87 *              by BSP_mve_send_buf() earlier. The callback is passed 'cleanup_txbuf_arg'
88 *              and a flag indicating whether the send had been successful.
89 *              The driver no longer accesses 'user_buf' after invoking this callback.
90 *              CONTEXT: This callback is executed either by BSP_mve_swipe_tx() or
91 *              BSP_mve_send_buf(), BSP_mve_init_hw(), BSP_mve_stop_hw() (the latter
92 *              ones calling BSP_mve_swipe_tx()).
93 *      void *cleanup_txbuf_arg:
94 *              Closure argument that is passed on to 'cleanup_txbuf()' callback;
95 *
96 *      void *(*alloc_rxbuf)(int *p_size, unsigned long *p_data_addr),
97 *              Pointer to user-supplied callback to allocate a buffer for subsequent
98 *              insertion into the RX ring by the driver.
99 *              RETURNS: opaque handle to the buffer (which may be a more complex object
100 *                               such as an 'mbuf'). The handle is not used by the driver directly
101 *                               but passed back to the 'consume_rxbuf()' callback.
102 *                               Size of the available data area and pointer to buffer's data area
103 *                               in '*psize' and '*p_data_area', respectively.
104 *                               If no buffer is available, this routine should return NULL in which
105 *                               case the driver drops the last packet and re-uses the last buffer
106 *                               instead of handing it out to 'consume_rxbuf()'.
107 *              CONTEXT: Called when initializing the RX ring (BSP_mve_init_hw()) or when
108 *                               swiping it (BSP_mve_swipe_rx()).
109 *             
110 *
111 *      void (*consume_rxbuf)(void *user_buf, void *consume_rxbuf_arg, int len);
112 *              Pointer to user-supplied callback to pass a received buffer back to
113 *              the user. The driver no longer accesses the buffer after invoking this
114 *              callback (with 'len'>0, see below). 'user_buf' is the buffer handle
115 *              previously generated by 'alloc_rxbuf()'.
116 *              The callback is passed 'cleanup_rxbuf_arg' and a 'len'
117 *              argument giving the number of bytes that were received.
118 *              'len' may be <=0 in which case the 'user_buf' argument is NULL.
119 *              'len' == 0 means that the last 'alloc_rxbuf()' had failed,
120 *              'len' < 0 indicates a receiver error. In both cases, the last packet
121 *              was dropped/missed and the last buffer will be re-used by the driver.
122 *              NOTE: the data are 'prefixed' with two bytes, i.e., the ethernet packet header
123 *                    is stored at offset 2 in the buffer's data area. Also, the FCS (4 bytes)
124 *                    is appended. 'len' accounts for both.
125 *              CONTEXT: Called from BSP_mve_swipe_rx().
126 *      void *cleanup_rxbuf_arg:
127 *              Closure argument that is passed on to 'consume_rxbuf()' callback;
128 *
129 *  rx_ring_size, tx_ring_size:
130 *              How many big to make the RX and TX descriptor rings. Note that the sizes
131 *              may be 0 in which case a reasonable default will be used.
132 *              If either ring size is < 0 then the RX or TX will be disabled.
133 *              Note that it is illegal in this case to use BSP_mve_swipe_rx() or
134 *              BSP_mve_swipe_tx(), respectively.
135 *
136 *  irq_mask:
137 *              Interrupts to enable. OR of flags from above.
138 *
139 */
140struct mveth_private *
141BSP_mve_setup(
142        int              unit,
143        rtems_id driver_tid,
144        void (*cleanup_txbuf)(void *user_buf, void *cleanup_txbuf_arg, int error_on_tx_occurred),
145        void *cleanup_txbuf_arg,
146        void *(*alloc_rxbuf)(int *p_size, uintptr_t *p_data_addr),
147        void (*consume_rxbuf)(void *user_buf, void *consume_rxbuf_arg, int len),
148        void *consume_rxbuf_arg,
149        int             rx_ring_size,
150        int             tx_ring_size,
151        int             irq_mask
152);
153
154/*
155 * Alternate 'setup' routine allowing the user to install an ISR rather
156 * than a task ID.
157 * All parameters (other than 'isr' / 'isr_arg') and the return value
158 * are identical to the BSP_mve_setup() entry point.
159 */
160struct mveth_private *
161BSP_mve_setup_1(
162        int              unit,
163        void     (*isr)(void *isr_arg),
164        void     *isr_arg,
165        void (*cleanup_txbuf)(void *user_buf, void *cleanup_txbuf_arg, int error_on_tx_occurred),
166        void *cleanup_txbuf_arg,
167        void *(*alloc_rxbuf)(int *p_size, uintptr_t *p_data_addr),
168        void (*consume_rxbuf)(void *user_buf, void *consume_rxbuf_arg, int len),
169        void *consume_rxbuf_arg,
170        int             rx_ring_size,
171        int             tx_ring_size,
172        int             irq_mask
173);
174
175
176/*
177 * Initialize interface hardware
178 *
179 * 'mp'                 handle obtained by from BSP_mve_setup().
180 * 'promisc'    whether to set promiscuous flag.
181 * 'enaddr'             pointer to six bytes with MAC address. Read
182 *                              from the device if NULL.
183 *
184 * Note:        Multicast filters are cleared by this routine.
185 *              However, in promiscuous mode the mcast filters
186 *              are programmed to accept all multicast frames.
187 */
188void
189BSP_mve_init_hw(struct mveth_private *mp, int promisc, unsigned char *enaddr);
190
191/*
192 * Clear multicast hash filter. No multicast frames are accepted
193 * after executing this routine (unless the hardware was initialized
194 * in 'promiscuous' mode).
195 */
196void
197BSP_mve_mcast_filter_clear(struct mveth_private *mp);
198
199/*
200 * Program multicast filter to accept all multicast frames
201 */
202void
203BSP_mve_mcast_filter_accept_all(struct mveth_private *mp);
204
205/*
206 * Add a MAC address to the multicast filter.
207 * Existing entries are not changed but note that
208 * the filter is imperfect, i.e., multiple MAC addresses
209 * may alias to a single filter entry. Hence software
210 * filtering must still be performed.
211 *
212 * If a higher-level driver implements IP multicasting
213 * then multiple IP addresses may alias to the same MAC
214 * address. This driver maintains a 'reference-count'
215 * which is incremented every time the same MAC-address
216 * is passed to this routine; the address is only removed
217 * from the filter if BSP_mve_mcast_filter_accept_del()
218 * is called the same number of times (or by BSP_mve_mcast_filter_clear).
219 */
220void
221BSP_mve_mcast_filter_accept_add(struct mveth_private *mp, unsigned char *enaddr);
222
223/*
224 * Remove a MAC address from the multicast filter.
225 * This routine decrements the reference count of the given
226 * MAC-address and removes it from the filter once the
227 * count reaches zero.
228 */
229void
230BSP_mve_mcast_filter_accept_del(struct mveth_private *mp, unsigned char *enaddr);
231
232/*
233 * Shutdown hardware and clean out the rings
234 */
235void
236BSP_mve_stop_hw(struct mveth_private *mp);
237
238/* calls BSP_mve_stop_hw(), releases all resources and marks the interface
239 * as unused.
240 * RETURNS 0 on success, nonzero on failure.
241 * NOTE:   the handle MUST NOT be used after successful execution of this
242 *         routine.
243 */
244int
245BSP_mve_detach(struct mveth_private *mp);
246
247/*
248 * Enqueue a mbuf chain or a raw data buffer for transmission;
249 * RETURN: #bytes sent or -1 if there are not enough free descriptors
250 *
251 * If 'len' is <=0 then 'm_head' is assumed to point to a mbuf chain.
252 * OTOH, a raw data packet (or a different type of buffer)
253 * may be send (non-BSD driver) by pointing data_p to the start of
254 * the data and passing 'len' > 0.
255 * 'm_head' is passed back to the 'cleanup_txbuf()' callback.
256 *
257 * Comments: software cache-flushing incurs a penalty if the
258 *           packet cannot be queued since it is flushed anyways.
259 *           The algorithm is slightly more efficient in the normal
260 *                       case, though.
261 *
262 * RETURNS: # bytes enqueued to device for transmission or -1 if no
263 *          space in the TX ring was available.
264 */
265int
266BSP_mve_send_buf(struct mveth_private *mp, void *m_head, void *data_p, int len);
267
268/* Descriptor scavenger; cleanup the TX ring, passing all buffers
269 * that have been sent to the cleanup_tx() callback.
270 * This routine is called from BSP_mve_send_buf(), BSP_mve_init_hw(),
271 * BSP_mve_stop_hw().
272 *
273 * RETURNS: number of buffers processed.
274 */
275int
276BSP_mve_swipe_tx(struct mveth_private *mp);
277
278/* Retrieve all received buffers from the RX ring, replacing them
279 * by fresh ones (obtained from the alloc_rxbuf() callback). The
280 * received buffers are passed to consume_rxbuf().
281 *
282 * RETURNS: number of buffers processed.
283 */
284int
285BSP_mve_swipe_rx(struct mveth_private *mp);
286
287/* read ethernet address from hw to buffer */
288void
289BSP_mve_read_eaddr(struct mveth_private *mp, unsigned char *eaddr);
290
291/* read/write media word.
292 *   'cmd': can be SIOCGIFMEDIA, SIOCSIFMEDIA, 0 or 1. The latter
293 *          are aliased to the former for convenience.
294 *  'parg': pointer to media word.
295 *
296 * RETURNS: 0 on success, nonzero on error
297 *
298 * NOTE:    This routine is thread-safe.
299 */
300int
301BSP_mve_media_ioctl(struct mveth_private *mp, int cmd, int *parg);
302
303/* Interrupt related routines */
304
305/* Note: the BSP_mve_enable/disable/ack_irqs() entry points
306 *       are deprecated.
307 *       The newer API where the user passes a mask allows
308 *       for more selective control.
309 */
310
311/* Enable all supported interrupts at device */
312void
313BSP_mve_enable_irqs(struct mveth_private *mp);
314
315/* Disable all supported interrupts at device */
316void
317BSP_mve_disable_irqs(struct mveth_private *mp);
318
319/* Acknowledge (and clear) all supported interrupts.
320 * RETURNS: interrupts that were raised.
321 */
322uint32_t
323BSP_mve_ack_irqs(struct mveth_private *mp);
324
325/* Enable interrupts included in 'mask' (leaving
326 * already enabled interrupts on). If the mask
327 * includes bits that were not passed to the 'setup'
328 * routine then the behavior is undefined.
329 */
330void
331BSP_mve_enable_irq_mask(struct mveth_private *mp, uint32_t irq_mask);
332
333/* Disable interrupts included in 'mask' (leaving
334 * other ones that are currently enabled on). If the
335 * mask includes bits that were not passed to the 'setup'
336 * routine then the behavior is undefined.
337 *
338 * RETURNS: Bitmask of interrupts that were enabled upon entry
339 *          into this routine. This can be used to restore the
340 *          previous state.
341 */
342uint32_t
343BSP_mve_disable_irq_mask(struct mveth_private *mp, uint32_t irq_mask);
344
345/* Acknowledge and clear selected interrupts.
346 *
347 * RETURNS: All pending interrupts.
348 *
349 * NOTE:    Only pending interrupts contained in 'mask'
350 *          are cleared. Others are left pending.
351 *
352 *          This routine can be used to check for pending
353 *          interrupts (pass mask ==  0) or to clear all
354 *          interrupts (pass mask == -1).
355 */
356uint32_t
357BSP_mve_ack_irq_mask(struct mveth_private *mp, uint32_t mask);
358
359/* If the PHY link status changes then some
360 * internal settings in the ethernet controller's
361 * serial port need to be updated to match the
362 * PHY settings. Use this routine to perform the
363 * necessary steps after a link change has been
364 * detected.
365 *
366 * RETURNS: 0 on success, -1 if the PHY state
367 *          could not be determined.
368 *
369 *          The current state of the media as read
370 *          by BSP_mve_media_ioctl() is returned in
371 *          *pmedia.
372 *
373 * NOTE:    This routine calls BSP_mve_media_ioctl().
374 */
375int
376BSP_mve_ack_link_chg(struct mveth_private *mp, int *pmedia);
377
378/* Retrieve the driver daemon TID that was passed to
379 * BSP_mve_setup().
380 */
381
382rtems_id
383BSP_mve_get_tid(struct mveth_private *mp);
384
385/* Dump statistics to file (stdout if NULL)
386 *
387 * NOTE: this routine is not thread safe
388 */
389void
390BSP_mve_dump_stats(struct mveth_private *mp, FILE *f);
391
392/*
393 *
394 * Example driver task loop (note: no synchronization of
395 * buffer access shown!).
396 * RTEMS_EVENTx = 0,1 or 2 depending on IF unit.
397 *
398 *    / * setup (obtain handle) and initialize hw here * /
399 *
400 *    do {
401 *      / * ISR disables IRQs and posts event * /
402 *              rtems_event_receive( RTEMS_EVENTx, RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &evs );
403 *              irqs = BSP_mve_ack_irqs(handle);
404 *      if ( irqs & BSP_MVE_IRQ_TX ) {
405 *                      BSP_mve_swipe_tx(handle); / * cleanup_txbuf() callback executed * /
406 *              }
407 *      if ( irqs & BSP_MVE_IRQ_RX ) {
408 *                      BSP_mve_swipe_rx(handle); / * alloc_rxbuf() and consume_rxbuf() executed * /
409 *              }
410 *              if ( irqs & BSP_MVE_IRQ_LINK ) {
411 *          / * update serial port settings from current link status * /
412 *          BSP_mve_ack_link_chg(handle, 0);
413 *              }
414 *              BSP_mve_enable_irqs(handle);
415 *    } while (1);
416 *
417 */
418
419#ifdef __cplusplus
420  }
421#endif
422
423#endif
Note: See TracBrowser for help on using the repository browser.