Files
kunlun/plc/halmac/inc/rx_pb_reorder.h
2024-09-28 14:24:04 +08:00

157 lines
4.0 KiB
C
Executable File

/****************************************************************************
Copyright(c) 2019 by Aerospace C.Power (Chongqing) Microelectronics. ALL RIGHTS RESERVED.
This Information is proprietary to Aerospace C.Power (Chongqing) Microelectronics and MAY NOT
be copied by any method or incorporated into another program without
the express written consent of Aerospace C.Power. This Information or any portion
thereof remains the property of Aerospace C.Power. The Information contained herein
is believed to be accurate and Aerospace C.Power assumes no responsibility or
liability for its use in any way and conveys no license or title under
any patent or copyright and makes no representation or warranty that this
Information is free from patent or copyright infringement.
****************************************************************************/
#ifndef RX_PB_REORDER_H
#define RX_PB_REORDER_H
#include "rx_mpdu_end.h"
#include "rx_mpdu_start.h"
#include "rx_pb_start.h"
#include "rx_pb_end.h"
#include "iot_pkt_api.h"
#include "os_timer_api.h"
#include "rx_desc_reg_api.h"
#include "mac_rx_buf_ring.h"
#ifdef __cplusplus
extern "C" {
#endif
#define INV_PB_TOTAL_CNT 0xFFFF
#define INV_PB_SSN 0xFFFFFFFF
/* max value of mac_rx_info and mac_tx_info. When report plc data to cvg,
* mac layer shall reserve this size in iot_pkt as the iot_pkt may be forward.
* Then the reserved header space shall be able to contain mac_rx_info.
*/
#define RX_FWD_RESV_LEN (sizeof(mac_rx_info_t) > \
sizeof(mac_tx_info) + sizeof(frame_control_t) ? \
sizeof(mac_rx_info_t) : \
sizeof(mac_tx_info) + sizeof(frame_control_t))
/*
reorder buf structure
msdu : msdu_buf
|
v
pb------> pb_buf
|
v
pb------> pb_buf
|
v
pb------> pb_buf
|
v
.
.
pb------> pb_buf
|
v
NULL
*/
typedef struct _pb_buf_list {
uint32_t ssn :16,
msdu_start :1,
msdu_end :1,
resv0 :14;
iot_pkt_t *pb_buf;
struct _pb_buf_list *next;
} pb_buf_list_t;
typedef struct _reorder_msdu_buf {
/* current recevied pb */
uint32_t pb_rdy_cnt : 16,
/* the total number pb in the msdu */
pb_total_cnt : 16;
/* pb_buf_list_t allocated count */
uint32_t pb_alloc_cnt : 16,
/* if the pb is reused for this msdu */
is_reused : 1,
pbsz : 10,
resv : 5;
/* at least one pb buf for SOF frame */
pb_buf_list_t pb_list;
} reorder_msdu_buf_t;
typedef struct _reorder_msdu_dbg {
uint32_t ssn :16,
msdu_start :1,
msdu_end :1,
resv0 :14;
uint32_t desc[16];
} reorder_msdu_dbg_t;
/*
* API
*/
/* init the msdu head node */
uint32_t reorder_buf_init(
reorder_msdu_buf_t *msdu, \
void *stream /* refer stream */
);
/* init the msdu head node when receive the first pb_buf */
uint32_t reorder_buf_init_first_pb(
reorder_msdu_buf_t *msdu, \
uint32_t pkt_size, /* msdu buf len */
void *stream, /* refer stream */
uint32_t msdu_st,
uint32_t msdu_ed,
uint32_t ssn,
/* must be the msdu_start pb if not null,
* to optimize the memory usage,
* we can use the same pb buf if
* the msdu len is smaller than
* the pb size
*/
iot_pkt_t *pb_buf
);
uint32_t pb_buf_list_init(pb_buf_list_t *pb, uint32_t msdu_st,
uint32_t msdu_ed,
uint32_t ssn,
iot_pkt_t *pb_buf
);
uint32_t reorder_buf_free(reorder_msdu_buf_t *msdu);
/* flush the reorder buf
* reset the msdu's counter
* and free all the pb_bufs,
* but keep the pb_buf_list allocated for fast allocation.
* usually called when a new msdu's pb received
*/
uint32_t reorder_buf_flush(reorder_msdu_buf_t *msdu);
/* release the msdu */
uint32_t reorder_buf_release(reorder_msdu_buf_t *msdu);
/*
* insert to exist msdu reorder structure
*/
uint32_t reorder_buf_insert(reorder_msdu_buf_t *msdu, \
iot_pkt_t *pb_buf, uint32_t ssn, uint32_t msdu_start,
uint32_t msdu_end, uint32_t is_retry, uint32_t pbsz);
#ifdef __cplusplus
}
#endif
#endif // !RX_PB_REORDER_H