diff options
author | Jonathan Herman <hermanjl@cs.unc.edu> | 2013-01-22 10:38:37 -0500 |
---|---|---|
committer | Jonathan Herman <hermanjl@cs.unc.edu> | 2013-01-22 10:38:37 -0500 |
commit | fcc9d2e5a6c89d22b8b773a64fb4ad21ac318446 (patch) | |
tree | a57612d1888735a2ec7972891b68c1ac5ec8faea /drivers/net/ixgbe | |
parent | 8dea78da5cee153b8af9c07a2745f6c55057fe12 (diff) |
Diffstat (limited to 'drivers/net/ixgbe')
25 files changed, 28512 insertions, 0 deletions
diff --git a/drivers/net/ixgbe/Makefile b/drivers/net/ixgbe/Makefile new file mode 100644 index 00000000000..7d7387fbdec --- /dev/null +++ b/drivers/net/ixgbe/Makefile | |||
@@ -0,0 +1,42 @@ | |||
1 | ################################################################################ | ||
2 | # | ||
3 | # Intel 10 Gigabit PCI Express Linux driver | ||
4 | # Copyright(c) 1999 - 2010 Intel Corporation. | ||
5 | # | ||
6 | # This program is free software; you can redistribute it and/or modify it | ||
7 | # under the terms and conditions of the GNU General Public License, | ||
8 | # version 2, as published by the Free Software Foundation. | ||
9 | # | ||
10 | # This program is distributed in the hope it will be useful, but WITHOUT | ||
11 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
12 | # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
13 | # more details. | ||
14 | # | ||
15 | # You should have received a copy of the GNU General Public License along with | ||
16 | # this program; if not, write to the Free Software Foundation, Inc., | ||
17 | # 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. | ||
18 | # | ||
19 | # The full GNU General Public License is included in this distribution in | ||
20 | # the file called "COPYING". | ||
21 | # | ||
22 | # Contact Information: | ||
23 | # Linux NICS <linux.nics@intel.com> | ||
24 | # e1000-devel Mailing List <e1000-devel@lists.sourceforge.net> | ||
25 | # Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 | ||
26 | # | ||
27 | ################################################################################ | ||
28 | |||
29 | # | ||
30 | # Makefile for the Intel(R) 10GbE PCI Express ethernet driver | ||
31 | # | ||
32 | |||
33 | obj-$(CONFIG_IXGBE) += ixgbe.o | ||
34 | |||
35 | ixgbe-objs := ixgbe_main.o ixgbe_common.o ixgbe_ethtool.o \ | ||
36 | ixgbe_82599.o ixgbe_82598.o ixgbe_phy.o ixgbe_sriov.o \ | ||
37 | ixgbe_mbx.o ixgbe_x540.o | ||
38 | |||
39 | ixgbe-$(CONFIG_IXGBE_DCB) += ixgbe_dcb.o ixgbe_dcb_82598.o \ | ||
40 | ixgbe_dcb_82599.o ixgbe_dcb_nl.o | ||
41 | |||
42 | ixgbe-$(CONFIG_FCOE:m=y) += ixgbe_fcoe.o | ||
diff --git a/drivers/net/ixgbe/ixgbe.h b/drivers/net/ixgbe/ixgbe.h new file mode 100644 index 00000000000..e04a8e49e6d --- /dev/null +++ b/drivers/net/ixgbe/ixgbe.h | |||
@@ -0,0 +1,617 @@ | |||
1 | /******************************************************************************* | ||
2 | |||
3 | Intel 10 Gigabit PCI Express Linux driver | ||
4 | Copyright(c) 1999 - 2011 Intel Corporation. | ||
5 | |||
6 | This program is free software; you can redistribute it and/or modify it | ||
7 | under the terms and conditions of the GNU General Public License, | ||
8 | version 2, as published by the Free Software Foundation. | ||
9 | |||
10 | This program is distributed in the hope it will be useful, but WITHOUT | ||
11 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
12 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
13 | more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License along with | ||
16 | this program; if not, write to the Free Software Foundation, Inc., | ||
17 | 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. | ||
18 | |||
19 | The full GNU General Public License is included in this distribution in | ||
20 | the file called "COPYING". | ||
21 | |||
22 | Contact Information: | ||
23 | e1000-devel Mailing List <e1000-devel@lists.sourceforge.net> | ||
24 | Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 | ||
25 | |||
26 | *******************************************************************************/ | ||
27 | |||
28 | #ifndef _IXGBE_H_ | ||
29 | #define _IXGBE_H_ | ||
30 | |||
31 | #include <linux/bitops.h> | ||
32 | #include <linux/types.h> | ||
33 | #include <linux/pci.h> | ||
34 | #include <linux/netdevice.h> | ||
35 | #include <linux/cpumask.h> | ||
36 | #include <linux/aer.h> | ||
37 | #include <linux/if_vlan.h> | ||
38 | |||
39 | #include "ixgbe_type.h" | ||
40 | #include "ixgbe_common.h" | ||
41 | #include "ixgbe_dcb.h" | ||
42 | #if defined(CONFIG_FCOE) || defined(CONFIG_FCOE_MODULE) | ||
43 | #define IXGBE_FCOE | ||
44 | #include "ixgbe_fcoe.h" | ||
45 | #endif /* CONFIG_FCOE or CONFIG_FCOE_MODULE */ | ||
46 | #ifdef CONFIG_IXGBE_DCA | ||
47 | #include <linux/dca.h> | ||
48 | #endif | ||
49 | |||
50 | /* common prefix used by pr_<> macros */ | ||
51 | #undef pr_fmt | ||
52 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt | ||
53 | |||
54 | /* TX/RX descriptor defines */ | ||
55 | #define IXGBE_DEFAULT_TXD 512 | ||
56 | #define IXGBE_MAX_TXD 4096 | ||
57 | #define IXGBE_MIN_TXD 64 | ||
58 | |||
59 | #define IXGBE_DEFAULT_RXD 512 | ||
60 | #define IXGBE_MAX_RXD 4096 | ||
61 | #define IXGBE_MIN_RXD 64 | ||
62 | |||
63 | /* flow control */ | ||
64 | #define IXGBE_MIN_FCRTL 0x40 | ||
65 | #define IXGBE_MAX_FCRTL 0x7FF80 | ||
66 | #define IXGBE_MIN_FCRTH 0x600 | ||
67 | #define IXGBE_MAX_FCRTH 0x7FFF0 | ||
68 | #define IXGBE_DEFAULT_FCPAUSE 0xFFFF | ||
69 | #define IXGBE_MIN_FCPAUSE 0 | ||
70 | #define IXGBE_MAX_FCPAUSE 0xFFFF | ||
71 | |||
72 | /* Supported Rx Buffer Sizes */ | ||
73 | #define IXGBE_RXBUFFER_512 512 /* Used for packet split */ | ||
74 | #define IXGBE_RXBUFFER_2048 2048 | ||
75 | #define IXGBE_RXBUFFER_4096 4096 | ||
76 | #define IXGBE_RXBUFFER_8192 8192 | ||
77 | #define IXGBE_MAX_RXBUFFER 16384 /* largest size for a single descriptor */ | ||
78 | |||
79 | /* | ||
80 | * NOTE: netdev_alloc_skb reserves up to 64 bytes, NET_IP_ALIGN mans we | ||
81 | * reserve 2 more, and skb_shared_info adds an additional 384 bytes more, | ||
82 | * this adds up to 512 bytes of extra data meaning the smallest allocation | ||
83 | * we could have is 1K. | ||
84 | * i.e. RXBUFFER_512 --> size-1024 slab | ||
85 | */ | ||
86 | #define IXGBE_RX_HDR_SIZE IXGBE_RXBUFFER_512 | ||
87 | |||
88 | #define MAXIMUM_ETHERNET_VLAN_SIZE (ETH_FRAME_LEN + ETH_FCS_LEN + VLAN_HLEN) | ||
89 | |||
90 | /* How many Rx Buffers do we bundle into one write to the hardware ? */ | ||
91 | #define IXGBE_RX_BUFFER_WRITE 16 /* Must be power of 2 */ | ||
92 | |||
93 | #define IXGBE_TX_FLAGS_CSUM (u32)(1) | ||
94 | #define IXGBE_TX_FLAGS_VLAN (u32)(1 << 1) | ||
95 | #define IXGBE_TX_FLAGS_TSO (u32)(1 << 2) | ||
96 | #define IXGBE_TX_FLAGS_IPV4 (u32)(1 << 3) | ||
97 | #define IXGBE_TX_FLAGS_FCOE (u32)(1 << 4) | ||
98 | #define IXGBE_TX_FLAGS_FSO (u32)(1 << 5) | ||
99 | #define IXGBE_TX_FLAGS_VLAN_MASK 0xffff0000 | ||
100 | #define IXGBE_TX_FLAGS_VLAN_PRIO_MASK 0x0000e000 | ||
101 | #define IXGBE_TX_FLAGS_VLAN_SHIFT 16 | ||
102 | |||
103 | #define IXGBE_MAX_RSC_INT_RATE 162760 | ||
104 | |||
105 | #define IXGBE_MAX_VF_MC_ENTRIES 30 | ||
106 | #define IXGBE_MAX_VF_FUNCTIONS 64 | ||
107 | #define IXGBE_MAX_VFTA_ENTRIES 128 | ||
108 | #define MAX_EMULATION_MAC_ADDRS 16 | ||
109 | #define IXGBE_MAX_PF_MACVLANS 15 | ||
110 | #define VMDQ_P(p) ((p) + adapter->num_vfs) | ||
111 | |||
112 | struct vf_data_storage { | ||
113 | unsigned char vf_mac_addresses[ETH_ALEN]; | ||
114 | u16 vf_mc_hashes[IXGBE_MAX_VF_MC_ENTRIES]; | ||
115 | u16 num_vf_mc_hashes; | ||
116 | u16 default_vf_vlan_id; | ||
117 | u16 vlans_enabled; | ||
118 | bool clear_to_send; | ||
119 | bool pf_set_mac; | ||
120 | u16 pf_vlan; /* When set, guest VLAN config not allowed. */ | ||
121 | u16 pf_qos; | ||
122 | u16 tx_rate; | ||
123 | }; | ||
124 | |||
125 | struct vf_macvlans { | ||
126 | struct list_head l; | ||
127 | int vf; | ||
128 | int rar_entry; | ||
129 | bool free; | ||
130 | bool is_macvlan; | ||
131 | u8 vf_macvlan[ETH_ALEN]; | ||
132 | }; | ||
133 | |||
134 | #define IXGBE_MAX_TXD_PWR 14 | ||
135 | #define IXGBE_MAX_DATA_PER_TXD (1 << IXGBE_MAX_TXD_PWR) | ||
136 | |||
137 | /* Tx Descriptors needed, worst case */ | ||
138 | #define TXD_USE_COUNT(S) DIV_ROUND_UP((S), IXGBE_MAX_DATA_PER_TXD) | ||
139 | #define DESC_NEEDED ((MAX_SKB_FRAGS * TXD_USE_COUNT(PAGE_SIZE)) + 4) | ||
140 | |||
141 | /* wrapper around a pointer to a socket buffer, | ||
142 | * so a DMA handle can be stored along with the buffer */ | ||
143 | struct ixgbe_tx_buffer { | ||
144 | struct sk_buff *skb; | ||
145 | dma_addr_t dma; | ||
146 | unsigned long time_stamp; | ||
147 | u16 length; | ||
148 | u16 next_to_watch; | ||
149 | unsigned int bytecount; | ||
150 | u16 gso_segs; | ||
151 | u8 mapped_as_page; | ||
152 | }; | ||
153 | |||
154 | struct ixgbe_rx_buffer { | ||
155 | struct sk_buff *skb; | ||
156 | dma_addr_t dma; | ||
157 | struct page *page; | ||
158 | dma_addr_t page_dma; | ||
159 | unsigned int page_offset; | ||
160 | }; | ||
161 | |||
162 | struct ixgbe_queue_stats { | ||
163 | u64 packets; | ||
164 | u64 bytes; | ||
165 | }; | ||
166 | |||
167 | struct ixgbe_tx_queue_stats { | ||
168 | u64 restart_queue; | ||
169 | u64 tx_busy; | ||
170 | u64 completed; | ||
171 | u64 tx_done_old; | ||
172 | }; | ||
173 | |||
174 | struct ixgbe_rx_queue_stats { | ||
175 | u64 rsc_count; | ||
176 | u64 rsc_flush; | ||
177 | u64 non_eop_descs; | ||
178 | u64 alloc_rx_page_failed; | ||
179 | u64 alloc_rx_buff_failed; | ||
180 | }; | ||
181 | |||
182 | enum ixbge_ring_state_t { | ||
183 | __IXGBE_TX_FDIR_INIT_DONE, | ||
184 | __IXGBE_TX_DETECT_HANG, | ||
185 | __IXGBE_HANG_CHECK_ARMED, | ||
186 | __IXGBE_RX_PS_ENABLED, | ||
187 | __IXGBE_RX_RSC_ENABLED, | ||
188 | }; | ||
189 | |||
190 | #define ring_is_ps_enabled(ring) \ | ||
191 | test_bit(__IXGBE_RX_PS_ENABLED, &(ring)->state) | ||
192 | #define set_ring_ps_enabled(ring) \ | ||
193 | set_bit(__IXGBE_RX_PS_ENABLED, &(ring)->state) | ||
194 | #define clear_ring_ps_enabled(ring) \ | ||
195 | clear_bit(__IXGBE_RX_PS_ENABLED, &(ring)->state) | ||
196 | #define check_for_tx_hang(ring) \ | ||
197 | test_bit(__IXGBE_TX_DETECT_HANG, &(ring)->state) | ||
198 | #define set_check_for_tx_hang(ring) \ | ||
199 | set_bit(__IXGBE_TX_DETECT_HANG, &(ring)->state) | ||
200 | #define clear_check_for_tx_hang(ring) \ | ||
201 | clear_bit(__IXGBE_TX_DETECT_HANG, &(ring)->state) | ||
202 | #define ring_is_rsc_enabled(ring) \ | ||
203 | test_bit(__IXGBE_RX_RSC_ENABLED, &(ring)->state) | ||
204 | #define set_ring_rsc_enabled(ring) \ | ||
205 | set_bit(__IXGBE_RX_RSC_ENABLED, &(ring)->state) | ||
206 | #define clear_ring_rsc_enabled(ring) \ | ||
207 | clear_bit(__IXGBE_RX_RSC_ENABLED, &(ring)->state) | ||
208 | struct ixgbe_ring { | ||
209 | void *desc; /* descriptor ring memory */ | ||
210 | struct device *dev; /* device for DMA mapping */ | ||
211 | struct net_device *netdev; /* netdev ring belongs to */ | ||
212 | union { | ||
213 | struct ixgbe_tx_buffer *tx_buffer_info; | ||
214 | struct ixgbe_rx_buffer *rx_buffer_info; | ||
215 | }; | ||
216 | unsigned long state; | ||
217 | u8 __iomem *tail; | ||
218 | |||
219 | u16 count; /* amount of descriptors */ | ||
220 | u16 rx_buf_len; | ||
221 | |||
222 | u8 queue_index; /* needed for multiqueue queue management */ | ||
223 | u8 reg_idx; /* holds the special value that gets | ||
224 | * the hardware register offset | ||
225 | * associated with this ring, which is | ||
226 | * different for DCB and RSS modes | ||
227 | */ | ||
228 | u8 atr_sample_rate; | ||
229 | u8 atr_count; | ||
230 | |||
231 | u16 next_to_use; | ||
232 | u16 next_to_clean; | ||
233 | |||
234 | u8 dcb_tc; | ||
235 | struct ixgbe_queue_stats stats; | ||
236 | struct u64_stats_sync syncp; | ||
237 | union { | ||
238 | struct ixgbe_tx_queue_stats tx_stats; | ||
239 | struct ixgbe_rx_queue_stats rx_stats; | ||
240 | }; | ||
241 | int numa_node; | ||
242 | unsigned int size; /* length in bytes */ | ||
243 | dma_addr_t dma; /* phys. address of descriptor ring */ | ||
244 | struct rcu_head rcu; | ||
245 | struct ixgbe_q_vector *q_vector; /* back-pointer to host q_vector */ | ||
246 | } ____cacheline_internodealigned_in_smp; | ||
247 | |||
248 | enum ixgbe_ring_f_enum { | ||
249 | RING_F_NONE = 0, | ||
250 | RING_F_VMDQ, /* SR-IOV uses the same ring feature */ | ||
251 | RING_F_RSS, | ||
252 | RING_F_FDIR, | ||
253 | #ifdef IXGBE_FCOE | ||
254 | RING_F_FCOE, | ||
255 | #endif /* IXGBE_FCOE */ | ||
256 | |||
257 | RING_F_ARRAY_SIZE /* must be last in enum set */ | ||
258 | }; | ||
259 | |||
260 | #define IXGBE_MAX_RSS_INDICES 16 | ||
261 | #define IXGBE_MAX_VMDQ_INDICES 64 | ||
262 | #define IXGBE_MAX_FDIR_INDICES 64 | ||
263 | #ifdef IXGBE_FCOE | ||
264 | #define IXGBE_MAX_FCOE_INDICES 8 | ||
265 | #define MAX_RX_QUEUES (IXGBE_MAX_FDIR_INDICES + IXGBE_MAX_FCOE_INDICES) | ||
266 | #define MAX_TX_QUEUES (IXGBE_MAX_FDIR_INDICES + IXGBE_MAX_FCOE_INDICES) | ||
267 | #else | ||
268 | #define MAX_RX_QUEUES IXGBE_MAX_FDIR_INDICES | ||
269 | #define MAX_TX_QUEUES IXGBE_MAX_FDIR_INDICES | ||
270 | #endif /* IXGBE_FCOE */ | ||
271 | struct ixgbe_ring_feature { | ||
272 | int indices; | ||
273 | int mask; | ||
274 | } ____cacheline_internodealigned_in_smp; | ||
275 | |||
276 | struct ixgbe_ring_container { | ||
277 | #if MAX_RX_QUEUES > MAX_TX_QUEUES | ||
278 | DECLARE_BITMAP(idx, MAX_RX_QUEUES); | ||
279 | #else | ||
280 | DECLARE_BITMAP(idx, MAX_TX_QUEUES); | ||
281 | #endif | ||
282 | unsigned int total_bytes; /* total bytes processed this int */ | ||
283 | unsigned int total_packets; /* total packets processed this int */ | ||
284 | u16 work_limit; /* total work allowed per interrupt */ | ||
285 | u8 count; /* total number of rings in vector */ | ||
286 | u8 itr; /* current ITR setting for ring */ | ||
287 | }; | ||
288 | |||
289 | #define MAX_RX_PACKET_BUFFERS ((adapter->flags & IXGBE_FLAG_DCB_ENABLED) \ | ||
290 | ? 8 : 1) | ||
291 | #define MAX_TX_PACKET_BUFFERS MAX_RX_PACKET_BUFFERS | ||
292 | |||
293 | /* MAX_MSIX_Q_VECTORS of these are allocated, | ||
294 | * but we only use one per queue-specific vector. | ||
295 | */ | ||
296 | struct ixgbe_q_vector { | ||
297 | struct ixgbe_adapter *adapter; | ||
298 | unsigned int v_idx; /* index of q_vector within array, also used for | ||
299 | * finding the bit in EICR and friends that | ||
300 | * represents the vector for this ring */ | ||
301 | #ifdef CONFIG_IXGBE_DCA | ||
302 | int cpu; /* CPU for DCA */ | ||
303 | #endif | ||
304 | struct napi_struct napi; | ||
305 | struct ixgbe_ring_container rx, tx; | ||
306 | u32 eitr; | ||
307 | cpumask_var_t affinity_mask; | ||
308 | char name[IFNAMSIZ + 9]; | ||
309 | }; | ||
310 | |||
311 | /* Helper macros to switch between ints/sec and what the register uses. | ||
312 | * And yes, it's the same math going both ways. The lowest value | ||
313 | * supported by all of the ixgbe hardware is 8. | ||
314 | */ | ||
315 | #define EITR_INTS_PER_SEC_TO_REG(_eitr) \ | ||
316 | ((_eitr) ? (1000000000 / ((_eitr) * 256)) : 8) | ||
317 | #define EITR_REG_TO_INTS_PER_SEC EITR_INTS_PER_SEC_TO_REG | ||
318 | |||
319 | static inline u16 ixgbe_desc_unused(struct ixgbe_ring *ring) | ||
320 | { | ||
321 | u16 ntc = ring->next_to_clean; | ||
322 | u16 ntu = ring->next_to_use; | ||
323 | |||
324 | return ((ntc > ntu) ? 0 : ring->count) + ntc - ntu - 1; | ||
325 | } | ||
326 | |||
327 | #define IXGBE_RX_DESC_ADV(R, i) \ | ||
328 | (&(((union ixgbe_adv_rx_desc *)((R)->desc))[i])) | ||
329 | #define IXGBE_TX_DESC_ADV(R, i) \ | ||
330 | (&(((union ixgbe_adv_tx_desc *)((R)->desc))[i])) | ||
331 | #define IXGBE_TX_CTXTDESC_ADV(R, i) \ | ||
332 | (&(((struct ixgbe_adv_tx_context_desc *)((R)->desc))[i])) | ||
333 | |||
334 | #define IXGBE_MAX_JUMBO_FRAME_SIZE 16128 | ||
335 | #ifdef IXGBE_FCOE | ||
336 | /* Use 3K as the baby jumbo frame size for FCoE */ | ||
337 | #define IXGBE_FCOE_JUMBO_FRAME_SIZE 3072 | ||
338 | #endif /* IXGBE_FCOE */ | ||
339 | |||
340 | #define OTHER_VECTOR 1 | ||
341 | #define NON_Q_VECTORS (OTHER_VECTOR) | ||
342 | |||
343 | #define MAX_MSIX_VECTORS_82599 64 | ||
344 | #define MAX_MSIX_Q_VECTORS_82599 64 | ||
345 | #define MAX_MSIX_VECTORS_82598 18 | ||
346 | #define MAX_MSIX_Q_VECTORS_82598 16 | ||
347 | |||
348 | #define MAX_MSIX_Q_VECTORS MAX_MSIX_Q_VECTORS_82599 | ||
349 | #define MAX_MSIX_COUNT MAX_MSIX_VECTORS_82599 | ||
350 | |||
351 | #define MIN_MSIX_Q_VECTORS 2 | ||
352 | #define MIN_MSIX_COUNT (MIN_MSIX_Q_VECTORS + NON_Q_VECTORS) | ||
353 | |||
354 | /* board specific private data structure */ | ||
355 | struct ixgbe_adapter { | ||
356 | unsigned long state; | ||
357 | |||
358 | /* Some features need tri-state capability, | ||
359 | * thus the additional *_CAPABLE flags. | ||
360 | */ | ||
361 | u32 flags; | ||
362 | #define IXGBE_FLAG_RX_CSUM_ENABLED (u32)(1) | ||
363 | #define IXGBE_FLAG_MSI_CAPABLE (u32)(1 << 1) | ||
364 | #define IXGBE_FLAG_MSI_ENABLED (u32)(1 << 2) | ||
365 | #define IXGBE_FLAG_MSIX_CAPABLE (u32)(1 << 3) | ||
366 | #define IXGBE_FLAG_MSIX_ENABLED (u32)(1 << 4) | ||
367 | #define IXGBE_FLAG_RX_1BUF_CAPABLE (u32)(1 << 6) | ||
368 | #define IXGBE_FLAG_RX_PS_CAPABLE (u32)(1 << 7) | ||
369 | #define IXGBE_FLAG_RX_PS_ENABLED (u32)(1 << 8) | ||
370 | #define IXGBE_FLAG_IN_NETPOLL (u32)(1 << 9) | ||
371 | #define IXGBE_FLAG_DCA_ENABLED (u32)(1 << 10) | ||
372 | #define IXGBE_FLAG_DCA_CAPABLE (u32)(1 << 11) | ||
373 | #define IXGBE_FLAG_IMIR_ENABLED (u32)(1 << 12) | ||
374 | #define IXGBE_FLAG_MQ_CAPABLE (u32)(1 << 13) | ||
375 | #define IXGBE_FLAG_DCB_ENABLED (u32)(1 << 14) | ||
376 | #define IXGBE_FLAG_RSS_ENABLED (u32)(1 << 16) | ||
377 | #define IXGBE_FLAG_RSS_CAPABLE (u32)(1 << 17) | ||
378 | #define IXGBE_FLAG_VMDQ_CAPABLE (u32)(1 << 18) | ||
379 | #define IXGBE_FLAG_VMDQ_ENABLED (u32)(1 << 19) | ||
380 | #define IXGBE_FLAG_FAN_FAIL_CAPABLE (u32)(1 << 20) | ||
381 | #define IXGBE_FLAG_NEED_LINK_UPDATE (u32)(1 << 22) | ||
382 | #define IXGBE_FLAG_NEED_LINK_CONFIG (u32)(1 << 23) | ||
383 | #define IXGBE_FLAG_FDIR_HASH_CAPABLE (u32)(1 << 24) | ||
384 | #define IXGBE_FLAG_FDIR_PERFECT_CAPABLE (u32)(1 << 25) | ||
385 | #define IXGBE_FLAG_FCOE_CAPABLE (u32)(1 << 26) | ||
386 | #define IXGBE_FLAG_FCOE_ENABLED (u32)(1 << 27) | ||
387 | #define IXGBE_FLAG_SRIOV_CAPABLE (u32)(1 << 28) | ||
388 | #define IXGBE_FLAG_SRIOV_ENABLED (u32)(1 << 29) | ||
389 | |||
390 | u32 flags2; | ||
391 | #define IXGBE_FLAG2_RSC_CAPABLE (u32)(1) | ||
392 | #define IXGBE_FLAG2_RSC_ENABLED (u32)(1 << 1) | ||
393 | #define IXGBE_FLAG2_TEMP_SENSOR_CAPABLE (u32)(1 << 2) | ||
394 | #define IXGBE_FLAG2_TEMP_SENSOR_EVENT (u32)(1 << 3) | ||
395 | #define IXGBE_FLAG2_SEARCH_FOR_SFP (u32)(1 << 4) | ||
396 | #define IXGBE_FLAG2_SFP_NEEDS_RESET (u32)(1 << 5) | ||
397 | #define IXGBE_FLAG2_RESET_REQUESTED (u32)(1 << 6) | ||
398 | #define IXGBE_FLAG2_FDIR_REQUIRES_REINIT (u32)(1 << 7) | ||
399 | |||
400 | unsigned long active_vlans[BITS_TO_LONGS(VLAN_N_VID)]; | ||
401 | u16 bd_number; | ||
402 | struct ixgbe_q_vector *q_vector[MAX_MSIX_Q_VECTORS]; | ||
403 | |||
404 | /* DCB parameters */ | ||
405 | struct ieee_pfc *ixgbe_ieee_pfc; | ||
406 | struct ieee_ets *ixgbe_ieee_ets; | ||
407 | struct ixgbe_dcb_config dcb_cfg; | ||
408 | struct ixgbe_dcb_config temp_dcb_cfg; | ||
409 | u8 dcb_set_bitmap; | ||
410 | u8 dcbx_cap; | ||
411 | enum ixgbe_fc_mode last_lfc_mode; | ||
412 | |||
413 | /* Interrupt Throttle Rate */ | ||
414 | u32 rx_itr_setting; | ||
415 | u32 tx_itr_setting; | ||
416 | u16 eitr_low; | ||
417 | u16 eitr_high; | ||
418 | |||
419 | /* Work limits */ | ||
420 | u16 tx_work_limit; | ||
421 | |||
422 | /* TX */ | ||
423 | struct ixgbe_ring *tx_ring[MAX_TX_QUEUES] ____cacheline_aligned_in_smp; | ||
424 | int num_tx_queues; | ||
425 | u32 tx_timeout_count; | ||
426 | bool detect_tx_hung; | ||
427 | |||
428 | u64 restart_queue; | ||
429 | u64 lsc_int; | ||
430 | |||
431 | /* RX */ | ||
432 | struct ixgbe_ring *rx_ring[MAX_RX_QUEUES] ____cacheline_aligned_in_smp; | ||
433 | int num_rx_queues; | ||
434 | int num_rx_pools; /* == num_rx_queues in 82598 */ | ||
435 | int num_rx_queues_per_pool; /* 1 if 82598, can be many if 82599 */ | ||
436 | u64 hw_csum_rx_error; | ||
437 | u64 hw_rx_no_dma_resources; | ||
438 | u64 non_eop_descs; | ||
439 | int num_msix_vectors; | ||
440 | int max_msix_q_vectors; /* true count of q_vectors for device */ | ||
441 | struct ixgbe_ring_feature ring_feature[RING_F_ARRAY_SIZE]; | ||
442 | struct msix_entry *msix_entries; | ||
443 | |||
444 | u32 alloc_rx_page_failed; | ||
445 | u32 alloc_rx_buff_failed; | ||
446 | |||
447 | /* default to trying for four seconds */ | ||
448 | #define IXGBE_TRY_LINK_TIMEOUT (4 * HZ) | ||
449 | |||
450 | /* OS defined structs */ | ||
451 | struct net_device *netdev; | ||
452 | struct pci_dev *pdev; | ||
453 | |||
454 | u32 test_icr; | ||
455 | struct ixgbe_ring test_tx_ring; | ||
456 | struct ixgbe_ring test_rx_ring; | ||
457 | |||
458 | /* structs defined in ixgbe_hw.h */ | ||
459 | struct ixgbe_hw hw; | ||
460 | u16 msg_enable; | ||
461 | struct ixgbe_hw_stats stats; | ||
462 | |||
463 | /* Interrupt Throttle Rate */ | ||
464 | u32 rx_eitr_param; | ||
465 | u32 tx_eitr_param; | ||
466 | |||
467 | u64 tx_busy; | ||
468 | unsigned int tx_ring_count; | ||
469 | unsigned int rx_ring_count; | ||
470 | |||
471 | u32 link_speed; | ||
472 | bool link_up; | ||
473 | unsigned long link_check_timeout; | ||
474 | |||
475 | struct work_struct service_task; | ||
476 | struct timer_list service_timer; | ||
477 | u32 fdir_pballoc; | ||
478 | u32 atr_sample_rate; | ||
479 | unsigned long fdir_overflow; /* number of times ATR was backed off */ | ||
480 | spinlock_t fdir_perfect_lock; | ||
481 | #ifdef IXGBE_FCOE | ||
482 | struct ixgbe_fcoe fcoe; | ||
483 | #endif /* IXGBE_FCOE */ | ||
484 | u64 rsc_total_count; | ||
485 | u64 rsc_total_flush; | ||
486 | u32 wol; | ||
487 | u16 eeprom_version; | ||
488 | |||
489 | int node; | ||
490 | u32 led_reg; | ||
491 | u32 interrupt_event; | ||
492 | char lsc_int_name[IFNAMSIZ + 9]; | ||
493 | |||
494 | /* SR-IOV */ | ||
495 | DECLARE_BITMAP(active_vfs, IXGBE_MAX_VF_FUNCTIONS); | ||
496 | unsigned int num_vfs; | ||
497 | struct vf_data_storage *vfinfo; | ||
498 | int vf_rate_link_speed; | ||
499 | struct vf_macvlans vf_mvs; | ||
500 | struct vf_macvlans *mv_list; | ||
501 | bool antispoofing_enabled; | ||
502 | |||
503 | struct hlist_head fdir_filter_list; | ||
504 | union ixgbe_atr_input fdir_mask; | ||
505 | int fdir_filter_count; | ||
506 | }; | ||
507 | |||
508 | struct ixgbe_fdir_filter { | ||
509 | struct hlist_node fdir_node; | ||
510 | union ixgbe_atr_input filter; | ||
511 | u16 sw_idx; | ||
512 | u16 action; | ||
513 | }; | ||
514 | |||
515 | enum ixbge_state_t { | ||
516 | __IXGBE_TESTING, | ||
517 | __IXGBE_RESETTING, | ||
518 | __IXGBE_DOWN, | ||
519 | __IXGBE_SERVICE_SCHED, | ||
520 | __IXGBE_IN_SFP_INIT, | ||
521 | }; | ||
522 | |||
523 | struct ixgbe_rsc_cb { | ||
524 | dma_addr_t dma; | ||
525 | u16 skb_cnt; | ||
526 | bool delay_unmap; | ||
527 | }; | ||
528 | #define IXGBE_RSC_CB(skb) ((struct ixgbe_rsc_cb *)(skb)->cb) | ||
529 | |||
530 | enum ixgbe_boards { | ||
531 | board_82598, | ||
532 | board_82599, | ||
533 | board_X540, | ||
534 | }; | ||
535 | |||
536 | extern struct ixgbe_info ixgbe_82598_info; | ||
537 | extern struct ixgbe_info ixgbe_82599_info; | ||
538 | extern struct ixgbe_info ixgbe_X540_info; | ||
539 | #ifdef CONFIG_IXGBE_DCB | ||
540 | extern const struct dcbnl_rtnl_ops dcbnl_ops; | ||
541 | extern int ixgbe_copy_dcb_cfg(struct ixgbe_dcb_config *src_dcb_cfg, | ||
542 | struct ixgbe_dcb_config *dst_dcb_cfg, | ||
543 | int tc_max); | ||
544 | #endif | ||
545 | |||
546 | extern char ixgbe_driver_name[]; | ||
547 | extern const char ixgbe_driver_version[]; | ||
548 | |||
549 | extern int ixgbe_up(struct ixgbe_adapter *adapter); | ||
550 | extern void ixgbe_down(struct ixgbe_adapter *adapter); | ||
551 | extern void ixgbe_reinit_locked(struct ixgbe_adapter *adapter); | ||
552 | extern void ixgbe_reset(struct ixgbe_adapter *adapter); | ||
553 | extern void ixgbe_set_ethtool_ops(struct net_device *netdev); | ||
554 | extern int ixgbe_setup_rx_resources(struct ixgbe_ring *); | ||
555 | extern int ixgbe_setup_tx_resources(struct ixgbe_ring *); | ||
556 | extern void ixgbe_free_rx_resources(struct ixgbe_ring *); | ||
557 | extern void ixgbe_free_tx_resources(struct ixgbe_ring *); | ||
558 | extern void ixgbe_configure_rx_ring(struct ixgbe_adapter *,struct ixgbe_ring *); | ||
559 | extern void ixgbe_configure_tx_ring(struct ixgbe_adapter *,struct ixgbe_ring *); | ||
560 | extern void ixgbe_disable_rx_queue(struct ixgbe_adapter *adapter, | ||
561 | struct ixgbe_ring *); | ||
562 | extern void ixgbe_update_stats(struct ixgbe_adapter *adapter); | ||
563 | extern int ixgbe_init_interrupt_scheme(struct ixgbe_adapter *adapter); | ||
564 | extern void ixgbe_clear_interrupt_scheme(struct ixgbe_adapter *adapter); | ||
565 | extern netdev_tx_t ixgbe_xmit_frame_ring(struct sk_buff *, | ||
566 | struct ixgbe_adapter *, | ||
567 | struct ixgbe_ring *); | ||
568 | extern void ixgbe_unmap_and_free_tx_resource(struct ixgbe_ring *, | ||
569 | struct ixgbe_tx_buffer *); | ||
570 | extern void ixgbe_alloc_rx_buffers(struct ixgbe_ring *, u16); | ||
571 | extern void ixgbe_write_eitr(struct ixgbe_q_vector *); | ||
572 | extern int ethtool_ioctl(struct ifreq *ifr); | ||
573 | extern s32 ixgbe_reinit_fdir_tables_82599(struct ixgbe_hw *hw); | ||
574 | extern s32 ixgbe_init_fdir_signature_82599(struct ixgbe_hw *hw, u32 fdirctrl); | ||
575 | extern s32 ixgbe_init_fdir_perfect_82599(struct ixgbe_hw *hw, u32 fdirctrl); | ||
576 | extern s32 ixgbe_fdir_add_signature_filter_82599(struct ixgbe_hw *hw, | ||
577 | union ixgbe_atr_hash_dword input, | ||
578 | union ixgbe_atr_hash_dword common, | ||
579 | u8 queue); | ||
580 | extern s32 ixgbe_fdir_set_input_mask_82599(struct ixgbe_hw *hw, | ||
581 | union ixgbe_atr_input *input_mask); | ||
582 | extern s32 ixgbe_fdir_write_perfect_filter_82599(struct ixgbe_hw *hw, | ||
583 | union ixgbe_atr_input *input, | ||
584 | u16 soft_id, u8 queue); | ||
585 | extern s32 ixgbe_fdir_erase_perfect_filter_82599(struct ixgbe_hw *hw, | ||
586 | union ixgbe_atr_input *input, | ||
587 | u16 soft_id); | ||
588 | extern void ixgbe_atr_compute_perfect_hash_82599(union ixgbe_atr_input *input, | ||
589 | union ixgbe_atr_input *mask); | ||
590 | extern void ixgbe_set_rx_mode(struct net_device *netdev); | ||
591 | extern int ixgbe_setup_tc(struct net_device *dev, u8 tc); | ||
592 | extern void ixgbe_tx_ctxtdesc(struct ixgbe_ring *, u32, u32, u32, u32); | ||
593 | extern void ixgbe_do_reset(struct net_device *netdev); | ||
594 | #ifdef IXGBE_FCOE | ||
595 | extern void ixgbe_configure_fcoe(struct ixgbe_adapter *adapter); | ||
596 | extern int ixgbe_fso(struct ixgbe_ring *tx_ring, struct sk_buff *skb, | ||
597 | u32 tx_flags, u8 *hdr_len); | ||
598 | extern void ixgbe_cleanup_fcoe(struct ixgbe_adapter *adapter); | ||
599 | extern int ixgbe_fcoe_ddp(struct ixgbe_adapter *adapter, | ||
600 | union ixgbe_adv_rx_desc *rx_desc, | ||
601 | struct sk_buff *skb, | ||
602 | u32 staterr); | ||
603 | extern int ixgbe_fcoe_ddp_get(struct net_device *netdev, u16 xid, | ||
604 | struct scatterlist *sgl, unsigned int sgc); | ||
605 | extern int ixgbe_fcoe_ddp_target(struct net_device *netdev, u16 xid, | ||
606 | struct scatterlist *sgl, unsigned int sgc); | ||
607 | extern int ixgbe_fcoe_ddp_put(struct net_device *netdev, u16 xid); | ||
608 | extern int ixgbe_fcoe_enable(struct net_device *netdev); | ||
609 | extern int ixgbe_fcoe_disable(struct net_device *netdev); | ||
610 | #ifdef CONFIG_IXGBE_DCB | ||
611 | extern u8 ixgbe_fcoe_getapp(struct ixgbe_adapter *adapter); | ||
612 | extern u8 ixgbe_fcoe_setapp(struct ixgbe_adapter *adapter, u8 up); | ||
613 | #endif /* CONFIG_IXGBE_DCB */ | ||
614 | extern int ixgbe_fcoe_get_wwn(struct net_device *netdev, u64 *wwn, int type); | ||
615 | #endif /* IXGBE_FCOE */ | ||
616 | |||
617 | #endif /* _IXGBE_H_ */ | ||
diff --git a/drivers/net/ixgbe/ixgbe_82598.c b/drivers/net/ixgbe/ixgbe_82598.c new file mode 100644 index 00000000000..0d4e3826449 --- /dev/null +++ b/drivers/net/ixgbe/ixgbe_82598.c | |||
@@ -0,0 +1,1353 @@ | |||
1 | /******************************************************************************* | ||
2 | |||
3 | Intel 10 Gigabit PCI Express Linux driver | ||
4 | Copyright(c) 1999 - 2011 Intel Corporation. | ||
5 | |||
6 | This program is free software; you can redistribute it and/or modify it | ||
7 | under the terms and conditions of the GNU General Public License, | ||
8 | version 2, as published by the Free Software Foundation. | ||
9 | |||
10 | This program is distributed in the hope it will be useful, but WITHOUT | ||
11 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
12 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
13 | more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License along with | ||
16 | this program; if not, write to the Free Software Foundation, Inc., | ||
17 | 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. | ||
18 | |||
19 | The full GNU General Public License is included in this distribution in | ||
20 | the file called "COPYING". | ||
21 | |||
22 | Contact Information: | ||
23 | e1000-devel Mailing List <e1000-devel@lists.sourceforge.net> | ||
24 | Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 | ||
25 | |||
26 | *******************************************************************************/ | ||
27 | |||
28 | #include <linux/pci.h> | ||
29 | #include <linux/delay.h> | ||
30 | #include <linux/sched.h> | ||
31 | |||
32 | #include "ixgbe.h" | ||
33 | #include "ixgbe_phy.h" | ||
34 | |||
35 | #define IXGBE_82598_MAX_TX_QUEUES 32 | ||
36 | #define IXGBE_82598_MAX_RX_QUEUES 64 | ||
37 | #define IXGBE_82598_RAR_ENTRIES 16 | ||
38 | #define IXGBE_82598_MC_TBL_SIZE 128 | ||
39 | #define IXGBE_82598_VFT_TBL_SIZE 128 | ||
40 | #define IXGBE_82598_RX_PB_SIZE 512 | ||
41 | |||
42 | static s32 ixgbe_setup_copper_link_82598(struct ixgbe_hw *hw, | ||
43 | ixgbe_link_speed speed, | ||
44 | bool autoneg, | ||
45 | bool autoneg_wait_to_complete); | ||
46 | static s32 ixgbe_read_i2c_eeprom_82598(struct ixgbe_hw *hw, u8 byte_offset, | ||
47 | u8 *eeprom_data); | ||
48 | |||
49 | /** | ||
50 | * ixgbe_set_pcie_completion_timeout - set pci-e completion timeout | ||
51 | * @hw: pointer to the HW structure | ||
52 | * | ||
53 | * The defaults for 82598 should be in the range of 50us to 50ms, | ||
54 | * however the hardware default for these parts is 500us to 1ms which is less | ||
55 | * than the 10ms recommended by the pci-e spec. To address this we need to | ||
56 | * increase the value to either 10ms to 250ms for capability version 1 config, | ||
57 | * or 16ms to 55ms for version 2. | ||
58 | **/ | ||
59 | static void ixgbe_set_pcie_completion_timeout(struct ixgbe_hw *hw) | ||
60 | { | ||
61 | struct ixgbe_adapter *adapter = hw->back; | ||
62 | u32 gcr = IXGBE_READ_REG(hw, IXGBE_GCR); | ||
63 | u16 pcie_devctl2; | ||
64 | |||
65 | /* only take action if timeout value is defaulted to 0 */ | ||
66 | if (gcr & IXGBE_GCR_CMPL_TMOUT_MASK) | ||
67 | goto out; | ||
68 | |||
69 | /* | ||
70 | * if capababilities version is type 1 we can write the | ||
71 | * timeout of 10ms to 250ms through the GCR register | ||
72 | */ | ||
73 | if (!(gcr & IXGBE_GCR_CAP_VER2)) { | ||
74 | gcr |= IXGBE_GCR_CMPL_TMOUT_10ms; | ||
75 | goto out; | ||
76 | } | ||
77 | |||
78 | /* | ||
79 | * for version 2 capabilities we need to write the config space | ||
80 | * directly in order to set the completion timeout value for | ||
81 | * 16ms to 55ms | ||
82 | */ | ||
83 | pci_read_config_word(adapter->pdev, | ||
84 | IXGBE_PCI_DEVICE_CONTROL2, &pcie_devctl2); | ||
85 | pcie_devctl2 |= IXGBE_PCI_DEVICE_CONTROL2_16ms; | ||
86 | pci_write_config_word(adapter->pdev, | ||
87 | IXGBE_PCI_DEVICE_CONTROL2, pcie_devctl2); | ||
88 | out: | ||
89 | /* disable completion timeout resend */ | ||
90 | gcr &= ~IXGBE_GCR_CMPL_TMOUT_RESEND; | ||
91 | IXGBE_WRITE_REG(hw, IXGBE_GCR, gcr); | ||
92 | } | ||
93 | |||
94 | /** | ||
95 | * ixgbe_get_pcie_msix_count_82598 - Gets MSI-X vector count | ||
96 | * @hw: pointer to hardware structure | ||
97 | * | ||
98 | * Read PCIe configuration space, and get the MSI-X vector count from | ||
99 | * the capabilities table. | ||
100 | **/ | ||
101 | static u16 ixgbe_get_pcie_msix_count_82598(struct ixgbe_hw *hw) | ||
102 | { | ||
103 | struct ixgbe_adapter *adapter = hw->back; | ||
104 | u16 msix_count; | ||
105 | pci_read_config_word(adapter->pdev, IXGBE_PCIE_MSIX_82598_CAPS, | ||
106 | &msix_count); | ||
107 | msix_count &= IXGBE_PCIE_MSIX_TBL_SZ_MASK; | ||
108 | |||
109 | /* MSI-X count is zero-based in HW, so increment to give proper value */ | ||
110 | msix_count++; | ||
111 | |||
112 | return msix_count; | ||
113 | } | ||
114 | |||
115 | /** | ||
116 | */ | ||
117 | static s32 ixgbe_get_invariants_82598(struct ixgbe_hw *hw) | ||
118 | { | ||
119 | struct ixgbe_mac_info *mac = &hw->mac; | ||
120 | |||
121 | /* Call PHY identify routine to get the phy type */ | ||
122 | ixgbe_identify_phy_generic(hw); | ||
123 | |||
124 | mac->mcft_size = IXGBE_82598_MC_TBL_SIZE; | ||
125 | mac->vft_size = IXGBE_82598_VFT_TBL_SIZE; | ||
126 | mac->num_rar_entries = IXGBE_82598_RAR_ENTRIES; | ||
127 | mac->max_rx_queues = IXGBE_82598_MAX_RX_QUEUES; | ||
128 | mac->max_tx_queues = IXGBE_82598_MAX_TX_QUEUES; | ||
129 | mac->max_msix_vectors = ixgbe_get_pcie_msix_count_82598(hw); | ||
130 | |||
131 | return 0; | ||
132 | } | ||
133 | |||
134 | /** | ||
135 | * ixgbe_init_phy_ops_82598 - PHY/SFP specific init | ||
136 | * @hw: pointer to hardware structure | ||
137 | * | ||
138 | * Initialize any function pointers that were not able to be | ||
139 | * set during get_invariants because the PHY/SFP type was | ||
140 | * not known. Perform the SFP init if necessary. | ||
141 | * | ||
142 | **/ | ||
143 | static s32 ixgbe_init_phy_ops_82598(struct ixgbe_hw *hw) | ||
144 | { | ||
145 | struct ixgbe_mac_info *mac = &hw->mac; | ||
146 | struct ixgbe_phy_info *phy = &hw->phy; | ||
147 | s32 ret_val = 0; | ||
148 | u16 list_offset, data_offset; | ||
149 | |||
150 | /* Identify the PHY */ | ||
151 | phy->ops.identify(hw); | ||
152 | |||
153 | /* Overwrite the link function pointers if copper PHY */ | ||
154 | if (mac->ops.get_media_type(hw) == ixgbe_media_type_copper) { | ||
155 | mac->ops.setup_link = &ixgbe_setup_copper_link_82598; | ||
156 | mac->ops.get_link_capabilities = | ||
157 | &ixgbe_get_copper_link_capabilities_generic; | ||
158 | } | ||
159 | |||
160 | switch (hw->phy.type) { | ||
161 | case ixgbe_phy_tn: | ||
162 | phy->ops.setup_link = &ixgbe_setup_phy_link_tnx; | ||
163 | phy->ops.check_link = &ixgbe_check_phy_link_tnx; | ||
164 | phy->ops.get_firmware_version = | ||
165 | &ixgbe_get_phy_firmware_version_tnx; | ||
166 | break; | ||
167 | case ixgbe_phy_nl: | ||
168 | phy->ops.reset = &ixgbe_reset_phy_nl; | ||
169 | |||
170 | /* Call SFP+ identify routine to get the SFP+ module type */ | ||
171 | ret_val = phy->ops.identify_sfp(hw); | ||
172 | if (ret_val != 0) | ||
173 | goto out; | ||
174 | else if (hw->phy.sfp_type == ixgbe_sfp_type_unknown) { | ||
175 | ret_val = IXGBE_ERR_SFP_NOT_SUPPORTED; | ||
176 | goto out; | ||
177 | } | ||
178 | |||
179 | /* Check to see if SFP+ module is supported */ | ||
180 | ret_val = ixgbe_get_sfp_init_sequence_offsets(hw, | ||
181 | &list_offset, | ||
182 | &data_offset); | ||
183 | if (ret_val != 0) { | ||
184 | ret_val = IXGBE_ERR_SFP_NOT_SUPPORTED; | ||
185 | goto out; | ||
186 | } | ||
187 | break; | ||
188 | default: | ||
189 | break; | ||
190 | } | ||
191 | |||
192 | out: | ||
193 | return ret_val; | ||
194 | } | ||
195 | |||
196 | /** | ||
197 | * ixgbe_start_hw_82598 - Prepare hardware for Tx/Rx | ||
198 | * @hw: pointer to hardware structure | ||
199 | * | ||
200 | * Starts the hardware using the generic start_hw function. | ||
201 | * Disables relaxed ordering Then set pcie completion timeout | ||
202 | * | ||
203 | **/ | ||
204 | static s32 ixgbe_start_hw_82598(struct ixgbe_hw *hw) | ||
205 | { | ||
206 | u32 regval; | ||
207 | u32 i; | ||
208 | s32 ret_val = 0; | ||
209 | |||
210 | ret_val = ixgbe_start_hw_generic(hw); | ||
211 | |||
212 | /* Disable relaxed ordering */ | ||
213 | for (i = 0; ((i < hw->mac.max_tx_queues) && | ||
214 | (i < IXGBE_DCA_MAX_QUEUES_82598)); i++) { | ||
215 | regval = IXGBE_READ_REG(hw, IXGBE_DCA_TXCTRL(i)); | ||
216 | regval &= ~IXGBE_DCA_TXCTRL_TX_WB_RO_EN; | ||
217 | IXGBE_WRITE_REG(hw, IXGBE_DCA_TXCTRL(i), regval); | ||
218 | } | ||
219 | |||
220 | for (i = 0; ((i < hw->mac.max_rx_queues) && | ||
221 | (i < IXGBE_DCA_MAX_QUEUES_82598)); i++) { | ||
222 | regval = IXGBE_READ_REG(hw, IXGBE_DCA_RXCTRL(i)); | ||
223 | regval &= ~(IXGBE_DCA_RXCTRL_DESC_WRO_EN | | ||
224 | IXGBE_DCA_RXCTRL_DESC_HSRO_EN); | ||
225 | IXGBE_WRITE_REG(hw, IXGBE_DCA_RXCTRL(i), regval); | ||
226 | } | ||
227 | |||
228 | hw->mac.rx_pb_size = IXGBE_82598_RX_PB_SIZE; | ||
229 | |||
230 | /* set the completion timeout for interface */ | ||
231 | if (ret_val == 0) | ||
232 | ixgbe_set_pcie_completion_timeout(hw); | ||
233 | |||
234 | return ret_val; | ||
235 | } | ||
236 | |||
237 | /** | ||
238 | * ixgbe_get_link_capabilities_82598 - Determines link capabilities | ||
239 | * @hw: pointer to hardware structure | ||
240 | * @speed: pointer to link speed | ||
241 | * @autoneg: boolean auto-negotiation value | ||
242 | * | ||
243 | * Determines the link capabilities by reading the AUTOC register. | ||
244 | **/ | ||
245 | static s32 ixgbe_get_link_capabilities_82598(struct ixgbe_hw *hw, | ||
246 | ixgbe_link_speed *speed, | ||
247 | bool *autoneg) | ||
248 | { | ||
249 | s32 status = 0; | ||
250 | u32 autoc = 0; | ||
251 | |||
252 | /* | ||
253 | * Determine link capabilities based on the stored value of AUTOC, | ||
254 | * which represents EEPROM defaults. If AUTOC value has not been | ||
255 | * stored, use the current register value. | ||
256 | */ | ||
257 | if (hw->mac.orig_link_settings_stored) | ||
258 | autoc = hw->mac.orig_autoc; | ||
259 | else | ||
260 | autoc = IXGBE_READ_REG(hw, IXGBE_AUTOC); | ||
261 | |||
262 | switch (autoc & IXGBE_AUTOC_LMS_MASK) { | ||
263 | case IXGBE_AUTOC_LMS_1G_LINK_NO_AN: | ||
264 | *speed = IXGBE_LINK_SPEED_1GB_FULL; | ||
265 | *autoneg = false; | ||
266 | break; | ||
267 | |||
268 | case IXGBE_AUTOC_LMS_10G_LINK_NO_AN: | ||
269 | *speed = IXGBE_LINK_SPEED_10GB_FULL; | ||
270 | *autoneg = false; | ||
271 | break; | ||
272 | |||
273 | case IXGBE_AUTOC_LMS_1G_AN: | ||
274 | *speed = IXGBE_LINK_SPEED_1GB_FULL; | ||
275 | *autoneg = true; | ||
276 | break; | ||
277 | |||
278 | case IXGBE_AUTOC_LMS_KX4_AN: | ||
279 | case IXGBE_AUTOC_LMS_KX4_AN_1G_AN: | ||
280 | *speed = IXGBE_LINK_SPEED_UNKNOWN; | ||
281 | if (autoc & IXGBE_AUTOC_KX4_SUPP) | ||
282 | *speed |= IXGBE_LINK_SPEED_10GB_FULL; | ||
283 | if (autoc & IXGBE_AUTOC_KX_SUPP) | ||
284 | *speed |= IXGBE_LINK_SPEED_1GB_FULL; | ||
285 | *autoneg = true; | ||
286 | break; | ||
287 | |||
288 | default: | ||
289 | status = IXGBE_ERR_LINK_SETUP; | ||
290 | break; | ||
291 | } | ||
292 | |||
293 | return status; | ||
294 | } | ||
295 | |||
296 | /** | ||
297 | * ixgbe_get_media_type_82598 - Determines media type | ||
298 | * @hw: pointer to hardware structure | ||
299 | * | ||
300 | * Returns the media type (fiber, copper, backplane) | ||
301 | **/ | ||
302 | static enum ixgbe_media_type ixgbe_get_media_type_82598(struct ixgbe_hw *hw) | ||
303 | { | ||
304 | enum ixgbe_media_type media_type; | ||
305 | |||
306 | /* Detect if there is a copper PHY attached. */ | ||
307 | switch (hw->phy.type) { | ||
308 | case ixgbe_phy_cu_unknown: | ||
309 | case ixgbe_phy_tn: | ||
310 | case ixgbe_phy_aq: | ||
311 | media_type = ixgbe_media_type_copper; | ||
312 | goto out; | ||
313 | default: | ||
314 | break; | ||
315 | } | ||
316 | |||
317 | /* Media type for I82598 is based on device ID */ | ||
318 | switch (hw->device_id) { | ||
319 | case IXGBE_DEV_ID_82598: | ||
320 | case IXGBE_DEV_ID_82598_BX: | ||
321 | /* Default device ID is mezzanine card KX/KX4 */ | ||
322 | media_type = ixgbe_media_type_backplane; | ||
323 | break; | ||
324 | case IXGBE_DEV_ID_82598AF_DUAL_PORT: | ||
325 | case IXGBE_DEV_ID_82598AF_SINGLE_PORT: | ||
326 | case IXGBE_DEV_ID_82598_DA_DUAL_PORT: | ||
327 | case IXGBE_DEV_ID_82598_SR_DUAL_PORT_EM: | ||
328 | case IXGBE_DEV_ID_82598EB_XF_LR: | ||
329 | case IXGBE_DEV_ID_82598EB_SFP_LOM: | ||
330 | media_type = ixgbe_media_type_fiber; | ||
331 | break; | ||
332 | case IXGBE_DEV_ID_82598EB_CX4: | ||
333 | case IXGBE_DEV_ID_82598_CX4_DUAL_PORT: | ||
334 | media_type = ixgbe_media_type_cx4; | ||
335 | break; | ||
336 | case IXGBE_DEV_ID_82598AT: | ||
337 | case IXGBE_DEV_ID_82598AT2: | ||
338 | media_type = ixgbe_media_type_copper; | ||
339 | break; | ||
340 | default: | ||
341 | media_type = ixgbe_media_type_unknown; | ||
342 | break; | ||
343 | } | ||
344 | out: | ||
345 | return media_type; | ||
346 | } | ||
347 | |||
348 | /** | ||
349 | * ixgbe_fc_enable_82598 - Enable flow control | ||
350 | * @hw: pointer to hardware structure | ||
351 | * @packetbuf_num: packet buffer number (0-7) | ||
352 | * | ||
353 | * Enable flow control according to the current settings. | ||
354 | **/ | ||
355 | static s32 ixgbe_fc_enable_82598(struct ixgbe_hw *hw, s32 packetbuf_num) | ||
356 | { | ||
357 | s32 ret_val = 0; | ||
358 | u32 fctrl_reg; | ||
359 | u32 rmcs_reg; | ||
360 | u32 reg; | ||
361 | u32 rx_pba_size; | ||
362 | u32 link_speed = 0; | ||
363 | bool link_up; | ||
364 | |||
365 | #ifdef CONFIG_DCB | ||
366 | if (hw->fc.requested_mode == ixgbe_fc_pfc) | ||
367 | goto out; | ||
368 | |||
369 | #endif /* CONFIG_DCB */ | ||
370 | /* | ||
371 | * On 82598 having Rx FC on causes resets while doing 1G | ||
372 | * so if it's on turn it off once we know link_speed. For | ||
373 | * more details see 82598 Specification update. | ||
374 | */ | ||
375 | hw->mac.ops.check_link(hw, &link_speed, &link_up, false); | ||
376 | if (link_up && link_speed == IXGBE_LINK_SPEED_1GB_FULL) { | ||
377 | switch (hw->fc.requested_mode) { | ||
378 | case ixgbe_fc_full: | ||
379 | hw->fc.requested_mode = ixgbe_fc_tx_pause; | ||
380 | break; | ||
381 | case ixgbe_fc_rx_pause: | ||
382 | hw->fc.requested_mode = ixgbe_fc_none; | ||
383 | break; | ||
384 | default: | ||
385 | /* no change */ | ||
386 | break; | ||
387 | } | ||
388 | } | ||
389 | |||
390 | /* Negotiate the fc mode to use */ | ||
391 | ret_val = ixgbe_fc_autoneg(hw); | ||
392 | if (ret_val == IXGBE_ERR_FLOW_CONTROL) | ||
393 | goto out; | ||
394 | |||
395 | /* Disable any previous flow control settings */ | ||
396 | fctrl_reg = IXGBE_READ_REG(hw, IXGBE_FCTRL); | ||
397 | fctrl_reg &= ~(IXGBE_FCTRL_RFCE | IXGBE_FCTRL_RPFCE); | ||
398 | |||
399 | rmcs_reg = IXGBE_READ_REG(hw, IXGBE_RMCS); | ||
400 | rmcs_reg &= ~(IXGBE_RMCS_TFCE_PRIORITY | IXGBE_RMCS_TFCE_802_3X); | ||
401 | |||
402 | /* | ||
403 | * The possible values of fc.current_mode are: | ||
404 | * 0: Flow control is completely disabled | ||
405 | * 1: Rx flow control is enabled (we can receive pause frames, | ||
406 | * but not send pause frames). | ||
407 | * 2: Tx flow control is enabled (we can send pause frames but | ||
408 | * we do not support receiving pause frames). | ||
409 | * 3: Both Rx and Tx flow control (symmetric) are enabled. | ||
410 | #ifdef CONFIG_DCB | ||
411 | * 4: Priority Flow Control is enabled. | ||
412 | #endif | ||
413 | * other: Invalid. | ||
414 | */ | ||
415 | switch (hw->fc.current_mode) { | ||
416 | case ixgbe_fc_none: | ||
417 | /* | ||
418 | * Flow control is disabled by software override or autoneg. | ||
419 | * The code below will actually disable it in the HW. | ||
420 | */ | ||
421 | break; | ||
422 | case ixgbe_fc_rx_pause: | ||
423 | /* | ||
424 | * Rx Flow control is enabled and Tx Flow control is | ||
425 | * disabled by software override. Since there really | ||
426 | * isn't a way to advertise that we are capable of RX | ||
427 | * Pause ONLY, we will advertise that we support both | ||
428 | * symmetric and asymmetric Rx PAUSE. Later, we will | ||
429 | * disable the adapter's ability to send PAUSE frames. | ||
430 | */ | ||
431 | fctrl_reg |= IXGBE_FCTRL_RFCE; | ||
432 | break; | ||
433 | case ixgbe_fc_tx_pause: | ||
434 | /* | ||
435 | * Tx Flow control is enabled, and Rx Flow control is | ||
436 | * disabled by software override. | ||
437 | */ | ||
438 | rmcs_reg |= IXGBE_RMCS_TFCE_802_3X; | ||
439 | break; | ||
440 | case ixgbe_fc_full: | ||
441 | /* Flow control (both Rx and Tx) is enabled by SW override. */ | ||
442 | fctrl_reg |= IXGBE_FCTRL_RFCE; | ||
443 | rmcs_reg |= IXGBE_RMCS_TFCE_802_3X; | ||
444 | break; | ||
445 | #ifdef CONFIG_DCB | ||
446 | case ixgbe_fc_pfc: | ||
447 | goto out; | ||
448 | break; | ||
449 | #endif /* CONFIG_DCB */ | ||
450 | default: | ||
451 | hw_dbg(hw, "Flow control param set incorrectly\n"); | ||
452 | ret_val = IXGBE_ERR_CONFIG; | ||
453 | goto out; | ||
454 | break; | ||
455 | } | ||
456 | |||
457 | /* Set 802.3x based flow control settings. */ | ||
458 | fctrl_reg |= IXGBE_FCTRL_DPF; | ||
459 | IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl_reg); | ||
460 | IXGBE_WRITE_REG(hw, IXGBE_RMCS, rmcs_reg); | ||
461 | |||
462 | /* Set up and enable Rx high/low water mark thresholds, enable XON. */ | ||
463 | if (hw->fc.current_mode & ixgbe_fc_tx_pause) { | ||
464 | rx_pba_size = IXGBE_READ_REG(hw, IXGBE_RXPBSIZE(packetbuf_num)); | ||
465 | rx_pba_size >>= IXGBE_RXPBSIZE_SHIFT; | ||
466 | |||
467 | reg = (rx_pba_size - hw->fc.low_water) << 6; | ||
468 | if (hw->fc.send_xon) | ||
469 | reg |= IXGBE_FCRTL_XONE; | ||
470 | |||
471 | IXGBE_WRITE_REG(hw, IXGBE_FCRTL(packetbuf_num), reg); | ||
472 | |||
473 | reg = (rx_pba_size - hw->fc.high_water) << 6; | ||
474 | reg |= IXGBE_FCRTH_FCEN; | ||
475 | |||
476 | IXGBE_WRITE_REG(hw, IXGBE_FCRTH(packetbuf_num), reg); | ||
477 | } | ||
478 | |||
479 | /* Configure pause time (2 TCs per register) */ | ||
480 | reg = IXGBE_READ_REG(hw, IXGBE_FCTTV(packetbuf_num / 2)); | ||
481 | if ((packetbuf_num & 1) == 0) | ||
482 | reg = (reg & 0xFFFF0000) | hw->fc.pause_time; | ||
483 | else | ||
484 | reg = (reg & 0x0000FFFF) | (hw->fc.pause_time << 16); | ||
485 | IXGBE_WRITE_REG(hw, IXGBE_FCTTV(packetbuf_num / 2), reg); | ||
486 | |||
487 | IXGBE_WRITE_REG(hw, IXGBE_FCRTV, (hw->fc.pause_time >> 1)); | ||
488 | |||
489 | out: | ||
490 | return ret_val; | ||
491 | } | ||
492 | |||
493 | /** | ||
494 | * ixgbe_start_mac_link_82598 - Configures MAC link settings | ||
495 | * @hw: pointer to hardware structure | ||
496 | * | ||
497 | * Configures link settings based on values in the ixgbe_hw struct. | ||
498 | * Restarts the link. Performs autonegotiation if needed. | ||
499 | **/ | ||
500 | static s32 ixgbe_start_mac_link_82598(struct ixgbe_hw *hw, | ||
501 | bool autoneg_wait_to_complete) | ||
502 | { | ||
503 | u32 autoc_reg; | ||
504 | u32 links_reg; | ||
505 | u32 i; | ||
506 | s32 status = 0; | ||
507 | |||
508 | /* Restart link */ | ||
509 | autoc_reg = IXGBE_READ_REG(hw, IXGBE_AUTOC); | ||
510 | autoc_reg |= IXGBE_AUTOC_AN_RESTART; | ||
511 | IXGBE_WRITE_REG(hw, IXGBE_AUTOC, autoc_reg); | ||
512 | |||
513 | /* Only poll for autoneg to complete if specified to do so */ | ||
514 | if (autoneg_wait_to_complete) { | ||
515 | if ((autoc_reg & IXGBE_AUTOC_LMS_MASK) == | ||
516 | IXGBE_AUTOC_LMS_KX4_AN || | ||
517 | (autoc_reg & IXGBE_AUTOC_LMS_MASK) == | ||
518 | IXGBE_AUTOC_LMS_KX4_AN_1G_AN) { | ||
519 | links_reg = 0; /* Just in case Autoneg time = 0 */ | ||
520 | for (i = 0; i < IXGBE_AUTO_NEG_TIME; i++) { | ||
521 | links_reg = IXGBE_READ_REG(hw, IXGBE_LINKS); | ||
522 | if (links_reg & IXGBE_LINKS_KX_AN_COMP) | ||
523 | break; | ||
524 | msleep(100); | ||
525 | } | ||
526 | if (!(links_reg & IXGBE_LINKS_KX_AN_COMP)) { | ||
527 | status = IXGBE_ERR_AUTONEG_NOT_COMPLETE; | ||
528 | hw_dbg(hw, "Autonegotiation did not complete.\n"); | ||
529 | } | ||
530 | } | ||
531 | } | ||
532 | |||
533 | /* Add delay to filter out noises during initial link setup */ | ||
534 | msleep(50); | ||
535 | |||
536 | return status; | ||
537 | } | ||
538 | |||
539 | /** | ||
540 | * ixgbe_validate_link_ready - Function looks for phy link | ||
541 | * @hw: pointer to hardware structure | ||
542 | * | ||
543 | * Function indicates success when phy link is available. If phy is not ready | ||
544 | * within 5 seconds of MAC indicating link, the function returns error. | ||
545 | **/ | ||
546 | static s32 ixgbe_validate_link_ready(struct ixgbe_hw *hw) | ||
547 | { | ||
548 | u32 timeout; | ||
549 | u16 an_reg; | ||
550 | |||
551 | if (hw->device_id != IXGBE_DEV_ID_82598AT2) | ||
552 | return 0; | ||
553 | |||
554 | for (timeout = 0; | ||
555 | timeout < IXGBE_VALIDATE_LINK_READY_TIMEOUT; timeout++) { | ||
556 | hw->phy.ops.read_reg(hw, MDIO_STAT1, MDIO_MMD_AN, &an_reg); | ||
557 | |||
558 | if ((an_reg & MDIO_AN_STAT1_COMPLETE) && | ||
559 | (an_reg & MDIO_STAT1_LSTATUS)) | ||
560 | break; | ||
561 | |||
562 | msleep(100); | ||
563 | } | ||
564 | |||
565 | if (timeout == IXGBE_VALIDATE_LINK_READY_TIMEOUT) { | ||
566 | hw_dbg(hw, "Link was indicated but link is down\n"); | ||
567 | return IXGBE_ERR_LINK_SETUP; | ||
568 | } | ||
569 | |||
570 | return 0; | ||
571 | } | ||
572 | |||
573 | /** | ||
574 | * ixgbe_check_mac_link_82598 - Get link/speed status | ||
575 | * @hw: pointer to hardware structure | ||
576 | * @speed: pointer to link speed | ||
577 | * @link_up: true is link is up, false otherwise | ||
578 | * @link_up_wait_to_complete: bool used to wait for link up or not | ||
579 | * | ||
580 | * Reads the links register to determine if link is up and the current speed | ||
581 | **/ | ||
582 | static s32 ixgbe_check_mac_link_82598(struct ixgbe_hw *hw, | ||
583 | ixgbe_link_speed *speed, bool *link_up, | ||
584 | bool link_up_wait_to_complete) | ||
585 | { | ||
586 | u32 links_reg; | ||
587 | u32 i; | ||
588 | u16 link_reg, adapt_comp_reg; | ||
589 | |||
590 | /* | ||
591 | * SERDES PHY requires us to read link status from register 0xC79F. | ||
592 | * Bit 0 set indicates link is up/ready; clear indicates link down. | ||
593 | * 0xC00C is read to check that the XAUI lanes are active. Bit 0 | ||
594 | * clear indicates active; set indicates inactive. | ||
595 | */ | ||
596 | if (hw->phy.type == ixgbe_phy_nl) { | ||
597 | hw->phy.ops.read_reg(hw, 0xC79F, MDIO_MMD_PMAPMD, &link_reg); | ||
598 | hw->phy.ops.read_reg(hw, 0xC79F, MDIO_MMD_PMAPMD, &link_reg); | ||
599 | hw->phy.ops.read_reg(hw, 0xC00C, MDIO_MMD_PMAPMD, | ||
600 | &adapt_comp_reg); | ||
601 | if (link_up_wait_to_complete) { | ||
602 | for (i = 0; i < IXGBE_LINK_UP_TIME; i++) { | ||
603 | if ((link_reg & 1) && | ||
604 | ((adapt_comp_reg & 1) == 0)) { | ||
605 | *link_up = true; | ||
606 | break; | ||
607 | } else { | ||
608 | *link_up = false; | ||
609 | } | ||
610 | msleep(100); | ||
611 | hw->phy.ops.read_reg(hw, 0xC79F, | ||
612 | MDIO_MMD_PMAPMD, | ||
613 | &link_reg); | ||
614 | hw->phy.ops.read_reg(hw, 0xC00C, | ||
615 | MDIO_MMD_PMAPMD, | ||
616 | &adapt_comp_reg); | ||
617 | } | ||
618 | } else { | ||
619 | if ((link_reg & 1) && ((adapt_comp_reg & 1) == 0)) | ||
620 | *link_up = true; | ||
621 | else | ||
622 | *link_up = false; | ||
623 | } | ||
624 | |||
625 | if (*link_up == false) | ||
626 | goto out; | ||
627 | } | ||
628 | |||
629 | links_reg = IXGBE_READ_REG(hw, IXGBE_LINKS); | ||
630 | if (link_up_wait_to_complete) { | ||
631 | for (i = 0; i < IXGBE_LINK_UP_TIME; i++) { | ||
632 | if (links_reg & IXGBE_LINKS_UP) { | ||
633 | *link_up = true; | ||
634 | break; | ||
635 | } else { | ||
636 | *link_up = false; | ||
637 | } | ||
638 | msleep(100); | ||
639 | links_reg = IXGBE_READ_REG(hw, IXGBE_LINKS); | ||
640 | } | ||
641 | } else { | ||
642 | if (links_reg & IXGBE_LINKS_UP) | ||
643 | *link_up = true; | ||
644 | else | ||
645 | *link_up = false; | ||
646 | } | ||
647 | |||
648 | if (links_reg & IXGBE_LINKS_SPEED) | ||
649 | *speed = IXGBE_LINK_SPEED_10GB_FULL; | ||
650 | else | ||
651 | *speed = IXGBE_LINK_SPEED_1GB_FULL; | ||
652 | |||
653 | if ((hw->device_id == IXGBE_DEV_ID_82598AT2) && (*link_up == true) && | ||
654 | (ixgbe_validate_link_ready(hw) != 0)) | ||
655 | *link_up = false; | ||
656 | |||
657 | /* if link is down, zero out the current_mode */ | ||
658 | if (*link_up == false) { | ||
659 | hw->fc.current_mode = ixgbe_fc_none; | ||
660 | hw->fc.fc_was_autonegged = false; | ||
661 | } | ||
662 | out: | ||
663 | return 0; | ||
664 | } | ||
665 | |||
666 | /** | ||
667 | * ixgbe_setup_mac_link_82598 - Set MAC link speed | ||
668 | * @hw: pointer to hardware structure | ||
669 | * @speed: new link speed | ||
670 | * @autoneg: true if auto-negotiation enabled | ||
671 | * @autoneg_wait_to_complete: true when waiting for completion is needed | ||
672 | * | ||
673 | * Set the link speed in the AUTOC register and restarts link. | ||
674 | **/ | ||
675 | static s32 ixgbe_setup_mac_link_82598(struct ixgbe_hw *hw, | ||
676 | ixgbe_link_speed speed, bool autoneg, | ||
677 | bool autoneg_wait_to_complete) | ||
678 | { | ||
679 | s32 status = 0; | ||
680 | ixgbe_link_speed link_capabilities = IXGBE_LINK_SPEED_UNKNOWN; | ||
681 | u32 curr_autoc = IXGBE_READ_REG(hw, IXGBE_AUTOC); | ||
682 | u32 autoc = curr_autoc; | ||
683 | u32 link_mode = autoc & IXGBE_AUTOC_LMS_MASK; | ||
684 | |||
685 | /* Check to see if speed passed in is supported. */ | ||
686 | ixgbe_get_link_capabilities_82598(hw, &link_capabilities, &autoneg); | ||
687 | speed &= link_capabilities; | ||
688 | |||
689 | if (speed == IXGBE_LINK_SPEED_UNKNOWN) | ||
690 | status = IXGBE_ERR_LINK_SETUP; | ||
691 | |||
692 | /* Set KX4/KX support according to speed requested */ | ||
693 | else if (link_mode == IXGBE_AUTOC_LMS_KX4_AN || | ||
694 | link_mode == IXGBE_AUTOC_LMS_KX4_AN_1G_AN) { | ||
695 | autoc &= ~IXGBE_AUTOC_KX4_KX_SUPP_MASK; | ||
696 | if (speed & IXGBE_LINK_SPEED_10GB_FULL) | ||
697 | autoc |= IXGBE_AUTOC_KX4_SUPP; | ||
698 | if (speed & IXGBE_LINK_SPEED_1GB_FULL) | ||
699 | autoc |= IXGBE_AUTOC_KX_SUPP; | ||
700 | if (autoc != curr_autoc) | ||
701 | IXGBE_WRITE_REG(hw, IXGBE_AUTOC, autoc); | ||
702 | } | ||
703 | |||
704 | if (status == 0) { | ||
705 | /* | ||
706 | * Setup and restart the link based on the new values in | ||
707 | * ixgbe_hw This will write the AUTOC register based on the new | ||
708 | * stored values | ||
709 | */ | ||
710 | status = ixgbe_start_mac_link_82598(hw, | ||
711 | autoneg_wait_to_complete); | ||
712 | } | ||
713 | |||
714 | return status; | ||
715 | } | ||
716 | |||
717 | |||
718 | /** | ||
719 | * ixgbe_setup_copper_link_82598 - Set the PHY autoneg advertised field | ||
720 | * @hw: pointer to hardware structure | ||
721 | * @speed: new link speed | ||
722 | * @autoneg: true if autonegotiation enabled | ||
723 | * @autoneg_wait_to_complete: true if waiting is needed to complete | ||
724 | * | ||
725 | * Sets the link speed in the AUTOC register in the MAC and restarts link. | ||
726 | **/ | ||
727 | static s32 ixgbe_setup_copper_link_82598(struct ixgbe_hw *hw, | ||
728 | ixgbe_link_speed speed, | ||
729 | bool autoneg, | ||
730 | bool autoneg_wait_to_complete) | ||
731 | { | ||
732 | s32 status; | ||
733 | |||
734 | /* Setup the PHY according to input speed */ | ||
735 | status = hw->phy.ops.setup_link_speed(hw, speed, autoneg, | ||
736 | autoneg_wait_to_complete); | ||
737 | /* Set up MAC */ | ||
738 | ixgbe_start_mac_link_82598(hw, autoneg_wait_to_complete); | ||
739 | |||
740 | return status; | ||
741 | } | ||
742 | |||
743 | /** | ||
744 | * ixgbe_reset_hw_82598 - Performs hardware reset | ||
745 | * @hw: pointer to hardware structure | ||
746 | * | ||
747 | * Resets the hardware by resetting the transmit and receive units, masks and | ||
748 | * clears all interrupts, performing a PHY reset, and performing a link (MAC) | ||
749 | * reset. | ||
750 | **/ | ||
751 | static s32 ixgbe_reset_hw_82598(struct ixgbe_hw *hw) | ||
752 | { | ||
753 | s32 status = 0; | ||
754 | s32 phy_status = 0; | ||
755 | u32 ctrl; | ||
756 | u32 gheccr; | ||
757 | u32 i; | ||
758 | u32 autoc; | ||
759 | u8 analog_val; | ||
760 | |||
761 | /* Call adapter stop to disable tx/rx and clear interrupts */ | ||
762 | hw->mac.ops.stop_adapter(hw); | ||
763 | |||
764 | /* | ||
765 | * Power up the Atlas Tx lanes if they are currently powered down. | ||
766 | * Atlas Tx lanes are powered down for MAC loopback tests, but | ||
767 | * they are not automatically restored on reset. | ||
768 | */ | ||
769 | hw->mac.ops.read_analog_reg8(hw, IXGBE_ATLAS_PDN_LPBK, &analog_val); | ||
770 | if (analog_val & IXGBE_ATLAS_PDN_TX_REG_EN) { | ||
771 | /* Enable Tx Atlas so packets can be transmitted again */ | ||
772 | hw->mac.ops.read_analog_reg8(hw, IXGBE_ATLAS_PDN_LPBK, | ||
773 | &analog_val); | ||
774 | analog_val &= ~IXGBE_ATLAS_PDN_TX_REG_EN; | ||
775 | hw->mac.ops.write_analog_reg8(hw, IXGBE_ATLAS_PDN_LPBK, | ||
776 | analog_val); | ||
777 | |||
778 | hw->mac.ops.read_analog_reg8(hw, IXGBE_ATLAS_PDN_10G, | ||
779 | &analog_val); | ||
780 | analog_val &= ~IXGBE_ATLAS_PDN_TX_10G_QL_ALL; | ||
781 | hw->mac.ops.write_analog_reg8(hw, IXGBE_ATLAS_PDN_10G, | ||
782 | analog_val); | ||
783 | |||
784 | hw->mac.ops.read_analog_reg8(hw, IXGBE_ATLAS_PDN_1G, | ||
785 | &analog_val); | ||
786 | analog_val &= ~IXGBE_ATLAS_PDN_TX_1G_QL_ALL; | ||
787 | hw->mac.ops.write_analog_reg8(hw, IXGBE_ATLAS_PDN_1G, | ||
788 | analog_val); | ||
789 | |||
790 | hw->mac.ops.read_analog_reg8(hw, IXGBE_ATLAS_PDN_AN, | ||
791 | &analog_val); | ||
792 | analog_val &= ~IXGBE_ATLAS_PDN_TX_AN_QL_ALL; | ||
793 | hw->mac.ops.write_analog_reg8(hw, IXGBE_ATLAS_PDN_AN, | ||
794 | analog_val); | ||
795 | } | ||
796 | |||
797 | /* Reset PHY */ | ||
798 | if (hw->phy.reset_disable == false) { | ||
799 | /* PHY ops must be identified and initialized prior to reset */ | ||
800 | |||
801 | /* Init PHY and function pointers, perform SFP setup */ | ||
802 | phy_status = hw->phy.ops.init(hw); | ||
803 | if (phy_status == IXGBE_ERR_SFP_NOT_SUPPORTED) | ||
804 | goto reset_hw_out; | ||
805 | else if (phy_status == IXGBE_ERR_SFP_NOT_PRESENT) | ||
806 | goto no_phy_reset; | ||
807 | |||
808 | hw->phy.ops.reset(hw); | ||
809 | } | ||
810 | |||
811 | no_phy_reset: | ||
812 | /* | ||
813 | * Prevent the PCI-E bus from from hanging by disabling PCI-E master | ||
814 | * access and verify no pending requests before reset | ||
815 | */ | ||
816 | ixgbe_disable_pcie_master(hw); | ||
817 | |||
818 | mac_reset_top: | ||
819 | /* | ||
820 | * Issue global reset to the MAC. This needs to be a SW reset. | ||
821 | * If link reset is used, it might reset the MAC when mng is using it | ||
822 | */ | ||
823 | ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL); | ||
824 | IXGBE_WRITE_REG(hw, IXGBE_CTRL, (ctrl | IXGBE_CTRL_RST)); | ||
825 | IXGBE_WRITE_FLUSH(hw); | ||
826 | |||
827 | /* Poll for reset bit to self-clear indicating reset is complete */ | ||
828 | for (i = 0; i < 10; i++) { | ||
829 | udelay(1); | ||
830 | ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL); | ||
831 | if (!(ctrl & IXGBE_CTRL_RST)) | ||
832 | break; | ||
833 | } | ||
834 | if (ctrl & IXGBE_CTRL_RST) { | ||
835 | status = IXGBE_ERR_RESET_FAILED; | ||
836 | hw_dbg(hw, "Reset polling failed to complete.\n"); | ||
837 | } | ||
838 | |||
839 | /* | ||
840 | * Double resets are required for recovery from certain error | ||
841 | * conditions. Between resets, it is necessary to stall to allow time | ||
842 | * for any pending HW events to complete. We use 1usec since that is | ||
843 | * what is needed for ixgbe_disable_pcie_master(). The second reset | ||
844 | * then clears out any effects of those events. | ||
845 | */ | ||
846 | if (hw->mac.flags & IXGBE_FLAGS_DOUBLE_RESET_REQUIRED) { | ||
847 | hw->mac.flags &= ~IXGBE_FLAGS_DOUBLE_RESET_REQUIRED; | ||
848 | udelay(1); | ||
849 | goto mac_reset_top; | ||
850 | } | ||
851 | |||
852 | msleep(50); | ||
853 | |||
854 | gheccr = IXGBE_READ_REG(hw, IXGBE_GHECCR); | ||
855 | gheccr &= ~((1 << 21) | (1 << 18) | (1 << 9) | (1 << 6)); | ||
856 | IXGBE_WRITE_REG(hw, IXGBE_GHECCR, gheccr); | ||
857 | |||
858 | /* | ||
859 | * Store the original AUTOC value if it has not been | ||
860 | * stored off yet. Otherwise restore the stored original | ||
861 | * AUTOC value since the reset operation sets back to deaults. | ||
862 | */ | ||
863 | autoc = IXGBE_READ_REG(hw, IXGBE_AUTOC); | ||
864 | if (hw->mac.orig_link_settings_stored == false) { | ||
865 | hw->mac.orig_autoc = autoc; | ||
866 | hw->mac.orig_link_settings_stored = true; | ||
867 | } else if (autoc != hw->mac.orig_autoc) { | ||
868 | IXGBE_WRITE_REG(hw, IXGBE_AUTOC, hw->mac.orig_autoc); | ||
869 | } | ||
870 | |||
871 | /* Store the permanent mac address */ | ||
872 | hw->mac.ops.get_mac_addr(hw, hw->mac.perm_addr); | ||
873 | |||
874 | /* | ||
875 | * Store MAC address from RAR0, clear receive address registers, and | ||
876 | * clear the multicast table | ||
877 | */ | ||
878 | hw->mac.ops.init_rx_addrs(hw); | ||
879 | |||
880 | reset_hw_out: | ||
881 | if (phy_status) | ||
882 | status = phy_status; | ||
883 | |||
884 | return status; | ||
885 | } | ||
886 | |||
887 | /** | ||
888 | * ixgbe_set_vmdq_82598 - Associate a VMDq set index with a rx address | ||
889 | * @hw: pointer to hardware struct | ||
890 | * @rar: receive address register index to associate with a VMDq index | ||
891 | * @vmdq: VMDq set index | ||
892 | **/ | ||
893 | static s32 ixgbe_set_vmdq_82598(struct ixgbe_hw *hw, u32 rar, u32 vmdq) | ||
894 | { | ||
895 | u32 rar_high; | ||
896 | u32 rar_entries = hw->mac.num_rar_entries; | ||
897 | |||
898 | /* Make sure we are using a valid rar index range */ | ||
899 | if (rar >= rar_entries) { | ||
900 | hw_dbg(hw, "RAR index %d is out of range.\n", rar); | ||
901 | return IXGBE_ERR_INVALID_ARGUMENT; | ||
902 | } | ||
903 | |||
904 | rar_high = IXGBE_READ_REG(hw, IXGBE_RAH(rar)); | ||
905 | rar_high &= ~IXGBE_RAH_VIND_MASK; | ||
906 | rar_high |= ((vmdq << IXGBE_RAH_VIND_SHIFT) & IXGBE_RAH_VIND_MASK); | ||
907 | IXGBE_WRITE_REG(hw, IXGBE_RAH(rar), rar_high); | ||
908 | return 0; | ||
909 | } | ||
910 | |||
911 | /** | ||
912 | * ixgbe_clear_vmdq_82598 - Disassociate a VMDq set index from an rx address | ||
913 | * @hw: pointer to hardware struct | ||
914 | * @rar: receive address register index to associate with a VMDq index | ||
915 | * @vmdq: VMDq clear index (not used in 82598, but elsewhere) | ||
916 | **/ | ||
917 | static s32 ixgbe_clear_vmdq_82598(struct ixgbe_hw *hw, u32 rar, u32 vmdq) | ||
918 | { | ||
919 | u32 rar_high; | ||
920 | u32 rar_entries = hw->mac.num_rar_entries; | ||
921 | |||
922 | |||
923 | /* Make sure we are using a valid rar index range */ | ||
924 | if (rar >= rar_entries) { | ||
925 | hw_dbg(hw, "RAR index %d is out of range.\n", rar); | ||
926 | return IXGBE_ERR_INVALID_ARGUMENT; | ||
927 | } | ||
928 | |||
929 | rar_high = IXGBE_READ_REG(hw, IXGBE_RAH(rar)); | ||
930 | if (rar_high & IXGBE_RAH_VIND_MASK) { | ||
931 | rar_high &= ~IXGBE_RAH_VIND_MASK; | ||
932 | IXGBE_WRITE_REG(hw, IXGBE_RAH(rar), rar_high); | ||
933 | } | ||
934 | |||
935 | return 0; | ||
936 | } | ||
937 | |||
938 | /** | ||
939 | * ixgbe_set_vfta_82598 - Set VLAN filter table | ||
940 | * @hw: pointer to hardware structure | ||
941 | * @vlan: VLAN id to write to VLAN filter | ||
942 | * @vind: VMDq output index that maps queue to VLAN id in VFTA | ||
943 | * @vlan_on: boolean flag to turn on/off VLAN in VFTA | ||
944 | * | ||
945 | * Turn on/off specified VLAN in the VLAN filter table. | ||
946 | **/ | ||
947 | static s32 ixgbe_set_vfta_82598(struct ixgbe_hw *hw, u32 vlan, u32 vind, | ||
948 | bool vlan_on) | ||
949 | { | ||
950 | u32 regindex; | ||
951 | u32 bitindex; | ||
952 | u32 bits; | ||
953 | u32 vftabyte; | ||
954 | |||
955 | if (vlan > 4095) | ||
956 | return IXGBE_ERR_PARAM; | ||
957 | |||
958 | /* Determine 32-bit word position in array */ | ||
959 | regindex = (vlan >> 5) & 0x7F; /* upper seven bits */ | ||
960 | |||
961 | /* Determine the location of the (VMD) queue index */ | ||
962 | vftabyte = ((vlan >> 3) & 0x03); /* bits (4:3) indicating byte array */ | ||
963 | bitindex = (vlan & 0x7) << 2; /* lower 3 bits indicate nibble */ | ||
964 | |||
965 | /* Set the nibble for VMD queue index */ | ||
966 | bits = IXGBE_READ_REG(hw, IXGBE_VFTAVIND(vftabyte, regindex)); | ||
967 | bits &= (~(0x0F << bitindex)); | ||
968 | bits |= (vind << bitindex); | ||
969 | IXGBE_WRITE_REG(hw, IXGBE_VFTAVIND(vftabyte, regindex), bits); | ||
970 | |||
971 | /* Determine the location of the bit for this VLAN id */ | ||
972 | bitindex = vlan & 0x1F; /* lower five bits */ | ||
973 | |||
974 | bits = IXGBE_READ_REG(hw, IXGBE_VFTA(regindex)); | ||
975 | if (vlan_on) | ||
976 | /* Turn on this VLAN id */ | ||
977 | bits |= (1 << bitindex); | ||
978 | else | ||
979 | /* Turn off this VLAN id */ | ||
980 | bits &= ~(1 << bitindex); | ||
981 | IXGBE_WRITE_REG(hw, IXGBE_VFTA(regindex), bits); | ||
982 | |||
983 | return 0; | ||
984 | } | ||
985 | |||
986 | /** | ||
987 | * ixgbe_clear_vfta_82598 - Clear VLAN filter table | ||
988 | * @hw: pointer to hardware structure | ||
989 | * | ||
990 | * Clears the VLAN filer table, and the VMDq index associated with the filter | ||
991 | **/ | ||
992 | static s32 ixgbe_clear_vfta_82598(struct ixgbe_hw *hw) | ||
993 | { | ||
994 | u32 offset; | ||
995 | u32 vlanbyte; | ||
996 | |||
997 | for (offset = 0; offset < hw->mac.vft_size; offset++) | ||
998 | IXGBE_WRITE_REG(hw, IXGBE_VFTA(offset), 0); | ||
999 | |||
1000 | for (vlanbyte = 0; vlanbyte < 4; vlanbyte++) | ||
1001 | for (offset = 0; offset < hw->mac.vft_size; offset++) | ||
1002 | IXGBE_WRITE_REG(hw, IXGBE_VFTAVIND(vlanbyte, offset), | ||
1003 | 0); | ||
1004 | |||
1005 | return 0; | ||
1006 | } | ||
1007 | |||
1008 | /** | ||
1009 | * ixgbe_read_analog_reg8_82598 - Reads 8 bit Atlas analog register | ||
1010 | * @hw: pointer to hardware structure | ||
1011 | * @reg: analog register to read | ||
1012 | * @val: read value | ||
1013 | * | ||
1014 | * Performs read operation to Atlas analog register specified. | ||
1015 | **/ | ||
1016 | static s32 ixgbe_read_analog_reg8_82598(struct ixgbe_hw *hw, u32 reg, u8 *val) | ||
1017 | { | ||
1018 | u32 atlas_ctl; | ||
1019 | |||
1020 | IXGBE_WRITE_REG(hw, IXGBE_ATLASCTL, | ||
1021 | IXGBE_ATLASCTL_WRITE_CMD | (reg << 8)); | ||
1022 | IXGBE_WRITE_FLUSH(hw); | ||
1023 | udelay(10); | ||
1024 | atlas_ctl = IXGBE_READ_REG(hw, IXGBE_ATLASCTL); | ||
1025 | *val = (u8)atlas_ctl; | ||
1026 | |||
1027 | return 0; | ||
1028 | } | ||
1029 | |||
1030 | /** | ||
1031 | * ixgbe_write_analog_reg8_82598 - Writes 8 bit Atlas analog register | ||
1032 | * @hw: pointer to hardware structure | ||
1033 | * @reg: atlas register to write | ||
1034 | * @val: value to write | ||
1035 | * | ||
1036 | * Performs write operation to Atlas analog register specified. | ||
1037 | **/ | ||
1038 | static s32 ixgbe_write_analog_reg8_82598(struct ixgbe_hw *hw, u32 reg, u8 val) | ||
1039 | { | ||
1040 | u32 atlas_ctl; | ||
1041 | |||
1042 | atlas_ctl = (reg << 8) | val; | ||
1043 | IXGBE_WRITE_REG(hw, IXGBE_ATLASCTL, atlas_ctl); | ||
1044 | IXGBE_WRITE_FLUSH(hw); | ||
1045 | udelay(10); | ||
1046 | |||
1047 | return 0; | ||
1048 | } | ||
1049 | |||
1050 | /** | ||
1051 | * ixgbe_read_i2c_eeprom_82598 - Reads 8 bit word over I2C interface. | ||
1052 | * @hw: pointer to hardware structure | ||
1053 | * @byte_offset: EEPROM byte offset to read | ||
1054 | * @eeprom_data: value read | ||
1055 | * | ||
1056 | * Performs 8 byte read operation to SFP module's EEPROM over I2C interface. | ||
1057 | **/ | ||
1058 | static s32 ixgbe_read_i2c_eeprom_82598(struct ixgbe_hw *hw, u8 byte_offset, | ||
1059 | u8 *eeprom_data) | ||
1060 | { | ||
1061 | s32 status = 0; | ||
1062 | u16 sfp_addr = 0; | ||
1063 | u16 sfp_data = 0; | ||
1064 | u16 sfp_stat = 0; | ||
1065 | u32 i; | ||
1066 | |||
1067 | if (hw->phy.type == ixgbe_phy_nl) { | ||
1068 | /* | ||
1069 | * phy SDA/SCL registers are at addresses 0xC30A to | ||
1070 | * 0xC30D. These registers are used to talk to the SFP+ | ||
1071 | * module's EEPROM through the SDA/SCL (I2C) interface. | ||
1072 | */ | ||
1073 | sfp_addr = (IXGBE_I2C_EEPROM_DEV_ADDR << 8) + byte_offset; | ||
1074 | sfp_addr = (sfp_addr | IXGBE_I2C_EEPROM_READ_MASK); | ||
1075 | hw->phy.ops.write_reg(hw, | ||
1076 | IXGBE_MDIO_PMA_PMD_SDA_SCL_ADDR, | ||
1077 | MDIO_MMD_PMAPMD, | ||
1078 | sfp_addr); | ||
1079 | |||
1080 | /* Poll status */ | ||
1081 | for (i = 0; i < 100; i++) { | ||
1082 | hw->phy.ops.read_reg(hw, | ||
1083 | IXGBE_MDIO_PMA_PMD_SDA_SCL_STAT, | ||
1084 | MDIO_MMD_PMAPMD, | ||
1085 | &sfp_stat); | ||
1086 | sfp_stat = sfp_stat & IXGBE_I2C_EEPROM_STATUS_MASK; | ||
1087 | if (sfp_stat != IXGBE_I2C_EEPROM_STATUS_IN_PROGRESS) | ||
1088 | break; | ||
1089 | usleep_range(10000, 20000); | ||
1090 | } | ||
1091 | |||
1092 | if (sfp_stat != IXGBE_I2C_EEPROM_STATUS_PASS) { | ||
1093 | hw_dbg(hw, "EEPROM read did not pass.\n"); | ||
1094 | status = IXGBE_ERR_SFP_NOT_PRESENT; | ||
1095 | goto out; | ||
1096 | } | ||
1097 | |||
1098 | /* Read data */ | ||
1099 | hw->phy.ops.read_reg(hw, IXGBE_MDIO_PMA_PMD_SDA_SCL_DATA, | ||
1100 | MDIO_MMD_PMAPMD, &sfp_data); | ||
1101 | |||
1102 | *eeprom_data = (u8)(sfp_data >> 8); | ||
1103 | } else { | ||
1104 | status = IXGBE_ERR_PHY; | ||
1105 | goto out; | ||
1106 | } | ||
1107 | |||
1108 | out: | ||
1109 | return status; | ||
1110 | } | ||
1111 | |||
1112 | /** | ||
1113 | * ixgbe_get_supported_physical_layer_82598 - Returns physical layer type | ||
1114 | * @hw: pointer to hardware structure | ||
1115 | * | ||
1116 | * Determines physical layer capabilities of the current configuration. | ||
1117 | **/ | ||
1118 | static u32 ixgbe_get_supported_physical_layer_82598(struct ixgbe_hw *hw) | ||
1119 | { | ||
1120 | u32 physical_layer = IXGBE_PHYSICAL_LAYER_UNKNOWN; | ||
1121 | u32 autoc = IXGBE_READ_REG(hw, IXGBE_AUTOC); | ||
1122 | u32 pma_pmd_10g = autoc & IXGBE_AUTOC_10G_PMA_PMD_MASK; | ||
1123 | u32 pma_pmd_1g = autoc & IXGBE_AUTOC_1G_PMA_PMD_MASK; | ||
1124 | u16 ext_ability = 0; | ||
1125 | |||
1126 | hw->phy.ops.identify(hw); | ||
1127 | |||
1128 | /* Copper PHY must be checked before AUTOC LMS to determine correct | ||
1129 | * physical layer because 10GBase-T PHYs use LMS = KX4/KX */ | ||
1130 | switch (hw->phy.type) { | ||
1131 | case ixgbe_phy_tn: | ||
1132 | case ixgbe_phy_aq: | ||
1133 | case ixgbe_phy_cu_unknown: | ||
1134 | hw->phy.ops.read_reg(hw, MDIO_PMA_EXTABLE, | ||
1135 | MDIO_MMD_PMAPMD, &ext_ability); | ||
1136 | if (ext_ability & MDIO_PMA_EXTABLE_10GBT) | ||
1137 | physical_layer |= IXGBE_PHYSICAL_LAYER_10GBASE_T; | ||
1138 | if (ext_ability & MDIO_PMA_EXTABLE_1000BT) | ||
1139 | physical_layer |= IXGBE_PHYSICAL_LAYER_1000BASE_T; | ||
1140 | if (ext_ability & MDIO_PMA_EXTABLE_100BTX) | ||
1141 | physical_layer |= IXGBE_PHYSICAL_LAYER_100BASE_TX; | ||
1142 | goto out; | ||
1143 | default: | ||
1144 | break; | ||
1145 | } | ||
1146 | |||
1147 | switch (autoc & IXGBE_AUTOC_LMS_MASK) { | ||
1148 | case IXGBE_AUTOC_LMS_1G_AN: | ||
1149 | case IXGBE_AUTOC_LMS_1G_LINK_NO_AN: | ||
1150 | if (pma_pmd_1g == IXGBE_AUTOC_1G_KX) | ||
1151 | physical_layer = IXGBE_PHYSICAL_LAYER_1000BASE_KX; | ||
1152 | else | ||
1153 | physical_layer = IXGBE_PHYSICAL_LAYER_1000BASE_BX; | ||
1154 | break; | ||
1155 | case IXGBE_AUTOC_LMS_10G_LINK_NO_AN: | ||
1156 | if (pma_pmd_10g == IXGBE_AUTOC_10G_CX4) | ||
1157 | physical_layer = IXGBE_PHYSICAL_LAYER_10GBASE_CX4; | ||
1158 | else if (pma_pmd_10g == IXGBE_AUTOC_10G_KX4) | ||
1159 | physical_layer = IXGBE_PHYSICAL_LAYER_10GBASE_KX4; | ||
1160 | else /* XAUI */ | ||
1161 | physical_layer = IXGBE_PHYSICAL_LAYER_UNKNOWN; | ||
1162 | break; | ||
1163 | case IXGBE_AUTOC_LMS_KX4_AN: | ||
1164 | case IXGBE_AUTOC_LMS_KX4_AN_1G_AN: | ||
1165 | if (autoc & IXGBE_AUTOC_KX_SUPP) | ||
1166 | physical_layer |= IXGBE_PHYSICAL_LAYER_1000BASE_KX; | ||
1167 | if (autoc & IXGBE_AUTOC_KX4_SUPP) | ||
1168 | physical_layer |= IXGBE_PHYSICAL_LAYER_10GBASE_KX4; | ||
1169 | break; | ||
1170 | default: | ||
1171 | break; | ||
1172 | } | ||
1173 | |||
1174 | if (hw->phy.type == ixgbe_phy_nl) { | ||
1175 | hw->phy.ops.identify_sfp(hw); | ||
1176 | |||
1177 | switch (hw->phy.sfp_type) { | ||
1178 | case ixgbe_sfp_type_da_cu: | ||
1179 | physical_layer = IXGBE_PHYSICAL_LAYER_SFP_PLUS_CU; | ||
1180 | break; | ||
1181 | case ixgbe_sfp_type_sr: | ||
1182 | physical_layer = IXGBE_PHYSICAL_LAYER_10GBASE_SR; | ||
1183 | break; | ||
1184 | case ixgbe_sfp_type_lr: | ||
1185 | physical_layer = IXGBE_PHYSICAL_LAYER_10GBASE_LR; | ||
1186 | break; | ||
1187 | default: | ||
1188 | physical_layer = IXGBE_PHYSICAL_LAYER_UNKNOWN; | ||
1189 | break; | ||
1190 | } | ||
1191 | } | ||
1192 | |||
1193 | switch (hw->device_id) { | ||
1194 | case IXGBE_DEV_ID_82598_DA_DUAL_PORT: | ||
1195 | physical_layer = IXGBE_PHYSICAL_LAYER_SFP_PLUS_CU; | ||
1196 | break; | ||
1197 | case IXGBE_DEV_ID_82598AF_DUAL_PORT: | ||
1198 | case IXGBE_DEV_ID_82598AF_SINGLE_PORT: | ||
1199 | case IXGBE_DEV_ID_82598_SR_DUAL_PORT_EM: | ||
1200 | physical_layer = IXGBE_PHYSICAL_LAYER_10GBASE_SR; | ||
1201 | break; | ||
1202 | case IXGBE_DEV_ID_82598EB_XF_LR: | ||
1203 | physical_layer = IXGBE_PHYSICAL_LAYER_10GBASE_LR; | ||
1204 | break; | ||
1205 | default: | ||
1206 | break; | ||
1207 | } | ||
1208 | |||
1209 | out: | ||
1210 | return physical_layer; | ||
1211 | } | ||
1212 | |||
1213 | /** | ||
1214 | * ixgbe_set_lan_id_multi_port_pcie_82598 - Set LAN id for PCIe multiple | ||
1215 | * port devices. | ||
1216 | * @hw: pointer to the HW structure | ||
1217 | * | ||
1218 | * Calls common function and corrects issue with some single port devices | ||
1219 | * that enable LAN1 but not LAN0. | ||
1220 | **/ | ||
1221 | static void ixgbe_set_lan_id_multi_port_pcie_82598(struct ixgbe_hw *hw) | ||
1222 | { | ||
1223 | struct ixgbe_bus_info *bus = &hw->bus; | ||
1224 | u16 pci_gen = 0; | ||
1225 | u16 pci_ctrl2 = 0; | ||
1226 | |||
1227 | ixgbe_set_lan_id_multi_port_pcie(hw); | ||
1228 | |||
1229 | /* check if LAN0 is disabled */ | ||
1230 | hw->eeprom.ops.read(hw, IXGBE_PCIE_GENERAL_PTR, &pci_gen); | ||
1231 | if ((pci_gen != 0) && (pci_gen != 0xFFFF)) { | ||
1232 | |||
1233 | hw->eeprom.ops.read(hw, pci_gen + IXGBE_PCIE_CTRL2, &pci_ctrl2); | ||
1234 | |||
1235 | /* if LAN0 is completely disabled force function to 0 */ | ||
1236 | if ((pci_ctrl2 & IXGBE_PCIE_CTRL2_LAN_DISABLE) && | ||
1237 | !(pci_ctrl2 & IXGBE_PCIE_CTRL2_DISABLE_SELECT) && | ||
1238 | !(pci_ctrl2 & IXGBE_PCIE_CTRL2_DUMMY_ENABLE)) { | ||
1239 | |||
1240 | bus->func = 0; | ||
1241 | } | ||
1242 | } | ||
1243 | } | ||
1244 | |||
1245 | /** | ||
1246 | * ixgbe_set_rxpba_82598 - Configure packet buffers | ||
1247 | * @hw: pointer to hardware structure | ||
1248 | * @dcb_config: pointer to ixgbe_dcb_config structure | ||
1249 | * | ||
1250 | * Configure packet buffers. | ||
1251 | */ | ||
1252 | static void ixgbe_set_rxpba_82598(struct ixgbe_hw *hw, int num_pb, u32 headroom, | ||
1253 | int strategy) | ||
1254 | { | ||
1255 | u32 rxpktsize = IXGBE_RXPBSIZE_64KB; | ||
1256 | u8 i = 0; | ||
1257 | |||
1258 | if (!num_pb) | ||
1259 | return; | ||
1260 | |||
1261 | /* Setup Rx packet buffer sizes */ | ||
1262 | switch (strategy) { | ||
1263 | case PBA_STRATEGY_WEIGHTED: | ||
1264 | /* Setup the first four at 80KB */ | ||
1265 | rxpktsize = IXGBE_RXPBSIZE_80KB; | ||
1266 | for (; i < 4; i++) | ||
1267 | IXGBE_WRITE_REG(hw, IXGBE_RXPBSIZE(i), rxpktsize); | ||
1268 | /* Setup the last four at 48KB...don't re-init i */ | ||
1269 | rxpktsize = IXGBE_RXPBSIZE_48KB; | ||
1270 | /* Fall Through */ | ||
1271 | case PBA_STRATEGY_EQUAL: | ||
1272 | default: | ||
1273 | /* Divide the remaining Rx packet buffer evenly among the TCs */ | ||
1274 | for (; i < IXGBE_MAX_PACKET_BUFFERS; i++) | ||
1275 | IXGBE_WRITE_REG(hw, IXGBE_RXPBSIZE(i), rxpktsize); | ||
1276 | break; | ||
1277 | } | ||
1278 | |||
1279 | /* Setup Tx packet buffer sizes */ | ||
1280 | for (i = 0; i < IXGBE_MAX_PACKET_BUFFERS; i++) | ||
1281 | IXGBE_WRITE_REG(hw, IXGBE_TXPBSIZE(i), IXGBE_TXPBSIZE_40KB); | ||
1282 | |||
1283 | return; | ||
1284 | } | ||
1285 | |||
1286 | static struct ixgbe_mac_operations mac_ops_82598 = { | ||
1287 | .init_hw = &ixgbe_init_hw_generic, | ||
1288 | .reset_hw = &ixgbe_reset_hw_82598, | ||
1289 | .start_hw = &ixgbe_start_hw_82598, | ||
1290 | .clear_hw_cntrs = &ixgbe_clear_hw_cntrs_generic, | ||
1291 | .get_media_type = &ixgbe_get_media_type_82598, | ||
1292 | .get_supported_physical_layer = &ixgbe_get_supported_physical_layer_82598, | ||
1293 | .enable_rx_dma = &ixgbe_enable_rx_dma_generic, | ||
1294 | .get_mac_addr = &ixgbe_get_mac_addr_generic, | ||
1295 | .stop_adapter = &ixgbe_stop_adapter_generic, | ||
1296 | .get_bus_info = &ixgbe_get_bus_info_generic, | ||
1297 | .set_lan_id = &ixgbe_set_lan_id_multi_port_pcie_82598, | ||
1298 | .read_analog_reg8 = &ixgbe_read_analog_reg8_82598, | ||
1299 | .write_analog_reg8 = &ixgbe_write_analog_reg8_82598, | ||
1300 | .setup_link = &ixgbe_setup_mac_link_82598, | ||
1301 | .set_rxpba = &ixgbe_set_rxpba_82598, | ||
1302 | .check_link = &ixgbe_check_mac_link_82598, | ||
1303 | .get_link_capabilities = &ixgbe_get_link_capabilities_82598, | ||
1304 | .led_on = &ixgbe_led_on_generic, | ||
1305 | .led_off = &ixgbe_led_off_generic, | ||
1306 | .blink_led_start = &ixgbe_blink_led_start_generic, | ||
1307 | .blink_led_stop = &ixgbe_blink_led_stop_generic, | ||
1308 | .set_rar = &ixgbe_set_rar_generic, | ||
1309 | .clear_rar = &ixgbe_clear_rar_generic, | ||
1310 | .set_vmdq = &ixgbe_set_vmdq_82598, | ||
1311 | .clear_vmdq = &ixgbe_clear_vmdq_82598, | ||
1312 | .init_rx_addrs = &ixgbe_init_rx_addrs_generic, | ||
1313 | .update_mc_addr_list = &ixgbe_update_mc_addr_list_generic, | ||
1314 | .enable_mc = &ixgbe_enable_mc_generic, | ||
1315 | .disable_mc = &ixgbe_disable_mc_generic, | ||
1316 | .clear_vfta = &ixgbe_clear_vfta_82598, | ||
1317 | .set_vfta = &ixgbe_set_vfta_82598, | ||
1318 | .fc_enable = &ixgbe_fc_enable_82598, | ||
1319 | .set_fw_drv_ver = NULL, | ||
1320 | .acquire_swfw_sync = &ixgbe_acquire_swfw_sync, | ||
1321 | .release_swfw_sync = &ixgbe_release_swfw_sync, | ||
1322 | }; | ||
1323 | |||
1324 | static struct ixgbe_eeprom_operations eeprom_ops_82598 = { | ||
1325 | .init_params = &ixgbe_init_eeprom_params_generic, | ||
1326 | .read = &ixgbe_read_eerd_generic, | ||
1327 | .read_buffer = &ixgbe_read_eerd_buffer_generic, | ||
1328 | .calc_checksum = &ixgbe_calc_eeprom_checksum_generic, | ||
1329 | .validate_checksum = &ixgbe_validate_eeprom_checksum_generic, | ||
1330 | .update_checksum = &ixgbe_update_eeprom_checksum_generic, | ||
1331 | }; | ||
1332 | |||
1333 | static struct ixgbe_phy_operations phy_ops_82598 = { | ||
1334 | .identify = &ixgbe_identify_phy_generic, | ||
1335 | .identify_sfp = &ixgbe_identify_sfp_module_generic, | ||
1336 | .init = &ixgbe_init_phy_ops_82598, | ||
1337 | .reset = &ixgbe_reset_phy_generic, | ||
1338 | .read_reg = &ixgbe_read_phy_reg_generic, | ||
1339 | .write_reg = &ixgbe_write_phy_reg_generic, | ||
1340 | .setup_link = &ixgbe_setup_phy_link_generic, | ||
1341 | .setup_link_speed = &ixgbe_setup_phy_link_speed_generic, | ||
1342 | .read_i2c_eeprom = &ixgbe_read_i2c_eeprom_82598, | ||
1343 | .check_overtemp = &ixgbe_tn_check_overtemp, | ||
1344 | }; | ||
1345 | |||
1346 | struct ixgbe_info ixgbe_82598_info = { | ||
1347 | .mac = ixgbe_mac_82598EB, | ||
1348 | .get_invariants = &ixgbe_get_invariants_82598, | ||
1349 | .mac_ops = &mac_ops_82598, | ||
1350 | .eeprom_ops = &eeprom_ops_82598, | ||
1351 | .phy_ops = &phy_ops_82598, | ||
1352 | }; | ||
1353 | |||
diff --git a/drivers/net/ixgbe/ixgbe_82599.c b/drivers/net/ixgbe/ixgbe_82599.c new file mode 100644 index 00000000000..34f30ec79c2 --- /dev/null +++ b/drivers/net/ixgbe/ixgbe_82599.c | |||
@@ -0,0 +1,2263 @@ | |||
1 | /******************************************************************************* | ||
2 | |||
3 | Intel 10 Gigabit PCI Express Linux driver | ||
4 | Copyright(c) 1999 - 2011 Intel Corporation. | ||
5 | |||
6 | This program is free software; you can redistribute it and/or modify it | ||
7 | under the terms and conditions of the GNU General Public License, | ||
8 | version 2, as published by the Free Software Foundation. | ||
9 | |||
10 | This program is distributed in the hope it will be useful, but WITHOUT | ||
11 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
12 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
13 | more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License along with | ||
16 | this program; if not, write to the Free Software Foundation, Inc., | ||
17 | 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. | ||
18 | |||
19 | The full GNU General Public License is included in this distribution in | ||
20 | the file called "COPYING". | ||
21 | |||
22 | Contact Information: | ||
23 | e1000-devel Mailing List <e1000-devel@lists.sourceforge.net> | ||
24 | Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 | ||
25 | |||
26 | *******************************************************************************/ | ||
27 | |||
28 | #include <linux/pci.h> | ||
29 | #include <linux/delay.h> | ||
30 | #include <linux/sched.h> | ||
31 | |||
32 | #include "ixgbe.h" | ||
33 | #include "ixgbe_phy.h" | ||
34 | #include "ixgbe_mbx.h" | ||
35 | |||
36 | #define IXGBE_82599_MAX_TX_QUEUES 128 | ||
37 | #define IXGBE_82599_MAX_RX_QUEUES 128 | ||
38 | #define IXGBE_82599_RAR_ENTRIES 128 | ||
39 | #define IXGBE_82599_MC_TBL_SIZE 128 | ||
40 | #define IXGBE_82599_VFT_TBL_SIZE 128 | ||
41 | #define IXGBE_82599_RX_PB_SIZE 512 | ||
42 | |||
43 | static void ixgbe_disable_tx_laser_multispeed_fiber(struct ixgbe_hw *hw); | ||
44 | static void ixgbe_enable_tx_laser_multispeed_fiber(struct ixgbe_hw *hw); | ||
45 | static void ixgbe_flap_tx_laser_multispeed_fiber(struct ixgbe_hw *hw); | ||
46 | static s32 ixgbe_setup_mac_link_multispeed_fiber(struct ixgbe_hw *hw, | ||
47 | ixgbe_link_speed speed, | ||
48 | bool autoneg, | ||
49 | bool autoneg_wait_to_complete); | ||
50 | static s32 ixgbe_setup_mac_link_smartspeed(struct ixgbe_hw *hw, | ||
51 | ixgbe_link_speed speed, | ||
52 | bool autoneg, | ||
53 | bool autoneg_wait_to_complete); | ||
54 | static s32 ixgbe_start_mac_link_82599(struct ixgbe_hw *hw, | ||
55 | bool autoneg_wait_to_complete); | ||
56 | static s32 ixgbe_setup_mac_link_82599(struct ixgbe_hw *hw, | ||
57 | ixgbe_link_speed speed, | ||
58 | bool autoneg, | ||
59 | bool autoneg_wait_to_complete); | ||
60 | static s32 ixgbe_setup_copper_link_82599(struct ixgbe_hw *hw, | ||
61 | ixgbe_link_speed speed, | ||
62 | bool autoneg, | ||
63 | bool autoneg_wait_to_complete); | ||
64 | static s32 ixgbe_verify_fw_version_82599(struct ixgbe_hw *hw); | ||
65 | static bool ixgbe_verify_lesm_fw_enabled_82599(struct ixgbe_hw *hw); | ||
66 | |||
67 | static void ixgbe_init_mac_link_ops_82599(struct ixgbe_hw *hw) | ||
68 | { | ||
69 | struct ixgbe_mac_info *mac = &hw->mac; | ||
70 | |||
71 | /* enable the laser control functions for SFP+ fiber */ | ||
72 | if (mac->ops.get_media_type(hw) == ixgbe_media_type_fiber) { | ||
73 | mac->ops.disable_tx_laser = | ||
74 | &ixgbe_disable_tx_laser_multispeed_fiber; | ||
75 | mac->ops.enable_tx_laser = | ||
76 | &ixgbe_enable_tx_laser_multispeed_fiber; | ||
77 | mac->ops.flap_tx_laser = &ixgbe_flap_tx_laser_multispeed_fiber; | ||
78 | } else { | ||
79 | mac->ops.disable_tx_laser = NULL; | ||
80 | mac->ops.enable_tx_laser = NULL; | ||
81 | mac->ops.flap_tx_laser = NULL; | ||
82 | } | ||
83 | |||
84 | if (hw->phy.multispeed_fiber) { | ||
85 | /* Set up dual speed SFP+ support */ | ||
86 | mac->ops.setup_link = &ixgbe_setup_mac_link_multispeed_fiber; | ||
87 | } else { | ||
88 | if ((mac->ops.get_media_type(hw) == | ||
89 | ixgbe_media_type_backplane) && | ||
90 | (hw->phy.smart_speed == ixgbe_smart_speed_auto || | ||
91 | hw->phy.smart_speed == ixgbe_smart_speed_on) && | ||
92 | !ixgbe_verify_lesm_fw_enabled_82599(hw)) | ||
93 | mac->ops.setup_link = &ixgbe_setup_mac_link_smartspeed; | ||
94 | else | ||
95 | mac->ops.setup_link = &ixgbe_setup_mac_link_82599; | ||
96 | } | ||
97 | } | ||
98 | |||
99 | static s32 ixgbe_setup_sfp_modules_82599(struct ixgbe_hw *hw) | ||
100 | { | ||
101 | s32 ret_val = 0; | ||
102 | u32 reg_anlp1 = 0; | ||
103 | u32 i = 0; | ||
104 | u16 list_offset, data_offset, data_value; | ||
105 | |||
106 | if (hw->phy.sfp_type != ixgbe_sfp_type_unknown) { | ||
107 | ixgbe_init_mac_link_ops_82599(hw); | ||
108 | |||
109 | hw->phy.ops.reset = NULL; | ||
110 | |||
111 | ret_val = ixgbe_get_sfp_init_sequence_offsets(hw, &list_offset, | ||
112 | &data_offset); | ||
113 | if (ret_val != 0) | ||
114 | goto setup_sfp_out; | ||
115 | |||
116 | /* PHY config will finish before releasing the semaphore */ | ||
117 | ret_val = hw->mac.ops.acquire_swfw_sync(hw, | ||
118 | IXGBE_GSSR_MAC_CSR_SM); | ||
119 | if (ret_val != 0) { | ||
120 | ret_val = IXGBE_ERR_SWFW_SYNC; | ||
121 | goto setup_sfp_out; | ||
122 | } | ||
123 | |||
124 | hw->eeprom.ops.read(hw, ++data_offset, &data_value); | ||
125 | while (data_value != 0xffff) { | ||
126 | IXGBE_WRITE_REG(hw, IXGBE_CORECTL, data_value); | ||
127 | IXGBE_WRITE_FLUSH(hw); | ||
128 | hw->eeprom.ops.read(hw, ++data_offset, &data_value); | ||
129 | } | ||
130 | |||
131 | /* Release the semaphore */ | ||
132 | hw->mac.ops.release_swfw_sync(hw, IXGBE_GSSR_MAC_CSR_SM); | ||
133 | /* | ||
134 | * Delay obtaining semaphore again to allow FW access, | ||
135 | * semaphore_delay is in ms usleep_range needs us. | ||
136 | */ | ||
137 | usleep_range(hw->eeprom.semaphore_delay * 1000, | ||
138 | hw->eeprom.semaphore_delay * 2000); | ||
139 | |||
140 | /* Now restart DSP by setting Restart_AN and clearing LMS */ | ||
141 | IXGBE_WRITE_REG(hw, IXGBE_AUTOC, ((IXGBE_READ_REG(hw, | ||
142 | IXGBE_AUTOC) & ~IXGBE_AUTOC_LMS_MASK) | | ||
143 | IXGBE_AUTOC_AN_RESTART)); | ||
144 | |||
145 | /* Wait for AN to leave state 0 */ | ||
146 | for (i = 0; i < 10; i++) { | ||
147 | usleep_range(4000, 8000); | ||
148 | reg_anlp1 = IXGBE_READ_REG(hw, IXGBE_ANLP1); | ||
149 | if (reg_anlp1 & IXGBE_ANLP1_AN_STATE_MASK) | ||
150 | break; | ||
151 | } | ||
152 | if (!(reg_anlp1 & IXGBE_ANLP1_AN_STATE_MASK)) { | ||
153 | hw_dbg(hw, "sfp module setup not complete\n"); | ||
154 | ret_val = IXGBE_ERR_SFP_SETUP_NOT_COMPLETE; | ||
155 | goto setup_sfp_out; | ||
156 | } | ||
157 | |||
158 | /* Restart DSP by setting Restart_AN and return to SFI mode */ | ||
159 | IXGBE_WRITE_REG(hw, IXGBE_AUTOC, (IXGBE_READ_REG(hw, | ||
160 | IXGBE_AUTOC) | IXGBE_AUTOC_LMS_10G_SERIAL | | ||
161 | IXGBE_AUTOC_AN_RESTART)); | ||
162 | } | ||
163 | |||
164 | setup_sfp_out: | ||
165 | return ret_val; | ||
166 | } | ||
167 | |||
168 | static s32 ixgbe_get_invariants_82599(struct ixgbe_hw *hw) | ||
169 | { | ||
170 | struct ixgbe_mac_info *mac = &hw->mac; | ||
171 | |||
172 | ixgbe_init_mac_link_ops_82599(hw); | ||
173 | |||
174 | mac->mcft_size = IXGBE_82599_MC_TBL_SIZE; | ||
175 | mac->vft_size = IXGBE_82599_VFT_TBL_SIZE; | ||
176 | mac->num_rar_entries = IXGBE_82599_RAR_ENTRIES; | ||
177 | mac->max_rx_queues = IXGBE_82599_MAX_RX_QUEUES; | ||
178 | mac->max_tx_queues = IXGBE_82599_MAX_TX_QUEUES; | ||
179 | mac->max_msix_vectors = ixgbe_get_pcie_msix_count_generic(hw); | ||
180 | |||
181 | return 0; | ||
182 | } | ||
183 | |||
184 | /** | ||
185 | * ixgbe_init_phy_ops_82599 - PHY/SFP specific init | ||
186 | * @hw: pointer to hardware structure | ||
187 | * | ||
188 | * Initialize any function pointers that were not able to be | ||
189 | * set during get_invariants because the PHY/SFP type was | ||
190 | * not known. Perform the SFP init if necessary. | ||
191 | * | ||
192 | **/ | ||
193 | static s32 ixgbe_init_phy_ops_82599(struct ixgbe_hw *hw) | ||
194 | { | ||
195 | struct ixgbe_mac_info *mac = &hw->mac; | ||
196 | struct ixgbe_phy_info *phy = &hw->phy; | ||
197 | s32 ret_val = 0; | ||
198 | |||
199 | /* Identify the PHY or SFP module */ | ||
200 | ret_val = phy->ops.identify(hw); | ||
201 | |||
202 | /* Setup function pointers based on detected SFP module and speeds */ | ||
203 | ixgbe_init_mac_link_ops_82599(hw); | ||
204 | |||
205 | /* If copper media, overwrite with copper function pointers */ | ||
206 | if (mac->ops.get_media_type(hw) == ixgbe_media_type_copper) { | ||
207 | mac->ops.setup_link = &ixgbe_setup_copper_link_82599; | ||
208 | mac->ops.get_link_capabilities = | ||
209 | &ixgbe_get_copper_link_capabilities_generic; | ||
210 | } | ||
211 | |||
212 | /* Set necessary function pointers based on phy type */ | ||
213 | switch (hw->phy.type) { | ||
214 | case ixgbe_phy_tn: | ||
215 | phy->ops.check_link = &ixgbe_check_phy_link_tnx; | ||
216 | phy->ops.setup_link = &ixgbe_setup_phy_link_tnx; | ||
217 | phy->ops.get_firmware_version = | ||
218 | &ixgbe_get_phy_firmware_version_tnx; | ||
219 | break; | ||
220 | case ixgbe_phy_aq: | ||
221 | phy->ops.get_firmware_version = | ||
222 | &ixgbe_get_phy_firmware_version_generic; | ||
223 | break; | ||
224 | default: | ||
225 | break; | ||
226 | } | ||
227 | |||
228 | return ret_val; | ||
229 | } | ||
230 | |||
231 | /** | ||
232 | * ixgbe_get_link_capabilities_82599 - Determines link capabilities | ||
233 | * @hw: pointer to hardware structure | ||
234 | * @speed: pointer to link speed | ||
235 | * @negotiation: true when autoneg or autotry is enabled | ||
236 | * | ||
237 | * Determines the link capabilities by reading the AUTOC register. | ||
238 | **/ | ||
239 | static s32 ixgbe_get_link_capabilities_82599(struct ixgbe_hw *hw, | ||
240 | ixgbe_link_speed *speed, | ||
241 | bool *negotiation) | ||
242 | { | ||
243 | s32 status = 0; | ||
244 | u32 autoc = 0; | ||
245 | |||
246 | /* Determine 1G link capabilities off of SFP+ type */ | ||
247 | if (hw->phy.sfp_type == ixgbe_sfp_type_1g_cu_core0 || | ||
248 | hw->phy.sfp_type == ixgbe_sfp_type_1g_cu_core1) { | ||
249 | *speed = IXGBE_LINK_SPEED_1GB_FULL; | ||
250 | *negotiation = true; | ||
251 | goto out; | ||
252 | } | ||
253 | |||
254 | /* | ||
255 | * Determine link capabilities based on the stored value of AUTOC, | ||
256 | * which represents EEPROM defaults. If AUTOC value has not been | ||
257 | * stored, use the current register value. | ||
258 | */ | ||
259 | if (hw->mac.orig_link_settings_stored) | ||
260 | autoc = hw->mac.orig_autoc; | ||
261 | else | ||
262 | autoc = IXGBE_READ_REG(hw, IXGBE_AUTOC); | ||
263 | |||
264 | switch (autoc & IXGBE_AUTOC_LMS_MASK) { | ||
265 | case IXGBE_AUTOC_LMS_1G_LINK_NO_AN: | ||
266 | *speed = IXGBE_LINK_SPEED_1GB_FULL; | ||
267 | *negotiation = false; | ||
268 | break; | ||
269 | |||
270 | case IXGBE_AUTOC_LMS_10G_LINK_NO_AN: | ||
271 | *speed = IXGBE_LINK_SPEED_10GB_FULL; | ||
272 | *negotiation = false; | ||
273 | break; | ||
274 | |||
275 | case IXGBE_AUTOC_LMS_1G_AN: | ||
276 | *speed = IXGBE_LINK_SPEED_1GB_FULL; | ||
277 | *negotiation = true; | ||
278 | break; | ||
279 | |||
280 | case IXGBE_AUTOC_LMS_10G_SERIAL: | ||
281 | *speed = IXGBE_LINK_SPEED_10GB_FULL; | ||
282 | *negotiation = false; | ||
283 | break; | ||
284 | |||
285 | case IXGBE_AUTOC_LMS_KX4_KX_KR: | ||
286 | case IXGBE_AUTOC_LMS_KX4_KX_KR_1G_AN: | ||
287 | *speed = IXGBE_LINK_SPEED_UNKNOWN; | ||
288 | if (autoc & IXGBE_AUTOC_KR_SUPP) | ||
289 | *speed |= IXGBE_LINK_SPEED_10GB_FULL; | ||
290 | if (autoc & IXGBE_AUTOC_KX4_SUPP) | ||
291 | *speed |= IXGBE_LINK_SPEED_10GB_FULL; | ||
292 | if (autoc & IXGBE_AUTOC_KX_SUPP) | ||
293 | *speed |= IXGBE_LINK_SPEED_1GB_FULL; | ||
294 | *negotiation = true; | ||
295 | break; | ||
296 | |||
297 | case IXGBE_AUTOC_LMS_KX4_KX_KR_SGMII: | ||
298 | *speed = IXGBE_LINK_SPEED_100_FULL; | ||
299 | if (autoc & IXGBE_AUTOC_KR_SUPP) | ||
300 | *speed |= IXGBE_LINK_SPEED_10GB_FULL; | ||
301 | if (autoc & IXGBE_AUTOC_KX4_SUPP) | ||
302 | *speed |= IXGBE_LINK_SPEED_10GB_FULL; | ||
303 | if (autoc & IXGBE_AUTOC_KX_SUPP) | ||
304 | *speed |= IXGBE_LINK_SPEED_1GB_FULL; | ||
305 | *negotiation = true; | ||
306 | break; | ||
307 | |||
308 | case IXGBE_AUTOC_LMS_SGMII_1G_100M: | ||
309 | *speed = IXGBE_LINK_SPEED_1GB_FULL | IXGBE_LINK_SPEED_100_FULL; | ||
310 | *negotiation = false; | ||
311 | break; | ||
312 | |||
313 | default: | ||
314 | status = IXGBE_ERR_LINK_SETUP; | ||
315 | goto out; | ||
316 | break; | ||
317 | } | ||
318 | |||
319 | if (hw->phy.multispeed_fiber) { | ||
320 | *speed |= IXGBE_LINK_SPEED_10GB_FULL | | ||
321 | IXGBE_LINK_SPEED_1GB_FULL; | ||
322 | *negotiation = true; | ||
323 | } | ||
324 | |||
325 | out: | ||
326 | return status; | ||
327 | } | ||
328 | |||
329 | /** | ||
330 | * ixgbe_get_media_type_82599 - Get media type | ||
331 | * @hw: pointer to hardware structure | ||
332 | * | ||
333 | * Returns the media type (fiber, copper, backplane) | ||
334 | **/ | ||
335 | static enum ixgbe_media_type ixgbe_get_media_type_82599(struct ixgbe_hw *hw) | ||
336 | { | ||
337 | enum ixgbe_media_type media_type; | ||
338 | |||
339 | /* Detect if there is a copper PHY attached. */ | ||
340 | switch (hw->phy.type) { | ||
341 | case ixgbe_phy_cu_unknown: | ||
342 | case ixgbe_phy_tn: | ||
343 | case ixgbe_phy_aq: | ||
344 | media_type = ixgbe_media_type_copper; | ||
345 | goto out; | ||
346 | default: | ||
347 | break; | ||
348 | } | ||
349 | |||
350 | switch (hw->device_id) { | ||
351 | case IXGBE_DEV_ID_82599_KX4: | ||
352 | case IXGBE_DEV_ID_82599_KX4_MEZZ: | ||
353 | case IXGBE_DEV_ID_82599_COMBO_BACKPLANE: | ||
354 | case IXGBE_DEV_ID_82599_KR: | ||
355 | case IXGBE_DEV_ID_82599_BACKPLANE_FCOE: | ||
356 | case IXGBE_DEV_ID_82599_XAUI_LOM: | ||
357 | /* Default device ID is mezzanine card KX/KX4 */ | ||
358 | media_type = ixgbe_media_type_backplane; | ||
359 | break; | ||
360 | case IXGBE_DEV_ID_82599_SFP: | ||
361 | case IXGBE_DEV_ID_82599_SFP_FCOE: | ||
362 | case IXGBE_DEV_ID_82599_SFP_EM: | ||
363 | case IXGBE_DEV_ID_82599_SFP_SF2: | ||
364 | media_type = ixgbe_media_type_fiber; | ||
365 | break; | ||
366 | case IXGBE_DEV_ID_82599_CX4: | ||
367 | media_type = ixgbe_media_type_cx4; | ||
368 | break; | ||
369 | case IXGBE_DEV_ID_82599_T3_LOM: | ||
370 | media_type = ixgbe_media_type_copper; | ||
371 | break; | ||
372 | case IXGBE_DEV_ID_82599_LS: | ||
373 | media_type = ixgbe_media_type_fiber_lco; | ||
374 | break; | ||
375 | default: | ||
376 | media_type = ixgbe_media_type_unknown; | ||
377 | break; | ||
378 | } | ||
379 | out: | ||
380 | return media_type; | ||
381 | } | ||
382 | |||
383 | /** | ||
384 | * ixgbe_start_mac_link_82599 - Setup MAC link settings | ||
385 | * @hw: pointer to hardware structure | ||
386 | * @autoneg_wait_to_complete: true when waiting for completion is needed | ||
387 | * | ||
388 | * Configures link settings based on values in the ixgbe_hw struct. | ||
389 | * Restarts the link. Performs autonegotiation if needed. | ||
390 | **/ | ||
391 | static s32 ixgbe_start_mac_link_82599(struct ixgbe_hw *hw, | ||
392 | bool autoneg_wait_to_complete) | ||
393 | { | ||
394 | u32 autoc_reg; | ||
395 | u32 links_reg; | ||
396 | u32 i; | ||
397 | s32 status = 0; | ||
398 | |||
399 | /* Restart link */ | ||
400 | autoc_reg = IXGBE_READ_REG(hw, IXGBE_AUTOC); | ||
401 | autoc_reg |= IXGBE_AUTOC_AN_RESTART; | ||
402 | IXGBE_WRITE_REG(hw, IXGBE_AUTOC, autoc_reg); | ||
403 | |||
404 | /* Only poll for autoneg to complete if specified to do so */ | ||
405 | if (autoneg_wait_to_complete) { | ||
406 | if ((autoc_reg & IXGBE_AUTOC_LMS_MASK) == | ||
407 | IXGBE_AUTOC_LMS_KX4_KX_KR || | ||
408 | (autoc_reg & IXGBE_AUTOC_LMS_MASK) == | ||
409 | IXGBE_AUTOC_LMS_KX4_KX_KR_1G_AN || | ||
410 | (autoc_reg & IXGBE_AUTOC_LMS_MASK) == | ||
411 | IXGBE_AUTOC_LMS_KX4_KX_KR_SGMII) { | ||
412 | links_reg = 0; /* Just in case Autoneg time = 0 */ | ||
413 | for (i = 0; i < IXGBE_AUTO_NEG_TIME; i++) { | ||
414 | links_reg = IXGBE_READ_REG(hw, IXGBE_LINKS); | ||
415 | if (links_reg & IXGBE_LINKS_KX_AN_COMP) | ||
416 | break; | ||
417 | msleep(100); | ||
418 | } | ||
419 | if (!(links_reg & IXGBE_LINKS_KX_AN_COMP)) { | ||
420 | status = IXGBE_ERR_AUTONEG_NOT_COMPLETE; | ||
421 | hw_dbg(hw, "Autoneg did not complete.\n"); | ||
422 | } | ||
423 | } | ||
424 | } | ||
425 | |||
426 | /* Add delay to filter out noises during initial link setup */ | ||
427 | msleep(50); | ||
428 | |||
429 | return status; | ||
430 | } | ||
431 | |||
432 | /** | ||
433 | * ixgbe_disable_tx_laser_multispeed_fiber - Disable Tx laser | ||
434 | * @hw: pointer to hardware structure | ||
435 | * | ||
436 | * The base drivers may require better control over SFP+ module | ||
437 | * PHY states. This includes selectively shutting down the Tx | ||
438 | * laser on the PHY, effectively halting physical link. | ||
439 | **/ | ||
440 | static void ixgbe_disable_tx_laser_multispeed_fiber(struct ixgbe_hw *hw) | ||
441 | { | ||
442 | u32 esdp_reg = IXGBE_READ_REG(hw, IXGBE_ESDP); | ||
443 | |||
444 | /* Disable tx laser; allow 100us to go dark per spec */ | ||
445 | esdp_reg |= IXGBE_ESDP_SDP3; | ||
446 | IXGBE_WRITE_REG(hw, IXGBE_ESDP, esdp_reg); | ||
447 | IXGBE_WRITE_FLUSH(hw); | ||
448 | udelay(100); | ||
449 | } | ||
450 | |||
451 | /** | ||
452 | * ixgbe_enable_tx_laser_multispeed_fiber - Enable Tx laser | ||
453 | * @hw: pointer to hardware structure | ||
454 | * | ||
455 | * The base drivers may require better control over SFP+ module | ||
456 | * PHY states. This includes selectively turning on the Tx | ||
457 | * laser on the PHY, effectively starting physical link. | ||
458 | **/ | ||
459 | static void ixgbe_enable_tx_laser_multispeed_fiber(struct ixgbe_hw *hw) | ||
460 | { | ||
461 | u32 esdp_reg = IXGBE_READ_REG(hw, IXGBE_ESDP); | ||
462 | |||
463 | /* Enable tx laser; allow 100ms to light up */ | ||
464 | esdp_reg &= ~IXGBE_ESDP_SDP3; | ||
465 | IXGBE_WRITE_REG(hw, IXGBE_ESDP, esdp_reg); | ||
466 | IXGBE_WRITE_FLUSH(hw); | ||
467 | msleep(100); | ||
468 | } | ||
469 | |||
470 | /** | ||
471 | * ixgbe_flap_tx_laser_multispeed_fiber - Flap Tx laser | ||
472 | * @hw: pointer to hardware structure | ||
473 | * | ||
474 | * When the driver changes the link speeds that it can support, | ||
475 | * it sets autotry_restart to true to indicate that we need to | ||
476 | * initiate a new autotry session with the link partner. To do | ||
477 | * so, we set the speed then disable and re-enable the tx laser, to | ||
478 | * alert the link partner that it also needs to restart autotry on its | ||
479 | * end. This is consistent with true clause 37 autoneg, which also | ||
480 | * involves a loss of signal. | ||
481 | **/ | ||
482 | static void ixgbe_flap_tx_laser_multispeed_fiber(struct ixgbe_hw *hw) | ||
483 | { | ||
484 | if (hw->mac.autotry_restart) { | ||
485 | ixgbe_disable_tx_laser_multispeed_fiber(hw); | ||
486 | ixgbe_enable_tx_laser_multispeed_fiber(hw); | ||
487 | hw->mac.autotry_restart = false; | ||
488 | } | ||
489 | } | ||
490 | |||
491 | /** | ||
492 | * ixgbe_setup_mac_link_multispeed_fiber - Set MAC link speed | ||
493 | * @hw: pointer to hardware structure | ||
494 | * @speed: new link speed | ||
495 | * @autoneg: true if autonegotiation enabled | ||
496 | * @autoneg_wait_to_complete: true when waiting for completion is needed | ||
497 | * | ||
498 | * Set the link speed in the AUTOC register and restarts link. | ||
499 | **/ | ||
500 | static s32 ixgbe_setup_mac_link_multispeed_fiber(struct ixgbe_hw *hw, | ||
501 | ixgbe_link_speed speed, | ||
502 | bool autoneg, | ||
503 | bool autoneg_wait_to_complete) | ||
504 | { | ||
505 | s32 status = 0; | ||
506 | ixgbe_link_speed link_speed = IXGBE_LINK_SPEED_UNKNOWN; | ||
507 | ixgbe_link_speed highest_link_speed = IXGBE_LINK_SPEED_UNKNOWN; | ||
508 | u32 speedcnt = 0; | ||
509 | u32 esdp_reg = IXGBE_READ_REG(hw, IXGBE_ESDP); | ||
510 | u32 i = 0; | ||
511 | bool link_up = false; | ||
512 | bool negotiation; | ||
513 | |||
514 | /* Mask off requested but non-supported speeds */ | ||
515 | status = hw->mac.ops.get_link_capabilities(hw, &link_speed, | ||
516 | &negotiation); | ||
517 | if (status != 0) | ||
518 | return status; | ||
519 | |||
520 | speed &= link_speed; | ||
521 | |||
522 | /* | ||
523 | * Try each speed one by one, highest priority first. We do this in | ||
524 | * software because 10gb fiber doesn't support speed autonegotiation. | ||
525 | */ | ||
526 | if (speed & IXGBE_LINK_SPEED_10GB_FULL) { | ||
527 | speedcnt++; | ||
528 | highest_link_speed = IXGBE_LINK_SPEED_10GB_FULL; | ||
529 | |||
530 | /* If we already have link at this speed, just jump out */ | ||
531 | status = hw->mac.ops.check_link(hw, &link_speed, &link_up, | ||
532 | false); | ||
533 | if (status != 0) | ||
534 | return status; | ||
535 | |||
536 | if ((link_speed == IXGBE_LINK_SPEED_10GB_FULL) && link_up) | ||
537 | goto out; | ||
538 | |||
539 | /* Set the module link speed */ | ||
540 | esdp_reg |= (IXGBE_ESDP_SDP5_DIR | IXGBE_ESDP_SDP5); | ||
541 | IXGBE_WRITE_REG(hw, IXGBE_ESDP, esdp_reg); | ||
542 | IXGBE_WRITE_FLUSH(hw); | ||
543 | |||
544 | /* Allow module to change analog characteristics (1G->10G) */ | ||
545 | msleep(40); | ||
546 | |||
547 | status = ixgbe_setup_mac_link_82599(hw, | ||
548 | IXGBE_LINK_SPEED_10GB_FULL, | ||
549 | autoneg, | ||
550 | autoneg_wait_to_complete); | ||
551 | if (status != 0) | ||
552 | return status; | ||
553 | |||
554 | /* Flap the tx laser if it has not already been done */ | ||
555 | hw->mac.ops.flap_tx_laser(hw); | ||
556 | |||
557 | /* | ||
558 | * Wait for the controller to acquire link. Per IEEE 802.3ap, | ||
559 | * Section 73.10.2, we may have to wait up to 500ms if KR is | ||
560 | * attempted. 82599 uses the same timing for 10g SFI. | ||
561 | */ | ||
562 | for (i = 0; i < 5; i++) { | ||
563 | /* Wait for the link partner to also set speed */ | ||
564 | msleep(100); | ||
565 | |||
566 | /* If we have link, just jump out */ | ||
567 | status = hw->mac.ops.check_link(hw, &link_speed, | ||
568 | &link_up, false); | ||
569 | if (status != 0) | ||
570 | return status; | ||
571 | |||
572 | if (link_up) | ||
573 | goto out; | ||
574 | } | ||
575 | } | ||
576 | |||
577 | if (speed & IXGBE_LINK_SPEED_1GB_FULL) { | ||
578 | speedcnt++; | ||
579 | if (highest_link_speed == IXGBE_LINK_SPEED_UNKNOWN) | ||
580 | highest_link_speed = IXGBE_LINK_SPEED_1GB_FULL; | ||
581 | |||
582 | /* If we already have link at this speed, just jump out */ | ||
583 | status = hw->mac.ops.check_link(hw, &link_speed, &link_up, | ||
584 | false); | ||
585 | if (status != 0) | ||
586 | return status; | ||
587 | |||
588 | if ((link_speed == IXGBE_LINK_SPEED_1GB_FULL) && link_up) | ||
589 | goto out; | ||
590 | |||
591 | /* Set the module link speed */ | ||
592 | esdp_reg &= ~IXGBE_ESDP_SDP5; | ||
593 | esdp_reg |= IXGBE_ESDP_SDP5_DIR; | ||
594 | IXGBE_WRITE_REG(hw, IXGBE_ESDP, esdp_reg); | ||
595 | IXGBE_WRITE_FLUSH(hw); | ||
596 | |||
597 | /* Allow module to change analog characteristics (10G->1G) */ | ||
598 | msleep(40); | ||
599 | |||
600 | status = ixgbe_setup_mac_link_82599(hw, | ||
601 | IXGBE_LINK_SPEED_1GB_FULL, | ||
602 | autoneg, | ||
603 | autoneg_wait_to_complete); | ||
604 | if (status != 0) | ||
605 | return status; | ||
606 | |||
607 | /* Flap the tx laser if it has not already been done */ | ||
608 | hw->mac.ops.flap_tx_laser(hw); | ||
609 | |||
610 | /* Wait for the link partner to also set speed */ | ||
611 | msleep(100); | ||
612 | |||
613 | /* If we have link, just jump out */ | ||
614 | status = hw->mac.ops.check_link(hw, &link_speed, &link_up, | ||
615 | false); | ||
616 | if (status != 0) | ||
617 | return status; | ||
618 | |||
619 | if (link_up) | ||
620 | goto out; | ||
621 | } | ||
622 | |||
623 | /* | ||
624 | * We didn't get link. Configure back to the highest speed we tried, | ||
625 | * (if there was more than one). We call ourselves back with just the | ||
626 | * single highest speed that the user requested. | ||
627 | */ | ||
628 | if (speedcnt > 1) | ||
629 | status = ixgbe_setup_mac_link_multispeed_fiber(hw, | ||
630 | highest_link_speed, | ||
631 | autoneg, | ||
632 | autoneg_wait_to_complete); | ||
633 | |||
634 | out: | ||
635 | /* Set autoneg_advertised value based on input link speed */ | ||
636 | hw->phy.autoneg_advertised = 0; | ||
637 | |||
638 | if (speed & IXGBE_LINK_SPEED_10GB_FULL) | ||
639 | hw->phy.autoneg_advertised |= IXGBE_LINK_SPEED_10GB_FULL; | ||
640 | |||
641 | if (speed & IXGBE_LINK_SPEED_1GB_FULL) | ||
642 | hw->phy.autoneg_advertised |= IXGBE_LINK_SPEED_1GB_FULL; | ||
643 | |||
644 | return status; | ||
645 | } | ||
646 | |||
647 | /** | ||
648 | * ixgbe_setup_mac_link_smartspeed - Set MAC link speed using SmartSpeed | ||
649 | * @hw: pointer to hardware structure | ||
650 | * @speed: new link speed | ||
651 | * @autoneg: true if autonegotiation enabled | ||
652 | * @autoneg_wait_to_complete: true when waiting for completion is needed | ||
653 | * | ||
654 | * Implements the Intel SmartSpeed algorithm. | ||
655 | **/ | ||
656 | static s32 ixgbe_setup_mac_link_smartspeed(struct ixgbe_hw *hw, | ||
657 | ixgbe_link_speed speed, bool autoneg, | ||
658 | bool autoneg_wait_to_complete) | ||
659 | { | ||
660 | s32 status = 0; | ||
661 | ixgbe_link_speed link_speed = IXGBE_LINK_SPEED_UNKNOWN; | ||
662 | s32 i, j; | ||
663 | bool link_up = false; | ||
664 | u32 autoc_reg = IXGBE_READ_REG(hw, IXGBE_AUTOC); | ||
665 | |||
666 | /* Set autoneg_advertised value based on input link speed */ | ||
667 | hw->phy.autoneg_advertised = 0; | ||
668 | |||
669 | if (speed & IXGBE_LINK_SPEED_10GB_FULL) | ||
670 | hw->phy.autoneg_advertised |= IXGBE_LINK_SPEED_10GB_FULL; | ||
671 | |||
672 | if (speed & IXGBE_LINK_SPEED_1GB_FULL) | ||
673 | hw->phy.autoneg_advertised |= IXGBE_LINK_SPEED_1GB_FULL; | ||
674 | |||
675 | if (speed & IXGBE_LINK_SPEED_100_FULL) | ||
676 | hw->phy.autoneg_advertised |= IXGBE_LINK_SPEED_100_FULL; | ||
677 | |||
678 | /* | ||
679 | * Implement Intel SmartSpeed algorithm. SmartSpeed will reduce the | ||
680 | * autoneg advertisement if link is unable to be established at the | ||
681 | * highest negotiated rate. This can sometimes happen due to integrity | ||
682 | * issues with the physical media connection. | ||
683 | */ | ||
684 | |||
685 | /* First, try to get link with full advertisement */ | ||
686 | hw->phy.smart_speed_active = false; | ||
687 | for (j = 0; j < IXGBE_SMARTSPEED_MAX_RETRIES; j++) { | ||
688 | status = ixgbe_setup_mac_link_82599(hw, speed, autoneg, | ||
689 | autoneg_wait_to_complete); | ||
690 | if (status != 0) | ||
691 | goto out; | ||
692 | |||
693 | /* | ||
694 | * Wait for the controller to acquire link. Per IEEE 802.3ap, | ||
695 | * Section 73.10.2, we may have to wait up to 500ms if KR is | ||
696 | * attempted, or 200ms if KX/KX4/BX/BX4 is attempted, per | ||
697 | * Table 9 in the AN MAS. | ||
698 | */ | ||
699 | for (i = 0; i < 5; i++) { | ||
700 | mdelay(100); | ||
701 | |||
702 | /* If we have link, just jump out */ | ||
703 | status = hw->mac.ops.check_link(hw, &link_speed, | ||
704 | &link_up, false); | ||
705 | if (status != 0) | ||
706 | goto out; | ||
707 | |||
708 | if (link_up) | ||
709 | goto out; | ||
710 | } | ||
711 | } | ||
712 | |||
713 | /* | ||
714 | * We didn't get link. If we advertised KR plus one of KX4/KX | ||
715 | * (or BX4/BX), then disable KR and try again. | ||
716 | */ | ||
717 | if (((autoc_reg & IXGBE_AUTOC_KR_SUPP) == 0) || | ||
718 | ((autoc_reg & IXGBE_AUTOC_KX4_KX_SUPP_MASK) == 0)) | ||
719 | goto out; | ||
720 | |||
721 | /* Turn SmartSpeed on to disable KR support */ | ||
722 | hw->phy.smart_speed_active = true; | ||
723 | status = ixgbe_setup_mac_link_82599(hw, speed, autoneg, | ||
724 | autoneg_wait_to_complete); | ||
725 | if (status != 0) | ||
726 | goto out; | ||
727 | |||
728 | /* | ||
729 | * Wait for the controller to acquire link. 600ms will allow for | ||
730 | * the AN link_fail_inhibit_timer as well for multiple cycles of | ||
731 | * parallel detect, both 10g and 1g. This allows for the maximum | ||
732 | * connect attempts as defined in the AN MAS table 73-7. | ||
733 | */ | ||
734 | for (i = 0; i < 6; i++) { | ||
735 | mdelay(100); | ||
736 | |||
737 | /* If we have link, just jump out */ | ||
738 | status = hw->mac.ops.check_link(hw, &link_speed, | ||
739 | &link_up, false); | ||
740 | if (status != 0) | ||
741 | goto out; | ||
742 | |||
743 | if (link_up) | ||
744 | goto out; | ||
745 | } | ||
746 | |||
747 | /* We didn't get link. Turn SmartSpeed back off. */ | ||
748 | hw->phy.smart_speed_active = false; | ||
749 | status = ixgbe_setup_mac_link_82599(hw, speed, autoneg, | ||
750 | autoneg_wait_to_complete); | ||
751 | |||
752 | out: | ||
753 | if (link_up && (link_speed == IXGBE_LINK_SPEED_1GB_FULL)) | ||
754 | hw_dbg(hw, "Smartspeed has downgraded the link speed from " | ||
755 | "the maximum advertised\n"); | ||
756 | return status; | ||
757 | } | ||
758 | |||
759 | /** | ||
760 | * ixgbe_setup_mac_link_82599 - Set MAC link speed | ||
761 | * @hw: pointer to hardware structure | ||
762 | * @speed: new link speed | ||
763 | * @autoneg: true if autonegotiation enabled | ||
764 | * @autoneg_wait_to_complete: true when waiting for completion is needed | ||
765 | * | ||
766 | * Set the link speed in the AUTOC register and restarts link. | ||
767 | **/ | ||
768 | static s32 ixgbe_setup_mac_link_82599(struct ixgbe_hw *hw, | ||
769 | ixgbe_link_speed speed, bool autoneg, | ||
770 | bool autoneg_wait_to_complete) | ||
771 | { | ||
772 | s32 status = 0; | ||
773 | u32 autoc = IXGBE_READ_REG(hw, IXGBE_AUTOC); | ||
774 | u32 autoc2 = IXGBE_READ_REG(hw, IXGBE_AUTOC2); | ||
775 | u32 start_autoc = autoc; | ||
776 | u32 orig_autoc = 0; | ||
777 | u32 link_mode = autoc & IXGBE_AUTOC_LMS_MASK; | ||
778 | u32 pma_pmd_1g = autoc & IXGBE_AUTOC_1G_PMA_PMD_MASK; | ||
779 | u32 pma_pmd_10g_serial = autoc2 & IXGBE_AUTOC2_10G_SERIAL_PMA_PMD_MASK; | ||
780 | u32 links_reg; | ||
781 | u32 i; | ||
782 | ixgbe_link_speed link_capabilities = IXGBE_LINK_SPEED_UNKNOWN; | ||
783 | |||
784 | /* Check to see if speed passed in is supported. */ | ||
785 | hw->mac.ops.get_link_capabilities(hw, &link_capabilities, &autoneg); | ||
786 | if (status != 0) | ||
787 | goto out; | ||
788 | |||
789 | speed &= link_capabilities; | ||
790 | |||
791 | if (speed == IXGBE_LINK_SPEED_UNKNOWN) { | ||
792 | status = IXGBE_ERR_LINK_SETUP; | ||
793 | goto out; | ||
794 | } | ||
795 | |||
796 | /* Use stored value (EEPROM defaults) of AUTOC to find KR/KX4 support*/ | ||
797 | if (hw->mac.orig_link_settings_stored) | ||
798 | orig_autoc = hw->mac.orig_autoc; | ||
799 | else | ||
800 | orig_autoc = autoc; | ||
801 | |||
802 | if (link_mode == IXGBE_AUTOC_LMS_KX4_KX_KR || | ||
803 | link_mode == IXGBE_AUTOC_LMS_KX4_KX_KR_1G_AN || | ||
804 | link_mode == IXGBE_AUTOC_LMS_KX4_KX_KR_SGMII) { | ||
805 | /* Set KX4/KX/KR support according to speed requested */ | ||
806 | autoc &= ~(IXGBE_AUTOC_KX4_KX_SUPP_MASK | IXGBE_AUTOC_KR_SUPP); | ||
807 | if (speed & IXGBE_LINK_SPEED_10GB_FULL) | ||
808 | if (orig_autoc & IXGBE_AUTOC_KX4_SUPP) | ||
809 | autoc |= IXGBE_AUTOC_KX4_SUPP; | ||
810 | if ((orig_autoc & IXGBE_AUTOC_KR_SUPP) && | ||
811 | (hw->phy.smart_speed_active == false)) | ||
812 | autoc |= IXGBE_AUTOC_KR_SUPP; | ||
813 | if (speed & IXGBE_LINK_SPEED_1GB_FULL) | ||
814 | autoc |= IXGBE_AUTOC_KX_SUPP; | ||
815 | } else if ((pma_pmd_1g == IXGBE_AUTOC_1G_SFI) && | ||
816 | (link_mode == IXGBE_AUTOC_LMS_1G_LINK_NO_AN || | ||
817 | link_mode == IXGBE_AUTOC_LMS_1G_AN)) { | ||
818 | /* Switch from 1G SFI to 10G SFI if requested */ | ||
819 | if ((speed == IXGBE_LINK_SPEED_10GB_FULL) && | ||
820 | (pma_pmd_10g_serial == IXGBE_AUTOC2_10G_SFI)) { | ||
821 | autoc &= ~IXGBE_AUTOC_LMS_MASK; | ||
822 | autoc |= IXGBE_AUTOC_LMS_10G_SERIAL; | ||
823 | } | ||
824 | } else if ((pma_pmd_10g_serial == IXGBE_AUTOC2_10G_SFI) && | ||
825 | (link_mode == IXGBE_AUTOC_LMS_10G_SERIAL)) { | ||
826 | /* Switch from 10G SFI to 1G SFI if requested */ | ||
827 | if ((speed == IXGBE_LINK_SPEED_1GB_FULL) && | ||
828 | (pma_pmd_1g == IXGBE_AUTOC_1G_SFI)) { | ||
829 | autoc &= ~IXGBE_AUTOC_LMS_MASK; | ||
830 | if (autoneg) | ||
831 | autoc |= IXGBE_AUTOC_LMS_1G_AN; | ||
832 | else | ||
833 | autoc |= IXGBE_AUTOC_LMS_1G_LINK_NO_AN; | ||
834 | } | ||
835 | } | ||
836 | |||
837 | if (autoc != start_autoc) { | ||
838 | /* Restart link */ | ||
839 | autoc |= IXGBE_AUTOC_AN_RESTART; | ||
840 | IXGBE_WRITE_REG(hw, IXGBE_AUTOC, autoc); | ||
841 | |||
842 | /* Only poll for autoneg to complete if specified to do so */ | ||
843 | if (autoneg_wait_to_complete) { | ||
844 | if (link_mode == IXGBE_AUTOC_LMS_KX4_KX_KR || | ||
845 | link_mode == IXGBE_AUTOC_LMS_KX4_KX_KR_1G_AN || | ||
846 | link_mode == IXGBE_AUTOC_LMS_KX4_KX_KR_SGMII) { | ||
847 | links_reg = 0; /*Just in case Autoneg time=0*/ | ||
848 | for (i = 0; i < IXGBE_AUTO_NEG_TIME; i++) { | ||
849 | links_reg = | ||
850 | IXGBE_READ_REG(hw, IXGBE_LINKS); | ||
851 | if (links_reg & IXGBE_LINKS_KX_AN_COMP) | ||
852 | break; | ||
853 | msleep(100); | ||
854 | } | ||
855 | if (!(links_reg & IXGBE_LINKS_KX_AN_COMP)) { | ||
856 | status = | ||
857 | IXGBE_ERR_AUTONEG_NOT_COMPLETE; | ||
858 | hw_dbg(hw, "Autoneg did not " | ||
859 | "complete.\n"); | ||
860 | } | ||
861 | } | ||
862 | } | ||
863 | |||
864 | /* Add delay to filter out noises during initial link setup */ | ||
865 | msleep(50); | ||
866 | } | ||
867 | |||
868 | out: | ||
869 | return status; | ||
870 | } | ||
871 | |||
872 | /** | ||
873 | * ixgbe_setup_copper_link_82599 - Set the PHY autoneg advertised field | ||
874 | * @hw: pointer to hardware structure | ||
875 | * @speed: new link speed | ||
876 | * @autoneg: true if autonegotiation enabled | ||
877 | * @autoneg_wait_to_complete: true if waiting is needed to complete | ||
878 | * | ||
879 | * Restarts link on PHY and MAC based on settings passed in. | ||
880 | **/ | ||
881 | static s32 ixgbe_setup_copper_link_82599(struct ixgbe_hw *hw, | ||
882 | ixgbe_link_speed speed, | ||
883 | bool autoneg, | ||
884 | bool autoneg_wait_to_complete) | ||
885 | { | ||
886 | s32 status; | ||
887 | |||
888 | /* Setup the PHY according to input speed */ | ||
889 | status = hw->phy.ops.setup_link_speed(hw, speed, autoneg, | ||
890 | autoneg_wait_to_complete); | ||
891 | /* Set up MAC */ | ||
892 | ixgbe_start_mac_link_82599(hw, autoneg_wait_to_complete); | ||
893 | |||
894 | return status; | ||
895 | } | ||
896 | |||
897 | /** | ||
898 | * ixgbe_reset_hw_82599 - Perform hardware reset | ||
899 | * @hw: pointer to hardware structure | ||
900 | * | ||
901 | * Resets the hardware by resetting the transmit and receive units, masks | ||
902 | * and clears all interrupts, perform a PHY reset, and perform a link (MAC) | ||
903 | * reset. | ||
904 | **/ | ||
905 | static s32 ixgbe_reset_hw_82599(struct ixgbe_hw *hw) | ||
906 | { | ||
907 | s32 status = 0; | ||
908 | u32 ctrl; | ||
909 | u32 i; | ||
910 | u32 autoc; | ||
911 | u32 autoc2; | ||
912 | |||
913 | /* Call adapter stop to disable tx/rx and clear interrupts */ | ||
914 | hw->mac.ops.stop_adapter(hw); | ||
915 | |||
916 | /* PHY ops must be identified and initialized prior to reset */ | ||
917 | |||
918 | /* Identify PHY and related function pointers */ | ||
919 | status = hw->phy.ops.init(hw); | ||
920 | |||
921 | if (status == IXGBE_ERR_SFP_NOT_SUPPORTED) | ||
922 | goto reset_hw_out; | ||
923 | |||
924 | /* Setup SFP module if there is one present. */ | ||
925 | if (hw->phy.sfp_setup_needed) { | ||
926 | status = hw->mac.ops.setup_sfp(hw); | ||
927 | hw->phy.sfp_setup_needed = false; | ||
928 | } | ||
929 | |||
930 | if (status == IXGBE_ERR_SFP_NOT_SUPPORTED) | ||
931 | goto reset_hw_out; | ||
932 | |||
933 | /* Reset PHY */ | ||
934 | if (hw->phy.reset_disable == false && hw->phy.ops.reset != NULL) | ||
935 | hw->phy.ops.reset(hw); | ||
936 | |||
937 | /* | ||
938 | * Prevent the PCI-E bus from from hanging by disabling PCI-E master | ||
939 | * access and verify no pending requests before reset | ||
940 | */ | ||
941 | ixgbe_disable_pcie_master(hw); | ||
942 | |||
943 | mac_reset_top: | ||
944 | /* | ||
945 | * Issue global reset to the MAC. This needs to be a SW reset. | ||
946 | * If link reset is used, it might reset the MAC when mng is using it | ||
947 | */ | ||
948 | ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL); | ||
949 | IXGBE_WRITE_REG(hw, IXGBE_CTRL, (ctrl | IXGBE_CTRL_RST)); | ||
950 | IXGBE_WRITE_FLUSH(hw); | ||
951 | |||
952 | /* Poll for reset bit to self-clear indicating reset is complete */ | ||
953 | for (i = 0; i < 10; i++) { | ||
954 | udelay(1); | ||
955 | ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL); | ||
956 | if (!(ctrl & IXGBE_CTRL_RST)) | ||
957 | break; | ||
958 | } | ||
959 | if (ctrl & IXGBE_CTRL_RST) { | ||
960 | status = IXGBE_ERR_RESET_FAILED; | ||
961 | hw_dbg(hw, "Reset polling failed to complete.\n"); | ||
962 | } | ||
963 | |||
964 | /* | ||
965 | * Double resets are required for recovery from certain error | ||
966 | * conditions. Between resets, it is necessary to stall to allow time | ||
967 | * for any pending HW events to complete. We use 1usec since that is | ||
968 | * what is needed for ixgbe_disable_pcie_master(). The second reset | ||
969 | * then clears out any effects of those events. | ||
970 | */ | ||
971 | if (hw->mac.flags & IXGBE_FLAGS_DOUBLE_RESET_REQUIRED) { | ||
972 | hw->mac.flags &= ~IXGBE_FLAGS_DOUBLE_RESET_REQUIRED; | ||
973 | udelay(1); | ||
974 | goto mac_reset_top; | ||
975 | } | ||
976 | |||
977 | msleep(50); | ||
978 | |||
979 | /* | ||
980 | * Store the original AUTOC/AUTOC2 values if they have not been | ||
981 | * stored off yet. Otherwise restore the stored original | ||
982 | * values since the reset operation sets back to defaults. | ||
983 | */ | ||
984 | autoc = IXGBE_READ_REG(hw, IXGBE_AUTOC); | ||
985 | autoc2 = IXGBE_READ_REG(hw, IXGBE_AUTOC2); | ||
986 | if (hw->mac.orig_link_settings_stored == false) { | ||
987 | hw->mac.orig_autoc = autoc; | ||
988 | hw->mac.orig_autoc2 = autoc2; | ||
989 | hw->mac.orig_link_settings_stored = true; | ||
990 | } else { | ||
991 | if (autoc != hw->mac.orig_autoc) | ||
992 | IXGBE_WRITE_REG(hw, IXGBE_AUTOC, (hw->mac.orig_autoc | | ||
993 | IXGBE_AUTOC_AN_RESTART)); | ||
994 | |||
995 | if ((autoc2 & IXGBE_AUTOC2_UPPER_MASK) != | ||
996 | (hw->mac.orig_autoc2 & IXGBE_AUTOC2_UPPER_MASK)) { | ||
997 | autoc2 &= ~IXGBE_AUTOC2_UPPER_MASK; | ||
998 | autoc2 |= (hw->mac.orig_autoc2 & | ||
999 | IXGBE_AUTOC2_UPPER_MASK); | ||
1000 | IXGBE_WRITE_REG(hw, IXGBE_AUTOC2, autoc2); | ||
1001 | } | ||
1002 | } | ||
1003 | |||
1004 | /* Store the permanent mac address */ | ||
1005 | hw->mac.ops.get_mac_addr(hw, hw->mac.perm_addr); | ||
1006 | |||
1007 | /* | ||
1008 | * Store MAC address from RAR0, clear receive address registers, and | ||
1009 | * clear the multicast table. Also reset num_rar_entries to 128, | ||
1010 | * since we modify this value when programming the SAN MAC address. | ||
1011 | */ | ||
1012 | hw->mac.num_rar_entries = 128; | ||
1013 | hw->mac.ops.init_rx_addrs(hw); | ||
1014 | |||
1015 | /* Store the permanent SAN mac address */ | ||
1016 | hw->mac.ops.get_san_mac_addr(hw, hw->mac.san_addr); | ||
1017 | |||
1018 | /* Add the SAN MAC address to the RAR only if it's a valid address */ | ||
1019 | if (ixgbe_validate_mac_addr(hw->mac.san_addr) == 0) { | ||
1020 | hw->mac.ops.set_rar(hw, hw->mac.num_rar_entries - 1, | ||
1021 | hw->mac.san_addr, 0, IXGBE_RAH_AV); | ||
1022 | |||
1023 | /* Reserve the last RAR for the SAN MAC address */ | ||
1024 | hw->mac.num_rar_entries--; | ||
1025 | } | ||
1026 | |||
1027 | /* Store the alternative WWNN/WWPN prefix */ | ||
1028 | hw->mac.ops.get_wwn_prefix(hw, &hw->mac.wwnn_prefix, | ||
1029 | &hw->mac.wwpn_prefix); | ||
1030 | |||
1031 | reset_hw_out: | ||
1032 | return status; | ||
1033 | } | ||
1034 | |||
1035 | /** | ||
1036 | * ixgbe_reinit_fdir_tables_82599 - Reinitialize Flow Director tables. | ||
1037 | * @hw: pointer to hardware structure | ||
1038 | **/ | ||
1039 | s32 ixgbe_reinit_fdir_tables_82599(struct ixgbe_hw *hw) | ||
1040 | { | ||
1041 | int i; | ||
1042 | u32 fdirctrl = IXGBE_READ_REG(hw, IXGBE_FDIRCTRL); | ||
1043 | fdirctrl &= ~IXGBE_FDIRCTRL_INIT_DONE; | ||
1044 | |||
1045 | /* | ||
1046 | * Before starting reinitialization process, | ||
1047 | * FDIRCMD.CMD must be zero. | ||
1048 | */ | ||
1049 | for (i = 0; i < IXGBE_FDIRCMD_CMD_POLL; i++) { | ||
1050 | if (!(IXGBE_READ_REG(hw, IXGBE_FDIRCMD) & | ||
1051 | IXGBE_FDIRCMD_CMD_MASK)) | ||
1052 | break; | ||
1053 | udelay(10); | ||
1054 | } | ||
1055 | if (i >= IXGBE_FDIRCMD_CMD_POLL) { | ||
1056 | hw_dbg(hw, "Flow Director previous command isn't complete, " | ||
1057 | "aborting table re-initialization.\n"); | ||
1058 | return IXGBE_ERR_FDIR_REINIT_FAILED; | ||
1059 | } | ||
1060 | |||
1061 | IXGBE_WRITE_REG(hw, IXGBE_FDIRFREE, 0); | ||
1062 | IXGBE_WRITE_FLUSH(hw); | ||
1063 | /* | ||
1064 | * 82599 adapters flow director init flow cannot be restarted, | ||
1065 | * Workaround 82599 silicon errata by performing the following steps | ||
1066 | * before re-writing the FDIRCTRL control register with the same value. | ||
1067 | * - write 1 to bit 8 of FDIRCMD register & | ||
1068 | * - write 0 to bit 8 of FDIRCMD register | ||
1069 | */ | ||
1070 | IXGBE_WRITE_REG(hw, IXGBE_FDIRCMD, | ||
1071 | (IXGBE_READ_REG(hw, IXGBE_FDIRCMD) | | ||
1072 | IXGBE_FDIRCMD_CLEARHT)); | ||
1073 | IXGBE_WRITE_FLUSH(hw); | ||
1074 | IXGBE_WRITE_REG(hw, IXGBE_FDIRCMD, | ||
1075 | (IXGBE_READ_REG(hw, IXGBE_FDIRCMD) & | ||
1076 | ~IXGBE_FDIRCMD_CLEARHT)); | ||
1077 | IXGBE_WRITE_FLUSH(hw); | ||
1078 | /* | ||
1079 | * Clear FDIR Hash register to clear any leftover hashes | ||
1080 | * waiting to be programmed. | ||
1081 | */ | ||
1082 | IXGBE_WRITE_REG(hw, IXGBE_FDIRHASH, 0x00); | ||
1083 | IXGBE_WRITE_FLUSH(hw); | ||
1084 | |||
1085 | IXGBE_WRITE_REG(hw, IXGBE_FDIRCTRL, fdirctrl); | ||
1086 | IXGBE_WRITE_FLUSH(hw); | ||
1087 | |||
1088 | /* Poll init-done after we write FDIRCTRL register */ | ||
1089 | for (i = 0; i < IXGBE_FDIR_INIT_DONE_POLL; i++) { | ||
1090 | if (IXGBE_READ_REG(hw, IXGBE_FDIRCTRL) & | ||
1091 | IXGBE_FDIRCTRL_INIT_DONE) | ||
1092 | break; | ||
1093 | udelay(10); | ||
1094 | } | ||
1095 | if (i >= IXGBE_FDIR_INIT_DONE_POLL) { | ||
1096 | hw_dbg(hw, "Flow Director Signature poll time exceeded!\n"); | ||
1097 | return IXGBE_ERR_FDIR_REINIT_FAILED; | ||
1098 | } | ||
1099 | |||
1100 | /* Clear FDIR statistics registers (read to clear) */ | ||
1101 | IXGBE_READ_REG(hw, IXGBE_FDIRUSTAT); | ||
1102 | IXGBE_READ_REG(hw, IXGBE_FDIRFSTAT); | ||
1103 | IXGBE_READ_REG(hw, IXGBE_FDIRMATCH); | ||
1104 | IXGBE_READ_REG(hw, IXGBE_FDIRMISS); | ||
1105 | IXGBE_READ_REG(hw, IXGBE_FDIRLEN); | ||
1106 | |||
1107 | return 0; | ||
1108 | } | ||
1109 | |||
1110 | /** | ||
1111 | * ixgbe_set_fdir_rxpba_82599 - Initialize Flow Director Rx packet buffer | ||
1112 | * @hw: pointer to hardware structure | ||
1113 | * @pballoc: which mode to allocate filters with | ||
1114 | **/ | ||
1115 | static s32 ixgbe_set_fdir_rxpba_82599(struct ixgbe_hw *hw, const u32 pballoc) | ||
1116 | { | ||
1117 | u32 fdir_pbsize = hw->mac.rx_pb_size << IXGBE_RXPBSIZE_SHIFT; | ||
1118 | u32 current_rxpbsize = 0; | ||
1119 | int i; | ||
1120 | |||
1121 | /* reserve space for Flow Director filters */ | ||
1122 | switch (pballoc) { | ||
1123 | case IXGBE_FDIR_PBALLOC_256K: | ||
1124 | fdir_pbsize -= 256 << IXGBE_RXPBSIZE_SHIFT; | ||
1125 | break; | ||
1126 | case IXGBE_FDIR_PBALLOC_128K: | ||
1127 | fdir_pbsize -= 128 << IXGBE_RXPBSIZE_SHIFT; | ||
1128 | break; | ||
1129 | case IXGBE_FDIR_PBALLOC_64K: | ||
1130 | fdir_pbsize -= 64 << IXGBE_RXPBSIZE_SHIFT; | ||
1131 | break; | ||
1132 | case IXGBE_FDIR_PBALLOC_NONE: | ||
1133 | default: | ||
1134 | return IXGBE_ERR_PARAM; | ||
1135 | } | ||
1136 | |||
1137 | /* determine current RX packet buffer size */ | ||
1138 | for (i = 0; i < 8; i++) | ||
1139 | current_rxpbsize += IXGBE_READ_REG(hw, IXGBE_RXPBSIZE(i)); | ||
1140 | |||
1141 | /* if there is already room for the filters do nothing */ | ||
1142 | if (current_rxpbsize <= fdir_pbsize) | ||
1143 | return 0; | ||
1144 | |||
1145 | if (current_rxpbsize > hw->mac.rx_pb_size) { | ||
1146 | /* | ||
1147 | * if rxpbsize is greater than max then HW max the Rx buffer | ||
1148 | * sizes are unconfigured or misconfigured since HW default is | ||
1149 | * to give the full buffer to each traffic class resulting in | ||
1150 | * the total size being buffer size 8x actual size | ||
1151 | * | ||
1152 | * This assumes no DCB since the RXPBSIZE registers appear to | ||
1153 | * be unconfigured. | ||
1154 | */ | ||
1155 | IXGBE_WRITE_REG(hw, IXGBE_RXPBSIZE(0), fdir_pbsize); | ||
1156 | for (i = 1; i < 8; i++) | ||
1157 | IXGBE_WRITE_REG(hw, IXGBE_RXPBSIZE(i), 0); | ||
1158 | } else { | ||
1159 | /* | ||
1160 | * Since the Rx packet buffer appears to have already been | ||
1161 | * configured we need to shrink each packet buffer by enough | ||
1162 | * to make room for the filters. As such we take each rxpbsize | ||
1163 | * value and multiply it by a fraction representing the size | ||
1164 | * needed over the size we currently have. | ||
1165 | * | ||
1166 | * We need to reduce fdir_pbsize and current_rxpbsize to | ||
1167 | * 1/1024 of their original values in order to avoid | ||
1168 | * overflowing the u32 being used to store rxpbsize. | ||
1169 | */ | ||
1170 | fdir_pbsize >>= IXGBE_RXPBSIZE_SHIFT; | ||
1171 | current_rxpbsize >>= IXGBE_RXPBSIZE_SHIFT; | ||
1172 | for (i = 0; i < 8; i++) { | ||
1173 | u32 rxpbsize = IXGBE_READ_REG(hw, IXGBE_RXPBSIZE(i)); | ||
1174 | rxpbsize *= fdir_pbsize; | ||
1175 | rxpbsize /= current_rxpbsize; | ||
1176 | IXGBE_WRITE_REG(hw, IXGBE_RXPBSIZE(i), rxpbsize); | ||
1177 | } | ||
1178 | } | ||
1179 | |||
1180 | return 0; | ||
1181 | } | ||
1182 | |||
1183 | /** | ||
1184 | * ixgbe_fdir_enable_82599 - Initialize Flow Director control registers | ||
1185 | * @hw: pointer to hardware structure | ||
1186 | * @fdirctrl: value to write to flow director control register | ||
1187 | **/ | ||
1188 | static void ixgbe_fdir_enable_82599(struct ixgbe_hw *hw, u32 fdirctrl) | ||
1189 | { | ||
1190 | int i; | ||
1191 | |||
1192 | /* Prime the keys for hashing */ | ||
1193 | IXGBE_WRITE_REG(hw, IXGBE_FDIRHKEY, IXGBE_ATR_BUCKET_HASH_KEY); | ||
1194 | IXGBE_WRITE_REG(hw, IXGBE_FDIRSKEY, IXGBE_ATR_SIGNATURE_HASH_KEY); | ||
1195 | |||
1196 | /* | ||
1197 | * Poll init-done after we write the register. Estimated times: | ||
1198 | * 10G: PBALLOC = 11b, timing is 60us | ||
1199 | * 1G: PBALLOC = 11b, timing is 600us | ||
1200 | * 100M: PBALLOC = 11b, timing is 6ms | ||
1201 | * | ||
1202 | * Multiple these timings by 4 if under full Rx load | ||
1203 | * | ||
1204 | * So we'll poll for IXGBE_FDIR_INIT_DONE_POLL times, sleeping for | ||
1205 | * 1 msec per poll time. If we're at line rate and drop to 100M, then | ||
1206 | * this might not finish in our poll time, but we can live with that | ||
1207 | * for now. | ||
1208 | */ | ||
1209 | IXGBE_WRITE_REG(hw, IXGBE_FDIRCTRL, fdirctrl); | ||
1210 | IXGBE_WRITE_FLUSH(hw); | ||
1211 | for (i = 0; i < IXGBE_FDIR_INIT_DONE_POLL; i++) { | ||
1212 | if (IXGBE_READ_REG(hw, IXGBE_FDIRCTRL) & | ||
1213 | IXGBE_FDIRCTRL_INIT_DONE) | ||
1214 | break; | ||
1215 | usleep_range(1000, 2000); | ||
1216 | } | ||
1217 | |||
1218 | if (i >= IXGBE_FDIR_INIT_DONE_POLL) | ||
1219 | hw_dbg(hw, "Flow Director poll time exceeded!\n"); | ||
1220 | } | ||
1221 | |||
1222 | /** | ||
1223 | * ixgbe_init_fdir_signature_82599 - Initialize Flow Director signature filters | ||
1224 | * @hw: pointer to hardware structure | ||
1225 | * @fdirctrl: value to write to flow director control register, initially | ||
1226 | * contains just the value of the Rx packet buffer allocation | ||
1227 | **/ | ||
1228 | s32 ixgbe_init_fdir_signature_82599(struct ixgbe_hw *hw, u32 fdirctrl) | ||
1229 | { | ||
1230 | s32 err; | ||
1231 | |||
1232 | /* Before enabling Flow Director, verify the Rx Packet Buffer size */ | ||
1233 | err = ixgbe_set_fdir_rxpba_82599(hw, fdirctrl); | ||
1234 | if (err) | ||
1235 | return err; | ||
1236 | |||
1237 | /* | ||
1238 | * Continue setup of fdirctrl register bits: | ||
1239 | * Move the flexible bytes to use the ethertype - shift 6 words | ||
1240 | * Set the maximum length per hash bucket to 0xA filters | ||
1241 | * Send interrupt when 64 filters are left | ||
1242 | */ | ||
1243 | fdirctrl |= (0x6 << IXGBE_FDIRCTRL_FLEX_SHIFT) | | ||
1244 | (0xA << IXGBE_FDIRCTRL_MAX_LENGTH_SHIFT) | | ||
1245 | (4 << IXGBE_FDIRCTRL_FULL_THRESH_SHIFT); | ||
1246 | |||
1247 | /* write hashes and fdirctrl register, poll for completion */ | ||
1248 | ixgbe_fdir_enable_82599(hw, fdirctrl); | ||
1249 | |||
1250 | return 0; | ||
1251 | } | ||
1252 | |||
1253 | /** | ||
1254 | * ixgbe_init_fdir_perfect_82599 - Initialize Flow Director perfect filters | ||
1255 | * @hw: pointer to hardware structure | ||
1256 | * @fdirctrl: value to write to flow director control register, initially | ||
1257 | * contains just the value of the Rx packet buffer allocation | ||
1258 | **/ | ||
1259 | s32 ixgbe_init_fdir_perfect_82599(struct ixgbe_hw *hw, u32 fdirctrl) | ||
1260 | { | ||
1261 | s32 err; | ||
1262 | |||
1263 | /* Before enabling Flow Director, verify the Rx Packet Buffer size */ | ||
1264 | err = ixgbe_set_fdir_rxpba_82599(hw, fdirctrl); | ||
1265 | if (err) | ||
1266 | return err; | ||
1267 | |||
1268 | /* | ||
1269 | * Continue setup of fdirctrl register bits: | ||
1270 | * Turn perfect match filtering on | ||
1271 | * Report hash in RSS field of Rx wb descriptor | ||
1272 | * Initialize the drop queue | ||
1273 | * Move the flexible bytes to use the ethertype - shift 6 words | ||
1274 | * Set the maximum length per hash bucket to 0xA filters | ||
1275 | * Send interrupt when 64 (0x4 * 16) filters are left | ||
1276 | */ | ||
1277 | fdirctrl |= IXGBE_FDIRCTRL_PERFECT_MATCH | | ||
1278 | IXGBE_FDIRCTRL_REPORT_STATUS | | ||
1279 | (IXGBE_FDIR_DROP_QUEUE << IXGBE_FDIRCTRL_DROP_Q_SHIFT) | | ||
1280 | (0x6 << IXGBE_FDIRCTRL_FLEX_SHIFT) | | ||
1281 | (0xA << IXGBE_FDIRCTRL_MAX_LENGTH_SHIFT) | | ||
1282 | (4 << IXGBE_FDIRCTRL_FULL_THRESH_SHIFT); | ||
1283 | |||
1284 | /* write hashes and fdirctrl register, poll for completion */ | ||
1285 | ixgbe_fdir_enable_82599(hw, fdirctrl); | ||
1286 | |||
1287 | return 0; | ||
1288 | } | ||
1289 | |||
1290 | /* | ||
1291 | * These defines allow us to quickly generate all of the necessary instructions | ||
1292 | * in the function below by simply calling out IXGBE_COMPUTE_SIG_HASH_ITERATION | ||
1293 | * for values 0 through 15 | ||
1294 | */ | ||
1295 | #define IXGBE_ATR_COMMON_HASH_KEY \ | ||
1296 | (IXGBE_ATR_BUCKET_HASH_KEY & IXGBE_ATR_SIGNATURE_HASH_KEY) | ||
1297 | #define IXGBE_COMPUTE_SIG_HASH_ITERATION(_n) \ | ||
1298 | do { \ | ||
1299 | u32 n = (_n); \ | ||
1300 | if (IXGBE_ATR_COMMON_HASH_KEY & (0x01 << n)) \ | ||
1301 | common_hash ^= lo_hash_dword >> n; \ | ||
1302 | else if (IXGBE_ATR_BUCKET_HASH_KEY & (0x01 << n)) \ | ||
1303 | bucket_hash ^= lo_hash_dword >> n; \ | ||
1304 | else if (IXGBE_ATR_SIGNATURE_HASH_KEY & (0x01 << n)) \ | ||
1305 | sig_hash ^= lo_hash_dword << (16 - n); \ | ||
1306 | if (IXGBE_ATR_COMMON_HASH_KEY & (0x01 << (n + 16))) \ | ||
1307 | common_hash ^= hi_hash_dword >> n; \ | ||
1308 | else if (IXGBE_ATR_BUCKET_HASH_KEY & (0x01 << (n + 16))) \ | ||
1309 | bucket_hash ^= hi_hash_dword >> n; \ | ||
1310 | else if (IXGBE_ATR_SIGNATURE_HASH_KEY & (0x01 << (n + 16))) \ | ||
1311 | sig_hash ^= hi_hash_dword << (16 - n); \ | ||
1312 | } while (0); | ||
1313 | |||
1314 | /** | ||
1315 | * ixgbe_atr_compute_sig_hash_82599 - Compute the signature hash | ||
1316 | * @stream: input bitstream to compute the hash on | ||
1317 | * | ||
1318 | * This function is almost identical to the function above but contains | ||
1319 | * several optomizations such as unwinding all of the loops, letting the | ||
1320 | * compiler work out all of the conditional ifs since the keys are static | ||
1321 | * defines, and computing two keys at once since the hashed dword stream | ||
1322 | * will be the same for both keys. | ||
1323 | **/ | ||
1324 | static u32 ixgbe_atr_compute_sig_hash_82599(union ixgbe_atr_hash_dword input, | ||
1325 | union ixgbe_atr_hash_dword common) | ||
1326 | { | ||
1327 | u32 hi_hash_dword, lo_hash_dword, flow_vm_vlan; | ||
1328 | u32 sig_hash = 0, bucket_hash = 0, common_hash = 0; | ||
1329 | |||
1330 | /* record the flow_vm_vlan bits as they are a key part to the hash */ | ||
1331 | flow_vm_vlan = ntohl(input.dword); | ||
1332 | |||
1333 | /* generate common hash dword */ | ||
1334 | hi_hash_dword = ntohl(common.dword); | ||
1335 | |||
1336 | /* low dword is word swapped version of common */ | ||
1337 | lo_hash_dword = (hi_hash_dword >> 16) | (hi_hash_dword << 16); | ||
1338 | |||
1339 | /* apply flow ID/VM pool/VLAN ID bits to hash words */ | ||
1340 | hi_hash_dword ^= flow_vm_vlan ^ (flow_vm_vlan >> 16); | ||
1341 | |||
1342 | /* Process bits 0 and 16 */ | ||
1343 | IXGBE_COMPUTE_SIG_HASH_ITERATION(0); | ||
1344 | |||
1345 | /* | ||
1346 | * apply flow ID/VM pool/VLAN ID bits to lo hash dword, we had to | ||
1347 | * delay this because bit 0 of the stream should not be processed | ||
1348 | * so we do not add the vlan until after bit 0 was processed | ||
1349 | */ | ||
1350 | lo_hash_dword ^= flow_vm_vlan ^ (flow_vm_vlan << 16); | ||
1351 | |||
1352 | /* Process remaining 30 bit of the key */ | ||
1353 | IXGBE_COMPUTE_SIG_HASH_ITERATION(1); | ||
1354 | IXGBE_COMPUTE_SIG_HASH_ITERATION(2); | ||
1355 | IXGBE_COMPUTE_SIG_HASH_ITERATION(3); | ||
1356 | IXGBE_COMPUTE_SIG_HASH_ITERATION(4); | ||
1357 | IXGBE_COMPUTE_SIG_HASH_ITERATION(5); | ||
1358 | IXGBE_COMPUTE_SIG_HASH_ITERATION(6); | ||
1359 | IXGBE_COMPUTE_SIG_HASH_ITERATION(7); | ||
1360 | IXGBE_COMPUTE_SIG_HASH_ITERATION(8); | ||
1361 | IXGBE_COMPUTE_SIG_HASH_ITERATION(9); | ||
1362 | IXGBE_COMPUTE_SIG_HASH_ITERATION(10); | ||
1363 | IXGBE_COMPUTE_SIG_HASH_ITERATION(11); | ||
1364 | IXGBE_COMPUTE_SIG_HASH_ITERATION(12); | ||
1365 | IXGBE_COMPUTE_SIG_HASH_ITERATION(13); | ||
1366 | IXGBE_COMPUTE_SIG_HASH_ITERATION(14); | ||
1367 | IXGBE_COMPUTE_SIG_HASH_ITERATION(15); | ||
1368 | |||
1369 | /* combine common_hash result with signature and bucket hashes */ | ||
1370 | bucket_hash ^= common_hash; | ||
1371 | bucket_hash &= IXGBE_ATR_HASH_MASK; | ||
1372 | |||
1373 | sig_hash ^= common_hash << 16; | ||
1374 | sig_hash &= IXGBE_ATR_HASH_MASK << 16; | ||
1375 | |||
1376 | /* return completed signature hash */ | ||
1377 | return sig_hash ^ bucket_hash; | ||
1378 | } | ||
1379 | |||
1380 | /** | ||
1381 | * ixgbe_atr_add_signature_filter_82599 - Adds a signature hash filter | ||
1382 | * @hw: pointer to hardware structure | ||
1383 | * @input: unique input dword | ||
1384 | * @common: compressed common input dword | ||
1385 | * @queue: queue index to direct traffic to | ||
1386 | **/ | ||
1387 | s32 ixgbe_fdir_add_signature_filter_82599(struct ixgbe_hw *hw, | ||
1388 | union ixgbe_atr_hash_dword input, | ||
1389 | union ixgbe_atr_hash_dword common, | ||
1390 | u8 queue) | ||
1391 | { | ||
1392 | u64 fdirhashcmd; | ||
1393 | u32 fdircmd; | ||
1394 | |||
1395 | /* | ||
1396 | * Get the flow_type in order to program FDIRCMD properly | ||
1397 | * lowest 2 bits are FDIRCMD.L4TYPE, third lowest bit is FDIRCMD.IPV6 | ||
1398 | */ | ||
1399 | switch (input.formatted.flow_type) { | ||
1400 | case IXGBE_ATR_FLOW_TYPE_TCPV4: | ||
1401 | case IXGBE_ATR_FLOW_TYPE_UDPV4: | ||
1402 | case IXGBE_ATR_FLOW_TYPE_SCTPV4: | ||
1403 | case IXGBE_ATR_FLOW_TYPE_TCPV6: | ||
1404 | case IXGBE_ATR_FLOW_TYPE_UDPV6: | ||
1405 | case IXGBE_ATR_FLOW_TYPE_SCTPV6: | ||
1406 | break; | ||
1407 | default: | ||
1408 | hw_dbg(hw, " Error on flow type input\n"); | ||
1409 | return IXGBE_ERR_CONFIG; | ||
1410 | } | ||
1411 | |||
1412 | /* configure FDIRCMD register */ | ||
1413 | fdircmd = IXGBE_FDIRCMD_CMD_ADD_FLOW | IXGBE_FDIRCMD_FILTER_UPDATE | | ||
1414 | IXGBE_FDIRCMD_LAST | IXGBE_FDIRCMD_QUEUE_EN; | ||
1415 | fdircmd |= input.formatted.flow_type << IXGBE_FDIRCMD_FLOW_TYPE_SHIFT; | ||
1416 | fdircmd |= (u32)queue << IXGBE_FDIRCMD_RX_QUEUE_SHIFT; | ||
1417 | |||
1418 | /* | ||
1419 | * The lower 32-bits of fdirhashcmd is for FDIRHASH, the upper 32-bits | ||
1420 | * is for FDIRCMD. Then do a 64-bit register write from FDIRHASH. | ||
1421 | */ | ||
1422 | fdirhashcmd = (u64)fdircmd << 32; | ||
1423 | fdirhashcmd |= ixgbe_atr_compute_sig_hash_82599(input, common); | ||
1424 | IXGBE_WRITE_REG64(hw, IXGBE_FDIRHASH, fdirhashcmd); | ||
1425 | |||
1426 | hw_dbg(hw, "Tx Queue=%x hash=%x\n", queue, (u32)fdirhashcmd); | ||
1427 | |||
1428 | return 0; | ||
1429 | } | ||
1430 | |||
1431 | #define IXGBE_COMPUTE_BKT_HASH_ITERATION(_n) \ | ||
1432 | do { \ | ||
1433 | u32 n = (_n); \ | ||
1434 | if (IXGBE_ATR_BUCKET_HASH_KEY & (0x01 << n)) \ | ||
1435 | bucket_hash ^= lo_hash_dword >> n; \ | ||
1436 | if (IXGBE_ATR_BUCKET_HASH_KEY & (0x01 << (n + 16))) \ | ||
1437 | bucket_hash ^= hi_hash_dword >> n; \ | ||
1438 | } while (0); | ||
1439 | |||
1440 | /** | ||
1441 | * ixgbe_atr_compute_perfect_hash_82599 - Compute the perfect filter hash | ||
1442 | * @atr_input: input bitstream to compute the hash on | ||
1443 | * @input_mask: mask for the input bitstream | ||
1444 | * | ||
1445 | * This function serves two main purposes. First it applys the input_mask | ||
1446 | * to the atr_input resulting in a cleaned up atr_input data stream. | ||
1447 | * Secondly it computes the hash and stores it in the bkt_hash field at | ||
1448 | * the end of the input byte stream. This way it will be available for | ||
1449 | * future use without needing to recompute the hash. | ||
1450 | **/ | ||
1451 | void ixgbe_atr_compute_perfect_hash_82599(union ixgbe_atr_input *input, | ||
1452 | union ixgbe_atr_input *input_mask) | ||
1453 | { | ||
1454 | |||
1455 | u32 hi_hash_dword, lo_hash_dword, flow_vm_vlan; | ||
1456 | u32 bucket_hash = 0; | ||
1457 | |||
1458 | /* Apply masks to input data */ | ||
1459 | input->dword_stream[0] &= input_mask->dword_stream[0]; | ||
1460 | input->dword_stream[1] &= input_mask->dword_stream[1]; | ||
1461 | input->dword_stream[2] &= input_mask->dword_stream[2]; | ||
1462 | input->dword_stream[3] &= input_mask->dword_stream[3]; | ||
1463 | input->dword_stream[4] &= input_mask->dword_stream[4]; | ||
1464 | input->dword_stream[5] &= input_mask->dword_stream[5]; | ||
1465 | input->dword_stream[6] &= input_mask->dword_stream[6]; | ||
1466 | input->dword_stream[7] &= input_mask->dword_stream[7]; | ||
1467 | input->dword_stream[8] &= input_mask->dword_stream[8]; | ||
1468 | input->dword_stream[9] &= input_mask->dword_stream[9]; | ||
1469 | input->dword_stream[10] &= input_mask->dword_stream[10]; | ||
1470 | |||
1471 | /* record the flow_vm_vlan bits as they are a key part to the hash */ | ||
1472 | flow_vm_vlan = ntohl(input->dword_stream[0]); | ||
1473 | |||
1474 | /* generate common hash dword */ | ||
1475 | hi_hash_dword = ntohl(input->dword_stream[1] ^ | ||
1476 | input->dword_stream[2] ^ | ||
1477 | input->dword_stream[3] ^ | ||
1478 | input->dword_stream[4] ^ | ||
1479 | input->dword_stream[5] ^ | ||
1480 | input->dword_stream[6] ^ | ||
1481 | input->dword_stream[7] ^ | ||
1482 | input->dword_stream[8] ^ | ||
1483 | input->dword_stream[9] ^ | ||
1484 | input->dword_stream[10]); | ||
1485 | |||
1486 | /* low dword is word swapped version of common */ | ||
1487 | lo_hash_dword = (hi_hash_dword >> 16) | (hi_hash_dword << 16); | ||
1488 | |||
1489 | /* apply flow ID/VM pool/VLAN ID bits to hash words */ | ||
1490 | hi_hash_dword ^= flow_vm_vlan ^ (flow_vm_vlan >> 16); | ||
1491 | |||
1492 | /* Process bits 0 and 16 */ | ||
1493 | IXGBE_COMPUTE_BKT_HASH_ITERATION(0); | ||
1494 | |||
1495 | /* | ||
1496 | * apply flow ID/VM pool/VLAN ID bits to lo hash dword, we had to | ||
1497 | * delay this because bit 0 of the stream should not be processed | ||
1498 | * so we do not add the vlan until after bit 0 was processed | ||
1499 | */ | ||
1500 | lo_hash_dword ^= flow_vm_vlan ^ (flow_vm_vlan << 16); | ||
1501 | |||
1502 | /* Process remaining 30 bit of the key */ | ||
1503 | IXGBE_COMPUTE_BKT_HASH_ITERATION(1); | ||
1504 | IXGBE_COMPUTE_BKT_HASH_ITERATION(2); | ||
1505 | IXGBE_COMPUTE_BKT_HASH_ITERATION(3); | ||
1506 | IXGBE_COMPUTE_BKT_HASH_ITERATION(4); | ||
1507 | IXGBE_COMPUTE_BKT_HASH_ITERATION(5); | ||
1508 | IXGBE_COMPUTE_BKT_HASH_ITERATION(6); | ||
1509 | IXGBE_COMPUTE_BKT_HASH_ITERATION(7); | ||
1510 | IXGBE_COMPUTE_BKT_HASH_ITERATION(8); | ||
1511 | IXGBE_COMPUTE_BKT_HASH_ITERATION(9); | ||
1512 | IXGBE_COMPUTE_BKT_HASH_ITERATION(10); | ||
1513 | IXGBE_COMPUTE_BKT_HASH_ITERATION(11); | ||
1514 | IXGBE_COMPUTE_BKT_HASH_ITERATION(12); | ||
1515 | IXGBE_COMPUTE_BKT_HASH_ITERATION(13); | ||
1516 | IXGBE_COMPUTE_BKT_HASH_ITERATION(14); | ||
1517 | IXGBE_COMPUTE_BKT_HASH_ITERATION(15); | ||
1518 | |||
1519 | /* | ||
1520 | * Limit hash to 13 bits since max bucket count is 8K. | ||
1521 | * Store result at the end of the input stream. | ||
1522 | */ | ||
1523 | input->formatted.bkt_hash = bucket_hash & 0x1FFF; | ||
1524 | } | ||
1525 | |||
1526 | /** | ||
1527 | * ixgbe_get_fdirtcpm_82599 - generate a tcp port from atr_input_masks | ||
1528 | * @input_mask: mask to be bit swapped | ||
1529 | * | ||
1530 | * The source and destination port masks for flow director are bit swapped | ||
1531 | * in that bit 15 effects bit 0, 14 effects 1, 13, 2 etc. In order to | ||
1532 | * generate a correctly swapped value we need to bit swap the mask and that | ||
1533 | * is what is accomplished by this function. | ||
1534 | **/ | ||
1535 | static u32 ixgbe_get_fdirtcpm_82599(union ixgbe_atr_input *input_mask) | ||
1536 | { | ||
1537 | u32 mask = ntohs(input_mask->formatted.dst_port); | ||
1538 | mask <<= IXGBE_FDIRTCPM_DPORTM_SHIFT; | ||
1539 | mask |= ntohs(input_mask->formatted.src_port); | ||
1540 | mask = ((mask & 0x55555555) << 1) | ((mask & 0xAAAAAAAA) >> 1); | ||
1541 | mask = ((mask & 0x33333333) << 2) | ((mask & 0xCCCCCCCC) >> 2); | ||
1542 | mask = ((mask & 0x0F0F0F0F) << 4) | ((mask & 0xF0F0F0F0) >> 4); | ||
1543 | return ((mask & 0x00FF00FF) << 8) | ((mask & 0xFF00FF00) >> 8); | ||
1544 | } | ||
1545 | |||
1546 | /* | ||
1547 | * These two macros are meant to address the fact that we have registers | ||
1548 | * that are either all or in part big-endian. As a result on big-endian | ||
1549 | * systems we will end up byte swapping the value to little-endian before | ||
1550 | * it is byte swapped again and written to the hardware in the original | ||
1551 | * big-endian format. | ||
1552 | */ | ||
1553 | #define IXGBE_STORE_AS_BE32(_value) \ | ||
1554 | (((u32)(_value) >> 24) | (((u32)(_value) & 0x00FF0000) >> 8) | \ | ||
1555 | (((u32)(_value) & 0x0000FF00) << 8) | ((u32)(_value) << 24)) | ||
1556 | |||
1557 | #define IXGBE_WRITE_REG_BE32(a, reg, value) \ | ||
1558 | IXGBE_WRITE_REG((a), (reg), IXGBE_STORE_AS_BE32(ntohl(value))) | ||
1559 | |||
1560 | #define IXGBE_STORE_AS_BE16(_value) \ | ||
1561 | ntohs(((u16)(_value) >> 8) | ((u16)(_value) << 8)) | ||
1562 | |||
1563 | s32 ixgbe_fdir_set_input_mask_82599(struct ixgbe_hw *hw, | ||
1564 | union ixgbe_atr_input *input_mask) | ||
1565 | { | ||
1566 | /* mask IPv6 since it is currently not supported */ | ||
1567 | u32 fdirm = IXGBE_FDIRM_DIPv6; | ||
1568 | u32 fdirtcpm; | ||
1569 | |||
1570 | /* | ||
1571 | * Program the relevant mask registers. If src/dst_port or src/dst_addr | ||
1572 | * are zero, then assume a full mask for that field. Also assume that | ||
1573 | * a VLAN of 0 is unspecified, so mask that out as well. L4type | ||
1574 | * cannot be masked out in this implementation. | ||
1575 | * | ||
1576 | * This also assumes IPv4 only. IPv6 masking isn't supported at this | ||
1577 | * point in time. | ||
1578 | */ | ||
1579 | |||
1580 | /* verify bucket hash is cleared on hash generation */ | ||
1581 | if (input_mask->formatted.bkt_hash) | ||
1582 | hw_dbg(hw, " bucket hash should always be 0 in mask\n"); | ||
1583 | |||
1584 | /* Program FDIRM and verify partial masks */ | ||
1585 | switch (input_mask->formatted.vm_pool & 0x7F) { | ||
1586 | case 0x0: | ||
1587 | fdirm |= IXGBE_FDIRM_POOL; | ||
1588 | case 0x7F: | ||
1589 | break; | ||
1590 | default: | ||
1591 | hw_dbg(hw, " Error on vm pool mask\n"); | ||
1592 | return IXGBE_ERR_CONFIG; | ||
1593 | } | ||
1594 | |||
1595 | switch (input_mask->formatted.flow_type & IXGBE_ATR_L4TYPE_MASK) { | ||
1596 | case 0x0: | ||
1597 | fdirm |= IXGBE_FDIRM_L4P; | ||
1598 | if (input_mask->formatted.dst_port || | ||
1599 | input_mask->formatted.src_port) { | ||
1600 | hw_dbg(hw, " Error on src/dst port mask\n"); | ||
1601 | return IXGBE_ERR_CONFIG; | ||
1602 | } | ||
1603 | case IXGBE_ATR_L4TYPE_MASK: | ||
1604 | break; | ||
1605 | default: | ||
1606 | hw_dbg(hw, " Error on flow type mask\n"); | ||
1607 | return IXGBE_ERR_CONFIG; | ||
1608 | } | ||
1609 | |||
1610 | switch (ntohs(input_mask->formatted.vlan_id) & 0xEFFF) { | ||
1611 | case 0x0000: | ||
1612 | /* mask VLAN ID, fall through to mask VLAN priority */ | ||
1613 | fdirm |= IXGBE_FDIRM_VLANID; | ||
1614 | case 0x0FFF: | ||
1615 | /* mask VLAN priority */ | ||
1616 | fdirm |= IXGBE_FDIRM_VLANP; | ||
1617 | break; | ||
1618 | case 0xE000: | ||
1619 | /* mask VLAN ID only, fall through */ | ||
1620 | fdirm |= IXGBE_FDIRM_VLANID; | ||
1621 | case 0xEFFF: | ||
1622 | /* no VLAN fields masked */ | ||
1623 | break; | ||
1624 | default: | ||
1625 | hw_dbg(hw, " Error on VLAN mask\n"); | ||
1626 | return IXGBE_ERR_CONFIG; | ||
1627 | } | ||
1628 | |||
1629 | switch (input_mask->formatted.flex_bytes & 0xFFFF) { | ||
1630 | case 0x0000: | ||
1631 | /* Mask Flex Bytes, fall through */ | ||
1632 | fdirm |= IXGBE_FDIRM_FLEX; | ||
1633 | case 0xFFFF: | ||
1634 | break; | ||
1635 | default: | ||
1636 | hw_dbg(hw, " Error on flexible byte mask\n"); | ||
1637 | return IXGBE_ERR_CONFIG; | ||
1638 | } | ||
1639 | |||
1640 | /* Now mask VM pool and destination IPv6 - bits 5 and 2 */ | ||
1641 | IXGBE_WRITE_REG(hw, IXGBE_FDIRM, fdirm); | ||
1642 | |||
1643 | /* store the TCP/UDP port masks, bit reversed from port layout */ | ||
1644 | fdirtcpm = ixgbe_get_fdirtcpm_82599(input_mask); | ||
1645 | |||
1646 | /* write both the same so that UDP and TCP use the same mask */ | ||
1647 | IXGBE_WRITE_REG(hw, IXGBE_FDIRTCPM, ~fdirtcpm); | ||
1648 | IXGBE_WRITE_REG(hw, IXGBE_FDIRUDPM, ~fdirtcpm); | ||
1649 | |||
1650 | /* store source and destination IP masks (big-enian) */ | ||
1651 | IXGBE_WRITE_REG_BE32(hw, IXGBE_FDIRSIP4M, | ||
1652 | ~input_mask->formatted.src_ip[0]); | ||
1653 | IXGBE_WRITE_REG_BE32(hw, IXGBE_FDIRDIP4M, | ||
1654 | ~input_mask->formatted.dst_ip[0]); | ||
1655 | |||
1656 | return 0; | ||
1657 | } | ||
1658 | |||
1659 | s32 ixgbe_fdir_write_perfect_filter_82599(struct ixgbe_hw *hw, | ||
1660 | union ixgbe_atr_input *input, | ||
1661 | u16 soft_id, u8 queue) | ||
1662 | { | ||
1663 | u32 fdirport, fdirvlan, fdirhash, fdircmd; | ||
1664 | |||
1665 | /* currently IPv6 is not supported, must be programmed with 0 */ | ||
1666 | IXGBE_WRITE_REG_BE32(hw, IXGBE_FDIRSIPv6(0), | ||
1667 | input->formatted.src_ip[0]); | ||
1668 | IXGBE_WRITE_REG_BE32(hw, IXGBE_FDIRSIPv6(1), | ||
1669 | input->formatted.src_ip[1]); | ||
1670 | IXGBE_WRITE_REG_BE32(hw, IXGBE_FDIRSIPv6(2), | ||
1671 | input->formatted.src_ip[2]); | ||
1672 | |||
1673 | /* record the source address (big-endian) */ | ||
1674 | IXGBE_WRITE_REG_BE32(hw, IXGBE_FDIRIPSA, input->formatted.src_ip[0]); | ||
1675 | |||
1676 | /* record the first 32 bits of the destination address (big-endian) */ | ||
1677 | IXGBE_WRITE_REG_BE32(hw, IXGBE_FDIRIPDA, input->formatted.dst_ip[0]); | ||
1678 | |||
1679 | /* record source and destination port (little-endian)*/ | ||
1680 | fdirport = ntohs(input->formatted.dst_port); | ||
1681 | fdirport <<= IXGBE_FDIRPORT_DESTINATION_SHIFT; | ||
1682 | fdirport |= ntohs(input->formatted.src_port); | ||
1683 | IXGBE_WRITE_REG(hw, IXGBE_FDIRPORT, fdirport); | ||
1684 | |||
1685 | /* record vlan (little-endian) and flex_bytes(big-endian) */ | ||
1686 | fdirvlan = IXGBE_STORE_AS_BE16(input->formatted.flex_bytes); | ||
1687 | fdirvlan <<= IXGBE_FDIRVLAN_FLEX_SHIFT; | ||
1688 | fdirvlan |= ntohs(input->formatted.vlan_id); | ||
1689 | IXGBE_WRITE_REG(hw, IXGBE_FDIRVLAN, fdirvlan); | ||
1690 | |||
1691 | /* configure FDIRHASH register */ | ||
1692 | fdirhash = input->formatted.bkt_hash; | ||
1693 | fdirhash |= soft_id << IXGBE_FDIRHASH_SIG_SW_INDEX_SHIFT; | ||
1694 | IXGBE_WRITE_REG(hw, IXGBE_FDIRHASH, fdirhash); | ||
1695 | |||
1696 | /* | ||
1697 | * flush all previous writes to make certain registers are | ||
1698 | * programmed prior to issuing the command | ||
1699 | */ | ||
1700 | IXGBE_WRITE_FLUSH(hw); | ||
1701 | |||
1702 | /* configure FDIRCMD register */ | ||
1703 | fdircmd = IXGBE_FDIRCMD_CMD_ADD_FLOW | IXGBE_FDIRCMD_FILTER_UPDATE | | ||
1704 | IXGBE_FDIRCMD_LAST | IXGBE_FDIRCMD_QUEUE_EN; | ||
1705 | if (queue == IXGBE_FDIR_DROP_QUEUE) | ||
1706 | fdircmd |= IXGBE_FDIRCMD_DROP; | ||
1707 | fdircmd |= input->formatted.flow_type << IXGBE_FDIRCMD_FLOW_TYPE_SHIFT; | ||
1708 | fdircmd |= (u32)queue << IXGBE_FDIRCMD_RX_QUEUE_SHIFT; | ||
1709 | fdircmd |= (u32)input->formatted.vm_pool << IXGBE_FDIRCMD_VT_POOL_SHIFT; | ||
1710 | |||
1711 | IXGBE_WRITE_REG(hw, IXGBE_FDIRCMD, fdircmd); | ||
1712 | |||
1713 | return 0; | ||
1714 | } | ||
1715 | |||
1716 | s32 ixgbe_fdir_erase_perfect_filter_82599(struct ixgbe_hw *hw, | ||
1717 | union ixgbe_atr_input *input, | ||
1718 | u16 soft_id) | ||
1719 | { | ||
1720 | u32 fdirhash; | ||
1721 | u32 fdircmd = 0; | ||
1722 | u32 retry_count; | ||
1723 | s32 err = 0; | ||
1724 | |||
1725 | /* configure FDIRHASH register */ | ||
1726 | fdirhash = input->formatted.bkt_hash; | ||
1727 | fdirhash |= soft_id << IXGBE_FDIRHASH_SIG_SW_INDEX_SHIFT; | ||
1728 | IXGBE_WRITE_REG(hw, IXGBE_FDIRHASH, fdirhash); | ||
1729 | |||
1730 | /* flush hash to HW */ | ||
1731 | IXGBE_WRITE_FLUSH(hw); | ||
1732 | |||
1733 | /* Query if filter is present */ | ||
1734 | IXGBE_WRITE_REG(hw, IXGBE_FDIRCMD, IXGBE_FDIRCMD_CMD_QUERY_REM_FILT); | ||
1735 | |||
1736 | for (retry_count = 10; retry_count; retry_count--) { | ||
1737 | /* allow 10us for query to process */ | ||
1738 | udelay(10); | ||
1739 | /* verify query completed successfully */ | ||
1740 | fdircmd = IXGBE_READ_REG(hw, IXGBE_FDIRCMD); | ||
1741 | if (!(fdircmd & IXGBE_FDIRCMD_CMD_MASK)) | ||
1742 | break; | ||
1743 | } | ||
1744 | |||
1745 | if (!retry_count) | ||
1746 | err = IXGBE_ERR_FDIR_REINIT_FAILED; | ||
1747 | |||
1748 | /* if filter exists in hardware then remove it */ | ||
1749 | if (fdircmd & IXGBE_FDIRCMD_FILTER_VALID) { | ||
1750 | IXGBE_WRITE_REG(hw, IXGBE_FDIRHASH, fdirhash); | ||
1751 | IXGBE_WRITE_FLUSH(hw); | ||
1752 | IXGBE_WRITE_REG(hw, IXGBE_FDIRCMD, | ||
1753 | IXGBE_FDIRCMD_CMD_REMOVE_FLOW); | ||
1754 | } | ||
1755 | |||
1756 | return err; | ||
1757 | } | ||
1758 | |||
1759 | /** | ||
1760 | * ixgbe_read_analog_reg8_82599 - Reads 8 bit Omer analog register | ||
1761 | * @hw: pointer to hardware structure | ||
1762 | * @reg: analog register to read | ||
1763 | * @val: read value | ||
1764 | * | ||
1765 | * Performs read operation to Omer analog register specified. | ||
1766 | **/ | ||
1767 | static s32 ixgbe_read_analog_reg8_82599(struct ixgbe_hw *hw, u32 reg, u8 *val) | ||
1768 | { | ||
1769 | u32 core_ctl; | ||
1770 | |||
1771 | IXGBE_WRITE_REG(hw, IXGBE_CORECTL, IXGBE_CORECTL_WRITE_CMD | | ||
1772 | (reg << 8)); | ||
1773 | IXGBE_WRITE_FLUSH(hw); | ||
1774 | udelay(10); | ||
1775 | core_ctl = IXGBE_READ_REG(hw, IXGBE_CORECTL); | ||
1776 | *val = (u8)core_ctl; | ||
1777 | |||
1778 | return 0; | ||
1779 | } | ||
1780 | |||
1781 | /** | ||
1782 | * ixgbe_write_analog_reg8_82599 - Writes 8 bit Omer analog register | ||
1783 | * @hw: pointer to hardware structure | ||
1784 | * @reg: atlas register to write | ||
1785 | * @val: value to write | ||
1786 | * | ||
1787 | * Performs write operation to Omer analog register specified. | ||
1788 | **/ | ||
1789 | static s32 ixgbe_write_analog_reg8_82599(struct ixgbe_hw *hw, u32 reg, u8 val) | ||
1790 | { | ||
1791 | u32 core_ctl; | ||
1792 | |||
1793 | core_ctl = (reg << 8) | val; | ||
1794 | IXGBE_WRITE_REG(hw, IXGBE_CORECTL, core_ctl); | ||
1795 | IXGBE_WRITE_FLUSH(hw); | ||
1796 | udelay(10); | ||
1797 | |||
1798 | return 0; | ||
1799 | } | ||
1800 | |||
1801 | /** | ||
1802 | * ixgbe_start_hw_82599 - Prepare hardware for Tx/Rx | ||
1803 | * @hw: pointer to hardware structure | ||
1804 | * | ||
1805 | * Starts the hardware using the generic start_hw function | ||
1806 | * and the generation start_hw function. | ||
1807 | * Then performs revision-specific operations, if any. | ||
1808 | **/ | ||
1809 | static s32 ixgbe_start_hw_82599(struct ixgbe_hw *hw) | ||
1810 | { | ||
1811 | s32 ret_val = 0; | ||
1812 | |||
1813 | ret_val = ixgbe_start_hw_generic(hw); | ||
1814 | if (ret_val != 0) | ||
1815 | goto out; | ||
1816 | |||
1817 | ret_val = ixgbe_start_hw_gen2(hw); | ||
1818 | if (ret_val != 0) | ||
1819 | goto out; | ||
1820 | |||
1821 | /* We need to run link autotry after the driver loads */ | ||
1822 | hw->mac.autotry_restart = true; | ||
1823 | hw->mac.rx_pb_size = IXGBE_82599_RX_PB_SIZE; | ||
1824 | |||
1825 | if (ret_val == 0) | ||
1826 | ret_val = ixgbe_verify_fw_version_82599(hw); | ||
1827 | out: | ||
1828 | return ret_val; | ||
1829 | } | ||
1830 | |||
1831 | /** | ||
1832 | * ixgbe_identify_phy_82599 - Get physical layer module | ||
1833 | * @hw: pointer to hardware structure | ||
1834 | * | ||
1835 | * Determines the physical layer module found on the current adapter. | ||
1836 | * If PHY already detected, maintains current PHY type in hw struct, | ||
1837 | * otherwise executes the PHY detection routine. | ||
1838 | **/ | ||
1839 | static s32 ixgbe_identify_phy_82599(struct ixgbe_hw *hw) | ||
1840 | { | ||
1841 | s32 status = IXGBE_ERR_PHY_ADDR_INVALID; | ||
1842 | |||
1843 | /* Detect PHY if not unknown - returns success if already detected. */ | ||
1844 | status = ixgbe_identify_phy_generic(hw); | ||
1845 | if (status != 0) { | ||
1846 | /* 82599 10GBASE-T requires an external PHY */ | ||
1847 | if (hw->mac.ops.get_media_type(hw) == ixgbe_media_type_copper) | ||
1848 | goto out; | ||
1849 | else | ||
1850 | status = ixgbe_identify_sfp_module_generic(hw); | ||
1851 | } | ||
1852 | |||
1853 | /* Set PHY type none if no PHY detected */ | ||
1854 | if (hw->phy.type == ixgbe_phy_unknown) { | ||
1855 | hw->phy.type = ixgbe_phy_none; | ||
1856 | status = 0; | ||
1857 | } | ||
1858 | |||
1859 | /* Return error if SFP module has been detected but is not supported */ | ||
1860 | if (hw->phy.type == ixgbe_phy_sfp_unsupported) | ||
1861 | status = IXGBE_ERR_SFP_NOT_SUPPORTED; | ||
1862 | |||
1863 | out: | ||
1864 | return status; | ||
1865 | } | ||
1866 | |||
1867 | /** | ||
1868 | * ixgbe_get_supported_physical_layer_82599 - Returns physical layer type | ||
1869 | * @hw: pointer to hardware structure | ||
1870 | * | ||
1871 | * Determines physical layer capabilities of the current configuration. | ||
1872 | **/ | ||
1873 | static u32 ixgbe_get_supported_physical_layer_82599(struct ixgbe_hw *hw) | ||
1874 | { | ||
1875 | u32 physical_layer = IXGBE_PHYSICAL_LAYER_UNKNOWN; | ||
1876 | u32 autoc = IXGBE_READ_REG(hw, IXGBE_AUTOC); | ||
1877 | u32 autoc2 = IXGBE_READ_REG(hw, IXGBE_AUTOC2); | ||
1878 | u32 pma_pmd_10g_serial = autoc2 & IXGBE_AUTOC2_10G_SERIAL_PMA_PMD_MASK; | ||
1879 | u32 pma_pmd_10g_parallel = autoc & IXGBE_AUTOC_10G_PMA_PMD_MASK; | ||
1880 | u32 pma_pmd_1g = autoc & IXGBE_AUTOC_1G_PMA_PMD_MASK; | ||
1881 | u16 ext_ability = 0; | ||
1882 | u8 comp_codes_10g = 0; | ||
1883 | u8 comp_codes_1g = 0; | ||
1884 | |||
1885 | hw->phy.ops.identify(hw); | ||
1886 | |||
1887 | switch (hw->phy.type) { | ||
1888 | case ixgbe_phy_tn: | ||
1889 | case ixgbe_phy_aq: | ||
1890 | case ixgbe_phy_cu_unknown: | ||
1891 | hw->phy.ops.read_reg(hw, MDIO_PMA_EXTABLE, MDIO_MMD_PMAPMD, | ||
1892 | &ext_ability); | ||
1893 | if (ext_ability & MDIO_PMA_EXTABLE_10GBT) | ||
1894 | physical_layer |= IXGBE_PHYSICAL_LAYER_10GBASE_T; | ||
1895 | if (ext_ability & MDIO_PMA_EXTABLE_1000BT) | ||
1896 | physical_layer |= IXGBE_PHYSICAL_LAYER_1000BASE_T; | ||
1897 | if (ext_ability & MDIO_PMA_EXTABLE_100BTX) | ||
1898 | physical_layer |= IXGBE_PHYSICAL_LAYER_100BASE_TX; | ||
1899 | goto out; | ||
1900 | default: | ||
1901 | break; | ||
1902 | } | ||
1903 | |||
1904 | switch (autoc & IXGBE_AUTOC_LMS_MASK) { | ||
1905 | case IXGBE_AUTOC_LMS_1G_AN: | ||
1906 | case IXGBE_AUTOC_LMS_1G_LINK_NO_AN: | ||
1907 | if (pma_pmd_1g == IXGBE_AUTOC_1G_KX_BX) { | ||
1908 | physical_layer = IXGBE_PHYSICAL_LAYER_1000BASE_KX | | ||
1909 | IXGBE_PHYSICAL_LAYER_1000BASE_BX; | ||
1910 | goto out; | ||
1911 | } else | ||
1912 | /* SFI mode so read SFP module */ | ||
1913 | goto sfp_check; | ||
1914 | break; | ||
1915 | case IXGBE_AUTOC_LMS_10G_LINK_NO_AN: | ||
1916 | if (pma_pmd_10g_parallel == IXGBE_AUTOC_10G_CX4) | ||
1917 | physical_layer = IXGBE_PHYSICAL_LAYER_10GBASE_CX4; | ||
1918 | else if (pma_pmd_10g_parallel == IXGBE_AUTOC_10G_KX4) | ||
1919 | physical_layer = IXGBE_PHYSICAL_LAYER_10GBASE_KX4; | ||
1920 | else if (pma_pmd_10g_parallel == IXGBE_AUTOC_10G_XAUI) | ||
1921 | physical_layer = IXGBE_PHYSICAL_LAYER_10GBASE_XAUI; | ||
1922 | goto out; | ||
1923 | break; | ||
1924 | case IXGBE_AUTOC_LMS_10G_SERIAL: | ||
1925 | if (pma_pmd_10g_serial == IXGBE_AUTOC2_10G_KR) { | ||
1926 | physical_layer = IXGBE_PHYSICAL_LAYER_10GBASE_KR; | ||
1927 | goto out; | ||
1928 | } else if (pma_pmd_10g_serial == IXGBE_AUTOC2_10G_SFI) | ||
1929 | goto sfp_check; | ||
1930 | break; | ||
1931 | case IXGBE_AUTOC_LMS_KX4_KX_KR: | ||
1932 | case IXGBE_AUTOC_LMS_KX4_KX_KR_1G_AN: | ||
1933 | if (autoc & IXGBE_AUTOC_KX_SUPP) | ||
1934 | physical_layer |= IXGBE_PHYSICAL_LAYER_1000BASE_KX; | ||
1935 | if (autoc & IXGBE_AUTOC_KX4_SUPP) | ||
1936 | physical_layer |= IXGBE_PHYSICAL_LAYER_10GBASE_KX4; | ||
1937 | if (autoc & IXGBE_AUTOC_KR_SUPP) | ||
1938 | physical_layer |= IXGBE_PHYSICAL_LAYER_10GBASE_KR; | ||
1939 | goto out; | ||
1940 | break; | ||
1941 | default: | ||
1942 | goto out; | ||
1943 | break; | ||
1944 | } | ||
1945 | |||
1946 | sfp_check: | ||
1947 | /* SFP check must be done last since DA modules are sometimes used to | ||
1948 | * test KR mode - we need to id KR mode correctly before SFP module. | ||
1949 | * Call identify_sfp because the pluggable module may have changed */ | ||
1950 | hw->phy.ops.identify_sfp(hw); | ||
1951 | if (hw->phy.sfp_type == ixgbe_sfp_type_not_present) | ||
1952 | goto out; | ||
1953 | |||
1954 | switch (hw->phy.type) { | ||
1955 | case ixgbe_phy_sfp_passive_tyco: | ||
1956 | case ixgbe_phy_sfp_passive_unknown: | ||
1957 | physical_layer = IXGBE_PHYSICAL_LAYER_SFP_PLUS_CU; | ||
1958 | break; | ||
1959 | case ixgbe_phy_sfp_ftl_active: | ||
1960 | case ixgbe_phy_sfp_active_unknown: | ||
1961 | physical_layer = IXGBE_PHYSICAL_LAYER_SFP_ACTIVE_DA; | ||
1962 | break; | ||
1963 | case ixgbe_phy_sfp_avago: | ||
1964 | case ixgbe_phy_sfp_ftl: | ||
1965 | case ixgbe_phy_sfp_intel: | ||
1966 | case ixgbe_phy_sfp_unknown: | ||
1967 | hw->phy.ops.read_i2c_eeprom(hw, | ||
1968 | IXGBE_SFF_1GBE_COMP_CODES, &comp_codes_1g); | ||
1969 | hw->phy.ops.read_i2c_eeprom(hw, | ||
1970 | IXGBE_SFF_10GBE_COMP_CODES, &comp_codes_10g); | ||
1971 | if (comp_codes_10g & IXGBE_SFF_10GBASESR_CAPABLE) | ||
1972 | physical_layer = IXGBE_PHYSICAL_LAYER_10GBASE_SR; | ||
1973 | else if (comp_codes_10g & IXGBE_SFF_10GBASELR_CAPABLE) | ||
1974 | physical_layer = IXGBE_PHYSICAL_LAYER_10GBASE_LR; | ||
1975 | else if (comp_codes_1g & IXGBE_SFF_1GBASET_CAPABLE) | ||
1976 | physical_layer = IXGBE_PHYSICAL_LAYER_1000BASE_T; | ||
1977 | break; | ||
1978 | default: | ||
1979 | break; | ||
1980 | } | ||
1981 | |||
1982 | out: | ||
1983 | return physical_layer; | ||
1984 | } | ||
1985 | |||
1986 | /** | ||
1987 | * ixgbe_enable_rx_dma_82599 - Enable the Rx DMA unit on 82599 | ||
1988 | * @hw: pointer to hardware structure | ||
1989 | * @regval: register value to write to RXCTRL | ||
1990 | * | ||
1991 | * Enables the Rx DMA unit for 82599 | ||
1992 | **/ | ||
1993 | static s32 ixgbe_enable_rx_dma_82599(struct ixgbe_hw *hw, u32 regval) | ||
1994 | { | ||
1995 | #define IXGBE_MAX_SECRX_POLL 30 | ||
1996 | int i; | ||
1997 | int secrxreg; | ||
1998 | |||
1999 | /* | ||
2000 | * Workaround for 82599 silicon errata when enabling the Rx datapath. | ||
2001 | * If traffic is incoming before we enable the Rx unit, it could hang | ||
2002 | * the Rx DMA unit. Therefore, make sure the security engine is | ||
2003 | * completely disabled prior to enabling the Rx unit. | ||
2004 | */ | ||
2005 | secrxreg = IXGBE_READ_REG(hw, IXGBE_SECRXCTRL); | ||
2006 | secrxreg |= IXGBE_SECRXCTRL_RX_DIS; | ||
2007 | IXGBE_WRITE_REG(hw, IXGBE_SECRXCTRL, secrxreg); | ||
2008 | for (i = 0; i < IXGBE_MAX_SECRX_POLL; i++) { | ||
2009 | secrxreg = IXGBE_READ_REG(hw, IXGBE_SECRXSTAT); | ||
2010 | if (secrxreg & IXGBE_SECRXSTAT_SECRX_RDY) | ||
2011 | break; | ||
2012 | else | ||
2013 | /* Use interrupt-safe sleep just in case */ | ||
2014 | udelay(10); | ||
2015 | } | ||
2016 | |||
2017 | /* For informational purposes only */ | ||
2018 | if (i >= IXGBE_MAX_SECRX_POLL) | ||
2019 | hw_dbg(hw, "Rx unit being enabled before security " | ||
2020 | "path fully disabled. Continuing with init.\n"); | ||
2021 | |||
2022 | IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, regval); | ||
2023 | secrxreg = IXGBE_READ_REG(hw, IXGBE_SECRXCTRL); | ||
2024 | secrxreg &= ~IXGBE_SECRXCTRL_RX_DIS; | ||
2025 | IXGBE_WRITE_REG(hw, IXGBE_SECRXCTRL, secrxreg); | ||
2026 | IXGBE_WRITE_FLUSH(hw); | ||
2027 | |||
2028 | return 0; | ||
2029 | } | ||
2030 | |||
2031 | /** | ||
2032 | * ixgbe_verify_fw_version_82599 - verify fw version for 82599 | ||
2033 | * @hw: pointer to hardware structure | ||
2034 | * | ||
2035 | * Verifies that installed the firmware version is 0.6 or higher | ||
2036 | * for SFI devices. All 82599 SFI devices should have version 0.6 or higher. | ||
2037 | * | ||
2038 | * Returns IXGBE_ERR_EEPROM_VERSION if the FW is not present or | ||
2039 | * if the FW version is not supported. | ||
2040 | **/ | ||
2041 | static s32 ixgbe_verify_fw_version_82599(struct ixgbe_hw *hw) | ||
2042 | { | ||
2043 | s32 status = IXGBE_ERR_EEPROM_VERSION; | ||
2044 | u16 fw_offset, fw_ptp_cfg_offset; | ||
2045 | u16 fw_version = 0; | ||
2046 | |||
2047 | /* firmware check is only necessary for SFI devices */ | ||
2048 | if (hw->phy.media_type != ixgbe_media_type_fiber) { | ||
2049 | status = 0; | ||
2050 | goto fw_version_out; | ||
2051 | } | ||
2052 | |||
2053 | /* get the offset to the Firmware Module block */ | ||
2054 | hw->eeprom.ops.read(hw, IXGBE_FW_PTR, &fw_offset); | ||
2055 | |||
2056 | if ((fw_offset == 0) || (fw_offset == 0xFFFF)) | ||
2057 | goto fw_version_out; | ||
2058 | |||
2059 | /* get the offset to the Pass Through Patch Configuration block */ | ||
2060 | hw->eeprom.ops.read(hw, (fw_offset + | ||
2061 | IXGBE_FW_PASSTHROUGH_PATCH_CONFIG_PTR), | ||
2062 | &fw_ptp_cfg_offset); | ||
2063 | |||
2064 | if ((fw_ptp_cfg_offset == 0) || (fw_ptp_cfg_offset == 0xFFFF)) | ||
2065 | goto fw_version_out; | ||
2066 | |||
2067 | /* get the firmware version */ | ||
2068 | hw->eeprom.ops.read(hw, (fw_ptp_cfg_offset + | ||
2069 | IXGBE_FW_PATCH_VERSION_4), | ||
2070 | &fw_version); | ||
2071 | |||
2072 | if (fw_version > 0x5) | ||
2073 | status = 0; | ||
2074 | |||
2075 | fw_version_out: | ||
2076 | return status; | ||
2077 | } | ||
2078 | |||
2079 | /** | ||
2080 | * ixgbe_verify_lesm_fw_enabled_82599 - Checks LESM FW module state. | ||
2081 | * @hw: pointer to hardware structure | ||
2082 | * | ||
2083 | * Returns true if the LESM FW module is present and enabled. Otherwise | ||
2084 | * returns false. Smart Speed must be disabled if LESM FW module is enabled. | ||
2085 | **/ | ||
2086 | static bool ixgbe_verify_lesm_fw_enabled_82599(struct ixgbe_hw *hw) | ||
2087 | { | ||
2088 | bool lesm_enabled = false; | ||
2089 | u16 fw_offset, fw_lesm_param_offset, fw_lesm_state; | ||
2090 | s32 status; | ||
2091 | |||
2092 | /* get the offset to the Firmware Module block */ | ||
2093 | status = hw->eeprom.ops.read(hw, IXGBE_FW_PTR, &fw_offset); | ||
2094 | |||
2095 | if ((status != 0) || | ||
2096 | (fw_offset == 0) || (fw_offset == 0xFFFF)) | ||
2097 | goto out; | ||
2098 | |||
2099 | /* get the offset to the LESM Parameters block */ | ||
2100 | status = hw->eeprom.ops.read(hw, (fw_offset + | ||
2101 | IXGBE_FW_LESM_PARAMETERS_PTR), | ||
2102 | &fw_lesm_param_offset); | ||
2103 | |||
2104 | if ((status != 0) || | ||
2105 | (fw_lesm_param_offset == 0) || (fw_lesm_param_offset == 0xFFFF)) | ||
2106 | goto out; | ||
2107 | |||
2108 | /* get the lesm state word */ | ||
2109 | status = hw->eeprom.ops.read(hw, (fw_lesm_param_offset + | ||
2110 | IXGBE_FW_LESM_STATE_1), | ||
2111 | &fw_lesm_state); | ||
2112 | |||
2113 | if ((status == 0) && | ||
2114 | (fw_lesm_state & IXGBE_FW_LESM_STATE_ENABLED)) | ||
2115 | lesm_enabled = true; | ||
2116 | |||
2117 | out: | ||
2118 | return lesm_enabled; | ||
2119 | } | ||
2120 | |||
2121 | /** | ||
2122 | * ixgbe_read_eeprom_buffer_82599 - Read EEPROM word(s) using | ||
2123 | * fastest available method | ||
2124 | * | ||
2125 | * @hw: pointer to hardware structure | ||
2126 | * @offset: offset of word in EEPROM to read | ||
2127 | * @words: number of words | ||
2128 | * @data: word(s) read from the EEPROM | ||
2129 | * | ||
2130 | * Retrieves 16 bit word(s) read from EEPROM | ||
2131 | **/ | ||
2132 | static s32 ixgbe_read_eeprom_buffer_82599(struct ixgbe_hw *hw, u16 offset, | ||
2133 | u16 words, u16 *data) | ||
2134 | { | ||
2135 | struct ixgbe_eeprom_info *eeprom = &hw->eeprom; | ||
2136 | s32 ret_val = IXGBE_ERR_CONFIG; | ||
2137 | |||
2138 | /* | ||
2139 | * If EEPROM is detected and can be addressed using 14 bits, | ||
2140 | * use EERD otherwise use bit bang | ||
2141 | */ | ||
2142 | if ((eeprom->type == ixgbe_eeprom_spi) && | ||
2143 | (offset + (words - 1) <= IXGBE_EERD_MAX_ADDR)) | ||
2144 | ret_val = ixgbe_read_eerd_buffer_generic(hw, offset, words, | ||
2145 | data); | ||
2146 | else | ||
2147 | ret_val = ixgbe_read_eeprom_buffer_bit_bang_generic(hw, offset, | ||
2148 | words, | ||
2149 | data); | ||
2150 | |||
2151 | return ret_val; | ||
2152 | } | ||
2153 | |||
2154 | /** | ||
2155 | * ixgbe_read_eeprom_82599 - Read EEPROM word using | ||
2156 | * fastest available method | ||
2157 | * | ||
2158 | * @hw: pointer to hardware structure | ||
2159 | * @offset: offset of word in the EEPROM to read | ||
2160 | * @data: word read from the EEPROM | ||
2161 | * | ||
2162 | * Reads a 16 bit word from the EEPROM | ||
2163 | **/ | ||
2164 | static s32 ixgbe_read_eeprom_82599(struct ixgbe_hw *hw, | ||
2165 | u16 offset, u16 *data) | ||
2166 | { | ||
2167 | struct ixgbe_eeprom_info *eeprom = &hw->eeprom; | ||
2168 | s32 ret_val = IXGBE_ERR_CONFIG; | ||
2169 | |||
2170 | /* | ||
2171 | * If EEPROM is detected and can be addressed using 14 bits, | ||
2172 | * use EERD otherwise use bit bang | ||
2173 | */ | ||
2174 | if ((eeprom->type == ixgbe_eeprom_spi) && | ||
2175 | (offset <= IXGBE_EERD_MAX_ADDR)) | ||
2176 | ret_val = ixgbe_read_eerd_generic(hw, offset, data); | ||
2177 | else | ||
2178 | ret_val = ixgbe_read_eeprom_bit_bang_generic(hw, offset, data); | ||
2179 | |||
2180 | return ret_val; | ||
2181 | } | ||
2182 | |||
2183 | static struct ixgbe_mac_operations mac_ops_82599 = { | ||
2184 | .init_hw = &ixgbe_init_hw_generic, | ||
2185 | .reset_hw = &ixgbe_reset_hw_82599, | ||
2186 | .start_hw = &ixgbe_start_hw_82599, | ||
2187 | .clear_hw_cntrs = &ixgbe_clear_hw_cntrs_generic, | ||
2188 | .get_media_type = &ixgbe_get_media_type_82599, | ||
2189 | .get_supported_physical_layer = &ixgbe_get_supported_physical_layer_82599, | ||
2190 | .enable_rx_dma = &ixgbe_enable_rx_dma_82599, | ||
2191 | .get_mac_addr = &ixgbe_get_mac_addr_generic, | ||
2192 | .get_san_mac_addr = &ixgbe_get_san_mac_addr_generic, | ||
2193 | .get_device_caps = &ixgbe_get_device_caps_generic, | ||
2194 | .get_wwn_prefix = &ixgbe_get_wwn_prefix_generic, | ||
2195 | .stop_adapter = &ixgbe_stop_adapter_generic, | ||
2196 | .get_bus_info = &ixgbe_get_bus_info_generic, | ||
2197 | .set_lan_id = &ixgbe_set_lan_id_multi_port_pcie, | ||
2198 | .read_analog_reg8 = &ixgbe_read_analog_reg8_82599, | ||
2199 | .write_analog_reg8 = &ixgbe_write_analog_reg8_82599, | ||
2200 | .setup_link = &ixgbe_setup_mac_link_82599, | ||
2201 | .set_rxpba = &ixgbe_set_rxpba_generic, | ||
2202 | .check_link = &ixgbe_check_mac_link_generic, | ||
2203 | .get_link_capabilities = &ixgbe_get_link_capabilities_82599, | ||
2204 | .led_on = &ixgbe_led_on_generic, | ||
2205 | .led_off = &ixgbe_led_off_generic, | ||
2206 | .blink_led_start = &ixgbe_blink_led_start_generic, | ||
2207 | .blink_led_stop = &ixgbe_blink_led_stop_generic, | ||
2208 | .set_rar = &ixgbe_set_rar_generic, | ||
2209 | .clear_rar = &ixgbe_clear_rar_generic, | ||
2210 | .set_vmdq = &ixgbe_set_vmdq_generic, | ||
2211 | .clear_vmdq = &ixgbe_clear_vmdq_generic, | ||
2212 | .init_rx_addrs = &ixgbe_init_rx_addrs_generic, | ||
2213 | .update_mc_addr_list = &ixgbe_update_mc_addr_list_generic, | ||
2214 | .enable_mc = &ixgbe_enable_mc_generic, | ||
2215 | .disable_mc = &ixgbe_disable_mc_generic, | ||
2216 | .clear_vfta = &ixgbe_clear_vfta_generic, | ||
2217 | .set_vfta = &ixgbe_set_vfta_generic, | ||
2218 | .fc_enable = &ixgbe_fc_enable_generic, | ||
2219 | .set_fw_drv_ver = &ixgbe_set_fw_drv_ver_generic, | ||
2220 | .init_uta_tables = &ixgbe_init_uta_tables_generic, | ||
2221 | .setup_sfp = &ixgbe_setup_sfp_modules_82599, | ||
2222 | .set_mac_anti_spoofing = &ixgbe_set_mac_anti_spoofing, | ||
2223 | .set_vlan_anti_spoofing = &ixgbe_set_vlan_anti_spoofing, | ||
2224 | .acquire_swfw_sync = &ixgbe_acquire_swfw_sync, | ||
2225 | .release_swfw_sync = &ixgbe_release_swfw_sync, | ||
2226 | |||
2227 | }; | ||
2228 | |||
2229 | static struct ixgbe_eeprom_operations eeprom_ops_82599 = { | ||
2230 | .init_params = &ixgbe_init_eeprom_params_generic, | ||
2231 | .read = &ixgbe_read_eeprom_82599, | ||
2232 | .read_buffer = &ixgbe_read_eeprom_buffer_82599, | ||
2233 | .write = &ixgbe_write_eeprom_generic, | ||
2234 | .write_buffer = &ixgbe_write_eeprom_buffer_bit_bang_generic, | ||
2235 | .calc_checksum = &ixgbe_calc_eeprom_checksum_generic, | ||
2236 | .validate_checksum = &ixgbe_validate_eeprom_checksum_generic, | ||
2237 | .update_checksum = &ixgbe_update_eeprom_checksum_generic, | ||
2238 | }; | ||
2239 | |||
2240 | static struct ixgbe_phy_operations phy_ops_82599 = { | ||
2241 | .identify = &ixgbe_identify_phy_82599, | ||
2242 | .identify_sfp = &ixgbe_identify_sfp_module_generic, | ||
2243 | .init = &ixgbe_init_phy_ops_82599, | ||
2244 | .reset = &ixgbe_reset_phy_generic, | ||
2245 | .read_reg = &ixgbe_read_phy_reg_generic, | ||
2246 | .write_reg = &ixgbe_write_phy_reg_generic, | ||
2247 | .setup_link = &ixgbe_setup_phy_link_generic, | ||
2248 | .setup_link_speed = &ixgbe_setup_phy_link_speed_generic, | ||
2249 | .read_i2c_byte = &ixgbe_read_i2c_byte_generic, | ||
2250 | .write_i2c_byte = &ixgbe_write_i2c_byte_generic, | ||
2251 | .read_i2c_eeprom = &ixgbe_read_i2c_eeprom_generic, | ||
2252 | .write_i2c_eeprom = &ixgbe_write_i2c_eeprom_generic, | ||
2253 | .check_overtemp = &ixgbe_tn_check_overtemp, | ||
2254 | }; | ||
2255 | |||
2256 | struct ixgbe_info ixgbe_82599_info = { | ||
2257 | .mac = ixgbe_mac_82599EB, | ||
2258 | .get_invariants = &ixgbe_get_invariants_82599, | ||
2259 | .mac_ops = &mac_ops_82599, | ||
2260 | .eeprom_ops = &eeprom_ops_82599, | ||
2261 | .phy_ops = &phy_ops_82599, | ||
2262 | .mbx_ops = &mbx_ops_generic, | ||
2263 | }; | ||
diff --git a/drivers/net/ixgbe/ixgbe_common.c b/drivers/net/ixgbe/ixgbe_common.c new file mode 100644 index 00000000000..fc1375f26fe --- /dev/null +++ b/drivers/net/ixgbe/ixgbe_common.c | |||
@@ -0,0 +1,3510 @@ | |||
1 | /******************************************************************************* | ||
2 | |||
3 | Intel 10 Gigabit PCI Express Linux driver | ||
4 | Copyright(c) 1999 - 2011 Intel Corporation. | ||
5 | |||
6 | This program is free software; you can redistribute it and/or modify it | ||
7 | under the terms and conditions of the GNU General Public License, | ||
8 | version 2, as published by the Free Software Foundation. | ||
9 | |||
10 | This program is distributed in the hope it will be useful, but WITHOUT | ||
11 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
12 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
13 | more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License along with | ||
16 | this program; if not, write to the Free Software Foundation, Inc., | ||
17 | 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. | ||
18 | |||
19 | The full GNU General Public License is included in this distribution in | ||
20 | the file called "COPYING". | ||
21 | |||
22 | Contact Information: | ||
23 | e1000-devel Mailing List <e1000-devel@lists.sourceforge.net> | ||
24 | Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 | ||
25 | |||
26 | *******************************************************************************/ | ||
27 | |||
28 | #include <linux/pci.h> | ||
29 | #include <linux/delay.h> | ||
30 | #include <linux/sched.h> | ||
31 | #include <linux/netdevice.h> | ||
32 | |||
33 | #include "ixgbe.h" | ||
34 | #include "ixgbe_common.h" | ||
35 | #include "ixgbe_phy.h" | ||
36 | |||
37 | static s32 ixgbe_acquire_eeprom(struct ixgbe_hw *hw); | ||
38 | static s32 ixgbe_get_eeprom_semaphore(struct ixgbe_hw *hw); | ||
39 | static void ixgbe_release_eeprom_semaphore(struct ixgbe_hw *hw); | ||
40 | static s32 ixgbe_ready_eeprom(struct ixgbe_hw *hw); | ||
41 | static void ixgbe_standby_eeprom(struct ixgbe_hw *hw); | ||
42 | static void ixgbe_shift_out_eeprom_bits(struct ixgbe_hw *hw, u16 data, | ||
43 | u16 count); | ||
44 | static u16 ixgbe_shift_in_eeprom_bits(struct ixgbe_hw *hw, u16 count); | ||
45 | static void ixgbe_raise_eeprom_clk(struct ixgbe_hw *hw, u32 *eec); | ||
46 | static void ixgbe_lower_eeprom_clk(struct ixgbe_hw *hw, u32 *eec); | ||
47 | static void ixgbe_release_eeprom(struct ixgbe_hw *hw); | ||
48 | |||
49 | static s32 ixgbe_mta_vector(struct ixgbe_hw *hw, u8 *mc_addr); | ||
50 | static s32 ixgbe_fc_autoneg_fiber(struct ixgbe_hw *hw); | ||
51 | static s32 ixgbe_fc_autoneg_backplane(struct ixgbe_hw *hw); | ||
52 | static s32 ixgbe_fc_autoneg_copper(struct ixgbe_hw *hw); | ||
53 | static s32 ixgbe_device_supports_autoneg_fc(struct ixgbe_hw *hw); | ||
54 | static s32 ixgbe_negotiate_fc(struct ixgbe_hw *hw, u32 adv_reg, u32 lp_reg, | ||
55 | u32 adv_sym, u32 adv_asm, u32 lp_sym, u32 lp_asm); | ||
56 | static s32 ixgbe_setup_fc(struct ixgbe_hw *hw, s32 packetbuf_num); | ||
57 | static s32 ixgbe_poll_eerd_eewr_done(struct ixgbe_hw *hw, u32 ee_reg); | ||
58 | static s32 ixgbe_read_eeprom_buffer_bit_bang(struct ixgbe_hw *hw, u16 offset, | ||
59 | u16 words, u16 *data); | ||
60 | static s32 ixgbe_write_eeprom_buffer_bit_bang(struct ixgbe_hw *hw, u16 offset, | ||
61 | u16 words, u16 *data); | ||
62 | static s32 ixgbe_detect_eeprom_page_size_generic(struct ixgbe_hw *hw, | ||
63 | u16 offset); | ||
64 | |||
65 | /** | ||
66 | * ixgbe_start_hw_generic - Prepare hardware for Tx/Rx | ||
67 | * @hw: pointer to hardware structure | ||
68 | * | ||
69 | * Starts the hardware by filling the bus info structure and media type, clears | ||
70 | * all on chip counters, initializes receive address registers, multicast | ||
71 | * table, VLAN filter table, calls routine to set up link and flow control | ||
72 | * settings, and leaves transmit and receive units disabled and uninitialized | ||
73 | **/ | ||
74 | s32 ixgbe_start_hw_generic(struct ixgbe_hw *hw) | ||
75 | { | ||
76 | u32 ctrl_ext; | ||
77 | |||
78 | /* Set the media type */ | ||
79 | hw->phy.media_type = hw->mac.ops.get_media_type(hw); | ||
80 | |||
81 | /* Identify the PHY */ | ||
82 | hw->phy.ops.identify(hw); | ||
83 | |||
84 | /* Clear the VLAN filter table */ | ||
85 | hw->mac.ops.clear_vfta(hw); | ||
86 | |||
87 | /* Clear statistics registers */ | ||
88 | hw->mac.ops.clear_hw_cntrs(hw); | ||
89 | |||
90 | /* Set No Snoop Disable */ | ||
91 | ctrl_ext = IXGBE_READ_REG(hw, IXGBE_CTRL_EXT); | ||
92 | ctrl_ext |= IXGBE_CTRL_EXT_NS_DIS; | ||
93 | IXGBE_WRITE_REG(hw, IXGBE_CTRL_EXT, ctrl_ext); | ||
94 | IXGBE_WRITE_FLUSH(hw); | ||
95 | |||
96 | /* Setup flow control */ | ||
97 | ixgbe_setup_fc(hw, 0); | ||
98 | |||
99 | /* Clear adapter stopped flag */ | ||
100 | hw->adapter_stopped = false; | ||
101 | |||
102 | return 0; | ||
103 | } | ||
104 | |||
105 | /** | ||
106 | * ixgbe_start_hw_gen2 - Init sequence for common device family | ||
107 | * @hw: pointer to hw structure | ||
108 | * | ||
109 | * Performs the init sequence common to the second generation | ||
110 | * of 10 GbE devices. | ||
111 | * Devices in the second generation: | ||
112 | * 82599 | ||
113 | * X540 | ||
114 | **/ | ||
115 | s32 ixgbe_start_hw_gen2(struct ixgbe_hw *hw) | ||
116 | { | ||
117 | u32 i; | ||
118 | u32 regval; | ||
119 | |||
120 | /* Clear the rate limiters */ | ||
121 | for (i = 0; i < hw->mac.max_tx_queues; i++) { | ||
122 | IXGBE_WRITE_REG(hw, IXGBE_RTTDQSEL, i); | ||
123 | IXGBE_WRITE_REG(hw, IXGBE_RTTBCNRC, 0); | ||
124 | } | ||
125 | IXGBE_WRITE_FLUSH(hw); | ||
126 | |||
127 | /* Disable relaxed ordering */ | ||
128 | for (i = 0; i < hw->mac.max_tx_queues; i++) { | ||
129 | regval = IXGBE_READ_REG(hw, IXGBE_DCA_TXCTRL_82599(i)); | ||
130 | regval &= ~IXGBE_DCA_TXCTRL_TX_WB_RO_EN; | ||
131 | IXGBE_WRITE_REG(hw, IXGBE_DCA_TXCTRL_82599(i), regval); | ||
132 | } | ||
133 | |||
134 | for (i = 0; i < hw->mac.max_rx_queues; i++) { | ||
135 | regval = IXGBE_READ_REG(hw, IXGBE_DCA_RXCTRL(i)); | ||
136 | regval &= ~(IXGBE_DCA_RXCTRL_DESC_WRO_EN | | ||
137 | IXGBE_DCA_RXCTRL_DESC_HSRO_EN); | ||
138 | IXGBE_WRITE_REG(hw, IXGBE_DCA_RXCTRL(i), regval); | ||
139 | } | ||
140 | |||
141 | return 0; | ||
142 | } | ||
143 | |||
144 | /** | ||
145 | * ixgbe_init_hw_generic - Generic hardware initialization | ||
146 | * @hw: pointer to hardware structure | ||
147 | * | ||
148 | * Initialize the hardware by resetting the hardware, filling the bus info | ||
149 | * structure and media type, clears all on chip counters, initializes receive | ||
150 | * address registers, multicast table, VLAN filter table, calls routine to set | ||
151 | * up link and flow control settings, and leaves transmit and receive units | ||
152 | * disabled and uninitialized | ||
153 | **/ | ||
154 | s32 ixgbe_init_hw_generic(struct ixgbe_hw *hw) | ||
155 | { | ||
156 | s32 status; | ||
157 | |||
158 | /* Reset the hardware */ | ||
159 | status = hw->mac.ops.reset_hw(hw); | ||
160 | |||
161 | if (status == 0) { | ||
162 | /* Start the HW */ | ||
163 | status = hw->mac.ops.start_hw(hw); | ||
164 | } | ||
165 | |||
166 | return status; | ||
167 | } | ||
168 | |||
169 | /** | ||
170 | * ixgbe_clear_hw_cntrs_generic - Generic clear hardware counters | ||
171 | * @hw: pointer to hardware structure | ||
172 | * | ||
173 | * Clears all hardware statistics counters by reading them from the hardware | ||
174 | * Statistics counters are clear on read. | ||
175 | **/ | ||
176 | s32 ixgbe_clear_hw_cntrs_generic(struct ixgbe_hw *hw) | ||
177 | { | ||
178 | u16 i = 0; | ||
179 | |||
180 | IXGBE_READ_REG(hw, IXGBE_CRCERRS); | ||
181 | IXGBE_READ_REG(hw, IXGBE_ILLERRC); | ||
182 | IXGBE_READ_REG(hw, IXGBE_ERRBC); | ||
183 | IXGBE_READ_REG(hw, IXGBE_MSPDC); | ||
184 | for (i = 0; i < 8; i++) | ||
185 | IXGBE_READ_REG(hw, IXGBE_MPC(i)); | ||
186 | |||
187 | IXGBE_READ_REG(hw, IXGBE_MLFC); | ||
188 | IXGBE_READ_REG(hw, IXGBE_MRFC); | ||
189 | IXGBE_READ_REG(hw, IXGBE_RLEC); | ||
190 | IXGBE_READ_REG(hw, IXGBE_LXONTXC); | ||
191 | IXGBE_READ_REG(hw, IXGBE_LXOFFTXC); | ||
192 | if (hw->mac.type >= ixgbe_mac_82599EB) { | ||
193 | IXGBE_READ_REG(hw, IXGBE_LXONRXCNT); | ||
194 | IXGBE_READ_REG(hw, IXGBE_LXOFFRXCNT); | ||
195 | } else { | ||
196 | IXGBE_READ_REG(hw, IXGBE_LXONRXC); | ||
197 | IXGBE_READ_REG(hw, IXGBE_LXOFFRXC); | ||
198 | } | ||
199 | |||
200 | for (i = 0; i < 8; i++) { | ||
201 | IXGBE_READ_REG(hw, IXGBE_PXONTXC(i)); | ||
202 | IXGBE_READ_REG(hw, IXGBE_PXOFFTXC(i)); | ||
203 | if (hw->mac.type >= ixgbe_mac_82599EB) { | ||
204 | IXGBE_READ_REG(hw, IXGBE_PXONRXCNT(i)); | ||
205 | IXGBE_READ_REG(hw, IXGBE_PXOFFRXCNT(i)); | ||
206 | } else { | ||
207 | IXGBE_READ_REG(hw, IXGBE_PXONRXC(i)); | ||
208 | IXGBE_READ_REG(hw, IXGBE_PXOFFRXC(i)); | ||
209 | } | ||
210 | } | ||
211 | if (hw->mac.type >= ixgbe_mac_82599EB) | ||
212 | for (i = 0; i < 8; i++) | ||
213 | IXGBE_READ_REG(hw, IXGBE_PXON2OFFCNT(i)); | ||
214 | IXGBE_READ_REG(hw, IXGBE_PRC64); | ||
215 | IXGBE_READ_REG(hw, IXGBE_PRC127); | ||
216 | IXGBE_READ_REG(hw, IXGBE_PRC255); | ||
217 | IXGBE_READ_REG(hw, IXGBE_PRC511); | ||
218 | IXGBE_READ_REG(hw, IXGBE_PRC1023); | ||
219 | IXGBE_READ_REG(hw, IXGBE_PRC1522); | ||
220 | IXGBE_READ_REG(hw, IXGBE_GPRC); | ||
221 | IXGBE_READ_REG(hw, IXGBE_BPRC); | ||
222 | IXGBE_READ_REG(hw, IXGBE_MPRC); | ||
223 | IXGBE_READ_REG(hw, IXGBE_GPTC); | ||
224 | IXGBE_READ_REG(hw, IXGBE_GORCL); | ||
225 | IXGBE_READ_REG(hw, IXGBE_GORCH); | ||
226 | IXGBE_READ_REG(hw, IXGBE_GOTCL); | ||
227 | IXGBE_READ_REG(hw, IXGBE_GOTCH); | ||
228 | for (i = 0; i < 8; i++) | ||
229 | IXGBE_READ_REG(hw, IXGBE_RNBC(i)); | ||
230 | IXGBE_READ_REG(hw, IXGBE_RUC); | ||
231 | IXGBE_READ_REG(hw, IXGBE_RFC); | ||
232 | IXGBE_READ_REG(hw, IXGBE_ROC); | ||
233 | IXGBE_READ_REG(hw, IXGBE_RJC); | ||
234 | IXGBE_READ_REG(hw, IXGBE_MNGPRC); | ||
235 | IXGBE_READ_REG(hw, IXGBE_MNGPDC); | ||
236 | IXGBE_READ_REG(hw, IXGBE_MNGPTC); | ||
237 | IXGBE_READ_REG(hw, IXGBE_TORL); | ||
238 | IXGBE_READ_REG(hw, IXGBE_TORH); | ||
239 | IXGBE_READ_REG(hw, IXGBE_TPR); | ||
240 | IXGBE_READ_REG(hw, IXGBE_TPT); | ||
241 | IXGBE_READ_REG(hw, IXGBE_PTC64); | ||
242 | IXGBE_READ_REG(hw, IXGBE_PTC127); | ||
243 | IXGBE_READ_REG(hw, IXGBE_PTC255); | ||
244 | IXGBE_READ_REG(hw, IXGBE_PTC511); | ||
245 | IXGBE_READ_REG(hw, IXGBE_PTC1023); | ||
246 | IXGBE_READ_REG(hw, IXGBE_PTC1522); | ||
247 | IXGBE_READ_REG(hw, IXGBE_MPTC); | ||
248 | IXGBE_READ_REG(hw, IXGBE_BPTC); | ||
249 | for (i = 0; i < 16; i++) { | ||
250 | IXGBE_READ_REG(hw, IXGBE_QPRC(i)); | ||
251 | IXGBE_READ_REG(hw, IXGBE_QPTC(i)); | ||
252 | if (hw->mac.type >= ixgbe_mac_82599EB) { | ||
253 | IXGBE_READ_REG(hw, IXGBE_QBRC_L(i)); | ||
254 | IXGBE_READ_REG(hw, IXGBE_QBRC_H(i)); | ||
255 | IXGBE_READ_REG(hw, IXGBE_QBTC_L(i)); | ||
256 | IXGBE_READ_REG(hw, IXGBE_QBTC_H(i)); | ||
257 | IXGBE_READ_REG(hw, IXGBE_QPRDC(i)); | ||
258 | } else { | ||
259 | IXGBE_READ_REG(hw, IXGBE_QBRC(i)); | ||
260 | IXGBE_READ_REG(hw, IXGBE_QBTC(i)); | ||
261 | } | ||
262 | } | ||
263 | |||
264 | if (hw->mac.type == ixgbe_mac_X540) { | ||
265 | if (hw->phy.id == 0) | ||
266 | hw->phy.ops.identify(hw); | ||
267 | hw->phy.ops.read_reg(hw, 0x3, IXGBE_PCRC8ECL, &i); | ||
268 | hw->phy.ops.read_reg(hw, 0x3, IXGBE_PCRC8ECH, &i); | ||
269 | hw->phy.ops.read_reg(hw, 0x3, IXGBE_LDPCECL, &i); | ||
270 | hw->phy.ops.read_reg(hw, 0x3, IXGBE_LDPCECH, &i); | ||
271 | } | ||
272 | |||
273 | return 0; | ||
274 | } | ||
275 | |||
276 | /** | ||
277 | * ixgbe_read_pba_string_generic - Reads part number string from EEPROM | ||
278 | * @hw: pointer to hardware structure | ||
279 | * @pba_num: stores the part number string from the EEPROM | ||
280 | * @pba_num_size: part number string buffer length | ||
281 | * | ||
282 | * Reads the part number string from the EEPROM. | ||
283 | **/ | ||
284 | s32 ixgbe_read_pba_string_generic(struct ixgbe_hw *hw, u8 *pba_num, | ||
285 | u32 pba_num_size) | ||
286 | { | ||
287 | s32 ret_val; | ||
288 | u16 data; | ||
289 | u16 pba_ptr; | ||
290 | u16 offset; | ||
291 | u16 length; | ||
292 | |||
293 | if (pba_num == NULL) { | ||
294 | hw_dbg(hw, "PBA string buffer was null\n"); | ||
295 | return IXGBE_ERR_INVALID_ARGUMENT; | ||
296 | } | ||
297 | |||
298 | ret_val = hw->eeprom.ops.read(hw, IXGBE_PBANUM0_PTR, &data); | ||
299 | if (ret_val) { | ||
300 | hw_dbg(hw, "NVM Read Error\n"); | ||
301 | return ret_val; | ||
302 | } | ||
303 | |||
304 | ret_val = hw->eeprom.ops.read(hw, IXGBE_PBANUM1_PTR, &pba_ptr); | ||
305 | if (ret_val) { | ||
306 | hw_dbg(hw, "NVM Read Error\n"); | ||
307 | return ret_val; | ||
308 | } | ||
309 | |||
310 | /* | ||
311 | * if data is not ptr guard the PBA must be in legacy format which | ||
312 | * means pba_ptr is actually our second data word for the PBA number | ||
313 | * and we can decode it into an ascii string | ||
314 | */ | ||
315 | if (data != IXGBE_PBANUM_PTR_GUARD) { | ||
316 | hw_dbg(hw, "NVM PBA number is not stored as string\n"); | ||
317 | |||
318 | /* we will need 11 characters to store the PBA */ | ||
319 | if (pba_num_size < 11) { | ||
320 | hw_dbg(hw, "PBA string buffer too small\n"); | ||
321 | return IXGBE_ERR_NO_SPACE; | ||
322 | } | ||
323 | |||
324 | /* extract hex string from data and pba_ptr */ | ||
325 | pba_num[0] = (data >> 12) & 0xF; | ||
326 | pba_num[1] = (data >> 8) & 0xF; | ||
327 | pba_num[2] = (data >> 4) & 0xF; | ||
328 | pba_num[3] = data & 0xF; | ||
329 | pba_num[4] = (pba_ptr >> 12) & 0xF; | ||
330 | pba_num[5] = (pba_ptr >> 8) & 0xF; | ||
331 | pba_num[6] = '-'; | ||
332 | pba_num[7] = 0; | ||
333 | pba_num[8] = (pba_ptr >> 4) & 0xF; | ||
334 | pba_num[9] = pba_ptr & 0xF; | ||
335 | |||
336 | /* put a null character on the end of our string */ | ||
337 | pba_num[10] = '\0'; | ||
338 | |||
339 | /* switch all the data but the '-' to hex char */ | ||
340 | for (offset = 0; offset < 10; offset++) { | ||
341 | if (pba_num[offset] < 0xA) | ||
342 | pba_num[offset] += '0'; | ||
343 | else if (pba_num[offset] < 0x10) | ||
344 | pba_num[offset] += 'A' - 0xA; | ||
345 | } | ||
346 | |||
347 | return 0; | ||
348 | } | ||
349 | |||
350 | ret_val = hw->eeprom.ops.read(hw, pba_ptr, &length); | ||
351 | if (ret_val) { | ||
352 | hw_dbg(hw, "NVM Read Error\n"); | ||
353 | return ret_val; | ||
354 | } | ||
355 | |||
356 | if (length == 0xFFFF || length == 0) { | ||
357 | hw_dbg(hw, "NVM PBA number section invalid length\n"); | ||
358 | return IXGBE_ERR_PBA_SECTION; | ||
359 | } | ||
360 | |||
361 | /* check if pba_num buffer is big enough */ | ||
362 | if (pba_num_size < (((u32)length * 2) - 1)) { | ||
363 | hw_dbg(hw, "PBA string buffer too small\n"); | ||
364 | return IXGBE_ERR_NO_SPACE; | ||
365 | } | ||
366 | |||
367 | /* trim pba length from start of string */ | ||
368 | pba_ptr++; | ||
369 | length--; | ||
370 | |||
371 | for (offset = 0; offset < length; offset++) { | ||
372 | ret_val = hw->eeprom.ops.read(hw, pba_ptr + offset, &data); | ||
373 | if (ret_val) { | ||
374 | hw_dbg(hw, "NVM Read Error\n"); | ||
375 | return ret_val; | ||
376 | } | ||
377 | pba_num[offset * 2] = (u8)(data >> 8); | ||
378 | pba_num[(offset * 2) + 1] = (u8)(data & 0xFF); | ||
379 | } | ||
380 | pba_num[offset * 2] = '\0'; | ||
381 | |||
382 | return 0; | ||
383 | } | ||
384 | |||
385 | /** | ||
386 | * ixgbe_get_mac_addr_generic - Generic get MAC address | ||
387 | * @hw: pointer to hardware structure | ||
388 | * @mac_addr: Adapter MAC address | ||
389 | * | ||
390 | * Reads the adapter's MAC address from first Receive Address Register (RAR0) | ||
391 | * A reset of the adapter must be performed prior to calling this function | ||
392 | * in order for the MAC address to have been loaded from the EEPROM into RAR0 | ||
393 | **/ | ||
394 | s32 ixgbe_get_mac_addr_generic(struct ixgbe_hw *hw, u8 *mac_addr) | ||
395 | { | ||
396 | u32 rar_high; | ||
397 | u32 rar_low; | ||
398 | u16 i; | ||
399 | |||
400 | rar_high = IXGBE_READ_REG(hw, IXGBE_RAH(0)); | ||
401 | rar_low = IXGBE_READ_REG(hw, IXGBE_RAL(0)); | ||
402 | |||
403 | for (i = 0; i < 4; i++) | ||
404 | mac_addr[i] = (u8)(rar_low >> (i*8)); | ||
405 | |||
406 | for (i = 0; i < 2; i++) | ||
407 | mac_addr[i+4] = (u8)(rar_high >> (i*8)); | ||
408 | |||
409 | return 0; | ||
410 | } | ||
411 | |||
412 | /** | ||
413 | * ixgbe_get_bus_info_generic - Generic set PCI bus info | ||
414 | * @hw: pointer to hardware structure | ||
415 | * | ||
416 | * Sets the PCI bus info (speed, width, type) within the ixgbe_hw structure | ||
417 | **/ | ||
418 | s32 ixgbe_get_bus_info_generic(struct ixgbe_hw *hw) | ||
419 | { | ||
420 | struct ixgbe_adapter *adapter = hw->back; | ||
421 | struct ixgbe_mac_info *mac = &hw->mac; | ||
422 | u16 link_status; | ||
423 | |||
424 | hw->bus.type = ixgbe_bus_type_pci_express; | ||
425 | |||
426 | /* Get the negotiated link width and speed from PCI config space */ | ||
427 | pci_read_config_word(adapter->pdev, IXGBE_PCI_LINK_STATUS, | ||
428 | &link_status); | ||
429 | |||
430 | switch (link_status & IXGBE_PCI_LINK_WIDTH) { | ||
431 | case IXGBE_PCI_LINK_WIDTH_1: | ||
432 | hw->bus.width = ixgbe_bus_width_pcie_x1; | ||
433 | break; | ||
434 | case IXGBE_PCI_LINK_WIDTH_2: | ||
435 | hw->bus.width = ixgbe_bus_width_pcie_x2; | ||
436 | break; | ||
437 | case IXGBE_PCI_LINK_WIDTH_4: | ||
438 | hw->bus.width = ixgbe_bus_width_pcie_x4; | ||
439 | break; | ||
440 | case IXGBE_PCI_LINK_WIDTH_8: | ||
441 | hw->bus.width = ixgbe_bus_width_pcie_x8; | ||
442 | break; | ||
443 | default: | ||
444 | hw->bus.width = ixgbe_bus_width_unknown; | ||
445 | break; | ||
446 | } | ||
447 | |||
448 | switch (link_status & IXGBE_PCI_LINK_SPEED) { | ||
449 | case IXGBE_PCI_LINK_SPEED_2500: | ||
450 | hw->bus.speed = ixgbe_bus_speed_2500; | ||
451 | break; | ||
452 | case IXGBE_PCI_LINK_SPEED_5000: | ||
453 | hw->bus.speed = ixgbe_bus_speed_5000; | ||
454 | break; | ||
455 | default: | ||
456 | hw->bus.speed = ixgbe_bus_speed_unknown; | ||
457 | break; | ||
458 | } | ||
459 | |||
460 | mac->ops.set_lan_id(hw); | ||
461 | |||
462 | return 0; | ||
463 | } | ||
464 | |||
465 | /** | ||
466 | * ixgbe_set_lan_id_multi_port_pcie - Set LAN id for PCIe multiple port devices | ||
467 | * @hw: pointer to the HW structure | ||
468 | * | ||
469 | * Determines the LAN function id by reading memory-mapped registers | ||
470 | * and swaps the port value if requested. | ||
471 | **/ | ||
472 | void ixgbe_set_lan_id_multi_port_pcie(struct ixgbe_hw *hw) | ||
473 | { | ||
474 | struct ixgbe_bus_info *bus = &hw->bus; | ||
475 | u32 reg; | ||
476 | |||
477 | reg = IXGBE_READ_REG(hw, IXGBE_STATUS); | ||
478 | bus->func = (reg & IXGBE_STATUS_LAN_ID) >> IXGBE_STATUS_LAN_ID_SHIFT; | ||
479 | bus->lan_id = bus->func; | ||
480 | |||
481 | /* check for a port swap */ | ||
482 | reg = IXGBE_READ_REG(hw, IXGBE_FACTPS); | ||
483 | if (reg & IXGBE_FACTPS_LFS) | ||
484 | bus->func ^= 0x1; | ||
485 | } | ||
486 | |||
487 | /** | ||
488 | * ixgbe_stop_adapter_generic - Generic stop Tx/Rx units | ||
489 | * @hw: pointer to hardware structure | ||
490 | * | ||
491 | * Sets the adapter_stopped flag within ixgbe_hw struct. Clears interrupts, | ||
492 | * disables transmit and receive units. The adapter_stopped flag is used by | ||
493 | * the shared code and drivers to determine if the adapter is in a stopped | ||
494 | * state and should not touch the hardware. | ||
495 | **/ | ||
496 | s32 ixgbe_stop_adapter_generic(struct ixgbe_hw *hw) | ||
497 | { | ||
498 | u32 number_of_queues; | ||
499 | u32 reg_val; | ||
500 | u16 i; | ||
501 | |||
502 | /* | ||
503 | * Set the adapter_stopped flag so other driver functions stop touching | ||
504 | * the hardware | ||
505 | */ | ||
506 | hw->adapter_stopped = true; | ||
507 | |||
508 | /* Disable the receive unit */ | ||
509 | reg_val = IXGBE_READ_REG(hw, IXGBE_RXCTRL); | ||
510 | reg_val &= ~(IXGBE_RXCTRL_RXEN); | ||
511 | IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, reg_val); | ||
512 | IXGBE_WRITE_FLUSH(hw); | ||
513 | usleep_range(2000, 4000); | ||
514 | |||
515 | /* Clear interrupt mask to stop from interrupts being generated */ | ||
516 | IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_IRQ_CLEAR_MASK); | ||
517 | |||
518 | /* Clear any pending interrupts */ | ||
519 | IXGBE_READ_REG(hw, IXGBE_EICR); | ||
520 | |||
521 | /* Disable the transmit unit. Each queue must be disabled. */ | ||
522 | number_of_queues = hw->mac.max_tx_queues; | ||
523 | for (i = 0; i < number_of_queues; i++) { | ||
524 | reg_val = IXGBE_READ_REG(hw, IXGBE_TXDCTL(i)); | ||
525 | if (reg_val & IXGBE_TXDCTL_ENABLE) { | ||
526 | reg_val &= ~IXGBE_TXDCTL_ENABLE; | ||
527 | IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(i), reg_val); | ||
528 | } | ||
529 | } | ||
530 | |||
531 | /* | ||
532 | * Prevent the PCI-E bus from from hanging by disabling PCI-E master | ||
533 | * access and verify no pending requests | ||
534 | */ | ||
535 | ixgbe_disable_pcie_master(hw); | ||
536 | |||
537 | return 0; | ||
538 | } | ||
539 | |||
540 | /** | ||
541 | * ixgbe_led_on_generic - Turns on the software controllable LEDs. | ||
542 | * @hw: pointer to hardware structure | ||
543 | * @index: led number to turn on | ||
544 | **/ | ||
545 | s32 ixgbe_led_on_generic(struct ixgbe_hw *hw, u32 index) | ||
546 | { | ||
547 | u32 led_reg = IXGBE_READ_REG(hw, IXGBE_LEDCTL); | ||
548 | |||
549 | /* To turn on the LED, set mode to ON. */ | ||
550 | led_reg &= ~IXGBE_LED_MODE_MASK(index); | ||
551 | led_reg |= IXGBE_LED_ON << IXGBE_LED_MODE_SHIFT(index); | ||
552 | IXGBE_WRITE_REG(hw, IXGBE_LEDCTL, led_reg); | ||
553 | IXGBE_WRITE_FLUSH(hw); | ||
554 | |||
555 | return 0; | ||
556 | } | ||
557 | |||
558 | /** | ||
559 | * ixgbe_led_off_generic - Turns off the software controllable LEDs. | ||
560 | * @hw: pointer to hardware structure | ||
561 | * @index: led number to turn off | ||
562 | **/ | ||
563 | s32 ixgbe_led_off_generic(struct ixgbe_hw *hw, u32 index) | ||
564 | { | ||
565 | u32 led_reg = IXGBE_READ_REG(hw, IXGBE_LEDCTL); | ||
566 | |||
567 | /* To turn off the LED, set mode to OFF. */ | ||
568 | led_reg &= ~IXGBE_LED_MODE_MASK(index); | ||
569 | led_reg |= IXGBE_LED_OFF << IXGBE_LED_MODE_SHIFT(index); | ||
570 | IXGBE_WRITE_REG(hw, IXGBE_LEDCTL, led_reg); | ||
571 | IXGBE_WRITE_FLUSH(hw); | ||
572 | |||
573 | return 0; | ||
574 | } | ||
575 | |||
576 | /** | ||
577 | * ixgbe_init_eeprom_params_generic - Initialize EEPROM params | ||
578 | * @hw: pointer to hardware structure | ||
579 | * | ||
580 | * Initializes the EEPROM parameters ixgbe_eeprom_info within the | ||
581 | * ixgbe_hw struct in order to set up EEPROM access. | ||
582 | **/ | ||
583 | s32 ixgbe_init_eeprom_params_generic(struct ixgbe_hw *hw) | ||
584 | { | ||
585 | struct ixgbe_eeprom_info *eeprom = &hw->eeprom; | ||
586 | u32 eec; | ||
587 | u16 eeprom_size; | ||
588 | |||
589 | if (eeprom->type == ixgbe_eeprom_uninitialized) { | ||
590 | eeprom->type = ixgbe_eeprom_none; | ||
591 | /* Set default semaphore delay to 10ms which is a well | ||
592 | * tested value */ | ||
593 | eeprom->semaphore_delay = 10; | ||
594 | /* Clear EEPROM page size, it will be initialized as needed */ | ||
595 | eeprom->word_page_size = 0; | ||
596 | |||
597 | /* | ||
598 | * Check for EEPROM present first. | ||
599 | * If not present leave as none | ||
600 | */ | ||
601 | eec = IXGBE_READ_REG(hw, IXGBE_EEC); | ||
602 | if (eec & IXGBE_EEC_PRES) { | ||
603 | eeprom->type = ixgbe_eeprom_spi; | ||
604 | |||
605 | /* | ||
606 | * SPI EEPROM is assumed here. This code would need to | ||
607 | * change if a future EEPROM is not SPI. | ||
608 | */ | ||
609 | eeprom_size = (u16)((eec & IXGBE_EEC_SIZE) >> | ||
610 | IXGBE_EEC_SIZE_SHIFT); | ||
611 | eeprom->word_size = 1 << (eeprom_size + | ||
612 | IXGBE_EEPROM_WORD_SIZE_SHIFT); | ||
613 | } | ||
614 | |||
615 | if (eec & IXGBE_EEC_ADDR_SIZE) | ||
616 | eeprom->address_bits = 16; | ||
617 | else | ||
618 | eeprom->address_bits = 8; | ||
619 | hw_dbg(hw, "Eeprom params: type = %d, size = %d, address bits: " | ||
620 | "%d\n", eeprom->type, eeprom->word_size, | ||
621 | eeprom->address_bits); | ||
622 | } | ||
623 | |||
624 | return 0; | ||
625 | } | ||
626 | |||
627 | /** | ||
628 | * ixgbe_write_eeprom_buffer_bit_bang_generic - Write EEPROM using bit-bang | ||
629 | * @hw: pointer to hardware structure | ||
630 | * @offset: offset within the EEPROM to write | ||
631 | * @words: number of words | ||
632 | * @data: 16 bit word(s) to write to EEPROM | ||
633 | * | ||
634 | * Reads 16 bit word(s) from EEPROM through bit-bang method | ||
635 | **/ | ||
636 | s32 ixgbe_write_eeprom_buffer_bit_bang_generic(struct ixgbe_hw *hw, u16 offset, | ||
637 | u16 words, u16 *data) | ||
638 | { | ||
639 | s32 status = 0; | ||
640 | u16 i, count; | ||
641 | |||
642 | hw->eeprom.ops.init_params(hw); | ||
643 | |||
644 | if (words == 0) { | ||
645 | status = IXGBE_ERR_INVALID_ARGUMENT; | ||
646 | goto out; | ||
647 | } | ||
648 | |||
649 | if (offset + words > hw->eeprom.word_size) { | ||
650 | status = IXGBE_ERR_EEPROM; | ||
651 | goto out; | ||
652 | } | ||
653 | |||
654 | /* | ||
655 | * The EEPROM page size cannot be queried from the chip. We do lazy | ||
656 | * initialization. It is worth to do that when we write large buffer. | ||
657 | */ | ||
658 | if ((hw->eeprom.word_page_size == 0) && | ||
659 | (words > IXGBE_EEPROM_PAGE_SIZE_MAX)) | ||
660 | ixgbe_detect_eeprom_page_size_generic(hw, offset); | ||
661 | |||
662 | /* | ||
663 | * We cannot hold synchronization semaphores for too long | ||
664 | * to avoid other entity starvation. However it is more efficient | ||
665 | * to read in bursts than synchronizing access for each word. | ||
666 | */ | ||
667 | for (i = 0; i < words; i += IXGBE_EEPROM_RD_BUFFER_MAX_COUNT) { | ||
668 | count = (words - i) / IXGBE_EEPROM_RD_BUFFER_MAX_COUNT > 0 ? | ||
669 | IXGBE_EEPROM_RD_BUFFER_MAX_COUNT : (words - i); | ||
670 | status = ixgbe_write_eeprom_buffer_bit_bang(hw, offset + i, | ||
671 | count, &data[i]); | ||
672 | |||
673 | if (status != 0) | ||
674 | break; | ||
675 | } | ||
676 | |||
677 | out: | ||
678 | return status; | ||
679 | } | ||
680 | |||
681 | /** | ||
682 | * ixgbe_write_eeprom_buffer_bit_bang - Writes 16 bit word(s) to EEPROM | ||
683 | * @hw: pointer to hardware structure | ||
684 | * @offset: offset within the EEPROM to be written to | ||
685 | * @words: number of word(s) | ||
686 | * @data: 16 bit word(s) to be written to the EEPROM | ||
687 | * | ||
688 | * If ixgbe_eeprom_update_checksum is not called after this function, the | ||
689 | * EEPROM will most likely contain an invalid checksum. | ||
690 | **/ | ||
691 | static s32 ixgbe_write_eeprom_buffer_bit_bang(struct ixgbe_hw *hw, u16 offset, | ||
692 | u16 words, u16 *data) | ||
693 | { | ||
694 | s32 status; | ||
695 | u16 word; | ||
696 | u16 page_size; | ||
697 | u16 i; | ||
698 | u8 write_opcode = IXGBE_EEPROM_WRITE_OPCODE_SPI; | ||
699 | |||
700 | /* Prepare the EEPROM for writing */ | ||
701 | status = ixgbe_acquire_eeprom(hw); | ||
702 | |||
703 | if (status == 0) { | ||
704 | if (ixgbe_ready_eeprom(hw) != 0) { | ||
705 | ixgbe_release_eeprom(hw); | ||
706 | status = IXGBE_ERR_EEPROM; | ||
707 | } | ||
708 | } | ||
709 | |||
710 | if (status == 0) { | ||
711 | for (i = 0; i < words; i++) { | ||
712 | ixgbe_standby_eeprom(hw); | ||
713 | |||
714 | /* Send the WRITE ENABLE command (8 bit opcode ) */ | ||
715 | ixgbe_shift_out_eeprom_bits(hw, | ||
716 | IXGBE_EEPROM_WREN_OPCODE_SPI, | ||
717 | IXGBE_EEPROM_OPCODE_BITS); | ||
718 | |||
719 | ixgbe_standby_eeprom(hw); | ||
720 | |||
721 | /* | ||
722 | * Some SPI eeproms use the 8th address bit embedded | ||
723 | * in the opcode | ||
724 | */ | ||
725 | if ((hw->eeprom.address_bits == 8) && | ||
726 | ((offset + i) >= 128)) | ||
727 | write_opcode |= IXGBE_EEPROM_A8_OPCODE_SPI; | ||
728 | |||
729 | /* Send the Write command (8-bit opcode + addr) */ | ||
730 | ixgbe_shift_out_eeprom_bits(hw, write_opcode, | ||
731 | IXGBE_EEPROM_OPCODE_BITS); | ||
732 | ixgbe_shift_out_eeprom_bits(hw, (u16)((offset + i) * 2), | ||
733 | hw->eeprom.address_bits); | ||
734 | |||
735 | page_size = hw->eeprom.word_page_size; | ||
736 | |||
737 | /* Send the data in burst via SPI*/ | ||
738 | do { | ||
739 | word = data[i]; | ||
740 | word = (word >> 8) | (word << 8); | ||
741 | ixgbe_shift_out_eeprom_bits(hw, word, 16); | ||
742 | |||
743 | if (page_size == 0) | ||
744 | break; | ||
745 | |||
746 | /* do not wrap around page */ | ||
747 | if (((offset + i) & (page_size - 1)) == | ||
748 | (page_size - 1)) | ||
749 | break; | ||
750 | } while (++i < words); | ||
751 | |||
752 | ixgbe_standby_eeprom(hw); | ||
753 | usleep_range(10000, 20000); | ||
754 | } | ||
755 | /* Done with writing - release the EEPROM */ | ||
756 | ixgbe_release_eeprom(hw); | ||
757 | } | ||
758 | |||
759 | return status; | ||
760 | } | ||
761 | |||
762 | /** | ||
763 | * ixgbe_write_eeprom_generic - Writes 16 bit value to EEPROM | ||
764 | * @hw: pointer to hardware structure | ||
765 | * @offset: offset within the EEPROM to be written to | ||
766 | * @data: 16 bit word to be written to the EEPROM | ||
767 | * | ||
768 | * If ixgbe_eeprom_update_checksum is not called after this function, the | ||
769 | * EEPROM will most likely contain an invalid checksum. | ||
770 | **/ | ||
771 | s32 ixgbe_write_eeprom_generic(struct ixgbe_hw *hw, u16 offset, u16 data) | ||
772 | { | ||
773 | s32 status; | ||
774 | |||
775 | hw->eeprom.ops.init_params(hw); | ||
776 | |||
777 | if (offset >= hw->eeprom.word_size) { | ||
778 | status = IXGBE_ERR_EEPROM; | ||
779 | goto out; | ||
780 | } | ||
781 | |||
782 | status = ixgbe_write_eeprom_buffer_bit_bang(hw, offset, 1, &data); | ||
783 | |||
784 | out: | ||
785 | return status; | ||
786 | } | ||
787 | |||
788 | /** | ||
789 | * ixgbe_read_eeprom_buffer_bit_bang_generic - Read EEPROM using bit-bang | ||
790 | * @hw: pointer to hardware structure | ||
791 | * @offset: offset within the EEPROM to be read | ||
792 | * @words: number of word(s) | ||
793 | * @data: read 16 bit words(s) from EEPROM | ||
794 | * | ||
795 | * Reads 16 bit word(s) from EEPROM through bit-bang method | ||
796 | **/ | ||
797 | s32 ixgbe_read_eeprom_buffer_bit_bang_generic(struct ixgbe_hw *hw, u16 offset, | ||
798 | u16 words, u16 *data) | ||
799 | { | ||
800 | s32 status = 0; | ||
801 | u16 i, count; | ||
802 | |||
803 | hw->eeprom.ops.init_params(hw); | ||
804 | |||
805 | if (words == 0) { | ||
806 | status = IXGBE_ERR_INVALID_ARGUMENT; | ||
807 | goto out; | ||
808 | } | ||
809 | |||
810 | if (offset + words > hw->eeprom.word_size) { | ||
811 | status = IXGBE_ERR_EEPROM; | ||
812 | goto out; | ||
813 | } | ||
814 | |||
815 | /* | ||
816 | * We cannot hold synchronization semaphores for too long | ||
817 | * to avoid other entity starvation. However it is more efficient | ||
818 | * to read in bursts than synchronizing access for each word. | ||
819 | */ | ||
820 | for (i = 0; i < words; i += IXGBE_EEPROM_RD_BUFFER_MAX_COUNT) { | ||
821 | count = (words - i) / IXGBE_EEPROM_RD_BUFFER_MAX_COUNT > 0 ? | ||
822 | IXGBE_EEPROM_RD_BUFFER_MAX_COUNT : (words - i); | ||
823 | |||
824 | status = ixgbe_read_eeprom_buffer_bit_bang(hw, offset + i, | ||
825 | count, &data[i]); | ||
826 | |||
827 | if (status != 0) | ||
828 | break; | ||
829 | } | ||
830 | |||
831 | out: | ||
832 | return status; | ||
833 | } | ||
834 | |||
835 | /** | ||
836 | * ixgbe_read_eeprom_buffer_bit_bang - Read EEPROM using bit-bang | ||
837 | * @hw: pointer to hardware structure | ||
838 | * @offset: offset within the EEPROM to be read | ||
839 | * @words: number of word(s) | ||
840 | * @data: read 16 bit word(s) from EEPROM | ||
841 | * | ||
842 | * Reads 16 bit word(s) from EEPROM through bit-bang method | ||
843 | **/ | ||
844 | static s32 ixgbe_read_eeprom_buffer_bit_bang(struct ixgbe_hw *hw, u16 offset, | ||
845 | u16 words, u16 *data) | ||
846 | { | ||
847 | s32 status; | ||
848 | u16 word_in; | ||
849 | u8 read_opcode = IXGBE_EEPROM_READ_OPCODE_SPI; | ||
850 | u16 i; | ||
851 | |||
852 | /* Prepare the EEPROM for reading */ | ||
853 | status = ixgbe_acquire_eeprom(hw); | ||
854 | |||
855 | if (status == 0) { | ||
856 | if (ixgbe_ready_eeprom(hw) != 0) { | ||
857 | ixgbe_release_eeprom(hw); | ||
858 | status = IXGBE_ERR_EEPROM; | ||
859 | } | ||
860 | } | ||
861 | |||
862 | if (status == 0) { | ||
863 | for (i = 0; i < words; i++) { | ||
864 | ixgbe_standby_eeprom(hw); | ||
865 | /* | ||
866 | * Some SPI eeproms use the 8th address bit embedded | ||
867 | * in the opcode | ||
868 | */ | ||
869 | if ((hw->eeprom.address_bits == 8) && | ||
870 | ((offset + i) >= 128)) | ||
871 | read_opcode |= IXGBE_EEPROM_A8_OPCODE_SPI; | ||
872 | |||
873 | /* Send the READ command (opcode + addr) */ | ||
874 | ixgbe_shift_out_eeprom_bits(hw, read_opcode, | ||
875 | IXGBE_EEPROM_OPCODE_BITS); | ||
876 | ixgbe_shift_out_eeprom_bits(hw, (u16)((offset + i) * 2), | ||
877 | hw->eeprom.address_bits); | ||
878 | |||
879 | /* Read the data. */ | ||
880 | word_in = ixgbe_shift_in_eeprom_bits(hw, 16); | ||
881 | data[i] = (word_in >> 8) | (word_in << 8); | ||
882 | } | ||
883 | |||
884 | /* End this read operation */ | ||
885 | ixgbe_release_eeprom(hw); | ||
886 | } | ||
887 | |||
888 | return status; | ||
889 | } | ||
890 | |||
891 | /** | ||
892 | * ixgbe_read_eeprom_bit_bang_generic - Read EEPROM word using bit-bang | ||
893 | * @hw: pointer to hardware structure | ||
894 | * @offset: offset within the EEPROM to be read | ||
895 | * @data: read 16 bit value from EEPROM | ||
896 | * | ||
897 | * Reads 16 bit value from EEPROM through bit-bang method | ||
898 | **/ | ||
899 | s32 ixgbe_read_eeprom_bit_bang_generic(struct ixgbe_hw *hw, u16 offset, | ||
900 | u16 *data) | ||
901 | { | ||
902 | s32 status; | ||
903 | |||
904 | hw->eeprom.ops.init_params(hw); | ||
905 | |||
906 | if (offset >= hw->eeprom.word_size) { | ||
907 | status = IXGBE_ERR_EEPROM; | ||
908 | goto out; | ||
909 | } | ||
910 | |||
911 | status = ixgbe_read_eeprom_buffer_bit_bang(hw, offset, 1, data); | ||
912 | |||
913 | out: | ||
914 | return status; | ||
915 | } | ||
916 | |||
917 | /** | ||
918 | * ixgbe_read_eerd_buffer_generic - Read EEPROM word(s) using EERD | ||
919 | * @hw: pointer to hardware structure | ||
920 | * @offset: offset of word in the EEPROM to read | ||
921 | * @words: number of word(s) | ||
922 | * @data: 16 bit word(s) from the EEPROM | ||
923 | * | ||
924 | * Reads a 16 bit word(s) from the EEPROM using the EERD register. | ||
925 | **/ | ||
926 | s32 ixgbe_read_eerd_buffer_generic(struct ixgbe_hw *hw, u16 offset, | ||
927 | u16 words, u16 *data) | ||
928 | { | ||
929 | u32 eerd; | ||
930 | s32 status = 0; | ||
931 | u32 i; | ||
932 | |||
933 | hw->eeprom.ops.init_params(hw); | ||
934 | |||
935 | if (words == 0) { | ||
936 | status = IXGBE_ERR_INVALID_ARGUMENT; | ||
937 | goto out; | ||
938 | } | ||
939 | |||
940 | if (offset >= hw->eeprom.word_size) { | ||
941 | status = IXGBE_ERR_EEPROM; | ||
942 | goto out; | ||
943 | } | ||
944 | |||
945 | for (i = 0; i < words; i++) { | ||
946 | eerd = ((offset + i) << IXGBE_EEPROM_RW_ADDR_SHIFT) + | ||
947 | IXGBE_EEPROM_RW_REG_START; | ||
948 | |||
949 | IXGBE_WRITE_REG(hw, IXGBE_EERD, eerd); | ||
950 | status = ixgbe_poll_eerd_eewr_done(hw, IXGBE_NVM_POLL_READ); | ||
951 | |||
952 | if (status == 0) { | ||
953 | data[i] = (IXGBE_READ_REG(hw, IXGBE_EERD) >> | ||
954 | IXGBE_EEPROM_RW_REG_DATA); | ||
955 | } else { | ||
956 | hw_dbg(hw, "Eeprom read timed out\n"); | ||
957 | goto out; | ||
958 | } | ||
959 | } | ||
960 | out: | ||
961 | return status; | ||
962 | } | ||
963 | |||
964 | /** | ||
965 | * ixgbe_detect_eeprom_page_size_generic - Detect EEPROM page size | ||
966 | * @hw: pointer to hardware structure | ||
967 | * @offset: offset within the EEPROM to be used as a scratch pad | ||
968 | * | ||
969 | * Discover EEPROM page size by writing marching data at given offset. | ||
970 | * This function is called only when we are writing a new large buffer | ||
971 | * at given offset so the data would be overwritten anyway. | ||
972 | **/ | ||
973 | static s32 ixgbe_detect_eeprom_page_size_generic(struct ixgbe_hw *hw, | ||
974 | u16 offset) | ||
975 | { | ||
976 | u16 data[IXGBE_EEPROM_PAGE_SIZE_MAX]; | ||
977 | s32 status = 0; | ||
978 | u16 i; | ||
979 | |||
980 | for (i = 0; i < IXGBE_EEPROM_PAGE_SIZE_MAX; i++) | ||
981 | data[i] = i; | ||
982 | |||
983 | hw->eeprom.word_page_size = IXGBE_EEPROM_PAGE_SIZE_MAX; | ||
984 | status = ixgbe_write_eeprom_buffer_bit_bang(hw, offset, | ||
985 | IXGBE_EEPROM_PAGE_SIZE_MAX, data); | ||
986 | hw->eeprom.word_page_size = 0; | ||
987 | if (status != 0) | ||
988 | goto out; | ||
989 | |||
990 | status = ixgbe_read_eeprom_buffer_bit_bang(hw, offset, 1, data); | ||
991 | if (status != 0) | ||
992 | goto out; | ||
993 | |||
994 | /* | ||
995 | * When writing in burst more than the actual page size | ||
996 | * EEPROM address wraps around current page. | ||
997 | */ | ||
998 | hw->eeprom.word_page_size = IXGBE_EEPROM_PAGE_SIZE_MAX - data[0]; | ||
999 | |||
1000 | hw_dbg(hw, "Detected EEPROM page size = %d words.", | ||
1001 | hw->eeprom.word_page_size); | ||
1002 | out: | ||
1003 | return status; | ||
1004 | } | ||
1005 | |||
1006 | /** | ||
1007 | * ixgbe_read_eerd_generic - Read EEPROM word using EERD | ||
1008 | * @hw: pointer to hardware structure | ||
1009 | * @offset: offset of word in the EEPROM to read | ||
1010 | * @data: word read from the EEPROM | ||
1011 | * | ||
1012 | * Reads a 16 bit word from the EEPROM using the EERD register. | ||
1013 | **/ | ||
1014 | s32 ixgbe_read_eerd_generic(struct ixgbe_hw *hw, u16 offset, u16 *data) | ||
1015 | { | ||
1016 | return ixgbe_read_eerd_buffer_generic(hw, offset, 1, data); | ||
1017 | } | ||
1018 | |||
1019 | /** | ||
1020 | * ixgbe_write_eewr_buffer_generic - Write EEPROM word(s) using EEWR | ||
1021 | * @hw: pointer to hardware structure | ||
1022 | * @offset: offset of word in the EEPROM to write | ||
1023 | * @words: number of words | ||
1024 | * @data: word(s) write to the EEPROM | ||
1025 | * | ||
1026 | * Write a 16 bit word(s) to the EEPROM using the EEWR register. | ||
1027 | **/ | ||
1028 | s32 ixgbe_write_eewr_buffer_generic(struct ixgbe_hw *hw, u16 offset, | ||
1029 | u16 words, u16 *data) | ||
1030 | { | ||
1031 | u32 eewr; | ||
1032 | s32 status = 0; | ||
1033 | u16 i; | ||
1034 | |||
1035 | hw->eeprom.ops.init_params(hw); | ||
1036 | |||
1037 | if (words == 0) { | ||
1038 | status = IXGBE_ERR_INVALID_ARGUMENT; | ||
1039 | goto out; | ||
1040 | } | ||
1041 | |||
1042 | if (offset >= hw->eeprom.word_size) { | ||
1043 | status = IXGBE_ERR_EEPROM; | ||
1044 | goto out; | ||
1045 | } | ||
1046 | |||
1047 | for (i = 0; i < words; i++) { | ||
1048 | eewr = ((offset + i) << IXGBE_EEPROM_RW_ADDR_SHIFT) | | ||
1049 | (data[i] << IXGBE_EEPROM_RW_REG_DATA) | | ||
1050 | IXGBE_EEPROM_RW_REG_START; | ||
1051 | |||
1052 | status = ixgbe_poll_eerd_eewr_done(hw, IXGBE_NVM_POLL_WRITE); | ||
1053 | if (status != 0) { | ||
1054 | hw_dbg(hw, "Eeprom write EEWR timed out\n"); | ||
1055 | goto out; | ||
1056 | } | ||
1057 | |||
1058 | IXGBE_WRITE_REG(hw, IXGBE_EEWR, eewr); | ||
1059 | |||
1060 | status = ixgbe_poll_eerd_eewr_done(hw, IXGBE_NVM_POLL_WRITE); | ||
1061 | if (status != 0) { | ||
1062 | hw_dbg(hw, "Eeprom write EEWR timed out\n"); | ||
1063 | goto out; | ||
1064 | } | ||
1065 | } | ||
1066 | |||
1067 | out: | ||
1068 | return status; | ||
1069 | } | ||
1070 | |||
1071 | /** | ||
1072 | * ixgbe_write_eewr_generic - Write EEPROM word using EEWR | ||
1073 | * @hw: pointer to hardware structure | ||
1074 | * @offset: offset of word in the EEPROM to write | ||
1075 | * @data: word write to the EEPROM | ||
1076 | * | ||
1077 | * Write a 16 bit word to the EEPROM using the EEWR register. | ||
1078 | **/ | ||
1079 | s32 ixgbe_write_eewr_generic(struct ixgbe_hw *hw, u16 offset, u16 data) | ||
1080 | { | ||
1081 | return ixgbe_write_eewr_buffer_generic(hw, offset, 1, &data); | ||
1082 | } | ||
1083 | |||
1084 | /** | ||
1085 | * ixgbe_poll_eerd_eewr_done - Poll EERD read or EEWR write status | ||
1086 | * @hw: pointer to hardware structure | ||
1087 | * @ee_reg: EEPROM flag for polling | ||
1088 | * | ||
1089 | * Polls the status bit (bit 1) of the EERD or EEWR to determine when the | ||
1090 | * read or write is done respectively. | ||
1091 | **/ | ||
1092 | static s32 ixgbe_poll_eerd_eewr_done(struct ixgbe_hw *hw, u32 ee_reg) | ||
1093 | { | ||
1094 | u32 i; | ||
1095 | u32 reg; | ||
1096 | s32 status = IXGBE_ERR_EEPROM; | ||
1097 | |||
1098 | for (i = 0; i < IXGBE_EERD_EEWR_ATTEMPTS; i++) { | ||
1099 | if (ee_reg == IXGBE_NVM_POLL_READ) | ||
1100 | reg = IXGBE_READ_REG(hw, IXGBE_EERD); | ||
1101 | else | ||
1102 | reg = IXGBE_READ_REG(hw, IXGBE_EEWR); | ||
1103 | |||
1104 | if (reg & IXGBE_EEPROM_RW_REG_DONE) { | ||
1105 | status = 0; | ||
1106 | break; | ||
1107 | } | ||
1108 | udelay(5); | ||
1109 | } | ||
1110 | return status; | ||
1111 | } | ||
1112 | |||
1113 | /** | ||
1114 | * ixgbe_acquire_eeprom - Acquire EEPROM using bit-bang | ||
1115 | * @hw: pointer to hardware structure | ||
1116 | * | ||
1117 | * Prepares EEPROM for access using bit-bang method. This function should | ||
1118 | * be called before issuing a command to the EEPROM. | ||
1119 | **/ | ||
1120 | static s32 ixgbe_acquire_eeprom(struct ixgbe_hw *hw) | ||
1121 | { | ||
1122 | s32 status = 0; | ||
1123 | u32 eec; | ||
1124 | u32 i; | ||
1125 | |||
1126 | if (hw->mac.ops.acquire_swfw_sync(hw, IXGBE_GSSR_EEP_SM) != 0) | ||
1127 | status = IXGBE_ERR_SWFW_SYNC; | ||
1128 | |||
1129 | if (status == 0) { | ||
1130 | eec = IXGBE_READ_REG(hw, IXGBE_EEC); | ||
1131 | |||
1132 | /* Request EEPROM Access */ | ||
1133 | eec |= IXGBE_EEC_REQ; | ||
1134 | IXGBE_WRITE_REG(hw, IXGBE_EEC, eec); | ||
1135 | |||
1136 | for (i = 0; i < IXGBE_EEPROM_GRANT_ATTEMPTS; i++) { | ||
1137 | eec = IXGBE_READ_REG(hw, IXGBE_EEC); | ||
1138 | if (eec & IXGBE_EEC_GNT) | ||
1139 | break; | ||
1140 | udelay(5); | ||
1141 | } | ||
1142 | |||
1143 | /* Release if grant not acquired */ | ||
1144 | if (!(eec & IXGBE_EEC_GNT)) { | ||
1145 | eec &= ~IXGBE_EEC_REQ; | ||
1146 | IXGBE_WRITE_REG(hw, IXGBE_EEC, eec); | ||
1147 | hw_dbg(hw, "Could not acquire EEPROM grant\n"); | ||
1148 | |||
1149 | hw->mac.ops.release_swfw_sync(hw, IXGBE_GSSR_EEP_SM); | ||
1150 | status = IXGBE_ERR_EEPROM; | ||
1151 | } | ||
1152 | |||
1153 | /* Setup EEPROM for Read/Write */ | ||
1154 | if (status == 0) { | ||
1155 | /* Clear CS and SK */ | ||
1156 | eec &= ~(IXGBE_EEC_CS | IXGBE_EEC_SK); | ||
1157 | IXGBE_WRITE_REG(hw, IXGBE_EEC, eec); | ||
1158 | IXGBE_WRITE_FLUSH(hw); | ||
1159 | udelay(1); | ||
1160 | } | ||
1161 | } | ||
1162 | return status; | ||
1163 | } | ||
1164 | |||
1165 | /** | ||
1166 | * ixgbe_get_eeprom_semaphore - Get hardware semaphore | ||
1167 | * @hw: pointer to hardware structure | ||
1168 | * | ||
1169 | * Sets the hardware semaphores so EEPROM access can occur for bit-bang method | ||
1170 | **/ | ||
1171 | static s32 ixgbe_get_eeprom_semaphore(struct ixgbe_hw *hw) | ||
1172 | { | ||
1173 | s32 status = IXGBE_ERR_EEPROM; | ||
1174 | u32 timeout = 2000; | ||
1175 | u32 i; | ||
1176 | u32 swsm; | ||
1177 | |||
1178 | /* Get SMBI software semaphore between device drivers first */ | ||
1179 | for (i = 0; i < timeout; i++) { | ||
1180 | /* | ||
1181 | * If the SMBI bit is 0 when we read it, then the bit will be | ||
1182 | * set and we have the semaphore | ||
1183 | */ | ||
1184 | swsm = IXGBE_READ_REG(hw, IXGBE_SWSM); | ||
1185 | if (!(swsm & IXGBE_SWSM_SMBI)) { | ||
1186 | status = 0; | ||
1187 | break; | ||
1188 | } | ||
1189 | udelay(50); | ||
1190 | } | ||
1191 | |||
1192 | if (i == timeout) { | ||
1193 | hw_dbg(hw, "Driver can't access the Eeprom - SMBI Semaphore " | ||
1194 | "not granted.\n"); | ||
1195 | /* | ||
1196 | * this release is particularly important because our attempts | ||
1197 | * above to get the semaphore may have succeeded, and if there | ||
1198 | * was a timeout, we should unconditionally clear the semaphore | ||
1199 | * bits to free the driver to make progress | ||
1200 | */ | ||
1201 | ixgbe_release_eeprom_semaphore(hw); | ||
1202 | |||
1203 | udelay(50); | ||
1204 | /* | ||
1205 | * one last try | ||
1206 | * If the SMBI bit is 0 when we read it, then the bit will be | ||
1207 | * set and we have the semaphore | ||
1208 | */ | ||
1209 | swsm = IXGBE_READ_REG(hw, IXGBE_SWSM); | ||
1210 | if (!(swsm & IXGBE_SWSM_SMBI)) | ||
1211 | status = 0; | ||
1212 | } | ||
1213 | |||
1214 | /* Now get the semaphore between SW/FW through the SWESMBI bit */ | ||
1215 | if (status == 0) { | ||
1216 | for (i = 0; i < timeout; i++) { | ||
1217 | swsm = IXGBE_READ_REG(hw, IXGBE_SWSM); | ||
1218 | |||
1219 | /* Set the SW EEPROM semaphore bit to request access */ | ||
1220 | swsm |= IXGBE_SWSM_SWESMBI; | ||
1221 | IXGBE_WRITE_REG(hw, IXGBE_SWSM, swsm); | ||
1222 | |||
1223 | /* | ||
1224 | * If we set the bit successfully then we got the | ||
1225 | * semaphore. | ||
1226 | */ | ||
1227 | swsm = IXGBE_READ_REG(hw, IXGBE_SWSM); | ||
1228 | if (swsm & IXGBE_SWSM_SWESMBI) | ||
1229 | break; | ||
1230 | |||
1231 | udelay(50); | ||
1232 | } | ||
1233 | |||
1234 | /* | ||
1235 | * Release semaphores and return error if SW EEPROM semaphore | ||
1236 | * was not granted because we don't have access to the EEPROM | ||
1237 | */ | ||
1238 | if (i >= timeout) { | ||
1239 | hw_dbg(hw, "SWESMBI Software EEPROM semaphore " | ||
1240 | "not granted.\n"); | ||
1241 | ixgbe_release_eeprom_semaphore(hw); | ||
1242 | status = IXGBE_ERR_EEPROM; | ||
1243 | } | ||
1244 | } else { | ||
1245 | hw_dbg(hw, "Software semaphore SMBI between device drivers " | ||
1246 | "not granted.\n"); | ||
1247 | } | ||
1248 | |||
1249 | return status; | ||
1250 | } | ||
1251 | |||
1252 | /** | ||
1253 | * ixgbe_release_eeprom_semaphore - Release hardware semaphore | ||
1254 | * @hw: pointer to hardware structure | ||
1255 | * | ||
1256 | * This function clears hardware semaphore bits. | ||
1257 | **/ | ||
1258 | static void ixgbe_release_eeprom_semaphore(struct ixgbe_hw *hw) | ||
1259 | { | ||
1260 | u32 swsm; | ||
1261 | |||
1262 | swsm = IXGBE_READ_REG(hw, IXGBE_SWSM); | ||
1263 | |||
1264 | /* Release both semaphores by writing 0 to the bits SWESMBI and SMBI */ | ||
1265 | swsm &= ~(IXGBE_SWSM_SWESMBI | IXGBE_SWSM_SMBI); | ||
1266 | IXGBE_WRITE_REG(hw, IXGBE_SWSM, swsm); | ||
1267 | IXGBE_WRITE_FLUSH(hw); | ||
1268 | } | ||
1269 | |||
1270 | /** | ||
1271 | * ixgbe_ready_eeprom - Polls for EEPROM ready | ||
1272 | * @hw: pointer to hardware structure | ||
1273 | **/ | ||
1274 | static s32 ixgbe_ready_eeprom(struct ixgbe_hw *hw) | ||
1275 | { | ||
1276 | s32 status = 0; | ||
1277 | u16 i; | ||
1278 | u8 spi_stat_reg; | ||
1279 | |||
1280 | /* | ||
1281 | * Read "Status Register" repeatedly until the LSB is cleared. The | ||
1282 | * EEPROM will signal that the command has been completed by clearing | ||
1283 | * bit 0 of the internal status register. If it's not cleared within | ||
1284 | * 5 milliseconds, then error out. | ||
1285 | */ | ||
1286 | for (i = 0; i < IXGBE_EEPROM_MAX_RETRY_SPI; i += 5) { | ||
1287 | ixgbe_shift_out_eeprom_bits(hw, IXGBE_EEPROM_RDSR_OPCODE_SPI, | ||
1288 | IXGBE_EEPROM_OPCODE_BITS); | ||
1289 | spi_stat_reg = (u8)ixgbe_shift_in_eeprom_bits(hw, 8); | ||
1290 | if (!(spi_stat_reg & IXGBE_EEPROM_STATUS_RDY_SPI)) | ||
1291 | break; | ||
1292 | |||
1293 | udelay(5); | ||
1294 | ixgbe_standby_eeprom(hw); | ||
1295 | } | ||
1296 | |||
1297 | /* | ||
1298 | * On some parts, SPI write time could vary from 0-20mSec on 3.3V | ||
1299 | * devices (and only 0-5mSec on 5V devices) | ||
1300 | */ | ||
1301 | if (i >= IXGBE_EEPROM_MAX_RETRY_SPI) { | ||
1302 | hw_dbg(hw, "SPI EEPROM Status error\n"); | ||
1303 | status = IXGBE_ERR_EEPROM; | ||
1304 | } | ||
1305 | |||
1306 | return status; | ||
1307 | } | ||
1308 | |||
1309 | /** | ||
1310 | * ixgbe_standby_eeprom - Returns EEPROM to a "standby" state | ||
1311 | * @hw: pointer to hardware structure | ||
1312 | **/ | ||
1313 | static void ixgbe_standby_eeprom(struct ixgbe_hw *hw) | ||
1314 | { | ||
1315 | u32 eec; | ||
1316 | |||
1317 | eec = IXGBE_READ_REG(hw, IXGBE_EEC); | ||
1318 | |||
1319 | /* Toggle CS to flush commands */ | ||
1320 | eec |= IXGBE_EEC_CS; | ||
1321 | IXGBE_WRITE_REG(hw, IXGBE_EEC, eec); | ||
1322 | IXGBE_WRITE_FLUSH(hw); | ||
1323 | udelay(1); | ||
1324 | eec &= ~IXGBE_EEC_CS; | ||
1325 | IXGBE_WRITE_REG(hw, IXGBE_EEC, eec); | ||
1326 | IXGBE_WRITE_FLUSH(hw); | ||
1327 | udelay(1); | ||
1328 | } | ||
1329 | |||
1330 | /** | ||
1331 | * ixgbe_shift_out_eeprom_bits - Shift data bits out to the EEPROM. | ||
1332 | * @hw: pointer to hardware structure | ||
1333 | * @data: data to send to the EEPROM | ||
1334 | * @count: number of bits to shift out | ||
1335 | **/ | ||
1336 | static void ixgbe_shift_out_eeprom_bits(struct ixgbe_hw *hw, u16 data, | ||
1337 | u16 count) | ||
1338 | { | ||
1339 | u32 eec; | ||
1340 | u32 mask; | ||
1341 | u32 i; | ||
1342 | |||
1343 | eec = IXGBE_READ_REG(hw, IXGBE_EEC); | ||
1344 | |||
1345 | /* | ||
1346 | * Mask is used to shift "count" bits of "data" out to the EEPROM | ||
1347 | * one bit at a time. Determine the starting bit based on count | ||
1348 | */ | ||
1349 | mask = 0x01 << (count - 1); | ||
1350 | |||
1351 | for (i = 0; i < count; i++) { | ||
1352 | /* | ||
1353 | * A "1" is shifted out to the EEPROM by setting bit "DI" to a | ||
1354 | * "1", and then raising and then lowering the clock (the SK | ||
1355 | * bit controls the clock input to the EEPROM). A "0" is | ||
1356 | * shifted out to the EEPROM by setting "DI" to "0" and then | ||
1357 | * raising and then lowering the clock. | ||
1358 | */ | ||
1359 | if (data & mask) | ||
1360 | eec |= IXGBE_EEC_DI; | ||
1361 | else | ||
1362 | eec &= ~IXGBE_EEC_DI; | ||
1363 | |||
1364 | IXGBE_WRITE_REG(hw, IXGBE_EEC, eec); | ||
1365 | IXGBE_WRITE_FLUSH(hw); | ||
1366 | |||
1367 | udelay(1); | ||
1368 | |||
1369 | ixgbe_raise_eeprom_clk(hw, &eec); | ||
1370 | ixgbe_lower_eeprom_clk(hw, &eec); | ||
1371 | |||
1372 | /* | ||
1373 | * Shift mask to signify next bit of data to shift in to the | ||
1374 | * EEPROM | ||
1375 | */ | ||
1376 | mask = mask >> 1; | ||
1377 | } | ||
1378 | |||
1379 | /* We leave the "DI" bit set to "0" when we leave this routine. */ | ||
1380 | eec &= ~IXGBE_EEC_DI; | ||
1381 | IXGBE_WRITE_REG(hw, IXGBE_EEC, eec); | ||
1382 | IXGBE_WRITE_FLUSH(hw); | ||
1383 | } | ||
1384 | |||
1385 | /** | ||
1386 | * ixgbe_shift_in_eeprom_bits - Shift data bits in from the EEPROM | ||
1387 | * @hw: pointer to hardware structure | ||
1388 | **/ | ||
1389 | static u16 ixgbe_shift_in_eeprom_bits(struct ixgbe_hw *hw, u16 count) | ||
1390 | { | ||
1391 | u32 eec; | ||
1392 | u32 i; | ||
1393 | u16 data = 0; | ||
1394 | |||
1395 | /* | ||
1396 | * In order to read a register from the EEPROM, we need to shift | ||
1397 | * 'count' bits in from the EEPROM. Bits are "shifted in" by raising | ||
1398 | * the clock input to the EEPROM (setting the SK bit), and then reading | ||
1399 | * the value of the "DO" bit. During this "shifting in" process the | ||
1400 | * "DI" bit should always be clear. | ||
1401 | */ | ||
1402 | eec = IXGBE_READ_REG(hw, IXGBE_EEC); | ||
1403 | |||
1404 | eec &= ~(IXGBE_EEC_DO | IXGBE_EEC_DI); | ||
1405 | |||
1406 | for (i = 0; i < count; i++) { | ||
1407 | data = data << 1; | ||
1408 | ixgbe_raise_eeprom_clk(hw, &eec); | ||
1409 | |||
1410 | eec = IXGBE_READ_REG(hw, IXGBE_EEC); | ||
1411 | |||
1412 | eec &= ~(IXGBE_EEC_DI); | ||
1413 | if (eec & IXGBE_EEC_DO) | ||
1414 | data |= 1; | ||
1415 | |||
1416 | ixgbe_lower_eeprom_clk(hw, &eec); | ||
1417 | } | ||
1418 | |||
1419 | return data; | ||
1420 | } | ||
1421 | |||
1422 | /** | ||
1423 | * ixgbe_raise_eeprom_clk - Raises the EEPROM's clock input. | ||
1424 | * @hw: pointer to hardware structure | ||
1425 | * @eec: EEC register's current value | ||
1426 | **/ | ||
1427 | static void ixgbe_raise_eeprom_clk(struct ixgbe_hw *hw, u32 *eec) | ||
1428 | { | ||
1429 | /* | ||
1430 | * Raise the clock input to the EEPROM | ||
1431 | * (setting the SK bit), then delay | ||
1432 | */ | ||
1433 | *eec = *eec | IXGBE_EEC_SK; | ||
1434 | IXGBE_WRITE_REG(hw, IXGBE_EEC, *eec); | ||
1435 | IXGBE_WRITE_FLUSH(hw); | ||
1436 | udelay(1); | ||
1437 | } | ||
1438 | |||
1439 | /** | ||
1440 | * ixgbe_lower_eeprom_clk - Lowers the EEPROM's clock input. | ||
1441 | * @hw: pointer to hardware structure | ||
1442 | * @eecd: EECD's current value | ||
1443 | **/ | ||
1444 | static void ixgbe_lower_eeprom_clk(struct ixgbe_hw *hw, u32 *eec) | ||
1445 | { | ||
1446 | /* | ||
1447 | * Lower the clock input to the EEPROM (clearing the SK bit), then | ||
1448 | * delay | ||
1449 | */ | ||
1450 | *eec = *eec & ~IXGBE_EEC_SK; | ||
1451 | IXGBE_WRITE_REG(hw, IXGBE_EEC, *eec); | ||
1452 | IXGBE_WRITE_FLUSH(hw); | ||
1453 | udelay(1); | ||
1454 | } | ||
1455 | |||
1456 | /** | ||
1457 | * ixgbe_release_eeprom - Release EEPROM, release semaphores | ||
1458 | * @hw: pointer to hardware structure | ||
1459 | **/ | ||
1460 | static void ixgbe_release_eeprom(struct ixgbe_hw *hw) | ||
1461 | { | ||
1462 | u32 eec; | ||
1463 | |||
1464 | eec = IXGBE_READ_REG(hw, IXGBE_EEC); | ||
1465 | |||
1466 | eec |= IXGBE_EEC_CS; /* Pull CS high */ | ||
1467 | eec &= ~IXGBE_EEC_SK; /* Lower SCK */ | ||
1468 | |||
1469 | IXGBE_WRITE_REG(hw, IXGBE_EEC, eec); | ||
1470 | IXGBE_WRITE_FLUSH(hw); | ||
1471 | |||
1472 | udelay(1); | ||
1473 | |||
1474 | /* Stop requesting EEPROM access */ | ||
1475 | eec &= ~IXGBE_EEC_REQ; | ||
1476 | IXGBE_WRITE_REG(hw, IXGBE_EEC, eec); | ||
1477 | |||
1478 | hw->mac.ops.release_swfw_sync(hw, IXGBE_GSSR_EEP_SM); | ||
1479 | |||
1480 | /* | ||
1481 | * Delay before attempt to obtain semaphore again to allow FW | ||
1482 | * access. semaphore_delay is in ms we need us for usleep_range | ||
1483 | */ | ||
1484 | usleep_range(hw->eeprom.semaphore_delay * 1000, | ||
1485 | hw->eeprom.semaphore_delay * 2000); | ||
1486 | } | ||
1487 | |||
1488 | /** | ||
1489 | * ixgbe_calc_eeprom_checksum_generic - Calculates and returns the checksum | ||
1490 | * @hw: pointer to hardware structure | ||
1491 | **/ | ||
1492 | u16 ixgbe_calc_eeprom_checksum_generic(struct ixgbe_hw *hw) | ||
1493 | { | ||
1494 | u16 i; | ||
1495 | u16 j; | ||
1496 | u16 checksum = 0; | ||
1497 | u16 length = 0; | ||
1498 | u16 pointer = 0; | ||
1499 | u16 word = 0; | ||
1500 | |||
1501 | /* Include 0x0-0x3F in the checksum */ | ||
1502 | for (i = 0; i < IXGBE_EEPROM_CHECKSUM; i++) { | ||
1503 | if (hw->eeprom.ops.read(hw, i, &word) != 0) { | ||
1504 | hw_dbg(hw, "EEPROM read failed\n"); | ||
1505 | break; | ||
1506 | } | ||
1507 | checksum += word; | ||
1508 | } | ||
1509 | |||
1510 | /* Include all data from pointers except for the fw pointer */ | ||
1511 | for (i = IXGBE_PCIE_ANALOG_PTR; i < IXGBE_FW_PTR; i++) { | ||
1512 | hw->eeprom.ops.read(hw, i, &pointer); | ||
1513 | |||
1514 | /* Make sure the pointer seems valid */ | ||
1515 | if (pointer != 0xFFFF && pointer != 0) { | ||
1516 | hw->eeprom.ops.read(hw, pointer, &length); | ||
1517 | |||
1518 | if (length != 0xFFFF && length != 0) { | ||
1519 | for (j = pointer+1; j <= pointer+length; j++) { | ||
1520 | hw->eeprom.ops.read(hw, j, &word); | ||
1521 | checksum += word; | ||
1522 | } | ||
1523 | } | ||
1524 | } | ||
1525 | } | ||
1526 | |||
1527 | checksum = (u16)IXGBE_EEPROM_SUM - checksum; | ||
1528 | |||
1529 | return checksum; | ||
1530 | } | ||
1531 | |||
1532 | /** | ||
1533 | * ixgbe_validate_eeprom_checksum_generic - Validate EEPROM checksum | ||
1534 | * @hw: pointer to hardware structure | ||
1535 | * @checksum_val: calculated checksum | ||
1536 | * | ||
1537 | * Performs checksum calculation and validates the EEPROM checksum. If the | ||
1538 | * caller does not need checksum_val, the value can be NULL. | ||
1539 | **/ | ||
1540 | s32 ixgbe_validate_eeprom_checksum_generic(struct ixgbe_hw *hw, | ||
1541 | u16 *checksum_val) | ||
1542 | { | ||
1543 | s32 status; | ||
1544 | u16 checksum; | ||
1545 | u16 read_checksum = 0; | ||
1546 | |||
1547 | /* | ||
1548 | * Read the first word from the EEPROM. If this times out or fails, do | ||
1549 | * not continue or we could be in for a very long wait while every | ||
1550 | * EEPROM read fails | ||
1551 | */ | ||
1552 | status = hw->eeprom.ops.read(hw, 0, &checksum); | ||
1553 | |||
1554 | if (status == 0) { | ||
1555 | checksum = hw->eeprom.ops.calc_checksum(hw); | ||
1556 | |||
1557 | hw->eeprom.ops.read(hw, IXGBE_EEPROM_CHECKSUM, &read_checksum); | ||
1558 | |||
1559 | /* | ||
1560 | * Verify read checksum from EEPROM is the same as | ||
1561 | * calculated checksum | ||
1562 | */ | ||
1563 | if (read_checksum != checksum) | ||
1564 | status = IXGBE_ERR_EEPROM_CHECKSUM; | ||
1565 | |||
1566 | /* If the user cares, return the calculated checksum */ | ||
1567 | if (checksum_val) | ||
1568 | *checksum_val = checksum; | ||
1569 | } else { | ||
1570 | hw_dbg(hw, "EEPROM read failed\n"); | ||
1571 | } | ||
1572 | |||
1573 | return status; | ||
1574 | } | ||
1575 | |||
1576 | /** | ||
1577 | * ixgbe_update_eeprom_checksum_generic - Updates the EEPROM checksum | ||
1578 | * @hw: pointer to hardware structure | ||
1579 | **/ | ||
1580 | s32 ixgbe_update_eeprom_checksum_generic(struct ixgbe_hw *hw) | ||
1581 | { | ||
1582 | s32 status; | ||
1583 | u16 checksum; | ||
1584 | |||
1585 | /* | ||
1586 | * Read the first word from the EEPROM. If this times out or fails, do | ||
1587 | * not continue or we could be in for a very long wait while every | ||
1588 | * EEPROM read fails | ||
1589 | */ | ||
1590 | status = hw->eeprom.ops.read(hw, 0, &checksum); | ||
1591 | |||
1592 | if (status == 0) { | ||
1593 | checksum = hw->eeprom.ops.calc_checksum(hw); | ||
1594 | status = hw->eeprom.ops.write(hw, IXGBE_EEPROM_CHECKSUM, | ||
1595 | checksum); | ||
1596 | } else { | ||
1597 | hw_dbg(hw, "EEPROM read failed\n"); | ||
1598 | } | ||
1599 | |||
1600 | return status; | ||
1601 | } | ||
1602 | |||
1603 | /** | ||
1604 | * ixgbe_validate_mac_addr - Validate MAC address | ||
1605 | * @mac_addr: pointer to MAC address. | ||
1606 | * | ||
1607 | * Tests a MAC address to ensure it is a valid Individual Address | ||
1608 | **/ | ||
1609 | s32 ixgbe_validate_mac_addr(u8 *mac_addr) | ||
1610 | { | ||
1611 | s32 status = 0; | ||
1612 | |||
1613 | /* Make sure it is not a multicast address */ | ||
1614 | if (IXGBE_IS_MULTICAST(mac_addr)) | ||
1615 | status = IXGBE_ERR_INVALID_MAC_ADDR; | ||
1616 | /* Not a broadcast address */ | ||
1617 | else if (IXGBE_IS_BROADCAST(mac_addr)) | ||
1618 | status = IXGBE_ERR_INVALID_MAC_ADDR; | ||
1619 | /* Reject the zero address */ | ||
1620 | else if (mac_addr[0] == 0 && mac_addr[1] == 0 && mac_addr[2] == 0 && | ||
1621 | mac_addr[3] == 0 && mac_addr[4] == 0 && mac_addr[5] == 0) | ||
1622 | status = IXGBE_ERR_INVALID_MAC_ADDR; | ||
1623 | |||
1624 | return status; | ||
1625 | } | ||
1626 | |||
1627 | /** | ||
1628 | * ixgbe_set_rar_generic - Set Rx address register | ||
1629 | * @hw: pointer to hardware structure | ||
1630 | * @index: Receive address register to write | ||
1631 | * @addr: Address to put into receive address register | ||
1632 | * @vmdq: VMDq "set" or "pool" index | ||
1633 | * @enable_addr: set flag that address is active | ||
1634 | * | ||
1635 | * Puts an ethernet address into a receive address register. | ||
1636 | **/ | ||
1637 | s32 ixgbe_set_rar_generic(struct ixgbe_hw *hw, u32 index, u8 *addr, u32 vmdq, | ||
1638 | u32 enable_addr) | ||
1639 | { | ||
1640 | u32 rar_low, rar_high; | ||
1641 | u32 rar_entries = hw->mac.num_rar_entries; | ||
1642 | |||
1643 | /* Make sure we are using a valid rar index range */ | ||
1644 | if (index >= rar_entries) { | ||
1645 | hw_dbg(hw, "RAR index %d is out of range.\n", index); | ||
1646 | return IXGBE_ERR_INVALID_ARGUMENT; | ||
1647 | } | ||
1648 | |||
1649 | /* setup VMDq pool selection before this RAR gets enabled */ | ||
1650 | hw->mac.ops.set_vmdq(hw, index, vmdq); | ||
1651 | |||
1652 | /* | ||
1653 | * HW expects these in little endian so we reverse the byte | ||
1654 | * order from network order (big endian) to little endian | ||
1655 | */ | ||
1656 | rar_low = ((u32)addr[0] | | ||
1657 | ((u32)addr[1] << 8) | | ||
1658 | ((u32)addr[2] << 16) | | ||
1659 | ((u32)addr[3] << 24)); | ||
1660 | /* | ||
1661 | * Some parts put the VMDq setting in the extra RAH bits, | ||
1662 | * so save everything except the lower 16 bits that hold part | ||
1663 | * of the address and the address valid bit. | ||
1664 | */ | ||
1665 | rar_high = IXGBE_READ_REG(hw, IXGBE_RAH(index)); | ||
1666 | rar_high &= ~(0x0000FFFF | IXGBE_RAH_AV); | ||
1667 | rar_high |= ((u32)addr[4] | ((u32)addr[5] << 8)); | ||
1668 | |||
1669 | if (enable_addr != 0) | ||
1670 | rar_high |= IXGBE_RAH_AV; | ||
1671 | |||
1672 | IXGBE_WRITE_REG(hw, IXGBE_RAL(index), rar_low); | ||
1673 | IXGBE_WRITE_REG(hw, IXGBE_RAH(index), rar_high); | ||
1674 | |||
1675 | return 0; | ||
1676 | } | ||
1677 | |||
1678 | /** | ||
1679 | * ixgbe_clear_rar_generic - Remove Rx address register | ||
1680 | * @hw: pointer to hardware structure | ||
1681 | * @index: Receive address register to write | ||
1682 | * | ||
1683 | * Clears an ethernet address from a receive address register. | ||
1684 | **/ | ||
1685 | s32 ixgbe_clear_rar_generic(struct ixgbe_hw *hw, u32 index) | ||
1686 | { | ||
1687 | u32 rar_high; | ||
1688 | u32 rar_entries = hw->mac.num_rar_entries; | ||
1689 | |||
1690 | /* Make sure we are using a valid rar index range */ | ||
1691 | if (index >= rar_entries) { | ||
1692 | hw_dbg(hw, "RAR index %d is out of range.\n", index); | ||
1693 | return IXGBE_ERR_INVALID_ARGUMENT; | ||
1694 | } | ||
1695 | |||
1696 | /* | ||
1697 | * Some parts put the VMDq setting in the extra RAH bits, | ||
1698 | * so save everything except the lower 16 bits that hold part | ||
1699 | * of the address and the address valid bit. | ||
1700 | */ | ||
1701 | rar_high = IXGBE_READ_REG(hw, IXGBE_RAH(index)); | ||
1702 | rar_high &= ~(0x0000FFFF | IXGBE_RAH_AV); | ||
1703 | |||
1704 | IXGBE_WRITE_REG(hw, IXGBE_RAL(index), 0); | ||
1705 | IXGBE_WRITE_REG(hw, IXGBE_RAH(index), rar_high); | ||
1706 | |||
1707 | /* clear VMDq pool/queue selection for this RAR */ | ||
1708 | hw->mac.ops.clear_vmdq(hw, index, IXGBE_CLEAR_VMDQ_ALL); | ||
1709 | |||
1710 | return 0; | ||
1711 | } | ||
1712 | |||
1713 | /** | ||
1714 | * ixgbe_init_rx_addrs_generic - Initializes receive address filters. | ||
1715 | * @hw: pointer to hardware structure | ||
1716 | * | ||
1717 | * Places the MAC address in receive address register 0 and clears the rest | ||
1718 | * of the receive address registers. Clears the multicast table. Assumes | ||
1719 | * the receiver is in reset when the routine is called. | ||
1720 | **/ | ||
1721 | s32 ixgbe_init_rx_addrs_generic(struct ixgbe_hw *hw) | ||
1722 | { | ||
1723 | u32 i; | ||
1724 | u32 rar_entries = hw->mac.num_rar_entries; | ||
1725 | |||
1726 | /* | ||
1727 | * If the current mac address is valid, assume it is a software override | ||
1728 | * to the permanent address. | ||
1729 | * Otherwise, use the permanent address from the eeprom. | ||
1730 | */ | ||
1731 | if (ixgbe_validate_mac_addr(hw->mac.addr) == | ||
1732 | IXGBE_ERR_INVALID_MAC_ADDR) { | ||
1733 | /* Get the MAC address from the RAR0 for later reference */ | ||
1734 | hw->mac.ops.get_mac_addr(hw, hw->mac.addr); | ||
1735 | |||
1736 | hw_dbg(hw, " Keeping Current RAR0 Addr =%pM\n", hw->mac.addr); | ||
1737 | } else { | ||
1738 | /* Setup the receive address. */ | ||
1739 | hw_dbg(hw, "Overriding MAC Address in RAR[0]\n"); | ||
1740 | hw_dbg(hw, " New MAC Addr =%pM\n", hw->mac.addr); | ||
1741 | |||
1742 | hw->mac.ops.set_rar(hw, 0, hw->mac.addr, 0, IXGBE_RAH_AV); | ||
1743 | |||
1744 | /* clear VMDq pool/queue selection for RAR 0 */ | ||
1745 | hw->mac.ops.clear_vmdq(hw, 0, IXGBE_CLEAR_VMDQ_ALL); | ||
1746 | } | ||
1747 | hw->addr_ctrl.overflow_promisc = 0; | ||
1748 | |||
1749 | hw->addr_ctrl.rar_used_count = 1; | ||
1750 | |||
1751 | /* Zero out the other receive addresses. */ | ||
1752 | hw_dbg(hw, "Clearing RAR[1-%d]\n", rar_entries - 1); | ||
1753 | for (i = 1; i < rar_entries; i++) { | ||
1754 | IXGBE_WRITE_REG(hw, IXGBE_RAL(i), 0); | ||
1755 | IXGBE_WRITE_REG(hw, IXGBE_RAH(i), 0); | ||
1756 | } | ||
1757 | |||
1758 | /* Clear the MTA */ | ||
1759 | hw->addr_ctrl.mta_in_use = 0; | ||
1760 | IXGBE_WRITE_REG(hw, IXGBE_MCSTCTRL, hw->mac.mc_filter_type); | ||
1761 | |||
1762 | hw_dbg(hw, " Clearing MTA\n"); | ||
1763 | for (i = 0; i < hw->mac.mcft_size; i++) | ||
1764 | IXGBE_WRITE_REG(hw, IXGBE_MTA(i), 0); | ||
1765 | |||
1766 | if (hw->mac.ops.init_uta_tables) | ||
1767 | hw->mac.ops.init_uta_tables(hw); | ||
1768 | |||
1769 | return 0; | ||
1770 | } | ||
1771 | |||
1772 | /** | ||
1773 | * ixgbe_mta_vector - Determines bit-vector in multicast table to set | ||
1774 | * @hw: pointer to hardware structure | ||
1775 | * @mc_addr: the multicast address | ||
1776 | * | ||
1777 | * Extracts the 12 bits, from a multicast address, to determine which | ||
1778 | * bit-vector to set in the multicast table. The hardware uses 12 bits, from | ||
1779 | * incoming rx multicast addresses, to determine the bit-vector to check in | ||
1780 | * the MTA. Which of the 4 combination, of 12-bits, the hardware uses is set | ||
1781 | * by the MO field of the MCSTCTRL. The MO field is set during initialization | ||
1782 | * to mc_filter_type. | ||
1783 | **/ | ||
1784 | static s32 ixgbe_mta_vector(struct ixgbe_hw *hw, u8 *mc_addr) | ||
1785 | { | ||
1786 | u32 vector = 0; | ||
1787 | |||
1788 | switch (hw->mac.mc_filter_type) { | ||
1789 | case 0: /* use bits [47:36] of the address */ | ||
1790 | vector = ((mc_addr[4] >> 4) | (((u16)mc_addr[5]) << 4)); | ||
1791 | break; | ||
1792 | case 1: /* use bits [46:35] of the address */ | ||
1793 | vector = ((mc_addr[4] >> 3) | (((u16)mc_addr[5]) << 5)); | ||
1794 | break; | ||
1795 | case 2: /* use bits [45:34] of the address */ | ||
1796 | vector = ((mc_addr[4] >> 2) | (((u16)mc_addr[5]) << 6)); | ||
1797 | break; | ||
1798 | case 3: /* use bits [43:32] of the address */ | ||
1799 | vector = ((mc_addr[4]) | (((u16)mc_addr[5]) << 8)); | ||
1800 | break; | ||
1801 | default: /* Invalid mc_filter_type */ | ||
1802 | hw_dbg(hw, "MC filter type param set incorrectly\n"); | ||
1803 | break; | ||
1804 | } | ||
1805 | |||
1806 | /* vector can only be 12-bits or boundary will be exceeded */ | ||
1807 | vector &= 0xFFF; | ||
1808 | return vector; | ||
1809 | } | ||
1810 | |||
1811 | /** | ||
1812 | * ixgbe_set_mta - Set bit-vector in multicast table | ||
1813 | * @hw: pointer to hardware structure | ||
1814 | * @hash_value: Multicast address hash value | ||
1815 | * | ||
1816 | * Sets the bit-vector in the multicast table. | ||
1817 | **/ | ||
1818 | static void ixgbe_set_mta(struct ixgbe_hw *hw, u8 *mc_addr) | ||
1819 | { | ||
1820 | u32 vector; | ||
1821 | u32 vector_bit; | ||
1822 | u32 vector_reg; | ||
1823 | |||
1824 | hw->addr_ctrl.mta_in_use++; | ||
1825 | |||
1826 | vector = ixgbe_mta_vector(hw, mc_addr); | ||
1827 | hw_dbg(hw, " bit-vector = 0x%03X\n", vector); | ||
1828 | |||
1829 | /* | ||
1830 | * The MTA is a register array of 128 32-bit registers. It is treated | ||
1831 | * like an array of 4096 bits. We want to set bit | ||
1832 | * BitArray[vector_value]. So we figure out what register the bit is | ||
1833 | * in, read it, OR in the new bit, then write back the new value. The | ||
1834 | * register is determined by the upper 7 bits of the vector value and | ||
1835 | * the bit within that register are determined by the lower 5 bits of | ||
1836 | * the value. | ||
1837 | */ | ||
1838 | vector_reg = (vector >> 5) & 0x7F; | ||
1839 | vector_bit = vector & 0x1F; | ||
1840 | hw->mac.mta_shadow[vector_reg] |= (1 << vector_bit); | ||
1841 | } | ||
1842 | |||
1843 | /** | ||
1844 | * ixgbe_update_mc_addr_list_generic - Updates MAC list of multicast addresses | ||
1845 | * @hw: pointer to hardware structure | ||
1846 | * @netdev: pointer to net device structure | ||
1847 | * | ||
1848 | * The given list replaces any existing list. Clears the MC addrs from receive | ||
1849 | * address registers and the multicast table. Uses unused receive address | ||
1850 | * registers for the first multicast addresses, and hashes the rest into the | ||
1851 | * multicast table. | ||
1852 | **/ | ||
1853 | s32 ixgbe_update_mc_addr_list_generic(struct ixgbe_hw *hw, | ||
1854 | struct net_device *netdev) | ||
1855 | { | ||
1856 | struct netdev_hw_addr *ha; | ||
1857 | u32 i; | ||
1858 | |||
1859 | /* | ||
1860 | * Set the new number of MC addresses that we are being requested to | ||
1861 | * use. | ||
1862 | */ | ||
1863 | hw->addr_ctrl.num_mc_addrs = netdev_mc_count(netdev); | ||
1864 | hw->addr_ctrl.mta_in_use = 0; | ||
1865 | |||
1866 | /* Clear mta_shadow */ | ||
1867 | hw_dbg(hw, " Clearing MTA\n"); | ||
1868 | memset(&hw->mac.mta_shadow, 0, sizeof(hw->mac.mta_shadow)); | ||
1869 | |||
1870 | /* Update mta shadow */ | ||
1871 | netdev_for_each_mc_addr(ha, netdev) { | ||
1872 | hw_dbg(hw, " Adding the multicast addresses:\n"); | ||
1873 | ixgbe_set_mta(hw, ha->addr); | ||
1874 | } | ||
1875 | |||
1876 | /* Enable mta */ | ||
1877 | for (i = 0; i < hw->mac.mcft_size; i++) | ||
1878 | IXGBE_WRITE_REG_ARRAY(hw, IXGBE_MTA(0), i, | ||
1879 | hw->mac.mta_shadow[i]); | ||
1880 | |||
1881 | if (hw->addr_ctrl.mta_in_use > 0) | ||
1882 | IXGBE_WRITE_REG(hw, IXGBE_MCSTCTRL, | ||
1883 | IXGBE_MCSTCTRL_MFE | hw->mac.mc_filter_type); | ||
1884 | |||
1885 | hw_dbg(hw, "ixgbe_update_mc_addr_list_generic Complete\n"); | ||
1886 | return 0; | ||
1887 | } | ||
1888 | |||
1889 | /** | ||
1890 | * ixgbe_enable_mc_generic - Enable multicast address in RAR | ||
1891 | * @hw: pointer to hardware structure | ||
1892 | * | ||
1893 | * Enables multicast address in RAR and the use of the multicast hash table. | ||
1894 | **/ | ||
1895 | s32 ixgbe_enable_mc_generic(struct ixgbe_hw *hw) | ||
1896 | { | ||
1897 | struct ixgbe_addr_filter_info *a = &hw->addr_ctrl; | ||
1898 | |||
1899 | if (a->mta_in_use > 0) | ||
1900 | IXGBE_WRITE_REG(hw, IXGBE_MCSTCTRL, IXGBE_MCSTCTRL_MFE | | ||
1901 | hw->mac.mc_filter_type); | ||
1902 | |||
1903 | return 0; | ||
1904 | } | ||
1905 | |||
1906 | /** | ||
1907 | * ixgbe_disable_mc_generic - Disable multicast address in RAR | ||
1908 | * @hw: pointer to hardware structure | ||
1909 | * | ||
1910 | * Disables multicast address in RAR and the use of the multicast hash table. | ||
1911 | **/ | ||
1912 | s32 ixgbe_disable_mc_generic(struct ixgbe_hw *hw) | ||
1913 | { | ||
1914 | struct ixgbe_addr_filter_info *a = &hw->addr_ctrl; | ||
1915 | |||
1916 | if (a->mta_in_use > 0) | ||
1917 | IXGBE_WRITE_REG(hw, IXGBE_MCSTCTRL, hw->mac.mc_filter_type); | ||
1918 | |||
1919 | return 0; | ||
1920 | } | ||
1921 | |||
1922 | /** | ||
1923 | * ixgbe_fc_enable_generic - Enable flow control | ||
1924 | * @hw: pointer to hardware structure | ||
1925 | * @packetbuf_num: packet buffer number (0-7) | ||
1926 | * | ||
1927 | * Enable flow control according to the current settings. | ||
1928 | **/ | ||
1929 | s32 ixgbe_fc_enable_generic(struct ixgbe_hw *hw, s32 packetbuf_num) | ||
1930 | { | ||
1931 | s32 ret_val = 0; | ||
1932 | u32 mflcn_reg, fccfg_reg; | ||
1933 | u32 reg; | ||
1934 | u32 rx_pba_size; | ||
1935 | u32 fcrtl, fcrth; | ||
1936 | |||
1937 | #ifdef CONFIG_DCB | ||
1938 | if (hw->fc.requested_mode == ixgbe_fc_pfc) | ||
1939 | goto out; | ||
1940 | |||
1941 | #endif /* CONFIG_DCB */ | ||
1942 | /* Negotiate the fc mode to use */ | ||
1943 | ret_val = ixgbe_fc_autoneg(hw); | ||
1944 | if (ret_val == IXGBE_ERR_FLOW_CONTROL) | ||
1945 | goto out; | ||
1946 | |||
1947 | /* Disable any previous flow control settings */ | ||
1948 | mflcn_reg = IXGBE_READ_REG(hw, IXGBE_MFLCN); | ||
1949 | mflcn_reg &= ~(IXGBE_MFLCN_RFCE | IXGBE_MFLCN_RPFCE); | ||
1950 | |||
1951 | fccfg_reg = IXGBE_READ_REG(hw, IXGBE_FCCFG); | ||
1952 | fccfg_reg &= ~(IXGBE_FCCFG_TFCE_802_3X | IXGBE_FCCFG_TFCE_PRIORITY); | ||
1953 | |||
1954 | /* | ||
1955 | * The possible values of fc.current_mode are: | ||
1956 | * 0: Flow control is completely disabled | ||
1957 | * 1: Rx flow control is enabled (we can receive pause frames, | ||
1958 | * but not send pause frames). | ||
1959 | * 2: Tx flow control is enabled (we can send pause frames but | ||
1960 | * we do not support receiving pause frames). | ||
1961 | * 3: Both Rx and Tx flow control (symmetric) are enabled. | ||
1962 | #ifdef CONFIG_DCB | ||
1963 | * 4: Priority Flow Control is enabled. | ||
1964 | #endif | ||
1965 | * other: Invalid. | ||
1966 | */ | ||
1967 | switch (hw->fc.current_mode) { | ||
1968 | case ixgbe_fc_none: | ||
1969 | /* | ||
1970 | * Flow control is disabled by software override or autoneg. | ||
1971 | * The code below will actually disable it in the HW. | ||
1972 | */ | ||
1973 | break; | ||
1974 | case ixgbe_fc_rx_pause: | ||
1975 | /* | ||
1976 | * Rx Flow control is enabled and Tx Flow control is | ||
1977 | * disabled by software override. Since there really | ||
1978 | * isn't a way to advertise that we are capable of RX | ||
1979 | * Pause ONLY, we will advertise that we support both | ||
1980 | * symmetric and asymmetric Rx PAUSE. Later, we will | ||
1981 | * disable the adapter's ability to send PAUSE frames. | ||
1982 | */ | ||
1983 | mflcn_reg |= IXGBE_MFLCN_RFCE; | ||
1984 | break; | ||
1985 | case ixgbe_fc_tx_pause: | ||
1986 | /* | ||
1987 | * Tx Flow control is enabled, and Rx Flow control is | ||
1988 | * disabled by software override. | ||
1989 | */ | ||
1990 | fccfg_reg |= IXGBE_FCCFG_TFCE_802_3X; | ||
1991 | break; | ||
1992 | case ixgbe_fc_full: | ||
1993 | /* Flow control (both Rx and Tx) is enabled by SW override. */ | ||
1994 | mflcn_reg |= IXGBE_MFLCN_RFCE; | ||
1995 | fccfg_reg |= IXGBE_FCCFG_TFCE_802_3X; | ||
1996 | break; | ||
1997 | #ifdef CONFIG_DCB | ||
1998 | case ixgbe_fc_pfc: | ||
1999 | goto out; | ||
2000 | break; | ||
2001 | #endif /* CONFIG_DCB */ | ||
2002 | default: | ||
2003 | hw_dbg(hw, "Flow control param set incorrectly\n"); | ||
2004 | ret_val = IXGBE_ERR_CONFIG; | ||
2005 | goto out; | ||
2006 | break; | ||
2007 | } | ||
2008 | |||
2009 | /* Set 802.3x based flow control settings. */ | ||
2010 | mflcn_reg |= IXGBE_MFLCN_DPF; | ||
2011 | IXGBE_WRITE_REG(hw, IXGBE_MFLCN, mflcn_reg); | ||
2012 | IXGBE_WRITE_REG(hw, IXGBE_FCCFG, fccfg_reg); | ||
2013 | |||
2014 | rx_pba_size = IXGBE_READ_REG(hw, IXGBE_RXPBSIZE(packetbuf_num)); | ||
2015 | rx_pba_size >>= IXGBE_RXPBSIZE_SHIFT; | ||
2016 | |||
2017 | fcrth = (rx_pba_size - hw->fc.high_water) << 10; | ||
2018 | fcrtl = (rx_pba_size - hw->fc.low_water) << 10; | ||
2019 | |||
2020 | if (hw->fc.current_mode & ixgbe_fc_tx_pause) { | ||
2021 | fcrth |= IXGBE_FCRTH_FCEN; | ||
2022 | if (hw->fc.send_xon) | ||
2023 | fcrtl |= IXGBE_FCRTL_XONE; | ||
2024 | } | ||
2025 | |||
2026 | IXGBE_WRITE_REG(hw, IXGBE_FCRTH_82599(packetbuf_num), fcrth); | ||
2027 | IXGBE_WRITE_REG(hw, IXGBE_FCRTL_82599(packetbuf_num), fcrtl); | ||
2028 | |||
2029 | /* Configure pause time (2 TCs per register) */ | ||
2030 | reg = IXGBE_READ_REG(hw, IXGBE_FCTTV(packetbuf_num / 2)); | ||
2031 | if ((packetbuf_num & 1) == 0) | ||
2032 | reg = (reg & 0xFFFF0000) | hw->fc.pause_time; | ||
2033 | else | ||
2034 | reg = (reg & 0x0000FFFF) | (hw->fc.pause_time << 16); | ||
2035 | IXGBE_WRITE_REG(hw, IXGBE_FCTTV(packetbuf_num / 2), reg); | ||
2036 | |||
2037 | IXGBE_WRITE_REG(hw, IXGBE_FCRTV, (hw->fc.pause_time >> 1)); | ||
2038 | |||
2039 | out: | ||
2040 | return ret_val; | ||
2041 | } | ||
2042 | |||
2043 | /** | ||
2044 | * ixgbe_fc_autoneg - Configure flow control | ||
2045 | * @hw: pointer to hardware structure | ||
2046 | * | ||
2047 | * Compares our advertised flow control capabilities to those advertised by | ||
2048 | * our link partner, and determines the proper flow control mode to use. | ||
2049 | **/ | ||
2050 | s32 ixgbe_fc_autoneg(struct ixgbe_hw *hw) | ||
2051 | { | ||
2052 | s32 ret_val = IXGBE_ERR_FC_NOT_NEGOTIATED; | ||
2053 | ixgbe_link_speed speed; | ||
2054 | bool link_up; | ||
2055 | |||
2056 | if (hw->fc.disable_fc_autoneg) | ||
2057 | goto out; | ||
2058 | |||
2059 | /* | ||
2060 | * AN should have completed when the cable was plugged in. | ||
2061 | * Look for reasons to bail out. Bail out if: | ||
2062 | * - FC autoneg is disabled, or if | ||
2063 | * - link is not up. | ||
2064 | * | ||
2065 | * Since we're being called from an LSC, link is already known to be up. | ||
2066 | * So use link_up_wait_to_complete=false. | ||
2067 | */ | ||
2068 | hw->mac.ops.check_link(hw, &speed, &link_up, false); | ||
2069 | if (!link_up) { | ||
2070 | ret_val = IXGBE_ERR_FLOW_CONTROL; | ||
2071 | goto out; | ||
2072 | } | ||
2073 | |||
2074 | switch (hw->phy.media_type) { | ||
2075 | /* Autoneg flow control on fiber adapters */ | ||
2076 | case ixgbe_media_type_fiber: | ||
2077 | if (speed == IXGBE_LINK_SPEED_1GB_FULL) | ||
2078 | ret_val = ixgbe_fc_autoneg_fiber(hw); | ||
2079 | break; | ||
2080 | |||
2081 | /* Autoneg flow control on backplane adapters */ | ||
2082 | case ixgbe_media_type_backplane: | ||
2083 | ret_val = ixgbe_fc_autoneg_backplane(hw); | ||
2084 | break; | ||
2085 | |||
2086 | /* Autoneg flow control on copper adapters */ | ||
2087 | case ixgbe_media_type_copper: | ||
2088 | if (ixgbe_device_supports_autoneg_fc(hw) == 0) | ||
2089 | ret_val = ixgbe_fc_autoneg_copper(hw); | ||
2090 | break; | ||
2091 | |||
2092 | default: | ||
2093 | break; | ||
2094 | } | ||
2095 | |||
2096 | out: | ||
2097 | if (ret_val == 0) { | ||
2098 | hw->fc.fc_was_autonegged = true; | ||
2099 | } else { | ||
2100 | hw->fc.fc_was_autonegged = false; | ||
2101 | hw->fc.current_mode = hw->fc.requested_mode; | ||
2102 | } | ||
2103 | return ret_val; | ||
2104 | } | ||
2105 | |||
2106 | /** | ||
2107 | * ixgbe_fc_autoneg_fiber - Enable flow control on 1 gig fiber | ||
2108 | * @hw: pointer to hardware structure | ||
2109 | * | ||
2110 | * Enable flow control according on 1 gig fiber. | ||
2111 | **/ | ||
2112 | static s32 ixgbe_fc_autoneg_fiber(struct ixgbe_hw *hw) | ||
2113 | { | ||
2114 | u32 pcs_anadv_reg, pcs_lpab_reg, linkstat; | ||
2115 | s32 ret_val; | ||
2116 | |||
2117 | /* | ||
2118 | * On multispeed fiber at 1g, bail out if | ||
2119 | * - link is up but AN did not complete, or if | ||
2120 | * - link is up and AN completed but timed out | ||
2121 | */ | ||
2122 | |||
2123 | linkstat = IXGBE_READ_REG(hw, IXGBE_PCS1GLSTA); | ||
2124 | if (((linkstat & IXGBE_PCS1GLSTA_AN_COMPLETE) == 0) || | ||
2125 | ((linkstat & IXGBE_PCS1GLSTA_AN_TIMED_OUT) == 1)) { | ||
2126 | ret_val = IXGBE_ERR_FC_NOT_NEGOTIATED; | ||
2127 | goto out; | ||
2128 | } | ||
2129 | |||
2130 | pcs_anadv_reg = IXGBE_READ_REG(hw, IXGBE_PCS1GANA); | ||
2131 | pcs_lpab_reg = IXGBE_READ_REG(hw, IXGBE_PCS1GANLP); | ||
2132 | |||
2133 | ret_val = ixgbe_negotiate_fc(hw, pcs_anadv_reg, | ||
2134 | pcs_lpab_reg, IXGBE_PCS1GANA_SYM_PAUSE, | ||
2135 | IXGBE_PCS1GANA_ASM_PAUSE, | ||
2136 | IXGBE_PCS1GANA_SYM_PAUSE, | ||
2137 | IXGBE_PCS1GANA_ASM_PAUSE); | ||
2138 | |||
2139 | out: | ||
2140 | return ret_val; | ||
2141 | } | ||
2142 | |||
2143 | /** | ||
2144 | * ixgbe_fc_autoneg_backplane - Enable flow control IEEE clause 37 | ||
2145 | * @hw: pointer to hardware structure | ||
2146 | * | ||
2147 | * Enable flow control according to IEEE clause 37. | ||
2148 | **/ | ||
2149 | static s32 ixgbe_fc_autoneg_backplane(struct ixgbe_hw *hw) | ||
2150 | { | ||
2151 | u32 links2, anlp1_reg, autoc_reg, links; | ||
2152 | s32 ret_val; | ||
2153 | |||
2154 | /* | ||
2155 | * On backplane, bail out if | ||
2156 | * - backplane autoneg was not completed, or if | ||
2157 | * - we are 82599 and link partner is not AN enabled | ||
2158 | */ | ||
2159 | links = IXGBE_READ_REG(hw, IXGBE_LINKS); | ||
2160 | if ((links & IXGBE_LINKS_KX_AN_COMP) == 0) { | ||
2161 | hw->fc.fc_was_autonegged = false; | ||
2162 | hw->fc.current_mode = hw->fc.requested_mode; | ||
2163 | ret_val = IXGBE_ERR_FC_NOT_NEGOTIATED; | ||
2164 | goto out; | ||
2165 | } | ||
2166 | |||
2167 | if (hw->mac.type == ixgbe_mac_82599EB) { | ||
2168 | links2 = IXGBE_READ_REG(hw, IXGBE_LINKS2); | ||
2169 | if ((links2 & IXGBE_LINKS2_AN_SUPPORTED) == 0) { | ||
2170 | hw->fc.fc_was_autonegged = false; | ||
2171 | hw->fc.current_mode = hw->fc.requested_mode; | ||
2172 | ret_val = IXGBE_ERR_FC_NOT_NEGOTIATED; | ||
2173 | goto out; | ||
2174 | } | ||
2175 | } | ||
2176 | /* | ||
2177 | * Read the 10g AN autoc and LP ability registers and resolve | ||
2178 | * local flow control settings accordingly | ||
2179 | */ | ||
2180 | autoc_reg = IXGBE_READ_REG(hw, IXGBE_AUTOC); | ||
2181 | anlp1_reg = IXGBE_READ_REG(hw, IXGBE_ANLP1); | ||
2182 | |||
2183 | ret_val = ixgbe_negotiate_fc(hw, autoc_reg, | ||
2184 | anlp1_reg, IXGBE_AUTOC_SYM_PAUSE, IXGBE_AUTOC_ASM_PAUSE, | ||
2185 | IXGBE_ANLP1_SYM_PAUSE, IXGBE_ANLP1_ASM_PAUSE); | ||
2186 | |||
2187 | out: | ||
2188 | return ret_val; | ||
2189 | } | ||
2190 | |||
2191 | /** | ||
2192 | * ixgbe_fc_autoneg_copper - Enable flow control IEEE clause 37 | ||
2193 | * @hw: pointer to hardware structure | ||
2194 | * | ||
2195 | * Enable flow control according to IEEE clause 37. | ||
2196 | **/ | ||
2197 | static s32 ixgbe_fc_autoneg_copper(struct ixgbe_hw *hw) | ||
2198 | { | ||
2199 | u16 technology_ability_reg = 0; | ||
2200 | u16 lp_technology_ability_reg = 0; | ||
2201 | |||
2202 | hw->phy.ops.read_reg(hw, MDIO_AN_ADVERTISE, | ||
2203 | MDIO_MMD_AN, | ||
2204 | &technology_ability_reg); | ||
2205 | hw->phy.ops.read_reg(hw, MDIO_AN_LPA, | ||
2206 | MDIO_MMD_AN, | ||
2207 | &lp_technology_ability_reg); | ||
2208 | |||
2209 | return ixgbe_negotiate_fc(hw, (u32)technology_ability_reg, | ||
2210 | (u32)lp_technology_ability_reg, | ||
2211 | IXGBE_TAF_SYM_PAUSE, IXGBE_TAF_ASM_PAUSE, | ||
2212 | IXGBE_TAF_SYM_PAUSE, IXGBE_TAF_ASM_PAUSE); | ||
2213 | } | ||
2214 | |||
2215 | /** | ||
2216 | * ixgbe_negotiate_fc - Negotiate flow control | ||
2217 | * @hw: pointer to hardware structure | ||
2218 | * @adv_reg: flow control advertised settings | ||
2219 | * @lp_reg: link partner's flow control settings | ||
2220 | * @adv_sym: symmetric pause bit in advertisement | ||
2221 | * @adv_asm: asymmetric pause bit in advertisement | ||
2222 | * @lp_sym: symmetric pause bit in link partner advertisement | ||
2223 | * @lp_asm: asymmetric pause bit in link partner advertisement | ||
2224 | * | ||
2225 | * Find the intersection between advertised settings and link partner's | ||
2226 | * advertised settings | ||
2227 | **/ | ||
2228 | static s32 ixgbe_negotiate_fc(struct ixgbe_hw *hw, u32 adv_reg, u32 lp_reg, | ||
2229 | u32 adv_sym, u32 adv_asm, u32 lp_sym, u32 lp_asm) | ||
2230 | { | ||
2231 | if ((!(adv_reg)) || (!(lp_reg))) | ||
2232 | return IXGBE_ERR_FC_NOT_NEGOTIATED; | ||
2233 | |||
2234 | if ((adv_reg & adv_sym) && (lp_reg & lp_sym)) { | ||
2235 | /* | ||
2236 | * Now we need to check if the user selected Rx ONLY | ||
2237 | * of pause frames. In this case, we had to advertise | ||
2238 | * FULL flow control because we could not advertise RX | ||
2239 | * ONLY. Hence, we must now check to see if we need to | ||
2240 | * turn OFF the TRANSMISSION of PAUSE frames. | ||
2241 | */ | ||
2242 | if (hw->fc.requested_mode == ixgbe_fc_full) { | ||
2243 | hw->fc.current_mode = ixgbe_fc_full; | ||
2244 | hw_dbg(hw, "Flow Control = FULL.\n"); | ||
2245 | } else { | ||
2246 | hw->fc.current_mode = ixgbe_fc_rx_pause; | ||
2247 | hw_dbg(hw, "Flow Control=RX PAUSE frames only\n"); | ||
2248 | } | ||
2249 | } else if (!(adv_reg & adv_sym) && (adv_reg & adv_asm) && | ||
2250 | (lp_reg & lp_sym) && (lp_reg & lp_asm)) { | ||
2251 | hw->fc.current_mode = ixgbe_fc_tx_pause; | ||
2252 | hw_dbg(hw, "Flow Control = TX PAUSE frames only.\n"); | ||
2253 | } else if ((adv_reg & adv_sym) && (adv_reg & adv_asm) && | ||
2254 | !(lp_reg & lp_sym) && (lp_reg & lp_asm)) { | ||
2255 | hw->fc.current_mode = ixgbe_fc_rx_pause; | ||
2256 | hw_dbg(hw, "Flow Control = RX PAUSE frames only.\n"); | ||
2257 | } else { | ||
2258 | hw->fc.current_mode = ixgbe_fc_none; | ||
2259 | hw_dbg(hw, "Flow Control = NONE.\n"); | ||
2260 | } | ||
2261 | return 0; | ||
2262 | } | ||
2263 | |||
2264 | /** | ||
2265 | * ixgbe_setup_fc - Set up flow control | ||
2266 | * @hw: pointer to hardware structure | ||
2267 | * | ||
2268 | * Called at init time to set up flow control. | ||
2269 | **/ | ||
2270 | static s32 ixgbe_setup_fc(struct ixgbe_hw *hw, s32 packetbuf_num) | ||
2271 | { | ||
2272 | s32 ret_val = 0; | ||
2273 | u32 reg = 0, reg_bp = 0; | ||
2274 | u16 reg_cu = 0; | ||
2275 | |||
2276 | #ifdef CONFIG_DCB | ||
2277 | if (hw->fc.requested_mode == ixgbe_fc_pfc) { | ||
2278 | hw->fc.current_mode = hw->fc.requested_mode; | ||
2279 | goto out; | ||
2280 | } | ||
2281 | |||
2282 | #endif /* CONFIG_DCB */ | ||
2283 | /* Validate the packetbuf configuration */ | ||
2284 | if (packetbuf_num < 0 || packetbuf_num > 7) { | ||
2285 | hw_dbg(hw, "Invalid packet buffer number [%d], expected range " | ||
2286 | "is 0-7\n", packetbuf_num); | ||
2287 | ret_val = IXGBE_ERR_INVALID_LINK_SETTINGS; | ||
2288 | goto out; | ||
2289 | } | ||
2290 | |||
2291 | /* | ||
2292 | * Validate the water mark configuration. Zero water marks are invalid | ||
2293 | * because it causes the controller to just blast out fc packets. | ||
2294 | */ | ||
2295 | if (!hw->fc.low_water || !hw->fc.high_water || !hw->fc.pause_time) { | ||
2296 | hw_dbg(hw, "Invalid water mark configuration\n"); | ||
2297 | ret_val = IXGBE_ERR_INVALID_LINK_SETTINGS; | ||
2298 | goto out; | ||
2299 | } | ||
2300 | |||
2301 | /* | ||
2302 | * Validate the requested mode. Strict IEEE mode does not allow | ||
2303 | * ixgbe_fc_rx_pause because it will cause us to fail at UNH. | ||
2304 | */ | ||
2305 | if (hw->fc.strict_ieee && hw->fc.requested_mode == ixgbe_fc_rx_pause) { | ||
2306 | hw_dbg(hw, "ixgbe_fc_rx_pause not valid in strict " | ||
2307 | "IEEE mode\n"); | ||
2308 | ret_val = IXGBE_ERR_INVALID_LINK_SETTINGS; | ||
2309 | goto out; | ||
2310 | } | ||
2311 | |||
2312 | /* | ||
2313 | * 10gig parts do not have a word in the EEPROM to determine the | ||
2314 | * default flow control setting, so we explicitly set it to full. | ||
2315 | */ | ||
2316 | if (hw->fc.requested_mode == ixgbe_fc_default) | ||
2317 | hw->fc.requested_mode = ixgbe_fc_full; | ||
2318 | |||
2319 | /* | ||
2320 | * Set up the 1G and 10G flow control advertisement registers so the | ||
2321 | * HW will be able to do fc autoneg once the cable is plugged in. If | ||
2322 | * we link at 10G, the 1G advertisement is harmless and vice versa. | ||
2323 | */ | ||
2324 | |||
2325 | switch (hw->phy.media_type) { | ||
2326 | case ixgbe_media_type_fiber: | ||
2327 | case ixgbe_media_type_backplane: | ||
2328 | reg = IXGBE_READ_REG(hw, IXGBE_PCS1GANA); | ||
2329 | reg_bp = IXGBE_READ_REG(hw, IXGBE_AUTOC); | ||
2330 | break; | ||
2331 | |||
2332 | case ixgbe_media_type_copper: | ||
2333 | hw->phy.ops.read_reg(hw, MDIO_AN_ADVERTISE, | ||
2334 | MDIO_MMD_AN, ®_cu); | ||
2335 | break; | ||
2336 | |||
2337 | default: | ||
2338 | ; | ||
2339 | } | ||
2340 | |||
2341 | /* | ||
2342 | * The possible values of fc.requested_mode are: | ||
2343 | * 0: Flow control is completely disabled | ||
2344 | * 1: Rx flow control is enabled (we can receive pause frames, | ||
2345 | * but not send pause frames). | ||
2346 | * 2: Tx flow control is enabled (we can send pause frames but | ||
2347 | * we do not support receiving pause frames). | ||
2348 | * 3: Both Rx and Tx flow control (symmetric) are enabled. | ||
2349 | #ifdef CONFIG_DCB | ||
2350 | * 4: Priority Flow Control is enabled. | ||
2351 | #endif | ||
2352 | * other: Invalid. | ||
2353 | */ | ||
2354 | switch (hw->fc.requested_mode) { | ||
2355 | case ixgbe_fc_none: | ||
2356 | /* Flow control completely disabled by software override. */ | ||
2357 | reg &= ~(IXGBE_PCS1GANA_SYM_PAUSE | IXGBE_PCS1GANA_ASM_PAUSE); | ||
2358 | if (hw->phy.media_type == ixgbe_media_type_backplane) | ||
2359 | reg_bp &= ~(IXGBE_AUTOC_SYM_PAUSE | | ||
2360 | IXGBE_AUTOC_ASM_PAUSE); | ||
2361 | else if (hw->phy.media_type == ixgbe_media_type_copper) | ||
2362 | reg_cu &= ~(IXGBE_TAF_SYM_PAUSE | IXGBE_TAF_ASM_PAUSE); | ||
2363 | break; | ||
2364 | case ixgbe_fc_rx_pause: | ||
2365 | /* | ||
2366 | * Rx Flow control is enabled and Tx Flow control is | ||
2367 | * disabled by software override. Since there really | ||
2368 | * isn't a way to advertise that we are capable of RX | ||
2369 | * Pause ONLY, we will advertise that we support both | ||
2370 | * symmetric and asymmetric Rx PAUSE. Later, we will | ||
2371 | * disable the adapter's ability to send PAUSE frames. | ||
2372 | */ | ||
2373 | reg |= (IXGBE_PCS1GANA_SYM_PAUSE | IXGBE_PCS1GANA_ASM_PAUSE); | ||
2374 | if (hw->phy.media_type == ixgbe_media_type_backplane) | ||
2375 | reg_bp |= (IXGBE_AUTOC_SYM_PAUSE | | ||
2376 | IXGBE_AUTOC_ASM_PAUSE); | ||
2377 | else if (hw->phy.media_type == ixgbe_media_type_copper) | ||
2378 | reg_cu |= (IXGBE_TAF_SYM_PAUSE | IXGBE_TAF_ASM_PAUSE); | ||
2379 | break; | ||
2380 | case ixgbe_fc_tx_pause: | ||
2381 | /* | ||
2382 | * Tx Flow control is enabled, and Rx Flow control is | ||
2383 | * disabled by software override. | ||
2384 | */ | ||
2385 | reg |= (IXGBE_PCS1GANA_ASM_PAUSE); | ||
2386 | reg &= ~(IXGBE_PCS1GANA_SYM_PAUSE); | ||
2387 | if (hw->phy.media_type == ixgbe_media_type_backplane) { | ||
2388 | reg_bp |= (IXGBE_AUTOC_ASM_PAUSE); | ||
2389 | reg_bp &= ~(IXGBE_AUTOC_SYM_PAUSE); | ||
2390 | } else if (hw->phy.media_type == ixgbe_media_type_copper) { | ||
2391 | reg_cu |= (IXGBE_TAF_ASM_PAUSE); | ||
2392 | reg_cu &= ~(IXGBE_TAF_SYM_PAUSE); | ||
2393 | } | ||
2394 | break; | ||
2395 | case ixgbe_fc_full: | ||
2396 | /* Flow control (both Rx and Tx) is enabled by SW override. */ | ||
2397 | reg |= (IXGBE_PCS1GANA_SYM_PAUSE | IXGBE_PCS1GANA_ASM_PAUSE); | ||
2398 | if (hw->phy.media_type == ixgbe_media_type_backplane) | ||
2399 | reg_bp |= (IXGBE_AUTOC_SYM_PAUSE | | ||
2400 | IXGBE_AUTOC_ASM_PAUSE); | ||
2401 | else if (hw->phy.media_type == ixgbe_media_type_copper) | ||
2402 | reg_cu |= (IXGBE_TAF_SYM_PAUSE | IXGBE_TAF_ASM_PAUSE); | ||
2403 | break; | ||
2404 | #ifdef CONFIG_DCB | ||
2405 | case ixgbe_fc_pfc: | ||
2406 | goto out; | ||
2407 | break; | ||
2408 | #endif /* CONFIG_DCB */ | ||
2409 | default: | ||
2410 | hw_dbg(hw, "Flow control param set incorrectly\n"); | ||
2411 | ret_val = IXGBE_ERR_CONFIG; | ||
2412 | goto out; | ||
2413 | break; | ||
2414 | } | ||
2415 | |||
2416 | if (hw->mac.type != ixgbe_mac_X540) { | ||
2417 | /* | ||
2418 | * Enable auto-negotiation between the MAC & PHY; | ||
2419 | * the MAC will advertise clause 37 flow control. | ||
2420 | */ | ||
2421 | IXGBE_WRITE_REG(hw, IXGBE_PCS1GANA, reg); | ||
2422 | reg = IXGBE_READ_REG(hw, IXGBE_PCS1GLCTL); | ||
2423 | |||
2424 | /* Disable AN timeout */ | ||
2425 | if (hw->fc.strict_ieee) | ||
2426 | reg &= ~IXGBE_PCS1GLCTL_AN_1G_TIMEOUT_EN; | ||
2427 | |||
2428 | IXGBE_WRITE_REG(hw, IXGBE_PCS1GLCTL, reg); | ||
2429 | hw_dbg(hw, "Set up FC; PCS1GLCTL = 0x%08X\n", reg); | ||
2430 | } | ||
2431 | |||
2432 | /* | ||
2433 | * AUTOC restart handles negotiation of 1G and 10G on backplane | ||
2434 | * and copper. There is no need to set the PCS1GCTL register. | ||
2435 | * | ||
2436 | */ | ||
2437 | if (hw->phy.media_type == ixgbe_media_type_backplane) { | ||
2438 | reg_bp |= IXGBE_AUTOC_AN_RESTART; | ||
2439 | IXGBE_WRITE_REG(hw, IXGBE_AUTOC, reg_bp); | ||
2440 | } else if ((hw->phy.media_type == ixgbe_media_type_copper) && | ||
2441 | (ixgbe_device_supports_autoneg_fc(hw) == 0)) { | ||
2442 | hw->phy.ops.write_reg(hw, MDIO_AN_ADVERTISE, | ||
2443 | MDIO_MMD_AN, reg_cu); | ||
2444 | } | ||
2445 | |||
2446 | hw_dbg(hw, "Set up FC; IXGBE_AUTOC = 0x%08X\n", reg); | ||
2447 | out: | ||
2448 | return ret_val; | ||
2449 | } | ||
2450 | |||
2451 | /** | ||
2452 | * ixgbe_disable_pcie_master - Disable PCI-express master access | ||
2453 | * @hw: pointer to hardware structure | ||
2454 | * | ||
2455 | * Disables PCI-Express master access and verifies there are no pending | ||
2456 | * requests. IXGBE_ERR_MASTER_REQUESTS_PENDING is returned if master disable | ||
2457 | * bit hasn't caused the master requests to be disabled, else 0 | ||
2458 | * is returned signifying master requests disabled. | ||
2459 | **/ | ||
2460 | s32 ixgbe_disable_pcie_master(struct ixgbe_hw *hw) | ||
2461 | { | ||
2462 | struct ixgbe_adapter *adapter = hw->back; | ||
2463 | u32 i; | ||
2464 | u32 reg_val; | ||
2465 | u32 number_of_queues; | ||
2466 | s32 status = 0; | ||
2467 | u16 dev_status = 0; | ||
2468 | |||
2469 | /* Just jump out if bus mastering is already disabled */ | ||
2470 | if (!(IXGBE_READ_REG(hw, IXGBE_STATUS) & IXGBE_STATUS_GIO)) | ||
2471 | goto out; | ||
2472 | |||
2473 | /* Disable the receive unit by stopping each queue */ | ||
2474 | number_of_queues = hw->mac.max_rx_queues; | ||
2475 | for (i = 0; i < number_of_queues; i++) { | ||
2476 | reg_val = IXGBE_READ_REG(hw, IXGBE_RXDCTL(i)); | ||
2477 | if (reg_val & IXGBE_RXDCTL_ENABLE) { | ||
2478 | reg_val &= ~IXGBE_RXDCTL_ENABLE; | ||
2479 | IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(i), reg_val); | ||
2480 | } | ||
2481 | } | ||
2482 | |||
2483 | reg_val = IXGBE_READ_REG(hw, IXGBE_CTRL); | ||
2484 | reg_val |= IXGBE_CTRL_GIO_DIS; | ||
2485 | IXGBE_WRITE_REG(hw, IXGBE_CTRL, reg_val); | ||
2486 | |||
2487 | for (i = 0; i < IXGBE_PCI_MASTER_DISABLE_TIMEOUT; i++) { | ||
2488 | if (!(IXGBE_READ_REG(hw, IXGBE_STATUS) & IXGBE_STATUS_GIO)) | ||
2489 | goto check_device_status; | ||
2490 | udelay(100); | ||
2491 | } | ||
2492 | |||
2493 | hw_dbg(hw, "GIO Master Disable bit didn't clear - requesting resets\n"); | ||
2494 | status = IXGBE_ERR_MASTER_REQUESTS_PENDING; | ||
2495 | |||
2496 | /* | ||
2497 | * Before proceeding, make sure that the PCIe block does not have | ||
2498 | * transactions pending. | ||
2499 | */ | ||
2500 | check_device_status: | ||
2501 | for (i = 0; i < IXGBE_PCI_MASTER_DISABLE_TIMEOUT; i++) { | ||
2502 | pci_read_config_word(adapter->pdev, IXGBE_PCI_DEVICE_STATUS, | ||
2503 | &dev_status); | ||
2504 | if (!(dev_status & IXGBE_PCI_DEVICE_STATUS_TRANSACTION_PENDING)) | ||
2505 | break; | ||
2506 | udelay(100); | ||
2507 | } | ||
2508 | |||
2509 | if (i == IXGBE_PCI_MASTER_DISABLE_TIMEOUT) | ||
2510 | hw_dbg(hw, "PCIe transaction pending bit also did not clear.\n"); | ||
2511 | else | ||
2512 | goto out; | ||
2513 | |||
2514 | /* | ||
2515 | * Two consecutive resets are required via CTRL.RST per datasheet | ||
2516 | * 5.2.5.3.2 Master Disable. We set a flag to inform the reset routine | ||
2517 | * of this need. The first reset prevents new master requests from | ||
2518 | * being issued by our device. We then must wait 1usec for any | ||
2519 | * remaining completions from the PCIe bus to trickle in, and then reset | ||
2520 | * again to clear out any effects they may have had on our device. | ||
2521 | */ | ||
2522 | hw->mac.flags |= IXGBE_FLAGS_DOUBLE_RESET_REQUIRED; | ||
2523 | |||
2524 | out: | ||
2525 | return status; | ||
2526 | } | ||
2527 | |||
2528 | |||
2529 | /** | ||
2530 | * ixgbe_acquire_swfw_sync - Acquire SWFW semaphore | ||
2531 | * @hw: pointer to hardware structure | ||
2532 | * @mask: Mask to specify which semaphore to acquire | ||
2533 | * | ||
2534 | * Acquires the SWFW semaphore through the GSSR register for the specified | ||
2535 | * function (CSR, PHY0, PHY1, EEPROM, Flash) | ||
2536 | **/ | ||
2537 | s32 ixgbe_acquire_swfw_sync(struct ixgbe_hw *hw, u16 mask) | ||
2538 | { | ||
2539 | u32 gssr; | ||
2540 | u32 swmask = mask; | ||
2541 | u32 fwmask = mask << 5; | ||
2542 | s32 timeout = 200; | ||
2543 | |||
2544 | while (timeout) { | ||
2545 | /* | ||
2546 | * SW EEPROM semaphore bit is used for access to all | ||
2547 | * SW_FW_SYNC/GSSR bits (not just EEPROM) | ||
2548 | */ | ||
2549 | if (ixgbe_get_eeprom_semaphore(hw)) | ||
2550 | return IXGBE_ERR_SWFW_SYNC; | ||
2551 | |||
2552 | gssr = IXGBE_READ_REG(hw, IXGBE_GSSR); | ||
2553 | if (!(gssr & (fwmask | swmask))) | ||
2554 | break; | ||
2555 | |||
2556 | /* | ||
2557 | * Firmware currently using resource (fwmask) or other software | ||
2558 | * thread currently using resource (swmask) | ||
2559 | */ | ||
2560 | ixgbe_release_eeprom_semaphore(hw); | ||
2561 | usleep_range(5000, 10000); | ||
2562 | timeout--; | ||
2563 | } | ||
2564 | |||
2565 | if (!timeout) { | ||
2566 | hw_dbg(hw, "Driver can't access resource, SW_FW_SYNC timeout.\n"); | ||
2567 | return IXGBE_ERR_SWFW_SYNC; | ||
2568 | } | ||
2569 | |||
2570 | gssr |= swmask; | ||
2571 | IXGBE_WRITE_REG(hw, IXGBE_GSSR, gssr); | ||
2572 | |||
2573 | ixgbe_release_eeprom_semaphore(hw); | ||
2574 | return 0; | ||
2575 | } | ||
2576 | |||
2577 | /** | ||
2578 | * ixgbe_release_swfw_sync - Release SWFW semaphore | ||
2579 | * @hw: pointer to hardware structure | ||
2580 | * @mask: Mask to specify which semaphore to release | ||
2581 | * | ||
2582 | * Releases the SWFW semaphore through the GSSR register for the specified | ||
2583 | * function (CSR, PHY0, PHY1, EEPROM, Flash) | ||
2584 | **/ | ||
2585 | void ixgbe_release_swfw_sync(struct ixgbe_hw *hw, u16 mask) | ||
2586 | { | ||
2587 | u32 gssr; | ||
2588 | u32 swmask = mask; | ||
2589 | |||
2590 | ixgbe_get_eeprom_semaphore(hw); | ||
2591 | |||
2592 | gssr = IXGBE_READ_REG(hw, IXGBE_GSSR); | ||
2593 | gssr &= ~swmask; | ||
2594 | IXGBE_WRITE_REG(hw, IXGBE_GSSR, gssr); | ||
2595 | |||
2596 | ixgbe_release_eeprom_semaphore(hw); | ||
2597 | } | ||
2598 | |||
2599 | /** | ||
2600 | * ixgbe_enable_rx_dma_generic - Enable the Rx DMA unit | ||
2601 | * @hw: pointer to hardware structure | ||
2602 | * @regval: register value to write to RXCTRL | ||
2603 | * | ||
2604 | * Enables the Rx DMA unit | ||
2605 | **/ | ||
2606 | s32 ixgbe_enable_rx_dma_generic(struct ixgbe_hw *hw, u32 regval) | ||
2607 | { | ||
2608 | IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, regval); | ||
2609 | |||
2610 | return 0; | ||
2611 | } | ||
2612 | |||
2613 | /** | ||
2614 | * ixgbe_blink_led_start_generic - Blink LED based on index. | ||
2615 | * @hw: pointer to hardware structure | ||
2616 | * @index: led number to blink | ||
2617 | **/ | ||
2618 | s32 ixgbe_blink_led_start_generic(struct ixgbe_hw *hw, u32 index) | ||
2619 | { | ||
2620 | ixgbe_link_speed speed = 0; | ||
2621 | bool link_up = 0; | ||
2622 | u32 autoc_reg = IXGBE_READ_REG(hw, IXGBE_AUTOC); | ||
2623 | u32 led_reg = IXGBE_READ_REG(hw, IXGBE_LEDCTL); | ||
2624 | |||
2625 | /* | ||
2626 | * Link must be up to auto-blink the LEDs; | ||
2627 | * Force it if link is down. | ||
2628 | */ | ||
2629 | hw->mac.ops.check_link(hw, &speed, &link_up, false); | ||
2630 | |||
2631 | if (!link_up) { | ||
2632 | autoc_reg |= IXGBE_AUTOC_AN_RESTART; | ||
2633 | autoc_reg |= IXGBE_AUTOC_FLU; | ||
2634 | IXGBE_WRITE_REG(hw, IXGBE_AUTOC, autoc_reg); | ||
2635 | IXGBE_WRITE_FLUSH(hw); | ||
2636 | usleep_range(10000, 20000); | ||
2637 | } | ||
2638 | |||
2639 | led_reg &= ~IXGBE_LED_MODE_MASK(index); | ||
2640 | led_reg |= IXGBE_LED_BLINK(index); | ||
2641 | IXGBE_WRITE_REG(hw, IXGBE_LEDCTL, led_reg); | ||
2642 | IXGBE_WRITE_FLUSH(hw); | ||
2643 | |||
2644 | return 0; | ||
2645 | } | ||
2646 | |||
2647 | /** | ||
2648 | * ixgbe_blink_led_stop_generic - Stop blinking LED based on index. | ||
2649 | * @hw: pointer to hardware structure | ||
2650 | * @index: led number to stop blinking | ||
2651 | **/ | ||
2652 | s32 ixgbe_blink_led_stop_generic(struct ixgbe_hw *hw, u32 index) | ||
2653 | { | ||
2654 | u32 autoc_reg = IXGBE_READ_REG(hw, IXGBE_AUTOC); | ||
2655 | u32 led_reg = IXGBE_READ_REG(hw, IXGBE_LEDCTL); | ||
2656 | |||
2657 | autoc_reg &= ~IXGBE_AUTOC_FLU; | ||
2658 | autoc_reg |= IXGBE_AUTOC_AN_RESTART; | ||
2659 | IXGBE_WRITE_REG(hw, IXGBE_AUTOC, autoc_reg); | ||
2660 | |||
2661 | led_reg &= ~IXGBE_LED_MODE_MASK(index); | ||
2662 | led_reg &= ~IXGBE_LED_BLINK(index); | ||
2663 | led_reg |= IXGBE_LED_LINK_ACTIVE << IXGBE_LED_MODE_SHIFT(index); | ||
2664 | IXGBE_WRITE_REG(hw, IXGBE_LEDCTL, led_reg); | ||
2665 | IXGBE_WRITE_FLUSH(hw); | ||
2666 | |||
2667 | return 0; | ||
2668 | } | ||
2669 | |||
2670 | /** | ||
2671 | * ixgbe_get_san_mac_addr_offset - Get SAN MAC address offset from the EEPROM | ||
2672 | * @hw: pointer to hardware structure | ||
2673 | * @san_mac_offset: SAN MAC address offset | ||
2674 | * | ||
2675 | * This function will read the EEPROM location for the SAN MAC address | ||
2676 | * pointer, and returns the value at that location. This is used in both | ||
2677 | * get and set mac_addr routines. | ||
2678 | **/ | ||
2679 | static s32 ixgbe_get_san_mac_addr_offset(struct ixgbe_hw *hw, | ||
2680 | u16 *san_mac_offset) | ||
2681 | { | ||
2682 | /* | ||
2683 | * First read the EEPROM pointer to see if the MAC addresses are | ||
2684 | * available. | ||
2685 | */ | ||
2686 | hw->eeprom.ops.read(hw, IXGBE_SAN_MAC_ADDR_PTR, san_mac_offset); | ||
2687 | |||
2688 | return 0; | ||
2689 | } | ||
2690 | |||
2691 | /** | ||
2692 | * ixgbe_get_san_mac_addr_generic - SAN MAC address retrieval from the EEPROM | ||
2693 | * @hw: pointer to hardware structure | ||
2694 | * @san_mac_addr: SAN MAC address | ||
2695 | * | ||
2696 | * Reads the SAN MAC address from the EEPROM, if it's available. This is | ||
2697 | * per-port, so set_lan_id() must be called before reading the addresses. | ||
2698 | * set_lan_id() is called by identify_sfp(), but this cannot be relied | ||
2699 | * upon for non-SFP connections, so we must call it here. | ||
2700 | **/ | ||
2701 | s32 ixgbe_get_san_mac_addr_generic(struct ixgbe_hw *hw, u8 *san_mac_addr) | ||
2702 | { | ||
2703 | u16 san_mac_data, san_mac_offset; | ||
2704 | u8 i; | ||
2705 | |||
2706 | /* | ||
2707 | * First read the EEPROM pointer to see if the MAC addresses are | ||
2708 | * available. If they're not, no point in calling set_lan_id() here. | ||
2709 | */ | ||
2710 | ixgbe_get_san_mac_addr_offset(hw, &san_mac_offset); | ||
2711 | |||
2712 | if ((san_mac_offset == 0) || (san_mac_offset == 0xFFFF)) { | ||
2713 | /* | ||
2714 | * No addresses available in this EEPROM. It's not an | ||
2715 | * error though, so just wipe the local address and return. | ||
2716 | */ | ||
2717 | for (i = 0; i < 6; i++) | ||
2718 | san_mac_addr[i] = 0xFF; | ||
2719 | |||
2720 | goto san_mac_addr_out; | ||
2721 | } | ||
2722 | |||
2723 | /* make sure we know which port we need to program */ | ||
2724 | hw->mac.ops.set_lan_id(hw); | ||
2725 | /* apply the port offset to the address offset */ | ||
2726 | (hw->bus.func) ? (san_mac_offset += IXGBE_SAN_MAC_ADDR_PORT1_OFFSET) : | ||
2727 | (san_mac_offset += IXGBE_SAN_MAC_ADDR_PORT0_OFFSET); | ||
2728 | for (i = 0; i < 3; i++) { | ||
2729 | hw->eeprom.ops.read(hw, san_mac_offset, &san_mac_data); | ||
2730 | san_mac_addr[i * 2] = (u8)(san_mac_data); | ||
2731 | san_mac_addr[i * 2 + 1] = (u8)(san_mac_data >> 8); | ||
2732 | san_mac_offset++; | ||
2733 | } | ||
2734 | |||
2735 | san_mac_addr_out: | ||
2736 | return 0; | ||
2737 | } | ||
2738 | |||
2739 | /** | ||
2740 | * ixgbe_get_pcie_msix_count_generic - Gets MSI-X vector count | ||
2741 | * @hw: pointer to hardware structure | ||
2742 | * | ||
2743 | * Read PCIe configuration space, and get the MSI-X vector count from | ||
2744 | * the capabilities table. | ||
2745 | **/ | ||
2746 | u32 ixgbe_get_pcie_msix_count_generic(struct ixgbe_hw *hw) | ||
2747 | { | ||
2748 | struct ixgbe_adapter *adapter = hw->back; | ||
2749 | u16 msix_count; | ||
2750 | pci_read_config_word(adapter->pdev, IXGBE_PCIE_MSIX_82599_CAPS, | ||
2751 | &msix_count); | ||
2752 | msix_count &= IXGBE_PCIE_MSIX_TBL_SZ_MASK; | ||
2753 | |||
2754 | /* MSI-X count is zero-based in HW, so increment to give proper value */ | ||
2755 | msix_count++; | ||
2756 | |||
2757 | return msix_count; | ||
2758 | } | ||
2759 | |||
2760 | /** | ||
2761 | * ixgbe_clear_vmdq_generic - Disassociate a VMDq pool index from a rx address | ||
2762 | * @hw: pointer to hardware struct | ||
2763 | * @rar: receive address register index to disassociate | ||
2764 | * @vmdq: VMDq pool index to remove from the rar | ||
2765 | **/ | ||
2766 | s32 ixgbe_clear_vmdq_generic(struct ixgbe_hw *hw, u32 rar, u32 vmdq) | ||
2767 | { | ||
2768 | u32 mpsar_lo, mpsar_hi; | ||
2769 | u32 rar_entries = hw->mac.num_rar_entries; | ||
2770 | |||
2771 | /* Make sure we are using a valid rar index range */ | ||
2772 | if (rar >= rar_entries) { | ||
2773 | hw_dbg(hw, "RAR index %d is out of range.\n", rar); | ||
2774 | return IXGBE_ERR_INVALID_ARGUMENT; | ||
2775 | } | ||
2776 | |||
2777 | mpsar_lo = IXGBE_READ_REG(hw, IXGBE_MPSAR_LO(rar)); | ||
2778 | mpsar_hi = IXGBE_READ_REG(hw, IXGBE_MPSAR_HI(rar)); | ||
2779 | |||
2780 | if (!mpsar_lo && !mpsar_hi) | ||
2781 | goto done; | ||
2782 | |||
2783 | if (vmdq == IXGBE_CLEAR_VMDQ_ALL) { | ||
2784 | if (mpsar_lo) { | ||
2785 | IXGBE_WRITE_REG(hw, IXGBE_MPSAR_LO(rar), 0); | ||
2786 | mpsar_lo = 0; | ||
2787 | } | ||
2788 | if (mpsar_hi) { | ||
2789 | IXGBE_WRITE_REG(hw, IXGBE_MPSAR_HI(rar), 0); | ||
2790 | mpsar_hi = 0; | ||
2791 | } | ||
2792 | } else if (vmdq < 32) { | ||
2793 | mpsar_lo &= ~(1 << vmdq); | ||
2794 | IXGBE_WRITE_REG(hw, IXGBE_MPSAR_LO(rar), mpsar_lo); | ||
2795 | } else { | ||
2796 | mpsar_hi &= ~(1 << (vmdq - 32)); | ||
2797 | IXGBE_WRITE_REG(hw, IXGBE_MPSAR_HI(rar), mpsar_hi); | ||
2798 | } | ||
2799 | |||
2800 | /* was that the last pool using this rar? */ | ||
2801 | if (mpsar_lo == 0 && mpsar_hi == 0 && rar != 0) | ||
2802 | hw->mac.ops.clear_rar(hw, rar); | ||
2803 | done: | ||
2804 | return 0; | ||
2805 | } | ||
2806 | |||
2807 | /** | ||
2808 | * ixgbe_set_vmdq_generic - Associate a VMDq pool index with a rx address | ||
2809 | * @hw: pointer to hardware struct | ||
2810 | * @rar: receive address register index to associate with a VMDq index | ||
2811 | * @vmdq: VMDq pool index | ||
2812 | **/ | ||
2813 | s32 ixgbe_set_vmdq_generic(struct ixgbe_hw *hw, u32 rar, u32 vmdq) | ||
2814 | { | ||
2815 | u32 mpsar; | ||
2816 | u32 rar_entries = hw->mac.num_rar_entries; | ||
2817 | |||
2818 | /* Make sure we are using a valid rar index range */ | ||
2819 | if (rar >= rar_entries) { | ||
2820 | hw_dbg(hw, "RAR index %d is out of range.\n", rar); | ||
2821 | return IXGBE_ERR_INVALID_ARGUMENT; | ||
2822 | } | ||
2823 | |||
2824 | if (vmdq < 32) { | ||
2825 | mpsar = IXGBE_READ_REG(hw, IXGBE_MPSAR_LO(rar)); | ||
2826 | mpsar |= 1 << vmdq; | ||
2827 | IXGBE_WRITE_REG(hw, IXGBE_MPSAR_LO(rar), mpsar); | ||
2828 | } else { | ||
2829 | mpsar = IXGBE_READ_REG(hw, IXGBE_MPSAR_HI(rar)); | ||
2830 | mpsar |= 1 << (vmdq - 32); | ||
2831 | IXGBE_WRITE_REG(hw, IXGBE_MPSAR_HI(rar), mpsar); | ||
2832 | } | ||
2833 | return 0; | ||
2834 | } | ||
2835 | |||
2836 | /** | ||
2837 | * ixgbe_init_uta_tables_generic - Initialize the Unicast Table Array | ||
2838 | * @hw: pointer to hardware structure | ||
2839 | **/ | ||
2840 | s32 ixgbe_init_uta_tables_generic(struct ixgbe_hw *hw) | ||
2841 | { | ||
2842 | int i; | ||
2843 | |||
2844 | for (i = 0; i < 128; i++) | ||
2845 | IXGBE_WRITE_REG(hw, IXGBE_UTA(i), 0); | ||
2846 | |||
2847 | return 0; | ||
2848 | } | ||
2849 | |||
2850 | /** | ||
2851 | * ixgbe_find_vlvf_slot - find the vlanid or the first empty slot | ||
2852 | * @hw: pointer to hardware structure | ||
2853 | * @vlan: VLAN id to write to VLAN filter | ||
2854 | * | ||
2855 | * return the VLVF index where this VLAN id should be placed | ||
2856 | * | ||
2857 | **/ | ||
2858 | static s32 ixgbe_find_vlvf_slot(struct ixgbe_hw *hw, u32 vlan) | ||
2859 | { | ||
2860 | u32 bits = 0; | ||
2861 | u32 first_empty_slot = 0; | ||
2862 | s32 regindex; | ||
2863 | |||
2864 | /* short cut the special case */ | ||
2865 | if (vlan == 0) | ||
2866 | return 0; | ||
2867 | |||
2868 | /* | ||
2869 | * Search for the vlan id in the VLVF entries. Save off the first empty | ||
2870 | * slot found along the way | ||
2871 | */ | ||
2872 | for (regindex = 1; regindex < IXGBE_VLVF_ENTRIES; regindex++) { | ||
2873 | bits = IXGBE_READ_REG(hw, IXGBE_VLVF(regindex)); | ||
2874 | if (!bits && !(first_empty_slot)) | ||
2875 | first_empty_slot = regindex; | ||
2876 | else if ((bits & 0x0FFF) == vlan) | ||
2877 | break; | ||
2878 | } | ||
2879 | |||
2880 | /* | ||
2881 | * If regindex is less than IXGBE_VLVF_ENTRIES, then we found the vlan | ||
2882 | * in the VLVF. Else use the first empty VLVF register for this | ||
2883 | * vlan id. | ||
2884 | */ | ||
2885 | if (regindex >= IXGBE_VLVF_ENTRIES) { | ||
2886 | if (first_empty_slot) | ||
2887 | regindex = first_empty_slot; | ||
2888 | else { | ||
2889 | hw_dbg(hw, "No space in VLVF.\n"); | ||
2890 | regindex = IXGBE_ERR_NO_SPACE; | ||
2891 | } | ||
2892 | } | ||
2893 | |||
2894 | return regindex; | ||
2895 | } | ||
2896 | |||
2897 | /** | ||
2898 | * ixgbe_set_vfta_generic - Set VLAN filter table | ||
2899 | * @hw: pointer to hardware structure | ||
2900 | * @vlan: VLAN id to write to VLAN filter | ||
2901 | * @vind: VMDq output index that maps queue to VLAN id in VFVFB | ||
2902 | * @vlan_on: boolean flag to turn on/off VLAN in VFVF | ||
2903 | * | ||
2904 | * Turn on/off specified VLAN in the VLAN filter table. | ||
2905 | **/ | ||
2906 | s32 ixgbe_set_vfta_generic(struct ixgbe_hw *hw, u32 vlan, u32 vind, | ||
2907 | bool vlan_on) | ||
2908 | { | ||
2909 | s32 regindex; | ||
2910 | u32 bitindex; | ||
2911 | u32 vfta; | ||
2912 | u32 bits; | ||
2913 | u32 vt; | ||
2914 | u32 targetbit; | ||
2915 | bool vfta_changed = false; | ||
2916 | |||
2917 | if (vlan > 4095) | ||
2918 | return IXGBE_ERR_PARAM; | ||
2919 | |||
2920 | /* | ||
2921 | * this is a 2 part operation - first the VFTA, then the | ||
2922 | * VLVF and VLVFB if VT Mode is set | ||
2923 | * We don't write the VFTA until we know the VLVF part succeeded. | ||
2924 | */ | ||
2925 | |||
2926 | /* Part 1 | ||
2927 | * The VFTA is a bitstring made up of 128 32-bit registers | ||
2928 | * that enable the particular VLAN id, much like the MTA: | ||
2929 | * bits[11-5]: which register | ||
2930 | * bits[4-0]: which bit in the register | ||
2931 | */ | ||
2932 | regindex = (vlan >> 5) & 0x7F; | ||
2933 | bitindex = vlan & 0x1F; | ||
2934 | targetbit = (1 << bitindex); | ||
2935 | vfta = IXGBE_READ_REG(hw, IXGBE_VFTA(regindex)); | ||
2936 | |||
2937 | if (vlan_on) { | ||
2938 | if (!(vfta & targetbit)) { | ||
2939 | vfta |= targetbit; | ||
2940 | vfta_changed = true; | ||
2941 | } | ||
2942 | } else { | ||
2943 | if ((vfta & targetbit)) { | ||
2944 | vfta &= ~targetbit; | ||
2945 | vfta_changed = true; | ||
2946 | } | ||
2947 | } | ||
2948 | |||
2949 | /* Part 2 | ||
2950 | * If VT Mode is set | ||
2951 | * Either vlan_on | ||
2952 | * make sure the vlan is in VLVF | ||
2953 | * set the vind bit in the matching VLVFB | ||
2954 | * Or !vlan_on | ||
2955 | * clear the pool bit and possibly the vind | ||
2956 | */ | ||
2957 | vt = IXGBE_READ_REG(hw, IXGBE_VT_CTL); | ||
2958 | if (vt & IXGBE_VT_CTL_VT_ENABLE) { | ||
2959 | s32 vlvf_index; | ||
2960 | |||
2961 | vlvf_index = ixgbe_find_vlvf_slot(hw, vlan); | ||
2962 | if (vlvf_index < 0) | ||
2963 | return vlvf_index; | ||
2964 | |||
2965 | if (vlan_on) { | ||
2966 | /* set the pool bit */ | ||
2967 | if (vind < 32) { | ||
2968 | bits = IXGBE_READ_REG(hw, | ||
2969 | IXGBE_VLVFB(vlvf_index*2)); | ||
2970 | bits |= (1 << vind); | ||
2971 | IXGBE_WRITE_REG(hw, | ||
2972 | IXGBE_VLVFB(vlvf_index*2), | ||
2973 | bits); | ||
2974 | } else { | ||
2975 | bits = IXGBE_READ_REG(hw, | ||
2976 | IXGBE_VLVFB((vlvf_index*2)+1)); | ||
2977 | bits |= (1 << (vind-32)); | ||
2978 | IXGBE_WRITE_REG(hw, | ||
2979 | IXGBE_VLVFB((vlvf_index*2)+1), | ||
2980 | bits); | ||
2981 | } | ||
2982 | } else { | ||
2983 | /* clear the pool bit */ | ||
2984 | if (vind < 32) { | ||
2985 | bits = IXGBE_READ_REG(hw, | ||
2986 | IXGBE_VLVFB(vlvf_index*2)); | ||
2987 | bits &= ~(1 << vind); | ||
2988 | IXGBE_WRITE_REG(hw, | ||
2989 | IXGBE_VLVFB(vlvf_index*2), | ||
2990 | bits); | ||
2991 | bits |= IXGBE_READ_REG(hw, | ||
2992 | IXGBE_VLVFB((vlvf_index*2)+1)); | ||
2993 | } else { | ||
2994 | bits = IXGBE_READ_REG(hw, | ||
2995 | IXGBE_VLVFB((vlvf_index*2)+1)); | ||
2996 | bits &= ~(1 << (vind-32)); | ||
2997 | IXGBE_WRITE_REG(hw, | ||
2998 | IXGBE_VLVFB((vlvf_index*2)+1), | ||
2999 | bits); | ||
3000 | bits |= IXGBE_READ_REG(hw, | ||
3001 | IXGBE_VLVFB(vlvf_index*2)); | ||
3002 | } | ||
3003 | } | ||
3004 | |||
3005 | /* | ||
3006 | * If there are still bits set in the VLVFB registers | ||
3007 | * for the VLAN ID indicated we need to see if the | ||
3008 | * caller is requesting that we clear the VFTA entry bit. | ||
3009 | * If the caller has requested that we clear the VFTA | ||
3010 | * entry bit but there are still pools/VFs using this VLAN | ||
3011 | * ID entry then ignore the request. We're not worried | ||
3012 | * about the case where we're turning the VFTA VLAN ID | ||
3013 | * entry bit on, only when requested to turn it off as | ||
3014 | * there may be multiple pools and/or VFs using the | ||
3015 | * VLAN ID entry. In that case we cannot clear the | ||
3016 | * VFTA bit until all pools/VFs using that VLAN ID have also | ||
3017 | * been cleared. This will be indicated by "bits" being | ||
3018 | * zero. | ||
3019 | */ | ||
3020 | if (bits) { | ||
3021 | IXGBE_WRITE_REG(hw, IXGBE_VLVF(vlvf_index), | ||
3022 | (IXGBE_VLVF_VIEN | vlan)); | ||
3023 | if (!vlan_on) { | ||
3024 | /* someone wants to clear the vfta entry | ||
3025 | * but some pools/VFs are still using it. | ||
3026 | * Ignore it. */ | ||
3027 | vfta_changed = false; | ||
3028 | } | ||
3029 | } | ||
3030 | else | ||
3031 | IXGBE_WRITE_REG(hw, IXGBE_VLVF(vlvf_index), 0); | ||
3032 | } | ||
3033 | |||
3034 | if (vfta_changed) | ||
3035 | IXGBE_WRITE_REG(hw, IXGBE_VFTA(regindex), vfta); | ||
3036 | |||
3037 | return 0; | ||
3038 | } | ||
3039 | |||
3040 | /** | ||
3041 | * ixgbe_clear_vfta_generic - Clear VLAN filter table | ||
3042 | * @hw: pointer to hardware structure | ||
3043 | * | ||
3044 | * Clears the VLAN filer table, and the VMDq index associated with the filter | ||
3045 | **/ | ||
3046 | s32 ixgbe_clear_vfta_generic(struct ixgbe_hw *hw) | ||
3047 | { | ||
3048 | u32 offset; | ||
3049 | |||
3050 | for (offset = 0; offset < hw->mac.vft_size; offset++) | ||
3051 | IXGBE_WRITE_REG(hw, IXGBE_VFTA(offset), 0); | ||
3052 | |||
3053 | for (offset = 0; offset < IXGBE_VLVF_ENTRIES; offset++) { | ||
3054 | IXGBE_WRITE_REG(hw, IXGBE_VLVF(offset), 0); | ||
3055 | IXGBE_WRITE_REG(hw, IXGBE_VLVFB(offset*2), 0); | ||
3056 | IXGBE_WRITE_REG(hw, IXGBE_VLVFB((offset*2)+1), 0); | ||
3057 | } | ||
3058 | |||
3059 | return 0; | ||
3060 | } | ||
3061 | |||
3062 | /** | ||
3063 | * ixgbe_check_mac_link_generic - Determine link and speed status | ||
3064 | * @hw: pointer to hardware structure | ||
3065 | * @speed: pointer to link speed | ||
3066 | * @link_up: true when link is up | ||
3067 | * @link_up_wait_to_complete: bool used to wait for link up or not | ||
3068 | * | ||
3069 | * Reads the links register to determine if link is up and the current speed | ||
3070 | **/ | ||
3071 | s32 ixgbe_check_mac_link_generic(struct ixgbe_hw *hw, ixgbe_link_speed *speed, | ||
3072 | bool *link_up, bool link_up_wait_to_complete) | ||
3073 | { | ||
3074 | u32 links_reg, links_orig; | ||
3075 | u32 i; | ||
3076 | |||
3077 | /* clear the old state */ | ||
3078 | links_orig = IXGBE_READ_REG(hw, IXGBE_LINKS); | ||
3079 | |||
3080 | links_reg = IXGBE_READ_REG(hw, IXGBE_LINKS); | ||
3081 | |||
3082 | if (links_orig != links_reg) { | ||
3083 | hw_dbg(hw, "LINKS changed from %08X to %08X\n", | ||
3084 | links_orig, links_reg); | ||
3085 | } | ||
3086 | |||
3087 | if (link_up_wait_to_complete) { | ||
3088 | for (i = 0; i < IXGBE_LINK_UP_TIME; i++) { | ||
3089 | if (links_reg & IXGBE_LINKS_UP) { | ||
3090 | *link_up = true; | ||
3091 | break; | ||
3092 | } else { | ||
3093 | *link_up = false; | ||
3094 | } | ||
3095 | msleep(100); | ||
3096 | links_reg = IXGBE_READ_REG(hw, IXGBE_LINKS); | ||
3097 | } | ||
3098 | } else { | ||
3099 | if (links_reg & IXGBE_LINKS_UP) | ||
3100 | *link_up = true; | ||
3101 | else | ||
3102 | *link_up = false; | ||
3103 | } | ||
3104 | |||
3105 | if ((links_reg & IXGBE_LINKS_SPEED_82599) == | ||
3106 | IXGBE_LINKS_SPEED_10G_82599) | ||
3107 | *speed = IXGBE_LINK_SPEED_10GB_FULL; | ||
3108 | else if ((links_reg & IXGBE_LINKS_SPEED_82599) == | ||
3109 | IXGBE_LINKS_SPEED_1G_82599) | ||
3110 | *speed = IXGBE_LINK_SPEED_1GB_FULL; | ||
3111 | else if ((links_reg & IXGBE_LINKS_SPEED_82599) == | ||
3112 | IXGBE_LINKS_SPEED_100_82599) | ||
3113 | *speed = IXGBE_LINK_SPEED_100_FULL; | ||
3114 | else | ||
3115 | *speed = IXGBE_LINK_SPEED_UNKNOWN; | ||
3116 | |||
3117 | /* if link is down, zero out the current_mode */ | ||
3118 | if (*link_up == false) { | ||
3119 | hw->fc.current_mode = ixgbe_fc_none; | ||
3120 | hw->fc.fc_was_autonegged = false; | ||
3121 | } | ||
3122 | |||
3123 | return 0; | ||
3124 | } | ||
3125 | |||
3126 | /** | ||
3127 | * ixgbe_get_wwn_prefix_generic Get alternative WWNN/WWPN prefix from | ||
3128 | * the EEPROM | ||
3129 | * @hw: pointer to hardware structure | ||
3130 | * @wwnn_prefix: the alternative WWNN prefix | ||
3131 | * @wwpn_prefix: the alternative WWPN prefix | ||
3132 | * | ||
3133 | * This function will read the EEPROM from the alternative SAN MAC address | ||
3134 | * block to check the support for the alternative WWNN/WWPN prefix support. | ||
3135 | **/ | ||
3136 | s32 ixgbe_get_wwn_prefix_generic(struct ixgbe_hw *hw, u16 *wwnn_prefix, | ||
3137 | u16 *wwpn_prefix) | ||
3138 | { | ||
3139 | u16 offset, caps; | ||
3140 | u16 alt_san_mac_blk_offset; | ||
3141 | |||
3142 | /* clear output first */ | ||
3143 | *wwnn_prefix = 0xFFFF; | ||
3144 | *wwpn_prefix = 0xFFFF; | ||
3145 | |||
3146 | /* check if alternative SAN MAC is supported */ | ||
3147 | hw->eeprom.ops.read(hw, IXGBE_ALT_SAN_MAC_ADDR_BLK_PTR, | ||
3148 | &alt_san_mac_blk_offset); | ||
3149 | |||
3150 | if ((alt_san_mac_blk_offset == 0) || | ||
3151 | (alt_san_mac_blk_offset == 0xFFFF)) | ||
3152 | goto wwn_prefix_out; | ||
3153 | |||
3154 | /* check capability in alternative san mac address block */ | ||
3155 | offset = alt_san_mac_blk_offset + IXGBE_ALT_SAN_MAC_ADDR_CAPS_OFFSET; | ||
3156 | hw->eeprom.ops.read(hw, offset, &caps); | ||
3157 | if (!(caps & IXGBE_ALT_SAN_MAC_ADDR_CAPS_ALTWWN)) | ||
3158 | goto wwn_prefix_out; | ||
3159 | |||
3160 | /* get the corresponding prefix for WWNN/WWPN */ | ||
3161 | offset = alt_san_mac_blk_offset + IXGBE_ALT_SAN_MAC_ADDR_WWNN_OFFSET; | ||
3162 | hw->eeprom.ops.read(hw, offset, wwnn_prefix); | ||
3163 | |||
3164 | offset = alt_san_mac_blk_offset + IXGBE_ALT_SAN_MAC_ADDR_WWPN_OFFSET; | ||
3165 | hw->eeprom.ops.read(hw, offset, wwpn_prefix); | ||
3166 | |||
3167 | wwn_prefix_out: | ||
3168 | return 0; | ||
3169 | } | ||
3170 | |||
3171 | /** | ||
3172 | * ixgbe_device_supports_autoneg_fc - Check if phy supports autoneg flow | ||
3173 | * control | ||
3174 | * @hw: pointer to hardware structure | ||
3175 | * | ||
3176 | * There are several phys that do not support autoneg flow control. This | ||
3177 | * function check the device id to see if the associated phy supports | ||
3178 | * autoneg flow control. | ||
3179 | **/ | ||
3180 | static s32 ixgbe_device_supports_autoneg_fc(struct ixgbe_hw *hw) | ||
3181 | { | ||
3182 | |||
3183 | switch (hw->device_id) { | ||
3184 | case IXGBE_DEV_ID_X540T: | ||
3185 | return 0; | ||
3186 | case IXGBE_DEV_ID_82599_T3_LOM: | ||
3187 | return 0; | ||
3188 | default: | ||
3189 | return IXGBE_ERR_FC_NOT_SUPPORTED; | ||
3190 | } | ||
3191 | } | ||
3192 | |||
3193 | /** | ||
3194 | * ixgbe_set_mac_anti_spoofing - Enable/Disable MAC anti-spoofing | ||
3195 | * @hw: pointer to hardware structure | ||
3196 | * @enable: enable or disable switch for anti-spoofing | ||
3197 | * @pf: Physical Function pool - do not enable anti-spoofing for the PF | ||
3198 | * | ||
3199 | **/ | ||
3200 | void ixgbe_set_mac_anti_spoofing(struct ixgbe_hw *hw, bool enable, int pf) | ||
3201 | { | ||
3202 | int j; | ||
3203 | int pf_target_reg = pf >> 3; | ||
3204 | int pf_target_shift = pf % 8; | ||
3205 | u32 pfvfspoof = 0; | ||
3206 | |||
3207 | if (hw->mac.type == ixgbe_mac_82598EB) | ||
3208 | return; | ||
3209 | |||
3210 | if (enable) | ||
3211 | pfvfspoof = IXGBE_SPOOF_MACAS_MASK; | ||
3212 | |||
3213 | /* | ||
3214 | * PFVFSPOOF register array is size 8 with 8 bits assigned to | ||
3215 | * MAC anti-spoof enables in each register array element. | ||
3216 | */ | ||
3217 | for (j = 0; j < IXGBE_PFVFSPOOF_REG_COUNT; j++) | ||
3218 | IXGBE_WRITE_REG(hw, IXGBE_PFVFSPOOF(j), pfvfspoof); | ||
3219 | |||
3220 | /* If not enabling anti-spoofing then done */ | ||
3221 | if (!enable) | ||
3222 | return; | ||
3223 | |||
3224 | /* | ||
3225 | * The PF should be allowed to spoof so that it can support | ||
3226 | * emulation mode NICs. Reset the bit assigned to the PF | ||
3227 | */ | ||
3228 | pfvfspoof = IXGBE_READ_REG(hw, IXGBE_PFVFSPOOF(pf_target_reg)); | ||
3229 | pfvfspoof ^= (1 << pf_target_shift); | ||
3230 | IXGBE_WRITE_REG(hw, IXGBE_PFVFSPOOF(pf_target_reg), pfvfspoof); | ||
3231 | } | ||
3232 | |||
3233 | /** | ||
3234 | * ixgbe_set_vlan_anti_spoofing - Enable/Disable VLAN anti-spoofing | ||
3235 | * @hw: pointer to hardware structure | ||
3236 | * @enable: enable or disable switch for VLAN anti-spoofing | ||
3237 | * @pf: Virtual Function pool - VF Pool to set for VLAN anti-spoofing | ||
3238 | * | ||
3239 | **/ | ||
3240 | void ixgbe_set_vlan_anti_spoofing(struct ixgbe_hw *hw, bool enable, int vf) | ||
3241 | { | ||
3242 | int vf_target_reg = vf >> 3; | ||
3243 | int vf_target_shift = vf % 8 + IXGBE_SPOOF_VLANAS_SHIFT; | ||
3244 | u32 pfvfspoof; | ||
3245 | |||
3246 | if (hw->mac.type == ixgbe_mac_82598EB) | ||
3247 | return; | ||
3248 | |||
3249 | pfvfspoof = IXGBE_READ_REG(hw, IXGBE_PFVFSPOOF(vf_target_reg)); | ||
3250 | if (enable) | ||
3251 | pfvfspoof |= (1 << vf_target_shift); | ||
3252 | else | ||
3253 | pfvfspoof &= ~(1 << vf_target_shift); | ||
3254 | IXGBE_WRITE_REG(hw, IXGBE_PFVFSPOOF(vf_target_reg), pfvfspoof); | ||
3255 | } | ||
3256 | |||
3257 | /** | ||
3258 | * ixgbe_get_device_caps_generic - Get additional device capabilities | ||
3259 | * @hw: pointer to hardware structure | ||
3260 | * @device_caps: the EEPROM word with the extra device capabilities | ||
3261 | * | ||
3262 | * This function will read the EEPROM location for the device capabilities, | ||
3263 | * and return the word through device_caps. | ||
3264 | **/ | ||
3265 | s32 ixgbe_get_device_caps_generic(struct ixgbe_hw *hw, u16 *device_caps) | ||
3266 | { | ||
3267 | hw->eeprom.ops.read(hw, IXGBE_DEVICE_CAPS, device_caps); | ||
3268 | |||
3269 | return 0; | ||
3270 | } | ||
3271 | |||
3272 | /** | ||
3273 | * ixgbe_set_rxpba_generic - Initialize RX packet buffer | ||
3274 | * @hw: pointer to hardware structure | ||
3275 | * @num_pb: number of packet buffers to allocate | ||
3276 | * @headroom: reserve n KB of headroom | ||
3277 | * @strategy: packet buffer allocation strategy | ||
3278 | **/ | ||
3279 | void ixgbe_set_rxpba_generic(struct ixgbe_hw *hw, | ||
3280 | int num_pb, | ||
3281 | u32 headroom, | ||
3282 | int strategy) | ||
3283 | { | ||
3284 | u32 pbsize = hw->mac.rx_pb_size; | ||
3285 | int i = 0; | ||
3286 | u32 rxpktsize, txpktsize, txpbthresh; | ||
3287 | |||
3288 | /* Reserve headroom */ | ||
3289 | pbsize -= headroom; | ||
3290 | |||
3291 | if (!num_pb) | ||
3292 | num_pb = 1; | ||
3293 | |||
3294 | /* Divide remaining packet buffer space amongst the number | ||
3295 | * of packet buffers requested using supplied strategy. | ||
3296 | */ | ||
3297 | switch (strategy) { | ||
3298 | case (PBA_STRATEGY_WEIGHTED): | ||
3299 | /* pba_80_48 strategy weight first half of packet buffer with | ||
3300 | * 5/8 of the packet buffer space. | ||
3301 | */ | ||
3302 | rxpktsize = ((pbsize * 5 * 2) / (num_pb * 8)); | ||
3303 | pbsize -= rxpktsize * (num_pb / 2); | ||
3304 | rxpktsize <<= IXGBE_RXPBSIZE_SHIFT; | ||
3305 | for (; i < (num_pb / 2); i++) | ||
3306 | IXGBE_WRITE_REG(hw, IXGBE_RXPBSIZE(i), rxpktsize); | ||
3307 | /* Fall through to configure remaining packet buffers */ | ||
3308 | case (PBA_STRATEGY_EQUAL): | ||
3309 | /* Divide the remaining Rx packet buffer evenly among the TCs */ | ||
3310 | rxpktsize = (pbsize / (num_pb - i)) << IXGBE_RXPBSIZE_SHIFT; | ||
3311 | for (; i < num_pb; i++) | ||
3312 | IXGBE_WRITE_REG(hw, IXGBE_RXPBSIZE(i), rxpktsize); | ||
3313 | break; | ||
3314 | default: | ||
3315 | break; | ||
3316 | } | ||
3317 | |||
3318 | /* | ||
3319 | * Setup Tx packet buffer and threshold equally for all TCs | ||
3320 | * TXPBTHRESH register is set in K so divide by 1024 and subtract | ||
3321 | * 10 since the largest packet we support is just over 9K. | ||
3322 | */ | ||
3323 | txpktsize = IXGBE_TXPBSIZE_MAX / num_pb; | ||
3324 | txpbthresh = (txpktsize / 1024) - IXGBE_TXPKT_SIZE_MAX; | ||
3325 | for (i = 0; i < num_pb; i++) { | ||
3326 | IXGBE_WRITE_REG(hw, IXGBE_TXPBSIZE(i), txpktsize); | ||
3327 | IXGBE_WRITE_REG(hw, IXGBE_TXPBTHRESH(i), txpbthresh); | ||
3328 | } | ||
3329 | |||
3330 | /* Clear unused TCs, if any, to zero buffer size*/ | ||
3331 | for (; i < IXGBE_MAX_PB; i++) { | ||
3332 | IXGBE_WRITE_REG(hw, IXGBE_RXPBSIZE(i), 0); | ||
3333 | IXGBE_WRITE_REG(hw, IXGBE_TXPBSIZE(i), 0); | ||
3334 | IXGBE_WRITE_REG(hw, IXGBE_TXPBTHRESH(i), 0); | ||
3335 | } | ||
3336 | } | ||
3337 | |||
3338 | /** | ||
3339 | * ixgbe_calculate_checksum - Calculate checksum for buffer | ||
3340 | * @buffer: pointer to EEPROM | ||
3341 | * @length: size of EEPROM to calculate a checksum for | ||
3342 | * Calculates the checksum for some buffer on a specified length. The | ||
3343 | * checksum calculated is returned. | ||
3344 | **/ | ||
3345 | static u8 ixgbe_calculate_checksum(u8 *buffer, u32 length) | ||
3346 | { | ||
3347 | u32 i; | ||
3348 | u8 sum = 0; | ||
3349 | |||
3350 | if (!buffer) | ||
3351 | return 0; | ||
3352 | |||
3353 | for (i = 0; i < length; i++) | ||
3354 | sum += buffer[i]; | ||
3355 | |||
3356 | return (u8) (0 - sum); | ||
3357 | } | ||
3358 | |||
3359 | /** | ||
3360 | * ixgbe_host_interface_command - Issue command to manageability block | ||
3361 | * @hw: pointer to the HW structure | ||
3362 | * @buffer: contains the command to write and where the return status will | ||
3363 | * be placed | ||
3364 | * @lenght: lenght of buffer, must be multiple of 4 bytes | ||
3365 | * | ||
3366 | * Communicates with the manageability block. On success return 0 | ||
3367 | * else return IXGBE_ERR_HOST_INTERFACE_COMMAND. | ||
3368 | **/ | ||
3369 | static s32 ixgbe_host_interface_command(struct ixgbe_hw *hw, u8 *buffer, | ||
3370 | u32 length) | ||
3371 | { | ||
3372 | u32 hicr, i; | ||
3373 | u32 hdr_size = sizeof(struct ixgbe_hic_hdr); | ||
3374 | u8 buf_len, dword_len; | ||
3375 | |||
3376 | s32 ret_val = 0; | ||
3377 | |||
3378 | if (length == 0 || length & 0x3 || | ||
3379 | length > IXGBE_HI_MAX_BLOCK_BYTE_LENGTH) { | ||
3380 | hw_dbg(hw, "Buffer length failure.\n"); | ||
3381 | ret_val = IXGBE_ERR_HOST_INTERFACE_COMMAND; | ||
3382 | goto out; | ||
3383 | } | ||
3384 | |||
3385 | /* Check that the host interface is enabled. */ | ||
3386 | hicr = IXGBE_READ_REG(hw, IXGBE_HICR); | ||
3387 | if ((hicr & IXGBE_HICR_EN) == 0) { | ||
3388 | hw_dbg(hw, "IXGBE_HOST_EN bit disabled.\n"); | ||
3389 | ret_val = IXGBE_ERR_HOST_INTERFACE_COMMAND; | ||
3390 | goto out; | ||
3391 | } | ||
3392 | |||
3393 | /* Calculate length in DWORDs */ | ||
3394 | dword_len = length >> 2; | ||
3395 | |||
3396 | /* | ||
3397 | * The device driver writes the relevant command block | ||
3398 | * into the ram area. | ||
3399 | */ | ||
3400 | for (i = 0; i < dword_len; i++) | ||
3401 | IXGBE_WRITE_REG_ARRAY(hw, IXGBE_FLEX_MNG, | ||
3402 | i, *((u32 *)buffer + i)); | ||
3403 | |||
3404 | /* Setting this bit tells the ARC that a new command is pending. */ | ||
3405 | IXGBE_WRITE_REG(hw, IXGBE_HICR, hicr | IXGBE_HICR_C); | ||
3406 | |||
3407 | for (i = 0; i < IXGBE_HI_COMMAND_TIMEOUT; i++) { | ||
3408 | hicr = IXGBE_READ_REG(hw, IXGBE_HICR); | ||
3409 | if (!(hicr & IXGBE_HICR_C)) | ||
3410 | break; | ||
3411 | usleep_range(1000, 2000); | ||
3412 | } | ||
3413 | |||
3414 | /* Check command successful completion. */ | ||
3415 | if (i == IXGBE_HI_COMMAND_TIMEOUT || | ||
3416 | (!(IXGBE_READ_REG(hw, IXGBE_HICR) & IXGBE_HICR_SV))) { | ||
3417 | hw_dbg(hw, "Command has failed with no status valid.\n"); | ||
3418 | ret_val = IXGBE_ERR_HOST_INTERFACE_COMMAND; | ||
3419 | goto out; | ||
3420 | } | ||
3421 | |||
3422 | /* Calculate length in DWORDs */ | ||
3423 | dword_len = hdr_size >> 2; | ||
3424 | |||
3425 | /* first pull in the header so we know the buffer length */ | ||
3426 | for (i = 0; i < dword_len; i++) | ||
3427 | *((u32 *)buffer + i) = | ||
3428 | IXGBE_READ_REG_ARRAY(hw, IXGBE_FLEX_MNG, i); | ||
3429 | |||
3430 | /* If there is any thing in data position pull it in */ | ||
3431 | buf_len = ((struct ixgbe_hic_hdr *)buffer)->buf_len; | ||
3432 | if (buf_len == 0) | ||
3433 | goto out; | ||
3434 | |||
3435 | if (length < (buf_len + hdr_size)) { | ||
3436 | hw_dbg(hw, "Buffer not large enough for reply message.\n"); | ||
3437 | ret_val = IXGBE_ERR_HOST_INTERFACE_COMMAND; | ||
3438 | goto out; | ||
3439 | } | ||
3440 | |||
3441 | /* Calculate length in DWORDs, add one for odd lengths */ | ||
3442 | dword_len = (buf_len + 1) >> 2; | ||
3443 | |||
3444 | /* Pull in the rest of the buffer (i is where we left off)*/ | ||
3445 | for (; i < buf_len; i++) | ||
3446 | *((u32 *)buffer + i) = | ||
3447 | IXGBE_READ_REG_ARRAY(hw, IXGBE_FLEX_MNG, i); | ||
3448 | |||
3449 | out: | ||
3450 | return ret_val; | ||
3451 | } | ||
3452 | |||
3453 | /** | ||
3454 | * ixgbe_set_fw_drv_ver_generic - Sends driver version to firmware | ||
3455 | * @hw: pointer to the HW structure | ||
3456 | * @maj: driver version major number | ||
3457 | * @min: driver version minor number | ||
3458 | * @build: driver version build number | ||
3459 | * @sub: driver version sub build number | ||
3460 | * | ||
3461 | * Sends driver version number to firmware through the manageability | ||
3462 | * block. On success return 0 | ||
3463 | * else returns IXGBE_ERR_SWFW_SYNC when encountering an error acquiring | ||
3464 | * semaphore or IXGBE_ERR_HOST_INTERFACE_COMMAND when command fails. | ||
3465 | **/ | ||
3466 | s32 ixgbe_set_fw_drv_ver_generic(struct ixgbe_hw *hw, u8 maj, u8 min, | ||
3467 | u8 build, u8 sub) | ||
3468 | { | ||
3469 | struct ixgbe_hic_drv_info fw_cmd; | ||
3470 | int i; | ||
3471 | s32 ret_val = 0; | ||
3472 | |||
3473 | if (hw->mac.ops.acquire_swfw_sync(hw, IXGBE_GSSR_SW_MNG_SM) != 0) { | ||
3474 | ret_val = IXGBE_ERR_SWFW_SYNC; | ||
3475 | goto out; | ||
3476 | } | ||
3477 | |||
3478 | fw_cmd.hdr.cmd = FW_CEM_CMD_DRIVER_INFO; | ||
3479 | fw_cmd.hdr.buf_len = FW_CEM_CMD_DRIVER_INFO_LEN; | ||
3480 | fw_cmd.hdr.cmd_or_resp.cmd_resv = FW_CEM_CMD_RESERVED; | ||
3481 | fw_cmd.port_num = (u8)hw->bus.func; | ||
3482 | fw_cmd.ver_maj = maj; | ||
3483 | fw_cmd.ver_min = min; | ||
3484 | fw_cmd.ver_build = build; | ||
3485 | fw_cmd.ver_sub = sub; | ||
3486 | fw_cmd.hdr.checksum = 0; | ||
3487 | fw_cmd.hdr.checksum = ixgbe_calculate_checksum((u8 *)&fw_cmd, | ||
3488 | (FW_CEM_HDR_LEN + fw_cmd.hdr.buf_len)); | ||
3489 | fw_cmd.pad = 0; | ||
3490 | fw_cmd.pad2 = 0; | ||
3491 | |||
3492 | for (i = 0; i <= FW_CEM_MAX_RETRIES; i++) { | ||
3493 | ret_val = ixgbe_host_interface_command(hw, (u8 *)&fw_cmd, | ||
3494 | sizeof(fw_cmd)); | ||
3495 | if (ret_val != 0) | ||
3496 | continue; | ||
3497 | |||
3498 | if (fw_cmd.hdr.cmd_or_resp.ret_status == | ||
3499 | FW_CEM_RESP_STATUS_SUCCESS) | ||
3500 | ret_val = 0; | ||
3501 | else | ||
3502 | ret_val = IXGBE_ERR_HOST_INTERFACE_COMMAND; | ||
3503 | |||
3504 | break; | ||
3505 | } | ||
3506 | |||
3507 | hw->mac.ops.release_swfw_sync(hw, IXGBE_GSSR_SW_MNG_SM); | ||
3508 | out: | ||
3509 | return ret_val; | ||
3510 | } | ||
diff --git a/drivers/net/ixgbe/ixgbe_common.h b/drivers/net/ixgbe/ixgbe_common.h new file mode 100644 index 00000000000..f24fd64a4c4 --- /dev/null +++ b/drivers/net/ixgbe/ixgbe_common.h | |||
@@ -0,0 +1,145 @@ | |||
1 | /******************************************************************************* | ||
2 | |||
3 | Intel 10 Gigabit PCI Express Linux driver | ||
4 | Copyright(c) 1999 - 2011 Intel Corporation. | ||
5 | |||
6 | This program is free software; you can redistribute it and/or modify it | ||
7 | under the terms and conditions of the GNU General Public License, | ||
8 | version 2, as published by the Free Software Foundation. | ||
9 | |||
10 | This program is distributed in the hope it will be useful, but WITHOUT | ||
11 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
12 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
13 | more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License along with | ||
16 | this program; if not, write to the Free Software Foundation, Inc., | ||
17 | 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. | ||
18 | |||
19 | The full GNU General Public License is included in this distribution in | ||
20 | the file called "COPYING". | ||
21 | |||
22 | Contact Information: | ||
23 | e1000-devel Mailing List <e1000-devel@lists.sourceforge.net> | ||
24 | Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 | ||
25 | |||
26 | *******************************************************************************/ | ||
27 | |||
28 | #ifndef _IXGBE_COMMON_H_ | ||
29 | #define _IXGBE_COMMON_H_ | ||
30 | |||
31 | #include "ixgbe_type.h" | ||
32 | #include "ixgbe.h" | ||
33 | |||
34 | u32 ixgbe_get_pcie_msix_count_generic(struct ixgbe_hw *hw); | ||
35 | s32 ixgbe_init_ops_generic(struct ixgbe_hw *hw); | ||
36 | s32 ixgbe_init_hw_generic(struct ixgbe_hw *hw); | ||
37 | s32 ixgbe_start_hw_generic(struct ixgbe_hw *hw); | ||
38 | s32 ixgbe_start_hw_gen2(struct ixgbe_hw *hw); | ||
39 | s32 ixgbe_clear_hw_cntrs_generic(struct ixgbe_hw *hw); | ||
40 | s32 ixgbe_read_pba_string_generic(struct ixgbe_hw *hw, u8 *pba_num, | ||
41 | u32 pba_num_size); | ||
42 | s32 ixgbe_get_mac_addr_generic(struct ixgbe_hw *hw, u8 *mac_addr); | ||
43 | s32 ixgbe_get_bus_info_generic(struct ixgbe_hw *hw); | ||
44 | void ixgbe_set_lan_id_multi_port_pcie(struct ixgbe_hw *hw); | ||
45 | s32 ixgbe_stop_adapter_generic(struct ixgbe_hw *hw); | ||
46 | |||
47 | s32 ixgbe_led_on_generic(struct ixgbe_hw *hw, u32 index); | ||
48 | s32 ixgbe_led_off_generic(struct ixgbe_hw *hw, u32 index); | ||
49 | |||
50 | s32 ixgbe_init_eeprom_params_generic(struct ixgbe_hw *hw); | ||
51 | s32 ixgbe_write_eeprom_generic(struct ixgbe_hw *hw, u16 offset, u16 data); | ||
52 | s32 ixgbe_write_eeprom_buffer_bit_bang_generic(struct ixgbe_hw *hw, u16 offset, | ||
53 | u16 words, u16 *data); | ||
54 | s32 ixgbe_read_eerd_generic(struct ixgbe_hw *hw, u16 offset, u16 *data); | ||
55 | s32 ixgbe_read_eerd_buffer_generic(struct ixgbe_hw *hw, u16 offset, | ||
56 | u16 words, u16 *data); | ||
57 | s32 ixgbe_write_eewr_generic(struct ixgbe_hw *hw, u16 offset, u16 data); | ||
58 | s32 ixgbe_write_eewr_buffer_generic(struct ixgbe_hw *hw, u16 offset, | ||
59 | u16 words, u16 *data); | ||
60 | s32 ixgbe_read_eeprom_bit_bang_generic(struct ixgbe_hw *hw, u16 offset, | ||
61 | u16 *data); | ||
62 | s32 ixgbe_read_eeprom_buffer_bit_bang_generic(struct ixgbe_hw *hw, u16 offset, | ||
63 | u16 words, u16 *data); | ||
64 | u16 ixgbe_calc_eeprom_checksum_generic(struct ixgbe_hw *hw); | ||
65 | s32 ixgbe_validate_eeprom_checksum_generic(struct ixgbe_hw *hw, | ||
66 | u16 *checksum_val); | ||
67 | s32 ixgbe_update_eeprom_checksum_generic(struct ixgbe_hw *hw); | ||
68 | |||
69 | s32 ixgbe_set_rar_generic(struct ixgbe_hw *hw, u32 index, u8 *addr, u32 vmdq, | ||
70 | u32 enable_addr); | ||
71 | s32 ixgbe_clear_rar_generic(struct ixgbe_hw *hw, u32 index); | ||
72 | s32 ixgbe_init_rx_addrs_generic(struct ixgbe_hw *hw); | ||
73 | s32 ixgbe_update_mc_addr_list_generic(struct ixgbe_hw *hw, | ||
74 | struct net_device *netdev); | ||
75 | s32 ixgbe_enable_mc_generic(struct ixgbe_hw *hw); | ||
76 | s32 ixgbe_disable_mc_generic(struct ixgbe_hw *hw); | ||
77 | s32 ixgbe_enable_rx_dma_generic(struct ixgbe_hw *hw, u32 regval); | ||
78 | s32 ixgbe_fc_enable_generic(struct ixgbe_hw *hw, s32 packtetbuf_num); | ||
79 | s32 ixgbe_fc_autoneg(struct ixgbe_hw *hw); | ||
80 | |||
81 | s32 ixgbe_validate_mac_addr(u8 *mac_addr); | ||
82 | s32 ixgbe_acquire_swfw_sync(struct ixgbe_hw *hw, u16 mask); | ||
83 | void ixgbe_release_swfw_sync(struct ixgbe_hw *hw, u16 mask); | ||
84 | s32 ixgbe_disable_pcie_master(struct ixgbe_hw *hw); | ||
85 | s32 ixgbe_get_san_mac_addr_generic(struct ixgbe_hw *hw, u8 *san_mac_addr); | ||
86 | s32 ixgbe_set_vmdq_generic(struct ixgbe_hw *hw, u32 rar, u32 vmdq); | ||
87 | s32 ixgbe_clear_vmdq_generic(struct ixgbe_hw *hw, u32 rar, u32 vmdq); | ||
88 | s32 ixgbe_init_uta_tables_generic(struct ixgbe_hw *hw); | ||
89 | s32 ixgbe_set_vfta_generic(struct ixgbe_hw *hw, u32 vlan, | ||
90 | u32 vind, bool vlan_on); | ||
91 | s32 ixgbe_clear_vfta_generic(struct ixgbe_hw *hw); | ||
92 | s32 ixgbe_check_mac_link_generic(struct ixgbe_hw *hw, | ||
93 | ixgbe_link_speed *speed, | ||
94 | bool *link_up, bool link_up_wait_to_complete); | ||
95 | s32 ixgbe_get_wwn_prefix_generic(struct ixgbe_hw *hw, u16 *wwnn_prefix, | ||
96 | u16 *wwpn_prefix); | ||
97 | s32 ixgbe_blink_led_start_generic(struct ixgbe_hw *hw, u32 index); | ||
98 | s32 ixgbe_blink_led_stop_generic(struct ixgbe_hw *hw, u32 index); | ||
99 | void ixgbe_set_mac_anti_spoofing(struct ixgbe_hw *hw, bool enable, int pf); | ||
100 | void ixgbe_set_vlan_anti_spoofing(struct ixgbe_hw *hw, bool enable, int vf); | ||
101 | s32 ixgbe_get_device_caps_generic(struct ixgbe_hw *hw, u16 *device_caps); | ||
102 | s32 ixgbe_set_fw_drv_ver_generic(struct ixgbe_hw *hw, u8 maj, u8 min, | ||
103 | u8 build, u8 ver); | ||
104 | |||
105 | void ixgbe_set_rxpba_generic(struct ixgbe_hw *hw, int num_pb, | ||
106 | u32 headroom, int strategy); | ||
107 | |||
108 | #define IXGBE_WRITE_REG(a, reg, value) writel((value), ((a)->hw_addr + (reg))) | ||
109 | |||
110 | #ifndef writeq | ||
111 | #define writeq(val, addr) writel((u32) (val), addr); \ | ||
112 | writel((u32) (val >> 32), (addr + 4)); | ||
113 | #endif | ||
114 | |||
115 | #define IXGBE_WRITE_REG64(a, reg, value) writeq((value), ((a)->hw_addr + (reg))) | ||
116 | |||
117 | #define IXGBE_READ_REG(a, reg) readl((a)->hw_addr + (reg)) | ||
118 | |||
119 | #define IXGBE_WRITE_REG_ARRAY(a, reg, offset, value) (\ | ||
120 | writel((value), ((a)->hw_addr + (reg) + ((offset) << 2)))) | ||
121 | |||
122 | #define IXGBE_READ_REG_ARRAY(a, reg, offset) (\ | ||
123 | readl((a)->hw_addr + (reg) + ((offset) << 2))) | ||
124 | |||
125 | #define IXGBE_WRITE_FLUSH(a) IXGBE_READ_REG(a, IXGBE_STATUS) | ||
126 | |||
127 | #define hw_dbg(hw, format, arg...) \ | ||
128 | netdev_dbg(((struct ixgbe_adapter *)(hw->back))->netdev, format, ##arg) | ||
129 | #define e_dev_info(format, arg...) \ | ||
130 | dev_info(&adapter->pdev->dev, format, ## arg) | ||
131 | #define e_dev_warn(format, arg...) \ | ||
132 | dev_warn(&adapter->pdev->dev, format, ## arg) | ||
133 | #define e_dev_err(format, arg...) \ | ||
134 | dev_err(&adapter->pdev->dev, format, ## arg) | ||
135 | #define e_dev_notice(format, arg...) \ | ||
136 | dev_notice(&adapter->pdev->dev, format, ## arg) | ||
137 | #define e_info(msglvl, format, arg...) \ | ||
138 | netif_info(adapter, msglvl, adapter->netdev, format, ## arg) | ||
139 | #define e_err(msglvl, format, arg...) \ | ||
140 | netif_err(adapter, msglvl, adapter->netdev, format, ## arg) | ||
141 | #define e_warn(msglvl, format, arg...) \ | ||
142 | netif_warn(adapter, msglvl, adapter->netdev, format, ## arg) | ||
143 | #define e_crit(msglvl, format, arg...) \ | ||
144 | netif_crit(adapter, msglvl, adapter->netdev, format, ## arg) | ||
145 | #endif /* IXGBE_COMMON */ | ||
diff --git a/drivers/net/ixgbe/ixgbe_dcb.c b/drivers/net/ixgbe/ixgbe_dcb.c new file mode 100644 index 00000000000..9d88c31487b --- /dev/null +++ b/drivers/net/ixgbe/ixgbe_dcb.c | |||
@@ -0,0 +1,320 @@ | |||
1 | /******************************************************************************* | ||
2 | |||
3 | Intel 10 Gigabit PCI Express Linux driver | ||
4 | Copyright(c) 1999 - 2011 Intel Corporation. | ||
5 | |||
6 | This program is free software; you can redistribute it and/or modify it | ||
7 | under the terms and conditions of the GNU General Public License, | ||
8 | version 2, as published by the Free Software Foundation. | ||
9 | |||
10 | This program is distributed in the hope it will be useful, but WITHOUT | ||
11 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
12 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
13 | more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License along with | ||
16 | this program; if not, write to the Free Software Foundation, Inc., | ||
17 | 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. | ||
18 | |||
19 | The full GNU General Public License is included in this distribution in | ||
20 | the file called "COPYING". | ||
21 | |||
22 | Contact Information: | ||
23 | Linux NICS <linux.nics@intel.com> | ||
24 | e1000-devel Mailing List <e1000-devel@lists.sourceforge.net> | ||
25 | Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 | ||
26 | |||
27 | *******************************************************************************/ | ||
28 | |||
29 | |||
30 | #include "ixgbe.h" | ||
31 | #include "ixgbe_type.h" | ||
32 | #include "ixgbe_dcb.h" | ||
33 | #include "ixgbe_dcb_82598.h" | ||
34 | #include "ixgbe_dcb_82599.h" | ||
35 | |||
36 | /** | ||
37 | * ixgbe_ieee_credits - This calculates the ieee traffic class | ||
38 | * credits from the configured bandwidth percentages. Credits | ||
39 | * are the smallest unit programmable into the underlying | ||
40 | * hardware. The IEEE 802.1Qaz specification do not use bandwidth | ||
41 | * groups so this is much simplified from the CEE case. | ||
42 | */ | ||
43 | s32 ixgbe_ieee_credits(__u8 *bw, __u16 *refill, __u16 *max, int max_frame) | ||
44 | { | ||
45 | int min_percent = 100; | ||
46 | int min_credit, multiplier; | ||
47 | int i; | ||
48 | |||
49 | min_credit = ((max_frame / 2) + DCB_CREDIT_QUANTUM - 1) / | ||
50 | DCB_CREDIT_QUANTUM; | ||
51 | |||
52 | for (i = 0; i < MAX_TRAFFIC_CLASS; i++) { | ||
53 | if (bw[i] < min_percent && bw[i]) | ||
54 | min_percent = bw[i]; | ||
55 | } | ||
56 | |||
57 | multiplier = (min_credit / min_percent) + 1; | ||
58 | |||
59 | /* Find out the hw credits for each TC */ | ||
60 | for (i = 0; i < MAX_TRAFFIC_CLASS; i++) { | ||
61 | int val = min(bw[i] * multiplier, MAX_CREDIT_REFILL); | ||
62 | |||
63 | if (val < min_credit) | ||
64 | val = min_credit; | ||
65 | refill[i] = val; | ||
66 | |||
67 | max[i] = bw[i] ? (bw[i] * MAX_CREDIT)/100 : min_credit; | ||
68 | } | ||
69 | return 0; | ||
70 | } | ||
71 | |||
72 | /** | ||
73 | * ixgbe_dcb_calculate_tc_credits - Calculates traffic class credits | ||
74 | * @ixgbe_dcb_config: Struct containing DCB settings. | ||
75 | * @direction: Configuring either Tx or Rx. | ||
76 | * | ||
77 | * This function calculates the credits allocated to each traffic class. | ||
78 | * It should be called only after the rules are checked by | ||
79 | * ixgbe_dcb_check_config(). | ||
80 | */ | ||
81 | s32 ixgbe_dcb_calculate_tc_credits(struct ixgbe_hw *hw, | ||
82 | struct ixgbe_dcb_config *dcb_config, | ||
83 | int max_frame, u8 direction) | ||
84 | { | ||
85 | struct tc_bw_alloc *p; | ||
86 | int min_credit; | ||
87 | int min_multiplier; | ||
88 | int min_percent = 100; | ||
89 | s32 ret_val = 0; | ||
90 | /* Initialization values default for Tx settings */ | ||
91 | u32 credit_refill = 0; | ||
92 | u32 credit_max = 0; | ||
93 | u16 link_percentage = 0; | ||
94 | u8 bw_percent = 0; | ||
95 | u8 i; | ||
96 | |||
97 | if (dcb_config == NULL) { | ||
98 | ret_val = DCB_ERR_CONFIG; | ||
99 | goto out; | ||
100 | } | ||
101 | |||
102 | min_credit = ((max_frame / 2) + DCB_CREDIT_QUANTUM - 1) / | ||
103 | DCB_CREDIT_QUANTUM; | ||
104 | |||
105 | /* Find smallest link percentage */ | ||
106 | for (i = 0; i < MAX_TRAFFIC_CLASS; i++) { | ||
107 | p = &dcb_config->tc_config[i].path[direction]; | ||
108 | bw_percent = dcb_config->bw_percentage[direction][p->bwg_id]; | ||
109 | link_percentage = p->bwg_percent; | ||
110 | |||
111 | link_percentage = (link_percentage * bw_percent) / 100; | ||
112 | |||
113 | if (link_percentage && link_percentage < min_percent) | ||
114 | min_percent = link_percentage; | ||
115 | } | ||
116 | |||
117 | /* | ||
118 | * The ratio between traffic classes will control the bandwidth | ||
119 | * percentages seen on the wire. To calculate this ratio we use | ||
120 | * a multiplier. It is required that the refill credits must be | ||
121 | * larger than the max frame size so here we find the smallest | ||
122 | * multiplier that will allow all bandwidth percentages to be | ||
123 | * greater than the max frame size. | ||
124 | */ | ||
125 | min_multiplier = (min_credit / min_percent) + 1; | ||
126 | |||
127 | /* Find out the link percentage for each TC first */ | ||
128 | for (i = 0; i < MAX_TRAFFIC_CLASS; i++) { | ||
129 | p = &dcb_config->tc_config[i].path[direction]; | ||
130 | bw_percent = dcb_config->bw_percentage[direction][p->bwg_id]; | ||
131 | |||
132 | link_percentage = p->bwg_percent; | ||
133 | /* Must be careful of integer division for very small nums */ | ||
134 | link_percentage = (link_percentage * bw_percent) / 100; | ||
135 | if (p->bwg_percent > 0 && link_percentage == 0) | ||
136 | link_percentage = 1; | ||
137 | |||
138 | /* Save link_percentage for reference */ | ||
139 | p->link_percent = (u8)link_percentage; | ||
140 | |||
141 | /* Calculate credit refill ratio using multiplier */ | ||
142 | credit_refill = min(link_percentage * min_multiplier, | ||
143 | MAX_CREDIT_REFILL); | ||
144 | p->data_credits_refill = (u16)credit_refill; | ||
145 | |||
146 | /* Calculate maximum credit for the TC */ | ||
147 | credit_max = (link_percentage * MAX_CREDIT) / 100; | ||
148 | |||
149 | /* | ||
150 | * Adjustment based on rule checking, if the percentage | ||
151 | * of a TC is too small, the maximum credit may not be | ||
152 | * enough to send out a jumbo frame in data plane arbitration. | ||
153 | */ | ||
154 | if (credit_max && (credit_max < min_credit)) | ||
155 | credit_max = min_credit; | ||
156 | |||
157 | if (direction == DCB_TX_CONFIG) { | ||
158 | /* | ||
159 | * Adjustment based on rule checking, if the | ||
160 | * percentage of a TC is too small, the maximum | ||
161 | * credit may not be enough to send out a TSO | ||
162 | * packet in descriptor plane arbitration. | ||
163 | */ | ||
164 | if ((hw->mac.type == ixgbe_mac_82598EB) && | ||
165 | credit_max && | ||
166 | (credit_max < MINIMUM_CREDIT_FOR_TSO)) | ||
167 | credit_max = MINIMUM_CREDIT_FOR_TSO; | ||
168 | |||
169 | dcb_config->tc_config[i].desc_credits_max = | ||
170 | (u16)credit_max; | ||
171 | } | ||
172 | |||
173 | p->data_credits_max = (u16)credit_max; | ||
174 | } | ||
175 | |||
176 | out: | ||
177 | return ret_val; | ||
178 | } | ||
179 | |||
180 | void ixgbe_dcb_unpack_pfc(struct ixgbe_dcb_config *cfg, u8 *pfc_en) | ||
181 | { | ||
182 | int i; | ||
183 | |||
184 | *pfc_en = 0; | ||
185 | for (i = 0; i < MAX_TRAFFIC_CLASS; i++) | ||
186 | *pfc_en |= (cfg->tc_config[i].dcb_pfc & 0xF) << i; | ||
187 | } | ||
188 | |||
189 | void ixgbe_dcb_unpack_refill(struct ixgbe_dcb_config *cfg, int direction, | ||
190 | u16 *refill) | ||
191 | { | ||
192 | struct tc_bw_alloc *p; | ||
193 | int i; | ||
194 | |||
195 | for (i = 0; i < MAX_TRAFFIC_CLASS; i++) { | ||
196 | p = &cfg->tc_config[i].path[direction]; | ||
197 | refill[i] = p->data_credits_refill; | ||
198 | } | ||
199 | } | ||
200 | |||
201 | void ixgbe_dcb_unpack_max(struct ixgbe_dcb_config *cfg, u16 *max) | ||
202 | { | ||
203 | int i; | ||
204 | |||
205 | for (i = 0; i < MAX_TRAFFIC_CLASS; i++) | ||
206 | max[i] = cfg->tc_config[i].desc_credits_max; | ||
207 | } | ||
208 | |||
209 | void ixgbe_dcb_unpack_bwgid(struct ixgbe_dcb_config *cfg, int direction, | ||
210 | u8 *bwgid) | ||
211 | { | ||
212 | struct tc_bw_alloc *p; | ||
213 | int i; | ||
214 | |||
215 | for (i = 0; i < MAX_TRAFFIC_CLASS; i++) { | ||
216 | p = &cfg->tc_config[i].path[direction]; | ||
217 | bwgid[i] = p->bwg_id; | ||
218 | } | ||
219 | } | ||
220 | |||
221 | void ixgbe_dcb_unpack_prio(struct ixgbe_dcb_config *cfg, int direction, | ||
222 | u8 *ptype) | ||
223 | { | ||
224 | struct tc_bw_alloc *p; | ||
225 | int i; | ||
226 | |||
227 | for (i = 0; i < MAX_TRAFFIC_CLASS; i++) { | ||
228 | p = &cfg->tc_config[i].path[direction]; | ||
229 | ptype[i] = p->prio_type; | ||
230 | } | ||
231 | } | ||
232 | |||
233 | /** | ||
234 | * ixgbe_dcb_hw_config - Config and enable DCB | ||
235 | * @hw: pointer to hardware structure | ||
236 | * @dcb_config: pointer to ixgbe_dcb_config structure | ||
237 | * | ||
238 | * Configure dcb settings and enable dcb mode. | ||
239 | */ | ||
240 | s32 ixgbe_dcb_hw_config(struct ixgbe_hw *hw, | ||
241 | struct ixgbe_dcb_config *dcb_config) | ||
242 | { | ||
243 | s32 ret = 0; | ||
244 | u8 pfc_en; | ||
245 | u8 ptype[MAX_TRAFFIC_CLASS]; | ||
246 | u8 bwgid[MAX_TRAFFIC_CLASS]; | ||
247 | u16 refill[MAX_TRAFFIC_CLASS]; | ||
248 | u16 max[MAX_TRAFFIC_CLASS]; | ||
249 | /* CEE does not define a priority to tc mapping so map 1:1 */ | ||
250 | u8 prio_tc[MAX_TRAFFIC_CLASS] = {0, 1, 2, 3, 4, 5, 6, 7}; | ||
251 | |||
252 | /* Unpack CEE standard containers */ | ||
253 | ixgbe_dcb_unpack_pfc(dcb_config, &pfc_en); | ||
254 | ixgbe_dcb_unpack_refill(dcb_config, DCB_TX_CONFIG, refill); | ||
255 | ixgbe_dcb_unpack_max(dcb_config, max); | ||
256 | ixgbe_dcb_unpack_bwgid(dcb_config, DCB_TX_CONFIG, bwgid); | ||
257 | ixgbe_dcb_unpack_prio(dcb_config, DCB_TX_CONFIG, ptype); | ||
258 | |||
259 | switch (hw->mac.type) { | ||
260 | case ixgbe_mac_82598EB: | ||
261 | ret = ixgbe_dcb_hw_config_82598(hw, pfc_en, refill, max, | ||
262 | bwgid, ptype); | ||
263 | break; | ||
264 | case ixgbe_mac_82599EB: | ||
265 | case ixgbe_mac_X540: | ||
266 | ret = ixgbe_dcb_hw_config_82599(hw, pfc_en, refill, max, | ||
267 | bwgid, ptype, prio_tc); | ||
268 | break; | ||
269 | default: | ||
270 | break; | ||
271 | } | ||
272 | return ret; | ||
273 | } | ||
274 | |||
275 | /* Helper routines to abstract HW specifics from DCB netlink ops */ | ||
276 | s32 ixgbe_dcb_hw_pfc_config(struct ixgbe_hw *hw, u8 pfc_en) | ||
277 | { | ||
278 | int ret = -EINVAL; | ||
279 | |||
280 | switch (hw->mac.type) { | ||
281 | case ixgbe_mac_82598EB: | ||
282 | ret = ixgbe_dcb_config_pfc_82598(hw, pfc_en); | ||
283 | break; | ||
284 | case ixgbe_mac_82599EB: | ||
285 | case ixgbe_mac_X540: | ||
286 | ret = ixgbe_dcb_config_pfc_82599(hw, pfc_en); | ||
287 | break; | ||
288 | default: | ||
289 | break; | ||
290 | } | ||
291 | return ret; | ||
292 | } | ||
293 | |||
294 | s32 ixgbe_dcb_hw_ets_config(struct ixgbe_hw *hw, | ||
295 | u16 *refill, u16 *max, u8 *bwg_id, | ||
296 | u8 *prio_type, u8 *prio_tc) | ||
297 | { | ||
298 | switch (hw->mac.type) { | ||
299 | case ixgbe_mac_82598EB: | ||
300 | ixgbe_dcb_config_rx_arbiter_82598(hw, refill, max, | ||
301 | prio_type); | ||
302 | ixgbe_dcb_config_tx_desc_arbiter_82598(hw, refill, max, | ||
303 | bwg_id, prio_type); | ||
304 | ixgbe_dcb_config_tx_data_arbiter_82598(hw, refill, max, | ||
305 | bwg_id, prio_type); | ||
306 | break; | ||
307 | case ixgbe_mac_82599EB: | ||
308 | case ixgbe_mac_X540: | ||
309 | ixgbe_dcb_config_rx_arbiter_82599(hw, refill, max, | ||
310 | bwg_id, prio_type, prio_tc); | ||
311 | ixgbe_dcb_config_tx_desc_arbiter_82599(hw, refill, max, | ||
312 | bwg_id, prio_type); | ||
313 | ixgbe_dcb_config_tx_data_arbiter_82599(hw, refill, max, bwg_id, | ||
314 | prio_type, prio_tc); | ||
315 | break; | ||
316 | default: | ||
317 | break; | ||
318 | } | ||
319 | return 0; | ||
320 | } | ||
diff --git a/drivers/net/ixgbe/ixgbe_dcb.h b/drivers/net/ixgbe/ixgbe_dcb.h new file mode 100644 index 00000000000..e85826ae032 --- /dev/null +++ b/drivers/net/ixgbe/ixgbe_dcb.h | |||
@@ -0,0 +1,167 @@ | |||
1 | /******************************************************************************* | ||
2 | |||
3 | Intel 10 Gigabit PCI Express Linux driver | ||
4 | Copyright(c) 1999 - 2011 Intel Corporation. | ||
5 | |||
6 | This program is free software; you can redistribute it and/or modify it | ||
7 | under the terms and conditions of the GNU General Public License, | ||
8 | version 2, as published by the Free Software Foundation. | ||
9 | |||
10 | This program is distributed in the hope it will be useful, but WITHOUT | ||
11 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
12 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
13 | more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License along with | ||
16 | this program; if not, write to the Free Software Foundation, Inc., | ||
17 | 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. | ||
18 | |||
19 | The full GNU General Public License is included in this distribution in | ||
20 | the file called "COPYING". | ||
21 | |||
22 | Contact Information: | ||
23 | Linux NICS <linux.nics@intel.com> | ||
24 | e1000-devel Mailing List <e1000-devel@lists.sourceforge.net> | ||
25 | Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 | ||
26 | |||
27 | *******************************************************************************/ | ||
28 | |||
29 | #ifndef _DCB_CONFIG_H_ | ||
30 | #define _DCB_CONFIG_H_ | ||
31 | |||
32 | #include "ixgbe_type.h" | ||
33 | |||
34 | /* DCB data structures */ | ||
35 | |||
36 | #define IXGBE_MAX_PACKET_BUFFERS 8 | ||
37 | #define MAX_USER_PRIORITY 8 | ||
38 | #define MAX_TRAFFIC_CLASS 8 | ||
39 | #define MAX_BW_GROUP 8 | ||
40 | #define BW_PERCENT 100 | ||
41 | |||
42 | #define DCB_TX_CONFIG 0 | ||
43 | #define DCB_RX_CONFIG 1 | ||
44 | |||
45 | /* DCB error Codes */ | ||
46 | #define DCB_SUCCESS 0 | ||
47 | #define DCB_ERR_CONFIG -1 | ||
48 | #define DCB_ERR_PARAM -2 | ||
49 | |||
50 | /* Transmit and receive Errors */ | ||
51 | /* Error in bandwidth group allocation */ | ||
52 | #define DCB_ERR_BW_GROUP -3 | ||
53 | /* Error in traffic class bandwidth allocation */ | ||
54 | #define DCB_ERR_TC_BW -4 | ||
55 | /* Traffic class has both link strict and group strict enabled */ | ||
56 | #define DCB_ERR_LS_GS -5 | ||
57 | /* Link strict traffic class has non zero bandwidth */ | ||
58 | #define DCB_ERR_LS_BW_NONZERO -6 | ||
59 | /* Link strict bandwidth group has non zero bandwidth */ | ||
60 | #define DCB_ERR_LS_BWG_NONZERO -7 | ||
61 | /* Traffic class has zero bandwidth */ | ||
62 | #define DCB_ERR_TC_BW_ZERO -8 | ||
63 | |||
64 | #define DCB_NOT_IMPLEMENTED 0x7FFFFFFF | ||
65 | |||
66 | struct dcb_pfc_tc_debug { | ||
67 | u8 tc; | ||
68 | u8 pause_status; | ||
69 | u64 pause_quanta; | ||
70 | }; | ||
71 | |||
72 | enum strict_prio_type { | ||
73 | prio_none = 0, | ||
74 | prio_group, | ||
75 | prio_link | ||
76 | }; | ||
77 | |||
78 | /* DCB capability definitions */ | ||
79 | #define IXGBE_DCB_PG_SUPPORT 0x00000001 | ||
80 | #define IXGBE_DCB_PFC_SUPPORT 0x00000002 | ||
81 | #define IXGBE_DCB_BCN_SUPPORT 0x00000004 | ||
82 | #define IXGBE_DCB_UP2TC_SUPPORT 0x00000008 | ||
83 | #define IXGBE_DCB_GSP_SUPPORT 0x00000010 | ||
84 | |||
85 | #define IXGBE_DCB_8_TC_SUPPORT 0x80 | ||
86 | |||
87 | struct dcb_support { | ||
88 | /* DCB capabilities */ | ||
89 | u32 capabilities; | ||
90 | |||
91 | /* Each bit represents a number of TCs configurable in the hw. | ||
92 | * If 8 traffic classes can be configured, the value is 0x80. | ||
93 | */ | ||
94 | u8 traffic_classes; | ||
95 | u8 pfc_traffic_classes; | ||
96 | }; | ||
97 | |||
98 | /* Traffic class bandwidth allocation per direction */ | ||
99 | struct tc_bw_alloc { | ||
100 | u8 bwg_id; /* Bandwidth Group (BWG) ID */ | ||
101 | u8 bwg_percent; /* % of BWG's bandwidth */ | ||
102 | u8 link_percent; /* % of link bandwidth */ | ||
103 | u8 up_to_tc_bitmap; /* User Priority to Traffic Class mapping */ | ||
104 | u16 data_credits_refill; /* Credit refill amount in 64B granularity */ | ||
105 | u16 data_credits_max; /* Max credits for a configured packet buffer | ||
106 | * in 64B granularity.*/ | ||
107 | enum strict_prio_type prio_type; /* Link or Group Strict Priority */ | ||
108 | }; | ||
109 | |||
110 | enum dcb_pfc_type { | ||
111 | pfc_disabled = 0, | ||
112 | pfc_enabled_full, | ||
113 | pfc_enabled_tx, | ||
114 | pfc_enabled_rx | ||
115 | }; | ||
116 | |||
117 | /* Traffic class configuration */ | ||
118 | struct tc_configuration { | ||
119 | struct tc_bw_alloc path[2]; /* One each for Tx/Rx */ | ||
120 | enum dcb_pfc_type dcb_pfc; /* Class based flow control setting */ | ||
121 | |||
122 | u16 desc_credits_max; /* For Tx Descriptor arbitration */ | ||
123 | u8 tc; /* Traffic class (TC) */ | ||
124 | }; | ||
125 | |||
126 | struct dcb_num_tcs { | ||
127 | u8 pg_tcs; | ||
128 | u8 pfc_tcs; | ||
129 | }; | ||
130 | |||
131 | struct ixgbe_dcb_config { | ||
132 | struct dcb_support support; | ||
133 | struct dcb_num_tcs num_tcs; | ||
134 | struct tc_configuration tc_config[MAX_TRAFFIC_CLASS]; | ||
135 | u8 bw_percentage[2][MAX_BW_GROUP]; /* One each for Tx/Rx */ | ||
136 | bool pfc_mode_enable; | ||
137 | |||
138 | u32 dcb_cfg_version; /* Not used...OS-specific? */ | ||
139 | u32 link_speed; /* For bandwidth allocation validation purpose */ | ||
140 | }; | ||
141 | |||
142 | /* DCB driver APIs */ | ||
143 | void ixgbe_dcb_unpack_pfc(struct ixgbe_dcb_config *cfg, u8 *pfc_en); | ||
144 | void ixgbe_dcb_unpack_refill(struct ixgbe_dcb_config *, int, u16 *); | ||
145 | void ixgbe_dcb_unpack_max(struct ixgbe_dcb_config *, u16 *); | ||
146 | void ixgbe_dcb_unpack_bwgid(struct ixgbe_dcb_config *, int, u8 *); | ||
147 | void ixgbe_dcb_unpack_prio(struct ixgbe_dcb_config *, int, u8 *); | ||
148 | |||
149 | /* DCB credits calculation */ | ||
150 | s32 ixgbe_ieee_credits(__u8 *bw, __u16 *refill, __u16 *max, int max_frame); | ||
151 | s32 ixgbe_dcb_calculate_tc_credits(struct ixgbe_hw *, | ||
152 | struct ixgbe_dcb_config *, int, u8); | ||
153 | |||
154 | /* DCB hw initialization */ | ||
155 | s32 ixgbe_dcb_hw_ets_config(struct ixgbe_hw *hw, u16 *refill, u16 *max, | ||
156 | u8 *bwg_id, u8 *prio_type, u8 *tc_prio); | ||
157 | s32 ixgbe_dcb_hw_pfc_config(struct ixgbe_hw *hw, u8 pfc_en); | ||
158 | s32 ixgbe_dcb_hw_config(struct ixgbe_hw *, struct ixgbe_dcb_config *); | ||
159 | |||
160 | /* DCB definitions for credit calculation */ | ||
161 | #define DCB_CREDIT_QUANTUM 64 /* DCB Quantum */ | ||
162 | #define MAX_CREDIT_REFILL 511 /* 0x1FF * 64B = 32704B */ | ||
163 | #define DCB_MAX_TSO_SIZE (32*1024) /* MAX TSO packet size supported in DCB mode */ | ||
164 | #define MINIMUM_CREDIT_FOR_TSO (DCB_MAX_TSO_SIZE/64 + 1) /* 513 for 32KB TSO packet */ | ||
165 | #define MAX_CREDIT 4095 /* Maximum credit supported: 256KB * 1204 / 64B */ | ||
166 | |||
167 | #endif /* _DCB_CONFIG_H */ | ||
diff --git a/drivers/net/ixgbe/ixgbe_dcb_82598.c b/drivers/net/ixgbe/ixgbe_dcb_82598.c new file mode 100644 index 00000000000..2288c3cac01 --- /dev/null +++ b/drivers/net/ixgbe/ixgbe_dcb_82598.c | |||
@@ -0,0 +1,297 @@ | |||
1 | /******************************************************************************* | ||
2 | |||
3 | Intel 10 Gigabit PCI Express Linux driver | ||
4 | Copyright(c) 1999 - 2011 Intel Corporation. | ||
5 | |||
6 | This program is free software; you can redistribute it and/or modify it | ||
7 | under the terms and conditions of the GNU General Public License, | ||
8 | version 2, as published by the Free Software Foundation. | ||
9 | |||
10 | This program is distributed in the hope it will be useful, but WITHOUT | ||
11 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
12 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
13 | more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License along with | ||
16 | this program; if not, write to the Free Software Foundation, Inc., | ||
17 | 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. | ||
18 | |||
19 | The full GNU General Public License is included in this distribution in | ||
20 | the file called "COPYING". | ||
21 | |||
22 | Contact Information: | ||
23 | Linux NICS <linux.nics@intel.com> | ||
24 | e1000-devel Mailing List <e1000-devel@lists.sourceforge.net> | ||
25 | Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 | ||
26 | |||
27 | *******************************************************************************/ | ||
28 | |||
29 | #include "ixgbe.h" | ||
30 | #include "ixgbe_type.h" | ||
31 | #include "ixgbe_dcb.h" | ||
32 | #include "ixgbe_dcb_82598.h" | ||
33 | |||
34 | /** | ||
35 | * ixgbe_dcb_config_rx_arbiter_82598 - Config Rx data arbiter | ||
36 | * @hw: pointer to hardware structure | ||
37 | * @dcb_config: pointer to ixgbe_dcb_config structure | ||
38 | * | ||
39 | * Configure Rx Data Arbiter and credits for each traffic class. | ||
40 | */ | ||
41 | s32 ixgbe_dcb_config_rx_arbiter_82598(struct ixgbe_hw *hw, | ||
42 | u16 *refill, | ||
43 | u16 *max, | ||
44 | u8 *prio_type) | ||
45 | { | ||
46 | u32 reg = 0; | ||
47 | u32 credit_refill = 0; | ||
48 | u32 credit_max = 0; | ||
49 | u8 i = 0; | ||
50 | |||
51 | reg = IXGBE_READ_REG(hw, IXGBE_RUPPBMR) | IXGBE_RUPPBMR_MQA; | ||
52 | IXGBE_WRITE_REG(hw, IXGBE_RUPPBMR, reg); | ||
53 | |||
54 | reg = IXGBE_READ_REG(hw, IXGBE_RMCS); | ||
55 | /* Enable Arbiter */ | ||
56 | reg &= ~IXGBE_RMCS_ARBDIS; | ||
57 | /* Enable Receive Recycle within the BWG */ | ||
58 | reg |= IXGBE_RMCS_RRM; | ||
59 | /* Enable Deficit Fixed Priority arbitration*/ | ||
60 | reg |= IXGBE_RMCS_DFP; | ||
61 | |||
62 | IXGBE_WRITE_REG(hw, IXGBE_RMCS, reg); | ||
63 | |||
64 | /* Configure traffic class credits and priority */ | ||
65 | for (i = 0; i < MAX_TRAFFIC_CLASS; i++) { | ||
66 | credit_refill = refill[i]; | ||
67 | credit_max = max[i]; | ||
68 | |||
69 | reg = credit_refill | (credit_max << IXGBE_RT2CR_MCL_SHIFT); | ||
70 | |||
71 | if (prio_type[i] == prio_link) | ||
72 | reg |= IXGBE_RT2CR_LSP; | ||
73 | |||
74 | IXGBE_WRITE_REG(hw, IXGBE_RT2CR(i), reg); | ||
75 | } | ||
76 | |||
77 | reg = IXGBE_READ_REG(hw, IXGBE_RDRXCTL); | ||
78 | reg |= IXGBE_RDRXCTL_RDMTS_1_2; | ||
79 | reg |= IXGBE_RDRXCTL_MPBEN; | ||
80 | reg |= IXGBE_RDRXCTL_MCEN; | ||
81 | IXGBE_WRITE_REG(hw, IXGBE_RDRXCTL, reg); | ||
82 | |||
83 | reg = IXGBE_READ_REG(hw, IXGBE_RXCTRL); | ||
84 | /* Make sure there is enough descriptors before arbitration */ | ||
85 | reg &= ~IXGBE_RXCTRL_DMBYPS; | ||
86 | IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, reg); | ||
87 | |||
88 | return 0; | ||
89 | } | ||
90 | |||
91 | /** | ||
92 | * ixgbe_dcb_config_tx_desc_arbiter_82598 - Config Tx Desc. arbiter | ||
93 | * @hw: pointer to hardware structure | ||
94 | * @dcb_config: pointer to ixgbe_dcb_config structure | ||
95 | * | ||
96 | * Configure Tx Descriptor Arbiter and credits for each traffic class. | ||
97 | */ | ||
98 | s32 ixgbe_dcb_config_tx_desc_arbiter_82598(struct ixgbe_hw *hw, | ||
99 | u16 *refill, | ||
100 | u16 *max, | ||
101 | u8 *bwg_id, | ||
102 | u8 *prio_type) | ||
103 | { | ||
104 | u32 reg, max_credits; | ||
105 | u8 i; | ||
106 | |||
107 | reg = IXGBE_READ_REG(hw, IXGBE_DPMCS); | ||
108 | |||
109 | /* Enable arbiter */ | ||
110 | reg &= ~IXGBE_DPMCS_ARBDIS; | ||
111 | /* Enable DFP and Recycle mode */ | ||
112 | reg |= (IXGBE_DPMCS_TDPAC | IXGBE_DPMCS_TRM); | ||
113 | reg |= IXGBE_DPMCS_TSOEF; | ||
114 | /* Configure Max TSO packet size 34KB including payload and headers */ | ||
115 | reg |= (0x4 << IXGBE_DPMCS_MTSOS_SHIFT); | ||
116 | |||
117 | IXGBE_WRITE_REG(hw, IXGBE_DPMCS, reg); | ||
118 | |||
119 | /* Configure traffic class credits and priority */ | ||
120 | for (i = 0; i < MAX_TRAFFIC_CLASS; i++) { | ||
121 | max_credits = max[i]; | ||
122 | reg = max_credits << IXGBE_TDTQ2TCCR_MCL_SHIFT; | ||
123 | reg |= refill[i]; | ||
124 | reg |= (u32)(bwg_id[i]) << IXGBE_TDTQ2TCCR_BWG_SHIFT; | ||
125 | |||
126 | if (prio_type[i] == prio_group) | ||
127 | reg |= IXGBE_TDTQ2TCCR_GSP; | ||
128 | |||
129 | if (prio_type[i] == prio_link) | ||
130 | reg |= IXGBE_TDTQ2TCCR_LSP; | ||
131 | |||
132 | IXGBE_WRITE_REG(hw, IXGBE_TDTQ2TCCR(i), reg); | ||
133 | } | ||
134 | |||
135 | return 0; | ||
136 | } | ||
137 | |||
138 | /** | ||
139 | * ixgbe_dcb_config_tx_data_arbiter_82598 - Config Tx data arbiter | ||
140 | * @hw: pointer to hardware structure | ||
141 | * @dcb_config: pointer to ixgbe_dcb_config structure | ||
142 | * | ||
143 | * Configure Tx Data Arbiter and credits for each traffic class. | ||
144 | */ | ||
145 | s32 ixgbe_dcb_config_tx_data_arbiter_82598(struct ixgbe_hw *hw, | ||
146 | u16 *refill, | ||
147 | u16 *max, | ||
148 | u8 *bwg_id, | ||
149 | u8 *prio_type) | ||
150 | { | ||
151 | u32 reg; | ||
152 | u8 i; | ||
153 | |||
154 | reg = IXGBE_READ_REG(hw, IXGBE_PDPMCS); | ||
155 | /* Enable Data Plane Arbiter */ | ||
156 | reg &= ~IXGBE_PDPMCS_ARBDIS; | ||
157 | /* Enable DFP and Transmit Recycle Mode */ | ||
158 | reg |= (IXGBE_PDPMCS_TPPAC | IXGBE_PDPMCS_TRM); | ||
159 | |||
160 | IXGBE_WRITE_REG(hw, IXGBE_PDPMCS, reg); | ||
161 | |||
162 | /* Configure traffic class credits and priority */ | ||
163 | for (i = 0; i < MAX_TRAFFIC_CLASS; i++) { | ||
164 | reg = refill[i]; | ||
165 | reg |= (u32)(max[i]) << IXGBE_TDPT2TCCR_MCL_SHIFT; | ||
166 | reg |= (u32)(bwg_id[i]) << IXGBE_TDPT2TCCR_BWG_SHIFT; | ||
167 | |||
168 | if (prio_type[i] == prio_group) | ||
169 | reg |= IXGBE_TDPT2TCCR_GSP; | ||
170 | |||
171 | if (prio_type[i] == prio_link) | ||
172 | reg |= IXGBE_TDPT2TCCR_LSP; | ||
173 | |||
174 | IXGBE_WRITE_REG(hw, IXGBE_TDPT2TCCR(i), reg); | ||
175 | } | ||
176 | |||
177 | /* Enable Tx packet buffer division */ | ||
178 | reg = IXGBE_READ_REG(hw, IXGBE_DTXCTL); | ||
179 | reg |= IXGBE_DTXCTL_ENDBUBD; | ||
180 | IXGBE_WRITE_REG(hw, IXGBE_DTXCTL, reg); | ||
181 | |||
182 | return 0; | ||
183 | } | ||
184 | |||
185 | /** | ||
186 | * ixgbe_dcb_config_pfc_82598 - Config priority flow control | ||
187 | * @hw: pointer to hardware structure | ||
188 | * @dcb_config: pointer to ixgbe_dcb_config structure | ||
189 | * | ||
190 | * Configure Priority Flow Control for each traffic class. | ||
191 | */ | ||
192 | s32 ixgbe_dcb_config_pfc_82598(struct ixgbe_hw *hw, u8 pfc_en) | ||
193 | { | ||
194 | u32 reg, rx_pba_size; | ||
195 | u8 i; | ||
196 | |||
197 | if (pfc_en) { | ||
198 | /* Enable Transmit Priority Flow Control */ | ||
199 | reg = IXGBE_READ_REG(hw, IXGBE_RMCS); | ||
200 | reg &= ~IXGBE_RMCS_TFCE_802_3X; | ||
201 | /* correct the reporting of our flow control status */ | ||
202 | reg |= IXGBE_RMCS_TFCE_PRIORITY; | ||
203 | IXGBE_WRITE_REG(hw, IXGBE_RMCS, reg); | ||
204 | |||
205 | /* Enable Receive Priority Flow Control */ | ||
206 | reg = IXGBE_READ_REG(hw, IXGBE_FCTRL); | ||
207 | reg &= ~IXGBE_FCTRL_RFCE; | ||
208 | reg |= IXGBE_FCTRL_RPFCE; | ||
209 | IXGBE_WRITE_REG(hw, IXGBE_FCTRL, reg); | ||
210 | |||
211 | /* Configure pause time */ | ||
212 | for (i = 0; i < (MAX_TRAFFIC_CLASS >> 1); i++) | ||
213 | IXGBE_WRITE_REG(hw, IXGBE_FCTTV(i), 0x68006800); | ||
214 | |||
215 | /* Configure flow control refresh threshold value */ | ||
216 | IXGBE_WRITE_REG(hw, IXGBE_FCRTV, 0x3400); | ||
217 | } | ||
218 | |||
219 | /* | ||
220 | * Configure flow control thresholds and enable priority flow control | ||
221 | * for each traffic class. | ||
222 | */ | ||
223 | for (i = 0; i < MAX_TRAFFIC_CLASS; i++) { | ||
224 | int enabled = pfc_en & (1 << i); | ||
225 | rx_pba_size = IXGBE_READ_REG(hw, IXGBE_RXPBSIZE(i)); | ||
226 | rx_pba_size >>= IXGBE_RXPBSIZE_SHIFT; | ||
227 | reg = (rx_pba_size - hw->fc.low_water) << 10; | ||
228 | |||
229 | if (enabled == pfc_enabled_tx || | ||
230 | enabled == pfc_enabled_full) | ||
231 | reg |= IXGBE_FCRTL_XONE; | ||
232 | |||
233 | IXGBE_WRITE_REG(hw, IXGBE_FCRTL(i), reg); | ||
234 | |||
235 | reg = (rx_pba_size - hw->fc.high_water) << 10; | ||
236 | if (enabled == pfc_enabled_tx || | ||
237 | enabled == pfc_enabled_full) | ||
238 | reg |= IXGBE_FCRTH_FCEN; | ||
239 | |||
240 | IXGBE_WRITE_REG(hw, IXGBE_FCRTH(i), reg); | ||
241 | } | ||
242 | |||
243 | return 0; | ||
244 | } | ||
245 | |||
246 | /** | ||
247 | * ixgbe_dcb_config_tc_stats_82598 - Configure traffic class statistics | ||
248 | * @hw: pointer to hardware structure | ||
249 | * | ||
250 | * Configure queue statistics registers, all queues belonging to same traffic | ||
251 | * class uses a single set of queue statistics counters. | ||
252 | */ | ||
253 | static s32 ixgbe_dcb_config_tc_stats_82598(struct ixgbe_hw *hw) | ||
254 | { | ||
255 | u32 reg = 0; | ||
256 | u8 i = 0; | ||
257 | u8 j = 0; | ||
258 | |||
259 | /* Receive Queues stats setting - 8 queues per statistics reg */ | ||
260 | for (i = 0, j = 0; i < 15 && j < 8; i = i + 2, j++) { | ||
261 | reg = IXGBE_READ_REG(hw, IXGBE_RQSMR(i)); | ||
262 | reg |= ((0x1010101) * j); | ||
263 | IXGBE_WRITE_REG(hw, IXGBE_RQSMR(i), reg); | ||
264 | reg = IXGBE_READ_REG(hw, IXGBE_RQSMR(i + 1)); | ||
265 | reg |= ((0x1010101) * j); | ||
266 | IXGBE_WRITE_REG(hw, IXGBE_RQSMR(i + 1), reg); | ||
267 | } | ||
268 | /* Transmit Queues stats setting - 4 queues per statistics reg */ | ||
269 | for (i = 0; i < 8; i++) { | ||
270 | reg = IXGBE_READ_REG(hw, IXGBE_TQSMR(i)); | ||
271 | reg |= ((0x1010101) * i); | ||
272 | IXGBE_WRITE_REG(hw, IXGBE_TQSMR(i), reg); | ||
273 | } | ||
274 | |||
275 | return 0; | ||
276 | } | ||
277 | |||
278 | /** | ||
279 | * ixgbe_dcb_hw_config_82598 - Config and enable DCB | ||
280 | * @hw: pointer to hardware structure | ||
281 | * @dcb_config: pointer to ixgbe_dcb_config structure | ||
282 | * | ||
283 | * Configure dcb settings and enable dcb mode. | ||
284 | */ | ||
285 | s32 ixgbe_dcb_hw_config_82598(struct ixgbe_hw *hw, u8 pfc_en, u16 *refill, | ||
286 | u16 *max, u8 *bwg_id, u8 *prio_type) | ||
287 | { | ||
288 | ixgbe_dcb_config_rx_arbiter_82598(hw, refill, max, prio_type); | ||
289 | ixgbe_dcb_config_tx_desc_arbiter_82598(hw, refill, max, | ||
290 | bwg_id, prio_type); | ||
291 | ixgbe_dcb_config_tx_data_arbiter_82598(hw, refill, max, | ||
292 | bwg_id, prio_type); | ||
293 | ixgbe_dcb_config_pfc_82598(hw, pfc_en); | ||
294 | ixgbe_dcb_config_tc_stats_82598(hw); | ||
295 | |||
296 | return 0; | ||
297 | } | ||
diff --git a/drivers/net/ixgbe/ixgbe_dcb_82598.h b/drivers/net/ixgbe/ixgbe_dcb_82598.h new file mode 100644 index 00000000000..2f318935561 --- /dev/null +++ b/drivers/net/ixgbe/ixgbe_dcb_82598.h | |||
@@ -0,0 +1,97 @@ | |||
1 | /******************************************************************************* | ||
2 | |||
3 | Intel 10 Gigabit PCI Express Linux driver | ||
4 | Copyright(c) 1999 - 2011 Intel Corporation. | ||
5 | |||
6 | This program is free software; you can redistribute it and/or modify it | ||
7 | under the terms and conditions of the GNU General Public License, | ||
8 | version 2, as published by the Free Software Foundation. | ||
9 | |||
10 | This program is distributed in the hope it will be useful, but WITHOUT | ||
11 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
12 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
13 | more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License along with | ||
16 | this program; if not, write to the Free Software Foundation, Inc., | ||
17 | 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. | ||
18 | |||
19 | The full GNU General Public License is included in this distribution in | ||
20 | the file called "COPYING". | ||
21 | |||
22 | Contact Information: | ||
23 | Linux NICS <linux.nics@intel.com> | ||
24 | e1000-devel Mailing List <e1000-devel@lists.sourceforge.net> | ||
25 | Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 | ||
26 | |||
27 | *******************************************************************************/ | ||
28 | |||
29 | #ifndef _DCB_82598_CONFIG_H_ | ||
30 | #define _DCB_82598_CONFIG_H_ | ||
31 | |||
32 | /* DCB register definitions */ | ||
33 | |||
34 | #define IXGBE_DPMCS_MTSOS_SHIFT 16 | ||
35 | #define IXGBE_DPMCS_TDPAC 0x00000001 /* 0 Round Robin, 1 DFP - Deficit Fixed Priority */ | ||
36 | #define IXGBE_DPMCS_TRM 0x00000010 /* Transmit Recycle Mode */ | ||
37 | #define IXGBE_DPMCS_ARBDIS 0x00000040 /* DCB arbiter disable */ | ||
38 | #define IXGBE_DPMCS_TSOEF 0x00080000 /* TSO Expand Factor: 0=x4, 1=x2 */ | ||
39 | |||
40 | #define IXGBE_RUPPBMR_MQA 0x80000000 /* Enable UP to queue mapping */ | ||
41 | |||
42 | #define IXGBE_RT2CR_MCL_SHIFT 12 /* Offset to Max Credit Limit setting */ | ||
43 | #define IXGBE_RT2CR_LSP 0x80000000 /* LSP enable bit */ | ||
44 | |||
45 | #define IXGBE_RDRXCTL_MPBEN 0x00000010 /* DMA config for multiple packet buffers enable */ | ||
46 | #define IXGBE_RDRXCTL_MCEN 0x00000040 /* DMA config for multiple cores (RSS) enable */ | ||
47 | |||
48 | #define IXGBE_TDTQ2TCCR_MCL_SHIFT 12 | ||
49 | #define IXGBE_TDTQ2TCCR_BWG_SHIFT 9 | ||
50 | #define IXGBE_TDTQ2TCCR_GSP 0x40000000 | ||
51 | #define IXGBE_TDTQ2TCCR_LSP 0x80000000 | ||
52 | |||
53 | #define IXGBE_TDPT2TCCR_MCL_SHIFT 12 | ||
54 | #define IXGBE_TDPT2TCCR_BWG_SHIFT 9 | ||
55 | #define IXGBE_TDPT2TCCR_GSP 0x40000000 | ||
56 | #define IXGBE_TDPT2TCCR_LSP 0x80000000 | ||
57 | |||
58 | #define IXGBE_PDPMCS_TPPAC 0x00000020 /* 0 Round Robin, 1 for DFP - Deficit Fixed Priority */ | ||
59 | #define IXGBE_PDPMCS_ARBDIS 0x00000040 /* Arbiter disable */ | ||
60 | #define IXGBE_PDPMCS_TRM 0x00000100 /* Transmit Recycle Mode enable */ | ||
61 | |||
62 | #define IXGBE_DTXCTL_ENDBUBD 0x00000004 /* Enable DBU buffer division */ | ||
63 | |||
64 | #define IXGBE_TXPBSIZE_40KB 0x0000A000 /* 40KB Packet Buffer */ | ||
65 | #define IXGBE_RXPBSIZE_48KB 0x0000C000 /* 48KB Packet Buffer */ | ||
66 | #define IXGBE_RXPBSIZE_64KB 0x00010000 /* 64KB Packet Buffer */ | ||
67 | #define IXGBE_RXPBSIZE_80KB 0x00014000 /* 80KB Packet Buffer */ | ||
68 | |||
69 | #define IXGBE_RDRXCTL_RDMTS_1_2 0x00000000 | ||
70 | |||
71 | /* DCB hardware-specific driver APIs */ | ||
72 | |||
73 | /* DCB PFC functions */ | ||
74 | s32 ixgbe_dcb_config_pfc_82598(struct ixgbe_hw *, u8 pfc_en); | ||
75 | |||
76 | /* DCB hw initialization */ | ||
77 | s32 ixgbe_dcb_config_rx_arbiter_82598(struct ixgbe_hw *hw, | ||
78 | u16 *refill, | ||
79 | u16 *max, | ||
80 | u8 *prio_type); | ||
81 | |||
82 | s32 ixgbe_dcb_config_tx_desc_arbiter_82598(struct ixgbe_hw *hw, | ||
83 | u16 *refill, | ||
84 | u16 *max, | ||
85 | u8 *bwg_id, | ||
86 | u8 *prio_type); | ||
87 | |||
88 | s32 ixgbe_dcb_config_tx_data_arbiter_82598(struct ixgbe_hw *hw, | ||
89 | u16 *refill, | ||
90 | u16 *max, | ||
91 | u8 *bwg_id, | ||
92 | u8 *prio_type); | ||
93 | |||
94 | s32 ixgbe_dcb_hw_config_82598(struct ixgbe_hw *hw, u8 pfc_en, u16 *refill, | ||
95 | u16 *max, u8 *bwg_id, u8 *prio_type); | ||
96 | |||
97 | #endif /* _DCB_82598_CONFIG_H */ | ||
diff --git a/drivers/net/ixgbe/ixgbe_dcb_82599.c b/drivers/net/ixgbe/ixgbe_dcb_82599.c new file mode 100644 index 00000000000..ade98200288 --- /dev/null +++ b/drivers/net/ixgbe/ixgbe_dcb_82599.c | |||
@@ -0,0 +1,346 @@ | |||
1 | /******************************************************************************* | ||
2 | |||
3 | Intel 10 Gigabit PCI Express Linux driver | ||
4 | Copyright(c) 1999 - 2011 Intel Corporation. | ||
5 | |||
6 | This program is free software; you can redistribute it and/or modify it | ||
7 | under the terms and conditions of the GNU General Public License, | ||
8 | version 2, as published by the Free Software Foundation. | ||
9 | |||
10 | This program is distributed in the hope it will be useful, but WITHOUT | ||
11 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
12 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
13 | more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License along with | ||
16 | this program; if not, write to the Free Software Foundation, Inc., | ||
17 | 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. | ||
18 | |||
19 | The full GNU General Public License is included in this distribution in | ||
20 | the file called "COPYING". | ||
21 | |||
22 | Contact Information: | ||
23 | e1000-devel Mailing List <e1000-devel@lists.sourceforge.net> | ||
24 | Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 | ||
25 | |||
26 | *******************************************************************************/ | ||
27 | |||
28 | #include "ixgbe.h" | ||
29 | #include "ixgbe_type.h" | ||
30 | #include "ixgbe_dcb.h" | ||
31 | #include "ixgbe_dcb_82599.h" | ||
32 | |||
33 | /** | ||
34 | * ixgbe_dcb_config_rx_arbiter_82599 - Config Rx Data arbiter | ||
35 | * @hw: pointer to hardware structure | ||
36 | * @refill: refill credits index by traffic class | ||
37 | * @max: max credits index by traffic class | ||
38 | * @bwg_id: bandwidth grouping indexed by traffic class | ||
39 | * @prio_type: priority type indexed by traffic class | ||
40 | * | ||
41 | * Configure Rx Packet Arbiter and credits for each traffic class. | ||
42 | */ | ||
43 | s32 ixgbe_dcb_config_rx_arbiter_82599(struct ixgbe_hw *hw, | ||
44 | u16 *refill, | ||
45 | u16 *max, | ||
46 | u8 *bwg_id, | ||
47 | u8 *prio_type, | ||
48 | u8 *prio_tc) | ||
49 | { | ||
50 | u32 reg = 0; | ||
51 | u32 credit_refill = 0; | ||
52 | u32 credit_max = 0; | ||
53 | u8 i = 0; | ||
54 | |||
55 | /* | ||
56 | * Disable the arbiter before changing parameters | ||
57 | * (always enable recycle mode; WSP) | ||
58 | */ | ||
59 | reg = IXGBE_RTRPCS_RRM | IXGBE_RTRPCS_RAC | IXGBE_RTRPCS_ARBDIS; | ||
60 | IXGBE_WRITE_REG(hw, IXGBE_RTRPCS, reg); | ||
61 | |||
62 | /* Map all traffic classes to their UP, 1 to 1 */ | ||
63 | reg = 0; | ||
64 | for (i = 0; i < MAX_TRAFFIC_CLASS; i++) | ||
65 | reg |= (prio_tc[i] << (i * IXGBE_RTRUP2TC_UP_SHIFT)); | ||
66 | IXGBE_WRITE_REG(hw, IXGBE_RTRUP2TC, reg); | ||
67 | |||
68 | /* Configure traffic class credits and priority */ | ||
69 | for (i = 0; i < MAX_TRAFFIC_CLASS; i++) { | ||
70 | credit_refill = refill[i]; | ||
71 | credit_max = max[i]; | ||
72 | reg = credit_refill | (credit_max << IXGBE_RTRPT4C_MCL_SHIFT); | ||
73 | |||
74 | reg |= (u32)(bwg_id[i]) << IXGBE_RTRPT4C_BWG_SHIFT; | ||
75 | |||
76 | if (prio_type[i] == prio_link) | ||
77 | reg |= IXGBE_RTRPT4C_LSP; | ||
78 | |||
79 | IXGBE_WRITE_REG(hw, IXGBE_RTRPT4C(i), reg); | ||
80 | } | ||
81 | |||
82 | /* | ||
83 | * Configure Rx packet plane (recycle mode; WSP) and | ||
84 | * enable arbiter | ||
85 | */ | ||
86 | reg = IXGBE_RTRPCS_RRM | IXGBE_RTRPCS_RAC; | ||
87 | IXGBE_WRITE_REG(hw, IXGBE_RTRPCS, reg); | ||
88 | |||
89 | return 0; | ||
90 | } | ||
91 | |||
92 | /** | ||
93 | * ixgbe_dcb_config_tx_desc_arbiter_82599 - Config Tx Desc. arbiter | ||
94 | * @hw: pointer to hardware structure | ||
95 | * @refill: refill credits index by traffic class | ||
96 | * @max: max credits index by traffic class | ||
97 | * @bwg_id: bandwidth grouping indexed by traffic class | ||
98 | * @prio_type: priority type indexed by traffic class | ||
99 | * | ||
100 | * Configure Tx Descriptor Arbiter and credits for each traffic class. | ||
101 | */ | ||
102 | s32 ixgbe_dcb_config_tx_desc_arbiter_82599(struct ixgbe_hw *hw, | ||
103 | u16 *refill, | ||
104 | u16 *max, | ||
105 | u8 *bwg_id, | ||
106 | u8 *prio_type) | ||
107 | { | ||
108 | u32 reg, max_credits; | ||
109 | u8 i; | ||
110 | |||
111 | /* Clear the per-Tx queue credits; we use per-TC instead */ | ||
112 | for (i = 0; i < 128; i++) { | ||
113 | IXGBE_WRITE_REG(hw, IXGBE_RTTDQSEL, i); | ||
114 | IXGBE_WRITE_REG(hw, IXGBE_RTTDT1C, 0); | ||
115 | } | ||
116 | |||
117 | /* Configure traffic class credits and priority */ | ||
118 | for (i = 0; i < MAX_TRAFFIC_CLASS; i++) { | ||
119 | max_credits = max[i]; | ||
120 | reg = max_credits << IXGBE_RTTDT2C_MCL_SHIFT; | ||
121 | reg |= refill[i]; | ||
122 | reg |= (u32)(bwg_id[i]) << IXGBE_RTTDT2C_BWG_SHIFT; | ||
123 | |||
124 | if (prio_type[i] == prio_group) | ||
125 | reg |= IXGBE_RTTDT2C_GSP; | ||
126 | |||
127 | if (prio_type[i] == prio_link) | ||
128 | reg |= IXGBE_RTTDT2C_LSP; | ||
129 | |||
130 | IXGBE_WRITE_REG(hw, IXGBE_RTTDT2C(i), reg); | ||
131 | } | ||
132 | |||
133 | /* | ||
134 | * Configure Tx descriptor plane (recycle mode; WSP) and | ||
135 | * enable arbiter | ||
136 | */ | ||
137 | reg = IXGBE_RTTDCS_TDPAC | IXGBE_RTTDCS_TDRM; | ||
138 | IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, reg); | ||
139 | |||
140 | return 0; | ||
141 | } | ||
142 | |||
143 | /** | ||
144 | * ixgbe_dcb_config_tx_data_arbiter_82599 - Config Tx Data arbiter | ||
145 | * @hw: pointer to hardware structure | ||
146 | * @refill: refill credits index by traffic class | ||
147 | * @max: max credits index by traffic class | ||
148 | * @bwg_id: bandwidth grouping indexed by traffic class | ||
149 | * @prio_type: priority type indexed by traffic class | ||
150 | * | ||
151 | * Configure Tx Packet Arbiter and credits for each traffic class. | ||
152 | */ | ||
153 | s32 ixgbe_dcb_config_tx_data_arbiter_82599(struct ixgbe_hw *hw, | ||
154 | u16 *refill, | ||
155 | u16 *max, | ||
156 | u8 *bwg_id, | ||
157 | u8 *prio_type, | ||
158 | u8 *prio_tc) | ||
159 | { | ||
160 | u32 reg; | ||
161 | u8 i; | ||
162 | |||
163 | /* | ||
164 | * Disable the arbiter before changing parameters | ||
165 | * (always enable recycle mode; SP; arb delay) | ||
166 | */ | ||
167 | reg = IXGBE_RTTPCS_TPPAC | IXGBE_RTTPCS_TPRM | | ||
168 | (IXGBE_RTTPCS_ARBD_DCB << IXGBE_RTTPCS_ARBD_SHIFT) | | ||
169 | IXGBE_RTTPCS_ARBDIS; | ||
170 | IXGBE_WRITE_REG(hw, IXGBE_RTTPCS, reg); | ||
171 | |||
172 | /* Map all traffic classes to their UP, 1 to 1 */ | ||
173 | reg = 0; | ||
174 | for (i = 0; i < MAX_TRAFFIC_CLASS; i++) | ||
175 | reg |= (prio_tc[i] << (i * IXGBE_RTTUP2TC_UP_SHIFT)); | ||
176 | IXGBE_WRITE_REG(hw, IXGBE_RTTUP2TC, reg); | ||
177 | |||
178 | /* Configure traffic class credits and priority */ | ||
179 | for (i = 0; i < MAX_TRAFFIC_CLASS; i++) { | ||
180 | reg = refill[i]; | ||
181 | reg |= (u32)(max[i]) << IXGBE_RTTPT2C_MCL_SHIFT; | ||
182 | reg |= (u32)(bwg_id[i]) << IXGBE_RTTPT2C_BWG_SHIFT; | ||
183 | |||
184 | if (prio_type[i] == prio_group) | ||
185 | reg |= IXGBE_RTTPT2C_GSP; | ||
186 | |||
187 | if (prio_type[i] == prio_link) | ||
188 | reg |= IXGBE_RTTPT2C_LSP; | ||
189 | |||
190 | IXGBE_WRITE_REG(hw, IXGBE_RTTPT2C(i), reg); | ||
191 | } | ||
192 | |||
193 | /* | ||
194 | * Configure Tx packet plane (recycle mode; SP; arb delay) and | ||
195 | * enable arbiter | ||
196 | */ | ||
197 | reg = IXGBE_RTTPCS_TPPAC | IXGBE_RTTPCS_TPRM | | ||
198 | (IXGBE_RTTPCS_ARBD_DCB << IXGBE_RTTPCS_ARBD_SHIFT); | ||
199 | IXGBE_WRITE_REG(hw, IXGBE_RTTPCS, reg); | ||
200 | |||
201 | return 0; | ||
202 | } | ||
203 | |||
204 | /** | ||
205 | * ixgbe_dcb_config_pfc_82599 - Configure priority flow control | ||
206 | * @hw: pointer to hardware structure | ||
207 | * @pfc_en: enabled pfc bitmask | ||
208 | * | ||
209 | * Configure Priority Flow Control (PFC) for each traffic class. | ||
210 | */ | ||
211 | s32 ixgbe_dcb_config_pfc_82599(struct ixgbe_hw *hw, u8 pfc_en) | ||
212 | { | ||
213 | u32 i, reg, rx_pba_size; | ||
214 | |||
215 | /* Configure PFC Tx thresholds per TC */ | ||
216 | for (i = 0; i < MAX_TRAFFIC_CLASS; i++) { | ||
217 | int enabled = pfc_en & (1 << i); | ||
218 | rx_pba_size = IXGBE_READ_REG(hw, IXGBE_RXPBSIZE(i)); | ||
219 | rx_pba_size >>= IXGBE_RXPBSIZE_SHIFT; | ||
220 | |||
221 | reg = (rx_pba_size - hw->fc.low_water) << 10; | ||
222 | |||
223 | if (enabled) | ||
224 | reg |= IXGBE_FCRTL_XONE; | ||
225 | IXGBE_WRITE_REG(hw, IXGBE_FCRTL_82599(i), reg); | ||
226 | |||
227 | reg = (rx_pba_size - hw->fc.high_water) << 10; | ||
228 | if (enabled) | ||
229 | reg |= IXGBE_FCRTH_FCEN; | ||
230 | IXGBE_WRITE_REG(hw, IXGBE_FCRTH_82599(i), reg); | ||
231 | } | ||
232 | |||
233 | if (pfc_en) { | ||
234 | /* Configure pause time (2 TCs per register) */ | ||
235 | reg = hw->fc.pause_time | (hw->fc.pause_time << 16); | ||
236 | for (i = 0; i < (MAX_TRAFFIC_CLASS / 2); i++) | ||
237 | IXGBE_WRITE_REG(hw, IXGBE_FCTTV(i), reg); | ||
238 | |||
239 | /* Configure flow control refresh threshold value */ | ||
240 | IXGBE_WRITE_REG(hw, IXGBE_FCRTV, hw->fc.pause_time / 2); | ||
241 | |||
242 | |||
243 | reg = IXGBE_FCCFG_TFCE_PRIORITY; | ||
244 | IXGBE_WRITE_REG(hw, IXGBE_FCCFG, reg); | ||
245 | /* | ||
246 | * Enable Receive PFC | ||
247 | * 82599 will always honor XOFF frames we receive when | ||
248 | * we are in PFC mode however X540 only honors enabled | ||
249 | * traffic classes. | ||
250 | */ | ||
251 | reg = IXGBE_READ_REG(hw, IXGBE_MFLCN); | ||
252 | reg &= ~IXGBE_MFLCN_RFCE; | ||
253 | reg |= IXGBE_MFLCN_RPFCE | IXGBE_MFLCN_DPF; | ||
254 | |||
255 | if (hw->mac.type == ixgbe_mac_X540) | ||
256 | reg |= pfc_en << IXGBE_MFLCN_RPFCE_SHIFT; | ||
257 | |||
258 | IXGBE_WRITE_REG(hw, IXGBE_MFLCN, reg); | ||
259 | |||
260 | } else { | ||
261 | for (i = 0; i < MAX_TRAFFIC_CLASS; i++) | ||
262 | hw->mac.ops.fc_enable(hw, i); | ||
263 | } | ||
264 | |||
265 | return 0; | ||
266 | } | ||
267 | |||
268 | /** | ||
269 | * ixgbe_dcb_config_tc_stats_82599 - Config traffic class statistics | ||
270 | * @hw: pointer to hardware structure | ||
271 | * | ||
272 | * Configure queue statistics registers, all queues belonging to same traffic | ||
273 | * class uses a single set of queue statistics counters. | ||
274 | */ | ||
275 | static s32 ixgbe_dcb_config_tc_stats_82599(struct ixgbe_hw *hw) | ||
276 | { | ||
277 | u32 reg = 0; | ||
278 | u8 i = 0; | ||
279 | |||
280 | /* | ||
281 | * Receive Queues stats setting | ||
282 | * 32 RQSMR registers, each configuring 4 queues. | ||
283 | * Set all 16 queues of each TC to the same stat | ||
284 | * with TC 'n' going to stat 'n'. | ||
285 | */ | ||
286 | for (i = 0; i < 32; i++) { | ||
287 | reg = 0x01010101 * (i / 4); | ||
288 | IXGBE_WRITE_REG(hw, IXGBE_RQSMR(i), reg); | ||
289 | } | ||
290 | /* | ||
291 | * Transmit Queues stats setting | ||
292 | * 32 TQSM registers, each controlling 4 queues. | ||
293 | * Set all queues of each TC to the same stat | ||
294 | * with TC 'n' going to stat 'n'. | ||
295 | * Tx queues are allocated non-uniformly to TCs: | ||
296 | * 32, 32, 16, 16, 8, 8, 8, 8. | ||
297 | */ | ||
298 | for (i = 0; i < 32; i++) { | ||
299 | if (i < 8) | ||
300 | reg = 0x00000000; | ||
301 | else if (i < 16) | ||
302 | reg = 0x01010101; | ||
303 | else if (i < 20) | ||
304 | reg = 0x02020202; | ||
305 | else if (i < 24) | ||
306 | reg = 0x03030303; | ||
307 | else if (i < 26) | ||
308 | reg = 0x04040404; | ||
309 | else if (i < 28) | ||
310 | reg = 0x05050505; | ||
311 | else if (i < 30) | ||
312 | reg = 0x06060606; | ||
313 | else | ||
314 | reg = 0x07070707; | ||
315 | IXGBE_WRITE_REG(hw, IXGBE_TQSM(i), reg); | ||
316 | } | ||
317 | |||
318 | return 0; | ||
319 | } | ||
320 | |||
321 | /** | ||
322 | * ixgbe_dcb_hw_config_82599 - Configure and enable DCB | ||
323 | * @hw: pointer to hardware structure | ||
324 | * @refill: refill credits index by traffic class | ||
325 | * @max: max credits index by traffic class | ||
326 | * @bwg_id: bandwidth grouping indexed by traffic class | ||
327 | * @prio_type: priority type indexed by traffic class | ||
328 | * @pfc_en: enabled pfc bitmask | ||
329 | * | ||
330 | * Configure dcb settings and enable dcb mode. | ||
331 | */ | ||
332 | s32 ixgbe_dcb_hw_config_82599(struct ixgbe_hw *hw, u8 pfc_en, u16 *refill, | ||
333 | u16 *max, u8 *bwg_id, u8 *prio_type, u8 *prio_tc) | ||
334 | { | ||
335 | ixgbe_dcb_config_rx_arbiter_82599(hw, refill, max, bwg_id, | ||
336 | prio_type, prio_tc); | ||
337 | ixgbe_dcb_config_tx_desc_arbiter_82599(hw, refill, max, | ||
338 | bwg_id, prio_type); | ||
339 | ixgbe_dcb_config_tx_data_arbiter_82599(hw, refill, max, | ||
340 | bwg_id, prio_type, prio_tc); | ||
341 | ixgbe_dcb_config_pfc_82599(hw, pfc_en); | ||
342 | ixgbe_dcb_config_tc_stats_82599(hw); | ||
343 | |||
344 | return 0; | ||
345 | } | ||
346 | |||
diff --git a/drivers/net/ixgbe/ixgbe_dcb_82599.h b/drivers/net/ixgbe/ixgbe_dcb_82599.h new file mode 100644 index 00000000000..08d1749862a --- /dev/null +++ b/drivers/net/ixgbe/ixgbe_dcb_82599.h | |||
@@ -0,0 +1,123 @@ | |||
1 | /******************************************************************************* | ||
2 | |||
3 | Intel 10 Gigabit PCI Express Linux driver | ||
4 | Copyright(c) 1999 - 2011 Intel Corporation. | ||
5 | |||
6 | This program is free software; you can redistribute it and/or modify it | ||
7 | under the terms and conditions of the GNU General Public License, | ||
8 | version 2, as published by the Free Software Foundation. | ||
9 | |||
10 | This program is distributed in the hope it will be useful, but WITHOUT | ||
11 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
12 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
13 | more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License along with | ||
16 | this program; if not, write to the Free Software Foundation, Inc., | ||
17 | 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. | ||
18 | |||
19 | The full GNU General Public License is included in this distribution in | ||
20 | the file called "COPYING". | ||
21 | |||
22 | Contact Information: | ||
23 | e1000-devel Mailing List <e1000-devel@lists.sourceforge.net> | ||
24 | Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 | ||
25 | |||
26 | *******************************************************************************/ | ||
27 | |||
28 | #ifndef _DCB_82599_CONFIG_H_ | ||
29 | #define _DCB_82599_CONFIG_H_ | ||
30 | |||
31 | /* DCB register definitions */ | ||
32 | #define IXGBE_RTTDCS_TDPAC 0x00000001 /* 0 Round Robin, | ||
33 | * 1 WSP - Weighted Strict Priority | ||
34 | */ | ||
35 | #define IXGBE_RTTDCS_VMPAC 0x00000002 /* 0 Round Robin, | ||
36 | * 1 WRR - Weighted Round Robin | ||
37 | */ | ||
38 | #define IXGBE_RTTDCS_TDRM 0x00000010 /* Transmit Recycle Mode */ | ||
39 | #define IXGBE_RTTDCS_ARBDIS 0x00000040 /* DCB arbiter disable */ | ||
40 | #define IXGBE_RTTDCS_BDPM 0x00400000 /* Bypass Data Pipe - must clear! */ | ||
41 | #define IXGBE_RTTDCS_BPBFSM 0x00800000 /* Bypass PB Free Space - must | ||
42 | * clear! | ||
43 | */ | ||
44 | #define IXGBE_RTTDCS_SPEED_CHG 0x80000000 /* Link speed change */ | ||
45 | |||
46 | /* Receive UP2TC mapping */ | ||
47 | #define IXGBE_RTRUP2TC_UP_SHIFT 3 | ||
48 | /* Transmit UP2TC mapping */ | ||
49 | #define IXGBE_RTTUP2TC_UP_SHIFT 3 | ||
50 | |||
51 | #define IXGBE_RTRPT4C_MCL_SHIFT 12 /* Offset to Max Credit Limit setting */ | ||
52 | #define IXGBE_RTRPT4C_BWG_SHIFT 9 /* Offset to BWG index */ | ||
53 | #define IXGBE_RTRPT4C_GSP 0x40000000 /* GSP enable bit */ | ||
54 | #define IXGBE_RTRPT4C_LSP 0x80000000 /* LSP enable bit */ | ||
55 | |||
56 | #define IXGBE_RDRXCTL_MPBEN 0x00000010 /* DMA config for multiple packet | ||
57 | * buffers enable | ||
58 | */ | ||
59 | #define IXGBE_RDRXCTL_MCEN 0x00000040 /* DMA config for multiple cores | ||
60 | * (RSS) enable | ||
61 | */ | ||
62 | |||
63 | /* RTRPCS Bit Masks */ | ||
64 | #define IXGBE_RTRPCS_RRM 0x00000002 /* Receive Recycle Mode enable */ | ||
65 | /* Receive Arbitration Control: 0 Round Robin, 1 DFP */ | ||
66 | #define IXGBE_RTRPCS_RAC 0x00000004 | ||
67 | #define IXGBE_RTRPCS_ARBDIS 0x00000040 /* Arbitration disable bit */ | ||
68 | |||
69 | /* RTTDT2C Bit Masks */ | ||
70 | #define IXGBE_RTTDT2C_MCL_SHIFT 12 | ||
71 | #define IXGBE_RTTDT2C_BWG_SHIFT 9 | ||
72 | #define IXGBE_RTTDT2C_GSP 0x40000000 | ||
73 | #define IXGBE_RTTDT2C_LSP 0x80000000 | ||
74 | |||
75 | #define IXGBE_RTTPT2C_MCL_SHIFT 12 | ||
76 | #define IXGBE_RTTPT2C_BWG_SHIFT 9 | ||
77 | #define IXGBE_RTTPT2C_GSP 0x40000000 | ||
78 | #define IXGBE_RTTPT2C_LSP 0x80000000 | ||
79 | |||
80 | /* RTTPCS Bit Masks */ | ||
81 | #define IXGBE_RTTPCS_TPPAC 0x00000020 /* 0 Round Robin, | ||
82 | * 1 SP - Strict Priority | ||
83 | */ | ||
84 | #define IXGBE_RTTPCS_ARBDIS 0x00000040 /* Arbiter disable */ | ||
85 | #define IXGBE_RTTPCS_TPRM 0x00000100 /* Transmit Recycle Mode enable */ | ||
86 | #define IXGBE_RTTPCS_ARBD_SHIFT 22 | ||
87 | #define IXGBE_RTTPCS_ARBD_DCB 0x4 /* Arbitration delay in DCB mode */ | ||
88 | |||
89 | /* SECTXMINIFG DCB */ | ||
90 | #define IXGBE_SECTX_DCB 0x00001F00 /* DCB TX Buffer IFG */ | ||
91 | |||
92 | |||
93 | /* DCB hardware-specific driver APIs */ | ||
94 | |||
95 | /* DCB PFC functions */ | ||
96 | s32 ixgbe_dcb_config_pfc_82599(struct ixgbe_hw *hw, u8 pfc_en); | ||
97 | |||
98 | /* DCB hw initialization */ | ||
99 | s32 ixgbe_dcb_config_rx_arbiter_82599(struct ixgbe_hw *hw, | ||
100 | u16 *refill, | ||
101 | u16 *max, | ||
102 | u8 *bwg_id, | ||
103 | u8 *prio_type, | ||
104 | u8 *prio_tc); | ||
105 | |||
106 | s32 ixgbe_dcb_config_tx_desc_arbiter_82599(struct ixgbe_hw *hw, | ||
107 | u16 *refill, | ||
108 | u16 *max, | ||
109 | u8 *bwg_id, | ||
110 | u8 *prio_type); | ||
111 | |||
112 | s32 ixgbe_dcb_config_tx_data_arbiter_82599(struct ixgbe_hw *hw, | ||
113 | u16 *refill, | ||
114 | u16 *max, | ||
115 | u8 *bwg_id, | ||
116 | u8 *prio_type, | ||
117 | u8 *prio_tc); | ||
118 | |||
119 | s32 ixgbe_dcb_hw_config_82599(struct ixgbe_hw *hw, u8 pfc_en, u16 *refill, | ||
120 | u16 *max, u8 *bwg_id, u8 *prio_type, | ||
121 | u8 *prio_tc); | ||
122 | |||
123 | #endif /* _DCB_82599_CONFIG_H */ | ||
diff --git a/drivers/net/ixgbe/ixgbe_dcb_nl.c b/drivers/net/ixgbe/ixgbe_dcb_nl.c new file mode 100644 index 00000000000..0ace6ce1d0b --- /dev/null +++ b/drivers/net/ixgbe/ixgbe_dcb_nl.c | |||
@@ -0,0 +1,816 @@ | |||
1 | /******************************************************************************* | ||
2 | |||
3 | Intel 10 Gigabit PCI Express Linux driver | ||
4 | Copyright(c) 1999 - 2011 Intel Corporation. | ||
5 | |||
6 | This program is free software; you can redistribute it and/or modify it | ||
7 | under the terms and conditions of the GNU General Public License, | ||
8 | version 2, as published by the Free Software Foundation. | ||
9 | |||
10 | This program is distributed in the hope it will be useful, but WITHOUT | ||
11 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
12 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
13 | more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License along with | ||
16 | this program; if not, write to the Free Software Foundation, Inc., | ||
17 | 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. | ||
18 | |||
19 | The full GNU General Public License is included in this distribution in | ||
20 | the file called "COPYING". | ||
21 | |||
22 | Contact Information: | ||
23 | Linux NICS <linux.nics@intel.com> | ||
24 | e1000-devel Mailing List <e1000-devel@lists.sourceforge.net> | ||
25 | Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 | ||
26 | |||
27 | *******************************************************************************/ | ||
28 | |||
29 | #include "ixgbe.h" | ||
30 | #include <linux/dcbnl.h> | ||
31 | #include "ixgbe_dcb_82598.h" | ||
32 | #include "ixgbe_dcb_82599.h" | ||
33 | |||
34 | /* Callbacks for DCB netlink in the kernel */ | ||
35 | #define BIT_DCB_MODE 0x01 | ||
36 | #define BIT_PFC 0x02 | ||
37 | #define BIT_PG_RX 0x04 | ||
38 | #define BIT_PG_TX 0x08 | ||
39 | #define BIT_APP_UPCHG 0x10 | ||
40 | #define BIT_LINKSPEED 0x80 | ||
41 | |||
42 | /* Responses for the DCB_C_SET_ALL command */ | ||
43 | #define DCB_HW_CHG_RST 0 /* DCB configuration changed with reset */ | ||
44 | #define DCB_NO_HW_CHG 1 /* DCB configuration did not change */ | ||
45 | #define DCB_HW_CHG 2 /* DCB configuration changed, no reset */ | ||
46 | |||
47 | int ixgbe_copy_dcb_cfg(struct ixgbe_dcb_config *src_dcb_cfg, | ||
48 | struct ixgbe_dcb_config *dst_dcb_cfg, int tc_max) | ||
49 | { | ||
50 | struct tc_configuration *src_tc_cfg = NULL; | ||
51 | struct tc_configuration *dst_tc_cfg = NULL; | ||
52 | int i; | ||
53 | |||
54 | if (!src_dcb_cfg || !dst_dcb_cfg) | ||
55 | return -EINVAL; | ||
56 | |||
57 | for (i = DCB_PG_ATTR_TC_0; i < tc_max + DCB_PG_ATTR_TC_0; i++) { | ||
58 | src_tc_cfg = &src_dcb_cfg->tc_config[i - DCB_PG_ATTR_TC_0]; | ||
59 | dst_tc_cfg = &dst_dcb_cfg->tc_config[i - DCB_PG_ATTR_TC_0]; | ||
60 | |||
61 | dst_tc_cfg->path[DCB_TX_CONFIG].prio_type = | ||
62 | src_tc_cfg->path[DCB_TX_CONFIG].prio_type; | ||
63 | |||
64 | dst_tc_cfg->path[DCB_TX_CONFIG].bwg_id = | ||
65 | src_tc_cfg->path[DCB_TX_CONFIG].bwg_id; | ||
66 | |||
67 | dst_tc_cfg->path[DCB_TX_CONFIG].bwg_percent = | ||
68 | src_tc_cfg->path[DCB_TX_CONFIG].bwg_percent; | ||
69 | |||
70 | dst_tc_cfg->path[DCB_TX_CONFIG].up_to_tc_bitmap = | ||
71 | src_tc_cfg->path[DCB_TX_CONFIG].up_to_tc_bitmap; | ||
72 | |||
73 | dst_tc_cfg->path[DCB_RX_CONFIG].prio_type = | ||
74 | src_tc_cfg->path[DCB_RX_CONFIG].prio_type; | ||
75 | |||
76 | dst_tc_cfg->path[DCB_RX_CONFIG].bwg_id = | ||
77 | src_tc_cfg->path[DCB_RX_CONFIG].bwg_id; | ||
78 | |||
79 | dst_tc_cfg->path[DCB_RX_CONFIG].bwg_percent = | ||
80 | src_tc_cfg->path[DCB_RX_CONFIG].bwg_percent; | ||
81 | |||
82 | dst_tc_cfg->path[DCB_RX_CONFIG].up_to_tc_bitmap = | ||
83 | src_tc_cfg->path[DCB_RX_CONFIG].up_to_tc_bitmap; | ||
84 | } | ||
85 | |||
86 | for (i = DCB_PG_ATTR_BW_ID_0; i < DCB_PG_ATTR_BW_ID_MAX; i++) { | ||
87 | dst_dcb_cfg->bw_percentage[DCB_TX_CONFIG] | ||
88 | [i-DCB_PG_ATTR_BW_ID_0] = src_dcb_cfg->bw_percentage | ||
89 | [DCB_TX_CONFIG][i-DCB_PG_ATTR_BW_ID_0]; | ||
90 | dst_dcb_cfg->bw_percentage[DCB_RX_CONFIG] | ||
91 | [i-DCB_PG_ATTR_BW_ID_0] = src_dcb_cfg->bw_percentage | ||
92 | [DCB_RX_CONFIG][i-DCB_PG_ATTR_BW_ID_0]; | ||
93 | } | ||
94 | |||
95 | for (i = DCB_PFC_UP_ATTR_0; i < DCB_PFC_UP_ATTR_MAX; i++) { | ||
96 | dst_dcb_cfg->tc_config[i - DCB_PFC_UP_ATTR_0].dcb_pfc = | ||
97 | src_dcb_cfg->tc_config[i - DCB_PFC_UP_ATTR_0].dcb_pfc; | ||
98 | } | ||
99 | |||
100 | dst_dcb_cfg->pfc_mode_enable = src_dcb_cfg->pfc_mode_enable; | ||
101 | |||
102 | return 0; | ||
103 | } | ||
104 | |||
105 | static u8 ixgbe_dcbnl_get_state(struct net_device *netdev) | ||
106 | { | ||
107 | struct ixgbe_adapter *adapter = netdev_priv(netdev); | ||
108 | |||
109 | return !!(adapter->flags & IXGBE_FLAG_DCB_ENABLED); | ||
110 | } | ||
111 | |||
112 | static u8 ixgbe_dcbnl_set_state(struct net_device *netdev, u8 state) | ||
113 | { | ||
114 | u8 err = 0; | ||
115 | struct ixgbe_adapter *adapter = netdev_priv(netdev); | ||
116 | |||
117 | /* verify there is something to do, if not then exit */ | ||
118 | if (!!state != !(adapter->flags & IXGBE_FLAG_DCB_ENABLED)) | ||
119 | return err; | ||
120 | |||
121 | if (state > 0) { | ||
122 | /* Turn on DCB */ | ||
123 | if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) { | ||
124 | e_err(drv, "Enable failed, needs MSI-X\n"); | ||
125 | err = 1; | ||
126 | goto out; | ||
127 | } | ||
128 | |||
129 | adapter->flags |= IXGBE_FLAG_DCB_ENABLED; | ||
130 | |||
131 | switch (adapter->hw.mac.type) { | ||
132 | case ixgbe_mac_82598EB: | ||
133 | adapter->last_lfc_mode = adapter->hw.fc.current_mode; | ||
134 | adapter->hw.fc.requested_mode = ixgbe_fc_none; | ||
135 | break; | ||
136 | case ixgbe_mac_82599EB: | ||
137 | case ixgbe_mac_X540: | ||
138 | adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE; | ||
139 | break; | ||
140 | default: | ||
141 | break; | ||
142 | } | ||
143 | |||
144 | ixgbe_setup_tc(netdev, MAX_TRAFFIC_CLASS); | ||
145 | } else { | ||
146 | /* Turn off DCB */ | ||
147 | adapter->hw.fc.requested_mode = adapter->last_lfc_mode; | ||
148 | adapter->temp_dcb_cfg.pfc_mode_enable = false; | ||
149 | adapter->dcb_cfg.pfc_mode_enable = false; | ||
150 | adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED; | ||
151 | switch (adapter->hw.mac.type) { | ||
152 | case ixgbe_mac_82599EB: | ||
153 | case ixgbe_mac_X540: | ||
154 | if (!(adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)) | ||
155 | adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE; | ||
156 | break; | ||
157 | default: | ||
158 | break; | ||
159 | } | ||
160 | ixgbe_setup_tc(netdev, 0); | ||
161 | } | ||
162 | |||
163 | out: | ||
164 | return err; | ||
165 | } | ||
166 | |||
167 | static void ixgbe_dcbnl_get_perm_hw_addr(struct net_device *netdev, | ||
168 | u8 *perm_addr) | ||
169 | { | ||
170 | struct ixgbe_adapter *adapter = netdev_priv(netdev); | ||
171 | int i, j; | ||
172 | |||
173 | memset(perm_addr, 0xff, MAX_ADDR_LEN); | ||
174 | |||
175 | for (i = 0; i < netdev->addr_len; i++) | ||
176 | perm_addr[i] = adapter->hw.mac.perm_addr[i]; | ||
177 | |||
178 | switch (adapter->hw.mac.type) { | ||
179 | case ixgbe_mac_82599EB: | ||
180 | case ixgbe_mac_X540: | ||
181 | for (j = 0; j < netdev->addr_len; j++, i++) | ||
182 | perm_addr[i] = adapter->hw.mac.san_addr[j]; | ||
183 | break; | ||
184 | default: | ||
185 | break; | ||
186 | } | ||
187 | } | ||
188 | |||
189 | static void ixgbe_dcbnl_set_pg_tc_cfg_tx(struct net_device *netdev, int tc, | ||
190 | u8 prio, u8 bwg_id, u8 bw_pct, | ||
191 | u8 up_map) | ||
192 | { | ||
193 | struct ixgbe_adapter *adapter = netdev_priv(netdev); | ||
194 | |||
195 | if (prio != DCB_ATTR_VALUE_UNDEFINED) | ||
196 | adapter->temp_dcb_cfg.tc_config[tc].path[0].prio_type = prio; | ||
197 | if (bwg_id != DCB_ATTR_VALUE_UNDEFINED) | ||
198 | adapter->temp_dcb_cfg.tc_config[tc].path[0].bwg_id = bwg_id; | ||
199 | if (bw_pct != DCB_ATTR_VALUE_UNDEFINED) | ||
200 | adapter->temp_dcb_cfg.tc_config[tc].path[0].bwg_percent = | ||
201 | bw_pct; | ||
202 | if (up_map != DCB_ATTR_VALUE_UNDEFINED) | ||
203 | adapter->temp_dcb_cfg.tc_config[tc].path[0].up_to_tc_bitmap = | ||
204 | up_map; | ||
205 | |||
206 | if ((adapter->temp_dcb_cfg.tc_config[tc].path[0].prio_type != | ||
207 | adapter->dcb_cfg.tc_config[tc].path[0].prio_type) || | ||
208 | (adapter->temp_dcb_cfg.tc_config[tc].path[0].bwg_id != | ||
209 | adapter->dcb_cfg.tc_config[tc].path[0].bwg_id) || | ||
210 | (adapter->temp_dcb_cfg.tc_config[tc].path[0].bwg_percent != | ||
211 | adapter->dcb_cfg.tc_config[tc].path[0].bwg_percent) || | ||
212 | (adapter->temp_dcb_cfg.tc_config[tc].path[0].up_to_tc_bitmap != | ||
213 | adapter->dcb_cfg.tc_config[tc].path[0].up_to_tc_bitmap)) | ||
214 | adapter->dcb_set_bitmap |= BIT_PG_TX; | ||
215 | } | ||
216 | |||
217 | static void ixgbe_dcbnl_set_pg_bwg_cfg_tx(struct net_device *netdev, int bwg_id, | ||
218 | u8 bw_pct) | ||
219 | { | ||
220 | struct ixgbe_adapter *adapter = netdev_priv(netdev); | ||
221 | |||
222 | adapter->temp_dcb_cfg.bw_percentage[0][bwg_id] = bw_pct; | ||
223 | |||
224 | if (adapter->temp_dcb_cfg.bw_percentage[0][bwg_id] != | ||
225 | adapter->dcb_cfg.bw_percentage[0][bwg_id]) | ||
226 | adapter->dcb_set_bitmap |= BIT_PG_TX; | ||
227 | } | ||
228 | |||
229 | static void ixgbe_dcbnl_set_pg_tc_cfg_rx(struct net_device *netdev, int tc, | ||
230 | u8 prio, u8 bwg_id, u8 bw_pct, | ||
231 | u8 up_map) | ||
232 | { | ||
233 | struct ixgbe_adapter *adapter = netdev_priv(netdev); | ||
234 | |||
235 | if (prio != DCB_ATTR_VALUE_UNDEFINED) | ||
236 | adapter->temp_dcb_cfg.tc_config[tc].path[1].prio_type = prio; | ||
237 | if (bwg_id != DCB_ATTR_VALUE_UNDEFINED) | ||
238 | adapter->temp_dcb_cfg.tc_config[tc].path[1].bwg_id = bwg_id; | ||
239 | if (bw_pct != DCB_ATTR_VALUE_UNDEFINED) | ||
240 | adapter->temp_dcb_cfg.tc_config[tc].path[1].bwg_percent = | ||
241 | bw_pct; | ||
242 | if (up_map != DCB_ATTR_VALUE_UNDEFINED) | ||
243 | adapter->temp_dcb_cfg.tc_config[tc].path[1].up_to_tc_bitmap = | ||
244 | up_map; | ||
245 | |||
246 | if ((adapter->temp_dcb_cfg.tc_config[tc].path[1].prio_type != | ||
247 | adapter->dcb_cfg.tc_config[tc].path[1].prio_type) || | ||
248 | (adapter->temp_dcb_cfg.tc_config[tc].path[1].bwg_id != | ||
249 | adapter->dcb_cfg.tc_config[tc].path[1].bwg_id) || | ||
250 | (adapter->temp_dcb_cfg.tc_config[tc].path[1].bwg_percent != | ||
251 | adapter->dcb_cfg.tc_config[tc].path[1].bwg_percent) || | ||
252 | (adapter->temp_dcb_cfg.tc_config[tc].path[1].up_to_tc_bitmap != | ||
253 | adapter->dcb_cfg.tc_config[tc].path[1].up_to_tc_bitmap)) | ||
254 | adapter->dcb_set_bitmap |= BIT_PG_RX; | ||
255 | } | ||
256 | |||
257 | static void ixgbe_dcbnl_set_pg_bwg_cfg_rx(struct net_device *netdev, int bwg_id, | ||
258 | u8 bw_pct) | ||
259 | { | ||
260 | struct ixgbe_adapter *adapter = netdev_priv(netdev); | ||
261 | |||
262 | adapter->temp_dcb_cfg.bw_percentage[1][bwg_id] = bw_pct; | ||
263 | |||
264 | if (adapter->temp_dcb_cfg.bw_percentage[1][bwg_id] != | ||
265 | adapter->dcb_cfg.bw_percentage[1][bwg_id]) | ||
266 | adapter->dcb_set_bitmap |= BIT_PG_RX; | ||
267 | } | ||
268 | |||
269 | static void ixgbe_dcbnl_get_pg_tc_cfg_tx(struct net_device *netdev, int tc, | ||
270 | u8 *prio, u8 *bwg_id, u8 *bw_pct, | ||
271 | u8 *up_map) | ||
272 | { | ||
273 | struct ixgbe_adapter *adapter = netdev_priv(netdev); | ||
274 | |||
275 | *prio = adapter->dcb_cfg.tc_config[tc].path[0].prio_type; | ||
276 | *bwg_id = adapter->dcb_cfg.tc_config[tc].path[0].bwg_id; | ||
277 | *bw_pct = adapter->dcb_cfg.tc_config[tc].path[0].bwg_percent; | ||
278 | *up_map = adapter->dcb_cfg.tc_config[tc].path[0].up_to_tc_bitmap; | ||
279 | } | ||
280 | |||
281 | static void ixgbe_dcbnl_get_pg_bwg_cfg_tx(struct net_device *netdev, int bwg_id, | ||
282 | u8 *bw_pct) | ||
283 | { | ||
284 | struct ixgbe_adapter *adapter = netdev_priv(netdev); | ||
285 | |||
286 | *bw_pct = adapter->dcb_cfg.bw_percentage[0][bwg_id]; | ||
287 | } | ||
288 | |||
289 | static void ixgbe_dcbnl_get_pg_tc_cfg_rx(struct net_device *netdev, int tc, | ||
290 | u8 *prio, u8 *bwg_id, u8 *bw_pct, | ||
291 | u8 *up_map) | ||
292 | { | ||
293 | struct ixgbe_adapter *adapter = netdev_priv(netdev); | ||
294 | |||
295 | *prio = adapter->dcb_cfg.tc_config[tc].path[1].prio_type; | ||
296 | *bwg_id = adapter->dcb_cfg.tc_config[tc].path[1].bwg_id; | ||
297 | *bw_pct = adapter->dcb_cfg.tc_config[tc].path[1].bwg_percent; | ||
298 | *up_map = adapter->dcb_cfg.tc_config[tc].path[1].up_to_tc_bitmap; | ||
299 | } | ||
300 | |||
301 | static void ixgbe_dcbnl_get_pg_bwg_cfg_rx(struct net_device *netdev, int bwg_id, | ||
302 | u8 *bw_pct) | ||
303 | { | ||
304 | struct ixgbe_adapter *adapter = netdev_priv(netdev); | ||
305 | |||
306 | *bw_pct = adapter->dcb_cfg.bw_percentage[1][bwg_id]; | ||
307 | } | ||
308 | |||
309 | static void ixgbe_dcbnl_set_pfc_cfg(struct net_device *netdev, int priority, | ||
310 | u8 setting) | ||
311 | { | ||
312 | struct ixgbe_adapter *adapter = netdev_priv(netdev); | ||
313 | |||
314 | adapter->temp_dcb_cfg.tc_config[priority].dcb_pfc = setting; | ||
315 | if (adapter->temp_dcb_cfg.tc_config[priority].dcb_pfc != | ||
316 | adapter->dcb_cfg.tc_config[priority].dcb_pfc) { | ||
317 | adapter->dcb_set_bitmap |= BIT_PFC; | ||
318 | adapter->temp_dcb_cfg.pfc_mode_enable = true; | ||
319 | } | ||
320 | } | ||
321 | |||
322 | static void ixgbe_dcbnl_get_pfc_cfg(struct net_device *netdev, int priority, | ||
323 | u8 *setting) | ||
324 | { | ||
325 | struct ixgbe_adapter *adapter = netdev_priv(netdev); | ||
326 | |||
327 | *setting = adapter->dcb_cfg.tc_config[priority].dcb_pfc; | ||
328 | } | ||
329 | |||
330 | static u8 ixgbe_dcbnl_set_all(struct net_device *netdev) | ||
331 | { | ||
332 | struct ixgbe_adapter *adapter = netdev_priv(netdev); | ||
333 | int ret; | ||
334 | #ifdef IXGBE_FCOE | ||
335 | struct dcb_app app = { | ||
336 | .selector = DCB_APP_IDTYPE_ETHTYPE, | ||
337 | .protocol = ETH_P_FCOE, | ||
338 | }; | ||
339 | u8 up = dcb_getapp(netdev, &app); | ||
340 | #endif | ||
341 | |||
342 | ret = ixgbe_copy_dcb_cfg(&adapter->temp_dcb_cfg, &adapter->dcb_cfg, | ||
343 | MAX_TRAFFIC_CLASS); | ||
344 | if (ret) | ||
345 | return DCB_NO_HW_CHG; | ||
346 | |||
347 | #ifdef IXGBE_FCOE | ||
348 | if (up && (up != (1 << adapter->fcoe.up))) | ||
349 | adapter->dcb_set_bitmap |= BIT_APP_UPCHG; | ||
350 | |||
351 | /* | ||
352 | * Only take down the adapter if an app change occurred. FCoE | ||
353 | * may shuffle tx rings in this case and this can not be done | ||
354 | * without a reset currently. | ||
355 | */ | ||
356 | if (adapter->dcb_set_bitmap & BIT_APP_UPCHG) { | ||
357 | while (test_and_set_bit(__IXGBE_RESETTING, &adapter->state)) | ||
358 | usleep_range(1000, 2000); | ||
359 | |||
360 | adapter->fcoe.up = ffs(up) - 1; | ||
361 | |||
362 | if (netif_running(netdev)) | ||
363 | netdev->netdev_ops->ndo_stop(netdev); | ||
364 | ixgbe_clear_interrupt_scheme(adapter); | ||
365 | } | ||
366 | #endif | ||
367 | |||
368 | if (adapter->dcb_cfg.pfc_mode_enable) { | ||
369 | switch (adapter->hw.mac.type) { | ||
370 | case ixgbe_mac_82599EB: | ||
371 | case ixgbe_mac_X540: | ||
372 | if (adapter->hw.fc.current_mode != ixgbe_fc_pfc) | ||
373 | adapter->last_lfc_mode = | ||
374 | adapter->hw.fc.current_mode; | ||
375 | break; | ||
376 | default: | ||
377 | break; | ||
378 | } | ||
379 | adapter->hw.fc.requested_mode = ixgbe_fc_pfc; | ||
380 | } else { | ||
381 | switch (adapter->hw.mac.type) { | ||
382 | case ixgbe_mac_82598EB: | ||
383 | adapter->hw.fc.requested_mode = ixgbe_fc_none; | ||
384 | break; | ||
385 | case ixgbe_mac_82599EB: | ||
386 | case ixgbe_mac_X540: | ||
387 | adapter->hw.fc.requested_mode = adapter->last_lfc_mode; | ||
388 | break; | ||
389 | default: | ||
390 | break; | ||
391 | } | ||
392 | } | ||
393 | |||
394 | #ifdef IXGBE_FCOE | ||
395 | if (adapter->dcb_set_bitmap & BIT_APP_UPCHG) { | ||
396 | ixgbe_init_interrupt_scheme(adapter); | ||
397 | if (netif_running(netdev)) | ||
398 | netdev->netdev_ops->ndo_open(netdev); | ||
399 | ret = DCB_HW_CHG_RST; | ||
400 | } | ||
401 | #endif | ||
402 | |||
403 | if (adapter->dcb_set_bitmap & BIT_PFC) { | ||
404 | u8 pfc_en; | ||
405 | ixgbe_dcb_unpack_pfc(&adapter->dcb_cfg, &pfc_en); | ||
406 | ixgbe_dcb_hw_pfc_config(&adapter->hw, pfc_en); | ||
407 | ret = DCB_HW_CHG; | ||
408 | } | ||
409 | |||
410 | if (adapter->dcb_set_bitmap & (BIT_PG_TX|BIT_PG_RX)) { | ||
411 | u16 refill[MAX_TRAFFIC_CLASS], max[MAX_TRAFFIC_CLASS]; | ||
412 | u8 bwg_id[MAX_TRAFFIC_CLASS], prio_type[MAX_TRAFFIC_CLASS]; | ||
413 | /* Priority to TC mapping in CEE case default to 1:1 */ | ||
414 | u8 prio_tc[MAX_TRAFFIC_CLASS] = {0, 1, 2, 3, 4, 5, 6, 7}; | ||
415 | int max_frame = adapter->netdev->mtu + ETH_HLEN + ETH_FCS_LEN; | ||
416 | |||
417 | #ifdef CONFIG_FCOE | ||
418 | if (adapter->netdev->features & NETIF_F_FCOE_MTU) | ||
419 | max_frame = max(max_frame, IXGBE_FCOE_JUMBO_FRAME_SIZE); | ||
420 | #endif | ||
421 | |||
422 | ixgbe_dcb_calculate_tc_credits(&adapter->hw, &adapter->dcb_cfg, | ||
423 | max_frame, DCB_TX_CONFIG); | ||
424 | ixgbe_dcb_calculate_tc_credits(&adapter->hw, &adapter->dcb_cfg, | ||
425 | max_frame, DCB_RX_CONFIG); | ||
426 | |||
427 | ixgbe_dcb_unpack_refill(&adapter->dcb_cfg, | ||
428 | DCB_TX_CONFIG, refill); | ||
429 | ixgbe_dcb_unpack_max(&adapter->dcb_cfg, max); | ||
430 | ixgbe_dcb_unpack_bwgid(&adapter->dcb_cfg, | ||
431 | DCB_TX_CONFIG, bwg_id); | ||
432 | ixgbe_dcb_unpack_prio(&adapter->dcb_cfg, | ||
433 | DCB_TX_CONFIG, prio_type); | ||
434 | |||
435 | ixgbe_dcb_hw_ets_config(&adapter->hw, refill, max, | ||
436 | bwg_id, prio_type, prio_tc); | ||
437 | } | ||
438 | |||
439 | if (adapter->dcb_cfg.pfc_mode_enable) | ||
440 | adapter->hw.fc.current_mode = ixgbe_fc_pfc; | ||
441 | |||
442 | if (adapter->dcb_set_bitmap & BIT_APP_UPCHG) | ||
443 | clear_bit(__IXGBE_RESETTING, &adapter->state); | ||
444 | adapter->dcb_set_bitmap = 0x00; | ||
445 | return ret; | ||
446 | } | ||
447 | |||
448 | static u8 ixgbe_dcbnl_getcap(struct net_device *netdev, int capid, u8 *cap) | ||
449 | { | ||
450 | struct ixgbe_adapter *adapter = netdev_priv(netdev); | ||
451 | |||
452 | switch (capid) { | ||
453 | case DCB_CAP_ATTR_PG: | ||
454 | *cap = true; | ||
455 | break; | ||
456 | case DCB_CAP_ATTR_PFC: | ||
457 | *cap = true; | ||
458 | break; | ||
459 | case DCB_CAP_ATTR_UP2TC: | ||
460 | *cap = false; | ||
461 | break; | ||
462 | case DCB_CAP_ATTR_PG_TCS: | ||
463 | *cap = 0x80; | ||
464 | break; | ||
465 | case DCB_CAP_ATTR_PFC_TCS: | ||
466 | *cap = 0x80; | ||
467 | break; | ||
468 | case DCB_CAP_ATTR_GSP: | ||
469 | *cap = true; | ||
470 | break; | ||
471 | case DCB_CAP_ATTR_BCN: | ||
472 | *cap = false; | ||
473 | break; | ||
474 | case DCB_CAP_ATTR_DCBX: | ||
475 | *cap = adapter->dcbx_cap; | ||
476 | break; | ||
477 | default: | ||
478 | *cap = false; | ||
479 | break; | ||
480 | } | ||
481 | |||
482 | return 0; | ||
483 | } | ||
484 | |||
485 | static u8 ixgbe_dcbnl_getnumtcs(struct net_device *netdev, int tcid, u8 *num) | ||
486 | { | ||
487 | struct ixgbe_adapter *adapter = netdev_priv(netdev); | ||
488 | u8 rval = 0; | ||
489 | |||
490 | if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) { | ||
491 | switch (tcid) { | ||
492 | case DCB_NUMTCS_ATTR_PG: | ||
493 | *num = MAX_TRAFFIC_CLASS; | ||
494 | break; | ||
495 | case DCB_NUMTCS_ATTR_PFC: | ||
496 | *num = MAX_TRAFFIC_CLASS; | ||
497 | break; | ||
498 | default: | ||
499 | rval = -EINVAL; | ||
500 | break; | ||
501 | } | ||
502 | } else { | ||
503 | rval = -EINVAL; | ||
504 | } | ||
505 | |||
506 | return rval; | ||
507 | } | ||
508 | |||
509 | static u8 ixgbe_dcbnl_setnumtcs(struct net_device *netdev, int tcid, u8 num) | ||
510 | { | ||
511 | return -EINVAL; | ||
512 | } | ||
513 | |||
514 | static u8 ixgbe_dcbnl_getpfcstate(struct net_device *netdev) | ||
515 | { | ||
516 | struct ixgbe_adapter *adapter = netdev_priv(netdev); | ||
517 | |||
518 | return adapter->dcb_cfg.pfc_mode_enable; | ||
519 | } | ||
520 | |||
521 | static void ixgbe_dcbnl_setpfcstate(struct net_device *netdev, u8 state) | ||
522 | { | ||
523 | struct ixgbe_adapter *adapter = netdev_priv(netdev); | ||
524 | |||
525 | adapter->temp_dcb_cfg.pfc_mode_enable = state; | ||
526 | if (adapter->temp_dcb_cfg.pfc_mode_enable != | ||
527 | adapter->dcb_cfg.pfc_mode_enable) | ||
528 | adapter->dcb_set_bitmap |= BIT_PFC; | ||
529 | } | ||
530 | |||
531 | /** | ||
532 | * ixgbe_dcbnl_getapp - retrieve the DCBX application user priority | ||
533 | * @netdev : the corresponding netdev | ||
534 | * @idtype : identifies the id as ether type or TCP/UDP port number | ||
535 | * @id: id is either ether type or TCP/UDP port number | ||
536 | * | ||
537 | * Returns : on success, returns a non-zero 802.1p user priority bitmap | ||
538 | * otherwise returns 0 as the invalid user priority bitmap to indicate an | ||
539 | * error. | ||
540 | */ | ||
541 | static u8 ixgbe_dcbnl_getapp(struct net_device *netdev, u8 idtype, u16 id) | ||
542 | { | ||
543 | struct ixgbe_adapter *adapter = netdev_priv(netdev); | ||
544 | struct dcb_app app = { | ||
545 | .selector = idtype, | ||
546 | .protocol = id, | ||
547 | }; | ||
548 | |||
549 | if (!(adapter->dcbx_cap & DCB_CAP_DCBX_VER_CEE)) | ||
550 | return 0; | ||
551 | |||
552 | return dcb_getapp(netdev, &app); | ||
553 | } | ||
554 | |||
555 | static int ixgbe_dcbnl_ieee_getets(struct net_device *dev, | ||
556 | struct ieee_ets *ets) | ||
557 | { | ||
558 | struct ixgbe_adapter *adapter = netdev_priv(dev); | ||
559 | struct ieee_ets *my_ets = adapter->ixgbe_ieee_ets; | ||
560 | |||
561 | /* No IEEE PFC settings available */ | ||
562 | if (!my_ets) | ||
563 | return -EINVAL; | ||
564 | |||
565 | ets->ets_cap = MAX_TRAFFIC_CLASS; | ||
566 | ets->cbs = my_ets->cbs; | ||
567 | memcpy(ets->tc_tx_bw, my_ets->tc_tx_bw, sizeof(ets->tc_tx_bw)); | ||
568 | memcpy(ets->tc_rx_bw, my_ets->tc_rx_bw, sizeof(ets->tc_rx_bw)); | ||
569 | memcpy(ets->tc_tsa, my_ets->tc_tsa, sizeof(ets->tc_tsa)); | ||
570 | memcpy(ets->prio_tc, my_ets->prio_tc, sizeof(ets->prio_tc)); | ||
571 | return 0; | ||
572 | } | ||
573 | |||
574 | static int ixgbe_dcbnl_ieee_setets(struct net_device *dev, | ||
575 | struct ieee_ets *ets) | ||
576 | { | ||
577 | struct ixgbe_adapter *adapter = netdev_priv(dev); | ||
578 | __u16 refill[IEEE_8021QAZ_MAX_TCS], max[IEEE_8021QAZ_MAX_TCS]; | ||
579 | __u8 prio_type[IEEE_8021QAZ_MAX_TCS]; | ||
580 | int max_frame = dev->mtu + ETH_HLEN + ETH_FCS_LEN; | ||
581 | int i, err; | ||
582 | __u64 *p = (__u64 *) ets->prio_tc; | ||
583 | /* naively give each TC a bwg to map onto CEE hardware */ | ||
584 | __u8 bwg_id[IEEE_8021QAZ_MAX_TCS] = {0, 1, 2, 3, 4, 5, 6, 7}; | ||
585 | |||
586 | if (!(adapter->dcbx_cap & DCB_CAP_DCBX_VER_IEEE)) | ||
587 | return -EINVAL; | ||
588 | |||
589 | if (!adapter->ixgbe_ieee_ets) { | ||
590 | adapter->ixgbe_ieee_ets = kmalloc(sizeof(struct ieee_ets), | ||
591 | GFP_KERNEL); | ||
592 | if (!adapter->ixgbe_ieee_ets) | ||
593 | return -ENOMEM; | ||
594 | } | ||
595 | |||
596 | memcpy(adapter->ixgbe_ieee_ets, ets, sizeof(*adapter->ixgbe_ieee_ets)); | ||
597 | |||
598 | /* Map TSA onto CEE prio type */ | ||
599 | for (i = 0; i < IEEE_8021QAZ_MAX_TCS; i++) { | ||
600 | switch (ets->tc_tsa[i]) { | ||
601 | case IEEE_8021QAZ_TSA_STRICT: | ||
602 | prio_type[i] = 2; | ||
603 | break; | ||
604 | case IEEE_8021QAZ_TSA_ETS: | ||
605 | prio_type[i] = 0; | ||
606 | break; | ||
607 | default: | ||
608 | /* Hardware only supports priority strict or | ||
609 | * ETS transmission selection algorithms if | ||
610 | * we receive some other value from dcbnl | ||
611 | * throw an error | ||
612 | */ | ||
613 | return -EINVAL; | ||
614 | } | ||
615 | } | ||
616 | |||
617 | if (*p) | ||
618 | ixgbe_dcbnl_set_state(dev, 1); | ||
619 | else | ||
620 | ixgbe_dcbnl_set_state(dev, 0); | ||
621 | |||
622 | ixgbe_ieee_credits(ets->tc_tx_bw, refill, max, max_frame); | ||
623 | err = ixgbe_dcb_hw_ets_config(&adapter->hw, refill, max, | ||
624 | bwg_id, prio_type, ets->prio_tc); | ||
625 | return err; | ||
626 | } | ||
627 | |||
628 | static int ixgbe_dcbnl_ieee_getpfc(struct net_device *dev, | ||
629 | struct ieee_pfc *pfc) | ||
630 | { | ||
631 | struct ixgbe_adapter *adapter = netdev_priv(dev); | ||
632 | struct ieee_pfc *my_pfc = adapter->ixgbe_ieee_pfc; | ||
633 | int i; | ||
634 | |||
635 | /* No IEEE PFC settings available */ | ||
636 | if (!my_pfc) | ||
637 | return -EINVAL; | ||
638 | |||
639 | pfc->pfc_cap = MAX_TRAFFIC_CLASS; | ||
640 | pfc->pfc_en = my_pfc->pfc_en; | ||
641 | pfc->mbc = my_pfc->mbc; | ||
642 | pfc->delay = my_pfc->delay; | ||
643 | |||
644 | for (i = 0; i < MAX_TRAFFIC_CLASS; i++) { | ||
645 | pfc->requests[i] = adapter->stats.pxoffrxc[i]; | ||
646 | pfc->indications[i] = adapter->stats.pxofftxc[i]; | ||
647 | } | ||
648 | |||
649 | return 0; | ||
650 | } | ||
651 | |||
652 | static int ixgbe_dcbnl_ieee_setpfc(struct net_device *dev, | ||
653 | struct ieee_pfc *pfc) | ||
654 | { | ||
655 | struct ixgbe_adapter *adapter = netdev_priv(dev); | ||
656 | int err; | ||
657 | |||
658 | if (!(adapter->dcbx_cap & DCB_CAP_DCBX_VER_IEEE)) | ||
659 | return -EINVAL; | ||
660 | |||
661 | if (!adapter->ixgbe_ieee_pfc) { | ||
662 | adapter->ixgbe_ieee_pfc = kmalloc(sizeof(struct ieee_pfc), | ||
663 | GFP_KERNEL); | ||
664 | if (!adapter->ixgbe_ieee_pfc) | ||
665 | return -ENOMEM; | ||
666 | } | ||
667 | |||
668 | memcpy(adapter->ixgbe_ieee_pfc, pfc, sizeof(*adapter->ixgbe_ieee_pfc)); | ||
669 | err = ixgbe_dcb_hw_pfc_config(&adapter->hw, pfc->pfc_en); | ||
670 | return err; | ||
671 | } | ||
672 | |||
673 | #ifdef IXGBE_FCOE | ||
674 | static void ixgbe_dcbnl_devreset(struct net_device *dev) | ||
675 | { | ||
676 | struct ixgbe_adapter *adapter = netdev_priv(dev); | ||
677 | |||
678 | if (netif_running(dev)) | ||
679 | dev->netdev_ops->ndo_stop(dev); | ||
680 | |||
681 | ixgbe_clear_interrupt_scheme(adapter); | ||
682 | ixgbe_init_interrupt_scheme(adapter); | ||
683 | |||
684 | if (netif_running(dev)) | ||
685 | dev->netdev_ops->ndo_open(dev); | ||
686 | } | ||
687 | #endif | ||
688 | |||
689 | static int ixgbe_dcbnl_ieee_setapp(struct net_device *dev, | ||
690 | struct dcb_app *app) | ||
691 | { | ||
692 | struct ixgbe_adapter *adapter = netdev_priv(dev); | ||
693 | int err = -EINVAL; | ||
694 | |||
695 | if (!(adapter->dcbx_cap & DCB_CAP_DCBX_VER_IEEE)) | ||
696 | return err; | ||
697 | |||
698 | err = dcb_ieee_setapp(dev, app); | ||
699 | |||
700 | #ifdef IXGBE_FCOE | ||
701 | if (!err && app->selector == IEEE_8021QAZ_APP_SEL_ETHERTYPE && | ||
702 | app->protocol == ETH_P_FCOE) { | ||
703 | u8 app_mask = dcb_ieee_getapp_mask(dev, app); | ||
704 | |||
705 | if (app_mask & (1 << adapter->fcoe.up)) | ||
706 | return err; | ||
707 | |||
708 | adapter->fcoe.up = app->priority; | ||
709 | ixgbe_dcbnl_devreset(dev); | ||
710 | } | ||
711 | #endif | ||
712 | return 0; | ||
713 | } | ||
714 | |||
715 | static int ixgbe_dcbnl_ieee_delapp(struct net_device *dev, | ||
716 | struct dcb_app *app) | ||
717 | { | ||
718 | struct ixgbe_adapter *adapter = netdev_priv(dev); | ||
719 | int err; | ||
720 | |||
721 | if (!(adapter->dcbx_cap & DCB_CAP_DCBX_VER_IEEE)) | ||
722 | return -EINVAL; | ||
723 | |||
724 | err = dcb_ieee_delapp(dev, app); | ||
725 | |||
726 | #ifdef IXGBE_FCOE | ||
727 | if (!err && app->selector == IEEE_8021QAZ_APP_SEL_ETHERTYPE && | ||
728 | app->protocol == ETH_P_FCOE) { | ||
729 | u8 app_mask = dcb_ieee_getapp_mask(dev, app); | ||
730 | |||
731 | if (app_mask & (1 << adapter->fcoe.up)) | ||
732 | return err; | ||
733 | |||
734 | adapter->fcoe.up = app_mask ? | ||
735 | ffs(app_mask) - 1 : IXGBE_FCOE_DEFTC; | ||
736 | ixgbe_dcbnl_devreset(dev); | ||
737 | } | ||
738 | #endif | ||
739 | return err; | ||
740 | } | ||
741 | |||
742 | static u8 ixgbe_dcbnl_getdcbx(struct net_device *dev) | ||
743 | { | ||
744 | struct ixgbe_adapter *adapter = netdev_priv(dev); | ||
745 | return adapter->dcbx_cap; | ||
746 | } | ||
747 | |||
748 | static u8 ixgbe_dcbnl_setdcbx(struct net_device *dev, u8 mode) | ||
749 | { | ||
750 | struct ixgbe_adapter *adapter = netdev_priv(dev); | ||
751 | struct ieee_ets ets = {0}; | ||
752 | struct ieee_pfc pfc = {0}; | ||
753 | |||
754 | /* no support for LLD_MANAGED modes or CEE+IEEE */ | ||
755 | if ((mode & DCB_CAP_DCBX_LLD_MANAGED) || | ||
756 | ((mode & DCB_CAP_DCBX_VER_IEEE) && (mode & DCB_CAP_DCBX_VER_CEE)) || | ||
757 | !(mode & DCB_CAP_DCBX_HOST)) | ||
758 | return 1; | ||
759 | |||
760 | if (mode == adapter->dcbx_cap) | ||
761 | return 0; | ||
762 | |||
763 | adapter->dcbx_cap = mode; | ||
764 | |||
765 | /* ETS and PFC defaults */ | ||
766 | ets.ets_cap = 8; | ||
767 | pfc.pfc_cap = 8; | ||
768 | |||
769 | if (mode & DCB_CAP_DCBX_VER_IEEE) { | ||
770 | ixgbe_dcbnl_ieee_setets(dev, &ets); | ||
771 | ixgbe_dcbnl_ieee_setpfc(dev, &pfc); | ||
772 | } else if (mode & DCB_CAP_DCBX_VER_CEE) { | ||
773 | adapter->dcb_set_bitmap |= (BIT_PFC & BIT_PG_TX & BIT_PG_RX); | ||
774 | ixgbe_dcbnl_set_all(dev); | ||
775 | } else { | ||
776 | /* Drop into single TC mode strict priority as this | ||
777 | * indicates CEE and IEEE versions are disabled | ||
778 | */ | ||
779 | ixgbe_dcbnl_ieee_setets(dev, &ets); | ||
780 | ixgbe_dcbnl_ieee_setpfc(dev, &pfc); | ||
781 | ixgbe_dcbnl_set_state(dev, 0); | ||
782 | } | ||
783 | |||
784 | return 0; | ||
785 | } | ||
786 | |||
787 | const struct dcbnl_rtnl_ops dcbnl_ops = { | ||
788 | .ieee_getets = ixgbe_dcbnl_ieee_getets, | ||
789 | .ieee_setets = ixgbe_dcbnl_ieee_setets, | ||
790 | .ieee_getpfc = ixgbe_dcbnl_ieee_getpfc, | ||
791 | .ieee_setpfc = ixgbe_dcbnl_ieee_setpfc, | ||
792 | .ieee_setapp = ixgbe_dcbnl_ieee_setapp, | ||
793 | .ieee_delapp = ixgbe_dcbnl_ieee_delapp, | ||
794 | .getstate = ixgbe_dcbnl_get_state, | ||
795 | .setstate = ixgbe_dcbnl_set_state, | ||
796 | .getpermhwaddr = ixgbe_dcbnl_get_perm_hw_addr, | ||
797 | .setpgtccfgtx = ixgbe_dcbnl_set_pg_tc_cfg_tx, | ||
798 | .setpgbwgcfgtx = ixgbe_dcbnl_set_pg_bwg_cfg_tx, | ||
799 | .setpgtccfgrx = ixgbe_dcbnl_set_pg_tc_cfg_rx, | ||
800 | .setpgbwgcfgrx = ixgbe_dcbnl_set_pg_bwg_cfg_rx, | ||
801 | .getpgtccfgtx = ixgbe_dcbnl_get_pg_tc_cfg_tx, | ||
802 | .getpgbwgcfgtx = ixgbe_dcbnl_get_pg_bwg_cfg_tx, | ||
803 | .getpgtccfgrx = ixgbe_dcbnl_get_pg_tc_cfg_rx, | ||
804 | .getpgbwgcfgrx = ixgbe_dcbnl_get_pg_bwg_cfg_rx, | ||
805 | .setpfccfg = ixgbe_dcbnl_set_pfc_cfg, | ||
806 | .getpfccfg = ixgbe_dcbnl_get_pfc_cfg, | ||
807 | .setall = ixgbe_dcbnl_set_all, | ||
808 | .getcap = ixgbe_dcbnl_getcap, | ||
809 | .getnumtcs = ixgbe_dcbnl_getnumtcs, | ||
810 | .setnumtcs = ixgbe_dcbnl_setnumtcs, | ||
811 | .getpfcstate = ixgbe_dcbnl_getpfcstate, | ||
812 | .setpfcstate = ixgbe_dcbnl_setpfcstate, | ||
813 | .getapp = ixgbe_dcbnl_getapp, | ||
814 | .getdcbx = ixgbe_dcbnl_getdcbx, | ||
815 | .setdcbx = ixgbe_dcbnl_setdcbx, | ||
816 | }; | ||
diff --git a/drivers/net/ixgbe/ixgbe_ethtool.c b/drivers/net/ixgbe/ixgbe_ethtool.c new file mode 100644 index 00000000000..82d4244c6e1 --- /dev/null +++ b/drivers/net/ixgbe/ixgbe_ethtool.c | |||
@@ -0,0 +1,2592 @@ | |||
1 | /******************************************************************************* | ||
2 | |||
3 | Intel 10 Gigabit PCI Express Linux driver | ||
4 | Copyright(c) 1999 - 2011 Intel Corporation. | ||
5 | |||
6 | This program is free software; you can redistribute it and/or modify it | ||
7 | under the terms and conditions of the GNU General Public License, | ||
8 | version 2, as published by the Free Software Foundation. | ||
9 | |||
10 | This program is distributed in the hope it will be useful, but WITHOUT | ||
11 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
12 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
13 | more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License along with | ||
16 | this program; if not, write to the Free Software Foundation, Inc., | ||
17 | 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. | ||
18 | |||
19 | The full GNU General Public License is included in this distribution in | ||
20 | the file called "COPYING". | ||
21 | |||
22 | Contact Information: | ||
23 | e1000-devel Mailing List <e1000-devel@lists.sourceforge.net> | ||
24 | Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 | ||
25 | |||
26 | *******************************************************************************/ | ||
27 | |||
28 | /* ethtool support for ixgbe */ | ||
29 | |||
30 | #include <linux/interrupt.h> | ||
31 | #include <linux/types.h> | ||
32 | #include <linux/module.h> | ||
33 | #include <linux/slab.h> | ||
34 | #include <linux/pci.h> | ||
35 | #include <linux/netdevice.h> | ||
36 | #include <linux/ethtool.h> | ||
37 | #include <linux/vmalloc.h> | ||
38 | #include <linux/uaccess.h> | ||
39 | |||
40 | #include "ixgbe.h" | ||
41 | |||
42 | |||
43 | #define IXGBE_ALL_RAR_ENTRIES 16 | ||
44 | |||
45 | enum {NETDEV_STATS, IXGBE_STATS}; | ||
46 | |||
47 | struct ixgbe_stats { | ||
48 | char stat_string[ETH_GSTRING_LEN]; | ||
49 | int type; | ||
50 | int sizeof_stat; | ||
51 | int stat_offset; | ||
52 | }; | ||
53 | |||
54 | #define IXGBE_STAT(m) IXGBE_STATS, \ | ||
55 | sizeof(((struct ixgbe_adapter *)0)->m), \ | ||
56 | offsetof(struct ixgbe_adapter, m) | ||
57 | #define IXGBE_NETDEV_STAT(m) NETDEV_STATS, \ | ||
58 | sizeof(((struct rtnl_link_stats64 *)0)->m), \ | ||
59 | offsetof(struct rtnl_link_stats64, m) | ||
60 | |||
61 | static struct ixgbe_stats ixgbe_gstrings_stats[] = { | ||
62 | {"rx_packets", IXGBE_NETDEV_STAT(rx_packets)}, | ||
63 | {"tx_packets", IXGBE_NETDEV_STAT(tx_packets)}, | ||
64 | {"rx_bytes", IXGBE_NETDEV_STAT(rx_bytes)}, | ||
65 | {"tx_bytes", IXGBE_NETDEV_STAT(tx_bytes)}, | ||
66 | {"rx_pkts_nic", IXGBE_STAT(stats.gprc)}, | ||
67 | {"tx_pkts_nic", IXGBE_STAT(stats.gptc)}, | ||
68 | {"rx_bytes_nic", IXGBE_STAT(stats.gorc)}, | ||
69 | {"tx_bytes_nic", IXGBE_STAT(stats.gotc)}, | ||
70 | {"lsc_int", IXGBE_STAT(lsc_int)}, | ||
71 | {"tx_busy", IXGBE_STAT(tx_busy)}, | ||
72 | {"non_eop_descs", IXGBE_STAT(non_eop_descs)}, | ||
73 | {"rx_errors", IXGBE_NETDEV_STAT(rx_errors)}, | ||
74 | {"tx_errors", IXGBE_NETDEV_STAT(tx_errors)}, | ||
75 | {"rx_dropped", IXGBE_NETDEV_STAT(rx_dropped)}, | ||
76 | {"tx_dropped", IXGBE_NETDEV_STAT(tx_dropped)}, | ||
77 | {"multicast", IXGBE_NETDEV_STAT(multicast)}, | ||
78 | {"broadcast", IXGBE_STAT(stats.bprc)}, | ||
79 | {"rx_no_buffer_count", IXGBE_STAT(stats.rnbc[0]) }, | ||
80 | {"collisions", IXGBE_NETDEV_STAT(collisions)}, | ||
81 | {"rx_over_errors", IXGBE_NETDEV_STAT(rx_over_errors)}, | ||
82 | {"rx_crc_errors", IXGBE_NETDEV_STAT(rx_crc_errors)}, | ||
83 | {"rx_frame_errors", IXGBE_NETDEV_STAT(rx_frame_errors)}, | ||
84 | {"hw_rsc_aggregated", IXGBE_STAT(rsc_total_count)}, | ||
85 | {"hw_rsc_flushed", IXGBE_STAT(rsc_total_flush)}, | ||
86 | {"fdir_match", IXGBE_STAT(stats.fdirmatch)}, | ||
87 | {"fdir_miss", IXGBE_STAT(stats.fdirmiss)}, | ||
88 | {"fdir_overflow", IXGBE_STAT(fdir_overflow)}, | ||
89 | {"rx_fifo_errors", IXGBE_NETDEV_STAT(rx_fifo_errors)}, | ||
90 | {"rx_missed_errors", IXGBE_NETDEV_STAT(rx_missed_errors)}, | ||
91 | {"tx_aborted_errors", IXGBE_NETDEV_STAT(tx_aborted_errors)}, | ||
92 | {"tx_carrier_errors", IXGBE_NETDEV_STAT(tx_carrier_errors)}, | ||
93 | {"tx_fifo_errors", IXGBE_NETDEV_STAT(tx_fifo_errors)}, | ||
94 | {"tx_heartbeat_errors", IXGBE_NETDEV_STAT(tx_heartbeat_errors)}, | ||
95 | {"tx_timeout_count", IXGBE_STAT(tx_timeout_count)}, | ||
96 | {"tx_restart_queue", IXGBE_STAT(restart_queue)}, | ||
97 | {"rx_long_length_errors", IXGBE_STAT(stats.roc)}, | ||
98 | {"rx_short_length_errors", IXGBE_STAT(stats.ruc)}, | ||
99 | {"tx_flow_control_xon", IXGBE_STAT(stats.lxontxc)}, | ||
100 | {"rx_flow_control_xon", IXGBE_STAT(stats.lxonrxc)}, | ||
101 | {"tx_flow_control_xoff", IXGBE_STAT(stats.lxofftxc)}, | ||
102 | {"rx_flow_control_xoff", IXGBE_STAT(stats.lxoffrxc)}, | ||
103 | {"rx_csum_offload_errors", IXGBE_STAT(hw_csum_rx_error)}, | ||
104 | {"alloc_rx_page_failed", IXGBE_STAT(alloc_rx_page_failed)}, | ||
105 | {"alloc_rx_buff_failed", IXGBE_STAT(alloc_rx_buff_failed)}, | ||
106 | {"rx_no_dma_resources", IXGBE_STAT(hw_rx_no_dma_resources)}, | ||
107 | {"os2bmc_rx_by_bmc", IXGBE_STAT(stats.o2bgptc)}, | ||
108 | {"os2bmc_tx_by_bmc", IXGBE_STAT(stats.b2ospc)}, | ||
109 | {"os2bmc_tx_by_host", IXGBE_STAT(stats.o2bspc)}, | ||
110 | {"os2bmc_rx_by_host", IXGBE_STAT(stats.b2ogprc)}, | ||
111 | #ifdef IXGBE_FCOE | ||
112 | {"fcoe_bad_fccrc", IXGBE_STAT(stats.fccrc)}, | ||
113 | {"rx_fcoe_dropped", IXGBE_STAT(stats.fcoerpdc)}, | ||
114 | {"rx_fcoe_packets", IXGBE_STAT(stats.fcoeprc)}, | ||
115 | {"rx_fcoe_dwords", IXGBE_STAT(stats.fcoedwrc)}, | ||
116 | {"tx_fcoe_packets", IXGBE_STAT(stats.fcoeptc)}, | ||
117 | {"tx_fcoe_dwords", IXGBE_STAT(stats.fcoedwtc)}, | ||
118 | #endif /* IXGBE_FCOE */ | ||
119 | }; | ||
120 | |||
121 | #define IXGBE_QUEUE_STATS_LEN \ | ||
122 | ((((struct ixgbe_adapter *)netdev_priv(netdev))->num_tx_queues + \ | ||
123 | ((struct ixgbe_adapter *)netdev_priv(netdev))->num_rx_queues) * \ | ||
124 | (sizeof(struct ixgbe_queue_stats) / sizeof(u64))) | ||
125 | #define IXGBE_GLOBAL_STATS_LEN ARRAY_SIZE(ixgbe_gstrings_stats) | ||
126 | #define IXGBE_PB_STATS_LEN ( \ | ||
127 | (((struct ixgbe_adapter *)netdev_priv(netdev))->flags & \ | ||
128 | IXGBE_FLAG_DCB_ENABLED) ? \ | ||
129 | (sizeof(((struct ixgbe_adapter *)0)->stats.pxonrxc) + \ | ||
130 | sizeof(((struct ixgbe_adapter *)0)->stats.pxontxc) + \ | ||
131 | sizeof(((struct ixgbe_adapter *)0)->stats.pxoffrxc) + \ | ||
132 | sizeof(((struct ixgbe_adapter *)0)->stats.pxofftxc)) \ | ||
133 | / sizeof(u64) : 0) | ||
134 | #define IXGBE_STATS_LEN (IXGBE_GLOBAL_STATS_LEN + \ | ||
135 | IXGBE_PB_STATS_LEN + \ | ||
136 | IXGBE_QUEUE_STATS_LEN) | ||
137 | |||
138 | static const char ixgbe_gstrings_test[][ETH_GSTRING_LEN] = { | ||
139 | "Register test (offline)", "Eeprom test (offline)", | ||
140 | "Interrupt test (offline)", "Loopback test (offline)", | ||
141 | "Link test (on/offline)" | ||
142 | }; | ||
143 | #define IXGBE_TEST_LEN sizeof(ixgbe_gstrings_test) / ETH_GSTRING_LEN | ||
144 | |||
145 | static int ixgbe_get_settings(struct net_device *netdev, | ||
146 | struct ethtool_cmd *ecmd) | ||
147 | { | ||
148 | struct ixgbe_adapter *adapter = netdev_priv(netdev); | ||
149 | struct ixgbe_hw *hw = &adapter->hw; | ||
150 | u32 link_speed = 0; | ||
151 | bool link_up; | ||
152 | |||
153 | ecmd->supported = SUPPORTED_10000baseT_Full; | ||
154 | ecmd->autoneg = AUTONEG_ENABLE; | ||
155 | ecmd->transceiver = XCVR_EXTERNAL; | ||
156 | if ((hw->phy.media_type == ixgbe_media_type_copper) || | ||
157 | (hw->phy.multispeed_fiber)) { | ||
158 | ecmd->supported |= (SUPPORTED_1000baseT_Full | | ||
159 | SUPPORTED_Autoneg); | ||
160 | |||
161 | switch (hw->mac.type) { | ||
162 | case ixgbe_mac_X540: | ||
163 | ecmd->supported |= SUPPORTED_100baseT_Full; | ||
164 | break; | ||
165 | default: | ||
166 | break; | ||
167 | } | ||
168 | |||
169 | ecmd->advertising = ADVERTISED_Autoneg; | ||
170 | if (hw->phy.autoneg_advertised) { | ||
171 | if (hw->phy.autoneg_advertised & | ||
172 | IXGBE_LINK_SPEED_100_FULL) | ||
173 | ecmd->advertising |= ADVERTISED_100baseT_Full; | ||
174 | if (hw->phy.autoneg_advertised & | ||
175 | IXGBE_LINK_SPEED_10GB_FULL) | ||
176 | ecmd->advertising |= ADVERTISED_10000baseT_Full; | ||
177 | if (hw->phy.autoneg_advertised & | ||
178 | IXGBE_LINK_SPEED_1GB_FULL) | ||
179 | ecmd->advertising |= ADVERTISED_1000baseT_Full; | ||
180 | } else { | ||
181 | /* | ||
182 | * Default advertised modes in case | ||
183 | * phy.autoneg_advertised isn't set. | ||
184 | */ | ||
185 | ecmd->advertising |= (ADVERTISED_10000baseT_Full | | ||
186 | ADVERTISED_1000baseT_Full); | ||
187 | if (hw->mac.type == ixgbe_mac_X540) | ||
188 | ecmd->advertising |= ADVERTISED_100baseT_Full; | ||
189 | } | ||
190 | |||
191 | if (hw->phy.media_type == ixgbe_media_type_copper) { | ||
192 | ecmd->supported |= SUPPORTED_TP; | ||
193 | ecmd->advertising |= ADVERTISED_TP; | ||
194 | ecmd->port = PORT_TP; | ||
195 | } else { | ||
196 | ecmd->supported |= SUPPORTED_FIBRE; | ||
197 | ecmd->advertising |= ADVERTISED_FIBRE; | ||
198 | ecmd->port = PORT_FIBRE; | ||
199 | } | ||
200 | } else if (hw->phy.media_type == ixgbe_media_type_backplane) { | ||
201 | /* Set as FIBRE until SERDES defined in kernel */ | ||
202 | if (hw->device_id == IXGBE_DEV_ID_82598_BX) { | ||
203 | ecmd->supported = (SUPPORTED_1000baseT_Full | | ||
204 | SUPPORTED_FIBRE); | ||
205 | ecmd->advertising = (ADVERTISED_1000baseT_Full | | ||
206 | ADVERTISED_FIBRE); | ||
207 | ecmd->port = PORT_FIBRE; | ||
208 | ecmd->autoneg = AUTONEG_DISABLE; | ||
209 | } else if ((hw->device_id == IXGBE_DEV_ID_82599_COMBO_BACKPLANE) || | ||
210 | (hw->device_id == IXGBE_DEV_ID_82599_KX4_MEZZ)) { | ||
211 | ecmd->supported |= (SUPPORTED_1000baseT_Full | | ||
212 | SUPPORTED_Autoneg | | ||
213 | SUPPORTED_FIBRE); | ||
214 | ecmd->advertising = (ADVERTISED_10000baseT_Full | | ||
215 | ADVERTISED_1000baseT_Full | | ||
216 | ADVERTISED_Autoneg | | ||
217 | ADVERTISED_FIBRE); | ||
218 | ecmd->port = PORT_FIBRE; | ||
219 | } else { | ||
220 | ecmd->supported |= (SUPPORTED_1000baseT_Full | | ||
221 | SUPPORTED_FIBRE); | ||
222 | ecmd->advertising = (ADVERTISED_10000baseT_Full | | ||
223 | ADVERTISED_1000baseT_Full | | ||
224 | ADVERTISED_FIBRE); | ||
225 | ecmd->port = PORT_FIBRE; | ||
226 | } | ||
227 | } else { | ||
228 | ecmd->supported |= SUPPORTED_FIBRE; | ||
229 | ecmd->advertising = (ADVERTISED_10000baseT_Full | | ||
230 | ADVERTISED_FIBRE); | ||
231 | ecmd->port = PORT_FIBRE; | ||
232 | ecmd->autoneg = AUTONEG_DISABLE; | ||
233 | } | ||
234 | |||
235 | /* Get PHY type */ | ||
236 | switch (adapter->hw.phy.type) { | ||
237 | case ixgbe_phy_tn: | ||
238 | case ixgbe_phy_aq: | ||
239 | case ixgbe_phy_cu_unknown: | ||
240 | /* Copper 10G-BASET */ | ||
241 | ecmd->port = PORT_TP; | ||
242 | break; | ||
243 | case ixgbe_phy_qt: | ||
244 | ecmd->port = PORT_FIBRE; | ||
245 | break; | ||
246 | case ixgbe_phy_nl: | ||
247 | case ixgbe_phy_sfp_passive_tyco: | ||
248 | case ixgbe_phy_sfp_passive_unknown: | ||
249 | case ixgbe_phy_sfp_ftl: | ||
250 | case ixgbe_phy_sfp_avago: | ||
251 | case ixgbe_phy_sfp_intel: | ||
252 | case ixgbe_phy_sfp_unknown: | ||
253 | switch (adapter->hw.phy.sfp_type) { | ||
254 | /* SFP+ devices, further checking needed */ | ||
255 | case ixgbe_sfp_type_da_cu: | ||
256 | case ixgbe_sfp_type_da_cu_core0: | ||
257 | case ixgbe_sfp_type_da_cu_core1: | ||
258 | ecmd->port = PORT_DA; | ||
259 | break; | ||
260 | case ixgbe_sfp_type_sr: | ||
261 | case ixgbe_sfp_type_lr: | ||
262 | case ixgbe_sfp_type_srlr_core0: | ||
263 | case ixgbe_sfp_type_srlr_core1: | ||
264 | ecmd->port = PORT_FIBRE; | ||
265 | break; | ||
266 | case ixgbe_sfp_type_not_present: | ||
267 | ecmd->port = PORT_NONE; | ||
268 | break; | ||
269 | case ixgbe_sfp_type_1g_cu_core0: | ||
270 | case ixgbe_sfp_type_1g_cu_core1: | ||
271 | ecmd->port = PORT_TP; | ||
272 | ecmd->supported = SUPPORTED_TP; | ||
273 | ecmd->advertising = (ADVERTISED_1000baseT_Full | | ||
274 | ADVERTISED_TP); | ||
275 | break; | ||
276 | case ixgbe_sfp_type_unknown: | ||
277 | default: | ||
278 | ecmd->port = PORT_OTHER; | ||
279 | break; | ||
280 | } | ||
281 | break; | ||
282 | case ixgbe_phy_xaui: | ||
283 | ecmd->port = PORT_NONE; | ||
284 | break; | ||
285 | case ixgbe_phy_unknown: | ||
286 | case ixgbe_phy_generic: | ||
287 | case ixgbe_phy_sfp_unsupported: | ||
288 | default: | ||
289 | ecmd->port = PORT_OTHER; | ||
290 | break; | ||
291 | } | ||
292 | |||
293 | hw->mac.ops.check_link(hw, &link_speed, &link_up, false); | ||
294 | if (link_up) { | ||
295 | switch (link_speed) { | ||
296 | case IXGBE_LINK_SPEED_10GB_FULL: | ||
297 | ethtool_cmd_speed_set(ecmd, SPEED_10000); | ||
298 | break; | ||
299 | case IXGBE_LINK_SPEED_1GB_FULL: | ||
300 | ethtool_cmd_speed_set(ecmd, SPEED_1000); | ||
301 | break; | ||
302 | case IXGBE_LINK_SPEED_100_FULL: | ||
303 | ethtool_cmd_speed_set(ecmd, SPEED_100); | ||
304 | break; | ||
305 | default: | ||
306 | break; | ||
307 | } | ||
308 | ecmd->duplex = DUPLEX_FULL; | ||
309 | } else { | ||
310 | ethtool_cmd_speed_set(ecmd, -1); | ||
311 | ecmd->duplex = -1; | ||
312 | } | ||
313 | |||
314 | return 0; | ||
315 | } | ||
316 | |||
317 | static int ixgbe_set_settings(struct net_device *netdev, | ||
318 | struct ethtool_cmd *ecmd) | ||
319 | { | ||
320 | struct ixgbe_adapter *adapter = netdev_priv(netdev); | ||
321 | struct ixgbe_hw *hw = &adapter->hw; | ||
322 | u32 advertised, old; | ||
323 | s32 err = 0; | ||
324 | |||
325 | if ((hw->phy.media_type == ixgbe_media_type_copper) || | ||
326 | (hw->phy.multispeed_fiber)) { | ||
327 | /* 10000/copper and 1000/copper must autoneg | ||
328 | * this function does not support any duplex forcing, but can | ||
329 | * limit the advertising of the adapter to only 10000 or 1000 */ | ||
330 | if (ecmd->autoneg == AUTONEG_DISABLE) | ||
331 | return -EINVAL; | ||
332 | |||
333 | old = hw->phy.autoneg_advertised; | ||
334 | advertised = 0; | ||
335 | if (ecmd->advertising & ADVERTISED_10000baseT_Full) | ||
336 | advertised |= IXGBE_LINK_SPEED_10GB_FULL; | ||
337 | |||
338 | if (ecmd->advertising & ADVERTISED_1000baseT_Full) | ||
339 | advertised |= IXGBE_LINK_SPEED_1GB_FULL; | ||
340 | |||
341 | if (ecmd->advertising & ADVERTISED_100baseT_Full) | ||
342 | advertised |= IXGBE_LINK_SPEED_100_FULL; | ||
343 | |||
344 | if (old == advertised) | ||
345 | return err; | ||
346 | /* this sets the link speed and restarts auto-neg */ | ||
347 | hw->mac.autotry_restart = true; | ||
348 | err = hw->mac.ops.setup_link(hw, advertised, true, true); | ||
349 | if (err) { | ||
350 | e_info(probe, "setup link failed with code %d\n", err); | ||
351 | hw->mac.ops.setup_link(hw, old, true, true); | ||
352 | } | ||
353 | } else { | ||
354 | /* in this case we currently only support 10Gb/FULL */ | ||
355 | u32 speed = ethtool_cmd_speed(ecmd); | ||
356 | if ((ecmd->autoneg == AUTONEG_ENABLE) || | ||
357 | (ecmd->advertising != ADVERTISED_10000baseT_Full) || | ||
358 | (speed + ecmd->duplex != SPEED_10000 + DUPLEX_FULL)) | ||
359 | return -EINVAL; | ||
360 | } | ||
361 | |||
362 | return err; | ||
363 | } | ||
364 | |||
365 | static void ixgbe_get_pauseparam(struct net_device *netdev, | ||
366 | struct ethtool_pauseparam *pause) | ||
367 | { | ||
368 | struct ixgbe_adapter *adapter = netdev_priv(netdev); | ||
369 | struct ixgbe_hw *hw = &adapter->hw; | ||
370 | |||
371 | /* | ||
372 | * Flow Control Autoneg isn't on if | ||
373 | * - we didn't ask for it OR | ||
374 | * - it failed, we know this by tx & rx being off | ||
375 | */ | ||
376 | if (hw->fc.disable_fc_autoneg || | ||
377 | (hw->fc.current_mode == ixgbe_fc_none)) | ||
378 | pause->autoneg = 0; | ||
379 | else | ||
380 | pause->autoneg = 1; | ||
381 | |||
382 | if (hw->fc.current_mode == ixgbe_fc_rx_pause) { | ||
383 | pause->rx_pause = 1; | ||
384 | } else if (hw->fc.current_mode == ixgbe_fc_tx_pause) { | ||
385 | pause->tx_pause = 1; | ||
386 | } else if (hw->fc.current_mode == ixgbe_fc_full) { | ||
387 | pause->rx_pause = 1; | ||
388 | pause->tx_pause = 1; | ||
389 | #ifdef CONFIG_DCB | ||
390 | } else if (hw->fc.current_mode == ixgbe_fc_pfc) { | ||
391 | pause->rx_pause = 0; | ||
392 | pause->tx_pause = 0; | ||
393 | #endif | ||
394 | } | ||
395 | } | ||
396 | |||
397 | static int ixgbe_set_pauseparam(struct net_device *netdev, | ||
398 | struct ethtool_pauseparam *pause) | ||
399 | { | ||
400 | struct ixgbe_adapter *adapter = netdev_priv(netdev); | ||
401 | struct ixgbe_hw *hw = &adapter->hw; | ||
402 | struct ixgbe_fc_info fc; | ||
403 | |||
404 | #ifdef CONFIG_DCB | ||
405 | if (adapter->dcb_cfg.pfc_mode_enable || | ||
406 | ((hw->mac.type == ixgbe_mac_82598EB) && | ||
407 | (adapter->flags & IXGBE_FLAG_DCB_ENABLED))) | ||
408 | return -EINVAL; | ||
409 | |||
410 | #endif | ||
411 | fc = hw->fc; | ||
412 | |||
413 | if (pause->autoneg != AUTONEG_ENABLE) | ||
414 | fc.disable_fc_autoneg = true; | ||
415 | else | ||
416 | fc.disable_fc_autoneg = false; | ||
417 | |||
418 | if ((pause->rx_pause && pause->tx_pause) || pause->autoneg) | ||
419 | fc.requested_mode = ixgbe_fc_full; | ||
420 | else if (pause->rx_pause && !pause->tx_pause) | ||
421 | fc.requested_mode = ixgbe_fc_rx_pause; | ||
422 | else if (!pause->rx_pause && pause->tx_pause) | ||
423 | fc.requested_mode = ixgbe_fc_tx_pause; | ||
424 | else if (!pause->rx_pause && !pause->tx_pause) | ||
425 | fc.requested_mode = ixgbe_fc_none; | ||
426 | else | ||
427 | return -EINVAL; | ||
428 | |||
429 | #ifdef CONFIG_DCB | ||
430 | adapter->last_lfc_mode = fc.requested_mode; | ||
431 | #endif | ||
432 | |||
433 | /* if the thing changed then we'll update and use new autoneg */ | ||
434 | if (memcmp(&fc, &hw->fc, sizeof(struct ixgbe_fc_info))) { | ||
435 | hw->fc = fc; | ||
436 | if (netif_running(netdev)) | ||
437 | ixgbe_reinit_locked(adapter); | ||
438 | else | ||
439 | ixgbe_reset(adapter); | ||
440 | } | ||
441 | |||
442 | return 0; | ||
443 | } | ||
444 | |||
445 | static u32 ixgbe_get_msglevel(struct net_device *netdev) | ||
446 | { | ||
447 | struct ixgbe_adapter *adapter = netdev_priv(netdev); | ||
448 | return adapter->msg_enable; | ||
449 | } | ||
450 | |||
451 | static void ixgbe_set_msglevel(struct net_device *netdev, u32 data) | ||
452 | { | ||
453 | struct ixgbe_adapter *adapter = netdev_priv(netdev); | ||
454 | adapter->msg_enable = data; | ||
455 | } | ||
456 | |||
457 | static int ixgbe_get_regs_len(struct net_device *netdev) | ||
458 | { | ||
459 | #define IXGBE_REGS_LEN 1128 | ||
460 | return IXGBE_REGS_LEN * sizeof(u32); | ||
461 | } | ||
462 | |||
463 | #define IXGBE_GET_STAT(_A_, _R_) _A_->stats._R_ | ||
464 | |||
465 | static void ixgbe_get_regs(struct net_device *netdev, | ||
466 | struct ethtool_regs *regs, void *p) | ||
467 | { | ||
468 | struct ixgbe_adapter *adapter = netdev_priv(netdev); | ||
469 | struct ixgbe_hw *hw = &adapter->hw; | ||
470 | u32 *regs_buff = p; | ||
471 | u8 i; | ||
472 | |||
473 | memset(p, 0, IXGBE_REGS_LEN * sizeof(u32)); | ||
474 | |||
475 | regs->version = (1 << 24) | hw->revision_id << 16 | hw->device_id; | ||
476 | |||
477 | /* General Registers */ | ||
478 | regs_buff[0] = IXGBE_READ_REG(hw, IXGBE_CTRL); | ||
479 | regs_buff[1] = IXGBE_READ_REG(hw, IXGBE_STATUS); | ||
480 | regs_buff[2] = IXGBE_READ_REG(hw, IXGBE_CTRL_EXT); | ||
481 | regs_buff[3] = IXGBE_READ_REG(hw, IXGBE_ESDP); | ||
482 | regs_buff[4] = IXGBE_READ_REG(hw, IXGBE_EODSDP); | ||
483 | regs_buff[5] = IXGBE_READ_REG(hw, IXGBE_LEDCTL); | ||
484 | regs_buff[6] = IXGBE_READ_REG(hw, IXGBE_FRTIMER); | ||
485 | regs_buff[7] = IXGBE_READ_REG(hw, IXGBE_TCPTIMER); | ||
486 | |||
487 | /* NVM Register */ | ||
488 | regs_buff[8] = IXGBE_READ_REG(hw, IXGBE_EEC); | ||
489 | regs_buff[9] = IXGBE_READ_REG(hw, IXGBE_EERD); | ||
490 | regs_buff[10] = IXGBE_READ_REG(hw, IXGBE_FLA); | ||
491 | regs_buff[11] = IXGBE_READ_REG(hw, IXGBE_EEMNGCTL); | ||
492 | regs_buff[12] = IXGBE_READ_REG(hw, IXGBE_EEMNGDATA); | ||
493 | regs_buff[13] = IXGBE_READ_REG(hw, IXGBE_FLMNGCTL); | ||
494 | regs_buff[14] = IXGBE_READ_REG(hw, IXGBE_FLMNGDATA); | ||
495 | regs_buff[15] = IXGBE_READ_REG(hw, IXGBE_FLMNGCNT); | ||
496 | regs_buff[16] = IXGBE_READ_REG(hw, IXGBE_FLOP); | ||
497 | regs_buff[17] = IXGBE_READ_REG(hw, IXGBE_GRC); | ||
498 | |||
499 | /* Interrupt */ | ||
500 | /* don't read EICR because it can clear interrupt causes, instead | ||
501 | * read EICS which is a shadow but doesn't clear EICR */ | ||
502 | regs_buff[18] = IXGBE_READ_REG(hw, IXGBE_EICS); | ||
503 | regs_buff[19] = IXGBE_READ_REG(hw, IXGBE_EICS); | ||
504 | regs_buff[20] = IXGBE_READ_REG(hw, IXGBE_EIMS); | ||
505 | regs_buff[21] = IXGBE_READ_REG(hw, IXGBE_EIMC); | ||
506 | regs_buff[22] = IXGBE_READ_REG(hw, IXGBE_EIAC); | ||
507 | regs_buff[23] = IXGBE_READ_REG(hw, IXGBE_EIAM); | ||
508 | regs_buff[24] = IXGBE_READ_REG(hw, IXGBE_EITR(0)); | ||
509 | regs_buff[25] = IXGBE_READ_REG(hw, IXGBE_IVAR(0)); | ||
510 | regs_buff[26] = IXGBE_READ_REG(hw, IXGBE_MSIXT); | ||
511 | regs_buff[27] = IXGBE_READ_REG(hw, IXGBE_MSIXPBA); | ||
512 | regs_buff[28] = IXGBE_READ_REG(hw, IXGBE_PBACL(0)); | ||
513 | regs_buff[29] = IXGBE_READ_REG(hw, IXGBE_GPIE); | ||
514 | |||
515 | /* Flow Control */ | ||
516 | regs_buff[30] = IXGBE_READ_REG(hw, IXGBE_PFCTOP); | ||
517 | regs_buff[31] = IXGBE_READ_REG(hw, IXGBE_FCTTV(0)); | ||
518 | regs_buff[32] = IXGBE_READ_REG(hw, IXGBE_FCTTV(1)); | ||
519 | regs_buff[33] = IXGBE_READ_REG(hw, IXGBE_FCTTV(2)); | ||
520 | regs_buff[34] = IXGBE_READ_REG(hw, IXGBE_FCTTV(3)); | ||
521 | for (i = 0; i < 8; i++) { | ||
522 | switch (hw->mac.type) { | ||
523 | case ixgbe_mac_82598EB: | ||
524 | regs_buff[35 + i] = IXGBE_READ_REG(hw, IXGBE_FCRTL(i)); | ||
525 | regs_buff[43 + i] = IXGBE_READ_REG(hw, IXGBE_FCRTH(i)); | ||
526 | break; | ||
527 | case ixgbe_mac_82599EB: | ||
528 | regs_buff[35 + i] = IXGBE_READ_REG(hw, IXGBE_FCRTL_82599(i)); | ||
529 | regs_buff[43 + i] = IXGBE_READ_REG(hw, IXGBE_FCRTH_82599(i)); | ||
530 | break; | ||
531 | default: | ||
532 | break; | ||
533 | } | ||
534 | } | ||
535 | regs_buff[51] = IXGBE_READ_REG(hw, IXGBE_FCRTV); | ||
536 | regs_buff[52] = IXGBE_READ_REG(hw, IXGBE_TFCS); | ||
537 | |||
538 | /* Receive DMA */ | ||
539 | for (i = 0; i < 64; i++) | ||
540 | regs_buff[53 + i] = IXGBE_READ_REG(hw, IXGBE_RDBAL(i)); | ||
541 | for (i = 0; i < 64; i++) | ||
542 | regs_buff[117 + i] = IXGBE_READ_REG(hw, IXGBE_RDBAH(i)); | ||
543 | for (i = 0; i < 64; i++) | ||
544 | regs_buff[181 + i] = IXGBE_READ_REG(hw, IXGBE_RDLEN(i)); | ||
545 | for (i = 0; i < 64; i++) | ||
546 | regs_buff[245 + i] = IXGBE_READ_REG(hw, IXGBE_RDH(i)); | ||
547 | for (i = 0; i < 64; i++) | ||
548 | regs_buff[309 + i] = IXGBE_READ_REG(hw, IXGBE_RDT(i)); | ||
549 | for (i = 0; i < 64; i++) | ||
550 | regs_buff[373 + i] = IXGBE_READ_REG(hw, IXGBE_RXDCTL(i)); | ||
551 | for (i = 0; i < 16; i++) | ||
552 | regs_buff[437 + i] = IXGBE_READ_REG(hw, IXGBE_SRRCTL(i)); | ||
553 | for (i = 0; i < 16; i++) | ||
554 | regs_buff[453 + i] = IXGBE_READ_REG(hw, IXGBE_DCA_RXCTRL(i)); | ||
555 | regs_buff[469] = IXGBE_READ_REG(hw, IXGBE_RDRXCTL); | ||
556 | for (i = 0; i < 8; i++) | ||
557 | regs_buff[470 + i] = IXGBE_READ_REG(hw, IXGBE_RXPBSIZE(i)); | ||
558 | regs_buff[478] = IXGBE_READ_REG(hw, IXGBE_RXCTRL); | ||
559 | regs_buff[479] = IXGBE_READ_REG(hw, IXGBE_DROPEN); | ||
560 | |||
561 | /* Receive */ | ||
562 | regs_buff[480] = IXGBE_READ_REG(hw, IXGBE_RXCSUM); | ||
563 | regs_buff[481] = IXGBE_READ_REG(hw, IXGBE_RFCTL); | ||
564 | for (i = 0; i < 16; i++) | ||
565 | regs_buff[482 + i] = IXGBE_READ_REG(hw, IXGBE_RAL(i)); | ||
566 | for (i = 0; i < 16; i++) | ||
567 | regs_buff[498 + i] = IXGBE_READ_REG(hw, IXGBE_RAH(i)); | ||
568 | regs_buff[514] = IXGBE_READ_REG(hw, IXGBE_PSRTYPE(0)); | ||
569 | regs_buff[515] = IXGBE_READ_REG(hw, IXGBE_FCTRL); | ||
570 | regs_buff[516] = IXGBE_READ_REG(hw, IXGBE_VLNCTRL); | ||
571 | regs_buff[517] = IXGBE_READ_REG(hw, IXGBE_MCSTCTRL); | ||
572 | regs_buff[518] = IXGBE_READ_REG(hw, IXGBE_MRQC); | ||
573 | regs_buff[519] = IXGBE_READ_REG(hw, IXGBE_VMD_CTL); | ||
574 | for (i = 0; i < 8; i++) | ||
575 | regs_buff[520 + i] = IXGBE_READ_REG(hw, IXGBE_IMIR(i)); | ||
576 | for (i = 0; i < 8; i++) | ||
577 | regs_buff[528 + i] = IXGBE_READ_REG(hw, IXGBE_IMIREXT(i)); | ||
578 | regs_buff[536] = IXGBE_READ_REG(hw, IXGBE_IMIRVP); | ||
579 | |||
580 | /* Transmit */ | ||
581 | for (i = 0; i < 32; i++) | ||
582 | regs_buff[537 + i] = IXGBE_READ_REG(hw, IXGBE_TDBAL(i)); | ||
583 | for (i = 0; i < 32; i++) | ||
584 | regs_buff[569 + i] = IXGBE_READ_REG(hw, IXGBE_TDBAH(i)); | ||
585 | for (i = 0; i < 32; i++) | ||
586 | regs_buff[601 + i] = IXGBE_READ_REG(hw, IXGBE_TDLEN(i)); | ||
587 | for (i = 0; i < 32; i++) | ||
588 | regs_buff[633 + i] = IXGBE_READ_REG(hw, IXGBE_TDH(i)); | ||
589 | for (i = 0; i < 32; i++) | ||
590 | regs_buff[665 + i] = IXGBE_READ_REG(hw, IXGBE_TDT(i)); | ||
591 | for (i = 0; i < 32; i++) | ||
592 | regs_buff[697 + i] = IXGBE_READ_REG(hw, IXGBE_TXDCTL(i)); | ||
593 | for (i = 0; i < 32; i++) | ||
594 | regs_buff[729 + i] = IXGBE_READ_REG(hw, IXGBE_TDWBAL(i)); | ||
595 | for (i = 0; i < 32; i++) | ||
596 | regs_buff[761 + i] = IXGBE_READ_REG(hw, IXGBE_TDWBAH(i)); | ||
597 | regs_buff[793] = IXGBE_READ_REG(hw, IXGBE_DTXCTL); | ||
598 | for (i = 0; i < 16; i++) | ||
599 | regs_buff[794 + i] = IXGBE_READ_REG(hw, IXGBE_DCA_TXCTRL(i)); | ||
600 | regs_buff[810] = IXGBE_READ_REG(hw, IXGBE_TIPG); | ||
601 | for (i = 0; i < 8; i++) | ||
602 | regs_buff[811 + i] = IXGBE_READ_REG(hw, IXGBE_TXPBSIZE(i)); | ||
603 | regs_buff[819] = IXGBE_READ_REG(hw, IXGBE_MNGTXMAP); | ||
604 | |||
605 | /* Wake Up */ | ||
606 | regs_buff[820] = IXGBE_READ_REG(hw, IXGBE_WUC); | ||
607 | regs_buff[821] = IXGBE_READ_REG(hw, IXGBE_WUFC); | ||
608 | regs_buff[822] = IXGBE_READ_REG(hw, IXGBE_WUS); | ||
609 | regs_buff[823] = IXGBE_READ_REG(hw, IXGBE_IPAV); | ||
610 | regs_buff[824] = IXGBE_READ_REG(hw, IXGBE_IP4AT); | ||
611 | regs_buff[825] = IXGBE_READ_REG(hw, IXGBE_IP6AT); | ||
612 | regs_buff[826] = IXGBE_READ_REG(hw, IXGBE_WUPL); | ||
613 | regs_buff[827] = IXGBE_READ_REG(hw, IXGBE_WUPM); | ||
614 | regs_buff[828] = IXGBE_READ_REG(hw, IXGBE_FHFT(0)); | ||
615 | |||
616 | /* DCB */ | ||
617 | regs_buff[829] = IXGBE_READ_REG(hw, IXGBE_RMCS); | ||
618 | regs_buff[830] = IXGBE_READ_REG(hw, IXGBE_DPMCS); | ||
619 | regs_buff[831] = IXGBE_READ_REG(hw, IXGBE_PDPMCS); | ||
620 | regs_buff[832] = IXGBE_READ_REG(hw, IXGBE_RUPPBMR); | ||
621 | for (i = 0; i < 8; i++) | ||
622 | regs_buff[833 + i] = IXGBE_READ_REG(hw, IXGBE_RT2CR(i)); | ||
623 | for (i = 0; i < 8; i++) | ||
624 | regs_buff[841 + i] = IXGBE_READ_REG(hw, IXGBE_RT2SR(i)); | ||
625 | for (i = 0; i < 8; i++) | ||
626 | regs_buff[849 + i] = IXGBE_READ_REG(hw, IXGBE_TDTQ2TCCR(i)); | ||
627 | for (i = 0; i < 8; i++) | ||
628 | regs_buff[857 + i] = IXGBE_READ_REG(hw, IXGBE_TDTQ2TCSR(i)); | ||
629 | for (i = 0; i < 8; i++) | ||
630 | regs_buff[865 + i] = IXGBE_READ_REG(hw, IXGBE_TDPT2TCCR(i)); | ||
631 | for (i = 0; i < 8; i++) | ||
632 | regs_buff[873 + i] = IXGBE_READ_REG(hw, IXGBE_TDPT2TCSR(i)); | ||
633 | |||
634 | /* Statistics */ | ||
635 | regs_buff[881] = IXGBE_GET_STAT(adapter, crcerrs); | ||
636 | regs_buff[882] = IXGBE_GET_STAT(adapter, illerrc); | ||
637 | regs_buff[883] = IXGBE_GET_STAT(adapter, errbc); | ||
638 | regs_buff[884] = IXGBE_GET_STAT(adapter, mspdc); | ||
639 | for (i = 0; i < 8; i++) | ||
640 | regs_buff[885 + i] = IXGBE_GET_STAT(adapter, mpc[i]); | ||
641 | regs_buff[893] = IXGBE_GET_STAT(adapter, mlfc); | ||
642 | regs_buff[894] = IXGBE_GET_STAT(adapter, mrfc); | ||
643 | regs_buff[895] = IXGBE_GET_STAT(adapter, rlec); | ||
644 | regs_buff[896] = IXGBE_GET_STAT(adapter, lxontxc); | ||
645 | regs_buff[897] = IXGBE_GET_STAT(adapter, lxonrxc); | ||
646 | regs_buff[898] = IXGBE_GET_STAT(adapter, lxofftxc); | ||
647 | regs_buff[899] = IXGBE_GET_STAT(adapter, lxoffrxc); | ||
648 | for (i = 0; i < 8; i++) | ||
649 | regs_buff[900 + i] = IXGBE_GET_STAT(adapter, pxontxc[i]); | ||
650 | for (i = 0; i < 8; i++) | ||
651 | regs_buff[908 + i] = IXGBE_GET_STAT(adapter, pxonrxc[i]); | ||
652 | for (i = 0; i < 8; i++) | ||
653 | regs_buff[916 + i] = IXGBE_GET_STAT(adapter, pxofftxc[i]); | ||
654 | for (i = 0; i < 8; i++) | ||
655 | regs_buff[924 + i] = IXGBE_GET_STAT(adapter, pxoffrxc[i]); | ||
656 | regs_buff[932] = IXGBE_GET_STAT(adapter, prc64); | ||
657 | regs_buff[933] = IXGBE_GET_STAT(adapter, prc127); | ||
658 | regs_buff[934] = IXGBE_GET_STAT(adapter, prc255); | ||
659 | regs_buff[935] = IXGBE_GET_STAT(adapter, prc511); | ||
660 | regs_buff[936] = IXGBE_GET_STAT(adapter, prc1023); | ||
661 | regs_buff[937] = IXGBE_GET_STAT(adapter, prc1522); | ||
662 | regs_buff[938] = IXGBE_GET_STAT(adapter, gprc); | ||
663 | regs_buff[939] = IXGBE_GET_STAT(adapter, bprc); | ||
664 | regs_buff[940] = IXGBE_GET_STAT(adapter, mprc); | ||
665 | regs_buff[941] = IXGBE_GET_STAT(adapter, gptc); | ||
666 | regs_buff[942] = IXGBE_GET_STAT(adapter, gorc); | ||
667 | regs_buff[944] = IXGBE_GET_STAT(adapter, gotc); | ||
668 | for (i = 0; i < 8; i++) | ||
669 | regs_buff[946 + i] = IXGBE_GET_STAT(adapter, rnbc[i]); | ||
670 | regs_buff[954] = IXGBE_GET_STAT(adapter, ruc); | ||
671 | regs_buff[955] = IXGBE_GET_STAT(adapter, rfc); | ||
672 | regs_buff[956] = IXGBE_GET_STAT(adapter, roc); | ||
673 | regs_buff[957] = IXGBE_GET_STAT(adapter, rjc); | ||
674 | regs_buff[958] = IXGBE_GET_STAT(adapter, mngprc); | ||
675 | regs_buff[959] = IXGBE_GET_STAT(adapter, mngpdc); | ||
676 | regs_buff[960] = IXGBE_GET_STAT(adapter, mngptc); | ||
677 | regs_buff[961] = IXGBE_GET_STAT(adapter, tor); | ||
678 | regs_buff[963] = IXGBE_GET_STAT(adapter, tpr); | ||
679 | regs_buff[964] = IXGBE_GET_STAT(adapter, tpt); | ||
680 | regs_buff[965] = IXGBE_GET_STAT(adapter, ptc64); | ||
681 | regs_buff[966] = IXGBE_GET_STAT(adapter, ptc127); | ||
682 | regs_buff[967] = IXGBE_GET_STAT(adapter, ptc255); | ||
683 | regs_buff[968] = IXGBE_GET_STAT(adapter, ptc511); | ||
684 | regs_buff[969] = IXGBE_GET_STAT(adapter, ptc1023); | ||
685 | regs_buff[970] = IXGBE_GET_STAT(adapter, ptc1522); | ||
686 | regs_buff[971] = IXGBE_GET_STAT(adapter, mptc); | ||
687 | regs_buff[972] = IXGBE_GET_STAT(adapter, bptc); | ||
688 | regs_buff[973] = IXGBE_GET_STAT(adapter, xec); | ||
689 | for (i = 0; i < 16; i++) | ||
690 | regs_buff[974 + i] = IXGBE_GET_STAT(adapter, qprc[i]); | ||
691 | for (i = 0; i < 16; i++) | ||
692 | regs_buff[990 + i] = IXGBE_GET_STAT(adapter, qptc[i]); | ||
693 | for (i = 0; i < 16; i++) | ||
694 | regs_buff[1006 + i] = IXGBE_GET_STAT(adapter, qbrc[i]); | ||
695 | for (i = 0; i < 16; i++) | ||
696 | regs_buff[1022 + i] = IXGBE_GET_STAT(adapter, qbtc[i]); | ||
697 | |||
698 | /* MAC */ | ||
699 | regs_buff[1038] = IXGBE_READ_REG(hw, IXGBE_PCS1GCFIG); | ||
700 | regs_buff[1039] = IXGBE_READ_REG(hw, IXGBE_PCS1GLCTL); | ||
701 | regs_buff[1040] = IXGBE_READ_REG(hw, IXGBE_PCS1GLSTA); | ||
702 | regs_buff[1041] = IXGBE_READ_REG(hw, IXGBE_PCS1GDBG0); | ||
703 | regs_buff[1042] = IXGBE_READ_REG(hw, IXGBE_PCS1GDBG1); | ||
704 | regs_buff[1043] = IXGBE_READ_REG(hw, IXGBE_PCS1GANA); | ||
705 | regs_buff[1044] = IXGBE_READ_REG(hw, IXGBE_PCS1GANLP); | ||
706 | regs_buff[1045] = IXGBE_READ_REG(hw, IXGBE_PCS1GANNP); | ||
707 | regs_buff[1046] = IXGBE_READ_REG(hw, IXGBE_PCS1GANLPNP); | ||
708 | regs_buff[1047] = IXGBE_READ_REG(hw, IXGBE_HLREG0); | ||
709 | regs_buff[1048] = IXGBE_READ_REG(hw, IXGBE_HLREG1); | ||
710 | regs_buff[1049] = IXGBE_READ_REG(hw, IXGBE_PAP); | ||
711 | regs_buff[1050] = IXGBE_READ_REG(hw, IXGBE_MACA); | ||
712 | regs_buff[1051] = IXGBE_READ_REG(hw, IXGBE_APAE); | ||
713 | regs_buff[1052] = IXGBE_READ_REG(hw, IXGBE_ARD); | ||
714 | regs_buff[1053] = IXGBE_READ_REG(hw, IXGBE_AIS); | ||
715 | regs_buff[1054] = IXGBE_READ_REG(hw, IXGBE_MSCA); | ||
716 | regs_buff[1055] = IXGBE_READ_REG(hw, IXGBE_MSRWD); | ||
717 | regs_buff[1056] = IXGBE_READ_REG(hw, IXGBE_MLADD); | ||
718 | regs_buff[1057] = IXGBE_READ_REG(hw, IXGBE_MHADD); | ||
719 | regs_buff[1058] = IXGBE_READ_REG(hw, IXGBE_TREG); | ||
720 | regs_buff[1059] = IXGBE_READ_REG(hw, IXGBE_PCSS1); | ||
721 | regs_buff[1060] = IXGBE_READ_REG(hw, IXGBE_PCSS2); | ||
722 | regs_buff[1061] = IXGBE_READ_REG(hw, IXGBE_XPCSS); | ||
723 | regs_buff[1062] = IXGBE_READ_REG(hw, IXGBE_SERDESC); | ||
724 | regs_buff[1063] = IXGBE_READ_REG(hw, IXGBE_MACS); | ||
725 | regs_buff[1064] = IXGBE_READ_REG(hw, IXGBE_AUTOC); | ||
726 | regs_buff[1065] = IXGBE_READ_REG(hw, IXGBE_LINKS); | ||
727 | regs_buff[1066] = IXGBE_READ_REG(hw, IXGBE_AUTOC2); | ||
728 | regs_buff[1067] = IXGBE_READ_REG(hw, IXGBE_AUTOC3); | ||
729 | regs_buff[1068] = IXGBE_READ_REG(hw, IXGBE_ANLP1); | ||
730 | regs_buff[1069] = IXGBE_READ_REG(hw, IXGBE_ANLP2); | ||
731 | regs_buff[1070] = IXGBE_READ_REG(hw, IXGBE_ATLASCTL); | ||
732 | |||
733 | /* Diagnostic */ | ||
734 | regs_buff[1071] = IXGBE_READ_REG(hw, IXGBE_RDSTATCTL); | ||
735 | for (i = 0; i < 8; i++) | ||
736 | regs_buff[1072 + i] = IXGBE_READ_REG(hw, IXGBE_RDSTAT(i)); | ||
737 | regs_buff[1080] = IXGBE_READ_REG(hw, IXGBE_RDHMPN); | ||
738 | for (i = 0; i < 4; i++) | ||
739 | regs_buff[1081 + i] = IXGBE_READ_REG(hw, IXGBE_RIC_DW(i)); | ||
740 | regs_buff[1085] = IXGBE_READ_REG(hw, IXGBE_RDPROBE); | ||
741 | regs_buff[1086] = IXGBE_READ_REG(hw, IXGBE_TDSTATCTL); | ||
742 | for (i = 0; i < 8; i++) | ||
743 | regs_buff[1087 + i] = IXGBE_READ_REG(hw, IXGBE_TDSTAT(i)); | ||
744 | regs_buff[1095] = IXGBE_READ_REG(hw, IXGBE_TDHMPN); | ||
745 | for (i = 0; i < 4; i++) | ||
746 | regs_buff[1096 + i] = IXGBE_READ_REG(hw, IXGBE_TIC_DW(i)); | ||
747 | regs_buff[1100] = IXGBE_READ_REG(hw, IXGBE_TDPROBE); | ||
748 | regs_buff[1101] = IXGBE_READ_REG(hw, IXGBE_TXBUFCTRL); | ||
749 | regs_buff[1102] = IXGBE_READ_REG(hw, IXGBE_TXBUFDATA0); | ||
750 | regs_buff[1103] = IXGBE_READ_REG(hw, IXGBE_TXBUFDATA1); | ||
751 | regs_buff[1104] = IXGBE_READ_REG(hw, IXGBE_TXBUFDATA2); | ||
752 | regs_buff[1105] = IXGBE_READ_REG(hw, IXGBE_TXBUFDATA3); | ||
753 | regs_buff[1106] = IXGBE_READ_REG(hw, IXGBE_RXBUFCTRL); | ||
754 | regs_buff[1107] = IXGBE_READ_REG(hw, IXGBE_RXBUFDATA0); | ||
755 | regs_buff[1108] = IXGBE_READ_REG(hw, IXGBE_RXBUFDATA1); | ||
756 | regs_buff[1109] = IXGBE_READ_REG(hw, IXGBE_RXBUFDATA2); | ||
757 | regs_buff[1110] = IXGBE_READ_REG(hw, IXGBE_RXBUFDATA3); | ||
758 | for (i = 0; i < 8; i++) | ||
759 | regs_buff[1111 + i] = IXGBE_READ_REG(hw, IXGBE_PCIE_DIAG(i)); | ||
760 | regs_buff[1119] = IXGBE_READ_REG(hw, IXGBE_RFVAL); | ||
761 | regs_buff[1120] = IXGBE_READ_REG(hw, IXGBE_MDFTC1); | ||
762 | regs_buff[1121] = IXGBE_READ_REG(hw, IXGBE_MDFTC2); | ||
763 | regs_buff[1122] = IXGBE_READ_REG(hw, IXGBE_MDFTFIFO1); | ||
764 | regs_buff[1123] = IXGBE_READ_REG(hw, IXGBE_MDFTFIFO2); | ||
765 | regs_buff[1124] = IXGBE_READ_REG(hw, IXGBE_MDFTS); | ||
766 | regs_buff[1125] = IXGBE_READ_REG(hw, IXGBE_PCIEECCCTL); | ||
767 | regs_buff[1126] = IXGBE_READ_REG(hw, IXGBE_PBTXECC); | ||
768 | regs_buff[1127] = IXGBE_READ_REG(hw, IXGBE_PBRXECC); | ||
769 | } | ||
770 | |||
771 | static int ixgbe_get_eeprom_len(struct net_device *netdev) | ||
772 | { | ||
773 | struct ixgbe_adapter *adapter = netdev_priv(netdev); | ||
774 | return adapter->hw.eeprom.word_size * 2; | ||
775 | } | ||
776 | |||
777 | static int ixgbe_get_eeprom(struct net_device *netdev, | ||
778 | struct ethtool_eeprom *eeprom, u8 *bytes) | ||
779 | { | ||
780 | struct ixgbe_adapter *adapter = netdev_priv(netdev); | ||
781 | struct ixgbe_hw *hw = &adapter->hw; | ||
782 | u16 *eeprom_buff; | ||
783 | int first_word, last_word, eeprom_len; | ||
784 | int ret_val = 0; | ||
785 | u16 i; | ||
786 | |||
787 | if (eeprom->len == 0) | ||
788 | return -EINVAL; | ||
789 | |||
790 | eeprom->magic = hw->vendor_id | (hw->device_id << 16); | ||
791 | |||
792 | first_word = eeprom->offset >> 1; | ||
793 | last_word = (eeprom->offset + eeprom->len - 1) >> 1; | ||
794 | eeprom_len = last_word - first_word + 1; | ||
795 | |||
796 | eeprom_buff = kmalloc(sizeof(u16) * eeprom_len, GFP_KERNEL); | ||
797 | if (!eeprom_buff) | ||
798 | return -ENOMEM; | ||
799 | |||
800 | ret_val = hw->eeprom.ops.read_buffer(hw, first_word, eeprom_len, | ||
801 | eeprom_buff); | ||
802 | |||
803 | /* Device's eeprom is always little-endian, word addressable */ | ||
804 | for (i = 0; i < eeprom_len; i++) | ||
805 | le16_to_cpus(&eeprom_buff[i]); | ||
806 | |||
807 | memcpy(bytes, (u8 *)eeprom_buff + (eeprom->offset & 1), eeprom->len); | ||
808 | kfree(eeprom_buff); | ||
809 | |||
810 | return ret_val; | ||
811 | } | ||
812 | |||
813 | static void ixgbe_get_drvinfo(struct net_device *netdev, | ||
814 | struct ethtool_drvinfo *drvinfo) | ||
815 | { | ||
816 | struct ixgbe_adapter *adapter = netdev_priv(netdev); | ||
817 | char firmware_version[32]; | ||
818 | |||
819 | strncpy(drvinfo->driver, ixgbe_driver_name, | ||
820 | sizeof(drvinfo->driver) - 1); | ||
821 | strncpy(drvinfo->version, ixgbe_driver_version, | ||
822 | sizeof(drvinfo->version) - 1); | ||
823 | |||
824 | snprintf(firmware_version, sizeof(firmware_version), "%d.%d-%d", | ||
825 | (adapter->eeprom_version & 0xF000) >> 12, | ||
826 | (adapter->eeprom_version & 0x0FF0) >> 4, | ||
827 | adapter->eeprom_version & 0x000F); | ||
828 | |||
829 | strncpy(drvinfo->fw_version, firmware_version, | ||
830 | sizeof(drvinfo->fw_version)); | ||
831 | strncpy(drvinfo->bus_info, pci_name(adapter->pdev), | ||
832 | sizeof(drvinfo->bus_info)); | ||
833 | drvinfo->n_stats = IXGBE_STATS_LEN; | ||
834 | drvinfo->testinfo_len = IXGBE_TEST_LEN; | ||
835 | drvinfo->regdump_len = ixgbe_get_regs_len(netdev); | ||
836 | } | ||
837 | |||
838 | static void ixgbe_get_ringparam(struct net_device *netdev, | ||
839 | struct ethtool_ringparam *ring) | ||
840 | { | ||
841 | struct ixgbe_adapter *adapter = netdev_priv(netdev); | ||
842 | struct ixgbe_ring *tx_ring = adapter->tx_ring[0]; | ||
843 | struct ixgbe_ring *rx_ring = adapter->rx_ring[0]; | ||
844 | |||
845 | ring->rx_max_pending = IXGBE_MAX_RXD; | ||
846 | ring->tx_max_pending = IXGBE_MAX_TXD; | ||
847 | ring->rx_mini_max_pending = 0; | ||
848 | ring->rx_jumbo_max_pending = 0; | ||
849 | ring->rx_pending = rx_ring->count; | ||
850 | ring->tx_pending = tx_ring->count; | ||
851 | ring->rx_mini_pending = 0; | ||
852 | ring->rx_jumbo_pending = 0; | ||
853 | } | ||
854 | |||
855 | static int ixgbe_set_ringparam(struct net_device *netdev, | ||
856 | struct ethtool_ringparam *ring) | ||
857 | { | ||
858 | struct ixgbe_adapter *adapter = netdev_priv(netdev); | ||
859 | struct ixgbe_ring *temp_tx_ring, *temp_rx_ring; | ||
860 | int i, err = 0; | ||
861 | u32 new_rx_count, new_tx_count; | ||
862 | bool need_update = false; | ||
863 | |||
864 | if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending)) | ||
865 | return -EINVAL; | ||
866 | |||
867 | new_rx_count = max(ring->rx_pending, (u32)IXGBE_MIN_RXD); | ||
868 | new_rx_count = min(new_rx_count, (u32)IXGBE_MAX_RXD); | ||
869 | new_rx_count = ALIGN(new_rx_count, IXGBE_REQ_RX_DESCRIPTOR_MULTIPLE); | ||
870 | |||
871 | new_tx_count = max(ring->tx_pending, (u32)IXGBE_MIN_TXD); | ||
872 | new_tx_count = min(new_tx_count, (u32)IXGBE_MAX_TXD); | ||
873 | new_tx_count = ALIGN(new_tx_count, IXGBE_REQ_TX_DESCRIPTOR_MULTIPLE); | ||
874 | |||
875 | if ((new_tx_count == adapter->tx_ring[0]->count) && | ||
876 | (new_rx_count == adapter->rx_ring[0]->count)) { | ||
877 | /* nothing to do */ | ||
878 | return 0; | ||
879 | } | ||
880 | |||
881 | while (test_and_set_bit(__IXGBE_RESETTING, &adapter->state)) | ||
882 | usleep_range(1000, 2000); | ||
883 | |||
884 | if (!netif_running(adapter->netdev)) { | ||
885 | for (i = 0; i < adapter->num_tx_queues; i++) | ||
886 | adapter->tx_ring[i]->count = new_tx_count; | ||
887 | for (i = 0; i < adapter->num_rx_queues; i++) | ||
888 | adapter->rx_ring[i]->count = new_rx_count; | ||
889 | adapter->tx_ring_count = new_tx_count; | ||
890 | adapter->rx_ring_count = new_rx_count; | ||
891 | goto clear_reset; | ||
892 | } | ||
893 | |||
894 | temp_tx_ring = vmalloc(adapter->num_tx_queues * sizeof(struct ixgbe_ring)); | ||
895 | if (!temp_tx_ring) { | ||
896 | err = -ENOMEM; | ||
897 | goto clear_reset; | ||
898 | } | ||
899 | |||
900 | if (new_tx_count != adapter->tx_ring_count) { | ||
901 | for (i = 0; i < adapter->num_tx_queues; i++) { | ||
902 | memcpy(&temp_tx_ring[i], adapter->tx_ring[i], | ||
903 | sizeof(struct ixgbe_ring)); | ||
904 | temp_tx_ring[i].count = new_tx_count; | ||
905 | err = ixgbe_setup_tx_resources(&temp_tx_ring[i]); | ||
906 | if (err) { | ||
907 | while (i) { | ||
908 | i--; | ||
909 | ixgbe_free_tx_resources(&temp_tx_ring[i]); | ||
910 | } | ||
911 | goto clear_reset; | ||
912 | } | ||
913 | } | ||
914 | need_update = true; | ||
915 | } | ||
916 | |||
917 | temp_rx_ring = vmalloc(adapter->num_rx_queues * sizeof(struct ixgbe_ring)); | ||
918 | if (!temp_rx_ring) { | ||
919 | err = -ENOMEM; | ||
920 | goto err_setup; | ||
921 | } | ||
922 | |||
923 | if (new_rx_count != adapter->rx_ring_count) { | ||
924 | for (i = 0; i < adapter->num_rx_queues; i++) { | ||
925 | memcpy(&temp_rx_ring[i], adapter->rx_ring[i], | ||
926 | sizeof(struct ixgbe_ring)); | ||
927 | temp_rx_ring[i].count = new_rx_count; | ||
928 | err = ixgbe_setup_rx_resources(&temp_rx_ring[i]); | ||
929 | if (err) { | ||
930 | while (i) { | ||
931 | i--; | ||
932 | ixgbe_free_rx_resources(&temp_rx_ring[i]); | ||
933 | } | ||
934 | goto err_setup; | ||
935 | } | ||
936 | } | ||
937 | need_update = true; | ||
938 | } | ||
939 | |||
940 | /* if rings need to be updated, here's the place to do it in one shot */ | ||
941 | if (need_update) { | ||
942 | ixgbe_down(adapter); | ||
943 | |||
944 | /* tx */ | ||
945 | if (new_tx_count != adapter->tx_ring_count) { | ||
946 | for (i = 0; i < adapter->num_tx_queues; i++) { | ||
947 | ixgbe_free_tx_resources(adapter->tx_ring[i]); | ||
948 | memcpy(adapter->tx_ring[i], &temp_tx_ring[i], | ||
949 | sizeof(struct ixgbe_ring)); | ||
950 | } | ||
951 | adapter->tx_ring_count = new_tx_count; | ||
952 | } | ||
953 | |||
954 | /* rx */ | ||
955 | if (new_rx_count != adapter->rx_ring_count) { | ||
956 | for (i = 0; i < adapter->num_rx_queues; i++) { | ||
957 | ixgbe_free_rx_resources(adapter->rx_ring[i]); | ||
958 | memcpy(adapter->rx_ring[i], &temp_rx_ring[i], | ||
959 | sizeof(struct ixgbe_ring)); | ||
960 | } | ||
961 | adapter->rx_ring_count = new_rx_count; | ||
962 | } | ||
963 | ixgbe_up(adapter); | ||
964 | } | ||
965 | |||
966 | vfree(temp_rx_ring); | ||
967 | err_setup: | ||
968 | vfree(temp_tx_ring); | ||
969 | clear_reset: | ||
970 | clear_bit(__IXGBE_RESETTING, &adapter->state); | ||
971 | return err; | ||
972 | } | ||
973 | |||
974 | static int ixgbe_get_sset_count(struct net_device *netdev, int sset) | ||
975 | { | ||
976 | switch (sset) { | ||
977 | case ETH_SS_TEST: | ||
978 | return IXGBE_TEST_LEN; | ||
979 | case ETH_SS_STATS: | ||
980 | return IXGBE_STATS_LEN; | ||
981 | default: | ||
982 | return -EOPNOTSUPP; | ||
983 | } | ||
984 | } | ||
985 | |||
986 | static void ixgbe_get_ethtool_stats(struct net_device *netdev, | ||
987 | struct ethtool_stats *stats, u64 *data) | ||
988 | { | ||
989 | struct ixgbe_adapter *adapter = netdev_priv(netdev); | ||
990 | struct rtnl_link_stats64 temp; | ||
991 | const struct rtnl_link_stats64 *net_stats; | ||
992 | unsigned int start; | ||
993 | struct ixgbe_ring *ring; | ||
994 | int i, j; | ||
995 | char *p = NULL; | ||
996 | |||
997 | ixgbe_update_stats(adapter); | ||
998 | net_stats = dev_get_stats(netdev, &temp); | ||
999 | for (i = 0; i < IXGBE_GLOBAL_STATS_LEN; i++) { | ||
1000 | switch (ixgbe_gstrings_stats[i].type) { | ||
1001 | case NETDEV_STATS: | ||
1002 | p = (char *) net_stats + | ||
1003 | ixgbe_gstrings_stats[i].stat_offset; | ||
1004 | break; | ||
1005 | case IXGBE_STATS: | ||
1006 | p = (char *) adapter + | ||
1007 | ixgbe_gstrings_stats[i].stat_offset; | ||
1008 | break; | ||
1009 | } | ||
1010 | |||
1011 | data[i] = (ixgbe_gstrings_stats[i].sizeof_stat == | ||
1012 | sizeof(u64)) ? *(u64 *)p : *(u32 *)p; | ||
1013 | } | ||
1014 | for (j = 0; j < adapter->num_tx_queues; j++) { | ||
1015 | ring = adapter->tx_ring[j]; | ||
1016 | do { | ||
1017 | start = u64_stats_fetch_begin_bh(&ring->syncp); | ||
1018 | data[i] = ring->stats.packets; | ||
1019 | data[i+1] = ring->stats.bytes; | ||
1020 | } while (u64_stats_fetch_retry_bh(&ring->syncp, start)); | ||
1021 | i += 2; | ||
1022 | } | ||
1023 | for (j = 0; j < adapter->num_rx_queues; j++) { | ||
1024 | ring = adapter->rx_ring[j]; | ||
1025 | do { | ||
1026 | start = u64_stats_fetch_begin_bh(&ring->syncp); | ||
1027 | data[i] = ring->stats.packets; | ||
1028 | data[i+1] = ring->stats.bytes; | ||
1029 | } while (u64_stats_fetch_retry_bh(&ring->syncp, start)); | ||
1030 | i += 2; | ||
1031 | } | ||
1032 | if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) { | ||
1033 | for (j = 0; j < MAX_TX_PACKET_BUFFERS; j++) { | ||
1034 | data[i++] = adapter->stats.pxontxc[j]; | ||
1035 | data[i++] = adapter->stats.pxofftxc[j]; | ||
1036 | } | ||
1037 | for (j = 0; j < MAX_RX_PACKET_BUFFERS; j++) { | ||
1038 | data[i++] = adapter->stats.pxonrxc[j]; | ||
1039 | data[i++] = adapter->stats.pxoffrxc[j]; | ||
1040 | } | ||
1041 | } | ||
1042 | } | ||
1043 | |||
1044 | static void ixgbe_get_strings(struct net_device *netdev, u32 stringset, | ||
1045 | u8 *data) | ||
1046 | { | ||
1047 | struct ixgbe_adapter *adapter = netdev_priv(netdev); | ||
1048 | char *p = (char *)data; | ||
1049 | int i; | ||
1050 | |||
1051 | switch (stringset) { | ||
1052 | case ETH_SS_TEST: | ||
1053 | memcpy(data, *ixgbe_gstrings_test, | ||
1054 | IXGBE_TEST_LEN * ETH_GSTRING_LEN); | ||
1055 | break; | ||
1056 | case ETH_SS_STATS: | ||
1057 | for (i = 0; i < IXGBE_GLOBAL_STATS_LEN; i++) { | ||
1058 | memcpy(p, ixgbe_gstrings_stats[i].stat_string, | ||
1059 | ETH_GSTRING_LEN); | ||
1060 | p += ETH_GSTRING_LEN; | ||
1061 | } | ||
1062 | for (i = 0; i < adapter->num_tx_queues; i++) { | ||
1063 | sprintf(p, "tx_queue_%u_packets", i); | ||
1064 | p += ETH_GSTRING_LEN; | ||
1065 | sprintf(p, "tx_queue_%u_bytes", i); | ||
1066 | p += ETH_GSTRING_LEN; | ||
1067 | } | ||
1068 | for (i = 0; i < adapter->num_rx_queues; i++) { | ||
1069 | sprintf(p, "rx_queue_%u_packets", i); | ||
1070 | p += ETH_GSTRING_LEN; | ||
1071 | sprintf(p, "rx_queue_%u_bytes", i); | ||
1072 | p += ETH_GSTRING_LEN; | ||
1073 | } | ||
1074 | if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) { | ||
1075 | for (i = 0; i < MAX_TX_PACKET_BUFFERS; i++) { | ||
1076 | sprintf(p, "tx_pb_%u_pxon", i); | ||
1077 | p += ETH_GSTRING_LEN; | ||
1078 | sprintf(p, "tx_pb_%u_pxoff", i); | ||
1079 | p += ETH_GSTRING_LEN; | ||
1080 | } | ||
1081 | for (i = 0; i < MAX_RX_PACKET_BUFFERS; i++) { | ||
1082 | sprintf(p, "rx_pb_%u_pxon", i); | ||
1083 | p += ETH_GSTRING_LEN; | ||
1084 | sprintf(p, "rx_pb_%u_pxoff", i); | ||
1085 | p += ETH_GSTRING_LEN; | ||
1086 | } | ||
1087 | } | ||
1088 | /* BUG_ON(p - data != IXGBE_STATS_LEN * ETH_GSTRING_LEN); */ | ||
1089 | break; | ||
1090 | } | ||
1091 | } | ||
1092 | |||
1093 | static int ixgbe_link_test(struct ixgbe_adapter *adapter, u64 *data) | ||
1094 | { | ||
1095 | struct ixgbe_hw *hw = &adapter->hw; | ||
1096 | bool link_up; | ||
1097 | u32 link_speed = 0; | ||
1098 | *data = 0; | ||
1099 | |||
1100 | hw->mac.ops.check_link(hw, &link_speed, &link_up, true); | ||
1101 | if (link_up) | ||
1102 | return *data; | ||
1103 | else | ||
1104 | *data = 1; | ||
1105 | return *data; | ||
1106 | } | ||
1107 | |||
1108 | /* ethtool register test data */ | ||
1109 | struct ixgbe_reg_test { | ||
1110 | u16 reg; | ||
1111 | u8 array_len; | ||
1112 | u8 test_type; | ||
1113 | u32 mask; | ||
1114 | u32 write; | ||
1115 | }; | ||
1116 | |||
1117 | /* In the hardware, registers are laid out either singly, in arrays | ||
1118 | * spaced 0x40 bytes apart, or in contiguous tables. We assume | ||
1119 | * most tests take place on arrays or single registers (handled | ||
1120 | * as a single-element array) and special-case the tables. | ||
1121 | * Table tests are always pattern tests. | ||
1122 | * | ||
1123 | * We also make provision for some required setup steps by specifying | ||
1124 | * registers to be written without any read-back testing. | ||
1125 | */ | ||
1126 | |||
1127 | #define PATTERN_TEST 1 | ||
1128 | #define SET_READ_TEST 2 | ||
1129 | #define WRITE_NO_TEST 3 | ||
1130 | #define TABLE32_TEST 4 | ||
1131 | #define TABLE64_TEST_LO 5 | ||
1132 | #define TABLE64_TEST_HI 6 | ||
1133 | |||
1134 | /* default 82599 register test */ | ||
1135 | static const struct ixgbe_reg_test reg_test_82599[] = { | ||
1136 | { IXGBE_FCRTL_82599(0), 1, PATTERN_TEST, 0x8007FFF0, 0x8007FFF0 }, | ||
1137 | { IXGBE_FCRTH_82599(0), 1, PATTERN_TEST, 0x8007FFF0, 0x8007FFF0 }, | ||
1138 | { IXGBE_PFCTOP, 1, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF }, | ||
1139 | { IXGBE_VLNCTRL, 1, PATTERN_TEST, 0x00000000, 0x00000000 }, | ||
1140 | { IXGBE_RDBAL(0), 4, PATTERN_TEST, 0xFFFFFF80, 0xFFFFFF80 }, | ||
1141 | { IXGBE_RDBAH(0), 4, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF }, | ||
1142 | { IXGBE_RDLEN(0), 4, PATTERN_TEST, 0x000FFF80, 0x000FFFFF }, | ||
1143 | { IXGBE_RXDCTL(0), 4, WRITE_NO_TEST, 0, IXGBE_RXDCTL_ENABLE }, | ||
1144 | { IXGBE_RDT(0), 4, PATTERN_TEST, 0x0000FFFF, 0x0000FFFF }, | ||
1145 | { IXGBE_RXDCTL(0), 4, WRITE_NO_TEST, 0, 0 }, | ||
1146 | { IXGBE_FCRTH(0), 1, PATTERN_TEST, 0x8007FFF0, 0x8007FFF0 }, | ||
1147 | { IXGBE_FCTTV(0), 1, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF }, | ||
1148 | { IXGBE_TDBAL(0), 4, PATTERN_TEST, 0xFFFFFF80, 0xFFFFFFFF }, | ||
1149 | { IXGBE_TDBAH(0), 4, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF }, | ||
1150 | { IXGBE_TDLEN(0), 4, PATTERN_TEST, 0x000FFF80, 0x000FFF80 }, | ||
1151 | { IXGBE_RXCTRL, 1, SET_READ_TEST, 0x00000001, 0x00000001 }, | ||
1152 | { IXGBE_RAL(0), 16, TABLE64_TEST_LO, 0xFFFFFFFF, 0xFFFFFFFF }, | ||
1153 | { IXGBE_RAL(0), 16, TABLE64_TEST_HI, 0x8001FFFF, 0x800CFFFF }, | ||
1154 | { IXGBE_MTA(0), 128, TABLE32_TEST, 0xFFFFFFFF, 0xFFFFFFFF }, | ||
1155 | { 0, 0, 0, 0 } | ||
1156 | }; | ||
1157 | |||
1158 | /* default 82598 register test */ | ||
1159 | static const struct ixgbe_reg_test reg_test_82598[] = { | ||
1160 | { IXGBE_FCRTL(0), 1, PATTERN_TEST, 0x8007FFF0, 0x8007FFF0 }, | ||
1161 | { IXGBE_FCRTH(0), 1, PATTERN_TEST, 0x8007FFF0, 0x8007FFF0 }, | ||
1162 | { IXGBE_PFCTOP, 1, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF }, | ||
1163 | { IXGBE_VLNCTRL, 1, PATTERN_TEST, 0x00000000, 0x00000000 }, | ||
1164 | { IXGBE_RDBAL(0), 4, PATTERN_TEST, 0xFFFFFF80, 0xFFFFFFFF }, | ||
1165 | { IXGBE_RDBAH(0), 4, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF }, | ||
1166 | { IXGBE_RDLEN(0), 4, PATTERN_TEST, 0x000FFF80, 0x000FFFFF }, | ||
1167 | /* Enable all four RX queues before testing. */ | ||
1168 | { IXGBE_RXDCTL(0), 4, WRITE_NO_TEST, 0, IXGBE_RXDCTL_ENABLE }, | ||
1169 | /* RDH is read-only for 82598, only test RDT. */ | ||
1170 | { IXGBE_RDT(0), 4, PATTERN_TEST, 0x0000FFFF, 0x0000FFFF }, | ||
1171 | { IXGBE_RXDCTL(0), 4, WRITE_NO_TEST, 0, 0 }, | ||
1172 | { IXGBE_FCRTH(0), 1, PATTERN_TEST, 0x8007FFF0, 0x8007FFF0 }, | ||
1173 | { IXGBE_FCTTV(0), 1, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF }, | ||
1174 | { IXGBE_TIPG, 1, PATTERN_TEST, 0x000000FF, 0x000000FF }, | ||
1175 | { IXGBE_TDBAL(0), 4, PATTERN_TEST, 0xFFFFFF80, 0xFFFFFFFF }, | ||
1176 | { IXGBE_TDBAH(0), 4, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF }, | ||
1177 | { IXGBE_TDLEN(0), 4, PATTERN_TEST, 0x000FFF80, 0x000FFFFF }, | ||
1178 | { IXGBE_RXCTRL, 1, SET_READ_TEST, 0x00000003, 0x00000003 }, | ||
1179 | { IXGBE_DTXCTL, 1, SET_READ_TEST, 0x00000005, 0x00000005 }, | ||
1180 | { IXGBE_RAL(0), 16, TABLE64_TEST_LO, 0xFFFFFFFF, 0xFFFFFFFF }, | ||
1181 | { IXGBE_RAL(0), 16, TABLE64_TEST_HI, 0x800CFFFF, 0x800CFFFF }, | ||
1182 | { IXGBE_MTA(0), 128, TABLE32_TEST, 0xFFFFFFFF, 0xFFFFFFFF }, | ||
1183 | { 0, 0, 0, 0 } | ||
1184 | }; | ||
1185 | |||
1186 | static bool reg_pattern_test(struct ixgbe_adapter *adapter, u64 *data, int reg, | ||
1187 | u32 mask, u32 write) | ||
1188 | { | ||
1189 | u32 pat, val, before; | ||
1190 | static const u32 test_pattern[] = { | ||
1191 | 0x5A5A5A5A, 0xA5A5A5A5, 0x00000000, 0xFFFFFFFF}; | ||
1192 | |||
1193 | for (pat = 0; pat < ARRAY_SIZE(test_pattern); pat++) { | ||
1194 | before = readl(adapter->hw.hw_addr + reg); | ||
1195 | writel((test_pattern[pat] & write), | ||
1196 | (adapter->hw.hw_addr + reg)); | ||
1197 | val = readl(adapter->hw.hw_addr + reg); | ||
1198 | if (val != (test_pattern[pat] & write & mask)) { | ||
1199 | e_err(drv, "pattern test reg %04X failed: got " | ||
1200 | "0x%08X expected 0x%08X\n", | ||
1201 | reg, val, (test_pattern[pat] & write & mask)); | ||
1202 | *data = reg; | ||
1203 | writel(before, adapter->hw.hw_addr + reg); | ||
1204 | return 1; | ||
1205 | } | ||
1206 | writel(before, adapter->hw.hw_addr + reg); | ||
1207 | } | ||
1208 | return 0; | ||
1209 | } | ||
1210 | |||
1211 | static bool reg_set_and_check(struct ixgbe_adapter *adapter, u64 *data, int reg, | ||
1212 | u32 mask, u32 write) | ||
1213 | { | ||
1214 | u32 val, before; | ||
1215 | before = readl(adapter->hw.hw_addr + reg); | ||
1216 | writel((write & mask), (adapter->hw.hw_addr + reg)); | ||
1217 | val = readl(adapter->hw.hw_addr + reg); | ||
1218 | if ((write & mask) != (val & mask)) { | ||
1219 | e_err(drv, "set/check reg %04X test failed: got 0x%08X " | ||
1220 | "expected 0x%08X\n", reg, (val & mask), (write & mask)); | ||
1221 | *data = reg; | ||
1222 | writel(before, (adapter->hw.hw_addr + reg)); | ||
1223 | return 1; | ||
1224 | } | ||
1225 | writel(before, (adapter->hw.hw_addr + reg)); | ||
1226 | return 0; | ||
1227 | } | ||
1228 | |||
1229 | #define REG_PATTERN_TEST(reg, mask, write) \ | ||
1230 | do { \ | ||
1231 | if (reg_pattern_test(adapter, data, reg, mask, write)) \ | ||
1232 | return 1; \ | ||
1233 | } while (0) \ | ||
1234 | |||
1235 | |||
1236 | #define REG_SET_AND_CHECK(reg, mask, write) \ | ||
1237 | do { \ | ||
1238 | if (reg_set_and_check(adapter, data, reg, mask, write)) \ | ||
1239 | return 1; \ | ||
1240 | } while (0) \ | ||
1241 | |||
1242 | static int ixgbe_reg_test(struct ixgbe_adapter *adapter, u64 *data) | ||
1243 | { | ||
1244 | const struct ixgbe_reg_test *test; | ||
1245 | u32 value, before, after; | ||
1246 | u32 i, toggle; | ||
1247 | |||
1248 | switch (adapter->hw.mac.type) { | ||
1249 | case ixgbe_mac_82598EB: | ||
1250 | toggle = 0x7FFFF3FF; | ||
1251 | test = reg_test_82598; | ||
1252 | break; | ||
1253 | case ixgbe_mac_82599EB: | ||
1254 | case ixgbe_mac_X540: | ||
1255 | toggle = 0x7FFFF30F; | ||
1256 | test = reg_test_82599; | ||
1257 | break; | ||
1258 | default: | ||
1259 | *data = 1; | ||
1260 | return 1; | ||
1261 | break; | ||
1262 | } | ||
1263 | |||
1264 | /* | ||
1265 | * Because the status register is such a special case, | ||
1266 | * we handle it separately from the rest of the register | ||
1267 | * tests. Some bits are read-only, some toggle, and some | ||
1268 | * are writeable on newer MACs. | ||
1269 | */ | ||
1270 | before = IXGBE_READ_REG(&adapter->hw, IXGBE_STATUS); | ||
1271 | value = (IXGBE_READ_REG(&adapter->hw, IXGBE_STATUS) & toggle); | ||
1272 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_STATUS, toggle); | ||
1273 | after = IXGBE_READ_REG(&adapter->hw, IXGBE_STATUS) & toggle; | ||
1274 | if (value != after) { | ||
1275 | e_err(drv, "failed STATUS register test got: 0x%08X " | ||
1276 | "expected: 0x%08X\n", after, value); | ||
1277 | *data = 1; | ||
1278 | return 1; | ||
1279 | } | ||
1280 | /* restore previous status */ | ||
1281 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_STATUS, before); | ||
1282 | |||
1283 | /* | ||
1284 | * Perform the remainder of the register test, looping through | ||
1285 | * the test table until we either fail or reach the null entry. | ||
1286 | */ | ||
1287 | while (test->reg) { | ||
1288 | for (i = 0; i < test->array_len; i++) { | ||
1289 | switch (test->test_type) { | ||
1290 | case PATTERN_TEST: | ||
1291 | REG_PATTERN_TEST(test->reg + (i * 0x40), | ||
1292 | test->mask, | ||
1293 | test->write); | ||
1294 | break; | ||
1295 | case SET_READ_TEST: | ||
1296 | REG_SET_AND_CHECK(test->reg + (i * 0x40), | ||
1297 | test->mask, | ||
1298 | test->write); | ||
1299 | break; | ||
1300 | case WRITE_NO_TEST: | ||
1301 | writel(test->write, | ||
1302 | (adapter->hw.hw_addr + test->reg) | ||
1303 | + (i * 0x40)); | ||
1304 | break; | ||
1305 | case TABLE32_TEST: | ||
1306 | REG_PATTERN_TEST(test->reg + (i * 4), | ||
1307 | test->mask, | ||
1308 | test->write); | ||
1309 | break; | ||
1310 | case TABLE64_TEST_LO: | ||
1311 | REG_PATTERN_TEST(test->reg + (i * 8), | ||
1312 | test->mask, | ||
1313 | test->write); | ||
1314 | break; | ||
1315 | case TABLE64_TEST_HI: | ||
1316 | REG_PATTERN_TEST((test->reg + 4) + (i * 8), | ||
1317 | test->mask, | ||
1318 | test->write); | ||
1319 | break; | ||
1320 | } | ||
1321 | } | ||
1322 | test++; | ||
1323 | } | ||
1324 | |||
1325 | *data = 0; | ||
1326 | return 0; | ||
1327 | } | ||
1328 | |||
1329 | static int ixgbe_eeprom_test(struct ixgbe_adapter *adapter, u64 *data) | ||
1330 | { | ||
1331 | struct ixgbe_hw *hw = &adapter->hw; | ||
1332 | if (hw->eeprom.ops.validate_checksum(hw, NULL)) | ||
1333 | *data = 1; | ||
1334 | else | ||
1335 | *data = 0; | ||
1336 | return *data; | ||
1337 | } | ||
1338 | |||
1339 | static irqreturn_t ixgbe_test_intr(int irq, void *data) | ||
1340 | { | ||
1341 | struct net_device *netdev = (struct net_device *) data; | ||
1342 | struct ixgbe_adapter *adapter = netdev_priv(netdev); | ||
1343 | |||
1344 | adapter->test_icr |= IXGBE_READ_REG(&adapter->hw, IXGBE_EICR); | ||
1345 | |||
1346 | return IRQ_HANDLED; | ||
1347 | } | ||
1348 | |||
1349 | static int ixgbe_intr_test(struct ixgbe_adapter *adapter, u64 *data) | ||
1350 | { | ||
1351 | struct net_device *netdev = adapter->netdev; | ||
1352 | u32 mask, i = 0, shared_int = true; | ||
1353 | u32 irq = adapter->pdev->irq; | ||
1354 | |||
1355 | *data = 0; | ||
1356 | |||
1357 | /* Hook up test interrupt handler just for this test */ | ||
1358 | if (adapter->msix_entries) { | ||
1359 | /* NOTE: we don't test MSI-X interrupts here, yet */ | ||
1360 | return 0; | ||
1361 | } else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED) { | ||
1362 | shared_int = false; | ||
1363 | if (request_irq(irq, ixgbe_test_intr, 0, netdev->name, | ||
1364 | netdev)) { | ||
1365 | *data = 1; | ||
1366 | return -1; | ||
1367 | } | ||
1368 | } else if (!request_irq(irq, ixgbe_test_intr, IRQF_PROBE_SHARED, | ||
1369 | netdev->name, netdev)) { | ||
1370 | shared_int = false; | ||
1371 | } else if (request_irq(irq, ixgbe_test_intr, IRQF_SHARED, | ||
1372 | netdev->name, netdev)) { | ||
1373 | *data = 1; | ||
1374 | return -1; | ||
1375 | } | ||
1376 | e_info(hw, "testing %s interrupt\n", shared_int ? | ||
1377 | "shared" : "unshared"); | ||
1378 | |||
1379 | /* Disable all the interrupts */ | ||
1380 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, 0xFFFFFFFF); | ||
1381 | IXGBE_WRITE_FLUSH(&adapter->hw); | ||
1382 | usleep_range(10000, 20000); | ||
1383 | |||
1384 | /* Test each interrupt */ | ||
1385 | for (; i < 10; i++) { | ||
1386 | /* Interrupt to test */ | ||
1387 | mask = 1 << i; | ||
1388 | |||
1389 | if (!shared_int) { | ||
1390 | /* | ||
1391 | * Disable the interrupts to be reported in | ||
1392 | * the cause register and then force the same | ||
1393 | * interrupt and see if one gets posted. If | ||
1394 | * an interrupt was posted to the bus, the | ||
1395 | * test failed. | ||
1396 | */ | ||
1397 | adapter->test_icr = 0; | ||
1398 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, | ||
1399 | ~mask & 0x00007FFF); | ||
1400 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS, | ||
1401 | ~mask & 0x00007FFF); | ||
1402 | IXGBE_WRITE_FLUSH(&adapter->hw); | ||
1403 | usleep_range(10000, 20000); | ||
1404 | |||
1405 | if (adapter->test_icr & mask) { | ||
1406 | *data = 3; | ||
1407 | break; | ||
1408 | } | ||
1409 | } | ||
1410 | |||
1411 | /* | ||
1412 | * Enable the interrupt to be reported in the cause | ||
1413 | * register and then force the same interrupt and see | ||
1414 | * if one gets posted. If an interrupt was not posted | ||
1415 | * to the bus, the test failed. | ||
1416 | */ | ||
1417 | adapter->test_icr = 0; | ||
1418 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, mask); | ||
1419 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS, mask); | ||
1420 | IXGBE_WRITE_FLUSH(&adapter->hw); | ||
1421 | usleep_range(10000, 20000); | ||
1422 | |||
1423 | if (!(adapter->test_icr &mask)) { | ||
1424 | *data = 4; | ||
1425 | break; | ||
1426 | } | ||
1427 | |||
1428 | if (!shared_int) { | ||
1429 | /* | ||
1430 | * Disable the other interrupts to be reported in | ||
1431 | * the cause register and then force the other | ||
1432 | * interrupts and see if any get posted. If | ||
1433 | * an interrupt was posted to the bus, the | ||
1434 | * test failed. | ||
1435 | */ | ||
1436 | adapter->test_icr = 0; | ||
1437 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, | ||
1438 | ~mask & 0x00007FFF); | ||
1439 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS, | ||
1440 | ~mask & 0x00007FFF); | ||
1441 | IXGBE_WRITE_FLUSH(&adapter->hw); | ||
1442 | usleep_range(10000, 20000); | ||
1443 | |||
1444 | if (adapter->test_icr) { | ||
1445 | *data = 5; | ||
1446 | break; | ||
1447 | } | ||
1448 | } | ||
1449 | } | ||
1450 | |||
1451 | /* Disable all the interrupts */ | ||
1452 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, 0xFFFFFFFF); | ||
1453 | IXGBE_WRITE_FLUSH(&adapter->hw); | ||
1454 | usleep_range(10000, 20000); | ||
1455 | |||
1456 | /* Unhook test interrupt handler */ | ||
1457 | free_irq(irq, netdev); | ||
1458 | |||
1459 | return *data; | ||
1460 | } | ||
1461 | |||
1462 | static void ixgbe_free_desc_rings(struct ixgbe_adapter *adapter) | ||
1463 | { | ||
1464 | struct ixgbe_ring *tx_ring = &adapter->test_tx_ring; | ||
1465 | struct ixgbe_ring *rx_ring = &adapter->test_rx_ring; | ||
1466 | struct ixgbe_hw *hw = &adapter->hw; | ||
1467 | u32 reg_ctl; | ||
1468 | |||
1469 | /* shut down the DMA engines now so they can be reinitialized later */ | ||
1470 | |||
1471 | /* first Rx */ | ||
1472 | reg_ctl = IXGBE_READ_REG(hw, IXGBE_RXCTRL); | ||
1473 | reg_ctl &= ~IXGBE_RXCTRL_RXEN; | ||
1474 | IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, reg_ctl); | ||
1475 | ixgbe_disable_rx_queue(adapter, rx_ring); | ||
1476 | |||
1477 | /* now Tx */ | ||
1478 | reg_ctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(tx_ring->reg_idx)); | ||
1479 | reg_ctl &= ~IXGBE_TXDCTL_ENABLE; | ||
1480 | IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(tx_ring->reg_idx), reg_ctl); | ||
1481 | |||
1482 | switch (hw->mac.type) { | ||
1483 | case ixgbe_mac_82599EB: | ||
1484 | case ixgbe_mac_X540: | ||
1485 | reg_ctl = IXGBE_READ_REG(hw, IXGBE_DMATXCTL); | ||
1486 | reg_ctl &= ~IXGBE_DMATXCTL_TE; | ||
1487 | IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, reg_ctl); | ||
1488 | break; | ||
1489 | default: | ||
1490 | break; | ||
1491 | } | ||
1492 | |||
1493 | ixgbe_reset(adapter); | ||
1494 | |||
1495 | ixgbe_free_tx_resources(&adapter->test_tx_ring); | ||
1496 | ixgbe_free_rx_resources(&adapter->test_rx_ring); | ||
1497 | } | ||
1498 | |||
1499 | static int ixgbe_setup_desc_rings(struct ixgbe_adapter *adapter) | ||
1500 | { | ||
1501 | struct ixgbe_ring *tx_ring = &adapter->test_tx_ring; | ||
1502 | struct ixgbe_ring *rx_ring = &adapter->test_rx_ring; | ||
1503 | u32 rctl, reg_data; | ||
1504 | int ret_val; | ||
1505 | int err; | ||
1506 | |||
1507 | /* Setup Tx descriptor ring and Tx buffers */ | ||
1508 | tx_ring->count = IXGBE_DEFAULT_TXD; | ||
1509 | tx_ring->queue_index = 0; | ||
1510 | tx_ring->dev = &adapter->pdev->dev; | ||
1511 | tx_ring->netdev = adapter->netdev; | ||
1512 | tx_ring->reg_idx = adapter->tx_ring[0]->reg_idx; | ||
1513 | tx_ring->numa_node = adapter->node; | ||
1514 | |||
1515 | err = ixgbe_setup_tx_resources(tx_ring); | ||
1516 | if (err) | ||
1517 | return 1; | ||
1518 | |||
1519 | switch (adapter->hw.mac.type) { | ||
1520 | case ixgbe_mac_82599EB: | ||
1521 | case ixgbe_mac_X540: | ||
1522 | reg_data = IXGBE_READ_REG(&adapter->hw, IXGBE_DMATXCTL); | ||
1523 | reg_data |= IXGBE_DMATXCTL_TE; | ||
1524 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_DMATXCTL, reg_data); | ||
1525 | break; | ||
1526 | default: | ||
1527 | break; | ||
1528 | } | ||
1529 | |||
1530 | ixgbe_configure_tx_ring(adapter, tx_ring); | ||
1531 | |||
1532 | /* Setup Rx Descriptor ring and Rx buffers */ | ||
1533 | rx_ring->count = IXGBE_DEFAULT_RXD; | ||
1534 | rx_ring->queue_index = 0; | ||
1535 | rx_ring->dev = &adapter->pdev->dev; | ||
1536 | rx_ring->netdev = adapter->netdev; | ||
1537 | rx_ring->reg_idx = adapter->rx_ring[0]->reg_idx; | ||
1538 | rx_ring->rx_buf_len = IXGBE_RXBUFFER_2048; | ||
1539 | rx_ring->numa_node = adapter->node; | ||
1540 | |||
1541 | err = ixgbe_setup_rx_resources(rx_ring); | ||
1542 | if (err) { | ||
1543 | ret_val = 4; | ||
1544 | goto err_nomem; | ||
1545 | } | ||
1546 | |||
1547 | rctl = IXGBE_READ_REG(&adapter->hw, IXGBE_RXCTRL); | ||
1548 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_RXCTRL, rctl & ~IXGBE_RXCTRL_RXEN); | ||
1549 | |||
1550 | ixgbe_configure_rx_ring(adapter, rx_ring); | ||
1551 | |||
1552 | rctl |= IXGBE_RXCTRL_RXEN | IXGBE_RXCTRL_DMBYPS; | ||
1553 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_RXCTRL, rctl); | ||
1554 | |||
1555 | return 0; | ||
1556 | |||
1557 | err_nomem: | ||
1558 | ixgbe_free_desc_rings(adapter); | ||
1559 | return ret_val; | ||
1560 | } | ||
1561 | |||
1562 | static int ixgbe_setup_loopback_test(struct ixgbe_adapter *adapter) | ||
1563 | { | ||
1564 | struct ixgbe_hw *hw = &adapter->hw; | ||
1565 | u32 reg_data; | ||
1566 | |||
1567 | /* X540 needs to set the MACC.FLU bit to force link up */ | ||
1568 | if (adapter->hw.mac.type == ixgbe_mac_X540) { | ||
1569 | reg_data = IXGBE_READ_REG(&adapter->hw, IXGBE_MACC); | ||
1570 | reg_data |= IXGBE_MACC_FLU; | ||
1571 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_MACC, reg_data); | ||
1572 | } | ||
1573 | |||
1574 | /* right now we only support MAC loopback in the driver */ | ||
1575 | reg_data = IXGBE_READ_REG(&adapter->hw, IXGBE_HLREG0); | ||
1576 | /* Setup MAC loopback */ | ||
1577 | reg_data |= IXGBE_HLREG0_LPBK; | ||
1578 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_HLREG0, reg_data); | ||
1579 | |||
1580 | reg_data = IXGBE_READ_REG(&adapter->hw, IXGBE_FCTRL); | ||
1581 | reg_data |= IXGBE_FCTRL_BAM | IXGBE_FCTRL_SBP | IXGBE_FCTRL_MPE; | ||
1582 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_FCTRL, reg_data); | ||
1583 | |||
1584 | reg_data = IXGBE_READ_REG(&adapter->hw, IXGBE_AUTOC); | ||
1585 | reg_data &= ~IXGBE_AUTOC_LMS_MASK; | ||
1586 | reg_data |= IXGBE_AUTOC_LMS_10G_LINK_NO_AN | IXGBE_AUTOC_FLU; | ||
1587 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_AUTOC, reg_data); | ||
1588 | IXGBE_WRITE_FLUSH(&adapter->hw); | ||
1589 | usleep_range(10000, 20000); | ||
1590 | |||
1591 | /* Disable Atlas Tx lanes; re-enabled in reset path */ | ||
1592 | if (hw->mac.type == ixgbe_mac_82598EB) { | ||
1593 | u8 atlas; | ||
1594 | |||
1595 | hw->mac.ops.read_analog_reg8(hw, IXGBE_ATLAS_PDN_LPBK, &atlas); | ||
1596 | atlas |= IXGBE_ATLAS_PDN_TX_REG_EN; | ||
1597 | hw->mac.ops.write_analog_reg8(hw, IXGBE_ATLAS_PDN_LPBK, atlas); | ||
1598 | |||
1599 | hw->mac.ops.read_analog_reg8(hw, IXGBE_ATLAS_PDN_10G, &atlas); | ||
1600 | atlas |= IXGBE_ATLAS_PDN_TX_10G_QL_ALL; | ||
1601 | hw->mac.ops.write_analog_reg8(hw, IXGBE_ATLAS_PDN_10G, atlas); | ||
1602 | |||
1603 | hw->mac.ops.read_analog_reg8(hw, IXGBE_ATLAS_PDN_1G, &atlas); | ||
1604 | atlas |= IXGBE_ATLAS_PDN_TX_1G_QL_ALL; | ||
1605 | hw->mac.ops.write_analog_reg8(hw, IXGBE_ATLAS_PDN_1G, atlas); | ||
1606 | |||
1607 | hw->mac.ops.read_analog_reg8(hw, IXGBE_ATLAS_PDN_AN, &atlas); | ||
1608 | atlas |= IXGBE_ATLAS_PDN_TX_AN_QL_ALL; | ||
1609 | hw->mac.ops.write_analog_reg8(hw, IXGBE_ATLAS_PDN_AN, atlas); | ||
1610 | } | ||
1611 | |||
1612 | return 0; | ||
1613 | } | ||
1614 | |||
1615 | static void ixgbe_loopback_cleanup(struct ixgbe_adapter *adapter) | ||
1616 | { | ||
1617 | u32 reg_data; | ||
1618 | |||
1619 | reg_data = IXGBE_READ_REG(&adapter->hw, IXGBE_HLREG0); | ||
1620 | reg_data &= ~IXGBE_HLREG0_LPBK; | ||
1621 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_HLREG0, reg_data); | ||
1622 | } | ||
1623 | |||
1624 | static void ixgbe_create_lbtest_frame(struct sk_buff *skb, | ||
1625 | unsigned int frame_size) | ||
1626 | { | ||
1627 | memset(skb->data, 0xFF, frame_size); | ||
1628 | frame_size &= ~1; | ||
1629 | memset(&skb->data[frame_size / 2], 0xAA, frame_size / 2 - 1); | ||
1630 | memset(&skb->data[frame_size / 2 + 10], 0xBE, 1); | ||
1631 | memset(&skb->data[frame_size / 2 + 12], 0xAF, 1); | ||
1632 | } | ||
1633 | |||
1634 | static int ixgbe_check_lbtest_frame(struct sk_buff *skb, | ||
1635 | unsigned int frame_size) | ||
1636 | { | ||
1637 | frame_size &= ~1; | ||
1638 | if (*(skb->data + 3) == 0xFF) { | ||
1639 | if ((*(skb->data + frame_size / 2 + 10) == 0xBE) && | ||
1640 | (*(skb->data + frame_size / 2 + 12) == 0xAF)) { | ||
1641 | return 0; | ||
1642 | } | ||
1643 | } | ||
1644 | return 13; | ||
1645 | } | ||
1646 | |||
1647 | static u16 ixgbe_clean_test_rings(struct ixgbe_ring *rx_ring, | ||
1648 | struct ixgbe_ring *tx_ring, | ||
1649 | unsigned int size) | ||
1650 | { | ||
1651 | union ixgbe_adv_rx_desc *rx_desc; | ||
1652 | struct ixgbe_rx_buffer *rx_buffer_info; | ||
1653 | struct ixgbe_tx_buffer *tx_buffer_info; | ||
1654 | const int bufsz = rx_ring->rx_buf_len; | ||
1655 | u32 staterr; | ||
1656 | u16 rx_ntc, tx_ntc, count = 0; | ||
1657 | |||
1658 | /* initialize next to clean and descriptor values */ | ||
1659 | rx_ntc = rx_ring->next_to_clean; | ||
1660 | tx_ntc = tx_ring->next_to_clean; | ||
1661 | rx_desc = IXGBE_RX_DESC_ADV(rx_ring, rx_ntc); | ||
1662 | staterr = le32_to_cpu(rx_desc->wb.upper.status_error); | ||
1663 | |||
1664 | while (staterr & IXGBE_RXD_STAT_DD) { | ||
1665 | /* check Rx buffer */ | ||
1666 | rx_buffer_info = &rx_ring->rx_buffer_info[rx_ntc]; | ||
1667 | |||
1668 | /* unmap Rx buffer, will be remapped by alloc_rx_buffers */ | ||
1669 | dma_unmap_single(rx_ring->dev, | ||
1670 | rx_buffer_info->dma, | ||
1671 | bufsz, | ||
1672 | DMA_FROM_DEVICE); | ||
1673 | rx_buffer_info->dma = 0; | ||
1674 | |||
1675 | /* verify contents of skb */ | ||
1676 | if (!ixgbe_check_lbtest_frame(rx_buffer_info->skb, size)) | ||
1677 | count++; | ||
1678 | |||
1679 | /* unmap buffer on Tx side */ | ||
1680 | tx_buffer_info = &tx_ring->tx_buffer_info[tx_ntc]; | ||
1681 | ixgbe_unmap_and_free_tx_resource(tx_ring, tx_buffer_info); | ||
1682 | |||
1683 | /* increment Rx/Tx next to clean counters */ | ||
1684 | rx_ntc++; | ||
1685 | if (rx_ntc == rx_ring->count) | ||
1686 | rx_ntc = 0; | ||
1687 | tx_ntc++; | ||
1688 | if (tx_ntc == tx_ring->count) | ||
1689 | tx_ntc = 0; | ||
1690 | |||
1691 | /* fetch next descriptor */ | ||
1692 | rx_desc = IXGBE_RX_DESC_ADV(rx_ring, rx_ntc); | ||
1693 | staterr = le32_to_cpu(rx_desc->wb.upper.status_error); | ||
1694 | } | ||
1695 | |||
1696 | /* re-map buffers to ring, store next to clean values */ | ||
1697 | ixgbe_alloc_rx_buffers(rx_ring, count); | ||
1698 | rx_ring->next_to_clean = rx_ntc; | ||
1699 | tx_ring->next_to_clean = tx_ntc; | ||
1700 | |||
1701 | return count; | ||
1702 | } | ||
1703 | |||
1704 | static int ixgbe_run_loopback_test(struct ixgbe_adapter *adapter) | ||
1705 | { | ||
1706 | struct ixgbe_ring *tx_ring = &adapter->test_tx_ring; | ||
1707 | struct ixgbe_ring *rx_ring = &adapter->test_rx_ring; | ||
1708 | int i, j, lc, good_cnt, ret_val = 0; | ||
1709 | unsigned int size = 1024; | ||
1710 | netdev_tx_t tx_ret_val; | ||
1711 | struct sk_buff *skb; | ||
1712 | |||
1713 | /* allocate test skb */ | ||
1714 | skb = alloc_skb(size, GFP_KERNEL); | ||
1715 | if (!skb) | ||
1716 | return 11; | ||
1717 | |||
1718 | /* place data into test skb */ | ||
1719 | ixgbe_create_lbtest_frame(skb, size); | ||
1720 | skb_put(skb, size); | ||
1721 | |||
1722 | /* | ||
1723 | * Calculate the loop count based on the largest descriptor ring | ||
1724 | * The idea is to wrap the largest ring a number of times using 64 | ||
1725 | * send/receive pairs during each loop | ||
1726 | */ | ||
1727 | |||
1728 | if (rx_ring->count <= tx_ring->count) | ||
1729 | lc = ((tx_ring->count / 64) * 2) + 1; | ||
1730 | else | ||
1731 | lc = ((rx_ring->count / 64) * 2) + 1; | ||
1732 | |||
1733 | for (j = 0; j <= lc; j++) { | ||
1734 | /* reset count of good packets */ | ||
1735 | good_cnt = 0; | ||
1736 | |||
1737 | /* place 64 packets on the transmit queue*/ | ||
1738 | for (i = 0; i < 64; i++) { | ||
1739 | skb_get(skb); | ||
1740 | tx_ret_val = ixgbe_xmit_frame_ring(skb, | ||
1741 | adapter, | ||
1742 | tx_ring); | ||
1743 | if (tx_ret_val == NETDEV_TX_OK) | ||
1744 | good_cnt++; | ||
1745 | } | ||
1746 | |||
1747 | if (good_cnt != 64) { | ||
1748 | ret_val = 12; | ||
1749 | break; | ||
1750 | } | ||
1751 | |||
1752 | /* allow 200 milliseconds for packets to go from Tx to Rx */ | ||
1753 | msleep(200); | ||
1754 | |||
1755 | good_cnt = ixgbe_clean_test_rings(rx_ring, tx_ring, size); | ||
1756 | if (good_cnt != 64) { | ||
1757 | ret_val = 13; | ||
1758 | break; | ||
1759 | } | ||
1760 | } | ||
1761 | |||
1762 | /* free the original skb */ | ||
1763 | kfree_skb(skb); | ||
1764 | |||
1765 | return ret_val; | ||
1766 | } | ||
1767 | |||
1768 | static int ixgbe_loopback_test(struct ixgbe_adapter *adapter, u64 *data) | ||
1769 | { | ||
1770 | *data = ixgbe_setup_desc_rings(adapter); | ||
1771 | if (*data) | ||
1772 | goto out; | ||
1773 | *data = ixgbe_setup_loopback_test(adapter); | ||
1774 | if (*data) | ||
1775 | goto err_loopback; | ||
1776 | *data = ixgbe_run_loopback_test(adapter); | ||
1777 | ixgbe_loopback_cleanup(adapter); | ||
1778 | |||
1779 | err_loopback: | ||
1780 | ixgbe_free_desc_rings(adapter); | ||
1781 | out: | ||
1782 | return *data; | ||
1783 | } | ||
1784 | |||
1785 | static void ixgbe_diag_test(struct net_device *netdev, | ||
1786 | struct ethtool_test *eth_test, u64 *data) | ||
1787 | { | ||
1788 | struct ixgbe_adapter *adapter = netdev_priv(netdev); | ||
1789 | bool if_running = netif_running(netdev); | ||
1790 | |||
1791 | set_bit(__IXGBE_TESTING, &adapter->state); | ||
1792 | if (eth_test->flags == ETH_TEST_FL_OFFLINE) { | ||
1793 | /* Offline tests */ | ||
1794 | |||
1795 | e_info(hw, "offline testing starting\n"); | ||
1796 | |||
1797 | /* Link test performed before hardware reset so autoneg doesn't | ||
1798 | * interfere with test result */ | ||
1799 | if (ixgbe_link_test(adapter, &data[4])) | ||
1800 | eth_test->flags |= ETH_TEST_FL_FAILED; | ||
1801 | |||
1802 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) { | ||
1803 | int i; | ||
1804 | for (i = 0; i < adapter->num_vfs; i++) { | ||
1805 | if (adapter->vfinfo[i].clear_to_send) { | ||
1806 | netdev_warn(netdev, "%s", | ||
1807 | "offline diagnostic is not " | ||
1808 | "supported when VFs are " | ||
1809 | "present\n"); | ||
1810 | data[0] = 1; | ||
1811 | data[1] = 1; | ||
1812 | data[2] = 1; | ||
1813 | data[3] = 1; | ||
1814 | eth_test->flags |= ETH_TEST_FL_FAILED; | ||
1815 | clear_bit(__IXGBE_TESTING, | ||
1816 | &adapter->state); | ||
1817 | goto skip_ol_tests; | ||
1818 | } | ||
1819 | } | ||
1820 | } | ||
1821 | |||
1822 | if (if_running) | ||
1823 | /* indicate we're in test mode */ | ||
1824 | dev_close(netdev); | ||
1825 | else | ||
1826 | ixgbe_reset(adapter); | ||
1827 | |||
1828 | e_info(hw, "register testing starting\n"); | ||
1829 | if (ixgbe_reg_test(adapter, &data[0])) | ||
1830 | eth_test->flags |= ETH_TEST_FL_FAILED; | ||
1831 | |||
1832 | ixgbe_reset(adapter); | ||
1833 | e_info(hw, "eeprom testing starting\n"); | ||
1834 | if (ixgbe_eeprom_test(adapter, &data[1])) | ||
1835 | eth_test->flags |= ETH_TEST_FL_FAILED; | ||
1836 | |||
1837 | ixgbe_reset(adapter); | ||
1838 | e_info(hw, "interrupt testing starting\n"); | ||
1839 | if (ixgbe_intr_test(adapter, &data[2])) | ||
1840 | eth_test->flags |= ETH_TEST_FL_FAILED; | ||
1841 | |||
1842 | /* If SRIOV or VMDq is enabled then skip MAC | ||
1843 | * loopback diagnostic. */ | ||
1844 | if (adapter->flags & (IXGBE_FLAG_SRIOV_ENABLED | | ||
1845 | IXGBE_FLAG_VMDQ_ENABLED)) { | ||
1846 | e_info(hw, "Skip MAC loopback diagnostic in VT " | ||
1847 | "mode\n"); | ||
1848 | data[3] = 0; | ||
1849 | goto skip_loopback; | ||
1850 | } | ||
1851 | |||
1852 | ixgbe_reset(adapter); | ||
1853 | e_info(hw, "loopback testing starting\n"); | ||
1854 | if (ixgbe_loopback_test(adapter, &data[3])) | ||
1855 | eth_test->flags |= ETH_TEST_FL_FAILED; | ||
1856 | |||
1857 | skip_loopback: | ||
1858 | ixgbe_reset(adapter); | ||
1859 | |||
1860 | clear_bit(__IXGBE_TESTING, &adapter->state); | ||
1861 | if (if_running) | ||
1862 | dev_open(netdev); | ||
1863 | } else { | ||
1864 | e_info(hw, "online testing starting\n"); | ||
1865 | /* Online tests */ | ||
1866 | if (ixgbe_link_test(adapter, &data[4])) | ||
1867 | eth_test->flags |= ETH_TEST_FL_FAILED; | ||
1868 | |||
1869 | /* Online tests aren't run; pass by default */ | ||
1870 | data[0] = 0; | ||
1871 | data[1] = 0; | ||
1872 | data[2] = 0; | ||
1873 | data[3] = 0; | ||
1874 | |||
1875 | clear_bit(__IXGBE_TESTING, &adapter->state); | ||
1876 | } | ||
1877 | skip_ol_tests: | ||
1878 | msleep_interruptible(4 * 1000); | ||
1879 | } | ||
1880 | |||
1881 | static int ixgbe_wol_exclusion(struct ixgbe_adapter *adapter, | ||
1882 | struct ethtool_wolinfo *wol) | ||
1883 | { | ||
1884 | struct ixgbe_hw *hw = &adapter->hw; | ||
1885 | int retval = 1; | ||
1886 | |||
1887 | /* WOL not supported except for the following */ | ||
1888 | switch(hw->device_id) { | ||
1889 | case IXGBE_DEV_ID_82599_SFP: | ||
1890 | /* Only this subdevice supports WOL */ | ||
1891 | if (hw->subsystem_device_id != IXGBE_SUBDEV_ID_82599_SFP) { | ||
1892 | wol->supported = 0; | ||
1893 | break; | ||
1894 | } | ||
1895 | retval = 0; | ||
1896 | break; | ||
1897 | case IXGBE_DEV_ID_82599_COMBO_BACKPLANE: | ||
1898 | /* All except this subdevice support WOL */ | ||
1899 | if (hw->subsystem_device_id == | ||
1900 | IXGBE_SUBDEV_ID_82599_KX4_KR_MEZZ) { | ||
1901 | wol->supported = 0; | ||
1902 | break; | ||
1903 | } | ||
1904 | retval = 0; | ||
1905 | break; | ||
1906 | case IXGBE_DEV_ID_82599_KX4: | ||
1907 | retval = 0; | ||
1908 | break; | ||
1909 | default: | ||
1910 | wol->supported = 0; | ||
1911 | } | ||
1912 | |||
1913 | return retval; | ||
1914 | } | ||
1915 | |||
1916 | static void ixgbe_get_wol(struct net_device *netdev, | ||
1917 | struct ethtool_wolinfo *wol) | ||
1918 | { | ||
1919 | struct ixgbe_adapter *adapter = netdev_priv(netdev); | ||
1920 | |||
1921 | wol->supported = WAKE_UCAST | WAKE_MCAST | | ||
1922 | WAKE_BCAST | WAKE_MAGIC; | ||
1923 | wol->wolopts = 0; | ||
1924 | |||
1925 | if (ixgbe_wol_exclusion(adapter, wol) || | ||
1926 | !device_can_wakeup(&adapter->pdev->dev)) | ||
1927 | return; | ||
1928 | |||
1929 | if (adapter->wol & IXGBE_WUFC_EX) | ||
1930 | wol->wolopts |= WAKE_UCAST; | ||
1931 | if (adapter->wol & IXGBE_WUFC_MC) | ||
1932 | wol->wolopts |= WAKE_MCAST; | ||
1933 | if (adapter->wol & IXGBE_WUFC_BC) | ||
1934 | wol->wolopts |= WAKE_BCAST; | ||
1935 | if (adapter->wol & IXGBE_WUFC_MAG) | ||
1936 | wol->wolopts |= WAKE_MAGIC; | ||
1937 | } | ||
1938 | |||
1939 | static int ixgbe_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol) | ||
1940 | { | ||
1941 | struct ixgbe_adapter *adapter = netdev_priv(netdev); | ||
1942 | |||
1943 | if (wol->wolopts & (WAKE_PHY | WAKE_ARP | WAKE_MAGICSECURE)) | ||
1944 | return -EOPNOTSUPP; | ||
1945 | |||
1946 | if (ixgbe_wol_exclusion(adapter, wol)) | ||
1947 | return wol->wolopts ? -EOPNOTSUPP : 0; | ||
1948 | |||
1949 | adapter->wol = 0; | ||
1950 | |||
1951 | if (wol->wolopts & WAKE_UCAST) | ||
1952 | adapter->wol |= IXGBE_WUFC_EX; | ||
1953 | if (wol->wolopts & WAKE_MCAST) | ||
1954 | adapter->wol |= IXGBE_WUFC_MC; | ||
1955 | if (wol->wolopts & WAKE_BCAST) | ||
1956 | adapter->wol |= IXGBE_WUFC_BC; | ||
1957 | if (wol->wolopts & WAKE_MAGIC) | ||
1958 | adapter->wol |= IXGBE_WUFC_MAG; | ||
1959 | |||
1960 | device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol); | ||
1961 | |||
1962 | return 0; | ||
1963 | } | ||
1964 | |||
1965 | static int ixgbe_nway_reset(struct net_device *netdev) | ||
1966 | { | ||
1967 | struct ixgbe_adapter *adapter = netdev_priv(netdev); | ||
1968 | |||
1969 | if (netif_running(netdev)) | ||
1970 | ixgbe_reinit_locked(adapter); | ||
1971 | |||
1972 | return 0; | ||
1973 | } | ||
1974 | |||
1975 | static int ixgbe_set_phys_id(struct net_device *netdev, | ||
1976 | enum ethtool_phys_id_state state) | ||
1977 | { | ||
1978 | struct ixgbe_adapter *adapter = netdev_priv(netdev); | ||
1979 | struct ixgbe_hw *hw = &adapter->hw; | ||
1980 | |||
1981 | switch (state) { | ||
1982 | case ETHTOOL_ID_ACTIVE: | ||
1983 | adapter->led_reg = IXGBE_READ_REG(hw, IXGBE_LEDCTL); | ||
1984 | return 2; | ||
1985 | |||
1986 | case ETHTOOL_ID_ON: | ||
1987 | hw->mac.ops.led_on(hw, IXGBE_LED_ON); | ||
1988 | break; | ||
1989 | |||
1990 | case ETHTOOL_ID_OFF: | ||
1991 | hw->mac.ops.led_off(hw, IXGBE_LED_ON); | ||
1992 | break; | ||
1993 | |||
1994 | case ETHTOOL_ID_INACTIVE: | ||
1995 | /* Restore LED settings */ | ||
1996 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_LEDCTL, adapter->led_reg); | ||
1997 | break; | ||
1998 | } | ||
1999 | |||
2000 | return 0; | ||
2001 | } | ||
2002 | |||
2003 | static int ixgbe_get_coalesce(struct net_device *netdev, | ||
2004 | struct ethtool_coalesce *ec) | ||
2005 | { | ||
2006 | struct ixgbe_adapter *adapter = netdev_priv(netdev); | ||
2007 | |||
2008 | ec->tx_max_coalesced_frames_irq = adapter->tx_work_limit; | ||
2009 | |||
2010 | /* only valid if in constant ITR mode */ | ||
2011 | switch (adapter->rx_itr_setting) { | ||
2012 | case 0: | ||
2013 | /* throttling disabled */ | ||
2014 | ec->rx_coalesce_usecs = 0; | ||
2015 | break; | ||
2016 | case 1: | ||
2017 | /* dynamic ITR mode */ | ||
2018 | ec->rx_coalesce_usecs = 1; | ||
2019 | break; | ||
2020 | default: | ||
2021 | /* fixed interrupt rate mode */ | ||
2022 | ec->rx_coalesce_usecs = 1000000/adapter->rx_eitr_param; | ||
2023 | break; | ||
2024 | } | ||
2025 | |||
2026 | /* if in mixed tx/rx queues per vector mode, report only rx settings */ | ||
2027 | if (adapter->q_vector[0]->tx.count && adapter->q_vector[0]->rx.count) | ||
2028 | return 0; | ||
2029 | |||
2030 | /* only valid if in constant ITR mode */ | ||
2031 | switch (adapter->tx_itr_setting) { | ||
2032 | case 0: | ||
2033 | /* throttling disabled */ | ||
2034 | ec->tx_coalesce_usecs = 0; | ||
2035 | break; | ||
2036 | case 1: | ||
2037 | /* dynamic ITR mode */ | ||
2038 | ec->tx_coalesce_usecs = 1; | ||
2039 | break; | ||
2040 | default: | ||
2041 | ec->tx_coalesce_usecs = 1000000/adapter->tx_eitr_param; | ||
2042 | break; | ||
2043 | } | ||
2044 | |||
2045 | return 0; | ||
2046 | } | ||
2047 | |||
2048 | /* | ||
2049 | * this function must be called before setting the new value of | ||
2050 | * rx_itr_setting | ||
2051 | */ | ||
2052 | static bool ixgbe_update_rsc(struct ixgbe_adapter *adapter, | ||
2053 | struct ethtool_coalesce *ec) | ||
2054 | { | ||
2055 | struct net_device *netdev = adapter->netdev; | ||
2056 | |||
2057 | if (!(adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE)) | ||
2058 | return false; | ||
2059 | |||
2060 | /* if interrupt rate is too high then disable RSC */ | ||
2061 | if (ec->rx_coalesce_usecs != 1 && | ||
2062 | ec->rx_coalesce_usecs <= 1000000/IXGBE_MAX_RSC_INT_RATE) { | ||
2063 | if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) { | ||
2064 | e_info(probe, "rx-usecs set too low, " | ||
2065 | "disabling RSC\n"); | ||
2066 | adapter->flags2 &= ~IXGBE_FLAG2_RSC_ENABLED; | ||
2067 | return true; | ||
2068 | } | ||
2069 | } else { | ||
2070 | /* check the feature flag value and enable RSC if necessary */ | ||
2071 | if ((netdev->features & NETIF_F_LRO) && | ||
2072 | !(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)) { | ||
2073 | e_info(probe, "rx-usecs set to %d, " | ||
2074 | "re-enabling RSC\n", | ||
2075 | ec->rx_coalesce_usecs); | ||
2076 | adapter->flags2 |= IXGBE_FLAG2_RSC_ENABLED; | ||
2077 | return true; | ||
2078 | } | ||
2079 | } | ||
2080 | return false; | ||
2081 | } | ||
2082 | |||
2083 | static int ixgbe_set_coalesce(struct net_device *netdev, | ||
2084 | struct ethtool_coalesce *ec) | ||
2085 | { | ||
2086 | struct ixgbe_adapter *adapter = netdev_priv(netdev); | ||
2087 | struct ixgbe_q_vector *q_vector; | ||
2088 | int i; | ||
2089 | bool need_reset = false; | ||
2090 | |||
2091 | /* don't accept tx specific changes if we've got mixed RxTx vectors */ | ||
2092 | if (adapter->q_vector[0]->tx.count && adapter->q_vector[0]->rx.count | ||
2093 | && ec->tx_coalesce_usecs) | ||
2094 | return -EINVAL; | ||
2095 | |||
2096 | if (ec->tx_max_coalesced_frames_irq) | ||
2097 | adapter->tx_work_limit = ec->tx_max_coalesced_frames_irq; | ||
2098 | |||
2099 | if (ec->rx_coalesce_usecs > 1) { | ||
2100 | /* check the limits */ | ||
2101 | if ((1000000/ec->rx_coalesce_usecs > IXGBE_MAX_INT_RATE) || | ||
2102 | (1000000/ec->rx_coalesce_usecs < IXGBE_MIN_INT_RATE)) | ||
2103 | return -EINVAL; | ||
2104 | |||
2105 | /* check the old value and enable RSC if necessary */ | ||
2106 | need_reset = ixgbe_update_rsc(adapter, ec); | ||
2107 | |||
2108 | /* store the value in ints/second */ | ||
2109 | adapter->rx_eitr_param = 1000000/ec->rx_coalesce_usecs; | ||
2110 | |||
2111 | /* static value of interrupt rate */ | ||
2112 | adapter->rx_itr_setting = adapter->rx_eitr_param; | ||
2113 | /* clear the lower bit as its used for dynamic state */ | ||
2114 | adapter->rx_itr_setting &= ~1; | ||
2115 | } else if (ec->rx_coalesce_usecs == 1) { | ||
2116 | /* check the old value and enable RSC if necessary */ | ||
2117 | need_reset = ixgbe_update_rsc(adapter, ec); | ||
2118 | |||
2119 | /* 1 means dynamic mode */ | ||
2120 | adapter->rx_eitr_param = 20000; | ||
2121 | adapter->rx_itr_setting = 1; | ||
2122 | } else { | ||
2123 | /* check the old value and enable RSC if necessary */ | ||
2124 | need_reset = ixgbe_update_rsc(adapter, ec); | ||
2125 | /* | ||
2126 | * any other value means disable eitr, which is best | ||
2127 | * served by setting the interrupt rate very high | ||
2128 | */ | ||
2129 | adapter->rx_eitr_param = IXGBE_MAX_INT_RATE; | ||
2130 | adapter->rx_itr_setting = 0; | ||
2131 | } | ||
2132 | |||
2133 | if (ec->tx_coalesce_usecs > 1) { | ||
2134 | /* | ||
2135 | * don't have to worry about max_int as above because | ||
2136 | * tx vectors don't do hardware RSC (an rx function) | ||
2137 | */ | ||
2138 | /* check the limits */ | ||
2139 | if ((1000000/ec->tx_coalesce_usecs > IXGBE_MAX_INT_RATE) || | ||
2140 | (1000000/ec->tx_coalesce_usecs < IXGBE_MIN_INT_RATE)) | ||
2141 | return -EINVAL; | ||
2142 | |||
2143 | /* store the value in ints/second */ | ||
2144 | adapter->tx_eitr_param = 1000000/ec->tx_coalesce_usecs; | ||
2145 | |||
2146 | /* static value of interrupt rate */ | ||
2147 | adapter->tx_itr_setting = adapter->tx_eitr_param; | ||
2148 | |||
2149 | /* clear the lower bit as its used for dynamic state */ | ||
2150 | adapter->tx_itr_setting &= ~1; | ||
2151 | } else if (ec->tx_coalesce_usecs == 1) { | ||
2152 | /* 1 means dynamic mode */ | ||
2153 | adapter->tx_eitr_param = 10000; | ||
2154 | adapter->tx_itr_setting = 1; | ||
2155 | } else { | ||
2156 | adapter->tx_eitr_param = IXGBE_MAX_INT_RATE; | ||
2157 | adapter->tx_itr_setting = 0; | ||
2158 | } | ||
2159 | |||
2160 | /* MSI/MSIx Interrupt Mode */ | ||
2161 | if (adapter->flags & | ||
2162 | (IXGBE_FLAG_MSIX_ENABLED | IXGBE_FLAG_MSI_ENABLED)) { | ||
2163 | int num_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; | ||
2164 | for (i = 0; i < num_vectors; i++) { | ||
2165 | q_vector = adapter->q_vector[i]; | ||
2166 | if (q_vector->tx.count && !q_vector->rx.count) | ||
2167 | /* tx only */ | ||
2168 | q_vector->eitr = adapter->tx_eitr_param; | ||
2169 | else | ||
2170 | /* rx only or mixed */ | ||
2171 | q_vector->eitr = adapter->rx_eitr_param; | ||
2172 | q_vector->tx.work_limit = adapter->tx_work_limit; | ||
2173 | ixgbe_write_eitr(q_vector); | ||
2174 | } | ||
2175 | /* Legacy Interrupt Mode */ | ||
2176 | } else { | ||
2177 | q_vector = adapter->q_vector[0]; | ||
2178 | q_vector->eitr = adapter->rx_eitr_param; | ||
2179 | q_vector->tx.work_limit = adapter->tx_work_limit; | ||
2180 | ixgbe_write_eitr(q_vector); | ||
2181 | } | ||
2182 | |||
2183 | /* | ||
2184 | * do reset here at the end to make sure EITR==0 case is handled | ||
2185 | * correctly w.r.t stopping tx, and changing TXDCTL.WTHRESH settings | ||
2186 | * also locks in RSC enable/disable which requires reset | ||
2187 | */ | ||
2188 | if (need_reset) | ||
2189 | ixgbe_do_reset(netdev); | ||
2190 | |||
2191 | return 0; | ||
2192 | } | ||
2193 | |||
2194 | static int ixgbe_get_ethtool_fdir_entry(struct ixgbe_adapter *adapter, | ||
2195 | struct ethtool_rxnfc *cmd) | ||
2196 | { | ||
2197 | union ixgbe_atr_input *mask = &adapter->fdir_mask; | ||
2198 | struct ethtool_rx_flow_spec *fsp = | ||
2199 | (struct ethtool_rx_flow_spec *)&cmd->fs; | ||
2200 | struct hlist_node *node, *node2; | ||
2201 | struct ixgbe_fdir_filter *rule = NULL; | ||
2202 | |||
2203 | /* report total rule count */ | ||
2204 | cmd->data = (1024 << adapter->fdir_pballoc) - 2; | ||
2205 | |||
2206 | hlist_for_each_entry_safe(rule, node, node2, | ||
2207 | &adapter->fdir_filter_list, fdir_node) { | ||
2208 | if (fsp->location <= rule->sw_idx) | ||
2209 | break; | ||
2210 | } | ||
2211 | |||
2212 | if (!rule || fsp->location != rule->sw_idx) | ||
2213 | return -EINVAL; | ||
2214 | |||
2215 | /* fill out the flow spec entry */ | ||
2216 | |||
2217 | /* set flow type field */ | ||
2218 | switch (rule->filter.formatted.flow_type) { | ||
2219 | case IXGBE_ATR_FLOW_TYPE_TCPV4: | ||
2220 | fsp->flow_type = TCP_V4_FLOW; | ||
2221 | break; | ||
2222 | case IXGBE_ATR_FLOW_TYPE_UDPV4: | ||
2223 | fsp->flow_type = UDP_V4_FLOW; | ||
2224 | break; | ||
2225 | case IXGBE_ATR_FLOW_TYPE_SCTPV4: | ||
2226 | fsp->flow_type = SCTP_V4_FLOW; | ||
2227 | break; | ||
2228 | case IXGBE_ATR_FLOW_TYPE_IPV4: | ||
2229 | fsp->flow_type = IP_USER_FLOW; | ||
2230 | fsp->h_u.usr_ip4_spec.ip_ver = ETH_RX_NFC_IP4; | ||
2231 | fsp->h_u.usr_ip4_spec.proto = 0; | ||
2232 | fsp->m_u.usr_ip4_spec.proto = 0; | ||
2233 | break; | ||
2234 | default: | ||
2235 | return -EINVAL; | ||
2236 | } | ||
2237 | |||
2238 | fsp->h_u.tcp_ip4_spec.psrc = rule->filter.formatted.src_port; | ||
2239 | fsp->m_u.tcp_ip4_spec.psrc = mask->formatted.src_port; | ||
2240 | fsp->h_u.tcp_ip4_spec.pdst = rule->filter.formatted.dst_port; | ||
2241 | fsp->m_u.tcp_ip4_spec.pdst = mask->formatted.dst_port; | ||
2242 | fsp->h_u.tcp_ip4_spec.ip4src = rule->filter.formatted.src_ip[0]; | ||
2243 | fsp->m_u.tcp_ip4_spec.ip4src = mask->formatted.src_ip[0]; | ||
2244 | fsp->h_u.tcp_ip4_spec.ip4dst = rule->filter.formatted.dst_ip[0]; | ||
2245 | fsp->m_u.tcp_ip4_spec.ip4dst = mask->formatted.dst_ip[0]; | ||
2246 | fsp->h_ext.vlan_tci = rule->filter.formatted.vlan_id; | ||
2247 | fsp->m_ext.vlan_tci = mask->formatted.vlan_id; | ||
2248 | fsp->h_ext.vlan_etype = rule->filter.formatted.flex_bytes; | ||
2249 | fsp->m_ext.vlan_etype = mask->formatted.flex_bytes; | ||
2250 | fsp->h_ext.data[1] = htonl(rule->filter.formatted.vm_pool); | ||
2251 | fsp->m_ext.data[1] = htonl(mask->formatted.vm_pool); | ||
2252 | fsp->flow_type |= FLOW_EXT; | ||
2253 | |||
2254 | /* record action */ | ||
2255 | if (rule->action == IXGBE_FDIR_DROP_QUEUE) | ||
2256 | fsp->ring_cookie = RX_CLS_FLOW_DISC; | ||
2257 | else | ||
2258 | fsp->ring_cookie = rule->action; | ||
2259 | |||
2260 | return 0; | ||
2261 | } | ||
2262 | |||
2263 | static int ixgbe_get_ethtool_fdir_all(struct ixgbe_adapter *adapter, | ||
2264 | struct ethtool_rxnfc *cmd, | ||
2265 | u32 *rule_locs) | ||
2266 | { | ||
2267 | struct hlist_node *node, *node2; | ||
2268 | struct ixgbe_fdir_filter *rule; | ||
2269 | int cnt = 0; | ||
2270 | |||
2271 | /* report total rule count */ | ||
2272 | cmd->data = (1024 << adapter->fdir_pballoc) - 2; | ||
2273 | |||
2274 | hlist_for_each_entry_safe(rule, node, node2, | ||
2275 | &adapter->fdir_filter_list, fdir_node) { | ||
2276 | if (cnt == cmd->rule_cnt) | ||
2277 | return -EMSGSIZE; | ||
2278 | rule_locs[cnt] = rule->sw_idx; | ||
2279 | cnt++; | ||
2280 | } | ||
2281 | |||
2282 | return 0; | ||
2283 | } | ||
2284 | |||
2285 | static int ixgbe_get_rxnfc(struct net_device *dev, struct ethtool_rxnfc *cmd, | ||
2286 | void *rule_locs) | ||
2287 | { | ||
2288 | struct ixgbe_adapter *adapter = netdev_priv(dev); | ||
2289 | int ret = -EOPNOTSUPP; | ||
2290 | |||
2291 | switch (cmd->cmd) { | ||
2292 | case ETHTOOL_GRXRINGS: | ||
2293 | cmd->data = adapter->num_rx_queues; | ||
2294 | ret = 0; | ||
2295 | break; | ||
2296 | case ETHTOOL_GRXCLSRLCNT: | ||
2297 | cmd->rule_cnt = adapter->fdir_filter_count; | ||
2298 | ret = 0; | ||
2299 | break; | ||
2300 | case ETHTOOL_GRXCLSRULE: | ||
2301 | ret = ixgbe_get_ethtool_fdir_entry(adapter, cmd); | ||
2302 | break; | ||
2303 | case ETHTOOL_GRXCLSRLALL: | ||
2304 | ret = ixgbe_get_ethtool_fdir_all(adapter, cmd, | ||
2305 | (u32 *)rule_locs); | ||
2306 | break; | ||
2307 | default: | ||
2308 | break; | ||
2309 | } | ||
2310 | |||
2311 | return ret; | ||
2312 | } | ||
2313 | |||
2314 | static int ixgbe_update_ethtool_fdir_entry(struct ixgbe_adapter *adapter, | ||
2315 | struct ixgbe_fdir_filter *input, | ||
2316 | u16 sw_idx) | ||
2317 | { | ||
2318 | struct ixgbe_hw *hw = &adapter->hw; | ||
2319 | struct hlist_node *node, *node2, *parent; | ||
2320 | struct ixgbe_fdir_filter *rule; | ||
2321 | int err = -EINVAL; | ||
2322 | |||
2323 | parent = NULL; | ||
2324 | rule = NULL; | ||
2325 | |||
2326 | hlist_for_each_entry_safe(rule, node, node2, | ||
2327 | &adapter->fdir_filter_list, fdir_node) { | ||
2328 | /* hash found, or no matching entry */ | ||
2329 | if (rule->sw_idx >= sw_idx) | ||
2330 | break; | ||
2331 | parent = node; | ||
2332 | } | ||
2333 | |||
2334 | /* if there is an old rule occupying our place remove it */ | ||
2335 | if (rule && (rule->sw_idx == sw_idx)) { | ||
2336 | if (!input || (rule->filter.formatted.bkt_hash != | ||
2337 | input->filter.formatted.bkt_hash)) { | ||
2338 | err = ixgbe_fdir_erase_perfect_filter_82599(hw, | ||
2339 | &rule->filter, | ||
2340 | sw_idx); | ||
2341 | } | ||
2342 | |||
2343 | hlist_del(&rule->fdir_node); | ||
2344 | kfree(rule); | ||
2345 | adapter->fdir_filter_count--; | ||
2346 | } | ||
2347 | |||
2348 | /* | ||
2349 | * If no input this was a delete, err should be 0 if a rule was | ||
2350 | * successfully found and removed from the list else -EINVAL | ||
2351 | */ | ||
2352 | if (!input) | ||
2353 | return err; | ||
2354 | |||
2355 | /* initialize node and set software index */ | ||
2356 | INIT_HLIST_NODE(&input->fdir_node); | ||
2357 | |||
2358 | /* add filter to the list */ | ||
2359 | if (parent) | ||
2360 | hlist_add_after(parent, &input->fdir_node); | ||
2361 | else | ||
2362 | hlist_add_head(&input->fdir_node, | ||
2363 | &adapter->fdir_filter_list); | ||
2364 | |||
2365 | /* update counts */ | ||
2366 | adapter->fdir_filter_count++; | ||
2367 | |||
2368 | return 0; | ||
2369 | } | ||
2370 | |||
2371 | static int ixgbe_flowspec_to_flow_type(struct ethtool_rx_flow_spec *fsp, | ||
2372 | u8 *flow_type) | ||
2373 | { | ||
2374 | switch (fsp->flow_type & ~FLOW_EXT) { | ||
2375 | case TCP_V4_FLOW: | ||
2376 | *flow_type = IXGBE_ATR_FLOW_TYPE_TCPV4; | ||
2377 | break; | ||
2378 | case UDP_V4_FLOW: | ||
2379 | *flow_type = IXGBE_ATR_FLOW_TYPE_UDPV4; | ||
2380 | break; | ||
2381 | case SCTP_V4_FLOW: | ||
2382 | *flow_type = IXGBE_ATR_FLOW_TYPE_SCTPV4; | ||
2383 | break; | ||
2384 | case IP_USER_FLOW: | ||
2385 | switch (fsp->h_u.usr_ip4_spec.proto) { | ||
2386 | case IPPROTO_TCP: | ||
2387 | *flow_type = IXGBE_ATR_FLOW_TYPE_TCPV4; | ||
2388 | break; | ||
2389 | case IPPROTO_UDP: | ||
2390 | *flow_type = IXGBE_ATR_FLOW_TYPE_UDPV4; | ||
2391 | break; | ||
2392 | case IPPROTO_SCTP: | ||
2393 | *flow_type = IXGBE_ATR_FLOW_TYPE_SCTPV4; | ||
2394 | break; | ||
2395 | case 0: | ||
2396 | if (!fsp->m_u.usr_ip4_spec.proto) { | ||
2397 | *flow_type = IXGBE_ATR_FLOW_TYPE_IPV4; | ||
2398 | break; | ||
2399 | } | ||
2400 | default: | ||
2401 | return 0; | ||
2402 | } | ||
2403 | break; | ||
2404 | default: | ||
2405 | return 0; | ||
2406 | } | ||
2407 | |||
2408 | return 1; | ||
2409 | } | ||
2410 | |||
2411 | static int ixgbe_add_ethtool_fdir_entry(struct ixgbe_adapter *adapter, | ||
2412 | struct ethtool_rxnfc *cmd) | ||
2413 | { | ||
2414 | struct ethtool_rx_flow_spec *fsp = | ||
2415 | (struct ethtool_rx_flow_spec *)&cmd->fs; | ||
2416 | struct ixgbe_hw *hw = &adapter->hw; | ||
2417 | struct ixgbe_fdir_filter *input; | ||
2418 | union ixgbe_atr_input mask; | ||
2419 | int err; | ||
2420 | |||
2421 | if (!(adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)) | ||
2422 | return -EOPNOTSUPP; | ||
2423 | |||
2424 | /* | ||
2425 | * Don't allow programming if the action is a queue greater than | ||
2426 | * the number of online Rx queues. | ||
2427 | */ | ||
2428 | if ((fsp->ring_cookie != RX_CLS_FLOW_DISC) && | ||
2429 | (fsp->ring_cookie >= adapter->num_rx_queues)) | ||
2430 | return -EINVAL; | ||
2431 | |||
2432 | /* Don't allow indexes to exist outside of available space */ | ||
2433 | if (fsp->location >= ((1024 << adapter->fdir_pballoc) - 2)) { | ||
2434 | e_err(drv, "Location out of range\n"); | ||
2435 | return -EINVAL; | ||
2436 | } | ||
2437 | |||
2438 | input = kzalloc(sizeof(*input), GFP_ATOMIC); | ||
2439 | if (!input) | ||
2440 | return -ENOMEM; | ||
2441 | |||
2442 | memset(&mask, 0, sizeof(union ixgbe_atr_input)); | ||
2443 | |||
2444 | /* set SW index */ | ||
2445 | input->sw_idx = fsp->location; | ||
2446 | |||
2447 | /* record flow type */ | ||
2448 | if (!ixgbe_flowspec_to_flow_type(fsp, | ||
2449 | &input->filter.formatted.flow_type)) { | ||
2450 | e_err(drv, "Unrecognized flow type\n"); | ||
2451 | goto err_out; | ||
2452 | } | ||
2453 | |||
2454 | mask.formatted.flow_type = IXGBE_ATR_L4TYPE_IPV6_MASK | | ||
2455 | IXGBE_ATR_L4TYPE_MASK; | ||
2456 | |||
2457 | if (input->filter.formatted.flow_type == IXGBE_ATR_FLOW_TYPE_IPV4) | ||
2458 | mask.formatted.flow_type &= IXGBE_ATR_L4TYPE_IPV6_MASK; | ||
2459 | |||
2460 | /* Copy input into formatted structures */ | ||
2461 | input->filter.formatted.src_ip[0] = fsp->h_u.tcp_ip4_spec.ip4src; | ||
2462 | mask.formatted.src_ip[0] = fsp->m_u.tcp_ip4_spec.ip4src; | ||
2463 | input->filter.formatted.dst_ip[0] = fsp->h_u.tcp_ip4_spec.ip4dst; | ||
2464 | mask.formatted.dst_ip[0] = fsp->m_u.tcp_ip4_spec.ip4dst; | ||
2465 | input->filter.formatted.src_port = fsp->h_u.tcp_ip4_spec.psrc; | ||
2466 | mask.formatted.src_port = fsp->m_u.tcp_ip4_spec.psrc; | ||
2467 | input->filter.formatted.dst_port = fsp->h_u.tcp_ip4_spec.pdst; | ||
2468 | mask.formatted.dst_port = fsp->m_u.tcp_ip4_spec.pdst; | ||
2469 | |||
2470 | if (fsp->flow_type & FLOW_EXT) { | ||
2471 | input->filter.formatted.vm_pool = | ||
2472 | (unsigned char)ntohl(fsp->h_ext.data[1]); | ||
2473 | mask.formatted.vm_pool = | ||
2474 | (unsigned char)ntohl(fsp->m_ext.data[1]); | ||
2475 | input->filter.formatted.vlan_id = fsp->h_ext.vlan_tci; | ||
2476 | mask.formatted.vlan_id = fsp->m_ext.vlan_tci; | ||
2477 | input->filter.formatted.flex_bytes = | ||
2478 | fsp->h_ext.vlan_etype; | ||
2479 | mask.formatted.flex_bytes = fsp->m_ext.vlan_etype; | ||
2480 | } | ||
2481 | |||
2482 | /* determine if we need to drop or route the packet */ | ||
2483 | if (fsp->ring_cookie == RX_CLS_FLOW_DISC) | ||
2484 | input->action = IXGBE_FDIR_DROP_QUEUE; | ||
2485 | else | ||
2486 | input->action = fsp->ring_cookie; | ||
2487 | |||
2488 | spin_lock(&adapter->fdir_perfect_lock); | ||
2489 | |||
2490 | if (hlist_empty(&adapter->fdir_filter_list)) { | ||
2491 | /* save mask and program input mask into HW */ | ||
2492 | memcpy(&adapter->fdir_mask, &mask, sizeof(mask)); | ||
2493 | err = ixgbe_fdir_set_input_mask_82599(hw, &mask); | ||
2494 | if (err) { | ||
2495 | e_err(drv, "Error writing mask\n"); | ||
2496 | goto err_out_w_lock; | ||
2497 | } | ||
2498 | } else if (memcmp(&adapter->fdir_mask, &mask, sizeof(mask))) { | ||
2499 | e_err(drv, "Only one mask supported per port\n"); | ||
2500 | goto err_out_w_lock; | ||
2501 | } | ||
2502 | |||
2503 | /* apply mask and compute/store hash */ | ||
2504 | ixgbe_atr_compute_perfect_hash_82599(&input->filter, &mask); | ||
2505 | |||
2506 | /* program filters to filter memory */ | ||
2507 | err = ixgbe_fdir_write_perfect_filter_82599(hw, | ||
2508 | &input->filter, input->sw_idx, | ||
2509 | (input->action == IXGBE_FDIR_DROP_QUEUE) ? | ||
2510 | IXGBE_FDIR_DROP_QUEUE : | ||
2511 | adapter->rx_ring[input->action]->reg_idx); | ||
2512 | if (err) | ||
2513 | goto err_out_w_lock; | ||
2514 | |||
2515 | ixgbe_update_ethtool_fdir_entry(adapter, input, input->sw_idx); | ||
2516 | |||
2517 | spin_unlock(&adapter->fdir_perfect_lock); | ||
2518 | |||
2519 | return err; | ||
2520 | err_out_w_lock: | ||
2521 | spin_unlock(&adapter->fdir_perfect_lock); | ||
2522 | err_out: | ||
2523 | kfree(input); | ||
2524 | return -EINVAL; | ||
2525 | } | ||
2526 | |||
2527 | static int ixgbe_del_ethtool_fdir_entry(struct ixgbe_adapter *adapter, | ||
2528 | struct ethtool_rxnfc *cmd) | ||
2529 | { | ||
2530 | struct ethtool_rx_flow_spec *fsp = | ||
2531 | (struct ethtool_rx_flow_spec *)&cmd->fs; | ||
2532 | int err; | ||
2533 | |||
2534 | spin_lock(&adapter->fdir_perfect_lock); | ||
2535 | err = ixgbe_update_ethtool_fdir_entry(adapter, NULL, fsp->location); | ||
2536 | spin_unlock(&adapter->fdir_perfect_lock); | ||
2537 | |||
2538 | return err; | ||
2539 | } | ||
2540 | |||
2541 | static int ixgbe_set_rxnfc(struct net_device *dev, struct ethtool_rxnfc *cmd) | ||
2542 | { | ||
2543 | struct ixgbe_adapter *adapter = netdev_priv(dev); | ||
2544 | int ret = -EOPNOTSUPP; | ||
2545 | |||
2546 | switch (cmd->cmd) { | ||
2547 | case ETHTOOL_SRXCLSRLINS: | ||
2548 | ret = ixgbe_add_ethtool_fdir_entry(adapter, cmd); | ||
2549 | break; | ||
2550 | case ETHTOOL_SRXCLSRLDEL: | ||
2551 | ret = ixgbe_del_ethtool_fdir_entry(adapter, cmd); | ||
2552 | break; | ||
2553 | default: | ||
2554 | break; | ||
2555 | } | ||
2556 | |||
2557 | return ret; | ||
2558 | } | ||
2559 | |||
2560 | static const struct ethtool_ops ixgbe_ethtool_ops = { | ||
2561 | .get_settings = ixgbe_get_settings, | ||
2562 | .set_settings = ixgbe_set_settings, | ||
2563 | .get_drvinfo = ixgbe_get_drvinfo, | ||
2564 | .get_regs_len = ixgbe_get_regs_len, | ||
2565 | .get_regs = ixgbe_get_regs, | ||
2566 | .get_wol = ixgbe_get_wol, | ||
2567 | .set_wol = ixgbe_set_wol, | ||
2568 | .nway_reset = ixgbe_nway_reset, | ||
2569 | .get_link = ethtool_op_get_link, | ||
2570 | .get_eeprom_len = ixgbe_get_eeprom_len, | ||
2571 | .get_eeprom = ixgbe_get_eeprom, | ||
2572 | .get_ringparam = ixgbe_get_ringparam, | ||
2573 | .set_ringparam = ixgbe_set_ringparam, | ||
2574 | .get_pauseparam = ixgbe_get_pauseparam, | ||
2575 | .set_pauseparam = ixgbe_set_pauseparam, | ||
2576 | .get_msglevel = ixgbe_get_msglevel, | ||
2577 | .set_msglevel = ixgbe_set_msglevel, | ||
2578 | .self_test = ixgbe_diag_test, | ||
2579 | .get_strings = ixgbe_get_strings, | ||
2580 | .set_phys_id = ixgbe_set_phys_id, | ||
2581 | .get_sset_count = ixgbe_get_sset_count, | ||
2582 | .get_ethtool_stats = ixgbe_get_ethtool_stats, | ||
2583 | .get_coalesce = ixgbe_get_coalesce, | ||
2584 | .set_coalesce = ixgbe_set_coalesce, | ||
2585 | .get_rxnfc = ixgbe_get_rxnfc, | ||
2586 | .set_rxnfc = ixgbe_set_rxnfc, | ||
2587 | }; | ||
2588 | |||
2589 | void ixgbe_set_ethtool_ops(struct net_device *netdev) | ||
2590 | { | ||
2591 | SET_ETHTOOL_OPS(netdev, &ixgbe_ethtool_ops); | ||
2592 | } | ||
diff --git a/drivers/net/ixgbe/ixgbe_fcoe.c b/drivers/net/ixgbe/ixgbe_fcoe.c new file mode 100644 index 00000000000..824edae7786 --- /dev/null +++ b/drivers/net/ixgbe/ixgbe_fcoe.c | |||
@@ -0,0 +1,836 @@ | |||
1 | /******************************************************************************* | ||
2 | |||
3 | Intel 10 Gigabit PCI Express Linux driver | ||
4 | Copyright(c) 1999 - 2011 Intel Corporation. | ||
5 | |||
6 | This program is free software; you can redistribute it and/or modify it | ||
7 | under the terms and conditions of the GNU General Public License, | ||
8 | version 2, as published by the Free Software Foundation. | ||
9 | |||
10 | This program is distributed in the hope it will be useful, but WITHOUT | ||
11 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
12 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
13 | more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License along with | ||
16 | this program; if not, write to the Free Software Foundation, Inc., | ||
17 | 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. | ||
18 | |||
19 | The full GNU General Public License is included in this distribution in | ||
20 | the file called "COPYING". | ||
21 | |||
22 | Contact Information: | ||
23 | e1000-devel Mailing List <e1000-devel@lists.sourceforge.net> | ||
24 | Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 | ||
25 | |||
26 | *******************************************************************************/ | ||
27 | |||
28 | #include "ixgbe.h" | ||
29 | #include <linux/if_ether.h> | ||
30 | #include <linux/gfp.h> | ||
31 | #include <linux/if_vlan.h> | ||
32 | #include <scsi/scsi_cmnd.h> | ||
33 | #include <scsi/scsi_device.h> | ||
34 | #include <scsi/fc/fc_fs.h> | ||
35 | #include <scsi/fc/fc_fcoe.h> | ||
36 | #include <scsi/libfc.h> | ||
37 | #include <scsi/libfcoe.h> | ||
38 | |||
39 | /** | ||
40 | * ixgbe_fcoe_clear_ddp - clear the given ddp context | ||
41 | * @ddp - ptr to the ixgbe_fcoe_ddp | ||
42 | * | ||
43 | * Returns : none | ||
44 | * | ||
45 | */ | ||
46 | static inline void ixgbe_fcoe_clear_ddp(struct ixgbe_fcoe_ddp *ddp) | ||
47 | { | ||
48 | ddp->len = 0; | ||
49 | ddp->err = 1; | ||
50 | ddp->udl = NULL; | ||
51 | ddp->udp = 0UL; | ||
52 | ddp->sgl = NULL; | ||
53 | ddp->sgc = 0; | ||
54 | } | ||
55 | |||
56 | /** | ||
57 | * ixgbe_fcoe_ddp_put - free the ddp context for a given xid | ||
58 | * @netdev: the corresponding net_device | ||
59 | * @xid: the xid that corresponding ddp will be freed | ||
60 | * | ||
61 | * This is the implementation of net_device_ops.ndo_fcoe_ddp_done | ||
62 | * and it is expected to be called by ULD, i.e., FCP layer of libfc | ||
63 | * to release the corresponding ddp context when the I/O is done. | ||
64 | * | ||
65 | * Returns : data length already ddp-ed in bytes | ||
66 | */ | ||
67 | int ixgbe_fcoe_ddp_put(struct net_device *netdev, u16 xid) | ||
68 | { | ||
69 | int len = 0; | ||
70 | struct ixgbe_fcoe *fcoe; | ||
71 | struct ixgbe_adapter *adapter; | ||
72 | struct ixgbe_fcoe_ddp *ddp; | ||
73 | u32 fcbuff; | ||
74 | |||
75 | if (!netdev) | ||
76 | goto out_ddp_put; | ||
77 | |||
78 | if (xid >= IXGBE_FCOE_DDP_MAX) | ||
79 | goto out_ddp_put; | ||
80 | |||
81 | adapter = netdev_priv(netdev); | ||
82 | fcoe = &adapter->fcoe; | ||
83 | ddp = &fcoe->ddp[xid]; | ||
84 | if (!ddp->udl) | ||
85 | goto out_ddp_put; | ||
86 | |||
87 | len = ddp->len; | ||
88 | /* if there an error, force to invalidate ddp context */ | ||
89 | if (ddp->err) { | ||
90 | spin_lock_bh(&fcoe->lock); | ||
91 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_FCFLT, 0); | ||
92 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_FCFLTRW, | ||
93 | (xid | IXGBE_FCFLTRW_WE)); | ||
94 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_FCBUFF, 0); | ||
95 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_FCDMARW, | ||
96 | (xid | IXGBE_FCDMARW_WE)); | ||
97 | |||
98 | /* guaranteed to be invalidated after 100us */ | ||
99 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_FCDMARW, | ||
100 | (xid | IXGBE_FCDMARW_RE)); | ||
101 | fcbuff = IXGBE_READ_REG(&adapter->hw, IXGBE_FCBUFF); | ||
102 | spin_unlock_bh(&fcoe->lock); | ||
103 | if (fcbuff & IXGBE_FCBUFF_VALID) | ||
104 | udelay(100); | ||
105 | } | ||
106 | if (ddp->sgl) | ||
107 | pci_unmap_sg(adapter->pdev, ddp->sgl, ddp->sgc, | ||
108 | DMA_FROM_DEVICE); | ||
109 | if (ddp->pool) { | ||
110 | pci_pool_free(ddp->pool, ddp->udl, ddp->udp); | ||
111 | ddp->pool = NULL; | ||
112 | } | ||
113 | |||
114 | ixgbe_fcoe_clear_ddp(ddp); | ||
115 | |||
116 | out_ddp_put: | ||
117 | return len; | ||
118 | } | ||
119 | |||
120 | /** | ||
121 | * ixgbe_fcoe_ddp_setup - called to set up ddp context | ||
122 | * @netdev: the corresponding net_device | ||
123 | * @xid: the exchange id requesting ddp | ||
124 | * @sgl: the scatter-gather list for this request | ||
125 | * @sgc: the number of scatter-gather items | ||
126 | * | ||
127 | * Returns : 1 for success and 0 for no ddp | ||
128 | */ | ||
129 | static int ixgbe_fcoe_ddp_setup(struct net_device *netdev, u16 xid, | ||
130 | struct scatterlist *sgl, unsigned int sgc, | ||
131 | int target_mode) | ||
132 | { | ||
133 | struct ixgbe_adapter *adapter; | ||
134 | struct ixgbe_hw *hw; | ||
135 | struct ixgbe_fcoe *fcoe; | ||
136 | struct ixgbe_fcoe_ddp *ddp; | ||
137 | struct scatterlist *sg; | ||
138 | unsigned int i, j, dmacount; | ||
139 | unsigned int len; | ||
140 | static const unsigned int bufflen = IXGBE_FCBUFF_MIN; | ||
141 | unsigned int firstoff = 0; | ||
142 | unsigned int lastsize; | ||
143 | unsigned int thisoff = 0; | ||
144 | unsigned int thislen = 0; | ||
145 | u32 fcbuff, fcdmarw, fcfltrw, fcrxctl; | ||
146 | dma_addr_t addr = 0; | ||
147 | struct pci_pool *pool; | ||
148 | |||
149 | if (!netdev || !sgl) | ||
150 | return 0; | ||
151 | |||
152 | adapter = netdev_priv(netdev); | ||
153 | if (xid >= IXGBE_FCOE_DDP_MAX) { | ||
154 | e_warn(drv, "xid=0x%x out-of-range\n", xid); | ||
155 | return 0; | ||
156 | } | ||
157 | |||
158 | /* no DDP if we are already down or resetting */ | ||
159 | if (test_bit(__IXGBE_DOWN, &adapter->state) || | ||
160 | test_bit(__IXGBE_RESETTING, &adapter->state)) | ||
161 | return 0; | ||
162 | |||
163 | fcoe = &adapter->fcoe; | ||
164 | if (!fcoe->pool) { | ||
165 | e_warn(drv, "xid=0x%x no ddp pool for fcoe\n", xid); | ||
166 | return 0; | ||
167 | } | ||
168 | |||
169 | ddp = &fcoe->ddp[xid]; | ||
170 | if (ddp->sgl) { | ||
171 | e_err(drv, "xid 0x%x w/ non-null sgl=%p nents=%d\n", | ||
172 | xid, ddp->sgl, ddp->sgc); | ||
173 | return 0; | ||
174 | } | ||
175 | ixgbe_fcoe_clear_ddp(ddp); | ||
176 | |||
177 | /* setup dma from scsi command sgl */ | ||
178 | dmacount = pci_map_sg(adapter->pdev, sgl, sgc, DMA_FROM_DEVICE); | ||
179 | if (dmacount == 0) { | ||
180 | e_err(drv, "xid 0x%x DMA map error\n", xid); | ||
181 | return 0; | ||
182 | } | ||
183 | |||
184 | /* alloc the udl from per cpu ddp pool */ | ||
185 | pool = *per_cpu_ptr(fcoe->pool, get_cpu()); | ||
186 | ddp->udl = pci_pool_alloc(pool, GFP_ATOMIC, &ddp->udp); | ||
187 | if (!ddp->udl) { | ||
188 | e_err(drv, "failed allocated ddp context\n"); | ||
189 | goto out_noddp_unmap; | ||
190 | } | ||
191 | ddp->pool = pool; | ||
192 | ddp->sgl = sgl; | ||
193 | ddp->sgc = sgc; | ||
194 | |||
195 | j = 0; | ||
196 | for_each_sg(sgl, sg, dmacount, i) { | ||
197 | addr = sg_dma_address(sg); | ||
198 | len = sg_dma_len(sg); | ||
199 | while (len) { | ||
200 | /* max number of buffers allowed in one DDP context */ | ||
201 | if (j >= IXGBE_BUFFCNT_MAX) { | ||
202 | e_err(drv, "xid=%x:%d,%d,%d:addr=%llx " | ||
203 | "not enough descriptors\n", | ||
204 | xid, i, j, dmacount, (u64)addr); | ||
205 | goto out_noddp_free; | ||
206 | } | ||
207 | |||
208 | /* get the offset of length of current buffer */ | ||
209 | thisoff = addr & ((dma_addr_t)bufflen - 1); | ||
210 | thislen = min((bufflen - thisoff), len); | ||
211 | /* | ||
212 | * all but the 1st buffer (j == 0) | ||
213 | * must be aligned on bufflen | ||
214 | */ | ||
215 | if ((j != 0) && (thisoff)) | ||
216 | goto out_noddp_free; | ||
217 | /* | ||
218 | * all but the last buffer | ||
219 | * ((i == (dmacount - 1)) && (thislen == len)) | ||
220 | * must end at bufflen | ||
221 | */ | ||
222 | if (((i != (dmacount - 1)) || (thislen != len)) | ||
223 | && ((thislen + thisoff) != bufflen)) | ||
224 | goto out_noddp_free; | ||
225 | |||
226 | ddp->udl[j] = (u64)(addr - thisoff); | ||
227 | /* only the first buffer may have none-zero offset */ | ||
228 | if (j == 0) | ||
229 | firstoff = thisoff; | ||
230 | len -= thislen; | ||
231 | addr += thislen; | ||
232 | j++; | ||
233 | } | ||
234 | } | ||
235 | /* only the last buffer may have non-full bufflen */ | ||
236 | lastsize = thisoff + thislen; | ||
237 | |||
238 | /* | ||
239 | * lastsize can not be buffer len. | ||
240 | * If it is then adding another buffer with lastsize = 1. | ||
241 | */ | ||
242 | if (lastsize == bufflen) { | ||
243 | if (j >= IXGBE_BUFFCNT_MAX) { | ||
244 | e_err(drv, "xid=%x:%d,%d,%d:addr=%llx " | ||
245 | "not enough user buffers. We need an extra " | ||
246 | "buffer because lastsize is bufflen.\n", | ||
247 | xid, i, j, dmacount, (u64)addr); | ||
248 | goto out_noddp_free; | ||
249 | } | ||
250 | |||
251 | ddp->udl[j] = (u64)(fcoe->extra_ddp_buffer_dma); | ||
252 | j++; | ||
253 | lastsize = 1; | ||
254 | } | ||
255 | put_cpu(); | ||
256 | |||
257 | fcbuff = (IXGBE_FCBUFF_4KB << IXGBE_FCBUFF_BUFFSIZE_SHIFT); | ||
258 | fcbuff |= ((j & 0xff) << IXGBE_FCBUFF_BUFFCNT_SHIFT); | ||
259 | fcbuff |= (firstoff << IXGBE_FCBUFF_OFFSET_SHIFT); | ||
260 | /* Set WRCONTX bit to allow DDP for target */ | ||
261 | if (target_mode) | ||
262 | fcbuff |= (IXGBE_FCBUFF_WRCONTX); | ||
263 | fcbuff |= (IXGBE_FCBUFF_VALID); | ||
264 | |||
265 | fcdmarw = xid; | ||
266 | fcdmarw |= IXGBE_FCDMARW_WE; | ||
267 | fcdmarw |= (lastsize << IXGBE_FCDMARW_LASTSIZE_SHIFT); | ||
268 | |||
269 | fcfltrw = xid; | ||
270 | fcfltrw |= IXGBE_FCFLTRW_WE; | ||
271 | |||
272 | /* program DMA context */ | ||
273 | hw = &adapter->hw; | ||
274 | spin_lock_bh(&fcoe->lock); | ||
275 | |||
276 | /* turn on last frame indication for target mode as FCP_RSPtarget is | ||
277 | * supposed to send FCP_RSP when it is done. */ | ||
278 | if (target_mode && !test_bit(__IXGBE_FCOE_TARGET, &fcoe->mode)) { | ||
279 | set_bit(__IXGBE_FCOE_TARGET, &fcoe->mode); | ||
280 | fcrxctl = IXGBE_READ_REG(hw, IXGBE_FCRXCTRL); | ||
281 | fcrxctl |= IXGBE_FCRXCTRL_LASTSEQH; | ||
282 | IXGBE_WRITE_REG(hw, IXGBE_FCRXCTRL, fcrxctl); | ||
283 | } | ||
284 | |||
285 | IXGBE_WRITE_REG(hw, IXGBE_FCPTRL, ddp->udp & DMA_BIT_MASK(32)); | ||
286 | IXGBE_WRITE_REG(hw, IXGBE_FCPTRH, (u64)ddp->udp >> 32); | ||
287 | IXGBE_WRITE_REG(hw, IXGBE_FCBUFF, fcbuff); | ||
288 | IXGBE_WRITE_REG(hw, IXGBE_FCDMARW, fcdmarw); | ||
289 | /* program filter context */ | ||
290 | IXGBE_WRITE_REG(hw, IXGBE_FCPARAM, 0); | ||
291 | IXGBE_WRITE_REG(hw, IXGBE_FCFLT, IXGBE_FCFLT_VALID); | ||
292 | IXGBE_WRITE_REG(hw, IXGBE_FCFLTRW, fcfltrw); | ||
293 | |||
294 | spin_unlock_bh(&fcoe->lock); | ||
295 | |||
296 | return 1; | ||
297 | |||
298 | out_noddp_free: | ||
299 | pci_pool_free(pool, ddp->udl, ddp->udp); | ||
300 | ixgbe_fcoe_clear_ddp(ddp); | ||
301 | |||
302 | out_noddp_unmap: | ||
303 | pci_unmap_sg(adapter->pdev, sgl, sgc, DMA_FROM_DEVICE); | ||
304 | put_cpu(); | ||
305 | return 0; | ||
306 | } | ||
307 | |||
308 | /** | ||
309 | * ixgbe_fcoe_ddp_get - called to set up ddp context in initiator mode | ||
310 | * @netdev: the corresponding net_device | ||
311 | * @xid: the exchange id requesting ddp | ||
312 | * @sgl: the scatter-gather list for this request | ||
313 | * @sgc: the number of scatter-gather items | ||
314 | * | ||
315 | * This is the implementation of net_device_ops.ndo_fcoe_ddp_setup | ||
316 | * and is expected to be called from ULD, e.g., FCP layer of libfc | ||
317 | * to set up ddp for the corresponding xid of the given sglist for | ||
318 | * the corresponding I/O. | ||
319 | * | ||
320 | * Returns : 1 for success and 0 for no ddp | ||
321 | */ | ||
322 | int ixgbe_fcoe_ddp_get(struct net_device *netdev, u16 xid, | ||
323 | struct scatterlist *sgl, unsigned int sgc) | ||
324 | { | ||
325 | return ixgbe_fcoe_ddp_setup(netdev, xid, sgl, sgc, 0); | ||
326 | } | ||
327 | |||
328 | /** | ||
329 | * ixgbe_fcoe_ddp_target - called to set up ddp context in target mode | ||
330 | * @netdev: the corresponding net_device | ||
331 | * @xid: the exchange id requesting ddp | ||
332 | * @sgl: the scatter-gather list for this request | ||
333 | * @sgc: the number of scatter-gather items | ||
334 | * | ||
335 | * This is the implementation of net_device_ops.ndo_fcoe_ddp_target | ||
336 | * and is expected to be called from ULD, e.g., FCP layer of libfc | ||
337 | * to set up ddp for the corresponding xid of the given sglist for | ||
338 | * the corresponding I/O. The DDP in target mode is a write I/O request | ||
339 | * from the initiator. | ||
340 | * | ||
341 | * Returns : 1 for success and 0 for no ddp | ||
342 | */ | ||
343 | int ixgbe_fcoe_ddp_target(struct net_device *netdev, u16 xid, | ||
344 | struct scatterlist *sgl, unsigned int sgc) | ||
345 | { | ||
346 | return ixgbe_fcoe_ddp_setup(netdev, xid, sgl, sgc, 1); | ||
347 | } | ||
348 | |||
349 | /** | ||
350 | * ixgbe_fcoe_ddp - check ddp status and mark it done | ||
351 | * @adapter: ixgbe adapter | ||
352 | * @rx_desc: advanced rx descriptor | ||
353 | * @skb: the skb holding the received data | ||
354 | * | ||
355 | * This checks ddp status. | ||
356 | * | ||
357 | * Returns : < 0 indicates an error or not a FCiE ddp, 0 indicates | ||
358 | * not passing the skb to ULD, > 0 indicates is the length of data | ||
359 | * being ddped. | ||
360 | */ | ||
361 | int ixgbe_fcoe_ddp(struct ixgbe_adapter *adapter, | ||
362 | union ixgbe_adv_rx_desc *rx_desc, | ||
363 | struct sk_buff *skb, | ||
364 | u32 staterr) | ||
365 | { | ||
366 | u16 xid; | ||
367 | u32 fctl; | ||
368 | u32 fceofe, fcerr, fcstat; | ||
369 | int rc = -EINVAL; | ||
370 | struct ixgbe_fcoe *fcoe; | ||
371 | struct ixgbe_fcoe_ddp *ddp; | ||
372 | struct fc_frame_header *fh; | ||
373 | struct fcoe_crc_eof *crc; | ||
374 | |||
375 | fcerr = (staterr & IXGBE_RXDADV_ERR_FCERR); | ||
376 | fceofe = (staterr & IXGBE_RXDADV_ERR_FCEOFE); | ||
377 | if (fcerr == IXGBE_FCERR_BADCRC) | ||
378 | skb_checksum_none_assert(skb); | ||
379 | else | ||
380 | skb->ip_summed = CHECKSUM_UNNECESSARY; | ||
381 | |||
382 | if (eth_hdr(skb)->h_proto == htons(ETH_P_8021Q)) | ||
383 | fh = (struct fc_frame_header *)(skb->data + | ||
384 | sizeof(struct vlan_hdr) + sizeof(struct fcoe_hdr)); | ||
385 | else | ||
386 | fh = (struct fc_frame_header *)(skb->data + | ||
387 | sizeof(struct fcoe_hdr)); | ||
388 | fctl = ntoh24(fh->fh_f_ctl); | ||
389 | if (fctl & FC_FC_EX_CTX) | ||
390 | xid = be16_to_cpu(fh->fh_ox_id); | ||
391 | else | ||
392 | xid = be16_to_cpu(fh->fh_rx_id); | ||
393 | |||
394 | if (xid >= IXGBE_FCOE_DDP_MAX) | ||
395 | goto ddp_out; | ||
396 | |||
397 | fcoe = &adapter->fcoe; | ||
398 | ddp = &fcoe->ddp[xid]; | ||
399 | if (!ddp->udl) | ||
400 | goto ddp_out; | ||
401 | |||
402 | if (fcerr | fceofe) | ||
403 | goto ddp_out; | ||
404 | |||
405 | fcstat = (staterr & IXGBE_RXDADV_STAT_FCSTAT); | ||
406 | if (fcstat) { | ||
407 | /* update length of DDPed data */ | ||
408 | ddp->len = le32_to_cpu(rx_desc->wb.lower.hi_dword.rss); | ||
409 | /* unmap the sg list when FCP_RSP is received */ | ||
410 | if (fcstat == IXGBE_RXDADV_STAT_FCSTAT_FCPRSP) { | ||
411 | pci_unmap_sg(adapter->pdev, ddp->sgl, | ||
412 | ddp->sgc, DMA_FROM_DEVICE); | ||
413 | ddp->err = (fcerr | fceofe); | ||
414 | ddp->sgl = NULL; | ||
415 | ddp->sgc = 0; | ||
416 | } | ||
417 | /* return 0 to bypass going to ULD for DDPed data */ | ||
418 | if (fcstat == IXGBE_RXDADV_STAT_FCSTAT_DDP) | ||
419 | rc = 0; | ||
420 | else if (ddp->len) | ||
421 | rc = ddp->len; | ||
422 | } | ||
423 | /* In target mode, check the last data frame of the sequence. | ||
424 | * For DDP in target mode, data is already DDPed but the header | ||
425 | * indication of the last data frame ould allow is to tell if we | ||
426 | * got all the data and the ULP can send FCP_RSP back, as this is | ||
427 | * not a full fcoe frame, we fill the trailer here so it won't be | ||
428 | * dropped by the ULP stack. | ||
429 | */ | ||
430 | if ((fh->fh_r_ctl == FC_RCTL_DD_SOL_DATA) && | ||
431 | (fctl & FC_FC_END_SEQ)) { | ||
432 | crc = (struct fcoe_crc_eof *)skb_put(skb, sizeof(*crc)); | ||
433 | crc->fcoe_eof = FC_EOF_T; | ||
434 | } | ||
435 | ddp_out: | ||
436 | return rc; | ||
437 | } | ||
438 | |||
439 | /** | ||
440 | * ixgbe_fso - ixgbe FCoE Sequence Offload (FSO) | ||
441 | * @adapter: ixgbe adapter | ||
442 | * @tx_ring: tx desc ring | ||
443 | * @skb: associated skb | ||
444 | * @tx_flags: tx flags | ||
445 | * @hdr_len: hdr_len to be returned | ||
446 | * | ||
447 | * This sets up large send offload for FCoE | ||
448 | * | ||
449 | * Returns : 0 indicates no FSO, > 0 for FSO, < 0 for error | ||
450 | */ | ||
451 | int ixgbe_fso(struct ixgbe_ring *tx_ring, struct sk_buff *skb, | ||
452 | u32 tx_flags, u8 *hdr_len) | ||
453 | { | ||
454 | struct fc_frame_header *fh; | ||
455 | u32 vlan_macip_lens; | ||
456 | u32 fcoe_sof_eof = 0; | ||
457 | u32 mss_l4len_idx; | ||
458 | u8 sof, eof; | ||
459 | |||
460 | if (skb_is_gso(skb) && (skb_shinfo(skb)->gso_type != SKB_GSO_FCOE)) { | ||
461 | dev_err(tx_ring->dev, "Wrong gso type %d:expecting SKB_GSO_FCOE\n", | ||
462 | skb_shinfo(skb)->gso_type); | ||
463 | return -EINVAL; | ||
464 | } | ||
465 | |||
466 | /* resets the header to point fcoe/fc */ | ||
467 | skb_set_network_header(skb, skb->mac_len); | ||
468 | skb_set_transport_header(skb, skb->mac_len + | ||
469 | sizeof(struct fcoe_hdr)); | ||
470 | |||
471 | /* sets up SOF and ORIS */ | ||
472 | sof = ((struct fcoe_hdr *)skb_network_header(skb))->fcoe_sof; | ||
473 | switch (sof) { | ||
474 | case FC_SOF_I2: | ||
475 | fcoe_sof_eof = IXGBE_ADVTXD_FCOEF_ORIS; | ||
476 | break; | ||
477 | case FC_SOF_I3: | ||
478 | fcoe_sof_eof = IXGBE_ADVTXD_FCOEF_SOF | | ||
479 | IXGBE_ADVTXD_FCOEF_ORIS; | ||
480 | break; | ||
481 | case FC_SOF_N2: | ||
482 | break; | ||
483 | case FC_SOF_N3: | ||
484 | fcoe_sof_eof = IXGBE_ADVTXD_FCOEF_SOF; | ||
485 | break; | ||
486 | default: | ||
487 | dev_warn(tx_ring->dev, "unknown sof = 0x%x\n", sof); | ||
488 | return -EINVAL; | ||
489 | } | ||
490 | |||
491 | /* the first byte of the last dword is EOF */ | ||
492 | skb_copy_bits(skb, skb->len - 4, &eof, 1); | ||
493 | /* sets up EOF and ORIE */ | ||
494 | switch (eof) { | ||
495 | case FC_EOF_N: | ||
496 | fcoe_sof_eof |= IXGBE_ADVTXD_FCOEF_EOF_N; | ||
497 | break; | ||
498 | case FC_EOF_T: | ||
499 | /* lso needs ORIE */ | ||
500 | if (skb_is_gso(skb)) | ||
501 | fcoe_sof_eof |= IXGBE_ADVTXD_FCOEF_EOF_N | | ||
502 | IXGBE_ADVTXD_FCOEF_ORIE; | ||
503 | else | ||
504 | fcoe_sof_eof |= IXGBE_ADVTXD_FCOEF_EOF_T; | ||
505 | break; | ||
506 | case FC_EOF_NI: | ||
507 | fcoe_sof_eof |= IXGBE_ADVTXD_FCOEF_EOF_NI; | ||
508 | break; | ||
509 | case FC_EOF_A: | ||
510 | fcoe_sof_eof |= IXGBE_ADVTXD_FCOEF_EOF_A; | ||
511 | break; | ||
512 | default: | ||
513 | dev_warn(tx_ring->dev, "unknown eof = 0x%x\n", eof); | ||
514 | return -EINVAL; | ||
515 | } | ||
516 | |||
517 | /* sets up PARINC indicating data offset */ | ||
518 | fh = (struct fc_frame_header *)skb_transport_header(skb); | ||
519 | if (fh->fh_f_ctl[2] & FC_FC_REL_OFF) | ||
520 | fcoe_sof_eof |= IXGBE_ADVTXD_FCOEF_PARINC; | ||
521 | |||
522 | /* include trailer in headlen as it is replicated per frame */ | ||
523 | *hdr_len = sizeof(struct fcoe_crc_eof); | ||
524 | |||
525 | /* hdr_len includes fc_hdr if FCoE LSO is enabled */ | ||
526 | if (skb_is_gso(skb)) | ||
527 | *hdr_len += (skb_transport_offset(skb) + | ||
528 | sizeof(struct fc_frame_header)); | ||
529 | |||
530 | /* mss_l4len_id: use 1 for FSO as TSO, no need for L4LEN */ | ||
531 | mss_l4len_idx = skb_shinfo(skb)->gso_size << IXGBE_ADVTXD_MSS_SHIFT; | ||
532 | mss_l4len_idx |= 1 << IXGBE_ADVTXD_IDX_SHIFT; | ||
533 | |||
534 | /* vlan_macip_lens: HEADLEN, MACLEN, VLAN tag */ | ||
535 | vlan_macip_lens = skb_transport_offset(skb) + | ||
536 | sizeof(struct fc_frame_header); | ||
537 | vlan_macip_lens |= (skb_transport_offset(skb) - 4) | ||
538 | << IXGBE_ADVTXD_MACLEN_SHIFT; | ||
539 | vlan_macip_lens |= tx_flags & IXGBE_TX_FLAGS_VLAN_MASK; | ||
540 | |||
541 | /* write context desc */ | ||
542 | ixgbe_tx_ctxtdesc(tx_ring, vlan_macip_lens, fcoe_sof_eof, | ||
543 | IXGBE_ADVTXT_TUCMD_FCOE, mss_l4len_idx); | ||
544 | |||
545 | return skb_is_gso(skb); | ||
546 | } | ||
547 | |||
548 | static void ixgbe_fcoe_ddp_pools_free(struct ixgbe_fcoe *fcoe) | ||
549 | { | ||
550 | unsigned int cpu; | ||
551 | struct pci_pool **pool; | ||
552 | |||
553 | for_each_possible_cpu(cpu) { | ||
554 | pool = per_cpu_ptr(fcoe->pool, cpu); | ||
555 | if (*pool) | ||
556 | pci_pool_destroy(*pool); | ||
557 | } | ||
558 | free_percpu(fcoe->pool); | ||
559 | fcoe->pool = NULL; | ||
560 | } | ||
561 | |||
562 | static void ixgbe_fcoe_ddp_pools_alloc(struct ixgbe_adapter *adapter) | ||
563 | { | ||
564 | struct ixgbe_fcoe *fcoe = &adapter->fcoe; | ||
565 | unsigned int cpu; | ||
566 | struct pci_pool **pool; | ||
567 | char pool_name[32]; | ||
568 | |||
569 | fcoe->pool = alloc_percpu(struct pci_pool *); | ||
570 | if (!fcoe->pool) | ||
571 | return; | ||
572 | |||
573 | /* allocate pci pool for each cpu */ | ||
574 | for_each_possible_cpu(cpu) { | ||
575 | snprintf(pool_name, 32, "ixgbe_fcoe_ddp_%d", cpu); | ||
576 | pool = per_cpu_ptr(fcoe->pool, cpu); | ||
577 | *pool = pci_pool_create(pool_name, | ||
578 | adapter->pdev, IXGBE_FCPTR_MAX, | ||
579 | IXGBE_FCPTR_ALIGN, PAGE_SIZE); | ||
580 | if (!*pool) { | ||
581 | e_err(drv, "failed to alloc DDP pool on cpu:%d\n", cpu); | ||
582 | ixgbe_fcoe_ddp_pools_free(fcoe); | ||
583 | return; | ||
584 | } | ||
585 | } | ||
586 | } | ||
587 | |||
588 | /** | ||
589 | * ixgbe_configure_fcoe - configures registers for fcoe at start | ||
590 | * @adapter: ptr to ixgbe adapter | ||
591 | * | ||
592 | * This sets up FCoE related registers | ||
593 | * | ||
594 | * Returns : none | ||
595 | */ | ||
596 | void ixgbe_configure_fcoe(struct ixgbe_adapter *adapter) | ||
597 | { | ||
598 | int i, fcoe_q, fcoe_i; | ||
599 | struct ixgbe_hw *hw = &adapter->hw; | ||
600 | struct ixgbe_fcoe *fcoe = &adapter->fcoe; | ||
601 | struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_FCOE]; | ||
602 | |||
603 | if (!fcoe->pool) { | ||
604 | spin_lock_init(&fcoe->lock); | ||
605 | |||
606 | ixgbe_fcoe_ddp_pools_alloc(adapter); | ||
607 | if (!fcoe->pool) { | ||
608 | e_err(drv, "failed to alloc percpu fcoe DDP pools\n"); | ||
609 | return; | ||
610 | } | ||
611 | |||
612 | /* Extra buffer to be shared by all DDPs for HW work around */ | ||
613 | fcoe->extra_ddp_buffer = kmalloc(IXGBE_FCBUFF_MIN, GFP_ATOMIC); | ||
614 | if (fcoe->extra_ddp_buffer == NULL) { | ||
615 | e_err(drv, "failed to allocated extra DDP buffer\n"); | ||
616 | goto out_ddp_pools; | ||
617 | } | ||
618 | |||
619 | fcoe->extra_ddp_buffer_dma = | ||
620 | dma_map_single(&adapter->pdev->dev, | ||
621 | fcoe->extra_ddp_buffer, | ||
622 | IXGBE_FCBUFF_MIN, | ||
623 | DMA_FROM_DEVICE); | ||
624 | if (dma_mapping_error(&adapter->pdev->dev, | ||
625 | fcoe->extra_ddp_buffer_dma)) { | ||
626 | e_err(drv, "failed to map extra DDP buffer\n"); | ||
627 | goto out_extra_ddp_buffer; | ||
628 | } | ||
629 | } | ||
630 | |||
631 | /* Enable L2 eth type filter for FCoE */ | ||
632 | IXGBE_WRITE_REG(hw, IXGBE_ETQF(IXGBE_ETQF_FILTER_FCOE), | ||
633 | (ETH_P_FCOE | IXGBE_ETQF_FCOE | IXGBE_ETQF_FILTER_EN)); | ||
634 | /* Enable L2 eth type filter for FIP */ | ||
635 | IXGBE_WRITE_REG(hw, IXGBE_ETQF(IXGBE_ETQF_FILTER_FIP), | ||
636 | (ETH_P_FIP | IXGBE_ETQF_FILTER_EN)); | ||
637 | if (adapter->ring_feature[RING_F_FCOE].indices) { | ||
638 | /* Use multiple rx queues for FCoE by redirection table */ | ||
639 | for (i = 0; i < IXGBE_FCRETA_SIZE; i++) { | ||
640 | fcoe_i = f->mask + i % f->indices; | ||
641 | fcoe_i &= IXGBE_FCRETA_ENTRY_MASK; | ||
642 | fcoe_q = adapter->rx_ring[fcoe_i]->reg_idx; | ||
643 | IXGBE_WRITE_REG(hw, IXGBE_FCRETA(i), fcoe_q); | ||
644 | } | ||
645 | IXGBE_WRITE_REG(hw, IXGBE_FCRECTL, IXGBE_FCRECTL_ENA); | ||
646 | IXGBE_WRITE_REG(hw, IXGBE_ETQS(IXGBE_ETQF_FILTER_FCOE), 0); | ||
647 | } else { | ||
648 | /* Use single rx queue for FCoE */ | ||
649 | fcoe_i = f->mask; | ||
650 | fcoe_q = adapter->rx_ring[fcoe_i]->reg_idx; | ||
651 | IXGBE_WRITE_REG(hw, IXGBE_FCRECTL, 0); | ||
652 | IXGBE_WRITE_REG(hw, IXGBE_ETQS(IXGBE_ETQF_FILTER_FCOE), | ||
653 | IXGBE_ETQS_QUEUE_EN | | ||
654 | (fcoe_q << IXGBE_ETQS_RX_QUEUE_SHIFT)); | ||
655 | } | ||
656 | /* send FIP frames to the first FCoE queue */ | ||
657 | fcoe_i = f->mask; | ||
658 | fcoe_q = adapter->rx_ring[fcoe_i]->reg_idx; | ||
659 | IXGBE_WRITE_REG(hw, IXGBE_ETQS(IXGBE_ETQF_FILTER_FIP), | ||
660 | IXGBE_ETQS_QUEUE_EN | | ||
661 | (fcoe_q << IXGBE_ETQS_RX_QUEUE_SHIFT)); | ||
662 | |||
663 | IXGBE_WRITE_REG(hw, IXGBE_FCRXCTRL, | ||
664 | IXGBE_FCRXCTRL_FCOELLI | | ||
665 | IXGBE_FCRXCTRL_FCCRCBO | | ||
666 | (FC_FCOE_VER << IXGBE_FCRXCTRL_FCOEVER_SHIFT)); | ||
667 | return; | ||
668 | |||
669 | out_extra_ddp_buffer: | ||
670 | kfree(fcoe->extra_ddp_buffer); | ||
671 | out_ddp_pools: | ||
672 | ixgbe_fcoe_ddp_pools_free(fcoe); | ||
673 | } | ||
674 | |||
675 | /** | ||
676 | * ixgbe_cleanup_fcoe - release all fcoe ddp context resources | ||
677 | * @adapter : ixgbe adapter | ||
678 | * | ||
679 | * Cleans up outstanding ddp context resources | ||
680 | * | ||
681 | * Returns : none | ||
682 | */ | ||
683 | void ixgbe_cleanup_fcoe(struct ixgbe_adapter *adapter) | ||
684 | { | ||
685 | int i; | ||
686 | struct ixgbe_fcoe *fcoe = &adapter->fcoe; | ||
687 | |||
688 | if (!fcoe->pool) | ||
689 | return; | ||
690 | |||
691 | for (i = 0; i < IXGBE_FCOE_DDP_MAX; i++) | ||
692 | ixgbe_fcoe_ddp_put(adapter->netdev, i); | ||
693 | dma_unmap_single(&adapter->pdev->dev, | ||
694 | fcoe->extra_ddp_buffer_dma, | ||
695 | IXGBE_FCBUFF_MIN, | ||
696 | DMA_FROM_DEVICE); | ||
697 | kfree(fcoe->extra_ddp_buffer); | ||
698 | ixgbe_fcoe_ddp_pools_free(fcoe); | ||
699 | } | ||
700 | |||
701 | /** | ||
702 | * ixgbe_fcoe_enable - turn on FCoE offload feature | ||
703 | * @netdev: the corresponding netdev | ||
704 | * | ||
705 | * Turns on FCoE offload feature in 82599. | ||
706 | * | ||
707 | * Returns : 0 indicates success or -EINVAL on failure | ||
708 | */ | ||
709 | int ixgbe_fcoe_enable(struct net_device *netdev) | ||
710 | { | ||
711 | int rc = -EINVAL; | ||
712 | struct ixgbe_adapter *adapter = netdev_priv(netdev); | ||
713 | struct ixgbe_fcoe *fcoe = &adapter->fcoe; | ||
714 | |||
715 | |||
716 | if (!(adapter->flags & IXGBE_FLAG_FCOE_CAPABLE)) | ||
717 | goto out_enable; | ||
718 | |||
719 | atomic_inc(&fcoe->refcnt); | ||
720 | if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) | ||
721 | goto out_enable; | ||
722 | |||
723 | e_info(drv, "Enabling FCoE offload features.\n"); | ||
724 | if (netif_running(netdev)) | ||
725 | netdev->netdev_ops->ndo_stop(netdev); | ||
726 | |||
727 | ixgbe_clear_interrupt_scheme(adapter); | ||
728 | |||
729 | adapter->flags |= IXGBE_FLAG_FCOE_ENABLED; | ||
730 | adapter->ring_feature[RING_F_FCOE].indices = IXGBE_FCRETA_SIZE; | ||
731 | netdev->features |= NETIF_F_FCOE_CRC; | ||
732 | netdev->features |= NETIF_F_FSO; | ||
733 | netdev->features |= NETIF_F_FCOE_MTU; | ||
734 | netdev->fcoe_ddp_xid = IXGBE_FCOE_DDP_MAX - 1; | ||
735 | |||
736 | ixgbe_init_interrupt_scheme(adapter); | ||
737 | netdev_features_change(netdev); | ||
738 | |||
739 | if (netif_running(netdev)) | ||
740 | netdev->netdev_ops->ndo_open(netdev); | ||
741 | rc = 0; | ||
742 | |||
743 | out_enable: | ||
744 | return rc; | ||
745 | } | ||
746 | |||
747 | /** | ||
748 | * ixgbe_fcoe_disable - turn off FCoE offload feature | ||
749 | * @netdev: the corresponding netdev | ||
750 | * | ||
751 | * Turns off FCoE offload feature in 82599. | ||
752 | * | ||
753 | * Returns : 0 indicates success or -EINVAL on failure | ||
754 | */ | ||
755 | int ixgbe_fcoe_disable(struct net_device *netdev) | ||
756 | { | ||
757 | int rc = -EINVAL; | ||
758 | struct ixgbe_adapter *adapter = netdev_priv(netdev); | ||
759 | struct ixgbe_fcoe *fcoe = &adapter->fcoe; | ||
760 | |||
761 | if (!(adapter->flags & IXGBE_FLAG_FCOE_CAPABLE)) | ||
762 | goto out_disable; | ||
763 | |||
764 | if (!(adapter->flags & IXGBE_FLAG_FCOE_ENABLED)) | ||
765 | goto out_disable; | ||
766 | |||
767 | if (!atomic_dec_and_test(&fcoe->refcnt)) | ||
768 | goto out_disable; | ||
769 | |||
770 | e_info(drv, "Disabling FCoE offload features.\n"); | ||
771 | netdev->features &= ~NETIF_F_FCOE_CRC; | ||
772 | netdev->features &= ~NETIF_F_FSO; | ||
773 | netdev->features &= ~NETIF_F_FCOE_MTU; | ||
774 | netdev->fcoe_ddp_xid = 0; | ||
775 | netdev_features_change(netdev); | ||
776 | |||
777 | if (netif_running(netdev)) | ||
778 | netdev->netdev_ops->ndo_stop(netdev); | ||
779 | |||
780 | ixgbe_clear_interrupt_scheme(adapter); | ||
781 | adapter->flags &= ~IXGBE_FLAG_FCOE_ENABLED; | ||
782 | adapter->ring_feature[RING_F_FCOE].indices = 0; | ||
783 | ixgbe_cleanup_fcoe(adapter); | ||
784 | ixgbe_init_interrupt_scheme(adapter); | ||
785 | |||
786 | if (netif_running(netdev)) | ||
787 | netdev->netdev_ops->ndo_open(netdev); | ||
788 | rc = 0; | ||
789 | |||
790 | out_disable: | ||
791 | return rc; | ||
792 | } | ||
793 | |||
794 | /** | ||
795 | * ixgbe_fcoe_get_wwn - get world wide name for the node or the port | ||
796 | * @netdev : ixgbe adapter | ||
797 | * @wwn : the world wide name | ||
798 | * @type: the type of world wide name | ||
799 | * | ||
800 | * Returns the node or port world wide name if both the prefix and the san | ||
801 | * mac address are valid, then the wwn is formed based on the NAA-2 for | ||
802 | * IEEE Extended name identifier (ref. to T10 FC-LS Spec., Sec. 15.3). | ||
803 | * | ||
804 | * Returns : 0 on success | ||
805 | */ | ||
806 | int ixgbe_fcoe_get_wwn(struct net_device *netdev, u64 *wwn, int type) | ||
807 | { | ||
808 | int rc = -EINVAL; | ||
809 | u16 prefix = 0xffff; | ||
810 | struct ixgbe_adapter *adapter = netdev_priv(netdev); | ||
811 | struct ixgbe_mac_info *mac = &adapter->hw.mac; | ||
812 | |||
813 | switch (type) { | ||
814 | case NETDEV_FCOE_WWNN: | ||
815 | prefix = mac->wwnn_prefix; | ||
816 | break; | ||
817 | case NETDEV_FCOE_WWPN: | ||
818 | prefix = mac->wwpn_prefix; | ||
819 | break; | ||
820 | default: | ||
821 | break; | ||
822 | } | ||
823 | |||
824 | if ((prefix != 0xffff) && | ||
825 | is_valid_ether_addr(mac->san_addr)) { | ||
826 | *wwn = ((u64) prefix << 48) | | ||
827 | ((u64) mac->san_addr[0] << 40) | | ||
828 | ((u64) mac->san_addr[1] << 32) | | ||
829 | ((u64) mac->san_addr[2] << 24) | | ||
830 | ((u64) mac->san_addr[3] << 16) | | ||
831 | ((u64) mac->san_addr[4] << 8) | | ||
832 | ((u64) mac->san_addr[5]); | ||
833 | rc = 0; | ||
834 | } | ||
835 | return rc; | ||
836 | } | ||
diff --git a/drivers/net/ixgbe/ixgbe_fcoe.h b/drivers/net/ixgbe/ixgbe_fcoe.h new file mode 100644 index 00000000000..99de145e290 --- /dev/null +++ b/drivers/net/ixgbe/ixgbe_fcoe.h | |||
@@ -0,0 +1,81 @@ | |||
1 | /******************************************************************************* | ||
2 | |||
3 | Intel 10 Gigabit PCI Express Linux driver | ||
4 | Copyright(c) 1999 - 2011 Intel Corporation. | ||
5 | |||
6 | This program is free software; you can redistribute it and/or modify it | ||
7 | under the terms and conditions of the GNU General Public License, | ||
8 | version 2, as published by the Free Software Foundation. | ||
9 | |||
10 | This program is distributed in the hope it will be useful, but WITHOUT | ||
11 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
12 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
13 | more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License along with | ||
16 | this program; if not, write to the Free Software Foundation, Inc., | ||
17 | 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. | ||
18 | |||
19 | The full GNU General Public License is included in this distribution in | ||
20 | the file called "COPYING". | ||
21 | |||
22 | Contact Information: | ||
23 | e1000-devel Mailing List <e1000-devel@lists.sourceforge.net> | ||
24 | Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 | ||
25 | |||
26 | *******************************************************************************/ | ||
27 | |||
28 | #ifndef _IXGBE_FCOE_H | ||
29 | #define _IXGBE_FCOE_H | ||
30 | |||
31 | #include <scsi/fc/fc_fs.h> | ||
32 | #include <scsi/fc/fc_fcoe.h> | ||
33 | |||
34 | /* shift bits within STAT fo FCSTAT */ | ||
35 | #define IXGBE_RXDADV_FCSTAT_SHIFT 4 | ||
36 | |||
37 | /* ddp user buffer */ | ||
38 | #define IXGBE_BUFFCNT_MAX 256 /* 8 bits bufcnt */ | ||
39 | #define IXGBE_FCPTR_ALIGN 16 | ||
40 | #define IXGBE_FCPTR_MAX (IXGBE_BUFFCNT_MAX * sizeof(dma_addr_t)) | ||
41 | #define IXGBE_FCBUFF_4KB 0x0 | ||
42 | #define IXGBE_FCBUFF_8KB 0x1 | ||
43 | #define IXGBE_FCBUFF_16KB 0x2 | ||
44 | #define IXGBE_FCBUFF_64KB 0x3 | ||
45 | #define IXGBE_FCBUFF_MAX 65536 /* 64KB max */ | ||
46 | #define IXGBE_FCBUFF_MIN 4096 /* 4KB min */ | ||
47 | #define IXGBE_FCOE_DDP_MAX 512 /* 9 bits xid */ | ||
48 | |||
49 | /* Default traffic class to use for FCoE */ | ||
50 | #define IXGBE_FCOE_DEFTC 3 | ||
51 | |||
52 | /* fcerr */ | ||
53 | #define IXGBE_FCERR_BADCRC 0x00100000 | ||
54 | |||
55 | /* FCoE DDP for target mode */ | ||
56 | #define __IXGBE_FCOE_TARGET 1 | ||
57 | |||
58 | struct ixgbe_fcoe_ddp { | ||
59 | int len; | ||
60 | u32 err; | ||
61 | unsigned int sgc; | ||
62 | struct scatterlist *sgl; | ||
63 | dma_addr_t udp; | ||
64 | u64 *udl; | ||
65 | struct pci_pool *pool; | ||
66 | }; | ||
67 | |||
68 | struct ixgbe_fcoe { | ||
69 | struct pci_pool **pool; | ||
70 | atomic_t refcnt; | ||
71 | spinlock_t lock; | ||
72 | struct ixgbe_fcoe_ddp ddp[IXGBE_FCOE_DDP_MAX]; | ||
73 | unsigned char *extra_ddp_buffer; | ||
74 | dma_addr_t extra_ddp_buffer_dma; | ||
75 | unsigned long mode; | ||
76 | #ifdef CONFIG_IXGBE_DCB | ||
77 | u8 up; | ||
78 | #endif | ||
79 | }; | ||
80 | |||
81 | #endif /* _IXGBE_FCOE_H */ | ||
diff --git a/drivers/net/ixgbe/ixgbe_main.c b/drivers/net/ixgbe/ixgbe_main.c new file mode 100644 index 00000000000..e1fcc958927 --- /dev/null +++ b/drivers/net/ixgbe/ixgbe_main.c | |||
@@ -0,0 +1,7936 @@ | |||
1 | /******************************************************************************* | ||
2 | |||
3 | Intel 10 Gigabit PCI Express Linux driver | ||
4 | Copyright(c) 1999 - 2011 Intel Corporation. | ||
5 | |||
6 | This program is free software; you can redistribute it and/or modify it | ||
7 | under the terms and conditions of the GNU General Public License, | ||
8 | version 2, as published by the Free Software Foundation. | ||
9 | |||
10 | This program is distributed in the hope it will be useful, but WITHOUT | ||
11 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
12 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
13 | more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License along with | ||
16 | this program; if not, write to the Free Software Foundation, Inc., | ||
17 | 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. | ||
18 | |||
19 | The full GNU General Public License is included in this distribution in | ||
20 | the file called "COPYING". | ||
21 | |||
22 | Contact Information: | ||
23 | e1000-devel Mailing List <e1000-devel@lists.sourceforge.net> | ||
24 | Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 | ||
25 | |||
26 | *******************************************************************************/ | ||
27 | |||
28 | #include <linux/types.h> | ||
29 | #include <linux/module.h> | ||
30 | #include <linux/pci.h> | ||
31 | #include <linux/netdevice.h> | ||
32 | #include <linux/vmalloc.h> | ||
33 | #include <linux/string.h> | ||
34 | #include <linux/in.h> | ||
35 | #include <linux/interrupt.h> | ||
36 | #include <linux/ip.h> | ||
37 | #include <linux/tcp.h> | ||
38 | #include <linux/sctp.h> | ||
39 | #include <linux/pkt_sched.h> | ||
40 | #include <linux/ipv6.h> | ||
41 | #include <linux/slab.h> | ||
42 | #include <net/checksum.h> | ||
43 | #include <net/ip6_checksum.h> | ||
44 | #include <linux/ethtool.h> | ||
45 | #include <linux/if_vlan.h> | ||
46 | #include <linux/prefetch.h> | ||
47 | #include <scsi/fc/fc_fcoe.h> | ||
48 | |||
49 | #include "ixgbe.h" | ||
50 | #include "ixgbe_common.h" | ||
51 | #include "ixgbe_dcb_82599.h" | ||
52 | #include "ixgbe_sriov.h" | ||
53 | |||
54 | char ixgbe_driver_name[] = "ixgbe"; | ||
55 | static const char ixgbe_driver_string[] = | ||
56 | "Intel(R) 10 Gigabit PCI Express Network Driver"; | ||
57 | #define MAJ 3 | ||
58 | #define MIN 4 | ||
59 | #define BUILD 8 | ||
60 | #define DRV_VERSION __stringify(MAJ) "." __stringify(MIN) "." \ | ||
61 | __stringify(BUILD) "-k" | ||
62 | const char ixgbe_driver_version[] = DRV_VERSION; | ||
63 | static const char ixgbe_copyright[] = | ||
64 | "Copyright (c) 1999-2011 Intel Corporation."; | ||
65 | |||
66 | static const struct ixgbe_info *ixgbe_info_tbl[] = { | ||
67 | [board_82598] = &ixgbe_82598_info, | ||
68 | [board_82599] = &ixgbe_82599_info, | ||
69 | [board_X540] = &ixgbe_X540_info, | ||
70 | }; | ||
71 | |||
72 | /* ixgbe_pci_tbl - PCI Device ID Table | ||
73 | * | ||
74 | * Wildcard entries (PCI_ANY_ID) should come last | ||
75 | * Last entry must be all 0s | ||
76 | * | ||
77 | * { Vendor ID, Device ID, SubVendor ID, SubDevice ID, | ||
78 | * Class, Class Mask, private data (not used) } | ||
79 | */ | ||
80 | static DEFINE_PCI_DEVICE_TABLE(ixgbe_pci_tbl) = { | ||
81 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598), | ||
82 | board_82598 }, | ||
83 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AF_DUAL_PORT), | ||
84 | board_82598 }, | ||
85 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AF_SINGLE_PORT), | ||
86 | board_82598 }, | ||
87 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AT), | ||
88 | board_82598 }, | ||
89 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AT2), | ||
90 | board_82598 }, | ||
91 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_CX4), | ||
92 | board_82598 }, | ||
93 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_CX4_DUAL_PORT), | ||
94 | board_82598 }, | ||
95 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_DA_DUAL_PORT), | ||
96 | board_82598 }, | ||
97 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_SR_DUAL_PORT_EM), | ||
98 | board_82598 }, | ||
99 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_XF_LR), | ||
100 | board_82598 }, | ||
101 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_SFP_LOM), | ||
102 | board_82598 }, | ||
103 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_BX), | ||
104 | board_82598 }, | ||
105 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KX4), | ||
106 | board_82599 }, | ||
107 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_XAUI_LOM), | ||
108 | board_82599 }, | ||
109 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KR), | ||
110 | board_82599 }, | ||
111 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP), | ||
112 | board_82599 }, | ||
113 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_EM), | ||
114 | board_82599 }, | ||
115 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KX4_MEZZ), | ||
116 | board_82599 }, | ||
117 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_CX4), | ||
118 | board_82599 }, | ||
119 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_BACKPLANE_FCOE), | ||
120 | board_82599 }, | ||
121 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_FCOE), | ||
122 | board_82599 }, | ||
123 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_T3_LOM), | ||
124 | board_82599 }, | ||
125 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_COMBO_BACKPLANE), | ||
126 | board_82599 }, | ||
127 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X540T), | ||
128 | board_X540 }, | ||
129 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_SF2), | ||
130 | board_82599 }, | ||
131 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_LS), | ||
132 | board_82599 }, | ||
133 | |||
134 | /* required last entry */ | ||
135 | {0, } | ||
136 | }; | ||
137 | MODULE_DEVICE_TABLE(pci, ixgbe_pci_tbl); | ||
138 | |||
139 | #ifdef CONFIG_IXGBE_DCA | ||
140 | static int ixgbe_notify_dca(struct notifier_block *, unsigned long event, | ||
141 | void *p); | ||
142 | static struct notifier_block dca_notifier = { | ||
143 | .notifier_call = ixgbe_notify_dca, | ||
144 | .next = NULL, | ||
145 | .priority = 0 | ||
146 | }; | ||
147 | #endif | ||
148 | |||
149 | #ifdef CONFIG_PCI_IOV | ||
150 | static unsigned int max_vfs; | ||
151 | module_param(max_vfs, uint, 0); | ||
152 | MODULE_PARM_DESC(max_vfs, | ||
153 | "Maximum number of virtual functions to allocate per physical function"); | ||
154 | #endif /* CONFIG_PCI_IOV */ | ||
155 | |||
156 | MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>"); | ||
157 | MODULE_DESCRIPTION("Intel(R) 10 Gigabit PCI Express Network Driver"); | ||
158 | MODULE_LICENSE("GPL"); | ||
159 | MODULE_VERSION(DRV_VERSION); | ||
160 | |||
161 | #define DEFAULT_DEBUG_LEVEL_SHIFT 3 | ||
162 | |||
163 | static inline void ixgbe_disable_sriov(struct ixgbe_adapter *adapter) | ||
164 | { | ||
165 | struct ixgbe_hw *hw = &adapter->hw; | ||
166 | u32 gcr; | ||
167 | u32 gpie; | ||
168 | u32 vmdctl; | ||
169 | |||
170 | #ifdef CONFIG_PCI_IOV | ||
171 | /* disable iov and allow time for transactions to clear */ | ||
172 | pci_disable_sriov(adapter->pdev); | ||
173 | #endif | ||
174 | |||
175 | /* turn off device IOV mode */ | ||
176 | gcr = IXGBE_READ_REG(hw, IXGBE_GCR_EXT); | ||
177 | gcr &= ~(IXGBE_GCR_EXT_SRIOV); | ||
178 | IXGBE_WRITE_REG(hw, IXGBE_GCR_EXT, gcr); | ||
179 | gpie = IXGBE_READ_REG(hw, IXGBE_GPIE); | ||
180 | gpie &= ~IXGBE_GPIE_VTMODE_MASK; | ||
181 | IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie); | ||
182 | |||
183 | /* set default pool back to 0 */ | ||
184 | vmdctl = IXGBE_READ_REG(hw, IXGBE_VT_CTL); | ||
185 | vmdctl &= ~IXGBE_VT_CTL_POOL_MASK; | ||
186 | IXGBE_WRITE_REG(hw, IXGBE_VT_CTL, vmdctl); | ||
187 | IXGBE_WRITE_FLUSH(hw); | ||
188 | |||
189 | /* take a breather then clean up driver data */ | ||
190 | msleep(100); | ||
191 | |||
192 | kfree(adapter->vfinfo); | ||
193 | adapter->vfinfo = NULL; | ||
194 | |||
195 | adapter->num_vfs = 0; | ||
196 | adapter->flags &= ~IXGBE_FLAG_SRIOV_ENABLED; | ||
197 | } | ||
198 | |||
199 | static void ixgbe_service_event_schedule(struct ixgbe_adapter *adapter) | ||
200 | { | ||
201 | if (!test_bit(__IXGBE_DOWN, &adapter->state) && | ||
202 | !test_and_set_bit(__IXGBE_SERVICE_SCHED, &adapter->state)) | ||
203 | schedule_work(&adapter->service_task); | ||
204 | } | ||
205 | |||
206 | static void ixgbe_service_event_complete(struct ixgbe_adapter *adapter) | ||
207 | { | ||
208 | BUG_ON(!test_bit(__IXGBE_SERVICE_SCHED, &adapter->state)); | ||
209 | |||
210 | /* flush memory to make sure state is correct before next watchog */ | ||
211 | smp_mb__before_clear_bit(); | ||
212 | clear_bit(__IXGBE_SERVICE_SCHED, &adapter->state); | ||
213 | } | ||
214 | |||
215 | struct ixgbe_reg_info { | ||
216 | u32 ofs; | ||
217 | char *name; | ||
218 | }; | ||
219 | |||
220 | static const struct ixgbe_reg_info ixgbe_reg_info_tbl[] = { | ||
221 | |||
222 | /* General Registers */ | ||
223 | {IXGBE_CTRL, "CTRL"}, | ||
224 | {IXGBE_STATUS, "STATUS"}, | ||
225 | {IXGBE_CTRL_EXT, "CTRL_EXT"}, | ||
226 | |||
227 | /* Interrupt Registers */ | ||
228 | {IXGBE_EICR, "EICR"}, | ||
229 | |||
230 | /* RX Registers */ | ||
231 | {IXGBE_SRRCTL(0), "SRRCTL"}, | ||
232 | {IXGBE_DCA_RXCTRL(0), "DRXCTL"}, | ||
233 | {IXGBE_RDLEN(0), "RDLEN"}, | ||
234 | {IXGBE_RDH(0), "RDH"}, | ||
235 | {IXGBE_RDT(0), "RDT"}, | ||
236 | {IXGBE_RXDCTL(0), "RXDCTL"}, | ||
237 | {IXGBE_RDBAL(0), "RDBAL"}, | ||
238 | {IXGBE_RDBAH(0), "RDBAH"}, | ||
239 | |||
240 | /* TX Registers */ | ||
241 | {IXGBE_TDBAL(0), "TDBAL"}, | ||
242 | {IXGBE_TDBAH(0), "TDBAH"}, | ||
243 | {IXGBE_TDLEN(0), "TDLEN"}, | ||
244 | {IXGBE_TDH(0), "TDH"}, | ||
245 | {IXGBE_TDT(0), "TDT"}, | ||
246 | {IXGBE_TXDCTL(0), "TXDCTL"}, | ||
247 | |||
248 | /* List Terminator */ | ||
249 | {} | ||
250 | }; | ||
251 | |||
252 | |||
253 | /* | ||
254 | * ixgbe_regdump - register printout routine | ||
255 | */ | ||
256 | static void ixgbe_regdump(struct ixgbe_hw *hw, struct ixgbe_reg_info *reginfo) | ||
257 | { | ||
258 | int i = 0, j = 0; | ||
259 | char rname[16]; | ||
260 | u32 regs[64]; | ||
261 | |||
262 | switch (reginfo->ofs) { | ||
263 | case IXGBE_SRRCTL(0): | ||
264 | for (i = 0; i < 64; i++) | ||
265 | regs[i] = IXGBE_READ_REG(hw, IXGBE_SRRCTL(i)); | ||
266 | break; | ||
267 | case IXGBE_DCA_RXCTRL(0): | ||
268 | for (i = 0; i < 64; i++) | ||
269 | regs[i] = IXGBE_READ_REG(hw, IXGBE_DCA_RXCTRL(i)); | ||
270 | break; | ||
271 | case IXGBE_RDLEN(0): | ||
272 | for (i = 0; i < 64; i++) | ||
273 | regs[i] = IXGBE_READ_REG(hw, IXGBE_RDLEN(i)); | ||
274 | break; | ||
275 | case IXGBE_RDH(0): | ||
276 | for (i = 0; i < 64; i++) | ||
277 | regs[i] = IXGBE_READ_REG(hw, IXGBE_RDH(i)); | ||
278 | break; | ||
279 | case IXGBE_RDT(0): | ||
280 | for (i = 0; i < 64; i++) | ||
281 | regs[i] = IXGBE_READ_REG(hw, IXGBE_RDT(i)); | ||
282 | break; | ||
283 | case IXGBE_RXDCTL(0): | ||
284 | for (i = 0; i < 64; i++) | ||
285 | regs[i] = IXGBE_READ_REG(hw, IXGBE_RXDCTL(i)); | ||
286 | break; | ||
287 | case IXGBE_RDBAL(0): | ||
288 | for (i = 0; i < 64; i++) | ||
289 | regs[i] = IXGBE_READ_REG(hw, IXGBE_RDBAL(i)); | ||
290 | break; | ||
291 | case IXGBE_RDBAH(0): | ||
292 | for (i = 0; i < 64; i++) | ||
293 | regs[i] = IXGBE_READ_REG(hw, IXGBE_RDBAH(i)); | ||
294 | break; | ||
295 | case IXGBE_TDBAL(0): | ||
296 | for (i = 0; i < 64; i++) | ||
297 | regs[i] = IXGBE_READ_REG(hw, IXGBE_TDBAL(i)); | ||
298 | break; | ||
299 | case IXGBE_TDBAH(0): | ||
300 | for (i = 0; i < 64; i++) | ||
301 | regs[i] = IXGBE_READ_REG(hw, IXGBE_TDBAH(i)); | ||
302 | break; | ||
303 | case IXGBE_TDLEN(0): | ||
304 | for (i = 0; i < 64; i++) | ||
305 | regs[i] = IXGBE_READ_REG(hw, IXGBE_TDLEN(i)); | ||
306 | break; | ||
307 | case IXGBE_TDH(0): | ||
308 | for (i = 0; i < 64; i++) | ||
309 | regs[i] = IXGBE_READ_REG(hw, IXGBE_TDH(i)); | ||
310 | break; | ||
311 | case IXGBE_TDT(0): | ||
312 | for (i = 0; i < 64; i++) | ||
313 | regs[i] = IXGBE_READ_REG(hw, IXGBE_TDT(i)); | ||
314 | break; | ||
315 | case IXGBE_TXDCTL(0): | ||
316 | for (i = 0; i < 64; i++) | ||
317 | regs[i] = IXGBE_READ_REG(hw, IXGBE_TXDCTL(i)); | ||
318 | break; | ||
319 | default: | ||
320 | pr_info("%-15s %08x\n", reginfo->name, | ||
321 | IXGBE_READ_REG(hw, reginfo->ofs)); | ||
322 | return; | ||
323 | } | ||
324 | |||
325 | for (i = 0; i < 8; i++) { | ||
326 | snprintf(rname, 16, "%s[%d-%d]", reginfo->name, i*8, i*8+7); | ||
327 | pr_err("%-15s", rname); | ||
328 | for (j = 0; j < 8; j++) | ||
329 | pr_cont(" %08x", regs[i*8+j]); | ||
330 | pr_cont("\n"); | ||
331 | } | ||
332 | |||
333 | } | ||
334 | |||
335 | /* | ||
336 | * ixgbe_dump - Print registers, tx-rings and rx-rings | ||
337 | */ | ||
338 | static void ixgbe_dump(struct ixgbe_adapter *adapter) | ||
339 | { | ||
340 | struct net_device *netdev = adapter->netdev; | ||
341 | struct ixgbe_hw *hw = &adapter->hw; | ||
342 | struct ixgbe_reg_info *reginfo; | ||
343 | int n = 0; | ||
344 | struct ixgbe_ring *tx_ring; | ||
345 | struct ixgbe_tx_buffer *tx_buffer_info; | ||
346 | union ixgbe_adv_tx_desc *tx_desc; | ||
347 | struct my_u0 { u64 a; u64 b; } *u0; | ||
348 | struct ixgbe_ring *rx_ring; | ||
349 | union ixgbe_adv_rx_desc *rx_desc; | ||
350 | struct ixgbe_rx_buffer *rx_buffer_info; | ||
351 | u32 staterr; | ||
352 | int i = 0; | ||
353 | |||
354 | if (!netif_msg_hw(adapter)) | ||
355 | return; | ||
356 | |||
357 | /* Print netdevice Info */ | ||
358 | if (netdev) { | ||
359 | dev_info(&adapter->pdev->dev, "Net device Info\n"); | ||
360 | pr_info("Device Name state " | ||
361 | "trans_start last_rx\n"); | ||
362 | pr_info("%-15s %016lX %016lX %016lX\n", | ||
363 | netdev->name, | ||
364 | netdev->state, | ||
365 | netdev->trans_start, | ||
366 | netdev->last_rx); | ||
367 | } | ||
368 | |||
369 | /* Print Registers */ | ||
370 | dev_info(&adapter->pdev->dev, "Register Dump\n"); | ||
371 | pr_info(" Register Name Value\n"); | ||
372 | for (reginfo = (struct ixgbe_reg_info *)ixgbe_reg_info_tbl; | ||
373 | reginfo->name; reginfo++) { | ||
374 | ixgbe_regdump(hw, reginfo); | ||
375 | } | ||
376 | |||
377 | /* Print TX Ring Summary */ | ||
378 | if (!netdev || !netif_running(netdev)) | ||
379 | goto exit; | ||
380 | |||
381 | dev_info(&adapter->pdev->dev, "TX Rings Summary\n"); | ||
382 | pr_info("Queue [NTU] [NTC] [bi(ntc)->dma ] leng ntw timestamp\n"); | ||
383 | for (n = 0; n < adapter->num_tx_queues; n++) { | ||
384 | tx_ring = adapter->tx_ring[n]; | ||
385 | tx_buffer_info = | ||
386 | &tx_ring->tx_buffer_info[tx_ring->next_to_clean]; | ||
387 | pr_info(" %5d %5X %5X %016llX %04X %3X %016llX\n", | ||
388 | n, tx_ring->next_to_use, tx_ring->next_to_clean, | ||
389 | (u64)tx_buffer_info->dma, | ||
390 | tx_buffer_info->length, | ||
391 | tx_buffer_info->next_to_watch, | ||
392 | (u64)tx_buffer_info->time_stamp); | ||
393 | } | ||
394 | |||
395 | /* Print TX Rings */ | ||
396 | if (!netif_msg_tx_done(adapter)) | ||
397 | goto rx_ring_summary; | ||
398 | |||
399 | dev_info(&adapter->pdev->dev, "TX Rings Dump\n"); | ||
400 | |||
401 | /* Transmit Descriptor Formats | ||
402 | * | ||
403 | * Advanced Transmit Descriptor | ||
404 | * +--------------------------------------------------------------+ | ||
405 | * 0 | Buffer Address [63:0] | | ||
406 | * +--------------------------------------------------------------+ | ||
407 | * 8 | PAYLEN | PORTS | IDX | STA | DCMD |DTYP | RSV | DTALEN | | ||
408 | * +--------------------------------------------------------------+ | ||
409 | * 63 46 45 40 39 36 35 32 31 24 23 20 19 0 | ||
410 | */ | ||
411 | |||
412 | for (n = 0; n < adapter->num_tx_queues; n++) { | ||
413 | tx_ring = adapter->tx_ring[n]; | ||
414 | pr_info("------------------------------------\n"); | ||
415 | pr_info("TX QUEUE INDEX = %d\n", tx_ring->queue_index); | ||
416 | pr_info("------------------------------------\n"); | ||
417 | pr_info("T [desc] [address 63:0 ] " | ||
418 | "[PlPOIdStDDt Ln] [bi->dma ] " | ||
419 | "leng ntw timestamp bi->skb\n"); | ||
420 | |||
421 | for (i = 0; tx_ring->desc && (i < tx_ring->count); i++) { | ||
422 | tx_desc = IXGBE_TX_DESC_ADV(tx_ring, i); | ||
423 | tx_buffer_info = &tx_ring->tx_buffer_info[i]; | ||
424 | u0 = (struct my_u0 *)tx_desc; | ||
425 | pr_info("T [0x%03X] %016llX %016llX %016llX" | ||
426 | " %04X %3X %016llX %p", i, | ||
427 | le64_to_cpu(u0->a), | ||
428 | le64_to_cpu(u0->b), | ||
429 | (u64)tx_buffer_info->dma, | ||
430 | tx_buffer_info->length, | ||
431 | tx_buffer_info->next_to_watch, | ||
432 | (u64)tx_buffer_info->time_stamp, | ||
433 | tx_buffer_info->skb); | ||
434 | if (i == tx_ring->next_to_use && | ||
435 | i == tx_ring->next_to_clean) | ||
436 | pr_cont(" NTC/U\n"); | ||
437 | else if (i == tx_ring->next_to_use) | ||
438 | pr_cont(" NTU\n"); | ||
439 | else if (i == tx_ring->next_to_clean) | ||
440 | pr_cont(" NTC\n"); | ||
441 | else | ||
442 | pr_cont("\n"); | ||
443 | |||
444 | if (netif_msg_pktdata(adapter) && | ||
445 | tx_buffer_info->dma != 0) | ||
446 | print_hex_dump(KERN_INFO, "", | ||
447 | DUMP_PREFIX_ADDRESS, 16, 1, | ||
448 | phys_to_virt(tx_buffer_info->dma), | ||
449 | tx_buffer_info->length, true); | ||
450 | } | ||
451 | } | ||
452 | |||
453 | /* Print RX Rings Summary */ | ||
454 | rx_ring_summary: | ||
455 | dev_info(&adapter->pdev->dev, "RX Rings Summary\n"); | ||
456 | pr_info("Queue [NTU] [NTC]\n"); | ||
457 | for (n = 0; n < adapter->num_rx_queues; n++) { | ||
458 | rx_ring = adapter->rx_ring[n]; | ||
459 | pr_info("%5d %5X %5X\n", | ||
460 | n, rx_ring->next_to_use, rx_ring->next_to_clean); | ||
461 | } | ||
462 | |||
463 | /* Print RX Rings */ | ||
464 | if (!netif_msg_rx_status(adapter)) | ||
465 | goto exit; | ||
466 | |||
467 | dev_info(&adapter->pdev->dev, "RX Rings Dump\n"); | ||
468 | |||
469 | /* Advanced Receive Descriptor (Read) Format | ||
470 | * 63 1 0 | ||
471 | * +-----------------------------------------------------+ | ||
472 | * 0 | Packet Buffer Address [63:1] |A0/NSE| | ||
473 | * +----------------------------------------------+------+ | ||
474 | * 8 | Header Buffer Address [63:1] | DD | | ||
475 | * +-----------------------------------------------------+ | ||
476 | * | ||
477 | * | ||
478 | * Advanced Receive Descriptor (Write-Back) Format | ||
479 | * | ||
480 | * 63 48 47 32 31 30 21 20 16 15 4 3 0 | ||
481 | * +------------------------------------------------------+ | ||
482 | * 0 | Packet IP |SPH| HDR_LEN | RSV|Packet| RSS | | ||
483 | * | Checksum Ident | | | | Type | Type | | ||
484 | * +------------------------------------------------------+ | ||
485 | * 8 | VLAN Tag | Length | Extended Error | Extended Status | | ||
486 | * +------------------------------------------------------+ | ||
487 | * 63 48 47 32 31 20 19 0 | ||
488 | */ | ||
489 | for (n = 0; n < adapter->num_rx_queues; n++) { | ||
490 | rx_ring = adapter->rx_ring[n]; | ||
491 | pr_info("------------------------------------\n"); | ||
492 | pr_info("RX QUEUE INDEX = %d\n", rx_ring->queue_index); | ||
493 | pr_info("------------------------------------\n"); | ||
494 | pr_info("R [desc] [ PktBuf A0] " | ||
495 | "[ HeadBuf DD] [bi->dma ] [bi->skb] " | ||
496 | "<-- Adv Rx Read format\n"); | ||
497 | pr_info("RWB[desc] [PcsmIpSHl PtRs] " | ||
498 | "[vl er S cks ln] ---------------- [bi->skb] " | ||
499 | "<-- Adv Rx Write-Back format\n"); | ||
500 | |||
501 | for (i = 0; i < rx_ring->count; i++) { | ||
502 | rx_buffer_info = &rx_ring->rx_buffer_info[i]; | ||
503 | rx_desc = IXGBE_RX_DESC_ADV(rx_ring, i); | ||
504 | u0 = (struct my_u0 *)rx_desc; | ||
505 | staterr = le32_to_cpu(rx_desc->wb.upper.status_error); | ||
506 | if (staterr & IXGBE_RXD_STAT_DD) { | ||
507 | /* Descriptor Done */ | ||
508 | pr_info("RWB[0x%03X] %016llX " | ||
509 | "%016llX ---------------- %p", i, | ||
510 | le64_to_cpu(u0->a), | ||
511 | le64_to_cpu(u0->b), | ||
512 | rx_buffer_info->skb); | ||
513 | } else { | ||
514 | pr_info("R [0x%03X] %016llX " | ||
515 | "%016llX %016llX %p", i, | ||
516 | le64_to_cpu(u0->a), | ||
517 | le64_to_cpu(u0->b), | ||
518 | (u64)rx_buffer_info->dma, | ||
519 | rx_buffer_info->skb); | ||
520 | |||
521 | if (netif_msg_pktdata(adapter)) { | ||
522 | print_hex_dump(KERN_INFO, "", | ||
523 | DUMP_PREFIX_ADDRESS, 16, 1, | ||
524 | phys_to_virt(rx_buffer_info->dma), | ||
525 | rx_ring->rx_buf_len, true); | ||
526 | |||
527 | if (rx_ring->rx_buf_len | ||
528 | < IXGBE_RXBUFFER_2048) | ||
529 | print_hex_dump(KERN_INFO, "", | ||
530 | DUMP_PREFIX_ADDRESS, 16, 1, | ||
531 | phys_to_virt( | ||
532 | rx_buffer_info->page_dma + | ||
533 | rx_buffer_info->page_offset | ||
534 | ), | ||
535 | PAGE_SIZE/2, true); | ||
536 | } | ||
537 | } | ||
538 | |||
539 | if (i == rx_ring->next_to_use) | ||
540 | pr_cont(" NTU\n"); | ||
541 | else if (i == rx_ring->next_to_clean) | ||
542 | pr_cont(" NTC\n"); | ||
543 | else | ||
544 | pr_cont("\n"); | ||
545 | |||
546 | } | ||
547 | } | ||
548 | |||
549 | exit: | ||
550 | return; | ||
551 | } | ||
552 | |||
553 | static void ixgbe_release_hw_control(struct ixgbe_adapter *adapter) | ||
554 | { | ||
555 | u32 ctrl_ext; | ||
556 | |||
557 | /* Let firmware take over control of h/w */ | ||
558 | ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT); | ||
559 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT, | ||
560 | ctrl_ext & ~IXGBE_CTRL_EXT_DRV_LOAD); | ||
561 | } | ||
562 | |||
563 | static void ixgbe_get_hw_control(struct ixgbe_adapter *adapter) | ||
564 | { | ||
565 | u32 ctrl_ext; | ||
566 | |||
567 | /* Let firmware know the driver has taken over */ | ||
568 | ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT); | ||
569 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT, | ||
570 | ctrl_ext | IXGBE_CTRL_EXT_DRV_LOAD); | ||
571 | } | ||
572 | |||
573 | /* | ||
574 | * ixgbe_set_ivar - set the IVAR registers, mapping interrupt causes to vectors | ||
575 | * @adapter: pointer to adapter struct | ||
576 | * @direction: 0 for Rx, 1 for Tx, -1 for other causes | ||
577 | * @queue: queue to map the corresponding interrupt to | ||
578 | * @msix_vector: the vector to map to the corresponding queue | ||
579 | * | ||
580 | */ | ||
581 | static void ixgbe_set_ivar(struct ixgbe_adapter *adapter, s8 direction, | ||
582 | u8 queue, u8 msix_vector) | ||
583 | { | ||
584 | u32 ivar, index; | ||
585 | struct ixgbe_hw *hw = &adapter->hw; | ||
586 | switch (hw->mac.type) { | ||
587 | case ixgbe_mac_82598EB: | ||
588 | msix_vector |= IXGBE_IVAR_ALLOC_VAL; | ||
589 | if (direction == -1) | ||
590 | direction = 0; | ||
591 | index = (((direction * 64) + queue) >> 2) & 0x1F; | ||
592 | ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(index)); | ||
593 | ivar &= ~(0xFF << (8 * (queue & 0x3))); | ||
594 | ivar |= (msix_vector << (8 * (queue & 0x3))); | ||
595 | IXGBE_WRITE_REG(hw, IXGBE_IVAR(index), ivar); | ||
596 | break; | ||
597 | case ixgbe_mac_82599EB: | ||
598 | case ixgbe_mac_X540: | ||
599 | if (direction == -1) { | ||
600 | /* other causes */ | ||
601 | msix_vector |= IXGBE_IVAR_ALLOC_VAL; | ||
602 | index = ((queue & 1) * 8); | ||
603 | ivar = IXGBE_READ_REG(&adapter->hw, IXGBE_IVAR_MISC); | ||
604 | ivar &= ~(0xFF << index); | ||
605 | ivar |= (msix_vector << index); | ||
606 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_IVAR_MISC, ivar); | ||
607 | break; | ||
608 | } else { | ||
609 | /* tx or rx causes */ | ||
610 | msix_vector |= IXGBE_IVAR_ALLOC_VAL; | ||
611 | index = ((16 * (queue & 1)) + (8 * direction)); | ||
612 | ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(queue >> 1)); | ||
613 | ivar &= ~(0xFF << index); | ||
614 | ivar |= (msix_vector << index); | ||
615 | IXGBE_WRITE_REG(hw, IXGBE_IVAR(queue >> 1), ivar); | ||
616 | break; | ||
617 | } | ||
618 | default: | ||
619 | break; | ||
620 | } | ||
621 | } | ||
622 | |||
623 | static inline void ixgbe_irq_rearm_queues(struct ixgbe_adapter *adapter, | ||
624 | u64 qmask) | ||
625 | { | ||
626 | u32 mask; | ||
627 | |||
628 | switch (adapter->hw.mac.type) { | ||
629 | case ixgbe_mac_82598EB: | ||
630 | mask = (IXGBE_EIMS_RTX_QUEUE & qmask); | ||
631 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS, mask); | ||
632 | break; | ||
633 | case ixgbe_mac_82599EB: | ||
634 | case ixgbe_mac_X540: | ||
635 | mask = (qmask & 0xFFFFFFFF); | ||
636 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(0), mask); | ||
637 | mask = (qmask >> 32); | ||
638 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(1), mask); | ||
639 | break; | ||
640 | default: | ||
641 | break; | ||
642 | } | ||
643 | } | ||
644 | |||
645 | void ixgbe_unmap_and_free_tx_resource(struct ixgbe_ring *tx_ring, | ||
646 | struct ixgbe_tx_buffer *tx_buffer_info) | ||
647 | { | ||
648 | if (tx_buffer_info->dma) { | ||
649 | if (tx_buffer_info->mapped_as_page) | ||
650 | dma_unmap_page(tx_ring->dev, | ||
651 | tx_buffer_info->dma, | ||
652 | tx_buffer_info->length, | ||
653 | DMA_TO_DEVICE); | ||
654 | else | ||
655 | dma_unmap_single(tx_ring->dev, | ||
656 | tx_buffer_info->dma, | ||
657 | tx_buffer_info->length, | ||
658 | DMA_TO_DEVICE); | ||
659 | tx_buffer_info->dma = 0; | ||
660 | } | ||
661 | if (tx_buffer_info->skb) { | ||
662 | dev_kfree_skb_any(tx_buffer_info->skb); | ||
663 | tx_buffer_info->skb = NULL; | ||
664 | } | ||
665 | tx_buffer_info->time_stamp = 0; | ||
666 | /* tx_buffer_info must be completely set up in the transmit path */ | ||
667 | } | ||
668 | |||
669 | static void ixgbe_update_xoff_received(struct ixgbe_adapter *adapter) | ||
670 | { | ||
671 | struct ixgbe_hw *hw = &adapter->hw; | ||
672 | struct ixgbe_hw_stats *hwstats = &adapter->stats; | ||
673 | u32 data = 0; | ||
674 | u32 xoff[8] = {0}; | ||
675 | int i; | ||
676 | |||
677 | if ((hw->fc.current_mode == ixgbe_fc_full) || | ||
678 | (hw->fc.current_mode == ixgbe_fc_rx_pause)) { | ||
679 | switch (hw->mac.type) { | ||
680 | case ixgbe_mac_82598EB: | ||
681 | data = IXGBE_READ_REG(hw, IXGBE_LXOFFRXC); | ||
682 | break; | ||
683 | default: | ||
684 | data = IXGBE_READ_REG(hw, IXGBE_LXOFFRXCNT); | ||
685 | } | ||
686 | hwstats->lxoffrxc += data; | ||
687 | |||
688 | /* refill credits (no tx hang) if we received xoff */ | ||
689 | if (!data) | ||
690 | return; | ||
691 | |||
692 | for (i = 0; i < adapter->num_tx_queues; i++) | ||
693 | clear_bit(__IXGBE_HANG_CHECK_ARMED, | ||
694 | &adapter->tx_ring[i]->state); | ||
695 | return; | ||
696 | } else if (!(adapter->dcb_cfg.pfc_mode_enable)) | ||
697 | return; | ||
698 | |||
699 | /* update stats for each tc, only valid with PFC enabled */ | ||
700 | for (i = 0; i < MAX_TX_PACKET_BUFFERS; i++) { | ||
701 | switch (hw->mac.type) { | ||
702 | case ixgbe_mac_82598EB: | ||
703 | xoff[i] = IXGBE_READ_REG(hw, IXGBE_PXOFFRXC(i)); | ||
704 | break; | ||
705 | default: | ||
706 | xoff[i] = IXGBE_READ_REG(hw, IXGBE_PXOFFRXCNT(i)); | ||
707 | } | ||
708 | hwstats->pxoffrxc[i] += xoff[i]; | ||
709 | } | ||
710 | |||
711 | /* disarm tx queues that have received xoff frames */ | ||
712 | for (i = 0; i < adapter->num_tx_queues; i++) { | ||
713 | struct ixgbe_ring *tx_ring = adapter->tx_ring[i]; | ||
714 | u8 tc = tx_ring->dcb_tc; | ||
715 | |||
716 | if (xoff[tc]) | ||
717 | clear_bit(__IXGBE_HANG_CHECK_ARMED, &tx_ring->state); | ||
718 | } | ||
719 | } | ||
720 | |||
721 | static u64 ixgbe_get_tx_completed(struct ixgbe_ring *ring) | ||
722 | { | ||
723 | return ring->tx_stats.completed; | ||
724 | } | ||
725 | |||
726 | static u64 ixgbe_get_tx_pending(struct ixgbe_ring *ring) | ||
727 | { | ||
728 | struct ixgbe_adapter *adapter = netdev_priv(ring->netdev); | ||
729 | struct ixgbe_hw *hw = &adapter->hw; | ||
730 | |||
731 | u32 head = IXGBE_READ_REG(hw, IXGBE_TDH(ring->reg_idx)); | ||
732 | u32 tail = IXGBE_READ_REG(hw, IXGBE_TDT(ring->reg_idx)); | ||
733 | |||
734 | if (head != tail) | ||
735 | return (head < tail) ? | ||
736 | tail - head : (tail + ring->count - head); | ||
737 | |||
738 | return 0; | ||
739 | } | ||
740 | |||
741 | static inline bool ixgbe_check_tx_hang(struct ixgbe_ring *tx_ring) | ||
742 | { | ||
743 | u32 tx_done = ixgbe_get_tx_completed(tx_ring); | ||
744 | u32 tx_done_old = tx_ring->tx_stats.tx_done_old; | ||
745 | u32 tx_pending = ixgbe_get_tx_pending(tx_ring); | ||
746 | bool ret = false; | ||
747 | |||
748 | clear_check_for_tx_hang(tx_ring); | ||
749 | |||
750 | /* | ||
751 | * Check for a hung queue, but be thorough. This verifies | ||
752 | * that a transmit has been completed since the previous | ||
753 | * check AND there is at least one packet pending. The | ||
754 | * ARMED bit is set to indicate a potential hang. The | ||
755 | * bit is cleared if a pause frame is received to remove | ||
756 | * false hang detection due to PFC or 802.3x frames. By | ||
757 | * requiring this to fail twice we avoid races with | ||
758 | * pfc clearing the ARMED bit and conditions where we | ||
759 | * run the check_tx_hang logic with a transmit completion | ||
760 | * pending but without time to complete it yet. | ||
761 | */ | ||
762 | if ((tx_done_old == tx_done) && tx_pending) { | ||
763 | /* make sure it is true for two checks in a row */ | ||
764 | ret = test_and_set_bit(__IXGBE_HANG_CHECK_ARMED, | ||
765 | &tx_ring->state); | ||
766 | } else { | ||
767 | /* update completed stats and continue */ | ||
768 | tx_ring->tx_stats.tx_done_old = tx_done; | ||
769 | /* reset the countdown */ | ||
770 | clear_bit(__IXGBE_HANG_CHECK_ARMED, &tx_ring->state); | ||
771 | } | ||
772 | |||
773 | return ret; | ||
774 | } | ||
775 | |||
776 | /** | ||
777 | * ixgbe_tx_timeout_reset - initiate reset due to Tx timeout | ||
778 | * @adapter: driver private struct | ||
779 | **/ | ||
780 | static void ixgbe_tx_timeout_reset(struct ixgbe_adapter *adapter) | ||
781 | { | ||
782 | |||
783 | /* Do the reset outside of interrupt context */ | ||
784 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) { | ||
785 | adapter->flags2 |= IXGBE_FLAG2_RESET_REQUESTED; | ||
786 | ixgbe_service_event_schedule(adapter); | ||
787 | } | ||
788 | } | ||
789 | |||
790 | /** | ||
791 | * ixgbe_clean_tx_irq - Reclaim resources after transmit completes | ||
792 | * @q_vector: structure containing interrupt and ring information | ||
793 | * @tx_ring: tx ring to clean | ||
794 | **/ | ||
795 | static bool ixgbe_clean_tx_irq(struct ixgbe_q_vector *q_vector, | ||
796 | struct ixgbe_ring *tx_ring) | ||
797 | { | ||
798 | struct ixgbe_adapter *adapter = q_vector->adapter; | ||
799 | union ixgbe_adv_tx_desc *tx_desc, *eop_desc; | ||
800 | struct ixgbe_tx_buffer *tx_buffer_info; | ||
801 | unsigned int total_bytes = 0, total_packets = 0; | ||
802 | u16 i, eop, count = 0; | ||
803 | |||
804 | i = tx_ring->next_to_clean; | ||
805 | eop = tx_ring->tx_buffer_info[i].next_to_watch; | ||
806 | eop_desc = IXGBE_TX_DESC_ADV(tx_ring, eop); | ||
807 | |||
808 | while ((eop_desc->wb.status & cpu_to_le32(IXGBE_TXD_STAT_DD)) && | ||
809 | (count < q_vector->tx.work_limit)) { | ||
810 | bool cleaned = false; | ||
811 | rmb(); /* read buffer_info after eop_desc */ | ||
812 | for ( ; !cleaned; count++) { | ||
813 | tx_desc = IXGBE_TX_DESC_ADV(tx_ring, i); | ||
814 | tx_buffer_info = &tx_ring->tx_buffer_info[i]; | ||
815 | |||
816 | tx_desc->wb.status = 0; | ||
817 | cleaned = (i == eop); | ||
818 | |||
819 | i++; | ||
820 | if (i == tx_ring->count) | ||
821 | i = 0; | ||
822 | |||
823 | if (cleaned && tx_buffer_info->skb) { | ||
824 | total_bytes += tx_buffer_info->bytecount; | ||
825 | total_packets += tx_buffer_info->gso_segs; | ||
826 | } | ||
827 | |||
828 | ixgbe_unmap_and_free_tx_resource(tx_ring, | ||
829 | tx_buffer_info); | ||
830 | } | ||
831 | |||
832 | tx_ring->tx_stats.completed++; | ||
833 | eop = tx_ring->tx_buffer_info[i].next_to_watch; | ||
834 | eop_desc = IXGBE_TX_DESC_ADV(tx_ring, eop); | ||
835 | } | ||
836 | |||
837 | tx_ring->next_to_clean = i; | ||
838 | tx_ring->stats.bytes += total_bytes; | ||
839 | tx_ring->stats.packets += total_packets; | ||
840 | u64_stats_update_begin(&tx_ring->syncp); | ||
841 | q_vector->tx.total_bytes += total_bytes; | ||
842 | q_vector->tx.total_packets += total_packets; | ||
843 | u64_stats_update_end(&tx_ring->syncp); | ||
844 | |||
845 | if (check_for_tx_hang(tx_ring) && ixgbe_check_tx_hang(tx_ring)) { | ||
846 | /* schedule immediate reset if we believe we hung */ | ||
847 | struct ixgbe_hw *hw = &adapter->hw; | ||
848 | tx_desc = IXGBE_TX_DESC_ADV(tx_ring, eop); | ||
849 | e_err(drv, "Detected Tx Unit Hang\n" | ||
850 | " Tx Queue <%d>\n" | ||
851 | " TDH, TDT <%x>, <%x>\n" | ||
852 | " next_to_use <%x>\n" | ||
853 | " next_to_clean <%x>\n" | ||
854 | "tx_buffer_info[next_to_clean]\n" | ||
855 | " time_stamp <%lx>\n" | ||
856 | " jiffies <%lx>\n", | ||
857 | tx_ring->queue_index, | ||
858 | IXGBE_READ_REG(hw, IXGBE_TDH(tx_ring->reg_idx)), | ||
859 | IXGBE_READ_REG(hw, IXGBE_TDT(tx_ring->reg_idx)), | ||
860 | tx_ring->next_to_use, eop, | ||
861 | tx_ring->tx_buffer_info[eop].time_stamp, jiffies); | ||
862 | |||
863 | netif_stop_subqueue(tx_ring->netdev, tx_ring->queue_index); | ||
864 | |||
865 | e_info(probe, | ||
866 | "tx hang %d detected on queue %d, resetting adapter\n", | ||
867 | adapter->tx_timeout_count + 1, tx_ring->queue_index); | ||
868 | |||
869 | /* schedule immediate reset if we believe we hung */ | ||
870 | ixgbe_tx_timeout_reset(adapter); | ||
871 | |||
872 | /* the adapter is about to reset, no point in enabling stuff */ | ||
873 | return true; | ||
874 | } | ||
875 | |||
876 | #define TX_WAKE_THRESHOLD (DESC_NEEDED * 2) | ||
877 | if (unlikely(count && netif_carrier_ok(tx_ring->netdev) && | ||
878 | (ixgbe_desc_unused(tx_ring) >= TX_WAKE_THRESHOLD))) { | ||
879 | /* Make sure that anybody stopping the queue after this | ||
880 | * sees the new next_to_clean. | ||
881 | */ | ||
882 | smp_mb(); | ||
883 | if (__netif_subqueue_stopped(tx_ring->netdev, tx_ring->queue_index) && | ||
884 | !test_bit(__IXGBE_DOWN, &adapter->state)) { | ||
885 | netif_wake_subqueue(tx_ring->netdev, tx_ring->queue_index); | ||
886 | ++tx_ring->tx_stats.restart_queue; | ||
887 | } | ||
888 | } | ||
889 | |||
890 | return count < q_vector->tx.work_limit; | ||
891 | } | ||
892 | |||
893 | #ifdef CONFIG_IXGBE_DCA | ||
894 | static void ixgbe_update_rx_dca(struct ixgbe_adapter *adapter, | ||
895 | struct ixgbe_ring *rx_ring, | ||
896 | int cpu) | ||
897 | { | ||
898 | struct ixgbe_hw *hw = &adapter->hw; | ||
899 | u32 rxctrl; | ||
900 | u8 reg_idx = rx_ring->reg_idx; | ||
901 | |||
902 | rxctrl = IXGBE_READ_REG(hw, IXGBE_DCA_RXCTRL(reg_idx)); | ||
903 | switch (hw->mac.type) { | ||
904 | case ixgbe_mac_82598EB: | ||
905 | rxctrl &= ~IXGBE_DCA_RXCTRL_CPUID_MASK; | ||
906 | rxctrl |= dca3_get_tag(&adapter->pdev->dev, cpu); | ||
907 | break; | ||
908 | case ixgbe_mac_82599EB: | ||
909 | case ixgbe_mac_X540: | ||
910 | rxctrl &= ~IXGBE_DCA_RXCTRL_CPUID_MASK_82599; | ||
911 | rxctrl |= (dca3_get_tag(&adapter->pdev->dev, cpu) << | ||
912 | IXGBE_DCA_RXCTRL_CPUID_SHIFT_82599); | ||
913 | break; | ||
914 | default: | ||
915 | break; | ||
916 | } | ||
917 | rxctrl |= IXGBE_DCA_RXCTRL_DESC_DCA_EN; | ||
918 | rxctrl |= IXGBE_DCA_RXCTRL_HEAD_DCA_EN; | ||
919 | rxctrl &= ~(IXGBE_DCA_RXCTRL_DESC_RRO_EN); | ||
920 | IXGBE_WRITE_REG(hw, IXGBE_DCA_RXCTRL(reg_idx), rxctrl); | ||
921 | } | ||
922 | |||
923 | static void ixgbe_update_tx_dca(struct ixgbe_adapter *adapter, | ||
924 | struct ixgbe_ring *tx_ring, | ||
925 | int cpu) | ||
926 | { | ||
927 | struct ixgbe_hw *hw = &adapter->hw; | ||
928 | u32 txctrl; | ||
929 | u8 reg_idx = tx_ring->reg_idx; | ||
930 | |||
931 | switch (hw->mac.type) { | ||
932 | case ixgbe_mac_82598EB: | ||
933 | txctrl = IXGBE_READ_REG(hw, IXGBE_DCA_TXCTRL(reg_idx)); | ||
934 | txctrl &= ~IXGBE_DCA_TXCTRL_CPUID_MASK; | ||
935 | txctrl |= dca3_get_tag(&adapter->pdev->dev, cpu); | ||
936 | txctrl |= IXGBE_DCA_TXCTRL_DESC_DCA_EN; | ||
937 | IXGBE_WRITE_REG(hw, IXGBE_DCA_TXCTRL(reg_idx), txctrl); | ||
938 | break; | ||
939 | case ixgbe_mac_82599EB: | ||
940 | case ixgbe_mac_X540: | ||
941 | txctrl = IXGBE_READ_REG(hw, IXGBE_DCA_TXCTRL_82599(reg_idx)); | ||
942 | txctrl &= ~IXGBE_DCA_TXCTRL_CPUID_MASK_82599; | ||
943 | txctrl |= (dca3_get_tag(&adapter->pdev->dev, cpu) << | ||
944 | IXGBE_DCA_TXCTRL_CPUID_SHIFT_82599); | ||
945 | txctrl |= IXGBE_DCA_TXCTRL_DESC_DCA_EN; | ||
946 | IXGBE_WRITE_REG(hw, IXGBE_DCA_TXCTRL_82599(reg_idx), txctrl); | ||
947 | break; | ||
948 | default: | ||
949 | break; | ||
950 | } | ||
951 | } | ||
952 | |||
953 | static void ixgbe_update_dca(struct ixgbe_q_vector *q_vector) | ||
954 | { | ||
955 | struct ixgbe_adapter *adapter = q_vector->adapter; | ||
956 | int cpu = get_cpu(); | ||
957 | long r_idx; | ||
958 | int i; | ||
959 | |||
960 | if (q_vector->cpu == cpu) | ||
961 | goto out_no_update; | ||
962 | |||
963 | r_idx = find_first_bit(q_vector->tx.idx, adapter->num_tx_queues); | ||
964 | for (i = 0; i < q_vector->tx.count; i++) { | ||
965 | ixgbe_update_tx_dca(adapter, adapter->tx_ring[r_idx], cpu); | ||
966 | r_idx = find_next_bit(q_vector->tx.idx, adapter->num_tx_queues, | ||
967 | r_idx + 1); | ||
968 | } | ||
969 | |||
970 | r_idx = find_first_bit(q_vector->rx.idx, adapter->num_rx_queues); | ||
971 | for (i = 0; i < q_vector->rx.count; i++) { | ||
972 | ixgbe_update_rx_dca(adapter, adapter->rx_ring[r_idx], cpu); | ||
973 | r_idx = find_next_bit(q_vector->rx.idx, adapter->num_rx_queues, | ||
974 | r_idx + 1); | ||
975 | } | ||
976 | |||
977 | q_vector->cpu = cpu; | ||
978 | out_no_update: | ||
979 | put_cpu(); | ||
980 | } | ||
981 | |||
982 | static void ixgbe_setup_dca(struct ixgbe_adapter *adapter) | ||
983 | { | ||
984 | int num_q_vectors; | ||
985 | int i; | ||
986 | |||
987 | if (!(adapter->flags & IXGBE_FLAG_DCA_ENABLED)) | ||
988 | return; | ||
989 | |||
990 | /* always use CB2 mode, difference is masked in the CB driver */ | ||
991 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 2); | ||
992 | |||
993 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) | ||
994 | num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; | ||
995 | else | ||
996 | num_q_vectors = 1; | ||
997 | |||
998 | for (i = 0; i < num_q_vectors; i++) { | ||
999 | adapter->q_vector[i]->cpu = -1; | ||
1000 | ixgbe_update_dca(adapter->q_vector[i]); | ||
1001 | } | ||
1002 | } | ||
1003 | |||
1004 | static int __ixgbe_notify_dca(struct device *dev, void *data) | ||
1005 | { | ||
1006 | struct ixgbe_adapter *adapter = dev_get_drvdata(dev); | ||
1007 | unsigned long event = *(unsigned long *)data; | ||
1008 | |||
1009 | if (!(adapter->flags & IXGBE_FLAG_DCA_CAPABLE)) | ||
1010 | return 0; | ||
1011 | |||
1012 | switch (event) { | ||
1013 | case DCA_PROVIDER_ADD: | ||
1014 | /* if we're already enabled, don't do it again */ | ||
1015 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) | ||
1016 | break; | ||
1017 | if (dca_add_requester(dev) == 0) { | ||
1018 | adapter->flags |= IXGBE_FLAG_DCA_ENABLED; | ||
1019 | ixgbe_setup_dca(adapter); | ||
1020 | break; | ||
1021 | } | ||
1022 | /* Fall Through since DCA is disabled. */ | ||
1023 | case DCA_PROVIDER_REMOVE: | ||
1024 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) { | ||
1025 | dca_remove_requester(dev); | ||
1026 | adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED; | ||
1027 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1); | ||
1028 | } | ||
1029 | break; | ||
1030 | } | ||
1031 | |||
1032 | return 0; | ||
1033 | } | ||
1034 | #endif /* CONFIG_IXGBE_DCA */ | ||
1035 | |||
1036 | static inline void ixgbe_rx_hash(union ixgbe_adv_rx_desc *rx_desc, | ||
1037 | struct sk_buff *skb) | ||
1038 | { | ||
1039 | skb->rxhash = le32_to_cpu(rx_desc->wb.lower.hi_dword.rss); | ||
1040 | } | ||
1041 | |||
1042 | /** | ||
1043 | * ixgbe_rx_is_fcoe - check the rx desc for incoming pkt type | ||
1044 | * @adapter: address of board private structure | ||
1045 | * @rx_desc: advanced rx descriptor | ||
1046 | * | ||
1047 | * Returns : true if it is FCoE pkt | ||
1048 | */ | ||
1049 | static inline bool ixgbe_rx_is_fcoe(struct ixgbe_adapter *adapter, | ||
1050 | union ixgbe_adv_rx_desc *rx_desc) | ||
1051 | { | ||
1052 | __le16 pkt_info = rx_desc->wb.lower.lo_dword.hs_rss.pkt_info; | ||
1053 | |||
1054 | return (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) && | ||
1055 | ((pkt_info & cpu_to_le16(IXGBE_RXDADV_PKTTYPE_ETQF_MASK)) == | ||
1056 | (cpu_to_le16(IXGBE_ETQF_FILTER_FCOE << | ||
1057 | IXGBE_RXDADV_PKTTYPE_ETQF_SHIFT))); | ||
1058 | } | ||
1059 | |||
1060 | /** | ||
1061 | * ixgbe_receive_skb - Send a completed packet up the stack | ||
1062 | * @adapter: board private structure | ||
1063 | * @skb: packet to send up | ||
1064 | * @status: hardware indication of status of receive | ||
1065 | * @rx_ring: rx descriptor ring (for a specific queue) to setup | ||
1066 | * @rx_desc: rx descriptor | ||
1067 | **/ | ||
1068 | static void ixgbe_receive_skb(struct ixgbe_q_vector *q_vector, | ||
1069 | struct sk_buff *skb, u8 status, | ||
1070 | struct ixgbe_ring *ring, | ||
1071 | union ixgbe_adv_rx_desc *rx_desc) | ||
1072 | { | ||
1073 | struct ixgbe_adapter *adapter = q_vector->adapter; | ||
1074 | struct napi_struct *napi = &q_vector->napi; | ||
1075 | bool is_vlan = (status & IXGBE_RXD_STAT_VP); | ||
1076 | u16 tag = le16_to_cpu(rx_desc->wb.upper.vlan); | ||
1077 | |||
1078 | if (is_vlan && (tag & VLAN_VID_MASK)) | ||
1079 | __vlan_hwaccel_put_tag(skb, tag); | ||
1080 | |||
1081 | if (!(adapter->flags & IXGBE_FLAG_IN_NETPOLL)) | ||
1082 | napi_gro_receive(napi, skb); | ||
1083 | else | ||
1084 | netif_rx(skb); | ||
1085 | } | ||
1086 | |||
1087 | /** | ||
1088 | * ixgbe_rx_checksum - indicate in skb if hw indicated a good cksum | ||
1089 | * @adapter: address of board private structure | ||
1090 | * @status_err: hardware indication of status of receive | ||
1091 | * @skb: skb currently being received and modified | ||
1092 | * @status_err: status error value of last descriptor in packet | ||
1093 | **/ | ||
1094 | static inline void ixgbe_rx_checksum(struct ixgbe_adapter *adapter, | ||
1095 | union ixgbe_adv_rx_desc *rx_desc, | ||
1096 | struct sk_buff *skb, | ||
1097 | u32 status_err) | ||
1098 | { | ||
1099 | skb->ip_summed = CHECKSUM_NONE; | ||
1100 | |||
1101 | /* Rx csum disabled */ | ||
1102 | if (!(adapter->flags & IXGBE_FLAG_RX_CSUM_ENABLED)) | ||
1103 | return; | ||
1104 | |||
1105 | /* if IP and error */ | ||
1106 | if ((status_err & IXGBE_RXD_STAT_IPCS) && | ||
1107 | (status_err & IXGBE_RXDADV_ERR_IPE)) { | ||
1108 | adapter->hw_csum_rx_error++; | ||
1109 | return; | ||
1110 | } | ||
1111 | |||
1112 | if (!(status_err & IXGBE_RXD_STAT_L4CS)) | ||
1113 | return; | ||
1114 | |||
1115 | if (status_err & IXGBE_RXDADV_ERR_TCPE) { | ||
1116 | u16 pkt_info = rx_desc->wb.lower.lo_dword.hs_rss.pkt_info; | ||
1117 | |||
1118 | /* | ||
1119 | * 82599 errata, UDP frames with a 0 checksum can be marked as | ||
1120 | * checksum errors. | ||
1121 | */ | ||
1122 | if ((pkt_info & IXGBE_RXDADV_PKTTYPE_UDP) && | ||
1123 | (adapter->hw.mac.type == ixgbe_mac_82599EB)) | ||
1124 | return; | ||
1125 | |||
1126 | adapter->hw_csum_rx_error++; | ||
1127 | return; | ||
1128 | } | ||
1129 | |||
1130 | /* It must be a TCP or UDP packet with a valid checksum */ | ||
1131 | skb->ip_summed = CHECKSUM_UNNECESSARY; | ||
1132 | } | ||
1133 | |||
1134 | static inline void ixgbe_release_rx_desc(struct ixgbe_ring *rx_ring, u32 val) | ||
1135 | { | ||
1136 | /* | ||
1137 | * Force memory writes to complete before letting h/w | ||
1138 | * know there are new descriptors to fetch. (Only | ||
1139 | * applicable for weak-ordered memory model archs, | ||
1140 | * such as IA-64). | ||
1141 | */ | ||
1142 | wmb(); | ||
1143 | writel(val, rx_ring->tail); | ||
1144 | } | ||
1145 | |||
1146 | /** | ||
1147 | * ixgbe_alloc_rx_buffers - Replace used receive buffers; packet split | ||
1148 | * @rx_ring: ring to place buffers on | ||
1149 | * @cleaned_count: number of buffers to replace | ||
1150 | **/ | ||
1151 | void ixgbe_alloc_rx_buffers(struct ixgbe_ring *rx_ring, u16 cleaned_count) | ||
1152 | { | ||
1153 | union ixgbe_adv_rx_desc *rx_desc; | ||
1154 | struct ixgbe_rx_buffer *bi; | ||
1155 | struct sk_buff *skb; | ||
1156 | u16 i = rx_ring->next_to_use; | ||
1157 | |||
1158 | /* do nothing if no valid netdev defined */ | ||
1159 | if (!rx_ring->netdev) | ||
1160 | return; | ||
1161 | |||
1162 | while (cleaned_count--) { | ||
1163 | rx_desc = IXGBE_RX_DESC_ADV(rx_ring, i); | ||
1164 | bi = &rx_ring->rx_buffer_info[i]; | ||
1165 | skb = bi->skb; | ||
1166 | |||
1167 | if (!skb) { | ||
1168 | skb = netdev_alloc_skb_ip_align(rx_ring->netdev, | ||
1169 | rx_ring->rx_buf_len); | ||
1170 | if (!skb) { | ||
1171 | rx_ring->rx_stats.alloc_rx_buff_failed++; | ||
1172 | goto no_buffers; | ||
1173 | } | ||
1174 | /* initialize queue mapping */ | ||
1175 | skb_record_rx_queue(skb, rx_ring->queue_index); | ||
1176 | bi->skb = skb; | ||
1177 | } | ||
1178 | |||
1179 | if (!bi->dma) { | ||
1180 | bi->dma = dma_map_single(rx_ring->dev, | ||
1181 | skb->data, | ||
1182 | rx_ring->rx_buf_len, | ||
1183 | DMA_FROM_DEVICE); | ||
1184 | if (dma_mapping_error(rx_ring->dev, bi->dma)) { | ||
1185 | rx_ring->rx_stats.alloc_rx_buff_failed++; | ||
1186 | bi->dma = 0; | ||
1187 | goto no_buffers; | ||
1188 | } | ||
1189 | } | ||
1190 | |||
1191 | if (ring_is_ps_enabled(rx_ring)) { | ||
1192 | if (!bi->page) { | ||
1193 | bi->page = netdev_alloc_page(rx_ring->netdev); | ||
1194 | if (!bi->page) { | ||
1195 | rx_ring->rx_stats.alloc_rx_page_failed++; | ||
1196 | goto no_buffers; | ||
1197 | } | ||
1198 | } | ||
1199 | |||
1200 | if (!bi->page_dma) { | ||
1201 | /* use a half page if we're re-using */ | ||
1202 | bi->page_offset ^= PAGE_SIZE / 2; | ||
1203 | bi->page_dma = dma_map_page(rx_ring->dev, | ||
1204 | bi->page, | ||
1205 | bi->page_offset, | ||
1206 | PAGE_SIZE / 2, | ||
1207 | DMA_FROM_DEVICE); | ||
1208 | if (dma_mapping_error(rx_ring->dev, | ||
1209 | bi->page_dma)) { | ||
1210 | rx_ring->rx_stats.alloc_rx_page_failed++; | ||
1211 | bi->page_dma = 0; | ||
1212 | goto no_buffers; | ||
1213 | } | ||
1214 | } | ||
1215 | |||
1216 | /* Refresh the desc even if buffer_addrs didn't change | ||
1217 | * because each write-back erases this info. */ | ||
1218 | rx_desc->read.pkt_addr = cpu_to_le64(bi->page_dma); | ||
1219 | rx_desc->read.hdr_addr = cpu_to_le64(bi->dma); | ||
1220 | } else { | ||
1221 | rx_desc->read.pkt_addr = cpu_to_le64(bi->dma); | ||
1222 | rx_desc->read.hdr_addr = 0; | ||
1223 | } | ||
1224 | |||
1225 | i++; | ||
1226 | if (i == rx_ring->count) | ||
1227 | i = 0; | ||
1228 | } | ||
1229 | |||
1230 | no_buffers: | ||
1231 | if (rx_ring->next_to_use != i) { | ||
1232 | rx_ring->next_to_use = i; | ||
1233 | ixgbe_release_rx_desc(rx_ring, i); | ||
1234 | } | ||
1235 | } | ||
1236 | |||
1237 | static inline u16 ixgbe_get_hlen(union ixgbe_adv_rx_desc *rx_desc) | ||
1238 | { | ||
1239 | /* HW will not DMA in data larger than the given buffer, even if it | ||
1240 | * parses the (NFS, of course) header to be larger. In that case, it | ||
1241 | * fills the header buffer and spills the rest into the page. | ||
1242 | */ | ||
1243 | u16 hdr_info = le16_to_cpu(rx_desc->wb.lower.lo_dword.hs_rss.hdr_info); | ||
1244 | u16 hlen = (hdr_info & IXGBE_RXDADV_HDRBUFLEN_MASK) >> | ||
1245 | IXGBE_RXDADV_HDRBUFLEN_SHIFT; | ||
1246 | if (hlen > IXGBE_RX_HDR_SIZE) | ||
1247 | hlen = IXGBE_RX_HDR_SIZE; | ||
1248 | return hlen; | ||
1249 | } | ||
1250 | |||
1251 | /** | ||
1252 | * ixgbe_transform_rsc_queue - change rsc queue into a full packet | ||
1253 | * @skb: pointer to the last skb in the rsc queue | ||
1254 | * | ||
1255 | * This function changes a queue full of hw rsc buffers into a completed | ||
1256 | * packet. It uses the ->prev pointers to find the first packet and then | ||
1257 | * turns it into the frag list owner. | ||
1258 | **/ | ||
1259 | static inline struct sk_buff *ixgbe_transform_rsc_queue(struct sk_buff *skb) | ||
1260 | { | ||
1261 | unsigned int frag_list_size = 0; | ||
1262 | unsigned int skb_cnt = 1; | ||
1263 | |||
1264 | while (skb->prev) { | ||
1265 | struct sk_buff *prev = skb->prev; | ||
1266 | frag_list_size += skb->len; | ||
1267 | skb->prev = NULL; | ||
1268 | skb = prev; | ||
1269 | skb_cnt++; | ||
1270 | } | ||
1271 | |||
1272 | skb_shinfo(skb)->frag_list = skb->next; | ||
1273 | skb->next = NULL; | ||
1274 | skb->len += frag_list_size; | ||
1275 | skb->data_len += frag_list_size; | ||
1276 | skb->truesize += frag_list_size; | ||
1277 | IXGBE_RSC_CB(skb)->skb_cnt = skb_cnt; | ||
1278 | |||
1279 | return skb; | ||
1280 | } | ||
1281 | |||
1282 | static inline bool ixgbe_get_rsc_state(union ixgbe_adv_rx_desc *rx_desc) | ||
1283 | { | ||
1284 | return !!(le32_to_cpu(rx_desc->wb.lower.lo_dword.data) & | ||
1285 | IXGBE_RXDADV_RSCCNT_MASK); | ||
1286 | } | ||
1287 | |||
1288 | static void ixgbe_clean_rx_irq(struct ixgbe_q_vector *q_vector, | ||
1289 | struct ixgbe_ring *rx_ring, | ||
1290 | int *work_done, int work_to_do) | ||
1291 | { | ||
1292 | struct ixgbe_adapter *adapter = q_vector->adapter; | ||
1293 | union ixgbe_adv_rx_desc *rx_desc, *next_rxd; | ||
1294 | struct ixgbe_rx_buffer *rx_buffer_info, *next_buffer; | ||
1295 | struct sk_buff *skb; | ||
1296 | unsigned int total_rx_bytes = 0, total_rx_packets = 0; | ||
1297 | const int current_node = numa_node_id(); | ||
1298 | #ifdef IXGBE_FCOE | ||
1299 | int ddp_bytes = 0; | ||
1300 | #endif /* IXGBE_FCOE */ | ||
1301 | u32 staterr; | ||
1302 | u16 i; | ||
1303 | u16 cleaned_count = 0; | ||
1304 | bool pkt_is_rsc = false; | ||
1305 | |||
1306 | i = rx_ring->next_to_clean; | ||
1307 | rx_desc = IXGBE_RX_DESC_ADV(rx_ring, i); | ||
1308 | staterr = le32_to_cpu(rx_desc->wb.upper.status_error); | ||
1309 | |||
1310 | while (staterr & IXGBE_RXD_STAT_DD) { | ||
1311 | u32 upper_len = 0; | ||
1312 | |||
1313 | rmb(); /* read descriptor and rx_buffer_info after status DD */ | ||
1314 | |||
1315 | rx_buffer_info = &rx_ring->rx_buffer_info[i]; | ||
1316 | |||
1317 | skb = rx_buffer_info->skb; | ||
1318 | rx_buffer_info->skb = NULL; | ||
1319 | prefetch(skb->data); | ||
1320 | |||
1321 | if (ring_is_rsc_enabled(rx_ring)) | ||
1322 | pkt_is_rsc = ixgbe_get_rsc_state(rx_desc); | ||
1323 | |||
1324 | /* linear means we are building an skb from multiple pages */ | ||
1325 | if (!skb_is_nonlinear(skb)) { | ||
1326 | u16 hlen; | ||
1327 | if (pkt_is_rsc && | ||
1328 | !(staterr & IXGBE_RXD_STAT_EOP) && | ||
1329 | !skb->prev) { | ||
1330 | /* | ||
1331 | * When HWRSC is enabled, delay unmapping | ||
1332 | * of the first packet. It carries the | ||
1333 | * header information, HW may still | ||
1334 | * access the header after the writeback. | ||
1335 | * Only unmap it when EOP is reached | ||
1336 | */ | ||
1337 | IXGBE_RSC_CB(skb)->delay_unmap = true; | ||
1338 | IXGBE_RSC_CB(skb)->dma = rx_buffer_info->dma; | ||
1339 | } else { | ||
1340 | dma_unmap_single(rx_ring->dev, | ||
1341 | rx_buffer_info->dma, | ||
1342 | rx_ring->rx_buf_len, | ||
1343 | DMA_FROM_DEVICE); | ||
1344 | } | ||
1345 | rx_buffer_info->dma = 0; | ||
1346 | |||
1347 | if (ring_is_ps_enabled(rx_ring)) { | ||
1348 | hlen = ixgbe_get_hlen(rx_desc); | ||
1349 | upper_len = le16_to_cpu(rx_desc->wb.upper.length); | ||
1350 | } else { | ||
1351 | hlen = le16_to_cpu(rx_desc->wb.upper.length); | ||
1352 | } | ||
1353 | |||
1354 | skb_put(skb, hlen); | ||
1355 | } else { | ||
1356 | /* assume packet split since header is unmapped */ | ||
1357 | upper_len = le16_to_cpu(rx_desc->wb.upper.length); | ||
1358 | } | ||
1359 | |||
1360 | if (upper_len) { | ||
1361 | dma_unmap_page(rx_ring->dev, | ||
1362 | rx_buffer_info->page_dma, | ||
1363 | PAGE_SIZE / 2, | ||
1364 | DMA_FROM_DEVICE); | ||
1365 | rx_buffer_info->page_dma = 0; | ||
1366 | skb_fill_page_desc(skb, skb_shinfo(skb)->nr_frags, | ||
1367 | rx_buffer_info->page, | ||
1368 | rx_buffer_info->page_offset, | ||
1369 | upper_len); | ||
1370 | |||
1371 | if ((page_count(rx_buffer_info->page) == 1) && | ||
1372 | (page_to_nid(rx_buffer_info->page) == current_node)) | ||
1373 | get_page(rx_buffer_info->page); | ||
1374 | else | ||
1375 | rx_buffer_info->page = NULL; | ||
1376 | |||
1377 | skb->len += upper_len; | ||
1378 | skb->data_len += upper_len; | ||
1379 | skb->truesize += upper_len; | ||
1380 | } | ||
1381 | |||
1382 | i++; | ||
1383 | if (i == rx_ring->count) | ||
1384 | i = 0; | ||
1385 | |||
1386 | next_rxd = IXGBE_RX_DESC_ADV(rx_ring, i); | ||
1387 | prefetch(next_rxd); | ||
1388 | cleaned_count++; | ||
1389 | |||
1390 | if (pkt_is_rsc) { | ||
1391 | u32 nextp = (staterr & IXGBE_RXDADV_NEXTP_MASK) >> | ||
1392 | IXGBE_RXDADV_NEXTP_SHIFT; | ||
1393 | next_buffer = &rx_ring->rx_buffer_info[nextp]; | ||
1394 | } else { | ||
1395 | next_buffer = &rx_ring->rx_buffer_info[i]; | ||
1396 | } | ||
1397 | |||
1398 | if (!(staterr & IXGBE_RXD_STAT_EOP)) { | ||
1399 | if (ring_is_ps_enabled(rx_ring)) { | ||
1400 | rx_buffer_info->skb = next_buffer->skb; | ||
1401 | rx_buffer_info->dma = next_buffer->dma; | ||
1402 | next_buffer->skb = skb; | ||
1403 | next_buffer->dma = 0; | ||
1404 | } else { | ||
1405 | skb->next = next_buffer->skb; | ||
1406 | skb->next->prev = skb; | ||
1407 | } | ||
1408 | rx_ring->rx_stats.non_eop_descs++; | ||
1409 | goto next_desc; | ||
1410 | } | ||
1411 | |||
1412 | if (skb->prev) { | ||
1413 | skb = ixgbe_transform_rsc_queue(skb); | ||
1414 | /* if we got here without RSC the packet is invalid */ | ||
1415 | if (!pkt_is_rsc) { | ||
1416 | __pskb_trim(skb, 0); | ||
1417 | rx_buffer_info->skb = skb; | ||
1418 | goto next_desc; | ||
1419 | } | ||
1420 | } | ||
1421 | |||
1422 | if (ring_is_rsc_enabled(rx_ring)) { | ||
1423 | if (IXGBE_RSC_CB(skb)->delay_unmap) { | ||
1424 | dma_unmap_single(rx_ring->dev, | ||
1425 | IXGBE_RSC_CB(skb)->dma, | ||
1426 | rx_ring->rx_buf_len, | ||
1427 | DMA_FROM_DEVICE); | ||
1428 | IXGBE_RSC_CB(skb)->dma = 0; | ||
1429 | IXGBE_RSC_CB(skb)->delay_unmap = false; | ||
1430 | } | ||
1431 | } | ||
1432 | if (pkt_is_rsc) { | ||
1433 | if (ring_is_ps_enabled(rx_ring)) | ||
1434 | rx_ring->rx_stats.rsc_count += | ||
1435 | skb_shinfo(skb)->nr_frags; | ||
1436 | else | ||
1437 | rx_ring->rx_stats.rsc_count += | ||
1438 | IXGBE_RSC_CB(skb)->skb_cnt; | ||
1439 | rx_ring->rx_stats.rsc_flush++; | ||
1440 | } | ||
1441 | |||
1442 | /* ERR_MASK will only have valid bits if EOP set */ | ||
1443 | if (unlikely(staterr & IXGBE_RXDADV_ERR_FRAME_ERR_MASK)) { | ||
1444 | dev_kfree_skb_any(skb); | ||
1445 | goto next_desc; | ||
1446 | } | ||
1447 | |||
1448 | ixgbe_rx_checksum(adapter, rx_desc, skb, staterr); | ||
1449 | if (adapter->netdev->features & NETIF_F_RXHASH) | ||
1450 | ixgbe_rx_hash(rx_desc, skb); | ||
1451 | |||
1452 | /* probably a little skewed due to removing CRC */ | ||
1453 | total_rx_bytes += skb->len; | ||
1454 | total_rx_packets++; | ||
1455 | |||
1456 | skb->protocol = eth_type_trans(skb, rx_ring->netdev); | ||
1457 | #ifdef IXGBE_FCOE | ||
1458 | /* if ddp, not passing to ULD unless for FCP_RSP or error */ | ||
1459 | if (ixgbe_rx_is_fcoe(adapter, rx_desc)) { | ||
1460 | ddp_bytes = ixgbe_fcoe_ddp(adapter, rx_desc, skb, | ||
1461 | staterr); | ||
1462 | if (!ddp_bytes) { | ||
1463 | dev_kfree_skb_any(skb); | ||
1464 | goto next_desc; | ||
1465 | } | ||
1466 | } | ||
1467 | #endif /* IXGBE_FCOE */ | ||
1468 | ixgbe_receive_skb(q_vector, skb, staterr, rx_ring, rx_desc); | ||
1469 | |||
1470 | next_desc: | ||
1471 | rx_desc->wb.upper.status_error = 0; | ||
1472 | |||
1473 | (*work_done)++; | ||
1474 | if (*work_done >= work_to_do) | ||
1475 | break; | ||
1476 | |||
1477 | /* return some buffers to hardware, one at a time is too slow */ | ||
1478 | if (cleaned_count >= IXGBE_RX_BUFFER_WRITE) { | ||
1479 | ixgbe_alloc_rx_buffers(rx_ring, cleaned_count); | ||
1480 | cleaned_count = 0; | ||
1481 | } | ||
1482 | |||
1483 | /* use prefetched values */ | ||
1484 | rx_desc = next_rxd; | ||
1485 | staterr = le32_to_cpu(rx_desc->wb.upper.status_error); | ||
1486 | } | ||
1487 | |||
1488 | rx_ring->next_to_clean = i; | ||
1489 | cleaned_count = ixgbe_desc_unused(rx_ring); | ||
1490 | |||
1491 | if (cleaned_count) | ||
1492 | ixgbe_alloc_rx_buffers(rx_ring, cleaned_count); | ||
1493 | |||
1494 | #ifdef IXGBE_FCOE | ||
1495 | /* include DDPed FCoE data */ | ||
1496 | if (ddp_bytes > 0) { | ||
1497 | unsigned int mss; | ||
1498 | |||
1499 | mss = rx_ring->netdev->mtu - sizeof(struct fcoe_hdr) - | ||
1500 | sizeof(struct fc_frame_header) - | ||
1501 | sizeof(struct fcoe_crc_eof); | ||
1502 | if (mss > 512) | ||
1503 | mss &= ~511; | ||
1504 | total_rx_bytes += ddp_bytes; | ||
1505 | total_rx_packets += DIV_ROUND_UP(ddp_bytes, mss); | ||
1506 | } | ||
1507 | #endif /* IXGBE_FCOE */ | ||
1508 | |||
1509 | u64_stats_update_begin(&rx_ring->syncp); | ||
1510 | rx_ring->stats.packets += total_rx_packets; | ||
1511 | rx_ring->stats.bytes += total_rx_bytes; | ||
1512 | u64_stats_update_end(&rx_ring->syncp); | ||
1513 | q_vector->rx.total_packets += total_rx_packets; | ||
1514 | q_vector->rx.total_bytes += total_rx_bytes; | ||
1515 | } | ||
1516 | |||
1517 | static int ixgbe_clean_rxonly(struct napi_struct *, int); | ||
1518 | /** | ||
1519 | * ixgbe_configure_msix - Configure MSI-X hardware | ||
1520 | * @adapter: board private structure | ||
1521 | * | ||
1522 | * ixgbe_configure_msix sets up the hardware to properly generate MSI-X | ||
1523 | * interrupts. | ||
1524 | **/ | ||
1525 | static void ixgbe_configure_msix(struct ixgbe_adapter *adapter) | ||
1526 | { | ||
1527 | struct ixgbe_q_vector *q_vector; | ||
1528 | int i, q_vectors, v_idx, r_idx; | ||
1529 | u32 mask; | ||
1530 | |||
1531 | q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; | ||
1532 | |||
1533 | /* | ||
1534 | * Populate the IVAR table and set the ITR values to the | ||
1535 | * corresponding register. | ||
1536 | */ | ||
1537 | for (v_idx = 0; v_idx < q_vectors; v_idx++) { | ||
1538 | q_vector = adapter->q_vector[v_idx]; | ||
1539 | /* XXX for_each_set_bit(...) */ | ||
1540 | r_idx = find_first_bit(q_vector->rx.idx, | ||
1541 | adapter->num_rx_queues); | ||
1542 | |||
1543 | for (i = 0; i < q_vector->rx.count; i++) { | ||
1544 | u8 reg_idx = adapter->rx_ring[r_idx]->reg_idx; | ||
1545 | ixgbe_set_ivar(adapter, 0, reg_idx, v_idx); | ||
1546 | r_idx = find_next_bit(q_vector->rx.idx, | ||
1547 | adapter->num_rx_queues, | ||
1548 | r_idx + 1); | ||
1549 | } | ||
1550 | r_idx = find_first_bit(q_vector->tx.idx, | ||
1551 | adapter->num_tx_queues); | ||
1552 | |||
1553 | for (i = 0; i < q_vector->tx.count; i++) { | ||
1554 | u8 reg_idx = adapter->tx_ring[r_idx]->reg_idx; | ||
1555 | ixgbe_set_ivar(adapter, 1, reg_idx, v_idx); | ||
1556 | r_idx = find_next_bit(q_vector->tx.idx, | ||
1557 | adapter->num_tx_queues, | ||
1558 | r_idx + 1); | ||
1559 | } | ||
1560 | |||
1561 | if (q_vector->tx.count && !q_vector->rx.count) | ||
1562 | /* tx only */ | ||
1563 | q_vector->eitr = adapter->tx_eitr_param; | ||
1564 | else if (q_vector->rx.count) | ||
1565 | /* rx or mixed */ | ||
1566 | q_vector->eitr = adapter->rx_eitr_param; | ||
1567 | |||
1568 | ixgbe_write_eitr(q_vector); | ||
1569 | /* If ATR is enabled, set interrupt affinity */ | ||
1570 | if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) { | ||
1571 | /* | ||
1572 | * Allocate the affinity_hint cpumask, assign the mask | ||
1573 | * for this vector, and set our affinity_hint for | ||
1574 | * this irq. | ||
1575 | */ | ||
1576 | if (!alloc_cpumask_var(&q_vector->affinity_mask, | ||
1577 | GFP_KERNEL)) | ||
1578 | return; | ||
1579 | cpumask_set_cpu(v_idx, q_vector->affinity_mask); | ||
1580 | irq_set_affinity_hint(adapter->msix_entries[v_idx].vector, | ||
1581 | q_vector->affinity_mask); | ||
1582 | } | ||
1583 | } | ||
1584 | |||
1585 | switch (adapter->hw.mac.type) { | ||
1586 | case ixgbe_mac_82598EB: | ||
1587 | ixgbe_set_ivar(adapter, -1, IXGBE_IVAR_OTHER_CAUSES_INDEX, | ||
1588 | v_idx); | ||
1589 | break; | ||
1590 | case ixgbe_mac_82599EB: | ||
1591 | case ixgbe_mac_X540: | ||
1592 | ixgbe_set_ivar(adapter, -1, 1, v_idx); | ||
1593 | break; | ||
1594 | |||
1595 | default: | ||
1596 | break; | ||
1597 | } | ||
1598 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITR(v_idx), 1950); | ||
1599 | |||
1600 | /* set up to autoclear timer, and the vectors */ | ||
1601 | mask = IXGBE_EIMS_ENABLE_MASK; | ||
1602 | if (adapter->num_vfs) | ||
1603 | mask &= ~(IXGBE_EIMS_OTHER | | ||
1604 | IXGBE_EIMS_MAILBOX | | ||
1605 | IXGBE_EIMS_LSC); | ||
1606 | else | ||
1607 | mask &= ~(IXGBE_EIMS_OTHER | IXGBE_EIMS_LSC); | ||
1608 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIAC, mask); | ||
1609 | } | ||
1610 | |||
1611 | enum latency_range { | ||
1612 | lowest_latency = 0, | ||
1613 | low_latency = 1, | ||
1614 | bulk_latency = 2, | ||
1615 | latency_invalid = 255 | ||
1616 | }; | ||
1617 | |||
1618 | /** | ||
1619 | * ixgbe_update_itr - update the dynamic ITR value based on statistics | ||
1620 | * @q_vector: structure containing interrupt and ring information | ||
1621 | * @ring_container: structure containing ring performance data | ||
1622 | * | ||
1623 | * Stores a new ITR value based on packets and byte | ||
1624 | * counts during the last interrupt. The advantage of per interrupt | ||
1625 | * computation is faster updates and more accurate ITR for the current | ||
1626 | * traffic pattern. Constants in this function were computed | ||
1627 | * based on theoretical maximum wire speed and thresholds were set based | ||
1628 | * on testing data as well as attempting to minimize response time | ||
1629 | * while increasing bulk throughput. | ||
1630 | * this functionality is controlled by the InterruptThrottleRate module | ||
1631 | * parameter (see ixgbe_param.c) | ||
1632 | **/ | ||
1633 | static void ixgbe_update_itr(struct ixgbe_q_vector *q_vector, | ||
1634 | struct ixgbe_ring_container *ring_container) | ||
1635 | { | ||
1636 | u64 bytes_perint; | ||
1637 | struct ixgbe_adapter *adapter = q_vector->adapter; | ||
1638 | int bytes = ring_container->total_bytes; | ||
1639 | int packets = ring_container->total_packets; | ||
1640 | u32 timepassed_us; | ||
1641 | u8 itr_setting = ring_container->itr; | ||
1642 | |||
1643 | if (packets == 0) | ||
1644 | return; | ||
1645 | |||
1646 | /* simple throttlerate management | ||
1647 | * 0-20MB/s lowest (100000 ints/s) | ||
1648 | * 20-100MB/s low (20000 ints/s) | ||
1649 | * 100-1249MB/s bulk (8000 ints/s) | ||
1650 | */ | ||
1651 | /* what was last interrupt timeslice? */ | ||
1652 | timepassed_us = 1000000/q_vector->eitr; | ||
1653 | bytes_perint = bytes / timepassed_us; /* bytes/usec */ | ||
1654 | |||
1655 | switch (itr_setting) { | ||
1656 | case lowest_latency: | ||
1657 | if (bytes_perint > adapter->eitr_low) | ||
1658 | itr_setting = low_latency; | ||
1659 | break; | ||
1660 | case low_latency: | ||
1661 | if (bytes_perint > adapter->eitr_high) | ||
1662 | itr_setting = bulk_latency; | ||
1663 | else if (bytes_perint <= adapter->eitr_low) | ||
1664 | itr_setting = lowest_latency; | ||
1665 | break; | ||
1666 | case bulk_latency: | ||
1667 | if (bytes_perint <= adapter->eitr_high) | ||
1668 | itr_setting = low_latency; | ||
1669 | break; | ||
1670 | } | ||
1671 | |||
1672 | /* clear work counters since we have the values we need */ | ||
1673 | ring_container->total_bytes = 0; | ||
1674 | ring_container->total_packets = 0; | ||
1675 | |||
1676 | /* write updated itr to ring container */ | ||
1677 | ring_container->itr = itr_setting; | ||
1678 | } | ||
1679 | |||
1680 | /** | ||
1681 | * ixgbe_write_eitr - write EITR register in hardware specific way | ||
1682 | * @q_vector: structure containing interrupt and ring information | ||
1683 | * | ||
1684 | * This function is made to be called by ethtool and by the driver | ||
1685 | * when it needs to update EITR registers at runtime. Hardware | ||
1686 | * specific quirks/differences are taken care of here. | ||
1687 | */ | ||
1688 | void ixgbe_write_eitr(struct ixgbe_q_vector *q_vector) | ||
1689 | { | ||
1690 | struct ixgbe_adapter *adapter = q_vector->adapter; | ||
1691 | struct ixgbe_hw *hw = &adapter->hw; | ||
1692 | int v_idx = q_vector->v_idx; | ||
1693 | u32 itr_reg = EITR_INTS_PER_SEC_TO_REG(q_vector->eitr); | ||
1694 | |||
1695 | switch (adapter->hw.mac.type) { | ||
1696 | case ixgbe_mac_82598EB: | ||
1697 | /* must write high and low 16 bits to reset counter */ | ||
1698 | itr_reg |= (itr_reg << 16); | ||
1699 | break; | ||
1700 | case ixgbe_mac_82599EB: | ||
1701 | case ixgbe_mac_X540: | ||
1702 | /* | ||
1703 | * 82599 and X540 can support a value of zero, so allow it for | ||
1704 | * max interrupt rate, but there is an errata where it can | ||
1705 | * not be zero with RSC | ||
1706 | */ | ||
1707 | if (itr_reg == 8 && | ||
1708 | !(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)) | ||
1709 | itr_reg = 0; | ||
1710 | |||
1711 | /* | ||
1712 | * set the WDIS bit to not clear the timer bits and cause an | ||
1713 | * immediate assertion of the interrupt | ||
1714 | */ | ||
1715 | itr_reg |= IXGBE_EITR_CNT_WDIS; | ||
1716 | break; | ||
1717 | default: | ||
1718 | break; | ||
1719 | } | ||
1720 | IXGBE_WRITE_REG(hw, IXGBE_EITR(v_idx), itr_reg); | ||
1721 | } | ||
1722 | |||
1723 | static void ixgbe_set_itr(struct ixgbe_q_vector *q_vector) | ||
1724 | { | ||
1725 | u32 new_itr = q_vector->eitr; | ||
1726 | u8 current_itr; | ||
1727 | |||
1728 | ixgbe_update_itr(q_vector, &q_vector->tx); | ||
1729 | ixgbe_update_itr(q_vector, &q_vector->rx); | ||
1730 | |||
1731 | current_itr = max(q_vector->rx.itr, q_vector->tx.itr); | ||
1732 | |||
1733 | switch (current_itr) { | ||
1734 | /* counts and packets in update_itr are dependent on these numbers */ | ||
1735 | case lowest_latency: | ||
1736 | new_itr = 100000; | ||
1737 | break; | ||
1738 | case low_latency: | ||
1739 | new_itr = 20000; /* aka hwitr = ~200 */ | ||
1740 | break; | ||
1741 | case bulk_latency: | ||
1742 | new_itr = 8000; | ||
1743 | break; | ||
1744 | default: | ||
1745 | break; | ||
1746 | } | ||
1747 | |||
1748 | if (new_itr != q_vector->eitr) { | ||
1749 | /* do an exponential smoothing */ | ||
1750 | new_itr = ((q_vector->eitr * 9) + new_itr)/10; | ||
1751 | |||
1752 | /* save the algorithm value here */ | ||
1753 | q_vector->eitr = new_itr; | ||
1754 | |||
1755 | ixgbe_write_eitr(q_vector); | ||
1756 | } | ||
1757 | } | ||
1758 | |||
1759 | /** | ||
1760 | * ixgbe_check_overtemp_subtask - check for over tempurature | ||
1761 | * @adapter: pointer to adapter | ||
1762 | **/ | ||
1763 | static void ixgbe_check_overtemp_subtask(struct ixgbe_adapter *adapter) | ||
1764 | { | ||
1765 | struct ixgbe_hw *hw = &adapter->hw; | ||
1766 | u32 eicr = adapter->interrupt_event; | ||
1767 | |||
1768 | if (test_bit(__IXGBE_DOWN, &adapter->state)) | ||
1769 | return; | ||
1770 | |||
1771 | if (!(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) && | ||
1772 | !(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_EVENT)) | ||
1773 | return; | ||
1774 | |||
1775 | adapter->flags2 &= ~IXGBE_FLAG2_TEMP_SENSOR_EVENT; | ||
1776 | |||
1777 | switch (hw->device_id) { | ||
1778 | case IXGBE_DEV_ID_82599_T3_LOM: | ||
1779 | /* | ||
1780 | * Since the warning interrupt is for both ports | ||
1781 | * we don't have to check if: | ||
1782 | * - This interrupt wasn't for our port. | ||
1783 | * - We may have missed the interrupt so always have to | ||
1784 | * check if we got a LSC | ||
1785 | */ | ||
1786 | if (!(eicr & IXGBE_EICR_GPI_SDP0) && | ||
1787 | !(eicr & IXGBE_EICR_LSC)) | ||
1788 | return; | ||
1789 | |||
1790 | if (!(eicr & IXGBE_EICR_LSC) && hw->mac.ops.check_link) { | ||
1791 | u32 autoneg; | ||
1792 | bool link_up = false; | ||
1793 | |||
1794 | hw->mac.ops.check_link(hw, &autoneg, &link_up, false); | ||
1795 | |||
1796 | if (link_up) | ||
1797 | return; | ||
1798 | } | ||
1799 | |||
1800 | /* Check if this is not due to overtemp */ | ||
1801 | if (hw->phy.ops.check_overtemp(hw) != IXGBE_ERR_OVERTEMP) | ||
1802 | return; | ||
1803 | |||
1804 | break; | ||
1805 | default: | ||
1806 | if (!(eicr & IXGBE_EICR_GPI_SDP0)) | ||
1807 | return; | ||
1808 | break; | ||
1809 | } | ||
1810 | e_crit(drv, | ||
1811 | "Network adapter has been stopped because it has over heated. " | ||
1812 | "Restart the computer. If the problem persists, " | ||
1813 | "power off the system and replace the adapter\n"); | ||
1814 | |||
1815 | adapter->interrupt_event = 0; | ||
1816 | } | ||
1817 | |||
1818 | static void ixgbe_check_fan_failure(struct ixgbe_adapter *adapter, u32 eicr) | ||
1819 | { | ||
1820 | struct ixgbe_hw *hw = &adapter->hw; | ||
1821 | |||
1822 | if ((adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) && | ||
1823 | (eicr & IXGBE_EICR_GPI_SDP1)) { | ||
1824 | e_crit(probe, "Fan has stopped, replace the adapter\n"); | ||
1825 | /* write to clear the interrupt */ | ||
1826 | IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1); | ||
1827 | } | ||
1828 | } | ||
1829 | |||
1830 | static void ixgbe_check_sfp_event(struct ixgbe_adapter *adapter, u32 eicr) | ||
1831 | { | ||
1832 | struct ixgbe_hw *hw = &adapter->hw; | ||
1833 | |||
1834 | if (eicr & IXGBE_EICR_GPI_SDP2) { | ||
1835 | /* Clear the interrupt */ | ||
1836 | IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP2); | ||
1837 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) { | ||
1838 | adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET; | ||
1839 | ixgbe_service_event_schedule(adapter); | ||
1840 | } | ||
1841 | } | ||
1842 | |||
1843 | if (eicr & IXGBE_EICR_GPI_SDP1) { | ||
1844 | /* Clear the interrupt */ | ||
1845 | IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1); | ||
1846 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) { | ||
1847 | adapter->flags |= IXGBE_FLAG_NEED_LINK_CONFIG; | ||
1848 | ixgbe_service_event_schedule(adapter); | ||
1849 | } | ||
1850 | } | ||
1851 | } | ||
1852 | |||
1853 | static void ixgbe_check_lsc(struct ixgbe_adapter *adapter) | ||
1854 | { | ||
1855 | struct ixgbe_hw *hw = &adapter->hw; | ||
1856 | |||
1857 | adapter->lsc_int++; | ||
1858 | adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE; | ||
1859 | adapter->link_check_timeout = jiffies; | ||
1860 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) { | ||
1861 | IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_LSC); | ||
1862 | IXGBE_WRITE_FLUSH(hw); | ||
1863 | ixgbe_service_event_schedule(adapter); | ||
1864 | } | ||
1865 | } | ||
1866 | |||
1867 | static irqreturn_t ixgbe_msix_lsc(int irq, void *data) | ||
1868 | { | ||
1869 | struct ixgbe_adapter *adapter = data; | ||
1870 | struct ixgbe_hw *hw = &adapter->hw; | ||
1871 | u32 eicr; | ||
1872 | |||
1873 | /* | ||
1874 | * Workaround for Silicon errata. Use clear-by-write instead | ||
1875 | * of clear-by-read. Reading with EICS will return the | ||
1876 | * interrupt causes without clearing, which later be done | ||
1877 | * with the write to EICR. | ||
1878 | */ | ||
1879 | eicr = IXGBE_READ_REG(hw, IXGBE_EICS); | ||
1880 | IXGBE_WRITE_REG(hw, IXGBE_EICR, eicr); | ||
1881 | |||
1882 | if (eicr & IXGBE_EICR_LSC) | ||
1883 | ixgbe_check_lsc(adapter); | ||
1884 | |||
1885 | if (eicr & IXGBE_EICR_MAILBOX) | ||
1886 | ixgbe_msg_task(adapter); | ||
1887 | |||
1888 | switch (hw->mac.type) { | ||
1889 | case ixgbe_mac_82599EB: | ||
1890 | case ixgbe_mac_X540: | ||
1891 | /* Handle Flow Director Full threshold interrupt */ | ||
1892 | if (eicr & IXGBE_EICR_FLOW_DIR) { | ||
1893 | int reinit_count = 0; | ||
1894 | int i; | ||
1895 | for (i = 0; i < adapter->num_tx_queues; i++) { | ||
1896 | struct ixgbe_ring *ring = adapter->tx_ring[i]; | ||
1897 | if (test_and_clear_bit(__IXGBE_TX_FDIR_INIT_DONE, | ||
1898 | &ring->state)) | ||
1899 | reinit_count++; | ||
1900 | } | ||
1901 | if (reinit_count) { | ||
1902 | /* no more flow director interrupts until after init */ | ||
1903 | IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_FLOW_DIR); | ||
1904 | eicr &= ~IXGBE_EICR_FLOW_DIR; | ||
1905 | adapter->flags2 |= IXGBE_FLAG2_FDIR_REQUIRES_REINIT; | ||
1906 | ixgbe_service_event_schedule(adapter); | ||
1907 | } | ||
1908 | } | ||
1909 | ixgbe_check_sfp_event(adapter, eicr); | ||
1910 | if ((adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) && | ||
1911 | ((eicr & IXGBE_EICR_GPI_SDP0) || (eicr & IXGBE_EICR_LSC))) { | ||
1912 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) { | ||
1913 | adapter->interrupt_event = eicr; | ||
1914 | adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_EVENT; | ||
1915 | ixgbe_service_event_schedule(adapter); | ||
1916 | } | ||
1917 | } | ||
1918 | break; | ||
1919 | default: | ||
1920 | break; | ||
1921 | } | ||
1922 | |||
1923 | ixgbe_check_fan_failure(adapter, eicr); | ||
1924 | |||
1925 | /* re-enable the original interrupt state, no lsc, no queues */ | ||
1926 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) | ||
1927 | IXGBE_WRITE_REG(hw, IXGBE_EIMS, eicr & | ||
1928 | ~(IXGBE_EIMS_LSC | IXGBE_EIMS_RTX_QUEUE)); | ||
1929 | |||
1930 | return IRQ_HANDLED; | ||
1931 | } | ||
1932 | |||
1933 | static inline void ixgbe_irq_enable_queues(struct ixgbe_adapter *adapter, | ||
1934 | u64 qmask) | ||
1935 | { | ||
1936 | u32 mask; | ||
1937 | struct ixgbe_hw *hw = &adapter->hw; | ||
1938 | |||
1939 | switch (hw->mac.type) { | ||
1940 | case ixgbe_mac_82598EB: | ||
1941 | mask = (IXGBE_EIMS_RTX_QUEUE & qmask); | ||
1942 | IXGBE_WRITE_REG(hw, IXGBE_EIMS, mask); | ||
1943 | break; | ||
1944 | case ixgbe_mac_82599EB: | ||
1945 | case ixgbe_mac_X540: | ||
1946 | mask = (qmask & 0xFFFFFFFF); | ||
1947 | if (mask) | ||
1948 | IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(0), mask); | ||
1949 | mask = (qmask >> 32); | ||
1950 | if (mask) | ||
1951 | IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(1), mask); | ||
1952 | break; | ||
1953 | default: | ||
1954 | break; | ||
1955 | } | ||
1956 | /* skip the flush */ | ||
1957 | } | ||
1958 | |||
1959 | static inline void ixgbe_irq_disable_queues(struct ixgbe_adapter *adapter, | ||
1960 | u64 qmask) | ||
1961 | { | ||
1962 | u32 mask; | ||
1963 | struct ixgbe_hw *hw = &adapter->hw; | ||
1964 | |||
1965 | switch (hw->mac.type) { | ||
1966 | case ixgbe_mac_82598EB: | ||
1967 | mask = (IXGBE_EIMS_RTX_QUEUE & qmask); | ||
1968 | IXGBE_WRITE_REG(hw, IXGBE_EIMC, mask); | ||
1969 | break; | ||
1970 | case ixgbe_mac_82599EB: | ||
1971 | case ixgbe_mac_X540: | ||
1972 | mask = (qmask & 0xFFFFFFFF); | ||
1973 | if (mask) | ||
1974 | IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(0), mask); | ||
1975 | mask = (qmask >> 32); | ||
1976 | if (mask) | ||
1977 | IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(1), mask); | ||
1978 | break; | ||
1979 | default: | ||
1980 | break; | ||
1981 | } | ||
1982 | /* skip the flush */ | ||
1983 | } | ||
1984 | |||
1985 | static irqreturn_t ixgbe_msix_clean_tx(int irq, void *data) | ||
1986 | { | ||
1987 | struct ixgbe_q_vector *q_vector = data; | ||
1988 | struct ixgbe_adapter *adapter = q_vector->adapter; | ||
1989 | struct ixgbe_ring *tx_ring; | ||
1990 | int i, r_idx; | ||
1991 | |||
1992 | if (!q_vector->tx.count) | ||
1993 | return IRQ_HANDLED; | ||
1994 | |||
1995 | r_idx = find_first_bit(q_vector->tx.idx, adapter->num_tx_queues); | ||
1996 | for (i = 0; i < q_vector->tx.count; i++) { | ||
1997 | tx_ring = adapter->tx_ring[r_idx]; | ||
1998 | r_idx = find_next_bit(q_vector->tx.idx, adapter->num_tx_queues, | ||
1999 | r_idx + 1); | ||
2000 | } | ||
2001 | |||
2002 | /* EIAM disabled interrupts (on this vector) for us */ | ||
2003 | napi_schedule(&q_vector->napi); | ||
2004 | |||
2005 | return IRQ_HANDLED; | ||
2006 | } | ||
2007 | |||
2008 | /** | ||
2009 | * ixgbe_msix_clean_rx - single unshared vector rx clean (all queues) | ||
2010 | * @irq: unused | ||
2011 | * @data: pointer to our q_vector struct for this interrupt vector | ||
2012 | **/ | ||
2013 | static irqreturn_t ixgbe_msix_clean_rx(int irq, void *data) | ||
2014 | { | ||
2015 | struct ixgbe_q_vector *q_vector = data; | ||
2016 | struct ixgbe_adapter *adapter = q_vector->adapter; | ||
2017 | struct ixgbe_ring *rx_ring; | ||
2018 | int r_idx; | ||
2019 | int i; | ||
2020 | |||
2021 | #ifdef CONFIG_IXGBE_DCA | ||
2022 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) | ||
2023 | ixgbe_update_dca(q_vector); | ||
2024 | #endif | ||
2025 | |||
2026 | r_idx = find_first_bit(q_vector->rx.idx, adapter->num_rx_queues); | ||
2027 | for (i = 0; i < q_vector->rx.count; i++) { | ||
2028 | rx_ring = adapter->rx_ring[r_idx]; | ||
2029 | r_idx = find_next_bit(q_vector->rx.idx, adapter->num_rx_queues, | ||
2030 | r_idx + 1); | ||
2031 | } | ||
2032 | |||
2033 | if (!q_vector->rx.count) | ||
2034 | return IRQ_HANDLED; | ||
2035 | |||
2036 | /* EIAM disabled interrupts (on this vector) for us */ | ||
2037 | napi_schedule(&q_vector->napi); | ||
2038 | |||
2039 | return IRQ_HANDLED; | ||
2040 | } | ||
2041 | |||
2042 | static irqreturn_t ixgbe_msix_clean_many(int irq, void *data) | ||
2043 | { | ||
2044 | struct ixgbe_q_vector *q_vector = data; | ||
2045 | struct ixgbe_adapter *adapter = q_vector->adapter; | ||
2046 | struct ixgbe_ring *ring; | ||
2047 | int r_idx; | ||
2048 | int i; | ||
2049 | |||
2050 | if (!q_vector->tx.count && !q_vector->rx.count) | ||
2051 | return IRQ_HANDLED; | ||
2052 | |||
2053 | r_idx = find_first_bit(q_vector->tx.idx, adapter->num_tx_queues); | ||
2054 | for (i = 0; i < q_vector->tx.count; i++) { | ||
2055 | ring = adapter->tx_ring[r_idx]; | ||
2056 | r_idx = find_next_bit(q_vector->tx.idx, adapter->num_tx_queues, | ||
2057 | r_idx + 1); | ||
2058 | } | ||
2059 | |||
2060 | r_idx = find_first_bit(q_vector->rx.idx, adapter->num_rx_queues); | ||
2061 | for (i = 0; i < q_vector->rx.count; i++) { | ||
2062 | ring = adapter->rx_ring[r_idx]; | ||
2063 | r_idx = find_next_bit(q_vector->rx.idx, adapter->num_rx_queues, | ||
2064 | r_idx + 1); | ||
2065 | } | ||
2066 | |||
2067 | /* EIAM disabled interrupts (on this vector) for us */ | ||
2068 | napi_schedule(&q_vector->napi); | ||
2069 | |||
2070 | return IRQ_HANDLED; | ||
2071 | } | ||
2072 | |||
2073 | /** | ||
2074 | * ixgbe_clean_rxonly - msix (aka one shot) rx clean routine | ||
2075 | * @napi: napi struct with our devices info in it | ||
2076 | * @budget: amount of work driver is allowed to do this pass, in packets | ||
2077 | * | ||
2078 | * This function is optimized for cleaning one queue only on a single | ||
2079 | * q_vector!!! | ||
2080 | **/ | ||
2081 | static int ixgbe_clean_rxonly(struct napi_struct *napi, int budget) | ||
2082 | { | ||
2083 | struct ixgbe_q_vector *q_vector = | ||
2084 | container_of(napi, struct ixgbe_q_vector, napi); | ||
2085 | struct ixgbe_adapter *adapter = q_vector->adapter; | ||
2086 | struct ixgbe_ring *rx_ring = NULL; | ||
2087 | int work_done = 0; | ||
2088 | long r_idx; | ||
2089 | |||
2090 | #ifdef CONFIG_IXGBE_DCA | ||
2091 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) | ||
2092 | ixgbe_update_dca(q_vector); | ||
2093 | #endif | ||
2094 | |||
2095 | r_idx = find_first_bit(q_vector->rx.idx, adapter->num_rx_queues); | ||
2096 | rx_ring = adapter->rx_ring[r_idx]; | ||
2097 | |||
2098 | ixgbe_clean_rx_irq(q_vector, rx_ring, &work_done, budget); | ||
2099 | |||
2100 | /* If all Rx work done, exit the polling mode */ | ||
2101 | if (work_done < budget) { | ||
2102 | napi_complete(napi); | ||
2103 | if (adapter->rx_itr_setting & 1) | ||
2104 | ixgbe_set_itr(q_vector); | ||
2105 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) | ||
2106 | ixgbe_irq_enable_queues(adapter, | ||
2107 | ((u64)1 << q_vector->v_idx)); | ||
2108 | } | ||
2109 | |||
2110 | return work_done; | ||
2111 | } | ||
2112 | |||
2113 | /** | ||
2114 | * ixgbe_clean_rxtx_many - msix (aka one shot) rx clean routine | ||
2115 | * @napi: napi struct with our devices info in it | ||
2116 | * @budget: amount of work driver is allowed to do this pass, in packets | ||
2117 | * | ||
2118 | * This function will clean more than one rx queue associated with a | ||
2119 | * q_vector. | ||
2120 | **/ | ||
2121 | static int ixgbe_clean_rxtx_many(struct napi_struct *napi, int budget) | ||
2122 | { | ||
2123 | struct ixgbe_q_vector *q_vector = | ||
2124 | container_of(napi, struct ixgbe_q_vector, napi); | ||
2125 | struct ixgbe_adapter *adapter = q_vector->adapter; | ||
2126 | struct ixgbe_ring *ring = NULL; | ||
2127 | int work_done = 0, i; | ||
2128 | long r_idx; | ||
2129 | bool tx_clean_complete = true; | ||
2130 | |||
2131 | #ifdef CONFIG_IXGBE_DCA | ||
2132 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) | ||
2133 | ixgbe_update_dca(q_vector); | ||
2134 | #endif | ||
2135 | |||
2136 | r_idx = find_first_bit(q_vector->tx.idx, adapter->num_tx_queues); | ||
2137 | for (i = 0; i < q_vector->tx.count; i++) { | ||
2138 | ring = adapter->tx_ring[r_idx]; | ||
2139 | tx_clean_complete &= ixgbe_clean_tx_irq(q_vector, ring); | ||
2140 | r_idx = find_next_bit(q_vector->tx.idx, adapter->num_tx_queues, | ||
2141 | r_idx + 1); | ||
2142 | } | ||
2143 | |||
2144 | /* attempt to distribute budget to each queue fairly, but don't allow | ||
2145 | * the budget to go below 1 because we'll exit polling */ | ||
2146 | budget /= (q_vector->rx.count ?: 1); | ||
2147 | budget = max(budget, 1); | ||
2148 | r_idx = find_first_bit(q_vector->rx.idx, adapter->num_rx_queues); | ||
2149 | for (i = 0; i < q_vector->rx.count; i++) { | ||
2150 | ring = adapter->rx_ring[r_idx]; | ||
2151 | ixgbe_clean_rx_irq(q_vector, ring, &work_done, budget); | ||
2152 | r_idx = find_next_bit(q_vector->rx.idx, adapter->num_rx_queues, | ||
2153 | r_idx + 1); | ||
2154 | } | ||
2155 | |||
2156 | r_idx = find_first_bit(q_vector->rx.idx, adapter->num_rx_queues); | ||
2157 | ring = adapter->rx_ring[r_idx]; | ||
2158 | /* If all Rx work done, exit the polling mode */ | ||
2159 | if (work_done < budget) { | ||
2160 | napi_complete(napi); | ||
2161 | if (adapter->rx_itr_setting & 1) | ||
2162 | ixgbe_set_itr(q_vector); | ||
2163 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) | ||
2164 | ixgbe_irq_enable_queues(adapter, | ||
2165 | ((u64)1 << q_vector->v_idx)); | ||
2166 | return 0; | ||
2167 | } | ||
2168 | |||
2169 | return work_done; | ||
2170 | } | ||
2171 | |||
2172 | /** | ||
2173 | * ixgbe_clean_txonly - msix (aka one shot) tx clean routine | ||
2174 | * @napi: napi struct with our devices info in it | ||
2175 | * @budget: amount of work driver is allowed to do this pass, in packets | ||
2176 | * | ||
2177 | * This function is optimized for cleaning one queue only on a single | ||
2178 | * q_vector!!! | ||
2179 | **/ | ||
2180 | static int ixgbe_clean_txonly(struct napi_struct *napi, int budget) | ||
2181 | { | ||
2182 | struct ixgbe_q_vector *q_vector = | ||
2183 | container_of(napi, struct ixgbe_q_vector, napi); | ||
2184 | struct ixgbe_adapter *adapter = q_vector->adapter; | ||
2185 | struct ixgbe_ring *tx_ring = NULL; | ||
2186 | int work_done = 0; | ||
2187 | long r_idx; | ||
2188 | |||
2189 | #ifdef CONFIG_IXGBE_DCA | ||
2190 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) | ||
2191 | ixgbe_update_dca(q_vector); | ||
2192 | #endif | ||
2193 | |||
2194 | r_idx = find_first_bit(q_vector->tx.idx, adapter->num_tx_queues); | ||
2195 | tx_ring = adapter->tx_ring[r_idx]; | ||
2196 | |||
2197 | if (!ixgbe_clean_tx_irq(q_vector, tx_ring)) | ||
2198 | work_done = budget; | ||
2199 | |||
2200 | /* If all Tx work done, exit the polling mode */ | ||
2201 | if (work_done < budget) { | ||
2202 | napi_complete(napi); | ||
2203 | if (adapter->tx_itr_setting & 1) | ||
2204 | ixgbe_set_itr(q_vector); | ||
2205 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) | ||
2206 | ixgbe_irq_enable_queues(adapter, | ||
2207 | ((u64)1 << q_vector->v_idx)); | ||
2208 | } | ||
2209 | |||
2210 | return work_done; | ||
2211 | } | ||
2212 | |||
2213 | static inline void map_vector_to_rxq(struct ixgbe_adapter *a, int v_idx, | ||
2214 | int r_idx) | ||
2215 | { | ||
2216 | struct ixgbe_q_vector *q_vector = a->q_vector[v_idx]; | ||
2217 | struct ixgbe_ring *rx_ring = a->rx_ring[r_idx]; | ||
2218 | |||
2219 | set_bit(r_idx, q_vector->rx.idx); | ||
2220 | q_vector->rx.count++; | ||
2221 | rx_ring->q_vector = q_vector; | ||
2222 | } | ||
2223 | |||
2224 | static inline void map_vector_to_txq(struct ixgbe_adapter *a, int v_idx, | ||
2225 | int t_idx) | ||
2226 | { | ||
2227 | struct ixgbe_q_vector *q_vector = a->q_vector[v_idx]; | ||
2228 | struct ixgbe_ring *tx_ring = a->tx_ring[t_idx]; | ||
2229 | |||
2230 | set_bit(t_idx, q_vector->tx.idx); | ||
2231 | q_vector->tx.count++; | ||
2232 | tx_ring->q_vector = q_vector; | ||
2233 | q_vector->tx.work_limit = a->tx_work_limit; | ||
2234 | } | ||
2235 | |||
2236 | /** | ||
2237 | * ixgbe_map_rings_to_vectors - Maps descriptor rings to vectors | ||
2238 | * @adapter: board private structure to initialize | ||
2239 | * | ||
2240 | * This function maps descriptor rings to the queue-specific vectors | ||
2241 | * we were allotted through the MSI-X enabling code. Ideally, we'd have | ||
2242 | * one vector per ring/queue, but on a constrained vector budget, we | ||
2243 | * group the rings as "efficiently" as possible. You would add new | ||
2244 | * mapping configurations in here. | ||
2245 | **/ | ||
2246 | static int ixgbe_map_rings_to_vectors(struct ixgbe_adapter *adapter) | ||
2247 | { | ||
2248 | int q_vectors; | ||
2249 | int v_start = 0; | ||
2250 | int rxr_idx = 0, txr_idx = 0; | ||
2251 | int rxr_remaining = adapter->num_rx_queues; | ||
2252 | int txr_remaining = adapter->num_tx_queues; | ||
2253 | int i, j; | ||
2254 | int rqpv, tqpv; | ||
2255 | int err = 0; | ||
2256 | |||
2257 | /* No mapping required if MSI-X is disabled. */ | ||
2258 | if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) | ||
2259 | goto out; | ||
2260 | |||
2261 | q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; | ||
2262 | |||
2263 | /* | ||
2264 | * The ideal configuration... | ||
2265 | * We have enough vectors to map one per queue. | ||
2266 | */ | ||
2267 | if (q_vectors == adapter->num_rx_queues + adapter->num_tx_queues) { | ||
2268 | for (; rxr_idx < rxr_remaining; v_start++, rxr_idx++) | ||
2269 | map_vector_to_rxq(adapter, v_start, rxr_idx); | ||
2270 | |||
2271 | for (; txr_idx < txr_remaining; v_start++, txr_idx++) | ||
2272 | map_vector_to_txq(adapter, v_start, txr_idx); | ||
2273 | |||
2274 | goto out; | ||
2275 | } | ||
2276 | |||
2277 | /* | ||
2278 | * If we don't have enough vectors for a 1-to-1 | ||
2279 | * mapping, we'll have to group them so there are | ||
2280 | * multiple queues per vector. | ||
2281 | */ | ||
2282 | /* Re-adjusting *qpv takes care of the remainder. */ | ||
2283 | for (i = v_start; i < q_vectors; i++) { | ||
2284 | rqpv = DIV_ROUND_UP(rxr_remaining, q_vectors - i); | ||
2285 | for (j = 0; j < rqpv; j++) { | ||
2286 | map_vector_to_rxq(adapter, i, rxr_idx); | ||
2287 | rxr_idx++; | ||
2288 | rxr_remaining--; | ||
2289 | } | ||
2290 | tqpv = DIV_ROUND_UP(txr_remaining, q_vectors - i); | ||
2291 | for (j = 0; j < tqpv; j++) { | ||
2292 | map_vector_to_txq(adapter, i, txr_idx); | ||
2293 | txr_idx++; | ||
2294 | txr_remaining--; | ||
2295 | } | ||
2296 | } | ||
2297 | out: | ||
2298 | return err; | ||
2299 | } | ||
2300 | |||
2301 | /** | ||
2302 | * ixgbe_request_msix_irqs - Initialize MSI-X interrupts | ||
2303 | * @adapter: board private structure | ||
2304 | * | ||
2305 | * ixgbe_request_msix_irqs allocates MSI-X vectors and requests | ||
2306 | * interrupts from the kernel. | ||
2307 | **/ | ||
2308 | static int ixgbe_request_msix_irqs(struct ixgbe_adapter *adapter) | ||
2309 | { | ||
2310 | struct net_device *netdev = adapter->netdev; | ||
2311 | irqreturn_t (*handler)(int, void *); | ||
2312 | int i, vector, q_vectors, err; | ||
2313 | int ri = 0, ti = 0; | ||
2314 | |||
2315 | /* Decrement for Other and TCP Timer vectors */ | ||
2316 | q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; | ||
2317 | |||
2318 | err = ixgbe_map_rings_to_vectors(adapter); | ||
2319 | if (err) | ||
2320 | return err; | ||
2321 | |||
2322 | #define SET_HANDLER(_v) (((_v)->rx.count && (_v)->tx.count) \ | ||
2323 | ? &ixgbe_msix_clean_many : \ | ||
2324 | (_v)->rx.count ? &ixgbe_msix_clean_rx : \ | ||
2325 | (_v)->tx.count ? &ixgbe_msix_clean_tx : \ | ||
2326 | NULL) | ||
2327 | for (vector = 0; vector < q_vectors; vector++) { | ||
2328 | struct ixgbe_q_vector *q_vector = adapter->q_vector[vector]; | ||
2329 | handler = SET_HANDLER(q_vector); | ||
2330 | |||
2331 | if (handler == &ixgbe_msix_clean_rx) { | ||
2332 | snprintf(q_vector->name, sizeof(q_vector->name) - 1, | ||
2333 | "%s-%s-%d", netdev->name, "rx", ri++); | ||
2334 | } else if (handler == &ixgbe_msix_clean_tx) { | ||
2335 | snprintf(q_vector->name, sizeof(q_vector->name) - 1, | ||
2336 | "%s-%s-%d", netdev->name, "tx", ti++); | ||
2337 | } else if (handler == &ixgbe_msix_clean_many) { | ||
2338 | snprintf(q_vector->name, sizeof(q_vector->name) - 1, | ||
2339 | "%s-%s-%d", netdev->name, "TxRx", ri++); | ||
2340 | ti++; | ||
2341 | } else { | ||
2342 | /* skip this unused q_vector */ | ||
2343 | continue; | ||
2344 | } | ||
2345 | err = request_irq(adapter->msix_entries[vector].vector, | ||
2346 | handler, 0, q_vector->name, | ||
2347 | q_vector); | ||
2348 | if (err) { | ||
2349 | e_err(probe, "request_irq failed for MSIX interrupt " | ||
2350 | "Error: %d\n", err); | ||
2351 | goto free_queue_irqs; | ||
2352 | } | ||
2353 | } | ||
2354 | |||
2355 | sprintf(adapter->lsc_int_name, "%s:lsc", netdev->name); | ||
2356 | err = request_irq(adapter->msix_entries[vector].vector, | ||
2357 | ixgbe_msix_lsc, 0, adapter->lsc_int_name, adapter); | ||
2358 | if (err) { | ||
2359 | e_err(probe, "request_irq for msix_lsc failed: %d\n", err); | ||
2360 | goto free_queue_irqs; | ||
2361 | } | ||
2362 | |||
2363 | return 0; | ||
2364 | |||
2365 | free_queue_irqs: | ||
2366 | for (i = vector - 1; i >= 0; i--) | ||
2367 | free_irq(adapter->msix_entries[--vector].vector, | ||
2368 | adapter->q_vector[i]); | ||
2369 | adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED; | ||
2370 | pci_disable_msix(adapter->pdev); | ||
2371 | kfree(adapter->msix_entries); | ||
2372 | adapter->msix_entries = NULL; | ||
2373 | return err; | ||
2374 | } | ||
2375 | |||
2376 | /** | ||
2377 | * ixgbe_irq_enable - Enable default interrupt generation settings | ||
2378 | * @adapter: board private structure | ||
2379 | **/ | ||
2380 | static inline void ixgbe_irq_enable(struct ixgbe_adapter *adapter, bool queues, | ||
2381 | bool flush) | ||
2382 | { | ||
2383 | u32 mask; | ||
2384 | |||
2385 | mask = (IXGBE_EIMS_ENABLE_MASK & ~IXGBE_EIMS_RTX_QUEUE); | ||
2386 | if (adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) | ||
2387 | mask |= IXGBE_EIMS_GPI_SDP0; | ||
2388 | if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) | ||
2389 | mask |= IXGBE_EIMS_GPI_SDP1; | ||
2390 | switch (adapter->hw.mac.type) { | ||
2391 | case ixgbe_mac_82599EB: | ||
2392 | case ixgbe_mac_X540: | ||
2393 | mask |= IXGBE_EIMS_ECC; | ||
2394 | mask |= IXGBE_EIMS_GPI_SDP1; | ||
2395 | mask |= IXGBE_EIMS_GPI_SDP2; | ||
2396 | if (adapter->num_vfs) | ||
2397 | mask |= IXGBE_EIMS_MAILBOX; | ||
2398 | break; | ||
2399 | default: | ||
2400 | break; | ||
2401 | } | ||
2402 | if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) | ||
2403 | mask |= IXGBE_EIMS_FLOW_DIR; | ||
2404 | |||
2405 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, mask); | ||
2406 | if (queues) | ||
2407 | ixgbe_irq_enable_queues(adapter, ~0); | ||
2408 | if (flush) | ||
2409 | IXGBE_WRITE_FLUSH(&adapter->hw); | ||
2410 | |||
2411 | if (adapter->num_vfs > 32) { | ||
2412 | u32 eitrsel = (1 << (adapter->num_vfs - 32)) - 1; | ||
2413 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, eitrsel); | ||
2414 | } | ||
2415 | } | ||
2416 | |||
2417 | /** | ||
2418 | * ixgbe_intr - legacy mode Interrupt Handler | ||
2419 | * @irq: interrupt number | ||
2420 | * @data: pointer to a network interface device structure | ||
2421 | **/ | ||
2422 | static irqreturn_t ixgbe_intr(int irq, void *data) | ||
2423 | { | ||
2424 | struct ixgbe_adapter *adapter = data; | ||
2425 | struct ixgbe_hw *hw = &adapter->hw; | ||
2426 | struct ixgbe_q_vector *q_vector = adapter->q_vector[0]; | ||
2427 | u32 eicr; | ||
2428 | |||
2429 | /* | ||
2430 | * Workaround for silicon errata on 82598. Mask the interrupts | ||
2431 | * before the read of EICR. | ||
2432 | */ | ||
2433 | IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_IRQ_CLEAR_MASK); | ||
2434 | |||
2435 | /* for NAPI, using EIAM to auto-mask tx/rx interrupt bits on read | ||
2436 | * therefore no explict interrupt disable is necessary */ | ||
2437 | eicr = IXGBE_READ_REG(hw, IXGBE_EICR); | ||
2438 | if (!eicr) { | ||
2439 | /* | ||
2440 | * shared interrupt alert! | ||
2441 | * make sure interrupts are enabled because the read will | ||
2442 | * have disabled interrupts due to EIAM | ||
2443 | * finish the workaround of silicon errata on 82598. Unmask | ||
2444 | * the interrupt that we masked before the EICR read. | ||
2445 | */ | ||
2446 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) | ||
2447 | ixgbe_irq_enable(adapter, true, true); | ||
2448 | return IRQ_NONE; /* Not our interrupt */ | ||
2449 | } | ||
2450 | |||
2451 | if (eicr & IXGBE_EICR_LSC) | ||
2452 | ixgbe_check_lsc(adapter); | ||
2453 | |||
2454 | switch (hw->mac.type) { | ||
2455 | case ixgbe_mac_82599EB: | ||
2456 | ixgbe_check_sfp_event(adapter, eicr); | ||
2457 | if ((adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) && | ||
2458 | ((eicr & IXGBE_EICR_GPI_SDP0) || (eicr & IXGBE_EICR_LSC))) { | ||
2459 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) { | ||
2460 | adapter->interrupt_event = eicr; | ||
2461 | adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_EVENT; | ||
2462 | ixgbe_service_event_schedule(adapter); | ||
2463 | } | ||
2464 | } | ||
2465 | break; | ||
2466 | default: | ||
2467 | break; | ||
2468 | } | ||
2469 | |||
2470 | ixgbe_check_fan_failure(adapter, eicr); | ||
2471 | |||
2472 | if (napi_schedule_prep(&(q_vector->napi))) { | ||
2473 | /* would disable interrupts here but EIAM disabled it */ | ||
2474 | __napi_schedule(&(q_vector->napi)); | ||
2475 | } | ||
2476 | |||
2477 | /* | ||
2478 | * re-enable link(maybe) and non-queue interrupts, no flush. | ||
2479 | * ixgbe_poll will re-enable the queue interrupts | ||
2480 | */ | ||
2481 | |||
2482 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) | ||
2483 | ixgbe_irq_enable(adapter, false, false); | ||
2484 | |||
2485 | return IRQ_HANDLED; | ||
2486 | } | ||
2487 | |||
2488 | static inline void ixgbe_reset_q_vectors(struct ixgbe_adapter *adapter) | ||
2489 | { | ||
2490 | int i, q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; | ||
2491 | |||
2492 | for (i = 0; i < q_vectors; i++) { | ||
2493 | struct ixgbe_q_vector *q_vector = adapter->q_vector[i]; | ||
2494 | bitmap_zero(q_vector->rx.idx, MAX_RX_QUEUES); | ||
2495 | bitmap_zero(q_vector->tx.idx, MAX_TX_QUEUES); | ||
2496 | q_vector->rx.count = 0; | ||
2497 | q_vector->tx.count = 0; | ||
2498 | } | ||
2499 | } | ||
2500 | |||
2501 | /** | ||
2502 | * ixgbe_request_irq - initialize interrupts | ||
2503 | * @adapter: board private structure | ||
2504 | * | ||
2505 | * Attempts to configure interrupts using the best available | ||
2506 | * capabilities of the hardware and kernel. | ||
2507 | **/ | ||
2508 | static int ixgbe_request_irq(struct ixgbe_adapter *adapter) | ||
2509 | { | ||
2510 | struct net_device *netdev = adapter->netdev; | ||
2511 | int err; | ||
2512 | |||
2513 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { | ||
2514 | err = ixgbe_request_msix_irqs(adapter); | ||
2515 | } else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED) { | ||
2516 | err = request_irq(adapter->pdev->irq, ixgbe_intr, 0, | ||
2517 | netdev->name, adapter); | ||
2518 | } else { | ||
2519 | err = request_irq(adapter->pdev->irq, ixgbe_intr, IRQF_SHARED, | ||
2520 | netdev->name, adapter); | ||
2521 | } | ||
2522 | |||
2523 | if (err) | ||
2524 | e_err(probe, "request_irq failed, Error %d\n", err); | ||
2525 | |||
2526 | return err; | ||
2527 | } | ||
2528 | |||
2529 | static void ixgbe_free_irq(struct ixgbe_adapter *adapter) | ||
2530 | { | ||
2531 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { | ||
2532 | int i, q_vectors; | ||
2533 | |||
2534 | q_vectors = adapter->num_msix_vectors; | ||
2535 | |||
2536 | i = q_vectors - 1; | ||
2537 | free_irq(adapter->msix_entries[i].vector, adapter); | ||
2538 | |||
2539 | i--; | ||
2540 | for (; i >= 0; i--) { | ||
2541 | /* free only the irqs that were actually requested */ | ||
2542 | if (!adapter->q_vector[i]->rx.count && | ||
2543 | !adapter->q_vector[i]->tx.count) | ||
2544 | continue; | ||
2545 | |||
2546 | free_irq(adapter->msix_entries[i].vector, | ||
2547 | adapter->q_vector[i]); | ||
2548 | } | ||
2549 | |||
2550 | ixgbe_reset_q_vectors(adapter); | ||
2551 | } else { | ||
2552 | free_irq(adapter->pdev->irq, adapter); | ||
2553 | } | ||
2554 | } | ||
2555 | |||
2556 | /** | ||
2557 | * ixgbe_irq_disable - Mask off interrupt generation on the NIC | ||
2558 | * @adapter: board private structure | ||
2559 | **/ | ||
2560 | static inline void ixgbe_irq_disable(struct ixgbe_adapter *adapter) | ||
2561 | { | ||
2562 | switch (adapter->hw.mac.type) { | ||
2563 | case ixgbe_mac_82598EB: | ||
2564 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, ~0); | ||
2565 | break; | ||
2566 | case ixgbe_mac_82599EB: | ||
2567 | case ixgbe_mac_X540: | ||
2568 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, 0xFFFF0000); | ||
2569 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(0), ~0); | ||
2570 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(1), ~0); | ||
2571 | if (adapter->num_vfs > 32) | ||
2572 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, 0); | ||
2573 | break; | ||
2574 | default: | ||
2575 | break; | ||
2576 | } | ||
2577 | IXGBE_WRITE_FLUSH(&adapter->hw); | ||
2578 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { | ||
2579 | int i; | ||
2580 | for (i = 0; i < adapter->num_msix_vectors; i++) | ||
2581 | synchronize_irq(adapter->msix_entries[i].vector); | ||
2582 | } else { | ||
2583 | synchronize_irq(adapter->pdev->irq); | ||
2584 | } | ||
2585 | } | ||
2586 | |||
2587 | /** | ||
2588 | * ixgbe_configure_msi_and_legacy - Initialize PIN (INTA...) and MSI interrupts | ||
2589 | * | ||
2590 | **/ | ||
2591 | static void ixgbe_configure_msi_and_legacy(struct ixgbe_adapter *adapter) | ||
2592 | { | ||
2593 | struct ixgbe_hw *hw = &adapter->hw; | ||
2594 | |||
2595 | IXGBE_WRITE_REG(hw, IXGBE_EITR(0), | ||
2596 | EITR_INTS_PER_SEC_TO_REG(adapter->rx_eitr_param)); | ||
2597 | |||
2598 | ixgbe_set_ivar(adapter, 0, 0, 0); | ||
2599 | ixgbe_set_ivar(adapter, 1, 0, 0); | ||
2600 | |||
2601 | map_vector_to_rxq(adapter, 0, 0); | ||
2602 | map_vector_to_txq(adapter, 0, 0); | ||
2603 | |||
2604 | e_info(hw, "Legacy interrupt IVAR setup done\n"); | ||
2605 | } | ||
2606 | |||
2607 | /** | ||
2608 | * ixgbe_configure_tx_ring - Configure 8259x Tx ring after Reset | ||
2609 | * @adapter: board private structure | ||
2610 | * @ring: structure containing ring specific data | ||
2611 | * | ||
2612 | * Configure the Tx descriptor ring after a reset. | ||
2613 | **/ | ||
2614 | void ixgbe_configure_tx_ring(struct ixgbe_adapter *adapter, | ||
2615 | struct ixgbe_ring *ring) | ||
2616 | { | ||
2617 | struct ixgbe_hw *hw = &adapter->hw; | ||
2618 | u64 tdba = ring->dma; | ||
2619 | int wait_loop = 10; | ||
2620 | u32 txdctl; | ||
2621 | u8 reg_idx = ring->reg_idx; | ||
2622 | |||
2623 | /* disable queue to avoid issues while updating state */ | ||
2624 | txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(reg_idx)); | ||
2625 | IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), | ||
2626 | txdctl & ~IXGBE_TXDCTL_ENABLE); | ||
2627 | IXGBE_WRITE_FLUSH(hw); | ||
2628 | |||
2629 | IXGBE_WRITE_REG(hw, IXGBE_TDBAL(reg_idx), | ||
2630 | (tdba & DMA_BIT_MASK(32))); | ||
2631 | IXGBE_WRITE_REG(hw, IXGBE_TDBAH(reg_idx), (tdba >> 32)); | ||
2632 | IXGBE_WRITE_REG(hw, IXGBE_TDLEN(reg_idx), | ||
2633 | ring->count * sizeof(union ixgbe_adv_tx_desc)); | ||
2634 | IXGBE_WRITE_REG(hw, IXGBE_TDH(reg_idx), 0); | ||
2635 | IXGBE_WRITE_REG(hw, IXGBE_TDT(reg_idx), 0); | ||
2636 | ring->tail = hw->hw_addr + IXGBE_TDT(reg_idx); | ||
2637 | |||
2638 | /* configure fetching thresholds */ | ||
2639 | if (adapter->rx_itr_setting == 0) { | ||
2640 | /* cannot set wthresh when itr==0 */ | ||
2641 | txdctl &= ~0x007F0000; | ||
2642 | } else { | ||
2643 | /* enable WTHRESH=8 descriptors, to encourage burst writeback */ | ||
2644 | txdctl |= (8 << 16); | ||
2645 | } | ||
2646 | if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) { | ||
2647 | /* PThresh workaround for Tx hang with DFP enabled. */ | ||
2648 | txdctl |= 32; | ||
2649 | } | ||
2650 | |||
2651 | /* reinitialize flowdirector state */ | ||
2652 | if ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) && | ||
2653 | adapter->atr_sample_rate) { | ||
2654 | ring->atr_sample_rate = adapter->atr_sample_rate; | ||
2655 | ring->atr_count = 0; | ||
2656 | set_bit(__IXGBE_TX_FDIR_INIT_DONE, &ring->state); | ||
2657 | } else { | ||
2658 | ring->atr_sample_rate = 0; | ||
2659 | } | ||
2660 | |||
2661 | clear_bit(__IXGBE_HANG_CHECK_ARMED, &ring->state); | ||
2662 | |||
2663 | /* enable queue */ | ||
2664 | txdctl |= IXGBE_TXDCTL_ENABLE; | ||
2665 | IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), txdctl); | ||
2666 | |||
2667 | /* TXDCTL.EN will return 0 on 82598 if link is down, so skip it */ | ||
2668 | if (hw->mac.type == ixgbe_mac_82598EB && | ||
2669 | !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP)) | ||
2670 | return; | ||
2671 | |||
2672 | /* poll to verify queue is enabled */ | ||
2673 | do { | ||
2674 | usleep_range(1000, 2000); | ||
2675 | txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(reg_idx)); | ||
2676 | } while (--wait_loop && !(txdctl & IXGBE_TXDCTL_ENABLE)); | ||
2677 | if (!wait_loop) | ||
2678 | e_err(drv, "Could not enable Tx Queue %d\n", reg_idx); | ||
2679 | } | ||
2680 | |||
2681 | static void ixgbe_setup_mtqc(struct ixgbe_adapter *adapter) | ||
2682 | { | ||
2683 | struct ixgbe_hw *hw = &adapter->hw; | ||
2684 | u32 rttdcs; | ||
2685 | u32 reg; | ||
2686 | u8 tcs = netdev_get_num_tc(adapter->netdev); | ||
2687 | |||
2688 | if (hw->mac.type == ixgbe_mac_82598EB) | ||
2689 | return; | ||
2690 | |||
2691 | /* disable the arbiter while setting MTQC */ | ||
2692 | rttdcs = IXGBE_READ_REG(hw, IXGBE_RTTDCS); | ||
2693 | rttdcs |= IXGBE_RTTDCS_ARBDIS; | ||
2694 | IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs); | ||
2695 | |||
2696 | /* set transmit pool layout */ | ||
2697 | switch (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) { | ||
2698 | case (IXGBE_FLAG_SRIOV_ENABLED): | ||
2699 | IXGBE_WRITE_REG(hw, IXGBE_MTQC, | ||
2700 | (IXGBE_MTQC_VT_ENA | IXGBE_MTQC_64VF)); | ||
2701 | break; | ||
2702 | default: | ||
2703 | if (!tcs) | ||
2704 | reg = IXGBE_MTQC_64Q_1PB; | ||
2705 | else if (tcs <= 4) | ||
2706 | reg = IXGBE_MTQC_RT_ENA | IXGBE_MTQC_4TC_4TQ; | ||
2707 | else | ||
2708 | reg = IXGBE_MTQC_RT_ENA | IXGBE_MTQC_8TC_8TQ; | ||
2709 | |||
2710 | IXGBE_WRITE_REG(hw, IXGBE_MTQC, reg); | ||
2711 | |||
2712 | /* Enable Security TX Buffer IFG for multiple pb */ | ||
2713 | if (tcs) { | ||
2714 | reg = IXGBE_READ_REG(hw, IXGBE_SECTXMINIFG); | ||
2715 | reg |= IXGBE_SECTX_DCB; | ||
2716 | IXGBE_WRITE_REG(hw, IXGBE_SECTXMINIFG, reg); | ||
2717 | } | ||
2718 | break; | ||
2719 | } | ||
2720 | |||
2721 | /* re-enable the arbiter */ | ||
2722 | rttdcs &= ~IXGBE_RTTDCS_ARBDIS; | ||
2723 | IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs); | ||
2724 | } | ||
2725 | |||
2726 | /** | ||
2727 | * ixgbe_configure_tx - Configure 8259x Transmit Unit after Reset | ||
2728 | * @adapter: board private structure | ||
2729 | * | ||
2730 | * Configure the Tx unit of the MAC after a reset. | ||
2731 | **/ | ||
2732 | static void ixgbe_configure_tx(struct ixgbe_adapter *adapter) | ||
2733 | { | ||
2734 | struct ixgbe_hw *hw = &adapter->hw; | ||
2735 | u32 dmatxctl; | ||
2736 | u32 i; | ||
2737 | |||
2738 | ixgbe_setup_mtqc(adapter); | ||
2739 | |||
2740 | if (hw->mac.type != ixgbe_mac_82598EB) { | ||
2741 | /* DMATXCTL.EN must be before Tx queues are enabled */ | ||
2742 | dmatxctl = IXGBE_READ_REG(hw, IXGBE_DMATXCTL); | ||
2743 | dmatxctl |= IXGBE_DMATXCTL_TE; | ||
2744 | IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, dmatxctl); | ||
2745 | } | ||
2746 | |||
2747 | /* Setup the HW Tx Head and Tail descriptor pointers */ | ||
2748 | for (i = 0; i < adapter->num_tx_queues; i++) | ||
2749 | ixgbe_configure_tx_ring(adapter, adapter->tx_ring[i]); | ||
2750 | } | ||
2751 | |||
2752 | #define IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT 2 | ||
2753 | |||
2754 | static void ixgbe_configure_srrctl(struct ixgbe_adapter *adapter, | ||
2755 | struct ixgbe_ring *rx_ring) | ||
2756 | { | ||
2757 | u32 srrctl; | ||
2758 | u8 reg_idx = rx_ring->reg_idx; | ||
2759 | |||
2760 | switch (adapter->hw.mac.type) { | ||
2761 | case ixgbe_mac_82598EB: { | ||
2762 | struct ixgbe_ring_feature *feature = adapter->ring_feature; | ||
2763 | const int mask = feature[RING_F_RSS].mask; | ||
2764 | reg_idx = reg_idx & mask; | ||
2765 | } | ||
2766 | break; | ||
2767 | case ixgbe_mac_82599EB: | ||
2768 | case ixgbe_mac_X540: | ||
2769 | default: | ||
2770 | break; | ||
2771 | } | ||
2772 | |||
2773 | srrctl = IXGBE_READ_REG(&adapter->hw, IXGBE_SRRCTL(reg_idx)); | ||
2774 | |||
2775 | srrctl &= ~IXGBE_SRRCTL_BSIZEHDR_MASK; | ||
2776 | srrctl &= ~IXGBE_SRRCTL_BSIZEPKT_MASK; | ||
2777 | if (adapter->num_vfs) | ||
2778 | srrctl |= IXGBE_SRRCTL_DROP_EN; | ||
2779 | |||
2780 | srrctl |= (IXGBE_RX_HDR_SIZE << IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT) & | ||
2781 | IXGBE_SRRCTL_BSIZEHDR_MASK; | ||
2782 | |||
2783 | if (ring_is_ps_enabled(rx_ring)) { | ||
2784 | #if (PAGE_SIZE / 2) > IXGBE_MAX_RXBUFFER | ||
2785 | srrctl |= IXGBE_MAX_RXBUFFER >> IXGBE_SRRCTL_BSIZEPKT_SHIFT; | ||
2786 | #else | ||
2787 | srrctl |= (PAGE_SIZE / 2) >> IXGBE_SRRCTL_BSIZEPKT_SHIFT; | ||
2788 | #endif | ||
2789 | srrctl |= IXGBE_SRRCTL_DESCTYPE_HDR_SPLIT_ALWAYS; | ||
2790 | } else { | ||
2791 | srrctl |= ALIGN(rx_ring->rx_buf_len, 1024) >> | ||
2792 | IXGBE_SRRCTL_BSIZEPKT_SHIFT; | ||
2793 | srrctl |= IXGBE_SRRCTL_DESCTYPE_ADV_ONEBUF; | ||
2794 | } | ||
2795 | |||
2796 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_SRRCTL(reg_idx), srrctl); | ||
2797 | } | ||
2798 | |||
2799 | static void ixgbe_setup_mrqc(struct ixgbe_adapter *adapter) | ||
2800 | { | ||
2801 | struct ixgbe_hw *hw = &adapter->hw; | ||
2802 | static const u32 seed[10] = { 0xE291D73D, 0x1805EC6C, 0x2A94B30D, | ||
2803 | 0xA54F2BEC, 0xEA49AF7C, 0xE214AD3D, 0xB855AABE, | ||
2804 | 0x6A3E67EA, 0x14364D17, 0x3BED200D}; | ||
2805 | u32 mrqc = 0, reta = 0; | ||
2806 | u32 rxcsum; | ||
2807 | int i, j; | ||
2808 | u8 tcs = netdev_get_num_tc(adapter->netdev); | ||
2809 | int maxq = adapter->ring_feature[RING_F_RSS].indices; | ||
2810 | |||
2811 | if (tcs) | ||
2812 | maxq = min(maxq, adapter->num_tx_queues / tcs); | ||
2813 | |||
2814 | /* Fill out hash function seeds */ | ||
2815 | for (i = 0; i < 10; i++) | ||
2816 | IXGBE_WRITE_REG(hw, IXGBE_RSSRK(i), seed[i]); | ||
2817 | |||
2818 | /* Fill out redirection table */ | ||
2819 | for (i = 0, j = 0; i < 128; i++, j++) { | ||
2820 | if (j == maxq) | ||
2821 | j = 0; | ||
2822 | /* reta = 4-byte sliding window of | ||
2823 | * 0x00..(indices-1)(indices-1)00..etc. */ | ||
2824 | reta = (reta << 8) | (j * 0x11); | ||
2825 | if ((i & 3) == 3) | ||
2826 | IXGBE_WRITE_REG(hw, IXGBE_RETA(i >> 2), reta); | ||
2827 | } | ||
2828 | |||
2829 | /* Disable indicating checksum in descriptor, enables RSS hash */ | ||
2830 | rxcsum = IXGBE_READ_REG(hw, IXGBE_RXCSUM); | ||
2831 | rxcsum |= IXGBE_RXCSUM_PCSD; | ||
2832 | IXGBE_WRITE_REG(hw, IXGBE_RXCSUM, rxcsum); | ||
2833 | |||
2834 | if (adapter->hw.mac.type == ixgbe_mac_82598EB && | ||
2835 | (adapter->flags & IXGBE_FLAG_RSS_ENABLED)) { | ||
2836 | mrqc = IXGBE_MRQC_RSSEN; | ||
2837 | } else { | ||
2838 | int mask = adapter->flags & (IXGBE_FLAG_RSS_ENABLED | ||
2839 | | IXGBE_FLAG_SRIOV_ENABLED); | ||
2840 | |||
2841 | switch (mask) { | ||
2842 | case (IXGBE_FLAG_RSS_ENABLED): | ||
2843 | if (!tcs) | ||
2844 | mrqc = IXGBE_MRQC_RSSEN; | ||
2845 | else if (tcs <= 4) | ||
2846 | mrqc = IXGBE_MRQC_RTRSS4TCEN; | ||
2847 | else | ||
2848 | mrqc = IXGBE_MRQC_RTRSS8TCEN; | ||
2849 | break; | ||
2850 | case (IXGBE_FLAG_SRIOV_ENABLED): | ||
2851 | mrqc = IXGBE_MRQC_VMDQEN; | ||
2852 | break; | ||
2853 | default: | ||
2854 | break; | ||
2855 | } | ||
2856 | } | ||
2857 | |||
2858 | /* Perform hash on these packet types */ | ||
2859 | mrqc |= IXGBE_MRQC_RSS_FIELD_IPV4 | ||
2860 | | IXGBE_MRQC_RSS_FIELD_IPV4_TCP | ||
2861 | | IXGBE_MRQC_RSS_FIELD_IPV6 | ||
2862 | | IXGBE_MRQC_RSS_FIELD_IPV6_TCP; | ||
2863 | |||
2864 | IXGBE_WRITE_REG(hw, IXGBE_MRQC, mrqc); | ||
2865 | } | ||
2866 | |||
2867 | /** | ||
2868 | * ixgbe_configure_rscctl - enable RSC for the indicated ring | ||
2869 | * @adapter: address of board private structure | ||
2870 | * @index: index of ring to set | ||
2871 | **/ | ||
2872 | static void ixgbe_configure_rscctl(struct ixgbe_adapter *adapter, | ||
2873 | struct ixgbe_ring *ring) | ||
2874 | { | ||
2875 | struct ixgbe_hw *hw = &adapter->hw; | ||
2876 | u32 rscctrl; | ||
2877 | int rx_buf_len; | ||
2878 | u8 reg_idx = ring->reg_idx; | ||
2879 | |||
2880 | if (!ring_is_rsc_enabled(ring)) | ||
2881 | return; | ||
2882 | |||
2883 | rx_buf_len = ring->rx_buf_len; | ||
2884 | rscctrl = IXGBE_READ_REG(hw, IXGBE_RSCCTL(reg_idx)); | ||
2885 | rscctrl |= IXGBE_RSCCTL_RSCEN; | ||
2886 | /* | ||
2887 | * we must limit the number of descriptors so that the | ||
2888 | * total size of max desc * buf_len is not greater | ||
2889 | * than 65535 | ||
2890 | */ | ||
2891 | if (ring_is_ps_enabled(ring)) { | ||
2892 | #if (MAX_SKB_FRAGS > 16) | ||
2893 | rscctrl |= IXGBE_RSCCTL_MAXDESC_16; | ||
2894 | #elif (MAX_SKB_FRAGS > 8) | ||
2895 | rscctrl |= IXGBE_RSCCTL_MAXDESC_8; | ||
2896 | #elif (MAX_SKB_FRAGS > 4) | ||
2897 | rscctrl |= IXGBE_RSCCTL_MAXDESC_4; | ||
2898 | #else | ||
2899 | rscctrl |= IXGBE_RSCCTL_MAXDESC_1; | ||
2900 | #endif | ||
2901 | } else { | ||
2902 | if (rx_buf_len < IXGBE_RXBUFFER_4096) | ||
2903 | rscctrl |= IXGBE_RSCCTL_MAXDESC_16; | ||
2904 | else if (rx_buf_len < IXGBE_RXBUFFER_8192) | ||
2905 | rscctrl |= IXGBE_RSCCTL_MAXDESC_8; | ||
2906 | else | ||
2907 | rscctrl |= IXGBE_RSCCTL_MAXDESC_4; | ||
2908 | } | ||
2909 | IXGBE_WRITE_REG(hw, IXGBE_RSCCTL(reg_idx), rscctrl); | ||
2910 | } | ||
2911 | |||
2912 | /** | ||
2913 | * ixgbe_set_uta - Set unicast filter table address | ||
2914 | * @adapter: board private structure | ||
2915 | * | ||
2916 | * The unicast table address is a register array of 32-bit registers. | ||
2917 | * The table is meant to be used in a way similar to how the MTA is used | ||
2918 | * however due to certain limitations in the hardware it is necessary to | ||
2919 | * set all the hash bits to 1 and use the VMOLR ROPE bit as a promiscuous | ||
2920 | * enable bit to allow vlan tag stripping when promiscuous mode is enabled | ||
2921 | **/ | ||
2922 | static void ixgbe_set_uta(struct ixgbe_adapter *adapter) | ||
2923 | { | ||
2924 | struct ixgbe_hw *hw = &adapter->hw; | ||
2925 | int i; | ||
2926 | |||
2927 | /* The UTA table only exists on 82599 hardware and newer */ | ||
2928 | if (hw->mac.type < ixgbe_mac_82599EB) | ||
2929 | return; | ||
2930 | |||
2931 | /* we only need to do this if VMDq is enabled */ | ||
2932 | if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)) | ||
2933 | return; | ||
2934 | |||
2935 | for (i = 0; i < 128; i++) | ||
2936 | IXGBE_WRITE_REG(hw, IXGBE_UTA(i), ~0); | ||
2937 | } | ||
2938 | |||
2939 | #define IXGBE_MAX_RX_DESC_POLL 10 | ||
2940 | static void ixgbe_rx_desc_queue_enable(struct ixgbe_adapter *adapter, | ||
2941 | struct ixgbe_ring *ring) | ||
2942 | { | ||
2943 | struct ixgbe_hw *hw = &adapter->hw; | ||
2944 | int wait_loop = IXGBE_MAX_RX_DESC_POLL; | ||
2945 | u32 rxdctl; | ||
2946 | u8 reg_idx = ring->reg_idx; | ||
2947 | |||
2948 | /* RXDCTL.EN will return 0 on 82598 if link is down, so skip it */ | ||
2949 | if (hw->mac.type == ixgbe_mac_82598EB && | ||
2950 | !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP)) | ||
2951 | return; | ||
2952 | |||
2953 | do { | ||
2954 | usleep_range(1000, 2000); | ||
2955 | rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx)); | ||
2956 | } while (--wait_loop && !(rxdctl & IXGBE_RXDCTL_ENABLE)); | ||
2957 | |||
2958 | if (!wait_loop) { | ||
2959 | e_err(drv, "RXDCTL.ENABLE on Rx queue %d not set within " | ||
2960 | "the polling period\n", reg_idx); | ||
2961 | } | ||
2962 | } | ||
2963 | |||
2964 | void ixgbe_disable_rx_queue(struct ixgbe_adapter *adapter, | ||
2965 | struct ixgbe_ring *ring) | ||
2966 | { | ||
2967 | struct ixgbe_hw *hw = &adapter->hw; | ||
2968 | int wait_loop = IXGBE_MAX_RX_DESC_POLL; | ||
2969 | u32 rxdctl; | ||
2970 | u8 reg_idx = ring->reg_idx; | ||
2971 | |||
2972 | rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx)); | ||
2973 | rxdctl &= ~IXGBE_RXDCTL_ENABLE; | ||
2974 | |||
2975 | /* write value back with RXDCTL.ENABLE bit cleared */ | ||
2976 | IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl); | ||
2977 | |||
2978 | if (hw->mac.type == ixgbe_mac_82598EB && | ||
2979 | !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP)) | ||
2980 | return; | ||
2981 | |||
2982 | /* the hardware may take up to 100us to really disable the rx queue */ | ||
2983 | do { | ||
2984 | udelay(10); | ||
2985 | rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx)); | ||
2986 | } while (--wait_loop && (rxdctl & IXGBE_RXDCTL_ENABLE)); | ||
2987 | |||
2988 | if (!wait_loop) { | ||
2989 | e_err(drv, "RXDCTL.ENABLE on Rx queue %d not cleared within " | ||
2990 | "the polling period\n", reg_idx); | ||
2991 | } | ||
2992 | } | ||
2993 | |||
2994 | void ixgbe_configure_rx_ring(struct ixgbe_adapter *adapter, | ||
2995 | struct ixgbe_ring *ring) | ||
2996 | { | ||
2997 | struct ixgbe_hw *hw = &adapter->hw; | ||
2998 | u64 rdba = ring->dma; | ||
2999 | u32 rxdctl; | ||
3000 | u8 reg_idx = ring->reg_idx; | ||
3001 | |||
3002 | /* disable queue to avoid issues while updating state */ | ||
3003 | rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx)); | ||
3004 | ixgbe_disable_rx_queue(adapter, ring); | ||
3005 | |||
3006 | IXGBE_WRITE_REG(hw, IXGBE_RDBAL(reg_idx), (rdba & DMA_BIT_MASK(32))); | ||
3007 | IXGBE_WRITE_REG(hw, IXGBE_RDBAH(reg_idx), (rdba >> 32)); | ||
3008 | IXGBE_WRITE_REG(hw, IXGBE_RDLEN(reg_idx), | ||
3009 | ring->count * sizeof(union ixgbe_adv_rx_desc)); | ||
3010 | IXGBE_WRITE_REG(hw, IXGBE_RDH(reg_idx), 0); | ||
3011 | IXGBE_WRITE_REG(hw, IXGBE_RDT(reg_idx), 0); | ||
3012 | ring->tail = hw->hw_addr + IXGBE_RDT(reg_idx); | ||
3013 | |||
3014 | ixgbe_configure_srrctl(adapter, ring); | ||
3015 | ixgbe_configure_rscctl(adapter, ring); | ||
3016 | |||
3017 | /* If operating in IOV mode set RLPML for X540 */ | ||
3018 | if ((adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) && | ||
3019 | hw->mac.type == ixgbe_mac_X540) { | ||
3020 | rxdctl &= ~IXGBE_RXDCTL_RLPMLMASK; | ||
3021 | rxdctl |= ((ring->netdev->mtu + ETH_HLEN + | ||
3022 | ETH_FCS_LEN + VLAN_HLEN) | IXGBE_RXDCTL_RLPML_EN); | ||
3023 | } | ||
3024 | |||
3025 | if (hw->mac.type == ixgbe_mac_82598EB) { | ||
3026 | /* | ||
3027 | * enable cache line friendly hardware writes: | ||
3028 | * PTHRESH=32 descriptors (half the internal cache), | ||
3029 | * this also removes ugly rx_no_buffer_count increment | ||
3030 | * HTHRESH=4 descriptors (to minimize latency on fetch) | ||
3031 | * WTHRESH=8 burst writeback up to two cache lines | ||
3032 | */ | ||
3033 | rxdctl &= ~0x3FFFFF; | ||
3034 | rxdctl |= 0x080420; | ||
3035 | } | ||
3036 | |||
3037 | /* enable receive descriptor ring */ | ||
3038 | rxdctl |= IXGBE_RXDCTL_ENABLE; | ||
3039 | IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl); | ||
3040 | |||
3041 | ixgbe_rx_desc_queue_enable(adapter, ring); | ||
3042 | ixgbe_alloc_rx_buffers(ring, ixgbe_desc_unused(ring)); | ||
3043 | } | ||
3044 | |||
3045 | static void ixgbe_setup_psrtype(struct ixgbe_adapter *adapter) | ||
3046 | { | ||
3047 | struct ixgbe_hw *hw = &adapter->hw; | ||
3048 | int p; | ||
3049 | |||
3050 | /* PSRTYPE must be initialized in non 82598 adapters */ | ||
3051 | u32 psrtype = IXGBE_PSRTYPE_TCPHDR | | ||
3052 | IXGBE_PSRTYPE_UDPHDR | | ||
3053 | IXGBE_PSRTYPE_IPV4HDR | | ||
3054 | IXGBE_PSRTYPE_L2HDR | | ||
3055 | IXGBE_PSRTYPE_IPV6HDR; | ||
3056 | |||
3057 | if (hw->mac.type == ixgbe_mac_82598EB) | ||
3058 | return; | ||
3059 | |||
3060 | if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) | ||
3061 | psrtype |= (adapter->num_rx_queues_per_pool << 29); | ||
3062 | |||
3063 | for (p = 0; p < adapter->num_rx_pools; p++) | ||
3064 | IXGBE_WRITE_REG(hw, IXGBE_PSRTYPE(adapter->num_vfs + p), | ||
3065 | psrtype); | ||
3066 | } | ||
3067 | |||
3068 | static void ixgbe_configure_virtualization(struct ixgbe_adapter *adapter) | ||
3069 | { | ||
3070 | struct ixgbe_hw *hw = &adapter->hw; | ||
3071 | u32 gcr_ext; | ||
3072 | u32 vt_reg_bits; | ||
3073 | u32 reg_offset, vf_shift; | ||
3074 | u32 vmdctl; | ||
3075 | |||
3076 | if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)) | ||
3077 | return; | ||
3078 | |||
3079 | vmdctl = IXGBE_READ_REG(hw, IXGBE_VT_CTL); | ||
3080 | vt_reg_bits = IXGBE_VMD_CTL_VMDQ_EN | IXGBE_VT_CTL_REPLEN; | ||
3081 | vt_reg_bits |= (adapter->num_vfs << IXGBE_VT_CTL_POOL_SHIFT); | ||
3082 | IXGBE_WRITE_REG(hw, IXGBE_VT_CTL, vmdctl | vt_reg_bits); | ||
3083 | |||
3084 | vf_shift = adapter->num_vfs % 32; | ||
3085 | reg_offset = (adapter->num_vfs > 32) ? 1 : 0; | ||
3086 | |||
3087 | /* Enable only the PF's pool for Tx/Rx */ | ||
3088 | IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset), (1 << vf_shift)); | ||
3089 | IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset ^ 1), 0); | ||
3090 | IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset), (1 << vf_shift)); | ||
3091 | IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset ^ 1), 0); | ||
3092 | IXGBE_WRITE_REG(hw, IXGBE_PFDTXGSWC, IXGBE_PFDTXGSWC_VT_LBEN); | ||
3093 | |||
3094 | /* Map PF MAC address in RAR Entry 0 to first pool following VFs */ | ||
3095 | hw->mac.ops.set_vmdq(hw, 0, adapter->num_vfs); | ||
3096 | |||
3097 | /* | ||
3098 | * Set up VF register offsets for selected VT Mode, | ||
3099 | * i.e. 32 or 64 VFs for SR-IOV | ||
3100 | */ | ||
3101 | gcr_ext = IXGBE_READ_REG(hw, IXGBE_GCR_EXT); | ||
3102 | gcr_ext |= IXGBE_GCR_EXT_MSIX_EN; | ||
3103 | gcr_ext |= IXGBE_GCR_EXT_VT_MODE_64; | ||
3104 | IXGBE_WRITE_REG(hw, IXGBE_GCR_EXT, gcr_ext); | ||
3105 | |||
3106 | /* enable Tx loopback for VF/PF communication */ | ||
3107 | IXGBE_WRITE_REG(hw, IXGBE_PFDTXGSWC, IXGBE_PFDTXGSWC_VT_LBEN); | ||
3108 | /* Enable MAC Anti-Spoofing */ | ||
3109 | hw->mac.ops.set_mac_anti_spoofing(hw, | ||
3110 | (adapter->antispoofing_enabled = | ||
3111 | (adapter->num_vfs != 0)), | ||
3112 | adapter->num_vfs); | ||
3113 | } | ||
3114 | |||
3115 | static void ixgbe_set_rx_buffer_len(struct ixgbe_adapter *adapter) | ||
3116 | { | ||
3117 | struct ixgbe_hw *hw = &adapter->hw; | ||
3118 | struct net_device *netdev = adapter->netdev; | ||
3119 | int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN; | ||
3120 | int rx_buf_len; | ||
3121 | struct ixgbe_ring *rx_ring; | ||
3122 | int i; | ||
3123 | u32 mhadd, hlreg0; | ||
3124 | |||
3125 | /* Decide whether to use packet split mode or not */ | ||
3126 | /* On by default */ | ||
3127 | adapter->flags |= IXGBE_FLAG_RX_PS_ENABLED; | ||
3128 | |||
3129 | /* Do not use packet split if we're in SR-IOV Mode */ | ||
3130 | if (adapter->num_vfs) | ||
3131 | adapter->flags &= ~IXGBE_FLAG_RX_PS_ENABLED; | ||
3132 | |||
3133 | /* Disable packet split due to 82599 erratum #45 */ | ||
3134 | if (hw->mac.type == ixgbe_mac_82599EB) | ||
3135 | adapter->flags &= ~IXGBE_FLAG_RX_PS_ENABLED; | ||
3136 | |||
3137 | /* Set the RX buffer length according to the mode */ | ||
3138 | if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED) { | ||
3139 | rx_buf_len = IXGBE_RX_HDR_SIZE; | ||
3140 | } else { | ||
3141 | if (!(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) && | ||
3142 | (netdev->mtu <= ETH_DATA_LEN)) | ||
3143 | rx_buf_len = MAXIMUM_ETHERNET_VLAN_SIZE; | ||
3144 | else | ||
3145 | rx_buf_len = ALIGN(max_frame + VLAN_HLEN, 1024); | ||
3146 | } | ||
3147 | |||
3148 | #ifdef IXGBE_FCOE | ||
3149 | /* adjust max frame to be able to do baby jumbo for FCoE */ | ||
3150 | if ((adapter->flags & IXGBE_FLAG_FCOE_ENABLED) && | ||
3151 | (max_frame < IXGBE_FCOE_JUMBO_FRAME_SIZE)) | ||
3152 | max_frame = IXGBE_FCOE_JUMBO_FRAME_SIZE; | ||
3153 | |||
3154 | #endif /* IXGBE_FCOE */ | ||
3155 | mhadd = IXGBE_READ_REG(hw, IXGBE_MHADD); | ||
3156 | if (max_frame != (mhadd >> IXGBE_MHADD_MFS_SHIFT)) { | ||
3157 | mhadd &= ~IXGBE_MHADD_MFS_MASK; | ||
3158 | mhadd |= max_frame << IXGBE_MHADD_MFS_SHIFT; | ||
3159 | |||
3160 | IXGBE_WRITE_REG(hw, IXGBE_MHADD, mhadd); | ||
3161 | } | ||
3162 | |||
3163 | hlreg0 = IXGBE_READ_REG(hw, IXGBE_HLREG0); | ||
3164 | /* set jumbo enable since MHADD.MFS is keeping size locked at max_frame */ | ||
3165 | hlreg0 |= IXGBE_HLREG0_JUMBOEN; | ||
3166 | IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg0); | ||
3167 | |||
3168 | /* | ||
3169 | * Setup the HW Rx Head and Tail Descriptor Pointers and | ||
3170 | * the Base and Length of the Rx Descriptor Ring | ||
3171 | */ | ||
3172 | for (i = 0; i < adapter->num_rx_queues; i++) { | ||
3173 | rx_ring = adapter->rx_ring[i]; | ||
3174 | rx_ring->rx_buf_len = rx_buf_len; | ||
3175 | |||
3176 | if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED) | ||
3177 | set_ring_ps_enabled(rx_ring); | ||
3178 | else | ||
3179 | clear_ring_ps_enabled(rx_ring); | ||
3180 | |||
3181 | if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) | ||
3182 | set_ring_rsc_enabled(rx_ring); | ||
3183 | else | ||
3184 | clear_ring_rsc_enabled(rx_ring); | ||
3185 | |||
3186 | #ifdef IXGBE_FCOE | ||
3187 | if (netdev->features & NETIF_F_FCOE_MTU) { | ||
3188 | struct ixgbe_ring_feature *f; | ||
3189 | f = &adapter->ring_feature[RING_F_FCOE]; | ||
3190 | if ((i >= f->mask) && (i < f->mask + f->indices)) { | ||
3191 | clear_ring_ps_enabled(rx_ring); | ||
3192 | if (rx_buf_len < IXGBE_FCOE_JUMBO_FRAME_SIZE) | ||
3193 | rx_ring->rx_buf_len = | ||
3194 | IXGBE_FCOE_JUMBO_FRAME_SIZE; | ||
3195 | } else if (!ring_is_rsc_enabled(rx_ring) && | ||
3196 | !ring_is_ps_enabled(rx_ring)) { | ||
3197 | rx_ring->rx_buf_len = | ||
3198 | IXGBE_FCOE_JUMBO_FRAME_SIZE; | ||
3199 | } | ||
3200 | } | ||
3201 | #endif /* IXGBE_FCOE */ | ||
3202 | } | ||
3203 | } | ||
3204 | |||
3205 | static void ixgbe_setup_rdrxctl(struct ixgbe_adapter *adapter) | ||
3206 | { | ||
3207 | struct ixgbe_hw *hw = &adapter->hw; | ||
3208 | u32 rdrxctl = IXGBE_READ_REG(hw, IXGBE_RDRXCTL); | ||
3209 | |||
3210 | switch (hw->mac.type) { | ||
3211 | case ixgbe_mac_82598EB: | ||
3212 | /* | ||
3213 | * For VMDq support of different descriptor types or | ||
3214 | * buffer sizes through the use of multiple SRRCTL | ||
3215 | * registers, RDRXCTL.MVMEN must be set to 1 | ||
3216 | * | ||
3217 | * also, the manual doesn't mention it clearly but DCA hints | ||
3218 | * will only use queue 0's tags unless this bit is set. Side | ||
3219 | * effects of setting this bit are only that SRRCTL must be | ||
3220 | * fully programmed [0..15] | ||
3221 | */ | ||
3222 | rdrxctl |= IXGBE_RDRXCTL_MVMEN; | ||
3223 | break; | ||
3224 | case ixgbe_mac_82599EB: | ||
3225 | case ixgbe_mac_X540: | ||
3226 | /* Disable RSC for ACK packets */ | ||
3227 | IXGBE_WRITE_REG(hw, IXGBE_RSCDBU, | ||
3228 | (IXGBE_RSCDBU_RSCACKDIS | IXGBE_READ_REG(hw, IXGBE_RSCDBU))); | ||
3229 | rdrxctl &= ~IXGBE_RDRXCTL_RSCFRSTSIZE; | ||
3230 | /* hardware requires some bits to be set by default */ | ||
3231 | rdrxctl |= (IXGBE_RDRXCTL_RSCACKC | IXGBE_RDRXCTL_FCOE_WRFIX); | ||
3232 | rdrxctl |= IXGBE_RDRXCTL_CRCSTRIP; | ||
3233 | break; | ||
3234 | default: | ||
3235 | /* We should do nothing since we don't know this hardware */ | ||
3236 | return; | ||
3237 | } | ||
3238 | |||
3239 | IXGBE_WRITE_REG(hw, IXGBE_RDRXCTL, rdrxctl); | ||
3240 | } | ||
3241 | |||
3242 | /** | ||
3243 | * ixgbe_configure_rx - Configure 8259x Receive Unit after Reset | ||
3244 | * @adapter: board private structure | ||
3245 | * | ||
3246 | * Configure the Rx unit of the MAC after a reset. | ||
3247 | **/ | ||
3248 | static void ixgbe_configure_rx(struct ixgbe_adapter *adapter) | ||
3249 | { | ||
3250 | struct ixgbe_hw *hw = &adapter->hw; | ||
3251 | int i; | ||
3252 | u32 rxctrl; | ||
3253 | |||
3254 | /* disable receives while setting up the descriptors */ | ||
3255 | rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL); | ||
3256 | IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN); | ||
3257 | |||
3258 | ixgbe_setup_psrtype(adapter); | ||
3259 | ixgbe_setup_rdrxctl(adapter); | ||
3260 | |||
3261 | /* Program registers for the distribution of queues */ | ||
3262 | ixgbe_setup_mrqc(adapter); | ||
3263 | |||
3264 | ixgbe_set_uta(adapter); | ||
3265 | |||
3266 | /* set_rx_buffer_len must be called before ring initialization */ | ||
3267 | ixgbe_set_rx_buffer_len(adapter); | ||
3268 | |||
3269 | /* | ||
3270 | * Setup the HW Rx Head and Tail Descriptor Pointers and | ||
3271 | * the Base and Length of the Rx Descriptor Ring | ||
3272 | */ | ||
3273 | for (i = 0; i < adapter->num_rx_queues; i++) | ||
3274 | ixgbe_configure_rx_ring(adapter, adapter->rx_ring[i]); | ||
3275 | |||
3276 | /* disable drop enable for 82598 parts */ | ||
3277 | if (hw->mac.type == ixgbe_mac_82598EB) | ||
3278 | rxctrl |= IXGBE_RXCTRL_DMBYPS; | ||
3279 | |||
3280 | /* enable all receives */ | ||
3281 | rxctrl |= IXGBE_RXCTRL_RXEN; | ||
3282 | hw->mac.ops.enable_rx_dma(hw, rxctrl); | ||
3283 | } | ||
3284 | |||
3285 | static void ixgbe_vlan_rx_add_vid(struct net_device *netdev, u16 vid) | ||
3286 | { | ||
3287 | struct ixgbe_adapter *adapter = netdev_priv(netdev); | ||
3288 | struct ixgbe_hw *hw = &adapter->hw; | ||
3289 | int pool_ndx = adapter->num_vfs; | ||
3290 | |||
3291 | /* add VID to filter table */ | ||
3292 | hw->mac.ops.set_vfta(&adapter->hw, vid, pool_ndx, true); | ||
3293 | set_bit(vid, adapter->active_vlans); | ||
3294 | } | ||
3295 | |||
3296 | static void ixgbe_vlan_rx_kill_vid(struct net_device *netdev, u16 vid) | ||
3297 | { | ||
3298 | struct ixgbe_adapter *adapter = netdev_priv(netdev); | ||
3299 | struct ixgbe_hw *hw = &adapter->hw; | ||
3300 | int pool_ndx = adapter->num_vfs; | ||
3301 | |||
3302 | /* remove VID from filter table */ | ||
3303 | hw->mac.ops.set_vfta(&adapter->hw, vid, pool_ndx, false); | ||
3304 | clear_bit(vid, adapter->active_vlans); | ||
3305 | } | ||
3306 | |||
3307 | /** | ||
3308 | * ixgbe_vlan_filter_disable - helper to disable hw vlan filtering | ||
3309 | * @adapter: driver data | ||
3310 | */ | ||
3311 | static void ixgbe_vlan_filter_disable(struct ixgbe_adapter *adapter) | ||
3312 | { | ||
3313 | struct ixgbe_hw *hw = &adapter->hw; | ||
3314 | u32 vlnctrl; | ||
3315 | |||
3316 | vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL); | ||
3317 | vlnctrl &= ~(IXGBE_VLNCTRL_VFE | IXGBE_VLNCTRL_CFIEN); | ||
3318 | IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl); | ||
3319 | } | ||
3320 | |||
3321 | /** | ||
3322 | * ixgbe_vlan_filter_enable - helper to enable hw vlan filtering | ||
3323 | * @adapter: driver data | ||
3324 | */ | ||
3325 | static void ixgbe_vlan_filter_enable(struct ixgbe_adapter *adapter) | ||
3326 | { | ||
3327 | struct ixgbe_hw *hw = &adapter->hw; | ||
3328 | u32 vlnctrl; | ||
3329 | |||
3330 | vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL); | ||
3331 | vlnctrl |= IXGBE_VLNCTRL_VFE; | ||
3332 | vlnctrl &= ~IXGBE_VLNCTRL_CFIEN; | ||
3333 | IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl); | ||
3334 | } | ||
3335 | |||
3336 | /** | ||
3337 | * ixgbe_vlan_strip_disable - helper to disable hw vlan stripping | ||
3338 | * @adapter: driver data | ||
3339 | */ | ||
3340 | static void ixgbe_vlan_strip_disable(struct ixgbe_adapter *adapter) | ||
3341 | { | ||
3342 | struct ixgbe_hw *hw = &adapter->hw; | ||
3343 | u32 vlnctrl; | ||
3344 | int i, j; | ||
3345 | |||
3346 | switch (hw->mac.type) { | ||
3347 | case ixgbe_mac_82598EB: | ||
3348 | vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL); | ||
3349 | vlnctrl &= ~IXGBE_VLNCTRL_VME; | ||
3350 | IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl); | ||
3351 | break; | ||
3352 | case ixgbe_mac_82599EB: | ||
3353 | case ixgbe_mac_X540: | ||
3354 | for (i = 0; i < adapter->num_rx_queues; i++) { | ||
3355 | j = adapter->rx_ring[i]->reg_idx; | ||
3356 | vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j)); | ||
3357 | vlnctrl &= ~IXGBE_RXDCTL_VME; | ||
3358 | IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl); | ||
3359 | } | ||
3360 | break; | ||
3361 | default: | ||
3362 | break; | ||
3363 | } | ||
3364 | } | ||
3365 | |||
3366 | /** | ||
3367 | * ixgbe_vlan_strip_enable - helper to enable hw vlan stripping | ||
3368 | * @adapter: driver data | ||
3369 | */ | ||
3370 | static void ixgbe_vlan_strip_enable(struct ixgbe_adapter *adapter) | ||
3371 | { | ||
3372 | struct ixgbe_hw *hw = &adapter->hw; | ||
3373 | u32 vlnctrl; | ||
3374 | int i, j; | ||
3375 | |||
3376 | switch (hw->mac.type) { | ||
3377 | case ixgbe_mac_82598EB: | ||
3378 | vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL); | ||
3379 | vlnctrl |= IXGBE_VLNCTRL_VME; | ||
3380 | IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl); | ||
3381 | break; | ||
3382 | case ixgbe_mac_82599EB: | ||
3383 | case ixgbe_mac_X540: | ||
3384 | for (i = 0; i < adapter->num_rx_queues; i++) { | ||
3385 | j = adapter->rx_ring[i]->reg_idx; | ||
3386 | vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j)); | ||
3387 | vlnctrl |= IXGBE_RXDCTL_VME; | ||
3388 | IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl); | ||
3389 | } | ||
3390 | break; | ||
3391 | default: | ||
3392 | break; | ||
3393 | } | ||
3394 | } | ||
3395 | |||
3396 | static void ixgbe_restore_vlan(struct ixgbe_adapter *adapter) | ||
3397 | { | ||
3398 | u16 vid; | ||
3399 | |||
3400 | ixgbe_vlan_rx_add_vid(adapter->netdev, 0); | ||
3401 | |||
3402 | for_each_set_bit(vid, adapter->active_vlans, VLAN_N_VID) | ||
3403 | ixgbe_vlan_rx_add_vid(adapter->netdev, vid); | ||
3404 | } | ||
3405 | |||
3406 | /** | ||
3407 | * ixgbe_write_uc_addr_list - write unicast addresses to RAR table | ||
3408 | * @netdev: network interface device structure | ||
3409 | * | ||
3410 | * Writes unicast address list to the RAR table. | ||
3411 | * Returns: -ENOMEM on failure/insufficient address space | ||
3412 | * 0 on no addresses written | ||
3413 | * X on writing X addresses to the RAR table | ||
3414 | **/ | ||
3415 | static int ixgbe_write_uc_addr_list(struct net_device *netdev) | ||
3416 | { | ||
3417 | struct ixgbe_adapter *adapter = netdev_priv(netdev); | ||
3418 | struct ixgbe_hw *hw = &adapter->hw; | ||
3419 | unsigned int vfn = adapter->num_vfs; | ||
3420 | unsigned int rar_entries = IXGBE_MAX_PF_MACVLANS; | ||
3421 | int count = 0; | ||
3422 | |||
3423 | /* return ENOMEM indicating insufficient memory for addresses */ | ||
3424 | if (netdev_uc_count(netdev) > rar_entries) | ||
3425 | return -ENOMEM; | ||
3426 | |||
3427 | if (!netdev_uc_empty(netdev) && rar_entries) { | ||
3428 | struct netdev_hw_addr *ha; | ||
3429 | /* return error if we do not support writing to RAR table */ | ||
3430 | if (!hw->mac.ops.set_rar) | ||
3431 | return -ENOMEM; | ||
3432 | |||
3433 | netdev_for_each_uc_addr(ha, netdev) { | ||
3434 | if (!rar_entries) | ||
3435 | break; | ||
3436 | hw->mac.ops.set_rar(hw, rar_entries--, ha->addr, | ||
3437 | vfn, IXGBE_RAH_AV); | ||
3438 | count++; | ||
3439 | } | ||
3440 | } | ||
3441 | /* write the addresses in reverse order to avoid write combining */ | ||
3442 | for (; rar_entries > 0 ; rar_entries--) | ||
3443 | hw->mac.ops.clear_rar(hw, rar_entries); | ||
3444 | |||
3445 | return count; | ||
3446 | } | ||
3447 | |||
3448 | /** | ||
3449 | * ixgbe_set_rx_mode - Unicast, Multicast and Promiscuous mode set | ||
3450 | * @netdev: network interface device structure | ||
3451 | * | ||
3452 | * The set_rx_method entry point is called whenever the unicast/multicast | ||
3453 | * address list or the network interface flags are updated. This routine is | ||
3454 | * responsible for configuring the hardware for proper unicast, multicast and | ||
3455 | * promiscuous mode. | ||
3456 | **/ | ||
3457 | void ixgbe_set_rx_mode(struct net_device *netdev) | ||
3458 | { | ||
3459 | struct ixgbe_adapter *adapter = netdev_priv(netdev); | ||
3460 | struct ixgbe_hw *hw = &adapter->hw; | ||
3461 | u32 fctrl, vmolr = IXGBE_VMOLR_BAM | IXGBE_VMOLR_AUPE; | ||
3462 | int count; | ||
3463 | |||
3464 | /* Check for Promiscuous and All Multicast modes */ | ||
3465 | |||
3466 | fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL); | ||
3467 | |||
3468 | /* set all bits that we expect to always be set */ | ||
3469 | fctrl |= IXGBE_FCTRL_BAM; | ||
3470 | fctrl |= IXGBE_FCTRL_DPF; /* discard pause frames when FC enabled */ | ||
3471 | fctrl |= IXGBE_FCTRL_PMCF; | ||
3472 | |||
3473 | /* clear the bits we are changing the status of */ | ||
3474 | fctrl &= ~(IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE); | ||
3475 | |||
3476 | if (netdev->flags & IFF_PROMISC) { | ||
3477 | hw->addr_ctrl.user_set_promisc = true; | ||
3478 | fctrl |= (IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE); | ||
3479 | vmolr |= (IXGBE_VMOLR_ROPE | IXGBE_VMOLR_MPE); | ||
3480 | /* don't hardware filter vlans in promisc mode */ | ||
3481 | ixgbe_vlan_filter_disable(adapter); | ||
3482 | } else { | ||
3483 | if (netdev->flags & IFF_ALLMULTI) { | ||
3484 | fctrl |= IXGBE_FCTRL_MPE; | ||
3485 | vmolr |= IXGBE_VMOLR_MPE; | ||
3486 | } else { | ||
3487 | /* | ||
3488 | * Write addresses to the MTA, if the attempt fails | ||
3489 | * then we should just turn on promiscuous mode so | ||
3490 | * that we can at least receive multicast traffic | ||
3491 | */ | ||
3492 | hw->mac.ops.update_mc_addr_list(hw, netdev); | ||
3493 | vmolr |= IXGBE_VMOLR_ROMPE; | ||
3494 | } | ||
3495 | ixgbe_vlan_filter_enable(adapter); | ||
3496 | hw->addr_ctrl.user_set_promisc = false; | ||
3497 | /* | ||
3498 | * Write addresses to available RAR registers, if there is not | ||
3499 | * sufficient space to store all the addresses then enable | ||
3500 | * unicast promiscuous mode | ||
3501 | */ | ||
3502 | count = ixgbe_write_uc_addr_list(netdev); | ||
3503 | if (count < 0) { | ||
3504 | fctrl |= IXGBE_FCTRL_UPE; | ||
3505 | vmolr |= IXGBE_VMOLR_ROPE; | ||
3506 | } | ||
3507 | } | ||
3508 | |||
3509 | if (adapter->num_vfs) { | ||
3510 | ixgbe_restore_vf_multicasts(adapter); | ||
3511 | vmolr |= IXGBE_READ_REG(hw, IXGBE_VMOLR(adapter->num_vfs)) & | ||
3512 | ~(IXGBE_VMOLR_MPE | IXGBE_VMOLR_ROMPE | | ||
3513 | IXGBE_VMOLR_ROPE); | ||
3514 | IXGBE_WRITE_REG(hw, IXGBE_VMOLR(adapter->num_vfs), vmolr); | ||
3515 | } | ||
3516 | |||
3517 | IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl); | ||
3518 | |||
3519 | if (netdev->features & NETIF_F_HW_VLAN_RX) | ||
3520 | ixgbe_vlan_strip_enable(adapter); | ||
3521 | else | ||
3522 | ixgbe_vlan_strip_disable(adapter); | ||
3523 | } | ||
3524 | |||
3525 | static void ixgbe_napi_enable_all(struct ixgbe_adapter *adapter) | ||
3526 | { | ||
3527 | int q_idx; | ||
3528 | struct ixgbe_q_vector *q_vector; | ||
3529 | int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; | ||
3530 | |||
3531 | /* legacy and MSI only use one vector */ | ||
3532 | if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) | ||
3533 | q_vectors = 1; | ||
3534 | |||
3535 | for (q_idx = 0; q_idx < q_vectors; q_idx++) { | ||
3536 | struct napi_struct *napi; | ||
3537 | q_vector = adapter->q_vector[q_idx]; | ||
3538 | napi = &q_vector->napi; | ||
3539 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { | ||
3540 | if (!q_vector->rx.count || !q_vector->tx.count) { | ||
3541 | if (q_vector->tx.count == 1) | ||
3542 | napi->poll = &ixgbe_clean_txonly; | ||
3543 | else if (q_vector->rx.count == 1) | ||
3544 | napi->poll = &ixgbe_clean_rxonly; | ||
3545 | } | ||
3546 | } | ||
3547 | |||
3548 | napi_enable(napi); | ||
3549 | } | ||
3550 | } | ||
3551 | |||
3552 | static void ixgbe_napi_disable_all(struct ixgbe_adapter *adapter) | ||
3553 | { | ||
3554 | int q_idx; | ||
3555 | struct ixgbe_q_vector *q_vector; | ||
3556 | int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; | ||
3557 | |||
3558 | /* legacy and MSI only use one vector */ | ||
3559 | if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) | ||
3560 | q_vectors = 1; | ||
3561 | |||
3562 | for (q_idx = 0; q_idx < q_vectors; q_idx++) { | ||
3563 | q_vector = adapter->q_vector[q_idx]; | ||
3564 | napi_disable(&q_vector->napi); | ||
3565 | } | ||
3566 | } | ||
3567 | |||
3568 | #ifdef CONFIG_IXGBE_DCB | ||
3569 | /* | ||
3570 | * ixgbe_configure_dcb - Configure DCB hardware | ||
3571 | * @adapter: ixgbe adapter struct | ||
3572 | * | ||
3573 | * This is called by the driver on open to configure the DCB hardware. | ||
3574 | * This is also called by the gennetlink interface when reconfiguring | ||
3575 | * the DCB state. | ||
3576 | */ | ||
3577 | static void ixgbe_configure_dcb(struct ixgbe_adapter *adapter) | ||
3578 | { | ||
3579 | struct ixgbe_hw *hw = &adapter->hw; | ||
3580 | int max_frame = adapter->netdev->mtu + ETH_HLEN + ETH_FCS_LEN; | ||
3581 | |||
3582 | if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED)) { | ||
3583 | if (hw->mac.type == ixgbe_mac_82598EB) | ||
3584 | netif_set_gso_max_size(adapter->netdev, 65536); | ||
3585 | return; | ||
3586 | } | ||
3587 | |||
3588 | if (hw->mac.type == ixgbe_mac_82598EB) | ||
3589 | netif_set_gso_max_size(adapter->netdev, 32768); | ||
3590 | |||
3591 | |||
3592 | /* Enable VLAN tag insert/strip */ | ||
3593 | adapter->netdev->features |= NETIF_F_HW_VLAN_RX; | ||
3594 | |||
3595 | hw->mac.ops.set_vfta(&adapter->hw, 0, 0, true); | ||
3596 | |||
3597 | /* reconfigure the hardware */ | ||
3598 | if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_CEE) { | ||
3599 | #ifdef CONFIG_FCOE | ||
3600 | if (adapter->netdev->features & NETIF_F_FCOE_MTU) | ||
3601 | max_frame = max(max_frame, IXGBE_FCOE_JUMBO_FRAME_SIZE); | ||
3602 | #endif | ||
3603 | ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame, | ||
3604 | DCB_TX_CONFIG); | ||
3605 | ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame, | ||
3606 | DCB_RX_CONFIG); | ||
3607 | ixgbe_dcb_hw_config(hw, &adapter->dcb_cfg); | ||
3608 | } else { | ||
3609 | struct net_device *dev = adapter->netdev; | ||
3610 | |||
3611 | if (adapter->ixgbe_ieee_ets) | ||
3612 | dev->dcbnl_ops->ieee_setets(dev, | ||
3613 | adapter->ixgbe_ieee_ets); | ||
3614 | if (adapter->ixgbe_ieee_pfc) | ||
3615 | dev->dcbnl_ops->ieee_setpfc(dev, | ||
3616 | adapter->ixgbe_ieee_pfc); | ||
3617 | } | ||
3618 | |||
3619 | /* Enable RSS Hash per TC */ | ||
3620 | if (hw->mac.type != ixgbe_mac_82598EB) { | ||
3621 | int i; | ||
3622 | u32 reg = 0; | ||
3623 | |||
3624 | for (i = 0; i < MAX_TRAFFIC_CLASS; i++) { | ||
3625 | u8 msb = 0; | ||
3626 | u8 cnt = adapter->netdev->tc_to_txq[i].count; | ||
3627 | |||
3628 | while (cnt >>= 1) | ||
3629 | msb++; | ||
3630 | |||
3631 | reg |= msb << IXGBE_RQTC_SHIFT_TC(i); | ||
3632 | } | ||
3633 | IXGBE_WRITE_REG(hw, IXGBE_RQTC, reg); | ||
3634 | } | ||
3635 | } | ||
3636 | |||
3637 | #endif | ||
3638 | |||
3639 | static void ixgbe_configure_pb(struct ixgbe_adapter *adapter) | ||
3640 | { | ||
3641 | int hdrm = 0; | ||
3642 | int num_tc = netdev_get_num_tc(adapter->netdev); | ||
3643 | struct ixgbe_hw *hw = &adapter->hw; | ||
3644 | |||
3645 | if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE || | ||
3646 | adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) | ||
3647 | hdrm = 64 << adapter->fdir_pballoc; | ||
3648 | |||
3649 | hw->mac.ops.set_rxpba(&adapter->hw, num_tc, hdrm, PBA_STRATEGY_EQUAL); | ||
3650 | } | ||
3651 | |||
3652 | static void ixgbe_fdir_filter_restore(struct ixgbe_adapter *adapter) | ||
3653 | { | ||
3654 | struct ixgbe_hw *hw = &adapter->hw; | ||
3655 | struct hlist_node *node, *node2; | ||
3656 | struct ixgbe_fdir_filter *filter; | ||
3657 | |||
3658 | spin_lock(&adapter->fdir_perfect_lock); | ||
3659 | |||
3660 | if (!hlist_empty(&adapter->fdir_filter_list)) | ||
3661 | ixgbe_fdir_set_input_mask_82599(hw, &adapter->fdir_mask); | ||
3662 | |||
3663 | hlist_for_each_entry_safe(filter, node, node2, | ||
3664 | &adapter->fdir_filter_list, fdir_node) { | ||
3665 | ixgbe_fdir_write_perfect_filter_82599(hw, | ||
3666 | &filter->filter, | ||
3667 | filter->sw_idx, | ||
3668 | (filter->action == IXGBE_FDIR_DROP_QUEUE) ? | ||
3669 | IXGBE_FDIR_DROP_QUEUE : | ||
3670 | adapter->rx_ring[filter->action]->reg_idx); | ||
3671 | } | ||
3672 | |||
3673 | spin_unlock(&adapter->fdir_perfect_lock); | ||
3674 | } | ||
3675 | |||
3676 | static void ixgbe_configure(struct ixgbe_adapter *adapter) | ||
3677 | { | ||
3678 | struct net_device *netdev = adapter->netdev; | ||
3679 | struct ixgbe_hw *hw = &adapter->hw; | ||
3680 | int i; | ||
3681 | |||
3682 | ixgbe_configure_pb(adapter); | ||
3683 | #ifdef CONFIG_IXGBE_DCB | ||
3684 | ixgbe_configure_dcb(adapter); | ||
3685 | #endif | ||
3686 | |||
3687 | ixgbe_set_rx_mode(netdev); | ||
3688 | ixgbe_restore_vlan(adapter); | ||
3689 | |||
3690 | #ifdef IXGBE_FCOE | ||
3691 | if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) | ||
3692 | ixgbe_configure_fcoe(adapter); | ||
3693 | |||
3694 | #endif /* IXGBE_FCOE */ | ||
3695 | if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) { | ||
3696 | for (i = 0; i < adapter->num_tx_queues; i++) | ||
3697 | adapter->tx_ring[i]->atr_sample_rate = | ||
3698 | adapter->atr_sample_rate; | ||
3699 | ixgbe_init_fdir_signature_82599(hw, adapter->fdir_pballoc); | ||
3700 | } else if (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) { | ||
3701 | ixgbe_init_fdir_perfect_82599(&adapter->hw, | ||
3702 | adapter->fdir_pballoc); | ||
3703 | ixgbe_fdir_filter_restore(adapter); | ||
3704 | } | ||
3705 | ixgbe_configure_virtualization(adapter); | ||
3706 | |||
3707 | ixgbe_configure_tx(adapter); | ||
3708 | ixgbe_configure_rx(adapter); | ||
3709 | } | ||
3710 | |||
3711 | static inline bool ixgbe_is_sfp(struct ixgbe_hw *hw) | ||
3712 | { | ||
3713 | switch (hw->phy.type) { | ||
3714 | case ixgbe_phy_sfp_avago: | ||
3715 | case ixgbe_phy_sfp_ftl: | ||
3716 | case ixgbe_phy_sfp_intel: | ||
3717 | case ixgbe_phy_sfp_unknown: | ||
3718 | case ixgbe_phy_sfp_passive_tyco: | ||
3719 | case ixgbe_phy_sfp_passive_unknown: | ||
3720 | case ixgbe_phy_sfp_active_unknown: | ||
3721 | case ixgbe_phy_sfp_ftl_active: | ||
3722 | return true; | ||
3723 | default: | ||
3724 | return false; | ||
3725 | } | ||
3726 | } | ||
3727 | |||
3728 | /** | ||
3729 | * ixgbe_sfp_link_config - set up SFP+ link | ||
3730 | * @adapter: pointer to private adapter struct | ||
3731 | **/ | ||
3732 | static void ixgbe_sfp_link_config(struct ixgbe_adapter *adapter) | ||
3733 | { | ||
3734 | /* | ||
3735 | * We are assuming the worst case scenerio here, and that | ||
3736 | * is that an SFP was inserted/removed after the reset | ||
3737 | * but before SFP detection was enabled. As such the best | ||
3738 | * solution is to just start searching as soon as we start | ||
3739 | */ | ||
3740 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) | ||
3741 | adapter->flags2 |= IXGBE_FLAG2_SEARCH_FOR_SFP; | ||
3742 | |||
3743 | adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET; | ||
3744 | } | ||
3745 | |||
3746 | /** | ||
3747 | * ixgbe_non_sfp_link_config - set up non-SFP+ link | ||
3748 | * @hw: pointer to private hardware struct | ||
3749 | * | ||
3750 | * Returns 0 on success, negative on failure | ||
3751 | **/ | ||
3752 | static int ixgbe_non_sfp_link_config(struct ixgbe_hw *hw) | ||
3753 | { | ||
3754 | u32 autoneg; | ||
3755 | bool negotiation, link_up = false; | ||
3756 | u32 ret = IXGBE_ERR_LINK_SETUP; | ||
3757 | |||
3758 | if (hw->mac.ops.check_link) | ||
3759 | ret = hw->mac.ops.check_link(hw, &autoneg, &link_up, false); | ||
3760 | |||
3761 | if (ret) | ||
3762 | goto link_cfg_out; | ||
3763 | |||
3764 | autoneg = hw->phy.autoneg_advertised; | ||
3765 | if ((!autoneg) && (hw->mac.ops.get_link_capabilities)) | ||
3766 | ret = hw->mac.ops.get_link_capabilities(hw, &autoneg, | ||
3767 | &negotiation); | ||
3768 | if (ret) | ||
3769 | goto link_cfg_out; | ||
3770 | |||
3771 | if (hw->mac.ops.setup_link) | ||
3772 | ret = hw->mac.ops.setup_link(hw, autoneg, negotiation, link_up); | ||
3773 | link_cfg_out: | ||
3774 | return ret; | ||
3775 | } | ||
3776 | |||
3777 | static void ixgbe_setup_gpie(struct ixgbe_adapter *adapter) | ||
3778 | { | ||
3779 | struct ixgbe_hw *hw = &adapter->hw; | ||
3780 | u32 gpie = 0; | ||
3781 | |||
3782 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { | ||
3783 | gpie = IXGBE_GPIE_MSIX_MODE | IXGBE_GPIE_PBA_SUPPORT | | ||
3784 | IXGBE_GPIE_OCD; | ||
3785 | gpie |= IXGBE_GPIE_EIAME; | ||
3786 | /* | ||
3787 | * use EIAM to auto-mask when MSI-X interrupt is asserted | ||
3788 | * this saves a register write for every interrupt | ||
3789 | */ | ||
3790 | switch (hw->mac.type) { | ||
3791 | case ixgbe_mac_82598EB: | ||
3792 | IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE); | ||
3793 | break; | ||
3794 | case ixgbe_mac_82599EB: | ||
3795 | case ixgbe_mac_X540: | ||
3796 | default: | ||
3797 | IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(0), 0xFFFFFFFF); | ||
3798 | IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(1), 0xFFFFFFFF); | ||
3799 | break; | ||
3800 | } | ||
3801 | } else { | ||
3802 | /* legacy interrupts, use EIAM to auto-mask when reading EICR, | ||
3803 | * specifically only auto mask tx and rx interrupts */ | ||
3804 | IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE); | ||
3805 | } | ||
3806 | |||
3807 | /* XXX: to interrupt immediately for EICS writes, enable this */ | ||
3808 | /* gpie |= IXGBE_GPIE_EIMEN; */ | ||
3809 | |||
3810 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) { | ||
3811 | gpie &= ~IXGBE_GPIE_VTMODE_MASK; | ||
3812 | gpie |= IXGBE_GPIE_VTMODE_64; | ||
3813 | } | ||
3814 | |||
3815 | /* Enable fan failure interrupt */ | ||
3816 | if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) | ||
3817 | gpie |= IXGBE_SDP1_GPIEN; | ||
3818 | |||
3819 | if (hw->mac.type == ixgbe_mac_82599EB) { | ||
3820 | gpie |= IXGBE_SDP1_GPIEN; | ||
3821 | gpie |= IXGBE_SDP2_GPIEN; | ||
3822 | } | ||
3823 | |||
3824 | IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie); | ||
3825 | } | ||
3826 | |||
3827 | static int ixgbe_up_complete(struct ixgbe_adapter *adapter) | ||
3828 | { | ||
3829 | struct ixgbe_hw *hw = &adapter->hw; | ||
3830 | int err; | ||
3831 | u32 ctrl_ext; | ||
3832 | |||
3833 | ixgbe_get_hw_control(adapter); | ||
3834 | ixgbe_setup_gpie(adapter); | ||
3835 | |||
3836 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) | ||
3837 | ixgbe_configure_msix(adapter); | ||
3838 | else | ||
3839 | ixgbe_configure_msi_and_legacy(adapter); | ||
3840 | |||
3841 | /* enable the optics for both mult-speed fiber and 82599 SFP+ fiber */ | ||
3842 | if (hw->mac.ops.enable_tx_laser && | ||
3843 | ((hw->phy.multispeed_fiber) || | ||
3844 | ((hw->mac.ops.get_media_type(hw) == ixgbe_media_type_fiber) && | ||
3845 | (hw->mac.type == ixgbe_mac_82599EB)))) | ||
3846 | hw->mac.ops.enable_tx_laser(hw); | ||
3847 | |||
3848 | clear_bit(__IXGBE_DOWN, &adapter->state); | ||
3849 | ixgbe_napi_enable_all(adapter); | ||
3850 | |||
3851 | if (ixgbe_is_sfp(hw)) { | ||
3852 | ixgbe_sfp_link_config(adapter); | ||
3853 | } else { | ||
3854 | err = ixgbe_non_sfp_link_config(hw); | ||
3855 | if (err) | ||
3856 | e_err(probe, "link_config FAILED %d\n", err); | ||
3857 | } | ||
3858 | |||
3859 | /* clear any pending interrupts, may auto mask */ | ||
3860 | IXGBE_READ_REG(hw, IXGBE_EICR); | ||
3861 | ixgbe_irq_enable(adapter, true, true); | ||
3862 | |||
3863 | /* | ||
3864 | * If this adapter has a fan, check to see if we had a failure | ||
3865 | * before we enabled the interrupt. | ||
3866 | */ | ||
3867 | if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) { | ||
3868 | u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP); | ||
3869 | if (esdp & IXGBE_ESDP_SDP1) | ||
3870 | e_crit(drv, "Fan has stopped, replace the adapter\n"); | ||
3871 | } | ||
3872 | |||
3873 | /* enable transmits */ | ||
3874 | netif_tx_start_all_queues(adapter->netdev); | ||
3875 | |||
3876 | /* bring the link up in the watchdog, this could race with our first | ||
3877 | * link up interrupt but shouldn't be a problem */ | ||
3878 | adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE; | ||
3879 | adapter->link_check_timeout = jiffies; | ||
3880 | mod_timer(&adapter->service_timer, jiffies); | ||
3881 | |||
3882 | /* Set PF Reset Done bit so PF/VF Mail Ops can work */ | ||
3883 | ctrl_ext = IXGBE_READ_REG(hw, IXGBE_CTRL_EXT); | ||
3884 | ctrl_ext |= IXGBE_CTRL_EXT_PFRSTD; | ||
3885 | IXGBE_WRITE_REG(hw, IXGBE_CTRL_EXT, ctrl_ext); | ||
3886 | |||
3887 | return 0; | ||
3888 | } | ||
3889 | |||
3890 | void ixgbe_reinit_locked(struct ixgbe_adapter *adapter) | ||
3891 | { | ||
3892 | WARN_ON(in_interrupt()); | ||
3893 | /* put off any impending NetWatchDogTimeout */ | ||
3894 | adapter->netdev->trans_start = jiffies; | ||
3895 | |||
3896 | while (test_and_set_bit(__IXGBE_RESETTING, &adapter->state)) | ||
3897 | usleep_range(1000, 2000); | ||
3898 | ixgbe_down(adapter); | ||
3899 | /* | ||
3900 | * If SR-IOV enabled then wait a bit before bringing the adapter | ||
3901 | * back up to give the VFs time to respond to the reset. The | ||
3902 | * two second wait is based upon the watchdog timer cycle in | ||
3903 | * the VF driver. | ||
3904 | */ | ||
3905 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) | ||
3906 | msleep(2000); | ||
3907 | ixgbe_up(adapter); | ||
3908 | clear_bit(__IXGBE_RESETTING, &adapter->state); | ||
3909 | } | ||
3910 | |||
3911 | int ixgbe_up(struct ixgbe_adapter *adapter) | ||
3912 | { | ||
3913 | /* hardware has been reset, we need to reload some things */ | ||
3914 | ixgbe_configure(adapter); | ||
3915 | |||
3916 | return ixgbe_up_complete(adapter); | ||
3917 | } | ||
3918 | |||
3919 | void ixgbe_reset(struct ixgbe_adapter *adapter) | ||
3920 | { | ||
3921 | struct ixgbe_hw *hw = &adapter->hw; | ||
3922 | int err; | ||
3923 | |||
3924 | /* lock SFP init bit to prevent race conditions with the watchdog */ | ||
3925 | while (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state)) | ||
3926 | usleep_range(1000, 2000); | ||
3927 | |||
3928 | /* clear all SFP and link config related flags while holding SFP_INIT */ | ||
3929 | adapter->flags2 &= ~(IXGBE_FLAG2_SEARCH_FOR_SFP | | ||
3930 | IXGBE_FLAG2_SFP_NEEDS_RESET); | ||
3931 | adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG; | ||
3932 | |||
3933 | err = hw->mac.ops.init_hw(hw); | ||
3934 | switch (err) { | ||
3935 | case 0: | ||
3936 | case IXGBE_ERR_SFP_NOT_PRESENT: | ||
3937 | case IXGBE_ERR_SFP_NOT_SUPPORTED: | ||
3938 | break; | ||
3939 | case IXGBE_ERR_MASTER_REQUESTS_PENDING: | ||
3940 | e_dev_err("master disable timed out\n"); | ||
3941 | break; | ||
3942 | case IXGBE_ERR_EEPROM_VERSION: | ||
3943 | /* We are running on a pre-production device, log a warning */ | ||
3944 | e_dev_warn("This device is a pre-production adapter/LOM. " | ||
3945 | "Please be aware there may be issuesassociated with " | ||
3946 | "your hardware. If you are experiencing problems " | ||
3947 | "please contact your Intel or hardware " | ||
3948 | "representative who provided you with this " | ||
3949 | "hardware.\n"); | ||
3950 | break; | ||
3951 | default: | ||
3952 | e_dev_err("Hardware Error: %d\n", err); | ||
3953 | } | ||
3954 | |||
3955 | clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state); | ||
3956 | |||
3957 | /* reprogram the RAR[0] in case user changed it. */ | ||
3958 | hw->mac.ops.set_rar(hw, 0, hw->mac.addr, adapter->num_vfs, | ||
3959 | IXGBE_RAH_AV); | ||
3960 | } | ||
3961 | |||
3962 | /** | ||
3963 | * ixgbe_clean_rx_ring - Free Rx Buffers per Queue | ||
3964 | * @rx_ring: ring to free buffers from | ||
3965 | **/ | ||
3966 | static void ixgbe_clean_rx_ring(struct ixgbe_ring *rx_ring) | ||
3967 | { | ||
3968 | struct device *dev = rx_ring->dev; | ||
3969 | unsigned long size; | ||
3970 | u16 i; | ||
3971 | |||
3972 | /* ring already cleared, nothing to do */ | ||
3973 | if (!rx_ring->rx_buffer_info) | ||
3974 | return; | ||
3975 | |||
3976 | /* Free all the Rx ring sk_buffs */ | ||
3977 | for (i = 0; i < rx_ring->count; i++) { | ||
3978 | struct ixgbe_rx_buffer *rx_buffer_info; | ||
3979 | |||
3980 | rx_buffer_info = &rx_ring->rx_buffer_info[i]; | ||
3981 | if (rx_buffer_info->dma) { | ||
3982 | dma_unmap_single(rx_ring->dev, rx_buffer_info->dma, | ||
3983 | rx_ring->rx_buf_len, | ||
3984 | DMA_FROM_DEVICE); | ||
3985 | rx_buffer_info->dma = 0; | ||
3986 | } | ||
3987 | if (rx_buffer_info->skb) { | ||
3988 | struct sk_buff *skb = rx_buffer_info->skb; | ||
3989 | rx_buffer_info->skb = NULL; | ||
3990 | do { | ||
3991 | struct sk_buff *this = skb; | ||
3992 | if (IXGBE_RSC_CB(this)->delay_unmap) { | ||
3993 | dma_unmap_single(dev, | ||
3994 | IXGBE_RSC_CB(this)->dma, | ||
3995 | rx_ring->rx_buf_len, | ||
3996 | DMA_FROM_DEVICE); | ||
3997 | IXGBE_RSC_CB(this)->dma = 0; | ||
3998 | IXGBE_RSC_CB(skb)->delay_unmap = false; | ||
3999 | } | ||
4000 | skb = skb->prev; | ||
4001 | dev_kfree_skb(this); | ||
4002 | } while (skb); | ||
4003 | } | ||
4004 | if (!rx_buffer_info->page) | ||
4005 | continue; | ||
4006 | if (rx_buffer_info->page_dma) { | ||
4007 | dma_unmap_page(dev, rx_buffer_info->page_dma, | ||
4008 | PAGE_SIZE / 2, DMA_FROM_DEVICE); | ||
4009 | rx_buffer_info->page_dma = 0; | ||
4010 | } | ||
4011 | put_page(rx_buffer_info->page); | ||
4012 | rx_buffer_info->page = NULL; | ||
4013 | rx_buffer_info->page_offset = 0; | ||
4014 | } | ||
4015 | |||
4016 | size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count; | ||
4017 | memset(rx_ring->rx_buffer_info, 0, size); | ||
4018 | |||
4019 | /* Zero out the descriptor ring */ | ||
4020 | memset(rx_ring->desc, 0, rx_ring->size); | ||
4021 | |||
4022 | rx_ring->next_to_clean = 0; | ||
4023 | rx_ring->next_to_use = 0; | ||
4024 | } | ||
4025 | |||
4026 | /** | ||
4027 | * ixgbe_clean_tx_ring - Free Tx Buffers | ||
4028 | * @tx_ring: ring to be cleaned | ||
4029 | **/ | ||
4030 | static void ixgbe_clean_tx_ring(struct ixgbe_ring *tx_ring) | ||
4031 | { | ||
4032 | struct ixgbe_tx_buffer *tx_buffer_info; | ||
4033 | unsigned long size; | ||
4034 | u16 i; | ||
4035 | |||
4036 | /* ring already cleared, nothing to do */ | ||
4037 | if (!tx_ring->tx_buffer_info) | ||
4038 | return; | ||
4039 | |||
4040 | /* Free all the Tx ring sk_buffs */ | ||
4041 | for (i = 0; i < tx_ring->count; i++) { | ||
4042 | tx_buffer_info = &tx_ring->tx_buffer_info[i]; | ||
4043 | ixgbe_unmap_and_free_tx_resource(tx_ring, tx_buffer_info); | ||
4044 | } | ||
4045 | |||
4046 | size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count; | ||
4047 | memset(tx_ring->tx_buffer_info, 0, size); | ||
4048 | |||
4049 | /* Zero out the descriptor ring */ | ||
4050 | memset(tx_ring->desc, 0, tx_ring->size); | ||
4051 | |||
4052 | tx_ring->next_to_use = 0; | ||
4053 | tx_ring->next_to_clean = 0; | ||
4054 | } | ||
4055 | |||
4056 | /** | ||
4057 | * ixgbe_clean_all_rx_rings - Free Rx Buffers for all queues | ||
4058 | * @adapter: board private structure | ||
4059 | **/ | ||
4060 | static void ixgbe_clean_all_rx_rings(struct ixgbe_adapter *adapter) | ||
4061 | { | ||
4062 | int i; | ||
4063 | |||
4064 | for (i = 0; i < adapter->num_rx_queues; i++) | ||
4065 | ixgbe_clean_rx_ring(adapter->rx_ring[i]); | ||
4066 | } | ||
4067 | |||
4068 | /** | ||
4069 | * ixgbe_clean_all_tx_rings - Free Tx Buffers for all queues | ||
4070 | * @adapter: board private structure | ||
4071 | **/ | ||
4072 | static void ixgbe_clean_all_tx_rings(struct ixgbe_adapter *adapter) | ||
4073 | { | ||
4074 | int i; | ||
4075 | |||
4076 | for (i = 0; i < adapter->num_tx_queues; i++) | ||
4077 | ixgbe_clean_tx_ring(adapter->tx_ring[i]); | ||
4078 | } | ||
4079 | |||
4080 | static void ixgbe_fdir_filter_exit(struct ixgbe_adapter *adapter) | ||
4081 | { | ||
4082 | struct hlist_node *node, *node2; | ||
4083 | struct ixgbe_fdir_filter *filter; | ||
4084 | |||
4085 | spin_lock(&adapter->fdir_perfect_lock); | ||
4086 | |||
4087 | hlist_for_each_entry_safe(filter, node, node2, | ||
4088 | &adapter->fdir_filter_list, fdir_node) { | ||
4089 | hlist_del(&filter->fdir_node); | ||
4090 | kfree(filter); | ||
4091 | } | ||
4092 | adapter->fdir_filter_count = 0; | ||
4093 | |||
4094 | spin_unlock(&adapter->fdir_perfect_lock); | ||
4095 | } | ||
4096 | |||
4097 | void ixgbe_down(struct ixgbe_adapter *adapter) | ||
4098 | { | ||
4099 | struct net_device *netdev = adapter->netdev; | ||
4100 | struct ixgbe_hw *hw = &adapter->hw; | ||
4101 | u32 rxctrl; | ||
4102 | int i; | ||
4103 | int num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; | ||
4104 | |||
4105 | /* signal that we are down to the interrupt handler */ | ||
4106 | set_bit(__IXGBE_DOWN, &adapter->state); | ||
4107 | |||
4108 | /* disable receives */ | ||
4109 | rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL); | ||
4110 | IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN); | ||
4111 | |||
4112 | /* disable all enabled rx queues */ | ||
4113 | for (i = 0; i < adapter->num_rx_queues; i++) | ||
4114 | /* this call also flushes the previous write */ | ||
4115 | ixgbe_disable_rx_queue(adapter, adapter->rx_ring[i]); | ||
4116 | |||
4117 | usleep_range(10000, 20000); | ||
4118 | |||
4119 | netif_tx_stop_all_queues(netdev); | ||
4120 | |||
4121 | /* call carrier off first to avoid false dev_watchdog timeouts */ | ||
4122 | netif_carrier_off(netdev); | ||
4123 | netif_tx_disable(netdev); | ||
4124 | |||
4125 | ixgbe_irq_disable(adapter); | ||
4126 | |||
4127 | ixgbe_napi_disable_all(adapter); | ||
4128 | |||
4129 | adapter->flags2 &= ~(IXGBE_FLAG2_FDIR_REQUIRES_REINIT | | ||
4130 | IXGBE_FLAG2_RESET_REQUESTED); | ||
4131 | adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE; | ||
4132 | |||
4133 | del_timer_sync(&adapter->service_timer); | ||
4134 | |||
4135 | /* disable receive for all VFs and wait one second */ | ||
4136 | if (adapter->num_vfs) { | ||
4137 | /* ping all the active vfs to let them know we are going down */ | ||
4138 | ixgbe_ping_all_vfs(adapter); | ||
4139 | |||
4140 | /* Disable all VFTE/VFRE TX/RX */ | ||
4141 | ixgbe_disable_tx_rx(adapter); | ||
4142 | |||
4143 | /* Mark all the VFs as inactive */ | ||
4144 | for (i = 0 ; i < adapter->num_vfs; i++) | ||
4145 | adapter->vfinfo[i].clear_to_send = 0; | ||
4146 | } | ||
4147 | |||
4148 | /* Cleanup the affinity_hint CPU mask memory and callback */ | ||
4149 | for (i = 0; i < num_q_vectors; i++) { | ||
4150 | struct ixgbe_q_vector *q_vector = adapter->q_vector[i]; | ||
4151 | /* clear the affinity_mask in the IRQ descriptor */ | ||
4152 | irq_set_affinity_hint(adapter->msix_entries[i]. vector, NULL); | ||
4153 | /* release the CPU mask memory */ | ||
4154 | free_cpumask_var(q_vector->affinity_mask); | ||
4155 | } | ||
4156 | |||
4157 | /* disable transmits in the hardware now that interrupts are off */ | ||
4158 | for (i = 0; i < adapter->num_tx_queues; i++) { | ||
4159 | u8 reg_idx = adapter->tx_ring[i]->reg_idx; | ||
4160 | IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), IXGBE_TXDCTL_SWFLSH); | ||
4161 | } | ||
4162 | |||
4163 | /* Disable the Tx DMA engine on 82599 and X540 */ | ||
4164 | switch (hw->mac.type) { | ||
4165 | case ixgbe_mac_82599EB: | ||
4166 | case ixgbe_mac_X540: | ||
4167 | IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, | ||
4168 | (IXGBE_READ_REG(hw, IXGBE_DMATXCTL) & | ||
4169 | ~IXGBE_DMATXCTL_TE)); | ||
4170 | break; | ||
4171 | default: | ||
4172 | break; | ||
4173 | } | ||
4174 | |||
4175 | if (!pci_channel_offline(adapter->pdev)) | ||
4176 | ixgbe_reset(adapter); | ||
4177 | |||
4178 | /* power down the optics for multispeed fiber and 82599 SFP+ fiber */ | ||
4179 | if (hw->mac.ops.disable_tx_laser && | ||
4180 | ((hw->phy.multispeed_fiber) || | ||
4181 | ((hw->mac.ops.get_media_type(hw) == ixgbe_media_type_fiber) && | ||
4182 | (hw->mac.type == ixgbe_mac_82599EB)))) | ||
4183 | hw->mac.ops.disable_tx_laser(hw); | ||
4184 | |||
4185 | ixgbe_clean_all_tx_rings(adapter); | ||
4186 | ixgbe_clean_all_rx_rings(adapter); | ||
4187 | |||
4188 | #ifdef CONFIG_IXGBE_DCA | ||
4189 | /* since we reset the hardware DCA settings were cleared */ | ||
4190 | ixgbe_setup_dca(adapter); | ||
4191 | #endif | ||
4192 | } | ||
4193 | |||
4194 | /** | ||
4195 | * ixgbe_poll - NAPI Rx polling callback | ||
4196 | * @napi: structure for representing this polling device | ||
4197 | * @budget: how many packets driver is allowed to clean | ||
4198 | * | ||
4199 | * This function is used for legacy and MSI, NAPI mode | ||
4200 | **/ | ||
4201 | static int ixgbe_poll(struct napi_struct *napi, int budget) | ||
4202 | { | ||
4203 | struct ixgbe_q_vector *q_vector = | ||
4204 | container_of(napi, struct ixgbe_q_vector, napi); | ||
4205 | struct ixgbe_adapter *adapter = q_vector->adapter; | ||
4206 | int tx_clean_complete, work_done = 0; | ||
4207 | |||
4208 | #ifdef CONFIG_IXGBE_DCA | ||
4209 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) | ||
4210 | ixgbe_update_dca(q_vector); | ||
4211 | #endif | ||
4212 | |||
4213 | tx_clean_complete = ixgbe_clean_tx_irq(q_vector, adapter->tx_ring[0]); | ||
4214 | ixgbe_clean_rx_irq(q_vector, adapter->rx_ring[0], &work_done, budget); | ||
4215 | |||
4216 | if (!tx_clean_complete) | ||
4217 | work_done = budget; | ||
4218 | |||
4219 | /* If budget not fully consumed, exit the polling mode */ | ||
4220 | if (work_done < budget) { | ||
4221 | napi_complete(napi); | ||
4222 | if (adapter->rx_itr_setting & 1) | ||
4223 | ixgbe_set_itr(q_vector); | ||
4224 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) | ||
4225 | ixgbe_irq_enable_queues(adapter, IXGBE_EIMS_RTX_QUEUE); | ||
4226 | } | ||
4227 | return work_done; | ||
4228 | } | ||
4229 | |||
4230 | /** | ||
4231 | * ixgbe_tx_timeout - Respond to a Tx Hang | ||
4232 | * @netdev: network interface device structure | ||
4233 | **/ | ||
4234 | static void ixgbe_tx_timeout(struct net_device *netdev) | ||
4235 | { | ||
4236 | struct ixgbe_adapter *adapter = netdev_priv(netdev); | ||
4237 | |||
4238 | /* Do the reset outside of interrupt context */ | ||
4239 | ixgbe_tx_timeout_reset(adapter); | ||
4240 | } | ||
4241 | |||
4242 | /** | ||
4243 | * ixgbe_set_rss_queues: Allocate queues for RSS | ||
4244 | * @adapter: board private structure to initialize | ||
4245 | * | ||
4246 | * This is our "base" multiqueue mode. RSS (Receive Side Scaling) will try | ||
4247 | * to allocate one Rx queue per CPU, and if available, one Tx queue per CPU. | ||
4248 | * | ||
4249 | **/ | ||
4250 | static inline bool ixgbe_set_rss_queues(struct ixgbe_adapter *adapter) | ||
4251 | { | ||
4252 | bool ret = false; | ||
4253 | struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_RSS]; | ||
4254 | |||
4255 | if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) { | ||
4256 | f->mask = 0xF; | ||
4257 | adapter->num_rx_queues = f->indices; | ||
4258 | adapter->num_tx_queues = f->indices; | ||
4259 | ret = true; | ||
4260 | } else { | ||
4261 | ret = false; | ||
4262 | } | ||
4263 | |||
4264 | return ret; | ||
4265 | } | ||
4266 | |||
4267 | /** | ||
4268 | * ixgbe_set_fdir_queues: Allocate queues for Flow Director | ||
4269 | * @adapter: board private structure to initialize | ||
4270 | * | ||
4271 | * Flow Director is an advanced Rx filter, attempting to get Rx flows back | ||
4272 | * to the original CPU that initiated the Tx session. This runs in addition | ||
4273 | * to RSS, so if a packet doesn't match an FDIR filter, we can still spread the | ||
4274 | * Rx load across CPUs using RSS. | ||
4275 | * | ||
4276 | **/ | ||
4277 | static inline bool ixgbe_set_fdir_queues(struct ixgbe_adapter *adapter) | ||
4278 | { | ||
4279 | bool ret = false; | ||
4280 | struct ixgbe_ring_feature *f_fdir = &adapter->ring_feature[RING_F_FDIR]; | ||
4281 | |||
4282 | f_fdir->indices = min((int)num_online_cpus(), f_fdir->indices); | ||
4283 | f_fdir->mask = 0; | ||
4284 | |||
4285 | /* Flow Director must have RSS enabled */ | ||
4286 | if ((adapter->flags & IXGBE_FLAG_RSS_ENABLED) && | ||
4287 | (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE)) { | ||
4288 | adapter->num_tx_queues = f_fdir->indices; | ||
4289 | adapter->num_rx_queues = f_fdir->indices; | ||
4290 | ret = true; | ||
4291 | } else { | ||
4292 | adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE; | ||
4293 | } | ||
4294 | return ret; | ||
4295 | } | ||
4296 | |||
4297 | #ifdef IXGBE_FCOE | ||
4298 | /** | ||
4299 | * ixgbe_set_fcoe_queues: Allocate queues for Fiber Channel over Ethernet (FCoE) | ||
4300 | * @adapter: board private structure to initialize | ||
4301 | * | ||
4302 | * FCoE RX FCRETA can use up to 8 rx queues for up to 8 different exchanges. | ||
4303 | * The ring feature mask is not used as a mask for FCoE, as it can take any 8 | ||
4304 | * rx queues out of the max number of rx queues, instead, it is used as the | ||
4305 | * index of the first rx queue used by FCoE. | ||
4306 | * | ||
4307 | **/ | ||
4308 | static inline bool ixgbe_set_fcoe_queues(struct ixgbe_adapter *adapter) | ||
4309 | { | ||
4310 | struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_FCOE]; | ||
4311 | |||
4312 | if (!(adapter->flags & IXGBE_FLAG_FCOE_ENABLED)) | ||
4313 | return false; | ||
4314 | |||
4315 | f->indices = min((int)num_online_cpus(), f->indices); | ||
4316 | |||
4317 | adapter->num_rx_queues = 1; | ||
4318 | adapter->num_tx_queues = 1; | ||
4319 | |||
4320 | if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) { | ||
4321 | e_info(probe, "FCoE enabled with RSS\n"); | ||
4322 | if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) | ||
4323 | ixgbe_set_fdir_queues(adapter); | ||
4324 | else | ||
4325 | ixgbe_set_rss_queues(adapter); | ||
4326 | } | ||
4327 | |||
4328 | /* adding FCoE rx rings to the end */ | ||
4329 | f->mask = adapter->num_rx_queues; | ||
4330 | adapter->num_rx_queues += f->indices; | ||
4331 | adapter->num_tx_queues += f->indices; | ||
4332 | |||
4333 | return true; | ||
4334 | } | ||
4335 | #endif /* IXGBE_FCOE */ | ||
4336 | |||
4337 | /* Artificial max queue cap per traffic class in DCB mode */ | ||
4338 | #define DCB_QUEUE_CAP 8 | ||
4339 | |||
4340 | #ifdef CONFIG_IXGBE_DCB | ||
4341 | static inline bool ixgbe_set_dcb_queues(struct ixgbe_adapter *adapter) | ||
4342 | { | ||
4343 | int per_tc_q, q, i, offset = 0; | ||
4344 | struct net_device *dev = adapter->netdev; | ||
4345 | int tcs = netdev_get_num_tc(dev); | ||
4346 | |||
4347 | if (!tcs) | ||
4348 | return false; | ||
4349 | |||
4350 | /* Map queue offset and counts onto allocated tx queues */ | ||
4351 | per_tc_q = min(dev->num_tx_queues / tcs, (unsigned int)DCB_QUEUE_CAP); | ||
4352 | q = min((int)num_online_cpus(), per_tc_q); | ||
4353 | |||
4354 | for (i = 0; i < tcs; i++) { | ||
4355 | netdev_set_prio_tc_map(dev, i, i); | ||
4356 | netdev_set_tc_queue(dev, i, q, offset); | ||
4357 | offset += q; | ||
4358 | } | ||
4359 | |||
4360 | adapter->num_tx_queues = q * tcs; | ||
4361 | adapter->num_rx_queues = q * tcs; | ||
4362 | |||
4363 | #ifdef IXGBE_FCOE | ||
4364 | /* FCoE enabled queues require special configuration indexed | ||
4365 | * by feature specific indices and mask. Here we map FCoE | ||
4366 | * indices onto the DCB queue pairs allowing FCoE to own | ||
4367 | * configuration later. | ||
4368 | */ | ||
4369 | if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) { | ||
4370 | int tc; | ||
4371 | struct ixgbe_ring_feature *f = | ||
4372 | &adapter->ring_feature[RING_F_FCOE]; | ||
4373 | |||
4374 | tc = netdev_get_prio_tc_map(dev, adapter->fcoe.up); | ||
4375 | f->indices = dev->tc_to_txq[tc].count; | ||
4376 | f->mask = dev->tc_to_txq[tc].offset; | ||
4377 | } | ||
4378 | #endif | ||
4379 | |||
4380 | return true; | ||
4381 | } | ||
4382 | #endif | ||
4383 | |||
4384 | /** | ||
4385 | * ixgbe_set_sriov_queues: Allocate queues for IOV use | ||
4386 | * @adapter: board private structure to initialize | ||
4387 | * | ||
4388 | * IOV doesn't actually use anything, so just NAK the | ||
4389 | * request for now and let the other queue routines | ||
4390 | * figure out what to do. | ||
4391 | */ | ||
4392 | static inline bool ixgbe_set_sriov_queues(struct ixgbe_adapter *adapter) | ||
4393 | { | ||
4394 | return false; | ||
4395 | } | ||
4396 | |||
4397 | /* | ||
4398 | * ixgbe_set_num_queues: Allocate queues for device, feature dependent | ||
4399 | * @adapter: board private structure to initialize | ||
4400 | * | ||
4401 | * This is the top level queue allocation routine. The order here is very | ||
4402 | * important, starting with the "most" number of features turned on at once, | ||
4403 | * and ending with the smallest set of features. This way large combinations | ||
4404 | * can be allocated if they're turned on, and smaller combinations are the | ||
4405 | * fallthrough conditions. | ||
4406 | * | ||
4407 | **/ | ||
4408 | static int ixgbe_set_num_queues(struct ixgbe_adapter *adapter) | ||
4409 | { | ||
4410 | /* Start with base case */ | ||
4411 | adapter->num_rx_queues = 1; | ||
4412 | adapter->num_tx_queues = 1; | ||
4413 | adapter->num_rx_pools = adapter->num_rx_queues; | ||
4414 | adapter->num_rx_queues_per_pool = 1; | ||
4415 | |||
4416 | if (ixgbe_set_sriov_queues(adapter)) | ||
4417 | goto done; | ||
4418 | |||
4419 | #ifdef CONFIG_IXGBE_DCB | ||
4420 | if (ixgbe_set_dcb_queues(adapter)) | ||
4421 | goto done; | ||
4422 | |||
4423 | #endif | ||
4424 | #ifdef IXGBE_FCOE | ||
4425 | if (ixgbe_set_fcoe_queues(adapter)) | ||
4426 | goto done; | ||
4427 | |||
4428 | #endif /* IXGBE_FCOE */ | ||
4429 | if (ixgbe_set_fdir_queues(adapter)) | ||
4430 | goto done; | ||
4431 | |||
4432 | if (ixgbe_set_rss_queues(adapter)) | ||
4433 | goto done; | ||
4434 | |||
4435 | /* fallback to base case */ | ||
4436 | adapter->num_rx_queues = 1; | ||
4437 | adapter->num_tx_queues = 1; | ||
4438 | |||
4439 | done: | ||
4440 | /* Notify the stack of the (possibly) reduced queue counts. */ | ||
4441 | netif_set_real_num_tx_queues(adapter->netdev, adapter->num_tx_queues); | ||
4442 | return netif_set_real_num_rx_queues(adapter->netdev, | ||
4443 | adapter->num_rx_queues); | ||
4444 | } | ||
4445 | |||
4446 | static void ixgbe_acquire_msix_vectors(struct ixgbe_adapter *adapter, | ||
4447 | int vectors) | ||
4448 | { | ||
4449 | int err, vector_threshold; | ||
4450 | |||
4451 | /* We'll want at least 3 (vector_threshold): | ||
4452 | * 1) TxQ[0] Cleanup | ||
4453 | * 2) RxQ[0] Cleanup | ||
4454 | * 3) Other (Link Status Change, etc.) | ||
4455 | * 4) TCP Timer (optional) | ||
4456 | */ | ||
4457 | vector_threshold = MIN_MSIX_COUNT; | ||
4458 | |||
4459 | /* The more we get, the more we will assign to Tx/Rx Cleanup | ||
4460 | * for the separate queues...where Rx Cleanup >= Tx Cleanup. | ||
4461 | * Right now, we simply care about how many we'll get; we'll | ||
4462 | * set them up later while requesting irq's. | ||
4463 | */ | ||
4464 | while (vectors >= vector_threshold) { | ||
4465 | err = pci_enable_msix(adapter->pdev, adapter->msix_entries, | ||
4466 | vectors); | ||
4467 | if (!err) /* Success in acquiring all requested vectors. */ | ||
4468 | break; | ||
4469 | else if (err < 0) | ||
4470 | vectors = 0; /* Nasty failure, quit now */ | ||
4471 | else /* err == number of vectors we should try again with */ | ||
4472 | vectors = err; | ||
4473 | } | ||
4474 | |||
4475 | if (vectors < vector_threshold) { | ||
4476 | /* Can't allocate enough MSI-X interrupts? Oh well. | ||
4477 | * This just means we'll go with either a single MSI | ||
4478 | * vector or fall back to legacy interrupts. | ||
4479 | */ | ||
4480 | netif_printk(adapter, hw, KERN_DEBUG, adapter->netdev, | ||
4481 | "Unable to allocate MSI-X interrupts\n"); | ||
4482 | adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED; | ||
4483 | kfree(adapter->msix_entries); | ||
4484 | adapter->msix_entries = NULL; | ||
4485 | } else { | ||
4486 | adapter->flags |= IXGBE_FLAG_MSIX_ENABLED; /* Woot! */ | ||
4487 | /* | ||
4488 | * Adjust for only the vectors we'll use, which is minimum | ||
4489 | * of max_msix_q_vectors + NON_Q_VECTORS, or the number of | ||
4490 | * vectors we were allocated. | ||
4491 | */ | ||
4492 | adapter->num_msix_vectors = min(vectors, | ||
4493 | adapter->max_msix_q_vectors + NON_Q_VECTORS); | ||
4494 | } | ||
4495 | } | ||
4496 | |||
4497 | /** | ||
4498 | * ixgbe_cache_ring_rss - Descriptor ring to register mapping for RSS | ||
4499 | * @adapter: board private structure to initialize | ||
4500 | * | ||
4501 | * Cache the descriptor ring offsets for RSS to the assigned rings. | ||
4502 | * | ||
4503 | **/ | ||
4504 | static inline bool ixgbe_cache_ring_rss(struct ixgbe_adapter *adapter) | ||
4505 | { | ||
4506 | int i; | ||
4507 | |||
4508 | if (!(adapter->flags & IXGBE_FLAG_RSS_ENABLED)) | ||
4509 | return false; | ||
4510 | |||
4511 | for (i = 0; i < adapter->num_rx_queues; i++) | ||
4512 | adapter->rx_ring[i]->reg_idx = i; | ||
4513 | for (i = 0; i < adapter->num_tx_queues; i++) | ||
4514 | adapter->tx_ring[i]->reg_idx = i; | ||
4515 | |||
4516 | return true; | ||
4517 | } | ||
4518 | |||
4519 | #ifdef CONFIG_IXGBE_DCB | ||
4520 | |||
4521 | /* ixgbe_get_first_reg_idx - Return first register index associated with ring */ | ||
4522 | static void ixgbe_get_first_reg_idx(struct ixgbe_adapter *adapter, u8 tc, | ||
4523 | unsigned int *tx, unsigned int *rx) | ||
4524 | { | ||
4525 | struct net_device *dev = adapter->netdev; | ||
4526 | struct ixgbe_hw *hw = &adapter->hw; | ||
4527 | u8 num_tcs = netdev_get_num_tc(dev); | ||
4528 | |||
4529 | *tx = 0; | ||
4530 | *rx = 0; | ||
4531 | |||
4532 | switch (hw->mac.type) { | ||
4533 | case ixgbe_mac_82598EB: | ||
4534 | *tx = tc << 2; | ||
4535 | *rx = tc << 3; | ||
4536 | break; | ||
4537 | case ixgbe_mac_82599EB: | ||
4538 | case ixgbe_mac_X540: | ||
4539 | if (num_tcs == 8) { | ||
4540 | if (tc < 3) { | ||
4541 | *tx = tc << 5; | ||
4542 | *rx = tc << 4; | ||
4543 | } else if (tc < 5) { | ||
4544 | *tx = ((tc + 2) << 4); | ||
4545 | *rx = tc << 4; | ||
4546 | } else if (tc < num_tcs) { | ||
4547 | *tx = ((tc + 8) << 3); | ||
4548 | *rx = tc << 4; | ||
4549 | } | ||
4550 | } else if (num_tcs == 4) { | ||
4551 | *rx = tc << 5; | ||
4552 | switch (tc) { | ||
4553 | case 0: | ||
4554 | *tx = 0; | ||
4555 | break; | ||
4556 | case 1: | ||
4557 | *tx = 64; | ||
4558 | break; | ||
4559 | case 2: | ||
4560 | *tx = 96; | ||
4561 | break; | ||
4562 | case 3: | ||
4563 | *tx = 112; | ||
4564 | break; | ||
4565 | default: | ||
4566 | break; | ||
4567 | } | ||
4568 | } | ||
4569 | break; | ||
4570 | default: | ||
4571 | break; | ||
4572 | } | ||
4573 | } | ||
4574 | |||
4575 | /** | ||
4576 | * ixgbe_cache_ring_dcb - Descriptor ring to register mapping for DCB | ||
4577 | * @adapter: board private structure to initialize | ||
4578 | * | ||
4579 | * Cache the descriptor ring offsets for DCB to the assigned rings. | ||
4580 | * | ||
4581 | **/ | ||
4582 | static inline bool ixgbe_cache_ring_dcb(struct ixgbe_adapter *adapter) | ||
4583 | { | ||
4584 | struct net_device *dev = adapter->netdev; | ||
4585 | int i, j, k; | ||
4586 | u8 num_tcs = netdev_get_num_tc(dev); | ||
4587 | |||
4588 | if (!num_tcs) | ||
4589 | return false; | ||
4590 | |||
4591 | for (i = 0, k = 0; i < num_tcs; i++) { | ||
4592 | unsigned int tx_s, rx_s; | ||
4593 | u16 count = dev->tc_to_txq[i].count; | ||
4594 | |||
4595 | ixgbe_get_first_reg_idx(adapter, i, &tx_s, &rx_s); | ||
4596 | for (j = 0; j < count; j++, k++) { | ||
4597 | adapter->tx_ring[k]->reg_idx = tx_s + j; | ||
4598 | adapter->rx_ring[k]->reg_idx = rx_s + j; | ||
4599 | adapter->tx_ring[k]->dcb_tc = i; | ||
4600 | adapter->rx_ring[k]->dcb_tc = i; | ||
4601 | } | ||
4602 | } | ||
4603 | |||
4604 | return true; | ||
4605 | } | ||
4606 | #endif | ||
4607 | |||
4608 | /** | ||
4609 | * ixgbe_cache_ring_fdir - Descriptor ring to register mapping for Flow Director | ||
4610 | * @adapter: board private structure to initialize | ||
4611 | * | ||
4612 | * Cache the descriptor ring offsets for Flow Director to the assigned rings. | ||
4613 | * | ||
4614 | **/ | ||
4615 | static inline bool ixgbe_cache_ring_fdir(struct ixgbe_adapter *adapter) | ||
4616 | { | ||
4617 | int i; | ||
4618 | bool ret = false; | ||
4619 | |||
4620 | if ((adapter->flags & IXGBE_FLAG_RSS_ENABLED) && | ||
4621 | (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE)) { | ||
4622 | for (i = 0; i < adapter->num_rx_queues; i++) | ||
4623 | adapter->rx_ring[i]->reg_idx = i; | ||
4624 | for (i = 0; i < adapter->num_tx_queues; i++) | ||
4625 | adapter->tx_ring[i]->reg_idx = i; | ||
4626 | ret = true; | ||
4627 | } | ||
4628 | |||
4629 | return ret; | ||
4630 | } | ||
4631 | |||
4632 | #ifdef IXGBE_FCOE | ||
4633 | /** | ||
4634 | * ixgbe_cache_ring_fcoe - Descriptor ring to register mapping for the FCoE | ||
4635 | * @adapter: board private structure to initialize | ||
4636 | * | ||
4637 | * Cache the descriptor ring offsets for FCoE mode to the assigned rings. | ||
4638 | * | ||
4639 | */ | ||
4640 | static inline bool ixgbe_cache_ring_fcoe(struct ixgbe_adapter *adapter) | ||
4641 | { | ||
4642 | struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_FCOE]; | ||
4643 | int i; | ||
4644 | u8 fcoe_rx_i = 0, fcoe_tx_i = 0; | ||
4645 | |||
4646 | if (!(adapter->flags & IXGBE_FLAG_FCOE_ENABLED)) | ||
4647 | return false; | ||
4648 | |||
4649 | if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) { | ||
4650 | if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) | ||
4651 | ixgbe_cache_ring_fdir(adapter); | ||
4652 | else | ||
4653 | ixgbe_cache_ring_rss(adapter); | ||
4654 | |||
4655 | fcoe_rx_i = f->mask; | ||
4656 | fcoe_tx_i = f->mask; | ||
4657 | } | ||
4658 | for (i = 0; i < f->indices; i++, fcoe_rx_i++, fcoe_tx_i++) { | ||
4659 | adapter->rx_ring[f->mask + i]->reg_idx = fcoe_rx_i; | ||
4660 | adapter->tx_ring[f->mask + i]->reg_idx = fcoe_tx_i; | ||
4661 | } | ||
4662 | return true; | ||
4663 | } | ||
4664 | |||
4665 | #endif /* IXGBE_FCOE */ | ||
4666 | /** | ||
4667 | * ixgbe_cache_ring_sriov - Descriptor ring to register mapping for sriov | ||
4668 | * @adapter: board private structure to initialize | ||
4669 | * | ||
4670 | * SR-IOV doesn't use any descriptor rings but changes the default if | ||
4671 | * no other mapping is used. | ||
4672 | * | ||
4673 | */ | ||
4674 | static inline bool ixgbe_cache_ring_sriov(struct ixgbe_adapter *adapter) | ||
4675 | { | ||
4676 | adapter->rx_ring[0]->reg_idx = adapter->num_vfs * 2; | ||
4677 | adapter->tx_ring[0]->reg_idx = adapter->num_vfs * 2; | ||
4678 | if (adapter->num_vfs) | ||
4679 | return true; | ||
4680 | else | ||
4681 | return false; | ||
4682 | } | ||
4683 | |||
4684 | /** | ||
4685 | * ixgbe_cache_ring_register - Descriptor ring to register mapping | ||
4686 | * @adapter: board private structure to initialize | ||
4687 | * | ||
4688 | * Once we know the feature-set enabled for the device, we'll cache | ||
4689 | * the register offset the descriptor ring is assigned to. | ||
4690 | * | ||
4691 | * Note, the order the various feature calls is important. It must start with | ||
4692 | * the "most" features enabled at the same time, then trickle down to the | ||
4693 | * least amount of features turned on at once. | ||
4694 | **/ | ||
4695 | static void ixgbe_cache_ring_register(struct ixgbe_adapter *adapter) | ||
4696 | { | ||
4697 | /* start with default case */ | ||
4698 | adapter->rx_ring[0]->reg_idx = 0; | ||
4699 | adapter->tx_ring[0]->reg_idx = 0; | ||
4700 | |||
4701 | if (ixgbe_cache_ring_sriov(adapter)) | ||
4702 | return; | ||
4703 | |||
4704 | #ifdef CONFIG_IXGBE_DCB | ||
4705 | if (ixgbe_cache_ring_dcb(adapter)) | ||
4706 | return; | ||
4707 | #endif | ||
4708 | |||
4709 | #ifdef IXGBE_FCOE | ||
4710 | if (ixgbe_cache_ring_fcoe(adapter)) | ||
4711 | return; | ||
4712 | #endif /* IXGBE_FCOE */ | ||
4713 | |||
4714 | if (ixgbe_cache_ring_fdir(adapter)) | ||
4715 | return; | ||
4716 | |||
4717 | if (ixgbe_cache_ring_rss(adapter)) | ||
4718 | return; | ||
4719 | } | ||
4720 | |||
4721 | /** | ||
4722 | * ixgbe_alloc_queues - Allocate memory for all rings | ||
4723 | * @adapter: board private structure to initialize | ||
4724 | * | ||
4725 | * We allocate one ring per queue at run-time since we don't know the | ||
4726 | * number of queues at compile-time. The polling_netdev array is | ||
4727 | * intended for Multiqueue, but should work fine with a single queue. | ||
4728 | **/ | ||
4729 | static int ixgbe_alloc_queues(struct ixgbe_adapter *adapter) | ||
4730 | { | ||
4731 | int rx = 0, tx = 0, nid = adapter->node; | ||
4732 | |||
4733 | if (nid < 0 || !node_online(nid)) | ||
4734 | nid = first_online_node; | ||
4735 | |||
4736 | for (; tx < adapter->num_tx_queues; tx++) { | ||
4737 | struct ixgbe_ring *ring; | ||
4738 | |||
4739 | ring = kzalloc_node(sizeof(*ring), GFP_KERNEL, nid); | ||
4740 | if (!ring) | ||
4741 | ring = kzalloc(sizeof(*ring), GFP_KERNEL); | ||
4742 | if (!ring) | ||
4743 | goto err_allocation; | ||
4744 | ring->count = adapter->tx_ring_count; | ||
4745 | ring->queue_index = tx; | ||
4746 | ring->numa_node = nid; | ||
4747 | ring->dev = &adapter->pdev->dev; | ||
4748 | ring->netdev = adapter->netdev; | ||
4749 | |||
4750 | adapter->tx_ring[tx] = ring; | ||
4751 | } | ||
4752 | |||
4753 | for (; rx < adapter->num_rx_queues; rx++) { | ||
4754 | struct ixgbe_ring *ring; | ||
4755 | |||
4756 | ring = kzalloc_node(sizeof(*ring), GFP_KERNEL, nid); | ||
4757 | if (!ring) | ||
4758 | ring = kzalloc(sizeof(*ring), GFP_KERNEL); | ||
4759 | if (!ring) | ||
4760 | goto err_allocation; | ||
4761 | ring->count = adapter->rx_ring_count; | ||
4762 | ring->queue_index = rx; | ||
4763 | ring->numa_node = nid; | ||
4764 | ring->dev = &adapter->pdev->dev; | ||
4765 | ring->netdev = adapter->netdev; | ||
4766 | |||
4767 | adapter->rx_ring[rx] = ring; | ||
4768 | } | ||
4769 | |||
4770 | ixgbe_cache_ring_register(adapter); | ||
4771 | |||
4772 | return 0; | ||
4773 | |||
4774 | err_allocation: | ||
4775 | while (tx) | ||
4776 | kfree(adapter->tx_ring[--tx]); | ||
4777 | |||
4778 | while (rx) | ||
4779 | kfree(adapter->rx_ring[--rx]); | ||
4780 | return -ENOMEM; | ||
4781 | } | ||
4782 | |||
4783 | /** | ||
4784 | * ixgbe_set_interrupt_capability - set MSI-X or MSI if supported | ||
4785 | * @adapter: board private structure to initialize | ||
4786 | * | ||
4787 | * Attempt to configure the interrupts using the best available | ||
4788 | * capabilities of the hardware and the kernel. | ||
4789 | **/ | ||
4790 | static int ixgbe_set_interrupt_capability(struct ixgbe_adapter *adapter) | ||
4791 | { | ||
4792 | struct ixgbe_hw *hw = &adapter->hw; | ||
4793 | int err = 0; | ||
4794 | int vector, v_budget; | ||
4795 | |||
4796 | /* | ||
4797 | * It's easy to be greedy for MSI-X vectors, but it really | ||
4798 | * doesn't do us much good if we have a lot more vectors | ||
4799 | * than CPU's. So let's be conservative and only ask for | ||
4800 | * (roughly) the same number of vectors as there are CPU's. | ||
4801 | */ | ||
4802 | v_budget = min(adapter->num_rx_queues + adapter->num_tx_queues, | ||
4803 | (int)num_online_cpus()) + NON_Q_VECTORS; | ||
4804 | |||
4805 | /* | ||
4806 | * At the same time, hardware can only support a maximum of | ||
4807 | * hw.mac->max_msix_vectors vectors. With features | ||
4808 | * such as RSS and VMDq, we can easily surpass the number of Rx and Tx | ||
4809 | * descriptor queues supported by our device. Thus, we cap it off in | ||
4810 | * those rare cases where the cpu count also exceeds our vector limit. | ||
4811 | */ | ||
4812 | v_budget = min(v_budget, (int)hw->mac.max_msix_vectors); | ||
4813 | |||
4814 | /* A failure in MSI-X entry allocation isn't fatal, but it does | ||
4815 | * mean we disable MSI-X capabilities of the adapter. */ | ||
4816 | adapter->msix_entries = kcalloc(v_budget, | ||
4817 | sizeof(struct msix_entry), GFP_KERNEL); | ||
4818 | if (adapter->msix_entries) { | ||
4819 | for (vector = 0; vector < v_budget; vector++) | ||
4820 | adapter->msix_entries[vector].entry = vector; | ||
4821 | |||
4822 | ixgbe_acquire_msix_vectors(adapter, v_budget); | ||
4823 | |||
4824 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) | ||
4825 | goto out; | ||
4826 | } | ||
4827 | |||
4828 | adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED; | ||
4829 | adapter->flags &= ~IXGBE_FLAG_RSS_ENABLED; | ||
4830 | if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) { | ||
4831 | e_err(probe, | ||
4832 | "ATR is not supported while multiple " | ||
4833 | "queues are disabled. Disabling Flow Director\n"); | ||
4834 | } | ||
4835 | adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE; | ||
4836 | adapter->atr_sample_rate = 0; | ||
4837 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) | ||
4838 | ixgbe_disable_sriov(adapter); | ||
4839 | |||
4840 | err = ixgbe_set_num_queues(adapter); | ||
4841 | if (err) | ||
4842 | return err; | ||
4843 | |||
4844 | err = pci_enable_msi(adapter->pdev); | ||
4845 | if (!err) { | ||
4846 | adapter->flags |= IXGBE_FLAG_MSI_ENABLED; | ||
4847 | } else { | ||
4848 | netif_printk(adapter, hw, KERN_DEBUG, adapter->netdev, | ||
4849 | "Unable to allocate MSI interrupt, " | ||
4850 | "falling back to legacy. Error: %d\n", err); | ||
4851 | /* reset err */ | ||
4852 | err = 0; | ||
4853 | } | ||
4854 | |||
4855 | out: | ||
4856 | return err; | ||
4857 | } | ||
4858 | |||
4859 | /** | ||
4860 | * ixgbe_alloc_q_vectors - Allocate memory for interrupt vectors | ||
4861 | * @adapter: board private structure to initialize | ||
4862 | * | ||
4863 | * We allocate one q_vector per queue interrupt. If allocation fails we | ||
4864 | * return -ENOMEM. | ||
4865 | **/ | ||
4866 | static int ixgbe_alloc_q_vectors(struct ixgbe_adapter *adapter) | ||
4867 | { | ||
4868 | int q_idx, num_q_vectors; | ||
4869 | struct ixgbe_q_vector *q_vector; | ||
4870 | int (*poll)(struct napi_struct *, int); | ||
4871 | |||
4872 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { | ||
4873 | num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; | ||
4874 | poll = &ixgbe_clean_rxtx_many; | ||
4875 | } else { | ||
4876 | num_q_vectors = 1; | ||
4877 | poll = &ixgbe_poll; | ||
4878 | } | ||
4879 | |||
4880 | for (q_idx = 0; q_idx < num_q_vectors; q_idx++) { | ||
4881 | q_vector = kzalloc_node(sizeof(struct ixgbe_q_vector), | ||
4882 | GFP_KERNEL, adapter->node); | ||
4883 | if (!q_vector) | ||
4884 | q_vector = kzalloc(sizeof(struct ixgbe_q_vector), | ||
4885 | GFP_KERNEL); | ||
4886 | if (!q_vector) | ||
4887 | goto err_out; | ||
4888 | q_vector->adapter = adapter; | ||
4889 | if (q_vector->tx.count && !q_vector->rx.count) | ||
4890 | q_vector->eitr = adapter->tx_eitr_param; | ||
4891 | else | ||
4892 | q_vector->eitr = adapter->rx_eitr_param; | ||
4893 | q_vector->v_idx = q_idx; | ||
4894 | netif_napi_add(adapter->netdev, &q_vector->napi, (*poll), 64); | ||
4895 | adapter->q_vector[q_idx] = q_vector; | ||
4896 | } | ||
4897 | |||
4898 | return 0; | ||
4899 | |||
4900 | err_out: | ||
4901 | while (q_idx) { | ||
4902 | q_idx--; | ||
4903 | q_vector = adapter->q_vector[q_idx]; | ||
4904 | netif_napi_del(&q_vector->napi); | ||
4905 | kfree(q_vector); | ||
4906 | adapter->q_vector[q_idx] = NULL; | ||
4907 | } | ||
4908 | return -ENOMEM; | ||
4909 | } | ||
4910 | |||
4911 | /** | ||
4912 | * ixgbe_free_q_vectors - Free memory allocated for interrupt vectors | ||
4913 | * @adapter: board private structure to initialize | ||
4914 | * | ||
4915 | * This function frees the memory allocated to the q_vectors. In addition if | ||
4916 | * NAPI is enabled it will delete any references to the NAPI struct prior | ||
4917 | * to freeing the q_vector. | ||
4918 | **/ | ||
4919 | static void ixgbe_free_q_vectors(struct ixgbe_adapter *adapter) | ||
4920 | { | ||
4921 | int q_idx, num_q_vectors; | ||
4922 | |||
4923 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) | ||
4924 | num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; | ||
4925 | else | ||
4926 | num_q_vectors = 1; | ||
4927 | |||
4928 | for (q_idx = 0; q_idx < num_q_vectors; q_idx++) { | ||
4929 | struct ixgbe_q_vector *q_vector = adapter->q_vector[q_idx]; | ||
4930 | adapter->q_vector[q_idx] = NULL; | ||
4931 | netif_napi_del(&q_vector->napi); | ||
4932 | kfree(q_vector); | ||
4933 | } | ||
4934 | } | ||
4935 | |||
4936 | static void ixgbe_reset_interrupt_capability(struct ixgbe_adapter *adapter) | ||
4937 | { | ||
4938 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { | ||
4939 | adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED; | ||
4940 | pci_disable_msix(adapter->pdev); | ||
4941 | kfree(adapter->msix_entries); | ||
4942 | adapter->msix_entries = NULL; | ||
4943 | } else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED) { | ||
4944 | adapter->flags &= ~IXGBE_FLAG_MSI_ENABLED; | ||
4945 | pci_disable_msi(adapter->pdev); | ||
4946 | } | ||
4947 | } | ||
4948 | |||
4949 | /** | ||
4950 | * ixgbe_init_interrupt_scheme - Determine proper interrupt scheme | ||
4951 | * @adapter: board private structure to initialize | ||
4952 | * | ||
4953 | * We determine which interrupt scheme to use based on... | ||
4954 | * - Kernel support (MSI, MSI-X) | ||
4955 | * - which can be user-defined (via MODULE_PARAM) | ||
4956 | * - Hardware queue count (num_*_queues) | ||
4957 | * - defined by miscellaneous hardware support/features (RSS, etc.) | ||
4958 | **/ | ||
4959 | int ixgbe_init_interrupt_scheme(struct ixgbe_adapter *adapter) | ||
4960 | { | ||
4961 | int err; | ||
4962 | |||
4963 | /* Number of supported queues */ | ||
4964 | err = ixgbe_set_num_queues(adapter); | ||
4965 | if (err) | ||
4966 | return err; | ||
4967 | |||
4968 | err = ixgbe_set_interrupt_capability(adapter); | ||
4969 | if (err) { | ||
4970 | e_dev_err("Unable to setup interrupt capabilities\n"); | ||
4971 | goto err_set_interrupt; | ||
4972 | } | ||
4973 | |||
4974 | err = ixgbe_alloc_q_vectors(adapter); | ||
4975 | if (err) { | ||
4976 | e_dev_err("Unable to allocate memory for queue vectors\n"); | ||
4977 | goto err_alloc_q_vectors; | ||
4978 | } | ||
4979 | |||
4980 | err = ixgbe_alloc_queues(adapter); | ||
4981 | if (err) { | ||
4982 | e_dev_err("Unable to allocate memory for queues\n"); | ||
4983 | goto err_alloc_queues; | ||
4984 | } | ||
4985 | |||
4986 | e_dev_info("Multiqueue %s: Rx Queue count = %u, Tx Queue count = %u\n", | ||
4987 | (adapter->num_rx_queues > 1) ? "Enabled" : "Disabled", | ||
4988 | adapter->num_rx_queues, adapter->num_tx_queues); | ||
4989 | |||
4990 | set_bit(__IXGBE_DOWN, &adapter->state); | ||
4991 | |||
4992 | return 0; | ||
4993 | |||
4994 | err_alloc_queues: | ||
4995 | ixgbe_free_q_vectors(adapter); | ||
4996 | err_alloc_q_vectors: | ||
4997 | ixgbe_reset_interrupt_capability(adapter); | ||
4998 | err_set_interrupt: | ||
4999 | return err; | ||
5000 | } | ||
5001 | |||
5002 | /** | ||
5003 | * ixgbe_clear_interrupt_scheme - Clear the current interrupt scheme settings | ||
5004 | * @adapter: board private structure to clear interrupt scheme on | ||
5005 | * | ||
5006 | * We go through and clear interrupt specific resources and reset the structure | ||
5007 | * to pre-load conditions | ||
5008 | **/ | ||
5009 | void ixgbe_clear_interrupt_scheme(struct ixgbe_adapter *adapter) | ||
5010 | { | ||
5011 | int i; | ||
5012 | |||
5013 | for (i = 0; i < adapter->num_tx_queues; i++) { | ||
5014 | kfree(adapter->tx_ring[i]); | ||
5015 | adapter->tx_ring[i] = NULL; | ||
5016 | } | ||
5017 | for (i = 0; i < adapter->num_rx_queues; i++) { | ||
5018 | struct ixgbe_ring *ring = adapter->rx_ring[i]; | ||
5019 | |||
5020 | /* ixgbe_get_stats64() might access this ring, we must wait | ||
5021 | * a grace period before freeing it. | ||
5022 | */ | ||
5023 | kfree_rcu(ring, rcu); | ||
5024 | adapter->rx_ring[i] = NULL; | ||
5025 | } | ||
5026 | |||
5027 | adapter->num_tx_queues = 0; | ||
5028 | adapter->num_rx_queues = 0; | ||
5029 | |||
5030 | ixgbe_free_q_vectors(adapter); | ||
5031 | ixgbe_reset_interrupt_capability(adapter); | ||
5032 | } | ||
5033 | |||
5034 | /** | ||
5035 | * ixgbe_sw_init - Initialize general software structures (struct ixgbe_adapter) | ||
5036 | * @adapter: board private structure to initialize | ||
5037 | * | ||
5038 | * ixgbe_sw_init initializes the Adapter private data structure. | ||
5039 | * Fields are initialized based on PCI device information and | ||
5040 | * OS network device settings (MTU size). | ||
5041 | **/ | ||
5042 | static int __devinit ixgbe_sw_init(struct ixgbe_adapter *adapter) | ||
5043 | { | ||
5044 | struct ixgbe_hw *hw = &adapter->hw; | ||
5045 | struct pci_dev *pdev = adapter->pdev; | ||
5046 | struct net_device *dev = adapter->netdev; | ||
5047 | unsigned int rss; | ||
5048 | #ifdef CONFIG_IXGBE_DCB | ||
5049 | int j; | ||
5050 | struct tc_configuration *tc; | ||
5051 | #endif | ||
5052 | int max_frame = dev->mtu + ETH_HLEN + ETH_FCS_LEN; | ||
5053 | |||
5054 | /* PCI config space info */ | ||
5055 | |||
5056 | hw->vendor_id = pdev->vendor; | ||
5057 | hw->device_id = pdev->device; | ||
5058 | hw->revision_id = pdev->revision; | ||
5059 | hw->subsystem_vendor_id = pdev->subsystem_vendor; | ||
5060 | hw->subsystem_device_id = pdev->subsystem_device; | ||
5061 | |||
5062 | /* Set capability flags */ | ||
5063 | rss = min(IXGBE_MAX_RSS_INDICES, (int)num_online_cpus()); | ||
5064 | adapter->ring_feature[RING_F_RSS].indices = rss; | ||
5065 | adapter->flags |= IXGBE_FLAG_RSS_ENABLED; | ||
5066 | switch (hw->mac.type) { | ||
5067 | case ixgbe_mac_82598EB: | ||
5068 | if (hw->device_id == IXGBE_DEV_ID_82598AT) | ||
5069 | adapter->flags |= IXGBE_FLAG_FAN_FAIL_CAPABLE; | ||
5070 | adapter->max_msix_q_vectors = MAX_MSIX_Q_VECTORS_82598; | ||
5071 | break; | ||
5072 | case ixgbe_mac_82599EB: | ||
5073 | case ixgbe_mac_X540: | ||
5074 | adapter->max_msix_q_vectors = MAX_MSIX_Q_VECTORS_82599; | ||
5075 | adapter->flags2 |= IXGBE_FLAG2_RSC_CAPABLE; | ||
5076 | adapter->flags2 |= IXGBE_FLAG2_RSC_ENABLED; | ||
5077 | if (hw->device_id == IXGBE_DEV_ID_82599_T3_LOM) | ||
5078 | adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE; | ||
5079 | /* Flow Director hash filters enabled */ | ||
5080 | adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE; | ||
5081 | adapter->atr_sample_rate = 20; | ||
5082 | adapter->ring_feature[RING_F_FDIR].indices = | ||
5083 | IXGBE_MAX_FDIR_INDICES; | ||
5084 | adapter->fdir_pballoc = IXGBE_FDIR_PBALLOC_64K; | ||
5085 | #ifdef IXGBE_FCOE | ||
5086 | adapter->flags |= IXGBE_FLAG_FCOE_CAPABLE; | ||
5087 | adapter->flags &= ~IXGBE_FLAG_FCOE_ENABLED; | ||
5088 | adapter->ring_feature[RING_F_FCOE].indices = 0; | ||
5089 | #ifdef CONFIG_IXGBE_DCB | ||
5090 | /* Default traffic class to use for FCoE */ | ||
5091 | adapter->fcoe.up = IXGBE_FCOE_DEFTC; | ||
5092 | #endif | ||
5093 | #endif /* IXGBE_FCOE */ | ||
5094 | break; | ||
5095 | default: | ||
5096 | break; | ||
5097 | } | ||
5098 | |||
5099 | /* n-tuple support exists, always init our spinlock */ | ||
5100 | spin_lock_init(&adapter->fdir_perfect_lock); | ||
5101 | |||
5102 | #ifdef CONFIG_IXGBE_DCB | ||
5103 | /* Configure DCB traffic classes */ | ||
5104 | for (j = 0; j < MAX_TRAFFIC_CLASS; j++) { | ||
5105 | tc = &adapter->dcb_cfg.tc_config[j]; | ||
5106 | tc->path[DCB_TX_CONFIG].bwg_id = 0; | ||
5107 | tc->path[DCB_TX_CONFIG].bwg_percent = 12 + (j & 1); | ||
5108 | tc->path[DCB_RX_CONFIG].bwg_id = 0; | ||
5109 | tc->path[DCB_RX_CONFIG].bwg_percent = 12 + (j & 1); | ||
5110 | tc->dcb_pfc = pfc_disabled; | ||
5111 | } | ||
5112 | adapter->dcb_cfg.bw_percentage[DCB_TX_CONFIG][0] = 100; | ||
5113 | adapter->dcb_cfg.bw_percentage[DCB_RX_CONFIG][0] = 100; | ||
5114 | adapter->dcb_cfg.pfc_mode_enable = false; | ||
5115 | adapter->dcb_set_bitmap = 0x00; | ||
5116 | adapter->dcbx_cap = DCB_CAP_DCBX_HOST | DCB_CAP_DCBX_VER_CEE; | ||
5117 | ixgbe_copy_dcb_cfg(&adapter->dcb_cfg, &adapter->temp_dcb_cfg, | ||
5118 | MAX_TRAFFIC_CLASS); | ||
5119 | |||
5120 | #endif | ||
5121 | |||
5122 | /* default flow control settings */ | ||
5123 | hw->fc.requested_mode = ixgbe_fc_full; | ||
5124 | hw->fc.current_mode = ixgbe_fc_full; /* init for ethtool output */ | ||
5125 | #ifdef CONFIG_DCB | ||
5126 | adapter->last_lfc_mode = hw->fc.current_mode; | ||
5127 | #endif | ||
5128 | hw->fc.high_water = FC_HIGH_WATER(max_frame); | ||
5129 | hw->fc.low_water = FC_LOW_WATER(max_frame); | ||
5130 | hw->fc.pause_time = IXGBE_DEFAULT_FCPAUSE; | ||
5131 | hw->fc.send_xon = true; | ||
5132 | hw->fc.disable_fc_autoneg = false; | ||
5133 | |||
5134 | /* enable itr by default in dynamic mode */ | ||
5135 | adapter->rx_itr_setting = 1; | ||
5136 | adapter->rx_eitr_param = 20000; | ||
5137 | adapter->tx_itr_setting = 1; | ||
5138 | adapter->tx_eitr_param = 10000; | ||
5139 | |||
5140 | /* set defaults for eitr in MegaBytes */ | ||
5141 | adapter->eitr_low = 10; | ||
5142 | adapter->eitr_high = 20; | ||
5143 | |||
5144 | /* set default ring sizes */ | ||
5145 | adapter->tx_ring_count = IXGBE_DEFAULT_TXD; | ||
5146 | adapter->rx_ring_count = IXGBE_DEFAULT_RXD; | ||
5147 | |||
5148 | /* set default work limits */ | ||
5149 | adapter->tx_work_limit = adapter->tx_ring_count; | ||
5150 | |||
5151 | /* initialize eeprom parameters */ | ||
5152 | if (ixgbe_init_eeprom_params_generic(hw)) { | ||
5153 | e_dev_err("EEPROM initialization failed\n"); | ||
5154 | return -EIO; | ||
5155 | } | ||
5156 | |||
5157 | /* enable rx csum by default */ | ||
5158 | adapter->flags |= IXGBE_FLAG_RX_CSUM_ENABLED; | ||
5159 | |||
5160 | /* get assigned NUMA node */ | ||
5161 | adapter->node = dev_to_node(&pdev->dev); | ||
5162 | |||
5163 | set_bit(__IXGBE_DOWN, &adapter->state); | ||
5164 | |||
5165 | return 0; | ||
5166 | } | ||
5167 | |||
5168 | /** | ||
5169 | * ixgbe_setup_tx_resources - allocate Tx resources (Descriptors) | ||
5170 | * @tx_ring: tx descriptor ring (for a specific queue) to setup | ||
5171 | * | ||
5172 | * Return 0 on success, negative on failure | ||
5173 | **/ | ||
5174 | int ixgbe_setup_tx_resources(struct ixgbe_ring *tx_ring) | ||
5175 | { | ||
5176 | struct device *dev = tx_ring->dev; | ||
5177 | int size; | ||
5178 | |||
5179 | size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count; | ||
5180 | tx_ring->tx_buffer_info = vzalloc_node(size, tx_ring->numa_node); | ||
5181 | if (!tx_ring->tx_buffer_info) | ||
5182 | tx_ring->tx_buffer_info = vzalloc(size); | ||
5183 | if (!tx_ring->tx_buffer_info) | ||
5184 | goto err; | ||
5185 | |||
5186 | /* round up to nearest 4K */ | ||
5187 | tx_ring->size = tx_ring->count * sizeof(union ixgbe_adv_tx_desc); | ||
5188 | tx_ring->size = ALIGN(tx_ring->size, 4096); | ||
5189 | |||
5190 | tx_ring->desc = dma_alloc_coherent(dev, tx_ring->size, | ||
5191 | &tx_ring->dma, GFP_KERNEL); | ||
5192 | if (!tx_ring->desc) | ||
5193 | goto err; | ||
5194 | |||
5195 | tx_ring->next_to_use = 0; | ||
5196 | tx_ring->next_to_clean = 0; | ||
5197 | return 0; | ||
5198 | |||
5199 | err: | ||
5200 | vfree(tx_ring->tx_buffer_info); | ||
5201 | tx_ring->tx_buffer_info = NULL; | ||
5202 | dev_err(dev, "Unable to allocate memory for the Tx descriptor ring\n"); | ||
5203 | return -ENOMEM; | ||
5204 | } | ||
5205 | |||
5206 | /** | ||
5207 | * ixgbe_setup_all_tx_resources - allocate all queues Tx resources | ||
5208 | * @adapter: board private structure | ||
5209 | * | ||
5210 | * If this function returns with an error, then it's possible one or | ||
5211 | * more of the rings is populated (while the rest are not). It is the | ||
5212 | * callers duty to clean those orphaned rings. | ||
5213 | * | ||
5214 | * Return 0 on success, negative on failure | ||
5215 | **/ | ||
5216 | static int ixgbe_setup_all_tx_resources(struct ixgbe_adapter *adapter) | ||
5217 | { | ||
5218 | int i, err = 0; | ||
5219 | |||
5220 | for (i = 0; i < adapter->num_tx_queues; i++) { | ||
5221 | err = ixgbe_setup_tx_resources(adapter->tx_ring[i]); | ||
5222 | if (!err) | ||
5223 | continue; | ||
5224 | e_err(probe, "Allocation for Tx Queue %u failed\n", i); | ||
5225 | break; | ||
5226 | } | ||
5227 | |||
5228 | return err; | ||
5229 | } | ||
5230 | |||
5231 | /** | ||
5232 | * ixgbe_setup_rx_resources - allocate Rx resources (Descriptors) | ||
5233 | * @rx_ring: rx descriptor ring (for a specific queue) to setup | ||
5234 | * | ||
5235 | * Returns 0 on success, negative on failure | ||
5236 | **/ | ||
5237 | int ixgbe_setup_rx_resources(struct ixgbe_ring *rx_ring) | ||
5238 | { | ||
5239 | struct device *dev = rx_ring->dev; | ||
5240 | int size; | ||
5241 | |||
5242 | size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count; | ||
5243 | rx_ring->rx_buffer_info = vzalloc_node(size, rx_ring->numa_node); | ||
5244 | if (!rx_ring->rx_buffer_info) | ||
5245 | rx_ring->rx_buffer_info = vzalloc(size); | ||
5246 | if (!rx_ring->rx_buffer_info) | ||
5247 | goto err; | ||
5248 | |||
5249 | /* Round up to nearest 4K */ | ||
5250 | rx_ring->size = rx_ring->count * sizeof(union ixgbe_adv_rx_desc); | ||
5251 | rx_ring->size = ALIGN(rx_ring->size, 4096); | ||
5252 | |||
5253 | rx_ring->desc = dma_alloc_coherent(dev, rx_ring->size, | ||
5254 | &rx_ring->dma, GFP_KERNEL); | ||
5255 | |||
5256 | if (!rx_ring->desc) | ||
5257 | goto err; | ||
5258 | |||
5259 | rx_ring->next_to_clean = 0; | ||
5260 | rx_ring->next_to_use = 0; | ||
5261 | |||
5262 | return 0; | ||
5263 | err: | ||
5264 | vfree(rx_ring->rx_buffer_info); | ||
5265 | rx_ring->rx_buffer_info = NULL; | ||
5266 | dev_err(dev, "Unable to allocate memory for the Rx descriptor ring\n"); | ||
5267 | return -ENOMEM; | ||
5268 | } | ||
5269 | |||
5270 | /** | ||
5271 | * ixgbe_setup_all_rx_resources - allocate all queues Rx resources | ||
5272 | * @adapter: board private structure | ||
5273 | * | ||
5274 | * If this function returns with an error, then it's possible one or | ||
5275 | * more of the rings is populated (while the rest are not). It is the | ||
5276 | * callers duty to clean those orphaned rings. | ||
5277 | * | ||
5278 | * Return 0 on success, negative on failure | ||
5279 | **/ | ||
5280 | static int ixgbe_setup_all_rx_resources(struct ixgbe_adapter *adapter) | ||
5281 | { | ||
5282 | int i, err = 0; | ||
5283 | |||
5284 | for (i = 0; i < adapter->num_rx_queues; i++) { | ||
5285 | err = ixgbe_setup_rx_resources(adapter->rx_ring[i]); | ||
5286 | if (!err) | ||
5287 | continue; | ||
5288 | e_err(probe, "Allocation for Rx Queue %u failed\n", i); | ||
5289 | break; | ||
5290 | } | ||
5291 | |||
5292 | return err; | ||
5293 | } | ||
5294 | |||
5295 | /** | ||
5296 | * ixgbe_free_tx_resources - Free Tx Resources per Queue | ||
5297 | * @tx_ring: Tx descriptor ring for a specific queue | ||
5298 | * | ||
5299 | * Free all transmit software resources | ||
5300 | **/ | ||
5301 | void ixgbe_free_tx_resources(struct ixgbe_ring *tx_ring) | ||
5302 | { | ||
5303 | ixgbe_clean_tx_ring(tx_ring); | ||
5304 | |||
5305 | vfree(tx_ring->tx_buffer_info); | ||
5306 | tx_ring->tx_buffer_info = NULL; | ||
5307 | |||
5308 | /* if not set, then don't free */ | ||
5309 | if (!tx_ring->desc) | ||
5310 | return; | ||
5311 | |||
5312 | dma_free_coherent(tx_ring->dev, tx_ring->size, | ||
5313 | tx_ring->desc, tx_ring->dma); | ||
5314 | |||
5315 | tx_ring->desc = NULL; | ||
5316 | } | ||
5317 | |||
5318 | /** | ||
5319 | * ixgbe_free_all_tx_resources - Free Tx Resources for All Queues | ||
5320 | * @adapter: board private structure | ||
5321 | * | ||
5322 | * Free all transmit software resources | ||
5323 | **/ | ||
5324 | static void ixgbe_free_all_tx_resources(struct ixgbe_adapter *adapter) | ||
5325 | { | ||
5326 | int i; | ||
5327 | |||
5328 | for (i = 0; i < adapter->num_tx_queues; i++) | ||
5329 | if (adapter->tx_ring[i]->desc) | ||
5330 | ixgbe_free_tx_resources(adapter->tx_ring[i]); | ||
5331 | } | ||
5332 | |||
5333 | /** | ||
5334 | * ixgbe_free_rx_resources - Free Rx Resources | ||
5335 | * @rx_ring: ring to clean the resources from | ||
5336 | * | ||
5337 | * Free all receive software resources | ||
5338 | **/ | ||
5339 | void ixgbe_free_rx_resources(struct ixgbe_ring *rx_ring) | ||
5340 | { | ||
5341 | ixgbe_clean_rx_ring(rx_ring); | ||
5342 | |||
5343 | vfree(rx_ring->rx_buffer_info); | ||
5344 | rx_ring->rx_buffer_info = NULL; | ||
5345 | |||
5346 | /* if not set, then don't free */ | ||
5347 | if (!rx_ring->desc) | ||
5348 | return; | ||
5349 | |||
5350 | dma_free_coherent(rx_ring->dev, rx_ring->size, | ||
5351 | rx_ring->desc, rx_ring->dma); | ||
5352 | |||
5353 | rx_ring->desc = NULL; | ||
5354 | } | ||
5355 | |||
5356 | /** | ||
5357 | * ixgbe_free_all_rx_resources - Free Rx Resources for All Queues | ||
5358 | * @adapter: board private structure | ||
5359 | * | ||
5360 | * Free all receive software resources | ||
5361 | **/ | ||
5362 | static void ixgbe_free_all_rx_resources(struct ixgbe_adapter *adapter) | ||
5363 | { | ||
5364 | int i; | ||
5365 | |||
5366 | for (i = 0; i < adapter->num_rx_queues; i++) | ||
5367 | if (adapter->rx_ring[i]->desc) | ||
5368 | ixgbe_free_rx_resources(adapter->rx_ring[i]); | ||
5369 | } | ||
5370 | |||
5371 | /** | ||
5372 | * ixgbe_change_mtu - Change the Maximum Transfer Unit | ||
5373 | * @netdev: network interface device structure | ||
5374 | * @new_mtu: new value for maximum frame size | ||
5375 | * | ||
5376 | * Returns 0 on success, negative on failure | ||
5377 | **/ | ||
5378 | static int ixgbe_change_mtu(struct net_device *netdev, int new_mtu) | ||
5379 | { | ||
5380 | struct ixgbe_adapter *adapter = netdev_priv(netdev); | ||
5381 | struct ixgbe_hw *hw = &adapter->hw; | ||
5382 | int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN; | ||
5383 | |||
5384 | /* MTU < 68 is an error and causes problems on some kernels */ | ||
5385 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED && | ||
5386 | hw->mac.type != ixgbe_mac_X540) { | ||
5387 | if ((new_mtu < 68) || (max_frame > MAXIMUM_ETHERNET_VLAN_SIZE)) | ||
5388 | return -EINVAL; | ||
5389 | } else { | ||
5390 | if ((new_mtu < 68) || (max_frame > IXGBE_MAX_JUMBO_FRAME_SIZE)) | ||
5391 | return -EINVAL; | ||
5392 | } | ||
5393 | |||
5394 | e_info(probe, "changing MTU from %d to %d\n", netdev->mtu, new_mtu); | ||
5395 | /* must set new MTU before calling down or up */ | ||
5396 | netdev->mtu = new_mtu; | ||
5397 | |||
5398 | hw->fc.high_water = FC_HIGH_WATER(max_frame); | ||
5399 | hw->fc.low_water = FC_LOW_WATER(max_frame); | ||
5400 | |||
5401 | if (netif_running(netdev)) | ||
5402 | ixgbe_reinit_locked(adapter); | ||
5403 | |||
5404 | return 0; | ||
5405 | } | ||
5406 | |||
5407 | /** | ||
5408 | * ixgbe_open - Called when a network interface is made active | ||
5409 | * @netdev: network interface device structure | ||
5410 | * | ||
5411 | * Returns 0 on success, negative value on failure | ||
5412 | * | ||
5413 | * The open entry point is called when a network interface is made | ||
5414 | * active by the system (IFF_UP). At this point all resources needed | ||
5415 | * for transmit and receive operations are allocated, the interrupt | ||
5416 | * handler is registered with the OS, the watchdog timer is started, | ||
5417 | * and the stack is notified that the interface is ready. | ||
5418 | **/ | ||
5419 | static int ixgbe_open(struct net_device *netdev) | ||
5420 | { | ||
5421 | struct ixgbe_adapter *adapter = netdev_priv(netdev); | ||
5422 | int err; | ||
5423 | |||
5424 | /* disallow open during test */ | ||
5425 | if (test_bit(__IXGBE_TESTING, &adapter->state)) | ||
5426 | return -EBUSY; | ||
5427 | |||
5428 | netif_carrier_off(netdev); | ||
5429 | |||
5430 | /* allocate transmit descriptors */ | ||
5431 | err = ixgbe_setup_all_tx_resources(adapter); | ||
5432 | if (err) | ||
5433 | goto err_setup_tx; | ||
5434 | |||
5435 | /* allocate receive descriptors */ | ||
5436 | err = ixgbe_setup_all_rx_resources(adapter); | ||
5437 | if (err) | ||
5438 | goto err_setup_rx; | ||
5439 | |||
5440 | ixgbe_configure(adapter); | ||
5441 | |||
5442 | err = ixgbe_request_irq(adapter); | ||
5443 | if (err) | ||
5444 | goto err_req_irq; | ||
5445 | |||
5446 | err = ixgbe_up_complete(adapter); | ||
5447 | if (err) | ||
5448 | goto err_up; | ||
5449 | |||
5450 | netif_tx_start_all_queues(netdev); | ||
5451 | |||
5452 | return 0; | ||
5453 | |||
5454 | err_up: | ||
5455 | ixgbe_release_hw_control(adapter); | ||
5456 | ixgbe_free_irq(adapter); | ||
5457 | err_req_irq: | ||
5458 | err_setup_rx: | ||
5459 | ixgbe_free_all_rx_resources(adapter); | ||
5460 | err_setup_tx: | ||
5461 | ixgbe_free_all_tx_resources(adapter); | ||
5462 | ixgbe_reset(adapter); | ||
5463 | |||
5464 | return err; | ||
5465 | } | ||
5466 | |||
5467 | /** | ||
5468 | * ixgbe_close - Disables a network interface | ||
5469 | * @netdev: network interface device structure | ||
5470 | * | ||
5471 | * Returns 0, this is not allowed to fail | ||
5472 | * | ||
5473 | * The close entry point is called when an interface is de-activated | ||
5474 | * by the OS. The hardware is still under the drivers control, but | ||
5475 | * needs to be disabled. A global MAC reset is issued to stop the | ||
5476 | * hardware, and all transmit and receive resources are freed. | ||
5477 | **/ | ||
5478 | static int ixgbe_close(struct net_device *netdev) | ||
5479 | { | ||
5480 | struct ixgbe_adapter *adapter = netdev_priv(netdev); | ||
5481 | |||
5482 | ixgbe_down(adapter); | ||
5483 | ixgbe_free_irq(adapter); | ||
5484 | |||
5485 | ixgbe_fdir_filter_exit(adapter); | ||
5486 | |||
5487 | ixgbe_free_all_tx_resources(adapter); | ||
5488 | ixgbe_free_all_rx_resources(adapter); | ||
5489 | |||
5490 | ixgbe_release_hw_control(adapter); | ||
5491 | |||
5492 | return 0; | ||
5493 | } | ||
5494 | |||
5495 | #ifdef CONFIG_PM | ||
5496 | static int ixgbe_resume(struct pci_dev *pdev) | ||
5497 | { | ||
5498 | struct ixgbe_adapter *adapter = pci_get_drvdata(pdev); | ||
5499 | struct net_device *netdev = adapter->netdev; | ||
5500 | u32 err; | ||
5501 | |||
5502 | pci_set_power_state(pdev, PCI_D0); | ||
5503 | pci_restore_state(pdev); | ||
5504 | /* | ||
5505 | * pci_restore_state clears dev->state_saved so call | ||
5506 | * pci_save_state to restore it. | ||
5507 | */ | ||
5508 | pci_save_state(pdev); | ||
5509 | |||
5510 | err = pci_enable_device_mem(pdev); | ||
5511 | if (err) { | ||
5512 | e_dev_err("Cannot enable PCI device from suspend\n"); | ||
5513 | return err; | ||
5514 | } | ||
5515 | pci_set_master(pdev); | ||
5516 | |||
5517 | pci_wake_from_d3(pdev, false); | ||
5518 | |||
5519 | err = ixgbe_init_interrupt_scheme(adapter); | ||
5520 | if (err) { | ||
5521 | e_dev_err("Cannot initialize interrupts for device\n"); | ||
5522 | return err; | ||
5523 | } | ||
5524 | |||
5525 | ixgbe_reset(adapter); | ||
5526 | |||
5527 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0); | ||
5528 | |||
5529 | if (netif_running(netdev)) { | ||
5530 | err = ixgbe_open(netdev); | ||
5531 | if (err) | ||
5532 | return err; | ||
5533 | } | ||
5534 | |||
5535 | netif_device_attach(netdev); | ||
5536 | |||
5537 | return 0; | ||
5538 | } | ||
5539 | #endif /* CONFIG_PM */ | ||
5540 | |||
5541 | static int __ixgbe_shutdown(struct pci_dev *pdev, bool *enable_wake) | ||
5542 | { | ||
5543 | struct ixgbe_adapter *adapter = pci_get_drvdata(pdev); | ||
5544 | struct net_device *netdev = adapter->netdev; | ||
5545 | struct ixgbe_hw *hw = &adapter->hw; | ||
5546 | u32 ctrl, fctrl; | ||
5547 | u32 wufc = adapter->wol; | ||
5548 | #ifdef CONFIG_PM | ||
5549 | int retval = 0; | ||
5550 | #endif | ||
5551 | |||
5552 | netif_device_detach(netdev); | ||
5553 | |||
5554 | if (netif_running(netdev)) { | ||
5555 | ixgbe_down(adapter); | ||
5556 | ixgbe_free_irq(adapter); | ||
5557 | ixgbe_free_all_tx_resources(adapter); | ||
5558 | ixgbe_free_all_rx_resources(adapter); | ||
5559 | } | ||
5560 | |||
5561 | ixgbe_clear_interrupt_scheme(adapter); | ||
5562 | #ifdef CONFIG_DCB | ||
5563 | kfree(adapter->ixgbe_ieee_pfc); | ||
5564 | kfree(adapter->ixgbe_ieee_ets); | ||
5565 | #endif | ||
5566 | |||
5567 | #ifdef CONFIG_PM | ||
5568 | retval = pci_save_state(pdev); | ||
5569 | if (retval) | ||
5570 | return retval; | ||
5571 | |||
5572 | #endif | ||
5573 | if (wufc) { | ||
5574 | ixgbe_set_rx_mode(netdev); | ||
5575 | |||
5576 | /* turn on all-multi mode if wake on multicast is enabled */ | ||
5577 | if (wufc & IXGBE_WUFC_MC) { | ||
5578 | fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL); | ||
5579 | fctrl |= IXGBE_FCTRL_MPE; | ||
5580 | IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl); | ||
5581 | } | ||
5582 | |||
5583 | ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL); | ||
5584 | ctrl |= IXGBE_CTRL_GIO_DIS; | ||
5585 | IXGBE_WRITE_REG(hw, IXGBE_CTRL, ctrl); | ||
5586 | |||
5587 | IXGBE_WRITE_REG(hw, IXGBE_WUFC, wufc); | ||
5588 | } else { | ||
5589 | IXGBE_WRITE_REG(hw, IXGBE_WUC, 0); | ||
5590 | IXGBE_WRITE_REG(hw, IXGBE_WUFC, 0); | ||
5591 | } | ||
5592 | |||
5593 | switch (hw->mac.type) { | ||
5594 | case ixgbe_mac_82598EB: | ||
5595 | pci_wake_from_d3(pdev, false); | ||
5596 | break; | ||
5597 | case ixgbe_mac_82599EB: | ||
5598 | case ixgbe_mac_X540: | ||
5599 | pci_wake_from_d3(pdev, !!wufc); | ||
5600 | break; | ||
5601 | default: | ||
5602 | break; | ||
5603 | } | ||
5604 | |||
5605 | *enable_wake = !!wufc; | ||
5606 | |||
5607 | ixgbe_release_hw_control(adapter); | ||
5608 | |||
5609 | pci_disable_device(pdev); | ||
5610 | |||
5611 | return 0; | ||
5612 | } | ||
5613 | |||
5614 | #ifdef CONFIG_PM | ||
5615 | static int ixgbe_suspend(struct pci_dev *pdev, pm_message_t state) | ||
5616 | { | ||
5617 | int retval; | ||
5618 | bool wake; | ||
5619 | |||
5620 | retval = __ixgbe_shutdown(pdev, &wake); | ||
5621 | if (retval) | ||
5622 | return retval; | ||
5623 | |||
5624 | if (wake) { | ||
5625 | pci_prepare_to_sleep(pdev); | ||
5626 | } else { | ||
5627 | pci_wake_from_d3(pdev, false); | ||
5628 | pci_set_power_state(pdev, PCI_D3hot); | ||
5629 | } | ||
5630 | |||
5631 | return 0; | ||
5632 | } | ||
5633 | #endif /* CONFIG_PM */ | ||
5634 | |||
5635 | static void ixgbe_shutdown(struct pci_dev *pdev) | ||
5636 | { | ||
5637 | bool wake; | ||
5638 | |||
5639 | __ixgbe_shutdown(pdev, &wake); | ||
5640 | |||
5641 | if (system_state == SYSTEM_POWER_OFF) { | ||
5642 | pci_wake_from_d3(pdev, wake); | ||
5643 | pci_set_power_state(pdev, PCI_D3hot); | ||
5644 | } | ||
5645 | } | ||
5646 | |||
5647 | /** | ||
5648 | * ixgbe_update_stats - Update the board statistics counters. | ||
5649 | * @adapter: board private structure | ||
5650 | **/ | ||
5651 | void ixgbe_update_stats(struct ixgbe_adapter *adapter) | ||
5652 | { | ||
5653 | struct net_device *netdev = adapter->netdev; | ||
5654 | struct ixgbe_hw *hw = &adapter->hw; | ||
5655 | struct ixgbe_hw_stats *hwstats = &adapter->stats; | ||
5656 | u64 total_mpc = 0; | ||
5657 | u32 i, missed_rx = 0, mpc, bprc, lxon, lxoff, xon_off_tot; | ||
5658 | u64 non_eop_descs = 0, restart_queue = 0, tx_busy = 0; | ||
5659 | u64 alloc_rx_page_failed = 0, alloc_rx_buff_failed = 0; | ||
5660 | u64 bytes = 0, packets = 0; | ||
5661 | |||
5662 | if (test_bit(__IXGBE_DOWN, &adapter->state) || | ||
5663 | test_bit(__IXGBE_RESETTING, &adapter->state)) | ||
5664 | return; | ||
5665 | |||
5666 | if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) { | ||
5667 | u64 rsc_count = 0; | ||
5668 | u64 rsc_flush = 0; | ||
5669 | for (i = 0; i < 16; i++) | ||
5670 | adapter->hw_rx_no_dma_resources += | ||
5671 | IXGBE_READ_REG(hw, IXGBE_QPRDC(i)); | ||
5672 | for (i = 0; i < adapter->num_rx_queues; i++) { | ||
5673 | rsc_count += adapter->rx_ring[i]->rx_stats.rsc_count; | ||
5674 | rsc_flush += adapter->rx_ring[i]->rx_stats.rsc_flush; | ||
5675 | } | ||
5676 | adapter->rsc_total_count = rsc_count; | ||
5677 | adapter->rsc_total_flush = rsc_flush; | ||
5678 | } | ||
5679 | |||
5680 | for (i = 0; i < adapter->num_rx_queues; i++) { | ||
5681 | struct ixgbe_ring *rx_ring = adapter->rx_ring[i]; | ||
5682 | non_eop_descs += rx_ring->rx_stats.non_eop_descs; | ||
5683 | alloc_rx_page_failed += rx_ring->rx_stats.alloc_rx_page_failed; | ||
5684 | alloc_rx_buff_failed += rx_ring->rx_stats.alloc_rx_buff_failed; | ||
5685 | bytes += rx_ring->stats.bytes; | ||
5686 | packets += rx_ring->stats.packets; | ||
5687 | } | ||
5688 | adapter->non_eop_descs = non_eop_descs; | ||
5689 | adapter->alloc_rx_page_failed = alloc_rx_page_failed; | ||
5690 | adapter->alloc_rx_buff_failed = alloc_rx_buff_failed; | ||
5691 | netdev->stats.rx_bytes = bytes; | ||
5692 | netdev->stats.rx_packets = packets; | ||
5693 | |||
5694 | bytes = 0; | ||
5695 | packets = 0; | ||
5696 | /* gather some stats to the adapter struct that are per queue */ | ||
5697 | for (i = 0; i < adapter->num_tx_queues; i++) { | ||
5698 | struct ixgbe_ring *tx_ring = adapter->tx_ring[i]; | ||
5699 | restart_queue += tx_ring->tx_stats.restart_queue; | ||
5700 | tx_busy += tx_ring->tx_stats.tx_busy; | ||
5701 | bytes += tx_ring->stats.bytes; | ||
5702 | packets += tx_ring->stats.packets; | ||
5703 | } | ||
5704 | adapter->restart_queue = restart_queue; | ||
5705 | adapter->tx_busy = tx_busy; | ||
5706 | netdev->stats.tx_bytes = bytes; | ||
5707 | netdev->stats.tx_packets = packets; | ||
5708 | |||
5709 | hwstats->crcerrs += IXGBE_READ_REG(hw, IXGBE_CRCERRS); | ||
5710 | for (i = 0; i < 8; i++) { | ||
5711 | /* for packet buffers not used, the register should read 0 */ | ||
5712 | mpc = IXGBE_READ_REG(hw, IXGBE_MPC(i)); | ||
5713 | missed_rx += mpc; | ||
5714 | hwstats->mpc[i] += mpc; | ||
5715 | total_mpc += hwstats->mpc[i]; | ||
5716 | if (hw->mac.type == ixgbe_mac_82598EB) | ||
5717 | hwstats->rnbc[i] += IXGBE_READ_REG(hw, IXGBE_RNBC(i)); | ||
5718 | hwstats->qptc[i] += IXGBE_READ_REG(hw, IXGBE_QPTC(i)); | ||
5719 | hwstats->qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC(i)); | ||
5720 | hwstats->qprc[i] += IXGBE_READ_REG(hw, IXGBE_QPRC(i)); | ||
5721 | hwstats->qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC(i)); | ||
5722 | switch (hw->mac.type) { | ||
5723 | case ixgbe_mac_82598EB: | ||
5724 | hwstats->pxonrxc[i] += | ||
5725 | IXGBE_READ_REG(hw, IXGBE_PXONRXC(i)); | ||
5726 | break; | ||
5727 | case ixgbe_mac_82599EB: | ||
5728 | case ixgbe_mac_X540: | ||
5729 | hwstats->pxonrxc[i] += | ||
5730 | IXGBE_READ_REG(hw, IXGBE_PXONRXCNT(i)); | ||
5731 | break; | ||
5732 | default: | ||
5733 | break; | ||
5734 | } | ||
5735 | hwstats->pxontxc[i] += IXGBE_READ_REG(hw, IXGBE_PXONTXC(i)); | ||
5736 | hwstats->pxofftxc[i] += IXGBE_READ_REG(hw, IXGBE_PXOFFTXC(i)); | ||
5737 | } | ||
5738 | hwstats->gprc += IXGBE_READ_REG(hw, IXGBE_GPRC); | ||
5739 | /* work around hardware counting issue */ | ||
5740 | hwstats->gprc -= missed_rx; | ||
5741 | |||
5742 | ixgbe_update_xoff_received(adapter); | ||
5743 | |||
5744 | /* 82598 hardware only has a 32 bit counter in the high register */ | ||
5745 | switch (hw->mac.type) { | ||
5746 | case ixgbe_mac_82598EB: | ||
5747 | hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXC); | ||
5748 | hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCH); | ||
5749 | hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCH); | ||
5750 | hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORH); | ||
5751 | break; | ||
5752 | case ixgbe_mac_X540: | ||
5753 | /* OS2BMC stats are X540 only*/ | ||
5754 | hwstats->o2bgptc += IXGBE_READ_REG(hw, IXGBE_O2BGPTC); | ||
5755 | hwstats->o2bspc += IXGBE_READ_REG(hw, IXGBE_O2BSPC); | ||
5756 | hwstats->b2ospc += IXGBE_READ_REG(hw, IXGBE_B2OSPC); | ||
5757 | hwstats->b2ogprc += IXGBE_READ_REG(hw, IXGBE_B2OGPRC); | ||
5758 | case ixgbe_mac_82599EB: | ||
5759 | hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCL); | ||
5760 | IXGBE_READ_REG(hw, IXGBE_GORCH); /* to clear */ | ||
5761 | hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCL); | ||
5762 | IXGBE_READ_REG(hw, IXGBE_GOTCH); /* to clear */ | ||
5763 | hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORL); | ||
5764 | IXGBE_READ_REG(hw, IXGBE_TORH); /* to clear */ | ||
5765 | hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXCNT); | ||
5766 | hwstats->fdirmatch += IXGBE_READ_REG(hw, IXGBE_FDIRMATCH); | ||
5767 | hwstats->fdirmiss += IXGBE_READ_REG(hw, IXGBE_FDIRMISS); | ||
5768 | #ifdef IXGBE_FCOE | ||
5769 | hwstats->fccrc += IXGBE_READ_REG(hw, IXGBE_FCCRC); | ||
5770 | hwstats->fcoerpdc += IXGBE_READ_REG(hw, IXGBE_FCOERPDC); | ||
5771 | hwstats->fcoeprc += IXGBE_READ_REG(hw, IXGBE_FCOEPRC); | ||
5772 | hwstats->fcoeptc += IXGBE_READ_REG(hw, IXGBE_FCOEPTC); | ||
5773 | hwstats->fcoedwrc += IXGBE_READ_REG(hw, IXGBE_FCOEDWRC); | ||
5774 | hwstats->fcoedwtc += IXGBE_READ_REG(hw, IXGBE_FCOEDWTC); | ||
5775 | #endif /* IXGBE_FCOE */ | ||
5776 | break; | ||
5777 | default: | ||
5778 | break; | ||
5779 | } | ||
5780 | bprc = IXGBE_READ_REG(hw, IXGBE_BPRC); | ||
5781 | hwstats->bprc += bprc; | ||
5782 | hwstats->mprc += IXGBE_READ_REG(hw, IXGBE_MPRC); | ||
5783 | if (hw->mac.type == ixgbe_mac_82598EB) | ||
5784 | hwstats->mprc -= bprc; | ||
5785 | hwstats->roc += IXGBE_READ_REG(hw, IXGBE_ROC); | ||
5786 | hwstats->prc64 += IXGBE_READ_REG(hw, IXGBE_PRC64); | ||
5787 | hwstats->prc127 += IXGBE_READ_REG(hw, IXGBE_PRC127); | ||
5788 | hwstats->prc255 += IXGBE_READ_REG(hw, IXGBE_PRC255); | ||
5789 | hwstats->prc511 += IXGBE_READ_REG(hw, IXGBE_PRC511); | ||
5790 | hwstats->prc1023 += IXGBE_READ_REG(hw, IXGBE_PRC1023); | ||
5791 | hwstats->prc1522 += IXGBE_READ_REG(hw, IXGBE_PRC1522); | ||
5792 | hwstats->rlec += IXGBE_READ_REG(hw, IXGBE_RLEC); | ||
5793 | lxon = IXGBE_READ_REG(hw, IXGBE_LXONTXC); | ||
5794 | hwstats->lxontxc += lxon; | ||
5795 | lxoff = IXGBE_READ_REG(hw, IXGBE_LXOFFTXC); | ||
5796 | hwstats->lxofftxc += lxoff; | ||
5797 | hwstats->ruc += IXGBE_READ_REG(hw, IXGBE_RUC); | ||
5798 | hwstats->gptc += IXGBE_READ_REG(hw, IXGBE_GPTC); | ||
5799 | hwstats->mptc += IXGBE_READ_REG(hw, IXGBE_MPTC); | ||
5800 | /* | ||
5801 | * 82598 errata - tx of flow control packets is included in tx counters | ||
5802 | */ | ||
5803 | xon_off_tot = lxon + lxoff; | ||
5804 | hwstats->gptc -= xon_off_tot; | ||
5805 | hwstats->mptc -= xon_off_tot; | ||
5806 | hwstats->gotc -= (xon_off_tot * (ETH_ZLEN + ETH_FCS_LEN)); | ||
5807 | hwstats->ruc += IXGBE_READ_REG(hw, IXGBE_RUC); | ||
5808 | hwstats->rfc += IXGBE_READ_REG(hw, IXGBE_RFC); | ||
5809 | hwstats->rjc += IXGBE_READ_REG(hw, IXGBE_RJC); | ||
5810 | hwstats->tpr += IXGBE_READ_REG(hw, IXGBE_TPR); | ||
5811 | hwstats->ptc64 += IXGBE_READ_REG(hw, IXGBE_PTC64); | ||
5812 | hwstats->ptc64 -= xon_off_tot; | ||
5813 | hwstats->ptc127 += IXGBE_READ_REG(hw, IXGBE_PTC127); | ||
5814 | hwstats->ptc255 += IXGBE_READ_REG(hw, IXGBE_PTC255); | ||
5815 | hwstats->ptc511 += IXGBE_READ_REG(hw, IXGBE_PTC511); | ||
5816 | hwstats->ptc1023 += IXGBE_READ_REG(hw, IXGBE_PTC1023); | ||
5817 | hwstats->ptc1522 += IXGBE_READ_REG(hw, IXGBE_PTC1522); | ||
5818 | hwstats->bptc += IXGBE_READ_REG(hw, IXGBE_BPTC); | ||
5819 | |||
5820 | /* Fill out the OS statistics structure */ | ||
5821 | netdev->stats.multicast = hwstats->mprc; | ||
5822 | |||
5823 | /* Rx Errors */ | ||
5824 | netdev->stats.rx_errors = hwstats->crcerrs + hwstats->rlec; | ||
5825 | netdev->stats.rx_dropped = 0; | ||
5826 | netdev->stats.rx_length_errors = hwstats->rlec; | ||
5827 | netdev->stats.rx_crc_errors = hwstats->crcerrs; | ||
5828 | netdev->stats.rx_missed_errors = total_mpc; | ||
5829 | } | ||
5830 | |||
5831 | /** | ||
5832 | * ixgbe_fdir_reinit_subtask - worker thread to reinit FDIR filter table | ||
5833 | * @adapter - pointer to the device adapter structure | ||
5834 | **/ | ||
5835 | static void ixgbe_fdir_reinit_subtask(struct ixgbe_adapter *adapter) | ||
5836 | { | ||
5837 | struct ixgbe_hw *hw = &adapter->hw; | ||
5838 | int i; | ||
5839 | |||
5840 | if (!(adapter->flags2 & IXGBE_FLAG2_FDIR_REQUIRES_REINIT)) | ||
5841 | return; | ||
5842 | |||
5843 | adapter->flags2 &= ~IXGBE_FLAG2_FDIR_REQUIRES_REINIT; | ||
5844 | |||
5845 | /* if interface is down do nothing */ | ||
5846 | if (test_bit(__IXGBE_DOWN, &adapter->state)) | ||
5847 | return; | ||
5848 | |||
5849 | /* do nothing if we are not using signature filters */ | ||
5850 | if (!(adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE)) | ||
5851 | return; | ||
5852 | |||
5853 | adapter->fdir_overflow++; | ||
5854 | |||
5855 | if (ixgbe_reinit_fdir_tables_82599(hw) == 0) { | ||
5856 | for (i = 0; i < adapter->num_tx_queues; i++) | ||
5857 | set_bit(__IXGBE_TX_FDIR_INIT_DONE, | ||
5858 | &(adapter->tx_ring[i]->state)); | ||
5859 | /* re-enable flow director interrupts */ | ||
5860 | IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMS_FLOW_DIR); | ||
5861 | } else { | ||
5862 | e_err(probe, "failed to finish FDIR re-initialization, " | ||
5863 | "ignored adding FDIR ATR filters\n"); | ||
5864 | } | ||
5865 | } | ||
5866 | |||
5867 | /** | ||
5868 | * ixgbe_check_hang_subtask - check for hung queues and dropped interrupts | ||
5869 | * @adapter - pointer to the device adapter structure | ||
5870 | * | ||
5871 | * This function serves two purposes. First it strobes the interrupt lines | ||
5872 | * in order to make certain interrupts are occuring. Secondly it sets the | ||
5873 | * bits needed to check for TX hangs. As a result we should immediately | ||
5874 | * determine if a hang has occured. | ||
5875 | */ | ||
5876 | static void ixgbe_check_hang_subtask(struct ixgbe_adapter *adapter) | ||
5877 | { | ||
5878 | struct ixgbe_hw *hw = &adapter->hw; | ||
5879 | u64 eics = 0; | ||
5880 | int i; | ||
5881 | |||
5882 | /* If we're down or resetting, just bail */ | ||
5883 | if (test_bit(__IXGBE_DOWN, &adapter->state) || | ||
5884 | test_bit(__IXGBE_RESETTING, &adapter->state)) | ||
5885 | return; | ||
5886 | |||
5887 | /* Force detection of hung controller */ | ||
5888 | if (netif_carrier_ok(adapter->netdev)) { | ||
5889 | for (i = 0; i < adapter->num_tx_queues; i++) | ||
5890 | set_check_for_tx_hang(adapter->tx_ring[i]); | ||
5891 | } | ||
5892 | |||
5893 | if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) { | ||
5894 | /* | ||
5895 | * for legacy and MSI interrupts don't set any bits | ||
5896 | * that are enabled for EIAM, because this operation | ||
5897 | * would set *both* EIMS and EICS for any bit in EIAM | ||
5898 | */ | ||
5899 | IXGBE_WRITE_REG(hw, IXGBE_EICS, | ||
5900 | (IXGBE_EICS_TCP_TIMER | IXGBE_EICS_OTHER)); | ||
5901 | } else { | ||
5902 | /* get one bit for every active tx/rx interrupt vector */ | ||
5903 | for (i = 0; i < adapter->num_msix_vectors - NON_Q_VECTORS; i++) { | ||
5904 | struct ixgbe_q_vector *qv = adapter->q_vector[i]; | ||
5905 | if (qv->rx.count || qv->tx.count) | ||
5906 | eics |= ((u64)1 << i); | ||
5907 | } | ||
5908 | } | ||
5909 | |||
5910 | /* Cause software interrupt to ensure rings are cleaned */ | ||
5911 | ixgbe_irq_rearm_queues(adapter, eics); | ||
5912 | |||
5913 | } | ||
5914 | |||
5915 | /** | ||
5916 | * ixgbe_watchdog_update_link - update the link status | ||
5917 | * @adapter - pointer to the device adapter structure | ||
5918 | * @link_speed - pointer to a u32 to store the link_speed | ||
5919 | **/ | ||
5920 | static void ixgbe_watchdog_update_link(struct ixgbe_adapter *adapter) | ||
5921 | { | ||
5922 | struct ixgbe_hw *hw = &adapter->hw; | ||
5923 | u32 link_speed = adapter->link_speed; | ||
5924 | bool link_up = adapter->link_up; | ||
5925 | int i; | ||
5926 | |||
5927 | if (!(adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE)) | ||
5928 | return; | ||
5929 | |||
5930 | if (hw->mac.ops.check_link) { | ||
5931 | hw->mac.ops.check_link(hw, &link_speed, &link_up, false); | ||
5932 | } else { | ||
5933 | /* always assume link is up, if no check link function */ | ||
5934 | link_speed = IXGBE_LINK_SPEED_10GB_FULL; | ||
5935 | link_up = true; | ||
5936 | } | ||
5937 | if (link_up) { | ||
5938 | if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) { | ||
5939 | for (i = 0; i < MAX_TRAFFIC_CLASS; i++) | ||
5940 | hw->mac.ops.fc_enable(hw, i); | ||
5941 | } else { | ||
5942 | hw->mac.ops.fc_enable(hw, 0); | ||
5943 | } | ||
5944 | } | ||
5945 | |||
5946 | if (link_up || | ||
5947 | time_after(jiffies, (adapter->link_check_timeout + | ||
5948 | IXGBE_TRY_LINK_TIMEOUT))) { | ||
5949 | adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE; | ||
5950 | IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMC_LSC); | ||
5951 | IXGBE_WRITE_FLUSH(hw); | ||
5952 | } | ||
5953 | |||
5954 | adapter->link_up = link_up; | ||
5955 | adapter->link_speed = link_speed; | ||
5956 | } | ||
5957 | |||
5958 | /** | ||
5959 | * ixgbe_watchdog_link_is_up - update netif_carrier status and | ||
5960 | * print link up message | ||
5961 | * @adapter - pointer to the device adapter structure | ||
5962 | **/ | ||
5963 | static void ixgbe_watchdog_link_is_up(struct ixgbe_adapter *adapter) | ||
5964 | { | ||
5965 | struct net_device *netdev = adapter->netdev; | ||
5966 | struct ixgbe_hw *hw = &adapter->hw; | ||
5967 | u32 link_speed = adapter->link_speed; | ||
5968 | bool flow_rx, flow_tx; | ||
5969 | |||
5970 | /* only continue if link was previously down */ | ||
5971 | if (netif_carrier_ok(netdev)) | ||
5972 | return; | ||
5973 | |||
5974 | adapter->flags2 &= ~IXGBE_FLAG2_SEARCH_FOR_SFP; | ||
5975 | |||
5976 | switch (hw->mac.type) { | ||
5977 | case ixgbe_mac_82598EB: { | ||
5978 | u32 frctl = IXGBE_READ_REG(hw, IXGBE_FCTRL); | ||
5979 | u32 rmcs = IXGBE_READ_REG(hw, IXGBE_RMCS); | ||
5980 | flow_rx = !!(frctl & IXGBE_FCTRL_RFCE); | ||
5981 | flow_tx = !!(rmcs & IXGBE_RMCS_TFCE_802_3X); | ||
5982 | } | ||
5983 | break; | ||
5984 | case ixgbe_mac_X540: | ||
5985 | case ixgbe_mac_82599EB: { | ||
5986 | u32 mflcn = IXGBE_READ_REG(hw, IXGBE_MFLCN); | ||
5987 | u32 fccfg = IXGBE_READ_REG(hw, IXGBE_FCCFG); | ||
5988 | flow_rx = !!(mflcn & IXGBE_MFLCN_RFCE); | ||
5989 | flow_tx = !!(fccfg & IXGBE_FCCFG_TFCE_802_3X); | ||
5990 | } | ||
5991 | break; | ||
5992 | default: | ||
5993 | flow_tx = false; | ||
5994 | flow_rx = false; | ||
5995 | break; | ||
5996 | } | ||
5997 | e_info(drv, "NIC Link is Up %s, Flow Control: %s\n", | ||
5998 | (link_speed == IXGBE_LINK_SPEED_10GB_FULL ? | ||
5999 | "10 Gbps" : | ||
6000 | (link_speed == IXGBE_LINK_SPEED_1GB_FULL ? | ||
6001 | "1 Gbps" : | ||
6002 | (link_speed == IXGBE_LINK_SPEED_100_FULL ? | ||
6003 | "100 Mbps" : | ||
6004 | "unknown speed"))), | ||
6005 | ((flow_rx && flow_tx) ? "RX/TX" : | ||
6006 | (flow_rx ? "RX" : | ||
6007 | (flow_tx ? "TX" : "None")))); | ||
6008 | |||
6009 | netif_carrier_on(netdev); | ||
6010 | ixgbe_check_vf_rate_limit(adapter); | ||
6011 | } | ||
6012 | |||
6013 | /** | ||
6014 | * ixgbe_watchdog_link_is_down - update netif_carrier status and | ||
6015 | * print link down message | ||
6016 | * @adapter - pointer to the adapter structure | ||
6017 | **/ | ||
6018 | static void ixgbe_watchdog_link_is_down(struct ixgbe_adapter* adapter) | ||
6019 | { | ||
6020 | struct net_device *netdev = adapter->netdev; | ||
6021 | struct ixgbe_hw *hw = &adapter->hw; | ||
6022 | |||
6023 | adapter->link_up = false; | ||
6024 | adapter->link_speed = 0; | ||
6025 | |||
6026 | /* only continue if link was up previously */ | ||
6027 | if (!netif_carrier_ok(netdev)) | ||
6028 | return; | ||
6029 | |||
6030 | /* poll for SFP+ cable when link is down */ | ||
6031 | if (ixgbe_is_sfp(hw) && hw->mac.type == ixgbe_mac_82598EB) | ||
6032 | adapter->flags2 |= IXGBE_FLAG2_SEARCH_FOR_SFP; | ||
6033 | |||
6034 | e_info(drv, "NIC Link is Down\n"); | ||
6035 | netif_carrier_off(netdev); | ||
6036 | } | ||
6037 | |||
6038 | /** | ||
6039 | * ixgbe_watchdog_flush_tx - flush queues on link down | ||
6040 | * @adapter - pointer to the device adapter structure | ||
6041 | **/ | ||
6042 | static void ixgbe_watchdog_flush_tx(struct ixgbe_adapter *adapter) | ||
6043 | { | ||
6044 | int i; | ||
6045 | int some_tx_pending = 0; | ||
6046 | |||
6047 | if (!netif_carrier_ok(adapter->netdev)) { | ||
6048 | for (i = 0; i < adapter->num_tx_queues; i++) { | ||
6049 | struct ixgbe_ring *tx_ring = adapter->tx_ring[i]; | ||
6050 | if (tx_ring->next_to_use != tx_ring->next_to_clean) { | ||
6051 | some_tx_pending = 1; | ||
6052 | break; | ||
6053 | } | ||
6054 | } | ||
6055 | |||
6056 | if (some_tx_pending) { | ||
6057 | /* We've lost link, so the controller stops DMA, | ||
6058 | * but we've got queued Tx work that's never going | ||
6059 | * to get done, so reset controller to flush Tx. | ||
6060 | * (Do the reset outside of interrupt context). | ||
6061 | */ | ||
6062 | adapter->flags2 |= IXGBE_FLAG2_RESET_REQUESTED; | ||
6063 | } | ||
6064 | } | ||
6065 | } | ||
6066 | |||
6067 | static void ixgbe_spoof_check(struct ixgbe_adapter *adapter) | ||
6068 | { | ||
6069 | u32 ssvpc; | ||
6070 | |||
6071 | /* Do not perform spoof check for 82598 */ | ||
6072 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) | ||
6073 | return; | ||
6074 | |||
6075 | ssvpc = IXGBE_READ_REG(&adapter->hw, IXGBE_SSVPC); | ||
6076 | |||
6077 | /* | ||
6078 | * ssvpc register is cleared on read, if zero then no | ||
6079 | * spoofed packets in the last interval. | ||
6080 | */ | ||
6081 | if (!ssvpc) | ||
6082 | return; | ||
6083 | |||
6084 | e_warn(drv, "%d Spoofed packets detected\n", ssvpc); | ||
6085 | } | ||
6086 | |||
6087 | /** | ||
6088 | * ixgbe_watchdog_subtask - check and bring link up | ||
6089 | * @adapter - pointer to the device adapter structure | ||
6090 | **/ | ||
6091 | static void ixgbe_watchdog_subtask(struct ixgbe_adapter *adapter) | ||
6092 | { | ||
6093 | /* if interface is down do nothing */ | ||
6094 | if (test_bit(__IXGBE_DOWN, &adapter->state)) | ||
6095 | return; | ||
6096 | |||
6097 | ixgbe_watchdog_update_link(adapter); | ||
6098 | |||
6099 | if (adapter->link_up) | ||
6100 | ixgbe_watchdog_link_is_up(adapter); | ||
6101 | else | ||
6102 | ixgbe_watchdog_link_is_down(adapter); | ||
6103 | |||
6104 | ixgbe_spoof_check(adapter); | ||
6105 | ixgbe_update_stats(adapter); | ||
6106 | |||
6107 | ixgbe_watchdog_flush_tx(adapter); | ||
6108 | } | ||
6109 | |||
6110 | /** | ||
6111 | * ixgbe_sfp_detection_subtask - poll for SFP+ cable | ||
6112 | * @adapter - the ixgbe adapter structure | ||
6113 | **/ | ||
6114 | static void ixgbe_sfp_detection_subtask(struct ixgbe_adapter *adapter) | ||
6115 | { | ||
6116 | struct ixgbe_hw *hw = &adapter->hw; | ||
6117 | s32 err; | ||
6118 | |||
6119 | /* not searching for SFP so there is nothing to do here */ | ||
6120 | if (!(adapter->flags2 & IXGBE_FLAG2_SEARCH_FOR_SFP) && | ||
6121 | !(adapter->flags2 & IXGBE_FLAG2_SFP_NEEDS_RESET)) | ||
6122 | return; | ||
6123 | |||
6124 | /* someone else is in init, wait until next service event */ | ||
6125 | if (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state)) | ||
6126 | return; | ||
6127 | |||
6128 | err = hw->phy.ops.identify_sfp(hw); | ||
6129 | if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) | ||
6130 | goto sfp_out; | ||
6131 | |||
6132 | if (err == IXGBE_ERR_SFP_NOT_PRESENT) { | ||
6133 | /* If no cable is present, then we need to reset | ||
6134 | * the next time we find a good cable. */ | ||
6135 | adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET; | ||
6136 | } | ||
6137 | |||
6138 | /* exit on error */ | ||
6139 | if (err) | ||
6140 | goto sfp_out; | ||
6141 | |||
6142 | /* exit if reset not needed */ | ||
6143 | if (!(adapter->flags2 & IXGBE_FLAG2_SFP_NEEDS_RESET)) | ||
6144 | goto sfp_out; | ||
6145 | |||
6146 | adapter->flags2 &= ~IXGBE_FLAG2_SFP_NEEDS_RESET; | ||
6147 | |||
6148 | /* | ||
6149 | * A module may be identified correctly, but the EEPROM may not have | ||
6150 | * support for that module. setup_sfp() will fail in that case, so | ||
6151 | * we should not allow that module to load. | ||
6152 | */ | ||
6153 | if (hw->mac.type == ixgbe_mac_82598EB) | ||
6154 | err = hw->phy.ops.reset(hw); | ||
6155 | else | ||
6156 | err = hw->mac.ops.setup_sfp(hw); | ||
6157 | |||
6158 | if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) | ||
6159 | goto sfp_out; | ||
6160 | |||
6161 | adapter->flags |= IXGBE_FLAG_NEED_LINK_CONFIG; | ||
6162 | e_info(probe, "detected SFP+: %d\n", hw->phy.sfp_type); | ||
6163 | |||
6164 | sfp_out: | ||
6165 | clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state); | ||
6166 | |||
6167 | if ((err == IXGBE_ERR_SFP_NOT_SUPPORTED) && | ||
6168 | (adapter->netdev->reg_state == NETREG_REGISTERED)) { | ||
6169 | e_dev_err("failed to initialize because an unsupported " | ||
6170 | "SFP+ module type was detected.\n"); | ||
6171 | e_dev_err("Reload the driver after installing a " | ||
6172 | "supported module.\n"); | ||
6173 | unregister_netdev(adapter->netdev); | ||
6174 | } | ||
6175 | } | ||
6176 | |||
6177 | /** | ||
6178 | * ixgbe_sfp_link_config_subtask - set up link SFP after module install | ||
6179 | * @adapter - the ixgbe adapter structure | ||
6180 | **/ | ||
6181 | static void ixgbe_sfp_link_config_subtask(struct ixgbe_adapter *adapter) | ||
6182 | { | ||
6183 | struct ixgbe_hw *hw = &adapter->hw; | ||
6184 | u32 autoneg; | ||
6185 | bool negotiation; | ||
6186 | |||
6187 | if (!(adapter->flags & IXGBE_FLAG_NEED_LINK_CONFIG)) | ||
6188 | return; | ||
6189 | |||
6190 | /* someone else is in init, wait until next service event */ | ||
6191 | if (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state)) | ||
6192 | return; | ||
6193 | |||
6194 | adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG; | ||
6195 | |||
6196 | autoneg = hw->phy.autoneg_advertised; | ||
6197 | if ((!autoneg) && (hw->mac.ops.get_link_capabilities)) | ||
6198 | hw->mac.ops.get_link_capabilities(hw, &autoneg, &negotiation); | ||
6199 | hw->mac.autotry_restart = false; | ||
6200 | if (hw->mac.ops.setup_link) | ||
6201 | hw->mac.ops.setup_link(hw, autoneg, negotiation, true); | ||
6202 | |||
6203 | adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE; | ||
6204 | adapter->link_check_timeout = jiffies; | ||
6205 | clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state); | ||
6206 | } | ||
6207 | |||
6208 | /** | ||
6209 | * ixgbe_service_timer - Timer Call-back | ||
6210 | * @data: pointer to adapter cast into an unsigned long | ||
6211 | **/ | ||
6212 | static void ixgbe_service_timer(unsigned long data) | ||
6213 | { | ||
6214 | struct ixgbe_adapter *adapter = (struct ixgbe_adapter *)data; | ||
6215 | unsigned long next_event_offset; | ||
6216 | |||
6217 | /* poll faster when waiting for link */ | ||
6218 | if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE) | ||
6219 | next_event_offset = HZ / 10; | ||
6220 | else | ||
6221 | next_event_offset = HZ * 2; | ||
6222 | |||
6223 | /* Reset the timer */ | ||
6224 | mod_timer(&adapter->service_timer, next_event_offset + jiffies); | ||
6225 | |||
6226 | ixgbe_service_event_schedule(adapter); | ||
6227 | } | ||
6228 | |||
6229 | static void ixgbe_reset_subtask(struct ixgbe_adapter *adapter) | ||
6230 | { | ||
6231 | if (!(adapter->flags2 & IXGBE_FLAG2_RESET_REQUESTED)) | ||
6232 | return; | ||
6233 | |||
6234 | adapter->flags2 &= ~IXGBE_FLAG2_RESET_REQUESTED; | ||
6235 | |||
6236 | /* If we're already down or resetting, just bail */ | ||
6237 | if (test_bit(__IXGBE_DOWN, &adapter->state) || | ||
6238 | test_bit(__IXGBE_RESETTING, &adapter->state)) | ||
6239 | return; | ||
6240 | |||
6241 | ixgbe_dump(adapter); | ||
6242 | netdev_err(adapter->netdev, "Reset adapter\n"); | ||
6243 | adapter->tx_timeout_count++; | ||
6244 | |||
6245 | ixgbe_reinit_locked(adapter); | ||
6246 | } | ||
6247 | |||
6248 | /** | ||
6249 | * ixgbe_service_task - manages and runs subtasks | ||
6250 | * @work: pointer to work_struct containing our data | ||
6251 | **/ | ||
6252 | static void ixgbe_service_task(struct work_struct *work) | ||
6253 | { | ||
6254 | struct ixgbe_adapter *adapter = container_of(work, | ||
6255 | struct ixgbe_adapter, | ||
6256 | service_task); | ||
6257 | |||
6258 | ixgbe_reset_subtask(adapter); | ||
6259 | ixgbe_sfp_detection_subtask(adapter); | ||
6260 | ixgbe_sfp_link_config_subtask(adapter); | ||
6261 | ixgbe_check_overtemp_subtask(adapter); | ||
6262 | ixgbe_watchdog_subtask(adapter); | ||
6263 | ixgbe_fdir_reinit_subtask(adapter); | ||
6264 | ixgbe_check_hang_subtask(adapter); | ||
6265 | |||
6266 | ixgbe_service_event_complete(adapter); | ||
6267 | } | ||
6268 | |||
6269 | void ixgbe_tx_ctxtdesc(struct ixgbe_ring *tx_ring, u32 vlan_macip_lens, | ||
6270 | u32 fcoe_sof_eof, u32 type_tucmd, u32 mss_l4len_idx) | ||
6271 | { | ||
6272 | struct ixgbe_adv_tx_context_desc *context_desc; | ||
6273 | u16 i = tx_ring->next_to_use; | ||
6274 | |||
6275 | context_desc = IXGBE_TX_CTXTDESC_ADV(tx_ring, i); | ||
6276 | |||
6277 | i++; | ||
6278 | tx_ring->next_to_use = (i < tx_ring->count) ? i : 0; | ||
6279 | |||
6280 | /* set bits to identify this as an advanced context descriptor */ | ||
6281 | type_tucmd |= IXGBE_TXD_CMD_DEXT | IXGBE_ADVTXD_DTYP_CTXT; | ||
6282 | |||
6283 | context_desc->vlan_macip_lens = cpu_to_le32(vlan_macip_lens); | ||
6284 | context_desc->seqnum_seed = cpu_to_le32(fcoe_sof_eof); | ||
6285 | context_desc->type_tucmd_mlhl = cpu_to_le32(type_tucmd); | ||
6286 | context_desc->mss_l4len_idx = cpu_to_le32(mss_l4len_idx); | ||
6287 | } | ||
6288 | |||
6289 | static int ixgbe_tso(struct ixgbe_ring *tx_ring, struct sk_buff *skb, | ||
6290 | u32 tx_flags, __be16 protocol, u8 *hdr_len) | ||
6291 | { | ||
6292 | int err; | ||
6293 | u32 vlan_macip_lens, type_tucmd; | ||
6294 | u32 mss_l4len_idx, l4len; | ||
6295 | |||
6296 | if (!skb_is_gso(skb)) | ||
6297 | return 0; | ||
6298 | |||
6299 | if (skb_header_cloned(skb)) { | ||
6300 | err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC); | ||
6301 | if (err) | ||
6302 | return err; | ||
6303 | } | ||
6304 | |||
6305 | /* ADV DTYP TUCMD MKRLOC/ISCSIHEDLEN */ | ||
6306 | type_tucmd = IXGBE_ADVTXD_TUCMD_L4T_TCP; | ||
6307 | |||
6308 | if (protocol == __constant_htons(ETH_P_IP)) { | ||
6309 | struct iphdr *iph = ip_hdr(skb); | ||
6310 | iph->tot_len = 0; | ||
6311 | iph->check = 0; | ||
6312 | tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr, | ||
6313 | iph->daddr, 0, | ||
6314 | IPPROTO_TCP, | ||
6315 | 0); | ||
6316 | type_tucmd |= IXGBE_ADVTXD_TUCMD_IPV4; | ||
6317 | } else if (skb_is_gso_v6(skb)) { | ||
6318 | ipv6_hdr(skb)->payload_len = 0; | ||
6319 | tcp_hdr(skb)->check = | ||
6320 | ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr, | ||
6321 | &ipv6_hdr(skb)->daddr, | ||
6322 | 0, IPPROTO_TCP, 0); | ||
6323 | } | ||
6324 | |||
6325 | l4len = tcp_hdrlen(skb); | ||
6326 | *hdr_len = skb_transport_offset(skb) + l4len; | ||
6327 | |||
6328 | /* mss_l4len_id: use 1 as index for TSO */ | ||
6329 | mss_l4len_idx = l4len << IXGBE_ADVTXD_L4LEN_SHIFT; | ||
6330 | mss_l4len_idx |= skb_shinfo(skb)->gso_size << IXGBE_ADVTXD_MSS_SHIFT; | ||
6331 | mss_l4len_idx |= 1 << IXGBE_ADVTXD_IDX_SHIFT; | ||
6332 | |||
6333 | /* vlan_macip_lens: HEADLEN, MACLEN, VLAN tag */ | ||
6334 | vlan_macip_lens = skb_network_header_len(skb); | ||
6335 | vlan_macip_lens |= skb_network_offset(skb) << IXGBE_ADVTXD_MACLEN_SHIFT; | ||
6336 | vlan_macip_lens |= tx_flags & IXGBE_TX_FLAGS_VLAN_MASK; | ||
6337 | |||
6338 | ixgbe_tx_ctxtdesc(tx_ring, vlan_macip_lens, 0, type_tucmd, | ||
6339 | mss_l4len_idx); | ||
6340 | |||
6341 | return 1; | ||
6342 | } | ||
6343 | |||
6344 | static bool ixgbe_tx_csum(struct ixgbe_ring *tx_ring, | ||
6345 | struct sk_buff *skb, u32 tx_flags, | ||
6346 | __be16 protocol) | ||
6347 | { | ||
6348 | u32 vlan_macip_lens = 0; | ||
6349 | u32 mss_l4len_idx = 0; | ||
6350 | u32 type_tucmd = 0; | ||
6351 | |||
6352 | if (skb->ip_summed != CHECKSUM_PARTIAL) { | ||
6353 | if (!(tx_flags & IXGBE_TX_FLAGS_VLAN)) | ||
6354 | return false; | ||
6355 | } else { | ||
6356 | u8 l4_hdr = 0; | ||
6357 | switch (protocol) { | ||
6358 | case __constant_htons(ETH_P_IP): | ||
6359 | vlan_macip_lens |= skb_network_header_len(skb); | ||
6360 | type_tucmd |= IXGBE_ADVTXD_TUCMD_IPV4; | ||
6361 | l4_hdr = ip_hdr(skb)->protocol; | ||
6362 | break; | ||
6363 | case __constant_htons(ETH_P_IPV6): | ||
6364 | vlan_macip_lens |= skb_network_header_len(skb); | ||
6365 | l4_hdr = ipv6_hdr(skb)->nexthdr; | ||
6366 | break; | ||
6367 | default: | ||
6368 | if (unlikely(net_ratelimit())) { | ||
6369 | dev_warn(tx_ring->dev, | ||
6370 | "partial checksum but proto=%x!\n", | ||
6371 | skb->protocol); | ||
6372 | } | ||
6373 | break; | ||
6374 | } | ||
6375 | |||
6376 | switch (l4_hdr) { | ||
6377 | case IPPROTO_TCP: | ||
6378 | type_tucmd |= IXGBE_ADVTXD_TUCMD_L4T_TCP; | ||
6379 | mss_l4len_idx = tcp_hdrlen(skb) << | ||
6380 | IXGBE_ADVTXD_L4LEN_SHIFT; | ||
6381 | break; | ||
6382 | case IPPROTO_SCTP: | ||
6383 | type_tucmd |= IXGBE_ADVTXD_TUCMD_L4T_SCTP; | ||
6384 | mss_l4len_idx = sizeof(struct sctphdr) << | ||
6385 | IXGBE_ADVTXD_L4LEN_SHIFT; | ||
6386 | break; | ||
6387 | case IPPROTO_UDP: | ||
6388 | mss_l4len_idx = sizeof(struct udphdr) << | ||
6389 | IXGBE_ADVTXD_L4LEN_SHIFT; | ||
6390 | break; | ||
6391 | default: | ||
6392 | if (unlikely(net_ratelimit())) { | ||
6393 | dev_warn(tx_ring->dev, | ||
6394 | "partial checksum but l4 proto=%x!\n", | ||
6395 | skb->protocol); | ||
6396 | } | ||
6397 | break; | ||
6398 | } | ||
6399 | } | ||
6400 | |||
6401 | vlan_macip_lens |= skb_network_offset(skb) << IXGBE_ADVTXD_MACLEN_SHIFT; | ||
6402 | vlan_macip_lens |= tx_flags & IXGBE_TX_FLAGS_VLAN_MASK; | ||
6403 | |||
6404 | ixgbe_tx_ctxtdesc(tx_ring, vlan_macip_lens, 0, | ||
6405 | type_tucmd, mss_l4len_idx); | ||
6406 | |||
6407 | return (skb->ip_summed == CHECKSUM_PARTIAL); | ||
6408 | } | ||
6409 | |||
6410 | static int ixgbe_tx_map(struct ixgbe_adapter *adapter, | ||
6411 | struct ixgbe_ring *tx_ring, | ||
6412 | struct sk_buff *skb, u32 tx_flags, | ||
6413 | unsigned int first, const u8 hdr_len) | ||
6414 | { | ||
6415 | struct device *dev = tx_ring->dev; | ||
6416 | struct ixgbe_tx_buffer *tx_buffer_info; | ||
6417 | unsigned int len; | ||
6418 | unsigned int total = skb->len; | ||
6419 | unsigned int offset = 0, size, count = 0; | ||
6420 | unsigned int nr_frags = skb_shinfo(skb)->nr_frags; | ||
6421 | unsigned int f; | ||
6422 | unsigned int bytecount = skb->len; | ||
6423 | u16 gso_segs = 1; | ||
6424 | u16 i; | ||
6425 | |||
6426 | i = tx_ring->next_to_use; | ||
6427 | |||
6428 | if (tx_flags & IXGBE_TX_FLAGS_FCOE) | ||
6429 | /* excluding fcoe_crc_eof for FCoE */ | ||
6430 | total -= sizeof(struct fcoe_crc_eof); | ||
6431 | |||
6432 | len = min(skb_headlen(skb), total); | ||
6433 | while (len) { | ||
6434 | tx_buffer_info = &tx_ring->tx_buffer_info[i]; | ||
6435 | size = min(len, (uint)IXGBE_MAX_DATA_PER_TXD); | ||
6436 | |||
6437 | tx_buffer_info->length = size; | ||
6438 | tx_buffer_info->mapped_as_page = false; | ||
6439 | tx_buffer_info->dma = dma_map_single(dev, | ||
6440 | skb->data + offset, | ||
6441 | size, DMA_TO_DEVICE); | ||
6442 | if (dma_mapping_error(dev, tx_buffer_info->dma)) | ||
6443 | goto dma_error; | ||
6444 | tx_buffer_info->time_stamp = jiffies; | ||
6445 | tx_buffer_info->next_to_watch = i; | ||
6446 | |||
6447 | len -= size; | ||
6448 | total -= size; | ||
6449 | offset += size; | ||
6450 | count++; | ||
6451 | |||
6452 | if (len) { | ||
6453 | i++; | ||
6454 | if (i == tx_ring->count) | ||
6455 | i = 0; | ||
6456 | } | ||
6457 | } | ||
6458 | |||
6459 | for (f = 0; f < nr_frags; f++) { | ||
6460 | struct skb_frag_struct *frag; | ||
6461 | |||
6462 | frag = &skb_shinfo(skb)->frags[f]; | ||
6463 | len = min((unsigned int)frag->size, total); | ||
6464 | offset = frag->page_offset; | ||
6465 | |||
6466 | while (len) { | ||
6467 | i++; | ||
6468 | if (i == tx_ring->count) | ||
6469 | i = 0; | ||
6470 | |||
6471 | tx_buffer_info = &tx_ring->tx_buffer_info[i]; | ||
6472 | size = min(len, (uint)IXGBE_MAX_DATA_PER_TXD); | ||
6473 | |||
6474 | tx_buffer_info->length = size; | ||
6475 | tx_buffer_info->dma = dma_map_page(dev, | ||
6476 | frag->page, | ||
6477 | offset, size, | ||
6478 | DMA_TO_DEVICE); | ||
6479 | tx_buffer_info->mapped_as_page = true; | ||
6480 | if (dma_mapping_error(dev, tx_buffer_info->dma)) | ||
6481 | goto dma_error; | ||
6482 | tx_buffer_info->time_stamp = jiffies; | ||
6483 | tx_buffer_info->next_to_watch = i; | ||
6484 | |||
6485 | len -= size; | ||
6486 | total -= size; | ||
6487 | offset += size; | ||
6488 | count++; | ||
6489 | } | ||
6490 | if (total == 0) | ||
6491 | break; | ||
6492 | } | ||
6493 | |||
6494 | if (tx_flags & IXGBE_TX_FLAGS_TSO) | ||
6495 | gso_segs = skb_shinfo(skb)->gso_segs; | ||
6496 | #ifdef IXGBE_FCOE | ||
6497 | /* adjust for FCoE Sequence Offload */ | ||
6498 | else if (tx_flags & IXGBE_TX_FLAGS_FSO) | ||
6499 | gso_segs = DIV_ROUND_UP(skb->len - hdr_len, | ||
6500 | skb_shinfo(skb)->gso_size); | ||
6501 | #endif /* IXGBE_FCOE */ | ||
6502 | bytecount += (gso_segs - 1) * hdr_len; | ||
6503 | |||
6504 | /* multiply data chunks by size of headers */ | ||
6505 | tx_ring->tx_buffer_info[i].bytecount = bytecount; | ||
6506 | tx_ring->tx_buffer_info[i].gso_segs = gso_segs; | ||
6507 | tx_ring->tx_buffer_info[i].skb = skb; | ||
6508 | tx_ring->tx_buffer_info[first].next_to_watch = i; | ||
6509 | |||
6510 | return count; | ||
6511 | |||
6512 | dma_error: | ||
6513 | e_dev_err("TX DMA map failed\n"); | ||
6514 | |||
6515 | /* clear timestamp and dma mappings for failed tx_buffer_info map */ | ||
6516 | tx_buffer_info->dma = 0; | ||
6517 | tx_buffer_info->time_stamp = 0; | ||
6518 | tx_buffer_info->next_to_watch = 0; | ||
6519 | if (count) | ||
6520 | count--; | ||
6521 | |||
6522 | /* clear timestamp and dma mappings for remaining portion of packet */ | ||
6523 | while (count--) { | ||
6524 | if (i == 0) | ||
6525 | i += tx_ring->count; | ||
6526 | i--; | ||
6527 | tx_buffer_info = &tx_ring->tx_buffer_info[i]; | ||
6528 | ixgbe_unmap_and_free_tx_resource(tx_ring, tx_buffer_info); | ||
6529 | } | ||
6530 | |||
6531 | return 0; | ||
6532 | } | ||
6533 | |||
6534 | static void ixgbe_tx_queue(struct ixgbe_ring *tx_ring, | ||
6535 | int tx_flags, int count, u32 paylen, u8 hdr_len) | ||
6536 | { | ||
6537 | union ixgbe_adv_tx_desc *tx_desc = NULL; | ||
6538 | struct ixgbe_tx_buffer *tx_buffer_info; | ||
6539 | u32 olinfo_status = 0, cmd_type_len = 0; | ||
6540 | unsigned int i; | ||
6541 | u32 txd_cmd = IXGBE_TXD_CMD_EOP | IXGBE_TXD_CMD_RS | IXGBE_TXD_CMD_IFCS; | ||
6542 | |||
6543 | cmd_type_len |= IXGBE_ADVTXD_DTYP_DATA; | ||
6544 | |||
6545 | cmd_type_len |= IXGBE_ADVTXD_DCMD_IFCS | IXGBE_ADVTXD_DCMD_DEXT; | ||
6546 | |||
6547 | if (tx_flags & IXGBE_TX_FLAGS_VLAN) | ||
6548 | cmd_type_len |= IXGBE_ADVTXD_DCMD_VLE; | ||
6549 | |||
6550 | if (tx_flags & IXGBE_TX_FLAGS_TSO) { | ||
6551 | cmd_type_len |= IXGBE_ADVTXD_DCMD_TSE; | ||
6552 | |||
6553 | olinfo_status |= IXGBE_TXD_POPTS_TXSM << | ||
6554 | IXGBE_ADVTXD_POPTS_SHIFT; | ||
6555 | |||
6556 | /* use index 1 context for tso */ | ||
6557 | olinfo_status |= (1 << IXGBE_ADVTXD_IDX_SHIFT); | ||
6558 | if (tx_flags & IXGBE_TX_FLAGS_IPV4) | ||
6559 | olinfo_status |= IXGBE_TXD_POPTS_IXSM << | ||
6560 | IXGBE_ADVTXD_POPTS_SHIFT; | ||
6561 | |||
6562 | } else if (tx_flags & IXGBE_TX_FLAGS_CSUM) | ||
6563 | olinfo_status |= IXGBE_TXD_POPTS_TXSM << | ||
6564 | IXGBE_ADVTXD_POPTS_SHIFT; | ||
6565 | |||
6566 | if (tx_flags & IXGBE_TX_FLAGS_FCOE) { | ||
6567 | olinfo_status |= IXGBE_ADVTXD_CC; | ||
6568 | olinfo_status |= (1 << IXGBE_ADVTXD_IDX_SHIFT); | ||
6569 | if (tx_flags & IXGBE_TX_FLAGS_FSO) | ||
6570 | cmd_type_len |= IXGBE_ADVTXD_DCMD_TSE; | ||
6571 | } | ||
6572 | |||
6573 | olinfo_status |= ((paylen - hdr_len) << IXGBE_ADVTXD_PAYLEN_SHIFT); | ||
6574 | |||
6575 | i = tx_ring->next_to_use; | ||
6576 | while (count--) { | ||
6577 | tx_buffer_info = &tx_ring->tx_buffer_info[i]; | ||
6578 | tx_desc = IXGBE_TX_DESC_ADV(tx_ring, i); | ||
6579 | tx_desc->read.buffer_addr = cpu_to_le64(tx_buffer_info->dma); | ||
6580 | tx_desc->read.cmd_type_len = | ||
6581 | cpu_to_le32(cmd_type_len | tx_buffer_info->length); | ||
6582 | tx_desc->read.olinfo_status = cpu_to_le32(olinfo_status); | ||
6583 | i++; | ||
6584 | if (i == tx_ring->count) | ||
6585 | i = 0; | ||
6586 | } | ||
6587 | |||
6588 | tx_desc->read.cmd_type_len |= cpu_to_le32(txd_cmd); | ||
6589 | |||
6590 | /* | ||
6591 | * Force memory writes to complete before letting h/w | ||
6592 | * know there are new descriptors to fetch. (Only | ||
6593 | * applicable for weak-ordered memory model archs, | ||
6594 | * such as IA-64). | ||
6595 | */ | ||
6596 | wmb(); | ||
6597 | |||
6598 | tx_ring->next_to_use = i; | ||
6599 | writel(i, tx_ring->tail); | ||
6600 | } | ||
6601 | |||
6602 | static void ixgbe_atr(struct ixgbe_ring *ring, struct sk_buff *skb, | ||
6603 | u32 tx_flags, __be16 protocol) | ||
6604 | { | ||
6605 | struct ixgbe_q_vector *q_vector = ring->q_vector; | ||
6606 | union ixgbe_atr_hash_dword input = { .dword = 0 }; | ||
6607 | union ixgbe_atr_hash_dword common = { .dword = 0 }; | ||
6608 | union { | ||
6609 | unsigned char *network; | ||
6610 | struct iphdr *ipv4; | ||
6611 | struct ipv6hdr *ipv6; | ||
6612 | } hdr; | ||
6613 | struct tcphdr *th; | ||
6614 | __be16 vlan_id; | ||
6615 | |||
6616 | /* if ring doesn't have a interrupt vector, cannot perform ATR */ | ||
6617 | if (!q_vector) | ||
6618 | return; | ||
6619 | |||
6620 | /* do nothing if sampling is disabled */ | ||
6621 | if (!ring->atr_sample_rate) | ||
6622 | return; | ||
6623 | |||
6624 | ring->atr_count++; | ||
6625 | |||
6626 | /* snag network header to get L4 type and address */ | ||
6627 | hdr.network = skb_network_header(skb); | ||
6628 | |||
6629 | /* Currently only IPv4/IPv6 with TCP is supported */ | ||
6630 | if ((protocol != __constant_htons(ETH_P_IPV6) || | ||
6631 | hdr.ipv6->nexthdr != IPPROTO_TCP) && | ||
6632 | (protocol != __constant_htons(ETH_P_IP) || | ||
6633 | hdr.ipv4->protocol != IPPROTO_TCP)) | ||
6634 | return; | ||
6635 | |||
6636 | th = tcp_hdr(skb); | ||
6637 | |||
6638 | /* skip this packet since the socket is closing */ | ||
6639 | if (th->fin) | ||
6640 | return; | ||
6641 | |||
6642 | /* sample on all syn packets or once every atr sample count */ | ||
6643 | if (!th->syn && (ring->atr_count < ring->atr_sample_rate)) | ||
6644 | return; | ||
6645 | |||
6646 | /* reset sample count */ | ||
6647 | ring->atr_count = 0; | ||
6648 | |||
6649 | vlan_id = htons(tx_flags >> IXGBE_TX_FLAGS_VLAN_SHIFT); | ||
6650 | |||
6651 | /* | ||
6652 | * src and dst are inverted, think how the receiver sees them | ||
6653 | * | ||
6654 | * The input is broken into two sections, a non-compressed section | ||
6655 | * containing vm_pool, vlan_id, and flow_type. The rest of the data | ||
6656 | * is XORed together and stored in the compressed dword. | ||
6657 | */ | ||
6658 | input.formatted.vlan_id = vlan_id; | ||
6659 | |||
6660 | /* | ||
6661 | * since src port and flex bytes occupy the same word XOR them together | ||
6662 | * and write the value to source port portion of compressed dword | ||
6663 | */ | ||
6664 | if (vlan_id) | ||
6665 | common.port.src ^= th->dest ^ __constant_htons(ETH_P_8021Q); | ||
6666 | else | ||
6667 | common.port.src ^= th->dest ^ protocol; | ||
6668 | common.port.dst ^= th->source; | ||
6669 | |||
6670 | if (protocol == __constant_htons(ETH_P_IP)) { | ||
6671 | input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV4; | ||
6672 | common.ip ^= hdr.ipv4->saddr ^ hdr.ipv4->daddr; | ||
6673 | } else { | ||
6674 | input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV6; | ||
6675 | common.ip ^= hdr.ipv6->saddr.s6_addr32[0] ^ | ||
6676 | hdr.ipv6->saddr.s6_addr32[1] ^ | ||
6677 | hdr.ipv6->saddr.s6_addr32[2] ^ | ||
6678 | hdr.ipv6->saddr.s6_addr32[3] ^ | ||
6679 | hdr.ipv6->daddr.s6_addr32[0] ^ | ||
6680 | hdr.ipv6->daddr.s6_addr32[1] ^ | ||
6681 | hdr.ipv6->daddr.s6_addr32[2] ^ | ||
6682 | hdr.ipv6->daddr.s6_addr32[3]; | ||
6683 | } | ||
6684 | |||
6685 | /* This assumes the Rx queue and Tx queue are bound to the same CPU */ | ||
6686 | ixgbe_fdir_add_signature_filter_82599(&q_vector->adapter->hw, | ||
6687 | input, common, ring->queue_index); | ||
6688 | } | ||
6689 | |||
6690 | static int __ixgbe_maybe_stop_tx(struct ixgbe_ring *tx_ring, u16 size) | ||
6691 | { | ||
6692 | netif_stop_subqueue(tx_ring->netdev, tx_ring->queue_index); | ||
6693 | /* Herbert's original patch had: | ||
6694 | * smp_mb__after_netif_stop_queue(); | ||
6695 | * but since that doesn't exist yet, just open code it. */ | ||
6696 | smp_mb(); | ||
6697 | |||
6698 | /* We need to check again in a case another CPU has just | ||
6699 | * made room available. */ | ||
6700 | if (likely(ixgbe_desc_unused(tx_ring) < size)) | ||
6701 | return -EBUSY; | ||
6702 | |||
6703 | /* A reprieve! - use start_queue because it doesn't call schedule */ | ||
6704 | netif_start_subqueue(tx_ring->netdev, tx_ring->queue_index); | ||
6705 | ++tx_ring->tx_stats.restart_queue; | ||
6706 | return 0; | ||
6707 | } | ||
6708 | |||
6709 | static inline int ixgbe_maybe_stop_tx(struct ixgbe_ring *tx_ring, u16 size) | ||
6710 | { | ||
6711 | if (likely(ixgbe_desc_unused(tx_ring) >= size)) | ||
6712 | return 0; | ||
6713 | return __ixgbe_maybe_stop_tx(tx_ring, size); | ||
6714 | } | ||
6715 | |||
6716 | static u16 ixgbe_select_queue(struct net_device *dev, struct sk_buff *skb) | ||
6717 | { | ||
6718 | struct ixgbe_adapter *adapter = netdev_priv(dev); | ||
6719 | int txq = skb_rx_queue_recorded(skb) ? skb_get_rx_queue(skb) : | ||
6720 | smp_processor_id(); | ||
6721 | #ifdef IXGBE_FCOE | ||
6722 | __be16 protocol = vlan_get_protocol(skb); | ||
6723 | |||
6724 | if (((protocol == htons(ETH_P_FCOE)) || | ||
6725 | (protocol == htons(ETH_P_FIP))) && | ||
6726 | (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)) { | ||
6727 | txq &= (adapter->ring_feature[RING_F_FCOE].indices - 1); | ||
6728 | txq += adapter->ring_feature[RING_F_FCOE].mask; | ||
6729 | return txq; | ||
6730 | } | ||
6731 | #endif | ||
6732 | |||
6733 | if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) { | ||
6734 | while (unlikely(txq >= dev->real_num_tx_queues)) | ||
6735 | txq -= dev->real_num_tx_queues; | ||
6736 | return txq; | ||
6737 | } | ||
6738 | |||
6739 | return skb_tx_hash(dev, skb); | ||
6740 | } | ||
6741 | |||
6742 | netdev_tx_t ixgbe_xmit_frame_ring(struct sk_buff *skb, | ||
6743 | struct ixgbe_adapter *adapter, | ||
6744 | struct ixgbe_ring *tx_ring) | ||
6745 | { | ||
6746 | int tso; | ||
6747 | u32 tx_flags = 0; | ||
6748 | #if PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD | ||
6749 | unsigned short f; | ||
6750 | #endif | ||
6751 | u16 first; | ||
6752 | u16 count = TXD_USE_COUNT(skb_headlen(skb)); | ||
6753 | __be16 protocol; | ||
6754 | u8 hdr_len = 0; | ||
6755 | |||
6756 | /* | ||
6757 | * need: 1 descriptor per page * PAGE_SIZE/IXGBE_MAX_DATA_PER_TXD, | ||
6758 | * + 1 desc for skb_head_len/IXGBE_MAX_DATA_PER_TXD, | ||
6759 | * + 2 desc gap to keep tail from touching head, | ||
6760 | * + 1 desc for context descriptor, | ||
6761 | * otherwise try next time | ||
6762 | */ | ||
6763 | #if PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD | ||
6764 | for (f = 0; f < skb_shinfo(skb)->nr_frags; f++) | ||
6765 | count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size); | ||
6766 | #else | ||
6767 | count += skb_shinfo(skb)->nr_frags; | ||
6768 | #endif | ||
6769 | if (ixgbe_maybe_stop_tx(tx_ring, count + 3)) { | ||
6770 | tx_ring->tx_stats.tx_busy++; | ||
6771 | return NETDEV_TX_BUSY; | ||
6772 | } | ||
6773 | |||
6774 | protocol = vlan_get_protocol(skb); | ||
6775 | |||
6776 | if (vlan_tx_tag_present(skb)) { | ||
6777 | tx_flags |= vlan_tx_tag_get(skb); | ||
6778 | if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) { | ||
6779 | tx_flags &= ~IXGBE_TX_FLAGS_VLAN_PRIO_MASK; | ||
6780 | tx_flags |= tx_ring->dcb_tc << 13; | ||
6781 | } | ||
6782 | tx_flags <<= IXGBE_TX_FLAGS_VLAN_SHIFT; | ||
6783 | tx_flags |= IXGBE_TX_FLAGS_VLAN; | ||
6784 | } else if (adapter->flags & IXGBE_FLAG_DCB_ENABLED && | ||
6785 | skb->priority != TC_PRIO_CONTROL) { | ||
6786 | tx_flags |= tx_ring->dcb_tc << 13; | ||
6787 | tx_flags <<= IXGBE_TX_FLAGS_VLAN_SHIFT; | ||
6788 | tx_flags |= IXGBE_TX_FLAGS_VLAN; | ||
6789 | } | ||
6790 | |||
6791 | #ifdef IXGBE_FCOE | ||
6792 | /* for FCoE with DCB, we force the priority to what | ||
6793 | * was specified by the switch */ | ||
6794 | if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED && | ||
6795 | (protocol == htons(ETH_P_FCOE))) | ||
6796 | tx_flags |= IXGBE_TX_FLAGS_FCOE; | ||
6797 | |||
6798 | #endif | ||
6799 | /* record the location of the first descriptor for this packet */ | ||
6800 | first = tx_ring->next_to_use; | ||
6801 | |||
6802 | if (tx_flags & IXGBE_TX_FLAGS_FCOE) { | ||
6803 | #ifdef IXGBE_FCOE | ||
6804 | /* setup tx offload for FCoE */ | ||
6805 | tso = ixgbe_fso(tx_ring, skb, tx_flags, &hdr_len); | ||
6806 | if (tso < 0) | ||
6807 | goto out_drop; | ||
6808 | else if (tso) | ||
6809 | tx_flags |= IXGBE_TX_FLAGS_FSO; | ||
6810 | #endif /* IXGBE_FCOE */ | ||
6811 | } else { | ||
6812 | if (protocol == htons(ETH_P_IP)) | ||
6813 | tx_flags |= IXGBE_TX_FLAGS_IPV4; | ||
6814 | tso = ixgbe_tso(tx_ring, skb, tx_flags, protocol, &hdr_len); | ||
6815 | if (tso < 0) | ||
6816 | goto out_drop; | ||
6817 | else if (tso) | ||
6818 | tx_flags |= IXGBE_TX_FLAGS_TSO; | ||
6819 | else if (ixgbe_tx_csum(tx_ring, skb, tx_flags, protocol)) | ||
6820 | tx_flags |= IXGBE_TX_FLAGS_CSUM; | ||
6821 | } | ||
6822 | |||
6823 | count = ixgbe_tx_map(adapter, tx_ring, skb, tx_flags, first, hdr_len); | ||
6824 | if (count) { | ||
6825 | /* add the ATR filter if ATR is on */ | ||
6826 | if (test_bit(__IXGBE_TX_FDIR_INIT_DONE, &tx_ring->state)) | ||
6827 | ixgbe_atr(tx_ring, skb, tx_flags, protocol); | ||
6828 | ixgbe_tx_queue(tx_ring, tx_flags, count, skb->len, hdr_len); | ||
6829 | ixgbe_maybe_stop_tx(tx_ring, DESC_NEEDED); | ||
6830 | |||
6831 | } else { | ||
6832 | tx_ring->tx_buffer_info[first].time_stamp = 0; | ||
6833 | tx_ring->next_to_use = first; | ||
6834 | goto out_drop; | ||
6835 | } | ||
6836 | |||
6837 | return NETDEV_TX_OK; | ||
6838 | |||
6839 | out_drop: | ||
6840 | dev_kfree_skb_any(skb); | ||
6841 | return NETDEV_TX_OK; | ||
6842 | } | ||
6843 | |||
6844 | static netdev_tx_t ixgbe_xmit_frame(struct sk_buff *skb, struct net_device *netdev) | ||
6845 | { | ||
6846 | struct ixgbe_adapter *adapter = netdev_priv(netdev); | ||
6847 | struct ixgbe_ring *tx_ring; | ||
6848 | |||
6849 | tx_ring = adapter->tx_ring[skb->queue_mapping]; | ||
6850 | return ixgbe_xmit_frame_ring(skb, adapter, tx_ring); | ||
6851 | } | ||
6852 | |||
6853 | /** | ||
6854 | * ixgbe_set_mac - Change the Ethernet Address of the NIC | ||
6855 | * @netdev: network interface device structure | ||
6856 | * @p: pointer to an address structure | ||
6857 | * | ||
6858 | * Returns 0 on success, negative on failure | ||
6859 | **/ | ||
6860 | static int ixgbe_set_mac(struct net_device *netdev, void *p) | ||
6861 | { | ||
6862 | struct ixgbe_adapter *adapter = netdev_priv(netdev); | ||
6863 | struct ixgbe_hw *hw = &adapter->hw; | ||
6864 | struct sockaddr *addr = p; | ||
6865 | |||
6866 | if (!is_valid_ether_addr(addr->sa_data)) | ||
6867 | return -EADDRNOTAVAIL; | ||
6868 | |||
6869 | memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len); | ||
6870 | memcpy(hw->mac.addr, addr->sa_data, netdev->addr_len); | ||
6871 | |||
6872 | hw->mac.ops.set_rar(hw, 0, hw->mac.addr, adapter->num_vfs, | ||
6873 | IXGBE_RAH_AV); | ||
6874 | |||
6875 | return 0; | ||
6876 | } | ||
6877 | |||
6878 | static int | ||
6879 | ixgbe_mdio_read(struct net_device *netdev, int prtad, int devad, u16 addr) | ||
6880 | { | ||
6881 | struct ixgbe_adapter *adapter = netdev_priv(netdev); | ||
6882 | struct ixgbe_hw *hw = &adapter->hw; | ||
6883 | u16 value; | ||
6884 | int rc; | ||
6885 | |||
6886 | if (prtad != hw->phy.mdio.prtad) | ||
6887 | return -EINVAL; | ||
6888 | rc = hw->phy.ops.read_reg(hw, addr, devad, &value); | ||
6889 | if (!rc) | ||
6890 | rc = value; | ||
6891 | return rc; | ||
6892 | } | ||
6893 | |||
6894 | static int ixgbe_mdio_write(struct net_device *netdev, int prtad, int devad, | ||
6895 | u16 addr, u16 value) | ||
6896 | { | ||
6897 | struct ixgbe_adapter *adapter = netdev_priv(netdev); | ||
6898 | struct ixgbe_hw *hw = &adapter->hw; | ||
6899 | |||
6900 | if (prtad != hw->phy.mdio.prtad) | ||
6901 | return -EINVAL; | ||
6902 | return hw->phy.ops.write_reg(hw, addr, devad, value); | ||
6903 | } | ||
6904 | |||
6905 | static int ixgbe_ioctl(struct net_device *netdev, struct ifreq *req, int cmd) | ||
6906 | { | ||
6907 | struct ixgbe_adapter *adapter = netdev_priv(netdev); | ||
6908 | |||
6909 | return mdio_mii_ioctl(&adapter->hw.phy.mdio, if_mii(req), cmd); | ||
6910 | } | ||
6911 | |||
6912 | /** | ||
6913 | * ixgbe_add_sanmac_netdev - Add the SAN MAC address to the corresponding | ||
6914 | * netdev->dev_addrs | ||
6915 | * @netdev: network interface device structure | ||
6916 | * | ||
6917 | * Returns non-zero on failure | ||
6918 | **/ | ||
6919 | static int ixgbe_add_sanmac_netdev(struct net_device *dev) | ||
6920 | { | ||
6921 | int err = 0; | ||
6922 | struct ixgbe_adapter *adapter = netdev_priv(dev); | ||
6923 | struct ixgbe_mac_info *mac = &adapter->hw.mac; | ||
6924 | |||
6925 | if (is_valid_ether_addr(mac->san_addr)) { | ||
6926 | rtnl_lock(); | ||
6927 | err = dev_addr_add(dev, mac->san_addr, NETDEV_HW_ADDR_T_SAN); | ||
6928 | rtnl_unlock(); | ||
6929 | } | ||
6930 | return err; | ||
6931 | } | ||
6932 | |||
6933 | /** | ||
6934 | * ixgbe_del_sanmac_netdev - Removes the SAN MAC address to the corresponding | ||
6935 | * netdev->dev_addrs | ||
6936 | * @netdev: network interface device structure | ||
6937 | * | ||
6938 | * Returns non-zero on failure | ||
6939 | **/ | ||
6940 | static int ixgbe_del_sanmac_netdev(struct net_device *dev) | ||
6941 | { | ||
6942 | int err = 0; | ||
6943 | struct ixgbe_adapter *adapter = netdev_priv(dev); | ||
6944 | struct ixgbe_mac_info *mac = &adapter->hw.mac; | ||
6945 | |||
6946 | if (is_valid_ether_addr(mac->san_addr)) { | ||
6947 | rtnl_lock(); | ||
6948 | err = dev_addr_del(dev, mac->san_addr, NETDEV_HW_ADDR_T_SAN); | ||
6949 | rtnl_unlock(); | ||
6950 | } | ||
6951 | return err; | ||
6952 | } | ||
6953 | |||
6954 | #ifdef CONFIG_NET_POLL_CONTROLLER | ||
6955 | /* | ||
6956 | * Polling 'interrupt' - used by things like netconsole to send skbs | ||
6957 | * without having to re-enable interrupts. It's not called while | ||
6958 | * the interrupt routine is executing. | ||
6959 | */ | ||
6960 | static void ixgbe_netpoll(struct net_device *netdev) | ||
6961 | { | ||
6962 | struct ixgbe_adapter *adapter = netdev_priv(netdev); | ||
6963 | int i; | ||
6964 | |||
6965 | /* if interface is down do nothing */ | ||
6966 | if (test_bit(__IXGBE_DOWN, &adapter->state)) | ||
6967 | return; | ||
6968 | |||
6969 | adapter->flags |= IXGBE_FLAG_IN_NETPOLL; | ||
6970 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { | ||
6971 | int num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; | ||
6972 | for (i = 0; i < num_q_vectors; i++) { | ||
6973 | struct ixgbe_q_vector *q_vector = adapter->q_vector[i]; | ||
6974 | ixgbe_msix_clean_many(0, q_vector); | ||
6975 | } | ||
6976 | } else { | ||
6977 | ixgbe_intr(adapter->pdev->irq, netdev); | ||
6978 | } | ||
6979 | adapter->flags &= ~IXGBE_FLAG_IN_NETPOLL; | ||
6980 | } | ||
6981 | #endif | ||
6982 | |||
6983 | static struct rtnl_link_stats64 *ixgbe_get_stats64(struct net_device *netdev, | ||
6984 | struct rtnl_link_stats64 *stats) | ||
6985 | { | ||
6986 | struct ixgbe_adapter *adapter = netdev_priv(netdev); | ||
6987 | int i; | ||
6988 | |||
6989 | rcu_read_lock(); | ||
6990 | for (i = 0; i < adapter->num_rx_queues; i++) { | ||
6991 | struct ixgbe_ring *ring = ACCESS_ONCE(adapter->rx_ring[i]); | ||
6992 | u64 bytes, packets; | ||
6993 | unsigned int start; | ||
6994 | |||
6995 | if (ring) { | ||
6996 | do { | ||
6997 | start = u64_stats_fetch_begin_bh(&ring->syncp); | ||
6998 | packets = ring->stats.packets; | ||
6999 | bytes = ring->stats.bytes; | ||
7000 | } while (u64_stats_fetch_retry_bh(&ring->syncp, start)); | ||
7001 | stats->rx_packets += packets; | ||
7002 | stats->rx_bytes += bytes; | ||
7003 | } | ||
7004 | } | ||
7005 | |||
7006 | for (i = 0; i < adapter->num_tx_queues; i++) { | ||
7007 | struct ixgbe_ring *ring = ACCESS_ONCE(adapter->tx_ring[i]); | ||
7008 | u64 bytes, packets; | ||
7009 | unsigned int start; | ||
7010 | |||
7011 | if (ring) { | ||
7012 | do { | ||
7013 | start = u64_stats_fetch_begin_bh(&ring->syncp); | ||
7014 | packets = ring->stats.packets; | ||
7015 | bytes = ring->stats.bytes; | ||
7016 | } while (u64_stats_fetch_retry_bh(&ring->syncp, start)); | ||
7017 | stats->tx_packets += packets; | ||
7018 | stats->tx_bytes += bytes; | ||
7019 | } | ||
7020 | } | ||
7021 | rcu_read_unlock(); | ||
7022 | /* following stats updated by ixgbe_watchdog_task() */ | ||
7023 | stats->multicast = netdev->stats.multicast; | ||
7024 | stats->rx_errors = netdev->stats.rx_errors; | ||
7025 | stats->rx_length_errors = netdev->stats.rx_length_errors; | ||
7026 | stats->rx_crc_errors = netdev->stats.rx_crc_errors; | ||
7027 | stats->rx_missed_errors = netdev->stats.rx_missed_errors; | ||
7028 | return stats; | ||
7029 | } | ||
7030 | |||
7031 | /* ixgbe_validate_rtr - verify 802.1Qp to Rx packet buffer mapping is valid. | ||
7032 | * #adapter: pointer to ixgbe_adapter | ||
7033 | * @tc: number of traffic classes currently enabled | ||
7034 | * | ||
7035 | * Configure a valid 802.1Qp to Rx packet buffer mapping ie confirm | ||
7036 | * 802.1Q priority maps to a packet buffer that exists. | ||
7037 | */ | ||
7038 | static void ixgbe_validate_rtr(struct ixgbe_adapter *adapter, u8 tc) | ||
7039 | { | ||
7040 | struct ixgbe_hw *hw = &adapter->hw; | ||
7041 | u32 reg, rsave; | ||
7042 | int i; | ||
7043 | |||
7044 | /* 82598 have a static priority to TC mapping that can not | ||
7045 | * be changed so no validation is needed. | ||
7046 | */ | ||
7047 | if (hw->mac.type == ixgbe_mac_82598EB) | ||
7048 | return; | ||
7049 | |||
7050 | reg = IXGBE_READ_REG(hw, IXGBE_RTRUP2TC); | ||
7051 | rsave = reg; | ||
7052 | |||
7053 | for (i = 0; i < MAX_TRAFFIC_CLASS; i++) { | ||
7054 | u8 up2tc = reg >> (i * IXGBE_RTRUP2TC_UP_SHIFT); | ||
7055 | |||
7056 | /* If up2tc is out of bounds default to zero */ | ||
7057 | if (up2tc > tc) | ||
7058 | reg &= ~(0x7 << IXGBE_RTRUP2TC_UP_SHIFT); | ||
7059 | } | ||
7060 | |||
7061 | if (reg != rsave) | ||
7062 | IXGBE_WRITE_REG(hw, IXGBE_RTRUP2TC, reg); | ||
7063 | |||
7064 | return; | ||
7065 | } | ||
7066 | |||
7067 | |||
7068 | /* ixgbe_setup_tc - routine to configure net_device for multiple traffic | ||
7069 | * classes. | ||
7070 | * | ||
7071 | * @netdev: net device to configure | ||
7072 | * @tc: number of traffic classes to enable | ||
7073 | */ | ||
7074 | int ixgbe_setup_tc(struct net_device *dev, u8 tc) | ||
7075 | { | ||
7076 | struct ixgbe_adapter *adapter = netdev_priv(dev); | ||
7077 | struct ixgbe_hw *hw = &adapter->hw; | ||
7078 | |||
7079 | /* If DCB is anabled do not remove traffic classes, multiple | ||
7080 | * traffic classes are required to implement DCB | ||
7081 | */ | ||
7082 | if (!tc && (adapter->flags & IXGBE_FLAG_DCB_ENABLED)) | ||
7083 | return 0; | ||
7084 | |||
7085 | /* Hardware supports up to 8 traffic classes */ | ||
7086 | if (tc > MAX_TRAFFIC_CLASS || | ||
7087 | (hw->mac.type == ixgbe_mac_82598EB && tc < MAX_TRAFFIC_CLASS)) | ||
7088 | return -EINVAL; | ||
7089 | |||
7090 | /* Hardware has to reinitialize queues and interrupts to | ||
7091 | * match packet buffer alignment. Unfortunantly, the | ||
7092 | * hardware is not flexible enough to do this dynamically. | ||
7093 | */ | ||
7094 | if (netif_running(dev)) | ||
7095 | ixgbe_close(dev); | ||
7096 | ixgbe_clear_interrupt_scheme(adapter); | ||
7097 | |||
7098 | if (tc) | ||
7099 | netdev_set_num_tc(dev, tc); | ||
7100 | else | ||
7101 | netdev_reset_tc(dev); | ||
7102 | |||
7103 | ixgbe_init_interrupt_scheme(adapter); | ||
7104 | ixgbe_validate_rtr(adapter, tc); | ||
7105 | if (netif_running(dev)) | ||
7106 | ixgbe_open(dev); | ||
7107 | |||
7108 | return 0; | ||
7109 | } | ||
7110 | |||
7111 | void ixgbe_do_reset(struct net_device *netdev) | ||
7112 | { | ||
7113 | struct ixgbe_adapter *adapter = netdev_priv(netdev); | ||
7114 | |||
7115 | if (netif_running(netdev)) | ||
7116 | ixgbe_reinit_locked(adapter); | ||
7117 | else | ||
7118 | ixgbe_reset(adapter); | ||
7119 | } | ||
7120 | |||
7121 | static u32 ixgbe_fix_features(struct net_device *netdev, u32 data) | ||
7122 | { | ||
7123 | struct ixgbe_adapter *adapter = netdev_priv(netdev); | ||
7124 | |||
7125 | #ifdef CONFIG_DCB | ||
7126 | if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) | ||
7127 | data &= ~NETIF_F_HW_VLAN_RX; | ||
7128 | #endif | ||
7129 | |||
7130 | /* return error if RXHASH is being enabled when RSS is not supported */ | ||
7131 | if (!(adapter->flags & IXGBE_FLAG_RSS_ENABLED)) | ||
7132 | data &= ~NETIF_F_RXHASH; | ||
7133 | |||
7134 | /* If Rx checksum is disabled, then RSC/LRO should also be disabled */ | ||
7135 | if (!(data & NETIF_F_RXCSUM)) | ||
7136 | data &= ~NETIF_F_LRO; | ||
7137 | |||
7138 | /* Turn off LRO if not RSC capable or invalid ITR settings */ | ||
7139 | if (!(adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE)) { | ||
7140 | data &= ~NETIF_F_LRO; | ||
7141 | } else if (!(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) && | ||
7142 | (adapter->rx_itr_setting != 1 && | ||
7143 | adapter->rx_itr_setting > IXGBE_MAX_RSC_INT_RATE)) { | ||
7144 | data &= ~NETIF_F_LRO; | ||
7145 | e_info(probe, "rx-usecs set too low, not enabling RSC\n"); | ||
7146 | } | ||
7147 | |||
7148 | return data; | ||
7149 | } | ||
7150 | |||
7151 | static int ixgbe_set_features(struct net_device *netdev, u32 data) | ||
7152 | { | ||
7153 | struct ixgbe_adapter *adapter = netdev_priv(netdev); | ||
7154 | bool need_reset = false; | ||
7155 | |||
7156 | /* If Rx checksum is disabled, then RSC/LRO should also be disabled */ | ||
7157 | if (!(data & NETIF_F_RXCSUM)) | ||
7158 | adapter->flags &= ~IXGBE_FLAG_RX_CSUM_ENABLED; | ||
7159 | else | ||
7160 | adapter->flags |= IXGBE_FLAG_RX_CSUM_ENABLED; | ||
7161 | |||
7162 | /* Make sure RSC matches LRO, reset if change */ | ||
7163 | if (!!(data & NETIF_F_LRO) != | ||
7164 | !!(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)) { | ||
7165 | adapter->flags2 ^= IXGBE_FLAG2_RSC_ENABLED; | ||
7166 | switch (adapter->hw.mac.type) { | ||
7167 | case ixgbe_mac_X540: | ||
7168 | case ixgbe_mac_82599EB: | ||
7169 | need_reset = true; | ||
7170 | break; | ||
7171 | default: | ||
7172 | break; | ||
7173 | } | ||
7174 | } | ||
7175 | |||
7176 | /* | ||
7177 | * Check if Flow Director n-tuple support was enabled or disabled. If | ||
7178 | * the state changed, we need to reset. | ||
7179 | */ | ||
7180 | if (!(adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)) { | ||
7181 | /* turn off ATR, enable perfect filters and reset */ | ||
7182 | if (data & NETIF_F_NTUPLE) { | ||
7183 | adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE; | ||
7184 | adapter->flags |= IXGBE_FLAG_FDIR_PERFECT_CAPABLE; | ||
7185 | need_reset = true; | ||
7186 | } | ||
7187 | } else if (!(data & NETIF_F_NTUPLE)) { | ||
7188 | /* turn off Flow Director, set ATR and reset */ | ||
7189 | adapter->flags &= ~IXGBE_FLAG_FDIR_PERFECT_CAPABLE; | ||
7190 | if ((adapter->flags & IXGBE_FLAG_RSS_ENABLED) && | ||
7191 | !(adapter->flags & IXGBE_FLAG_DCB_ENABLED)) | ||
7192 | adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE; | ||
7193 | need_reset = true; | ||
7194 | } | ||
7195 | |||
7196 | if (need_reset) | ||
7197 | ixgbe_do_reset(netdev); | ||
7198 | |||
7199 | return 0; | ||
7200 | |||
7201 | } | ||
7202 | |||
7203 | static const struct net_device_ops ixgbe_netdev_ops = { | ||
7204 | .ndo_open = ixgbe_open, | ||
7205 | .ndo_stop = ixgbe_close, | ||
7206 | .ndo_start_xmit = ixgbe_xmit_frame, | ||
7207 | .ndo_select_queue = ixgbe_select_queue, | ||
7208 | .ndo_set_rx_mode = ixgbe_set_rx_mode, | ||
7209 | .ndo_set_multicast_list = ixgbe_set_rx_mode, | ||
7210 | .ndo_validate_addr = eth_validate_addr, | ||
7211 | .ndo_set_mac_address = ixgbe_set_mac, | ||
7212 | .ndo_change_mtu = ixgbe_change_mtu, | ||
7213 | .ndo_tx_timeout = ixgbe_tx_timeout, | ||
7214 | .ndo_vlan_rx_add_vid = ixgbe_vlan_rx_add_vid, | ||
7215 | .ndo_vlan_rx_kill_vid = ixgbe_vlan_rx_kill_vid, | ||
7216 | .ndo_do_ioctl = ixgbe_ioctl, | ||
7217 | .ndo_set_vf_mac = ixgbe_ndo_set_vf_mac, | ||
7218 | .ndo_set_vf_vlan = ixgbe_ndo_set_vf_vlan, | ||
7219 | .ndo_set_vf_tx_rate = ixgbe_ndo_set_vf_bw, | ||
7220 | .ndo_get_vf_config = ixgbe_ndo_get_vf_config, | ||
7221 | .ndo_get_stats64 = ixgbe_get_stats64, | ||
7222 | .ndo_setup_tc = ixgbe_setup_tc, | ||
7223 | #ifdef CONFIG_NET_POLL_CONTROLLER | ||
7224 | .ndo_poll_controller = ixgbe_netpoll, | ||
7225 | #endif | ||
7226 | #ifdef IXGBE_FCOE | ||
7227 | .ndo_fcoe_ddp_setup = ixgbe_fcoe_ddp_get, | ||
7228 | .ndo_fcoe_ddp_target = ixgbe_fcoe_ddp_target, | ||
7229 | .ndo_fcoe_ddp_done = ixgbe_fcoe_ddp_put, | ||
7230 | .ndo_fcoe_enable = ixgbe_fcoe_enable, | ||
7231 | .ndo_fcoe_disable = ixgbe_fcoe_disable, | ||
7232 | .ndo_fcoe_get_wwn = ixgbe_fcoe_get_wwn, | ||
7233 | #endif /* IXGBE_FCOE */ | ||
7234 | .ndo_set_features = ixgbe_set_features, | ||
7235 | .ndo_fix_features = ixgbe_fix_features, | ||
7236 | }; | ||
7237 | |||
7238 | static void __devinit ixgbe_probe_vf(struct ixgbe_adapter *adapter, | ||
7239 | const struct ixgbe_info *ii) | ||
7240 | { | ||
7241 | #ifdef CONFIG_PCI_IOV | ||
7242 | struct ixgbe_hw *hw = &adapter->hw; | ||
7243 | int err; | ||
7244 | int num_vf_macvlans, i; | ||
7245 | struct vf_macvlans *mv_list; | ||
7246 | |||
7247 | if (hw->mac.type == ixgbe_mac_82598EB || !max_vfs) | ||
7248 | return; | ||
7249 | |||
7250 | /* The 82599 supports up to 64 VFs per physical function | ||
7251 | * but this implementation limits allocation to 63 so that | ||
7252 | * basic networking resources are still available to the | ||
7253 | * physical function | ||
7254 | */ | ||
7255 | adapter->num_vfs = (max_vfs > 63) ? 63 : max_vfs; | ||
7256 | adapter->flags |= IXGBE_FLAG_SRIOV_ENABLED; | ||
7257 | err = pci_enable_sriov(adapter->pdev, adapter->num_vfs); | ||
7258 | if (err) { | ||
7259 | e_err(probe, "Failed to enable PCI sriov: %d\n", err); | ||
7260 | goto err_novfs; | ||
7261 | } | ||
7262 | |||
7263 | num_vf_macvlans = hw->mac.num_rar_entries - | ||
7264 | (IXGBE_MAX_PF_MACVLANS + 1 + adapter->num_vfs); | ||
7265 | |||
7266 | adapter->mv_list = mv_list = kcalloc(num_vf_macvlans, | ||
7267 | sizeof(struct vf_macvlans), | ||
7268 | GFP_KERNEL); | ||
7269 | if (mv_list) { | ||
7270 | /* Initialize list of VF macvlans */ | ||
7271 | INIT_LIST_HEAD(&adapter->vf_mvs.l); | ||
7272 | for (i = 0; i < num_vf_macvlans; i++) { | ||
7273 | mv_list->vf = -1; | ||
7274 | mv_list->free = true; | ||
7275 | mv_list->rar_entry = hw->mac.num_rar_entries - | ||
7276 | (i + adapter->num_vfs + 1); | ||
7277 | list_add(&mv_list->l, &adapter->vf_mvs.l); | ||
7278 | mv_list++; | ||
7279 | } | ||
7280 | } | ||
7281 | |||
7282 | /* If call to enable VFs succeeded then allocate memory | ||
7283 | * for per VF control structures. | ||
7284 | */ | ||
7285 | adapter->vfinfo = | ||
7286 | kcalloc(adapter->num_vfs, | ||
7287 | sizeof(struct vf_data_storage), GFP_KERNEL); | ||
7288 | if (adapter->vfinfo) { | ||
7289 | /* Now that we're sure SR-IOV is enabled | ||
7290 | * and memory allocated set up the mailbox parameters | ||
7291 | */ | ||
7292 | ixgbe_init_mbx_params_pf(hw); | ||
7293 | memcpy(&hw->mbx.ops, ii->mbx_ops, | ||
7294 | sizeof(hw->mbx.ops)); | ||
7295 | |||
7296 | /* Disable RSC when in SR-IOV mode */ | ||
7297 | adapter->flags2 &= ~(IXGBE_FLAG2_RSC_CAPABLE | | ||
7298 | IXGBE_FLAG2_RSC_ENABLED); | ||
7299 | return; | ||
7300 | } | ||
7301 | |||
7302 | /* Oh oh */ | ||
7303 | e_err(probe, "Unable to allocate memory for VF Data Storage - " | ||
7304 | "SRIOV disabled\n"); | ||
7305 | pci_disable_sriov(adapter->pdev); | ||
7306 | |||
7307 | err_novfs: | ||
7308 | adapter->flags &= ~IXGBE_FLAG_SRIOV_ENABLED; | ||
7309 | adapter->num_vfs = 0; | ||
7310 | #endif /* CONFIG_PCI_IOV */ | ||
7311 | } | ||
7312 | |||
7313 | /** | ||
7314 | * ixgbe_probe - Device Initialization Routine | ||
7315 | * @pdev: PCI device information struct | ||
7316 | * @ent: entry in ixgbe_pci_tbl | ||
7317 | * | ||
7318 | * Returns 0 on success, negative on failure | ||
7319 | * | ||
7320 | * ixgbe_probe initializes an adapter identified by a pci_dev structure. | ||
7321 | * The OS initialization, configuring of the adapter private structure, | ||
7322 | * and a hardware reset occur. | ||
7323 | **/ | ||
7324 | static int __devinit ixgbe_probe(struct pci_dev *pdev, | ||
7325 | const struct pci_device_id *ent) | ||
7326 | { | ||
7327 | struct net_device *netdev; | ||
7328 | struct ixgbe_adapter *adapter = NULL; | ||
7329 | struct ixgbe_hw *hw; | ||
7330 | const struct ixgbe_info *ii = ixgbe_info_tbl[ent->driver_data]; | ||
7331 | static int cards_found; | ||
7332 | int i, err, pci_using_dac; | ||
7333 | u8 part_str[IXGBE_PBANUM_LENGTH]; | ||
7334 | unsigned int indices = num_possible_cpus(); | ||
7335 | #ifdef IXGBE_FCOE | ||
7336 | u16 device_caps; | ||
7337 | #endif | ||
7338 | u32 eec; | ||
7339 | |||
7340 | /* Catch broken hardware that put the wrong VF device ID in | ||
7341 | * the PCIe SR-IOV capability. | ||
7342 | */ | ||
7343 | if (pdev->is_virtfn) { | ||
7344 | WARN(1, KERN_ERR "%s (%hx:%hx) should not be a VF!\n", | ||
7345 | pci_name(pdev), pdev->vendor, pdev->device); | ||
7346 | return -EINVAL; | ||
7347 | } | ||
7348 | |||
7349 | err = pci_enable_device_mem(pdev); | ||
7350 | if (err) | ||
7351 | return err; | ||
7352 | |||
7353 | if (!dma_set_mask(&pdev->dev, DMA_BIT_MASK(64)) && | ||
7354 | !dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(64))) { | ||
7355 | pci_using_dac = 1; | ||
7356 | } else { | ||
7357 | err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32)); | ||
7358 | if (err) { | ||
7359 | err = dma_set_coherent_mask(&pdev->dev, | ||
7360 | DMA_BIT_MASK(32)); | ||
7361 | if (err) { | ||
7362 | dev_err(&pdev->dev, | ||
7363 | "No usable DMA configuration, aborting\n"); | ||
7364 | goto err_dma; | ||
7365 | } | ||
7366 | } | ||
7367 | pci_using_dac = 0; | ||
7368 | } | ||
7369 | |||
7370 | err = pci_request_selected_regions(pdev, pci_select_bars(pdev, | ||
7371 | IORESOURCE_MEM), ixgbe_driver_name); | ||
7372 | if (err) { | ||
7373 | dev_err(&pdev->dev, | ||
7374 | "pci_request_selected_regions failed 0x%x\n", err); | ||
7375 | goto err_pci_reg; | ||
7376 | } | ||
7377 | |||
7378 | pci_enable_pcie_error_reporting(pdev); | ||
7379 | |||
7380 | pci_set_master(pdev); | ||
7381 | pci_save_state(pdev); | ||
7382 | |||
7383 | #ifdef CONFIG_IXGBE_DCB | ||
7384 | indices *= MAX_TRAFFIC_CLASS; | ||
7385 | #endif | ||
7386 | |||
7387 | if (ii->mac == ixgbe_mac_82598EB) | ||
7388 | indices = min_t(unsigned int, indices, IXGBE_MAX_RSS_INDICES); | ||
7389 | else | ||
7390 | indices = min_t(unsigned int, indices, IXGBE_MAX_FDIR_INDICES); | ||
7391 | |||
7392 | #ifdef IXGBE_FCOE | ||
7393 | indices += min_t(unsigned int, num_possible_cpus(), | ||
7394 | IXGBE_MAX_FCOE_INDICES); | ||
7395 | #endif | ||
7396 | netdev = alloc_etherdev_mq(sizeof(struct ixgbe_adapter), indices); | ||
7397 | if (!netdev) { | ||
7398 | err = -ENOMEM; | ||
7399 | goto err_alloc_etherdev; | ||
7400 | } | ||
7401 | |||
7402 | SET_NETDEV_DEV(netdev, &pdev->dev); | ||
7403 | |||
7404 | adapter = netdev_priv(netdev); | ||
7405 | pci_set_drvdata(pdev, adapter); | ||
7406 | |||
7407 | adapter->netdev = netdev; | ||
7408 | adapter->pdev = pdev; | ||
7409 | hw = &adapter->hw; | ||
7410 | hw->back = adapter; | ||
7411 | adapter->msg_enable = (1 << DEFAULT_DEBUG_LEVEL_SHIFT) - 1; | ||
7412 | |||
7413 | hw->hw_addr = ioremap(pci_resource_start(pdev, 0), | ||
7414 | pci_resource_len(pdev, 0)); | ||
7415 | if (!hw->hw_addr) { | ||
7416 | err = -EIO; | ||
7417 | goto err_ioremap; | ||
7418 | } | ||
7419 | |||
7420 | for (i = 1; i <= 5; i++) { | ||
7421 | if (pci_resource_len(pdev, i) == 0) | ||
7422 | continue; | ||
7423 | } | ||
7424 | |||
7425 | netdev->netdev_ops = &ixgbe_netdev_ops; | ||
7426 | ixgbe_set_ethtool_ops(netdev); | ||
7427 | netdev->watchdog_timeo = 5 * HZ; | ||
7428 | strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1); | ||
7429 | |||
7430 | adapter->bd_number = cards_found; | ||
7431 | |||
7432 | /* Setup hw api */ | ||
7433 | memcpy(&hw->mac.ops, ii->mac_ops, sizeof(hw->mac.ops)); | ||
7434 | hw->mac.type = ii->mac; | ||
7435 | |||
7436 | /* EEPROM */ | ||
7437 | memcpy(&hw->eeprom.ops, ii->eeprom_ops, sizeof(hw->eeprom.ops)); | ||
7438 | eec = IXGBE_READ_REG(hw, IXGBE_EEC); | ||
7439 | /* If EEPROM is valid (bit 8 = 1), use default otherwise use bit bang */ | ||
7440 | if (!(eec & (1 << 8))) | ||
7441 | hw->eeprom.ops.read = &ixgbe_read_eeprom_bit_bang_generic; | ||
7442 | |||
7443 | /* PHY */ | ||
7444 | memcpy(&hw->phy.ops, ii->phy_ops, sizeof(hw->phy.ops)); | ||
7445 | hw->phy.sfp_type = ixgbe_sfp_type_unknown; | ||
7446 | /* ixgbe_identify_phy_generic will set prtad and mmds properly */ | ||
7447 | hw->phy.mdio.prtad = MDIO_PRTAD_NONE; | ||
7448 | hw->phy.mdio.mmds = 0; | ||
7449 | hw->phy.mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22; | ||
7450 | hw->phy.mdio.dev = netdev; | ||
7451 | hw->phy.mdio.mdio_read = ixgbe_mdio_read; | ||
7452 | hw->phy.mdio.mdio_write = ixgbe_mdio_write; | ||
7453 | |||
7454 | ii->get_invariants(hw); | ||
7455 | |||
7456 | /* setup the private structure */ | ||
7457 | err = ixgbe_sw_init(adapter); | ||
7458 | if (err) | ||
7459 | goto err_sw_init; | ||
7460 | |||
7461 | /* Make it possible the adapter to be woken up via WOL */ | ||
7462 | switch (adapter->hw.mac.type) { | ||
7463 | case ixgbe_mac_82599EB: | ||
7464 | case ixgbe_mac_X540: | ||
7465 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0); | ||
7466 | break; | ||
7467 | default: | ||
7468 | break; | ||
7469 | } | ||
7470 | |||
7471 | /* | ||
7472 | * If there is a fan on this device and it has failed log the | ||
7473 | * failure. | ||
7474 | */ | ||
7475 | if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) { | ||
7476 | u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP); | ||
7477 | if (esdp & IXGBE_ESDP_SDP1) | ||
7478 | e_crit(probe, "Fan has stopped, replace the adapter\n"); | ||
7479 | } | ||
7480 | |||
7481 | /* reset_hw fills in the perm_addr as well */ | ||
7482 | hw->phy.reset_if_overtemp = true; | ||
7483 | err = hw->mac.ops.reset_hw(hw); | ||
7484 | hw->phy.reset_if_overtemp = false; | ||
7485 | if (err == IXGBE_ERR_SFP_NOT_PRESENT && | ||
7486 | hw->mac.type == ixgbe_mac_82598EB) { | ||
7487 | err = 0; | ||
7488 | } else if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) { | ||
7489 | e_dev_err("failed to load because an unsupported SFP+ " | ||
7490 | "module type was detected.\n"); | ||
7491 | e_dev_err("Reload the driver after installing a supported " | ||
7492 | "module.\n"); | ||
7493 | goto err_sw_init; | ||
7494 | } else if (err) { | ||
7495 | e_dev_err("HW Init failed: %d\n", err); | ||
7496 | goto err_sw_init; | ||
7497 | } | ||
7498 | |||
7499 | ixgbe_probe_vf(adapter, ii); | ||
7500 | |||
7501 | netdev->features = NETIF_F_SG | | ||
7502 | NETIF_F_IP_CSUM | | ||
7503 | NETIF_F_IPV6_CSUM | | ||
7504 | NETIF_F_HW_VLAN_TX | | ||
7505 | NETIF_F_HW_VLAN_RX | | ||
7506 | NETIF_F_HW_VLAN_FILTER | | ||
7507 | NETIF_F_TSO | | ||
7508 | NETIF_F_TSO6 | | ||
7509 | NETIF_F_GRO | | ||
7510 | NETIF_F_RXHASH | | ||
7511 | NETIF_F_RXCSUM; | ||
7512 | |||
7513 | netdev->hw_features = netdev->features; | ||
7514 | |||
7515 | switch (adapter->hw.mac.type) { | ||
7516 | case ixgbe_mac_82599EB: | ||
7517 | case ixgbe_mac_X540: | ||
7518 | netdev->features |= NETIF_F_SCTP_CSUM; | ||
7519 | netdev->hw_features |= NETIF_F_SCTP_CSUM | | ||
7520 | NETIF_F_NTUPLE; | ||
7521 | break; | ||
7522 | default: | ||
7523 | break; | ||
7524 | } | ||
7525 | |||
7526 | netdev->vlan_features |= NETIF_F_TSO; | ||
7527 | netdev->vlan_features |= NETIF_F_TSO6; | ||
7528 | netdev->vlan_features |= NETIF_F_IP_CSUM; | ||
7529 | netdev->vlan_features |= NETIF_F_IPV6_CSUM; | ||
7530 | netdev->vlan_features |= NETIF_F_SG; | ||
7531 | |||
7532 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) | ||
7533 | adapter->flags &= ~(IXGBE_FLAG_RSS_ENABLED | | ||
7534 | IXGBE_FLAG_DCB_ENABLED); | ||
7535 | |||
7536 | #ifdef CONFIG_IXGBE_DCB | ||
7537 | netdev->dcbnl_ops = &dcbnl_ops; | ||
7538 | #endif | ||
7539 | |||
7540 | #ifdef IXGBE_FCOE | ||
7541 | if (adapter->flags & IXGBE_FLAG_FCOE_CAPABLE) { | ||
7542 | if (hw->mac.ops.get_device_caps) { | ||
7543 | hw->mac.ops.get_device_caps(hw, &device_caps); | ||
7544 | if (device_caps & IXGBE_DEVICE_CAPS_FCOE_OFFLOADS) | ||
7545 | adapter->flags &= ~IXGBE_FLAG_FCOE_CAPABLE; | ||
7546 | } | ||
7547 | } | ||
7548 | if (adapter->flags & IXGBE_FLAG_FCOE_CAPABLE) { | ||
7549 | netdev->vlan_features |= NETIF_F_FCOE_CRC; | ||
7550 | netdev->vlan_features |= NETIF_F_FSO; | ||
7551 | netdev->vlan_features |= NETIF_F_FCOE_MTU; | ||
7552 | } | ||
7553 | #endif /* IXGBE_FCOE */ | ||
7554 | if (pci_using_dac) { | ||
7555 | netdev->features |= NETIF_F_HIGHDMA; | ||
7556 | netdev->vlan_features |= NETIF_F_HIGHDMA; | ||
7557 | } | ||
7558 | |||
7559 | if (adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE) | ||
7560 | netdev->hw_features |= NETIF_F_LRO; | ||
7561 | if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) | ||
7562 | netdev->features |= NETIF_F_LRO; | ||
7563 | |||
7564 | /* make sure the EEPROM is good */ | ||
7565 | if (hw->eeprom.ops.validate_checksum(hw, NULL) < 0) { | ||
7566 | e_dev_err("The EEPROM Checksum Is Not Valid\n"); | ||
7567 | err = -EIO; | ||
7568 | goto err_eeprom; | ||
7569 | } | ||
7570 | |||
7571 | memcpy(netdev->dev_addr, hw->mac.perm_addr, netdev->addr_len); | ||
7572 | memcpy(netdev->perm_addr, hw->mac.perm_addr, netdev->addr_len); | ||
7573 | |||
7574 | if (ixgbe_validate_mac_addr(netdev->perm_addr)) { | ||
7575 | e_dev_err("invalid MAC address\n"); | ||
7576 | err = -EIO; | ||
7577 | goto err_eeprom; | ||
7578 | } | ||
7579 | |||
7580 | /* power down the optics for multispeed fiber and 82599 SFP+ fiber */ | ||
7581 | if (hw->mac.ops.disable_tx_laser && | ||
7582 | ((hw->phy.multispeed_fiber) || | ||
7583 | ((hw->mac.ops.get_media_type(hw) == ixgbe_media_type_fiber) && | ||
7584 | (hw->mac.type == ixgbe_mac_82599EB)))) | ||
7585 | hw->mac.ops.disable_tx_laser(hw); | ||
7586 | |||
7587 | setup_timer(&adapter->service_timer, &ixgbe_service_timer, | ||
7588 | (unsigned long) adapter); | ||
7589 | |||
7590 | INIT_WORK(&adapter->service_task, ixgbe_service_task); | ||
7591 | clear_bit(__IXGBE_SERVICE_SCHED, &adapter->state); | ||
7592 | |||
7593 | err = ixgbe_init_interrupt_scheme(adapter); | ||
7594 | if (err) | ||
7595 | goto err_sw_init; | ||
7596 | |||
7597 | if (!(adapter->flags & IXGBE_FLAG_RSS_ENABLED)) { | ||
7598 | netdev->hw_features &= ~NETIF_F_RXHASH; | ||
7599 | netdev->features &= ~NETIF_F_RXHASH; | ||
7600 | } | ||
7601 | |||
7602 | switch (pdev->device) { | ||
7603 | case IXGBE_DEV_ID_82599_SFP: | ||
7604 | /* Only this subdevice supports WOL */ | ||
7605 | if (pdev->subsystem_device == IXGBE_SUBDEV_ID_82599_SFP) | ||
7606 | adapter->wol = IXGBE_WUFC_MAG; | ||
7607 | break; | ||
7608 | case IXGBE_DEV_ID_82599_COMBO_BACKPLANE: | ||
7609 | /* All except this subdevice support WOL */ | ||
7610 | if (pdev->subsystem_device != IXGBE_SUBDEV_ID_82599_KX4_KR_MEZZ) | ||
7611 | adapter->wol = IXGBE_WUFC_MAG; | ||
7612 | break; | ||
7613 | case IXGBE_DEV_ID_82599_KX4: | ||
7614 | adapter->wol = IXGBE_WUFC_MAG; | ||
7615 | break; | ||
7616 | default: | ||
7617 | adapter->wol = 0; | ||
7618 | break; | ||
7619 | } | ||
7620 | device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol); | ||
7621 | |||
7622 | /* pick up the PCI bus settings for reporting later */ | ||
7623 | hw->mac.ops.get_bus_info(hw); | ||
7624 | |||
7625 | /* print bus type/speed/width info */ | ||
7626 | e_dev_info("(PCI Express:%s:%s) %pM\n", | ||
7627 | (hw->bus.speed == ixgbe_bus_speed_5000 ? "5.0GT/s" : | ||
7628 | hw->bus.speed == ixgbe_bus_speed_2500 ? "2.5GT/s" : | ||
7629 | "Unknown"), | ||
7630 | (hw->bus.width == ixgbe_bus_width_pcie_x8 ? "Width x8" : | ||
7631 | hw->bus.width == ixgbe_bus_width_pcie_x4 ? "Width x4" : | ||
7632 | hw->bus.width == ixgbe_bus_width_pcie_x1 ? "Width x1" : | ||
7633 | "Unknown"), | ||
7634 | netdev->dev_addr); | ||
7635 | |||
7636 | err = ixgbe_read_pba_string_generic(hw, part_str, IXGBE_PBANUM_LENGTH); | ||
7637 | if (err) | ||
7638 | strncpy(part_str, "Unknown", IXGBE_PBANUM_LENGTH); | ||
7639 | if (ixgbe_is_sfp(hw) && hw->phy.sfp_type != ixgbe_sfp_type_not_present) | ||
7640 | e_dev_info("MAC: %d, PHY: %d, SFP+: %d, PBA No: %s\n", | ||
7641 | hw->mac.type, hw->phy.type, hw->phy.sfp_type, | ||
7642 | part_str); | ||
7643 | else | ||
7644 | e_dev_info("MAC: %d, PHY: %d, PBA No: %s\n", | ||
7645 | hw->mac.type, hw->phy.type, part_str); | ||
7646 | |||
7647 | if (hw->bus.width <= ixgbe_bus_width_pcie_x4) { | ||
7648 | e_dev_warn("PCI-Express bandwidth available for this card is " | ||
7649 | "not sufficient for optimal performance.\n"); | ||
7650 | e_dev_warn("For optimal performance a x8 PCI-Express slot " | ||
7651 | "is required.\n"); | ||
7652 | } | ||
7653 | |||
7654 | /* save off EEPROM version number */ | ||
7655 | hw->eeprom.ops.read(hw, 0x29, &adapter->eeprom_version); | ||
7656 | |||
7657 | /* reset the hardware with the new settings */ | ||
7658 | err = hw->mac.ops.start_hw(hw); | ||
7659 | |||
7660 | if (err == IXGBE_ERR_EEPROM_VERSION) { | ||
7661 | /* We are running on a pre-production device, log a warning */ | ||
7662 | e_dev_warn("This device is a pre-production adapter/LOM. " | ||
7663 | "Please be aware there may be issues associated " | ||
7664 | "with your hardware. If you are experiencing " | ||
7665 | "problems please contact your Intel or hardware " | ||
7666 | "representative who provided you with this " | ||
7667 | "hardware.\n"); | ||
7668 | } | ||
7669 | strcpy(netdev->name, "eth%d"); | ||
7670 | err = register_netdev(netdev); | ||
7671 | if (err) | ||
7672 | goto err_register; | ||
7673 | |||
7674 | /* carrier off reporting is important to ethtool even BEFORE open */ | ||
7675 | netif_carrier_off(netdev); | ||
7676 | |||
7677 | #ifdef CONFIG_IXGBE_DCA | ||
7678 | if (dca_add_requester(&pdev->dev) == 0) { | ||
7679 | adapter->flags |= IXGBE_FLAG_DCA_ENABLED; | ||
7680 | ixgbe_setup_dca(adapter); | ||
7681 | } | ||
7682 | #endif | ||
7683 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) { | ||
7684 | e_info(probe, "IOV is enabled with %d VFs\n", adapter->num_vfs); | ||
7685 | for (i = 0; i < adapter->num_vfs; i++) | ||
7686 | ixgbe_vf_configuration(pdev, (i | 0x10000000)); | ||
7687 | } | ||
7688 | |||
7689 | /* Inform firmware of driver version */ | ||
7690 | if (hw->mac.ops.set_fw_drv_ver) | ||
7691 | hw->mac.ops.set_fw_drv_ver(hw, MAJ, MIN, BUILD, | ||
7692 | FW_CEM_UNUSED_VER); | ||
7693 | |||
7694 | /* add san mac addr to netdev */ | ||
7695 | ixgbe_add_sanmac_netdev(netdev); | ||
7696 | |||
7697 | e_dev_info("Intel(R) 10 Gigabit Network Connection\n"); | ||
7698 | cards_found++; | ||
7699 | return 0; | ||
7700 | |||
7701 | err_register: | ||
7702 | ixgbe_release_hw_control(adapter); | ||
7703 | ixgbe_clear_interrupt_scheme(adapter); | ||
7704 | err_sw_init: | ||
7705 | err_eeprom: | ||
7706 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) | ||
7707 | ixgbe_disable_sriov(adapter); | ||
7708 | adapter->flags2 &= ~IXGBE_FLAG2_SEARCH_FOR_SFP; | ||
7709 | iounmap(hw->hw_addr); | ||
7710 | err_ioremap: | ||
7711 | free_netdev(netdev); | ||
7712 | err_alloc_etherdev: | ||
7713 | pci_release_selected_regions(pdev, | ||
7714 | pci_select_bars(pdev, IORESOURCE_MEM)); | ||
7715 | err_pci_reg: | ||
7716 | err_dma: | ||
7717 | pci_disable_device(pdev); | ||
7718 | return err; | ||
7719 | } | ||
7720 | |||
7721 | /** | ||
7722 | * ixgbe_remove - Device Removal Routine | ||
7723 | * @pdev: PCI device information struct | ||
7724 | * | ||
7725 | * ixgbe_remove is called by the PCI subsystem to alert the driver | ||
7726 | * that it should release a PCI device. The could be caused by a | ||
7727 | * Hot-Plug event, or because the driver is going to be removed from | ||
7728 | * memory. | ||
7729 | **/ | ||
7730 | static void __devexit ixgbe_remove(struct pci_dev *pdev) | ||
7731 | { | ||
7732 | struct ixgbe_adapter *adapter = pci_get_drvdata(pdev); | ||
7733 | struct net_device *netdev = adapter->netdev; | ||
7734 | |||
7735 | set_bit(__IXGBE_DOWN, &adapter->state); | ||
7736 | cancel_work_sync(&adapter->service_task); | ||
7737 | |||
7738 | #ifdef CONFIG_IXGBE_DCA | ||
7739 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) { | ||
7740 | adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED; | ||
7741 | dca_remove_requester(&pdev->dev); | ||
7742 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1); | ||
7743 | } | ||
7744 | |||
7745 | #endif | ||
7746 | #ifdef IXGBE_FCOE | ||
7747 | if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) | ||
7748 | ixgbe_cleanup_fcoe(adapter); | ||
7749 | |||
7750 | #endif /* IXGBE_FCOE */ | ||
7751 | |||
7752 | /* remove the added san mac */ | ||
7753 | ixgbe_del_sanmac_netdev(netdev); | ||
7754 | |||
7755 | if (netdev->reg_state == NETREG_REGISTERED) | ||
7756 | unregister_netdev(netdev); | ||
7757 | |||
7758 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) | ||
7759 | ixgbe_disable_sriov(adapter); | ||
7760 | |||
7761 | ixgbe_clear_interrupt_scheme(adapter); | ||
7762 | |||
7763 | ixgbe_release_hw_control(adapter); | ||
7764 | |||
7765 | iounmap(adapter->hw.hw_addr); | ||
7766 | pci_release_selected_regions(pdev, pci_select_bars(pdev, | ||
7767 | IORESOURCE_MEM)); | ||
7768 | |||
7769 | e_dev_info("complete\n"); | ||
7770 | |||
7771 | free_netdev(netdev); | ||
7772 | |||
7773 | pci_disable_pcie_error_reporting(pdev); | ||
7774 | |||
7775 | pci_disable_device(pdev); | ||
7776 | } | ||
7777 | |||
7778 | /** | ||
7779 | * ixgbe_io_error_detected - called when PCI error is detected | ||
7780 | * @pdev: Pointer to PCI device | ||
7781 | * @state: The current pci connection state | ||
7782 | * | ||
7783 | * This function is called after a PCI bus error affecting | ||
7784 | * this device has been detected. | ||
7785 | */ | ||
7786 | static pci_ers_result_t ixgbe_io_error_detected(struct pci_dev *pdev, | ||
7787 | pci_channel_state_t state) | ||
7788 | { | ||
7789 | struct ixgbe_adapter *adapter = pci_get_drvdata(pdev); | ||
7790 | struct net_device *netdev = adapter->netdev; | ||
7791 | |||
7792 | netif_device_detach(netdev); | ||
7793 | |||
7794 | if (state == pci_channel_io_perm_failure) | ||
7795 | return PCI_ERS_RESULT_DISCONNECT; | ||
7796 | |||
7797 | if (netif_running(netdev)) | ||
7798 | ixgbe_down(adapter); | ||
7799 | pci_disable_device(pdev); | ||
7800 | |||
7801 | /* Request a slot reset. */ | ||
7802 | return PCI_ERS_RESULT_NEED_RESET; | ||
7803 | } | ||
7804 | |||
7805 | /** | ||
7806 | * ixgbe_io_slot_reset - called after the pci bus has been reset. | ||
7807 | * @pdev: Pointer to PCI device | ||
7808 | * | ||
7809 | * Restart the card from scratch, as if from a cold-boot. | ||
7810 | */ | ||
7811 | static pci_ers_result_t ixgbe_io_slot_reset(struct pci_dev *pdev) | ||
7812 | { | ||
7813 | struct ixgbe_adapter *adapter = pci_get_drvdata(pdev); | ||
7814 | pci_ers_result_t result; | ||
7815 | int err; | ||
7816 | |||
7817 | if (pci_enable_device_mem(pdev)) { | ||
7818 | e_err(probe, "Cannot re-enable PCI device after reset.\n"); | ||
7819 | result = PCI_ERS_RESULT_DISCONNECT; | ||
7820 | } else { | ||
7821 | pci_set_master(pdev); | ||
7822 | pci_restore_state(pdev); | ||
7823 | pci_save_state(pdev); | ||
7824 | |||
7825 | pci_wake_from_d3(pdev, false); | ||
7826 | |||
7827 | ixgbe_reset(adapter); | ||
7828 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0); | ||
7829 | result = PCI_ERS_RESULT_RECOVERED; | ||
7830 | } | ||
7831 | |||
7832 | err = pci_cleanup_aer_uncorrect_error_status(pdev); | ||
7833 | if (err) { | ||
7834 | e_dev_err("pci_cleanup_aer_uncorrect_error_status " | ||
7835 | "failed 0x%0x\n", err); | ||
7836 | /* non-fatal, continue */ | ||
7837 | } | ||
7838 | |||
7839 | return result; | ||
7840 | } | ||
7841 | |||
7842 | /** | ||
7843 | * ixgbe_io_resume - called when traffic can start flowing again. | ||
7844 | * @pdev: Pointer to PCI device | ||
7845 | * | ||
7846 | * This callback is called when the error recovery driver tells us that | ||
7847 | * its OK to resume normal operation. | ||
7848 | */ | ||
7849 | static void ixgbe_io_resume(struct pci_dev *pdev) | ||
7850 | { | ||
7851 | struct ixgbe_adapter *adapter = pci_get_drvdata(pdev); | ||
7852 | struct net_device *netdev = adapter->netdev; | ||
7853 | |||
7854 | if (netif_running(netdev)) { | ||
7855 | if (ixgbe_up(adapter)) { | ||
7856 | e_info(probe, "ixgbe_up failed after reset\n"); | ||
7857 | return; | ||
7858 | } | ||
7859 | } | ||
7860 | |||
7861 | netif_device_attach(netdev); | ||
7862 | } | ||
7863 | |||
7864 | static struct pci_error_handlers ixgbe_err_handler = { | ||
7865 | .error_detected = ixgbe_io_error_detected, | ||
7866 | .slot_reset = ixgbe_io_slot_reset, | ||
7867 | .resume = ixgbe_io_resume, | ||
7868 | }; | ||
7869 | |||
7870 | static struct pci_driver ixgbe_driver = { | ||
7871 | .name = ixgbe_driver_name, | ||
7872 | .id_table = ixgbe_pci_tbl, | ||
7873 | .probe = ixgbe_probe, | ||
7874 | .remove = __devexit_p(ixgbe_remove), | ||
7875 | #ifdef CONFIG_PM | ||
7876 | .suspend = ixgbe_suspend, | ||
7877 | .resume = ixgbe_resume, | ||
7878 | #endif | ||
7879 | .shutdown = ixgbe_shutdown, | ||
7880 | .err_handler = &ixgbe_err_handler | ||
7881 | }; | ||
7882 | |||
7883 | /** | ||
7884 | * ixgbe_init_module - Driver Registration Routine | ||
7885 | * | ||
7886 | * ixgbe_init_module is the first routine called when the driver is | ||
7887 | * loaded. All it does is register with the PCI subsystem. | ||
7888 | **/ | ||
7889 | static int __init ixgbe_init_module(void) | ||
7890 | { | ||
7891 | int ret; | ||
7892 | pr_info("%s - version %s\n", ixgbe_driver_string, ixgbe_driver_version); | ||
7893 | pr_info("%s\n", ixgbe_copyright); | ||
7894 | |||
7895 | #ifdef CONFIG_IXGBE_DCA | ||
7896 | dca_register_notify(&dca_notifier); | ||
7897 | #endif | ||
7898 | |||
7899 | ret = pci_register_driver(&ixgbe_driver); | ||
7900 | return ret; | ||
7901 | } | ||
7902 | |||
7903 | module_init(ixgbe_init_module); | ||
7904 | |||
7905 | /** | ||
7906 | * ixgbe_exit_module - Driver Exit Cleanup Routine | ||
7907 | * | ||
7908 | * ixgbe_exit_module is called just before the driver is removed | ||
7909 | * from memory. | ||
7910 | **/ | ||
7911 | static void __exit ixgbe_exit_module(void) | ||
7912 | { | ||
7913 | #ifdef CONFIG_IXGBE_DCA | ||
7914 | dca_unregister_notify(&dca_notifier); | ||
7915 | #endif | ||
7916 | pci_unregister_driver(&ixgbe_driver); | ||
7917 | rcu_barrier(); /* Wait for completion of call_rcu()'s */ | ||
7918 | } | ||
7919 | |||
7920 | #ifdef CONFIG_IXGBE_DCA | ||
7921 | static int ixgbe_notify_dca(struct notifier_block *nb, unsigned long event, | ||
7922 | void *p) | ||
7923 | { | ||
7924 | int ret_val; | ||
7925 | |||
7926 | ret_val = driver_for_each_device(&ixgbe_driver.driver, NULL, &event, | ||
7927 | __ixgbe_notify_dca); | ||
7928 | |||
7929 | return ret_val ? NOTIFY_BAD : NOTIFY_DONE; | ||
7930 | } | ||
7931 | |||
7932 | #endif /* CONFIG_IXGBE_DCA */ | ||
7933 | |||
7934 | module_exit(ixgbe_exit_module); | ||
7935 | |||
7936 | /* ixgbe_main.c */ | ||
diff --git a/drivers/net/ixgbe/ixgbe_mbx.c b/drivers/net/ixgbe/ixgbe_mbx.c new file mode 100644 index 00000000000..1ff0eefcfd0 --- /dev/null +++ b/drivers/net/ixgbe/ixgbe_mbx.c | |||
@@ -0,0 +1,471 @@ | |||
1 | /******************************************************************************* | ||
2 | |||
3 | Intel 10 Gigabit PCI Express Linux driver | ||
4 | Copyright(c) 1999 - 2011 Intel Corporation. | ||
5 | |||
6 | This program is free software; you can redistribute it and/or modify it | ||
7 | under the terms and conditions of the GNU General Public License, | ||
8 | version 2, as published by the Free Software Foundation. | ||
9 | |||
10 | This program is distributed in the hope it will be useful, but WITHOUT | ||
11 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
12 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
13 | more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License along with | ||
16 | this program; if not, write to the Free Software Foundation, Inc., | ||
17 | 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. | ||
18 | |||
19 | The full GNU General Public License is included in this distribution in | ||
20 | the file called "COPYING". | ||
21 | |||
22 | Contact Information: | ||
23 | e1000-devel Mailing List <e1000-devel@lists.sourceforge.net> | ||
24 | Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 | ||
25 | |||
26 | *******************************************************************************/ | ||
27 | |||
28 | #include <linux/pci.h> | ||
29 | #include <linux/delay.h> | ||
30 | #include "ixgbe_type.h" | ||
31 | #include "ixgbe_common.h" | ||
32 | #include "ixgbe_mbx.h" | ||
33 | |||
34 | /** | ||
35 | * ixgbe_read_mbx - Reads a message from the mailbox | ||
36 | * @hw: pointer to the HW structure | ||
37 | * @msg: The message buffer | ||
38 | * @size: Length of buffer | ||
39 | * @mbx_id: id of mailbox to read | ||
40 | * | ||
41 | * returns SUCCESS if it successfuly read message from buffer | ||
42 | **/ | ||
43 | s32 ixgbe_read_mbx(struct ixgbe_hw *hw, u32 *msg, u16 size, u16 mbx_id) | ||
44 | { | ||
45 | struct ixgbe_mbx_info *mbx = &hw->mbx; | ||
46 | s32 ret_val = IXGBE_ERR_MBX; | ||
47 | |||
48 | /* limit read to size of mailbox */ | ||
49 | if (size > mbx->size) | ||
50 | size = mbx->size; | ||
51 | |||
52 | if (mbx->ops.read) | ||
53 | ret_val = mbx->ops.read(hw, msg, size, mbx_id); | ||
54 | |||
55 | return ret_val; | ||
56 | } | ||
57 | |||
58 | /** | ||
59 | * ixgbe_write_mbx - Write a message to the mailbox | ||
60 | * @hw: pointer to the HW structure | ||
61 | * @msg: The message buffer | ||
62 | * @size: Length of buffer | ||
63 | * @mbx_id: id of mailbox to write | ||
64 | * | ||
65 | * returns SUCCESS if it successfully copied message into the buffer | ||
66 | **/ | ||
67 | s32 ixgbe_write_mbx(struct ixgbe_hw *hw, u32 *msg, u16 size, u16 mbx_id) | ||
68 | { | ||
69 | struct ixgbe_mbx_info *mbx = &hw->mbx; | ||
70 | s32 ret_val = 0; | ||
71 | |||
72 | if (size > mbx->size) | ||
73 | ret_val = IXGBE_ERR_MBX; | ||
74 | |||
75 | else if (mbx->ops.write) | ||
76 | ret_val = mbx->ops.write(hw, msg, size, mbx_id); | ||
77 | |||
78 | return ret_val; | ||
79 | } | ||
80 | |||
81 | /** | ||
82 | * ixgbe_check_for_msg - checks to see if someone sent us mail | ||
83 | * @hw: pointer to the HW structure | ||
84 | * @mbx_id: id of mailbox to check | ||
85 | * | ||
86 | * returns SUCCESS if the Status bit was found or else ERR_MBX | ||
87 | **/ | ||
88 | s32 ixgbe_check_for_msg(struct ixgbe_hw *hw, u16 mbx_id) | ||
89 | { | ||
90 | struct ixgbe_mbx_info *mbx = &hw->mbx; | ||
91 | s32 ret_val = IXGBE_ERR_MBX; | ||
92 | |||
93 | if (mbx->ops.check_for_msg) | ||
94 | ret_val = mbx->ops.check_for_msg(hw, mbx_id); | ||
95 | |||
96 | return ret_val; | ||
97 | } | ||
98 | |||
99 | /** | ||
100 | * ixgbe_check_for_ack - checks to see if someone sent us ACK | ||
101 | * @hw: pointer to the HW structure | ||
102 | * @mbx_id: id of mailbox to check | ||
103 | * | ||
104 | * returns SUCCESS if the Status bit was found or else ERR_MBX | ||
105 | **/ | ||
106 | s32 ixgbe_check_for_ack(struct ixgbe_hw *hw, u16 mbx_id) | ||
107 | { | ||
108 | struct ixgbe_mbx_info *mbx = &hw->mbx; | ||
109 | s32 ret_val = IXGBE_ERR_MBX; | ||
110 | |||
111 | if (mbx->ops.check_for_ack) | ||
112 | ret_val = mbx->ops.check_for_ack(hw, mbx_id); | ||
113 | |||
114 | return ret_val; | ||
115 | } | ||
116 | |||
117 | /** | ||
118 | * ixgbe_check_for_rst - checks to see if other side has reset | ||
119 | * @hw: pointer to the HW structure | ||
120 | * @mbx_id: id of mailbox to check | ||
121 | * | ||
122 | * returns SUCCESS if the Status bit was found or else ERR_MBX | ||
123 | **/ | ||
124 | s32 ixgbe_check_for_rst(struct ixgbe_hw *hw, u16 mbx_id) | ||
125 | { | ||
126 | struct ixgbe_mbx_info *mbx = &hw->mbx; | ||
127 | s32 ret_val = IXGBE_ERR_MBX; | ||
128 | |||
129 | if (mbx->ops.check_for_rst) | ||
130 | ret_val = mbx->ops.check_for_rst(hw, mbx_id); | ||
131 | |||
132 | return ret_val; | ||
133 | } | ||
134 | |||
135 | /** | ||
136 | * ixgbe_poll_for_msg - Wait for message notification | ||
137 | * @hw: pointer to the HW structure | ||
138 | * @mbx_id: id of mailbox to write | ||
139 | * | ||
140 | * returns SUCCESS if it successfully received a message notification | ||
141 | **/ | ||
142 | static s32 ixgbe_poll_for_msg(struct ixgbe_hw *hw, u16 mbx_id) | ||
143 | { | ||
144 | struct ixgbe_mbx_info *mbx = &hw->mbx; | ||
145 | int countdown = mbx->timeout; | ||
146 | |||
147 | if (!countdown || !mbx->ops.check_for_msg) | ||
148 | goto out; | ||
149 | |||
150 | while (countdown && mbx->ops.check_for_msg(hw, mbx_id)) { | ||
151 | countdown--; | ||
152 | if (!countdown) | ||
153 | break; | ||
154 | udelay(mbx->usec_delay); | ||
155 | } | ||
156 | |||
157 | out: | ||
158 | return countdown ? 0 : IXGBE_ERR_MBX; | ||
159 | } | ||
160 | |||
161 | /** | ||
162 | * ixgbe_poll_for_ack - Wait for message acknowledgement | ||
163 | * @hw: pointer to the HW structure | ||
164 | * @mbx_id: id of mailbox to write | ||
165 | * | ||
166 | * returns SUCCESS if it successfully received a message acknowledgement | ||
167 | **/ | ||
168 | static s32 ixgbe_poll_for_ack(struct ixgbe_hw *hw, u16 mbx_id) | ||
169 | { | ||
170 | struct ixgbe_mbx_info *mbx = &hw->mbx; | ||
171 | int countdown = mbx->timeout; | ||
172 | |||
173 | if (!countdown || !mbx->ops.check_for_ack) | ||
174 | goto out; | ||
175 | |||
176 | while (countdown && mbx->ops.check_for_ack(hw, mbx_id)) { | ||
177 | countdown--; | ||
178 | if (!countdown) | ||
179 | break; | ||
180 | udelay(mbx->usec_delay); | ||
181 | } | ||
182 | |||
183 | out: | ||
184 | return countdown ? 0 : IXGBE_ERR_MBX; | ||
185 | } | ||
186 | |||
187 | /** | ||
188 | * ixgbe_read_posted_mbx - Wait for message notification and receive message | ||
189 | * @hw: pointer to the HW structure | ||
190 | * @msg: The message buffer | ||
191 | * @size: Length of buffer | ||
192 | * @mbx_id: id of mailbox to write | ||
193 | * | ||
194 | * returns SUCCESS if it successfully received a message notification and | ||
195 | * copied it into the receive buffer. | ||
196 | **/ | ||
197 | static s32 ixgbe_read_posted_mbx(struct ixgbe_hw *hw, u32 *msg, u16 size, | ||
198 | u16 mbx_id) | ||
199 | { | ||
200 | struct ixgbe_mbx_info *mbx = &hw->mbx; | ||
201 | s32 ret_val = IXGBE_ERR_MBX; | ||
202 | |||
203 | if (!mbx->ops.read) | ||
204 | goto out; | ||
205 | |||
206 | ret_val = ixgbe_poll_for_msg(hw, mbx_id); | ||
207 | |||
208 | /* if ack received read message, otherwise we timed out */ | ||
209 | if (!ret_val) | ||
210 | ret_val = mbx->ops.read(hw, msg, size, mbx_id); | ||
211 | out: | ||
212 | return ret_val; | ||
213 | } | ||
214 | |||
215 | /** | ||
216 | * ixgbe_write_posted_mbx - Write a message to the mailbox, wait for ack | ||
217 | * @hw: pointer to the HW structure | ||
218 | * @msg: The message buffer | ||
219 | * @size: Length of buffer | ||
220 | * @mbx_id: id of mailbox to write | ||
221 | * | ||
222 | * returns SUCCESS if it successfully copied message into the buffer and | ||
223 | * received an ack to that message within delay * timeout period | ||
224 | **/ | ||
225 | static s32 ixgbe_write_posted_mbx(struct ixgbe_hw *hw, u32 *msg, u16 size, | ||
226 | u16 mbx_id) | ||
227 | { | ||
228 | struct ixgbe_mbx_info *mbx = &hw->mbx; | ||
229 | s32 ret_val = IXGBE_ERR_MBX; | ||
230 | |||
231 | /* exit if either we can't write or there isn't a defined timeout */ | ||
232 | if (!mbx->ops.write || !mbx->timeout) | ||
233 | goto out; | ||
234 | |||
235 | /* send msg */ | ||
236 | ret_val = mbx->ops.write(hw, msg, size, mbx_id); | ||
237 | |||
238 | /* if msg sent wait until we receive an ack */ | ||
239 | if (!ret_val) | ||
240 | ret_val = ixgbe_poll_for_ack(hw, mbx_id); | ||
241 | out: | ||
242 | return ret_val; | ||
243 | } | ||
244 | |||
245 | static s32 ixgbe_check_for_bit_pf(struct ixgbe_hw *hw, u32 mask, s32 index) | ||
246 | { | ||
247 | u32 mbvficr = IXGBE_READ_REG(hw, IXGBE_MBVFICR(index)); | ||
248 | s32 ret_val = IXGBE_ERR_MBX; | ||
249 | |||
250 | if (mbvficr & mask) { | ||
251 | ret_val = 0; | ||
252 | IXGBE_WRITE_REG(hw, IXGBE_MBVFICR(index), mask); | ||
253 | } | ||
254 | |||
255 | return ret_val; | ||
256 | } | ||
257 | |||
258 | /** | ||
259 | * ixgbe_check_for_msg_pf - checks to see if the VF has sent mail | ||
260 | * @hw: pointer to the HW structure | ||
261 | * @vf_number: the VF index | ||
262 | * | ||
263 | * returns SUCCESS if the VF has set the Status bit or else ERR_MBX | ||
264 | **/ | ||
265 | static s32 ixgbe_check_for_msg_pf(struct ixgbe_hw *hw, u16 vf_number) | ||
266 | { | ||
267 | s32 ret_val = IXGBE_ERR_MBX; | ||
268 | s32 index = IXGBE_MBVFICR_INDEX(vf_number); | ||
269 | u32 vf_bit = vf_number % 16; | ||
270 | |||
271 | if (!ixgbe_check_for_bit_pf(hw, IXGBE_MBVFICR_VFREQ_VF1 << vf_bit, | ||
272 | index)) { | ||
273 | ret_val = 0; | ||
274 | hw->mbx.stats.reqs++; | ||
275 | } | ||
276 | |||
277 | return ret_val; | ||
278 | } | ||
279 | |||
280 | /** | ||
281 | * ixgbe_check_for_ack_pf - checks to see if the VF has ACKed | ||
282 | * @hw: pointer to the HW structure | ||
283 | * @vf_number: the VF index | ||
284 | * | ||
285 | * returns SUCCESS if the VF has set the Status bit or else ERR_MBX | ||
286 | **/ | ||
287 | static s32 ixgbe_check_for_ack_pf(struct ixgbe_hw *hw, u16 vf_number) | ||
288 | { | ||
289 | s32 ret_val = IXGBE_ERR_MBX; | ||
290 | s32 index = IXGBE_MBVFICR_INDEX(vf_number); | ||
291 | u32 vf_bit = vf_number % 16; | ||
292 | |||
293 | if (!ixgbe_check_for_bit_pf(hw, IXGBE_MBVFICR_VFACK_VF1 << vf_bit, | ||
294 | index)) { | ||
295 | ret_val = 0; | ||
296 | hw->mbx.stats.acks++; | ||
297 | } | ||
298 | |||
299 | return ret_val; | ||
300 | } | ||
301 | |||
302 | /** | ||
303 | * ixgbe_check_for_rst_pf - checks to see if the VF has reset | ||
304 | * @hw: pointer to the HW structure | ||
305 | * @vf_number: the VF index | ||
306 | * | ||
307 | * returns SUCCESS if the VF has set the Status bit or else ERR_MBX | ||
308 | **/ | ||
309 | static s32 ixgbe_check_for_rst_pf(struct ixgbe_hw *hw, u16 vf_number) | ||
310 | { | ||
311 | u32 reg_offset = (vf_number < 32) ? 0 : 1; | ||
312 | u32 vf_shift = vf_number % 32; | ||
313 | u32 vflre = 0; | ||
314 | s32 ret_val = IXGBE_ERR_MBX; | ||
315 | |||
316 | switch (hw->mac.type) { | ||
317 | case ixgbe_mac_82599EB: | ||
318 | vflre = IXGBE_READ_REG(hw, IXGBE_VFLRE(reg_offset)); | ||
319 | break; | ||
320 | case ixgbe_mac_X540: | ||
321 | vflre = IXGBE_READ_REG(hw, IXGBE_VFLREC(reg_offset)); | ||
322 | break; | ||
323 | default: | ||
324 | break; | ||
325 | } | ||
326 | |||
327 | if (vflre & (1 << vf_shift)) { | ||
328 | ret_val = 0; | ||
329 | IXGBE_WRITE_REG(hw, IXGBE_VFLREC(reg_offset), (1 << vf_shift)); | ||
330 | hw->mbx.stats.rsts++; | ||
331 | } | ||
332 | |||
333 | return ret_val; | ||
334 | } | ||
335 | |||
336 | /** | ||
337 | * ixgbe_obtain_mbx_lock_pf - obtain mailbox lock | ||
338 | * @hw: pointer to the HW structure | ||
339 | * @vf_number: the VF index | ||
340 | * | ||
341 | * return SUCCESS if we obtained the mailbox lock | ||
342 | **/ | ||
343 | static s32 ixgbe_obtain_mbx_lock_pf(struct ixgbe_hw *hw, u16 vf_number) | ||
344 | { | ||
345 | s32 ret_val = IXGBE_ERR_MBX; | ||
346 | u32 p2v_mailbox; | ||
347 | |||
348 | /* Take ownership of the buffer */ | ||
349 | IXGBE_WRITE_REG(hw, IXGBE_PFMAILBOX(vf_number), IXGBE_PFMAILBOX_PFU); | ||
350 | |||
351 | /* reserve mailbox for vf use */ | ||
352 | p2v_mailbox = IXGBE_READ_REG(hw, IXGBE_PFMAILBOX(vf_number)); | ||
353 | if (p2v_mailbox & IXGBE_PFMAILBOX_PFU) | ||
354 | ret_val = 0; | ||
355 | |||
356 | return ret_val; | ||
357 | } | ||
358 | |||
359 | /** | ||
360 | * ixgbe_write_mbx_pf - Places a message in the mailbox | ||
361 | * @hw: pointer to the HW structure | ||
362 | * @msg: The message buffer | ||
363 | * @size: Length of buffer | ||
364 | * @vf_number: the VF index | ||
365 | * | ||
366 | * returns SUCCESS if it successfully copied message into the buffer | ||
367 | **/ | ||
368 | static s32 ixgbe_write_mbx_pf(struct ixgbe_hw *hw, u32 *msg, u16 size, | ||
369 | u16 vf_number) | ||
370 | { | ||
371 | s32 ret_val; | ||
372 | u16 i; | ||
373 | |||
374 | /* lock the mailbox to prevent pf/vf race condition */ | ||
375 | ret_val = ixgbe_obtain_mbx_lock_pf(hw, vf_number); | ||
376 | if (ret_val) | ||
377 | goto out_no_write; | ||
378 | |||
379 | /* flush msg and acks as we are overwriting the message buffer */ | ||
380 | ixgbe_check_for_msg_pf(hw, vf_number); | ||
381 | ixgbe_check_for_ack_pf(hw, vf_number); | ||
382 | |||
383 | /* copy the caller specified message to the mailbox memory buffer */ | ||
384 | for (i = 0; i < size; i++) | ||
385 | IXGBE_WRITE_REG_ARRAY(hw, IXGBE_PFMBMEM(vf_number), i, msg[i]); | ||
386 | |||
387 | /* Interrupt VF to tell it a message has been sent and release buffer*/ | ||
388 | IXGBE_WRITE_REG(hw, IXGBE_PFMAILBOX(vf_number), IXGBE_PFMAILBOX_STS); | ||
389 | |||
390 | /* update stats */ | ||
391 | hw->mbx.stats.msgs_tx++; | ||
392 | |||
393 | out_no_write: | ||
394 | return ret_val; | ||
395 | |||
396 | } | ||
397 | |||
398 | /** | ||
399 | * ixgbe_read_mbx_pf - Read a message from the mailbox | ||
400 | * @hw: pointer to the HW structure | ||
401 | * @msg: The message buffer | ||
402 | * @size: Length of buffer | ||
403 | * @vf_number: the VF index | ||
404 | * | ||
405 | * This function copies a message from the mailbox buffer to the caller's | ||
406 | * memory buffer. The presumption is that the caller knows that there was | ||
407 | * a message due to a VF request so no polling for message is needed. | ||
408 | **/ | ||
409 | static s32 ixgbe_read_mbx_pf(struct ixgbe_hw *hw, u32 *msg, u16 size, | ||
410 | u16 vf_number) | ||
411 | { | ||
412 | s32 ret_val; | ||
413 | u16 i; | ||
414 | |||
415 | /* lock the mailbox to prevent pf/vf race condition */ | ||
416 | ret_val = ixgbe_obtain_mbx_lock_pf(hw, vf_number); | ||
417 | if (ret_val) | ||
418 | goto out_no_read; | ||
419 | |||
420 | /* copy the message to the mailbox memory buffer */ | ||
421 | for (i = 0; i < size; i++) | ||
422 | msg[i] = IXGBE_READ_REG_ARRAY(hw, IXGBE_PFMBMEM(vf_number), i); | ||
423 | |||
424 | /* Acknowledge the message and release buffer */ | ||
425 | IXGBE_WRITE_REG(hw, IXGBE_PFMAILBOX(vf_number), IXGBE_PFMAILBOX_ACK); | ||
426 | |||
427 | /* update stats */ | ||
428 | hw->mbx.stats.msgs_rx++; | ||
429 | |||
430 | out_no_read: | ||
431 | return ret_val; | ||
432 | } | ||
433 | |||
434 | #ifdef CONFIG_PCI_IOV | ||
435 | /** | ||
436 | * ixgbe_init_mbx_params_pf - set initial values for pf mailbox | ||
437 | * @hw: pointer to the HW structure | ||
438 | * | ||
439 | * Initializes the hw->mbx struct to correct values for pf mailbox | ||
440 | */ | ||
441 | void ixgbe_init_mbx_params_pf(struct ixgbe_hw *hw) | ||
442 | { | ||
443 | struct ixgbe_mbx_info *mbx = &hw->mbx; | ||
444 | |||
445 | if (hw->mac.type != ixgbe_mac_82599EB && | ||
446 | hw->mac.type != ixgbe_mac_X540) | ||
447 | return; | ||
448 | |||
449 | mbx->timeout = 0; | ||
450 | mbx->usec_delay = 0; | ||
451 | |||
452 | mbx->stats.msgs_tx = 0; | ||
453 | mbx->stats.msgs_rx = 0; | ||
454 | mbx->stats.reqs = 0; | ||
455 | mbx->stats.acks = 0; | ||
456 | mbx->stats.rsts = 0; | ||
457 | |||
458 | mbx->size = IXGBE_VFMAILBOX_SIZE; | ||
459 | } | ||
460 | #endif /* CONFIG_PCI_IOV */ | ||
461 | |||
462 | struct ixgbe_mbx_operations mbx_ops_generic = { | ||
463 | .read = ixgbe_read_mbx_pf, | ||
464 | .write = ixgbe_write_mbx_pf, | ||
465 | .read_posted = ixgbe_read_posted_mbx, | ||
466 | .write_posted = ixgbe_write_posted_mbx, | ||
467 | .check_for_msg = ixgbe_check_for_msg_pf, | ||
468 | .check_for_ack = ixgbe_check_for_ack_pf, | ||
469 | .check_for_rst = ixgbe_check_for_rst_pf, | ||
470 | }; | ||
471 | |||
diff --git a/drivers/net/ixgbe/ixgbe_mbx.h b/drivers/net/ixgbe/ixgbe_mbx.h new file mode 100644 index 00000000000..b239bdac38d --- /dev/null +++ b/drivers/net/ixgbe/ixgbe_mbx.h | |||
@@ -0,0 +1,93 @@ | |||
1 | /******************************************************************************* | ||
2 | |||
3 | Intel 10 Gigabit PCI Express Linux driver | ||
4 | Copyright(c) 1999 - 2011 Intel Corporation. | ||
5 | |||
6 | This program is free software; you can redistribute it and/or modify it | ||
7 | under the terms and conditions of the GNU General Public License, | ||
8 | version 2, as published by the Free Software Foundation. | ||
9 | |||
10 | This program is distributed in the hope it will be useful, but WITHOUT | ||
11 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
12 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
13 | more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License along with | ||
16 | this program; if not, write to the Free Software Foundation, Inc., | ||
17 | 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. | ||
18 | |||
19 | The full GNU General Public License is included in this distribution in | ||
20 | the file called "COPYING". | ||
21 | |||
22 | Contact Information: | ||
23 | e1000-devel Mailing List <e1000-devel@lists.sourceforge.net> | ||
24 | Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 | ||
25 | |||
26 | *******************************************************************************/ | ||
27 | |||
28 | #ifndef _IXGBE_MBX_H_ | ||
29 | #define _IXGBE_MBX_H_ | ||
30 | |||
31 | #include "ixgbe_type.h" | ||
32 | |||
33 | #define IXGBE_VFMAILBOX_SIZE 16 /* 16 32 bit words - 64 bytes */ | ||
34 | #define IXGBE_ERR_MBX -100 | ||
35 | |||
36 | #define IXGBE_VFMAILBOX 0x002FC | ||
37 | #define IXGBE_VFMBMEM 0x00200 | ||
38 | |||
39 | #define IXGBE_PFMAILBOX_STS 0x00000001 /* Initiate message send to VF */ | ||
40 | #define IXGBE_PFMAILBOX_ACK 0x00000002 /* Ack message recv'd from VF */ | ||
41 | #define IXGBE_PFMAILBOX_VFU 0x00000004 /* VF owns the mailbox buffer */ | ||
42 | #define IXGBE_PFMAILBOX_PFU 0x00000008 /* PF owns the mailbox buffer */ | ||
43 | #define IXGBE_PFMAILBOX_RVFU 0x00000010 /* Reset VFU - used when VF stuck */ | ||
44 | |||
45 | #define IXGBE_MBVFICR_VFREQ_MASK 0x0000FFFF /* bits for VF messages */ | ||
46 | #define IXGBE_MBVFICR_VFREQ_VF1 0x00000001 /* bit for VF 1 message */ | ||
47 | #define IXGBE_MBVFICR_VFACK_MASK 0xFFFF0000 /* bits for VF acks */ | ||
48 | #define IXGBE_MBVFICR_VFACK_VF1 0x00010000 /* bit for VF 1 ack */ | ||
49 | |||
50 | |||
51 | /* If it's a IXGBE_VF_* msg then it originates in the VF and is sent to the | ||
52 | * PF. The reverse is true if it is IXGBE_PF_*. | ||
53 | * Message ACK's are the value or'd with 0xF0000000 | ||
54 | */ | ||
55 | #define IXGBE_VT_MSGTYPE_ACK 0x80000000 /* Messages below or'd with | ||
56 | * this are the ACK */ | ||
57 | #define IXGBE_VT_MSGTYPE_NACK 0x40000000 /* Messages below or'd with | ||
58 | * this are the NACK */ | ||
59 | #define IXGBE_VT_MSGTYPE_CTS 0x20000000 /* Indicates that VF is still | ||
60 | clear to send requests */ | ||
61 | #define IXGBE_VT_MSGINFO_SHIFT 16 | ||
62 | /* bits 23:16 are used for exra info for certain messages */ | ||
63 | #define IXGBE_VT_MSGINFO_MASK (0xFF << IXGBE_VT_MSGINFO_SHIFT) | ||
64 | |||
65 | #define IXGBE_VF_RESET 0x01 /* VF requests reset */ | ||
66 | #define IXGBE_VF_SET_MAC_ADDR 0x02 /* VF requests PF to set MAC addr */ | ||
67 | #define IXGBE_VF_SET_MULTICAST 0x03 /* VF requests PF to set MC addr */ | ||
68 | #define IXGBE_VF_SET_VLAN 0x04 /* VF requests PF to set VLAN */ | ||
69 | #define IXGBE_VF_SET_LPE 0x05 /* VF requests PF to set VMOLR.LPE */ | ||
70 | #define IXGBE_VF_SET_MACVLAN 0x06 /* VF requests PF for unicast filter */ | ||
71 | |||
72 | /* length of permanent address message returned from PF */ | ||
73 | #define IXGBE_VF_PERMADDR_MSG_LEN 4 | ||
74 | /* word in permanent address message with the current multicast type */ | ||
75 | #define IXGBE_VF_MC_TYPE_WORD 3 | ||
76 | |||
77 | #define IXGBE_PF_CONTROL_MSG 0x0100 /* PF control message */ | ||
78 | |||
79 | #define IXGBE_VF_MBX_INIT_TIMEOUT 2000 /* number of retries on mailbox */ | ||
80 | #define IXGBE_VF_MBX_INIT_DELAY 500 /* microseconds between retries */ | ||
81 | |||
82 | s32 ixgbe_read_mbx(struct ixgbe_hw *, u32 *, u16, u16); | ||
83 | s32 ixgbe_write_mbx(struct ixgbe_hw *, u32 *, u16, u16); | ||
84 | s32 ixgbe_check_for_msg(struct ixgbe_hw *, u16); | ||
85 | s32 ixgbe_check_for_ack(struct ixgbe_hw *, u16); | ||
86 | s32 ixgbe_check_for_rst(struct ixgbe_hw *, u16); | ||
87 | #ifdef CONFIG_PCI_IOV | ||
88 | void ixgbe_init_mbx_params_pf(struct ixgbe_hw *); | ||
89 | #endif /* CONFIG_PCI_IOV */ | ||
90 | |||
91 | extern struct ixgbe_mbx_operations mbx_ops_generic; | ||
92 | |||
93 | #endif /* _IXGBE_MBX_H_ */ | ||
diff --git a/drivers/net/ixgbe/ixgbe_phy.c b/drivers/net/ixgbe/ixgbe_phy.c new file mode 100644 index 00000000000..f7ca3511b9f --- /dev/null +++ b/drivers/net/ixgbe/ixgbe_phy.c | |||
@@ -0,0 +1,1725 @@ | |||
1 | /******************************************************************************* | ||
2 | |||
3 | Intel 10 Gigabit PCI Express Linux driver | ||
4 | Copyright(c) 1999 - 2011 Intel Corporation. | ||
5 | |||
6 | This program is free software; you can redistribute it and/or modify it | ||
7 | under the terms and conditions of the GNU General Public License, | ||
8 | version 2, as published by the Free Software Foundation. | ||
9 | |||
10 | This program is distributed in the hope it will be useful, but WITHOUT | ||
11 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
12 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
13 | more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License along with | ||
16 | this program; if not, write to the Free Software Foundation, Inc., | ||
17 | 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. | ||
18 | |||
19 | The full GNU General Public License is included in this distribution in | ||
20 | the file called "COPYING". | ||
21 | |||
22 | Contact Information: | ||
23 | e1000-devel Mailing List <e1000-devel@lists.sourceforge.net> | ||
24 | Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 | ||
25 | |||
26 | *******************************************************************************/ | ||
27 | |||
28 | #include <linux/pci.h> | ||
29 | #include <linux/delay.h> | ||
30 | #include <linux/sched.h> | ||
31 | |||
32 | #include "ixgbe_common.h" | ||
33 | #include "ixgbe_phy.h" | ||
34 | |||
35 | static void ixgbe_i2c_start(struct ixgbe_hw *hw); | ||
36 | static void ixgbe_i2c_stop(struct ixgbe_hw *hw); | ||
37 | static s32 ixgbe_clock_in_i2c_byte(struct ixgbe_hw *hw, u8 *data); | ||
38 | static s32 ixgbe_clock_out_i2c_byte(struct ixgbe_hw *hw, u8 data); | ||
39 | static s32 ixgbe_get_i2c_ack(struct ixgbe_hw *hw); | ||
40 | static s32 ixgbe_clock_in_i2c_bit(struct ixgbe_hw *hw, bool *data); | ||
41 | static s32 ixgbe_clock_out_i2c_bit(struct ixgbe_hw *hw, bool data); | ||
42 | static s32 ixgbe_raise_i2c_clk(struct ixgbe_hw *hw, u32 *i2cctl); | ||
43 | static void ixgbe_lower_i2c_clk(struct ixgbe_hw *hw, u32 *i2cctl); | ||
44 | static s32 ixgbe_set_i2c_data(struct ixgbe_hw *hw, u32 *i2cctl, bool data); | ||
45 | static bool ixgbe_get_i2c_data(u32 *i2cctl); | ||
46 | static void ixgbe_i2c_bus_clear(struct ixgbe_hw *hw); | ||
47 | static enum ixgbe_phy_type ixgbe_get_phy_type_from_id(u32 phy_id); | ||
48 | static s32 ixgbe_get_phy_id(struct ixgbe_hw *hw); | ||
49 | |||
50 | /** | ||
51 | * ixgbe_identify_phy_generic - Get physical layer module | ||
52 | * @hw: pointer to hardware structure | ||
53 | * | ||
54 | * Determines the physical layer module found on the current adapter. | ||
55 | **/ | ||
56 | s32 ixgbe_identify_phy_generic(struct ixgbe_hw *hw) | ||
57 | { | ||
58 | s32 status = IXGBE_ERR_PHY_ADDR_INVALID; | ||
59 | u32 phy_addr; | ||
60 | u16 ext_ability = 0; | ||
61 | |||
62 | if (hw->phy.type == ixgbe_phy_unknown) { | ||
63 | for (phy_addr = 0; phy_addr < IXGBE_MAX_PHY_ADDR; phy_addr++) { | ||
64 | hw->phy.mdio.prtad = phy_addr; | ||
65 | if (mdio45_probe(&hw->phy.mdio, phy_addr) == 0) { | ||
66 | ixgbe_get_phy_id(hw); | ||
67 | hw->phy.type = | ||
68 | ixgbe_get_phy_type_from_id(hw->phy.id); | ||
69 | |||
70 | if (hw->phy.type == ixgbe_phy_unknown) { | ||
71 | hw->phy.ops.read_reg(hw, | ||
72 | MDIO_PMA_EXTABLE, | ||
73 | MDIO_MMD_PMAPMD, | ||
74 | &ext_ability); | ||
75 | if (ext_ability & | ||
76 | (MDIO_PMA_EXTABLE_10GBT | | ||
77 | MDIO_PMA_EXTABLE_1000BT)) | ||
78 | hw->phy.type = | ||
79 | ixgbe_phy_cu_unknown; | ||
80 | else | ||
81 | hw->phy.type = | ||
82 | ixgbe_phy_generic; | ||
83 | } | ||
84 | |||
85 | status = 0; | ||
86 | break; | ||
87 | } | ||
88 | } | ||
89 | /* clear value if nothing found */ | ||
90 | if (status != 0) | ||
91 | hw->phy.mdio.prtad = 0; | ||
92 | } else { | ||
93 | status = 0; | ||
94 | } | ||
95 | |||
96 | return status; | ||
97 | } | ||
98 | |||
99 | /** | ||
100 | * ixgbe_get_phy_id - Get the phy type | ||
101 | * @hw: pointer to hardware structure | ||
102 | * | ||
103 | **/ | ||
104 | static s32 ixgbe_get_phy_id(struct ixgbe_hw *hw) | ||
105 | { | ||
106 | u32 status; | ||
107 | u16 phy_id_high = 0; | ||
108 | u16 phy_id_low = 0; | ||
109 | |||
110 | status = hw->phy.ops.read_reg(hw, MDIO_DEVID1, MDIO_MMD_PMAPMD, | ||
111 | &phy_id_high); | ||
112 | |||
113 | if (status == 0) { | ||
114 | hw->phy.id = (u32)(phy_id_high << 16); | ||
115 | status = hw->phy.ops.read_reg(hw, MDIO_DEVID2, MDIO_MMD_PMAPMD, | ||
116 | &phy_id_low); | ||
117 | hw->phy.id |= (u32)(phy_id_low & IXGBE_PHY_REVISION_MASK); | ||
118 | hw->phy.revision = (u32)(phy_id_low & ~IXGBE_PHY_REVISION_MASK); | ||
119 | } | ||
120 | return status; | ||
121 | } | ||
122 | |||
123 | /** | ||
124 | * ixgbe_get_phy_type_from_id - Get the phy type | ||
125 | * @hw: pointer to hardware structure | ||
126 | * | ||
127 | **/ | ||
128 | static enum ixgbe_phy_type ixgbe_get_phy_type_from_id(u32 phy_id) | ||
129 | { | ||
130 | enum ixgbe_phy_type phy_type; | ||
131 | |||
132 | switch (phy_id) { | ||
133 | case TN1010_PHY_ID: | ||
134 | phy_type = ixgbe_phy_tn; | ||
135 | break; | ||
136 | case X540_PHY_ID: | ||
137 | phy_type = ixgbe_phy_aq; | ||
138 | break; | ||
139 | case QT2022_PHY_ID: | ||
140 | phy_type = ixgbe_phy_qt; | ||
141 | break; | ||
142 | case ATH_PHY_ID: | ||
143 | phy_type = ixgbe_phy_nl; | ||
144 | break; | ||
145 | default: | ||
146 | phy_type = ixgbe_phy_unknown; | ||
147 | break; | ||
148 | } | ||
149 | |||
150 | return phy_type; | ||
151 | } | ||
152 | |||
153 | /** | ||
154 | * ixgbe_reset_phy_generic - Performs a PHY reset | ||
155 | * @hw: pointer to hardware structure | ||
156 | **/ | ||
157 | s32 ixgbe_reset_phy_generic(struct ixgbe_hw *hw) | ||
158 | { | ||
159 | u32 i; | ||
160 | u16 ctrl = 0; | ||
161 | s32 status = 0; | ||
162 | |||
163 | if (hw->phy.type == ixgbe_phy_unknown) | ||
164 | status = ixgbe_identify_phy_generic(hw); | ||
165 | |||
166 | if (status != 0 || hw->phy.type == ixgbe_phy_none) | ||
167 | goto out; | ||
168 | |||
169 | /* Don't reset PHY if it's shut down due to overtemp. */ | ||
170 | if (!hw->phy.reset_if_overtemp && | ||
171 | (IXGBE_ERR_OVERTEMP == hw->phy.ops.check_overtemp(hw))) | ||
172 | goto out; | ||
173 | |||
174 | /* | ||
175 | * Perform soft PHY reset to the PHY_XS. | ||
176 | * This will cause a soft reset to the PHY | ||
177 | */ | ||
178 | hw->phy.ops.write_reg(hw, MDIO_CTRL1, | ||
179 | MDIO_MMD_PHYXS, | ||
180 | MDIO_CTRL1_RESET); | ||
181 | |||
182 | /* | ||
183 | * Poll for reset bit to self-clear indicating reset is complete. | ||
184 | * Some PHYs could take up to 3 seconds to complete and need about | ||
185 | * 1.7 usec delay after the reset is complete. | ||
186 | */ | ||
187 | for (i = 0; i < 30; i++) { | ||
188 | msleep(100); | ||
189 | hw->phy.ops.read_reg(hw, MDIO_CTRL1, | ||
190 | MDIO_MMD_PHYXS, &ctrl); | ||
191 | if (!(ctrl & MDIO_CTRL1_RESET)) { | ||
192 | udelay(2); | ||
193 | break; | ||
194 | } | ||
195 | } | ||
196 | |||
197 | if (ctrl & MDIO_CTRL1_RESET) { | ||
198 | status = IXGBE_ERR_RESET_FAILED; | ||
199 | hw_dbg(hw, "PHY reset polling failed to complete.\n"); | ||
200 | } | ||
201 | |||
202 | out: | ||
203 | return status; | ||
204 | } | ||
205 | |||
206 | /** | ||
207 | * ixgbe_read_phy_reg_generic - Reads a value from a specified PHY register | ||
208 | * @hw: pointer to hardware structure | ||
209 | * @reg_addr: 32 bit address of PHY register to read | ||
210 | * @phy_data: Pointer to read data from PHY register | ||
211 | **/ | ||
212 | s32 ixgbe_read_phy_reg_generic(struct ixgbe_hw *hw, u32 reg_addr, | ||
213 | u32 device_type, u16 *phy_data) | ||
214 | { | ||
215 | u32 command; | ||
216 | u32 i; | ||
217 | u32 data; | ||
218 | s32 status = 0; | ||
219 | u16 gssr; | ||
220 | |||
221 | if (IXGBE_READ_REG(hw, IXGBE_STATUS) & IXGBE_STATUS_LAN_ID_1) | ||
222 | gssr = IXGBE_GSSR_PHY1_SM; | ||
223 | else | ||
224 | gssr = IXGBE_GSSR_PHY0_SM; | ||
225 | |||
226 | if (hw->mac.ops.acquire_swfw_sync(hw, gssr) != 0) | ||
227 | status = IXGBE_ERR_SWFW_SYNC; | ||
228 | |||
229 | if (status == 0) { | ||
230 | /* Setup and write the address cycle command */ | ||
231 | command = ((reg_addr << IXGBE_MSCA_NP_ADDR_SHIFT) | | ||
232 | (device_type << IXGBE_MSCA_DEV_TYPE_SHIFT) | | ||
233 | (hw->phy.mdio.prtad << IXGBE_MSCA_PHY_ADDR_SHIFT) | | ||
234 | (IXGBE_MSCA_ADDR_CYCLE | IXGBE_MSCA_MDI_COMMAND)); | ||
235 | |||
236 | IXGBE_WRITE_REG(hw, IXGBE_MSCA, command); | ||
237 | |||
238 | /* | ||
239 | * Check every 10 usec to see if the address cycle completed. | ||
240 | * The MDI Command bit will clear when the operation is | ||
241 | * complete | ||
242 | */ | ||
243 | for (i = 0; i < IXGBE_MDIO_COMMAND_TIMEOUT; i++) { | ||
244 | udelay(10); | ||
245 | |||
246 | command = IXGBE_READ_REG(hw, IXGBE_MSCA); | ||
247 | |||
248 | if ((command & IXGBE_MSCA_MDI_COMMAND) == 0) | ||
249 | break; | ||
250 | } | ||
251 | |||
252 | if ((command & IXGBE_MSCA_MDI_COMMAND) != 0) { | ||
253 | hw_dbg(hw, "PHY address command did not complete.\n"); | ||
254 | status = IXGBE_ERR_PHY; | ||
255 | } | ||
256 | |||
257 | if (status == 0) { | ||
258 | /* | ||
259 | * Address cycle complete, setup and write the read | ||
260 | * command | ||
261 | */ | ||
262 | command = ((reg_addr << IXGBE_MSCA_NP_ADDR_SHIFT) | | ||
263 | (device_type << IXGBE_MSCA_DEV_TYPE_SHIFT) | | ||
264 | (hw->phy.mdio.prtad << | ||
265 | IXGBE_MSCA_PHY_ADDR_SHIFT) | | ||
266 | (IXGBE_MSCA_READ | IXGBE_MSCA_MDI_COMMAND)); | ||
267 | |||
268 | IXGBE_WRITE_REG(hw, IXGBE_MSCA, command); | ||
269 | |||
270 | /* | ||
271 | * Check every 10 usec to see if the address cycle | ||
272 | * completed. The MDI Command bit will clear when the | ||
273 | * operation is complete | ||
274 | */ | ||
275 | for (i = 0; i < IXGBE_MDIO_COMMAND_TIMEOUT; i++) { | ||
276 | udelay(10); | ||
277 | |||
278 | command = IXGBE_READ_REG(hw, IXGBE_MSCA); | ||
279 | |||
280 | if ((command & IXGBE_MSCA_MDI_COMMAND) == 0) | ||
281 | break; | ||
282 | } | ||
283 | |||
284 | if ((command & IXGBE_MSCA_MDI_COMMAND) != 0) { | ||
285 | hw_dbg(hw, "PHY read command didn't complete\n"); | ||
286 | status = IXGBE_ERR_PHY; | ||
287 | } else { | ||
288 | /* | ||
289 | * Read operation is complete. Get the data | ||
290 | * from MSRWD | ||
291 | */ | ||
292 | data = IXGBE_READ_REG(hw, IXGBE_MSRWD); | ||
293 | data >>= IXGBE_MSRWD_READ_DATA_SHIFT; | ||
294 | *phy_data = (u16)(data); | ||
295 | } | ||
296 | } | ||
297 | |||
298 | hw->mac.ops.release_swfw_sync(hw, gssr); | ||
299 | } | ||
300 | |||
301 | return status; | ||
302 | } | ||
303 | |||
304 | /** | ||
305 | * ixgbe_write_phy_reg_generic - Writes a value to specified PHY register | ||
306 | * @hw: pointer to hardware structure | ||
307 | * @reg_addr: 32 bit PHY register to write | ||
308 | * @device_type: 5 bit device type | ||
309 | * @phy_data: Data to write to the PHY register | ||
310 | **/ | ||
311 | s32 ixgbe_write_phy_reg_generic(struct ixgbe_hw *hw, u32 reg_addr, | ||
312 | u32 device_type, u16 phy_data) | ||
313 | { | ||
314 | u32 command; | ||
315 | u32 i; | ||
316 | s32 status = 0; | ||
317 | u16 gssr; | ||
318 | |||
319 | if (IXGBE_READ_REG(hw, IXGBE_STATUS) & IXGBE_STATUS_LAN_ID_1) | ||
320 | gssr = IXGBE_GSSR_PHY1_SM; | ||
321 | else | ||
322 | gssr = IXGBE_GSSR_PHY0_SM; | ||
323 | |||
324 | if (hw->mac.ops.acquire_swfw_sync(hw, gssr) != 0) | ||
325 | status = IXGBE_ERR_SWFW_SYNC; | ||
326 | |||
327 | if (status == 0) { | ||
328 | /* Put the data in the MDI single read and write data register*/ | ||
329 | IXGBE_WRITE_REG(hw, IXGBE_MSRWD, (u32)phy_data); | ||
330 | |||
331 | /* Setup and write the address cycle command */ | ||
332 | command = ((reg_addr << IXGBE_MSCA_NP_ADDR_SHIFT) | | ||
333 | (device_type << IXGBE_MSCA_DEV_TYPE_SHIFT) | | ||
334 | (hw->phy.mdio.prtad << IXGBE_MSCA_PHY_ADDR_SHIFT) | | ||
335 | (IXGBE_MSCA_ADDR_CYCLE | IXGBE_MSCA_MDI_COMMAND)); | ||
336 | |||
337 | IXGBE_WRITE_REG(hw, IXGBE_MSCA, command); | ||
338 | |||
339 | /* | ||
340 | * Check every 10 usec to see if the address cycle completed. | ||
341 | * The MDI Command bit will clear when the operation is | ||
342 | * complete | ||
343 | */ | ||
344 | for (i = 0; i < IXGBE_MDIO_COMMAND_TIMEOUT; i++) { | ||
345 | udelay(10); | ||
346 | |||
347 | command = IXGBE_READ_REG(hw, IXGBE_MSCA); | ||
348 | |||
349 | if ((command & IXGBE_MSCA_MDI_COMMAND) == 0) | ||
350 | break; | ||
351 | } | ||
352 | |||
353 | if ((command & IXGBE_MSCA_MDI_COMMAND) != 0) { | ||
354 | hw_dbg(hw, "PHY address cmd didn't complete\n"); | ||
355 | status = IXGBE_ERR_PHY; | ||
356 | } | ||
357 | |||
358 | if (status == 0) { | ||
359 | /* | ||
360 | * Address cycle complete, setup and write the write | ||
361 | * command | ||
362 | */ | ||
363 | command = ((reg_addr << IXGBE_MSCA_NP_ADDR_SHIFT) | | ||
364 | (device_type << IXGBE_MSCA_DEV_TYPE_SHIFT) | | ||
365 | (hw->phy.mdio.prtad << | ||
366 | IXGBE_MSCA_PHY_ADDR_SHIFT) | | ||
367 | (IXGBE_MSCA_WRITE | IXGBE_MSCA_MDI_COMMAND)); | ||
368 | |||
369 | IXGBE_WRITE_REG(hw, IXGBE_MSCA, command); | ||
370 | |||
371 | /* | ||
372 | * Check every 10 usec to see if the address cycle | ||
373 | * completed. The MDI Command bit will clear when the | ||
374 | * operation is complete | ||
375 | */ | ||
376 | for (i = 0; i < IXGBE_MDIO_COMMAND_TIMEOUT; i++) { | ||
377 | udelay(10); | ||
378 | |||
379 | command = IXGBE_READ_REG(hw, IXGBE_MSCA); | ||
380 | |||
381 | if ((command & IXGBE_MSCA_MDI_COMMAND) == 0) | ||
382 | break; | ||
383 | } | ||
384 | |||
385 | if ((command & IXGBE_MSCA_MDI_COMMAND) != 0) { | ||
386 | hw_dbg(hw, "PHY address cmd didn't complete\n"); | ||
387 | status = IXGBE_ERR_PHY; | ||
388 | } | ||
389 | } | ||
390 | |||
391 | hw->mac.ops.release_swfw_sync(hw, gssr); | ||
392 | } | ||
393 | |||
394 | return status; | ||
395 | } | ||
396 | |||
397 | /** | ||
398 | * ixgbe_setup_phy_link_generic - Set and restart autoneg | ||
399 | * @hw: pointer to hardware structure | ||
400 | * | ||
401 | * Restart autonegotiation and PHY and waits for completion. | ||
402 | **/ | ||
403 | s32 ixgbe_setup_phy_link_generic(struct ixgbe_hw *hw) | ||
404 | { | ||
405 | s32 status = 0; | ||
406 | u32 time_out; | ||
407 | u32 max_time_out = 10; | ||
408 | u16 autoneg_reg = IXGBE_MII_AUTONEG_REG; | ||
409 | bool autoneg = false; | ||
410 | ixgbe_link_speed speed; | ||
411 | |||
412 | ixgbe_get_copper_link_capabilities_generic(hw, &speed, &autoneg); | ||
413 | |||
414 | if (speed & IXGBE_LINK_SPEED_10GB_FULL) { | ||
415 | /* Set or unset auto-negotiation 10G advertisement */ | ||
416 | hw->phy.ops.read_reg(hw, MDIO_AN_10GBT_CTRL, | ||
417 | MDIO_MMD_AN, | ||
418 | &autoneg_reg); | ||
419 | |||
420 | autoneg_reg &= ~MDIO_AN_10GBT_CTRL_ADV10G; | ||
421 | if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_10GB_FULL) | ||
422 | autoneg_reg |= MDIO_AN_10GBT_CTRL_ADV10G; | ||
423 | |||
424 | hw->phy.ops.write_reg(hw, MDIO_AN_10GBT_CTRL, | ||
425 | MDIO_MMD_AN, | ||
426 | autoneg_reg); | ||
427 | } | ||
428 | |||
429 | if (speed & IXGBE_LINK_SPEED_1GB_FULL) { | ||
430 | /* Set or unset auto-negotiation 1G advertisement */ | ||
431 | hw->phy.ops.read_reg(hw, | ||
432 | IXGBE_MII_AUTONEG_VENDOR_PROVISION_1_REG, | ||
433 | MDIO_MMD_AN, | ||
434 | &autoneg_reg); | ||
435 | |||
436 | autoneg_reg &= ~IXGBE_MII_1GBASE_T_ADVERTISE; | ||
437 | if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_1GB_FULL) | ||
438 | autoneg_reg |= IXGBE_MII_1GBASE_T_ADVERTISE; | ||
439 | |||
440 | hw->phy.ops.write_reg(hw, | ||
441 | IXGBE_MII_AUTONEG_VENDOR_PROVISION_1_REG, | ||
442 | MDIO_MMD_AN, | ||
443 | autoneg_reg); | ||
444 | } | ||
445 | |||
446 | if (speed & IXGBE_LINK_SPEED_100_FULL) { | ||
447 | /* Set or unset auto-negotiation 100M advertisement */ | ||
448 | hw->phy.ops.read_reg(hw, MDIO_AN_ADVERTISE, | ||
449 | MDIO_MMD_AN, | ||
450 | &autoneg_reg); | ||
451 | |||
452 | autoneg_reg &= ~(ADVERTISE_100FULL | | ||
453 | ADVERTISE_100HALF); | ||
454 | if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_100_FULL) | ||
455 | autoneg_reg |= ADVERTISE_100FULL; | ||
456 | |||
457 | hw->phy.ops.write_reg(hw, MDIO_AN_ADVERTISE, | ||
458 | MDIO_MMD_AN, | ||
459 | autoneg_reg); | ||
460 | } | ||
461 | |||
462 | /* Restart PHY autonegotiation and wait for completion */ | ||
463 | hw->phy.ops.read_reg(hw, MDIO_CTRL1, | ||
464 | MDIO_MMD_AN, &autoneg_reg); | ||
465 | |||
466 | autoneg_reg |= MDIO_AN_CTRL1_RESTART; | ||
467 | |||
468 | hw->phy.ops.write_reg(hw, MDIO_CTRL1, | ||
469 | MDIO_MMD_AN, autoneg_reg); | ||
470 | |||
471 | /* Wait for autonegotiation to finish */ | ||
472 | for (time_out = 0; time_out < max_time_out; time_out++) { | ||
473 | udelay(10); | ||
474 | /* Restart PHY autonegotiation and wait for completion */ | ||
475 | status = hw->phy.ops.read_reg(hw, MDIO_STAT1, | ||
476 | MDIO_MMD_AN, | ||
477 | &autoneg_reg); | ||
478 | |||
479 | autoneg_reg &= MDIO_AN_STAT1_COMPLETE; | ||
480 | if (autoneg_reg == MDIO_AN_STAT1_COMPLETE) { | ||
481 | break; | ||
482 | } | ||
483 | } | ||
484 | |||
485 | if (time_out == max_time_out) { | ||
486 | status = IXGBE_ERR_LINK_SETUP; | ||
487 | hw_dbg(hw, "ixgbe_setup_phy_link_generic: time out"); | ||
488 | } | ||
489 | |||
490 | return status; | ||
491 | } | ||
492 | |||
493 | /** | ||
494 | * ixgbe_setup_phy_link_speed_generic - Sets the auto advertised capabilities | ||
495 | * @hw: pointer to hardware structure | ||
496 | * @speed: new link speed | ||
497 | * @autoneg: true if autonegotiation enabled | ||
498 | **/ | ||
499 | s32 ixgbe_setup_phy_link_speed_generic(struct ixgbe_hw *hw, | ||
500 | ixgbe_link_speed speed, | ||
501 | bool autoneg, | ||
502 | bool autoneg_wait_to_complete) | ||
503 | { | ||
504 | |||
505 | /* | ||
506 | * Clear autoneg_advertised and set new values based on input link | ||
507 | * speed. | ||
508 | */ | ||
509 | hw->phy.autoneg_advertised = 0; | ||
510 | |||
511 | if (speed & IXGBE_LINK_SPEED_10GB_FULL) | ||
512 | hw->phy.autoneg_advertised |= IXGBE_LINK_SPEED_10GB_FULL; | ||
513 | |||
514 | if (speed & IXGBE_LINK_SPEED_1GB_FULL) | ||
515 | hw->phy.autoneg_advertised |= IXGBE_LINK_SPEED_1GB_FULL; | ||
516 | |||
517 | if (speed & IXGBE_LINK_SPEED_100_FULL) | ||
518 | hw->phy.autoneg_advertised |= IXGBE_LINK_SPEED_100_FULL; | ||
519 | |||
520 | /* Setup link based on the new speed settings */ | ||
521 | hw->phy.ops.setup_link(hw); | ||
522 | |||
523 | return 0; | ||
524 | } | ||
525 | |||
526 | /** | ||
527 | * ixgbe_get_copper_link_capabilities_generic - Determines link capabilities | ||
528 | * @hw: pointer to hardware structure | ||
529 | * @speed: pointer to link speed | ||
530 | * @autoneg: boolean auto-negotiation value | ||
531 | * | ||
532 | * Determines the link capabilities by reading the AUTOC register. | ||
533 | */ | ||
534 | s32 ixgbe_get_copper_link_capabilities_generic(struct ixgbe_hw *hw, | ||
535 | ixgbe_link_speed *speed, | ||
536 | bool *autoneg) | ||
537 | { | ||
538 | s32 status = IXGBE_ERR_LINK_SETUP; | ||
539 | u16 speed_ability; | ||
540 | |||
541 | *speed = 0; | ||
542 | *autoneg = true; | ||
543 | |||
544 | status = hw->phy.ops.read_reg(hw, MDIO_SPEED, MDIO_MMD_PMAPMD, | ||
545 | &speed_ability); | ||
546 | |||
547 | if (status == 0) { | ||
548 | if (speed_ability & MDIO_SPEED_10G) | ||
549 | *speed |= IXGBE_LINK_SPEED_10GB_FULL; | ||
550 | if (speed_ability & MDIO_PMA_SPEED_1000) | ||
551 | *speed |= IXGBE_LINK_SPEED_1GB_FULL; | ||
552 | if (speed_ability & MDIO_PMA_SPEED_100) | ||
553 | *speed |= IXGBE_LINK_SPEED_100_FULL; | ||
554 | } | ||
555 | |||
556 | return status; | ||
557 | } | ||
558 | |||
559 | /** | ||
560 | * ixgbe_check_phy_link_tnx - Determine link and speed status | ||
561 | * @hw: pointer to hardware structure | ||
562 | * | ||
563 | * Reads the VS1 register to determine if link is up and the current speed for | ||
564 | * the PHY. | ||
565 | **/ | ||
566 | s32 ixgbe_check_phy_link_tnx(struct ixgbe_hw *hw, ixgbe_link_speed *speed, | ||
567 | bool *link_up) | ||
568 | { | ||
569 | s32 status = 0; | ||
570 | u32 time_out; | ||
571 | u32 max_time_out = 10; | ||
572 | u16 phy_link = 0; | ||
573 | u16 phy_speed = 0; | ||
574 | u16 phy_data = 0; | ||
575 | |||
576 | /* Initialize speed and link to default case */ | ||
577 | *link_up = false; | ||
578 | *speed = IXGBE_LINK_SPEED_10GB_FULL; | ||
579 | |||
580 | /* | ||
581 | * Check current speed and link status of the PHY register. | ||
582 | * This is a vendor specific register and may have to | ||
583 | * be changed for other copper PHYs. | ||
584 | */ | ||
585 | for (time_out = 0; time_out < max_time_out; time_out++) { | ||
586 | udelay(10); | ||
587 | status = hw->phy.ops.read_reg(hw, | ||
588 | MDIO_STAT1, | ||
589 | MDIO_MMD_VEND1, | ||
590 | &phy_data); | ||
591 | phy_link = phy_data & | ||
592 | IXGBE_MDIO_VENDOR_SPECIFIC_1_LINK_STATUS; | ||
593 | phy_speed = phy_data & | ||
594 | IXGBE_MDIO_VENDOR_SPECIFIC_1_SPEED_STATUS; | ||
595 | if (phy_link == IXGBE_MDIO_VENDOR_SPECIFIC_1_LINK_STATUS) { | ||
596 | *link_up = true; | ||
597 | if (phy_speed == | ||
598 | IXGBE_MDIO_VENDOR_SPECIFIC_1_SPEED_STATUS) | ||
599 | *speed = IXGBE_LINK_SPEED_1GB_FULL; | ||
600 | break; | ||
601 | } | ||
602 | } | ||
603 | |||
604 | return status; | ||
605 | } | ||
606 | |||
607 | /** | ||
608 | * ixgbe_setup_phy_link_tnx - Set and restart autoneg | ||
609 | * @hw: pointer to hardware structure | ||
610 | * | ||
611 | * Restart autonegotiation and PHY and waits for completion. | ||
612 | **/ | ||
613 | s32 ixgbe_setup_phy_link_tnx(struct ixgbe_hw *hw) | ||
614 | { | ||
615 | s32 status = 0; | ||
616 | u32 time_out; | ||
617 | u32 max_time_out = 10; | ||
618 | u16 autoneg_reg = IXGBE_MII_AUTONEG_REG; | ||
619 | bool autoneg = false; | ||
620 | ixgbe_link_speed speed; | ||
621 | |||
622 | ixgbe_get_copper_link_capabilities_generic(hw, &speed, &autoneg); | ||
623 | |||
624 | if (speed & IXGBE_LINK_SPEED_10GB_FULL) { | ||
625 | /* Set or unset auto-negotiation 10G advertisement */ | ||
626 | hw->phy.ops.read_reg(hw, MDIO_AN_10GBT_CTRL, | ||
627 | MDIO_MMD_AN, | ||
628 | &autoneg_reg); | ||
629 | |||
630 | autoneg_reg &= ~MDIO_AN_10GBT_CTRL_ADV10G; | ||
631 | if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_10GB_FULL) | ||
632 | autoneg_reg |= MDIO_AN_10GBT_CTRL_ADV10G; | ||
633 | |||
634 | hw->phy.ops.write_reg(hw, MDIO_AN_10GBT_CTRL, | ||
635 | MDIO_MMD_AN, | ||
636 | autoneg_reg); | ||
637 | } | ||
638 | |||
639 | if (speed & IXGBE_LINK_SPEED_1GB_FULL) { | ||
640 | /* Set or unset auto-negotiation 1G advertisement */ | ||
641 | hw->phy.ops.read_reg(hw, IXGBE_MII_AUTONEG_XNP_TX_REG, | ||
642 | MDIO_MMD_AN, | ||
643 | &autoneg_reg); | ||
644 | |||
645 | autoneg_reg &= ~IXGBE_MII_1GBASE_T_ADVERTISE_XNP_TX; | ||
646 | if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_1GB_FULL) | ||
647 | autoneg_reg |= IXGBE_MII_1GBASE_T_ADVERTISE_XNP_TX; | ||
648 | |||
649 | hw->phy.ops.write_reg(hw, IXGBE_MII_AUTONEG_XNP_TX_REG, | ||
650 | MDIO_MMD_AN, | ||
651 | autoneg_reg); | ||
652 | } | ||
653 | |||
654 | if (speed & IXGBE_LINK_SPEED_100_FULL) { | ||
655 | /* Set or unset auto-negotiation 100M advertisement */ | ||
656 | hw->phy.ops.read_reg(hw, MDIO_AN_ADVERTISE, | ||
657 | MDIO_MMD_AN, | ||
658 | &autoneg_reg); | ||
659 | |||
660 | autoneg_reg &= ~(ADVERTISE_100FULL | | ||
661 | ADVERTISE_100HALF); | ||
662 | if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_100_FULL) | ||
663 | autoneg_reg |= ADVERTISE_100FULL; | ||
664 | |||
665 | hw->phy.ops.write_reg(hw, MDIO_AN_ADVERTISE, | ||
666 | MDIO_MMD_AN, | ||
667 | autoneg_reg); | ||
668 | } | ||
669 | |||
670 | /* Restart PHY autonegotiation and wait for completion */ | ||
671 | hw->phy.ops.read_reg(hw, MDIO_CTRL1, | ||
672 | MDIO_MMD_AN, &autoneg_reg); | ||
673 | |||
674 | autoneg_reg |= MDIO_AN_CTRL1_RESTART; | ||
675 | |||
676 | hw->phy.ops.write_reg(hw, MDIO_CTRL1, | ||
677 | MDIO_MMD_AN, autoneg_reg); | ||
678 | |||
679 | /* Wait for autonegotiation to finish */ | ||
680 | for (time_out = 0; time_out < max_time_out; time_out++) { | ||
681 | udelay(10); | ||
682 | /* Restart PHY autonegotiation and wait for completion */ | ||
683 | status = hw->phy.ops.read_reg(hw, MDIO_STAT1, | ||
684 | MDIO_MMD_AN, | ||
685 | &autoneg_reg); | ||
686 | |||
687 | autoneg_reg &= MDIO_AN_STAT1_COMPLETE; | ||
688 | if (autoneg_reg == MDIO_AN_STAT1_COMPLETE) | ||
689 | break; | ||
690 | } | ||
691 | |||
692 | if (time_out == max_time_out) { | ||
693 | status = IXGBE_ERR_LINK_SETUP; | ||
694 | hw_dbg(hw, "ixgbe_setup_phy_link_tnx: time out"); | ||
695 | } | ||
696 | |||
697 | return status; | ||
698 | } | ||
699 | |||
700 | /** | ||
701 | * ixgbe_get_phy_firmware_version_tnx - Gets the PHY Firmware Version | ||
702 | * @hw: pointer to hardware structure | ||
703 | * @firmware_version: pointer to the PHY Firmware Version | ||
704 | **/ | ||
705 | s32 ixgbe_get_phy_firmware_version_tnx(struct ixgbe_hw *hw, | ||
706 | u16 *firmware_version) | ||
707 | { | ||
708 | s32 status = 0; | ||
709 | |||
710 | status = hw->phy.ops.read_reg(hw, TNX_FW_REV, | ||
711 | MDIO_MMD_VEND1, | ||
712 | firmware_version); | ||
713 | |||
714 | return status; | ||
715 | } | ||
716 | |||
717 | /** | ||
718 | * ixgbe_get_phy_firmware_version_generic - Gets the PHY Firmware Version | ||
719 | * @hw: pointer to hardware structure | ||
720 | * @firmware_version: pointer to the PHY Firmware Version | ||
721 | **/ | ||
722 | s32 ixgbe_get_phy_firmware_version_generic(struct ixgbe_hw *hw, | ||
723 | u16 *firmware_version) | ||
724 | { | ||
725 | s32 status = 0; | ||
726 | |||
727 | status = hw->phy.ops.read_reg(hw, AQ_FW_REV, | ||
728 | MDIO_MMD_VEND1, | ||
729 | firmware_version); | ||
730 | |||
731 | return status; | ||
732 | } | ||
733 | |||
734 | /** | ||
735 | * ixgbe_reset_phy_nl - Performs a PHY reset | ||
736 | * @hw: pointer to hardware structure | ||
737 | **/ | ||
738 | s32 ixgbe_reset_phy_nl(struct ixgbe_hw *hw) | ||
739 | { | ||
740 | u16 phy_offset, control, eword, edata, block_crc; | ||
741 | bool end_data = false; | ||
742 | u16 list_offset, data_offset; | ||
743 | u16 phy_data = 0; | ||
744 | s32 ret_val = 0; | ||
745 | u32 i; | ||
746 | |||
747 | hw->phy.ops.read_reg(hw, MDIO_CTRL1, MDIO_MMD_PHYXS, &phy_data); | ||
748 | |||
749 | /* reset the PHY and poll for completion */ | ||
750 | hw->phy.ops.write_reg(hw, MDIO_CTRL1, MDIO_MMD_PHYXS, | ||
751 | (phy_data | MDIO_CTRL1_RESET)); | ||
752 | |||
753 | for (i = 0; i < 100; i++) { | ||
754 | hw->phy.ops.read_reg(hw, MDIO_CTRL1, MDIO_MMD_PHYXS, | ||
755 | &phy_data); | ||
756 | if ((phy_data & MDIO_CTRL1_RESET) == 0) | ||
757 | break; | ||
758 | usleep_range(10000, 20000); | ||
759 | } | ||
760 | |||
761 | if ((phy_data & MDIO_CTRL1_RESET) != 0) { | ||
762 | hw_dbg(hw, "PHY reset did not complete.\n"); | ||
763 | ret_val = IXGBE_ERR_PHY; | ||
764 | goto out; | ||
765 | } | ||
766 | |||
767 | /* Get init offsets */ | ||
768 | ret_val = ixgbe_get_sfp_init_sequence_offsets(hw, &list_offset, | ||
769 | &data_offset); | ||
770 | if (ret_val != 0) | ||
771 | goto out; | ||
772 | |||
773 | ret_val = hw->eeprom.ops.read(hw, data_offset, &block_crc); | ||
774 | data_offset++; | ||
775 | while (!end_data) { | ||
776 | /* | ||
777 | * Read control word from PHY init contents offset | ||
778 | */ | ||
779 | ret_val = hw->eeprom.ops.read(hw, data_offset, &eword); | ||
780 | control = (eword & IXGBE_CONTROL_MASK_NL) >> | ||
781 | IXGBE_CONTROL_SHIFT_NL; | ||
782 | edata = eword & IXGBE_DATA_MASK_NL; | ||
783 | switch (control) { | ||
784 | case IXGBE_DELAY_NL: | ||
785 | data_offset++; | ||
786 | hw_dbg(hw, "DELAY: %d MS\n", edata); | ||
787 | usleep_range(edata * 1000, edata * 2000); | ||
788 | break; | ||
789 | case IXGBE_DATA_NL: | ||
790 | hw_dbg(hw, "DATA:\n"); | ||
791 | data_offset++; | ||
792 | hw->eeprom.ops.read(hw, data_offset++, | ||
793 | &phy_offset); | ||
794 | for (i = 0; i < edata; i++) { | ||
795 | hw->eeprom.ops.read(hw, data_offset, &eword); | ||
796 | hw->phy.ops.write_reg(hw, phy_offset, | ||
797 | MDIO_MMD_PMAPMD, eword); | ||
798 | hw_dbg(hw, "Wrote %4.4x to %4.4x\n", eword, | ||
799 | phy_offset); | ||
800 | data_offset++; | ||
801 | phy_offset++; | ||
802 | } | ||
803 | break; | ||
804 | case IXGBE_CONTROL_NL: | ||
805 | data_offset++; | ||
806 | hw_dbg(hw, "CONTROL:\n"); | ||
807 | if (edata == IXGBE_CONTROL_EOL_NL) { | ||
808 | hw_dbg(hw, "EOL\n"); | ||
809 | end_data = true; | ||
810 | } else if (edata == IXGBE_CONTROL_SOL_NL) { | ||
811 | hw_dbg(hw, "SOL\n"); | ||
812 | } else { | ||
813 | hw_dbg(hw, "Bad control value\n"); | ||
814 | ret_val = IXGBE_ERR_PHY; | ||
815 | goto out; | ||
816 | } | ||
817 | break; | ||
818 | default: | ||
819 | hw_dbg(hw, "Bad control type\n"); | ||
820 | ret_val = IXGBE_ERR_PHY; | ||
821 | goto out; | ||
822 | } | ||
823 | } | ||
824 | |||
825 | out: | ||
826 | return ret_val; | ||
827 | } | ||
828 | |||
829 | /** | ||
830 | * ixgbe_identify_sfp_module_generic - Identifies SFP modules | ||
831 | * @hw: pointer to hardware structure | ||
832 | * | ||
833 | * Searches for and identifies the SFP module and assigns appropriate PHY type. | ||
834 | **/ | ||
835 | s32 ixgbe_identify_sfp_module_generic(struct ixgbe_hw *hw) | ||
836 | { | ||
837 | s32 status = IXGBE_ERR_PHY_ADDR_INVALID; | ||
838 | u32 vendor_oui = 0; | ||
839 | enum ixgbe_sfp_type stored_sfp_type = hw->phy.sfp_type; | ||
840 | u8 identifier = 0; | ||
841 | u8 comp_codes_1g = 0; | ||
842 | u8 comp_codes_10g = 0; | ||
843 | u8 oui_bytes[3] = {0, 0, 0}; | ||
844 | u8 cable_tech = 0; | ||
845 | u8 cable_spec = 0; | ||
846 | u16 enforce_sfp = 0; | ||
847 | |||
848 | if (hw->mac.ops.get_media_type(hw) != ixgbe_media_type_fiber) { | ||
849 | hw->phy.sfp_type = ixgbe_sfp_type_not_present; | ||
850 | status = IXGBE_ERR_SFP_NOT_PRESENT; | ||
851 | goto out; | ||
852 | } | ||
853 | |||
854 | status = hw->phy.ops.read_i2c_eeprom(hw, | ||
855 | IXGBE_SFF_IDENTIFIER, | ||
856 | &identifier); | ||
857 | |||
858 | if (status == IXGBE_ERR_SWFW_SYNC || | ||
859 | status == IXGBE_ERR_I2C || | ||
860 | status == IXGBE_ERR_SFP_NOT_PRESENT) | ||
861 | goto err_read_i2c_eeprom; | ||
862 | |||
863 | /* LAN ID is needed for sfp_type determination */ | ||
864 | hw->mac.ops.set_lan_id(hw); | ||
865 | |||
866 | if (identifier != IXGBE_SFF_IDENTIFIER_SFP) { | ||
867 | hw->phy.type = ixgbe_phy_sfp_unsupported; | ||
868 | status = IXGBE_ERR_SFP_NOT_SUPPORTED; | ||
869 | } else { | ||
870 | status = hw->phy.ops.read_i2c_eeprom(hw, | ||
871 | IXGBE_SFF_1GBE_COMP_CODES, | ||
872 | &comp_codes_1g); | ||
873 | |||
874 | if (status == IXGBE_ERR_SWFW_SYNC || | ||
875 | status == IXGBE_ERR_I2C || | ||
876 | status == IXGBE_ERR_SFP_NOT_PRESENT) | ||
877 | goto err_read_i2c_eeprom; | ||
878 | |||
879 | status = hw->phy.ops.read_i2c_eeprom(hw, | ||
880 | IXGBE_SFF_10GBE_COMP_CODES, | ||
881 | &comp_codes_10g); | ||
882 | |||
883 | if (status == IXGBE_ERR_SWFW_SYNC || | ||
884 | status == IXGBE_ERR_I2C || | ||
885 | status == IXGBE_ERR_SFP_NOT_PRESENT) | ||
886 | goto err_read_i2c_eeprom; | ||
887 | status = hw->phy.ops.read_i2c_eeprom(hw, | ||
888 | IXGBE_SFF_CABLE_TECHNOLOGY, | ||
889 | &cable_tech); | ||
890 | |||
891 | if (status == IXGBE_ERR_SWFW_SYNC || | ||
892 | status == IXGBE_ERR_I2C || | ||
893 | status == IXGBE_ERR_SFP_NOT_PRESENT) | ||
894 | goto err_read_i2c_eeprom; | ||
895 | |||
896 | /* ID Module | ||
897 | * ========= | ||
898 | * 0 SFP_DA_CU | ||
899 | * 1 SFP_SR | ||
900 | * 2 SFP_LR | ||
901 | * 3 SFP_DA_CORE0 - 82599-specific | ||
902 | * 4 SFP_DA_CORE1 - 82599-specific | ||
903 | * 5 SFP_SR/LR_CORE0 - 82599-specific | ||
904 | * 6 SFP_SR/LR_CORE1 - 82599-specific | ||
905 | * 7 SFP_act_lmt_DA_CORE0 - 82599-specific | ||
906 | * 8 SFP_act_lmt_DA_CORE1 - 82599-specific | ||
907 | * 9 SFP_1g_cu_CORE0 - 82599-specific | ||
908 | * 10 SFP_1g_cu_CORE1 - 82599-specific | ||
909 | */ | ||
910 | if (hw->mac.type == ixgbe_mac_82598EB) { | ||
911 | if (cable_tech & IXGBE_SFF_DA_PASSIVE_CABLE) | ||
912 | hw->phy.sfp_type = ixgbe_sfp_type_da_cu; | ||
913 | else if (comp_codes_10g & IXGBE_SFF_10GBASESR_CAPABLE) | ||
914 | hw->phy.sfp_type = ixgbe_sfp_type_sr; | ||
915 | else if (comp_codes_10g & IXGBE_SFF_10GBASELR_CAPABLE) | ||
916 | hw->phy.sfp_type = ixgbe_sfp_type_lr; | ||
917 | else | ||
918 | hw->phy.sfp_type = ixgbe_sfp_type_unknown; | ||
919 | } else if (hw->mac.type == ixgbe_mac_82599EB) { | ||
920 | if (cable_tech & IXGBE_SFF_DA_PASSIVE_CABLE) { | ||
921 | if (hw->bus.lan_id == 0) | ||
922 | hw->phy.sfp_type = | ||
923 | ixgbe_sfp_type_da_cu_core0; | ||
924 | else | ||
925 | hw->phy.sfp_type = | ||
926 | ixgbe_sfp_type_da_cu_core1; | ||
927 | } else if (cable_tech & IXGBE_SFF_DA_ACTIVE_CABLE) { | ||
928 | hw->phy.ops.read_i2c_eeprom( | ||
929 | hw, IXGBE_SFF_CABLE_SPEC_COMP, | ||
930 | &cable_spec); | ||
931 | if (cable_spec & | ||
932 | IXGBE_SFF_DA_SPEC_ACTIVE_LIMITING) { | ||
933 | if (hw->bus.lan_id == 0) | ||
934 | hw->phy.sfp_type = | ||
935 | ixgbe_sfp_type_da_act_lmt_core0; | ||
936 | else | ||
937 | hw->phy.sfp_type = | ||
938 | ixgbe_sfp_type_da_act_lmt_core1; | ||
939 | } else { | ||
940 | hw->phy.sfp_type = | ||
941 | ixgbe_sfp_type_unknown; | ||
942 | } | ||
943 | } else if (comp_codes_10g & | ||
944 | (IXGBE_SFF_10GBASESR_CAPABLE | | ||
945 | IXGBE_SFF_10GBASELR_CAPABLE)) { | ||
946 | if (hw->bus.lan_id == 0) | ||
947 | hw->phy.sfp_type = | ||
948 | ixgbe_sfp_type_srlr_core0; | ||
949 | else | ||
950 | hw->phy.sfp_type = | ||
951 | ixgbe_sfp_type_srlr_core1; | ||
952 | } else if (comp_codes_1g & IXGBE_SFF_1GBASET_CAPABLE) { | ||
953 | if (hw->bus.lan_id == 0) | ||
954 | hw->phy.sfp_type = | ||
955 | ixgbe_sfp_type_1g_cu_core0; | ||
956 | else | ||
957 | hw->phy.sfp_type = | ||
958 | ixgbe_sfp_type_1g_cu_core1; | ||
959 | } else { | ||
960 | hw->phy.sfp_type = ixgbe_sfp_type_unknown; | ||
961 | } | ||
962 | } | ||
963 | |||
964 | if (hw->phy.sfp_type != stored_sfp_type) | ||
965 | hw->phy.sfp_setup_needed = true; | ||
966 | |||
967 | /* Determine if the SFP+ PHY is dual speed or not. */ | ||
968 | hw->phy.multispeed_fiber = false; | ||
969 | if (((comp_codes_1g & IXGBE_SFF_1GBASESX_CAPABLE) && | ||
970 | (comp_codes_10g & IXGBE_SFF_10GBASESR_CAPABLE)) || | ||
971 | ((comp_codes_1g & IXGBE_SFF_1GBASELX_CAPABLE) && | ||
972 | (comp_codes_10g & IXGBE_SFF_10GBASELR_CAPABLE))) | ||
973 | hw->phy.multispeed_fiber = true; | ||
974 | |||
975 | /* Determine PHY vendor */ | ||
976 | if (hw->phy.type != ixgbe_phy_nl) { | ||
977 | hw->phy.id = identifier; | ||
978 | status = hw->phy.ops.read_i2c_eeprom(hw, | ||
979 | IXGBE_SFF_VENDOR_OUI_BYTE0, | ||
980 | &oui_bytes[0]); | ||
981 | |||
982 | if (status == IXGBE_ERR_SWFW_SYNC || | ||
983 | status == IXGBE_ERR_I2C || | ||
984 | status == IXGBE_ERR_SFP_NOT_PRESENT) | ||
985 | goto err_read_i2c_eeprom; | ||
986 | |||
987 | status = hw->phy.ops.read_i2c_eeprom(hw, | ||
988 | IXGBE_SFF_VENDOR_OUI_BYTE1, | ||
989 | &oui_bytes[1]); | ||
990 | |||
991 | if (status == IXGBE_ERR_SWFW_SYNC || | ||
992 | status == IXGBE_ERR_I2C || | ||
993 | status == IXGBE_ERR_SFP_NOT_PRESENT) | ||
994 | goto err_read_i2c_eeprom; | ||
995 | |||
996 | status = hw->phy.ops.read_i2c_eeprom(hw, | ||
997 | IXGBE_SFF_VENDOR_OUI_BYTE2, | ||
998 | &oui_bytes[2]); | ||
999 | |||
1000 | if (status == IXGBE_ERR_SWFW_SYNC || | ||
1001 | status == IXGBE_ERR_I2C || | ||
1002 | status == IXGBE_ERR_SFP_NOT_PRESENT) | ||
1003 | goto err_read_i2c_eeprom; | ||
1004 | |||
1005 | vendor_oui = | ||
1006 | ((oui_bytes[0] << IXGBE_SFF_VENDOR_OUI_BYTE0_SHIFT) | | ||
1007 | (oui_bytes[1] << IXGBE_SFF_VENDOR_OUI_BYTE1_SHIFT) | | ||
1008 | (oui_bytes[2] << IXGBE_SFF_VENDOR_OUI_BYTE2_SHIFT)); | ||
1009 | |||
1010 | switch (vendor_oui) { | ||
1011 | case IXGBE_SFF_VENDOR_OUI_TYCO: | ||
1012 | if (cable_tech & IXGBE_SFF_DA_PASSIVE_CABLE) | ||
1013 | hw->phy.type = | ||
1014 | ixgbe_phy_sfp_passive_tyco; | ||
1015 | break; | ||
1016 | case IXGBE_SFF_VENDOR_OUI_FTL: | ||
1017 | if (cable_tech & IXGBE_SFF_DA_ACTIVE_CABLE) | ||
1018 | hw->phy.type = ixgbe_phy_sfp_ftl_active; | ||
1019 | else | ||
1020 | hw->phy.type = ixgbe_phy_sfp_ftl; | ||
1021 | break; | ||
1022 | case IXGBE_SFF_VENDOR_OUI_AVAGO: | ||
1023 | hw->phy.type = ixgbe_phy_sfp_avago; | ||
1024 | break; | ||
1025 | case IXGBE_SFF_VENDOR_OUI_INTEL: | ||
1026 | hw->phy.type = ixgbe_phy_sfp_intel; | ||
1027 | break; | ||
1028 | default: | ||
1029 | if (cable_tech & IXGBE_SFF_DA_PASSIVE_CABLE) | ||
1030 | hw->phy.type = | ||
1031 | ixgbe_phy_sfp_passive_unknown; | ||
1032 | else if (cable_tech & IXGBE_SFF_DA_ACTIVE_CABLE) | ||
1033 | hw->phy.type = | ||
1034 | ixgbe_phy_sfp_active_unknown; | ||
1035 | else | ||
1036 | hw->phy.type = ixgbe_phy_sfp_unknown; | ||
1037 | break; | ||
1038 | } | ||
1039 | } | ||
1040 | |||
1041 | /* Allow any DA cable vendor */ | ||
1042 | if (cable_tech & (IXGBE_SFF_DA_PASSIVE_CABLE | | ||
1043 | IXGBE_SFF_DA_ACTIVE_CABLE)) { | ||
1044 | status = 0; | ||
1045 | goto out; | ||
1046 | } | ||
1047 | |||
1048 | /* Verify supported 1G SFP modules */ | ||
1049 | if (comp_codes_10g == 0 && | ||
1050 | !(hw->phy.sfp_type == ixgbe_sfp_type_1g_cu_core1 || | ||
1051 | hw->phy.sfp_type == ixgbe_sfp_type_1g_cu_core0)) { | ||
1052 | hw->phy.type = ixgbe_phy_sfp_unsupported; | ||
1053 | status = IXGBE_ERR_SFP_NOT_SUPPORTED; | ||
1054 | goto out; | ||
1055 | } | ||
1056 | |||
1057 | /* Anything else 82598-based is supported */ | ||
1058 | if (hw->mac.type == ixgbe_mac_82598EB) { | ||
1059 | status = 0; | ||
1060 | goto out; | ||
1061 | } | ||
1062 | |||
1063 | hw->mac.ops.get_device_caps(hw, &enforce_sfp); | ||
1064 | if (!(enforce_sfp & IXGBE_DEVICE_CAPS_ALLOW_ANY_SFP) && | ||
1065 | !((hw->phy.sfp_type == ixgbe_sfp_type_1g_cu_core0) || | ||
1066 | (hw->phy.sfp_type == ixgbe_sfp_type_1g_cu_core1))) { | ||
1067 | /* Make sure we're a supported PHY type */ | ||
1068 | if (hw->phy.type == ixgbe_phy_sfp_intel) { | ||
1069 | status = 0; | ||
1070 | } else { | ||
1071 | hw_dbg(hw, "SFP+ module not supported\n"); | ||
1072 | hw->phy.type = ixgbe_phy_sfp_unsupported; | ||
1073 | status = IXGBE_ERR_SFP_NOT_SUPPORTED; | ||
1074 | } | ||
1075 | } else { | ||
1076 | status = 0; | ||
1077 | } | ||
1078 | } | ||
1079 | |||
1080 | out: | ||
1081 | return status; | ||
1082 | |||
1083 | err_read_i2c_eeprom: | ||
1084 | hw->phy.sfp_type = ixgbe_sfp_type_not_present; | ||
1085 | if (hw->phy.type != ixgbe_phy_nl) { | ||
1086 | hw->phy.id = 0; | ||
1087 | hw->phy.type = ixgbe_phy_unknown; | ||
1088 | } | ||
1089 | return IXGBE_ERR_SFP_NOT_PRESENT; | ||
1090 | } | ||
1091 | |||
1092 | /** | ||
1093 | * ixgbe_get_sfp_init_sequence_offsets - Provides offset of PHY init sequence | ||
1094 | * @hw: pointer to hardware structure | ||
1095 | * @list_offset: offset to the SFP ID list | ||
1096 | * @data_offset: offset to the SFP data block | ||
1097 | * | ||
1098 | * Checks the MAC's EEPROM to see if it supports a given SFP+ module type, if | ||
1099 | * so it returns the offsets to the phy init sequence block. | ||
1100 | **/ | ||
1101 | s32 ixgbe_get_sfp_init_sequence_offsets(struct ixgbe_hw *hw, | ||
1102 | u16 *list_offset, | ||
1103 | u16 *data_offset) | ||
1104 | { | ||
1105 | u16 sfp_id; | ||
1106 | u16 sfp_type = hw->phy.sfp_type; | ||
1107 | |||
1108 | if (hw->phy.sfp_type == ixgbe_sfp_type_unknown) | ||
1109 | return IXGBE_ERR_SFP_NOT_SUPPORTED; | ||
1110 | |||
1111 | if (hw->phy.sfp_type == ixgbe_sfp_type_not_present) | ||
1112 | return IXGBE_ERR_SFP_NOT_PRESENT; | ||
1113 | |||
1114 | if ((hw->device_id == IXGBE_DEV_ID_82598_SR_DUAL_PORT_EM) && | ||
1115 | (hw->phy.sfp_type == ixgbe_sfp_type_da_cu)) | ||
1116 | return IXGBE_ERR_SFP_NOT_SUPPORTED; | ||
1117 | |||
1118 | /* | ||
1119 | * Limiting active cables and 1G Phys must be initialized as | ||
1120 | * SR modules | ||
1121 | */ | ||
1122 | if (sfp_type == ixgbe_sfp_type_da_act_lmt_core0 || | ||
1123 | sfp_type == ixgbe_sfp_type_1g_cu_core0) | ||
1124 | sfp_type = ixgbe_sfp_type_srlr_core0; | ||
1125 | else if (sfp_type == ixgbe_sfp_type_da_act_lmt_core1 || | ||
1126 | sfp_type == ixgbe_sfp_type_1g_cu_core1) | ||
1127 | sfp_type = ixgbe_sfp_type_srlr_core1; | ||
1128 | |||
1129 | /* Read offset to PHY init contents */ | ||
1130 | hw->eeprom.ops.read(hw, IXGBE_PHY_INIT_OFFSET_NL, list_offset); | ||
1131 | |||
1132 | if ((!*list_offset) || (*list_offset == 0xFFFF)) | ||
1133 | return IXGBE_ERR_SFP_NO_INIT_SEQ_PRESENT; | ||
1134 | |||
1135 | /* Shift offset to first ID word */ | ||
1136 | (*list_offset)++; | ||
1137 | |||
1138 | /* | ||
1139 | * Find the matching SFP ID in the EEPROM | ||
1140 | * and program the init sequence | ||
1141 | */ | ||
1142 | hw->eeprom.ops.read(hw, *list_offset, &sfp_id); | ||
1143 | |||
1144 | while (sfp_id != IXGBE_PHY_INIT_END_NL) { | ||
1145 | if (sfp_id == sfp_type) { | ||
1146 | (*list_offset)++; | ||
1147 | hw->eeprom.ops.read(hw, *list_offset, data_offset); | ||
1148 | if ((!*data_offset) || (*data_offset == 0xFFFF)) { | ||
1149 | hw_dbg(hw, "SFP+ module not supported\n"); | ||
1150 | return IXGBE_ERR_SFP_NOT_SUPPORTED; | ||
1151 | } else { | ||
1152 | break; | ||
1153 | } | ||
1154 | } else { | ||
1155 | (*list_offset) += 2; | ||
1156 | if (hw->eeprom.ops.read(hw, *list_offset, &sfp_id)) | ||
1157 | return IXGBE_ERR_PHY; | ||
1158 | } | ||
1159 | } | ||
1160 | |||
1161 | if (sfp_id == IXGBE_PHY_INIT_END_NL) { | ||
1162 | hw_dbg(hw, "No matching SFP+ module found\n"); | ||
1163 | return IXGBE_ERR_SFP_NOT_SUPPORTED; | ||
1164 | } | ||
1165 | |||
1166 | return 0; | ||
1167 | } | ||
1168 | |||
1169 | /** | ||
1170 | * ixgbe_read_i2c_eeprom_generic - Reads 8 bit EEPROM word over I2C interface | ||
1171 | * @hw: pointer to hardware structure | ||
1172 | * @byte_offset: EEPROM byte offset to read | ||
1173 | * @eeprom_data: value read | ||
1174 | * | ||
1175 | * Performs byte read operation to SFP module's EEPROM over I2C interface. | ||
1176 | **/ | ||
1177 | s32 ixgbe_read_i2c_eeprom_generic(struct ixgbe_hw *hw, u8 byte_offset, | ||
1178 | u8 *eeprom_data) | ||
1179 | { | ||
1180 | return hw->phy.ops.read_i2c_byte(hw, byte_offset, | ||
1181 | IXGBE_I2C_EEPROM_DEV_ADDR, | ||
1182 | eeprom_data); | ||
1183 | } | ||
1184 | |||
1185 | /** | ||
1186 | * ixgbe_write_i2c_eeprom_generic - Writes 8 bit EEPROM word over I2C interface | ||
1187 | * @hw: pointer to hardware structure | ||
1188 | * @byte_offset: EEPROM byte offset to write | ||
1189 | * @eeprom_data: value to write | ||
1190 | * | ||
1191 | * Performs byte write operation to SFP module's EEPROM over I2C interface. | ||
1192 | **/ | ||
1193 | s32 ixgbe_write_i2c_eeprom_generic(struct ixgbe_hw *hw, u8 byte_offset, | ||
1194 | u8 eeprom_data) | ||
1195 | { | ||
1196 | return hw->phy.ops.write_i2c_byte(hw, byte_offset, | ||
1197 | IXGBE_I2C_EEPROM_DEV_ADDR, | ||
1198 | eeprom_data); | ||
1199 | } | ||
1200 | |||
1201 | /** | ||
1202 | * ixgbe_read_i2c_byte_generic - Reads 8 bit word over I2C | ||
1203 | * @hw: pointer to hardware structure | ||
1204 | * @byte_offset: byte offset to read | ||
1205 | * @data: value read | ||
1206 | * | ||
1207 | * Performs byte read operation to SFP module's EEPROM over I2C interface at | ||
1208 | * a specified deivce address. | ||
1209 | **/ | ||
1210 | s32 ixgbe_read_i2c_byte_generic(struct ixgbe_hw *hw, u8 byte_offset, | ||
1211 | u8 dev_addr, u8 *data) | ||
1212 | { | ||
1213 | s32 status = 0; | ||
1214 | u32 max_retry = 10; | ||
1215 | u32 retry = 0; | ||
1216 | u16 swfw_mask = 0; | ||
1217 | bool nack = 1; | ||
1218 | |||
1219 | if (IXGBE_READ_REG(hw, IXGBE_STATUS) & IXGBE_STATUS_LAN_ID_1) | ||
1220 | swfw_mask = IXGBE_GSSR_PHY1_SM; | ||
1221 | else | ||
1222 | swfw_mask = IXGBE_GSSR_PHY0_SM; | ||
1223 | |||
1224 | do { | ||
1225 | if (hw->mac.ops.acquire_swfw_sync(hw, swfw_mask) != 0) { | ||
1226 | status = IXGBE_ERR_SWFW_SYNC; | ||
1227 | goto read_byte_out; | ||
1228 | } | ||
1229 | |||
1230 | ixgbe_i2c_start(hw); | ||
1231 | |||
1232 | /* Device Address and write indication */ | ||
1233 | status = ixgbe_clock_out_i2c_byte(hw, dev_addr); | ||
1234 | if (status != 0) | ||
1235 | goto fail; | ||
1236 | |||
1237 | status = ixgbe_get_i2c_ack(hw); | ||
1238 | if (status != 0) | ||
1239 | goto fail; | ||
1240 | |||
1241 | status = ixgbe_clock_out_i2c_byte(hw, byte_offset); | ||
1242 | if (status != 0) | ||
1243 | goto fail; | ||
1244 | |||
1245 | status = ixgbe_get_i2c_ack(hw); | ||
1246 | if (status != 0) | ||
1247 | goto fail; | ||
1248 | |||
1249 | ixgbe_i2c_start(hw); | ||
1250 | |||
1251 | /* Device Address and read indication */ | ||
1252 | status = ixgbe_clock_out_i2c_byte(hw, (dev_addr | 0x1)); | ||
1253 | if (status != 0) | ||
1254 | goto fail; | ||
1255 | |||
1256 | status = ixgbe_get_i2c_ack(hw); | ||
1257 | if (status != 0) | ||
1258 | goto fail; | ||
1259 | |||
1260 | status = ixgbe_clock_in_i2c_byte(hw, data); | ||
1261 | if (status != 0) | ||
1262 | goto fail; | ||
1263 | |||
1264 | status = ixgbe_clock_out_i2c_bit(hw, nack); | ||
1265 | if (status != 0) | ||
1266 | goto fail; | ||
1267 | |||
1268 | ixgbe_i2c_stop(hw); | ||
1269 | break; | ||
1270 | |||
1271 | fail: | ||
1272 | hw->mac.ops.release_swfw_sync(hw, swfw_mask); | ||
1273 | msleep(100); | ||
1274 | ixgbe_i2c_bus_clear(hw); | ||
1275 | retry++; | ||
1276 | if (retry < max_retry) | ||
1277 | hw_dbg(hw, "I2C byte read error - Retrying.\n"); | ||
1278 | else | ||
1279 | hw_dbg(hw, "I2C byte read error.\n"); | ||
1280 | |||
1281 | } while (retry < max_retry); | ||
1282 | |||
1283 | hw->mac.ops.release_swfw_sync(hw, swfw_mask); | ||
1284 | |||
1285 | read_byte_out: | ||
1286 | return status; | ||
1287 | } | ||
1288 | |||
1289 | /** | ||
1290 | * ixgbe_write_i2c_byte_generic - Writes 8 bit word over I2C | ||
1291 | * @hw: pointer to hardware structure | ||
1292 | * @byte_offset: byte offset to write | ||
1293 | * @data: value to write | ||
1294 | * | ||
1295 | * Performs byte write operation to SFP module's EEPROM over I2C interface at | ||
1296 | * a specified device address. | ||
1297 | **/ | ||
1298 | s32 ixgbe_write_i2c_byte_generic(struct ixgbe_hw *hw, u8 byte_offset, | ||
1299 | u8 dev_addr, u8 data) | ||
1300 | { | ||
1301 | s32 status = 0; | ||
1302 | u32 max_retry = 1; | ||
1303 | u32 retry = 0; | ||
1304 | u16 swfw_mask = 0; | ||
1305 | |||
1306 | if (IXGBE_READ_REG(hw, IXGBE_STATUS) & IXGBE_STATUS_LAN_ID_1) | ||
1307 | swfw_mask = IXGBE_GSSR_PHY1_SM; | ||
1308 | else | ||
1309 | swfw_mask = IXGBE_GSSR_PHY0_SM; | ||
1310 | |||
1311 | if (hw->mac.ops.acquire_swfw_sync(hw, swfw_mask) != 0) { | ||
1312 | status = IXGBE_ERR_SWFW_SYNC; | ||
1313 | goto write_byte_out; | ||
1314 | } | ||
1315 | |||
1316 | do { | ||
1317 | ixgbe_i2c_start(hw); | ||
1318 | |||
1319 | status = ixgbe_clock_out_i2c_byte(hw, dev_addr); | ||
1320 | if (status != 0) | ||
1321 | goto fail; | ||
1322 | |||
1323 | status = ixgbe_get_i2c_ack(hw); | ||
1324 | if (status != 0) | ||
1325 | goto fail; | ||
1326 | |||
1327 | status = ixgbe_clock_out_i2c_byte(hw, byte_offset); | ||
1328 | if (status != 0) | ||
1329 | goto fail; | ||
1330 | |||
1331 | status = ixgbe_get_i2c_ack(hw); | ||
1332 | if (status != 0) | ||
1333 | goto fail; | ||
1334 | |||
1335 | status = ixgbe_clock_out_i2c_byte(hw, data); | ||
1336 | if (status != 0) | ||
1337 | goto fail; | ||
1338 | |||
1339 | status = ixgbe_get_i2c_ack(hw); | ||
1340 | if (status != 0) | ||
1341 | goto fail; | ||
1342 | |||
1343 | ixgbe_i2c_stop(hw); | ||
1344 | break; | ||
1345 | |||
1346 | fail: | ||
1347 | ixgbe_i2c_bus_clear(hw); | ||
1348 | retry++; | ||
1349 | if (retry < max_retry) | ||
1350 | hw_dbg(hw, "I2C byte write error - Retrying.\n"); | ||
1351 | else | ||
1352 | hw_dbg(hw, "I2C byte write error.\n"); | ||
1353 | } while (retry < max_retry); | ||
1354 | |||
1355 | hw->mac.ops.release_swfw_sync(hw, swfw_mask); | ||
1356 | |||
1357 | write_byte_out: | ||
1358 | return status; | ||
1359 | } | ||
1360 | |||
1361 | /** | ||
1362 | * ixgbe_i2c_start - Sets I2C start condition | ||
1363 | * @hw: pointer to hardware structure | ||
1364 | * | ||
1365 | * Sets I2C start condition (High -> Low on SDA while SCL is High) | ||
1366 | **/ | ||
1367 | static void ixgbe_i2c_start(struct ixgbe_hw *hw) | ||
1368 | { | ||
1369 | u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL); | ||
1370 | |||
1371 | /* Start condition must begin with data and clock high */ | ||
1372 | ixgbe_set_i2c_data(hw, &i2cctl, 1); | ||
1373 | ixgbe_raise_i2c_clk(hw, &i2cctl); | ||
1374 | |||
1375 | /* Setup time for start condition (4.7us) */ | ||
1376 | udelay(IXGBE_I2C_T_SU_STA); | ||
1377 | |||
1378 | ixgbe_set_i2c_data(hw, &i2cctl, 0); | ||
1379 | |||
1380 | /* Hold time for start condition (4us) */ | ||
1381 | udelay(IXGBE_I2C_T_HD_STA); | ||
1382 | |||
1383 | ixgbe_lower_i2c_clk(hw, &i2cctl); | ||
1384 | |||
1385 | /* Minimum low period of clock is 4.7 us */ | ||
1386 | udelay(IXGBE_I2C_T_LOW); | ||
1387 | |||
1388 | } | ||
1389 | |||
1390 | /** | ||
1391 | * ixgbe_i2c_stop - Sets I2C stop condition | ||
1392 | * @hw: pointer to hardware structure | ||
1393 | * | ||
1394 | * Sets I2C stop condition (Low -> High on SDA while SCL is High) | ||
1395 | **/ | ||
1396 | static void ixgbe_i2c_stop(struct ixgbe_hw *hw) | ||
1397 | { | ||
1398 | u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL); | ||
1399 | |||
1400 | /* Stop condition must begin with data low and clock high */ | ||
1401 | ixgbe_set_i2c_data(hw, &i2cctl, 0); | ||
1402 | ixgbe_raise_i2c_clk(hw, &i2cctl); | ||
1403 | |||
1404 | /* Setup time for stop condition (4us) */ | ||
1405 | udelay(IXGBE_I2C_T_SU_STO); | ||
1406 | |||
1407 | ixgbe_set_i2c_data(hw, &i2cctl, 1); | ||
1408 | |||
1409 | /* bus free time between stop and start (4.7us)*/ | ||
1410 | udelay(IXGBE_I2C_T_BUF); | ||
1411 | } | ||
1412 | |||
1413 | /** | ||
1414 | * ixgbe_clock_in_i2c_byte - Clocks in one byte via I2C | ||
1415 | * @hw: pointer to hardware structure | ||
1416 | * @data: data byte to clock in | ||
1417 | * | ||
1418 | * Clocks in one byte data via I2C data/clock | ||
1419 | **/ | ||
1420 | static s32 ixgbe_clock_in_i2c_byte(struct ixgbe_hw *hw, u8 *data) | ||
1421 | { | ||
1422 | s32 status = 0; | ||
1423 | s32 i; | ||
1424 | bool bit = 0; | ||
1425 | |||
1426 | for (i = 7; i >= 0; i--) { | ||
1427 | status = ixgbe_clock_in_i2c_bit(hw, &bit); | ||
1428 | *data |= bit << i; | ||
1429 | |||
1430 | if (status != 0) | ||
1431 | break; | ||
1432 | } | ||
1433 | |||
1434 | return status; | ||
1435 | } | ||
1436 | |||
1437 | /** | ||
1438 | * ixgbe_clock_out_i2c_byte - Clocks out one byte via I2C | ||
1439 | * @hw: pointer to hardware structure | ||
1440 | * @data: data byte clocked out | ||
1441 | * | ||
1442 | * Clocks out one byte data via I2C data/clock | ||
1443 | **/ | ||
1444 | static s32 ixgbe_clock_out_i2c_byte(struct ixgbe_hw *hw, u8 data) | ||
1445 | { | ||
1446 | s32 status = 0; | ||
1447 | s32 i; | ||
1448 | u32 i2cctl; | ||
1449 | bool bit = 0; | ||
1450 | |||
1451 | for (i = 7; i >= 0; i--) { | ||
1452 | bit = (data >> i) & 0x1; | ||
1453 | status = ixgbe_clock_out_i2c_bit(hw, bit); | ||
1454 | |||
1455 | if (status != 0) | ||
1456 | break; | ||
1457 | } | ||
1458 | |||
1459 | /* Release SDA line (set high) */ | ||
1460 | i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL); | ||
1461 | i2cctl |= IXGBE_I2C_DATA_OUT; | ||
1462 | IXGBE_WRITE_REG(hw, IXGBE_I2CCTL, i2cctl); | ||
1463 | |||
1464 | return status; | ||
1465 | } | ||
1466 | |||
1467 | /** | ||
1468 | * ixgbe_get_i2c_ack - Polls for I2C ACK | ||
1469 | * @hw: pointer to hardware structure | ||
1470 | * | ||
1471 | * Clocks in/out one bit via I2C data/clock | ||
1472 | **/ | ||
1473 | static s32 ixgbe_get_i2c_ack(struct ixgbe_hw *hw) | ||
1474 | { | ||
1475 | s32 status; | ||
1476 | u32 i = 0; | ||
1477 | u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL); | ||
1478 | u32 timeout = 10; | ||
1479 | bool ack = 1; | ||
1480 | |||
1481 | status = ixgbe_raise_i2c_clk(hw, &i2cctl); | ||
1482 | |||
1483 | if (status != 0) | ||
1484 | goto out; | ||
1485 | |||
1486 | /* Minimum high period of clock is 4us */ | ||
1487 | udelay(IXGBE_I2C_T_HIGH); | ||
1488 | |||
1489 | /* Poll for ACK. Note that ACK in I2C spec is | ||
1490 | * transition from 1 to 0 */ | ||
1491 | for (i = 0; i < timeout; i++) { | ||
1492 | i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL); | ||
1493 | ack = ixgbe_get_i2c_data(&i2cctl); | ||
1494 | |||
1495 | udelay(1); | ||
1496 | if (ack == 0) | ||
1497 | break; | ||
1498 | } | ||
1499 | |||
1500 | if (ack == 1) { | ||
1501 | hw_dbg(hw, "I2C ack was not received.\n"); | ||
1502 | status = IXGBE_ERR_I2C; | ||
1503 | } | ||
1504 | |||
1505 | ixgbe_lower_i2c_clk(hw, &i2cctl); | ||
1506 | |||
1507 | /* Minimum low period of clock is 4.7 us */ | ||
1508 | udelay(IXGBE_I2C_T_LOW); | ||
1509 | |||
1510 | out: | ||
1511 | return status; | ||
1512 | } | ||
1513 | |||
1514 | /** | ||
1515 | * ixgbe_clock_in_i2c_bit - Clocks in one bit via I2C data/clock | ||
1516 | * @hw: pointer to hardware structure | ||
1517 | * @data: read data value | ||
1518 | * | ||
1519 | * Clocks in one bit via I2C data/clock | ||
1520 | **/ | ||
1521 | static s32 ixgbe_clock_in_i2c_bit(struct ixgbe_hw *hw, bool *data) | ||
1522 | { | ||
1523 | s32 status; | ||
1524 | u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL); | ||
1525 | |||
1526 | status = ixgbe_raise_i2c_clk(hw, &i2cctl); | ||
1527 | |||
1528 | /* Minimum high period of clock is 4us */ | ||
1529 | udelay(IXGBE_I2C_T_HIGH); | ||
1530 | |||
1531 | i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL); | ||
1532 | *data = ixgbe_get_i2c_data(&i2cctl); | ||
1533 | |||
1534 | ixgbe_lower_i2c_clk(hw, &i2cctl); | ||
1535 | |||
1536 | /* Minimum low period of clock is 4.7 us */ | ||
1537 | udelay(IXGBE_I2C_T_LOW); | ||
1538 | |||
1539 | return status; | ||
1540 | } | ||
1541 | |||
1542 | /** | ||
1543 | * ixgbe_clock_out_i2c_bit - Clocks in/out one bit via I2C data/clock | ||
1544 | * @hw: pointer to hardware structure | ||
1545 | * @data: data value to write | ||
1546 | * | ||
1547 | * Clocks out one bit via I2C data/clock | ||
1548 | **/ | ||
1549 | static s32 ixgbe_clock_out_i2c_bit(struct ixgbe_hw *hw, bool data) | ||
1550 | { | ||
1551 | s32 status; | ||
1552 | u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL); | ||
1553 | |||
1554 | status = ixgbe_set_i2c_data(hw, &i2cctl, data); | ||
1555 | if (status == 0) { | ||
1556 | status = ixgbe_raise_i2c_clk(hw, &i2cctl); | ||
1557 | |||
1558 | /* Minimum high period of clock is 4us */ | ||
1559 | udelay(IXGBE_I2C_T_HIGH); | ||
1560 | |||
1561 | ixgbe_lower_i2c_clk(hw, &i2cctl); | ||
1562 | |||
1563 | /* Minimum low period of clock is 4.7 us. | ||
1564 | * This also takes care of the data hold time. | ||
1565 | */ | ||
1566 | udelay(IXGBE_I2C_T_LOW); | ||
1567 | } else { | ||
1568 | status = IXGBE_ERR_I2C; | ||
1569 | hw_dbg(hw, "I2C data was not set to %X\n", data); | ||
1570 | } | ||
1571 | |||
1572 | return status; | ||
1573 | } | ||
1574 | /** | ||
1575 | * ixgbe_raise_i2c_clk - Raises the I2C SCL clock | ||
1576 | * @hw: pointer to hardware structure | ||
1577 | * @i2cctl: Current value of I2CCTL register | ||
1578 | * | ||
1579 | * Raises the I2C clock line '0'->'1' | ||
1580 | **/ | ||
1581 | static s32 ixgbe_raise_i2c_clk(struct ixgbe_hw *hw, u32 *i2cctl) | ||
1582 | { | ||
1583 | s32 status = 0; | ||
1584 | |||
1585 | *i2cctl |= IXGBE_I2C_CLK_OUT; | ||
1586 | |||
1587 | IXGBE_WRITE_REG(hw, IXGBE_I2CCTL, *i2cctl); | ||
1588 | IXGBE_WRITE_FLUSH(hw); | ||
1589 | |||
1590 | /* SCL rise time (1000ns) */ | ||
1591 | udelay(IXGBE_I2C_T_RISE); | ||
1592 | |||
1593 | return status; | ||
1594 | } | ||
1595 | |||
1596 | /** | ||
1597 | * ixgbe_lower_i2c_clk - Lowers the I2C SCL clock | ||
1598 | * @hw: pointer to hardware structure | ||
1599 | * @i2cctl: Current value of I2CCTL register | ||
1600 | * | ||
1601 | * Lowers the I2C clock line '1'->'0' | ||
1602 | **/ | ||
1603 | static void ixgbe_lower_i2c_clk(struct ixgbe_hw *hw, u32 *i2cctl) | ||
1604 | { | ||
1605 | |||
1606 | *i2cctl &= ~IXGBE_I2C_CLK_OUT; | ||
1607 | |||
1608 | IXGBE_WRITE_REG(hw, IXGBE_I2CCTL, *i2cctl); | ||
1609 | IXGBE_WRITE_FLUSH(hw); | ||
1610 | |||
1611 | /* SCL fall time (300ns) */ | ||
1612 | udelay(IXGBE_I2C_T_FALL); | ||
1613 | } | ||
1614 | |||
1615 | /** | ||
1616 | * ixgbe_set_i2c_data - Sets the I2C data bit | ||
1617 | * @hw: pointer to hardware structure | ||
1618 | * @i2cctl: Current value of I2CCTL register | ||
1619 | * @data: I2C data value (0 or 1) to set | ||
1620 | * | ||
1621 | * Sets the I2C data bit | ||
1622 | **/ | ||
1623 | static s32 ixgbe_set_i2c_data(struct ixgbe_hw *hw, u32 *i2cctl, bool data) | ||
1624 | { | ||
1625 | s32 status = 0; | ||
1626 | |||
1627 | if (data) | ||
1628 | *i2cctl |= IXGBE_I2C_DATA_OUT; | ||
1629 | else | ||
1630 | *i2cctl &= ~IXGBE_I2C_DATA_OUT; | ||
1631 | |||
1632 | IXGBE_WRITE_REG(hw, IXGBE_I2CCTL, *i2cctl); | ||
1633 | IXGBE_WRITE_FLUSH(hw); | ||
1634 | |||
1635 | /* Data rise/fall (1000ns/300ns) and set-up time (250ns) */ | ||
1636 | udelay(IXGBE_I2C_T_RISE + IXGBE_I2C_T_FALL + IXGBE_I2C_T_SU_DATA); | ||
1637 | |||
1638 | /* Verify data was set correctly */ | ||
1639 | *i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL); | ||
1640 | if (data != ixgbe_get_i2c_data(i2cctl)) { | ||
1641 | status = IXGBE_ERR_I2C; | ||
1642 | hw_dbg(hw, "Error - I2C data was not set to %X.\n", data); | ||
1643 | } | ||
1644 | |||
1645 | return status; | ||
1646 | } | ||
1647 | |||
1648 | /** | ||
1649 | * ixgbe_get_i2c_data - Reads the I2C SDA data bit | ||
1650 | * @hw: pointer to hardware structure | ||
1651 | * @i2cctl: Current value of I2CCTL register | ||
1652 | * | ||
1653 | * Returns the I2C data bit value | ||
1654 | **/ | ||
1655 | static bool ixgbe_get_i2c_data(u32 *i2cctl) | ||
1656 | { | ||
1657 | bool data; | ||
1658 | |||
1659 | if (*i2cctl & IXGBE_I2C_DATA_IN) | ||
1660 | data = 1; | ||
1661 | else | ||
1662 | data = 0; | ||
1663 | |||
1664 | return data; | ||
1665 | } | ||
1666 | |||
1667 | /** | ||
1668 | * ixgbe_i2c_bus_clear - Clears the I2C bus | ||
1669 | * @hw: pointer to hardware structure | ||
1670 | * | ||
1671 | * Clears the I2C bus by sending nine clock pulses. | ||
1672 | * Used when data line is stuck low. | ||
1673 | **/ | ||
1674 | static void ixgbe_i2c_bus_clear(struct ixgbe_hw *hw) | ||
1675 | { | ||
1676 | u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL); | ||
1677 | u32 i; | ||
1678 | |||
1679 | ixgbe_i2c_start(hw); | ||
1680 | |||
1681 | ixgbe_set_i2c_data(hw, &i2cctl, 1); | ||
1682 | |||
1683 | for (i = 0; i < 9; i++) { | ||
1684 | ixgbe_raise_i2c_clk(hw, &i2cctl); | ||
1685 | |||
1686 | /* Min high period of clock is 4us */ | ||
1687 | udelay(IXGBE_I2C_T_HIGH); | ||
1688 | |||
1689 | ixgbe_lower_i2c_clk(hw, &i2cctl); | ||
1690 | |||
1691 | /* Min low period of clock is 4.7us*/ | ||
1692 | udelay(IXGBE_I2C_T_LOW); | ||
1693 | } | ||
1694 | |||
1695 | ixgbe_i2c_start(hw); | ||
1696 | |||
1697 | /* Put the i2c bus back to default state */ | ||
1698 | ixgbe_i2c_stop(hw); | ||
1699 | } | ||
1700 | |||
1701 | /** | ||
1702 | * ixgbe_tn_check_overtemp - Checks if an overtemp occurred. | ||
1703 | * @hw: pointer to hardware structure | ||
1704 | * | ||
1705 | * Checks if the LASI temp alarm status was triggered due to overtemp | ||
1706 | **/ | ||
1707 | s32 ixgbe_tn_check_overtemp(struct ixgbe_hw *hw) | ||
1708 | { | ||
1709 | s32 status = 0; | ||
1710 | u16 phy_data = 0; | ||
1711 | |||
1712 | if (hw->device_id != IXGBE_DEV_ID_82599_T3_LOM) | ||
1713 | goto out; | ||
1714 | |||
1715 | /* Check that the LASI temp alarm status was triggered */ | ||
1716 | hw->phy.ops.read_reg(hw, IXGBE_TN_LASI_STATUS_REG, | ||
1717 | MDIO_MMD_PMAPMD, &phy_data); | ||
1718 | |||
1719 | if (!(phy_data & IXGBE_TN_LASI_STATUS_TEMP_ALARM)) | ||
1720 | goto out; | ||
1721 | |||
1722 | status = IXGBE_ERR_OVERTEMP; | ||
1723 | out: | ||
1724 | return status; | ||
1725 | } | ||
diff --git a/drivers/net/ixgbe/ixgbe_phy.h b/drivers/net/ixgbe/ixgbe_phy.h new file mode 100644 index 00000000000..197bdd13106 --- /dev/null +++ b/drivers/net/ixgbe/ixgbe_phy.h | |||
@@ -0,0 +1,131 @@ | |||
1 | /******************************************************************************* | ||
2 | |||
3 | Intel 10 Gigabit PCI Express Linux driver | ||
4 | Copyright(c) 1999 - 2011 Intel Corporation. | ||
5 | |||
6 | This program is free software; you can redistribute it and/or modify it | ||
7 | under the terms and conditions of the GNU General Public License, | ||
8 | version 2, as published by the Free Software Foundation. | ||
9 | |||
10 | This program is distributed in the hope it will be useful, but WITHOUT | ||
11 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
12 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
13 | more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License along with | ||
16 | this program; if not, write to the Free Software Foundation, Inc., | ||
17 | 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. | ||
18 | |||
19 | The full GNU General Public License is included in this distribution in | ||
20 | the file called "COPYING". | ||
21 | |||
22 | Contact Information: | ||
23 | e1000-devel Mailing List <e1000-devel@lists.sourceforge.net> | ||
24 | Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 | ||
25 | |||
26 | *******************************************************************************/ | ||
27 | |||
28 | #ifndef _IXGBE_PHY_H_ | ||
29 | #define _IXGBE_PHY_H_ | ||
30 | |||
31 | #include "ixgbe_type.h" | ||
32 | #define IXGBE_I2C_EEPROM_DEV_ADDR 0xA0 | ||
33 | |||
34 | /* EEPROM byte offsets */ | ||
35 | #define IXGBE_SFF_IDENTIFIER 0x0 | ||
36 | #define IXGBE_SFF_IDENTIFIER_SFP 0x3 | ||
37 | #define IXGBE_SFF_VENDOR_OUI_BYTE0 0x25 | ||
38 | #define IXGBE_SFF_VENDOR_OUI_BYTE1 0x26 | ||
39 | #define IXGBE_SFF_VENDOR_OUI_BYTE2 0x27 | ||
40 | #define IXGBE_SFF_1GBE_COMP_CODES 0x6 | ||
41 | #define IXGBE_SFF_10GBE_COMP_CODES 0x3 | ||
42 | #define IXGBE_SFF_CABLE_TECHNOLOGY 0x8 | ||
43 | #define IXGBE_SFF_CABLE_SPEC_COMP 0x3C | ||
44 | |||
45 | /* Bitmasks */ | ||
46 | #define IXGBE_SFF_DA_PASSIVE_CABLE 0x4 | ||
47 | #define IXGBE_SFF_DA_ACTIVE_CABLE 0x8 | ||
48 | #define IXGBE_SFF_DA_SPEC_ACTIVE_LIMITING 0x4 | ||
49 | #define IXGBE_SFF_1GBASESX_CAPABLE 0x1 | ||
50 | #define IXGBE_SFF_1GBASELX_CAPABLE 0x2 | ||
51 | #define IXGBE_SFF_1GBASET_CAPABLE 0x8 | ||
52 | #define IXGBE_SFF_10GBASESR_CAPABLE 0x10 | ||
53 | #define IXGBE_SFF_10GBASELR_CAPABLE 0x20 | ||
54 | #define IXGBE_I2C_EEPROM_READ_MASK 0x100 | ||
55 | #define IXGBE_I2C_EEPROM_STATUS_MASK 0x3 | ||
56 | #define IXGBE_I2C_EEPROM_STATUS_NO_OPERATION 0x0 | ||
57 | #define IXGBE_I2C_EEPROM_STATUS_PASS 0x1 | ||
58 | #define IXGBE_I2C_EEPROM_STATUS_FAIL 0x2 | ||
59 | #define IXGBE_I2C_EEPROM_STATUS_IN_PROGRESS 0x3 | ||
60 | |||
61 | /* Flow control defines */ | ||
62 | #define IXGBE_TAF_SYM_PAUSE 0x400 | ||
63 | #define IXGBE_TAF_ASM_PAUSE 0x800 | ||
64 | |||
65 | /* Bit-shift macros */ | ||
66 | #define IXGBE_SFF_VENDOR_OUI_BYTE0_SHIFT 24 | ||
67 | #define IXGBE_SFF_VENDOR_OUI_BYTE1_SHIFT 16 | ||
68 | #define IXGBE_SFF_VENDOR_OUI_BYTE2_SHIFT 8 | ||
69 | |||
70 | /* Vendor OUIs: format of OUI is 0x[byte0][byte1][byte2][00] */ | ||
71 | #define IXGBE_SFF_VENDOR_OUI_TYCO 0x00407600 | ||
72 | #define IXGBE_SFF_VENDOR_OUI_FTL 0x00906500 | ||
73 | #define IXGBE_SFF_VENDOR_OUI_AVAGO 0x00176A00 | ||
74 | #define IXGBE_SFF_VENDOR_OUI_INTEL 0x001B2100 | ||
75 | |||
76 | /* I2C SDA and SCL timing parameters for standard mode */ | ||
77 | #define IXGBE_I2C_T_HD_STA 4 | ||
78 | #define IXGBE_I2C_T_LOW 5 | ||
79 | #define IXGBE_I2C_T_HIGH 4 | ||
80 | #define IXGBE_I2C_T_SU_STA 5 | ||
81 | #define IXGBE_I2C_T_HD_DATA 5 | ||
82 | #define IXGBE_I2C_T_SU_DATA 1 | ||
83 | #define IXGBE_I2C_T_RISE 1 | ||
84 | #define IXGBE_I2C_T_FALL 1 | ||
85 | #define IXGBE_I2C_T_SU_STO 4 | ||
86 | #define IXGBE_I2C_T_BUF 5 | ||
87 | |||
88 | #define IXGBE_TN_LASI_STATUS_REG 0x9005 | ||
89 | #define IXGBE_TN_LASI_STATUS_TEMP_ALARM 0x0008 | ||
90 | |||
91 | s32 ixgbe_init_phy_ops_generic(struct ixgbe_hw *hw); | ||
92 | s32 ixgbe_identify_phy_generic(struct ixgbe_hw *hw); | ||
93 | s32 ixgbe_reset_phy_generic(struct ixgbe_hw *hw); | ||
94 | s32 ixgbe_read_phy_reg_generic(struct ixgbe_hw *hw, u32 reg_addr, | ||
95 | u32 device_type, u16 *phy_data); | ||
96 | s32 ixgbe_write_phy_reg_generic(struct ixgbe_hw *hw, u32 reg_addr, | ||
97 | u32 device_type, u16 phy_data); | ||
98 | s32 ixgbe_setup_phy_link_generic(struct ixgbe_hw *hw); | ||
99 | s32 ixgbe_setup_phy_link_speed_generic(struct ixgbe_hw *hw, | ||
100 | ixgbe_link_speed speed, | ||
101 | bool autoneg, | ||
102 | bool autoneg_wait_to_complete); | ||
103 | s32 ixgbe_get_copper_link_capabilities_generic(struct ixgbe_hw *hw, | ||
104 | ixgbe_link_speed *speed, | ||
105 | bool *autoneg); | ||
106 | |||
107 | /* PHY specific */ | ||
108 | s32 ixgbe_check_phy_link_tnx(struct ixgbe_hw *hw, | ||
109 | ixgbe_link_speed *speed, | ||
110 | bool *link_up); | ||
111 | s32 ixgbe_setup_phy_link_tnx(struct ixgbe_hw *hw); | ||
112 | s32 ixgbe_get_phy_firmware_version_tnx(struct ixgbe_hw *hw, | ||
113 | u16 *firmware_version); | ||
114 | s32 ixgbe_get_phy_firmware_version_generic(struct ixgbe_hw *hw, | ||
115 | u16 *firmware_version); | ||
116 | |||
117 | s32 ixgbe_reset_phy_nl(struct ixgbe_hw *hw); | ||
118 | s32 ixgbe_identify_sfp_module_generic(struct ixgbe_hw *hw); | ||
119 | s32 ixgbe_get_sfp_init_sequence_offsets(struct ixgbe_hw *hw, | ||
120 | u16 *list_offset, | ||
121 | u16 *data_offset); | ||
122 | s32 ixgbe_tn_check_overtemp(struct ixgbe_hw *hw); | ||
123 | s32 ixgbe_read_i2c_byte_generic(struct ixgbe_hw *hw, u8 byte_offset, | ||
124 | u8 dev_addr, u8 *data); | ||
125 | s32 ixgbe_write_i2c_byte_generic(struct ixgbe_hw *hw, u8 byte_offset, | ||
126 | u8 dev_addr, u8 data); | ||
127 | s32 ixgbe_read_i2c_eeprom_generic(struct ixgbe_hw *hw, u8 byte_offset, | ||
128 | u8 *eeprom_data); | ||
129 | s32 ixgbe_write_i2c_eeprom_generic(struct ixgbe_hw *hw, u8 byte_offset, | ||
130 | u8 eeprom_data); | ||
131 | #endif /* _IXGBE_PHY_H_ */ | ||
diff --git a/drivers/net/ixgbe/ixgbe_sriov.c b/drivers/net/ixgbe/ixgbe_sriov.c new file mode 100644 index 00000000000..d99d01e2132 --- /dev/null +++ b/drivers/net/ixgbe/ixgbe_sriov.c | |||
@@ -0,0 +1,687 @@ | |||
1 | /******************************************************************************* | ||
2 | |||
3 | Intel 10 Gigabit PCI Express Linux driver | ||
4 | Copyright(c) 1999 - 2011 Intel Corporation. | ||
5 | |||
6 | This program is free software; you can redistribute it and/or modify it | ||
7 | under the terms and conditions of the GNU General Public License, | ||
8 | version 2, as published by the Free Software Foundation. | ||
9 | |||
10 | This program is distributed in the hope it will be useful, but WITHOUT | ||
11 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
12 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
13 | more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License along with | ||
16 | this program; if not, write to the Free Software Foundation, Inc., | ||
17 | 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. | ||
18 | |||
19 | The full GNU General Public License is included in this distribution in | ||
20 | the file called "COPYING". | ||
21 | |||
22 | Contact Information: | ||
23 | e1000-devel Mailing List <e1000-devel@lists.sourceforge.net> | ||
24 | Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 | ||
25 | |||
26 | *******************************************************************************/ | ||
27 | |||
28 | #include <linux/types.h> | ||
29 | #include <linux/module.h> | ||
30 | #include <linux/pci.h> | ||
31 | #include <linux/netdevice.h> | ||
32 | #include <linux/vmalloc.h> | ||
33 | #include <linux/string.h> | ||
34 | #include <linux/in.h> | ||
35 | #include <linux/ip.h> | ||
36 | #include <linux/tcp.h> | ||
37 | #include <linux/ipv6.h> | ||
38 | #ifdef NETIF_F_HW_VLAN_TX | ||
39 | #include <linux/if_vlan.h> | ||
40 | #endif | ||
41 | |||
42 | #include "ixgbe.h" | ||
43 | |||
44 | #include "ixgbe_sriov.h" | ||
45 | |||
46 | static int ixgbe_set_vf_multicasts(struct ixgbe_adapter *adapter, | ||
47 | int entries, u16 *hash_list, u32 vf) | ||
48 | { | ||
49 | struct vf_data_storage *vfinfo = &adapter->vfinfo[vf]; | ||
50 | struct ixgbe_hw *hw = &adapter->hw; | ||
51 | int i; | ||
52 | u32 vector_bit; | ||
53 | u32 vector_reg; | ||
54 | u32 mta_reg; | ||
55 | |||
56 | /* only so many hash values supported */ | ||
57 | entries = min(entries, IXGBE_MAX_VF_MC_ENTRIES); | ||
58 | |||
59 | /* | ||
60 | * salt away the number of multi cast addresses assigned | ||
61 | * to this VF for later use to restore when the PF multi cast | ||
62 | * list changes | ||
63 | */ | ||
64 | vfinfo->num_vf_mc_hashes = entries; | ||
65 | |||
66 | /* | ||
67 | * VFs are limited to using the MTA hash table for their multicast | ||
68 | * addresses | ||
69 | */ | ||
70 | for (i = 0; i < entries; i++) { | ||
71 | vfinfo->vf_mc_hashes[i] = hash_list[i]; | ||
72 | } | ||
73 | |||
74 | for (i = 0; i < vfinfo->num_vf_mc_hashes; i++) { | ||
75 | vector_reg = (vfinfo->vf_mc_hashes[i] >> 5) & 0x7F; | ||
76 | vector_bit = vfinfo->vf_mc_hashes[i] & 0x1F; | ||
77 | mta_reg = IXGBE_READ_REG(hw, IXGBE_MTA(vector_reg)); | ||
78 | mta_reg |= (1 << vector_bit); | ||
79 | IXGBE_WRITE_REG(hw, IXGBE_MTA(vector_reg), mta_reg); | ||
80 | } | ||
81 | |||
82 | return 0; | ||
83 | } | ||
84 | |||
85 | static void ixgbe_restore_vf_macvlans(struct ixgbe_adapter *adapter) | ||
86 | { | ||
87 | struct ixgbe_hw *hw = &adapter->hw; | ||
88 | struct list_head *pos; | ||
89 | struct vf_macvlans *entry; | ||
90 | |||
91 | list_for_each(pos, &adapter->vf_mvs.l) { | ||
92 | entry = list_entry(pos, struct vf_macvlans, l); | ||
93 | if (entry->free == false) | ||
94 | hw->mac.ops.set_rar(hw, entry->rar_entry, | ||
95 | entry->vf_macvlan, | ||
96 | entry->vf, IXGBE_RAH_AV); | ||
97 | } | ||
98 | } | ||
99 | |||
100 | void ixgbe_restore_vf_multicasts(struct ixgbe_adapter *adapter) | ||
101 | { | ||
102 | struct ixgbe_hw *hw = &adapter->hw; | ||
103 | struct vf_data_storage *vfinfo; | ||
104 | int i, j; | ||
105 | u32 vector_bit; | ||
106 | u32 vector_reg; | ||
107 | u32 mta_reg; | ||
108 | |||
109 | for (i = 0; i < adapter->num_vfs; i++) { | ||
110 | vfinfo = &adapter->vfinfo[i]; | ||
111 | for (j = 0; j < vfinfo->num_vf_mc_hashes; j++) { | ||
112 | hw->addr_ctrl.mta_in_use++; | ||
113 | vector_reg = (vfinfo->vf_mc_hashes[j] >> 5) & 0x7F; | ||
114 | vector_bit = vfinfo->vf_mc_hashes[j] & 0x1F; | ||
115 | mta_reg = IXGBE_READ_REG(hw, IXGBE_MTA(vector_reg)); | ||
116 | mta_reg |= (1 << vector_bit); | ||
117 | IXGBE_WRITE_REG(hw, IXGBE_MTA(vector_reg), mta_reg); | ||
118 | } | ||
119 | } | ||
120 | |||
121 | /* Restore any VF macvlans */ | ||
122 | ixgbe_restore_vf_macvlans(adapter); | ||
123 | } | ||
124 | |||
125 | static int ixgbe_set_vf_vlan(struct ixgbe_adapter *adapter, int add, int vid, | ||
126 | u32 vf) | ||
127 | { | ||
128 | return adapter->hw.mac.ops.set_vfta(&adapter->hw, vid, vf, (bool)add); | ||
129 | } | ||
130 | |||
131 | static void ixgbe_set_vf_lpe(struct ixgbe_adapter *adapter, u32 *msgbuf) | ||
132 | { | ||
133 | struct ixgbe_hw *hw = &adapter->hw; | ||
134 | int new_mtu = msgbuf[1]; | ||
135 | u32 max_frs; | ||
136 | int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN; | ||
137 | |||
138 | /* Only X540 supports jumbo frames in IOV mode */ | ||
139 | if (adapter->hw.mac.type != ixgbe_mac_X540) | ||
140 | return; | ||
141 | |||
142 | /* MTU < 68 is an error and causes problems on some kernels */ | ||
143 | if ((new_mtu < 68) || (max_frame > IXGBE_MAX_JUMBO_FRAME_SIZE)) { | ||
144 | e_err(drv, "VF mtu %d out of range\n", new_mtu); | ||
145 | return; | ||
146 | } | ||
147 | |||
148 | max_frs = (IXGBE_READ_REG(hw, IXGBE_MAXFRS) & | ||
149 | IXGBE_MHADD_MFS_MASK) >> IXGBE_MHADD_MFS_SHIFT; | ||
150 | if (max_frs < new_mtu) { | ||
151 | max_frs = new_mtu << IXGBE_MHADD_MFS_SHIFT; | ||
152 | IXGBE_WRITE_REG(hw, IXGBE_MAXFRS, max_frs); | ||
153 | } | ||
154 | |||
155 | e_info(hw, "VF requests change max MTU to %d\n", new_mtu); | ||
156 | } | ||
157 | |||
158 | static void ixgbe_set_vmolr(struct ixgbe_hw *hw, u32 vf, bool aupe) | ||
159 | { | ||
160 | u32 vmolr = IXGBE_READ_REG(hw, IXGBE_VMOLR(vf)); | ||
161 | vmolr |= (IXGBE_VMOLR_ROMPE | | ||
162 | IXGBE_VMOLR_BAM); | ||
163 | if (aupe) | ||
164 | vmolr |= IXGBE_VMOLR_AUPE; | ||
165 | else | ||
166 | vmolr &= ~IXGBE_VMOLR_AUPE; | ||
167 | IXGBE_WRITE_REG(hw, IXGBE_VMOLR(vf), vmolr); | ||
168 | } | ||
169 | |||
170 | static void ixgbe_set_vmvir(struct ixgbe_adapter *adapter, u32 vid, u32 vf) | ||
171 | { | ||
172 | struct ixgbe_hw *hw = &adapter->hw; | ||
173 | |||
174 | if (vid) | ||
175 | IXGBE_WRITE_REG(hw, IXGBE_VMVIR(vf), | ||
176 | (vid | IXGBE_VMVIR_VLANA_DEFAULT)); | ||
177 | else | ||
178 | IXGBE_WRITE_REG(hw, IXGBE_VMVIR(vf), 0); | ||
179 | } | ||
180 | |||
181 | static inline void ixgbe_vf_reset_event(struct ixgbe_adapter *adapter, u32 vf) | ||
182 | { | ||
183 | struct ixgbe_hw *hw = &adapter->hw; | ||
184 | int rar_entry = hw->mac.num_rar_entries - (vf + 1); | ||
185 | |||
186 | /* reset offloads to defaults */ | ||
187 | if (adapter->vfinfo[vf].pf_vlan) { | ||
188 | ixgbe_set_vf_vlan(adapter, true, | ||
189 | adapter->vfinfo[vf].pf_vlan, vf); | ||
190 | ixgbe_set_vmvir(adapter, | ||
191 | (adapter->vfinfo[vf].pf_vlan | | ||
192 | (adapter->vfinfo[vf].pf_qos << | ||
193 | VLAN_PRIO_SHIFT)), vf); | ||
194 | ixgbe_set_vmolr(hw, vf, false); | ||
195 | } else { | ||
196 | ixgbe_set_vmvir(adapter, 0, vf); | ||
197 | ixgbe_set_vmolr(hw, vf, true); | ||
198 | } | ||
199 | |||
200 | /* reset multicast table array for vf */ | ||
201 | adapter->vfinfo[vf].num_vf_mc_hashes = 0; | ||
202 | |||
203 | /* Flush and reset the mta with the new values */ | ||
204 | ixgbe_set_rx_mode(adapter->netdev); | ||
205 | |||
206 | hw->mac.ops.clear_rar(hw, rar_entry); | ||
207 | } | ||
208 | |||
209 | static int ixgbe_set_vf_mac(struct ixgbe_adapter *adapter, | ||
210 | int vf, unsigned char *mac_addr) | ||
211 | { | ||
212 | struct ixgbe_hw *hw = &adapter->hw; | ||
213 | int rar_entry = hw->mac.num_rar_entries - (vf + 1); | ||
214 | |||
215 | memcpy(adapter->vfinfo[vf].vf_mac_addresses, mac_addr, 6); | ||
216 | hw->mac.ops.set_rar(hw, rar_entry, mac_addr, vf, IXGBE_RAH_AV); | ||
217 | |||
218 | return 0; | ||
219 | } | ||
220 | |||
221 | static int ixgbe_set_vf_macvlan(struct ixgbe_adapter *adapter, | ||
222 | int vf, int index, unsigned char *mac_addr) | ||
223 | { | ||
224 | struct ixgbe_hw *hw = &adapter->hw; | ||
225 | struct list_head *pos; | ||
226 | struct vf_macvlans *entry; | ||
227 | |||
228 | if (index <= 1) { | ||
229 | list_for_each(pos, &adapter->vf_mvs.l) { | ||
230 | entry = list_entry(pos, struct vf_macvlans, l); | ||
231 | if (entry->vf == vf) { | ||
232 | entry->vf = -1; | ||
233 | entry->free = true; | ||
234 | entry->is_macvlan = false; | ||
235 | hw->mac.ops.clear_rar(hw, entry->rar_entry); | ||
236 | } | ||
237 | } | ||
238 | } | ||
239 | |||
240 | /* | ||
241 | * If index was zero then we were asked to clear the uc list | ||
242 | * for the VF. We're done. | ||
243 | */ | ||
244 | if (!index) | ||
245 | return 0; | ||
246 | |||
247 | entry = NULL; | ||
248 | |||
249 | list_for_each(pos, &adapter->vf_mvs.l) { | ||
250 | entry = list_entry(pos, struct vf_macvlans, l); | ||
251 | if (entry->free) | ||
252 | break; | ||
253 | } | ||
254 | |||
255 | /* | ||
256 | * If we traversed the entire list and didn't find a free entry | ||
257 | * then we're out of space on the RAR table. Also entry may | ||
258 | * be NULL because the original memory allocation for the list | ||
259 | * failed, which is not fatal but does mean we can't support | ||
260 | * VF requests for MACVLAN because we couldn't allocate | ||
261 | * memory for the list management required. | ||
262 | */ | ||
263 | if (!entry || !entry->free) | ||
264 | return -ENOSPC; | ||
265 | |||
266 | entry->free = false; | ||
267 | entry->is_macvlan = true; | ||
268 | entry->vf = vf; | ||
269 | memcpy(entry->vf_macvlan, mac_addr, ETH_ALEN); | ||
270 | |||
271 | hw->mac.ops.set_rar(hw, entry->rar_entry, mac_addr, vf, IXGBE_RAH_AV); | ||
272 | |||
273 | return 0; | ||
274 | } | ||
275 | |||
276 | int ixgbe_vf_configuration(struct pci_dev *pdev, unsigned int event_mask) | ||
277 | { | ||
278 | unsigned char vf_mac_addr[6]; | ||
279 | struct ixgbe_adapter *adapter = pci_get_drvdata(pdev); | ||
280 | unsigned int vfn = (event_mask & 0x3f); | ||
281 | |||
282 | bool enable = ((event_mask & 0x10000000U) != 0); | ||
283 | |||
284 | if (enable) { | ||
285 | random_ether_addr(vf_mac_addr); | ||
286 | e_info(probe, "IOV: VF %d is enabled MAC %pM\n", | ||
287 | vfn, vf_mac_addr); | ||
288 | /* | ||
289 | * Store away the VF "permananet" MAC address, it will ask | ||
290 | * for it later. | ||
291 | */ | ||
292 | memcpy(adapter->vfinfo[vfn].vf_mac_addresses, vf_mac_addr, 6); | ||
293 | } | ||
294 | |||
295 | return 0; | ||
296 | } | ||
297 | |||
298 | static inline void ixgbe_vf_reset_msg(struct ixgbe_adapter *adapter, u32 vf) | ||
299 | { | ||
300 | struct ixgbe_hw *hw = &adapter->hw; | ||
301 | u32 reg; | ||
302 | u32 reg_offset, vf_shift; | ||
303 | |||
304 | vf_shift = vf % 32; | ||
305 | reg_offset = vf / 32; | ||
306 | |||
307 | /* enable transmit and receive for vf */ | ||
308 | reg = IXGBE_READ_REG(hw, IXGBE_VFTE(reg_offset)); | ||
309 | reg |= (reg | (1 << vf_shift)); | ||
310 | IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset), reg); | ||
311 | |||
312 | reg = IXGBE_READ_REG(hw, IXGBE_VFRE(reg_offset)); | ||
313 | reg |= (reg | (1 << vf_shift)); | ||
314 | IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset), reg); | ||
315 | |||
316 | /* Enable counting of spoofed packets in the SSVPC register */ | ||
317 | reg = IXGBE_READ_REG(hw, IXGBE_VMECM(reg_offset)); | ||
318 | reg |= (1 << vf_shift); | ||
319 | IXGBE_WRITE_REG(hw, IXGBE_VMECM(reg_offset), reg); | ||
320 | |||
321 | ixgbe_vf_reset_event(adapter, vf); | ||
322 | } | ||
323 | |||
324 | static int ixgbe_rcv_msg_from_vf(struct ixgbe_adapter *adapter, u32 vf) | ||
325 | { | ||
326 | u32 mbx_size = IXGBE_VFMAILBOX_SIZE; | ||
327 | u32 msgbuf[IXGBE_VFMAILBOX_SIZE]; | ||
328 | struct ixgbe_hw *hw = &adapter->hw; | ||
329 | s32 retval; | ||
330 | int entries; | ||
331 | u16 *hash_list; | ||
332 | int add, vid, index; | ||
333 | u8 *new_mac; | ||
334 | |||
335 | retval = ixgbe_read_mbx(hw, msgbuf, mbx_size, vf); | ||
336 | |||
337 | if (retval) | ||
338 | pr_err("Error receiving message from VF\n"); | ||
339 | |||
340 | /* this is a message we already processed, do nothing */ | ||
341 | if (msgbuf[0] & (IXGBE_VT_MSGTYPE_ACK | IXGBE_VT_MSGTYPE_NACK)) | ||
342 | return retval; | ||
343 | |||
344 | /* | ||
345 | * until the vf completes a virtual function reset it should not be | ||
346 | * allowed to start any configuration. | ||
347 | */ | ||
348 | |||
349 | if (msgbuf[0] == IXGBE_VF_RESET) { | ||
350 | unsigned char *vf_mac = adapter->vfinfo[vf].vf_mac_addresses; | ||
351 | new_mac = (u8 *)(&msgbuf[1]); | ||
352 | e_info(probe, "VF Reset msg received from vf %d\n", vf); | ||
353 | adapter->vfinfo[vf].clear_to_send = false; | ||
354 | ixgbe_vf_reset_msg(adapter, vf); | ||
355 | adapter->vfinfo[vf].clear_to_send = true; | ||
356 | |||
357 | if (is_valid_ether_addr(new_mac) && | ||
358 | !adapter->vfinfo[vf].pf_set_mac) | ||
359 | ixgbe_set_vf_mac(adapter, vf, vf_mac); | ||
360 | else | ||
361 | ixgbe_set_vf_mac(adapter, | ||
362 | vf, adapter->vfinfo[vf].vf_mac_addresses); | ||
363 | |||
364 | /* reply to reset with ack and vf mac address */ | ||
365 | msgbuf[0] = IXGBE_VF_RESET | IXGBE_VT_MSGTYPE_ACK; | ||
366 | memcpy(new_mac, vf_mac, IXGBE_ETH_LENGTH_OF_ADDRESS); | ||
367 | /* | ||
368 | * Piggyback the multicast filter type so VF can compute the | ||
369 | * correct vectors | ||
370 | */ | ||
371 | msgbuf[3] = hw->mac.mc_filter_type; | ||
372 | ixgbe_write_mbx(hw, msgbuf, IXGBE_VF_PERMADDR_MSG_LEN, vf); | ||
373 | |||
374 | return retval; | ||
375 | } | ||
376 | |||
377 | if (!adapter->vfinfo[vf].clear_to_send) { | ||
378 | msgbuf[0] |= IXGBE_VT_MSGTYPE_NACK; | ||
379 | ixgbe_write_mbx(hw, msgbuf, 1, vf); | ||
380 | return retval; | ||
381 | } | ||
382 | |||
383 | switch ((msgbuf[0] & 0xFFFF)) { | ||
384 | case IXGBE_VF_SET_MAC_ADDR: | ||
385 | new_mac = ((u8 *)(&msgbuf[1])); | ||
386 | if (is_valid_ether_addr(new_mac) && | ||
387 | !adapter->vfinfo[vf].pf_set_mac) { | ||
388 | ixgbe_set_vf_mac(adapter, vf, new_mac); | ||
389 | } else if (memcmp(adapter->vfinfo[vf].vf_mac_addresses, | ||
390 | new_mac, ETH_ALEN)) { | ||
391 | e_warn(drv, "VF %d attempted to override " | ||
392 | "administratively set MAC address\nReload " | ||
393 | "the VF driver to resume operations\n", vf); | ||
394 | retval = -1; | ||
395 | } | ||
396 | break; | ||
397 | case IXGBE_VF_SET_MULTICAST: | ||
398 | entries = (msgbuf[0] & IXGBE_VT_MSGINFO_MASK) | ||
399 | >> IXGBE_VT_MSGINFO_SHIFT; | ||
400 | hash_list = (u16 *)&msgbuf[1]; | ||
401 | retval = ixgbe_set_vf_multicasts(adapter, entries, | ||
402 | hash_list, vf); | ||
403 | break; | ||
404 | case IXGBE_VF_SET_LPE: | ||
405 | ixgbe_set_vf_lpe(adapter, msgbuf); | ||
406 | break; | ||
407 | case IXGBE_VF_SET_VLAN: | ||
408 | add = (msgbuf[0] & IXGBE_VT_MSGINFO_MASK) | ||
409 | >> IXGBE_VT_MSGINFO_SHIFT; | ||
410 | vid = (msgbuf[1] & IXGBE_VLVF_VLANID_MASK); | ||
411 | if (adapter->vfinfo[vf].pf_vlan) { | ||
412 | e_warn(drv, "VF %d attempted to override " | ||
413 | "administratively set VLAN configuration\n" | ||
414 | "Reload the VF driver to resume operations\n", | ||
415 | vf); | ||
416 | retval = -1; | ||
417 | } else { | ||
418 | retval = ixgbe_set_vf_vlan(adapter, add, vid, vf); | ||
419 | } | ||
420 | break; | ||
421 | case IXGBE_VF_SET_MACVLAN: | ||
422 | index = (msgbuf[0] & IXGBE_VT_MSGINFO_MASK) >> | ||
423 | IXGBE_VT_MSGINFO_SHIFT; | ||
424 | /* | ||
425 | * If the VF is allowed to set MAC filters then turn off | ||
426 | * anti-spoofing to avoid false positives. An index | ||
427 | * greater than 0 will indicate the VF is setting a | ||
428 | * macvlan MAC filter. | ||
429 | */ | ||
430 | if (index > 0 && adapter->antispoofing_enabled) { | ||
431 | hw->mac.ops.set_mac_anti_spoofing(hw, false, | ||
432 | adapter->num_vfs); | ||
433 | hw->mac.ops.set_vlan_anti_spoofing(hw, false, vf); | ||
434 | adapter->antispoofing_enabled = false; | ||
435 | } | ||
436 | retval = ixgbe_set_vf_macvlan(adapter, vf, index, | ||
437 | (unsigned char *)(&msgbuf[1])); | ||
438 | break; | ||
439 | default: | ||
440 | e_err(drv, "Unhandled Msg %8.8x\n", msgbuf[0]); | ||
441 | retval = IXGBE_ERR_MBX; | ||
442 | break; | ||
443 | } | ||
444 | |||
445 | /* notify the VF of the results of what it sent us */ | ||
446 | if (retval) | ||
447 | msgbuf[0] |= IXGBE_VT_MSGTYPE_NACK; | ||
448 | else | ||
449 | msgbuf[0] |= IXGBE_VT_MSGTYPE_ACK; | ||
450 | |||
451 | msgbuf[0] |= IXGBE_VT_MSGTYPE_CTS; | ||
452 | |||
453 | ixgbe_write_mbx(hw, msgbuf, 1, vf); | ||
454 | |||
455 | return retval; | ||
456 | } | ||
457 | |||
458 | static void ixgbe_rcv_ack_from_vf(struct ixgbe_adapter *adapter, u32 vf) | ||
459 | { | ||
460 | struct ixgbe_hw *hw = &adapter->hw; | ||
461 | u32 msg = IXGBE_VT_MSGTYPE_NACK; | ||
462 | |||
463 | /* if device isn't clear to send it shouldn't be reading either */ | ||
464 | if (!adapter->vfinfo[vf].clear_to_send) | ||
465 | ixgbe_write_mbx(hw, &msg, 1, vf); | ||
466 | } | ||
467 | |||
468 | void ixgbe_msg_task(struct ixgbe_adapter *adapter) | ||
469 | { | ||
470 | struct ixgbe_hw *hw = &adapter->hw; | ||
471 | u32 vf; | ||
472 | |||
473 | for (vf = 0; vf < adapter->num_vfs; vf++) { | ||
474 | /* process any reset requests */ | ||
475 | if (!ixgbe_check_for_rst(hw, vf)) | ||
476 | ixgbe_vf_reset_event(adapter, vf); | ||
477 | |||
478 | /* process any messages pending */ | ||
479 | if (!ixgbe_check_for_msg(hw, vf)) | ||
480 | ixgbe_rcv_msg_from_vf(adapter, vf); | ||
481 | |||
482 | /* process any acks */ | ||
483 | if (!ixgbe_check_for_ack(hw, vf)) | ||
484 | ixgbe_rcv_ack_from_vf(adapter, vf); | ||
485 | } | ||
486 | } | ||
487 | |||
488 | void ixgbe_disable_tx_rx(struct ixgbe_adapter *adapter) | ||
489 | { | ||
490 | struct ixgbe_hw *hw = &adapter->hw; | ||
491 | |||
492 | /* disable transmit and receive for all vfs */ | ||
493 | IXGBE_WRITE_REG(hw, IXGBE_VFTE(0), 0); | ||
494 | IXGBE_WRITE_REG(hw, IXGBE_VFTE(1), 0); | ||
495 | |||
496 | IXGBE_WRITE_REG(hw, IXGBE_VFRE(0), 0); | ||
497 | IXGBE_WRITE_REG(hw, IXGBE_VFRE(1), 0); | ||
498 | } | ||
499 | |||
500 | void ixgbe_ping_all_vfs(struct ixgbe_adapter *adapter) | ||
501 | { | ||
502 | struct ixgbe_hw *hw = &adapter->hw; | ||
503 | u32 ping; | ||
504 | int i; | ||
505 | |||
506 | for (i = 0 ; i < adapter->num_vfs; i++) { | ||
507 | ping = IXGBE_PF_CONTROL_MSG; | ||
508 | if (adapter->vfinfo[i].clear_to_send) | ||
509 | ping |= IXGBE_VT_MSGTYPE_CTS; | ||
510 | ixgbe_write_mbx(hw, &ping, 1, i); | ||
511 | } | ||
512 | } | ||
513 | |||
514 | int ixgbe_ndo_set_vf_mac(struct net_device *netdev, int vf, u8 *mac) | ||
515 | { | ||
516 | struct ixgbe_adapter *adapter = netdev_priv(netdev); | ||
517 | if (!is_valid_ether_addr(mac) || (vf >= adapter->num_vfs)) | ||
518 | return -EINVAL; | ||
519 | adapter->vfinfo[vf].pf_set_mac = true; | ||
520 | dev_info(&adapter->pdev->dev, "setting MAC %pM on VF %d\n", mac, vf); | ||
521 | dev_info(&adapter->pdev->dev, "Reload the VF driver to make this" | ||
522 | " change effective."); | ||
523 | if (test_bit(__IXGBE_DOWN, &adapter->state)) { | ||
524 | dev_warn(&adapter->pdev->dev, "The VF MAC address has been set," | ||
525 | " but the PF device is not up.\n"); | ||
526 | dev_warn(&adapter->pdev->dev, "Bring the PF device up before" | ||
527 | " attempting to use the VF device.\n"); | ||
528 | } | ||
529 | return ixgbe_set_vf_mac(adapter, vf, mac); | ||
530 | } | ||
531 | |||
532 | int ixgbe_ndo_set_vf_vlan(struct net_device *netdev, int vf, u16 vlan, u8 qos) | ||
533 | { | ||
534 | int err = 0; | ||
535 | struct ixgbe_adapter *adapter = netdev_priv(netdev); | ||
536 | struct ixgbe_hw *hw = &adapter->hw; | ||
537 | |||
538 | if ((vf >= adapter->num_vfs) || (vlan > 4095) || (qos > 7)) | ||
539 | return -EINVAL; | ||
540 | if (vlan || qos) { | ||
541 | err = ixgbe_set_vf_vlan(adapter, true, vlan, vf); | ||
542 | if (err) | ||
543 | goto out; | ||
544 | ixgbe_set_vmvir(adapter, vlan | (qos << VLAN_PRIO_SHIFT), vf); | ||
545 | ixgbe_set_vmolr(hw, vf, false); | ||
546 | if (adapter->antispoofing_enabled) | ||
547 | hw->mac.ops.set_vlan_anti_spoofing(hw, true, vf); | ||
548 | adapter->vfinfo[vf].pf_vlan = vlan; | ||
549 | adapter->vfinfo[vf].pf_qos = qos; | ||
550 | dev_info(&adapter->pdev->dev, | ||
551 | "Setting VLAN %d, QOS 0x%x on VF %d\n", vlan, qos, vf); | ||
552 | if (test_bit(__IXGBE_DOWN, &adapter->state)) { | ||
553 | dev_warn(&adapter->pdev->dev, | ||
554 | "The VF VLAN has been set," | ||
555 | " but the PF device is not up.\n"); | ||
556 | dev_warn(&adapter->pdev->dev, | ||
557 | "Bring the PF device up before" | ||
558 | " attempting to use the VF device.\n"); | ||
559 | } | ||
560 | } else { | ||
561 | err = ixgbe_set_vf_vlan(adapter, false, | ||
562 | adapter->vfinfo[vf].pf_vlan, vf); | ||
563 | ixgbe_set_vmvir(adapter, vlan, vf); | ||
564 | ixgbe_set_vmolr(hw, vf, true); | ||
565 | hw->mac.ops.set_vlan_anti_spoofing(hw, false, vf); | ||
566 | adapter->vfinfo[vf].pf_vlan = 0; | ||
567 | adapter->vfinfo[vf].pf_qos = 0; | ||
568 | } | ||
569 | out: | ||
570 | return err; | ||
571 | } | ||
572 | |||
573 | static int ixgbe_link_mbps(int internal_link_speed) | ||
574 | { | ||
575 | switch (internal_link_speed) { | ||
576 | case IXGBE_LINK_SPEED_100_FULL: | ||
577 | return 100; | ||
578 | case IXGBE_LINK_SPEED_1GB_FULL: | ||
579 | return 1000; | ||
580 | case IXGBE_LINK_SPEED_10GB_FULL: | ||
581 | return 10000; | ||
582 | default: | ||
583 | return 0; | ||
584 | } | ||
585 | } | ||
586 | |||
587 | static void ixgbe_set_vf_rate_limit(struct ixgbe_hw *hw, int vf, int tx_rate, | ||
588 | int link_speed) | ||
589 | { | ||
590 | int rf_dec, rf_int; | ||
591 | u32 bcnrc_val; | ||
592 | |||
593 | if (tx_rate != 0) { | ||
594 | /* Calculate the rate factor values to set */ | ||
595 | rf_int = link_speed / tx_rate; | ||
596 | rf_dec = (link_speed - (rf_int * tx_rate)); | ||
597 | rf_dec = (rf_dec * (1<<IXGBE_RTTBCNRC_RF_INT_SHIFT)) / tx_rate; | ||
598 | |||
599 | bcnrc_val = IXGBE_RTTBCNRC_RS_ENA; | ||
600 | bcnrc_val |= ((rf_int<<IXGBE_RTTBCNRC_RF_INT_SHIFT) & | ||
601 | IXGBE_RTTBCNRC_RF_INT_MASK); | ||
602 | bcnrc_val |= (rf_dec & IXGBE_RTTBCNRC_RF_DEC_MASK); | ||
603 | } else { | ||
604 | bcnrc_val = 0; | ||
605 | } | ||
606 | |||
607 | IXGBE_WRITE_REG(hw, IXGBE_RTTDQSEL, 2*vf); /* vf Y uses queue 2*Y */ | ||
608 | /* | ||
609 | * Set global transmit compensation time to the MMW_SIZE in RTTBCNRM | ||
610 | * register. Typically MMW_SIZE=0x014 if 9728-byte jumbo is supported | ||
611 | * and 0x004 otherwise. | ||
612 | */ | ||
613 | switch (hw->mac.type) { | ||
614 | case ixgbe_mac_82599EB: | ||
615 | IXGBE_WRITE_REG(hw, IXGBE_RTTBCNRM, 0x4); | ||
616 | break; | ||
617 | case ixgbe_mac_X540: | ||
618 | IXGBE_WRITE_REG(hw, IXGBE_RTTBCNRM, 0x14); | ||
619 | break; | ||
620 | default: | ||
621 | break; | ||
622 | } | ||
623 | |||
624 | IXGBE_WRITE_REG(hw, IXGBE_RTTBCNRC, bcnrc_val); | ||
625 | } | ||
626 | |||
627 | void ixgbe_check_vf_rate_limit(struct ixgbe_adapter *adapter) | ||
628 | { | ||
629 | int actual_link_speed, i; | ||
630 | bool reset_rate = false; | ||
631 | |||
632 | /* VF Tx rate limit was not set */ | ||
633 | if (adapter->vf_rate_link_speed == 0) | ||
634 | return; | ||
635 | |||
636 | actual_link_speed = ixgbe_link_mbps(adapter->link_speed); | ||
637 | if (actual_link_speed != adapter->vf_rate_link_speed) { | ||
638 | reset_rate = true; | ||
639 | adapter->vf_rate_link_speed = 0; | ||
640 | dev_info(&adapter->pdev->dev, | ||
641 | "Link speed has been changed. VF Transmit rate " | ||
642 | "is disabled\n"); | ||
643 | } | ||
644 | |||
645 | for (i = 0; i < adapter->num_vfs; i++) { | ||
646 | if (reset_rate) | ||
647 | adapter->vfinfo[i].tx_rate = 0; | ||
648 | |||
649 | ixgbe_set_vf_rate_limit(&adapter->hw, i, | ||
650 | adapter->vfinfo[i].tx_rate, | ||
651 | actual_link_speed); | ||
652 | } | ||
653 | } | ||
654 | |||
655 | int ixgbe_ndo_set_vf_bw(struct net_device *netdev, int vf, int tx_rate) | ||
656 | { | ||
657 | struct ixgbe_adapter *adapter = netdev_priv(netdev); | ||
658 | struct ixgbe_hw *hw = &adapter->hw; | ||
659 | int actual_link_speed; | ||
660 | |||
661 | actual_link_speed = ixgbe_link_mbps(adapter->link_speed); | ||
662 | if ((vf >= adapter->num_vfs) || (!adapter->link_up) || | ||
663 | (tx_rate > actual_link_speed) || (actual_link_speed != 10000) || | ||
664 | ((tx_rate != 0) && (tx_rate <= 10))) | ||
665 | /* rate limit cannot be set to 10Mb or less in 10Gb adapters */ | ||
666 | return -EINVAL; | ||
667 | |||
668 | adapter->vf_rate_link_speed = actual_link_speed; | ||
669 | adapter->vfinfo[vf].tx_rate = (u16)tx_rate; | ||
670 | ixgbe_set_vf_rate_limit(hw, vf, tx_rate, actual_link_speed); | ||
671 | |||
672 | return 0; | ||
673 | } | ||
674 | |||
675 | int ixgbe_ndo_get_vf_config(struct net_device *netdev, | ||
676 | int vf, struct ifla_vf_info *ivi) | ||
677 | { | ||
678 | struct ixgbe_adapter *adapter = netdev_priv(netdev); | ||
679 | if (vf >= adapter->num_vfs) | ||
680 | return -EINVAL; | ||
681 | ivi->vf = vf; | ||
682 | memcpy(&ivi->mac, adapter->vfinfo[vf].vf_mac_addresses, ETH_ALEN); | ||
683 | ivi->tx_rate = adapter->vfinfo[vf].tx_rate; | ||
684 | ivi->vlan = adapter->vfinfo[vf].pf_vlan; | ||
685 | ivi->qos = adapter->vfinfo[vf].pf_qos; | ||
686 | return 0; | ||
687 | } | ||
diff --git a/drivers/net/ixgbe/ixgbe_sriov.h b/drivers/net/ixgbe/ixgbe_sriov.h new file mode 100644 index 00000000000..34175564bb7 --- /dev/null +++ b/drivers/net/ixgbe/ixgbe_sriov.h | |||
@@ -0,0 +1,46 @@ | |||
1 | /******************************************************************************* | ||
2 | |||
3 | Intel 10 Gigabit PCI Express Linux driver | ||
4 | Copyright(c) 1999 - 2011 Intel Corporation. | ||
5 | |||
6 | This program is free software; you can redistribute it and/or modify it | ||
7 | under the terms and conditions of the GNU General Public License, | ||
8 | version 2, as published by the Free Software Foundation. | ||
9 | |||
10 | This program is distributed in the hope it will be useful, but WITHOUT | ||
11 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
12 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
13 | more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License along with | ||
16 | this program; if not, write to the Free Software Foundation, Inc., | ||
17 | 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. | ||
18 | |||
19 | The full GNU General Public License is included in this distribution in | ||
20 | the file called "COPYING". | ||
21 | |||
22 | Contact Information: | ||
23 | e1000-devel Mailing List <e1000-devel@lists.sourceforge.net> | ||
24 | Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 | ||
25 | |||
26 | *******************************************************************************/ | ||
27 | |||
28 | #ifndef _IXGBE_SRIOV_H_ | ||
29 | #define _IXGBE_SRIOV_H_ | ||
30 | |||
31 | void ixgbe_restore_vf_multicasts(struct ixgbe_adapter *adapter); | ||
32 | void ixgbe_msg_task(struct ixgbe_adapter *adapter); | ||
33 | int ixgbe_vf_configuration(struct pci_dev *pdev, unsigned int event_mask); | ||
34 | void ixgbe_disable_tx_rx(struct ixgbe_adapter *adapter); | ||
35 | void ixgbe_ping_all_vfs(struct ixgbe_adapter *adapter); | ||
36 | void ixgbe_dump_registers(struct ixgbe_adapter *adapter); | ||
37 | int ixgbe_ndo_set_vf_mac(struct net_device *netdev, int queue, u8 *mac); | ||
38 | int ixgbe_ndo_set_vf_vlan(struct net_device *netdev, int queue, u16 vlan, | ||
39 | u8 qos); | ||
40 | int ixgbe_ndo_set_vf_bw(struct net_device *netdev, int vf, int tx_rate); | ||
41 | int ixgbe_ndo_get_vf_config(struct net_device *netdev, | ||
42 | int vf, struct ifla_vf_info *ivi); | ||
43 | void ixgbe_check_vf_rate_limit(struct ixgbe_adapter *adapter); | ||
44 | |||
45 | #endif /* _IXGBE_SRIOV_H_ */ | ||
46 | |||
diff --git a/drivers/net/ixgbe/ixgbe_type.h b/drivers/net/ixgbe/ixgbe_type.h new file mode 100644 index 00000000000..e0d970ebab7 --- /dev/null +++ b/drivers/net/ixgbe/ixgbe_type.h | |||
@@ -0,0 +1,2877 @@ | |||
1 | /******************************************************************************* | ||
2 | |||
3 | Intel 10 Gigabit PCI Express Linux driver | ||
4 | Copyright(c) 1999 - 2011 Intel Corporation. | ||
5 | |||
6 | This program is free software; you can redistribute it and/or modify it | ||
7 | under the terms and conditions of the GNU General Public License, | ||
8 | version 2, as published by the Free Software Foundation. | ||
9 | |||
10 | This program is distributed in the hope it will be useful, but WITHOUT | ||
11 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
12 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
13 | more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License along with | ||
16 | this program; if not, write to the Free Software Foundation, Inc., | ||
17 | 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. | ||
18 | |||
19 | The full GNU General Public License is included in this distribution in | ||
20 | the file called "COPYING". | ||
21 | |||
22 | Contact Information: | ||
23 | e1000-devel Mailing List <e1000-devel@lists.sourceforge.net> | ||
24 | Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 | ||
25 | |||
26 | *******************************************************************************/ | ||
27 | |||
28 | #ifndef _IXGBE_TYPE_H_ | ||
29 | #define _IXGBE_TYPE_H_ | ||
30 | |||
31 | #include <linux/types.h> | ||
32 | #include <linux/mdio.h> | ||
33 | #include <linux/netdevice.h> | ||
34 | |||
35 | /* Vendor ID */ | ||
36 | #define IXGBE_INTEL_VENDOR_ID 0x8086 | ||
37 | |||
38 | /* Device IDs */ | ||
39 | #define IXGBE_DEV_ID_82598 0x10B6 | ||
40 | #define IXGBE_DEV_ID_82598_BX 0x1508 | ||
41 | #define IXGBE_DEV_ID_82598AF_DUAL_PORT 0x10C6 | ||
42 | #define IXGBE_DEV_ID_82598AF_SINGLE_PORT 0x10C7 | ||
43 | #define IXGBE_DEV_ID_82598EB_SFP_LOM 0x10DB | ||
44 | #define IXGBE_DEV_ID_82598AT 0x10C8 | ||
45 | #define IXGBE_DEV_ID_82598AT2 0x150B | ||
46 | #define IXGBE_DEV_ID_82598EB_CX4 0x10DD | ||
47 | #define IXGBE_DEV_ID_82598_CX4_DUAL_PORT 0x10EC | ||
48 | #define IXGBE_DEV_ID_82598_DA_DUAL_PORT 0x10F1 | ||
49 | #define IXGBE_DEV_ID_82598_SR_DUAL_PORT_EM 0x10E1 | ||
50 | #define IXGBE_DEV_ID_82598EB_XF_LR 0x10F4 | ||
51 | #define IXGBE_DEV_ID_82599_KX4 0x10F7 | ||
52 | #define IXGBE_DEV_ID_82599_KX4_MEZZ 0x1514 | ||
53 | #define IXGBE_DEV_ID_82599_KR 0x1517 | ||
54 | #define IXGBE_DEV_ID_82599_T3_LOM 0x151C | ||
55 | #define IXGBE_DEV_ID_82599_CX4 0x10F9 | ||
56 | #define IXGBE_DEV_ID_82599_SFP 0x10FB | ||
57 | #define IXGBE_DEV_ID_82599_BACKPLANE_FCOE 0x152a | ||
58 | #define IXGBE_DEV_ID_82599_SFP_FCOE 0x1529 | ||
59 | #define IXGBE_SUBDEV_ID_82599_SFP 0x11A9 | ||
60 | #define IXGBE_DEV_ID_82599_SFP_EM 0x1507 | ||
61 | #define IXGBE_DEV_ID_82599_SFP_SF2 0x154D | ||
62 | #define IXGBE_DEV_ID_82599_XAUI_LOM 0x10FC | ||
63 | #define IXGBE_DEV_ID_82599_COMBO_BACKPLANE 0x10F8 | ||
64 | #define IXGBE_SUBDEV_ID_82599_KX4_KR_MEZZ 0x000C | ||
65 | #define IXGBE_DEV_ID_82599_LS 0x154F | ||
66 | #define IXGBE_DEV_ID_X540T 0x1528 | ||
67 | |||
68 | /* General Registers */ | ||
69 | #define IXGBE_CTRL 0x00000 | ||
70 | #define IXGBE_STATUS 0x00008 | ||
71 | #define IXGBE_CTRL_EXT 0x00018 | ||
72 | #define IXGBE_ESDP 0x00020 | ||
73 | #define IXGBE_EODSDP 0x00028 | ||
74 | #define IXGBE_I2CCTL 0x00028 | ||
75 | #define IXGBE_LEDCTL 0x00200 | ||
76 | #define IXGBE_FRTIMER 0x00048 | ||
77 | #define IXGBE_TCPTIMER 0x0004C | ||
78 | #define IXGBE_CORESPARE 0x00600 | ||
79 | #define IXGBE_EXVET 0x05078 | ||
80 | |||
81 | /* NVM Registers */ | ||
82 | #define IXGBE_EEC 0x10010 | ||
83 | #define IXGBE_EERD 0x10014 | ||
84 | #define IXGBE_EEWR 0x10018 | ||
85 | #define IXGBE_FLA 0x1001C | ||
86 | #define IXGBE_EEMNGCTL 0x10110 | ||
87 | #define IXGBE_EEMNGDATA 0x10114 | ||
88 | #define IXGBE_FLMNGCTL 0x10118 | ||
89 | #define IXGBE_FLMNGDATA 0x1011C | ||
90 | #define IXGBE_FLMNGCNT 0x10120 | ||
91 | #define IXGBE_FLOP 0x1013C | ||
92 | #define IXGBE_GRC 0x10200 | ||
93 | |||
94 | /* General Receive Control */ | ||
95 | #define IXGBE_GRC_MNG 0x00000001 /* Manageability Enable */ | ||
96 | #define IXGBE_GRC_APME 0x00000002 /* APM enabled in EEPROM */ | ||
97 | |||
98 | #define IXGBE_VPDDIAG0 0x10204 | ||
99 | #define IXGBE_VPDDIAG1 0x10208 | ||
100 | |||
101 | /* I2CCTL Bit Masks */ | ||
102 | #define IXGBE_I2C_CLK_IN 0x00000001 | ||
103 | #define IXGBE_I2C_CLK_OUT 0x00000002 | ||
104 | #define IXGBE_I2C_DATA_IN 0x00000004 | ||
105 | #define IXGBE_I2C_DATA_OUT 0x00000008 | ||
106 | |||
107 | /* Interrupt Registers */ | ||
108 | #define IXGBE_EICR 0x00800 | ||
109 | #define IXGBE_EICS 0x00808 | ||
110 | #define IXGBE_EIMS 0x00880 | ||
111 | #define IXGBE_EIMC 0x00888 | ||
112 | #define IXGBE_EIAC 0x00810 | ||
113 | #define IXGBE_EIAM 0x00890 | ||
114 | #define IXGBE_EICS_EX(_i) (0x00A90 + (_i) * 4) | ||
115 | #define IXGBE_EIMS_EX(_i) (0x00AA0 + (_i) * 4) | ||
116 | #define IXGBE_EIMC_EX(_i) (0x00AB0 + (_i) * 4) | ||
117 | #define IXGBE_EIAM_EX(_i) (0x00AD0 + (_i) * 4) | ||
118 | /* | ||
119 | * 82598 EITR is 16 bits but set the limits based on the max | ||
120 | * supported by all ixgbe hardware. 82599 EITR is only 12 bits, | ||
121 | * with the lower 3 always zero. | ||
122 | */ | ||
123 | #define IXGBE_MAX_INT_RATE 488281 | ||
124 | #define IXGBE_MIN_INT_RATE 956 | ||
125 | #define IXGBE_MAX_EITR 0x00000FF8 | ||
126 | #define IXGBE_MIN_EITR 8 | ||
127 | #define IXGBE_EITR(_i) (((_i) <= 23) ? (0x00820 + ((_i) * 4)) : \ | ||
128 | (0x012300 + (((_i) - 24) * 4))) | ||
129 | #define IXGBE_EITR_ITR_INT_MASK 0x00000FF8 | ||
130 | #define IXGBE_EITR_LLI_MOD 0x00008000 | ||
131 | #define IXGBE_EITR_CNT_WDIS 0x80000000 | ||
132 | #define IXGBE_IVAR(_i) (0x00900 + ((_i) * 4)) /* 24 at 0x900-0x960 */ | ||
133 | #define IXGBE_IVAR_MISC 0x00A00 /* misc MSI-X interrupt causes */ | ||
134 | #define IXGBE_EITRSEL 0x00894 | ||
135 | #define IXGBE_MSIXT 0x00000 /* MSI-X Table. 0x0000 - 0x01C */ | ||
136 | #define IXGBE_MSIXPBA 0x02000 /* MSI-X Pending bit array */ | ||
137 | #define IXGBE_PBACL(_i) (((_i) == 0) ? (0x11068) : (0x110C0 + ((_i) * 4))) | ||
138 | #define IXGBE_GPIE 0x00898 | ||
139 | |||
140 | /* Flow Control Registers */ | ||
141 | #define IXGBE_FCADBUL 0x03210 | ||
142 | #define IXGBE_FCADBUH 0x03214 | ||
143 | #define IXGBE_FCAMACL 0x04328 | ||
144 | #define IXGBE_FCAMACH 0x0432C | ||
145 | #define IXGBE_FCRTH_82599(_i) (0x03260 + ((_i) * 4)) /* 8 of these (0-7) */ | ||
146 | #define IXGBE_FCRTL_82599(_i) (0x03220 + ((_i) * 4)) /* 8 of these (0-7) */ | ||
147 | #define IXGBE_PFCTOP 0x03008 | ||
148 | #define IXGBE_FCTTV(_i) (0x03200 + ((_i) * 4)) /* 4 of these (0-3) */ | ||
149 | #define IXGBE_FCRTL(_i) (0x03220 + ((_i) * 8)) /* 8 of these (0-7) */ | ||
150 | #define IXGBE_FCRTH(_i) (0x03260 + ((_i) * 8)) /* 8 of these (0-7) */ | ||
151 | #define IXGBE_FCRTV 0x032A0 | ||
152 | #define IXGBE_FCCFG 0x03D00 | ||
153 | #define IXGBE_TFCS 0x0CE00 | ||
154 | |||
155 | /* Receive DMA Registers */ | ||
156 | #define IXGBE_RDBAL(_i) (((_i) < 64) ? (0x01000 + ((_i) * 0x40)) : \ | ||
157 | (0x0D000 + ((_i - 64) * 0x40))) | ||
158 | #define IXGBE_RDBAH(_i) (((_i) < 64) ? (0x01004 + ((_i) * 0x40)) : \ | ||
159 | (0x0D004 + ((_i - 64) * 0x40))) | ||
160 | #define IXGBE_RDLEN(_i) (((_i) < 64) ? (0x01008 + ((_i) * 0x40)) : \ | ||
161 | (0x0D008 + ((_i - 64) * 0x40))) | ||
162 | #define IXGBE_RDH(_i) (((_i) < 64) ? (0x01010 + ((_i) * 0x40)) : \ | ||
163 | (0x0D010 + ((_i - 64) * 0x40))) | ||
164 | #define IXGBE_RDT(_i) (((_i) < 64) ? (0x01018 + ((_i) * 0x40)) : \ | ||
165 | (0x0D018 + ((_i - 64) * 0x40))) | ||
166 | #define IXGBE_RXDCTL(_i) (((_i) < 64) ? (0x01028 + ((_i) * 0x40)) : \ | ||
167 | (0x0D028 + ((_i - 64) * 0x40))) | ||
168 | #define IXGBE_RSCCTL(_i) (((_i) < 64) ? (0x0102C + ((_i) * 0x40)) : \ | ||
169 | (0x0D02C + ((_i - 64) * 0x40))) | ||
170 | #define IXGBE_RSCDBU 0x03028 | ||
171 | #define IXGBE_RDDCC 0x02F20 | ||
172 | #define IXGBE_RXMEMWRAP 0x03190 | ||
173 | #define IXGBE_STARCTRL 0x03024 | ||
174 | /* | ||
175 | * Split and Replication Receive Control Registers | ||
176 | * 00-15 : 0x02100 + n*4 | ||
177 | * 16-64 : 0x01014 + n*0x40 | ||
178 | * 64-127: 0x0D014 + (n-64)*0x40 | ||
179 | */ | ||
180 | #define IXGBE_SRRCTL(_i) (((_i) <= 15) ? (0x02100 + ((_i) * 4)) : \ | ||
181 | (((_i) < 64) ? (0x01014 + ((_i) * 0x40)) : \ | ||
182 | (0x0D014 + ((_i - 64) * 0x40)))) | ||
183 | /* | ||
184 | * Rx DCA Control Register: | ||
185 | * 00-15 : 0x02200 + n*4 | ||
186 | * 16-64 : 0x0100C + n*0x40 | ||
187 | * 64-127: 0x0D00C + (n-64)*0x40 | ||
188 | */ | ||
189 | #define IXGBE_DCA_RXCTRL(_i) (((_i) <= 15) ? (0x02200 + ((_i) * 4)) : \ | ||
190 | (((_i) < 64) ? (0x0100C + ((_i) * 0x40)) : \ | ||
191 | (0x0D00C + ((_i - 64) * 0x40)))) | ||
192 | #define IXGBE_RDRXCTL 0x02F00 | ||
193 | #define IXGBE_RXPBSIZE(_i) (0x03C00 + ((_i) * 4)) | ||
194 | /* 8 of these 0x03C00 - 0x03C1C */ | ||
195 | #define IXGBE_RXCTRL 0x03000 | ||
196 | #define IXGBE_DROPEN 0x03D04 | ||
197 | #define IXGBE_RXPBSIZE_SHIFT 10 | ||
198 | |||
199 | /* Receive Registers */ | ||
200 | #define IXGBE_RXCSUM 0x05000 | ||
201 | #define IXGBE_RFCTL 0x05008 | ||
202 | #define IXGBE_DRECCCTL 0x02F08 | ||
203 | #define IXGBE_DRECCCTL_DISABLE 0 | ||
204 | /* Multicast Table Array - 128 entries */ | ||
205 | #define IXGBE_MTA(_i) (0x05200 + ((_i) * 4)) | ||
206 | #define IXGBE_RAL(_i) (((_i) <= 15) ? (0x05400 + ((_i) * 8)) : \ | ||
207 | (0x0A200 + ((_i) * 8))) | ||
208 | #define IXGBE_RAH(_i) (((_i) <= 15) ? (0x05404 + ((_i) * 8)) : \ | ||
209 | (0x0A204 + ((_i) * 8))) | ||
210 | #define IXGBE_MPSAR_LO(_i) (0x0A600 + ((_i) * 8)) | ||
211 | #define IXGBE_MPSAR_HI(_i) (0x0A604 + ((_i) * 8)) | ||
212 | /* Packet split receive type */ | ||
213 | #define IXGBE_PSRTYPE(_i) (((_i) <= 15) ? (0x05480 + ((_i) * 4)) : \ | ||
214 | (0x0EA00 + ((_i) * 4))) | ||
215 | /* array of 4096 1-bit vlan filters */ | ||
216 | #define IXGBE_VFTA(_i) (0x0A000 + ((_i) * 4)) | ||
217 | /*array of 4096 4-bit vlan vmdq indices */ | ||
218 | #define IXGBE_VFTAVIND(_j, _i) (0x0A200 + ((_j) * 0x200) + ((_i) * 4)) | ||
219 | #define IXGBE_FCTRL 0x05080 | ||
220 | #define IXGBE_VLNCTRL 0x05088 | ||
221 | #define IXGBE_MCSTCTRL 0x05090 | ||
222 | #define IXGBE_MRQC 0x05818 | ||
223 | #define IXGBE_SAQF(_i) (0x0E000 + ((_i) * 4)) /* Source Address Queue Filter */ | ||
224 | #define IXGBE_DAQF(_i) (0x0E200 + ((_i) * 4)) /* Dest. Address Queue Filter */ | ||
225 | #define IXGBE_SDPQF(_i) (0x0E400 + ((_i) * 4)) /* Src Dest. Addr Queue Filter */ | ||
226 | #define IXGBE_FTQF(_i) (0x0E600 + ((_i) * 4)) /* Five Tuple Queue Filter */ | ||
227 | #define IXGBE_ETQF(_i) (0x05128 + ((_i) * 4)) /* EType Queue Filter */ | ||
228 | #define IXGBE_ETQS(_i) (0x0EC00 + ((_i) * 4)) /* EType Queue Select */ | ||
229 | #define IXGBE_SYNQF 0x0EC30 /* SYN Packet Queue Filter */ | ||
230 | #define IXGBE_RQTC 0x0EC70 | ||
231 | #define IXGBE_MTQC 0x08120 | ||
232 | #define IXGBE_VLVF(_i) (0x0F100 + ((_i) * 4)) /* 64 of these (0-63) */ | ||
233 | #define IXGBE_VLVFB(_i) (0x0F200 + ((_i) * 4)) /* 128 of these (0-127) */ | ||
234 | #define IXGBE_VMVIR(_i) (0x08000 + ((_i) * 4)) /* 64 of these (0-63) */ | ||
235 | #define IXGBE_VT_CTL 0x051B0 | ||
236 | #define IXGBE_PFMAILBOX(_i) (0x04B00 + (4 * (_i))) /* 64 total */ | ||
237 | #define IXGBE_PFMBMEM(_i) (0x13000 + (64 * (_i))) /* 64 Mailboxes, 16 DW each */ | ||
238 | #define IXGBE_PFMBICR(_i) (0x00710 + (4 * (_i))) /* 4 total */ | ||
239 | #define IXGBE_PFMBIMR(_i) (0x00720 + (4 * (_i))) /* 4 total */ | ||
240 | #define IXGBE_VFRE(_i) (0x051E0 + ((_i) * 4)) | ||
241 | #define IXGBE_VFTE(_i) (0x08110 + ((_i) * 4)) | ||
242 | #define IXGBE_VMECM(_i) (0x08790 + ((_i) * 4)) | ||
243 | #define IXGBE_QDE 0x2F04 | ||
244 | #define IXGBE_VMTXSW(_i) (0x05180 + ((_i) * 4)) /* 2 total */ | ||
245 | #define IXGBE_VMOLR(_i) (0x0F000 + ((_i) * 4)) /* 64 total */ | ||
246 | #define IXGBE_UTA(_i) (0x0F400 + ((_i) * 4)) | ||
247 | #define IXGBE_MRCTL(_i) (0x0F600 + ((_i) * 4)) | ||
248 | #define IXGBE_VMRVLAN(_i) (0x0F610 + ((_i) * 4)) | ||
249 | #define IXGBE_VMRVM(_i) (0x0F630 + ((_i) * 4)) | ||
250 | #define IXGBE_L34T_IMIR(_i) (0x0E800 + ((_i) * 4)) /*128 of these (0-127)*/ | ||
251 | #define IXGBE_RXFECCERR0 0x051B8 | ||
252 | #define IXGBE_LLITHRESH 0x0EC90 | ||
253 | #define IXGBE_IMIR(_i) (0x05A80 + ((_i) * 4)) /* 8 of these (0-7) */ | ||
254 | #define IXGBE_IMIREXT(_i) (0x05AA0 + ((_i) * 4)) /* 8 of these (0-7) */ | ||
255 | #define IXGBE_IMIRVP 0x05AC0 | ||
256 | #define IXGBE_VMD_CTL 0x0581C | ||
257 | #define IXGBE_RETA(_i) (0x05C00 + ((_i) * 4)) /* 32 of these (0-31) */ | ||
258 | #define IXGBE_RSSRK(_i) (0x05C80 + ((_i) * 4)) /* 10 of these (0-9) */ | ||
259 | |||
260 | /* Flow Director registers */ | ||
261 | #define IXGBE_FDIRCTRL 0x0EE00 | ||
262 | #define IXGBE_FDIRHKEY 0x0EE68 | ||
263 | #define IXGBE_FDIRSKEY 0x0EE6C | ||
264 | #define IXGBE_FDIRDIP4M 0x0EE3C | ||
265 | #define IXGBE_FDIRSIP4M 0x0EE40 | ||
266 | #define IXGBE_FDIRTCPM 0x0EE44 | ||
267 | #define IXGBE_FDIRUDPM 0x0EE48 | ||
268 | #define IXGBE_FDIRIP6M 0x0EE74 | ||
269 | #define IXGBE_FDIRM 0x0EE70 | ||
270 | |||
271 | /* Flow Director Stats registers */ | ||
272 | #define IXGBE_FDIRFREE 0x0EE38 | ||
273 | #define IXGBE_FDIRLEN 0x0EE4C | ||
274 | #define IXGBE_FDIRUSTAT 0x0EE50 | ||
275 | #define IXGBE_FDIRFSTAT 0x0EE54 | ||
276 | #define IXGBE_FDIRMATCH 0x0EE58 | ||
277 | #define IXGBE_FDIRMISS 0x0EE5C | ||
278 | |||
279 | /* Flow Director Programming registers */ | ||
280 | #define IXGBE_FDIRSIPv6(_i) (0x0EE0C + ((_i) * 4)) /* 3 of these (0-2) */ | ||
281 | #define IXGBE_FDIRIPSA 0x0EE18 | ||
282 | #define IXGBE_FDIRIPDA 0x0EE1C | ||
283 | #define IXGBE_FDIRPORT 0x0EE20 | ||
284 | #define IXGBE_FDIRVLAN 0x0EE24 | ||
285 | #define IXGBE_FDIRHASH 0x0EE28 | ||
286 | #define IXGBE_FDIRCMD 0x0EE2C | ||
287 | |||
288 | /* Transmit DMA registers */ | ||
289 | #define IXGBE_TDBAL(_i) (0x06000 + ((_i) * 0x40)) /* 32 of these (0-31)*/ | ||
290 | #define IXGBE_TDBAH(_i) (0x06004 + ((_i) * 0x40)) | ||
291 | #define IXGBE_TDLEN(_i) (0x06008 + ((_i) * 0x40)) | ||
292 | #define IXGBE_TDH(_i) (0x06010 + ((_i) * 0x40)) | ||
293 | #define IXGBE_TDT(_i) (0x06018 + ((_i) * 0x40)) | ||
294 | #define IXGBE_TXDCTL(_i) (0x06028 + ((_i) * 0x40)) | ||
295 | #define IXGBE_TDWBAL(_i) (0x06038 + ((_i) * 0x40)) | ||
296 | #define IXGBE_TDWBAH(_i) (0x0603C + ((_i) * 0x40)) | ||
297 | #define IXGBE_DTXCTL 0x07E00 | ||
298 | |||
299 | #define IXGBE_DMATXCTL 0x04A80 | ||
300 | #define IXGBE_PFVFSPOOF(_i) (0x08200 + ((_i) * 4)) /* 8 of these 0 - 7 */ | ||
301 | #define IXGBE_PFDTXGSWC 0x08220 | ||
302 | #define IXGBE_DTXMXSZRQ 0x08100 | ||
303 | #define IXGBE_DTXTCPFLGL 0x04A88 | ||
304 | #define IXGBE_DTXTCPFLGH 0x04A8C | ||
305 | #define IXGBE_LBDRPEN 0x0CA00 | ||
306 | #define IXGBE_TXPBTHRESH(_i) (0x04950 + ((_i) * 4)) /* 8 of these 0 - 7 */ | ||
307 | |||
308 | #define IXGBE_DMATXCTL_TE 0x1 /* Transmit Enable */ | ||
309 | #define IXGBE_DMATXCTL_NS 0x2 /* No Snoop LSO hdr buffer */ | ||
310 | #define IXGBE_DMATXCTL_GDV 0x8 /* Global Double VLAN */ | ||
311 | #define IXGBE_DMATXCTL_VT_SHIFT 16 /* VLAN EtherType */ | ||
312 | |||
313 | #define IXGBE_PFDTXGSWC_VT_LBEN 0x1 /* Local L2 VT switch enable */ | ||
314 | |||
315 | /* Anti-spoofing defines */ | ||
316 | #define IXGBE_SPOOF_MACAS_MASK 0xFF | ||
317 | #define IXGBE_SPOOF_VLANAS_MASK 0xFF00 | ||
318 | #define IXGBE_SPOOF_VLANAS_SHIFT 8 | ||
319 | #define IXGBE_PFVFSPOOF_REG_COUNT 8 | ||
320 | |||
321 | #define IXGBE_DCA_TXCTRL(_i) (0x07200 + ((_i) * 4)) /* 16 of these (0-15) */ | ||
322 | /* Tx DCA Control register : 128 of these (0-127) */ | ||
323 | #define IXGBE_DCA_TXCTRL_82599(_i) (0x0600C + ((_i) * 0x40)) | ||
324 | #define IXGBE_TIPG 0x0CB00 | ||
325 | #define IXGBE_TXPBSIZE(_i) (0x0CC00 + ((_i) * 4)) /* 8 of these */ | ||
326 | #define IXGBE_MNGTXMAP 0x0CD10 | ||
327 | #define IXGBE_TIPG_FIBER_DEFAULT 3 | ||
328 | #define IXGBE_TXPBSIZE_SHIFT 10 | ||
329 | |||
330 | /* Wake up registers */ | ||
331 | #define IXGBE_WUC 0x05800 | ||
332 | #define IXGBE_WUFC 0x05808 | ||
333 | #define IXGBE_WUS 0x05810 | ||
334 | #define IXGBE_IPAV 0x05838 | ||
335 | #define IXGBE_IP4AT 0x05840 /* IPv4 table 0x5840-0x5858 */ | ||
336 | #define IXGBE_IP6AT 0x05880 /* IPv6 table 0x5880-0x588F */ | ||
337 | |||
338 | #define IXGBE_WUPL 0x05900 | ||
339 | #define IXGBE_WUPM 0x05A00 /* wake up pkt memory 0x5A00-0x5A7C */ | ||
340 | #define IXGBE_FHFT(_n) (0x09000 + (_n * 0x100)) /* Flex host filter table */ | ||
341 | #define IXGBE_FHFT_EXT(_n) (0x09800 + (_n * 0x100)) /* Ext Flexible Host | ||
342 | * Filter Table */ | ||
343 | |||
344 | #define IXGBE_FLEXIBLE_FILTER_COUNT_MAX 4 | ||
345 | #define IXGBE_EXT_FLEXIBLE_FILTER_COUNT_MAX 2 | ||
346 | |||
347 | /* Each Flexible Filter is at most 128 (0x80) bytes in length */ | ||
348 | #define IXGBE_FLEXIBLE_FILTER_SIZE_MAX 128 | ||
349 | #define IXGBE_FHFT_LENGTH_OFFSET 0xFC /* Length byte in FHFT */ | ||
350 | #define IXGBE_FHFT_LENGTH_MASK 0x0FF /* Length in lower byte */ | ||
351 | |||
352 | /* Definitions for power management and wakeup registers */ | ||
353 | /* Wake Up Control */ | ||
354 | #define IXGBE_WUC_PME_EN 0x00000002 /* PME Enable */ | ||
355 | #define IXGBE_WUC_PME_STATUS 0x00000004 /* PME Status */ | ||
356 | #define IXGBE_WUC_WKEN 0x00000010 /* Enable PE_WAKE_N pin assertion */ | ||
357 | |||
358 | /* Wake Up Filter Control */ | ||
359 | #define IXGBE_WUFC_LNKC 0x00000001 /* Link Status Change Wakeup Enable */ | ||
360 | #define IXGBE_WUFC_MAG 0x00000002 /* Magic Packet Wakeup Enable */ | ||
361 | #define IXGBE_WUFC_EX 0x00000004 /* Directed Exact Wakeup Enable */ | ||
362 | #define IXGBE_WUFC_MC 0x00000008 /* Directed Multicast Wakeup Enable */ | ||
363 | #define IXGBE_WUFC_BC 0x00000010 /* Broadcast Wakeup Enable */ | ||
364 | #define IXGBE_WUFC_ARP 0x00000020 /* ARP Request Packet Wakeup Enable */ | ||
365 | #define IXGBE_WUFC_IPV4 0x00000040 /* Directed IPv4 Packet Wakeup Enable */ | ||
366 | #define IXGBE_WUFC_IPV6 0x00000080 /* Directed IPv6 Packet Wakeup Enable */ | ||
367 | #define IXGBE_WUFC_MNG 0x00000100 /* Directed Mgmt Packet Wakeup Enable */ | ||
368 | |||
369 | #define IXGBE_WUFC_IGNORE_TCO 0x00008000 /* Ignore WakeOn TCO packets */ | ||
370 | #define IXGBE_WUFC_FLX0 0x00010000 /* Flexible Filter 0 Enable */ | ||
371 | #define IXGBE_WUFC_FLX1 0x00020000 /* Flexible Filter 1 Enable */ | ||
372 | #define IXGBE_WUFC_FLX2 0x00040000 /* Flexible Filter 2 Enable */ | ||
373 | #define IXGBE_WUFC_FLX3 0x00080000 /* Flexible Filter 3 Enable */ | ||
374 | #define IXGBE_WUFC_FLX4 0x00100000 /* Flexible Filter 4 Enable */ | ||
375 | #define IXGBE_WUFC_FLX5 0x00200000 /* Flexible Filter 5 Enable */ | ||
376 | #define IXGBE_WUFC_FLX_FILTERS 0x000F0000 /* Mask for 4 flex filters */ | ||
377 | #define IXGBE_WUFC_EXT_FLX_FILTERS 0x00300000 /* Mask for Ext. flex filters */ | ||
378 | #define IXGBE_WUFC_ALL_FILTERS 0x003F00FF /* Mask for all wakeup filters */ | ||
379 | #define IXGBE_WUFC_FLX_OFFSET 16 /* Offset to the Flexible Filters bits */ | ||
380 | |||
381 | /* Wake Up Status */ | ||
382 | #define IXGBE_WUS_LNKC IXGBE_WUFC_LNKC | ||
383 | #define IXGBE_WUS_MAG IXGBE_WUFC_MAG | ||
384 | #define IXGBE_WUS_EX IXGBE_WUFC_EX | ||
385 | #define IXGBE_WUS_MC IXGBE_WUFC_MC | ||
386 | #define IXGBE_WUS_BC IXGBE_WUFC_BC | ||
387 | #define IXGBE_WUS_ARP IXGBE_WUFC_ARP | ||
388 | #define IXGBE_WUS_IPV4 IXGBE_WUFC_IPV4 | ||
389 | #define IXGBE_WUS_IPV6 IXGBE_WUFC_IPV6 | ||
390 | #define IXGBE_WUS_MNG IXGBE_WUFC_MNG | ||
391 | #define IXGBE_WUS_FLX0 IXGBE_WUFC_FLX0 | ||
392 | #define IXGBE_WUS_FLX1 IXGBE_WUFC_FLX1 | ||
393 | #define IXGBE_WUS_FLX2 IXGBE_WUFC_FLX2 | ||
394 | #define IXGBE_WUS_FLX3 IXGBE_WUFC_FLX3 | ||
395 | #define IXGBE_WUS_FLX4 IXGBE_WUFC_FLX4 | ||
396 | #define IXGBE_WUS_FLX5 IXGBE_WUFC_FLX5 | ||
397 | #define IXGBE_WUS_FLX_FILTERS IXGBE_WUFC_FLX_FILTERS | ||
398 | |||
399 | /* Wake Up Packet Length */ | ||
400 | #define IXGBE_WUPL_LENGTH_MASK 0xFFFF | ||
401 | |||
402 | /* DCB registers */ | ||
403 | #define IXGBE_RMCS 0x03D00 | ||
404 | #define IXGBE_DPMCS 0x07F40 | ||
405 | #define IXGBE_PDPMCS 0x0CD00 | ||
406 | #define IXGBE_RUPPBMR 0x050A0 | ||
407 | #define IXGBE_RT2CR(_i) (0x03C20 + ((_i) * 4)) /* 8 of these (0-7) */ | ||
408 | #define IXGBE_RT2SR(_i) (0x03C40 + ((_i) * 4)) /* 8 of these (0-7) */ | ||
409 | #define IXGBE_TDTQ2TCCR(_i) (0x0602C + ((_i) * 0x40)) /* 8 of these (0-7) */ | ||
410 | #define IXGBE_TDTQ2TCSR(_i) (0x0622C + ((_i) * 0x40)) /* 8 of these (0-7) */ | ||
411 | #define IXGBE_TDPT2TCCR(_i) (0x0CD20 + ((_i) * 4)) /* 8 of these (0-7) */ | ||
412 | #define IXGBE_TDPT2TCSR(_i) (0x0CD40 + ((_i) * 4)) /* 8 of these (0-7) */ | ||
413 | |||
414 | |||
415 | /* Security Control Registers */ | ||
416 | #define IXGBE_SECTXCTRL 0x08800 | ||
417 | #define IXGBE_SECTXSTAT 0x08804 | ||
418 | #define IXGBE_SECTXBUFFAF 0x08808 | ||
419 | #define IXGBE_SECTXMINIFG 0x08810 | ||
420 | #define IXGBE_SECRXCTRL 0x08D00 | ||
421 | #define IXGBE_SECRXSTAT 0x08D04 | ||
422 | |||
423 | /* Security Bit Fields and Masks */ | ||
424 | #define IXGBE_SECTXCTRL_SECTX_DIS 0x00000001 | ||
425 | #define IXGBE_SECTXCTRL_TX_DIS 0x00000002 | ||
426 | #define IXGBE_SECTXCTRL_STORE_FORWARD 0x00000004 | ||
427 | |||
428 | #define IXGBE_SECTXSTAT_SECTX_RDY 0x00000001 | ||
429 | #define IXGBE_SECTXSTAT_ECC_TXERR 0x00000002 | ||
430 | |||
431 | #define IXGBE_SECRXCTRL_SECRX_DIS 0x00000001 | ||
432 | #define IXGBE_SECRXCTRL_RX_DIS 0x00000002 | ||
433 | |||
434 | #define IXGBE_SECRXSTAT_SECRX_RDY 0x00000001 | ||
435 | #define IXGBE_SECRXSTAT_ECC_RXERR 0x00000002 | ||
436 | |||
437 | /* LinkSec (MacSec) Registers */ | ||
438 | #define IXGBE_LSECTXCAP 0x08A00 | ||
439 | #define IXGBE_LSECRXCAP 0x08F00 | ||
440 | #define IXGBE_LSECTXCTRL 0x08A04 | ||
441 | #define IXGBE_LSECTXSCL 0x08A08 /* SCI Low */ | ||
442 | #define IXGBE_LSECTXSCH 0x08A0C /* SCI High */ | ||
443 | #define IXGBE_LSECTXSA 0x08A10 | ||
444 | #define IXGBE_LSECTXPN0 0x08A14 | ||
445 | #define IXGBE_LSECTXPN1 0x08A18 | ||
446 | #define IXGBE_LSECTXKEY0(_n) (0x08A1C + (4 * (_n))) /* 4 of these (0-3) */ | ||
447 | #define IXGBE_LSECTXKEY1(_n) (0x08A2C + (4 * (_n))) /* 4 of these (0-3) */ | ||
448 | #define IXGBE_LSECRXCTRL 0x08F04 | ||
449 | #define IXGBE_LSECRXSCL 0x08F08 | ||
450 | #define IXGBE_LSECRXSCH 0x08F0C | ||
451 | #define IXGBE_LSECRXSA(_i) (0x08F10 + (4 * (_i))) /* 2 of these (0-1) */ | ||
452 | #define IXGBE_LSECRXPN(_i) (0x08F18 + (4 * (_i))) /* 2 of these (0-1) */ | ||
453 | #define IXGBE_LSECRXKEY(_n, _m) (0x08F20 + ((0x10 * (_n)) + (4 * (_m)))) | ||
454 | #define IXGBE_LSECTXUT 0x08A3C /* OutPktsUntagged */ | ||
455 | #define IXGBE_LSECTXPKTE 0x08A40 /* OutPktsEncrypted */ | ||
456 | #define IXGBE_LSECTXPKTP 0x08A44 /* OutPktsProtected */ | ||
457 | #define IXGBE_LSECTXOCTE 0x08A48 /* OutOctetsEncrypted */ | ||
458 | #define IXGBE_LSECTXOCTP 0x08A4C /* OutOctetsProtected */ | ||
459 | #define IXGBE_LSECRXUT 0x08F40 /* InPktsUntagged/InPktsNoTag */ | ||
460 | #define IXGBE_LSECRXOCTD 0x08F44 /* InOctetsDecrypted */ | ||
461 | #define IXGBE_LSECRXOCTV 0x08F48 /* InOctetsValidated */ | ||
462 | #define IXGBE_LSECRXBAD 0x08F4C /* InPktsBadTag */ | ||
463 | #define IXGBE_LSECRXNOSCI 0x08F50 /* InPktsNoSci */ | ||
464 | #define IXGBE_LSECRXUNSCI 0x08F54 /* InPktsUnknownSci */ | ||
465 | #define IXGBE_LSECRXUNCH 0x08F58 /* InPktsUnchecked */ | ||
466 | #define IXGBE_LSECRXDELAY 0x08F5C /* InPktsDelayed */ | ||
467 | #define IXGBE_LSECRXLATE 0x08F60 /* InPktsLate */ | ||
468 | #define IXGBE_LSECRXOK(_n) (0x08F64 + (0x04 * (_n))) /* InPktsOk */ | ||
469 | #define IXGBE_LSECRXINV(_n) (0x08F6C + (0x04 * (_n))) /* InPktsInvalid */ | ||
470 | #define IXGBE_LSECRXNV(_n) (0x08F74 + (0x04 * (_n))) /* InPktsNotValid */ | ||
471 | #define IXGBE_LSECRXUNSA 0x08F7C /* InPktsUnusedSa */ | ||
472 | #define IXGBE_LSECRXNUSA 0x08F80 /* InPktsNotUsingSa */ | ||
473 | |||
474 | /* LinkSec (MacSec) Bit Fields and Masks */ | ||
475 | #define IXGBE_LSECTXCAP_SUM_MASK 0x00FF0000 | ||
476 | #define IXGBE_LSECTXCAP_SUM_SHIFT 16 | ||
477 | #define IXGBE_LSECRXCAP_SUM_MASK 0x00FF0000 | ||
478 | #define IXGBE_LSECRXCAP_SUM_SHIFT 16 | ||
479 | |||
480 | #define IXGBE_LSECTXCTRL_EN_MASK 0x00000003 | ||
481 | #define IXGBE_LSECTXCTRL_DISABLE 0x0 | ||
482 | #define IXGBE_LSECTXCTRL_AUTH 0x1 | ||
483 | #define IXGBE_LSECTXCTRL_AUTH_ENCRYPT 0x2 | ||
484 | #define IXGBE_LSECTXCTRL_AISCI 0x00000020 | ||
485 | #define IXGBE_LSECTXCTRL_PNTHRSH_MASK 0xFFFFFF00 | ||
486 | #define IXGBE_LSECTXCTRL_RSV_MASK 0x000000D8 | ||
487 | |||
488 | #define IXGBE_LSECRXCTRL_EN_MASK 0x0000000C | ||
489 | #define IXGBE_LSECRXCTRL_EN_SHIFT 2 | ||
490 | #define IXGBE_LSECRXCTRL_DISABLE 0x0 | ||
491 | #define IXGBE_LSECRXCTRL_CHECK 0x1 | ||
492 | #define IXGBE_LSECRXCTRL_STRICT 0x2 | ||
493 | #define IXGBE_LSECRXCTRL_DROP 0x3 | ||
494 | #define IXGBE_LSECRXCTRL_PLSH 0x00000040 | ||
495 | #define IXGBE_LSECRXCTRL_RP 0x00000080 | ||
496 | #define IXGBE_LSECRXCTRL_RSV_MASK 0xFFFFFF33 | ||
497 | |||
498 | /* IpSec Registers */ | ||
499 | #define IXGBE_IPSTXIDX 0x08900 | ||
500 | #define IXGBE_IPSTXSALT 0x08904 | ||
501 | #define IXGBE_IPSTXKEY(_i) (0x08908 + (4 * (_i))) /* 4 of these (0-3) */ | ||
502 | #define IXGBE_IPSRXIDX 0x08E00 | ||
503 | #define IXGBE_IPSRXIPADDR(_i) (0x08E04 + (4 * (_i))) /* 4 of these (0-3) */ | ||
504 | #define IXGBE_IPSRXSPI 0x08E14 | ||
505 | #define IXGBE_IPSRXIPIDX 0x08E18 | ||
506 | #define IXGBE_IPSRXKEY(_i) (0x08E1C + (4 * (_i))) /* 4 of these (0-3) */ | ||
507 | #define IXGBE_IPSRXSALT 0x08E2C | ||
508 | #define IXGBE_IPSRXMOD 0x08E30 | ||
509 | |||
510 | #define IXGBE_SECTXCTRL_STORE_FORWARD_ENABLE 0x4 | ||
511 | |||
512 | /* DCB registers */ | ||
513 | #define IXGBE_RTRPCS 0x02430 | ||
514 | #define IXGBE_RTTDCS 0x04900 | ||
515 | #define IXGBE_RTTDCS_ARBDIS 0x00000040 /* DCB arbiter disable */ | ||
516 | #define IXGBE_RTTPCS 0x0CD00 | ||
517 | #define IXGBE_RTRUP2TC 0x03020 | ||
518 | #define IXGBE_RTTUP2TC 0x0C800 | ||
519 | #define IXGBE_RTRPT4C(_i) (0x02140 + ((_i) * 4)) /* 8 of these (0-7) */ | ||
520 | #define IXGBE_TXLLQ(_i) (0x082E0 + ((_i) * 4)) /* 4 of these (0-3) */ | ||
521 | #define IXGBE_RTRPT4S(_i) (0x02160 + ((_i) * 4)) /* 8 of these (0-7) */ | ||
522 | #define IXGBE_RTTDT2C(_i) (0x04910 + ((_i) * 4)) /* 8 of these (0-7) */ | ||
523 | #define IXGBE_RTTDT2S(_i) (0x04930 + ((_i) * 4)) /* 8 of these (0-7) */ | ||
524 | #define IXGBE_RTTPT2C(_i) (0x0CD20 + ((_i) * 4)) /* 8 of these (0-7) */ | ||
525 | #define IXGBE_RTTPT2S(_i) (0x0CD40 + ((_i) * 4)) /* 8 of these (0-7) */ | ||
526 | #define IXGBE_RTTDQSEL 0x04904 | ||
527 | #define IXGBE_RTTDT1C 0x04908 | ||
528 | #define IXGBE_RTTDT1S 0x0490C | ||
529 | #define IXGBE_RTTDTECC 0x04990 | ||
530 | #define IXGBE_RTTDTECC_NO_BCN 0x00000100 | ||
531 | #define IXGBE_RTTBCNRC 0x04984 | ||
532 | #define IXGBE_RTTBCNRC_RS_ENA 0x80000000 | ||
533 | #define IXGBE_RTTBCNRC_RF_DEC_MASK 0x00003FFF | ||
534 | #define IXGBE_RTTBCNRC_RF_INT_SHIFT 14 | ||
535 | #define IXGBE_RTTBCNRC_RF_INT_MASK \ | ||
536 | (IXGBE_RTTBCNRC_RF_DEC_MASK << IXGBE_RTTBCNRC_RF_INT_SHIFT) | ||
537 | #define IXGBE_RTTBCNRM 0x04980 | ||
538 | |||
539 | /* FCoE DMA Context Registers */ | ||
540 | #define IXGBE_FCPTRL 0x02410 /* FC User Desc. PTR Low */ | ||
541 | #define IXGBE_FCPTRH 0x02414 /* FC USer Desc. PTR High */ | ||
542 | #define IXGBE_FCBUFF 0x02418 /* FC Buffer Control */ | ||
543 | #define IXGBE_FCDMARW 0x02420 /* FC Receive DMA RW */ | ||
544 | #define IXGBE_FCINVST0 0x03FC0 /* FC Invalid DMA Context Status Reg 0 */ | ||
545 | #define IXGBE_FCINVST(_i) (IXGBE_FCINVST0 + ((_i) * 4)) | ||
546 | #define IXGBE_FCBUFF_VALID (1 << 0) /* DMA Context Valid */ | ||
547 | #define IXGBE_FCBUFF_BUFFSIZE (3 << 3) /* User Buffer Size */ | ||
548 | #define IXGBE_FCBUFF_WRCONTX (1 << 7) /* 0: Initiator, 1: Target */ | ||
549 | #define IXGBE_FCBUFF_BUFFCNT 0x0000ff00 /* Number of User Buffers */ | ||
550 | #define IXGBE_FCBUFF_OFFSET 0xffff0000 /* User Buffer Offset */ | ||
551 | #define IXGBE_FCBUFF_BUFFSIZE_SHIFT 3 | ||
552 | #define IXGBE_FCBUFF_BUFFCNT_SHIFT 8 | ||
553 | #define IXGBE_FCBUFF_OFFSET_SHIFT 16 | ||
554 | #define IXGBE_FCDMARW_WE (1 << 14) /* Write enable */ | ||
555 | #define IXGBE_FCDMARW_RE (1 << 15) /* Read enable */ | ||
556 | #define IXGBE_FCDMARW_FCOESEL 0x000001ff /* FC X_ID: 11 bits */ | ||
557 | #define IXGBE_FCDMARW_LASTSIZE 0xffff0000 /* Last User Buffer Size */ | ||
558 | #define IXGBE_FCDMARW_LASTSIZE_SHIFT 16 | ||
559 | |||
560 | /* FCoE SOF/EOF */ | ||
561 | #define IXGBE_TEOFF 0x04A94 /* Tx FC EOF */ | ||
562 | #define IXGBE_TSOFF 0x04A98 /* Tx FC SOF */ | ||
563 | #define IXGBE_REOFF 0x05158 /* Rx FC EOF */ | ||
564 | #define IXGBE_RSOFF 0x051F8 /* Rx FC SOF */ | ||
565 | /* FCoE Filter Context Registers */ | ||
566 | #define IXGBE_FCFLT 0x05108 /* FC FLT Context */ | ||
567 | #define IXGBE_FCFLTRW 0x05110 /* FC Filter RW Control */ | ||
568 | #define IXGBE_FCPARAM 0x051d8 /* FC Offset Parameter */ | ||
569 | #define IXGBE_FCFLT_VALID (1 << 0) /* Filter Context Valid */ | ||
570 | #define IXGBE_FCFLT_FIRST (1 << 1) /* Filter First */ | ||
571 | #define IXGBE_FCFLT_SEQID 0x00ff0000 /* Sequence ID */ | ||
572 | #define IXGBE_FCFLT_SEQCNT 0xff000000 /* Sequence Count */ | ||
573 | #define IXGBE_FCFLTRW_RVALDT (1 << 13) /* Fast Re-Validation */ | ||
574 | #define IXGBE_FCFLTRW_WE (1 << 14) /* Write Enable */ | ||
575 | #define IXGBE_FCFLTRW_RE (1 << 15) /* Read Enable */ | ||
576 | /* FCoE Receive Control */ | ||
577 | #define IXGBE_FCRXCTRL 0x05100 /* FC Receive Control */ | ||
578 | #define IXGBE_FCRXCTRL_FCOELLI (1 << 0) /* Low latency interrupt */ | ||
579 | #define IXGBE_FCRXCTRL_SAVBAD (1 << 1) /* Save Bad Frames */ | ||
580 | #define IXGBE_FCRXCTRL_FRSTRDH (1 << 2) /* EN 1st Read Header */ | ||
581 | #define IXGBE_FCRXCTRL_LASTSEQH (1 << 3) /* EN Last Header in Seq */ | ||
582 | #define IXGBE_FCRXCTRL_ALLH (1 << 4) /* EN All Headers */ | ||
583 | #define IXGBE_FCRXCTRL_FRSTSEQH (1 << 5) /* EN 1st Seq. Header */ | ||
584 | #define IXGBE_FCRXCTRL_ICRC (1 << 6) /* Ignore Bad FC CRC */ | ||
585 | #define IXGBE_FCRXCTRL_FCCRCBO (1 << 7) /* FC CRC Byte Ordering */ | ||
586 | #define IXGBE_FCRXCTRL_FCOEVER 0x00000f00 /* FCoE Version: 4 bits */ | ||
587 | #define IXGBE_FCRXCTRL_FCOEVER_SHIFT 8 | ||
588 | /* FCoE Redirection */ | ||
589 | #define IXGBE_FCRECTL 0x0ED00 /* FC Redirection Control */ | ||
590 | #define IXGBE_FCRETA0 0x0ED10 /* FC Redirection Table 0 */ | ||
591 | #define IXGBE_FCRETA(_i) (IXGBE_FCRETA0 + ((_i) * 4)) /* FCoE Redir */ | ||
592 | #define IXGBE_FCRECTL_ENA 0x1 /* FCoE Redir Table Enable */ | ||
593 | #define IXGBE_FCRETA_SIZE 8 /* Max entries in FCRETA */ | ||
594 | #define IXGBE_FCRETA_ENTRY_MASK 0x0000007f /* 7 bits for the queue index */ | ||
595 | |||
596 | /* Stats registers */ | ||
597 | #define IXGBE_CRCERRS 0x04000 | ||
598 | #define IXGBE_ILLERRC 0x04004 | ||
599 | #define IXGBE_ERRBC 0x04008 | ||
600 | #define IXGBE_MSPDC 0x04010 | ||
601 | #define IXGBE_MPC(_i) (0x03FA0 + ((_i) * 4)) /* 8 of these 3FA0-3FBC*/ | ||
602 | #define IXGBE_MLFC 0x04034 | ||
603 | #define IXGBE_MRFC 0x04038 | ||
604 | #define IXGBE_RLEC 0x04040 | ||
605 | #define IXGBE_LXONTXC 0x03F60 | ||
606 | #define IXGBE_LXONRXC 0x0CF60 | ||
607 | #define IXGBE_LXOFFTXC 0x03F68 | ||
608 | #define IXGBE_LXOFFRXC 0x0CF68 | ||
609 | #define IXGBE_LXONRXCNT 0x041A4 | ||
610 | #define IXGBE_LXOFFRXCNT 0x041A8 | ||
611 | #define IXGBE_PXONRXCNT(_i) (0x04140 + ((_i) * 4)) /* 8 of these */ | ||
612 | #define IXGBE_PXOFFRXCNT(_i) (0x04160 + ((_i) * 4)) /* 8 of these */ | ||
613 | #define IXGBE_PXON2OFFCNT(_i) (0x03240 + ((_i) * 4)) /* 8 of these */ | ||
614 | #define IXGBE_PXONTXC(_i) (0x03F00 + ((_i) * 4)) /* 8 of these 3F00-3F1C*/ | ||
615 | #define IXGBE_PXONRXC(_i) (0x0CF00 + ((_i) * 4)) /* 8 of these CF00-CF1C*/ | ||
616 | #define IXGBE_PXOFFTXC(_i) (0x03F20 + ((_i) * 4)) /* 8 of these 3F20-3F3C*/ | ||
617 | #define IXGBE_PXOFFRXC(_i) (0x0CF20 + ((_i) * 4)) /* 8 of these CF20-CF3C*/ | ||
618 | #define IXGBE_PRC64 0x0405C | ||
619 | #define IXGBE_PRC127 0x04060 | ||
620 | #define IXGBE_PRC255 0x04064 | ||
621 | #define IXGBE_PRC511 0x04068 | ||
622 | #define IXGBE_PRC1023 0x0406C | ||
623 | #define IXGBE_PRC1522 0x04070 | ||
624 | #define IXGBE_GPRC 0x04074 | ||
625 | #define IXGBE_BPRC 0x04078 | ||
626 | #define IXGBE_MPRC 0x0407C | ||
627 | #define IXGBE_GPTC 0x04080 | ||
628 | #define IXGBE_GORCL 0x04088 | ||
629 | #define IXGBE_GORCH 0x0408C | ||
630 | #define IXGBE_GOTCL 0x04090 | ||
631 | #define IXGBE_GOTCH 0x04094 | ||
632 | #define IXGBE_RNBC(_i) (0x03FC0 + ((_i) * 4)) /* 8 of these 3FC0-3FDC*/ | ||
633 | #define IXGBE_RUC 0x040A4 | ||
634 | #define IXGBE_RFC 0x040A8 | ||
635 | #define IXGBE_ROC 0x040AC | ||
636 | #define IXGBE_RJC 0x040B0 | ||
637 | #define IXGBE_MNGPRC 0x040B4 | ||
638 | #define IXGBE_MNGPDC 0x040B8 | ||
639 | #define IXGBE_MNGPTC 0x0CF90 | ||
640 | #define IXGBE_TORL 0x040C0 | ||
641 | #define IXGBE_TORH 0x040C4 | ||
642 | #define IXGBE_TPR 0x040D0 | ||
643 | #define IXGBE_TPT 0x040D4 | ||
644 | #define IXGBE_PTC64 0x040D8 | ||
645 | #define IXGBE_PTC127 0x040DC | ||
646 | #define IXGBE_PTC255 0x040E0 | ||
647 | #define IXGBE_PTC511 0x040E4 | ||
648 | #define IXGBE_PTC1023 0x040E8 | ||
649 | #define IXGBE_PTC1522 0x040EC | ||
650 | #define IXGBE_MPTC 0x040F0 | ||
651 | #define IXGBE_BPTC 0x040F4 | ||
652 | #define IXGBE_XEC 0x04120 | ||
653 | #define IXGBE_SSVPC 0x08780 | ||
654 | |||
655 | #define IXGBE_RQSMR(_i) (0x02300 + ((_i) * 4)) | ||
656 | #define IXGBE_TQSMR(_i) (((_i) <= 7) ? (0x07300 + ((_i) * 4)) : \ | ||
657 | (0x08600 + ((_i) * 4))) | ||
658 | #define IXGBE_TQSM(_i) (0x08600 + ((_i) * 4)) | ||
659 | |||
660 | #define IXGBE_QPRC(_i) (0x01030 + ((_i) * 0x40)) /* 16 of these */ | ||
661 | #define IXGBE_QPTC(_i) (0x06030 + ((_i) * 0x40)) /* 16 of these */ | ||
662 | #define IXGBE_QBRC(_i) (0x01034 + ((_i) * 0x40)) /* 16 of these */ | ||
663 | #define IXGBE_QBTC(_i) (0x06034 + ((_i) * 0x40)) /* 16 of these */ | ||
664 | #define IXGBE_QBRC_L(_i) (0x01034 + ((_i) * 0x40)) /* 16 of these */ | ||
665 | #define IXGBE_QBRC_H(_i) (0x01038 + ((_i) * 0x40)) /* 16 of these */ | ||
666 | #define IXGBE_QPRDC(_i) (0x01430 + ((_i) * 0x40)) /* 16 of these */ | ||
667 | #define IXGBE_QBTC_L(_i) (0x08700 + ((_i) * 0x8)) /* 16 of these */ | ||
668 | #define IXGBE_QBTC_H(_i) (0x08704 + ((_i) * 0x8)) /* 16 of these */ | ||
669 | #define IXGBE_FCCRC 0x05118 /* Count of Good Eth CRC w/ Bad FC CRC */ | ||
670 | #define IXGBE_FCOERPDC 0x0241C /* FCoE Rx Packets Dropped Count */ | ||
671 | #define IXGBE_FCLAST 0x02424 /* FCoE Last Error Count */ | ||
672 | #define IXGBE_FCOEPRC 0x02428 /* Number of FCoE Packets Received */ | ||
673 | #define IXGBE_FCOEDWRC 0x0242C /* Number of FCoE DWords Received */ | ||
674 | #define IXGBE_FCOEPTC 0x08784 /* Number of FCoE Packets Transmitted */ | ||
675 | #define IXGBE_FCOEDWTC 0x08788 /* Number of FCoE DWords Transmitted */ | ||
676 | #define IXGBE_O2BGPTC 0x041C4 | ||
677 | #define IXGBE_O2BSPC 0x087B0 | ||
678 | #define IXGBE_B2OSPC 0x041C0 | ||
679 | #define IXGBE_B2OGPRC 0x02F90 | ||
680 | #define IXGBE_PCRC8ECL 0x0E810 | ||
681 | #define IXGBE_PCRC8ECH 0x0E811 | ||
682 | #define IXGBE_PCRC8ECH_MASK 0x1F | ||
683 | #define IXGBE_LDPCECL 0x0E820 | ||
684 | #define IXGBE_LDPCECH 0x0E821 | ||
685 | |||
686 | /* Management */ | ||
687 | #define IXGBE_MAVTV(_i) (0x05010 + ((_i) * 4)) /* 8 of these (0-7) */ | ||
688 | #define IXGBE_MFUTP(_i) (0x05030 + ((_i) * 4)) /* 8 of these (0-7) */ | ||
689 | #define IXGBE_MANC 0x05820 | ||
690 | #define IXGBE_MFVAL 0x05824 | ||
691 | #define IXGBE_MANC2H 0x05860 | ||
692 | #define IXGBE_MDEF(_i) (0x05890 + ((_i) * 4)) /* 8 of these (0-7) */ | ||
693 | #define IXGBE_MIPAF 0x058B0 | ||
694 | #define IXGBE_MMAL(_i) (0x05910 + ((_i) * 8)) /* 4 of these (0-3) */ | ||
695 | #define IXGBE_MMAH(_i) (0x05914 + ((_i) * 8)) /* 4 of these (0-3) */ | ||
696 | #define IXGBE_FTFT 0x09400 /* 0x9400-0x97FC */ | ||
697 | #define IXGBE_METF(_i) (0x05190 + ((_i) * 4)) /* 4 of these (0-3) */ | ||
698 | #define IXGBE_MDEF_EXT(_i) (0x05160 + ((_i) * 4)) /* 8 of these (0-7) */ | ||
699 | #define IXGBE_LSWFW 0x15014 | ||
700 | |||
701 | /* ARC Subsystem registers */ | ||
702 | #define IXGBE_HICR 0x15F00 | ||
703 | #define IXGBE_FWSTS 0x15F0C | ||
704 | #define IXGBE_HSMC0R 0x15F04 | ||
705 | #define IXGBE_HSMC1R 0x15F08 | ||
706 | #define IXGBE_SWSR 0x15F10 | ||
707 | #define IXGBE_HFDR 0x15FE8 | ||
708 | #define IXGBE_FLEX_MNG 0x15800 /* 0x15800 - 0x15EFC */ | ||
709 | |||
710 | #define IXGBE_HICR_EN 0x01 /* Enable bit - RO */ | ||
711 | /* Driver sets this bit when done to put command in RAM */ | ||
712 | #define IXGBE_HICR_C 0x02 | ||
713 | #define IXGBE_HICR_SV 0x04 /* Status Validity */ | ||
714 | #define IXGBE_HICR_FW_RESET_ENABLE 0x40 | ||
715 | #define IXGBE_HICR_FW_RESET 0x80 | ||
716 | |||
717 | /* PCI-E registers */ | ||
718 | #define IXGBE_GCR 0x11000 | ||
719 | #define IXGBE_GTV 0x11004 | ||
720 | #define IXGBE_FUNCTAG 0x11008 | ||
721 | #define IXGBE_GLT 0x1100C | ||
722 | #define IXGBE_GSCL_1 0x11010 | ||
723 | #define IXGBE_GSCL_2 0x11014 | ||
724 | #define IXGBE_GSCL_3 0x11018 | ||
725 | #define IXGBE_GSCL_4 0x1101C | ||
726 | #define IXGBE_GSCN_0 0x11020 | ||
727 | #define IXGBE_GSCN_1 0x11024 | ||
728 | #define IXGBE_GSCN_2 0x11028 | ||
729 | #define IXGBE_GSCN_3 0x1102C | ||
730 | #define IXGBE_FACTPS 0x10150 | ||
731 | #define IXGBE_PCIEANACTL 0x11040 | ||
732 | #define IXGBE_SWSM 0x10140 | ||
733 | #define IXGBE_FWSM 0x10148 | ||
734 | #define IXGBE_GSSR 0x10160 | ||
735 | #define IXGBE_MREVID 0x11064 | ||
736 | #define IXGBE_DCA_ID 0x11070 | ||
737 | #define IXGBE_DCA_CTRL 0x11074 | ||
738 | #define IXGBE_SWFW_SYNC IXGBE_GSSR | ||
739 | |||
740 | /* PCIe registers 82599-specific */ | ||
741 | #define IXGBE_GCR_EXT 0x11050 | ||
742 | #define IXGBE_GSCL_5_82599 0x11030 | ||
743 | #define IXGBE_GSCL_6_82599 0x11034 | ||
744 | #define IXGBE_GSCL_7_82599 0x11038 | ||
745 | #define IXGBE_GSCL_8_82599 0x1103C | ||
746 | #define IXGBE_PHYADR_82599 0x11040 | ||
747 | #define IXGBE_PHYDAT_82599 0x11044 | ||
748 | #define IXGBE_PHYCTL_82599 0x11048 | ||
749 | #define IXGBE_PBACLR_82599 0x11068 | ||
750 | #define IXGBE_CIAA_82599 0x11088 | ||
751 | #define IXGBE_CIAD_82599 0x1108C | ||
752 | #define IXGBE_PICAUSE 0x110B0 | ||
753 | #define IXGBE_PIENA 0x110B8 | ||
754 | #define IXGBE_CDQ_MBR_82599 0x110B4 | ||
755 | #define IXGBE_PCIESPARE 0x110BC | ||
756 | #define IXGBE_MISC_REG_82599 0x110F0 | ||
757 | #define IXGBE_ECC_CTRL_0_82599 0x11100 | ||
758 | #define IXGBE_ECC_CTRL_1_82599 0x11104 | ||
759 | #define IXGBE_ECC_STATUS_82599 0x110E0 | ||
760 | #define IXGBE_BAR_CTRL_82599 0x110F4 | ||
761 | |||
762 | /* PCI Express Control */ | ||
763 | #define IXGBE_GCR_CMPL_TMOUT_MASK 0x0000F000 | ||
764 | #define IXGBE_GCR_CMPL_TMOUT_10ms 0x00001000 | ||
765 | #define IXGBE_GCR_CMPL_TMOUT_RESEND 0x00010000 | ||
766 | #define IXGBE_GCR_CAP_VER2 0x00040000 | ||
767 | |||
768 | #define IXGBE_GCR_EXT_MSIX_EN 0x80000000 | ||
769 | #define IXGBE_GCR_EXT_VT_MODE_16 0x00000001 | ||
770 | #define IXGBE_GCR_EXT_VT_MODE_32 0x00000002 | ||
771 | #define IXGBE_GCR_EXT_VT_MODE_64 0x00000003 | ||
772 | #define IXGBE_GCR_EXT_SRIOV (IXGBE_GCR_EXT_MSIX_EN | \ | ||
773 | IXGBE_GCR_EXT_VT_MODE_64) | ||
774 | |||
775 | /* Time Sync Registers */ | ||
776 | #define IXGBE_TSYNCRXCTL 0x05188 /* Rx Time Sync Control register - RW */ | ||
777 | #define IXGBE_TSYNCTXCTL 0x08C00 /* Tx Time Sync Control register - RW */ | ||
778 | #define IXGBE_RXSTMPL 0x051E8 /* Rx timestamp Low - RO */ | ||
779 | #define IXGBE_RXSTMPH 0x051A4 /* Rx timestamp High - RO */ | ||
780 | #define IXGBE_RXSATRL 0x051A0 /* Rx timestamp attribute low - RO */ | ||
781 | #define IXGBE_RXSATRH 0x051A8 /* Rx timestamp attribute high - RO */ | ||
782 | #define IXGBE_RXMTRL 0x05120 /* RX message type register low - RW */ | ||
783 | #define IXGBE_TXSTMPL 0x08C04 /* Tx timestamp value Low - RO */ | ||
784 | #define IXGBE_TXSTMPH 0x08C08 /* Tx timestamp value High - RO */ | ||
785 | #define IXGBE_SYSTIML 0x08C0C /* System time register Low - RO */ | ||
786 | #define IXGBE_SYSTIMH 0x08C10 /* System time register High - RO */ | ||
787 | #define IXGBE_TIMINCA 0x08C14 /* Increment attributes register - RW */ | ||
788 | #define IXGBE_TIMADJL 0x08C18 /* Time Adjustment Offset register Low - RW */ | ||
789 | #define IXGBE_TIMADJH 0x08C1C /* Time Adjustment Offset register High - RW */ | ||
790 | #define IXGBE_TSAUXC 0x08C20 /* TimeSync Auxiliary Control register - RW */ | ||
791 | #define IXGBE_TRGTTIML0 0x08C24 /* Target Time Register 0 Low - RW */ | ||
792 | #define IXGBE_TRGTTIMH0 0x08C28 /* Target Time Register 0 High - RW */ | ||
793 | #define IXGBE_TRGTTIML1 0x08C2C /* Target Time Register 1 Low - RW */ | ||
794 | #define IXGBE_TRGTTIMH1 0x08C30 /* Target Time Register 1 High - RW */ | ||
795 | #define IXGBE_FREQOUT0 0x08C34 /* Frequency Out 0 Control register - RW */ | ||
796 | #define IXGBE_FREQOUT1 0x08C38 /* Frequency Out 1 Control register - RW */ | ||
797 | #define IXGBE_AUXSTMPL0 0x08C3C /* Auxiliary Time Stamp 0 register Low - RO */ | ||
798 | #define IXGBE_AUXSTMPH0 0x08C40 /* Auxiliary Time Stamp 0 register High - RO */ | ||
799 | #define IXGBE_AUXSTMPL1 0x08C44 /* Auxiliary Time Stamp 1 register Low - RO */ | ||
800 | #define IXGBE_AUXSTMPH1 0x08C48 /* Auxiliary Time Stamp 1 register High - RO */ | ||
801 | |||
802 | /* Diagnostic Registers */ | ||
803 | #define IXGBE_RDSTATCTL 0x02C20 | ||
804 | #define IXGBE_RDSTAT(_i) (0x02C00 + ((_i) * 4)) /* 0x02C00-0x02C1C */ | ||
805 | #define IXGBE_RDHMPN 0x02F08 | ||
806 | #define IXGBE_RIC_DW(_i) (0x02F10 + ((_i) * 4)) | ||
807 | #define IXGBE_RDPROBE 0x02F20 | ||
808 | #define IXGBE_RDMAM 0x02F30 | ||
809 | #define IXGBE_RDMAD 0x02F34 | ||
810 | #define IXGBE_TDSTATCTL 0x07C20 | ||
811 | #define IXGBE_TDSTAT(_i) (0x07C00 + ((_i) * 4)) /* 0x07C00 - 0x07C1C */ | ||
812 | #define IXGBE_TDHMPN 0x07F08 | ||
813 | #define IXGBE_TDHMPN2 0x082FC | ||
814 | #define IXGBE_TXDESCIC 0x082CC | ||
815 | #define IXGBE_TIC_DW(_i) (0x07F10 + ((_i) * 4)) | ||
816 | #define IXGBE_TIC_DW2(_i) (0x082B0 + ((_i) * 4)) | ||
817 | #define IXGBE_TDPROBE 0x07F20 | ||
818 | #define IXGBE_TXBUFCTRL 0x0C600 | ||
819 | #define IXGBE_TXBUFDATA0 0x0C610 | ||
820 | #define IXGBE_TXBUFDATA1 0x0C614 | ||
821 | #define IXGBE_TXBUFDATA2 0x0C618 | ||
822 | #define IXGBE_TXBUFDATA3 0x0C61C | ||
823 | #define IXGBE_RXBUFCTRL 0x03600 | ||
824 | #define IXGBE_RXBUFDATA0 0x03610 | ||
825 | #define IXGBE_RXBUFDATA1 0x03614 | ||
826 | #define IXGBE_RXBUFDATA2 0x03618 | ||
827 | #define IXGBE_RXBUFDATA3 0x0361C | ||
828 | #define IXGBE_PCIE_DIAG(_i) (0x11090 + ((_i) * 4)) /* 8 of these */ | ||
829 | #define IXGBE_RFVAL 0x050A4 | ||
830 | #define IXGBE_MDFTC1 0x042B8 | ||
831 | #define IXGBE_MDFTC2 0x042C0 | ||
832 | #define IXGBE_MDFTFIFO1 0x042C4 | ||
833 | #define IXGBE_MDFTFIFO2 0x042C8 | ||
834 | #define IXGBE_MDFTS 0x042CC | ||
835 | #define IXGBE_RXDATAWRPTR(_i) (0x03700 + ((_i) * 4)) /* 8 of these 3700-370C*/ | ||
836 | #define IXGBE_RXDESCWRPTR(_i) (0x03710 + ((_i) * 4)) /* 8 of these 3710-371C*/ | ||
837 | #define IXGBE_RXDATARDPTR(_i) (0x03720 + ((_i) * 4)) /* 8 of these 3720-372C*/ | ||
838 | #define IXGBE_RXDESCRDPTR(_i) (0x03730 + ((_i) * 4)) /* 8 of these 3730-373C*/ | ||
839 | #define IXGBE_TXDATAWRPTR(_i) (0x0C700 + ((_i) * 4)) /* 8 of these C700-C70C*/ | ||
840 | #define IXGBE_TXDESCWRPTR(_i) (0x0C710 + ((_i) * 4)) /* 8 of these C710-C71C*/ | ||
841 | #define IXGBE_TXDATARDPTR(_i) (0x0C720 + ((_i) * 4)) /* 8 of these C720-C72C*/ | ||
842 | #define IXGBE_TXDESCRDPTR(_i) (0x0C730 + ((_i) * 4)) /* 8 of these C730-C73C*/ | ||
843 | #define IXGBE_PCIEECCCTL 0x1106C | ||
844 | #define IXGBE_RXWRPTR(_i) (0x03100 + ((_i) * 4)) /* 8 of these 3100-310C*/ | ||
845 | #define IXGBE_RXUSED(_i) (0x03120 + ((_i) * 4)) /* 8 of these 3120-312C*/ | ||
846 | #define IXGBE_RXRDPTR(_i) (0x03140 + ((_i) * 4)) /* 8 of these 3140-314C*/ | ||
847 | #define IXGBE_RXRDWRPTR(_i) (0x03160 + ((_i) * 4)) /* 8 of these 3160-310C*/ | ||
848 | #define IXGBE_TXWRPTR(_i) (0x0C100 + ((_i) * 4)) /* 8 of these C100-C10C*/ | ||
849 | #define IXGBE_TXUSED(_i) (0x0C120 + ((_i) * 4)) /* 8 of these C120-C12C*/ | ||
850 | #define IXGBE_TXRDPTR(_i) (0x0C140 + ((_i) * 4)) /* 8 of these C140-C14C*/ | ||
851 | #define IXGBE_TXRDWRPTR(_i) (0x0C160 + ((_i) * 4)) /* 8 of these C160-C10C*/ | ||
852 | #define IXGBE_PCIEECCCTL0 0x11100 | ||
853 | #define IXGBE_PCIEECCCTL1 0x11104 | ||
854 | #define IXGBE_RXDBUECC 0x03F70 | ||
855 | #define IXGBE_TXDBUECC 0x0CF70 | ||
856 | #define IXGBE_RXDBUEST 0x03F74 | ||
857 | #define IXGBE_TXDBUEST 0x0CF74 | ||
858 | #define IXGBE_PBTXECC 0x0C300 | ||
859 | #define IXGBE_PBRXECC 0x03300 | ||
860 | #define IXGBE_GHECCR 0x110B0 | ||
861 | |||
862 | /* MAC Registers */ | ||
863 | #define IXGBE_PCS1GCFIG 0x04200 | ||
864 | #define IXGBE_PCS1GLCTL 0x04208 | ||
865 | #define IXGBE_PCS1GLSTA 0x0420C | ||
866 | #define IXGBE_PCS1GDBG0 0x04210 | ||
867 | #define IXGBE_PCS1GDBG1 0x04214 | ||
868 | #define IXGBE_PCS1GANA 0x04218 | ||
869 | #define IXGBE_PCS1GANLP 0x0421C | ||
870 | #define IXGBE_PCS1GANNP 0x04220 | ||
871 | #define IXGBE_PCS1GANLPNP 0x04224 | ||
872 | #define IXGBE_HLREG0 0x04240 | ||
873 | #define IXGBE_HLREG1 0x04244 | ||
874 | #define IXGBE_PAP 0x04248 | ||
875 | #define IXGBE_MACA 0x0424C | ||
876 | #define IXGBE_APAE 0x04250 | ||
877 | #define IXGBE_ARD 0x04254 | ||
878 | #define IXGBE_AIS 0x04258 | ||
879 | #define IXGBE_MSCA 0x0425C | ||
880 | #define IXGBE_MSRWD 0x04260 | ||
881 | #define IXGBE_MLADD 0x04264 | ||
882 | #define IXGBE_MHADD 0x04268 | ||
883 | #define IXGBE_MAXFRS 0x04268 | ||
884 | #define IXGBE_TREG 0x0426C | ||
885 | #define IXGBE_PCSS1 0x04288 | ||
886 | #define IXGBE_PCSS2 0x0428C | ||
887 | #define IXGBE_XPCSS 0x04290 | ||
888 | #define IXGBE_MFLCN 0x04294 | ||
889 | #define IXGBE_SERDESC 0x04298 | ||
890 | #define IXGBE_MACS 0x0429C | ||
891 | #define IXGBE_AUTOC 0x042A0 | ||
892 | #define IXGBE_LINKS 0x042A4 | ||
893 | #define IXGBE_LINKS2 0x04324 | ||
894 | #define IXGBE_AUTOC2 0x042A8 | ||
895 | #define IXGBE_AUTOC3 0x042AC | ||
896 | #define IXGBE_ANLP1 0x042B0 | ||
897 | #define IXGBE_ANLP2 0x042B4 | ||
898 | #define IXGBE_MACC 0x04330 | ||
899 | #define IXGBE_ATLASCTL 0x04800 | ||
900 | #define IXGBE_MMNGC 0x042D0 | ||
901 | #define IXGBE_ANLPNP1 0x042D4 | ||
902 | #define IXGBE_ANLPNP2 0x042D8 | ||
903 | #define IXGBE_KRPCSFC 0x042E0 | ||
904 | #define IXGBE_KRPCSS 0x042E4 | ||
905 | #define IXGBE_FECS1 0x042E8 | ||
906 | #define IXGBE_FECS2 0x042EC | ||
907 | #define IXGBE_SMADARCTL 0x14F10 | ||
908 | #define IXGBE_MPVC 0x04318 | ||
909 | #define IXGBE_SGMIIC 0x04314 | ||
910 | |||
911 | /* Statistics Registers */ | ||
912 | #define IXGBE_RXNFGPC 0x041B0 | ||
913 | #define IXGBE_RXNFGBCL 0x041B4 | ||
914 | #define IXGBE_RXNFGBCH 0x041B8 | ||
915 | #define IXGBE_RXDGPC 0x02F50 | ||
916 | #define IXGBE_RXDGBCL 0x02F54 | ||
917 | #define IXGBE_RXDGBCH 0x02F58 | ||
918 | #define IXGBE_RXDDGPC 0x02F5C | ||
919 | #define IXGBE_RXDDGBCL 0x02F60 | ||
920 | #define IXGBE_RXDDGBCH 0x02F64 | ||
921 | #define IXGBE_RXLPBKGPC 0x02F68 | ||
922 | #define IXGBE_RXLPBKGBCL 0x02F6C | ||
923 | #define IXGBE_RXLPBKGBCH 0x02F70 | ||
924 | #define IXGBE_RXDLPBKGPC 0x02F74 | ||
925 | #define IXGBE_RXDLPBKGBCL 0x02F78 | ||
926 | #define IXGBE_RXDLPBKGBCH 0x02F7C | ||
927 | #define IXGBE_TXDGPC 0x087A0 | ||
928 | #define IXGBE_TXDGBCL 0x087A4 | ||
929 | #define IXGBE_TXDGBCH 0x087A8 | ||
930 | |||
931 | #define IXGBE_RXDSTATCTRL 0x02F40 | ||
932 | |||
933 | /* Copper Pond 2 link timeout */ | ||
934 | #define IXGBE_VALIDATE_LINK_READY_TIMEOUT 50 | ||
935 | |||
936 | /* Omer CORECTL */ | ||
937 | #define IXGBE_CORECTL 0x014F00 | ||
938 | /* BARCTRL */ | ||
939 | #define IXGBE_BARCTRL 0x110F4 | ||
940 | #define IXGBE_BARCTRL_FLSIZE 0x0700 | ||
941 | #define IXGBE_BARCTRL_FLSIZE_SHIFT 8 | ||
942 | #define IXGBE_BARCTRL_CSRSIZE 0x2000 | ||
943 | |||
944 | /* RSCCTL Bit Masks */ | ||
945 | #define IXGBE_RSCCTL_RSCEN 0x01 | ||
946 | #define IXGBE_RSCCTL_MAXDESC_1 0x00 | ||
947 | #define IXGBE_RSCCTL_MAXDESC_4 0x04 | ||
948 | #define IXGBE_RSCCTL_MAXDESC_8 0x08 | ||
949 | #define IXGBE_RSCCTL_MAXDESC_16 0x0C | ||
950 | |||
951 | /* RSCDBU Bit Masks */ | ||
952 | #define IXGBE_RSCDBU_RSCSMALDIS_MASK 0x0000007F | ||
953 | #define IXGBE_RSCDBU_RSCACKDIS 0x00000080 | ||
954 | |||
955 | /* RDRXCTL Bit Masks */ | ||
956 | #define IXGBE_RDRXCTL_RDMTS_1_2 0x00000000 /* Rx Desc Min Threshold Size */ | ||
957 | #define IXGBE_RDRXCTL_CRCSTRIP 0x00000002 /* CRC Strip */ | ||
958 | #define IXGBE_RDRXCTL_MVMEN 0x00000020 | ||
959 | #define IXGBE_RDRXCTL_DMAIDONE 0x00000008 /* DMA init cycle done */ | ||
960 | #define IXGBE_RDRXCTL_AGGDIS 0x00010000 /* Aggregation disable */ | ||
961 | #define IXGBE_RDRXCTL_RSCFRSTSIZE 0x003E0000 /* RSC First packet size */ | ||
962 | #define IXGBE_RDRXCTL_RSCLLIDIS 0x00800000 /* Disable RSC compl on LLI */ | ||
963 | #define IXGBE_RDRXCTL_RSCACKC 0x02000000 /* must set 1 when RSC enabled */ | ||
964 | #define IXGBE_RDRXCTL_FCOE_WRFIX 0x04000000 /* must set 1 when RSC enabled */ | ||
965 | |||
966 | /* RQTC Bit Masks and Shifts */ | ||
967 | #define IXGBE_RQTC_SHIFT_TC(_i) ((_i) * 4) | ||
968 | #define IXGBE_RQTC_TC0_MASK (0x7 << 0) | ||
969 | #define IXGBE_RQTC_TC1_MASK (0x7 << 4) | ||
970 | #define IXGBE_RQTC_TC2_MASK (0x7 << 8) | ||
971 | #define IXGBE_RQTC_TC3_MASK (0x7 << 12) | ||
972 | #define IXGBE_RQTC_TC4_MASK (0x7 << 16) | ||
973 | #define IXGBE_RQTC_TC5_MASK (0x7 << 20) | ||
974 | #define IXGBE_RQTC_TC6_MASK (0x7 << 24) | ||
975 | #define IXGBE_RQTC_TC7_MASK (0x7 << 28) | ||
976 | |||
977 | /* PSRTYPE.RQPL Bit masks and shift */ | ||
978 | #define IXGBE_PSRTYPE_RQPL_MASK 0x7 | ||
979 | #define IXGBE_PSRTYPE_RQPL_SHIFT 29 | ||
980 | |||
981 | /* CTRL Bit Masks */ | ||
982 | #define IXGBE_CTRL_GIO_DIS 0x00000004 /* Global IO Master Disable bit */ | ||
983 | #define IXGBE_CTRL_LNK_RST 0x00000008 /* Link Reset. Resets everything. */ | ||
984 | #define IXGBE_CTRL_RST 0x04000000 /* Reset (SW) */ | ||
985 | |||
986 | /* FACTPS */ | ||
987 | #define IXGBE_FACTPS_LFS 0x40000000 /* LAN Function Select */ | ||
988 | |||
989 | /* MHADD Bit Masks */ | ||
990 | #define IXGBE_MHADD_MFS_MASK 0xFFFF0000 | ||
991 | #define IXGBE_MHADD_MFS_SHIFT 16 | ||
992 | |||
993 | /* Extended Device Control */ | ||
994 | #define IXGBE_CTRL_EXT_PFRSTD 0x00004000 /* Physical Function Reset Done */ | ||
995 | #define IXGBE_CTRL_EXT_NS_DIS 0x00010000 /* No Snoop disable */ | ||
996 | #define IXGBE_CTRL_EXT_RO_DIS 0x00020000 /* Relaxed Ordering disable */ | ||
997 | #define IXGBE_CTRL_EXT_DRV_LOAD 0x10000000 /* Driver loaded bit for FW */ | ||
998 | |||
999 | /* Direct Cache Access (DCA) definitions */ | ||
1000 | #define IXGBE_DCA_CTRL_DCA_ENABLE 0x00000000 /* DCA Enable */ | ||
1001 | #define IXGBE_DCA_CTRL_DCA_DISABLE 0x00000001 /* DCA Disable */ | ||
1002 | |||
1003 | #define IXGBE_DCA_CTRL_DCA_MODE_CB1 0x00 /* DCA Mode CB1 */ | ||
1004 | #define IXGBE_DCA_CTRL_DCA_MODE_CB2 0x02 /* DCA Mode CB2 */ | ||
1005 | |||
1006 | #define IXGBE_DCA_RXCTRL_CPUID_MASK 0x0000001F /* Rx CPUID Mask */ | ||
1007 | #define IXGBE_DCA_RXCTRL_CPUID_MASK_82599 0xFF000000 /* Rx CPUID Mask */ | ||
1008 | #define IXGBE_DCA_RXCTRL_CPUID_SHIFT_82599 24 /* Rx CPUID Shift */ | ||
1009 | #define IXGBE_DCA_RXCTRL_DESC_DCA_EN (1 << 5) /* DCA Rx Desc enable */ | ||
1010 | #define IXGBE_DCA_RXCTRL_HEAD_DCA_EN (1 << 6) /* DCA Rx Desc header enable */ | ||
1011 | #define IXGBE_DCA_RXCTRL_DATA_DCA_EN (1 << 7) /* DCA Rx Desc payload enable */ | ||
1012 | #define IXGBE_DCA_RXCTRL_DESC_RRO_EN (1 << 9) /* DCA Rx rd Desc Relax Order */ | ||
1013 | #define IXGBE_DCA_RXCTRL_DESC_WRO_EN (1 << 13) /* DCA Rx wr Desc Relax Order */ | ||
1014 | #define IXGBE_DCA_RXCTRL_DESC_HSRO_EN (1 << 15) /* DCA Rx Split Header RO */ | ||
1015 | |||
1016 | #define IXGBE_DCA_TXCTRL_CPUID_MASK 0x0000001F /* Tx CPUID Mask */ | ||
1017 | #define IXGBE_DCA_TXCTRL_CPUID_MASK_82599 0xFF000000 /* Tx CPUID Mask */ | ||
1018 | #define IXGBE_DCA_TXCTRL_CPUID_SHIFT_82599 24 /* Tx CPUID Shift */ | ||
1019 | #define IXGBE_DCA_TXCTRL_DESC_DCA_EN (1 << 5) /* DCA Tx Desc enable */ | ||
1020 | #define IXGBE_DCA_TXCTRL_TX_WB_RO_EN (1 << 11) /* Tx Desc writeback RO bit */ | ||
1021 | #define IXGBE_DCA_MAX_QUEUES_82598 16 /* DCA regs only on 16 queues */ | ||
1022 | |||
1023 | /* MSCA Bit Masks */ | ||
1024 | #define IXGBE_MSCA_NP_ADDR_MASK 0x0000FFFF /* MDI Address (new protocol) */ | ||
1025 | #define IXGBE_MSCA_NP_ADDR_SHIFT 0 | ||
1026 | #define IXGBE_MSCA_DEV_TYPE_MASK 0x001F0000 /* Device Type (new protocol) */ | ||
1027 | #define IXGBE_MSCA_DEV_TYPE_SHIFT 16 /* Register Address (old protocol */ | ||
1028 | #define IXGBE_MSCA_PHY_ADDR_MASK 0x03E00000 /* PHY Address mask */ | ||
1029 | #define IXGBE_MSCA_PHY_ADDR_SHIFT 21 /* PHY Address shift*/ | ||
1030 | #define IXGBE_MSCA_OP_CODE_MASK 0x0C000000 /* OP CODE mask */ | ||
1031 | #define IXGBE_MSCA_OP_CODE_SHIFT 26 /* OP CODE shift */ | ||
1032 | #define IXGBE_MSCA_ADDR_CYCLE 0x00000000 /* OP CODE 00 (addr cycle) */ | ||
1033 | #define IXGBE_MSCA_WRITE 0x04000000 /* OP CODE 01 (write) */ | ||
1034 | #define IXGBE_MSCA_READ 0x0C000000 /* OP CODE 11 (read) */ | ||
1035 | #define IXGBE_MSCA_READ_AUTOINC 0x08000000 /* OP CODE 10 (read, auto inc)*/ | ||
1036 | #define IXGBE_MSCA_ST_CODE_MASK 0x30000000 /* ST Code mask */ | ||
1037 | #define IXGBE_MSCA_ST_CODE_SHIFT 28 /* ST Code shift */ | ||
1038 | #define IXGBE_MSCA_NEW_PROTOCOL 0x00000000 /* ST CODE 00 (new protocol) */ | ||
1039 | #define IXGBE_MSCA_OLD_PROTOCOL 0x10000000 /* ST CODE 01 (old protocol) */ | ||
1040 | #define IXGBE_MSCA_MDI_COMMAND 0x40000000 /* Initiate MDI command */ | ||
1041 | #define IXGBE_MSCA_MDI_IN_PROG_EN 0x80000000 /* MDI in progress enable */ | ||
1042 | |||
1043 | /* MSRWD bit masks */ | ||
1044 | #define IXGBE_MSRWD_WRITE_DATA_MASK 0x0000FFFF | ||
1045 | #define IXGBE_MSRWD_WRITE_DATA_SHIFT 0 | ||
1046 | #define IXGBE_MSRWD_READ_DATA_MASK 0xFFFF0000 | ||
1047 | #define IXGBE_MSRWD_READ_DATA_SHIFT 16 | ||
1048 | |||
1049 | /* Atlas registers */ | ||
1050 | #define IXGBE_ATLAS_PDN_LPBK 0x24 | ||
1051 | #define IXGBE_ATLAS_PDN_10G 0xB | ||
1052 | #define IXGBE_ATLAS_PDN_1G 0xC | ||
1053 | #define IXGBE_ATLAS_PDN_AN 0xD | ||
1054 | |||
1055 | /* Atlas bit masks */ | ||
1056 | #define IXGBE_ATLASCTL_WRITE_CMD 0x00010000 | ||
1057 | #define IXGBE_ATLAS_PDN_TX_REG_EN 0x10 | ||
1058 | #define IXGBE_ATLAS_PDN_TX_10G_QL_ALL 0xF0 | ||
1059 | #define IXGBE_ATLAS_PDN_TX_1G_QL_ALL 0xF0 | ||
1060 | #define IXGBE_ATLAS_PDN_TX_AN_QL_ALL 0xF0 | ||
1061 | |||
1062 | /* Omer bit masks */ | ||
1063 | #define IXGBE_CORECTL_WRITE_CMD 0x00010000 | ||
1064 | |||
1065 | /* MDIO definitions */ | ||
1066 | |||
1067 | #define IXGBE_MDIO_COMMAND_TIMEOUT 100 /* PHY Timeout for 1 GB mode */ | ||
1068 | |||
1069 | #define IXGBE_MDIO_VENDOR_SPECIFIC_1_CONTROL 0x0 /* VS1 Control Reg */ | ||
1070 | #define IXGBE_MDIO_VENDOR_SPECIFIC_1_STATUS 0x1 /* VS1 Status Reg */ | ||
1071 | #define IXGBE_MDIO_VENDOR_SPECIFIC_1_LINK_STATUS 0x0008 /* 1 = Link Up */ | ||
1072 | #define IXGBE_MDIO_VENDOR_SPECIFIC_1_SPEED_STATUS 0x0010 /* 0 - 10G, 1 - 1G */ | ||
1073 | #define IXGBE_MDIO_VENDOR_SPECIFIC_1_10G_SPEED 0x0018 | ||
1074 | #define IXGBE_MDIO_VENDOR_SPECIFIC_1_1G_SPEED 0x0010 | ||
1075 | |||
1076 | #define IXGBE_MDIO_PMA_PMD_SDA_SCL_ADDR 0xC30A /* PHY_XS SDA/SCL Addr Reg */ | ||
1077 | #define IXGBE_MDIO_PMA_PMD_SDA_SCL_DATA 0xC30B /* PHY_XS SDA/SCL Data Reg */ | ||
1078 | #define IXGBE_MDIO_PMA_PMD_SDA_SCL_STAT 0xC30C /* PHY_XS SDA/SCL Status Reg */ | ||
1079 | |||
1080 | /* MII clause 22/28 definitions */ | ||
1081 | #define IXGBE_MII_AUTONEG_VENDOR_PROVISION_1_REG 0xC400 /* 1G Provisioning 1 */ | ||
1082 | #define IXGBE_MII_AUTONEG_XNP_TX_REG 0x17 /* 1G XNP Transmit */ | ||
1083 | #define IXGBE_MII_1GBASE_T_ADVERTISE_XNP_TX 0x4000 /* full duplex, bit:14*/ | ||
1084 | #define IXGBE_MII_1GBASE_T_ADVERTISE 0x8000 /* full duplex, bit:15*/ | ||
1085 | #define IXGBE_MII_AUTONEG_REG 0x0 | ||
1086 | |||
1087 | #define IXGBE_PHY_REVISION_MASK 0xFFFFFFF0 | ||
1088 | #define IXGBE_MAX_PHY_ADDR 32 | ||
1089 | |||
1090 | /* PHY IDs*/ | ||
1091 | #define TN1010_PHY_ID 0x00A19410 | ||
1092 | #define TNX_FW_REV 0xB | ||
1093 | #define X540_PHY_ID 0x01540200 | ||
1094 | #define QT2022_PHY_ID 0x0043A400 | ||
1095 | #define ATH_PHY_ID 0x03429050 | ||
1096 | #define AQ_FW_REV 0x20 | ||
1097 | |||
1098 | /* PHY Types */ | ||
1099 | #define IXGBE_M88E1145_E_PHY_ID 0x01410CD0 | ||
1100 | |||
1101 | /* Special PHY Init Routine */ | ||
1102 | #define IXGBE_PHY_INIT_OFFSET_NL 0x002B | ||
1103 | #define IXGBE_PHY_INIT_END_NL 0xFFFF | ||
1104 | #define IXGBE_CONTROL_MASK_NL 0xF000 | ||
1105 | #define IXGBE_DATA_MASK_NL 0x0FFF | ||
1106 | #define IXGBE_CONTROL_SHIFT_NL 12 | ||
1107 | #define IXGBE_DELAY_NL 0 | ||
1108 | #define IXGBE_DATA_NL 1 | ||
1109 | #define IXGBE_CONTROL_NL 0x000F | ||
1110 | #define IXGBE_CONTROL_EOL_NL 0x0FFF | ||
1111 | #define IXGBE_CONTROL_SOL_NL 0x0000 | ||
1112 | |||
1113 | /* General purpose Interrupt Enable */ | ||
1114 | #define IXGBE_SDP0_GPIEN 0x00000001 /* SDP0 */ | ||
1115 | #define IXGBE_SDP1_GPIEN 0x00000002 /* SDP1 */ | ||
1116 | #define IXGBE_SDP2_GPIEN 0x00000004 /* SDP2 */ | ||
1117 | #define IXGBE_GPIE_MSIX_MODE 0x00000010 /* MSI-X mode */ | ||
1118 | #define IXGBE_GPIE_OCD 0x00000020 /* Other Clear Disable */ | ||
1119 | #define IXGBE_GPIE_EIMEN 0x00000040 /* Immediate Interrupt Enable */ | ||
1120 | #define IXGBE_GPIE_EIAME 0x40000000 | ||
1121 | #define IXGBE_GPIE_PBA_SUPPORT 0x80000000 | ||
1122 | #define IXGBE_GPIE_RSC_DELAY_SHIFT 11 | ||
1123 | #define IXGBE_GPIE_VTMODE_MASK 0x0000C000 /* VT Mode Mask */ | ||
1124 | #define IXGBE_GPIE_VTMODE_16 0x00004000 /* 16 VFs 8 queues per VF */ | ||
1125 | #define IXGBE_GPIE_VTMODE_32 0x00008000 /* 32 VFs 4 queues per VF */ | ||
1126 | #define IXGBE_GPIE_VTMODE_64 0x0000C000 /* 64 VFs 2 queues per VF */ | ||
1127 | |||
1128 | /* Packet Buffer Initialization */ | ||
1129 | #define IXGBE_TXPBSIZE_20KB 0x00005000 /* 20KB Packet Buffer */ | ||
1130 | #define IXGBE_TXPBSIZE_40KB 0x0000A000 /* 40KB Packet Buffer */ | ||
1131 | #define IXGBE_RXPBSIZE_48KB 0x0000C000 /* 48KB Packet Buffer */ | ||
1132 | #define IXGBE_RXPBSIZE_64KB 0x00010000 /* 64KB Packet Buffer */ | ||
1133 | #define IXGBE_RXPBSIZE_80KB 0x00014000 /* 80KB Packet Buffer */ | ||
1134 | #define IXGBE_RXPBSIZE_128KB 0x00020000 /* 128KB Packet Buffer */ | ||
1135 | #define IXGBE_RXPBSIZE_MAX 0x00080000 /* 512KB Packet Buffer*/ | ||
1136 | #define IXGBE_TXPBSIZE_MAX 0x00028000 /* 160KB Packet Buffer*/ | ||
1137 | |||
1138 | #define IXGBE_TXPKT_SIZE_MAX 0xA /* Max Tx Packet size */ | ||
1139 | #define IXGBE_MAX_PB 8 | ||
1140 | |||
1141 | /* Packet buffer allocation strategies */ | ||
1142 | enum { | ||
1143 | PBA_STRATEGY_EQUAL = 0, /* Distribute PB space equally */ | ||
1144 | #define PBA_STRATEGY_EQUAL PBA_STRATEGY_EQUAL | ||
1145 | PBA_STRATEGY_WEIGHTED = 1, /* Weight front half of TCs */ | ||
1146 | #define PBA_STRATEGY_WEIGHTED PBA_STRATEGY_WEIGHTED | ||
1147 | }; | ||
1148 | |||
1149 | /* Transmit Flow Control status */ | ||
1150 | #define IXGBE_TFCS_TXOFF 0x00000001 | ||
1151 | #define IXGBE_TFCS_TXOFF0 0x00000100 | ||
1152 | #define IXGBE_TFCS_TXOFF1 0x00000200 | ||
1153 | #define IXGBE_TFCS_TXOFF2 0x00000400 | ||
1154 | #define IXGBE_TFCS_TXOFF3 0x00000800 | ||
1155 | #define IXGBE_TFCS_TXOFF4 0x00001000 | ||
1156 | #define IXGBE_TFCS_TXOFF5 0x00002000 | ||
1157 | #define IXGBE_TFCS_TXOFF6 0x00004000 | ||
1158 | #define IXGBE_TFCS_TXOFF7 0x00008000 | ||
1159 | |||
1160 | /* TCP Timer */ | ||
1161 | #define IXGBE_TCPTIMER_KS 0x00000100 | ||
1162 | #define IXGBE_TCPTIMER_COUNT_ENABLE 0x00000200 | ||
1163 | #define IXGBE_TCPTIMER_COUNT_FINISH 0x00000400 | ||
1164 | #define IXGBE_TCPTIMER_LOOP 0x00000800 | ||
1165 | #define IXGBE_TCPTIMER_DURATION_MASK 0x000000FF | ||
1166 | |||
1167 | /* HLREG0 Bit Masks */ | ||
1168 | #define IXGBE_HLREG0_TXCRCEN 0x00000001 /* bit 0 */ | ||
1169 | #define IXGBE_HLREG0_RXCRCSTRP 0x00000002 /* bit 1 */ | ||
1170 | #define IXGBE_HLREG0_JUMBOEN 0x00000004 /* bit 2 */ | ||
1171 | #define IXGBE_HLREG0_TXPADEN 0x00000400 /* bit 10 */ | ||
1172 | #define IXGBE_HLREG0_TXPAUSEEN 0x00001000 /* bit 12 */ | ||
1173 | #define IXGBE_HLREG0_RXPAUSEEN 0x00004000 /* bit 14 */ | ||
1174 | #define IXGBE_HLREG0_LPBK 0x00008000 /* bit 15 */ | ||
1175 | #define IXGBE_HLREG0_MDCSPD 0x00010000 /* bit 16 */ | ||
1176 | #define IXGBE_HLREG0_CONTMDC 0x00020000 /* bit 17 */ | ||
1177 | #define IXGBE_HLREG0_CTRLFLTR 0x00040000 /* bit 18 */ | ||
1178 | #define IXGBE_HLREG0_PREPEND 0x00F00000 /* bits 20-23 */ | ||
1179 | #define IXGBE_HLREG0_PRIPAUSEEN 0x01000000 /* bit 24 */ | ||
1180 | #define IXGBE_HLREG0_RXPAUSERECDA 0x06000000 /* bits 25-26 */ | ||
1181 | #define IXGBE_HLREG0_RXLNGTHERREN 0x08000000 /* bit 27 */ | ||
1182 | #define IXGBE_HLREG0_RXPADSTRIPEN 0x10000000 /* bit 28 */ | ||
1183 | |||
1184 | /* VMD_CTL bitmasks */ | ||
1185 | #define IXGBE_VMD_CTL_VMDQ_EN 0x00000001 | ||
1186 | #define IXGBE_VMD_CTL_VMDQ_FILTER 0x00000002 | ||
1187 | |||
1188 | /* VT_CTL bitmasks */ | ||
1189 | #define IXGBE_VT_CTL_DIS_DEFPL 0x20000000 /* disable default pool */ | ||
1190 | #define IXGBE_VT_CTL_REPLEN 0x40000000 /* replication enabled */ | ||
1191 | #define IXGBE_VT_CTL_VT_ENABLE 0x00000001 /* Enable VT Mode */ | ||
1192 | #define IXGBE_VT_CTL_POOL_SHIFT 7 | ||
1193 | #define IXGBE_VT_CTL_POOL_MASK (0x3F << IXGBE_VT_CTL_POOL_SHIFT) | ||
1194 | |||
1195 | /* VMOLR bitmasks */ | ||
1196 | #define IXGBE_VMOLR_AUPE 0x01000000 /* accept untagged packets */ | ||
1197 | #define IXGBE_VMOLR_ROMPE 0x02000000 /* accept packets in MTA tbl */ | ||
1198 | #define IXGBE_VMOLR_ROPE 0x04000000 /* accept packets in UC tbl */ | ||
1199 | #define IXGBE_VMOLR_BAM 0x08000000 /* accept broadcast packets */ | ||
1200 | #define IXGBE_VMOLR_MPE 0x10000000 /* multicast promiscuous */ | ||
1201 | |||
1202 | /* VFRE bitmask */ | ||
1203 | #define IXGBE_VFRE_ENABLE_ALL 0xFFFFFFFF | ||
1204 | |||
1205 | #define IXGBE_VF_INIT_TIMEOUT 200 /* Number of retries to clear RSTI */ | ||
1206 | |||
1207 | /* RDHMPN and TDHMPN bitmasks */ | ||
1208 | #define IXGBE_RDHMPN_RDICADDR 0x007FF800 | ||
1209 | #define IXGBE_RDHMPN_RDICRDREQ 0x00800000 | ||
1210 | #define IXGBE_RDHMPN_RDICADDR_SHIFT 11 | ||
1211 | #define IXGBE_TDHMPN_TDICADDR 0x003FF800 | ||
1212 | #define IXGBE_TDHMPN_TDICRDREQ 0x00800000 | ||
1213 | #define IXGBE_TDHMPN_TDICADDR_SHIFT 11 | ||
1214 | |||
1215 | #define IXGBE_RDMAM_MEM_SEL_SHIFT 13 | ||
1216 | #define IXGBE_RDMAM_DWORD_SHIFT 9 | ||
1217 | #define IXGBE_RDMAM_DESC_COMP_FIFO 1 | ||
1218 | #define IXGBE_RDMAM_DFC_CMD_FIFO 2 | ||
1219 | #define IXGBE_RDMAM_TCN_STATUS_RAM 4 | ||
1220 | #define IXGBE_RDMAM_WB_COLL_FIFO 5 | ||
1221 | #define IXGBE_RDMAM_QSC_CNT_RAM 6 | ||
1222 | #define IXGBE_RDMAM_QSC_QUEUE_CNT 8 | ||
1223 | #define IXGBE_RDMAM_QSC_QUEUE_RAM 0xA | ||
1224 | #define IXGBE_RDMAM_DESC_COM_FIFO_RANGE 135 | ||
1225 | #define IXGBE_RDMAM_DESC_COM_FIFO_COUNT 4 | ||
1226 | #define IXGBE_RDMAM_DFC_CMD_FIFO_RANGE 48 | ||
1227 | #define IXGBE_RDMAM_DFC_CMD_FIFO_COUNT 7 | ||
1228 | #define IXGBE_RDMAM_TCN_STATUS_RAM_RANGE 256 | ||
1229 | #define IXGBE_RDMAM_TCN_STATUS_RAM_COUNT 9 | ||
1230 | #define IXGBE_RDMAM_WB_COLL_FIFO_RANGE 8 | ||
1231 | #define IXGBE_RDMAM_WB_COLL_FIFO_COUNT 4 | ||
1232 | #define IXGBE_RDMAM_QSC_CNT_RAM_RANGE 64 | ||
1233 | #define IXGBE_RDMAM_QSC_CNT_RAM_COUNT 4 | ||
1234 | #define IXGBE_RDMAM_QSC_QUEUE_CNT_RANGE 32 | ||
1235 | #define IXGBE_RDMAM_QSC_QUEUE_CNT_COUNT 4 | ||
1236 | #define IXGBE_RDMAM_QSC_QUEUE_RAM_RANGE 128 | ||
1237 | #define IXGBE_RDMAM_QSC_QUEUE_RAM_COUNT 8 | ||
1238 | |||
1239 | #define IXGBE_TXDESCIC_READY 0x80000000 | ||
1240 | |||
1241 | /* Receive Checksum Control */ | ||
1242 | #define IXGBE_RXCSUM_IPPCSE 0x00001000 /* IP payload checksum enable */ | ||
1243 | #define IXGBE_RXCSUM_PCSD 0x00002000 /* packet checksum disabled */ | ||
1244 | |||
1245 | /* FCRTL Bit Masks */ | ||
1246 | #define IXGBE_FCRTL_XONE 0x80000000 /* XON enable */ | ||
1247 | #define IXGBE_FCRTH_FCEN 0x80000000 /* Packet buffer fc enable */ | ||
1248 | |||
1249 | /* PAP bit masks*/ | ||
1250 | #define IXGBE_PAP_TXPAUSECNT_MASK 0x0000FFFF /* Pause counter mask */ | ||
1251 | |||
1252 | /* RMCS Bit Masks */ | ||
1253 | #define IXGBE_RMCS_RRM 0x00000002 /* Receive Recycle Mode enable */ | ||
1254 | /* Receive Arbitration Control: 0 Round Robin, 1 DFP */ | ||
1255 | #define IXGBE_RMCS_RAC 0x00000004 | ||
1256 | #define IXGBE_RMCS_DFP IXGBE_RMCS_RAC /* Deficit Fixed Priority ena */ | ||
1257 | #define IXGBE_RMCS_TFCE_802_3X 0x00000008 /* Tx Priority FC ena */ | ||
1258 | #define IXGBE_RMCS_TFCE_PRIORITY 0x00000010 /* Tx Priority FC ena */ | ||
1259 | #define IXGBE_RMCS_ARBDIS 0x00000040 /* Arbitration disable bit */ | ||
1260 | |||
1261 | /* FCCFG Bit Masks */ | ||
1262 | #define IXGBE_FCCFG_TFCE_802_3X 0x00000008 /* Tx link FC enable */ | ||
1263 | #define IXGBE_FCCFG_TFCE_PRIORITY 0x00000010 /* Tx priority FC enable */ | ||
1264 | |||
1265 | /* Interrupt register bitmasks */ | ||
1266 | |||
1267 | /* Extended Interrupt Cause Read */ | ||
1268 | #define IXGBE_EICR_RTX_QUEUE 0x0000FFFF /* RTx Queue Interrupt */ | ||
1269 | #define IXGBE_EICR_FLOW_DIR 0x00010000 /* FDir Exception */ | ||
1270 | #define IXGBE_EICR_RX_MISS 0x00020000 /* Packet Buffer Overrun */ | ||
1271 | #define IXGBE_EICR_PCI 0x00040000 /* PCI Exception */ | ||
1272 | #define IXGBE_EICR_MAILBOX 0x00080000 /* VF to PF Mailbox Interrupt */ | ||
1273 | #define IXGBE_EICR_LSC 0x00100000 /* Link Status Change */ | ||
1274 | #define IXGBE_EICR_LINKSEC 0x00200000 /* PN Threshold */ | ||
1275 | #define IXGBE_EICR_MNG 0x00400000 /* Manageability Event Interrupt */ | ||
1276 | #define IXGBE_EICR_GPI_SDP0 0x01000000 /* Gen Purpose Interrupt on SDP0 */ | ||
1277 | #define IXGBE_EICR_GPI_SDP1 0x02000000 /* Gen Purpose Interrupt on SDP1 */ | ||
1278 | #define IXGBE_EICR_GPI_SDP2 0x04000000 /* Gen Purpose Interrupt on SDP2 */ | ||
1279 | #define IXGBE_EICR_ECC 0x10000000 /* ECC Error */ | ||
1280 | #define IXGBE_EICR_PBUR 0x10000000 /* Packet Buffer Handler Error */ | ||
1281 | #define IXGBE_EICR_DHER 0x20000000 /* Descriptor Handler Error */ | ||
1282 | #define IXGBE_EICR_TCP_TIMER 0x40000000 /* TCP Timer */ | ||
1283 | #define IXGBE_EICR_OTHER 0x80000000 /* Interrupt Cause Active */ | ||
1284 | |||
1285 | /* Extended Interrupt Cause Set */ | ||
1286 | #define IXGBE_EICS_RTX_QUEUE IXGBE_EICR_RTX_QUEUE /* RTx Queue Interrupt */ | ||
1287 | #define IXGBE_EICS_FLOW_DIR IXGBE_EICR_FLOW_DIR /* FDir Exception */ | ||
1288 | #define IXGBE_EICS_RX_MISS IXGBE_EICR_RX_MISS /* Pkt Buffer Overrun */ | ||
1289 | #define IXGBE_EICS_PCI IXGBE_EICR_PCI /* PCI Exception */ | ||
1290 | #define IXGBE_EICS_MAILBOX IXGBE_EICR_MAILBOX /* VF to PF Mailbox Int */ | ||
1291 | #define IXGBE_EICS_LSC IXGBE_EICR_LSC /* Link Status Change */ | ||
1292 | #define IXGBE_EICS_MNG IXGBE_EICR_MNG /* MNG Event Interrupt */ | ||
1293 | #define IXGBE_EICS_GPI_SDP0 IXGBE_EICR_GPI_SDP0 /* SDP0 Gen Purpose Int */ | ||
1294 | #define IXGBE_EICS_GPI_SDP1 IXGBE_EICR_GPI_SDP1 /* SDP1 Gen Purpose Int */ | ||
1295 | #define IXGBE_EICS_GPI_SDP2 IXGBE_EICR_GPI_SDP2 /* SDP2 Gen Purpose Int */ | ||
1296 | #define IXGBE_EICS_ECC IXGBE_EICR_ECC /* ECC Error */ | ||
1297 | #define IXGBE_EICS_PBUR IXGBE_EICR_PBUR /* Pkt Buf Handler Err */ | ||
1298 | #define IXGBE_EICS_DHER IXGBE_EICR_DHER /* Desc Handler Error */ | ||
1299 | #define IXGBE_EICS_TCP_TIMER IXGBE_EICR_TCP_TIMER /* TCP Timer */ | ||
1300 | #define IXGBE_EICS_OTHER IXGBE_EICR_OTHER /* INT Cause Active */ | ||
1301 | |||
1302 | /* Extended Interrupt Mask Set */ | ||
1303 | #define IXGBE_EIMS_RTX_QUEUE IXGBE_EICR_RTX_QUEUE /* RTx Queue Interrupt */ | ||
1304 | #define IXGBE_EIMS_FLOW_DIR IXGBE_EICR_FLOW_DIR /* FDir Exception */ | ||
1305 | #define IXGBE_EIMS_RX_MISS IXGBE_EICR_RX_MISS /* Packet Buffer Overrun */ | ||
1306 | #define IXGBE_EIMS_PCI IXGBE_EICR_PCI /* PCI Exception */ | ||
1307 | #define IXGBE_EIMS_MAILBOX IXGBE_EICR_MAILBOX /* VF to PF Mailbox Int */ | ||
1308 | #define IXGBE_EIMS_LSC IXGBE_EICR_LSC /* Link Status Change */ | ||
1309 | #define IXGBE_EIMS_MNG IXGBE_EICR_MNG /* MNG Event Interrupt */ | ||
1310 | #define IXGBE_EIMS_GPI_SDP0 IXGBE_EICR_GPI_SDP0 /* SDP0 Gen Purpose Int */ | ||
1311 | #define IXGBE_EIMS_GPI_SDP1 IXGBE_EICR_GPI_SDP1 /* SDP1 Gen Purpose Int */ | ||
1312 | #define IXGBE_EIMS_GPI_SDP2 IXGBE_EICR_GPI_SDP2 /* SDP2 Gen Purpose Int */ | ||
1313 | #define IXGBE_EIMS_ECC IXGBE_EICR_ECC /* ECC Error */ | ||
1314 | #define IXGBE_EIMS_PBUR IXGBE_EICR_PBUR /* Pkt Buf Handler Err */ | ||
1315 | #define IXGBE_EIMS_DHER IXGBE_EICR_DHER /* Descr Handler Error */ | ||
1316 | #define IXGBE_EIMS_TCP_TIMER IXGBE_EICR_TCP_TIMER /* TCP Timer */ | ||
1317 | #define IXGBE_EIMS_OTHER IXGBE_EICR_OTHER /* INT Cause Active */ | ||
1318 | |||
1319 | /* Extended Interrupt Mask Clear */ | ||
1320 | #define IXGBE_EIMC_RTX_QUEUE IXGBE_EICR_RTX_QUEUE /* RTx Queue Interrupt */ | ||
1321 | #define IXGBE_EIMC_FLOW_DIR IXGBE_EICR_FLOW_DIR /* FDir Exception */ | ||
1322 | #define IXGBE_EIMC_RX_MISS IXGBE_EICR_RX_MISS /* Packet Buffer Overrun */ | ||
1323 | #define IXGBE_EIMC_PCI IXGBE_EICR_PCI /* PCI Exception */ | ||
1324 | #define IXGBE_EIMC_MAILBOX IXGBE_EICR_MAILBOX /* VF to PF Mailbox Int */ | ||
1325 | #define IXGBE_EIMC_LSC IXGBE_EICR_LSC /* Link Status Change */ | ||
1326 | #define IXGBE_EIMC_MNG IXGBE_EICR_MNG /* MNG Event Interrupt */ | ||
1327 | #define IXGBE_EIMC_GPI_SDP0 IXGBE_EICR_GPI_SDP0 /* SDP0 Gen Purpose Int */ | ||
1328 | #define IXGBE_EIMC_GPI_SDP1 IXGBE_EICR_GPI_SDP1 /* SDP1 Gen Purpose Int */ | ||
1329 | #define IXGBE_EIMC_GPI_SDP2 IXGBE_EICR_GPI_SDP2 /* SDP2 Gen Purpose Int */ | ||
1330 | #define IXGBE_EIMC_ECC IXGBE_EICR_ECC /* ECC Error */ | ||
1331 | #define IXGBE_EIMC_PBUR IXGBE_EICR_PBUR /* Pkt Buf Handler Err */ | ||
1332 | #define IXGBE_EIMC_DHER IXGBE_EICR_DHER /* Desc Handler Err */ | ||
1333 | #define IXGBE_EIMC_TCP_TIMER IXGBE_EICR_TCP_TIMER /* TCP Timer */ | ||
1334 | #define IXGBE_EIMC_OTHER IXGBE_EICR_OTHER /* INT Cause Active */ | ||
1335 | |||
1336 | #define IXGBE_EIMS_ENABLE_MASK ( \ | ||
1337 | IXGBE_EIMS_RTX_QUEUE | \ | ||
1338 | IXGBE_EIMS_LSC | \ | ||
1339 | IXGBE_EIMS_TCP_TIMER | \ | ||
1340 | IXGBE_EIMS_OTHER) | ||
1341 | |||
1342 | /* Immediate Interrupt Rx (A.K.A. Low Latency Interrupt) */ | ||
1343 | #define IXGBE_IMIR_PORT_IM_EN 0x00010000 /* TCP port enable */ | ||
1344 | #define IXGBE_IMIR_PORT_BP 0x00020000 /* TCP port check bypass */ | ||
1345 | #define IXGBE_IMIREXT_SIZE_BP 0x00001000 /* Packet size bypass */ | ||
1346 | #define IXGBE_IMIREXT_CTRL_URG 0x00002000 /* Check URG bit in header */ | ||
1347 | #define IXGBE_IMIREXT_CTRL_ACK 0x00004000 /* Check ACK bit in header */ | ||
1348 | #define IXGBE_IMIREXT_CTRL_PSH 0x00008000 /* Check PSH bit in header */ | ||
1349 | #define IXGBE_IMIREXT_CTRL_RST 0x00010000 /* Check RST bit in header */ | ||
1350 | #define IXGBE_IMIREXT_CTRL_SYN 0x00020000 /* Check SYN bit in header */ | ||
1351 | #define IXGBE_IMIREXT_CTRL_FIN 0x00040000 /* Check FIN bit in header */ | ||
1352 | #define IXGBE_IMIREXT_CTRL_BP 0x00080000 /* Bypass check of control bits */ | ||
1353 | #define IXGBE_IMIR_SIZE_BP_82599 0x00001000 /* Packet size bypass */ | ||
1354 | #define IXGBE_IMIR_CTRL_URG_82599 0x00002000 /* Check URG bit in header */ | ||
1355 | #define IXGBE_IMIR_CTRL_ACK_82599 0x00004000 /* Check ACK bit in header */ | ||
1356 | #define IXGBE_IMIR_CTRL_PSH_82599 0x00008000 /* Check PSH bit in header */ | ||
1357 | #define IXGBE_IMIR_CTRL_RST_82599 0x00010000 /* Check RST bit in header */ | ||
1358 | #define IXGBE_IMIR_CTRL_SYN_82599 0x00020000 /* Check SYN bit in header */ | ||
1359 | #define IXGBE_IMIR_CTRL_FIN_82599 0x00040000 /* Check FIN bit in header */ | ||
1360 | #define IXGBE_IMIR_CTRL_BP_82599 0x00080000 /* Bypass check of control bits */ | ||
1361 | #define IXGBE_IMIR_LLI_EN_82599 0x00100000 /* Enables low latency Int */ | ||
1362 | #define IXGBE_IMIR_RX_QUEUE_MASK_82599 0x0000007F /* Rx Queue Mask */ | ||
1363 | #define IXGBE_IMIR_RX_QUEUE_SHIFT_82599 21 /* Rx Queue Shift */ | ||
1364 | #define IXGBE_IMIRVP_PRIORITY_MASK 0x00000007 /* VLAN priority mask */ | ||
1365 | #define IXGBE_IMIRVP_PRIORITY_EN 0x00000008 /* VLAN priority enable */ | ||
1366 | |||
1367 | #define IXGBE_MAX_FTQF_FILTERS 128 | ||
1368 | #define IXGBE_FTQF_PROTOCOL_MASK 0x00000003 | ||
1369 | #define IXGBE_FTQF_PROTOCOL_TCP 0x00000000 | ||
1370 | #define IXGBE_FTQF_PROTOCOL_UDP 0x00000001 | ||
1371 | #define IXGBE_FTQF_PROTOCOL_SCTP 2 | ||
1372 | #define IXGBE_FTQF_PRIORITY_MASK 0x00000007 | ||
1373 | #define IXGBE_FTQF_PRIORITY_SHIFT 2 | ||
1374 | #define IXGBE_FTQF_POOL_MASK 0x0000003F | ||
1375 | #define IXGBE_FTQF_POOL_SHIFT 8 | ||
1376 | #define IXGBE_FTQF_5TUPLE_MASK_MASK 0x0000001F | ||
1377 | #define IXGBE_FTQF_5TUPLE_MASK_SHIFT 25 | ||
1378 | #define IXGBE_FTQF_SOURCE_ADDR_MASK 0x1E | ||
1379 | #define IXGBE_FTQF_DEST_ADDR_MASK 0x1D | ||
1380 | #define IXGBE_FTQF_SOURCE_PORT_MASK 0x1B | ||
1381 | #define IXGBE_FTQF_DEST_PORT_MASK 0x17 | ||
1382 | #define IXGBE_FTQF_PROTOCOL_COMP_MASK 0x0F | ||
1383 | #define IXGBE_FTQF_POOL_MASK_EN 0x40000000 | ||
1384 | #define IXGBE_FTQF_QUEUE_ENABLE 0x80000000 | ||
1385 | |||
1386 | /* Interrupt clear mask */ | ||
1387 | #define IXGBE_IRQ_CLEAR_MASK 0xFFFFFFFF | ||
1388 | |||
1389 | /* Interrupt Vector Allocation Registers */ | ||
1390 | #define IXGBE_IVAR_REG_NUM 25 | ||
1391 | #define IXGBE_IVAR_REG_NUM_82599 64 | ||
1392 | #define IXGBE_IVAR_TXRX_ENTRY 96 | ||
1393 | #define IXGBE_IVAR_RX_ENTRY 64 | ||
1394 | #define IXGBE_IVAR_RX_QUEUE(_i) (0 + (_i)) | ||
1395 | #define IXGBE_IVAR_TX_QUEUE(_i) (64 + (_i)) | ||
1396 | #define IXGBE_IVAR_TX_ENTRY 32 | ||
1397 | |||
1398 | #define IXGBE_IVAR_TCP_TIMER_INDEX 96 /* 0 based index */ | ||
1399 | #define IXGBE_IVAR_OTHER_CAUSES_INDEX 97 /* 0 based index */ | ||
1400 | |||
1401 | #define IXGBE_MSIX_VECTOR(_i) (0 + (_i)) | ||
1402 | |||
1403 | #define IXGBE_IVAR_ALLOC_VAL 0x80 /* Interrupt Allocation valid */ | ||
1404 | |||
1405 | /* ETYPE Queue Filter/Select Bit Masks */ | ||
1406 | #define IXGBE_MAX_ETQF_FILTERS 8 | ||
1407 | #define IXGBE_ETQF_FCOE 0x08000000 /* bit 27 */ | ||
1408 | #define IXGBE_ETQF_BCN 0x10000000 /* bit 28 */ | ||
1409 | #define IXGBE_ETQF_1588 0x40000000 /* bit 30 */ | ||
1410 | #define IXGBE_ETQF_FILTER_EN 0x80000000 /* bit 31 */ | ||
1411 | #define IXGBE_ETQF_POOL_ENABLE (1 << 26) /* bit 26 */ | ||
1412 | |||
1413 | #define IXGBE_ETQS_RX_QUEUE 0x007F0000 /* bits 22:16 */ | ||
1414 | #define IXGBE_ETQS_RX_QUEUE_SHIFT 16 | ||
1415 | #define IXGBE_ETQS_LLI 0x20000000 /* bit 29 */ | ||
1416 | #define IXGBE_ETQS_QUEUE_EN 0x80000000 /* bit 31 */ | ||
1417 | |||
1418 | /* | ||
1419 | * ETQF filter list: one static filter per filter consumer. This is | ||
1420 | * to avoid filter collisions later. Add new filters | ||
1421 | * here!! | ||
1422 | * | ||
1423 | * Current filters: | ||
1424 | * EAPOL 802.1x (0x888e): Filter 0 | ||
1425 | * FCoE (0x8906): Filter 2 | ||
1426 | * 1588 (0x88f7): Filter 3 | ||
1427 | * FIP (0x8914): Filter 4 | ||
1428 | */ | ||
1429 | #define IXGBE_ETQF_FILTER_EAPOL 0 | ||
1430 | #define IXGBE_ETQF_FILTER_FCOE 2 | ||
1431 | #define IXGBE_ETQF_FILTER_1588 3 | ||
1432 | #define IXGBE_ETQF_FILTER_FIP 4 | ||
1433 | /* VLAN Control Bit Masks */ | ||
1434 | #define IXGBE_VLNCTRL_VET 0x0000FFFF /* bits 0-15 */ | ||
1435 | #define IXGBE_VLNCTRL_CFI 0x10000000 /* bit 28 */ | ||
1436 | #define IXGBE_VLNCTRL_CFIEN 0x20000000 /* bit 29 */ | ||
1437 | #define IXGBE_VLNCTRL_VFE 0x40000000 /* bit 30 */ | ||
1438 | #define IXGBE_VLNCTRL_VME 0x80000000 /* bit 31 */ | ||
1439 | |||
1440 | /* VLAN pool filtering masks */ | ||
1441 | #define IXGBE_VLVF_VIEN 0x80000000 /* filter is valid */ | ||
1442 | #define IXGBE_VLVF_ENTRIES 64 | ||
1443 | #define IXGBE_VLVF_VLANID_MASK 0x00000FFF | ||
1444 | |||
1445 | /* Per VF Port VLAN insertion rules */ | ||
1446 | #define IXGBE_VMVIR_VLANA_DEFAULT 0x40000000 /* Always use default VLAN */ | ||
1447 | #define IXGBE_VMVIR_VLANA_NEVER 0x80000000 /* Never insert VLAN tag */ | ||
1448 | |||
1449 | #define IXGBE_ETHERNET_IEEE_VLAN_TYPE 0x8100 /* 802.1q protocol */ | ||
1450 | |||
1451 | /* STATUS Bit Masks */ | ||
1452 | #define IXGBE_STATUS_LAN_ID 0x0000000C /* LAN ID */ | ||
1453 | #define IXGBE_STATUS_LAN_ID_SHIFT 2 /* LAN ID Shift*/ | ||
1454 | #define IXGBE_STATUS_GIO 0x00080000 /* GIO Master Enable Status */ | ||
1455 | |||
1456 | #define IXGBE_STATUS_LAN_ID_0 0x00000000 /* LAN ID 0 */ | ||
1457 | #define IXGBE_STATUS_LAN_ID_1 0x00000004 /* LAN ID 1 */ | ||
1458 | |||
1459 | /* ESDP Bit Masks */ | ||
1460 | #define IXGBE_ESDP_SDP0 0x00000001 /* SDP0 Data Value */ | ||
1461 | #define IXGBE_ESDP_SDP1 0x00000002 /* SDP1 Data Value */ | ||
1462 | #define IXGBE_ESDP_SDP2 0x00000004 /* SDP2 Data Value */ | ||
1463 | #define IXGBE_ESDP_SDP3 0x00000008 /* SDP3 Data Value */ | ||
1464 | #define IXGBE_ESDP_SDP4 0x00000010 /* SDP4 Data Value */ | ||
1465 | #define IXGBE_ESDP_SDP5 0x00000020 /* SDP5 Data Value */ | ||
1466 | #define IXGBE_ESDP_SDP6 0x00000040 /* SDP6 Data Value */ | ||
1467 | #define IXGBE_ESDP_SDP4_DIR 0x00000004 /* SDP4 IO direction */ | ||
1468 | #define IXGBE_ESDP_SDP5_DIR 0x00002000 /* SDP5 IO direction */ | ||
1469 | |||
1470 | /* LEDCTL Bit Masks */ | ||
1471 | #define IXGBE_LED_IVRT_BASE 0x00000040 | ||
1472 | #define IXGBE_LED_BLINK_BASE 0x00000080 | ||
1473 | #define IXGBE_LED_MODE_MASK_BASE 0x0000000F | ||
1474 | #define IXGBE_LED_OFFSET(_base, _i) (_base << (8 * (_i))) | ||
1475 | #define IXGBE_LED_MODE_SHIFT(_i) (8*(_i)) | ||
1476 | #define IXGBE_LED_IVRT(_i) IXGBE_LED_OFFSET(IXGBE_LED_IVRT_BASE, _i) | ||
1477 | #define IXGBE_LED_BLINK(_i) IXGBE_LED_OFFSET(IXGBE_LED_BLINK_BASE, _i) | ||
1478 | #define IXGBE_LED_MODE_MASK(_i) IXGBE_LED_OFFSET(IXGBE_LED_MODE_MASK_BASE, _i) | ||
1479 | |||
1480 | /* LED modes */ | ||
1481 | #define IXGBE_LED_LINK_UP 0x0 | ||
1482 | #define IXGBE_LED_LINK_10G 0x1 | ||
1483 | #define IXGBE_LED_MAC 0x2 | ||
1484 | #define IXGBE_LED_FILTER 0x3 | ||
1485 | #define IXGBE_LED_LINK_ACTIVE 0x4 | ||
1486 | #define IXGBE_LED_LINK_1G 0x5 | ||
1487 | #define IXGBE_LED_ON 0xE | ||
1488 | #define IXGBE_LED_OFF 0xF | ||
1489 | |||
1490 | /* AUTOC Bit Masks */ | ||
1491 | #define IXGBE_AUTOC_KX4_KX_SUPP_MASK 0xC0000000 | ||
1492 | #define IXGBE_AUTOC_KX4_SUPP 0x80000000 | ||
1493 | #define IXGBE_AUTOC_KX_SUPP 0x40000000 | ||
1494 | #define IXGBE_AUTOC_PAUSE 0x30000000 | ||
1495 | #define IXGBE_AUTOC_ASM_PAUSE 0x20000000 | ||
1496 | #define IXGBE_AUTOC_SYM_PAUSE 0x10000000 | ||
1497 | #define IXGBE_AUTOC_RF 0x08000000 | ||
1498 | #define IXGBE_AUTOC_PD_TMR 0x06000000 | ||
1499 | #define IXGBE_AUTOC_AN_RX_LOOSE 0x01000000 | ||
1500 | #define IXGBE_AUTOC_AN_RX_DRIFT 0x00800000 | ||
1501 | #define IXGBE_AUTOC_AN_RX_ALIGN 0x007C0000 | ||
1502 | #define IXGBE_AUTOC_FECA 0x00040000 | ||
1503 | #define IXGBE_AUTOC_FECR 0x00020000 | ||
1504 | #define IXGBE_AUTOC_KR_SUPP 0x00010000 | ||
1505 | #define IXGBE_AUTOC_AN_RESTART 0x00001000 | ||
1506 | #define IXGBE_AUTOC_FLU 0x00000001 | ||
1507 | #define IXGBE_AUTOC_LMS_SHIFT 13 | ||
1508 | #define IXGBE_AUTOC_LMS_10G_SERIAL (0x3 << IXGBE_AUTOC_LMS_SHIFT) | ||
1509 | #define IXGBE_AUTOC_LMS_KX4_KX_KR (0x4 << IXGBE_AUTOC_LMS_SHIFT) | ||
1510 | #define IXGBE_AUTOC_LMS_SGMII_1G_100M (0x5 << IXGBE_AUTOC_LMS_SHIFT) | ||
1511 | #define IXGBE_AUTOC_LMS_KX4_KX_KR_1G_AN (0x6 << IXGBE_AUTOC_LMS_SHIFT) | ||
1512 | #define IXGBE_AUTOC_LMS_KX4_KX_KR_SGMII (0x7 << IXGBE_AUTOC_LMS_SHIFT) | ||
1513 | #define IXGBE_AUTOC_LMS_MASK (0x7 << IXGBE_AUTOC_LMS_SHIFT) | ||
1514 | #define IXGBE_AUTOC_LMS_1G_LINK_NO_AN (0x0 << IXGBE_AUTOC_LMS_SHIFT) | ||
1515 | #define IXGBE_AUTOC_LMS_10G_LINK_NO_AN (0x1 << IXGBE_AUTOC_LMS_SHIFT) | ||
1516 | #define IXGBE_AUTOC_LMS_1G_AN (0x2 << IXGBE_AUTOC_LMS_SHIFT) | ||
1517 | #define IXGBE_AUTOC_LMS_KX4_AN (0x4 << IXGBE_AUTOC_LMS_SHIFT) | ||
1518 | #define IXGBE_AUTOC_LMS_KX4_AN_1G_AN (0x6 << IXGBE_AUTOC_LMS_SHIFT) | ||
1519 | #define IXGBE_AUTOC_LMS_ATTACH_TYPE (0x7 << IXGBE_AUTOC_10G_PMA_PMD_SHIFT) | ||
1520 | |||
1521 | #define IXGBE_AUTOC_1G_PMA_PMD_MASK 0x00000200 | ||
1522 | #define IXGBE_AUTOC_1G_PMA_PMD_SHIFT 9 | ||
1523 | #define IXGBE_AUTOC_10G_PMA_PMD_MASK 0x00000180 | ||
1524 | #define IXGBE_AUTOC_10G_PMA_PMD_SHIFT 7 | ||
1525 | #define IXGBE_AUTOC_10G_XAUI (0x0 << IXGBE_AUTOC_10G_PMA_PMD_SHIFT) | ||
1526 | #define IXGBE_AUTOC_10G_KX4 (0x1 << IXGBE_AUTOC_10G_PMA_PMD_SHIFT) | ||
1527 | #define IXGBE_AUTOC_10G_CX4 (0x2 << IXGBE_AUTOC_10G_PMA_PMD_SHIFT) | ||
1528 | #define IXGBE_AUTOC_1G_BX (0x0 << IXGBE_AUTOC_1G_PMA_PMD_SHIFT) | ||
1529 | #define IXGBE_AUTOC_1G_KX (0x1 << IXGBE_AUTOC_1G_PMA_PMD_SHIFT) | ||
1530 | #define IXGBE_AUTOC_1G_SFI (0x0 << IXGBE_AUTOC_1G_PMA_PMD_SHIFT) | ||
1531 | #define IXGBE_AUTOC_1G_KX_BX (0x1 << IXGBE_AUTOC_1G_PMA_PMD_SHIFT) | ||
1532 | |||
1533 | #define IXGBE_AUTOC2_UPPER_MASK 0xFFFF0000 | ||
1534 | #define IXGBE_AUTOC2_10G_SERIAL_PMA_PMD_MASK 0x00030000 | ||
1535 | #define IXGBE_AUTOC2_10G_SERIAL_PMA_PMD_SHIFT 16 | ||
1536 | #define IXGBE_AUTOC2_10G_KR (0x0 << IXGBE_AUTOC2_10G_SERIAL_PMA_PMD_SHIFT) | ||
1537 | #define IXGBE_AUTOC2_10G_XFI (0x1 << IXGBE_AUTOC2_10G_SERIAL_PMA_PMD_SHIFT) | ||
1538 | #define IXGBE_AUTOC2_10G_SFI (0x2 << IXGBE_AUTOC2_10G_SERIAL_PMA_PMD_SHIFT) | ||
1539 | |||
1540 | #define IXGBE_MACC_FLU 0x00000001 | ||
1541 | #define IXGBE_MACC_FSV_10G 0x00030000 | ||
1542 | #define IXGBE_MACC_FS 0x00040000 | ||
1543 | #define IXGBE_MAC_RX2TX_LPBK 0x00000002 | ||
1544 | |||
1545 | /* LINKS Bit Masks */ | ||
1546 | #define IXGBE_LINKS_KX_AN_COMP 0x80000000 | ||
1547 | #define IXGBE_LINKS_UP 0x40000000 | ||
1548 | #define IXGBE_LINKS_SPEED 0x20000000 | ||
1549 | #define IXGBE_LINKS_MODE 0x18000000 | ||
1550 | #define IXGBE_LINKS_RX_MODE 0x06000000 | ||
1551 | #define IXGBE_LINKS_TX_MODE 0x01800000 | ||
1552 | #define IXGBE_LINKS_XGXS_EN 0x00400000 | ||
1553 | #define IXGBE_LINKS_SGMII_EN 0x02000000 | ||
1554 | #define IXGBE_LINKS_PCS_1G_EN 0x00200000 | ||
1555 | #define IXGBE_LINKS_1G_AN_EN 0x00100000 | ||
1556 | #define IXGBE_LINKS_KX_AN_IDLE 0x00080000 | ||
1557 | #define IXGBE_LINKS_1G_SYNC 0x00040000 | ||
1558 | #define IXGBE_LINKS_10G_ALIGN 0x00020000 | ||
1559 | #define IXGBE_LINKS_10G_LANE_SYNC 0x00017000 | ||
1560 | #define IXGBE_LINKS_TL_FAULT 0x00001000 | ||
1561 | #define IXGBE_LINKS_SIGNAL 0x00000F00 | ||
1562 | |||
1563 | #define IXGBE_LINKS_SPEED_82599 0x30000000 | ||
1564 | #define IXGBE_LINKS_SPEED_10G_82599 0x30000000 | ||
1565 | #define IXGBE_LINKS_SPEED_1G_82599 0x20000000 | ||
1566 | #define IXGBE_LINKS_SPEED_100_82599 0x10000000 | ||
1567 | #define IXGBE_LINK_UP_TIME 90 /* 9.0 Seconds */ | ||
1568 | #define IXGBE_AUTO_NEG_TIME 45 /* 4.5 Seconds */ | ||
1569 | |||
1570 | #define IXGBE_LINKS2_AN_SUPPORTED 0x00000040 | ||
1571 | |||
1572 | /* PCS1GLSTA Bit Masks */ | ||
1573 | #define IXGBE_PCS1GLSTA_LINK_OK 1 | ||
1574 | #define IXGBE_PCS1GLSTA_SYNK_OK 0x10 | ||
1575 | #define IXGBE_PCS1GLSTA_AN_COMPLETE 0x10000 | ||
1576 | #define IXGBE_PCS1GLSTA_AN_PAGE_RX 0x20000 | ||
1577 | #define IXGBE_PCS1GLSTA_AN_TIMED_OUT 0x40000 | ||
1578 | #define IXGBE_PCS1GLSTA_AN_REMOTE_FAULT 0x80000 | ||
1579 | #define IXGBE_PCS1GLSTA_AN_ERROR_RWS 0x100000 | ||
1580 | |||
1581 | #define IXGBE_PCS1GANA_SYM_PAUSE 0x80 | ||
1582 | #define IXGBE_PCS1GANA_ASM_PAUSE 0x100 | ||
1583 | |||
1584 | /* PCS1GLCTL Bit Masks */ | ||
1585 | #define IXGBE_PCS1GLCTL_AN_1G_TIMEOUT_EN 0x00040000 /* PCS 1G autoneg to en */ | ||
1586 | #define IXGBE_PCS1GLCTL_FLV_LINK_UP 1 | ||
1587 | #define IXGBE_PCS1GLCTL_FORCE_LINK 0x20 | ||
1588 | #define IXGBE_PCS1GLCTL_LOW_LINK_LATCH 0x40 | ||
1589 | #define IXGBE_PCS1GLCTL_AN_ENABLE 0x10000 | ||
1590 | #define IXGBE_PCS1GLCTL_AN_RESTART 0x20000 | ||
1591 | |||
1592 | /* ANLP1 Bit Masks */ | ||
1593 | #define IXGBE_ANLP1_PAUSE 0x0C00 | ||
1594 | #define IXGBE_ANLP1_SYM_PAUSE 0x0400 | ||
1595 | #define IXGBE_ANLP1_ASM_PAUSE 0x0800 | ||
1596 | #define IXGBE_ANLP1_AN_STATE_MASK 0x000f0000 | ||
1597 | |||
1598 | /* SW Semaphore Register bitmasks */ | ||
1599 | #define IXGBE_SWSM_SMBI 0x00000001 /* Driver Semaphore bit */ | ||
1600 | #define IXGBE_SWSM_SWESMBI 0x00000002 /* FW Semaphore bit */ | ||
1601 | #define IXGBE_SWSM_WMNG 0x00000004 /* Wake MNG Clock */ | ||
1602 | #define IXGBE_SWFW_REGSMP 0x80000000 /* Register Semaphore bit 31 */ | ||
1603 | |||
1604 | /* SW_FW_SYNC/GSSR definitions */ | ||
1605 | #define IXGBE_GSSR_EEP_SM 0x0001 | ||
1606 | #define IXGBE_GSSR_PHY0_SM 0x0002 | ||
1607 | #define IXGBE_GSSR_PHY1_SM 0x0004 | ||
1608 | #define IXGBE_GSSR_MAC_CSR_SM 0x0008 | ||
1609 | #define IXGBE_GSSR_FLASH_SM 0x0010 | ||
1610 | #define IXGBE_GSSR_SW_MNG_SM 0x0400 | ||
1611 | |||
1612 | /* FW Status register bitmask */ | ||
1613 | #define IXGBE_FWSTS_FWRI 0x00000200 /* Firmware Reset Indication */ | ||
1614 | |||
1615 | /* EEC Register */ | ||
1616 | #define IXGBE_EEC_SK 0x00000001 /* EEPROM Clock */ | ||
1617 | #define IXGBE_EEC_CS 0x00000002 /* EEPROM Chip Select */ | ||
1618 | #define IXGBE_EEC_DI 0x00000004 /* EEPROM Data In */ | ||
1619 | #define IXGBE_EEC_DO 0x00000008 /* EEPROM Data Out */ | ||
1620 | #define IXGBE_EEC_FWE_MASK 0x00000030 /* FLASH Write Enable */ | ||
1621 | #define IXGBE_EEC_FWE_DIS 0x00000010 /* Disable FLASH writes */ | ||
1622 | #define IXGBE_EEC_FWE_EN 0x00000020 /* Enable FLASH writes */ | ||
1623 | #define IXGBE_EEC_FWE_SHIFT 4 | ||
1624 | #define IXGBE_EEC_REQ 0x00000040 /* EEPROM Access Request */ | ||
1625 | #define IXGBE_EEC_GNT 0x00000080 /* EEPROM Access Grant */ | ||
1626 | #define IXGBE_EEC_PRES 0x00000100 /* EEPROM Present */ | ||
1627 | #define IXGBE_EEC_ARD 0x00000200 /* EEPROM Auto Read Done */ | ||
1628 | #define IXGBE_EEC_FLUP 0x00800000 /* Flash update command */ | ||
1629 | #define IXGBE_EEC_SEC1VAL 0x02000000 /* Sector 1 Valid */ | ||
1630 | #define IXGBE_EEC_FLUDONE 0x04000000 /* Flash update done */ | ||
1631 | /* EEPROM Addressing bits based on type (0-small, 1-large) */ | ||
1632 | #define IXGBE_EEC_ADDR_SIZE 0x00000400 | ||
1633 | #define IXGBE_EEC_SIZE 0x00007800 /* EEPROM Size */ | ||
1634 | #define IXGBE_EERD_MAX_ADDR 0x00003FFF /* EERD alows 14 bits for addr. */ | ||
1635 | |||
1636 | #define IXGBE_EEC_SIZE_SHIFT 11 | ||
1637 | #define IXGBE_EEPROM_WORD_SIZE_SHIFT 6 | ||
1638 | #define IXGBE_EEPROM_OPCODE_BITS 8 | ||
1639 | |||
1640 | /* Part Number String Length */ | ||
1641 | #define IXGBE_PBANUM_LENGTH 11 | ||
1642 | |||
1643 | /* Checksum and EEPROM pointers */ | ||
1644 | #define IXGBE_PBANUM_PTR_GUARD 0xFAFA | ||
1645 | #define IXGBE_EEPROM_CHECKSUM 0x3F | ||
1646 | #define IXGBE_EEPROM_SUM 0xBABA | ||
1647 | #define IXGBE_PCIE_ANALOG_PTR 0x03 | ||
1648 | #define IXGBE_ATLAS0_CONFIG_PTR 0x04 | ||
1649 | #define IXGBE_PHY_PTR 0x04 | ||
1650 | #define IXGBE_ATLAS1_CONFIG_PTR 0x05 | ||
1651 | #define IXGBE_OPTION_ROM_PTR 0x05 | ||
1652 | #define IXGBE_PCIE_GENERAL_PTR 0x06 | ||
1653 | #define IXGBE_PCIE_CONFIG0_PTR 0x07 | ||
1654 | #define IXGBE_PCIE_CONFIG1_PTR 0x08 | ||
1655 | #define IXGBE_CORE0_PTR 0x09 | ||
1656 | #define IXGBE_CORE1_PTR 0x0A | ||
1657 | #define IXGBE_MAC0_PTR 0x0B | ||
1658 | #define IXGBE_MAC1_PTR 0x0C | ||
1659 | #define IXGBE_CSR0_CONFIG_PTR 0x0D | ||
1660 | #define IXGBE_CSR1_CONFIG_PTR 0x0E | ||
1661 | #define IXGBE_FW_PTR 0x0F | ||
1662 | #define IXGBE_PBANUM0_PTR 0x15 | ||
1663 | #define IXGBE_PBANUM1_PTR 0x16 | ||
1664 | #define IXGBE_FREE_SPACE_PTR 0X3E | ||
1665 | #define IXGBE_SAN_MAC_ADDR_PTR 0x28 | ||
1666 | #define IXGBE_DEVICE_CAPS 0x2C | ||
1667 | #define IXGBE_SERIAL_NUMBER_MAC_ADDR 0x11 | ||
1668 | #define IXGBE_PCIE_MSIX_82599_CAPS 0x72 | ||
1669 | #define IXGBE_PCIE_MSIX_82598_CAPS 0x62 | ||
1670 | |||
1671 | /* MSI-X capability fields masks */ | ||
1672 | #define IXGBE_PCIE_MSIX_TBL_SZ_MASK 0x7FF | ||
1673 | |||
1674 | /* Legacy EEPROM word offsets */ | ||
1675 | #define IXGBE_ISCSI_BOOT_CAPS 0x0033 | ||
1676 | #define IXGBE_ISCSI_SETUP_PORT_0 0x0030 | ||
1677 | #define IXGBE_ISCSI_SETUP_PORT_1 0x0034 | ||
1678 | |||
1679 | /* EEPROM Commands - SPI */ | ||
1680 | #define IXGBE_EEPROM_MAX_RETRY_SPI 5000 /* Max wait 5ms for RDY signal */ | ||
1681 | #define IXGBE_EEPROM_STATUS_RDY_SPI 0x01 | ||
1682 | #define IXGBE_EEPROM_READ_OPCODE_SPI 0x03 /* EEPROM read opcode */ | ||
1683 | #define IXGBE_EEPROM_WRITE_OPCODE_SPI 0x02 /* EEPROM write opcode */ | ||
1684 | #define IXGBE_EEPROM_A8_OPCODE_SPI 0x08 /* opcode bit-3 = addr bit-8 */ | ||
1685 | #define IXGBE_EEPROM_WREN_OPCODE_SPI 0x06 /* EEPROM set Write Ena latch */ | ||
1686 | /* EEPROM reset Write Enable latch */ | ||
1687 | #define IXGBE_EEPROM_WRDI_OPCODE_SPI 0x04 | ||
1688 | #define IXGBE_EEPROM_RDSR_OPCODE_SPI 0x05 /* EEPROM read Status reg */ | ||
1689 | #define IXGBE_EEPROM_WRSR_OPCODE_SPI 0x01 /* EEPROM write Status reg */ | ||
1690 | #define IXGBE_EEPROM_ERASE4K_OPCODE_SPI 0x20 /* EEPROM ERASE 4KB */ | ||
1691 | #define IXGBE_EEPROM_ERASE64K_OPCODE_SPI 0xD8 /* EEPROM ERASE 64KB */ | ||
1692 | #define IXGBE_EEPROM_ERASE256_OPCODE_SPI 0xDB /* EEPROM ERASE 256B */ | ||
1693 | |||
1694 | /* EEPROM Read Register */ | ||
1695 | #define IXGBE_EEPROM_RW_REG_DATA 16 /* data offset in EEPROM read reg */ | ||
1696 | #define IXGBE_EEPROM_RW_REG_DONE 2 /* Offset to READ done bit */ | ||
1697 | #define IXGBE_EEPROM_RW_REG_START 1 /* First bit to start operation */ | ||
1698 | #define IXGBE_EEPROM_RW_ADDR_SHIFT 2 /* Shift to the address bits */ | ||
1699 | #define IXGBE_NVM_POLL_WRITE 1 /* Flag for polling for write complete */ | ||
1700 | #define IXGBE_NVM_POLL_READ 0 /* Flag for polling for read complete */ | ||
1701 | |||
1702 | #define IXGBE_ETH_LENGTH_OF_ADDRESS 6 | ||
1703 | |||
1704 | #define IXGBE_EEPROM_PAGE_SIZE_MAX 128 | ||
1705 | #define IXGBE_EEPROM_RD_BUFFER_MAX_COUNT 512 /* EEPROM words # read in burst */ | ||
1706 | #define IXGBE_EEPROM_WR_BUFFER_MAX_COUNT 256 /* EEPROM words # wr in burst */ | ||
1707 | |||
1708 | #ifndef IXGBE_EEPROM_GRANT_ATTEMPTS | ||
1709 | #define IXGBE_EEPROM_GRANT_ATTEMPTS 1000 /* EEPROM # attempts to gain grant */ | ||
1710 | #endif | ||
1711 | |||
1712 | #ifndef IXGBE_EERD_EEWR_ATTEMPTS | ||
1713 | /* Number of 5 microseconds we wait for EERD read and | ||
1714 | * EERW write to complete */ | ||
1715 | #define IXGBE_EERD_EEWR_ATTEMPTS 100000 | ||
1716 | #endif | ||
1717 | |||
1718 | #ifndef IXGBE_FLUDONE_ATTEMPTS | ||
1719 | /* # attempts we wait for flush update to complete */ | ||
1720 | #define IXGBE_FLUDONE_ATTEMPTS 20000 | ||
1721 | #endif | ||
1722 | |||
1723 | #define IXGBE_PCIE_CTRL2 0x5 /* PCIe Control 2 Offset */ | ||
1724 | #define IXGBE_PCIE_CTRL2_DUMMY_ENABLE 0x8 /* Dummy Function Enable */ | ||
1725 | #define IXGBE_PCIE_CTRL2_LAN_DISABLE 0x2 /* LAN PCI Disable */ | ||
1726 | #define IXGBE_PCIE_CTRL2_DISABLE_SELECT 0x1 /* LAN Disable Select */ | ||
1727 | |||
1728 | #define IXGBE_SAN_MAC_ADDR_PORT0_OFFSET 0x0 | ||
1729 | #define IXGBE_SAN_MAC_ADDR_PORT1_OFFSET 0x3 | ||
1730 | #define IXGBE_DEVICE_CAPS_ALLOW_ANY_SFP 0x1 | ||
1731 | #define IXGBE_DEVICE_CAPS_FCOE_OFFLOADS 0x2 | ||
1732 | #define IXGBE_FW_LESM_PARAMETERS_PTR 0x2 | ||
1733 | #define IXGBE_FW_LESM_STATE_1 0x1 | ||
1734 | #define IXGBE_FW_LESM_STATE_ENABLED 0x8000 /* LESM Enable bit */ | ||
1735 | #define IXGBE_FW_PASSTHROUGH_PATCH_CONFIG_PTR 0x4 | ||
1736 | #define IXGBE_FW_PATCH_VERSION_4 0x7 | ||
1737 | #define IXGBE_FCOE_IBA_CAPS_BLK_PTR 0x33 /* iSCSI/FCOE block */ | ||
1738 | #define IXGBE_FCOE_IBA_CAPS_FCOE 0x20 /* FCOE flags */ | ||
1739 | #define IXGBE_ISCSI_FCOE_BLK_PTR 0x17 /* iSCSI/FCOE block */ | ||
1740 | #define IXGBE_ISCSI_FCOE_FLAGS_OFFSET 0x0 /* FCOE flags */ | ||
1741 | #define IXGBE_ISCSI_FCOE_FLAGS_ENABLE 0x1 /* FCOE flags enable bit */ | ||
1742 | #define IXGBE_ALT_SAN_MAC_ADDR_BLK_PTR 0x27 /* Alt. SAN MAC block */ | ||
1743 | #define IXGBE_ALT_SAN_MAC_ADDR_CAPS_OFFSET 0x0 /* Alt. SAN MAC capability */ | ||
1744 | #define IXGBE_ALT_SAN_MAC_ADDR_PORT0_OFFSET 0x1 /* Alt. SAN MAC 0 offset */ | ||
1745 | #define IXGBE_ALT_SAN_MAC_ADDR_PORT1_OFFSET 0x4 /* Alt. SAN MAC 1 offset */ | ||
1746 | #define IXGBE_ALT_SAN_MAC_ADDR_WWNN_OFFSET 0x7 /* Alt. WWNN prefix offset */ | ||
1747 | #define IXGBE_ALT_SAN_MAC_ADDR_WWPN_OFFSET 0x8 /* Alt. WWPN prefix offset */ | ||
1748 | #define IXGBE_ALT_SAN_MAC_ADDR_CAPS_SANMAC 0x0 /* Alt. SAN MAC exists */ | ||
1749 | #define IXGBE_ALT_SAN_MAC_ADDR_CAPS_ALTWWN 0x1 /* Alt. WWN base exists */ | ||
1750 | |||
1751 | /* PCI Bus Info */ | ||
1752 | #define IXGBE_PCI_DEVICE_STATUS 0xAA | ||
1753 | #define IXGBE_PCI_DEVICE_STATUS_TRANSACTION_PENDING 0x0020 | ||
1754 | #define IXGBE_PCI_LINK_STATUS 0xB2 | ||
1755 | #define IXGBE_PCI_DEVICE_CONTROL2 0xC8 | ||
1756 | #define IXGBE_PCI_LINK_WIDTH 0x3F0 | ||
1757 | #define IXGBE_PCI_LINK_WIDTH_1 0x10 | ||
1758 | #define IXGBE_PCI_LINK_WIDTH_2 0x20 | ||
1759 | #define IXGBE_PCI_LINK_WIDTH_4 0x40 | ||
1760 | #define IXGBE_PCI_LINK_WIDTH_8 0x80 | ||
1761 | #define IXGBE_PCI_LINK_SPEED 0xF | ||
1762 | #define IXGBE_PCI_LINK_SPEED_2500 0x1 | ||
1763 | #define IXGBE_PCI_LINK_SPEED_5000 0x2 | ||
1764 | #define IXGBE_PCI_HEADER_TYPE_REGISTER 0x0E | ||
1765 | #define IXGBE_PCI_HEADER_TYPE_MULTIFUNC 0x80 | ||
1766 | #define IXGBE_PCI_DEVICE_CONTROL2_16ms 0x0005 | ||
1767 | |||
1768 | /* Number of 100 microseconds we wait for PCI Express master disable */ | ||
1769 | #define IXGBE_PCI_MASTER_DISABLE_TIMEOUT 800 | ||
1770 | |||
1771 | /* Check whether address is multicast. This is little-endian specific check.*/ | ||
1772 | #define IXGBE_IS_MULTICAST(Address) \ | ||
1773 | (bool)(((u8 *)(Address))[0] & ((u8)0x01)) | ||
1774 | |||
1775 | /* Check whether an address is broadcast. */ | ||
1776 | #define IXGBE_IS_BROADCAST(Address) \ | ||
1777 | ((((u8 *)(Address))[0] == ((u8)0xff)) && \ | ||
1778 | (((u8 *)(Address))[1] == ((u8)0xff))) | ||
1779 | |||
1780 | /* RAH */ | ||
1781 | #define IXGBE_RAH_VIND_MASK 0x003C0000 | ||
1782 | #define IXGBE_RAH_VIND_SHIFT 18 | ||
1783 | #define IXGBE_RAH_AV 0x80000000 | ||
1784 | #define IXGBE_CLEAR_VMDQ_ALL 0xFFFFFFFF | ||
1785 | |||
1786 | /* Header split receive */ | ||
1787 | #define IXGBE_RFCTL_ISCSI_DIS 0x00000001 | ||
1788 | #define IXGBE_RFCTL_ISCSI_DWC_MASK 0x0000003E | ||
1789 | #define IXGBE_RFCTL_ISCSI_DWC_SHIFT 1 | ||
1790 | #define IXGBE_RFCTL_NFSW_DIS 0x00000040 | ||
1791 | #define IXGBE_RFCTL_NFSR_DIS 0x00000080 | ||
1792 | #define IXGBE_RFCTL_NFS_VER_MASK 0x00000300 | ||
1793 | #define IXGBE_RFCTL_NFS_VER_SHIFT 8 | ||
1794 | #define IXGBE_RFCTL_NFS_VER_2 0 | ||
1795 | #define IXGBE_RFCTL_NFS_VER_3 1 | ||
1796 | #define IXGBE_RFCTL_NFS_VER_4 2 | ||
1797 | #define IXGBE_RFCTL_IPV6_DIS 0x00000400 | ||
1798 | #define IXGBE_RFCTL_IPV6_XSUM_DIS 0x00000800 | ||
1799 | #define IXGBE_RFCTL_IPFRSP_DIS 0x00004000 | ||
1800 | #define IXGBE_RFCTL_IPV6_EX_DIS 0x00010000 | ||
1801 | #define IXGBE_RFCTL_NEW_IPV6_EXT_DIS 0x00020000 | ||
1802 | |||
1803 | /* Transmit Config masks */ | ||
1804 | #define IXGBE_TXDCTL_ENABLE 0x02000000 /* Enable specific Tx Queue */ | ||
1805 | #define IXGBE_TXDCTL_SWFLSH 0x04000000 /* Tx Desc. write-back flushing */ | ||
1806 | #define IXGBE_TXDCTL_WTHRESH_SHIFT 16 /* shift to WTHRESH bits */ | ||
1807 | /* Enable short packet padding to 64 bytes */ | ||
1808 | #define IXGBE_TX_PAD_ENABLE 0x00000400 | ||
1809 | #define IXGBE_JUMBO_FRAME_ENABLE 0x00000004 /* Allow jumbo frames */ | ||
1810 | /* This allows for 16K packets + 4k for vlan */ | ||
1811 | #define IXGBE_MAX_FRAME_SZ 0x40040000 | ||
1812 | |||
1813 | #define IXGBE_TDWBAL_HEAD_WB_ENABLE 0x1 /* Tx head write-back enable */ | ||
1814 | #define IXGBE_TDWBAL_SEQNUM_WB_ENABLE 0x2 /* Tx seq# write-back enable */ | ||
1815 | |||
1816 | /* Receive Config masks */ | ||
1817 | #define IXGBE_RXCTRL_RXEN 0x00000001 /* Enable Receiver */ | ||
1818 | #define IXGBE_RXCTRL_DMBYPS 0x00000002 /* Descriptor Monitor Bypass */ | ||
1819 | #define IXGBE_RXDCTL_ENABLE 0x02000000 /* Enable specific Rx Queue */ | ||
1820 | #define IXGBE_RXDCTL_RLPMLMASK 0x00003FFF /* Only supported on the X540 */ | ||
1821 | #define IXGBE_RXDCTL_RLPML_EN 0x00008000 | ||
1822 | #define IXGBE_RXDCTL_VME 0x40000000 /* VLAN mode enable */ | ||
1823 | |||
1824 | #define IXGBE_FCTRL_SBP 0x00000002 /* Store Bad Packet */ | ||
1825 | #define IXGBE_FCTRL_MPE 0x00000100 /* Multicast Promiscuous Ena*/ | ||
1826 | #define IXGBE_FCTRL_UPE 0x00000200 /* Unicast Promiscuous Ena */ | ||
1827 | #define IXGBE_FCTRL_BAM 0x00000400 /* Broadcast Accept Mode */ | ||
1828 | #define IXGBE_FCTRL_PMCF 0x00001000 /* Pass MAC Control Frames */ | ||
1829 | #define IXGBE_FCTRL_DPF 0x00002000 /* Discard Pause Frame */ | ||
1830 | /* Receive Priority Flow Control Enable */ | ||
1831 | #define IXGBE_FCTRL_RPFCE 0x00004000 | ||
1832 | #define IXGBE_FCTRL_RFCE 0x00008000 /* Receive Flow Control Ena */ | ||
1833 | #define IXGBE_MFLCN_PMCF 0x00000001 /* Pass MAC Control Frames */ | ||
1834 | #define IXGBE_MFLCN_DPF 0x00000002 /* Discard Pause Frame */ | ||
1835 | #define IXGBE_MFLCN_RPFCE 0x00000004 /* Receive Priority FC Enable */ | ||
1836 | #define IXGBE_MFLCN_RFCE 0x00000008 /* Receive FC Enable */ | ||
1837 | |||
1838 | #define IXGBE_MFLCN_RPFCE_SHIFT 4 | ||
1839 | |||
1840 | /* Multiple Receive Queue Control */ | ||
1841 | #define IXGBE_MRQC_RSSEN 0x00000001 /* RSS Enable */ | ||
1842 | #define IXGBE_MRQC_MRQE_MASK 0xF /* Bits 3:0 */ | ||
1843 | #define IXGBE_MRQC_RT8TCEN 0x00000002 /* 8 TC no RSS */ | ||
1844 | #define IXGBE_MRQC_RT4TCEN 0x00000003 /* 4 TC no RSS */ | ||
1845 | #define IXGBE_MRQC_RTRSS8TCEN 0x00000004 /* 8 TC w/ RSS */ | ||
1846 | #define IXGBE_MRQC_RTRSS4TCEN 0x00000005 /* 4 TC w/ RSS */ | ||
1847 | #define IXGBE_MRQC_VMDQEN 0x00000008 /* VMDq2 64 pools no RSS */ | ||
1848 | #define IXGBE_MRQC_VMDQRSS32EN 0x0000000A /* VMDq2 32 pools w/ RSS */ | ||
1849 | #define IXGBE_MRQC_VMDQRSS64EN 0x0000000B /* VMDq2 64 pools w/ RSS */ | ||
1850 | #define IXGBE_MRQC_VMDQRT8TCEN 0x0000000C /* VMDq2/RT 16 pool 8 TC */ | ||
1851 | #define IXGBE_MRQC_VMDQRT4TCEN 0x0000000D /* VMDq2/RT 32 pool 4 TC */ | ||
1852 | #define IXGBE_MRQC_RSS_FIELD_MASK 0xFFFF0000 | ||
1853 | #define IXGBE_MRQC_RSS_FIELD_IPV4_TCP 0x00010000 | ||
1854 | #define IXGBE_MRQC_RSS_FIELD_IPV4 0x00020000 | ||
1855 | #define IXGBE_MRQC_RSS_FIELD_IPV6_EX_TCP 0x00040000 | ||
1856 | #define IXGBE_MRQC_RSS_FIELD_IPV6_EX 0x00080000 | ||
1857 | #define IXGBE_MRQC_RSS_FIELD_IPV6 0x00100000 | ||
1858 | #define IXGBE_MRQC_RSS_FIELD_IPV6_TCP 0x00200000 | ||
1859 | #define IXGBE_MRQC_RSS_FIELD_IPV4_UDP 0x00400000 | ||
1860 | #define IXGBE_MRQC_RSS_FIELD_IPV6_UDP 0x00800000 | ||
1861 | #define IXGBE_MRQC_RSS_FIELD_IPV6_EX_UDP 0x01000000 | ||
1862 | #define IXGBE_MRQC_L3L4TXSWEN 0x00008000 | ||
1863 | |||
1864 | /* Queue Drop Enable */ | ||
1865 | #define IXGBE_QDE_ENABLE 0x00000001 | ||
1866 | #define IXGBE_QDE_IDX_MASK 0x00007F00 | ||
1867 | #define IXGBE_QDE_IDX_SHIFT 8 | ||
1868 | |||
1869 | #define IXGBE_TXD_POPTS_IXSM 0x01 /* Insert IP checksum */ | ||
1870 | #define IXGBE_TXD_POPTS_TXSM 0x02 /* Insert TCP/UDP checksum */ | ||
1871 | #define IXGBE_TXD_CMD_EOP 0x01000000 /* End of Packet */ | ||
1872 | #define IXGBE_TXD_CMD_IFCS 0x02000000 /* Insert FCS (Ethernet CRC) */ | ||
1873 | #define IXGBE_TXD_CMD_IC 0x04000000 /* Insert Checksum */ | ||
1874 | #define IXGBE_TXD_CMD_RS 0x08000000 /* Report Status */ | ||
1875 | #define IXGBE_TXD_CMD_DEXT 0x20000000 /* Descriptor extension (0 = legacy) */ | ||
1876 | #define IXGBE_TXD_CMD_VLE 0x40000000 /* Add VLAN tag */ | ||
1877 | #define IXGBE_TXD_STAT_DD 0x00000001 /* Descriptor Done */ | ||
1878 | |||
1879 | #define IXGBE_RXDADV_IPSEC_STATUS_SECP 0x00020000 | ||
1880 | #define IXGBE_RXDADV_IPSEC_ERROR_INVALID_PROTOCOL 0x08000000 | ||
1881 | #define IXGBE_RXDADV_IPSEC_ERROR_INVALID_LENGTH 0x10000000 | ||
1882 | #define IXGBE_RXDADV_IPSEC_ERROR_AUTH_FAILED 0x18000000 | ||
1883 | #define IXGBE_RXDADV_IPSEC_ERROR_BIT_MASK 0x18000000 | ||
1884 | /* Multiple Transmit Queue Command Register */ | ||
1885 | #define IXGBE_MTQC_RT_ENA 0x1 /* DCB Enable */ | ||
1886 | #define IXGBE_MTQC_VT_ENA 0x2 /* VMDQ2 Enable */ | ||
1887 | #define IXGBE_MTQC_64Q_1PB 0x0 /* 64 queues 1 pack buffer */ | ||
1888 | #define IXGBE_MTQC_32VF 0x8 /* 4 TX Queues per pool w/32VF's */ | ||
1889 | #define IXGBE_MTQC_64VF 0x4 /* 2 TX Queues per pool w/64VF's */ | ||
1890 | #define IXGBE_MTQC_8TC_8TQ 0xC /* 8 TC if RT_ENA or 8 TQ if VT_ENA */ | ||
1891 | #define IXGBE_MTQC_4TC_4TQ 0x8 /* 4 TC if RT_ENA or 4 TQ if VT_ENA */ | ||
1892 | |||
1893 | /* Receive Descriptor bit definitions */ | ||
1894 | #define IXGBE_RXD_STAT_DD 0x01 /* Descriptor Done */ | ||
1895 | #define IXGBE_RXD_STAT_EOP 0x02 /* End of Packet */ | ||
1896 | #define IXGBE_RXD_STAT_FLM 0x04 /* FDir Match */ | ||
1897 | #define IXGBE_RXD_STAT_VP 0x08 /* IEEE VLAN Packet */ | ||
1898 | #define IXGBE_RXDADV_NEXTP_MASK 0x000FFFF0 /* Next Descriptor Index */ | ||
1899 | #define IXGBE_RXDADV_NEXTP_SHIFT 0x00000004 | ||
1900 | #define IXGBE_RXD_STAT_UDPCS 0x10 /* UDP xsum calculated */ | ||
1901 | #define IXGBE_RXD_STAT_L4CS 0x20 /* L4 xsum calculated */ | ||
1902 | #define IXGBE_RXD_STAT_IPCS 0x40 /* IP xsum calculated */ | ||
1903 | #define IXGBE_RXD_STAT_PIF 0x80 /* passed in-exact filter */ | ||
1904 | #define IXGBE_RXD_STAT_CRCV 0x100 /* Speculative CRC Valid */ | ||
1905 | #define IXGBE_RXD_STAT_VEXT 0x200 /* 1st VLAN found */ | ||
1906 | #define IXGBE_RXD_STAT_UDPV 0x400 /* Valid UDP checksum */ | ||
1907 | #define IXGBE_RXD_STAT_DYNINT 0x800 /* Pkt caused INT via DYNINT */ | ||
1908 | #define IXGBE_RXD_STAT_LLINT 0x800 /* Pkt caused Low Latency Interrupt */ | ||
1909 | #define IXGBE_RXD_STAT_TS 0x10000 /* Time Stamp */ | ||
1910 | #define IXGBE_RXD_STAT_SECP 0x20000 /* Security Processing */ | ||
1911 | #define IXGBE_RXD_STAT_LB 0x40000 /* Loopback Status */ | ||
1912 | #define IXGBE_RXD_STAT_ACK 0x8000 /* ACK Packet indication */ | ||
1913 | #define IXGBE_RXD_ERR_CE 0x01 /* CRC Error */ | ||
1914 | #define IXGBE_RXD_ERR_LE 0x02 /* Length Error */ | ||
1915 | #define IXGBE_RXD_ERR_PE 0x08 /* Packet Error */ | ||
1916 | #define IXGBE_RXD_ERR_OSE 0x10 /* Oversize Error */ | ||
1917 | #define IXGBE_RXD_ERR_USE 0x20 /* Undersize Error */ | ||
1918 | #define IXGBE_RXD_ERR_TCPE 0x40 /* TCP/UDP Checksum Error */ | ||
1919 | #define IXGBE_RXD_ERR_IPE 0x80 /* IP Checksum Error */ | ||
1920 | #define IXGBE_RXDADV_ERR_MASK 0xfff00000 /* RDESC.ERRORS mask */ | ||
1921 | #define IXGBE_RXDADV_ERR_SHIFT 20 /* RDESC.ERRORS shift */ | ||
1922 | #define IXGBE_RXDADV_ERR_FCEOFE 0x80000000 /* FCoEFe/IPE */ | ||
1923 | #define IXGBE_RXDADV_ERR_FCERR 0x00700000 /* FCERR/FDIRERR */ | ||
1924 | #define IXGBE_RXDADV_ERR_FDIR_LEN 0x00100000 /* FDIR Length error */ | ||
1925 | #define IXGBE_RXDADV_ERR_FDIR_DROP 0x00200000 /* FDIR Drop error */ | ||
1926 | #define IXGBE_RXDADV_ERR_FDIR_COLL 0x00400000 /* FDIR Collision error */ | ||
1927 | #define IXGBE_RXDADV_ERR_HBO 0x00800000 /*Header Buffer Overflow */ | ||
1928 | #define IXGBE_RXDADV_ERR_CE 0x01000000 /* CRC Error */ | ||
1929 | #define IXGBE_RXDADV_ERR_LE 0x02000000 /* Length Error */ | ||
1930 | #define IXGBE_RXDADV_ERR_PE 0x08000000 /* Packet Error */ | ||
1931 | #define IXGBE_RXDADV_ERR_OSE 0x10000000 /* Oversize Error */ | ||
1932 | #define IXGBE_RXDADV_ERR_USE 0x20000000 /* Undersize Error */ | ||
1933 | #define IXGBE_RXDADV_ERR_TCPE 0x40000000 /* TCP/UDP Checksum Error */ | ||
1934 | #define IXGBE_RXDADV_ERR_IPE 0x80000000 /* IP Checksum Error */ | ||
1935 | #define IXGBE_RXD_VLAN_ID_MASK 0x0FFF /* VLAN ID is in lower 12 bits */ | ||
1936 | #define IXGBE_RXD_PRI_MASK 0xE000 /* Priority is in upper 3 bits */ | ||
1937 | #define IXGBE_RXD_PRI_SHIFT 13 | ||
1938 | #define IXGBE_RXD_CFI_MASK 0x1000 /* CFI is bit 12 */ | ||
1939 | #define IXGBE_RXD_CFI_SHIFT 12 | ||
1940 | |||
1941 | #define IXGBE_RXDADV_STAT_DD IXGBE_RXD_STAT_DD /* Done */ | ||
1942 | #define IXGBE_RXDADV_STAT_EOP IXGBE_RXD_STAT_EOP /* End of Packet */ | ||
1943 | #define IXGBE_RXDADV_STAT_FLM IXGBE_RXD_STAT_FLM /* FDir Match */ | ||
1944 | #define IXGBE_RXDADV_STAT_VP IXGBE_RXD_STAT_VP /* IEEE VLAN Pkt */ | ||
1945 | #define IXGBE_RXDADV_STAT_MASK 0x000fffff /* Stat/NEXTP: bit 0-19 */ | ||
1946 | #define IXGBE_RXDADV_STAT_FCEOFS 0x00000040 /* FCoE EOF/SOF Stat */ | ||
1947 | #define IXGBE_RXDADV_STAT_FCSTAT 0x00000030 /* FCoE Pkt Stat */ | ||
1948 | #define IXGBE_RXDADV_STAT_FCSTAT_NOMTCH 0x00000000 /* 00: No Ctxt Match */ | ||
1949 | #define IXGBE_RXDADV_STAT_FCSTAT_NODDP 0x00000010 /* 01: Ctxt w/o DDP */ | ||
1950 | #define IXGBE_RXDADV_STAT_FCSTAT_FCPRSP 0x00000020 /* 10: Recv. FCP_RSP */ | ||
1951 | #define IXGBE_RXDADV_STAT_FCSTAT_DDP 0x00000030 /* 11: Ctxt w/ DDP */ | ||
1952 | |||
1953 | /* PSRTYPE bit definitions */ | ||
1954 | #define IXGBE_PSRTYPE_TCPHDR 0x00000010 | ||
1955 | #define IXGBE_PSRTYPE_UDPHDR 0x00000020 | ||
1956 | #define IXGBE_PSRTYPE_IPV4HDR 0x00000100 | ||
1957 | #define IXGBE_PSRTYPE_IPV6HDR 0x00000200 | ||
1958 | #define IXGBE_PSRTYPE_L2HDR 0x00001000 | ||
1959 | |||
1960 | /* SRRCTL bit definitions */ | ||
1961 | #define IXGBE_SRRCTL_BSIZEPKT_SHIFT 10 /* so many KBs */ | ||
1962 | #define IXGBE_SRRCTL_RDMTS_SHIFT 22 | ||
1963 | #define IXGBE_SRRCTL_RDMTS_MASK 0x01C00000 | ||
1964 | #define IXGBE_SRRCTL_DROP_EN 0x10000000 | ||
1965 | #define IXGBE_SRRCTL_BSIZEPKT_MASK 0x0000007F | ||
1966 | #define IXGBE_SRRCTL_BSIZEHDR_MASK 0x00003F00 | ||
1967 | #define IXGBE_SRRCTL_DESCTYPE_LEGACY 0x00000000 | ||
1968 | #define IXGBE_SRRCTL_DESCTYPE_ADV_ONEBUF 0x02000000 | ||
1969 | #define IXGBE_SRRCTL_DESCTYPE_HDR_SPLIT 0x04000000 | ||
1970 | #define IXGBE_SRRCTL_DESCTYPE_HDR_REPLICATION_LARGE_PKT 0x08000000 | ||
1971 | #define IXGBE_SRRCTL_DESCTYPE_HDR_SPLIT_ALWAYS 0x0A000000 | ||
1972 | #define IXGBE_SRRCTL_DESCTYPE_MASK 0x0E000000 | ||
1973 | |||
1974 | #define IXGBE_RXDPS_HDRSTAT_HDRSP 0x00008000 | ||
1975 | #define IXGBE_RXDPS_HDRSTAT_HDRLEN_MASK 0x000003FF | ||
1976 | |||
1977 | #define IXGBE_RXDADV_RSSTYPE_MASK 0x0000000F | ||
1978 | #define IXGBE_RXDADV_PKTTYPE_MASK 0x0000FFF0 | ||
1979 | #define IXGBE_RXDADV_PKTTYPE_MASK_EX 0x0001FFF0 | ||
1980 | #define IXGBE_RXDADV_HDRBUFLEN_MASK 0x00007FE0 | ||
1981 | #define IXGBE_RXDADV_RSCCNT_MASK 0x001E0000 | ||
1982 | #define IXGBE_RXDADV_RSCCNT_SHIFT 17 | ||
1983 | #define IXGBE_RXDADV_HDRBUFLEN_SHIFT 5 | ||
1984 | #define IXGBE_RXDADV_SPLITHEADER_EN 0x00001000 | ||
1985 | #define IXGBE_RXDADV_SPH 0x8000 | ||
1986 | |||
1987 | /* RSS Hash results */ | ||
1988 | #define IXGBE_RXDADV_RSSTYPE_NONE 0x00000000 | ||
1989 | #define IXGBE_RXDADV_RSSTYPE_IPV4_TCP 0x00000001 | ||
1990 | #define IXGBE_RXDADV_RSSTYPE_IPV4 0x00000002 | ||
1991 | #define IXGBE_RXDADV_RSSTYPE_IPV6_TCP 0x00000003 | ||
1992 | #define IXGBE_RXDADV_RSSTYPE_IPV6_EX 0x00000004 | ||
1993 | #define IXGBE_RXDADV_RSSTYPE_IPV6 0x00000005 | ||
1994 | #define IXGBE_RXDADV_RSSTYPE_IPV6_TCP_EX 0x00000006 | ||
1995 | #define IXGBE_RXDADV_RSSTYPE_IPV4_UDP 0x00000007 | ||
1996 | #define IXGBE_RXDADV_RSSTYPE_IPV6_UDP 0x00000008 | ||
1997 | #define IXGBE_RXDADV_RSSTYPE_IPV6_UDP_EX 0x00000009 | ||
1998 | |||
1999 | /* RSS Packet Types as indicated in the receive descriptor. */ | ||
2000 | #define IXGBE_RXDADV_PKTTYPE_NONE 0x00000000 | ||
2001 | #define IXGBE_RXDADV_PKTTYPE_IPV4 0x00000010 /* IPv4 hdr present */ | ||
2002 | #define IXGBE_RXDADV_PKTTYPE_IPV4_EX 0x00000020 /* IPv4 hdr + extensions */ | ||
2003 | #define IXGBE_RXDADV_PKTTYPE_IPV6 0x00000040 /* IPv6 hdr present */ | ||
2004 | #define IXGBE_RXDADV_PKTTYPE_IPV6_EX 0x00000080 /* IPv6 hdr + extensions */ | ||
2005 | #define IXGBE_RXDADV_PKTTYPE_TCP 0x00000100 /* TCP hdr present */ | ||
2006 | #define IXGBE_RXDADV_PKTTYPE_UDP 0x00000200 /* UDP hdr present */ | ||
2007 | #define IXGBE_RXDADV_PKTTYPE_SCTP 0x00000400 /* SCTP hdr present */ | ||
2008 | #define IXGBE_RXDADV_PKTTYPE_NFS 0x00000800 /* NFS hdr present */ | ||
2009 | #define IXGBE_RXDADV_PKTTYPE_IPSEC_ESP 0x00001000 /* IPSec ESP */ | ||
2010 | #define IXGBE_RXDADV_PKTTYPE_IPSEC_AH 0x00002000 /* IPSec AH */ | ||
2011 | #define IXGBE_RXDADV_PKTTYPE_LINKSEC 0x00004000 /* LinkSec Encap */ | ||
2012 | #define IXGBE_RXDADV_PKTTYPE_ETQF 0x00008000 /* PKTTYPE is ETQF index */ | ||
2013 | #define IXGBE_RXDADV_PKTTYPE_ETQF_MASK 0x00000070 /* ETQF has 8 indices */ | ||
2014 | #define IXGBE_RXDADV_PKTTYPE_ETQF_SHIFT 4 /* Right-shift 4 bits */ | ||
2015 | |||
2016 | /* Security Processing bit Indication */ | ||
2017 | #define IXGBE_RXDADV_LNKSEC_STATUS_SECP 0x00020000 | ||
2018 | #define IXGBE_RXDADV_LNKSEC_ERROR_NO_SA_MATCH 0x08000000 | ||
2019 | #define IXGBE_RXDADV_LNKSEC_ERROR_REPLAY_ERROR 0x10000000 | ||
2020 | #define IXGBE_RXDADV_LNKSEC_ERROR_BIT_MASK 0x18000000 | ||
2021 | #define IXGBE_RXDADV_LNKSEC_ERROR_BAD_SIG 0x18000000 | ||
2022 | |||
2023 | /* Masks to determine if packets should be dropped due to frame errors */ | ||
2024 | #define IXGBE_RXD_ERR_FRAME_ERR_MASK ( \ | ||
2025 | IXGBE_RXD_ERR_CE | \ | ||
2026 | IXGBE_RXD_ERR_LE | \ | ||
2027 | IXGBE_RXD_ERR_PE | \ | ||
2028 | IXGBE_RXD_ERR_OSE | \ | ||
2029 | IXGBE_RXD_ERR_USE) | ||
2030 | |||
2031 | #define IXGBE_RXDADV_ERR_FRAME_ERR_MASK ( \ | ||
2032 | IXGBE_RXDADV_ERR_CE | \ | ||
2033 | IXGBE_RXDADV_ERR_LE | \ | ||
2034 | IXGBE_RXDADV_ERR_PE | \ | ||
2035 | IXGBE_RXDADV_ERR_OSE | \ | ||
2036 | IXGBE_RXDADV_ERR_USE) | ||
2037 | |||
2038 | /* Multicast bit mask */ | ||
2039 | #define IXGBE_MCSTCTRL_MFE 0x4 | ||
2040 | |||
2041 | /* Number of Transmit and Receive Descriptors must be a multiple of 8 */ | ||
2042 | #define IXGBE_REQ_TX_DESCRIPTOR_MULTIPLE 8 | ||
2043 | #define IXGBE_REQ_RX_DESCRIPTOR_MULTIPLE 8 | ||
2044 | #define IXGBE_REQ_TX_BUFFER_GRANULARITY 1024 | ||
2045 | |||
2046 | /* Vlan-specific macros */ | ||
2047 | #define IXGBE_RX_DESC_SPECIAL_VLAN_MASK 0x0FFF /* VLAN ID in lower 12 bits */ | ||
2048 | #define IXGBE_RX_DESC_SPECIAL_PRI_MASK 0xE000 /* Priority in upper 3 bits */ | ||
2049 | #define IXGBE_RX_DESC_SPECIAL_PRI_SHIFT 0x000D /* Priority in upper 3 of 16 */ | ||
2050 | #define IXGBE_TX_DESC_SPECIAL_PRI_SHIFT IXGBE_RX_DESC_SPECIAL_PRI_SHIFT | ||
2051 | |||
2052 | /* SR-IOV specific macros */ | ||
2053 | #define IXGBE_MBVFICR_INDEX(vf_number) (vf_number >> 4) | ||
2054 | #define IXGBE_MBVFICR(_i) (0x00710 + (_i * 4)) | ||
2055 | #define IXGBE_VFLRE(_i) (((_i & 1) ? 0x001C0 : 0x00600)) | ||
2056 | #define IXGBE_VFLREC(_i) (0x00700 + (_i * 4)) | ||
2057 | |||
2058 | enum ixgbe_fdir_pballoc_type { | ||
2059 | IXGBE_FDIR_PBALLOC_NONE = 0, | ||
2060 | IXGBE_FDIR_PBALLOC_64K = 1, | ||
2061 | IXGBE_FDIR_PBALLOC_128K = 2, | ||
2062 | IXGBE_FDIR_PBALLOC_256K = 3, | ||
2063 | }; | ||
2064 | #define IXGBE_FDIR_PBALLOC_SIZE_SHIFT 16 | ||
2065 | |||
2066 | /* Flow Director register values */ | ||
2067 | #define IXGBE_FDIRCTRL_PBALLOC_64K 0x00000001 | ||
2068 | #define IXGBE_FDIRCTRL_PBALLOC_128K 0x00000002 | ||
2069 | #define IXGBE_FDIRCTRL_PBALLOC_256K 0x00000003 | ||
2070 | #define IXGBE_FDIRCTRL_INIT_DONE 0x00000008 | ||
2071 | #define IXGBE_FDIRCTRL_PERFECT_MATCH 0x00000010 | ||
2072 | #define IXGBE_FDIRCTRL_REPORT_STATUS 0x00000020 | ||
2073 | #define IXGBE_FDIRCTRL_REPORT_STATUS_ALWAYS 0x00000080 | ||
2074 | #define IXGBE_FDIRCTRL_DROP_Q_SHIFT 8 | ||
2075 | #define IXGBE_FDIRCTRL_FLEX_SHIFT 16 | ||
2076 | #define IXGBE_FDIRCTRL_SEARCHLIM 0x00800000 | ||
2077 | #define IXGBE_FDIRCTRL_MAX_LENGTH_SHIFT 24 | ||
2078 | #define IXGBE_FDIRCTRL_FULL_THRESH_MASK 0xF0000000 | ||
2079 | #define IXGBE_FDIRCTRL_FULL_THRESH_SHIFT 28 | ||
2080 | |||
2081 | #define IXGBE_FDIRTCPM_DPORTM_SHIFT 16 | ||
2082 | #define IXGBE_FDIRUDPM_DPORTM_SHIFT 16 | ||
2083 | #define IXGBE_FDIRIP6M_DIPM_SHIFT 16 | ||
2084 | #define IXGBE_FDIRM_VLANID 0x00000001 | ||
2085 | #define IXGBE_FDIRM_VLANP 0x00000002 | ||
2086 | #define IXGBE_FDIRM_POOL 0x00000004 | ||
2087 | #define IXGBE_FDIRM_L4P 0x00000008 | ||
2088 | #define IXGBE_FDIRM_FLEX 0x00000010 | ||
2089 | #define IXGBE_FDIRM_DIPv6 0x00000020 | ||
2090 | |||
2091 | #define IXGBE_FDIRFREE_FREE_MASK 0xFFFF | ||
2092 | #define IXGBE_FDIRFREE_FREE_SHIFT 0 | ||
2093 | #define IXGBE_FDIRFREE_COLL_MASK 0x7FFF0000 | ||
2094 | #define IXGBE_FDIRFREE_COLL_SHIFT 16 | ||
2095 | #define IXGBE_FDIRLEN_MAXLEN_MASK 0x3F | ||
2096 | #define IXGBE_FDIRLEN_MAXLEN_SHIFT 0 | ||
2097 | #define IXGBE_FDIRLEN_MAXHASH_MASK 0x7FFF0000 | ||
2098 | #define IXGBE_FDIRLEN_MAXHASH_SHIFT 16 | ||
2099 | #define IXGBE_FDIRUSTAT_ADD_MASK 0xFFFF | ||
2100 | #define IXGBE_FDIRUSTAT_ADD_SHIFT 0 | ||
2101 | #define IXGBE_FDIRUSTAT_REMOVE_MASK 0xFFFF0000 | ||
2102 | #define IXGBE_FDIRUSTAT_REMOVE_SHIFT 16 | ||
2103 | #define IXGBE_FDIRFSTAT_FADD_MASK 0x00FF | ||
2104 | #define IXGBE_FDIRFSTAT_FADD_SHIFT 0 | ||
2105 | #define IXGBE_FDIRFSTAT_FREMOVE_MASK 0xFF00 | ||
2106 | #define IXGBE_FDIRFSTAT_FREMOVE_SHIFT 8 | ||
2107 | #define IXGBE_FDIRPORT_DESTINATION_SHIFT 16 | ||
2108 | #define IXGBE_FDIRVLAN_FLEX_SHIFT 16 | ||
2109 | #define IXGBE_FDIRHASH_BUCKET_VALID_SHIFT 15 | ||
2110 | #define IXGBE_FDIRHASH_SIG_SW_INDEX_SHIFT 16 | ||
2111 | |||
2112 | #define IXGBE_FDIRCMD_CMD_MASK 0x00000003 | ||
2113 | #define IXGBE_FDIRCMD_CMD_ADD_FLOW 0x00000001 | ||
2114 | #define IXGBE_FDIRCMD_CMD_REMOVE_FLOW 0x00000002 | ||
2115 | #define IXGBE_FDIRCMD_CMD_QUERY_REM_FILT 0x00000003 | ||
2116 | #define IXGBE_FDIRCMD_FILTER_VALID 0x00000004 | ||
2117 | #define IXGBE_FDIRCMD_FILTER_UPDATE 0x00000008 | ||
2118 | #define IXGBE_FDIRCMD_IPv6DMATCH 0x00000010 | ||
2119 | #define IXGBE_FDIRCMD_L4TYPE_UDP 0x00000020 | ||
2120 | #define IXGBE_FDIRCMD_L4TYPE_TCP 0x00000040 | ||
2121 | #define IXGBE_FDIRCMD_L4TYPE_SCTP 0x00000060 | ||
2122 | #define IXGBE_FDIRCMD_IPV6 0x00000080 | ||
2123 | #define IXGBE_FDIRCMD_CLEARHT 0x00000100 | ||
2124 | #define IXGBE_FDIRCMD_DROP 0x00000200 | ||
2125 | #define IXGBE_FDIRCMD_INT 0x00000400 | ||
2126 | #define IXGBE_FDIRCMD_LAST 0x00000800 | ||
2127 | #define IXGBE_FDIRCMD_COLLISION 0x00001000 | ||
2128 | #define IXGBE_FDIRCMD_QUEUE_EN 0x00008000 | ||
2129 | #define IXGBE_FDIRCMD_FLOW_TYPE_SHIFT 5 | ||
2130 | #define IXGBE_FDIRCMD_RX_QUEUE_SHIFT 16 | ||
2131 | #define IXGBE_FDIRCMD_VT_POOL_SHIFT 24 | ||
2132 | #define IXGBE_FDIR_INIT_DONE_POLL 10 | ||
2133 | #define IXGBE_FDIRCMD_CMD_POLL 10 | ||
2134 | |||
2135 | #define IXGBE_FDIR_DROP_QUEUE 127 | ||
2136 | |||
2137 | /* Manageablility Host Interface defines */ | ||
2138 | #define IXGBE_HI_MAX_BLOCK_BYTE_LENGTH 1792 /* Num of bytes in range */ | ||
2139 | #define IXGBE_HI_MAX_BLOCK_DWORD_LENGTH 448 /* Num of dwords in range */ | ||
2140 | #define IXGBE_HI_COMMAND_TIMEOUT 500 /* Process HI command limit */ | ||
2141 | |||
2142 | /* CEM Support */ | ||
2143 | #define FW_CEM_HDR_LEN 0x4 | ||
2144 | #define FW_CEM_CMD_DRIVER_INFO 0xDD | ||
2145 | #define FW_CEM_CMD_DRIVER_INFO_LEN 0x5 | ||
2146 | #define FW_CEM_CMD_RESERVED 0x0 | ||
2147 | #define FW_CEM_UNUSED_VER 0x0 | ||
2148 | #define FW_CEM_MAX_RETRIES 3 | ||
2149 | #define FW_CEM_RESP_STATUS_SUCCESS 0x1 | ||
2150 | |||
2151 | /* Host Interface Command Structures */ | ||
2152 | struct ixgbe_hic_hdr { | ||
2153 | u8 cmd; | ||
2154 | u8 buf_len; | ||
2155 | union { | ||
2156 | u8 cmd_resv; | ||
2157 | u8 ret_status; | ||
2158 | } cmd_or_resp; | ||
2159 | u8 checksum; | ||
2160 | }; | ||
2161 | |||
2162 | struct ixgbe_hic_drv_info { | ||
2163 | struct ixgbe_hic_hdr hdr; | ||
2164 | u8 port_num; | ||
2165 | u8 ver_sub; | ||
2166 | u8 ver_build; | ||
2167 | u8 ver_min; | ||
2168 | u8 ver_maj; | ||
2169 | u8 pad; /* end spacing to ensure length is mult. of dword */ | ||
2170 | u16 pad2; /* end spacing to ensure length is mult. of dword2 */ | ||
2171 | }; | ||
2172 | |||
2173 | /* Transmit Descriptor - Advanced */ | ||
2174 | union ixgbe_adv_tx_desc { | ||
2175 | struct { | ||
2176 | __le64 buffer_addr; /* Address of descriptor's data buf */ | ||
2177 | __le32 cmd_type_len; | ||
2178 | __le32 olinfo_status; | ||
2179 | } read; | ||
2180 | struct { | ||
2181 | __le64 rsvd; /* Reserved */ | ||
2182 | __le32 nxtseq_seed; | ||
2183 | __le32 status; | ||
2184 | } wb; | ||
2185 | }; | ||
2186 | |||
2187 | /* Receive Descriptor - Advanced */ | ||
2188 | union ixgbe_adv_rx_desc { | ||
2189 | struct { | ||
2190 | __le64 pkt_addr; /* Packet buffer address */ | ||
2191 | __le64 hdr_addr; /* Header buffer address */ | ||
2192 | } read; | ||
2193 | struct { | ||
2194 | struct { | ||
2195 | union { | ||
2196 | __le32 data; | ||
2197 | struct { | ||
2198 | __le16 pkt_info; /* RSS, Pkt type */ | ||
2199 | __le16 hdr_info; /* Splithdr, hdrlen */ | ||
2200 | } hs_rss; | ||
2201 | } lo_dword; | ||
2202 | union { | ||
2203 | __le32 rss; /* RSS Hash */ | ||
2204 | struct { | ||
2205 | __le16 ip_id; /* IP id */ | ||
2206 | __le16 csum; /* Packet Checksum */ | ||
2207 | } csum_ip; | ||
2208 | } hi_dword; | ||
2209 | } lower; | ||
2210 | struct { | ||
2211 | __le32 status_error; /* ext status/error */ | ||
2212 | __le16 length; /* Packet length */ | ||
2213 | __le16 vlan; /* VLAN tag */ | ||
2214 | } upper; | ||
2215 | } wb; /* writeback */ | ||
2216 | }; | ||
2217 | |||
2218 | /* Context descriptors */ | ||
2219 | struct ixgbe_adv_tx_context_desc { | ||
2220 | __le32 vlan_macip_lens; | ||
2221 | __le32 seqnum_seed; | ||
2222 | __le32 type_tucmd_mlhl; | ||
2223 | __le32 mss_l4len_idx; | ||
2224 | }; | ||
2225 | |||
2226 | /* Adv Transmit Descriptor Config Masks */ | ||
2227 | #define IXGBE_ADVTXD_DTALEN_MASK 0x0000FFFF /* Data buf length(bytes) */ | ||
2228 | #define IXGBE_ADVTXD_MAC_LINKSEC 0x00040000 /* Insert LinkSec */ | ||
2229 | #define IXGBE_ADVTXD_IPSEC_SA_INDEX_MASK 0x000003FF /* IPSec SA index */ | ||
2230 | #define IXGBE_ADVTXD_IPSEC_ESP_LEN_MASK 0x000001FF /* IPSec ESP length */ | ||
2231 | #define IXGBE_ADVTXD_DTYP_MASK 0x00F00000 /* DTYP mask */ | ||
2232 | #define IXGBE_ADVTXD_DTYP_CTXT 0x00200000 /* Advanced Context Desc */ | ||
2233 | #define IXGBE_ADVTXD_DTYP_DATA 0x00300000 /* Advanced Data Descriptor */ | ||
2234 | #define IXGBE_ADVTXD_DCMD_EOP IXGBE_TXD_CMD_EOP /* End of Packet */ | ||
2235 | #define IXGBE_ADVTXD_DCMD_IFCS IXGBE_TXD_CMD_IFCS /* Insert FCS */ | ||
2236 | #define IXGBE_ADVTXD_DCMD_RS IXGBE_TXD_CMD_RS /* Report Status */ | ||
2237 | #define IXGBE_ADVTXD_DCMD_DDTYP_ISCSI 0x10000000 /* DDP hdr type or iSCSI */ | ||
2238 | #define IXGBE_ADVTXD_DCMD_DEXT IXGBE_TXD_CMD_DEXT /* Desc ext (1=Adv) */ | ||
2239 | #define IXGBE_ADVTXD_DCMD_VLE IXGBE_TXD_CMD_VLE /* VLAN pkt enable */ | ||
2240 | #define IXGBE_ADVTXD_DCMD_TSE 0x80000000 /* TCP Seg enable */ | ||
2241 | #define IXGBE_ADVTXD_STAT_DD IXGBE_TXD_STAT_DD /* Descriptor Done */ | ||
2242 | #define IXGBE_ADVTXD_STAT_SN_CRC 0x00000002 /* NXTSEQ/SEED pres in WB */ | ||
2243 | #define IXGBE_ADVTXD_STAT_RSV 0x0000000C /* STA Reserved */ | ||
2244 | #define IXGBE_ADVTXD_IDX_SHIFT 4 /* Adv desc Index shift */ | ||
2245 | #define IXGBE_ADVTXD_CC 0x00000080 /* Check Context */ | ||
2246 | #define IXGBE_ADVTXD_POPTS_SHIFT 8 /* Adv desc POPTS shift */ | ||
2247 | #define IXGBE_ADVTXD_POPTS_IXSM (IXGBE_TXD_POPTS_IXSM << \ | ||
2248 | IXGBE_ADVTXD_POPTS_SHIFT) | ||
2249 | #define IXGBE_ADVTXD_POPTS_TXSM (IXGBE_TXD_POPTS_TXSM << \ | ||
2250 | IXGBE_ADVTXD_POPTS_SHIFT) | ||
2251 | #define IXGBE_ADVTXD_POPTS_ISCO_1ST 0x00000000 /* 1st TSO of iSCSI PDU */ | ||
2252 | #define IXGBE_ADVTXD_POPTS_ISCO_MDL 0x00000800 /* Middle TSO of iSCSI PDU */ | ||
2253 | #define IXGBE_ADVTXD_POPTS_ISCO_LAST 0x00001000 /* Last TSO of iSCSI PDU */ | ||
2254 | #define IXGBE_ADVTXD_POPTS_ISCO_FULL 0x00001800 /* 1st&Last TSO-full iSCSI PDU */ | ||
2255 | #define IXGBE_ADVTXD_POPTS_RSV 0x00002000 /* POPTS Reserved */ | ||
2256 | #define IXGBE_ADVTXD_PAYLEN_SHIFT 14 /* Adv desc PAYLEN shift */ | ||
2257 | #define IXGBE_ADVTXD_MACLEN_SHIFT 9 /* Adv ctxt desc mac len shift */ | ||
2258 | #define IXGBE_ADVTXD_VLAN_SHIFT 16 /* Adv ctxt vlan tag shift */ | ||
2259 | #define IXGBE_ADVTXD_TUCMD_IPV4 0x00000400 /* IP Packet Type: 1=IPv4 */ | ||
2260 | #define IXGBE_ADVTXD_TUCMD_IPV6 0x00000000 /* IP Packet Type: 0=IPv6 */ | ||
2261 | #define IXGBE_ADVTXD_TUCMD_L4T_UDP 0x00000000 /* L4 Packet TYPE of UDP */ | ||
2262 | #define IXGBE_ADVTXD_TUCMD_L4T_TCP 0x00000800 /* L4 Packet TYPE of TCP */ | ||
2263 | #define IXGBE_ADVTXD_TUCMD_L4T_SCTP 0x00001000 /* L4 Packet TYPE of SCTP */ | ||
2264 | #define IXGBE_ADVTXD_TUCMD_MKRREQ 0x00002000 /*Req requires Markers and CRC*/ | ||
2265 | #define IXGBE_ADVTXD_POPTS_IPSEC 0x00000400 /* IPSec offload request */ | ||
2266 | #define IXGBE_ADVTXD_TUCMD_IPSEC_TYPE_ESP 0x00002000 /* IPSec Type ESP */ | ||
2267 | #define IXGBE_ADVTXD_TUCMD_IPSEC_ENCRYPT_EN 0x00004000/* ESP Encrypt Enable */ | ||
2268 | #define IXGBE_ADVTXT_TUCMD_FCOE 0x00008000 /* FCoE Frame Type */ | ||
2269 | #define IXGBE_ADVTXD_FCOEF_EOF_MASK (0x3 << 10) /* FC EOF index */ | ||
2270 | #define IXGBE_ADVTXD_FCOEF_SOF ((1 << 2) << 10) /* FC SOF index */ | ||
2271 | #define IXGBE_ADVTXD_FCOEF_PARINC ((1 << 3) << 10) /* Rel_Off in F_CTL */ | ||
2272 | #define IXGBE_ADVTXD_FCOEF_ORIE ((1 << 4) << 10) /* Orientation: End */ | ||
2273 | #define IXGBE_ADVTXD_FCOEF_ORIS ((1 << 5) << 10) /* Orientation: Start */ | ||
2274 | #define IXGBE_ADVTXD_FCOEF_EOF_N (0x0 << 10) /* 00: EOFn */ | ||
2275 | #define IXGBE_ADVTXD_FCOEF_EOF_T (0x1 << 10) /* 01: EOFt */ | ||
2276 | #define IXGBE_ADVTXD_FCOEF_EOF_NI (0x2 << 10) /* 10: EOFni */ | ||
2277 | #define IXGBE_ADVTXD_FCOEF_EOF_A (0x3 << 10) /* 11: EOFa */ | ||
2278 | #define IXGBE_ADVTXD_L4LEN_SHIFT 8 /* Adv ctxt L4LEN shift */ | ||
2279 | #define IXGBE_ADVTXD_MSS_SHIFT 16 /* Adv ctxt MSS shift */ | ||
2280 | |||
2281 | /* Autonegotiation advertised speeds */ | ||
2282 | typedef u32 ixgbe_autoneg_advertised; | ||
2283 | /* Link speed */ | ||
2284 | typedef u32 ixgbe_link_speed; | ||
2285 | #define IXGBE_LINK_SPEED_UNKNOWN 0 | ||
2286 | #define IXGBE_LINK_SPEED_100_FULL 0x0008 | ||
2287 | #define IXGBE_LINK_SPEED_1GB_FULL 0x0020 | ||
2288 | #define IXGBE_LINK_SPEED_10GB_FULL 0x0080 | ||
2289 | #define IXGBE_LINK_SPEED_82598_AUTONEG (IXGBE_LINK_SPEED_1GB_FULL | \ | ||
2290 | IXGBE_LINK_SPEED_10GB_FULL) | ||
2291 | #define IXGBE_LINK_SPEED_82599_AUTONEG (IXGBE_LINK_SPEED_100_FULL | \ | ||
2292 | IXGBE_LINK_SPEED_1GB_FULL | \ | ||
2293 | IXGBE_LINK_SPEED_10GB_FULL) | ||
2294 | |||
2295 | |||
2296 | /* Physical layer type */ | ||
2297 | typedef u32 ixgbe_physical_layer; | ||
2298 | #define IXGBE_PHYSICAL_LAYER_UNKNOWN 0 | ||
2299 | #define IXGBE_PHYSICAL_LAYER_10GBASE_T 0x0001 | ||
2300 | #define IXGBE_PHYSICAL_LAYER_1000BASE_T 0x0002 | ||
2301 | #define IXGBE_PHYSICAL_LAYER_100BASE_TX 0x0004 | ||
2302 | #define IXGBE_PHYSICAL_LAYER_SFP_PLUS_CU 0x0008 | ||
2303 | #define IXGBE_PHYSICAL_LAYER_10GBASE_LR 0x0010 | ||
2304 | #define IXGBE_PHYSICAL_LAYER_10GBASE_LRM 0x0020 | ||
2305 | #define IXGBE_PHYSICAL_LAYER_10GBASE_SR 0x0040 | ||
2306 | #define IXGBE_PHYSICAL_LAYER_10GBASE_KX4 0x0080 | ||
2307 | #define IXGBE_PHYSICAL_LAYER_10GBASE_CX4 0x0100 | ||
2308 | #define IXGBE_PHYSICAL_LAYER_1000BASE_KX 0x0200 | ||
2309 | #define IXGBE_PHYSICAL_LAYER_1000BASE_BX 0x0400 | ||
2310 | #define IXGBE_PHYSICAL_LAYER_10GBASE_KR 0x0800 | ||
2311 | #define IXGBE_PHYSICAL_LAYER_10GBASE_XAUI 0x1000 | ||
2312 | #define IXGBE_PHYSICAL_LAYER_SFP_ACTIVE_DA 0x2000 | ||
2313 | |||
2314 | /* Flow Control Macros */ | ||
2315 | #define PAUSE_RTT 8 | ||
2316 | #define PAUSE_MTU(MTU) ((MTU + 1024 - 1) / 1024) | ||
2317 | |||
2318 | #define FC_HIGH_WATER(MTU) ((((PAUSE_RTT + PAUSE_MTU(MTU)) * 144) + 99) / 100 +\ | ||
2319 | PAUSE_MTU(MTU)) | ||
2320 | #define FC_LOW_WATER(MTU) (2 * (2 * PAUSE_MTU(MTU) + PAUSE_RTT)) | ||
2321 | |||
2322 | /* Software ATR hash keys */ | ||
2323 | #define IXGBE_ATR_BUCKET_HASH_KEY 0x3DAD14E2 | ||
2324 | #define IXGBE_ATR_SIGNATURE_HASH_KEY 0x174D3614 | ||
2325 | |||
2326 | /* Software ATR input stream values and masks */ | ||
2327 | #define IXGBE_ATR_HASH_MASK 0x7fff | ||
2328 | #define IXGBE_ATR_L4TYPE_MASK 0x3 | ||
2329 | #define IXGBE_ATR_L4TYPE_UDP 0x1 | ||
2330 | #define IXGBE_ATR_L4TYPE_TCP 0x2 | ||
2331 | #define IXGBE_ATR_L4TYPE_SCTP 0x3 | ||
2332 | #define IXGBE_ATR_L4TYPE_IPV6_MASK 0x4 | ||
2333 | enum ixgbe_atr_flow_type { | ||
2334 | IXGBE_ATR_FLOW_TYPE_IPV4 = 0x0, | ||
2335 | IXGBE_ATR_FLOW_TYPE_UDPV4 = 0x1, | ||
2336 | IXGBE_ATR_FLOW_TYPE_TCPV4 = 0x2, | ||
2337 | IXGBE_ATR_FLOW_TYPE_SCTPV4 = 0x3, | ||
2338 | IXGBE_ATR_FLOW_TYPE_IPV6 = 0x4, | ||
2339 | IXGBE_ATR_FLOW_TYPE_UDPV6 = 0x5, | ||
2340 | IXGBE_ATR_FLOW_TYPE_TCPV6 = 0x6, | ||
2341 | IXGBE_ATR_FLOW_TYPE_SCTPV6 = 0x7, | ||
2342 | }; | ||
2343 | |||
2344 | /* Flow Director ATR input struct. */ | ||
2345 | union ixgbe_atr_input { | ||
2346 | /* | ||
2347 | * Byte layout in order, all values with MSB first: | ||
2348 | * | ||
2349 | * vm_pool - 1 byte | ||
2350 | * flow_type - 1 byte | ||
2351 | * vlan_id - 2 bytes | ||
2352 | * src_ip - 16 bytes | ||
2353 | * dst_ip - 16 bytes | ||
2354 | * src_port - 2 bytes | ||
2355 | * dst_port - 2 bytes | ||
2356 | * flex_bytes - 2 bytes | ||
2357 | * bkt_hash - 2 bytes | ||
2358 | */ | ||
2359 | struct { | ||
2360 | u8 vm_pool; | ||
2361 | u8 flow_type; | ||
2362 | __be16 vlan_id; | ||
2363 | __be32 dst_ip[4]; | ||
2364 | __be32 src_ip[4]; | ||
2365 | __be16 src_port; | ||
2366 | __be16 dst_port; | ||
2367 | __be16 flex_bytes; | ||
2368 | __be16 bkt_hash; | ||
2369 | } formatted; | ||
2370 | __be32 dword_stream[11]; | ||
2371 | }; | ||
2372 | |||
2373 | /* Flow Director compressed ATR hash input struct */ | ||
2374 | union ixgbe_atr_hash_dword { | ||
2375 | struct { | ||
2376 | u8 vm_pool; | ||
2377 | u8 flow_type; | ||
2378 | __be16 vlan_id; | ||
2379 | } formatted; | ||
2380 | __be32 ip; | ||
2381 | struct { | ||
2382 | __be16 src; | ||
2383 | __be16 dst; | ||
2384 | } port; | ||
2385 | __be16 flex_bytes; | ||
2386 | __be32 dword; | ||
2387 | }; | ||
2388 | |||
2389 | enum ixgbe_eeprom_type { | ||
2390 | ixgbe_eeprom_uninitialized = 0, | ||
2391 | ixgbe_eeprom_spi, | ||
2392 | ixgbe_flash, | ||
2393 | ixgbe_eeprom_none /* No NVM support */ | ||
2394 | }; | ||
2395 | |||
2396 | enum ixgbe_mac_type { | ||
2397 | ixgbe_mac_unknown = 0, | ||
2398 | ixgbe_mac_82598EB, | ||
2399 | ixgbe_mac_82599EB, | ||
2400 | ixgbe_mac_X540, | ||
2401 | ixgbe_num_macs | ||
2402 | }; | ||
2403 | |||
2404 | enum ixgbe_phy_type { | ||
2405 | ixgbe_phy_unknown = 0, | ||
2406 | ixgbe_phy_none, | ||
2407 | ixgbe_phy_tn, | ||
2408 | ixgbe_phy_aq, | ||
2409 | ixgbe_phy_cu_unknown, | ||
2410 | ixgbe_phy_qt, | ||
2411 | ixgbe_phy_xaui, | ||
2412 | ixgbe_phy_nl, | ||
2413 | ixgbe_phy_sfp_passive_tyco, | ||
2414 | ixgbe_phy_sfp_passive_unknown, | ||
2415 | ixgbe_phy_sfp_active_unknown, | ||
2416 | ixgbe_phy_sfp_avago, | ||
2417 | ixgbe_phy_sfp_ftl, | ||
2418 | ixgbe_phy_sfp_ftl_active, | ||
2419 | ixgbe_phy_sfp_unknown, | ||
2420 | ixgbe_phy_sfp_intel, | ||
2421 | ixgbe_phy_sfp_unsupported, | ||
2422 | ixgbe_phy_generic | ||
2423 | }; | ||
2424 | |||
2425 | /* | ||
2426 | * SFP+ module type IDs: | ||
2427 | * | ||
2428 | * ID Module Type | ||
2429 | * ============= | ||
2430 | * 0 SFP_DA_CU | ||
2431 | * 1 SFP_SR | ||
2432 | * 2 SFP_LR | ||
2433 | * 3 SFP_DA_CU_CORE0 - 82599-specific | ||
2434 | * 4 SFP_DA_CU_CORE1 - 82599-specific | ||
2435 | * 5 SFP_SR/LR_CORE0 - 82599-specific | ||
2436 | * 6 SFP_SR/LR_CORE1 - 82599-specific | ||
2437 | */ | ||
2438 | enum ixgbe_sfp_type { | ||
2439 | ixgbe_sfp_type_da_cu = 0, | ||
2440 | ixgbe_sfp_type_sr = 1, | ||
2441 | ixgbe_sfp_type_lr = 2, | ||
2442 | ixgbe_sfp_type_da_cu_core0 = 3, | ||
2443 | ixgbe_sfp_type_da_cu_core1 = 4, | ||
2444 | ixgbe_sfp_type_srlr_core0 = 5, | ||
2445 | ixgbe_sfp_type_srlr_core1 = 6, | ||
2446 | ixgbe_sfp_type_da_act_lmt_core0 = 7, | ||
2447 | ixgbe_sfp_type_da_act_lmt_core1 = 8, | ||
2448 | ixgbe_sfp_type_1g_cu_core0 = 9, | ||
2449 | ixgbe_sfp_type_1g_cu_core1 = 10, | ||
2450 | ixgbe_sfp_type_not_present = 0xFFFE, | ||
2451 | ixgbe_sfp_type_unknown = 0xFFFF | ||
2452 | }; | ||
2453 | |||
2454 | enum ixgbe_media_type { | ||
2455 | ixgbe_media_type_unknown = 0, | ||
2456 | ixgbe_media_type_fiber, | ||
2457 | ixgbe_media_type_fiber_lco, | ||
2458 | ixgbe_media_type_copper, | ||
2459 | ixgbe_media_type_backplane, | ||
2460 | ixgbe_media_type_cx4, | ||
2461 | ixgbe_media_type_virtual | ||
2462 | }; | ||
2463 | |||
2464 | /* Flow Control Settings */ | ||
2465 | enum ixgbe_fc_mode { | ||
2466 | ixgbe_fc_none = 0, | ||
2467 | ixgbe_fc_rx_pause, | ||
2468 | ixgbe_fc_tx_pause, | ||
2469 | ixgbe_fc_full, | ||
2470 | #ifdef CONFIG_DCB | ||
2471 | ixgbe_fc_pfc, | ||
2472 | #endif | ||
2473 | ixgbe_fc_default | ||
2474 | }; | ||
2475 | |||
2476 | /* Smart Speed Settings */ | ||
2477 | #define IXGBE_SMARTSPEED_MAX_RETRIES 3 | ||
2478 | enum ixgbe_smart_speed { | ||
2479 | ixgbe_smart_speed_auto = 0, | ||
2480 | ixgbe_smart_speed_on, | ||
2481 | ixgbe_smart_speed_off | ||
2482 | }; | ||
2483 | |||
2484 | /* PCI bus types */ | ||
2485 | enum ixgbe_bus_type { | ||
2486 | ixgbe_bus_type_unknown = 0, | ||
2487 | ixgbe_bus_type_pci, | ||
2488 | ixgbe_bus_type_pcix, | ||
2489 | ixgbe_bus_type_pci_express, | ||
2490 | ixgbe_bus_type_reserved | ||
2491 | }; | ||
2492 | |||
2493 | /* PCI bus speeds */ | ||
2494 | enum ixgbe_bus_speed { | ||
2495 | ixgbe_bus_speed_unknown = 0, | ||
2496 | ixgbe_bus_speed_33 = 33, | ||
2497 | ixgbe_bus_speed_66 = 66, | ||
2498 | ixgbe_bus_speed_100 = 100, | ||
2499 | ixgbe_bus_speed_120 = 120, | ||
2500 | ixgbe_bus_speed_133 = 133, | ||
2501 | ixgbe_bus_speed_2500 = 2500, | ||
2502 | ixgbe_bus_speed_5000 = 5000, | ||
2503 | ixgbe_bus_speed_reserved | ||
2504 | }; | ||
2505 | |||
2506 | /* PCI bus widths */ | ||
2507 | enum ixgbe_bus_width { | ||
2508 | ixgbe_bus_width_unknown = 0, | ||
2509 | ixgbe_bus_width_pcie_x1 = 1, | ||
2510 | ixgbe_bus_width_pcie_x2 = 2, | ||
2511 | ixgbe_bus_width_pcie_x4 = 4, | ||
2512 | ixgbe_bus_width_pcie_x8 = 8, | ||
2513 | ixgbe_bus_width_32 = 32, | ||
2514 | ixgbe_bus_width_64 = 64, | ||
2515 | ixgbe_bus_width_reserved | ||
2516 | }; | ||
2517 | |||
2518 | struct ixgbe_addr_filter_info { | ||
2519 | u32 num_mc_addrs; | ||
2520 | u32 rar_used_count; | ||
2521 | u32 mta_in_use; | ||
2522 | u32 overflow_promisc; | ||
2523 | bool uc_set_promisc; | ||
2524 | bool user_set_promisc; | ||
2525 | }; | ||
2526 | |||
2527 | /* Bus parameters */ | ||
2528 | struct ixgbe_bus_info { | ||
2529 | enum ixgbe_bus_speed speed; | ||
2530 | enum ixgbe_bus_width width; | ||
2531 | enum ixgbe_bus_type type; | ||
2532 | |||
2533 | u16 func; | ||
2534 | u16 lan_id; | ||
2535 | }; | ||
2536 | |||
2537 | /* Flow control parameters */ | ||
2538 | struct ixgbe_fc_info { | ||
2539 | u32 high_water; /* Flow Control High-water */ | ||
2540 | u32 low_water; /* Flow Control Low-water */ | ||
2541 | u16 pause_time; /* Flow Control Pause timer */ | ||
2542 | bool send_xon; /* Flow control send XON */ | ||
2543 | bool strict_ieee; /* Strict IEEE mode */ | ||
2544 | bool disable_fc_autoneg; /* Do not autonegotiate FC */ | ||
2545 | bool fc_was_autonegged; /* Is current_mode the result of autonegging? */ | ||
2546 | enum ixgbe_fc_mode current_mode; /* FC mode in effect */ | ||
2547 | enum ixgbe_fc_mode requested_mode; /* FC mode requested by caller */ | ||
2548 | }; | ||
2549 | |||
2550 | /* Statistics counters collected by the MAC */ | ||
2551 | struct ixgbe_hw_stats { | ||
2552 | u64 crcerrs; | ||
2553 | u64 illerrc; | ||
2554 | u64 errbc; | ||
2555 | u64 mspdc; | ||
2556 | u64 mpctotal; | ||
2557 | u64 mpc[8]; | ||
2558 | u64 mlfc; | ||
2559 | u64 mrfc; | ||
2560 | u64 rlec; | ||
2561 | u64 lxontxc; | ||
2562 | u64 lxonrxc; | ||
2563 | u64 lxofftxc; | ||
2564 | u64 lxoffrxc; | ||
2565 | u64 pxontxc[8]; | ||
2566 | u64 pxonrxc[8]; | ||
2567 | u64 pxofftxc[8]; | ||
2568 | u64 pxoffrxc[8]; | ||
2569 | u64 prc64; | ||
2570 | u64 prc127; | ||
2571 | u64 prc255; | ||
2572 | u64 prc511; | ||
2573 | u64 prc1023; | ||
2574 | u64 prc1522; | ||
2575 | u64 gprc; | ||
2576 | u64 bprc; | ||
2577 | u64 mprc; | ||
2578 | u64 gptc; | ||
2579 | u64 gorc; | ||
2580 | u64 gotc; | ||
2581 | u64 rnbc[8]; | ||
2582 | u64 ruc; | ||
2583 | u64 rfc; | ||
2584 | u64 roc; | ||
2585 | u64 rjc; | ||
2586 | u64 mngprc; | ||
2587 | u64 mngpdc; | ||
2588 | u64 mngptc; | ||
2589 | u64 tor; | ||
2590 | u64 tpr; | ||
2591 | u64 tpt; | ||
2592 | u64 ptc64; | ||
2593 | u64 ptc127; | ||
2594 | u64 ptc255; | ||
2595 | u64 ptc511; | ||
2596 | u64 ptc1023; | ||
2597 | u64 ptc1522; | ||
2598 | u64 mptc; | ||
2599 | u64 bptc; | ||
2600 | u64 xec; | ||
2601 | u64 rqsmr[16]; | ||
2602 | u64 tqsmr[8]; | ||
2603 | u64 qprc[16]; | ||
2604 | u64 qptc[16]; | ||
2605 | u64 qbrc[16]; | ||
2606 | u64 qbtc[16]; | ||
2607 | u64 qprdc[16]; | ||
2608 | u64 pxon2offc[8]; | ||
2609 | u64 fdirustat_add; | ||
2610 | u64 fdirustat_remove; | ||
2611 | u64 fdirfstat_fadd; | ||
2612 | u64 fdirfstat_fremove; | ||
2613 | u64 fdirmatch; | ||
2614 | u64 fdirmiss; | ||
2615 | u64 fccrc; | ||
2616 | u64 fcoerpdc; | ||
2617 | u64 fcoeprc; | ||
2618 | u64 fcoeptc; | ||
2619 | u64 fcoedwrc; | ||
2620 | u64 fcoedwtc; | ||
2621 | u64 b2ospc; | ||
2622 | u64 b2ogprc; | ||
2623 | u64 o2bgptc; | ||
2624 | u64 o2bspc; | ||
2625 | }; | ||
2626 | |||
2627 | /* forward declaration */ | ||
2628 | struct ixgbe_hw; | ||
2629 | |||
2630 | /* iterator type for walking multicast address lists */ | ||
2631 | typedef u8* (*ixgbe_mc_addr_itr) (struct ixgbe_hw *hw, u8 **mc_addr_ptr, | ||
2632 | u32 *vmdq); | ||
2633 | |||
2634 | /* Function pointer table */ | ||
2635 | struct ixgbe_eeprom_operations { | ||
2636 | s32 (*init_params)(struct ixgbe_hw *); | ||
2637 | s32 (*read)(struct ixgbe_hw *, u16, u16 *); | ||
2638 | s32 (*read_buffer)(struct ixgbe_hw *, u16, u16, u16 *); | ||
2639 | s32 (*write)(struct ixgbe_hw *, u16, u16); | ||
2640 | s32 (*write_buffer)(struct ixgbe_hw *, u16, u16, u16 *); | ||
2641 | s32 (*validate_checksum)(struct ixgbe_hw *, u16 *); | ||
2642 | s32 (*update_checksum)(struct ixgbe_hw *); | ||
2643 | u16 (*calc_checksum)(struct ixgbe_hw *); | ||
2644 | }; | ||
2645 | |||
2646 | struct ixgbe_mac_operations { | ||
2647 | s32 (*init_hw)(struct ixgbe_hw *); | ||
2648 | s32 (*reset_hw)(struct ixgbe_hw *); | ||
2649 | s32 (*start_hw)(struct ixgbe_hw *); | ||
2650 | s32 (*clear_hw_cntrs)(struct ixgbe_hw *); | ||
2651 | enum ixgbe_media_type (*get_media_type)(struct ixgbe_hw *); | ||
2652 | u32 (*get_supported_physical_layer)(struct ixgbe_hw *); | ||
2653 | s32 (*get_mac_addr)(struct ixgbe_hw *, u8 *); | ||
2654 | s32 (*get_san_mac_addr)(struct ixgbe_hw *, u8 *); | ||
2655 | s32 (*get_device_caps)(struct ixgbe_hw *, u16 *); | ||
2656 | s32 (*get_wwn_prefix)(struct ixgbe_hw *, u16 *, u16 *); | ||
2657 | s32 (*stop_adapter)(struct ixgbe_hw *); | ||
2658 | s32 (*get_bus_info)(struct ixgbe_hw *); | ||
2659 | void (*set_lan_id)(struct ixgbe_hw *); | ||
2660 | s32 (*read_analog_reg8)(struct ixgbe_hw*, u32, u8*); | ||
2661 | s32 (*write_analog_reg8)(struct ixgbe_hw*, u32, u8); | ||
2662 | s32 (*setup_sfp)(struct ixgbe_hw *); | ||
2663 | s32 (*enable_rx_dma)(struct ixgbe_hw *, u32); | ||
2664 | s32 (*acquire_swfw_sync)(struct ixgbe_hw *, u16); | ||
2665 | void (*release_swfw_sync)(struct ixgbe_hw *, u16); | ||
2666 | |||
2667 | /* Link */ | ||
2668 | void (*disable_tx_laser)(struct ixgbe_hw *); | ||
2669 | void (*enable_tx_laser)(struct ixgbe_hw *); | ||
2670 | void (*flap_tx_laser)(struct ixgbe_hw *); | ||
2671 | s32 (*setup_link)(struct ixgbe_hw *, ixgbe_link_speed, bool, bool); | ||
2672 | s32 (*check_link)(struct ixgbe_hw *, ixgbe_link_speed *, bool *, bool); | ||
2673 | s32 (*get_link_capabilities)(struct ixgbe_hw *, ixgbe_link_speed *, | ||
2674 | bool *); | ||
2675 | |||
2676 | /* Packet Buffer Manipulation */ | ||
2677 | void (*set_rxpba)(struct ixgbe_hw *, int, u32, int); | ||
2678 | |||
2679 | /* LED */ | ||
2680 | s32 (*led_on)(struct ixgbe_hw *, u32); | ||
2681 | s32 (*led_off)(struct ixgbe_hw *, u32); | ||
2682 | s32 (*blink_led_start)(struct ixgbe_hw *, u32); | ||
2683 | s32 (*blink_led_stop)(struct ixgbe_hw *, u32); | ||
2684 | |||
2685 | /* RAR, Multicast, VLAN */ | ||
2686 | s32 (*set_rar)(struct ixgbe_hw *, u32, u8 *, u32, u32); | ||
2687 | s32 (*clear_rar)(struct ixgbe_hw *, u32); | ||
2688 | s32 (*set_vmdq)(struct ixgbe_hw *, u32, u32); | ||
2689 | s32 (*clear_vmdq)(struct ixgbe_hw *, u32, u32); | ||
2690 | s32 (*init_rx_addrs)(struct ixgbe_hw *); | ||
2691 | s32 (*update_mc_addr_list)(struct ixgbe_hw *, struct net_device *); | ||
2692 | s32 (*enable_mc)(struct ixgbe_hw *); | ||
2693 | s32 (*disable_mc)(struct ixgbe_hw *); | ||
2694 | s32 (*clear_vfta)(struct ixgbe_hw *); | ||
2695 | s32 (*set_vfta)(struct ixgbe_hw *, u32, u32, bool); | ||
2696 | s32 (*init_uta_tables)(struct ixgbe_hw *); | ||
2697 | void (*set_mac_anti_spoofing)(struct ixgbe_hw *, bool, int); | ||
2698 | void (*set_vlan_anti_spoofing)(struct ixgbe_hw *, bool, int); | ||
2699 | |||
2700 | /* Flow Control */ | ||
2701 | s32 (*fc_enable)(struct ixgbe_hw *, s32); | ||
2702 | |||
2703 | /* Manageability interface */ | ||
2704 | s32 (*set_fw_drv_ver)(struct ixgbe_hw *, u8, u8, u8, u8); | ||
2705 | }; | ||
2706 | |||
2707 | struct ixgbe_phy_operations { | ||
2708 | s32 (*identify)(struct ixgbe_hw *); | ||
2709 | s32 (*identify_sfp)(struct ixgbe_hw *); | ||
2710 | s32 (*init)(struct ixgbe_hw *); | ||
2711 | s32 (*reset)(struct ixgbe_hw *); | ||
2712 | s32 (*read_reg)(struct ixgbe_hw *, u32, u32, u16 *); | ||
2713 | s32 (*write_reg)(struct ixgbe_hw *, u32, u32, u16); | ||
2714 | s32 (*setup_link)(struct ixgbe_hw *); | ||
2715 | s32 (*setup_link_speed)(struct ixgbe_hw *, ixgbe_link_speed, bool, | ||
2716 | bool); | ||
2717 | s32 (*check_link)(struct ixgbe_hw *, ixgbe_link_speed *, bool *); | ||
2718 | s32 (*get_firmware_version)(struct ixgbe_hw *, u16 *); | ||
2719 | s32 (*read_i2c_byte)(struct ixgbe_hw *, u8, u8, u8 *); | ||
2720 | s32 (*write_i2c_byte)(struct ixgbe_hw *, u8, u8, u8); | ||
2721 | s32 (*read_i2c_eeprom)(struct ixgbe_hw *, u8 , u8 *); | ||
2722 | s32 (*write_i2c_eeprom)(struct ixgbe_hw *, u8, u8); | ||
2723 | s32 (*check_overtemp)(struct ixgbe_hw *); | ||
2724 | }; | ||
2725 | |||
2726 | struct ixgbe_eeprom_info { | ||
2727 | struct ixgbe_eeprom_operations ops; | ||
2728 | enum ixgbe_eeprom_type type; | ||
2729 | u32 semaphore_delay; | ||
2730 | u16 word_size; | ||
2731 | u16 address_bits; | ||
2732 | u16 word_page_size; | ||
2733 | }; | ||
2734 | |||
2735 | #define IXGBE_FLAGS_DOUBLE_RESET_REQUIRED 0x01 | ||
2736 | struct ixgbe_mac_info { | ||
2737 | struct ixgbe_mac_operations ops; | ||
2738 | enum ixgbe_mac_type type; | ||
2739 | u8 addr[IXGBE_ETH_LENGTH_OF_ADDRESS]; | ||
2740 | u8 perm_addr[IXGBE_ETH_LENGTH_OF_ADDRESS]; | ||
2741 | u8 san_addr[IXGBE_ETH_LENGTH_OF_ADDRESS]; | ||
2742 | /* prefix for World Wide Node Name (WWNN) */ | ||
2743 | u16 wwnn_prefix; | ||
2744 | /* prefix for World Wide Port Name (WWPN) */ | ||
2745 | u16 wwpn_prefix; | ||
2746 | #define IXGBE_MAX_MTA 128 | ||
2747 | u32 mta_shadow[IXGBE_MAX_MTA]; | ||
2748 | s32 mc_filter_type; | ||
2749 | u32 mcft_size; | ||
2750 | u32 vft_size; | ||
2751 | u32 num_rar_entries; | ||
2752 | u32 rar_highwater; | ||
2753 | u32 rx_pb_size; | ||
2754 | u32 max_tx_queues; | ||
2755 | u32 max_rx_queues; | ||
2756 | u32 max_msix_vectors; | ||
2757 | u32 orig_autoc; | ||
2758 | u32 orig_autoc2; | ||
2759 | bool orig_link_settings_stored; | ||
2760 | bool autotry_restart; | ||
2761 | u8 flags; | ||
2762 | }; | ||
2763 | |||
2764 | struct ixgbe_phy_info { | ||
2765 | struct ixgbe_phy_operations ops; | ||
2766 | struct mdio_if_info mdio; | ||
2767 | enum ixgbe_phy_type type; | ||
2768 | u32 id; | ||
2769 | enum ixgbe_sfp_type sfp_type; | ||
2770 | bool sfp_setup_needed; | ||
2771 | u32 revision; | ||
2772 | enum ixgbe_media_type media_type; | ||
2773 | bool reset_disable; | ||
2774 | ixgbe_autoneg_advertised autoneg_advertised; | ||
2775 | enum ixgbe_smart_speed smart_speed; | ||
2776 | bool smart_speed_active; | ||
2777 | bool multispeed_fiber; | ||
2778 | bool reset_if_overtemp; | ||
2779 | }; | ||
2780 | |||
2781 | #include "ixgbe_mbx.h" | ||
2782 | |||
2783 | struct ixgbe_mbx_operations { | ||
2784 | s32 (*init_params)(struct ixgbe_hw *hw); | ||
2785 | s32 (*read)(struct ixgbe_hw *, u32 *, u16, u16); | ||
2786 | s32 (*write)(struct ixgbe_hw *, u32 *, u16, u16); | ||
2787 | s32 (*read_posted)(struct ixgbe_hw *, u32 *, u16, u16); | ||
2788 | s32 (*write_posted)(struct ixgbe_hw *, u32 *, u16, u16); | ||
2789 | s32 (*check_for_msg)(struct ixgbe_hw *, u16); | ||
2790 | s32 (*check_for_ack)(struct ixgbe_hw *, u16); | ||
2791 | s32 (*check_for_rst)(struct ixgbe_hw *, u16); | ||
2792 | }; | ||
2793 | |||
2794 | struct ixgbe_mbx_stats { | ||
2795 | u32 msgs_tx; | ||
2796 | u32 msgs_rx; | ||
2797 | |||
2798 | u32 acks; | ||
2799 | u32 reqs; | ||
2800 | u32 rsts; | ||
2801 | }; | ||
2802 | |||
2803 | struct ixgbe_mbx_info { | ||
2804 | struct ixgbe_mbx_operations ops; | ||
2805 | struct ixgbe_mbx_stats stats; | ||
2806 | u32 timeout; | ||
2807 | u32 usec_delay; | ||
2808 | u32 v2p_mailbox; | ||
2809 | u16 size; | ||
2810 | }; | ||
2811 | |||
2812 | struct ixgbe_hw { | ||
2813 | u8 __iomem *hw_addr; | ||
2814 | void *back; | ||
2815 | struct ixgbe_mac_info mac; | ||
2816 | struct ixgbe_addr_filter_info addr_ctrl; | ||
2817 | struct ixgbe_fc_info fc; | ||
2818 | struct ixgbe_phy_info phy; | ||
2819 | struct ixgbe_eeprom_info eeprom; | ||
2820 | struct ixgbe_bus_info bus; | ||
2821 | struct ixgbe_mbx_info mbx; | ||
2822 | u16 device_id; | ||
2823 | u16 vendor_id; | ||
2824 | u16 subsystem_device_id; | ||
2825 | u16 subsystem_vendor_id; | ||
2826 | u8 revision_id; | ||
2827 | bool adapter_stopped; | ||
2828 | bool force_full_reset; | ||
2829 | }; | ||
2830 | |||
2831 | struct ixgbe_info { | ||
2832 | enum ixgbe_mac_type mac; | ||
2833 | s32 (*get_invariants)(struct ixgbe_hw *); | ||
2834 | struct ixgbe_mac_operations *mac_ops; | ||
2835 | struct ixgbe_eeprom_operations *eeprom_ops; | ||
2836 | struct ixgbe_phy_operations *phy_ops; | ||
2837 | struct ixgbe_mbx_operations *mbx_ops; | ||
2838 | }; | ||
2839 | |||
2840 | |||
2841 | /* Error Codes */ | ||
2842 | #define IXGBE_ERR_EEPROM -1 | ||
2843 | #define IXGBE_ERR_EEPROM_CHECKSUM -2 | ||
2844 | #define IXGBE_ERR_PHY -3 | ||
2845 | #define IXGBE_ERR_CONFIG -4 | ||
2846 | #define IXGBE_ERR_PARAM -5 | ||
2847 | #define IXGBE_ERR_MAC_TYPE -6 | ||
2848 | #define IXGBE_ERR_UNKNOWN_PHY -7 | ||
2849 | #define IXGBE_ERR_LINK_SETUP -8 | ||
2850 | #define IXGBE_ERR_ADAPTER_STOPPED -9 | ||
2851 | #define IXGBE_ERR_INVALID_MAC_ADDR -10 | ||
2852 | #define IXGBE_ERR_DEVICE_NOT_SUPPORTED -11 | ||
2853 | #define IXGBE_ERR_MASTER_REQUESTS_PENDING -12 | ||
2854 | #define IXGBE_ERR_INVALID_LINK_SETTINGS -13 | ||
2855 | #define IXGBE_ERR_AUTONEG_NOT_COMPLETE -14 | ||
2856 | #define IXGBE_ERR_RESET_FAILED -15 | ||
2857 | #define IXGBE_ERR_SWFW_SYNC -16 | ||
2858 | #define IXGBE_ERR_PHY_ADDR_INVALID -17 | ||
2859 | #define IXGBE_ERR_I2C -18 | ||
2860 | #define IXGBE_ERR_SFP_NOT_SUPPORTED -19 | ||
2861 | #define IXGBE_ERR_SFP_NOT_PRESENT -20 | ||
2862 | #define IXGBE_ERR_SFP_NO_INIT_SEQ_PRESENT -21 | ||
2863 | #define IXGBE_ERR_NO_SAN_ADDR_PTR -22 | ||
2864 | #define IXGBE_ERR_FDIR_REINIT_FAILED -23 | ||
2865 | #define IXGBE_ERR_EEPROM_VERSION -24 | ||
2866 | #define IXGBE_ERR_NO_SPACE -25 | ||
2867 | #define IXGBE_ERR_OVERTEMP -26 | ||
2868 | #define IXGBE_ERR_FC_NOT_NEGOTIATED -27 | ||
2869 | #define IXGBE_ERR_FC_NOT_SUPPORTED -28 | ||
2870 | #define IXGBE_ERR_FLOW_CONTROL -29 | ||
2871 | #define IXGBE_ERR_SFP_SETUP_NOT_COMPLETE -30 | ||
2872 | #define IXGBE_ERR_PBA_SECTION -31 | ||
2873 | #define IXGBE_ERR_INVALID_ARGUMENT -32 | ||
2874 | #define IXGBE_ERR_HOST_INTERFACE_COMMAND -33 | ||
2875 | #define IXGBE_NOT_IMPLEMENTED 0x7FFFFFFF | ||
2876 | |||
2877 | #endif /* _IXGBE_TYPE_H_ */ | ||
diff --git a/drivers/net/ixgbe/ixgbe_x540.c b/drivers/net/ixgbe/ixgbe_x540.c new file mode 100644 index 00000000000..2696c78e9f4 --- /dev/null +++ b/drivers/net/ixgbe/ixgbe_x540.c | |||
@@ -0,0 +1,941 @@ | |||
1 | /******************************************************************************* | ||
2 | |||
3 | Intel 10 Gigabit PCI Express Linux driver | ||
4 | Copyright(c) 1999 - 2011 Intel Corporation. | ||
5 | |||
6 | This program is free software; you can redistribute it and/or modify it | ||
7 | under the terms and conditions of the GNU General Public License, | ||
8 | version 2, as published by the Free Software Foundation. | ||
9 | |||
10 | This program is distributed in the hope it will be useful, but WITHOUT | ||
11 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
12 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
13 | more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License along with | ||
16 | this program; if not, write to the Free Software Foundation, Inc., | ||
17 | 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. | ||
18 | |||
19 | The full GNU General Public License is included in this distribution in | ||
20 | the file called "COPYING". | ||
21 | |||
22 | Contact Information: | ||
23 | e1000-devel Mailing List <e1000-devel@lists.sourceforge.net> | ||
24 | Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 | ||
25 | |||
26 | *******************************************************************************/ | ||
27 | |||
28 | #include <linux/pci.h> | ||
29 | #include <linux/delay.h> | ||
30 | #include <linux/sched.h> | ||
31 | |||
32 | #include "ixgbe.h" | ||
33 | #include "ixgbe_phy.h" | ||
34 | |||
35 | #define IXGBE_X540_MAX_TX_QUEUES 128 | ||
36 | #define IXGBE_X540_MAX_RX_QUEUES 128 | ||
37 | #define IXGBE_X540_RAR_ENTRIES 128 | ||
38 | #define IXGBE_X540_MC_TBL_SIZE 128 | ||
39 | #define IXGBE_X540_VFT_TBL_SIZE 128 | ||
40 | #define IXGBE_X540_RX_PB_SIZE 384 | ||
41 | |||
42 | static s32 ixgbe_update_flash_X540(struct ixgbe_hw *hw); | ||
43 | static s32 ixgbe_poll_flash_update_done_X540(struct ixgbe_hw *hw); | ||
44 | static s32 ixgbe_acquire_swfw_sync_X540(struct ixgbe_hw *hw, u16 mask); | ||
45 | static void ixgbe_release_swfw_sync_X540(struct ixgbe_hw *hw, u16 mask); | ||
46 | static s32 ixgbe_get_swfw_sync_semaphore(struct ixgbe_hw *hw); | ||
47 | static void ixgbe_release_swfw_sync_semaphore(struct ixgbe_hw *hw); | ||
48 | |||
49 | static enum ixgbe_media_type ixgbe_get_media_type_X540(struct ixgbe_hw *hw) | ||
50 | { | ||
51 | return ixgbe_media_type_copper; | ||
52 | } | ||
53 | |||
54 | static s32 ixgbe_get_invariants_X540(struct ixgbe_hw *hw) | ||
55 | { | ||
56 | struct ixgbe_mac_info *mac = &hw->mac; | ||
57 | |||
58 | /* Call PHY identify routine to get the phy type */ | ||
59 | ixgbe_identify_phy_generic(hw); | ||
60 | |||
61 | mac->mcft_size = IXGBE_X540_MC_TBL_SIZE; | ||
62 | mac->vft_size = IXGBE_X540_VFT_TBL_SIZE; | ||
63 | mac->num_rar_entries = IXGBE_X540_RAR_ENTRIES; | ||
64 | mac->max_rx_queues = IXGBE_X540_MAX_RX_QUEUES; | ||
65 | mac->max_tx_queues = IXGBE_X540_MAX_TX_QUEUES; | ||
66 | mac->max_msix_vectors = ixgbe_get_pcie_msix_count_generic(hw); | ||
67 | |||
68 | return 0; | ||
69 | } | ||
70 | |||
71 | /** | ||
72 | * ixgbe_setup_mac_link_X540 - Set the auto advertised capabilitires | ||
73 | * @hw: pointer to hardware structure | ||
74 | * @speed: new link speed | ||
75 | * @autoneg: true if autonegotiation enabled | ||
76 | * @autoneg_wait_to_complete: true when waiting for completion is needed | ||
77 | **/ | ||
78 | static s32 ixgbe_setup_mac_link_X540(struct ixgbe_hw *hw, | ||
79 | ixgbe_link_speed speed, bool autoneg, | ||
80 | bool autoneg_wait_to_complete) | ||
81 | { | ||
82 | return hw->phy.ops.setup_link_speed(hw, speed, autoneg, | ||
83 | autoneg_wait_to_complete); | ||
84 | } | ||
85 | |||
86 | /** | ||
87 | * ixgbe_reset_hw_X540 - Perform hardware reset | ||
88 | * @hw: pointer to hardware structure | ||
89 | * | ||
90 | * Resets the hardware by resetting the transmit and receive units, masks | ||
91 | * and clears all interrupts, perform a PHY reset, and perform a link (MAC) | ||
92 | * reset. | ||
93 | **/ | ||
94 | static s32 ixgbe_reset_hw_X540(struct ixgbe_hw *hw) | ||
95 | { | ||
96 | ixgbe_link_speed link_speed; | ||
97 | s32 status = 0; | ||
98 | u32 ctrl; | ||
99 | u32 ctrl_ext; | ||
100 | u32 reset_bit; | ||
101 | u32 i; | ||
102 | u32 autoc; | ||
103 | u32 autoc2; | ||
104 | bool link_up = false; | ||
105 | |||
106 | /* Call adapter stop to disable tx/rx and clear interrupts */ | ||
107 | hw->mac.ops.stop_adapter(hw); | ||
108 | |||
109 | /* | ||
110 | * Prevent the PCI-E bus from from hanging by disabling PCI-E master | ||
111 | * access and verify no pending requests before reset | ||
112 | */ | ||
113 | ixgbe_disable_pcie_master(hw); | ||
114 | |||
115 | mac_reset_top: | ||
116 | /* | ||
117 | * Issue global reset to the MAC. Needs to be SW reset if link is up. | ||
118 | * If link reset is used when link is up, it might reset the PHY when | ||
119 | * mng is using it. If link is down or the flag to force full link | ||
120 | * reset is set, then perform link reset. | ||
121 | */ | ||
122 | if (hw->force_full_reset) { | ||
123 | reset_bit = IXGBE_CTRL_LNK_RST; | ||
124 | } else { | ||
125 | hw->mac.ops.check_link(hw, &link_speed, &link_up, false); | ||
126 | if (!link_up) | ||
127 | reset_bit = IXGBE_CTRL_LNK_RST; | ||
128 | else | ||
129 | reset_bit = IXGBE_CTRL_RST; | ||
130 | } | ||
131 | |||
132 | ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL); | ||
133 | IXGBE_WRITE_REG(hw, IXGBE_CTRL, (ctrl | reset_bit)); | ||
134 | IXGBE_WRITE_FLUSH(hw); | ||
135 | |||
136 | /* Poll for reset bit to self-clear indicating reset is complete */ | ||
137 | for (i = 0; i < 10; i++) { | ||
138 | udelay(1); | ||
139 | ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL); | ||
140 | if (!(ctrl & reset_bit)) | ||
141 | break; | ||
142 | } | ||
143 | if (ctrl & reset_bit) { | ||
144 | status = IXGBE_ERR_RESET_FAILED; | ||
145 | hw_dbg(hw, "Reset polling failed to complete.\n"); | ||
146 | } | ||
147 | |||
148 | /* | ||
149 | * Double resets are required for recovery from certain error | ||
150 | * conditions. Between resets, it is necessary to stall to allow time | ||
151 | * for any pending HW events to complete. We use 1usec since that is | ||
152 | * what is needed for ixgbe_disable_pcie_master(). The second reset | ||
153 | * then clears out any effects of those events. | ||
154 | */ | ||
155 | if (hw->mac.flags & IXGBE_FLAGS_DOUBLE_RESET_REQUIRED) { | ||
156 | hw->mac.flags &= ~IXGBE_FLAGS_DOUBLE_RESET_REQUIRED; | ||
157 | udelay(1); | ||
158 | goto mac_reset_top; | ||
159 | } | ||
160 | |||
161 | /* Clear PF Reset Done bit so PF/VF Mail Ops can work */ | ||
162 | ctrl_ext = IXGBE_READ_REG(hw, IXGBE_CTRL_EXT); | ||
163 | ctrl_ext |= IXGBE_CTRL_EXT_PFRSTD; | ||
164 | IXGBE_WRITE_REG(hw, IXGBE_CTRL_EXT, ctrl_ext); | ||
165 | IXGBE_WRITE_FLUSH(hw); | ||
166 | |||
167 | msleep(50); | ||
168 | |||
169 | /* Set the Rx packet buffer size. */ | ||
170 | IXGBE_WRITE_REG(hw, IXGBE_RXPBSIZE(0), 384 << IXGBE_RXPBSIZE_SHIFT); | ||
171 | |||
172 | /* Store the permanent mac address */ | ||
173 | hw->mac.ops.get_mac_addr(hw, hw->mac.perm_addr); | ||
174 | |||
175 | /* | ||
176 | * Store the original AUTOC/AUTOC2 values if they have not been | ||
177 | * stored off yet. Otherwise restore the stored original | ||
178 | * values since the reset operation sets back to defaults. | ||
179 | */ | ||
180 | autoc = IXGBE_READ_REG(hw, IXGBE_AUTOC); | ||
181 | autoc2 = IXGBE_READ_REG(hw, IXGBE_AUTOC2); | ||
182 | if (hw->mac.orig_link_settings_stored == false) { | ||
183 | hw->mac.orig_autoc = autoc; | ||
184 | hw->mac.orig_autoc2 = autoc2; | ||
185 | hw->mac.orig_link_settings_stored = true; | ||
186 | } else { | ||
187 | if (autoc != hw->mac.orig_autoc) | ||
188 | IXGBE_WRITE_REG(hw, IXGBE_AUTOC, (hw->mac.orig_autoc | | ||
189 | IXGBE_AUTOC_AN_RESTART)); | ||
190 | |||
191 | if ((autoc2 & IXGBE_AUTOC2_UPPER_MASK) != | ||
192 | (hw->mac.orig_autoc2 & IXGBE_AUTOC2_UPPER_MASK)) { | ||
193 | autoc2 &= ~IXGBE_AUTOC2_UPPER_MASK; | ||
194 | autoc2 |= (hw->mac.orig_autoc2 & | ||
195 | IXGBE_AUTOC2_UPPER_MASK); | ||
196 | IXGBE_WRITE_REG(hw, IXGBE_AUTOC2, autoc2); | ||
197 | } | ||
198 | } | ||
199 | |||
200 | /* | ||
201 | * Store MAC address from RAR0, clear receive address registers, and | ||
202 | * clear the multicast table. Also reset num_rar_entries to 128, | ||
203 | * since we modify this value when programming the SAN MAC address. | ||
204 | */ | ||
205 | hw->mac.num_rar_entries = IXGBE_X540_MAX_TX_QUEUES; | ||
206 | hw->mac.ops.init_rx_addrs(hw); | ||
207 | |||
208 | /* Store the permanent mac address */ | ||
209 | hw->mac.ops.get_mac_addr(hw, hw->mac.perm_addr); | ||
210 | |||
211 | /* Store the permanent SAN mac address */ | ||
212 | hw->mac.ops.get_san_mac_addr(hw, hw->mac.san_addr); | ||
213 | |||
214 | /* Add the SAN MAC address to the RAR only if it's a valid address */ | ||
215 | if (ixgbe_validate_mac_addr(hw->mac.san_addr) == 0) { | ||
216 | hw->mac.ops.set_rar(hw, hw->mac.num_rar_entries - 1, | ||
217 | hw->mac.san_addr, 0, IXGBE_RAH_AV); | ||
218 | |||
219 | /* Reserve the last RAR for the SAN MAC address */ | ||
220 | hw->mac.num_rar_entries--; | ||
221 | } | ||
222 | |||
223 | /* Store the alternative WWNN/WWPN prefix */ | ||
224 | hw->mac.ops.get_wwn_prefix(hw, &hw->mac.wwnn_prefix, | ||
225 | &hw->mac.wwpn_prefix); | ||
226 | |||
227 | return status; | ||
228 | } | ||
229 | |||
230 | /** | ||
231 | * ixgbe_start_hw_X540 - Prepare hardware for Tx/Rx | ||
232 | * @hw: pointer to hardware structure | ||
233 | * | ||
234 | * Starts the hardware using the generic start_hw function | ||
235 | * and the generation start_hw function. | ||
236 | * Then performs revision-specific operations, if any. | ||
237 | **/ | ||
238 | static s32 ixgbe_start_hw_X540(struct ixgbe_hw *hw) | ||
239 | { | ||
240 | s32 ret_val = 0; | ||
241 | |||
242 | ret_val = ixgbe_start_hw_generic(hw); | ||
243 | if (ret_val != 0) | ||
244 | goto out; | ||
245 | |||
246 | ret_val = ixgbe_start_hw_gen2(hw); | ||
247 | hw->mac.rx_pb_size = IXGBE_X540_RX_PB_SIZE; | ||
248 | out: | ||
249 | return ret_val; | ||
250 | } | ||
251 | |||
252 | /** | ||
253 | * ixgbe_get_supported_physical_layer_X540 - Returns physical layer type | ||
254 | * @hw: pointer to hardware structure | ||
255 | * | ||
256 | * Determines physical layer capabilities of the current configuration. | ||
257 | **/ | ||
258 | static u32 ixgbe_get_supported_physical_layer_X540(struct ixgbe_hw *hw) | ||
259 | { | ||
260 | u32 physical_layer = IXGBE_PHYSICAL_LAYER_UNKNOWN; | ||
261 | u16 ext_ability = 0; | ||
262 | |||
263 | hw->phy.ops.identify(hw); | ||
264 | |||
265 | hw->phy.ops.read_reg(hw, MDIO_PMA_EXTABLE, MDIO_MMD_PMAPMD, | ||
266 | &ext_ability); | ||
267 | if (ext_ability & MDIO_PMA_EXTABLE_10GBT) | ||
268 | physical_layer |= IXGBE_PHYSICAL_LAYER_10GBASE_T; | ||
269 | if (ext_ability & MDIO_PMA_EXTABLE_1000BT) | ||
270 | physical_layer |= IXGBE_PHYSICAL_LAYER_1000BASE_T; | ||
271 | if (ext_ability & MDIO_PMA_EXTABLE_100BTX) | ||
272 | physical_layer |= IXGBE_PHYSICAL_LAYER_100BASE_TX; | ||
273 | |||
274 | return physical_layer; | ||
275 | } | ||
276 | |||
277 | /** | ||
278 | * ixgbe_init_eeprom_params_X540 - Initialize EEPROM params | ||
279 | * @hw: pointer to hardware structure | ||
280 | * | ||
281 | * Initializes the EEPROM parameters ixgbe_eeprom_info within the | ||
282 | * ixgbe_hw struct in order to set up EEPROM access. | ||
283 | **/ | ||
284 | static s32 ixgbe_init_eeprom_params_X540(struct ixgbe_hw *hw) | ||
285 | { | ||
286 | struct ixgbe_eeprom_info *eeprom = &hw->eeprom; | ||
287 | u32 eec; | ||
288 | u16 eeprom_size; | ||
289 | |||
290 | if (eeprom->type == ixgbe_eeprom_uninitialized) { | ||
291 | eeprom->semaphore_delay = 10; | ||
292 | eeprom->type = ixgbe_flash; | ||
293 | |||
294 | eec = IXGBE_READ_REG(hw, IXGBE_EEC); | ||
295 | eeprom_size = (u16)((eec & IXGBE_EEC_SIZE) >> | ||
296 | IXGBE_EEC_SIZE_SHIFT); | ||
297 | eeprom->word_size = 1 << (eeprom_size + | ||
298 | IXGBE_EEPROM_WORD_SIZE_SHIFT); | ||
299 | |||
300 | hw_dbg(hw, "Eeprom params: type = %d, size = %d\n", | ||
301 | eeprom->type, eeprom->word_size); | ||
302 | } | ||
303 | |||
304 | return 0; | ||
305 | } | ||
306 | |||
307 | /** | ||
308 | * ixgbe_read_eerd_X540- Read EEPROM word using EERD | ||
309 | * @hw: pointer to hardware structure | ||
310 | * @offset: offset of word in the EEPROM to read | ||
311 | * @data: word read from the EEPROM | ||
312 | * | ||
313 | * Reads a 16 bit word from the EEPROM using the EERD register. | ||
314 | **/ | ||
315 | static s32 ixgbe_read_eerd_X540(struct ixgbe_hw *hw, u16 offset, u16 *data) | ||
316 | { | ||
317 | s32 status = 0; | ||
318 | |||
319 | if (hw->mac.ops.acquire_swfw_sync(hw, IXGBE_GSSR_EEP_SM) == | ||
320 | 0) | ||
321 | status = ixgbe_read_eerd_generic(hw, offset, data); | ||
322 | else | ||
323 | status = IXGBE_ERR_SWFW_SYNC; | ||
324 | |||
325 | hw->mac.ops.release_swfw_sync(hw, IXGBE_GSSR_EEP_SM); | ||
326 | return status; | ||
327 | } | ||
328 | |||
329 | /** | ||
330 | * ixgbe_read_eerd_buffer_X540 - Read EEPROM word(s) using EERD | ||
331 | * @hw: pointer to hardware structure | ||
332 | * @offset: offset of word in the EEPROM to read | ||
333 | * @words: number of words | ||
334 | * @data: word(s) read from the EEPROM | ||
335 | * | ||
336 | * Reads a 16 bit word(s) from the EEPROM using the EERD register. | ||
337 | **/ | ||
338 | static s32 ixgbe_read_eerd_buffer_X540(struct ixgbe_hw *hw, | ||
339 | u16 offset, u16 words, u16 *data) | ||
340 | { | ||
341 | s32 status = 0; | ||
342 | |||
343 | if (hw->mac.ops.acquire_swfw_sync(hw, IXGBE_GSSR_EEP_SM) == | ||
344 | 0) | ||
345 | status = ixgbe_read_eerd_buffer_generic(hw, offset, | ||
346 | words, data); | ||
347 | else | ||
348 | status = IXGBE_ERR_SWFW_SYNC; | ||
349 | |||
350 | hw->mac.ops.release_swfw_sync(hw, IXGBE_GSSR_EEP_SM); | ||
351 | return status; | ||
352 | } | ||
353 | |||
354 | /** | ||
355 | * ixgbe_write_eewr_X540 - Write EEPROM word using EEWR | ||
356 | * @hw: pointer to hardware structure | ||
357 | * @offset: offset of word in the EEPROM to write | ||
358 | * @data: word write to the EEPROM | ||
359 | * | ||
360 | * Write a 16 bit word to the EEPROM using the EEWR register. | ||
361 | **/ | ||
362 | static s32 ixgbe_write_eewr_X540(struct ixgbe_hw *hw, u16 offset, u16 data) | ||
363 | { | ||
364 | s32 status = 0; | ||
365 | |||
366 | if (hw->mac.ops.acquire_swfw_sync(hw, IXGBE_GSSR_EEP_SM) == 0) | ||
367 | status = ixgbe_write_eewr_generic(hw, offset, data); | ||
368 | else | ||
369 | status = IXGBE_ERR_SWFW_SYNC; | ||
370 | |||
371 | hw->mac.ops.release_swfw_sync(hw, IXGBE_GSSR_EEP_SM); | ||
372 | return status; | ||
373 | } | ||
374 | |||
375 | /** | ||
376 | * ixgbe_write_eewr_buffer_X540 - Write EEPROM word(s) using EEWR | ||
377 | * @hw: pointer to hardware structure | ||
378 | * @offset: offset of word in the EEPROM to write | ||
379 | * @words: number of words | ||
380 | * @data: word(s) write to the EEPROM | ||
381 | * | ||
382 | * Write a 16 bit word(s) to the EEPROM using the EEWR register. | ||
383 | **/ | ||
384 | static s32 ixgbe_write_eewr_buffer_X540(struct ixgbe_hw *hw, | ||
385 | u16 offset, u16 words, u16 *data) | ||
386 | { | ||
387 | s32 status = 0; | ||
388 | |||
389 | if (hw->mac.ops.acquire_swfw_sync(hw, IXGBE_GSSR_EEP_SM) == | ||
390 | 0) | ||
391 | status = ixgbe_write_eewr_buffer_generic(hw, offset, | ||
392 | words, data); | ||
393 | else | ||
394 | status = IXGBE_ERR_SWFW_SYNC; | ||
395 | |||
396 | hw->mac.ops.release_swfw_sync(hw, IXGBE_GSSR_EEP_SM); | ||
397 | return status; | ||
398 | } | ||
399 | |||
400 | /** | ||
401 | * ixgbe_calc_eeprom_checksum_X540 - Calculates and returns the checksum | ||
402 | * | ||
403 | * This function does not use synchronization for EERD and EEWR. It can | ||
404 | * be used internally by function which utilize ixgbe_acquire_swfw_sync_X540. | ||
405 | * | ||
406 | * @hw: pointer to hardware structure | ||
407 | **/ | ||
408 | static u16 ixgbe_calc_eeprom_checksum_X540(struct ixgbe_hw *hw) | ||
409 | { | ||
410 | u16 i; | ||
411 | u16 j; | ||
412 | u16 checksum = 0; | ||
413 | u16 length = 0; | ||
414 | u16 pointer = 0; | ||
415 | u16 word = 0; | ||
416 | |||
417 | /* | ||
418 | * Do not use hw->eeprom.ops.read because we do not want to take | ||
419 | * the synchronization semaphores here. Instead use | ||
420 | * ixgbe_read_eerd_generic | ||
421 | */ | ||
422 | |||
423 | /* Include 0x0-0x3F in the checksum */ | ||
424 | for (i = 0; i < IXGBE_EEPROM_CHECKSUM; i++) { | ||
425 | if (ixgbe_read_eerd_generic(hw, i, &word) != 0) { | ||
426 | hw_dbg(hw, "EEPROM read failed\n"); | ||
427 | break; | ||
428 | } | ||
429 | checksum += word; | ||
430 | } | ||
431 | |||
432 | /* | ||
433 | * Include all data from pointers 0x3, 0x6-0xE. This excludes the | ||
434 | * FW, PHY module, and PCIe Expansion/Option ROM pointers. | ||
435 | */ | ||
436 | for (i = IXGBE_PCIE_ANALOG_PTR; i < IXGBE_FW_PTR; i++) { | ||
437 | if (i == IXGBE_PHY_PTR || i == IXGBE_OPTION_ROM_PTR) | ||
438 | continue; | ||
439 | |||
440 | if (ixgbe_read_eerd_generic(hw, i, &pointer) != 0) { | ||
441 | hw_dbg(hw, "EEPROM read failed\n"); | ||
442 | break; | ||
443 | } | ||
444 | |||
445 | /* Skip pointer section if the pointer is invalid. */ | ||
446 | if (pointer == 0xFFFF || pointer == 0 || | ||
447 | pointer >= hw->eeprom.word_size) | ||
448 | continue; | ||
449 | |||
450 | if (ixgbe_read_eerd_generic(hw, pointer, &length) != 0) { | ||
451 | hw_dbg(hw, "EEPROM read failed\n"); | ||
452 | break; | ||
453 | } | ||
454 | |||
455 | /* Skip pointer section if length is invalid. */ | ||
456 | if (length == 0xFFFF || length == 0 || | ||
457 | (pointer + length) >= hw->eeprom.word_size) | ||
458 | continue; | ||
459 | |||
460 | for (j = pointer+1; j <= pointer+length; j++) { | ||
461 | if (ixgbe_read_eerd_generic(hw, j, &word) != 0) { | ||
462 | hw_dbg(hw, "EEPROM read failed\n"); | ||
463 | break; | ||
464 | } | ||
465 | checksum += word; | ||
466 | } | ||
467 | } | ||
468 | |||
469 | checksum = (u16)IXGBE_EEPROM_SUM - checksum; | ||
470 | |||
471 | return checksum; | ||
472 | } | ||
473 | |||
474 | /** | ||
475 | * ixgbe_validate_eeprom_checksum_X540 - Validate EEPROM checksum | ||
476 | * @hw: pointer to hardware structure | ||
477 | * @checksum_val: calculated checksum | ||
478 | * | ||
479 | * Performs checksum calculation and validates the EEPROM checksum. If the | ||
480 | * caller does not need checksum_val, the value can be NULL. | ||
481 | **/ | ||
482 | static s32 ixgbe_validate_eeprom_checksum_X540(struct ixgbe_hw *hw, | ||
483 | u16 *checksum_val) | ||
484 | { | ||
485 | s32 status; | ||
486 | u16 checksum; | ||
487 | u16 read_checksum = 0; | ||
488 | |||
489 | /* | ||
490 | * Read the first word from the EEPROM. If this times out or fails, do | ||
491 | * not continue or we could be in for a very long wait while every | ||
492 | * EEPROM read fails | ||
493 | */ | ||
494 | status = hw->eeprom.ops.read(hw, 0, &checksum); | ||
495 | |||
496 | if (status != 0) { | ||
497 | hw_dbg(hw, "EEPROM read failed\n"); | ||
498 | goto out; | ||
499 | } | ||
500 | |||
501 | if (hw->mac.ops.acquire_swfw_sync(hw, IXGBE_GSSR_EEP_SM) == 0) { | ||
502 | checksum = hw->eeprom.ops.calc_checksum(hw); | ||
503 | |||
504 | /* | ||
505 | * Do not use hw->eeprom.ops.read because we do not want to take | ||
506 | * the synchronization semaphores twice here. | ||
507 | */ | ||
508 | ixgbe_read_eerd_generic(hw, IXGBE_EEPROM_CHECKSUM, | ||
509 | &read_checksum); | ||
510 | |||
511 | /* | ||
512 | * Verify read checksum from EEPROM is the same as | ||
513 | * calculated checksum | ||
514 | */ | ||
515 | if (read_checksum != checksum) | ||
516 | status = IXGBE_ERR_EEPROM_CHECKSUM; | ||
517 | |||
518 | /* If the user cares, return the calculated checksum */ | ||
519 | if (checksum_val) | ||
520 | *checksum_val = checksum; | ||
521 | } else { | ||
522 | status = IXGBE_ERR_SWFW_SYNC; | ||
523 | } | ||
524 | |||
525 | hw->mac.ops.release_swfw_sync(hw, IXGBE_GSSR_EEP_SM); | ||
526 | out: | ||
527 | return status; | ||
528 | } | ||
529 | |||
530 | /** | ||
531 | * ixgbe_update_eeprom_checksum_X540 - Updates the EEPROM checksum and flash | ||
532 | * @hw: pointer to hardware structure | ||
533 | * | ||
534 | * After writing EEPROM to shadow RAM using EEWR register, software calculates | ||
535 | * checksum and updates the EEPROM and instructs the hardware to update | ||
536 | * the flash. | ||
537 | **/ | ||
538 | static s32 ixgbe_update_eeprom_checksum_X540(struct ixgbe_hw *hw) | ||
539 | { | ||
540 | s32 status; | ||
541 | u16 checksum; | ||
542 | |||
543 | /* | ||
544 | * Read the first word from the EEPROM. If this times out or fails, do | ||
545 | * not continue or we could be in for a very long wait while every | ||
546 | * EEPROM read fails | ||
547 | */ | ||
548 | status = hw->eeprom.ops.read(hw, 0, &checksum); | ||
549 | |||
550 | if (status != 0) | ||
551 | hw_dbg(hw, "EEPROM read failed\n"); | ||
552 | |||
553 | if (hw->mac.ops.acquire_swfw_sync(hw, IXGBE_GSSR_EEP_SM) == 0) { | ||
554 | checksum = hw->eeprom.ops.calc_checksum(hw); | ||
555 | |||
556 | /* | ||
557 | * Do not use hw->eeprom.ops.write because we do not want to | ||
558 | * take the synchronization semaphores twice here. | ||
559 | */ | ||
560 | status = ixgbe_write_eewr_generic(hw, IXGBE_EEPROM_CHECKSUM, | ||
561 | checksum); | ||
562 | |||
563 | if (status == 0) | ||
564 | status = ixgbe_update_flash_X540(hw); | ||
565 | else | ||
566 | status = IXGBE_ERR_SWFW_SYNC; | ||
567 | } | ||
568 | |||
569 | hw->mac.ops.release_swfw_sync(hw, IXGBE_GSSR_EEP_SM); | ||
570 | |||
571 | return status; | ||
572 | } | ||
573 | |||
574 | /** | ||
575 | * ixgbe_update_flash_X540 - Instruct HW to copy EEPROM to Flash device | ||
576 | * @hw: pointer to hardware structure | ||
577 | * | ||
578 | * Set FLUP (bit 23) of the EEC register to instruct Hardware to copy | ||
579 | * EEPROM from shadow RAM to the flash device. | ||
580 | **/ | ||
581 | static s32 ixgbe_update_flash_X540(struct ixgbe_hw *hw) | ||
582 | { | ||
583 | u32 flup; | ||
584 | s32 status = IXGBE_ERR_EEPROM; | ||
585 | |||
586 | status = ixgbe_poll_flash_update_done_X540(hw); | ||
587 | if (status == IXGBE_ERR_EEPROM) { | ||
588 | hw_dbg(hw, "Flash update time out\n"); | ||
589 | goto out; | ||
590 | } | ||
591 | |||
592 | flup = IXGBE_READ_REG(hw, IXGBE_EEC) | IXGBE_EEC_FLUP; | ||
593 | IXGBE_WRITE_REG(hw, IXGBE_EEC, flup); | ||
594 | |||
595 | status = ixgbe_poll_flash_update_done_X540(hw); | ||
596 | if (status == 0) | ||
597 | hw_dbg(hw, "Flash update complete\n"); | ||
598 | else | ||
599 | hw_dbg(hw, "Flash update time out\n"); | ||
600 | |||
601 | if (hw->revision_id == 0) { | ||
602 | flup = IXGBE_READ_REG(hw, IXGBE_EEC); | ||
603 | |||
604 | if (flup & IXGBE_EEC_SEC1VAL) { | ||
605 | flup |= IXGBE_EEC_FLUP; | ||
606 | IXGBE_WRITE_REG(hw, IXGBE_EEC, flup); | ||
607 | } | ||
608 | |||
609 | status = ixgbe_poll_flash_update_done_X540(hw); | ||
610 | if (status == 0) | ||
611 | hw_dbg(hw, "Flash update complete\n"); | ||
612 | else | ||
613 | hw_dbg(hw, "Flash update time out\n"); | ||
614 | } | ||
615 | out: | ||
616 | return status; | ||
617 | } | ||
618 | |||
619 | /** | ||
620 | * ixgbe_poll_flash_update_done_X540 - Poll flash update status | ||
621 | * @hw: pointer to hardware structure | ||
622 | * | ||
623 | * Polls the FLUDONE (bit 26) of the EEC Register to determine when the | ||
624 | * flash update is done. | ||
625 | **/ | ||
626 | static s32 ixgbe_poll_flash_update_done_X540(struct ixgbe_hw *hw) | ||
627 | { | ||
628 | u32 i; | ||
629 | u32 reg; | ||
630 | s32 status = IXGBE_ERR_EEPROM; | ||
631 | |||
632 | for (i = 0; i < IXGBE_FLUDONE_ATTEMPTS; i++) { | ||
633 | reg = IXGBE_READ_REG(hw, IXGBE_EEC); | ||
634 | if (reg & IXGBE_EEC_FLUDONE) { | ||
635 | status = 0; | ||
636 | break; | ||
637 | } | ||
638 | udelay(5); | ||
639 | } | ||
640 | return status; | ||
641 | } | ||
642 | |||
643 | /** | ||
644 | * ixgbe_acquire_swfw_sync_X540 - Acquire SWFW semaphore | ||
645 | * @hw: pointer to hardware structure | ||
646 | * @mask: Mask to specify which semaphore to acquire | ||
647 | * | ||
648 | * Acquires the SWFW semaphore thought the SW_FW_SYNC register for | ||
649 | * the specified function (CSR, PHY0, PHY1, NVM, Flash) | ||
650 | **/ | ||
651 | static s32 ixgbe_acquire_swfw_sync_X540(struct ixgbe_hw *hw, u16 mask) | ||
652 | { | ||
653 | u32 swfw_sync; | ||
654 | u32 swmask = mask; | ||
655 | u32 fwmask = mask << 5; | ||
656 | u32 hwmask = 0; | ||
657 | u32 timeout = 200; | ||
658 | u32 i; | ||
659 | |||
660 | if (swmask == IXGBE_GSSR_EEP_SM) | ||
661 | hwmask = IXGBE_GSSR_FLASH_SM; | ||
662 | |||
663 | for (i = 0; i < timeout; i++) { | ||
664 | /* | ||
665 | * SW NVM semaphore bit is used for access to all | ||
666 | * SW_FW_SYNC bits (not just NVM) | ||
667 | */ | ||
668 | if (ixgbe_get_swfw_sync_semaphore(hw)) | ||
669 | return IXGBE_ERR_SWFW_SYNC; | ||
670 | |||
671 | swfw_sync = IXGBE_READ_REG(hw, IXGBE_SWFW_SYNC); | ||
672 | if (!(swfw_sync & (fwmask | swmask | hwmask))) { | ||
673 | swfw_sync |= swmask; | ||
674 | IXGBE_WRITE_REG(hw, IXGBE_SWFW_SYNC, swfw_sync); | ||
675 | ixgbe_release_swfw_sync_semaphore(hw); | ||
676 | break; | ||
677 | } else { | ||
678 | /* | ||
679 | * Firmware currently using resource (fwmask), | ||
680 | * hardware currently using resource (hwmask), | ||
681 | * or other software thread currently using | ||
682 | * resource (swmask) | ||
683 | */ | ||
684 | ixgbe_release_swfw_sync_semaphore(hw); | ||
685 | usleep_range(5000, 10000); | ||
686 | } | ||
687 | } | ||
688 | |||
689 | /* | ||
690 | * If the resource is not released by the FW/HW the SW can assume that | ||
691 | * the FW/HW malfunctions. In that case the SW should sets the | ||
692 | * SW bit(s) of the requested resource(s) while ignoring the | ||
693 | * corresponding FW/HW bits in the SW_FW_SYNC register. | ||
694 | */ | ||
695 | if (i >= timeout) { | ||
696 | swfw_sync = IXGBE_READ_REG(hw, IXGBE_SWFW_SYNC); | ||
697 | if (swfw_sync & (fwmask | hwmask)) { | ||
698 | if (ixgbe_get_swfw_sync_semaphore(hw)) | ||
699 | return IXGBE_ERR_SWFW_SYNC; | ||
700 | |||
701 | swfw_sync |= swmask; | ||
702 | IXGBE_WRITE_REG(hw, IXGBE_SWFW_SYNC, swfw_sync); | ||
703 | ixgbe_release_swfw_sync_semaphore(hw); | ||
704 | } | ||
705 | } | ||
706 | |||
707 | usleep_range(5000, 10000); | ||
708 | return 0; | ||
709 | } | ||
710 | |||
711 | /** | ||
712 | * ixgbe_release_swfw_sync_X540 - Release SWFW semaphore | ||
713 | * @hw: pointer to hardware structure | ||
714 | * @mask: Mask to specify which semaphore to release | ||
715 | * | ||
716 | * Releases the SWFW semaphore through the SW_FW_SYNC register | ||
717 | * for the specified function (CSR, PHY0, PHY1, EVM, Flash) | ||
718 | **/ | ||
719 | static void ixgbe_release_swfw_sync_X540(struct ixgbe_hw *hw, u16 mask) | ||
720 | { | ||
721 | u32 swfw_sync; | ||
722 | u32 swmask = mask; | ||
723 | |||
724 | ixgbe_get_swfw_sync_semaphore(hw); | ||
725 | |||
726 | swfw_sync = IXGBE_READ_REG(hw, IXGBE_SWFW_SYNC); | ||
727 | swfw_sync &= ~swmask; | ||
728 | IXGBE_WRITE_REG(hw, IXGBE_SWFW_SYNC, swfw_sync); | ||
729 | |||
730 | ixgbe_release_swfw_sync_semaphore(hw); | ||
731 | usleep_range(5000, 10000); | ||
732 | } | ||
733 | |||
734 | /** | ||
735 | * ixgbe_get_nvm_semaphore - Get hardware semaphore | ||
736 | * @hw: pointer to hardware structure | ||
737 | * | ||
738 | * Sets the hardware semaphores so SW/FW can gain control of shared resources | ||
739 | **/ | ||
740 | static s32 ixgbe_get_swfw_sync_semaphore(struct ixgbe_hw *hw) | ||
741 | { | ||
742 | s32 status = IXGBE_ERR_EEPROM; | ||
743 | u32 timeout = 2000; | ||
744 | u32 i; | ||
745 | u32 swsm; | ||
746 | |||
747 | /* Get SMBI software semaphore between device drivers first */ | ||
748 | for (i = 0; i < timeout; i++) { | ||
749 | /* | ||
750 | * If the SMBI bit is 0 when we read it, then the bit will be | ||
751 | * set and we have the semaphore | ||
752 | */ | ||
753 | swsm = IXGBE_READ_REG(hw, IXGBE_SWSM); | ||
754 | if (!(swsm & IXGBE_SWSM_SMBI)) { | ||
755 | status = 0; | ||
756 | break; | ||
757 | } | ||
758 | udelay(50); | ||
759 | } | ||
760 | |||
761 | /* Now get the semaphore between SW/FW through the REGSMP bit */ | ||
762 | if (status) { | ||
763 | for (i = 0; i < timeout; i++) { | ||
764 | swsm = IXGBE_READ_REG(hw, IXGBE_SWFW_SYNC); | ||
765 | if (!(swsm & IXGBE_SWFW_REGSMP)) | ||
766 | break; | ||
767 | |||
768 | udelay(50); | ||
769 | } | ||
770 | } else { | ||
771 | hw_dbg(hw, "Software semaphore SMBI between device drivers " | ||
772 | "not granted.\n"); | ||
773 | } | ||
774 | |||
775 | return status; | ||
776 | } | ||
777 | |||
778 | /** | ||
779 | * ixgbe_release_nvm_semaphore - Release hardware semaphore | ||
780 | * @hw: pointer to hardware structure | ||
781 | * | ||
782 | * This function clears hardware semaphore bits. | ||
783 | **/ | ||
784 | static void ixgbe_release_swfw_sync_semaphore(struct ixgbe_hw *hw) | ||
785 | { | ||
786 | u32 swsm; | ||
787 | |||
788 | /* Release both semaphores by writing 0 to the bits REGSMP and SMBI */ | ||
789 | |||
790 | swsm = IXGBE_READ_REG(hw, IXGBE_SWSM); | ||
791 | swsm &= ~IXGBE_SWSM_SMBI; | ||
792 | IXGBE_WRITE_REG(hw, IXGBE_SWSM, swsm); | ||
793 | |||
794 | swsm = IXGBE_READ_REG(hw, IXGBE_SWFW_SYNC); | ||
795 | swsm &= ~IXGBE_SWFW_REGSMP; | ||
796 | IXGBE_WRITE_REG(hw, IXGBE_SWFW_SYNC, swsm); | ||
797 | |||
798 | IXGBE_WRITE_FLUSH(hw); | ||
799 | } | ||
800 | |||
801 | /** | ||
802 | * ixgbe_blink_led_start_X540 - Blink LED based on index. | ||
803 | * @hw: pointer to hardware structure | ||
804 | * @index: led number to blink | ||
805 | * | ||
806 | * Devices that implement the version 2 interface: | ||
807 | * X540 | ||
808 | **/ | ||
809 | static s32 ixgbe_blink_led_start_X540(struct ixgbe_hw *hw, u32 index) | ||
810 | { | ||
811 | u32 macc_reg; | ||
812 | u32 ledctl_reg; | ||
813 | |||
814 | /* | ||
815 | * In order for the blink bit in the LED control register | ||
816 | * to work, link and speed must be forced in the MAC. We | ||
817 | * will reverse this when we stop the blinking. | ||
818 | */ | ||
819 | macc_reg = IXGBE_READ_REG(hw, IXGBE_MACC); | ||
820 | macc_reg |= IXGBE_MACC_FLU | IXGBE_MACC_FSV_10G | IXGBE_MACC_FS; | ||
821 | IXGBE_WRITE_REG(hw, IXGBE_MACC, macc_reg); | ||
822 | |||
823 | /* Set the LED to LINK_UP + BLINK. */ | ||
824 | ledctl_reg = IXGBE_READ_REG(hw, IXGBE_LEDCTL); | ||
825 | ledctl_reg &= ~IXGBE_LED_MODE_MASK(index); | ||
826 | ledctl_reg |= IXGBE_LED_BLINK(index); | ||
827 | IXGBE_WRITE_REG(hw, IXGBE_LEDCTL, ledctl_reg); | ||
828 | IXGBE_WRITE_FLUSH(hw); | ||
829 | |||
830 | return 0; | ||
831 | } | ||
832 | |||
833 | /** | ||
834 | * ixgbe_blink_led_stop_X540 - Stop blinking LED based on index. | ||
835 | * @hw: pointer to hardware structure | ||
836 | * @index: led number to stop blinking | ||
837 | * | ||
838 | * Devices that implement the version 2 interface: | ||
839 | * X540 | ||
840 | **/ | ||
841 | static s32 ixgbe_blink_led_stop_X540(struct ixgbe_hw *hw, u32 index) | ||
842 | { | ||
843 | u32 macc_reg; | ||
844 | u32 ledctl_reg; | ||
845 | |||
846 | /* Restore the LED to its default value. */ | ||
847 | ledctl_reg = IXGBE_READ_REG(hw, IXGBE_LEDCTL); | ||
848 | ledctl_reg &= ~IXGBE_LED_MODE_MASK(index); | ||
849 | ledctl_reg |= IXGBE_LED_LINK_ACTIVE << IXGBE_LED_MODE_SHIFT(index); | ||
850 | ledctl_reg &= ~IXGBE_LED_BLINK(index); | ||
851 | IXGBE_WRITE_REG(hw, IXGBE_LEDCTL, ledctl_reg); | ||
852 | |||
853 | /* Unforce link and speed in the MAC. */ | ||
854 | macc_reg = IXGBE_READ_REG(hw, IXGBE_MACC); | ||
855 | macc_reg &= ~(IXGBE_MACC_FLU | IXGBE_MACC_FSV_10G | IXGBE_MACC_FS); | ||
856 | IXGBE_WRITE_REG(hw, IXGBE_MACC, macc_reg); | ||
857 | IXGBE_WRITE_FLUSH(hw); | ||
858 | |||
859 | return 0; | ||
860 | } | ||
861 | static struct ixgbe_mac_operations mac_ops_X540 = { | ||
862 | .init_hw = &ixgbe_init_hw_generic, | ||
863 | .reset_hw = &ixgbe_reset_hw_X540, | ||
864 | .start_hw = &ixgbe_start_hw_X540, | ||
865 | .clear_hw_cntrs = &ixgbe_clear_hw_cntrs_generic, | ||
866 | .get_media_type = &ixgbe_get_media_type_X540, | ||
867 | .get_supported_physical_layer = | ||
868 | &ixgbe_get_supported_physical_layer_X540, | ||
869 | .enable_rx_dma = &ixgbe_enable_rx_dma_generic, | ||
870 | .get_mac_addr = &ixgbe_get_mac_addr_generic, | ||
871 | .get_san_mac_addr = &ixgbe_get_san_mac_addr_generic, | ||
872 | .get_device_caps = &ixgbe_get_device_caps_generic, | ||
873 | .get_wwn_prefix = &ixgbe_get_wwn_prefix_generic, | ||
874 | .stop_adapter = &ixgbe_stop_adapter_generic, | ||
875 | .get_bus_info = &ixgbe_get_bus_info_generic, | ||
876 | .set_lan_id = &ixgbe_set_lan_id_multi_port_pcie, | ||
877 | .read_analog_reg8 = NULL, | ||
878 | .write_analog_reg8 = NULL, | ||
879 | .setup_link = &ixgbe_setup_mac_link_X540, | ||
880 | .set_rxpba = &ixgbe_set_rxpba_generic, | ||
881 | .check_link = &ixgbe_check_mac_link_generic, | ||
882 | .get_link_capabilities = &ixgbe_get_copper_link_capabilities_generic, | ||
883 | .led_on = &ixgbe_led_on_generic, | ||
884 | .led_off = &ixgbe_led_off_generic, | ||
885 | .blink_led_start = &ixgbe_blink_led_start_X540, | ||
886 | .blink_led_stop = &ixgbe_blink_led_stop_X540, | ||
887 | .set_rar = &ixgbe_set_rar_generic, | ||
888 | .clear_rar = &ixgbe_clear_rar_generic, | ||
889 | .set_vmdq = &ixgbe_set_vmdq_generic, | ||
890 | .clear_vmdq = &ixgbe_clear_vmdq_generic, | ||
891 | .init_rx_addrs = &ixgbe_init_rx_addrs_generic, | ||
892 | .update_mc_addr_list = &ixgbe_update_mc_addr_list_generic, | ||
893 | .enable_mc = &ixgbe_enable_mc_generic, | ||
894 | .disable_mc = &ixgbe_disable_mc_generic, | ||
895 | .clear_vfta = &ixgbe_clear_vfta_generic, | ||
896 | .set_vfta = &ixgbe_set_vfta_generic, | ||
897 | .fc_enable = &ixgbe_fc_enable_generic, | ||
898 | .set_fw_drv_ver = &ixgbe_set_fw_drv_ver_generic, | ||
899 | .init_uta_tables = &ixgbe_init_uta_tables_generic, | ||
900 | .setup_sfp = NULL, | ||
901 | .set_mac_anti_spoofing = &ixgbe_set_mac_anti_spoofing, | ||
902 | .set_vlan_anti_spoofing = &ixgbe_set_vlan_anti_spoofing, | ||
903 | .acquire_swfw_sync = &ixgbe_acquire_swfw_sync_X540, | ||
904 | .release_swfw_sync = &ixgbe_release_swfw_sync_X540, | ||
905 | }; | ||
906 | |||
907 | static struct ixgbe_eeprom_operations eeprom_ops_X540 = { | ||
908 | .init_params = &ixgbe_init_eeprom_params_X540, | ||
909 | .read = &ixgbe_read_eerd_X540, | ||
910 | .read_buffer = &ixgbe_read_eerd_buffer_X540, | ||
911 | .write = &ixgbe_write_eewr_X540, | ||
912 | .write_buffer = &ixgbe_write_eewr_buffer_X540, | ||
913 | .calc_checksum = &ixgbe_calc_eeprom_checksum_X540, | ||
914 | .validate_checksum = &ixgbe_validate_eeprom_checksum_X540, | ||
915 | .update_checksum = &ixgbe_update_eeprom_checksum_X540, | ||
916 | }; | ||
917 | |||
918 | static struct ixgbe_phy_operations phy_ops_X540 = { | ||
919 | .identify = &ixgbe_identify_phy_generic, | ||
920 | .identify_sfp = &ixgbe_identify_sfp_module_generic, | ||
921 | .init = NULL, | ||
922 | .reset = NULL, | ||
923 | .read_reg = &ixgbe_read_phy_reg_generic, | ||
924 | .write_reg = &ixgbe_write_phy_reg_generic, | ||
925 | .setup_link = &ixgbe_setup_phy_link_generic, | ||
926 | .setup_link_speed = &ixgbe_setup_phy_link_speed_generic, | ||
927 | .read_i2c_byte = &ixgbe_read_i2c_byte_generic, | ||
928 | .write_i2c_byte = &ixgbe_write_i2c_byte_generic, | ||
929 | .read_i2c_eeprom = &ixgbe_read_i2c_eeprom_generic, | ||
930 | .write_i2c_eeprom = &ixgbe_write_i2c_eeprom_generic, | ||
931 | .check_overtemp = &ixgbe_tn_check_overtemp, | ||
932 | }; | ||
933 | |||
934 | struct ixgbe_info ixgbe_X540_info = { | ||
935 | .mac = ixgbe_mac_X540, | ||
936 | .get_invariants = &ixgbe_get_invariants_X540, | ||
937 | .mac_ops = &mac_ops_X540, | ||
938 | .eeprom_ops = &eeprom_ops_X540, | ||
939 | .phy_ops = &phy_ops_X540, | ||
940 | .mbx_ops = &mbx_ops_generic, | ||
941 | }; | ||