aboutsummaryrefslogtreecommitdiffstats
path: root/src/twa.h
blob: 413e70b8aaddf00237843ff99c398d9ae8f9a9ad (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
/*
 * twa.h:
 *
 * Copyright (c) 2017 James McKenzie <foss@madingley.org>,
 * All rights reserved.
 *
 */

#ifndef _TWA_H_
#define _TWA_H_

#define TWA_PACKED __attribute__ (( packed ))

typedef uint64_t dma_addr_t;


#define TW_SENSE_DATA_LENGTH                  18

#define TW_COMMAND_SIZE (sizeof(dma_addr_t) > 4 ? 5 : 4)
#define TW_APACHE_MAX_SGL_LENGTH (sizeof(dma_addr_t) > 4 ? 72 : 109)
#define TW_ESCALADE_MAX_SGL_LENGTH (sizeof(dma_addr_t) > 4 ? 41 : 62)
#define TW_PADDING_LENGTH (sizeof(dma_addr_t) > 4 ? 8 : 0)

typedef struct TWA_PACKED TAG_TW_SG_Entry
{
  dma_addr_t address;
  uint32_t length;
} TW_SG_Entry;


typedef struct TWA_PACKED TAG_TW_Command_Apache_Header
{
  unsigned char sense_data[TW_SENSE_DATA_LENGTH];
  struct TWA_PACKED
  {
    char reserved[4];
    unsigned short error;
    unsigned char padding;
    unsigned char severity__reserved;
  } status_block;
  unsigned char err_specific_desc[98];
  struct TWA_PACKED
  {
    unsigned char size_header;
    unsigned short reserved;
    unsigned char size_sense;
  } header_desc;
} TW_Command_Apache_Header;


/* Command Packet */
typedef struct TWA_PACKED TW_Command
{
  /* First DWORD */
  struct TWA_PACKED
  {
    unsigned char opcode:5;
    unsigned char sgl_offset:3;
  } byte0;
  unsigned char size;
  unsigned char request_id;
  struct TWA_PACKED
  {
    unsigned char unit:4;
    unsigned char host_id:4;
  } byte3;
  /* Second DWORD */
  unsigned char status;
  unsigned char flags;

  union
  {
    unsigned short block_count;
    unsigned short parameter_count;
    unsigned short message_credits;
  } byte6;
  union
  {
    struct TWA_PACKED
    {
      uint32_t lba;
      TW_SG_Entry sgl[TW_ESCALADE_MAX_SGL_LENGTH];
      dma_addr_t padding;
    } io;
    struct
    {
      TW_SG_Entry sgl[TW_ESCALADE_MAX_SGL_LENGTH];
      uint32_t padding;
      dma_addr_t padding2;
    } param;
  } byte8_offset;
} TW_Command;

typedef struct TWA_PACKED TAG_TW_Command_Apache
{
  unsigned char opcode__reserved;
  unsigned char unit;
  unsigned short request_id__lunl;
  unsigned char status;
  unsigned char sgl_offset;
  unsigned short sgl_entries__lunh;
  unsigned char cdb[16];
  TW_SG_Entry sg_list[TW_APACHE_MAX_SGL_LENGTH];
  unsigned char padding[TW_PADDING_LENGTH];
} TW_Command_Apache;


typedef struct TWA_PACKED TAG_TW_Command_Full
{
  TW_Command_Apache_Header header;
  union
  {
    TW_Command oldcommand;
    TW_Command_Apache newcommand;
  } command;
} TW_Command_Full;



typedef struct TWA_PACKED TAG_TW_Ioctl_Driver_Command
{
  unsigned int control_code;
  unsigned int status;
  unsigned int unique_id;
  unsigned int sequence_id;
  unsigned int os_specific;
  unsigned int buffer_length;
} TW_Ioctl_Driver_Command;



typedef struct TWA_PACKED TAG_TW_Ioctl_Apache
{
  TW_Ioctl_Driver_Command driver_command;
  char padding[488];
  TW_Command_Full firmware_command;
  char data_buffer[0];
} TW_Ioctl_Buf_Apache;

typedef struct TWA_PACKED
{
  unsigned short table_id;
  unsigned short parameter_id;
  unsigned short parameter_size_bytes;
  unsigned short actual_parameter_size_bytes;
  unsigned char data[0];
} TW_Param_Apache, *PTW_Param_Apache;

typedef struct
{
  uint8_t resv;
  uint8_t tw_sec;
  uint8_t tw_min;
  uint8_t tw_hour;
  uint8_t tw_day;
  uint8_t tw_month;
  uint16_t tw_year;
} TW_DateTime;

#define TW_IOCTL_FIRMWARE_PASS_THROUGH 0x108

#define TW_OP_GET_PARAM       0x12
#define TW_OP_SET_PARAM       0x13

#define TW_TIMEKEEP_TABLE                     0x040A
#define TW_TIMEKEEP_DATETIME			0x4


#endif /* _TWA_H_ */