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 
46a6a5580cSJeff Kirsher struct enic_msix_entry {
47a6a5580cSJeff Kirsher 	int requested;
48a6a5580cSJeff Kirsher 	char devname[IFNAMSIZ];
49a6a5580cSJeff Kirsher 	irqreturn_t (*isr)(int, void *);
50a6a5580cSJeff Kirsher 	void *devid;
51a6a5580cSJeff Kirsher };
52a6a5580cSJeff Kirsher 
538749b427SRoopa Prabhu /* priv_flags */
548749b427SRoopa Prabhu #define ENIC_SRIOV_ENABLED		(1 << 0)
558749b427SRoopa Prabhu 
568749b427SRoopa Prabhu /* enic port profile set flags */
57a6a5580cSJeff Kirsher #define ENIC_PORT_REQUEST_APPLIED	(1 << 0)
58a6a5580cSJeff Kirsher #define ENIC_SET_REQUEST		(1 << 1)
59a6a5580cSJeff Kirsher #define ENIC_SET_NAME			(1 << 2)
60a6a5580cSJeff Kirsher #define ENIC_SET_INSTANCE		(1 << 3)
61a6a5580cSJeff Kirsher #define ENIC_SET_HOST			(1 << 4)
62a6a5580cSJeff Kirsher 
63a6a5580cSJeff Kirsher struct enic_port_profile {
64a6a5580cSJeff Kirsher 	u32 set;
65a6a5580cSJeff Kirsher 	u8 request;
66a6a5580cSJeff Kirsher 	char name[PORT_PROFILE_MAX];
67a6a5580cSJeff Kirsher 	u8 instance_uuid[PORT_UUID_MAX];
68a6a5580cSJeff Kirsher 	u8 host_uuid[PORT_UUID_MAX];
69a6a5580cSJeff Kirsher 	u8 vf_mac[ETH_ALEN];
70a6a5580cSJeff Kirsher 	u8 mac_addr[ETH_ALEN];
71a6a5580cSJeff Kirsher };
72a6a5580cSJeff Kirsher 
73a6a5580cSJeff Kirsher /* Per-instance private data structure */
74a6a5580cSJeff Kirsher struct enic {
75a6a5580cSJeff Kirsher 	struct net_device *netdev;
76a6a5580cSJeff Kirsher 	struct pci_dev *pdev;
77a6a5580cSJeff Kirsher 	struct vnic_enet_config config;
78a6a5580cSJeff Kirsher 	struct vnic_dev_bar bar[ENIC_BARS_MAX];
79a6a5580cSJeff Kirsher 	struct vnic_dev *vdev;
80a6a5580cSJeff Kirsher 	struct timer_list notify_timer;
81a6a5580cSJeff Kirsher 	struct work_struct reset;
82a6a5580cSJeff Kirsher 	struct work_struct change_mtu_work;
83a6a5580cSJeff Kirsher 	struct msix_entry msix_entry[ENIC_INTR_MAX];
84a6a5580cSJeff Kirsher 	struct enic_msix_entry msix[ENIC_INTR_MAX];
85a6a5580cSJeff Kirsher 	u32 msg_enable;
86a6a5580cSJeff Kirsher 	spinlock_t devcmd_lock;
87a6a5580cSJeff Kirsher 	u8 mac_addr[ETH_ALEN];
88a6a5580cSJeff Kirsher 	u8 mc_addr[ENIC_MULTICAST_PERFECT_FILTERS][ETH_ALEN];
89a6a5580cSJeff Kirsher 	u8 uc_addr[ENIC_UNICAST_PERFECT_FILTERS][ETH_ALEN];
90a6a5580cSJeff Kirsher 	unsigned int flags;
918749b427SRoopa Prabhu 	unsigned int priv_flags;
92a6a5580cSJeff Kirsher 	unsigned int mc_count;
93a6a5580cSJeff Kirsher 	unsigned int uc_count;
94a6a5580cSJeff Kirsher 	u32 port_mtu;
95a6a5580cSJeff Kirsher 	u32 rx_coalesce_usecs;
96a6a5580cSJeff Kirsher 	u32 tx_coalesce_usecs;
978749b427SRoopa Prabhu #ifdef CONFIG_PCI_IOV
98413708bbSDan Carpenter 	u16 num_vfs;
998749b427SRoopa Prabhu #endif
1000b038566SNeel Patel 	spinlock_t enic_api_lock;
1013f192795SRoopa Prabhu 	struct enic_port_profile *pp;
102a6a5580cSJeff Kirsher 
103a6a5580cSJeff Kirsher 	/* work queue cache line section */
104a6a5580cSJeff Kirsher 	____cacheline_aligned struct vnic_wq wq[ENIC_WQ_MAX];
105a6a5580cSJeff Kirsher 	spinlock_t wq_lock[ENIC_WQ_MAX];
106a6a5580cSJeff Kirsher 	unsigned int wq_count;
107a6a5580cSJeff Kirsher 	u16 loop_enable;
108a6a5580cSJeff Kirsher 	u16 loop_tag;
109a6a5580cSJeff Kirsher 
110a6a5580cSJeff Kirsher 	/* receive queue cache line section */
111a6a5580cSJeff Kirsher 	____cacheline_aligned struct vnic_rq rq[ENIC_RQ_MAX];
112a6a5580cSJeff Kirsher 	unsigned int rq_count;
113a6a5580cSJeff Kirsher 	u64 rq_truncated_pkts;
114a6a5580cSJeff Kirsher 	u64 rq_bad_fcs;
115a6a5580cSJeff Kirsher 	struct napi_struct napi[ENIC_RQ_MAX];
116a6a5580cSJeff Kirsher 
117a6a5580cSJeff Kirsher 	/* interrupt resource cache line section */
118a6a5580cSJeff Kirsher 	____cacheline_aligned struct vnic_intr intr[ENIC_INTR_MAX];
119a6a5580cSJeff Kirsher 	unsigned int intr_count;
120a6a5580cSJeff Kirsher 	u32 __iomem *legacy_pba;		/* memory-mapped */
121a6a5580cSJeff Kirsher 
122a6a5580cSJeff Kirsher 	/* completion queue cache line section */
123a6a5580cSJeff Kirsher 	____cacheline_aligned struct vnic_cq cq[ENIC_CQ_MAX];
124a6a5580cSJeff Kirsher 	unsigned int cq_count;
125a6a5580cSJeff Kirsher };
126a6a5580cSJeff Kirsher 
127a6a5580cSJeff Kirsher static inline struct device *enic_get_dev(struct enic *enic)
128a6a5580cSJeff Kirsher {
129a6a5580cSJeff Kirsher 	return &(enic->pdev->dev);
130a6a5580cSJeff Kirsher }
131a6a5580cSJeff Kirsher 
132f13bbc2fSNeel Patel static inline unsigned int enic_cq_rq(struct enic *enic, unsigned int rq)
133f13bbc2fSNeel Patel {
134f13bbc2fSNeel Patel 	return rq;
135f13bbc2fSNeel Patel }
136f13bbc2fSNeel Patel 
137f13bbc2fSNeel Patel static inline unsigned int enic_cq_wq(struct enic *enic, unsigned int wq)
138f13bbc2fSNeel Patel {
139f13bbc2fSNeel Patel 	return enic->rq_count + wq;
140f13bbc2fSNeel Patel }
141f13bbc2fSNeel Patel 
142f13bbc2fSNeel Patel static inline unsigned int enic_legacy_io_intr(void)
143f13bbc2fSNeel Patel {
144f13bbc2fSNeel Patel 	return 0;
145f13bbc2fSNeel Patel }
146f13bbc2fSNeel Patel 
147f13bbc2fSNeel Patel static inline unsigned int enic_legacy_err_intr(void)
148f13bbc2fSNeel Patel {
149f13bbc2fSNeel Patel 	return 1;
150f13bbc2fSNeel Patel }
151f13bbc2fSNeel Patel 
152f13bbc2fSNeel Patel static inline unsigned int enic_legacy_notify_intr(void)
153f13bbc2fSNeel Patel {
154f13bbc2fSNeel Patel 	return 2;
155f13bbc2fSNeel Patel }
156f13bbc2fSNeel Patel 
157f13bbc2fSNeel Patel static inline unsigned int enic_msix_rq_intr(struct enic *enic,
158f13bbc2fSNeel Patel 	unsigned int rq)
159f13bbc2fSNeel Patel {
160f13bbc2fSNeel Patel 	return enic->cq[enic_cq_rq(enic, rq)].interrupt_offset;
161f13bbc2fSNeel Patel }
162f13bbc2fSNeel Patel 
163f13bbc2fSNeel Patel static inline unsigned int enic_msix_wq_intr(struct enic *enic,
164f13bbc2fSNeel Patel 	unsigned int wq)
165f13bbc2fSNeel Patel {
166f13bbc2fSNeel Patel 	return enic->cq[enic_cq_wq(enic, wq)].interrupt_offset;
167f13bbc2fSNeel Patel }
168f13bbc2fSNeel Patel 
169f13bbc2fSNeel Patel static inline unsigned int enic_msix_err_intr(struct enic *enic)
170f13bbc2fSNeel Patel {
171f13bbc2fSNeel Patel 	return enic->rq_count + enic->wq_count;
172f13bbc2fSNeel Patel }
173f13bbc2fSNeel Patel 
174f13bbc2fSNeel Patel static inline unsigned int enic_msix_notify_intr(struct enic *enic)
175f13bbc2fSNeel Patel {
176f13bbc2fSNeel Patel 	return enic->rq_count + enic->wq_count + 1;
177f13bbc2fSNeel Patel }
178f13bbc2fSNeel Patel 
179a6a5580cSJeff Kirsher void enic_reset_addr_lists(struct enic *enic);
1808749b427SRoopa Prabhu int enic_sriov_enabled(struct enic *enic);
181889d13f5SRoopa Prabhu int enic_is_valid_vf(struct enic *enic, int vf);
1823f192795SRoopa Prabhu int enic_is_dynamic(struct enic *enic);
183f13bbc2fSNeel Patel void enic_set_ethtool_ops(struct net_device *netdev);
184a6a5580cSJeff Kirsher 
185a6a5580cSJeff Kirsher #endif /* _ENIC_H_ */
186