TT-System-Firmware APIs 19.15.99
Tenstorrent Firmware
Loading...
Searching...
No Matches
bh_chip.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2024 Tenstorrent AI ULC
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7#ifndef INCLUDE_TENSTORRENT_LIB_BH_CHIP_H_
8#define INCLUDE_TENSTORRENT_LIB_BH_CHIP_H_
9
10#include "bh_arc.h"
11
12#include <zephyr/kernel.h>
13#include <zephyr/device.h>
14#include <zephyr/drivers/gpio.h>
15
16#ifdef __cplusplus
17extern "C" {
18#endif
19
26
41
43 /* Flag set when bootrom has been loaded and the arc_soft_reset sequence can be applied. */
45
46 /*
47 * Flag set when we need to send or receive 1 time info to chip.
48 * Could be used for static data or config of peripherals.
49 */
51
52 unsigned int bus_cancel_flag;
53
54 /*
55 * notify the main thread to apply reset sequence
56 * also used during initial workaround application to invoke a reset as soon
57 * as the workaround has been applied
58 */
60 volatile bool performing_reset;
61
62 /* notify the main thread to handle therm trip */
63 volatile bool therm_trip_triggered;
65
66 /* notify the main thread to handle pgood events */
67 volatile bool pgood_fall_triggered;
68 volatile bool pgood_rise_triggered;
71
72 /* Max allowable time between pings from SMC in ms */
74
75 /* Keep track of telemetry heartbeat for autoreset */
77
78 /* Tracks program counter during last ARC hang */
80 /* Was ARC watchdog triggered? */
82
83 /* Requested fan speed in %. */
85 /* Is that a forced or automatic fan speed? */
87
88 /* Last seen CM2DM message sequence number, to know if the current message is a repeat. */
91
92 /* Cable power limit detected at boot, written to scratch register during resets. */
94
95 /*
96 * Per-chip DMC init timing
97 * perst_seen flags whether dm_init_done should be tracked.
98 * dm_init_done is in DMC clock cycles
99 * arc_start_time is ASIC refclk counter read over JTAG (see jtag_bootrom_soft_reset_arc).
100 */
104};
105
113
114#define DT_PHANDLE_OR_CHILD(node_id, name) \
115 COND_CODE_1(DT_NODE_HAS_PROP(node_id, name), (DT_PHANDLE(node_id, name)), \
116 (DT_CHILD(node_id, name)))
117
118#define HAS_DT_PHANDLE_OR_CHILD(node_id, name) DT_NODE_EXISTS(DT_PHANDLE_OR_CHILD(node_id, name))
119#define BH_CHIP_COUNT DT_PROP_LEN_OR(DT_PATH(chips), chips, 0)
120extern struct bh_chip BH_CHIPS[BH_CHIP_COUNT];
121
122#if BH_CHIP_COUNT > 0
123#define ARRAY_FOR_EACH_BH_CHIP(chip) ARRAY_FOR_EACH_PTR(BH_CHIPS, chip)
124#else
125#define ARRAY_FOR_EACH_BH_CHIP(chip) \
126 for (struct bh_chip * (chip) = NULL; (chip) != NULL; (chip) = NULL)
127#endif
128
129#define MAKE_STRUCT_FIELD(n) .n
130
131#define INIT_STRAP(n) MAKE_STRUCT_FIELD(DT_NODE_FULL_NAME_TOKEN(n)) = GPIO_DT_SPEC_GET(n, gpios),
132
133#define INIT_CHIP(n, prop, idx) \
134 { \
135 .config = { \
136 .asic_reset = GPIO_DT_SPEC_GET( \
137 DT_PHANDLE_OR_CHILD(DT_PHANDLE_BY_IDX(n, prop, idx), asic_reset), \
138 gpios), \
139 .spi_reset = GPIO_DT_SPEC_GET( \
140 DT_PHANDLE_OR_CHILD(DT_PHANDLE_BY_IDX(n, prop, idx), spi_reset), \
141 gpios), \
142 .flash = DEVICE_DT_GET_OR_NULL( \
143 DT_PHANDLE_OR_CHILD(DT_PHANDLE_BY_IDX(n, prop, idx), flash)), \
144 .jtag = DEVICE_DT_GET( \
145 DT_PHANDLE_OR_CHILD(DT_PHANDLE_BY_IDX(n, prop, idx), jtag)), \
146 .arc = BH_ARC_INIT( \
147 DT_PHANDLE_OR_CHILD(DT_PHANDLE_BY_IDX(n, prop, idx), arc)), \
148 .spi_mux = GPIO_DT_SPEC_GET( \
149 DT_PHANDLE_OR_CHILD(DT_PHANDLE_BY_IDX(n, prop, idx), spi_mux), \
150 gpios), \
151 .spi_mux1 = GPIO_DT_SPEC_GET_OR( \
152 DT_PHANDLE_OR_CHILD(DT_PHANDLE_BY_IDX(n, prop, idx), spi_mux1), \
153 gpios, {0}), \
154 .pgood = GPIO_DT_SPEC_GET( \
155 DT_PHANDLE_OR_CHILD(DT_PHANDLE_BY_IDX(n, prop, idx), pgood), \
156 gpios), \
157 .therm_trip = GPIO_DT_SPEC_GET( \
158 DT_PHANDLE_OR_CHILD(DT_PHANDLE_BY_IDX(n, prop, idx), therm_trip), \
159 gpios), \
160 .strapping = {COND_CODE_1( \
161 HAS_DT_PHANDLE_OR_CHILD(DT_PHANDLE_BY_IDX(n, prop, idx), strapping), \
162 (DT_FOREACH_CHILD(DT_PHANDLE_OR_CHILD(DT_PHANDLE_BY_IDX(n, prop, idx), strapping), \
163 INIT_STRAP)), \
164 ())}, \
165 }, \
166 .auto_reset_timer = Z_TIMER_INITIALIZER( \
167 BH_CHIPS[idx].auto_reset_timer, \
168 bh_chip_auto_reset, NULL), \
169 },
170
171#define BH_CHIP_PRIMARY_INDEX DT_PROP(DT_PATH(chips), primary)
172
173int jtag_bootrom_reset_sequence(struct bh_chip *chip, bool force_reset, uint16_t cable_power_limit);
174
177
179int bh_chip_set_static_info(struct bh_chip *chip, dmStaticInfo *info);
181int bh_chip_set_input_power_lim(struct bh_chip *chip, uint16_t max_power);
182int bh_chip_set_fan_rpm(struct bh_chip *chip, uint16_t rpm);
183int bh_chip_set_therm_trip_count(struct bh_chip *chip, uint16_t therm_trip_count);
184int bh_chip_write_logs(struct bh_chip *chip, char *log_data, size_t log_size);
185
186void bh_chip_auto_reset(struct k_timer *timer);
187
188void bh_chip_assert_asic_reset(const struct bh_chip *chip);
189void bh_chip_deassert_asic_reset(const struct bh_chip *chip);
190
191void bh_chip_set_straps(struct bh_chip *chip);
192void bh_chip_unset_straps(struct bh_chip *chip);
193
194void bh_chip_assert_spi_reset(const struct bh_chip *chip);
195void bh_chip_deassert_spi_reset(const struct bh_chip *chip);
196
197int bh_chip_reset_chip(struct bh_chip *chip, bool force_reset);
198
199int therm_trip_gpio_setup(struct bh_chip *chip);
200int pgood_gpio_setup(struct bh_chip *chip);
201
202void handle_pgood_event(struct bh_chip *chip, struct gpio_dt_spec board_fault_led);
203
204#ifdef __cplusplus
205}
206#endif
207
208#endif /* INCLUDE_TENSTORRENT_LIB_BH_CHIP_H_ */
#define BH_CHIP_COUNT
Definition bh_chip.h:119
int bh_chip_write_logs(struct bh_chip *chip, char *log_data, size_t log_size)
Definition bh_chip.c:138
int bh_chip_set_fan_rpm(struct bh_chip *chip, uint16_t rpm)
Definition bh_chip.c:109
int jtag_bootrom_reset_sequence(struct bh_chip *chip, bool force_reset, uint16_t cable_power_limit)
Definition reset.c:32
void bh_chip_assert_asic_reset(const struct bh_chip *chip)
Definition bh_chip.c:152
void bh_chip_unset_straps(struct bh_chip *chip)
Definition strapping.c:47
int bh_chip_set_input_power(struct bh_chip *chip, uint16_t power)
Definition bh_chip.c:91
int therm_trip_gpio_setup(struct bh_chip *chip)
Definition bh_chip.c:201
void bh_chip_cancel_bus_transfer_clear(struct bh_chip *chip)
Definition bh_chip.c:26
int bh_chip_set_input_power_lim(struct bh_chip *chip, uint16_t max_power)
Definition bh_chip.c:100
void bh_chip_auto_reset(struct k_timer *timer)
Definition bh_chip.c:128
void bh_chip_assert_spi_reset(const struct bh_chip *chip)
Definition bh_chip.c:162
int bh_chip_set_static_info(struct bh_chip *chip, dmStaticInfo *info)
Definition bh_chip.c:78
int bh_chip_set_therm_trip_count(struct bh_chip *chip, uint16_t therm_trip_count)
Definition bh_chip.c:118
int bh_chip_reset_chip(struct bh_chip *chip, bool force_reset)
Definition bh_chip.c:172
void bh_chip_set_straps(struct bh_chip *chip)
Definition strapping.c:12
void bh_chip_cancel_bus_transfer_set(struct bh_chip *chip)
Definition bh_chip.c:21
struct bh_chip BH_CHIPS[DT_PROP_LEN_OR(DT_PATH(chips), chips, 0)]
void handle_pgood_event(struct bh_chip *chip, struct gpio_dt_spec board_fault_led)
Definition bh_chip.c:264
cm2dmMessageRet bh_chip_get_cm2dm_message(struct bh_chip *chip)
Definition bh_chip.c:31
void bh_chip_deassert_asic_reset(const struct bh_chip *chip)
Definition bh_chip.c:157
void bh_chip_deassert_spi_reset(const struct bh_chip *chip)
Definition bh_chip.c:167
int pgood_gpio_setup(struct bh_chip *chip)
Definition bh_chip.c:240
static uint16_t power
Definition cm2dm_msg.c:44
long atomic_t
__UINT32_TYPE__ uint32_t
__UINT8_TYPE__ uint8_t
__UINT16_TYPE__ uint16_t
__INT64_TYPE__ int64_t
Definition bh_arc.h:70
Definition bh_chip.h:27
struct bh_arc arc
Definition bh_chip.h:39
struct gpio_dt_spec asic_reset
Definition bh_chip.h:28
const struct device * jtag
Definition bh_chip.h:35
const struct device * flash
Definition bh_chip.h:34
struct gpio_dt_spec spi_mux
Definition bh_chip.h:30
struct gpio_dt_spec spi_mux1
Definition bh_chip.h:31
struct gpio_dt_spec spi_reset
Definition bh_chip.h:29
const struct bh_straps strapping
Definition bh_chip.h:37
struct gpio_dt_spec therm_trip
Definition bh_chip.h:33
struct gpio_dt_spec pgood
Definition bh_chip.h:32
Definition bh_chip.h:42
uint32_t arc_hang_pc
Definition bh_chip.h:79
bool arc_wdog_triggered
Definition bh_chip.h:81
uint8_t fan_speed
Definition bh_chip.h:84
int64_t pgood_last_trip_ms
Definition bh_chip.h:70
bool pgood_severe_fault
Definition bh_chip.h:69
uint32_t dm_init_done
Definition bh_chip.h:102
uint8_t last_cm2dm_seq_num
Definition bh_chip.h:89
bool workaround_applied
Definition bh_chip.h:44
bool perst_seen
Definition bh_chip.h:101
bool last_cm2dm_seq_num_valid
Definition bh_chip.h:90
volatile bool therm_trip_triggered
Definition bh_chip.h:63
atomic_t trigger_reset
Definition bh_chip.h:59
uint16_t cable_power_limit
Definition bh_chip.h:93
uint16_t therm_trip_count
Definition bh_chip.h:64
uint32_t telemetry_heartbeat
Definition bh_chip.h:76
volatile bool pgood_fall_triggered
Definition bh_chip.h:67
volatile bool performing_reset
Definition bh_chip.h:60
uint32_t arc_start_time
Definition bh_chip.h:103
volatile bool pgood_rise_triggered
Definition bh_chip.h:68
bool arc_needs_init_msg
Definition bh_chip.h:50
unsigned int bus_cancel_flag
Definition bh_chip.h:52
uint32_t auto_reset_timeout
Definition bh_chip.h:73
bool fan_speed_forced
Definition bh_chip.h:86
Definition bh_chip.h:106
struct bh_chip_data data
Definition bh_chip.h:108
struct gpio_callback therm_trip_cb
Definition bh_chip.h:109
const struct bh_chip_config config
Definition bh_chip.h:107
struct k_timer auto_reset_timer
Definition bh_chip.h:111
struct gpio_callback pgood_cb
Definition bh_chip.h:110
Definition bh_chip.h:20
struct gpio_dt_spec gpio6
Definition bh_chip.h:21
struct gpio_dt_spec gpio38
Definition bh_chip.h:22
struct gpio_dt_spec gpio40
Definition bh_chip.h:24
struct gpio_dt_spec gpio39
Definition bh_chip.h:23
Definition bh_arc.h:76
Definition bh_arc.h:41