net/enic: support drop flow action
[dpdk.git] / drivers / net / enic / enic_res.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright 2008-2017 Cisco Systems, Inc.  All rights reserved.
3  * Copyright 2007 Nuova Systems, Inc.  All rights reserved.
4  */
5
6 #include "enic_compat.h"
7 #include "rte_ethdev_driver.h"
8 #include "wq_enet_desc.h"
9 #include "rq_enet_desc.h"
10 #include "cq_enet_desc.h"
11 #include "vnic_resource.h"
12 #include "vnic_enet.h"
13 #include "vnic_dev.h"
14 #include "vnic_wq.h"
15 #include "vnic_rq.h"
16 #include "vnic_cq.h"
17 #include "vnic_intr.h"
18 #include "vnic_stats.h"
19 #include "vnic_nic.h"
20 #include "vnic_rss.h"
21 #include "enic_res.h"
22 #include "enic.h"
23
24 int enic_get_vnic_config(struct enic *enic)
25 {
26         struct vnic_enet_config *c = &enic->config;
27         int err;
28
29         err = vnic_dev_get_mac_addr(enic->vdev, enic->mac_addr);
30         if (err) {
31                 dev_err(enic_get_dev(enic),
32                         "Error getting MAC addr, %d\n", err);
33                 return err;
34         }
35
36
37 #define GET_CONFIG(m) \
38         do { \
39                 err = vnic_dev_spec(enic->vdev, \
40                         offsetof(struct vnic_enet_config, m), \
41                         sizeof(c->m), &c->m); \
42                 if (err) { \
43                         dev_err(enic_get_dev(enic), \
44                                 "Error getting %s, %d\n", #m, err); \
45                         return err; \
46                 } \
47         } while (0)
48
49         GET_CONFIG(flags);
50         GET_CONFIG(wq_desc_count);
51         GET_CONFIG(rq_desc_count);
52         GET_CONFIG(mtu);
53         GET_CONFIG(intr_timer_type);
54         GET_CONFIG(intr_mode);
55         GET_CONFIG(intr_timer_usec);
56         GET_CONFIG(loop_tag);
57         GET_CONFIG(num_arfs);
58         GET_CONFIG(max_pkt_size);
59
60         /* max packet size is only defined in newer VIC firmware
61          * and will be 0 for legacy firmware and VICs
62          */
63         if (c->max_pkt_size > ENIC_DEFAULT_RX_MAX_PKT_SIZE)
64                 enic->max_mtu = c->max_pkt_size - (ETHER_HDR_LEN + 4);
65         else
66                 enic->max_mtu = ENIC_DEFAULT_RX_MAX_PKT_SIZE
67                                 - (ETHER_HDR_LEN + 4);
68         if (c->mtu == 0)
69                 c->mtu = 1500;
70
71         enic->rte_dev->data->mtu = min_t(u16, enic->max_mtu,
72                                          max_t(u16, ENIC_MIN_MTU, c->mtu));
73
74         enic->adv_filters = vnic_dev_capable_adv_filters(enic->vdev);
75         dev_info(enic, "Advanced Filters %savailable\n", ((enic->adv_filters)
76                  ? "" : "not "));
77
78         err = vnic_dev_capable_filter_mode(enic->vdev, &enic->flow_filter_mode,
79                                            &enic->filter_actions);
80         if (err) {
81                 dev_err(enic_get_dev(enic),
82                         "Error getting filter modes, %d\n", err);
83                 return err;
84         }
85
86         dev_info(enic, "Flow api filter mode: %s Actions: %s%s%s\n",
87                 ((enic->flow_filter_mode == FILTER_DPDK_1) ? "DPDK" :
88                 ((enic->flow_filter_mode == FILTER_USNIC_IP) ? "USNIC" :
89                 ((enic->flow_filter_mode == FILTER_IPV4_5TUPLE) ? "5TUPLE" :
90                 "NONE"))),
91                 ((enic->filter_actions & FILTER_ACTION_RQ_STEERING_FLAG) ?
92                  "steer " : ""),
93                 ((enic->filter_actions & FILTER_ACTION_FILTER_ID_FLAG) ?
94                  "tag " : ""),
95                 ((enic->filter_actions & FILTER_ACTION_DROP_FLAG) ?
96                  "drop " : ""));
97
98         c->wq_desc_count =
99                 min_t(u32, ENIC_MAX_WQ_DESCS,
100                 max_t(u32, ENIC_MIN_WQ_DESCS,
101                 c->wq_desc_count));
102         c->wq_desc_count &= 0xffffffe0; /* must be aligned to groups of 32 */
103
104         c->rq_desc_count =
105                 min_t(u32, ENIC_MAX_RQ_DESCS,
106                 max_t(u32, ENIC_MIN_RQ_DESCS,
107                 c->rq_desc_count));
108         c->rq_desc_count &= 0xffffffe0; /* must be aligned to groups of 32 */
109
110         c->intr_timer_usec = min_t(u32, c->intr_timer_usec,
111                 vnic_dev_get_intr_coal_timer_max(enic->vdev));
112
113         dev_info(enic_get_dev(enic),
114                 "vNIC MAC addr %02x:%02x:%02x:%02x:%02x:%02x "
115                 "wq/rq %d/%d mtu %d, max mtu:%d\n",
116                 enic->mac_addr[0], enic->mac_addr[1], enic->mac_addr[2],
117                 enic->mac_addr[3], enic->mac_addr[4], enic->mac_addr[5],
118                 c->wq_desc_count, c->rq_desc_count,
119                 enic->rte_dev->data->mtu, enic->max_mtu);
120         dev_info(enic_get_dev(enic), "vNIC csum tx/rx %s/%s "
121                 "rss %s intr mode %s type %s timer %d usec "
122                 "loopback tag 0x%04x\n",
123                 ENIC_SETTING(enic, TXCSUM) ? "yes" : "no",
124                 ENIC_SETTING(enic, RXCSUM) ? "yes" : "no",
125                 ENIC_SETTING(enic, RSS) ? "yes" : "no",
126                 c->intr_mode == VENET_INTR_MODE_INTX ? "INTx" :
127                 c->intr_mode == VENET_INTR_MODE_MSI ? "MSI" :
128                 c->intr_mode == VENET_INTR_MODE_ANY ? "any" :
129                 "unknown",
130                 c->intr_timer_type == VENET_INTR_TYPE_MIN ? "min" :
131                 c->intr_timer_type == VENET_INTR_TYPE_IDLE ? "idle" :
132                 "unknown",
133                 c->intr_timer_usec,
134                 c->loop_tag);
135
136         /* RSS settings from vNIC */
137         enic->reta_size = ENIC_RSS_RETA_SIZE;
138         enic->hash_key_size = ENIC_RSS_HASH_KEY_SIZE;
139         enic->flow_type_rss_offloads = 0;
140         if (ENIC_SETTING(enic, RSSHASH_IPV4))
141                 enic->flow_type_rss_offloads |= ETH_RSS_IPV4;
142         if (ENIC_SETTING(enic, RSSHASH_TCPIPV4))
143                 enic->flow_type_rss_offloads |= ETH_RSS_NONFRAG_IPV4_TCP;
144         if (ENIC_SETTING(enic, RSSHASH_IPV6))
145                 enic->flow_type_rss_offloads |= ETH_RSS_IPV6;
146         if (ENIC_SETTING(enic, RSSHASH_TCPIPV6))
147                 enic->flow_type_rss_offloads |= ETH_RSS_NONFRAG_IPV6_TCP;
148         if (ENIC_SETTING(enic, RSSHASH_IPV6_EX))
149                 enic->flow_type_rss_offloads |= ETH_RSS_IPV6_EX;
150         if (ENIC_SETTING(enic, RSSHASH_TCPIPV6_EX))
151                 enic->flow_type_rss_offloads |= ETH_RSS_IPV6_TCP_EX;
152         if (vnic_dev_capable_udp_rss(enic->vdev)) {
153                 enic->flow_type_rss_offloads |=
154                         ETH_RSS_NONFRAG_IPV4_UDP | ETH_RSS_NONFRAG_IPV6_UDP;
155         }
156
157         /* Zero offloads if RSS is not enabled */
158         if (!ENIC_SETTING(enic, RSS))
159                 enic->flow_type_rss_offloads = 0;
160
161         return 0;
162 }
163
164 int enic_add_vlan(struct enic *enic, u16 vlanid)
165 {
166         u64 a0 = vlanid, a1 = 0;
167         int wait = 1000;
168         int err;
169
170         err = vnic_dev_cmd(enic->vdev, CMD_VLAN_ADD, &a0, &a1, wait);
171         if (err)
172                 dev_err(enic_get_dev(enic), "Can't add vlan id, %d\n", err);
173
174         return err;
175 }
176
177 int enic_del_vlan(struct enic *enic, u16 vlanid)
178 {
179         u64 a0 = vlanid, a1 = 0;
180         int wait = 1000;
181         int err;
182
183         err = vnic_dev_cmd(enic->vdev, CMD_VLAN_DEL, &a0, &a1, wait);
184         if (err)
185                 dev_err(enic_get_dev(enic), "Can't delete vlan id, %d\n", err);
186
187         return err;
188 }
189
190 int enic_set_nic_cfg(struct enic *enic, u8 rss_default_cpu, u8 rss_hash_type,
191         u8 rss_hash_bits, u8 rss_base_cpu, u8 rss_enable, u8 tso_ipid_split_en,
192         u8 ig_vlan_strip_en)
193 {
194         u64 a0, a1;
195         u32 nic_cfg;
196         int wait = 1000;
197
198         vnic_set_nic_cfg(&nic_cfg, rss_default_cpu,
199                 rss_hash_type, rss_hash_bits, rss_base_cpu,
200                 rss_enable, tso_ipid_split_en, ig_vlan_strip_en);
201
202         a0 = nic_cfg;
203         a1 = 0;
204
205         return vnic_dev_cmd(enic->vdev, CMD_NIC_CFG, &a0, &a1, wait);
206 }
207
208 int enic_set_rss_key(struct enic *enic, dma_addr_t key_pa, u64 len)
209 {
210         u64 a0 = (u64)key_pa, a1 = len;
211         int wait = 1000;
212
213         return vnic_dev_cmd(enic->vdev, CMD_RSS_KEY, &a0, &a1, wait);
214 }
215
216 int enic_set_rss_cpu(struct enic *enic, dma_addr_t cpu_pa, u64 len)
217 {
218         u64 a0 = (u64)cpu_pa, a1 = len;
219         int wait = 1000;
220
221         return vnic_dev_cmd(enic->vdev, CMD_RSS_CPU, &a0, &a1, wait);
222 }
223
224 void enic_free_vnic_resources(struct enic *enic)
225 {
226         unsigned int i;
227
228         for (i = 0; i < enic->wq_count; i++)
229                 vnic_wq_free(&enic->wq[i]);
230         for (i = 0; i < enic_vnic_rq_count(enic); i++)
231                 if (enic->rq[i].in_use)
232                         vnic_rq_free(&enic->rq[i]);
233         for (i = 0; i < enic->cq_count; i++)
234                 vnic_cq_free(&enic->cq[i]);
235         for (i = 0; i < enic->intr_count; i++)
236                 vnic_intr_free(&enic->intr[i]);
237 }
238
239 void enic_get_res_counts(struct enic *enic)
240 {
241         enic->conf_wq_count = vnic_dev_get_res_count(enic->vdev, RES_TYPE_WQ);
242         enic->conf_rq_count = vnic_dev_get_res_count(enic->vdev, RES_TYPE_RQ);
243         enic->conf_cq_count = vnic_dev_get_res_count(enic->vdev, RES_TYPE_CQ);
244         enic->conf_intr_count = vnic_dev_get_res_count(enic->vdev,
245                 RES_TYPE_INTR_CTRL);
246
247         dev_info(enic_get_dev(enic),
248                 "vNIC resources avail: wq %d rq %d cq %d intr %d\n",
249                 enic->conf_wq_count, enic->conf_rq_count,
250                 enic->conf_cq_count, enic->conf_intr_count);
251 }