aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/ethernet/intel/ixgbe
diff options
context:
space:
mode:
authorJeff Kirsher <jeffrey.t.kirsher@intel.com>2011-04-07 10:42:33 -0400
committerJeff Kirsher <jeffrey.t.kirsher@intel.com>2011-08-10 23:03:27 -0400
commitdee1ad47f2ee75f5146d83ca757c1b7861c34c3b (patch)
tree47cbdefe3d0f9b729724e378ad6a96eaddfd5fbc /drivers/net/ethernet/intel/ixgbe
parentf7917c009c28c941ba151ee66f04dc7f6a2e1e0b (diff)
intel: Move the Intel wired LAN drivers
Moves the Intel wired LAN drivers into drivers/net/ethernet/intel/ and the necessary Kconfig and Makefile changes. Signed-off-by: Jeff Kirsher <jeffrey.t.kirsher@intel.com>
Diffstat (limited to 'drivers/net/ethernet/intel/ixgbe')
-rw-r--r--drivers/net/ethernet/intel/ixgbe/Makefile42
-rw-r--r--drivers/net/ethernet/intel/ixgbe/ixgbe.h617
-rw-r--r--drivers/net/ethernet/intel/ixgbe/ixgbe_82598.c1353
-rw-r--r--drivers/net/ethernet/intel/ixgbe/ixgbe_82599.c2263
-rw-r--r--drivers/net/ethernet/intel/ixgbe/ixgbe_common.c3510
-rw-r--r--drivers/net/ethernet/intel/ixgbe/ixgbe_common.h145
-rw-r--r--drivers/net/ethernet/intel/ixgbe/ixgbe_dcb.c320
-rw-r--r--drivers/net/ethernet/intel/ixgbe/ixgbe_dcb.h167
-rw-r--r--drivers/net/ethernet/intel/ixgbe/ixgbe_dcb_82598.c297
-rw-r--r--drivers/net/ethernet/intel/ixgbe/ixgbe_dcb_82598.h97
-rw-r--r--drivers/net/ethernet/intel/ixgbe/ixgbe_dcb_82599.c346
-rw-r--r--drivers/net/ethernet/intel/ixgbe/ixgbe_dcb_82599.h123
-rw-r--r--drivers/net/ethernet/intel/ixgbe/ixgbe_dcb_nl.c816
-rw-r--r--drivers/net/ethernet/intel/ixgbe/ixgbe_ethtool.c2592
-rw-r--r--drivers/net/ethernet/intel/ixgbe/ixgbe_fcoe.c836
-rw-r--r--drivers/net/ethernet/intel/ixgbe/ixgbe_fcoe.h81
-rw-r--r--drivers/net/ethernet/intel/ixgbe/ixgbe_main.c7934
-rw-r--r--drivers/net/ethernet/intel/ixgbe/ixgbe_mbx.c471
-rw-r--r--drivers/net/ethernet/intel/ixgbe/ixgbe_mbx.h93
-rw-r--r--drivers/net/ethernet/intel/ixgbe/ixgbe_phy.c1725
-rw-r--r--drivers/net/ethernet/intel/ixgbe/ixgbe_phy.h131
-rw-r--r--drivers/net/ethernet/intel/ixgbe/ixgbe_sriov.c687
-rw-r--r--drivers/net/ethernet/intel/ixgbe/ixgbe_sriov.h46
-rw-r--r--drivers/net/ethernet/intel/ixgbe/ixgbe_type.h2877
-rw-r--r--drivers/net/ethernet/intel/ixgbe/ixgbe_x540.c941
25 files changed, 28510 insertions, 0 deletions
diff --git a/drivers/net/ethernet/intel/ixgbe/Makefile b/drivers/net/ethernet/intel/ixgbe/Makefile
new file mode 100644
index 000000000000..7d7387fbdecd
--- /dev/null
+++ b/drivers/net/ethernet/intel/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
33obj-$(CONFIG_IXGBE) += ixgbe.o
34
35ixgbe-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
39ixgbe-$(CONFIG_IXGBE_DCB) += ixgbe_dcb.o ixgbe_dcb_82598.o \
40 ixgbe_dcb_82599.o ixgbe_dcb_nl.o
41
42ixgbe-$(CONFIG_FCOE:m=y) += ixgbe_fcoe.o
diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe.h b/drivers/net/ethernet/intel/ixgbe/ixgbe.h
new file mode 100644
index 000000000000..e04a8e49e6dc
--- /dev/null
+++ b/drivers/net/ethernet/intel/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
112struct 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
125struct 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 */
143struct 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
154struct 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
162struct ixgbe_queue_stats {
163 u64 packets;
164 u64 bytes;
165};
166
167struct ixgbe_tx_queue_stats {
168 u64 restart_queue;
169 u64 tx_busy;
170 u64 completed;
171 u64 tx_done_old;
172};
173
174struct 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
182enum 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)
208struct 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
248enum 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 */
271struct ixgbe_ring_feature {
272 int indices;
273 int mask;
274} ____cacheline_internodealigned_in_smp;
275
276struct 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 */
296struct 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
319static 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 */
355struct 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
508struct ixgbe_fdir_filter {
509 struct hlist_node fdir_node;
510 union ixgbe_atr_input filter;
511 u16 sw_idx;
512 u16 action;
513};
514
515enum ixbge_state_t {
516 __IXGBE_TESTING,
517 __IXGBE_RESETTING,
518 __IXGBE_DOWN,
519 __IXGBE_SERVICE_SCHED,
520 __IXGBE_IN_SFP_INIT,
521};
522
523struct 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
530enum ixgbe_boards {
531 board_82598,
532 board_82599,
533 board_X540,
534};
535
536extern struct ixgbe_info ixgbe_82598_info;
537extern struct ixgbe_info ixgbe_82599_info;
538extern struct ixgbe_info ixgbe_X540_info;
539#ifdef CONFIG_IXGBE_DCB
540extern const struct dcbnl_rtnl_ops dcbnl_ops;
541extern 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
546extern char ixgbe_driver_name[];
547extern const char ixgbe_driver_version[];
548
549extern int ixgbe_up(struct ixgbe_adapter *adapter);
550extern void ixgbe_down(struct ixgbe_adapter *adapter);
551extern void ixgbe_reinit_locked(struct ixgbe_adapter *adapter);
552extern void ixgbe_reset(struct ixgbe_adapter *adapter);
553extern void ixgbe_set_ethtool_ops(struct net_device *netdev);
554extern int ixgbe_setup_rx_resources(struct ixgbe_ring *);
555extern int ixgbe_setup_tx_resources(struct ixgbe_ring *);
556extern void ixgbe_free_rx_resources(struct ixgbe_ring *);
557extern void ixgbe_free_tx_resources(struct ixgbe_ring *);
558extern void ixgbe_configure_rx_ring(struct ixgbe_adapter *,struct ixgbe_ring *);
559extern void ixgbe_configure_tx_ring(struct ixgbe_adapter *,struct ixgbe_ring *);
560extern void ixgbe_disable_rx_queue(struct ixgbe_adapter *adapter,
561 struct ixgbe_ring *);
562extern void ixgbe_update_stats(struct ixgbe_adapter *adapter);
563extern int ixgbe_init_interrupt_scheme(struct ixgbe_adapter *adapter);
564extern void ixgbe_clear_interrupt_scheme(struct ixgbe_adapter *adapter);
565extern netdev_tx_t ixgbe_xmit_frame_ring(struct sk_buff *,
566 struct ixgbe_adapter *,
567 struct ixgbe_ring *);
568extern void ixgbe_unmap_and_free_tx_resource(struct ixgbe_ring *,
569 struct ixgbe_tx_buffer *);
570extern void ixgbe_alloc_rx_buffers(struct ixgbe_ring *, u16);
571extern void ixgbe_write_eitr(struct ixgbe_q_vector *);
572extern int ethtool_ioctl(struct ifreq *ifr);
573extern s32 ixgbe_reinit_fdir_tables_82599(struct ixgbe_hw *hw);
574extern s32 ixgbe_init_fdir_signature_82599(struct ixgbe_hw *hw, u32 fdirctrl);
575extern s32 ixgbe_init_fdir_perfect_82599(struct ixgbe_hw *hw, u32 fdirctrl);
576extern 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);
580extern s32 ixgbe_fdir_set_input_mask_82599(struct ixgbe_hw *hw,
581 union ixgbe_atr_input *input_mask);
582extern s32 ixgbe_fdir_write_perfect_filter_82599(struct ixgbe_hw *hw,
583 union ixgbe_atr_input *input,
584 u16 soft_id, u8 queue);
585extern s32 ixgbe_fdir_erase_perfect_filter_82599(struct ixgbe_hw *hw,
586 union ixgbe_atr_input *input,
587 u16 soft_id);
588extern void ixgbe_atr_compute_perfect_hash_82599(union ixgbe_atr_input *input,
589 union ixgbe_atr_input *mask);
590extern void ixgbe_set_rx_mode(struct net_device *netdev);
591extern int ixgbe_setup_tc(struct net_device *dev, u8 tc);
592extern void ixgbe_tx_ctxtdesc(struct ixgbe_ring *, u32, u32, u32, u32);
593extern void ixgbe_do_reset(struct net_device *netdev);
594#ifdef IXGBE_FCOE
595extern void ixgbe_configure_fcoe(struct ixgbe_adapter *adapter);
596extern int ixgbe_fso(struct ixgbe_ring *tx_ring, struct sk_buff *skb,
597 u32 tx_flags, u8 *hdr_len);
598extern void ixgbe_cleanup_fcoe(struct ixgbe_adapter *adapter);
599extern int ixgbe_fcoe_ddp(struct ixgbe_adapter *adapter,
600 union ixgbe_adv_rx_desc *rx_desc,
601 struct sk_buff *skb,
602 u32 staterr);
603extern int ixgbe_fcoe_ddp_get(struct net_device *netdev, u16 xid,
604 struct scatterlist *sgl, unsigned int sgc);
605extern int ixgbe_fcoe_ddp_target(struct net_device *netdev, u16 xid,
606 struct scatterlist *sgl, unsigned int sgc);
607extern int ixgbe_fcoe_ddp_put(struct net_device *netdev, u16 xid);
608extern int ixgbe_fcoe_enable(struct net_device *netdev);
609extern int ixgbe_fcoe_disable(struct net_device *netdev);
610#ifdef CONFIG_IXGBE_DCB
611extern u8 ixgbe_fcoe_getapp(struct ixgbe_adapter *adapter);
612extern u8 ixgbe_fcoe_setapp(struct ixgbe_adapter *adapter, u8 up);
613#endif /* CONFIG_IXGBE_DCB */
614extern 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/ethernet/intel/ixgbe/ixgbe_82598.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_82598.c
new file mode 100644
index 000000000000..0d4e38264492
--- /dev/null
+++ b/drivers/net/ethernet/intel/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
42static s32 ixgbe_setup_copper_link_82598(struct ixgbe_hw *hw,
43 ixgbe_link_speed speed,
44 bool autoneg,
45 bool autoneg_wait_to_complete);
46static 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 **/
59static 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);
88out:
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 **/
101static 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 */
117static 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 **/
143static 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
192out:
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 **/
204static 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 **/
245static 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 **/
302static 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 }
344out:
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 **/
355static 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
489out:
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 **/
500static 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 **/
546static 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 **/
582static 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 }
662out:
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 **/
675static 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 **/
727static 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 **/
751static 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
811no_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
818mac_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
880reset_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 **/
893static 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 **/
917static 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 **/
947static 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 **/
992static 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 **/
1016static 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 **/
1038static 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 **/
1058static 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
1108out:
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 **/
1118static 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
1209out:
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 **/
1221static 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 */
1252static 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
1286static 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
1324static 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
1333static 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
1346struct 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/ethernet/intel/ixgbe/ixgbe_82599.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_82599.c
new file mode 100644
index 000000000000..34f30ec79c2e
--- /dev/null
+++ b/drivers/net/ethernet/intel/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
43static void ixgbe_disable_tx_laser_multispeed_fiber(struct ixgbe_hw *hw);
44static void ixgbe_enable_tx_laser_multispeed_fiber(struct ixgbe_hw *hw);
45static void ixgbe_flap_tx_laser_multispeed_fiber(struct ixgbe_hw *hw);
46static 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);
50static s32 ixgbe_setup_mac_link_smartspeed(struct ixgbe_hw *hw,
51 ixgbe_link_speed speed,
52 bool autoneg,
53 bool autoneg_wait_to_complete);
54static s32 ixgbe_start_mac_link_82599(struct ixgbe_hw *hw,
55 bool autoneg_wait_to_complete);
56static s32 ixgbe_setup_mac_link_82599(struct ixgbe_hw *hw,
57 ixgbe_link_speed speed,
58 bool autoneg,
59 bool autoneg_wait_to_complete);
60static s32 ixgbe_setup_copper_link_82599(struct ixgbe_hw *hw,
61 ixgbe_link_speed speed,
62 bool autoneg,
63 bool autoneg_wait_to_complete);
64static s32 ixgbe_verify_fw_version_82599(struct ixgbe_hw *hw);
65static bool ixgbe_verify_lesm_fw_enabled_82599(struct ixgbe_hw *hw);
66
67static 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
99static 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
164setup_sfp_out:
165 return ret_val;
166}
167
168static 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 **/
193static 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 **/
239static 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
325out:
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 **/
335static 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 }
379out:
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 **/
391static 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 **/
440static 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 **/
459static 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 **/
482static 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 **/
500static 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
634out:
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 **/
656static 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
752out:
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 **/
768static 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
868out:
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 **/
881static 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 **/
905static 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
943mac_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
1031reset_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 **/
1039s32 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 **/
1115static 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 **/
1188static 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 **/
1228s32 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 **/
1259s32 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) \
1298do { \
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 **/
1324static 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 **/
1387s32 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) \
1432do { \
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 **/
1451void 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 **/
1535static 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
1563s32 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
1659s32 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
1716s32 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 **/
1767static 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 **/
1789static 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 **/
1809static 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);
1827out:
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 **/
1839static 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
1863out:
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 **/
1873static 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
1946sfp_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
1982out:
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 **/
1993static 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 **/
2041static 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
2075fw_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 **/
2086static 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
2117out:
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 **/
2132static 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 **/
2164static 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
2183static 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
2229static 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
2240static 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
2256struct 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/ethernet/intel/ixgbe/ixgbe_common.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_common.c
new file mode 100644
index 000000000000..fc1375f26fe5
--- /dev/null
+++ b/drivers/net/ethernet/intel/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
37static s32 ixgbe_acquire_eeprom(struct ixgbe_hw *hw);
38static s32 ixgbe_get_eeprom_semaphore(struct ixgbe_hw *hw);
39static void ixgbe_release_eeprom_semaphore(struct ixgbe_hw *hw);
40static s32 ixgbe_ready_eeprom(struct ixgbe_hw *hw);
41static void ixgbe_standby_eeprom(struct ixgbe_hw *hw);
42static void ixgbe_shift_out_eeprom_bits(struct ixgbe_hw *hw, u16 data,
43 u16 count);
44static u16 ixgbe_shift_in_eeprom_bits(struct ixgbe_hw *hw, u16 count);
45static void ixgbe_raise_eeprom_clk(struct ixgbe_hw *hw, u32 *eec);
46static void ixgbe_lower_eeprom_clk(struct ixgbe_hw *hw, u32 *eec);
47static void ixgbe_release_eeprom(struct ixgbe_hw *hw);
48
49static s32 ixgbe_mta_vector(struct ixgbe_hw *hw, u8 *mc_addr);
50static s32 ixgbe_fc_autoneg_fiber(struct ixgbe_hw *hw);
51static s32 ixgbe_fc_autoneg_backplane(struct ixgbe_hw *hw);
52static s32 ixgbe_fc_autoneg_copper(struct ixgbe_hw *hw);
53static s32 ixgbe_device_supports_autoneg_fc(struct ixgbe_hw *hw);
54static 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);
56static s32 ixgbe_setup_fc(struct ixgbe_hw *hw, s32 packetbuf_num);
57static s32 ixgbe_poll_eerd_eewr_done(struct ixgbe_hw *hw, u32 ee_reg);
58static s32 ixgbe_read_eeprom_buffer_bit_bang(struct ixgbe_hw *hw, u16 offset,
59 u16 words, u16 *data);
60static s32 ixgbe_write_eeprom_buffer_bit_bang(struct ixgbe_hw *hw, u16 offset,
61 u16 words, u16 *data);
62static 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 **/
74s32 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 **/
115s32 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 **/
154s32 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 **/
176s32 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 **/
284s32 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 **/
394s32 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 **/
418s32 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 **/
472void 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 **/
496s32 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 **/
545s32 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 **/
563s32 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 **/
583s32 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 **/
636s32 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
677out:
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 **/
691static 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 **/
771s32 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
784out:
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 **/
797s32 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
831out:
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 **/
844static 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 **/
899s32 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
913out:
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 **/
926s32 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 }
960out:
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 **/
973static 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);
1002out:
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 **/
1014s32 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 **/
1028s32 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
1067out:
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 **/
1079s32 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 **/
1092static 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 **/
1120static 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 **/
1171static 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 **/
1258static 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 **/
1274static 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 **/
1313static 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 **/
1336static 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 **/
1389static 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 **/
1427static 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 **/
1444static 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 **/
1460static 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 **/
1492u16 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 **/
1540s32 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 **/
1580s32 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 **/
1609s32 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 **/
1637s32 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 **/
1685s32 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 **/
1721s32 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 **/
1784static 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 **/
1818static 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 **/
1853s32 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 **/
1895s32 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 **/
1912s32 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 **/
1929s32 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
2039out:
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 **/
2050s32 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
2096out:
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 **/
2112static 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
2139out:
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 **/
2149static 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
2187out:
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 **/
2197static 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 **/
2228static 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 **/
2270static 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, &reg_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);
2447out:
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 **/
2460s32 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 */
2500check_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
2524out:
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 **/
2537s32 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 **/
2585void 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 **/
2606s32 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 **/
2618s32 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 **/
2652s32 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 **/
2679static 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 **/
2701s32 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
2735san_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 **/
2746u32 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 **/
2766s32 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);
2803done:
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 **/
2813s32 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 **/
2840s32 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 **/
2858static 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 **/
2906s32 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 **/
3046s32 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 **/
3071s32 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 **/
3136s32 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
3167wwn_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 **/
3180static 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 **/
3200void 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 **/
3240void 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 **/
3265s32 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 **/
3279void 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 **/
3345static 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 **/
3369static 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
3449out:
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 **/
3466s32 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);
3508out:
3509 return ret_val;
3510}
diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_common.h b/drivers/net/ethernet/intel/ixgbe/ixgbe_common.h
new file mode 100644
index 000000000000..f24fd64a4c46
--- /dev/null
+++ b/drivers/net/ethernet/intel/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
34u32 ixgbe_get_pcie_msix_count_generic(struct ixgbe_hw *hw);
35s32 ixgbe_init_ops_generic(struct ixgbe_hw *hw);
36s32 ixgbe_init_hw_generic(struct ixgbe_hw *hw);
37s32 ixgbe_start_hw_generic(struct ixgbe_hw *hw);
38s32 ixgbe_start_hw_gen2(struct ixgbe_hw *hw);
39s32 ixgbe_clear_hw_cntrs_generic(struct ixgbe_hw *hw);
40s32 ixgbe_read_pba_string_generic(struct ixgbe_hw *hw, u8 *pba_num,
41 u32 pba_num_size);
42s32 ixgbe_get_mac_addr_generic(struct ixgbe_hw *hw, u8 *mac_addr);
43s32 ixgbe_get_bus_info_generic(struct ixgbe_hw *hw);
44void ixgbe_set_lan_id_multi_port_pcie(struct ixgbe_hw *hw);
45s32 ixgbe_stop_adapter_generic(struct ixgbe_hw *hw);
46
47s32 ixgbe_led_on_generic(struct ixgbe_hw *hw, u32 index);
48s32 ixgbe_led_off_generic(struct ixgbe_hw *hw, u32 index);
49
50s32 ixgbe_init_eeprom_params_generic(struct ixgbe_hw *hw);
51s32 ixgbe_write_eeprom_generic(struct ixgbe_hw *hw, u16 offset, u16 data);
52s32 ixgbe_write_eeprom_buffer_bit_bang_generic(struct ixgbe_hw *hw, u16 offset,
53 u16 words, u16 *data);
54s32 ixgbe_read_eerd_generic(struct ixgbe_hw *hw, u16 offset, u16 *data);
55s32 ixgbe_read_eerd_buffer_generic(struct ixgbe_hw *hw, u16 offset,
56 u16 words, u16 *data);
57s32 ixgbe_write_eewr_generic(struct ixgbe_hw *hw, u16 offset, u16 data);
58s32 ixgbe_write_eewr_buffer_generic(struct ixgbe_hw *hw, u16 offset,
59 u16 words, u16 *data);
60s32 ixgbe_read_eeprom_bit_bang_generic(struct ixgbe_hw *hw, u16 offset,
61 u16 *data);
62s32 ixgbe_read_eeprom_buffer_bit_bang_generic(struct ixgbe_hw *hw, u16 offset,
63 u16 words, u16 *data);
64u16 ixgbe_calc_eeprom_checksum_generic(struct ixgbe_hw *hw);
65s32 ixgbe_validate_eeprom_checksum_generic(struct ixgbe_hw *hw,
66 u16 *checksum_val);
67s32 ixgbe_update_eeprom_checksum_generic(struct ixgbe_hw *hw);
68
69s32 ixgbe_set_rar_generic(struct ixgbe_hw *hw, u32 index, u8 *addr, u32 vmdq,
70 u32 enable_addr);
71s32 ixgbe_clear_rar_generic(struct ixgbe_hw *hw, u32 index);
72s32 ixgbe_init_rx_addrs_generic(struct ixgbe_hw *hw);
73s32 ixgbe_update_mc_addr_list_generic(struct ixgbe_hw *hw,
74 struct net_device *netdev);
75s32 ixgbe_enable_mc_generic(struct ixgbe_hw *hw);
76s32 ixgbe_disable_mc_generic(struct ixgbe_hw *hw);
77s32 ixgbe_enable_rx_dma_generic(struct ixgbe_hw *hw, u32 regval);
78s32 ixgbe_fc_enable_generic(struct ixgbe_hw *hw, s32 packtetbuf_num);
79s32 ixgbe_fc_autoneg(struct ixgbe_hw *hw);
80
81s32 ixgbe_validate_mac_addr(u8 *mac_addr);
82s32 ixgbe_acquire_swfw_sync(struct ixgbe_hw *hw, u16 mask);
83void ixgbe_release_swfw_sync(struct ixgbe_hw *hw, u16 mask);
84s32 ixgbe_disable_pcie_master(struct ixgbe_hw *hw);
85s32 ixgbe_get_san_mac_addr_generic(struct ixgbe_hw *hw, u8 *san_mac_addr);
86s32 ixgbe_set_vmdq_generic(struct ixgbe_hw *hw, u32 rar, u32 vmdq);
87s32 ixgbe_clear_vmdq_generic(struct ixgbe_hw *hw, u32 rar, u32 vmdq);
88s32 ixgbe_init_uta_tables_generic(struct ixgbe_hw *hw);
89s32 ixgbe_set_vfta_generic(struct ixgbe_hw *hw, u32 vlan,
90 u32 vind, bool vlan_on);
91s32 ixgbe_clear_vfta_generic(struct ixgbe_hw *hw);
92s32 ixgbe_check_mac_link_generic(struct ixgbe_hw *hw,
93 ixgbe_link_speed *speed,
94 bool *link_up, bool link_up_wait_to_complete);
95s32 ixgbe_get_wwn_prefix_generic(struct ixgbe_hw *hw, u16 *wwnn_prefix,
96 u16 *wwpn_prefix);
97s32 ixgbe_blink_led_start_generic(struct ixgbe_hw *hw, u32 index);
98s32 ixgbe_blink_led_stop_generic(struct ixgbe_hw *hw, u32 index);
99void ixgbe_set_mac_anti_spoofing(struct ixgbe_hw *hw, bool enable, int pf);
100void ixgbe_set_vlan_anti_spoofing(struct ixgbe_hw *hw, bool enable, int vf);
101s32 ixgbe_get_device_caps_generic(struct ixgbe_hw *hw, u16 *device_caps);
102s32 ixgbe_set_fw_drv_ver_generic(struct ixgbe_hw *hw, u8 maj, u8 min,
103 u8 build, u8 ver);
104
105void 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/ethernet/intel/ixgbe/ixgbe_dcb.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_dcb.c
new file mode 100644
index 000000000000..9d88c31487bc
--- /dev/null
+++ b/drivers/net/ethernet/intel/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 */
43s32 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 */
81s32 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
176out:
177 return ret_val;
178}
179
180void 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
189void 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
201void 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
209void 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
221void 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 */
240s32 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 */
276s32 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
294s32 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/ethernet/intel/ixgbe/ixgbe_dcb.h b/drivers/net/ethernet/intel/ixgbe/ixgbe_dcb.h
new file mode 100644
index 000000000000..e85826ae0320
--- /dev/null
+++ b/drivers/net/ethernet/intel/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
66struct dcb_pfc_tc_debug {
67 u8 tc;
68 u8 pause_status;
69 u64 pause_quanta;
70};
71
72enum 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
87struct 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 */
99struct 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
110enum 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 */
118struct 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
126struct dcb_num_tcs {
127 u8 pg_tcs;
128 u8 pfc_tcs;
129};
130
131struct 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 */
143void ixgbe_dcb_unpack_pfc(struct ixgbe_dcb_config *cfg, u8 *pfc_en);
144void ixgbe_dcb_unpack_refill(struct ixgbe_dcb_config *, int, u16 *);
145void ixgbe_dcb_unpack_max(struct ixgbe_dcb_config *, u16 *);
146void ixgbe_dcb_unpack_bwgid(struct ixgbe_dcb_config *, int, u8 *);
147void ixgbe_dcb_unpack_prio(struct ixgbe_dcb_config *, int, u8 *);
148
149/* DCB credits calculation */
150s32 ixgbe_ieee_credits(__u8 *bw, __u16 *refill, __u16 *max, int max_frame);
151s32 ixgbe_dcb_calculate_tc_credits(struct ixgbe_hw *,
152 struct ixgbe_dcb_config *, int, u8);
153
154/* DCB hw initialization */
155s32 ixgbe_dcb_hw_ets_config(struct ixgbe_hw *hw, u16 *refill, u16 *max,
156 u8 *bwg_id, u8 *prio_type, u8 *tc_prio);
157s32 ixgbe_dcb_hw_pfc_config(struct ixgbe_hw *hw, u8 pfc_en);
158s32 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/ethernet/intel/ixgbe/ixgbe_dcb_82598.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_dcb_82598.c
new file mode 100644
index 000000000000..2288c3cac010
--- /dev/null
+++ b/drivers/net/ethernet/intel/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 */
41s32 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 */
98s32 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 */
145s32 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 */
192s32 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 */
253static 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 */
285s32 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/ethernet/intel/ixgbe/ixgbe_dcb_82598.h b/drivers/net/ethernet/intel/ixgbe/ixgbe_dcb_82598.h
new file mode 100644
index 000000000000..2f318935561a
--- /dev/null
+++ b/drivers/net/ethernet/intel/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 */
74s32 ixgbe_dcb_config_pfc_82598(struct ixgbe_hw *, u8 pfc_en);
75
76/* DCB hw initialization */
77s32 ixgbe_dcb_config_rx_arbiter_82598(struct ixgbe_hw *hw,
78 u16 *refill,
79 u16 *max,
80 u8 *prio_type);
81
82s32 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
88s32 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
94s32 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/ethernet/intel/ixgbe/ixgbe_dcb_82599.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_dcb_82599.c
new file mode 100644
index 000000000000..ade98200288c
--- /dev/null
+++ b/drivers/net/ethernet/intel/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 */
43s32 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 */
102s32 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 */
153s32 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 */
211s32 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 */
275static 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 */
332s32 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/ethernet/intel/ixgbe/ixgbe_dcb_82599.h b/drivers/net/ethernet/intel/ixgbe/ixgbe_dcb_82599.h
new file mode 100644
index 000000000000..08d1749862a3
--- /dev/null
+++ b/drivers/net/ethernet/intel/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 */
96s32 ixgbe_dcb_config_pfc_82599(struct ixgbe_hw *hw, u8 pfc_en);
97
98/* DCB hw initialization */
99s32 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
106s32 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
112s32 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
119s32 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/ethernet/intel/ixgbe/ixgbe_dcb_nl.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_dcb_nl.c
new file mode 100644
index 000000000000..0ace6ce1d0b4
--- /dev/null
+++ b/drivers/net/ethernet/intel/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
47int 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
105static 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
112static 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
163out:
164 return err;
165}
166
167static 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
189static 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
217static 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
229static 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
257static 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
269static 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
281static 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
289static 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
301static 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
309static 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
322static 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
330static 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
448static 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
485static 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
509static u8 ixgbe_dcbnl_setnumtcs(struct net_device *netdev, int tcid, u8 num)
510{
511 return -EINVAL;
512}
513
514static 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
521static 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 */
541static 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
555static 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
574static 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
628static 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
652static 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
674static 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
689static 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
715static 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
742static u8 ixgbe_dcbnl_getdcbx(struct net_device *dev)
743{
744 struct ixgbe_adapter *adapter = netdev_priv(dev);
745 return adapter->dcbx_cap;
746}
747
748static 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
787const 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/ethernet/intel/ixgbe/ixgbe_ethtool.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_ethtool.c
new file mode 100644
index 000000000000..82d4244c6e10
--- /dev/null
+++ b/drivers/net/ethernet/intel/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
45enum {NETDEV_STATS, IXGBE_STATS};
46
47struct 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
61static 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
138static 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
145static 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
317static 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
365static 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
397static 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
445static u32 ixgbe_get_msglevel(struct net_device *netdev)
446{
447 struct ixgbe_adapter *adapter = netdev_priv(netdev);
448 return adapter->msg_enable;
449}
450
451static 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
457static 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
465static 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
771static 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
777static 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
813static 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
838static 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
855static 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);
967err_setup:
968 vfree(temp_tx_ring);
969clear_reset:
970 clear_bit(__IXGBE_RESETTING, &adapter->state);
971 return err;
972}
973
974static 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
986static 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
1044static 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
1093static 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 */
1109struct 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 */
1135static 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 */
1159static 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
1186static 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
1211static 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
1242static 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
1329static 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
1339static 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
1349static 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
1462static 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
1499static 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
1557err_nomem:
1558 ixgbe_free_desc_rings(adapter);
1559 return ret_val;
1560}
1561
1562static 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
1615static 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
1624static 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
1634static 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
1647static 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
1704static 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
1768static 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
1779err_loopback:
1780 ixgbe_free_desc_rings(adapter);
1781out:
1782 return *data;
1783}
1784
1785static 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
1857skip_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 }
1877skip_ol_tests:
1878 msleep_interruptible(4 * 1000);
1879}
1880
1881static 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
1916static 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
1939static 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
1965static 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
1975static 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
2003static 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 */
2052static 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
2083static 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
2194static 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
2263static 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
2285static 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
2314static 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
2371static 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
2411static 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;
2520err_out_w_lock:
2521 spin_unlock(&adapter->fdir_perfect_lock);
2522err_out:
2523 kfree(input);
2524 return -EINVAL;
2525}
2526
2527static 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
2541static 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
2560static 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
2589void ixgbe_set_ethtool_ops(struct net_device *netdev)
2590{
2591 SET_ETHTOOL_OPS(netdev, &ixgbe_ethtool_ops);
2592}
diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_fcoe.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_fcoe.c
new file mode 100644
index 000000000000..824edae77865
--- /dev/null
+++ b/drivers/net/ethernet/intel/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 */
46static 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 */
67int 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
116out_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 */
129static 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
298out_noddp_free:
299 pci_pool_free(pool, ddp->udl, ddp->udp);
300 ixgbe_fcoe_clear_ddp(ddp);
301
302out_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 */
322int 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 */
343int 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 */
361int 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 }
435ddp_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 */
451int 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
548static 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
562static 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 */
596void 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
669out_extra_ddp_buffer:
670 kfree(fcoe->extra_ddp_buffer);
671out_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 */
683void 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 */
709int 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
743out_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 */
755int 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
790out_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 */
806int 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/ethernet/intel/ixgbe/ixgbe_fcoe.h b/drivers/net/ethernet/intel/ixgbe/ixgbe_fcoe.h
new file mode 100644
index 000000000000..99de145e290d
--- /dev/null
+++ b/drivers/net/ethernet/intel/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
58struct 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
68struct 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/ethernet/intel/ixgbe/ixgbe_main.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c
new file mode 100644
index 000000000000..e86297b32733
--- /dev/null
+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c
@@ -0,0 +1,7934 @@
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
54char ixgbe_driver_name[] = "ixgbe";
55static 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"
62const char ixgbe_driver_version[] = DRV_VERSION;
63static const char ixgbe_copyright[] =
64 "Copyright (c) 1999-2011 Intel Corporation.";
65
66static 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 */
80static 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};
137MODULE_DEVICE_TABLE(pci, ixgbe_pci_tbl);
138
139#ifdef CONFIG_IXGBE_DCA
140static int ixgbe_notify_dca(struct notifier_block *, unsigned long event,
141 void *p);
142static 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
150static unsigned int max_vfs;
151module_param(max_vfs, uint, 0);
152MODULE_PARM_DESC(max_vfs,
153 "Maximum number of virtual functions to allocate per physical function");
154#endif /* CONFIG_PCI_IOV */
155
156MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
157MODULE_DESCRIPTION("Intel(R) 10 Gigabit PCI Express Network Driver");
158MODULE_LICENSE("GPL");
159MODULE_VERSION(DRV_VERSION);
160
161#define DEFAULT_DEBUG_LEVEL_SHIFT 3
162
163static 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
199static 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
206static 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
215struct ixgbe_reg_info {
216 u32 ofs;
217 char *name;
218};
219
220static 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 */
256static 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 */
338static 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 */
454rx_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
549exit:
550 return;
551}
552
553static 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
563static 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 */
581static 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
623static 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
645void 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
669static 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
721static u64 ixgbe_get_tx_completed(struct ixgbe_ring *ring)
722{
723 return ring->tx_stats.completed;
724}
725
726static 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
741static 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 **/
780static 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 **/
795static 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
894static 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
923static 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
953static 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;
978out_no_update:
979 put_cpu();
980}
981
982static 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
1004static 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
1036static 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 */
1049static 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 **/
1068static 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 **/
1094static 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
1134static 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 **/
1151void 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
1230no_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
1237static 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 **/
1259static 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
1282static 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
1288static 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 /* if this is a skb from previous receive DMA will be 0 */
1325 if (rx_buffer_info->dma) {
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 goto next_desc;
1464 }
1465#endif /* IXGBE_FCOE */
1466 ixgbe_receive_skb(q_vector, skb, staterr, rx_ring, rx_desc);
1467
1468next_desc:
1469 rx_desc->wb.upper.status_error = 0;
1470
1471 (*work_done)++;
1472 if (*work_done >= work_to_do)
1473 break;
1474
1475 /* return some buffers to hardware, one at a time is too slow */
1476 if (cleaned_count >= IXGBE_RX_BUFFER_WRITE) {
1477 ixgbe_alloc_rx_buffers(rx_ring, cleaned_count);
1478 cleaned_count = 0;
1479 }
1480
1481 /* use prefetched values */
1482 rx_desc = next_rxd;
1483 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
1484 }
1485
1486 rx_ring->next_to_clean = i;
1487 cleaned_count = ixgbe_desc_unused(rx_ring);
1488
1489 if (cleaned_count)
1490 ixgbe_alloc_rx_buffers(rx_ring, cleaned_count);
1491
1492#ifdef IXGBE_FCOE
1493 /* include DDPed FCoE data */
1494 if (ddp_bytes > 0) {
1495 unsigned int mss;
1496
1497 mss = rx_ring->netdev->mtu - sizeof(struct fcoe_hdr) -
1498 sizeof(struct fc_frame_header) -
1499 sizeof(struct fcoe_crc_eof);
1500 if (mss > 512)
1501 mss &= ~511;
1502 total_rx_bytes += ddp_bytes;
1503 total_rx_packets += DIV_ROUND_UP(ddp_bytes, mss);
1504 }
1505#endif /* IXGBE_FCOE */
1506
1507 u64_stats_update_begin(&rx_ring->syncp);
1508 rx_ring->stats.packets += total_rx_packets;
1509 rx_ring->stats.bytes += total_rx_bytes;
1510 u64_stats_update_end(&rx_ring->syncp);
1511 q_vector->rx.total_packets += total_rx_packets;
1512 q_vector->rx.total_bytes += total_rx_bytes;
1513}
1514
1515static int ixgbe_clean_rxonly(struct napi_struct *, int);
1516/**
1517 * ixgbe_configure_msix - Configure MSI-X hardware
1518 * @adapter: board private structure
1519 *
1520 * ixgbe_configure_msix sets up the hardware to properly generate MSI-X
1521 * interrupts.
1522 **/
1523static void ixgbe_configure_msix(struct ixgbe_adapter *adapter)
1524{
1525 struct ixgbe_q_vector *q_vector;
1526 int i, q_vectors, v_idx, r_idx;
1527 u32 mask;
1528
1529 q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
1530
1531 /*
1532 * Populate the IVAR table and set the ITR values to the
1533 * corresponding register.
1534 */
1535 for (v_idx = 0; v_idx < q_vectors; v_idx++) {
1536 q_vector = adapter->q_vector[v_idx];
1537 /* XXX for_each_set_bit(...) */
1538 r_idx = find_first_bit(q_vector->rx.idx,
1539 adapter->num_rx_queues);
1540
1541 for (i = 0; i < q_vector->rx.count; i++) {
1542 u8 reg_idx = adapter->rx_ring[r_idx]->reg_idx;
1543 ixgbe_set_ivar(adapter, 0, reg_idx, v_idx);
1544 r_idx = find_next_bit(q_vector->rx.idx,
1545 adapter->num_rx_queues,
1546 r_idx + 1);
1547 }
1548 r_idx = find_first_bit(q_vector->tx.idx,
1549 adapter->num_tx_queues);
1550
1551 for (i = 0; i < q_vector->tx.count; i++) {
1552 u8 reg_idx = adapter->tx_ring[r_idx]->reg_idx;
1553 ixgbe_set_ivar(adapter, 1, reg_idx, v_idx);
1554 r_idx = find_next_bit(q_vector->tx.idx,
1555 adapter->num_tx_queues,
1556 r_idx + 1);
1557 }
1558
1559 if (q_vector->tx.count && !q_vector->rx.count)
1560 /* tx only */
1561 q_vector->eitr = adapter->tx_eitr_param;
1562 else if (q_vector->rx.count)
1563 /* rx or mixed */
1564 q_vector->eitr = adapter->rx_eitr_param;
1565
1566 ixgbe_write_eitr(q_vector);
1567 /* If ATR is enabled, set interrupt affinity */
1568 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
1569 /*
1570 * Allocate the affinity_hint cpumask, assign the mask
1571 * for this vector, and set our affinity_hint for
1572 * this irq.
1573 */
1574 if (!alloc_cpumask_var(&q_vector->affinity_mask,
1575 GFP_KERNEL))
1576 return;
1577 cpumask_set_cpu(v_idx, q_vector->affinity_mask);
1578 irq_set_affinity_hint(adapter->msix_entries[v_idx].vector,
1579 q_vector->affinity_mask);
1580 }
1581 }
1582
1583 switch (adapter->hw.mac.type) {
1584 case ixgbe_mac_82598EB:
1585 ixgbe_set_ivar(adapter, -1, IXGBE_IVAR_OTHER_CAUSES_INDEX,
1586 v_idx);
1587 break;
1588 case ixgbe_mac_82599EB:
1589 case ixgbe_mac_X540:
1590 ixgbe_set_ivar(adapter, -1, 1, v_idx);
1591 break;
1592
1593 default:
1594 break;
1595 }
1596 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITR(v_idx), 1950);
1597
1598 /* set up to autoclear timer, and the vectors */
1599 mask = IXGBE_EIMS_ENABLE_MASK;
1600 if (adapter->num_vfs)
1601 mask &= ~(IXGBE_EIMS_OTHER |
1602 IXGBE_EIMS_MAILBOX |
1603 IXGBE_EIMS_LSC);
1604 else
1605 mask &= ~(IXGBE_EIMS_OTHER | IXGBE_EIMS_LSC);
1606 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIAC, mask);
1607}
1608
1609enum latency_range {
1610 lowest_latency = 0,
1611 low_latency = 1,
1612 bulk_latency = 2,
1613 latency_invalid = 255
1614};
1615
1616/**
1617 * ixgbe_update_itr - update the dynamic ITR value based on statistics
1618 * @q_vector: structure containing interrupt and ring information
1619 * @ring_container: structure containing ring performance data
1620 *
1621 * Stores a new ITR value based on packets and byte
1622 * counts during the last interrupt. The advantage of per interrupt
1623 * computation is faster updates and more accurate ITR for the current
1624 * traffic pattern. Constants in this function were computed
1625 * based on theoretical maximum wire speed and thresholds were set based
1626 * on testing data as well as attempting to minimize response time
1627 * while increasing bulk throughput.
1628 * this functionality is controlled by the InterruptThrottleRate module
1629 * parameter (see ixgbe_param.c)
1630 **/
1631static void ixgbe_update_itr(struct ixgbe_q_vector *q_vector,
1632 struct ixgbe_ring_container *ring_container)
1633{
1634 u64 bytes_perint;
1635 struct ixgbe_adapter *adapter = q_vector->adapter;
1636 int bytes = ring_container->total_bytes;
1637 int packets = ring_container->total_packets;
1638 u32 timepassed_us;
1639 u8 itr_setting = ring_container->itr;
1640
1641 if (packets == 0)
1642 return;
1643
1644 /* simple throttlerate management
1645 * 0-20MB/s lowest (100000 ints/s)
1646 * 20-100MB/s low (20000 ints/s)
1647 * 100-1249MB/s bulk (8000 ints/s)
1648 */
1649 /* what was last interrupt timeslice? */
1650 timepassed_us = 1000000/q_vector->eitr;
1651 bytes_perint = bytes / timepassed_us; /* bytes/usec */
1652
1653 switch (itr_setting) {
1654 case lowest_latency:
1655 if (bytes_perint > adapter->eitr_low)
1656 itr_setting = low_latency;
1657 break;
1658 case low_latency:
1659 if (bytes_perint > adapter->eitr_high)
1660 itr_setting = bulk_latency;
1661 else if (bytes_perint <= adapter->eitr_low)
1662 itr_setting = lowest_latency;
1663 break;
1664 case bulk_latency:
1665 if (bytes_perint <= adapter->eitr_high)
1666 itr_setting = low_latency;
1667 break;
1668 }
1669
1670 /* clear work counters since we have the values we need */
1671 ring_container->total_bytes = 0;
1672 ring_container->total_packets = 0;
1673
1674 /* write updated itr to ring container */
1675 ring_container->itr = itr_setting;
1676}
1677
1678/**
1679 * ixgbe_write_eitr - write EITR register in hardware specific way
1680 * @q_vector: structure containing interrupt and ring information
1681 *
1682 * This function is made to be called by ethtool and by the driver
1683 * when it needs to update EITR registers at runtime. Hardware
1684 * specific quirks/differences are taken care of here.
1685 */
1686void ixgbe_write_eitr(struct ixgbe_q_vector *q_vector)
1687{
1688 struct ixgbe_adapter *adapter = q_vector->adapter;
1689 struct ixgbe_hw *hw = &adapter->hw;
1690 int v_idx = q_vector->v_idx;
1691 u32 itr_reg = EITR_INTS_PER_SEC_TO_REG(q_vector->eitr);
1692
1693 switch (adapter->hw.mac.type) {
1694 case ixgbe_mac_82598EB:
1695 /* must write high and low 16 bits to reset counter */
1696 itr_reg |= (itr_reg << 16);
1697 break;
1698 case ixgbe_mac_82599EB:
1699 case ixgbe_mac_X540:
1700 /*
1701 * 82599 and X540 can support a value of zero, so allow it for
1702 * max interrupt rate, but there is an errata where it can
1703 * not be zero with RSC
1704 */
1705 if (itr_reg == 8 &&
1706 !(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED))
1707 itr_reg = 0;
1708
1709 /*
1710 * set the WDIS bit to not clear the timer bits and cause an
1711 * immediate assertion of the interrupt
1712 */
1713 itr_reg |= IXGBE_EITR_CNT_WDIS;
1714 break;
1715 default:
1716 break;
1717 }
1718 IXGBE_WRITE_REG(hw, IXGBE_EITR(v_idx), itr_reg);
1719}
1720
1721static void ixgbe_set_itr(struct ixgbe_q_vector *q_vector)
1722{
1723 u32 new_itr = q_vector->eitr;
1724 u8 current_itr;
1725
1726 ixgbe_update_itr(q_vector, &q_vector->tx);
1727 ixgbe_update_itr(q_vector, &q_vector->rx);
1728
1729 current_itr = max(q_vector->rx.itr, q_vector->tx.itr);
1730
1731 switch (current_itr) {
1732 /* counts and packets in update_itr are dependent on these numbers */
1733 case lowest_latency:
1734 new_itr = 100000;
1735 break;
1736 case low_latency:
1737 new_itr = 20000; /* aka hwitr = ~200 */
1738 break;
1739 case bulk_latency:
1740 new_itr = 8000;
1741 break;
1742 default:
1743 break;
1744 }
1745
1746 if (new_itr != q_vector->eitr) {
1747 /* do an exponential smoothing */
1748 new_itr = ((q_vector->eitr * 9) + new_itr)/10;
1749
1750 /* save the algorithm value here */
1751 q_vector->eitr = new_itr;
1752
1753 ixgbe_write_eitr(q_vector);
1754 }
1755}
1756
1757/**
1758 * ixgbe_check_overtemp_subtask - check for over tempurature
1759 * @adapter: pointer to adapter
1760 **/
1761static void ixgbe_check_overtemp_subtask(struct ixgbe_adapter *adapter)
1762{
1763 struct ixgbe_hw *hw = &adapter->hw;
1764 u32 eicr = adapter->interrupt_event;
1765
1766 if (test_bit(__IXGBE_DOWN, &adapter->state))
1767 return;
1768
1769 if (!(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) &&
1770 !(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_EVENT))
1771 return;
1772
1773 adapter->flags2 &= ~IXGBE_FLAG2_TEMP_SENSOR_EVENT;
1774
1775 switch (hw->device_id) {
1776 case IXGBE_DEV_ID_82599_T3_LOM:
1777 /*
1778 * Since the warning interrupt is for both ports
1779 * we don't have to check if:
1780 * - This interrupt wasn't for our port.
1781 * - We may have missed the interrupt so always have to
1782 * check if we got a LSC
1783 */
1784 if (!(eicr & IXGBE_EICR_GPI_SDP0) &&
1785 !(eicr & IXGBE_EICR_LSC))
1786 return;
1787
1788 if (!(eicr & IXGBE_EICR_LSC) && hw->mac.ops.check_link) {
1789 u32 autoneg;
1790 bool link_up = false;
1791
1792 hw->mac.ops.check_link(hw, &autoneg, &link_up, false);
1793
1794 if (link_up)
1795 return;
1796 }
1797
1798 /* Check if this is not due to overtemp */
1799 if (hw->phy.ops.check_overtemp(hw) != IXGBE_ERR_OVERTEMP)
1800 return;
1801
1802 break;
1803 default:
1804 if (!(eicr & IXGBE_EICR_GPI_SDP0))
1805 return;
1806 break;
1807 }
1808 e_crit(drv,
1809 "Network adapter has been stopped because it has over heated. "
1810 "Restart the computer. If the problem persists, "
1811 "power off the system and replace the adapter\n");
1812
1813 adapter->interrupt_event = 0;
1814}
1815
1816static void ixgbe_check_fan_failure(struct ixgbe_adapter *adapter, u32 eicr)
1817{
1818 struct ixgbe_hw *hw = &adapter->hw;
1819
1820 if ((adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) &&
1821 (eicr & IXGBE_EICR_GPI_SDP1)) {
1822 e_crit(probe, "Fan has stopped, replace the adapter\n");
1823 /* write to clear the interrupt */
1824 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1);
1825 }
1826}
1827
1828static void ixgbe_check_sfp_event(struct ixgbe_adapter *adapter, u32 eicr)
1829{
1830 struct ixgbe_hw *hw = &adapter->hw;
1831
1832 if (eicr & IXGBE_EICR_GPI_SDP2) {
1833 /* Clear the interrupt */
1834 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP2);
1835 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
1836 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
1837 ixgbe_service_event_schedule(adapter);
1838 }
1839 }
1840
1841 if (eicr & IXGBE_EICR_GPI_SDP1) {
1842 /* Clear the interrupt */
1843 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1);
1844 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
1845 adapter->flags |= IXGBE_FLAG_NEED_LINK_CONFIG;
1846 ixgbe_service_event_schedule(adapter);
1847 }
1848 }
1849}
1850
1851static void ixgbe_check_lsc(struct ixgbe_adapter *adapter)
1852{
1853 struct ixgbe_hw *hw = &adapter->hw;
1854
1855 adapter->lsc_int++;
1856 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
1857 adapter->link_check_timeout = jiffies;
1858 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
1859 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_LSC);
1860 IXGBE_WRITE_FLUSH(hw);
1861 ixgbe_service_event_schedule(adapter);
1862 }
1863}
1864
1865static irqreturn_t ixgbe_msix_lsc(int irq, void *data)
1866{
1867 struct ixgbe_adapter *adapter = data;
1868 struct ixgbe_hw *hw = &adapter->hw;
1869 u32 eicr;
1870
1871 /*
1872 * Workaround for Silicon errata. Use clear-by-write instead
1873 * of clear-by-read. Reading with EICS will return the
1874 * interrupt causes without clearing, which later be done
1875 * with the write to EICR.
1876 */
1877 eicr = IXGBE_READ_REG(hw, IXGBE_EICS);
1878 IXGBE_WRITE_REG(hw, IXGBE_EICR, eicr);
1879
1880 if (eicr & IXGBE_EICR_LSC)
1881 ixgbe_check_lsc(adapter);
1882
1883 if (eicr & IXGBE_EICR_MAILBOX)
1884 ixgbe_msg_task(adapter);
1885
1886 switch (hw->mac.type) {
1887 case ixgbe_mac_82599EB:
1888 case ixgbe_mac_X540:
1889 /* Handle Flow Director Full threshold interrupt */
1890 if (eicr & IXGBE_EICR_FLOW_DIR) {
1891 int reinit_count = 0;
1892 int i;
1893 for (i = 0; i < adapter->num_tx_queues; i++) {
1894 struct ixgbe_ring *ring = adapter->tx_ring[i];
1895 if (test_and_clear_bit(__IXGBE_TX_FDIR_INIT_DONE,
1896 &ring->state))
1897 reinit_count++;
1898 }
1899 if (reinit_count) {
1900 /* no more flow director interrupts until after init */
1901 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_FLOW_DIR);
1902 eicr &= ~IXGBE_EICR_FLOW_DIR;
1903 adapter->flags2 |= IXGBE_FLAG2_FDIR_REQUIRES_REINIT;
1904 ixgbe_service_event_schedule(adapter);
1905 }
1906 }
1907 ixgbe_check_sfp_event(adapter, eicr);
1908 if ((adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) &&
1909 ((eicr & IXGBE_EICR_GPI_SDP0) || (eicr & IXGBE_EICR_LSC))) {
1910 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
1911 adapter->interrupt_event = eicr;
1912 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_EVENT;
1913 ixgbe_service_event_schedule(adapter);
1914 }
1915 }
1916 break;
1917 default:
1918 break;
1919 }
1920
1921 ixgbe_check_fan_failure(adapter, eicr);
1922
1923 /* re-enable the original interrupt state, no lsc, no queues */
1924 if (!test_bit(__IXGBE_DOWN, &adapter->state))
1925 IXGBE_WRITE_REG(hw, IXGBE_EIMS, eicr &
1926 ~(IXGBE_EIMS_LSC | IXGBE_EIMS_RTX_QUEUE));
1927
1928 return IRQ_HANDLED;
1929}
1930
1931static inline void ixgbe_irq_enable_queues(struct ixgbe_adapter *adapter,
1932 u64 qmask)
1933{
1934 u32 mask;
1935 struct ixgbe_hw *hw = &adapter->hw;
1936
1937 switch (hw->mac.type) {
1938 case ixgbe_mac_82598EB:
1939 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
1940 IXGBE_WRITE_REG(hw, IXGBE_EIMS, mask);
1941 break;
1942 case ixgbe_mac_82599EB:
1943 case ixgbe_mac_X540:
1944 mask = (qmask & 0xFFFFFFFF);
1945 if (mask)
1946 IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(0), mask);
1947 mask = (qmask >> 32);
1948 if (mask)
1949 IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(1), mask);
1950 break;
1951 default:
1952 break;
1953 }
1954 /* skip the flush */
1955}
1956
1957static inline void ixgbe_irq_disable_queues(struct ixgbe_adapter *adapter,
1958 u64 qmask)
1959{
1960 u32 mask;
1961 struct ixgbe_hw *hw = &adapter->hw;
1962
1963 switch (hw->mac.type) {
1964 case ixgbe_mac_82598EB:
1965 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
1966 IXGBE_WRITE_REG(hw, IXGBE_EIMC, mask);
1967 break;
1968 case ixgbe_mac_82599EB:
1969 case ixgbe_mac_X540:
1970 mask = (qmask & 0xFFFFFFFF);
1971 if (mask)
1972 IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(0), mask);
1973 mask = (qmask >> 32);
1974 if (mask)
1975 IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(1), mask);
1976 break;
1977 default:
1978 break;
1979 }
1980 /* skip the flush */
1981}
1982
1983static irqreturn_t ixgbe_msix_clean_tx(int irq, void *data)
1984{
1985 struct ixgbe_q_vector *q_vector = data;
1986 struct ixgbe_adapter *adapter = q_vector->adapter;
1987 struct ixgbe_ring *tx_ring;
1988 int i, r_idx;
1989
1990 if (!q_vector->tx.count)
1991 return IRQ_HANDLED;
1992
1993 r_idx = find_first_bit(q_vector->tx.idx, adapter->num_tx_queues);
1994 for (i = 0; i < q_vector->tx.count; i++) {
1995 tx_ring = adapter->tx_ring[r_idx];
1996 r_idx = find_next_bit(q_vector->tx.idx, adapter->num_tx_queues,
1997 r_idx + 1);
1998 }
1999
2000 /* EIAM disabled interrupts (on this vector) for us */
2001 napi_schedule(&q_vector->napi);
2002
2003 return IRQ_HANDLED;
2004}
2005
2006/**
2007 * ixgbe_msix_clean_rx - single unshared vector rx clean (all queues)
2008 * @irq: unused
2009 * @data: pointer to our q_vector struct for this interrupt vector
2010 **/
2011static irqreturn_t ixgbe_msix_clean_rx(int irq, void *data)
2012{
2013 struct ixgbe_q_vector *q_vector = data;
2014 struct ixgbe_adapter *adapter = q_vector->adapter;
2015 struct ixgbe_ring *rx_ring;
2016 int r_idx;
2017 int i;
2018
2019#ifdef CONFIG_IXGBE_DCA
2020 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
2021 ixgbe_update_dca(q_vector);
2022#endif
2023
2024 r_idx = find_first_bit(q_vector->rx.idx, adapter->num_rx_queues);
2025 for (i = 0; i < q_vector->rx.count; i++) {
2026 rx_ring = adapter->rx_ring[r_idx];
2027 r_idx = find_next_bit(q_vector->rx.idx, adapter->num_rx_queues,
2028 r_idx + 1);
2029 }
2030
2031 if (!q_vector->rx.count)
2032 return IRQ_HANDLED;
2033
2034 /* EIAM disabled interrupts (on this vector) for us */
2035 napi_schedule(&q_vector->napi);
2036
2037 return IRQ_HANDLED;
2038}
2039
2040static irqreturn_t ixgbe_msix_clean_many(int irq, void *data)
2041{
2042 struct ixgbe_q_vector *q_vector = data;
2043 struct ixgbe_adapter *adapter = q_vector->adapter;
2044 struct ixgbe_ring *ring;
2045 int r_idx;
2046 int i;
2047
2048 if (!q_vector->tx.count && !q_vector->rx.count)
2049 return IRQ_HANDLED;
2050
2051 r_idx = find_first_bit(q_vector->tx.idx, adapter->num_tx_queues);
2052 for (i = 0; i < q_vector->tx.count; i++) {
2053 ring = adapter->tx_ring[r_idx];
2054 r_idx = find_next_bit(q_vector->tx.idx, adapter->num_tx_queues,
2055 r_idx + 1);
2056 }
2057
2058 r_idx = find_first_bit(q_vector->rx.idx, adapter->num_rx_queues);
2059 for (i = 0; i < q_vector->rx.count; i++) {
2060 ring = adapter->rx_ring[r_idx];
2061 r_idx = find_next_bit(q_vector->rx.idx, adapter->num_rx_queues,
2062 r_idx + 1);
2063 }
2064
2065 /* EIAM disabled interrupts (on this vector) for us */
2066 napi_schedule(&q_vector->napi);
2067
2068 return IRQ_HANDLED;
2069}
2070
2071/**
2072 * ixgbe_clean_rxonly - msix (aka one shot) rx clean routine
2073 * @napi: napi struct with our devices info in it
2074 * @budget: amount of work driver is allowed to do this pass, in packets
2075 *
2076 * This function is optimized for cleaning one queue only on a single
2077 * q_vector!!!
2078 **/
2079static int ixgbe_clean_rxonly(struct napi_struct *napi, int budget)
2080{
2081 struct ixgbe_q_vector *q_vector =
2082 container_of(napi, struct ixgbe_q_vector, napi);
2083 struct ixgbe_adapter *adapter = q_vector->adapter;
2084 struct ixgbe_ring *rx_ring = NULL;
2085 int work_done = 0;
2086 long r_idx;
2087
2088#ifdef CONFIG_IXGBE_DCA
2089 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
2090 ixgbe_update_dca(q_vector);
2091#endif
2092
2093 r_idx = find_first_bit(q_vector->rx.idx, adapter->num_rx_queues);
2094 rx_ring = adapter->rx_ring[r_idx];
2095
2096 ixgbe_clean_rx_irq(q_vector, rx_ring, &work_done, budget);
2097
2098 /* If all Rx work done, exit the polling mode */
2099 if (work_done < budget) {
2100 napi_complete(napi);
2101 if (adapter->rx_itr_setting & 1)
2102 ixgbe_set_itr(q_vector);
2103 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2104 ixgbe_irq_enable_queues(adapter,
2105 ((u64)1 << q_vector->v_idx));
2106 }
2107
2108 return work_done;
2109}
2110
2111/**
2112 * ixgbe_clean_rxtx_many - msix (aka one shot) rx clean routine
2113 * @napi: napi struct with our devices info in it
2114 * @budget: amount of work driver is allowed to do this pass, in packets
2115 *
2116 * This function will clean more than one rx queue associated with a
2117 * q_vector.
2118 **/
2119static int ixgbe_clean_rxtx_many(struct napi_struct *napi, int budget)
2120{
2121 struct ixgbe_q_vector *q_vector =
2122 container_of(napi, struct ixgbe_q_vector, napi);
2123 struct ixgbe_adapter *adapter = q_vector->adapter;
2124 struct ixgbe_ring *ring = NULL;
2125 int work_done = 0, i;
2126 long r_idx;
2127 bool tx_clean_complete = true;
2128
2129#ifdef CONFIG_IXGBE_DCA
2130 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
2131 ixgbe_update_dca(q_vector);
2132#endif
2133
2134 r_idx = find_first_bit(q_vector->tx.idx, adapter->num_tx_queues);
2135 for (i = 0; i < q_vector->tx.count; i++) {
2136 ring = adapter->tx_ring[r_idx];
2137 tx_clean_complete &= ixgbe_clean_tx_irq(q_vector, ring);
2138 r_idx = find_next_bit(q_vector->tx.idx, adapter->num_tx_queues,
2139 r_idx + 1);
2140 }
2141
2142 /* attempt to distribute budget to each queue fairly, but don't allow
2143 * the budget to go below 1 because we'll exit polling */
2144 budget /= (q_vector->rx.count ?: 1);
2145 budget = max(budget, 1);
2146 r_idx = find_first_bit(q_vector->rx.idx, adapter->num_rx_queues);
2147 for (i = 0; i < q_vector->rx.count; i++) {
2148 ring = adapter->rx_ring[r_idx];
2149 ixgbe_clean_rx_irq(q_vector, ring, &work_done, budget);
2150 r_idx = find_next_bit(q_vector->rx.idx, adapter->num_rx_queues,
2151 r_idx + 1);
2152 }
2153
2154 r_idx = find_first_bit(q_vector->rx.idx, adapter->num_rx_queues);
2155 ring = adapter->rx_ring[r_idx];
2156 /* If all Rx work done, exit the polling mode */
2157 if (work_done < budget) {
2158 napi_complete(napi);
2159 if (adapter->rx_itr_setting & 1)
2160 ixgbe_set_itr(q_vector);
2161 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2162 ixgbe_irq_enable_queues(adapter,
2163 ((u64)1 << q_vector->v_idx));
2164 return 0;
2165 }
2166
2167 return work_done;
2168}
2169
2170/**
2171 * ixgbe_clean_txonly - msix (aka one shot) tx clean routine
2172 * @napi: napi struct with our devices info in it
2173 * @budget: amount of work driver is allowed to do this pass, in packets
2174 *
2175 * This function is optimized for cleaning one queue only on a single
2176 * q_vector!!!
2177 **/
2178static int ixgbe_clean_txonly(struct napi_struct *napi, int budget)
2179{
2180 struct ixgbe_q_vector *q_vector =
2181 container_of(napi, struct ixgbe_q_vector, napi);
2182 struct ixgbe_adapter *adapter = q_vector->adapter;
2183 struct ixgbe_ring *tx_ring = NULL;
2184 int work_done = 0;
2185 long r_idx;
2186
2187#ifdef CONFIG_IXGBE_DCA
2188 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
2189 ixgbe_update_dca(q_vector);
2190#endif
2191
2192 r_idx = find_first_bit(q_vector->tx.idx, adapter->num_tx_queues);
2193 tx_ring = adapter->tx_ring[r_idx];
2194
2195 if (!ixgbe_clean_tx_irq(q_vector, tx_ring))
2196 work_done = budget;
2197
2198 /* If all Tx work done, exit the polling mode */
2199 if (work_done < budget) {
2200 napi_complete(napi);
2201 if (adapter->tx_itr_setting & 1)
2202 ixgbe_set_itr(q_vector);
2203 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2204 ixgbe_irq_enable_queues(adapter,
2205 ((u64)1 << q_vector->v_idx));
2206 }
2207
2208 return work_done;
2209}
2210
2211static inline void map_vector_to_rxq(struct ixgbe_adapter *a, int v_idx,
2212 int r_idx)
2213{
2214 struct ixgbe_q_vector *q_vector = a->q_vector[v_idx];
2215 struct ixgbe_ring *rx_ring = a->rx_ring[r_idx];
2216
2217 set_bit(r_idx, q_vector->rx.idx);
2218 q_vector->rx.count++;
2219 rx_ring->q_vector = q_vector;
2220}
2221
2222static inline void map_vector_to_txq(struct ixgbe_adapter *a, int v_idx,
2223 int t_idx)
2224{
2225 struct ixgbe_q_vector *q_vector = a->q_vector[v_idx];
2226 struct ixgbe_ring *tx_ring = a->tx_ring[t_idx];
2227
2228 set_bit(t_idx, q_vector->tx.idx);
2229 q_vector->tx.count++;
2230 tx_ring->q_vector = q_vector;
2231 q_vector->tx.work_limit = a->tx_work_limit;
2232}
2233
2234/**
2235 * ixgbe_map_rings_to_vectors - Maps descriptor rings to vectors
2236 * @adapter: board private structure to initialize
2237 *
2238 * This function maps descriptor rings to the queue-specific vectors
2239 * we were allotted through the MSI-X enabling code. Ideally, we'd have
2240 * one vector per ring/queue, but on a constrained vector budget, we
2241 * group the rings as "efficiently" as possible. You would add new
2242 * mapping configurations in here.
2243 **/
2244static int ixgbe_map_rings_to_vectors(struct ixgbe_adapter *adapter)
2245{
2246 int q_vectors;
2247 int v_start = 0;
2248 int rxr_idx = 0, txr_idx = 0;
2249 int rxr_remaining = adapter->num_rx_queues;
2250 int txr_remaining = adapter->num_tx_queues;
2251 int i, j;
2252 int rqpv, tqpv;
2253 int err = 0;
2254
2255 /* No mapping required if MSI-X is disabled. */
2256 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
2257 goto out;
2258
2259 q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
2260
2261 /*
2262 * The ideal configuration...
2263 * We have enough vectors to map one per queue.
2264 */
2265 if (q_vectors == adapter->num_rx_queues + adapter->num_tx_queues) {
2266 for (; rxr_idx < rxr_remaining; v_start++, rxr_idx++)
2267 map_vector_to_rxq(adapter, v_start, rxr_idx);
2268
2269 for (; txr_idx < txr_remaining; v_start++, txr_idx++)
2270 map_vector_to_txq(adapter, v_start, txr_idx);
2271
2272 goto out;
2273 }
2274
2275 /*
2276 * If we don't have enough vectors for a 1-to-1
2277 * mapping, we'll have to group them so there are
2278 * multiple queues per vector.
2279 */
2280 /* Re-adjusting *qpv takes care of the remainder. */
2281 for (i = v_start; i < q_vectors; i++) {
2282 rqpv = DIV_ROUND_UP(rxr_remaining, q_vectors - i);
2283 for (j = 0; j < rqpv; j++) {
2284 map_vector_to_rxq(adapter, i, rxr_idx);
2285 rxr_idx++;
2286 rxr_remaining--;
2287 }
2288 tqpv = DIV_ROUND_UP(txr_remaining, q_vectors - i);
2289 for (j = 0; j < tqpv; j++) {
2290 map_vector_to_txq(adapter, i, txr_idx);
2291 txr_idx++;
2292 txr_remaining--;
2293 }
2294 }
2295out:
2296 return err;
2297}
2298
2299/**
2300 * ixgbe_request_msix_irqs - Initialize MSI-X interrupts
2301 * @adapter: board private structure
2302 *
2303 * ixgbe_request_msix_irqs allocates MSI-X vectors and requests
2304 * interrupts from the kernel.
2305 **/
2306static int ixgbe_request_msix_irqs(struct ixgbe_adapter *adapter)
2307{
2308 struct net_device *netdev = adapter->netdev;
2309 irqreturn_t (*handler)(int, void *);
2310 int i, vector, q_vectors, err;
2311 int ri = 0, ti = 0;
2312
2313 /* Decrement for Other and TCP Timer vectors */
2314 q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
2315
2316 err = ixgbe_map_rings_to_vectors(adapter);
2317 if (err)
2318 return err;
2319
2320#define SET_HANDLER(_v) (((_v)->rx.count && (_v)->tx.count) \
2321 ? &ixgbe_msix_clean_many : \
2322 (_v)->rx.count ? &ixgbe_msix_clean_rx : \
2323 (_v)->tx.count ? &ixgbe_msix_clean_tx : \
2324 NULL)
2325 for (vector = 0; vector < q_vectors; vector++) {
2326 struct ixgbe_q_vector *q_vector = adapter->q_vector[vector];
2327 handler = SET_HANDLER(q_vector);
2328
2329 if (handler == &ixgbe_msix_clean_rx) {
2330 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
2331 "%s-%s-%d", netdev->name, "rx", ri++);
2332 } else if (handler == &ixgbe_msix_clean_tx) {
2333 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
2334 "%s-%s-%d", netdev->name, "tx", ti++);
2335 } else if (handler == &ixgbe_msix_clean_many) {
2336 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
2337 "%s-%s-%d", netdev->name, "TxRx", ri++);
2338 ti++;
2339 } else {
2340 /* skip this unused q_vector */
2341 continue;
2342 }
2343 err = request_irq(adapter->msix_entries[vector].vector,
2344 handler, 0, q_vector->name,
2345 q_vector);
2346 if (err) {
2347 e_err(probe, "request_irq failed for MSIX interrupt "
2348 "Error: %d\n", err);
2349 goto free_queue_irqs;
2350 }
2351 }
2352
2353 sprintf(adapter->lsc_int_name, "%s:lsc", netdev->name);
2354 err = request_irq(adapter->msix_entries[vector].vector,
2355 ixgbe_msix_lsc, 0, adapter->lsc_int_name, adapter);
2356 if (err) {
2357 e_err(probe, "request_irq for msix_lsc failed: %d\n", err);
2358 goto free_queue_irqs;
2359 }
2360
2361 return 0;
2362
2363free_queue_irqs:
2364 for (i = vector - 1; i >= 0; i--)
2365 free_irq(adapter->msix_entries[--vector].vector,
2366 adapter->q_vector[i]);
2367 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
2368 pci_disable_msix(adapter->pdev);
2369 kfree(adapter->msix_entries);
2370 adapter->msix_entries = NULL;
2371 return err;
2372}
2373
2374/**
2375 * ixgbe_irq_enable - Enable default interrupt generation settings
2376 * @adapter: board private structure
2377 **/
2378static inline void ixgbe_irq_enable(struct ixgbe_adapter *adapter, bool queues,
2379 bool flush)
2380{
2381 u32 mask;
2382
2383 mask = (IXGBE_EIMS_ENABLE_MASK & ~IXGBE_EIMS_RTX_QUEUE);
2384 if (adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE)
2385 mask |= IXGBE_EIMS_GPI_SDP0;
2386 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE)
2387 mask |= IXGBE_EIMS_GPI_SDP1;
2388 switch (adapter->hw.mac.type) {
2389 case ixgbe_mac_82599EB:
2390 case ixgbe_mac_X540:
2391 mask |= IXGBE_EIMS_ECC;
2392 mask |= IXGBE_EIMS_GPI_SDP1;
2393 mask |= IXGBE_EIMS_GPI_SDP2;
2394 if (adapter->num_vfs)
2395 mask |= IXGBE_EIMS_MAILBOX;
2396 break;
2397 default:
2398 break;
2399 }
2400 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE)
2401 mask |= IXGBE_EIMS_FLOW_DIR;
2402
2403 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, mask);
2404 if (queues)
2405 ixgbe_irq_enable_queues(adapter, ~0);
2406 if (flush)
2407 IXGBE_WRITE_FLUSH(&adapter->hw);
2408
2409 if (adapter->num_vfs > 32) {
2410 u32 eitrsel = (1 << (adapter->num_vfs - 32)) - 1;
2411 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, eitrsel);
2412 }
2413}
2414
2415/**
2416 * ixgbe_intr - legacy mode Interrupt Handler
2417 * @irq: interrupt number
2418 * @data: pointer to a network interface device structure
2419 **/
2420static irqreturn_t ixgbe_intr(int irq, void *data)
2421{
2422 struct ixgbe_adapter *adapter = data;
2423 struct ixgbe_hw *hw = &adapter->hw;
2424 struct ixgbe_q_vector *q_vector = adapter->q_vector[0];
2425 u32 eicr;
2426
2427 /*
2428 * Workaround for silicon errata on 82598. Mask the interrupts
2429 * before the read of EICR.
2430 */
2431 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_IRQ_CLEAR_MASK);
2432
2433 /* for NAPI, using EIAM to auto-mask tx/rx interrupt bits on read
2434 * therefore no explict interrupt disable is necessary */
2435 eicr = IXGBE_READ_REG(hw, IXGBE_EICR);
2436 if (!eicr) {
2437 /*
2438 * shared interrupt alert!
2439 * make sure interrupts are enabled because the read will
2440 * have disabled interrupts due to EIAM
2441 * finish the workaround of silicon errata on 82598. Unmask
2442 * the interrupt that we masked before the EICR read.
2443 */
2444 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2445 ixgbe_irq_enable(adapter, true, true);
2446 return IRQ_NONE; /* Not our interrupt */
2447 }
2448
2449 if (eicr & IXGBE_EICR_LSC)
2450 ixgbe_check_lsc(adapter);
2451
2452 switch (hw->mac.type) {
2453 case ixgbe_mac_82599EB:
2454 ixgbe_check_sfp_event(adapter, eicr);
2455 if ((adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) &&
2456 ((eicr & IXGBE_EICR_GPI_SDP0) || (eicr & IXGBE_EICR_LSC))) {
2457 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
2458 adapter->interrupt_event = eicr;
2459 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_EVENT;
2460 ixgbe_service_event_schedule(adapter);
2461 }
2462 }
2463 break;
2464 default:
2465 break;
2466 }
2467
2468 ixgbe_check_fan_failure(adapter, eicr);
2469
2470 if (napi_schedule_prep(&(q_vector->napi))) {
2471 /* would disable interrupts here but EIAM disabled it */
2472 __napi_schedule(&(q_vector->napi));
2473 }
2474
2475 /*
2476 * re-enable link(maybe) and non-queue interrupts, no flush.
2477 * ixgbe_poll will re-enable the queue interrupts
2478 */
2479
2480 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2481 ixgbe_irq_enable(adapter, false, false);
2482
2483 return IRQ_HANDLED;
2484}
2485
2486static inline void ixgbe_reset_q_vectors(struct ixgbe_adapter *adapter)
2487{
2488 int i, q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
2489
2490 for (i = 0; i < q_vectors; i++) {
2491 struct ixgbe_q_vector *q_vector = adapter->q_vector[i];
2492 bitmap_zero(q_vector->rx.idx, MAX_RX_QUEUES);
2493 bitmap_zero(q_vector->tx.idx, MAX_TX_QUEUES);
2494 q_vector->rx.count = 0;
2495 q_vector->tx.count = 0;
2496 }
2497}
2498
2499/**
2500 * ixgbe_request_irq - initialize interrupts
2501 * @adapter: board private structure
2502 *
2503 * Attempts to configure interrupts using the best available
2504 * capabilities of the hardware and kernel.
2505 **/
2506static int ixgbe_request_irq(struct ixgbe_adapter *adapter)
2507{
2508 struct net_device *netdev = adapter->netdev;
2509 int err;
2510
2511 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
2512 err = ixgbe_request_msix_irqs(adapter);
2513 } else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED) {
2514 err = request_irq(adapter->pdev->irq, ixgbe_intr, 0,
2515 netdev->name, adapter);
2516 } else {
2517 err = request_irq(adapter->pdev->irq, ixgbe_intr, IRQF_SHARED,
2518 netdev->name, adapter);
2519 }
2520
2521 if (err)
2522 e_err(probe, "request_irq failed, Error %d\n", err);
2523
2524 return err;
2525}
2526
2527static void ixgbe_free_irq(struct ixgbe_adapter *adapter)
2528{
2529 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
2530 int i, q_vectors;
2531
2532 q_vectors = adapter->num_msix_vectors;
2533
2534 i = q_vectors - 1;
2535 free_irq(adapter->msix_entries[i].vector, adapter);
2536
2537 i--;
2538 for (; i >= 0; i--) {
2539 /* free only the irqs that were actually requested */
2540 if (!adapter->q_vector[i]->rx.count &&
2541 !adapter->q_vector[i]->tx.count)
2542 continue;
2543
2544 free_irq(adapter->msix_entries[i].vector,
2545 adapter->q_vector[i]);
2546 }
2547
2548 ixgbe_reset_q_vectors(adapter);
2549 } else {
2550 free_irq(adapter->pdev->irq, adapter);
2551 }
2552}
2553
2554/**
2555 * ixgbe_irq_disable - Mask off interrupt generation on the NIC
2556 * @adapter: board private structure
2557 **/
2558static inline void ixgbe_irq_disable(struct ixgbe_adapter *adapter)
2559{
2560 switch (adapter->hw.mac.type) {
2561 case ixgbe_mac_82598EB:
2562 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, ~0);
2563 break;
2564 case ixgbe_mac_82599EB:
2565 case ixgbe_mac_X540:
2566 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, 0xFFFF0000);
2567 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(0), ~0);
2568 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(1), ~0);
2569 if (adapter->num_vfs > 32)
2570 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, 0);
2571 break;
2572 default:
2573 break;
2574 }
2575 IXGBE_WRITE_FLUSH(&adapter->hw);
2576 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
2577 int i;
2578 for (i = 0; i < adapter->num_msix_vectors; i++)
2579 synchronize_irq(adapter->msix_entries[i].vector);
2580 } else {
2581 synchronize_irq(adapter->pdev->irq);
2582 }
2583}
2584
2585/**
2586 * ixgbe_configure_msi_and_legacy - Initialize PIN (INTA...) and MSI interrupts
2587 *
2588 **/
2589static void ixgbe_configure_msi_and_legacy(struct ixgbe_adapter *adapter)
2590{
2591 struct ixgbe_hw *hw = &adapter->hw;
2592
2593 IXGBE_WRITE_REG(hw, IXGBE_EITR(0),
2594 EITR_INTS_PER_SEC_TO_REG(adapter->rx_eitr_param));
2595
2596 ixgbe_set_ivar(adapter, 0, 0, 0);
2597 ixgbe_set_ivar(adapter, 1, 0, 0);
2598
2599 map_vector_to_rxq(adapter, 0, 0);
2600 map_vector_to_txq(adapter, 0, 0);
2601
2602 e_info(hw, "Legacy interrupt IVAR setup done\n");
2603}
2604
2605/**
2606 * ixgbe_configure_tx_ring - Configure 8259x Tx ring after Reset
2607 * @adapter: board private structure
2608 * @ring: structure containing ring specific data
2609 *
2610 * Configure the Tx descriptor ring after a reset.
2611 **/
2612void ixgbe_configure_tx_ring(struct ixgbe_adapter *adapter,
2613 struct ixgbe_ring *ring)
2614{
2615 struct ixgbe_hw *hw = &adapter->hw;
2616 u64 tdba = ring->dma;
2617 int wait_loop = 10;
2618 u32 txdctl;
2619 u8 reg_idx = ring->reg_idx;
2620
2621 /* disable queue to avoid issues while updating state */
2622 txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(reg_idx));
2623 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx),
2624 txdctl & ~IXGBE_TXDCTL_ENABLE);
2625 IXGBE_WRITE_FLUSH(hw);
2626
2627 IXGBE_WRITE_REG(hw, IXGBE_TDBAL(reg_idx),
2628 (tdba & DMA_BIT_MASK(32)));
2629 IXGBE_WRITE_REG(hw, IXGBE_TDBAH(reg_idx), (tdba >> 32));
2630 IXGBE_WRITE_REG(hw, IXGBE_TDLEN(reg_idx),
2631 ring->count * sizeof(union ixgbe_adv_tx_desc));
2632 IXGBE_WRITE_REG(hw, IXGBE_TDH(reg_idx), 0);
2633 IXGBE_WRITE_REG(hw, IXGBE_TDT(reg_idx), 0);
2634 ring->tail = hw->hw_addr + IXGBE_TDT(reg_idx);
2635
2636 /* configure fetching thresholds */
2637 if (adapter->rx_itr_setting == 0) {
2638 /* cannot set wthresh when itr==0 */
2639 txdctl &= ~0x007F0000;
2640 } else {
2641 /* enable WTHRESH=8 descriptors, to encourage burst writeback */
2642 txdctl |= (8 << 16);
2643 }
2644 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
2645 /* PThresh workaround for Tx hang with DFP enabled. */
2646 txdctl |= 32;
2647 }
2648
2649 /* reinitialize flowdirector state */
2650 if ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) &&
2651 adapter->atr_sample_rate) {
2652 ring->atr_sample_rate = adapter->atr_sample_rate;
2653 ring->atr_count = 0;
2654 set_bit(__IXGBE_TX_FDIR_INIT_DONE, &ring->state);
2655 } else {
2656 ring->atr_sample_rate = 0;
2657 }
2658
2659 clear_bit(__IXGBE_HANG_CHECK_ARMED, &ring->state);
2660
2661 /* enable queue */
2662 txdctl |= IXGBE_TXDCTL_ENABLE;
2663 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), txdctl);
2664
2665 /* TXDCTL.EN will return 0 on 82598 if link is down, so skip it */
2666 if (hw->mac.type == ixgbe_mac_82598EB &&
2667 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
2668 return;
2669
2670 /* poll to verify queue is enabled */
2671 do {
2672 usleep_range(1000, 2000);
2673 txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(reg_idx));
2674 } while (--wait_loop && !(txdctl & IXGBE_TXDCTL_ENABLE));
2675 if (!wait_loop)
2676 e_err(drv, "Could not enable Tx Queue %d\n", reg_idx);
2677}
2678
2679static void ixgbe_setup_mtqc(struct ixgbe_adapter *adapter)
2680{
2681 struct ixgbe_hw *hw = &adapter->hw;
2682 u32 rttdcs;
2683 u32 reg;
2684 u8 tcs = netdev_get_num_tc(adapter->netdev);
2685
2686 if (hw->mac.type == ixgbe_mac_82598EB)
2687 return;
2688
2689 /* disable the arbiter while setting MTQC */
2690 rttdcs = IXGBE_READ_REG(hw, IXGBE_RTTDCS);
2691 rttdcs |= IXGBE_RTTDCS_ARBDIS;
2692 IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs);
2693
2694 /* set transmit pool layout */
2695 switch (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
2696 case (IXGBE_FLAG_SRIOV_ENABLED):
2697 IXGBE_WRITE_REG(hw, IXGBE_MTQC,
2698 (IXGBE_MTQC_VT_ENA | IXGBE_MTQC_64VF));
2699 break;
2700 default:
2701 if (!tcs)
2702 reg = IXGBE_MTQC_64Q_1PB;
2703 else if (tcs <= 4)
2704 reg = IXGBE_MTQC_RT_ENA | IXGBE_MTQC_4TC_4TQ;
2705 else
2706 reg = IXGBE_MTQC_RT_ENA | IXGBE_MTQC_8TC_8TQ;
2707
2708 IXGBE_WRITE_REG(hw, IXGBE_MTQC, reg);
2709
2710 /* Enable Security TX Buffer IFG for multiple pb */
2711 if (tcs) {
2712 reg = IXGBE_READ_REG(hw, IXGBE_SECTXMINIFG);
2713 reg |= IXGBE_SECTX_DCB;
2714 IXGBE_WRITE_REG(hw, IXGBE_SECTXMINIFG, reg);
2715 }
2716 break;
2717 }
2718
2719 /* re-enable the arbiter */
2720 rttdcs &= ~IXGBE_RTTDCS_ARBDIS;
2721 IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs);
2722}
2723
2724/**
2725 * ixgbe_configure_tx - Configure 8259x Transmit Unit after Reset
2726 * @adapter: board private structure
2727 *
2728 * Configure the Tx unit of the MAC after a reset.
2729 **/
2730static void ixgbe_configure_tx(struct ixgbe_adapter *adapter)
2731{
2732 struct ixgbe_hw *hw = &adapter->hw;
2733 u32 dmatxctl;
2734 u32 i;
2735
2736 ixgbe_setup_mtqc(adapter);
2737
2738 if (hw->mac.type != ixgbe_mac_82598EB) {
2739 /* DMATXCTL.EN must be before Tx queues are enabled */
2740 dmatxctl = IXGBE_READ_REG(hw, IXGBE_DMATXCTL);
2741 dmatxctl |= IXGBE_DMATXCTL_TE;
2742 IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, dmatxctl);
2743 }
2744
2745 /* Setup the HW Tx Head and Tail descriptor pointers */
2746 for (i = 0; i < adapter->num_tx_queues; i++)
2747 ixgbe_configure_tx_ring(adapter, adapter->tx_ring[i]);
2748}
2749
2750#define IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT 2
2751
2752static void ixgbe_configure_srrctl(struct ixgbe_adapter *adapter,
2753 struct ixgbe_ring *rx_ring)
2754{
2755 u32 srrctl;
2756 u8 reg_idx = rx_ring->reg_idx;
2757
2758 switch (adapter->hw.mac.type) {
2759 case ixgbe_mac_82598EB: {
2760 struct ixgbe_ring_feature *feature = adapter->ring_feature;
2761 const int mask = feature[RING_F_RSS].mask;
2762 reg_idx = reg_idx & mask;
2763 }
2764 break;
2765 case ixgbe_mac_82599EB:
2766 case ixgbe_mac_X540:
2767 default:
2768 break;
2769 }
2770
2771 srrctl = IXGBE_READ_REG(&adapter->hw, IXGBE_SRRCTL(reg_idx));
2772
2773 srrctl &= ~IXGBE_SRRCTL_BSIZEHDR_MASK;
2774 srrctl &= ~IXGBE_SRRCTL_BSIZEPKT_MASK;
2775 if (adapter->num_vfs)
2776 srrctl |= IXGBE_SRRCTL_DROP_EN;
2777
2778 srrctl |= (IXGBE_RX_HDR_SIZE << IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT) &
2779 IXGBE_SRRCTL_BSIZEHDR_MASK;
2780
2781 if (ring_is_ps_enabled(rx_ring)) {
2782#if (PAGE_SIZE / 2) > IXGBE_MAX_RXBUFFER
2783 srrctl |= IXGBE_MAX_RXBUFFER >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
2784#else
2785 srrctl |= (PAGE_SIZE / 2) >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
2786#endif
2787 srrctl |= IXGBE_SRRCTL_DESCTYPE_HDR_SPLIT_ALWAYS;
2788 } else {
2789 srrctl |= ALIGN(rx_ring->rx_buf_len, 1024) >>
2790 IXGBE_SRRCTL_BSIZEPKT_SHIFT;
2791 srrctl |= IXGBE_SRRCTL_DESCTYPE_ADV_ONEBUF;
2792 }
2793
2794 IXGBE_WRITE_REG(&adapter->hw, IXGBE_SRRCTL(reg_idx), srrctl);
2795}
2796
2797static void ixgbe_setup_mrqc(struct ixgbe_adapter *adapter)
2798{
2799 struct ixgbe_hw *hw = &adapter->hw;
2800 static const u32 seed[10] = { 0xE291D73D, 0x1805EC6C, 0x2A94B30D,
2801 0xA54F2BEC, 0xEA49AF7C, 0xE214AD3D, 0xB855AABE,
2802 0x6A3E67EA, 0x14364D17, 0x3BED200D};
2803 u32 mrqc = 0, reta = 0;
2804 u32 rxcsum;
2805 int i, j;
2806 u8 tcs = netdev_get_num_tc(adapter->netdev);
2807 int maxq = adapter->ring_feature[RING_F_RSS].indices;
2808
2809 if (tcs)
2810 maxq = min(maxq, adapter->num_tx_queues / tcs);
2811
2812 /* Fill out hash function seeds */
2813 for (i = 0; i < 10; i++)
2814 IXGBE_WRITE_REG(hw, IXGBE_RSSRK(i), seed[i]);
2815
2816 /* Fill out redirection table */
2817 for (i = 0, j = 0; i < 128; i++, j++) {
2818 if (j == maxq)
2819 j = 0;
2820 /* reta = 4-byte sliding window of
2821 * 0x00..(indices-1)(indices-1)00..etc. */
2822 reta = (reta << 8) | (j * 0x11);
2823 if ((i & 3) == 3)
2824 IXGBE_WRITE_REG(hw, IXGBE_RETA(i >> 2), reta);
2825 }
2826
2827 /* Disable indicating checksum in descriptor, enables RSS hash */
2828 rxcsum = IXGBE_READ_REG(hw, IXGBE_RXCSUM);
2829 rxcsum |= IXGBE_RXCSUM_PCSD;
2830 IXGBE_WRITE_REG(hw, IXGBE_RXCSUM, rxcsum);
2831
2832 if (adapter->hw.mac.type == ixgbe_mac_82598EB &&
2833 (adapter->flags & IXGBE_FLAG_RSS_ENABLED)) {
2834 mrqc = IXGBE_MRQC_RSSEN;
2835 } else {
2836 int mask = adapter->flags & (IXGBE_FLAG_RSS_ENABLED
2837 | IXGBE_FLAG_SRIOV_ENABLED);
2838
2839 switch (mask) {
2840 case (IXGBE_FLAG_RSS_ENABLED):
2841 if (!tcs)
2842 mrqc = IXGBE_MRQC_RSSEN;
2843 else if (tcs <= 4)
2844 mrqc = IXGBE_MRQC_RTRSS4TCEN;
2845 else
2846 mrqc = IXGBE_MRQC_RTRSS8TCEN;
2847 break;
2848 case (IXGBE_FLAG_SRIOV_ENABLED):
2849 mrqc = IXGBE_MRQC_VMDQEN;
2850 break;
2851 default:
2852 break;
2853 }
2854 }
2855
2856 /* Perform hash on these packet types */
2857 mrqc |= IXGBE_MRQC_RSS_FIELD_IPV4
2858 | IXGBE_MRQC_RSS_FIELD_IPV4_TCP
2859 | IXGBE_MRQC_RSS_FIELD_IPV6
2860 | IXGBE_MRQC_RSS_FIELD_IPV6_TCP;
2861
2862 IXGBE_WRITE_REG(hw, IXGBE_MRQC, mrqc);
2863}
2864
2865/**
2866 * ixgbe_configure_rscctl - enable RSC for the indicated ring
2867 * @adapter: address of board private structure
2868 * @index: index of ring to set
2869 **/
2870static void ixgbe_configure_rscctl(struct ixgbe_adapter *adapter,
2871 struct ixgbe_ring *ring)
2872{
2873 struct ixgbe_hw *hw = &adapter->hw;
2874 u32 rscctrl;
2875 int rx_buf_len;
2876 u8 reg_idx = ring->reg_idx;
2877
2878 if (!ring_is_rsc_enabled(ring))
2879 return;
2880
2881 rx_buf_len = ring->rx_buf_len;
2882 rscctrl = IXGBE_READ_REG(hw, IXGBE_RSCCTL(reg_idx));
2883 rscctrl |= IXGBE_RSCCTL_RSCEN;
2884 /*
2885 * we must limit the number of descriptors so that the
2886 * total size of max desc * buf_len is not greater
2887 * than 65535
2888 */
2889 if (ring_is_ps_enabled(ring)) {
2890#if (MAX_SKB_FRAGS > 16)
2891 rscctrl |= IXGBE_RSCCTL_MAXDESC_16;
2892#elif (MAX_SKB_FRAGS > 8)
2893 rscctrl |= IXGBE_RSCCTL_MAXDESC_8;
2894#elif (MAX_SKB_FRAGS > 4)
2895 rscctrl |= IXGBE_RSCCTL_MAXDESC_4;
2896#else
2897 rscctrl |= IXGBE_RSCCTL_MAXDESC_1;
2898#endif
2899 } else {
2900 if (rx_buf_len < IXGBE_RXBUFFER_4096)
2901 rscctrl |= IXGBE_RSCCTL_MAXDESC_16;
2902 else if (rx_buf_len < IXGBE_RXBUFFER_8192)
2903 rscctrl |= IXGBE_RSCCTL_MAXDESC_8;
2904 else
2905 rscctrl |= IXGBE_RSCCTL_MAXDESC_4;
2906 }
2907 IXGBE_WRITE_REG(hw, IXGBE_RSCCTL(reg_idx), rscctrl);
2908}
2909
2910/**
2911 * ixgbe_set_uta - Set unicast filter table address
2912 * @adapter: board private structure
2913 *
2914 * The unicast table address is a register array of 32-bit registers.
2915 * The table is meant to be used in a way similar to how the MTA is used
2916 * however due to certain limitations in the hardware it is necessary to
2917 * set all the hash bits to 1 and use the VMOLR ROPE bit as a promiscuous
2918 * enable bit to allow vlan tag stripping when promiscuous mode is enabled
2919 **/
2920static void ixgbe_set_uta(struct ixgbe_adapter *adapter)
2921{
2922 struct ixgbe_hw *hw = &adapter->hw;
2923 int i;
2924
2925 /* The UTA table only exists on 82599 hardware and newer */
2926 if (hw->mac.type < ixgbe_mac_82599EB)
2927 return;
2928
2929 /* we only need to do this if VMDq is enabled */
2930 if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
2931 return;
2932
2933 for (i = 0; i < 128; i++)
2934 IXGBE_WRITE_REG(hw, IXGBE_UTA(i), ~0);
2935}
2936
2937#define IXGBE_MAX_RX_DESC_POLL 10
2938static void ixgbe_rx_desc_queue_enable(struct ixgbe_adapter *adapter,
2939 struct ixgbe_ring *ring)
2940{
2941 struct ixgbe_hw *hw = &adapter->hw;
2942 int wait_loop = IXGBE_MAX_RX_DESC_POLL;
2943 u32 rxdctl;
2944 u8 reg_idx = ring->reg_idx;
2945
2946 /* RXDCTL.EN will return 0 on 82598 if link is down, so skip it */
2947 if (hw->mac.type == ixgbe_mac_82598EB &&
2948 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
2949 return;
2950
2951 do {
2952 usleep_range(1000, 2000);
2953 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
2954 } while (--wait_loop && !(rxdctl & IXGBE_RXDCTL_ENABLE));
2955
2956 if (!wait_loop) {
2957 e_err(drv, "RXDCTL.ENABLE on Rx queue %d not set within "
2958 "the polling period\n", reg_idx);
2959 }
2960}
2961
2962void ixgbe_disable_rx_queue(struct ixgbe_adapter *adapter,
2963 struct ixgbe_ring *ring)
2964{
2965 struct ixgbe_hw *hw = &adapter->hw;
2966 int wait_loop = IXGBE_MAX_RX_DESC_POLL;
2967 u32 rxdctl;
2968 u8 reg_idx = ring->reg_idx;
2969
2970 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
2971 rxdctl &= ~IXGBE_RXDCTL_ENABLE;
2972
2973 /* write value back with RXDCTL.ENABLE bit cleared */
2974 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl);
2975
2976 if (hw->mac.type == ixgbe_mac_82598EB &&
2977 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
2978 return;
2979
2980 /* the hardware may take up to 100us to really disable the rx queue */
2981 do {
2982 udelay(10);
2983 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
2984 } while (--wait_loop && (rxdctl & IXGBE_RXDCTL_ENABLE));
2985
2986 if (!wait_loop) {
2987 e_err(drv, "RXDCTL.ENABLE on Rx queue %d not cleared within "
2988 "the polling period\n", reg_idx);
2989 }
2990}
2991
2992void ixgbe_configure_rx_ring(struct ixgbe_adapter *adapter,
2993 struct ixgbe_ring *ring)
2994{
2995 struct ixgbe_hw *hw = &adapter->hw;
2996 u64 rdba = ring->dma;
2997 u32 rxdctl;
2998 u8 reg_idx = ring->reg_idx;
2999
3000 /* disable queue to avoid issues while updating state */
3001 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
3002 ixgbe_disable_rx_queue(adapter, ring);
3003
3004 IXGBE_WRITE_REG(hw, IXGBE_RDBAL(reg_idx), (rdba & DMA_BIT_MASK(32)));
3005 IXGBE_WRITE_REG(hw, IXGBE_RDBAH(reg_idx), (rdba >> 32));
3006 IXGBE_WRITE_REG(hw, IXGBE_RDLEN(reg_idx),
3007 ring->count * sizeof(union ixgbe_adv_rx_desc));
3008 IXGBE_WRITE_REG(hw, IXGBE_RDH(reg_idx), 0);
3009 IXGBE_WRITE_REG(hw, IXGBE_RDT(reg_idx), 0);
3010 ring->tail = hw->hw_addr + IXGBE_RDT(reg_idx);
3011
3012 ixgbe_configure_srrctl(adapter, ring);
3013 ixgbe_configure_rscctl(adapter, ring);
3014
3015 /* If operating in IOV mode set RLPML for X540 */
3016 if ((adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) &&
3017 hw->mac.type == ixgbe_mac_X540) {
3018 rxdctl &= ~IXGBE_RXDCTL_RLPMLMASK;
3019 rxdctl |= ((ring->netdev->mtu + ETH_HLEN +
3020 ETH_FCS_LEN + VLAN_HLEN) | IXGBE_RXDCTL_RLPML_EN);
3021 }
3022
3023 if (hw->mac.type == ixgbe_mac_82598EB) {
3024 /*
3025 * enable cache line friendly hardware writes:
3026 * PTHRESH=32 descriptors (half the internal cache),
3027 * this also removes ugly rx_no_buffer_count increment
3028 * HTHRESH=4 descriptors (to minimize latency on fetch)
3029 * WTHRESH=8 burst writeback up to two cache lines
3030 */
3031 rxdctl &= ~0x3FFFFF;
3032 rxdctl |= 0x080420;
3033 }
3034
3035 /* enable receive descriptor ring */
3036 rxdctl |= IXGBE_RXDCTL_ENABLE;
3037 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl);
3038
3039 ixgbe_rx_desc_queue_enable(adapter, ring);
3040 ixgbe_alloc_rx_buffers(ring, ixgbe_desc_unused(ring));
3041}
3042
3043static void ixgbe_setup_psrtype(struct ixgbe_adapter *adapter)
3044{
3045 struct ixgbe_hw *hw = &adapter->hw;
3046 int p;
3047
3048 /* PSRTYPE must be initialized in non 82598 adapters */
3049 u32 psrtype = IXGBE_PSRTYPE_TCPHDR |
3050 IXGBE_PSRTYPE_UDPHDR |
3051 IXGBE_PSRTYPE_IPV4HDR |
3052 IXGBE_PSRTYPE_L2HDR |
3053 IXGBE_PSRTYPE_IPV6HDR;
3054
3055 if (hw->mac.type == ixgbe_mac_82598EB)
3056 return;
3057
3058 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED)
3059 psrtype |= (adapter->num_rx_queues_per_pool << 29);
3060
3061 for (p = 0; p < adapter->num_rx_pools; p++)
3062 IXGBE_WRITE_REG(hw, IXGBE_PSRTYPE(adapter->num_vfs + p),
3063 psrtype);
3064}
3065
3066static void ixgbe_configure_virtualization(struct ixgbe_adapter *adapter)
3067{
3068 struct ixgbe_hw *hw = &adapter->hw;
3069 u32 gcr_ext;
3070 u32 vt_reg_bits;
3071 u32 reg_offset, vf_shift;
3072 u32 vmdctl;
3073
3074 if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
3075 return;
3076
3077 vmdctl = IXGBE_READ_REG(hw, IXGBE_VT_CTL);
3078 vt_reg_bits = IXGBE_VMD_CTL_VMDQ_EN | IXGBE_VT_CTL_REPLEN;
3079 vt_reg_bits |= (adapter->num_vfs << IXGBE_VT_CTL_POOL_SHIFT);
3080 IXGBE_WRITE_REG(hw, IXGBE_VT_CTL, vmdctl | vt_reg_bits);
3081
3082 vf_shift = adapter->num_vfs % 32;
3083 reg_offset = (adapter->num_vfs > 32) ? 1 : 0;
3084
3085 /* Enable only the PF's pool for Tx/Rx */
3086 IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset), (1 << vf_shift));
3087 IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset ^ 1), 0);
3088 IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset), (1 << vf_shift));
3089 IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset ^ 1), 0);
3090 IXGBE_WRITE_REG(hw, IXGBE_PFDTXGSWC, IXGBE_PFDTXGSWC_VT_LBEN);
3091
3092 /* Map PF MAC address in RAR Entry 0 to first pool following VFs */
3093 hw->mac.ops.set_vmdq(hw, 0, adapter->num_vfs);
3094
3095 /*
3096 * Set up VF register offsets for selected VT Mode,
3097 * i.e. 32 or 64 VFs for SR-IOV
3098 */
3099 gcr_ext = IXGBE_READ_REG(hw, IXGBE_GCR_EXT);
3100 gcr_ext |= IXGBE_GCR_EXT_MSIX_EN;
3101 gcr_ext |= IXGBE_GCR_EXT_VT_MODE_64;
3102 IXGBE_WRITE_REG(hw, IXGBE_GCR_EXT, gcr_ext);
3103
3104 /* enable Tx loopback for VF/PF communication */
3105 IXGBE_WRITE_REG(hw, IXGBE_PFDTXGSWC, IXGBE_PFDTXGSWC_VT_LBEN);
3106 /* Enable MAC Anti-Spoofing */
3107 hw->mac.ops.set_mac_anti_spoofing(hw,
3108 (adapter->antispoofing_enabled =
3109 (adapter->num_vfs != 0)),
3110 adapter->num_vfs);
3111}
3112
3113static void ixgbe_set_rx_buffer_len(struct ixgbe_adapter *adapter)
3114{
3115 struct ixgbe_hw *hw = &adapter->hw;
3116 struct net_device *netdev = adapter->netdev;
3117 int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
3118 int rx_buf_len;
3119 struct ixgbe_ring *rx_ring;
3120 int i;
3121 u32 mhadd, hlreg0;
3122
3123 /* Decide whether to use packet split mode or not */
3124 /* On by default */
3125 adapter->flags |= IXGBE_FLAG_RX_PS_ENABLED;
3126
3127 /* Do not use packet split if we're in SR-IOV Mode */
3128 if (adapter->num_vfs)
3129 adapter->flags &= ~IXGBE_FLAG_RX_PS_ENABLED;
3130
3131 /* Disable packet split due to 82599 erratum #45 */
3132 if (hw->mac.type == ixgbe_mac_82599EB)
3133 adapter->flags &= ~IXGBE_FLAG_RX_PS_ENABLED;
3134
3135 /* Set the RX buffer length according to the mode */
3136 if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED) {
3137 rx_buf_len = IXGBE_RX_HDR_SIZE;
3138 } else {
3139 if (!(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) &&
3140 (netdev->mtu <= ETH_DATA_LEN))
3141 rx_buf_len = MAXIMUM_ETHERNET_VLAN_SIZE;
3142 else
3143 rx_buf_len = ALIGN(max_frame + VLAN_HLEN, 1024);
3144 }
3145
3146#ifdef IXGBE_FCOE
3147 /* adjust max frame to be able to do baby jumbo for FCoE */
3148 if ((adapter->flags & IXGBE_FLAG_FCOE_ENABLED) &&
3149 (max_frame < IXGBE_FCOE_JUMBO_FRAME_SIZE))
3150 max_frame = IXGBE_FCOE_JUMBO_FRAME_SIZE;
3151
3152#endif /* IXGBE_FCOE */
3153 mhadd = IXGBE_READ_REG(hw, IXGBE_MHADD);
3154 if (max_frame != (mhadd >> IXGBE_MHADD_MFS_SHIFT)) {
3155 mhadd &= ~IXGBE_MHADD_MFS_MASK;
3156 mhadd |= max_frame << IXGBE_MHADD_MFS_SHIFT;
3157
3158 IXGBE_WRITE_REG(hw, IXGBE_MHADD, mhadd);
3159 }
3160
3161 hlreg0 = IXGBE_READ_REG(hw, IXGBE_HLREG0);
3162 /* set jumbo enable since MHADD.MFS is keeping size locked at max_frame */
3163 hlreg0 |= IXGBE_HLREG0_JUMBOEN;
3164 IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg0);
3165
3166 /*
3167 * Setup the HW Rx Head and Tail Descriptor Pointers and
3168 * the Base and Length of the Rx Descriptor Ring
3169 */
3170 for (i = 0; i < adapter->num_rx_queues; i++) {
3171 rx_ring = adapter->rx_ring[i];
3172 rx_ring->rx_buf_len = rx_buf_len;
3173
3174 if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED)
3175 set_ring_ps_enabled(rx_ring);
3176 else
3177 clear_ring_ps_enabled(rx_ring);
3178
3179 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
3180 set_ring_rsc_enabled(rx_ring);
3181 else
3182 clear_ring_rsc_enabled(rx_ring);
3183
3184#ifdef IXGBE_FCOE
3185 if (netdev->features & NETIF_F_FCOE_MTU) {
3186 struct ixgbe_ring_feature *f;
3187 f = &adapter->ring_feature[RING_F_FCOE];
3188 if ((i >= f->mask) && (i < f->mask + f->indices)) {
3189 clear_ring_ps_enabled(rx_ring);
3190 if (rx_buf_len < IXGBE_FCOE_JUMBO_FRAME_SIZE)
3191 rx_ring->rx_buf_len =
3192 IXGBE_FCOE_JUMBO_FRAME_SIZE;
3193 } else if (!ring_is_rsc_enabled(rx_ring) &&
3194 !ring_is_ps_enabled(rx_ring)) {
3195 rx_ring->rx_buf_len =
3196 IXGBE_FCOE_JUMBO_FRAME_SIZE;
3197 }
3198 }
3199#endif /* IXGBE_FCOE */
3200 }
3201}
3202
3203static void ixgbe_setup_rdrxctl(struct ixgbe_adapter *adapter)
3204{
3205 struct ixgbe_hw *hw = &adapter->hw;
3206 u32 rdrxctl = IXGBE_READ_REG(hw, IXGBE_RDRXCTL);
3207
3208 switch (hw->mac.type) {
3209 case ixgbe_mac_82598EB:
3210 /*
3211 * For VMDq support of different descriptor types or
3212 * buffer sizes through the use of multiple SRRCTL
3213 * registers, RDRXCTL.MVMEN must be set to 1
3214 *
3215 * also, the manual doesn't mention it clearly but DCA hints
3216 * will only use queue 0's tags unless this bit is set. Side
3217 * effects of setting this bit are only that SRRCTL must be
3218 * fully programmed [0..15]
3219 */
3220 rdrxctl |= IXGBE_RDRXCTL_MVMEN;
3221 break;
3222 case ixgbe_mac_82599EB:
3223 case ixgbe_mac_X540:
3224 /* Disable RSC for ACK packets */
3225 IXGBE_WRITE_REG(hw, IXGBE_RSCDBU,
3226 (IXGBE_RSCDBU_RSCACKDIS | IXGBE_READ_REG(hw, IXGBE_RSCDBU)));
3227 rdrxctl &= ~IXGBE_RDRXCTL_RSCFRSTSIZE;
3228 /* hardware requires some bits to be set by default */
3229 rdrxctl |= (IXGBE_RDRXCTL_RSCACKC | IXGBE_RDRXCTL_FCOE_WRFIX);
3230 rdrxctl |= IXGBE_RDRXCTL_CRCSTRIP;
3231 break;
3232 default:
3233 /* We should do nothing since we don't know this hardware */
3234 return;
3235 }
3236
3237 IXGBE_WRITE_REG(hw, IXGBE_RDRXCTL, rdrxctl);
3238}
3239
3240/**
3241 * ixgbe_configure_rx - Configure 8259x Receive Unit after Reset
3242 * @adapter: board private structure
3243 *
3244 * Configure the Rx unit of the MAC after a reset.
3245 **/
3246static void ixgbe_configure_rx(struct ixgbe_adapter *adapter)
3247{
3248 struct ixgbe_hw *hw = &adapter->hw;
3249 int i;
3250 u32 rxctrl;
3251
3252 /* disable receives while setting up the descriptors */
3253 rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
3254 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN);
3255
3256 ixgbe_setup_psrtype(adapter);
3257 ixgbe_setup_rdrxctl(adapter);
3258
3259 /* Program registers for the distribution of queues */
3260 ixgbe_setup_mrqc(adapter);
3261
3262 ixgbe_set_uta(adapter);
3263
3264 /* set_rx_buffer_len must be called before ring initialization */
3265 ixgbe_set_rx_buffer_len(adapter);
3266
3267 /*
3268 * Setup the HW Rx Head and Tail Descriptor Pointers and
3269 * the Base and Length of the Rx Descriptor Ring
3270 */
3271 for (i = 0; i < adapter->num_rx_queues; i++)
3272 ixgbe_configure_rx_ring(adapter, adapter->rx_ring[i]);
3273
3274 /* disable drop enable for 82598 parts */
3275 if (hw->mac.type == ixgbe_mac_82598EB)
3276 rxctrl |= IXGBE_RXCTRL_DMBYPS;
3277
3278 /* enable all receives */
3279 rxctrl |= IXGBE_RXCTRL_RXEN;
3280 hw->mac.ops.enable_rx_dma(hw, rxctrl);
3281}
3282
3283static void ixgbe_vlan_rx_add_vid(struct net_device *netdev, u16 vid)
3284{
3285 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3286 struct ixgbe_hw *hw = &adapter->hw;
3287 int pool_ndx = adapter->num_vfs;
3288
3289 /* add VID to filter table */
3290 hw->mac.ops.set_vfta(&adapter->hw, vid, pool_ndx, true);
3291 set_bit(vid, adapter->active_vlans);
3292}
3293
3294static void ixgbe_vlan_rx_kill_vid(struct net_device *netdev, u16 vid)
3295{
3296 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3297 struct ixgbe_hw *hw = &adapter->hw;
3298 int pool_ndx = adapter->num_vfs;
3299
3300 /* remove VID from filter table */
3301 hw->mac.ops.set_vfta(&adapter->hw, vid, pool_ndx, false);
3302 clear_bit(vid, adapter->active_vlans);
3303}
3304
3305/**
3306 * ixgbe_vlan_filter_disable - helper to disable hw vlan filtering
3307 * @adapter: driver data
3308 */
3309static void ixgbe_vlan_filter_disable(struct ixgbe_adapter *adapter)
3310{
3311 struct ixgbe_hw *hw = &adapter->hw;
3312 u32 vlnctrl;
3313
3314 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3315 vlnctrl &= ~(IXGBE_VLNCTRL_VFE | IXGBE_VLNCTRL_CFIEN);
3316 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3317}
3318
3319/**
3320 * ixgbe_vlan_filter_enable - helper to enable hw vlan filtering
3321 * @adapter: driver data
3322 */
3323static void ixgbe_vlan_filter_enable(struct ixgbe_adapter *adapter)
3324{
3325 struct ixgbe_hw *hw = &adapter->hw;
3326 u32 vlnctrl;
3327
3328 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3329 vlnctrl |= IXGBE_VLNCTRL_VFE;
3330 vlnctrl &= ~IXGBE_VLNCTRL_CFIEN;
3331 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3332}
3333
3334/**
3335 * ixgbe_vlan_strip_disable - helper to disable hw vlan stripping
3336 * @adapter: driver data
3337 */
3338static void ixgbe_vlan_strip_disable(struct ixgbe_adapter *adapter)
3339{
3340 struct ixgbe_hw *hw = &adapter->hw;
3341 u32 vlnctrl;
3342 int i, j;
3343
3344 switch (hw->mac.type) {
3345 case ixgbe_mac_82598EB:
3346 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3347 vlnctrl &= ~IXGBE_VLNCTRL_VME;
3348 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3349 break;
3350 case ixgbe_mac_82599EB:
3351 case ixgbe_mac_X540:
3352 for (i = 0; i < adapter->num_rx_queues; i++) {
3353 j = adapter->rx_ring[i]->reg_idx;
3354 vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
3355 vlnctrl &= ~IXGBE_RXDCTL_VME;
3356 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl);
3357 }
3358 break;
3359 default:
3360 break;
3361 }
3362}
3363
3364/**
3365 * ixgbe_vlan_strip_enable - helper to enable hw vlan stripping
3366 * @adapter: driver data
3367 */
3368static void ixgbe_vlan_strip_enable(struct ixgbe_adapter *adapter)
3369{
3370 struct ixgbe_hw *hw = &adapter->hw;
3371 u32 vlnctrl;
3372 int i, j;
3373
3374 switch (hw->mac.type) {
3375 case ixgbe_mac_82598EB:
3376 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3377 vlnctrl |= IXGBE_VLNCTRL_VME;
3378 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3379 break;
3380 case ixgbe_mac_82599EB:
3381 case ixgbe_mac_X540:
3382 for (i = 0; i < adapter->num_rx_queues; i++) {
3383 j = adapter->rx_ring[i]->reg_idx;
3384 vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
3385 vlnctrl |= IXGBE_RXDCTL_VME;
3386 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl);
3387 }
3388 break;
3389 default:
3390 break;
3391 }
3392}
3393
3394static void ixgbe_restore_vlan(struct ixgbe_adapter *adapter)
3395{
3396 u16 vid;
3397
3398 ixgbe_vlan_rx_add_vid(adapter->netdev, 0);
3399
3400 for_each_set_bit(vid, adapter->active_vlans, VLAN_N_VID)
3401 ixgbe_vlan_rx_add_vid(adapter->netdev, vid);
3402}
3403
3404/**
3405 * ixgbe_write_uc_addr_list - write unicast addresses to RAR table
3406 * @netdev: network interface device structure
3407 *
3408 * Writes unicast address list to the RAR table.
3409 * Returns: -ENOMEM on failure/insufficient address space
3410 * 0 on no addresses written
3411 * X on writing X addresses to the RAR table
3412 **/
3413static int ixgbe_write_uc_addr_list(struct net_device *netdev)
3414{
3415 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3416 struct ixgbe_hw *hw = &adapter->hw;
3417 unsigned int vfn = adapter->num_vfs;
3418 unsigned int rar_entries = IXGBE_MAX_PF_MACVLANS;
3419 int count = 0;
3420
3421 /* return ENOMEM indicating insufficient memory for addresses */
3422 if (netdev_uc_count(netdev) > rar_entries)
3423 return -ENOMEM;
3424
3425 if (!netdev_uc_empty(netdev) && rar_entries) {
3426 struct netdev_hw_addr *ha;
3427 /* return error if we do not support writing to RAR table */
3428 if (!hw->mac.ops.set_rar)
3429 return -ENOMEM;
3430
3431 netdev_for_each_uc_addr(ha, netdev) {
3432 if (!rar_entries)
3433 break;
3434 hw->mac.ops.set_rar(hw, rar_entries--, ha->addr,
3435 vfn, IXGBE_RAH_AV);
3436 count++;
3437 }
3438 }
3439 /* write the addresses in reverse order to avoid write combining */
3440 for (; rar_entries > 0 ; rar_entries--)
3441 hw->mac.ops.clear_rar(hw, rar_entries);
3442
3443 return count;
3444}
3445
3446/**
3447 * ixgbe_set_rx_mode - Unicast, Multicast and Promiscuous mode set
3448 * @netdev: network interface device structure
3449 *
3450 * The set_rx_method entry point is called whenever the unicast/multicast
3451 * address list or the network interface flags are updated. This routine is
3452 * responsible for configuring the hardware for proper unicast, multicast and
3453 * promiscuous mode.
3454 **/
3455void ixgbe_set_rx_mode(struct net_device *netdev)
3456{
3457 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3458 struct ixgbe_hw *hw = &adapter->hw;
3459 u32 fctrl, vmolr = IXGBE_VMOLR_BAM | IXGBE_VMOLR_AUPE;
3460 int count;
3461
3462 /* Check for Promiscuous and All Multicast modes */
3463
3464 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
3465
3466 /* set all bits that we expect to always be set */
3467 fctrl |= IXGBE_FCTRL_BAM;
3468 fctrl |= IXGBE_FCTRL_DPF; /* discard pause frames when FC enabled */
3469 fctrl |= IXGBE_FCTRL_PMCF;
3470
3471 /* clear the bits we are changing the status of */
3472 fctrl &= ~(IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
3473
3474 if (netdev->flags & IFF_PROMISC) {
3475 hw->addr_ctrl.user_set_promisc = true;
3476 fctrl |= (IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
3477 vmolr |= (IXGBE_VMOLR_ROPE | IXGBE_VMOLR_MPE);
3478 /* don't hardware filter vlans in promisc mode */
3479 ixgbe_vlan_filter_disable(adapter);
3480 } else {
3481 if (netdev->flags & IFF_ALLMULTI) {
3482 fctrl |= IXGBE_FCTRL_MPE;
3483 vmolr |= IXGBE_VMOLR_MPE;
3484 } else {
3485 /*
3486 * Write addresses to the MTA, if the attempt fails
3487 * then we should just turn on promiscuous mode so
3488 * that we can at least receive multicast traffic
3489 */
3490 hw->mac.ops.update_mc_addr_list(hw, netdev);
3491 vmolr |= IXGBE_VMOLR_ROMPE;
3492 }
3493 ixgbe_vlan_filter_enable(adapter);
3494 hw->addr_ctrl.user_set_promisc = false;
3495 /*
3496 * Write addresses to available RAR registers, if there is not
3497 * sufficient space to store all the addresses then enable
3498 * unicast promiscuous mode
3499 */
3500 count = ixgbe_write_uc_addr_list(netdev);
3501 if (count < 0) {
3502 fctrl |= IXGBE_FCTRL_UPE;
3503 vmolr |= IXGBE_VMOLR_ROPE;
3504 }
3505 }
3506
3507 if (adapter->num_vfs) {
3508 ixgbe_restore_vf_multicasts(adapter);
3509 vmolr |= IXGBE_READ_REG(hw, IXGBE_VMOLR(adapter->num_vfs)) &
3510 ~(IXGBE_VMOLR_MPE | IXGBE_VMOLR_ROMPE |
3511 IXGBE_VMOLR_ROPE);
3512 IXGBE_WRITE_REG(hw, IXGBE_VMOLR(adapter->num_vfs), vmolr);
3513 }
3514
3515 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
3516
3517 if (netdev->features & NETIF_F_HW_VLAN_RX)
3518 ixgbe_vlan_strip_enable(adapter);
3519 else
3520 ixgbe_vlan_strip_disable(adapter);
3521}
3522
3523static void ixgbe_napi_enable_all(struct ixgbe_adapter *adapter)
3524{
3525 int q_idx;
3526 struct ixgbe_q_vector *q_vector;
3527 int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
3528
3529 /* legacy and MSI only use one vector */
3530 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
3531 q_vectors = 1;
3532
3533 for (q_idx = 0; q_idx < q_vectors; q_idx++) {
3534 struct napi_struct *napi;
3535 q_vector = adapter->q_vector[q_idx];
3536 napi = &q_vector->napi;
3537 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
3538 if (!q_vector->rx.count || !q_vector->tx.count) {
3539 if (q_vector->tx.count == 1)
3540 napi->poll = &ixgbe_clean_txonly;
3541 else if (q_vector->rx.count == 1)
3542 napi->poll = &ixgbe_clean_rxonly;
3543 }
3544 }
3545
3546 napi_enable(napi);
3547 }
3548}
3549
3550static void ixgbe_napi_disable_all(struct ixgbe_adapter *adapter)
3551{
3552 int q_idx;
3553 struct ixgbe_q_vector *q_vector;
3554 int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
3555
3556 /* legacy and MSI only use one vector */
3557 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
3558 q_vectors = 1;
3559
3560 for (q_idx = 0; q_idx < q_vectors; q_idx++) {
3561 q_vector = adapter->q_vector[q_idx];
3562 napi_disable(&q_vector->napi);
3563 }
3564}
3565
3566#ifdef CONFIG_IXGBE_DCB
3567/*
3568 * ixgbe_configure_dcb - Configure DCB hardware
3569 * @adapter: ixgbe adapter struct
3570 *
3571 * This is called by the driver on open to configure the DCB hardware.
3572 * This is also called by the gennetlink interface when reconfiguring
3573 * the DCB state.
3574 */
3575static void ixgbe_configure_dcb(struct ixgbe_adapter *adapter)
3576{
3577 struct ixgbe_hw *hw = &adapter->hw;
3578 int max_frame = adapter->netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
3579
3580 if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED)) {
3581 if (hw->mac.type == ixgbe_mac_82598EB)
3582 netif_set_gso_max_size(adapter->netdev, 65536);
3583 return;
3584 }
3585
3586 if (hw->mac.type == ixgbe_mac_82598EB)
3587 netif_set_gso_max_size(adapter->netdev, 32768);
3588
3589
3590 /* Enable VLAN tag insert/strip */
3591 adapter->netdev->features |= NETIF_F_HW_VLAN_RX;
3592
3593 hw->mac.ops.set_vfta(&adapter->hw, 0, 0, true);
3594
3595 /* reconfigure the hardware */
3596 if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_CEE) {
3597#ifdef CONFIG_FCOE
3598 if (adapter->netdev->features & NETIF_F_FCOE_MTU)
3599 max_frame = max(max_frame, IXGBE_FCOE_JUMBO_FRAME_SIZE);
3600#endif
3601 ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame,
3602 DCB_TX_CONFIG);
3603 ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame,
3604 DCB_RX_CONFIG);
3605 ixgbe_dcb_hw_config(hw, &adapter->dcb_cfg);
3606 } else {
3607 struct net_device *dev = adapter->netdev;
3608
3609 if (adapter->ixgbe_ieee_ets)
3610 dev->dcbnl_ops->ieee_setets(dev,
3611 adapter->ixgbe_ieee_ets);
3612 if (adapter->ixgbe_ieee_pfc)
3613 dev->dcbnl_ops->ieee_setpfc(dev,
3614 adapter->ixgbe_ieee_pfc);
3615 }
3616
3617 /* Enable RSS Hash per TC */
3618 if (hw->mac.type != ixgbe_mac_82598EB) {
3619 int i;
3620 u32 reg = 0;
3621
3622 for (i = 0; i < MAX_TRAFFIC_CLASS; i++) {
3623 u8 msb = 0;
3624 u8 cnt = adapter->netdev->tc_to_txq[i].count;
3625
3626 while (cnt >>= 1)
3627 msb++;
3628
3629 reg |= msb << IXGBE_RQTC_SHIFT_TC(i);
3630 }
3631 IXGBE_WRITE_REG(hw, IXGBE_RQTC, reg);
3632 }
3633}
3634
3635#endif
3636
3637static void ixgbe_configure_pb(struct ixgbe_adapter *adapter)
3638{
3639 int hdrm = 0;
3640 int num_tc = netdev_get_num_tc(adapter->netdev);
3641 struct ixgbe_hw *hw = &adapter->hw;
3642
3643 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE ||
3644 adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)
3645 hdrm = 64 << adapter->fdir_pballoc;
3646
3647 hw->mac.ops.set_rxpba(&adapter->hw, num_tc, hdrm, PBA_STRATEGY_EQUAL);
3648}
3649
3650static void ixgbe_fdir_filter_restore(struct ixgbe_adapter *adapter)
3651{
3652 struct ixgbe_hw *hw = &adapter->hw;
3653 struct hlist_node *node, *node2;
3654 struct ixgbe_fdir_filter *filter;
3655
3656 spin_lock(&adapter->fdir_perfect_lock);
3657
3658 if (!hlist_empty(&adapter->fdir_filter_list))
3659 ixgbe_fdir_set_input_mask_82599(hw, &adapter->fdir_mask);
3660
3661 hlist_for_each_entry_safe(filter, node, node2,
3662 &adapter->fdir_filter_list, fdir_node) {
3663 ixgbe_fdir_write_perfect_filter_82599(hw,
3664 &filter->filter,
3665 filter->sw_idx,
3666 (filter->action == IXGBE_FDIR_DROP_QUEUE) ?
3667 IXGBE_FDIR_DROP_QUEUE :
3668 adapter->rx_ring[filter->action]->reg_idx);
3669 }
3670
3671 spin_unlock(&adapter->fdir_perfect_lock);
3672}
3673
3674static void ixgbe_configure(struct ixgbe_adapter *adapter)
3675{
3676 struct net_device *netdev = adapter->netdev;
3677 struct ixgbe_hw *hw = &adapter->hw;
3678 int i;
3679
3680 ixgbe_configure_pb(adapter);
3681#ifdef CONFIG_IXGBE_DCB
3682 ixgbe_configure_dcb(adapter);
3683#endif
3684
3685 ixgbe_set_rx_mode(netdev);
3686 ixgbe_restore_vlan(adapter);
3687
3688#ifdef IXGBE_FCOE
3689 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)
3690 ixgbe_configure_fcoe(adapter);
3691
3692#endif /* IXGBE_FCOE */
3693 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
3694 for (i = 0; i < adapter->num_tx_queues; i++)
3695 adapter->tx_ring[i]->atr_sample_rate =
3696 adapter->atr_sample_rate;
3697 ixgbe_init_fdir_signature_82599(hw, adapter->fdir_pballoc);
3698 } else if (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) {
3699 ixgbe_init_fdir_perfect_82599(&adapter->hw,
3700 adapter->fdir_pballoc);
3701 ixgbe_fdir_filter_restore(adapter);
3702 }
3703 ixgbe_configure_virtualization(adapter);
3704
3705 ixgbe_configure_tx(adapter);
3706 ixgbe_configure_rx(adapter);
3707}
3708
3709static inline bool ixgbe_is_sfp(struct ixgbe_hw *hw)
3710{
3711 switch (hw->phy.type) {
3712 case ixgbe_phy_sfp_avago:
3713 case ixgbe_phy_sfp_ftl:
3714 case ixgbe_phy_sfp_intel:
3715 case ixgbe_phy_sfp_unknown:
3716 case ixgbe_phy_sfp_passive_tyco:
3717 case ixgbe_phy_sfp_passive_unknown:
3718 case ixgbe_phy_sfp_active_unknown:
3719 case ixgbe_phy_sfp_ftl_active:
3720 return true;
3721 default:
3722 return false;
3723 }
3724}
3725
3726/**
3727 * ixgbe_sfp_link_config - set up SFP+ link
3728 * @adapter: pointer to private adapter struct
3729 **/
3730static void ixgbe_sfp_link_config(struct ixgbe_adapter *adapter)
3731{
3732 /*
3733 * We are assuming the worst case scenerio here, and that
3734 * is that an SFP was inserted/removed after the reset
3735 * but before SFP detection was enabled. As such the best
3736 * solution is to just start searching as soon as we start
3737 */
3738 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
3739 adapter->flags2 |= IXGBE_FLAG2_SEARCH_FOR_SFP;
3740
3741 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
3742}
3743
3744/**
3745 * ixgbe_non_sfp_link_config - set up non-SFP+ link
3746 * @hw: pointer to private hardware struct
3747 *
3748 * Returns 0 on success, negative on failure
3749 **/
3750static int ixgbe_non_sfp_link_config(struct ixgbe_hw *hw)
3751{
3752 u32 autoneg;
3753 bool negotiation, link_up = false;
3754 u32 ret = IXGBE_ERR_LINK_SETUP;
3755
3756 if (hw->mac.ops.check_link)
3757 ret = hw->mac.ops.check_link(hw, &autoneg, &link_up, false);
3758
3759 if (ret)
3760 goto link_cfg_out;
3761
3762 autoneg = hw->phy.autoneg_advertised;
3763 if ((!autoneg) && (hw->mac.ops.get_link_capabilities))
3764 ret = hw->mac.ops.get_link_capabilities(hw, &autoneg,
3765 &negotiation);
3766 if (ret)
3767 goto link_cfg_out;
3768
3769 if (hw->mac.ops.setup_link)
3770 ret = hw->mac.ops.setup_link(hw, autoneg, negotiation, link_up);
3771link_cfg_out:
3772 return ret;
3773}
3774
3775static void ixgbe_setup_gpie(struct ixgbe_adapter *adapter)
3776{
3777 struct ixgbe_hw *hw = &adapter->hw;
3778 u32 gpie = 0;
3779
3780 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
3781 gpie = IXGBE_GPIE_MSIX_MODE | IXGBE_GPIE_PBA_SUPPORT |
3782 IXGBE_GPIE_OCD;
3783 gpie |= IXGBE_GPIE_EIAME;
3784 /*
3785 * use EIAM to auto-mask when MSI-X interrupt is asserted
3786 * this saves a register write for every interrupt
3787 */
3788 switch (hw->mac.type) {
3789 case ixgbe_mac_82598EB:
3790 IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
3791 break;
3792 case ixgbe_mac_82599EB:
3793 case ixgbe_mac_X540:
3794 default:
3795 IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(0), 0xFFFFFFFF);
3796 IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(1), 0xFFFFFFFF);
3797 break;
3798 }
3799 } else {
3800 /* legacy interrupts, use EIAM to auto-mask when reading EICR,
3801 * specifically only auto mask tx and rx interrupts */
3802 IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
3803 }
3804
3805 /* XXX: to interrupt immediately for EICS writes, enable this */
3806 /* gpie |= IXGBE_GPIE_EIMEN; */
3807
3808 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
3809 gpie &= ~IXGBE_GPIE_VTMODE_MASK;
3810 gpie |= IXGBE_GPIE_VTMODE_64;
3811 }
3812
3813 /* Enable fan failure interrupt */
3814 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE)
3815 gpie |= IXGBE_SDP1_GPIEN;
3816
3817 if (hw->mac.type == ixgbe_mac_82599EB) {
3818 gpie |= IXGBE_SDP1_GPIEN;
3819 gpie |= IXGBE_SDP2_GPIEN;
3820 }
3821
3822 IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie);
3823}
3824
3825static int ixgbe_up_complete(struct ixgbe_adapter *adapter)
3826{
3827 struct ixgbe_hw *hw = &adapter->hw;
3828 int err;
3829 u32 ctrl_ext;
3830
3831 ixgbe_get_hw_control(adapter);
3832 ixgbe_setup_gpie(adapter);
3833
3834 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
3835 ixgbe_configure_msix(adapter);
3836 else
3837 ixgbe_configure_msi_and_legacy(adapter);
3838
3839 /* enable the optics for both mult-speed fiber and 82599 SFP+ fiber */
3840 if (hw->mac.ops.enable_tx_laser &&
3841 ((hw->phy.multispeed_fiber) ||
3842 ((hw->mac.ops.get_media_type(hw) == ixgbe_media_type_fiber) &&
3843 (hw->mac.type == ixgbe_mac_82599EB))))
3844 hw->mac.ops.enable_tx_laser(hw);
3845
3846 clear_bit(__IXGBE_DOWN, &adapter->state);
3847 ixgbe_napi_enable_all(adapter);
3848
3849 if (ixgbe_is_sfp(hw)) {
3850 ixgbe_sfp_link_config(adapter);
3851 } else {
3852 err = ixgbe_non_sfp_link_config(hw);
3853 if (err)
3854 e_err(probe, "link_config FAILED %d\n", err);
3855 }
3856
3857 /* clear any pending interrupts, may auto mask */
3858 IXGBE_READ_REG(hw, IXGBE_EICR);
3859 ixgbe_irq_enable(adapter, true, true);
3860
3861 /*
3862 * If this adapter has a fan, check to see if we had a failure
3863 * before we enabled the interrupt.
3864 */
3865 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
3866 u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
3867 if (esdp & IXGBE_ESDP_SDP1)
3868 e_crit(drv, "Fan has stopped, replace the adapter\n");
3869 }
3870
3871 /* enable transmits */
3872 netif_tx_start_all_queues(adapter->netdev);
3873
3874 /* bring the link up in the watchdog, this could race with our first
3875 * link up interrupt but shouldn't be a problem */
3876 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
3877 adapter->link_check_timeout = jiffies;
3878 mod_timer(&adapter->service_timer, jiffies);
3879
3880 /* Set PF Reset Done bit so PF/VF Mail Ops can work */
3881 ctrl_ext = IXGBE_READ_REG(hw, IXGBE_CTRL_EXT);
3882 ctrl_ext |= IXGBE_CTRL_EXT_PFRSTD;
3883 IXGBE_WRITE_REG(hw, IXGBE_CTRL_EXT, ctrl_ext);
3884
3885 return 0;
3886}
3887
3888void ixgbe_reinit_locked(struct ixgbe_adapter *adapter)
3889{
3890 WARN_ON(in_interrupt());
3891 /* put off any impending NetWatchDogTimeout */
3892 adapter->netdev->trans_start = jiffies;
3893
3894 while (test_and_set_bit(__IXGBE_RESETTING, &adapter->state))
3895 usleep_range(1000, 2000);
3896 ixgbe_down(adapter);
3897 /*
3898 * If SR-IOV enabled then wait a bit before bringing the adapter
3899 * back up to give the VFs time to respond to the reset. The
3900 * two second wait is based upon the watchdog timer cycle in
3901 * the VF driver.
3902 */
3903 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
3904 msleep(2000);
3905 ixgbe_up(adapter);
3906 clear_bit(__IXGBE_RESETTING, &adapter->state);
3907}
3908
3909int ixgbe_up(struct ixgbe_adapter *adapter)
3910{
3911 /* hardware has been reset, we need to reload some things */
3912 ixgbe_configure(adapter);
3913
3914 return ixgbe_up_complete(adapter);
3915}
3916
3917void ixgbe_reset(struct ixgbe_adapter *adapter)
3918{
3919 struct ixgbe_hw *hw = &adapter->hw;
3920 int err;
3921
3922 /* lock SFP init bit to prevent race conditions with the watchdog */
3923 while (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
3924 usleep_range(1000, 2000);
3925
3926 /* clear all SFP and link config related flags while holding SFP_INIT */
3927 adapter->flags2 &= ~(IXGBE_FLAG2_SEARCH_FOR_SFP |
3928 IXGBE_FLAG2_SFP_NEEDS_RESET);
3929 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG;
3930
3931 err = hw->mac.ops.init_hw(hw);
3932 switch (err) {
3933 case 0:
3934 case IXGBE_ERR_SFP_NOT_PRESENT:
3935 case IXGBE_ERR_SFP_NOT_SUPPORTED:
3936 break;
3937 case IXGBE_ERR_MASTER_REQUESTS_PENDING:
3938 e_dev_err("master disable timed out\n");
3939 break;
3940 case IXGBE_ERR_EEPROM_VERSION:
3941 /* We are running on a pre-production device, log a warning */
3942 e_dev_warn("This device is a pre-production adapter/LOM. "
3943 "Please be aware there may be issuesassociated with "
3944 "your hardware. If you are experiencing problems "
3945 "please contact your Intel or hardware "
3946 "representative who provided you with this "
3947 "hardware.\n");
3948 break;
3949 default:
3950 e_dev_err("Hardware Error: %d\n", err);
3951 }
3952
3953 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
3954
3955 /* reprogram the RAR[0] in case user changed it. */
3956 hw->mac.ops.set_rar(hw, 0, hw->mac.addr, adapter->num_vfs,
3957 IXGBE_RAH_AV);
3958}
3959
3960/**
3961 * ixgbe_clean_rx_ring - Free Rx Buffers per Queue
3962 * @rx_ring: ring to free buffers from
3963 **/
3964static void ixgbe_clean_rx_ring(struct ixgbe_ring *rx_ring)
3965{
3966 struct device *dev = rx_ring->dev;
3967 unsigned long size;
3968 u16 i;
3969
3970 /* ring already cleared, nothing to do */
3971 if (!rx_ring->rx_buffer_info)
3972 return;
3973
3974 /* Free all the Rx ring sk_buffs */
3975 for (i = 0; i < rx_ring->count; i++) {
3976 struct ixgbe_rx_buffer *rx_buffer_info;
3977
3978 rx_buffer_info = &rx_ring->rx_buffer_info[i];
3979 if (rx_buffer_info->dma) {
3980 dma_unmap_single(rx_ring->dev, rx_buffer_info->dma,
3981 rx_ring->rx_buf_len,
3982 DMA_FROM_DEVICE);
3983 rx_buffer_info->dma = 0;
3984 }
3985 if (rx_buffer_info->skb) {
3986 struct sk_buff *skb = rx_buffer_info->skb;
3987 rx_buffer_info->skb = NULL;
3988 do {
3989 struct sk_buff *this = skb;
3990 if (IXGBE_RSC_CB(this)->delay_unmap) {
3991 dma_unmap_single(dev,
3992 IXGBE_RSC_CB(this)->dma,
3993 rx_ring->rx_buf_len,
3994 DMA_FROM_DEVICE);
3995 IXGBE_RSC_CB(this)->dma = 0;
3996 IXGBE_RSC_CB(skb)->delay_unmap = false;
3997 }
3998 skb = skb->prev;
3999 dev_kfree_skb(this);
4000 } while (skb);
4001 }
4002 if (!rx_buffer_info->page)
4003 continue;
4004 if (rx_buffer_info->page_dma) {
4005 dma_unmap_page(dev, rx_buffer_info->page_dma,
4006 PAGE_SIZE / 2, DMA_FROM_DEVICE);
4007 rx_buffer_info->page_dma = 0;
4008 }
4009 put_page(rx_buffer_info->page);
4010 rx_buffer_info->page = NULL;
4011 rx_buffer_info->page_offset = 0;
4012 }
4013
4014 size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
4015 memset(rx_ring->rx_buffer_info, 0, size);
4016
4017 /* Zero out the descriptor ring */
4018 memset(rx_ring->desc, 0, rx_ring->size);
4019
4020 rx_ring->next_to_clean = 0;
4021 rx_ring->next_to_use = 0;
4022}
4023
4024/**
4025 * ixgbe_clean_tx_ring - Free Tx Buffers
4026 * @tx_ring: ring to be cleaned
4027 **/
4028static void ixgbe_clean_tx_ring(struct ixgbe_ring *tx_ring)
4029{
4030 struct ixgbe_tx_buffer *tx_buffer_info;
4031 unsigned long size;
4032 u16 i;
4033
4034 /* ring already cleared, nothing to do */
4035 if (!tx_ring->tx_buffer_info)
4036 return;
4037
4038 /* Free all the Tx ring sk_buffs */
4039 for (i = 0; i < tx_ring->count; i++) {
4040 tx_buffer_info = &tx_ring->tx_buffer_info[i];
4041 ixgbe_unmap_and_free_tx_resource(tx_ring, tx_buffer_info);
4042 }
4043
4044 size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
4045 memset(tx_ring->tx_buffer_info, 0, size);
4046
4047 /* Zero out the descriptor ring */
4048 memset(tx_ring->desc, 0, tx_ring->size);
4049
4050 tx_ring->next_to_use = 0;
4051 tx_ring->next_to_clean = 0;
4052}
4053
4054/**
4055 * ixgbe_clean_all_rx_rings - Free Rx Buffers for all queues
4056 * @adapter: board private structure
4057 **/
4058static void ixgbe_clean_all_rx_rings(struct ixgbe_adapter *adapter)
4059{
4060 int i;
4061
4062 for (i = 0; i < adapter->num_rx_queues; i++)
4063 ixgbe_clean_rx_ring(adapter->rx_ring[i]);
4064}
4065
4066/**
4067 * ixgbe_clean_all_tx_rings - Free Tx Buffers for all queues
4068 * @adapter: board private structure
4069 **/
4070static void ixgbe_clean_all_tx_rings(struct ixgbe_adapter *adapter)
4071{
4072 int i;
4073
4074 for (i = 0; i < adapter->num_tx_queues; i++)
4075 ixgbe_clean_tx_ring(adapter->tx_ring[i]);
4076}
4077
4078static void ixgbe_fdir_filter_exit(struct ixgbe_adapter *adapter)
4079{
4080 struct hlist_node *node, *node2;
4081 struct ixgbe_fdir_filter *filter;
4082
4083 spin_lock(&adapter->fdir_perfect_lock);
4084
4085 hlist_for_each_entry_safe(filter, node, node2,
4086 &adapter->fdir_filter_list, fdir_node) {
4087 hlist_del(&filter->fdir_node);
4088 kfree(filter);
4089 }
4090 adapter->fdir_filter_count = 0;
4091
4092 spin_unlock(&adapter->fdir_perfect_lock);
4093}
4094
4095void ixgbe_down(struct ixgbe_adapter *adapter)
4096{
4097 struct net_device *netdev = adapter->netdev;
4098 struct ixgbe_hw *hw = &adapter->hw;
4099 u32 rxctrl;
4100 int i;
4101 int num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
4102
4103 /* signal that we are down to the interrupt handler */
4104 set_bit(__IXGBE_DOWN, &adapter->state);
4105
4106 /* disable receives */
4107 rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
4108 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN);
4109
4110 /* disable all enabled rx queues */
4111 for (i = 0; i < adapter->num_rx_queues; i++)
4112 /* this call also flushes the previous write */
4113 ixgbe_disable_rx_queue(adapter, adapter->rx_ring[i]);
4114
4115 usleep_range(10000, 20000);
4116
4117 netif_tx_stop_all_queues(netdev);
4118
4119 /* call carrier off first to avoid false dev_watchdog timeouts */
4120 netif_carrier_off(netdev);
4121 netif_tx_disable(netdev);
4122
4123 ixgbe_irq_disable(adapter);
4124
4125 ixgbe_napi_disable_all(adapter);
4126
4127 adapter->flags2 &= ~(IXGBE_FLAG2_FDIR_REQUIRES_REINIT |
4128 IXGBE_FLAG2_RESET_REQUESTED);
4129 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE;
4130
4131 del_timer_sync(&adapter->service_timer);
4132
4133 /* disable receive for all VFs and wait one second */
4134 if (adapter->num_vfs) {
4135 /* ping all the active vfs to let them know we are going down */
4136 ixgbe_ping_all_vfs(adapter);
4137
4138 /* Disable all VFTE/VFRE TX/RX */
4139 ixgbe_disable_tx_rx(adapter);
4140
4141 /* Mark all the VFs as inactive */
4142 for (i = 0 ; i < adapter->num_vfs; i++)
4143 adapter->vfinfo[i].clear_to_send = 0;
4144 }
4145
4146 /* Cleanup the affinity_hint CPU mask memory and callback */
4147 for (i = 0; i < num_q_vectors; i++) {
4148 struct ixgbe_q_vector *q_vector = adapter->q_vector[i];
4149 /* clear the affinity_mask in the IRQ descriptor */
4150 irq_set_affinity_hint(adapter->msix_entries[i]. vector, NULL);
4151 /* release the CPU mask memory */
4152 free_cpumask_var(q_vector->affinity_mask);
4153 }
4154
4155 /* disable transmits in the hardware now that interrupts are off */
4156 for (i = 0; i < adapter->num_tx_queues; i++) {
4157 u8 reg_idx = adapter->tx_ring[i]->reg_idx;
4158 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), IXGBE_TXDCTL_SWFLSH);
4159 }
4160
4161 /* Disable the Tx DMA engine on 82599 and X540 */
4162 switch (hw->mac.type) {
4163 case ixgbe_mac_82599EB:
4164 case ixgbe_mac_X540:
4165 IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL,
4166 (IXGBE_READ_REG(hw, IXGBE_DMATXCTL) &
4167 ~IXGBE_DMATXCTL_TE));
4168 break;
4169 default:
4170 break;
4171 }
4172
4173 if (!pci_channel_offline(adapter->pdev))
4174 ixgbe_reset(adapter);
4175
4176 /* power down the optics for multispeed fiber and 82599 SFP+ fiber */
4177 if (hw->mac.ops.disable_tx_laser &&
4178 ((hw->phy.multispeed_fiber) ||
4179 ((hw->mac.ops.get_media_type(hw) == ixgbe_media_type_fiber) &&
4180 (hw->mac.type == ixgbe_mac_82599EB))))
4181 hw->mac.ops.disable_tx_laser(hw);
4182
4183 ixgbe_clean_all_tx_rings(adapter);
4184 ixgbe_clean_all_rx_rings(adapter);
4185
4186#ifdef CONFIG_IXGBE_DCA
4187 /* since we reset the hardware DCA settings were cleared */
4188 ixgbe_setup_dca(adapter);
4189#endif
4190}
4191
4192/**
4193 * ixgbe_poll - NAPI Rx polling callback
4194 * @napi: structure for representing this polling device
4195 * @budget: how many packets driver is allowed to clean
4196 *
4197 * This function is used for legacy and MSI, NAPI mode
4198 **/
4199static int ixgbe_poll(struct napi_struct *napi, int budget)
4200{
4201 struct ixgbe_q_vector *q_vector =
4202 container_of(napi, struct ixgbe_q_vector, napi);
4203 struct ixgbe_adapter *adapter = q_vector->adapter;
4204 int tx_clean_complete, work_done = 0;
4205
4206#ifdef CONFIG_IXGBE_DCA
4207 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
4208 ixgbe_update_dca(q_vector);
4209#endif
4210
4211 tx_clean_complete = ixgbe_clean_tx_irq(q_vector, adapter->tx_ring[0]);
4212 ixgbe_clean_rx_irq(q_vector, adapter->rx_ring[0], &work_done, budget);
4213
4214 if (!tx_clean_complete)
4215 work_done = budget;
4216
4217 /* If budget not fully consumed, exit the polling mode */
4218 if (work_done < budget) {
4219 napi_complete(napi);
4220 if (adapter->rx_itr_setting & 1)
4221 ixgbe_set_itr(q_vector);
4222 if (!test_bit(__IXGBE_DOWN, &adapter->state))
4223 ixgbe_irq_enable_queues(adapter, IXGBE_EIMS_RTX_QUEUE);
4224 }
4225 return work_done;
4226}
4227
4228/**
4229 * ixgbe_tx_timeout - Respond to a Tx Hang
4230 * @netdev: network interface device structure
4231 **/
4232static void ixgbe_tx_timeout(struct net_device *netdev)
4233{
4234 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4235
4236 /* Do the reset outside of interrupt context */
4237 ixgbe_tx_timeout_reset(adapter);
4238}
4239
4240/**
4241 * ixgbe_set_rss_queues: Allocate queues for RSS
4242 * @adapter: board private structure to initialize
4243 *
4244 * This is our "base" multiqueue mode. RSS (Receive Side Scaling) will try
4245 * to allocate one Rx queue per CPU, and if available, one Tx queue per CPU.
4246 *
4247 **/
4248static inline bool ixgbe_set_rss_queues(struct ixgbe_adapter *adapter)
4249{
4250 bool ret = false;
4251 struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_RSS];
4252
4253 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
4254 f->mask = 0xF;
4255 adapter->num_rx_queues = f->indices;
4256 adapter->num_tx_queues = f->indices;
4257 ret = true;
4258 } else {
4259 ret = false;
4260 }
4261
4262 return ret;
4263}
4264
4265/**
4266 * ixgbe_set_fdir_queues: Allocate queues for Flow Director
4267 * @adapter: board private structure to initialize
4268 *
4269 * Flow Director is an advanced Rx filter, attempting to get Rx flows back
4270 * to the original CPU that initiated the Tx session. This runs in addition
4271 * to RSS, so if a packet doesn't match an FDIR filter, we can still spread the
4272 * Rx load across CPUs using RSS.
4273 *
4274 **/
4275static inline bool ixgbe_set_fdir_queues(struct ixgbe_adapter *adapter)
4276{
4277 bool ret = false;
4278 struct ixgbe_ring_feature *f_fdir = &adapter->ring_feature[RING_F_FDIR];
4279
4280 f_fdir->indices = min((int)num_online_cpus(), f_fdir->indices);
4281 f_fdir->mask = 0;
4282
4283 /* Flow Director must have RSS enabled */
4284 if ((adapter->flags & IXGBE_FLAG_RSS_ENABLED) &&
4285 (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE)) {
4286 adapter->num_tx_queues = f_fdir->indices;
4287 adapter->num_rx_queues = f_fdir->indices;
4288 ret = true;
4289 } else {
4290 adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
4291 }
4292 return ret;
4293}
4294
4295#ifdef IXGBE_FCOE
4296/**
4297 * ixgbe_set_fcoe_queues: Allocate queues for Fiber Channel over Ethernet (FCoE)
4298 * @adapter: board private structure to initialize
4299 *
4300 * FCoE RX FCRETA can use up to 8 rx queues for up to 8 different exchanges.
4301 * The ring feature mask is not used as a mask for FCoE, as it can take any 8
4302 * rx queues out of the max number of rx queues, instead, it is used as the
4303 * index of the first rx queue used by FCoE.
4304 *
4305 **/
4306static inline bool ixgbe_set_fcoe_queues(struct ixgbe_adapter *adapter)
4307{
4308 struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_FCOE];
4309
4310 if (!(adapter->flags & IXGBE_FLAG_FCOE_ENABLED))
4311 return false;
4312
4313 f->indices = min((int)num_online_cpus(), f->indices);
4314
4315 adapter->num_rx_queues = 1;
4316 adapter->num_tx_queues = 1;
4317
4318 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
4319 e_info(probe, "FCoE enabled with RSS\n");
4320 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE)
4321 ixgbe_set_fdir_queues(adapter);
4322 else
4323 ixgbe_set_rss_queues(adapter);
4324 }
4325
4326 /* adding FCoE rx rings to the end */
4327 f->mask = adapter->num_rx_queues;
4328 adapter->num_rx_queues += f->indices;
4329 adapter->num_tx_queues += f->indices;
4330
4331 return true;
4332}
4333#endif /* IXGBE_FCOE */
4334
4335/* Artificial max queue cap per traffic class in DCB mode */
4336#define DCB_QUEUE_CAP 8
4337
4338#ifdef CONFIG_IXGBE_DCB
4339static inline bool ixgbe_set_dcb_queues(struct ixgbe_adapter *adapter)
4340{
4341 int per_tc_q, q, i, offset = 0;
4342 struct net_device *dev = adapter->netdev;
4343 int tcs = netdev_get_num_tc(dev);
4344
4345 if (!tcs)
4346 return false;
4347
4348 /* Map queue offset and counts onto allocated tx queues */
4349 per_tc_q = min(dev->num_tx_queues / tcs, (unsigned int)DCB_QUEUE_CAP);
4350 q = min((int)num_online_cpus(), per_tc_q);
4351
4352 for (i = 0; i < tcs; i++) {
4353 netdev_set_prio_tc_map(dev, i, i);
4354 netdev_set_tc_queue(dev, i, q, offset);
4355 offset += q;
4356 }
4357
4358 adapter->num_tx_queues = q * tcs;
4359 adapter->num_rx_queues = q * tcs;
4360
4361#ifdef IXGBE_FCOE
4362 /* FCoE enabled queues require special configuration indexed
4363 * by feature specific indices and mask. Here we map FCoE
4364 * indices onto the DCB queue pairs allowing FCoE to own
4365 * configuration later.
4366 */
4367 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) {
4368 int tc;
4369 struct ixgbe_ring_feature *f =
4370 &adapter->ring_feature[RING_F_FCOE];
4371
4372 tc = netdev_get_prio_tc_map(dev, adapter->fcoe.up);
4373 f->indices = dev->tc_to_txq[tc].count;
4374 f->mask = dev->tc_to_txq[tc].offset;
4375 }
4376#endif
4377
4378 return true;
4379}
4380#endif
4381
4382/**
4383 * ixgbe_set_sriov_queues: Allocate queues for IOV use
4384 * @adapter: board private structure to initialize
4385 *
4386 * IOV doesn't actually use anything, so just NAK the
4387 * request for now and let the other queue routines
4388 * figure out what to do.
4389 */
4390static inline bool ixgbe_set_sriov_queues(struct ixgbe_adapter *adapter)
4391{
4392 return false;
4393}
4394
4395/*
4396 * ixgbe_set_num_queues: Allocate queues for device, feature dependent
4397 * @adapter: board private structure to initialize
4398 *
4399 * This is the top level queue allocation routine. The order here is very
4400 * important, starting with the "most" number of features turned on at once,
4401 * and ending with the smallest set of features. This way large combinations
4402 * can be allocated if they're turned on, and smaller combinations are the
4403 * fallthrough conditions.
4404 *
4405 **/
4406static int ixgbe_set_num_queues(struct ixgbe_adapter *adapter)
4407{
4408 /* Start with base case */
4409 adapter->num_rx_queues = 1;
4410 adapter->num_tx_queues = 1;
4411 adapter->num_rx_pools = adapter->num_rx_queues;
4412 adapter->num_rx_queues_per_pool = 1;
4413
4414 if (ixgbe_set_sriov_queues(adapter))
4415 goto done;
4416
4417#ifdef CONFIG_IXGBE_DCB
4418 if (ixgbe_set_dcb_queues(adapter))
4419 goto done;
4420
4421#endif
4422#ifdef IXGBE_FCOE
4423 if (ixgbe_set_fcoe_queues(adapter))
4424 goto done;
4425
4426#endif /* IXGBE_FCOE */
4427 if (ixgbe_set_fdir_queues(adapter))
4428 goto done;
4429
4430 if (ixgbe_set_rss_queues(adapter))
4431 goto done;
4432
4433 /* fallback to base case */
4434 adapter->num_rx_queues = 1;
4435 adapter->num_tx_queues = 1;
4436
4437done:
4438 /* Notify the stack of the (possibly) reduced queue counts. */
4439 netif_set_real_num_tx_queues(adapter->netdev, adapter->num_tx_queues);
4440 return netif_set_real_num_rx_queues(adapter->netdev,
4441 adapter->num_rx_queues);
4442}
4443
4444static void ixgbe_acquire_msix_vectors(struct ixgbe_adapter *adapter,
4445 int vectors)
4446{
4447 int err, vector_threshold;
4448
4449 /* We'll want at least 3 (vector_threshold):
4450 * 1) TxQ[0] Cleanup
4451 * 2) RxQ[0] Cleanup
4452 * 3) Other (Link Status Change, etc.)
4453 * 4) TCP Timer (optional)
4454 */
4455 vector_threshold = MIN_MSIX_COUNT;
4456
4457 /* The more we get, the more we will assign to Tx/Rx Cleanup
4458 * for the separate queues...where Rx Cleanup >= Tx Cleanup.
4459 * Right now, we simply care about how many we'll get; we'll
4460 * set them up later while requesting irq's.
4461 */
4462 while (vectors >= vector_threshold) {
4463 err = pci_enable_msix(adapter->pdev, adapter->msix_entries,
4464 vectors);
4465 if (!err) /* Success in acquiring all requested vectors. */
4466 break;
4467 else if (err < 0)
4468 vectors = 0; /* Nasty failure, quit now */
4469 else /* err == number of vectors we should try again with */
4470 vectors = err;
4471 }
4472
4473 if (vectors < vector_threshold) {
4474 /* Can't allocate enough MSI-X interrupts? Oh well.
4475 * This just means we'll go with either a single MSI
4476 * vector or fall back to legacy interrupts.
4477 */
4478 netif_printk(adapter, hw, KERN_DEBUG, adapter->netdev,
4479 "Unable to allocate MSI-X interrupts\n");
4480 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
4481 kfree(adapter->msix_entries);
4482 adapter->msix_entries = NULL;
4483 } else {
4484 adapter->flags |= IXGBE_FLAG_MSIX_ENABLED; /* Woot! */
4485 /*
4486 * Adjust for only the vectors we'll use, which is minimum
4487 * of max_msix_q_vectors + NON_Q_VECTORS, or the number of
4488 * vectors we were allocated.
4489 */
4490 adapter->num_msix_vectors = min(vectors,
4491 adapter->max_msix_q_vectors + NON_Q_VECTORS);
4492 }
4493}
4494
4495/**
4496 * ixgbe_cache_ring_rss - Descriptor ring to register mapping for RSS
4497 * @adapter: board private structure to initialize
4498 *
4499 * Cache the descriptor ring offsets for RSS to the assigned rings.
4500 *
4501 **/
4502static inline bool ixgbe_cache_ring_rss(struct ixgbe_adapter *adapter)
4503{
4504 int i;
4505
4506 if (!(adapter->flags & IXGBE_FLAG_RSS_ENABLED))
4507 return false;
4508
4509 for (i = 0; i < adapter->num_rx_queues; i++)
4510 adapter->rx_ring[i]->reg_idx = i;
4511 for (i = 0; i < adapter->num_tx_queues; i++)
4512 adapter->tx_ring[i]->reg_idx = i;
4513
4514 return true;
4515}
4516
4517#ifdef CONFIG_IXGBE_DCB
4518
4519/* ixgbe_get_first_reg_idx - Return first register index associated with ring */
4520static void ixgbe_get_first_reg_idx(struct ixgbe_adapter *adapter, u8 tc,
4521 unsigned int *tx, unsigned int *rx)
4522{
4523 struct net_device *dev = adapter->netdev;
4524 struct ixgbe_hw *hw = &adapter->hw;
4525 u8 num_tcs = netdev_get_num_tc(dev);
4526
4527 *tx = 0;
4528 *rx = 0;
4529
4530 switch (hw->mac.type) {
4531 case ixgbe_mac_82598EB:
4532 *tx = tc << 2;
4533 *rx = tc << 3;
4534 break;
4535 case ixgbe_mac_82599EB:
4536 case ixgbe_mac_X540:
4537 if (num_tcs == 8) {
4538 if (tc < 3) {
4539 *tx = tc << 5;
4540 *rx = tc << 4;
4541 } else if (tc < 5) {
4542 *tx = ((tc + 2) << 4);
4543 *rx = tc << 4;
4544 } else if (tc < num_tcs) {
4545 *tx = ((tc + 8) << 3);
4546 *rx = tc << 4;
4547 }
4548 } else if (num_tcs == 4) {
4549 *rx = tc << 5;
4550 switch (tc) {
4551 case 0:
4552 *tx = 0;
4553 break;
4554 case 1:
4555 *tx = 64;
4556 break;
4557 case 2:
4558 *tx = 96;
4559 break;
4560 case 3:
4561 *tx = 112;
4562 break;
4563 default:
4564 break;
4565 }
4566 }
4567 break;
4568 default:
4569 break;
4570 }
4571}
4572
4573/**
4574 * ixgbe_cache_ring_dcb - Descriptor ring to register mapping for DCB
4575 * @adapter: board private structure to initialize
4576 *
4577 * Cache the descriptor ring offsets for DCB to the assigned rings.
4578 *
4579 **/
4580static inline bool ixgbe_cache_ring_dcb(struct ixgbe_adapter *adapter)
4581{
4582 struct net_device *dev = adapter->netdev;
4583 int i, j, k;
4584 u8 num_tcs = netdev_get_num_tc(dev);
4585
4586 if (!num_tcs)
4587 return false;
4588
4589 for (i = 0, k = 0; i < num_tcs; i++) {
4590 unsigned int tx_s, rx_s;
4591 u16 count = dev->tc_to_txq[i].count;
4592
4593 ixgbe_get_first_reg_idx(adapter, i, &tx_s, &rx_s);
4594 for (j = 0; j < count; j++, k++) {
4595 adapter->tx_ring[k]->reg_idx = tx_s + j;
4596 adapter->rx_ring[k]->reg_idx = rx_s + j;
4597 adapter->tx_ring[k]->dcb_tc = i;
4598 adapter->rx_ring[k]->dcb_tc = i;
4599 }
4600 }
4601
4602 return true;
4603}
4604#endif
4605
4606/**
4607 * ixgbe_cache_ring_fdir - Descriptor ring to register mapping for Flow Director
4608 * @adapter: board private structure to initialize
4609 *
4610 * Cache the descriptor ring offsets for Flow Director to the assigned rings.
4611 *
4612 **/
4613static inline bool ixgbe_cache_ring_fdir(struct ixgbe_adapter *adapter)
4614{
4615 int i;
4616 bool ret = false;
4617
4618 if ((adapter->flags & IXGBE_FLAG_RSS_ENABLED) &&
4619 (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE)) {
4620 for (i = 0; i < adapter->num_rx_queues; i++)
4621 adapter->rx_ring[i]->reg_idx = i;
4622 for (i = 0; i < adapter->num_tx_queues; i++)
4623 adapter->tx_ring[i]->reg_idx = i;
4624 ret = true;
4625 }
4626
4627 return ret;
4628}
4629
4630#ifdef IXGBE_FCOE
4631/**
4632 * ixgbe_cache_ring_fcoe - Descriptor ring to register mapping for the FCoE
4633 * @adapter: board private structure to initialize
4634 *
4635 * Cache the descriptor ring offsets for FCoE mode to the assigned rings.
4636 *
4637 */
4638static inline bool ixgbe_cache_ring_fcoe(struct ixgbe_adapter *adapter)
4639{
4640 struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_FCOE];
4641 int i;
4642 u8 fcoe_rx_i = 0, fcoe_tx_i = 0;
4643
4644 if (!(adapter->flags & IXGBE_FLAG_FCOE_ENABLED))
4645 return false;
4646
4647 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
4648 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE)
4649 ixgbe_cache_ring_fdir(adapter);
4650 else
4651 ixgbe_cache_ring_rss(adapter);
4652
4653 fcoe_rx_i = f->mask;
4654 fcoe_tx_i = f->mask;
4655 }
4656 for (i = 0; i < f->indices; i++, fcoe_rx_i++, fcoe_tx_i++) {
4657 adapter->rx_ring[f->mask + i]->reg_idx = fcoe_rx_i;
4658 adapter->tx_ring[f->mask + i]->reg_idx = fcoe_tx_i;
4659 }
4660 return true;
4661}
4662
4663#endif /* IXGBE_FCOE */
4664/**
4665 * ixgbe_cache_ring_sriov - Descriptor ring to register mapping for sriov
4666 * @adapter: board private structure to initialize
4667 *
4668 * SR-IOV doesn't use any descriptor rings but changes the default if
4669 * no other mapping is used.
4670 *
4671 */
4672static inline bool ixgbe_cache_ring_sriov(struct ixgbe_adapter *adapter)
4673{
4674 adapter->rx_ring[0]->reg_idx = adapter->num_vfs * 2;
4675 adapter->tx_ring[0]->reg_idx = adapter->num_vfs * 2;
4676 if (adapter->num_vfs)
4677 return true;
4678 else
4679 return false;
4680}
4681
4682/**
4683 * ixgbe_cache_ring_register - Descriptor ring to register mapping
4684 * @adapter: board private structure to initialize
4685 *
4686 * Once we know the feature-set enabled for the device, we'll cache
4687 * the register offset the descriptor ring is assigned to.
4688 *
4689 * Note, the order the various feature calls is important. It must start with
4690 * the "most" features enabled at the same time, then trickle down to the
4691 * least amount of features turned on at once.
4692 **/
4693static void ixgbe_cache_ring_register(struct ixgbe_adapter *adapter)
4694{
4695 /* start with default case */
4696 adapter->rx_ring[0]->reg_idx = 0;
4697 adapter->tx_ring[0]->reg_idx = 0;
4698
4699 if (ixgbe_cache_ring_sriov(adapter))
4700 return;
4701
4702#ifdef CONFIG_IXGBE_DCB
4703 if (ixgbe_cache_ring_dcb(adapter))
4704 return;
4705#endif
4706
4707#ifdef IXGBE_FCOE
4708 if (ixgbe_cache_ring_fcoe(adapter))
4709 return;
4710#endif /* IXGBE_FCOE */
4711
4712 if (ixgbe_cache_ring_fdir(adapter))
4713 return;
4714
4715 if (ixgbe_cache_ring_rss(adapter))
4716 return;
4717}
4718
4719/**
4720 * ixgbe_alloc_queues - Allocate memory for all rings
4721 * @adapter: board private structure to initialize
4722 *
4723 * We allocate one ring per queue at run-time since we don't know the
4724 * number of queues at compile-time. The polling_netdev array is
4725 * intended for Multiqueue, but should work fine with a single queue.
4726 **/
4727static int ixgbe_alloc_queues(struct ixgbe_adapter *adapter)
4728{
4729 int rx = 0, tx = 0, nid = adapter->node;
4730
4731 if (nid < 0 || !node_online(nid))
4732 nid = first_online_node;
4733
4734 for (; tx < adapter->num_tx_queues; tx++) {
4735 struct ixgbe_ring *ring;
4736
4737 ring = kzalloc_node(sizeof(*ring), GFP_KERNEL, nid);
4738 if (!ring)
4739 ring = kzalloc(sizeof(*ring), GFP_KERNEL);
4740 if (!ring)
4741 goto err_allocation;
4742 ring->count = adapter->tx_ring_count;
4743 ring->queue_index = tx;
4744 ring->numa_node = nid;
4745 ring->dev = &adapter->pdev->dev;
4746 ring->netdev = adapter->netdev;
4747
4748 adapter->tx_ring[tx] = ring;
4749 }
4750
4751 for (; rx < adapter->num_rx_queues; rx++) {
4752 struct ixgbe_ring *ring;
4753
4754 ring = kzalloc_node(sizeof(*ring), GFP_KERNEL, nid);
4755 if (!ring)
4756 ring = kzalloc(sizeof(*ring), GFP_KERNEL);
4757 if (!ring)
4758 goto err_allocation;
4759 ring->count = adapter->rx_ring_count;
4760 ring->queue_index = rx;
4761 ring->numa_node = nid;
4762 ring->dev = &adapter->pdev->dev;
4763 ring->netdev = adapter->netdev;
4764
4765 adapter->rx_ring[rx] = ring;
4766 }
4767
4768 ixgbe_cache_ring_register(adapter);
4769
4770 return 0;
4771
4772err_allocation:
4773 while (tx)
4774 kfree(adapter->tx_ring[--tx]);
4775
4776 while (rx)
4777 kfree(adapter->rx_ring[--rx]);
4778 return -ENOMEM;
4779}
4780
4781/**
4782 * ixgbe_set_interrupt_capability - set MSI-X or MSI if supported
4783 * @adapter: board private structure to initialize
4784 *
4785 * Attempt to configure the interrupts using the best available
4786 * capabilities of the hardware and the kernel.
4787 **/
4788static int ixgbe_set_interrupt_capability(struct ixgbe_adapter *adapter)
4789{
4790 struct ixgbe_hw *hw = &adapter->hw;
4791 int err = 0;
4792 int vector, v_budget;
4793
4794 /*
4795 * It's easy to be greedy for MSI-X vectors, but it really
4796 * doesn't do us much good if we have a lot more vectors
4797 * than CPU's. So let's be conservative and only ask for
4798 * (roughly) the same number of vectors as there are CPU's.
4799 */
4800 v_budget = min(adapter->num_rx_queues + adapter->num_tx_queues,
4801 (int)num_online_cpus()) + NON_Q_VECTORS;
4802
4803 /*
4804 * At the same time, hardware can only support a maximum of
4805 * hw.mac->max_msix_vectors vectors. With features
4806 * such as RSS and VMDq, we can easily surpass the number of Rx and Tx
4807 * descriptor queues supported by our device. Thus, we cap it off in
4808 * those rare cases where the cpu count also exceeds our vector limit.
4809 */
4810 v_budget = min(v_budget, (int)hw->mac.max_msix_vectors);
4811
4812 /* A failure in MSI-X entry allocation isn't fatal, but it does
4813 * mean we disable MSI-X capabilities of the adapter. */
4814 adapter->msix_entries = kcalloc(v_budget,
4815 sizeof(struct msix_entry), GFP_KERNEL);
4816 if (adapter->msix_entries) {
4817 for (vector = 0; vector < v_budget; vector++)
4818 adapter->msix_entries[vector].entry = vector;
4819
4820 ixgbe_acquire_msix_vectors(adapter, v_budget);
4821
4822 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
4823 goto out;
4824 }
4825
4826 adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED;
4827 adapter->flags &= ~IXGBE_FLAG_RSS_ENABLED;
4828 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
4829 e_err(probe,
4830 "ATR is not supported while multiple "
4831 "queues are disabled. Disabling Flow Director\n");
4832 }
4833 adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
4834 adapter->atr_sample_rate = 0;
4835 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
4836 ixgbe_disable_sriov(adapter);
4837
4838 err = ixgbe_set_num_queues(adapter);
4839 if (err)
4840 return err;
4841
4842 err = pci_enable_msi(adapter->pdev);
4843 if (!err) {
4844 adapter->flags |= IXGBE_FLAG_MSI_ENABLED;
4845 } else {
4846 netif_printk(adapter, hw, KERN_DEBUG, adapter->netdev,
4847 "Unable to allocate MSI interrupt, "
4848 "falling back to legacy. Error: %d\n", err);
4849 /* reset err */
4850 err = 0;
4851 }
4852
4853out:
4854 return err;
4855}
4856
4857/**
4858 * ixgbe_alloc_q_vectors - Allocate memory for interrupt vectors
4859 * @adapter: board private structure to initialize
4860 *
4861 * We allocate one q_vector per queue interrupt. If allocation fails we
4862 * return -ENOMEM.
4863 **/
4864static int ixgbe_alloc_q_vectors(struct ixgbe_adapter *adapter)
4865{
4866 int q_idx, num_q_vectors;
4867 struct ixgbe_q_vector *q_vector;
4868 int (*poll)(struct napi_struct *, int);
4869
4870 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
4871 num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
4872 poll = &ixgbe_clean_rxtx_many;
4873 } else {
4874 num_q_vectors = 1;
4875 poll = &ixgbe_poll;
4876 }
4877
4878 for (q_idx = 0; q_idx < num_q_vectors; q_idx++) {
4879 q_vector = kzalloc_node(sizeof(struct ixgbe_q_vector),
4880 GFP_KERNEL, adapter->node);
4881 if (!q_vector)
4882 q_vector = kzalloc(sizeof(struct ixgbe_q_vector),
4883 GFP_KERNEL);
4884 if (!q_vector)
4885 goto err_out;
4886 q_vector->adapter = adapter;
4887 if (q_vector->tx.count && !q_vector->rx.count)
4888 q_vector->eitr = adapter->tx_eitr_param;
4889 else
4890 q_vector->eitr = adapter->rx_eitr_param;
4891 q_vector->v_idx = q_idx;
4892 netif_napi_add(adapter->netdev, &q_vector->napi, (*poll), 64);
4893 adapter->q_vector[q_idx] = q_vector;
4894 }
4895
4896 return 0;
4897
4898err_out:
4899 while (q_idx) {
4900 q_idx--;
4901 q_vector = adapter->q_vector[q_idx];
4902 netif_napi_del(&q_vector->napi);
4903 kfree(q_vector);
4904 adapter->q_vector[q_idx] = NULL;
4905 }
4906 return -ENOMEM;
4907}
4908
4909/**
4910 * ixgbe_free_q_vectors - Free memory allocated for interrupt vectors
4911 * @adapter: board private structure to initialize
4912 *
4913 * This function frees the memory allocated to the q_vectors. In addition if
4914 * NAPI is enabled it will delete any references to the NAPI struct prior
4915 * to freeing the q_vector.
4916 **/
4917static void ixgbe_free_q_vectors(struct ixgbe_adapter *adapter)
4918{
4919 int q_idx, num_q_vectors;
4920
4921 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
4922 num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
4923 else
4924 num_q_vectors = 1;
4925
4926 for (q_idx = 0; q_idx < num_q_vectors; q_idx++) {
4927 struct ixgbe_q_vector *q_vector = adapter->q_vector[q_idx];
4928 adapter->q_vector[q_idx] = NULL;
4929 netif_napi_del(&q_vector->napi);
4930 kfree(q_vector);
4931 }
4932}
4933
4934static void ixgbe_reset_interrupt_capability(struct ixgbe_adapter *adapter)
4935{
4936 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
4937 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
4938 pci_disable_msix(adapter->pdev);
4939 kfree(adapter->msix_entries);
4940 adapter->msix_entries = NULL;
4941 } else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED) {
4942 adapter->flags &= ~IXGBE_FLAG_MSI_ENABLED;
4943 pci_disable_msi(adapter->pdev);
4944 }
4945}
4946
4947/**
4948 * ixgbe_init_interrupt_scheme - Determine proper interrupt scheme
4949 * @adapter: board private structure to initialize
4950 *
4951 * We determine which interrupt scheme to use based on...
4952 * - Kernel support (MSI, MSI-X)
4953 * - which can be user-defined (via MODULE_PARAM)
4954 * - Hardware queue count (num_*_queues)
4955 * - defined by miscellaneous hardware support/features (RSS, etc.)
4956 **/
4957int ixgbe_init_interrupt_scheme(struct ixgbe_adapter *adapter)
4958{
4959 int err;
4960
4961 /* Number of supported queues */
4962 err = ixgbe_set_num_queues(adapter);
4963 if (err)
4964 return err;
4965
4966 err = ixgbe_set_interrupt_capability(adapter);
4967 if (err) {
4968 e_dev_err("Unable to setup interrupt capabilities\n");
4969 goto err_set_interrupt;
4970 }
4971
4972 err = ixgbe_alloc_q_vectors(adapter);
4973 if (err) {
4974 e_dev_err("Unable to allocate memory for queue vectors\n");
4975 goto err_alloc_q_vectors;
4976 }
4977
4978 err = ixgbe_alloc_queues(adapter);
4979 if (err) {
4980 e_dev_err("Unable to allocate memory for queues\n");
4981 goto err_alloc_queues;
4982 }
4983
4984 e_dev_info("Multiqueue %s: Rx Queue count = %u, Tx Queue count = %u\n",
4985 (adapter->num_rx_queues > 1) ? "Enabled" : "Disabled",
4986 adapter->num_rx_queues, adapter->num_tx_queues);
4987
4988 set_bit(__IXGBE_DOWN, &adapter->state);
4989
4990 return 0;
4991
4992err_alloc_queues:
4993 ixgbe_free_q_vectors(adapter);
4994err_alloc_q_vectors:
4995 ixgbe_reset_interrupt_capability(adapter);
4996err_set_interrupt:
4997 return err;
4998}
4999
5000/**
5001 * ixgbe_clear_interrupt_scheme - Clear the current interrupt scheme settings
5002 * @adapter: board private structure to clear interrupt scheme on
5003 *
5004 * We go through and clear interrupt specific resources and reset the structure
5005 * to pre-load conditions
5006 **/
5007void ixgbe_clear_interrupt_scheme(struct ixgbe_adapter *adapter)
5008{
5009 int i;
5010
5011 for (i = 0; i < adapter->num_tx_queues; i++) {
5012 kfree(adapter->tx_ring[i]);
5013 adapter->tx_ring[i] = NULL;
5014 }
5015 for (i = 0; i < adapter->num_rx_queues; i++) {
5016 struct ixgbe_ring *ring = adapter->rx_ring[i];
5017
5018 /* ixgbe_get_stats64() might access this ring, we must wait
5019 * a grace period before freeing it.
5020 */
5021 kfree_rcu(ring, rcu);
5022 adapter->rx_ring[i] = NULL;
5023 }
5024
5025 adapter->num_tx_queues = 0;
5026 adapter->num_rx_queues = 0;
5027
5028 ixgbe_free_q_vectors(adapter);
5029 ixgbe_reset_interrupt_capability(adapter);
5030}
5031
5032/**
5033 * ixgbe_sw_init - Initialize general software structures (struct ixgbe_adapter)
5034 * @adapter: board private structure to initialize
5035 *
5036 * ixgbe_sw_init initializes the Adapter private data structure.
5037 * Fields are initialized based on PCI device information and
5038 * OS network device settings (MTU size).
5039 **/
5040static int __devinit ixgbe_sw_init(struct ixgbe_adapter *adapter)
5041{
5042 struct ixgbe_hw *hw = &adapter->hw;
5043 struct pci_dev *pdev = adapter->pdev;
5044 struct net_device *dev = adapter->netdev;
5045 unsigned int rss;
5046#ifdef CONFIG_IXGBE_DCB
5047 int j;
5048 struct tc_configuration *tc;
5049#endif
5050 int max_frame = dev->mtu + ETH_HLEN + ETH_FCS_LEN;
5051
5052 /* PCI config space info */
5053
5054 hw->vendor_id = pdev->vendor;
5055 hw->device_id = pdev->device;
5056 hw->revision_id = pdev->revision;
5057 hw->subsystem_vendor_id = pdev->subsystem_vendor;
5058 hw->subsystem_device_id = pdev->subsystem_device;
5059
5060 /* Set capability flags */
5061 rss = min(IXGBE_MAX_RSS_INDICES, (int)num_online_cpus());
5062 adapter->ring_feature[RING_F_RSS].indices = rss;
5063 adapter->flags |= IXGBE_FLAG_RSS_ENABLED;
5064 switch (hw->mac.type) {
5065 case ixgbe_mac_82598EB:
5066 if (hw->device_id == IXGBE_DEV_ID_82598AT)
5067 adapter->flags |= IXGBE_FLAG_FAN_FAIL_CAPABLE;
5068 adapter->max_msix_q_vectors = MAX_MSIX_Q_VECTORS_82598;
5069 break;
5070 case ixgbe_mac_82599EB:
5071 case ixgbe_mac_X540:
5072 adapter->max_msix_q_vectors = MAX_MSIX_Q_VECTORS_82599;
5073 adapter->flags2 |= IXGBE_FLAG2_RSC_CAPABLE;
5074 adapter->flags2 |= IXGBE_FLAG2_RSC_ENABLED;
5075 if (hw->device_id == IXGBE_DEV_ID_82599_T3_LOM)
5076 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE;
5077 /* Flow Director hash filters enabled */
5078 adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE;
5079 adapter->atr_sample_rate = 20;
5080 adapter->ring_feature[RING_F_FDIR].indices =
5081 IXGBE_MAX_FDIR_INDICES;
5082 adapter->fdir_pballoc = IXGBE_FDIR_PBALLOC_64K;
5083#ifdef IXGBE_FCOE
5084 adapter->flags |= IXGBE_FLAG_FCOE_CAPABLE;
5085 adapter->flags &= ~IXGBE_FLAG_FCOE_ENABLED;
5086 adapter->ring_feature[RING_F_FCOE].indices = 0;
5087#ifdef CONFIG_IXGBE_DCB
5088 /* Default traffic class to use for FCoE */
5089 adapter->fcoe.up = IXGBE_FCOE_DEFTC;
5090#endif
5091#endif /* IXGBE_FCOE */
5092 break;
5093 default:
5094 break;
5095 }
5096
5097 /* n-tuple support exists, always init our spinlock */
5098 spin_lock_init(&adapter->fdir_perfect_lock);
5099
5100#ifdef CONFIG_IXGBE_DCB
5101 /* Configure DCB traffic classes */
5102 for (j = 0; j < MAX_TRAFFIC_CLASS; j++) {
5103 tc = &adapter->dcb_cfg.tc_config[j];
5104 tc->path[DCB_TX_CONFIG].bwg_id = 0;
5105 tc->path[DCB_TX_CONFIG].bwg_percent = 12 + (j & 1);
5106 tc->path[DCB_RX_CONFIG].bwg_id = 0;
5107 tc->path[DCB_RX_CONFIG].bwg_percent = 12 + (j & 1);
5108 tc->dcb_pfc = pfc_disabled;
5109 }
5110 adapter->dcb_cfg.bw_percentage[DCB_TX_CONFIG][0] = 100;
5111 adapter->dcb_cfg.bw_percentage[DCB_RX_CONFIG][0] = 100;
5112 adapter->dcb_cfg.pfc_mode_enable = false;
5113 adapter->dcb_set_bitmap = 0x00;
5114 adapter->dcbx_cap = DCB_CAP_DCBX_HOST | DCB_CAP_DCBX_VER_CEE;
5115 ixgbe_copy_dcb_cfg(&adapter->dcb_cfg, &adapter->temp_dcb_cfg,
5116 MAX_TRAFFIC_CLASS);
5117
5118#endif
5119
5120 /* default flow control settings */
5121 hw->fc.requested_mode = ixgbe_fc_full;
5122 hw->fc.current_mode = ixgbe_fc_full; /* init for ethtool output */
5123#ifdef CONFIG_DCB
5124 adapter->last_lfc_mode = hw->fc.current_mode;
5125#endif
5126 hw->fc.high_water = FC_HIGH_WATER(max_frame);
5127 hw->fc.low_water = FC_LOW_WATER(max_frame);
5128 hw->fc.pause_time = IXGBE_DEFAULT_FCPAUSE;
5129 hw->fc.send_xon = true;
5130 hw->fc.disable_fc_autoneg = false;
5131
5132 /* enable itr by default in dynamic mode */
5133 adapter->rx_itr_setting = 1;
5134 adapter->rx_eitr_param = 20000;
5135 adapter->tx_itr_setting = 1;
5136 adapter->tx_eitr_param = 10000;
5137
5138 /* set defaults for eitr in MegaBytes */
5139 adapter->eitr_low = 10;
5140 adapter->eitr_high = 20;
5141
5142 /* set default ring sizes */
5143 adapter->tx_ring_count = IXGBE_DEFAULT_TXD;
5144 adapter->rx_ring_count = IXGBE_DEFAULT_RXD;
5145
5146 /* set default work limits */
5147 adapter->tx_work_limit = adapter->tx_ring_count;
5148
5149 /* initialize eeprom parameters */
5150 if (ixgbe_init_eeprom_params_generic(hw)) {
5151 e_dev_err("EEPROM initialization failed\n");
5152 return -EIO;
5153 }
5154
5155 /* enable rx csum by default */
5156 adapter->flags |= IXGBE_FLAG_RX_CSUM_ENABLED;
5157
5158 /* get assigned NUMA node */
5159 adapter->node = dev_to_node(&pdev->dev);
5160
5161 set_bit(__IXGBE_DOWN, &adapter->state);
5162
5163 return 0;
5164}
5165
5166/**
5167 * ixgbe_setup_tx_resources - allocate Tx resources (Descriptors)
5168 * @tx_ring: tx descriptor ring (for a specific queue) to setup
5169 *
5170 * Return 0 on success, negative on failure
5171 **/
5172int ixgbe_setup_tx_resources(struct ixgbe_ring *tx_ring)
5173{
5174 struct device *dev = tx_ring->dev;
5175 int size;
5176
5177 size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
5178 tx_ring->tx_buffer_info = vzalloc_node(size, tx_ring->numa_node);
5179 if (!tx_ring->tx_buffer_info)
5180 tx_ring->tx_buffer_info = vzalloc(size);
5181 if (!tx_ring->tx_buffer_info)
5182 goto err;
5183
5184 /* round up to nearest 4K */
5185 tx_ring->size = tx_ring->count * sizeof(union ixgbe_adv_tx_desc);
5186 tx_ring->size = ALIGN(tx_ring->size, 4096);
5187
5188 tx_ring->desc = dma_alloc_coherent(dev, tx_ring->size,
5189 &tx_ring->dma, GFP_KERNEL);
5190 if (!tx_ring->desc)
5191 goto err;
5192
5193 tx_ring->next_to_use = 0;
5194 tx_ring->next_to_clean = 0;
5195 return 0;
5196
5197err:
5198 vfree(tx_ring->tx_buffer_info);
5199 tx_ring->tx_buffer_info = NULL;
5200 dev_err(dev, "Unable to allocate memory for the Tx descriptor ring\n");
5201 return -ENOMEM;
5202}
5203
5204/**
5205 * ixgbe_setup_all_tx_resources - allocate all queues Tx resources
5206 * @adapter: board private structure
5207 *
5208 * If this function returns with an error, then it's possible one or
5209 * more of the rings is populated (while the rest are not). It is the
5210 * callers duty to clean those orphaned rings.
5211 *
5212 * Return 0 on success, negative on failure
5213 **/
5214static int ixgbe_setup_all_tx_resources(struct ixgbe_adapter *adapter)
5215{
5216 int i, err = 0;
5217
5218 for (i = 0; i < adapter->num_tx_queues; i++) {
5219 err = ixgbe_setup_tx_resources(adapter->tx_ring[i]);
5220 if (!err)
5221 continue;
5222 e_err(probe, "Allocation for Tx Queue %u failed\n", i);
5223 break;
5224 }
5225
5226 return err;
5227}
5228
5229/**
5230 * ixgbe_setup_rx_resources - allocate Rx resources (Descriptors)
5231 * @rx_ring: rx descriptor ring (for a specific queue) to setup
5232 *
5233 * Returns 0 on success, negative on failure
5234 **/
5235int ixgbe_setup_rx_resources(struct ixgbe_ring *rx_ring)
5236{
5237 struct device *dev = rx_ring->dev;
5238 int size;
5239
5240 size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
5241 rx_ring->rx_buffer_info = vzalloc_node(size, rx_ring->numa_node);
5242 if (!rx_ring->rx_buffer_info)
5243 rx_ring->rx_buffer_info = vzalloc(size);
5244 if (!rx_ring->rx_buffer_info)
5245 goto err;
5246
5247 /* Round up to nearest 4K */
5248 rx_ring->size = rx_ring->count * sizeof(union ixgbe_adv_rx_desc);
5249 rx_ring->size = ALIGN(rx_ring->size, 4096);
5250
5251 rx_ring->desc = dma_alloc_coherent(dev, rx_ring->size,
5252 &rx_ring->dma, GFP_KERNEL);
5253
5254 if (!rx_ring->desc)
5255 goto err;
5256
5257 rx_ring->next_to_clean = 0;
5258 rx_ring->next_to_use = 0;
5259
5260 return 0;
5261err:
5262 vfree(rx_ring->rx_buffer_info);
5263 rx_ring->rx_buffer_info = NULL;
5264 dev_err(dev, "Unable to allocate memory for the Rx descriptor ring\n");
5265 return -ENOMEM;
5266}
5267
5268/**
5269 * ixgbe_setup_all_rx_resources - allocate all queues Rx resources
5270 * @adapter: board private structure
5271 *
5272 * If this function returns with an error, then it's possible one or
5273 * more of the rings is populated (while the rest are not). It is the
5274 * callers duty to clean those orphaned rings.
5275 *
5276 * Return 0 on success, negative on failure
5277 **/
5278static int ixgbe_setup_all_rx_resources(struct ixgbe_adapter *adapter)
5279{
5280 int i, err = 0;
5281
5282 for (i = 0; i < adapter->num_rx_queues; i++) {
5283 err = ixgbe_setup_rx_resources(adapter->rx_ring[i]);
5284 if (!err)
5285 continue;
5286 e_err(probe, "Allocation for Rx Queue %u failed\n", i);
5287 break;
5288 }
5289
5290 return err;
5291}
5292
5293/**
5294 * ixgbe_free_tx_resources - Free Tx Resources per Queue
5295 * @tx_ring: Tx descriptor ring for a specific queue
5296 *
5297 * Free all transmit software resources
5298 **/
5299void ixgbe_free_tx_resources(struct ixgbe_ring *tx_ring)
5300{
5301 ixgbe_clean_tx_ring(tx_ring);
5302
5303 vfree(tx_ring->tx_buffer_info);
5304 tx_ring->tx_buffer_info = NULL;
5305
5306 /* if not set, then don't free */
5307 if (!tx_ring->desc)
5308 return;
5309
5310 dma_free_coherent(tx_ring->dev, tx_ring->size,
5311 tx_ring->desc, tx_ring->dma);
5312
5313 tx_ring->desc = NULL;
5314}
5315
5316/**
5317 * ixgbe_free_all_tx_resources - Free Tx Resources for All Queues
5318 * @adapter: board private structure
5319 *
5320 * Free all transmit software resources
5321 **/
5322static void ixgbe_free_all_tx_resources(struct ixgbe_adapter *adapter)
5323{
5324 int i;
5325
5326 for (i = 0; i < adapter->num_tx_queues; i++)
5327 if (adapter->tx_ring[i]->desc)
5328 ixgbe_free_tx_resources(adapter->tx_ring[i]);
5329}
5330
5331/**
5332 * ixgbe_free_rx_resources - Free Rx Resources
5333 * @rx_ring: ring to clean the resources from
5334 *
5335 * Free all receive software resources
5336 **/
5337void ixgbe_free_rx_resources(struct ixgbe_ring *rx_ring)
5338{
5339 ixgbe_clean_rx_ring(rx_ring);
5340
5341 vfree(rx_ring->rx_buffer_info);
5342 rx_ring->rx_buffer_info = NULL;
5343
5344 /* if not set, then don't free */
5345 if (!rx_ring->desc)
5346 return;
5347
5348 dma_free_coherent(rx_ring->dev, rx_ring->size,
5349 rx_ring->desc, rx_ring->dma);
5350
5351 rx_ring->desc = NULL;
5352}
5353
5354/**
5355 * ixgbe_free_all_rx_resources - Free Rx Resources for All Queues
5356 * @adapter: board private structure
5357 *
5358 * Free all receive software resources
5359 **/
5360static void ixgbe_free_all_rx_resources(struct ixgbe_adapter *adapter)
5361{
5362 int i;
5363
5364 for (i = 0; i < adapter->num_rx_queues; i++)
5365 if (adapter->rx_ring[i]->desc)
5366 ixgbe_free_rx_resources(adapter->rx_ring[i]);
5367}
5368
5369/**
5370 * ixgbe_change_mtu - Change the Maximum Transfer Unit
5371 * @netdev: network interface device structure
5372 * @new_mtu: new value for maximum frame size
5373 *
5374 * Returns 0 on success, negative on failure
5375 **/
5376static int ixgbe_change_mtu(struct net_device *netdev, int new_mtu)
5377{
5378 struct ixgbe_adapter *adapter = netdev_priv(netdev);
5379 struct ixgbe_hw *hw = &adapter->hw;
5380 int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN;
5381
5382 /* MTU < 68 is an error and causes problems on some kernels */
5383 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED &&
5384 hw->mac.type != ixgbe_mac_X540) {
5385 if ((new_mtu < 68) || (max_frame > MAXIMUM_ETHERNET_VLAN_SIZE))
5386 return -EINVAL;
5387 } else {
5388 if ((new_mtu < 68) || (max_frame > IXGBE_MAX_JUMBO_FRAME_SIZE))
5389 return -EINVAL;
5390 }
5391
5392 e_info(probe, "changing MTU from %d to %d\n", netdev->mtu, new_mtu);
5393 /* must set new MTU before calling down or up */
5394 netdev->mtu = new_mtu;
5395
5396 hw->fc.high_water = FC_HIGH_WATER(max_frame);
5397 hw->fc.low_water = FC_LOW_WATER(max_frame);
5398
5399 if (netif_running(netdev))
5400 ixgbe_reinit_locked(adapter);
5401
5402 return 0;
5403}
5404
5405/**
5406 * ixgbe_open - Called when a network interface is made active
5407 * @netdev: network interface device structure
5408 *
5409 * Returns 0 on success, negative value on failure
5410 *
5411 * The open entry point is called when a network interface is made
5412 * active by the system (IFF_UP). At this point all resources needed
5413 * for transmit and receive operations are allocated, the interrupt
5414 * handler is registered with the OS, the watchdog timer is started,
5415 * and the stack is notified that the interface is ready.
5416 **/
5417static int ixgbe_open(struct net_device *netdev)
5418{
5419 struct ixgbe_adapter *adapter = netdev_priv(netdev);
5420 int err;
5421
5422 /* disallow open during test */
5423 if (test_bit(__IXGBE_TESTING, &adapter->state))
5424 return -EBUSY;
5425
5426 netif_carrier_off(netdev);
5427
5428 /* allocate transmit descriptors */
5429 err = ixgbe_setup_all_tx_resources(adapter);
5430 if (err)
5431 goto err_setup_tx;
5432
5433 /* allocate receive descriptors */
5434 err = ixgbe_setup_all_rx_resources(adapter);
5435 if (err)
5436 goto err_setup_rx;
5437
5438 ixgbe_configure(adapter);
5439
5440 err = ixgbe_request_irq(adapter);
5441 if (err)
5442 goto err_req_irq;
5443
5444 err = ixgbe_up_complete(adapter);
5445 if (err)
5446 goto err_up;
5447
5448 netif_tx_start_all_queues(netdev);
5449
5450 return 0;
5451
5452err_up:
5453 ixgbe_release_hw_control(adapter);
5454 ixgbe_free_irq(adapter);
5455err_req_irq:
5456err_setup_rx:
5457 ixgbe_free_all_rx_resources(adapter);
5458err_setup_tx:
5459 ixgbe_free_all_tx_resources(adapter);
5460 ixgbe_reset(adapter);
5461
5462 return err;
5463}
5464
5465/**
5466 * ixgbe_close - Disables a network interface
5467 * @netdev: network interface device structure
5468 *
5469 * Returns 0, this is not allowed to fail
5470 *
5471 * The close entry point is called when an interface is de-activated
5472 * by the OS. The hardware is still under the drivers control, but
5473 * needs to be disabled. A global MAC reset is issued to stop the
5474 * hardware, and all transmit and receive resources are freed.
5475 **/
5476static int ixgbe_close(struct net_device *netdev)
5477{
5478 struct ixgbe_adapter *adapter = netdev_priv(netdev);
5479
5480 ixgbe_down(adapter);
5481 ixgbe_free_irq(adapter);
5482
5483 ixgbe_fdir_filter_exit(adapter);
5484
5485 ixgbe_free_all_tx_resources(adapter);
5486 ixgbe_free_all_rx_resources(adapter);
5487
5488 ixgbe_release_hw_control(adapter);
5489
5490 return 0;
5491}
5492
5493#ifdef CONFIG_PM
5494static int ixgbe_resume(struct pci_dev *pdev)
5495{
5496 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
5497 struct net_device *netdev = adapter->netdev;
5498 u32 err;
5499
5500 pci_set_power_state(pdev, PCI_D0);
5501 pci_restore_state(pdev);
5502 /*
5503 * pci_restore_state clears dev->state_saved so call
5504 * pci_save_state to restore it.
5505 */
5506 pci_save_state(pdev);
5507
5508 err = pci_enable_device_mem(pdev);
5509 if (err) {
5510 e_dev_err("Cannot enable PCI device from suspend\n");
5511 return err;
5512 }
5513 pci_set_master(pdev);
5514
5515 pci_wake_from_d3(pdev, false);
5516
5517 err = ixgbe_init_interrupt_scheme(adapter);
5518 if (err) {
5519 e_dev_err("Cannot initialize interrupts for device\n");
5520 return err;
5521 }
5522
5523 ixgbe_reset(adapter);
5524
5525 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
5526
5527 if (netif_running(netdev)) {
5528 err = ixgbe_open(netdev);
5529 if (err)
5530 return err;
5531 }
5532
5533 netif_device_attach(netdev);
5534
5535 return 0;
5536}
5537#endif /* CONFIG_PM */
5538
5539static int __ixgbe_shutdown(struct pci_dev *pdev, bool *enable_wake)
5540{
5541 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
5542 struct net_device *netdev = adapter->netdev;
5543 struct ixgbe_hw *hw = &adapter->hw;
5544 u32 ctrl, fctrl;
5545 u32 wufc = adapter->wol;
5546#ifdef CONFIG_PM
5547 int retval = 0;
5548#endif
5549
5550 netif_device_detach(netdev);
5551
5552 if (netif_running(netdev)) {
5553 ixgbe_down(adapter);
5554 ixgbe_free_irq(adapter);
5555 ixgbe_free_all_tx_resources(adapter);
5556 ixgbe_free_all_rx_resources(adapter);
5557 }
5558
5559 ixgbe_clear_interrupt_scheme(adapter);
5560#ifdef CONFIG_DCB
5561 kfree(adapter->ixgbe_ieee_pfc);
5562 kfree(adapter->ixgbe_ieee_ets);
5563#endif
5564
5565#ifdef CONFIG_PM
5566 retval = pci_save_state(pdev);
5567 if (retval)
5568 return retval;
5569
5570#endif
5571 if (wufc) {
5572 ixgbe_set_rx_mode(netdev);
5573
5574 /* turn on all-multi mode if wake on multicast is enabled */
5575 if (wufc & IXGBE_WUFC_MC) {
5576 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
5577 fctrl |= IXGBE_FCTRL_MPE;
5578 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
5579 }
5580
5581 ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL);
5582 ctrl |= IXGBE_CTRL_GIO_DIS;
5583 IXGBE_WRITE_REG(hw, IXGBE_CTRL, ctrl);
5584
5585 IXGBE_WRITE_REG(hw, IXGBE_WUFC, wufc);
5586 } else {
5587 IXGBE_WRITE_REG(hw, IXGBE_WUC, 0);
5588 IXGBE_WRITE_REG(hw, IXGBE_WUFC, 0);
5589 }
5590
5591 switch (hw->mac.type) {
5592 case ixgbe_mac_82598EB:
5593 pci_wake_from_d3(pdev, false);
5594 break;
5595 case ixgbe_mac_82599EB:
5596 case ixgbe_mac_X540:
5597 pci_wake_from_d3(pdev, !!wufc);
5598 break;
5599 default:
5600 break;
5601 }
5602
5603 *enable_wake = !!wufc;
5604
5605 ixgbe_release_hw_control(adapter);
5606
5607 pci_disable_device(pdev);
5608
5609 return 0;
5610}
5611
5612#ifdef CONFIG_PM
5613static int ixgbe_suspend(struct pci_dev *pdev, pm_message_t state)
5614{
5615 int retval;
5616 bool wake;
5617
5618 retval = __ixgbe_shutdown(pdev, &wake);
5619 if (retval)
5620 return retval;
5621
5622 if (wake) {
5623 pci_prepare_to_sleep(pdev);
5624 } else {
5625 pci_wake_from_d3(pdev, false);
5626 pci_set_power_state(pdev, PCI_D3hot);
5627 }
5628
5629 return 0;
5630}
5631#endif /* CONFIG_PM */
5632
5633static void ixgbe_shutdown(struct pci_dev *pdev)
5634{
5635 bool wake;
5636
5637 __ixgbe_shutdown(pdev, &wake);
5638
5639 if (system_state == SYSTEM_POWER_OFF) {
5640 pci_wake_from_d3(pdev, wake);
5641 pci_set_power_state(pdev, PCI_D3hot);
5642 }
5643}
5644
5645/**
5646 * ixgbe_update_stats - Update the board statistics counters.
5647 * @adapter: board private structure
5648 **/
5649void ixgbe_update_stats(struct ixgbe_adapter *adapter)
5650{
5651 struct net_device *netdev = adapter->netdev;
5652 struct ixgbe_hw *hw = &adapter->hw;
5653 struct ixgbe_hw_stats *hwstats = &adapter->stats;
5654 u64 total_mpc = 0;
5655 u32 i, missed_rx = 0, mpc, bprc, lxon, lxoff, xon_off_tot;
5656 u64 non_eop_descs = 0, restart_queue = 0, tx_busy = 0;
5657 u64 alloc_rx_page_failed = 0, alloc_rx_buff_failed = 0;
5658 u64 bytes = 0, packets = 0;
5659
5660 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
5661 test_bit(__IXGBE_RESETTING, &adapter->state))
5662 return;
5663
5664 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) {
5665 u64 rsc_count = 0;
5666 u64 rsc_flush = 0;
5667 for (i = 0; i < 16; i++)
5668 adapter->hw_rx_no_dma_resources +=
5669 IXGBE_READ_REG(hw, IXGBE_QPRDC(i));
5670 for (i = 0; i < adapter->num_rx_queues; i++) {
5671 rsc_count += adapter->rx_ring[i]->rx_stats.rsc_count;
5672 rsc_flush += adapter->rx_ring[i]->rx_stats.rsc_flush;
5673 }
5674 adapter->rsc_total_count = rsc_count;
5675 adapter->rsc_total_flush = rsc_flush;
5676 }
5677
5678 for (i = 0; i < adapter->num_rx_queues; i++) {
5679 struct ixgbe_ring *rx_ring = adapter->rx_ring[i];
5680 non_eop_descs += rx_ring->rx_stats.non_eop_descs;
5681 alloc_rx_page_failed += rx_ring->rx_stats.alloc_rx_page_failed;
5682 alloc_rx_buff_failed += rx_ring->rx_stats.alloc_rx_buff_failed;
5683 bytes += rx_ring->stats.bytes;
5684 packets += rx_ring->stats.packets;
5685 }
5686 adapter->non_eop_descs = non_eop_descs;
5687 adapter->alloc_rx_page_failed = alloc_rx_page_failed;
5688 adapter->alloc_rx_buff_failed = alloc_rx_buff_failed;
5689 netdev->stats.rx_bytes = bytes;
5690 netdev->stats.rx_packets = packets;
5691
5692 bytes = 0;
5693 packets = 0;
5694 /* gather some stats to the adapter struct that are per queue */
5695 for (i = 0; i < adapter->num_tx_queues; i++) {
5696 struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
5697 restart_queue += tx_ring->tx_stats.restart_queue;
5698 tx_busy += tx_ring->tx_stats.tx_busy;
5699 bytes += tx_ring->stats.bytes;
5700 packets += tx_ring->stats.packets;
5701 }
5702 adapter->restart_queue = restart_queue;
5703 adapter->tx_busy = tx_busy;
5704 netdev->stats.tx_bytes = bytes;
5705 netdev->stats.tx_packets = packets;
5706
5707 hwstats->crcerrs += IXGBE_READ_REG(hw, IXGBE_CRCERRS);
5708 for (i = 0; i < 8; i++) {
5709 /* for packet buffers not used, the register should read 0 */
5710 mpc = IXGBE_READ_REG(hw, IXGBE_MPC(i));
5711 missed_rx += mpc;
5712 hwstats->mpc[i] += mpc;
5713 total_mpc += hwstats->mpc[i];
5714 if (hw->mac.type == ixgbe_mac_82598EB)
5715 hwstats->rnbc[i] += IXGBE_READ_REG(hw, IXGBE_RNBC(i));
5716 hwstats->qptc[i] += IXGBE_READ_REG(hw, IXGBE_QPTC(i));
5717 hwstats->qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC(i));
5718 hwstats->qprc[i] += IXGBE_READ_REG(hw, IXGBE_QPRC(i));
5719 hwstats->qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC(i));
5720 switch (hw->mac.type) {
5721 case ixgbe_mac_82598EB:
5722 hwstats->pxonrxc[i] +=
5723 IXGBE_READ_REG(hw, IXGBE_PXONRXC(i));
5724 break;
5725 case ixgbe_mac_82599EB:
5726 case ixgbe_mac_X540:
5727 hwstats->pxonrxc[i] +=
5728 IXGBE_READ_REG(hw, IXGBE_PXONRXCNT(i));
5729 break;
5730 default:
5731 break;
5732 }
5733 hwstats->pxontxc[i] += IXGBE_READ_REG(hw, IXGBE_PXONTXC(i));
5734 hwstats->pxofftxc[i] += IXGBE_READ_REG(hw, IXGBE_PXOFFTXC(i));
5735 }
5736 hwstats->gprc += IXGBE_READ_REG(hw, IXGBE_GPRC);
5737 /* work around hardware counting issue */
5738 hwstats->gprc -= missed_rx;
5739
5740 ixgbe_update_xoff_received(adapter);
5741
5742 /* 82598 hardware only has a 32 bit counter in the high register */
5743 switch (hw->mac.type) {
5744 case ixgbe_mac_82598EB:
5745 hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXC);
5746 hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCH);
5747 hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCH);
5748 hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORH);
5749 break;
5750 case ixgbe_mac_X540:
5751 /* OS2BMC stats are X540 only*/
5752 hwstats->o2bgptc += IXGBE_READ_REG(hw, IXGBE_O2BGPTC);
5753 hwstats->o2bspc += IXGBE_READ_REG(hw, IXGBE_O2BSPC);
5754 hwstats->b2ospc += IXGBE_READ_REG(hw, IXGBE_B2OSPC);
5755 hwstats->b2ogprc += IXGBE_READ_REG(hw, IXGBE_B2OGPRC);
5756 case ixgbe_mac_82599EB:
5757 hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCL);
5758 IXGBE_READ_REG(hw, IXGBE_GORCH); /* to clear */
5759 hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCL);
5760 IXGBE_READ_REG(hw, IXGBE_GOTCH); /* to clear */
5761 hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORL);
5762 IXGBE_READ_REG(hw, IXGBE_TORH); /* to clear */
5763 hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXCNT);
5764 hwstats->fdirmatch += IXGBE_READ_REG(hw, IXGBE_FDIRMATCH);
5765 hwstats->fdirmiss += IXGBE_READ_REG(hw, IXGBE_FDIRMISS);
5766#ifdef IXGBE_FCOE
5767 hwstats->fccrc += IXGBE_READ_REG(hw, IXGBE_FCCRC);
5768 hwstats->fcoerpdc += IXGBE_READ_REG(hw, IXGBE_FCOERPDC);
5769 hwstats->fcoeprc += IXGBE_READ_REG(hw, IXGBE_FCOEPRC);
5770 hwstats->fcoeptc += IXGBE_READ_REG(hw, IXGBE_FCOEPTC);
5771 hwstats->fcoedwrc += IXGBE_READ_REG(hw, IXGBE_FCOEDWRC);
5772 hwstats->fcoedwtc += IXGBE_READ_REG(hw, IXGBE_FCOEDWTC);
5773#endif /* IXGBE_FCOE */
5774 break;
5775 default:
5776 break;
5777 }
5778 bprc = IXGBE_READ_REG(hw, IXGBE_BPRC);
5779 hwstats->bprc += bprc;
5780 hwstats->mprc += IXGBE_READ_REG(hw, IXGBE_MPRC);
5781 if (hw->mac.type == ixgbe_mac_82598EB)
5782 hwstats->mprc -= bprc;
5783 hwstats->roc += IXGBE_READ_REG(hw, IXGBE_ROC);
5784 hwstats->prc64 += IXGBE_READ_REG(hw, IXGBE_PRC64);
5785 hwstats->prc127 += IXGBE_READ_REG(hw, IXGBE_PRC127);
5786 hwstats->prc255 += IXGBE_READ_REG(hw, IXGBE_PRC255);
5787 hwstats->prc511 += IXGBE_READ_REG(hw, IXGBE_PRC511);
5788 hwstats->prc1023 += IXGBE_READ_REG(hw, IXGBE_PRC1023);
5789 hwstats->prc1522 += IXGBE_READ_REG(hw, IXGBE_PRC1522);
5790 hwstats->rlec += IXGBE_READ_REG(hw, IXGBE_RLEC);
5791 lxon = IXGBE_READ_REG(hw, IXGBE_LXONTXC);
5792 hwstats->lxontxc += lxon;
5793 lxoff = IXGBE_READ_REG(hw, IXGBE_LXOFFTXC);
5794 hwstats->lxofftxc += lxoff;
5795 hwstats->ruc += IXGBE_READ_REG(hw, IXGBE_RUC);
5796 hwstats->gptc += IXGBE_READ_REG(hw, IXGBE_GPTC);
5797 hwstats->mptc += IXGBE_READ_REG(hw, IXGBE_MPTC);
5798 /*
5799 * 82598 errata - tx of flow control packets is included in tx counters
5800 */
5801 xon_off_tot = lxon + lxoff;
5802 hwstats->gptc -= xon_off_tot;
5803 hwstats->mptc -= xon_off_tot;
5804 hwstats->gotc -= (xon_off_tot * (ETH_ZLEN + ETH_FCS_LEN));
5805 hwstats->ruc += IXGBE_READ_REG(hw, IXGBE_RUC);
5806 hwstats->rfc += IXGBE_READ_REG(hw, IXGBE_RFC);
5807 hwstats->rjc += IXGBE_READ_REG(hw, IXGBE_RJC);
5808 hwstats->tpr += IXGBE_READ_REG(hw, IXGBE_TPR);
5809 hwstats->ptc64 += IXGBE_READ_REG(hw, IXGBE_PTC64);
5810 hwstats->ptc64 -= xon_off_tot;
5811 hwstats->ptc127 += IXGBE_READ_REG(hw, IXGBE_PTC127);
5812 hwstats->ptc255 += IXGBE_READ_REG(hw, IXGBE_PTC255);
5813 hwstats->ptc511 += IXGBE_READ_REG(hw, IXGBE_PTC511);
5814 hwstats->ptc1023 += IXGBE_READ_REG(hw, IXGBE_PTC1023);
5815 hwstats->ptc1522 += IXGBE_READ_REG(hw, IXGBE_PTC1522);
5816 hwstats->bptc += IXGBE_READ_REG(hw, IXGBE_BPTC);
5817
5818 /* Fill out the OS statistics structure */
5819 netdev->stats.multicast = hwstats->mprc;
5820
5821 /* Rx Errors */
5822 netdev->stats.rx_errors = hwstats->crcerrs + hwstats->rlec;
5823 netdev->stats.rx_dropped = 0;
5824 netdev->stats.rx_length_errors = hwstats->rlec;
5825 netdev->stats.rx_crc_errors = hwstats->crcerrs;
5826 netdev->stats.rx_missed_errors = total_mpc;
5827}
5828
5829/**
5830 * ixgbe_fdir_reinit_subtask - worker thread to reinit FDIR filter table
5831 * @adapter - pointer to the device adapter structure
5832 **/
5833static void ixgbe_fdir_reinit_subtask(struct ixgbe_adapter *adapter)
5834{
5835 struct ixgbe_hw *hw = &adapter->hw;
5836 int i;
5837
5838 if (!(adapter->flags2 & IXGBE_FLAG2_FDIR_REQUIRES_REINIT))
5839 return;
5840
5841 adapter->flags2 &= ~IXGBE_FLAG2_FDIR_REQUIRES_REINIT;
5842
5843 /* if interface is down do nothing */
5844 if (test_bit(__IXGBE_DOWN, &adapter->state))
5845 return;
5846
5847 /* do nothing if we are not using signature filters */
5848 if (!(adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE))
5849 return;
5850
5851 adapter->fdir_overflow++;
5852
5853 if (ixgbe_reinit_fdir_tables_82599(hw) == 0) {
5854 for (i = 0; i < adapter->num_tx_queues; i++)
5855 set_bit(__IXGBE_TX_FDIR_INIT_DONE,
5856 &(adapter->tx_ring[i]->state));
5857 /* re-enable flow director interrupts */
5858 IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMS_FLOW_DIR);
5859 } else {
5860 e_err(probe, "failed to finish FDIR re-initialization, "
5861 "ignored adding FDIR ATR filters\n");
5862 }
5863}
5864
5865/**
5866 * ixgbe_check_hang_subtask - check for hung queues and dropped interrupts
5867 * @adapter - pointer to the device adapter structure
5868 *
5869 * This function serves two purposes. First it strobes the interrupt lines
5870 * in order to make certain interrupts are occuring. Secondly it sets the
5871 * bits needed to check for TX hangs. As a result we should immediately
5872 * determine if a hang has occured.
5873 */
5874static void ixgbe_check_hang_subtask(struct ixgbe_adapter *adapter)
5875{
5876 struct ixgbe_hw *hw = &adapter->hw;
5877 u64 eics = 0;
5878 int i;
5879
5880 /* If we're down or resetting, just bail */
5881 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
5882 test_bit(__IXGBE_RESETTING, &adapter->state))
5883 return;
5884
5885 /* Force detection of hung controller */
5886 if (netif_carrier_ok(adapter->netdev)) {
5887 for (i = 0; i < adapter->num_tx_queues; i++)
5888 set_check_for_tx_hang(adapter->tx_ring[i]);
5889 }
5890
5891 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) {
5892 /*
5893 * for legacy and MSI interrupts don't set any bits
5894 * that are enabled for EIAM, because this operation
5895 * would set *both* EIMS and EICS for any bit in EIAM
5896 */
5897 IXGBE_WRITE_REG(hw, IXGBE_EICS,
5898 (IXGBE_EICS_TCP_TIMER | IXGBE_EICS_OTHER));
5899 } else {
5900 /* get one bit for every active tx/rx interrupt vector */
5901 for (i = 0; i < adapter->num_msix_vectors - NON_Q_VECTORS; i++) {
5902 struct ixgbe_q_vector *qv = adapter->q_vector[i];
5903 if (qv->rx.count || qv->tx.count)
5904 eics |= ((u64)1 << i);
5905 }
5906 }
5907
5908 /* Cause software interrupt to ensure rings are cleaned */
5909 ixgbe_irq_rearm_queues(adapter, eics);
5910
5911}
5912
5913/**
5914 * ixgbe_watchdog_update_link - update the link status
5915 * @adapter - pointer to the device adapter structure
5916 * @link_speed - pointer to a u32 to store the link_speed
5917 **/
5918static void ixgbe_watchdog_update_link(struct ixgbe_adapter *adapter)
5919{
5920 struct ixgbe_hw *hw = &adapter->hw;
5921 u32 link_speed = adapter->link_speed;
5922 bool link_up = adapter->link_up;
5923 int i;
5924
5925 if (!(adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE))
5926 return;
5927
5928 if (hw->mac.ops.check_link) {
5929 hw->mac.ops.check_link(hw, &link_speed, &link_up, false);
5930 } else {
5931 /* always assume link is up, if no check link function */
5932 link_speed = IXGBE_LINK_SPEED_10GB_FULL;
5933 link_up = true;
5934 }
5935 if (link_up) {
5936 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
5937 for (i = 0; i < MAX_TRAFFIC_CLASS; i++)
5938 hw->mac.ops.fc_enable(hw, i);
5939 } else {
5940 hw->mac.ops.fc_enable(hw, 0);
5941 }
5942 }
5943
5944 if (link_up ||
5945 time_after(jiffies, (adapter->link_check_timeout +
5946 IXGBE_TRY_LINK_TIMEOUT))) {
5947 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE;
5948 IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMC_LSC);
5949 IXGBE_WRITE_FLUSH(hw);
5950 }
5951
5952 adapter->link_up = link_up;
5953 adapter->link_speed = link_speed;
5954}
5955
5956/**
5957 * ixgbe_watchdog_link_is_up - update netif_carrier status and
5958 * print link up message
5959 * @adapter - pointer to the device adapter structure
5960 **/
5961static void ixgbe_watchdog_link_is_up(struct ixgbe_adapter *adapter)
5962{
5963 struct net_device *netdev = adapter->netdev;
5964 struct ixgbe_hw *hw = &adapter->hw;
5965 u32 link_speed = adapter->link_speed;
5966 bool flow_rx, flow_tx;
5967
5968 /* only continue if link was previously down */
5969 if (netif_carrier_ok(netdev))
5970 return;
5971
5972 adapter->flags2 &= ~IXGBE_FLAG2_SEARCH_FOR_SFP;
5973
5974 switch (hw->mac.type) {
5975 case ixgbe_mac_82598EB: {
5976 u32 frctl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
5977 u32 rmcs = IXGBE_READ_REG(hw, IXGBE_RMCS);
5978 flow_rx = !!(frctl & IXGBE_FCTRL_RFCE);
5979 flow_tx = !!(rmcs & IXGBE_RMCS_TFCE_802_3X);
5980 }
5981 break;
5982 case ixgbe_mac_X540:
5983 case ixgbe_mac_82599EB: {
5984 u32 mflcn = IXGBE_READ_REG(hw, IXGBE_MFLCN);
5985 u32 fccfg = IXGBE_READ_REG(hw, IXGBE_FCCFG);
5986 flow_rx = !!(mflcn & IXGBE_MFLCN_RFCE);
5987 flow_tx = !!(fccfg & IXGBE_FCCFG_TFCE_802_3X);
5988 }
5989 break;
5990 default:
5991 flow_tx = false;
5992 flow_rx = false;
5993 break;
5994 }
5995 e_info(drv, "NIC Link is Up %s, Flow Control: %s\n",
5996 (link_speed == IXGBE_LINK_SPEED_10GB_FULL ?
5997 "10 Gbps" :
5998 (link_speed == IXGBE_LINK_SPEED_1GB_FULL ?
5999 "1 Gbps" :
6000 (link_speed == IXGBE_LINK_SPEED_100_FULL ?
6001 "100 Mbps" :
6002 "unknown speed"))),
6003 ((flow_rx && flow_tx) ? "RX/TX" :
6004 (flow_rx ? "RX" :
6005 (flow_tx ? "TX" : "None"))));
6006
6007 netif_carrier_on(netdev);
6008 ixgbe_check_vf_rate_limit(adapter);
6009}
6010
6011/**
6012 * ixgbe_watchdog_link_is_down - update netif_carrier status and
6013 * print link down message
6014 * @adapter - pointer to the adapter structure
6015 **/
6016static void ixgbe_watchdog_link_is_down(struct ixgbe_adapter* adapter)
6017{
6018 struct net_device *netdev = adapter->netdev;
6019 struct ixgbe_hw *hw = &adapter->hw;
6020
6021 adapter->link_up = false;
6022 adapter->link_speed = 0;
6023
6024 /* only continue if link was up previously */
6025 if (!netif_carrier_ok(netdev))
6026 return;
6027
6028 /* poll for SFP+ cable when link is down */
6029 if (ixgbe_is_sfp(hw) && hw->mac.type == ixgbe_mac_82598EB)
6030 adapter->flags2 |= IXGBE_FLAG2_SEARCH_FOR_SFP;
6031
6032 e_info(drv, "NIC Link is Down\n");
6033 netif_carrier_off(netdev);
6034}
6035
6036/**
6037 * ixgbe_watchdog_flush_tx - flush queues on link down
6038 * @adapter - pointer to the device adapter structure
6039 **/
6040static void ixgbe_watchdog_flush_tx(struct ixgbe_adapter *adapter)
6041{
6042 int i;
6043 int some_tx_pending = 0;
6044
6045 if (!netif_carrier_ok(adapter->netdev)) {
6046 for (i = 0; i < adapter->num_tx_queues; i++) {
6047 struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
6048 if (tx_ring->next_to_use != tx_ring->next_to_clean) {
6049 some_tx_pending = 1;
6050 break;
6051 }
6052 }
6053
6054 if (some_tx_pending) {
6055 /* We've lost link, so the controller stops DMA,
6056 * but we've got queued Tx work that's never going
6057 * to get done, so reset controller to flush Tx.
6058 * (Do the reset outside of interrupt context).
6059 */
6060 adapter->flags2 |= IXGBE_FLAG2_RESET_REQUESTED;
6061 }
6062 }
6063}
6064
6065static void ixgbe_spoof_check(struct ixgbe_adapter *adapter)
6066{
6067 u32 ssvpc;
6068
6069 /* Do not perform spoof check for 82598 */
6070 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
6071 return;
6072
6073 ssvpc = IXGBE_READ_REG(&adapter->hw, IXGBE_SSVPC);
6074
6075 /*
6076 * ssvpc register is cleared on read, if zero then no
6077 * spoofed packets in the last interval.
6078 */
6079 if (!ssvpc)
6080 return;
6081
6082 e_warn(drv, "%d Spoofed packets detected\n", ssvpc);
6083}
6084
6085/**
6086 * ixgbe_watchdog_subtask - check and bring link up
6087 * @adapter - pointer to the device adapter structure
6088 **/
6089static void ixgbe_watchdog_subtask(struct ixgbe_adapter *adapter)
6090{
6091 /* if interface is down do nothing */
6092 if (test_bit(__IXGBE_DOWN, &adapter->state))
6093 return;
6094
6095 ixgbe_watchdog_update_link(adapter);
6096
6097 if (adapter->link_up)
6098 ixgbe_watchdog_link_is_up(adapter);
6099 else
6100 ixgbe_watchdog_link_is_down(adapter);
6101
6102 ixgbe_spoof_check(adapter);
6103 ixgbe_update_stats(adapter);
6104
6105 ixgbe_watchdog_flush_tx(adapter);
6106}
6107
6108/**
6109 * ixgbe_sfp_detection_subtask - poll for SFP+ cable
6110 * @adapter - the ixgbe adapter structure
6111 **/
6112static void ixgbe_sfp_detection_subtask(struct ixgbe_adapter *adapter)
6113{
6114 struct ixgbe_hw *hw = &adapter->hw;
6115 s32 err;
6116
6117 /* not searching for SFP so there is nothing to do here */
6118 if (!(adapter->flags2 & IXGBE_FLAG2_SEARCH_FOR_SFP) &&
6119 !(adapter->flags2 & IXGBE_FLAG2_SFP_NEEDS_RESET))
6120 return;
6121
6122 /* someone else is in init, wait until next service event */
6123 if (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
6124 return;
6125
6126 err = hw->phy.ops.identify_sfp(hw);
6127 if (err == IXGBE_ERR_SFP_NOT_SUPPORTED)
6128 goto sfp_out;
6129
6130 if (err == IXGBE_ERR_SFP_NOT_PRESENT) {
6131 /* If no cable is present, then we need to reset
6132 * the next time we find a good cable. */
6133 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
6134 }
6135
6136 /* exit on error */
6137 if (err)
6138 goto sfp_out;
6139
6140 /* exit if reset not needed */
6141 if (!(adapter->flags2 & IXGBE_FLAG2_SFP_NEEDS_RESET))
6142 goto sfp_out;
6143
6144 adapter->flags2 &= ~IXGBE_FLAG2_SFP_NEEDS_RESET;
6145
6146 /*
6147 * A module may be identified correctly, but the EEPROM may not have
6148 * support for that module. setup_sfp() will fail in that case, so
6149 * we should not allow that module to load.
6150 */
6151 if (hw->mac.type == ixgbe_mac_82598EB)
6152 err = hw->phy.ops.reset(hw);
6153 else
6154 err = hw->mac.ops.setup_sfp(hw);
6155
6156 if (err == IXGBE_ERR_SFP_NOT_SUPPORTED)
6157 goto sfp_out;
6158
6159 adapter->flags |= IXGBE_FLAG_NEED_LINK_CONFIG;
6160 e_info(probe, "detected SFP+: %d\n", hw->phy.sfp_type);
6161
6162sfp_out:
6163 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
6164
6165 if ((err == IXGBE_ERR_SFP_NOT_SUPPORTED) &&
6166 (adapter->netdev->reg_state == NETREG_REGISTERED)) {
6167 e_dev_err("failed to initialize because an unsupported "
6168 "SFP+ module type was detected.\n");
6169 e_dev_err("Reload the driver after installing a "
6170 "supported module.\n");
6171 unregister_netdev(adapter->netdev);
6172 }
6173}
6174
6175/**
6176 * ixgbe_sfp_link_config_subtask - set up link SFP after module install
6177 * @adapter - the ixgbe adapter structure
6178 **/
6179static void ixgbe_sfp_link_config_subtask(struct ixgbe_adapter *adapter)
6180{
6181 struct ixgbe_hw *hw = &adapter->hw;
6182 u32 autoneg;
6183 bool negotiation;
6184
6185 if (!(adapter->flags & IXGBE_FLAG_NEED_LINK_CONFIG))
6186 return;
6187
6188 /* someone else is in init, wait until next service event */
6189 if (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
6190 return;
6191
6192 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG;
6193
6194 autoneg = hw->phy.autoneg_advertised;
6195 if ((!autoneg) && (hw->mac.ops.get_link_capabilities))
6196 hw->mac.ops.get_link_capabilities(hw, &autoneg, &negotiation);
6197 hw->mac.autotry_restart = false;
6198 if (hw->mac.ops.setup_link)
6199 hw->mac.ops.setup_link(hw, autoneg, negotiation, true);
6200
6201 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
6202 adapter->link_check_timeout = jiffies;
6203 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
6204}
6205
6206/**
6207 * ixgbe_service_timer - Timer Call-back
6208 * @data: pointer to adapter cast into an unsigned long
6209 **/
6210static void ixgbe_service_timer(unsigned long data)
6211{
6212 struct ixgbe_adapter *adapter = (struct ixgbe_adapter *)data;
6213 unsigned long next_event_offset;
6214
6215 /* poll faster when waiting for link */
6216 if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE)
6217 next_event_offset = HZ / 10;
6218 else
6219 next_event_offset = HZ * 2;
6220
6221 /* Reset the timer */
6222 mod_timer(&adapter->service_timer, next_event_offset + jiffies);
6223
6224 ixgbe_service_event_schedule(adapter);
6225}
6226
6227static void ixgbe_reset_subtask(struct ixgbe_adapter *adapter)
6228{
6229 if (!(adapter->flags2 & IXGBE_FLAG2_RESET_REQUESTED))
6230 return;
6231
6232 adapter->flags2 &= ~IXGBE_FLAG2_RESET_REQUESTED;
6233
6234 /* If we're already down or resetting, just bail */
6235 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
6236 test_bit(__IXGBE_RESETTING, &adapter->state))
6237 return;
6238
6239 ixgbe_dump(adapter);
6240 netdev_err(adapter->netdev, "Reset adapter\n");
6241 adapter->tx_timeout_count++;
6242
6243 ixgbe_reinit_locked(adapter);
6244}
6245
6246/**
6247 * ixgbe_service_task - manages and runs subtasks
6248 * @work: pointer to work_struct containing our data
6249 **/
6250static void ixgbe_service_task(struct work_struct *work)
6251{
6252 struct ixgbe_adapter *adapter = container_of(work,
6253 struct ixgbe_adapter,
6254 service_task);
6255
6256 ixgbe_reset_subtask(adapter);
6257 ixgbe_sfp_detection_subtask(adapter);
6258 ixgbe_sfp_link_config_subtask(adapter);
6259 ixgbe_check_overtemp_subtask(adapter);
6260 ixgbe_watchdog_subtask(adapter);
6261 ixgbe_fdir_reinit_subtask(adapter);
6262 ixgbe_check_hang_subtask(adapter);
6263
6264 ixgbe_service_event_complete(adapter);
6265}
6266
6267void ixgbe_tx_ctxtdesc(struct ixgbe_ring *tx_ring, u32 vlan_macip_lens,
6268 u32 fcoe_sof_eof, u32 type_tucmd, u32 mss_l4len_idx)
6269{
6270 struct ixgbe_adv_tx_context_desc *context_desc;
6271 u16 i = tx_ring->next_to_use;
6272
6273 context_desc = IXGBE_TX_CTXTDESC_ADV(tx_ring, i);
6274
6275 i++;
6276 tx_ring->next_to_use = (i < tx_ring->count) ? i : 0;
6277
6278 /* set bits to identify this as an advanced context descriptor */
6279 type_tucmd |= IXGBE_TXD_CMD_DEXT | IXGBE_ADVTXD_DTYP_CTXT;
6280
6281 context_desc->vlan_macip_lens = cpu_to_le32(vlan_macip_lens);
6282 context_desc->seqnum_seed = cpu_to_le32(fcoe_sof_eof);
6283 context_desc->type_tucmd_mlhl = cpu_to_le32(type_tucmd);
6284 context_desc->mss_l4len_idx = cpu_to_le32(mss_l4len_idx);
6285}
6286
6287static int ixgbe_tso(struct ixgbe_ring *tx_ring, struct sk_buff *skb,
6288 u32 tx_flags, __be16 protocol, u8 *hdr_len)
6289{
6290 int err;
6291 u32 vlan_macip_lens, type_tucmd;
6292 u32 mss_l4len_idx, l4len;
6293
6294 if (!skb_is_gso(skb))
6295 return 0;
6296
6297 if (skb_header_cloned(skb)) {
6298 err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
6299 if (err)
6300 return err;
6301 }
6302
6303 /* ADV DTYP TUCMD MKRLOC/ISCSIHEDLEN */
6304 type_tucmd = IXGBE_ADVTXD_TUCMD_L4T_TCP;
6305
6306 if (protocol == __constant_htons(ETH_P_IP)) {
6307 struct iphdr *iph = ip_hdr(skb);
6308 iph->tot_len = 0;
6309 iph->check = 0;
6310 tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr,
6311 iph->daddr, 0,
6312 IPPROTO_TCP,
6313 0);
6314 type_tucmd |= IXGBE_ADVTXD_TUCMD_IPV4;
6315 } else if (skb_is_gso_v6(skb)) {
6316 ipv6_hdr(skb)->payload_len = 0;
6317 tcp_hdr(skb)->check =
6318 ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
6319 &ipv6_hdr(skb)->daddr,
6320 0, IPPROTO_TCP, 0);
6321 }
6322
6323 l4len = tcp_hdrlen(skb);
6324 *hdr_len = skb_transport_offset(skb) + l4len;
6325
6326 /* mss_l4len_id: use 1 as index for TSO */
6327 mss_l4len_idx = l4len << IXGBE_ADVTXD_L4LEN_SHIFT;
6328 mss_l4len_idx |= skb_shinfo(skb)->gso_size << IXGBE_ADVTXD_MSS_SHIFT;
6329 mss_l4len_idx |= 1 << IXGBE_ADVTXD_IDX_SHIFT;
6330
6331 /* vlan_macip_lens: HEADLEN, MACLEN, VLAN tag */
6332 vlan_macip_lens = skb_network_header_len(skb);
6333 vlan_macip_lens |= skb_network_offset(skb) << IXGBE_ADVTXD_MACLEN_SHIFT;
6334 vlan_macip_lens |= tx_flags & IXGBE_TX_FLAGS_VLAN_MASK;
6335
6336 ixgbe_tx_ctxtdesc(tx_ring, vlan_macip_lens, 0, type_tucmd,
6337 mss_l4len_idx);
6338
6339 return 1;
6340}
6341
6342static bool ixgbe_tx_csum(struct ixgbe_ring *tx_ring,
6343 struct sk_buff *skb, u32 tx_flags,
6344 __be16 protocol)
6345{
6346 u32 vlan_macip_lens = 0;
6347 u32 mss_l4len_idx = 0;
6348 u32 type_tucmd = 0;
6349
6350 if (skb->ip_summed != CHECKSUM_PARTIAL) {
6351 if (!(tx_flags & IXGBE_TX_FLAGS_VLAN))
6352 return false;
6353 } else {
6354 u8 l4_hdr = 0;
6355 switch (protocol) {
6356 case __constant_htons(ETH_P_IP):
6357 vlan_macip_lens |= skb_network_header_len(skb);
6358 type_tucmd |= IXGBE_ADVTXD_TUCMD_IPV4;
6359 l4_hdr = ip_hdr(skb)->protocol;
6360 break;
6361 case __constant_htons(ETH_P_IPV6):
6362 vlan_macip_lens |= skb_network_header_len(skb);
6363 l4_hdr = ipv6_hdr(skb)->nexthdr;
6364 break;
6365 default:
6366 if (unlikely(net_ratelimit())) {
6367 dev_warn(tx_ring->dev,
6368 "partial checksum but proto=%x!\n",
6369 skb->protocol);
6370 }
6371 break;
6372 }
6373
6374 switch (l4_hdr) {
6375 case IPPROTO_TCP:
6376 type_tucmd |= IXGBE_ADVTXD_TUCMD_L4T_TCP;
6377 mss_l4len_idx = tcp_hdrlen(skb) <<
6378 IXGBE_ADVTXD_L4LEN_SHIFT;
6379 break;
6380 case IPPROTO_SCTP:
6381 type_tucmd |= IXGBE_ADVTXD_TUCMD_L4T_SCTP;
6382 mss_l4len_idx = sizeof(struct sctphdr) <<
6383 IXGBE_ADVTXD_L4LEN_SHIFT;
6384 break;
6385 case IPPROTO_UDP:
6386 mss_l4len_idx = sizeof(struct udphdr) <<
6387 IXGBE_ADVTXD_L4LEN_SHIFT;
6388 break;
6389 default:
6390 if (unlikely(net_ratelimit())) {
6391 dev_warn(tx_ring->dev,
6392 "partial checksum but l4 proto=%x!\n",
6393 skb->protocol);
6394 }
6395 break;
6396 }
6397 }
6398
6399 vlan_macip_lens |= skb_network_offset(skb) << IXGBE_ADVTXD_MACLEN_SHIFT;
6400 vlan_macip_lens |= tx_flags & IXGBE_TX_FLAGS_VLAN_MASK;
6401
6402 ixgbe_tx_ctxtdesc(tx_ring, vlan_macip_lens, 0,
6403 type_tucmd, mss_l4len_idx);
6404
6405 return (skb->ip_summed == CHECKSUM_PARTIAL);
6406}
6407
6408static int ixgbe_tx_map(struct ixgbe_adapter *adapter,
6409 struct ixgbe_ring *tx_ring,
6410 struct sk_buff *skb, u32 tx_flags,
6411 unsigned int first, const u8 hdr_len)
6412{
6413 struct device *dev = tx_ring->dev;
6414 struct ixgbe_tx_buffer *tx_buffer_info;
6415 unsigned int len;
6416 unsigned int total = skb->len;
6417 unsigned int offset = 0, size, count = 0;
6418 unsigned int nr_frags = skb_shinfo(skb)->nr_frags;
6419 unsigned int f;
6420 unsigned int bytecount = skb->len;
6421 u16 gso_segs = 1;
6422 u16 i;
6423
6424 i = tx_ring->next_to_use;
6425
6426 if (tx_flags & IXGBE_TX_FLAGS_FCOE)
6427 /* excluding fcoe_crc_eof for FCoE */
6428 total -= sizeof(struct fcoe_crc_eof);
6429
6430 len = min(skb_headlen(skb), total);
6431 while (len) {
6432 tx_buffer_info = &tx_ring->tx_buffer_info[i];
6433 size = min(len, (uint)IXGBE_MAX_DATA_PER_TXD);
6434
6435 tx_buffer_info->length = size;
6436 tx_buffer_info->mapped_as_page = false;
6437 tx_buffer_info->dma = dma_map_single(dev,
6438 skb->data + offset,
6439 size, DMA_TO_DEVICE);
6440 if (dma_mapping_error(dev, tx_buffer_info->dma))
6441 goto dma_error;
6442 tx_buffer_info->time_stamp = jiffies;
6443 tx_buffer_info->next_to_watch = i;
6444
6445 len -= size;
6446 total -= size;
6447 offset += size;
6448 count++;
6449
6450 if (len) {
6451 i++;
6452 if (i == tx_ring->count)
6453 i = 0;
6454 }
6455 }
6456
6457 for (f = 0; f < nr_frags; f++) {
6458 struct skb_frag_struct *frag;
6459
6460 frag = &skb_shinfo(skb)->frags[f];
6461 len = min((unsigned int)frag->size, total);
6462 offset = frag->page_offset;
6463
6464 while (len) {
6465 i++;
6466 if (i == tx_ring->count)
6467 i = 0;
6468
6469 tx_buffer_info = &tx_ring->tx_buffer_info[i];
6470 size = min(len, (uint)IXGBE_MAX_DATA_PER_TXD);
6471
6472 tx_buffer_info->length = size;
6473 tx_buffer_info->dma = dma_map_page(dev,
6474 frag->page,
6475 offset, size,
6476 DMA_TO_DEVICE);
6477 tx_buffer_info->mapped_as_page = true;
6478 if (dma_mapping_error(dev, tx_buffer_info->dma))
6479 goto dma_error;
6480 tx_buffer_info->time_stamp = jiffies;
6481 tx_buffer_info->next_to_watch = i;
6482
6483 len -= size;
6484 total -= size;
6485 offset += size;
6486 count++;
6487 }
6488 if (total == 0)
6489 break;
6490 }
6491
6492 if (tx_flags & IXGBE_TX_FLAGS_TSO)
6493 gso_segs = skb_shinfo(skb)->gso_segs;
6494#ifdef IXGBE_FCOE
6495 /* adjust for FCoE Sequence Offload */
6496 else if (tx_flags & IXGBE_TX_FLAGS_FSO)
6497 gso_segs = DIV_ROUND_UP(skb->len - hdr_len,
6498 skb_shinfo(skb)->gso_size);
6499#endif /* IXGBE_FCOE */
6500 bytecount += (gso_segs - 1) * hdr_len;
6501
6502 /* multiply data chunks by size of headers */
6503 tx_ring->tx_buffer_info[i].bytecount = bytecount;
6504 tx_ring->tx_buffer_info[i].gso_segs = gso_segs;
6505 tx_ring->tx_buffer_info[i].skb = skb;
6506 tx_ring->tx_buffer_info[first].next_to_watch = i;
6507
6508 return count;
6509
6510dma_error:
6511 e_dev_err("TX DMA map failed\n");
6512
6513 /* clear timestamp and dma mappings for failed tx_buffer_info map */
6514 tx_buffer_info->dma = 0;
6515 tx_buffer_info->time_stamp = 0;
6516 tx_buffer_info->next_to_watch = 0;
6517 if (count)
6518 count--;
6519
6520 /* clear timestamp and dma mappings for remaining portion of packet */
6521 while (count--) {
6522 if (i == 0)
6523 i += tx_ring->count;
6524 i--;
6525 tx_buffer_info = &tx_ring->tx_buffer_info[i];
6526 ixgbe_unmap_and_free_tx_resource(tx_ring, tx_buffer_info);
6527 }
6528
6529 return 0;
6530}
6531
6532static void ixgbe_tx_queue(struct ixgbe_ring *tx_ring,
6533 int tx_flags, int count, u32 paylen, u8 hdr_len)
6534{
6535 union ixgbe_adv_tx_desc *tx_desc = NULL;
6536 struct ixgbe_tx_buffer *tx_buffer_info;
6537 u32 olinfo_status = 0, cmd_type_len = 0;
6538 unsigned int i;
6539 u32 txd_cmd = IXGBE_TXD_CMD_EOP | IXGBE_TXD_CMD_RS | IXGBE_TXD_CMD_IFCS;
6540
6541 cmd_type_len |= IXGBE_ADVTXD_DTYP_DATA;
6542
6543 cmd_type_len |= IXGBE_ADVTXD_DCMD_IFCS | IXGBE_ADVTXD_DCMD_DEXT;
6544
6545 if (tx_flags & IXGBE_TX_FLAGS_VLAN)
6546 cmd_type_len |= IXGBE_ADVTXD_DCMD_VLE;
6547
6548 if (tx_flags & IXGBE_TX_FLAGS_TSO) {
6549 cmd_type_len |= IXGBE_ADVTXD_DCMD_TSE;
6550
6551 olinfo_status |= IXGBE_TXD_POPTS_TXSM <<
6552 IXGBE_ADVTXD_POPTS_SHIFT;
6553
6554 /* use index 1 context for tso */
6555 olinfo_status |= (1 << IXGBE_ADVTXD_IDX_SHIFT);
6556 if (tx_flags & IXGBE_TX_FLAGS_IPV4)
6557 olinfo_status |= IXGBE_TXD_POPTS_IXSM <<
6558 IXGBE_ADVTXD_POPTS_SHIFT;
6559
6560 } else if (tx_flags & IXGBE_TX_FLAGS_CSUM)
6561 olinfo_status |= IXGBE_TXD_POPTS_TXSM <<
6562 IXGBE_ADVTXD_POPTS_SHIFT;
6563
6564 if (tx_flags & IXGBE_TX_FLAGS_FCOE) {
6565 olinfo_status |= IXGBE_ADVTXD_CC;
6566 olinfo_status |= (1 << IXGBE_ADVTXD_IDX_SHIFT);
6567 if (tx_flags & IXGBE_TX_FLAGS_FSO)
6568 cmd_type_len |= IXGBE_ADVTXD_DCMD_TSE;
6569 }
6570
6571 olinfo_status |= ((paylen - hdr_len) << IXGBE_ADVTXD_PAYLEN_SHIFT);
6572
6573 i = tx_ring->next_to_use;
6574 while (count--) {
6575 tx_buffer_info = &tx_ring->tx_buffer_info[i];
6576 tx_desc = IXGBE_TX_DESC_ADV(tx_ring, i);
6577 tx_desc->read.buffer_addr = cpu_to_le64(tx_buffer_info->dma);
6578 tx_desc->read.cmd_type_len =
6579 cpu_to_le32(cmd_type_len | tx_buffer_info->length);
6580 tx_desc->read.olinfo_status = cpu_to_le32(olinfo_status);
6581 i++;
6582 if (i == tx_ring->count)
6583 i = 0;
6584 }
6585
6586 tx_desc->read.cmd_type_len |= cpu_to_le32(txd_cmd);
6587
6588 /*
6589 * Force memory writes to complete before letting h/w
6590 * know there are new descriptors to fetch. (Only
6591 * applicable for weak-ordered memory model archs,
6592 * such as IA-64).
6593 */
6594 wmb();
6595
6596 tx_ring->next_to_use = i;
6597 writel(i, tx_ring->tail);
6598}
6599
6600static void ixgbe_atr(struct ixgbe_ring *ring, struct sk_buff *skb,
6601 u32 tx_flags, __be16 protocol)
6602{
6603 struct ixgbe_q_vector *q_vector = ring->q_vector;
6604 union ixgbe_atr_hash_dword input = { .dword = 0 };
6605 union ixgbe_atr_hash_dword common = { .dword = 0 };
6606 union {
6607 unsigned char *network;
6608 struct iphdr *ipv4;
6609 struct ipv6hdr *ipv6;
6610 } hdr;
6611 struct tcphdr *th;
6612 __be16 vlan_id;
6613
6614 /* if ring doesn't have a interrupt vector, cannot perform ATR */
6615 if (!q_vector)
6616 return;
6617
6618 /* do nothing if sampling is disabled */
6619 if (!ring->atr_sample_rate)
6620 return;
6621
6622 ring->atr_count++;
6623
6624 /* snag network header to get L4 type and address */
6625 hdr.network = skb_network_header(skb);
6626
6627 /* Currently only IPv4/IPv6 with TCP is supported */
6628 if ((protocol != __constant_htons(ETH_P_IPV6) ||
6629 hdr.ipv6->nexthdr != IPPROTO_TCP) &&
6630 (protocol != __constant_htons(ETH_P_IP) ||
6631 hdr.ipv4->protocol != IPPROTO_TCP))
6632 return;
6633
6634 th = tcp_hdr(skb);
6635
6636 /* skip this packet since the socket is closing */
6637 if (th->fin)
6638 return;
6639
6640 /* sample on all syn packets or once every atr sample count */
6641 if (!th->syn && (ring->atr_count < ring->atr_sample_rate))
6642 return;
6643
6644 /* reset sample count */
6645 ring->atr_count = 0;
6646
6647 vlan_id = htons(tx_flags >> IXGBE_TX_FLAGS_VLAN_SHIFT);
6648
6649 /*
6650 * src and dst are inverted, think how the receiver sees them
6651 *
6652 * The input is broken into two sections, a non-compressed section
6653 * containing vm_pool, vlan_id, and flow_type. The rest of the data
6654 * is XORed together and stored in the compressed dword.
6655 */
6656 input.formatted.vlan_id = vlan_id;
6657
6658 /*
6659 * since src port and flex bytes occupy the same word XOR them together
6660 * and write the value to source port portion of compressed dword
6661 */
6662 if (vlan_id)
6663 common.port.src ^= th->dest ^ __constant_htons(ETH_P_8021Q);
6664 else
6665 common.port.src ^= th->dest ^ protocol;
6666 common.port.dst ^= th->source;
6667
6668 if (protocol == __constant_htons(ETH_P_IP)) {
6669 input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV4;
6670 common.ip ^= hdr.ipv4->saddr ^ hdr.ipv4->daddr;
6671 } else {
6672 input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV6;
6673 common.ip ^= hdr.ipv6->saddr.s6_addr32[0] ^
6674 hdr.ipv6->saddr.s6_addr32[1] ^
6675 hdr.ipv6->saddr.s6_addr32[2] ^
6676 hdr.ipv6->saddr.s6_addr32[3] ^
6677 hdr.ipv6->daddr.s6_addr32[0] ^
6678 hdr.ipv6->daddr.s6_addr32[1] ^
6679 hdr.ipv6->daddr.s6_addr32[2] ^
6680 hdr.ipv6->daddr.s6_addr32[3];
6681 }
6682
6683 /* This assumes the Rx queue and Tx queue are bound to the same CPU */
6684 ixgbe_fdir_add_signature_filter_82599(&q_vector->adapter->hw,
6685 input, common, ring->queue_index);
6686}
6687
6688static int __ixgbe_maybe_stop_tx(struct ixgbe_ring *tx_ring, u16 size)
6689{
6690 netif_stop_subqueue(tx_ring->netdev, tx_ring->queue_index);
6691 /* Herbert's original patch had:
6692 * smp_mb__after_netif_stop_queue();
6693 * but since that doesn't exist yet, just open code it. */
6694 smp_mb();
6695
6696 /* We need to check again in a case another CPU has just
6697 * made room available. */
6698 if (likely(ixgbe_desc_unused(tx_ring) < size))
6699 return -EBUSY;
6700
6701 /* A reprieve! - use start_queue because it doesn't call schedule */
6702 netif_start_subqueue(tx_ring->netdev, tx_ring->queue_index);
6703 ++tx_ring->tx_stats.restart_queue;
6704 return 0;
6705}
6706
6707static inline int ixgbe_maybe_stop_tx(struct ixgbe_ring *tx_ring, u16 size)
6708{
6709 if (likely(ixgbe_desc_unused(tx_ring) >= size))
6710 return 0;
6711 return __ixgbe_maybe_stop_tx(tx_ring, size);
6712}
6713
6714static u16 ixgbe_select_queue(struct net_device *dev, struct sk_buff *skb)
6715{
6716 struct ixgbe_adapter *adapter = netdev_priv(dev);
6717 int txq = skb_rx_queue_recorded(skb) ? skb_get_rx_queue(skb) :
6718 smp_processor_id();
6719#ifdef IXGBE_FCOE
6720 __be16 protocol = vlan_get_protocol(skb);
6721
6722 if (((protocol == htons(ETH_P_FCOE)) ||
6723 (protocol == htons(ETH_P_FIP))) &&
6724 (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)) {
6725 txq &= (adapter->ring_feature[RING_F_FCOE].indices - 1);
6726 txq += adapter->ring_feature[RING_F_FCOE].mask;
6727 return txq;
6728 }
6729#endif
6730
6731 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
6732 while (unlikely(txq >= dev->real_num_tx_queues))
6733 txq -= dev->real_num_tx_queues;
6734 return txq;
6735 }
6736
6737 return skb_tx_hash(dev, skb);
6738}
6739
6740netdev_tx_t ixgbe_xmit_frame_ring(struct sk_buff *skb,
6741 struct ixgbe_adapter *adapter,
6742 struct ixgbe_ring *tx_ring)
6743{
6744 int tso;
6745 u32 tx_flags = 0;
6746#if PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD
6747 unsigned short f;
6748#endif
6749 u16 first;
6750 u16 count = TXD_USE_COUNT(skb_headlen(skb));
6751 __be16 protocol;
6752 u8 hdr_len = 0;
6753
6754 /*
6755 * need: 1 descriptor per page * PAGE_SIZE/IXGBE_MAX_DATA_PER_TXD,
6756 * + 1 desc for skb_head_len/IXGBE_MAX_DATA_PER_TXD,
6757 * + 2 desc gap to keep tail from touching head,
6758 * + 1 desc for context descriptor,
6759 * otherwise try next time
6760 */
6761#if PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD
6762 for (f = 0; f < skb_shinfo(skb)->nr_frags; f++)
6763 count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size);
6764#else
6765 count += skb_shinfo(skb)->nr_frags;
6766#endif
6767 if (ixgbe_maybe_stop_tx(tx_ring, count + 3)) {
6768 tx_ring->tx_stats.tx_busy++;
6769 return NETDEV_TX_BUSY;
6770 }
6771
6772 protocol = vlan_get_protocol(skb);
6773
6774 if (vlan_tx_tag_present(skb)) {
6775 tx_flags |= vlan_tx_tag_get(skb);
6776 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
6777 tx_flags &= ~IXGBE_TX_FLAGS_VLAN_PRIO_MASK;
6778 tx_flags |= tx_ring->dcb_tc << 13;
6779 }
6780 tx_flags <<= IXGBE_TX_FLAGS_VLAN_SHIFT;
6781 tx_flags |= IXGBE_TX_FLAGS_VLAN;
6782 } else if (adapter->flags & IXGBE_FLAG_DCB_ENABLED &&
6783 skb->priority != TC_PRIO_CONTROL) {
6784 tx_flags |= tx_ring->dcb_tc << 13;
6785 tx_flags <<= IXGBE_TX_FLAGS_VLAN_SHIFT;
6786 tx_flags |= IXGBE_TX_FLAGS_VLAN;
6787 }
6788
6789#ifdef IXGBE_FCOE
6790 /* for FCoE with DCB, we force the priority to what
6791 * was specified by the switch */
6792 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED &&
6793 (protocol == htons(ETH_P_FCOE)))
6794 tx_flags |= IXGBE_TX_FLAGS_FCOE;
6795
6796#endif
6797 /* record the location of the first descriptor for this packet */
6798 first = tx_ring->next_to_use;
6799
6800 if (tx_flags & IXGBE_TX_FLAGS_FCOE) {
6801#ifdef IXGBE_FCOE
6802 /* setup tx offload for FCoE */
6803 tso = ixgbe_fso(tx_ring, skb, tx_flags, &hdr_len);
6804 if (tso < 0)
6805 goto out_drop;
6806 else if (tso)
6807 tx_flags |= IXGBE_TX_FLAGS_FSO;
6808#endif /* IXGBE_FCOE */
6809 } else {
6810 if (protocol == htons(ETH_P_IP))
6811 tx_flags |= IXGBE_TX_FLAGS_IPV4;
6812 tso = ixgbe_tso(tx_ring, skb, tx_flags, protocol, &hdr_len);
6813 if (tso < 0)
6814 goto out_drop;
6815 else if (tso)
6816 tx_flags |= IXGBE_TX_FLAGS_TSO;
6817 else if (ixgbe_tx_csum(tx_ring, skb, tx_flags, protocol))
6818 tx_flags |= IXGBE_TX_FLAGS_CSUM;
6819 }
6820
6821 count = ixgbe_tx_map(adapter, tx_ring, skb, tx_flags, first, hdr_len);
6822 if (count) {
6823 /* add the ATR filter if ATR is on */
6824 if (test_bit(__IXGBE_TX_FDIR_INIT_DONE, &tx_ring->state))
6825 ixgbe_atr(tx_ring, skb, tx_flags, protocol);
6826 ixgbe_tx_queue(tx_ring, tx_flags, count, skb->len, hdr_len);
6827 ixgbe_maybe_stop_tx(tx_ring, DESC_NEEDED);
6828
6829 } else {
6830 tx_ring->tx_buffer_info[first].time_stamp = 0;
6831 tx_ring->next_to_use = first;
6832 goto out_drop;
6833 }
6834
6835 return NETDEV_TX_OK;
6836
6837out_drop:
6838 dev_kfree_skb_any(skb);
6839 return NETDEV_TX_OK;
6840}
6841
6842static netdev_tx_t ixgbe_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
6843{
6844 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6845 struct ixgbe_ring *tx_ring;
6846
6847 tx_ring = adapter->tx_ring[skb->queue_mapping];
6848 return ixgbe_xmit_frame_ring(skb, adapter, tx_ring);
6849}
6850
6851/**
6852 * ixgbe_set_mac - Change the Ethernet Address of the NIC
6853 * @netdev: network interface device structure
6854 * @p: pointer to an address structure
6855 *
6856 * Returns 0 on success, negative on failure
6857 **/
6858static int ixgbe_set_mac(struct net_device *netdev, void *p)
6859{
6860 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6861 struct ixgbe_hw *hw = &adapter->hw;
6862 struct sockaddr *addr = p;
6863
6864 if (!is_valid_ether_addr(addr->sa_data))
6865 return -EADDRNOTAVAIL;
6866
6867 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
6868 memcpy(hw->mac.addr, addr->sa_data, netdev->addr_len);
6869
6870 hw->mac.ops.set_rar(hw, 0, hw->mac.addr, adapter->num_vfs,
6871 IXGBE_RAH_AV);
6872
6873 return 0;
6874}
6875
6876static int
6877ixgbe_mdio_read(struct net_device *netdev, int prtad, int devad, u16 addr)
6878{
6879 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6880 struct ixgbe_hw *hw = &adapter->hw;
6881 u16 value;
6882 int rc;
6883
6884 if (prtad != hw->phy.mdio.prtad)
6885 return -EINVAL;
6886 rc = hw->phy.ops.read_reg(hw, addr, devad, &value);
6887 if (!rc)
6888 rc = value;
6889 return rc;
6890}
6891
6892static int ixgbe_mdio_write(struct net_device *netdev, int prtad, int devad,
6893 u16 addr, u16 value)
6894{
6895 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6896 struct ixgbe_hw *hw = &adapter->hw;
6897
6898 if (prtad != hw->phy.mdio.prtad)
6899 return -EINVAL;
6900 return hw->phy.ops.write_reg(hw, addr, devad, value);
6901}
6902
6903static int ixgbe_ioctl(struct net_device *netdev, struct ifreq *req, int cmd)
6904{
6905 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6906
6907 return mdio_mii_ioctl(&adapter->hw.phy.mdio, if_mii(req), cmd);
6908}
6909
6910/**
6911 * ixgbe_add_sanmac_netdev - Add the SAN MAC address to the corresponding
6912 * netdev->dev_addrs
6913 * @netdev: network interface device structure
6914 *
6915 * Returns non-zero on failure
6916 **/
6917static int ixgbe_add_sanmac_netdev(struct net_device *dev)
6918{
6919 int err = 0;
6920 struct ixgbe_adapter *adapter = netdev_priv(dev);
6921 struct ixgbe_mac_info *mac = &adapter->hw.mac;
6922
6923 if (is_valid_ether_addr(mac->san_addr)) {
6924 rtnl_lock();
6925 err = dev_addr_add(dev, mac->san_addr, NETDEV_HW_ADDR_T_SAN);
6926 rtnl_unlock();
6927 }
6928 return err;
6929}
6930
6931/**
6932 * ixgbe_del_sanmac_netdev - Removes the SAN MAC address to the corresponding
6933 * netdev->dev_addrs
6934 * @netdev: network interface device structure
6935 *
6936 * Returns non-zero on failure
6937 **/
6938static int ixgbe_del_sanmac_netdev(struct net_device *dev)
6939{
6940 int err = 0;
6941 struct ixgbe_adapter *adapter = netdev_priv(dev);
6942 struct ixgbe_mac_info *mac = &adapter->hw.mac;
6943
6944 if (is_valid_ether_addr(mac->san_addr)) {
6945 rtnl_lock();
6946 err = dev_addr_del(dev, mac->san_addr, NETDEV_HW_ADDR_T_SAN);
6947 rtnl_unlock();
6948 }
6949 return err;
6950}
6951
6952#ifdef CONFIG_NET_POLL_CONTROLLER
6953/*
6954 * Polling 'interrupt' - used by things like netconsole to send skbs
6955 * without having to re-enable interrupts. It's not called while
6956 * the interrupt routine is executing.
6957 */
6958static void ixgbe_netpoll(struct net_device *netdev)
6959{
6960 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6961 int i;
6962
6963 /* if interface is down do nothing */
6964 if (test_bit(__IXGBE_DOWN, &adapter->state))
6965 return;
6966
6967 adapter->flags |= IXGBE_FLAG_IN_NETPOLL;
6968 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
6969 int num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
6970 for (i = 0; i < num_q_vectors; i++) {
6971 struct ixgbe_q_vector *q_vector = adapter->q_vector[i];
6972 ixgbe_msix_clean_many(0, q_vector);
6973 }
6974 } else {
6975 ixgbe_intr(adapter->pdev->irq, netdev);
6976 }
6977 adapter->flags &= ~IXGBE_FLAG_IN_NETPOLL;
6978}
6979#endif
6980
6981static struct rtnl_link_stats64 *ixgbe_get_stats64(struct net_device *netdev,
6982 struct rtnl_link_stats64 *stats)
6983{
6984 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6985 int i;
6986
6987 rcu_read_lock();
6988 for (i = 0; i < adapter->num_rx_queues; i++) {
6989 struct ixgbe_ring *ring = ACCESS_ONCE(adapter->rx_ring[i]);
6990 u64 bytes, packets;
6991 unsigned int start;
6992
6993 if (ring) {
6994 do {
6995 start = u64_stats_fetch_begin_bh(&ring->syncp);
6996 packets = ring->stats.packets;
6997 bytes = ring->stats.bytes;
6998 } while (u64_stats_fetch_retry_bh(&ring->syncp, start));
6999 stats->rx_packets += packets;
7000 stats->rx_bytes += bytes;
7001 }
7002 }
7003
7004 for (i = 0; i < adapter->num_tx_queues; i++) {
7005 struct ixgbe_ring *ring = ACCESS_ONCE(adapter->tx_ring[i]);
7006 u64 bytes, packets;
7007 unsigned int start;
7008
7009 if (ring) {
7010 do {
7011 start = u64_stats_fetch_begin_bh(&ring->syncp);
7012 packets = ring->stats.packets;
7013 bytes = ring->stats.bytes;
7014 } while (u64_stats_fetch_retry_bh(&ring->syncp, start));
7015 stats->tx_packets += packets;
7016 stats->tx_bytes += bytes;
7017 }
7018 }
7019 rcu_read_unlock();
7020 /* following stats updated by ixgbe_watchdog_task() */
7021 stats->multicast = netdev->stats.multicast;
7022 stats->rx_errors = netdev->stats.rx_errors;
7023 stats->rx_length_errors = netdev->stats.rx_length_errors;
7024 stats->rx_crc_errors = netdev->stats.rx_crc_errors;
7025 stats->rx_missed_errors = netdev->stats.rx_missed_errors;
7026 return stats;
7027}
7028
7029/* ixgbe_validate_rtr - verify 802.1Qp to Rx packet buffer mapping is valid.
7030 * #adapter: pointer to ixgbe_adapter
7031 * @tc: number of traffic classes currently enabled
7032 *
7033 * Configure a valid 802.1Qp to Rx packet buffer mapping ie confirm
7034 * 802.1Q priority maps to a packet buffer that exists.
7035 */
7036static void ixgbe_validate_rtr(struct ixgbe_adapter *adapter, u8 tc)
7037{
7038 struct ixgbe_hw *hw = &adapter->hw;
7039 u32 reg, rsave;
7040 int i;
7041
7042 /* 82598 have a static priority to TC mapping that can not
7043 * be changed so no validation is needed.
7044 */
7045 if (hw->mac.type == ixgbe_mac_82598EB)
7046 return;
7047
7048 reg = IXGBE_READ_REG(hw, IXGBE_RTRUP2TC);
7049 rsave = reg;
7050
7051 for (i = 0; i < MAX_TRAFFIC_CLASS; i++) {
7052 u8 up2tc = reg >> (i * IXGBE_RTRUP2TC_UP_SHIFT);
7053
7054 /* If up2tc is out of bounds default to zero */
7055 if (up2tc > tc)
7056 reg &= ~(0x7 << IXGBE_RTRUP2TC_UP_SHIFT);
7057 }
7058
7059 if (reg != rsave)
7060 IXGBE_WRITE_REG(hw, IXGBE_RTRUP2TC, reg);
7061
7062 return;
7063}
7064
7065
7066/* ixgbe_setup_tc - routine to configure net_device for multiple traffic
7067 * classes.
7068 *
7069 * @netdev: net device to configure
7070 * @tc: number of traffic classes to enable
7071 */
7072int ixgbe_setup_tc(struct net_device *dev, u8 tc)
7073{
7074 struct ixgbe_adapter *adapter = netdev_priv(dev);
7075 struct ixgbe_hw *hw = &adapter->hw;
7076
7077 /* If DCB is anabled do not remove traffic classes, multiple
7078 * traffic classes are required to implement DCB
7079 */
7080 if (!tc && (adapter->flags & IXGBE_FLAG_DCB_ENABLED))
7081 return 0;
7082
7083 /* Hardware supports up to 8 traffic classes */
7084 if (tc > MAX_TRAFFIC_CLASS ||
7085 (hw->mac.type == ixgbe_mac_82598EB && tc < MAX_TRAFFIC_CLASS))
7086 return -EINVAL;
7087
7088 /* Hardware has to reinitialize queues and interrupts to
7089 * match packet buffer alignment. Unfortunantly, the
7090 * hardware is not flexible enough to do this dynamically.
7091 */
7092 if (netif_running(dev))
7093 ixgbe_close(dev);
7094 ixgbe_clear_interrupt_scheme(adapter);
7095
7096 if (tc)
7097 netdev_set_num_tc(dev, tc);
7098 else
7099 netdev_reset_tc(dev);
7100
7101 ixgbe_init_interrupt_scheme(adapter);
7102 ixgbe_validate_rtr(adapter, tc);
7103 if (netif_running(dev))
7104 ixgbe_open(dev);
7105
7106 return 0;
7107}
7108
7109void ixgbe_do_reset(struct net_device *netdev)
7110{
7111 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7112
7113 if (netif_running(netdev))
7114 ixgbe_reinit_locked(adapter);
7115 else
7116 ixgbe_reset(adapter);
7117}
7118
7119static u32 ixgbe_fix_features(struct net_device *netdev, u32 data)
7120{
7121 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7122
7123#ifdef CONFIG_DCB
7124 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED)
7125 data &= ~NETIF_F_HW_VLAN_RX;
7126#endif
7127
7128 /* return error if RXHASH is being enabled when RSS is not supported */
7129 if (!(adapter->flags & IXGBE_FLAG_RSS_ENABLED))
7130 data &= ~NETIF_F_RXHASH;
7131
7132 /* If Rx checksum is disabled, then RSC/LRO should also be disabled */
7133 if (!(data & NETIF_F_RXCSUM))
7134 data &= ~NETIF_F_LRO;
7135
7136 /* Turn off LRO if not RSC capable or invalid ITR settings */
7137 if (!(adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE)) {
7138 data &= ~NETIF_F_LRO;
7139 } else if (!(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) &&
7140 (adapter->rx_itr_setting != 1 &&
7141 adapter->rx_itr_setting > IXGBE_MAX_RSC_INT_RATE)) {
7142 data &= ~NETIF_F_LRO;
7143 e_info(probe, "rx-usecs set too low, not enabling RSC\n");
7144 }
7145
7146 return data;
7147}
7148
7149static int ixgbe_set_features(struct net_device *netdev, u32 data)
7150{
7151 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7152 bool need_reset = false;
7153
7154 /* If Rx checksum is disabled, then RSC/LRO should also be disabled */
7155 if (!(data & NETIF_F_RXCSUM))
7156 adapter->flags &= ~IXGBE_FLAG_RX_CSUM_ENABLED;
7157 else
7158 adapter->flags |= IXGBE_FLAG_RX_CSUM_ENABLED;
7159
7160 /* Make sure RSC matches LRO, reset if change */
7161 if (!!(data & NETIF_F_LRO) !=
7162 !!(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)) {
7163 adapter->flags2 ^= IXGBE_FLAG2_RSC_ENABLED;
7164 switch (adapter->hw.mac.type) {
7165 case ixgbe_mac_X540:
7166 case ixgbe_mac_82599EB:
7167 need_reset = true;
7168 break;
7169 default:
7170 break;
7171 }
7172 }
7173
7174 /*
7175 * Check if Flow Director n-tuple support was enabled or disabled. If
7176 * the state changed, we need to reset.
7177 */
7178 if (!(adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)) {
7179 /* turn off ATR, enable perfect filters and reset */
7180 if (data & NETIF_F_NTUPLE) {
7181 adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
7182 adapter->flags |= IXGBE_FLAG_FDIR_PERFECT_CAPABLE;
7183 need_reset = true;
7184 }
7185 } else if (!(data & NETIF_F_NTUPLE)) {
7186 /* turn off Flow Director, set ATR and reset */
7187 adapter->flags &= ~IXGBE_FLAG_FDIR_PERFECT_CAPABLE;
7188 if ((adapter->flags & IXGBE_FLAG_RSS_ENABLED) &&
7189 !(adapter->flags & IXGBE_FLAG_DCB_ENABLED))
7190 adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE;
7191 need_reset = true;
7192 }
7193
7194 if (need_reset)
7195 ixgbe_do_reset(netdev);
7196
7197 return 0;
7198
7199}
7200
7201static const struct net_device_ops ixgbe_netdev_ops = {
7202 .ndo_open = ixgbe_open,
7203 .ndo_stop = ixgbe_close,
7204 .ndo_start_xmit = ixgbe_xmit_frame,
7205 .ndo_select_queue = ixgbe_select_queue,
7206 .ndo_set_rx_mode = ixgbe_set_rx_mode,
7207 .ndo_set_multicast_list = ixgbe_set_rx_mode,
7208 .ndo_validate_addr = eth_validate_addr,
7209 .ndo_set_mac_address = ixgbe_set_mac,
7210 .ndo_change_mtu = ixgbe_change_mtu,
7211 .ndo_tx_timeout = ixgbe_tx_timeout,
7212 .ndo_vlan_rx_add_vid = ixgbe_vlan_rx_add_vid,
7213 .ndo_vlan_rx_kill_vid = ixgbe_vlan_rx_kill_vid,
7214 .ndo_do_ioctl = ixgbe_ioctl,
7215 .ndo_set_vf_mac = ixgbe_ndo_set_vf_mac,
7216 .ndo_set_vf_vlan = ixgbe_ndo_set_vf_vlan,
7217 .ndo_set_vf_tx_rate = ixgbe_ndo_set_vf_bw,
7218 .ndo_get_vf_config = ixgbe_ndo_get_vf_config,
7219 .ndo_get_stats64 = ixgbe_get_stats64,
7220 .ndo_setup_tc = ixgbe_setup_tc,
7221#ifdef CONFIG_NET_POLL_CONTROLLER
7222 .ndo_poll_controller = ixgbe_netpoll,
7223#endif
7224#ifdef IXGBE_FCOE
7225 .ndo_fcoe_ddp_setup = ixgbe_fcoe_ddp_get,
7226 .ndo_fcoe_ddp_target = ixgbe_fcoe_ddp_target,
7227 .ndo_fcoe_ddp_done = ixgbe_fcoe_ddp_put,
7228 .ndo_fcoe_enable = ixgbe_fcoe_enable,
7229 .ndo_fcoe_disable = ixgbe_fcoe_disable,
7230 .ndo_fcoe_get_wwn = ixgbe_fcoe_get_wwn,
7231#endif /* IXGBE_FCOE */
7232 .ndo_set_features = ixgbe_set_features,
7233 .ndo_fix_features = ixgbe_fix_features,
7234};
7235
7236static void __devinit ixgbe_probe_vf(struct ixgbe_adapter *adapter,
7237 const struct ixgbe_info *ii)
7238{
7239#ifdef CONFIG_PCI_IOV
7240 struct ixgbe_hw *hw = &adapter->hw;
7241 int err;
7242 int num_vf_macvlans, i;
7243 struct vf_macvlans *mv_list;
7244
7245 if (hw->mac.type == ixgbe_mac_82598EB || !max_vfs)
7246 return;
7247
7248 /* The 82599 supports up to 64 VFs per physical function
7249 * but this implementation limits allocation to 63 so that
7250 * basic networking resources are still available to the
7251 * physical function
7252 */
7253 adapter->num_vfs = (max_vfs > 63) ? 63 : max_vfs;
7254 adapter->flags |= IXGBE_FLAG_SRIOV_ENABLED;
7255 err = pci_enable_sriov(adapter->pdev, adapter->num_vfs);
7256 if (err) {
7257 e_err(probe, "Failed to enable PCI sriov: %d\n", err);
7258 goto err_novfs;
7259 }
7260
7261 num_vf_macvlans = hw->mac.num_rar_entries -
7262 (IXGBE_MAX_PF_MACVLANS + 1 + adapter->num_vfs);
7263
7264 adapter->mv_list = mv_list = kcalloc(num_vf_macvlans,
7265 sizeof(struct vf_macvlans),
7266 GFP_KERNEL);
7267 if (mv_list) {
7268 /* Initialize list of VF macvlans */
7269 INIT_LIST_HEAD(&adapter->vf_mvs.l);
7270 for (i = 0; i < num_vf_macvlans; i++) {
7271 mv_list->vf = -1;
7272 mv_list->free = true;
7273 mv_list->rar_entry = hw->mac.num_rar_entries -
7274 (i + adapter->num_vfs + 1);
7275 list_add(&mv_list->l, &adapter->vf_mvs.l);
7276 mv_list++;
7277 }
7278 }
7279
7280 /* If call to enable VFs succeeded then allocate memory
7281 * for per VF control structures.
7282 */
7283 adapter->vfinfo =
7284 kcalloc(adapter->num_vfs,
7285 sizeof(struct vf_data_storage), GFP_KERNEL);
7286 if (adapter->vfinfo) {
7287 /* Now that we're sure SR-IOV is enabled
7288 * and memory allocated set up the mailbox parameters
7289 */
7290 ixgbe_init_mbx_params_pf(hw);
7291 memcpy(&hw->mbx.ops, ii->mbx_ops,
7292 sizeof(hw->mbx.ops));
7293
7294 /* Disable RSC when in SR-IOV mode */
7295 adapter->flags2 &= ~(IXGBE_FLAG2_RSC_CAPABLE |
7296 IXGBE_FLAG2_RSC_ENABLED);
7297 return;
7298 }
7299
7300 /* Oh oh */
7301 e_err(probe, "Unable to allocate memory for VF Data Storage - "
7302 "SRIOV disabled\n");
7303 pci_disable_sriov(adapter->pdev);
7304
7305err_novfs:
7306 adapter->flags &= ~IXGBE_FLAG_SRIOV_ENABLED;
7307 adapter->num_vfs = 0;
7308#endif /* CONFIG_PCI_IOV */
7309}
7310
7311/**
7312 * ixgbe_probe - Device Initialization Routine
7313 * @pdev: PCI device information struct
7314 * @ent: entry in ixgbe_pci_tbl
7315 *
7316 * Returns 0 on success, negative on failure
7317 *
7318 * ixgbe_probe initializes an adapter identified by a pci_dev structure.
7319 * The OS initialization, configuring of the adapter private structure,
7320 * and a hardware reset occur.
7321 **/
7322static int __devinit ixgbe_probe(struct pci_dev *pdev,
7323 const struct pci_device_id *ent)
7324{
7325 struct net_device *netdev;
7326 struct ixgbe_adapter *adapter = NULL;
7327 struct ixgbe_hw *hw;
7328 const struct ixgbe_info *ii = ixgbe_info_tbl[ent->driver_data];
7329 static int cards_found;
7330 int i, err, pci_using_dac;
7331 u8 part_str[IXGBE_PBANUM_LENGTH];
7332 unsigned int indices = num_possible_cpus();
7333#ifdef IXGBE_FCOE
7334 u16 device_caps;
7335#endif
7336 u32 eec;
7337
7338 /* Catch broken hardware that put the wrong VF device ID in
7339 * the PCIe SR-IOV capability.
7340 */
7341 if (pdev->is_virtfn) {
7342 WARN(1, KERN_ERR "%s (%hx:%hx) should not be a VF!\n",
7343 pci_name(pdev), pdev->vendor, pdev->device);
7344 return -EINVAL;
7345 }
7346
7347 err = pci_enable_device_mem(pdev);
7348 if (err)
7349 return err;
7350
7351 if (!dma_set_mask(&pdev->dev, DMA_BIT_MASK(64)) &&
7352 !dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(64))) {
7353 pci_using_dac = 1;
7354 } else {
7355 err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32));
7356 if (err) {
7357 err = dma_set_coherent_mask(&pdev->dev,
7358 DMA_BIT_MASK(32));
7359 if (err) {
7360 dev_err(&pdev->dev,
7361 "No usable DMA configuration, aborting\n");
7362 goto err_dma;
7363 }
7364 }
7365 pci_using_dac = 0;
7366 }
7367
7368 err = pci_request_selected_regions(pdev, pci_select_bars(pdev,
7369 IORESOURCE_MEM), ixgbe_driver_name);
7370 if (err) {
7371 dev_err(&pdev->dev,
7372 "pci_request_selected_regions failed 0x%x\n", err);
7373 goto err_pci_reg;
7374 }
7375
7376 pci_enable_pcie_error_reporting(pdev);
7377
7378 pci_set_master(pdev);
7379 pci_save_state(pdev);
7380
7381#ifdef CONFIG_IXGBE_DCB
7382 indices *= MAX_TRAFFIC_CLASS;
7383#endif
7384
7385 if (ii->mac == ixgbe_mac_82598EB)
7386 indices = min_t(unsigned int, indices, IXGBE_MAX_RSS_INDICES);
7387 else
7388 indices = min_t(unsigned int, indices, IXGBE_MAX_FDIR_INDICES);
7389
7390#ifdef IXGBE_FCOE
7391 indices += min_t(unsigned int, num_possible_cpus(),
7392 IXGBE_MAX_FCOE_INDICES);
7393#endif
7394 netdev = alloc_etherdev_mq(sizeof(struct ixgbe_adapter), indices);
7395 if (!netdev) {
7396 err = -ENOMEM;
7397 goto err_alloc_etherdev;
7398 }
7399
7400 SET_NETDEV_DEV(netdev, &pdev->dev);
7401
7402 adapter = netdev_priv(netdev);
7403 pci_set_drvdata(pdev, adapter);
7404
7405 adapter->netdev = netdev;
7406 adapter->pdev = pdev;
7407 hw = &adapter->hw;
7408 hw->back = adapter;
7409 adapter->msg_enable = (1 << DEFAULT_DEBUG_LEVEL_SHIFT) - 1;
7410
7411 hw->hw_addr = ioremap(pci_resource_start(pdev, 0),
7412 pci_resource_len(pdev, 0));
7413 if (!hw->hw_addr) {
7414 err = -EIO;
7415 goto err_ioremap;
7416 }
7417
7418 for (i = 1; i <= 5; i++) {
7419 if (pci_resource_len(pdev, i) == 0)
7420 continue;
7421 }
7422
7423 netdev->netdev_ops = &ixgbe_netdev_ops;
7424 ixgbe_set_ethtool_ops(netdev);
7425 netdev->watchdog_timeo = 5 * HZ;
7426 strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1);
7427
7428 adapter->bd_number = cards_found;
7429
7430 /* Setup hw api */
7431 memcpy(&hw->mac.ops, ii->mac_ops, sizeof(hw->mac.ops));
7432 hw->mac.type = ii->mac;
7433
7434 /* EEPROM */
7435 memcpy(&hw->eeprom.ops, ii->eeprom_ops, sizeof(hw->eeprom.ops));
7436 eec = IXGBE_READ_REG(hw, IXGBE_EEC);
7437 /* If EEPROM is valid (bit 8 = 1), use default otherwise use bit bang */
7438 if (!(eec & (1 << 8)))
7439 hw->eeprom.ops.read = &ixgbe_read_eeprom_bit_bang_generic;
7440
7441 /* PHY */
7442 memcpy(&hw->phy.ops, ii->phy_ops, sizeof(hw->phy.ops));
7443 hw->phy.sfp_type = ixgbe_sfp_type_unknown;
7444 /* ixgbe_identify_phy_generic will set prtad and mmds properly */
7445 hw->phy.mdio.prtad = MDIO_PRTAD_NONE;
7446 hw->phy.mdio.mmds = 0;
7447 hw->phy.mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22;
7448 hw->phy.mdio.dev = netdev;
7449 hw->phy.mdio.mdio_read = ixgbe_mdio_read;
7450 hw->phy.mdio.mdio_write = ixgbe_mdio_write;
7451
7452 ii->get_invariants(hw);
7453
7454 /* setup the private structure */
7455 err = ixgbe_sw_init(adapter);
7456 if (err)
7457 goto err_sw_init;
7458
7459 /* Make it possible the adapter to be woken up via WOL */
7460 switch (adapter->hw.mac.type) {
7461 case ixgbe_mac_82599EB:
7462 case ixgbe_mac_X540:
7463 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
7464 break;
7465 default:
7466 break;
7467 }
7468
7469 /*
7470 * If there is a fan on this device and it has failed log the
7471 * failure.
7472 */
7473 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
7474 u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
7475 if (esdp & IXGBE_ESDP_SDP1)
7476 e_crit(probe, "Fan has stopped, replace the adapter\n");
7477 }
7478
7479 /* reset_hw fills in the perm_addr as well */
7480 hw->phy.reset_if_overtemp = true;
7481 err = hw->mac.ops.reset_hw(hw);
7482 hw->phy.reset_if_overtemp = false;
7483 if (err == IXGBE_ERR_SFP_NOT_PRESENT &&
7484 hw->mac.type == ixgbe_mac_82598EB) {
7485 err = 0;
7486 } else if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) {
7487 e_dev_err("failed to load because an unsupported SFP+ "
7488 "module type was detected.\n");
7489 e_dev_err("Reload the driver after installing a supported "
7490 "module.\n");
7491 goto err_sw_init;
7492 } else if (err) {
7493 e_dev_err("HW Init failed: %d\n", err);
7494 goto err_sw_init;
7495 }
7496
7497 ixgbe_probe_vf(adapter, ii);
7498
7499 netdev->features = NETIF_F_SG |
7500 NETIF_F_IP_CSUM |
7501 NETIF_F_IPV6_CSUM |
7502 NETIF_F_HW_VLAN_TX |
7503 NETIF_F_HW_VLAN_RX |
7504 NETIF_F_HW_VLAN_FILTER |
7505 NETIF_F_TSO |
7506 NETIF_F_TSO6 |
7507 NETIF_F_GRO |
7508 NETIF_F_RXHASH |
7509 NETIF_F_RXCSUM;
7510
7511 netdev->hw_features = netdev->features;
7512
7513 switch (adapter->hw.mac.type) {
7514 case ixgbe_mac_82599EB:
7515 case ixgbe_mac_X540:
7516 netdev->features |= NETIF_F_SCTP_CSUM;
7517 netdev->hw_features |= NETIF_F_SCTP_CSUM |
7518 NETIF_F_NTUPLE;
7519 break;
7520 default:
7521 break;
7522 }
7523
7524 netdev->vlan_features |= NETIF_F_TSO;
7525 netdev->vlan_features |= NETIF_F_TSO6;
7526 netdev->vlan_features |= NETIF_F_IP_CSUM;
7527 netdev->vlan_features |= NETIF_F_IPV6_CSUM;
7528 netdev->vlan_features |= NETIF_F_SG;
7529
7530 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
7531 adapter->flags &= ~(IXGBE_FLAG_RSS_ENABLED |
7532 IXGBE_FLAG_DCB_ENABLED);
7533
7534#ifdef CONFIG_IXGBE_DCB
7535 netdev->dcbnl_ops = &dcbnl_ops;
7536#endif
7537
7538#ifdef IXGBE_FCOE
7539 if (adapter->flags & IXGBE_FLAG_FCOE_CAPABLE) {
7540 if (hw->mac.ops.get_device_caps) {
7541 hw->mac.ops.get_device_caps(hw, &device_caps);
7542 if (device_caps & IXGBE_DEVICE_CAPS_FCOE_OFFLOADS)
7543 adapter->flags &= ~IXGBE_FLAG_FCOE_CAPABLE;
7544 }
7545 }
7546 if (adapter->flags & IXGBE_FLAG_FCOE_CAPABLE) {
7547 netdev->vlan_features |= NETIF_F_FCOE_CRC;
7548 netdev->vlan_features |= NETIF_F_FSO;
7549 netdev->vlan_features |= NETIF_F_FCOE_MTU;
7550 }
7551#endif /* IXGBE_FCOE */
7552 if (pci_using_dac) {
7553 netdev->features |= NETIF_F_HIGHDMA;
7554 netdev->vlan_features |= NETIF_F_HIGHDMA;
7555 }
7556
7557 if (adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE)
7558 netdev->hw_features |= NETIF_F_LRO;
7559 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
7560 netdev->features |= NETIF_F_LRO;
7561
7562 /* make sure the EEPROM is good */
7563 if (hw->eeprom.ops.validate_checksum(hw, NULL) < 0) {
7564 e_dev_err("The EEPROM Checksum Is Not Valid\n");
7565 err = -EIO;
7566 goto err_eeprom;
7567 }
7568
7569 memcpy(netdev->dev_addr, hw->mac.perm_addr, netdev->addr_len);
7570 memcpy(netdev->perm_addr, hw->mac.perm_addr, netdev->addr_len);
7571
7572 if (ixgbe_validate_mac_addr(netdev->perm_addr)) {
7573 e_dev_err("invalid MAC address\n");
7574 err = -EIO;
7575 goto err_eeprom;
7576 }
7577
7578 /* power down the optics for multispeed fiber and 82599 SFP+ fiber */
7579 if (hw->mac.ops.disable_tx_laser &&
7580 ((hw->phy.multispeed_fiber) ||
7581 ((hw->mac.ops.get_media_type(hw) == ixgbe_media_type_fiber) &&
7582 (hw->mac.type == ixgbe_mac_82599EB))))
7583 hw->mac.ops.disable_tx_laser(hw);
7584
7585 setup_timer(&adapter->service_timer, &ixgbe_service_timer,
7586 (unsigned long) adapter);
7587
7588 INIT_WORK(&adapter->service_task, ixgbe_service_task);
7589 clear_bit(__IXGBE_SERVICE_SCHED, &adapter->state);
7590
7591 err = ixgbe_init_interrupt_scheme(adapter);
7592 if (err)
7593 goto err_sw_init;
7594
7595 if (!(adapter->flags & IXGBE_FLAG_RSS_ENABLED)) {
7596 netdev->hw_features &= ~NETIF_F_RXHASH;
7597 netdev->features &= ~NETIF_F_RXHASH;
7598 }
7599
7600 switch (pdev->device) {
7601 case IXGBE_DEV_ID_82599_SFP:
7602 /* Only this subdevice supports WOL */
7603 if (pdev->subsystem_device == IXGBE_SUBDEV_ID_82599_SFP)
7604 adapter->wol = IXGBE_WUFC_MAG;
7605 break;
7606 case IXGBE_DEV_ID_82599_COMBO_BACKPLANE:
7607 /* All except this subdevice support WOL */
7608 if (pdev->subsystem_device != IXGBE_SUBDEV_ID_82599_KX4_KR_MEZZ)
7609 adapter->wol = IXGBE_WUFC_MAG;
7610 break;
7611 case IXGBE_DEV_ID_82599_KX4:
7612 adapter->wol = IXGBE_WUFC_MAG;
7613 break;
7614 default:
7615 adapter->wol = 0;
7616 break;
7617 }
7618 device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
7619
7620 /* pick up the PCI bus settings for reporting later */
7621 hw->mac.ops.get_bus_info(hw);
7622
7623 /* print bus type/speed/width info */
7624 e_dev_info("(PCI Express:%s:%s) %pM\n",
7625 (hw->bus.speed == ixgbe_bus_speed_5000 ? "5.0GT/s" :
7626 hw->bus.speed == ixgbe_bus_speed_2500 ? "2.5GT/s" :
7627 "Unknown"),
7628 (hw->bus.width == ixgbe_bus_width_pcie_x8 ? "Width x8" :
7629 hw->bus.width == ixgbe_bus_width_pcie_x4 ? "Width x4" :
7630 hw->bus.width == ixgbe_bus_width_pcie_x1 ? "Width x1" :
7631 "Unknown"),
7632 netdev->dev_addr);
7633
7634 err = ixgbe_read_pba_string_generic(hw, part_str, IXGBE_PBANUM_LENGTH);
7635 if (err)
7636 strncpy(part_str, "Unknown", IXGBE_PBANUM_LENGTH);
7637 if (ixgbe_is_sfp(hw) && hw->phy.sfp_type != ixgbe_sfp_type_not_present)
7638 e_dev_info("MAC: %d, PHY: %d, SFP+: %d, PBA No: %s\n",
7639 hw->mac.type, hw->phy.type, hw->phy.sfp_type,
7640 part_str);
7641 else
7642 e_dev_info("MAC: %d, PHY: %d, PBA No: %s\n",
7643 hw->mac.type, hw->phy.type, part_str);
7644
7645 if (hw->bus.width <= ixgbe_bus_width_pcie_x4) {
7646 e_dev_warn("PCI-Express bandwidth available for this card is "
7647 "not sufficient for optimal performance.\n");
7648 e_dev_warn("For optimal performance a x8 PCI-Express slot "
7649 "is required.\n");
7650 }
7651
7652 /* save off EEPROM version number */
7653 hw->eeprom.ops.read(hw, 0x29, &adapter->eeprom_version);
7654
7655 /* reset the hardware with the new settings */
7656 err = hw->mac.ops.start_hw(hw);
7657
7658 if (err == IXGBE_ERR_EEPROM_VERSION) {
7659 /* We are running on a pre-production device, log a warning */
7660 e_dev_warn("This device is a pre-production adapter/LOM. "
7661 "Please be aware there may be issues associated "
7662 "with your hardware. If you are experiencing "
7663 "problems please contact your Intel or hardware "
7664 "representative who provided you with this "
7665 "hardware.\n");
7666 }
7667 strcpy(netdev->name, "eth%d");
7668 err = register_netdev(netdev);
7669 if (err)
7670 goto err_register;
7671
7672 /* carrier off reporting is important to ethtool even BEFORE open */
7673 netif_carrier_off(netdev);
7674
7675#ifdef CONFIG_IXGBE_DCA
7676 if (dca_add_requester(&pdev->dev) == 0) {
7677 adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
7678 ixgbe_setup_dca(adapter);
7679 }
7680#endif
7681 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
7682 e_info(probe, "IOV is enabled with %d VFs\n", adapter->num_vfs);
7683 for (i = 0; i < adapter->num_vfs; i++)
7684 ixgbe_vf_configuration(pdev, (i | 0x10000000));
7685 }
7686
7687 /* Inform firmware of driver version */
7688 if (hw->mac.ops.set_fw_drv_ver)
7689 hw->mac.ops.set_fw_drv_ver(hw, MAJ, MIN, BUILD,
7690 FW_CEM_UNUSED_VER);
7691
7692 /* add san mac addr to netdev */
7693 ixgbe_add_sanmac_netdev(netdev);
7694
7695 e_dev_info("Intel(R) 10 Gigabit Network Connection\n");
7696 cards_found++;
7697 return 0;
7698
7699err_register:
7700 ixgbe_release_hw_control(adapter);
7701 ixgbe_clear_interrupt_scheme(adapter);
7702err_sw_init:
7703err_eeprom:
7704 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
7705 ixgbe_disable_sriov(adapter);
7706 adapter->flags2 &= ~IXGBE_FLAG2_SEARCH_FOR_SFP;
7707 iounmap(hw->hw_addr);
7708err_ioremap:
7709 free_netdev(netdev);
7710err_alloc_etherdev:
7711 pci_release_selected_regions(pdev,
7712 pci_select_bars(pdev, IORESOURCE_MEM));
7713err_pci_reg:
7714err_dma:
7715 pci_disable_device(pdev);
7716 return err;
7717}
7718
7719/**
7720 * ixgbe_remove - Device Removal Routine
7721 * @pdev: PCI device information struct
7722 *
7723 * ixgbe_remove is called by the PCI subsystem to alert the driver
7724 * that it should release a PCI device. The could be caused by a
7725 * Hot-Plug event, or because the driver is going to be removed from
7726 * memory.
7727 **/
7728static void __devexit ixgbe_remove(struct pci_dev *pdev)
7729{
7730 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
7731 struct net_device *netdev = adapter->netdev;
7732
7733 set_bit(__IXGBE_DOWN, &adapter->state);
7734 cancel_work_sync(&adapter->service_task);
7735
7736#ifdef CONFIG_IXGBE_DCA
7737 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
7738 adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
7739 dca_remove_requester(&pdev->dev);
7740 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1);
7741 }
7742
7743#endif
7744#ifdef IXGBE_FCOE
7745 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)
7746 ixgbe_cleanup_fcoe(adapter);
7747
7748#endif /* IXGBE_FCOE */
7749
7750 /* remove the added san mac */
7751 ixgbe_del_sanmac_netdev(netdev);
7752
7753 if (netdev->reg_state == NETREG_REGISTERED)
7754 unregister_netdev(netdev);
7755
7756 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
7757 ixgbe_disable_sriov(adapter);
7758
7759 ixgbe_clear_interrupt_scheme(adapter);
7760
7761 ixgbe_release_hw_control(adapter);
7762
7763 iounmap(adapter->hw.hw_addr);
7764 pci_release_selected_regions(pdev, pci_select_bars(pdev,
7765 IORESOURCE_MEM));
7766
7767 e_dev_info("complete\n");
7768
7769 free_netdev(netdev);
7770
7771 pci_disable_pcie_error_reporting(pdev);
7772
7773 pci_disable_device(pdev);
7774}
7775
7776/**
7777 * ixgbe_io_error_detected - called when PCI error is detected
7778 * @pdev: Pointer to PCI device
7779 * @state: The current pci connection state
7780 *
7781 * This function is called after a PCI bus error affecting
7782 * this device has been detected.
7783 */
7784static pci_ers_result_t ixgbe_io_error_detected(struct pci_dev *pdev,
7785 pci_channel_state_t state)
7786{
7787 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
7788 struct net_device *netdev = adapter->netdev;
7789
7790 netif_device_detach(netdev);
7791
7792 if (state == pci_channel_io_perm_failure)
7793 return PCI_ERS_RESULT_DISCONNECT;
7794
7795 if (netif_running(netdev))
7796 ixgbe_down(adapter);
7797 pci_disable_device(pdev);
7798
7799 /* Request a slot reset. */
7800 return PCI_ERS_RESULT_NEED_RESET;
7801}
7802
7803/**
7804 * ixgbe_io_slot_reset - called after the pci bus has been reset.
7805 * @pdev: Pointer to PCI device
7806 *
7807 * Restart the card from scratch, as if from a cold-boot.
7808 */
7809static pci_ers_result_t ixgbe_io_slot_reset(struct pci_dev *pdev)
7810{
7811 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
7812 pci_ers_result_t result;
7813 int err;
7814
7815 if (pci_enable_device_mem(pdev)) {
7816 e_err(probe, "Cannot re-enable PCI device after reset.\n");
7817 result = PCI_ERS_RESULT_DISCONNECT;
7818 } else {
7819 pci_set_master(pdev);
7820 pci_restore_state(pdev);
7821 pci_save_state(pdev);
7822
7823 pci_wake_from_d3(pdev, false);
7824
7825 ixgbe_reset(adapter);
7826 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
7827 result = PCI_ERS_RESULT_RECOVERED;
7828 }
7829
7830 err = pci_cleanup_aer_uncorrect_error_status(pdev);
7831 if (err) {
7832 e_dev_err("pci_cleanup_aer_uncorrect_error_status "
7833 "failed 0x%0x\n", err);
7834 /* non-fatal, continue */
7835 }
7836
7837 return result;
7838}
7839
7840/**
7841 * ixgbe_io_resume - called when traffic can start flowing again.
7842 * @pdev: Pointer to PCI device
7843 *
7844 * This callback is called when the error recovery driver tells us that
7845 * its OK to resume normal operation.
7846 */
7847static void ixgbe_io_resume(struct pci_dev *pdev)
7848{
7849 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
7850 struct net_device *netdev = adapter->netdev;
7851
7852 if (netif_running(netdev)) {
7853 if (ixgbe_up(adapter)) {
7854 e_info(probe, "ixgbe_up failed after reset\n");
7855 return;
7856 }
7857 }
7858
7859 netif_device_attach(netdev);
7860}
7861
7862static struct pci_error_handlers ixgbe_err_handler = {
7863 .error_detected = ixgbe_io_error_detected,
7864 .slot_reset = ixgbe_io_slot_reset,
7865 .resume = ixgbe_io_resume,
7866};
7867
7868static struct pci_driver ixgbe_driver = {
7869 .name = ixgbe_driver_name,
7870 .id_table = ixgbe_pci_tbl,
7871 .probe = ixgbe_probe,
7872 .remove = __devexit_p(ixgbe_remove),
7873#ifdef CONFIG_PM
7874 .suspend = ixgbe_suspend,
7875 .resume = ixgbe_resume,
7876#endif
7877 .shutdown = ixgbe_shutdown,
7878 .err_handler = &ixgbe_err_handler
7879};
7880
7881/**
7882 * ixgbe_init_module - Driver Registration Routine
7883 *
7884 * ixgbe_init_module is the first routine called when the driver is
7885 * loaded. All it does is register with the PCI subsystem.
7886 **/
7887static int __init ixgbe_init_module(void)
7888{
7889 int ret;
7890 pr_info("%s - version %s\n", ixgbe_driver_string, ixgbe_driver_version);
7891 pr_info("%s\n", ixgbe_copyright);
7892
7893#ifdef CONFIG_IXGBE_DCA
7894 dca_register_notify(&dca_notifier);
7895#endif
7896
7897 ret = pci_register_driver(&ixgbe_driver);
7898 return ret;
7899}
7900
7901module_init(ixgbe_init_module);
7902
7903/**
7904 * ixgbe_exit_module - Driver Exit Cleanup Routine
7905 *
7906 * ixgbe_exit_module is called just before the driver is removed
7907 * from memory.
7908 **/
7909static void __exit ixgbe_exit_module(void)
7910{
7911#ifdef CONFIG_IXGBE_DCA
7912 dca_unregister_notify(&dca_notifier);
7913#endif
7914 pci_unregister_driver(&ixgbe_driver);
7915 rcu_barrier(); /* Wait for completion of call_rcu()'s */
7916}
7917
7918#ifdef CONFIG_IXGBE_DCA
7919static int ixgbe_notify_dca(struct notifier_block *nb, unsigned long event,
7920 void *p)
7921{
7922 int ret_val;
7923
7924 ret_val = driver_for_each_device(&ixgbe_driver.driver, NULL, &event,
7925 __ixgbe_notify_dca);
7926
7927 return ret_val ? NOTIFY_BAD : NOTIFY_DONE;
7928}
7929
7930#endif /* CONFIG_IXGBE_DCA */
7931
7932module_exit(ixgbe_exit_module);
7933
7934/* ixgbe_main.c */
diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_mbx.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_mbx.c
new file mode 100644
index 000000000000..1ff0eefcfd0a
--- /dev/null
+++ b/drivers/net/ethernet/intel/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 **/
43s32 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 **/
67s32 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 **/
88s32 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 **/
106s32 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 **/
124s32 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 **/
142static 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
157out:
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 **/
168static 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
183out:
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 **/
197static 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);
211out:
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 **/
225static 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);
241out:
242 return ret_val;
243}
244
245static 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 **/
265static 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 **/
287static 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 **/
309static 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 **/
343static 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 **/
368static 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
393out_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 **/
409static 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
430out_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 */
441void 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
462struct 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/ethernet/intel/ixgbe/ixgbe_mbx.h b/drivers/net/ethernet/intel/ixgbe/ixgbe_mbx.h
new file mode 100644
index 000000000000..b239bdac38da
--- /dev/null
+++ b/drivers/net/ethernet/intel/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
82s32 ixgbe_read_mbx(struct ixgbe_hw *, u32 *, u16, u16);
83s32 ixgbe_write_mbx(struct ixgbe_hw *, u32 *, u16, u16);
84s32 ixgbe_check_for_msg(struct ixgbe_hw *, u16);
85s32 ixgbe_check_for_ack(struct ixgbe_hw *, u16);
86s32 ixgbe_check_for_rst(struct ixgbe_hw *, u16);
87#ifdef CONFIG_PCI_IOV
88void ixgbe_init_mbx_params_pf(struct ixgbe_hw *);
89#endif /* CONFIG_PCI_IOV */
90
91extern struct ixgbe_mbx_operations mbx_ops_generic;
92
93#endif /* _IXGBE_MBX_H_ */
diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_phy.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_phy.c
new file mode 100644
index 000000000000..f7ca3511b9fe
--- /dev/null
+++ b/drivers/net/ethernet/intel/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
35static void ixgbe_i2c_start(struct ixgbe_hw *hw);
36static void ixgbe_i2c_stop(struct ixgbe_hw *hw);
37static s32 ixgbe_clock_in_i2c_byte(struct ixgbe_hw *hw, u8 *data);
38static s32 ixgbe_clock_out_i2c_byte(struct ixgbe_hw *hw, u8 data);
39static s32 ixgbe_get_i2c_ack(struct ixgbe_hw *hw);
40static s32 ixgbe_clock_in_i2c_bit(struct ixgbe_hw *hw, bool *data);
41static s32 ixgbe_clock_out_i2c_bit(struct ixgbe_hw *hw, bool data);
42static s32 ixgbe_raise_i2c_clk(struct ixgbe_hw *hw, u32 *i2cctl);
43static void ixgbe_lower_i2c_clk(struct ixgbe_hw *hw, u32 *i2cctl);
44static s32 ixgbe_set_i2c_data(struct ixgbe_hw *hw, u32 *i2cctl, bool data);
45static bool ixgbe_get_i2c_data(u32 *i2cctl);
46static void ixgbe_i2c_bus_clear(struct ixgbe_hw *hw);
47static enum ixgbe_phy_type ixgbe_get_phy_type_from_id(u32 phy_id);
48static 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 **/
56s32 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 **/
104static 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 **/
128static 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 **/
157s32 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
202out:
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 **/
212s32 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 **/
311s32 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 **/
403s32 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 **/
499s32 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 */
534s32 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 **/
566s32 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 **/
613s32 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 **/
705s32 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 **/
722s32 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 **/
738s32 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
825out:
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 **/
835s32 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
1080out:
1081 return status;
1082
1083err_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 **/
1101s32 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 **/
1177s32 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 **/
1193s32 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 **/
1210s32 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
1271fail:
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
1285read_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 **/
1298s32 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
1346fail:
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
1357write_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 **/
1367static 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 **/
1396static 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 **/
1420static 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 **/
1444static 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 **/
1473static 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
1510out:
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 **/
1521static 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 **/
1549static 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 **/
1581static 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 **/
1603static 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 **/
1623static 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 **/
1655static 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 **/
1674static 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 **/
1707s32 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;
1723out:
1724 return status;
1725}
diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_phy.h b/drivers/net/ethernet/intel/ixgbe/ixgbe_phy.h
new file mode 100644
index 000000000000..197bdd13106a
--- /dev/null
+++ b/drivers/net/ethernet/intel/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
91s32 ixgbe_init_phy_ops_generic(struct ixgbe_hw *hw);
92s32 ixgbe_identify_phy_generic(struct ixgbe_hw *hw);
93s32 ixgbe_reset_phy_generic(struct ixgbe_hw *hw);
94s32 ixgbe_read_phy_reg_generic(struct ixgbe_hw *hw, u32 reg_addr,
95 u32 device_type, u16 *phy_data);
96s32 ixgbe_write_phy_reg_generic(struct ixgbe_hw *hw, u32 reg_addr,
97 u32 device_type, u16 phy_data);
98s32 ixgbe_setup_phy_link_generic(struct ixgbe_hw *hw);
99s32 ixgbe_setup_phy_link_speed_generic(struct ixgbe_hw *hw,
100 ixgbe_link_speed speed,
101 bool autoneg,
102 bool autoneg_wait_to_complete);
103s32 ixgbe_get_copper_link_capabilities_generic(struct ixgbe_hw *hw,
104 ixgbe_link_speed *speed,
105 bool *autoneg);
106
107/* PHY specific */
108s32 ixgbe_check_phy_link_tnx(struct ixgbe_hw *hw,
109 ixgbe_link_speed *speed,
110 bool *link_up);
111s32 ixgbe_setup_phy_link_tnx(struct ixgbe_hw *hw);
112s32 ixgbe_get_phy_firmware_version_tnx(struct ixgbe_hw *hw,
113 u16 *firmware_version);
114s32 ixgbe_get_phy_firmware_version_generic(struct ixgbe_hw *hw,
115 u16 *firmware_version);
116
117s32 ixgbe_reset_phy_nl(struct ixgbe_hw *hw);
118s32 ixgbe_identify_sfp_module_generic(struct ixgbe_hw *hw);
119s32 ixgbe_get_sfp_init_sequence_offsets(struct ixgbe_hw *hw,
120 u16 *list_offset,
121 u16 *data_offset);
122s32 ixgbe_tn_check_overtemp(struct ixgbe_hw *hw);
123s32 ixgbe_read_i2c_byte_generic(struct ixgbe_hw *hw, u8 byte_offset,
124 u8 dev_addr, u8 *data);
125s32 ixgbe_write_i2c_byte_generic(struct ixgbe_hw *hw, u8 byte_offset,
126 u8 dev_addr, u8 data);
127s32 ixgbe_read_i2c_eeprom_generic(struct ixgbe_hw *hw, u8 byte_offset,
128 u8 *eeprom_data);
129s32 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/ethernet/intel/ixgbe/ixgbe_sriov.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_sriov.c
new file mode 100644
index 000000000000..d99d01e21326
--- /dev/null
+++ b/drivers/net/ethernet/intel/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
46static 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
85static 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
100void 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
125static 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
131static 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
158static 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
170static 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
181static 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
209static 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
221static 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
276int 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
298static 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
324static 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
458static 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
468void 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
488void 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
500void 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
514int 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
532int 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 }
569out:
570 return err;
571}
572
573static 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
587static 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
627void 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
655int 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
675int 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/ethernet/intel/ixgbe/ixgbe_sriov.h b/drivers/net/ethernet/intel/ixgbe/ixgbe_sriov.h
new file mode 100644
index 000000000000..34175564bb78
--- /dev/null
+++ b/drivers/net/ethernet/intel/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
31void ixgbe_restore_vf_multicasts(struct ixgbe_adapter *adapter);
32void ixgbe_msg_task(struct ixgbe_adapter *adapter);
33int ixgbe_vf_configuration(struct pci_dev *pdev, unsigned int event_mask);
34void ixgbe_disable_tx_rx(struct ixgbe_adapter *adapter);
35void ixgbe_ping_all_vfs(struct ixgbe_adapter *adapter);
36void ixgbe_dump_registers(struct ixgbe_adapter *adapter);
37int ixgbe_ndo_set_vf_mac(struct net_device *netdev, int queue, u8 *mac);
38int ixgbe_ndo_set_vf_vlan(struct net_device *netdev, int queue, u16 vlan,
39 u8 qos);
40int ixgbe_ndo_set_vf_bw(struct net_device *netdev, int vf, int tx_rate);
41int ixgbe_ndo_get_vf_config(struct net_device *netdev,
42 int vf, struct ifla_vf_info *ivi);
43void ixgbe_check_vf_rate_limit(struct ixgbe_adapter *adapter);
44
45#endif /* _IXGBE_SRIOV_H_ */
46
diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h b/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
new file mode 100644
index 000000000000..e0d970ebab7a
--- /dev/null
+++ b/drivers/net/ethernet/intel/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 */
1142enum {
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
2058enum 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 */
2152struct 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
2162struct 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 */
2174union 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 */
2188union 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 */
2219struct 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 */
2282typedef u32 ixgbe_autoneg_advertised;
2283/* Link speed */
2284typedef 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 */
2297typedef 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
2333enum 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. */
2345union 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 */
2374union 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
2389enum ixgbe_eeprom_type {
2390 ixgbe_eeprom_uninitialized = 0,
2391 ixgbe_eeprom_spi,
2392 ixgbe_flash,
2393 ixgbe_eeprom_none /* No NVM support */
2394};
2395
2396enum 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
2404enum 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 */
2438enum 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
2454enum 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 */
2465enum 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
2478enum 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 */
2485enum 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 */
2494enum 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 */
2507enum 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
2518struct 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 */
2528struct 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 */
2538struct 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 */
2551struct 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 */
2628struct ixgbe_hw;
2629
2630/* iterator type for walking multicast address lists */
2631typedef u8* (*ixgbe_mc_addr_itr) (struct ixgbe_hw *hw, u8 **mc_addr_ptr,
2632 u32 *vmdq);
2633
2634/* Function pointer table */
2635struct 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
2646struct 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
2707struct 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
2726struct 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
2736struct 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
2764struct 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
2783struct 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
2794struct ixgbe_mbx_stats {
2795 u32 msgs_tx;
2796 u32 msgs_rx;
2797
2798 u32 acks;
2799 u32 reqs;
2800 u32 rsts;
2801};
2802
2803struct 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
2812struct 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
2831struct 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/ethernet/intel/ixgbe/ixgbe_x540.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_x540.c
new file mode 100644
index 000000000000..2696c78e9f46
--- /dev/null
+++ b/drivers/net/ethernet/intel/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
42static s32 ixgbe_update_flash_X540(struct ixgbe_hw *hw);
43static s32 ixgbe_poll_flash_update_done_X540(struct ixgbe_hw *hw);
44static s32 ixgbe_acquire_swfw_sync_X540(struct ixgbe_hw *hw, u16 mask);
45static void ixgbe_release_swfw_sync_X540(struct ixgbe_hw *hw, u16 mask);
46static s32 ixgbe_get_swfw_sync_semaphore(struct ixgbe_hw *hw);
47static void ixgbe_release_swfw_sync_semaphore(struct ixgbe_hw *hw);
48
49static enum ixgbe_media_type ixgbe_get_media_type_X540(struct ixgbe_hw *hw)
50{
51 return ixgbe_media_type_copper;
52}
53
54static 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 **/
78static 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 **/
94static 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
115mac_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 **/
238static 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;
248out:
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 **/
258static 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 **/
284static 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 **/
315static 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 **/
338static 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 **/
362static 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 **/
384static 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 **/
408static 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 **/
482static 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);
526out:
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 **/
538static 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 **/
581static 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 }
615out:
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 **/
626static 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 **/
651static 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 **/
719static 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 **/
740static 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 **/
784static 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 **/
809static 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 **/
841static 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}
861static 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
907static 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
918static 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
934struct 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};