Re: Patch to support AR816x/AR817x chipsets in alc(4)

2018-12-03 Thread Genadijus Paleckis
Ping?

Could anyone give more feedback on this one?

Im running this patch for around 2 minths without issues on my laptop
with E2400 chipset.

I understand that this is quite big change and also it might be that
no one has supported card for this driver. Or perhaps because of the
driver being for unawanted vendor (Atheros) Is there any other reason
for this not to be added to the driver?

I'd also appreciate any feedback if I messed that up.

Thanks

On Wed, Nov 14, 2018 at 09:20:38PM +, Genadijus Paleckis wrote:
> Hi all,
> 
> I'm piggybacking on post from Jason Hunt
> https://marc.info/?l=openbsd-tech&m=146881042926430&w=2
> 
> Please find attached diff for alc(4) synced with FreeBSD alc(4).
> 
> In addition to original diff this one adds support to E2200, E2400
> and E2500 cards made by Attansic. I am running it for more than a month
> with E2400 model I have in my laptop without any issues.
> 
> I sent patch to kevlo@ who was very helpful with the feedback. I made all
> requested modifications.
> 
> If that's OK would be great to have it merged.
> 
> 
> $ dmesg | grep alc
> alc0 at pci5 dev 0 function 0 "Attansic Technology Killer E2400 Gigabit
> Ethernet" rev 0x10: msi, address d4:81:d7:8a:01:27
> atphy0 at alc0 phy 0: AR8035 10/100/1000 PHY, rev. 9
> 
> 
> Index: sys/dev/pci/if_alc.c
> ===
> RCS file: /cvs/src/sys/dev/pci/if_alc.c,v
> retrieving revision 1.42
> diff -u -p -r1.42 if_alc.c
> --- sys/dev/pci/if_alc.c  8 Sep 2017 05:36:52 -   1.42
> +++ sys/dev/pci/if_alc.c  14 Nov 2018 21:00:34 -
> @@ -26,7 +26,7 @@
>   * SUCH DAMAGE.
>   */
>  
> -/* Driver for Atheros AR8131/AR8132 PCIe Ethernet. */
> +/* Driver for Atheros AR813x/AR815x/AR816x/AR817x PCIe Ethernet. */
>  
>  #include "bpfilter.h"
>  #include "vlan.h"
> @@ -76,12 +76,17 @@ void  alc_watchdog(struct ifnet *);
>  int  alc_mediachange(struct ifnet *);
>  void alc_mediastatus(struct ifnet *, struct ifmediareq *);
>  
> -void alc_aspm(struct alc_softc *, uint64_t);
> +void alc_aspm(struct alc_softc *, int, uint64_t);
> +void alc_aspm_813x(struct alc_softc *, uint64_t);
> +void alc_aspm_816x(struct alc_softc *, int);
>  void alc_disable_l0s_l1(struct alc_softc *);
>  int  alc_dma_alloc(struct alc_softc *);
>  void alc_dma_free(struct alc_softc *);
>  int  alc_encap(struct alc_softc *, struct mbuf *);
>  void alc_get_macaddr(struct alc_softc *);
> +void alc_get_macaddr_813x(struct alc_softc *);
> +void alc_get_macaddr_816x(struct alc_softc *);
> +void alc_get_macaddr_par(struct alc_softc *);
>  void alc_init_cmb(struct alc_softc *);
>  void alc_init_rr_ring(struct alc_softc *);
>  int  alc_init_rx_ring(struct alc_softc *);
> @@ -89,9 +94,23 @@ void   alc_init_smb(struct alc_softc *);
>  void alc_init_tx_ring(struct alc_softc *);
>  int  alc_intr(void *);
>  void alc_mac_config(struct alc_softc *);
> +uint32_t alc_mii_readreg_813x(struct alc_softc *, int, int);
> +uint32_t alc_mii_readreg_816x(struct alc_softc *, int, int);
> +uint32_t alc_mii_writereg_813x(struct alc_softc *, int, int, int);
> +uint32_t alc_mii_writereg_816x(struct alc_softc *, int, int, int);
> +void alc_dsp_fixup(struct alc_softc *, int);
>  int  alc_miibus_readreg(struct device *, int, int);
>  void alc_miibus_statchg(struct device *);
> +int  alc_miibus_writeregr(struct device *, int, int, int);
>  void alc_miibus_writereg(struct device *, int, int, int);
> +uint32_t alc_miidbg_readreg(struct alc_softc *, int);
> +uint32_t alc_miidbg_writereg(struct alc_softc *, int, int);
> +uint32_t alc_miiext_readreg(struct alc_softc *, int, int);
> +uint32_t alc_miiext_writereg(struct alc_softc *, int, int, int);
> +void alc_phy_reset_813x(struct alc_softc *);
> +void alc_phy_reset_816x(struct alc_softc *);
> +void alc_setwol_813x(struct alc_softc *);
> +void alc_setwol_816x(struct alc_softc *);
>  int  alc_newbuf(struct alc_softc *, struct alc_rxdesc *);
>  void alc_phy_down(struct alc_softc *);
>  void alc_phy_reset(struct alc_softc *);
> @@ -108,6 +127,12 @@ void alc_stop_mac(struct alc_softc *);
>  void alc_stop_queue(struct alc_softc *);
>  void alc_tick(void *);
>  void alc_txeof(struct alc_softc *);
> +void alc_init_pcie(struct alc_softc *, int);
> +void alc_config_msi(struct alc_softc *);
> +int  alc_dma_alloc(struct alc_softc *);
> +void alc_dma_free(struct alc_softc *);
> +int  alc_encap(struct alc_softc *, struct mbuf *);
> +void alc_osc_reset(struct alc_softc *);
>  
>  uint32_t alc_dma_burst[] = { 128, 256, 512, 1024, 2048, 4096, 0 };
>  
> @@ -117,11 +142,18 @@ const struct pci_matchid alc_devices[] =
>   { PCI_VENDOR_ATTANSIC, PCI_PRODUCT_ATTANSIC_L1D },
>   { PCI_VENDOR_ATTANSIC, PCI_PRODUCT_ATTANSIC_L1D_1 },
>   { PCI_VENDOR_ATTANSIC, PCI_PRODUCT_ATTANSIC_L2C_1 },
> - { PCI_VENDOR_ATTANSIC, PCI_PRODUCT_ATTANSIC_L2C_2 }
> + { PCI_VENDOR_ATTANSIC, PCI_PRODUCT_ATTANSIC_L2C_2 },
> + { PCI_VENDOR_ATTANSIC, PCI_PRODUCT

Patch to support AR816x/AR817x chipsets in alc(4)

2018-11-14 Thread Genadijus Paleckis
Hi all,

I'm piggybacking on post from Jason Hunt
https://marc.info/?l=openbsd-tech&m=146881042926430&w=2

Please find attached diff for alc(4) synced with FreeBSD alc(4).

In addition to original diff this one adds support to E2200, E2400
and E2500 cards made by Attansic. I am running it for more than a month
with E2400 model I have in my laptop without any issues.

I sent patch to kevlo@ who was very helpful with the feedback. I made all
requested modifications.

If that's OK would be great to have it merged.


$ dmesg | grep alc
alc0 at pci5 dev 0 function 0 "Attansic Technology Killer E2400 Gigabit
Ethernet" rev 0x10: msi, address d4:81:d7:8a:01:27
atphy0 at alc0 phy 0: AR8035 10/100/1000 PHY, rev. 9


Index: sys/dev/pci/if_alc.c
===
RCS file: /cvs/src/sys/dev/pci/if_alc.c,v
retrieving revision 1.42
diff -u -p -r1.42 if_alc.c
--- sys/dev/pci/if_alc.c8 Sep 2017 05:36:52 -   1.42
+++ sys/dev/pci/if_alc.c14 Nov 2018 21:00:34 -
@@ -26,7 +26,7 @@
  * SUCH DAMAGE.
  */
 
-/* Driver for Atheros AR8131/AR8132 PCIe Ethernet. */
+/* Driver for Atheros AR813x/AR815x/AR816x/AR817x PCIe Ethernet. */
 
 #include "bpfilter.h"
 #include "vlan.h"
@@ -76,12 +76,17 @@ voidalc_watchdog(struct ifnet *);
 intalc_mediachange(struct ifnet *);
 void   alc_mediastatus(struct ifnet *, struct ifmediareq *);
 
-void   alc_aspm(struct alc_softc *, uint64_t);
+void   alc_aspm(struct alc_softc *, int, uint64_t);
+void   alc_aspm_813x(struct alc_softc *, uint64_t);
+void   alc_aspm_816x(struct alc_softc *, int);
 void   alc_disable_l0s_l1(struct alc_softc *);
 intalc_dma_alloc(struct alc_softc *);
 void   alc_dma_free(struct alc_softc *);
 intalc_encap(struct alc_softc *, struct mbuf *);
 void   alc_get_macaddr(struct alc_softc *);
+void   alc_get_macaddr_813x(struct alc_softc *);
+void   alc_get_macaddr_816x(struct alc_softc *);
+void   alc_get_macaddr_par(struct alc_softc *);
 void   alc_init_cmb(struct alc_softc *);
 void   alc_init_rr_ring(struct alc_softc *);
 intalc_init_rx_ring(struct alc_softc *);
@@ -89,9 +94,23 @@ void alc_init_smb(struct alc_softc *);
 void   alc_init_tx_ring(struct alc_softc *);
 intalc_intr(void *);
 void   alc_mac_config(struct alc_softc *);
+uint32_t   alc_mii_readreg_813x(struct alc_softc *, int, int);
+uint32_t   alc_mii_readreg_816x(struct alc_softc *, int, int);
+uint32_t   alc_mii_writereg_813x(struct alc_softc *, int, int, int);
+uint32_t   alc_mii_writereg_816x(struct alc_softc *, int, int, int);
+void   alc_dsp_fixup(struct alc_softc *, int);
 intalc_miibus_readreg(struct device *, int, int);
 void   alc_miibus_statchg(struct device *);
+intalc_miibus_writeregr(struct device *, int, int, int);
 void   alc_miibus_writereg(struct device *, int, int, int);
+uint32_t   alc_miidbg_readreg(struct alc_softc *, int);
+uint32_t   alc_miidbg_writereg(struct alc_softc *, int, int);
+uint32_t   alc_miiext_readreg(struct alc_softc *, int, int);
+uint32_t   alc_miiext_writereg(struct alc_softc *, int, int, int);
+void   alc_phy_reset_813x(struct alc_softc *);
+void   alc_phy_reset_816x(struct alc_softc *);
+void   alc_setwol_813x(struct alc_softc *);
+void   alc_setwol_816x(struct alc_softc *);
 intalc_newbuf(struct alc_softc *, struct alc_rxdesc *);
 void   alc_phy_down(struct alc_softc *);
 void   alc_phy_reset(struct alc_softc *);
@@ -108,6 +127,12 @@ void   alc_stop_mac(struct alc_softc *);
 void   alc_stop_queue(struct alc_softc *);
 void   alc_tick(void *);
 void   alc_txeof(struct alc_softc *);
+void   alc_init_pcie(struct alc_softc *, int);
+void   alc_config_msi(struct alc_softc *);
+intalc_dma_alloc(struct alc_softc *);
+void   alc_dma_free(struct alc_softc *);
+intalc_encap(struct alc_softc *, struct mbuf *);
+void   alc_osc_reset(struct alc_softc *);
 
 uint32_t alc_dma_burst[] = { 128, 256, 512, 1024, 2048, 4096, 0 };
 
@@ -117,11 +142,18 @@ const struct pci_matchid alc_devices[] =
{ PCI_VENDOR_ATTANSIC, PCI_PRODUCT_ATTANSIC_L1D },
{ PCI_VENDOR_ATTANSIC, PCI_PRODUCT_ATTANSIC_L1D_1 },
{ PCI_VENDOR_ATTANSIC, PCI_PRODUCT_ATTANSIC_L2C_1 },
-   { PCI_VENDOR_ATTANSIC, PCI_PRODUCT_ATTANSIC_L2C_2 }
+   { PCI_VENDOR_ATTANSIC, PCI_PRODUCT_ATTANSIC_L2C_2 },
+   { PCI_VENDOR_ATTANSIC, PCI_PRODUCT_ATTANSIC_AR8161 },
+   { PCI_VENDOR_ATTANSIC, PCI_PRODUCT_ATTANSIC_AR8162 },
+   { PCI_VENDOR_ATTANSIC, PCI_PRODUCT_ATTANSIC_AR8171 },
+   { PCI_VENDOR_ATTANSIC, PCI_PRODUCT_ATTANSIC_AR8172 },
+   { PCI_VENDOR_ATTANSIC, PCI_PRODUCT_ATTANSIC_E2200 },
+   { PCI_VENDOR_ATTANSIC, PCI_PRODUCT_ATTANSIC_E2400 },
+   { PCI_VENDOR_ATTANSIC, PCI_PRODUCT_ATTANSIC_E2500 }
 };
 
 struct cfattach alc_ca = {
-   sizeof (struct alc_softc), alc_match, alc_attach, NULL,
+   sizeof (struct alc_softc), alc_match, alc_attach, alc_detach,
alc_activate
 };
 
