alc(4): add support for Mikrotik 10/25G NIC

The new Mikrotik 10/25G NIC is mostly compatible with AR8151 hardware,
with few exceptions:

* card supports only 32bit DMA operations
* card does not support write-one-to-clear semantics for interrupt status
  register
* MDIO operations can take longer to complete

This patch adds support for Mikrotik 10/25G NIC to the alc driver
while maintaining support for all earlier HW.

The patch was tested with FreeBSD main branch as of commit
f4b38c360e

This was tested on Intel i7-4790K system with Mikrotik 10/25G NIC.
This was tested on Intel i7-4790K system with RB44Ge (AR8151 based 4-port NIC)
to verify backwards compatibility.

PR:	256000
Submitted by:	 Gatis Peisenieks  <gatis@mikrotik.com>
MFC after:	1 week
This commit is contained in:
Konstantin Belousov 2021-05-20 01:14:18 +03:00
parent 96480d9b33
commit 77b637338a
3 changed files with 24 additions and 3 deletions

View File

@ -1438,6 +1438,8 @@ alc_attach(device_t dev)
case DEVICEID_ATHEROS_AR8151:
case DEVICEID_ATHEROS_AR8151_V2:
sc->alc_flags |= ALC_FLAG_APS;
if (CSR_READ_4(sc, ALC_MT_MAGIC) == MT_MAGIC)
sc->alc_flags |= ALC_FLAG_MT;
/* FALLTHROUGH */
default:
break;
@ -1977,6 +1979,8 @@ alc_dma_alloc(struct alc_softc *sc)
int error, i;
lowaddr = BUS_SPACE_MAXADDR;
if (sc->alc_flags & ALC_FLAG_MT)
lowaddr = BUS_SPACE_MAXSIZE_32BIT;
again:
/* Create parent DMA tag. */
error = bus_dma_tag_create(
@ -2219,7 +2223,7 @@ alc_dma_alloc(struct alc_softc *sc)
error = bus_dma_tag_create(
bus_get_dma_tag(sc->alc_dev), /* parent */
1, 0, /* alignment, boundary */
BUS_SPACE_MAXADDR, /* lowaddr */
lowaddr, /* lowaddr */
BUS_SPACE_MAXADDR, /* highaddr */
NULL, NULL, /* filter, filterarg */
BUS_SPACE_MAXSIZE_32BIT, /* maxsize */
@ -3339,6 +3343,11 @@ alc_intr(void *arg)
sc = (struct alc_softc *)arg;
if (sc->alc_flags & ALC_FLAG_MT) {
taskqueue_enqueue(sc->alc_tq, &sc->alc_int_task);
return (FILTER_HANDLED);
}
status = CSR_READ_4(sc, ALC_INTR_STATUS);
if ((status & ALC_INTRS) == 0)
return (FILTER_STRAY);
@ -3416,6 +3425,9 @@ alc_int_task(void *arg, int pending)
done:
if ((ifp->if_drv_flags & IFF_DRV_RUNNING) != 0) {
/* Re-enable interrupts if we're running. */
if (sc->alc_flags & ALC_FLAG_MT)
CSR_WRITE_4(sc, ALC_INTR_STATUS, 0);
else
CSR_WRITE_4(sc, ALC_INTR_STATUS, 0x7FFFFFFF);
}
ALC_UNLOCK(sc);

View File

@ -1121,6 +1121,14 @@
#define MII_EXT_ANEG_NLP78 0x8027
#define ANEG_NLP78_120M_DEFAULT 0x8A05
#define ALC_MT_MAGIC 0x1F00
#define ALC_MT_MODE 0x1F04
#define ALC_MT_SPEED 0x1F08
#define ALC_MT_VERSION 0x1F0C
#define MT_MAGIC 0xaabb1234
#define MT_MODE_4Q BIT(0)
/* Statistics counters collected by the MAC. */
struct smb {
/* Rx stats. */

View File

@ -239,6 +239,7 @@ struct alc_softc {
#define ALC_FLAG_LINK_WAR 0x4000
#define ALC_FLAG_E2X00 0x8000
#define ALC_FLAG_LINK 0x10000
#define ALC_FLAG_MT 0x20000
struct callout alc_tick_ch;
struct alc_hw_stats alc_stats;
@ -284,6 +285,6 @@ do { \
#define ALC_TX_TIMEOUT 5
#define ALC_RESET_TIMEOUT 100
#define ALC_TIMEOUT 1000
#define ALC_PHY_TIMEOUT 1000
#define ALC_PHY_TIMEOUT 10000
#endif /* _IF_ALCVAR_H */