1 /* 2 * Copyright (c) 2020 HiSilicon (Shanghai) Technologies CO., LIMITED. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 * Description: hcc types. 15 * Author: 16 * Create: 2021-05-13 17 */ 18 19 #ifndef __HCC_TYPES_H__ 20 #define __HCC_TYPES_H__ 21 22 #include "td_type.h" 23 #include "hcc_cfg_comm.h" 24 25 typedef enum _hcc_queue_dir_ { 26 HCC_DIR_TX = 0x0, 27 HCC_DIR_RX = 0x1, 28 HCC_DIR_COUNT 29 } hcc_queue_dir; 30 31 /* 32 * HCC default macro 33 */ 34 #define HCC_DEFAULT_ALIGN_LEN 1 35 36 /* hcc tx transfer flow control */ 37 #define HCC_FC_NONE 0x0 /* 对调用者不进行流控,netbuf一直缓冲在hcc队列中,这种类型的数据包不宜过多 */ 38 #define HCC_FC_WAIT 0x1 /* 阻塞等待,如果是在中断上下文调用,该标记被自动清除,非中断上下文生效 */ 39 #define HCC_FC_NET 0x2 /* 对于网络层的流控 */ 40 #define HCC_FC_DROP 0x4 /* 流控采用丢包方式,流控时返回成功 */ 41 #define HCC_FC_ALL (HCC_FC_WAIT | HCC_FC_NET | HCC_FC_DROP) 42 43 typedef struct _hcc_transfer_param { 44 td_u8 service_type : 4; 45 td_u8 sub_type : 4; 46 td_u8 queue_id; /* 期望进入的队列号 */ 47 td_u16 fc_flag; /* 流控标记 */ 48 td_u8 *user_param; 49 } hcc_transfer_param; 50 51 typedef td_u32 (*hcc_msg_rx)(td_u8 *cb_data); 52 53 /* 54 * 功能描述:业务数据结构内存释放函数 55 * queue_id: 队列ID号。使用场景:一个业务可能使用不同内存池管理,建议不同内存池的数据使用不同队列传输, 56 * 通过 queue_id 区分使用的内存池; 57 * buf: 业务实际传输数据,其中包含 hcc头和payload,hcc头由调用者分配空间,由hcc模块内部填充; 58 * len: buf数据的长度,为hcc头的长度+payload的总长度; 59 * user_param: 业务使用数据,使用场景:业务传输数据的buf为内部结构体的一部分,buf和内部结构需要同时释放和申请, 60 * 通过buf地址无法计算出其所在结构的首地址,因此增加用户数据指针,具体指针内容hcc模块不关心; 61 */ 62 typedef td_u32 (*hcc_adapt_priv_alloc)(hcc_queue_type queue_id, td_u32 len, td_u8 **buf, td_u8 **user_param); 63 /* 64 * 功能描述:业务数据结构内存申请函数 65 * queue_id: 释放内存所在队列号; 66 */ 67 typedef td_void (*hcc_adapt_priv_free)(hcc_queue_type queue_id, td_u8 *buf, td_u8 *user_param); 68 /* 69 * 功能描述:业务开始流控函数,停止或减缓业务数据发送 70 * queue_id: 需要开始流控的队列号。 71 */ 72 typedef td_void (*hcc_flowctl_start_subq)(hcc_queue_type queue_id); 73 /* 74 * 功能描述:业务停止流控函数,恢复业务数据发送 75 * queue_id: 需要停止流控的队列号。 76 */ 77 typedef td_void (*hcc_flowctl_stop_subq)(hcc_queue_type queue_id); 78 /* 79 * 功能描述:业务数据接收处理函数 80 * queue_id: 接收数据所在队列号; 81 */ 82 typedef td_u32 (*hcc_adapt_priv_rx_process)(hcc_queue_type queue_id, td_u8 sub_type, 83 td_u8 *buf, td_u32 len, td_u8 *user_param); 84 typedef struct _hcc_adapt_ops_ { 85 hcc_adapt_priv_free free; 86 hcc_adapt_priv_alloc alloc; 87 hcc_flowctl_stop_subq stop_subq; 88 hcc_flowctl_start_subq start_subq; 89 hcc_adapt_priv_rx_process rx_proc; 90 } hcc_adapt_ops; 91 92 #pragma pack(push, 1) 93 typedef struct _hcc_queue_ctrl_ { 94 td_u32 service_type : 4; // 队列所属的业务类型 95 td_u32 sub_type : 4; // 队列所属的业务子类型 96 td_u32 transfer_mode : 3; // 队列发送模式: 单条发送、聚合发送 接收mode也用该字节 // hcc_transfer_mode 97 td_u32 fc_enable : 1; // 队列流控使能,初始化默认打开 98 td_u32 flow_type : 4; // 队列流控类型, hcc_flowctrl_type 99 td_u32 low_waterline : 8; // 队列的低水线 100 td_u32 high_waterline : 8; // 队列的高水线 101 102 td_u16 extend; // ipc配置为队列中buff最大长度 103 td_u8 burst_limit; // 队列每次处理数据包的上限,达到上限让出机会给其他队列处理; 104 td_u8 credit_bottom_value; // flow_type 为 HCC_FLOWCTRL_CREDIT 时,该字段生效,低于该值将不再发送; 105 } hcc_queue_ctrl; 106 #pragma pack(pop) 107 108 typedef struct { 109 td_u8 dir; /* hcc_queue_dir */ 110 td_u8 queue_id; /* hcc_queue_type */ 111 hcc_queue_ctrl queue_ctrl; 112 } hcc_queue_cfg; // 配置队列信息 113 #endif 114