The SMMU engine on HIP09 chip has a hardware issue. SMMU pagetable prefetch features may prefetch and use a invalid PTE even the PTE is valid at that time. This will cause the device trigger fake pagefaults. The solution is to avoid prefetching by adding a SYNC command when smmu mapping a iova. But the performance of nic has a sharp drop. Then we do this workaround, always enable tx bounce buffer, avoid mapping/unmapping on TX path. This issue only affects HNS3, so we always enable tx bounce buffer when smmu enabled to improve performance.
Unified · Split
| @@ -11,6 +11,7 @@ · 10 unmodified lines | |||
| 11 | #include <linux/irq.h> | 11 | #include <linux/irq.h> |
| 12 | #include <linux/ip.h> | 12 | #include <linux/ip.h> |
| 13 | #include <linux/ipv6.h> | 13 | #include <linux/ipv6.h> |
| 14 | #include <linux/iommu.h> | ||
| 14 | #include <linux/module.h> | 15 | #include <linux/module.h> |
| 15 | #include <linux/pci.h> | 16 | #include <linux/pci.h> |
| 16 | #include <linux/skbuff.h> | 17 | #include <linux/skbuff.h> |
| @@ -1039,6 +1040,8 @@ static bool hns3_can_use_tx_sgl(struct hns3_enet_ring *ring, · 1022 unmodified lines | |||
| 1039 | static void hns3_init_tx_spare_buffer(struct hns3_enet_ring *ring) | 1040 | static void hns3_init_tx_spare_buffer(struct hns3_enet_ring *ring) |
| 1040 | { | 1041 | { |
| 1041 | u32 alloc_size = ring->tqp->handle->kinfo.tx_spare_buf_size; | 1042 | u32 alloc_size = ring->tqp->handle->kinfo.tx_spare_buf_size; |
| 1043 | struct net_device *netdev = ring_to_netdev(ring); | ||
| 1044 | struct hns3_nic_priv *priv = netdev_priv(netdev); | ||
| 1042 | struct hns3_tx_spare *tx_spare; | 1045 | struct hns3_tx_spare *tx_spare; |
| 1043 | struct page *page; | 1046 | struct page *page; |
| 1044 | dma_addr_t dma; | 1047 | dma_addr_t dma; |
| @@ -1080,6 +1083,7 @@ static void hns3_init_tx_spare_buffer(struct hns3_enet_ring *ring) · 35 unmodified lines | |||
| 1080 | tx_spare->buf = page_address(page); | 1083 | tx_spare->buf = page_address(page); |
| 1081 | tx_spare->len = PAGE_SIZE << order; | 1084 | tx_spare->len = PAGE_SIZE << order; |
| 1082 | ring->tx_spare = tx_spare; | 1085 | ring->tx_spare = tx_spare; |
| 1086 | ring->tx_copybreak = priv->tx_copybreak; | ||
| 1083 | return; | 1087 | return; |
| 1084 | 1088 | ||
| 1085 | dma_mapping_error: | 1089 | dma_mapping_error: |
| @@ -4874,6 +4878,30 @@ static void hns3_nic_dealloc_vector_data(struct hns3_nic_priv *priv) · 3788 unmodified lines | |||
| 4874 | devm_kfree(&pdev->dev, priv->tqp_vector); | 4878 | devm_kfree(&pdev->dev, priv->tqp_vector); |
| 4875 | } | 4879 | } |
| 4876 | 4880 | ||
| 4881 | static void hns3_update_tx_spare_buf_config(struct hns3_nic_priv *priv) | ||
| 4882 | { | ||
| 4883 | #define HNS3_MIN_SPARE_BUF_SIZE (2 * 1024 * 1024) | ||
| 4884 | #define HNS3_MAX_PACKET_SIZE (64 * 1024) | ||
| 4885 | |||
| 4886 | struct iommu_domain *domain = iommu_get_domain_for_dev(priv->dev); | ||
| 4887 | struct hnae3_ae_dev *ae_dev = hns3_get_ae_dev(priv->ae_handle); | ||
| 4888 | struct hnae3_handle *handle = priv->ae_handle; | ||
| 4889 | |||
| 4890 | if (ae_dev->dev_version < HNAE3_DEVICE_VERSION_V3) | ||
| 4891 | return; | ||
| 4892 | |||
| 4893 | if (!(domain && iommu_is_dma_domain(domain))) | ||
| 4894 | return; | ||
| 4895 | |||
| 4896 | priv->min_tx_copybreak = HNS3_MAX_PACKET_SIZE; | ||
| 4897 | priv->min_tx_spare_buf_size = HNS3_MIN_SPARE_BUF_SIZE; | ||
| 4898 | |||
| 4899 | if (priv->tx_copybreak < priv->min_tx_copybreak) | ||
| 4900 | priv->tx_copybreak = priv->min_tx_copybreak; | ||
| 4901 | if (handle->kinfo.tx_spare_buf_size < priv->min_tx_spare_buf_size) | ||
| 4902 | handle->kinfo.tx_spare_buf_size = priv->min_tx_spare_buf_size; | ||
| 4903 | } | ||
| 4904 | |||
| 4877 | static void hns3_ring_get_cfg(struct hnae3_queue *q, struct hns3_nic_priv *priv, | 4905 | static void hns3_ring_get_cfg(struct hnae3_queue *q, struct hns3_nic_priv *priv, |
| 4878 | unsigned int ring_type) | 4906 | unsigned int ring_type) |
| 4879 | { | 4907 | { |
| @@ -5107,6 +5135,7 @@ int hns3_init_all_ring(struct hns3_nic_priv *priv) · 227 unmodified lines | |||
| 5107 | int i, j; | 5135 | int i, j; |
| 5108 | int ret; | 5136 | int ret; |
| 5109 | 5137 | ||
| 5138 | hns3_update_tx_spare_buf_config(priv); | ||
| 5110 | for (i = 0; i < ring_num; i++) { | 5139 | for (i = 0; i < ring_num; i++) { |
| 5111 | ret = hns3_alloc_ring_memory(&priv->ring[i]); | 5140 | ret = hns3_alloc_ring_memory(&priv->ring[i]); |
| 5112 | if (ret) { | 5141 | if (ret) { |
| @@ -5311,6 +5340,8 @@ static int hns3_client_init(struct hnae3_handle *handle) · 198 unmodified lines | |||
| 5311 | priv->ae_handle = handle; | 5340 | priv->ae_handle = handle; |
| 5312 | priv->tx_timeout_count = 0; | 5341 | priv->tx_timeout_count = 0; |
| 5313 | priv->max_non_tso_bd_num = ae_dev->dev_specs.max_non_tso_bd_num; | 5342 | priv->max_non_tso_bd_num = ae_dev->dev_specs.max_non_tso_bd_num; |
| 5343 | priv->min_tx_copybreak = 0; | ||
| 5344 | priv->min_tx_spare_buf_size = 0; | ||
| 5314 | set_bit(HNS3_NIC_STATE_DOWN, &priv->state); | 5345 | set_bit(HNS3_NIC_STATE_DOWN, &priv->state); |
| 5315 | 5346 | ||
| 5316 | handle->msg_enable = netif_msg_init(debug, DEFAULT_MSG_LEVEL); | 5347 | handle->msg_enable = netif_msg_init(debug, DEFAULT_MSG_LEVEL); |
| @@ -596,6 +596,8 @@ struct hns3_nic_priv { · 595 unmodified lines | |||
| 596 | struct hns3_enet_coalesce rx_coal; | 596 | struct hns3_enet_coalesce rx_coal; |
| 597 | u32 tx_copybreak; | 597 | u32 tx_copybreak; |
| 598 | u32 rx_copybreak; | 598 | u32 rx_copybreak; |
| 599 | u32 min_tx_copybreak; | ||
| 600 | u32 min_tx_spare_buf_size; | ||
| 599 | }; | 601 | }; |
| 600 | 602 | ||
| 601 | union l3_hdr_info { | 603 | union l3_hdr_info { |