Skip to content

Commit

Permalink
net: ppp: Convert to use k_fifo instead of k_work
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
jukkar authored and galak committed May 7, 2021
1 parent 0808ead commit 2697275
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 14 deletions.
7 changes: 7 additions & 0 deletions subsys/net/l2/ppp/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,11 @@ config NET_L2_PPP_MGMT
Enable support net_mgmt ppp interface which can be used to
configure at run-time ppp drivers and L2 settings.

config NET_L2_PPP_TX_STACK_SIZE
int "Stack size for TX handler"
default 2048 if COVERAGE_GCOV
default 1024
help
Set the TX handler stack size.

endif # NET_L2_PPP
15 changes: 1 addition & 14 deletions subsys/net/l2/ppp/fsm.c
Original file line number Diff line number Diff line change
Expand Up @@ -159,18 +159,6 @@ static void ppp_fsm_timeout(struct k_work *work)
}
}

static void ppp_pkt_send(struct k_work *work)
{
struct net_pkt *pkt = CONTAINER_OF(work, struct net_pkt, work);
int ret;

ret = net_send_data(pkt);
if (ret < 0) {
net_pkt_unref(pkt);
}
}


void ppp_fsm_init(struct ppp_fsm *fsm, uint16_t protocol)
{
fsm->protocol = protocol;
Expand Down Expand Up @@ -541,8 +529,7 @@ int ppp_send_pkt(struct ppp_fsm *fsm, struct net_if *iface,
* have returned from this function. That is bad because the
* fsm would be in wrong state and the received pkt is dropped.
*/
k_work_init(net_pkt_work(pkt), ppp_pkt_send);
k_work_submit(net_pkt_work(pkt));
ppp_queue_pkt(pkt);
} else {
ret = net_send_data(pkt);
if (ret < 0) {
Expand Down
1 change: 1 addition & 0 deletions subsys/net/l2/ppp/ppp_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ int ppp_config_info_req(struct ppp_fsm *fsm,
.close = proto_close, \
}

void ppp_queue_pkt(struct net_pkt *pkt);
const char *ppp_phase_str(enum ppp_phase phase);
const char *ppp_state_str(enum ppp_state state);
const char *ppp_proto2str(uint16_t proto);
Expand Down
42 changes: 42 additions & 0 deletions subsys/net/l2/ppp/ppp_l2.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,21 @@ LOG_MODULE_REGISTER(net_l2_ppp, CONFIG_NET_L2_PPP_LOG_LEVEL);
#include "ppp_stats.h"
#include "ppp_internal.h"

static K_FIFO_DEFINE(tx_queue);

#if IS_ENABLED(CONFIG_NET_TC_THREAD_COOPERATIVE)
/* Lowest priority cooperative thread */
#define THREAD_PRIORITY K_PRIO_COOP(CONFIG_NUM_COOP_PRIORITIES - 1)
#else
#define THREAD_PRIORITY K_PRIO_PREEMPT(CONFIG_NUM_PREEMPT_PRIORITIES - 1)
#endif

static void tx_handler(void);

static K_THREAD_DEFINE(tx_handler_thread, CONFIG_NET_L2_PPP_TX_STACK_SIZE,
(k_thread_entry_t)tx_handler, NULL, NULL, NULL,
THREAD_PRIORITY, 0, 0);

static const struct ppp_protocol_handler *ppp_lcp;

static void ppp_update_rx_stats(struct net_if *iface,
Expand Down Expand Up @@ -429,6 +444,33 @@ static void ppp_startup(struct k_work *work)
}
}

void ppp_queue_pkt(struct net_pkt *pkt)
{
k_fifo_put(&tx_queue, pkt);
}

static void tx_handler(void)
{
struct net_pkt *pkt;
int ret;

NET_DBG("PPP TX started");

k_thread_name_set(NULL, "ppp_tx");

while (1) {
pkt = k_fifo_get(&tx_queue, K_FOREVER);
if (pkt == NULL) {
continue;
}

ret = net_send_data(pkt);
if (ret < 0) {
net_pkt_unref(pkt);
}
}
}

void net_ppp_init(struct net_if *iface)
{
struct ppp_context *ctx = net_if_l2_data(iface);
Expand Down

0 comments on commit 2697275

Please sign in to comment.