Abstract octeon board handling a little
authorvisa <visa@openbsd.org>
Sat, 30 Jan 2021 14:59:13 +0000 (14:59 +0000)
committervisa <visa@openbsd.org>
Sat, 30 Jan 2021 14:59:13 +0000 (14:59 +0000)
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.

sys/arch/octeon/dev/amdcf.c
sys/arch/octeon/dev/cn30xxgmx.c
sys/arch/octeon/dev/cn30xxsmi.c
sys/arch/octeon/dev/octrtc.c
sys/arch/octeon/include/octeonvar.h
sys/arch/octeon/octeon/machdep.c

index 9c60dc5..48314d5 100644 (file)
@@ -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;
index 7e4cf59..803cb9c 100644 (file)
@@ -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;
index c4b212a..9b47528 100644 (file)
@@ -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];
index 129f837..ecb2819 100644 (file)
@@ -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;
 }
index 8ad00dd..1fb0063 100644 (file)
@@ -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;
 
index 060f5ac..a92959b 100644 (file)
@@ -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)
 {