@@ -138,6 +170,22 @@ int
 alc_mii

Patch to support AR816x/AR817x chipsets in alc(4)

2018-11-03 Thread Genadijus Paleckis
Hi all,

I'm piggybacking on post from Jason Hunt
https://marc.info/?l=openbsd-tech&m=146881042926430&w=2

Please find attached diff for alc(4) synced with FreeBSD alc(4).

In addition to original diff this one adds support to E2200, E2400
and E2500 cards made by Attansic. I am running it for around a month
with E2400 model I have in my laptop without any issues.

If that's OK, would be great to have it merged.


$ dmesg | grep alc
alc0 at pci5 dev 0 function 0 "Attansic Technology Killer E2400 Gigabit
Ethernet" rev 0x10: msi, address d4:81:d7:8a:01:27
atphy0 at alc0 phy 0: AR8035 10/100/1000 PHY, rev. 9

diff --git a/sys/dev/pci/if_alc.c b/sys/dev/pci/if_alc.c
index 7b5e628ef..958146053 100644
--- a/sys/dev/pci/if_alc.c
+++ b/sys/dev/pci/if_alc.c
@@ -26,7 +26,7 @@
  * SUCH DAMAGE.
  */
 
-/* Driver for Atheros AR8131/AR8132 PCIe Ethernet. */
+/* Driver for Atheros AR813x/AR815x/AR816x/AR817x PCIe Ethernet. */
 
 #include "bpfilter.h"
 #include "vlan.h"
