dpti.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  1. /***************************************************************************
  2. dpti.h - description
  3. -------------------
  4. begin : Thu Sep 7 2000
  5. copyright : (C) 2001 by Adaptec
  6. See Documentation/scsi/dpti.txt for history, notes, license info
  7. and credits
  8. ***************************************************************************/
  9. /***************************************************************************
  10. * *
  11. * This program is free software; you can redistribute it and/or modify *
  12. * it under the terms of the GNU General Public License as published by *
  13. * the Free Software Foundation; either version 2 of the License, or *
  14. * (at your option) any later version. *
  15. * *
  16. ***************************************************************************/
  17. #ifndef _DPT_H
  18. #define _DPT_H
  19. #ifndef LINUX_VERSION_CODE
  20. #include <linux/version.h>
  21. #endif
  22. #if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,00)
  23. #define MAX_TO_IOP_MESSAGES (210)
  24. #else
  25. #define MAX_TO_IOP_MESSAGES (255)
  26. #endif
  27. #define MAX_FROM_IOP_MESSAGES (255)
  28. /*
  29. * SCSI interface function Prototypes
  30. */
  31. static int adpt_detect(struct scsi_host_template * sht);
  32. static int adpt_queue(struct scsi_cmnd * cmd, void (*cmdcomplete) (struct scsi_cmnd *));
  33. static int adpt_abort(struct scsi_cmnd * cmd);
  34. static int adpt_reset(struct scsi_cmnd* cmd);
  35. static int adpt_release(struct Scsi_Host *host);
  36. static int adpt_slave_configure(struct scsi_device *);
  37. static const char *adpt_info(struct Scsi_Host *pSHost);
  38. static int adpt_bios_param(struct scsi_device * sdev, struct block_device *dev,
  39. sector_t, int geom[]);
  40. static int adpt_bus_reset(struct scsi_cmnd* cmd);
  41. static int adpt_device_reset(struct scsi_cmnd* cmd);
  42. /*
  43. * Scsi_Host_Template (see hosts.h)
  44. */
  45. #define DPT_DRIVER_NAME "Adaptec I2O RAID"
  46. #ifndef HOSTS_C
  47. #include "dpt/sys_info.h"
  48. #include <linux/wait.h>
  49. #include "dpt/dpti_i2o.h"
  50. #include "dpt/dpti_ioctl.h"
  51. #define DPT_I2O_VERSION "2.4 Build 5go"
  52. #define DPT_VERSION 2
  53. #define DPT_REVISION '4'
  54. #define DPT_SUBREVISION '5'
  55. #define DPT_BETA ""
  56. #define DPT_MONTH 8
  57. #define DPT_DAY 7
  58. #define DPT_YEAR (2001-1980)
  59. #define DPT_DRIVER "dpt_i2o"
  60. #define DPTI_I2O_MAJOR (151)
  61. #define DPT_ORGANIZATION_ID (0x1B) /* For Private Messages */
  62. #define DPTI_MAX_HBA (16)
  63. #define MAX_CHANNEL (5) // Maximum Channel # Supported
  64. #define MAX_ID (128) // Maximum Target ID Supported
  65. /* Sizes in 4 byte words */
  66. #define REPLY_FRAME_SIZE (17)
  67. #define MAX_MESSAGE_SIZE (128)
  68. #define SG_LIST_ELEMENTS (56)
  69. #define EMPTY_QUEUE 0xffffffff
  70. #define I2O_INTERRUPT_PENDING_B (0x08)
  71. #define PCI_DPT_VENDOR_ID (0x1044) // DPT PCI Vendor ID
  72. #define PCI_DPT_DEVICE_ID (0xA501) // DPT PCI I2O Device ID
  73. #define PCI_DPT_RAPTOR_DEVICE_ID (0xA511)
  74. //#define REBOOT_NOTIFIER 1
  75. /* Debugging macro from Linux Device Drivers - Rubini */
  76. #undef PDEBUG
  77. #ifdef DEBUG
  78. //TODO add debug level switch
  79. # define PDEBUG(fmt, args...) printk(KERN_DEBUG "dpti: " fmt, ##args)
  80. # define PDEBUGV(fmt, args...) printk(KERN_DEBUG "dpti: " fmt, ##args)
  81. #else
  82. # define PDEBUG(fmt, args...) /* not debugging: nothing */
  83. # define PDEBUGV(fmt, args...) /* not debugging: nothing */
  84. #endif
  85. #define PERROR(fmt, args...) printk(KERN_ERR fmt, ##args)
  86. #define PWARN(fmt, args...) printk(KERN_WARNING fmt, ##args)
  87. #define PINFO(fmt, args...) printk(KERN_INFO fmt, ##args)
  88. #define PCRIT(fmt, args...) printk(KERN_CRIT fmt, ##args)
  89. #define SHUTDOWN_SIGS (sigmask(SIGKILL)|sigmask(SIGINT)|sigmask(SIGTERM))
  90. // Command timeouts
  91. #define FOREVER (0)
  92. #define TMOUT_INQUIRY (20)
  93. #define TMOUT_FLUSH (360/45)
  94. #define TMOUT_ABORT (30)
  95. #define TMOUT_SCSI (300)
  96. #define TMOUT_IOPRESET (360)
  97. #define TMOUT_GETSTATUS (15)
  98. #define TMOUT_INITOUTBOUND (15)
  99. #define TMOUT_LCT (360)
  100. #define I2O_SCSI_DEVICE_DSC_MASK 0x00FF
  101. #define I2O_DETAIL_STATUS_UNSUPPORTED_FUNCTION 0x000A
  102. #define I2O_SCSI_DSC_MASK 0xFF00
  103. #define I2O_SCSI_DSC_SUCCESS 0x0000
  104. #define I2O_SCSI_DSC_REQUEST_ABORTED 0x0200
  105. #define I2O_SCSI_DSC_UNABLE_TO_ABORT 0x0300
  106. #define I2O_SCSI_DSC_COMPLETE_WITH_ERROR 0x0400
  107. #define I2O_SCSI_DSC_ADAPTER_BUSY 0x0500
  108. #define I2O_SCSI_DSC_REQUEST_INVALID 0x0600
  109. #define I2O_SCSI_DSC_PATH_INVALID 0x0700
  110. #define I2O_SCSI_DSC_DEVICE_NOT_PRESENT 0x0800
  111. #define I2O_SCSI_DSC_UNABLE_TO_TERMINATE 0x0900
  112. #define I2O_SCSI_DSC_SELECTION_TIMEOUT 0x0A00
  113. #define I2O_SCSI_DSC_COMMAND_TIMEOUT 0x0B00
  114. #define I2O_SCSI_DSC_MR_MESSAGE_RECEIVED 0x0D00
  115. #define I2O_SCSI_DSC_SCSI_BUS_RESET 0x0E00
  116. #define I2O_SCSI_DSC_PARITY_ERROR_FAILURE 0x0F00
  117. #define I2O_SCSI_DSC_AUTOSENSE_FAILED 0x1000
  118. #define I2O_SCSI_DSC_NO_ADAPTER 0x1100
  119. #define I2O_SCSI_DSC_DATA_OVERRUN 0x1200
  120. #define I2O_SCSI_DSC_UNEXPECTED_BUS_FREE 0x1300
  121. #define I2O_SCSI_DSC_SEQUENCE_FAILURE 0x1400
  122. #define I2O_SCSI_DSC_REQUEST_LENGTH_ERROR 0x1500
  123. #define I2O_SCSI_DSC_PROVIDE_FAILURE 0x1600
  124. #define I2O_SCSI_DSC_BDR_MESSAGE_SENT 0x1700
  125. #define I2O_SCSI_DSC_REQUEST_TERMINATED 0x1800
  126. #define I2O_SCSI_DSC_IDE_MESSAGE_SENT 0x3300
  127. #define I2O_SCSI_DSC_RESOURCE_UNAVAILABLE 0x3400
  128. #define I2O_SCSI_DSC_UNACKNOWLEDGED_EVENT 0x3500
  129. #define I2O_SCSI_DSC_MESSAGE_RECEIVED 0x3600
  130. #define I2O_SCSI_DSC_INVALID_CDB 0x3700
  131. #define I2O_SCSI_DSC_LUN_INVALID 0x3800
  132. #define I2O_SCSI_DSC_SCSI_TID_INVALID 0x3900
  133. #define I2O_SCSI_DSC_FUNCTION_UNAVAILABLE 0x3A00
  134. #define I2O_SCSI_DSC_NO_NEXUS 0x3B00
  135. #define I2O_SCSI_DSC_SCSI_IID_INVALID 0x3C00
  136. #define I2O_SCSI_DSC_CDB_RECEIVED 0x3D00
  137. #define I2O_SCSI_DSC_LUN_ALREADY_ENABLED 0x3E00
  138. #define I2O_SCSI_DSC_BUS_BUSY 0x3F00
  139. #define I2O_SCSI_DSC_QUEUE_FROZEN 0x4000
  140. #ifndef TRUE
  141. #define TRUE 1
  142. #define FALSE 0
  143. #endif
  144. #define HBA_FLAGS_INSTALLED_B 0x00000001 // Adapter Was Installed
  145. #define HBA_FLAGS_BLINKLED_B 0x00000002 // Adapter In Blink LED State
  146. #define HBA_FLAGS_IN_RESET 0x00000040 /* in reset */
  147. #define HBA_HOSTRESET_FAILED 0x00000080 /* adpt_resethost failed */
  148. // Device state flags
  149. #define DPTI_DEV_ONLINE 0x00
  150. #define DPTI_DEV_UNSCANNED 0x01
  151. #define DPTI_DEV_RESET 0x02
  152. #define DPTI_DEV_OFFLINE 0x04
  153. struct adpt_device {
  154. struct adpt_device* next_lun;
  155. u32 flags;
  156. u32 type;
  157. u32 capacity;
  158. u32 block_size;
  159. u8 scsi_channel;
  160. u8 scsi_id;
  161. u8 scsi_lun;
  162. u8 state;
  163. u16 tid;
  164. struct i2o_device* pI2o_dev;
  165. struct scsi_device *pScsi_dev;
  166. };
  167. struct adpt_channel {
  168. struct adpt_device* device[MAX_ID]; /* used as an array of 128 scsi ids */
  169. u8 scsi_id;
  170. u8 type;
  171. u16 tid;
  172. u32 state;
  173. struct i2o_device* pI2o_dev;
  174. };
  175. // HBA state flags
  176. #define DPTI_STATE_RESET (0x01)
  177. #define DPTI_STATE_IOCTL (0x02)
  178. typedef struct _adpt_hba {
  179. struct _adpt_hba *next;
  180. struct pci_dev *pDev;
  181. struct Scsi_Host *host;
  182. u32 state;
  183. spinlock_t state_lock;
  184. int unit;
  185. int host_no; /* SCSI host number */
  186. u8 initialized;
  187. u8 in_use; /* is the management node open*/
  188. char name[32];
  189. char detail[55];
  190. void __iomem *base_addr_virt;
  191. void __iomem *msg_addr_virt;
  192. ulong base_addr_phys;
  193. void __iomem *post_port;
  194. void __iomem *reply_port;
  195. void __iomem *irq_mask;
  196. u16 post_count;
  197. u32 post_fifo_size;
  198. u32 reply_fifo_size;
  199. u32* reply_pool;
  200. u32 sg_tablesize; // Scatter/Gather List Size.
  201. u8 top_scsi_channel;
  202. u8 top_scsi_id;
  203. u8 top_scsi_lun;
  204. i2o_status_block* status_block;
  205. i2o_hrt* hrt;
  206. i2o_lct* lct;
  207. uint lct_size;
  208. struct i2o_device* devices;
  209. struct adpt_channel channel[MAX_CHANNEL];
  210. struct proc_dir_entry* proc_entry; /* /proc dir */
  211. void __iomem *FwDebugBuffer_P; // Virtual Address Of FW Debug Buffer
  212. u32 FwDebugBufferSize; // FW Debug Buffer Size In Bytes
  213. void __iomem *FwDebugStrLength_P;// Virtual Addr Of FW Debug String Len
  214. void __iomem *FwDebugFlags_P; // Virtual Address Of FW Debug Flags
  215. void __iomem *FwDebugBLEDflag_P;// Virtual Addr Of FW Debug BLED
  216. void __iomem *FwDebugBLEDvalue_P;// Virtual Addr Of FW Debug BLED
  217. u32 FwDebugFlags;
  218. } adpt_hba;
  219. struct sg_simple_element {
  220. u32 flag_count;
  221. u32 addr_bus;
  222. };
  223. /*
  224. * Function Prototypes
  225. */
  226. static void adpt_i2o_sys_shutdown(void);
  227. static int adpt_init(void);
  228. static int adpt_i2o_build_sys_table(void);
  229. static irqreturn_t adpt_isr(int irq, void *dev_id, struct pt_regs *regs);
  230. #ifdef REBOOT_NOTIFIER
  231. static int adpt_reboot_event(struct notifier_block *n, ulong code, void *p);
  232. #endif
  233. static void adpt_i2o_report_hba_unit(adpt_hba* pHba, struct i2o_device *d);
  234. static int adpt_i2o_query_scalar(adpt_hba* pHba, int tid,
  235. int group, int field, void *buf, int buflen);
  236. #ifdef DEBUG
  237. static const char *adpt_i2o_get_class_name(int class);
  238. #endif
  239. static int adpt_i2o_issue_params(int cmd, adpt_hba* pHba, int tid,
  240. void *opblk, int oplen, void *resblk, int reslen);
  241. static int adpt_i2o_post_wait(adpt_hba* pHba, u32* msg, int len, int timeout);
  242. static int adpt_i2o_lct_get(adpt_hba* pHba);
  243. static int adpt_i2o_parse_lct(adpt_hba* pHba);
  244. static int adpt_i2o_activate_hba(adpt_hba* pHba);
  245. static int adpt_i2o_enable_hba(adpt_hba* pHba);
  246. static int adpt_i2o_install_device(adpt_hba* pHba, struct i2o_device *d);
  247. static s32 adpt_i2o_post_this(adpt_hba* pHba, u32* data, int len);
  248. static s32 adpt_i2o_quiesce_hba(adpt_hba* pHba);
  249. static s32 adpt_i2o_status_get(adpt_hba* pHba);
  250. static s32 adpt_i2o_init_outbound_q(adpt_hba* pHba);
  251. static s32 adpt_i2o_hrt_get(adpt_hba* pHba);
  252. static s32 adpt_scsi_to_i2o(adpt_hba* pHba, struct scsi_cmnd* cmd, struct adpt_device* dptdevice);
  253. static s32 adpt_i2o_to_scsi(void __iomem *reply, struct scsi_cmnd* cmd);
  254. static s32 adpt_scsi_register(adpt_hba* pHba,struct scsi_host_template * sht);
  255. static s32 adpt_hba_reset(adpt_hba* pHba);
  256. static s32 adpt_i2o_reset_hba(adpt_hba* pHba);
  257. static s32 adpt_rescan(adpt_hba* pHba);
  258. static s32 adpt_i2o_reparse_lct(adpt_hba* pHba);
  259. static s32 adpt_send_nop(adpt_hba*pHba,u32 m);
  260. static void adpt_i2o_delete_hba(adpt_hba* pHba);
  261. static void adpt_inquiry(adpt_hba* pHba);
  262. static void adpt_fail_posted_scbs(adpt_hba* pHba);
  263. static struct adpt_device* adpt_find_device(adpt_hba* pHba, u32 chan, u32 id, u32 lun);
  264. static int adpt_install_hba(struct scsi_host_template* sht, struct pci_dev* pDev) ;
  265. static int adpt_i2o_online_hba(adpt_hba* pHba);
  266. static void adpt_i2o_post_wait_complete(u32, int);
  267. static int adpt_i2o_systab_send(adpt_hba* pHba);
  268. static int adpt_ioctl(struct inode *inode, struct file *file, uint cmd, ulong arg);
  269. static int adpt_open(struct inode *inode, struct file *file);
  270. static int adpt_close(struct inode *inode, struct file *file);
  271. #ifdef UARTDELAY
  272. static void adpt_delay(int millisec);
  273. #endif
  274. #if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,0)
  275. static struct pci_dev* adpt_pci_find_device(uint vendor, struct pci_dev* from);
  276. #endif
  277. #if defined __ia64__
  278. static void adpt_ia64_info(sysInfo_S* si);
  279. #endif
  280. #if defined __sparc__
  281. static void adpt_sparc_info(sysInfo_S* si);
  282. #endif
  283. #if defined __alpha__
  284. static void adpt_sparc_info(sysInfo_S* si);
  285. #endif
  286. #if defined __i386__
  287. static void adpt_i386_info(sysInfo_S* si);
  288. #endif
  289. #define PRINT_BUFFER_SIZE 512
  290. #define HBA_FLAGS_DBG_FLAGS_MASK 0xffff0000 // Mask for debug flags
  291. #define HBA_FLAGS_DBG_KERNEL_PRINT_B 0x00010000 // Kernel Debugger Print
  292. #define HBA_FLAGS_DBG_FW_PRINT_B 0x00020000 // Firmware Debugger Print
  293. #define HBA_FLAGS_DBG_FUNCTION_ENTRY_B 0x00040000 // Function Entry Point
  294. #define HBA_FLAGS_DBG_FUNCTION_EXIT_B 0x00080000 // Function Exit
  295. #define HBA_FLAGS_DBG_ERROR_B 0x00100000 // Error Conditions
  296. #define HBA_FLAGS_DBG_INIT_B 0x00200000 // Init Prints
  297. #define HBA_FLAGS_DBG_OS_COMMANDS_B 0x00400000 // OS Command Info
  298. #define HBA_FLAGS_DBG_SCAN_B 0x00800000 // Device Scan
  299. #define FW_DEBUG_STR_LENGTH_OFFSET 0
  300. #define FW_DEBUG_FLAGS_OFFSET 4
  301. #define FW_DEBUG_BLED_OFFSET 8
  302. #define FW_DEBUG_FLAGS_NO_HEADERS_B 0x01
  303. #endif /* !HOSTS_C */
  304. #endif /* _DPT_H */