Changeset 243ddb5 in rtems


Ignore:
Timestamp:
Jun 15, 2018, 12:28:36 PM (10 months ago)
Author:
Daniel Hellstrom <daniel@…>
Branches:
master
Children:
aea3134e
Parents:
2fbe2ef3
git-author:
Daniel Hellstrom <daniel@…> (06/15/18 12:28:36)
git-committer:
Daniel Hellstrom <daniel@…> (08/24/18 13:51:39)
Message:

leon,greth: enable MAC filtering (promiscous mode, multicast)

It enabled promiscous mode or sets the multicast filter according
to the configuration and parameters to ioctl(SIOCSIFFLAGS),
ioctl(SIOCADDMULTI) and ioctl(SIOCDELMULTI).
On SIOCADDMULTI/SIOCDELMULTI requests the greth ioctl calls the
Ethernet helper functions ether_addmulti()/ether_delmulti() which
tells the greth driver when its required to update the MAC multicast
filtering.

The interface notifies support for multicast by setting IFF_MULTICAST.

The GRETH has two registers which contains a bit-mask of allowed MAC
addresses. The incomming MAC address is CRC:ed and the CRC is used as
an index into the bit-mask to determine to allow or drop the frame.

Location:
bsps/sparc
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • bsps/sparc/include/bsp/greth.h

    r2fbe2ef3 r243ddb5  
    2525   volatile uint32_t txdesc;       /* Transmit descriptor pointer */
    2626   volatile uint32_t rxdesc;       /* Receive descriptor pointer */
     27   volatile uint32_t edcl;         /* EDCL IP register */
     28   volatile uint32_t ht_msb;       /* Multicast MSB hash */
     29   volatile uint32_t ht_lsb;       /* Multicast LSB hash */
    2730} greth_regs;
    2831
     
    8487#define GRETH_CTRL_SP           0x00000080 /* 100MBit speed mode */
    8588#define GRETH_CTRL_GB           0x00000100 /* 1GBit speed mode */
     89#define GRETH_CTRL_MCE          0x00000800 /* Multicast Enable */
    8690#define GRETH_CTRL_DD           0x00001000 /* Disable EDCL Duplex Detection */
    8791#define GRETH_CTRL_ED           0x00004000 /* EDCL Disable */
     92#define GRETH_CTRL_MC           0x02000000 /* Multicast available */
     93#define GRETH_CTRL_ME           0x04000000 /* MDIO interrupts enabled */
     94#define GRETH_CTRL_GA           0x08000000 /* Gigabit MAC available */
    8895
    8996/* Status Register */
  • bsps/sparc/shared/net/greth.c

    r2fbe2ef3 r243ddb5  
    195195   unsigned int advmodes; /* advertise ethernet speed modes. 0 = all modes. */
    196196   struct timespec auto_neg_time;
     197   int mc_available;
    197198
    198199   /*
     
    342343}
    343344
     345/*
     346 * Generates the hash words based on CRCs of the enabled MAC addresses that are
     347 * allowed to be received. The allowed MAC addresses are maintained in a linked
     348 * "multi-cast" list available in the arpcom structure.
     349 *
     350 * Returns the number of MAC addresses that were processed (in the list)
     351 */
     352static int
     353greth_mac_filter_calc(struct arpcom *ac, uint32_t *msb, uint32_t *lsb)
     354{
     355    struct ether_multistep step;
     356    struct ether_multi *enm;
     357    int cnt = 0;
     358    uint32_t crc, htindex, ht[2] = {0, 0};
     359
     360    /* Go through the Ethernet Multicast addresses one by one and add their
     361     * CRC contribution to the MAC filter.
     362     */
     363    ETHER_FIRST_MULTI(step, ac, enm);
     364    while (enm) {
     365        crc = ether_crc32_be((uint8_t *)enm->enm_addrlo, 6);
     366        htindex = crc & 0x3f;
     367        ht[htindex >> 5] |= (1 << (htindex & 0x1F));
     368        cnt++;
     369        ETHER_NEXT_MULTI(step, enm);
     370    }
     371
     372    if (cnt > 0) {
     373        *msb = ht[1];
     374        *lsb = ht[0];
     375    }
     376
     377    return cnt;
     378}
     379
     380/*
     381 * Initialize the ethernet hardware
     382 */
     383static int greth_mac_filter_set(struct greth_softc *sc)
     384{
     385    struct ifnet *ifp = &sc->arpcom.ac_if;
     386    uint32_t hash_msb, hash_lsb, ctrl;
     387    SPIN_IRQFLAGS(flags);
     388
     389    hash_msb = 0;
     390    hash_lsb = 0;
     391    ctrl = 0;
     392    if (ifp->if_flags & IFF_PROMISC) {
     393        /* No need to enable multi-cast when promiscous mode accepts all */
     394        ctrl |= GRETH_CTRL_PRO;
     395    } else if(!sc->mc_available) {
     396        return EINVAL; /* no hardware support for multicast filtering. */
     397    } else if (ifp->if_flags & IFF_ALLMULTI) {
     398        /* We should accept all multicast addresses */
     399        ctrl |= GRETH_CTRL_MCE;
     400        hash_msb = 0xFFFFFFFF;
     401        hash_lsb = 0xFFFFFFFF;
     402    } else if (greth_mac_filter_calc(&sc->arpcom, &hash_msb, &hash_lsb) > 0) {
     403        /* Generate hash for MAC filtering out multicast addresses */
     404        ctrl |= GRETH_CTRL_MCE;
     405    } else {
     406        /* Multicast list is empty .. disable multicast */
     407    }
     408    SPIN_LOCK_IRQ(&sc->devlock, flags);
     409    sc->regs->ht_msb = hash_msb;
     410    sc->regs->ht_lsb = hash_lsb;
     411    sc->regs->ctrl = (sc->regs->ctrl & ~(GRETH_CTRL_PRO | GRETH_CTRL_MCE)) |
     412                     ctrl;
     413    SPIN_UNLOCK_IRQ(&sc->devlock, flags);
     414
     415    return 0;
     416}
    344417
    345418/*
     
    11831256
    11841257    /*
     1258     * Setup promiscous/multi-cast MAC address filters if user enabled it
     1259     */
     1260    greth_mac_filter_set(sc);
     1261
     1262    /*
    11851263     * Tell the world that we're running.
    11861264     */
     
    12411319    struct greth_softc *sc = ifp->if_softc;
    12421320    int error = 0;
     1321    struct ifreq *ifr;
    12431322
    12441323    switch (command)
     
    12741353
    12751354          /*
    1276            * FIXME: All sorts of multicast commands need to be added here!
     1355           * Multicast commands: Enabling/disabling filtering of MAC addresses
    12771356           */
     1357      case SIOCADDMULTI:
     1358      case SIOCDELMULTI:
     1359      ifr = (struct ifreq *)data;
     1360      if (command == SIOCADDMULTI) {
     1361        error = ether_addmulti(ifr, &sc->arpcom);
     1362      } else {
     1363        error = ether_delmulti(ifr, &sc->arpcom);
     1364      }
     1365      if (error == ENETRESET) {
     1366        error = greth_mac_filter_set(sc);
     1367      }
     1368      break;
     1369
    12781370      default:
    12791371          error = EINVAL;
     
    13371429    ifp->if_output = ether_output;
    13381430    ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX;
     1431    if (sc->mc_available)
     1432        ifp->if_flags |= IFF_MULTICAST;
    13391433    if (ifp->if_snd.ifq_maxlen == 0)
    13401434        ifp->if_snd.ifq_maxlen = ifqmaxlen;
     
    15411635        sc->advmodes = value->i;
    15421636
     1637    /* Check if multicast support is available */
     1638    sc->mc_available = sc->regs->ctrl & GRETH_CTRL_MC;
     1639
    15431640    return 0;
    15441641}
Note: See TracChangeset for help on using the changeset viewer.