1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253
|
/*-
* Copyright (c) 2008, Pyun YongHyeon <yongari@FreeBSD.org>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice unmodified, this list of conditions, and the following
* disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $FreeBSD$
*/
#ifndef _IF_JMEVAR_H
#define _IF_JMEVAR_H
#include <sys/queue.h>
#include <sys/callout.h>
#include <sys/taskqueue.h>
/*
* JMC250 supports upto 1024 descriptors and the number of
* descriptors should be multiple of 16.
*/
#define JME_TX_RING_CNT 384
#define JME_RX_RING_CNT 256
/*
* Tx/Rx descriptor queue base should be 16bytes aligned and
* should not cross 4G bytes boundary on the 64bits address
* mode.
*/
#define JME_TX_RING_ALIGN 16
#define JME_RX_RING_ALIGN 16
#define JME_TSO_MAXSEGSIZE 4096
#define JME_TSO_MAXSIZE (65535 + sizeof(struct ether_vlan_header))
#define JME_MAXTXSEGS 35
#define JME_RX_BUF_ALIGN sizeof(uint64_t)
#define JME_SSB_ALIGN 16
#define JME_ADDR_LO(x) ((uint64_t) (x) & 0xFFFFFFFF)
#define JME_ADDR_HI(x) ((uint64_t) (x) >> 32)
#define JME_MSI_MESSAGES 8
#define JME_MSIX_MESSAGES 8
/* Water mark to kick reclaiming Tx buffers. */
#define JME_TX_DESC_HIWAT (JME_TX_RING_CNT - (((JME_TX_RING_CNT) * 3) / 10))
/*
* JMC250 can send 9K jumbo frame on Tx path and can receive
* 65535 bytes.
*/
#define JME_JUMBO_FRAMELEN 9216
#define JME_JUMBO_MTU \
(JME_JUMBO_FRAMELEN - sizeof(struct ether_vlan_header) - \
ETHER_HDR_LEN - ETHER_CRC_LEN)
#define JME_MAX_MTU \
(ETHER_MAX_LEN + sizeof(struct ether_vlan_header) - \
ETHER_HDR_LEN - ETHER_CRC_LEN)
/*
* JMC250 can't handle Tx checksum offload/TSO if frame length
* is larger than its FIFO size(2K). It's also good idea to not
* use jumbo frame if hardware is running at half-duplex media.
* Because the jumbo frame may not fit into the Tx FIFO,
* collisions make hardware fetch frame from host memory with
* DMA again which in turn slows down Tx performance
* significantly.
*/
#define JME_TX_FIFO_SIZE 2000
/*
* JMC250 has just 4K Rx FIFO. To support jumbo frame that is
* larger than 4K bytes in length, Rx FIFO threshold should be
* adjusted to minimize Rx FIFO overrun.
*/
#define JME_RX_FIFO_SIZE 4000
#define JME_DESC_INC(x, y) ((x) = ((x) + 1) % (y))
#define JME_PROC_MIN 10
#define JME_PROC_DEFAULT (JME_RX_RING_CNT / 2)
#define JME_PROC_MAX (JME_RX_RING_CNT - 1)
struct jme_txdesc {
struct mbuf *tx_m;
bus_dmamap_t tx_dmamap;
int tx_ndesc;
struct jme_desc *tx_desc;
};
struct jme_rxdesc {
struct mbuf *rx_m;
bus_dmamap_t rx_dmamap;
struct jme_desc *rx_desc;
};
struct jme_chain_data{
bus_dma_tag_t jme_ring_tag;
bus_dma_tag_t jme_buffer_tag;
bus_dma_tag_t jme_ssb_tag;
bus_dmamap_t jme_ssb_map;
bus_dma_tag_t jme_tx_tag;
struct jme_txdesc jme_txdesc[JME_TX_RING_CNT];
bus_dma_tag_t jme_rx_tag;
struct jme_rxdesc jme_rxdesc[JME_RX_RING_CNT];
bus_dma_tag_t jme_tx_ring_tag;
bus_dmamap_t jme_tx_ring_map;
bus_dma_tag_t jme_rx_ring_tag;
bus_dmamap_t jme_rx_ring_map;
bus_dmamap_t jme_rx_sparemap;
int jme_tx_prod;
int jme_tx_cons;
int jme_tx_cnt;
int jme_rx_cons;
int jme_rxlen;
struct mbuf *jme_rxhead;
struct mbuf *jme_rxtail;
};
struct jme_ring_data {
struct jme_desc *jme_tx_ring;
bus_addr_t jme_tx_ring_paddr;
struct jme_desc *jme_rx_ring;
bus_addr_t jme_rx_ring_paddr;
struct jme_ssb *jme_ssb_block;
bus_addr_t jme_ssb_block_paddr;
};
#define JME_TX_RING_ADDR(sc, i) \
((sc)->jme_rdata.jme_tx_ring_paddr + sizeof(struct jme_desc) * (i))
#define JME_RX_RING_ADDR(sc, i) \
((sc)->jme_rdata.jme_rx_ring_paddr + sizeof(struct jme_desc) * (i))
#define JME_TX_RING_SIZE \
(sizeof(struct jme_desc) * JME_TX_RING_CNT)
#define JME_RX_RING_SIZE \
(sizeof(struct jme_desc) * JME_RX_RING_CNT)
#define JME_SSB_SIZE sizeof(struct jme_ssb)
/* Statistics counters. */
struct jme_hw_stats {
uint32_t rx_good_frames;
uint32_t rx_crc_errs;
uint32_t rx_mii_errs;
uint32_t rx_fifo_oflows;
uint32_t rx_desc_empty;
uint32_t rx_bad_frames;
uint32_t tx_good_frames;
uint32_t tx_bad_frames;
};
/*
* Software state per device.
*/
struct jme_softc {
struct ifnet *jme_ifp;
device_t jme_dev;
device_t jme_miibus;
struct resource *jme_res[1];
struct resource_spec *jme_res_spec;
struct resource *jme_irq[JME_MSI_MESSAGES];
struct resource_spec *jme_irq_spec;
void *jme_intrhand[JME_MSI_MESSAGES];
int jme_rev;
int jme_chip_rev;
int jme_phyaddr;
uint8_t jme_eaddr[ETHER_ADDR_LEN];
uint32_t jme_tx_dma_size;
uint32_t jme_rx_dma_size;
int jme_flags;
#define JME_FLAG_FPGA 0x00000001
#define JME_FLAG_PCIE 0x00000002
#define JME_FLAG_PCIX 0x00000004
#define JME_FLAG_MSI 0x00000008
#define JME_FLAG_MSIX 0x00000010
#define JME_FLAG_PMCAP 0x00000020
#define JME_FLAG_FASTETH 0x00000040
#define JME_FLAG_NOJUMBO 0x00000080
#define JME_FLAG_RXCLK 0x00000100
#define JME_FLAG_TXCLK 0x00000200
#define JME_FLAG_DMA32BIT 0x00000400
#define JME_FLAG_HWMIB 0x00000800
#define JME_FLAG_EFUSE 0x00001000
#define JME_FLAG_PCCPCD 0x00002000
#define JME_FLAG_DETACH 0x40000000
#define JME_FLAG_LINK 0x80000000
struct jme_hw_stats jme_ostats;
struct jme_hw_stats jme_stats;
struct callout jme_tick_ch;
struct jme_chain_data jme_cdata;
struct jme_ring_data jme_rdata;
int jme_if_flags;
int jme_watchdog_timer;
uint32_t jme_txcsr;
uint32_t jme_rxcsr;
int jme_process_limit;
int jme_tx_coal_to;
int jme_tx_pcd_to;
int jme_tx_coal_pkt;
int jme_rx_coal_to;
int jme_rx_pcd_to;
int jme_rx_coal_pkt;
volatile int jme_morework;
struct task jme_int_task;
struct task jme_link_task;
struct taskqueue *jme_tq;
struct mtx jme_mtx;
};
/* Register access macros. */
#define CSR_WRITE_4(_sc, reg, val) \
bus_write_4((_sc)->jme_res[0], (reg), (val))
#define CSR_READ_4(_sc, reg) \
bus_read_4((_sc)->jme_res[0], (reg))
#define JME_LOCK(_sc) mtx_lock(&(_sc)->jme_mtx)
#define JME_UNLOCK(_sc) mtx_unlock(&(_sc)->jme_mtx)
#define JME_LOCK_ASSERT(_sc) mtx_assert(&(_sc)->jme_mtx, MA_OWNED)
#define JME_MAXERR 5
#define JME_RXCHAIN_RESET(_sc) \
do { \
(_sc)->jme_cdata.jme_rxhead = NULL; \
(_sc)->jme_cdata.jme_rxtail = NULL; \
(_sc)->jme_cdata.jme_rxlen = 0; \
} while (0)
#define JME_TX_TIMEOUT 5
#define JME_TIMEOUT 1000
#define JME_PHY_TIMEOUT 1000
#define JME_EEPROM_TIMEOUT 1000
#endif
|