Re: perlre(1) and substitution evaluations

2013-12-01 Thread john slee
On 30 November 2013 21:59, Lars Nooden lars.noo...@gmail.com wrote:

 perlre(1) seems to be missing information about substitution evaluations
 with the /e option.  The functionality is present in perl:


It is, however, already documented in perlop(1)

John


Re: pop3 daemon with ssl/tls and STARTTLS, V2

2013-12-01 Thread Gilles Chehade
On Tue, Nov 26, 2013 at 06:19:14PM -0500, James Turner wrote:
 
 Hi Sunil,
 
 I've been following your development on bitbucket and want to see if you
 ever got any feedback from the smtpd guys?
 

I don't use pop3 so I can't really give feedback on day to day use, but
code look very readable, clean and nice.

I'll give a real try when I'm done with some stuff that are keeping me
busy these days.

-- 
Gilles Chehade

https://www.poolp.org  @poolpOrg



jme(4) fixes for jme_encap(), fixes crashing under load

2013-12-01 Thread Brad Smith
Here is a diff to fix a few issues with jme_encap(). I noticed some issues with
jme_encap() as it was ported from DragonFly. I had fixed similar issues with
age(4) and alc(4), also originating from DragonFly. Maybe age/alc took 
inspiration
from jme when being ported from DragonFly?

- Remove the maximum DMA segments handling bits as it is unused between
  DragonFly and OpenBSD.
- Fix error handling for bus_dmamap_load_mbuf() so as to not try unloading
  a DMA map that had not already been loaded.
- Clean up the DMA chain defragmenting path to remove unwanted printfs and
  simplify things a bit.
- Have jme_encap() check the number of mapped DMA segments against the TX
  ring to see if it'll fit as do most of the driver nowadays.
- Remove the KASSERT's that shouldn't be there.
- Simplify the dummy descriptor handling to be closer to the FreeBSD
  driver since unlike the DragonFly driver this orinated from our
  driver always uses the 64-bit dummy descriptor.
- If the ring was full make sure to IF_PREPEND() the packet back on
  the queue since it wasn't transmitted.

Tested by com...@daknet.org and vigdis+o...@chown.me and myself.

OK?


Index: if_jme.c
===
RCS file: /home/cvs/src/sys/dev/pci/if_jme.c,v
retrieving revision 1.32
diff -u -p -r1.32 if_jme.c
--- if_jme.c3 Nov 2013 23:27:33 -   1.32
+++ if_jme.c28 Nov 2013 19:38:12 -
@@ -1044,48 +1044,36 @@ jme_encap(struct jme_softc *sc, struct m
struct jme_txdesc *txd;
struct jme_desc *desc;
struct mbuf *m;
-   int maxsegs;
int error, i, prod;
uint32_t cflags;
 
prod = sc-jme_cdata.jme_tx_prod;
txd = sc-jme_cdata.jme_txdesc[prod];
 
-   maxsegs = (JME_TX_RING_CNT - sc-jme_cdata.jme_tx_cnt) -
- (JME_TXD_RSVD + 1);
-   if (maxsegs  JME_MAXTXSEGS)
-   maxsegs = JME_MAXTXSEGS;
-   if (maxsegs  (sc-jme_txd_spare - 1))
-   panic(%s: not enough segments %d, sc-sc_dev.dv_xname,
-   maxsegs);
-
error = bus_dmamap_load_mbuf(sc-sc_dmat, txd-tx_dmamap,
 *m_head, BUS_DMA_NOWAIT);
+   if (error != 0  error != EFBIG)
+   goto drop;
if (error != 0) {
-   bus_dmamap_unload(sc-sc_dmat, txd-tx_dmamap);
-   error = EFBIG;
-   }
-   if (error == EFBIG) {
if (m_defrag(*m_head, M_DONTWAIT)) {
-   printf(%s: can't defrag TX mbuf\n,
-   sc-sc_dev.dv_xname);
-   m_freem(*m_head);
-   *m_head = NULL;
-   return (ENOBUFS);
-   }
-   error = bus_dmamap_load_mbuf(sc-sc_dmat,
-txd-tx_dmamap, *m_head,
-BUS_DMA_NOWAIT);
-   if (error != 0) {
-   printf(%s: could not load defragged TX mbuf\n,
-   sc-sc_dev.dv_xname);
-   m_freem(*m_head);
-   *m_head = NULL;
-   return (error);
-   }
-   } else if (error) {
-   printf(%s: could not load TX mbuf\n, sc-sc_dev.dv_xname);
-   return (error);
+   error = ENOBUFS;
+   goto drop;
+   }
+   error = bus_dmamap_load_mbuf(sc-sc_dmat, txd-tx_dmamap,
+*m_head, BUS_DMA_NOWAIT);
+   if (error != 0)
+   goto drop;
+   }
+
+   /*
+* Check descriptor overrun. Leave one free descriptor.
+* Since we always use 64bit address mode for transmitting,
+* each Tx request requires one more dummy descriptor.
+*/
+   if (sc-jme_cdata.jme_tx_cnt + txd-tx_dmamap-dm_nsegs + JME_TXD_RSVD 
+   JME_TX_RING_CNT - JME_TXD_RSVD) {
+   bus_dmamap_unload(sc-sc_dmat, txd-tx_dmamap);
+   return (ENOBUFS);
}
 
