1 /* 2 * This file is part of the Chelsio T4 PCI-E SR-IOV Virtual Function Ethernet 3 * driver for Linux. 4 * 5 * Copyright (c) 2009-2010 Chelsio Communications, Inc. All rights reserved. 6 * 7 * This software is available to you under a choice of one of two 8 * licenses. You may choose to be licensed under the terms of the GNU 9 * General Public License (GPL) Version 2, available from the file 10 * COPYING in the main directory of this source tree, or the 11 * OpenIB.org BSD license below: 12 * 13 * Redistribution and use in source and binary forms, with or 14 * without modification, are permitted provided that the following 15 * conditions are met: 16 * 17 * - Redistributions of source code must retain the above 18 * copyright notice, this list of conditions and the following 19 * disclaimer. 20 * 21 * - Redistributions in binary form must reproduce the above 22 * copyright notice, this list of conditions and the following 23 * disclaimer in the documentation and/or other materials 24 * provided with the distribution. 25 * 26 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 27 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 28 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 29 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 30 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 31 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 32 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 33 * SOFTWARE. 34 */ 35 36 #ifndef __T4VF_COMMON_H__ 37 #define __T4VF_COMMON_H__ 38 39 #include "../cxgb4/t4fw_api.h" 40 41 /* 42 * The "len16" field of a Firmware Command Structure ... 43 */ 44 #define FW_LEN16(fw_struct) FW_CMD_LEN16(sizeof(fw_struct) / 16) 45 46 /* 47 * Per-VF statistics. 48 */ 49 struct t4vf_port_stats { 50 /* 51 * TX statistics. 52 */ 53 u64 tx_bcast_bytes; /* broadcast */ 54 u64 tx_bcast_frames; 55 u64 tx_mcast_bytes; /* multicast */ 56 u64 tx_mcast_frames; 57 u64 tx_ucast_bytes; /* unicast */ 58 u64 tx_ucast_frames; 59 u64 tx_drop_frames; /* TX dropped frames */ 60 u64 tx_offload_bytes; /* offload */ 61 u64 tx_offload_frames; 62 63 /* 64 * RX statistics. 65 */ 66 u64 rx_bcast_bytes; /* broadcast */ 67 u64 rx_bcast_frames; 68 u64 rx_mcast_bytes; /* multicast */ 69 u64 rx_mcast_frames; 70 u64 rx_ucast_bytes; 71 u64 rx_ucast_frames; /* unicast */ 72 73 u64 rx_err_frames; /* RX error frames */ 74 }; 75 76 /* 77 * Per-"port" (Virtual Interface) link configuration ... 78 */ 79 struct link_config { 80 unsigned int supported; /* link capabilities */ 81 unsigned int advertising; /* advertised capabilities */ 82 unsigned short requested_speed; /* speed user has requested */ 83 unsigned short speed; /* actual link speed */ 84 unsigned char requested_fc; /* flow control user has requested */ 85 unsigned char fc; /* actual link flow control */ 86 unsigned char autoneg; /* autonegotiating? */ 87 unsigned char link_ok; /* link up? */ 88 }; 89 90 enum { 91 PAUSE_RX = 1 << 0, 92 PAUSE_TX = 1 << 1, 93 PAUSE_AUTONEG = 1 << 2 94 }; 95 96 /* 97 * General device parameters ... 98 */ 99 struct dev_params { 100 u32 fwrev; /* firmware version */ 101 u32 tprev; /* TP Microcode Version */ 102 }; 103 104 /* 105 * Scatter Gather Engine parameters. These are almost all determined by the 106 * Physical Function Driver. We just need to grab them to see within which 107 * environment we're playing ... 108 */ 109 struct sge_params { 110 u32 sge_control; /* padding, boundaries, lengths, etc. */ 111 u32 sge_host_page_size; /* RDMA page sizes */ 112 u32 sge_queues_per_page; /* RDMA queues/page */ 113 u32 sge_user_mode_limits; /* limits for BAR2 user mode accesses */ 114 u32 sge_fl_buffer_size[16]; /* free list buffer sizes */ 115 u32 sge_ingress_rx_threshold; /* RX counter interrupt threshold[4] */ 116 u32 sge_timer_value_0_and_1; /* interrupt coalescing timer values */ 117 u32 sge_timer_value_2_and_3; 118 u32 sge_timer_value_4_and_5; 119 }; 120 121 /* 122 * Vital Product Data parameters. 123 */ 124 struct vpd_params { 125 u32 cclk; /* Core Clock (KHz) */ 126 }; 127 128 /* 129 * Global Receive Side Scaling (RSS) parameters in host-native format. 130 */ 131 struct rss_params { 132 unsigned int mode; /* RSS mode */ 133 union { 134 struct { 135 unsigned int synmapen:1; /* SYN Map Enable */ 136 unsigned int syn4tupenipv6:1; /* enable hashing 4-tuple IPv6 SYNs */ 137 unsigned int syn2tupenipv6:1; /* enable hashing 2-tuple IPv6 SYNs */ 138 unsigned int syn4tupenipv4:1; /* enable hashing 4-tuple IPv4 SYNs */ 139 unsigned int syn2tupenipv4:1; /* enable hashing 2-tuple IPv4 SYNs */ 140 unsigned int ofdmapen:1; /* Offload Map Enable */ 141 unsigned int tnlmapen:1; /* Tunnel Map Enable */ 142 unsigned int tnlalllookup:1; /* Tunnel All Lookup */ 143 unsigned int hashtoeplitz:1; /* use Toeplitz hash */ 144 } basicvirtual; 145 } u; 146 }; 147 148 /* 149 * Virtual Interface RSS Configuration in host-native format. 150 */ 151 union rss_vi_config { 152 struct { 153 u16 defaultq; /* Ingress Queue ID for !tnlalllookup */ 154 unsigned int ip6fourtupen:1; /* hash 4-tuple IPv6 ingress packets */ 155 unsigned int ip6twotupen:1; /* hash 2-tuple IPv6 ingress packets */ 156 unsigned int ip4fourtupen:1; /* hash 4-tuple IPv4 ingress packets */ 157 unsigned int ip4twotupen:1; /* hash 2-tuple IPv4 ingress packets */ 158 int udpen; /* hash 4-tuple UDP ingress packets */ 159 } basicvirtual; 160 }; 161 162 /* 163 * Maximum resources provisioned for a PCI VF. 164 */ 165 struct vf_resources { 166 unsigned int nvi; /* N virtual interfaces */ 167 unsigned int neq; /* N egress Qs */ 168 unsigned int nethctrl; /* N egress ETH or CTRL Qs */ 169 unsigned int niqflint; /* N ingress Qs/w free list(s) & intr */ 170 unsigned int niq; /* N ingress Qs */ 171 unsigned int tc; /* PCI-E traffic class */ 172 unsigned int pmask; /* port access rights mask */ 173 unsigned int nexactf; /* N exact MPS filters */ 174 unsigned int r_caps; /* read capabilities */ 175 unsigned int wx_caps; /* write/execute capabilities */ 176 }; 177 178 /* 179 * Per-"adapter" (Virtual Function) parameters. 180 */ 181 struct adapter_params { 182 struct dev_params dev; /* general device parameters */ 183 struct sge_params sge; /* Scatter Gather Engine */ 184 struct vpd_params vpd; /* Vital Product Data */ 185 struct rss_params rss; /* Receive Side Scaling */ 186 struct vf_resources vfres; /* Virtual Function Resource limits */ 187 u8 nports; /* # of Ethernet "ports" */ 188 }; 189 190 #include "adapter.h" 191 192 #ifndef PCI_VENDOR_ID_CHELSIO 193 # define PCI_VENDOR_ID_CHELSIO 0x1425 194 #endif 195 196 #define for_each_port(adapter, iter) \ 197 for (iter = 0; iter < (adapter)->params.nports; iter++) 198 199 static inline bool is_10g_port(const struct link_config *lc) 200 { 201 return (lc->supported & SUPPORTED_10000baseT_Full) != 0; 202 } 203 204 static inline unsigned int core_ticks_per_usec(const struct adapter *adapter) 205 { 206 return adapter->params.vpd.cclk / 1000; 207 } 208 209 static inline unsigned int us_to_core_ticks(const struct adapter *adapter, 210 unsigned int us) 211 { 212 return (us * adapter->params.vpd.cclk) / 1000; 213 } 214 215 static inline unsigned int core_ticks_to_us(const struct adapter *adapter, 216 unsigned int ticks) 217 { 218 return (ticks * 1000) / adapter->params.vpd.cclk; 219 } 220 221 int t4vf_wr_mbox_core(struct adapter *, const void *, int, void *, bool); 222 223 static inline int t4vf_wr_mbox(struct adapter *adapter, const void *cmd, 224 int size, void *rpl) 225 { 226 return t4vf_wr_mbox_core(adapter, cmd, size, rpl, true); 227 } 228 229 static inline int t4vf_wr_mbox_ns(struct adapter *adapter, const void *cmd, 230 int size, void *rpl) 231 { 232 return t4vf_wr_mbox_core(adapter, cmd, size, rpl, false); 233 } 234 235 int __devinit t4vf_wait_dev_ready(struct adapter *); 236 int __devinit t4vf_port_init(struct adapter *, int); 237 238 int t4vf_fw_reset(struct adapter *); 239 int t4vf_query_params(struct adapter *, unsigned int, const u32 *, u32 *); 240 int t4vf_set_params(struct adapter *, unsigned int, const u32 *, const u32 *); 241 242 int t4vf_get_sge_params(struct adapter *); 243 int t4vf_get_vpd_params(struct adapter *); 244 int t4vf_get_dev_params(struct adapter *); 245 int t4vf_get_rss_glb_config(struct adapter *); 246 int t4vf_get_vfres(struct adapter *); 247 248 int t4vf_read_rss_vi_config(struct adapter *, unsigned int, 249 union rss_vi_config *); 250 int t4vf_write_rss_vi_config(struct adapter *, unsigned int, 251 union rss_vi_config *); 252 int t4vf_config_rss_range(struct adapter *, unsigned int, int, int, 253 const u16 *, int); 254 255 int t4vf_alloc_vi(struct adapter *, int); 256 int t4vf_free_vi(struct adapter *, int); 257 int t4vf_enable_vi(struct adapter *, unsigned int, bool, bool); 258 int t4vf_identify_port(struct adapter *, unsigned int, unsigned int); 259 260 int t4vf_set_rxmode(struct adapter *, unsigned int, int, int, int, int, int, 261 bool); 262 int t4vf_alloc_mac_filt(struct adapter *, unsigned int, bool, unsigned int, 263 const u8 **, u16 *, u64 *, bool); 264 int t4vf_change_mac(struct adapter *, unsigned int, int, const u8 *, bool); 265 int t4vf_set_addr_hash(struct adapter *, unsigned int, bool, u64, bool); 266 int t4vf_get_port_stats(struct adapter *, int, struct t4vf_port_stats *); 267 268 int t4vf_iq_free(struct adapter *, unsigned int, unsigned int, unsigned int, 269 unsigned int); 270 int t4vf_eth_eq_free(struct adapter *, unsigned int); 271 272 int t4vf_handle_fw_rpl(struct adapter *, const __be64 *); 273 274 #endif /* __T4VF_COMMON_H__ */ 275