cxgb_osdep.h revision 167526
1/************************************************************************** 2 3Copyright (c) 2007, Chelsio Inc. 4All rights reserved. 5 6Redistribution and use in source and binary forms, with or without 7modification, are permitted provided that the following conditions are met: 8 9 1. Redistributions of source code must retain the above copyright notice, 10 this list of conditions and the following disclaimer. 11 12 2. Redistributions in binary form must reproduce the above copyright 13 notice, this list of conditions and the following disclaimer in the 14 documentation and/or other materials provided with the distribution. 15 16 3. Neither the name of the Chelsio Corporation nor the names of its 17 contributors may be used to endorse or promote products derived from 18 this software without specific prior written permission. 19 20THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 24LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30POSSIBILITY OF SUCH DAMAGE. 31 32 33$FreeBSD: head/sys/dev/cxgb/cxgb_osdep.h 167526 2007-03-14 06:35:38Z kmacy $ 34 35***************************************************************************/ 36 37#include <sys/param.h> 38#include <sys/systm.h> 39#include <sys/ctype.h> 40#include <sys/endian.h> 41#include <sys/bus.h> 42 43#include <dev/mii/mii.h> 44 45#include <dev/cxgb/common/cxgb_version.h> 46#include <dev/cxgb/cxgb_config.h> 47 48#ifndef _CXGB_OSDEP_H_ 49#define _CXGB_OSDEP_H_ 50 51typedef struct adapter adapter_t; 52 53struct sge_rspq; 54 55struct t3_mbuf_hdr { 56 struct mbuf *mh_head; 57 struct mbuf *mh_tail; 58}; 59 60#if __FreeBSD_version > 700030 61#define INTR_FILTERS 62#define FIRMWARE_LATEST 63#endif 64 65#if ((__FreeBSD_version > 602103) && (__FreeBSD_version < 700000)) 66#define FIRMWARE_LATEST 67#endif 68 69#if __FreeBSD_version > 700000 70#define MSI_SUPPORTED 71#define TSO_SUPPORTED 72#define VLAN_SUPPORTED 73#define TASKQUEUE_CURRENT 74#endif 75 76/* 77 * Workaround for weird Chelsio issue 78 */ 79#if __FreeBSD_version > 700029 80#define PRIV_SUPPORTED 81#endif 82 83#define CXGB_TX_CLEANUP_THRESHOLD 32 84 85 86#ifdef DEBUG_PRINT 87#define DPRINTF printf 88#else 89#define DPRINTF(...) 90#endif 91 92#define TX_MAX_SIZE (1 << 16) /* 64KB */ 93#define TX_MAX_SEGS 36 /* maximum supported by card */ 94#define TX_MAX_DESC 4 /* max descriptors per packet */ 95#define TX_START_MAX_DESC (TX_MAX_DESC << 1) /* maximum number of descriptors 96 * call to start used per */ 97#define TX_CLEAN_MAX_DESC (TX_MAX_DESC << 2) /* maximum tx descriptors 98 * to clean per iteration */ 99 100 101#if defined(__i386__) || defined(__amd64__) 102#define mb() __asm volatile("mfence":::"memory") 103#define rmb() __asm volatile("lfence":::"memory") 104#define wmb() __asm volatile("sfence" ::: "memory") 105#define smp_mb() mb() 106 107#define USE_PREFETCH 108#ifdef USE_PREFETCH 109#define L1_CACHE_BYTES 64 110static __inline 111void prefetch(void *x) 112{ 113 __asm volatile("prefetcht0 %0" :: "m" (*(unsigned long *)x)); 114} 115#else 116#define prefetch(x) 117#endif 118 119#endif 120#define DBG_RX (1 << 0) 121static const int debug_flags = DBG_RX; 122 123#ifdef DEBUG_PRINT 124#define DBG(flag, msg) do { \ 125 if ((flag & debug_flags)) \ 126 printf msg; \ 127} while (0) 128#else 129#define DBG(...) 130#endif 131 132#define promisc_rx_mode(rm) ((rm)->port->ifp->if_flags & IFF_PROMISC) 133#define allmulti_rx_mode(rm) ((rm)->port->ifp->if_flags & IFF_ALLMULTI) 134 135#define CH_ERR(adap, fmt, ...)device_printf(adap->dev, fmt, ##__VA_ARGS__); 136 137#define CH_WARN(adap, fmt, ...) device_printf(adap->dev, fmt, ##__VA_ARGS__) 138#define CH_ALERT(adap, fmt, ...) device_printf(adap->dev, fmt, ##__VA_ARGS__) 139 140#define t3_os_sleep(x) DELAY((x) * 1000) 141 142/* Standard PHY definitions */ 143#define BMCR_LOOPBACK BMCR_LOOP 144#define BMCR_ISOLATE BMCR_ISO 145#define BMCR_ANENABLE BMCR_AUTOEN 146#define BMCR_SPEED1000 BMCR_SPEED1 147#define BMCR_SPEED100 BMCR_SPEED0 148#define BMCR_ANRESTART BMCR_STARTNEG 149#define BMCR_FULLDPLX BMCR_FDX 150#define BMSR_LSTATUS BMSR_LINK 151#define BMSR_ANEGCOMPLETE BMSR_ACOMP 152 153#define MII_LPA MII_ANLPAR 154#define MII_ADVERTISE MII_ANAR 155#define MII_CTRL1000 MII_100T2CR 156 157#define ADVERTISE_PAUSE_CAP ANAR_FC 158#define ADVERTISE_PAUSE_ASYM 0x0800 159#define ADVERTISE_1000HALF ANAR_X_HD 160#define ADVERTISE_1000FULL ANAR_X_FD 161#define ADVERTISE_10FULL ANAR_10_FD 162#define ADVERTISE_10HALF ANAR_10 163#define ADVERTISE_100FULL ANAR_TX_FD 164#define ADVERTISE_100HALF ANAR_TX 165 166/* Standard PCI Extended Capaibilities definitions */ 167#define PCI_CAP_ID_VPD 0x03 168#define PCI_VPD_ADDR 2 169#define PCI_VPD_ADDR_F 0x8000 170#define PCI_VPD_DATA 4 171 172#define PCI_CAP_ID_EXP 0x10 173#define PCI_EXP_DEVCTL 8 174#define PCI_EXP_DEVCTL_PAYLOAD 0x00e0 175#define PCI_EXP_LNKCTL 16 176#define PCI_EXP_LNKSTA 18 177 178/* 179 * Linux compatibility macros 180 */ 181 182/* Some simple translations */ 183#define __devinit 184#define udelay(x) DELAY(x) 185#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) 186#define le32_to_cpu(x) le32toh(x) 187#define cpu_to_le32(x) htole32(x) 188#define swab32(x) bswap32(x) 189#define simple_strtoul strtoul 190 191/* More types and endian definitions */ 192typedef uint8_t u8; 193typedef uint16_t u16; 194typedef uint32_t u32; 195typedef uint64_t u64; 196 197typedef uint8_t __u8; 198typedef uint16_t __u16; 199typedef uint32_t __u32; 200typedef uint8_t __be8; 201typedef uint16_t __be16; 202typedef uint32_t __be32; 203typedef uint64_t __be64; 204 205#if BYTE_ORDER == BIG_ENDIAN 206#define __BIG_ENDIAN_BITFIELD 207#elif BYTE_ORDER == LITTLE_ENDIAN 208#define __LITTLE_ENDIAN_BITFIELD 209#else 210#error "Must set BYTE_ORDER" 211#endif 212 213/* Indicates what features are supported by the interface. */ 214#define SUPPORTED_10baseT_Half (1 << 0) 215#define SUPPORTED_10baseT_Full (1 << 1) 216#define SUPPORTED_100baseT_Half (1 << 2) 217#define SUPPORTED_100baseT_Full (1 << 3) 218#define SUPPORTED_1000baseT_Half (1 << 4) 219#define SUPPORTED_1000baseT_Full (1 << 5) 220#define SUPPORTED_Autoneg (1 << 6) 221#define SUPPORTED_TP (1 << 7) 222#define SUPPORTED_AUI (1 << 8) 223#define SUPPORTED_MII (1 << 9) 224#define SUPPORTED_FIBRE (1 << 10) 225#define SUPPORTED_BNC (1 << 11) 226#define SUPPORTED_10000baseT_Full (1 << 12) 227#define SUPPORTED_Pause (1 << 13) 228#define SUPPORTED_Asym_Pause (1 << 14) 229 230/* Indicates what features are advertised by the interface. */ 231#define ADVERTISED_10baseT_Half (1 << 0) 232#define ADVERTISED_10baseT_Full (1 << 1) 233#define ADVERTISED_100baseT_Half (1 << 2) 234#define ADVERTISED_100baseT_Full (1 << 3) 235#define ADVERTISED_1000baseT_Half (1 << 4) 236#define ADVERTISED_1000baseT_Full (1 << 5) 237#define ADVERTISED_Autoneg (1 << 6) 238#define ADVERTISED_TP (1 << 7) 239#define ADVERTISED_AUI (1 << 8) 240#define ADVERTISED_MII (1 << 9) 241#define ADVERTISED_FIBRE (1 << 10) 242#define ADVERTISED_BNC (1 << 11) 243#define ADVERTISED_10000baseT_Full (1 << 12) 244#define ADVERTISED_Pause (1 << 13) 245#define ADVERTISED_Asym_Pause (1 << 14) 246 247/* Enable or disable autonegotiation. If this is set to enable, 248 * the forced link modes above are completely ignored. 249 */ 250#define AUTONEG_DISABLE 0x00 251#define AUTONEG_ENABLE 0x01 252 253#define SPEED_10 10 254#define SPEED_100 100 255#define SPEED_1000 1000 256#define SPEED_10000 10000 257#define DUPLEX_HALF 0 258#define DUPLEX_FULL 1 259 260#endif 261