Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/dev/pci - Introduce IPMI and ASF related code from FreeB...



details:   https://anonhg.NetBSD.org/src/rev/6a2af42c1422
branches:  trunk
changeset: 751205:6a2af42c1422
user:      msaitoh <msaitoh%NetBSD.org@localhost>
date:      Thu Jan 28 03:09:13 2010 +0000

description:
- Introduce IPMI and ASF related code from FreeBSD. It fixes some problems
  which occured in netboot on sparc64 and PR#32767
- move the code of disabling host interrput in bge_stop() like linux tg3
  driver.
- fix the return value of bge_eeprom_getbyte().
- remove an unused structure.
- KNF

diffstat:

 sys/dev/pci/if_bge.c    |  454 +++++++++++++++++++++++++++++++++--------------
 sys/dev/pci/if_bgereg.h |   42 +++-
 sys/dev/pci/if_bgevar.h |    9 +-
 3 files changed, 353 insertions(+), 152 deletions(-)

diffs (truncated from 852 to 300 lines):

diff -r 64be30b17273 -r 6a2af42c1422 sys/dev/pci/if_bge.c
--- a/sys/dev/pci/if_bge.c      Thu Jan 28 02:55:31 2010 +0000
+++ b/sys/dev/pci/if_bge.c      Thu Jan 28 03:09:13 2010 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_bge.c,v 1.176 2010/01/25 10:25:30 martin Exp $      */
+/*     $NetBSD: if_bge.c,v 1.177 2010/01/28 03:09:13 msaitoh Exp $     */
 
 /*
  * Copyright (c) 2001 Wind River Systems
@@ -79,7 +79,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_bge.c,v 1.176 2010/01/25 10:25:30 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_bge.c,v 1.177 2010/01/28 03:09:13 msaitoh Exp $");
 
 #include "vlan.h"
 #include "rnd.h"
@@ -180,64 +180,87 @@
 #define NBGE_RX_THRESH (sizeof(bge_rx_threshes) / sizeof(bge_rx_threshes[0]))
 
 /* XXX patchable; should be sysctl'able */
-static int     bge_auto_thresh = 1;
-static int     bge_rx_thresh_lvl;
-
-static int     bge_rxthresh_nodenum;
+static int bge_auto_thresh = 1;
+static int bge_rx_thresh_lvl;
+
+static int bge_rxthresh_nodenum;
 
 typedef int (*bge_eaddr_fcn_t)(struct bge_softc *, uint8_t[]);
 
