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