1use nix::errno::Errno;
5use thiserror::Error;
6
7#[derive(Error, Debug)]
8pub enum CfgFailType {
9 #[error("Nix error: {0}")]
10 Nix(#[from] nix::Error),
11
12 #[error("Size mismiatch: recieved {0} bytes")]
13 SizeMismatch(usize),
14}
15
16#[derive(Error, Debug)]
17pub enum PciOpenError {
18 #[error("Failed to open device /dev/tenstorrent/{id}: {source}")]
19 DeviceOpenFailed { id: usize, source: std::io::Error },
20
21 #[error("Failed to recognize id for device /dev/tenstorrent/{pci_id}: {device_id:x}")]
22 UnrecognizedDeviceId { pci_id: usize, device_id: u16 },
23
24 #[error("ioctl {name} failed for device {id} with: {source}")]
25 IoctlError {
26 name: String,
27 id: usize,
28 source: nix::Error,
29 },
30
31 #[error("Failed to map {name} from device {id}")]
32 BarMappingError { name: String, id: usize },
33
34 #[error("When creating anon buffer {buffer} for device {device_id} hit error {source}")]
35 FakeMmapFailed {
36 buffer: String,
37 device_id: usize,
38 source: std::io::Error,
39 },
40}
41
42#[derive(Error, Debug)]
43pub enum PciError {
44 #[error("DMA buffer mapping failed for device {id} with error {source}")]
45 DmaBufferMappingFailed { id: usize, source: std::io::Error },
46
47 #[error("DMA for device {id} is not configured")]
48 DmaNotConfigured { id: usize },
49
50 #[error("DMA buffer allocation on device {id} failed ({size} bytes) with error {err}")]
51 DmaAllocationFailed { id: usize, size: u32, err: Errno },
52
53 #[error("On device {id} tried to use 64-bit DMA, but ARC fw does not support it")]
54 No64bitDma { id: usize },
55
56 #[error("On device {id} tried to write {size} bytes, but DMA only allows a max of 28 bits")]
57 DmaTooLarge { id: usize, size: usize },
58
59 #[error("Read 0xffffffff from ARC scratch[6]: you should reset the board.")]
60 BrokenConnection,
61
62 #[error("Failed to read from device {id} config space[offset: {offset}, size: {size}]; Failed with {source}")]
63 CfgReadFailed {
64 id: usize,
65 offset: usize,
66 size: usize,
67
68 source: CfgFailType,
69 },
70
71 #[error("Failed to write into device {id} config space[offset: {offset}, size: {size}]; Failed with {source}")]
72 CfgWriteFailed {
73 id: usize,
74 offset: usize,
75 size: usize,
76
77 source: CfgFailType,
78 },
79
80 #[error("Tried to access tlb {id} which is out of range")]
81 TlbOutOfRange { id: usize },
82
83 #[error("Failed to reserve tlb for NOC IO; {0}")]
84 TlbAllocationError(String),
85
86 #[error("Ioctl failed with {0}")]
87 IoctlError(Errno),
88
89 #[error("During PciDevice initialization the PCI bar could not be mapped")]
90 BarUnmapped,
91
92 #[error("{0}")]
93 DeviceOpenError(#[from] PciOpenError),
94}