#define DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d))
+/*
+ * Because hardware always access register in little-endian mode based on hns3
+ * network engine, so driver should also call rte_cpu_to_le_32 to convert data
+ * in little-endian mode before writing register and call rte_le_to_cpu_32 to
+ * convert data after reading from register.
+ *
+ * Here the driver encapsulates the data conversion operation in the register
+ * read/write operation function as below:
+ * hns3_write_reg
+ * hns3_write_reg_opt
+ * hns3_read_reg
+ * Therefore, when calling these functions, conversion is not required again.
+ */
static inline void hns3_write_reg(void *base, uint32_t reg, uint32_t value)
{
- rte_write32(value, (volatile void *)((char *)base + reg));
+ rte_write32(rte_cpu_to_le_32(value),
+ (volatile void *)((char *)base + reg));
+}
+
+/*
+ * The optimized function for writing registers used in the '.rx_pkt_burst' and
+ * '.tx_pkt_burst' ops implementation function.
+ */
+static inline void hns3_write_reg_opt(volatile void *addr, uint32_t value)
+{
+ rte_io_wmb();
+ rte_write32_relaxed(rte_cpu_to_le_32(value), addr);
}
static inline uint32_t hns3_read_reg(void *base, uint32_t reg)
{
- return rte_read32((volatile void *)((char *)base + reg));
+ uint32_t read_val = rte_read32((volatile void *)((char *)base + reg));
+ return rte_le_to_cpu_32(read_val);
}
#define hns3_write_dev(a, reg, value) \
rxq->configured = true;
rxq->io_base = (void *)((char *)hw->io_base + HNS3_TQP_REG_OFFSET +
idx * HNS3_TQP_REG_SIZE);
+ rxq->io_head_reg = (volatile void *)((char *)rxq->io_base +
+ HNS3_RING_RX_HEAD_REG);
rxq->rx_buf_len = rx_buf_size;
rxq->l2_errors = 0;
rxq->pkt_len_errors = 0;
return NULL;
}
-static void
-hns3_clean_rx_buffers(struct hns3_rx_queue *rxq, int count)
-{
- rxq->next_to_use += count;
- if (rxq->next_to_use >= rxq->nb_rx_desc)
- rxq->next_to_use -= rxq->nb_rx_desc;
-
- hns3_write_dev(rxq, HNS3_RING_RX_HEAD_REG, count);
-}
-
static int
hns3_handle_bdinfo(struct hns3_rx_queue *rxq, struct rte_mbuf *rxm,
uint32_t bd_base_info, uint32_t l234_info,
rxq->rx_free_hold += nb_rx_bd;
if (rxq->rx_free_hold > rxq->rx_free_thresh) {
- hns3_clean_rx_buffers(rxq, rxq->rx_free_hold);
+ hns3_write_reg_opt(rxq->io_head_reg, rxq->rx_free_hold);
rxq->rx_free_hold = 0;
}