Re: re(4): tedu some unused code

2013-12-31 Thread Brad Smith
On Tue, Dec 31, 2013 at 09:55:54AM -0800, Chris Cappuccio wrote:
> Brad Smith [b...@comstyle.com] wrote:
> > tedu some unused code. it has never been enabled and will not be; to
> > deal with a hardware defect for rare boards. unmaintained, untested, etc.
> > want to get rid of it.
> > 
> > Comments? OK?
> > 
> 
> If RE_DIAG wasn't being compiled in, then it should be removed. The BUGS
> section of re(4) needs to be updated to reflect the fact that the driver
> does not detect this condition.

Good idea especially since it has never been enabled so the driver
has never been able to detect this defective hardware.


Index: sys/dev/ic/re.c
===
RCS file: /home/cvs/src/sys/dev/ic/re.c,v
retrieving revision 1.146
diff -u -p -r1.146 re.c
--- sys/dev/ic/re.c 25 Oct 2013 22:48:10 -  1.146
+++ sys/dev/ic/re.c 31 Dec 2013 00:49:27 -
@@ -197,10 +197,6 @@ void   re_setup_intr(struct rl_softc *, in
 intre_wol(struct ifnet*, int);
 #endif
 
-#ifdef RE_DIAG
-intre_diag(struct rl_softc *);
-#endif
-
 struct cfdriver re_cd = {
0, "re", DV_IFNET
 };
@@ -615,190 +611,6 @@ re_reset(struct rl_softc *sc)
CSR_WRITE_1(sc, RL_LDPS, 1);
 }
 
