1 /*        $NetBSD: if_gscanreg.h,v 1.1 2025/04/03 16:33:48 bouyer Exp $         */
2 
3 /*
4  * Copyright (c) 2025 The NetBSD Foundation, Inc.
5  * All rights reserved.
6  *
7  * This code is derived from software contributed to The NetBSD Foundation
8  * by Manuel Bouyer.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 /* control messages */
33 #define GSCAN_SET_HOST_FORMAT           0 /* out */
34 
35 struct gscan_set_hf {
36           uint32_t hf_byte_order; /* set to 0x0000beef */
37 } __packed;
38 
39 #define GSCAN_SET_BITTIMING             1 /* out */
40 
41 struct gscan_bt {
42           uint32_t bt_prop_seg;
43           uint32_t bt_phase_seg1;
44           uint32_t bt_phase_seg2;
45           uint32_t bt_swj;
46           uint32_t bt_brp;
47 } __packed;
48 
49 #define GSCAN_SET_MODE                            2 /* out */
50 
51 struct gscan_set_mode {
52           uint32_t mode_mode;
53 #define MODE_RESET 0
54 #define MODE_START 1
55           uint32_t mode_flags;
56 #define FLAGS_LISTEN_ONLY     0x01
57 #define FLAGS_LOOPBACK                  0x02
58 #define FLAGS_TRIPLE_SAMPLE   0x04
59 #define FLAGS_ONE_SHOT                  0x08
60 } __packed;
61 
62 #define GSCAN_BERR                      3 /* ??? */
63 #define GSCAN_GET_BT_CONST              4 /* in  */
64 
65 struct gscan_bt_const {
66           uint32_t btc_features;
67 #define FEAT_LISTEN_ONLY      0x01
68 #define FEAT_LOOPBACK                   0x02
69 #define FEAT_TRIPLE_SAMPLE    0x04
70 #define FEAT_ONE_SHOT                   0x08
71 #define FEAT_HW_TS            0x10
72 #define FEAT_IDENTIFY                   0x20
73           uint32_t btc_fclk;
74           uint32_t btc_tseg1_min;
75           uint32_t btc_tseg1_max;
76           uint32_t btc_tseg2_min;
77           uint32_t btc_tseg2_max;
78           uint32_t btc_swj_max;
79           uint32_t btc_brp_min;
80           uint32_t btc_brp_max;
81           uint32_t btc_brp_inc;
82 } __packed;
83 
84 #define GSCAN_GET_DEVICE_CONFIG                   5 /* in  */
85 
86 struct gscan_config {
87           uint8_t _pad[3];
88           uint8_t conf_count;
89           uint32_t sw_version;
90           uint32_t hw_version;
91 } __packed;
92 
93 #define GSCAN_TIMESTAMP                           6 /* ??? */
94 #define GSCAN_SET_IDENTIFY              7 /* out */
95 
96 struct gscan_ident {
97           uint32_t ident_state; /* 0 = LED off, 1 = LED on */
98 } __packed;
99 
100 /*
101  * CAN frame on in and out endpoints */
102 struct gscan_frame {
103           uint32_t gsframe_echo_id;
104           uint32_t gsframe_can_id;
105           uint8_t  gsframe_can_dlc;
106           uint8_t  gsframe_channel;
107           uint8_t  gsframe_flags;
108           uint8_t  _res;
109           uint8_t  gsframe_can_data[8];
110 } __packed;
111 
112 #define GSFRAME_FLAG_OVER 0x01
113