Remove unused macros
[dragonfly.git] / sys / dev / netif / jme / if_jmevar.h
1 /*-
2  * Copyright (c) 2008, Pyun YongHyeon <yongari@FreeBSD.org>
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 unmodified, this list of conditions, and the following
10  *    disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25  * SUCH DAMAGE.
26  *
27  * $FreeBSD: src/sys/dev/jme/if_jmevar.h,v 1.1 2008/05/27 01:42:01 yongari Exp $
28  * $DragonFly: src/sys/dev/netif/jme/if_jmevar.h,v 1.8 2008/11/26 11:55:18 sephe Exp $
29  */
30
31 #ifndef _IF_JMEVAR_H
32 #define _IF_JMEVAR_H
33
34 #include <sys/queue.h>
35 #include <sys/callout.h>
36 #include <sys/taskqueue.h>
37
38 /*
39  * JMC250 supports upto JME_NDESC_MAX descriptors and the number of
40  * descriptors should be multiple of JME_NDESC_ALIGN.
41  */
42 #define JME_TX_DESC_CNT_DEF     384
43 #define JME_RX_DESC_CNT_DEF     256
44
45 #define JME_NDESC_ALIGN         16
46 #define JME_NDESC_MAX           1024
47
48 /*
49  * Tx/Rx descriptor queue base should be 16bytes aligned and
50  * should not cross 4G bytes boundary on the 64bits address
51  * mode.
52  */
53 #define JME_TX_RING_ALIGN       16
54 #define JME_RX_RING_ALIGN       16
55 #define JME_TSO_MAXSEGSIZE      4096
56 #define JME_TSO_MAXSIZE         (65535 + sizeof(struct ether_vlan_header))
57 #define JME_MAXTXSEGS           32
58 #define JME_RX_BUF_ALIGN        sizeof(uint64_t)
59 #define JME_SSB_ALIGN           16
60
61 #define JME_ADDR_LO(x)          ((uint64_t) (x) & 0xFFFFFFFF)
62 #define JME_ADDR_HI(x)          ((uint64_t) (x) >> 32)
63
64 #define JME_MSI_MESSAGES        8
65 #define JME_MSIX_MESSAGES       8
66
67 /* Water mark to kick reclaiming Tx buffers. */
68 #define JME_TX_DESC_HIWAT(sc)   \
69         ((sc)->jme_tx_desc_cnt - (((sc)->jme_tx_desc_cnt * 3) / 10))
70
71 /*
72  * JMC250 can send 9K jumbo frame on Tx path and can receive
73  * 65535 bytes.
74  */
75 #define JME_JUMBO_FRAMELEN      9216
76 #define JME_JUMBO_MTU                                                   \
77         (JME_JUMBO_FRAMELEN - sizeof(struct ether_vlan_header) -        \
78          ETHER_HDR_LEN - ETHER_CRC_LEN)
79 #define JME_MAX_MTU                                                     \
80         (ETHER_MAX_LEN + sizeof(struct ether_vlan_header) -             \
81          ETHER_HDR_LEN - ETHER_CRC_LEN)
82 /*
83  * JMC250 can't handle Tx checksum offload/TSO if frame length
84  * is larger than its FIFO size(2K). It's also good idea to not
85  * use jumbo frame if hardware is running at half-duplex media.
86  * Because the jumbo frame may not fit into the Tx FIFO,
87  * collisions make hardware fetch frame from host memory with
88  * DMA again which in turn slows down Tx performance
89  * significantly.
90  */
91 #define JME_TX_FIFO_SIZE        2000
92 /*
93  * JMC250 has just 4K Rx FIFO. To support jumbo frame that is
94  * larger than 4K bytes in length, Rx FIFO threshold should be
95  * adjusted to minimize Rx FIFO overrun.
96  */
97 #define JME_RX_FIFO_SIZE        4000
98
99 #define JME_DESC_INC(x, y)      ((x) = ((x) + 1) % (y))
100
101 struct jme_txdesc {
102         struct mbuf             *tx_m;
103         bus_dmamap_t            tx_dmamap;
104         int                     tx_ndesc;
105         struct jme_desc         *tx_desc;
106 };
107
108 struct jme_rxdesc {
109         struct mbuf             *rx_m;
110         bus_dmamap_t            rx_dmamap;
111         struct jme_desc         *rx_desc;
112 };
113
114 struct jme_chain_data {
115         /*
116          * Top level tags
117          */
118         bus_dma_tag_t           jme_ring_tag;   /* parent ring tag */
119         bus_dma_tag_t           jme_buffer_tag; /* parent mbuf/ssb tag */
120
121         /*
122          * Shadow status block
123          */
124         struct jme_ssb          *jme_ssb_block;
125         bus_addr_t              jme_ssb_block_paddr;
126         bus_dma_tag_t           jme_ssb_tag;
127         bus_dmamap_t            jme_ssb_map;
128
129         /*
130          * TX ring/descs
131          */
132         bus_dma_tag_t           jme_tx_tag;     /* TX mbuf tag */
133         struct jme_txdesc       *jme_txdesc;
134
135         struct jme_desc         *jme_tx_ring;
136         bus_addr_t              jme_tx_ring_paddr;
137         bus_dma_tag_t           jme_tx_ring_tag;
138         bus_dmamap_t            jme_tx_ring_map;
139
140         int                     jme_tx_prod;
141         int                     jme_tx_cons;
142         int                     jme_tx_cnt;
143
144         /*
145          * RX ring/descs
146          */
147         bus_dma_tag_t           jme_rx_tag;     /* RX mbuf tag */
148         bus_dmamap_t            jme_rx_sparemap;
149         struct jme_rxdesc       *jme_rxdesc;
150
151         struct jme_desc         *jme_rx_ring;
152         bus_addr_t              jme_rx_ring_paddr;
153         bus_dma_tag_t           jme_rx_ring_tag;
154         bus_dmamap_t            jme_rx_ring_map;
155
156         int                     jme_rx_cons;
157
158         int                     jme_rxlen;
159         struct mbuf             *jme_rxhead;
160         struct mbuf             *jme_rxtail;
161 };
162
163 #define JME_TX_RING_SIZE(sc)    \
164     (sizeof(struct jme_desc) * (sc)->jme_tx_desc_cnt)
165 #define JME_RX_RING_SIZE(sc)    \
166     (sizeof(struct jme_desc) * (sc)->jme_rx_desc_cnt)
167 #define JME_SSB_SIZE            sizeof(struct jme_ssb)
168
169 struct jme_dmamap_ctx {
170         int                     nsegs;
171         bus_dma_segment_t       *segs;
172 };
173
174 /*
175  * Software state per device.
176  */
177 struct jme_softc {
178         struct arpcom           arpcom;
179         device_t                jme_dev;
180
181         int                     jme_mem_rid;
182         struct resource         *jme_mem_res;
183         bus_space_tag_t         jme_mem_bt;
184         bus_space_handle_t      jme_mem_bh;
185
186         int                     jme_irq_rid;
187         struct resource         *jme_irq_res;
188         void                    *jme_irq_handle;
189
190         device_t                jme_miibus;
191         int                     jme_phyaddr;
192         bus_addr_t              jme_lowaddr;
193
194         uint32_t                jme_clksrc;
195         uint32_t                jme_clksrc_1000;
196         uint32_t                jme_tx_dma_size;
197         uint32_t                jme_rx_dma_size;
198
199         uint32_t                jme_caps;
200 #define JME_CAP_FPGA            0x0001
201 #define JME_CAP_PCIE            0x0002
202 #define JME_CAP_PMCAP           0x0004
203 #define JME_CAP_FASTETH         0x0008
204 #define JME_CAP_JUMBO           0x0010
205
206         uint32_t                jme_workaround;
207 #define JME_WA_EXTFIFO          0x0001
208 #define JME_WA_HDX              0x0002
209
210         uint32_t                jme_flags;
211 #define JME_FLAG_MSI            0x0001
212 #define JME_FLAG_MSIX           0x0002
213 #define JME_FLAG_DETACH         0x0004
214 #define JME_FLAG_LINK           0x0008
215
216         struct callout          jme_tick_ch;
217         struct jme_chain_data   jme_cdata;
218         int                     jme_if_flags;
219         uint32_t                jme_txcsr;
220         uint32_t                jme_rxcsr;
221
222         int                     jme_txd_spare;
223
224         struct sysctl_ctx_list  jme_sysctl_ctx;
225         struct sysctl_oid       *jme_sysctl_tree;
226
227         /*
228          * Sysctl variables
229          */
230         int                     jme_tx_coal_to;
231         int                     jme_tx_coal_pkt;
232         int                     jme_rx_coal_to;
233         int                     jme_rx_coal_pkt;
234         int                     jme_rx_desc_cnt;
235         int                     jme_tx_desc_cnt;
236 };
237
238 /* Register access macros. */
239 #define CSR_WRITE_4(_sc, reg, val)      \
240         bus_space_write_4((_sc)->jme_mem_bt, (_sc)->jme_mem_bh, (reg), (val))
241 #define CSR_READ_4(_sc, reg)            \
242         bus_space_read_4((_sc)->jme_mem_bt, (_sc)->jme_mem_bh, (reg))
243
244 #define JME_MAXERR      5
245
246 #define JME_RXCHAIN_RESET(_sc)                                          \
247 do {                                                                    \
248         (_sc)->jme_cdata.jme_rxhead = NULL;                             \
249         (_sc)->jme_cdata.jme_rxtail = NULL;                             \
250         (_sc)->jme_cdata.jme_rxlen = 0;                                 \
251 } while (0)
252
253 #define JME_TX_TIMEOUT          5
254 #define JME_TIMEOUT             1000
255 #define JME_PHY_TIMEOUT         1000
256 #define JME_EEPROM_TIMEOUT      1000
257
258 #define JME_TXD_RSVD            1
259
260 #endif