Alexander Duyck | b3890e3 | 2014-09-20 19:46:05 -0400 | [diff] [blame] | 1 | /* Intel Ethernet Switch Host Interface Driver |
| 2 | * Copyright(c) 2013 - 2014 Intel Corporation. |
| 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> |
| 29 | |
Alexander Duyck | 0e7b364 | 2014-09-20 19:48:10 -0400 | [diff] [blame] | 30 | #include "fm10k_pf.h" |
| 31 | |
| 32 | #define FM10K_MAX_JUMBO_FRAME_SIZE 15358 /* Maximum supported size 15K */ |
| 33 | |
Alexander Duyck | 18283ca | 2014-09-20 19:48:51 -0400 | [diff] [blame^] | 34 | struct fm10k_ring_container { |
| 35 | unsigned int total_bytes; /* total bytes processed this int */ |
| 36 | unsigned int total_packets; /* total packets processed this int */ |
| 37 | u16 work_limit; /* total work allowed per interrupt */ |
| 38 | u16 itr; /* interrupt throttle rate value */ |
| 39 | u8 count; /* total number of rings in vector */ |
| 40 | }; |
| 41 | |
| 42 | #define FM10K_ITR_MAX 0x0FFF /* maximum value for ITR */ |
| 43 | #define FM10K_ITR_10K 100 /* 100us */ |
| 44 | #define FM10K_ITR_20K 50 /* 50us */ |
| 45 | #define FM10K_ITR_ADAPTIVE 0x8000 /* adaptive interrupt moderation flag */ |
| 46 | |
| 47 | #define FM10K_ITR_ENABLE (FM10K_ITR_AUTOMASK | FM10K_ITR_MASK_CLEAR) |
| 48 | |
| 49 | #define MAX_Q_VECTORS 256 |
| 50 | #define MIN_Q_VECTORS 1 |
| 51 | enum fm10k_non_q_vectors { |
| 52 | FM10K_MBX_VECTOR, |
| 53 | NON_Q_VECTORS_PF |
| 54 | }; |
| 55 | |
| 56 | #define NON_Q_VECTORS(hw) (((hw)->mac.type == fm10k_mac_pf) ? \ |
| 57 | NON_Q_VECTORS_PF : \ |
| 58 | 0) |
| 59 | #define MIN_MSIX_COUNT(hw) (MIN_Q_VECTORS + NON_Q_VECTORS(hw)) |
| 60 | |
| 61 | struct fm10k_q_vector { |
| 62 | struct fm10k_intfc *interface; |
| 63 | u32 __iomem *itr; /* pointer to ITR register for this vector */ |
| 64 | u16 v_idx; /* index of q_vector within interface array */ |
| 65 | struct fm10k_ring_container rx, tx; |
| 66 | |
| 67 | struct napi_struct napi; |
| 68 | char name[IFNAMSIZ + 9]; |
| 69 | |
| 70 | struct rcu_head rcu; /* to avoid race with update stats on free */ |
| 71 | }; |
| 72 | |
Alexander Duyck | 0e7b364 | 2014-09-20 19:48:10 -0400 | [diff] [blame] | 73 | enum fm10k_ring_f_enum { |
| 74 | RING_F_RSS, |
| 75 | RING_F_QOS, |
| 76 | RING_F_ARRAY_SIZE /* must be last in enum set */ |
| 77 | }; |
| 78 | |
| 79 | struct fm10k_ring_feature { |
| 80 | u16 limit; /* upper limit on feature indices */ |
| 81 | u16 indices; /* current value of indices */ |
| 82 | u16 mask; /* Mask used for feature to ring mapping */ |
| 83 | u16 offset; /* offset to start of feature */ |
| 84 | }; |
| 85 | |
| 86 | #define fm10k_vxlan_port_for_each(vp, intfc) \ |
| 87 | list_for_each_entry(vp, &(intfc)->vxlan_port, list) |
| 88 | struct fm10k_vxlan_port { |
| 89 | struct list_head list; |
| 90 | sa_family_t sa_family; |
| 91 | __be16 port; |
| 92 | }; |
Alexander Duyck | 04a5aef | 2014-09-20 19:46:45 -0400 | [diff] [blame] | 93 | |
| 94 | struct fm10k_intfc { |
Alexander Duyck | 0e7b364 | 2014-09-20 19:48:10 -0400 | [diff] [blame] | 95 | unsigned long active_vlans[BITS_TO_LONGS(VLAN_N_VID)]; |
| 96 | struct net_device *netdev; |
Alexander Duyck | 04a5aef | 2014-09-20 19:46:45 -0400 | [diff] [blame] | 97 | struct pci_dev *pdev; |
Alexander Duyck | 0e7b364 | 2014-09-20 19:48:10 -0400 | [diff] [blame] | 98 | unsigned long state; |
Alexander Duyck | 04a5aef | 2014-09-20 19:46:45 -0400 | [diff] [blame] | 99 | |
Alexander Duyck | 0e7b364 | 2014-09-20 19:48:10 -0400 | [diff] [blame] | 100 | u32 flags; |
| 101 | #define FM10K_FLAG_RESET_REQUESTED (u32)(1 << 0) |
| 102 | #define FM10K_FLAG_RSS_FIELD_IPV4_UDP (u32)(1 << 1) |
| 103 | #define FM10K_FLAG_RSS_FIELD_IPV6_UDP (u32)(1 << 2) |
| 104 | #define FM10K_FLAG_RX_TS_ENABLED (u32)(1 << 3) |
| 105 | #define FM10K_FLAG_SWPRI_CONFIG (u32)(1 << 4) |
| 106 | int xcast_mode; |
| 107 | |
Alexander Duyck | 18283ca | 2014-09-20 19:48:51 -0400 | [diff] [blame^] | 108 | /* Tx fast path data */ |
| 109 | int num_tx_queues; |
| 110 | u16 tx_itr; |
| 111 | |
| 112 | /* Rx fast path data */ |
| 113 | int num_rx_queues; |
| 114 | u16 rx_itr; |
| 115 | |
Alexander Duyck | 0e7b364 | 2014-09-20 19:48:10 -0400 | [diff] [blame] | 116 | u64 rx_overrun_pf; |
| 117 | u64 rx_overrun_vf; |
| 118 | |
Alexander Duyck | 18283ca | 2014-09-20 19:48:51 -0400 | [diff] [blame^] | 119 | /* Queueing vectors */ |
| 120 | struct fm10k_q_vector *q_vector[MAX_Q_VECTORS]; |
| 121 | struct msix_entry *msix_entries; |
| 122 | int num_q_vectors; /* current number of q_vectors for device */ |
Alexander Duyck | 0e7b364 | 2014-09-20 19:48:10 -0400 | [diff] [blame] | 123 | struct fm10k_ring_feature ring_feature[RING_F_ARRAY_SIZE]; |
| 124 | |
| 125 | struct fm10k_hw_stats stats; |
Alexander Duyck | 04a5aef | 2014-09-20 19:46:45 -0400 | [diff] [blame] | 126 | struct fm10k_hw hw; |
| 127 | u32 __iomem *uc_addr; |
Alexander Duyck | 0e7b364 | 2014-09-20 19:48:10 -0400 | [diff] [blame] | 128 | u16 msg_enable; |
Alexander Duyck | 18283ca | 2014-09-20 19:48:51 -0400 | [diff] [blame^] | 129 | u16 tx_ring_count; |
| 130 | u16 rx_ring_count; |
Alexander Duyck | 0e7b364 | 2014-09-20 19:48:10 -0400 | [diff] [blame] | 131 | |
| 132 | u32 reta[FM10K_RETA_SIZE]; |
| 133 | u32 rssrk[FM10K_RSSRK_SIZE]; |
| 134 | |
| 135 | /* VXLAN port tracking information */ |
| 136 | struct list_head vxlan_port; |
| 137 | |
| 138 | #if defined(HAVE_DCBNL_IEEE) && defined(CONFIG_DCB) |
| 139 | u8 pfc_en; |
| 140 | #endif |
| 141 | u8 rx_pause; |
| 142 | |
| 143 | /* GLORT resources in use by PF */ |
| 144 | u16 glort; |
| 145 | u16 glort_count; |
| 146 | |
| 147 | /* VLAN ID for updating multicast/unicast lists */ |
| 148 | u16 vid; |
Alexander Duyck | 04a5aef | 2014-09-20 19:46:45 -0400 | [diff] [blame] | 149 | }; |
Alexander Duyck | b3890e3 | 2014-09-20 19:46:05 -0400 | [diff] [blame] | 150 | |
Alexander Duyck | 0e7b364 | 2014-09-20 19:48:10 -0400 | [diff] [blame] | 151 | enum fm10k_state_t { |
| 152 | __FM10K_RESETTING, |
| 153 | __FM10K_DOWN, |
| 154 | __FM10K_MBX_LOCK, |
| 155 | __FM10K_LINK_DOWN, |
| 156 | }; |
| 157 | |
| 158 | static inline void fm10k_mbx_lock(struct fm10k_intfc *interface) |
| 159 | { |
| 160 | /* busy loop if we cannot obtain the lock as some calls |
| 161 | * such as ndo_set_rx_mode may be made in atomic context |
| 162 | */ |
| 163 | while (test_and_set_bit(__FM10K_MBX_LOCK, &interface->state)) |
| 164 | udelay(20); |
| 165 | } |
| 166 | |
| 167 | static inline void fm10k_mbx_unlock(struct fm10k_intfc *interface) |
| 168 | { |
| 169 | /* flush memory to make sure state is correct */ |
| 170 | smp_mb__before_atomic(); |
| 171 | clear_bit(__FM10K_MBX_LOCK, &interface->state); |
| 172 | } |
| 173 | |
| 174 | static inline int fm10k_mbx_trylock(struct fm10k_intfc *interface) |
| 175 | { |
| 176 | return !test_and_set_bit(__FM10K_MBX_LOCK, &interface->state); |
| 177 | } |
| 178 | |
Alexander Duyck | b3890e3 | 2014-09-20 19:46:05 -0400 | [diff] [blame] | 179 | /* main */ |
| 180 | extern char fm10k_driver_name[]; |
| 181 | extern const char fm10k_driver_version[]; |
Alexander Duyck | 18283ca | 2014-09-20 19:48:51 -0400 | [diff] [blame^] | 182 | int fm10k_init_queueing_scheme(struct fm10k_intfc *interface); |
| 183 | void fm10k_clear_queueing_scheme(struct fm10k_intfc *interface); |
Alexander Duyck | b3890e3 | 2014-09-20 19:46:05 -0400 | [diff] [blame] | 184 | |
| 185 | /* PCI */ |
Alexander Duyck | 18283ca | 2014-09-20 19:48:51 -0400 | [diff] [blame^] | 186 | void fm10k_mbx_free_irq(struct fm10k_intfc *); |
| 187 | int fm10k_mbx_request_irq(struct fm10k_intfc *); |
| 188 | void fm10k_qv_free_irq(struct fm10k_intfc *interface); |
| 189 | int fm10k_qv_request_irq(struct fm10k_intfc *interface); |
Alexander Duyck | b3890e3 | 2014-09-20 19:46:05 -0400 | [diff] [blame] | 190 | int fm10k_register_pci_driver(void); |
| 191 | void fm10k_unregister_pci_driver(void); |
Alexander Duyck | 504c5ea | 2014-09-20 19:48:29 -0400 | [diff] [blame] | 192 | void fm10k_up(struct fm10k_intfc *interface); |
| 193 | void fm10k_down(struct fm10k_intfc *interface); |
Alexander Duyck | 0e7b364 | 2014-09-20 19:48:10 -0400 | [diff] [blame] | 194 | |
| 195 | /* Netdev */ |
| 196 | struct net_device *fm10k_alloc_netdev(void); |
Alexander Duyck | 8f5e20d | 2014-09-20 19:48:20 -0400 | [diff] [blame] | 197 | void fm10k_restore_rx_state(struct fm10k_intfc *); |
| 198 | void fm10k_reset_rx_state(struct fm10k_intfc *); |
Alexander Duyck | 504c5ea | 2014-09-20 19:48:29 -0400 | [diff] [blame] | 199 | int fm10k_open(struct net_device *netdev); |
| 200 | int fm10k_close(struct net_device *netdev); |
Alexander Duyck | b3890e3 | 2014-09-20 19:46:05 -0400 | [diff] [blame] | 201 | #endif /* _FM10K_H_ */ |