-static int     bge_probe(device_t, cfdata_t, void *);
-static void    bge_attach(device_t, device_t, void *);
-static void    bge_release_resources(struct bge_softc *);
-static void    bge_txeof(struct bge_softc *);
-static void    bge_rxeof(struct bge_softc *);
-
-static int     bge_get_eaddr_fw(struct bge_softc *, uint8_t[]);
-static int     bge_get_eaddr_mem(struct bge_softc *, uint8_t[]);
-static int     bge_get_eaddr_nvram(struct bge_softc *, uint8_t[]);
-static int     bge_get_eaddr_eeprom(struct bge_softc *, uint8_t[]);
-static int     bge_get_eaddr(struct bge_softc *, uint8_t[]);
-
-static void    bge_tick(void *);
-static void    bge_stats_update(struct bge_softc *);
-static void    bge_stats_update_regs(struct bge_softc *);
-static int     bge_encap(struct bge_softc *, struct mbuf *, uint32_t *);
-
-static int     bge_intr(void *);
-static void    bge_start(struct ifnet *);
-static int     bge_ioctl(struct ifnet *, u_long, void *);
-static int     bge_init(struct ifnet *);
-static void    bge_stop(struct ifnet *, int);
-static void    bge_watchdog(struct ifnet *);
-static int     bge_ifmedia_upd(struct ifnet *);
-static void    bge_ifmedia_sts(struct ifnet *, struct ifmediareq *);
-
-static void    bge_setmulti(struct bge_softc *);
-
-static void    bge_handle_events(struct bge_softc *);
-static int     bge_alloc_jumbo_mem(struct bge_softc *);
+static int bge_probe(device_t, cfdata_t, void *);
+static void bge_attach(device_t, device_t, void *);
+static void bge_release_resources(struct bge_softc *);
+
+static int bge_get_eaddr_fw(struct bge_softc *, uint8_t[]);
+static int bge_get_eaddr_mem(struct bge_softc *, uint8_t[]);
+static int bge_get_eaddr_nvram(struct bge_softc *, uint8_t[]);
+static int bge_get_eaddr_eeprom(struct bge_softc *, uint8_t[]);
+static int bge_get_eaddr(struct bge_softc *, uint8_t[]);
+
+static void bge_txeof(struct bge_softc *);
+static void bge_rxeof(struct bge_softc *);
+
+static void bge_asf_driver_up (struct bge_softc *);
+static void bge_tick(void *);
+static void bge_stats_update(struct bge_softc *);
+static void bge_stats_update_regs(struct bge_softc *);
+static int bge_encap(struct bge_softc *, struct mbuf *, uint32_t *);
+
+static int bge_intr(void *);
+static void bge_start(struct ifnet *);
+static int bge_ioctl(struct ifnet *, u_long, void *);
+static int bge_init(struct ifnet *);
+static void bge_stop(struct ifnet *, int);
+static void bge_watchdog(struct ifnet *);
+static int bge_ifmedia_upd(struct ifnet *);
+static void bge_ifmedia_sts(struct ifnet *, struct ifmediareq *);
+
+static uint8_t bge_nvram_getbyte(struct bge_softc *, int, uint8_t *);
+static int bge_read_nvram(struct bge_softc *, uint8_t *, int, int);
+
+static uint8_t bge_eeprom_getbyte(struct bge_softc *, int, uint8_t *);
+static int bge_read_eeprom(struct bge_softc *, void *, int, int);
+static void bge_setmulti(struct bge_softc *);
+
+static void bge_handle_events(struct bge_softc *);
+static int bge_alloc_jumbo_mem(struct bge_softc *);
 #if 0 /* XXX */
-static void    bge_free_jumbo_mem(struct bge_softc *);
+static void bge_free_jumbo_mem(struct bge_softc *);
 #endif
-static void    *bge_jalloc(struct bge_softc *);
-static void    bge_jfree(struct mbuf *, void *, size_t, void *);
-static int     bge_newbuf_std(struct bge_softc *, int, struct mbuf *,
+static void *bge_jalloc(struct bge_softc *);
+static void bge_jfree(struct mbuf *, void *, size_t, void *);
+static int bge_newbuf_std(struct bge_softc *, int, struct mbuf *,
                               bus_dmamap_t);
-static int     bge_newbuf_jumbo(struct bge_softc *, int, struct mbuf *);
-static int     bge_init_rx_ring_std(struct bge_softc *);
-static void    bge_free_rx_ring_std(struct bge_softc *);
-static int     bge_init_rx_ring_jumbo(struct bge_softc *);
-static void    bge_free_rx_ring_jumbo(struct bge_softc *);
-static void    bge_free_tx_ring(struct bge_softc *);
-static int     bge_init_tx_ring(struct bge_softc *);
-
-static int     bge_chipinit(struct bge_softc *);
-static int     bge_blockinit(struct bge_softc *);
-static int     bge_setpowerstate(struct bge_softc *, int);
-
-static void    bge_reset(struct bge_softc *);
-static void    bge_link_upd(struct bge_softc *);
+static int bge_newbuf_jumbo(struct bge_softc *, int, struct mbuf *);
+static int bge_init_rx_ring_std(struct bge_softc *);
+static void bge_free_rx_ring_std(struct bge_softc *);
+static int bge_init_rx_ring_jumbo(struct bge_softc *);
+static void bge_free_rx_ring_jumbo(struct bge_softc *);
+static void bge_free_tx_ring(struct bge_softc *);
+static int bge_init_tx_ring(struct bge_softc *);
+
+static int bge_chipinit(struct bge_softc *);
+static int bge_blockinit(struct bge_softc *);
+static int bge_setpowerstate(struct bge_softc *, int);
+static uint32_t bge_readmem_ind(struct bge_softc *, int);
+static void bge_writemem_ind(struct bge_softc *, int, int);
+static void bge_writembx(struct bge_softc *, int, int);
+static void bge_writemem_direct(struct bge_softc *, int, int);
+static void bge_writereg_ind(struct bge_softc *, int, int);
+static void bge_set_max_readrq(struct bge_softc *);
+
+static int bge_miibus_readreg(device_t, int, int);
+static void bge_miibus_writereg(device_t, int, int, int);
+static void bge_miibus_statchg(device_t);
+
+#define        BGE_RESET_START 1
+#define        BGE_RESET_STOP  2
+static void bge_sig_post_reset(struct bge_softc *, int);
+static void bge_sig_legacy(struct bge_softc *, int);
+static void bge_sig_pre_reset(struct bge_softc *, int);
+static void bge_stop_fw(struct bge_softc *);
+static int bge_reset(struct bge_softc *);
+static void bge_link_upd(struct bge_softc *);
 
 #ifdef BGE_DEBUG
 #define DPRINTF(x)     if (bgedebug) printf x
@@ -697,6 +720,8 @@
        { 0, NULL }
 };
 
+static int bge_allow_asf = 1;
+
 CFATTACH_DECL_NEW(bge, sizeof(struct bge_softc),
     bge_probe, bge_attach, NULL, NULL);
 
@@ -717,6 +742,31 @@
        pci_conf_write(sc->sc_pc, sc->sc_pcitag, BGE_PCI_MEMWIN_DATA, val);
 }
 
+/*
+ * PCI Express only
+ */
+static void
+bge_set_max_readrq(struct bge_softc *sc)
+{
+       device_t dev;
+       pcireg_t val;
+
+       dev = sc->bge_dev;
+
+       val = pci_conf_read(sc->sc_pc, sc->sc_pcitag, sc->bge_expcap
+           + PCI_PCIE_DCSR);
+       if ((val & PCI_PCIE_DCSR_MAX_READ_REQ) !=
+           BGE_PCIE_DEVCTL_MAX_READRQ_4096) {
+                       printf("adjust device control 0x%04x ",
+                           val);
+               val &= ~PCI_PCIE_DCSR_MAX_READ_REQ;
+               val |= BGE_PCIE_DEVCTL_MAX_READRQ_4096;
+               pci_conf_write(sc->sc_pc, sc->sc_pcitag, sc->bge_expcap
+                   + PCI_PCIE_DCSR, val);
+                       printf("-> 0x%04x\n", val);
+       }
+}
+
 #ifdef notdef
 static uint32_t
 bge_readreg_ind(struct bge_softc *sc, int off)
@@ -855,7 +905,7 @@
 
        if (i == BGE_TIMEOUT * 10) {
                aprint_error_dev(sc->bge_dev, "eeprom read timed out\n");
-               return 0;
+               return 1;
        }
 
        /* Get result. */
@@ -971,7 +1021,7 @@
        }
 
        CSR_WRITE_4(sc, BGE_MI_COMM, BGE_MICMD_WRITE | BGE_MICOMM_BUSY |
-           BGE_MIPHY(phy) | BGE_MIREG(reg)|val);
+           BGE_MIPHY(phy) | BGE_MIREG(reg) | val);
 
        for (i = 0; i < BGE_TIMEOUT; i++) {
                delay(10);
@@ -1597,36 +1647,82 @@
                CSR_WRITE_4(sc, BGE_MAR0 + (i * 4), hashes[i]);
 }
 
