xref: /linux/drivers/net/ethernet/cisco/enic/vnic_dev.h (revision f14aa5ea415b8add245e976bfab96a12986c6843)
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  * Copyright 2008-2010 Cisco Systems, Inc.  All rights reserved.
4  * Copyright 2007 Nuova Systems, Inc.  All rights reserved.
5  */
6 
7 #ifndef _VNIC_DEV_H_
8 #define _VNIC_DEV_H_
9 
10 #include "vnic_resource.h"
11 #include "vnic_devcmd.h"
12 
13 #ifndef VNIC_PADDR_TARGET
14 #define VNIC_PADDR_TARGET	0x0000000000000000ULL
15 #endif
16 
17 #ifndef readq
18 static inline u64 readq(void __iomem *reg)
19 {
20 	return (((u64)readl(reg + 0x4UL) << 32) |
21 		(u64)readl(reg));
22 }
23 
24 static inline void writeq(u64 val, void __iomem *reg)
25 {
26 	writel(val & 0xffffffff, reg);
27 	writel(val >> 32, reg + 0x4UL);
28 }
29 #endif
30 
31 #undef pr_fmt
32 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
33 
34 #define VNIC_DESC_SIZE_ALIGN	16
35 #define VNIC_DESC_COUNT_ALIGN	32
36 #define VNIC_DESC_BASE_ALIGN	512
37 #define VNIC_DESC_MAX_COUNT	4096
38 
39 enum vnic_dev_intr_mode {
40 	VNIC_DEV_INTR_MODE_UNKNOWN,
41 	VNIC_DEV_INTR_MODE_INTX,
42 	VNIC_DEV_INTR_MODE_MSI,
43 	VNIC_DEV_INTR_MODE_MSIX,
44 };
45 
46 struct vnic_dev_bar {
47 	void __iomem *vaddr;
48 	dma_addr_t bus_addr;
49 	unsigned long len;
50 };
51 
52 struct vnic_dev_ring {
53 	void *descs;
54 	size_t size;
55 	dma_addr_t base_addr;
56 	size_t base_align;
57 	void *descs_unaligned;
58 	size_t size_unaligned;
59 	dma_addr_t base_addr_unaligned;
60 	unsigned int desc_size;
61 	unsigned int desc_count;
62 	unsigned int desc_avail;
63 };
64 
65 enum vnic_proxy_type {
66 	PROXY_NONE,
67 	PROXY_BY_BDF,
68 	PROXY_BY_INDEX,
69 };
70 
71 struct vnic_res {
72 	void __iomem *vaddr;
73 	dma_addr_t bus_addr;
74 	unsigned int count;
75 };
76 
77 struct vnic_intr_coal_timer_info {
78 	u32 mul;
79 	u32 div;
80 	u32 max_usec;
81 };
82 
83 struct vnic_dev {
84 	void *priv;
85 	struct pci_dev *pdev;
86 	struct vnic_res res[RES_TYPE_MAX];
87 	enum vnic_dev_intr_mode intr_mode;
88 	struct vnic_devcmd __iomem *devcmd;
89 	struct vnic_devcmd_notify *notify;
90 	struct vnic_devcmd_notify notify_copy;
91 	dma_addr_t notify_pa;
92 	u32 notify_sz;
93 	dma_addr_t linkstatus_pa;
94 	struct vnic_stats *stats;
95 	dma_addr_t stats_pa;
96 	struct vnic_devcmd_fw_info *fw_info;
97 	dma_addr_t fw_info_pa;
98 	enum vnic_proxy_type proxy;
99 	u32 proxy_index;
100 	u64 args[VNIC_DEVCMD_NARGS];
101 	struct vnic_intr_coal_timer_info intr_coal_timer_info;
102 	struct devcmd2_controller *devcmd2;
103 	int (*devcmd_rtn)(struct vnic_dev *vdev, enum vnic_devcmd_cmd cmd,
104 			  int wait);
105 };
106 
107 struct vnic_stats;
108 
109 void *vnic_dev_priv(struct vnic_dev *vdev);
110 unsigned int vnic_dev_get_res_count(struct vnic_dev *vdev,
111 	enum vnic_res_type type);
112 void __iomem *vnic_dev_get_res(struct vnic_dev *vdev, enum vnic_res_type type,
113 	unsigned int index);
114 void vnic_dev_clear_desc_ring(struct vnic_dev_ring *ring);
115 int vnic_dev_alloc_desc_ring(struct vnic_dev *vdev, struct vnic_dev_ring *ring,
116 	unsigned int desc_count, unsigned int desc_size);
117 void vnic_dev_free_desc_ring(struct vnic_dev *vdev,
118 	struct vnic_dev_ring *ring);
119 int vnic_dev_cmd(struct vnic_dev *vdev, enum vnic_devcmd_cmd cmd,
120 	u64 *a0, u64 *a1, int wait);
121 void vnic_dev_cmd_proxy_by_index_start(struct vnic_dev *vdev, u16 index);
122 void vnic_dev_cmd_proxy_end(struct vnic_dev *vdev);
123 int vnic_dev_fw_info(struct vnic_dev *vdev,
124 	struct vnic_devcmd_fw_info **fw_info);
125 int vnic_dev_spec(struct vnic_dev *vdev, unsigned int offset, unsigned int size,
126 	void *value);
127 int vnic_dev_stats_dump(struct vnic_dev *vdev, struct vnic_stats **stats);
128 int vnic_dev_hang_notify(struct vnic_dev *vdev);
129 int vnic_dev_packet_filter(struct vnic_dev *vdev, int directed, int multicast,
130 	int broadcast, int promisc, int allmulti);
131 int vnic_dev_add_addr(struct vnic_dev *vdev, const u8 *addr);
132 int vnic_dev_del_addr(struct vnic_dev *vdev, const u8 *addr);
133 int vnic_dev_get_mac_addr(struct vnic_dev *vdev, u8 *mac_addr);
134 int vnic_dev_notify_set(struct vnic_dev *vdev, u16 intr);
135 int vnic_dev_notify_unset(struct vnic_dev *vdev);
136 int vnic_dev_link_status(struct vnic_dev *vdev);
137 u32 vnic_dev_port_speed(struct vnic_dev *vdev);
138 u32 vnic_dev_msg_lvl(struct vnic_dev *vdev);
139 u32 vnic_dev_mtu(struct vnic_dev *vdev);
140 int vnic_dev_close(struct vnic_dev *vdev);
141 int vnic_dev_enable_wait(struct vnic_dev *vdev);
142 int vnic_dev_disable(struct vnic_dev *vdev);
143 int vnic_dev_open(struct vnic_dev *vdev, int arg);
144 int vnic_dev_open_done(struct vnic_dev *vdev, int *done);
145 int vnic_dev_init(struct vnic_dev *vdev, int arg);
146 int vnic_dev_deinit(struct vnic_dev *vdev);
147 void vnic_dev_intr_coal_timer_info_default(struct vnic_dev *vdev);
148 int vnic_dev_intr_coal_timer_info(struct vnic_dev *vdev);
149 int vnic_dev_hang_reset(struct vnic_dev *vdev, int arg);
150 int vnic_dev_soft_reset(struct vnic_dev *vdev, int arg);
151 int vnic_dev_hang_reset_done(struct vnic_dev *vdev, int *done);
152 int vnic_dev_soft_reset_done(struct vnic_dev *vdev, int *done);
153 void vnic_dev_set_intr_mode(struct vnic_dev *vdev,
154 	enum vnic_dev_intr_mode intr_mode);
155 enum vnic_dev_intr_mode vnic_dev_get_intr_mode(struct vnic_dev *vdev);
156 u32 vnic_dev_intr_coal_timer_usec_to_hw(struct vnic_dev *vdev, u32 usec);
157 u32 vnic_dev_intr_coal_timer_hw_to_usec(struct vnic_dev *vdev, u32 hw_cycles);
158 u32 vnic_dev_get_intr_coal_timer_max(struct vnic_dev *vdev);
159 void vnic_dev_unregister(struct vnic_dev *vdev);
160 int vnic_dev_set_ig_vlan_rewrite_mode(struct vnic_dev *vdev,
161 	u8 ig_vlan_rewrite_mode);
162 struct vnic_dev *vnic_dev_register(struct vnic_dev *vdev,
163 	void *priv, struct pci_dev *pdev, struct vnic_dev_bar *bar,
164 	unsigned int num_bars);
165 struct pci_dev *vnic_dev_get_pdev(struct vnic_dev *vdev);
166 int vnic_dev_init_prov2(struct vnic_dev *vdev, u8 *buf, u32 len);
167 int vnic_dev_enable2(struct vnic_dev *vdev, int active);
168 int vnic_dev_enable2_done(struct vnic_dev *vdev, int *status);
169 int vnic_dev_deinit_done(struct vnic_dev *vdev, int *status);
170 int vnic_dev_set_mac_addr(struct vnic_dev *vdev, u8 *mac_addr);
171 int vnic_dev_classifier(struct vnic_dev *vdev, u8 cmd, u16 *entry,
172 			struct filter *data);
173 int vnic_devcmd_init(struct vnic_dev *vdev);
174 int vnic_dev_overlay_offload_ctrl(struct vnic_dev *vdev, u8 overlay, u8 config);
175 int vnic_dev_overlay_offload_cfg(struct vnic_dev *vdev, u8 overlay,
176 				 u16 vxlan_udp_port_number);
177 int vnic_dev_get_supported_feature_ver(struct vnic_dev *vdev, u8 feature,
178 				       u64 *supported_versions, u64 *a1);
179 int vnic_dev_capable_rss_hash_type(struct vnic_dev *vdev, u8 *rss_hash_type);
180 
181 #endif /* _VNIC_DEV_H_ */
182