2 * Copyright (c) 2008, Pyun YongHyeon <yongari@FreeBSD.org>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice unmodified, this list of conditions, and the following
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.
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
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.4 2008/09/13 04:04:39 sephe Exp $
34 #include <sys/queue.h>
35 #include <sys/callout.h>
36 #include <sys/taskqueue.h>
39 * JMC250 supports upto 1024 descriptors and the number of
40 * descriptors should be multiple of 16.
42 #define JME_TX_RING_CNT 384
43 #define JME_RX_RING_CNT 256
45 * Tx/Rx descriptor queue base should be 16bytes aligned and
46 * should not cross 4G bytes boundary on the 64bits address
49 #define JME_TX_RING_ALIGN 16
50 #define JME_RX_RING_ALIGN 16
51 #define JME_TSO_MAXSEGSIZE 4096
52 #define JME_TSO_MAXSIZE (65535 + sizeof(struct ether_vlan_header))
53 #define JME_MAXTXSEGS 32
54 #define JME_RX_BUF_ALIGN sizeof(uint64_t)
55 #define JME_SSB_ALIGN 16
57 #define JME_ADDR_LO(x) ((uint64_t) (x) & 0xFFFFFFFF)
58 #define JME_ADDR_HI(x) ((uint64_t) (x) >> 32)
60 #define JME_MSI_MESSAGES 8
61 #define JME_MSIX_MESSAGES 8
63 /* Water mark to kick reclaiming Tx buffers. */
64 #define JME_TX_DESC_HIWAT (JME_TX_RING_CNT - (((JME_TX_RING_CNT) * 3) / 10))
67 * JMC250 can send 9K jumbo frame on Tx path and can receive
70 #define JME_JUMBO_FRAMELEN 9216
71 #define JME_JUMBO_MTU \
72 (JME_JUMBO_FRAMELEN - sizeof(struct ether_vlan_header) - \
73 ETHER_HDR_LEN - ETHER_CRC_LEN)
75 (ETHER_MAX_LEN + sizeof(struct ether_vlan_header) - \
76 ETHER_HDR_LEN - ETHER_CRC_LEN)
78 * JMC250 can't handle Tx checksum offload/TSO if frame length
79 * is larger than its FIFO size(2K). It's also good idea to not
80 * use jumbo frame if hardware is running at half-duplex media.
81 * Because the jumbo frame may not fit into the Tx FIFO,
82 * collisions make hardware fetch frame from host memory with
83 * DMA again which in turn slows down Tx performance
86 #define JME_TX_FIFO_SIZE 2000
88 * JMC250 has just 4K Rx FIFO. To support jumbo frame that is
89 * larger than 4K bytes in length, Rx FIFO threshold should be
90 * adjusted to minimize Rx FIFO overrun.
92 #define JME_RX_FIFO_SIZE 4000
94 #define JME_DESC_INC(x, y) ((x) = ((x) + 1) % (y))
96 #define JME_PROC_MIN 10
97 #define JME_PROC_DEFAULT (JME_RX_RING_CNT / 2)
98 #define JME_PROC_MAX (JME_RX_RING_CNT - 1)
102 bus_dmamap_t tx_dmamap;
104 struct jme_desc *tx_desc;
109 bus_dmamap_t rx_dmamap;
110 struct jme_desc *rx_desc;
113 struct jme_chain_data{
114 bus_dma_tag_t jme_ring_tag;
115 bus_dma_tag_t jme_buffer_tag;
116 bus_dma_tag_t jme_ssb_tag;
117 bus_dmamap_t jme_ssb_map;
118 bus_dma_tag_t jme_tx_tag;
119 struct jme_txdesc jme_txdesc[JME_TX_RING_CNT];
120 bus_dma_tag_t jme_rx_tag;
121 struct jme_rxdesc jme_rxdesc[JME_RX_RING_CNT];
122 bus_dma_tag_t jme_tx_ring_tag;
123 bus_dmamap_t jme_tx_ring_map;
124 bus_dma_tag_t jme_rx_ring_tag;
125 bus_dmamap_t jme_rx_ring_map;
126 bus_dmamap_t jme_rx_sparemap;
134 struct mbuf *jme_rxhead;
135 struct mbuf *jme_rxtail;
138 struct jme_ring_data {
139 struct jme_desc *jme_tx_ring;
140 bus_addr_t jme_tx_ring_paddr;
141 struct jme_desc *jme_rx_ring;
142 bus_addr_t jme_rx_ring_paddr;
143 struct jme_ssb *jme_ssb_block;
144 bus_addr_t jme_ssb_block_paddr;
147 #define JME_TX_RING_ADDR(sc, i) \
148 ((sc)->jme_rdata.jme_tx_ring_paddr + sizeof(struct jme_desc) * (i))
149 #define JME_RX_RING_ADDR(sc, i) \
150 ((sc)->jme_rdata.jme_rx_ring_paddr + sizeof(struct jme_desc) * (i))
152 #define JME_TX_RING_SIZE \
153 (sizeof(struct jme_desc) * JME_TX_RING_CNT)
154 #define JME_RX_RING_SIZE \
155 (sizeof(struct jme_desc) * JME_RX_RING_CNT)
156 #define JME_SSB_SIZE sizeof(struct jme_ssb)
158 struct jme_dmamap_ctx {
160 bus_dma_segment_t *segs;
164 * Software state per device.
167 struct arpcom arpcom;
171 struct resource *jme_mem_res;
172 bus_space_tag_t jme_mem_bt;
173 bus_space_handle_t jme_mem_bh;
176 struct resource *jme_irq_res;
177 void *jme_irq_handle;
182 uint32_t jme_tx_dma_size;
183 uint32_t jme_rx_dma_size;
186 #define JME_CAP_FPGA 0x0001
187 #define JME_CAP_PCIE 0x0002
188 #define JME_CAP_PMCAP 0x0004
189 #define JME_CAP_FASTETH 0x0008
190 #define JME_CAP_JUMBO 0x0010
191 #define JME_CAP_EXTFIFO 0x0020
194 #define JME_FLAG_MSI 0x0001
195 #define JME_FLAG_MSIX 0x0002
196 #define JME_FLAG_DETACH 0x0004
197 #define JME_FLAG_LINK 0x0008
199 struct callout jme_tick_ch;
200 struct jme_chain_data jme_cdata;
201 struct jme_ring_data jme_rdata;
208 struct sysctl_ctx_list jme_sysctl_ctx;
209 struct sysctl_oid *jme_sysctl_tree;
214 int jme_process_limit;
221 /* Register access macros. */
222 #define CSR_WRITE_4(_sc, reg, val) \
223 bus_space_write_4((_sc)->jme_mem_bt, (_sc)->jme_mem_bh, (reg), (val))
224 #define CSR_READ_4(_sc, reg) \
225 bus_space_read_4((_sc)->jme_mem_bt, (_sc)->jme_mem_bh, (reg))
229 #define JME_RXCHAIN_RESET(_sc) \
231 (_sc)->jme_cdata.jme_rxhead = NULL; \
232 (_sc)->jme_cdata.jme_rxtail = NULL; \
233 (_sc)->jme_cdata.jme_rxlen = 0; \
236 #define JME_TX_TIMEOUT 5
237 #define JME_TIMEOUT 1000
238 #define JME_PHY_TIMEOUT 1000
239 #define JME_EEPROM_TIMEOUT 1000
241 #define JME_TXD_RSVD 1