@@ -76,12 +76,17 @@ voidalc_watchdog(struct ifnet *);
 intalc_mediachange(struct ifnet *);
 void   alc_mediastatus(struct ifnet *, struct ifmediareq *);
 
-void   alc_aspm(struct alc_softc *, uint64_t);
+void   alc_aspm(struct alc_softc *, int, uint64_t);
+void   alc_aspm_813x(struct alc_softc *, uint64_t);
+void   alc_aspm_816x(struct alc_softc *, int);
 void   alc_disable_l0s_l1(struct alc_softc *);
 intalc_dma_alloc(struct alc_softc *);
 void   alc_dma_free(struct alc_softc *);
 intalc_encap(struct alc_softc *, struct mbuf *);
 void   alc_get_macaddr(struct alc_softc *);
+void   alc_get_macaddr_813x(struct alc_softc *);
+void   alc_get_macaddr_816x(struct alc_softc *);
+void   alc_get_macaddr_par(struct alc_softc *);
 void   alc_init_cmb(struct alc_softc *);
 void   alc_init_rr_ring(struct alc_softc *);
 intalc_init_rx_ring(struct alc_softc *);
@@ -89,9 +94,23 @@ void alc_init_smb(struct alc_softc *);
 void   alc_init_tx_ring(struct alc_softc *);
 intalc_intr(void *);
 void   alc_mac_config(struct alc_softc *);
