src/dpdk/drivers/net/hns3/hns3_stats.c
static int
hns3_update_mac_stats(struct hns3_hw *hw, const uint32_t desc_num)
{
	uint64_t *data = (uint64_t *)(&hw->mac_stats);
	struct hns3_cmd_desc *desc;
	uint64_t *desc_data;
	uint16_t i, k, n;
	int ret;

	desc = rte_malloc("hns3_mac_desc",
			  desc_num * sizeof(struct hns3_cmd_desc), 0);
	if (desc == NULL) {
		hns3_err(hw, "Mac_update_stats alloced desc malloc fail");
		return -ENOMEM;
	}

	hns3_cmd_setup_basic_desc(desc, HNS3_OPC_STATS_MAC_ALL, true);
	ret = hns3_cmd_send(hw, desc, desc_num);
	if (ret) {
		hns3_err(hw, "Update complete MAC pkt stats fail : %d", ret);
		rte_free(desc);
		return ret;
	}

	for (i = 0; i < desc_num; i++) {
		/* For special opcode 0034, only the first desc has the head */
		if (i == 0) {
			desc_data = (uint64_t *)(&desc[i].data[0]);
			n = HNS3_RD_FIRST_STATS_NUM;
		} else {
			desc_data = (uint64_t *)(&desc[i]);
			n = HNS3_RD_OTHER_STATS_NUM;
		}

		for (k = 0; k < n; k++) {
			*data += rte_le_to_cpu_64(*desc_data);
			data++;
			desc_data++;
		}
	}
	rte_free(desc);

	return 0;
}
/*
 * Query all the MAC statistics data of Network ICL command ,opcode id: 0x0034.
 * This command is used before send 'query_mac_stat command', the descriptor
 * number of 'query_mac_stat command' must match with reg_num in this command.
 * @praram hw
 *   Pointer to structure hns3_hw.
 * @return
 *   0 on success.
 */
Query all the MAC statistics data of Network ICL command ,opcode id: 0x0034.
This command is used before send 'query_mac_stat command', the descriptor
number of 'query_mac_stat command' must match with reg_num in this command.
@praram hw
Pointer to structure hns3_hw.
@return
0 on success.
Query all the MAC statistics data of Network ICL command opcode id : 0x0034 . This command is used before send ' query_mac_stat command ' the descriptor number of ' query_mac_stat command ' must match with reg_num in this command . @praram hw Pointer to structure hns3_hw . @return 0 on success .
static int
hns3_update_mac_stats(struct hns3_hw *hw, const uint32_t desc_num)
{
	uint64_t *data = (uint64_t *)(&hw->mac_stats);
	struct hns3_cmd_desc *desc;
	uint64_t *desc_data;
	uint16_t i, k, n;
	int ret;
	desc = rte_malloc("hns3_mac_desc",
			  desc_num * sizeof(struct hns3_cmd_desc), 0);
	if (desc == NULL) {
		hns3_err(hw, "Mac_update_stats alloced desc malloc fail");
		return -ENOMEM;
	}
	hns3_cmd_setup_basic_desc(desc, HNS3_OPC_STATS_MAC_ALL, true);
	ret = hns3_cmd_send(hw, desc, desc_num);
	if (ret) {
		hns3_err(hw, "Update complete MAC pkt stats fail : %d", ret);
		rte_free(desc);
		return ret;
	}
	for (i = 0; i < desc_num; i++) {
		if (i == 0) {
			desc_data = (uint64_t *)(&desc[i].data[0]);
			n = HNS3_RD_FIRST_STATS_NUM;
		} else {
			desc_data = (uint64_t *)(&desc[i]);
			n = HNS3_RD_OTHER_STATS_NUM;
		}
		for (k = 0; k < n; k++) {
			*data += rte_le_to_cpu_64(*desc_data);
			data++;
			desc_data++;
		}
	}
	rte_free(desc);
	return 0;
}
static int hns3_update_mac_stats ( struct hns3_hw * hw , const uint32_t desc_num ) { uint64_t * data = ( uint64_t * ) ( & hw -> mac_stats ) ; struct hns3_cmd_desc * desc ; uint64_t * desc_data ; uint16_t i , k , n ; int ret ; desc = rte_malloc ( " " , desc_num * sizeof ( struct hns3_cmd_desc ) , 0 ) ; if ( desc == NULL ) { hns3_err ( hw , " " ) ; return - ENOMEM ; } hns3_cmd_setup_basic_desc ( desc , HNS3_OPC_STATS_MAC_ALL , true ) ; ret = hns3_cmd_send ( hw , desc , desc_num ) ; if ( ret ) { hns3_err ( hw , " " , ret ) ; rte_free ( desc ) ; return ret ; } for ( i = 0 ; i < desc_num ; i ++ ) { if ( i == 0 ) { desc_data = ( uint64_t * ) ( & desc [ i ] . data [ 0 ] ) ; n = HNS3_RD_FIRST_STATS_NUM ; } else { desc_data = ( uint64_t * ) ( & desc [ i ] ) ; n = HNS3_RD_OTHER_STATS_NUM ; } for ( k = 0 ; k < n ; k ++ ) { * data += rte_le_to_cpu_64 ( * desc_data ) ; data ++ ; desc_data ++ ; } } rte_free ( desc ) ; return 0 ; }
Query all the MAC statistics data of Network ICL command ,opcode id: 0x0034.
Query all the MAC statistics data of Network ICL command opcode id : 0x0034 .
/* For special opcode 0034, only the first desc has the head */