Skip to content

Commit 2697275

Browse files
jukkargalak
authored andcommitted
net: ppp: Convert to use k_fifo instead of k_work
Following commits will remove k_work from net_pkt, so convert PPP L2 to use k_fifo when sending PPP data. Signed-off-by: Jukka Rissanen <[email protected]>
1 parent 0808ead commit 2697275

File tree

4 files changed

+51
-14
lines changed

4 files changed

+51
-14
lines changed

subsys/net/l2/ppp/Kconfig

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,4 +92,11 @@ config NET_L2_PPP_MGMT
9292
Enable support net_mgmt ppp interface which can be used to
9393
configure at run-time ppp drivers and L2 settings.
9494

95+
config NET_L2_PPP_TX_STACK_SIZE
96+
int "Stack size for TX handler"
97+
default 2048 if COVERAGE_GCOV
98+
default 1024
99+
help
100+
Set the TX handler stack size.
101+
95102
endif # NET_L2_PPP

subsys/net/l2/ppp/fsm.c

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -159,18 +159,6 @@ static void ppp_fsm_timeout(struct k_work *work)
159159
}
160160
}
161161

162-
static void ppp_pkt_send(struct k_work *work)
163-
{
164-
struct net_pkt *pkt = CONTAINER_OF(work, struct net_pkt, work);
165-
int ret;
166-
167-
ret = net_send_data(pkt);
168-
if (ret < 0) {
169-
net_pkt_unref(pkt);
170-
}
171-
}
172-
173-
174162
void ppp_fsm_init(struct ppp_fsm *fsm, uint16_t protocol)
175163
{
176164
fsm->protocol = protocol;
@@ -541,8 +529,7 @@ int ppp_send_pkt(struct ppp_fsm *fsm, struct net_if *iface,
541529
* have returned from this function. That is bad because the
542530
* fsm would be in wrong state and the received pkt is dropped.
543531
*/
544-
k_work_init(net_pkt_work(pkt), ppp_pkt_send);
545-
k_work_submit(net_pkt_work(pkt));
532+
ppp_queue_pkt(pkt);
546533
} else {
547534
ret = net_send_data(pkt);
548535
if (ret < 0) {

subsys/net/l2/ppp/ppp_internal.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ int ppp_config_info_req(struct ppp_fsm *fsm,
101101
.close = proto_close, \
102102
}
103103

104+
void ppp_queue_pkt(struct net_pkt *pkt);
104105
const char *ppp_phase_str(enum ppp_phase phase);
105106
const char *ppp_state_str(enum ppp_state state);
106107
const char *ppp_proto2str(uint16_t proto);

subsys/net/l2/ppp/ppp_l2.c

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,21 @@ LOG_MODULE_REGISTER(net_l2_ppp, CONFIG_NET_L2_PPP_LOG_LEVEL);
2121
#include "ppp_stats.h"
2222
#include "ppp_internal.h"
2323

24+
static K_FIFO_DEFINE(tx_queue);
25+
26+
#if IS_ENABLED(CONFIG_NET_TC_THREAD_COOPERATIVE)
27+
/* Lowest priority cooperative thread */
28+
#define THREAD_PRIORITY K_PRIO_COOP(CONFIG_NUM_COOP_PRIORITIES - 1)
29+
#else
30+
#define THREAD_PRIORITY K_PRIO_PREEMPT(CONFIG_NUM_PREEMPT_PRIORITIES - 1)
31+
#endif
32+
33+
static void tx_handler(void);
34+
35+
static K_THREAD_DEFINE(tx_handler_thread, CONFIG_NET_L2_PPP_TX_STACK_SIZE,
36+
(k_thread_entry_t)tx_handler, NULL, NULL, NULL,
37+
THREAD_PRIORITY, 0, 0);
38+
2439
static const struct ppp_protocol_handler *ppp_lcp;
2540

2641
static void ppp_update_rx_stats(struct net_if *iface,
@@ -429,6 +444,33 @@ static void ppp_startup(struct k_work *work)
429444
}
430445
}
431446

447+
void ppp_queue_pkt(struct net_pkt *pkt)
448+
{
449+
k_fifo_put(&tx_queue, pkt);
450+
}
451+
452+
static void tx_handler(void)
453+
{
454+
struct net_pkt *pkt;
455+
int ret;
456+
457+
NET_DBG("PPP TX started");
458+
459+
k_thread_name_set(NULL, "ppp_tx");
460+
461+
while (1) {
462+
pkt = k_fifo_get(&tx_queue, K_FOREVER);
463+
if (pkt == NULL) {
464+
continue;
465+
}
466+
467+
ret = net_send_data(pkt);
468+
if (ret < 0) {
469+
net_pkt_unref(pkt);
470+
}
471+
}
472+
}
473+
432474
void net_ppp_init(struct net_if *iface)
433475
{
434476
struct ppp_context *ctx = net_if_l2_data(iface);

0 commit comments

Comments
 (0)