sfxge.h revision 278940
1/*- 2 * Copyright (c) 2010-2011 Solarflare Communications, Inc. 3 * All rights reserved. 4 * 5 * This software was developed in part by Philip Paeps under contract for 6 * Solarflare Communications, Inc. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 1. Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * 2. Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in the 15 * documentation and/or other materials provided with the distribution. 16 * 17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 * SUCH DAMAGE. 28 * 29 * $FreeBSD: head/sys/dev/sfxge/sfxge.h 278940 2015-02-18 06:21:59Z arybchik $ 30 */ 31 32#ifndef _SFXGE_H 33#define _SFXGE_H 34 35#include <sys/param.h> 36#include <sys/kernel.h> 37#include <sys/condvar.h> 38#include <sys/socket.h> 39#include <sys/sysctl.h> 40#include <sys/sx.h> 41#include <vm/uma.h> 42 43#include <net/ethernet.h> 44#include <net/if.h> 45#include <net/if_var.h> 46#include <net/if_media.h> 47#include <net/if_types.h> 48 49/* 50 * Backward-compatibility 51 */ 52#ifndef CACHE_LINE_SIZE 53/* This should be right on most machines the driver will be used on, and 54 * we needn't care too much about wasting a few KB per interface. 55 */ 56#define CACHE_LINE_SIZE 128 57#endif 58#ifndef IFCAP_LINKSTATE 59#define IFCAP_LINKSTATE 0 60#endif 61#ifndef IFCAP_VLAN_HWTSO 62#define IFCAP_VLAN_HWTSO 0 63#endif 64#ifndef IFM_10G_T 65#define IFM_10G_T IFM_UNKNOWN 66#endif 67#ifndef IFM_10G_KX4 68#define IFM_10G_KX4 IFM_10G_CX4 69#endif 70#if __FreeBSD_version >= 800054 71/* Networking core is multiqueue aware. We can manage our own TX 72 * queues and use m_pkthdr.flowid. 73 */ 74#define SFXGE_HAVE_MQ 75#endif 76#if (__FreeBSD_version >= 800501 && __FreeBSD_version < 900000) || \ 77 __FreeBSD_version >= 900003 78#define SFXGE_HAVE_DESCRIBE_INTR 79#endif 80#ifdef IFM_ETH_RXPAUSE 81#define SFXGE_HAVE_PAUSE_MEDIAOPTS 82#endif 83#ifndef CTLTYPE_U64 84#define CTLTYPE_U64 CTLTYPE_QUAD 85#endif 86 87#include "sfxge_rx.h" 88#include "sfxge_tx.h" 89 90#define ROUNDUP_POW_OF_TWO(_n) (1ULL << flsl((_n) - 1)) 91 92#define SFXGE_IP_ALIGN 2 93 94#define SFXGE_ETHERTYPE_LOOPBACK 0x9000 /* Xerox loopback */ 95 96enum sfxge_evq_state { 97 SFXGE_EVQ_UNINITIALIZED = 0, 98 SFXGE_EVQ_INITIALIZED, 99 SFXGE_EVQ_STARTING, 100 SFXGE_EVQ_STARTED 101}; 102 103#define SFXGE_EV_BATCH 16384 104 105struct sfxge_evq { 106 /* Structure members below are sorted by usage order */ 107 struct sfxge_softc *sc; 108 struct mtx lock; 109 unsigned int index; 110 enum sfxge_evq_state init_state; 111 efsys_mem_t mem; 112 efx_evq_t *common; 113 unsigned int read_ptr; 114 boolean_t exception; 115 unsigned int rx_done; 116 unsigned int tx_done; 117 118 /* Linked list of TX queues with completions to process */ 119 struct sfxge_txq *txq; 120 struct sfxge_txq **txqs; 121 122 /* Structure members not used on event processing path */ 123 unsigned int buf_base_id; 124 unsigned int entries; 125 char lock_name[SFXGE_LOCK_NAME_MAX]; 126} __aligned(CACHE_LINE_SIZE); 127 128#define SFXGE_NDESCS 1024 129#define SFXGE_MODERATION 30 130 131enum sfxge_intr_state { 132 SFXGE_INTR_UNINITIALIZED = 0, 133 SFXGE_INTR_INITIALIZED, 134 SFXGE_INTR_TESTING, 135 SFXGE_INTR_STARTED 136}; 137 138struct sfxge_intr_hdl { 139 int eih_rid; 140 void *eih_tag; 141 struct resource *eih_res; 142}; 143 144struct sfxge_intr { 145 enum sfxge_intr_state state; 146 struct resource *msix_res; 147 struct sfxge_intr_hdl *table; 148 int n_alloc; 149 int type; 150 efsys_mem_t status; 151 uint32_t zero_count; 152}; 153 154enum sfxge_mcdi_state { 155 SFXGE_MCDI_UNINITIALIZED = 0, 156 SFXGE_MCDI_INITIALIZED, 157 SFXGE_MCDI_BUSY, 158 SFXGE_MCDI_COMPLETED 159}; 160 161struct sfxge_mcdi { 162 struct mtx lock; 163 struct cv cv; 164 enum sfxge_mcdi_state state; 165 efx_mcdi_transport_t transport; 166 167 /* Only used in debugging output */ 168 char lock_name[SFXGE_LOCK_NAME_MAX]; 169}; 170 171struct sfxge_hw_stats { 172 clock_t update_time; 173 efsys_mem_t dma_buf; 174 void *decode_buf; 175}; 176 177enum sfxge_port_state { 178 SFXGE_PORT_UNINITIALIZED = 0, 179 SFXGE_PORT_INITIALIZED, 180 SFXGE_PORT_STARTED 181}; 182 183struct sfxge_port { 184 struct sfxge_softc *sc; 185 struct mtx lock; 186 enum sfxge_port_state init_state; 187#ifndef SFXGE_HAVE_PAUSE_MEDIAOPTS 188 unsigned int wanted_fc; 189#endif 190 struct sfxge_hw_stats phy_stats; 191 struct sfxge_hw_stats mac_stats; 192 efx_link_mode_t link_mode; 193 194 /* Only used in debugging output */ 195 char lock_name[SFXGE_LOCK_NAME_MAX]; 196}; 197 198enum sfxge_softc_state { 199 SFXGE_UNINITIALIZED = 0, 200 SFXGE_INITIALIZED, 201 SFXGE_REGISTERED, 202 SFXGE_STARTED 203}; 204 205struct sfxge_softc { 206 device_t dev; 207 struct sx softc_lock; 208 char softc_lock_name[SFXGE_LOCK_NAME_MAX]; 209 enum sfxge_softc_state init_state; 210 struct ifnet *ifnet; 211 unsigned int if_flags; 212 struct sysctl_oid *stats_node; 213 struct sysctl_oid *txqs_node; 214 215 struct task task_reset; 216 217 efx_family_t family; 218 caddr_t vpd_data; 219 size_t vpd_size; 220 efx_nic_t *enp; 221 efsys_lock_t enp_lock; 222 223 unsigned int rxq_entries; 224 unsigned int txq_entries; 225 226 bus_dma_tag_t parent_dma_tag; 227 efsys_bar_t bar; 228 229 struct sfxge_intr intr; 230 struct sfxge_mcdi mcdi; 231 struct sfxge_port port; 232 uint32_t buffer_table_next; 233 234 struct sfxge_evq *evq[SFXGE_RX_SCALE_MAX]; 235 unsigned int ev_moderation; 236#if EFSYS_OPT_QSTATS 237 clock_t ev_stats_update_time; 238 uint64_t ev_stats[EV_NQSTATS]; 239#endif 240 241 unsigned int max_rss_channels; 242 uma_zone_t rxq_cache; 243 struct sfxge_rxq *rxq[SFXGE_RX_SCALE_MAX]; 244 unsigned int rx_indir_table[SFXGE_RX_SCALE_MAX]; 245 246#ifdef SFXGE_HAVE_MQ 247 struct sfxge_txq *txq[SFXGE_TXQ_NTYPES + SFXGE_RX_SCALE_MAX]; 248#else 249 struct sfxge_txq *txq[SFXGE_TXQ_NTYPES]; 250#endif 251 252 struct ifmedia media; 253 254 size_t rx_prefix_size; 255 size_t rx_buffer_size; 256 uma_zone_t rx_buffer_zone; 257 258#ifndef SFXGE_HAVE_MQ 259 struct mtx tx_lock __aligned(CACHE_LINE_SIZE); 260 char tx_lock_name[SFXGE_LOCK_NAME_MAX]; 261#endif 262 263 unsigned int evq_count; 264 unsigned int rxq_count; 265 unsigned int txq_count; 266}; 267 268#define SFXGE_LINK_UP(sc) ((sc)->port.link_mode != EFX_LINK_DOWN) 269#define SFXGE_RUNNING(sc) ((sc)->ifnet->if_drv_flags & IFF_DRV_RUNNING) 270 271#define SFXGE_PARAM(_name) "hw.sfxge." #_name 272 273SYSCTL_DECL(_hw_sfxge); 274 275/* 276 * From sfxge.c. 277 */ 278extern void sfxge_schedule_reset(struct sfxge_softc *sc); 279extern void sfxge_sram_buf_tbl_alloc(struct sfxge_softc *sc, size_t n, 280 uint32_t *idp); 281 282/* 283 * From sfxge_dma.c. 284 */ 285extern int sfxge_dma_init(struct sfxge_softc *sc); 286extern void sfxge_dma_fini(struct sfxge_softc *sc); 287extern int sfxge_dma_alloc(struct sfxge_softc *sc, bus_size_t len, 288 efsys_mem_t *esmp); 289extern void sfxge_dma_free(efsys_mem_t *esmp); 290extern int sfxge_dma_map_sg_collapse(bus_dma_tag_t tag, bus_dmamap_t map, 291 struct mbuf **mp, bus_dma_segment_t *segs, int *nsegs, int maxsegs); 292 293/* 294 * From sfxge_ev.c. 295 */ 296extern int sfxge_ev_init(struct sfxge_softc *sc); 297extern void sfxge_ev_fini(struct sfxge_softc *sc); 298extern int sfxge_ev_start(struct sfxge_softc *sc); 299extern void sfxge_ev_stop(struct sfxge_softc *sc); 300extern int sfxge_ev_qpoll(struct sfxge_evq *evq); 301 302/* 303 * From sfxge_intr.c. 304 */ 305extern int sfxge_intr_init(struct sfxge_softc *sc); 306extern void sfxge_intr_fini(struct sfxge_softc *sc); 307extern int sfxge_intr_start(struct sfxge_softc *sc); 308extern void sfxge_intr_stop(struct sfxge_softc *sc); 309 310/* 311 * From sfxge_mcdi.c. 312 */ 313extern int sfxge_mcdi_init(struct sfxge_softc *sc); 314extern void sfxge_mcdi_fini(struct sfxge_softc *sc); 315 316/* 317 * From sfxge_port.c. 318 */ 319extern int sfxge_port_init(struct sfxge_softc *sc); 320extern void sfxge_port_fini(struct sfxge_softc *sc); 321extern int sfxge_port_start(struct sfxge_softc *sc); 322extern void sfxge_port_stop(struct sfxge_softc *sc); 323extern void sfxge_mac_link_update(struct sfxge_softc *sc, 324 efx_link_mode_t mode); 325extern int sfxge_mac_filter_set(struct sfxge_softc *sc); 326extern int sfxge_port_ifmedia_init(struct sfxge_softc *sc); 327 328#define SFXGE_MAX_MTU (9 * 1024) 329 330#define SFXGE_ADAPTER_LOCK_INIT(_sc, _ifname) \ 331 do { \ 332 struct sfxge_softc *__sc = (_sc); \ 333 \ 334 snprintf((__sc)->softc_lock_name, \ 335 sizeof((__sc)->softc_lock_name), \ 336 "%s:softc", (_ifname)); \ 337 sx_init(&(__sc)->softc_lock, (__sc)->softc_lock_name); \ 338 } while (B_FALSE) 339#define SFXGE_ADAPTER_LOCK_DESTROY(_sc) \ 340 sx_destroy(&(_sc)->softc_lock) 341#define SFXGE_ADAPTER_LOCK(_sc) \ 342 sx_xlock(&(_sc)->softc_lock) 343#define SFXGE_ADAPTER_UNLOCK(_sc) \ 344 sx_xunlock(&(_sc)->softc_lock) 345#define SFXGE_ADAPTER_LOCK_ASSERT_OWNED(_sc) \ 346 sx_assert(&(_sc)->softc_lock, LA_XLOCKED) 347 348#define SFXGE_PORT_LOCK_INIT(_port, _ifname) \ 349 do { \ 350 struct sfxge_port *__port = (_port); \ 351 \ 352 snprintf((__port)->lock_name, \ 353 sizeof((__port)->lock_name), \ 354 "%s:port", (_ifname)); \ 355 mtx_init(&(__port)->lock, (__port)->lock_name, \ 356 NULL, MTX_DEF); \ 357 } while (B_FALSE) 358#define SFXGE_PORT_LOCK_DESTROY(_port) \ 359 mtx_destroy(&(_port)->lock) 360#define SFXGE_PORT_LOCK(_port) \ 361 mtx_lock(&(_port)->lock) 362#define SFXGE_PORT_UNLOCK(_port) \ 363 mtx_unlock(&(_port)->lock) 364#define SFXGE_PORT_LOCK_ASSERT_OWNED(_port) \ 365 mtx_assert(&(_port)->lock, MA_OWNED) 366 367#define SFXGE_MCDI_LOCK_INIT(_mcdi, _ifname) \ 368 do { \ 369 struct sfxge_mcdi *__mcdi = (_mcdi); \ 370 \ 371 snprintf((__mcdi)->lock_name, \ 372 sizeof((__mcdi)->lock_name), \ 373 "%s:mcdi", (_ifname)); \ 374 mtx_init(&(__mcdi)->lock, (__mcdi)->lock_name, \ 375 NULL, MTX_DEF); \ 376 } while (B_FALSE) 377#define SFXGE_MCDI_LOCK_DESTROY(_mcdi) \ 378 mtx_destroy(&(_mcdi)->lock) 379#define SFXGE_MCDI_LOCK(_mcdi) \ 380 mtx_lock(&(_mcdi)->lock) 381#define SFXGE_MCDI_UNLOCK(_mcdi) \ 382 mtx_unlock(&(_mcdi)->lock) 383#define SFXGE_MCDI_LOCK_ASSERT_OWNED(_mcdi) \ 384 mtx_assert(&(_mcdi)->lock, MA_OWNED) 385 386#define SFXGE_EVQ_LOCK_INIT(_evq, _ifname, _evq_index) \ 387 do { \ 388 struct sfxge_evq *__evq = (_evq); \ 389 \ 390 snprintf((__evq)->lock_name, \ 391 sizeof((__evq)->lock_name), \ 392 "%s:evq%u", (_ifname), (_evq_index)); \ 393 mtx_init(&(__evq)->lock, (__evq)->lock_name, \ 394 NULL, MTX_DEF); \ 395 } while (B_FALSE) 396#define SFXGE_EVQ_LOCK_DESTROY(_evq) \ 397 mtx_destroy(&(_evq)->lock) 398#define SFXGE_EVQ_LOCK(_evq) \ 399 mtx_lock(&(_evq)->lock) 400#define SFXGE_EVQ_UNLOCK(_evq) \ 401 mtx_unlock(&(_evq)->lock) 402#define SFXGE_EVQ_LOCK_ASSERT_OWNED(_evq) \ 403 mtx_assert(&(_evq)->lock, MA_OWNED) 404 405#endif /* _SFXGE_H */ 406