+uint32_t   alc_mii_readreg_813x(struct alc_softc *, int, int);
+uint32_t   alc_mii_readreg_816x(struct alc_softc *, int, int);
+uint32_t   alc_mii_writereg_813x(struct alc_softc *, int, int, int);
+uint32_t   alc_mii_writereg_816x(struct alc_softc *, int, int, int);
+void   alc_dsp_fixup(struct alc_softc *, int);
 intalc_miibus_readreg(struct device *, int, int);
 void   alc_miibus_statchg(struct device *);
+intalc_miibus_writeregr(struct device *, int, int, int);
 void   alc_miibus_writereg(struct device *, int, int, int);
+uint32_t   alc_miidbg_readreg(struct alc_softc *, int);
+uint32_t   alc_miidbg_writereg(struct alc_softc *, int, int);
+uint32_t   alc_miiext_readreg(struct alc_softc *, int, int);
+uint32_t   alc_miiext_writereg(struct alc_softc *, int, int, int);
+void   alc_phy_reset_813x(struct alc_softc *);
+void   alc_phy_reset_816x(struct alc_softc *);
+void   alc_setwol_813x(struct alc_softc *);
+void   alc_setwol_816x(struct alc_softc *);
 intalc_newbuf(struct alc_softc *, struct alc_rxdesc *);
 void   alc_phy_down(struct alc_softc *);
 void   alc_phy_reset(struct alc_softc *);
