Merge branch 'sfc-fix-bugs-introduced-by-XDP-patches'

Edward Cree says:

====================
sfc: fix bugs introduced by XDP patches

Two fixes for bugs introduced by the XDP support in the sfc driver.
====================

Signed-off-by: David S. Miller <davem@davemloft.net>

+26 -29
+18 -19
drivers/net/ethernet/sfc/efx.c
··· 1472 n_xdp_tx = num_possible_cpus(); 1473 n_xdp_ev = DIV_ROUND_UP(n_xdp_tx, EFX_TXQ_TYPES); 1474 1475 /* Check resources. 1476 * We need a channel per event queue, plus a VI per tx queue. 1477 * This may be more pessimistic than it needs to be. ··· 1499 n_xdp_tx, n_xdp_ev); 1500 } 1501 1502 - n_channels = min(n_channels, max_channels); 1503 - 1504 - vec_count = pci_msix_vec_count(efx->pci_dev); 1505 - if (vec_count < 0) 1506 - return vec_count; 1507 if (vec_count < n_channels) { 1508 netif_err(efx, drv, efx->net_dev, 1509 "WARNING: Insufficient MSI-X vectors available (%d < %u).\n", ··· 1508 n_channels = vec_count; 1509 } 1510 1511 - efx->n_channels = n_channels; 1512 1513 - /* Do not create the PTP TX queue(s) if PTP uses the MC directly. */ 1514 - if (extra_channels && !efx_ptp_use_mac_tx_timestamps(efx)) 1515 - n_channels--; 1516 1517 /* Ignore XDP tx channels when creating rx channels. */ 1518 n_channels -= efx->n_xdp_channels; ··· 1530 efx->n_rx_channels = n_channels; 1531 } 1532 1533 - if (efx->n_xdp_channels) 1534 - efx->xdp_channel_offset = efx->tx_channel_offset + 1535 - efx->n_tx_channels; 1536 - else 1537 - efx->xdp_channel_offset = efx->n_channels; 1538 1539 netif_dbg(efx, drv, efx->net_dev, 1540 "Allocating %u RX channels\n", ··· 1548 static int efx_probe_interrupts(struct efx_nic *efx) 1549 { 1550 unsigned int extra_channels = 0; 1551 unsigned int i, j; 1552 int rc; 1553 ··· 1630 for (i = 0; i < EFX_MAX_EXTRA_CHANNELS; i++) { 1631 if (!efx->extra_channel_type[i]) 1632 continue; 1633 - if (efx->interrupt_mode != EFX_INT_MODE_MSIX || 1634 - efx->n_channels <= extra_channels) { 1635 efx->extra_channel_type[i]->handle_no_channel(efx); 1636 } else { 1637 --j; ··· 1641 } 1642 } 1643 1644 /* RSS might be usable on VFs even if it is disabled on the PF */ 1645 #ifdef CONFIG_SFC_SRIOV 1646 if (efx->type->sriov_wanted) { 1647 - efx->rss_spread = ((efx->n_rx_channels > 1 || 1648 !efx->type->sriov_wanted(efx)) ? 1649 - efx->n_rx_channels : efx_vf_size(efx)); 1650 return 0; 1651 } 1652 #endif 1653 - efx->rss_spread = efx->n_rx_channels; 1654 1655 return 0; 1656 }
··· 1472 n_xdp_tx = num_possible_cpus(); 1473 n_xdp_ev = DIV_ROUND_UP(n_xdp_tx, EFX_TXQ_TYPES); 1474 1475 + vec_count = pci_msix_vec_count(efx->pci_dev); 1476 + if (vec_count < 0) 1477 + return vec_count; 1478 + 1479 + max_channels = min_t(unsigned int, vec_count, max_channels); 1480 + 1481 /* Check resources. 1482 * We need a channel per event queue, plus a VI per tx queue. 1483 * This may be more pessimistic than it needs to be. ··· 1493 n_xdp_tx, n_xdp_ev); 1494 } 1495 1496 if (vec_count < n_channels) { 1497 netif_err(efx, drv, efx->net_dev, 1498 "WARNING: Insufficient MSI-X vectors available (%d < %u).\n", ··· 1507 n_channels = vec_count; 1508 } 1509 1510 + n_channels = min(n_channels, max_channels); 1511 1512 + efx->n_channels = n_channels; 1513 1514 /* Ignore XDP tx channels when creating rx channels. */ 1515 n_channels -= efx->n_xdp_channels; ··· 1531 efx->n_rx_channels = n_channels; 1532 } 1533 1534 + efx->n_rx_channels = min(efx->n_rx_channels, parallelism); 1535 + efx->n_tx_channels = min(efx->n_tx_channels, parallelism); 1536 + 1537 + efx->xdp_channel_offset = n_channels; 1538 1539 netif_dbg(efx, drv, efx->net_dev, 1540 "Allocating %u RX channels\n", ··· 1550 static int efx_probe_interrupts(struct efx_nic *efx) 1551 { 1552 unsigned int extra_channels = 0; 1553 + unsigned int rss_spread; 1554 unsigned int i, j; 1555 int rc; 1556 ··· 1631 for (i = 0; i < EFX_MAX_EXTRA_CHANNELS; i++) { 1632 if (!efx->extra_channel_type[i]) 1633 continue; 1634 + if (j <= efx->tx_channel_offset + efx->n_tx_channels) { 1635 efx->extra_channel_type[i]->handle_no_channel(efx); 1636 } else { 1637 --j; ··· 1643 } 1644 } 1645 1646 + rss_spread = efx->n_rx_channels; 1647 /* RSS might be usable on VFs even if it is disabled on the PF */ 1648 #ifdef CONFIG_SFC_SRIOV 1649 if (efx->type->sriov_wanted) { 1650 + efx->rss_spread = ((rss_spread > 1 || 1651 !efx->type->sriov_wanted(efx)) ? 1652 + rss_spread : efx_vf_size(efx)); 1653 return 0; 1654 } 1655 #endif 1656 + efx->rss_spread = rss_spread; 1657 1658 return 0; 1659 }
+1 -3
drivers/net/ethernet/sfc/net_driver.h
··· 1533 1534 static inline bool efx_channel_has_tx_queues(struct efx_channel *channel) 1535 { 1536 - return efx_channel_is_xdp_tx(channel) || 1537 - (channel->type && channel->type->want_txqs && 1538 - channel->type->want_txqs(channel)); 1539 } 1540 1541 static inline struct efx_tx_queue *
··· 1533 1534 static inline bool efx_channel_has_tx_queues(struct efx_channel *channel) 1535 { 1536 + return true; 1537 } 1538 1539 static inline struct efx_tx_queue *
+7 -7
drivers/net/ethernet/sfc/rx.c
··· 96 97 void efx_rx_config_page_split(struct efx_nic *efx) 98 { 99 - efx->rx_page_buf_step = ALIGN(efx->rx_dma_len + efx->rx_ip_align, 100 EFX_RX_BUF_ALIGNMENT); 101 efx->rx_bufs_per_page = efx->rx_buffer_order ? 1 : 102 ((PAGE_SIZE - sizeof(struct efx_rx_page_state)) / 103 - (efx->rx_page_buf_step + XDP_PACKET_HEADROOM)); 104 efx->rx_buffer_truesize = (PAGE_SIZE << efx->rx_buffer_order) / 105 efx->rx_bufs_per_page; 106 efx->rx_pages_per_batch = DIV_ROUND_UP(EFX_RX_PREFERRED_BATCH, ··· 191 page_offset = sizeof(struct efx_rx_page_state); 192 193 do { 194 - page_offset += XDP_PACKET_HEADROOM; 195 - dma_addr += XDP_PACKET_HEADROOM; 196 - 197 index = rx_queue->added_count & rx_queue->ptr_mask; 198 rx_buf = efx_rx_buffer(rx_queue, index); 199 - rx_buf->dma_addr = dma_addr + efx->rx_ip_align; 200 rx_buf->page = page; 201 - rx_buf->page_offset = page_offset + efx->rx_ip_align; 202 rx_buf->len = efx->rx_dma_len; 203 rx_buf->flags = 0; 204 ++rx_queue->added_count;
··· 96 97 void efx_rx_config_page_split(struct efx_nic *efx) 98 { 99 + efx->rx_page_buf_step = ALIGN(efx->rx_dma_len + efx->rx_ip_align + 100 + XDP_PACKET_HEADROOM, 101 EFX_RX_BUF_ALIGNMENT); 102 efx->rx_bufs_per_page = efx->rx_buffer_order ? 1 : 103 ((PAGE_SIZE - sizeof(struct efx_rx_page_state)) / 104 + efx->rx_page_buf_step); 105 efx->rx_buffer_truesize = (PAGE_SIZE << efx->rx_buffer_order) / 106 efx->rx_bufs_per_page; 107 efx->rx_pages_per_batch = DIV_ROUND_UP(EFX_RX_PREFERRED_BATCH, ··· 190 page_offset = sizeof(struct efx_rx_page_state); 191 192 do { 193 index = rx_queue->added_count & rx_queue->ptr_mask; 194 rx_buf = efx_rx_buffer(rx_queue, index); 195 + rx_buf->dma_addr = dma_addr + efx->rx_ip_align + 196 + XDP_PACKET_HEADROOM; 197 rx_buf->page = page; 198 + rx_buf->page_offset = page_offset + efx->rx_ip_align + 199 + XDP_PACKET_HEADROOM; 200 rx_buf->len = efx->rx_dma_len; 201 rx_buf->flags = 0; 202 ++rx_queue->added_count;