fm10k: stop spurious link down messages when Tx FIFO is full
Subsystems (2)
PATCH v3 1/16 fm10k: stop spurious link down messages when Tx FIFO is full
In fm10k_get_host_state_generic, we check the mailbox tx_read() function to ensure that the mailbox is still open. This function also checks to make sure we have space to transmit another message. Unfortunately, if we just recently sent a bunch of messages (such as enabling hundreds of VLANs on a VF) this can result in a race where the watchdog task thinks the link went down just because we haven't had time to process all these messages yet.
Instead, lets just check whether the mailbox is still open. This ensures that we don't race with the Tx fifo, and we only link down once the mailbox is not open.
This is safe, because if the FIFO fills up and we're unable to send a message for too long, we'll end up triggering the timeout detection which results in a reset. Additionally, since we still check to ensure the mailbox state is OPEN, we'll transition to link down whenever the mailbox closes as well.
--- drivers/net/ethernet/intel/fm10k/fm10k_common.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/net/ethernet/intel/fm10k/fm10k_common.c +3 -3
@@ -1,5 +1,5 @@/* Intel(R) Ethernet Switch Host Interface Driver -* Copyright(c) 2013 - 2016 Intel Corporation. +* Copyright(c) 2013 - 2017 Intel Corporation. * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License,
@@ -517,8 +517,8 @@ s32 fm10k_get_host_state_generic(struct fm10k_hw *hw, bool *host_ready) goto out; } -/* verify Mailbox is still valid */ -if (!mbx->ops.tx_ready (mbx,FM10K_VFMBX_MSG_MTU )) +/* verify Mailbox is still open */ +if (mbx->state !=FM10K_STATE_OPEN ) goto out;/* interface cannot receive traffic without logical ports */
Signature · 1 line
2.13.0.615.gb09ed6e59a40
PATCH v3 2/16 fm10k: fix typos on fall through comments
Newer versions of GCC since version 7 now warn when a case statement may fall through without an explicit comment. "Fallthough" does not count as it is misspelled. Fix the typos for these comments to appease the new warnings.
--- drivers/net/ethernet/intel/fm10k/fm10k_mbx.c | 4 ++-- drivers/net/ethernet/intel/fm10k/fm10k_pf.c | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-)
drivers/net/ethernet/intel/fm10k/fm10k_mbx.c +2 -2
@@ -1,5 +1,5 @@/* Intel(R) Ethernet Switch Host Interface Driver -* Copyright(c) 2013 - 2016 Intel Corporation. +* Copyright(c) 2013 - 2017 Intel Corporation. * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License,
@@ -1586,7 +1586,7 @@ s32 fm10k_pfvf_mbx_init(struct fm10k_hw *hw, struct fm10k_mbx_info *mbx, mbx->mbmem_reg =FM10K_MBMEM_VF (id,0 );break ; } -/* fallthough */ +/* fall through */ default :return FM10K_MBX_ERR_NO_MBX ; }
drivers/net/ethernet/intel/fm10k/fm10k_pf.c +5 -5
@@ -1,5 +1,5 @@/* Intel(R) Ethernet Switch Host Interface Driver -* Copyright(c) 2013 - 2016 Intel Corporation. +* Copyright(c) 2013 - 2017 Intel Corporation. * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License,
@@ -1334,19 +1334,19 @@ static u8 fm10k_iov_supported_xcast_mode_pf(struct fm10k_vf_info *vf_info,case FM10K_XCAST_MODE_PROMISC :if (vf_flags &FM10K_VF_FLAG_PROMISC_CAPABLE )return FM10K_XCAST_MODE_PROMISC ; -/* fallthough */ +/* fall through */ case FM10K_XCAST_MODE_ALLMULTI :if (vf_flags &FM10K_VF_FLAG_ALLMULTI_CAPABLE )return FM10K_XCAST_MODE_ALLMULTI ; -/* fallthough */ +/* fall through */ case FM10K_XCAST_MODE_MULTI :if (vf_flags &FM10K_VF_FLAG_MULTI_CAPABLE )return FM10K_XCAST_MODE_MULTI ; -/* fallthough */ +/* fall through */ case FM10K_XCAST_MODE_NONE :if (vf_flags &FM10K_VF_FLAG_NONE_CAPABLE )return FM10K_XCAST_MODE_NONE ; -/* fallthough */ +/* fall through */ default :break ; }
Signature · 1 line
2.13.0.615.gb09ed6e59a40
Singh
PATCH v3 2/16 fm10k: fix typos on fall through comments
Quoted 9 lines
-----Original Message-----
From: Intel-wired-lan [mailto:intel-wired-lan-bounces at osuosl.org] On Behalf Of Jacob Keller
Sent: Monday, July 10, 2017 1:23 PM
To: jtkirhse at osuosl.org; Intel Wired LAN <[email protected]>
Cc: jekeller at osuosl.org
Subject: [Intel-wired-lan] [PATCH v3 02/16] fm10k: fix typos on fall through comments
Quoted 7 lines
Newer versions of GCC since version 7 now warn when a case statement may fall through without an explicit comment. "Fallthough" does not count as it is misspelled. Fix the typos for these comments to appease the new warnings.
Signed-off-by Jacob Keller <[email protected]>---
PATCH v3 3/16 fm10k: avoid possible truncation of q_vector->name
In reply to Jacob KellerNew versions of GCC since version 7 began warning about possible truncation of calls to snprintf. We can fix this and avoid false positives. First, we should pass the full buffer size to snprintf, because it guarantees a NULL character as part of its passed length, so passing len-1 is simply wasting a byte of possible storage.
Second, if we make the ri and ti variables unsigned, the compiler is able to correctly reason that the value never gets larger than 256, so it doesn't need to warn about the full space required to print a signed integer.
--- drivers/net/ethernet/intel/fm10k/fm10k_pci.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)
drivers/net/ethernet/intel/fm10k/fm10k_pci.c +7 -7
@@ -1544,7 +1544,7 @@ int fm10k_qv_request_irq(struct fm10k_intfc *interface)struct net_device *dev = interface->netdev;struct fm10k_hw *hw = &interface->hw;struct msix_entry *entry; -int ri =0 , ti =0 ; +unsigned int ri =0 , ti =0 ;int vector, err; entry = &interface->msix_entries[NON_Q_VECTORS (hw)];
@@ -1554,15 +1554,15 @@ int fm10k_qv_request_irq(struct fm10k_intfc *interface)/* name the vector */ if (q_vector->tx.count && q_vector->rx.count) { -snprintf (q_vector->name,sizeof (q_vector->name) -1 , -"%s-TxRx-%d" , dev->name, ri++); +snprintf (q_vector->name,sizeof (q_vector->name), +"%s-TxRx-%u" , dev->name, ri++); ti++; }else if (q_vector->rx.count) { -snprintf (q_vector->name,sizeof (q_vector->name) -1 , -"%s-rx-%d" , dev->name, ri++); +snprintf (q_vector->name,sizeof (q_vector->name), +"%s-rx-%u" , dev->name, ri++); }else if (q_vector->tx.count) { -snprintf (q_vector->name,sizeof (q_vector->name) -1 , -"%s-tx-%d" , dev->name, ti++); +snprintf (q_vector->name,sizeof (q_vector->name), +"%s-tx-%u" , dev->name, ti++); }else {/* skip this unused q_vector */ continue ;
Signature · 1 line
2.13.0.615.gb09ed6e59a40
Singh
PATCH v3 3/16 fm10k: avoid possible truncation of q_vector->name
Quoted 15 lines
-----Original Message-----
From: Intel-wired-lan [mailto:intel-wired-lan-bounces at osuosl.org] On Behalf Of Jacob Keller
Sent: Monday, July 10, 2017 1:23 PM
To: jtkirhse at osuosl.org; Intel Wired LAN <[email protected]>
Cc: jekeller at osuosl.org
Subject: [Intel-wired-lan] [PATCH v3 03/16] fm10k: avoid possible truncation ofq_vector->nameNew versions of GCC since version 7 began warning about possible truncation of calls to snprintf. We can fix this and avoid false positives. First, we should pass the full buffer size to snprintf, because it guarantees a NULL character as part of its passed length, so passing len-1 is simply wasting a byte of possible storage.
Quoted 7 lines
Second, if we make the ri and ti variables unsigned, the compiler is able to correctly reason that the value never gets larger than 256, so it doesn't need to warn about the full space required to print a signed integer.
Signed-off-by Jacob Keller <[email protected]>---
PATCH v3 4/16 fm10k: add missing fall through comment
In reply to Jacob KellerNewer versions of GCC starting with 7 now additionally warn when a case statement may fall through without an explicit comment mentioning it. Add such a comment to silence the warning, as this is expected.
Unfortunately the comment must come directly before the next case statement, so we put it outside the #ifdef. Otherwise, the compiler cannot properly detect it and thus the warning is displayed regardless.
--- drivers/net/ethernet/intel/fm10k/fm10k_main.c | 1 + 1 file changed, 1 insertion(+)
drivers/net/ethernet/intel/fm10k/fm10k_main.c +1 -0
@@ -876,6 +876,7 @@ static void fm10k_tx_csum(struct fm10k_ring *tx_ring,case IPPROTO_GRE :if (skb->encapsulation)break ; +/* fall through */ default :if (unlikely (net_ratelimit ())) { dev_warn(tx_ring->dev,
Signature · 1 line
2.13.0.615.gb09ed6e59a40
Singh
PATCH v3 4/16 fm10k: add missing fall through comment
Quoted 13 lines
-----Original Message-----
From: Intel-wired-lan [mailto:intel-wired-lan-bounces at osuosl.org] On Behalf Of Jacob Keller
Sent: Monday, July 10, 2017 1:23 PM
To: jtkirhse at osuosl.org; Intel Wired LAN <[email protected]>
Cc: jekeller at osuosl.org
Subject: [Intel-wired-lan] [PATCH v3 04/16] fm10k: add missing fall through commentNewer versions of GCC starting with 7 now additionally warn when a case statement may fall through without an explicit comment mentioning it. Add such a comment to silence the warning, as this is expected.
Quoted 6 lines
Unfortunately the comment must come directly before the next case statement, so we put it outside the #ifdef. Otherwise, the compiler cannot properly detect it and thus the warning is displayed regardless.
Signed-off-by Jacob Keller <[email protected]>---
PATCH v3 5/16 fm10k: avoid needless delay when loading driver
In reply to Jacob KellerWhen we load the driver, we set the last_reset to be in the future, which delays the initial driver reset. Additionally, the service task isn't scheduled to run automatically until the timer runs out. This causes a needless delay of the first reset to begin talking to the switch manager.
We can avoid this by simply not setting last_reset and immediately scheduling the service task while in probe. This allows the device to wake up faster, and avoids this delay.
--- drivers/net/ethernet/intel/fm10k/fm10k_pci.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/net/ethernet/intel/fm10k/fm10k_pci.c +2 -4
@@ -1800,9 +1800,6 @@ static int fm10k_sw_init(struct fm10k_intfc *interface, netdev->vlan_features |=NETIF_F_HIGHDMA ; } -/* delay any future reset requests */ - interface->last_reset = jiffies + (10 *HZ ); -/* reset and initialize the hardware so it is in a known state */ err = hw->mac.ops.reset_hw (hw);if (err) {
@@ -2079,8 +2076,9 @@ static int fm10k_probe(struct pci_dev *pdev, const struct pci_device_id *ent)/* enable SR-IOV after registering netdev to enforce PF/VF ordering */ fm10k_iov_configure (pdev,0 ); -/* clear the service task disable bit to allow service task to start */ +/* clear the service task disable bit and kick off service task */ clear_bit (__FM10K_SERVICE_DISABLE, interface->state); +fm10k_service_event_schedule (interface);return 0 ;
Signature · 1 line
2.13.0.615.gb09ed6e59a40
Singh
PATCH v3 5/16 fm10k: avoid needless delay when loading driver
Quoted 15 lines
-----Original Message-----
From: Intel-wired-lan [mailto:intel-wired-lan-bounces at osuosl.org] On Behalf Of Jacob Keller
Sent: Monday, July 10, 2017 1:23 PM
To: jtkirhse at osuosl.org; Intel Wired LAN <[email protected]>
Cc: jekeller at osuosl.org
Subject: [Intel-wired-lan] [PATCH v3 05/16] fm10k: avoid needless delay when loading driverWhen we load the driver, we set the
last_resetto be in the future, which delays the initial driver reset. Additionally, the service task isn't scheduled to run automatically until the timer runs out. This causes a needless delay of the first reset to begin talking to the switch manager.
Quoted 6 lines
We can avoid this by simply not setting
last_resetand immediately scheduling the service task while in probe. This allows the device to wake up faster, and avoids this delay.Signed-off-by Jacob Keller <[email protected]>---
PATCH v3 6/16 fm10k: simplify reading PFVFLRE register
In reply to Jacob KellerWe're doing a really convoluted bitshift and read for the PFVFLRE register. Just reading the PFVFLRE(1), shifting it by 32, then reading PFVFLRE(0) should be sufficient.
--- drivers/net/ethernet/intel/fm10k/fm10k_iov.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/net/ethernet/intel/fm10k/fm10k_iov.c +2 -4
@@ -1,5 +1,5 @@/* Intel(R) Ethernet Switch Host Interface Driver -* Copyright(c) 2013 - 2016 Intel Corporation. +* Copyright(c) 2013 - 2017 Intel Corporation. * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License,
@@ -67,10 +67,8 @@ s32 fm10k_iov_event(struct fm10k_intfc *interface)/* read VFLRE to determine if any VFs have been reset */ do { - vflre = fm10k_read_reg(hw, FM10K_PFVFLRE(0)); + vflre = fm10k_read_reg(hw, FM10K_PFVFLRE(1)); vflre <<= 32; - vflre |= fm10k_read_reg(hw, FM10K_PFVFLRE(1)); - vflre = (vflre << 32) | (vflre >> 32); vflre |= fm10k_read_reg(hw, FM10K_PFVFLRE(0)); i = iov_data->num_vfs;
Signature · 1 line
2.13.0.615.gb09ed6e59a40
Singh
PATCH v3 6/16 fm10k: simplify reading PFVFLRE register
Quoted 9 lines
-----Original Message-----
From: Intel-wired-lan [mailto:intel-wired-lan-bounces at osuosl.org] On Behalf Of Jacob Keller
Sent: Monday, July 10, 2017 1:23 PM
To: jtkirhse at osuosl.org; Intel Wired LAN <[email protected]>
Cc: jekeller at osuosl.org
Subject: [Intel-wired-lan] [PATCH v3 06/16] fm10k: simplify reading PFVFLRE register
Quoted 6 lines
We're doing a really convoluted bitshift and read for the PFVFLRE register. Just reading the PFVFLRE(1), shifting it by 32, then reading PFVFLRE(0) should be sufficient.
Signed-off-by Jacob Keller <[email protected]>---
PATCH v3 7/16 fm10k: don't loop while resetting VFs due to VFLR event
In reply to Jacob KellerWe've always had a really weird looping construction for resetting VFs. We read the VFLRE register and reset the VF if the corresponding bit is set, which makes sense. However we loop continuously until we no longer have any bits left unset. At first this makes sense, as a sort of "keep trying until we succeed" concept.
Unfortunately this causes a problem if we happen to surprise remove while this code is executing, because in this case we'll always read all 1s for the VFLRE register. This results in a hard lockup on the CPU because the loop will never terminate.
Because our own reset function will clear the VFLR event register always, (except when we've lost PCIe link obviously) there is no real reason to loop. In practice, we'll loop over once and find that no VFs are pending anymore.
Lets just check once. Since we're clear the notification when we reset there's no benefit to the loop. Additionally, there shouldn't be a race as future VLFRE events should trigger an interrupt. Additionally, we didn't warn or do anything in the looped case anyways.
--- drivers/net/ethernet/intel/fm10k/fm10k_iov.c | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-)
drivers/net/ethernet/intel/fm10k/fm10k_iov.c +11 -13
@@ -66,23 +66,21 @@ s32 fm10k_iov_event(struct fm10k_intfc *interface) goto read_unlock;/* read VFLRE to determine if any VFs have been reset */ -do { - vflre =fm10k_read_reg (hw,FM10K_PFVFLRE (1 )); - vflre <<=32 ; - vflre |=fm10k_read_reg (hw,FM10K_PFVFLRE (0 )); + vflre =fm10k_read_reg (hw,FM10K_PFVFLRE (1 )); + vflre <<=32 ; + vflre |=fm10k_read_reg (hw,FM10K_PFVFLRE (0 )); - i = iov_data->num_vfs; + i = iov_data->num_vfs; -for (vflre <<=64 - i; vflre && i--; vflre += vflre) { -struct fm10k_vf_info *vf_info = &iov_data->vf_info[i]; +for (vflre <<=64 - i; vflre && i--; vflre += vflre) { +struct fm10k_vf_info *vf_info = &iov_data->vf_info[i]; -if (vflre >=0 ) -continue ; +if (vflre >=0 ) +continue ; - hw->iov.ops.reset_resources (hw, vf_info); - vf_info->mbx.ops.connect (hw, &vf_info->mbx); - } - }while (i != iov_data->num_vfs); + hw->iov.ops.reset_resources (hw, vf_info); + vf_info->mbx.ops.connect (hw, &vf_info->mbx); + } read_unlock:rcu_read_unlock ();
Signature · 1 line
2.13.0.615.gb09ed6e59a40
Singh
PATCH v3 7/16 fm10k: don't loop while resetting VFs due to VFLR event
Quoted 27 lines
-----Original Message-----
From: Intel-wired-lan [mailto:intel-wired-lan-bounces at osuosl.org] On Behalf Of Jacob Keller
Sent: Monday, July 10, 2017 1:23 PM
To: jtkirhse at osuosl.org; Intel Wired LAN <[email protected]>
Cc: jekeller at osuosl.org
Subject: [Intel-wired-lan] [PATCH v3 07/16] fm10k: don't loop while resetting VFs due to VFLR eventWe've always had a really weird looping construction for resetting VFs. We read the VFLRE register and reset the VF if the corresponding bit is set, which makes sense. However we loop continuously until we no longer have any bits left unset. At first this makes sense, as a sort of "keep trying until we succeed" concept.
Unfortunately this causes a problem if we happen to surprise remove while this code is executing, because in this case we'll always read all 1s for the VFLRE register. This results in a hard lockup on the CPU because the loop will never terminate.
Because our own reset function will clear the VFLR event register always, (except when we've lost PCIe link obviously) there is no real reason to loop. In practice, we'll loop over once and find that no VFs are pending anymore.
Quoted 7 lines
Lets just check once. Since we're clear the notification when we reset there's no benefit to the loop. Additionally, there shouldn't be a race as future VLFRE events should trigger an interrupt. Additionally, we didn't warn or do anything in the looped case anyways.
Signed-off-by Jacob Keller <[email protected]>---
PATCH v3 8/16 fm10k: avoid divide by zero in rare cases when device is resetting
In reply to Jacob KellerIt is possible that under rare circumstances the device is undergoing a reset, such as when a PFLR occurs, and the device may be transmitting simultaneously. In this case, we might attempt to divide by zero when finding the proper r_idx. Instead, lets read the num_tx_queues once, and make sure it's non-zero.
--- drivers/net/ethernet/intel/fm10k/fm10k_netdev.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/net/ethernet/intel/fm10k/fm10k_netdev.c +6 -2
@@ -643,9 +643,13 @@ int fm10k_close(struct net_device *netdev)static netdev_tx_t fm10k_xmit_frame (struct sk_buff *skb,struct net_device *dev) {struct fm10k_intfc *interface =netdev_priv (dev); +int num_tx_queues =READ_ONCE (interface->num_tx_queues);unsigned int r_idx = skb->queue_mapping;int err; +if (!num_tx_queues) +return NETDEV_TX_BUSY ; +if ((skb->protocol ==htons (ETH_P_8021Q )) && !skb_vlan_tag_present (skb)) {/* FM10K only supports hardware tagging, any tags in frame
@@ -698,8 +702,8 @@ static netdev_tx_t fm10k_xmit_frame(struct sk_buff *skb, struct net_device *dev)__skb_put (skb, pad_len); } -if (r_idx >= interface->num_tx_queues) - r_idx %= interface->num_tx_queues; +if (r_idx >= num_tx_queues) + r_idx %= num_tx_queues; err =fm10k_xmit_frame_ring (skb, interface->tx_ring[r_idx]);
Signature · 1 line
2.13.0.615.gb09ed6e59a40
Singh
PATCH v3 8/16 fm10k: avoid divide by zero in rare cases when device is resetting
Quoted 11 lines
-----Original Message-----
From: Intel-wired-lan [mailto:intel-wired-lan-bounces at osuosl.org] On Behalf Of Jacob Keller
Sent: Monday, July 10, 2017 1:23 PM
To: jtkirhse at osuosl.org; Intel Wired LAN <[email protected]>
Cc: jekeller at osuosl.org
Subject: [Intel-wired-lan] [PATCH v3 08/16] fm10k: avoid divide by zero in rare cases when device is resetting
Quoted 8 lines
It is possible that under rare circumstances the device is undergoing a reset, such as when a PFLR occurs, and the device may be transmitting simultaneously. In this case, we might attempt to divide by zero when finding the proper
r_idx. Instead, lets read thenum_tx_queuesonce, and make sure it's non-zero.Signed-off-by Jacob Keller <[email protected]>---
PATCH v3 9/16 fm10k: move fm10k_prepare_for_reset and fm10k_handle_reset
In reply to Jacob KellerA future patch needs these functions defined earlier in the file. Move them closer to above where they will be called.
--- drivers/net/ethernet/intel/fm10k/fm10k_pci.c | 58 ++++++++++++++-------------- 1 file changed, 29 insertions(+), 29 deletions(-)
drivers/net/ethernet/intel/fm10k/fm10k_pci.c +29 -29
@@ -132,35 +132,6 @@ static void fm10k_service_timer(unsigned long data)fm10k_service_event_schedule (interface); } -static void fm10k_detach_subtask (struct fm10k_intfc *interface) -{ -struct net_device *netdev = interface->netdev; -u32 __iomem *hw_addr; -u32 value; - -/* do nothing if device is still present or hw_addr is set */ -if (netif_device_present (netdev) || interface->hw.hw_addr) -return ; - -/* check the real address space to see if we've recovered */ - hw_addr =READ_ONCE (interface->uc_addr); - value =readl (hw_addr); -if (~value) { - interface->hw.hw_addr = interface->uc_addr; -netif_device_attach (netdev); -set_bit (FM10K_FLAG_RESET_REQUESTED , interface->flags); -netdev_warn (netdev,"PCIe link restored, device now attached\n" ); -return ; - } - -rtnl_lock (); - -if (netif_running (netdev)) -dev_close (netdev); - -rtnl_unlock (); -} -static void fm10k_prepare_for_reset (struct fm10k_intfc *interface) {struct net_device *netdev = interface->netdev;
@@ -270,6 +241,35 @@ static int fm10k_handle_reset(struct fm10k_intfc *interface)return err; } +static void fm10k_detach_subtask (struct fm10k_intfc *interface) +{ +struct net_device *netdev = interface->netdev; +u32 __iomem *hw_addr; +u32 value; + +/* do nothing if device is still present or hw_addr is set */ +if (netif_device_present (netdev) || interface->hw.hw_addr) +return ; + +/* check the real address space to see if we've recovered */ + hw_addr =READ_ONCE (interface->uc_addr); + value =readl (hw_addr); +if (~value) { + interface->hw.hw_addr = interface->uc_addr; +netif_device_attach (netdev); +set_bit (FM10K_FLAG_RESET_REQUESTED , interface->flags); +netdev_warn (netdev,"PCIe link restored, device now attached\n" ); +return ; + } + +rtnl_lock (); + +if (netif_running (netdev)) +dev_close (netdev); + +rtnl_unlock (); +} +static void fm10k_reinit (struct fm10k_intfc *interface) {int err;
Signature · 1 line
2.13.0.615.gb09ed6e59a40
Singh
PATCH v3 9/16 fm10k: move fm10k_prepare_for_reset and fm10k_handle_reset
Quoted 11 lines
-----Original Message-----
From: Intel-wired-lan [mailto:intel-wired-lan-bounces at osuosl.org] On Behalf Of Jacob Keller
Sent: Monday, July 10, 2017 1:23 PM
To: jtkirhse at osuosl.org; Intel Wired LAN <[email protected]>
Cc: jekeller at osuosl.org
Subject: [Intel-wired-lan] [PATCH v3 09/16] fm10k: movefm10k_prepare_for_resetandfm10k_handle_reset
Quoted 5 lines
A future patch needs these functions defined earlier in the file. Move them closer to above where they will be called.
Signed-off-by Jacob Keller <[email protected]>---
PATCH v3 10/16 fm10k: prevent race condition of __FM10K_SERVICE_SCHED
In reply to Jacob KellerAlthough very unlikely, it is possible that cancel_work_sync() may stop the service_task before it actually started. In this case, the __FM10K_SERVICE_SCHED bit will never be cleared. This results in the service task being unable to reschedule in the future. Add a helper function which sets the service disable bit, waits for the service task to stop and clears the schedule bit, thus avoiding the race condition. We know the schedule bit is safe to clear because the cancel_work_sync() guarantees the service task is not running.
Add a helper function also to restart the service task, for symmetry. This is not strictly needed but helps the mental model of how to stop and start the service task.
This race could only happen in fm10k_suspend/fm10k_resume as this is the only place where the service task is actually restarted. Thus, suspend/resume testing would be ideal. However, note that the chance of this happening is very slim as the service event is scheduled for immediate execution, and you would have to trigger a suspend at almost the exact same time as the service task was scheduled.
--- drivers/net/ethernet/intel/fm10k/fm10k_pci.c | 32 ++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 7 deletions(-)
drivers/net/ethernet/intel/fm10k/fm10k_pci.c +25 -7
@@ -118,6 +118,27 @@ static void fm10k_service_event_complete(struct fm10k_intfc *interface)fm10k_service_event_schedule (interface); } +static void fm10k_stop_service_event (struct fm10k_intfc *interface) +{ +set_bit (__FM10K_SERVICE_DISABLE, interface->state); +cancel_work_sync (&interface->service_task); + +/* It's possible that cancel_work_sync stopped the service task from +* running before it could actually start. In this case the +* __FM10K_SERVICE_SCHED bit will never be cleared. Since we know that +* the service task cannot be running at this point, we need to clear +* the scheduled bit, as otherwise the service task may never be +* restarted. +*/ +clear_bit (__FM10K_SERVICE_SCHED, interface->state); +} + +static void fm10k_start_service_event (struct fm10k_intfc *interface) +{ +clear_bit (__FM10K_SERVICE_DISABLE, interface->state); +fm10k_service_event_schedule (interface); +} +/** * fm10k_service_timer - Timer Call-back * @data: pointer to interface cast into an unsigned long
@@ -2116,8 +2137,7 @@ static void fm10k_remove(struct pci_dev *pdev)del_timer_sync (&interface->service_timer); -set_bit (__FM10K_SERVICE_DISABLE, interface->state); -cancel_work_sync (&interface->service_task); +fm10k_stop_service_event (interface);/* free netdev, this may bounce the interrupts due to setup_tc */ if (netdev->reg_state ==NETREG_REGISTERED )
@@ -2155,8 +2175,7 @@ static void fm10k_prepare_suspend(struct fm10k_intfc *interface)* stopped. We stop the watchdog task until after we resume software * activity. */ -set_bit (__FM10K_SERVICE_DISABLE, interface->state); -cancel_work_sync (&interface->service_task); +fm10k_stop_service_event (interface);fm10k_prepare_for_reset (interface); }
@@ -2183,9 +2202,8 @@ static int fm10k_handle_resume(struct fm10k_intfc *interface) interface->link_down_event = jiffies + (HZ );set_bit (__FM10K_LINK_DOWN, interface->state); -/* clear the service task disable bit to allow service task to start */ -clear_bit (__FM10K_SERVICE_DISABLE, interface->state); -fm10k_service_event_schedule (interface); +/* restart the service task */ +fm10k_start_service_event (interface);return err; }
Signature · 1 line
2.13.0.615.gb09ed6e59a40
Singh
PATCH v3 10/16 fm10k: prevent race condition of __FM10K_SERVICE_SCHED
Quoted 31 lines
-----Original Message-----
From: Intel-wired-lan [mailto:intel-wired-lan-bounces at osuosl.org] On Behalf Of Jacob Keller
Sent: Monday, July 10, 2017 1:23 PM
To: jtkirhse at osuosl.org; Intel Wired LAN <[email protected]>
Cc: jekeller at osuosl.org
Subject: [Intel-wired-lan] [PATCH v3 10/16] fm10k: prevent race condition of__FM10K_SERVICE_SCHEDAlthough very unlikely, it is possible that
cancel_work_sync()may stop theservice_taskbefore it actually started. In this case, the__FM10K_SERVICE_SCHEDbit will never be cleared. This results in the service task being unable to reschedule in the future. Add a helper function which sets the service disable bit, waits for the service task to stop and clears the schedule bit, thus avoiding the race condition. We know the schedule bit is safe to clear because thecancel_work_sync()guarantees the service task is not running.Add a helper function also to restart the service task, for symmetry. This is not strictly needed but helps the mental model of how to stop and start the service task.
This race could only happen in fm10k_suspend/fm10k_resume as this is the only place where the service task is actually restarted. Thus, suspend/resume testing would be ideal. However, note that the chance of this happening is very slim as the service event is scheduled for immediate execution, and you would have to trigger a suspend at almost the exact same time as the service task was scheduled.
Quoted 2 lines
Signed-off-by Jacob Keller <[email protected]>---
PATCH v3 11/16 fm10k: prepare_for_reset() when we lose PCIe Link
In reply to Jacob KellerIf we lose PCIe link, such as when an unannounced PFLR event occurs, or when a device is surprise removed, we currently detach the device and close the netdev. This unfortunately leaves a lot of things still active, such as the msix_mbx_pf IRQ, and Tx/Rx resources.
This can cause problems because the register reads will return potentially invalid values which may result in unknown driver behavior.
Begin the process of resetting using fm10k_prepare_for_reset(), much in the same way as the suspend and resume cycle does. This will attempt to shutdown as much as possible, in order to prevent possible issues.
A naive implementation for this has issues, because there are now multiple flows calling the reset logic and setting a reset bit. This would cause problems, because the "re-attach" routine might call fm10k_handle_reset() prior to the reset actually finishing. Instead, we'll add state bits to indicate which flow actually initiated the reset.
For the general reset flow, we'll assume that if someone else is resetting that we do not need to handle it at all, so it does not need its own state bit. For the suspend case, we will simply issue a warning indicating that we are attempting to recover from this case when resuming.
For the detached subtask, we'll simply refuse to re-attach until we've actually initiated a reset as part of that flow.
Finally, we'll stop attempting to manage the mailbox subtask when we're detached, since there's nothing we can do if we don't have a PCIe address.
Overall this produces a much cleaner shutdown and recovery cycle for a PCIe surprise remove event.
--- drivers/net/ethernet/intel/fm10k/fm10k.h | 2 + drivers/net/ethernet/intel/fm10k/fm10k_pci.c | 105 ++++++++++++++++++++------- 2 files changed, 80 insertions(+), 27 deletions(-)
drivers/net/ethernet/intel/fm10k/fm10k.h +2 -0
@@ -270,6 +270,8 @@ enum fm10k_flags_t {enum fm10k_state_t { __FM10K_RESETTING, + __FM10K_RESET_DETACHED, + __FM10K_RESET_SUSPENDED, __FM10K_DOWN, __FM10K_SERVICE_SCHED, __FM10K_SERVICE_REQUEST,
drivers/net/ethernet/intel/fm10k/fm10k_pci.c +78 -27
185 lines not on this page · raw message
Signature · 1 line
2.13.0.615.gb09ed6e59a40
Singh
PATCH v3 11/16 fm10k: prepare_for_reset() when we lose PCIe Link
Quoted 43 lines
-----Original Message-----
From: Intel-wired-lan [mailto:intel-wired-lan-bounces at osuosl.org] On Behalf Of Jacob Keller
Sent: Monday, July 10, 2017 1:23 PM
To: jtkirhse at osuosl.org; Intel Wired LAN <[email protected]>
Cc: jekeller at osuosl.org
Subject: [Intel-wired-lan] [PATCH v3 11/16] fm10k:prepare_for_reset()when we lose PCIe LinkIf we lose PCIe link, such as when an unannounced PFLR event occurs, or when a device is surprise removed, we currently detach the device and close the netdev. This unfortunately leaves a lot of things still active, such as the
msix_mbx_pfIRQ, and Tx/Rx resources.This can cause problems because the register reads will return potentially invalid values which may result in unknown driver behavior.
Begin the process of resetting using
fm10k_prepare_for_reset(), much in the same way as the suspend and resume cycle does. This will attempt to shutdown as much as possible, in order to prevent possible issues.A naive implementation for this has issues, because there are now multiple flows calling the reset logic and setting a reset bit. This would cause problems, because the "re-attach" routine might call
fm10k_handle_reset()prior to the reset actually finishing. Instead, we'll add state bits to indicate which flow actually initiated the reset.For the general reset flow, we'll assume that if someone else is resetting that we do not need to handle it at all, so it does not need its own state bit. For the suspend case, we will simply issue a warning indicating that we are attempting to recover from this case when resuming.
For the detached subtask, we'll simply refuse to re-attach until we've actually initiated a reset as part of that flow.
Finally, we'll stop attempting to manage the mailbox subtask when we're detached, since there's nothing we can do if we don't have a PCIe address.
Quoted 5 lines
Overall this produces a much cleaner shutdown and recovery cycle for a PCIe surprise remove event.
Signed-off-by Jacob Keller <[email protected]>---
PATCH v3 12/16 fm10k: use spinlock to implement mailbox lock
In reply to Jacob KellerLets not re-invent the locking wheel. Remove our bitlock and use a proper spinlock instead.
--- drivers/net/ethernet/intel/fm10k/fm10k.h | 15 +++++---------- drivers/net/ethernet/intel/fm10k/fm10k_pci.c | 3 +++ 2 files changed, 8 insertions(+), 10 deletions(-)
drivers/net/ethernet/intel/fm10k/fm10k.h +5 -10
@@ -276,7 +276,6 @@ enum fm10k_state_t { __FM10K_SERVICE_SCHED, __FM10K_SERVICE_REQUEST, __FM10K_SERVICE_DISABLE, - __FM10K_MBX_LOCK, __FM10K_LINK_DOWN, __FM10K_UPDATING_STATS,/* This value must be last and determines the BITMAP size */
@@ -346,6 +345,8 @@ struct fm10k_intfc {struct fm10k_hw_stats stats;struct fm10k_hw hw; +/* Mailbox lock */ +spinlock_t mbx_lock;u32 __iomem *uc_addr;u32 __iomem *sw_addr;u16 msg_enable;
@@ -386,23 +387,17 @@ struct fm10k_intfc {static inline void fm10k_mbx_lock (struct fm10k_intfc *interface) { -/* busy loop if we cannot obtain the lock as some calls -* such as ndo_set_rx_mode may be made in atomic context -*/ -while (test_and_set_bit (__FM10K_MBX_LOCK, interface->state)) -udelay (20 ); +spin_lock (&interface->mbx_lock); }static inline void fm10k_mbx_unlock (struct fm10k_intfc *interface) { -/* flush memory to make sure state is correct */ -smp_mb__before_atomic (); -clear_bit (__FM10K_MBX_LOCK, interface->state); +spin_unlock (&interface->mbx_lock); }static inline int fm10k_mbx_trylock (struct fm10k_intfc *interface) { -return !test_and_set_bit (__FM10K_MBX_LOCK, interface->state); +return spin_trylock (&interface->mbx_lock); }/* fm10k_test_staterr - test bits in Rx descriptor status and error fields */
drivers/net/ethernet/intel/fm10k/fm10k_pci.c +3 -0
@@ -1921,6 +1921,9 @@ static int fm10k_sw_init(struct fm10k_intfc *interface,netdev_rss_key_fill (rss_key,sizeof (rss_key));memcpy (interface->rssrk, rss_key,sizeof (rss_key)); +/* Initialize the mailbox lock */ +spin_lock_init (&interface->mbx_lock); +/* Start off interface as being down */ set_bit (__FM10K_DOWN, interface->state);set_bit (__FM10K_UPDATING_STATS, interface->state);
Signature · 1 line
2.13.0.615.gb09ed6e59a40
Singh
PATCH v3 12/16 fm10k: use spinlock to implement mailbox lock
Quoted 11 lines
-----Original Message-----
From: Intel-wired-lan [mailto:intel-wired-lan-bounces at osuosl.org] On Behalf Of Jacob Keller
Sent: Monday, July 10, 2017 1:23 PM
To: jtkirhse at osuosl.org; Intel Wired LAN <[email protected]>
Cc: jekeller at osuosl.org
Subject: [Intel-wired-lan] [PATCH v3 12/16] fm10k: use spinlock to implement mailbox lock
Quoted 5 lines
Lets not re-invent the locking wheel. Remove our bitlock and use a proper spinlock instead.
Signed-off-by Jacob Keller <[email protected]>---
PATCH v3 13/16 fm10k: use generic PM hooks instead of legacy PCIe power hooks
In reply to Jacob KellerReplace the PCI specific legacy power management hooks with the new generic power management hooks which work properly for both suspend and hibernate. The new generic system is better and properly handles the lower level PCIe power management rather than forcing the driver to handle it.
--- drivers/net/ethernet/intel/fm10k/fm10k_pci.c | 67 +++++++++------------------- 1 file changed, 22 insertions(+), 45 deletions(-)
drivers/net/ethernet/intel/fm10k/fm10k_pci.c +22 -45
@@ -2264,36 +2264,19 @@ static int fm10k_handle_resume(struct fm10k_intfc *interface)#ifdef CONFIG_PM /** -* fm10k_resume - Restore device to pre-sleep state -* @pdev: PCI device information struct +* fm10k_resume - Generic PM resume hook +* @dev: generic device structure * -* fm10k_resume is called after the system has powered back up from a sleep -* state and is ready to resume operation. This function is meant to restore -* the device back to its pre-sleep state. +* Generic PM hook used when waking the device from a low power state after +* suspend or hibernation. This function does not need to handle lower PCIe +* device state as the stack takes care of that for us. **/ -static int fm10k_resume (struct pci_dev *pdev) +static int fm10k_resume (struct device *dev) { -struct fm10k_intfc *interface =pci_get_drvdata (pdev); +struct fm10k_intfc *interface =pci_get_drvdata (to_pci_dev (dev));struct net_device *netdev = interface->netdev;struct fm10k_hw *hw = &interface->hw; -u32 err; - -pci_set_power_state (pdev,PCI_D0 ); -pci_restore_state (pdev); - -/* pci_restore_state clears dev->state_saved so call -* pci_save_state to restore it. -*/ -pci_save_state (pdev); - - err =pci_enable_device_mem (pdev); -if (err) { -dev_err (&pdev->dev,"Cannot enable PCI device from suspend\n" ); -return err; - } -pci_set_master (pdev); - -pci_wake_from_d3 (pdev, false); +int err;/* refresh hw_addr in case it was dropped */ hw->hw_addr = interface->uc_addr;
@@ -2308,36 +2291,27 @@ static int fm10k_resume(struct pci_dev *pdev) }/** -* fm10k_suspend - Prepare the device for a system sleep state -* @pdev: PCI device information struct +* fm10k_suspend - Generic PM suspend hook +* @dev: generic device structure * -* fm10k_suspend is meant to shutdown the device prior to the system entering -* a sleep state. The fm10k hardware does not support wake on lan so the -* driver simply needs to shut down the device so it is in a low power state. +* Generic PM hook used when setting the device into a low power state for +* system suspend or hibernation. This function does not need to handle lower +* PCIe device state as the stack takes care of that for us. **/ -static int fm10k_suspend (struct pci_dev *pdev, -pm_message_t __always_unused state) +static int fm10k_suspend (struct device *dev) { -struct fm10k_intfc *interface =pci_get_drvdata (pdev); +struct fm10k_intfc *interface =pci_get_drvdata (to_pci_dev (dev));struct net_device *netdev = interface->netdev; -int err =0 ;netif_device_detach (netdev);fm10k_prepare_suspend (interface); - err =pci_save_state (pdev); -if (err) -return err; - -pci_disable_device (pdev); -pci_wake_from_d3 (pdev, false); -pci_set_power_state (pdev, PCI_D3hot); -return 0 ; }#endif /* CONFIG_PM */ +/** * fm10k_io_error_detected - called when PCI error is detected * @pdev: Pointer to PCI device
@@ -2457,15 +2431,18 @@ static const struct pci_error_handlers fm10k_err_handler = { .reset_notify = fm10k_io_reset_notify, }; +static SIMPLE_DEV_PM_OPS(fm10k_pm_ops, fm10k_suspend, fm10k_resume); +static struct pci_driver fm10k_driver = { .name = fm10k_driver_name, .id_table = fm10k_pci_tbl, .probe = fm10k_probe, .remove = fm10k_remove, #ifdef CONFIG_PM - .suspend = fm10k_suspend, - .resume = fm10k_resume, -#endif + .driver = { + .pm = &fm10k_pm_ops, + }, +#endif /* CONFIG_PM */ .sriov_configure = fm10k_iov_configure, .err_handler = &fm10k_err_handler };
Signature · 1 line
2.13.0.615.gb09ed6e59a40
Singh
PATCH v3 13/16 fm10k: use generic PM hooks instead of legacy PCIe power hooks
Quoted 11 lines
-----Original Message-----
From: Intel-wired-lan [mailto:intel-wired-lan-bounces at osuosl.org] On Behalf Of Jacob Keller
Sent: Monday, July 10, 2017 1:23 PM
To: jtkirhse at osuosl.org; Intel Wired LAN <[email protected]>
Cc: jekeller at osuosl.org
Subject: [Intel-wired-lan] [PATCH v3 13/16] fm10k: use generic PM hooks instead of legacy PCIe power hooks
Quoted 8 lines
Replace the PCI specific legacy power management hooks with the new generic power management hooks which work properly for both suspend and hibernate. The new generic system is better and properly handles the lower level PCIe power management rather than forcing the driver to handle it.
Signed-off-by Jacob Keller <[email protected]>---
PATCH v3 14/16 fm10k: introduce a message queue for MAC/VLAN messages
In reply to Jacob KellerUnder some circumstances, when dealing with a large number of MAC address or VLAN updates at once, the fm10k driver, particularly the VFs can overload the mailbox with too many messages at once.
This results in a mailbox timeout, which causes the driver to initiate a reset. During the reset, we re-send all the same messages that originally caused the timeout. This results in a cycle of resets each triggering a future reset.
To fix or avoid this, we introduce a workqueue item which monitors a queue of MAC and VLAN requests. These requests are queued to the end of the list, and we process as a FIFO periodically.
Initially we only handle requests for the netdev, but we do handle unicast MAC addresses, multicast MAC addresses, and update VLAN requests.
A future patch will add support to use this queue for handling MAC update requests from the VF<->PF mailbox.
The MAC/VLAN work item will keep checking to make sure that each request does not overflow the mailbox and cause a timeout. If it might, then the work item will reschedule itself a short time later. This avoids any reset cycle, since we never send the message if the mailbox is not ready.
As an alternative, we tried increasing the mailbox message FIFO, but this just delays the problem and results in needless memory waste on the system. Our new message queue is dynamically allocated so only uses as much memory as it needs. Additionally, it need not be contiguous like the Tx and Rx FIFOs.
Note that this patch chose to only create a queue for MAC and VLAN messages, since these are the only messages sent in a large enough volume to cause the reset loop. Other messages are very unlikely to overflow the mailbox Tx fifo so easily.
--- drivers/net/ethernet/intel/fm10k/fm10k.h | 39 +++++ drivers/net/ethernet/intel/fm10k/fm10k_netdev.c | 199 ++++++++++++++++++----- drivers/net/ethernet/intel/fm10k/fm10k_pci.c | 201 ++++++++++++++++++++++++ 3 files changed, 397 insertions(+), 42 deletions(-)
drivers/net/ethernet/intel/fm10k/fm10k.h +39 -0
@@ -248,6 +248,29 @@ struct fm10k_udp_port {__be16 port; }; +enum fm10k_macvlan_request_type { +FM10K_UC_MAC_REQUEST , +FM10K_MC_MAC_REQUEST , +FM10K_VLAN_REQUEST +}; + +struct fm10k_macvlan_request { +enum fm10k_macvlan_request_type type; +struct list_head list; +union { +struct fm10k_mac_request { +u8 addr[ETH_ALEN ]; +u16 glort; +u16 vid; + } mac; +struct fm10k_vlan_request { +u32 vid; +u8 vsi; + } vlan; + }; +bool set; +}; +/* one work queue for entire driver */ extern struct workqueue_struct *fm10k_workqueue;
@@ -276,6 +299,9 @@ enum fm10k_state_t { __FM10K_SERVICE_SCHED, __FM10K_SERVICE_REQUEST, __FM10K_SERVICE_DISABLE, + __FM10K_MACVLAN_SCHED, + __FM10K_MACVLAN_REQUEST, + __FM10K_MACVLAN_DISABLE, __FM10K_LINK_DOWN, __FM10K_UPDATING_STATS, /* This value must be last and determines the BITMAP size */
@@ -368,6 +394,12 @@ struct fm10k_intfc {struct list_head vxlan_port;struct list_head geneve_port; +/* MAC/VLAN update queue */ +struct list_head macvlan_requests; +struct delayed_work macvlan_task; +/* MAC/VLAN update queue lock */ +spinlock_t macvlan_lock; +#ifdef CONFIG_DEBUG_FS struct dentry *dbg_intfc;#endif /* CONFIG_DEBUG_FS */
@@ -487,6 +519,7 @@ void fm10k_up(struct fm10k_intfc *interface);void fm10k_down (struct fm10k_intfc *interface);void fm10k_update_stats (struct fm10k_intfc *interface);void fm10k_service_event_schedule (struct fm10k_intfc *interface); +void fm10k_macvlan_schedule (struct fm10k_intfc *interface);void fm10k_update_rx_drop_en (struct fm10k_intfc *interface);#ifdef CONFIG_NET_POLL_CONTROLLER void fm10k_netpoll (struct net_device *netdev);
@@ -507,6 +540,12 @@ void fm10k_reset_rx_state(struct fm10k_intfc *);int fm10k_setup_tc (struct net_device *dev,u8 tc);int fm10k_open (struct net_device *netdev);int fm10k_close (struct net_device *netdev); +int fm10k_queue_vlan_request (struct fm10k_intfc *interface,u32 vid, +u8 vsi,bool set); +int fm10k_queue_mac_request (struct fm10k_intfc *interface,u16 glort, +const unsigned char *addr,u16 vid,bool set); +void fm10k_clear_macvlan_queue (struct fm10k_intfc *interface, +u16 glort,bool vlans);/* Ethtool */ void fm10k_set_ethtool_ops (struct net_device *dev);
drivers/net/ethernet/intel/fm10k/fm10k_netdev.c +157 -42
307 lines not on this page · raw message
drivers/net/ethernet/intel/fm10k/fm10k_pci.c +201 -0
260 lines not on this page · raw message
Signature · 1 line
2.13.0.615.gb09ed6e59a40
Singh
PATCH v3 14/16 fm10k: introduce a message queue for MAC/VLAN messages
Quoted 43 lines
-----Original Message-----
From: Intel-wired-lan [mailto:intel-wired-lan-bounces at osuosl.org] On Behalf Of Jacob Keller
Sent: Monday, July 10, 2017 1:23 PM
To: jtkirhse at osuosl.org; Intel Wired LAN <[email protected]>
Cc: jekeller at osuosl.org
Subject: [Intel-wired-lan] [PATCH v3 14/16] fm10k: introduce a message queue for MAC/VLAN messagesUnder some circumstances, when dealing with a large number of MAC address or VLAN updates at once, the fm10k driver, particularly the VFs can overload the mailbox with too many messages at once.
This results in a mailbox timeout, which causes the driver to initiate a reset. During the reset, we re-send all the same messages that originally caused the timeout. This results in a cycle of resets each triggering a future reset.
To fix or avoid this, we introduce a workqueue item which monitors a queue of MAC and VLAN requests. These requests are queued to the end of the list, and we process as a FIFO periodically.
Initially we only handle requests for the netdev, but we do handle unicast MAC addresses, multicast MAC addresses, and update VLAN requests.
A future patch will add support to use this queue for handling MAC update requests from the VF<->PF mailbox.
The MAC/VLAN work item will keep checking to make sure that each request does not overflow the mailbox and cause a timeout. If it might, then the work item will reschedule itself a short time later. This avoids any reset cycle, since we never send the message if the mailbox is not ready.
As an alternative, we tried increasing the mailbox message FIFO, but this just delays the problem and results in needless memory waste on the system. Our new message queue is dynamically allocated so only uses as much memory as it needs. Additionally, it need not be contiguous like the Tx and Rx FIFOs.
Quoted 7 lines
Note that this patch chose to only create a queue for MAC and VLAN messages, since these are the only messages sent in a large enough volume to cause the reset loop. Other messages are very unlikely to overflow the mailbox Tx fifo so easily.
Signed-off-by Jacob Keller <[email protected]>---
PATCH v3 15/16 fm10k: use the MAC/VLAN queue for VF<->PF MAC/VLAN requests
In reply to Jacob KellerNow that we have a working MAC/VLAN queue for handling MAC/VLAN messages from the netdev, replace the default handler for the VF<->PF messages. This new handler is very similar to the default code, but uses the MAC/VLAN queue instead of sending the message directly. Unfortunately we can't easily re-use the default code, so we'll just replace the entire function.
This ensures that a VF requesting a large number of VLANs or MAC addresses does not start a reset cycle, as explained in the commit which introduced the message queue.
--- drivers/net/ethernet/intel/fm10k/fm10k_iov.c | 132 ++++++++++++++++++++++++++- drivers/net/ethernet/intel/fm10k/fm10k_pf.c | 2 +- drivers/net/ethernet/intel/fm10k/fm10k_pf.h | 3 +- 3 files changed, 133 insertions(+), 4 deletions(-)
drivers/net/ethernet/intel/fm10k/fm10k_iov.c +130 -2
@@ -35,10 +35,133 @@ static s32 fm10k_iov_msg_error(struct fm10k_hw *hw, u32 **results,return fm10k_tlv_msg_error (hw, results, mbx); } +/** +* fm10k_iov_msg_queue_mac_vlan - Message handler for MAC/VLAN request from VF +* @hw: Pointer to hardware structure +* @results: Pointer array to message, results[0] is pointer to message +* @mbx: Pointer to mailbox information structure +* +* This function is a custom handler for MAC/VLAN requests from the VF. The +* assumption is that it is acceptable to directly hande off the message from +* the VF to the PF's switch manager. However, we use a MAC/VLAN message +* queue to avoid overloading the mailbox when a large number of requests +* come in. +**/ +static s32 fm10k_iov_msg_queue_mac_vlan (struct fm10k_hw *hw,u32 **results, +struct fm10k_mbx_info *mbx) +{ +struct fm10k_vf_info *vf_info = (struct fm10k_vf_info *)mbx; +struct fm10k_intfc *interface = hw->back; +u8 mac[ETH_ALEN ]; +u32 *result; +int err =0 ; +bool set; +u16 vlan; +u32 vid; + +/* we shouldn't be updating rules on a disabled interface */ +if (!FM10K_VF_FLAG_ENABLED (vf_info)) + err =FM10K_ERR_PARAM ; + +if (!err && !!results[FM10K_MAC_VLAN_MSG_VLAN ]) { + result = results[FM10K_MAC_VLAN_MSG_VLAN ]; + +/* record VLAN id requested */ + err =fm10k_tlv_attr_get_u32 (result, &vid); +if (err) +return err; + + set = !(vid &FM10K_VLAN_CLEAR ); + vid &= ~FM10K_VLAN_CLEAR ; + +/* if the length field has been set, this is a multi-bit +* update request. For multi-bit requests, simply disallow +* them when the pf_vid has been set. In this case, the PF +* should have already cleared the VLAN_TABLE, and if we +* allowed them, it could allow a rogue VF to receive traffic +* on a VLAN it was not assigned. In the single-bit case, we +* need to modify requests for VLAN 0 to use the default PF or +* SW vid when assigned. +*/ + +if (vid >>16 ) { +/* prevent multi-bit requests when PF has +* administratively set the VLAN for this VF +*/ +if (vf_info->pf_vid) +return FM10K_ERR_PARAM ; + }else { + err =fm10k_iov_select_vid (vf_info, (u16 )vid); +if (err <0 ) +return err; + + vid = err; + } + +/* update VSI info for VF in regards to VLAN table */ + err = hw->mac.ops.update_vlan (hw, vid, vf_info->vsi, set); + } + +if (!err && !!results[FM10K_MAC_VLAN_MSG_MAC ]) { + result = results[FM10K_MAC_VLAN_MSG_MAC ]; + +/* record unicast MAC address requested */ + err =fm10k_tlv_attr_get_mac_vlan (result, mac, &vlan); +if (err) +return err; + +/* block attempts to set MAC for a locked device */ +if (is_valid_ether_addr (vf_info->mac) && + !ether_addr_equal (mac, vf_info->mac)) +return FM10K_ERR_PARAM ; + + set = !(vlan &FM10K_VLAN_CLEAR ); + vlan &= ~FM10K_VLAN_CLEAR ; + + err =fm10k_iov_select_vid (vf_info, vlan); +if (err <0 ) +return err; + + vlan = (u16 )err; + +/* Add this request to the MAC/VLAN queue */ + err =fm10k_queue_mac_request (interface, vf_info->glort, + mac, vlan, set); + } + +if (!err && !!results[FM10K_MAC_VLAN_MSG_MULTICAST ]) { + result = results[FM10K_MAC_VLAN_MSG_MULTICAST ]; + +/* record multicast MAC address requested */ + err =fm10k_tlv_attr_get_mac_vlan (result, mac, &vlan); +if (err) +return err; + +/* verify that the VF is allowed to request multicast */ +if (!(vf_info->vf_flags &FM10K_VF_FLAG_MULTI_ENABLED )) +return FM10K_ERR_PARAM ; + + set = !(vlan &FM10K_VLAN_CLEAR ); + vlan &= ~FM10K_VLAN_CLEAR ; + + err =fm10k_iov_select_vid (vf_info, vlan); +if (err <0 ) +return err; + + vlan = (u16 )err; + +/* Add this request to the MAC/VLAN queue */ + err =fm10k_queue_mac_request (interface, vf_info->glort, + mac, vlan, set); + } + +return err; +} +static const struct fm10k_msg_data iov_mbx_data[] = {FM10K_TLV_MSG_TEST_HANDLER (fm10k_tlv_msg_test),FM10K_VF_MSG_MSIX_HANDLER (fm10k_iov_msg_msix_pf), -FM10K_VF_MSG_MAC_VLAN_HANDLER (fm10k_iov_msg_mac_vlan_pf), +FM10K_VF_MSG_MAC_VLAN_HANDLER (fm10k_iov_msg_queue_mac_vlan),FM10K_VF_MSG_LPORT_STATE_HANDLER (fm10k_iov_msg_lport_state_pf),FM10K_TLV_MSG_ERROR_HANDLER (fm10k_iov_msg_error), };
@@ -126,8 +249,10 @@ s32 fm10k_iov_mbx(struct fm10k_intfc *interface) hw->mbx.ops.process (hw, &hw->mbx);/* verify port mapping is valid, if not reset port */ -if (vf_info->vf_flags && !fm10k_glort_valid_pf (hw, glort)) +if (vf_info->vf_flags && !fm10k_glort_valid_pf (hw, glort)) { hw->iov.ops.reset_lport (hw, vf_info); +fm10k_clear_macvlan_queue (interface, glort, false); + }/* reset VFs that have mailbox timed out */ if (!mbx->timeout) {
@@ -190,6 +315,7 @@ void fm10k_iov_suspend(struct pci_dev *pdev) hw->iov.ops.reset_resources (hw, vf_info); hw->iov.ops.reset_lport (hw, vf_info); +fm10k_clear_macvlan_queue (interface, vf_info->glort, false); } }
@@ -414,6 +540,8 @@ static inline void fm10k_reset_vf_info(struct fm10k_intfc *interface,/* disable LPORT for this VF which clears switch rules */ hw->iov.ops.reset_lport (hw, vf_info); +fm10k_clear_macvlan_queue (interface, vf_info->glort, false); +/* assign new MAC+VLAN for this VF */ hw->iov.ops.assign_default_mac_vlan (hw, vf_info);
drivers/net/ethernet/intel/fm10k/fm10k_pf.c +1 -1
@@ -1186,7 +1186,7 @@ s32 fm10k_iov_msg_msix_pf(struct fm10k_hw *hw, u32 **results,* Will report an error if the VLAN ID is out of range. For VID = 0, it will * return either the pf_vid or sw_vid depending on which one is set. */ -static s32 fm10k_iov_select_vid (struct fm10k_vf_info *vf_info,u16 vid) +s32 fm10k_iov_select_vid (struct fm10k_vf_info *vf_info,u16 vid) {if (!vid)return vf_info->pf_vid ? vf_info->pf_vid : vf_info->sw_vid;
drivers/net/ethernet/intel/fm10k/fm10k_pf.h +2 -1
@@ -1,5 +1,5 @@/* Intel(R) Ethernet Switch Host Interface Driver -* Copyright(c) 2013 - 2016 Intel Corporation. +* Copyright(c) 2013 - 2017 Intel Corporation. * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License,
@@ -114,6 +114,7 @@ extern const struct fm10k_tlv_attr fm10k_err_msg_attr[];#define FM10K_PF_MSG_ERR_HANDLER (msg, func) \ FM10K_MSG_HANDLER(FM10K_PF_MSG_ID_##msg, fm10k_err_msg_attr, func) +s32 fm10k_iov_select_vid (struct fm10k_vf_info *vf_info,u16 vid);s32 fm10k_iov_msg_msix_pf (struct fm10k_hw *,u32 **,struct fm10k_mbx_info *);s32 fm10k_iov_msg_mac_vlan_pf (struct fm10k_hw *,u32 **,struct fm10k_mbx_info *);
Signature · 1 line
2.13.0.615.gb09ed6e59a40
Singh
PATCH v3 15/16 fm10k: use the MAC/VLAN queue for VF<->PF MAC/VLAN requests
Quoted 19 lines
-----Original Message-----
From: Intel-wired-lan [mailto:intel-wired-lan-bounces at osuosl.org] On Behalf Of Jacob Keller
Sent: Monday, July 10, 2017 1:23 PM
To: jtkirhse at osuosl.org; Intel Wired LAN <[email protected]>
Cc: jekeller at osuosl.org
Subject: [Intel-wired-lan] [PATCH v3 15/16] fm10k: use the MAC/VLAN queue for VF<->PF MAC/VLAN requestsNow that we have a working MAC/VLAN queue for handling MAC/VLAN messages
from the netdev, replace the default handler for the VF<->PF messages. This new handler is very similar to the default code, but uses the MAC/VLAN queue instead of sending the message directly. Unfortunately we can't easily re-use the default code, so we'll just replace the entire function.
Quoted 7 lines
This ensures that a VF requesting a large number of VLANs or MAC addresses does not start a reset cycle, as explained in the commit which introduced the message queue.
Signed-off-by Jacob Keller <[email protected]>Reviewed-by Kwan, Ngai-mint <[email protected]>---
PATCH v3 16/16 fm10k: bump version number
In reply to Jacob Keller--- drivers/net/ethernet/intel/fm10k/fm10k_main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/intel/fm10k/fm10k_main.c +1 -1
@@ -28,7 +28,7 @@#include "fm10k.h" -#define DRV_VERSION "0.21.7-k" +#define DRV_VERSION "0.22.1-k"#define DRV_SUMMARY "Intel(R) Ethernet Switch Host Interface Driver"const char fm10k_driver_version[] =DRV_VERSION ;char fm10k_driver_name[] ="fm10k" ;
Signature · 1 line
2.13.0.615.gb09ed6e59a40
Singh
PATCH v3 16/16 fm10k: bump version number
Quoted 10 lines
-----Original Message-----
From: Intel-wired-lan [mailto:intel-wired-lan-bounces at osuosl.org] On Behalf Of Jacob Keller
Sent: Monday, July 10, 2017 1:23 PM
To: jtkirhse at osuosl.org; Intel Wired LAN <[email protected]>
Cc: jekeller at osuosl.org
Subject: [Intel-wired-lan] [PATCH v3 16/16] fm10k: bump version number
Quoted 2 lines
Signed-off-by Jacob Keller <[email protected]>---
Singh
PATCH v3 1/16 fm10k: stop spurious link down messages when Tx FIFO is full
In reply to Jacob KellerQuoted 22 lines
-----Original Message-----
From: Intel-wired-lan [mailto:intel-wired-lan-bounces at osuosl.org] On Behalf Of Jacob Keller
Sent: Monday, July 10, 2017 1:23 PM
To: jtkirhse at osuosl.org; Intel Wired LAN <[email protected]>
Cc: jekeller at osuosl.org
Subject: [Intel-wired-lan] [PATCH v3 01/16] fm10k: stop spurious link down messages when Tx FIFO is fullIn
fm10k_get_host_state_generic, we check the mailboxtx_read()function to ensure that the mailbox is still open. This function also checks to make sure we have space to transmit another message. Unfortunately, if we just recently sent a bunch of messages (such as enabling hundreds of VLANs on a VF) this can result in a race where the watchdog task thinks the link went down just because we haven't had time to process all these messages yet.Instead, lets just check whether the mailbox is still open. This ensures that we don't race with the Tx fifo, and we only link down once the mailbox is not open.
Quoted 8 lines
This is safe, because if the FIFO fills up and we're unable to send a message for too long, we'll end up triggering the timeout detection which results in a reset. Additionally, since we still check to ensure the mailbox state is OPEN, we'll transition to link down whenever the mailbox closes as well.
Signed-off-by Jacob Keller <[email protected]>---