1 1.1 jklos /************************************************************************** 2 1.1 jklos 3 1.1 jklos Copyright (c) 2007, Chelsio Inc. 4 1.1 jklos All rights reserved. 5 1.1 jklos 6 1.1 jklos Redistribution and use in source and binary forms, with or without 7 1.1 jklos modification, are permitted provided that the following conditions are met: 8 1.1 jklos 9 1.1 jklos 1. Redistributions of source code must retain the above copyright notice, 10 1.1 jklos this list of conditions and the following disclaimer. 11 1.1 jklos 12 1.1 jklos 2. Neither the name of the Chelsio Corporation nor the names of its 13 1.1 jklos contributors may be used to endorse or promote products derived from 14 1.1 jklos this software without specific prior written permission. 15 1.1 jklos 16 1.1 jklos THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 1.1 jklos AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 1.1 jklos IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 1.1 jklos ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 20 1.1 jklos LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 1.1 jklos CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 1.1 jklos SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 1.1 jklos INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 1.1 jklos CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 1.1 jklos ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 1.1 jklos POSSIBILITY OF SUCH DAMAGE. 27 1.1 jklos 28 1.1 jklos ***************************************************************************/ 29 1.1 jklos #ifndef __CHELSIO_COMMON_H 30 1.1 jklos #define __CHELSIO_COMMON_H 31 1.1 jklos 32 1.1 jklos #ifdef CONFIG_DEFINED 33 1.1 jklos #include <cxgb_osdep.h> 34 1.1 jklos #else 35 1.1 jklos #include <dev/pci/cxgb/cxgb_osdep.h> 36 1.1 jklos // ??? #include <dev/pci/cxgb/cxgb_toedev.h> 37 1.1 jklos #endif 38 1.1 jklos 39 1.1 jklos enum { 40 1.1 jklos MAX_FRAME_SIZE = 10240, /* max MAC frame size, includes header + FCS */ 41 1.1 jklos EEPROMSIZE = 8192, /* Serial EEPROM size */ 42 1.1 jklos SERNUM_LEN = 16, /* Serial # length */ 43 1.1 jklos RSS_TABLE_SIZE = 64, /* size of RSS lookup and mapping tables */ 44 1.1 jklos TCB_SIZE = 128, /* TCB size */ 45 1.1 jklos NMTUS = 16, /* size of MTU table */ 46 1.1 jklos NCCTRL_WIN = 32, /* # of congestion control windows */ 47 1.1 jklos NTX_SCHED = 8, /* # of HW Tx scheduling queues */ 48 1.1 jklos PROTO_SRAM_LINES = 128, /* size of protocol sram */ 49 1.1 jklos MAX_NPORTS = 4, 50 1.1 jklos TP_TMR_RES = 200, 51 1.1 jklos TP_SRAM_OFFSET = 4096, /* TP SRAM content offset in eeprom */ 52 1.1 jklos TP_SRAM_LEN = 2112, /* TP SRAM content offset in eeprom */ 53 1.1 jklos }; 54 1.1 jklos 55 1.1 jklos #define MAX_RX_COALESCING_LEN 12288U 56 1.1 jklos 57 1.1 jklos enum { 58 1.1 jklos PAUSE_RX = 1 << 0, 59 1.1 jklos PAUSE_TX = 1 << 1, 60 1.1 jklos PAUSE_AUTONEG = 1 << 2 61 1.1 jklos }; 62 1.1 jklos 63 1.1 jklos enum { 64 1.1 jklos SUPPORTED_IRQ = 1 << 24 65 1.1 jklos }; 66 1.1 jklos 67 1.1 jklos enum { /* adapter interrupt-maintained statistics */ 68 1.1 jklos STAT_ULP_CH0_PBL_OOB, 69 1.1 jklos STAT_ULP_CH1_PBL_OOB, 70 1.1 jklos STAT_PCI_CORR_ECC, 71 1.1 jklos 72 1.1 jklos IRQ_NUM_STATS /* keep last */ 73 1.1 jklos }; 74 1.1 jklos 75 1.1 jklos enum { 76 1.1 jklos TP_VERSION_MAJOR = 1, 77 1.1 jklos TP_VERSION_MINOR = 1, 78 1.1 jklos TP_VERSION_MICRO = 0 79 1.1 jklos }; 80 1.1 jklos 81 1.1 jklos #define S_TP_VERSION_MAJOR 16 82 1.1 jklos #define M_TP_VERSION_MAJOR 0xFF 83 1.1 jklos #define V_TP_VERSION_MAJOR(x) ((x) << S_TP_VERSION_MAJOR) 84 1.1 jklos #define G_TP_VERSION_MAJOR(x) \ 85 1.1 jklos (((x) >> S_TP_VERSION_MAJOR) & M_TP_VERSION_MAJOR) 86 1.1 jklos 87 1.1 jklos #define S_TP_VERSION_MINOR 8 88 1.1 jklos #define M_TP_VERSION_MINOR 0xFF 89 1.1 jklos #define V_TP_VERSION_MINOR(x) ((x) << S_TP_VERSION_MINOR) 90 1.1 jklos #define G_TP_VERSION_MINOR(x) \ 91 1.1 jklos (((x) >> S_TP_VERSION_MINOR) & M_TP_VERSION_MINOR) 92 1.1 jklos 93 1.1 jklos #define S_TP_VERSION_MICRO 0 94 1.1 jklos #define M_TP_VERSION_MICRO 0xFF 95 1.1 jklos #define V_TP_VERSION_MICRO(x) ((x) << S_TP_VERSION_MICRO) 96 1.1 jklos #define G_TP_VERSION_MICRO(x) \ 97 1.1 jklos (((x) >> S_TP_VERSION_MICRO) & M_TP_VERSION_MICRO) 98 1.1 jklos 99 1.1 jklos enum { 100 1.1 jklos FW_VERSION_MAJOR = 4, 101 1.1 jklos FW_VERSION_MINOR = 7, 102 1.1 jklos FW_VERSION_MICRO = 0 103 1.1 jklos }; 104 1.1 jklos 105 1.1 jklos enum { 106 1.1 jklos SGE_QSETS = 8, /* # of SGE Tx/Rx/RspQ sets */ 107 1.1 jklos SGE_RXQ_PER_SET = 2, /* # of Rx queues per set */ 108 1.1 jklos SGE_TXQ_PER_SET = 3 /* # of Tx queues per set */ 109 1.1 jklos }; 110 1.1 jklos 111 1.1 jklos enum sge_context_type { /* SGE egress context types */ 112 1.1 jklos SGE_CNTXT_RDMA = 0, 113 1.1 jklos SGE_CNTXT_ETH = 2, 114 1.1 jklos SGE_CNTXT_OFLD = 4, 115 1.1 jklos SGE_CNTXT_CTRL = 5 116 1.1 jklos }; 117 1.1 jklos 118 1.1 jklos enum { 119 1.1 jklos AN_PKT_SIZE = 32, /* async notification packet size */ 120 1.1 jklos IMMED_PKT_SIZE = 48 /* packet size for immediate data */ 121 1.1 jklos }; 122 1.1 jklos 123 1.1 jklos struct sg_ent { /* SGE scatter/gather entry */ 124 1.1 jklos u32 len[2]; 125 1.1 jklos u64 addr[2]; 126 1.1 jklos }; 127 1.1 jklos 128 1.1 jklos #ifndef SGE_NUM_GENBITS 129 1.1 jklos /* Must be 1 or 2 */ 130 1.1 jklos # define SGE_NUM_GENBITS 2 131 1.1 jklos #endif 132 1.1 jklos 133 1.1 jklos #define TX_DESC_FLITS 16U 134 1.1 jklos #define WR_FLITS (TX_DESC_FLITS + 1 - SGE_NUM_GENBITS) 135 1.1 jklos 136 1.1 jklos struct cphy; 137 1.1 jklos 138 1.1 jklos struct mdio_ops { 139 1.1 jklos int (*read)(adapter_t *adapter, int phy_addr, int mmd_addr, 140 1.1 jklos int reg_addr, unsigned int *val); 141 1.1 jklos int (*write)(adapter_t *adapter, int phy_addr, int mmd_addr, 142 1.1 jklos int reg_addr, unsigned int val); 143 1.1 jklos }; 144 1.1 jklos 145 1.1 jklos struct adapter_info { 146 1.1 jklos unsigned char nports0; /* # of ports on channel 0 */ 147 1.1 jklos unsigned char nports1; /* # of ports on channel 1 */ 148 1.1 jklos unsigned char phy_base_addr; /* MDIO PHY base address */ 149 1.1 jklos unsigned char mdien:1; 150 1.1 jklos unsigned char mdiinv:1; 151 1.1 jklos unsigned int gpio_out; /* GPIO output settings */ 152 1.1 jklos unsigned int gpio_intr; /* GPIO IRQ enable mask */ 153 1.1 jklos unsigned long caps; /* adapter capabilities */ 154 1.1 jklos const struct mdio_ops *mdio_ops; /* MDIO operations */ 155 1.1 jklos const char *desc; /* product description */ 156 1.1 jklos }; 157 1.1 jklos 158 1.1 jklos struct port_type_info { 159 1.1 jklos void (*phy_prep)(struct cphy *phy, adapter_t *adapter, int phy_addr, 160 1.1 jklos const struct mdio_ops *ops); 161 1.1 jklos unsigned int caps; 162 1.1 jklos const char *desc; 163 1.1 jklos }; 164 1.1 jklos 165 1.1 jklos struct mc5_stats { 166 1.1 jklos unsigned long parity_err; 167 1.1 jklos unsigned long active_rgn_full; 168 1.1 jklos unsigned long nfa_srch_err; 169 1.1 jklos unsigned long unknown_cmd; 170 1.1 jklos unsigned long reqq_parity_err; 171 1.1 jklos unsigned long dispq_parity_err; 172 1.1 jklos unsigned long del_act_empty; 173 1.1 jklos }; 174 1.1 jklos 175 1.1 jklos struct mc7_stats { 176 1.1 jklos unsigned long corr_err; 177 1.1 jklos unsigned long uncorr_err; 178 1.1 jklos unsigned long parity_err; 179 1.1 jklos unsigned long addr_err; 180 1.1 jklos }; 181 1.1 jklos 182 1.1 jklos struct mac_stats { 183 1.1 jklos u64 tx_octets; /* total # of octets in good frames */ 184 1.1 jklos u64 tx_octets_bad; /* total # of octets in error frames */ 185 1.1 jklos u64 tx_frames; /* all good frames */ 186 1.1 jklos u64 tx_mcast_frames; /* good multicast frames */ 187 1.1 jklos u64 tx_bcast_frames; /* good broadcast frames */ 188 1.1 jklos u64 tx_pause; /* # of transmitted pause frames */ 189 1.1 jklos u64 tx_deferred; /* frames with deferred transmissions */ 190 1.1 jklos u64 tx_late_collisions; /* # of late collisions */ 191 1.1 jklos u64 tx_total_collisions; /* # of total collisions */ 192 1.4 andvar u64 tx_excess_collisions; /* frame errors from excessive collisions */ 193 1.1 jklos u64 tx_underrun; /* # of Tx FIFO underruns */ 194 1.1 jklos u64 tx_len_errs; /* # of Tx length errors */ 195 1.1 jklos u64 tx_mac_internal_errs; /* # of internal MAC errors on Tx */ 196 1.1 jklos u64 tx_excess_deferral; /* # of frames with excessive deferral */ 197 1.1 jklos u64 tx_fcs_errs; /* # of frames with bad FCS */ 198 1.1 jklos 199 1.1 jklos u64 tx_frames_64; /* # of Tx frames in a particular range */ 200 1.1 jklos u64 tx_frames_65_127; 201 1.1 jklos u64 tx_frames_128_255; 202 1.1 jklos u64 tx_frames_256_511; 203 1.1 jklos u64 tx_frames_512_1023; 204 1.1 jklos u64 tx_frames_1024_1518; 205 1.1 jklos u64 tx_frames_1519_max; 206 1.1 jklos 207 1.1 jklos u64 rx_octets; /* total # of octets in good frames */ 208 1.1 jklos u64 rx_octets_bad; /* total # of octets in error frames */ 209 1.1 jklos u64 rx_frames; /* all good frames */ 210 1.1 jklos u64 rx_mcast_frames; /* good multicast frames */ 211 1.1 jklos u64 rx_bcast_frames; /* good broadcast frames */ 212 1.1 jklos u64 rx_pause; /* # of received pause frames */ 213 1.1 jklos u64 rx_fcs_errs; /* # of received frames with bad FCS */ 214 1.1 jklos u64 rx_align_errs; /* alignment errors */ 215 1.1 jklos u64 rx_symbol_errs; /* symbol errors */ 216 1.1 jklos u64 rx_data_errs; /* data errors */ 217 1.1 jklos u64 rx_sequence_errs; /* sequence errors */ 218 1.1 jklos u64 rx_runt; /* # of runt frames */ 219 1.1 jklos u64 rx_jabber; /* # of jabber frames */ 220 1.1 jklos u64 rx_short; /* # of short frames */ 221 1.1 jklos u64 rx_too_long; /* # of oversized frames */ 222 1.1 jklos u64 rx_mac_internal_errs; /* # of internal MAC errors on Rx */ 223 1.1 jklos 224 1.1 jklos u64 rx_frames_64; /* # of Rx frames in a particular range */ 225 1.1 jklos u64 rx_frames_65_127; 226 1.1 jklos u64 rx_frames_128_255; 227 1.1 jklos u64 rx_frames_256_511; 228 1.1 jklos u64 rx_frames_512_1023; 229 1.1 jklos u64 rx_frames_1024_1518; 230 1.1 jklos u64 rx_frames_1519_max; 231 1.1 jklos 232 1.1 jklos u64 rx_cong_drops; /* # of Rx drops due to SGE congestion */ 233 1.1 jklos 234 1.1 jklos unsigned long tx_fifo_parity_err; 235 1.1 jklos unsigned long rx_fifo_parity_err; 236 1.1 jklos unsigned long tx_fifo_urun; 237 1.1 jklos unsigned long rx_fifo_ovfl; 238 1.1 jklos unsigned long serdes_signal_loss; 239 1.1 jklos unsigned long xaui_pcs_ctc_err; 240 1.1 jklos unsigned long xaui_pcs_align_change; 241 1.1 jklos 242 1.1 jklos unsigned long num_toggled; /* # times toggled TxEn due to stuck TX */ 243 1.1 jklos unsigned long num_resets; /* # times reset due to stuck TX */ 244 1.1 jklos }; 245 1.1 jklos 246 1.1 jklos struct tp_mib_stats { 247 1.1 jklos u32 ipInReceive_hi; 248 1.1 jklos u32 ipInReceive_lo; 249 1.1 jklos u32 ipInHdrErrors_hi; 250 1.1 jklos u32 ipInHdrErrors_lo; 251 1.1 jklos u32 ipInAddrErrors_hi; 252 1.1 jklos u32 ipInAddrErrors_lo; 253 1.1 jklos u32 ipInUnknownProtos_hi; 254 1.1 jklos u32 ipInUnknownProtos_lo; 255 1.1 jklos u32 ipInDiscards_hi; 256 1.1 jklos u32 ipInDiscards_lo; 257 1.1 jklos u32 ipInDelivers_hi; 258 1.1 jklos u32 ipInDelivers_lo; 259 1.1 jklos u32 ipOutRequests_hi; 260 1.1 jklos u32 ipOutRequests_lo; 261 1.1 jklos u32 ipOutDiscards_hi; 262 1.1 jklos u32 ipOutDiscards_lo; 263 1.1 jklos u32 ipOutNoRoutes_hi; 264 1.1 jklos u32 ipOutNoRoutes_lo; 265 1.1 jklos u32 ipReasmTimeout; 266 1.1 jklos u32 ipReasmReqds; 267 1.1 jklos u32 ipReasmOKs; 268 1.1 jklos u32 ipReasmFails; 269 1.1 jklos 270 1.1 jklos u32 reserved[8]; 271 1.1 jklos 272 1.1 jklos u32 tcpActiveOpens; 273 1.1 jklos u32 tcpPassiveOpens; 274 1.1 jklos u32 tcpAttemptFails; 275 1.1 jklos u32 tcpEstabResets; 276 1.1 jklos u32 tcpOutRsts; 277 1.1 jklos u32 tcpCurrEstab; 278 1.1 jklos u32 tcpInSegs_hi; 279 1.1 jklos u32 tcpInSegs_lo; 280 1.1 jklos u32 tcpOutSegs_hi; 281 1.1 jklos u32 tcpOutSegs_lo; 282 1.1 jklos u32 tcpRetransSeg_hi; 283 1.1 jklos u32 tcpRetransSeg_lo; 284 1.1 jklos u32 tcpInErrs_hi; 285 1.1 jklos u32 tcpInErrs_lo; 286 1.1 jklos u32 tcpRtoMin; 287 1.1 jklos u32 tcpRtoMax; 288 1.1 jklos }; 289 1.1 jklos 290 1.1 jklos struct tp_params { 291 1.1 jklos unsigned int nchan; /* # of channels */ 292 1.1 jklos unsigned int pmrx_size; /* total PMRX capacity */ 293 1.1 jklos unsigned int pmtx_size; /* total PMTX capacity */ 294 1.1 jklos unsigned int cm_size; /* total CM capacity */ 295 1.1 jklos unsigned int chan_rx_size; /* per channel Rx size */ 296 1.1 jklos unsigned int chan_tx_size; /* per channel Tx size */ 297 1.1 jklos unsigned int rx_pg_size; /* Rx page size */ 298 1.1 jklos unsigned int tx_pg_size; /* Tx page size */ 299 1.1 jklos unsigned int rx_num_pgs; /* # of Rx pages */ 300 1.1 jklos unsigned int tx_num_pgs; /* # of Tx pages */ 301 1.1 jklos unsigned int ntimer_qs; /* # of timer queues */ 302 1.1 jklos unsigned int tre; /* log2 of core clocks per TP tick */ 303 1.1 jklos unsigned int dack_re; /* DACK timer resolution */ 304 1.1 jklos }; 305 1.1 jklos 306 1.1 jklos struct qset_params { /* SGE queue set parameters */ 307 1.1 jklos unsigned int polling; /* polling/interrupt service for rspq */ 308 1.1 jklos unsigned int lro; /* large receive offload */ 309 1.1 jklos unsigned int coalesce_nsecs; /* irq coalescing timer */ 310 1.1 jklos unsigned int rspq_size; /* # of entries in response queue */ 311 1.1 jklos unsigned int fl_size; /* # of entries in regular free list */ 312 1.1 jklos unsigned int jumbo_size; /* # of entries in jumbo free list */ 313 1.1 jklos unsigned int txq_size[SGE_TXQ_PER_SET]; /* Tx queue sizes */ 314 1.1 jklos unsigned int cong_thres; /* FL congestion threshold */ 315 1.1 jklos unsigned int vector; /* Interrupt (line or vector) number */ 316 1.1 jklos }; 317 1.1 jklos 318 1.1 jklos struct sge_params { 319 1.1 jklos unsigned int max_pkt_size; /* max offload pkt size */ 320 1.1 jklos struct qset_params qset[SGE_QSETS]; 321 1.1 jklos }; 322 1.1 jklos 323 1.1 jklos struct mc5_params { 324 1.1 jklos unsigned int mode; /* selects MC5 width */ 325 1.1 jklos unsigned int nservers; /* size of server region */ 326 1.1 jklos unsigned int nfilters; /* size of filter region */ 327 1.1 jklos unsigned int nroutes; /* size of routing region */ 328 1.1 jklos }; 329 1.1 jklos 330 1.1 jklos /* Default MC5 region sizes */ 331 1.1 jklos enum { 332 1.1 jklos DEFAULT_NSERVERS = 512, 333 1.1 jklos DEFAULT_NFILTERS = 128 334 1.1 jklos }; 335 1.1 jklos 336 1.1 jklos /* MC5 modes, these must be non-0 */ 337 1.1 jklos enum { 338 1.1 jklos MC5_MODE_144_BIT = 1, 339 1.1 jklos MC5_MODE_72_BIT = 2 340 1.1 jklos }; 341 1.1 jklos 342 1.1 jklos /* MC5 min active region size */ 343 1.1 jklos enum { MC5_MIN_TIDS = 16 }; 344 1.1 jklos 345 1.1 jklos struct vpd_params { 346 1.1 jklos unsigned int cclk; 347 1.1 jklos unsigned int mclk; 348 1.1 jklos unsigned int uclk; 349 1.1 jklos unsigned int mdc; 350 1.1 jklos unsigned int mem_timing; 351 1.1 jklos u8 sn[SERNUM_LEN + 1]; 352 1.1 jklos u8 eth_base[6]; 353 1.1 jklos u8 port_type[MAX_NPORTS]; 354 1.1 jklos unsigned short xauicfg[2]; 355 1.1 jklos }; 356 1.1 jklos 357 1.1 jklos struct pci_params { 358 1.1 jklos unsigned int vpd_cap_addr; 359 1.1 jklos unsigned int pcie_cap_addr; 360 1.1 jklos unsigned short speed; 361 1.1 jklos unsigned char width; 362 1.1 jklos unsigned char variant; 363 1.1 jklos }; 364 1.1 jklos 365 1.1 jklos enum { 366 1.1 jklos PCI_VARIANT_PCI, 367 1.1 jklos PCI_VARIANT_PCIX_MODE1_PARITY, 368 1.1 jklos PCI_VARIANT_PCIX_MODE1_ECC, 369 1.1 jklos PCI_VARIANT_PCIX_266_MODE2, 370 1.1 jklos PCI_VARIANT_PCIE 371 1.1 jklos }; 372 1.1 jklos 373 1.1 jklos struct adapter_params { 374 1.1 jklos struct sge_params sge; 375 1.1 jklos struct mc5_params mc5; 376 1.1 jklos struct tp_params tp; 377 1.1 jklos struct vpd_params vpd; 378 1.1 jklos struct pci_params pci; 379 1.1 jklos 380 1.1 jklos const struct adapter_info *info; 381 1.1 jklos 382 1.1 jklos #ifdef CONFIG_CHELSIO_T3_CORE 383 1.1 jklos unsigned short mtus[NMTUS]; 384 1.1 jklos unsigned short a_wnd[NCCTRL_WIN]; 385 1.1 jklos unsigned short b_wnd[NCCTRL_WIN]; 386 1.1 jklos #endif 387 1.1 jklos unsigned int nports; /* # of ethernet ports */ 388 1.1 jklos unsigned int chan_map; /* bitmap of in-use Tx channels */ 389 1.1 jklos unsigned int stats_update_period; /* MAC stats accumulation period */ 390 1.1 jklos unsigned int linkpoll_period; /* link poll period in 0.1s */ 391 1.1 jklos unsigned int rev; /* chip revision */ 392 1.1 jklos unsigned int offload; 393 1.1 jklos }; 394 1.1 jklos 395 1.1 jklos enum { /* chip revisions */ 396 1.1 jklos T3_REV_A = 0, 397 1.1 jklos T3_REV_B = 2, 398 1.1 jklos T3_REV_B2 = 3, 399 1.1 jklos T3_REV_C = 4, 400 1.1 jklos }; 401 1.1 jklos 402 1.1 jklos struct trace_params { 403 1.1 jklos u32 sip; 404 1.1 jklos u32 sip_mask; 405 1.1 jklos u32 dip; 406 1.1 jklos u32 dip_mask; 407 1.1 jklos u16 sport; 408 1.1 jklos u16 sport_mask; 409 1.1 jklos u16 dport; 410 1.1 jklos u16 dport_mask; 411 1.1 jklos u32 vlan:12; 412 1.1 jklos u32 vlan_mask:12; 413 1.1 jklos u32 intf:4; 414 1.1 jklos u32 intf_mask:4; 415 1.1 jklos u8 proto; 416 1.1 jklos u8 proto_mask; 417 1.1 jklos }; 418 1.1 jklos 419 1.1 jklos struct link_config { 420 1.1 jklos unsigned int supported; /* link capabilities */ 421 1.1 jklos unsigned int advertising; /* advertised capabilities */ 422 1.1 jklos unsigned short requested_speed; /* speed user has requested */ 423 1.1 jklos unsigned short speed; /* actual link speed */ 424 1.1 jklos unsigned char requested_duplex; /* duplex user has requested */ 425 1.1 jklos unsigned char duplex; /* actual link duplex */ 426 1.1 jklos unsigned char requested_fc; /* flow control user has requested */ 427 1.1 jklos unsigned char fc; /* actual link flow control */ 428 1.1 jklos unsigned char autoneg; /* autonegotiating? */ 429 1.1 jklos unsigned int link_ok; /* link up? */ 430 1.1 jklos }; 431 1.1 jklos 432 1.1 jklos #define SPEED_INVALID 0xffff 433 1.1 jklos #define DUPLEX_INVALID 0xff 434 1.1 jklos 435 1.1 jklos struct mc5 { 436 1.1 jklos adapter_t *adapter; 437 1.1 jklos unsigned int tcam_size; 438 1.1 jklos unsigned char part_type; 439 1.1 jklos unsigned char parity_enabled; 440 1.1 jklos unsigned char mode; 441 1.1 jklos struct mc5_stats stats; 442 1.1 jklos }; 443 1.1 jklos 444 1.3 christos static __inline unsigned int t3_mc5_size(const struct mc5 *p) 445 1.1 jklos { 446 1.1 jklos return p->tcam_size; 447 1.1 jklos } 448 1.1 jklos 449 1.1 jklos struct mc7 { 450 1.1 jklos adapter_t *adapter; /* backpointer to adapter */ 451 1.1 jklos unsigned int size; /* memory size in bytes */ 452 1.1 jklos unsigned int width; /* MC7 interface width */ 453 1.1 jklos unsigned int offset; /* register address offset for MC7 instance */ 454 1.1 jklos const char *name; /* name of MC7 instance */ 455 1.1 jklos struct mc7_stats stats; /* MC7 statistics */ 456 1.1 jklos }; 457 1.1 jklos 458 1.3 christos static __inline unsigned int t3_mc7_size(const struct mc7 *p) 459 1.1 jklos { 460 1.1 jklos return p->size; 461 1.1 jklos } 462 1.1 jklos 463 1.1 jklos struct cmac { 464 1.1 jklos adapter_t *adapter; 465 1.1 jklos unsigned int offset; 466 1.1 jklos unsigned char nucast; /* # of address filters for unicast MACs */ 467 1.1 jklos unsigned char multiport; /* multiple ports connected to this MAC */ 468 1.1 jklos unsigned char ext_port; /* external MAC port */ 469 1.1 jklos unsigned char promisc_map; /* which external ports are promiscuous */ 470 1.1 jklos unsigned int tx_tcnt; 471 1.1 jklos unsigned int tx_xcnt; 472 1.1 jklos u64 tx_mcnt; 473 1.1 jklos unsigned int rx_xcnt; 474 1.1 jklos unsigned int rx_ocnt; 475 1.1 jklos u64 rx_mcnt; 476 1.1 jklos unsigned int toggle_cnt; 477 1.1 jklos unsigned int txen; 478 1.1 jklos u64 rx_pause; 479 1.1 jklos struct mac_stats stats; 480 1.1 jklos }; 481 1.1 jklos 482 1.1 jklos enum { 483 1.1 jklos MAC_DIRECTION_RX = 1, 484 1.1 jklos MAC_DIRECTION_TX = 2, 485 1.1 jklos MAC_RXFIFO_SIZE = 32768 486 1.1 jklos }; 487 1.1 jklos 488 1.1 jklos /* IEEE 802.3ae specified MDIO devices */ 489 1.1 jklos enum { 490 1.1 jklos MDIO_DEV_PMA_PMD = 1, 491 1.1 jklos MDIO_DEV_WIS = 2, 492 1.1 jklos MDIO_DEV_PCS = 3, 493 1.1 jklos MDIO_DEV_XGXS = 4 494 1.1 jklos }; 495 1.1 jklos 496 1.1 jklos /* PHY loopback direction */ 497 1.1 jklos enum { 498 1.1 jklos PHY_LOOPBACK_TX = 1, 499 1.1 jklos PHY_LOOPBACK_RX = 2 500 1.1 jklos }; 501 1.1 jklos 502 1.1 jklos /* PHY interrupt types */ 503 1.1 jklos enum { 504 1.1 jklos cphy_cause_link_change = 1, 505 1.1 jklos cphy_cause_fifo_error = 2 506 1.1 jklos }; 507 1.1 jklos 508 1.1 jklos /* PHY operations */ 509 1.1 jklos struct cphy_ops { 510 1.1 jklos void (*destroy)(struct cphy *phy); 511 1.1 jklos int (*reset)(struct cphy *phy, int wait); 512 1.1 jklos 513 1.1 jklos int (*intr_enable)(struct cphy *phy); 514 1.1 jklos int (*intr_disable)(struct cphy *phy); 515 1.1 jklos int (*intr_clear)(struct cphy *phy); 516 1.1 jklos int (*intr_handler)(struct cphy *phy); 517 1.1 jklos 518 1.1 jklos int (*autoneg_enable)(struct cphy *phy); 519 1.1 jklos int (*autoneg_restart)(struct cphy *phy); 520 1.1 jklos 521 1.1 jklos int (*advertise)(struct cphy *phy, unsigned int advertise_map); 522 1.1 jklos int (*set_loopback)(struct cphy *phy, int mmd, int dir, int enable); 523 1.1 jklos int (*set_speed_duplex)(struct cphy *phy, int speed, int duplex); 524 1.1 jklos int (*get_link_status)(struct cphy *phy, int *link_ok, int *speed, 525 1.1 jklos int *duplex, int *fc); 526 1.1 jklos int (*power_down)(struct cphy *phy, int enable); 527 1.1 jklos }; 528 1.1 jklos 529 1.1 jklos /* A PHY instance */ 530 1.1 jklos struct cphy { 531 1.1 jklos int addr; /* PHY address */ 532 1.1 jklos adapter_t *adapter; /* associated adapter */ 533 1.1 jklos unsigned long fifo_errors; /* FIFO over/under-flows */ 534 1.1 jklos const struct cphy_ops *ops; /* PHY operations */ 535 1.1 jklos int (*mdio_read)(adapter_t *adapter, int phy_addr, int mmd_addr, 536 1.1 jklos int reg_addr, unsigned int *val); 537 1.1 jklos int (*mdio_write)(adapter_t *adapter, int phy_addr, int mmd_addr, 538 1.1 jklos int reg_addr, unsigned int val); 539 1.1 jklos }; 540 1.1 jklos 541 1.1 jklos /* Convenience MDIO read/write wrappers */ 542 1.3 christos static __inline int mdio_read(struct cphy *phy, int mmd, int reg, 543 1.1 jklos unsigned int *valp) 544 1.1 jklos { 545 1.1 jklos return phy->mdio_read(phy->adapter, phy->addr, mmd, reg, valp); 546 1.1 jklos } 547 1.1 jklos 548 1.3 christos static __inline int mdio_write(struct cphy *phy, int mmd, int reg, 549 1.1 jklos unsigned int val) 550 1.1 jklos { 551 1.1 jklos return phy->mdio_write(phy->adapter, phy->addr, mmd, reg, val); 552 1.1 jklos } 553 1.1 jklos 554 1.1 jklos /* Convenience initializer */ 555 1.3 christos static __inline void cphy_init(struct cphy *phy, adapter_t *adapter, 556 1.1 jklos int phy_addr, struct cphy_ops *phy_ops, 557 1.1 jklos const struct mdio_ops *mdio_ops) 558 1.1 jklos { 559 1.1 jklos phy->adapter = adapter; 560 1.1 jklos phy->addr = phy_addr; 561 1.1 jklos phy->ops = phy_ops; 562 1.1 jklos if (mdio_ops) { 563 1.1 jklos phy->mdio_read = mdio_ops->read; 564 1.1 jklos phy->mdio_write = mdio_ops->write; 565 1.1 jklos } 566 1.1 jklos } 567 1.1 jklos 568 1.1 jklos /* Accumulate MAC statistics every 180 seconds. For 1G we multiply by 10. */ 569 1.1 jklos #define MAC_STATS_ACCUM_SECS 180 570 1.1 jklos 571 1.1 jklos /* The external MAC needs accumulation every 30 seconds */ 572 1.1 jklos #define VSC_STATS_ACCUM_SECS 30 573 1.1 jklos 574 1.1 jklos #define XGM_REG(reg_addr, idx) \ 575 1.1 jklos ((reg_addr) + (idx) * (XGMAC0_1_BASE_ADDR - XGMAC0_0_BASE_ADDR)) 576 1.1 jklos 577 1.1 jklos struct addr_val_pair { 578 1.1 jklos unsigned int reg_addr; 579 1.1 jklos unsigned int val; 580 1.1 jklos }; 581 1.1 jklos 582 1.1 jklos #ifdef CONFIG_DEFINED 583 1.1 jklos #include <cxgb_adapter.h> 584 1.1 jklos #else 585 1.1 jklos #include <dev/pci/cxgb/cxgb_adapter.h> 586 1.1 jklos #endif 587 1.1 jklos 588 1.1 jklos #ifndef PCI_VENDOR_ID_CHELSIO 589 1.1 jklos # define PCI_VENDOR_ID_CHELSIO 0x1425 590 1.1 jklos #endif 591 1.1 jklos 592 1.1 jklos #define for_each_port(adapter, iter) \ 593 1.1 jklos for (iter = 0; iter < (adapter)->params.nports; ++iter) 594 1.1 jklos 595 1.1 jklos #define adapter_info(adap) ((adap)->params.info) 596 1.1 jklos 597 1.3 christos static __inline int uses_xaui(const adapter_t *adap) 598 1.1 jklos { 599 1.1 jklos return adapter_info(adap)->caps & SUPPORTED_AUI; 600 1.1 jklos } 601 1.1 jklos 602 1.3 christos static __inline int is_10G(const adapter_t *adap) 603 1.1 jklos { 604 1.1 jklos return adapter_info(adap)->caps & SUPPORTED_10000baseT_Full; 605 1.1 jklos } 606 1.1 jklos 607 1.3 christos static __inline int is_offload(const adapter_t *adap) 608 1.1 jklos { 609 1.1 jklos #ifdef CONFIG_CHELSIO_T3_CORE 610 1.1 jklos return adap->params.offload; 611 1.1 jklos #else 612 1.1 jklos return 0; 613 1.1 jklos #endif 614 1.1 jklos } 615 1.1 jklos 616 1.3 christos static __inline unsigned int core_ticks_per_usec(const adapter_t *adap) 617 1.1 jklos { 618 1.1 jklos return adap->params.vpd.cclk / 1000; 619 1.1 jklos } 620 1.1 jklos 621 1.3 christos static __inline unsigned int dack_ticks_to_usec(const adapter_t *adap, 622 1.1 jklos unsigned int ticks) 623 1.1 jklos { 624 1.1 jklos return (ticks << adap->params.tp.dack_re) / core_ticks_per_usec(adap); 625 1.1 jklos } 626 1.1 jklos 627 1.3 christos static __inline unsigned int is_pcie(const adapter_t *adap) 628 1.1 jklos { 629 1.1 jklos return adap->params.pci.variant == PCI_VARIANT_PCIE; 630 1.1 jklos } 631 1.1 jklos 632 1.1 jklos void t3_set_reg_field(adapter_t *adap, unsigned int addr, u32 mask, u32 val); 633 1.1 jklos void t3_write_regs(adapter_t *adapter, const struct addr_val_pair *p, int n, 634 1.1 jklos unsigned int offset); 635 1.1 jklos int t3_wait_op_done_val(adapter_t *adapter, int reg, u32 mask, int polarity, 636 1.1 jklos int attempts, int delay, u32 *valp); 637 1.1 jklos 638 1.3 christos static __inline int t3_wait_op_done(adapter_t *adapter, int reg, u32 mask, 639 1.1 jklos int polarity, int attempts, int delay) 640 1.1 jklos { 641 1.1 jklos return t3_wait_op_done_val(adapter, reg, mask, polarity, attempts, 642 1.1 jklos delay, NULL); 643 1.1 jklos } 644 1.1 jklos 645 1.1 jklos int t3_mdio_change_bits(struct cphy *phy, int mmd, int reg, unsigned int clear, 646 1.1 jklos unsigned int set); 647 1.1 jklos int t3_phy_reset(struct cphy *phy, int mmd, int wait); 648 1.1 jklos int t3_phy_advertise(struct cphy *phy, unsigned int advert); 649 1.1 jklos int t3_set_phy_speed_duplex(struct cphy *phy, int speed, int duplex); 650 1.1 jklos 651 1.1 jklos void t3_intr_enable(adapter_t *adapter); 652 1.1 jklos void t3_intr_disable(adapter_t *adapter); 653 1.1 jklos void t3_intr_clear(adapter_t *adapter); 654 1.1 jklos void t3_port_intr_enable(adapter_t *adapter, int idx); 655 1.1 jklos void t3_port_intr_disable(adapter_t *adapter, int idx); 656 1.1 jklos void t3_port_intr_clear(adapter_t *adapter, int idx); 657 1.1 jklos int t3_slow_intr_handler(adapter_t *adapter); 658 1.1 jklos int t3_phy_intr_handler(adapter_t *adapter); 659 1.1 jklos 660 1.1 jklos void t3_link_changed(adapter_t *adapter, int port_id); 661 1.1 jklos int t3_link_start(struct cphy *phy, struct cmac *mac, struct link_config *lc); 662 1.1 jklos const struct adapter_info *t3_get_adapter_info(unsigned int board_id); 663 1.1 jklos int t3_seeprom_read(adapter_t *adapter, u32 addr, u32 *data); 664 1.1 jklos int t3_seeprom_write(adapter_t *adapter, u32 addr, u32 data); 665 1.1 jklos int t3_seeprom_wp(adapter_t *adapter, int enable); 666 1.1 jklos int t3_read_flash(adapter_t *adapter, unsigned int addr, unsigned int nwords, 667 1.1 jklos u32 *data, int byte_oriented); 668 1.1 jklos int t3_get_tp_version(adapter_t *adapter, u32 *vers); 669 1.1 jklos int t3_check_tpsram_version(adapter_t *adapter); 670 1.1 jklos int t3_check_tpsram(adapter_t *adapter, const u8 *tp_ram, unsigned int size); 671 1.2 joerg int t3_load_fw(adapter_t *adapter, const u8 *fw_data, unsigned int size); 672 1.1 jklos int t3_get_fw_version(adapter_t *adapter, u32 *vers); 673 1.1 jklos int t3_check_fw_version(adapter_t *adapter); 674 1.1 jklos int t3_init_hw(adapter_t *adapter, u32 fw_params); 675 1.1 jklos void mac_prep(struct cmac *mac, adapter_t *adapter, int index); 676 1.1 jklos void early_hw_init(adapter_t *adapter, const struct adapter_info *ai); 677 1.1 jklos int t3_prep_adapter(adapter_t *adapter, const struct adapter_info *ai, int reset); 678 1.1 jklos void t3_led_ready(adapter_t *adapter); 679 1.1 jklos void t3_fatal_err(adapter_t *adapter); 680 1.1 jklos void t3_set_vlan_accel(adapter_t *adapter, unsigned int ports, int on); 681 1.1 jklos void t3_enable_filters(adapter_t *adap); 682 1.1 jklos void t3_config_rss(adapter_t *adapter, unsigned int rss_config, const u8 *cpus, 683 1.1 jklos const u16 *rspq); 684 1.1 jklos int t3_read_rss(adapter_t *adapter, u8 *lkup, u16 *map); 685 1.1 jklos int t3_set_proto_sram(adapter_t *adap, const u8 *data); 686 1.1 jklos int t3_mps_set_active_ports(adapter_t *adap, unsigned int port_mask); 687 1.1 jklos void t3_port_failover(adapter_t *adapter, int port); 688 1.1 jklos void t3_failover_done(adapter_t *adapter, int port); 689 1.1 jklos void t3_failover_clear(adapter_t *adapter); 690 1.1 jklos int t3_cim_ctl_blk_read(adapter_t *adap, unsigned int addr, unsigned int n, 691 1.1 jklos unsigned int *valp); 692 1.1 jklos int t3_mc7_bd_read(struct mc7 *mc7, unsigned int start, unsigned int n, 693 1.1 jklos u64 *buf); 694 1.1 jklos 695 1.1 jklos int t3_mac_reset(struct cmac *mac); 696 1.1 jklos void t3b_pcs_reset(struct cmac *mac); 697 1.1 jklos int t3_mac_enable(struct cmac *mac, int which); 698 1.1 jklos int t3_mac_disable(struct cmac *mac, int which); 699 1.1 jklos int t3_mac_set_mtu(struct cmac *mac, unsigned int mtu); 700 1.1 jklos int t3_mac_set_rx_mode(struct cmac *mac, struct t3_rx_mode *rm); 701 1.1 jklos int t3_mac_set_address(struct cmac *mac, unsigned int idx, u8 addr[6]); 702 1.1 jklos int t3_mac_set_num_ucast(struct cmac *mac, unsigned char n); 703 1.1 jklos const struct mac_stats *t3_mac_update_stats(struct cmac *mac); 704 1.1 jklos int t3_mac_set_speed_duplex_fc(struct cmac *mac, int speed, int duplex, 705 1.1 jklos int fc); 706 1.1 jklos int t3b2_mac_watchdog_task(struct cmac *mac); 707 1.1 jklos 708 1.1 jklos void t3_mc5_prep(adapter_t *adapter, struct mc5 *mc5, int mode); 709 1.1 jklos int t3_mc5_init(struct mc5 *mc5, unsigned int nservers, unsigned int nfilters, 710 1.1 jklos unsigned int nroutes); 711 1.1 jklos void t3_mc5_intr_handler(struct mc5 *mc5); 712 1.1 jklos int t3_read_mc5_range(const struct mc5 *mc5, unsigned int start, unsigned int n, 713 1.1 jklos u32 *buf); 714 1.1 jklos 715 1.1 jklos #ifdef CONFIG_CHELSIO_T3_CORE 716 1.1 jklos int t3_tp_set_coalescing_size(adapter_t *adap, unsigned int size, int psh); 717 1.1 jklos void t3_tp_set_max_rxsize(adapter_t *adap, unsigned int size); 718 1.1 jklos void t3_tp_set_offload_mode(adapter_t *adap, int enable); 719 1.1 jklos void t3_tp_get_mib_stats(adapter_t *adap, struct tp_mib_stats *tps); 720 1.1 jklos void t3_load_mtus(adapter_t *adap, unsigned short mtus[NMTUS], 721 1.1 jklos unsigned short alpha[NCCTRL_WIN], 722 1.1 jklos unsigned short beta[NCCTRL_WIN], unsigned short mtu_cap); 723 1.1 jklos void t3_read_hw_mtus(adapter_t *adap, unsigned short mtus[NMTUS]); 724 1.1 jklos void t3_get_cong_cntl_tab(adapter_t *adap, 725 1.1 jklos unsigned short incr[NMTUS][NCCTRL_WIN]); 726 1.1 jklos void t3_config_trace_filter(adapter_t *adapter, const struct trace_params *tp, 727 1.1 jklos int filter_index, int invert, int enable); 728 1.1 jklos int t3_config_sched(adapter_t *adap, unsigned int kbps, int sched); 729 1.1 jklos int t3_set_sched_ipg(adapter_t *adap, int sched, unsigned int ipg); 730 1.1 jklos void t3_get_tx_sched(adapter_t *adap, unsigned int sched, unsigned int *kbps, 731 1.1 jklos unsigned int *ipg); 732 1.1 jklos void t3_read_pace_tbl(adapter_t *adap, unsigned int pace_vals[NTX_SCHED]); 733 1.1 jklos void t3_set_pace_tbl(adapter_t *adap, unsigned int *pace_vals, 734 1.1 jklos unsigned int start, unsigned int n); 735 1.1 jklos #endif 736 1.1 jklos 737 1.1 jklos void t3_sge_prep(adapter_t *adap, struct sge_params *p); 738 1.1 jklos void t3_sge_init(adapter_t *adap, struct sge_params *p); 739 1.1 jklos int t3_sge_init_ecntxt(adapter_t *adapter, unsigned int id, int gts_enable, 740 1.1 jklos enum sge_context_type type, int respq, u64 base_addr, 741 1.1 jklos unsigned int size, unsigned int token, int gen, 742 1.1 jklos unsigned int cidx); 743 1.1 jklos int t3_sge_init_flcntxt(adapter_t *adapter, unsigned int id, int gts_enable, 744 1.1 jklos u64 base_addr, unsigned int size, unsigned int esize, 745 1.1 jklos unsigned int cong_thres, int gen, unsigned int cidx); 746 1.1 jklos int t3_sge_init_rspcntxt(adapter_t *adapter, unsigned int id, int irq_vec_idx, 747 1.1 jklos u64 base_addr, unsigned int size, 748 1.1 jklos unsigned int fl_thres, int gen, unsigned int cidx); 749 1.1 jklos int t3_sge_init_cqcntxt(adapter_t *adapter, unsigned int id, u64 base_addr, 750 1.1 jklos unsigned int size, int rspq, int ovfl_mode, 751 1.1 jklos unsigned int credits, unsigned int credit_thres); 752 1.1 jklos int t3_sge_enable_ecntxt(adapter_t *adapter, unsigned int id, int enable); 753 1.1 jklos int t3_sge_disable_fl(adapter_t *adapter, unsigned int id); 754 1.1 jklos int t3_sge_disable_rspcntxt(adapter_t *adapter, unsigned int id); 755 1.1 jklos int t3_sge_disable_cqcntxt(adapter_t *adapter, unsigned int id); 756 1.1 jklos int t3_sge_read_ecntxt(adapter_t *adapter, unsigned int id, u32 data[4]); 757 1.1 jklos int t3_sge_read_fl(adapter_t *adapter, unsigned int id, u32 data[4]); 758 1.1 jklos int t3_sge_read_cq(adapter_t *adapter, unsigned int id, u32 data[4]); 759 1.1 jklos int t3_sge_read_rspq(adapter_t *adapter, unsigned int id, u32 data[4]); 760 1.1 jklos int t3_sge_cqcntxt_op(adapter_t *adapter, unsigned int id, unsigned int op, 761 1.1 jklos unsigned int credits); 762 1.1 jklos 763 1.1 jklos int t3_elmr_blk_write(adapter_t *adap, int start, const u32 *vals, int n); 764 1.1 jklos int t3_elmr_blk_read(adapter_t *adap, int start, u32 *vals, int n); 765 1.1 jklos int t3_vsc7323_init(adapter_t *adap, int nports); 766 1.1 jklos int t3_vsc7323_set_speed_fc(adapter_t *adap, int speed, int fc, int port); 767 1.1 jklos int t3_vsc7323_set_mtu(adapter_t *adap, unsigned int mtu, int port); 768 1.1 jklos int t3_vsc7323_set_addr(adapter_t *adap, u8 addr[6], int port); 769 1.1 jklos int t3_vsc7323_enable(adapter_t *adap, int port, int which); 770 1.1 jklos int t3_vsc7323_disable(adapter_t *adap, int port, int which); 771 1.1 jklos const struct mac_stats *t3_vsc7323_update_stats(struct cmac *mac); 772 1.1 jklos 773 1.1 jklos void t3_mv88e1xxx_phy_prep(struct cphy *phy, adapter_t *adapter, int phy_addr, 774 1.1 jklos const struct mdio_ops *mdio_ops); 775 1.1 jklos void t3_vsc8211_phy_prep(struct cphy *phy, adapter_t *adapter, int phy_addr, 776 1.1 jklos const struct mdio_ops *mdio_ops); 777 1.1 jklos void t3_ael1002_phy_prep(struct cphy *phy, adapter_t *adapter, int phy_addr, 778 1.1 jklos const struct mdio_ops *mdio_ops); 779 1.1 jklos void t3_ael1006_phy_prep(struct cphy *phy, adapter_t *adapter, int phy_addr, 780 1.1 jklos const struct mdio_ops *mdio_ops); 781 1.1 jklos void t3_qt2045_phy_prep(struct cphy *phy, adapter_t *adapter, int phy_addr, 782 1.1 jklos const struct mdio_ops *mdio_ops); 783 1.1 jklos void t3_xaui_direct_phy_prep(struct cphy *phy, adapter_t *adapter, int phy_addr, 784 1.1 jklos const struct mdio_ops *mdio_ops); 785 1.1 jklos #endif /* __CHELSIO_COMMON_H */ 786