1 /***************************************************************************
5 copyright : (C) 2001 by Adaptec
6 email : deanna_bonds@adaptec.com
8 See README.dpti for history, notes, license info, and credits
9 ***************************************************************************/
11 /***************************************************************************
13 * This program is free software; you can redistribute it and/or modify *
14 * it under the terms of the GNU General Public License as published by *
15 * the Free Software Foundation; either version 2 of the License, or *
16 * (at your option) any later version. *
18 ***************************************************************************/
23 #ifndef LINUX_VERSION_CODE
24 #include <linux/version.h>
27 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,00)
28 #define MAX_TO_IOP_MESSAGES (210)
30 #define MAX_TO_IOP_MESSAGES (255)
32 #define MAX_FROM_IOP_MESSAGES (255)
36 * SCSI interface function Prototypes
39 static int adpt_proc_info(char *buffer, char **start, off_t offset,
40 int length, int inode, int inout);
41 static int adpt_detect(Scsi_Host_Template * sht);
42 static int adpt_queue(Scsi_Cmnd * cmd, void (*cmdcomplete) (Scsi_Cmnd *));
43 static int adpt_abort(Scsi_Cmnd * cmd);
44 static int adpt_reset(Scsi_Cmnd* cmd);
45 static int adpt_release(struct Scsi_Host *host);
47 static const char *adpt_info(struct Scsi_Host *pSHost);
48 static int adpt_bios_param(Disk * disk, kdev_t dev, int geom[]);
50 static int adpt_bus_reset(Scsi_Cmnd* cmd);
51 static int adpt_device_reset(Scsi_Cmnd* cmd);
55 * Scsi_Host_Template (see hosts.h)
58 #define DPT_DRIVER_NAME "Adaptec I2O RAID"
60 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,3,00)
62 proc_info: adpt_proc_info, \
63 detect: adpt_detect, \
64 release: adpt_release, \
66 queuecommand: adpt_queue, \
67 eh_abort_handler: adpt_abort, \
68 eh_device_reset_handler: adpt_device_reset, \
69 eh_bus_reset_handler: adpt_bus_reset, \
70 eh_host_reset_handler: adpt_reset, \
71 bios_param: adpt_bios_param, \
72 can_queue: MAX_TO_IOP_MESSAGES ,/* max simultaneous cmds */\
73 this_id: 7, /* scsi id of host adapter */\
74 sg_tablesize: 0, /* max scatter-gather cmds */\
75 cmd_per_lun: 256, /* cmds per lun (linked cmds) */\
76 use_clustering: ENABLE_CLUSTERING, \
80 #else /* KERNEL_VERSION > 2.2.16 */
83 proc_info: adpt_proc_info, \
84 detect: adpt_detect, \
85 release: adpt_release, \
87 queuecommand: adpt_queue, \
88 eh_abort_handler: adpt_abort, \
89 eh_device_reset_handler: adpt_device_reset, \
90 eh_bus_reset_handler: adpt_bus_reset, \
91 eh_host_reset_handler: adpt_reset, \
92 bios_param: adpt_bios_param, \
93 can_queue: MAX_TO_IOP_MESSAGES, /* max simultaneous cmds */\
94 this_id: 7, /* scsi id of host adapter */\
95 sg_tablesize: 0, /* max scatter-gather cmds */\
96 cmd_per_lun: 256, /* cmds per lun (linked cmds) */\
97 use_clustering: ENABLE_CLUSTERING, \
99 proc_name: "dpt_i2o" /* this is the name of our proc node*/ \
105 #include "dpt/sys_info.h"
106 #include <linux/wait.h>
107 #include "dpt/dpti_i2o.h"
108 #include "dpt/dpti_ioctl.h"
110 #define DPT_I2O_VERSION "2.4 Build 5"
111 #define DPT_VERSION 2
112 #define DPT_REVISION '4'
113 #define DPT_SUBREVISION '5'
117 #define DPT_YEAR (2001-1980)
119 #define DPT_DRIVER "dpt_i2o"
120 #define DPTI_I2O_MAJOR (151)
121 #define DPT_ORGANIZATION_ID (0x1B) /* For Private Messages */
122 #define DPTI_MAX_HBA (16)
123 #define MAX_CHANNEL (5) // Maximum Channel # Supported
124 #define MAX_ID (128) // Maximum Target ID Supported
126 /* Sizes in 4 byte words */
127 #define REPLY_FRAME_SIZE (17)
128 #define MAX_MESSAGE_SIZE (128)
129 #define SG_LIST_ELEMENTS (56)
131 #define EMPTY_QUEUE 0xffffffff
132 #define I2O_INTERRUPT_PENDING_B (0x08)
134 #define PCI_DPT_VENDOR_ID (0x1044) // DPT PCI Vendor ID
135 #define PCI_DPT_DEVICE_ID (0xA501) // DPT PCI I2O Device ID
136 #define PCI_DPT_RAPTOR_DEVICE_ID (0xA511)
138 //#define REBOOT_NOTIFIER 1
139 /* Debugging macro from Linux Device Drivers - Rubini */
142 //TODO add debug level switch
143 # define PDEBUG(fmt, args...) printk(KERN_DEBUG "dpti: " fmt, ##args)
144 # define PDEBUGV(fmt, args...) printk(KERN_DEBUG "dpti: " fmt, ##args)
146 # define PDEBUG(fmt, args...) /* not debugging: nothing */
147 # define PDEBUGV(fmt, args...) /* not debugging: nothing */
150 #define PERROR(fmt, args...) printk(KERN_ERR fmt, ##args)
151 #define PWARN(fmt, args...) printk(KERN_WARNING fmt, ##args)
152 #define PINFO(fmt, args...) printk(KERN_INFO fmt, ##args)
153 #define PCRIT(fmt, args...) printk(KERN_CRIT fmt, ##args)
155 #define SHUTDOWN_SIGS (sigmask(SIGKILL)|sigmask(SIGINT)|sigmask(SIGTERM))
159 #define TMOUT_INQUIRY (20)
160 #define TMOUT_FLUSH (360/45)
161 #define TMOUT_ABORT (30)
162 #define TMOUT_SCSI (300)
163 #define TMOUT_IOPRESET (360)
164 #define TMOUT_GETSTATUS (15)
165 #define TMOUT_INITOUTBOUND (15)
166 #define TMOUT_LCT (360)
169 #define I2O_SCSI_DEVICE_DSC_MASK 0x00FF
171 #define I2O_DETAIL_STATUS_UNSUPPORTED_FUNCTION 0x000A
173 #define I2O_SCSI_DSC_MASK 0xFF00
174 #define I2O_SCSI_DSC_SUCCESS 0x0000
175 #define I2O_SCSI_DSC_REQUEST_ABORTED 0x0200
176 #define I2O_SCSI_DSC_UNABLE_TO_ABORT 0x0300
177 #define I2O_SCSI_DSC_COMPLETE_WITH_ERROR 0x0400
178 #define I2O_SCSI_DSC_ADAPTER_BUSY 0x0500
179 #define I2O_SCSI_DSC_REQUEST_INVALID 0x0600
180 #define I2O_SCSI_DSC_PATH_INVALID 0x0700
181 #define I2O_SCSI_DSC_DEVICE_NOT_PRESENT 0x0800
182 #define I2O_SCSI_DSC_UNABLE_TO_TERMINATE 0x0900
183 #define I2O_SCSI_DSC_SELECTION_TIMEOUT 0x0A00
184 #define I2O_SCSI_DSC_COMMAND_TIMEOUT 0x0B00
185 #define I2O_SCSI_DSC_MR_MESSAGE_RECEIVED 0x0D00
186 #define I2O_SCSI_DSC_SCSI_BUS_RESET 0x0E00
187 #define I2O_SCSI_DSC_PARITY_ERROR_FAILURE 0x0F00
188 #define I2O_SCSI_DSC_AUTOSENSE_FAILED 0x1000
189 #define I2O_SCSI_DSC_NO_ADAPTER 0x1100
190 #define I2O_SCSI_DSC_DATA_OVERRUN 0x1200
191 #define I2O_SCSI_DSC_UNEXPECTED_BUS_FREE 0x1300
192 #define I2O_SCSI_DSC_SEQUENCE_FAILURE 0x1400
193 #define I2O_SCSI_DSC_REQUEST_LENGTH_ERROR 0x1500
194 #define I2O_SCSI_DSC_PROVIDE_FAILURE 0x1600
195 #define I2O_SCSI_DSC_BDR_MESSAGE_SENT 0x1700
196 #define I2O_SCSI_DSC_REQUEST_TERMINATED 0x1800
197 #define I2O_SCSI_DSC_IDE_MESSAGE_SENT 0x3300
198 #define I2O_SCSI_DSC_RESOURCE_UNAVAILABLE 0x3400
199 #define I2O_SCSI_DSC_UNACKNOWLEDGED_EVENT 0x3500
200 #define I2O_SCSI_DSC_MESSAGE_RECEIVED 0x3600
201 #define I2O_SCSI_DSC_INVALID_CDB 0x3700
202 #define I2O_SCSI_DSC_LUN_INVALID 0x3800
203 #define I2O_SCSI_DSC_SCSI_TID_INVALID 0x3900
204 #define I2O_SCSI_DSC_FUNCTION_UNAVAILABLE 0x3A00
205 #define I2O_SCSI_DSC_NO_NEXUS 0x3B00
206 #define I2O_SCSI_DSC_SCSI_IID_INVALID 0x3C00
207 #define I2O_SCSI_DSC_CDB_RECEIVED 0x3D00
208 #define I2O_SCSI_DSC_LUN_ALREADY_ENABLED 0x3E00
209 #define I2O_SCSI_DSC_BUS_BUSY 0x3F00
210 #define I2O_SCSI_DSC_QUEUE_FROZEN 0x4000
218 #define HBA_FLAGS_INSTALLED_B 0x00000001 // Adapter Was Installed
219 #define HBA_FLAGS_BLINKLED_B 0x00000002 // Adapter In Blink LED State
220 #define HBA_FLAGS_IN_RESET 0x00000040 /* in reset */
221 #define HBA_HOSTRESET_FAILED 0x00000080 /* adpt_resethost failed */
224 // Device state flags
225 #define DPTI_DEV_ONLINE 0x00
226 #define DPTI_DEV_UNSCANNED 0x01
227 #define DPTI_DEV_RESET 0x02
228 #define DPTI_DEV_OFFLINE 0x04
232 struct adpt_device* next_lun;
242 struct i2o_device* pI2o_dev;
243 Scsi_Device *pScsi_dev;
246 struct adpt_channel {
247 struct adpt_device* device[MAX_ID]; /* used as an array of 128 scsi ids */
252 struct i2o_device* pI2o_dev;
256 #define DPTI_STATE_RESET (0x01)
257 #define DPTI_STATE_IOCTL (0x02)
259 typedef struct _adpt_hba {
260 struct _adpt_hba *next;
261 struct pci_dev *pDev;
262 struct Scsi_Host *host;
264 spinlock_t state_lock;
266 int host_no; /* SCSI host number */
268 u8 in_use; /* is the management node open*/
273 ulong base_addr_virt;
275 ulong base_addr_phys;
283 u32 sg_tablesize; // Scatter/Gather List Size.
288 i2o_status_block* status_block;
292 struct i2o_device* devices;
293 struct adpt_channel channel[MAX_CHANNEL];
294 struct proc_dir_entry* proc_entry; /* /proc dir */
296 ulong FwDebugBuffer_P; // Virtual Address Of FW Debug Buffer
297 u32 FwDebugBufferSize; // FW Debug Buffer Size In Bytes
298 ulong FwDebugStrLength_P; // Virtual Addr Of FW Debug String Len
299 ulong FwDebugFlags_P; // Virtual Address Of FW Debug Flags
300 ulong FwDebugBLEDflag_P; // Virtual Addr Of FW Debug BLED
301 ulong FwDebugBLEDvalue_P; // Virtual Addr Of FW Debug BLED
305 struct sg_simple_element {
311 * Function Prototypes
314 static void adpt_i2o_sys_shutdown(void);
315 static int adpt_init(void);
316 static int adpt_i2o_build_sys_table(void);
317 static void adpt_isr(int irq, void *dev_id, struct pt_regs *regs);
318 #ifdef REBOOT_NOTIFIER
319 static int adpt_reboot_event(struct notifier_block *n, ulong code, void *p);
322 static void adpt_i2o_report_hba_unit(adpt_hba* pHba, struct i2o_device *d);
323 static int adpt_i2o_query_scalar(adpt_hba* pHba, int tid,
324 int group, int field, void *buf, int buflen);
326 static const char *adpt_i2o_get_class_name(int class);
328 static int adpt_i2o_issue_params(int cmd, adpt_hba* pHba, int tid,
329 void *opblk, int oplen, void *resblk, int reslen);
330 static int adpt_i2o_post_wait(adpt_hba* pHba, u32* msg, int len, int timeout);
331 static int adpt_i2o_lct_get(adpt_hba* pHba);
332 static int adpt_i2o_parse_lct(adpt_hba* pHba);
333 static int adpt_i2o_activate_hba(adpt_hba* pHba);
334 static int adpt_i2o_enable_hba(adpt_hba* pHba);
335 static int adpt_i2o_install_device(adpt_hba* pHba, struct i2o_device *d);
336 static s32 adpt_i2o_post_this(adpt_hba* pHba, u32* data, int len);
337 static s32 adpt_i2o_quiesce_hba(adpt_hba* pHba);
338 static s32 adpt_i2o_status_get(adpt_hba* pHba);
339 static s32 adpt_i2o_init_outbound_q(adpt_hba* pHba);
340 static s32 adpt_i2o_hrt_get(adpt_hba* pHba);
341 static s32 adpt_scsi_to_i2o(adpt_hba* pHba, Scsi_Cmnd* cmd, struct adpt_device* dptdevice);
342 static s32 adpt_i2o_to_scsi(ulong reply, Scsi_Cmnd* cmd);
343 static s32 adpt_scsi_register(adpt_hba* pHba,Scsi_Host_Template * sht);
344 static s32 adpt_hba_reset(adpt_hba* pHba);
345 static s32 adpt_i2o_reset_hba(adpt_hba* pHba);
346 static s32 adpt_rescan(adpt_hba* pHba);
347 static s32 adpt_i2o_reparse_lct(adpt_hba* pHba);
348 static s32 adpt_send_nop(adpt_hba*pHba,u32 m);
349 static void adpt_i2o_delete_hba(adpt_hba* pHba);
350 static void adpt_select_queue_depths(struct Scsi_Host *host, Scsi_Device * devicelist);
351 static void adpt_inquiry(adpt_hba* pHba);
352 static void adpt_fail_posted_scbs(adpt_hba* pHba);
353 static struct adpt_device* adpt_find_device(adpt_hba* pHba, u32 chan, u32 id, u32 lun);
354 static int adpt_install_hba(Scsi_Host_Template* sht, struct pci_dev* pDev) ;
355 static int adpt_i2o_online_hba(adpt_hba* pHba);
356 static void adpt_i2o_post_wait_complete(u32, int);
357 static int adpt_i2o_systab_send(adpt_hba* pHba);
359 static int adpt_ioctl(struct inode *inode, struct file *file, uint cmd, ulong arg);
360 static int adpt_open(struct inode *inode, struct file *file);
361 static int adpt_close(struct inode *inode, struct file *file);
365 static void adpt_delay(int millisec);
368 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,0)
369 static struct pci_dev* adpt_pci_find_device(uint vendor, struct pci_dev* from);
373 static void adpt_ia64_info(sysInfo_S* si);
375 #if defined __sparc__
376 static void adpt_sparc_info(sysInfo_S* si);
378 #if defined __alpha__
379 static void adpt_sparc_info(sysInfo_S* si);
382 static void adpt_i386_info(sysInfo_S* si);
385 #define PRINT_BUFFER_SIZE 512
387 #define HBA_FLAGS_DBG_FLAGS_MASK 0xffff0000 // Mask for debug flags
388 #define HBA_FLAGS_DBG_KERNEL_PRINT_B 0x00010000 // Kernel Debugger Print
389 #define HBA_FLAGS_DBG_FW_PRINT_B 0x00020000 // Firmware Debugger Print
390 #define HBA_FLAGS_DBG_FUNCTION_ENTRY_B 0x00040000 // Function Entry Point
391 #define HBA_FLAGS_DBG_FUNCTION_EXIT_B 0x00080000 // Function Exit
392 #define HBA_FLAGS_DBG_ERROR_B 0x00100000 // Error Conditions
393 #define HBA_FLAGS_DBG_INIT_B 0x00200000 // Init Prints
394 #define HBA_FLAGS_DBG_OS_COMMANDS_B 0x00400000 // OS Command Info
395 #define HBA_FLAGS_DBG_SCAN_B 0x00800000 // Device Scan
397 #define FW_DEBUG_STR_LENGTH_OFFSET 0
398 #define FW_DEBUG_FLAGS_OFFSET 4
399 #define FW_DEBUG_BLED_OFFSET 8
401 #define FW_DEBUG_FLAGS_NO_HEADERS_B 0x01
402 #endif /* !HOSTS_C */