m = *m_head;
@@ -1113,7 +1101,6 @@ jme_encap(struct jme_softc *sc, struct m
desc-addr_hi = htole32(m-m_pkthdr.len);
desc-addr_lo = 0;
sc-jme_cdata.jme_tx_cnt++;
-   KASSERT(sc-jme_cdata.jme_tx_cnt  JME_TX_RING_CNT - JME_TXD_RSVD);
JME_DESC_INC(prod, JME_TX_RING_CNT);
for (i = 0; i  txd-tx_dmamap-dm_nsegs; i++) {
desc = sc-jme_rdata.jme_tx_ring[prod];
@@ -1123,10 +1110,7 @@ jme_encap(struct jme_softc *sc, struct m
htole32(JME_ADDR_HI(txd-tx_dmamap-dm_segs[i].ds_addr));
desc-addr_lo =
htole32(JME_ADDR_LO(txd-tx_dmamap-dm_segs[i].ds_addr));
-
sc-jme_cdata.jme_tx_cnt++;
-   KASSERT(sc-jme_cdata.jme_tx_cnt =
-JME_TX_RING_CNT - JME_TXD_RSVD);
JME_DESC_INC(prod, JME_TX_RING_CNT);
}
 

pcn(4) receive filter / ioctl handling fixes/updating

2013-12-01 Thread Brad Smith
Here is a diff to clean up and and fix up the receive filter and
ioctl handling code to be in line with the other drivers. Also fixes
being not able to bring the interface out of all multicast mode once
the range or promisc mode has been removed/disabled.

Tested with QEMU and VMware's pcn(4) adapters.

OK?


Index: if_pcn.c
===
RCS file: /home/cvs/src/sys/dev/pci/if_pcn.c,v
retrieving revision 1.28
diff -u -p -r1.28 if_pcn.c
--- if_pcn.c26 Nov 2013 09:50:33 -  1.28
+++ if_pcn.c2 Dec 2013 00:34:05 -
@@ -1057,31 +1057,24 @@ pcn_ioctl(struct ifnet *ifp, u_long cmd,
switch (cmd) {
case SIOCSIFADDR:
ifp-if_flags |= IFF_UP;
-
-   switch (ifa-ifa_addr-sa_family) {
-#ifdef INET
-   case AF_INET:
+   if (!(ifp-if_flags  IFF_RUNNING))
pcn_init(ifp);
+#ifdef INET
+   if (ifa-ifa_addr-sa_family == AF_INET)
arp_ifinit(sc-sc_arpcom, ifa);
-   break;
 #endif
-   default:
-   pcn_init(ifp);
-   break;
-   }
break;
 
case SIOCSIFFLAGS:
-   /*
-* If interface is marked up and not running, then start it.
-* If it is marked down and running, stop it.
-* XXX If it's up then re-initialize it. This is so flags
-* such as IFF_PROMISC are handled.
-*/
-   if (ifp-if_flags  IFF_UP)
-   pcn_init(ifp);
-   else if (ifp-if_flags  IFF_RUNNING)
-   pcn_stop(ifp, 1);
+   if (ifp-if_flags  IFF_UP) {
+   if (ifp-if_flags  IFF_RUNNING)
+   error = ENETRESET;
+   else
+   pcn_init(ifp);
+   } else {
+   if (ifp-if_flags  IFF_RUNNING)
+   pcn_stop(ifp, 1);
+   }
break;
 
case SIOCSIFMEDIA:
@@ -1570,10 +1563,6 @@ pcn_init(struct ifnet *ifp)
 
/* Initialize MODE for the initialization block. */
sc-sc_mode = 0;
-   if (ifp-if_flags  IFF_PROMISC)
-   sc-sc_mode |= LE_C15_PROM;
-   if ((ifp-if_flags  IFF_BROADCAST) == 0)
-   sc-sc_mode |= LE_C15_DRCVBC;
 
/*
 * If we have MII, simply select MII in the MODE register,
@@ -1593,6 +1582,9 @@ pcn_init(struct ifnet *ifp)
pcn_bcr_read(sc, LE_BCR32) | LE_B32_DANAS);
}
 
+   /* Set the multicast filter in the init block. */
+   pcn_set_filter(sc);
+
/*
 * Set the Tx and Rx descriptor ring addresses in the init
 * block, the TLEN and RLEN other fields of the init block
@@ -1610,9 +1602,6 @@ pcn_init(struct ifnet *ifp)
sc-sc_initblock.init_padr[1] = htole32(enaddr[4] |
(enaddr[5]  8));
 
-   /* Set the multicast filter in the init block. */
-   pcn_set_filter(sc);
-
/* Initialize CSR3. */
pcn_csr_write(sc, LE_CSR3, LE_C3_MISSM|LE_C3_IDONM|LE_C3_DXSUFLO);
 
@@ -1835,46 +1824,43 @@ pcn_set_filter(struct pcn_softc *sc)
struct ether_multistep step;
uint32_t crc;
 
-   /*
-* Set up the multicast address filter by passing all multicast
-* addresses through a CRC generator, and then using the high
-* order 6 bits as an index into the 64-bit logical address
-* filter.  The high order bits select the word, while the rest
-* of the bits select the bit within the word.
-*/
-
-   if (ifp-if_flags  IFF_ALLMULTI || ifp-if_flags  IFF_PROMISC ||
-   ac-ac_multirangecnt  0)
-   goto allmulti;
-
-   sc-sc_initblock.init_ladrf[0] =
-   sc-sc_initblock.init_ladrf[1] =
-   sc-sc_initblock.init_ladrf[2] =
-   sc-sc_initblock.init_ladrf[3] = 0;
-
-   ETHER_FIRST_MULTI(step, ac, enm);
-   while (enm != NULL) {
-   crc = ether_crc32_le(enm-enm_addrlo, ETHER_ADDR_LEN);
-
-   /* Just want the 6 most significant bits. */
-   crc = 26;
-
-   /* Set the corresponding bit in the filter. */
-   sc-sc_initblock.init_ladrf[crc  4] |=
-   htole16(1  (crc  0xf));
+   ifp-if_flags = ~IFF_ALLMULTI;
 
-   ETHER_NEXT_MULTI(step, enm);
-   }
+   if (ifp-if_flags  IFF_PROMISC || ac-ac_multirangecnt  0) {
+   ifp-if_flags |= IFF_ALLMULTI;
+   if (ifp-if_flags  IFF_PROMISC)
+   sc-sc_mode |= LE_C15_PROM;
+   sc-sc_initblock.init_ladrf[0] =
+   sc-sc_initblock.init_ladrf[1] =
+   sc-sc_initblock.init_ladrf[2] =
+   sc-sc_initblock.init_ladrf[3] = 0x;
+   } else {
+   

tl(4) ThunderLAN diff needs testing

2013-12-01 Thread Brad Smith
Here is a diff for the tl(4) ThunderLAN driver to clean up and update the
receive filter / ioctl handling code to be in line with the other drivers.
I also want to try reinstating the hash filter and get that working properly.

Anyone with hw and able to test? OK?


Index: if_tl.c
===
RCS file: /home/cvs/src/sys/dev/pci/if_tl.c,v
retrieving revision 1.57
diff -u -p -r1.57 if_tl.c
--- if_tl.c 26 Nov 2013 09:50:33 -  1.57
+++ if_tl.c 2 Dec 2013 01:17:00 -
@@ -277,10 +277,8 @@ void tl_miibus_writereg(struct device *,
 void tl_miibus_statchg(struct device *);
 
 void tl_setmode(struct tl_softc *, int);
-#if 0
 int tl_calchash(caddr_t);
-#endif
-void tl_setmulti(struct tl_softc *);
+void tl_iff(struct tl_softc *);
 void tl_setfilt(struct tl_softc *, caddr_t, int);
 void tl_softreset(struct tl_softc *, int);
 void tl_hardreset(struct device *);
@@ -744,7 +742,6 @@ tl_setmode(struct tl_softc *sc, int medi
}
 }
 
-#if 0
 /*
  * Calculate the hash of a MAC address for programming the multicast hash
  * table.  This hash is simply the address split into 6-bit chunks
@@ -763,7 +760,6 @@ tl_calchash(caddr_t addr)
(addr[2] ^ addr[5]);
return ((t  18) ^ (t  12) ^ (t  6) ^ t)  0x3f;
 }
-#endif
 
 /*
  * The ThunderLAN has a perfect MAC address filter in addition to
@@ -801,36 +797,41 @@ tl_setfilt(struct tl_softc *sc, caddr_t 
  * update the multicast filter.
  */
 void
-tl_setmulti(struct tl_softc *sc)
+tl_iff(struct tl_softc *sc)
 {
-   struct ifnet*ifp;
-   u_int32_t   hashes[2] = { 0, 0 };
-   int h;
-   struct arpcom *ac = sc-arpcom;
+   struct ifnet*ifp = sc-arpcom.ac_if;
+   struct arpcom   *ac = sc-arpcom;
struct ether_multistep step;
struct ether_multi *enm;
-   ifp = sc-arpcom.ac_if;
-
-   tl_dio_write32(sc, TL_HASH1, 0);
-   tl_dio_write32(sc, TL_HASH2, 0);
+   u_int32_t   hashes[2];
+   int h = 0;
 
+   tl_dio_clrbit(sc, TL_NETCMD, (TL_CMD_CAF | TL_CMD_NOBRX));
+   bzero(hashes, sizeof(hashes));
ifp-if_flags = ~IFF_ALLMULTI;
-   ETHER_FIRST_MULTI(step, ac, enm);
-   h = 0;
-   while (enm != NULL) {
-   h++;
-   ETHER_NEXT_MULTI(step, enm);
-   }
-   if (h) {
-   hashes[0] = hashes[1] = 0x;
+
+   if (ifp-if_flags  IFF_PROMISC || ac-ac_multirangecnt  0) {
ifp-if_flags |= IFF_ALLMULTI;
-   } else
-   hashes[0] = hashes[1] = 0x;
+   if (ifp-if_flags  IFF_PROMISC)
+   tl_dio_setbit(sc, TL_NETCMD, TL_CMD_CAF);
+   else
+   hashes[0] = hashes[1] = 0x;
+   } else {
+   ETHER_FIRST_MULTI(step, ac, enm);
+   while (enm != NULL) {
+   h = tl_calchash(enm-enm_addrlo);
+
+   if (h  32)
+   hashes[0] |= (1  h);
+   else
+   hashes[1] |= (1  (h - 32));
+
+   ETHER_NEXT_MULTI(step, enm);
+   }
+   }
 
tl_dio_write32(sc, TL_HASH1, hashes[0]);
tl_dio_write32(sc, TL_HASH2, hashes[1]);
-
-   return;
 }
 
 /*
@@ -1569,29 +1570,13 @@ tl_init(void *xsc)
/* Set PCI burst size */
tl_dio_write8(sc, TL_BSIZEREG, TL_RXBURST_16LONG|TL_TXBURST_16LONG);
 
-   /*
-* Set 'capture all frames' bit for promiscuous mode.
-*/
-   if (ifp-if_flags  IFF_PROMISC)
-   tl_dio_setbit(sc, TL_NETCMD, TL_CMD_CAF);
-   else
-   tl_dio_clrbit(sc, TL_NETCMD, TL_CMD_CAF);
-
-   /*
-* Set capture broadcast bit to capture broadcast frames.
-*/
-   if (ifp-if_flags  IFF_BROADCAST)
-   tl_dio_clrbit(sc, TL_NETCMD, TL_CMD_NOBRX);
-   else
-   tl_dio_setbit(sc, TL_NETCMD, TL_CMD_NOBRX);
-
tl_dio_write16(sc, TL_MAXRX, MCLBYTES);
 
/* Init our MAC address */
tl_setfilt(sc, (caddr_t)sc-arpcom.ac_enaddr, 0);
 
-   /* Init multicast filter, if needed. */
-   tl_setmulti(sc);
+   /* Program promiscuous mode and multicast filters. */
+   tl_iff(sc);
 
/* Init circular RX list. */
if (tl_list_rx_init(sc) == ENOBUFS) {
@@ -1688,40 +1673,24 @@ tl_ioctl(struct ifnet *ifp, u_long comma
switch(command) {
case SIOCSIFADDR:
ifp-if_flags |= IFF_UP;
-   switch (ifa-ifa_addr-sa_family) {
-#ifdef INET
-   case AF_INET:
+   if (!(ifp-if_flags  IFF_RUNNING))
tl_init(sc);
+#ifdef INET
+   if (ifa-ifa_addr-sa_family == AF_INET)
arp_ifinit(sc-arpcom, ifa);
-   break;
-#endif /* INET */
-   default:
-

sf(4) Starfire diff needs testing

2013-12-01 Thread Brad Smith
Here is a diff for the sf(4) Starfire driver to clean up and update the
receive filter / ioctl handling code to be in line with the other drivers.

Anyone with hw and able to test? OK?


Index: aic6915.c
===
RCS file: /home/cvs/src/sys/dev/ic/aic6915.c,v
retrieving revision 1.11
diff -u -p -r1.11 aic6915.c
--- aic6915.c   26 Nov 2013 09:50:32 -  1.11
+++ aic6915.c   1 Dec 2013 00:48:16 -
@@ -89,7 +89,7 @@ void  sf_macreset(struct sf_softc *);
 void   sf_rxdrain(struct sf_softc *);
 intsf_add_rxbuf(struct sf_softc *, int);
 uint8_tsf_read_eeprom(struct sf_softc *, int);
-void   sf_set_filter(struct sf_softc *);
+void   sf_iff(struct sf_softc *);
 
 intsf_mii_read(struct device *, int, int);
 void   sf_mii_write(struct device *, int, int, int);
@@ -532,19 +532,14 @@ sf_ioctl(struct ifnet *ifp, u_long cmd, 
 
case SIOCSIFFLAGS:
if (ifp-if_flags  IFF_UP) {
-   if (ifp-if_flags  IFF_RUNNING 
-   ((ifp-if_flags ^ sc-sc_flags) 
-IFF_PROMISC)) {
-   sf_set_filter(sc);
-   } else {
-   if (!(ifp-if_flags  IFF_RUNNING))
-   sf_init(ifp);
-   }
+   if (ifp-if_flags  IFF_RUNNING)
+   error = ENETRESET;
+   else
+   sf_init(ifp);
} else {
if (ifp-if_flags  IFF_RUNNING)
sf_stop(ifp, 1);
}
-   sc-sc_flags = ifp-if_flags;
break;
 
case SIOCGIFMEDIA:
@@ -558,7 +553,7 @@ sf_ioctl(struct ifnet *ifp, u_long cmd, 
 
if (error == ENETRESET) {
if (ifp-if_flags  IFF_RUNNING)
-   sf_set_filter(sc);
+   sf_iff(sc);
error = 0;
}
 
@@ -1087,10 +1082,9 @@ sf_init(struct ifnet *ifp)
RDC_RxBurstSize(4));/* default */
 
/*
-* Set the receive filter.
+* Program promiscuous mode and multicast filters.
 */
-   sc-sc_RxAddressFilteringCtl = 0;
-   sf_set_filter(sc);
+   sf_iff(sc);
 
/*
 * Set MacConfig1.  When we set the media, MacConfig1 will
@@ -1293,85 +1287,65 @@ sf_set_filter_hash(struct sf_softc *sc, 
 }
 
 /*
- * sf_set_filter:
+ * sf_iff:
  *
  * Set the Starfire receive filter.
  */
 void
-sf_set_filter(struct sf_softc *sc)
+sf_iff(struct sf_softc *sc)
 {
struct arpcom *ac = sc-sc_arpcom;
struct ifnet *ifp = sc-sc_arpcom.ac_if;
struct ether_multi *enm;
struct ether_multistep step;
+   uint32_t filterctl;
int i;
 
-   /* Start by clearing the perfect and hash tables. */
+   filterctl = sf_funcreg_read(sc, SF_RxAddressFilteringCtl);
+   filterctl = ~(RAFC_PassBroadcast | RAFC_PromiscuousMode |
+   RAFC_PerfectFilteringMode(3) | RAFC_HashFilteringMode(3));
+   ifp-if_flags = ~IFF_ALLMULTI;
+
+   /* Clear the perfect and hash tables. */
for (i = 0; i  SF_PERFECT_SIZE; i += sizeof(uint32_t))
sf_genreg_write(sc, SF_PERFECT_BASE + i, 0);
-
for (i = 0; i  SF_HASH_SIZE; i += sizeof(uint32_t))
sf_genreg_write(sc, SF_HASH_BASE + i, 0);
 
/*
-* Clear the perfect and hash mode bits.
-*/
-   sc-sc_RxAddressFilteringCtl =
-   ~(RAFC_PerfectFilteringMode(3) | RAFC_HashFilteringMode(3));
-
-   if (ifp-if_flags  IFF_BROADCAST)
-   sc-sc_RxAddressFilteringCtl |= RAFC_PassBroadcast;
-   else
-   sc-sc_RxAddressFilteringCtl = ~RAFC_PassBroadcast;
-
-   if (ifp-if_flags  IFF_PROMISC) {
-   sc-sc_RxAddressFilteringCtl |= RAFC_PromiscuousMode;
-   goto allmulti;
-   } else
-   sc-sc_RxAddressFilteringCtl = ~RAFC_PromiscuousMode;
-
-   /*
-* Set normal perfect filtering mode.
+* Always accept broadcast frames.
 */
-   sc-sc_RxAddressFilteringCtl |= RAFC_PerfectFilteringMode(1);
+   filterctl |= RAFC_PassBroadcast;
 
-   /*
-* First, write the station address to the perfect filter
-* table.
-*/
-   sf_set_filter_perfect(sc, 0, LLADDR(ifp-if_sadl));
+   if (ifp-if_flags  IFF_PROMISC || ac-ac_multirangecnt  0) {
+   ifp-if_flags |= IFF_ALLMULTI;
+   filterctl |= RAFC_PassMulticast;
+   if (ifp-if_flags  IFF_PROMISC)
+   filterctl |= RAFC_PromiscuousMode;
+   } else {
+   /*
+* Set hash only multicast dest, match regardless of VLAN ID.
+*/
+   filterctl |= RAFC_HashFilteringMode(2);
 
-   if (ac-ac_multirangecnt  0)
-   goto 

nge(4) DP83820 / DP83821 diff needs testing

2013-12-01 Thread Brad Smith
Here is a diff for the sf(4) Starfire driver to clean up and update the
receive filter / ioctl handling code to be in line with the other drivers.

Anyone with hw and able to test? OK?


Index: if_nge.c
===
RCS file: /home/cvs/src/sys/dev/pci/if_nge.c,v
retrieving revision 1.78
diff -u -p -r1.78 if_nge.c
--- if_nge.c26 Nov 2013 09:50:33 -  1.78
+++ if_nge.c2 Dec 2013 01:42:46 -
@@ -173,7 +173,7 @@ int nge_miibus_readreg(struct device *, 
 void nge_miibus_writereg(struct device *, int, int, int);
 void nge_miibus_statchg(struct device *);
 
-void nge_setmulti(struct nge_softc *);
+void nge_iff(struct nge_softc *);
 void nge_reset(struct nge_softc *);
 int nge_list_rx_init(struct nge_softc *);
 int nge_list_tx_init(struct nge_softc *);
@@ -577,7 +577,7 @@ nge_miibus_statchg(struct device *dev)
 }
 
 void
-nge_setmulti(struct nge_softc *sc)
+nge_iff(struct nge_softc *sc)
 {
struct arpcom   *ac = sc-arpcom;
struct ifnet*ifp = ac-ac_if;
@@ -1491,7 +1491,6 @@ nge_intr(void *arg)
 
if (status  NGE_ISR_SYSERR) {
nge_reset(sc);
-   ifp-if_flags = ~IFF_RUNNING;
nge_init(sc);
}
 
@@ -1650,9 +1649,6 @@ nge_init(void *xsc)
u_int32_t   txcfg, rxcfg;
int s, media;
 
-   if (ifp-if_flags  IFF_RUNNING)
-   return;
-
s = splnet();
 
/*
@@ -1688,32 +1684,9 @@ nge_init(void *xsc)
nge_list_tx_init(sc);
 
/*
-* For the NatSemi chip, we have to explicitly enable the
-* reception of ARP frames, as well as turn on the 'perfect
-* match' filter where we store the station address, otherwise
-* we won't receive unicasts meant for this host.
-*/
-   NGE_SETBIT(sc, NGE_RXFILT_CTL, NGE_RXFILTCTL_ARP);
-   NGE_SETBIT(sc, NGE_RXFILT_CTL, NGE_RXFILTCTL_PERFECT);
-
-/* If we want promiscuous mode, set the allframes bit. */
-   if (ifp-if_flags  IFF_PROMISC)
-   NGE_SETBIT(sc, NGE_RXFILT_CTL, NGE_RXFILTCTL_ALLPHYS);
-   else
-   NGE_CLRBIT(sc, NGE_RXFILT_CTL, NGE_RXFILTCTL_ALLPHYS);
-
-   /*
-* Set the capture broadcast bit to capture broadcast frames.
-*/
-   if (ifp-if_flags  IFF_BROADCAST)
-   NGE_SETBIT(sc, NGE_RXFILT_CTL, NGE_RXFILTCTL_BROAD);
-   else
-   NGE_CLRBIT(sc, NGE_RXFILT_CTL, NGE_RXFILTCTL_BROAD);
-
-   /*
-* Load the multicast filter.
+* Program promiscuous mode and multicast filters.
 */
-   nge_setmulti(sc);
+   nge_iff(sc);
 
/* Turn the receive filter on */
NGE_SETBIT(sc, NGE_RXFILT_CTL, NGE_RXFILTCTL_ENABLE);
@@ -1969,7 +1942,6 @@ nge_ioctl(struct ifnet *ifp, u_long comm
struct nge_softc*sc = ifp-if_softc;
struct ifaddr   *ifa = (struct ifaddr *) data;
struct ifreq*ifr = (struct ifreq *) data;
-   struct mii_data *mii;
int s, error = 0;
 
s = splnet();
@@ -1977,45 +1949,25 @@ nge_ioctl(struct ifnet *ifp, u_long comm
switch(command) {
case SIOCSIFADDR:
ifp-if_flags |= IFF_UP;
-   switch (ifa-ifa_addr-sa_family) {
-#ifdef INET
-   case AF_INET:
+   if (!(ifp-if_flags  IFF_RUNNING))
nge_init(sc);
+
+#ifdef INET
+   if (ifa-ifa_addr-sa_family == AF_INET)
arp_ifinit(sc-arpcom, ifa);
-   break;
-#endif /* INET */
-   default:
-   nge_init(sc);
-   break;
-}
+#endif
break;
 
case SIOCSIFFLAGS:
if (ifp-if_flags  IFF_UP) {
-   if (ifp-if_flags  IFF_RUNNING 
-   ifp-if_flags  IFF_PROMISC 
-   !(sc-nge_if_flags  IFF_PROMISC)) {
-   NGE_SETBIT(sc, NGE_RXFILT_CTL,
-   NGE_RXFILTCTL_ALLPHYS|
-   NGE_RXFILTCTL_ALLMULTI);
-   } else if (ifp-if_flags  IFF_RUNNING 
-   !(ifp-if_flags  IFF_PROMISC) 
-   sc-nge_if_flags  IFF_PROMISC) {
-   NGE_CLRBIT(sc, NGE_RXFILT_CTL,
-   NGE_RXFILTCTL_ALLPHYS);
-   if (!(ifp-if_flags  IFF_ALLMULTI))
-   NGE_CLRBIT(sc, NGE_RXFILT_CTL,
-   NGE_RXFILTCTL_ALLMULTI);
-   } else {
-   ifp-if_flags = ~IFF_RUNNING;
+   if (ifp-if_flags  IFF_RUNNING)
+   error = ENETRESET;
+

mtd(4) Myson MTD800/MTD803/MTD891 diff needs testing

2013-12-01 Thread Brad Smith
Here is a diff for the mtd(4) Myson MTD800/MTD803/MTD891 driver to clean up
and update the receive filter / ioctl handling code to be in line with the
other drivers.

Anyone with hw and able to test? OK?


Index: mtd8xx.c
===
RCS file: /home/cvs/src/sys/dev/ic/mtd8xx.c,v
retrieving revision 1.21
diff -u -p -r1.21 mtd8xx.c
--- mtd8xx.c26 Nov 2013 09:50:33 -  1.21
+++ mtd8xx.c2 Dec 2013 01:34:24 -
@@ -68,7 +68,7 @@ static u_int32_t mtd_mii_command(struct 
 static int mtd_miibus_readreg(struct device *, int, int);
 static void mtd_miibus_writereg(struct device *, int, int, int);
 static void mtd_miibus_statchg(struct device *);
-static void mtd_setmulti(struct mtd_softc *);
+void mtd_iff(struct mtd_softc *);
 
 static int mtd_encap(struct mtd_softc *, struct mbuf *, u_int32_t *);
 static int mtd_list_rx_init(struct mtd_softc *);
@@ -313,42 +313,45 @@ mtd_miibus_statchg(struct device *self)
 
 
 void
-mtd_setmulti(struct mtd_softc *sc)
+mtd_iff(struct mtd_softc *sc)
 {
struct arpcom *ac = sc-sc_arpcom;
struct ifnet *ifp = sc-sc_arpcom.ac_if;
-   u_int32_t rxfilt, crc, hash[2] = { 0, 0 };
struct ether_multistep step;
struct ether_multi *enm;
-   int mcnt = 0;
+   u_int32_t rxfilt, crc, hash[2];
 
-   if (ac-ac_multirangecnt  0)
-   ifp-if_flags |= IFF_ALLMULTI;
+   rxfilt = CSR_READ_4(MTD_TCRRCR);
+   rxfilt = ~(RCR_AB | RCR_AM | RCR_PROM);
+   ifp-if_flags = ~IFF_ALLMULTI;
+
+   /*
+* Always accept broadcast frames.
+*/
+   rxfilt |= RCR_AB;
 
-   rxfilt = CSR_READ_4(MTD_TCRRCR)  ~RCR_AM;
-   if (ifp-if_flags  (IFF_ALLMULTI | IFF_PROMISC)) {
+   if (ifp-if_flags  IFF_PROMISC || ac-ac_multirangecnt  0) {
+   ifp-if_flags |= IFF_ALLMULTI;
rxfilt |= RCR_AM;
-   CSR_WRITE_4(MTD_TCRRCR, rxfilt);
-   CSR_WRITE_4(MTD_MAR0, 0x);
-   CSR_WRITE_4(MTD_MAR4, 0x);
-   return;
-   }
+   if (ifp-if_flags  IFF_PROMISC)
+   rxfilt |= RCR_PROM;
+   hash[0] = hash[1] = 0x;
+   } else {
+   rxfilt |= RCR_AM;
+   /* Program new filter. */
+   bzero(hash, sizeof(hash));
+
+   ETHER_FIRST_MULTI(step, sc-sc_arpcom, enm);
+   while (enm != NULL) {
+   crc = ether_crc32_be(enm-enm_addrlo,
+   ETHER_ADDR_LEN)  26;
+
+   hash[crc  5] |= 1  (crc  0xf);
 
-   /* First, zot all the existing hash bits. */
-   CSR_WRITE_4(MTD_MAR0, 0);
-   CSR_WRITE_4(MTD_MAR4, 0);
-
-   /* Now program new ones. */
-   ETHER_FIRST_MULTI(step, ac, enm);
-   while (enm != NULL) {
-   crc = ether_crc32_be(enm-enm_addrlo, ETHER_ADDR_LEN)  26;
-   hash[crc  5] |= 1  (crc  0xf);
-   ++mcnt;
-   ETHER_NEXT_MULTI(step, enm);
+   ETHER_NEXT_MULTI(step, enm);
+   }
}
 
-   if (mcnt)
-   rxfilt |= RCR_AM;
CSR_WRITE_4(MTD_MAR0, hash[0]);
CSR_WRITE_4(MTD_MAR4, hash[1]);
CSR_WRITE_4(MTD_TCRRCR, rxfilt);
@@ -584,37 +587,39 @@ mtd_ioctl(struct ifnet *ifp, u_long comm
switch (command) {
case SIOCSIFADDR:
ifp-if_flags |= IFF_UP;
-   mtd_init(ifp);
-   switch (ifa-ifa_addr-sa_family) {
+   if (!(ifp-if_flags  IFF_RUNNING))
+   mtd_init(ifp);
+
 #ifdef INET
-   case AF_INET:
+   if (ifa-ifa_addr-sa_family == AF_INET)
arp_ifinit(sc-sc_arpcom, ifa);
-   break;
-#endif /* INET */
-   }
+#endif
break;
 
case SIOCSIFFLAGS:
-   if (ifp-if_flags  IFF_UP)
-   mtd_init(ifp);
-   else {
+   if (ifp-if_flags  IFF_UP) {
+   if (ifp-if_flags  IFF_RUNNING)
+   error = ENETRESET;
+   else
+   mtd_init(ifp);
+   } else {
if (ifp-if_flags  IFF_RUNNING)
mtd_stop(ifp);
}
-   error = 0;
break;
 
case SIOCGIFMEDIA:
case SIOCSIFMEDIA:
error = ifmedia_ioctl(ifp, ifr, sc-sc_mii.mii_media, command);
break;
+
default:
error = ether_ioctl(ifp, sc-sc_arpcom, command, data);
}
 
if (error == ENETRESET) {
if (ifp-if_flags  IFF_RUNNING)
-   mtd_setmulti(sc);
+   mtd_iff(sc);
error = 0;
}
 
@@ -646,17 +651,8 @@ mtd_init(struct ifnet *ifp)
CSR_SETBIT(MTD_TCRRCR, 

Re: nge(4) DP83820 / DP83821 diff needs testing

2013-12-01 Thread Brad Smith

On 01/12/13 8:45 PM, Brad Smith wrote:

Here is a diff for the sf(4) Starfire driver to clean up and update the
receive filter / ioctl handling code to be in line with the other drivers.


Oops. Should have said..

Here is a diff for the nge(4) DP83820 / DP83821 driver to clean up and
update the receive filter / ioctl handling code to be in line with the
other drivers.


Anyone with hw and able to test? OK?


Index: if_nge.c
===
RCS file: /home/cvs/src/sys/dev/pci/if_nge.c,v
retrieving revision 1.78
diff -u -p -r1.78 if_nge.c
--- if_nge.c26 Nov 2013 09:50:33 -  1.78
+++ if_nge.c2 Dec 2013 01:42:46 -
@@ -173,7 +173,7 @@ int nge_miibus_readreg(struct device *,
  void nge_miibus_writereg(struct device *, int, int, int);
  void nge_miibus_statchg(struct device *);

-void nge_setmulti(struct nge_softc *);
+void nge_iff(struct nge_softc *);
  void nge_reset(struct nge_softc *);
  int nge_list_rx_init(struct nge_softc *);
  int nge_list_tx_init(struct nge_softc *);
@@ -577,7 +577,7 @@ nge_miibus_statchg(struct device *dev)
  }

  void
-nge_setmulti(struct nge_softc *sc)
+nge_iff(struct nge_softc *sc)
  {
struct arpcom   *ac = sc-arpcom;
struct ifnet*ifp = ac-ac_if;
@@ -1491,7 +1491,6 @@ nge_intr(void *arg)

if (status  NGE_ISR_SYSERR) {
nge_reset(sc);
-   ifp-if_flags = ~IFF_RUNNING;
nge_init(sc);
}

@@ -1650,9 +1649,6 @@ nge_init(void *xsc)
u_int32_t   txcfg, rxcfg;
int s, media;

-   if (ifp-if_flags  IFF_RUNNING)
-   return;
-
s = splnet();

/*
@@ -1688,32 +1684,9 @@ nge_init(void *xsc)
nge_list_tx_init(sc);

/*
-* For the NatSemi chip, we have to explicitly enable the
-* reception of ARP frames, as well as turn on the 'perfect
-* match' filter where we store the station address, otherwise
-* we won't receive unicasts meant for this host.
-*/
-   NGE_SETBIT(sc, NGE_RXFILT_CTL, NGE_RXFILTCTL_ARP);
-   NGE_SETBIT(sc, NGE_RXFILT_CTL, NGE_RXFILTCTL_PERFECT);
-
-/* If we want promiscuous mode, set the allframes bit. */
-   if (ifp-if_flags  IFF_PROMISC)
-   NGE_SETBIT(sc, NGE_RXFILT_CTL, NGE_RXFILTCTL_ALLPHYS);
-   else
-   NGE_CLRBIT(sc, NGE_RXFILT_CTL, NGE_RXFILTCTL_ALLPHYS);
-
-   /*
-* Set the capture broadcast bit to capture broadcast frames.
-*/
-   if (ifp-if_flags  IFF_BROADCAST)
-   NGE_SETBIT(sc, NGE_RXFILT_CTL, NGE_RXFILTCTL_BROAD);
-   else
-   NGE_CLRBIT(sc, NGE_RXFILT_CTL, NGE_RXFILTCTL_BROAD);
-
-   /*
-* Load the multicast filter.
+* Program promiscuous mode and multicast filters.
 */
-   nge_setmulti(sc);
+   nge_iff(sc);

/* Turn the receive filter on */
NGE_SETBIT(sc, NGE_RXFILT_CTL, NGE_RXFILTCTL_ENABLE);
@@ -1969,7 +1942,6 @@ nge_ioctl(struct ifnet *ifp, u_long comm
struct nge_softc*sc = ifp-if_softc;
struct ifaddr   *ifa = (struct ifaddr *) data;
struct ifreq*ifr = (struct ifreq *) data;
-   struct mii_data *mii;
int s, error = 0;

s = splnet();
@@ -1977,45 +1949,25 @@ nge_ioctl(struct ifnet *ifp, u_long comm
switch(command) {
case SIOCSIFADDR:
ifp-if_flags |= IFF_UP;
-   switch (ifa-ifa_addr-sa_family) {
-#ifdef INET
-   case AF_INET:
+   if (!(ifp-if_flags  IFF_RUNNING))
nge_init(sc);
+
+#ifdef INET
+   if (ifa-ifa_addr-sa_family == AF_INET)
arp_ifinit(sc-arpcom, ifa);
-   break;
-#endif /* INET */
-   default:
-   nge_init(sc);
-   break;
-}
+#endif
break;

case SIOCSIFFLAGS:
if (ifp-if_flags  IFF_UP) {
-   if (ifp-if_flags  IFF_RUNNING 
-   ifp-if_flags  IFF_PROMISC 
-   !(sc-nge_if_flags  IFF_PROMISC)) {
-   NGE_SETBIT(sc, NGE_RXFILT_CTL,
-   NGE_RXFILTCTL_ALLPHYS|
-   NGE_RXFILTCTL_ALLMULTI);
-   } else if (ifp-if_flags  IFF_RUNNING 
-   !(ifp-if_flags  IFF_PROMISC) 
-   sc-nge_if_flags  IFF_PROMISC) {
-   NGE_CLRBIT(sc, NGE_RXFILT_CTL,
-   NGE_RXFILTCTL_ALLPHYS);
-   if (!(ifp-if_flags  IFF_ALLMULTI))
-   NGE_CLRBIT(sc, NGE_RXFILT_CTL,
-   

bce(4) Broadcom BCM4401 diff needs testing

2013-12-01 Thread Brad Smith
Here is a diff for the bce(4) Broadcom BCM4401 driver to clean up and update
the receive filter / ioctl handling code to be in line with the other drivers.

Anyone with hw and able to test? OK?


Index: if_bce.c
===
RCS file: /home/cvs/src/sys/dev/pci/if_bce.c,v
retrieving revision 1.37
diff -u -p -r1.37 if_bce.c
--- if_bce.c21 Aug 2013 05:21:43 -  1.37
+++ if_bce.c9 Sep 2013 18:31:22 -
@@ -146,7 +146,7 @@ voidbce_add_mac(struct bce_softc *, u_i
 void   bce_add_rxbuf(struct bce_softc *, int);
 void   bce_stop(struct ifnet *);
 void   bce_reset(struct bce_softc *);
-void   bce_set_filter(struct ifnet *);
+void   bce_iff(struct ifnet *);
 intbce_mii_read(struct device *, int, int);
 void   bce_mii_write(struct device *, int, int, int);
 void   bce_statchg(struct device *);
@@ -473,28 +473,24 @@ bce_ioctl(struct ifnet *ifp, u_long cmd,
switch (cmd) {
case SIOCSIFADDR:
ifp-if_flags |= IFF_UP;
-
-   switch (ifa-ifa_addr-sa_family) {
-#ifdef INET
-   case AF_INET:
+   if (!(ifp-if_flags  IFF_RUNNING))
bce_init(ifp);
+#ifdef INET
+   if (ifa-ifa_addr-sa_family == AF_INET)
arp_ifinit(sc-bce_ac, ifa);
-   break;
-#endif /* INET */
-   default:
-   bce_init(ifp);
-   break;
-   }
+#endif
break;
 
case SIOCSIFFLAGS:
-   if (ifp-if_flags  IFF_UP)
+   if (ifp-if_flags  IFF_UP) {
if (ifp-if_flags  IFF_RUNNING)
-   bce_set_filter(ifp);
+   error = ENETRESET;
else
bce_init(ifp);
-   else if (ifp-if_flags  IFF_RUNNING)
-   bce_stop(ifp);
+   } else {
+   if (ifp-if_flags  IFF_RUNNING)
+   bce_stop(ifp);
+   }
break;
 
case SIOCSIFMEDIA:
@@ -508,7 +504,7 @@ bce_ioctl(struct ifnet *ifp, u_long cmd,
 
if (error == ENETRESET) {
if (ifp-if_flags  IFF_RUNNING)
-   bce_set_filter(ifp);
+   bce_iff(ifp);
error = 0;
}
 
@@ -871,8 +867,8 @@ bce_init(struct ifnet *ifp)
/* setup DMA interrupt control */
bus_space_write_4(sc-bce_btag, sc-bce_bhandle, BCE_DMAI_CTL, 1  
24);/* MAGIC */
 
-   /* setup packet filter */
-   bce_set_filter(ifp);
+   /* program promiscuous mode and multicast filters */
+   bce_iff(ifp);
 
/* set max frame length, account for possible VLAN tag */
bus_space_write_4(sc-bce_btag, sc-bce_bhandle, BCE_RX_MAX,
@@ -1198,51 +1194,35 @@ bce_reset(struct bce_softc *sc)
 
 /* Set up the receive filter. */
 void
-bce_set_filter(struct ifnet *ifp)
+bce_iff(struct ifnet *ifp)
 {
struct bce_softc *sc = ifp-if_softc;
+   struct arpcom *ac = sc-bce_ac;
+   u_int32_t rxctl;
 
-   if (ifp-if_flags  IFF_PROMISC) {
-   ifp-if_flags |= IFF_ALLMULTI;
-   bus_space_write_4(sc-bce_btag, sc-bce_bhandle, BCE_RX_CTL,
-   bus_space_read_4(sc-bce_btag, sc-bce_bhandle, BCE_RX_CTL)
-   | ERC_PE);
-   } else {
-   ifp-if_flags = ~IFF_ALLMULTI;
-
-   /* turn off promiscuous */
-   bus_space_write_4(sc-bce_btag, sc-bce_bhandle, BCE_RX_CTL,
-   bus_space_read_4(sc-bce_btag, sc-bce_bhandle,
-   BCE_RX_CTL)  ~ERC_PE);
+   rxctl = bus_space_read_4(sc-bce_btag, sc-bce_bhandle, BCE_RX_CTL);
+   rxctl = ~(ERC_AM | ERC_DB | ERC_PE);
+   ifp-if_flags |= IFF_ALLMULTI;
 
-   /* enable/disable broadcast */
-   if (ifp-if_flags  IFF_BROADCAST)
-   bus_space_write_4(sc-bce_btag, sc-bce_bhandle,
-   BCE_RX_CTL, bus_space_read_4(sc-bce_btag,
-   sc-bce_bhandle, BCE_RX_CTL)  ~ERC_DB);
-   else
-   bus_space_write_4(sc-bce_btag, sc-bce_bhandle,
-   BCE_RX_CTL, bus_space_read_4(sc-bce_btag,
-   sc-bce_bhandle, BCE_RX_CTL) | ERC_DB);
-
-   /* disable the filter */
-   bus_space_write_4(sc-bce_btag, sc-bce_bhandle, BCE_FILT_CTL,
-   0);
+   /* disable the filter */
+   bus_space_write_4(sc-bce_btag, sc-bce_bhandle, BCE_FILT_CTL, 0);
 
-   /* add our own address */
-   bce_add_mac(sc, sc-bce_ac.ac_enaddr, 0);
+   /* add our own address */
+   bce_add_mac(sc, ac-ac_enaddr, 0);
 
-   /* for now accept all multicast */
-   bus_space_write_4(sc-bce_btag, sc-bce_bhandle, BCE_RX_CTL,
-  

epic(4) SMC 83C170 diff needs testing

2013-12-01 Thread Brad Smith
Here is a diff for the epic(4) SMC 83C170 driver to clean up and update the
receive filter / ioctl handling code to be in line with the other drivers.

Anyone with hw and able to test? OK?


Index: smc83c170.c
===
RCS file: /home/cvs/src/sys/dev/ic/smc83c170.c,v
retrieving revision 1.16
diff -u -p -r1.16 smc83c170.c
--- smc83c170.c 26 Nov 2013 09:50:33 -  1.16
+++ smc83c170.c 1 Dec 2013 01:12:31 -
@@ -84,7 +84,7 @@ void  epic_reset(struct epic_softc *);
 void   epic_rxdrain(struct epic_softc *);
 intepic_add_rxbuf(struct epic_softc *, int);
 void   epic_read_eeprom(struct epic_softc *, int, int, u_int16_t *);
-void   epic_set_mchash(struct epic_softc *);
+void   epic_iff(struct epic_softc *);
 void   epic_fixup_clock_source(struct epic_softc *);
 intepic_mii_read(struct device *, int, int);
 void   epic_mii_write(struct device *, int, int, int);
@@ -536,31 +536,24 @@ epic_ioctl(struct ifnet *ifp, u_long cmd
switch (cmd) {
case SIOCSIFADDR:
ifp-if_flags |= IFF_UP;
-
-   switch (ifa-ifa_addr-sa_family) {
-#ifdef INET
-   case AF_INET:
+   if (!(ifp-if_flags  IFF_RUNNING))
epic_init(ifp);
+#ifdef INET
+   if (ifa-ifa_addr-sa_family == AF_INET)
arp_ifinit(sc-sc_arpcom, ifa);
-   break;
 #endif
-   default:
-   epic_init(ifp);
-   break;
-   }
break;
 
case SIOCSIFFLAGS:
-   /*
-* If interface is marked up and not running, then start it.
-* If it is marked down and running, stop it.
-* XXX If it's up then re-initialize it. This is so flags
-* such as IFF_PROMISC are handled.
-*/
-   if (ifp-if_flags  IFF_UP)
-   epic_init(ifp);
-   else if (ifp-if_flags  IFF_RUNNING)
-   epic_stop(ifp, 1);
+   if (ifp-if_flags  IFF_UP) {
+   if (ifp-if_flags  IFF_RUNNING)
+   error = ENETRESET;
+   else
+   epic_init(ifp);
+   } else {
+   if (ifp-if_flags  IFF_RUNNING)
+   epic_stop(ifp, 1);
+   }
break;
 
case SIOCSIFMEDIA:
@@ -575,7 +568,7 @@ epic_ioctl(struct ifnet *ifp, u_long cmd
if (error == ENETRESET) {
if (ifp-if_flags  IFF_RUNNING) {
mii_pollstat(sc-sc_mii);
-   epic_set_mchash(sc);
+   epic_iff(sc);
}
error = 0;
}
@@ -974,8 +967,8 @@ epic_init(struct ifnet *ifp)
/* Set the current media. */
epic_mediachange(ifp);
 
-   /* Set up the multicast hash table. */
-   epic_set_mchash(sc);
+   /* Program promiscuous mode and multicast filters. */
+   epic_iff(sc);
 
/*
 * Initialize the transmit descriptor ring.  txlast is initialized
@@ -1260,7 +1253,7 @@ epic_add_rxbuf(struct epic_softc *sc, in
  * NOTE: We rely on a recently-updated mii_media_active here!
  */
 void
-epic_set_mchash(struct epic_softc *sc)
+epic_iff(struct epic_softc *sc)
 {
struct arpcom *ac = sc-sc_arpcom;
struct ifnet *ifp = sc-sc_arpcom.ac_if;
@@ -1268,47 +1261,38 @@ epic_set_mchash(struct epic_softc *sc)
struct ether_multistep step;
u_int32_t hash, mchash[4];
 
-   /*
-* Set up the multicast address filter by passing all multicast
-* addresses through a CRC generator, and then using the low-order
-* 6 bits as an index into the 64 bit multicast hash table (only
-* the lower 16 bits of each 32 bit multicast hash register are
-* valid).  The high order bits select the register, while the
-* rest of the bits select the bit within the register.
-*/
-
-   if (ifp-if_flags  IFF_PROMISC)
-   goto allmulti;
-
-   if (IFM_SUBTYPE(sc-sc_mii.mii_media_active) == IFM_10_T) {
-   /* XXX hardware bug in 10Mbps mode. */
-   goto allmulti;
-   }
+   ifp-if_flags = ~IFF_ALLMULTI;
 
-   if (ac-ac_multirangecnt  0)
-   goto allmulti;
+   if (ifp-if_flags  IFF_PROMISC || ac-ac_multirangecnt  0 ||
+   IFM_SUBTYPE(sc-sc_mii.mii_media_active) == IFM_10_T) {
+   ifp-if_flags |= IFF_ALLMULTI;
+   mchash[0] = mchash[1] = mchash[2] = mchash[3] = 0x;
+   } else {
+   mchash[0] = mchash[1] = mchash[2] = mchash[3] = 0;
 
-   mchash[0] = mchash[1] = mchash[2] = mchash[3] = 0;
+   /*
+* Set up the multicast address filter by passing all
+* multicast addresses through a CRC generator, 

txp(4) 3Com 3XP Typhoon/Sidewinder diff needs testing

2013-12-01 Thread Brad Smith
Here is a diff for the txp(4) 3Com 3XP Typhoon/Sidewinder driver to clean up
and update the receive filter / ioctl handling code to be in line with the
other drivers.

Anyone with hw and able to test? OK?


Index: if_txp.c
===
RCS file: /home/cvs/src/sys/dev/pci/if_txp.c,v
retrieving revision 1.108
diff -u -p -r1.108 if_txp.c
--- if_txp.c26 Nov 2013 09:50:33 -  1.108
+++ if_txp.c2 Dec 2013 02:04:44 -
@@ -103,7 +103,7 @@ int txp_download_fw_section(struct txp_s
 int txp_alloc_rings(struct txp_softc *);
 void txp_dma_free(struct txp_softc *, struct txp_dma_alloc *);
 int txp_dma_malloc(struct txp_softc *, bus_size_t, struct txp_dma_alloc *, 
int);
-void txp_set_filter(struct txp_softc *);
+void txp_iff(struct txp_softc *);
 
 int txp_cmd_desc_numfree(struct txp_softc *);
 int txp_command(struct txp_softc *, u_int16_t, u_int16_t, u_int32_t,
@@ -1184,22 +1184,21 @@ txp_ioctl(struct ifnet *ifp, u_long comm
switch(command) {
case SIOCSIFADDR:
ifp-if_flags |= IFF_UP;
-   switch (ifa-ifa_addr-sa_family) {
-#ifdef INET
-   case AF_INET:
+   if (!(ifp-if_flags  IFF_RUNNING))
txp_init(sc);
+
+#ifdef INET
+   if (ifa-ifa_addr-sa_family == AF_INET)
arp_ifinit(sc-sc_arpcom, ifa);
-   break;
-#endif /* INET */
-   default:
-   txp_init(sc);
-   break;
-   }
+#endif
break;
 
case SIOCSIFFLAGS:
if (ifp-if_flags  IFF_UP) {
-   txp_init(sc);
+   if (ifp-if_flags  IFF_RUNNING)
+   error = ENETRESET;
+   else
+   txp_init(sc);
} else {
if (ifp-if_flags  IFF_RUNNING)
txp_stop(sc);
@@ -1217,7 +1216,7 @@ txp_ioctl(struct ifnet *ifp, u_long comm
 
if (error == ENETRESET) {
if (ifp-if_flags  IFF_RUNNING)
-   txp_set_filter(sc);
+   txp_iff(sc);
error = 0;
}
 
@@ -1235,7 +1234,8 @@ txp_init(struct txp_softc *sc)
 
s = splnet();
 
-   txp_set_filter(sc);
+   /* Program promiscuous mode and multicast filters. */
+   txp_iff(sc);
 
txp_command(sc, TXP_CMD_TX_ENABLE, 0, 0, 0, NULL, NULL, NULL, 1);
txp_command(sc, TXP_CMD_RX_ENABLE, 0, 0, 0, NULL, NULL, NULL, 1);
@@ -1843,51 +1843,46 @@ txp_show_descriptor(void *d)
 }
 
 void
-txp_set_filter(struct txp_softc *sc)
+txp_iff(struct txp_softc *sc)
 {
struct arpcom *ac = sc-sc_arpcom;
struct ifnet *ifp = sc-sc_arpcom.ac_if;
-   u_int32_t hashbit, hash[2];
-   u_int16_t filter;
-   int mcnt = 0;
struct ether_multi *enm;
struct ether_multistep step;
+   u_int32_t hashbit, hash[2];
+   u_int16_t filter;
 
-   if (ifp-if_flags  IFF_PROMISC) {
-   filter = TXP_RXFILT_PROMISC;
-   goto setit;
-   }
-
-   if (ac-ac_multirangecnt  0)
-   ifp-if_flags |= IFF_ALLMULTI;
-
-   filter = TXP_RXFILT_DIRECT;
+   bzero(hash, sizeof(hash));
+   ifp-if_flags = ~IFF_ALLMULTI;
 
-   if (ifp-if_flags  IFF_BROADCAST)
-   filter |= TXP_RXFILT_BROADCAST;
+   /*
+* Always accept broadcast packets.
+* Always accept frames destined to our station address.
+*/
+   filter = TXP_RXFILT_BROADCAST | TXP_RXFILT_DIRECT;
 
-   if (ifp-if_flags  IFF_ALLMULTI)
-   filter |= TXP_RXFILT_ALLMULTI;
-   else {
-   hash[0] = hash[1] = 0;
+   if (ifp-if_flags  IFF_PROMISC || ac-ac_multirangecnt  0) {
+   ifp-if_flags |= IFF_ALLMULTI;
+   if (ifp-if_flags  IFF_PROMISC)
+   filter |= TXP_RXFILT_PROMISC;
+   else
+   filter |= TXP_RXFILT_ALLMULTI;
+   } else {
+   filter |= TXP_RXFILT_HASHMULTI;
 
ETHER_FIRST_MULTI(step, ac, enm);
while (enm != NULL) {
-   mcnt++;
hashbit = (u_int16_t)(ether_crc32_be(enm-enm_addrlo,
ETHER_ADDR_LEN)  (64 - 1));
+
hash[hashbit / 32] |= (1  hashbit % 32);
-   ETHER_NEXT_MULTI(step, enm);
-   }
 
-   if (mcnt  0) {
-   filter |= TXP_RXFILT_HASHMULTI;
-   txp_command(sc, TXP_CMD_MCAST_HASH_MASK_WRITE,
-   2, hash[0], hash[1], NULL, NULL, NULL, 0);
+   ETHER_NEXT_MULTI(step, enm);
}
}
 
-setit:
+   txp_command(sc, TXP_CMD_MCAST_HASH_MASK_WRITE,
+   2, hash[0], hash[1], NULL, NULL, NULL, 0);

cue(4) CATC USB-EL1201A diff needs testing

2013-12-01 Thread Brad Smith
Here is a diff for the cue(4) CATC USB-EL1201A driver to clean up and update
the receive filter / ioctl handling code to be in line with the other drivers.

Anyone with hw and able to test? OK?


Index: if_cue.c
===
RCS file: /home/cvs/src/sys/dev/usb/if_cue.c,v
retrieving revision 1.64
diff -u -p -r1.64 if_cue.c
--- if_cue.c15 Nov 2013 10:17:39 -  1.64
+++ if_cue.c17 Nov 2013 20:26:19 -
@@ -139,7 +139,7 @@ void cue_init(void *);
 void cue_stop(struct cue_softc *);
 void cue_watchdog(struct ifnet *);
 
-void cue_setmulti(struct cue_softc *);
+void cue_iff(struct cue_softc *);
 void cue_reset(struct cue_softc *);
 
 int cue_csr_read_1(struct cue_softc *, int);
@@ -340,52 +340,50 @@ cue_getmac(struct cue_softc *sc, void *b
 #define CUE_BITS   9
 
 void
-cue_setmulti(struct cue_softc *sc)
+cue_iff(struct cue_softc *sc)
 {
+   struct ifnet*ifp = GET_IFP(sc);
struct arpcom   *ac = sc-arpcom;
-   struct ifnet*ifp;
struct ether_multi  *enm;
struct ether_multistep  step;
u_int32_t   h, i;
 
-   ifp = GET_IFP(sc);
-
-   DPRINTFN(2,(%s: cue_setmulti if_flags=0x%x\n,
+   DPRINTFN(2,(%s: cue_iff if_flags=0x%x\n,
sc-cue_dev.dv_xname, ifp-if_flags));
 
+   CUE_CLRBIT(sc, CUE_ETHCTL, CUE_ETHCTL_PROMISC);
+   ifp-if_flags = ~IFF_ALLMULTI;
+
if (ifp-if_flags  IFF_PROMISC || ac-ac_multirangecnt  0) {
ifp-if_flags |= IFF_ALLMULTI;
+   if (ifp-if_flags  IFF_PROMISC)
+   CUE_SETBIT(sc, CUE_ETHCTL, CUE_ETHCTL_PROMISC);
for (i = 0; i  CUE_MCAST_TABLE_LEN; i++)
sc-cue_mctab[i] = 0xFF;
-   cue_mem(sc, CUE_CMD_WRITESRAM, CUE_MCAST_TABLE_ADDR,
-   sc-cue_mctab, CUE_MCAST_TABLE_LEN);
-   return;
-   }
+   } else {
+   /* first, zot all the existing hash bits */
+   for (i = 0; i  CUE_MCAST_TABLE_LEN; i++)
+   sc-cue_mctab[i] = 0;
 
-   /* first, zot all the existing hash bits */
-   for (i = 0; i  CUE_MCAST_TABLE_LEN; i++)
-   sc-cue_mctab[i] = 0;
-
-   /* now program new ones */
-   ETHER_FIRST_MULTI(step, ac, enm);
-   while (enm != NULL) {
-   h = ether_crc32_le(enm-enm_addrlo, ETHER_ADDR_LEN) 
-   ((1  CUE_BITS) - 1);
-   sc-cue_mctab[h  3] |= 1  (h  0x7);
-   ETHER_NEXT_MULTI(step, enm);
-   }
+   /* now program new ones */
+   ETHER_FIRST_MULTI(step, ac, enm);
+   while (enm != NULL) {
+   h = ether_crc32_le(enm-enm_addrlo, ETHER_ADDR_LEN) 
+   ((1  CUE_BITS) - 1);
 
-   ifp-if_flags = ~IFF_ALLMULTI;
+   sc-cue_mctab[h  3] |= 1  (h  0x7);
+
+   ETHER_NEXT_MULTI(step, enm);
+   }
+   }
 
/*
 * Also include the broadcast address in the filter
 * so we can receive broadcast frames.
 */
-   if (ifp-if_flags  IFF_BROADCAST) {
-   h = ether_crc32_le(etherbroadcastaddr, ETHER_ADDR_LEN) 
-   ((1  CUE_BITS) - 1);
-   sc-cue_mctab[h  3] |= 1  (h  0x7);
-   }
+   h = ether_crc32_le(etherbroadcastaddr, ETHER_ADDR_LEN) 
+   ((1  CUE_BITS) - 1);
+   sc-cue_mctab[h  3] |= 1  (h  0x7);
 
cue_mem(sc, CUE_CMD_WRITESRAM, CUE_MCAST_TABLE_ADDR,
sc-cue_mctab, CUE_MCAST_TABLE_LEN);
@@ -970,17 +968,12 @@ cue_init(void *xsc)
 
DPRINTFN(10,(%s: %s: enter\n, sc-cue_dev.dv_xname,__func__));
 
-   if (ifp-if_flags  IFF_RUNNING)
-   return;
-
s = splnet();
 
/*
 * Cancel pending I/O and free all RX/TX buffers.
 */
-#if 1
cue_reset(sc);
-#endif
 
/* Set advanced operation modes. */
cue_csr_write_1(sc, CUE_ADVANCED_OPMODES,
@@ -1011,8 +1004,8 @@ cue_init(void *xsc)
return;
}
 
-   /* Load the multicast filter. */
-   cue_setmulti(sc);
+   /* Program promiscuous mode and multicast filters. */
+   cue_iff(sc);
 
/*
 * Set the number of RX and TX buffers that we want
@@ -1094,37 +1087,24 @@ cue_ioctl(struct ifnet *ifp, u_long comm
switch(command) {
case SIOCSIFADDR:
ifp-if_flags |= IFF_UP;
-   cue_init(sc);
-
-   switch (ifa-ifa_addr-sa_family) {
+   if (!(ifp-if_flags  IFF_RUNNING))
+   cue_init(sc);
 #ifdef INET
-   case AF_INET:
+   if (ifa-ifa_addr-sa_family == AF_INET)
arp_ifinit(sc-arpcom, ifa);
-   break;
-#endif /* INET */
-   }
+#endif
break;
 
case SIOCSIFFLAGS:
if (ifp-if_flags