-const int bge_swapbits[] = {
-       0,
-       BGE_MODECTL_BYTESWAP_DATA,
-       BGE_MODECTL_WORDSWAP_DATA,
-       BGE_MODECTL_BYTESWAP_NONFRAME,
-       BGE_MODECTL_WORDSWAP_NONFRAME,
-
-       BGE_MODECTL_BYTESWAP_DATA|BGE_MODECTL_WORDSWAP_DATA,
-       BGE_MODECTL_BYTESWAP_DATA|BGE_MODECTL_BYTESWAP_NONFRAME,
-       BGE_MODECTL_BYTESWAP_DATA|BGE_MODECTL_WORDSWAP_NONFRAME,
-
-       BGE_MODECTL_WORDSWAP_DATA|BGE_MODECTL_BYTESWAP_NONFRAME,
-       BGE_MODECTL_WORDSWAP_DATA|BGE_MODECTL_WORDSWAP_NONFRAME,
-
-       BGE_MODECTL_BYTESWAP_NONFRAME|BGE_MODECTL_WORDSWAP_NONFRAME,
-
-       BGE_MODECTL_BYTESWAP_DATA|BGE_MODECTL_WORDSWAP_DATA|
-           BGE_MODECTL_BYTESWAP_NONFRAME,
-       BGE_MODECTL_BYTESWAP_DATA|BGE_MODECTL_WORDSWAP_DATA|
-           BGE_MODECTL_WORDSWAP_NONFRAME,
-       BGE_MODECTL_BYTESWAP_DATA|BGE_MODECTL_BYTESWAP_NONFRAME|
-           BGE_MODECTL_WORDSWAP_NONFRAME,
-       BGE_MODECTL_WORDSWAP_DATA|BGE_MODECTL_BYTESWAP_NONFRAME|
-           BGE_MODECTL_WORDSWAP_NONFRAME,
-
-       BGE_MODECTL_BYTESWAP_DATA|BGE_MODECTL_WORDSWAP_DATA|
-           BGE_MODECTL_BYTESWAP_NONFRAME|BGE_MODECTL_WORDSWAP_NONFRAME,
-};
-
-int bge_swapindex = 0;
+static void
+bge_sig_pre_reset(sc, type)
+       struct bge_softc *sc;
+       int type;
+{
+       /*
+        * Some chips don't like this so only do this if ASF is enabled
+        */
+       if (sc->bge_asf_mode)
+               bge_writemem_ind(sc, BGE_SOFTWARE_GENCOMM, BGE_MAGIC_NUMBER);
+
+       if (sc->bge_asf_mode & ASF_NEW_HANDSHAKE) {
+               switch (type) {
+               case BGE_RESET_START:
+                       bge_writemem_ind(sc, BGE_SDI_STATUS, 0x1); /* START */
+                       break;
+               case BGE_RESET_STOP:
+                       bge_writemem_ind(sc, BGE_SDI_STATUS, 0x2); /* UNLOAD */
+                       break;
+               }
+       }
+}
+
+static void
+bge_sig_post_reset(sc, type)
+       struct bge_softc *sc;
+       int type;
+{
+       if (sc->bge_asf_mode & ASF_NEW_HANDSHAKE) {
+               switch (type) {
+               case BGE_RESET_START:
+                       bge_writemem_ind(sc, BGE_SDI_STATUS, 0x80000001);
+                       /* START DONE */
+                       break;
+               case BGE_RESET_STOP:
+                       bge_writemem_ind(sc, BGE_SDI_STATUS, 0x80000002);
+                       break;
+               }
+       }
+}
+
+static void
+bge_sig_legacy(sc, type)
+       struct bge_softc *sc;
+       int type;
+{
+       if (sc->bge_asf_mode) {
+               switch (type) {
+               case BGE_RESET_START:



Home | Main Index | Thread Index | Old Index