smartmontools SVN Rev 3317
Utility to control and monitor storage systems with "S.M.A.R.T."
dev_areca.h
Go to the documentation of this file.
00001 /*
00002  * dev_areca.h
00003  *
00004  * Home page of code is: http://smartmontools.sourceforge.net
00005  *
00006  * Copyright (C) 2012 Hank Wu <hank@areca.com.tw>
00007  *
00008  * This program is free software; you can redistribute it and/or modify
00009  * it under the terms of the GNU General Public License as published by
00010  * the Free Software Foundation; either version 2, or (at your option)
00011  * any later version.
00012  *
00013  * You should have received a copy of the GNU General Public License
00014  * (for example COPYING); If not, see <http://www.gnu.org/licenses/>.
00015  *
00016  */
00017 
00018 #ifndef DEV_ARECA_H
00019 #define DEV_ARECA_H
00020 
00021 #define DEV_ARECA_H_CVSID "$Id: dev_areca.h 3854 2013-09-12 05:36:20Z chrfranke $"
00022 
00023 /////////////////////////////////////////////////////////////////////////////
00024 /// Areca RAID support
00025 
00026 /* GENERIC ARECA IO CONTROL CODE*/
00027 enum _GENERIC_ARCMSR_CMDS
00028 {
00029 ARCMSR_READ_RQBUFFER = 0,
00030 ARCMSR_WRITE_WQBUFFER,
00031 ARCMSR_CLEAR_RQBUFFER,
00032 ARCMSR_CLEAR_WQBUFFER,
00033 ARCMSR_RETURN_CODE_3F,
00034 ARCMSR_CMD_TOTAL
00035 };
00036 
00037 #define ARECA_SIG_STR  "ARCMSR"
00038 
00039 #if defined(_WIN32) || defined(__CYGWIN__)
00040 #define ARCMSR_IOCTL_READ_RQBUFFER           0x90002004
00041 #define ARCMSR_IOCTL_WRITE_WQBUFFER          0x90002008
00042 #define ARCMSR_IOCTL_CLEAR_RQBUFFER          0x9000200C
00043 #define ARCMSR_IOCTL_CLEAR_WQBUFFER          0x90002010
00044 #define ARCMSR_IOCTL_RETURN_CODE_3F          0x90002018
00045 #elif defined(__linux__)
00046 /*DeviceType*/
00047 #define ARECA_SATA_RAID                      0x90000000
00048 /*FunctionCode*/
00049 #define FUNCTION_READ_RQBUFFER               0x0801
00050 #define FUNCTION_WRITE_WQBUFFER              0x0802
00051 #define FUNCTION_CLEAR_RQBUFFER              0x0803
00052 #define FUNCTION_CLEAR_WQBUFFER              0x0804
00053 #define FUNCTION_RETURN_CODE_3F              0x0806
00054 
00055 /* ARECA IO CONTROL CODE*/
00056 #define ARCMSR_IOCTL_READ_RQBUFFER           (ARECA_SATA_RAID | FUNCTION_READ_RQBUFFER)
00057 #define ARCMSR_IOCTL_WRITE_WQBUFFER          (ARECA_SATA_RAID | FUNCTION_WRITE_WQBUFFER)
00058 #define ARCMSR_IOCTL_CLEAR_RQBUFFER          (ARECA_SATA_RAID | FUNCTION_CLEAR_RQBUFFER)
00059 #define ARCMSR_IOCTL_CLEAR_WQBUFFER          (ARECA_SATA_RAID | FUNCTION_CLEAR_WQBUFFER)
00060 #define ARCMSR_IOCTL_RETURN_CODE_3F          (ARECA_SATA_RAID | FUNCTION_RETURN_CODE_3F)
00061 #elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
00062 #include <sys/ioctl.h> // _IOWR
00063 
00064 /*FunctionCode*/
00065 #define FUNCTION_READ_RQBUFFER               0x0801
00066 #define FUNCTION_WRITE_WQBUFFER              0x0802
00067 #define FUNCTION_CLEAR_RQBUFFER              0x0803
00068 #define FUNCTION_CLEAR_WQBUFFER              0x0804
00069 #define FUNCTION_RETURN_CODE_3F              0x0806
00070 
00071 /* ARECA IO CONTROL CODE*/
00072 #define ARCMSR_IOCTL_READ_RQBUFFER           _IOWR('F', FUNCTION_READ_RQBUFFER, sSRB_BUFFER)
00073 #define ARCMSR_IOCTL_WRITE_WQBUFFER          _IOWR('F', FUNCTION_WRITE_WQBUFFER, sSRB_BUFFER)
00074 #define ARCMSR_IOCTL_CLEAR_RQBUFFER          _IOWR('F', FUNCTION_CLEAR_RQBUFFER, sSRB_BUFFER)
00075 #define ARCMSR_IOCTL_CLEAR_WQBUFFER          _IOWR('F', FUNCTION_CLEAR_WQBUFFER, sSRB_BUFFER)
00076 #define ARCMSR_IOCTL_RETURN_CODE_3F          _IOWR('F', FUNCTION_RETURN_CODE_3F, sSRB_BUFFER)
00077 #endif
00078 
00079 
00080 // The SRB_IO_CONTROL & SRB_BUFFER structures are used to communicate(to/from) to areca driver
00081 typedef struct _ARCMSR_IO_HDR
00082 {
00083   unsigned int HeaderLength;
00084   unsigned char Signature[8];
00085   unsigned int Timeout;
00086   unsigned int ControlCode;
00087   unsigned int ReturnCode;
00088   unsigned int Length;
00089 } sARCMSR_IO_HDR;
00090 
00091 typedef struct _SRB_BUFFER
00092 {
00093   sARCMSR_IO_HDR  srbioctl;
00094   unsigned char   ioctldatabuffer[1032]; // the buffer to put the command data to/from firmware
00095 } sSRB_BUFFER;
00096 
00097 class generic_areca_device :
00098 virtual public smart_device
00099 {
00100 public:
00101   generic_areca_device(smart_interface * intf, const char * dev_name, int disknum, int encnum = 1);
00102   ~generic_areca_device() throw();
00103 
00104   /////////////////////////////////////////////////////////////////////
00105   // OS-dependent functions
00106   virtual bool arcmsr_lock() = 0;
00107   virtual bool arcmsr_unlock() = 0;
00108   virtual int arcmsr_do_scsi_io(struct scsi_cmnd_io * iop) = 0;
00109 
00110   /////////////////////////////////////////////////////////////////////
00111   // OS-independent functions
00112   virtual int arcmsr_command_handler(unsigned long arcmsr_cmd, unsigned char *data, int data_len);
00113   virtual int arcmsr_ui_handler(unsigned char *areca_packet, int areca_packet_len, unsigned char *result);
00114   virtual bool arcmsr_probe();
00115   virtual int arcmsr_get_dev_type();
00116   virtual int arcmsr_get_controller_type();
00117   virtual bool arcmsr_scsi_pass_through(scsi_cmnd_io * iop);
00118   virtual bool arcmsr_ata_pass_through(const ata_cmd_in & in, ata_cmd_out & out);
00119 
00120 protected:
00121   generic_areca_device() : smart_device(never_called)
00122   {
00123   }
00124 
00125   void set_disknum(int disknum)
00126   {m_disknum = disknum;}
00127 
00128   void set_encnum(int encnum)
00129   {m_encnum = encnum;}
00130 
00131   int get_disknum()
00132   {return m_disknum;}
00133 
00134   int get_encnum()
00135   {return m_encnum;}
00136 
00137 private:
00138   int m_disknum; ///< Disk number.
00139   int m_encnum;  ///< Enclosure number.
00140  };
00141 
00142 // SATA(ATA) device behind Areca RAID Controller
00143 class areca_ata_device
00144 : public ata_device,
00145   public generic_areca_device
00146 {
00147 public:
00148   areca_ata_device(smart_interface * intf, const char * dev_name, int disknum, int encnum = 1);
00149   ~areca_ata_device() throw();
00150   bool arcmsr_lock() { return true; }
00151   bool arcmsr_unlock() { return true; }
00152   int arcmsr_do_scsi_io(struct scsi_cmnd_io * /* iop */)
00153   {
00154       return -1;
00155   }
00156 protected:
00157   areca_ata_device(): smart_device(never_called)
00158   {
00159   }
00160   virtual bool ata_pass_through(const ata_cmd_in & in, ata_cmd_out & out);
00161 };
00162 
00163 // SAS(SCSI) device behind Areca RAID Controller
00164 class areca_scsi_device
00165 : public scsi_device,
00166   public generic_areca_device
00167 {
00168 public:
00169   areca_scsi_device(smart_interface * intf, const char * dev_name, int disknum, int encnum = 1);
00170   ~areca_scsi_device() throw();
00171   bool arcmsr_lock() { return true; }
00172   bool arcmsr_unlock() { return true; }
00173   int arcmsr_do_scsi_io(struct scsi_cmnd_io * /* iop */)
00174   {
00175       return -1;
00176   }
00177 protected:
00178   areca_scsi_device(): smart_device(never_called)
00179   {
00180   }
00181   virtual bool scsi_pass_through(scsi_cmnd_io * iop);
00182 };
00183 
00184 #endif