smartmontools  SVN Rev 5304
Utility to control and monitor storage systems with "S.M.A.R.T."
dev_areca.h
Go to the documentation of this file.
1 /*
2  * dev_areca.h
3  *
4  * Home page of code is: https://www.smartmontools.org
5  *
6  * Copyright (C) 2012 Hank Wu <hank@areca.com.tw>
7  *
8  * SPDX-License-Identifier: GPL-2.0-or-later
9  */
10 
11 #ifndef DEV_ARECA_H
12 #define DEV_ARECA_H
13 
14 #define DEV_ARECA_H_CVSID "$Id: dev_areca.h 5198 2021-02-01 20:36:02Z chrfranke $"
15 
16 /////////////////////////////////////////////////////////////////////////////
17 /// Areca RAID support
18 
19 /* GENERIC ARECA IO CONTROL CODE*/
21 {
28 };
29 
30 #define ARECA_SIG_STR "ARCMSR"
31 
32 #if defined(_WIN32) || defined(__CYGWIN__)
33 #define ARCMSR_IOCTL_READ_RQBUFFER 0x90002004
34 #define ARCMSR_IOCTL_WRITE_WQBUFFER 0x90002008
35 #define ARCMSR_IOCTL_CLEAR_RQBUFFER 0x9000200C
36 #define ARCMSR_IOCTL_CLEAR_WQBUFFER 0x90002010
37 #define ARCMSR_IOCTL_RETURN_CODE_3F 0x90002018
38 #elif defined(__linux__)
39 /*DeviceType*/
40 #define ARECA_SATA_RAID 0x90000000
41 /*FunctionCode*/
42 #define FUNCTION_READ_RQBUFFER 0x0801
43 #define FUNCTION_WRITE_WQBUFFER 0x0802
44 #define FUNCTION_CLEAR_RQBUFFER 0x0803
45 #define FUNCTION_CLEAR_WQBUFFER 0x0804
46 #define FUNCTION_RETURN_CODE_3F 0x0806
47 
48 /* ARECA IO CONTROL CODE*/
49 #define ARCMSR_IOCTL_READ_RQBUFFER (ARECA_SATA_RAID | FUNCTION_READ_RQBUFFER)
50 #define ARCMSR_IOCTL_WRITE_WQBUFFER (ARECA_SATA_RAID | FUNCTION_WRITE_WQBUFFER)
51 #define ARCMSR_IOCTL_CLEAR_RQBUFFER (ARECA_SATA_RAID | FUNCTION_CLEAR_RQBUFFER)
52 #define ARCMSR_IOCTL_CLEAR_WQBUFFER (ARECA_SATA_RAID | FUNCTION_CLEAR_WQBUFFER)
53 #define ARCMSR_IOCTL_RETURN_CODE_3F (ARECA_SATA_RAID | FUNCTION_RETURN_CODE_3F)
54 #elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
55 #include <sys/ioctl.h> // _IOWR
56 
57 /*FunctionCode*/
58 #define FUNCTION_READ_RQBUFFER 0x0801
59 #define FUNCTION_WRITE_WQBUFFER 0x0802
60 #define FUNCTION_CLEAR_RQBUFFER 0x0803
61 #define FUNCTION_CLEAR_WQBUFFER 0x0804
62 #define FUNCTION_RETURN_CODE_3F 0x0806
63 
64 /* ARECA IO CONTROL CODE*/
65 #define ARCMSR_IOCTL_READ_RQBUFFER _IOWR('F', FUNCTION_READ_RQBUFFER, sSRB_BUFFER)
66 #define ARCMSR_IOCTL_WRITE_WQBUFFER _IOWR('F', FUNCTION_WRITE_WQBUFFER, sSRB_BUFFER)
67 #define ARCMSR_IOCTL_CLEAR_RQBUFFER _IOWR('F', FUNCTION_CLEAR_RQBUFFER, sSRB_BUFFER)
68 #define ARCMSR_IOCTL_CLEAR_WQBUFFER _IOWR('F', FUNCTION_CLEAR_WQBUFFER, sSRB_BUFFER)
69 #define ARCMSR_IOCTL_RETURN_CODE_3F _IOWR('F', FUNCTION_RETURN_CODE_3F, sSRB_BUFFER)
70 #endif
71 
72 
73 // The SRB_IO_CONTROL & SRB_BUFFER structures are used to communicate(to/from) to areca driver
74 typedef struct _ARCMSR_IO_HDR
75 {
76  unsigned int HeaderLength;
77  unsigned char Signature[8];
78  unsigned int Timeout;
79  unsigned int ControlCode;
80  unsigned int ReturnCode;
81  unsigned int Length;
83 
84 typedef struct _SRB_BUFFER
85 {
87  unsigned char ioctldatabuffer[1032]; // the buffer to put the command data to/from firmware
89 
91 virtual public smart_device
92 {
93 public:
94  generic_areca_device(smart_interface * intf, const char * dev_name, int disknum, int encnum = 1);
96 
97  /////////////////////////////////////////////////////////////////////
98  // OS-dependent functions
99  virtual bool arcmsr_lock() = 0;
100  virtual bool arcmsr_unlock() = 0;
101  virtual int arcmsr_do_scsi_io(struct scsi_cmnd_io * iop) = 0;
102 
103  /////////////////////////////////////////////////////////////////////
104  // OS-independent functions
105  virtual int arcmsr_command_handler(unsigned long arcmsr_cmd, unsigned char *data, int data_len);
106  virtual int arcmsr_ui_handler(unsigned char *areca_packet, int areca_packet_len, unsigned char *result);
107  virtual bool arcmsr_probe();
108  virtual int arcmsr_get_dev_type();
109  virtual int arcmsr_get_controller_type();
110  virtual bool arcmsr_scsi_pass_through(scsi_cmnd_io * iop);
111  virtual bool arcmsr_ata_pass_through(const ata_cmd_in & in, ata_cmd_out & out);
112 
113 protected:
116  m_disknum(-1), m_encnum(-1)
117  { }
118 
119  void set_disknum(int disknum)
120  {m_disknum = disknum;}
121 
122  void set_encnum(int encnum)
123  {m_encnum = encnum;}
124 
126  {return m_disknum;}
127 
129  {return m_encnum;}
130 
131 private:
132  int m_disknum; ///< Disk number.
133  int m_encnum; ///< Enclosure number.
134  };
135 
136 // SATA(ATA) device behind Areca RAID Controller
138 : public ata_device,
139  public generic_areca_device
140 {
141 public:
142  areca_ata_device(smart_interface * intf, const char * dev_name, int disknum, int encnum = 1);
144  bool arcmsr_lock() override { return true; }
145  bool arcmsr_unlock() override { return true; }
146  int arcmsr_do_scsi_io(struct scsi_cmnd_io * /* iop */) override
147  {
148  return -1;
149  }
150 protected:
152  {
153  }
154  virtual bool ata_pass_through(const ata_cmd_in & in, ata_cmd_out & out) override;
155 };
156 
157 // SAS(SCSI) device behind Areca RAID Controller
159 : public scsi_device,
160  public generic_areca_device
161 {
162 public:
163  areca_scsi_device(smart_interface * intf, const char * dev_name, int disknum, int encnum = 1);
165  bool arcmsr_lock() override { return true; }
166  bool arcmsr_unlock() override { return true; }
167  int arcmsr_do_scsi_io(struct scsi_cmnd_io * /* iop */) override
168  {
169  return -1;
170  }
171 protected:
173  {
174  }
175  virtual bool scsi_pass_through(scsi_cmnd_io * iop) override;
176 };
177 
178 #endif
bool arcmsr_unlock() override
Definition: dev_areca.h:145
bool arcmsr_lock() override
Definition: dev_areca.h:144
virtual bool ata_pass_through(const ata_cmd_in &in, ata_cmd_out &out) override
ATA pass through.
Definition: dev_areca.cpp:661
int arcmsr_do_scsi_io(struct scsi_cmnd_io *) override
Definition: dev_areca.h:146
bool arcmsr_lock() override
Definition: dev_areca.h:165
int arcmsr_do_scsi_io(struct scsi_cmnd_io *) override
Definition: dev_areca.h:167
bool arcmsr_unlock() override
Definition: dev_areca.h:166
virtual bool scsi_pass_through(scsi_cmnd_io *iop) override
SCSI pass through.
Definition: dev_areca.cpp:689
ATA device access.
int m_encnum
Enclosure number.
Definition: dev_areca.h:133
virtual int arcmsr_get_dev_type()
Definition: dev_areca.cpp:343
virtual int arcmsr_do_scsi_io(struct scsi_cmnd_io *iop)=0
virtual int arcmsr_get_controller_type()
Definition: dev_areca.cpp:327
void set_disknum(int disknum)
Definition: dev_areca.h:119
virtual bool arcmsr_lock()=0
virtual bool arcmsr_unlock()=0
void set_encnum(int encnum)
Definition: dev_areca.h:122
virtual bool arcmsr_probe()
Definition: dev_areca.cpp:257
int m_disknum
Disk number.
Definition: dev_areca.h:132
virtual bool arcmsr_ata_pass_through(const ata_cmd_in &in, ata_cmd_out &out)
Definition: dev_areca.cpp:378
virtual int arcmsr_ui_handler(unsigned char *areca_packet, int areca_packet_len, unsigned char *result)
Definition: dev_areca.cpp:271
virtual int arcmsr_command_handler(unsigned long arcmsr_cmd, unsigned char *data, int data_len)
Definition: dev_areca.cpp:107
virtual bool arcmsr_scsi_pass_through(scsi_cmnd_io *iop)
Definition: dev_areca.cpp:530
SCSI device access.
Base class for all devices.
Definition: dev_interface.h:33
The platform interface abstraction.
struct _ARCMSR_IO_HDR sARCMSR_IO_HDR
_GENERIC_ARCMSR_CMDS
Areca RAID support.
Definition: dev_areca.h:21
@ ARCMSR_WRITE_WQBUFFER
Definition: dev_areca.h:23
@ ARCMSR_READ_RQBUFFER
Definition: dev_areca.h:22
@ ARCMSR_RETURN_CODE_3F
Definition: dev_areca.h:26
@ ARCMSR_CLEAR_WQBUFFER
Definition: dev_areca.h:25
@ ARCMSR_CLEAR_RQBUFFER
Definition: dev_areca.h:24
@ ARCMSR_CMD_TOTAL
Definition: dev_areca.h:27
struct _SRB_BUFFER sSRB_BUFFER
ptr_t data
Definition: megaraid.h:15
unsigned int ReturnCode
Definition: dev_areca.h:80
unsigned int Length
Definition: dev_areca.h:81
unsigned int ControlCode
Definition: dev_areca.h:79
unsigned int HeaderLength
Definition: dev_areca.h:76
unsigned int Timeout
Definition: dev_areca.h:78
unsigned char Signature[8]
Definition: dev_areca.h:77
sARCMSR_IO_HDR srbioctl
Definition: dev_areca.h:86
unsigned char ioctldatabuffer[1032]
Definition: dev_areca.h:87
ATA pass through input parameters.
ATA pass through output parameters.