diff --git a/sys/conf/files.arm64 b/sys/conf/files.arm64 index 3c22663e030b..b83188b6bb28 100644 --- a/sys/conf/files.arm64 +++ b/sys/conf/files.arm64 @@ -1,662 +1,666 @@ # $FreeBSD$ ## ## Kernel ## kern/msi_if.m optional intrng kern/pic_if.m optional intrng kern/subr_devmap.c standard kern/subr_intr.c optional intrng kern/subr_physmem.c standard libkern/strlen.c standard libkern/arm64/crc32c_armv8.S standard arm/arm/generic_timer.c standard arm/arm/gic.c standard arm/arm/gic_acpi.c optional acpi arm/arm/gic_fdt.c optional fdt arm/arm/gic_if.m standard arm/arm/pmu.c standard arm/arm/pmu_acpi.c optional acpi arm/arm/pmu_fdt.c optional fdt arm64/acpica/acpi_iort.c optional acpi arm64/acpica/acpi_machdep.c optional acpi arm64/acpica/OsdEnvironment.c optional acpi arm64/acpica/acpi_wakeup.c optional acpi arm64/acpica/pci_cfgreg.c optional acpi pci arm64/arm64/autoconf.c standard arm64/arm64/bus_machdep.c standard arm64/arm64/bus_space_asm.S standard arm64/arm64/busdma_bounce.c standard arm64/arm64/busdma_machdep.c standard arm64/arm64/clock.c standard arm64/arm64/copyinout.S standard arm64/arm64/cpu_errata.c standard arm64/arm64/cpufunc_asm.S standard arm64/arm64/db_disasm.c optional ddb arm64/arm64/db_interface.c optional ddb arm64/arm64/db_trace.c optional ddb arm64/arm64/debug_monitor.c standard arm64/arm64/disassem.c optional ddb arm64/arm64/dump_machdep.c standard arm64/arm64/efirt_machdep.c optional efirt arm64/arm64/elf32_machdep.c optional compat_freebsd32 arm64/arm64/elf_machdep.c standard arm64/arm64/exception.S standard arm64/arm64/exec_machdep.c standard arm64/arm64/freebsd32_machdep.c optional compat_freebsd32 arm64/arm64/gdb_machdep.c optional gdb arm64/arm64/gicv3_its.c optional intrng fdt arm64/arm64/gic_v3.c standard arm64/arm64/gic_v3_acpi.c optional acpi arm64/arm64/gic_v3_fdt.c optional fdt arm64/arm64/hyp_stub.S standard arm64/arm64/identcpu.c standard arm64/arm64/locore.S standard no-obj arm64/arm64/machdep.c standard arm64/arm64/machdep_boot.c standard arm64/arm64/mem.c standard arm64/arm64/memcmp.S standard arm64/arm64/memcpy.S standard arm64/arm64/memset.S standard arm64/arm64/minidump_machdep.c standard arm64/arm64/mp_machdep.c optional smp arm64/arm64/nexus.c standard arm64/arm64/ofw_machdep.c optional fdt arm64/arm64/ptrauth.c standard \ compile-with "${NORMAL_C:N-mbranch-protection*}" arm64/arm64/pmap.c standard arm64/arm64/ptrace_machdep.c standard arm64/arm64/sigtramp.S standard arm64/arm64/stack_machdep.c optional ddb | stack arm64/arm64/strcmp.S standard arm64/arm64/strncmp.S standard arm64/arm64/support_ifunc.c standard arm64/arm64/support.S standard arm64/arm64/swtch.S standard arm64/arm64/sys_machdep.c standard arm64/arm64/trap.c standard arm64/arm64/uio_machdep.c standard arm64/arm64/uma_machdep.c standard arm64/arm64/undefined.c standard arm64/arm64/unwind.c optional ddb | kdtrace_hooks | stack arm64/arm64/vfp.c standard arm64/arm64/vm_machdep.c standard arm64/coresight/coresight.c standard arm64/coresight/coresight_acpi.c optional acpi arm64/coresight/coresight_fdt.c optional fdt arm64/coresight/coresight_if.m standard arm64/coresight/coresight_cmd.c standard arm64/coresight/coresight_cpu_debug.c optional fdt arm64/coresight/coresight_etm4x.c standard arm64/coresight/coresight_etm4x_acpi.c optional acpi arm64/coresight/coresight_etm4x_fdt.c optional fdt arm64/coresight/coresight_funnel.c standard arm64/coresight/coresight_funnel_acpi.c optional acpi arm64/coresight/coresight_funnel_fdt.c optional fdt arm64/coresight/coresight_replicator.c standard arm64/coresight/coresight_replicator_acpi.c optional acpi arm64/coresight/coresight_replicator_fdt.c optional fdt arm64/coresight/coresight_tmc.c standard arm64/coresight/coresight_tmc_acpi.c optional acpi arm64/coresight/coresight_tmc_fdt.c optional fdt arm64/iommu/iommu.c optional iommu arm64/iommu/iommu_if.m optional iommu arm64/iommu/iommu_pmap.c optional iommu arm64/iommu/smmu.c optional iommu arm64/iommu/smmu_acpi.c optional iommu acpi arm64/iommu/smmu_fdt.c optional iommu fdt arm64/iommu/smmu_quirks.c optional iommu dev/iommu/busdma_iommu.c optional iommu dev/iommu/iommu_gas.c optional iommu crypto/armv8/armv8_crypto.c optional armv8crypto armv8_crypto_wrap.o optional armv8crypto \ dependency "$S/crypto/armv8/armv8_crypto_wrap.c" \ compile-with "${CC} -c ${CFLAGS:C/^-O2$/-O3/:N-nostdinc:N-mgeneral-regs-only} -I$S/crypto/armv8/ ${WERROR} ${NO_WCAST_QUAL} -march=armv8-a+crypto ${.IMPSRC}" \ no-implicit-rule \ clean "armv8_crypto_wrap.o" aesv8-armx.o optional armv8crypto | ossl \ dependency "$S/crypto/openssl/aarch64/aesv8-armx.S" \ compile-with "${CC} -c ${CFLAGS:C/^-O2$/-O3/:N-nostdinc:N-mgeneral-regs-only} -I$S/crypto/armv8/ ${WERROR} ${NO_WCAST_QUAL} -march=armv8-a+crypto ${.IMPSRC}" \ no-implicit-rule \ clean "aesv8-armx.o" ghashv8-armx.o optional armv8crypto \ dependency "$S/crypto/openssl/aarch64/ghashv8-armx.S" \ compile-with "${CC} -c ${CFLAGS:C/^-O2$/-O3/:N-nostdinc:N-mgeneral-regs-only} -I$S/crypto/armv8/ ${WERROR} ${NO_WCAST_QUAL} -march=armv8-a+crypto ${.IMPSRC}" \ no-implicit-rule \ clean "ghashv8-armx.o" crypto/des/des_enc.c optional netsmb crypto/openssl/ossl_aarch64.c optional ossl crypto/openssl/aarch64/chacha-armv8.S optional ossl \ compile-with "${CC} -c ${CFLAGS:N-mgeneral-regs-only} ${WERROR} ${.IMPSRC}" crypto/openssl/aarch64/poly1305-armv8.S optional ossl \ compile-with "${CC} -c ${CFLAGS:N-mgeneral-regs-only} ${WERROR} ${.IMPSRC}" crypto/openssl/aarch64/sha1-armv8.S optional ossl \ compile-with "${CC} -c ${CFLAGS:N-mgeneral-regs-only} ${WERROR} ${.IMPSRC}" crypto/openssl/aarch64/sha256-armv8.S optional ossl \ compile-with "${CC} -c ${CFLAGS:N-mgeneral-regs-only} ${WERROR} ${.IMPSRC}" crypto/openssl/aarch64/sha512-armv8.S optional ossl \ compile-with "${CC} -c ${CFLAGS:N-mgeneral-regs-only} ${WERROR} ${.IMPSRC}" crypto/openssl/aarch64/vpaes-armv8.S optional ossl \ compile-with "${CC} -c ${CFLAGS:N-mgeneral-regs-only} ${WERROR} ${.IMPSRC}" dev/acpica/acpi_bus_if.m optional acpi dev/acpica/acpi_if.m optional acpi dev/acpica/acpi_pci_link.c optional acpi pci dev/acpica/acpi_pcib.c optional acpi pci dev/acpica/acpi_pxm.c optional acpi dev/ahci/ahci_generic.c optional ahci cddl/dev/dtrace/aarch64/dtrace_asm.S optional dtrace compile-with "${DTRACE_S}" cddl/dev/dtrace/aarch64/dtrace_subr.c optional dtrace compile-with "${DTRACE_C}" cddl/dev/fbt/aarch64/fbt_isa.c optional dtrace_fbt | dtraceall compile-with "${FBT_C}" contrib/openzfs/module/icp/asm-aarch64/blake3/b3_aarch64_sse2.S optional zfs compile-with "${ZFS_S:N-mgeneral-regs-only}" contrib/openzfs/module/icp/asm-aarch64/blake3/b3_aarch64_sse41.S optional zfs compile-with "${ZFS_S:N-mgeneral-regs-only}" ## ## ASoC support ## dev/sound/fdt/audio_dai_if.m optional sound fdt dev/sound/fdt/audio_soc.c optional sound fdt dev/sound/fdt/dummy_codec.c optional sound fdt dev/sound/fdt/simple_amplifier.c optional sound fdt ## ## Device drivers ## dev/axgbe/if_axgbe.c optional axa fdt dev/axgbe/xgbe-desc.c optional axa fdt dev/axgbe/xgbe-dev.c optional axa fdt dev/axgbe/xgbe-drv.c optional axa fdt dev/axgbe/xgbe-mdio.c optional axa fdt dev/axgbe/xgbe-sysctl.c optional axa fdt dev/axgbe/xgbe-txrx.c optional axa fdt dev/axgbe/xgbe_osdep.c optional axa fdt dev/axgbe/xgbe-phy-v1.c optional axa fdt dev/cpufreq/cpufreq_dt.c optional cpufreq fdt dev/dpaa2/dpaa2_bp.c optional soc_nxp_ls dpaa2 dev/dpaa2/dpaa2_cmd_if.m optional soc_nxp_ls dpaa2 dev/dpaa2/dpaa2_con.c optional soc_nxp_ls dpaa2 dev/dpaa2/dpaa2_io.c optional soc_nxp_ls dpaa2 dev/dpaa2/dpaa2_mac.c optional soc_nxp_ls dpaa2 dev/dpaa2/dpaa2_mc.c optional soc_nxp_ls dpaa2 dev/dpaa2/dpaa2_mc_acpi.c optional soc_nxp_ls dpaa2 acpi dev/dpaa2/dpaa2_mc_fdt.c optional soc_nxp_ls dpaa2 fdt dev/dpaa2/dpaa2_mc_if.m optional soc_nxp_ls dpaa2 dev/dpaa2/dpaa2_mcp.c optional soc_nxp_ls dpaa2 dev/dpaa2/dpaa2_ni.c optional soc_nxp_ls dpaa2 dev/dpaa2/dpaa2_rc.c optional soc_nxp_ls dpaa2 dev/dpaa2/dpaa2_swp.c optional soc_nxp_ls dpaa2 dev/dpaa2/dpaa2_swp_if.m optional soc_nxp_ls dpaa2 dev/dpaa2/memac_mdio_acpi.c optional soc_nxp_ls dpaa2 acpi dev/dpaa2/memac_mdio_common.c optional soc_nxp_ls dpaa2 acpi | soc_nxp_ls dpaa2 fdt dev/dpaa2/memac_mdio_fdt.c optional soc_nxp_ls dpaa2 fdt dev/dpaa2/memac_mdio_if.m optional soc_nxp_ls dpaa2 acpi | soc_nxp_ls dpaa2 fdt dev/dwc/if_dwc.c optional fdt dwc_rk soc_rockchip_rk3328 | fdt dwc_rk soc_rockchip_rk3399 | fdt dwc_socfpga soc_intel_stratix10 dev/dwc/if_dwc_if.m optional fdt dwc_rk soc_rockchip_rk3328 | fdt dwc_rk soc_rockchip_rk3399 | fdt dwc_socfpga soc_intel_stratix10 dev/enetc/enetc_mdio.c optional enetc soc_nxp_ls dev/enetc/if_enetc.c optional enetc iflib pci fdt soc_nxp_ls +dev/eqos/if_eqos.c optional eqos +dev/eqos/if_eqos_if.m optional eqos +dev/eqos/if_eqos_fdt.c optional eqos fdt + dev/etherswitch/felix/felix.c optional enetc etherswitch fdt felix pci soc_nxp_ls dev/firmware/arm/scmi.c optional fdt scmi dev/firmware/arm/scmi_clk.c optional fdt scmi dev/firmware/arm/scmi_shmem.c optional fdt scmi dev/gpio/pl061.c optional pl061 gpio dev/gpio/pl061_acpi.c optional pl061 gpio acpi dev/gpio/pl061_fdt.c optional pl061 gpio fdt dev/gpio/qoriq_gpio.c optional soc_nxp_ls gpio fdt dev/hwpmc/hwpmc_arm64.c optional hwpmc dev/hwpmc/hwpmc_arm64_md.c optional hwpmc dev/hwpmc/hwpmc_cmn600.c optional hwpmc acpi arm64/arm64/cmn600.c optional hwpmc acpi dev/hwpmc/hwpmc_dmc620.c optional hwpmc acpi dev/hwpmc/pmu_dmc620.c optional hwpmc acpi # Microsoft Hyper-V dev/hyperv/vmbus/hyperv.c optional hyperv acpi dev/hyperv/vmbus/aarch64/hyperv_aarch64.c optional hyperv acpi dev/hyperv/vmbus/vmbus.c optional hyperv acpi pci dev/hyperv/vmbus/aarch64/vmbus_aarch64.c optional hyperv acpi dev/hyperv/vmbus/vmbus_if.m optional hyperv acpi dev/hyperv/vmbus/vmbus_res.c optional hyperv acpi dev/hyperv/vmbus/vmbus_xact.c optional hyperv acpi dev/hyperv/vmbus/aarch64/hyperv_machdep.c optional hyperv acpi dev/hyperv/vmbus/vmbus_chan.c optional hyperv acpi dev/hyperv/vmbus/hyperv_busdma.c optional hyperv acpi dev/hyperv/vmbus/vmbus_br.c optional hyperv acpi dev/hyperv/storvsc/hv_storvsc_drv_freebsd.c optional hyperv acpi dev/hyperv/utilities/vmbus_timesync.c optional hyperv acpi dev/hyperv/utilities/vmbus_heartbeat.c optional hyperv acpi dev/hyperv/utilities/vmbus_ic.c optional hyperv acpi dev/hyperv/utilities/vmbus_shutdown.c optional hyperv acpi dev/hyperv/utilities/hv_kvp.c optional hyperv acpi dev/hyperv/netvsc/hn_nvs.c optional hyperv acpi dev/hyperv/netvsc/hn_rndis.c optional hyperv acpi dev/hyperv/netvsc/if_hn.c optional hyperv acpi dev/ice/if_ice_iflib.c optional ice pci \ compile-with "${NORMAL_C} -I$S/dev/ice" dev/ice/ice_lib.c optional ice pci \ compile-with "${NORMAL_C} -I$S/dev/ice" dev/ice/ice_osdep.c optional ice pci \ compile-with "${NORMAL_C} -I$S/dev/ice" dev/ice/ice_resmgr.c optional ice pci \ compile-with "${NORMAL_C} -I$S/dev/ice" dev/ice/ice_strings.c optional ice pci \ compile-with "${NORMAL_C} -I$S/dev/ice" dev/ice/ice_iflib_recovery_txrx.c optional ice pci \ compile-with "${NORMAL_C} -I$S/dev/ice" dev/ice/ice_iflib_txrx.c optional ice pci \ compile-with "${NORMAL_C} -I$S/dev/ice" dev/ice/ice_common.c optional ice pci \ compile-with "${NORMAL_C} -I$S/dev/ice" dev/ice/ice_controlq.c optional ice pci \ compile-with "${NORMAL_C} -I$S/dev/ice" dev/ice/ice_dcb.c optional ice pci \ compile-with "${NORMAL_C} -I$S/dev/ice" dev/ice/ice_flex_pipe.c optional ice pci \ compile-with "${NORMAL_C} -I$S/dev/ice" dev/ice/ice_flow.c optional ice pci \ compile-with "${NORMAL_C} -I$S/dev/ice" dev/ice/ice_nvm.c optional ice pci \ compile-with "${NORMAL_C} -I$S/dev/ice" dev/ice/ice_sched.c optional ice pci \ compile-with "${NORMAL_C} -I$S/dev/ice" dev/ice/ice_switch.c optional ice pci \ compile-with "${NORMAL_C} -I$S/dev/ice" dev/ice/ice_vlan_mode.c optional ice pci \ compile-with "${NORMAL_C} -I$S/dev/ice" dev/ice/ice_fw_logging.c optional ice pci \ compile-with "${NORMAL_C} -I$S/dev/ice" dev/ice/ice_fwlog.c optional ice pci \ compile-with "${NORMAL_C} -I$S/dev/ice" dev/ice/ice_rdma.c optional ice pci \ compile-with "${NORMAL_C} -I$S/dev/ice" dev/ice/irdma_if.m optional ice pci \ compile-with "${NORMAL_M} -I$S/dev/ice" dev/ice/irdma_di_if.m optional ice pci \ compile-with "${NORMAL_M} -I$S/dev/ice" ice_ddp.c optional ice_ddp \ compile-with "${AWK} -f $S/tools/fw_stub.awk ice_ddp.fw:ice_ddp:0x01031b00 -mice_ddp -c${.TARGET}" \ no-ctfconvert no-implicit-rule before-depend local \ clean "ice_ddp.c" ice_ddp.fwo optional ice_ddp \ dependency "ice_ddp.fw" \ compile-with "${NORMAL_FWO}" \ no-implicit-rule \ clean "ice_ddp.fwo" ice_ddp.fw optional ice_ddp \ dependency "$S/contrib/dev/ice/ice-1.3.27.0.pkg" \ compile-with "${CP} $S/contrib/dev/ice/ice-1.3.27.0.pkg ice_ddp.fw" \ no-obj no-implicit-rule \ clean "ice_ddp.fw" dev/iicbus/sy8106a.c optional sy8106a fdt dev/iicbus/twsi/mv_twsi.c optional twsi fdt dev/iicbus/twsi/a10_twsi.c optional twsi fdt dev/iicbus/twsi/twsi.c optional twsi fdt dev/ipmi/ipmi.c optional ipmi dev/ipmi/ipmi_acpi.c optional ipmi acpi dev/ipmi/ipmi_kcs.c optional ipmi dev/ipmi/ipmi_smic.c optional ipmi dev/mailbox/arm/arm_doorbell.c optional fdt arm_doorbell dev/mbox/mbox_if.m optional soc_brcm_bcm2837 dev/mmc/host/dwmmc.c optional dwmmc fdt dev/mmc/host/dwmmc_altera.c optional dwmmc dwmmc_altera fdt dev/mmc/host/dwmmc_hisi.c optional dwmmc dwmmc_hisi fdt dev/mmc/host/dwmmc_rockchip.c optional dwmmc rk_dwmmc fdt dev/neta/if_mvneta_fdt.c optional neta fdt dev/neta/if_mvneta.c optional neta mdio mii fdt dev/ofw/ofw_cpu.c optional fdt dev/ofw/ofw_pci.c optional fdt pci dev/ofw/ofw_pcib.c optional fdt pci dev/pci/controller/pci_n1sdp.c optional pci_n1sdp acpi dev/pci/pci_host_generic.c optional pci dev/pci/pci_host_generic_acpi.c optional pci acpi dev/pci/pci_host_generic_fdt.c optional pci fdt dev/pci/pci_dw_mv.c optional pci fdt dev/pci/pci_dw.c optional pci fdt dev/pci/pci_dw_if.m optional pci fdt dev/psci/psci.c standard dev/psci/smccc_arm64.S standard dev/psci/smccc.c standard dev/safexcel/safexcel.c optional safexcel fdt dev/sdhci/sdhci_xenon.c optional sdhci_xenon sdhci dev/sdhci/sdhci_xenon_acpi.c optional sdhci_xenon sdhci acpi dev/sdhci/sdhci_xenon_fdt.c optional sdhci_xenon sdhci fdt dev/sram/mmio_sram.c optional fdt mmio_sram dev/sram/mmio_sram_if.m optional fdt mmio_sram dev/uart/uart_cpu_arm64.c optional uart dev/uart/uart_dev_mu.c optional uart uart_mu fdt dev/uart/uart_dev_pl011.c optional uart pl011 dev/usb/controller/dwc_otg_hisi.c optional dwcotg fdt soc_hisi_hi6220 dev/usb/controller/dwc3.c optional xhci acpi dwc3 | xhci fdt dwc3 dev/usb/controller/ehci_mv.c optional ehci_mv fdt dev/usb/controller/generic_ehci.c optional ehci dev/usb/controller/generic_ehci_acpi.c optional ehci acpi dev/usb/controller/generic_ehci_fdt.c optional ehci fdt dev/usb/controller/generic_ohci.c optional ohci fdt dev/usb/controller/generic_usb_if.m optional ohci fdt dev/usb/controller/musb_otg_allwinner.c optional musb fdt soc_allwinner_a64 dev/usb/controller/usb_nop_xceiv.c optional fdt dev/usb/controller/generic_xhci.c optional xhci dev/usb/controller/generic_xhci_acpi.c optional xhci acpi dev/usb/controller/generic_xhci_fdt.c optional xhci fdt dev/vnic/mrml_bridge.c optional vnic fdt dev/vnic/nic_main.c optional vnic pci dev/vnic/nicvf_main.c optional vnic pci pci_iov dev/vnic/nicvf_queues.c optional vnic pci pci_iov dev/vnic/thunder_bgx_fdt.c optional soc_cavm_thunderx pci vnic fdt dev/vnic/thunder_bgx.c optional soc_cavm_thunderx pci vnic pci dev/vnic/thunder_mdio_fdt.c optional soc_cavm_thunderx pci vnic fdt dev/vnic/thunder_mdio.c optional soc_cavm_thunderx pci vnic dev/vnic/lmac_if.m optional inet | inet6 | vnic ## ## SoC Support ## # Allwinner common files arm/allwinner/a10_timer.c optional a10_timer fdt arm/allwinner/a10_codec.c optional sound a10_codec fdt arm/allwinner/a31_dmac.c optional a31_dmac fdt arm/allwinner/a33_codec.c optional fdt sound a33_codec arm/allwinner/a64/sun50i_a64_acodec.c optional fdt sound a64_codec arm/allwinner/sunxi_dma_if.m optional a31_dmac arm/allwinner/aw_cir.c optional evdev aw_cir fdt arm/allwinner/aw_dwc3.c optional aw_dwc3 fdt arm/allwinner/aw_gpio.c optional gpio aw_gpio fdt arm/allwinner/aw_i2s.c optional fdt sound aw_i2s arm/allwinner/aw_mmc.c optional mmc aw_mmc fdt | mmccam aw_mmc fdt arm/allwinner/aw_nmi.c optional aw_nmi fdt \ compile-with "${NORMAL_C} -I$S/contrib/device-tree/include" arm/allwinner/aw_pwm.c optional aw_pwm fdt arm/allwinner/aw_r_intc.c optional aw_r_intc fdt arm/allwinner/aw_rsb.c optional aw_rsb fdt arm/allwinner/aw_rtc.c optional aw_rtc fdt arm/allwinner/aw_sid.c optional aw_sid nvmem fdt arm/allwinner/aw_spi.c optional aw_spi fdt arm/allwinner/aw_syscon.c optional aw_syscon syscon fdt arm/allwinner/aw_thermal.c optional aw_thermal nvmem fdt arm/allwinner/aw_usbphy.c optional ehci aw_usbphy fdt arm/allwinner/aw_usb3phy.c optional xhci aw_usbphy fdt arm/allwinner/aw_wdog.c optional aw_wdog fdt arm/allwinner/axp81x.c optional axp81x fdt arm/allwinner/if_awg.c optional awg syscon aw_sid nvmem fdt # Allwinner clock driver arm/allwinner/clkng/aw_ccung.c optional aw_ccu fdt arm/allwinner/clkng/aw_clk_frac.c optional aw_ccu fdt arm/allwinner/clkng/aw_clk_m.c optional aw_ccu fdt arm/allwinner/clkng/aw_clk_mipi.c optional aw_ccu fdt arm/allwinner/clkng/aw_clk_nkmp.c optional aw_ccu fdt arm/allwinner/clkng/aw_clk_nm.c optional aw_ccu fdt arm/allwinner/clkng/aw_clk_nmm.c optional aw_ccu fdt arm/allwinner/clkng/aw_clk_np.c optional aw_ccu fdt arm/allwinner/clkng/aw_clk_prediv_mux.c optional aw_ccu fdt arm/allwinner/clkng/ccu_a64.c optional soc_allwinner_a64 aw_ccu fdt arm/allwinner/clkng/ccu_h3.c optional soc_allwinner_h5 aw_ccu fdt arm/allwinner/clkng/ccu_h6.c optional soc_allwinner_h6 aw_ccu fdt arm/allwinner/clkng/ccu_h6_r.c optional soc_allwinner_h6 aw_ccu fdt arm/allwinner/clkng/ccu_sun8i_r.c optional aw_ccu fdt arm/allwinner/clkng/ccu_de2.c optional aw_ccu fdt # Allwinner padconf files arm/allwinner/a64/a64_padconf.c optional soc_allwinner_a64 fdt arm/allwinner/a64/a64_r_padconf.c optional soc_allwinner_a64 fdt arm/allwinner/h3/h3_padconf.c optional soc_allwinner_h5 fdt arm/allwinner/h3/h3_r_padconf.c optional soc_allwinner_h5 fdt arm/allwinner/h6/h6_padconf.c optional soc_allwinner_h6 fdt arm/allwinner/h6/h6_r_padconf.c optional soc_allwinner_h6 fdt # Altera/Intel dev/altera/dwc/if_dwc_socfpga.c optional fdt dwc_socfpga arm64/intel/firmware.c optional soc_intel_stratix10 fdt arm64/intel/stratix10-soc-fpga-mgr.c optional soc_intel_stratix10 fdt arm64/intel/stratix10-svc.c optional soc_intel_stratix10 fdt # Annapurna arm/annapurna/alpine/alpine_ccu.c optional al_ccu fdt arm/annapurna/alpine/alpine_nb_service.c optional al_nb_service fdt arm/annapurna/alpine/alpine_pci.c optional al_pci fdt arm/annapurna/alpine/alpine_pci_msix.c optional al_pci fdt arm/annapurna/alpine/alpine_serdes.c optional al_serdes fdt \ no-depend \ compile-with "${CC} -c -o ${.TARGET} ${CFLAGS} -I$S/contrib/alpine-hal -I$S/contrib/alpine-hal/eth ${.IMPSRC}" # Broadcom arm64/broadcom/brcmmdio/mdio_mux_iproc.c optional soc_brcm_ns2 fdt arm64/broadcom/brcmmdio/mdio_nexus_iproc.c optional soc_brcm_ns2 fdt arm64/broadcom/brcmmdio/mdio_ns2_pcie_phy.c optional soc_brcm_ns2 fdt pci arm64/broadcom/genet/if_genet.c optional soc_brcm_bcm2838 fdt genet arm/broadcom/bcm2835/bcm2835_audio.c optional sound vchiq fdt \ compile-with "${NORMAL_C} -DUSE_VCHIQ_ARM -D__VCCOREVER__=0x04000000 -I$S/contrib/vchiq" arm/broadcom/bcm2835/bcm2835_bsc.c optional bcm2835_bsc fdt arm/broadcom/bcm2835/bcm2835_clkman.c optional soc_brcm_bcm2837 fdt | soc_brcm_bcm2838 fdt arm/broadcom/bcm2835/bcm2835_cpufreq.c optional soc_brcm_bcm2837 fdt | soc_brcm_bcm2838 fdt arm/broadcom/bcm2835/bcm2835_dma.c optional soc_brcm_bcm2837 fdt | soc_brcm_bcm2838 fdt arm/broadcom/bcm2835/bcm2835_fbd.c optional vt soc_brcm_bcm2837 fdt | vt soc_brcm_bcm2838 fdt arm/broadcom/bcm2835/bcm2835_firmware.c optional soc_brcm_bcm2837 fdt | soc_brcm_bcm2838 fdt arm/broadcom/bcm2835/bcm2835_ft5406.c optional evdev bcm2835_ft5406 fdt arm/broadcom/bcm2835/bcm2835_gpio.c optional gpio soc_brcm_bcm2837 fdt | gpio soc_brcm_bcm2838 fdt arm/broadcom/bcm2835/bcm2835_intr.c optional soc_brcm_bcm2837 fdt | soc_brcm_bcm2838 fdt arm/broadcom/bcm2835/bcm2835_mbox.c optional soc_brcm_bcm2837 fdt | soc_brcm_bcm2838 fdt arm/broadcom/bcm2835/bcm2835_rng.c optional !random_loadable soc_brcm_bcm2837 fdt | !random_loadable soc_brcm_bcm2838 fdt arm/broadcom/bcm2835/bcm2835_sdhci.c optional sdhci soc_brcm_bcm2837 fdt | sdhci soc_brcm_bcm2838 fdt arm/broadcom/bcm2835/bcm2835_sdhost.c optional sdhci soc_brcm_bcm2837 fdt | sdhci soc_brcm_bcm2838 fdt arm/broadcom/bcm2835/bcm2835_spi.c optional bcm2835_spi fdt arm/broadcom/bcm2835/bcm2835_vcbus.c optional soc_brcm_bcm2837 fdt | soc_brcm_bcm2838 fdt arm/broadcom/bcm2835/bcm2835_vcio.c optional soc_brcm_bcm2837 fdt | soc_brcm_bcm2838 fdt arm/broadcom/bcm2835/bcm2835_wdog.c optional soc_brcm_bcm2837 fdt | soc_brcm_bcm2838 fdt arm/broadcom/bcm2835/bcm2836.c optional soc_brcm_bcm2837 fdt | soc_brcm_bcm2838 fdt arm/broadcom/bcm2835/bcm283x_dwc_fdt.c optional dwcotg fdt soc_brcm_bcm2837 | dwcotg fdt soc_brcm_bcm2838 arm/broadcom/bcm2835/bcm2838_pci.c optional soc_brcm_bcm2838 fdt pci arm/broadcom/bcm2835/bcm2838_xhci.c optional soc_brcm_bcm2838 fdt pci xhci arm/broadcom/bcm2835/raspberrypi_gpio.c optional soc_brcm_bcm2837 gpio fdt | soc_brcm_bcm2838 gpio fdt contrib/vchiq/interface/compat/vchi_bsd.c optional vchiq soc_brcm_bcm2837 \ compile-with "${NORMAL_C} -DUSE_VCHIQ_ARM -D__VCCOREVER__=0x04000000 -I$S/contrib/vchiq" contrib/vchiq/interface/vchiq_arm/vchiq_2835_arm.c optional vchiq soc_brcm_bcm2837 \ compile-with "${NORMAL_C} -Wno-unused -DUSE_VCHIQ_ARM -D__VCCOREVER__=0x04000000 -I$S/contrib/vchiq" contrib/vchiq/interface/vchiq_arm/vchiq_arm.c optional vchiq soc_brcm_bcm2837 \ compile-with "${NORMAL_C} -Wno-unused -DUSE_VCHIQ_ARM -D__VCCOREVER__=0x04000000 -I$S/contrib/vchiq" contrib/vchiq/interface/vchiq_arm/vchiq_connected.c optional vchiq soc_brcm_bcm2837 \ compile-with "${NORMAL_C} -DUSE_VCHIQ_ARM -D__VCCOREVER__=0x04000000 -I$S/contrib/vchiq" contrib/vchiq/interface/vchiq_arm/vchiq_core.c optional vchiq soc_brcm_bcm2837 \ compile-with "${NORMAL_C} -DUSE_VCHIQ_ARM -D__VCCOREVER__=0x04000000 -I$S/contrib/vchiq" contrib/vchiq/interface/vchiq_arm/vchiq_kern_lib.c optional vchiq soc_brcm_bcm2837 \ compile-with "${NORMAL_C} -DUSE_VCHIQ_ARM -D__VCCOREVER__=0x04000000 -I$S/contrib/vchiq" contrib/vchiq/interface/vchiq_arm/vchiq_kmod.c optional vchiq soc_brcm_bcm2837 \ compile-with "${NORMAL_C} -DUSE_VCHIQ_ARM -D__VCCOREVER__=0x04000000 -I$S/contrib/vchiq" contrib/vchiq/interface/vchiq_arm/vchiq_shim.c optional vchiq soc_brcm_bcm2837 \ compile-with "${NORMAL_C} -DUSE_VCHIQ_ARM -D__VCCOREVER__=0x04000000 -I$S/contrib/vchiq" contrib/vchiq/interface/vchiq_arm/vchiq_util.c optional vchiq soc_brcm_bcm2837 \ compile-with "${NORMAL_C} -DUSE_VCHIQ_ARM -D__VCCOREVER__=0x04000000 -I$S/contrib/vchiq" # Cavium arm64/cavium/thunder_pcie_fdt.c optional soc_cavm_thunderx pci fdt arm64/cavium/thunder_pcie_pem.c optional soc_cavm_thunderx pci arm64/cavium/thunder_pcie_pem_fdt.c optional soc_cavm_thunderx pci fdt arm64/cavium/thunder_pcie_common.c optional soc_cavm_thunderx pci # i.MX8 Clock support arm64/freescale/imx/imx8mq_ccm.c optional fdt soc_freescale_imx8 arm64/freescale/imx/clk/imx_clk_gate.c optional fdt soc_freescale_imx8 arm64/freescale/imx/clk/imx_clk_mux.c optional fdt soc_freescale_imx8 arm64/freescale/imx/clk/imx_clk_composite.c optional fdt soc_freescale_imx8 arm64/freescale/imx/clk/imx_clk_sscg_pll.c optional fdt soc_freescale_imx8 arm64/freescale/imx/clk/imx_clk_frac_pll.c optional fdt soc_freescale_imx8 # iMX drivers arm/freescale/imx/imx_gpio.c optional gpio soc_freescale_imx8 fdt arm/freescale/imx/imx_i2c.c optional fsliic arm/freescale/imx/imx_machdep.c optional fdt soc_freescale_imx8 arm64/freescale/imx/imx7gpc.c optional fdt soc_freescale_imx8 dev/ffec/if_ffec.c optional ffec # Marvell arm/mv/a37x0_gpio.c optional a37x0_gpio gpio fdt arm/mv/a37x0_iic.c optional a37x0_iic iicbus fdt arm/mv/a37x0_spi.c optional a37x0_spi spibus fdt arm/mv/clk/a37x0_tbg.c optional a37x0_tbg clk fdt syscon arm/mv/clk/a37x0_xtal.c optional a37x0_xtal clk fdt syscon arm/mv/armada38x/armada38x_rtc.c optional mv_rtc fdt arm/mv/gpio.c optional mv_gpio fdt arm/mv/mvebu_gpio.c optional mv_gpio fdt arm/mv/mvebu_pinctrl.c optional mvebu_pinctrl fdt arm/mv/mv_ap806_clock.c optional soc_marvell_8k fdt arm/mv/mv_ap806_gicp.c optional mv_ap806_gicp fdt arm/mv/mv_ap806_sei.c optional mv_ap806_sei fdt arm/mv/mv_cp110_clock.c optional soc_marvell_8k fdt arm/mv/mv_cp110_icu.c optional mv_cp110_icu fdt arm/mv/mv_cp110_icu_bus.c optional mv_cp110_icu fdt arm/mv/mv_thermal.c optional soc_marvell_8k mv_thermal fdt arm/mv/clk/a37x0_tbg_pll.c optional a37x0_tbg clk fdt syscon arm/mv/clk/a37x0_periph_clk_driver.c optional a37x0_nb_periph a37x0_sb_periph clk fdt syscon arm/mv/clk/a37x0_nb_periph_clk_driver.c optional a37x0_nb_periph clk fdt syscon arm/mv/clk/a37x0_sb_periph_clk_driver.c optional a37x0_sb_periph clk fdt syscon arm/mv/clk/periph.c optional a37x0_nb_periph a37x0_sb_periph clk fdt syscon arm/mv/clk/periph_clk_d.c optional a37x0_nb_periph a37x0_sb_periph clk fdt syscon arm/mv/clk/periph_clk_fixed.c optional a37x0_nb_periph a37x0_sb_periph clk fdt syscon arm/mv/clk/periph_clk_gate.c optional a37x0_nb_periph a37x0_sb_periph clk fdt syscon arm/mv/clk/periph_clk_mux_gate.c optional a37x0_nb_periph a37x0_sb_periph clk fdt syscon # NVidia arm/nvidia/tegra_abpmisc.c optional fdt soc_nvidia_tegra210 arm/nvidia/tegra_ahci.c optional fdt soc_nvidia_tegra210 arm/nvidia/tegra_efuse.c optional fdt soc_nvidia_tegra210 arm/nvidia/tegra_ehci.c optional fdt soc_nvidia_tegra210 arm/nvidia/tegra_gpio.c optional fdt soc_nvidia_tegra210 arm/nvidia/tegra_i2c.c optional fdt soc_nvidia_tegra210 arm/nvidia/tegra_lic.c optional fdt soc_nvidia_tegra210 arm/nvidia/tegra_mc.c optional fdt soc_nvidia_tegra210 arm/nvidia/tegra_pcie.c optional fdt soc_nvidia_tegra210 arm/nvidia/tegra_sdhci.c optional fdt soc_nvidia_tegra210 arm/nvidia/tegra_soctherm_if.m optional fdt soc_nvidia_tegra210 arm/nvidia/tegra_soctherm.c optional fdt soc_nvidia_tegra210 arm/nvidia/tegra_uart.c optional fdt soc_nvidia_tegra210 arm/nvidia/tegra_usbphy.c optional fdt soc_nvidia_tegra210 arm/nvidia/tegra_xhci.c optional fdt soc_nvidia_tegra210 arm64/nvidia/tegra210/max77620.c optional fdt soc_nvidia_tegra210 arm64/nvidia/tegra210/max77620_gpio.c optional fdt soc_nvidia_tegra210 arm64/nvidia/tegra210/max77620_regulators.c optional fdt soc_nvidia_tegra210 arm64/nvidia/tegra210/max77620_rtc.c optional fdt soc_nvidia_tegra210 arm64/nvidia/tegra210/tegra210_car.c optional fdt soc_nvidia_tegra210 arm64/nvidia/tegra210/tegra210_clk_per.c optional fdt soc_nvidia_tegra210 arm64/nvidia/tegra210/tegra210_clk_pll.c optional fdt soc_nvidia_tegra210 arm64/nvidia/tegra210/tegra210_clk_super.c optional fdt soc_nvidia_tegra210 arm64/nvidia/tegra210/tegra210_coretemp.c optional fdt soc_nvidia_tegra210 arm64/nvidia/tegra210/tegra210_cpufreq.c optional fdt soc_nvidia_tegra210 arm64/nvidia/tegra210/tegra210_pinmux.c optional fdt soc_nvidia_tegra210 arm64/nvidia/tegra210/tegra210_pmc.c optional fdt soc_nvidia_tegra210 arm64/nvidia/tegra210/tegra210_xusbpadctl.c optional fdt soc_nvidia_tegra210 # Nvidia firmware for Tegra tegra210_xusb_fw.c optional tegra210_xusb_fw \ dependency "$S/conf/files.arm64" \ compile-with "${AWK} -f $S/tools/fw_stub.awk tegra210_xusb.fw:tegra210_xusb_fw -mtegra210_xusb_fw -c${.TARGET}" \ no-ctfconvert no-implicit-rule before-depend local \ clean "tegra210_xusb_fw.c" tegra210_xusb.fwo optional tegra210_xusb_fw \ dependency "tegra210_xusb.fw" \ compile-with "${NORMAL_FWO}" \ no-implicit-rule \ clean "tegra210_xusb.fwo" tegra210_xusb.fw optional tegra210_xusb_fw \ dependency "$S/contrib/dev/nvidia/tegra210_xusb.bin.uu" \ compile-with "${NORMAL_FW}" \ no-obj no-implicit-rule \ clean "tegra210_xusb.fw" # NXP arm/freescale/vybrid/vf_i2c.c optional vf_i2c iicbus soc_nxp_ls arm64/qoriq/qoriq_dw_pci.c optional pci fdt soc_nxp_ls arm64/qoriq/qoriq_gpio_pic.c optional gpio fdt soc_nxp_ls arm64/qoriq/qoriq_therm.c optional pci fdt soc_nxp_ls arm64/qoriq/qoriq_therm_if.m optional pci fdt soc_nxp_ls arm64/qoriq/clk/ls1028a_clkgen.c optional clk soc_nxp_ls fdt arm64/qoriq/clk/ls1028a_flexspi_clk.c optional clk soc_nxp_ls fdt arm64/qoriq/clk/ls1046a_clkgen.c optional clk soc_nxp_ls fdt arm64/qoriq/clk/ls1088a_clkgen.c optional clk soc_nxp_ls fdt arm64/qoriq/clk/lx2160a_clkgen.c optional clk soc_nxp_ls fdt arm64/qoriq/clk/qoriq_clk_pll.c optional clk soc_nxp_ls arm64/qoriq/clk/qoriq_clkgen.c optional clk soc_nxp_ls fdt dev/ahci/ahci_fsl_fdt.c optional soc_nxp_ls ahci fdt dev/flash/flexspi/flex_spi.c optional clk flex_spi soc_nxp_ls fdt # Qualcomm arm64/qualcomm/qcom_gcc.c optional qcom_gcc fdt # RockChip Drivers arm64/rockchip/rk3328_codec.c optional fdt rk3328codec soc_rockchip_rk3328 arm64/rockchip/rk3399_emmcphy.c optional fdt rk_emmcphy soc_rockchip_rk3399 arm64/rockchip/rk_dwc3.c optional fdt rk_dwc3 soc_rockchip_rk3399 | fdt rk_dwc3 soc_rockchip_rk3568 arm64/rockchip/rk_i2c.c optional fdt rk_i2c soc_rockchip_rk3328 | fdt rk_i2c soc_rockchip_rk3399 | fdt rk_i2c soc_rockchip_rk3568 arm64/rockchip/rk_i2s.c optional fdt sound soc_rockchip_rk3328 | fdt sound soc_rockchip_rk3399 arm64/rockchip/rk_otp.c optional fdt soc_rockchip_rk3568 arm64/rockchip/rk_otp_if.m optional fdt soc_rockchip_rk3568 dev/iicbus/pmic/rockchip/rk8xx.c optional fdt rk805 soc_rockchip_rk3328 | fdt rk805 soc_rockchip_rk3399 | fdt soc_rockchip_rk3568 dev/iicbus/pmic/rockchip/rk8xx_clocks.c optional fdt rk805 soc_rockchip_rk3328 | fdt rk805 soc_rockchip_rk3399 | fdt soc_rockchip_rk3568 dev/iicbus/pmic/rockchip/rk8xx_regulators.c optional fdt rk805 soc_rockchip_rk3328 | fdt rk805 soc_rockchip_rk3399 | fdt soc_rockchip_rk3568 dev/iicbus/pmic/rockchip/rk8xx_rtc.c optional fdt rk805 soc_rockchip_rk3328 | fdt rk805 soc_rockchip_rk3399 | fdt soc_rockchip_rk3568 dev/iicbus/pmic/rockchip/rk805.c optional fdt rk805 soc_rockchip_rk3328 dev/iicbus/pmic/rockchip/rk808.c optional fdt rk805 soc_rockchip_rk3399 dev/iicbus/pmic/rockchip/rk817.c optional fdt rk817 soc_rockchip_rk3568 arm64/rockchip/rk_grf.c optional fdt soc_rockchip_rk3328 | fdt soc_rockchip_rk3399 | fdt soc_rockchip_rk3568 arm64/rockchip/rk_pinctrl.c optional fdt rk_pinctrl soc_rockchip_rk3328 | fdt rk_pinctrl soc_rockchip_rk3399 | fdt soc_rockchip_rk3568 arm64/rockchip/rk_gpio.c optional fdt rk_gpio soc_rockchip_rk3328 | fdt rk_gpio soc_rockchip_rk3399 | fdt soc_rockchip_rk3568 arm64/rockchip/rk_iodomain.c optional fdt rk_iodomain arm64/rockchip/rk_spi.c optional fdt rk_spi arm64/rockchip/rk_usb2phy.c optional fdt rk_usb2phy soc_rockchip_rk3328 | fdt rk_usb2phy soc_rockchip_rk3399 | fdt rk_usb2phy soc_rockchip_rk3568 arm64/rockchip/rk_typec_phy.c optional fdt rk_typec_phy soc_rockchip_rk3399 arm64/rockchip/if_dwc_rk.c optional fdt dwc_rk soc_rockchip_rk3328 | fdt dwc_rk soc_rockchip_rk3399 arm64/rockchip/rk_tsadc_if.m optional fdt soc_rockchip_rk3399 | fdt soc_rockchip_rk3568 arm64/rockchip/rk_tsadc.c optional fdt soc_rockchip_rk3399 | fdt soc_rockchip_rk3568 arm64/rockchip/rk_pwm.c optional fdt rk_pwm arm64/rockchip/rk_pcie.c optional fdt pci soc_rockchip_rk3399 arm64/rockchip/rk_pcie_phy.c optional fdt pci soc_rockchip_rk3399 # RockChip Clock support arm64/rockchip/clk/rk_cru.c optional fdt soc_rockchip_rk3328 | fdt soc_rockchip_rk3399 | fdt soc_rockchip_rk3568 arm64/rockchip/clk/rk_clk_armclk.c optional fdt soc_rockchip_rk3328 | fdt soc_rockchip_rk3399 | fdt soc_rockchip_rk3568 arm64/rockchip/clk/rk_clk_composite.c optional fdt soc_rockchip_rk3328 | fdt soc_rockchip_rk3399 | fdt soc_rockchip_rk3568 arm64/rockchip/clk/rk_clk_fract.c optional fdt soc_rockchip_rk3328 | fdt soc_rockchip_rk3399 | fdt soc_rockchip_rk3568 arm64/rockchip/clk/rk_clk_gate.c optional fdt soc_rockchip_rk3328 | fdt soc_rockchip_rk3399 | fdt soc_rockchip_rk3568 arm64/rockchip/clk/rk_clk_mux.c optional fdt soc_rockchip_rk3328 | fdt soc_rockchip_rk3399 | fdt soc_rockchip_rk3568 arm64/rockchip/clk/rk_clk_pll.c optional fdt soc_rockchip_rk3328 | fdt soc_rockchip_rk3399 | fdt soc_rockchip_rk3568 arm64/rockchip/clk/rk3328_cru.c optional fdt soc_rockchip_rk3328 arm64/rockchip/clk/rk3399_cru.c optional fdt soc_rockchip_rk3399 arm64/rockchip/clk/rk3399_pmucru.c optional fdt soc_rockchip_rk3399 arm64/rockchip/clk/rk3568_cru.c optional fdt soc_rockchip_rk3568 arm64/rockchip/clk/rk3568_pmucru.c optional fdt soc_rockchip_rk3568 # Xilinx arm/xilinx/uart_dev_cdnc.c optional uart soc_xilinx_zynq fdt diff --git a/sys/dev/eqos/if_eqos.c b/sys/dev/eqos/if_eqos.c new file mode 100644 index 000000000000..cacc51ef97b5 --- /dev/null +++ b/sys/dev/eqos/if_eqos.c @@ -0,0 +1,1292 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2022 Soren Schmidt + * Copyright (c) 2022 Jared McNeill + * 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 AUTHOR ``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 AUTHOR 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. + * + * $Id: eqos.c 1059 2022-12-08 19:32:32Z sos $ + */ + +/* + * DesignWare Ethernet Quality-of-Service controller + */ + +#include "opt_platform.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include +#include + +#include "miibus_if.h" +#include "if_eqos_if.h" + +#ifdef FDT +#include +#include +#include +#include +#endif + +#include +#include + +#define DESC_BOUNDARY (1ULL << 32) +#define DESC_ALIGN sizeof(struct eqos_dma_desc) +#define DESC_OFFSET(n) ((n) * sizeof(struct eqos_dma_desc)) + +#define TX_DESC_COUNT EQOS_DMA_DESC_COUNT +#define TX_DESC_SIZE (TX_DESC_COUNT * DESC_ALIGN) +#define TX_MAX_SEGS (TX_DESC_COUNT / 2) +#define TX_NEXT(n) (((n) + 1 ) % TX_DESC_COUNT) +#define TX_QUEUED(h, t) ((((h) - (t)) + TX_DESC_COUNT) % TX_DESC_COUNT) + +#define RX_DESC_COUNT EQOS_DMA_DESC_COUNT +#define RX_DESC_SIZE (RX_DESC_COUNT * DESC_ALIGN) +#define RX_NEXT(n) (((n) + 1) % RX_DESC_COUNT) + +#define MII_BUSY_RETRY 1000 +#define WATCHDOG_TIMEOUT_SECS 3 + +#define EQOS_LOCK(sc) mtx_lock(&(sc)->lock) +#define EQOS_UNLOCK(sc) mtx_unlock(&(sc)->lock) +#define EQOS_ASSERT_LOCKED(sc) mtx_assert(&(sc)->lock, MA_OWNED) + +#define RD4(sc, o) bus_read_4(sc->res[EQOS_RES_MEM], (o)) +#define WR4(sc, o, v) bus_write_4(sc->res[EQOS_RES_MEM], (o), (v)) + + +static struct resource_spec eqos_spec[] = { + { SYS_RES_MEMORY, 0, RF_ACTIVE }, + { SYS_RES_IRQ, 0, RF_ACTIVE }, + { -1, 0 } +}; + +static void eqos_tick(void *softc); + + +static int +eqos_miibus_readreg(device_t dev, int phy, int reg) +{ + struct eqos_softc *sc = device_get_softc(dev); + uint32_t addr; + int retry, val; + + addr = sc->csr_clock_range | + (phy << GMAC_MAC_MDIO_ADDRESS_PA_SHIFT) | + (reg << GMAC_MAC_MDIO_ADDRESS_RDA_SHIFT) | + GMAC_MAC_MDIO_ADDRESS_GOC_READ | GMAC_MAC_MDIO_ADDRESS_GB; + WR4(sc, GMAC_MAC_MDIO_ADDRESS, addr); + + DELAY(100); + + for (retry = MII_BUSY_RETRY; retry > 0; retry--) { + addr = RD4(sc, GMAC_MAC_MDIO_ADDRESS); + if (!(addr & GMAC_MAC_MDIO_ADDRESS_GB)) { + val = RD4(sc, GMAC_MAC_MDIO_DATA) & 0xFFFF; + break; + } + DELAY(10); + } + if (!retry) { + device_printf(dev, "phy read timeout, phy=%d reg=%d\n", + phy, reg); + return (ETIMEDOUT); + } + return (val); +} + +static int +eqos_miibus_writereg(device_t dev, int phy, int reg, int val) +{ + struct eqos_softc *sc = device_get_softc(dev); + uint32_t addr; + int retry; + + WR4(sc, GMAC_MAC_MDIO_DATA, val); + + addr = sc->csr_clock_range | + (phy << GMAC_MAC_MDIO_ADDRESS_PA_SHIFT) | + (reg << GMAC_MAC_MDIO_ADDRESS_RDA_SHIFT) | + GMAC_MAC_MDIO_ADDRESS_GOC_WRITE | GMAC_MAC_MDIO_ADDRESS_GB; + WR4(sc, GMAC_MAC_MDIO_ADDRESS, addr); + + DELAY(100); + + for (retry = MII_BUSY_RETRY; retry > 0; retry--) { + addr = RD4(sc, GMAC_MAC_MDIO_ADDRESS); + if (!(addr & GMAC_MAC_MDIO_ADDRESS_GB)) + break; + DELAY(10); + } + if (!retry) { + device_printf(dev, "phy write timeout, phy=%d reg=%d\n", + phy, reg); + return (ETIMEDOUT); + } + return (0); +} + +static void +eqos_miibus_statchg(device_t dev) +{ + struct eqos_softc *sc = device_get_softc(dev); + struct mii_data *mii = device_get_softc(sc->miibus); + uint32_t reg; + + EQOS_ASSERT_LOCKED(sc); + + if (mii->mii_media_status & IFM_ACTIVE) + sc->link_up = true; + else + sc->link_up = false; + + reg = RD4(sc, GMAC_MAC_CONFIGURATION); + + switch (IFM_SUBTYPE(mii->mii_media_active)) { + case IFM_10_T: + reg |= GMAC_MAC_CONFIGURATION_PS; + reg &= ~GMAC_MAC_CONFIGURATION_FES; + break; + case IFM_100_TX: + reg |= GMAC_MAC_CONFIGURATION_PS; + reg |= GMAC_MAC_CONFIGURATION_FES; + break; + case IFM_1000_T: + case IFM_1000_SX: + reg &= ~GMAC_MAC_CONFIGURATION_PS; + reg &= ~GMAC_MAC_CONFIGURATION_FES; + break; + case IFM_2500_T: + case IFM_2500_SX: + reg &= ~GMAC_MAC_CONFIGURATION_PS; + reg |= GMAC_MAC_CONFIGURATION_FES; + break; + default: + sc->link_up = false; + return; + } + + if ((IFM_OPTIONS(mii->mii_media_active) & IFM_FDX)) + reg |= GMAC_MAC_CONFIGURATION_DM; + else + reg &= ~GMAC_MAC_CONFIGURATION_DM; + + WR4(sc, GMAC_MAC_CONFIGURATION, reg); + + EQOS_SET_SPEED(dev, IFM_SUBTYPE(mii->mii_media_active)); + + WR4(sc, GMAC_MAC_1US_TIC_COUNTER, (sc->csr_clock / 1000000) - 1); +} + +static void +eqos_media_status(struct ifnet *ifp, struct ifmediareq *ifmr) +{ + struct eqos_softc *sc = ifp->if_softc; + struct mii_data *mii = device_get_softc(sc->miibus); + + EQOS_LOCK(sc); + mii_pollstat(mii); + ifmr->ifm_active = mii->mii_media_active; + ifmr->ifm_status = mii->mii_media_status; + EQOS_UNLOCK(sc); +} + +static int +eqos_media_change(struct ifnet *ifp) +{ + struct eqos_softc *sc = ifp->if_softc; + int error; + + EQOS_LOCK(sc); + error = mii_mediachg(device_get_softc(sc->miibus)); + EQOS_UNLOCK(sc); + return (error); +} + +static void +eqos_setup_txdesc(struct eqos_softc *sc, int index, int flags, + bus_addr_t paddr, u_int len, u_int total_len) +{ + uint32_t tdes2, tdes3; + + if (!paddr || !len) { + tdes2 = 0; + tdes3 = flags; + } else { + tdes2 = (flags & EQOS_TDES3_LD) ? EQOS_TDES2_IOC : 0; + tdes3 = flags; + } + bus_dmamap_sync(sc->tx.desc_tag, sc->tx.desc_map, BUS_DMASYNC_PREWRITE); + sc->tx.desc_ring[index].des0 = htole32((uint32_t)paddr); + sc->tx.desc_ring[index].des1 = htole32((uint32_t)(paddr >> 32)); + sc->tx.desc_ring[index].des2 = htole32(tdes2 | len); + sc->tx.desc_ring[index].des3 = htole32(tdes3 | total_len); +} + +static int +eqos_setup_txbuf(struct eqos_softc *sc, struct mbuf *m) +{ + bus_dma_segment_t segs[TX_MAX_SEGS]; + int first = sc->tx.head; + int error, nsegs, idx; + uint32_t flags; + + error = bus_dmamap_load_mbuf_sg(sc->tx.buf_tag, + sc->tx.buf_map[first].map, m, segs, &nsegs, 0); + if (error == EFBIG) { + struct mbuf *mb; + + device_printf(sc->dev, "TX packet too big trying defrag\n"); + bus_dmamap_unload(sc->tx.buf_tag, sc->tx.buf_map[first].map); + if (!(mb = m_defrag(m, M_NOWAIT))) + return (ENOMEM); + m = mb; + error = bus_dmamap_load_mbuf_sg(sc->tx.buf_tag, + sc->tx.buf_map[first].map, m, segs, &nsegs, 0); + } + if (error) + return (ENOMEM); + + if (TX_QUEUED(sc->tx.head, sc->tx.tail) + nsegs > TX_DESC_COUNT) { + bus_dmamap_unload(sc->tx.buf_tag, sc->tx.buf_map[first].map); + device_printf(sc->dev, "TX packet no more queue space\n"); + return (ENOMEM); + } + + bus_dmamap_sync(sc->tx.buf_tag, sc->tx.buf_map[first].map, + BUS_DMASYNC_PREWRITE); + + sc->tx.buf_map[first].mbuf = m; + + for (flags = EQOS_TDES3_FD, idx = 0; idx < nsegs; idx++) { + if (idx == (nsegs - 1)) + flags |= EQOS_TDES3_LD; + eqos_setup_txdesc(sc, sc->tx.head, flags, segs[idx].ds_addr, + segs[idx].ds_len, m->m_pkthdr.len); + flags &= ~EQOS_TDES3_FD; + flags |= EQOS_TDES3_OWN; + sc->tx.head = TX_NEXT(sc->tx.head); + } + + /* + * Defer setting OWN bit on the first descriptor + * until all descriptors have been updated + */ + bus_dmamap_sync(sc->tx.desc_tag, sc->tx.desc_map, BUS_DMASYNC_PREWRITE); + sc->tx.desc_ring[first].des3 |= htole32(EQOS_TDES3_OWN); + + return (0); +} + +static void +eqos_setup_rxdesc(struct eqos_softc *sc, int index, bus_addr_t paddr) +{ + + sc->rx.desc_ring[index].des0 = htole32((uint32_t)paddr); + sc->rx.desc_ring[index].des1 = htole32((uint32_t)(paddr >> 32)); + sc->rx.desc_ring[index].des2 = htole32(0); + bus_dmamap_sync(sc->rx.desc_tag, sc->rx.desc_map, BUS_DMASYNC_PREWRITE); + sc->rx.desc_ring[index].des3 = htole32(EQOS_RDES3_OWN | EQOS_RDES3_IOC | + EQOS_RDES3_BUF1V); +} + +static int +eqos_setup_rxbuf(struct eqos_softc *sc, int index, struct mbuf *m) +{ + struct bus_dma_segment seg; + int error, nsegs; + + m_adj(m, ETHER_ALIGN); + + error = bus_dmamap_load_mbuf_sg(sc->rx.buf_tag, + sc->rx.buf_map[index].map, m, &seg, &nsegs, 0); + if (error) + return (error); + + bus_dmamap_sync(sc->rx.buf_tag, sc->rx.buf_map[index].map, + BUS_DMASYNC_PREREAD); + + sc->rx.buf_map[index].mbuf = m; + eqos_setup_rxdesc(sc, index, seg.ds_addr); + + return (0); +} + +static struct mbuf * +eqos_alloc_mbufcl(struct eqos_softc *sc) +{ + struct mbuf *m; + + if ((m = m_getcl(M_NOWAIT, MT_DATA, M_PKTHDR))) + m->m_pkthdr.len = m->m_len = m->m_ext.ext_size; + return (m); +} + +static void +eqos_enable_intr(struct eqos_softc *sc) +{ + + WR4(sc, GMAC_DMA_CHAN0_INTR_ENABLE, + GMAC_DMA_CHAN0_INTR_ENABLE_NIE | GMAC_DMA_CHAN0_INTR_ENABLE_AIE | + GMAC_DMA_CHAN0_INTR_ENABLE_FBE | GMAC_DMA_CHAN0_INTR_ENABLE_RIE | + GMAC_DMA_CHAN0_INTR_ENABLE_TIE); +} + +static void +eqos_disable_intr(struct eqos_softc *sc) +{ + + WR4(sc, GMAC_DMA_CHAN0_INTR_ENABLE, 0); +} + +static uint32_t +eqos_bitrev32(uint32_t x) +{ + + x = (((x & 0xaaaaaaaa) >> 1) | ((x & 0x55555555) << 1)); + x = (((x & 0xcccccccc) >> 2) | ((x & 0x33333333) << 2)); + x = (((x & 0xf0f0f0f0) >> 4) | ((x & 0x0f0f0f0f) << 4)); + x = (((x & 0xff00ff00) >> 8) | ((x & 0x00ff00ff) << 8)); + return ((x >> 16) | (x << 16)); +} + +static u_int +eqos_hash_maddr(void *arg, struct sockaddr_dl *sdl, u_int cnt) +{ + uint32_t crc, *hash = arg; + + crc = ether_crc32_le(LLADDR(sdl), ETHER_ADDR_LEN); + crc &= 0x7f; + crc = eqos_bitrev32(~crc) >> 26; + hash[crc >> 5] |= 1 << (crc & 0x1f); + return (1); +} + +static void +eqos_setup_rxfilter(struct eqos_softc *sc) +{ + struct ifnet *ifp = sc->ifp; + uint32_t pfil, hash[2]; + const uint8_t *eaddr; + uint32_t val; + + EQOS_ASSERT_LOCKED(sc); + + pfil = RD4(sc, GMAC_MAC_PACKET_FILTER); + pfil &= ~(GMAC_MAC_PACKET_FILTER_PR | + GMAC_MAC_PACKET_FILTER_PM | + GMAC_MAC_PACKET_FILTER_HMC | + GMAC_MAC_PACKET_FILTER_PCF_MASK); + hash[0] = hash[1] = 0xffffffff; + + if ((ifp->if_flags & IFF_PROMISC)) { + pfil |= GMAC_MAC_PACKET_FILTER_PR | + GMAC_MAC_PACKET_FILTER_PCF_ALL; + } else if ((ifp->if_flags & IFF_ALLMULTI)) { + pfil |= GMAC_MAC_PACKET_FILTER_PM; + } else { + hash[0] = hash[1] = 0; + pfil |= GMAC_MAC_PACKET_FILTER_HMC; + if_foreach_llmaddr(ifp, eqos_hash_maddr, hash); + } + + /* Write our unicast address */ + eaddr = IF_LLADDR(ifp); + val = eaddr[4] | (eaddr[5] << 8); + WR4(sc, GMAC_MAC_ADDRESS0_HIGH, val); + val = eaddr[0] | (eaddr[1] << 8) | (eaddr[2] << 16) | + (eaddr[3] << 24); + WR4(sc, GMAC_MAC_ADDRESS0_LOW, val); + + /* Multicast hash filters */ + WR4(sc, GMAC_MAC_HASH_TABLE_REG0, hash[1]); + WR4(sc, GMAC_MAC_HASH_TABLE_REG1, hash[0]); + + /* Packet filter config */ + WR4(sc, GMAC_MAC_PACKET_FILTER, pfil); +} + +static int +eqos_reset(struct eqos_softc *sc) +{ + uint32_t val; + int retry; + + WR4(sc, GMAC_DMA_MODE, GMAC_DMA_MODE_SWR); + for (retry = 2000; retry > 0; retry--) { + DELAY(1000); + val = RD4(sc, GMAC_DMA_MODE); + if (!(val & GMAC_DMA_MODE_SWR)) + return (0); + } + return (ETIMEDOUT); +} + +static void +eqos_init_rings(struct eqos_softc *sc) +{ + + WR4(sc, GMAC_DMA_CHAN0_TX_BASE_ADDR_HI, + (uint32_t)(sc->tx.desc_ring_paddr >> 32)); + WR4(sc, GMAC_DMA_CHAN0_TX_BASE_ADDR, + (uint32_t)sc->tx.desc_ring_paddr); + WR4(sc, GMAC_DMA_CHAN0_TX_RING_LEN, TX_DESC_COUNT - 1); + + WR4(sc, GMAC_DMA_CHAN0_RX_BASE_ADDR_HI, + (uint32_t)(sc->rx.desc_ring_paddr >> 32)); + WR4(sc, GMAC_DMA_CHAN0_RX_BASE_ADDR, + (uint32_t)sc->rx.desc_ring_paddr); + WR4(sc, GMAC_DMA_CHAN0_RX_RING_LEN, RX_DESC_COUNT - 1); + + WR4(sc, GMAC_DMA_CHAN0_RX_END_ADDR, + (uint32_t)sc->rx.desc_ring_paddr + DESC_OFFSET(RX_DESC_COUNT)); +} + +static void +eqos_init(void *if_softc) +{ + struct eqos_softc *sc = if_softc; + struct ifnet *ifp = sc->ifp; + struct mii_data *mii = device_get_softc(sc->miibus); + uint32_t val; + + if (if_getdrvflags(ifp) & IFF_DRV_RUNNING) + return; + + EQOS_LOCK(sc); + + eqos_init_rings(sc); + + eqos_setup_rxfilter(sc); + + WR4(sc, GMAC_MAC_1US_TIC_COUNTER, (sc->csr_clock / 1000000) - 1); + + /* Enable transmit and receive DMA */ + val = RD4(sc, GMAC_DMA_CHAN0_CONTROL); + val &= ~GMAC_DMA_CHAN0_CONTROL_DSL_MASK; + val |= ((DESC_ALIGN - 16) / 8) << GMAC_DMA_CHAN0_CONTROL_DSL_SHIFT; + val |= GMAC_DMA_CHAN0_CONTROL_PBLX8; + WR4(sc, GMAC_DMA_CHAN0_CONTROL, val); + val = RD4(sc, GMAC_DMA_CHAN0_TX_CONTROL); + val |= GMAC_DMA_CHAN0_TX_CONTROL_OSP; + val |= GMAC_DMA_CHAN0_TX_CONTROL_START; + WR4(sc, GMAC_DMA_CHAN0_TX_CONTROL, val); + val = RD4(sc, GMAC_DMA_CHAN0_RX_CONTROL); + val &= ~GMAC_DMA_CHAN0_RX_CONTROL_RBSZ_MASK; + val |= (MCLBYTES << GMAC_DMA_CHAN0_RX_CONTROL_RBSZ_SHIFT); + val |= GMAC_DMA_CHAN0_RX_CONTROL_START; + WR4(sc, GMAC_DMA_CHAN0_RX_CONTROL, val); + + /* Disable counters */ + WR4(sc, GMAC_MMC_CONTROL, + GMAC_MMC_CONTROL_CNTFREEZ | + GMAC_MMC_CONTROL_CNTPRST | + GMAC_MMC_CONTROL_CNTPRSTLVL); + + /* Configure operation modes */ + WR4(sc, GMAC_MTL_TXQ0_OPERATION_MODE, + GMAC_MTL_TXQ0_OPERATION_MODE_TSF | + GMAC_MTL_TXQ0_OPERATION_MODE_TXQEN_EN); + WR4(sc, GMAC_MTL_RXQ0_OPERATION_MODE, + GMAC_MTL_RXQ0_OPERATION_MODE_RSF | + GMAC_MTL_RXQ0_OPERATION_MODE_FEP | + GMAC_MTL_RXQ0_OPERATION_MODE_FUP); + + /* Enable flow control */ + val = RD4(sc, GMAC_MAC_Q0_TX_FLOW_CTRL); + val |= 0xFFFFU << GMAC_MAC_Q0_TX_FLOW_CTRL_PT_SHIFT; + val |= GMAC_MAC_Q0_TX_FLOW_CTRL_TFE; + WR4(sc, GMAC_MAC_Q0_TX_FLOW_CTRL, val); + val = RD4(sc, GMAC_MAC_RX_FLOW_CTRL); + val |= GMAC_MAC_RX_FLOW_CTRL_RFE; + WR4(sc, GMAC_MAC_RX_FLOW_CTRL, val); + + /* set RX queue mode. must be in DCB mode. */ + WR4(sc, GMAC_RXQ_CTRL0, (GMAC_RXQ_CTRL0_EN_MASK << 16) | + GMAC_RXQ_CTRL0_EN_DCB); + + /* Enable transmitter and receiver */ + val = RD4(sc, GMAC_MAC_CONFIGURATION); + val |= GMAC_MAC_CONFIGURATION_BE; + val |= GMAC_MAC_CONFIGURATION_JD; + val |= GMAC_MAC_CONFIGURATION_JE; + val |= GMAC_MAC_CONFIGURATION_DCRS; + val |= GMAC_MAC_CONFIGURATION_TE; + val |= GMAC_MAC_CONFIGURATION_RE; + WR4(sc, GMAC_MAC_CONFIGURATION, val); + + eqos_enable_intr(sc); + + if_setdrvflagbits(ifp, IFF_DRV_RUNNING, IFF_DRV_OACTIVE); + + mii_mediachg(mii); + callout_reset(&sc->callout, hz, eqos_tick, sc); + + EQOS_UNLOCK(sc); +} + +static void +eqos_start_locked(struct ifnet *ifp) +{ + struct eqos_softc *sc = ifp->if_softc; + struct mbuf *m; + int pending = 0; + + if (!sc->link_up) + return; + + if ((if_getdrvflags(ifp) & (IFF_DRV_RUNNING|IFF_DRV_OACTIVE)) != + IFF_DRV_RUNNING) + return; + + while (true) { + if (TX_QUEUED(sc->tx.head, sc->tx.tail) >= + TX_DESC_COUNT - TX_MAX_SEGS) { + if_setdrvflagbits(ifp, IFF_DRV_OACTIVE, 0); + break; + } + + if (!(m = if_dequeue(ifp))) + break; + + if (eqos_setup_txbuf(sc, m)) { + if_sendq_prepend(ifp, m); + if_setdrvflagbits(ifp, IFF_DRV_OACTIVE, 0); + break; + } + if_bpfmtap(ifp, m); + pending++; + } + + if (pending) { + bus_dmamap_sync(sc->tx.desc_tag, sc->tx.desc_map, + BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE); + + /* Start and run TX DMA */ + WR4(sc, GMAC_DMA_CHAN0_TX_END_ADDR, + (uint32_t)sc->tx.desc_ring_paddr + DESC_OFFSET(sc->tx.head)); + sc->tx_watchdog = WATCHDOG_TIMEOUT_SECS; + } +} + +static void +eqos_start(struct ifnet *ifp) +{ + struct eqos_softc *sc = ifp->if_softc; + + EQOS_LOCK(sc); + eqos_start_locked(ifp); + EQOS_UNLOCK(sc); +} + +static void +eqos_stop(struct eqos_softc *sc) +{ + struct ifnet *ifp = sc->ifp; + uint32_t val; + int retry; + + EQOS_LOCK(sc); + + if_setdrvflagbits(ifp, 0, IFF_DRV_RUNNING | IFF_DRV_OACTIVE); + + callout_stop(&sc->callout); + + /* Disable receiver */ + val = RD4(sc, GMAC_MAC_CONFIGURATION); + val &= ~GMAC_MAC_CONFIGURATION_RE; + WR4(sc, GMAC_MAC_CONFIGURATION, val); + + /* Stop receive DMA */ + val = RD4(sc, GMAC_DMA_CHAN0_RX_CONTROL); + val &= ~GMAC_DMA_CHAN0_RX_CONTROL_START; + WR4(sc, GMAC_DMA_CHAN0_RX_CONTROL, val); + + /* Stop transmit DMA */ + val = RD4(sc, GMAC_DMA_CHAN0_TX_CONTROL); + val &= ~GMAC_DMA_CHAN0_TX_CONTROL_START; + WR4(sc, GMAC_DMA_CHAN0_TX_CONTROL, val); + + /* Flush data in the TX FIFO */ + val = RD4(sc, GMAC_MTL_TXQ0_OPERATION_MODE); + val |= GMAC_MTL_TXQ0_OPERATION_MODE_FTQ; + WR4(sc, GMAC_MTL_TXQ0_OPERATION_MODE, val); + for (retry = 10000; retry > 0; retry--) { + val = RD4(sc, GMAC_MTL_TXQ0_OPERATION_MODE); + if (!(val & GMAC_MTL_TXQ0_OPERATION_MODE_FTQ)) + break; + DELAY(10); + } + if (!retry) + device_printf(sc->dev, "timeout flushing TX queue\n"); + + /* Disable transmitter */ + val = RD4(sc, GMAC_MAC_CONFIGURATION); + val &= ~GMAC_MAC_CONFIGURATION_TE; + WR4(sc, GMAC_MAC_CONFIGURATION, val); + + eqos_disable_intr(sc); + + EQOS_UNLOCK(sc); +} + +static void +eqos_rxintr(struct eqos_softc *sc) +{ + struct ifnet *ifp = sc->ifp; + struct mbuf *m; + uint32_t rdes3; + int error, length; + + while (true) { + rdes3 = le32toh(sc->rx.desc_ring[sc->rx.head].des3); + if ((rdes3 & EQOS_RDES3_OWN)) + break; + + if (rdes3 & (EQOS_RDES3_OE | EQOS_RDES3_RE)) + printf("Receive errer rdes3=%08x\n", rdes3); + + bus_dmamap_sync(sc->rx.buf_tag, + sc->rx.buf_map[sc->rx.head].map, BUS_DMASYNC_POSTREAD); + bus_dmamap_unload(sc->rx.buf_tag, + sc->rx.buf_map[sc->rx.head].map); + + length = rdes3 & EQOS_RDES3_LENGTH_MASK; + if (length) { + m = sc->rx.buf_map[sc->rx.head].mbuf; + m->m_pkthdr.rcvif = ifp; + m->m_pkthdr.len = length; + m->m_len = length; + m->m_nextpkt = NULL; + + /* Remove trailing FCS */ + m_adj(m, -ETHER_CRC_LEN); + + EQOS_UNLOCK(sc); + (*ifp->if_input)(ifp, m); + EQOS_LOCK(sc); + } + + if ((m = eqos_alloc_mbufcl(sc))) { + if ((error = eqos_setup_rxbuf(sc, sc->rx.head, m))) + printf("ERROR: Hole in RX ring!!\n"); + } + else + if_inc_counter(ifp, IFCOUNTER_IERRORS, 1); + + if_inc_counter(ifp, IFCOUNTER_IPACKETS, 1); + + WR4(sc, GMAC_DMA_CHAN0_RX_END_ADDR, + (uint32_t)sc->rx.desc_ring_paddr + DESC_OFFSET(sc->rx.head)); + + sc->rx.head = RX_NEXT(sc->rx.head); + } +} + +static void +eqos_txintr(struct eqos_softc *sc) +{ + struct ifnet *ifp = sc->ifp; + struct eqos_bufmap *bmap; + uint32_t tdes3; + + EQOS_ASSERT_LOCKED(sc); + + while (sc->tx.tail != sc->tx.head) { + tdes3 = le32toh(sc->tx.desc_ring[sc->tx.tail].des3); + if ((tdes3 & EQOS_TDES3_OWN)) + break; + + bmap = &sc->tx.buf_map[sc->tx.tail]; + if (bmap->mbuf) { + bus_dmamap_sync(sc->tx.buf_tag, bmap->map, + BUS_DMASYNC_POSTWRITE); + bus_dmamap_unload(sc->tx.buf_tag, bmap->map); + m_freem(bmap->mbuf); + bmap->mbuf = NULL; + } + + eqos_setup_txdesc(sc, sc->tx.tail, 0, 0, 0, 0); + + if_setdrvflagbits(ifp, 0, IFF_DRV_OACTIVE); + + /* Last descriptor in a packet contains DMA status */ + if ((tdes3 & EQOS_TDES3_LD)) { + if ((tdes3 & EQOS_TDES3_DE)) { + if_inc_counter(ifp, IFCOUNTER_OERRORS, 1); + } else if ((tdes3 & EQOS_TDES3_ES)) { + if_inc_counter(ifp, IFCOUNTER_OERRORS, 1); + } else { + if_inc_counter(ifp, IFCOUNTER_OPACKETS, 1); + } + } + sc->tx.tail = TX_NEXT(sc->tx.tail); + } + if (sc->tx.tail == sc->tx.head) + sc->tx_watchdog = 0; + eqos_start_locked(sc->ifp); +} + +static void +eqos_intr_mtl(struct eqos_softc *sc, uint32_t mtl_status) +{ + uint32_t mtl_istat = 0; + + if ((mtl_status & GMAC_MTL_INTERRUPT_STATUS_Q0IS)) { + uint32_t mtl_clear = 0; + + mtl_istat = RD4(sc, GMAC_MTL_Q0_INTERRUPT_CTRL_STATUS); + if ((mtl_istat & GMAC_MTL_Q0_INTERRUPT_CTRL_STATUS_RXOVFIS)) { + mtl_clear |= GMAC_MTL_Q0_INTERRUPT_CTRL_STATUS_RXOVFIS; + } + if ((mtl_istat & GMAC_MTL_Q0_INTERRUPT_CTRL_STATUS_TXUNFIS)) { + mtl_clear |= GMAC_MTL_Q0_INTERRUPT_CTRL_STATUS_TXUNFIS; + } + if (mtl_clear) { + mtl_clear |= (mtl_istat & + (GMAC_MTL_Q0_INTERRUPT_CTRL_STATUS_RXOIE | + GMAC_MTL_Q0_INTERRUPT_CTRL_STATUS_TXUIE)); + WR4(sc, GMAC_MTL_Q0_INTERRUPT_CTRL_STATUS, mtl_clear); + } + } + if (bootverbose) + device_printf(sc->dev, + "GMAC_MTL_INTERRUPT_STATUS = 0x%08X, " + "GMAC_MTL_INTERRUPT_STATUS_Q0IS = 0x%08X\n", + mtl_status, mtl_istat); +} + +static void +eqos_tick(void *softc) +{ + struct eqos_softc *sc = softc; + struct mii_data *mii = device_get_softc(sc->miibus); + bool link_status; + + EQOS_ASSERT_LOCKED(sc); + + if (sc->tx_watchdog > 0) + if (!--sc->tx_watchdog) { + device_printf(sc->dev, "watchdog timeout\n"); + eqos_txintr(sc); + } + + link_status = sc->link_up; + mii_tick(mii); + if (sc->link_up && !link_status) + eqos_start_locked(sc->ifp); + + callout_reset(&sc->callout, hz, eqos_tick, sc); +} + +static void +eqos_intr(void *arg) +{ + struct eqos_softc *sc = arg; + uint32_t mac_status, mtl_status, dma_status, rx_tx_status; + + mac_status = RD4(sc, GMAC_MAC_INTERRUPT_STATUS); + mac_status &= RD4(sc, GMAC_MAC_INTERRUPT_ENABLE); + + if (mac_status) + device_printf(sc->dev, "MAC interrupt\n"); + + if ((mtl_status = RD4(sc, GMAC_MTL_INTERRUPT_STATUS))) + eqos_intr_mtl(sc, mtl_status); + + dma_status = RD4(sc, GMAC_DMA_CHAN0_STATUS); + dma_status &= RD4(sc, GMAC_DMA_CHAN0_INTR_ENABLE); + + if (dma_status) + WR4(sc, GMAC_DMA_CHAN0_STATUS, dma_status); + + EQOS_LOCK(sc); + + if (dma_status & GMAC_DMA_CHAN0_STATUS_RI) + eqos_rxintr(sc); + + if (dma_status & GMAC_DMA_CHAN0_STATUS_TI) + eqos_txintr(sc); + + EQOS_UNLOCK(sc); + + if (!(mac_status | mtl_status | dma_status)) { + device_printf(sc->dev, + "spurious interrupt mac=%08x mtl=%08x dma=%08x\n", + RD4(sc, GMAC_MAC_INTERRUPT_STATUS), + RD4(sc, GMAC_MTL_INTERRUPT_STATUS), + RD4(sc, GMAC_DMA_CHAN0_STATUS)); + } + if ((rx_tx_status = RD4(sc, GMAC_MAC_RX_TX_STATUS))) + device_printf(sc->dev, "RX/TX status interrupt\n"); +} + +static int +eqos_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data) +{ + struct eqos_softc *sc = ifp->if_softc; + struct ifreq *ifr = (struct ifreq *)data; + struct mii_data *mii; + int flags, mask; + int error = 0; + + switch (cmd) { + case SIOCSIFFLAGS: + if (if_getflags(ifp) & IFF_UP) { + if (if_getdrvflags(ifp) & IFF_DRV_RUNNING) { + flags = if_getflags(ifp); + if ((flags & (IFF_PROMISC|IFF_ALLMULTI))) { + EQOS_LOCK(sc); + eqos_setup_rxfilter(sc); + EQOS_UNLOCK(sc); + } + } + else { + eqos_init(sc); + } + } + else { + if (if_getdrvflags(ifp) & IFF_DRV_RUNNING) + eqos_stop(sc); + } + break; + + case SIOCADDMULTI: + case SIOCDELMULTI: + if (if_getdrvflags(ifp) & IFF_DRV_RUNNING) { + EQOS_LOCK(sc); + eqos_setup_rxfilter(sc); + EQOS_UNLOCK(sc); + } + break; + + case SIOCSIFMEDIA: + case SIOCGIFMEDIA: + mii = device_get_softc(sc->miibus); + error = ifmedia_ioctl(ifp, ifr, &mii->mii_media, cmd); + break; + + case SIOCSIFCAP: + mask = ifr->ifr_reqcap ^ if_getcapenable(ifp); + if (mask & IFCAP_VLAN_MTU) + if_togglecapenable(ifp, IFCAP_VLAN_MTU); + if (mask & IFCAP_RXCSUM) + if_togglecapenable(ifp, IFCAP_RXCSUM); + if (mask & IFCAP_TXCSUM) + if_togglecapenable(ifp, IFCAP_TXCSUM); + if ((if_getcapenable(ifp) & IFCAP_TXCSUM)) + if_sethwassistbits(ifp, + CSUM_IP | CSUM_UDP | CSUM_TCP, 0); + else + if_sethwassistbits(ifp, + 0, CSUM_IP | CSUM_UDP | CSUM_TCP); + break; + + default: + error = ether_ioctl(ifp, cmd, data); + break; + } + + return (error); +} + +static void +eqos_get_eaddr(struct eqos_softc *sc, uint8_t *eaddr) +{ + uint32_t maclo, machi; + + maclo = htobe32(RD4(sc, GMAC_MAC_ADDRESS0_LOW)); + machi = htobe16(RD4(sc, GMAC_MAC_ADDRESS0_HIGH) & 0xFFFF); + + /* if no valid MAC address generate random */ + if (maclo == 0xffffffff && machi == 0xffff) { + maclo = 0xf2 | (arc4random() & 0xffff0000); + machi = arc4random() & 0x0000ffff; + } + eaddr[0] = maclo & 0xff; + eaddr[1] = (maclo >> 8) & 0xff; + eaddr[2] = (maclo >> 16) & 0xff; + eaddr[3] = (maclo >> 24) & 0xff; + eaddr[4] = machi & 0xff; + eaddr[5] = (machi >> 8) & 0xff; +} + +static void +eqos_axi_configure(struct eqos_softc *sc) +{ + uint32_t val; + + val = RD4(sc, GMAC_DMA_SYSBUS_MODE); + + /* Max Write Outstanding Req Limit */ + val &= ~GMAC_DMA_SYSBUS_MODE_WR_OSR_LMT_MASK; + val |= 0x03 << GMAC_DMA_SYSBUS_MODE_WR_OSR_LMT_SHIFT; + + /* Max Read Outstanding Req Limit */ + val &= ~GMAC_DMA_SYSBUS_MODE_RD_OSR_LMT_MASK; + val |= 0x07 << GMAC_DMA_SYSBUS_MODE_RD_OSR_LMT_SHIFT; + + /* Allowed Burst Length's */ + val |= GMAC_DMA_SYSBUS_MODE_BLEN16; + val |= GMAC_DMA_SYSBUS_MODE_BLEN8; + val |= GMAC_DMA_SYSBUS_MODE_BLEN4; + + /* Fixed Burst Length */ + val |= GMAC_DMA_SYSBUS_MODE_MB; + + WR4(sc, GMAC_DMA_SYSBUS_MODE, val); +} + +static void +eqos_get1paddr(void *arg, bus_dma_segment_t *segs, int nsegs, int error) +{ + + if (!error) + *(bus_addr_t *)arg = segs[0].ds_addr; +} + +static int +eqos_setup_dma(struct eqos_softc *sc) +{ + struct mbuf *m; + int error, i; + + /* Set up TX descriptor ring, descriptors, and dma maps */ + if ((error = bus_dma_tag_create(bus_get_dma_tag(sc->dev), + DESC_ALIGN, DESC_BOUNDARY, + BUS_SPACE_MAXADDR_32BIT, + BUS_SPACE_MAXADDR, NULL, NULL, + TX_DESC_SIZE, 1, TX_DESC_SIZE, 0, + NULL, NULL, &sc->tx.desc_tag))) { + device_printf(sc->dev, "could not create TX ring DMA tag\n"); + return (error); + } + + if ((error = bus_dmamem_alloc(sc->tx.desc_tag, + (void**)&sc->tx.desc_ring, + BUS_DMA_COHERENT | BUS_DMA_WAITOK | BUS_DMA_ZERO, + &sc->tx.desc_map))) { + device_printf(sc->dev, + "could not allocate TX descriptor ring.\n"); + return (error); + } + + if ((error = bus_dmamap_load(sc->tx.desc_tag, sc->tx.desc_map, + sc->tx.desc_ring, + TX_DESC_SIZE, eqos_get1paddr, &sc->tx.desc_ring_paddr, 0))) { + device_printf(sc->dev, + "could not load TX descriptor ring map.\n"); + return (error); + } + + if ((error = bus_dma_tag_create(bus_get_dma_tag(sc->dev), 1, 0, + BUS_SPACE_MAXADDR_32BIT, + BUS_SPACE_MAXADDR, NULL, NULL, + MCLBYTES*TX_MAX_SEGS, TX_MAX_SEGS, + MCLBYTES, 0, NULL, NULL, + &sc->tx.buf_tag))) { + device_printf(sc->dev, "could not create TX buffer DMA tag.\n"); + return (error); + } + + for (i = 0; i < TX_DESC_COUNT; i++) { + if ((error = bus_dmamap_create(sc->tx.buf_tag, BUS_DMA_COHERENT, + &sc->tx.buf_map[i].map))) { + device_printf(sc->dev, "cannot create TX buffer map\n"); + return (error); + } + eqos_setup_txdesc(sc, i, EQOS_TDES3_OWN, 0, 0, 0); + } + + /* Set up RX descriptor ring, descriptors, dma maps, and mbufs */ + if ((error = bus_dma_tag_create(bus_get_dma_tag(sc->dev), + DESC_ALIGN, DESC_BOUNDARY, + BUS_SPACE_MAXADDR_32BIT, + BUS_SPACE_MAXADDR, NULL, NULL, + RX_DESC_SIZE, 1, RX_DESC_SIZE, 0, + NULL, NULL, &sc->rx.desc_tag))) { + device_printf(sc->dev, "could not create RX ring DMA tag.\n"); + return (error); + } + + if ((error = bus_dmamem_alloc(sc->rx.desc_tag, + (void **)&sc->rx.desc_ring, + BUS_DMA_COHERENT | BUS_DMA_WAITOK | BUS_DMA_ZERO, + &sc->rx.desc_map))) { + device_printf(sc->dev, + "could not allocate RX descriptor ring.\n"); + return (error); + } + + if ((error = bus_dmamap_load(sc->rx.desc_tag, sc->rx.desc_map, + sc->rx.desc_ring, RX_DESC_SIZE, eqos_get1paddr, + &sc->rx.desc_ring_paddr, 0))) { + device_printf(sc->dev, + "could not load RX descriptor ring map.\n"); + return (error); + } + + if ((error = bus_dma_tag_create(bus_get_dma_tag(sc->dev), 1, 0, + BUS_SPACE_MAXADDR_32BIT, + BUS_SPACE_MAXADDR, NULL, NULL, + MCLBYTES, 1, + MCLBYTES, 0, NULL, NULL, + &sc->rx.buf_tag))) { + device_printf(sc->dev, "could not create RX buf DMA tag.\n"); + return (error); + } + + for (i = 0; i < RX_DESC_COUNT; i++) { + if ((error = bus_dmamap_create(sc->rx.buf_tag, BUS_DMA_COHERENT, + &sc->rx.buf_map[i].map))) { + device_printf(sc->dev, "cannot create RX buffer map\n"); + return (error); + } + if (!(m = eqos_alloc_mbufcl(sc))) { + device_printf(sc->dev, "cannot allocate RX mbuf\n"); + return (ENOMEM); + } + if ((error = eqos_setup_rxbuf(sc, i, m))) { + device_printf(sc->dev, "cannot create RX buffer\n"); + return (error); + } + } + + if (bootverbose) + device_printf(sc->dev, "TX ring @ 0x%lx, RX ring @ 0x%lx\n", + sc->tx.desc_ring_paddr, sc->rx.desc_ring_paddr); + return (0); +} + +static int +eqos_attach(device_t dev) +{ + struct eqos_softc *sc = device_get_softc(dev); + struct ifnet *ifp; + uint32_t ver; + uint8_t eaddr[ETHER_ADDR_LEN]; + u_int userver, snpsver; + int error; + int n; + + /* setup resources */ + if (bus_alloc_resources(dev, eqos_spec, sc->res)) { + device_printf(dev, "Could not allocate resources\n"); + bus_release_resources(dev, eqos_spec, sc->res); + return (ENXIO); + } + + sc->dev = dev; + ver = RD4(sc, GMAC_MAC_VERSION); + userver = (ver & GMAC_MAC_VERSION_USERVER_MASK) >> + GMAC_MAC_VERSION_USERVER_SHIFT; + snpsver = ver & GMAC_MAC_VERSION_SNPSVER_MASK; + + if (snpsver != 0x51) { + device_printf(dev, "EQOS version 0x%02xx not supported\n", + snpsver); + return (ENXIO); + } + + for (n = 0; n < 4; n++) + sc->hw_feature[n] = RD4(sc, GMAC_MAC_HW_FEATURE(n)); + + if (bootverbose) { + device_printf(dev, "DesignWare EQOS ver 0x%02x (0x%02x)\n", + snpsver, userver); + device_printf(dev, "hw features %08x %08x %08x %08x\n", + sc->hw_feature[0], sc->hw_feature[1], + sc->hw_feature[2], sc->hw_feature[3]); + } + + + if ((error = EQOS_INIT(dev))) + return (error); + + mtx_init(&sc->lock, "eqos lock", MTX_NETWORK_LOCK, MTX_DEF); + callout_init_mtx(&sc->callout, &sc->lock, 0); + + eqos_get_eaddr(sc, eaddr); + if (bootverbose) + device_printf(sc->dev, "Ethernet address %6D\n", eaddr, ":"); + + /* Soft reset EMAC core */ + if ((error = eqos_reset(sc))) { + device_printf(sc->dev, "reset timeout!\n"); + return (error); + } + + /* Configure AXI Bus mode parameters */ + eqos_axi_configure(sc); + + /* Setup DMA descriptors */ + if (eqos_setup_dma(sc)) { + device_printf(sc->dev, "failed to setup DMA descriptors\n"); + return (EINVAL); + } + + /* setup interrupt delivery */ + if ((bus_setup_intr(dev, sc->res[EQOS_RES_IRQ0], EQOS_INTR_FLAGS, + NULL, eqos_intr, sc, &sc->irq_handle))) { + device_printf(dev, "unable to setup 1st interrupt\n"); + bus_release_resources(dev, eqos_spec, sc->res); + return (ENXIO); + } + + /* Setup ethernet interface */ + ifp = sc->ifp = if_alloc(IFT_ETHER); + ifp->if_softc = sc; + if_initname(ifp, device_get_name(sc->dev), device_get_unit(sc->dev)); + if_setflags(sc->ifp, IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST); + if_setstartfn(ifp, eqos_start); + if_setioctlfn(ifp, eqos_ioctl); + if_setinitfn(ifp, eqos_init); + if_setsendqlen(ifp, TX_DESC_COUNT - 1); + if_setsendqready(ifp); + if_setcapabilities(ifp, IFCAP_VLAN_MTU /*| IFCAP_HWCSUM*/); + if_setcapenable(ifp, if_getcapabilities(ifp)); + + /* Attach MII driver */ + if ((error = mii_attach(sc->dev, &sc->miibus, ifp, eqos_media_change, + eqos_media_status, BMSR_DEFCAPMASK, MII_PHY_ANY, + MII_OFFSET_ANY, 0))) { + device_printf(sc->dev, "PHY attach failed\n"); + return (ENXIO); + } + + /* Attach ethernet interface */ + ether_ifattach(ifp, eaddr); + + return (0); +} + +static int +eqos_detach(device_t dev) +{ + struct eqos_softc *sc = device_get_softc(dev); + int i; + + if (device_is_attached(dev)) { + EQOS_LOCK(sc); + eqos_stop(sc); + EQOS_UNLOCK(sc); + sc->ifp->if_flags &= ~IFF_UP; + ether_ifdetach(sc->ifp); + } + + if (sc->miibus) + device_delete_child(dev, sc->miibus); + bus_generic_detach(dev); + + if (sc->irq_handle) + bus_teardown_intr(dev, sc->res[EQOS_RES_IRQ0], + sc->irq_handle); + + if (sc->ifp) + if_free(sc->ifp); + + bus_release_resources(dev, eqos_spec, sc->res); + + if (sc->tx.desc_tag) { + if (sc->tx.desc_map) { + bus_dmamap_unload(sc->tx.desc_tag, sc->tx.desc_map); + bus_dmamem_free(sc->tx.desc_tag, sc->tx.desc_ring, + sc->tx.desc_map); + } + bus_dma_tag_destroy(sc->tx.desc_tag); + } + if (sc->tx.buf_tag) { + for (i = 0; i < TX_DESC_COUNT; i++) { + m_free(sc->tx.buf_map[i].mbuf); + bus_dmamap_destroy(sc->tx.buf_tag, + sc->tx.buf_map[i].map); + } + bus_dma_tag_destroy(sc->tx.buf_tag); + } + + if (sc->rx.desc_tag) { + if (sc->rx.desc_map) { + bus_dmamap_unload(sc->rx.desc_tag, sc->rx.desc_map); + bus_dmamem_free(sc->rx.desc_tag, sc->rx.desc_ring, + sc->rx.desc_map); + } + bus_dma_tag_destroy(sc->rx.desc_tag); + } + if (sc->rx.buf_tag) { + for (i = 0; i < RX_DESC_COUNT; i++) { + m_free(sc->rx.buf_map[i].mbuf); + bus_dmamap_destroy(sc->rx.buf_tag, + sc->rx.buf_map[i].map); + } + bus_dma_tag_destroy(sc->rx.buf_tag); + } + + mtx_destroy(&sc->lock); + + return (0); +} + + +static device_method_t eqos_methods[] = { + /* Device Interface */ + DEVMETHOD(device_attach, eqos_attach), + DEVMETHOD(device_detach, eqos_detach), + + /* MII Interface */ + DEVMETHOD(miibus_readreg, eqos_miibus_readreg), + DEVMETHOD(miibus_writereg, eqos_miibus_writereg), + DEVMETHOD(miibus_statchg, eqos_miibus_statchg), + + DEVMETHOD_END +}; + +driver_t eqos_driver = { + "eqos", + eqos_methods, + sizeof(struct eqos_softc), +}; + +DRIVER_MODULE(miibus, eqos, miibus_driver, 0, 0); diff --git a/sys/dev/eqos/if_eqos_fdt.c b/sys/dev/eqos/if_eqos_fdt.c new file mode 100644 index 000000000000..020aeb435285 --- /dev/null +++ b/sys/dev/eqos/if_eqos_fdt.c @@ -0,0 +1,255 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2022 Soren Schmidt + * 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 AUTHOR 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 AUTHOR 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. + * + * $Id: eqos_fdt.c 1049 2022-12-03 14:25:46Z sos $ + */ + +#include "opt_platform.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include +#include + +#include +#include +#include + +#include + +#include "if_eqos_if.h" +#include "syscon_if.h" +#include "gpio_if.h" +#include "rk_otp_if.h" + +#define RK356XGMAC0 0xfe2a0000 +#define RK356XGMAC1 0xfe010000 +#define RK3588GMAC0 0xfe1b0000 +#define RK3588GMAC1 0xfe1c0000 + +#define EQOS_GRF_GMAC0 0x0380 +#define EQOS_GRF_GMAC1 0x0388 +#define EQOS_CON0_OFFSET 0 +#define EQOS_CON1_OFFSET 4 + +#define EQOS_GMAC_PHY_INTF_SEL_RGMII 0x00fc0010 +#define EQOS_GMAC_PHY_INTF_SEL_RMII 0x00fc0040 +#define EQOS_GMAC_RXCLK_DLY_ENABLE 0x00020002 +#define EQOS_GMAC_RXCLK_DLY_DISABLE 0x00020000 +#define EQOS_GMAC_TXCLK_DLY_ENABLE 0x00010001 +#define EQOS_GMAC_TXCLK_DLY_DISABLE 0x00010000 +#define EQOS_GMAC_CLK_RX_DL_CFG(val) (0x7f000000 | val << 8) +#define EQOS_GMAC_CLK_TX_DL_CFG(val) (0x007f0000 | val) + +#define WR4(sc, o, v) bus_write_4(sc->res[EQOS_RES_MEM], (o), (v)) + +static const struct ofw_compat_data compat_data[] = { + {"snps,dwmac-4.20a", 1}, + { NULL, 0 } +}; + + +static int +eqos_phy_reset(device_t dev) +{ + pcell_t gpio_prop[4]; + pcell_t delay_prop[3]; + phandle_t node, gpio_node; + device_t gpio; + uint32_t pin, flags; + uint32_t pin_value; + + node = ofw_bus_get_node(dev); + if (OF_getencprop(node, "snps,reset-gpio", + gpio_prop, sizeof(gpio_prop)) <= 0) + return (0); + + if (OF_getencprop(node, "snps,reset-delays-us", + delay_prop, sizeof(delay_prop)) <= 0) { + device_printf(dev, + "Wrong property for snps,reset-delays-us"); + return (ENXIO); + } + + gpio_node = OF_node_from_xref(gpio_prop[0]); + if ((gpio = OF_device_from_xref(gpio_prop[0])) == NULL) { + device_printf(dev, + "Can't find gpio controller for phy reset\n"); + return (ENXIO); + } + + if (GPIO_MAP_GPIOS(gpio, node, gpio_node, + nitems(gpio_prop) - 1, + gpio_prop + 1, &pin, &flags) != 0) { + device_printf(dev, "Can't map gpio for phy reset\n"); + return (ENXIO); + } + + pin_value = GPIO_PIN_LOW; + if (OF_hasprop(node, "snps,reset-active-low")) + pin_value = GPIO_PIN_HIGH; + + GPIO_PIN_SETFLAGS(gpio, pin, GPIO_PIN_OUTPUT); + GPIO_PIN_SET(gpio, pin, pin_value); + DELAY(delay_prop[0]); + GPIO_PIN_SET(gpio, pin, !pin_value); + DELAY(delay_prop[1]); + GPIO_PIN_SET(gpio, pin, pin_value); + DELAY(delay_prop[2]); + + return (0); +} + +static int +eqos_fdt_init(device_t dev) +{ + struct eqos_softc *sc = device_get_softc(dev); + phandle_t node = ofw_bus_get_node(dev); + hwreset_t eqos_reset; + regulator_t eqos_supply; + uint32_t rx_delay, tx_delay; + uint8_t buffer[16]; + + if (OF_hasprop(node, "rockchip,grf") && + syscon_get_by_ofw_property(dev, node, "rockchip,grf", &sc->grf)) { + device_printf(dev, "cannot get grf driver handle\n"); + return (ENXIO); + } + + /* figure out if gmac0 or gmac1 offset */ + switch (rman_get_start(sc->res[EQOS_RES_MEM])) { + case RK356XGMAC0: /* RK356X gmac0 */ + sc->grf_offset = EQOS_GRF_GMAC0; + break; + case RK356XGMAC1: /* RK356X gmac1 */ + sc->grf_offset = EQOS_GRF_GMAC1; + break; + case RK3588GMAC0: /* RK3588 gmac0 */ + case RK3588GMAC1: /* RK3588 gmac1 */ + default: + device_printf(dev, "Unknown eqos address\n"); + return (ENXIO); + } + + if (hwreset_get_by_ofw_idx(dev, node, 0, &eqos_reset)) { + device_printf(dev, "cannot get reset\n"); + return (ENXIO); + } + else + hwreset_assert(eqos_reset); + + sc->csr_clock = 125000000; + sc->csr_clock_range = GMAC_MAC_MDIO_ADDRESS_CR_100_150; + + if (OF_getencprop(node, "tx_delay", &tx_delay, sizeof(tx_delay)) <= 0) + tx_delay = 0x30; + if (OF_getencprop(node, "rx_delay", &rx_delay, sizeof(rx_delay)) <= 0) + rx_delay = 0x10; + + SYSCON_WRITE_4(sc->grf, sc->grf_offset + EQOS_CON0_OFFSET, + EQOS_GMAC_CLK_RX_DL_CFG(rx_delay) | + EQOS_GMAC_CLK_TX_DL_CFG(tx_delay)); + SYSCON_WRITE_4(sc->grf, sc->grf_offset + EQOS_CON1_OFFSET, + EQOS_GMAC_PHY_INTF_SEL_RGMII | + EQOS_GMAC_RXCLK_DLY_ENABLE | + EQOS_GMAC_TXCLK_DLY_ENABLE); + + if (!regulator_get_by_ofw_property(dev, 0, "phy-supply", + &eqos_supply)) { + if (regulator_enable(eqos_supply)) + device_printf(dev, "cannot enable 'phy' regulator\n"); + } + else + device_printf(dev, "no phy-supply property\n"); + + if (eqos_phy_reset(dev)) + return (ENXIO); + + if (eqos_reset) + hwreset_deassert(eqos_reset); + + /* set the MAC address if we have OTP data handy */ + if (!RK_OTP_READ(dev, buffer, 0, sizeof(buffer))) { + uint32_t mac; + + mac = hash32_buf(buffer, sizeof(buffer), HASHINIT); + WR4(sc, GMAC_MAC_ADDRESS0_LOW, + htobe32((mac & 0xffffff00) | 0x22)); + + mac = hash32_buf(buffer, sizeof(buffer), mac); + WR4(sc, GMAC_MAC_ADDRESS0_HIGH, + htobe16((mac & 0x0000ffff) + (device_get_unit(dev) << 8))); + } + + return (0); +} + +static int +eqos_fdt_probe(device_t dev) +{ + + if (!ofw_bus_status_okay(dev)) + return (ENXIO); + if (ofw_bus_search_compatible(dev, compat_data)->ocd_data == 0) + return (ENXIO); + + device_set_desc(dev, "DesignWare EQOS Gigabit ethernet"); + + return (BUS_PROBE_DEFAULT); +} + + +static device_method_t eqos_fdt_methods[] = { + /* Device interface */ + DEVMETHOD(device_probe, eqos_fdt_probe), + + /* EQOS interface */ + DEVMETHOD(eqos_init, eqos_fdt_init), + + DEVMETHOD_END +}; + +DEFINE_CLASS_1(eqos, eqos_fdt_driver, eqos_fdt_methods, + sizeof(struct eqos_softc), eqos_driver); +DRIVER_MODULE(eqos, simplebus, eqos_fdt_driver, 0, 0); +MODULE_DEPEND(eqos, ether, 1, 1, 1); +MODULE_DEPEND(eqos, miibus, 1, 1, 1); diff --git a/sys/dev/eqos/if_eqos_if.m b/sys/dev/eqos/if_eqos_if.m new file mode 100644 index 000000000000..0f56ce76c960 --- /dev/null +++ b/sys/dev/eqos/if_eqos_if.m @@ -0,0 +1,63 @@ +#- +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# +# Copyright (c) 2022 Soren Schmidt +# 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 AUTHOR 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 AUTHOR 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. +# +# $Id: eqos_if.m 921 2022-08-09 18:38:11Z sos $ +# + +INTERFACE eqos; + +CODE { + static int + eqos_default_init(device_t dev) + { + return (0); + } + + static int + eqos_default_set_speed(device_t dev, int speed) + { + return (0); + } +}; + +HEADER { +}; + +# +# Initialize SoC specific registers. +# +METHOD int init { + device_t dev; +} DEFAULT eqos_default_init; + +# +# Signal media change to a specific hardware +# +METHOD int set_speed { + device_t dev; + int speed; +} DEFAULT eqos_default_set_speed; diff --git a/sys/dev/eqos/if_eqos_reg.h b/sys/dev/eqos/if_eqos_reg.h new file mode 100644 index 000000000000..90764109b3ab --- /dev/null +++ b/sys/dev/eqos/if_eqos_reg.h @@ -0,0 +1,295 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2022 Jared McNeill + * 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 AUTHOR ``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 AUTHOR 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. + * + * $Id: eqos_reg.h 921 2022-08-09 18:38:11Z sos $ + */ + +/* + * DesignWare Ethernet Quality-of-Service controller + */ + +#ifndef _EQOS_REG_H +#define _EQOS_REG_H + +#define GMAC_MAC_CONFIGURATION 0x0000 +#define GMAC_MAC_CONFIGURATION_CST (1U << 21) +#define GMAC_MAC_CONFIGURATION_ACS (1U << 20) +#define GMAC_MAC_CONFIGURATION_BE (1U << 18) +#define GMAC_MAC_CONFIGURATION_JD (1U << 17) +#define GMAC_MAC_CONFIGURATION_JE (1U << 16) +#define GMAC_MAC_CONFIGURATION_PS (1U << 15) +#define GMAC_MAC_CONFIGURATION_FES (1U << 14) +#define GMAC_MAC_CONFIGURATION_DM (1U << 13) +#define GMAC_MAC_CONFIGURATION_DCRS (1U << 9) +#define GMAC_MAC_CONFIGURATION_TE (1U << 1) +#define GMAC_MAC_CONFIGURATION_RE (1U << 0) +#define GMAC_MAC_EXT_CONFIGURATION 0x0004 +#define GMAC_MAC_PACKET_FILTER 0x0008 +#define GMAC_MAC_PACKET_FILTER_HPF (1U << 10) +#define GMAC_MAC_PACKET_FILTER_PCF_MASK (3U << 6) +#define GMAC_MAC_PACKET_FILTER_PCF_ALL (2U << 6) +#define GMAC_MAC_PACKET_FILTER_DBF (1U << 5) +#define GMAC_MAC_PACKET_FILTER_PM (1U << 4) +#define GMAC_MAC_PACKET_FILTER_HMC (1U << 2) +#define GMAC_MAC_PACKET_FILTER_HUC (1U << 1) +#define GMAC_MAC_PACKET_FILTER_PR (1U << 0) +#define GMAC_MAC_WATCHDOG_TIMEOUT 0x000C +#define GMAC_MAC_HASH_TABLE_REG0 0x0010 +#define GMAC_MAC_HASH_TABLE_REG1 0x0014 +#define GMAC_MAC_VLAN_TAG 0x0050 +#define GMAC_MAC_Q0_TX_FLOW_CTRL 0x0070 +#define GMAC_MAC_Q0_TX_FLOW_CTRL_PT_SHIFT 16 +#define GMAC_MAC_Q0_TX_FLOW_CTRL_TFE (1U << 1) +#define GMAC_MAC_RX_FLOW_CTRL 0x0090 +#define GMAC_MAC_RX_FLOW_CTRL_RFE (1U << 0) +#define GMAC_RXQ_CTRL0 0x00A0 +#define GMAC_RXQ_CTRL0_EN_MASK 0x3 +#define GMAC_RXQ_CTRL0_EN_DCB 0x2 +#define GMAC_RXQ_CTRL1 0x00A4 +#define GMAC_MAC_INTERRUPT_STATUS 0x00B0 +#define GMAC_MAC_INTERRUPT_ENABLE 0x00B4 +#define GMAC_MAC_RX_TX_STATUS 0x00B8 +#define GMAC_MAC_RX_TX_STATUS_RWT (1U << 8) +#define GMAC_MAC_RX_TX_STATUS_EXCOL (1U << 5) +#define GMAC_MAC_RX_TX_STATUS_LCOL (1U << 4) +#define GMAC_MAC_RX_TX_STATUS_EXDEF (1U << 3) +#define GMAC_MAC_RX_TX_STATUS_LCARR (1U << 2) +#define GMAC_MAC_RX_TX_STATUS_NCARR (1U << 1) +#define GMAC_MAC_RX_TX_STATUS_TJT (1U << 0) +#define GMAC_MAC_PMT_CONTROL_STATUS 0x00C0 +#define GMAC_MAC_RWK_PACKET_FILTER 0x00C4 +#define GMAC_MAC_LPI_CONTROL_STATUS 0x00D0 +#define GMAC_MAC_LPI_TIMERS_CONTROL 0x00D4 +#define GMAC_MAC_LPI_ENTRY_TIMER 0x00D8 +#define GMAC_MAC_1US_TIC_COUNTER 0x00DC +#define GMAC_MAC_PHYIF_CONTROL_STATUS 0x00F8 +#define GMAC_MAC_VERSION 0x0110 +#define GMAC_MAC_VERSION_USERVER_SHIFT 8 +#define GMAC_MAC_VERSION_USERVER_MASK (0xFFU << GMAC_MAC_VERSION_USERVER_SHIFT) +#define GMAC_MAC_VERSION_SNPSVER_MASK 0xFFU +#define GMAC_MAC_DEBUG 0x0114 +#define GMAC_MAC_HW_FEATURE(n) (0x011C + 0x4 * (n)) +#define GMAC_MAC_HW_FEATURE1_ADDR64_SHIFT 14 +#define GMAC_MAC_HW_FEATURE1_ADDR64_MASK (0x3U << GMAC_MAC_HW_FEATURE1_ADDR64_SHIFT) +#define GMAC_MAC_HW_FEATURE1_ADDR64_32BIT (0x0U << GMAC_MAC_HW_FEATURE1_ADDR64_SHIFT) +#define GMAC_MAC_MDIO_ADDRESS 0x0200 +#define GMAC_MAC_MDIO_ADDRESS_PA_SHIFT 21 +#define GMAC_MAC_MDIO_ADDRESS_RDA_SHIFT 16 +#define GMAC_MAC_MDIO_ADDRESS_CR_SHIFT 8 +#define GMAC_MAC_MDIO_ADDRESS_CR_MASK (0x7U << GMAC_MAC_MDIO_ADDRESS_CR_SHIFT) +#define GMAC_MAC_MDIO_ADDRESS_CR_60_100 (0U << GMAC_MAC_MDIO_ADDRESS_CR_SHIFT) +#define GMAC_MAC_MDIO_ADDRESS_CR_100_150 (1U << GMAC_MAC_MDIO_ADDRESS_CR_SHIFT) +#define GMAC_MAC_MDIO_ADDRESS_CR_20_35 (2U << GMAC_MAC_MDIO_ADDRESS_CR_SHIFT) +#define GMAC_MAC_MDIO_ADDRESS_CR_35_60 (3U << GMAC_MAC_MDIO_ADDRESS_CR_SHIFT) +#define GMAC_MAC_MDIO_ADDRESS_CR_150_250 (4U << GMAC_MAC_MDIO_ADDRESS_CR_SHIFT) +#define GMAC_MAC_MDIO_ADDRESS_CR_250_300 (5U << GMAC_MAC_MDIO_ADDRESS_CR_SHIFT) +#define GMAC_MAC_MDIO_ADDRESS_CR_300_500 (6U << GMAC_MAC_MDIO_ADDRESS_CR_SHIFT) +#define GMAC_MAC_MDIO_ADDRESS_CR_500_800 (7U << GMAC_MAC_MDIO_ADDRESS_CR_SHIFT) +#define GMAC_MAC_MDIO_ADDRESS_SKAP (1U << 4) +#define GMAC_MAC_MDIO_ADDRESS_GOC_SHIFT 2 +#define GMAC_MAC_MDIO_ADDRESS_GOC_READ (3U << GMAC_MAC_MDIO_ADDRESS_GOC_SHIFT) +#define GMAC_MAC_MDIO_ADDRESS_GOC_WRITE (1U << GMAC_MAC_MDIO_ADDRESS_GOC_SHIFT) +#define GMAC_MAC_MDIO_ADDRESS_C45E (1U << 1) +#define GMAC_MAC_MDIO_ADDRESS_GB (1U << 0) +#define GMAC_MAC_MDIO_DATA 0x0204 +#define GMAC_MAC_CSR_SW_CTRL 0x0230 +#define GMAC_MAC_ADDRESS0_HIGH 0x0300 +#define GMAC_MAC_ADDRESS0_LOW 0x0304 +#define GMAC_MMC_CONTROL 0x0700 +#define GMAC_MMC_CONTROL_UCDBC (1U << 8) +#define GMAC_MMC_CONTROL_CNTPRSTLVL (1U << 5) +#define GMAC_MMC_CONTROL_CNTPRST (1U << 4) +#define GMAC_MMC_CONTROL_CNTFREEZ (1U << 3) +#define GMAC_MMC_CONTROL_RSTONRD (1U << 2) +#define GMAC_MMC_CONTROL_CNTSTOPRO (1U << 1) +#define GMAC_MMC_CONTROL_CNTRST (1U << 0) +#define GMAC_MMC_RX_INTERRUPT 0x0704 +#define GMAC_MMC_TX_INTERRUPT 0x0708 +#define GMAC_MMC_RX_INTERRUPT_MASK 0x070C +#define GMAC_MMC_TX_INTERRUPT_MASK 0x0710 +#define GMAC_TX_OCTET_COUNT_GOOD_BAD 0x0714 +#define GMAC_TX_PACKET_COUNT_GOOD_BAD 0x0718 +#define GMAC_TX_UNDERFLOW_ERROR_PACKETS 0x0748 +#define GMAC_TX_CARRIER_ERROR_PACKETS 0x0760 +#define GMAC_TX_OCTET_COUNT_GOOD 0x0764 +#define GMAC_TX_PACKET_COUNT_GOOD 0x0768 +#define GMAC_RX_PACKETS_COUNT_GOOD_BAD 0x0780 +#define GMAC_RX_OCTET_COUNT_GOOD_BAD 0x0784 +#define GMAC_RX_OCTET_COUNT_GOOD 0x0788 +#define GMAC_RX_MULTICAST_PACKETS_GOOD 0x0790 +#define GMAC_RX_CRC_ERROR_PACKETS 0x0794 +#define GMAC_RX_LENGTH_ERROR_PACKETS 0x07C8 +#define GMAC_RX_FIFO_OVERFLOW_PACKETS 0x07D4 +#define GMAC_MMC_IPC_RX_INTERRUPT_MASK 0x0800 +#define GMAC_MMC_IPC_RX_INTERRUPT 0x0808 +#define GMAC_RXIPV4_GOOD_PACKETS 0x0810 +#define GMAC_RXIPV4_HEADER_ERROR_PACKETS 0x0814 +#define GMAC_RXIPV6_GOOD_PACKETS 0x0824 +#define GMAC_RXIPV6_HEADER_ERROR_PACKETS 0x0828 +#define GMAC_RXUDP_ERROR_PACKETS 0x0834 +#define GMAC_RXTCP_ERROR_PACKETS 0x083C +#define GMAC_RXICMP_ERROR_PACKETS 0x0844 +#define GMAC_RXIPV4_HEADER_ERROR_OCTETS 0x0854 +#define GMAC_RXIPV6_HEADER_ERROR_OCTETS 0x0868 +#define GMAC_RXUDP_ERROR_OCTETS 0x0874 +#define GMAC_RXTCP_ERROR_OCTETS 0x087C +#define GMAC_RXICMP_ERROR_OCTETS 0x0884 +#define GMAC_MAC_TIMESTAMP_CONTROL 0x0B00 +#define GMAC_MAC_SUB_SECOND_INCREMENT 0x0B04 +#define GMAC_MAC_SYSTEM_TIME_SECS 0x0B08 +#define GMAC_MAC_SYSTEM_TIME_NS 0x0B0C +#define GMAC_MAC_SYS_TIME_SECS_UPDATE 0x0B10 +#define GMAC_MAC_SYS_TIME_NS_UPDATE 0x0B14 +#define GMAC_MAC_TIMESTAMP_ADDEND 0x0B18 +#define GMAC_MAC_TIMESTAMP_STATUS 0x0B20 +#define GMAC_MAC_TX_TS_STATUS_NS 0x0B30 +#define GMAC_MAC_TX_TS_STATUS_SECS 0x0B34 +#define GMAC_MAC_AUXILIARY_CONTROL 0x0B40 +#define GMAC_MAC_AUXILIARY_TS_NS 0x0B48 +#define GMAC_MAC_AUXILIARY_TS_SECS 0x0B4C +#define GMAC_MAC_TS_INGRESS_CORR_NS 0x0B58 +#define GMAC_MAC_TS_EGRESS_CORR_NS 0x0B5C +#define GMAC_MAC_TS_INGRESS_LATENCY 0x0B68 +#define GMAC_MAC_TS_EGRESS_LATENCY 0x0B6C +#define GMAC_MAC_PPS_CONTROL 0x0B70 +#define GMAC_MTL_DBG_CTL 0x0C08 +#define GMAC_MTL_DBG_STS 0x0C0C +#define GMAC_MTL_FIFO_DEBUG_DATA 0x0C10 +#define GMAC_MTL_INTERRUPT_STATUS 0x0C20 +#define GMAC_MTL_INTERRUPT_STATUS_DBGIS (1U << 17) +#define GMAC_MTL_INTERRUPT_STATUS_Q0IS (1U << 0) +#define GMAC_MTL_TXQ0_OPERATION_MODE 0x0D00 +#define GMAC_MTL_TXQ0_OPERATION_MODE_TXQEN_SHIFT 2 +#define GMAC_MTL_TXQ0_OPERATION_MODE_TXQEN_MASK (0x3U << GMAC_MTL_TXQ0_OPERATION_MODE_TXQEN_SHIFT) +#define GMAC_MTL_TXQ0_OPERATION_MODE_TXQEN_EN (2U << GMAC_MTL_TXQ0_OPERATION_MODE_TXQEN_SHIFT) +#define GMAC_MTL_TXQ0_OPERATION_MODE_TSF (1U << 1) +#define GMAC_MTL_TXQ0_OPERATION_MODE_FTQ (1U << 0) +#define GMAC_MTL_TXQ0_UNDERFLOW 0x0D04 +#define GMAC_MTL_TXQ0_DEBUG 0x0D08 +#define GMAC_MTL_Q0_INTERRUPT_CTRL_STATUS 0x0D2C +#define GMAC_MTL_Q0_INTERRUPT_CTRL_STATUS_RXOIE (1U << 24) +#define GMAC_MTL_Q0_INTERRUPT_CTRL_STATUS_RXOVFIS (1U << 16) +#define GMAC_MTL_Q0_INTERRUPT_CTRL_STATUS_TXUIE (1U << 8) +#define GMAC_MTL_Q0_INTERRUPT_CTRL_STATUS_TXUNFIS (1U << 0) +#define GMAC_MTL_RXQ0_OPERATION_MODE 0x0D30 +#define GMAC_MTL_RXQ0_OPERATION_MODE_RSF (1U << 5) +#define GMAC_MTL_RXQ0_OPERATION_MODE_FEP (1U << 4) +#define GMAC_MTL_RXQ0_OPERATION_MODE_FUP (1U << 3) +#define GMAC_MTL_RXQ0_MISS_PKT_OVF_CNT 0x0D34 +#define GMAC_MTL_RXQ0_DEBUG 0x0D38 +#define GMAC_DMA_MODE 0x1000 +#define GMAC_DMA_MODE_SWR (1U << 0) +#define GMAC_DMA_SYSBUS_MODE 0x1004 +#define GMAC_DMA_SYSBUS_MODE_WR_OSR_LMT_SHIFT 24 +#define GMAC_DMA_SYSBUS_MODE_WR_OSR_LMT_MASK (0x3U << GMAC_DMA_SYSBUS_MODE_WR_OSR_LMT_SHIFT) +#define GMAC_DMA_SYSBUS_MODE_RD_OSR_LMT_SHIFT 16 +#define GMAC_DMA_SYSBUS_MODE_RD_OSR_LMT_MASK (0x7U << GMAC_DMA_SYSBUS_MODE_RD_OSR_LMT_SHIFT) +#define GMAC_DMA_SYSBUS_MODE_MB (1U << 14) +#define GMAC_DMA_SYSBUS_MODE_EAME (1U << 11) +#define GMAC_DMA_SYSBUS_MODE_BLEN16 (1U << 3) +#define GMAC_DMA_SYSBUS_MODE_BLEN8 (1U << 2) +#define GMAC_DMA_SYSBUS_MODE_BLEN4 (1U << 1) +#define GMAC_DMA_SYSBUS_MODE_FB (1U << 0) +#define GMAC_DMA_INTERRUPT_STATUS 0x1008 +#define GMAC_DMA_DEBUG_STATUS0 0x100C +#define GMAC_AXI_LPI_ENTRY_INTERVAL 0x1040 +#define GMAC_RWK_FILTERn_BYTE_MASK(n) (0x10C0 + 0x4 * (n)) +#define GMAC_RWK_FILTER01_CRC 0x10D0 +#define GMAC_RWK_FILTER23_CRC 0x10D4 +#define GMAC_RWK_FILTER_OFFSET 0x10D8 +#define GMAC_RWK_FILTER_COMMAND 0x10DC +#define GMAC_DMA_CHAN0_CONTROL 0x1100 +#define GMAC_DMA_CHAN0_CONTROL_DSL_SHIFT 18 +#define GMAC_DMA_CHAN0_CONTROL_DSL_MASK (0x7U << GMAC_DMA_CHAN0_CONTROL_DSL_SHIFT) +#define GMAC_DMA_CHAN0_CONTROL_PBLX8 (1U << 16) +#define GMAC_DMA_CHAN0_TX_CONTROL 0x1104 +#define GMAC_DMA_CHAN0_TX_CONTROL_OSP (1U << 4) +#define GMAC_DMA_CHAN0_TX_CONTROL_START (1U << 0) +#define GMAC_DMA_CHAN0_RX_CONTROL 0x1108 +#define GMAC_DMA_CHAN0_RX_CONTROL_RBSZ_SHIFT 1 +#define GMAC_DMA_CHAN0_RX_CONTROL_RBSZ_MASK (0x3FFFU << GMAC_DMA_CHAN0_RX_CONTROL_RBSZ_SHIFT) +#define GMAC_DMA_CHAN0_RX_CONTROL_START (1U << 0) +#define GMAC_DMA_CHAN0_TX_BASE_ADDR_HI 0x1110 +#define GMAC_DMA_CHAN0_TX_BASE_ADDR 0x1114 +#define GMAC_DMA_CHAN0_RX_BASE_ADDR_HI 0x1118 +#define GMAC_DMA_CHAN0_RX_BASE_ADDR 0x111C +#define GMAC_DMA_CHAN0_TX_END_ADDR 0x1120 +#define GMAC_DMA_CHAN0_RX_END_ADDR 0x1128 +#define GMAC_DMA_CHAN0_TX_RING_LEN 0x112C +#define GMAC_DMA_CHAN0_RX_RING_LEN 0x1130 +#define GMAC_DMA_CHAN0_INTR_ENABLE 0x1134 +#define GMAC_DMA_CHAN0_INTR_ENABLE_NIE (1U << 15) +#define GMAC_DMA_CHAN0_INTR_ENABLE_AIE (1U << 14) +#define GMAC_DMA_CHAN0_INTR_ENABLE_CDE (1U << 13) +#define GMAC_DMA_CHAN0_INTR_ENABLE_FBE (1U << 12) +#define GMAC_DMA_CHAN0_INTR_ENABLE_ERI (1U << 11) +#define GMAC_DMA_CHAN0_INTR_ENABLE_ETI (1U << 10) +#define GMAC_DMA_CHAN0_INTR_ENABLE_RWT (1U << 9) +#define GMAC_DMA_CHAN0_INTR_ENABLE_RPS (1U << 8) +#define GMAC_DMA_CHAN0_INTR_ENABLE_RBU (1U << 7) +#define GMAC_DMA_CHAN0_INTR_ENABLE_RIE (1U << 6) +#define GMAC_DMA_CHAN0_INTR_ENABLE_TPU (1U << 2) +#define GMAC_DMA_CHAN0_INTR_ENABLE_TPS (1U << 1) +#define GMAC_DMA_CHAN0_INTR_ENABLE_TIE (1U << 0) +#define GMAC_DMA_CHAN0_RX_WATCHDOG 0x1138 +#define GMAC_DMA_CHAN0_SLOT_CTRL_STATUS 0x113C +#define GMAC_DMA_CHAN0_CUR_TX_DESC 0x1144 +#define GMAC_DMA_CHAN0_CUR_RX_DESC 0x114C +#define GMAC_DMA_CHAN0_CUR_TX_BUF_ADDR 0x1154 +#define GMAC_DMA_CHAN0_CUR_RX_BUF_ADDR 0x115C +#define GMAC_DMA_CHAN0_STATUS 0x1160 +#define GMAC_DMA_CHAN0_STATUS_NIS (1U << 15) +#define GMAC_DMA_CHAN0_STATUS_AIS (1U << 14) +#define GMAC_DMA_CHAN0_STATUS_CDE (1U << 13) +#define GMAC_DMA_CHAN0_STATUS_FB (1U << 12) +#define GMAC_DMA_CHAN0_STATUS_ERI (1U << 11) +#define GMAC_DMA_CHAN0_STATUS_ETI (1U << 10) +#define GMAC_DMA_CHAN0_STATUS_RWT (1U << 9) +#define GMAC_DMA_CHAN0_STATUS_RPS (1U << 8) +#define GMAC_DMA_CHAN0_STATUS_RBU (1U << 7) +#define GMAC_DMA_CHAN0_STATUS_RI (1U << 6) +#define GMAC_DMA_CHAN0_STATUS_TPU (1U << 2) +#define GMAC_DMA_CHAN0_STATUS_TPS (1U << 1) +#define GMAC_DMA_CHAN0_STATUS_TI (1U << 0) + +#define EQOS_TDES2_IOC (1U << 31) +#define EQOS_TDES3_OWN (1U << 31) +#define EQOS_TDES3_FD (1U << 29) +#define EQOS_TDES3_LD (1U << 28) +#define EQOS_TDES3_DE (1U << 23) +#define EQOS_TDES3_OE (1U << 21) +#define EQOS_TDES3_ES (1U << 15) + +#define EQOS_RDES3_OWN (1U << 31) +#define EQOS_RDES3_IOC (1U << 30) +#define EQOS_RDES3_BUF1V (1U << 24) +#define EQOS_RDES3_GP (1U << 23) +#define EQOS_RDES3_OE (1U << 21) +#define EQOS_RDES3_RE (1U << 20) +#define EQOS_RDES3_LENGTH_MASK 0x7FFFU + +#endif diff --git a/sys/dev/eqos/if_eqos_var.h b/sys/dev/eqos/if_eqos_var.h new file mode 100644 index 000000000000..5bc887d23cd8 --- /dev/null +++ b/sys/dev/eqos/if_eqos_var.h @@ -0,0 +1,99 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2022 Soren Schmidt + * Copyright (c) 2022 Jared McNeill + * 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 AUTHOR ``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 AUTHOR 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. + * + * $Id: eqos_var.h 1009 2022-11-15 20:17:35Z sos $ + */ + +/* + * DesignWare Ethernet Quality-of-Service controller + */ + +#ifndef _EQOS_VAR_H +#define _EQOS_VAR_H + +#include + +#define EQOS_DMA_DESC_COUNT 256 + +#define EQOS_RES_MEM 0 +#define EQOS_RES_IRQ0 1 +#define EQOS_RES_COUNT 2 + +#define EQOS_INTR_FLAGS (INTR_TYPE_NET | INTR_MPSAFE) + +struct eqos_dma_desc { + uint32_t des0; + uint32_t des1; + uint32_t des2; + uint32_t des3; +} __packed; + +struct eqos_bufmap { + bus_dmamap_t map; + struct mbuf *mbuf; +}; + +struct eqos_ring { + bus_dma_tag_t desc_tag; + bus_dmamap_t desc_map; + struct eqos_dma_desc *desc_ring; + bus_addr_t desc_ring_paddr; + + bus_dma_tag_t buf_tag; + struct eqos_bufmap buf_map[EQOS_DMA_DESC_COUNT]; + + u_int head; + u_int tail; +}; + +struct eqos_softc { + device_t dev; + struct resource *res[EQOS_RES_COUNT]; + void *irq_handle; +#ifdef FDT + struct syscon *grf; + int grf_offset; +#endif + uint32_t csr_clock; + uint32_t csr_clock_range; + uint32_t hw_feature[4]; + bool link_up; + int tx_watchdog; + + struct ifnet *ifp; + device_t miibus; + struct mtx lock; + struct callout callout; + + struct eqos_ring tx; + struct eqos_ring rx; +}; + +DECLARE_CLASS(eqos_driver); + +#endif