310 lines
11 KiB
C
Executable File
310 lines
11 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 MAC_TX_HW_H
|
|
#define MAC_TX_HW_H
|
|
|
|
#include "os_types.h"
|
|
#include "plc_utils.h"
|
|
#include "mac_pdev.h"
|
|
#include "mac_msdu.h"
|
|
#include "tx_mpdu_start.h"
|
|
#include "mac_dma.h"
|
|
#include "tx_stream_start.h"
|
|
#include "iot_plc_led.h"
|
|
#include "mpdu_header.h"
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
#define SW_SCHE_REV 0
|
|
|
|
#define HW_WRITE_DESC_TIME 200
|
|
|
|
/* for tx hang check time, be careful for HW
|
|
* scheduler time of RX only period.
|
|
* TX_HANG_CHECK_TIME_MS * TX_HANG_HANDLE_CNT = 30S
|
|
*/
|
|
#define TX_HANG_CHECK_TIME_MS (15*1000)
|
|
#define TX_HANG_HANDLE_CNT (3)
|
|
|
|
#define BCN_WARNING_DEPTH (4)
|
|
|
|
/* above this may trigger adjust packet detection threshold */
|
|
#define CSMA_Q_NORMAL_DEPTH (PLC_TX_MPDU_POOL_SIZE >> 4)
|
|
|
|
/* above this would trigger ignore CCA energy */
|
|
#define CSMA_Q_WARNING_DEPTH (PLC_TX_MPDU_POOL_SIZE >> 2)
|
|
|
|
#define CSMA_RX_FALSE_ALARM_THD (300)
|
|
|
|
/* BCSMA warning depth */
|
|
#define BCSMA_Q_WARNING_DEPTH (1)
|
|
|
|
/* define the cnt of bcsma non exist beacon period, uint period cnt */
|
|
#define BCSMA_NON_EXIST_PD_CNT (6)
|
|
|
|
uint32_t mac_tx_hw_init(uint32_t proto, mac_pdev_t *pdev);
|
|
|
|
/*
|
|
mac tx a buf frag list to PLC network
|
|
mpdu level interface with hw
|
|
|
|
(IN) frag_list - list for tx, it can support dma frag, if HW can support
|
|
scatter/gather, the buffer list can be transfered to HW desc directly.
|
|
(OUT) return 0 for successful put into HW queue, other
|
|
value for failed
|
|
|
|
*/
|
|
uint32_t mac_tx_hw(mac_pdev_t *pdev, tei_t src_tei, tei_t dst_tei,
|
|
uint32_t nid, uint32_t lid, uint32_t delimiter_type,
|
|
dma_frag_t *frag_list);
|
|
|
|
/*
|
|
* mac_tx_hw_comp() - callback method for sending data complete.
|
|
*
|
|
* @buffer: address of pointer to the data buffer to be sent
|
|
* @len: length of data to be sent
|
|
* @need_free: if the iot_pkt shall be freed
|
|
* @txcomp_desc: hardware info on the sending option
|
|
* return:
|
|
* TRUE -- Take the event successfully
|
|
* FALSE -- Failed to take the event within ms milliseconds
|
|
*/
|
|
uint32_t mac_tx_hw_comp(mac_pdev_t *pdev, void *buffer, size_t len,
|
|
uint32_t need_free, void* txcomp_desc);
|
|
|
|
|
|
/* tx stream */
|
|
uint32_t mac_tx_hw_stream(mac_pdev_t *pdev, tx_stream_start *stream);
|
|
uint32_t mac_tx_hw_stream_comp(mac_pdev_t *pdev, tx_stream_start *stream);
|
|
|
|
/* tx mpdu */
|
|
uint32_t mac_tx_hw_mpdu(mac_queue_ctxt_t *tx_ctxt, uint32_t hwq_id, \
|
|
tx_mpdu_start *mpdu);
|
|
uint32_t mac_tx_hw_mpdu_comp(uint32_t hwqid, uint32_t is_phy_comp);
|
|
|
|
uint32_t mac_tx_hw_mpdu_comp_dsr(uint32_t hwqid);
|
|
|
|
mac_msdu_t *mac_tx_hw_msdu_comp(uint32_t hwq_id,
|
|
tx_mpdu_start *current_mpdu, mac_pdev_t *pdev, uint32_t is_phy_comp);
|
|
|
|
uint32_t mac_tx_mpdu_fill_macinfo(tx_mpdu_start *mpdu_start, \
|
|
uint32_t swqid, uint32_t pb_num_in_desc, uint32_t need_encry,
|
|
uint32_t need_ack, uint32_t symppb, uint32_t flppb, uint32_t fl_amend,
|
|
uint32_t pb_hdr_crc_len,
|
|
uint32_t hw_retry_cnt, uint32_t list_start, uint32_t list_end,
|
|
tx_mpdu_end *mpdu_end, tx_pb_start *pb_start, \
|
|
tx_mpdu_start *next, uint32_t pb_buf_reuse, \
|
|
uint32_t sw_buf_offset, uint32_t is_msdu, uint32_t avln_idx_in_desc,\
|
|
uint32_t key_table_idx_in_desc, uint32_t key_idx_in_desc,
|
|
uint32_t tx_desc_reuse
|
|
);
|
|
|
|
uint32_t mac_tx_mpdu_fill_phyinfo(tx_mpdu_start *mpdu_start, \
|
|
uint32_t tx_port, uint32_t tx_power, phase_t phase,
|
|
uint32_t hw_band_id, uint32_t ppdu_mode,
|
|
uint32_t tx_tone_amp_table_idx,
|
|
uint32_t pb_mod, uint32_t rate_mode
|
|
);
|
|
|
|
uint32_t mac_tx_mpdu_fill_fcinfo(tx_mpdu_start *mpdu_start,\
|
|
uint32_t proto, uint32_t pb_num, phase_t phase_in_fc,\
|
|
uint32_t delimter, uint32_t network, uint32_t nid, uint32_t bcn_period_cnt,\
|
|
uint32_t tmi, uint32_t ext_tmi, tei_t dtei, tei_t stei,\
|
|
lid_t lid, uint32_t bcast,uint32_t retry_in_fc, uint8_t need_encry,\
|
|
uint32_t key_table_idx_in_desc, uint32_t key_idx_in_desc,\
|
|
uint8_t *fc_rawdata
|
|
);
|
|
|
|
void mac_get_nncco_sw_info_from_fc(void *fc, nncco_fc_info_t *nn_fc_info);
|
|
|
|
uint32_t mac_fill_nncco_variable_fcinfo(uint32_t proto, void *fc_p,
|
|
nncco_fc_info_t *nn_fc_info);
|
|
|
|
void mac_tx_mpdu_fill_pb_start(tx_pb_start *pb, \
|
|
tx_pb_start *next, void *buf_addr, uint32_t pb_seq, \
|
|
uint32_t msdu_start, uint32_t msdu_end, uint32_t proto
|
|
);
|
|
|
|
uint32_t mac_tx_mpdu_form_pb_list(tx_pb_start **pb_list, \
|
|
iot_pkt_t *pkt_buf, uint32_t pb_num_per_mpdu, \
|
|
uint32_t bitmap, uint32_t pb_sz, uint32_t proto
|
|
);
|
|
|
|
|
|
uint32_t mac_tx_flush_all_tdma_queue(mac_queue_ctxt_t *tx_ctxt);
|
|
|
|
/* flush queue according to specifc type */
|
|
uint32_t mac_tx_flush_all_queue(mac_queue_ctxt_t *tx_ctxt, \
|
|
uint32_t is_all_csma, uint32_t is_all_tdma);
|
|
|
|
/**
|
|
*@brief mac_handle_timeout_tx_abort handle phy tx abort is electrical level.
|
|
*@return [none.]
|
|
*/
|
|
void mac_handle_timeout_tx_abort();
|
|
|
|
/**
|
|
*@brief mac_check_timeout_tx_abort trigger phy_tx_abort dsr.
|
|
*@return [none.]
|
|
*/
|
|
void mac_check_timeout_tx_abort();
|
|
|
|
void mac_tx_mpdu_fill_total_len(tx_mpdu_start *mpdu, uint32_t len);
|
|
|
|
void mac_tx_mpdu_fill_proto(tx_mpdu_start *mpdu, uint32_t proto);
|
|
|
|
/*
|
|
*@brief mac send sound
|
|
*/
|
|
uint32_t mac_send_sound(pdevid_t pdev_id, \
|
|
uint32_t proto, \
|
|
uint32_t nid, /* if gp, fill in snid */\
|
|
uint32_t dtei, \
|
|
uint32_t stei, \
|
|
lid_t lid, \
|
|
phase_t phase, \
|
|
uint32_t tmi, \
|
|
uint32_t rc
|
|
);
|
|
|
|
/*
|
|
* mac_crc_set_fc_swcrc() - calculate MPDU fccs and filling
|
|
* @proto: mpdu data protocol, for example
|
|
* PLC_PROTO_TYPE_SG 0
|
|
* PLC_PROTO_TYPE_GP 1
|
|
* PLC_PROTO_TYPE_AV 2
|
|
* PLC_PROTO_TYPE_SPG 3
|
|
* @mpdu: tx mpdu start description point
|
|
*
|
|
* return: error num, reference iot_errno.h
|
|
*/
|
|
uint8_t mac_crc_set_fc_swcrc(uint32_t proto, tx_mpdu_start *mpdu);
|
|
|
|
/*
|
|
* mac_crc_set_fc_swcrc() - calculate PB crc and filling
|
|
* @proto: mpdu data protocol, eg.
|
|
* PLC_PROTO_TYPE_SG 0
|
|
* PLC_PROTO_TYPE_GP 1
|
|
* PLC_PROTO_TYPE_AV 2
|
|
* PLC_PROTO_TYPE_SPG 3
|
|
* @pb_st: tx pb start description point
|
|
* @delimite: delimite type,
|
|
* @pb_sz: pb size(eg. 72/136/264/520...)
|
|
*
|
|
* return: error num, reference iot_errno.h
|
|
*/
|
|
uint8_t mac_crc_set_pb_swcrc(uint32_t proto, tx_pb_start *pb_st,
|
|
uint8_t delimite, uint32_t pb_sz);
|
|
|
|
/**
|
|
*@brief mac_cal_ucast_hw_sw_retry_cnt cal ucast hw sw retry cnt.
|
|
*@param pdev [pointer to pdev]
|
|
*@param first_try_done_flag [is first time tx msdu]
|
|
*@param cur_retry_cnt [current retry cnt]
|
|
*@param dft_hw_retry_cnt [default hw retry cnt]
|
|
*@param pb_num [current msdu tx pb num]
|
|
*@param *hw_retry_cnt [hw retry cnt]
|
|
*@param *sw_retry_cnt [sw retry cnt]
|
|
*@exception [none.]
|
|
*@return [0]
|
|
*/
|
|
uint32_t mac_cal_ucast_hw_sw_retry_cnt(mac_pdev_t *pdev,
|
|
uint32_t first_try_done_flag, uint32_t cur_retry_cnt,
|
|
uint32_t dft_hw_retry_cnt, uint32_t pb_num, uint32_t *hw_retry_cnt,
|
|
uint32_t *sw_retry_cnt);
|
|
|
|
/**
|
|
*@brief mac_cal_fd_and_preamble_time calculation the additional time for
|
|
different platform/chip version
|
|
*@param bandid cur bandid
|
|
*@param tmi cur tmi
|
|
*@exception [none.]
|
|
*@return [0]
|
|
*/
|
|
uint32_t mac_cal_fd_and_preamble_time(uint32_t bandid, uint32_t tmi);
|
|
|
|
/**
|
|
*@brief mac_tx_cal_fl calculation mpdu tx time
|
|
*
|
|
*@param is_bcast indicate this mpdu is broadcast or
|
|
* unicast.
|
|
* 0: unicast, others: broadcast
|
|
*@param rate_id phy tx rate mode id.
|
|
* 0: SR, 1:QR, 2:XR, 3: FSK
|
|
*@param proto_band_id phy tx protocol band id
|
|
*@param tmi tx tmi
|
|
*@param extmi tx extmi
|
|
*@param pb_num pb number in this mpdu
|
|
*
|
|
*@return mpdu tx time. unit:ms
|
|
*/
|
|
uint16_t mac_tx_cal_fl(uint8_t is_bcast, uint8_t rate_id,
|
|
uint32_t proto_band_id, uint32_t tmi, uint32_t extmi, uint32_t pb_num);
|
|
|
|
/**
|
|
*@brief mac_tx_get_slot_guard get hw cmd slot guard time.
|
|
*
|
|
*@param proto protocol type.
|
|
*@param delimiter delimiter type. see FC_DELIM_TYPE.
|
|
*
|
|
*@return cmd slot guard time. unit: us
|
|
*/
|
|
uint32_t mac_tx_get_slot_guard(uint8_t proto, uint8_t delimiter);
|
|
|
|
/**
|
|
*@brief mac_tx_fill_extsackinfo mac fill ext sack info.
|
|
*@param proto [protocal]
|
|
*@param fc [fc]
|
|
*@param delimiter [delimiter type]
|
|
*@param nid [nid]
|
|
*@param ext_type [ext type]
|
|
*@param addr [mac addr]
|
|
*@param stei [stei]
|
|
*@param sn [sn]
|
|
*@exception [none.]
|
|
*@return [none]
|
|
*/
|
|
void mac_tx_fill_extsackinfo(uint32_t proto, void *fc, uint32_t delimiter, \
|
|
uint32_t nid, uint32_t ext_type, uint8_t *addr, uint16_t stei, uint8_t sn);
|
|
|
|
/**
|
|
*@brief mac_tx_set_mpdu_ppm set current mpdu tx ppm
|
|
*@param mpdu_start [mpdu start desc]
|
|
*@param proto [protocal type]
|
|
*@param delimiter [delimiter type]
|
|
*@param param [set ppm parameter]
|
|
*@param is_fixed_ppm [fixed ppm or scan ppm mode]
|
|
*@return [none]
|
|
*/
|
|
void mac_tx_set_mpdu_ppm(tx_mpdu_start *mpdu_start, uint32_t proto,
|
|
uint32_t delimter, uint8_t param, uint8_t is_fixed_ppm);
|
|
|
|
/*
|
|
* @breif mac_tx_flush_bcsma_pending_queue() check bcsma is pending and handle
|
|
* @param tx_ctxt the pointer of the hwq_ctxt
|
|
* @return uint32_t 1 -> do not flush hwq.
|
|
* 0 -> already flush hwq;
|
|
*/
|
|
uint32_t mac_tx_flush_bcsma_pending_queue(mac_queue_ctxt_t *tx_ctxt);
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
#endif // !MAC_TX_HW_H
|