-#ifdef RE_DIAG
-
-/*
- * The following routine is designed to test for a defect on some
- * 32-bit 8169 cards. Some of these NICs have the REQ64# and ACK64#
- * lines connected to the bus, however for a 32-bit only card, they
- * should be pulled high. The result of this defect is that the
- * NIC will not work right if you plug it into a 64-bit slot: DMA
- * operations will be done with 64-bit transfers, which will fail
- * because the 64-bit data lines aren't connected.
- *
- * There's no way to work around this (short of talking a soldering
- * iron to the board), however we can detect it. The method we use
- * here is to put the NIC into digital loopback mode, set the receiver
- * to promiscuous mode, and then try to send a frame. We then compare
- * the frame data we sent to what was received. If the data matches,
- * then the NIC is working correctly, otherwise we know the user has
- * a defective NIC which has been mistakenly plugged into a 64-bit PCI
- * slot. In the latter case, there's no way the NIC can work correctly,
- * so we print out a message on the console and abort the device attach.
- */
-
-int
-re_diag(struct rl_softc *sc)
-{
-   struct ifnet*ifp = &sc->sc_arpcom.ac_if;
-   struct mbuf *m0;
-   struct ether_header *eh;
-   struct rl_rxsoft*rxs;
-   struct rl_desc  *cur_rx;
-   bus_dmamap_tdmamap;
-   u_int16_t   status;
-   u_int32_t   rxstat;
-   int total_len, i, s, error = 0, phyaddr;
-   u_int8_tdst[] = { 0x00, 'h', 'e', 'l', 'l', 'o' };
-   u_int8_tsrc[] = { 0x00, 'w', 'o', 'r', 'l', 'd' };
-
-   DPRINTF(("inside re_diag\n"));
-   /* Allocate a single mbuf */
-
-   MGETHDR(m0, M_DONTWAIT, MT_DATA);
-   if (m0 == NULL)
-   return (ENOBUFS);
-
-   /*
-* Initialize the NIC in test mode. This sets the chip up
-* so that it can send and receive frames, but performs the
-* following special functions:
-* - Puts receiver in promiscuous mode
-* - Enables digital loopback mode
-* - Leaves interrupts turned off
-*/
-
-   ifp->if_flags |= IFF_PROMISC;
-   sc->rl_testmode = 1;
-   re_reset(sc);
-   re_init(ifp);
-   sc->rl_flags |= RL_FLAG_LINK;
-   if (sc->sc_hwrev == RL_HWREV_8139CPLUS)
-   phyaddr = 0;
-   else
-   phyaddr = 1;
-
-   re_miibus_writereg((struct device *)sc, phyaddr, MII_BMCR,
-   BMCR_RESET);
-   for (i = 0; i < RL_TIMEOUT; i++) {
-   status = re_miibus_readreg((struct device *)sc,
-   phyaddr, MII_BMCR);
-   if (!(status & BMCR_RESET))
-   break;
-   }
-
-   re_miibus_writereg((struct device *)sc, phyaddr, MII_BMCR,
-   BMCR_LOOP);
-   CSR_WRITE_2(sc, RL_ISR, RL_INTRS);
-
-   DELAY(10);
-
-   /* Put some data in the mbuf */
-
-   eh = mtod(m0, struct ether_header *);
-   bcopy ((char *)&dst, eh->ether_dhost, ETHER_ADDR_LEN);
-   bcopy ((char *)&src, eh->ether_shost, ETHER_ADDR_LEN);
-   eh->ether_type = htons(ETHERTYPE_IP);
-   m0->m_pkthdr.len = m0->m_len = ETHER_MIN_LEN - ETHER_CRC_LEN;
-
-   /*
-* Queue the packet, start transmission.
-*/
-
-   CSR_WRITE_2(sc, RL_ISR, 0x);
-   s = splnet();
-   IFQ_ENQUEUE(&ifp->if_snd, m0, NULL, error);
-   re_start(ifp);
-   splx(s);
-   m0 = NULL;
-
-   DPRINTF(("re_diag: transmission started\n"));
-
-   /* Wait for it to propagate through the chip */
-
-   DELAY(10);
-   for (i = 0; i < RL_TIMEOUT; i

Re: re(4): tedu some unused code

2013-12-31 Thread Chris Cappuccio
Brad Smith [b...@comstyle.com] wrote:
> tedu some unused code. it has never been enabled and will not be; to
> deal with a hardware defect for rare boards. unmaintained, untested, etc.
> want to get rid of it.
> 
> Comments? OK?
> 

If RE_DIAG wasn't being compiled in, then it should be removed. The BUGS
section of re(4) needs to be updated to reflect the fact that the driver
does not detect this condition.



re(4): tedu some unused code

2013-12-30 Thread Brad Smith
tedu some unused code. it has never been enabled and will not be; to
deal with a hardware defect for rare boards. unmaintained, untested, etc.
want to get rid of it.

Comments? OK?


Index: re.c
===
RCS file: /home/cvs/src/sys/dev/ic/re.c,v
retrieving revision 1.146
diff -u -p -r1.146 re.c
--- re.c25 Oct 2013 22:48:10 -  1.146
+++ re.c31 Dec 2013 00:49:27 -
@@ -197,10 +197,6 @@ void   re_setup_intr(struct rl_softc *, in
 intre_wol(struct ifnet*, int);
 #endif
 
-#ifdef RE_DIAG
-intre_diag(struct rl_softc *);
-#endif
-
 struct cfdriver re_cd = {
0, "re", DV_IFNET
 };
@@ -615,190 +611,6 @@ re_reset(struct rl_softc *sc)
CSR_WRITE_1(sc, RL_LDPS, 1);
 }
 
-#ifdef RE_DIAG
-
-/*
- * The following routine is designed to test for a defect on some
- * 32-bit 8169 cards. Some of these NICs have the REQ64# and ACK64#
- * lines connected to the bus, however for a 32-bit only card, they
- * should be pulled high. The result of this defect is that the
- * NIC will not work right if you plug it into a 64-bit slot: DMA
- * operations will be done with 64-bit transfers, which will fail
- * because the 64-bit data lines aren't connected.
- *
- * There's no way to work around this (short of talking a soldering
- * iron to the board), however we can detect it. The method we use
- * here is to put the NIC into digital loopback mode, set the receiver
- * to promiscuous mode, and then try to send a frame. We then compare
- * the frame data we sent to what was received. If the data matches,
- * then the NIC is working correctly, otherwise we know the user has
- * a defective NIC which has been mistakenly plugged into a 64-bit PCI
- * slot. In the latter case, there's no way the NIC can work correctly,
- * so we print out a message on the console and abort the device attach.
- */
-
-int
-re_diag(struct rl_softc *sc)
-{
-   struct ifnet*ifp = &sc->sc_arpcom.ac_if;
-   struct mbuf *m0;
-   struct ether_header *eh;
-   struct rl_rxsoft*rxs;
-   struct rl_desc  *cur_rx;
-   bus_dmamap_tdmamap;
-   u_int16_t   status;
-   u_int32_t   rxstat;
-   int total_len, i, s, error = 0, phyaddr;
-   u_int8_tdst[] = { 0x00, 'h', 'e', 'l', 'l', 'o' };
-   u_int8_tsrc[] = { 0x00, 'w', 'o', 'r', 'l', 'd' };
-
-   DPRINTF(("inside re_diag\n"));
-   /* Allocate a single mbuf */
-
-   MGETHDR(m0, M_DONTWAIT, MT_DATA);
-   if (m0 == NULL)
-   return (ENOBUFS);
-
-   /*
-* Initialize the NIC in test mode. This sets the chip up
-* so that it can send and receive frames, but performs the
-* following special functions:
-* - Puts receiver in promiscuous mode
-* - Enables digital loopback mode
-* - Leaves interrupts turned off
-*/
-
-   ifp->if_flags |= IFF_PROMISC;
-   sc->rl_testmode = 1;
-   re_reset(sc);
-   re_init(ifp);
-   sc->rl_flags |= RL_FLAG_LINK;
-   if (sc->sc_hwrev == RL_HWREV_8139CPLUS)
-   phyaddr = 0;
-   else
-   phyaddr = 1;
-
-   re_miibus_writereg((struct device *)sc, phyaddr, MII_BMCR,
-   BMCR_RESET);
-   for (i = 0; i < RL_TIMEOUT; i++) {
-   status = re_miibus_readreg((struct device *)sc,
-   phyaddr, MII_BMCR);
-   if (!(status & BMCR_RESET))
-   break;
-   }
-
-   re_miibus_writereg((struct device *)sc, phyaddr, MII_BMCR,
-   BMCR_LOOP);
-   CSR_WRITE_2(sc, RL_ISR, RL_INTRS);
-
-   DELAY(10);
-
-   /* Put some data in the mbuf */
-
-   eh = mtod(m0, struct ether_header *);
-   bcopy ((char *)&dst, eh->ether_dhost, ETHER_ADDR_LEN);
-   bcopy ((char *)&src, eh->ether_shost, ETHER_ADDR_LEN);
-   eh->ether_type = htons(ETHERTYPE_IP);
-   m0->m_pkthdr.len = m0->m_len = ETHER_MIN_LEN - ETHER_CRC_LEN;
-
-   /*
-* Queue the packet, start transmission.
-*/
-
-   CSR_WRITE_2(sc, RL_ISR, 0x);
-   s = splnet();
-   IFQ_ENQUEUE(&ifp->if_snd, m0, NULL, error);
-   re_start(ifp);
-   splx(s);
-   m0 = NULL;
-
-   DPRINTF(("re_diag: transmission started\n"));
-
-   /* Wait for it to propagate through the chip */
-
-   DELAY(10);
-   for (i = 0; i < RL_TIMEOUT; i++) {
-   status = CSR_READ_2(sc, RL_ISR);
-   CSR_WRITE_2(sc, RL_ISR, status);
-   if ((status & (RL_ISR_TIMEOUT_EXPIRED|RL_ISR_RX_OK)) ==
-   (RL_ISR_TIMEOUT_EXPIRED|RL_ISR_RX_OK))
-   break;
-   DELAY(10);
-   }
-   if (i == RL_TIMEOUT) {
-   printf("%s: diagnostic failed, failed to receive packet "
-   "in loopback mode\n", sc->sc_dev.dv_xna