0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036 #ifndef __T4VF_COMMON_H__
0037 #define __T4VF_COMMON_H__
0038
0039 #include "../cxgb4/t4_hw.h"
0040 #include "../cxgb4/t4fw_api.h"
0041
0042 #define CHELSIO_CHIP_CODE(version, revision) (((version) << 4) | (revision))
0043 #define CHELSIO_CHIP_VERSION(code) (((code) >> 4) & 0xf)
0044 #define CHELSIO_CHIP_RELEASE(code) ((code) & 0xf)
0045
0046
0047
0048
0049
0050
0051
0052
0053 #define CHELSIO_T4 0x4
0054 #define CHELSIO_T5 0x5
0055 #define CHELSIO_T6 0x6
0056
0057 enum chip_type {
0058 T4_A1 = CHELSIO_CHIP_CODE(CHELSIO_T4, 1),
0059 T4_A2 = CHELSIO_CHIP_CODE(CHELSIO_T4, 2),
0060 T4_FIRST_REV = T4_A1,
0061 T4_LAST_REV = T4_A2,
0062
0063 T5_A0 = CHELSIO_CHIP_CODE(CHELSIO_T5, 0),
0064 T5_A1 = CHELSIO_CHIP_CODE(CHELSIO_T5, 1),
0065 T5_FIRST_REV = T5_A0,
0066 T5_LAST_REV = T5_A1,
0067 };
0068
0069
0070
0071
0072 #define FW_LEN16(fw_struct) FW_CMD_LEN16_V(sizeof(fw_struct) / 16)
0073
0074
0075
0076
0077 struct t4vf_port_stats {
0078
0079
0080
0081 u64 tx_bcast_bytes;
0082 u64 tx_bcast_frames;
0083 u64 tx_mcast_bytes;
0084 u64 tx_mcast_frames;
0085 u64 tx_ucast_bytes;
0086 u64 tx_ucast_frames;
0087 u64 tx_drop_frames;
0088 u64 tx_offload_bytes;
0089 u64 tx_offload_frames;
0090
0091
0092
0093
0094 u64 rx_bcast_bytes;
0095 u64 rx_bcast_frames;
0096 u64 rx_mcast_bytes;
0097 u64 rx_mcast_frames;
0098 u64 rx_ucast_bytes;
0099 u64 rx_ucast_frames;
0100
0101 u64 rx_err_frames;
0102 };
0103
0104
0105
0106
0107 typedef u16 fw_port_cap16_t;
0108 typedef u32 fw_port_cap32_t;
0109
0110 enum fw_caps {
0111 FW_CAPS_UNKNOWN = 0,
0112 FW_CAPS16 = 1,
0113 FW_CAPS32 = 2,
0114 };
0115
0116 enum cc_pause {
0117 PAUSE_RX = 1 << 0,
0118 PAUSE_TX = 1 << 1,
0119 PAUSE_AUTONEG = 1 << 2
0120 };
0121
0122 enum cc_fec {
0123 FEC_AUTO = 1 << 0,
0124 FEC_RS = 1 << 1,
0125 FEC_BASER_RS = 1 << 2,
0126 };
0127
0128 struct link_config {
0129 fw_port_cap32_t pcaps;
0130 fw_port_cap32_t acaps;
0131 fw_port_cap32_t lpacaps;
0132
0133 fw_port_cap32_t speed_caps;
0134 u32 speed;
0135
0136 enum cc_pause requested_fc;
0137 enum cc_pause fc;
0138 enum cc_pause advertised_fc;
0139
0140 enum cc_fec auto_fec;
0141 enum cc_fec requested_fec;
0142 enum cc_fec fec;
0143
0144 unsigned char autoneg;
0145
0146 unsigned char link_ok;
0147 unsigned char link_down_rc;
0148 };
0149
0150
0151
0152
0153 static inline bool is_x_10g_port(const struct link_config *lc)
0154 {
0155 fw_port_cap32_t speeds, high_speeds;
0156
0157 speeds = FW_PORT_CAP32_SPEED_V(FW_PORT_CAP32_SPEED_G(lc->pcaps));
0158 high_speeds =
0159 speeds & ~(FW_PORT_CAP32_SPEED_100M | FW_PORT_CAP32_SPEED_1G);
0160
0161 return high_speeds != 0;
0162 }
0163
0164
0165
0166
0167 struct dev_params {
0168 u32 fwrev;
0169 u32 tprev;
0170 };
0171
0172
0173
0174
0175
0176
0177 struct sge_params {
0178 u32 sge_control;
0179 u32 sge_control2;
0180 u32 sge_host_page_size;
0181 u32 sge_egress_queues_per_page;
0182 u32 sge_ingress_queues_per_page;
0183 u32 sge_vf_hps;
0184 u32 sge_vf_eq_qpp;
0185 u32 sge_vf_iq_qpp;
0186 u32 sge_fl_buffer_size[16];
0187 u32 sge_ingress_rx_threshold;
0188 u32 sge_congestion_control;
0189 u32 sge_timer_value_0_and_1;
0190 u32 sge_timer_value_2_and_3;
0191 u32 sge_timer_value_4_and_5;
0192 };
0193
0194
0195
0196
0197 struct vpd_params {
0198 u32 cclk;
0199 };
0200
0201
0202 struct arch_specific_params {
0203 u32 sge_fl_db;
0204 u16 mps_tcam_size;
0205 };
0206
0207
0208
0209
0210 struct rss_params {
0211 unsigned int mode;
0212 union {
0213 struct {
0214 unsigned int synmapen:1;
0215 unsigned int syn4tupenipv6:1;
0216 unsigned int syn2tupenipv6:1;
0217 unsigned int syn4tupenipv4:1;
0218 unsigned int syn2tupenipv4:1;
0219 unsigned int ofdmapen:1;
0220 unsigned int tnlmapen:1;
0221 unsigned int tnlalllookup:1;
0222 unsigned int hashtoeplitz:1;
0223 } basicvirtual;
0224 } u;
0225 };
0226
0227
0228
0229
0230 union rss_vi_config {
0231 struct {
0232 u16 defaultq;
0233 unsigned int ip6fourtupen:1;
0234 unsigned int ip6twotupen:1;
0235 unsigned int ip4fourtupen:1;
0236 unsigned int ip4twotupen:1;
0237 int udpen;
0238 } basicvirtual;
0239 };
0240
0241
0242
0243
0244 struct vf_resources {
0245 unsigned int nvi;
0246 unsigned int neq;
0247 unsigned int nethctrl;
0248 unsigned int niqflint;
0249 unsigned int niq;
0250 unsigned int tc;
0251 unsigned int pmask;
0252 unsigned int nexactf;
0253 unsigned int r_caps;
0254 unsigned int wx_caps;
0255 };
0256
0257
0258
0259
0260 struct adapter_params {
0261 struct dev_params dev;
0262 struct sge_params sge;
0263 struct vpd_params vpd;
0264 struct rss_params rss;
0265 struct vf_resources vfres;
0266 struct arch_specific_params arch;
0267 enum chip_type chip;
0268 u8 nports;
0269 u8 fw_caps_support;
0270 };
0271
0272
0273
0274
0275
0276 struct mbox_cmd {
0277 u64 cmd[MBOX_LEN / 8];
0278 u64 timestamp;
0279 u32 seqno;
0280 s16 access;
0281 s16 execute;
0282 };
0283
0284 struct mbox_cmd_log {
0285 unsigned int size;
0286 unsigned int cursor;
0287 u32 seqno;
0288
0289 };
0290
0291
0292
0293
0294 static inline struct mbox_cmd *mbox_cmd_log_entry(struct mbox_cmd_log *log,
0295 unsigned int entry_idx)
0296 {
0297 return &((struct mbox_cmd *)&(log)[1])[entry_idx];
0298 }
0299
0300 #include "adapter.h"
0301
0302 #ifndef PCI_VENDOR_ID_CHELSIO
0303 # define PCI_VENDOR_ID_CHELSIO 0x1425
0304 #endif
0305
0306 #define for_each_port(adapter, iter) \
0307 for (iter = 0; iter < (adapter)->params.nports; iter++)
0308
0309 static inline unsigned int core_ticks_per_usec(const struct adapter *adapter)
0310 {
0311 return adapter->params.vpd.cclk / 1000;
0312 }
0313
0314 static inline unsigned int us_to_core_ticks(const struct adapter *adapter,
0315 unsigned int us)
0316 {
0317 return (us * adapter->params.vpd.cclk) / 1000;
0318 }
0319
0320 static inline unsigned int core_ticks_to_us(const struct adapter *adapter,
0321 unsigned int ticks)
0322 {
0323 return (ticks * 1000) / adapter->params.vpd.cclk;
0324 }
0325
0326 int t4vf_wr_mbox_core(struct adapter *, const void *, int, void *, bool);
0327
0328 static inline int t4vf_wr_mbox(struct adapter *adapter, const void *cmd,
0329 int size, void *rpl)
0330 {
0331 return t4vf_wr_mbox_core(adapter, cmd, size, rpl, true);
0332 }
0333
0334 static inline int t4vf_wr_mbox_ns(struct adapter *adapter, const void *cmd,
0335 int size, void *rpl)
0336 {
0337 return t4vf_wr_mbox_core(adapter, cmd, size, rpl, false);
0338 }
0339
0340 #define CHELSIO_PCI_ID_VER(dev_id) ((dev_id) >> 12)
0341
0342 static inline int is_t4(enum chip_type chip)
0343 {
0344 return CHELSIO_CHIP_VERSION(chip) == CHELSIO_T4;
0345 }
0346
0347
0348
0349
0350
0351
0352
0353
0354 static inline int hash_mac_addr(const u8 *addr)
0355 {
0356 u32 a = ((u32)addr[0] << 16) | ((u32)addr[1] << 8) | addr[2];
0357 u32 b = ((u32)addr[3] << 16) | ((u32)addr[4] << 8) | addr[5];
0358
0359 a ^= b;
0360 a ^= (a >> 12);
0361 a ^= (a >> 6);
0362 return a & 0x3f;
0363 }
0364
0365 int t4vf_wait_dev_ready(struct adapter *);
0366 int t4vf_port_init(struct adapter *, int);
0367
0368 int t4vf_fw_reset(struct adapter *);
0369 int t4vf_set_params(struct adapter *, unsigned int, const u32 *, const u32 *);
0370
0371 int t4vf_fl_pkt_align(struct adapter *adapter);
0372 enum t4_bar2_qtype { T4_BAR2_QTYPE_EGRESS, T4_BAR2_QTYPE_INGRESS };
0373 int t4vf_bar2_sge_qregs(struct adapter *adapter,
0374 unsigned int qid,
0375 enum t4_bar2_qtype qtype,
0376 u64 *pbar2_qoffset,
0377 unsigned int *pbar2_qid);
0378
0379 unsigned int t4vf_get_pf_from_vf(struct adapter *);
0380 int t4vf_get_sge_params(struct adapter *);
0381 int t4vf_get_vpd_params(struct adapter *);
0382 int t4vf_get_dev_params(struct adapter *);
0383 int t4vf_get_rss_glb_config(struct adapter *);
0384 int t4vf_get_vfres(struct adapter *);
0385
0386 int t4vf_read_rss_vi_config(struct adapter *, unsigned int,
0387 union rss_vi_config *);
0388 int t4vf_write_rss_vi_config(struct adapter *, unsigned int,
0389 union rss_vi_config *);
0390 int t4vf_config_rss_range(struct adapter *, unsigned int, int, int,
0391 const u16 *, int);
0392
0393 int t4vf_alloc_vi(struct adapter *, int);
0394 int t4vf_free_vi(struct adapter *, int);
0395 int t4vf_enable_vi(struct adapter *adapter, unsigned int viid, bool rx_en,
0396 bool tx_en);
0397 int t4vf_enable_pi(struct adapter *adapter, struct port_info *pi, bool rx_en,
0398 bool tx_en);
0399 int t4vf_identify_port(struct adapter *, unsigned int, unsigned int);
0400
0401 int t4vf_set_rxmode(struct adapter *, unsigned int, int, int, int, int, int,
0402 bool);
0403 int t4vf_alloc_mac_filt(struct adapter *, unsigned int, bool, unsigned int,
0404 const u8 **, u16 *, u64 *, bool);
0405 int t4vf_free_mac_filt(struct adapter *, unsigned int, unsigned int naddr,
0406 const u8 **, bool);
0407 int t4vf_change_mac(struct adapter *, unsigned int, int, const u8 *, bool);
0408 int t4vf_set_addr_hash(struct adapter *, unsigned int, bool, u64, bool);
0409 int t4vf_get_port_stats(struct adapter *, int, struct t4vf_port_stats *);
0410
0411 int t4vf_iq_free(struct adapter *, unsigned int, unsigned int, unsigned int,
0412 unsigned int);
0413 int t4vf_eth_eq_free(struct adapter *, unsigned int);
0414
0415 int t4vf_update_port_info(struct port_info *pi);
0416 int t4vf_handle_fw_rpl(struct adapter *, const __be64 *);
0417 int t4vf_prep_adapter(struct adapter *);
0418 int t4vf_get_vf_mac_acl(struct adapter *adapter, unsigned int port,
0419 unsigned int *naddr, u8 *addr);
0420 int t4vf_get_vf_vlan_acl(struct adapter *adapter);
0421
0422 #endif