When a buffer pool cannot be allocated in open(), ibmveth_alloc_queue_buffer_pools() clears the pool's active flag. Nothing sets it again except an MTU change or a pool sysfs write, so every later open() runs without that pool, possibly without one large enough for the MTU. With multi-queue RX, later in this series, every queue copies queue 0's pool flags on open(), so a failure on queue 0 would disable that pool on all queues. The clear came with commit 860f242eb534 ("[PATCH] ibmveth change buffer pools dynamically"), whose unwind freed only active pools. The unwind now frees every pool, and ibmveth_free_buffer_pool() handles one that was never allocated, so the clear no longer serves the unwind. Drop it, so open() still fails with -ENOMEM and the next open() retries the pool. This only changes what happens after an allocation failure, so it goes to net-next. Found by code review; not reported from the field. Fixes: 860f242eb534 ("[PATCH] ibmveth change buffer pools dynamically") Signed-off-by: Mingming Cao --- drivers/net/ethernet/ibm/ibmveth.c | 1 - 1 file changed, 1 deletion(-) diff --git a/drivers/net/ethernet/ibm/ibmveth.c b/drivers/net/ethernet/ibm/ibmveth.c index e121faf50f04..388cfa43f514 100644 --- a/drivers/net/ethernet/ibm/ibmveth.c +++ b/drivers/net/ethernet/ibm/ibmveth.c @@ -866,7 +866,6 @@ static int ibmveth_alloc_queue_buffer_pools(struct ibmveth_adapter *adapter, queue, i, bpool->buff_size, bpool->size); - bpool->active = 0; /* Undo the pools this queue already allocated; the * failed one freed its own partial allocation. */ -- 2.50.1 (Apple Git-155) ibmveth transmits on up to 16 TX queues, each under its own TX lock, but they all update the same counters (tx_packets, tx_bytes, tx_dropped, tx_large_packets and tx_send_failed), so two queues sending at once can lose counts. Multi-queue RX, later in this series, would have the same problem, so fix TX first and lay the ground for the per-queue RX counters that follow. Give each TX queue its own counters, written under its TX lock, and move tx_large_packets and tx_send_failed there from struct ibmveth_adapter. ip -s link reads them through a new ndo_get_stats64; RX still comes from dev->stats for now. ethtool -S keeps its keys and order. Both sum every TX queue, not just the live ones, so lowering the TX count never makes a total go backwards. Found by code review while making the RX statistics per queue; not reported from the field. Fixes: d926793c1de9 ("ibmveth: Implement multi queue on xmit") Signed-off-by: Mingming Cao --- Only statistics are lost, so this goes to net-next despite the Fixes: tag. drivers/net/ethernet/ibm/ibmveth.c | 187 ++++++++++++++++++++++++----- drivers/net/ethernet/ibm/ibmveth.h | 14 ++- 2 files changed, 169 insertions(+), 32 deletions(-) diff --git a/drivers/net/ethernet/ibm/ibmveth.c b/drivers/net/ethernet/ibm/ibmveth.c index 388cfa43f514..3a29fa601dba 100644 --- a/drivers/net/ethernet/ibm/ibmveth.c +++ b/drivers/net/ethernet/ibm/ibmveth.c @@ -72,30 +72,55 @@ module_param(old_large_send, bool, 0444); MODULE_PARM_DESC(old_large_send, "Use old large send method on firmware that supports the new method"); +/** + * enum ibmveth_stat_src - where an ethtool -S counter is stored + * @IBMVETH_STAT_ADAPTER: plain u64 in struct ibmveth_adapter + * @IBMVETH_STAT_TX_QSUM: per-queue u64, summed over tx_qstats[] + * + * Counters live per queue so that queues never share a field. + */ +enum ibmveth_stat_src { + IBMVETH_STAT_ADAPTER, + IBMVETH_STAT_TX_QSUM, +}; + struct ibmveth_stat { char name[ETH_GSTRING_LEN]; - int offset; + enum ibmveth_stat_src src; + /* Offset into the struct named by @src. */ + size_t off; }; #define IBMVETH_STAT_OFF(stat) offsetof(struct ibmveth_adapter, stat) +#define IBMVETH_TXQ_OFF(stat) offsetof(struct ibmveth_tx_queue_stats, stat) + +/* Single writer per counter; lockless readers use READ_ONCE(). */ +#define IBMVETH_STAT_ADD(stat, n) WRITE_ONCE((stat), (stat) + (n)) +#define IBMVETH_STAT_INC(stat) IBMVETH_STAT_ADD(stat, 1) #define IBMVETH_GET_STAT(a, off) *((u64 *)(((unsigned long)(a)) + off)) +#define IBMVETH_ADAPTER_STAT(key, field) \ + { key, IBMVETH_STAT_ADAPTER, IBMVETH_STAT_OFF(field) } +#define IBMVETH_TXQ_STAT(key, field) \ + { key, IBMVETH_STAT_TX_QSUM, IBMVETH_TXQ_OFF(field) } + +/* Key names and order are user-visible: append only. */ static struct ibmveth_stat ibmveth_stats[] = { - { "replenish_task_cycles", IBMVETH_STAT_OFF(replenish_task_cycles) }, - { "replenish_no_mem", IBMVETH_STAT_OFF(replenish_no_mem) }, - { "replenish_add_buff_failure", - IBMVETH_STAT_OFF(replenish_add_buff_failure) }, - { "replenish_add_buff_success", - IBMVETH_STAT_OFF(replenish_add_buff_success) }, - { "rx_invalid_buffer", IBMVETH_STAT_OFF(rx_invalid_buffer) }, - { "rx_no_buffer", IBMVETH_STAT_OFF(rx_no_buffer) }, - { "tx_map_failed", IBMVETH_STAT_OFF(tx_map_failed) }, - { "tx_send_failed", IBMVETH_STAT_OFF(tx_send_failed) }, - { "fw_enabled_ipv4_csum", IBMVETH_STAT_OFF(fw_ipv4_csum_support) }, - { "fw_enabled_ipv6_csum", IBMVETH_STAT_OFF(fw_ipv6_csum_support) }, - { "tx_large_packets", IBMVETH_STAT_OFF(tx_large_packets) }, - { "rx_large_packets", IBMVETH_STAT_OFF(rx_large_packets) }, - { "fw_enabled_large_send", IBMVETH_STAT_OFF(fw_large_send_support) } + IBMVETH_ADAPTER_STAT("replenish_task_cycles", replenish_task_cycles), + IBMVETH_ADAPTER_STAT("replenish_no_mem", replenish_no_mem), + IBMVETH_ADAPTER_STAT("replenish_add_buff_failure", + replenish_add_buff_failure), + IBMVETH_ADAPTER_STAT("replenish_add_buff_success", + replenish_add_buff_success), + IBMVETH_ADAPTER_STAT("rx_invalid_buffer", rx_invalid_buffer), + IBMVETH_ADAPTER_STAT("rx_no_buffer", rx_no_buffer), + IBMVETH_ADAPTER_STAT("tx_map_failed", tx_map_failed), + IBMVETH_TXQ_STAT("tx_send_failed", send_failures), + IBMVETH_ADAPTER_STAT("fw_enabled_ipv4_csum", fw_ipv4_csum_support), + IBMVETH_ADAPTER_STAT("fw_enabled_ipv6_csum", fw_ipv6_csum_support), + IBMVETH_TXQ_STAT("tx_large_packets", large_packets), + IBMVETH_ADAPTER_STAT("rx_large_packets", rx_large_packets), + IBMVETH_ADAPTER_STAT("fw_enabled_large_send", fw_large_send_support), }; /* simple methods of getting data from the current rxq entry */ @@ -225,6 +250,33 @@ ibmveth_free_filter_list(struct ibmveth_adapter *adapter) } } +/** + * ibmveth_alloc_tx_qstats - Allocate per-queue TX statistics + * @adapter: ibmveth adapter structure + * + * Return: 0 on success, -ENOMEM on failure + */ +static int ibmveth_alloc_tx_qstats(struct ibmveth_adapter *adapter) +{ + adapter->tx_qstats = kcalloc(IBMVETH_MAX_QUEUES, + sizeof(*adapter->tx_qstats), + GFP_KERNEL); + if (!adapter->tx_qstats) + return -ENOMEM; + + return 0; +} + +/** + * ibmveth_free_tx_qstats - Free per-queue TX statistics + * @adapter: ibmveth adapter structure + */ +static void ibmveth_free_tx_qstats(struct ibmveth_adapter *adapter) +{ + kfree(adapter->tx_qstats); + adapter->tx_qstats = NULL; +} + /** * ibmveth_alloc_rx_queues - Allocate per-queue RX resources * @adapter: ibmveth adapter structure @@ -1580,6 +1632,39 @@ static int ibmveth_set_features(struct net_device *dev, return rc1 ? rc1 : rc2; } +/* + * Sum every slot, not just the live queues, so shrinking the queue + * count cannot make a counter go backwards. + */ +static u64 ibmveth_sum_tx_qstat(struct ibmveth_adapter *adapter, size_t off) +{ + u64 total = 0; + int i; + + for (i = 0; i < IBMVETH_MAX_QUEUES; i++) { + const u8 *q = (const u8 *)&adapter->tx_qstats[i]; + + total += READ_ONCE(*(const u64 *)(q + off)); + } + + return total; +} + +static u64 ibmveth_ethtool_adapter_stat(struct ibmveth_adapter *adapter, + int index) +{ + const struct ibmveth_stat *stat = &ibmveth_stats[index]; + + switch (stat->src) { + case IBMVETH_STAT_TX_QSUM: + return ibmveth_sum_tx_qstat(adapter, stat->off); + case IBMVETH_STAT_ADAPTER: + break; + } + + return IBMVETH_GET_STAT(adapter, stat->off); +} + static void ibmveth_get_strings(struct net_device *dev, u32 stringset, u8 *data) { int i; @@ -1608,7 +1693,7 @@ static void ibmveth_get_ethtool_stats(struct net_device *dev, struct ibmveth_adapter *adapter = netdev_priv(dev); for (i = 0; i < ARRAY_SIZE(ibmveth_stats); i++) - data[i] = IBMVETH_GET_STAT(adapter, ibmveth_stats[i].offset); + data[i] = ibmveth_ethtool_adapter_stat(adapter, i); } static void ibmveth_get_channels(struct net_device *netdev, @@ -1729,8 +1814,10 @@ static int ibmveth_send(struct ibmveth_adapter *adapter, } static int ibmveth_is_packet_unsupported(struct sk_buff *skb, - struct net_device *netdev) + struct ibmveth_adapter *adapter, + int queue_num) { + struct net_device *netdev = adapter->netdev; struct ethhdr *ether_header; int ret = 0; @@ -1738,7 +1825,7 @@ static int ibmveth_is_packet_unsupported(struct sk_buff *skb, if (ether_addr_equal(ether_header->h_dest, netdev->dev_addr)) { netdev_dbg(netdev, "veth doesn't support loopback packets, dropping packet.\n"); - netdev->stats.tx_dropped++; + IBMVETH_STAT_INC(adapter->tx_qstats[queue_num].dropped_packets); ret = -EOPNOTSUPP; } @@ -1749,22 +1836,25 @@ static netdev_tx_t ibmveth_start_xmit(struct sk_buff *skb, struct net_device *netdev) { struct ibmveth_adapter *adapter = netdev_priv(netdev); + struct ibmveth_tx_queue_stats *txs; unsigned int desc_flags, total_bytes; union ibmveth_buf_desc desc; int i, queue_num = skb_get_queue_mapping(skb); unsigned long mss = 0; void *ltb; + txs = &adapter->tx_qstats[queue_num]; + /* A sender that picked its queue before ethtool -L shrank the TX * queues can get here after that queue's LTB was freed. */ ltb = READ_ONCE(adapter->tx_ltb_ptr[queue_num]); if (unlikely(!ltb)) { - netdev->stats.tx_dropped++; + IBMVETH_STAT_INC(txs->dropped_packets); goto out; } - if (ibmveth_is_packet_unsupported(skb, netdev)) + if (ibmveth_is_packet_unsupported(skb, adapter, queue_num)) goto out; /* veth can't checksum offload UDP */ if (skb->ip_summed == CHECKSUM_PARTIAL && @@ -1775,7 +1865,7 @@ static netdev_tx_t ibmveth_start_xmit(struct sk_buff *skb, skb_checksum_help(skb)) { netdev_err(netdev, "tx: failed to checksum packet\n"); - netdev->stats.tx_dropped++; + IBMVETH_STAT_INC(txs->dropped_packets); goto out; } @@ -1798,7 +1888,7 @@ static netdev_tx_t ibmveth_start_xmit(struct sk_buff *skb, if (skb->ip_summed == CHECKSUM_PARTIAL && skb_is_gso(skb)) { if (adapter->fw_large_send_support) { mss = (unsigned long)skb_shinfo(skb)->gso_size; - adapter->tx_large_packets++; + IBMVETH_STAT_INC(txs->large_packets); } else if (!skb_is_gso_v6(skb)) { /* Put -1 in the IP checksum to tell phyp it * is a largesend packet. Put the mss in @@ -1807,7 +1897,7 @@ static netdev_tx_t ibmveth_start_xmit(struct sk_buff *skb, ip_hdr(skb)->check = 0xffff; tcp_hdr(skb)->check = cpu_to_be16(skb_shinfo(skb)->gso_size); - adapter->tx_large_packets++; + IBMVETH_STAT_INC(txs->large_packets); } } @@ -1815,7 +1905,7 @@ static netdev_tx_t ibmveth_start_xmit(struct sk_buff *skb, if (unlikely(skb->len > adapter->tx_ltb_size)) { netdev_err(adapter->netdev, "tx: packet size (%u) exceeds ltb (%u)\n", skb->len, adapter->tx_ltb_size); - netdev->stats.tx_dropped++; + IBMVETH_STAT_INC(txs->dropped_packets); goto out; } memcpy(ltb, skb->data, skb_headlen(skb)); @@ -1832,7 +1922,7 @@ static netdev_tx_t ibmveth_start_xmit(struct sk_buff *skb, if (unlikely(total_bytes != skb->len)) { netdev_err(adapter->netdev, "tx: incorrect packet len copied into ltb (%u != %u)\n", skb->len, total_bytes); - netdev->stats.tx_dropped++; + IBMVETH_STAT_INC(txs->dropped_packets); goto out; } desc.fields.flags_len = desc_flags | skb->len; @@ -1841,11 +1931,11 @@ static netdev_tx_t ibmveth_start_xmit(struct sk_buff *skb, dma_wmb(); if (ibmveth_send(adapter, desc.desc, mss)) { - adapter->tx_send_failed++; - netdev->stats.tx_dropped++; + IBMVETH_STAT_INC(txs->send_failures); + IBMVETH_STAT_INC(txs->dropped_packets); } else { - netdev->stats.tx_packets++; - netdev->stats.tx_bytes += skb->len; + IBMVETH_STAT_INC(txs->packets); + IBMVETH_STAT_ADD(txs->bytes, skb->len); } out: @@ -2414,6 +2504,34 @@ static netdev_features_t ibmveth_features_check(struct sk_buff *skb, return vlan_features_check(skb, features); } +/** + * ibmveth_get_stats64 - Return aggregated per-queue statistics + * @dev: network device + * @stats: rtnl link statistics storage + * + * Sums per-queue tx_qstats into the rtnl counters; RX still comes from + * dev->stats. + * Walk the full allocated arrays (not the live queue count) so shrinking + * channels cannot make the totals go backwards. + */ +static void ibmveth_get_stats64(struct net_device *dev, + struct rtnl_link_stats64 *stats) +{ + struct ibmveth_adapter *adapter = netdev_priv(dev); + int i; + + stats->rx_packets = READ_ONCE(dev->stats.rx_packets); + stats->rx_bytes = READ_ONCE(dev->stats.rx_bytes); + stats->rx_dropped = READ_ONCE(dev->stats.rx_dropped); + + for (i = 0; i < IBMVETH_MAX_QUEUES; i++) { + stats->tx_packets += READ_ONCE(adapter->tx_qstats[i].packets); + stats->tx_bytes += READ_ONCE(adapter->tx_qstats[i].bytes); + stats->tx_dropped += + READ_ONCE(adapter->tx_qstats[i].dropped_packets); + } +} + static const struct net_device_ops ibmveth_netdev_ops = { .ndo_open = ibmveth_open, .ndo_stop = ibmveth_close, @@ -2426,6 +2544,7 @@ static const struct net_device_ops ibmveth_netdev_ops = { .ndo_validate_addr = eth_validate_addr, .ndo_set_mac_address = ibmveth_set_mac_addr, .ndo_features_check = ibmveth_features_check, + .ndo_get_stats64 = ibmveth_get_stats64, }; /** @@ -2581,6 +2700,11 @@ static int ibmveth_probe(struct vio_dev *dev, const struct vio_device_id *id) kobject_uevent(kobj, KOBJ_ADD); } + if (ibmveth_alloc_tx_qstats(adapter)) { + rc = -ENOMEM; + goto err_put_pools; + } + rc = netif_set_real_num_tx_queues(netdev, min(num_online_cpus(), IBMVETH_DEFAULT_QUEUES)); if (rc) { @@ -2610,6 +2734,7 @@ static int ibmveth_probe(struct vio_dev *dev, const struct vio_device_id *id) err_put_pools: ibmveth_put_pool_kobjs(adapter); + ibmveth_free_tx_qstats(adapter); free_netdev(netdev); return rc; } @@ -2625,6 +2750,8 @@ static void ibmveth_remove(struct vio_dev *dev) unregister_netdev(netdev); + ibmveth_free_tx_qstats(adapter); + free_netdev(netdev); dev_set_drvdata(&dev->dev, NULL); } diff --git a/drivers/net/ethernet/ibm/ibmveth.h b/drivers/net/ethernet/ibm/ibmveth.h index 60a94f1d23bc..03b087ed5761 100644 --- a/drivers/net/ethernet/ibm/ibmveth.h +++ b/drivers/net/ethernet/ibm/ibmveth.h @@ -134,6 +134,15 @@ static int pool_active[] = { 1, 1, 0, 0, 1}; #define IBM_VETH_INVALID_MAP ((u16)0xffff) +/* Per-queue TX counters; serialized by the stack's per-queue TX lock. */ +struct ibmveth_tx_queue_stats { + u64 packets; + u64 bytes; + u64 large_packets; + u64 dropped_packets; + u64 send_failures; +} ____cacheline_aligned_in_smp; + struct ibmveth_buff_pool { u32 size; u32 index; @@ -195,9 +204,10 @@ struct ibmveth_adapter { u64 rx_invalid_buffer; u64 rx_no_buffer; u64 tx_map_failed; - u64 tx_send_failed; - u64 tx_large_packets; u64 rx_large_packets; + + struct ibmveth_tx_queue_stats *tx_qstats; + /* Ethtool settings */ u8 duplex; u32 speed; -- 2.50.1 (Apple Git-155) Power11 firmware can give a virtual ethernet adapter several RX queues. Add the PAPR 11.20.00 hcall numbers to register a queue, add buffers to it and free it: H_REG_LOGICAL_LAN_QUEUE (0x49C), H_ADD_LOGICAL_LAN_BUFFERS_QUEUE (0x4A0) and H_FREE_LOGICAL_LAN_QUEUE (0x4A8). ibmveth uses the first two later in this series; it frees every queue with one H_FREE_LOGICAL_LAN, so the third only completes the set. Raise MAX_HCALL_OPCODE so hvCall_inst counts them. KVM's enabled_hcalls bitmap keeps its size, and KVM implements none of them, so KVM_CAP_PPC_ENABLE_HCALL still rejects them. The tools/perf powerpc-hcalls names will follow separately. Signed-off-by: Mingming Cao --- arch/powerpc/include/asm/hvcall.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/arch/powerpc/include/asm/hvcall.h b/arch/powerpc/include/asm/hvcall.h index dff90a7d7f70..3b3cc9ed20be 100644 --- a/arch/powerpc/include/asm/hvcall.h +++ b/arch/powerpc/include/asm/hvcall.h @@ -362,7 +362,10 @@ #define H_GUEST_DELETE 0x488 #define H_PKS_WRAP_OBJECT 0x490 #define H_PKS_UNWRAP_OBJECT 0x494 -#define MAX_HCALL_OPCODE H_PKS_UNWRAP_OBJECT +#define H_REG_LOGICAL_LAN_QUEUE 0x49C +#define H_ADD_LOGICAL_LAN_BUFFERS_QUEUE 0x4A0 +#define H_FREE_LOGICAL_LAN_QUEUE 0x4A8 +#define MAX_HCALL_OPCODE H_FREE_LOGICAL_LAN_QUEUE /* Scope args for H_SCM_UNBIND_ALL */ #define H_UNBIND_SCOPE_ALL (0x1) -- 2.50.1 (Apple Git-155) This is preparation for multi-queue (MQ) RX; nothing sets multi_queue yet, so single-queue behavior does not change. With MQ, PHYP (the PowerVM hypervisor) identifies each RX queue by a handle, and buffers are posted to a queue through it. On MQ firmware, H_REGISTER_LOGICAL_LAN also returns queue 0's handle, which ibmveth ignores today. Add a multi_queue flag and a queue_handle[] array. When multi_queue is set, register queue 0 with h_register_logical_lan_with_handle(), which makes the same hcall and saves the handle. Signed-off-by: Mingming Cao --- drivers/net/ethernet/ibm/ibmveth.c | 20 +++++++++++++-- drivers/net/ethernet/ibm/ibmveth.h | 40 ++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/ibm/ibmveth.c b/drivers/net/ethernet/ibm/ibmveth.c index 3a29fa601dba..236992ded33a 100644 --- a/drivers/net/ethernet/ibm/ibmveth.c +++ b/drivers/net/ethernet/ibm/ibmveth.c @@ -1192,6 +1192,7 @@ static long ibmveth_register_logical_lan(struct ibmveth_adapter *adapter, unsigned long ua = adapter->vdev->unit_address; unsigned long buf_dma = adapter->buffer_list_dma[0]; unsigned long filter_dma = adapter->filter_list_dma; + unsigned long qh0; /* * After a kexec the adapter will still be open, so our attempt to @@ -1199,8 +1200,23 @@ static long ibmveth_register_logical_lan(struct ibmveth_adapter *adapter, * try again, but only once. */ retry: - rc = h_register_logical_lan(ua, buf_dma, rxq_desc.desc, filter_dma, - mac_address); + /* In multi-queue mode, obtain a queue handle for queue 0 so all RX + * queues, even a single one, use the per-queue buffer hypercalls. + * multi_queue never changes after probe; PowerVM blocks LPM to a + * host without MQ support, so these hypercalls do not go away. + */ + if (adapter->multi_queue) { + rc = h_register_logical_lan_with_handle(ua, buf_dma, + rxq_desc.desc, + filter_dma, + mac_address, + &qh0); + if (rc == H_SUCCESS) + adapter->queue_handle[0] = qh0; + } else { + rc = h_register_logical_lan(ua, buf_dma, rxq_desc.desc, + filter_dma, mac_address); + } if (rc != H_SUCCESS && try_again) { rc = ibmveth_free_logical_lan(adapter); diff --git a/drivers/net/ethernet/ibm/ibmveth.h b/drivers/net/ethernet/ibm/ibmveth.h index 03b087ed5761..7ac3372afc0f 100644 --- a/drivers/net/ethernet/ibm/ibmveth.h +++ b/drivers/net/ethernet/ibm/ibmveth.h @@ -68,6 +68,43 @@ static inline long h_add_logical_lan_buffers(unsigned long unit_address, desc5, desc6, desc7, desc8); } +/** + * h_register_logical_lan_with_handle - Register primary queue and get handle + * @unit_address: Device unit address + * @buffer_list: DMA address of buffer list + * @rec_queue: Buffer descriptor of receive queue + * @filter_list: DMA address of filter list + * @mac_address: MAC address + * @queue_handle: Output queue handle on success + * + * Like h_register_logical_lan(), but returns queue 0's handle so that + * multi-queue mode can post buffers to every queue by handle. R4 + * carries a handle only on firmware that reports MQ RX support in + * H_ILLAN_ATTRIBUTES. + * + * Return: hypervisor return code + */ +static inline long +h_register_logical_lan_with_handle(unsigned long unit_address, + unsigned long buffer_list, + unsigned long rec_queue, + unsigned long filter_list, + unsigned long mac_address, + unsigned long *queue_handle) +{ + unsigned long retbuf[PLPAR_HCALL_BUFSIZE]; + long rc; + + rc = plpar_hcall(H_REGISTER_LOGICAL_LAN, retbuf, + unit_address, buffer_list, rec_queue, + filter_list, mac_address); + + if (rc == H_SUCCESS) + *queue_handle = retbuf[0]; + + return rc; +} + /* FW allows us to send 6 descriptors but we only use one so mark * the other 5 as unused (0) */ @@ -184,7 +221,10 @@ struct ibmveth_adapter { struct ibmveth_buff_pool rx_buff_pool[IBMVETH_MAX_RX_QUEUES][IBMVETH_NUM_BUFF_POOLS]; struct ibmveth_rx_q rx_queue[IBMVETH_MAX_RX_QUEUES]; + /* Opaque PHYP cookie, 0 can be valid. Set only in multi_queue mode. */ + u64 queue_handle[IBMVETH_MAX_RX_QUEUES]; unsigned int queue_irq[IBMVETH_MAX_RX_QUEUES]; + bool multi_queue; unsigned int num_rx_queues; int rx_csum; int large_send; -- 2.50.1 (Apple Git-155) This is preparation for multi-queue (MQ) RX; nothing sets multi_queue yet, so single-queue behavior does not change. PHYP delivers frames only to registered RX queues. Queue 0 is registered with H_REGISTER_LOGICAL_LAN; each further (subordinate) queue is registered with H_REG_LOGICAL_LAN_QUEUE, which returns its handle and the hardware number of its interrupt. In MQ mode, open() registers queues 1..N-1 after queue 0 and maps each queue's interrupt. If that fails, open() disposes of the mappings and frees every queue with one H_FREE_LOGICAL_LAN. There is no fallback to one queue, since PowerVM blocks Live Partition Migration to a host without MQ support. PHYP fails H_FREE_LOGICAL_LAN only with H_PARAMETER, when no LAN is registered, and the RX memory is then freed. Any other failure may leave the LAN registered. MQ mode then leaks the RX memory, still mapped, so whatever PHYP still writes lands in memory nothing else uses. Single-queue mode frees it, as close() always has: CMO (Cooperative Memory Overcommitment) partitions are single-queue and must not keep memory mapped at remove. Signed-off-by: Mingming Cao --- drivers/net/ethernet/ibm/ibmveth.c | 163 +++++++++++++++++++++++++++-- drivers/net/ethernet/ibm/ibmveth.h | 32 ++++++ 2 files changed, 188 insertions(+), 7 deletions(-) diff --git a/drivers/net/ethernet/ibm/ibmveth.c b/drivers/net/ethernet/ibm/ibmveth.c index 236992ded33a..5783c0ce34a3 100644 --- a/drivers/net/ethernet/ibm/ibmveth.c +++ b/drivers/net/ethernet/ibm/ibmveth.c @@ -13,6 +13,7 @@ #include #include +#include #include #include #include @@ -21,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -449,6 +451,28 @@ ibmveth_enable_irq(struct ibmveth_adapter *adapter, int queue_index) return ibmveth_toggle_irq(adapter, queue_index, true); } +/** + * ibmveth_dispose_subordinate_irq_mappings - Drop subordinate virq mappings + * @adapter: ibmveth adapter structure + * + * Subordinate queues get mappings from irq_create_mapping() during PHYP + * registration; queue 0 uses netdev->irq and is left alone. Call after + * free_irq(), or after a registration failure that may have mapped only + * some of the queues. + */ +static void +ibmveth_dispose_subordinate_irq_mappings(struct ibmveth_adapter *adapter) +{ + int i; + + for (i = 1; i < adapter->num_rx_queues; i++) { + if (adapter->queue_irq[i]) { + irq_dispose_mapping(adapter->queue_irq[i]); + adapter->queue_irq[i] = 0; + } + } +} + /** * ibmveth_setup_rx_interrupts - Register IRQs and enable NAPI * @adapter: ibmveth adapter structure @@ -493,7 +517,7 @@ err_free_irqs: * * Mask, napi_disable, wait for the poll tail, remask, then free_irq. * napi_disable() does not wait past napi_complete_done(), which can - * unmask. + * unmask. Then dispose of the subordinate queues' IRQ mappings. */ static void ibmveth_cleanup_rx_interrupts(struct ibmveth_adapter *adapter) @@ -517,6 +541,8 @@ ibmveth_cleanup_rx_interrupts(struct ibmveth_adapter *adapter) for (i = 0; i < adapter->num_rx_queues; i++) free_irq(adapter->queue_irq[i], &adapter->napi[i]); + + ibmveth_dispose_subordinate_irq_mappings(adapter); } /** @@ -783,6 +809,10 @@ static void ibmveth_update_rx_no_buffer(struct ibmveth_adapter *adapter) { __be64 *p; + /* NULL after ibmveth_leak_rx_memory(). */ + if (!adapter->buffer_list_addr[0]) + return; + p = adapter->buffer_list_addr[0] + 4096 - 8; adapter->rx_no_buffer = be64_to_cpup(p); } @@ -1228,12 +1258,49 @@ retry: return rc; } +/** + * ibmveth_leak_rx_memory - Keep the RX memory PHYP may still own + * @adapter: ibmveth adapter structure + * + * Forgets each queue's ring, buffer list and pool buffers and the filter + * list without unmapping or freeing them, so the free paths skip them + * and their TCEs are not reused by later mappings. + */ +static void ibmveth_leak_rx_memory(struct ibmveth_adapter *adapter) +{ + struct ibmveth_buff_pool *pool; + int i, j; + + netdev_err(adapter->netdev, "leaking RX memory of %d queues\n", + adapter->num_rx_queues); + + for (i = 0; i < adapter->num_rx_queues; i++) { + adapter->rx_queue[i].queue_addr = NULL; + adapter->buffer_list_addr[i] = NULL; + adapter->buffer_list_dma[i] = 0; + for (j = 0; j < IBMVETH_NUM_BUFF_POOLS; j++) { + pool = &adapter->rx_buff_pool[i][j]; + pool->free_map = NULL; + pool->dma_addr = NULL; + pool->skbuff = NULL; + } + } + adapter->filter_list_addr = NULL; + adapter->filter_list_dma = 0; +} + /** * ibmveth_free_all_queues - Free all RX queues at once * @adapter: ibmveth adapter structure * - * Issues one H_FREE_LOGICAL_LAN. A failure is logged; the caller still - * frees the RX memory, as close() always has. + * Issues one H_FREE_LOGICAL_LAN, which frees the logical LAN and every + * RX queue registered under it. Past busy, PHYP fails it only with + * H_PARAMETER, when no LAN is registered, and the caller then frees the + * RX memory. On any other failure in multi-queue mode the RX memory is + * leaked instead. Single-queue mode frees it, as close() always has: + * CMO partitions are single-queue and must not keep it mapped at + * remove, and the unmap clears the adapter's TCEs before the pages are + * freed. */ static void ibmveth_free_all_queues(struct ibmveth_adapter *adapter) { @@ -1243,6 +1310,68 @@ static void ibmveth_free_all_queues(struct ibmveth_adapter *adapter) if (lpar_rc != H_SUCCESS) netdev_err(adapter->netdev, "h_free_logical_lan failed: %ld\n", lpar_rc); + + if (lpar_rc != H_SUCCESS && lpar_rc != H_PARAMETER && + adapter->multi_queue) + ibmveth_leak_rx_memory(adapter); +} + +/** + * ibmveth_register_rx_queue - Register one subordinate RX queue + * @adapter: ibmveth adapter structure + * @queue_idx: RX queue index (1..N-1) + * + * Registers the queue with H_REG_LOGICAL_LAN_QUEUE and maps its interrupt. + * Only called in multi-queue mode, which probe enables only on firmware + * with MQ support; PowerVM blocks Live Partition Migration to a host + * without it. On failure the caller frees every queue with + * H_FREE_LOGICAL_LAN. + * + * Return: 0 on success, -ENOMEM if the interrupt cannot be mapped, + * -EIO if H_REG_LOGICAL_LAN_QUEUE fails + */ +static int ibmveth_register_rx_queue(struct ibmveth_adapter *adapter, + int queue_idx) +{ + struct ibmveth_rx_q *rxq = &adapter->rx_queue[queue_idx]; + unsigned long bl = adapter->buffer_list_dma[queue_idx]; + unsigned long ua = adapter->vdev->unit_address; + union ibmveth_buf_desc rxq_desc; + unsigned long handle, hwirq; + unsigned int virq; + long lpar_rc; + + rxq_desc.fields.flags_len = IBMVETH_BUF_VALID | rxq->queue_len; + rxq_desc.fields.address = rxq->queue_dma; + + do { + lpar_rc = h_register_logical_lan_queue(ua, bl, rxq_desc.desc, + &handle, &hwirq); + if (H_IS_LONG_BUSY(lpar_rc)) { + msleep(get_longbusy_msecs(lpar_rc)); + lpar_rc = H_BUSY; + } else if (lpar_rc == H_BUSY) { + cond_resched(); + } + } while (lpar_rc == H_BUSY); + if (lpar_rc != H_SUCCESS) { + netdev_err(adapter->netdev, + "h_register_logical_lan_queue failed for queue %d: %ld\n", + queue_idx, lpar_rc); + return -EIO; + } + + virq = irq_create_mapping(NULL, hwirq); + if (!virq) { + netdev_err(adapter->netdev, + "failed to map IRQ for queue %d (hwirq=%lu)\n", + queue_idx, hwirq); + return -ENOMEM; + } + + adapter->queue_handle[queue_idx] = handle; + adapter->queue_irq[queue_idx] = virq; + return 0; } /** @@ -1250,9 +1379,11 @@ static void ibmveth_free_all_queues(struct ibmveth_adapter *adapter) * @adapter: ibmveth adapter structure * @mac_address: MAC address for device registration * - * Registers queue 0 with H_REGISTER_LOGICAL_LAN. + * Registers queue 0 via ibmveth_register_logical_lan(), then subordinate + * queues 1..N-1 when multi-queue mode is enabled. * - * Return: 0 on success, -ENONET if queue 0 registration fails + * Return: 0 on success, -ENONET if queue 0 registration fails, + * or the error from ibmveth_register_rx_queue() */ static int ibmveth_register_rx_queues(struct ibmveth_adapter *adapter, u64 mac_address) @@ -1260,6 +1391,8 @@ ibmveth_register_rx_queues(struct ibmveth_adapter *adapter, u64 mac_address) struct net_device *netdev = adapter->netdev; union ibmveth_buf_desc rxq_desc; long lpar_rc; + unsigned int num; + int i, rc; rxq_desc.fields.flags_len = IBMVETH_BUF_VALID | adapter->rx_queue[0].queue_len; @@ -1280,7 +1413,22 @@ ibmveth_register_rx_queues(struct ibmveth_adapter *adapter, u64 mac_address) return -ENONET; } + num = adapter->num_rx_queues; + if (num == 1 || !adapter->multi_queue) + return 0; + + for (i = 1; i < num; i++) { + rc = ibmveth_register_rx_queue(adapter, i); + if (rc) + goto err_unregister; + } + return 0; + +err_unregister: + ibmveth_dispose_subordinate_irq_mappings(adapter); + ibmveth_free_all_queues(adapter); + return rc; } static int ibmveth_open(struct net_device *netdev) @@ -1332,7 +1480,7 @@ static int ibmveth_open(struct net_device *netdev) */ rc = ibmveth_setup_rx_interrupts(adapter); if (rc) - goto out_free_all_queues; + goto out_unregister_queues; netdev_dbg(netdev, "initial replenish cycle\n"); ibmveth_schedule_rx_queue(adapter, 0); @@ -1349,7 +1497,8 @@ static int ibmveth_open(struct net_device *netdev) return 0; -out_free_all_queues: +out_unregister_queues: + ibmveth_dispose_subordinate_irq_mappings(adapter); ibmveth_free_all_queues(adapter); out_free_buffer_pools: ibmveth_free_buffer_pools(adapter); diff --git a/drivers/net/ethernet/ibm/ibmveth.h b/drivers/net/ethernet/ibm/ibmveth.h index 7ac3372afc0f..34f57ad07a2f 100644 --- a/drivers/net/ethernet/ibm/ibmveth.h +++ b/drivers/net/ethernet/ibm/ibmveth.h @@ -68,6 +68,38 @@ static inline long h_add_logical_lan_buffers(unsigned long unit_address, desc5, desc6, desc7, desc8); } +/** + * h_register_logical_lan_queue - Register a subordinate receive queue + * @unit_address: Device unit address + * @buffer_list: DMA address of 4KB page for tracking registered buffers + * @rec_queue: Buffer descriptor of receive queue + * @queue_handle: Output queue handle on success + * @irq: Output hypervisor IRQ number on success + * + * Return: hypervisor return code; H_BUSY and H_LONG_BUSY_* mean retry + */ +static inline long +h_register_logical_lan_queue(unsigned long unit_address, + unsigned long buffer_list, + unsigned long rec_queue, + unsigned long *queue_handle, + unsigned long *irq) +{ + unsigned long retbuf[PLPAR_HCALL_BUFSIZE]; + long rc; + + rc = plpar_hcall(H_REG_LOGICAL_LAN_QUEUE, + retbuf, unit_address, + buffer_list, rec_queue); + + if (rc == H_SUCCESS) { + *queue_handle = retbuf[0]; + *irq = retbuf[1]; + } + + return rc; +} + /** * h_register_logical_lan_with_handle - Register primary queue and get handle * @unit_address: Device unit address -- 2.50.1 (Apple Git-155) This is preparation for multi-queue (MQ) RX; nothing sets multi_queue yet, so single-queue behavior does not change. The RX interrupt handler masks the queue's interrupt and schedules NAPI, and the poll unmasks it when done. Both go through ibmveth_toggle_irq(), which only handles queue 0 with h_vio_signal(). A subordinate queue's interrupt is controlled with H_VIOCTL on the hardware number H_REG_LOGICAL_LAN_QUEUE returned. Keep that number in queue_hwirq[] and add the H_VIOCTL branch, so the existing handler and poll can mask and unmask any queue. Mask each subordinate queue as soon as its interrupt is mapped, so it cannot fire before its NAPI is enabled; if that fails, open() fails. Signed-off-by: Mingming Cao --- drivers/net/ethernet/ibm/ibmveth.c | 32 +++++++++++++++++++++--------- drivers/net/ethernet/ibm/ibmveth.h | 4 ++++ 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/drivers/net/ethernet/ibm/ibmveth.c b/drivers/net/ethernet/ibm/ibmveth.c index 5783c0ce34a3..1a9499438930 100644 --- a/drivers/net/ethernet/ibm/ibmveth.c +++ b/drivers/net/ethernet/ibm/ibmveth.c @@ -402,8 +402,7 @@ ibmveth_cleanup_rx_resources(struct ibmveth_adapter *adapter) * @queue_index: RX queue index * @enable: true to unmask, false to mask * - * Only queue 0 exists for now. Its interrupt is the adapter's own, which - * h_vio_signal() controls, so @queue_index is used only for logging. + * Queue 0 uses h_vio_signal(); subordinate queues use H_VIOCTL. * * Return: 0 on success, -EIO on failure */ @@ -414,8 +413,17 @@ ibmveth_toggle_irq(struct ibmveth_adapter *adapter, int queue_index, const char *action = enable ? "enable" : "disable"; unsigned long h_rc; - h_rc = h_vio_signal(adapter->vdev->unit_address, - enable ? VIO_IRQ_ENABLE : VIO_IRQ_DISABLE); + if (queue_index == 0) + h_rc = h_vio_signal(adapter->vdev->unit_address, + enable ? VIO_IRQ_ENABLE : VIO_IRQ_DISABLE); + else + h_rc = plpar_hcall_norets(H_VIOCTL, + adapter->vdev->unit_address, + enable ? H_ENABLE_VIO_INTERRUPT : + H_DISABLE_VIO_INTERRUPT, + adapter->queue_hwirq[queue_index], + 0, 0); + if (h_rc) { dev_err_ratelimited(&adapter->netdev->dev, "Failed to %s IRQ for queue %d, rc=0x%lx\n", @@ -477,9 +485,9 @@ ibmveth_dispose_subordinate_irq_mappings(struct ibmveth_adapter *adapter) * ibmveth_setup_rx_interrupts - Register IRQs and enable NAPI * @adapter: ibmveth adapter structure * - * The queues must already be masked in PHYP, as they are before the LAN - * is registered; this does not unmask them. The caller kicks NAPI, and - * the first poll unmasks. + * The queues must already be masked in PHYP: queue 0 before the LAN is + * registered, the others as they are registered. This does not unmask + * them. The caller kicks NAPI, and the first poll unmasks. * * Return: 0 on success, negative error code on failure */ @@ -1328,7 +1336,8 @@ static void ibmveth_free_all_queues(struct ibmveth_adapter *adapter) * H_FREE_LOGICAL_LAN. * * Return: 0 on success, -ENOMEM if the interrupt cannot be mapped, - * -EIO if H_REG_LOGICAL_LAN_QUEUE fails + * -EIO if H_REG_LOGICAL_LAN_QUEUE fails or the interrupt + * cannot be masked */ static int ibmveth_register_rx_queue(struct ibmveth_adapter *adapter, int queue_idx) @@ -1371,7 +1380,12 @@ static int ibmveth_register_rx_queue(struct ibmveth_adapter *adapter, adapter->queue_handle[queue_idx] = handle; adapter->queue_irq[queue_idx] = virq; - return 0; + adapter->queue_hwirq[queue_idx] = hwirq; + + /* setup_rx_interrupts() expects every queue masked: until NAPI is + * enabled, the handler does not mask it. + */ + return ibmveth_disable_irq(adapter, queue_idx); } /** diff --git a/drivers/net/ethernet/ibm/ibmveth.h b/drivers/net/ethernet/ibm/ibmveth.h index 34f57ad07a2f..398d3a862503 100644 --- a/drivers/net/ethernet/ibm/ibmveth.h +++ b/drivers/net/ethernet/ibm/ibmveth.h @@ -256,6 +256,10 @@ struct ibmveth_adapter { /* Opaque PHYP cookie, 0 can be valid. Set only in multi_queue mode. */ u64 queue_handle[IBMVETH_MAX_RX_QUEUES]; unsigned int queue_irq[IBMVETH_MAX_RX_QUEUES]; + /* PHYP interrupt number for H_VIOCTL, subordinate queues only; + * queue 0 uses h_vio_signal(), so entry 0 is never read. + */ + unsigned long queue_hwirq[IBMVETH_MAX_RX_QUEUES]; bool multi_queue; unsigned int num_rx_queues; int rx_csum; -- 2.50.1 (Apple Git-155) This is preparation for multi-queue (MQ) RX; nothing sets multi_queue yet, so single-queue behavior does not change. With MQ, every RX queue, queue 0 included, posts buffers with H_ADD_LOGICAL_LAN_BUFFERS_QUEUE against its handle. It packs two buffer addresses per argument, so one call carries up to 12 buffers instead of 8. Add ibmveth_add_logical_lan_buffers(), which picks the hcall for the adapter's mode, and pass the queue index to replenish. IBMVETH_MAX_RX_PER_HCALL becomes 12 and sizes the descriptor array; the legacy hcall keeps its limit of 8 as IBMVETH_MAX_RX_REGULAR, which probe now uses. An unexpected H_FUNCTION (hcall not supported) from the MQ hcall schedules a reset. Unlike the legacy batch hcall, it cannot disappear after Live Partition Migration, since PowerVM blocks migration to a host without MQ. If H_FUNCTION comes back after the reopen, the reset leaves the device down. As with the single queue today, a queue whose refill posts no buffer gets no further interrupt. Signed-off-by: Mingming Cao --- drivers/net/ethernet/ibm/ibmveth.c | 131 ++++++++++++++++++++++++----- drivers/net/ethernet/ibm/ibmveth.h | 41 ++++++++- 2 files changed, 151 insertions(+), 21 deletions(-) diff --git a/drivers/net/ethernet/ibm/ibmveth.c b/drivers/net/ethernet/ibm/ibmveth.c index 1a9499438930..cafbed3d1512 100644 --- a/drivers/net/ethernet/ibm/ibmveth.c +++ b/drivers/net/ethernet/ibm/ibmveth.c @@ -634,11 +634,81 @@ static inline void ibmveth_flush_buffer(void *addr, unsigned long length) asm("dcbf %0,%1,1" :: "b" (addr), "r" (offset)); } +/** + * ibmveth_add_logical_lan_buffers - Add receive buffers to hypervisor + * @adapter: ibmveth adapter structure + * @descs: array of buffer descriptors to add + * @filled: number of valid descriptors in the array + * @buff_size: size of each buffer (multi-queue mode only) + * @queue_index: RX queue index + * + * Return: hypervisor return code + */ +static long ibmveth_add_logical_lan_buffers(struct ibmveth_adapter *adapter, + union ibmveth_buf_desc *descs, + int filled, + unsigned long buff_size, + int queue_index) +{ + struct vio_dev *vdev = adapter->vdev; + long rc; + + /* + * The MQ hcall takes six ioba words (12 packed addresses). The + * legacy hcall takes eight descriptors. The argument lists below + * are written out by hand; keep the defines matched to those lists. + */ + static_assert(IBMVETH_MAX_RX_PER_HCALL == 12); + static_assert(IBMVETH_MAX_RX_REGULAR == 8); + + if (adapter->multi_queue) { + unsigned long buffersznum = (buff_size << 32) | filled; + unsigned long ioba[IBMVETH_MAX_RX_PER_HCALL / 2] = {0}; + unsigned long handle = adapter->queue_handle[queue_index]; + int i; + + /* Even descriptors go in the high 32 bits of an ioba word, + * odd ones in the low 32 bits. + */ + for (i = 0; i < filled && i < IBMVETH_MAX_RX_PER_HCALL; i++) { + int pair_idx = i / 2; + int is_high = (i % 2 == 0); + + if (is_high) + ioba[pair_idx] = (unsigned long) + descs[i].fields.address << 32; + else + ioba[pair_idx] |= descs[i].fields.address; + } + + rc = h_add_logical_lan_buffers_queue(vdev->unit_address, + handle, + buffersznum, + ioba[0], ioba[1], ioba[2], + ioba[3], ioba[4], ioba[5]); + } else if (filled == 1) { + rc = h_add_logical_lan_buffer(vdev->unit_address, + descs[0].desc); + } else { + /* Legacy 8-desc hcall; rx_buffers_per_hcall never exceeds + * IBMVETH_MAX_RX_REGULAR outside multi-queue mode. + */ + rc = h_add_logical_lan_buffers(vdev->unit_address, + descs[0].desc, descs[1].desc, + descs[2].desc, descs[3].desc, + descs[4].desc, descs[5].desc, + descs[6].desc, descs[7].desc); + } + + return rc; +} + /* replenish the buffers for a pool. note that we don't need to * skb_reserve these since they are used for incoming... */ static void ibmveth_replenish_buffer_pool(struct ibmveth_adapter *adapter, - struct ibmveth_buff_pool *pool) + struct ibmveth_buff_pool *pool, + int queue_index) { union ibmveth_buf_desc descs[IBMVETH_MAX_RX_PER_HCALL] = {0}; u32 remaining = pool->size - atomic_read(&pool->available); @@ -724,24 +794,16 @@ static void ibmveth_replenish_buffer_pool(struct ibmveth_adapter *adapter, if (!filled) break; - /* single buffer case*/ - if (filled == 1) - lpar_rc = h_add_logical_lan_buffer(vdev->unit_address, - descs[0].desc); - else - /* Multi-buffer hcall */ - lpar_rc = h_add_logical_lan_buffers(vdev->unit_address, - descs[0].desc, - descs[1].desc, - descs[2].desc, - descs[3].desc, - descs[4].desc, - descs[5].desc, - descs[6].desc, - descs[7].desc); + lpar_rc = ibmveth_add_logical_lan_buffers(adapter, descs, + filled, + pool->buff_size, + queue_index); if (lpar_rc != H_SUCCESS) { dev_warn_ratelimited(dev, - "RX h_add_logical_lan failed: filled=%u, rc=%lu, batch=%u\n", + "RX %s failed: filled=%u, rc=%lu, batch=%u\n", + adapter->multi_queue ? + "h_add_logical_lan_buffers_queue" : + "h_add_logical_lan", filled, lpar_rc, batch); goto hcall_failure; } @@ -782,6 +844,21 @@ hcall_failure: } adapter->replenish_add_buff_failure += filled; + /* PowerVM blocks LPM to a host without MQ support once probe + * has enabled multi-queue mode, so unlike the legacy batch + * hcall below, this hcall cannot disappear across migration. + * Reset on an unexpected H_FUNCTION rather than sit without + * buffers, link up. + */ + if (lpar_rc == H_FUNCTION && adapter->multi_queue) { + dev_err_ratelimited(dev, + "MQ buffer add H_FUNCTION (q=%d, batch=%u), reset\n", + queue_index, batch); + WRITE_ONCE(adapter->mq_hfunc, true); + schedule_work(&adapter->work); + break; + } + /* * If multi rx buffers hcall is no longer supported by FW * e.g. in the case of Live Partition Migration @@ -839,7 +916,8 @@ static void ibmveth_replenish_task(struct ibmveth_adapter *adapter, if (pool->active && (atomic_read(&pool->available) < pool->threshold)) - ibmveth_replenish_buffer_pool(adapter, pool); + ibmveth_replenish_buffer_pool(adapter, pool, + queue_index); } ibmveth_update_rx_no_buffer(adapter); @@ -1543,6 +1621,8 @@ static int ibmveth_close(struct net_device *netdev) netif_tx_disable(netdev); ibmveth_cleanup_rx_interrupts(adapter); + WRITE_ONCE(adapter->mq_hfunc, false); + adapter->mq_hfunc_reopened = false; ibmveth_free_all_queues(adapter); ibmveth_update_rx_no_buffer(adapter); @@ -1578,8 +1658,19 @@ static void ibmveth_reset(struct work_struct *w) rtnl_lock(); if (netif_running(netdev)) { + bool hfunc = READ_ONCE(adapter->mq_hfunc); + bool give_up = hfunc && adapter->mq_hfunc_reopened; + dev_close(netdev); - dev_open(netdev, NULL); + /* Firmware that returns MQ H_FUNCTION again after a reopen + * would do so on every reopen; leave the device down rather + * than close and reopen forever. + */ + if (give_up) + netdev_err(netdev, + "MQ buffer add H_FUNCTION again after reset, leaving device down\n"); + else if (!dev_open(netdev, NULL)) + adapter->mq_hfunc_reopened = hfunc; } rtnl_unlock(); @@ -2846,7 +2937,7 @@ static int ibmveth_probe(struct vio_dev *dev, const struct vio_device_id *id) if (ret == H_SUCCESS && (ret_attr & IBMVETH_ILLAN_RX_MULTI_BUFF_SUPPORT)) { - adapter->rx_buffers_per_hcall = IBMVETH_MAX_RX_PER_HCALL; + adapter->rx_buffers_per_hcall = IBMVETH_MAX_RX_REGULAR; netdev_dbg(netdev, "RX Multi-buffer hcall supported by FW, batch set to %u\n", adapter->rx_buffers_per_hcall); diff --git a/drivers/net/ethernet/ibm/ibmveth.h b/drivers/net/ethernet/ibm/ibmveth.h index 398d3a862503..dd89f108e726 100644 --- a/drivers/net/ethernet/ibm/ibmveth.h +++ b/drivers/net/ethernet/ibm/ibmveth.h @@ -100,6 +100,40 @@ h_register_logical_lan_queue(unsigned long unit_address, return rc; } +/** + * h_add_logical_lan_buffers_queue - Add buffers to an RX queue by handle + * @unit_address: Device unit address + * @queue_handle: Queue handle from h_register_logical_lan_queue() or + * h_register_logical_lan_with_handle() (queue 0) + * @buffersznum: Buffer size (upper 32 bits) | count (lower 32 bits) + * @ioba12: Buffer addresses 1 and 2 packed ((addr1 << 32) | addr2) + * @ioba34: Buffer addresses 3 and 4 packed + * @ioba56: Buffer addresses 5 and 6 packed + * @ioba78: Buffer addresses 7 and 8 packed + * @ioba910: Buffer addresses 9 and 10 packed + * @ioba1112: Buffer addresses 11 and 12 packed + * + * Return: hypervisor return code + */ +static inline long h_add_logical_lan_buffers_queue(unsigned long unit_address, + unsigned long queue_handle, + unsigned long buffersznum, + unsigned long ioba12, + unsigned long ioba34, + unsigned long ioba56, + unsigned long ioba78, + unsigned long ioba910, + unsigned long ioba1112) +{ + unsigned long retbuf[PLPAR_HCALL9_BUFSIZE]; + + return plpar_hcall9(H_ADD_LOGICAL_LAN_BUFFERS_QUEUE, + retbuf, unit_address, + queue_handle, buffersznum, + ioba12, ioba34, ioba56, + ioba78, ioba910, ioba1112); +} + /** * h_register_logical_lan_with_handle - Register primary queue and get handle * @unit_address: Device unit address @@ -194,7 +228,8 @@ static inline long h_illan_attributes(unsigned long unit_address, #define IBMVETH_DEFAULT_QUEUES 8U #define IBMVETH_MAX_RX_QUEUES 1U #define IBMVETH_DEFAULT_RX_QUEUES 1U -#define IBMVETH_MAX_RX_PER_HCALL 8U +#define IBMVETH_MAX_RX_REGULAR 8U +#define IBMVETH_MAX_RX_PER_HCALL 12U static int pool_size[] = { 512, 1024 * 2, 1024 * 16, 1024 * 32, 1024 * 64 }; static int pool_count[] = { 256, 512, 256, 256, 256 }; @@ -267,6 +302,10 @@ struct ibmveth_adapter { bool is_active_trunk; /* Set by a successful ibmveth_open(), cleared by ibmveth_close(). */ bool opened; + /* MQ buffer add returned H_FUNCTION; cleared by ibmveth_close(). */ + bool mq_hfunc; + /* ibmveth_reset() reopened after mq_hfunc; cleared by ibmveth_close(). */ + bool mq_hfunc_reopened; unsigned int rx_buffers_per_hcall; u64 fw_ipv6_csum_support; -- 2.50.1 (Apple Git-155) This is preparation for multi-queue (MQ) RX; nothing sets multi_queue yet, so single-queue behavior does not change. An RX queue starts with no buffers and its interrupt masked, and PHYP interrupts a queue only after placing a frame in one of its buffers. The first NAPI poll posts the buffers and unmasks the interrupt, but open() and resume schedule NAPI only on queue 0, so the other queues would never receive. Schedule NAPI on every RX queue in open() and resume. Refill still runs only from a queue's own NAPI poll, so no two contexts touch one queue's buffers and no lock is needed. Signed-off-by: Mingming Cao --- drivers/net/ethernet/ibm/ibmveth.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/drivers/net/ethernet/ibm/ibmveth.c b/drivers/net/ethernet/ibm/ibmveth.c index cafbed3d1512..fbaa964c6963 100644 --- a/drivers/net/ethernet/ibm/ibmveth.c +++ b/drivers/net/ethernet/ibm/ibmveth.c @@ -1574,8 +1574,9 @@ static int ibmveth_open(struct net_device *netdev) if (rc) goto out_unregister_queues; - netdev_dbg(netdev, "initial replenish cycle\n"); - ibmveth_schedule_rx_queue(adapter, 0); + /* Each queue's first poll posts its buffers and unmasks it. */ + for (i = 0; i < adapter->num_rx_queues; i++) + ibmveth_schedule_rx_queue(adapter, i); /* netif_tx_lock() takes each txq lock, so a sender that then sees * DRV_XOFF clear under its txq lock also sees the LTBs set up above. @@ -3204,8 +3205,12 @@ static int ibmveth_resume(struct device *dev) { struct net_device *netdev = dev_get_drvdata(dev); struct ibmveth_adapter *adapter = netdev_priv(netdev); + unsigned int num = adapter->num_rx_queues; + int i; + + for (i = 0; i < num; i++) + ibmveth_schedule_rx_queue(adapter, i); - ibmveth_schedule_rx_queue(adapter, 0); return 0; } -- 2.50.1 (Apple Git-155) This is preparation for multi-queue (MQ) RX; nothing sets multi_queue yet. Single-queue behavior is unchanged apart from the drop_monitor note below. The RX counters live in the adapter and in netdev->stats. With MQ, each RX queue's NAPI poll can run on another CPU at the same time, and unlocked increments of shared counters would lose counts. Move them into per-queue counters, as an earlier patch did for TX, each written only by its queue's NAPI poll or with that NAPI disabled. ndo_get_stats64 and ethtool -S sum them, and ethtool -S keeps its keys. Nothing writes netdev->stats any more. drop_monitor's summary mode reads dev->stats.rx_dropped directly, so it no longer reports ibmveth RX drops; ip -s link still counts them. Signed-off-by: Mingming Cao --- drivers/net/ethernet/ibm/ibmveth.c | 144 +++++++++++++++++++++-------- drivers/net/ethernet/ibm/ibmveth.h | 29 ++++-- 2 files changed, 126 insertions(+), 47 deletions(-) diff --git a/drivers/net/ethernet/ibm/ibmveth.c b/drivers/net/ethernet/ibm/ibmveth.c index fbaa964c6963..e36c25609c62 100644 --- a/drivers/net/ethernet/ibm/ibmveth.c +++ b/drivers/net/ethernet/ibm/ibmveth.c @@ -77,12 +77,14 @@ MODULE_PARM_DESC(old_large_send, /** * enum ibmveth_stat_src - where an ethtool -S counter is stored * @IBMVETH_STAT_ADAPTER: plain u64 in struct ibmveth_adapter + * @IBMVETH_STAT_RX_QSUM: per-queue u64, summed over rx_qstats[] * @IBMVETH_STAT_TX_QSUM: per-queue u64, summed over tx_qstats[] * * Counters live per queue so that queues never share a field. */ enum ibmveth_stat_src { IBMVETH_STAT_ADAPTER, + IBMVETH_STAT_RX_QSUM, IBMVETH_STAT_TX_QSUM, }; @@ -94,6 +96,7 @@ struct ibmveth_stat { }; #define IBMVETH_STAT_OFF(stat) offsetof(struct ibmveth_adapter, stat) +#define IBMVETH_RXQ_OFF(stat) offsetof(struct ibmveth_rx_queue_stats, stat) #define IBMVETH_TXQ_OFF(stat) offsetof(struct ibmveth_tx_queue_stats, stat) /* Single writer per counter; lockless readers use READ_ONCE(). */ @@ -103,25 +106,27 @@ struct ibmveth_stat { #define IBMVETH_ADAPTER_STAT(key, field) \ { key, IBMVETH_STAT_ADAPTER, IBMVETH_STAT_OFF(field) } +#define IBMVETH_RXQ_STAT(key, field) \ + { key, IBMVETH_STAT_RX_QSUM, IBMVETH_RXQ_OFF(field) } #define IBMVETH_TXQ_STAT(key, field) \ { key, IBMVETH_STAT_TX_QSUM, IBMVETH_TXQ_OFF(field) } /* Key names and order are user-visible: append only. */ static struct ibmveth_stat ibmveth_stats[] = { - IBMVETH_ADAPTER_STAT("replenish_task_cycles", replenish_task_cycles), - IBMVETH_ADAPTER_STAT("replenish_no_mem", replenish_no_mem), - IBMVETH_ADAPTER_STAT("replenish_add_buff_failure", - replenish_add_buff_failure), - IBMVETH_ADAPTER_STAT("replenish_add_buff_success", - replenish_add_buff_success), - IBMVETH_ADAPTER_STAT("rx_invalid_buffer", rx_invalid_buffer), - IBMVETH_ADAPTER_STAT("rx_no_buffer", rx_no_buffer), + IBMVETH_RXQ_STAT("replenish_task_cycles", replenish_task_cycles), + IBMVETH_RXQ_STAT("replenish_no_mem", replenish_no_mem), + IBMVETH_RXQ_STAT("replenish_add_buff_failure", + replenish_add_buff_failure), + IBMVETH_RXQ_STAT("replenish_add_buff_success", + replenish_add_buff_success), + IBMVETH_RXQ_STAT("rx_invalid_buffer", invalid_buffers), + IBMVETH_RXQ_STAT("rx_no_buffer", no_buffer_drops), IBMVETH_ADAPTER_STAT("tx_map_failed", tx_map_failed), IBMVETH_TXQ_STAT("tx_send_failed", send_failures), IBMVETH_ADAPTER_STAT("fw_enabled_ipv4_csum", fw_ipv4_csum_support), IBMVETH_ADAPTER_STAT("fw_enabled_ipv6_csum", fw_ipv6_csum_support), IBMVETH_TXQ_STAT("tx_large_packets", large_packets), - IBMVETH_ADAPTER_STAT("rx_large_packets", rx_large_packets), + IBMVETH_RXQ_STAT("rx_large_packets", large_packets), IBMVETH_ADAPTER_STAT("fw_enabled_large_send", fw_large_send_support), }; @@ -252,6 +257,33 @@ ibmveth_free_filter_list(struct ibmveth_adapter *adapter) } } +/** + * ibmveth_alloc_rx_qstats - Allocate per-queue RX statistics + * @adapter: ibmveth adapter structure + * + * Return: 0 on success, -ENOMEM on failure + */ +static int ibmveth_alloc_rx_qstats(struct ibmveth_adapter *adapter) +{ + adapter->rx_qstats = kcalloc(IBMVETH_MAX_RX_QUEUES, + sizeof(*adapter->rx_qstats), + GFP_KERNEL); + if (!adapter->rx_qstats) + return -ENOMEM; + + return 0; +} + +/** + * ibmveth_free_rx_qstats - Free per-queue RX statistics + * @adapter: ibmveth adapter structure + */ +static void ibmveth_free_rx_qstats(struct ibmveth_adapter *adapter) +{ + kfree(adapter->rx_qstats); + adapter->rx_qstats = NULL; +} + /** * ibmveth_alloc_tx_qstats - Allocate per-queue TX statistics * @adapter: ibmveth adapter structure @@ -703,6 +735,14 @@ static long ibmveth_add_logical_lan_buffers(struct ibmveth_adapter *adapter, return rc; } +static void ibmveth_count_add_fail(struct ibmveth_rx_queue_stats *qstats, + bool no_mem) +{ + if (no_mem) + IBMVETH_STAT_INC(qstats->replenish_no_mem); + IBMVETH_STAT_INC(qstats->replenish_add_buff_failure); +} + /* replenish the buffers for a pool. note that we don't need to * skb_reserve these since they are used for incoming... */ @@ -710,6 +750,8 @@ static void ibmveth_replenish_buffer_pool(struct ibmveth_adapter *adapter, struct ibmveth_buff_pool *pool, int queue_index) { + struct ibmveth_rx_queue_stats *qstats = + &adapter->rx_qstats[queue_index]; union ibmveth_buf_desc descs[IBMVETH_MAX_RX_PER_HCALL] = {0}; u32 remaining = pool->size - atomic_read(&pool->available); u64 correlators[IBMVETH_MAX_RX_PER_HCALL] = {0}; @@ -735,7 +777,7 @@ static void ibmveth_replenish_buffer_pool(struct ibmveth_adapter *adapter, for (filled = 0; filled < min(remaining, batch); filled++) { index = pool->free_map[free_index]; if (WARN_ON(index == IBM_VETH_INVALID_MAP)) { - adapter->replenish_add_buff_failure++; + ibmveth_count_add_fail(qstats, false); netdev_info(adapter->netdev, "Invalid map index %u, reset\n", index); @@ -749,8 +791,7 @@ static void ibmveth_replenish_buffer_pool(struct ibmveth_adapter *adapter, skb = netdev_alloc_skb(adapter->netdev, pool->buff_size); if (!skb) { - adapter->replenish_no_mem++; - adapter->replenish_add_buff_failure++; + ibmveth_count_add_fail(qstats, true); break; } @@ -759,7 +800,7 @@ static void ibmveth_replenish_buffer_pool(struct ibmveth_adapter *adapter, DMA_FROM_DEVICE); if (dma_mapping_error(dev, dma_addr)) { dev_kfree_skb_any(skb); - adapter->replenish_add_buff_failure++; + ibmveth_count_add_fail(qstats, false); break; } @@ -819,7 +860,7 @@ static void ibmveth_replenish_buffer_pool(struct ibmveth_adapter *adapter, } buffers_added += filled; - adapter->replenish_add_buff_success += filled; + IBMVETH_STAT_ADD(qstats->replenish_add_buff_success, filled); remaining -= filled; memset(&descs, 0, sizeof(descs)); @@ -842,7 +883,7 @@ hcall_failure: pool->skbuff[index] = NULL; } } - adapter->replenish_add_buff_failure += filled; + IBMVETH_STAT_ADD(qstats->replenish_add_buff_failure, filled); /* PowerVM blocks LPM to a host without MQ support once probe * has enabled multi-queue mode, so unlike the legacy batch @@ -890,16 +931,18 @@ hcall_failure: * because there was not a buffer in the buffer list capable of holding * the frame. */ -static void ibmveth_update_rx_no_buffer(struct ibmveth_adapter *adapter) +static void ibmveth_update_rx_no_buffer(struct ibmveth_adapter *adapter, + int queue_index) { __be64 *p; /* NULL after ibmveth_leak_rx_memory(). */ - if (!adapter->buffer_list_addr[0]) + if (!adapter->buffer_list_addr[queue_index]) return; - p = adapter->buffer_list_addr[0] + 4096 - 8; - adapter->rx_no_buffer = be64_to_cpup(p); + p = adapter->buffer_list_addr[queue_index] + 4096 - 8; + WRITE_ONCE(adapter->rx_qstats[queue_index].no_buffer_drops, + be64_to_cpu(READ_ONCE(*p))); } /* replenish routine */ @@ -908,7 +951,7 @@ static void ibmveth_replenish_task(struct ibmveth_adapter *adapter, { int i; - adapter->replenish_task_cycles++; + IBMVETH_STAT_INC(adapter->rx_qstats[queue_index].replenish_task_cycles); for (i = (IBMVETH_NUM_BUFF_POOLS - 1); i >= 0; i--) { struct ibmveth_buff_pool *pool = @@ -920,7 +963,7 @@ static void ibmveth_replenish_task(struct ibmveth_adapter *adapter, queue_index); } - ibmveth_update_rx_no_buffer(adapter); + ibmveth_update_rx_no_buffer(adapter, queue_index); } /* empty and free ana buffer pool - also used to do cleanup in error paths */ @@ -1608,6 +1651,7 @@ out: static int ibmveth_close(struct net_device *netdev) { struct ibmveth_adapter *adapter = netdev_priv(netdev); + int i; /* change_mtu, pool sysfs, set_csum and set_tso call close() and * open() directly. If that open() fails, IFF_UP stays set and @@ -1626,7 +1670,8 @@ static int ibmveth_close(struct net_device *netdev) adapter->mq_hfunc_reopened = false; ibmveth_free_all_queues(adapter); - ibmveth_update_rx_no_buffer(adapter); + for (i = 0; i < adapter->num_rx_queues; i++) + ibmveth_update_rx_no_buffer(adapter, i); ibmveth_free_buffer_pools(adapter); ibmveth_cleanup_rx_resources(adapter); ibmveth_free_filter_list(adapter); @@ -1904,9 +1949,23 @@ static int ibmveth_set_features(struct net_device *dev, } /* - * Sum every slot, not just the live queues, so shrinking the queue - * count cannot make a counter go backwards. + * The RX and TX sums below add every slot, not just the live queues, + * so shrinking either queue count cannot make a counter go backwards. */ +static u64 ibmveth_sum_rx_qstat(struct ibmveth_adapter *adapter, size_t off) +{ + u64 total = 0; + int i; + + for (i = 0; i < IBMVETH_MAX_RX_QUEUES; i++) { + const u8 *q = (const u8 *)&adapter->rx_qstats[i]; + + total += READ_ONCE(*(const u64 *)(q + off)); + } + + return total; +} + static u64 ibmveth_sum_tx_qstat(struct ibmveth_adapter *adapter, size_t off) { u64 total = 0; @@ -1927,6 +1986,8 @@ static u64 ibmveth_ethtool_adapter_stat(struct ibmveth_adapter *adapter, const struct ibmveth_stat *stat = &ibmveth_stats[index]; switch (stat->src) { + case IBMVETH_STAT_RX_QSUM: + return ibmveth_sum_rx_qstat(adapter, stat->off); case IBMVETH_STAT_TX_QSUM: return ibmveth_sum_tx_qstat(adapter, stat->off); case IBMVETH_STAT_ADAPTER: @@ -2380,12 +2441,12 @@ static bool ibmveth_poll_recycle_invalid(struct net_device *netdev, { int rc; - adapter->rx_invalid_buffer++; + IBMVETH_STAT_INC(adapter->rx_qstats[queue_index].invalid_buffers); netdev_dbg(netdev, "recycling invalid buffer\n"); rc = ibmveth_rxq_harvest_buffer(adapter, queue_index, correlator, true); if (unlikely(rc)) - netdev->stats.rx_dropped++; + IBMVETH_STAT_INC(adapter->rx_qstats[queue_index].dropped); return rc; } @@ -2400,7 +2461,7 @@ static void ibmveth_poll_drop_bad_frame(struct net_device *netdev, "bad RX frame offset %u length %u (buffer %u) on queue %d, dropping\n", off, len, room, queue_index); ibmveth_rxq_harvest_buffer(adapter, queue_index, correlator, true); - netdev->stats.rx_dropped++; + IBMVETH_STAT_INC(adapter->rx_qstats[queue_index].dropped); } /** @@ -2416,6 +2477,7 @@ static void ibmveth_poll_deliver_frame(struct napi_struct *napi, struct net_device *netdev, int queue_index, u64 correlator) { + struct ibmveth_rx_queue_stats *rxs = &adapter->rx_qstats[queue_index]; int length = ibmveth_rxq_frame_length(adapter, queue_index); int offset = ibmveth_rxq_frame_offset(adapter, queue_index); int csum_good = ibmveth_rxq_csum_good(adapter, queue_index); @@ -2430,7 +2492,7 @@ static void ibmveth_poll_deliver_frame(struct napi_struct *napi, skb = ibmveth_rxq_get_buffer(adapter, queue_index, correlator); if (unlikely(!skb)) { ibmveth_rxq_advance(adapter, queue_index); - netdev->stats.rx_dropped++; + IBMVETH_STAT_INC(rxs->dropped); return; } @@ -2468,7 +2530,7 @@ static void ibmveth_poll_deliver_frame(struct napi_struct *napi, correlator, true); if (unlikely(rc)) { dev_kfree_skb_any(new_skb); - netdev->stats.rx_dropped++; + IBMVETH_STAT_INC(rxs->dropped); return; } skb = new_skb; @@ -2476,7 +2538,7 @@ static void ibmveth_poll_deliver_frame(struct napi_struct *napi, rc = ibmveth_rxq_harvest_buffer(adapter, queue_index, correlator, false); if (unlikely(rc)) { - netdev->stats.rx_dropped++; + IBMVETH_STAT_INC(rxs->dropped); return; } skb_reserve(skb, offset); @@ -2499,7 +2561,7 @@ static void ibmveth_poll_deliver_frame(struct napi_struct *napi, lrg_pkt || iph_check == 0xffff) { if (!ibmveth_rx_mss_helper(skb, mss, lrg_pkt)) csum_good = 0; - adapter->rx_large_packets++; + IBMVETH_STAT_INC(rxs->large_packets); } if (csum_good) { @@ -2509,8 +2571,8 @@ static void ibmveth_poll_deliver_frame(struct napi_struct *napi, napi_gro_receive(napi, skb); /* send it up */ - netdev->stats.rx_packets++; - netdev->stats.rx_bytes += length; + IBMVETH_STAT_INC(rxs->packets); + IBMVETH_STAT_ADD(rxs->bytes, length); } static int ibmveth_poll(struct napi_struct *napi, int budget) @@ -2780,8 +2842,7 @@ static netdev_features_t ibmveth_features_check(struct sk_buff *skb, * @dev: network device * @stats: rtnl link statistics storage * - * Sums per-queue tx_qstats into the rtnl counters; RX still comes from - * dev->stats. + * Sums per-queue rx_qstats and tx_qstats into the rtnl counters. * Walk the full allocated arrays (not the live queue count) so shrinking * channels cannot make the totals go backwards. */ @@ -2791,9 +2852,11 @@ static void ibmveth_get_stats64(struct net_device *dev, struct ibmveth_adapter *adapter = netdev_priv(dev); int i; - stats->rx_packets = READ_ONCE(dev->stats.rx_packets); - stats->rx_bytes = READ_ONCE(dev->stats.rx_bytes); - stats->rx_dropped = READ_ONCE(dev->stats.rx_dropped); + for (i = 0; i < IBMVETH_MAX_RX_QUEUES; i++) { + stats->rx_packets += READ_ONCE(adapter->rx_qstats[i].packets); + stats->rx_bytes += READ_ONCE(adapter->rx_qstats[i].bytes); + stats->rx_dropped += READ_ONCE(adapter->rx_qstats[i].dropped); + } for (i = 0; i < IBMVETH_MAX_QUEUES; i++) { stats->tx_packets += READ_ONCE(adapter->tx_qstats[i].packets); @@ -2971,7 +3034,8 @@ static int ibmveth_probe(struct vio_dev *dev, const struct vio_device_id *id) kobject_uevent(kobj, KOBJ_ADD); } - if (ibmveth_alloc_tx_qstats(adapter)) { + if (ibmveth_alloc_rx_qstats(adapter) || + ibmveth_alloc_tx_qstats(adapter)) { rc = -ENOMEM; goto err_put_pools; } @@ -3006,6 +3070,7 @@ static int ibmveth_probe(struct vio_dev *dev, const struct vio_device_id *id) err_put_pools: ibmveth_put_pool_kobjs(adapter); ibmveth_free_tx_qstats(adapter); + ibmveth_free_rx_qstats(adapter); free_netdev(netdev); return rc; } @@ -3022,6 +3087,7 @@ static void ibmveth_remove(struct vio_dev *dev) unregister_netdev(netdev); ibmveth_free_tx_qstats(adapter); + ibmveth_free_rx_qstats(adapter); free_netdev(netdev); dev_set_drvdata(&dev->dev, NULL); diff --git a/drivers/net/ethernet/ibm/ibmveth.h b/drivers/net/ethernet/ibm/ibmveth.h index dd89f108e726..d45f173edda2 100644 --- a/drivers/net/ethernet/ibm/ibmveth.h +++ b/drivers/net/ethernet/ibm/ibmveth.h @@ -238,6 +238,26 @@ static int pool_active[] = { 1, 1, 0, 0, 1}; #define IBM_VETH_INVALID_MAP ((u16)0xffff) +/* + * Per-queue RX counters, written only from this queue's NAPI poll or + * with its NAPI disabled. Readers take no lock; 64-bit accesses do not + * tear on PPC64, so writers use IBMVETH_STAT_INC()/IBMVETH_STAT_ADD() + * and readers READ_ONCE(). + */ +struct ibmveth_rx_queue_stats { + u64 packets; + u64 bytes; + u64 large_packets; + u64 invalid_buffers; + u64 dropped; + /* PHYP's drop count from the buffer-list page. */ + u64 no_buffer_drops; + u64 replenish_task_cycles; + u64 replenish_no_mem; + u64 replenish_add_buff_failure; + u64 replenish_add_buff_success; +} ____cacheline_aligned_in_smp; + /* Per-queue TX counters; serialized by the stack's per-queue TX lock. */ struct ibmveth_tx_queue_stats { u64 packets; @@ -311,16 +331,9 @@ struct ibmveth_adapter { u64 fw_ipv6_csum_support; u64 fw_ipv4_csum_support; u64 fw_large_send_support; - /* adapter specific stats */ - u64 replenish_task_cycles; - u64 replenish_no_mem; - u64 replenish_add_buff_failure; - u64 replenish_add_buff_success; - u64 rx_invalid_buffer; - u64 rx_no_buffer; u64 tx_map_failed; - u64 rx_large_packets; + struct ibmveth_rx_queue_stats *rx_qstats; struct ibmveth_tx_queue_stats *tx_qstats; /* Ethtool settings */ -- 2.50.1 (Apple Git-155) rx_no_buffer counts frames PHYP dropped because the queue had no buffer posted. PHYP keeps the count in each queue's buffer-list page, which H_FREE_LOGICAL_LAN zeroes, and close() reads it after the free, so it goes back to 0 on every close/open. The next patch reports it as per-queue hw_drops, which must not go backwards. Read each queue's count just before H_FREE_LOGICAL_LAN and add it to a per-queue running total. Replenish and close store the running total plus the live count as one precomputed sum, and readers use only that sum, so a count moving into the total is never seen twice. Between those updates the sum does not move, including while a queue out of buffers gets no polls. Report the sum as rx_missed_errors, which if_link.h defines as drops for lack of buffer space, so ip -s link now shows these drops as missed; ethtool -S keeps calling it rx_no_buffer. Both changes apply to single-queue adapters too. Signed-off-by: Mingming Cao --- drivers/net/ethernet/ibm/ibmveth.c | 74 +++++++++++++++++++++++++++--- drivers/net/ethernet/ibm/ibmveth.h | 6 ++- 2 files changed, 73 insertions(+), 7 deletions(-) diff --git a/drivers/net/ethernet/ibm/ibmveth.c b/drivers/net/ethernet/ibm/ibmveth.c index e36c25609c62..56b645ffb18c 100644 --- a/drivers/net/ethernet/ibm/ibmveth.c +++ b/drivers/net/ethernet/ibm/ibmveth.c @@ -79,6 +79,8 @@ MODULE_PARM_DESC(old_large_send, * @IBMVETH_STAT_ADAPTER: plain u64 in struct ibmveth_adapter * @IBMVETH_STAT_RX_QSUM: per-queue u64, summed over rx_qstats[] * @IBMVETH_STAT_TX_QSUM: per-queue u64, summed over tx_qstats[] + * @IBMVETH_STAT_RX_NO_BUFFER: running total plus the value from the + * queue's last replenish pass (see ibmveth_sum_rx_no_buffer()) * * Counters live per queue so that queues never share a field. */ @@ -86,6 +88,7 @@ enum ibmveth_stat_src { IBMVETH_STAT_ADAPTER, IBMVETH_STAT_RX_QSUM, IBMVETH_STAT_TX_QSUM, + IBMVETH_STAT_RX_NO_BUFFER, }; struct ibmveth_stat { @@ -120,7 +123,8 @@ static struct ibmveth_stat ibmveth_stats[] = { IBMVETH_RXQ_STAT("replenish_add_buff_success", replenish_add_buff_success), IBMVETH_RXQ_STAT("rx_invalid_buffer", invalid_buffers), - IBMVETH_RXQ_STAT("rx_no_buffer", no_buffer_drops), + /* off unused; summed in ibmveth_ethtool_adapter_stat() */ + { "rx_no_buffer", IBMVETH_STAT_RX_NO_BUFFER, 0 }, IBMVETH_ADAPTER_STAT("tx_map_failed", tx_map_failed), IBMVETH_TXQ_STAT("tx_send_failed", send_failures), IBMVETH_ADAPTER_STAT("fw_enabled_ipv4_csum", fw_ipv4_csum_support), @@ -934,15 +938,49 @@ hcall_failure: static void ibmveth_update_rx_no_buffer(struct ibmveth_adapter *adapter, int queue_index) { + struct ibmveth_rx_queue_stats *qstats; __be64 *p; + u64 drops; /* NULL after ibmveth_leak_rx_memory(). */ if (!adapter->buffer_list_addr[queue_index]) return; p = adapter->buffer_list_addr[queue_index] + 4096 - 8; - WRITE_ONCE(adapter->rx_qstats[queue_index].no_buffer_drops, - be64_to_cpu(READ_ONCE(*p))); + drops = be64_to_cpu(READ_ONCE(*p)); + + qstats = &adapter->rx_qstats[queue_index]; + + /* PHYP's count only grows while the queue is registered, and the + * free path retires it; if it ever reads lower, keep what was seen. + */ + if (drops < qstats->no_buffer_drops) + IBMVETH_STAT_ADD(qstats->no_buffer_retired, + qstats->no_buffer_drops); + WRITE_ONCE(qstats->no_buffer_drops, drops); + WRITE_ONCE(qstats->no_buffer_total, + qstats->no_buffer_retired + drops); +} + +static u64 ibmveth_rx_no_buffer_total(struct ibmveth_adapter *adapter, + int queue_index) +{ + return READ_ONCE(adapter->rx_qstats[queue_index].no_buffer_total); +} + +/* + * Fold the last sample into retired once the queue is freed: the next + * registration restarts PHYP's counter at 0. The fold leaves + * no_buffer_total unchanged. + */ +static void ibmveth_retire_rx_no_buffer(struct ibmveth_adapter *adapter, + int queue_index) +{ + struct ibmveth_rx_queue_stats *qstats; + + qstats = &adapter->rx_qstats[queue_index]; + IBMVETH_STAT_ADD(qstats->no_buffer_retired, qstats->no_buffer_drops); + WRITE_ONCE(qstats->no_buffer_drops, 0); } /* replenish routine */ @@ -1430,16 +1468,26 @@ static void ibmveth_leak_rx_memory(struct ibmveth_adapter *adapter) * CMO partitions are single-queue and must not keep it mapped at * remove, and the unmap clears the adapter's TCEs before the pages are * freed. + * + * PHYP zeroes the buffer-list pages on free, so each queue's no-buffer + * counter is sampled before H_FREE_LOGICAL_LAN and retired after it. */ static void ibmveth_free_all_queues(struct ibmveth_adapter *adapter) { long lpar_rc; + int i; + + for (i = 0; i < adapter->num_rx_queues; i++) + ibmveth_update_rx_no_buffer(adapter, i); lpar_rc = ibmveth_free_logical_lan(adapter); if (lpar_rc != H_SUCCESS) netdev_err(adapter->netdev, "h_free_logical_lan failed: %ld\n", lpar_rc); + for (i = 0; i < adapter->num_rx_queues; i++) + ibmveth_retire_rx_no_buffer(adapter, i); + if (lpar_rc != H_SUCCESS && lpar_rc != H_PARAMETER && adapter->multi_queue) ibmveth_leak_rx_memory(adapter); @@ -1651,7 +1699,6 @@ out: static int ibmveth_close(struct net_device *netdev) { struct ibmveth_adapter *adapter = netdev_priv(netdev); - int i; /* change_mtu, pool sysfs, set_csum and set_tso call close() and * open() directly. If that open() fails, IFF_UP stays set and @@ -1670,8 +1717,6 @@ static int ibmveth_close(struct net_device *netdev) adapter->mq_hfunc_reopened = false; ibmveth_free_all_queues(adapter); - for (i = 0; i < adapter->num_rx_queues; i++) - ibmveth_update_rx_no_buffer(adapter, i); ibmveth_free_buffer_pools(adapter); ibmveth_cleanup_rx_resources(adapter); ibmveth_free_filter_list(adapter); @@ -1966,6 +2011,17 @@ static u64 ibmveth_sum_rx_qstat(struct ibmveth_adapter *adapter, size_t off) return total; } +static u64 ibmveth_sum_rx_no_buffer(struct ibmveth_adapter *adapter) +{ + u64 total = 0; + int i; + + for (i = 0; i < IBMVETH_MAX_RX_QUEUES; i++) + total += ibmveth_rx_no_buffer_total(adapter, i); + + return total; +} + static u64 ibmveth_sum_tx_qstat(struct ibmveth_adapter *adapter, size_t off) { u64 total = 0; @@ -1990,6 +2046,8 @@ static u64 ibmveth_ethtool_adapter_stat(struct ibmveth_adapter *adapter, return ibmveth_sum_rx_qstat(adapter, stat->off); case IBMVETH_STAT_TX_QSUM: return ibmveth_sum_tx_qstat(adapter, stat->off); + case IBMVETH_STAT_RX_NO_BUFFER: + return ibmveth_sum_rx_no_buffer(adapter); case IBMVETH_STAT_ADAPTER: break; } @@ -2843,6 +2901,9 @@ static netdev_features_t ibmveth_features_check(struct sk_buff *skb, * @stats: rtnl link statistics storage * * Sums per-queue rx_qstats and tx_qstats into the rtnl counters. + * rx_missed_errors is the PHYP no-buffer sum (retired plus the value + * from the last replenish pass), which if_link.h counts separately + * from rx_dropped. * Walk the full allocated arrays (not the live queue count) so shrinking * channels cannot make the totals go backwards. */ @@ -2857,6 +2918,7 @@ static void ibmveth_get_stats64(struct net_device *dev, stats->rx_bytes += READ_ONCE(adapter->rx_qstats[i].bytes); stats->rx_dropped += READ_ONCE(adapter->rx_qstats[i].dropped); } + stats->rx_missed_errors = ibmveth_sum_rx_no_buffer(adapter); for (i = 0; i < IBMVETH_MAX_QUEUES; i++) { stats->tx_packets += READ_ONCE(adapter->tx_qstats[i].packets); diff --git a/drivers/net/ethernet/ibm/ibmveth.h b/drivers/net/ethernet/ibm/ibmveth.h index d45f173edda2..d6d28b75dd99 100644 --- a/drivers/net/ethernet/ibm/ibmveth.h +++ b/drivers/net/ethernet/ibm/ibmveth.h @@ -250,8 +250,12 @@ struct ibmveth_rx_queue_stats { u64 large_packets; u64 invalid_buffers; u64 dropped; - /* PHYP's drop count from the buffer-list page. */ + /* PHYP's per-page absolute drop count for the live page. */ u64 no_buffer_drops; + /* Absolutes from retired pages or seen before a lower reading. */ + u64 no_buffer_retired; + /* no_buffer_retired + no_buffer_drops, for lockless readers. */ + u64 no_buffer_total; u64 replenish_task_cycles; u64 replenish_no_mem; u64 replenish_add_buff_failure; -- 2.50.1 (Apple Git-155) ip -s link and ethtool -S only show device totals, so they cannot show whether traffic is spread over the queues or which queue drops. Implement netdev_stat_ops so qstats-get shows each queue: packets and bytes, and for RX alloc_fail and PHYP's no-buffer drops as hw_drops and hw_drop_overruns. This already covers today's TX queues. RX alloc_fail counts failed skb allocations both when refilling buffers and for copybreak, which then passes the frame up in its pool buffer. Nothing counted the copybreak failures before. An invalid buffer PHYP hands back carries no frame, so it is not a hw_drop; it stays in ethtool -S as rx_invalid_buffer. A frame PHYP delivered but the driver then dropped is rx_dropped, not a hw_drop. TX hw_drops is left unset, because the TX drop count includes frames rejected before they reached PHYP. Queues above the live count are reported in the base stats, so the qstats total still matches ndo_get_stats64 after the queue count goes down. Signed-off-by: Mingming Cao --- drivers/net/ethernet/ibm/ibmveth.c | 75 +++++++++++++++++++++++++++++- drivers/net/ethernet/ibm/ibmveth.h | 1 + 2 files changed, 75 insertions(+), 1 deletion(-) diff --git a/drivers/net/ethernet/ibm/ibmveth.c b/drivers/net/ethernet/ibm/ibmveth.c index 56b645ffb18c..f30d8ba23320 100644 --- a/drivers/net/ethernet/ibm/ibmveth.c +++ b/drivers/net/ethernet/ibm/ibmveth.c @@ -37,6 +37,7 @@ #include #include #include +#include #include "ibmveth.h" @@ -2577,8 +2578,11 @@ static void ibmveth_poll_deliver_frame(struct napi_struct *napi, } new_skb = NULL; - if (length < rx_copybreak) + if (length < rx_copybreak) { new_skb = netdev_alloc_skb(netdev, length); + if (unlikely(!new_skb)) + IBMVETH_STAT_INC(rxs->copybreak_no_mem); + } if (new_skb) { skb_copy_to_linear_data(new_skb, skb->data + offset, length); @@ -2928,6 +2932,74 @@ static void ibmveth_get_stats64(struct net_device *dev, } } +static void ibmveth_get_queue_stats_rx(struct net_device *dev, int idx, + struct netdev_queue_stats_rx *stats) +{ + struct ibmveth_adapter *adapter = netdev_priv(dev); + u64 no_buffer; + + stats->packets = READ_ONCE(adapter->rx_qstats[idx].packets); + stats->bytes = READ_ONCE(adapter->rx_qstats[idx].bytes); + /* Frames PHYP dropped for lack of a posted buffer: the last sample + * of the live page plus pages this queue already released. + */ + no_buffer = ibmveth_rx_no_buffer_total(adapter, idx); + stats->hw_drops = no_buffer; + stats->hw_drop_overruns = no_buffer; + stats->alloc_fail = + READ_ONCE(adapter->rx_qstats[idx].replenish_no_mem) + + READ_ONCE(adapter->rx_qstats[idx].copybreak_no_mem); +} + +static void ibmveth_get_queue_stats_tx(struct net_device *dev, int idx, + struct netdev_queue_stats_tx *stats) +{ + struct ibmveth_adapter *adapter = netdev_priv(dev); + + stats->packets = READ_ONCE(adapter->tx_qstats[idx].packets); + stats->bytes = READ_ONCE(adapter->tx_qstats[idx].bytes); + /* TX hw_drops left unset: dropped_packets includes + * software xmit rejects that never reached PHYP. + */ +} + +/** + * ibmveth_get_base_stats - account for traffic not on a live queue + * @dev: network device + * @rx: RX base statistics storage + * @tx: TX base statistics storage + * + * The core sums get_queue_stats_{rx,tx}() only below + * real_num_{rx,tx}_queues, while ibmveth_get_stats64() walks every + * slot. Report the slots at or above real_num here so the two agree + * after the queue count goes down. + * + * Every field the queue callbacks set must be set here too: the core + * drops a field from the device total if the base leaves it unset. + */ +static void ibmveth_get_base_stats(struct net_device *dev, + struct netdev_queue_stats_rx *rx, + struct netdev_queue_stats_tx *tx) +{ + rx->packets = 0; + rx->bytes = 0; + rx->alloc_fail = 0; + rx->hw_drops = 0; + rx->hw_drop_overruns = 0; + tx->packets = 0; + tx->bytes = 0; + + netdev_stat_queue_sum(dev, dev->real_num_rx_queues, + IBMVETH_MAX_RX_QUEUES, rx, + dev->real_num_tx_queues, IBMVETH_MAX_QUEUES, tx); +} + +static const struct netdev_stat_ops ibmveth_stat_ops = { + .get_queue_stats_rx = ibmveth_get_queue_stats_rx, + .get_queue_stats_tx = ibmveth_get_queue_stats_tx, + .get_base_stats = ibmveth_get_base_stats, +}; + static const struct net_device_ops ibmveth_netdev_ops = { .ndo_open = ibmveth_open, .ndo_stop = ibmveth_close, @@ -3032,6 +3104,7 @@ static int ibmveth_probe(struct vio_dev *dev, const struct vio_device_id *id) netdev->irq = dev->irq; netdev->netdev_ops = &ibmveth_netdev_ops; netdev->ethtool_ops = &netdev_ethtool_ops; + netdev->stat_ops = &ibmveth_stat_ops; SET_NETDEV_DEV(netdev, &dev->dev); netdev->hw_features = NETIF_F_SG; if (vio_get_attribute(dev, "ibm,illan-options", NULL) != NULL) { diff --git a/drivers/net/ethernet/ibm/ibmveth.h b/drivers/net/ethernet/ibm/ibmveth.h index d6d28b75dd99..588209144de7 100644 --- a/drivers/net/ethernet/ibm/ibmveth.h +++ b/drivers/net/ethernet/ibm/ibmveth.h @@ -260,6 +260,7 @@ struct ibmveth_rx_queue_stats { u64 replenish_no_mem; u64 replenish_add_buff_failure; u64 replenish_add_buff_success; + u64 copybreak_no_mem; } ____cacheline_aligned_in_smp; /* Per-queue TX counters; serialized by the stack's per-queue TX lock. */ -- 2.50.1 (Apple Git-155) Turn on multi-queue (MQ) RX, so an adapter on MQ firmware spreads its receive processing over several queues and CPUs. When firmware sets IBMVETH_ILLAN_RX_MULTI_QUEUE_SUPPORT, probe sets multi_queue and the adapter comes up with netif_get_num_default_rss_queues() RX queues, at most 8; otherwise it stays single-queue. CMO (Cooperative Memory Overcommitment) and MQ firmware do not coexist; probe still keeps MQ off under CMO, because get_desired_dma(), used only under CMO, sizes the entitlement for one queue. PHYP picks the queue for each frame with a hash, so there is no RSS configuration. Raise IBMVETH_MAX_RX_QUEUES to 16, well within the 129 RX queues every MQ adapter can register; RX count changes are rejected until the next patch. MQ posts up to 12 buffers per hcall. Each queue gets its own buffer pools, sized like queue 0's; the poolN sysfs settings apply to every queue. Each queue's RX buffers take about 34 MB, so 8 queues take about 270 MB. Each queue also gets its own NAPI, added with netif_napi_add_config() so it keeps its NAPI ID across reopen and RX count changes, and linked to its queue and IRQ for netdev netlink. Probe adds a NAPI for every RX queue the adapter may use: all 16 when MQ is enabled, otherwise one. This moves the NAPI weight from 16 to the default 64 on every adapter; replenish runs once per poll whatever the budget, so the weight only bounds the frame loop. Queue N's interrupt (N >= 1) is named ibmveth--rxN; queue 0 keeps netdev->name. Received skbs record their RX queue only when there is more than one, so a single-queue adapter that forwards traffic still spreads it over TX queues by flow hash. Probe logs whether the adapter is multi-queue or single-queue, and the reset work logs the adapter it resets. Signed-off-by: Mingming Cao --- drivers/net/ethernet/ibm/ibmveth.c | 140 ++++++++++++++++++++++++++--- drivers/net/ethernet/ibm/ibmveth.h | 5 +- 2 files changed, 132 insertions(+), 13 deletions(-) diff --git a/drivers/net/ethernet/ibm/ibmveth.c b/drivers/net/ethernet/ibm/ibmveth.c index f30d8ba23320..20cb9202b7d3 100644 --- a/drivers/net/ethernet/ibm/ibmveth.c +++ b/drivers/net/ethernet/ibm/ibmveth.c @@ -519,7 +519,31 @@ ibmveth_dispose_subordinate_irq_mappings(struct ibmveth_adapter *adapter) } /** - * ibmveth_setup_rx_interrupts - Register IRQs and enable NAPI + * ibmveth_queue_irq_name - Name for one RX queue's Linux IRQ + * @adapter: ibmveth adapter structure + * @queue_idx: RX queue index + * + * Queue 0 keeps netdev->name, as before multi-queue. Subordinate queues + * use "ibmveth--rx", which survives a rename. + * request_irq() keeps the pointer, so the string lives in the adapter. + * + * Return: the name to pass to request_irq() + */ +static const char *ibmveth_queue_irq_name(struct ibmveth_adapter *adapter, + int queue_idx) +{ + char *name = adapter->queue_irq_name[queue_idx]; + + if (!queue_idx) + return adapter->netdev->name; + + snprintf(name, sizeof(adapter->queue_irq_name[0]), "ibmveth-%x-rx%d", + adapter->vdev->unit_address, queue_idx); + return name; +} + +/** + * ibmveth_setup_rx_interrupts - Register IRQs, enable and link NAPI * @adapter: ibmveth adapter structure * * The queues must already be masked in PHYP: queue 0 before the LAN is @@ -536,7 +560,8 @@ ibmveth_setup_rx_interrupts(struct ibmveth_adapter *adapter) for (i = 0; i < num; i++) { rc = request_irq(adapter->queue_irq[i], ibmveth_interrupt, - 0, netdev->name, &adapter->napi[i]); + 0, ibmveth_queue_irq_name(adapter, i), + &adapter->napi[i]); if (rc) { netdev_err(netdev, "request_irq() failed for irq 0x%x queue %d: %d\n", @@ -545,8 +570,12 @@ ibmveth_setup_rx_interrupts(struct ibmveth_adapter *adapter) } } - for (i = 0; i < num; i++) + for (i = 0; i < num; i++) { + netif_napi_set_irq(&adapter->napi[i], adapter->queue_irq[i]); napi_enable(&adapter->napi[i]); + netif_queue_set_napi(netdev, i, NETDEV_QUEUE_TYPE_RX, + &adapter->napi[i]); + } return 0; @@ -584,8 +613,12 @@ ibmveth_cleanup_rx_interrupts(struct ibmveth_adapter *adapter) synchronize_irq(adapter->queue_irq[i]); } - for (i = 0; i < adapter->num_rx_queues; i++) + for (i = 0; i < adapter->num_rx_queues; i++) { + netif_queue_set_napi(adapter->netdev, i, NETDEV_QUEUE_TYPE_RX, + NULL); + netif_napi_set_irq(&adapter->napi[i], -1); free_irq(adapter->queue_irq[i], &adapter->napi[i]); + } ibmveth_dispose_subordinate_irq_mappings(adapter); } @@ -1131,12 +1164,30 @@ static int ibmveth_alloc_queue_buffer_pools(struct ibmveth_adapter *adapter, * ibmveth_alloc_buffer_pools - Allocate buffer pools for all queues * @adapter: ibmveth adapter structure * + * Copy queue 0's pool metadata onto any further queues, then allocate + * buffer pools for every queue. + * * Return: 0 on success, -ENOMEM on failure */ static int ibmveth_alloc_buffer_pools(struct ibmveth_adapter *adapter) { - int q, rc; + int i, q, rc; + + for (q = 1; q < adapter->num_rx_queues; q++) { + for (i = 0; i < IBMVETH_NUM_BUFF_POOLS; i++) { + struct ibmveth_buff_pool *src = + &adapter->rx_buff_pool[0][i]; + struct ibmveth_buff_pool *dst = + &adapter->rx_buff_pool[q][i]; + + dst->size = src->size; + dst->index = src->index; + dst->buff_size = src->buff_size; + dst->threshold = src->threshold; + dst->active = src->active; + } + } for (q = 0; q < adapter->num_rx_queues; q++) { rc = ibmveth_alloc_queue_buffer_pools(adapter, q); @@ -1753,6 +1804,9 @@ static void ibmveth_reset(struct work_struct *w) bool hfunc = READ_ONCE(adapter->mq_hfunc); bool give_up = hfunc && adapter->mq_hfunc_reopened; + if (net_ratelimit()) + netdev_info(netdev, "resetting %08x (close/open)\n", + adapter->vdev->unit_address); dev_close(netdev); /* Firmware that returns MQ H_FUNCTION again after a reopen * would do so on every reopen; leave the device down rather @@ -2105,6 +2159,14 @@ static int ibmveth_set_channels(struct net_device *netdev, goal = channels->tx_count; int rc, i, alloc_rc = 0; + /* + * RX channel resize is not supported; reject any request that + * changes rx_count. Read-modify-write TX adjustments submit the + * current rx_count and proceed. + */ + if (channels->rx_count != adapter->num_rx_queues) + return -EOPNOTSUPP; + /* If the device is not open (including a failed close/open with * IFF_UP still set) then don't allocate, just set desired * netdev_queue's and return @@ -2631,6 +2693,12 @@ static void ibmveth_poll_deliver_frame(struct napi_struct *napi, ibmveth_rx_csum_helper(skb, adapter); } + /* skb_tx_hash() picks the egress queue from a recorded RX queue + * instead of the flow hash, so only record one when there are + * several. num_rx_queues changes only while the device is closed. + */ + if (adapter->num_rx_queues > 1) + skb_record_rx_queue(skb, queue_index); napi_gro_receive(napi, skb); /* send it up */ IBMVETH_STAT_INC(rxs->packets); @@ -3086,7 +3154,8 @@ static int ibmveth_probe(struct vio_dev *dev, const struct vio_device_id *id) return -EINVAL; } - netdev = alloc_etherdev_mqs(sizeof(struct ibmveth_adapter), IBMVETH_MAX_QUEUES, 1); + netdev = alloc_etherdev_mqs(sizeof(struct ibmveth_adapter), + IBMVETH_MAX_QUEUES, IBMVETH_MAX_RX_QUEUES); if (!netdev) return -ENOMEM; @@ -3099,8 +3168,6 @@ static int ibmveth_probe(struct vio_dev *dev, const struct vio_device_id *id) adapter->mcastFilterSize = be32_to_cpu(*mcastFilterSize_p); ibmveth_init_link_settings(netdev); - netif_napi_add_weight(netdev, &adapter->napi[0], ibmveth_poll, 16); - netdev->irq = dev->irq; netdev->netdev_ops = &ibmveth_netdev_ops; netdev->ethtool_ops = &netdev_ethtool_ops; @@ -3132,11 +3199,36 @@ static int ibmveth_probe(struct vio_dev *dev, const struct vio_device_id *id) netdev->features |= NETIF_F_FRAGLIST; } - adapter->num_rx_queues = IBMVETH_DEFAULT_RX_QUEUES; + /* get_desired_dma() sizes the CMO entitlement for one RX queue. */ + if (ret == H_SUCCESS && + (ret_attr & IBMVETH_ILLAN_RX_MULTI_QUEUE_SUPPORT) && + !firmware_has_feature(FW_FEATURE_CMO)) { + adapter->multi_queue = true; + adapter->num_rx_queues = + min_t(unsigned int, netif_get_num_default_rss_queues(), + IBMVETH_MQ_DEFAULT_RX_QUEUES); + netdev_dbg(netdev, "RX multi queue mode enabled: %u queues\n", + adapter->num_rx_queues); + } else { + adapter->multi_queue = false; + adapter->num_rx_queues = IBMVETH_DEFAULT_RX_QUEUES; + } + + /* MQ may later raise the RX count with ethtool -L, so pre-add every + * possible NAPI with a stable config index. Single-queue adapters + * never grow past one. + */ + for (i = 0; i < (adapter->multi_queue ? IBMVETH_MAX_RX_QUEUES : 1); i++) + netif_napi_add_config(netdev, &adapter->napi[i], + ibmveth_poll, i); if (ret == H_SUCCESS && (ret_attr & IBMVETH_ILLAN_RX_MULTI_BUFF_SUPPORT)) { - adapter->rx_buffers_per_hcall = IBMVETH_MAX_RX_REGULAR; + if (adapter->multi_queue) + adapter->rx_buffers_per_hcall = + IBMVETH_MAX_RX_PER_HCALL; + else + adapter->rx_buffers_per_hcall = IBMVETH_MAX_RX_REGULAR; netdev_dbg(netdev, "RX Multi-buffer hcall supported by FW, batch set to %u\n", adapter->rx_buffers_per_hcall); @@ -3178,10 +3270,34 @@ static int ibmveth_probe(struct vio_dev *dev, const struct vio_device_id *id) rc = netif_set_real_num_tx_queues(netdev, min(num_online_cpus(), IBMVETH_DEFAULT_QUEUES)); if (rc) { - netdev_dbg(netdev, "failed to set number of tx queues rc=%d\n", - rc); + dev_err(&dev->dev, "failed to set number of tx queues rc=%d\n", + rc); goto err_put_pools; } + + /* alloc_etherdev_mqs() set real_num_rx_queues to the maximum. */ + rc = netif_set_real_num_rx_queues(netdev, adapter->num_rx_queues); + if (rc) { + dev_err(&dev->dev, "failed to set number of rx queues rc=%d\n", + rc); + goto err_put_pools; + } + + if (adapter->multi_queue) { + dev_info(&dev->dev, + "Multi-queue LAN %08x: %u RX queues (max %u), %u TX queues\n", + adapter->vdev->unit_address, adapter->num_rx_queues, + IBMVETH_MAX_RX_QUEUES, netdev->real_num_tx_queues); + } else { + dev_info(&dev->dev, + "Single-queue LAN %08x: %u TX queues (h_illan rc=%ld, FW MQ=%d, CMO=%d)\n", + adapter->vdev->unit_address, + netdev->real_num_tx_queues, ret, + (ret == H_SUCCESS && + (ret_attr & IBMVETH_ILLAN_RX_MULTI_QUEUE_SUPPORT)) ? 1 : 0, + firmware_has_feature(FW_FEATURE_CMO) ? 1 : 0); + } + adapter->tx_ltb_size = PAGE_ALIGN(IBMVETH_MAX_TX_BUF_SIZE); for (i = 0; i < IBMVETH_MAX_QUEUES; i++) adapter->tx_ltb_ptr[i] = NULL; diff --git a/drivers/net/ethernet/ibm/ibmveth.h b/drivers/net/ethernet/ibm/ibmveth.h index 588209144de7..be6207fba9e3 100644 --- a/drivers/net/ethernet/ibm/ibmveth.h +++ b/drivers/net/ethernet/ibm/ibmveth.h @@ -30,6 +30,7 @@ #define IbmVethMcastRemoveFilter 0x2UL #define IbmVethMcastClearFilterTable 0x3UL +#define IBMVETH_ILLAN_RX_MULTI_QUEUE_SUPPORT 0x0000000000080000UL #define IBMVETH_ILLAN_RX_MULTI_BUFF_SUPPORT 0x0000000000040000UL #define IBMVETH_ILLAN_LRG_SR_ENABLED 0x0000000000010000UL #define IBMVETH_ILLAN_LRG_SND_SUPPORT 0x0000000000008000UL @@ -226,8 +227,9 @@ static inline long h_illan_attributes(unsigned long unit_address, #define IBMVETH_MAX_TX_BUF_SIZE (1024 * 64) #define IBMVETH_MAX_QUEUES 16U #define IBMVETH_DEFAULT_QUEUES 8U -#define IBMVETH_MAX_RX_QUEUES 1U +#define IBMVETH_MAX_RX_QUEUES 16U #define IBMVETH_DEFAULT_RX_QUEUES 1U +#define IBMVETH_MQ_DEFAULT_RX_QUEUES 8U #define IBMVETH_MAX_RX_REGULAR 8U #define IBMVETH_MAX_RX_PER_HCALL 12U @@ -320,6 +322,7 @@ struct ibmveth_adapter { * queue 0 uses h_vio_signal(), so entry 0 is never read. */ unsigned long queue_hwirq[IBMVETH_MAX_RX_QUEUES]; + char queue_irq_name[IBMVETH_MAX_RX_QUEUES][32]; bool multi_queue; unsigned int num_rx_queues; int rx_csum; -- 2.50.1 (Apple Git-155) With MQ, ethtool -L still rejects RX count changes, so the count cannot be raised for throughput or lowered to save memory. Accept 1 to 16 RX queues on MQ firmware; without MQ, max_rx stays at the current count. RX queues are registered with PHYP at open, so change the count as change_mtu() does: if the device is up, close it, set the counts and reopen it; if it is down, just set them, so the count can still be lowered if PHYP refuses a queue at open. Traffic stops while the device is closed. A TX-only change keeps the live path. Restore the RX mode after the reopen, since close/open does not run dev_set_rx_mode(). If the reopen fails, restore the old counts and reopen. If either step fails, the device is left closed with IFF_UP still set and whichever counts are in place, so schedule the reset work: it tries one more open and leaves the device down if that fails too. A queue count change is logged with the old and new counts. Signed-off-by: Mingming Cao --- drivers/net/ethernet/ibm/ibmveth.c | 110 +++++++++++++++++++++++++---- 1 file changed, 98 insertions(+), 12 deletions(-) diff --git a/drivers/net/ethernet/ibm/ibmveth.c b/drivers/net/ethernet/ibm/ibmveth.c index 20cb9202b7d3..87ce6bcda472 100644 --- a/drivers/net/ethernet/ibm/ibmveth.c +++ b/drivers/net/ethernet/ibm/ibmveth.c @@ -43,6 +43,7 @@ static irqreturn_t ibmveth_interrupt(int irq, void *dev_instance); static unsigned long ibmveth_get_desired_dma(struct vio_dev *vdev); +static void ibmveth_set_multicast_list(struct net_device *netdev); static struct kobj_type ktype_veth_pool; @@ -1729,7 +1730,8 @@ static int ibmveth_open(struct net_device *netdev) netif_tx_unlock_bh(netdev); adapter->opened = true; - netdev_dbg(netdev, "open complete\n"); + netdev_dbg(netdev, "open complete: %u RX, %u TX queues\n", + adapter->num_rx_queues, netdev->real_num_tx_queues); return 0; @@ -1752,9 +1754,10 @@ static int ibmveth_close(struct net_device *netdev) { struct ibmveth_adapter *adapter = netdev_priv(netdev); - /* change_mtu, pool sysfs, set_csum and set_tso call close() and - * open() directly. If that open() fails, IFF_UP stays set and - * NAPI is disabled; a second close() would hang in napi_disable(). + /* change_mtu, pool sysfs, set_csum, set_tso and set_channels call + * close() and open() directly. If that open() fails, IFF_UP stays + * set and NAPI is disabled; a second close() would hang in + * napi_disable(). */ if (!adapter->opened) return 0; @@ -2144,11 +2147,90 @@ static void ibmveth_get_ethtool_stats(struct net_device *dev, static void ibmveth_get_channels(struct net_device *netdev, struct ethtool_channels *channels) { + struct ibmveth_adapter *adapter = netdev_priv(netdev); + channels->max_tx = ibmveth_real_max_tx_queues(); channels->tx_count = netdev->real_num_tx_queues; - channels->max_rx = netdev->real_num_rx_queues; channels->rx_count = netdev->real_num_rx_queues; + channels->max_rx = adapter->multi_queue ? + IBMVETH_MAX_RX_QUEUES : channels->rx_count; +} + +/* Called with the device closed: open() sizes the RX queues and the TX + * LTBs from these counts. + */ +static int ibmveth_set_queue_counts(struct net_device *netdev, + unsigned int rx, unsigned int tx) +{ + struct ibmveth_adapter *adapter = netdev_priv(netdev); + unsigned int old_rx = adapter->num_rx_queues; + unsigned int old_tx = netdev->real_num_tx_queues; + int rc; + + rc = netif_set_real_num_queues(netdev, tx, rx); + if (!rc) { + adapter->num_rx_queues = rx; + if (old_rx != rx || old_tx != tx) { + if (adapter->multi_queue) + netdev_info(netdev, + "queues %08x: RX %u -> %u, TX %u -> %u\n", + adapter->vdev->unit_address, + old_rx, rx, old_tx, tx); + else if (old_tx != tx) + netdev_info(netdev, + "queues %08x: TX %u -> %u (RX 1)\n", + adapter->vdev->unit_address, + old_tx, tx); + } + } + return rc; +} + +static void ibmveth_restore_rx_mode(struct net_device *netdev) +{ + netif_addr_lock_bh(netdev); + ibmveth_set_multicast_list(netdev); + netif_addr_unlock_bh(netdev); +} + +static int ibmveth_reopen_with_counts(struct net_device *netdev, + unsigned int rx, unsigned int tx) +{ + struct ibmveth_adapter *adapter = netdev_priv(netdev); + unsigned int old_rx = adapter->num_rx_queues; + unsigned int old_tx = netdev->real_num_tx_queues; + int rc, rc2; + + ibmveth_close(netdev); + + rc = ibmveth_set_queue_counts(netdev, rx, tx); + if (!rc) { + rc = ibmveth_open(netdev); + if (!rc) { + ibmveth_restore_rx_mode(netdev); + return 0; + } + if (ibmveth_set_queue_counts(netdev, old_rx, old_tx)) { + netdev_err(netdev, "failed to restore %u RX / %u TX queues\n", + old_rx, old_tx); + goto out_reset; + } + } + + rc2 = ibmveth_open(netdev); + if (!rc2) { + ibmveth_restore_rx_mode(netdev); + return rc; + } + netdev_err(netdev, "reopen with the old queue counts failed: %d\n", + rc2); +out_reset: + /* Closed with IFF_UP set: the reset work closes and reopens once + * more, and dev_open() leaves the device down if that fails. + */ + schedule_work(&adapter->work); + return rc; } static int ibmveth_set_channels(struct net_device *netdev, @@ -2156,16 +2238,20 @@ static int ibmveth_set_channels(struct net_device *netdev, { struct ibmveth_adapter *adapter = netdev_priv(netdev); unsigned int old = netdev->real_num_tx_queues, - goal = channels->tx_count; + goal = channels->tx_count, + rx = channels->rx_count; int rc, i, alloc_rc = 0; - /* - * RX channel resize is not supported; reject any request that - * changes rx_count. Read-modify-write TX adjustments submit the - * current rx_count and proceed. + /* A TX-only -L resubmits the current rx_count and takes the live + * TX path below. An RX change closes and reopens a running device, + * and applies the TX count in the same window; a closed device + * just takes the new counts. */ - if (channels->rx_count != adapter->num_rx_queues) - return -EOPNOTSUPP; + if (rx != adapter->num_rx_queues) { + if (adapter->opened) + return ibmveth_reopen_with_counts(netdev, rx, goal); + return ibmveth_set_queue_counts(netdev, rx, goal); + } /* If the device is not open (including a failed close/open with * IFF_UP still set) then don't allocate, just set desired -- 2.50.1 (Apple Git-155)