Skip to content

Commit 70efb83

Browse files
mniestrojnashif
authored andcommitted
drivers: wifi: esp: process received packets in esp_rx thread
So far received packets were parsed (at AT command level) and allocated in [esp_rx] thread. Then they were submitted to [esp_workq] thread for processing (calling application callback). This flow results in following deadlock when esp_workq thread waits on response to some AT command: - [esp_rx] waits on allocation of new RX packet - [esp_workq] waits for [esp_rx] to process response to AT command that was just sent - blocked [esp_workq] prevents processing and deallocating RX packets - [esp_rx] times out on allocation and closes socket Process RX packets directly from [esp_rx] thread to prevent above deadlock. Signed-off-by: Marcin Niestroj <[email protected]>
1 parent 8bc242e commit 70efb83

File tree

3 files changed

+8
-23
lines changed

3 files changed

+8
-23
lines changed

drivers/wifi/esp/esp.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,6 @@ static inline int esp_cmd_send(struct esp_data *data,
377377
}
378378

379379
void esp_connect_work(struct k_work *work);
380-
void esp_recv_work(struct k_work *work);
381380
void esp_recvdata_work(struct k_work *work);
382381
void esp_close_work(struct k_work *work);
383382

drivers/wifi/esp/esp_offload.c

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -469,24 +469,6 @@ void esp_recvdata_work(struct k_work *work)
469469
}
470470
}
471471

472-
void esp_recv_work(struct k_work *work)
473-
{
474-
struct net_pkt *pkt = CONTAINER_OF(work, struct net_pkt, work);
475-
struct net_context *context = pkt->context;
476-
struct esp_socket *sock = context->offload_context;
477-
478-
k_mutex_lock(&sock->lock, K_FOREVER);
479-
if (sock->recv_cb) {
480-
sock->recv_cb(context, pkt, NULL, NULL,
481-
0, sock->recv_user_data);
482-
k_sem_give(&sock->sem_data_ready);
483-
} else {
484-
/* Discard */
485-
net_pkt_unref(pkt);
486-
}
487-
k_mutex_unlock(&sock->lock);
488-
}
489-
490472
void esp_close_work(struct k_work *work)
491473
{
492474
struct esp_socket *sock = CONTAINER_OF(work, struct esp_socket,

drivers/wifi/esp/esp_socket.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,6 @@ void esp_socket_rx(struct esp_socket *sock, struct net_buf *buf,
145145
size_t offset, size_t len)
146146
{
147147
struct net_pkt *pkt;
148-
int err;
149148
atomic_val_t flags;
150149

151150
flags = esp_socket_flags(sock);
@@ -168,11 +167,16 @@ void esp_socket_rx(struct esp_socket *sock, struct net_buf *buf,
168167
return;
169168
}
170169

171-
k_work_init(&pkt->work, esp_recv_work);
172-
err = esp_socket_work_submit(sock, &pkt->work);
173-
if (err) {
170+
k_mutex_lock(&sock->lock, K_FOREVER);
171+
if (sock->recv_cb) {
172+
sock->recv_cb(sock->context, pkt, NULL, NULL,
173+
0, sock->recv_user_data);
174+
k_sem_give(&sock->sem_data_ready);
175+
} else {
176+
/* Discard */
174177
net_pkt_unref(pkt);
175178
}
179+
k_mutex_unlock(&sock->lock);
176180
}
177181

178182
void esp_socket_close(struct esp_socket *sock)

0 commit comments

Comments
 (0)