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 
102a6a5580cSJeff Kirsher /* Per-instance private data structure */
103a6a5580cSJeff Kirsher struct enic {
104a6a5580cSJeff Kirsher 	struct net_device *netdev;
105a6a5580cSJeff Kirsher 	struct pci_dev *pdev;
106a6a5580cSJeff Kirsher 	struct vnic_enet_config config;
107a6a5580cSJeff Kirsher 	struct vnic_dev_bar bar[ENIC_BARS_MAX];
108a6a5580cSJeff Kirsher 	struct vnic_dev *vdev;
109a6a5580cSJeff Kirsher 	struct timer_list notify_timer;
110a6a5580cSJeff Kirsher 	struct work_struct reset;
111a6a5580cSJeff Kirsher 	struct work_struct change_mtu_work;
112a6a5580cSJeff Kirsher 	struct msix_entry msix_entry[ENIC_INTR_MAX];
113a6a5580cSJeff Kirsher 	struct enic_msix_entry msix[ENIC_INTR_MAX];
114a6a5580cSJeff Kirsher 	u32 msg_enable;
115a6a5580cSJeff Kirsher 	spinlock_t devcmd_lock;
116a6a5580cSJeff Kirsher 	u8 mac_addr[ETH_ALEN];
117a6a5580cSJeff Kirsher 	u8 mc_addr[ENIC_MULTICAST_PERFECT_FILTERS][ETH_ALEN];
118a6a5580cSJeff Kirsher 	u8 uc_addr[ENIC_UNICAST_PERFECT_FILTERS][ETH_ALEN];
119a6a5580cSJeff Kirsher 	unsigned int flags;
1208749b427SRoopa Prabhu 	unsigned int priv_flags;
121a6a5580cSJeff Kirsher 	unsigned int mc_count;
122a6a5580cSJeff Kirsher 	unsigned int uc_count;
123a6a5580cSJeff Kirsher 	u32 port_mtu;
1247c2ce6e6SSujith Sankar 	struct enic_rx_coal rx_coalesce_setting;
125a6a5580cSJeff Kirsher 	u32 rx_coalesce_usecs;
126a6a5580cSJeff Kirsher 	u32 tx_coalesce_usecs;
1278749b427SRoopa Prabhu #ifdef CONFIG_PCI_IOV
128413708bbSDan Carpenter 	u16 num_vfs;
1298749b427SRoopa Prabhu #endif
1300b038566SNeel Patel 	spinlock_t enic_api_lock;
1313f192795SRoopa Prabhu 	struct enic_port_profile *pp;
132a6a5580cSJeff Kirsher 
133a6a5580cSJeff Kirsher 	/* work queue cache line section */
134a6a5580cSJeff Kirsher 	____cacheline_aligned struct vnic_wq wq[ENIC_WQ_MAX];
135a6a5580cSJeff Kirsher 	spinlock_t wq_lock[ENIC_WQ_MAX];
136a6a5580cSJeff Kirsher 	unsigned int wq_count;
137a6a5580cSJeff Kirsher 	u16 loop_enable;
138a6a5580cSJeff Kirsher 	u16 loop_tag;
139a6a5580cSJeff Kirsher 
140a6a5580cSJeff Kirsher 	/* receive queue cache line section */
141a6a5580cSJeff Kirsher 	____cacheline_aligned struct vnic_rq rq[ENIC_RQ_MAX];
142a6a5580cSJeff Kirsher 	unsigned int rq_count;
143a6a5580cSJeff Kirsher 	u64 rq_truncated_pkts;
144a6a5580cSJeff Kirsher 	u64 rq_bad_fcs;
145a6a5580cSJeff Kirsher 	struct napi_struct napi[ENIC_RQ_MAX];
146a6a5580cSJeff Kirsher 
147a6a5580cSJeff Kirsher 	/* interrupt resource cache line section */
148a6a5580cSJeff Kirsher 	____cacheline_aligned struct vnic_intr intr[ENIC_INTR_MAX];
149a6a5580cSJeff Kirsher 	unsigned int intr_count;
150a6a5580cSJeff Kirsher 	u32 __iomem *legacy_pba;		/* memory-mapped */
151a6a5580cSJeff Kirsher 
152a6a5580cSJeff Kirsher 	/* completion queue cache line section */
153a6a5580cSJeff Kirsher 	____cacheline_aligned struct vnic_cq cq[ENIC_CQ_MAX];
154a6a5580cSJeff Kirsher 	unsigned int cq_count;
155a6a5580cSJeff Kirsher };
156a6a5580cSJeff Kirsher 
157a6a5580cSJeff Kirsher static inline struct device *enic_get_dev(struct enic *enic)
158a6a5580cSJeff Kirsher {
159a6a5580cSJeff Kirsher 	return &(enic->pdev->dev);
160a6a5580cSJeff Kirsher }
161a6a5580cSJeff Kirsher 
162f13bbc2fSNeel Patel static inline unsigned int enic_cq_rq(struct enic *enic, unsigned int rq)
163f13bbc2fSNeel Patel {
164f13bbc2fSNeel Patel 	return rq;
165f13bbc2fSNeel Patel }
166f13bbc2fSNeel Patel 
167f13bbc2fSNeel Patel static inline unsigned int enic_cq_wq(struct enic *enic, unsigned int wq)
168f13bbc2fSNeel Patel {
169f13bbc2fSNeel Patel 	return enic->rq_count + wq;
170f13bbc2fSNeel Patel }
171f13bbc2fSNeel Patel 
172f13bbc2fSNeel Patel static inline unsigned int enic_legacy_io_intr(void)
173f13bbc2fSNeel Patel {
174f13bbc2fSNeel Patel 	return 0;
175f13bbc2fSNeel Patel }
176f13bbc2fSNeel Patel 
177f13bbc2fSNeel Patel static inline unsigned int enic_legacy_err_intr(void)
178f13bbc2fSNeel Patel {
179f13bbc2fSNeel Patel 	return 1;
180f13bbc2fSNeel Patel }
181f13bbc2fSNeel Patel 
182f13bbc2fSNeel Patel static inline unsigned int enic_legacy_notify_intr(void)
183f13bbc2fSNeel Patel {
184f13bbc2fSNeel Patel 	return 2;
185f13bbc2fSNeel Patel }
186f13bbc2fSNeel Patel 
187f13bbc2fSNeel Patel static inline unsigned int enic_msix_rq_intr(struct enic *enic,
188f13bbc2fSNeel Patel 	unsigned int rq)
189f13bbc2fSNeel Patel {
190f13bbc2fSNeel Patel 	return enic->cq[enic_cq_rq(enic, rq)].interrupt_offset;
191f13bbc2fSNeel Patel }
192f13bbc2fSNeel Patel 
193f13bbc2fSNeel Patel static inline unsigned int enic_msix_wq_intr(struct enic *enic,
194f13bbc2fSNeel Patel 	unsigned int wq)
195f13bbc2fSNeel Patel {
196f13bbc2fSNeel Patel 	return enic->cq[enic_cq_wq(enic, wq)].interrupt_offset;
197f13bbc2fSNeel Patel }
198f13bbc2fSNeel Patel 
199f13bbc2fSNeel Patel static inline unsigned int enic_msix_err_intr(struct enic *enic)
200f13bbc2fSNeel Patel {
201f13bbc2fSNeel Patel 	return enic->rq_count + enic->wq_count;
202f13bbc2fSNeel Patel }
203f13bbc2fSNeel Patel 
204f13bbc2fSNeel Patel static inline unsigned int enic_msix_notify_intr(struct enic *enic)
205f13bbc2fSNeel Patel {
206f13bbc2fSNeel Patel 	return enic->rq_count + enic->wq_count + 1;
207f13bbc2fSNeel Patel }
208f13bbc2fSNeel Patel 
209a6a5580cSJeff Kirsher void enic_reset_addr_lists(struct enic *enic);
2108749b427SRoopa Prabhu int enic_sriov_enabled(struct enic *enic);
211889d13f5SRoopa Prabhu int enic_is_valid_vf(struct enic *enic, int vf);
2123f192795SRoopa Prabhu int enic_is_dynamic(struct enic *enic);
213f13bbc2fSNeel Patel void enic_set_ethtool_ops(struct net_device *netdev);
214a6a5580cSJeff Kirsher 
215a6a5580cSJeff Kirsher #endif /* _ENIC_H_ */
216