@@ -108,6 +127,12 @@ void   alc_stop_mac(struct alc_softc *);
 void   alc_stop_queue(struct alc_softc *);
 void   alc_tick(void *);
 void   alc_txeof(struct alc_softc *);
+void   alc_init_pcie(struct alc_softc *, int);
+void   alc_config_msi(struct alc_softc *);
+intalc_dma_alloc(struct alc_softc *);
+void   alc_dma_free(struct alc_softc *);
+intalc_encap(struct alc_softc *, struct mbuf *);
+void   alc_osc_reset(struct alc_softc *);
 
 uint32_t alc_dma_burst[] = { 128, 256, 512, 1024, 2048, 4096, 0 };
 
@@ -117,11 +142,18 @@ const struct pci_matchid alc_devices[] = {
{ PCI_VENDOR_ATTANSIC, PCI_PRODUCT_ATTANSIC_L1D },
{ PCI_VENDOR_ATTANSIC, PCI_PRODUCT_ATTANSIC_L1D_1 },
{ PCI_VENDOR_ATTANSIC, PCI_PRODUCT_ATTANSIC_L2C_1 },
-   { PCI_VENDOR_ATTANSIC, PCI_PRODUCT_ATTANSIC_L2C_2 }
+   { PCI_VENDOR_ATTANSIC, PCI_PRODUCT_ATTANSIC_L2C_2 },
+   { PCI_VENDOR_ATTANSIC, PCI_PRODUCT_ATTANSIC_AR8161 },
+   { PCI_VENDOR_ATTANSIC, PCI_PRODUCT_ATTANSIC_AR8162 },
+   { PCI_VENDOR_ATTANSIC, PCI_PRODUCT_ATTANSIC_AR8171 },
+   { PCI_VENDOR_ATTANSIC, PCI_PRODUCT_ATTANSIC_AR8172 },
+   { PCI_VENDOR_ATTANSIC, PCI_PRODUCT_ATTANSIC_E2200 },
+   { PCI_VENDOR_ATTANSIC, PCI_PRODUCT_ATTANSIC_E2400 },
+   { PCI_VENDOR_ATTANSIC, PCI_PRODUCT_ATTANSIC_E2500 }
 };
 
 struct cfattach alc_ca = {
-   sizeof (struct alc_softc), alc_match, alc_attach, NULL,
+   sizeof (struct alc_softc), alc_match, alc_attach, alc_detach,
alc_activate
 };
 
@@ -138,6 +170,22 @@ int
 alc_miibus_readreg(struct device *dev, int phy, int reg)
 {
struct alc_softc *sc = (struct alc_softc *)dev;
+   uint32_t v = 0;
+
+   if (phy != sc->alc_phyaddr)
+   return (0);
+
+   if ((sc->alc_flags & ALC_FLAG_AR816X_FAMILY) != 0)
+