1a6a5580cSJeff Kirsher /*
2a6a5580cSJeff Kirsher  * Copyright 2008-2010 Cisco Systems, Inc.  All rights reserved.
3a6a5580cSJeff Kirsher  * Copyright 2007 Nuova Systems, Inc.  All rights reserved.
4a6a5580cSJeff Kirsher  *
5a6a5580cSJeff Kirsher  * This program is free software; you may redistribute it and/or modify
6a6a5580cSJeff Kirsher  * it under the terms of the GNU General Public License as published by
7a6a5580cSJeff Kirsher  * the Free Software Foundation; version 2 of the License.
8a6a5580cSJeff Kirsher  *
9a6a5580cSJeff Kirsher  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
10a6a5580cSJeff Kirsher  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
11a6a5580cSJeff Kirsher  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
12a6a5580cSJeff Kirsher  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
13a6a5580cSJeff Kirsher  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
14a6a5580cSJeff Kirsher  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
15a6a5580cSJeff Kirsher  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
16a6a5580cSJeff Kirsher  * SOFTWARE.
17a6a5580cSJeff Kirsher  *
18a6a5580cSJeff Kirsher  */
19a6a5580cSJeff Kirsher 
20a6a5580cSJeff Kirsher #ifndef _ENIC_H_
21a6a5580cSJeff Kirsher #define _ENIC_H_
22a6a5580cSJeff Kirsher 
23a6a5580cSJeff Kirsher #include "vnic_enet.h"
24a6a5580cSJeff Kirsher #include "vnic_dev.h"
25a6a5580cSJeff Kirsher #include "vnic_wq.h"
26a6a5580cSJeff Kirsher #include "vnic_rq.h"
27a6a5580cSJeff Kirsher #include "vnic_cq.h"
28a6a5580cSJeff Kirsher #include "vnic_intr.h"
29a6a5580cSJeff Kirsher #include "vnic_stats.h"
30a6a5580cSJeff Kirsher #include "vnic_nic.h"
31a6a5580cSJeff Kirsher #include "vnic_rss.h"
32fef1f07cSJosh Boyer #include <linux/irq.h>
33a6a5580cSJeff Kirsher 
34a6a5580cSJeff Kirsher #define DRV_NAME		"enic"
35a6a5580cSJeff Kirsher #define DRV_DESCRIPTION		"Cisco VIC Ethernet NIC Driver"
36001e1c1dSgovindarajulu.v #define DRV_VERSION		"2.1.1.50"
3792e2b469SNeel Patel #define DRV_COPYRIGHT		"Copyright 2008-2013 Cisco Systems, Inc"
38a6a5580cSJeff Kirsher 
39a6a5580cSJeff Kirsher #define ENIC_BARS_MAX		6
40a6a5580cSJeff Kirsher 
41822473b6Sgovindarajulu.v #define ENIC_WQ_MAX		8
4263da93d9SNeel Patel #define ENIC_RQ_MAX		8
43a6a5580cSJeff Kirsher #define ENIC_CQ_MAX		(ENIC_WQ_MAX + ENIC_RQ_MAX)
44a6a5580cSJeff Kirsher #define ENIC_INTR_MAX		(ENIC_CQ_MAX + 2)
45a6a5580cSJeff Kirsher 
467c2ce6e6SSujith Sankar #define ENIC_AIC_LARGE_PKT_DIFF	3
477c2ce6e6SSujith Sankar 
48a6a5580cSJeff Kirsher struct enic_msix_entry {
49a6a5580cSJeff Kirsher 	int requested;
50a6a5580cSJeff Kirsher 	char devname[IFNAMSIZ];
51a6a5580cSJeff Kirsher 	irqreturn_t (*isr)(int, void *);
52a6a5580cSJeff Kirsher 	void *devid;
53a6a5580cSJeff Kirsher };
54a6a5580cSJeff Kirsher 
557c2ce6e6SSujith Sankar /* Store only the lower range.  Higher range is given by fw. */
567c2ce6e6SSujith Sankar struct enic_intr_mod_range {
577c2ce6e6SSujith Sankar 	u32 small_pkt_range_start;
587c2ce6e6SSujith Sankar 	u32 large_pkt_range_start;
597c2ce6e6SSujith Sankar };
607c2ce6e6SSujith Sankar 
617c2ce6e6SSujith Sankar struct enic_intr_mod_table {
627c2ce6e6SSujith Sankar 	u32 rx_rate;
637c2ce6e6SSujith Sankar 	u32 range_percent;
647c2ce6e6SSujith Sankar };
657c2ce6e6SSujith Sankar 
667c2ce6e6SSujith Sankar #define ENIC_MAX_LINK_SPEEDS		3
677c2ce6e6SSujith Sankar #define ENIC_LINK_SPEED_10G		10000
687c2ce6e6SSujith Sankar #define ENIC_LINK_SPEED_4G		4000
697c2ce6e6SSujith Sankar #define ENIC_LINK_40G_INDEX		2
707c2ce6e6SSujith Sankar #define ENIC_LINK_10G_INDEX		1
717c2ce6e6SSujith Sankar #define ENIC_LINK_4G_INDEX		0
727c2ce6e6SSujith Sankar #define ENIC_RX_COALESCE_RANGE_END	125
737c2ce6e6SSujith Sankar #define ENIC_AIC_TS_BREAK		100
747c2ce6e6SSujith Sankar 
757c2ce6e6SSujith Sankar struct enic_rx_coal {
767c2ce6e6SSujith Sankar 	u32 small_pkt_range_start;
777c2ce6e6SSujith Sankar 	u32 large_pkt_range_start;
787c2ce6e6SSujith Sankar 	u32 range_end;
797c2ce6e6SSujith Sankar 	u32 use_adaptive_rx_coalesce;
807c2ce6e6SSujith Sankar };
817c2ce6e6SSujith Sankar 
828749b427SRoopa Prabhu /* priv_flags */
838749b427SRoopa Prabhu #define ENIC_SRIOV_ENABLED		(1 << 0)
848749b427SRoopa Prabhu 
858749b427SRoopa Prabhu /* enic port profile set flags */
86a6a5580cSJeff Kirsher #define ENIC_PORT_REQUEST_APPLIED	(1 << 0)
87a6a5580cSJeff Kirsher #define ENIC_SET_REQUEST		(1 << 1)
88a6a5580cSJeff Kirsher #define ENIC_SET_NAME			(1 << 2)
89a6a5580cSJeff Kirsher #define ENIC_SET_INSTANCE		(1 << 3)
90a6a5580cSJeff Kirsher #define ENIC_SET_HOST			(1 << 4)
91a6a5580cSJeff Kirsher 
92a6a5580cSJeff Kirsher struct enic_port_profile {
93a6a5580cSJeff Kirsher 	u32 set;
94a6a5580cSJeff Kirsher 	u8 request;
95a6a5580cSJeff Kirsher 	char name[PORT_PROFILE_MAX];
96a6a5580cSJeff Kirsher 	u8 instance_uuid[PORT_UUID_MAX];
97a6a5580cSJeff Kirsher 	u8 host_uuid[PORT_UUID_MAX];
98a6a5580cSJeff Kirsher 	u8 vf_mac[ETH_ALEN];
99a6a5580cSJeff Kirsher 	u8 mac_addr[ETH_ALEN];
100a6a5580cSJeff Kirsher };
101a6a5580cSJeff Kirsher 
102a145df23SGovindarajulu Varadarajan #ifdef CONFIG_RFS_ACCEL
103a145df23SGovindarajulu Varadarajan /* enic_rfs_fltr_node - rfs filter node in hash table
104a145df23SGovindarajulu Varadarajan  *	@@keys: IPv4 5 tuple
105a145df23SGovindarajulu Varadarajan  *	@flow_id: flow_id of clsf filter provided by kernel
106a145df23SGovindarajulu Varadarajan  *	@fltr_id: filter id of clsf filter returned by adaptor
107a145df23SGovindarajulu Varadarajan  *	@rq_id: desired rq index
108a145df23SGovindarajulu Varadarajan  *	@node: hlist_node
109a145df23SGovindarajulu Varadarajan  */
110a145df23SGovindarajulu Varadarajan struct enic_rfs_fltr_node {
111a145df23SGovindarajulu Varadarajan 	struct flow_keys keys;
112a145df23SGovindarajulu Varadarajan 	u32 flow_id;
113a145df23SGovindarajulu Varadarajan 	u16 fltr_id;
114a145df23SGovindarajulu Varadarajan 	u16 rq_id;
115a145df23SGovindarajulu Varadarajan 	struct hlist_node node;
116a145df23SGovindarajulu Varadarajan };
117a145df23SGovindarajulu Varadarajan 
118a145df23SGovindarajulu Varadarajan /* enic_rfs_flw_tbl - rfs flow table
119a145df23SGovindarajulu Varadarajan  *	@max: Maximum number of filters vNIC supports
120a145df23SGovindarajulu Varadarajan  *	@free: Number of free filters available
121a145df23SGovindarajulu Varadarajan  *	@toclean: hash table index to clean next
122a145df23SGovindarajulu Varadarajan  *	@ht_head: hash table list head
123a145df23SGovindarajulu Varadarajan  *	@lock: spin lock
124a145df23SGovindarajulu Varadarajan  *	@rfs_may_expire: timer function for enic_rps_may_expire_flow
125a145df23SGovindarajulu Varadarajan  */
126a145df23SGovindarajulu Varadarajan struct enic_rfs_flw_tbl {
127a145df23SGovindarajulu Varadarajan 	u16 max;
128a145df23SGovindarajulu Varadarajan 	int free;
129a145df23SGovindarajulu Varadarajan 
130a145df23SGovindarajulu Varadarajan #define ENIC_RFS_FLW_BITSHIFT	(10)
131a145df23SGovindarajulu Varadarajan #define ENIC_RFS_FLW_MASK	((1 << ENIC_RFS_FLW_BITSHIFT) - 1)
132a145df23SGovindarajulu Varadarajan 	u16 toclean:ENIC_RFS_FLW_BITSHIFT;
133a145df23SGovindarajulu Varadarajan 	struct hlist_head ht_head[1 << ENIC_RFS_FLW_BITSHIFT];
134a145df23SGovindarajulu Varadarajan 	spinlock_t lock;
135a145df23SGovindarajulu Varadarajan 	struct timer_list rfs_may_expire;
136a145df23SGovindarajulu Varadarajan };
137a145df23SGovindarajulu Varadarajan 
138a145df23SGovindarajulu Varadarajan #endif /* CONFIG_RFS_ACCEL */
139a145df23SGovindarajulu Varadarajan 
140a6a5580cSJeff Kirsher /* Per-instance private data structure */
141a6a5580cSJeff Kirsher struct enic {
142a6a5580cSJeff Kirsher 	struct net_device *netdev;
143a6a5580cSJeff Kirsher 	struct pci_dev *pdev;
144a6a5580cSJeff Kirsher 	struct vnic_enet_config config;
145a6a5580cSJeff Kirsher 	struct vnic_dev_bar bar[ENIC_BARS_MAX];
146a6a5580cSJeff Kirsher 	struct vnic_dev *vdev;
147a6a5580cSJeff Kirsher 	struct timer_list notify_timer;
148a6a5580cSJeff Kirsher 	struct work_struct reset;
149a6a5580cSJeff Kirsher 	struct work_struct change_mtu_work;
150a6a5580cSJeff Kirsher 	struct msix_entry msix_entry[ENIC_INTR_MAX];
151a6a5580cSJeff Kirsher 	struct enic_msix_entry msix[ENIC_INTR_MAX];
152a6a5580cSJeff Kirsher 	u32 msg_enable;
153a6a5580cSJeff Kirsher 	spinlock_t devcmd_lock;
154a6a5580cSJeff Kirsher 	u8 mac_addr[ETH_ALEN];
155a6a5580cSJeff Kirsher 	unsigned int flags;
1568749b427SRoopa Prabhu 	unsigned int priv_flags;
157a6a5580cSJeff Kirsher 	unsigned int mc_count;
158a6a5580cSJeff Kirsher 	unsigned int uc_count;
159a6a5580cSJeff Kirsher 	u32 port_mtu;
1607c2ce6e6SSujith Sankar 	struct enic_rx_coal rx_coalesce_setting;
161a6a5580cSJeff Kirsher 	u32 rx_coalesce_usecs;
162a6a5580cSJeff Kirsher 	u32 tx_coalesce_usecs;
1638749b427SRoopa Prabhu #ifdef CONFIG_PCI_IOV
164413708bbSDan Carpenter 	u16 num_vfs;
1658749b427SRoopa Prabhu #endif
1660b038566SNeel Patel 	spinlock_t enic_api_lock;
1673f192795SRoopa Prabhu 	struct enic_port_profile *pp;
168a6a5580cSJeff Kirsher 
169a6a5580cSJeff Kirsher 	/* work queue cache line section */
170a6a5580cSJeff Kirsher 	____cacheline_aligned struct vnic_wq wq[ENIC_WQ_MAX];
171a6a5580cSJeff Kirsher 	spinlock_t wq_lock[ENIC_WQ_MAX];
172a6a5580cSJeff Kirsher 	unsigned int wq_count;
173a6a5580cSJeff Kirsher 	u16 loop_enable;
174a6a5580cSJeff Kirsher 	u16 loop_tag;
175a6a5580cSJeff Kirsher 
176a6a5580cSJeff Kirsher 	/* receive queue cache line section */
177a6a5580cSJeff Kirsher 	____cacheline_aligned struct vnic_rq rq[ENIC_RQ_MAX];
178a6a5580cSJeff Kirsher 	unsigned int rq_count;
179a6a5580cSJeff Kirsher 	u64 rq_truncated_pkts;
180a6a5580cSJeff Kirsher 	u64 rq_bad_fcs;
181a6a5580cSJeff Kirsher 	struct napi_struct napi[ENIC_RQ_MAX];
182a6a5580cSJeff Kirsher 
183a6a5580cSJeff Kirsher 	/* interrupt resource cache line section */
184a6a5580cSJeff Kirsher 	____cacheline_aligned struct vnic_intr intr[ENIC_INTR_MAX];
185a6a5580cSJeff Kirsher 	unsigned int intr_count;
186a6a5580cSJeff Kirsher 	u32 __iomem *legacy_pba;		/* memory-mapped */
187a6a5580cSJeff Kirsher 
188a6a5580cSJeff Kirsher 	/* completion queue cache line section */
189a6a5580cSJeff Kirsher 	____cacheline_aligned struct vnic_cq cq[ENIC_CQ_MAX];
190a6a5580cSJeff Kirsher 	unsigned int cq_count;
191a145df23SGovindarajulu Varadarajan #ifdef CONFIG_RFS_ACCEL
192a145df23SGovindarajulu Varadarajan 	struct enic_rfs_flw_tbl rfs_h;
193a145df23SGovindarajulu Varadarajan #endif
194a6a5580cSJeff Kirsher };
195a6a5580cSJeff Kirsher 
196a6a5580cSJeff Kirsher static inline struct device *enic_get_dev(struct enic *enic)
197a6a5580cSJeff Kirsher {
198a6a5580cSJeff Kirsher 	return &(enic->pdev->dev);
199a6a5580cSJeff Kirsher }
200a6a5580cSJeff Kirsher 
201f13bbc2fSNeel Patel static inline unsigned int enic_cq_rq(struct enic *enic, unsigned int rq)
202f13bbc2fSNeel Patel {
203f13bbc2fSNeel Patel 	return rq;
204f13bbc2fSNeel Patel }
205f13bbc2fSNeel Patel 
206f13bbc2fSNeel Patel static inline unsigned int enic_cq_wq(struct enic *enic, unsigned int wq)
207f13bbc2fSNeel Patel {
208f13bbc2fSNeel Patel 	return enic->rq_count + wq;
209f13bbc2fSNeel Patel }
210f13bbc2fSNeel Patel 
211f13bbc2fSNeel Patel static inline unsigned int enic_legacy_io_intr(void)
212f13bbc2fSNeel Patel {
213f13bbc2fSNeel Patel 	return 0;
214f13bbc2fSNeel Patel }
215f13bbc2fSNeel Patel 
216f13bbc2fSNeel Patel static inline unsigned int enic_legacy_err_intr(void)
217f13bbc2fSNeel Patel {
218f13bbc2fSNeel Patel 	return 1;
219f13bbc2fSNeel Patel }
220f13bbc2fSNeel Patel 
221f13bbc2fSNeel Patel static inline unsigned int enic_legacy_notify_intr(void)
222f13bbc2fSNeel Patel {
223f13bbc2fSNeel Patel 	return 2;
224f13bbc2fSNeel Patel }
225f13bbc2fSNeel Patel 
226f13bbc2fSNeel Patel static inline unsigned int enic_msix_rq_intr(struct enic *enic,
227f13bbc2fSNeel Patel 	unsigned int rq)
228f13bbc2fSNeel Patel {
229f13bbc2fSNeel Patel 	return enic->cq[enic_cq_rq(enic, rq)].interrupt_offset;
230f13bbc2fSNeel Patel }
231f13bbc2fSNeel Patel 
232f13bbc2fSNeel Patel static inline unsigned int enic_msix_wq_intr(struct enic *enic,
233f13bbc2fSNeel Patel 	unsigned int wq)
234f13bbc2fSNeel Patel {
235f13bbc2fSNeel Patel 	return enic->cq[enic_cq_wq(enic, wq)].interrupt_offset;
236f13bbc2fSNeel Patel }
237f13bbc2fSNeel Patel 
238f13bbc2fSNeel Patel static inline unsigned int enic_msix_err_intr(struct enic *enic)
239f13bbc2fSNeel Patel {
240f13bbc2fSNeel Patel 	return enic->rq_count + enic->wq_count;
241f13bbc2fSNeel Patel }
242f13bbc2fSNeel Patel 
243f13bbc2fSNeel Patel static inline unsigned int enic_msix_notify_intr(struct enic *enic)
244f13bbc2fSNeel Patel {
245f13bbc2fSNeel Patel 	return enic->rq_count + enic->wq_count + 1;
246f13bbc2fSNeel Patel }
247f13bbc2fSNeel Patel 
248a6a5580cSJeff Kirsher void enic_reset_addr_lists(struct enic *enic);
2498749b427SRoopa Prabhu int enic_sriov_enabled(struct enic *enic);
250889d13f5SRoopa Prabhu int enic_is_valid_vf(struct enic *enic, int vf);
2513f192795SRoopa Prabhu int enic_is_dynamic(struct enic *enic);
252f13bbc2fSNeel Patel void enic_set_ethtool_ops(struct net_device *netdev);
253a6a5580cSJeff Kirsher 
254a6a5580cSJeff Kirsher #endif /* _ENIC_H_ */
255