Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | 3w-9xxx.c -- 3ware 9000 Storage Controller device driver for Linux. |
| 3 | |
adam radford | 2c9bce5 | 2016-12-09 11:08:05 -0800 | [diff] [blame] | 4 | Written By: Adam Radford <aradford@gmail.com> |
| 5 | Modifications By: Tom Couch |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | |
adam radford | 7a252fe | 2009-03-09 12:15:01 -0800 | [diff] [blame] | 7 | Copyright (C) 2004-2009 Applied Micro Circuits Corporation. |
adam radford | 4deedd8 | 2010-03-08 12:37:46 -0800 | [diff] [blame] | 8 | Copyright (C) 2010 LSI Corporation. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | |
| 10 | This program is free software; you can redistribute it and/or modify |
| 11 | it under the terms of the GNU General Public License as published by |
| 12 | the Free Software Foundation; version 2 of the License. |
| 13 | |
| 14 | This program is distributed in the hope that it will be useful, |
| 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | GNU General Public License for more details. |
| 18 | |
| 19 | NO WARRANTY |
| 20 | THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR |
| 21 | CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT |
| 22 | LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, |
| 23 | MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is |
| 24 | solely responsible for determining the appropriateness of using and |
| 25 | distributing the Program and assumes all risks associated with its |
| 26 | exercise of rights under this Agreement, including but not limited to |
| 27 | the risks and costs of program errors, damage to or loss of data, |
| 28 | programs or equipment, and unavailability or interruption of operations. |
| 29 | |
| 30 | DISCLAIMER OF LIABILITY |
| 31 | NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY |
| 32 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 33 | DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND |
| 34 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR |
| 35 | TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE |
| 36 | USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED |
| 37 | HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES |
| 38 | |
| 39 | You should have received a copy of the GNU General Public License |
| 40 | along with this program; if not, write to the Free Software |
| 41 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 42 | |
| 43 | Bugs/Comments/Suggestions should be mailed to: |
adam radford | 2c9bce5 | 2016-12-09 11:08:05 -0800 | [diff] [blame] | 44 | aradford@gmail.com |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | |
| 46 | Note: This version of the driver does not contain a bundled firmware |
| 47 | image. |
| 48 | |
| 49 | History |
| 50 | ------- |
| 51 | 2.26.02.000 - Driver cleanup for kernel submission. |
| 52 | 2.26.02.001 - Replace schedule_timeout() calls with msleep(). |
| 53 | 2.26.02.002 - Add support for PAE mode. |
| 54 | Add lun support. |
| 55 | Fix twa_remove() to free irq handler/unregister_chrdev() |
| 56 | before shutting down card. |
| 57 | Change to new 'change_queue_depth' api. |
| 58 | Fix 'handled=1' ISR usage, remove bogus IRQ check. |
| 59 | Remove un-needed eh_abort handler. |
| 60 | Add support for embedded firmware error strings. |
adam radford | d327d08 | 2005-09-09 15:55:13 -0700 | [diff] [blame] | 61 | 2.26.02.003 - Correctly handle single sgl's with use_sg=1. |
adam radford | 49bfd8d | 2005-09-21 17:20:14 -0700 | [diff] [blame] | 62 | 2.26.02.004 - Add support for 9550SX controllers. |
adam radford | 62288f1 | 2006-02-05 14:51:43 -0800 | [diff] [blame] | 63 | 2.26.02.005 - Fix use_sg == 0 mapping on systems with 4GB or higher. |
adam radford | 75913d9 | 2006-03-15 12:43:19 -0800 | [diff] [blame] | 64 | 2.26.02.006 - Fix 9550SX pchip reset timeout. |
| 65 | Add big endian support. |
adam radford | 1e08dcb | 2006-04-11 11:25:09 -0700 | [diff] [blame] | 66 | 2.26.02.007 - Disable local interrupts during kmap/unmap_atomic(). |
adam radford | 4039c30 | 2006-10-26 18:01:06 -0700 | [diff] [blame] | 67 | 2.26.02.008 - Free irq handler in __twa_shutdown(). |
| 68 | Serialize reset code. |
| 69 | Add support for 9650SE controllers. |
adam radford | 0e78d15 | 2007-07-20 15:28:28 -0700 | [diff] [blame] | 70 | 2.26.02.009 - Fix dma mask setting to fallback to 32-bit if 64-bit fails. |
| 71 | 2.26.02.010 - Add support for 9690SA controllers. |
adam radford | 3dabec7 | 2008-07-22 16:47:40 -0700 | [diff] [blame] | 72 | 2.26.02.011 - Increase max AENs drained to 256. |
| 73 | Add MSI support and "use_msi" module parameter. |
| 74 | Fix bug in twa_get_param() on 4GB+. |
| 75 | Use pci_resource_len() for ioremap(). |
adam radford | 7a252fe | 2009-03-09 12:15:01 -0800 | [diff] [blame] | 76 | 2.26.02.012 - Add power management support. |
adam radford | 53ca353 | 2009-12-10 11:53:31 -0800 | [diff] [blame] | 77 | 2.26.02.013 - Fix bug in twa_load_sgl(). |
adam radford | 4deedd8 | 2010-03-08 12:37:46 -0800 | [diff] [blame] | 78 | 2.26.02.014 - Force 60 second timeout default. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | */ |
| 80 | |
| 81 | #include <linux/module.h> |
| 82 | #include <linux/reboot.h> |
| 83 | #include <linux/spinlock.h> |
| 84 | #include <linux/interrupt.h> |
| 85 | #include <linux/moduleparam.h> |
| 86 | #include <linux/errno.h> |
| 87 | #include <linux/types.h> |
| 88 | #include <linux/delay.h> |
| 89 | #include <linux/pci.h> |
| 90 | #include <linux/time.h> |
Jes Sorensen | a12e25bd | 2006-01-11 08:39:45 -0500 | [diff] [blame] | 91 | #include <linux/mutex.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 92 | #include <linux/slab.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | #include <asm/io.h> |
| 94 | #include <asm/irq.h> |
Linus Torvalds | 7c0f6ba | 2016-12-24 11:46:01 -0800 | [diff] [blame] | 95 | #include <linux/uaccess.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | #include <scsi/scsi.h> |
| 97 | #include <scsi/scsi_host.h> |
| 98 | #include <scsi/scsi_tcq.h> |
| 99 | #include <scsi/scsi_cmnd.h> |
| 100 | #include "3w-9xxx.h" |
| 101 | |
| 102 | /* Globals */ |
adam radford | 4deedd8 | 2010-03-08 12:37:46 -0800 | [diff] [blame] | 103 | #define TW_DRIVER_VERSION "2.26.02.014" |
Arnd Bergmann | c45d15d | 2010-06-02 14:28:52 +0200 | [diff] [blame] | 104 | static DEFINE_MUTEX(twa_chrdev_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | static TW_Device_Extension *twa_device_extension_list[TW_MAX_SLOT]; |
| 106 | static unsigned int twa_device_extension_count; |
| 107 | static int twa_major = -1; |
| 108 | extern struct timezone sys_tz; |
| 109 | |
| 110 | /* Module parameters */ |
adam radford | 4deedd8 | 2010-03-08 12:37:46 -0800 | [diff] [blame] | 111 | MODULE_AUTHOR ("LSI"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | MODULE_DESCRIPTION ("3ware 9000 Storage Controller Linux Driver"); |
| 113 | MODULE_LICENSE("GPL"); |
| 114 | MODULE_VERSION(TW_DRIVER_VERSION); |
| 115 | |
adam radford | 3dabec7 | 2008-07-22 16:47:40 -0700 | [diff] [blame] | 116 | static int use_msi = 0; |
| 117 | module_param(use_msi, int, S_IRUGO); |
| 118 | MODULE_PARM_DESC(use_msi, "Use Message Signaled Interrupts. Default: 0"); |
| 119 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | /* Function prototypes */ |
| 121 | static void twa_aen_queue_event(TW_Device_Extension *tw_dev, TW_Command_Apache_Header *header); |
| 122 | static int twa_aen_read_queue(TW_Device_Extension *tw_dev, int request_id); |
| 123 | static char *twa_aen_severity_lookup(unsigned char severity_code); |
| 124 | static void twa_aen_sync_time(TW_Device_Extension *tw_dev, int request_id); |
Arnd Bergmann | f4927c4 | 2010-04-27 00:24:01 +0200 | [diff] [blame] | 125 | static long twa_chrdev_ioctl(struct file *file, unsigned int cmd, unsigned long arg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | static int twa_chrdev_open(struct inode *inode, struct file *file); |
| 127 | static int twa_fill_sense(TW_Device_Extension *tw_dev, int request_id, int copy_sense, int print_host); |
| 128 | static void twa_free_request_id(TW_Device_Extension *tw_dev,int request_id); |
| 129 | static void twa_get_request_id(TW_Device_Extension *tw_dev, int *request_id); |
| 130 | static int twa_initconnection(TW_Device_Extension *tw_dev, int message_credits, |
Hannes Reinecke | bf4eebb | 2021-01-13 10:04:28 +0100 | [diff] [blame] | 131 | u32 set_features, unsigned short current_fw_srl, |
| 132 | unsigned short current_fw_arch_id, |
| 133 | unsigned short current_fw_branch, |
| 134 | unsigned short current_fw_build, |
| 135 | unsigned short *fw_on_ctlr_srl, |
| 136 | unsigned short *fw_on_ctlr_arch_id, |
| 137 | unsigned short *fw_on_ctlr_branch, |
| 138 | unsigned short *fw_on_ctlr_build, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | u32 *init_connect_result); |
adam radford | 0e78d15 | 2007-07-20 15:28:28 -0700 | [diff] [blame] | 140 | static void twa_load_sgl(TW_Device_Extension *tw_dev, TW_Command_Full *full_command_packet, int request_id, dma_addr_t dma_handle, int length); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | static int twa_poll_response(TW_Device_Extension *tw_dev, int request_id, int seconds); |
| 142 | static int twa_poll_status_gone(TW_Device_Extension *tw_dev, u32 flag, int seconds); |
| 143 | static int twa_post_command_packet(TW_Device_Extension *tw_dev, int request_id, char internal); |
adam radford | 0e78d15 | 2007-07-20 15:28:28 -0700 | [diff] [blame] | 144 | static int twa_reset_device_extension(TW_Device_Extension *tw_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | static int twa_reset_sequence(TW_Device_Extension *tw_dev, int soft_reset); |
Nathan Chancellor | 09968e5 | 2018-10-18 14:55:41 -0700 | [diff] [blame] | 146 | static int twa_scsiop_execute_scsi(TW_Device_Extension *tw_dev, int request_id, |
| 147 | unsigned char *cdb, int use_sg, |
| 148 | TW_SG_Entry *sglistarg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | static void twa_scsiop_execute_scsi_complete(TW_Device_Extension *tw_dev, int request_id); |
| 150 | static char *twa_string_lookup(twa_message_type *table, unsigned int aen_code); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | |
| 152 | /* Functions */ |
| 153 | |
| 154 | /* Show some statistics about the card */ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 155 | static ssize_t twa_show_stats(struct device *dev, |
| 156 | struct device_attribute *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | { |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 158 | struct Scsi_Host *host = class_to_shost(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | TW_Device_Extension *tw_dev = (TW_Device_Extension *)host->hostdata; |
| 160 | unsigned long flags = 0; |
| 161 | ssize_t len; |
| 162 | |
| 163 | spin_lock_irqsave(tw_dev->host->host_lock, flags); |
| 164 | len = snprintf(buf, PAGE_SIZE, "3w-9xxx Driver version: %s\n" |
| 165 | "Current commands posted: %4d\n" |
| 166 | "Max commands posted: %4d\n" |
| 167 | "Current pending commands: %4d\n" |
| 168 | "Max pending commands: %4d\n" |
| 169 | "Last sgl length: %4d\n" |
| 170 | "Max sgl length: %4d\n" |
| 171 | "Last sector count: %4d\n" |
| 172 | "Max sector count: %4d\n" |
| 173 | "SCSI Host Resets: %4d\n" |
Hannes Reinecke | bf4eebb | 2021-01-13 10:04:28 +0100 | [diff] [blame] | 174 | "AEN's: %4d\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | TW_DRIVER_VERSION, |
| 176 | tw_dev->posted_request_count, |
| 177 | tw_dev->max_posted_request_count, |
| 178 | tw_dev->pending_request_count, |
| 179 | tw_dev->max_pending_request_count, |
| 180 | tw_dev->sgl_entries, |
| 181 | tw_dev->max_sgl_entries, |
| 182 | tw_dev->sector_count, |
| 183 | tw_dev->max_sector_count, |
| 184 | tw_dev->num_resets, |
| 185 | tw_dev->aen_count); |
| 186 | spin_unlock_irqrestore(tw_dev->host->host_lock, flags); |
| 187 | return len; |
| 188 | } /* End twa_show_stats() */ |
| 189 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 | /* Create sysfs 'stats' entry */ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 191 | static struct device_attribute twa_host_stats_attr = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 192 | .attr = { |
Hannes Reinecke | bf4eebb | 2021-01-13 10:04:28 +0100 | [diff] [blame] | 193 | .name = "stats", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 | .mode = S_IRUGO, |
| 195 | }, |
| 196 | .show = twa_show_stats |
| 197 | }; |
| 198 | |
| 199 | /* Host attributes initializer */ |
Bart Van Assche | bd21c1e | 2021-10-12 16:35:19 -0700 | [diff] [blame] | 200 | static struct attribute *twa_host_attrs[] = { |
| 201 | &twa_host_stats_attr.attr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 202 | NULL, |
| 203 | }; |
| 204 | |
Bart Van Assche | bd21c1e | 2021-10-12 16:35:19 -0700 | [diff] [blame] | 205 | ATTRIBUTE_GROUPS(twa_host); |
| 206 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 207 | /* File operations struct for character device */ |
Arjan van de Ven | 00977a5 | 2007-02-12 00:55:34 -0800 | [diff] [blame] | 208 | static const struct file_operations twa_fops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 | .owner = THIS_MODULE, |
Arnd Bergmann | f4927c4 | 2010-04-27 00:24:01 +0200 | [diff] [blame] | 210 | .unlocked_ioctl = twa_chrdev_ioctl, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | .open = twa_chrdev_open, |
Arnd Bergmann | 6038f37 | 2010-08-15 18:52:59 +0200 | [diff] [blame] | 212 | .release = NULL, |
| 213 | .llseek = noop_llseek, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | }; |
| 215 | |
Christoph Hellwig | 15e3d5a | 2015-10-03 19:16:07 +0200 | [diff] [blame] | 216 | /* |
| 217 | * The controllers use an inline buffer instead of a mapped SGL for small, |
| 218 | * single entry buffers. Note that we treat a zero-length transfer like |
| 219 | * a mapped SGL. |
| 220 | */ |
| 221 | static bool twa_command_mapped(struct scsi_cmnd *cmd) |
| 222 | { |
| 223 | return scsi_sg_count(cmd) != 1 || |
| 224 | scsi_bufflen(cmd) >= TW_MIN_SGL_LENGTH; |
| 225 | } |
| 226 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 227 | /* This function will complete an aen request from the isr */ |
| 228 | static int twa_aen_complete(TW_Device_Extension *tw_dev, int request_id) |
| 229 | { |
| 230 | TW_Command_Full *full_command_packet; |
| 231 | TW_Command *command_packet; |
| 232 | TW_Command_Apache_Header *header; |
| 233 | unsigned short aen; |
| 234 | int retval = 1; |
| 235 | |
| 236 | header = (TW_Command_Apache_Header *)tw_dev->generic_buffer_virt[request_id]; |
| 237 | tw_dev->posted_request_count--; |
adam radford | 75913d9 | 2006-03-15 12:43:19 -0800 | [diff] [blame] | 238 | aen = le16_to_cpu(header->status_block.error); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 239 | full_command_packet = tw_dev->command_packet_virt[request_id]; |
| 240 | command_packet = &full_command_packet->command.oldcommand; |
| 241 | |
| 242 | /* First check for internal completion of set param for time sync */ |
| 243 | if (TW_OP_OUT(command_packet->opcode__sgloffset) == TW_OP_SET_PARAM) { |
| 244 | /* Keep reading the queue in case there are more aen's */ |
| 245 | if (twa_aen_read_queue(tw_dev, request_id)) |
| 246 | goto out2; |
Hannes Reinecke | bf4eebb | 2021-01-13 10:04:28 +0100 | [diff] [blame] | 247 | else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 | retval = 0; |
| 249 | goto out; |
| 250 | } |
| 251 | } |
| 252 | |
| 253 | switch (aen) { |
| 254 | case TW_AEN_QUEUE_EMPTY: |
| 255 | /* Quit reading the queue if this is the last one */ |
| 256 | break; |
| 257 | case TW_AEN_SYNC_TIME_WITH_HOST: |
| 258 | twa_aen_sync_time(tw_dev, request_id); |
| 259 | retval = 0; |
| 260 | goto out; |
| 261 | default: |
| 262 | twa_aen_queue_event(tw_dev, header); |
| 263 | |
| 264 | /* If there are more aen's, keep reading the queue */ |
| 265 | if (twa_aen_read_queue(tw_dev, request_id)) |
| 266 | goto out2; |
| 267 | else { |
| 268 | retval = 0; |
| 269 | goto out; |
| 270 | } |
| 271 | } |
| 272 | retval = 0; |
| 273 | out2: |
| 274 | tw_dev->state[request_id] = TW_S_COMPLETED; |
| 275 | twa_free_request_id(tw_dev, request_id); |
| 276 | clear_bit(TW_IN_ATTENTION_LOOP, &tw_dev->flags); |
| 277 | out: |
| 278 | return retval; |
| 279 | } /* End twa_aen_complete() */ |
| 280 | |
| 281 | /* This function will drain aen queue */ |
| 282 | static int twa_aen_drain_queue(TW_Device_Extension *tw_dev, int no_check_reset) |
| 283 | { |
| 284 | int request_id = 0; |
Nathan Chancellor | 09968e5 | 2018-10-18 14:55:41 -0700 | [diff] [blame] | 285 | unsigned char cdb[TW_MAX_CDB_LEN]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 286 | TW_SG_Entry sglist[1]; |
| 287 | int finished = 0, count = 0; |
| 288 | TW_Command_Full *full_command_packet; |
| 289 | TW_Command_Apache_Header *header; |
| 290 | unsigned short aen; |
| 291 | int first_reset = 0, queue = 0, retval = 1; |
| 292 | |
| 293 | if (no_check_reset) |
| 294 | first_reset = 0; |
| 295 | else |
| 296 | first_reset = 1; |
| 297 | |
| 298 | full_command_packet = tw_dev->command_packet_virt[request_id]; |
| 299 | memset(full_command_packet, 0, sizeof(TW_Command_Full)); |
| 300 | |
| 301 | /* Initialize cdb */ |
| 302 | memset(&cdb, 0, TW_MAX_CDB_LEN); |
| 303 | cdb[0] = REQUEST_SENSE; /* opcode */ |
| 304 | cdb[4] = TW_ALLOCATION_LENGTH; /* allocation length */ |
| 305 | |
| 306 | /* Initialize sglist */ |
| 307 | memset(&sglist, 0, sizeof(TW_SG_Entry)); |
Samuel Holland | 05f7f1b9 | 2021-04-27 18:59:15 -0500 | [diff] [blame] | 308 | sglist[0].length = cpu_to_le32(TW_SECTOR_SIZE); |
| 309 | sglist[0].address = TW_CPU_TO_SGL(tw_dev->generic_buffer_phys[request_id]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 310 | |
Samuel Holland | 05f7f1b9 | 2021-04-27 18:59:15 -0500 | [diff] [blame] | 311 | if (tw_dev->generic_buffer_phys[request_id] & TW_ALIGNMENT_9000_SGL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 312 | TW_PRINTK(tw_dev->host, TW_DRIVER, 0x1, "Found unaligned address during AEN drain"); |
| 313 | goto out; |
| 314 | } |
| 315 | |
| 316 | /* Mark internal command */ |
| 317 | tw_dev->srb[request_id] = NULL; |
| 318 | |
| 319 | do { |
| 320 | /* Send command to the board */ |
| 321 | if (twa_scsiop_execute_scsi(tw_dev, request_id, cdb, 1, sglist)) { |
| 322 | TW_PRINTK(tw_dev->host, TW_DRIVER, 0x2, "Error posting request sense"); |
| 323 | goto out; |
| 324 | } |
| 325 | |
| 326 | /* Now poll for completion */ |
| 327 | if (twa_poll_response(tw_dev, request_id, 30)) { |
| 328 | TW_PRINTK(tw_dev->host, TW_DRIVER, 0x3, "No valid response while draining AEN queue"); |
| 329 | tw_dev->posted_request_count--; |
| 330 | goto out; |
| 331 | } |
| 332 | |
| 333 | tw_dev->posted_request_count--; |
| 334 | header = (TW_Command_Apache_Header *)tw_dev->generic_buffer_virt[request_id]; |
adam radford | 75913d9 | 2006-03-15 12:43:19 -0800 | [diff] [blame] | 335 | aen = le16_to_cpu(header->status_block.error); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 336 | queue = 0; |
| 337 | count++; |
| 338 | |
| 339 | switch (aen) { |
| 340 | case TW_AEN_QUEUE_EMPTY: |
| 341 | if (first_reset != 1) |
| 342 | goto out; |
| 343 | else |
| 344 | finished = 1; |
| 345 | break; |
| 346 | case TW_AEN_SOFT_RESET: |
| 347 | if (first_reset == 0) |
| 348 | first_reset = 1; |
| 349 | else |
| 350 | queue = 1; |
| 351 | break; |
| 352 | case TW_AEN_SYNC_TIME_WITH_HOST: |
| 353 | break; |
| 354 | default: |
| 355 | queue = 1; |
| 356 | } |
| 357 | |
| 358 | /* Now queue an event info */ |
| 359 | if (queue) |
| 360 | twa_aen_queue_event(tw_dev, header); |
| 361 | } while ((finished == 0) && (count < TW_MAX_AEN_DRAIN)); |
| 362 | |
| 363 | if (count == TW_MAX_AEN_DRAIN) |
| 364 | goto out; |
| 365 | |
| 366 | retval = 0; |
| 367 | out: |
| 368 | tw_dev->state[request_id] = TW_S_INITIAL; |
| 369 | return retval; |
| 370 | } /* End twa_aen_drain_queue() */ |
| 371 | |
| 372 | /* This function will queue an event */ |
| 373 | static void twa_aen_queue_event(TW_Device_Extension *tw_dev, TW_Command_Apache_Header *header) |
| 374 | { |
| 375 | u32 local_time; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 376 | TW_Event *event; |
| 377 | unsigned short aen; |
| 378 | char host[16]; |
| 379 | char *error_str; |
| 380 | |
| 381 | tw_dev->aen_count++; |
| 382 | |
| 383 | /* Fill out event info */ |
| 384 | event = tw_dev->event_queue[tw_dev->error_index]; |
| 385 | |
| 386 | /* Check for clobber */ |
| 387 | host[0] = '\0'; |
| 388 | if (tw_dev->host) { |
| 389 | sprintf(host, " scsi%d:", tw_dev->host->host_no); |
| 390 | if (event->retrieved == TW_AEN_NOT_RETRIEVED) |
| 391 | tw_dev->aen_clobber = 1; |
| 392 | } |
| 393 | |
adam radford | 75913d9 | 2006-03-15 12:43:19 -0800 | [diff] [blame] | 394 | aen = le16_to_cpu(header->status_block.error); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 395 | memset(event, 0, sizeof(TW_Event)); |
| 396 | |
| 397 | event->severity = TW_SEV_OUT(header->status_block.severity__reserved); |
Arnd Bergmann | 9c88673f | 2017-11-10 16:58:25 +0100 | [diff] [blame] | 398 | /* event->time_stamp_sec overflows in y2106 */ |
| 399 | local_time = (u32)(ktime_get_real_seconds() - (sys_tz.tz_minuteswest * 60)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 400 | event->time_stamp_sec = local_time; |
| 401 | event->aen_code = aen; |
| 402 | event->retrieved = TW_AEN_NOT_RETRIEVED; |
| 403 | event->sequence_id = tw_dev->error_sequence_id; |
| 404 | tw_dev->error_sequence_id++; |
| 405 | |
| 406 | /* Check for embedded error string */ |
| 407 | error_str = &(header->err_specific_desc[strlen(header->err_specific_desc)+1]); |
| 408 | |
| 409 | header->err_specific_desc[sizeof(header->err_specific_desc) - 1] = '\0'; |
| 410 | event->parameter_len = strlen(header->err_specific_desc); |
adam radford | 75913d9 | 2006-03-15 12:43:19 -0800 | [diff] [blame] | 411 | memcpy(event->parameter_data, header->err_specific_desc, event->parameter_len + (error_str[0] == '\0' ? 0 : (1 + strlen(error_str)))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 412 | if (event->severity != TW_AEN_SEVERITY_DEBUG) |
| 413 | printk(KERN_WARNING "3w-9xxx:%s AEN: %s (0x%02X:0x%04X): %s:%s.\n", |
| 414 | host, |
| 415 | twa_aen_severity_lookup(TW_SEV_OUT(header->status_block.severity__reserved)), |
| 416 | TW_MESSAGE_SOURCE_CONTROLLER_EVENT, aen, |
| 417 | error_str[0] == '\0' ? twa_string_lookup(twa_aen_table, aen) : error_str, |
| 418 | header->err_specific_desc); |
| 419 | else |
| 420 | tw_dev->aen_count--; |
| 421 | |
| 422 | if ((tw_dev->error_index + 1) == TW_Q_LENGTH) |
| 423 | tw_dev->event_queue_wrapped = 1; |
| 424 | tw_dev->error_index = (tw_dev->error_index + 1 ) % TW_Q_LENGTH; |
| 425 | } /* End twa_aen_queue_event() */ |
| 426 | |
| 427 | /* This function will read the aen queue from the isr */ |
| 428 | static int twa_aen_read_queue(TW_Device_Extension *tw_dev, int request_id) |
| 429 | { |
Nathan Chancellor | 09968e5 | 2018-10-18 14:55:41 -0700 | [diff] [blame] | 430 | unsigned char cdb[TW_MAX_CDB_LEN]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 431 | TW_SG_Entry sglist[1]; |
| 432 | TW_Command_Full *full_command_packet; |
| 433 | int retval = 1; |
| 434 | |
| 435 | full_command_packet = tw_dev->command_packet_virt[request_id]; |
| 436 | memset(full_command_packet, 0, sizeof(TW_Command_Full)); |
| 437 | |
| 438 | /* Initialize cdb */ |
| 439 | memset(&cdb, 0, TW_MAX_CDB_LEN); |
| 440 | cdb[0] = REQUEST_SENSE; /* opcode */ |
| 441 | cdb[4] = TW_ALLOCATION_LENGTH; /* allocation length */ |
| 442 | |
| 443 | /* Initialize sglist */ |
| 444 | memset(&sglist, 0, sizeof(TW_SG_Entry)); |
Samuel Holland | 05f7f1b9 | 2021-04-27 18:59:15 -0500 | [diff] [blame] | 445 | sglist[0].length = cpu_to_le32(TW_SECTOR_SIZE); |
| 446 | sglist[0].address = TW_CPU_TO_SGL(tw_dev->generic_buffer_phys[request_id]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 447 | |
| 448 | /* Mark internal command */ |
| 449 | tw_dev->srb[request_id] = NULL; |
| 450 | |
| 451 | /* Now post the command packet */ |
| 452 | if (twa_scsiop_execute_scsi(tw_dev, request_id, cdb, 1, sglist)) { |
| 453 | TW_PRINTK(tw_dev->host, TW_DRIVER, 0x4, "Post failed while reading AEN queue"); |
| 454 | goto out; |
| 455 | } |
| 456 | retval = 0; |
| 457 | out: |
| 458 | return retval; |
| 459 | } /* End twa_aen_read_queue() */ |
| 460 | |
| 461 | /* This function will look up an AEN severity string */ |
| 462 | static char *twa_aen_severity_lookup(unsigned char severity_code) |
| 463 | { |
| 464 | char *retval = NULL; |
| 465 | |
| 466 | if ((severity_code < (unsigned char) TW_AEN_SEVERITY_ERROR) || |
| 467 | (severity_code > (unsigned char) TW_AEN_SEVERITY_DEBUG)) |
| 468 | goto out; |
| 469 | |
| 470 | retval = twa_aen_severity_table[severity_code]; |
| 471 | out: |
| 472 | return retval; |
| 473 | } /* End twa_aen_severity_lookup() */ |
| 474 | |
| 475 | /* This function will sync firmware time with the host time */ |
| 476 | static void twa_aen_sync_time(TW_Device_Extension *tw_dev, int request_id) |
| 477 | { |
| 478 | u32 schedulertime; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 479 | TW_Command_Full *full_command_packet; |
| 480 | TW_Command *command_packet; |
| 481 | TW_Param_Apache *param; |
Arnd Bergmann | bc8f916 | 2017-11-10 16:58:26 +0100 | [diff] [blame] | 482 | time64_t local_time; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 483 | |
| 484 | /* Fill out the command packet */ |
| 485 | full_command_packet = tw_dev->command_packet_virt[request_id]; |
| 486 | memset(full_command_packet, 0, sizeof(TW_Command_Full)); |
| 487 | command_packet = &full_command_packet->command.oldcommand; |
| 488 | command_packet->opcode__sgloffset = TW_OPSGL_IN(2, TW_OP_SET_PARAM); |
| 489 | command_packet->request_id = request_id; |
adam radford | 75913d9 | 2006-03-15 12:43:19 -0800 | [diff] [blame] | 490 | command_packet->byte8_offset.param.sgl[0].address = TW_CPU_TO_SGL(tw_dev->generic_buffer_phys[request_id]); |
| 491 | command_packet->byte8_offset.param.sgl[0].length = cpu_to_le32(TW_SECTOR_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 492 | command_packet->size = TW_COMMAND_SIZE; |
adam radford | 75913d9 | 2006-03-15 12:43:19 -0800 | [diff] [blame] | 493 | command_packet->byte6_offset.parameter_count = cpu_to_le16(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 494 | |
| 495 | /* Setup the param */ |
| 496 | param = (TW_Param_Apache *)tw_dev->generic_buffer_virt[request_id]; |
| 497 | memset(param, 0, TW_SECTOR_SIZE); |
adam radford | 75913d9 | 2006-03-15 12:43:19 -0800 | [diff] [blame] | 498 | param->table_id = cpu_to_le16(TW_TIMEKEEP_TABLE | 0x8000); /* Controller time keep table */ |
| 499 | param->parameter_id = cpu_to_le16(0x3); /* SchedulerTime */ |
| 500 | param->parameter_size_bytes = cpu_to_le16(4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 501 | |
Hannes Reinecke | bf4eebb | 2021-01-13 10:04:28 +0100 | [diff] [blame] | 502 | /* Convert system time in UTC to local time seconds since last |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 503 | Sunday 12:00AM */ |
Arnd Bergmann | bc8f916 | 2017-11-10 16:58:26 +0100 | [diff] [blame] | 504 | local_time = (ktime_get_real_seconds() - (sys_tz.tz_minuteswest * 60)); |
| 505 | div_u64_rem(local_time - (3 * 86400), 604800, &schedulertime); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 506 | |
Samuel Holland | 05f7f1b9 | 2021-04-27 18:59:15 -0500 | [diff] [blame] | 507 | memcpy(param->data, &(__le32){cpu_to_le32(schedulertime)}, sizeof(__le32)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 508 | |
| 509 | /* Mark internal command */ |
| 510 | tw_dev->srb[request_id] = NULL; |
| 511 | |
| 512 | /* Now post the command */ |
| 513 | twa_post_command_packet(tw_dev, request_id, 1); |
| 514 | } /* End twa_aen_sync_time() */ |
| 515 | |
| 516 | /* This function will allocate memory and check if it is correctly aligned */ |
| 517 | static int twa_allocate_memory(TW_Device_Extension *tw_dev, int size, int which) |
| 518 | { |
| 519 | int i; |
| 520 | dma_addr_t dma_handle; |
| 521 | unsigned long *cpu_addr; |
| 522 | int retval = 1; |
| 523 | |
Christoph Hellwig | b000bce | 2018-10-10 17:53:41 +0200 | [diff] [blame] | 524 | cpu_addr = dma_alloc_coherent(&tw_dev->tw_pci_dev->dev, |
| 525 | size * TW_Q_LENGTH, &dma_handle, GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 526 | if (!cpu_addr) { |
| 527 | TW_PRINTK(tw_dev->host, TW_DRIVER, 0x5, "Memory allocation failed"); |
| 528 | goto out; |
| 529 | } |
| 530 | |
| 531 | if ((unsigned long)cpu_addr % (TW_ALIGNMENT_9000)) { |
| 532 | TW_PRINTK(tw_dev->host, TW_DRIVER, 0x6, "Failed to allocate correctly aligned memory"); |
Christoph Hellwig | b000bce | 2018-10-10 17:53:41 +0200 | [diff] [blame] | 533 | dma_free_coherent(&tw_dev->tw_pci_dev->dev, size * TW_Q_LENGTH, |
| 534 | cpu_addr, dma_handle); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 535 | goto out; |
| 536 | } |
| 537 | |
| 538 | memset(cpu_addr, 0, size*TW_Q_LENGTH); |
| 539 | |
| 540 | for (i = 0; i < TW_Q_LENGTH; i++) { |
| 541 | switch(which) { |
| 542 | case 0: |
| 543 | tw_dev->command_packet_phys[i] = dma_handle+(i*size); |
| 544 | tw_dev->command_packet_virt[i] = (TW_Command_Full *)((unsigned char *)cpu_addr + (i*size)); |
| 545 | break; |
| 546 | case 1: |
| 547 | tw_dev->generic_buffer_phys[i] = dma_handle+(i*size); |
| 548 | tw_dev->generic_buffer_virt[i] = (unsigned long *)((unsigned char *)cpu_addr + (i*size)); |
| 549 | break; |
| 550 | } |
| 551 | } |
| 552 | retval = 0; |
| 553 | out: |
| 554 | return retval; |
| 555 | } /* End twa_allocate_memory() */ |
| 556 | |
| 557 | /* This function will check the status register for unexpected bits */ |
| 558 | static int twa_check_bits(u32 status_reg_value) |
| 559 | { |
| 560 | int retval = 1; |
| 561 | |
| 562 | if ((status_reg_value & TW_STATUS_EXPECTED_BITS) != TW_STATUS_EXPECTED_BITS) |
| 563 | goto out; |
| 564 | if ((status_reg_value & TW_STATUS_UNEXPECTED_BITS) != 0) |
| 565 | goto out; |
| 566 | |
| 567 | retval = 0; |
| 568 | out: |
| 569 | return retval; |
| 570 | } /* End twa_check_bits() */ |
| 571 | |
| 572 | /* This function will check the srl and decide if we are compatible */ |
| 573 | static int twa_check_srl(TW_Device_Extension *tw_dev, int *flashed) |
| 574 | { |
| 575 | int retval = 1; |
| 576 | unsigned short fw_on_ctlr_srl = 0, fw_on_ctlr_arch_id = 0; |
| 577 | unsigned short fw_on_ctlr_branch = 0, fw_on_ctlr_build = 0; |
| 578 | u32 init_connect_result = 0; |
| 579 | |
| 580 | if (twa_initconnection(tw_dev, TW_INIT_MESSAGE_CREDITS, |
| 581 | TW_EXTENDED_INIT_CONNECT, TW_CURRENT_DRIVER_SRL, |
| 582 | TW_9000_ARCH_ID, TW_CURRENT_DRIVER_BRANCH, |
| 583 | TW_CURRENT_DRIVER_BUILD, &fw_on_ctlr_srl, |
| 584 | &fw_on_ctlr_arch_id, &fw_on_ctlr_branch, |
| 585 | &fw_on_ctlr_build, &init_connect_result)) { |
| 586 | TW_PRINTK(tw_dev->host, TW_DRIVER, 0x7, "Initconnection failed while checking SRL"); |
| 587 | goto out; |
| 588 | } |
| 589 | |
adam radford | 4039c30 | 2006-10-26 18:01:06 -0700 | [diff] [blame] | 590 | tw_dev->tw_compat_info.working_srl = fw_on_ctlr_srl; |
| 591 | tw_dev->tw_compat_info.working_branch = fw_on_ctlr_branch; |
| 592 | tw_dev->tw_compat_info.working_build = fw_on_ctlr_build; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 593 | |
| 594 | /* Try base mode compatibility */ |
| 595 | if (!(init_connect_result & TW_CTLR_FW_COMPATIBLE)) { |
| 596 | if (twa_initconnection(tw_dev, TW_INIT_MESSAGE_CREDITS, |
| 597 | TW_EXTENDED_INIT_CONNECT, |
| 598 | TW_BASE_FW_SRL, TW_9000_ARCH_ID, |
| 599 | TW_BASE_FW_BRANCH, TW_BASE_FW_BUILD, |
| 600 | &fw_on_ctlr_srl, &fw_on_ctlr_arch_id, |
| 601 | &fw_on_ctlr_branch, &fw_on_ctlr_build, |
| 602 | &init_connect_result)) { |
| 603 | TW_PRINTK(tw_dev->host, TW_DRIVER, 0xa, "Initconnection (base mode) failed while checking SRL"); |
| 604 | goto out; |
| 605 | } |
| 606 | if (!(init_connect_result & TW_CTLR_FW_COMPATIBLE)) { |
| 607 | if (TW_CURRENT_DRIVER_SRL > fw_on_ctlr_srl) { |
| 608 | TW_PRINTK(tw_dev->host, TW_DRIVER, 0x32, "Firmware and driver incompatibility: please upgrade firmware"); |
| 609 | } else { |
| 610 | TW_PRINTK(tw_dev->host, TW_DRIVER, 0x33, "Firmware and driver incompatibility: please upgrade driver"); |
| 611 | } |
| 612 | goto out; |
| 613 | } |
adam radford | 4039c30 | 2006-10-26 18:01:06 -0700 | [diff] [blame] | 614 | tw_dev->tw_compat_info.working_srl = TW_BASE_FW_SRL; |
| 615 | tw_dev->tw_compat_info.working_branch = TW_BASE_FW_BRANCH; |
| 616 | tw_dev->tw_compat_info.working_build = TW_BASE_FW_BUILD; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 617 | } |
adam radford | 4039c30 | 2006-10-26 18:01:06 -0700 | [diff] [blame] | 618 | |
| 619 | /* Load rest of compatibility struct */ |
Rickard Strandqvist | 2195d96 | 2014-07-27 17:11:18 +0200 | [diff] [blame] | 620 | strlcpy(tw_dev->tw_compat_info.driver_version, TW_DRIVER_VERSION, |
| 621 | sizeof(tw_dev->tw_compat_info.driver_version)); |
adam radford | 4039c30 | 2006-10-26 18:01:06 -0700 | [diff] [blame] | 622 | tw_dev->tw_compat_info.driver_srl_high = TW_CURRENT_DRIVER_SRL; |
| 623 | tw_dev->tw_compat_info.driver_branch_high = TW_CURRENT_DRIVER_BRANCH; |
| 624 | tw_dev->tw_compat_info.driver_build_high = TW_CURRENT_DRIVER_BUILD; |
| 625 | tw_dev->tw_compat_info.driver_srl_low = TW_BASE_FW_SRL; |
| 626 | tw_dev->tw_compat_info.driver_branch_low = TW_BASE_FW_BRANCH; |
| 627 | tw_dev->tw_compat_info.driver_build_low = TW_BASE_FW_BUILD; |
| 628 | tw_dev->tw_compat_info.fw_on_ctlr_srl = fw_on_ctlr_srl; |
| 629 | tw_dev->tw_compat_info.fw_on_ctlr_branch = fw_on_ctlr_branch; |
| 630 | tw_dev->tw_compat_info.fw_on_ctlr_build = fw_on_ctlr_build; |
| 631 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 632 | retval = 0; |
| 633 | out: |
| 634 | return retval; |
| 635 | } /* End twa_check_srl() */ |
| 636 | |
| 637 | /* This function handles ioctl for the character device */ |
Arnd Bergmann | f4927c4 | 2010-04-27 00:24:01 +0200 | [diff] [blame] | 638 | static long twa_chrdev_ioctl(struct file *file, unsigned int cmd, unsigned long arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 639 | { |
Al Viro | 496ad9a | 2013-01-23 17:07:38 -0500 | [diff] [blame] | 640 | struct inode *inode = file_inode(file); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 641 | long timeout; |
| 642 | unsigned long *cpu_addr, data_buffer_length_adjusted = 0, flags = 0; |
| 643 | dma_addr_t dma_handle; |
| 644 | int request_id = 0; |
| 645 | unsigned int sequence_id = 0; |
| 646 | unsigned char event_index, start_index; |
| 647 | TW_Ioctl_Driver_Command driver_command; |
| 648 | TW_Ioctl_Buf_Apache *tw_ioctl; |
| 649 | TW_Lock *tw_lock; |
| 650 | TW_Command_Full *full_command_packet; |
| 651 | TW_Compatibility_Info *tw_compat_info; |
| 652 | TW_Event *event; |
Arnd Bergmann | 07ffd4c | 2017-11-10 16:58:27 +0100 | [diff] [blame] | 653 | ktime_t current_time; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 654 | TW_Device_Extension *tw_dev = twa_device_extension_list[iminor(inode)]; |
| 655 | int retval = TW_IOCTL_ERROR_OS_EFAULT; |
| 656 | void __user *argp = (void __user *)arg; |
| 657 | |
Arnd Bergmann | c45d15d | 2010-06-02 14:28:52 +0200 | [diff] [blame] | 658 | mutex_lock(&twa_chrdev_mutex); |
Arnd Bergmann | f4927c4 | 2010-04-27 00:24:01 +0200 | [diff] [blame] | 659 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 660 | /* Only let one of these through at a time */ |
Jes Sorensen | a12e25bd | 2006-01-11 08:39:45 -0500 | [diff] [blame] | 661 | if (mutex_lock_interruptible(&tw_dev->ioctl_lock)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 662 | retval = TW_IOCTL_ERROR_OS_EINTR; |
| 663 | goto out; |
| 664 | } |
| 665 | |
| 666 | /* First copy down the driver command */ |
| 667 | if (copy_from_user(&driver_command, argp, sizeof(TW_Ioctl_Driver_Command))) |
| 668 | goto out2; |
| 669 | |
| 670 | /* Check data buffer size */ |
adam radford | 4039c30 | 2006-10-26 18:01:06 -0700 | [diff] [blame] | 671 | if (driver_command.buffer_length > TW_MAX_SECTORS * 2048) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 672 | retval = TW_IOCTL_ERROR_OS_EINVAL; |
| 673 | goto out2; |
| 674 | } |
| 675 | |
| 676 | /* Hardware can only do multiple of 512 byte transfers */ |
| 677 | data_buffer_length_adjusted = (driver_command.buffer_length + 511) & ~511; |
| 678 | |
| 679 | /* Now allocate ioctl buf memory */ |
Samuel Holland | 44c5027 | 2021-04-27 18:59:13 -0500 | [diff] [blame] | 680 | cpu_addr = dma_alloc_coherent(&tw_dev->tw_pci_dev->dev, |
| 681 | sizeof(TW_Ioctl_Buf_Apache) + data_buffer_length_adjusted, |
| 682 | &dma_handle, GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 683 | if (!cpu_addr) { |
| 684 | retval = TW_IOCTL_ERROR_OS_ENOMEM; |
| 685 | goto out2; |
| 686 | } |
| 687 | |
| 688 | tw_ioctl = (TW_Ioctl_Buf_Apache *)cpu_addr; |
| 689 | |
| 690 | /* Now copy down the entire ioctl */ |
Samuel Holland | 44c5027 | 2021-04-27 18:59:13 -0500 | [diff] [blame] | 691 | if (copy_from_user(tw_ioctl, argp, sizeof(TW_Ioctl_Buf_Apache) + driver_command.buffer_length)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 692 | goto out3; |
| 693 | |
| 694 | /* See which ioctl we are doing */ |
| 695 | switch (cmd) { |
| 696 | case TW_IOCTL_FIRMWARE_PASS_THROUGH: |
| 697 | spin_lock_irqsave(tw_dev->host->host_lock, flags); |
| 698 | twa_get_request_id(tw_dev, &request_id); |
| 699 | |
| 700 | /* Flag internal command */ |
| 701 | tw_dev->srb[request_id] = NULL; |
| 702 | |
| 703 | /* Flag chrdev ioctl */ |
| 704 | tw_dev->chrdev_request_id = request_id; |
| 705 | |
| 706 | full_command_packet = &tw_ioctl->firmware_command; |
| 707 | |
| 708 | /* Load request id and sglist for both command types */ |
adam radford | 0e78d15 | 2007-07-20 15:28:28 -0700 | [diff] [blame] | 709 | twa_load_sgl(tw_dev, full_command_packet, request_id, dma_handle, data_buffer_length_adjusted); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 710 | |
| 711 | memcpy(tw_dev->command_packet_virt[request_id], &(tw_ioctl->firmware_command), sizeof(TW_Command_Full)); |
| 712 | |
| 713 | /* Now post the command packet to the controller */ |
| 714 | twa_post_command_packet(tw_dev, request_id, 1); |
| 715 | spin_unlock_irqrestore(tw_dev->host->host_lock, flags); |
| 716 | |
| 717 | timeout = TW_IOCTL_CHRDEV_TIMEOUT*HZ; |
| 718 | |
| 719 | /* Now wait for command to complete */ |
| 720 | timeout = wait_event_timeout(tw_dev->ioctl_wqueue, tw_dev->chrdev_request_id == TW_IOCTL_CHRDEV_FREE, timeout); |
| 721 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 722 | /* We timed out, and didn't get an interrupt */ |
| 723 | if (tw_dev->chrdev_request_id != TW_IOCTL_CHRDEV_FREE) { |
| 724 | /* Now we need to reset the board */ |
| 725 | printk(KERN_WARNING "3w-9xxx: scsi%d: WARNING: (0x%02X:0x%04X): Character ioctl (0x%x) timed out, resetting card.\n", |
adam radford | 0e78d15 | 2007-07-20 15:28:28 -0700 | [diff] [blame] | 726 | tw_dev->host->host_no, TW_DRIVER, 0x37, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 727 | cmd); |
| 728 | retval = TW_IOCTL_ERROR_OS_EIO; |
adam radford | 0e78d15 | 2007-07-20 15:28:28 -0700 | [diff] [blame] | 729 | twa_reset_device_extension(tw_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 730 | goto out3; |
| 731 | } |
| 732 | |
| 733 | /* Now copy in the command packet response */ |
| 734 | memcpy(&(tw_ioctl->firmware_command), tw_dev->command_packet_virt[request_id], sizeof(TW_Command_Full)); |
Hannes Reinecke | bf4eebb | 2021-01-13 10:04:28 +0100 | [diff] [blame] | 735 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 736 | /* Now complete the io */ |
| 737 | spin_lock_irqsave(tw_dev->host->host_lock, flags); |
| 738 | tw_dev->posted_request_count--; |
| 739 | tw_dev->state[request_id] = TW_S_COMPLETED; |
| 740 | twa_free_request_id(tw_dev, request_id); |
| 741 | spin_unlock_irqrestore(tw_dev->host->host_lock, flags); |
| 742 | break; |
| 743 | case TW_IOCTL_GET_COMPATIBILITY_INFO: |
| 744 | tw_ioctl->driver_command.status = 0; |
Dirk Hohndel | 06fe9fb | 2009-09-28 21:43:57 -0400 | [diff] [blame] | 745 | /* Copy compatibility struct into ioctl data buffer */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 746 | tw_compat_info = (TW_Compatibility_Info *)tw_ioctl->data_buffer; |
adam radford | 4039c30 | 2006-10-26 18:01:06 -0700 | [diff] [blame] | 747 | memcpy(tw_compat_info, &tw_dev->tw_compat_info, sizeof(TW_Compatibility_Info)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 748 | break; |
| 749 | case TW_IOCTL_GET_LAST_EVENT: |
| 750 | if (tw_dev->event_queue_wrapped) { |
| 751 | if (tw_dev->aen_clobber) { |
| 752 | tw_ioctl->driver_command.status = TW_IOCTL_ERROR_STATUS_AEN_CLOBBER; |
| 753 | tw_dev->aen_clobber = 0; |
| 754 | } else |
| 755 | tw_ioctl->driver_command.status = 0; |
| 756 | } else { |
| 757 | if (!tw_dev->error_index) { |
| 758 | tw_ioctl->driver_command.status = TW_IOCTL_ERROR_STATUS_NO_MORE_EVENTS; |
| 759 | break; |
| 760 | } |
| 761 | tw_ioctl->driver_command.status = 0; |
| 762 | } |
| 763 | event_index = (tw_dev->error_index - 1 + TW_Q_LENGTH) % TW_Q_LENGTH; |
| 764 | memcpy(tw_ioctl->data_buffer, tw_dev->event_queue[event_index], sizeof(TW_Event)); |
| 765 | tw_dev->event_queue[event_index]->retrieved = TW_AEN_RETRIEVED; |
| 766 | break; |
| 767 | case TW_IOCTL_GET_FIRST_EVENT: |
| 768 | if (tw_dev->event_queue_wrapped) { |
| 769 | if (tw_dev->aen_clobber) { |
| 770 | tw_ioctl->driver_command.status = TW_IOCTL_ERROR_STATUS_AEN_CLOBBER; |
| 771 | tw_dev->aen_clobber = 0; |
Hannes Reinecke | bf4eebb | 2021-01-13 10:04:28 +0100 | [diff] [blame] | 772 | } else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 773 | tw_ioctl->driver_command.status = 0; |
| 774 | event_index = tw_dev->error_index; |
| 775 | } else { |
| 776 | if (!tw_dev->error_index) { |
| 777 | tw_ioctl->driver_command.status = TW_IOCTL_ERROR_STATUS_NO_MORE_EVENTS; |
| 778 | break; |
| 779 | } |
| 780 | tw_ioctl->driver_command.status = 0; |
| 781 | event_index = 0; |
| 782 | } |
| 783 | memcpy(tw_ioctl->data_buffer, tw_dev->event_queue[event_index], sizeof(TW_Event)); |
| 784 | tw_dev->event_queue[event_index]->retrieved = TW_AEN_RETRIEVED; |
| 785 | break; |
| 786 | case TW_IOCTL_GET_NEXT_EVENT: |
| 787 | event = (TW_Event *)tw_ioctl->data_buffer; |
| 788 | sequence_id = event->sequence_id; |
| 789 | tw_ioctl->driver_command.status = 0; |
| 790 | |
| 791 | if (tw_dev->event_queue_wrapped) { |
| 792 | if (tw_dev->aen_clobber) { |
| 793 | tw_ioctl->driver_command.status = TW_IOCTL_ERROR_STATUS_AEN_CLOBBER; |
| 794 | tw_dev->aen_clobber = 0; |
| 795 | } |
| 796 | start_index = tw_dev->error_index; |
| 797 | } else { |
| 798 | if (!tw_dev->error_index) { |
| 799 | tw_ioctl->driver_command.status = TW_IOCTL_ERROR_STATUS_NO_MORE_EVENTS; |
| 800 | break; |
| 801 | } |
| 802 | start_index = 0; |
| 803 | } |
| 804 | event_index = (start_index + sequence_id - tw_dev->event_queue[start_index]->sequence_id + 1) % TW_Q_LENGTH; |
| 805 | |
| 806 | if (!(tw_dev->event_queue[event_index]->sequence_id > sequence_id)) { |
| 807 | if (tw_ioctl->driver_command.status == TW_IOCTL_ERROR_STATUS_AEN_CLOBBER) |
| 808 | tw_dev->aen_clobber = 1; |
| 809 | tw_ioctl->driver_command.status = TW_IOCTL_ERROR_STATUS_NO_MORE_EVENTS; |
| 810 | break; |
| 811 | } |
| 812 | memcpy(tw_ioctl->data_buffer, tw_dev->event_queue[event_index], sizeof(TW_Event)); |
| 813 | tw_dev->event_queue[event_index]->retrieved = TW_AEN_RETRIEVED; |
| 814 | break; |
| 815 | case TW_IOCTL_GET_PREVIOUS_EVENT: |
| 816 | event = (TW_Event *)tw_ioctl->data_buffer; |
| 817 | sequence_id = event->sequence_id; |
| 818 | tw_ioctl->driver_command.status = 0; |
| 819 | |
| 820 | if (tw_dev->event_queue_wrapped) { |
| 821 | if (tw_dev->aen_clobber) { |
| 822 | tw_ioctl->driver_command.status = TW_IOCTL_ERROR_STATUS_AEN_CLOBBER; |
| 823 | tw_dev->aen_clobber = 0; |
| 824 | } |
| 825 | start_index = tw_dev->error_index; |
| 826 | } else { |
| 827 | if (!tw_dev->error_index) { |
| 828 | tw_ioctl->driver_command.status = TW_IOCTL_ERROR_STATUS_NO_MORE_EVENTS; |
| 829 | break; |
| 830 | } |
| 831 | start_index = 0; |
| 832 | } |
| 833 | event_index = (start_index + sequence_id - tw_dev->event_queue[start_index]->sequence_id - 1) % TW_Q_LENGTH; |
| 834 | |
| 835 | if (!(tw_dev->event_queue[event_index]->sequence_id < sequence_id)) { |
| 836 | if (tw_ioctl->driver_command.status == TW_IOCTL_ERROR_STATUS_AEN_CLOBBER) |
| 837 | tw_dev->aen_clobber = 1; |
| 838 | tw_ioctl->driver_command.status = TW_IOCTL_ERROR_STATUS_NO_MORE_EVENTS; |
| 839 | break; |
| 840 | } |
| 841 | memcpy(tw_ioctl->data_buffer, tw_dev->event_queue[event_index], sizeof(TW_Event)); |
| 842 | tw_dev->event_queue[event_index]->retrieved = TW_AEN_RETRIEVED; |
| 843 | break; |
| 844 | case TW_IOCTL_GET_LOCK: |
| 845 | tw_lock = (TW_Lock *)tw_ioctl->data_buffer; |
Arnd Bergmann | 07ffd4c | 2017-11-10 16:58:27 +0100 | [diff] [blame] | 846 | current_time = ktime_get(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 847 | |
Arnd Bergmann | 07ffd4c | 2017-11-10 16:58:27 +0100 | [diff] [blame] | 848 | if ((tw_lock->force_flag == 1) || (tw_dev->ioctl_sem_lock == 0) || |
| 849 | ktime_after(current_time, tw_dev->ioctl_time)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 850 | tw_dev->ioctl_sem_lock = 1; |
Arnd Bergmann | 07ffd4c | 2017-11-10 16:58:27 +0100 | [diff] [blame] | 851 | tw_dev->ioctl_time = ktime_add_ms(current_time, tw_lock->timeout_msec); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 852 | tw_ioctl->driver_command.status = 0; |
| 853 | tw_lock->time_remaining_msec = tw_lock->timeout_msec; |
| 854 | } else { |
| 855 | tw_ioctl->driver_command.status = TW_IOCTL_ERROR_STATUS_LOCKED; |
Arnd Bergmann | 07ffd4c | 2017-11-10 16:58:27 +0100 | [diff] [blame] | 856 | tw_lock->time_remaining_msec = ktime_ms_delta(tw_dev->ioctl_time, current_time); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 857 | } |
| 858 | break; |
| 859 | case TW_IOCTL_RELEASE_LOCK: |
| 860 | if (tw_dev->ioctl_sem_lock == 1) { |
| 861 | tw_dev->ioctl_sem_lock = 0; |
| 862 | tw_ioctl->driver_command.status = 0; |
| 863 | } else { |
| 864 | tw_ioctl->driver_command.status = TW_IOCTL_ERROR_STATUS_NOT_LOCKED; |
| 865 | } |
| 866 | break; |
| 867 | default: |
| 868 | retval = TW_IOCTL_ERROR_OS_ENOTTY; |
| 869 | goto out3; |
| 870 | } |
| 871 | |
| 872 | /* Now copy the entire response to userspace */ |
Samuel Holland | 44c5027 | 2021-04-27 18:59:13 -0500 | [diff] [blame] | 873 | if (copy_to_user(argp, tw_ioctl, sizeof(TW_Ioctl_Buf_Apache) + driver_command.buffer_length) == 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 874 | retval = 0; |
| 875 | out3: |
| 876 | /* Now free ioctl buf memory */ |
Samuel Holland | 44c5027 | 2021-04-27 18:59:13 -0500 | [diff] [blame] | 877 | dma_free_coherent(&tw_dev->tw_pci_dev->dev, |
| 878 | sizeof(TW_Ioctl_Buf_Apache) + data_buffer_length_adjusted, |
| 879 | cpu_addr, dma_handle); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 880 | out2: |
Jes Sorensen | a12e25bd | 2006-01-11 08:39:45 -0500 | [diff] [blame] | 881 | mutex_unlock(&tw_dev->ioctl_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 882 | out: |
Arnd Bergmann | c45d15d | 2010-06-02 14:28:52 +0200 | [diff] [blame] | 883 | mutex_unlock(&twa_chrdev_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 884 | return retval; |
| 885 | } /* End twa_chrdev_ioctl() */ |
| 886 | |
| 887 | /* This function handles open for the character device */ |
Jonathan Corbet | f2b9857 | 2008-05-18 15:32:43 -0600 | [diff] [blame] | 888 | /* NOTE that this function will race with remove. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 889 | static int twa_chrdev_open(struct inode *inode, struct file *file) |
| 890 | { |
| 891 | unsigned int minor_number; |
| 892 | int retval = TW_IOCTL_ERROR_OS_ENODEV; |
| 893 | |
Wenwen Wang | c9318a3 | 2018-05-07 19:46:43 -0500 | [diff] [blame] | 894 | if (!capable(CAP_SYS_ADMIN)) { |
| 895 | retval = -EACCES; |
| 896 | goto out; |
| 897 | } |
| 898 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 899 | minor_number = iminor(inode); |
| 900 | if (minor_number >= twa_device_extension_count) |
| 901 | goto out; |
| 902 | retval = 0; |
| 903 | out: |
| 904 | return retval; |
| 905 | } /* End twa_chrdev_open() */ |
| 906 | |
| 907 | /* This function will print readable messages from status register errors */ |
| 908 | static int twa_decode_bits(TW_Device_Extension *tw_dev, u32 status_reg_value) |
| 909 | { |
| 910 | int retval = 1; |
| 911 | |
| 912 | /* Check for various error conditions and handle them appropriately */ |
| 913 | if (status_reg_value & TW_STATUS_PCI_PARITY_ERROR) { |
| 914 | TW_PRINTK(tw_dev->host, TW_DRIVER, 0xc, "PCI Parity Error: clearing"); |
| 915 | writel(TW_CONTROL_CLEAR_PARITY_ERROR, TW_CONTROL_REG_ADDR(tw_dev)); |
| 916 | } |
| 917 | |
| 918 | if (status_reg_value & TW_STATUS_PCI_ABORT) { |
| 919 | TW_PRINTK(tw_dev->host, TW_DRIVER, 0xd, "PCI Abort: clearing"); |
| 920 | writel(TW_CONTROL_CLEAR_PCI_ABORT, TW_CONTROL_REG_ADDR(tw_dev)); |
| 921 | pci_write_config_word(tw_dev->tw_pci_dev, PCI_STATUS, TW_PCI_CLEAR_PCI_ABORT); |
| 922 | } |
| 923 | |
| 924 | if (status_reg_value & TW_STATUS_QUEUE_ERROR) { |
adam radford | 0e78d15 | 2007-07-20 15:28:28 -0700 | [diff] [blame] | 925 | if (((tw_dev->tw_pci_dev->device != PCI_DEVICE_ID_3WARE_9650SE) && |
| 926 | (tw_dev->tw_pci_dev->device != PCI_DEVICE_ID_3WARE_9690SA)) || |
| 927 | (!test_bit(TW_IN_RESET, &tw_dev->flags))) |
adam radford | 4039c30 | 2006-10-26 18:01:06 -0700 | [diff] [blame] | 928 | TW_PRINTK(tw_dev->host, TW_DRIVER, 0xe, "Controller Queue Error: clearing"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 929 | writel(TW_CONTROL_CLEAR_QUEUE_ERROR, TW_CONTROL_REG_ADDR(tw_dev)); |
| 930 | } |
| 931 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 932 | if (status_reg_value & TW_STATUS_MICROCONTROLLER_ERROR) { |
| 933 | if (tw_dev->reset_print == 0) { |
| 934 | TW_PRINTK(tw_dev->host, TW_DRIVER, 0x10, "Microcontroller Error: clearing"); |
| 935 | tw_dev->reset_print = 1; |
| 936 | } |
| 937 | goto out; |
| 938 | } |
| 939 | retval = 0; |
| 940 | out: |
| 941 | return retval; |
| 942 | } /* End twa_decode_bits() */ |
| 943 | |
| 944 | /* This function will empty the response queue */ |
| 945 | static int twa_empty_response_queue(TW_Device_Extension *tw_dev) |
| 946 | { |
Lee Jones | ea7fb53 | 2021-03-12 09:47:37 +0000 | [diff] [blame] | 947 | u32 status_reg_value; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 948 | int count = 0, retval = 1; |
| 949 | |
| 950 | status_reg_value = readl(TW_STATUS_REG_ADDR(tw_dev)); |
| 951 | |
| 952 | while (((status_reg_value & TW_STATUS_RESPONSE_QUEUE_EMPTY) == 0) && (count < TW_MAX_RESPONSE_DRAIN)) { |
Lee Jones | ea7fb53 | 2021-03-12 09:47:37 +0000 | [diff] [blame] | 953 | readl(TW_RESPONSE_QUEUE_REG_ADDR(tw_dev)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 954 | status_reg_value = readl(TW_STATUS_REG_ADDR(tw_dev)); |
| 955 | count++; |
| 956 | } |
| 957 | if (count == TW_MAX_RESPONSE_DRAIN) |
| 958 | goto out; |
| 959 | |
| 960 | retval = 0; |
| 961 | out: |
| 962 | return retval; |
| 963 | } /* End twa_empty_response_queue() */ |
| 964 | |
adam radford | 49bfd8d | 2005-09-21 17:20:14 -0700 | [diff] [blame] | 965 | /* This function will clear the pchip/response queue on 9550SX */ |
| 966 | static int twa_empty_response_queue_large(TW_Device_Extension *tw_dev) |
| 967 | { |
adam radford | 75913d9 | 2006-03-15 12:43:19 -0800 | [diff] [blame] | 968 | u32 response_que_value = 0; |
| 969 | unsigned long before; |
| 970 | int retval = 1; |
adam radford | 49bfd8d | 2005-09-21 17:20:14 -0700 | [diff] [blame] | 971 | |
adam radford | 0e78d15 | 2007-07-20 15:28:28 -0700 | [diff] [blame] | 972 | if (tw_dev->tw_pci_dev->device != PCI_DEVICE_ID_3WARE_9000) { |
adam radford | 75913d9 | 2006-03-15 12:43:19 -0800 | [diff] [blame] | 973 | before = jiffies; |
| 974 | while ((response_que_value & TW_9550SX_DRAIN_COMPLETED) != TW_9550SX_DRAIN_COMPLETED) { |
adam radford | 49bfd8d | 2005-09-21 17:20:14 -0700 | [diff] [blame] | 975 | response_que_value = readl(TW_RESPONSE_QUEUE_REG_ADDR_LARGE(tw_dev)); |
adam radford | 4039c30 | 2006-10-26 18:01:06 -0700 | [diff] [blame] | 976 | msleep(1); |
adam radford | 75913d9 | 2006-03-15 12:43:19 -0800 | [diff] [blame] | 977 | if (time_after(jiffies, before + HZ * 30)) |
adam radford | 49bfd8d | 2005-09-21 17:20:14 -0700 | [diff] [blame] | 978 | goto out; |
adam radford | 49bfd8d | 2005-09-21 17:20:14 -0700 | [diff] [blame] | 979 | } |
adam radford | 75913d9 | 2006-03-15 12:43:19 -0800 | [diff] [blame] | 980 | /* P-chip settle time */ |
| 981 | msleep(500); |
adam radford | 49bfd8d | 2005-09-21 17:20:14 -0700 | [diff] [blame] | 982 | retval = 0; |
| 983 | } else |
| 984 | retval = 0; |
| 985 | out: |
| 986 | return retval; |
| 987 | } /* End twa_empty_response_queue_large() */ |
| 988 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 989 | /* This function passes sense keys from firmware to scsi layer */ |
| 990 | static int twa_fill_sense(TW_Device_Extension *tw_dev, int request_id, int copy_sense, int print_host) |
| 991 | { |
| 992 | TW_Command_Full *full_command_packet; |
| 993 | unsigned short error; |
| 994 | int retval = 1; |
| 995 | char *error_str; |
| 996 | |
| 997 | full_command_packet = tw_dev->command_packet_virt[request_id]; |
| 998 | |
| 999 | /* Check for embedded error string */ |
| 1000 | error_str = &(full_command_packet->header.err_specific_desc[strlen(full_command_packet->header.err_specific_desc) + 1]); |
| 1001 | |
| 1002 | /* Don't print error for Logical unit not supported during rollcall */ |
adam radford | 75913d9 | 2006-03-15 12:43:19 -0800 | [diff] [blame] | 1003 | error = le16_to_cpu(full_command_packet->header.status_block.error); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1004 | if ((error != TW_ERROR_LOGICAL_UNIT_NOT_SUPPORTED) && (error != TW_ERROR_UNIT_OFFLINE)) { |
| 1005 | if (print_host) |
| 1006 | printk(KERN_WARNING "3w-9xxx: scsi%d: ERROR: (0x%02X:0x%04X): %s:%s.\n", |
| 1007 | tw_dev->host->host_no, |
Samuel Holland | 05f7f1b9 | 2021-04-27 18:59:15 -0500 | [diff] [blame] | 1008 | TW_MESSAGE_SOURCE_CONTROLLER_ERROR, error, |
| 1009 | error_str[0] ? error_str : twa_string_lookup(twa_error_table, error), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1010 | full_command_packet->header.err_specific_desc); |
| 1011 | else |
| 1012 | printk(KERN_WARNING "3w-9xxx: ERROR: (0x%02X:0x%04X): %s:%s.\n", |
Samuel Holland | 05f7f1b9 | 2021-04-27 18:59:15 -0500 | [diff] [blame] | 1013 | TW_MESSAGE_SOURCE_CONTROLLER_ERROR, error, |
| 1014 | error_str[0] ? error_str : twa_string_lookup(twa_error_table, error), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1015 | full_command_packet->header.err_specific_desc); |
| 1016 | } |
| 1017 | |
| 1018 | if (copy_sense) { |
| 1019 | memcpy(tw_dev->srb[request_id]->sense_buffer, full_command_packet->header.sense_data, TW_SENSE_DATA_LENGTH); |
| 1020 | tw_dev->srb[request_id]->result = (full_command_packet->command.newcommand.status << 1); |
| 1021 | retval = TW_ISR_DONT_RESULT; |
| 1022 | goto out; |
| 1023 | } |
| 1024 | retval = 0; |
| 1025 | out: |
| 1026 | return retval; |
| 1027 | } /* End twa_fill_sense() */ |
| 1028 | |
| 1029 | /* This function will free up device extension resources */ |
| 1030 | static void twa_free_device_extension(TW_Device_Extension *tw_dev) |
| 1031 | { |
| 1032 | if (tw_dev->command_packet_virt[0]) |
Christoph Hellwig | b000bce | 2018-10-10 17:53:41 +0200 | [diff] [blame] | 1033 | dma_free_coherent(&tw_dev->tw_pci_dev->dev, |
| 1034 | sizeof(TW_Command_Full) * TW_Q_LENGTH, |
| 1035 | tw_dev->command_packet_virt[0], |
| 1036 | tw_dev->command_packet_phys[0]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1037 | |
| 1038 | if (tw_dev->generic_buffer_virt[0]) |
Christoph Hellwig | b000bce | 2018-10-10 17:53:41 +0200 | [diff] [blame] | 1039 | dma_free_coherent(&tw_dev->tw_pci_dev->dev, |
| 1040 | TW_SECTOR_SIZE * TW_Q_LENGTH, |
| 1041 | tw_dev->generic_buffer_virt[0], |
| 1042 | tw_dev->generic_buffer_phys[0]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1043 | |
Jesper Juhl | c9475cb | 2005-11-07 01:01:26 -0800 | [diff] [blame] | 1044 | kfree(tw_dev->event_queue[0]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1045 | } /* End twa_free_device_extension() */ |
| 1046 | |
| 1047 | /* This function will free a request id */ |
| 1048 | static void twa_free_request_id(TW_Device_Extension *tw_dev, int request_id) |
| 1049 | { |
| 1050 | tw_dev->free_queue[tw_dev->free_tail] = request_id; |
| 1051 | tw_dev->state[request_id] = TW_S_FINISHED; |
| 1052 | tw_dev->free_tail = (tw_dev->free_tail + 1) % TW_Q_LENGTH; |
| 1053 | } /* End twa_free_request_id() */ |
| 1054 | |
Alexey Dobriyan | 7f927fc | 2006-03-28 01:56:53 -0800 | [diff] [blame] | 1055 | /* This function will get parameter table entries from the firmware */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1056 | static void *twa_get_param(TW_Device_Extension *tw_dev, int request_id, int table_id, int parameter_id, int parameter_size_bytes) |
| 1057 | { |
| 1058 | TW_Command_Full *full_command_packet; |
| 1059 | TW_Command *command_packet; |
| 1060 | TW_Param_Apache *param; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1061 | void *retval = NULL; |
| 1062 | |
| 1063 | /* Setup the command packet */ |
| 1064 | full_command_packet = tw_dev->command_packet_virt[request_id]; |
| 1065 | memset(full_command_packet, 0, sizeof(TW_Command_Full)); |
| 1066 | command_packet = &full_command_packet->command.oldcommand; |
| 1067 | |
| 1068 | command_packet->opcode__sgloffset = TW_OPSGL_IN(2, TW_OP_GET_PARAM); |
Hannes Reinecke | bf4eebb | 2021-01-13 10:04:28 +0100 | [diff] [blame] | 1069 | command_packet->size = TW_COMMAND_SIZE; |
| 1070 | command_packet->request_id = request_id; |
adam radford | 75913d9 | 2006-03-15 12:43:19 -0800 | [diff] [blame] | 1071 | command_packet->byte6_offset.block_count = cpu_to_le16(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1072 | |
| 1073 | /* Now setup the param */ |
| 1074 | param = (TW_Param_Apache *)tw_dev->generic_buffer_virt[request_id]; |
| 1075 | memset(param, 0, TW_SECTOR_SIZE); |
adam radford | 75913d9 | 2006-03-15 12:43:19 -0800 | [diff] [blame] | 1076 | param->table_id = cpu_to_le16(table_id | 0x8000); |
| 1077 | param->parameter_id = cpu_to_le16(parameter_id); |
| 1078 | param->parameter_size_bytes = cpu_to_le16(parameter_size_bytes); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1079 | |
adam radford | 3dabec7 | 2008-07-22 16:47:40 -0700 | [diff] [blame] | 1080 | command_packet->byte8_offset.param.sgl[0].address = TW_CPU_TO_SGL(tw_dev->generic_buffer_phys[request_id]); |
adam radford | 75913d9 | 2006-03-15 12:43:19 -0800 | [diff] [blame] | 1081 | command_packet->byte8_offset.param.sgl[0].length = cpu_to_le32(TW_SECTOR_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1082 | |
| 1083 | /* Post the command packet to the board */ |
| 1084 | twa_post_command_packet(tw_dev, request_id, 1); |
| 1085 | |
| 1086 | /* Poll for completion */ |
| 1087 | if (twa_poll_response(tw_dev, request_id, 30)) |
| 1088 | TW_PRINTK(tw_dev->host, TW_DRIVER, 0x13, "No valid response during get param") |
| 1089 | else |
| 1090 | retval = (void *)&(param->data[0]); |
| 1091 | |
| 1092 | tw_dev->posted_request_count--; |
| 1093 | tw_dev->state[request_id] = TW_S_INITIAL; |
| 1094 | |
| 1095 | return retval; |
| 1096 | } /* End twa_get_param() */ |
| 1097 | |
| 1098 | /* This function will assign an available request id */ |
| 1099 | static void twa_get_request_id(TW_Device_Extension *tw_dev, int *request_id) |
| 1100 | { |
| 1101 | *request_id = tw_dev->free_queue[tw_dev->free_head]; |
| 1102 | tw_dev->free_head = (tw_dev->free_head + 1) % TW_Q_LENGTH; |
| 1103 | tw_dev->state[*request_id] = TW_S_STARTED; |
| 1104 | } /* End twa_get_request_id() */ |
| 1105 | |
| 1106 | /* This function will send an initconnection command to controller */ |
| 1107 | static int twa_initconnection(TW_Device_Extension *tw_dev, int message_credits, |
Hannes Reinecke | bf4eebb | 2021-01-13 10:04:28 +0100 | [diff] [blame] | 1108 | u32 set_features, unsigned short current_fw_srl, |
| 1109 | unsigned short current_fw_arch_id, |
| 1110 | unsigned short current_fw_branch, |
| 1111 | unsigned short current_fw_build, |
| 1112 | unsigned short *fw_on_ctlr_srl, |
| 1113 | unsigned short *fw_on_ctlr_arch_id, |
| 1114 | unsigned short *fw_on_ctlr_branch, |
| 1115 | unsigned short *fw_on_ctlr_build, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1116 | u32 *init_connect_result) |
| 1117 | { |
| 1118 | TW_Command_Full *full_command_packet; |
| 1119 | TW_Initconnect *tw_initconnect; |
| 1120 | int request_id = 0, retval = 1; |
| 1121 | |
| 1122 | /* Initialize InitConnection command packet */ |
| 1123 | full_command_packet = tw_dev->command_packet_virt[request_id]; |
| 1124 | memset(full_command_packet, 0, sizeof(TW_Command_Full)); |
| 1125 | full_command_packet->header.header_desc.size_header = 128; |
Hannes Reinecke | bf4eebb | 2021-01-13 10:04:28 +0100 | [diff] [blame] | 1126 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1127 | tw_initconnect = (TW_Initconnect *)&full_command_packet->command.oldcommand; |
| 1128 | tw_initconnect->opcode__reserved = TW_OPRES_IN(0, TW_OP_INIT_CONNECTION); |
| 1129 | tw_initconnect->request_id = request_id; |
adam radford | 75913d9 | 2006-03-15 12:43:19 -0800 | [diff] [blame] | 1130 | tw_initconnect->message_credits = cpu_to_le16(message_credits); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1131 | |
| 1132 | /* Turn on 64-bit sgl support if we need to */ |
Samuel Holland | 05f7f1b9 | 2021-04-27 18:59:15 -0500 | [diff] [blame] | 1133 | set_features |= sizeof(dma_addr_t) > 4 ? 1 : 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1134 | |
Samuel Holland | 05f7f1b9 | 2021-04-27 18:59:15 -0500 | [diff] [blame] | 1135 | tw_initconnect->features = cpu_to_le32(set_features); |
adam radford | 75913d9 | 2006-03-15 12:43:19 -0800 | [diff] [blame] | 1136 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1137 | if (set_features & TW_EXTENDED_INIT_CONNECT) { |
| 1138 | tw_initconnect->size = TW_INIT_COMMAND_PACKET_SIZE_EXTENDED; |
adam radford | 75913d9 | 2006-03-15 12:43:19 -0800 | [diff] [blame] | 1139 | tw_initconnect->fw_srl = cpu_to_le16(current_fw_srl); |
| 1140 | tw_initconnect->fw_arch_id = cpu_to_le16(current_fw_arch_id); |
| 1141 | tw_initconnect->fw_branch = cpu_to_le16(current_fw_branch); |
| 1142 | tw_initconnect->fw_build = cpu_to_le16(current_fw_build); |
Hannes Reinecke | bf4eebb | 2021-01-13 10:04:28 +0100 | [diff] [blame] | 1143 | } else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1144 | tw_initconnect->size = TW_INIT_COMMAND_PACKET_SIZE; |
| 1145 | |
| 1146 | /* Send command packet to the board */ |
| 1147 | twa_post_command_packet(tw_dev, request_id, 1); |
| 1148 | |
| 1149 | /* Poll for completion */ |
| 1150 | if (twa_poll_response(tw_dev, request_id, 30)) { |
| 1151 | TW_PRINTK(tw_dev->host, TW_DRIVER, 0x15, "No valid response during init connection"); |
| 1152 | } else { |
| 1153 | if (set_features & TW_EXTENDED_INIT_CONNECT) { |
adam radford | 75913d9 | 2006-03-15 12:43:19 -0800 | [diff] [blame] | 1154 | *fw_on_ctlr_srl = le16_to_cpu(tw_initconnect->fw_srl); |
| 1155 | *fw_on_ctlr_arch_id = le16_to_cpu(tw_initconnect->fw_arch_id); |
| 1156 | *fw_on_ctlr_branch = le16_to_cpu(tw_initconnect->fw_branch); |
| 1157 | *fw_on_ctlr_build = le16_to_cpu(tw_initconnect->fw_build); |
| 1158 | *init_connect_result = le32_to_cpu(tw_initconnect->result); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1159 | } |
| 1160 | retval = 0; |
| 1161 | } |
| 1162 | |
| 1163 | tw_dev->posted_request_count--; |
| 1164 | tw_dev->state[request_id] = TW_S_INITIAL; |
| 1165 | |
| 1166 | return retval; |
| 1167 | } /* End twa_initconnection() */ |
| 1168 | |
| 1169 | /* This function will initialize the fields of a device extension */ |
| 1170 | static int twa_initialize_device_extension(TW_Device_Extension *tw_dev) |
| 1171 | { |
| 1172 | int i, retval = 1; |
| 1173 | |
| 1174 | /* Initialize command packet buffers */ |
| 1175 | if (twa_allocate_memory(tw_dev, sizeof(TW_Command_Full), 0)) { |
| 1176 | TW_PRINTK(tw_dev->host, TW_DRIVER, 0x16, "Command packet memory allocation failed"); |
| 1177 | goto out; |
| 1178 | } |
| 1179 | |
| 1180 | /* Initialize generic buffer */ |
| 1181 | if (twa_allocate_memory(tw_dev, TW_SECTOR_SIZE, 1)) { |
| 1182 | TW_PRINTK(tw_dev->host, TW_DRIVER, 0x17, "Generic memory allocation failed"); |
| 1183 | goto out; |
| 1184 | } |
| 1185 | |
| 1186 | /* Allocate event info space */ |
Yoann Padioleau | dd00cc4 | 2007-07-19 01:49:03 -0700 | [diff] [blame] | 1187 | tw_dev->event_queue[0] = kcalloc(TW_Q_LENGTH, sizeof(TW_Event), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1188 | if (!tw_dev->event_queue[0]) { |
| 1189 | TW_PRINTK(tw_dev->host, TW_DRIVER, 0x18, "Event info memory allocation failed"); |
| 1190 | goto out; |
| 1191 | } |
| 1192 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1193 | |
| 1194 | for (i = 0; i < TW_Q_LENGTH; i++) { |
| 1195 | tw_dev->event_queue[i] = (TW_Event *)((unsigned char *)tw_dev->event_queue[0] + (i * sizeof(TW_Event))); |
| 1196 | tw_dev->free_queue[i] = i; |
| 1197 | tw_dev->state[i] = TW_S_INITIAL; |
| 1198 | } |
| 1199 | |
| 1200 | tw_dev->pending_head = TW_Q_START; |
| 1201 | tw_dev->pending_tail = TW_Q_START; |
| 1202 | tw_dev->free_head = TW_Q_START; |
| 1203 | tw_dev->free_tail = TW_Q_START; |
| 1204 | tw_dev->error_sequence_id = 1; |
| 1205 | tw_dev->chrdev_request_id = TW_IOCTL_CHRDEV_FREE; |
| 1206 | |
Jes Sorensen | a12e25bd | 2006-01-11 08:39:45 -0500 | [diff] [blame] | 1207 | mutex_init(&tw_dev->ioctl_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1208 | init_waitqueue_head(&tw_dev->ioctl_wqueue); |
| 1209 | |
| 1210 | retval = 0; |
| 1211 | out: |
| 1212 | return retval; |
| 1213 | } /* End twa_initialize_device_extension() */ |
| 1214 | |
| 1215 | /* This function is the interrupt service routine */ |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 1216 | static irqreturn_t twa_interrupt(int irq, void *dev_instance) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1217 | { |
| 1218 | int request_id, error = 0; |
| 1219 | u32 status_reg_value; |
| 1220 | TW_Response_Queue response_que; |
| 1221 | TW_Command_Full *full_command_packet; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1222 | TW_Device_Extension *tw_dev = (TW_Device_Extension *)dev_instance; |
| 1223 | int handled = 0; |
| 1224 | |
| 1225 | /* Get the per adapter lock */ |
| 1226 | spin_lock(tw_dev->host->host_lock); |
| 1227 | |
| 1228 | /* Read the registers */ |
| 1229 | status_reg_value = readl(TW_STATUS_REG_ADDR(tw_dev)); |
| 1230 | |
| 1231 | /* Check if this is our interrupt, otherwise bail */ |
| 1232 | if (!(status_reg_value & TW_STATUS_VALID_INTERRUPT)) |
| 1233 | goto twa_interrupt_bail; |
| 1234 | |
| 1235 | handled = 1; |
| 1236 | |
adam radford | 4039c30 | 2006-10-26 18:01:06 -0700 | [diff] [blame] | 1237 | /* If we are resetting, bail */ |
| 1238 | if (test_bit(TW_IN_RESET, &tw_dev->flags)) |
| 1239 | goto twa_interrupt_bail; |
| 1240 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1241 | /* Check controller for errors */ |
| 1242 | if (twa_check_bits(status_reg_value)) { |
| 1243 | if (twa_decode_bits(tw_dev, status_reg_value)) { |
| 1244 | TW_CLEAR_ALL_INTERRUPTS(tw_dev); |
| 1245 | goto twa_interrupt_bail; |
| 1246 | } |
| 1247 | } |
| 1248 | |
| 1249 | /* Handle host interrupt */ |
| 1250 | if (status_reg_value & TW_STATUS_HOST_INTERRUPT) |
| 1251 | TW_CLEAR_HOST_INTERRUPT(tw_dev); |
| 1252 | |
| 1253 | /* Handle attention interrupt */ |
| 1254 | if (status_reg_value & TW_STATUS_ATTENTION_INTERRUPT) { |
| 1255 | TW_CLEAR_ATTENTION_INTERRUPT(tw_dev); |
| 1256 | if (!(test_and_set_bit(TW_IN_ATTENTION_LOOP, &tw_dev->flags))) { |
| 1257 | twa_get_request_id(tw_dev, &request_id); |
| 1258 | |
| 1259 | error = twa_aen_read_queue(tw_dev, request_id); |
| 1260 | if (error) { |
| 1261 | tw_dev->state[request_id] = TW_S_COMPLETED; |
| 1262 | twa_free_request_id(tw_dev, request_id); |
| 1263 | clear_bit(TW_IN_ATTENTION_LOOP, &tw_dev->flags); |
| 1264 | } |
| 1265 | } |
| 1266 | } |
| 1267 | |
| 1268 | /* Handle command interrupt */ |
| 1269 | if (status_reg_value & TW_STATUS_COMMAND_INTERRUPT) { |
| 1270 | TW_MASK_COMMAND_INTERRUPT(tw_dev); |
| 1271 | /* Drain as many pending commands as we can */ |
| 1272 | while (tw_dev->pending_request_count > 0) { |
| 1273 | request_id = tw_dev->pending_queue[tw_dev->pending_head]; |
| 1274 | if (tw_dev->state[request_id] != TW_S_PENDING) { |
| 1275 | TW_PRINTK(tw_dev->host, TW_DRIVER, 0x19, "Found request id that wasn't pending"); |
| 1276 | TW_CLEAR_ALL_INTERRUPTS(tw_dev); |
| 1277 | goto twa_interrupt_bail; |
| 1278 | } |
| 1279 | if (twa_post_command_packet(tw_dev, request_id, 1)==0) { |
| 1280 | tw_dev->pending_head = (tw_dev->pending_head + 1) % TW_Q_LENGTH; |
| 1281 | tw_dev->pending_request_count--; |
| 1282 | } else { |
| 1283 | /* If we get here, we will continue re-posting on the next command interrupt */ |
| 1284 | break; |
| 1285 | } |
| 1286 | } |
| 1287 | } |
| 1288 | |
| 1289 | /* Handle response interrupt */ |
| 1290 | if (status_reg_value & TW_STATUS_RESPONSE_INTERRUPT) { |
| 1291 | |
| 1292 | /* Drain the response queue from the board */ |
| 1293 | while ((status_reg_value & TW_STATUS_RESPONSE_QUEUE_EMPTY) == 0) { |
| 1294 | /* Complete the response */ |
| 1295 | response_que.value = readl(TW_RESPONSE_QUEUE_REG_ADDR(tw_dev)); |
| 1296 | request_id = TW_RESID_OUT(response_que.response_id); |
| 1297 | full_command_packet = tw_dev->command_packet_virt[request_id]; |
| 1298 | error = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1299 | /* Check for command packet errors */ |
| 1300 | if (full_command_packet->command.newcommand.status != 0) { |
Harvey Harrison | 9bcf091 | 2008-05-22 15:45:07 -0700 | [diff] [blame] | 1301 | if (tw_dev->srb[request_id] != NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1302 | error = twa_fill_sense(tw_dev, request_id, 1, 1); |
| 1303 | } else { |
| 1304 | /* Skip ioctl error prints */ |
| 1305 | if (request_id != tw_dev->chrdev_request_id) { |
| 1306 | error = twa_fill_sense(tw_dev, request_id, 0, 1); |
| 1307 | } |
| 1308 | } |
| 1309 | } |
| 1310 | |
| 1311 | /* Check for correct state */ |
| 1312 | if (tw_dev->state[request_id] != TW_S_POSTED) { |
Harvey Harrison | 9bcf091 | 2008-05-22 15:45:07 -0700 | [diff] [blame] | 1313 | if (tw_dev->srb[request_id] != NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1314 | TW_PRINTK(tw_dev->host, TW_DRIVER, 0x1a, "Received a request id that wasn't posted"); |
| 1315 | TW_CLEAR_ALL_INTERRUPTS(tw_dev); |
| 1316 | goto twa_interrupt_bail; |
| 1317 | } |
| 1318 | } |
| 1319 | |
| 1320 | /* Check for internal command completion */ |
Harvey Harrison | 9bcf091 | 2008-05-22 15:45:07 -0700 | [diff] [blame] | 1321 | if (tw_dev->srb[request_id] == NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1322 | if (request_id != tw_dev->chrdev_request_id) { |
| 1323 | if (twa_aen_complete(tw_dev, request_id)) |
| 1324 | TW_PRINTK(tw_dev->host, TW_DRIVER, 0x1b, "Error completing AEN during attention interrupt"); |
| 1325 | } else { |
| 1326 | tw_dev->chrdev_request_id = TW_IOCTL_CHRDEV_FREE; |
| 1327 | wake_up(&tw_dev->ioctl_wqueue); |
| 1328 | } |
| 1329 | } else { |
FUJITA Tomonori | 0debe01 | 2007-05-26 02:33:31 +0900 | [diff] [blame] | 1330 | struct scsi_cmnd *cmd; |
| 1331 | |
| 1332 | cmd = tw_dev->srb[request_id]; |
| 1333 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1334 | twa_scsiop_execute_scsi_complete(tw_dev, request_id); |
| 1335 | /* If no error command was a success */ |
| 1336 | if (error == 0) { |
FUJITA Tomonori | 0debe01 | 2007-05-26 02:33:31 +0900 | [diff] [blame] | 1337 | cmd->result = (DID_OK << 16); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1338 | } |
| 1339 | |
| 1340 | /* If error, command failed */ |
| 1341 | if (error == 1) { |
| 1342 | /* Ask for a host reset */ |
Hannes Reinecke | 3d45cefc | 2021-04-27 10:30:46 +0200 | [diff] [blame] | 1343 | cmd->result = (DID_OK << 16) | SAM_STAT_CHECK_CONDITION; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1344 | } |
| 1345 | |
| 1346 | /* Report residual bytes for single sgl */ |
FUJITA Tomonori | 0debe01 | 2007-05-26 02:33:31 +0900 | [diff] [blame] | 1347 | if ((scsi_sg_count(cmd) <= 1) && (full_command_packet->command.newcommand.status == 0)) { |
Samuel Holland | 05f7f1b9 | 2021-04-27 18:59:15 -0500 | [diff] [blame] | 1348 | u32 length = le32_to_cpu(full_command_packet->command.newcommand.sg_list[0].length); |
| 1349 | |
| 1350 | if (length < scsi_bufflen(cmd)) |
| 1351 | scsi_set_resid(cmd, scsi_bufflen(cmd) - length); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1352 | } |
| 1353 | |
| 1354 | /* Now complete the io */ |
Christoph Hellwig | 15e3d5a | 2015-10-03 19:16:07 +0200 | [diff] [blame] | 1355 | if (twa_command_mapped(cmd)) |
| 1356 | scsi_dma_unmap(cmd); |
Bart Van Assche | 3e6d383 | 2021-10-07 13:28:03 -0700 | [diff] [blame] | 1357 | scsi_done(cmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1358 | tw_dev->state[request_id] = TW_S_COMPLETED; |
| 1359 | twa_free_request_id(tw_dev, request_id); |
| 1360 | tw_dev->posted_request_count--; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1361 | } |
| 1362 | |
| 1363 | /* Check for valid status after each drain */ |
| 1364 | status_reg_value = readl(TW_STATUS_REG_ADDR(tw_dev)); |
| 1365 | if (twa_check_bits(status_reg_value)) { |
| 1366 | if (twa_decode_bits(tw_dev, status_reg_value)) { |
| 1367 | TW_CLEAR_ALL_INTERRUPTS(tw_dev); |
| 1368 | goto twa_interrupt_bail; |
| 1369 | } |
| 1370 | } |
| 1371 | } |
| 1372 | } |
| 1373 | |
| 1374 | twa_interrupt_bail: |
| 1375 | spin_unlock(tw_dev->host->host_lock); |
| 1376 | return IRQ_RETVAL(handled); |
| 1377 | } /* End twa_interrupt() */ |
| 1378 | |
| 1379 | /* This function will load the request id and various sgls for ioctls */ |
adam radford | 0e78d15 | 2007-07-20 15:28:28 -0700 | [diff] [blame] | 1380 | static void twa_load_sgl(TW_Device_Extension *tw_dev, TW_Command_Full *full_command_packet, int request_id, dma_addr_t dma_handle, int length) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1381 | { |
| 1382 | TW_Command *oldcommand; |
| 1383 | TW_Command_Apache *newcommand; |
| 1384 | TW_SG_Entry *sgl; |
adam radford | 0e78d15 | 2007-07-20 15:28:28 -0700 | [diff] [blame] | 1385 | unsigned int pae = 0; |
| 1386 | |
| 1387 | if ((sizeof(long) < 8) && (sizeof(dma_addr_t) > 4)) |
| 1388 | pae = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1389 | |
| 1390 | if (TW_OP_OUT(full_command_packet->command.newcommand.opcode__reserved) == TW_OP_EXECUTE_SCSI) { |
| 1391 | newcommand = &full_command_packet->command.newcommand; |
adam radford | 4039c30 | 2006-10-26 18:01:06 -0700 | [diff] [blame] | 1392 | newcommand->request_id__lunl = |
Samuel Holland | 05f7f1b9 | 2021-04-27 18:59:15 -0500 | [diff] [blame] | 1393 | TW_REQ_LUN_IN(TW_LUN_OUT(newcommand->request_id__lunl), request_id); |
adam radford | 53ca353 | 2009-12-10 11:53:31 -0800 | [diff] [blame] | 1394 | if (length) { |
Samuel Holland | 44c5027 | 2021-04-27 18:59:13 -0500 | [diff] [blame] | 1395 | newcommand->sg_list[0].address = TW_CPU_TO_SGL(dma_handle + sizeof(TW_Ioctl_Buf_Apache)); |
adam radford | 53ca353 | 2009-12-10 11:53:31 -0800 | [diff] [blame] | 1396 | newcommand->sg_list[0].length = cpu_to_le32(length); |
| 1397 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1398 | newcommand->sgl_entries__lunh = |
Samuel Holland | 05f7f1b9 | 2021-04-27 18:59:15 -0500 | [diff] [blame] | 1399 | TW_REQ_LUN_IN(TW_LUN_OUT(newcommand->sgl_entries__lunh), length ? 1 : 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1400 | } else { |
| 1401 | oldcommand = &full_command_packet->command.oldcommand; |
| 1402 | oldcommand->request_id = request_id; |
| 1403 | |
| 1404 | if (TW_SGL_OUT(oldcommand->opcode__sgloffset)) { |
| 1405 | /* Load the sg list */ |
adam radford | 0e78d15 | 2007-07-20 15:28:28 -0700 | [diff] [blame] | 1406 | if (tw_dev->tw_pci_dev->device == PCI_DEVICE_ID_3WARE_9690SA) |
| 1407 | sgl = (TW_SG_Entry *)((u32 *)oldcommand+oldcommand->size - (sizeof(TW_SG_Entry)/4) + pae); |
| 1408 | else |
| 1409 | sgl = (TW_SG_Entry *)((u32 *)oldcommand+TW_SGL_OUT(oldcommand->opcode__sgloffset)); |
Samuel Holland | 44c5027 | 2021-04-27 18:59:13 -0500 | [diff] [blame] | 1410 | sgl->address = TW_CPU_TO_SGL(dma_handle + sizeof(TW_Ioctl_Buf_Apache)); |
adam radford | 75913d9 | 2006-03-15 12:43:19 -0800 | [diff] [blame] | 1411 | sgl->length = cpu_to_le32(length); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1412 | |
adam radford | 0e78d15 | 2007-07-20 15:28:28 -0700 | [diff] [blame] | 1413 | oldcommand->size += pae; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1414 | } |
| 1415 | } |
| 1416 | } /* End twa_load_sgl() */ |
| 1417 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1418 | /* This function will poll for a response interrupt of a request */ |
| 1419 | static int twa_poll_response(TW_Device_Extension *tw_dev, int request_id, int seconds) |
| 1420 | { |
| 1421 | int retval = 1, found = 0, response_request_id; |
| 1422 | TW_Response_Queue response_queue; |
| 1423 | TW_Command_Full *full_command_packet = tw_dev->command_packet_virt[request_id]; |
| 1424 | |
| 1425 | if (twa_poll_status_gone(tw_dev, TW_STATUS_RESPONSE_QUEUE_EMPTY, seconds) == 0) { |
| 1426 | response_queue.value = readl(TW_RESPONSE_QUEUE_REG_ADDR(tw_dev)); |
| 1427 | response_request_id = TW_RESID_OUT(response_queue.response_id); |
| 1428 | if (request_id != response_request_id) { |
| 1429 | TW_PRINTK(tw_dev->host, TW_DRIVER, 0x1e, "Found unexpected request id while polling for response"); |
| 1430 | goto out; |
| 1431 | } |
| 1432 | if (TW_OP_OUT(full_command_packet->command.newcommand.opcode__reserved) == TW_OP_EXECUTE_SCSI) { |
| 1433 | if (full_command_packet->command.newcommand.status != 0) { |
| 1434 | /* bad response */ |
| 1435 | twa_fill_sense(tw_dev, request_id, 0, 0); |
| 1436 | goto out; |
| 1437 | } |
| 1438 | found = 1; |
| 1439 | } else { |
| 1440 | if (full_command_packet->command.oldcommand.status != 0) { |
| 1441 | /* bad response */ |
| 1442 | twa_fill_sense(tw_dev, request_id, 0, 0); |
| 1443 | goto out; |
| 1444 | } |
| 1445 | found = 1; |
| 1446 | } |
| 1447 | } |
| 1448 | |
| 1449 | if (found) |
| 1450 | retval = 0; |
| 1451 | out: |
| 1452 | return retval; |
| 1453 | } /* End twa_poll_response() */ |
| 1454 | |
| 1455 | /* This function will poll the status register for a flag */ |
| 1456 | static int twa_poll_status(TW_Device_Extension *tw_dev, u32 flag, int seconds) |
| 1457 | { |
Hannes Reinecke | bf4eebb | 2021-01-13 10:04:28 +0100 | [diff] [blame] | 1458 | u32 status_reg_value; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1459 | unsigned long before; |
| 1460 | int retval = 1; |
| 1461 | |
| 1462 | status_reg_value = readl(TW_STATUS_REG_ADDR(tw_dev)); |
| 1463 | before = jiffies; |
| 1464 | |
| 1465 | if (twa_check_bits(status_reg_value)) |
| 1466 | twa_decode_bits(tw_dev, status_reg_value); |
| 1467 | |
| 1468 | while ((status_reg_value & flag) != flag) { |
| 1469 | status_reg_value = readl(TW_STATUS_REG_ADDR(tw_dev)); |
| 1470 | |
| 1471 | if (twa_check_bits(status_reg_value)) |
| 1472 | twa_decode_bits(tw_dev, status_reg_value); |
| 1473 | |
| 1474 | if (time_after(jiffies, before + HZ * seconds)) |
| 1475 | goto out; |
| 1476 | |
| 1477 | msleep(50); |
| 1478 | } |
| 1479 | retval = 0; |
| 1480 | out: |
| 1481 | return retval; |
| 1482 | } /* End twa_poll_status() */ |
| 1483 | |
| 1484 | /* This function will poll the status register for disappearance of a flag */ |
| 1485 | static int twa_poll_status_gone(TW_Device_Extension *tw_dev, u32 flag, int seconds) |
| 1486 | { |
| 1487 | u32 status_reg_value; |
| 1488 | unsigned long before; |
| 1489 | int retval = 1; |
| 1490 | |
| 1491 | status_reg_value = readl(TW_STATUS_REG_ADDR(tw_dev)); |
| 1492 | before = jiffies; |
| 1493 | |
| 1494 | if (twa_check_bits(status_reg_value)) |
| 1495 | twa_decode_bits(tw_dev, status_reg_value); |
| 1496 | |
| 1497 | while ((status_reg_value & flag) != 0) { |
| 1498 | status_reg_value = readl(TW_STATUS_REG_ADDR(tw_dev)); |
| 1499 | if (twa_check_bits(status_reg_value)) |
| 1500 | twa_decode_bits(tw_dev, status_reg_value); |
| 1501 | |
| 1502 | if (time_after(jiffies, before + HZ * seconds)) |
| 1503 | goto out; |
| 1504 | |
| 1505 | msleep(50); |
| 1506 | } |
| 1507 | retval = 0; |
| 1508 | out: |
| 1509 | return retval; |
| 1510 | } /* End twa_poll_status_gone() */ |
| 1511 | |
| 1512 | /* This function will attempt to post a command packet to the board */ |
| 1513 | static int twa_post_command_packet(TW_Device_Extension *tw_dev, int request_id, char internal) |
| 1514 | { |
| 1515 | u32 status_reg_value; |
| 1516 | dma_addr_t command_que_value; |
| 1517 | int retval = 1; |
| 1518 | |
| 1519 | command_que_value = tw_dev->command_packet_phys[request_id]; |
adam radford | 4039c30 | 2006-10-26 18:01:06 -0700 | [diff] [blame] | 1520 | |
| 1521 | /* For 9650SE write low 4 bytes first */ |
adam radford | 0e78d15 | 2007-07-20 15:28:28 -0700 | [diff] [blame] | 1522 | if ((tw_dev->tw_pci_dev->device == PCI_DEVICE_ID_3WARE_9650SE) || |
| 1523 | (tw_dev->tw_pci_dev->device == PCI_DEVICE_ID_3WARE_9690SA)) { |
adam radford | 4039c30 | 2006-10-26 18:01:06 -0700 | [diff] [blame] | 1524 | command_que_value += TW_COMMAND_OFFSET; |
| 1525 | writel((u32)command_que_value, TW_COMMAND_QUEUE_REG_ADDR_LARGE(tw_dev)); |
| 1526 | } |
| 1527 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1528 | status_reg_value = readl(TW_STATUS_REG_ADDR(tw_dev)); |
| 1529 | |
| 1530 | if (twa_check_bits(status_reg_value)) |
| 1531 | twa_decode_bits(tw_dev, status_reg_value); |
| 1532 | |
| 1533 | if (((tw_dev->pending_request_count > 0) && (tw_dev->state[request_id] != TW_S_PENDING)) || (status_reg_value & TW_STATUS_COMMAND_QUEUE_FULL)) { |
| 1534 | |
| 1535 | /* Only pend internal driver commands */ |
| 1536 | if (!internal) { |
| 1537 | retval = SCSI_MLQUEUE_HOST_BUSY; |
| 1538 | goto out; |
| 1539 | } |
| 1540 | |
| 1541 | /* Couldn't post the command packet, so we do it later */ |
| 1542 | if (tw_dev->state[request_id] != TW_S_PENDING) { |
| 1543 | tw_dev->state[request_id] = TW_S_PENDING; |
| 1544 | tw_dev->pending_request_count++; |
| 1545 | if (tw_dev->pending_request_count > tw_dev->max_pending_request_count) { |
| 1546 | tw_dev->max_pending_request_count = tw_dev->pending_request_count; |
| 1547 | } |
| 1548 | tw_dev->pending_queue[tw_dev->pending_tail] = request_id; |
| 1549 | tw_dev->pending_tail = (tw_dev->pending_tail + 1) % TW_Q_LENGTH; |
| 1550 | } |
| 1551 | TW_UNMASK_COMMAND_INTERRUPT(tw_dev); |
| 1552 | goto out; |
| 1553 | } else { |
adam radford | 0e78d15 | 2007-07-20 15:28:28 -0700 | [diff] [blame] | 1554 | if ((tw_dev->tw_pci_dev->device == PCI_DEVICE_ID_3WARE_9650SE) || |
| 1555 | (tw_dev->tw_pci_dev->device == PCI_DEVICE_ID_3WARE_9690SA)) { |
adam radford | 4039c30 | 2006-10-26 18:01:06 -0700 | [diff] [blame] | 1556 | /* Now write upper 4 bytes */ |
| 1557 | writel((u32)((u64)command_que_value >> 32), TW_COMMAND_QUEUE_REG_ADDR_LARGE(tw_dev) + 0x4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1558 | } else { |
adam radford | 4039c30 | 2006-10-26 18:01:06 -0700 | [diff] [blame] | 1559 | if (sizeof(dma_addr_t) > 4) { |
| 1560 | command_que_value += TW_COMMAND_OFFSET; |
| 1561 | writel((u32)command_que_value, TW_COMMAND_QUEUE_REG_ADDR(tw_dev)); |
| 1562 | writel((u32)((u64)command_que_value >> 32), TW_COMMAND_QUEUE_REG_ADDR(tw_dev) + 0x4); |
| 1563 | } else { |
| 1564 | writel(TW_COMMAND_OFFSET + command_que_value, TW_COMMAND_QUEUE_REG_ADDR(tw_dev)); |
| 1565 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1566 | } |
| 1567 | tw_dev->state[request_id] = TW_S_POSTED; |
| 1568 | tw_dev->posted_request_count++; |
| 1569 | if (tw_dev->posted_request_count > tw_dev->max_posted_request_count) { |
| 1570 | tw_dev->max_posted_request_count = tw_dev->posted_request_count; |
| 1571 | } |
| 1572 | } |
| 1573 | retval = 0; |
| 1574 | out: |
| 1575 | return retval; |
| 1576 | } /* End twa_post_command_packet() */ |
| 1577 | |
| 1578 | /* This function will reset a device extension */ |
adam radford | 0e78d15 | 2007-07-20 15:28:28 -0700 | [diff] [blame] | 1579 | static int twa_reset_device_extension(TW_Device_Extension *tw_dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1580 | { |
| 1581 | int i = 0; |
| 1582 | int retval = 1; |
| 1583 | unsigned long flags = 0; |
| 1584 | |
| 1585 | set_bit(TW_IN_RESET, &tw_dev->flags); |
| 1586 | TW_DISABLE_INTERRUPTS(tw_dev); |
| 1587 | TW_MASK_COMMAND_INTERRUPT(tw_dev); |
| 1588 | spin_lock_irqsave(tw_dev->host->host_lock, flags); |
| 1589 | |
| 1590 | /* Abort all requests that are in progress */ |
| 1591 | for (i = 0; i < TW_Q_LENGTH; i++) { |
| 1592 | if ((tw_dev->state[i] != TW_S_FINISHED) && |
| 1593 | (tw_dev->state[i] != TW_S_INITIAL) && |
| 1594 | (tw_dev->state[i] != TW_S_COMPLETED)) { |
| 1595 | if (tw_dev->srb[i]) { |
Christoph Hellwig | 118c855 | 2015-04-23 09:48:51 +0200 | [diff] [blame] | 1596 | struct scsi_cmnd *cmd = tw_dev->srb[i]; |
| 1597 | |
| 1598 | cmd->result = (DID_RESET << 16); |
Christoph Hellwig | 15e3d5a | 2015-10-03 19:16:07 +0200 | [diff] [blame] | 1599 | if (twa_command_mapped(cmd)) |
| 1600 | scsi_dma_unmap(cmd); |
Bart Van Assche | 3e6d383 | 2021-10-07 13:28:03 -0700 | [diff] [blame] | 1601 | scsi_done(cmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1602 | } |
| 1603 | } |
| 1604 | } |
| 1605 | |
| 1606 | /* Reset queues and counts */ |
| 1607 | for (i = 0; i < TW_Q_LENGTH; i++) { |
| 1608 | tw_dev->free_queue[i] = i; |
| 1609 | tw_dev->state[i] = TW_S_INITIAL; |
| 1610 | } |
| 1611 | tw_dev->free_head = TW_Q_START; |
| 1612 | tw_dev->free_tail = TW_Q_START; |
| 1613 | tw_dev->posted_request_count = 0; |
| 1614 | tw_dev->pending_request_count = 0; |
| 1615 | tw_dev->pending_head = TW_Q_START; |
| 1616 | tw_dev->pending_tail = TW_Q_START; |
| 1617 | tw_dev->reset_print = 0; |
| 1618 | |
| 1619 | spin_unlock_irqrestore(tw_dev->host->host_lock, flags); |
| 1620 | |
| 1621 | if (twa_reset_sequence(tw_dev, 1)) |
| 1622 | goto out; |
| 1623 | |
| 1624 | TW_ENABLE_AND_CLEAR_INTERRUPTS(tw_dev); |
adam radford | 4039c30 | 2006-10-26 18:01:06 -0700 | [diff] [blame] | 1625 | clear_bit(TW_IN_RESET, &tw_dev->flags); |
| 1626 | tw_dev->chrdev_request_id = TW_IOCTL_CHRDEV_FREE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1627 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1628 | retval = 0; |
| 1629 | out: |
| 1630 | return retval; |
| 1631 | } /* End twa_reset_device_extension() */ |
| 1632 | |
| 1633 | /* This function will reset a controller */ |
| 1634 | static int twa_reset_sequence(TW_Device_Extension *tw_dev, int soft_reset) |
| 1635 | { |
| 1636 | int tries = 0, retval = 1, flashed = 0, do_soft_reset = soft_reset; |
| 1637 | |
| 1638 | while (tries < TW_MAX_RESET_TRIES) { |
adam radford | 49bfd8d | 2005-09-21 17:20:14 -0700 | [diff] [blame] | 1639 | if (do_soft_reset) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1640 | TW_SOFT_RESET(tw_dev); |
adam radford | 49bfd8d | 2005-09-21 17:20:14 -0700 | [diff] [blame] | 1641 | /* Clear pchip/response queue on 9550SX */ |
| 1642 | if (twa_empty_response_queue_large(tw_dev)) { |
| 1643 | TW_PRINTK(tw_dev->host, TW_DRIVER, 0x36, "Response queue (large) empty failed during reset sequence"); |
| 1644 | do_soft_reset = 1; |
| 1645 | tries++; |
| 1646 | continue; |
| 1647 | } |
| 1648 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1649 | |
| 1650 | /* Make sure controller is in a good state */ |
| 1651 | if (twa_poll_status(tw_dev, TW_STATUS_MICROCONTROLLER_READY | (do_soft_reset == 1 ? TW_STATUS_ATTENTION_INTERRUPT : 0), 60)) { |
| 1652 | TW_PRINTK(tw_dev->host, TW_DRIVER, 0x1f, "Microcontroller not ready during reset sequence"); |
| 1653 | do_soft_reset = 1; |
| 1654 | tries++; |
| 1655 | continue; |
| 1656 | } |
| 1657 | |
| 1658 | /* Empty response queue */ |
| 1659 | if (twa_empty_response_queue(tw_dev)) { |
| 1660 | TW_PRINTK(tw_dev->host, TW_DRIVER, 0x20, "Response queue empty failed during reset sequence"); |
| 1661 | do_soft_reset = 1; |
| 1662 | tries++; |
| 1663 | continue; |
| 1664 | } |
| 1665 | |
| 1666 | flashed = 0; |
| 1667 | |
| 1668 | /* Check for compatibility/flash */ |
| 1669 | if (twa_check_srl(tw_dev, &flashed)) { |
| 1670 | TW_PRINTK(tw_dev->host, TW_DRIVER, 0x21, "Compatibility check failed during reset sequence"); |
| 1671 | do_soft_reset = 1; |
| 1672 | tries++; |
| 1673 | continue; |
| 1674 | } else { |
| 1675 | if (flashed) { |
| 1676 | tries++; |
| 1677 | continue; |
| 1678 | } |
| 1679 | } |
| 1680 | |
| 1681 | /* Drain the AEN queue */ |
| 1682 | if (twa_aen_drain_queue(tw_dev, soft_reset)) { |
| 1683 | TW_PRINTK(tw_dev->host, TW_DRIVER, 0x22, "AEN drain failed during reset sequence"); |
| 1684 | do_soft_reset = 1; |
| 1685 | tries++; |
| 1686 | continue; |
| 1687 | } |
| 1688 | |
| 1689 | /* If we got here, controller is in a good state */ |
| 1690 | retval = 0; |
| 1691 | goto out; |
| 1692 | } |
| 1693 | out: |
| 1694 | return retval; |
| 1695 | } /* End twa_reset_sequence() */ |
| 1696 | |
| 1697 | /* This funciton returns unit geometry in cylinders/heads/sectors */ |
| 1698 | static int twa_scsi_biosparam(struct scsi_device *sdev, struct block_device *bdev, sector_t capacity, int geom[]) |
| 1699 | { |
| 1700 | int heads, sectors, cylinders; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1701 | |
| 1702 | if (capacity >= 0x200000) { |
| 1703 | heads = 255; |
| 1704 | sectors = 63; |
| 1705 | cylinders = sector_div(capacity, heads * sectors); |
| 1706 | } else { |
| 1707 | heads = 64; |
| 1708 | sectors = 32; |
| 1709 | cylinders = sector_div(capacity, heads * sectors); |
| 1710 | } |
| 1711 | |
| 1712 | geom[0] = heads; |
| 1713 | geom[1] = sectors; |
| 1714 | geom[2] = cylinders; |
| 1715 | |
| 1716 | return 0; |
| 1717 | } /* End twa_scsi_biosparam() */ |
| 1718 | |
| 1719 | /* This is the new scsi eh reset function */ |
| 1720 | static int twa_scsi_eh_reset(struct scsi_cmnd *SCpnt) |
| 1721 | { |
| 1722 | TW_Device_Extension *tw_dev = NULL; |
| 1723 | int retval = FAILED; |
| 1724 | |
| 1725 | tw_dev = (TW_Device_Extension *)SCpnt->device->host->hostdata; |
| 1726 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1727 | tw_dev->num_resets++; |
| 1728 | |
Jeff Garzik | 017560f | 2005-10-24 18:04:36 -0400 | [diff] [blame] | 1729 | sdev_printk(KERN_WARNING, SCpnt->device, |
| 1730 | "WARNING: (0x%02X:0x%04X): Command (0x%x) timed out, resetting card.\n", |
| 1731 | TW_DRIVER, 0x2c, SCpnt->cmnd[0]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1732 | |
adam radford | 4039c30 | 2006-10-26 18:01:06 -0700 | [diff] [blame] | 1733 | /* Make sure we are not issuing an ioctl or resetting from ioctl */ |
| 1734 | mutex_lock(&tw_dev->ioctl_lock); |
| 1735 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1736 | /* Now reset the card and some of the device extension data */ |
adam radford | 0e78d15 | 2007-07-20 15:28:28 -0700 | [diff] [blame] | 1737 | if (twa_reset_device_extension(tw_dev)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1738 | TW_PRINTK(tw_dev->host, TW_DRIVER, 0x2b, "Controller reset failed during scsi host reset"); |
| 1739 | goto out; |
| 1740 | } |
| 1741 | |
| 1742 | retval = SUCCESS; |
| 1743 | out: |
adam radford | 4039c30 | 2006-10-26 18:01:06 -0700 | [diff] [blame] | 1744 | mutex_unlock(&tw_dev->ioctl_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1745 | return retval; |
| 1746 | } /* End twa_scsi_eh_reset() */ |
| 1747 | |
| 1748 | /* This is the main scsi queue function to handle scsi opcodes */ |
Bart Van Assche | af049df | 2021-10-07 13:46:14 -0700 | [diff] [blame] | 1749 | static int twa_scsi_queue_lck(struct scsi_cmnd *SCpnt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1750 | { |
Bart Van Assche | af049df | 2021-10-07 13:46:14 -0700 | [diff] [blame] | 1751 | void (*done)(struct scsi_cmnd *) = scsi_done; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1752 | int request_id, retval; |
| 1753 | TW_Device_Extension *tw_dev = (TW_Device_Extension *)SCpnt->device->host->hostdata; |
| 1754 | |
adam radford | 4039c30 | 2006-10-26 18:01:06 -0700 | [diff] [blame] | 1755 | /* If we are resetting due to timed out ioctl, report as busy */ |
| 1756 | if (test_bit(TW_IN_RESET, &tw_dev->flags)) { |
| 1757 | retval = SCSI_MLQUEUE_HOST_BUSY; |
| 1758 | goto out; |
| 1759 | } |
| 1760 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1761 | /* Check if this FW supports luns */ |
adam radford | 4039c30 | 2006-10-26 18:01:06 -0700 | [diff] [blame] | 1762 | if ((SCpnt->device->lun != 0) && (tw_dev->tw_compat_info.working_srl < TW_FW_SRL_LUNS_SUPPORTED)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1763 | SCpnt->result = (DID_BAD_TARGET << 16); |
| 1764 | done(SCpnt); |
| 1765 | retval = 0; |
| 1766 | goto out; |
| 1767 | } |
| 1768 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1769 | /* Get a free request id */ |
| 1770 | twa_get_request_id(tw_dev, &request_id); |
| 1771 | |
| 1772 | /* Save the scsi command for use by the ISR */ |
| 1773 | tw_dev->srb[request_id] = SCpnt; |
| 1774 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1775 | retval = twa_scsiop_execute_scsi(tw_dev, request_id, NULL, 0, NULL); |
| 1776 | switch (retval) { |
| 1777 | case SCSI_MLQUEUE_HOST_BUSY: |
Christoph Hellwig | 15e3d5a | 2015-10-03 19:16:07 +0200 | [diff] [blame] | 1778 | if (twa_command_mapped(SCpnt)) |
| 1779 | scsi_dma_unmap(SCpnt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1780 | twa_free_request_id(tw_dev, request_id); |
| 1781 | break; |
| 1782 | case 1: |
Christoph Hellwig | 118c855 | 2015-04-23 09:48:51 +0200 | [diff] [blame] | 1783 | SCpnt->result = (DID_ERROR << 16); |
Christoph Hellwig | 15e3d5a | 2015-10-03 19:16:07 +0200 | [diff] [blame] | 1784 | if (twa_command_mapped(SCpnt)) |
| 1785 | scsi_dma_unmap(SCpnt); |
Christoph Hellwig | 118c855 | 2015-04-23 09:48:51 +0200 | [diff] [blame] | 1786 | done(SCpnt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1787 | tw_dev->state[request_id] = TW_S_COMPLETED; |
| 1788 | twa_free_request_id(tw_dev, request_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1789 | retval = 0; |
| 1790 | } |
| 1791 | out: |
| 1792 | return retval; |
| 1793 | } /* End twa_scsi_queue() */ |
| 1794 | |
Jeff Garzik | f281233 | 2010-11-16 02:10:29 -0500 | [diff] [blame] | 1795 | static DEF_SCSI_QCMD(twa_scsi_queue) |
| 1796 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1797 | /* This function hands scsi cdb's to the firmware */ |
Nathan Chancellor | 09968e5 | 2018-10-18 14:55:41 -0700 | [diff] [blame] | 1798 | static int twa_scsiop_execute_scsi(TW_Device_Extension *tw_dev, int request_id, |
| 1799 | unsigned char *cdb, int use_sg, |
| 1800 | TW_SG_Entry *sglistarg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1801 | { |
| 1802 | TW_Command_Full *full_command_packet; |
| 1803 | TW_Command_Apache *command_packet; |
| 1804 | u32 num_sectors = 0x0; |
| 1805 | int i, sg_count; |
| 1806 | struct scsi_cmnd *srb = NULL; |
Lee Jones | ea7fb53 | 2021-03-12 09:47:37 +0000 | [diff] [blame] | 1807 | struct scatterlist *sg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1808 | int retval = 1; |
| 1809 | |
Lee Jones | ea7fb53 | 2021-03-12 09:47:37 +0000 | [diff] [blame] | 1810 | if (tw_dev->srb[request_id]) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1811 | srb = tw_dev->srb[request_id]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1812 | |
| 1813 | /* Initialize command packet */ |
| 1814 | full_command_packet = tw_dev->command_packet_virt[request_id]; |
| 1815 | full_command_packet->header.header_desc.size_header = 128; |
| 1816 | full_command_packet->header.status_block.error = 0; |
| 1817 | full_command_packet->header.status_block.severity__reserved = 0; |
| 1818 | |
| 1819 | command_packet = &full_command_packet->command.newcommand; |
| 1820 | command_packet->status = 0; |
| 1821 | command_packet->opcode__reserved = TW_OPRES_IN(0, TW_OP_EXECUTE_SCSI); |
| 1822 | |
| 1823 | /* We forced 16 byte cdb use earlier */ |
| 1824 | if (!cdb) |
| 1825 | memcpy(command_packet->cdb, srb->cmnd, TW_MAX_CDB_LEN); |
| 1826 | else |
| 1827 | memcpy(command_packet->cdb, cdb, TW_MAX_CDB_LEN); |
| 1828 | |
| 1829 | if (srb) { |
| 1830 | command_packet->unit = srb->device->id; |
| 1831 | command_packet->request_id__lunl = |
Samuel Holland | 05f7f1b9 | 2021-04-27 18:59:15 -0500 | [diff] [blame] | 1832 | TW_REQ_LUN_IN(srb->device->lun, request_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1833 | } else { |
| 1834 | command_packet->request_id__lunl = |
Samuel Holland | 05f7f1b9 | 2021-04-27 18:59:15 -0500 | [diff] [blame] | 1835 | TW_REQ_LUN_IN(0, request_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1836 | command_packet->unit = 0; |
| 1837 | } |
| 1838 | |
| 1839 | command_packet->sgl_offset = 16; |
| 1840 | |
| 1841 | if (!sglistarg) { |
| 1842 | /* Map sglist from scsi layer to cmd packet */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1843 | |
FUJITA Tomonori | 0debe01 | 2007-05-26 02:33:31 +0900 | [diff] [blame] | 1844 | if (scsi_sg_count(srb)) { |
Christoph Hellwig | 15e3d5a | 2015-10-03 19:16:07 +0200 | [diff] [blame] | 1845 | if (!twa_command_mapped(srb)) { |
FUJITA Tomonori | 035f5e0 | 2008-03-09 13:44:37 +0900 | [diff] [blame] | 1846 | if (srb->sc_data_direction == DMA_TO_DEVICE || |
| 1847 | srb->sc_data_direction == DMA_BIDIRECTIONAL) |
| 1848 | scsi_sg_copy_to_buffer(srb, |
| 1849 | tw_dev->generic_buffer_virt[request_id], |
| 1850 | TW_SECTOR_SIZE); |
adam radford | 75913d9 | 2006-03-15 12:43:19 -0800 | [diff] [blame] | 1851 | command_packet->sg_list[0].address = TW_CPU_TO_SGL(tw_dev->generic_buffer_phys[request_id]); |
| 1852 | command_packet->sg_list[0].length = cpu_to_le32(TW_MIN_SGL_LENGTH); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1853 | } else { |
Christoph Hellwig | 118c855 | 2015-04-23 09:48:51 +0200 | [diff] [blame] | 1854 | sg_count = scsi_dma_map(srb); |
| 1855 | if (sg_count < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1856 | goto out; |
| 1857 | |
FUJITA Tomonori | 0debe01 | 2007-05-26 02:33:31 +0900 | [diff] [blame] | 1858 | scsi_for_each_sg(srb, sg, sg_count, i) { |
| 1859 | command_packet->sg_list[i].address = TW_CPU_TO_SGL(sg_dma_address(sg)); |
| 1860 | command_packet->sg_list[i].length = cpu_to_le32(sg_dma_len(sg)); |
adam radford | 75913d9 | 2006-03-15 12:43:19 -0800 | [diff] [blame] | 1861 | if (command_packet->sg_list[i].address & TW_CPU_TO_SGL(TW_ALIGNMENT_9000_SGL)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1862 | TW_PRINTK(tw_dev->host, TW_DRIVER, 0x2e, "Found unaligned sgl address during execute scsi"); |
| 1863 | goto out; |
| 1864 | } |
| 1865 | } |
| 1866 | } |
Samuel Holland | 05f7f1b9 | 2021-04-27 18:59:15 -0500 | [diff] [blame] | 1867 | command_packet->sgl_entries__lunh = TW_REQ_LUN_IN((srb->device->lun >> 4), scsi_sg_count(tw_dev->srb[request_id])); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1868 | } |
| 1869 | } else { |
| 1870 | /* Internal cdb post */ |
| 1871 | for (i = 0; i < use_sg; i++) { |
Samuel Holland | 05f7f1b9 | 2021-04-27 18:59:15 -0500 | [diff] [blame] | 1872 | command_packet->sg_list[i].address = sglistarg[i].address; |
| 1873 | command_packet->sg_list[i].length = sglistarg[i].length; |
adam radford | 75913d9 | 2006-03-15 12:43:19 -0800 | [diff] [blame] | 1874 | if (command_packet->sg_list[i].address & TW_CPU_TO_SGL(TW_ALIGNMENT_9000_SGL)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1875 | TW_PRINTK(tw_dev->host, TW_DRIVER, 0x2f, "Found unaligned sgl address during internal post"); |
| 1876 | goto out; |
| 1877 | } |
| 1878 | } |
Samuel Holland | 05f7f1b9 | 2021-04-27 18:59:15 -0500 | [diff] [blame] | 1879 | command_packet->sgl_entries__lunh = TW_REQ_LUN_IN(0, use_sg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1880 | } |
| 1881 | |
| 1882 | if (srb) { |
| 1883 | if (srb->cmnd[0] == READ_6 || srb->cmnd[0] == WRITE_6) |
| 1884 | num_sectors = (u32)srb->cmnd[4]; |
| 1885 | |
| 1886 | if (srb->cmnd[0] == READ_10 || srb->cmnd[0] == WRITE_10) |
| 1887 | num_sectors = (u32)srb->cmnd[8] | ((u32)srb->cmnd[7] << 8); |
| 1888 | } |
| 1889 | |
| 1890 | /* Update sector statistic */ |
| 1891 | tw_dev->sector_count = num_sectors; |
| 1892 | if (tw_dev->sector_count > tw_dev->max_sector_count) |
| 1893 | tw_dev->max_sector_count = tw_dev->sector_count; |
| 1894 | |
| 1895 | /* Update SG statistics */ |
| 1896 | if (srb) { |
FUJITA Tomonori | 0debe01 | 2007-05-26 02:33:31 +0900 | [diff] [blame] | 1897 | tw_dev->sgl_entries = scsi_sg_count(tw_dev->srb[request_id]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1898 | if (tw_dev->sgl_entries > tw_dev->max_sgl_entries) |
| 1899 | tw_dev->max_sgl_entries = tw_dev->sgl_entries; |
| 1900 | } |
| 1901 | |
| 1902 | /* Now post the command to the board */ |
| 1903 | if (srb) { |
| 1904 | retval = twa_post_command_packet(tw_dev, request_id, 0); |
| 1905 | } else { |
| 1906 | twa_post_command_packet(tw_dev, request_id, 1); |
| 1907 | retval = 0; |
| 1908 | } |
| 1909 | out: |
| 1910 | return retval; |
| 1911 | } /* End twa_scsiop_execute_scsi() */ |
| 1912 | |
| 1913 | /* This function completes an execute scsi operation */ |
| 1914 | static void twa_scsiop_execute_scsi_complete(TW_Device_Extension *tw_dev, int request_id) |
| 1915 | { |
FUJITA Tomonori | 0debe01 | 2007-05-26 02:33:31 +0900 | [diff] [blame] | 1916 | struct scsi_cmnd *cmd = tw_dev->srb[request_id]; |
FUJITA Tomonori | 0debe01 | 2007-05-26 02:33:31 +0900 | [diff] [blame] | 1917 | |
Christoph Hellwig | 15e3d5a | 2015-10-03 19:16:07 +0200 | [diff] [blame] | 1918 | if (!twa_command_mapped(cmd) && |
FUJITA Tomonori | 0debe01 | 2007-05-26 02:33:31 +0900 | [diff] [blame] | 1919 | (cmd->sc_data_direction == DMA_FROM_DEVICE || |
| 1920 | cmd->sc_data_direction == DMA_BIDIRECTIONAL)) { |
FUJITA Tomonori | b1192d5 | 2007-05-31 15:24:03 +0900 | [diff] [blame] | 1921 | if (scsi_sg_count(cmd) == 1) { |
FUJITA Tomonori | 035f5e0 | 2008-03-09 13:44:37 +0900 | [diff] [blame] | 1922 | void *buf = tw_dev->generic_buffer_virt[request_id]; |
| 1923 | |
FUJITA Tomonori | 035f5e0 | 2008-03-09 13:44:37 +0900 | [diff] [blame] | 1924 | scsi_sg_copy_from_buffer(cmd, buf, TW_SECTOR_SIZE); |
adam radford | d327d08 | 2005-09-09 15:55:13 -0700 | [diff] [blame] | 1925 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1926 | } |
| 1927 | } /* End twa_scsiop_execute_scsi_complete() */ |
| 1928 | |
| 1929 | /* This function tells the controller to shut down */ |
| 1930 | static void __twa_shutdown(TW_Device_Extension *tw_dev) |
| 1931 | { |
| 1932 | /* Disable interrupts */ |
| 1933 | TW_DISABLE_INTERRUPTS(tw_dev); |
| 1934 | |
adam radford | 4039c30 | 2006-10-26 18:01:06 -0700 | [diff] [blame] | 1935 | /* Free up the IRQ */ |
| 1936 | free_irq(tw_dev->tw_pci_dev->irq, tw_dev); |
| 1937 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1938 | printk(KERN_WARNING "3w-9xxx: Shutting down host %d.\n", tw_dev->host->host_no); |
| 1939 | |
| 1940 | /* Tell the card we are shutting down */ |
| 1941 | if (twa_initconnection(tw_dev, 1, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL)) { |
| 1942 | TW_PRINTK(tw_dev->host, TW_DRIVER, 0x31, "Connection shutdown failed"); |
| 1943 | } else { |
| 1944 | printk(KERN_WARNING "3w-9xxx: Shutdown complete.\n"); |
| 1945 | } |
| 1946 | |
| 1947 | /* Clear all interrupts just before exit */ |
| 1948 | TW_CLEAR_ALL_INTERRUPTS(tw_dev); |
| 1949 | } /* End __twa_shutdown() */ |
| 1950 | |
| 1951 | /* Wrapper for __twa_shutdown */ |
Greg Kroah-Hartman | d18c3db | 2005-06-23 17:35:56 -0700 | [diff] [blame] | 1952 | static void twa_shutdown(struct pci_dev *pdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1953 | { |
Greg Kroah-Hartman | d18c3db | 2005-06-23 17:35:56 -0700 | [diff] [blame] | 1954 | struct Scsi_Host *host = pci_get_drvdata(pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1955 | TW_Device_Extension *tw_dev = (TW_Device_Extension *)host->hostdata; |
| 1956 | |
| 1957 | __twa_shutdown(tw_dev); |
| 1958 | } /* End twa_shutdown() */ |
| 1959 | |
| 1960 | /* This function will look up a string */ |
| 1961 | static char *twa_string_lookup(twa_message_type *table, unsigned int code) |
| 1962 | { |
| 1963 | int index; |
| 1964 | |
| 1965 | for (index = 0; ((code != table[index].code) && |
| 1966 | (table[index].text != (char *)0)); index++); |
| 1967 | return(table[index].text); |
| 1968 | } /* End twa_string_lookup() */ |
| 1969 | |
adam radford | 4deedd8 | 2010-03-08 12:37:46 -0800 | [diff] [blame] | 1970 | /* This function gets called when a disk is coming on-line */ |
| 1971 | static int twa_slave_configure(struct scsi_device *sdev) |
| 1972 | { |
| 1973 | /* Force 60 second timeout */ |
| 1974 | blk_queue_rq_timeout(sdev->request_queue, 60 * HZ); |
| 1975 | |
| 1976 | return 0; |
| 1977 | } /* End twa_slave_configure() */ |
| 1978 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1979 | /* scsi_host_template initializer */ |
| 1980 | static struct scsi_host_template driver_template = { |
| 1981 | .module = THIS_MODULE, |
| 1982 | .name = "3ware 9000 Storage Controller", |
| 1983 | .queuecommand = twa_scsi_queue, |
| 1984 | .eh_host_reset_handler = twa_scsi_eh_reset, |
| 1985 | .bios_param = twa_scsi_biosparam, |
Christoph Hellwig | db5ed4d | 2014-11-13 15:08:42 +0100 | [diff] [blame] | 1986 | .change_queue_depth = scsi_change_queue_depth, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1987 | .can_queue = TW_Q_LENGTH-2, |
adam radford | 4deedd8 | 2010-03-08 12:37:46 -0800 | [diff] [blame] | 1988 | .slave_configure = twa_slave_configure, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1989 | .this_id = -1, |
| 1990 | .sg_tablesize = TW_APACHE_MAX_SGL_LENGTH, |
| 1991 | .max_sectors = TW_MAX_SECTORS, |
| 1992 | .cmd_per_lun = TW_MAX_CMDS_PER_LUN, |
Bart Van Assche | bd21c1e | 2021-10-12 16:35:19 -0700 | [diff] [blame] | 1993 | .shost_groups = twa_host_groups, |
Martin K. Petersen | 54b2b50 | 2013-10-23 06:25:40 -0400 | [diff] [blame] | 1994 | .emulated = 1, |
| 1995 | .no_write_same = 1, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1996 | }; |
| 1997 | |
| 1998 | /* This function will probe and initialize a card */ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 1999 | static int twa_probe(struct pci_dev *pdev, const struct pci_device_id *dev_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2000 | { |
| 2001 | struct Scsi_Host *host = NULL; |
| 2002 | TW_Device_Extension *tw_dev; |
adam radford | 3dabec7 | 2008-07-22 16:47:40 -0700 | [diff] [blame] | 2003 | unsigned long mem_addr, mem_len; |
Hannes Reinecke | 33d6667 | 2019-02-18 08:34:20 +0100 | [diff] [blame] | 2004 | int retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2005 | |
| 2006 | retval = pci_enable_device(pdev); |
| 2007 | if (retval) { |
| 2008 | TW_PRINTK(host, TW_DRIVER, 0x34, "Failed to enable pci device"); |
| 2009 | goto out_disable_device; |
| 2010 | } |
| 2011 | |
| 2012 | pci_set_master(pdev); |
Tony Battersby | 1e6c38c | 2007-11-09 13:04:35 -0500 | [diff] [blame] | 2013 | pci_try_set_mwi(pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2014 | |
Hannes Reinecke | 33d6667 | 2019-02-18 08:34:20 +0100 | [diff] [blame] | 2015 | retval = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64)); |
| 2016 | if (retval) |
| 2017 | retval = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32)); |
| 2018 | if (retval) { |
Christoph Hellwig | b000bce | 2018-10-10 17:53:41 +0200 | [diff] [blame] | 2019 | TW_PRINTK(host, TW_DRIVER, 0x23, "Failed to set dma mask"); |
| 2020 | retval = -ENODEV; |
| 2021 | goto out_disable_device; |
| 2022 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2023 | |
| 2024 | host = scsi_host_alloc(&driver_template, sizeof(TW_Device_Extension)); |
| 2025 | if (!host) { |
| 2026 | TW_PRINTK(host, TW_DRIVER, 0x24, "Failed to allocate memory for device extension"); |
| 2027 | retval = -ENOMEM; |
| 2028 | goto out_disable_device; |
| 2029 | } |
| 2030 | tw_dev = (TW_Device_Extension *)host->hostdata; |
| 2031 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2032 | /* Save values to device extension */ |
| 2033 | tw_dev->host = host; |
| 2034 | tw_dev->tw_pci_dev = pdev; |
| 2035 | |
| 2036 | if (twa_initialize_device_extension(tw_dev)) { |
| 2037 | TW_PRINTK(tw_dev->host, TW_DRIVER, 0x25, "Failed to initialize device extension"); |
Anton Vasilyev | 4dc98c1 | 2018-07-27 16:51:57 +0300 | [diff] [blame] | 2038 | retval = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2039 | goto out_free_device_extension; |
| 2040 | } |
| 2041 | |
| 2042 | /* Request IO regions */ |
| 2043 | retval = pci_request_regions(pdev, "3w-9xxx"); |
| 2044 | if (retval) { |
| 2045 | TW_PRINTK(tw_dev->host, TW_DRIVER, 0x26, "Failed to get mem region"); |
| 2046 | goto out_free_device_extension; |
| 2047 | } |
| 2048 | |
adam radford | 3dabec7 | 2008-07-22 16:47:40 -0700 | [diff] [blame] | 2049 | if (pdev->device == PCI_DEVICE_ID_3WARE_9000) { |
adam radford | 49bfd8d | 2005-09-21 17:20:14 -0700 | [diff] [blame] | 2050 | mem_addr = pci_resource_start(pdev, 1); |
adam radford | 3dabec7 | 2008-07-22 16:47:40 -0700 | [diff] [blame] | 2051 | mem_len = pci_resource_len(pdev, 1); |
| 2052 | } else { |
adam radford | 49bfd8d | 2005-09-21 17:20:14 -0700 | [diff] [blame] | 2053 | mem_addr = pci_resource_start(pdev, 2); |
adam radford | 3dabec7 | 2008-07-22 16:47:40 -0700 | [diff] [blame] | 2054 | mem_len = pci_resource_len(pdev, 2); |
| 2055 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2056 | |
| 2057 | /* Save base address */ |
adam radford | 3dabec7 | 2008-07-22 16:47:40 -0700 | [diff] [blame] | 2058 | tw_dev->base_addr = ioremap(mem_addr, mem_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2059 | if (!tw_dev->base_addr) { |
| 2060 | TW_PRINTK(tw_dev->host, TW_DRIVER, 0x35, "Failed to ioremap"); |
Anton Vasilyev | 4dc98c1 | 2018-07-27 16:51:57 +0300 | [diff] [blame] | 2061 | retval = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2062 | goto out_release_mem_region; |
| 2063 | } |
| 2064 | |
| 2065 | /* Disable interrupts on the card */ |
| 2066 | TW_DISABLE_INTERRUPTS(tw_dev); |
| 2067 | |
| 2068 | /* Initialize the card */ |
Anton Vasilyev | 4dc98c1 | 2018-07-27 16:51:57 +0300 | [diff] [blame] | 2069 | if (twa_reset_sequence(tw_dev, 0)) { |
| 2070 | retval = -ENOMEM; |
adam radford | 4039c30 | 2006-10-26 18:01:06 -0700 | [diff] [blame] | 2071 | goto out_iounmap; |
Anton Vasilyev | 4dc98c1 | 2018-07-27 16:51:57 +0300 | [diff] [blame] | 2072 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2073 | |
| 2074 | /* Set host specific parameters */ |
adam radford | 0e78d15 | 2007-07-20 15:28:28 -0700 | [diff] [blame] | 2075 | if ((pdev->device == PCI_DEVICE_ID_3WARE_9650SE) || |
| 2076 | (pdev->device == PCI_DEVICE_ID_3WARE_9690SA)) |
adam radford | 4039c30 | 2006-10-26 18:01:06 -0700 | [diff] [blame] | 2077 | host->max_id = TW_MAX_UNITS_9650SE; |
| 2078 | else |
| 2079 | host->max_id = TW_MAX_UNITS; |
| 2080 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2081 | host->max_cmd_len = TW_MAX_CDB_LEN; |
| 2082 | |
| 2083 | /* Channels aren't supported by adapter */ |
adam radford | 4039c30 | 2006-10-26 18:01:06 -0700 | [diff] [blame] | 2084 | host->max_lun = TW_MAX_LUNS(tw_dev->tw_compat_info.working_srl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2085 | host->max_channel = 0; |
| 2086 | |
| 2087 | /* Register the card with the kernel SCSI layer */ |
| 2088 | retval = scsi_add_host(host, &pdev->dev); |
| 2089 | if (retval) { |
| 2090 | TW_PRINTK(tw_dev->host, TW_DRIVER, 0x27, "scsi add host failed"); |
adam radford | 4039c30 | 2006-10-26 18:01:06 -0700 | [diff] [blame] | 2091 | goto out_iounmap; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2092 | } |
| 2093 | |
| 2094 | pci_set_drvdata(pdev, host); |
| 2095 | |
adam radford | 3dabec7 | 2008-07-22 16:47:40 -0700 | [diff] [blame] | 2096 | printk(KERN_WARNING "3w-9xxx: scsi%d: Found a 3ware 9000 Storage Controller at 0x%lx, IRQ: %d.\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2097 | host->host_no, mem_addr, pdev->irq); |
| 2098 | printk(KERN_WARNING "3w-9xxx: scsi%d: Firmware %s, BIOS %s, Ports: %d.\n", |
| 2099 | host->host_no, |
| 2100 | (char *)twa_get_param(tw_dev, 0, TW_VERSION_TABLE, |
| 2101 | TW_PARAM_FWVER, TW_PARAM_FWVER_LENGTH), |
| 2102 | (char *)twa_get_param(tw_dev, 1, TW_VERSION_TABLE, |
| 2103 | TW_PARAM_BIOSVER, TW_PARAM_BIOSVER_LENGTH), |
Samuel Holland | 05f7f1b9 | 2021-04-27 18:59:15 -0500 | [diff] [blame] | 2104 | le32_to_cpu(*(__le32 *)twa_get_param(tw_dev, 2, TW_INFORMATION_TABLE, |
adam radford | 75913d9 | 2006-03-15 12:43:19 -0800 | [diff] [blame] | 2105 | TW_PARAM_PORTCOUNT, TW_PARAM_PORTCOUNT_LENGTH))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2106 | |
adam radford | 3dabec7 | 2008-07-22 16:47:40 -0700 | [diff] [blame] | 2107 | /* Try to enable MSI */ |
| 2108 | if (use_msi && (pdev->device != PCI_DEVICE_ID_3WARE_9000) && |
| 2109 | !pci_enable_msi(pdev)) |
| 2110 | set_bit(TW_USING_MSI, &tw_dev->flags); |
| 2111 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2112 | /* Now setup the interrupt handler */ |
Thomas Gleixner | 1d6f359 | 2006-07-01 19:29:42 -0700 | [diff] [blame] | 2113 | retval = request_irq(pdev->irq, twa_interrupt, IRQF_SHARED, "3w-9xxx", tw_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2114 | if (retval) { |
| 2115 | TW_PRINTK(tw_dev->host, TW_DRIVER, 0x30, "Error requesting IRQ"); |
| 2116 | goto out_remove_host; |
| 2117 | } |
| 2118 | |
| 2119 | twa_device_extension_list[twa_device_extension_count] = tw_dev; |
| 2120 | twa_device_extension_count++; |
| 2121 | |
| 2122 | /* Re-enable interrupts on the card */ |
| 2123 | TW_ENABLE_AND_CLEAR_INTERRUPTS(tw_dev); |
| 2124 | |
| 2125 | /* Finally, scan the host */ |
| 2126 | scsi_scan_host(host); |
| 2127 | |
| 2128 | if (twa_major == -1) { |
| 2129 | if ((twa_major = register_chrdev (0, "twa", &twa_fops)) < 0) |
| 2130 | TW_PRINTK(host, TW_DRIVER, 0x29, "Failed to register character device"); |
| 2131 | } |
| 2132 | return 0; |
| 2133 | |
| 2134 | out_remove_host: |
adam radford | 3dabec7 | 2008-07-22 16:47:40 -0700 | [diff] [blame] | 2135 | if (test_bit(TW_USING_MSI, &tw_dev->flags)) |
| 2136 | pci_disable_msi(pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2137 | scsi_remove_host(host); |
adam radford | 4039c30 | 2006-10-26 18:01:06 -0700 | [diff] [blame] | 2138 | out_iounmap: |
| 2139 | iounmap(tw_dev->base_addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2140 | out_release_mem_region: |
| 2141 | pci_release_regions(pdev); |
| 2142 | out_free_device_extension: |
| 2143 | twa_free_device_extension(tw_dev); |
| 2144 | scsi_host_put(host); |
| 2145 | out_disable_device: |
| 2146 | pci_disable_device(pdev); |
| 2147 | |
| 2148 | return retval; |
| 2149 | } /* End twa_probe() */ |
| 2150 | |
| 2151 | /* This function is called to remove a device */ |
| 2152 | static void twa_remove(struct pci_dev *pdev) |
| 2153 | { |
| 2154 | struct Scsi_Host *host = pci_get_drvdata(pdev); |
| 2155 | TW_Device_Extension *tw_dev = (TW_Device_Extension *)host->hostdata; |
| 2156 | |
| 2157 | scsi_remove_host(tw_dev->host); |
| 2158 | |
| 2159 | /* Unregister character device */ |
| 2160 | if (twa_major >= 0) { |
| 2161 | unregister_chrdev(twa_major, "twa"); |
| 2162 | twa_major = -1; |
| 2163 | } |
| 2164 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2165 | /* Shutdown the card */ |
| 2166 | __twa_shutdown(tw_dev); |
| 2167 | |
adam radford | 3dabec7 | 2008-07-22 16:47:40 -0700 | [diff] [blame] | 2168 | /* Disable MSI if enabled */ |
| 2169 | if (test_bit(TW_USING_MSI, &tw_dev->flags)) |
| 2170 | pci_disable_msi(pdev); |
| 2171 | |
adam radford | 4039c30 | 2006-10-26 18:01:06 -0700 | [diff] [blame] | 2172 | /* Free IO remapping */ |
| 2173 | iounmap(tw_dev->base_addr); |
| 2174 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2175 | /* Free up the mem region */ |
| 2176 | pci_release_regions(pdev); |
| 2177 | |
| 2178 | /* Free up device extension resources */ |
| 2179 | twa_free_device_extension(tw_dev); |
| 2180 | |
| 2181 | scsi_host_put(tw_dev->host); |
| 2182 | pci_disable_device(pdev); |
| 2183 | twa_device_extension_count--; |
| 2184 | } /* End twa_remove() */ |
| 2185 | |
adam radford | 7a252fe | 2009-03-09 12:15:01 -0800 | [diff] [blame] | 2186 | /* This function is called on PCI suspend */ |
Vaibhav Gupta | d53ae6b | 2020-11-02 22:17:23 +0530 | [diff] [blame] | 2187 | static int __maybe_unused twa_suspend(struct device *dev) |
adam radford | 7a252fe | 2009-03-09 12:15:01 -0800 | [diff] [blame] | 2188 | { |
Vaibhav Gupta | d53ae6b | 2020-11-02 22:17:23 +0530 | [diff] [blame] | 2189 | struct pci_dev *pdev = to_pci_dev(dev); |
adam radford | 7a252fe | 2009-03-09 12:15:01 -0800 | [diff] [blame] | 2190 | struct Scsi_Host *host = pci_get_drvdata(pdev); |
| 2191 | TW_Device_Extension *tw_dev = (TW_Device_Extension *)host->hostdata; |
| 2192 | |
| 2193 | printk(KERN_WARNING "3w-9xxx: Suspending host %d.\n", tw_dev->host->host_no); |
| 2194 | |
| 2195 | TW_DISABLE_INTERRUPTS(tw_dev); |
| 2196 | free_irq(tw_dev->tw_pci_dev->irq, tw_dev); |
| 2197 | |
| 2198 | if (test_bit(TW_USING_MSI, &tw_dev->flags)) |
| 2199 | pci_disable_msi(pdev); |
| 2200 | |
| 2201 | /* Tell the card we are shutting down */ |
| 2202 | if (twa_initconnection(tw_dev, 1, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL)) { |
| 2203 | TW_PRINTK(tw_dev->host, TW_DRIVER, 0x38, "Connection shutdown failed during suspend"); |
| 2204 | } else { |
| 2205 | printk(KERN_WARNING "3w-9xxx: Suspend complete.\n"); |
| 2206 | } |
| 2207 | TW_CLEAR_ALL_INTERRUPTS(tw_dev); |
| 2208 | |
adam radford | 7a252fe | 2009-03-09 12:15:01 -0800 | [diff] [blame] | 2209 | return 0; |
| 2210 | } /* End twa_suspend() */ |
| 2211 | |
| 2212 | /* This function is called on PCI resume */ |
Vaibhav Gupta | d53ae6b | 2020-11-02 22:17:23 +0530 | [diff] [blame] | 2213 | static int __maybe_unused twa_resume(struct device *dev) |
adam radford | 7a252fe | 2009-03-09 12:15:01 -0800 | [diff] [blame] | 2214 | { |
| 2215 | int retval = 0; |
Vaibhav Gupta | d53ae6b | 2020-11-02 22:17:23 +0530 | [diff] [blame] | 2216 | struct pci_dev *pdev = to_pci_dev(dev); |
adam radford | 7a252fe | 2009-03-09 12:15:01 -0800 | [diff] [blame] | 2217 | struct Scsi_Host *host = pci_get_drvdata(pdev); |
| 2218 | TW_Device_Extension *tw_dev = (TW_Device_Extension *)host->hostdata; |
| 2219 | |
| 2220 | printk(KERN_WARNING "3w-9xxx: Resuming host %d.\n", tw_dev->host->host_no); |
adam radford | 7a252fe | 2009-03-09 12:15:01 -0800 | [diff] [blame] | 2221 | |
adam radford | 7a252fe | 2009-03-09 12:15:01 -0800 | [diff] [blame] | 2222 | pci_try_set_mwi(pdev); |
| 2223 | |
Hannes Reinecke | 33d6667 | 2019-02-18 08:34:20 +0100 | [diff] [blame] | 2224 | retval = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64)); |
| 2225 | if (retval) |
| 2226 | retval = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32)); |
| 2227 | if (retval) { |
Christoph Hellwig | b000bce | 2018-10-10 17:53:41 +0200 | [diff] [blame] | 2228 | TW_PRINTK(host, TW_DRIVER, 0x40, "Failed to set dma mask during resume"); |
| 2229 | retval = -ENODEV; |
| 2230 | goto out_disable_device; |
| 2231 | } |
adam radford | 7a252fe | 2009-03-09 12:15:01 -0800 | [diff] [blame] | 2232 | |
| 2233 | /* Initialize the card */ |
| 2234 | if (twa_reset_sequence(tw_dev, 0)) { |
| 2235 | retval = -ENODEV; |
| 2236 | goto out_disable_device; |
| 2237 | } |
| 2238 | |
| 2239 | /* Now setup the interrupt handler */ |
| 2240 | retval = request_irq(pdev->irq, twa_interrupt, IRQF_SHARED, "3w-9xxx", tw_dev); |
| 2241 | if (retval) { |
| 2242 | TW_PRINTK(tw_dev->host, TW_DRIVER, 0x42, "Error requesting IRQ during resume"); |
| 2243 | retval = -ENODEV; |
| 2244 | goto out_disable_device; |
| 2245 | } |
| 2246 | |
| 2247 | /* Now enable MSI if enabled */ |
| 2248 | if (test_bit(TW_USING_MSI, &tw_dev->flags)) |
| 2249 | pci_enable_msi(pdev); |
| 2250 | |
| 2251 | /* Re-enable interrupts on the card */ |
| 2252 | TW_ENABLE_AND_CLEAR_INTERRUPTS(tw_dev); |
| 2253 | |
| 2254 | printk(KERN_WARNING "3w-9xxx: Resume complete.\n"); |
| 2255 | return 0; |
| 2256 | |
| 2257 | out_disable_device: |
| 2258 | scsi_remove_host(host); |
adam radford | 7a252fe | 2009-03-09 12:15:01 -0800 | [diff] [blame] | 2259 | |
| 2260 | return retval; |
| 2261 | } /* End twa_resume() */ |
adam radford | 7a252fe | 2009-03-09 12:15:01 -0800 | [diff] [blame] | 2262 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2263 | /* PCI Devices supported by this driver */ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 2264 | static struct pci_device_id twa_pci_tbl[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2265 | { PCI_VENDOR_ID_3WARE, PCI_DEVICE_ID_3WARE_9000, |
| 2266 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, |
adam radford | 49bfd8d | 2005-09-21 17:20:14 -0700 | [diff] [blame] | 2267 | { PCI_VENDOR_ID_3WARE, PCI_DEVICE_ID_3WARE_9550SX, |
| 2268 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, |
adam radford | 4039c30 | 2006-10-26 18:01:06 -0700 | [diff] [blame] | 2269 | { PCI_VENDOR_ID_3WARE, PCI_DEVICE_ID_3WARE_9650SE, |
| 2270 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, |
adam radford | 0e78d15 | 2007-07-20 15:28:28 -0700 | [diff] [blame] | 2271 | { PCI_VENDOR_ID_3WARE, PCI_DEVICE_ID_3WARE_9690SA, |
| 2272 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2273 | { } |
| 2274 | }; |
| 2275 | MODULE_DEVICE_TABLE(pci, twa_pci_tbl); |
| 2276 | |
Vaibhav Gupta | d53ae6b | 2020-11-02 22:17:23 +0530 | [diff] [blame] | 2277 | static SIMPLE_DEV_PM_OPS(twa_pm_ops, twa_suspend, twa_resume); |
| 2278 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2279 | /* pci_driver initializer */ |
| 2280 | static struct pci_driver twa_driver = { |
| 2281 | .name = "3w-9xxx", |
| 2282 | .id_table = twa_pci_tbl, |
| 2283 | .probe = twa_probe, |
| 2284 | .remove = twa_remove, |
Vaibhav Gupta | d53ae6b | 2020-11-02 22:17:23 +0530 | [diff] [blame] | 2285 | .driver.pm = &twa_pm_ops, |
Greg Kroah-Hartman | d18c3db | 2005-06-23 17:35:56 -0700 | [diff] [blame] | 2286 | .shutdown = twa_shutdown |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2287 | }; |
| 2288 | |
| 2289 | /* This function is called on driver initialization */ |
| 2290 | static int __init twa_init(void) |
| 2291 | { |
| 2292 | printk(KERN_WARNING "3ware 9000 Storage Controller device driver for Linux v%s.\n", TW_DRIVER_VERSION); |
| 2293 | |
Henrik Kretzschmar | dcbccbde | 2006-09-25 16:58:58 -0700 | [diff] [blame] | 2294 | return pci_register_driver(&twa_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2295 | } /* End twa_init() */ |
| 2296 | |
| 2297 | /* This function is called on driver exit */ |
| 2298 | static void __exit twa_exit(void) |
| 2299 | { |
| 2300 | pci_unregister_driver(&twa_driver); |
| 2301 | } /* End twa_exit() */ |
| 2302 | |
| 2303 | module_init(twa_init); |
| 2304 | module_exit(twa_exit); |
| 2305 | |