source: rtems-libbsd/freebsd/sys/dev/tsec/if_tsec.h @ 8fe59fe

4.1155-freebsd-126-freebsd-12freebsd-9.3
Last change on this file since 8fe59fe was 8fe59fe, checked in by Sebastian Huber <sebastian.huber@…>, on 11/18/13 at 11:46:27

if_tsec: Add Nexus support

  • Property mode set to 100644
File size: 11.5 KB
RevLine 
[70bb42b]1/*-
2 * Copyright (C) 2006-2007 Semihalf, Piotr Kruszynski
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 *    notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 *    notice, this list of conditions and the following disclaimer in the
12 *    documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
15 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN
17 * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
18 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
19 * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
21 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
22 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
23 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 *
25 * $FreeBSD$
26 */
27
28#ifndef _IF_TSEC_H
29#define _IF_TSEC_H
30
31#include <dev/ofw/openfirm.h>
32
33#define TSEC_RX_NUM_DESC        256
34#define TSEC_TX_NUM_DESC        256
35
36/* Interrupt Coalescing types */
37#define TSEC_IC_RX              0
38#define TSEC_IC_TX              1
39
40/* eTSEC ID */
41#define TSEC_ETSEC_ID           0x0124
42
43/* Frame sizes */
44#define TSEC_MIN_FRAME_SIZE     64
45#define TSEC_MAX_FRAME_SIZE     9600
46
47struct tsec_softc {
48        /* XXX MII bus requires that struct ifnet is first!!! */
49        struct ifnet    *tsec_ifp;
50       
51        struct mtx      transmit_lock;  /* transmitter lock */
52        struct mtx      receive_lock;   /* receiver lock */
53
[8fe59fe]54#ifndef __rtems__
[70bb42b]55        phandle_t       node;
[8fe59fe]56#endif /* __rtems__ */
[70bb42b]57        device_t        dev;
58        device_t        tsec_miibus;
59        struct mii_data *tsec_mii;      /* MII media control */
60        int             tsec_link;
61
62        bus_dma_tag_t   tsec_tx_dtag;   /* TX descriptors tag */
63        bus_dmamap_t    tsec_tx_dmap;   /* TX descriptors map */
64        struct tsec_desc *tsec_tx_vaddr;/* vadress of TX descriptors */
65        uint32_t        tsec_tx_raddr;  /* real adress of TX descriptors */
66
67        bus_dma_tag_t   tsec_rx_dtag;   /* RX descriptors tag */
68        bus_dmamap_t    tsec_rx_dmap;   /* RX descriptors map */
69        struct tsec_desc *tsec_rx_vaddr; /* vadress of RX descriptors */
70        uint32_t        tsec_rx_raddr;  /* real adress of RX descriptors */
71
72        bus_dma_tag_t   tsec_tx_mtag;   /* TX mbufs tag */
73        bus_dma_tag_t   tsec_rx_mtag;   /* TX mbufs tag */
74
75        struct rx_data_type {
76                bus_dmamap_t    map;    /* mbuf map */
77                struct mbuf     *mbuf;
78                uint32_t        paddr;  /* DMA addres of buffer */
79        } rx_data[TSEC_RX_NUM_DESC];
80
81        uint32_t        tx_cur_desc_cnt;
82        uint32_t        tx_dirty_desc_cnt;
83        uint32_t        rx_cur_desc_cnt;
84
85        struct resource *sc_rres;       /* register resource */
86        int             sc_rrid;        /* register rid */
87        struct {
88                bus_space_tag_t bst;
89                bus_space_handle_t bsh;
90        } sc_bas;
91
92        struct resource *sc_transmit_ires;
93        void            *sc_transmit_ihand;
94        int             sc_transmit_irid;
95        struct resource *sc_receive_ires;
96        void            *sc_receive_ihand;
97        int             sc_receive_irid;
98        struct resource *sc_error_ires;
99        void            *sc_error_ihand;
100        int             sc_error_irid;
101
102        int             tsec_if_flags;
103        int             is_etsec;
104
105        /* Watchdog and MII tick related */
106        struct callout  tsec_callout;
107        int             tsec_watchdog;
108
109        /* TX maps */
110        bus_dmamap_t    tx_map_data[TSEC_TX_NUM_DESC];
111
112        /* unused TX maps data */
113        uint32_t        tx_map_unused_get_cnt;
114        uint32_t        tx_map_unused_put_cnt;
115        bus_dmamap_t    *tx_map_unused_data[TSEC_TX_NUM_DESC];
116
117        /* used TX maps data */
118        uint32_t        tx_map_used_get_cnt;
119        uint32_t        tx_map_used_put_cnt;
120        bus_dmamap_t    *tx_map_used_data[TSEC_TX_NUM_DESC];
121       
122        /* mbufs in TX queue */
123        uint32_t        tx_mbuf_used_get_cnt;
124        uint32_t        tx_mbuf_used_put_cnt;
125        struct mbuf     *tx_mbuf_used_data[TSEC_TX_NUM_DESC];
126
127        /* interrupt coalescing */
128        struct mtx      ic_lock;
129        uint32_t        rx_ic_time;     /* RW, valid values 0..65535 */
130        uint32_t        rx_ic_count;    /* RW, valid values 0..255 */
131        uint32_t        tx_ic_time;
132        uint32_t        tx_ic_count;
133
134        /* currently received frame */
135        struct mbuf     *frame;
136
137        int             phyaddr;
138        struct tsec_softc *phy_sc;
139};
140
141/* interface to get/put generic objects */
142#define TSEC_CNT_INIT(cnt, wrap) ((cnt) = ((wrap) - 1))
143
144#define TSEC_INC(count, wrap) (count = ((count) + 1) & ((wrap) - 1))
145
146#define TSEC_GET_GENERIC(hand, tab, count, wrap) \
147                ((hand)->tab[TSEC_INC((hand)->count, wrap)])
148
149#define TSEC_PUT_GENERIC(hand, tab, count, wrap, val)   \
150                ((hand)->tab[TSEC_INC((hand)->count, wrap)] = val)
151
152#define TSEC_BACK_GENERIC(sc, count, wrap) do {                 \
153                if ((sc)->count > 0)                            \
154                        (sc)->count--;                          \
155                else                                            \
156                        (sc)->count = (wrap) - 1;               \
157} while (0)
158
159/* TX maps interface */
160#define TSEC_TX_MAP_CNT_INIT(sc) do {                                           \
161                TSEC_CNT_INIT((sc)->tx_map_unused_get_cnt, TSEC_TX_NUM_DESC);   \
162                TSEC_CNT_INIT((sc)->tx_map_unused_put_cnt, TSEC_TX_NUM_DESC);   \
163                TSEC_CNT_INIT((sc)->tx_map_used_get_cnt, TSEC_TX_NUM_DESC);     \
164                TSEC_CNT_INIT((sc)->tx_map_used_put_cnt, TSEC_TX_NUM_DESC);     \
165} while (0)
166
167/* interface to get/put unused TX maps */
168#define TSEC_ALLOC_TX_MAP(sc)                                                   \
169                TSEC_GET_GENERIC(sc, tx_map_unused_data, tx_map_unused_get_cnt, \
170                TSEC_TX_NUM_DESC)
171
172#define TSEC_FREE_TX_MAP(sc, val)                                               \
173                TSEC_PUT_GENERIC(sc, tx_map_unused_data, tx_map_unused_put_cnt, \
174                TSEC_TX_NUM_DESC, val)
175
176/* interface to get/put used TX maps */
177#define TSEC_GET_TX_MAP(sc)                                                     \
178                TSEC_GET_GENERIC(sc, tx_map_used_data, tx_map_used_get_cnt,     \
179                TSEC_TX_NUM_DESC)
180
181#define TSEC_PUT_TX_MAP(sc, val)                                                \
182                TSEC_PUT_GENERIC(sc, tx_map_used_data, tx_map_used_put_cnt,     \
183                TSEC_TX_NUM_DESC, val)
184
185/* interface to get/put TX mbufs in send queue */
186#define TSEC_TX_MBUF_CNT_INIT(sc) do {                                          \
187                TSEC_CNT_INIT((sc)->tx_mbuf_used_get_cnt, TSEC_TX_NUM_DESC);    \
188                TSEC_CNT_INIT((sc)->tx_mbuf_used_put_cnt, TSEC_TX_NUM_DESC);    \
189} while (0)
190
191#define TSEC_GET_TX_MBUF(sc)                                                    \
192                TSEC_GET_GENERIC(sc, tx_mbuf_used_data, tx_mbuf_used_get_cnt,   \
193                TSEC_TX_NUM_DESC)
194
195#define TSEC_PUT_TX_MBUF(sc, val)                                               \
196                TSEC_PUT_GENERIC(sc, tx_mbuf_used_data, tx_mbuf_used_put_cnt,   \
197                TSEC_TX_NUM_DESC, val)
198
199#define TSEC_EMPTYQ_TX_MBUF(sc) \
200                ((sc)->tx_mbuf_used_get_cnt == (sc)->tx_mbuf_used_put_cnt)
201
202/* interface for manage tx tsec_desc */
203#define TSEC_TX_DESC_CNT_INIT(sc) do {                                          \
204                TSEC_CNT_INIT((sc)->tx_cur_desc_cnt, TSEC_TX_NUM_DESC);         \
205                TSEC_CNT_INIT((sc)->tx_dirty_desc_cnt, TSEC_TX_NUM_DESC);       \
206} while (0)
207
208#define TSEC_GET_CUR_TX_DESC(sc)                                                \
209                &TSEC_GET_GENERIC(sc, tsec_tx_vaddr, tx_cur_desc_cnt,           \
210                TSEC_TX_NUM_DESC)
211
212#define TSEC_GET_DIRTY_TX_DESC(sc)                                              \
213                &TSEC_GET_GENERIC(sc, tsec_tx_vaddr, tx_dirty_desc_cnt,         \
214                TSEC_TX_NUM_DESC)
215
216#define TSEC_BACK_DIRTY_TX_DESC(sc) \
217                TSEC_BACK_GENERIC(sc, tx_dirty_desc_cnt, TSEC_TX_NUM_DESC)
218
219#define TSEC_CUR_DIFF_DIRTY_TX_DESC(sc) \
220                ((sc)->tx_cur_desc_cnt != (sc)->tx_dirty_desc_cnt)
221
222#define TSEC_FREE_TX_DESC(sc)                                           \
223                (((sc)->tx_cur_desc_cnt < (sc)->tx_dirty_desc_cnt) ?    \
224                ((sc)->tx_dirty_desc_cnt - (sc)->tx_cur_desc_cnt - 1)   \
225                :                                                       \
226                (TSEC_TX_NUM_DESC - (sc)->tx_cur_desc_cnt               \
227                + (sc)->tx_dirty_desc_cnt - 1))
228
229/* interface for manage rx tsec_desc */
230#define TSEC_RX_DESC_CNT_INIT(sc) do {                                  \
231                TSEC_CNT_INIT((sc)->rx_cur_desc_cnt, TSEC_RX_NUM_DESC); \
232} while (0)
233
234#define TSEC_GET_CUR_RX_DESC(sc)                                        \
235                &TSEC_GET_GENERIC(sc, tsec_rx_vaddr, rx_cur_desc_cnt,   \
236                TSEC_RX_NUM_DESC)
237
238#define TSEC_BACK_CUR_RX_DESC(sc) \
239                TSEC_BACK_GENERIC(sc, rx_cur_desc_cnt, TSEC_RX_NUM_DESC)
240
241#define TSEC_GET_CUR_RX_DESC_CNT(sc) \
242                ((sc)->rx_cur_desc_cnt)
243
244/* init all counters (for init only!) */
245#define TSEC_TX_RX_COUNTERS_INIT(sc) do {       \
246                TSEC_TX_MAP_CNT_INIT(sc);       \
247                TSEC_TX_MBUF_CNT_INIT(sc);      \
248                TSEC_TX_DESC_CNT_INIT(sc);      \
249                TSEC_RX_DESC_CNT_INIT(sc);      \
250} while (0)
251
252/* read/write bus functions */
253#define TSEC_READ(sc, reg)              \
254                bus_space_read_4((sc)->sc_bas.bst, (sc)->sc_bas.bsh, (reg))
255#define TSEC_WRITE(sc, reg, val)        \
256                bus_space_write_4((sc)->sc_bas.bst, (sc)->sc_bas.bsh, (reg), (val))
257
258/* Lock for transmitter */
259#define TSEC_TRANSMIT_LOCK(sc) do {                                     \
260                mtx_assert(&(sc)->receive_lock, MA_NOTOWNED);           \
261                mtx_lock(&(sc)->transmit_lock);                         \
262} while (0)
263
264#define TSEC_TRANSMIT_UNLOCK(sc)        mtx_unlock(&(sc)->transmit_lock)
265#define TSEC_TRANSMIT_LOCK_ASSERT(sc)   mtx_assert(&(sc)->transmit_lock, MA_OWNED)
266
267/* Lock for receiver */
268#define TSEC_RECEIVE_LOCK(sc) do {                                      \
269                mtx_assert(&(sc)->transmit_lock, MA_NOTOWNED);          \
270                mtx_lock(&(sc)->receive_lock);                          \
271} while (0)
272
273#define TSEC_RECEIVE_UNLOCK(sc)         mtx_unlock(&(sc)->receive_lock)
274#define TSEC_RECEIVE_LOCK_ASSERT(sc)    mtx_assert(&(sc)->receive_lock, MA_OWNED)
275
276/* Lock for interrupts coalescing */
277#define TSEC_IC_LOCK(sc) do {                                           \
278                mtx_assert(&(sc)->ic_lock, MA_NOTOWNED);                \
279                mtx_lock(&(sc)->ic_lock);                               \
280} while (0)
281
282#define TSEC_IC_UNLOCK(sc)              mtx_unlock(&(sc)->ic_lock)
283#define TSEC_IC_LOCK_ASSERT(sc)         mtx_assert(&(sc)->ic_lock, MA_OWNED)
284
285/* Global tsec lock (with all locks) */
286#define TSEC_GLOBAL_LOCK(sc) do {                                       \
287                if ((mtx_owned(&(sc)->transmit_lock) ? 1 : 0) !=        \
288                        (mtx_owned(&(sc)->receive_lock) ? 1 : 0)) {     \
289                        panic("tsec deadlock possibility detection!");  \
290                }                                                       \
291                mtx_lock(&(sc)->transmit_lock);                         \
292                mtx_lock(&(sc)->receive_lock);                          \
293} while (0)
294
295#define TSEC_GLOBAL_UNLOCK(sc) do {             \
296                TSEC_RECEIVE_UNLOCK(sc);        \
297                TSEC_TRANSMIT_UNLOCK(sc);       \
298} while (0)
299
300#define TSEC_GLOBAL_LOCK_ASSERT(sc) do {        \
301                TSEC_TRANSMIT_LOCK_ASSERT(sc);  \
302                TSEC_RECEIVE_LOCK_ASSERT(sc);   \
303} while (0)
304
305/* From global to {transmit,receive} */
306#define TSEC_GLOBAL_TO_TRANSMIT_LOCK(sc) do {   \
307                mtx_unlock(&(sc)->receive_lock);\
308} while (0)
309
310#define TSEC_GLOBAL_TO_RECEIVE_LOCK(sc) do {    \
311                mtx_unlock(&(sc)->transmit_lock);\
312} while (0)
313
314struct tsec_desc {
315        volatile uint16_t       flags;  /* descriptor flags */
316        volatile uint16_t       length; /* buffer length */
317        volatile uint32_t       bufptr; /* buffer pointer */
318};
319
320#define TSEC_READ_RETRY 10000
321#define TSEC_READ_DELAY 100
322
323/* Structures and defines for TCP/IP Off-load */
324struct tsec_tx_fcb {
325        volatile uint16_t       flags;
326        volatile uint8_t        l4_offset;
327        volatile uint8_t        l3_offset;
328        volatile uint16_t       ph_chsum;
329        volatile uint16_t       vlan;
330};
331
332struct tsec_rx_fcb {
333        volatile uint16_t       flags;
334        volatile uint8_t        rq_index;
335        volatile uint8_t        protocol;
336        volatile uint16_t       unused;
337        volatile uint16_t       vlan;
338};
339
340#define TSEC_CHECKSUM_FEATURES  (CSUM_IP | CSUM_TCP | CSUM_UDP)
341
342#define TSEC_TX_FCB_IP4         TSEC_TX_FCB_L3_IS_IP
343#define TSEC_TX_FCB_IP6         (TSEC_TX_FCB_L3_IS_IP | TSEC_TX_FCB_L3_IS_IP6)
344
345#define TSEC_TX_FCB_TCP         TSEC_TX_FCB_L4_IS_TCP_UDP
346#define TSEC_TX_FCB_UDP         (TSEC_TX_FCB_L4_IS_TCP_UDP | TSEC_TX_FCB_L4_IS_UDP)
347
348#define TSEC_RX_FCB_IP_CSUM_CHECKED(flags)                                      \
349                ((flags & (TSEC_RX_FCB_IP_FOUND | TSEC_RX_FCB_IP6_FOUND |       \
350                TSEC_RX_FCB_IP_CSUM | TSEC_RX_FCB_PARSE_ERROR))                 \
351                 == (TSEC_RX_FCB_IP_FOUND | TSEC_RX_FCB_IP_CSUM))
352
353#define TSEC_RX_FCB_TCP_UDP_CSUM_CHECKED(flags)                                 \
354                ((flags & (TSEC_RX_FCB_TCP_UDP_FOUND | TSEC_RX_FCB_TCP_UDP_CSUM \
355                | TSEC_RX_FCB_PARSE_ERROR))                                     \
356                == (TSEC_RX_FCB_TCP_UDP_FOUND | TSEC_RX_FCB_TCP_UDP_CSUM))
357
358/* Prototypes */
359extern devclass_t tsec_devclass;
360
361int     tsec_attach(struct tsec_softc *sc);
362int     tsec_detach(struct tsec_softc *sc);
363
364void    tsec_error_intr(void *arg);
365void    tsec_receive_intr(void *arg);
366void    tsec_transmit_intr(void *arg);
367
368int     tsec_miibus_readreg(device_t dev, int phy, int reg);
369int     tsec_miibus_writereg(device_t dev, int phy, int reg, int value);
370void    tsec_miibus_statchg(device_t dev);
371int     tsec_resume(device_t dev); /* XXX */
372int     tsec_shutdown(device_t dev);
373int     tsec_suspend(device_t dev); /* XXX */
374
375void    tsec_get_hwaddr(struct tsec_softc *sc, uint8_t *addr);
376
377#endif /* _IF_TSEC_H */
Note: See TracBrowser for help on using the repository browser.