blob: 826a11714d5e2b70438d5d0b6dece028a60a911c [file] [log] [blame]
Alexander Duyckb3890e32014-09-20 19:46:05 -04001/* Intel Ethernet Switch Host Interface Driver
2 * Copyright(c) 2013 - 2014 Intel Corporation.
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms and conditions of the GNU General Public License,
6 * version 2, as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11 * more details.
12 *
13 * The full GNU General Public License is included in this distribution in
14 * the file called "COPYING".
15 *
16 * Contact Information:
17 * e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
18 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
19 */
20
21#ifndef _FM10K_H_
22#define _FM10K_H_
23
24#include <linux/types.h>
25#include <linux/etherdevice.h>
26#include <linux/rtnetlink.h>
27#include <linux/if_vlan.h>
28#include <linux/pci.h>
29
Alexander Duyck0e7b3642014-09-20 19:48:10 -040030#include "fm10k_pf.h"
31
32#define FM10K_MAX_JUMBO_FRAME_SIZE 15358 /* Maximum supported size 15K */
33
Alexander Duyck18283ca2014-09-20 19:48:51 -040034struct fm10k_ring_container {
35 unsigned int total_bytes; /* total bytes processed this int */
36 unsigned int total_packets; /* total packets processed this int */
37 u16 work_limit; /* total work allowed per interrupt */
38 u16 itr; /* interrupt throttle rate value */
39 u8 count; /* total number of rings in vector */
40};
41
42#define FM10K_ITR_MAX 0x0FFF /* maximum value for ITR */
43#define FM10K_ITR_10K 100 /* 100us */
44#define FM10K_ITR_20K 50 /* 50us */
45#define FM10K_ITR_ADAPTIVE 0x8000 /* adaptive interrupt moderation flag */
46
47#define FM10K_ITR_ENABLE (FM10K_ITR_AUTOMASK | FM10K_ITR_MASK_CLEAR)
48
49#define MAX_Q_VECTORS 256
50#define MIN_Q_VECTORS 1
51enum fm10k_non_q_vectors {
52 FM10K_MBX_VECTOR,
53 NON_Q_VECTORS_PF
54};
55
56#define NON_Q_VECTORS(hw) (((hw)->mac.type == fm10k_mac_pf) ? \
57 NON_Q_VECTORS_PF : \
58 0)
59#define MIN_MSIX_COUNT(hw) (MIN_Q_VECTORS + NON_Q_VECTORS(hw))
60
61struct fm10k_q_vector {
62 struct fm10k_intfc *interface;
63 u32 __iomem *itr; /* pointer to ITR register for this vector */
64 u16 v_idx; /* index of q_vector within interface array */
65 struct fm10k_ring_container rx, tx;
66
67 struct napi_struct napi;
68 char name[IFNAMSIZ + 9];
69
70 struct rcu_head rcu; /* to avoid race with update stats on free */
71};
72
Alexander Duyck0e7b3642014-09-20 19:48:10 -040073enum fm10k_ring_f_enum {
74 RING_F_RSS,
75 RING_F_QOS,
76 RING_F_ARRAY_SIZE /* must be last in enum set */
77};
78
79struct fm10k_ring_feature {
80 u16 limit; /* upper limit on feature indices */
81 u16 indices; /* current value of indices */
82 u16 mask; /* Mask used for feature to ring mapping */
83 u16 offset; /* offset to start of feature */
84};
85
86#define fm10k_vxlan_port_for_each(vp, intfc) \
87 list_for_each_entry(vp, &(intfc)->vxlan_port, list)
88struct fm10k_vxlan_port {
89 struct list_head list;
90 sa_family_t sa_family;
91 __be16 port;
92};
Alexander Duyck04a5aef2014-09-20 19:46:45 -040093
94struct fm10k_intfc {
Alexander Duyck0e7b3642014-09-20 19:48:10 -040095 unsigned long active_vlans[BITS_TO_LONGS(VLAN_N_VID)];
96 struct net_device *netdev;
Alexander Duyck04a5aef2014-09-20 19:46:45 -040097 struct pci_dev *pdev;
Alexander Duyck0e7b3642014-09-20 19:48:10 -040098 unsigned long state;
Alexander Duyck04a5aef2014-09-20 19:46:45 -040099
Alexander Duyck0e7b3642014-09-20 19:48:10 -0400100 u32 flags;
101#define FM10K_FLAG_RESET_REQUESTED (u32)(1 << 0)
102#define FM10K_FLAG_RSS_FIELD_IPV4_UDP (u32)(1 << 1)
103#define FM10K_FLAG_RSS_FIELD_IPV6_UDP (u32)(1 << 2)
104#define FM10K_FLAG_RX_TS_ENABLED (u32)(1 << 3)
105#define FM10K_FLAG_SWPRI_CONFIG (u32)(1 << 4)
106 int xcast_mode;
107
Alexander Duyck18283ca2014-09-20 19:48:51 -0400108 /* Tx fast path data */
109 int num_tx_queues;
110 u16 tx_itr;
111
112 /* Rx fast path data */
113 int num_rx_queues;
114 u16 rx_itr;
115
Alexander Duyck0e7b3642014-09-20 19:48:10 -0400116 u64 rx_overrun_pf;
117 u64 rx_overrun_vf;
118
Alexander Duyck18283ca2014-09-20 19:48:51 -0400119 /* Queueing vectors */
120 struct fm10k_q_vector *q_vector[MAX_Q_VECTORS];
121 struct msix_entry *msix_entries;
122 int num_q_vectors; /* current number of q_vectors for device */
Alexander Duyck0e7b3642014-09-20 19:48:10 -0400123 struct fm10k_ring_feature ring_feature[RING_F_ARRAY_SIZE];
124
125 struct fm10k_hw_stats stats;
Alexander Duyck04a5aef2014-09-20 19:46:45 -0400126 struct fm10k_hw hw;
127 u32 __iomem *uc_addr;
Alexander Duyck0e7b3642014-09-20 19:48:10 -0400128 u16 msg_enable;
Alexander Duyck18283ca2014-09-20 19:48:51 -0400129 u16 tx_ring_count;
130 u16 rx_ring_count;
Alexander Duyck0e7b3642014-09-20 19:48:10 -0400131
132 u32 reta[FM10K_RETA_SIZE];
133 u32 rssrk[FM10K_RSSRK_SIZE];
134
135 /* VXLAN port tracking information */
136 struct list_head vxlan_port;
137
138#if defined(HAVE_DCBNL_IEEE) && defined(CONFIG_DCB)
139 u8 pfc_en;
140#endif
141 u8 rx_pause;
142
143 /* GLORT resources in use by PF */
144 u16 glort;
145 u16 glort_count;
146
147 /* VLAN ID for updating multicast/unicast lists */
148 u16 vid;
Alexander Duyck04a5aef2014-09-20 19:46:45 -0400149};
Alexander Duyckb3890e32014-09-20 19:46:05 -0400150
Alexander Duyck0e7b3642014-09-20 19:48:10 -0400151enum fm10k_state_t {
152 __FM10K_RESETTING,
153 __FM10K_DOWN,
154 __FM10K_MBX_LOCK,
155 __FM10K_LINK_DOWN,
156};
157
158static inline void fm10k_mbx_lock(struct fm10k_intfc *interface)
159{
160 /* busy loop if we cannot obtain the lock as some calls
161 * such as ndo_set_rx_mode may be made in atomic context
162 */
163 while (test_and_set_bit(__FM10K_MBX_LOCK, &interface->state))
164 udelay(20);
165}
166
167static inline void fm10k_mbx_unlock(struct fm10k_intfc *interface)
168{
169 /* flush memory to make sure state is correct */
170 smp_mb__before_atomic();
171 clear_bit(__FM10K_MBX_LOCK, &interface->state);
172}
173
174static inline int fm10k_mbx_trylock(struct fm10k_intfc *interface)
175{
176 return !test_and_set_bit(__FM10K_MBX_LOCK, &interface->state);
177}
178
Alexander Duyckb3890e32014-09-20 19:46:05 -0400179/* main */
180extern char fm10k_driver_name[];
181extern const char fm10k_driver_version[];
Alexander Duyck18283ca2014-09-20 19:48:51 -0400182int fm10k_init_queueing_scheme(struct fm10k_intfc *interface);
183void fm10k_clear_queueing_scheme(struct fm10k_intfc *interface);
Alexander Duyckb3890e32014-09-20 19:46:05 -0400184
185/* PCI */
Alexander Duyck18283ca2014-09-20 19:48:51 -0400186void fm10k_mbx_free_irq(struct fm10k_intfc *);
187int fm10k_mbx_request_irq(struct fm10k_intfc *);
188void fm10k_qv_free_irq(struct fm10k_intfc *interface);
189int fm10k_qv_request_irq(struct fm10k_intfc *interface);
Alexander Duyckb3890e32014-09-20 19:46:05 -0400190int fm10k_register_pci_driver(void);
191void fm10k_unregister_pci_driver(void);
Alexander Duyck504c5ea2014-09-20 19:48:29 -0400192void fm10k_up(struct fm10k_intfc *interface);
193void fm10k_down(struct fm10k_intfc *interface);
Alexander Duyck0e7b3642014-09-20 19:48:10 -0400194
195/* Netdev */
196struct net_device *fm10k_alloc_netdev(void);
Alexander Duyck8f5e20d2014-09-20 19:48:20 -0400197void fm10k_restore_rx_state(struct fm10k_intfc *);
198void fm10k_reset_rx_state(struct fm10k_intfc *);
Alexander Duyck504c5ea2014-09-20 19:48:29 -0400199int fm10k_open(struct net_device *netdev);
200int fm10k_close(struct net_device *netdev);
Alexander Duyckb3890e32014-09-20 19:46:05 -0400201#endif /* _FM10K_H_ */