Commit 5188f218 authored by Peng Li's avatar Peng Li Committed by David S. Miller

net: hns3: move DMA map into hns3_fill_desc

To solve the L3 checksum error problem which happens when driver
does not clear L3 checksum, DMA map should be done after calling
skb_cow_head.

This patch moves DMA map into hns3_fill_desc to ensure that DMA
map is done after calling skb_cow_head.

Fixes: 76ad4f0e ("net: hns3: Add support of HNS3 Ethernet Driver for hip08 SoC")
Signed-off-by: default avatarFuyun Liang <liangfuyun1@huawei.com>
Signed-off-by: default avatarPeng Li <lipeng321@huawei.com>
Signed-off-by: default avatarYunsheng Lin <linyunsheng@huawei.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 0bbbf15d
...@@ -977,18 +977,20 @@ static int hns3_fill_desc_vtags(struct sk_buff *skb, ...@@ -977,18 +977,20 @@ static int hns3_fill_desc_vtags(struct sk_buff *skb,
} }
static int hns3_fill_desc(struct hns3_enet_ring *ring, void *priv, static int hns3_fill_desc(struct hns3_enet_ring *ring, void *priv,
int size, dma_addr_t dma, int frag_end, int size, int frag_end, enum hns_desc_type type)
enum hns_desc_type type)
{ {
struct hns3_desc_cb *desc_cb = &ring->desc_cb[ring->next_to_use]; struct hns3_desc_cb *desc_cb = &ring->desc_cb[ring->next_to_use];
struct hns3_desc *desc = &ring->desc[ring->next_to_use]; struct hns3_desc *desc = &ring->desc[ring->next_to_use];
struct device *dev = ring_to_dev(ring);
u32 ol_type_vlan_len_msec = 0; u32 ol_type_vlan_len_msec = 0;
u16 bdtp_fe_sc_vld_ra_ri = 0; u16 bdtp_fe_sc_vld_ra_ri = 0;
struct skb_frag_struct *frag;
u32 type_cs_vlan_tso = 0; u32 type_cs_vlan_tso = 0;
struct sk_buff *skb; struct sk_buff *skb;
u16 inner_vtag = 0; u16 inner_vtag = 0;
u16 out_vtag = 0; u16 out_vtag = 0;
u32 paylen = 0; u32 paylen = 0;
dma_addr_t dma;
u16 mss = 0; u16 mss = 0;
u8 ol4_proto; u8 ol4_proto;
u8 il4_proto; u8 il4_proto;
...@@ -997,11 +999,9 @@ static int hns3_fill_desc(struct hns3_enet_ring *ring, void *priv, ...@@ -997,11 +999,9 @@ static int hns3_fill_desc(struct hns3_enet_ring *ring, void *priv,
/* The txbd's baseinfo of DESC_TYPE_PAGE & DESC_TYPE_SKB */ /* The txbd's baseinfo of DESC_TYPE_PAGE & DESC_TYPE_SKB */
desc_cb->priv = priv; desc_cb->priv = priv;
desc_cb->length = size; desc_cb->length = size;
desc_cb->dma = dma;
desc_cb->type = type; desc_cb->type = type;
/* now, fill the descriptor */ /* now, fill the descriptor */
desc->addr = cpu_to_le64(dma);
desc->tx.send_size = cpu_to_le16((u16)size); desc->tx.send_size = cpu_to_le16((u16)size);
hns3_set_txbd_baseinfo(&bdtp_fe_sc_vld_ra_ri, frag_end); hns3_set_txbd_baseinfo(&bdtp_fe_sc_vld_ra_ri, frag_end);
desc->tx.bdtp_fe_sc_vld_ra_ri = cpu_to_le16(bdtp_fe_sc_vld_ra_ri); desc->tx.bdtp_fe_sc_vld_ra_ri = cpu_to_le16(bdtp_fe_sc_vld_ra_ri);
...@@ -1046,8 +1046,21 @@ static int hns3_fill_desc(struct hns3_enet_ring *ring, void *priv, ...@@ -1046,8 +1046,21 @@ static int hns3_fill_desc(struct hns3_enet_ring *ring, void *priv,
desc->tx.mss = cpu_to_le16(mss); desc->tx.mss = cpu_to_le16(mss);
desc->tx.vlan_tag = cpu_to_le16(inner_vtag); desc->tx.vlan_tag = cpu_to_le16(inner_vtag);
desc->tx.outer_vlan_tag = cpu_to_le16(out_vtag); desc->tx.outer_vlan_tag = cpu_to_le16(out_vtag);
dma = dma_map_single(dev, skb->data, size, DMA_TO_DEVICE);
} else {
frag = (struct skb_frag_struct *)priv;
dma = skb_frag_dma_map(dev, frag, 0, size, DMA_TO_DEVICE);
}
if (dma_mapping_error(ring->dev, dma)) {
ring->stats.sw_err_cnt++;
return -ENOMEM;
} }
desc_cb->dma = dma;
desc->addr = cpu_to_le64(dma);
/* move ring pointer to next.*/ /* move ring pointer to next.*/
ring_ptr_move_fw(ring, next_to_use); ring_ptr_move_fw(ring, next_to_use);
...@@ -1137,12 +1150,10 @@ netdev_tx_t hns3_nic_net_xmit(struct sk_buff *skb, struct net_device *netdev) ...@@ -1137,12 +1150,10 @@ netdev_tx_t hns3_nic_net_xmit(struct sk_buff *skb, struct net_device *netdev)
struct hns3_nic_ring_data *ring_data = struct hns3_nic_ring_data *ring_data =
&tx_ring_data(priv, skb->queue_mapping); &tx_ring_data(priv, skb->queue_mapping);
struct hns3_enet_ring *ring = ring_data->ring; struct hns3_enet_ring *ring = ring_data->ring;
struct device *dev = priv->dev;
struct netdev_queue *dev_queue; struct netdev_queue *dev_queue;
struct skb_frag_struct *frag; struct skb_frag_struct *frag;
int next_to_use_head; int next_to_use_head;
int next_to_use_frag; int next_to_use_frag;
dma_addr_t dma;
int buf_num; int buf_num;
int seg_num; int seg_num;
int size; int size;
...@@ -1177,15 +1188,8 @@ netdev_tx_t hns3_nic_net_xmit(struct sk_buff *skb, struct net_device *netdev) ...@@ -1177,15 +1188,8 @@ netdev_tx_t hns3_nic_net_xmit(struct sk_buff *skb, struct net_device *netdev)
next_to_use_head = ring->next_to_use; next_to_use_head = ring->next_to_use;
dma = dma_map_single(dev, skb->data, size, DMA_TO_DEVICE); ret = priv->ops.fill_desc(ring, skb, size, seg_num == 1 ? 1 : 0,
if (dma_mapping_error(dev, dma)) { DESC_TYPE_SKB);
netdev_err(netdev, "TX head DMA map failed\n");
ring->stats.sw_err_cnt++;
goto out_err_tx_ok;
}
ret = priv->ops.fill_desc(ring, skb, size, dma, seg_num == 1 ? 1 : 0,
DESC_TYPE_SKB);
if (ret) if (ret)
goto head_dma_map_err; goto head_dma_map_err;
...@@ -1194,15 +1198,10 @@ netdev_tx_t hns3_nic_net_xmit(struct sk_buff *skb, struct net_device *netdev) ...@@ -1194,15 +1198,10 @@ netdev_tx_t hns3_nic_net_xmit(struct sk_buff *skb, struct net_device *netdev)
for (i = 1; i < seg_num; i++) { for (i = 1; i < seg_num; i++) {
frag = &skb_shinfo(skb)->frags[i - 1]; frag = &skb_shinfo(skb)->frags[i - 1];
size = skb_frag_size(frag); size = skb_frag_size(frag);
dma = skb_frag_dma_map(dev, frag, 0, size, DMA_TO_DEVICE);
if (dma_mapping_error(dev, dma)) { ret = priv->ops.fill_desc(ring, frag, size,
netdev_err(netdev, "TX frag(%d) DMA map failed\n", i); seg_num - 1 == i ? 1 : 0,
ring->stats.sw_err_cnt++; DESC_TYPE_PAGE);
goto frag_dma_map_err;
}
ret = priv->ops.fill_desc(ring, skb_frag_page(frag), size, dma,
seg_num - 1 == i ? 1 : 0,
DESC_TYPE_PAGE);
if (ret) if (ret)
goto frag_dma_map_err; goto frag_dma_map_err;
......
...@@ -419,8 +419,7 @@ struct hns3_nic_ring_data { ...@@ -419,8 +419,7 @@ struct hns3_nic_ring_data {
struct hns3_nic_ops { struct hns3_nic_ops {
int (*fill_desc)(struct hns3_enet_ring *ring, void *priv, int (*fill_desc)(struct hns3_enet_ring *ring, void *priv,
int size, dma_addr_t dma, int frag_end, int size, int frag_end, enum hns_desc_type type);
enum hns_desc_type type);
int (*maybe_stop_tx)(struct sk_buff **out_skb, int (*maybe_stop_tx)(struct sk_buff **out_skb,
int *bnum, struct hns3_enet_ring *ring); int *bnum, struct hns3_enet_ring *ring);
void (*get_rxd_bnum)(u32 bnum_flag, int *out_bnum); void (*get_rxd_bnum)(u32 bnum_flag, int *out_bnum);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment