Source-Changes-HG archive

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

[src/trunk]: src/sys/arch/mips/cavium/dev Redo cnmac attachments - cnmacM @ g...



details:   https://anonhg.NetBSD.org/src/rev/364c36d44983
branches:  trunk
changeset: 973181:364c36d44983
user:      simonb <simonb%NetBSD.org@localhost>
date:      Tue Jun 23 05:17:13 2020 +0000

description:
Redo cnmac attachments - cnmacM @ gmxN @ pip0 @ iobus
Support SGMII mode used on CN70XX.
Most functional changes from OpenBSD octeon port.  Still more to come from
the OpenBSD driver.

diffstat:

 sys/arch/mips/cavium/dev/if_cnmac.c      |  805 ++++++------------------------
 sys/arch/mips/cavium/dev/if_cnmacvar.h   |   56 +-
 sys/arch/mips/cavium/dev/octeon_gmx.c    |  756 +++++++++++++++-------------
 sys/arch/mips/cavium/dev/octeon_gmxreg.h |   90 +++-
 sys/arch/mips/cavium/dev/octeon_gmxvar.h |   45 +-
 5 files changed, 679 insertions(+), 1073 deletions(-)

diffs (truncated from 2533 to 300 lines):

diff -r 6d2207c86df2 -r 364c36d44983 sys/arch/mips/cavium/dev/if_cnmac.c
--- a/sys/arch/mips/cavium/dev/if_cnmac.c       Tue Jun 23 05:15:33 2020 +0000
+++ b/sys/arch/mips/cavium/dev/if_cnmac.c       Tue Jun 23 05:17:13 2020 +0000
@@ -1,11 +1,33 @@
-/*     $NetBSD: if_cnmac.c,v 1.23 2020/06/22 02:26:19 simonb Exp $     */
+/*     $NetBSD: if_cnmac.c,v 1.24 2020/06/23 05:17:13 simonb Exp $     */
+
+/*
+ * Copyright (c) 2007 Internet Initiative Japan, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
 
 #include <sys/cdefs.h>
-#if 0
-__KERNEL_RCSID(0, "$NetBSD: if_cnmac.c,v 1.23 2020/06/22 02:26:19 simonb Exp $");
-#endif
-
-#include "opt_octeon.h"
+__KERNEL_RCSID(0, "$NetBSD: if_cnmac.c,v 1.24 2020/06/23 05:17:13 simonb Exp $");
 
 /*
  * If no free send buffer is available, free all the sent buffers and bail out.
@@ -30,7 +52,6 @@
 #include <sys/syslog.h>
 
 #include <net/if.h>
-#include <net/if_dl.h>
 #include <net/if_media.h>
 #include <net/if_ether.h>
 #include <net/route.h>
@@ -52,23 +73,24 @@
 #include <mips/cpuregs.h>
 
 #include <mips/cavium/octeonreg.h>
+#include <mips/cavium/octeonvar.h>
 #include <mips/cavium/include/iobusvar.h>
 
 #include <mips/cavium/dev/octeon_ciureg.h>
+#include <mips/cavium/dev/octeon_faureg.h>
+#include <mips/cavium/dev/octeon_fpareg.h>
 #include <mips/cavium/dev/octeon_gmxreg.h>
 #include <mips/cavium/dev/octeon_pipreg.h>
 #include <mips/cavium/dev/octeon_powreg.h>
-#include <mips/cavium/dev/octeon_faureg.h>
-#include <mips/cavium/dev/octeon_fpareg.h>
+#include <mips/cavium/dev/octeon_fauvar.h>
 #include <mips/cavium/dev/octeon_fpavar.h>
 #include <mips/cavium/dev/octeon_gmxvar.h>
-#include <mips/cavium/dev/octeon_fauvar.h>
-#include <mips/cavium/dev/octeon_powvar.h>
 #include <mips/cavium/dev/octeon_ipdvar.h>
 #include <mips/cavium/dev/octeon_pipvar.h>
 #include <mips/cavium/dev/octeon_pkovar.h>
-#include <mips/cavium/dev/octeon_asxvar.h>
+#include <mips/cavium/dev/octeon_powvar.h>
 #include <mips/cavium/dev/octeon_smivar.h>
+
 #include <mips/cavium/dev/if_cnmacvar.h>
 
 /*
@@ -86,8 +108,6 @@
 static void    cnmac_pip_init(struct cnmac_softc *);
 static void    cnmac_ipd_init(struct cnmac_softc *);
 static void    cnmac_pko_init(struct cnmac_softc *);
-static void    cnmac_asx_init(struct cnmac_softc *);
-static void    cnmac_smi_init(struct cnmac_softc *);
 
 static void    cnmac_board_mac_addr(uint8_t *, size_t, struct cnmac_softc *);
 
@@ -107,11 +127,8 @@
     uint64_t *);
 static inline void cnmac_send_queue_del(struct cnmac_softc *, struct mbuf **,
     uint64_t **);
-static inline int cnmac_buf_free_work(struct cnmac_softc *, uint64_t *,
-    uint64_t);
-static inline void cnmac_buf_ext_free_m(struct mbuf *, void *, size_t, void *);
-static inline void cnmac_buf_ext_free_ext(struct mbuf *, void *, size_t,
-    void *);
+static inline int cnmac_buf_free_work(struct cnmac_softc *, uint64_t *);
+static inline void cnmac_buf_ext_free(struct mbuf *, void *, size_t, void *);
 
 static int     cnmac_ioctl(struct ifnet *, u_long, void *);
 static void    cnmac_watchdog(struct ifnet *);
@@ -122,7 +139,8 @@
 static inline int cnmac_send_cmd(struct cnmac_softc *, uint64_t, uint64_t,
     int *);
 static inline uint64_t cnmac_send_makecmd_w1(int, paddr_t);
-static inline uint64_t cnmac_send_makecmd_w0(uint64_t, uint64_t, size_t, int);
+static inline uint64_t cnmac_send_makecmd_w0(uint64_t, uint64_t, size_t, int,
+    int);
 static inline int cnmac_send_makecmd_gbuf(struct cnmac_softc *, struct mbuf *,
     uint64_t *, int *);
 static inline int cnmac_send_makecmd(struct cnmac_softc *, struct mbuf *,
@@ -140,25 +158,12 @@
 
 static inline int cnmac_recv_mbuf(struct cnmac_softc *, uint64_t *,
     struct mbuf **);
-static inline int cnmac_recv_check_code(struct cnmac_softc *, uint64_t);
-static inline int cnmac_recv_check_jumbo(struct cnmac_softc *, uint64_t);
-static inline int cnmac_recv_check_link(struct cnmac_softc *, uint64_t);
 static inline int cnmac_recv_check(struct cnmac_softc *, uint64_t);
 static inline int cnmac_recv(struct cnmac_softc *, uint64_t *);
-static void    cnmac_recv_redir(struct ifnet *, struct mbuf *);
-static inline void cnmac_recv_intr(void *, uint64_t *);
-
-/* Device driver context */
-static struct  cnmac_softc *cnmac_gsc[GMX_PORT_NUNITS];
-static void    *cnmac_pow_recv_ih;
+static int     cnmac_intr(void *);
 
-/* sysctl'able parameters */
+/* device parameters */
 int            cnmac_param_pko_cmd_w0_n2 = 1;
-int            cnmac_param_pip_dyn_rs = 1;
-int            cnmac_param_redir = 0;
-int            cnmac_param_pktbuf = 0;
-int            cnmac_param_rate = 0;
-int            cnmac_param_intr = 0;
 
 CFATTACH_DECL_NEW(cnmac, sizeof(struct cnmac_softc),
     cnmac_match, cnmac_attach, NULL, NULL);
@@ -177,12 +182,14 @@
        _ENTRY(SG)
 #undef _ENTRY
 };
-struct octfpa_buf      *cnmac_pools[8/* XXX */];
+struct octfpa_buf      *cnmac_pools[FPA_NPOOLS];
 #define        cnmac_fb_pkt    cnmac_pools[OCTEON_POOL_NO_PKT]
 #define        cnmac_fb_wqe    cnmac_pools[OCTEON_POOL_NO_WQE]
 #define        cnmac_fb_cmd    cnmac_pools[OCTEON_POOL_NO_CMD]
 #define        cnmac_fb_sg     cnmac_pools[OCTEON_POOL_NO_SG]
 
+static int     cnmac_npowgroups = 0;
+
 static void
 cnmac_buf_init(struct cnmac_softc *sc)
 {
@@ -225,12 +232,18 @@
        prop_object_t clk;
        uint8_t enaddr[ETHER_ADDR_LEN];
 
+       if (cnmac_npowgroups >= OCTEON_POW_GROUP_MAX) {
+               printf(": out of POW groups\n");
+       }
+
        sc->sc_dev = self;
        sc->sc_regt = ga->ga_regt;
        sc->sc_port = ga->ga_portno;
        sc->sc_port_type = ga->ga_port_type;
        sc->sc_gmx = ga->ga_gmx;
        sc->sc_gmx_port = ga->ga_gmx_port;
+       sc->sc_smi = ga->ga_smi;
+       sc->sc_powgroup = cnmac_npowgroups++;
 
        if (sc->sc_port >= CVMSEG_LM_ETHER_COUNT) {
                /*
@@ -255,11 +268,9 @@
        }
 
        cnmac_board_mac_addr(enaddr, sizeof(enaddr), sc);
-       printf("%s: Ethernet address %s\n", device_xname(sc->sc_dev),
+       printf("%s: Ethernet address %s\n", device_xname(self),
            ether_sprintf(enaddr));
 
-       cnmac_gsc[sc->sc_port] = sc;
-
        SIMPLEQ_INIT(&sc->sc_sendq);
        sc->sc_soft_req_thresh = 15/* XXX */;
        sc->sc_ext_callback_cnt = 0;
@@ -269,19 +280,19 @@
        callout_init(&sc->sc_tick_misc_ch, 0);
        callout_init(&sc->sc_tick_free_ch, 0);
 
+       const int dv_unit = device_unit(self);
        octfau_op_init(&sc->sc_fau_done,
-           OCTEON_CVMSEG_ETHER_OFFSET(sc->sc_port, csm_ether_fau_done),
-           OCT_FAU_REG_ADDR_END - (8 * (sc->sc_port + 1))/* XXX */);
+           OCTEON_CVMSEG_ETHER_OFFSET(dv_unit, csm_ether_fau_done),
+           OCT_FAU_REG_ADDR_END - (8 * (dv_unit + 1))/* XXX */);
        octfau_op_set_8(&sc->sc_fau_done, 0);
 
        cnmac_pip_init(sc);
        cnmac_ipd_init(sc);
        cnmac_pko_init(sc);
-       cnmac_asx_init(sc);
-       cnmac_smi_init(sc);
+
+       cnmac_configure_common(sc);
 
        sc->sc_gmx_port->sc_ipd = sc->sc_ipd;
-       sc->sc_gmx_port->sc_port_asx = sc->sc_asx;
        sc->sc_gmx_port->sc_port_mii = &sc->sc_mii;
        sc->sc_gmx_port->sc_port_ec = &sc->sc_ethercom;
        /* XXX */
@@ -292,7 +303,7 @@
 
        cnmac_mediainit(sc);
 
-       strncpy(ifp->if_xname, device_xname(sc->sc_dev), sizeof(ifp->if_xname));
+       strncpy(ifp->if_xname, device_xname(self), sizeof(ifp->if_xname));
        ifp->if_softc = sc;
        ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
        ifp->if_ioctl = cnmac_ioctl;
@@ -303,10 +314,18 @@
        IFQ_SET_MAXLEN(&ifp->if_snd, uimax(GATHER_QUEUE_SIZE, IFQ_MAXLEN));
        IFQ_SET_READY(&ifp->if_snd);
 
-       /* XXX: not yet tx checksum */
+       
        ifp->if_capabilities =
+#if 0  /* XXX: no tx checksum yet */
+           IFCAP_CSUM_IPv4_Tx | IFCAP_CSUM_IPv4_Rx |
+           IFCAP_CSUM_TCPv4_Tx | IFCAP_CSUM_TCPv4_Rx |
+           IFCAP_CSUM_UDPv4_Tx | IFCAP_CSUM_UDPv4_Rx |
+           IFCAP_CSUM_TCPv6_Tx | IFCAP_CSUM_TCPv6_Rx |
+           IFCAP_CSUM_UDPv6_Tx | IFCAP_CSUM_UDPv6_Rx;
+#else
            IFCAP_CSUM_IPv4_Rx | IFCAP_CSUM_TCPv4_Rx | IFCAP_CSUM_UDPv4_Rx |
            IFCAP_CSUM_TCPv6_Rx | IFCAP_CSUM_UDPv6_Rx;
+#endif
 
        /* 802.1Q VLAN-sized frames are supported */
        sc->sc_ethercom.ec_capabilities |= ETHERCAP_VLAN_MTU;
@@ -317,32 +336,25 @@
        ether_ifattach(ifp, enaddr);
        octgmx_set_filter(sc->sc_gmx_port);
 
-       /* XXX */
-       sc->sc_rate_recv_check_link_cap.tv_sec = 1;
-       sc->sc_rate_recv_check_jumbo_cap.tv_sec = 1;
-       sc->sc_rate_recv_check_code_cap.tv_sec = 1;
-       sc->sc_rate_recv_fixup_odd_nibble_short_cap.tv_sec = 1;
-       sc->sc_rate_recv_fixup_odd_nibble_preamble_cap.tv_sec = 1;
-       sc->sc_rate_recv_fixup_odd_nibble_crc_cap.tv_sec = 1;
-       /* XXX */
-
 #if 1
        cnmac_buf_init(sc);
 #endif
 
-       if (cnmac_pow_recv_ih == NULL)
-               cnmac_pow_recv_ih
-                   = octpow_intr_establish(OCTEON_POW_GROUP_PIP,
-                       IPL_NET, cnmac_recv_intr, NULL, NULL);
+       sc->sc_ih = octeon_intr_establish(POW_WORKQ_IRQ(sc->sc_powgroup),
+           IPL_NET, cnmac_intr, sc);
+       if (sc->sc_ih == NULL)
+               panic("%s: could not set up interrupt", device_xname(self));
 
        dict = device_properties(sc->sc_gmx->sc_dev);
 
        clk = prop_dictionary_get(dict, "rgmii-tx");
-       KASSERT(clk != NULL);
-       sc->sc_gmx_port->sc_clk_tx_setting = prop_number_signed_value(clk);
+       if (clk)
+               sc->sc_gmx_port->sc_clk_tx_setting =
+                   prop_number_signed_value(clk);
        clk = prop_dictionary_get(dict, "rgmii-rx");
-       KASSERT(clk != NULL);
-       sc->sc_gmx_port->sc_clk_rx_setting = prop_number_signed_value(clk);
+       if (clk)
+               sc->sc_gmx_port->sc_clk_rx_setting =
+                   prop_number_signed_value(clk);
 }
 
 /* ---- submodules */
@@ -356,9 +368,10 @@
        pip_aa.aa_port = sc->sc_port;
        pip_aa.aa_regt = sc->sc_regt;
        pip_aa.aa_tag_type = POW_TAG_TYPE_ORDERED/* XXX */;
-       pip_aa.aa_receive_group = OCTEON_POW_GROUP_PIP;
+       pip_aa.aa_receive_group = sc->sc_powgroup;
        pip_aa.aa_ip_offset = sc->sc_ip_offset;
        octpip_init(&pip_aa, &sc->sc_pip);
+       octpip_port_config(sc->sc_pip);
 }
 
 /* XXX */
@@ -388,28 +401,6 @@



Home | Main Index | Thread Index | Old Index