Skip to content

Commit a1d2887

Browse files
rjarrychristophefontaine
authored andcommitted
port: implement interface callbacks for hardware configuration
Implement the iface_type callbacks for DPDK ethernet ports, allowing configuration operations to be performed through the interface layer instead of directly on port objects. Ignore ENOSYS and EOPNOTSUPP errors from DPDK drivers when hardware features are unavailable. Update interface flags based on actual hardware state after configuration attempts to reflect what the driver actually supports. Signed-off-by: Robin Jarry <rjarry@redhat.com>
1 parent 5a82d56 commit a1d2887

1 file changed

Lines changed: 160 additions & 0 deletions

File tree

modules/infra/control/port.c

Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,159 @@ int port_configure(struct iface_info_port *p, uint16_t n_txq_min) {
146146
return 0;
147147
}
148148

149+
static int port_up_down(struct iface *iface, bool up) {
150+
struct iface_info_port *p = (struct iface_info_port *)iface->info;
151+
int ret;
152+
153+
if (up) {
154+
ret = rte_eth_dev_set_link_up(p->port_id);
155+
switch (ret) {
156+
case 0:
157+
case -ENOSYS:
158+
case -EOPNOTSUPP:
159+
break;
160+
default:
161+
return errno_log(-ret, "rte_eth_dev_set_link_up");
162+
}
163+
iface->flags |= GR_IFACE_F_UP;
164+
} else {
165+
ret = rte_eth_dev_set_link_down(p->port_id);
166+
switch (ret) {
167+
case 0:
168+
case -ENOSYS:
169+
case -EOPNOTSUPP:
170+
break;
171+
default:
172+
return errno_log(-ret, "rte_eth_dev_set_link_down");
173+
}
174+
iface->flags &= ~GR_IFACE_F_UP;
175+
}
176+
177+
return 0;
178+
}
179+
180+
static int port_mac_set(struct iface *iface, const struct rte_ether_addr *mac) {
181+
struct iface_info_port *p = (struct iface_info_port *)iface->info;
182+
int ret;
183+
184+
if (!rte_is_zero_ether_addr(mac)) {
185+
struct rte_ether_addr mut_mac = *mac;
186+
if ((ret = rte_eth_dev_default_mac_addr_set(p->port_id, &mut_mac)) < 0)
187+
return errno_log(-ret, "rte_eth_dev_default_mac_addr_set");
188+
p->mac = mut_mac;
189+
} else if ((ret = rte_eth_macaddr_get(p->port_id, &p->mac)) < 0) {
190+
return errno_log(-ret, "rte_eth_macaddr_get");
191+
}
192+
193+
return 0;
194+
}
195+
196+
static int port_promisc_set(struct iface *iface, bool enabled) {
197+
struct iface_info_port *p = (struct iface_info_port *)iface->info;
198+
int ret;
199+
200+
if (enabled)
201+
ret = rte_eth_promiscuous_enable(p->port_id);
202+
else
203+
ret = rte_eth_promiscuous_disable(p->port_id);
204+
205+
switch (ret) {
206+
case 0:
207+
case -ENOSYS:
208+
case -EOPNOTSUPP:
209+
break;
210+
default:
211+
return errno_log(-ret, "rte_eth_promiscuous_{en,dis}able");
212+
}
213+
214+
if (rte_eth_promiscuous_get(p->port_id) == 1)
215+
iface->flags |= GR_IFACE_F_PROMISC;
216+
else
217+
iface->flags &= ~GR_IFACE_F_PROMISC;
218+
219+
return 0;
220+
}
221+
222+
static int port_allmulti_set(struct iface *iface, bool enabled) {
223+
struct iface_info_port *p = (struct iface_info_port *)iface->info;
224+
int ret;
225+
226+
if (enabled)
227+
ret = rte_eth_allmulticast_enable(p->port_id);
228+
else
229+
ret = rte_eth_allmulticast_disable(p->port_id);
230+
231+
switch (ret) {
232+
case 0:
233+
case -ENOSYS:
234+
case -EOPNOTSUPP:
235+
break;
236+
default:
237+
return errno_log(-ret, "rte_eth_allmulticast_{en,dis}able");
238+
}
239+
240+
if (rte_eth_allmulticast_get(p->port_id) == 1)
241+
iface->flags |= GR_IFACE_F_ALLMULTI;
242+
else
243+
iface->flags &= ~GR_IFACE_F_ALLMULTI;
244+
245+
return 0;
246+
}
247+
248+
static int port_mtu_set(struct iface *iface, uint16_t mtu) {
249+
struct iface_info_port *p = (struct iface_info_port *)iface->info;
250+
int ret;
251+
252+
if (mtu != 0) {
253+
ret = rte_eth_dev_set_mtu(p->port_id, mtu);
254+
switch (ret) {
255+
case 0:
256+
case -ENOSYS:
257+
case -EOPNOTSUPP:
258+
break;
259+
default:
260+
return errno_log(-ret, "rte_eth_dev_set_mtu");
261+
}
262+
iface->mtu = mtu;
263+
} else {
264+
if ((ret = rte_eth_dev_get_mtu(p->port_id, &iface->mtu)) < 0)
265+
return errno_log(-ret, "rte_eth_dev_get_mtu");
266+
}
267+
268+
gr_vec_foreach (struct iface *s, iface->subinterfaces)
269+
s->mtu = iface->mtu;
270+
271+
return 0;
272+
}
273+
274+
static int port_vlan_add(struct iface *iface, uint16_t vlan_id) {
275+
struct iface_info_port *p = (struct iface_info_port *)iface->info;
276+
int ret = rte_eth_dev_vlan_filter(p->port_id, vlan_id, true);
277+
switch (ret) {
278+
case 0:
279+
case -ENOSYS:
280+
case -EOPNOTSUPP:
281+
break;
282+
default:
283+
return errno_log(-ret, "rte_eth_dev_vlan_filter");
284+
}
285+
return 0;
286+
}
287+
288+
static int port_vlan_del(struct iface *iface, uint16_t vlan_id) {
289+
struct iface_info_port *p = (struct iface_info_port *)iface->info;
290+
int ret = rte_eth_dev_vlan_filter(p->port_id, vlan_id, false);
291+
switch (ret) {
292+
case 0:
293+
case -ENOSYS:
294+
case -EOPNOTSUPP:
295+
break;
296+
default:
297+
return errno_log(-ret, "rte_eth_dev_vlan_filter");
298+
}
299+
return 0;
300+
}
301+
149302
static int iface_port_reconfig(
150303
struct iface *iface,
151304
uint64_t set_attrs,
@@ -702,6 +855,13 @@ static struct iface_type iface_type_port = {
702855
.get_eth_addr = port_mac_get,
703856
.add_eth_addr = port_mac_add,
704857
.del_eth_addr = port_mac_del,
858+
.set_eth_addr = port_mac_set,
859+
.set_mtu = port_mtu_set,
860+
.set_up_down = port_up_down,
861+
.set_promisc = port_promisc_set,
862+
.set_allmulti = port_allmulti_set,
863+
.add_vlan = port_vlan_add,
864+
.del_vlan = port_vlan_del,
705865
.to_api = port_to_api,
706866
};
707867

0 commit comments

Comments
 (0)