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