Jacob Keller | 8664109 | 2016-04-07 08:21:21 -0700 | [diff] [blame] | 1 | /* Intel(R) Ethernet Switch Host Interface Driver |
Jacob Keller | 9de6a1a | 2016-04-01 16:17:31 -0700 | [diff] [blame] | 2 | * Copyright(c) 2013 - 2016 Intel Corporation. |
Alexander Duyck | b3890e3 | 2014-09-20 19:46:05 -0400 | [diff] [blame] | 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify it |
| 5 | * under the terms and conditions of the GNU General Public License, |
| 6 | * version 2, as published by the Free Software Foundation. |
| 7 | * |
| 8 | * This program is distributed in the hope it will be useful, but WITHOUT |
| 9 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 10 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 11 | * more details. |
| 12 | * |
| 13 | * The full GNU General Public License is included in this distribution in |
| 14 | * the file called "COPYING". |
| 15 | * |
| 16 | * Contact Information: |
| 17 | * e1000-devel Mailing List <e1000-devel@lists.sourceforge.net> |
| 18 | * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 |
| 19 | */ |
| 20 | |
| 21 | #ifndef _FM10K_H_ |
| 22 | #define _FM10K_H_ |
| 23 | |
| 24 | #include <linux/types.h> |
| 25 | #include <linux/etherdevice.h> |
Jacob Keller | 504b0fd | 2015-10-29 13:43:40 -0700 | [diff] [blame] | 26 | #include <linux/cpumask.h> |
Alexander Duyck | b3890e3 | 2014-09-20 19:46:05 -0400 | [diff] [blame] | 27 | #include <linux/rtnetlink.h> |
| 28 | #include <linux/if_vlan.h> |
| 29 | #include <linux/pci.h> |
| 30 | |
Alexander Duyck | 0e7b364 | 2014-09-20 19:48:10 -0400 | [diff] [blame] | 31 | #include "fm10k_pf.h" |
Alexander Duyck | 5cb8db4 | 2014-09-20 19:51:40 -0400 | [diff] [blame] | 32 | #include "fm10k_vf.h" |
Alexander Duyck | 0e7b364 | 2014-09-20 19:48:10 -0400 | [diff] [blame] | 33 | |
Jacob Keller | 8c7ee6d | 2015-08-25 13:49:11 -0700 | [diff] [blame] | 34 | #define FM10K_MAX_JUMBO_FRAME_SIZE 15342 /* Maximum supported size 15K */ |
Alexander Duyck | 0e7b364 | 2014-09-20 19:48:10 -0400 | [diff] [blame] | 35 | |
Alexander Duyck | e27ef59 | 2014-09-20 19:49:03 -0400 | [diff] [blame] | 36 | #define MAX_QUEUES FM10K_MAX_QUEUES_PF |
| 37 | |
| 38 | #define FM10K_MIN_RXD 128 |
| 39 | #define FM10K_MAX_RXD 4096 |
| 40 | #define FM10K_DEFAULT_RXD 256 |
| 41 | |
| 42 | #define FM10K_MIN_TXD 128 |
| 43 | #define FM10K_MAX_TXD 4096 |
| 44 | #define FM10K_DEFAULT_TXD 256 |
| 45 | #define FM10K_DEFAULT_TX_WORK 256 |
| 46 | |
| 47 | #define FM10K_RXBUFFER_256 256 |
Alexander Duyck | e27ef59 | 2014-09-20 19:49:03 -0400 | [diff] [blame] | 48 | #define FM10K_RX_HDR_LEN FM10K_RXBUFFER_256 |
Alexander Duyck | fd33396 | 2014-09-26 06:33:49 +0000 | [diff] [blame] | 49 | #define FM10K_RXBUFFER_2048 2048 |
| 50 | #define FM10K_RX_BUFSZ FM10K_RXBUFFER_2048 |
Alexander Duyck | e27ef59 | 2014-09-20 19:49:03 -0400 | [diff] [blame] | 51 | |
| 52 | /* How many Rx Buffers do we bundle into one write to the hardware ? */ |
| 53 | #define FM10K_RX_BUFFER_WRITE 16 /* Must be power of 2 */ |
| 54 | |
Alexander Duyck | 5cd5e2e | 2014-09-20 19:51:15 -0400 | [diff] [blame] | 55 | #define FM10K_MAX_STATIONS 63 |
| 56 | struct fm10k_l2_accel { |
| 57 | int size; |
| 58 | u16 count; |
| 59 | u16 dglort; |
| 60 | struct rcu_head rcu; |
| 61 | struct net_device *macvlan[0]; |
| 62 | }; |
| 63 | |
Alexander Duyck | e27ef59 | 2014-09-20 19:49:03 -0400 | [diff] [blame] | 64 | enum fm10k_ring_state_t { |
| 65 | __FM10K_TX_DETECT_HANG, |
| 66 | __FM10K_HANG_CHECK_ARMED, |
Jacob Keller | 504b0fd | 2015-10-29 13:43:40 -0700 | [diff] [blame] | 67 | __FM10K_TX_XPS_INIT_DONE, |
Alexander Duyck | e27ef59 | 2014-09-20 19:49:03 -0400 | [diff] [blame] | 68 | }; |
| 69 | |
| 70 | #define check_for_tx_hang(ring) \ |
| 71 | test_bit(__FM10K_TX_DETECT_HANG, &(ring)->state) |
| 72 | #define set_check_for_tx_hang(ring) \ |
| 73 | set_bit(__FM10K_TX_DETECT_HANG, &(ring)->state) |
| 74 | #define clear_check_for_tx_hang(ring) \ |
| 75 | clear_bit(__FM10K_TX_DETECT_HANG, &(ring)->state) |
| 76 | |
| 77 | struct fm10k_tx_buffer { |
| 78 | struct fm10k_tx_desc *next_to_watch; |
| 79 | struct sk_buff *skb; |
| 80 | unsigned int bytecount; |
| 81 | u16 gso_segs; |
| 82 | u16 tx_flags; |
| 83 | DEFINE_DMA_UNMAP_ADDR(dma); |
| 84 | DEFINE_DMA_UNMAP_LEN(len); |
| 85 | }; |
| 86 | |
| 87 | struct fm10k_rx_buffer { |
| 88 | dma_addr_t dma; |
| 89 | struct page *page; |
| 90 | u32 page_offset; |
| 91 | }; |
| 92 | |
| 93 | struct fm10k_queue_stats { |
| 94 | u64 packets; |
| 95 | u64 bytes; |
| 96 | }; |
| 97 | |
| 98 | struct fm10k_tx_queue_stats { |
| 99 | u64 restart_queue; |
| 100 | u64 csum_err; |
| 101 | u64 tx_busy; |
| 102 | u64 tx_done_old; |
Jacob Keller | 80043f3 | 2015-07-01 17:38:36 -0700 | [diff] [blame] | 103 | u64 csum_good; |
Alexander Duyck | e27ef59 | 2014-09-20 19:49:03 -0400 | [diff] [blame] | 104 | }; |
| 105 | |
| 106 | struct fm10k_rx_queue_stats { |
| 107 | u64 alloc_failed; |
| 108 | u64 csum_err; |
| 109 | u64 errors; |
Jacob Keller | 80043f3 | 2015-07-01 17:38:36 -0700 | [diff] [blame] | 110 | u64 csum_good; |
| 111 | u64 switch_errors; |
| 112 | u64 drops; |
| 113 | u64 pp_errors; |
| 114 | u64 link_errors; |
| 115 | u64 length_errors; |
Alexander Duyck | e27ef59 | 2014-09-20 19:49:03 -0400 | [diff] [blame] | 116 | }; |
| 117 | |
| 118 | struct fm10k_ring { |
| 119 | struct fm10k_q_vector *q_vector;/* backpointer to host q_vector */ |
| 120 | struct net_device *netdev; /* netdev ring belongs to */ |
| 121 | struct device *dev; /* device for DMA mapping */ |
Alexander Duyck | 5cd5e2e | 2014-09-20 19:51:15 -0400 | [diff] [blame] | 122 | struct fm10k_l2_accel __rcu *l2_accel; /* L2 acceleration list */ |
Alexander Duyck | e27ef59 | 2014-09-20 19:49:03 -0400 | [diff] [blame] | 123 | void *desc; /* descriptor ring memory */ |
| 124 | union { |
| 125 | struct fm10k_tx_buffer *tx_buffer; |
| 126 | struct fm10k_rx_buffer *rx_buffer; |
| 127 | }; |
| 128 | u32 __iomem *tail; |
| 129 | unsigned long state; |
| 130 | dma_addr_t dma; /* phys. address of descriptor ring */ |
| 131 | unsigned int size; /* length in bytes */ |
| 132 | |
| 133 | u8 queue_index; /* needed for queue management */ |
| 134 | u8 reg_idx; /* holds the special value that gets |
| 135 | * the hardware register offset |
| 136 | * associated with this ring, which is |
| 137 | * different for DCB and RSS modes |
| 138 | */ |
| 139 | u8 qos_pc; /* priority class of queue */ |
Jacob Keller | aa502b4 | 2015-11-02 12:10:22 -0800 | [diff] [blame] | 140 | u16 vid; /* default VLAN ID of queue */ |
Alexander Duyck | e27ef59 | 2014-09-20 19:49:03 -0400 | [diff] [blame] | 141 | u16 count; /* amount of descriptors */ |
| 142 | |
| 143 | u16 next_to_alloc; |
| 144 | u16 next_to_use; |
| 145 | u16 next_to_clean; |
| 146 | |
| 147 | struct fm10k_queue_stats stats; |
| 148 | struct u64_stats_sync syncp; |
| 149 | union { |
| 150 | /* Tx */ |
| 151 | struct fm10k_tx_queue_stats tx_stats; |
| 152 | /* Rx */ |
| 153 | struct { |
| 154 | struct fm10k_rx_queue_stats rx_stats; |
| 155 | struct sk_buff *skb; |
| 156 | }; |
| 157 | }; |
| 158 | } ____cacheline_internodealigned_in_smp; |
| 159 | |
Alexander Duyck | 18283ca | 2014-09-20 19:48:51 -0400 | [diff] [blame] | 160 | struct fm10k_ring_container { |
Alexander Duyck | e27ef59 | 2014-09-20 19:49:03 -0400 | [diff] [blame] | 161 | struct fm10k_ring *ring; /* pointer to linked list of rings */ |
Alexander Duyck | 18283ca | 2014-09-20 19:48:51 -0400 | [diff] [blame] | 162 | unsigned int total_bytes; /* total bytes processed this int */ |
| 163 | unsigned int total_packets; /* total packets processed this int */ |
| 164 | u16 work_limit; /* total work allowed per interrupt */ |
| 165 | u16 itr; /* interrupt throttle rate value */ |
Bruce Allan | 3d02b3d | 2015-10-28 17:19:56 -0700 | [diff] [blame] | 166 | u8 itr_scale; /* ITR adjustment based on PCI speed */ |
Alexander Duyck | 18283ca | 2014-09-20 19:48:51 -0400 | [diff] [blame] | 167 | u8 count; /* total number of rings in vector */ |
| 168 | }; |
| 169 | |
| 170 | #define FM10K_ITR_MAX 0x0FFF /* maximum value for ITR */ |
| 171 | #define FM10K_ITR_10K 100 /* 100us */ |
| 172 | #define FM10K_ITR_20K 50 /* 50us */ |
Jacob Keller | dbf4284 | 2015-10-16 10:57:09 -0700 | [diff] [blame] | 173 | #define FM10K_ITR_40K 25 /* 25us */ |
Alexander Duyck | 18283ca | 2014-09-20 19:48:51 -0400 | [diff] [blame] | 174 | #define FM10K_ITR_ADAPTIVE 0x8000 /* adaptive interrupt moderation flag */ |
| 175 | |
Jacob Keller | 584373f | 2015-10-16 10:57:06 -0700 | [diff] [blame] | 176 | #define ITR_IS_ADAPTIVE(itr) (!!(itr & FM10K_ITR_ADAPTIVE)) |
| 177 | |
Jacob Keller | dbf4284 | 2015-10-16 10:57:09 -0700 | [diff] [blame] | 178 | #define FM10K_TX_ITR_DEFAULT FM10K_ITR_40K |
Jacob Keller | 436ea95 | 2015-10-16 10:57:08 -0700 | [diff] [blame] | 179 | #define FM10K_RX_ITR_DEFAULT FM10K_ITR_20K |
Alexander Duyck | 18283ca | 2014-09-20 19:48:51 -0400 | [diff] [blame] | 180 | #define FM10K_ITR_ENABLE (FM10K_ITR_AUTOMASK | FM10K_ITR_MASK_CLEAR) |
| 181 | |
Alexander Duyck | e27ef59 | 2014-09-20 19:49:03 -0400 | [diff] [blame] | 182 | static inline struct netdev_queue *txring_txq(const struct fm10k_ring *ring) |
| 183 | { |
| 184 | return &ring->netdev->_tx[ring->queue_index]; |
| 185 | } |
| 186 | |
| 187 | /* iterator for handling rings in ring container */ |
| 188 | #define fm10k_for_each_ring(pos, head) \ |
| 189 | for (pos = &(head).ring[(head).count]; (--pos) >= (head).ring;) |
| 190 | |
Alexander Duyck | 18283ca | 2014-09-20 19:48:51 -0400 | [diff] [blame] | 191 | #define MAX_Q_VECTORS 256 |
| 192 | #define MIN_Q_VECTORS 1 |
| 193 | enum fm10k_non_q_vectors { |
| 194 | FM10K_MBX_VECTOR, |
Alexander Duyck | 5cb8db4 | 2014-09-20 19:51:40 -0400 | [diff] [blame] | 195 | #define NON_Q_VECTORS_VF NON_Q_VECTORS_PF |
Alexander Duyck | 18283ca | 2014-09-20 19:48:51 -0400 | [diff] [blame] | 196 | NON_Q_VECTORS_PF |
| 197 | }; |
| 198 | |
| 199 | #define NON_Q_VECTORS(hw) (((hw)->mac.type == fm10k_mac_pf) ? \ |
| 200 | NON_Q_VECTORS_PF : \ |
Alexander Duyck | 5cb8db4 | 2014-09-20 19:51:40 -0400 | [diff] [blame] | 201 | NON_Q_VECTORS_VF) |
Alexander Duyck | 18283ca | 2014-09-20 19:48:51 -0400 | [diff] [blame] | 202 | #define MIN_MSIX_COUNT(hw) (MIN_Q_VECTORS + NON_Q_VECTORS(hw)) |
| 203 | |
| 204 | struct fm10k_q_vector { |
| 205 | struct fm10k_intfc *interface; |
| 206 | u32 __iomem *itr; /* pointer to ITR register for this vector */ |
| 207 | u16 v_idx; /* index of q_vector within interface array */ |
| 208 | struct fm10k_ring_container rx, tx; |
| 209 | |
| 210 | struct napi_struct napi; |
Jacob Keller | 504b0fd | 2015-10-29 13:43:40 -0700 | [diff] [blame] | 211 | cpumask_t affinity_mask; |
Alexander Duyck | 18283ca | 2014-09-20 19:48:51 -0400 | [diff] [blame] | 212 | char name[IFNAMSIZ + 9]; |
| 213 | |
Alexander Duyck | 7461fd9 | 2014-09-20 19:53:23 -0400 | [diff] [blame] | 214 | #ifdef CONFIG_DEBUG_FS |
| 215 | struct dentry *dbg_q_vector; |
| 216 | #endif /* CONFIG_DEBUG_FS */ |
Alexander Duyck | 18283ca | 2014-09-20 19:48:51 -0400 | [diff] [blame] | 217 | struct rcu_head rcu; /* to avoid race with update stats on free */ |
Alexander Duyck | e27ef59 | 2014-09-20 19:49:03 -0400 | [diff] [blame] | 218 | |
| 219 | /* for dynamic allocation of rings associated with this q_vector */ |
| 220 | struct fm10k_ring ring[0] ____cacheline_internodealigned_in_smp; |
Alexander Duyck | 18283ca | 2014-09-20 19:48:51 -0400 | [diff] [blame] | 221 | }; |
| 222 | |
Alexander Duyck | 0e7b364 | 2014-09-20 19:48:10 -0400 | [diff] [blame] | 223 | enum fm10k_ring_f_enum { |
| 224 | RING_F_RSS, |
| 225 | RING_F_QOS, |
| 226 | RING_F_ARRAY_SIZE /* must be last in enum set */ |
| 227 | }; |
| 228 | |
| 229 | struct fm10k_ring_feature { |
| 230 | u16 limit; /* upper limit on feature indices */ |
| 231 | u16 indices; /* current value of indices */ |
| 232 | u16 mask; /* Mask used for feature to ring mapping */ |
| 233 | u16 offset; /* offset to start of feature */ |
| 234 | }; |
| 235 | |
Alexander Duyck | 883a9cc | 2014-09-20 19:52:09 -0400 | [diff] [blame] | 236 | struct fm10k_iov_data { |
| 237 | unsigned int num_vfs; |
| 238 | unsigned int next_vf_mbx; |
| 239 | struct rcu_head rcu; |
| 240 | struct fm10k_vf_info vf_info[0]; |
| 241 | }; |
| 242 | |
Alexander Duyck | 0e7b364 | 2014-09-20 19:48:10 -0400 | [diff] [blame] | 243 | #define fm10k_vxlan_port_for_each(vp, intfc) \ |
| 244 | list_for_each_entry(vp, &(intfc)->vxlan_port, list) |
| 245 | struct fm10k_vxlan_port { |
| 246 | struct list_head list; |
| 247 | sa_family_t sa_family; |
| 248 | __be16 port; |
| 249 | }; |
Alexander Duyck | 04a5aef | 2014-09-20 19:46:45 -0400 | [diff] [blame] | 250 | |
Jeff Kirsher | b382bb1 | 2015-04-03 13:27:05 -0700 | [diff] [blame] | 251 | /* one work queue for entire driver */ |
| 252 | extern struct workqueue_struct *fm10k_workqueue; |
| 253 | |
Alexander Duyck | 04a5aef | 2014-09-20 19:46:45 -0400 | [diff] [blame] | 254 | struct fm10k_intfc { |
Alexander Duyck | 0e7b364 | 2014-09-20 19:48:10 -0400 | [diff] [blame] | 255 | unsigned long active_vlans[BITS_TO_LONGS(VLAN_N_VID)]; |
| 256 | struct net_device *netdev; |
Alexander Duyck | 5cd5e2e | 2014-09-20 19:51:15 -0400 | [diff] [blame] | 257 | struct fm10k_l2_accel *l2_accel; /* pointer to L2 acceleration list */ |
Alexander Duyck | 04a5aef | 2014-09-20 19:46:45 -0400 | [diff] [blame] | 258 | struct pci_dev *pdev; |
Alexander Duyck | 0e7b364 | 2014-09-20 19:48:10 -0400 | [diff] [blame] | 259 | unsigned long state; |
Alexander Duyck | 04a5aef | 2014-09-20 19:46:45 -0400 | [diff] [blame] | 260 | |
Alexander Duyck | 0e7b364 | 2014-09-20 19:48:10 -0400 | [diff] [blame] | 261 | u32 flags; |
Bruce Allan | fcdb0a9 | 2015-12-22 13:43:49 -0800 | [diff] [blame] | 262 | #define FM10K_FLAG_RESET_REQUESTED (u32)(BIT(0)) |
| 263 | #define FM10K_FLAG_RSS_FIELD_IPV4_UDP (u32)(BIT(1)) |
| 264 | #define FM10K_FLAG_RSS_FIELD_IPV6_UDP (u32)(BIT(2)) |
| 265 | #define FM10K_FLAG_RX_TS_ENABLED (u32)(BIT(3)) |
| 266 | #define FM10K_FLAG_SWPRI_CONFIG (u32)(BIT(4)) |
| 267 | #define FM10K_FLAG_DEBUG_STATS (u32)(BIT(5)) |
Alexander Duyck | 0e7b364 | 2014-09-20 19:48:10 -0400 | [diff] [blame] | 268 | int xcast_mode; |
| 269 | |
Alexander Duyck | 18283ca | 2014-09-20 19:48:51 -0400 | [diff] [blame] | 270 | /* Tx fast path data */ |
| 271 | int num_tx_queues; |
| 272 | u16 tx_itr; |
| 273 | |
| 274 | /* Rx fast path data */ |
| 275 | int num_rx_queues; |
| 276 | u16 rx_itr; |
| 277 | |
Alexander Duyck | e27ef59 | 2014-09-20 19:49:03 -0400 | [diff] [blame] | 278 | /* TX */ |
| 279 | struct fm10k_ring *tx_ring[MAX_QUEUES] ____cacheline_aligned_in_smp; |
| 280 | |
Alexander Duyck | b7d8514 | 2014-09-20 19:49:25 -0400 | [diff] [blame] | 281 | u64 restart_queue; |
| 282 | u64 tx_busy; |
| 283 | u64 tx_csum_errors; |
| 284 | u64 alloc_failed; |
| 285 | u64 rx_csum_errors; |
Alexander Duyck | b7d8514 | 2014-09-20 19:49:25 -0400 | [diff] [blame] | 286 | |
| 287 | u64 tx_bytes_nic; |
| 288 | u64 tx_packets_nic; |
| 289 | u64 rx_bytes_nic; |
| 290 | u64 rx_packets_nic; |
| 291 | u64 rx_drops_nic; |
Alexander Duyck | 0e7b364 | 2014-09-20 19:48:10 -0400 | [diff] [blame] | 292 | u64 rx_overrun_pf; |
| 293 | u64 rx_overrun_vf; |
Jacob Keller | 80043f3 | 2015-07-01 17:38:36 -0700 | [diff] [blame] | 294 | |
| 295 | /* Debug Statistics */ |
| 296 | u64 hw_sm_mbx_full; |
| 297 | u64 hw_csum_tx_good; |
| 298 | u64 hw_csum_rx_good; |
| 299 | u64 rx_switch_errors; |
| 300 | u64 rx_drops; |
| 301 | u64 rx_pp_errors; |
| 302 | u64 rx_link_errors; |
| 303 | u64 rx_length_errors; |
| 304 | |
Alexander Duyck | b7d8514 | 2014-09-20 19:49:25 -0400 | [diff] [blame] | 305 | u32 tx_timeout_count; |
Alexander Duyck | 0e7b364 | 2014-09-20 19:48:10 -0400 | [diff] [blame] | 306 | |
Alexander Duyck | e27ef59 | 2014-09-20 19:49:03 -0400 | [diff] [blame] | 307 | /* RX */ |
| 308 | struct fm10k_ring *rx_ring[MAX_QUEUES]; |
| 309 | |
Alexander Duyck | 18283ca | 2014-09-20 19:48:51 -0400 | [diff] [blame] | 310 | /* Queueing vectors */ |
| 311 | struct fm10k_q_vector *q_vector[MAX_Q_VECTORS]; |
| 312 | struct msix_entry *msix_entries; |
| 313 | int num_q_vectors; /* current number of q_vectors for device */ |
Alexander Duyck | 0e7b364 | 2014-09-20 19:48:10 -0400 | [diff] [blame] | 314 | struct fm10k_ring_feature ring_feature[RING_F_ARRAY_SIZE]; |
| 315 | |
Alexander Duyck | 883a9cc | 2014-09-20 19:52:09 -0400 | [diff] [blame] | 316 | /* SR-IOV information management structure */ |
| 317 | struct fm10k_iov_data *iov_data; |
| 318 | |
Alexander Duyck | 0e7b364 | 2014-09-20 19:48:10 -0400 | [diff] [blame] | 319 | struct fm10k_hw_stats stats; |
Alexander Duyck | 04a5aef | 2014-09-20 19:46:45 -0400 | [diff] [blame] | 320 | struct fm10k_hw hw; |
| 321 | u32 __iomem *uc_addr; |
Alexander Duyck | a211e01 | 2014-09-20 19:54:07 -0400 | [diff] [blame] | 322 | u32 __iomem *sw_addr; |
Alexander Duyck | 0e7b364 | 2014-09-20 19:48:10 -0400 | [diff] [blame] | 323 | u16 msg_enable; |
Alexander Duyck | 18283ca | 2014-09-20 19:48:51 -0400 | [diff] [blame] | 324 | u16 tx_ring_count; |
| 325 | u16 rx_ring_count; |
Alexander Duyck | b7d8514 | 2014-09-20 19:49:25 -0400 | [diff] [blame] | 326 | struct timer_list service_timer; |
| 327 | struct work_struct service_task; |
| 328 | unsigned long next_stats_update; |
| 329 | unsigned long next_tx_hang_check; |
| 330 | unsigned long last_reset; |
| 331 | unsigned long link_down_event; |
| 332 | bool host_ready; |
Jacob Keller | a7a7783 | 2016-04-01 16:17:33 -0700 | [diff] [blame] | 333 | bool lport_map_failed; |
Alexander Duyck | 0e7b364 | 2014-09-20 19:48:10 -0400 | [diff] [blame] | 334 | |
| 335 | u32 reta[FM10K_RETA_SIZE]; |
| 336 | u32 rssrk[FM10K_RSSRK_SIZE]; |
| 337 | |
| 338 | /* VXLAN port tracking information */ |
| 339 | struct list_head vxlan_port; |
| 340 | |
Alexander Duyck | 7461fd9 | 2014-09-20 19:53:23 -0400 | [diff] [blame] | 341 | #ifdef CONFIG_DEBUG_FS |
| 342 | struct dentry *dbg_intfc; |
Alexander Duyck | 7461fd9 | 2014-09-20 19:53:23 -0400 | [diff] [blame] | 343 | #endif /* CONFIG_DEBUG_FS */ |
Alexander Duyck | a211e01 | 2014-09-20 19:54:07 -0400 | [diff] [blame] | 344 | |
Alexander Duyck | 9f801ab | 2014-09-20 19:53:08 -0400 | [diff] [blame] | 345 | #ifdef CONFIG_DCB |
Alexander Duyck | 0e7b364 | 2014-09-20 19:48:10 -0400 | [diff] [blame] | 346 | u8 pfc_en; |
| 347 | #endif |
| 348 | u8 rx_pause; |
| 349 | |
| 350 | /* GLORT resources in use by PF */ |
| 351 | u16 glort; |
| 352 | u16 glort_count; |
| 353 | |
| 354 | /* VLAN ID for updating multicast/unicast lists */ |
| 355 | u16 vid; |
Alexander Duyck | 04a5aef | 2014-09-20 19:46:45 -0400 | [diff] [blame] | 356 | }; |
Alexander Duyck | b3890e3 | 2014-09-20 19:46:05 -0400 | [diff] [blame] | 357 | |
Alexander Duyck | 0e7b364 | 2014-09-20 19:48:10 -0400 | [diff] [blame] | 358 | enum fm10k_state_t { |
| 359 | __FM10K_RESETTING, |
| 360 | __FM10K_DOWN, |
Alexander Duyck | b7d8514 | 2014-09-20 19:49:25 -0400 | [diff] [blame] | 361 | __FM10K_SERVICE_SCHED, |
| 362 | __FM10K_SERVICE_DISABLE, |
Alexander Duyck | 0e7b364 | 2014-09-20 19:48:10 -0400 | [diff] [blame] | 363 | __FM10K_MBX_LOCK, |
| 364 | __FM10K_LINK_DOWN, |
| 365 | }; |
| 366 | |
| 367 | static inline void fm10k_mbx_lock(struct fm10k_intfc *interface) |
| 368 | { |
| 369 | /* busy loop if we cannot obtain the lock as some calls |
| 370 | * such as ndo_set_rx_mode may be made in atomic context |
| 371 | */ |
| 372 | while (test_and_set_bit(__FM10K_MBX_LOCK, &interface->state)) |
| 373 | udelay(20); |
| 374 | } |
| 375 | |
| 376 | static inline void fm10k_mbx_unlock(struct fm10k_intfc *interface) |
| 377 | { |
| 378 | /* flush memory to make sure state is correct */ |
| 379 | smp_mb__before_atomic(); |
| 380 | clear_bit(__FM10K_MBX_LOCK, &interface->state); |
| 381 | } |
| 382 | |
| 383 | static inline int fm10k_mbx_trylock(struct fm10k_intfc *interface) |
| 384 | { |
| 385 | return !test_and_set_bit(__FM10K_MBX_LOCK, &interface->state); |
| 386 | } |
| 387 | |
Alexander Duyck | e27ef59 | 2014-09-20 19:49:03 -0400 | [diff] [blame] | 388 | /* fm10k_test_staterr - test bits in Rx descriptor status and error fields */ |
| 389 | static inline __le32 fm10k_test_staterr(union fm10k_rx_desc *rx_desc, |
| 390 | const u32 stat_err_bits) |
| 391 | { |
| 392 | return rx_desc->d.staterr & cpu_to_le32(stat_err_bits); |
| 393 | } |
| 394 | |
| 395 | /* fm10k_desc_unused - calculate if we have unused descriptors */ |
| 396 | static inline u16 fm10k_desc_unused(struct fm10k_ring *ring) |
| 397 | { |
| 398 | s16 unused = ring->next_to_clean - ring->next_to_use - 1; |
| 399 | |
| 400 | return likely(unused < 0) ? unused + ring->count : unused; |
| 401 | } |
| 402 | |
| 403 | #define FM10K_TX_DESC(R, i) \ |
| 404 | (&(((struct fm10k_tx_desc *)((R)->desc))[i])) |
| 405 | #define FM10K_RX_DESC(R, i) \ |
| 406 | (&(((union fm10k_rx_desc *)((R)->desc))[i])) |
| 407 | |
| 408 | #define FM10K_MAX_TXD_PWR 14 |
Jacob Keller | 124579d | 2016-04-14 13:17:27 -0700 | [diff] [blame^] | 409 | #define FM10K_MAX_DATA_PER_TXD (1u << FM10K_MAX_TXD_PWR) |
Alexander Duyck | e27ef59 | 2014-09-20 19:49:03 -0400 | [diff] [blame] | 410 | |
| 411 | /* Tx Descriptors needed, worst case */ |
| 412 | #define TXD_USE_COUNT(S) DIV_ROUND_UP((S), FM10K_MAX_DATA_PER_TXD) |
| 413 | #define DESC_NEEDED (MAX_SKB_FRAGS + 4) |
| 414 | |
| 415 | enum fm10k_tx_flags { |
| 416 | /* Tx offload flags */ |
| 417 | FM10K_TX_FLAGS_CSUM = 0x01, |
| 418 | }; |
| 419 | |
| 420 | /* This structure is stored as little endian values as that is the native |
| 421 | * format of the Rx descriptor. The ordering of these fields is reversed |
| 422 | * from the actual ftag header to allow for a single bswap to take care |
| 423 | * of placing all of the values in network order |
| 424 | */ |
| 425 | union fm10k_ftag_info { |
| 426 | __le64 ftag; |
| 427 | struct { |
| 428 | /* dglort and sglort combined into a single 32bit desc read */ |
| 429 | __le32 glort; |
Jacob Keller | aa502b4 | 2015-11-02 12:10:22 -0800 | [diff] [blame] | 430 | /* upper 16 bits of VLAN are reserved 0 for swpri_type_user */ |
Alexander Duyck | e27ef59 | 2014-09-20 19:49:03 -0400 | [diff] [blame] | 431 | __le32 vlan; |
| 432 | } d; |
| 433 | struct { |
| 434 | __le16 dglort; |
| 435 | __le16 sglort; |
| 436 | __le16 vlan; |
| 437 | __le16 swpri_type_user; |
| 438 | } w; |
| 439 | }; |
| 440 | |
| 441 | struct fm10k_cb { |
Alexander Duyck | a211e01 | 2014-09-20 19:54:07 -0400 | [diff] [blame] | 442 | union { |
| 443 | __le64 tstamp; |
| 444 | unsigned long ts_tx_timeout; |
| 445 | }; |
Alexander Duyck | e27ef59 | 2014-09-20 19:49:03 -0400 | [diff] [blame] | 446 | union fm10k_ftag_info fi; |
| 447 | }; |
| 448 | |
| 449 | #define FM10K_CB(skb) ((struct fm10k_cb *)(skb)->cb) |
| 450 | |
Alexander Duyck | b3890e3 | 2014-09-20 19:46:05 -0400 | [diff] [blame] | 451 | /* main */ |
| 452 | extern char fm10k_driver_name[]; |
| 453 | extern const char fm10k_driver_version[]; |
Alexander Duyck | 18283ca | 2014-09-20 19:48:51 -0400 | [diff] [blame] | 454 | int fm10k_init_queueing_scheme(struct fm10k_intfc *interface); |
| 455 | void fm10k_clear_queueing_scheme(struct fm10k_intfc *interface); |
Matthew Vick | 5bf33dc | 2015-01-29 07:17:27 +0000 | [diff] [blame] | 456 | __be16 fm10k_tx_encap_offload(struct sk_buff *skb); |
Alexander Duyck | b101c96 | 2014-09-20 19:50:03 -0400 | [diff] [blame] | 457 | netdev_tx_t fm10k_xmit_frame_ring(struct sk_buff *skb, |
| 458 | struct fm10k_ring *tx_ring); |
| 459 | void fm10k_tx_timeout_reset(struct fm10k_intfc *interface); |
| 460 | bool fm10k_check_tx_hang(struct fm10k_ring *tx_ring); |
| 461 | void fm10k_alloc_rx_buffers(struct fm10k_ring *rx_ring, u16 cleaned_count); |
Alexander Duyck | b3890e3 | 2014-09-20 19:46:05 -0400 | [diff] [blame] | 462 | |
| 463 | /* PCI */ |
Alexander Duyck | 18283ca | 2014-09-20 19:48:51 -0400 | [diff] [blame] | 464 | void fm10k_mbx_free_irq(struct fm10k_intfc *); |
| 465 | int fm10k_mbx_request_irq(struct fm10k_intfc *); |
| 466 | void fm10k_qv_free_irq(struct fm10k_intfc *interface); |
| 467 | int fm10k_qv_request_irq(struct fm10k_intfc *interface); |
Alexander Duyck | b3890e3 | 2014-09-20 19:46:05 -0400 | [diff] [blame] | 468 | int fm10k_register_pci_driver(void); |
| 469 | void fm10k_unregister_pci_driver(void); |
Alexander Duyck | 504c5ea | 2014-09-20 19:48:29 -0400 | [diff] [blame] | 470 | void fm10k_up(struct fm10k_intfc *interface); |
| 471 | void fm10k_down(struct fm10k_intfc *interface); |
Alexander Duyck | b7d8514 | 2014-09-20 19:49:25 -0400 | [diff] [blame] | 472 | void fm10k_update_stats(struct fm10k_intfc *interface); |
| 473 | void fm10k_service_event_schedule(struct fm10k_intfc *interface); |
| 474 | void fm10k_update_rx_drop_en(struct fm10k_intfc *interface); |
Jeff Kirsher | 8b4a98c | 2015-04-10 19:14:31 -0700 | [diff] [blame] | 475 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 476 | void fm10k_netpoll(struct net_device *netdev); |
| 477 | #endif |
Alexander Duyck | 0e7b364 | 2014-09-20 19:48:10 -0400 | [diff] [blame] | 478 | |
| 479 | /* Netdev */ |
Jacob Keller | e024490 | 2015-10-16 10:56:56 -0700 | [diff] [blame] | 480 | struct net_device *fm10k_alloc_netdev(const struct fm10k_info *info); |
Alexander Duyck | 3abaae4 | 2014-09-20 19:49:43 -0400 | [diff] [blame] | 481 | int fm10k_setup_rx_resources(struct fm10k_ring *); |
| 482 | int fm10k_setup_tx_resources(struct fm10k_ring *); |
| 483 | void fm10k_free_rx_resources(struct fm10k_ring *); |
| 484 | void fm10k_free_tx_resources(struct fm10k_ring *); |
| 485 | void fm10k_clean_all_rx_rings(struct fm10k_intfc *); |
| 486 | void fm10k_clean_all_tx_rings(struct fm10k_intfc *); |
| 487 | void fm10k_unmap_and_free_tx_resource(struct fm10k_ring *, |
| 488 | struct fm10k_tx_buffer *); |
Alexander Duyck | 8f5e20d | 2014-09-20 19:48:20 -0400 | [diff] [blame] | 489 | void fm10k_restore_rx_state(struct fm10k_intfc *); |
| 490 | void fm10k_reset_rx_state(struct fm10k_intfc *); |
Alexander Duyck | aa3ac82 | 2014-09-20 19:50:42 -0400 | [diff] [blame] | 491 | int fm10k_setup_tc(struct net_device *dev, u8 tc); |
Alexander Duyck | 504c5ea | 2014-09-20 19:48:29 -0400 | [diff] [blame] | 492 | int fm10k_open(struct net_device *netdev); |
| 493 | int fm10k_close(struct net_device *netdev); |
Alexander Duyck | 82dd0f7 | 2014-09-20 19:50:15 -0400 | [diff] [blame] | 494 | |
| 495 | /* Ethtool */ |
| 496 | void fm10k_set_ethtool_ops(struct net_device *dev); |
Jacob Keller | 0ea7fae | 2016-02-16 16:19:24 -0800 | [diff] [blame] | 497 | u32 fm10k_get_reta_size(struct net_device *netdev); |
| 498 | void fm10k_write_reta(struct fm10k_intfc *interface, const u32 *indir); |
Alexander Duyck | 883a9cc | 2014-09-20 19:52:09 -0400 | [diff] [blame] | 499 | |
| 500 | /* IOV */ |
| 501 | s32 fm10k_iov_event(struct fm10k_intfc *interface); |
| 502 | s32 fm10k_iov_mbx(struct fm10k_intfc *interface); |
| 503 | void fm10k_iov_suspend(struct pci_dev *pdev); |
| 504 | int fm10k_iov_resume(struct pci_dev *pdev); |
| 505 | void fm10k_iov_disable(struct pci_dev *pdev); |
| 506 | int fm10k_iov_configure(struct pci_dev *pdev, int num_vfs); |
| 507 | s32 fm10k_iov_update_pvid(struct fm10k_intfc *interface, u16 glort, u16 pvid); |
| 508 | int fm10k_ndo_set_vf_mac(struct net_device *netdev, int vf_idx, u8 *mac); |
| 509 | int fm10k_ndo_set_vf_vlan(struct net_device *netdev, |
| 510 | int vf_idx, u16 vid, u8 qos); |
| 511 | int fm10k_ndo_set_vf_bw(struct net_device *netdev, int vf_idx, int rate, |
| 512 | int unused); |
| 513 | int fm10k_ndo_get_vf_config(struct net_device *netdev, |
| 514 | int vf_idx, struct ifla_vf_info *ivi); |
Alexander Duyck | 9f801ab | 2014-09-20 19:53:08 -0400 | [diff] [blame] | 515 | |
Alexander Duyck | 7461fd9 | 2014-09-20 19:53:23 -0400 | [diff] [blame] | 516 | /* DebugFS */ |
| 517 | #ifdef CONFIG_DEBUG_FS |
| 518 | void fm10k_dbg_q_vector_init(struct fm10k_q_vector *q_vector); |
| 519 | void fm10k_dbg_q_vector_exit(struct fm10k_q_vector *q_vector); |
| 520 | void fm10k_dbg_intfc_init(struct fm10k_intfc *interface); |
| 521 | void fm10k_dbg_intfc_exit(struct fm10k_intfc *interface); |
| 522 | void fm10k_dbg_init(void); |
| 523 | void fm10k_dbg_exit(void); |
| 524 | #else |
| 525 | static inline void fm10k_dbg_q_vector_init(struct fm10k_q_vector *q_vector) {} |
| 526 | static inline void fm10k_dbg_q_vector_exit(struct fm10k_q_vector *q_vector) {} |
| 527 | static inline void fm10k_dbg_intfc_init(struct fm10k_intfc *interface) {} |
| 528 | static inline void fm10k_dbg_intfc_exit(struct fm10k_intfc *interface) {} |
| 529 | static inline void fm10k_dbg_init(void) {} |
| 530 | static inline void fm10k_dbg_exit(void) {} |
| 531 | #endif /* CONFIG_DEBUG_FS */ |
| 532 | |
Alexander Duyck | 9f801ab | 2014-09-20 19:53:08 -0400 | [diff] [blame] | 533 | /* DCB */ |
Jacob Keller | 5682366 | 2015-10-27 12:51:09 -0700 | [diff] [blame] | 534 | #ifdef CONFIG_DCB |
Alexander Duyck | 9f801ab | 2014-09-20 19:53:08 -0400 | [diff] [blame] | 535 | void fm10k_dcbnl_set_ops(struct net_device *dev); |
Jacob Keller | 5682366 | 2015-10-27 12:51:09 -0700 | [diff] [blame] | 536 | #else |
| 537 | static inline void fm10k_dcbnl_set_ops(struct net_device *dev) {} |
| 538 | #endif |
Alexander Duyck | b3890e3 | 2014-09-20 19:46:05 -0400 | [diff] [blame] | 539 | #endif /* _FM10K_H_ */ |