2 3w-sas.c -- LSI 3ware SAS/SATA-RAID Controller device driver for Linux.
4 Written By: Adam Radford <linuxraid@lsi.com>
6 Copyright (C) 2009 LSI Corporation.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; version 2 of the License.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
18 THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR
19 CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT
20 LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
21 MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is
22 solely responsible for determining the appropriateness of using and
23 distributing the Program and assumes all risks associated with its
24 exercise of rights under this Agreement, including but not limited to
25 the risks and costs of program errors, damage to or loss of data,
26 programs or equipment, and unavailability or interruption of operations.
28 DISCLAIMER OF LIABILITY
29 NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY
30 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31 DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND
32 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
33 TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
34 USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
35 HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES
37 You should have received a copy of the GNU General Public License
38 along with this program; if not, write to the Free Software
39 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
41 Controllers supported by this driver:
43 LSI 3ware 9750 6Gb/s SAS/SATA-RAID
45 Bugs/Comments/Suggestions should be mailed to:
48 For more information, goto:
53 3.26.02.000 - Initial driver release.
56 #include <linux/module.h>
57 #include <linux/reboot.h>
58 #include <linux/spinlock.h>
59 #include <linux/interrupt.h>
60 #include <linux/moduleparam.h>
61 #include <linux/errno.h>
62 #include <linux/types.h>
63 #include <linux/delay.h>
64 #include <linux/pci.h>
65 #include <linux/time.h>
66 #include <linux/mutex.h>
67 #include <linux/slab.h>
70 #include <asm/uaccess.h>
71 #include <scsi/scsi.h>
72 #include <scsi/scsi_host.h>
73 #include <scsi/scsi_tcq.h>
74 #include <scsi/scsi_cmnd.h>
78 #define TW_DRIVER_VERSION "3.26.02.000"
79 static DEFINE_MUTEX(twl_chrdev_mutex
);
80 static TW_Device_Extension
*twl_device_extension_list
[TW_MAX_SLOT
];
81 static unsigned int twl_device_extension_count
;
82 static int twl_major
= -1;
83 extern struct timezone sys_tz
;
85 /* Module parameters */
86 MODULE_AUTHOR ("LSI");
87 MODULE_DESCRIPTION ("LSI 3ware SAS/SATA-RAID Linux Driver");
88 MODULE_LICENSE("GPL");
89 MODULE_VERSION(TW_DRIVER_VERSION
);
92 module_param(use_msi
, int, S_IRUGO
);
93 MODULE_PARM_DESC(use_msi
, "Use Message Signaled Interrupts. Default: 0");
95 /* Function prototypes */
96 static int twl_reset_device_extension(TW_Device_Extension
*tw_dev
, int ioctl_reset
);
100 /* This function returns AENs through sysfs */
101 static ssize_t
twl_sysfs_aen_read(struct file
*filp
, struct kobject
*kobj
,
102 struct bin_attribute
*bin_attr
,
103 char *outbuf
, loff_t offset
, size_t count
)
105 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
106 struct Scsi_Host
*shost
= class_to_shost(dev
);
107 TW_Device_Extension
*tw_dev
= (TW_Device_Extension
*)shost
->hostdata
;
108 unsigned long flags
= 0;
111 if (!capable(CAP_SYS_ADMIN
))
114 spin_lock_irqsave(tw_dev
->host
->host_lock
, flags
);
115 ret
= memory_read_from_buffer(outbuf
, count
, &offset
, tw_dev
->event_queue
[0], sizeof(TW_Event
) * TW_Q_LENGTH
);
116 spin_unlock_irqrestore(tw_dev
->host
->host_lock
, flags
);
119 } /* End twl_sysfs_aen_read() */
121 /* aen_read sysfs attribute initializer */
122 static struct bin_attribute twl_sysfs_aen_read_attr
= {
124 .name
= "3ware_aen_read",
128 .read
= twl_sysfs_aen_read
131 /* This function returns driver compatibility info through sysfs */
132 static ssize_t
twl_sysfs_compat_info(struct file
*filp
, struct kobject
*kobj
,
133 struct bin_attribute
*bin_attr
,
134 char *outbuf
, loff_t offset
, size_t count
)
136 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
137 struct Scsi_Host
*shost
= class_to_shost(dev
);
138 TW_Device_Extension
*tw_dev
= (TW_Device_Extension
*)shost
->hostdata
;
139 unsigned long flags
= 0;
142 if (!capable(CAP_SYS_ADMIN
))
145 spin_lock_irqsave(tw_dev
->host
->host_lock
, flags
);
146 ret
= memory_read_from_buffer(outbuf
, count
, &offset
, &tw_dev
->tw_compat_info
, sizeof(TW_Compatibility_Info
));
147 spin_unlock_irqrestore(tw_dev
->host
->host_lock
, flags
);
150 } /* End twl_sysfs_compat_info() */
152 /* compat_info sysfs attribute initializer */
153 static struct bin_attribute twl_sysfs_compat_info_attr
= {
155 .name
= "3ware_compat_info",
159 .read
= twl_sysfs_compat_info
162 /* Show some statistics about the card */
163 static ssize_t
twl_show_stats(struct device
*dev
,
164 struct device_attribute
*attr
, char *buf
)
166 struct Scsi_Host
*host
= class_to_shost(dev
);
167 TW_Device_Extension
*tw_dev
= (TW_Device_Extension
*)host
->hostdata
;
168 unsigned long flags
= 0;
171 spin_lock_irqsave(tw_dev
->host
->host_lock
, flags
);
172 len
= snprintf(buf
, PAGE_SIZE
, "3w-sas Driver version: %s\n"
173 "Current commands posted: %4d\n"
174 "Max commands posted: %4d\n"
175 "Last sgl length: %4d\n"
176 "Max sgl length: %4d\n"
177 "Last sector count: %4d\n"
178 "Max sector count: %4d\n"
179 "SCSI Host Resets: %4d\n"
182 tw_dev
->posted_request_count
,
183 tw_dev
->max_posted_request_count
,
185 tw_dev
->max_sgl_entries
,
186 tw_dev
->sector_count
,
187 tw_dev
->max_sector_count
,
190 spin_unlock_irqrestore(tw_dev
->host
->host_lock
, flags
);
192 } /* End twl_show_stats() */
194 /* stats sysfs attribute initializer */
195 static struct device_attribute twl_host_stats_attr
= {
197 .name
= "3ware_stats",
200 .show
= twl_show_stats
203 /* Host attributes initializer */
204 static struct device_attribute
*twl_host_attrs
[] = {
205 &twl_host_stats_attr
,
209 /* This function will look up an AEN severity string */
210 static char *twl_aen_severity_lookup(unsigned char severity_code
)
214 if ((severity_code
< (unsigned char) TW_AEN_SEVERITY_ERROR
) ||
215 (severity_code
> (unsigned char) TW_AEN_SEVERITY_DEBUG
))
218 retval
= twl_aen_severity_table
[severity_code
];
221 } /* End twl_aen_severity_lookup() */
223 /* This function will queue an event */
224 static void twl_aen_queue_event(TW_Device_Extension
*tw_dev
, TW_Command_Apache_Header
*header
)
235 /* Fill out event info */
236 event
= tw_dev
->event_queue
[tw_dev
->error_index
];
240 sprintf(host
, " scsi%d:", tw_dev
->host
->host_no
);
242 aen
= le16_to_cpu(header
->status_block
.error
);
243 memset(event
, 0, sizeof(TW_Event
));
245 event
->severity
= TW_SEV_OUT(header
->status_block
.severity__reserved
);
246 do_gettimeofday(&time
);
247 local_time
= (u32
)(time
.tv_sec
- (sys_tz
.tz_minuteswest
* 60));
248 event
->time_stamp_sec
= local_time
;
249 event
->aen_code
= aen
;
250 event
->retrieved
= TW_AEN_NOT_RETRIEVED
;
251 event
->sequence_id
= tw_dev
->error_sequence_id
;
252 tw_dev
->error_sequence_id
++;
254 /* Check for embedded error string */
255 error_str
= &(header
->err_specific_desc
[strlen(header
->err_specific_desc
)+1]);
257 header
->err_specific_desc
[sizeof(header
->err_specific_desc
) - 1] = '\0';
258 event
->parameter_len
= strlen(header
->err_specific_desc
);
259 memcpy(event
->parameter_data
, header
->err_specific_desc
, event
->parameter_len
+ 1 + strlen(error_str
));
260 if (event
->severity
!= TW_AEN_SEVERITY_DEBUG
)
261 printk(KERN_WARNING
"3w-sas:%s AEN: %s (0x%02X:0x%04X): %s:%s.\n",
263 twl_aen_severity_lookup(TW_SEV_OUT(header
->status_block
.severity__reserved
)),
264 TW_MESSAGE_SOURCE_CONTROLLER_EVENT
, aen
, error_str
,
265 header
->err_specific_desc
);
269 tw_dev
->error_index
= (tw_dev
->error_index
+ 1 ) % TW_Q_LENGTH
;
270 } /* End twl_aen_queue_event() */
272 /* This function will attempt to post a command packet to the board */
273 static int twl_post_command_packet(TW_Device_Extension
*tw_dev
, int request_id
)
275 dma_addr_t command_que_value
;
277 command_que_value
= tw_dev
->command_packet_phys
[request_id
];
278 command_que_value
+= TW_COMMAND_OFFSET
;
280 /* First write upper 4 bytes */
281 writel((u32
)((u64
)command_que_value
>> 32), TWL_HIBQPH_REG_ADDR(tw_dev
));
282 /* Then the lower 4 bytes */
283 writel((u32
)(command_que_value
| TWL_PULL_MODE
), TWL_HIBQPL_REG_ADDR(tw_dev
));
285 tw_dev
->state
[request_id
] = TW_S_POSTED
;
286 tw_dev
->posted_request_count
++;
287 if (tw_dev
->posted_request_count
> tw_dev
->max_posted_request_count
)
288 tw_dev
->max_posted_request_count
= tw_dev
->posted_request_count
;
291 } /* End twl_post_command_packet() */
293 /* This function hands scsi cdb's to the firmware */
294 static int twl_scsiop_execute_scsi(TW_Device_Extension
*tw_dev
, int request_id
, char *cdb
, int use_sg
, TW_SG_Entry_ISO
*sglistarg
)
296 TW_Command_Full
*full_command_packet
;
297 TW_Command_Apache
*command_packet
;
299 struct scsi_cmnd
*srb
= NULL
;
300 struct scatterlist
*sglist
= NULL
, *sg
;
303 if (tw_dev
->srb
[request_id
]) {
304 srb
= tw_dev
->srb
[request_id
];
305 if (scsi_sglist(srb
))
306 sglist
= scsi_sglist(srb
);
309 /* Initialize command packet */
310 full_command_packet
= tw_dev
->command_packet_virt
[request_id
];
311 full_command_packet
->header
.header_desc
.size_header
= 128;
312 full_command_packet
->header
.status_block
.error
= 0;
313 full_command_packet
->header
.status_block
.severity__reserved
= 0;
315 command_packet
= &full_command_packet
->command
.newcommand
;
316 command_packet
->status
= 0;
317 command_packet
->opcode__reserved
= TW_OPRES_IN(0, TW_OP_EXECUTE_SCSI
);
319 /* We forced 16 byte cdb use earlier */
321 memcpy(command_packet
->cdb
, srb
->cmnd
, TW_MAX_CDB_LEN
);
323 memcpy(command_packet
->cdb
, cdb
, TW_MAX_CDB_LEN
);
326 command_packet
->unit
= srb
->device
->id
;
327 command_packet
->request_id__lunl
=
328 cpu_to_le16(TW_REQ_LUN_IN(srb
->device
->lun
, request_id
));
330 command_packet
->request_id__lunl
=
331 cpu_to_le16(TW_REQ_LUN_IN(0, request_id
));
332 command_packet
->unit
= 0;
335 command_packet
->sgl_offset
= 16;
338 /* Map sglist from scsi layer to cmd packet */
339 if (scsi_sg_count(srb
)) {
340 sg_count
= scsi_dma_map(srb
);
344 scsi_for_each_sg(srb
, sg
, sg_count
, i
) {
345 command_packet
->sg_list
[i
].address
= TW_CPU_TO_SGL(sg_dma_address(sg
));
346 command_packet
->sg_list
[i
].length
= TW_CPU_TO_SGL(sg_dma_len(sg
));
348 command_packet
->sgl_entries__lunh
= cpu_to_le16(TW_REQ_LUN_IN((srb
->device
->lun
>> 4), scsi_sg_count(tw_dev
->srb
[request_id
])));
351 /* Internal cdb post */
352 for (i
= 0; i
< use_sg
; i
++) {
353 command_packet
->sg_list
[i
].address
= TW_CPU_TO_SGL(sglistarg
[i
].address
);
354 command_packet
->sg_list
[i
].length
= TW_CPU_TO_SGL(sglistarg
[i
].length
);
356 command_packet
->sgl_entries__lunh
= cpu_to_le16(TW_REQ_LUN_IN(0, use_sg
));
359 /* Update some stats */
361 tw_dev
->sector_count
= scsi_bufflen(srb
) / 512;
362 if (tw_dev
->sector_count
> tw_dev
->max_sector_count
)
363 tw_dev
->max_sector_count
= tw_dev
->sector_count
;
364 tw_dev
->sgl_entries
= scsi_sg_count(srb
);
365 if (tw_dev
->sgl_entries
> tw_dev
->max_sgl_entries
)
366 tw_dev
->max_sgl_entries
= tw_dev
->sgl_entries
;
369 /* Now post the command to the board */
370 retval
= twl_post_command_packet(tw_dev
, request_id
);
374 } /* End twl_scsiop_execute_scsi() */
376 /* This function will read the aen queue from the isr */
377 static int twl_aen_read_queue(TW_Device_Extension
*tw_dev
, int request_id
)
379 char cdb
[TW_MAX_CDB_LEN
];
380 TW_SG_Entry_ISO sglist
[1];
381 TW_Command_Full
*full_command_packet
;
384 full_command_packet
= tw_dev
->command_packet_virt
[request_id
];
385 memset(full_command_packet
, 0, sizeof(TW_Command_Full
));
388 memset(&cdb
, 0, TW_MAX_CDB_LEN
);
389 cdb
[0] = REQUEST_SENSE
; /* opcode */
390 cdb
[4] = TW_ALLOCATION_LENGTH
; /* allocation length */
392 /* Initialize sglist */
393 memset(&sglist
, 0, sizeof(TW_SG_Entry_ISO
));
394 sglist
[0].length
= TW_SECTOR_SIZE
;
395 sglist
[0].address
= tw_dev
->generic_buffer_phys
[request_id
];
397 /* Mark internal command */
398 tw_dev
->srb
[request_id
] = NULL
;
400 /* Now post the command packet */
401 if (twl_scsiop_execute_scsi(tw_dev
, request_id
, cdb
, 1, sglist
)) {
402 TW_PRINTK(tw_dev
->host
, TW_DRIVER
, 0x2, "Post failed while reading AEN queue");
408 } /* End twl_aen_read_queue() */
410 /* This function will sync firmware time with the host time */
411 static void twl_aen_sync_time(TW_Device_Extension
*tw_dev
, int request_id
)
415 TW_Command_Full
*full_command_packet
;
416 TW_Command
*command_packet
;
417 TW_Param_Apache
*param
;
420 /* Fill out the command packet */
421 full_command_packet
= tw_dev
->command_packet_virt
[request_id
];
422 memset(full_command_packet
, 0, sizeof(TW_Command_Full
));
423 command_packet
= &full_command_packet
->command
.oldcommand
;
424 command_packet
->opcode__sgloffset
= TW_OPSGL_IN(2, TW_OP_SET_PARAM
);
425 command_packet
->request_id
= request_id
;
426 command_packet
->byte8_offset
.param
.sgl
[0].address
= TW_CPU_TO_SGL(tw_dev
->generic_buffer_phys
[request_id
]);
427 command_packet
->byte8_offset
.param
.sgl
[0].length
= TW_CPU_TO_SGL(TW_SECTOR_SIZE
);
428 command_packet
->size
= TW_COMMAND_SIZE
;
429 command_packet
->byte6_offset
.parameter_count
= cpu_to_le16(1);
431 /* Setup the param */
432 param
= (TW_Param_Apache
*)tw_dev
->generic_buffer_virt
[request_id
];
433 memset(param
, 0, TW_SECTOR_SIZE
);
434 param
->table_id
= cpu_to_le16(TW_TIMEKEEP_TABLE
| 0x8000); /* Controller time keep table */
435 param
->parameter_id
= cpu_to_le16(0x3); /* SchedulerTime */
436 param
->parameter_size_bytes
= cpu_to_le16(4);
438 /* Convert system time in UTC to local time seconds since last
440 do_gettimeofday(&utc
);
441 local_time
= (u32
)(utc
.tv_sec
- (sys_tz
.tz_minuteswest
* 60));
442 schedulertime
= local_time
- (3 * 86400);
443 schedulertime
= cpu_to_le32(schedulertime
% 604800);
445 memcpy(param
->data
, &schedulertime
, sizeof(u32
));
447 /* Mark internal command */
448 tw_dev
->srb
[request_id
] = NULL
;
450 /* Now post the command */
451 twl_post_command_packet(tw_dev
, request_id
);
452 } /* End twl_aen_sync_time() */
454 /* This function will assign an available request id */
455 static void twl_get_request_id(TW_Device_Extension
*tw_dev
, int *request_id
)
457 *request_id
= tw_dev
->free_queue
[tw_dev
->free_head
];
458 tw_dev
->free_head
= (tw_dev
->free_head
+ 1) % TW_Q_LENGTH
;
459 tw_dev
->state
[*request_id
] = TW_S_STARTED
;
460 } /* End twl_get_request_id() */
462 /* This function will free a request id */
463 static void twl_free_request_id(TW_Device_Extension
*tw_dev
, int request_id
)
465 tw_dev
->free_queue
[tw_dev
->free_tail
] = request_id
;
466 tw_dev
->state
[request_id
] = TW_S_FINISHED
;
467 tw_dev
->free_tail
= (tw_dev
->free_tail
+ 1) % TW_Q_LENGTH
;
468 } /* End twl_free_request_id() */
470 /* This function will complete an aen request from the isr */
471 static int twl_aen_complete(TW_Device_Extension
*tw_dev
, int request_id
)
473 TW_Command_Full
*full_command_packet
;
474 TW_Command
*command_packet
;
475 TW_Command_Apache_Header
*header
;
479 header
= (TW_Command_Apache_Header
*)tw_dev
->generic_buffer_virt
[request_id
];
480 tw_dev
->posted_request_count
--;
481 aen
= le16_to_cpu(header
->status_block
.error
);
482 full_command_packet
= tw_dev
->command_packet_virt
[request_id
];
483 command_packet
= &full_command_packet
->command
.oldcommand
;
485 /* First check for internal completion of set param for time sync */
486 if (TW_OP_OUT(command_packet
->opcode__sgloffset
) == TW_OP_SET_PARAM
) {
487 /* Keep reading the queue in case there are more aen's */
488 if (twl_aen_read_queue(tw_dev
, request_id
))
497 case TW_AEN_QUEUE_EMPTY
:
498 /* Quit reading the queue if this is the last one */
500 case TW_AEN_SYNC_TIME_WITH_HOST
:
501 twl_aen_sync_time(tw_dev
, request_id
);
505 twl_aen_queue_event(tw_dev
, header
);
507 /* If there are more aen's, keep reading the queue */
508 if (twl_aen_read_queue(tw_dev
, request_id
))
517 tw_dev
->state
[request_id
] = TW_S_COMPLETED
;
518 twl_free_request_id(tw_dev
, request_id
);
519 clear_bit(TW_IN_ATTENTION_LOOP
, &tw_dev
->flags
);
522 } /* End twl_aen_complete() */
524 /* This function will poll for a response */
525 static int twl_poll_response(TW_Device_Extension
*tw_dev
, int request_id
, int seconds
)
527 unsigned long before
;
537 if (sizeof(dma_addr_t
) > 4) {
538 regh
= readl(TWL_HOBQPH_REG_ADDR(tw_dev
));
539 regl
= readl(TWL_HOBQPL_REG_ADDR(tw_dev
));
540 mfa
= ((u64
)regh
<< 32) | regl
;
542 mfa
= readl(TWL_HOBQPL_REG_ADDR(tw_dev
));
546 if (TW_RESID_OUT(response
) == request_id
)
549 if (time_after(jiffies
, before
+ HZ
* seconds
))
557 } /* End twl_poll_response() */
559 /* This function will drain the aen queue */
560 static int twl_aen_drain_queue(TW_Device_Extension
*tw_dev
, int no_check_reset
)
563 char cdb
[TW_MAX_CDB_LEN
];
564 TW_SG_Entry_ISO sglist
[1];
565 int finished
= 0, count
= 0;
566 TW_Command_Full
*full_command_packet
;
567 TW_Command_Apache_Header
*header
;
569 int first_reset
= 0, queue
= 0, retval
= 1;
576 full_command_packet
= tw_dev
->command_packet_virt
[request_id
];
577 memset(full_command_packet
, 0, sizeof(TW_Command_Full
));
580 memset(&cdb
, 0, TW_MAX_CDB_LEN
);
581 cdb
[0] = REQUEST_SENSE
; /* opcode */
582 cdb
[4] = TW_ALLOCATION_LENGTH
; /* allocation length */
584 /* Initialize sglist */
585 memset(&sglist
, 0, sizeof(TW_SG_Entry_ISO
));
586 sglist
[0].length
= TW_SECTOR_SIZE
;
587 sglist
[0].address
= tw_dev
->generic_buffer_phys
[request_id
];
589 /* Mark internal command */
590 tw_dev
->srb
[request_id
] = NULL
;
593 /* Send command to the board */
594 if (twl_scsiop_execute_scsi(tw_dev
, request_id
, cdb
, 1, sglist
)) {
595 TW_PRINTK(tw_dev
->host
, TW_DRIVER
, 0x3, "Error posting request sense");
599 /* Now poll for completion */
600 if (twl_poll_response(tw_dev
, request_id
, 30)) {
601 TW_PRINTK(tw_dev
->host
, TW_DRIVER
, 0x4, "No valid response while draining AEN queue");
602 tw_dev
->posted_request_count
--;
606 tw_dev
->posted_request_count
--;
607 header
= (TW_Command_Apache_Header
*)tw_dev
->generic_buffer_virt
[request_id
];
608 aen
= le16_to_cpu(header
->status_block
.error
);
613 case TW_AEN_QUEUE_EMPTY
:
614 if (first_reset
!= 1)
619 case TW_AEN_SOFT_RESET
:
620 if (first_reset
== 0)
625 case TW_AEN_SYNC_TIME_WITH_HOST
:
631 /* Now queue an event info */
633 twl_aen_queue_event(tw_dev
, header
);
634 } while ((finished
== 0) && (count
< TW_MAX_AEN_DRAIN
));
636 if (count
== TW_MAX_AEN_DRAIN
)
641 tw_dev
->state
[request_id
] = TW_S_INITIAL
;
643 } /* End twl_aen_drain_queue() */
645 /* This function will allocate memory and check if it is correctly aligned */
646 static int twl_allocate_memory(TW_Device_Extension
*tw_dev
, int size
, int which
)
649 dma_addr_t dma_handle
;
650 unsigned long *cpu_addr
;
653 cpu_addr
= pci_zalloc_consistent(tw_dev
->tw_pci_dev
, size
* TW_Q_LENGTH
,
656 TW_PRINTK(tw_dev
->host
, TW_DRIVER
, 0x5, "Memory allocation failed");
660 for (i
= 0; i
< TW_Q_LENGTH
; i
++) {
663 tw_dev
->command_packet_phys
[i
] = dma_handle
+(i
*size
);
664 tw_dev
->command_packet_virt
[i
] = (TW_Command_Full
*)((unsigned char *)cpu_addr
+ (i
*size
));
667 tw_dev
->generic_buffer_phys
[i
] = dma_handle
+(i
*size
);
668 tw_dev
->generic_buffer_virt
[i
] = (unsigned long *)((unsigned char *)cpu_addr
+ (i
*size
));
671 tw_dev
->sense_buffer_phys
[i
] = dma_handle
+(i
*size
);
672 tw_dev
->sense_buffer_virt
[i
] = (TW_Command_Apache_Header
*)((unsigned char *)cpu_addr
+ (i
*size
));
679 } /* End twl_allocate_memory() */
681 /* This function will load the request id and various sgls for ioctls */
682 static void twl_load_sgl(TW_Device_Extension
*tw_dev
, TW_Command_Full
*full_command_packet
, int request_id
, dma_addr_t dma_handle
, int length
)
684 TW_Command
*oldcommand
;
685 TW_Command_Apache
*newcommand
;
686 TW_SG_Entry_ISO
*sgl
;
687 unsigned int pae
= 0;
689 if ((sizeof(long) < 8) && (sizeof(dma_addr_t
) > 4))
692 if (TW_OP_OUT(full_command_packet
->command
.newcommand
.opcode__reserved
) == TW_OP_EXECUTE_SCSI
) {
693 newcommand
= &full_command_packet
->command
.newcommand
;
694 newcommand
->request_id__lunl
=
695 cpu_to_le16(TW_REQ_LUN_IN(TW_LUN_OUT(newcommand
->request_id__lunl
), request_id
));
697 newcommand
->sg_list
[0].address
= TW_CPU_TO_SGL(dma_handle
+ sizeof(TW_Ioctl_Buf_Apache
) - 1);
698 newcommand
->sg_list
[0].length
= TW_CPU_TO_SGL(length
);
700 newcommand
->sgl_entries__lunh
=
701 cpu_to_le16(TW_REQ_LUN_IN(TW_LUN_OUT(newcommand
->sgl_entries__lunh
), length
? 1 : 0));
703 oldcommand
= &full_command_packet
->command
.oldcommand
;
704 oldcommand
->request_id
= request_id
;
706 if (TW_SGL_OUT(oldcommand
->opcode__sgloffset
)) {
707 /* Load the sg list */
708 sgl
= (TW_SG_Entry_ISO
*)((u32
*)oldcommand
+oldcommand
->size
- (sizeof(TW_SG_Entry_ISO
)/4) + pae
+ (sizeof(dma_addr_t
) > 4 ? 1 : 0));
709 sgl
->address
= TW_CPU_TO_SGL(dma_handle
+ sizeof(TW_Ioctl_Buf_Apache
) - 1);
710 sgl
->length
= TW_CPU_TO_SGL(length
);
711 oldcommand
->size
+= pae
;
712 oldcommand
->size
+= sizeof(dma_addr_t
) > 4 ? 1 : 0;
715 } /* End twl_load_sgl() */
717 /* This function handles ioctl for the character device
718 This interface is used by smartmontools open source software */
719 static long twl_chrdev_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
722 unsigned long *cpu_addr
, data_buffer_length_adjusted
= 0, flags
= 0;
723 dma_addr_t dma_handle
;
725 TW_Ioctl_Driver_Command driver_command
;
726 struct inode
*inode
= file_inode(file
);
727 TW_Ioctl_Buf_Apache
*tw_ioctl
;
728 TW_Command_Full
*full_command_packet
;
729 TW_Device_Extension
*tw_dev
= twl_device_extension_list
[iminor(inode
)];
730 int retval
= -EFAULT
;
731 void __user
*argp
= (void __user
*)arg
;
733 mutex_lock(&twl_chrdev_mutex
);
735 /* Only let one of these through at a time */
736 if (mutex_lock_interruptible(&tw_dev
->ioctl_lock
)) {
741 /* First copy down the driver command */
742 if (copy_from_user(&driver_command
, argp
, sizeof(TW_Ioctl_Driver_Command
)))
745 /* Check data buffer size */
746 if (driver_command
.buffer_length
> TW_MAX_SECTORS
* 2048) {
751 /* Hardware can only do multiple of 512 byte transfers */
752 data_buffer_length_adjusted
= (driver_command
.buffer_length
+ 511) & ~511;
754 /* Now allocate ioctl buf memory */
755 cpu_addr
= dma_alloc_coherent(&tw_dev
->tw_pci_dev
->dev
, data_buffer_length_adjusted
+sizeof(TW_Ioctl_Buf_Apache
) - 1, &dma_handle
, GFP_KERNEL
);
761 tw_ioctl
= (TW_Ioctl_Buf_Apache
*)cpu_addr
;
763 /* Now copy down the entire ioctl */
764 if (copy_from_user(tw_ioctl
, argp
, driver_command
.buffer_length
+ sizeof(TW_Ioctl_Buf_Apache
) - 1))
767 /* See which ioctl we are doing */
769 case TW_IOCTL_FIRMWARE_PASS_THROUGH
:
770 spin_lock_irqsave(tw_dev
->host
->host_lock
, flags
);
771 twl_get_request_id(tw_dev
, &request_id
);
773 /* Flag internal command */
774 tw_dev
->srb
[request_id
] = NULL
;
776 /* Flag chrdev ioctl */
777 tw_dev
->chrdev_request_id
= request_id
;
779 full_command_packet
= (TW_Command_Full
*)&tw_ioctl
->firmware_command
;
781 /* Load request id and sglist for both command types */
782 twl_load_sgl(tw_dev
, full_command_packet
, request_id
, dma_handle
, data_buffer_length_adjusted
);
784 memcpy(tw_dev
->command_packet_virt
[request_id
], &(tw_ioctl
->firmware_command
), sizeof(TW_Command_Full
));
786 /* Now post the command packet to the controller */
787 twl_post_command_packet(tw_dev
, request_id
);
788 spin_unlock_irqrestore(tw_dev
->host
->host_lock
, flags
);
790 timeout
= TW_IOCTL_CHRDEV_TIMEOUT
*HZ
;
792 /* Now wait for command to complete */
793 timeout
= wait_event_timeout(tw_dev
->ioctl_wqueue
, tw_dev
->chrdev_request_id
== TW_IOCTL_CHRDEV_FREE
, timeout
);
795 /* We timed out, and didn't get an interrupt */
796 if (tw_dev
->chrdev_request_id
!= TW_IOCTL_CHRDEV_FREE
) {
797 /* Now we need to reset the board */
798 printk(KERN_WARNING
"3w-sas: scsi%d: WARNING: (0x%02X:0x%04X): Character ioctl (0x%x) timed out, resetting card.\n",
799 tw_dev
->host
->host_no
, TW_DRIVER
, 0x6,
802 twl_reset_device_extension(tw_dev
, 1);
806 /* Now copy in the command packet response */
807 memcpy(&(tw_ioctl
->firmware_command
), tw_dev
->command_packet_virt
[request_id
], sizeof(TW_Command_Full
));
809 /* Now complete the io */
810 spin_lock_irqsave(tw_dev
->host
->host_lock
, flags
);
811 tw_dev
->posted_request_count
--;
812 tw_dev
->state
[request_id
] = TW_S_COMPLETED
;
813 twl_free_request_id(tw_dev
, request_id
);
814 spin_unlock_irqrestore(tw_dev
->host
->host_lock
, flags
);
821 /* Now copy the entire response to userspace */
822 if (copy_to_user(argp
, tw_ioctl
, sizeof(TW_Ioctl_Buf_Apache
) + driver_command
.buffer_length
- 1) == 0)
825 /* Now free ioctl buf memory */
826 dma_free_coherent(&tw_dev
->tw_pci_dev
->dev
, data_buffer_length_adjusted
+sizeof(TW_Ioctl_Buf_Apache
) - 1, cpu_addr
, dma_handle
);
828 mutex_unlock(&tw_dev
->ioctl_lock
);
830 mutex_unlock(&twl_chrdev_mutex
);
832 } /* End twl_chrdev_ioctl() */
834 /* This function handles open for the character device */
835 static int twl_chrdev_open(struct inode
*inode
, struct file
*file
)
837 unsigned int minor_number
;
838 int retval
= -ENODEV
;
840 if (!capable(CAP_SYS_ADMIN
)) {
845 minor_number
= iminor(inode
);
846 if (minor_number
>= twl_device_extension_count
)
851 } /* End twl_chrdev_open() */
853 /* File operations struct for character device */
854 static const struct file_operations twl_fops
= {
855 .owner
= THIS_MODULE
,
856 .unlocked_ioctl
= twl_chrdev_ioctl
,
857 .open
= twl_chrdev_open
,
859 .llseek
= noop_llseek
,
862 /* This function passes sense data from firmware to scsi layer */
863 static int twl_fill_sense(TW_Device_Extension
*tw_dev
, int i
, int request_id
, int copy_sense
, int print_host
)
865 TW_Command_Apache_Header
*header
;
866 TW_Command_Full
*full_command_packet
;
867 unsigned short error
;
871 header
= tw_dev
->sense_buffer_virt
[i
];
872 full_command_packet
= tw_dev
->command_packet_virt
[request_id
];
874 /* Get embedded firmware error string */
875 error_str
= &(header
->err_specific_desc
[strlen(header
->err_specific_desc
) + 1]);
877 /* Don't print error for Logical unit not supported during rollcall */
878 error
= le16_to_cpu(header
->status_block
.error
);
879 if ((error
!= TW_ERROR_LOGICAL_UNIT_NOT_SUPPORTED
) && (error
!= TW_ERROR_UNIT_OFFLINE
) && (error
!= TW_ERROR_INVALID_FIELD_IN_CDB
)) {
881 printk(KERN_WARNING
"3w-sas: scsi%d: ERROR: (0x%02X:0x%04X): %s:%s.\n",
882 tw_dev
->host
->host_no
,
883 TW_MESSAGE_SOURCE_CONTROLLER_ERROR
,
884 header
->status_block
.error
,
886 header
->err_specific_desc
);
888 printk(KERN_WARNING
"3w-sas: ERROR: (0x%02X:0x%04X): %s:%s.\n",
889 TW_MESSAGE_SOURCE_CONTROLLER_ERROR
,
890 header
->status_block
.error
,
892 header
->err_specific_desc
);
896 memcpy(tw_dev
->srb
[request_id
]->sense_buffer
, header
->sense_data
, TW_SENSE_DATA_LENGTH
);
897 tw_dev
->srb
[request_id
]->result
= (full_command_packet
->command
.newcommand
.status
<< 1);
902 } /* End twl_fill_sense() */
904 /* This function will free up device extension resources */
905 static void twl_free_device_extension(TW_Device_Extension
*tw_dev
)
907 if (tw_dev
->command_packet_virt
[0])
908 pci_free_consistent(tw_dev
->tw_pci_dev
,
909 sizeof(TW_Command_Full
)*TW_Q_LENGTH
,
910 tw_dev
->command_packet_virt
[0],
911 tw_dev
->command_packet_phys
[0]);
913 if (tw_dev
->generic_buffer_virt
[0])
914 pci_free_consistent(tw_dev
->tw_pci_dev
,
915 TW_SECTOR_SIZE
*TW_Q_LENGTH
,
916 tw_dev
->generic_buffer_virt
[0],
917 tw_dev
->generic_buffer_phys
[0]);
919 if (tw_dev
->sense_buffer_virt
[0])
920 pci_free_consistent(tw_dev
->tw_pci_dev
,
921 sizeof(TW_Command_Apache_Header
)*
923 tw_dev
->sense_buffer_virt
[0],
924 tw_dev
->sense_buffer_phys
[0]);
926 kfree(tw_dev
->event_queue
[0]);
927 } /* End twl_free_device_extension() */
929 /* This function will get parameter table entries from the firmware */
930 static void *twl_get_param(TW_Device_Extension
*tw_dev
, int request_id
, int table_id
, int parameter_id
, int parameter_size_bytes
)
932 TW_Command_Full
*full_command_packet
;
933 TW_Command
*command_packet
;
934 TW_Param_Apache
*param
;
937 /* Setup the command packet */
938 full_command_packet
= tw_dev
->command_packet_virt
[request_id
];
939 memset(full_command_packet
, 0, sizeof(TW_Command_Full
));
940 command_packet
= &full_command_packet
->command
.oldcommand
;
942 command_packet
->opcode__sgloffset
= TW_OPSGL_IN(2, TW_OP_GET_PARAM
);
943 command_packet
->size
= TW_COMMAND_SIZE
;
944 command_packet
->request_id
= request_id
;
945 command_packet
->byte6_offset
.block_count
= cpu_to_le16(1);
947 /* Now setup the param */
948 param
= (TW_Param_Apache
*)tw_dev
->generic_buffer_virt
[request_id
];
949 memset(param
, 0, TW_SECTOR_SIZE
);
950 param
->table_id
= cpu_to_le16(table_id
| 0x8000);
951 param
->parameter_id
= cpu_to_le16(parameter_id
);
952 param
->parameter_size_bytes
= cpu_to_le16(parameter_size_bytes
);
954 command_packet
->byte8_offset
.param
.sgl
[0].address
= TW_CPU_TO_SGL(tw_dev
->generic_buffer_phys
[request_id
]);
955 command_packet
->byte8_offset
.param
.sgl
[0].length
= TW_CPU_TO_SGL(TW_SECTOR_SIZE
);
957 /* Post the command packet to the board */
958 twl_post_command_packet(tw_dev
, request_id
);
960 /* Poll for completion */
961 if (twl_poll_response(tw_dev
, request_id
, 30))
962 TW_PRINTK(tw_dev
->host
, TW_DRIVER
, 0x7, "No valid response during get param")
964 retval
= (void *)&(param
->data
[0]);
966 tw_dev
->posted_request_count
--;
967 tw_dev
->state
[request_id
] = TW_S_INITIAL
;
970 } /* End twl_get_param() */
972 /* This function will send an initconnection command to controller */
973 static int twl_initconnection(TW_Device_Extension
*tw_dev
, int message_credits
,
974 u32 set_features
, unsigned short current_fw_srl
,
975 unsigned short current_fw_arch_id
,
976 unsigned short current_fw_branch
,
977 unsigned short current_fw_build
,
978 unsigned short *fw_on_ctlr_srl
,
979 unsigned short *fw_on_ctlr_arch_id
,
980 unsigned short *fw_on_ctlr_branch
,
981 unsigned short *fw_on_ctlr_build
,
982 u32
*init_connect_result
)
984 TW_Command_Full
*full_command_packet
;
985 TW_Initconnect
*tw_initconnect
;
986 int request_id
= 0, retval
= 1;
988 /* Initialize InitConnection command packet */
989 full_command_packet
= tw_dev
->command_packet_virt
[request_id
];
990 memset(full_command_packet
, 0, sizeof(TW_Command_Full
));
991 full_command_packet
->header
.header_desc
.size_header
= 128;
993 tw_initconnect
= (TW_Initconnect
*)&full_command_packet
->command
.oldcommand
;
994 tw_initconnect
->opcode__reserved
= TW_OPRES_IN(0, TW_OP_INIT_CONNECTION
);
995 tw_initconnect
->request_id
= request_id
;
996 tw_initconnect
->message_credits
= cpu_to_le16(message_credits
);
997 tw_initconnect
->features
= set_features
;
999 /* Turn on 64-bit sgl support if we need to */
1000 tw_initconnect
->features
|= sizeof(dma_addr_t
) > 4 ? 1 : 0;
1002 tw_initconnect
->features
= cpu_to_le32(tw_initconnect
->features
);
1004 if (set_features
& TW_EXTENDED_INIT_CONNECT
) {
1005 tw_initconnect
->size
= TW_INIT_COMMAND_PACKET_SIZE_EXTENDED
;
1006 tw_initconnect
->fw_srl
= cpu_to_le16(current_fw_srl
);
1007 tw_initconnect
->fw_arch_id
= cpu_to_le16(current_fw_arch_id
);
1008 tw_initconnect
->fw_branch
= cpu_to_le16(current_fw_branch
);
1009 tw_initconnect
->fw_build
= cpu_to_le16(current_fw_build
);
1011 tw_initconnect
->size
= TW_INIT_COMMAND_PACKET_SIZE
;
1013 /* Send command packet to the board */
1014 twl_post_command_packet(tw_dev
, request_id
);
1016 /* Poll for completion */
1017 if (twl_poll_response(tw_dev
, request_id
, 30)) {
1018 TW_PRINTK(tw_dev
->host
, TW_DRIVER
, 0x8, "No valid response during init connection");
1020 if (set_features
& TW_EXTENDED_INIT_CONNECT
) {
1021 *fw_on_ctlr_srl
= le16_to_cpu(tw_initconnect
->fw_srl
);
1022 *fw_on_ctlr_arch_id
= le16_to_cpu(tw_initconnect
->fw_arch_id
);
1023 *fw_on_ctlr_branch
= le16_to_cpu(tw_initconnect
->fw_branch
);
1024 *fw_on_ctlr_build
= le16_to_cpu(tw_initconnect
->fw_build
);
1025 *init_connect_result
= le32_to_cpu(tw_initconnect
->result
);
1030 tw_dev
->posted_request_count
--;
1031 tw_dev
->state
[request_id
] = TW_S_INITIAL
;
1034 } /* End twl_initconnection() */
1036 /* This function will initialize the fields of a device extension */
1037 static int twl_initialize_device_extension(TW_Device_Extension
*tw_dev
)
1041 /* Initialize command packet buffers */
1042 if (twl_allocate_memory(tw_dev
, sizeof(TW_Command_Full
), 0)) {
1043 TW_PRINTK(tw_dev
->host
, TW_DRIVER
, 0x9, "Command packet memory allocation failed");
1047 /* Initialize generic buffer */
1048 if (twl_allocate_memory(tw_dev
, TW_SECTOR_SIZE
, 1)) {
1049 TW_PRINTK(tw_dev
->host
, TW_DRIVER
, 0xa, "Generic memory allocation failed");
1053 /* Allocate sense buffers */
1054 if (twl_allocate_memory(tw_dev
, sizeof(TW_Command_Apache_Header
), 2)) {
1055 TW_PRINTK(tw_dev
->host
, TW_DRIVER
, 0xb, "Sense buffer allocation failed");
1059 /* Allocate event info space */
1060 tw_dev
->event_queue
[0] = kcalloc(TW_Q_LENGTH
, sizeof(TW_Event
), GFP_KERNEL
);
1061 if (!tw_dev
->event_queue
[0]) {
1062 TW_PRINTK(tw_dev
->host
, TW_DRIVER
, 0xc, "Event info memory allocation failed");
1066 for (i
= 0; i
< TW_Q_LENGTH
; i
++) {
1067 tw_dev
->event_queue
[i
] = (TW_Event
*)((unsigned char *)tw_dev
->event_queue
[0] + (i
* sizeof(TW_Event
)));
1068 tw_dev
->free_queue
[i
] = i
;
1069 tw_dev
->state
[i
] = TW_S_INITIAL
;
1072 tw_dev
->free_head
= TW_Q_START
;
1073 tw_dev
->free_tail
= TW_Q_START
;
1074 tw_dev
->error_sequence_id
= 1;
1075 tw_dev
->chrdev_request_id
= TW_IOCTL_CHRDEV_FREE
;
1077 mutex_init(&tw_dev
->ioctl_lock
);
1078 init_waitqueue_head(&tw_dev
->ioctl_wqueue
);
1083 } /* End twl_initialize_device_extension() */
1085 /* This function will handle attention interrupts */
1086 static int twl_handle_attention_interrupt(TW_Device_Extension
*tw_dev
)
1089 u32 request_id
, doorbell
;
1091 /* Read doorbell status */
1092 doorbell
= readl(TWL_HOBDB_REG_ADDR(tw_dev
));
1094 /* Check for controller errors */
1095 if (doorbell
& TWL_DOORBELL_CONTROLLER_ERROR
) {
1096 TW_PRINTK(tw_dev
->host
, TW_DRIVER
, 0xd, "Microcontroller Error: clearing");
1100 /* Check if we need to perform an AEN drain */
1101 if (doorbell
& TWL_DOORBELL_ATTENTION_INTERRUPT
) {
1102 if (!(test_and_set_bit(TW_IN_ATTENTION_LOOP
, &tw_dev
->flags
))) {
1103 twl_get_request_id(tw_dev
, &request_id
);
1104 if (twl_aen_read_queue(tw_dev
, request_id
)) {
1105 tw_dev
->state
[request_id
] = TW_S_COMPLETED
;
1106 twl_free_request_id(tw_dev
, request_id
);
1107 clear_bit(TW_IN_ATTENTION_LOOP
, &tw_dev
->flags
);
1114 /* Clear doorbell interrupt */
1115 TWL_CLEAR_DB_INTERRUPT(tw_dev
);
1117 /* Make sure the clear was flushed by reading it back */
1118 readl(TWL_HOBDBC_REG_ADDR(tw_dev
));
1121 } /* End twl_handle_attention_interrupt() */
1123 /* Interrupt service routine */
1124 static irqreturn_t
twl_interrupt(int irq
, void *dev_instance
)
1126 TW_Device_Extension
*tw_dev
= (TW_Device_Extension
*)dev_instance
;
1127 int i
, handled
= 0, error
= 0;
1129 u32 reg
, regl
, regh
, response
, request_id
= 0;
1130 struct scsi_cmnd
*cmd
;
1131 TW_Command_Full
*full_command_packet
;
1133 spin_lock(tw_dev
->host
->host_lock
);
1135 /* Read host interrupt status */
1136 reg
= readl(TWL_HISTAT_REG_ADDR(tw_dev
));
1138 /* Check if this is our interrupt, otherwise bail */
1139 if (!(reg
& TWL_HISTATUS_VALID_INTERRUPT
))
1140 goto twl_interrupt_bail
;
1144 /* If we are resetting, bail */
1145 if (test_bit(TW_IN_RESET
, &tw_dev
->flags
))
1146 goto twl_interrupt_bail
;
1148 /* Attention interrupt */
1149 if (reg
& TWL_HISTATUS_ATTENTION_INTERRUPT
) {
1150 if (twl_handle_attention_interrupt(tw_dev
)) {
1151 TWL_MASK_INTERRUPTS(tw_dev
);
1152 goto twl_interrupt_bail
;
1156 /* Response interrupt */
1157 while (reg
& TWL_HISTATUS_RESPONSE_INTERRUPT
) {
1158 if (sizeof(dma_addr_t
) > 4) {
1159 regh
= readl(TWL_HOBQPH_REG_ADDR(tw_dev
));
1160 regl
= readl(TWL_HOBQPL_REG_ADDR(tw_dev
));
1161 mfa
= ((u64
)regh
<< 32) | regl
;
1163 mfa
= readl(TWL_HOBQPL_REG_ADDR(tw_dev
));
1166 response
= (u32
)mfa
;
1168 /* Check for command packet error */
1169 if (!TW_NOTMFA_OUT(response
)) {
1170 for (i
=0;i
<TW_Q_LENGTH
;i
++) {
1171 if (tw_dev
->sense_buffer_phys
[i
] == mfa
) {
1172 request_id
= le16_to_cpu(tw_dev
->sense_buffer_virt
[i
]->header_desc
.request_id
);
1173 if (tw_dev
->srb
[request_id
] != NULL
)
1174 error
= twl_fill_sense(tw_dev
, i
, request_id
, 1, 1);
1176 /* Skip ioctl error prints */
1177 if (request_id
!= tw_dev
->chrdev_request_id
)
1178 error
= twl_fill_sense(tw_dev
, i
, request_id
, 0, 1);
1180 memcpy(tw_dev
->command_packet_virt
[request_id
], tw_dev
->sense_buffer_virt
[i
], sizeof(TW_Command_Apache_Header
));
1183 /* Now re-post the sense buffer */
1184 writel((u32
)((u64
)tw_dev
->sense_buffer_phys
[i
] >> 32), TWL_HOBQPH_REG_ADDR(tw_dev
));
1185 writel((u32
)tw_dev
->sense_buffer_phys
[i
], TWL_HOBQPL_REG_ADDR(tw_dev
));
1190 request_id
= TW_RESID_OUT(response
);
1192 full_command_packet
= tw_dev
->command_packet_virt
[request_id
];
1194 /* Check for correct state */
1195 if (tw_dev
->state
[request_id
] != TW_S_POSTED
) {
1196 if (tw_dev
->srb
[request_id
] != NULL
) {
1197 TW_PRINTK(tw_dev
->host
, TW_DRIVER
, 0xe, "Received a request id that wasn't posted");
1198 TWL_MASK_INTERRUPTS(tw_dev
);
1199 goto twl_interrupt_bail
;
1203 /* Check for internal command completion */
1204 if (tw_dev
->srb
[request_id
] == NULL
) {
1205 if (request_id
!= tw_dev
->chrdev_request_id
) {
1206 if (twl_aen_complete(tw_dev
, request_id
))
1207 TW_PRINTK(tw_dev
->host
, TW_DRIVER
, 0xf, "Error completing AEN during attention interrupt");
1209 tw_dev
->chrdev_request_id
= TW_IOCTL_CHRDEV_FREE
;
1210 wake_up(&tw_dev
->ioctl_wqueue
);
1213 cmd
= tw_dev
->srb
[request_id
];
1216 cmd
->result
= (DID_OK
<< 16);
1218 /* Report residual bytes for single sgl */
1219 if ((scsi_sg_count(cmd
) <= 1) && (full_command_packet
->command
.newcommand
.status
== 0)) {
1220 if (full_command_packet
->command
.newcommand
.sg_list
[0].length
< scsi_bufflen(tw_dev
->srb
[request_id
]))
1221 scsi_set_resid(cmd
, scsi_bufflen(cmd
) - full_command_packet
->command
.newcommand
.sg_list
[0].length
);
1224 /* Now complete the io */
1225 scsi_dma_unmap(cmd
);
1226 cmd
->scsi_done(cmd
);
1227 tw_dev
->state
[request_id
] = TW_S_COMPLETED
;
1228 twl_free_request_id(tw_dev
, request_id
);
1229 tw_dev
->posted_request_count
--;
1232 /* Check for another response interrupt */
1233 reg
= readl(TWL_HISTAT_REG_ADDR(tw_dev
));
1237 spin_unlock(tw_dev
->host
->host_lock
);
1238 return IRQ_RETVAL(handled
);
1239 } /* End twl_interrupt() */
1241 /* This function will poll for a register change */
1242 static int twl_poll_register(TW_Device_Extension
*tw_dev
, void *reg
, u32 value
, u32 result
, int seconds
)
1244 unsigned long before
;
1248 reg_value
= readl(reg
);
1251 while ((reg_value
& value
) != result
) {
1252 reg_value
= readl(reg
);
1253 if (time_after(jiffies
, before
+ HZ
* seconds
))
1260 } /* End twl_poll_register() */
1262 /* This function will reset a controller */
1263 static int twl_reset_sequence(TW_Device_Extension
*tw_dev
, int soft_reset
)
1268 unsigned short fw_on_ctlr_srl
= 0, fw_on_ctlr_arch_id
= 0;
1269 unsigned short fw_on_ctlr_branch
= 0, fw_on_ctlr_build
= 0;
1270 u32 init_connect_result
= 0;
1272 int do_soft_reset
= soft_reset
;
1274 while (tries
< TW_MAX_RESET_TRIES
) {
1275 /* Do a soft reset if one is needed */
1276 if (do_soft_reset
) {
1277 TWL_SOFT_RESET(tw_dev
);
1279 /* Make sure controller is in a good state */
1280 if (twl_poll_register(tw_dev
, TWL_SCRPD3_REG_ADDR(tw_dev
), TWL_CONTROLLER_READY
, 0x0, 30)) {
1281 TW_PRINTK(tw_dev
->host
, TW_DRIVER
, 0x10, "Controller never went non-ready during reset sequence");
1285 if (twl_poll_register(tw_dev
, TWL_SCRPD3_REG_ADDR(tw_dev
), TWL_CONTROLLER_READY
, TWL_CONTROLLER_READY
, 60)) {
1286 TW_PRINTK(tw_dev
->host
, TW_DRIVER
, 0x11, "Controller not ready during reset sequence");
1293 if (twl_initconnection(tw_dev
, TW_INIT_MESSAGE_CREDITS
,
1294 TW_EXTENDED_INIT_CONNECT
, TW_CURRENT_DRIVER_SRL
,
1295 TW_9750_ARCH_ID
, TW_CURRENT_DRIVER_BRANCH
,
1296 TW_CURRENT_DRIVER_BUILD
, &fw_on_ctlr_srl
,
1297 &fw_on_ctlr_arch_id
, &fw_on_ctlr_branch
,
1298 &fw_on_ctlr_build
, &init_connect_result
)) {
1299 TW_PRINTK(tw_dev
->host
, TW_DRIVER
, 0x12, "Initconnection failed while checking SRL");
1305 /* Load sense buffers */
1306 while (i
< TW_Q_LENGTH
) {
1307 writel((u32
)((u64
)tw_dev
->sense_buffer_phys
[i
] >> 32), TWL_HOBQPH_REG_ADDR(tw_dev
));
1308 writel((u32
)tw_dev
->sense_buffer_phys
[i
], TWL_HOBQPL_REG_ADDR(tw_dev
));
1310 /* Check status for over-run after each write */
1311 status
= readl(TWL_STATUS_REG_ADDR(tw_dev
));
1312 if (!(status
& TWL_STATUS_OVERRUN_SUBMIT
))
1316 /* Now check status */
1317 status
= readl(TWL_STATUS_REG_ADDR(tw_dev
));
1319 TW_PRINTK(tw_dev
->host
, TW_DRIVER
, 0x13, "Bad controller status after loading sense buffers");
1325 /* Drain the AEN queue */
1326 if (twl_aen_drain_queue(tw_dev
, soft_reset
)) {
1327 TW_PRINTK(tw_dev
->host
, TW_DRIVER
, 0x14, "AEN drain failed during reset sequence");
1333 /* Load rest of compatibility struct */
1334 strncpy(tw_dev
->tw_compat_info
.driver_version
, TW_DRIVER_VERSION
, strlen(TW_DRIVER_VERSION
));
1335 tw_dev
->tw_compat_info
.driver_srl_high
= TW_CURRENT_DRIVER_SRL
;
1336 tw_dev
->tw_compat_info
.driver_branch_high
= TW_CURRENT_DRIVER_BRANCH
;
1337 tw_dev
->tw_compat_info
.driver_build_high
= TW_CURRENT_DRIVER_BUILD
;
1338 tw_dev
->tw_compat_info
.driver_srl_low
= TW_BASE_FW_SRL
;
1339 tw_dev
->tw_compat_info
.driver_branch_low
= TW_BASE_FW_BRANCH
;
1340 tw_dev
->tw_compat_info
.driver_build_low
= TW_BASE_FW_BUILD
;
1341 tw_dev
->tw_compat_info
.fw_on_ctlr_srl
= fw_on_ctlr_srl
;
1342 tw_dev
->tw_compat_info
.fw_on_ctlr_branch
= fw_on_ctlr_branch
;
1343 tw_dev
->tw_compat_info
.fw_on_ctlr_build
= fw_on_ctlr_build
;
1345 /* If we got here, controller is in a good state */
1351 } /* End twl_reset_sequence() */
1353 /* This function will reset a device extension */
1354 static int twl_reset_device_extension(TW_Device_Extension
*tw_dev
, int ioctl_reset
)
1356 int i
= 0, retval
= 1;
1357 unsigned long flags
= 0;
1359 /* Block SCSI requests while we are resetting */
1361 scsi_block_requests(tw_dev
->host
);
1363 set_bit(TW_IN_RESET
, &tw_dev
->flags
);
1364 TWL_MASK_INTERRUPTS(tw_dev
);
1365 TWL_CLEAR_DB_INTERRUPT(tw_dev
);
1367 spin_lock_irqsave(tw_dev
->host
->host_lock
, flags
);
1369 /* Abort all requests that are in progress */
1370 for (i
= 0; i
< TW_Q_LENGTH
; i
++) {
1371 if ((tw_dev
->state
[i
] != TW_S_FINISHED
) &&
1372 (tw_dev
->state
[i
] != TW_S_INITIAL
) &&
1373 (tw_dev
->state
[i
] != TW_S_COMPLETED
)) {
1374 struct scsi_cmnd
*cmd
= tw_dev
->srb
[i
];
1377 cmd
->result
= (DID_RESET
<< 16);
1378 scsi_dma_unmap(cmd
);
1379 cmd
->scsi_done(cmd
);
1384 /* Reset queues and counts */
1385 for (i
= 0; i
< TW_Q_LENGTH
; i
++) {
1386 tw_dev
->free_queue
[i
] = i
;
1387 tw_dev
->state
[i
] = TW_S_INITIAL
;
1389 tw_dev
->free_head
= TW_Q_START
;
1390 tw_dev
->free_tail
= TW_Q_START
;
1391 tw_dev
->posted_request_count
= 0;
1393 spin_unlock_irqrestore(tw_dev
->host
->host_lock
, flags
);
1395 if (twl_reset_sequence(tw_dev
, 1))
1398 TWL_UNMASK_INTERRUPTS(tw_dev
);
1400 clear_bit(TW_IN_RESET
, &tw_dev
->flags
);
1401 tw_dev
->chrdev_request_id
= TW_IOCTL_CHRDEV_FREE
;
1406 scsi_unblock_requests(tw_dev
->host
);
1408 } /* End twl_reset_device_extension() */
1410 /* This funciton returns unit geometry in cylinders/heads/sectors */
1411 static int twl_scsi_biosparam(struct scsi_device
*sdev
, struct block_device
*bdev
, sector_t capacity
, int geom
[])
1414 TW_Device_Extension
*tw_dev
;
1416 tw_dev
= (TW_Device_Extension
*)sdev
->host
->hostdata
;
1418 if (capacity
>= 0x200000) {
1428 geom
[2] = sector_div(capacity
, heads
* sectors
); /* cylinders */
1431 } /* End twl_scsi_biosparam() */
1433 /* This is the new scsi eh reset function */
1434 static int twl_scsi_eh_reset(struct scsi_cmnd
*SCpnt
)
1436 TW_Device_Extension
*tw_dev
= NULL
;
1437 int retval
= FAILED
;
1439 tw_dev
= (TW_Device_Extension
*)SCpnt
->device
->host
->hostdata
;
1441 tw_dev
->num_resets
++;
1443 sdev_printk(KERN_WARNING
, SCpnt
->device
,
1444 "WARNING: (0x%02X:0x%04X): Command (0x%x) timed out, resetting card.\n",
1445 TW_DRIVER
, 0x2c, SCpnt
->cmnd
[0]);
1447 /* Make sure we are not issuing an ioctl or resetting from ioctl */
1448 mutex_lock(&tw_dev
->ioctl_lock
);
1450 /* Now reset the card and some of the device extension data */
1451 if (twl_reset_device_extension(tw_dev
, 0)) {
1452 TW_PRINTK(tw_dev
->host
, TW_DRIVER
, 0x15, "Controller reset failed during scsi host reset");
1458 mutex_unlock(&tw_dev
->ioctl_lock
);
1460 } /* End twl_scsi_eh_reset() */
1462 /* This is the main scsi queue function to handle scsi opcodes */
1463 static int twl_scsi_queue_lck(struct scsi_cmnd
*SCpnt
, void (*done
)(struct scsi_cmnd
*))
1465 int request_id
, retval
;
1466 TW_Device_Extension
*tw_dev
= (TW_Device_Extension
*)SCpnt
->device
->host
->hostdata
;
1468 /* If we are resetting due to timed out ioctl, report as busy */
1469 if (test_bit(TW_IN_RESET
, &tw_dev
->flags
)) {
1470 retval
= SCSI_MLQUEUE_HOST_BUSY
;
1474 /* Save done function into scsi_cmnd struct */
1475 SCpnt
->scsi_done
= done
;
1477 /* Get a free request id */
1478 twl_get_request_id(tw_dev
, &request_id
);
1480 /* Save the scsi command for use by the ISR */
1481 tw_dev
->srb
[request_id
] = SCpnt
;
1483 retval
= twl_scsiop_execute_scsi(tw_dev
, request_id
, NULL
, 0, NULL
);
1485 tw_dev
->state
[request_id
] = TW_S_COMPLETED
;
1486 twl_free_request_id(tw_dev
, request_id
);
1487 SCpnt
->result
= (DID_ERROR
<< 16);
1493 } /* End twl_scsi_queue() */
1495 static DEF_SCSI_QCMD(twl_scsi_queue
)
1497 /* This function tells the controller to shut down */
1498 static void __twl_shutdown(TW_Device_Extension
*tw_dev
)
1500 /* Disable interrupts */
1501 TWL_MASK_INTERRUPTS(tw_dev
);
1503 /* Free up the IRQ */
1504 free_irq(tw_dev
->tw_pci_dev
->irq
, tw_dev
);
1506 printk(KERN_WARNING
"3w-sas: Shutting down host %d.\n", tw_dev
->host
->host_no
);
1508 /* Tell the card we are shutting down */
1509 if (twl_initconnection(tw_dev
, 1, 0, 0, 0, 0, 0, NULL
, NULL
, NULL
, NULL
, NULL
)) {
1510 TW_PRINTK(tw_dev
->host
, TW_DRIVER
, 0x16, "Connection shutdown failed");
1512 printk(KERN_WARNING
"3w-sas: Shutdown complete.\n");
1515 /* Clear doorbell interrupt just before exit */
1516 TWL_CLEAR_DB_INTERRUPT(tw_dev
);
1517 } /* End __twl_shutdown() */
1519 /* Wrapper for __twl_shutdown */
1520 static void twl_shutdown(struct pci_dev
*pdev
)
1522 struct Scsi_Host
*host
= pci_get_drvdata(pdev
);
1523 TW_Device_Extension
*tw_dev
;
1528 tw_dev
= (TW_Device_Extension
*)host
->hostdata
;
1531 __twl_shutdown(tw_dev
);
1532 } /* End twl_shutdown() */
1534 /* This function configures unit settings when a unit is coming on-line */
1535 static int twl_slave_configure(struct scsi_device
*sdev
)
1537 /* Force 60 second timeout */
1538 blk_queue_rq_timeout(sdev
->request_queue
, 60 * HZ
);
1541 } /* End twl_slave_configure() */
1543 /* scsi_host_template initializer */
1544 static struct scsi_host_template driver_template
= {
1545 .module
= THIS_MODULE
,
1547 .queuecommand
= twl_scsi_queue
,
1548 .eh_host_reset_handler
= twl_scsi_eh_reset
,
1549 .bios_param
= twl_scsi_biosparam
,
1550 .change_queue_depth
= scsi_change_queue_depth
,
1551 .can_queue
= TW_Q_LENGTH
-2,
1552 .slave_configure
= twl_slave_configure
,
1554 .sg_tablesize
= TW_LIBERATOR_MAX_SGL_LENGTH
,
1555 .max_sectors
= TW_MAX_SECTORS
,
1556 .cmd_per_lun
= TW_MAX_CMDS_PER_LUN
,
1557 .use_clustering
= ENABLE_CLUSTERING
,
1558 .shost_attrs
= twl_host_attrs
,
1563 /* This function will probe and initialize a card */
1564 static int twl_probe(struct pci_dev
*pdev
, const struct pci_device_id
*dev_id
)
1566 struct Scsi_Host
*host
= NULL
;
1567 TW_Device_Extension
*tw_dev
;
1568 int retval
= -ENODEV
;
1569 int *ptr_phycount
, phycount
=0;
1571 retval
= pci_enable_device(pdev
);
1573 TW_PRINTK(host
, TW_DRIVER
, 0x17, "Failed to enable pci device");
1574 goto out_disable_device
;
1577 pci_set_master(pdev
);
1578 pci_try_set_mwi(pdev
);
1580 if (pci_set_dma_mask(pdev
, DMA_BIT_MASK(64))
1581 || pci_set_consistent_dma_mask(pdev
, DMA_BIT_MASK(64)))
1582 if (pci_set_dma_mask(pdev
, DMA_BIT_MASK(32))
1583 || pci_set_consistent_dma_mask(pdev
, DMA_BIT_MASK(32))) {
1584 TW_PRINTK(host
, TW_DRIVER
, 0x18, "Failed to set dma mask");
1586 goto out_disable_device
;
1589 host
= scsi_host_alloc(&driver_template
, sizeof(TW_Device_Extension
));
1591 TW_PRINTK(host
, TW_DRIVER
, 0x19, "Failed to allocate memory for device extension");
1593 goto out_disable_device
;
1595 tw_dev
= shost_priv(host
);
1597 /* Save values to device extension */
1598 tw_dev
->host
= host
;
1599 tw_dev
->tw_pci_dev
= pdev
;
1601 if (twl_initialize_device_extension(tw_dev
)) {
1602 TW_PRINTK(tw_dev
->host
, TW_DRIVER
, 0x1a, "Failed to initialize device extension");
1604 goto out_free_device_extension
;
1607 /* Request IO regions */
1608 retval
= pci_request_regions(pdev
, "3w-sas");
1610 TW_PRINTK(tw_dev
->host
, TW_DRIVER
, 0x1b, "Failed to get mem region");
1611 goto out_free_device_extension
;
1614 /* Save base address, use region 1 */
1615 tw_dev
->base_addr
= pci_iomap(pdev
, 1, 0);
1616 if (!tw_dev
->base_addr
) {
1617 TW_PRINTK(tw_dev
->host
, TW_DRIVER
, 0x1c, "Failed to ioremap");
1619 goto out_release_mem_region
;
1622 /* Disable interrupts on the card */
1623 TWL_MASK_INTERRUPTS(tw_dev
);
1625 /* Initialize the card */
1626 if (twl_reset_sequence(tw_dev
, 0)) {
1627 TW_PRINTK(tw_dev
->host
, TW_DRIVER
, 0x1d, "Controller reset failed during probe");
1632 /* Set host specific parameters */
1633 host
->max_id
= TW_MAX_UNITS
;
1634 host
->max_cmd_len
= TW_MAX_CDB_LEN
;
1635 host
->max_lun
= TW_MAX_LUNS
;
1636 host
->max_channel
= 0;
1638 /* Register the card with the kernel SCSI layer */
1639 retval
= scsi_add_host(host
, &pdev
->dev
);
1641 TW_PRINTK(tw_dev
->host
, TW_DRIVER
, 0x1e, "scsi add host failed");
1645 pci_set_drvdata(pdev
, host
);
1647 printk(KERN_WARNING
"3w-sas: scsi%d: Found an LSI 3ware %s Controller at 0x%llx, IRQ: %d.\n",
1649 (char *)twl_get_param(tw_dev
, 1, TW_VERSION_TABLE
,
1650 TW_PARAM_MODEL
, TW_PARAM_MODEL_LENGTH
),
1651 (u64
)pci_resource_start(pdev
, 1), pdev
->irq
);
1653 ptr_phycount
= twl_get_param(tw_dev
, 2, TW_PARAM_PHY_SUMMARY_TABLE
,
1654 TW_PARAM_PHYCOUNT
, TW_PARAM_PHYCOUNT_LENGTH
);
1656 phycount
= le32_to_cpu(*(int *)ptr_phycount
);
1658 printk(KERN_WARNING
"3w-sas: scsi%d: Firmware %s, BIOS %s, Phys: %d.\n",
1660 (char *)twl_get_param(tw_dev
, 1, TW_VERSION_TABLE
,
1661 TW_PARAM_FWVER
, TW_PARAM_FWVER_LENGTH
),
1662 (char *)twl_get_param(tw_dev
, 2, TW_VERSION_TABLE
,
1663 TW_PARAM_BIOSVER
, TW_PARAM_BIOSVER_LENGTH
),
1666 /* Try to enable MSI */
1667 if (use_msi
&& !pci_enable_msi(pdev
))
1668 set_bit(TW_USING_MSI
, &tw_dev
->flags
);
1670 /* Now setup the interrupt handler */
1671 retval
= request_irq(pdev
->irq
, twl_interrupt
, IRQF_SHARED
, "3w-sas", tw_dev
);
1673 TW_PRINTK(tw_dev
->host
, TW_DRIVER
, 0x1f, "Error requesting IRQ");
1674 goto out_remove_host
;
1677 twl_device_extension_list
[twl_device_extension_count
] = tw_dev
;
1678 twl_device_extension_count
++;
1680 /* Re-enable interrupts on the card */
1681 TWL_UNMASK_INTERRUPTS(tw_dev
);
1683 /* Finally, scan the host */
1684 scsi_scan_host(host
);
1686 /* Add sysfs binary files */
1687 if (sysfs_create_bin_file(&host
->shost_dev
.kobj
, &twl_sysfs_aen_read_attr
))
1688 TW_PRINTK(tw_dev
->host
, TW_DRIVER
, 0x20, "Failed to create sysfs binary file: 3ware_aen_read");
1689 if (sysfs_create_bin_file(&host
->shost_dev
.kobj
, &twl_sysfs_compat_info_attr
))
1690 TW_PRINTK(tw_dev
->host
, TW_DRIVER
, 0x21, "Failed to create sysfs binary file: 3ware_compat_info");
1692 if (twl_major
== -1) {
1693 if ((twl_major
= register_chrdev (0, "twl", &twl_fops
)) < 0)
1694 TW_PRINTK(host
, TW_DRIVER
, 0x22, "Failed to register character device");
1700 if (test_bit(TW_USING_MSI
, &tw_dev
->flags
))
1701 pci_disable_msi(pdev
);
1702 scsi_remove_host(host
);
1704 iounmap(tw_dev
->base_addr
);
1705 out_release_mem_region
:
1706 pci_release_regions(pdev
);
1707 out_free_device_extension
:
1708 twl_free_device_extension(tw_dev
);
1709 scsi_host_put(host
);
1711 pci_disable_device(pdev
);
1714 } /* End twl_probe() */
1716 /* This function is called to remove a device */
1717 static void twl_remove(struct pci_dev
*pdev
)
1719 struct Scsi_Host
*host
= pci_get_drvdata(pdev
);
1720 TW_Device_Extension
*tw_dev
;
1725 tw_dev
= (TW_Device_Extension
*)host
->hostdata
;
1727 if (!tw_dev
->online
)
1730 /* Remove sysfs binary files */
1731 sysfs_remove_bin_file(&host
->shost_dev
.kobj
, &twl_sysfs_aen_read_attr
);
1732 sysfs_remove_bin_file(&host
->shost_dev
.kobj
, &twl_sysfs_compat_info_attr
);
1734 scsi_remove_host(tw_dev
->host
);
1736 /* Unregister character device */
1737 if (twl_major
>= 0) {
1738 unregister_chrdev(twl_major
, "twl");
1742 /* Shutdown the card */
1743 __twl_shutdown(tw_dev
);
1745 /* Disable MSI if enabled */
1746 if (test_bit(TW_USING_MSI
, &tw_dev
->flags
))
1747 pci_disable_msi(pdev
);
1749 /* Free IO remapping */
1750 iounmap(tw_dev
->base_addr
);
1752 /* Free up the mem region */
1753 pci_release_regions(pdev
);
1755 /* Free up device extension resources */
1756 twl_free_device_extension(tw_dev
);
1758 scsi_host_put(tw_dev
->host
);
1759 pci_disable_device(pdev
);
1760 twl_device_extension_count
--;
1761 } /* End twl_remove() */
1764 /* This function is called on PCI suspend */
1765 static int twl_suspend(struct pci_dev
*pdev
, pm_message_t state
)
1767 struct Scsi_Host
*host
= pci_get_drvdata(pdev
);
1768 TW_Device_Extension
*tw_dev
= (TW_Device_Extension
*)host
->hostdata
;
1770 printk(KERN_WARNING
"3w-sas: Suspending host %d.\n", tw_dev
->host
->host_no
);
1771 /* Disable interrupts */
1772 TWL_MASK_INTERRUPTS(tw_dev
);
1774 free_irq(tw_dev
->tw_pci_dev
->irq
, tw_dev
);
1776 /* Tell the card we are shutting down */
1777 if (twl_initconnection(tw_dev
, 1, 0, 0, 0, 0, 0, NULL
, NULL
, NULL
, NULL
, NULL
)) {
1778 TW_PRINTK(tw_dev
->host
, TW_DRIVER
, 0x23, "Connection shutdown failed during suspend");
1780 printk(KERN_WARNING
"3w-sas: Suspend complete.\n");
1783 /* Clear doorbell interrupt */
1784 TWL_CLEAR_DB_INTERRUPT(tw_dev
);
1786 pci_save_state(pdev
);
1787 pci_disable_device(pdev
);
1788 pci_set_power_state(pdev
, pci_choose_state(pdev
, state
));
1791 } /* End twl_suspend() */
1793 /* This function is called on PCI resume */
1794 static int twl_resume(struct pci_dev
*pdev
)
1797 struct Scsi_Host
*host
= pci_get_drvdata(pdev
);
1798 TW_Device_Extension
*tw_dev
= (TW_Device_Extension
*)host
->hostdata
;
1800 printk(KERN_WARNING
"3w-sas: Resuming host %d.\n", tw_dev
->host
->host_no
);
1801 pci_set_power_state(pdev
, PCI_D0
);
1802 pci_enable_wake(pdev
, PCI_D0
, 0);
1803 pci_restore_state(pdev
);
1805 retval
= pci_enable_device(pdev
);
1807 TW_PRINTK(tw_dev
->host
, TW_DRIVER
, 0x24, "Enable device failed during resume");
1811 pci_set_master(pdev
);
1812 pci_try_set_mwi(pdev
);
1814 if (pci_set_dma_mask(pdev
, DMA_BIT_MASK(64))
1815 || pci_set_consistent_dma_mask(pdev
, DMA_BIT_MASK(64)))
1816 if (pci_set_dma_mask(pdev
, DMA_BIT_MASK(32))
1817 || pci_set_consistent_dma_mask(pdev
, DMA_BIT_MASK(32))) {
1818 TW_PRINTK(host
, TW_DRIVER
, 0x25, "Failed to set dma mask during resume");
1820 goto out_disable_device
;
1823 /* Initialize the card */
1824 if (twl_reset_sequence(tw_dev
, 0)) {
1826 goto out_disable_device
;
1829 /* Now setup the interrupt handler */
1830 retval
= request_irq(pdev
->irq
, twl_interrupt
, IRQF_SHARED
, "3w-sas", tw_dev
);
1832 TW_PRINTK(tw_dev
->host
, TW_DRIVER
, 0x26, "Error requesting IRQ during resume");
1834 goto out_disable_device
;
1837 /* Now enable MSI if enabled */
1838 if (test_bit(TW_USING_MSI
, &tw_dev
->flags
))
1839 pci_enable_msi(pdev
);
1841 /* Re-enable interrupts on the card */
1842 TWL_UNMASK_INTERRUPTS(tw_dev
);
1844 printk(KERN_WARNING
"3w-sas: Resume complete.\n");
1848 scsi_remove_host(host
);
1849 pci_disable_device(pdev
);
1852 } /* End twl_resume() */
1855 /* PCI Devices supported by this driver */
1856 static struct pci_device_id twl_pci_tbl
[] = {
1857 { PCI_VDEVICE(3WARE
, PCI_DEVICE_ID_3WARE_9750
) },
1860 MODULE_DEVICE_TABLE(pci
, twl_pci_tbl
);
1862 /* pci_driver initializer */
1863 static struct pci_driver twl_driver
= {
1865 .id_table
= twl_pci_tbl
,
1867 .remove
= twl_remove
,
1869 .suspend
= twl_suspend
,
1870 .resume
= twl_resume
,
1872 .shutdown
= twl_shutdown
1875 /* This function is called on driver initialization */
1876 static int __init
twl_init(void)
1878 printk(KERN_INFO
"LSI 3ware SAS/SATA-RAID Controller device driver for Linux v%s.\n", TW_DRIVER_VERSION
);
1880 return pci_register_driver(&twl_driver
);
1881 } /* End twl_init() */
1883 /* This function is called on driver exit */
1884 static void __exit
twl_exit(void)
1886 pci_unregister_driver(&twl_driver
);
1887 } /* End twl_exit() */
1889 module_init(twl_init
);
1890 module_exit(twl_exit
);