Skip to content

Commit 030e106

Browse files
committed
F-Stack's kni can work on DPDK 18.11 LTS now.
1 parent abee258 commit 030e106

File tree

5 files changed

+114
-20
lines changed

5 files changed

+114
-20
lines changed

example/main.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ char html[] =
2727
"Server: F-Stack\r\n"
2828
"Date: Sat, 25 Feb 2017 09:26:33 GMT\r\n"
2929
"Content-Type: text/html\r\n"
30-
"Content-Length: 439\r\n"
30+
"Content-Length: 438\r\n"
3131
"Last-Modified: Tue, 21 Feb 2017 09:44:03 GMT\r\n"
3232
"Connection: keep-alive\r\n"
3333
"Accept-Ranges: bytes\r\n"
@@ -93,7 +93,7 @@ int loop(void *arg)
9393
char buf[256];
9494
size_t readlen = ff_read(clientfd, buf, sizeof(buf));
9595

96-
ff_write(clientfd, html, strlen(html));
96+
ff_write(clientfd, html, sizeof(html) - 1);
9797
} else {
9898
printf("unknown event: %8.8X\n", event.flags);
9999
}

example/main_epoll.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ char html[] =
2828
"Server: F-Stack\r\n"
2929
"Date: Sat, 25 Feb 2017 09:26:33 GMT\r\n"
3030
"Content-Type: text/html\r\n"
31-
"Content-Length: 439\r\n"
31+
"Content-Length: 438\r\n"
3232
"Last-Modified: Tue, 21 Feb 2017 09:44:03 GMT\r\n"
3333
"Connection: keep-alive\r\n"
3434
"Accept-Ranges: bytes\r\n"
@@ -89,7 +89,7 @@ int loop(void *arg)
8989
char buf[256];
9090
size_t readlen = ff_read( events[i].data.fd, buf, sizeof(buf));
9191
if(readlen > 0) {
92-
ff_write( events[i].data.fd, html, strlen(html));
92+
ff_write( events[i].data.fd, html, sizeof(html) - 1);
9393
} else {
9494
ff_epoll_ctl(epfd, EPOLL_CTL_DEL, events[i].data.fd, NULL);
9595
ff_close( events[i].data.fd);

lib/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ else
4141
endif
4242
endif
4343

44-
DPDK_CFLAGS= -Wall -Werror -include ${FF_DPDK}/include/rte_config.h
44+
DPDK_CFLAGS= -Wall -Wno-deprecated-declarations -Werror -include ${FF_DPDK}/include/rte_config.h
4545
DPDK_CFLAGS+= -march=native -DRTE_MACHINE_CPUFLAG_SSE -DRTE_MACHINE_CPUFLAG_SSE2 -DRTE_MACHINE_CPUFLAG_SSE3
4646
DPDK_CFLAGS+= -DRTE_MACHINE_CPUFLAG_SSSE3 -DRTE_MACHINE_CPUFLAG_SSE4_1 -DRTE_MACHINE_CPUFLAG_SSE4_2
4747
DPDK_CFLAGS+= -DRTE_COMPILE_TIME_CPUFLAGS=RTE_CPUFLAG_SSE,RTE_CPUFLAG_SSE2,RTE_CPUFLAG_SSE3,RTE_CPUFLAG_SSSE3,RTE_CPUFLAG_SSE4_1,RTE_CPUFLAG_SSE4_2

lib/ff_dpdk_if.c

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -572,6 +572,10 @@ init_port_start(void)
572572
uint16_t nb_queues = pconf->nb_lcores;
573573

574574
struct rte_eth_dev_info dev_info;
575+
struct rte_eth_conf port_conf = {0};
576+
struct rte_eth_rxconf rxq_conf;
577+
struct rte_eth_txconf txq_conf;
578+
575579
rte_eth_dev_info_get(port_id, &dev_info);
576580

577581
if (nb_queues > dev_info.max_rx_queues) {
@@ -598,8 +602,6 @@ init_port_start(void)
598602
rte_memcpy(pconf->mac,
599603
addr.addr_bytes, ETHER_ADDR_LEN);
600604

601-
struct rte_eth_conf port_conf = {0};
602-
603605
/* Set RSS mode */
604606
uint64_t default_rss_hf = ETH_RSS_PROTO_MASK;
605607
port_conf.rxmode.mq_mode = ETH_MQ_RX_RSS;
@@ -689,6 +691,14 @@ init_port_start(void)
689691
if (ret != 0) {
690692
return ret;
691693
}
694+
695+
static uint16_t nb_rxd = RX_QUEUE_SIZE;
696+
static uint16_t nb_txd = TX_QUEUE_SIZE;
697+
ret = rte_eth_dev_adjust_nb_rx_tx_desc(port_id, &nb_rxd, &nb_txd);
698+
if (ret < 0)
699+
printf("Could not adjust number of descriptors "
700+
"for port%u (%d)\n", (unsigned)port_id, ret);
701+
692702
uint16_t q;
693703
for (q = 0; q < nb_queues; q++) {
694704
if (numa_on) {
@@ -697,14 +707,18 @@ init_port_start(void)
697707
}
698708
mbuf_pool = pktmbuf_pool[socketid];
699709

700-
ret = rte_eth_tx_queue_setup(port_id, q, TX_QUEUE_SIZE,
701-
socketid, &dev_info.default_txconf);
710+
txq_conf = dev_info.default_txconf;
711+
txq_conf.offloads = port_conf.txmode.offloads;
712+
ret = rte_eth_tx_queue_setup(port_id, q, nb_txd,
713+
socketid, &txq_conf);
702714
if (ret < 0) {
703715
return ret;
704716
}
705-
706-
ret = rte_eth_rx_queue_setup(port_id, q, RX_QUEUE_SIZE,
707-
socketid, &dev_info.default_rxconf, mbuf_pool);
717+
718+
rxq_conf = dev_info.default_rxconf;
719+
rxq_conf.offloads = port_conf.rxmode.offloads;
720+
ret = rte_eth_rx_queue_setup(port_id, q, nb_rxd,
721+
socketid, &rxq_conf, mbuf_pool);
708722
if (ret < 0) {
709723
return ret;
710724
}

lib/ff_dpdk_kni.c

Lines changed: 88 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ struct kni_interface_stats {
7979

8080
struct rte_ring **kni_rp;
8181
struct kni_interface_stats **kni_stat;
82+
int kni_link = ETH_LINK_DOWN;
8283

8384
static void
8485
set_bitmap(uint16_t port, unsigned char *bitmap)
@@ -129,12 +130,51 @@ kni_change_mtu(uint16_t port_id, unsigned new_mtu)
129130
return 0;
130131
}
131132

133+
static void
134+
log_link_state(struct rte_kni *kni, int prev, struct rte_eth_link *link)
135+
{
136+
if (kni == NULL || link == NULL)
137+
return;
138+
139+
if (prev == ETH_LINK_DOWN && link->link_status == ETH_LINK_UP) {
140+
kni_link = ETH_LINK_UP;
141+
printf("%s NIC Link is Up %d Mbps %s %s.\n",
142+
rte_kni_get_name(kni),
143+
link->link_speed,
144+
link->link_autoneg ? "(AutoNeg)" : "(Fixed)",
145+
link->link_duplex ? "Full Duplex" : "Half Duplex");
146+
} else if (prev == ETH_LINK_UP && link->link_status == ETH_LINK_DOWN) {
147+
kni_link = ETH_LINK_DOWN;
148+
printf("%s NIC Link is Down.\n",
149+
rte_kni_get_name(kni));
150+
}
151+
}
152+
153+
/*
154+
* Monitor the link status of all ports and update the
155+
* corresponding KNI interface(s)
156+
*/
157+
static void *
158+
monitor_all_ports_link_status(uint16_t port_id)
159+
{
160+
struct rte_eth_link link;
161+
unsigned int i;
162+
int prev;
163+
164+
memset(&link, 0, sizeof(link));
165+
rte_eth_link_get_nowait(port_id, &link);
166+
prev = rte_kni_update_link(kni_stat[port_id]->kni, link.link_status);
167+
log_link_state(kni_stat[port_id]->kni, prev, &link);
168+
169+
return NULL;
170+
}
171+
132172
static int
133173
kni_config_network_interface(uint16_t port_id, uint8_t if_up)
134174
{
135175
int ret = 0;
136176

137-
if (port_id >= rte_eth_dev_count_avail() || port_id >= RTE_MAX_ETHPORTS) {
177+
if (!rte_eth_dev_is_valid_port(port_id)) {
138178
printf("Invalid port id %d\n", port_id);
139179
return -EINVAL;
140180
}
@@ -158,13 +198,46 @@ kni_config_network_interface(uint16_t port_id, uint8_t if_up)
158198
}
159199
}
160200

201+
if (!if_up)
202+
kni_link = ETH_LINK_DOWN;
203+
161204
if (ret < 0)
162205
printf("Failed to Configure network interface of %d %s\n",
163206
port_id, if_up ? "up" : "down");
164207

165208
return ret;
166209
}
167210

211+
static void
212+
print_ethaddr(const char *name, struct ether_addr *mac_addr)
213+
{
214+
char buf[ETHER_ADDR_FMT_SIZE];
215+
ether_format_addr(buf, ETHER_ADDR_FMT_SIZE, mac_addr);
216+
printf("\t%s%s\n", name, buf);
217+
}
218+
219+
220+
/* Callback for request of configuring mac address */
221+
static int
222+
kni_config_mac_address(uint16_t port_id, uint8_t mac_addr[])
223+
{
224+
int ret = 0;
225+
226+
if (!rte_eth_dev_is_valid_port(port_id)) {
227+
printf("Invalid port id %d\n", port_id);
228+
return -EINVAL;
229+
}
230+
231+
print_ethaddr("Address:", (struct ether_addr *)mac_addr);
232+
233+
ret = rte_eth_dev_default_mac_addr_set(port_id,
234+
(struct ether_addr *)mac_addr);
235+
if (ret < 0)
236+
printf("Failed to config mac_addr for port %d\n", port_id);
237+
238+
return ret;
239+
}
240+
168241
static int
169242
kni_process_tx(uint16_t port_id, uint16_t queue_id,
170243
struct rte_mbuf **pkts_burst, unsigned count)
@@ -363,17 +436,22 @@ ff_kni_alloc(uint16_t port_id, unsigned socket_id,
363436
memset(&dev_info, 0, sizeof(dev_info));
364437
rte_eth_dev_info_get(port_id, &dev_info);
365438
if (dev_info.device)
366-
bus = rte_bus_find_by_device(dev_info.device);
367-
if (bus && !strcmp(bus->name, "pci")) {
368-
pci_dev = RTE_DEV_TO_PCI(dev_info.device);
369-
conf.addr = pci_dev->addr;
370-
conf.id = pci_dev->id;
371-
}
439+
bus = rte_bus_find_by_device(dev_info.device);
440+
if (bus && !strcmp(bus->name, "pci")) {
441+
pci_dev = RTE_DEV_TO_PCI(dev_info.device);
442+
conf.addr = pci_dev->addr;
443+
conf.id = pci_dev->id;
444+
}
445+
446+
/* Get the interface default mac address */
447+
rte_eth_macaddr_get(port_id,
448+
(struct ether_addr *)&conf.mac_addr);
372449

373450
memset(&ops, 0, sizeof(ops));
374451
ops.port_id = port_id;
375452
ops.change_mtu = kni_change_mtu;
376453
ops.config_network_if = kni_config_network_interface;
454+
ops.config_mac_address = kni_config_mac_address;
377455

378456
kni_stat[port_id]->kni = rte_kni_alloc(mbuf_pool, &conf, &ops);
379457
if (kni_stat[port_id]->kni == NULL)
@@ -407,11 +485,13 @@ ff_kni_alloc(uint16_t port_id, unsigned socket_id,
407485
rte_ring_free_count(kni_rp[port_id]));
408486
}
409487

410-
411488
void
412489
ff_kni_process(uint16_t port_id, uint16_t queue_id,
413490
struct rte_mbuf **pkts_burst, unsigned count)
414491
{
492+
if (unlikely(kni_link == ETH_LINK_DOWN)) {
493+
monitor_all_ports_link_status(port_id);
494+
}
415495
kni_process_tx(port_id, queue_id, pkts_burst, count);
416496
kni_process_rx(port_id, queue_id, pkts_burst, count);
417497
}

0 commit comments

Comments
 (0)