From: visa Date: Sat, 30 Jan 2021 14:59:13 +0000 (+0000) Subject: Abstract octeon board handling a little X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=2bbf581cd0b529f21a6f418a4467e74927b76dd5;p=openbsd Abstract octeon board handling a little Detect octeon board model in one place, and replace firmware-supplied board_type with an abstract model identifier in driver code. This makes it easier to manage with different products, and board flavours, that happen to use the same model information, such as board_type. --- diff --git a/sys/arch/octeon/dev/amdcf.c b/sys/arch/octeon/dev/amdcf.c index 9c60dc598f6..48314d581fa 100644 --- a/sys/arch/octeon/dev/amdcf.c +++ b/sys/arch/octeon/dev/amdcf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: amdcf.c,v 1.6 2018/05/30 14:53:56 fcambus Exp $ */ +/* $OpenBSD: amdcf.c,v 1.7 2021/01/30 14:59:13 visa Exp $ */ /* * Copyright (c) 2007, Juniper Networks, Inc. @@ -218,7 +218,7 @@ amdcf_match(struct device *parent, void *match, void *aux) return 0; /* Only for DSR machines */ - if (octeon_boot_info->board_type != BOARD_TYPE_DSR_500) + if (octeon_board != BOARD_DLINK_DSR_500) return 0; return 1; diff --git a/sys/arch/octeon/dev/cn30xxgmx.c b/sys/arch/octeon/dev/cn30xxgmx.c index 7e4cf59e2c9..803cb9c5cc5 100644 --- a/sys/arch/octeon/dev/cn30xxgmx.c +++ b/sys/arch/octeon/dev/cn30xxgmx.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cn30xxgmx.c,v 1.47 2020/09/08 15:46:36 visa Exp $ */ +/* $OpenBSD: cn30xxgmx.c,v 1.48 2021/01/30 14:59:13 visa Exp $ */ /* * Copyright (c) 2007 Internet Initiative Japan, Inc. @@ -1333,14 +1333,14 @@ cn30xxgmx_rgmii_timing(struct cn30xxgmx_port_softc *sc) * > ... */ - switch (octeon_boot_info->board_type) { + switch (octeon_board) { default: /* Default parameter of CN30XX */ clk_tx_setting = 24; clk_rx_setting = 24; break; - case BOARD_TYPE_UBIQUITI_E100: - case BOARD_TYPE_UBIQUITI_E120: + case BOARD_UBIQUITI_E100: + case BOARD_UBIQUITI_E120: clk_tx_setting = 16; clk_rx_setting = 0; break; diff --git a/sys/arch/octeon/dev/cn30xxsmi.c b/sys/arch/octeon/dev/cn30xxsmi.c index c4b212a68e7..9b475281518 100644 --- a/sys/arch/octeon/dev/cn30xxsmi.c +++ b/sys/arch/octeon/dev/cn30xxsmi.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cn30xxsmi.c,v 1.7 2019/09/28 22:20:25 deraadt Exp $ */ +/* $OpenBSD: cn30xxsmi.c,v 1.8 2021/01/30 14:59:13 visa Exp $ */ /* * Copyright (c) 2007 Internet Initiative Japan, Inc. @@ -179,14 +179,14 @@ cn30xxsmi_get_phy(int phandle, int port, struct cn30xxsmi_softc **psmi, if (smi == NULL) return ENOENT; - switch (octeon_boot_info->board_type) { - case BOARD_TYPE_UBIQUITI_E100: - case BOARD_TYPE_UBIQUITI_E120: + switch (octeon_board) { + case BOARD_UBIQUITI_E100: + case BOARD_UBIQUITI_E120: if (port > 2) return ENOENT; reg = 7 - port; break; - case BOARD_TYPE_CN3010_EVB_HS5: + case BOARD_CN3010_EVB_HS5: if (port >= nitems(cam0100_phys)) return ENOENT; reg = cam0100_phys[port]; diff --git a/sys/arch/octeon/dev/octrtc.c b/sys/arch/octeon/dev/octrtc.c index 129f83726c3..ecb28194147 100644 --- a/sys/arch/octeon/dev/octrtc.c +++ b/sys/arch/octeon/dev/octrtc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: octrtc.c,v 1.12 2020/06/30 14:47:16 visa Exp $ */ +/* $OpenBSD: octrtc.c,v 1.13 2021/01/30 14:59:13 visa Exp $ */ /* * Copyright (c) 2013, 2014 Paul Irofti. @@ -80,14 +80,14 @@ union mio_tws_sw_twsi_reg { }; -static const uint16_t no_rtc_boards[] = { - BOARD_TYPE_UBIQUITI_E100, - BOARD_TYPE_UBIQUITI_E120, - BOARD_TYPE_UBIQUITI_E200, - BOARD_TYPE_UBIQUITI_E220, - BOARD_TYPE_UBIQUITI_E300, - BOARD_TYPE_UBIQUITI_E1000, - BOARD_TYPE_RHINOLABS_SHASTA +static const enum octeon_board no_rtc_boards[] = { + BOARD_UBIQUITI_E100, + BOARD_UBIQUITI_E120, + BOARD_UBIQUITI_E200, + BOARD_UBIQUITI_E220, + BOARD_UBIQUITI_E300, + BOARD_UBIQUITI_E1000, + BOARD_RHINOLABS_UTM8, }; int @@ -100,7 +100,7 @@ octrtc_match(struct device *parent, void *match, void *aux) if (strcmp(maa->maa_name, cf->cf_driver->cd_name) != 0) return 0; for (i = 0; i < nitems(no_rtc_boards); i++) - if (octeon_boot_info->board_type == no_rtc_boards[i]) + if (octeon_board == no_rtc_boards[i]) return 0; return 1; } diff --git a/sys/arch/octeon/include/octeonvar.h b/sys/arch/octeon/include/octeonvar.h index 8ad00ddb9eb..1fb0063a9a2 100644 --- a/sys/arch/octeon/include/octeonvar.h +++ b/sys/arch/octeon/include/octeonvar.h @@ -1,4 +1,4 @@ -/* $OpenBSD: octeonvar.h,v 1.49 2020/09/04 15:18:05 visa Exp $ */ +/* $OpenBSD: octeonvar.h,v 1.50 2021/01/30 14:59:14 visa Exp $ */ /* $NetBSD: maltavar.h,v 1.3 2002/03/18 10:10:16 simonb Exp $ */ /*- @@ -202,24 +202,28 @@ enum cnmac_stat { cnmac_stat_count }; -/* - * Octeon board types known to work with OpenBSD/octeon. - * NB: BOARD_TYPE_UBIQUITI_E100 is also used by other vendors, but we don't run - * on those boards yet. - */ -#define BOARD_TYPE_CN3010_EVB_HS5 11 -#define BOARD_TYPE_UBIQUITI_E100 20002 -#define BOARD_TYPE_UBIQUITI_E200 20003 -#define BOARD_TYPE_UBIQUITI_E120 20004 -#define BOARD_TYPE_UBIQUITI_E220 20005 -#define BOARD_TYPE_UBIQUITI_E1000 20010 -#define BOARD_TYPE_RHINOLABS_SHASTA 20012 -#define BOARD_TYPE_DSR_500 20015 -#define BOARD_TYPE_UBIQUITI_E300 20300 - #if defined(_KERNEL) || defined(_STANDALONE) #define OCTEON_ARGV_MAX 64 +/* + * OCTEON board types recognized by OpenBSD/octeon. + * + * It is fine to use BOARD_UNKNOWN when the board does not need + * special treatment. + */ +enum octeon_board { + BOARD_UNKNOWN, + BOARD_CN3010_EVB_HS5, + BOARD_DLINK_DSR_500, + BOARD_RHINOLABS_UTM8, + BOARD_UBIQUITI_E100, + BOARD_UBIQUITI_E120, + BOARD_UBIQUITI_E200, + BOARD_UBIQUITI_E220, + BOARD_UBIQUITI_E300, + BOARD_UBIQUITI_E1000, +}; + struct boot_desc { uint32_t desc_ver; uint32_t desc_size; @@ -306,6 +310,7 @@ struct octeon_bootmem_block { uint64_t size; }; +extern enum octeon_board octeon_board; extern struct boot_desc *octeon_boot_desc; extern struct boot_info *octeon_boot_info; diff --git a/sys/arch/octeon/octeon/machdep.c b/sys/arch/octeon/octeon/machdep.c index 060f5acd8f7..a92959b8789 100644 --- a/sys/arch/octeon/octeon/machdep.c +++ b/sys/arch/octeon/octeon/machdep.c @@ -1,4 +1,4 @@ -/* $OpenBSD: machdep.c,v 1.127 2020/07/18 08:37:44 visa Exp $ */ +/* $OpenBSD: machdep.c,v 1.128 2021/01/30 14:59:14 visa Exp $ */ /* * Copyright (c) 2009, 2010 Miodrag Vallat. @@ -102,6 +102,7 @@ vm_map_t phys_map; extern struct timecounter cp0_timecounter; extern uint8_t dt_blob_start[]; +enum octeon_board octeon_board; struct boot_desc *octeon_boot_desc; struct boot_info *octeon_boot_info; @@ -139,6 +140,7 @@ int octeon_cpuspeed(int *); void octeon_tlb_init(void); static void process_bootargs(void); static uint64_t get_ncpusfound(void); +static enum octeon_board get_octeon_board(void); cons_decl(octuart); struct consdev uartcons = cons_init(octuart); @@ -441,8 +443,8 @@ mips_init(register_t a0, register_t a1, register_t a2, register_t a3) bootcpu_hwinfo.clock / 1000000); cpu_cpuspeed = octeon_cpuspeed; - ncpusfound = get_ncpusfound(); + octeon_board = get_octeon_board(); process_bootargs(); @@ -822,6 +824,35 @@ get_ncpusfound(void) return ncpus; } +static enum octeon_board +get_octeon_board(void) +{ + switch (octeon_boot_info->board_type) { + case 11: + return BOARD_CN3010_EVB_HS5; + case 20002: + return BOARD_UBIQUITI_E100; + case 20003: + return BOARD_UBIQUITI_E200; + case 20004: + return BOARD_UBIQUITI_E120; + case 20005: + return BOARD_UBIQUITI_E220; + case 20010: + return BOARD_UBIQUITI_E1000; + case 20012: + return BOARD_RHINOLABS_UTM8; + case 20015: + return BOARD_DLINK_DSR_500; + case 20300: + return BOARD_UBIQUITI_E300; + default: + break; + } + + return BOARD_UNKNOWN; +} + static void process_bootargs(void) {