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$
28 */
29
30 #ifndef _IF_JMEVAR_H
31 #define _IF_JMEVAR_H
32
33 #include <sys/queue.h>
34 #include <sys/callout.h>
35 #include <sys/taskqueue.h>
36
37 /*
38 * JMC250 supports upto 1024 descriptors and the number of
39 * descriptors should be multiple of 16.
40 */
41 #define JME_TX_RING_CNT 384
42 #define JME_RX_RING_CNT 256
43 /*
44 * Tx/Rx descriptor queue base should be 16bytes aligned and
45 * should not cross 4G bytes boundary on the 64bits address
46 * mode.
47 */
48 #define JME_TX_RING_ALIGN 16
49 #define JME_RX_RING_ALIGN 16
50 #define JME_TSO_MAXSEGSIZE 4096
51 #define JME_TSO_MAXSIZE (65535 + sizeof(struct ether_vlan_header))
52 #define JME_MAXTXSEGS 32
53 #define JME_RX_BUF_ALIGN sizeof(uint64_t)
54 #define JME_SSB_ALIGN 16
55
56 #define JME_ADDR_LO(x) ((uint64_t) (x) & 0xFFFFFFFF)
57 #define JME_ADDR_HI(x) ((uint64_t) (x) >> 32)
58
59 #define JME_MSI_MESSAGES 8
60 #define JME_MSIX_MESSAGES 8
61
62 /* Water mark to kick reclaiming Tx buffers. */
63 #define JME_TX_DESC_HIWAT (JME_TX_RING_CNT - (((JME_TX_RING_CNT) * 3) / 10))
64
65 /*
66 * JMC250 can send 9K jumbo frame on Tx path and can receive
67 * 65535 bytes.
68 */
69 #define JME_JUMBO_FRAMELEN 9216
70 #define JME_JUMBO_MTU \
71 (JME_JUMBO_FRAMELEN - sizeof(struct ether_vlan_header) - \
72 ETHER_HDR_LEN - ETHER_CRC_LEN)
73 #define JME_MAX_MTU \
74 (ETHER_MAX_LEN + sizeof(struct ether_vlan_header) - \
75 ETHER_HDR_LEN - ETHER_CRC_LEN)
76 /*
77 * JMC250 can't handle Tx checksum offload/TSO if frame length
78 * is larger than its FIFO size(2K). It's also good idea to not
79 * use jumbo frame if hardware is running at half-duplex media.
80 * Because the jumbo frame may not fit into the Tx FIFO,
81 * collisions make hardware fetch frame from host memory with
82 * DMA again which in turn slows down Tx performance
83 * significantly.
84 */
85 #define JME_TX_FIFO_SIZE 2000
86 /*
87 * JMC250 has just 4K Rx FIFO. To support jumbo frame that is
88 * larger than 4K bytes in length, Rx FIFO threshold should be
89 * adjusted to minimize Rx FIFO overrun.
90 */
91 #define JME_RX_FIFO_SIZE 4000
92
93 #define JME_DESC_INC(x, y) ((x) = ((x) + 1) % (y))
94
95 #define JME_PROC_MIN 10
96 #define JME_PROC_DEFAULT (JME_RX_RING_CNT / 2)
97 #define JME_PROC_MAX (JME_RX_RING_CNT - 1)
98
99 struct jme_txdesc {
100 struct mbuf *tx_m;
101 bus_dmamap_t tx_dmamap;
102 int tx_ndesc;
103 struct jme_desc *tx_desc;
104 };
105
106 struct jme_rxdesc {
107 struct mbuf *rx_m;
108 bus_dmamap_t rx_dmamap;
109 struct jme_desc *rx_desc;
110 };
111
112 struct jme_chain_data{
113 bus_dma_tag_t jme_ring_tag;
114 bus_dma_tag_t jme_buffer_tag;
115 bus_dma_tag_t jme_ssb_tag;
116 bus_dmamap_t jme_ssb_map;
117 bus_dma_tag_t jme_tx_tag;
118 struct jme_txdesc jme_txdesc[JME_TX_RING_CNT];
119 bus_dma_tag_t jme_rx_tag;
120 struct jme_rxdesc jme_rxdesc[JME_RX_RING_CNT];
121 bus_dma_tag_t jme_tx_ring_tag;
122 bus_dmamap_t jme_tx_ring_map;
123 bus_dma_tag_t jme_rx_ring_tag;
124 bus_dmamap_t jme_rx_ring_map;
125 bus_dmamap_t jme_rx_sparemap;
126
127 int jme_tx_prod;
128 int jme_tx_cons;
129 int jme_tx_cnt;
130 int jme_rx_cons;
131 int jme_rxlen;
132
133 struct mbuf *jme_rxhead;
134 struct mbuf *jme_rxtail;
135 };
136
137 struct jme_ring_data {
138 struct jme_desc *jme_tx_ring;
139 bus_addr_t jme_tx_ring_paddr;
140 struct jme_desc *jme_rx_ring;
141 bus_addr_t jme_rx_ring_paddr;
142 struct jme_ssb *jme_ssb_block;
143 bus_addr_t jme_ssb_block_paddr;
144 };
145
146 #define JME_TX_RING_ADDR(sc, i) \
147 ((sc)->jme_rdata.jme_tx_ring_paddr + sizeof(struct jme_desc) * (i))
148 #define JME_RX_RING_ADDR(sc, i) \
149 ((sc)->jme_rdata.jme_rx_ring_paddr + sizeof(struct jme_desc) * (i))
150
151 #define JME_TX_RING_SIZE \
152 (sizeof(struct jme_desc) * JME_TX_RING_CNT)
153 #define JME_RX_RING_SIZE \
154 (sizeof(struct jme_desc) * JME_RX_RING_CNT)
155 #define JME_SSB_SIZE sizeof(struct jme_ssb)
156
157 /*
158 * Software state per device.
159 */
160 struct jme_softc {
161 struct ifnet *jme_ifp;
162 device_t jme_dev;
163 device_t jme_miibus;
164 struct resource *jme_res[1];
165 struct resource_spec *jme_res_spec;
166 struct resource *jme_irq[JME_MSI_MESSAGES];
167 struct resource_spec *jme_irq_spec;
168 void *jme_intrhand[JME_MSI_MESSAGES];
169 int jme_rev;
170 int jme_chip_rev;
171 int jme_phyaddr;
172 uint8_t jme_eaddr[ETHER_ADDR_LEN];
173 uint32_t jme_tx_dma_size;
174 uint32_t jme_rx_dma_size;
175 int jme_flags;
176 #define JME_FLAG_FPGA 0x0001
177 #define JME_FLAG_PCIE 0x0002
178 #define JME_FLAG_PCIX 0x0003
179 #define JME_FLAG_MSI 0x0004
180 #define JME_FLAG_MSIX 0x0010
181 #define JME_FLAG_PMCAP 0x0020
182 #define JME_FLAG_FASTETH 0x0040
183 #define JME_FLAG_NOJUMBO 0x0080
184 #define JME_FLAG_DETACH 0x4000
185 #define JME_FLAG_LINK 0x8000
186
187 struct callout jme_tick_ch;
188 struct jme_chain_data jme_cdata;
189 struct jme_ring_data jme_rdata;
190 int jme_if_flags;
191 int jme_watchdog_timer;
192 uint32_t jme_txcsr;
193 uint32_t jme_rxcsr;
194 int jme_process_limit;
195 int jme_tx_coal_to;
196 int jme_tx_coal_pkt;
197 int jme_rx_coal_to;
198 int jme_rx_coal_pkt;
199 volatile int jme_morework;
200
201 struct task jme_int_task;
202 struct task jme_tx_task;
203 struct task jme_link_task;
204 struct taskqueue *jme_tq;
205 struct mtx jme_mtx;
206 };
207
208 /* Register access macros. */
209 #define CSR_WRITE_4(_sc, reg, val) \
210 bus_write_4((_sc)->jme_res[0], (reg), (val))
211 #define CSR_READ_4(_sc, reg) \
212 bus_read_4((_sc)->jme_res[0], (reg))
213
214 #define JME_LOCK(_sc) mtx_lock(&(_sc)->jme_mtx)
215 #define JME_UNLOCK(_sc) mtx_unlock(&(_sc)->jme_mtx)
216 #define JME_LOCK_ASSERT(_sc) mtx_assert(&(_sc)->jme_mtx, MA_OWNED)
217
218 #define JME_MAXERR 5
219
220 #define JME_RXCHAIN_RESET(_sc) \
221 do { \
222 (_sc)->jme_cdata.jme_rxhead = NULL; \
223 (_sc)->jme_cdata.jme_rxtail = NULL; \
224 (_sc)->jme_cdata.jme_rxlen = 0; \
225 } while (0)
226
227 #define JME_TX_TIMEOUT 5
228 #define JME_TIMEOUT 1000
229 #define JME_PHY_TIMEOUT 1000
230 #define JME_EEPROM_TIMEOUT 1000
231
232 #endif
Cache object: f80bb2b9c0ba916c38a0ce1fd1550a8d
|