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.
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"
17 #include "vnic_intr.h"
18 #include "vnic_stats.h"
24 int enic_get_vnic_config(struct enic *enic)
26 struct vnic_enet_config *c = &enic->config;
29 err = vnic_dev_get_mac_addr(enic->vdev, enic->mac_addr);
31 dev_err(enic_get_dev(enic),
32 "Error getting MAC addr, %d\n", err);
37 #define GET_CONFIG(m) \
39 err = vnic_dev_spec(enic->vdev, \
40 offsetof(struct vnic_enet_config, m), \
41 sizeof(c->m), &c->m); \
43 dev_err(enic_get_dev(enic), \
44 "Error getting %s, %d\n", #m, err); \
50 GET_CONFIG(wq_desc_count);
51 GET_CONFIG(rq_desc_count);
53 GET_CONFIG(intr_timer_type);
54 GET_CONFIG(intr_mode);
55 GET_CONFIG(intr_timer_usec);
58 GET_CONFIG(max_pkt_size);
60 /* max packet size is only defined in newer VIC firmware
61 * and will be 0 for legacy firmware and VICs
63 if (c->max_pkt_size > ENIC_DEFAULT_RX_MAX_PKT_SIZE)
64 enic->max_mtu = c->max_pkt_size - (ETHER_HDR_LEN + 4);
66 enic->max_mtu = ENIC_DEFAULT_RX_MAX_PKT_SIZE
67 - (ETHER_HDR_LEN + 4);
71 enic->rte_dev->data->mtu = min_t(u16, enic->max_mtu,
72 max_t(u16, ENIC_MIN_MTU, c->mtu));
74 enic->adv_filters = vnic_dev_capable_adv_filters(enic->vdev);
75 dev_info(enic, "Advanced Filters %savailable\n", ((enic->adv_filters)
78 err = vnic_dev_capable_filter_mode(enic->vdev, &enic->flow_filter_mode,
81 dev_err(enic_get_dev(enic),
82 "Error getting filter modes, %d\n", err);
86 dev_info(enic, "Flow api filter mode: %s, Filter tagging %savailable\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" :
91 ((enic->filter_tags) ? "" : "not "));
94 min_t(u32, ENIC_MAX_WQ_DESCS,
95 max_t(u32, ENIC_MIN_WQ_DESCS,
97 c->wq_desc_count &= 0xffffffe0; /* must be aligned to groups of 32 */
100 min_t(u32, ENIC_MAX_RQ_DESCS,
101 max_t(u32, ENIC_MIN_RQ_DESCS,
103 c->rq_desc_count &= 0xffffffe0; /* must be aligned to groups of 32 */
105 c->intr_timer_usec = min_t(u32, c->intr_timer_usec,
106 vnic_dev_get_intr_coal_timer_max(enic->vdev));
108 dev_info(enic_get_dev(enic),
109 "vNIC MAC addr %02x:%02x:%02x:%02x:%02x:%02x "
110 "wq/rq %d/%d mtu %d, max mtu:%d\n",
111 enic->mac_addr[0], enic->mac_addr[1], enic->mac_addr[2],
112 enic->mac_addr[3], enic->mac_addr[4], enic->mac_addr[5],
113 c->wq_desc_count, c->rq_desc_count,
114 enic->rte_dev->data->mtu, enic->max_mtu);
115 dev_info(enic_get_dev(enic), "vNIC csum tx/rx %s/%s "
116 "rss %s intr mode %s type %s timer %d usec "
117 "loopback tag 0x%04x\n",
118 ENIC_SETTING(enic, TXCSUM) ? "yes" : "no",
119 ENIC_SETTING(enic, RXCSUM) ? "yes" : "no",
120 ENIC_SETTING(enic, RSS) ? "yes" : "no",
121 c->intr_mode == VENET_INTR_MODE_INTX ? "INTx" :
122 c->intr_mode == VENET_INTR_MODE_MSI ? "MSI" :
123 c->intr_mode == VENET_INTR_MODE_ANY ? "any" :
125 c->intr_timer_type == VENET_INTR_TYPE_MIN ? "min" :
126 c->intr_timer_type == VENET_INTR_TYPE_IDLE ? "idle" :
134 int enic_add_vlan(struct enic *enic, u16 vlanid)
136 u64 a0 = vlanid, a1 = 0;
140 err = vnic_dev_cmd(enic->vdev, CMD_VLAN_ADD, &a0, &a1, wait);
142 dev_err(enic_get_dev(enic), "Can't add vlan id, %d\n", err);
147 int enic_del_vlan(struct enic *enic, u16 vlanid)
149 u64 a0 = vlanid, a1 = 0;
153 err = vnic_dev_cmd(enic->vdev, CMD_VLAN_DEL, &a0, &a1, wait);
155 dev_err(enic_get_dev(enic), "Can't delete vlan id, %d\n", err);
160 int enic_set_nic_cfg(struct enic *enic, u8 rss_default_cpu, u8 rss_hash_type,
161 u8 rss_hash_bits, u8 rss_base_cpu, u8 rss_enable, u8 tso_ipid_split_en,
168 vnic_set_nic_cfg(&nic_cfg, rss_default_cpu,
169 rss_hash_type, rss_hash_bits, rss_base_cpu,
170 rss_enable, tso_ipid_split_en, ig_vlan_strip_en);
175 return vnic_dev_cmd(enic->vdev, CMD_NIC_CFG, &a0, &a1, wait);
178 int enic_set_rss_key(struct enic *enic, dma_addr_t key_pa, u64 len)
180 u64 a0 = (u64)key_pa, a1 = len;
183 return vnic_dev_cmd(enic->vdev, CMD_RSS_KEY, &a0, &a1, wait);
186 int enic_set_rss_cpu(struct enic *enic, dma_addr_t cpu_pa, u64 len)
188 u64 a0 = (u64)cpu_pa, a1 = len;
191 return vnic_dev_cmd(enic->vdev, CMD_RSS_CPU, &a0, &a1, wait);
194 void enic_free_vnic_resources(struct enic *enic)
198 for (i = 0; i < enic->wq_count; i++)
199 vnic_wq_free(&enic->wq[i]);
200 for (i = 0; i < enic_vnic_rq_count(enic); i++)
201 if (enic->rq[i].in_use)
202 vnic_rq_free(&enic->rq[i]);
203 for (i = 0; i < enic->cq_count; i++)
204 vnic_cq_free(&enic->cq[i]);
205 vnic_intr_free(&enic->intr);
208 void enic_get_res_counts(struct enic *enic)
210 enic->conf_wq_count = vnic_dev_get_res_count(enic->vdev, RES_TYPE_WQ);
211 enic->conf_rq_count = vnic_dev_get_res_count(enic->vdev, RES_TYPE_RQ);
212 enic->conf_cq_count = vnic_dev_get_res_count(enic->vdev, RES_TYPE_CQ);
213 enic->conf_intr_count = vnic_dev_get_res_count(enic->vdev,
216 dev_info(enic_get_dev(enic),
217 "vNIC resources avail: wq %d rq %d cq %d intr %d\n",
218 enic->conf_wq_count, enic->conf_rq_count,
219 enic->conf_cq_count, enic->conf_intr_count);