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