On 03/03/20(Tue) 11:37, Martin Pieuchot wrote:
> Currently em_hw_init() uses some hardcorded values to configure TX
> rings.  Diff below convert it to use the value of the first queue.
> This is currently a no-op.  It makes the code consistent with the
> rest of the driver and reduce the size of upcoming diffs.
> 
> Note that even if a single queue is currently used two of them are
> setup.  Document this has an historical behavior and keep it like it
> is, there's not much need to introduce regression here :)

Updated diff that includes a chunk I missed in previous spotted by
jmatthew@.

ok?

Index: dev/pci/if_em.c
===================================================================
RCS file: /cvs/src/sys/dev/pci/if_em.c,v
retrieving revision 1.346
diff -u -p -r1.346 if_em.c
--- dev/pci/if_em.c     3 Mar 2020 10:43:29 -0000       1.346
+++ dev/pci/if_em.c     4 Mar 2020 17:08:18 -0000
@@ -1883,7 +1883,7 @@ em_hardware_init(struct em_softc *sc)
 
        em_disable_aspm(sc);
 
-       if ((ret_val = em_init_hw(&sc->hw)) != 0) {
+       if ((ret_val = em_init_hw(sc)) != 0) {
                if (ret_val == E1000_DEFER_INIT) {
                        INIT_DEBUGOUT("\nHardware Initialization Deferred ");
                        return (EAGAIN);
Index: dev/pci/if_em_hw.c
===================================================================
RCS file: /cvs/src/sys/dev/pci/if_em_hw.c,v
retrieving revision 1.106
diff -u -p -r1.106 if_em_hw.c
--- dev/pci/if_em_hw.c  4 Feb 2020 10:59:23 -0000       1.106
+++ dev/pci/if_em_hw.c  4 Mar 2020 17:09:31 -0000
@@ -56,6 +56,7 @@
 #include <dev/pci/pcireg.h>
 #include <dev/pci/pcivar.h>
 
+#include <dev/pci/if_em.h>
 #include <dev/pci/if_em_hw.h>
 #include <dev/pci/if_em_soc.h>
 
@@ -92,7 +93,7 @@ static int32_t        em_init_lcd_from_nvm_conf
 static int32_t em_init_lcd_from_nvm(struct em_hw *);
 static int32_t em_phy_no_cable_workaround(struct em_hw *);
 static void    em_init_rx_addrs(struct em_hw *);
-static void    em_initialize_hardware_bits(struct em_hw *);
+static void    em_initialize_hardware_bits(struct em_softc *);
 static void    em_toggle_lanphypc_pch_lpt(struct em_hw *);
 static int     em_disable_ulp_lpt_lp(struct em_hw *hw, bool force);
 static boolean_t em_is_onboard_nvm_eeprom(struct em_hw *);
@@ -712,6 +713,7 @@ em_set_mac_type(struct em_hw *hw)
 
        return E1000_SUCCESS;
 }
+
 /*****************************************************************************
  * Set media type and TBI compatibility.
  *
@@ -1115,8 +1117,11 @@ em_reset_hw(struct em_hw *hw)
  *
  *****************************************************************************/
 STATIC void
-em_initialize_hardware_bits(struct em_hw *hw)
+em_initialize_hardware_bits(struct em_softc *sc)
 {
+       struct em_hw *hw = &sc->hw;
+       struct em_queue *que = sc->queues; /* Use only first queue. */
+
        DEBUGFUNC("em_initialize_hardware_bits");
 
        if ((hw->mac_type >= em_82571) && (!hw->initialize_hw_bits_disable)) {
@@ -1124,18 +1129,24 @@ em_initialize_hardware_bits(struct em_hw
                uint32_t reg_ctrl, reg_ctrl_ext;
                uint32_t reg_tarc0, reg_tarc1;
                uint32_t reg_tctl;
-               uint32_t reg_txdctl, reg_txdctl1;
+               uint32_t reg_txdctl;
                reg_tarc0 = E1000_READ_REG(hw, TARC0);
                reg_tarc0 &= ~0x78000000;       /* Clear bits 30, 29, 28, and
                                                 * 27 */
 
-               reg_txdctl = E1000_READ_REG(hw, TXDCTL(0));
+               reg_txdctl = E1000_READ_REG(hw, TXDCTL(que->me));
                reg_txdctl |= E1000_TXDCTL_COUNT_DESC;  /* Set bit 22 */
-               E1000_WRITE_REG(hw, TXDCTL(0), reg_txdctl);
+               E1000_WRITE_REG(hw, TXDCTL(que->me), reg_txdctl);
 
-               reg_txdctl1 = E1000_READ_REG(hw, TXDCTL(1));
-               reg_txdctl1 |= E1000_TXDCTL_COUNT_DESC; /* Set bit 22 */
-               E1000_WRITE_REG(hw, TXDCTL(1), reg_txdctl1);
+               /*
+                * Old code always initialized queue 1,
+                * even when unused, keep behaviour
+                */
+               if (sc->num_queues == 1) {
+                       reg_txdctl = E1000_READ_REG(hw, TXDCTL(1));
+                       reg_txdctl |= E1000_TXDCTL_COUNT_DESC;
+                       E1000_WRITE_REG(hw, TXDCTL(1), reg_txdctl);
+               }
 
                switch (hw->mac_type) {
                case em_82571:
@@ -1430,8 +1441,10 @@ out:
  * the transmit and receive units disabled and uninitialized.
  *****************************************************************************/
 int32_t
-em_init_hw(struct em_hw *hw)
+em_init_hw(struct em_softc *sc)
 {
+       struct em_hw *hw = &sc->hw;
+       struct em_queue *que = sc->queues; /* Use only first queue. */
        uint32_t ctrl;
        uint32_t i;
        int32_t  ret_val;
@@ -1513,7 +1526,7 @@ em_init_hw(struct em_hw *hw)
        /* Magic delay that improves problems with i219LM on HP Elitebook */
        msec_delay(1);
        /* Must be called after em_set_media_type because media_type is used */
-       em_initialize_hardware_bits(hw);
+       em_initialize_hardware_bits(sc);
 
        /* Disabling VLAN filtering. */
        DEBUGOUT("Initializing the IEEE VLAN\n");
@@ -1626,10 +1639,10 @@ em_init_hw(struct em_hw *hw)
 
        /* Set the transmit descriptor write-back policy */
        if (hw->mac_type > em_82544) {
-               ctrl = E1000_READ_REG(hw, TXDCTL(0));
+               ctrl = E1000_READ_REG(hw, TXDCTL(que->me));
                ctrl = (ctrl & ~E1000_TXDCTL_WTHRESH) | 
                    E1000_TXDCTL_FULL_TX_DESC_WB;
-               E1000_WRITE_REG(hw, TXDCTL(0), ctrl);
+               E1000_WRITE_REG(hw, TXDCTL(que->me), ctrl);
        }
        if ((hw->mac_type == em_82573) || (hw->mac_type == em_82574)) {
                em_enable_tx_pkt_filtering(hw);
@@ -1674,10 +1687,16 @@ em_init_hw(struct em_hw *hw)
        case em_pch_lpt:
        case em_pch_spt:
        case em_pch_cnp:
-               ctrl = E1000_READ_REG(hw, TXDCTL(1));
-               ctrl = (ctrl & ~E1000_TXDCTL_WTHRESH) | 
-                   E1000_TXDCTL_FULL_TX_DESC_WB;
-               E1000_WRITE_REG(hw, TXDCTL(1), ctrl);
+               /*
+                * Old code always initialized queue 1,
+                * even when unused, keep behaviour
+                */
+               if (sc->num_queues == 1) {
+                       ctrl = E1000_READ_REG(hw, TXDCTL(1));
+                       ctrl = (ctrl & ~E1000_TXDCTL_WTHRESH) | 
+                           E1000_TXDCTL_FULL_TX_DESC_WB;
+                       E1000_WRITE_REG(hw, TXDCTL(1), ctrl);
+               }
                break;
        }
 
Index: dev/pci/if_em_hw.h
===================================================================
RCS file: /cvs/src/sys/dev/pci/if_em_hw.h,v
retrieving revision 1.80
diff -u -p -r1.80 if_em_hw.h
--- dev/pci/if_em_hw.h  4 Feb 2020 10:59:23 -0000       1.80
+++ dev/pci/if_em_hw.h  4 Mar 2020 17:08:18 -0000
@@ -336,9 +336,11 @@ typedef enum {
 
 /* Function prototypes */
 /* Initialization */
+struct em_softc;
 int32_t em_reset_hw(struct em_hw *hw);
-int32_t em_init_hw(struct em_hw *hw);
+int32_t em_init_hw(struct em_softc *sc);
 int32_t em_set_mac_type(struct em_hw *hw);
+int em_max_queues(struct em_hw *hw);
 void em_set_media_type(struct em_hw *hw);
 
 /* Link Configuration */

Reply via email to