Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    1) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    2)    3w-sas.c -- LSI 3ware SAS/SATA-RAID Controller device driver for Linux.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    3) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    4)    Written By: Adam Radford <aradford@gmail.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    5) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    6)    Copyright (C) 2009 LSI Corporation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    7) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    8)    This program is free software; you can redistribute it and/or modify
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    9)    it under the terms of the GNU General Public License as published by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   10)    the Free Software Foundation; version 2 of the License.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   11) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   12)    This program is distributed in the hope that it will be useful,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   13)    but WITHOUT ANY WARRANTY; without even the implied warranty of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   14)    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   15)    GNU General Public License for more details.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   16) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   17)    NO WARRANTY
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   18)    THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   19)    CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   20)    LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   21)    MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   22)    solely responsible for determining the appropriateness of using and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   23)    distributing the Program and assumes all risks associated with its
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   24)    exercise of rights under this Agreement, including but not limited to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   25)    the risks and costs of program errors, damage to or loss of data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   26)    programs or equipment, and unavailability or interruption of operations.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   27) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   28)    DISCLAIMER OF LIABILITY
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   29)    NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   30)    DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   31)    DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   32)    ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   33)    TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   34)    USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   35)    HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   36) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   37)    You should have received a copy of the GNU General Public License
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   38)    along with this program; if not, write to the Free Software
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   39)    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   40) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   41)    Controllers supported by this driver:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   42) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   43)    LSI 3ware 9750 6Gb/s SAS/SATA-RAID
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   44) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   45)    Bugs/Comments/Suggestions should be mailed to:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   46)    aradford@gmail.com
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   47) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   48)    History
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   49)    -------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   50)    3.26.02.000 - Initial driver release.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   51) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   52) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   53) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   54) #include <linux/reboot.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   55) #include <linux/spinlock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   56) #include <linux/interrupt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   57) #include <linux/moduleparam.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   58) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   59) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   60) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   61) #include <linux/pci.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   62) #include <linux/time.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   63) #include <linux/mutex.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   64) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   65) #include <asm/io.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   66) #include <asm/irq.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   67) #include <linux/uaccess.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   68) #include <scsi/scsi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   69) #include <scsi/scsi_host.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   70) #include <scsi/scsi_tcq.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   71) #include <scsi/scsi_cmnd.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   72) #include "3w-sas.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   73) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   74) /* Globals */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   75) #define TW_DRIVER_VERSION "3.26.02.000"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   76) static DEFINE_MUTEX(twl_chrdev_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   77) static TW_Device_Extension *twl_device_extension_list[TW_MAX_SLOT];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   78) static unsigned int twl_device_extension_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   79) static int twl_major = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   80) extern struct timezone sys_tz;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   81) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   82) /* Module parameters */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   83) MODULE_AUTHOR ("LSI");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   84) MODULE_DESCRIPTION ("LSI 3ware SAS/SATA-RAID Linux Driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   85) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   86) MODULE_VERSION(TW_DRIVER_VERSION);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   87) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   88) static int use_msi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   89) module_param(use_msi, int, S_IRUGO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   90) MODULE_PARM_DESC(use_msi, "Use Message Signaled Interrupts. Default: 0");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   91) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   92) /* Function prototypes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   93) static int twl_reset_device_extension(TW_Device_Extension *tw_dev, int ioctl_reset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   94) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   95) /* Functions */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   96) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   97) /* This function returns AENs through sysfs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   98) static ssize_t twl_sysfs_aen_read(struct file *filp, struct kobject *kobj,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   99) 				  struct bin_attribute *bin_attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  100) 				  char *outbuf, loff_t offset, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  101) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  102) 	struct device *dev = container_of(kobj, struct device, kobj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  103) 	struct Scsi_Host *shost = class_to_shost(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  104) 	TW_Device_Extension *tw_dev = (TW_Device_Extension *)shost->hostdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  105) 	unsigned long flags = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  106) 	ssize_t ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  107) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  108) 	if (!capable(CAP_SYS_ADMIN))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  109) 		return -EACCES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  110) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  111) 	spin_lock_irqsave(tw_dev->host->host_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  112) 	ret = memory_read_from_buffer(outbuf, count, &offset, tw_dev->event_queue[0], sizeof(TW_Event) * TW_Q_LENGTH);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  113) 	spin_unlock_irqrestore(tw_dev->host->host_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  114) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  115) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  116) } /* End twl_sysfs_aen_read() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  117) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  118) /* aen_read sysfs attribute initializer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  119) static struct bin_attribute twl_sysfs_aen_read_attr = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  120) 	.attr = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  121) 		.name = "3ware_aen_read",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  122) 		.mode = S_IRUSR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  123) 	}, 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  124) 	.size = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  125) 	.read = twl_sysfs_aen_read
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  126) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  127) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  128) /* This function returns driver compatibility info through sysfs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  129) static ssize_t twl_sysfs_compat_info(struct file *filp, struct kobject *kobj,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  130) 				     struct bin_attribute *bin_attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  131) 				     char *outbuf, loff_t offset, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  132) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  133) 	struct device *dev = container_of(kobj, struct device, kobj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  134) 	struct Scsi_Host *shost = class_to_shost(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  135) 	TW_Device_Extension *tw_dev = (TW_Device_Extension *)shost->hostdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  136) 	unsigned long flags = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  137) 	ssize_t ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  138) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  139) 	if (!capable(CAP_SYS_ADMIN))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  140) 		return -EACCES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  141) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  142) 	spin_lock_irqsave(tw_dev->host->host_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  143) 	ret = memory_read_from_buffer(outbuf, count, &offset, &tw_dev->tw_compat_info, sizeof(TW_Compatibility_Info));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  144) 	spin_unlock_irqrestore(tw_dev->host->host_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  145) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  146) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  147) } /* End twl_sysfs_compat_info() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  148) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  149) /* compat_info sysfs attribute initializer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  150) static struct bin_attribute twl_sysfs_compat_info_attr = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  151) 	.attr = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  152) 		.name = "3ware_compat_info",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  153) 		.mode = S_IRUSR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  154) 	}, 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  155) 	.size = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  156) 	.read = twl_sysfs_compat_info
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  157) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  158) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  159) /* Show some statistics about the card */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  160) static ssize_t twl_show_stats(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  161) 			      struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  162) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  163) 	struct Scsi_Host *host = class_to_shost(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  164) 	TW_Device_Extension *tw_dev = (TW_Device_Extension *)host->hostdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  165) 	unsigned long flags = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  166) 	ssize_t len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  167) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  168) 	spin_lock_irqsave(tw_dev->host->host_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  169) 	len = snprintf(buf, PAGE_SIZE, "3w-sas Driver version: %s\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  170) 		       "Current commands posted:   %4d\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  171) 		       "Max commands posted:       %4d\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  172) 		       "Last sgl length:           %4d\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  173) 		       "Max sgl length:            %4d\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  174) 		       "Last sector count:         %4d\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  175) 		       "Max sector count:          %4d\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  176) 		       "SCSI Host Resets:          %4d\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  177) 		       "AEN's:                     %4d\n", 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  178) 		       TW_DRIVER_VERSION,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  179) 		       tw_dev->posted_request_count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  180) 		       tw_dev->max_posted_request_count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  181) 		       tw_dev->sgl_entries,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  182) 		       tw_dev->max_sgl_entries,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  183) 		       tw_dev->sector_count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  184) 		       tw_dev->max_sector_count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  185) 		       tw_dev->num_resets,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  186) 		       tw_dev->aen_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  187) 	spin_unlock_irqrestore(tw_dev->host->host_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  188) 	return len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  189) } /* End twl_show_stats() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  190) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  191) /* stats sysfs attribute initializer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  192) static struct device_attribute twl_host_stats_attr = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  193) 	.attr = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  194) 		.name = 	"3ware_stats",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  195) 		.mode =		S_IRUGO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  196) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  197) 	.show = twl_show_stats
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  198) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  199) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  200) /* Host attributes initializer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  201) static struct device_attribute *twl_host_attrs[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  202) 	&twl_host_stats_attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  203) 	NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  204) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  205) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  206) /* This function will look up an AEN severity string */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  207) static char *twl_aen_severity_lookup(unsigned char severity_code)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  208) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  209) 	char *retval = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  210) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  211) 	if ((severity_code < (unsigned char) TW_AEN_SEVERITY_ERROR) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  212) 	    (severity_code > (unsigned char) TW_AEN_SEVERITY_DEBUG))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  213) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  214) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  215) 	retval = twl_aen_severity_table[severity_code];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  216) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  217) 	return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  218) } /* End twl_aen_severity_lookup() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  219) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  220) /* This function will queue an event */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  221) static void twl_aen_queue_event(TW_Device_Extension *tw_dev, TW_Command_Apache_Header *header)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  222) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  223) 	u32 local_time;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  224) 	TW_Event *event;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  225) 	unsigned short aen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  226) 	char host[16];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  227) 	char *error_str;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  228) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  229) 	tw_dev->aen_count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  230) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  231) 	/* Fill out event info */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  232) 	event = tw_dev->event_queue[tw_dev->error_index];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  233) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  234) 	host[0] = '\0';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  235) 	if (tw_dev->host)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  236) 		sprintf(host, " scsi%d:", tw_dev->host->host_no);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  237) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  238) 	aen = le16_to_cpu(header->status_block.error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  239) 	memset(event, 0, sizeof(TW_Event));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  240) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  241) 	event->severity = TW_SEV_OUT(header->status_block.severity__reserved);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  242) 	/* event->time_stamp_sec overflows in y2106 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  243) 	local_time = (u32)(ktime_get_real_seconds() - (sys_tz.tz_minuteswest * 60));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  244) 	event->time_stamp_sec = local_time;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  245) 	event->aen_code = aen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  246) 	event->retrieved = TW_AEN_NOT_RETRIEVED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  247) 	event->sequence_id = tw_dev->error_sequence_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  248) 	tw_dev->error_sequence_id++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  249) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  250) 	/* Check for embedded error string */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  251) 	error_str = &(header->err_specific_desc[strlen(header->err_specific_desc)+1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  252) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  253) 	header->err_specific_desc[sizeof(header->err_specific_desc) - 1] = '\0';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  254) 	event->parameter_len = strlen(header->err_specific_desc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  255) 	memcpy(event->parameter_data, header->err_specific_desc, event->parameter_len + 1 + strlen(error_str));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  256) 	if (event->severity != TW_AEN_SEVERITY_DEBUG)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  257) 		printk(KERN_WARNING "3w-sas:%s AEN: %s (0x%02X:0x%04X): %s:%s.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  258) 		       host,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  259) 		       twl_aen_severity_lookup(TW_SEV_OUT(header->status_block.severity__reserved)),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  260) 		       TW_MESSAGE_SOURCE_CONTROLLER_EVENT, aen, error_str,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  261) 		       header->err_specific_desc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  262) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  263) 		tw_dev->aen_count--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  264) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  265) 	tw_dev->error_index = (tw_dev->error_index + 1 ) % TW_Q_LENGTH;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  266) } /* End twl_aen_queue_event() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  267) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  268) /* This function will attempt to post a command packet to the board */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  269) static int twl_post_command_packet(TW_Device_Extension *tw_dev, int request_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  270) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  271) 	dma_addr_t command_que_value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  272) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  273) 	command_que_value = tw_dev->command_packet_phys[request_id];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  274) 	command_que_value += TW_COMMAND_OFFSET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  275) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  276) 	/* First write upper 4 bytes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  277) 	writel((u32)((u64)command_que_value >> 32), TWL_HIBQPH_REG_ADDR(tw_dev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  278) 	/* Then the lower 4 bytes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  279) 	writel((u32)(command_que_value | TWL_PULL_MODE), TWL_HIBQPL_REG_ADDR(tw_dev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  280) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  281) 	tw_dev->state[request_id] = TW_S_POSTED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  282) 	tw_dev->posted_request_count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  283) 	if (tw_dev->posted_request_count > tw_dev->max_posted_request_count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  284) 		tw_dev->max_posted_request_count = tw_dev->posted_request_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  285) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  286) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  287) } /* End twl_post_command_packet() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  288) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  289) /* This function hands scsi cdb's to the firmware */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  290) static int twl_scsiop_execute_scsi(TW_Device_Extension *tw_dev, int request_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  291) 				   unsigned char *cdb, int use_sg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  292) 				   TW_SG_Entry_ISO *sglistarg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  293) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  294) 	TW_Command_Full *full_command_packet;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  295) 	TW_Command_Apache *command_packet;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  296) 	int i, sg_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  297) 	struct scsi_cmnd *srb = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  298) 	struct scatterlist *sglist = NULL, *sg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  299) 	int retval = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  300) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  301) 	if (tw_dev->srb[request_id]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  302) 		srb = tw_dev->srb[request_id];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  303) 		if (scsi_sglist(srb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  304) 			sglist = scsi_sglist(srb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  305) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  306) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  307) 	/* Initialize command packet */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  308) 	full_command_packet = tw_dev->command_packet_virt[request_id];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  309) 	full_command_packet->header.header_desc.size_header = 128;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  310) 	full_command_packet->header.status_block.error = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  311) 	full_command_packet->header.status_block.severity__reserved = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  312) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  313) 	command_packet = &full_command_packet->command.newcommand;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  314) 	command_packet->status = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  315) 	command_packet->opcode__reserved = TW_OPRES_IN(0, TW_OP_EXECUTE_SCSI);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  316) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  317) 	/* We forced 16 byte cdb use earlier */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  318) 	if (!cdb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  319) 		memcpy(command_packet->cdb, srb->cmnd, TW_MAX_CDB_LEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  320) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  321) 		memcpy(command_packet->cdb, cdb, TW_MAX_CDB_LEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  322) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  323) 	if (srb) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  324) 		command_packet->unit = srb->device->id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  325) 		command_packet->request_id__lunl =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  326) 			cpu_to_le16(TW_REQ_LUN_IN(srb->device->lun, request_id));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  327) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  328) 		command_packet->request_id__lunl =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  329) 			cpu_to_le16(TW_REQ_LUN_IN(0, request_id));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  330) 		command_packet->unit = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  331) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  332) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  333) 	command_packet->sgl_offset = 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  334) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  335) 	if (!sglistarg) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  336) 		/* Map sglist from scsi layer to cmd packet */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  337) 		if (scsi_sg_count(srb)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  338) 			sg_count = scsi_dma_map(srb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  339) 			if (sg_count <= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  340) 				goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  341) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  342) 			scsi_for_each_sg(srb, sg, sg_count, i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  343) 				command_packet->sg_list[i].address = TW_CPU_TO_SGL(sg_dma_address(sg));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  344) 				command_packet->sg_list[i].length = TW_CPU_TO_SGL(sg_dma_len(sg));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  345) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  346) 			command_packet->sgl_entries__lunh = cpu_to_le16(TW_REQ_LUN_IN((srb->device->lun >> 4), scsi_sg_count(tw_dev->srb[request_id])));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  347) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  348) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  349) 		/* Internal cdb post */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  350) 		for (i = 0; i < use_sg; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  351) 			command_packet->sg_list[i].address = TW_CPU_TO_SGL(sglistarg[i].address);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  352) 			command_packet->sg_list[i].length = TW_CPU_TO_SGL(sglistarg[i].length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  353) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  354) 		command_packet->sgl_entries__lunh = cpu_to_le16(TW_REQ_LUN_IN(0, use_sg));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  355) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  356) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  357) 	/* Update some stats */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  358) 	if (srb) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  359) 		tw_dev->sector_count = scsi_bufflen(srb) / 512;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  360) 		if (tw_dev->sector_count > tw_dev->max_sector_count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  361) 			tw_dev->max_sector_count = tw_dev->sector_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  362) 		tw_dev->sgl_entries = scsi_sg_count(srb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  363) 		if (tw_dev->sgl_entries > tw_dev->max_sgl_entries)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  364) 			tw_dev->max_sgl_entries = tw_dev->sgl_entries;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  365) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  366) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  367) 	/* Now post the command to the board */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  368) 	retval = twl_post_command_packet(tw_dev, request_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  369) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  370) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  371) 	return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  372) } /* End twl_scsiop_execute_scsi() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  373) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  374) /* This function will read the aen queue from the isr */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  375) static int twl_aen_read_queue(TW_Device_Extension *tw_dev, int request_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  376) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  377) 	unsigned char cdb[TW_MAX_CDB_LEN];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  378) 	TW_SG_Entry_ISO sglist[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  379) 	TW_Command_Full *full_command_packet;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  380) 	int retval = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  381) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  382) 	full_command_packet = tw_dev->command_packet_virt[request_id];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  383) 	memset(full_command_packet, 0, sizeof(TW_Command_Full));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  384) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  385) 	/* Initialize cdb */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  386) 	memset(&cdb, 0, TW_MAX_CDB_LEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  387) 	cdb[0] = REQUEST_SENSE; /* opcode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  388) 	cdb[4] = TW_ALLOCATION_LENGTH; /* allocation length */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  389) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  390) 	/* Initialize sglist */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  391) 	memset(&sglist, 0, sizeof(TW_SG_Entry_ISO));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  392) 	sglist[0].length = TW_SECTOR_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  393) 	sglist[0].address = tw_dev->generic_buffer_phys[request_id];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  394) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  395) 	/* Mark internal command */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  396) 	tw_dev->srb[request_id] = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  397) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  398) 	/* Now post the command packet */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  399) 	if (twl_scsiop_execute_scsi(tw_dev, request_id, cdb, 1, sglist)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  400) 		TW_PRINTK(tw_dev->host, TW_DRIVER, 0x2, "Post failed while reading AEN queue");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  401) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  402) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  403) 	retval = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  404) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  405) 	return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  406) } /* End twl_aen_read_queue() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  407) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  408) /* This function will sync firmware time with the host time */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  409) static void twl_aen_sync_time(TW_Device_Extension *tw_dev, int request_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  410) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  411) 	u32 schedulertime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  412) 	TW_Command_Full *full_command_packet;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  413) 	TW_Command *command_packet;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  414) 	TW_Param_Apache *param;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  415) 	time64_t local_time;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  416) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  417) 	/* Fill out the command packet */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  418) 	full_command_packet = tw_dev->command_packet_virt[request_id];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  419) 	memset(full_command_packet, 0, sizeof(TW_Command_Full));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  420) 	command_packet = &full_command_packet->command.oldcommand;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  421) 	command_packet->opcode__sgloffset = TW_OPSGL_IN(2, TW_OP_SET_PARAM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  422) 	command_packet->request_id = request_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  423) 	command_packet->byte8_offset.param.sgl[0].address = TW_CPU_TO_SGL(tw_dev->generic_buffer_phys[request_id]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  424) 	command_packet->byte8_offset.param.sgl[0].length = TW_CPU_TO_SGL(TW_SECTOR_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  425) 	command_packet->size = TW_COMMAND_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  426) 	command_packet->byte6_offset.parameter_count = cpu_to_le16(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  427) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  428) 	/* Setup the param */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  429) 	param = (TW_Param_Apache *)tw_dev->generic_buffer_virt[request_id];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  430) 	memset(param, 0, TW_SECTOR_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  431) 	param->table_id = cpu_to_le16(TW_TIMEKEEP_TABLE | 0x8000); /* Controller time keep table */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  432) 	param->parameter_id = cpu_to_le16(0x3); /* SchedulerTime */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  433) 	param->parameter_size_bytes = cpu_to_le16(4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  434) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  435) 	/* Convert system time in UTC to local time seconds since last 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  436)            Sunday 12:00AM */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  437) 	local_time = (ktime_get_real_seconds() - (sys_tz.tz_minuteswest * 60));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  438) 	div_u64_rem(local_time - (3 * 86400), 604800, &schedulertime);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  439) 	schedulertime = cpu_to_le32(schedulertime);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  440) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  441) 	memcpy(param->data, &schedulertime, sizeof(u32));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  442) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  443) 	/* Mark internal command */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  444) 	tw_dev->srb[request_id] = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  445) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  446) 	/* Now post the command */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  447) 	twl_post_command_packet(tw_dev, request_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  448) } /* End twl_aen_sync_time() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  449) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  450) /* This function will assign an available request id */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  451) static void twl_get_request_id(TW_Device_Extension *tw_dev, int *request_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  452) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  453) 	*request_id = tw_dev->free_queue[tw_dev->free_head];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  454) 	tw_dev->free_head = (tw_dev->free_head + 1) % TW_Q_LENGTH;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  455) 	tw_dev->state[*request_id] = TW_S_STARTED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  456) } /* End twl_get_request_id() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  457) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  458) /* This function will free a request id */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  459) static void twl_free_request_id(TW_Device_Extension *tw_dev, int request_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  460) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  461) 	tw_dev->free_queue[tw_dev->free_tail] = request_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  462) 	tw_dev->state[request_id] = TW_S_FINISHED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  463) 	tw_dev->free_tail = (tw_dev->free_tail + 1) % TW_Q_LENGTH;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  464) } /* End twl_free_request_id() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  465) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  466) /* This function will complete an aen request from the isr */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  467) static int twl_aen_complete(TW_Device_Extension *tw_dev, int request_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  468) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  469) 	TW_Command_Full *full_command_packet;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  470) 	TW_Command *command_packet;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  471) 	TW_Command_Apache_Header *header;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  472) 	unsigned short aen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  473) 	int retval = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  474) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  475) 	header = (TW_Command_Apache_Header *)tw_dev->generic_buffer_virt[request_id];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  476) 	tw_dev->posted_request_count--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  477) 	aen = le16_to_cpu(header->status_block.error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  478) 	full_command_packet = tw_dev->command_packet_virt[request_id];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  479) 	command_packet = &full_command_packet->command.oldcommand;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  480) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  481) 	/* First check for internal completion of set param for time sync */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  482) 	if (TW_OP_OUT(command_packet->opcode__sgloffset) == TW_OP_SET_PARAM) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  483) 		/* Keep reading the queue in case there are more aen's */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  484) 		if (twl_aen_read_queue(tw_dev, request_id))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  485) 			goto out2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  486) 	        else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  487) 			retval = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  488) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  489) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  490) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  491) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  492) 	switch (aen) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  493) 	case TW_AEN_QUEUE_EMPTY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  494) 		/* Quit reading the queue if this is the last one */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  495) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  496) 	case TW_AEN_SYNC_TIME_WITH_HOST:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  497) 		twl_aen_sync_time(tw_dev, request_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  498) 		retval = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  499) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  500) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  501) 		twl_aen_queue_event(tw_dev, header);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  502) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  503) 		/* If there are more aen's, keep reading the queue */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  504) 		if (twl_aen_read_queue(tw_dev, request_id))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  505) 			goto out2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  506) 		else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  507) 			retval = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  508) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  509) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  510) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  511) 	retval = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  512) out2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  513) 	tw_dev->state[request_id] = TW_S_COMPLETED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  514) 	twl_free_request_id(tw_dev, request_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  515) 	clear_bit(TW_IN_ATTENTION_LOOP, &tw_dev->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  516) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  517) 	return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  518) } /* End twl_aen_complete() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  519) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  520) /* This function will poll for a response */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  521) static int twl_poll_response(TW_Device_Extension *tw_dev, int request_id, int seconds)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  522) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  523) 	unsigned long before;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  524) 	dma_addr_t mfa;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  525) 	u32 regh, regl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  526) 	u32 response;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  527) 	int retval = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  528) 	int found = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  529) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  530) 	before = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  531) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  532) 	while (!found) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  533) 		if (sizeof(dma_addr_t) > 4) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  534) 			regh = readl(TWL_HOBQPH_REG_ADDR(tw_dev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  535) 			regl = readl(TWL_HOBQPL_REG_ADDR(tw_dev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  536) 			mfa = ((u64)regh << 32) | regl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  537) 		} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  538) 			mfa = readl(TWL_HOBQPL_REG_ADDR(tw_dev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  539) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  540) 		response = (u32)mfa;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  541) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  542) 		if (TW_RESID_OUT(response) == request_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  543) 			found = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  544) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  545) 		if (time_after(jiffies, before + HZ * seconds))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  546) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  547) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  548) 		msleep(50);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  549) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  550) 	retval = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  551) out: 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  552) 	return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  553) } /* End twl_poll_response() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  554) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  555) /* This function will drain the aen queue */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  556) static int twl_aen_drain_queue(TW_Device_Extension *tw_dev, int no_check_reset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  557) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  558) 	int request_id = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  559) 	unsigned char cdb[TW_MAX_CDB_LEN];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  560) 	TW_SG_Entry_ISO sglist[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  561) 	int finished = 0, count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  562) 	TW_Command_Full *full_command_packet;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  563) 	TW_Command_Apache_Header *header;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  564) 	unsigned short aen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  565) 	int first_reset = 0, queue = 0, retval = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  566) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  567) 	if (no_check_reset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  568) 		first_reset = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  569) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  570) 		first_reset = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  571) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  572) 	full_command_packet = tw_dev->command_packet_virt[request_id];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  573) 	memset(full_command_packet, 0, sizeof(TW_Command_Full));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  574) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  575) 	/* Initialize cdb */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  576) 	memset(&cdb, 0, TW_MAX_CDB_LEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  577) 	cdb[0] = REQUEST_SENSE; /* opcode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  578) 	cdb[4] = TW_ALLOCATION_LENGTH; /* allocation length */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  579) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  580) 	/* Initialize sglist */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  581) 	memset(&sglist, 0, sizeof(TW_SG_Entry_ISO));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  582) 	sglist[0].length = TW_SECTOR_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  583) 	sglist[0].address = tw_dev->generic_buffer_phys[request_id];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  584) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  585) 	/* Mark internal command */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  586) 	tw_dev->srb[request_id] = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  587) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  588) 	do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  589) 		/* Send command to the board */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  590) 		if (twl_scsiop_execute_scsi(tw_dev, request_id, cdb, 1, sglist)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  591) 			TW_PRINTK(tw_dev->host, TW_DRIVER, 0x3, "Error posting request sense");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  592) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  593) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  594) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  595) 		/* Now poll for completion */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  596) 		if (twl_poll_response(tw_dev, request_id, 30)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  597) 			TW_PRINTK(tw_dev->host, TW_DRIVER, 0x4, "No valid response while draining AEN queue");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  598) 			tw_dev->posted_request_count--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  599) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  600) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  601) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  602) 		tw_dev->posted_request_count--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  603) 		header = (TW_Command_Apache_Header *)tw_dev->generic_buffer_virt[request_id];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  604) 		aen = le16_to_cpu(header->status_block.error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  605) 		queue = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  606) 		count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  607) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  608) 		switch (aen) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  609) 		case TW_AEN_QUEUE_EMPTY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  610) 			if (first_reset != 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  611) 				goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  612) 			else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  613) 				finished = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  614) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  615) 		case TW_AEN_SOFT_RESET:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  616) 			if (first_reset == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  617) 				first_reset = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  618) 			else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  619) 				queue = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  620) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  621) 		case TW_AEN_SYNC_TIME_WITH_HOST:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  622) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  623) 		default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  624) 			queue = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  625) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  626) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  627) 		/* Now queue an event info */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  628) 		if (queue)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  629) 			twl_aen_queue_event(tw_dev, header);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  630) 	} while ((finished == 0) && (count < TW_MAX_AEN_DRAIN));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  631) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  632) 	if (count == TW_MAX_AEN_DRAIN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  633) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  634) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  635) 	retval = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  636) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  637) 	tw_dev->state[request_id] = TW_S_INITIAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  638) 	return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  639) } /* End twl_aen_drain_queue() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  640) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  641) /* This function will allocate memory and check if it is correctly aligned */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  642) static int twl_allocate_memory(TW_Device_Extension *tw_dev, int size, int which)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  643) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  644) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  645) 	dma_addr_t dma_handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  646) 	unsigned long *cpu_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  647) 	int retval = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  648) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  649) 	cpu_addr = dma_alloc_coherent(&tw_dev->tw_pci_dev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  650) 				      size * TW_Q_LENGTH, &dma_handle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  651) 				      GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  652) 	if (!cpu_addr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  653) 		TW_PRINTK(tw_dev->host, TW_DRIVER, 0x5, "Memory allocation failed");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  654) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  655) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  656) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  657) 	for (i = 0; i < TW_Q_LENGTH; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  658) 		switch(which) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  659) 		case 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  660) 			tw_dev->command_packet_phys[i] = dma_handle+(i*size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  661) 			tw_dev->command_packet_virt[i] = (TW_Command_Full *)((unsigned char *)cpu_addr + (i*size));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  662) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  663) 		case 1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  664) 			tw_dev->generic_buffer_phys[i] = dma_handle+(i*size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  665) 			tw_dev->generic_buffer_virt[i] = (unsigned long *)((unsigned char *)cpu_addr + (i*size));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  666) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  667) 		case 2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  668) 			tw_dev->sense_buffer_phys[i] = dma_handle+(i*size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  669) 			tw_dev->sense_buffer_virt[i] = (TW_Command_Apache_Header *)((unsigned char *)cpu_addr + (i*size));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  670) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  671) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  672) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  673) 	retval = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  674) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  675) 	return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  676) } /* End twl_allocate_memory() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  677) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  678) /* This function will load the request id and various sgls for ioctls */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  679) static void twl_load_sgl(TW_Device_Extension *tw_dev, TW_Command_Full *full_command_packet, int request_id, dma_addr_t dma_handle, int length)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  680) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  681) 	TW_Command *oldcommand;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  682) 	TW_Command_Apache *newcommand;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  683) 	TW_SG_Entry_ISO *sgl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  684) 	unsigned int pae = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  685) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  686) 	if ((sizeof(long) < 8) && (sizeof(dma_addr_t) > 4))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  687) 		pae = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  688) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  689) 	if (TW_OP_OUT(full_command_packet->command.newcommand.opcode__reserved) == TW_OP_EXECUTE_SCSI) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  690) 		newcommand = &full_command_packet->command.newcommand;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  691) 		newcommand->request_id__lunl =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  692) 			cpu_to_le16(TW_REQ_LUN_IN(TW_LUN_OUT(newcommand->request_id__lunl), request_id));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  693) 		if (length) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  694) 			newcommand->sg_list[0].address = TW_CPU_TO_SGL(dma_handle + sizeof(TW_Ioctl_Buf_Apache) - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  695) 			newcommand->sg_list[0].length = TW_CPU_TO_SGL(length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  696) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  697) 		newcommand->sgl_entries__lunh =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  698) 			cpu_to_le16(TW_REQ_LUN_IN(TW_LUN_OUT(newcommand->sgl_entries__lunh), length ? 1 : 0));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  699) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  700) 		oldcommand = &full_command_packet->command.oldcommand;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  701) 		oldcommand->request_id = request_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  702) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  703) 		if (TW_SGL_OUT(oldcommand->opcode__sgloffset)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  704) 			/* Load the sg list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  705) 			sgl = (TW_SG_Entry_ISO *)((u32 *)oldcommand+oldcommand->size - (sizeof(TW_SG_Entry_ISO)/4) + pae + (sizeof(dma_addr_t) > 4 ? 1 : 0));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  706) 			sgl->address = TW_CPU_TO_SGL(dma_handle + sizeof(TW_Ioctl_Buf_Apache) - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  707) 			sgl->length = TW_CPU_TO_SGL(length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  708) 			oldcommand->size += pae;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  709) 			oldcommand->size += sizeof(dma_addr_t) > 4 ? 1 : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  710) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  711) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  712) } /* End twl_load_sgl() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  713) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  714) /* This function handles ioctl for the character device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  715)    This interface is used by smartmontools open source software */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  716) static long twl_chrdev_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  717) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  718) 	long timeout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  719) 	unsigned long *cpu_addr, data_buffer_length_adjusted = 0, flags = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  720) 	dma_addr_t dma_handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  721) 	int request_id = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  722) 	TW_Ioctl_Driver_Command driver_command;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  723) 	struct inode *inode = file_inode(file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  724) 	TW_Ioctl_Buf_Apache *tw_ioctl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  725) 	TW_Command_Full *full_command_packet;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  726) 	TW_Device_Extension *tw_dev = twl_device_extension_list[iminor(inode)];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  727) 	int retval = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  728) 	void __user *argp = (void __user *)arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  729) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  730) 	mutex_lock(&twl_chrdev_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  731) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  732) 	/* Only let one of these through at a time */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  733) 	if (mutex_lock_interruptible(&tw_dev->ioctl_lock)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  734) 		retval = -EINTR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  735) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  736) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  737) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  738) 	/* First copy down the driver command */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  739) 	if (copy_from_user(&driver_command, argp, sizeof(TW_Ioctl_Driver_Command)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  740) 		goto out2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  741) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  742) 	/* Check data buffer size */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  743) 	if (driver_command.buffer_length > TW_MAX_SECTORS * 2048) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  744) 		retval = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  745) 		goto out2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  746) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  747) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  748) 	/* Hardware can only do multiple of 512 byte transfers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  749) 	data_buffer_length_adjusted = (driver_command.buffer_length + 511) & ~511;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  750) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  751) 	/* Now allocate ioctl buf memory */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  752) 	cpu_addr = dma_alloc_coherent(&tw_dev->tw_pci_dev->dev, data_buffer_length_adjusted+sizeof(TW_Ioctl_Buf_Apache) - 1, &dma_handle, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  753) 	if (!cpu_addr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  754) 		retval = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  755) 		goto out2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  756) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  757) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  758) 	tw_ioctl = (TW_Ioctl_Buf_Apache *)cpu_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  759) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  760) 	/* Now copy down the entire ioctl */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  761) 	if (copy_from_user(tw_ioctl, argp, driver_command.buffer_length + sizeof(TW_Ioctl_Buf_Apache) - 1))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  762) 		goto out3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  763) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  764) 	/* See which ioctl we are doing */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  765) 	switch (cmd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  766) 	case TW_IOCTL_FIRMWARE_PASS_THROUGH:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  767) 		spin_lock_irqsave(tw_dev->host->host_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  768) 		twl_get_request_id(tw_dev, &request_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  769) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  770) 		/* Flag internal command */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  771) 		tw_dev->srb[request_id] = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  772) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  773) 		/* Flag chrdev ioctl */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  774) 		tw_dev->chrdev_request_id = request_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  775) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  776) 		full_command_packet = (TW_Command_Full *)&tw_ioctl->firmware_command;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  777) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  778) 		/* Load request id and sglist for both command types */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  779) 		twl_load_sgl(tw_dev, full_command_packet, request_id, dma_handle, data_buffer_length_adjusted);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  780) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  781) 		memcpy(tw_dev->command_packet_virt[request_id], &(tw_ioctl->firmware_command), sizeof(TW_Command_Full));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  782) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  783) 		/* Now post the command packet to the controller */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  784) 		twl_post_command_packet(tw_dev, request_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  785) 		spin_unlock_irqrestore(tw_dev->host->host_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  786) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  787) 		timeout = TW_IOCTL_CHRDEV_TIMEOUT*HZ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  788) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  789) 		/* Now wait for command to complete */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  790) 		timeout = wait_event_timeout(tw_dev->ioctl_wqueue, tw_dev->chrdev_request_id == TW_IOCTL_CHRDEV_FREE, timeout);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  791) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  792) 		/* We timed out, and didn't get an interrupt */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  793) 		if (tw_dev->chrdev_request_id != TW_IOCTL_CHRDEV_FREE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  794) 			/* Now we need to reset the board */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  795) 			printk(KERN_WARNING "3w-sas: scsi%d: WARNING: (0x%02X:0x%04X): Character ioctl (0x%x) timed out, resetting card.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  796) 			       tw_dev->host->host_no, TW_DRIVER, 0x6,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  797) 			       cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  798) 			retval = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  799) 			twl_reset_device_extension(tw_dev, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  800) 			goto out3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  801) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  802) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  803) 		/* Now copy in the command packet response */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  804) 		memcpy(&(tw_ioctl->firmware_command), tw_dev->command_packet_virt[request_id], sizeof(TW_Command_Full));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  805) 		
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  806) 		/* Now complete the io */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  807) 		spin_lock_irqsave(tw_dev->host->host_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  808) 		tw_dev->posted_request_count--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  809) 		tw_dev->state[request_id] = TW_S_COMPLETED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  810) 		twl_free_request_id(tw_dev, request_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  811) 		spin_unlock_irqrestore(tw_dev->host->host_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  812) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  813) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  814) 		retval = -ENOTTY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  815) 		goto out3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  816) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  817) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  818) 	/* Now copy the entire response to userspace */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  819) 	if (copy_to_user(argp, tw_ioctl, sizeof(TW_Ioctl_Buf_Apache) + driver_command.buffer_length - 1) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  820) 		retval = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  821) out3:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  822) 	/* Now free ioctl buf memory */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  823) 	dma_free_coherent(&tw_dev->tw_pci_dev->dev, data_buffer_length_adjusted+sizeof(TW_Ioctl_Buf_Apache) - 1, cpu_addr, dma_handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  824) out2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  825) 	mutex_unlock(&tw_dev->ioctl_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  826) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  827) 	mutex_unlock(&twl_chrdev_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  828) 	return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  829) } /* End twl_chrdev_ioctl() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  830) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  831) /* This function handles open for the character device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  832) static int twl_chrdev_open(struct inode *inode, struct file *file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  833) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  834) 	unsigned int minor_number;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  835) 	int retval = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  836) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  837) 	if (!capable(CAP_SYS_ADMIN)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  838) 		retval = -EACCES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  839) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  840) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  841) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  842) 	minor_number = iminor(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  843) 	if (minor_number >= twl_device_extension_count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  844) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  845) 	retval = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  846) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  847) 	return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  848) } /* End twl_chrdev_open() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  849) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  850) /* File operations struct for character device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  851) static const struct file_operations twl_fops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  852) 	.owner		= THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  853) 	.unlocked_ioctl	= twl_chrdev_ioctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  854) 	.open		= twl_chrdev_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  855) 	.release	= NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  856) 	.llseek		= noop_llseek,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  857) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  858) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  859) /* This function passes sense data from firmware to scsi layer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  860) static int twl_fill_sense(TW_Device_Extension *tw_dev, int i, int request_id, int copy_sense, int print_host)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  861) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  862) 	TW_Command_Apache_Header *header;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  863) 	TW_Command_Full *full_command_packet;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  864) 	unsigned short error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  865) 	char *error_str;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  866) 	int retval = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  867) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  868) 	header = tw_dev->sense_buffer_virt[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  869) 	full_command_packet = tw_dev->command_packet_virt[request_id];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  870) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  871) 	/* Get embedded firmware error string */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  872) 	error_str = &(header->err_specific_desc[strlen(header->err_specific_desc) + 1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  873) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  874) 	/* Don't print error for Logical unit not supported during rollcall */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  875) 	error = le16_to_cpu(header->status_block.error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  876) 	if ((error != TW_ERROR_LOGICAL_UNIT_NOT_SUPPORTED) && (error != TW_ERROR_UNIT_OFFLINE) && (error != TW_ERROR_INVALID_FIELD_IN_CDB)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  877) 		if (print_host)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  878) 			printk(KERN_WARNING "3w-sas: scsi%d: ERROR: (0x%02X:0x%04X): %s:%s.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  879) 			       tw_dev->host->host_no,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  880) 			       TW_MESSAGE_SOURCE_CONTROLLER_ERROR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  881) 			       header->status_block.error,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  882) 			       error_str, 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  883) 			       header->err_specific_desc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  884) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  885) 			printk(KERN_WARNING "3w-sas: ERROR: (0x%02X:0x%04X): %s:%s.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  886) 			       TW_MESSAGE_SOURCE_CONTROLLER_ERROR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  887) 			       header->status_block.error,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  888) 			       error_str,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  889) 			       header->err_specific_desc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  890) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  891) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  892) 	if (copy_sense) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  893) 		memcpy(tw_dev->srb[request_id]->sense_buffer, header->sense_data, TW_SENSE_DATA_LENGTH);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  894) 		tw_dev->srb[request_id]->result = (full_command_packet->command.newcommand.status << 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  895) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  896) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  897) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  898) 	return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  899) } /* End twl_fill_sense() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  900) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  901) /* This function will free up device extension resources */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  902) static void twl_free_device_extension(TW_Device_Extension *tw_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  903) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  904) 	if (tw_dev->command_packet_virt[0])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  905) 		dma_free_coherent(&tw_dev->tw_pci_dev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  906) 				    sizeof(TW_Command_Full)*TW_Q_LENGTH,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  907) 				    tw_dev->command_packet_virt[0],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  908) 				    tw_dev->command_packet_phys[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  909) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  910) 	if (tw_dev->generic_buffer_virt[0])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  911) 		dma_free_coherent(&tw_dev->tw_pci_dev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  912) 				    TW_SECTOR_SIZE*TW_Q_LENGTH,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  913) 				    tw_dev->generic_buffer_virt[0],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  914) 				    tw_dev->generic_buffer_phys[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  915) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  916) 	if (tw_dev->sense_buffer_virt[0])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  917) 		dma_free_coherent(&tw_dev->tw_pci_dev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  918) 				    sizeof(TW_Command_Apache_Header)*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  919) 				    TW_Q_LENGTH,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  920) 				    tw_dev->sense_buffer_virt[0],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  921) 				    tw_dev->sense_buffer_phys[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  922) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  923) 	kfree(tw_dev->event_queue[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  924) } /* End twl_free_device_extension() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  925) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  926) /* This function will get parameter table entries from the firmware */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  927) static void *twl_get_param(TW_Device_Extension *tw_dev, int request_id, int table_id, int parameter_id, int parameter_size_bytes)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  928) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  929) 	TW_Command_Full *full_command_packet;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  930) 	TW_Command *command_packet;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  931) 	TW_Param_Apache *param;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  932) 	void *retval = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  933) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  934) 	/* Setup the command packet */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  935) 	full_command_packet = tw_dev->command_packet_virt[request_id];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  936) 	memset(full_command_packet, 0, sizeof(TW_Command_Full));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  937) 	command_packet = &full_command_packet->command.oldcommand;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  938) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  939) 	command_packet->opcode__sgloffset = TW_OPSGL_IN(2, TW_OP_GET_PARAM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  940) 	command_packet->size              = TW_COMMAND_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  941) 	command_packet->request_id        = request_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  942) 	command_packet->byte6_offset.block_count = cpu_to_le16(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  943) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  944) 	/* Now setup the param */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  945) 	param = (TW_Param_Apache *)tw_dev->generic_buffer_virt[request_id];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  946) 	memset(param, 0, TW_SECTOR_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  947) 	param->table_id = cpu_to_le16(table_id | 0x8000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  948) 	param->parameter_id = cpu_to_le16(parameter_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  949) 	param->parameter_size_bytes = cpu_to_le16(parameter_size_bytes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  950) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  951) 	command_packet->byte8_offset.param.sgl[0].address = TW_CPU_TO_SGL(tw_dev->generic_buffer_phys[request_id]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  952) 	command_packet->byte8_offset.param.sgl[0].length = TW_CPU_TO_SGL(TW_SECTOR_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  953) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  954) 	/* Post the command packet to the board */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  955) 	twl_post_command_packet(tw_dev, request_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  956) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  957) 	/* Poll for completion */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  958) 	if (twl_poll_response(tw_dev, request_id, 30))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  959) 		TW_PRINTK(tw_dev->host, TW_DRIVER, 0x7, "No valid response during get param")
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  960) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  961) 		retval = (void *)&(param->data[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  962) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  963) 	tw_dev->posted_request_count--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  964) 	tw_dev->state[request_id] = TW_S_INITIAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  965) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  966) 	return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  967) } /* End twl_get_param() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  968) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  969) /* This function will send an initconnection command to controller */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  970) static int twl_initconnection(TW_Device_Extension *tw_dev, int message_credits,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  971)  			      u32 set_features, unsigned short current_fw_srl, 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  972) 			      unsigned short current_fw_arch_id, 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  973) 			      unsigned short current_fw_branch, 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  974) 			      unsigned short current_fw_build, 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  975) 			      unsigned short *fw_on_ctlr_srl, 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  976) 			      unsigned short *fw_on_ctlr_arch_id, 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  977) 			      unsigned short *fw_on_ctlr_branch, 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  978) 			      unsigned short *fw_on_ctlr_build, 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  979) 			      u32 *init_connect_result)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  980) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  981) 	TW_Command_Full *full_command_packet;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  982) 	TW_Initconnect *tw_initconnect;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  983) 	int request_id = 0, retval = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  984) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  985) 	/* Initialize InitConnection command packet */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  986) 	full_command_packet = tw_dev->command_packet_virt[request_id];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  987) 	memset(full_command_packet, 0, sizeof(TW_Command_Full));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  988) 	full_command_packet->header.header_desc.size_header = 128;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  989) 	
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  990) 	tw_initconnect = (TW_Initconnect *)&full_command_packet->command.oldcommand;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  991) 	tw_initconnect->opcode__reserved = TW_OPRES_IN(0, TW_OP_INIT_CONNECTION);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  992) 	tw_initconnect->request_id = request_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  993) 	tw_initconnect->message_credits = cpu_to_le16(message_credits);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  994) 	tw_initconnect->features = set_features;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  995) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  996) 	/* Turn on 64-bit sgl support if we need to */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  997) 	tw_initconnect->features |= sizeof(dma_addr_t) > 4 ? 1 : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  998) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  999) 	tw_initconnect->features = cpu_to_le32(tw_initconnect->features);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) 	if (set_features & TW_EXTENDED_INIT_CONNECT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) 		tw_initconnect->size = TW_INIT_COMMAND_PACKET_SIZE_EXTENDED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) 		tw_initconnect->fw_srl = cpu_to_le16(current_fw_srl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) 		tw_initconnect->fw_arch_id = cpu_to_le16(current_fw_arch_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) 		tw_initconnect->fw_branch = cpu_to_le16(current_fw_branch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) 		tw_initconnect->fw_build = cpu_to_le16(current_fw_build);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) 	} else 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) 		tw_initconnect->size = TW_INIT_COMMAND_PACKET_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) 	/* Send command packet to the board */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) 	twl_post_command_packet(tw_dev, request_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) 	/* Poll for completion */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014) 	if (twl_poll_response(tw_dev, request_id, 30)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) 		TW_PRINTK(tw_dev->host, TW_DRIVER, 0x8, "No valid response during init connection");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) 		if (set_features & TW_EXTENDED_INIT_CONNECT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) 			*fw_on_ctlr_srl = le16_to_cpu(tw_initconnect->fw_srl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) 			*fw_on_ctlr_arch_id = le16_to_cpu(tw_initconnect->fw_arch_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) 			*fw_on_ctlr_branch = le16_to_cpu(tw_initconnect->fw_branch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) 			*fw_on_ctlr_build = le16_to_cpu(tw_initconnect->fw_build);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) 			*init_connect_result = le32_to_cpu(tw_initconnect->result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) 		retval = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) 	tw_dev->posted_request_count--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028) 	tw_dev->state[request_id] = TW_S_INITIAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) 	return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) } /* End twl_initconnection() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) /* This function will initialize the fields of a device extension */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) static int twl_initialize_device_extension(TW_Device_Extension *tw_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) 	int i, retval = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038) 	/* Initialize command packet buffers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) 	if (twl_allocate_memory(tw_dev, sizeof(TW_Command_Full), 0)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040) 		TW_PRINTK(tw_dev->host, TW_DRIVER, 0x9, "Command packet memory allocation failed");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) 	/* Initialize generic buffer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) 	if (twl_allocate_memory(tw_dev, TW_SECTOR_SIZE, 1)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) 		TW_PRINTK(tw_dev->host, TW_DRIVER, 0xa, "Generic memory allocation failed");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050) 	/* Allocate sense buffers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) 	if (twl_allocate_memory(tw_dev, sizeof(TW_Command_Apache_Header), 2)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052) 		TW_PRINTK(tw_dev->host, TW_DRIVER, 0xb, "Sense buffer allocation failed");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056) 	/* Allocate event info space */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057) 	tw_dev->event_queue[0] = kcalloc(TW_Q_LENGTH, sizeof(TW_Event), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058) 	if (!tw_dev->event_queue[0]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059) 		TW_PRINTK(tw_dev->host, TW_DRIVER, 0xc, "Event info memory allocation failed");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063) 	for (i = 0; i < TW_Q_LENGTH; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) 		tw_dev->event_queue[i] = (TW_Event *)((unsigned char *)tw_dev->event_queue[0] + (i * sizeof(TW_Event)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065) 		tw_dev->free_queue[i] = i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) 		tw_dev->state[i] = TW_S_INITIAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) 	tw_dev->free_head = TW_Q_START;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070) 	tw_dev->free_tail = TW_Q_START;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071) 	tw_dev->error_sequence_id = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072) 	tw_dev->chrdev_request_id = TW_IOCTL_CHRDEV_FREE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074) 	mutex_init(&tw_dev->ioctl_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075) 	init_waitqueue_head(&tw_dev->ioctl_wqueue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077) 	retval = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079) 	return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080) } /* End twl_initialize_device_extension() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082) /* This function will handle attention interrupts */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083) static int twl_handle_attention_interrupt(TW_Device_Extension *tw_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085) 	int retval = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086) 	u32 request_id, doorbell;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088) 	/* Read doorbell status */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089) 	doorbell = readl(TWL_HOBDB_REG_ADDR(tw_dev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091) 	/* Check for controller errors */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092) 	if (doorbell & TWL_DOORBELL_CONTROLLER_ERROR) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093) 		TW_PRINTK(tw_dev->host, TW_DRIVER, 0xd, "Microcontroller Error: clearing");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097) 	/* Check if we need to perform an AEN drain */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098) 	if (doorbell & TWL_DOORBELL_ATTENTION_INTERRUPT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099) 		if (!(test_and_set_bit(TW_IN_ATTENTION_LOOP, &tw_dev->flags))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100) 			twl_get_request_id(tw_dev, &request_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101) 			if (twl_aen_read_queue(tw_dev, request_id)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102) 				tw_dev->state[request_id] = TW_S_COMPLETED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103) 				twl_free_request_id(tw_dev, request_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104) 				clear_bit(TW_IN_ATTENTION_LOOP, &tw_dev->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109) 	retval = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111) 	/* Clear doorbell interrupt */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112) 	TWL_CLEAR_DB_INTERRUPT(tw_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114) 	/* Make sure the clear was flushed by reading it back */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115) 	readl(TWL_HOBDBC_REG_ADDR(tw_dev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117) 	return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118) } /* End twl_handle_attention_interrupt() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120) /* Interrupt service routine */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121) static irqreturn_t twl_interrupt(int irq, void *dev_instance)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123) 	TW_Device_Extension *tw_dev = (TW_Device_Extension *)dev_instance;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124) 	int i, handled = 0, error = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125) 	dma_addr_t mfa = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126) 	u32 reg, regl, regh, response, request_id = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127) 	struct scsi_cmnd *cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128) 	TW_Command_Full *full_command_packet;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130) 	spin_lock(tw_dev->host->host_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132) 	/* Read host interrupt status */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133) 	reg = readl(TWL_HISTAT_REG_ADDR(tw_dev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135) 	/* Check if this is our interrupt, otherwise bail */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136) 	if (!(reg & TWL_HISTATUS_VALID_INTERRUPT))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137) 		goto twl_interrupt_bail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139) 	handled = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141) 	/* If we are resetting, bail */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142) 	if (test_bit(TW_IN_RESET, &tw_dev->flags))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143) 		goto twl_interrupt_bail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145) 	/* Attention interrupt */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146) 	if (reg & TWL_HISTATUS_ATTENTION_INTERRUPT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147) 		if (twl_handle_attention_interrupt(tw_dev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148) 			TWL_MASK_INTERRUPTS(tw_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149) 			goto twl_interrupt_bail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153) 	/* Response interrupt */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154) 	while (reg & TWL_HISTATUS_RESPONSE_INTERRUPT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155) 		if (sizeof(dma_addr_t) > 4) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156) 			regh = readl(TWL_HOBQPH_REG_ADDR(tw_dev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157) 			regl = readl(TWL_HOBQPL_REG_ADDR(tw_dev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1158) 			mfa = ((u64)regh << 32) | regl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1159) 		} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1160) 			mfa = readl(TWL_HOBQPL_REG_ADDR(tw_dev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1161) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1162) 		error = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1163) 		response = (u32)mfa;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1164) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1165) 		/* Check for command packet error */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1166) 		if (!TW_NOTMFA_OUT(response)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1167) 			for (i=0;i<TW_Q_LENGTH;i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1168) 				if (tw_dev->sense_buffer_phys[i] == mfa) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1169) 					request_id = le16_to_cpu(tw_dev->sense_buffer_virt[i]->header_desc.request_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1170) 					if (tw_dev->srb[request_id] != NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1171) 						error = twl_fill_sense(tw_dev, i, request_id, 1, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1172) 					else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1173) 						/* Skip ioctl error prints */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1174) 						if (request_id != tw_dev->chrdev_request_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1175) 							error = twl_fill_sense(tw_dev, i, request_id, 0, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1176) 						else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1177) 							memcpy(tw_dev->command_packet_virt[request_id], tw_dev->sense_buffer_virt[i], sizeof(TW_Command_Apache_Header));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1178) 					}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1179) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1180) 					/* Now re-post the sense buffer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1181) 					writel((u32)((u64)tw_dev->sense_buffer_phys[i] >> 32), TWL_HOBQPH_REG_ADDR(tw_dev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1182) 					writel((u32)tw_dev->sense_buffer_phys[i], TWL_HOBQPL_REG_ADDR(tw_dev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1183) 					break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1184) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1185) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1186) 		} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1187) 			request_id = TW_RESID_OUT(response);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1188) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1189) 		full_command_packet = tw_dev->command_packet_virt[request_id];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1190) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1191) 		/* Check for correct state */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1192) 		if (tw_dev->state[request_id] != TW_S_POSTED) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1193) 			if (tw_dev->srb[request_id] != NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1194) 				TW_PRINTK(tw_dev->host, TW_DRIVER, 0xe, "Received a request id that wasn't posted");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1195) 				TWL_MASK_INTERRUPTS(tw_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1196) 				goto twl_interrupt_bail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1197) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1198) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1199) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1200) 		/* Check for internal command completion */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1201) 		if (tw_dev->srb[request_id] == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1202) 			if (request_id != tw_dev->chrdev_request_id) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1203) 				if (twl_aen_complete(tw_dev, request_id))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1204) 					TW_PRINTK(tw_dev->host, TW_DRIVER, 0xf, "Error completing AEN during attention interrupt");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1205) 			} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1206) 				tw_dev->chrdev_request_id = TW_IOCTL_CHRDEV_FREE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1207) 				wake_up(&tw_dev->ioctl_wqueue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1208) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1209) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1210) 			cmd = tw_dev->srb[request_id];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1211) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1212) 			if (!error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1213) 				cmd->result = (DID_OK << 16);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1214) 			
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1215) 			/* Report residual bytes for single sgl */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1216) 			if ((scsi_sg_count(cmd) <= 1) && (full_command_packet->command.newcommand.status == 0)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1217) 				if (full_command_packet->command.newcommand.sg_list[0].length < scsi_bufflen(tw_dev->srb[request_id]))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1218) 					scsi_set_resid(cmd, scsi_bufflen(cmd) - full_command_packet->command.newcommand.sg_list[0].length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1219) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1220) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1221) 			/* Now complete the io */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1222) 			scsi_dma_unmap(cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1223) 			cmd->scsi_done(cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1224) 			tw_dev->state[request_id] = TW_S_COMPLETED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1225) 			twl_free_request_id(tw_dev, request_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1226) 			tw_dev->posted_request_count--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1227) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1228) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1229) 		/* Check for another response interrupt */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1230) 		reg = readl(TWL_HISTAT_REG_ADDR(tw_dev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1231) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1232) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1233) twl_interrupt_bail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1234) 	spin_unlock(tw_dev->host->host_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1235) 	return IRQ_RETVAL(handled);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1236) } /* End twl_interrupt() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1237) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1238) /* This function will poll for a register change */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1239) static int twl_poll_register(TW_Device_Extension *tw_dev, void *reg, u32 value, u32 result, int seconds)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1240) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1241) 	unsigned long before;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1242) 	int retval = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1243) 	u32 reg_value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1244) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1245) 	reg_value = readl(reg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1246) 	before = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1247) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1248)         while ((reg_value & value) != result) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1249) 		reg_value = readl(reg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1250) 		if (time_after(jiffies, before + HZ * seconds))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1251) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1252) 		msleep(50);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1253) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1254) 	retval = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1255) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1256) 	return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1257) } /* End twl_poll_register() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1258) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1259) /* This function will reset a controller */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1260) static int twl_reset_sequence(TW_Device_Extension *tw_dev, int soft_reset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1261) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1262) 	int retval = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1263) 	int i = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1264) 	u32 status = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1265) 	unsigned short fw_on_ctlr_srl = 0, fw_on_ctlr_arch_id = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1266) 	unsigned short fw_on_ctlr_branch = 0, fw_on_ctlr_build = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1267) 	u32 init_connect_result = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1268) 	int tries = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1269) 	int do_soft_reset = soft_reset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1270) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1271) 	while (tries < TW_MAX_RESET_TRIES) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1272) 		/* Do a soft reset if one is needed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1273) 		if (do_soft_reset) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1274) 			TWL_SOFT_RESET(tw_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1275) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1276) 			/* Make sure controller is in a good state */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1277) 			if (twl_poll_register(tw_dev, TWL_SCRPD3_REG_ADDR(tw_dev), TWL_CONTROLLER_READY, 0x0, 30)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1278) 				TW_PRINTK(tw_dev->host, TW_DRIVER, 0x10, "Controller never went non-ready during reset sequence");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1279) 				tries++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1280) 				continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1281) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1282) 			if (twl_poll_register(tw_dev, TWL_SCRPD3_REG_ADDR(tw_dev), TWL_CONTROLLER_READY, TWL_CONTROLLER_READY, 60)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1283) 				TW_PRINTK(tw_dev->host, TW_DRIVER, 0x11, "Controller not ready during reset sequence");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1284) 				tries++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1285) 				continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1286) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1287) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1288) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1289) 		/* Initconnect */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1290) 		if (twl_initconnection(tw_dev, TW_INIT_MESSAGE_CREDITS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1291) 				       TW_EXTENDED_INIT_CONNECT, TW_CURRENT_DRIVER_SRL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1292) 				       TW_9750_ARCH_ID, TW_CURRENT_DRIVER_BRANCH,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1293) 				       TW_CURRENT_DRIVER_BUILD, &fw_on_ctlr_srl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1294) 				       &fw_on_ctlr_arch_id, &fw_on_ctlr_branch,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1295) 				       &fw_on_ctlr_build, &init_connect_result)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1296) 			TW_PRINTK(tw_dev->host, TW_DRIVER, 0x12, "Initconnection failed while checking SRL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1297) 			do_soft_reset = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1298) 			tries++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1299) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1300) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1301) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1302) 		/* Load sense buffers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1303) 		while (i < TW_Q_LENGTH) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1304) 			writel((u32)((u64)tw_dev->sense_buffer_phys[i] >> 32), TWL_HOBQPH_REG_ADDR(tw_dev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1305) 			writel((u32)tw_dev->sense_buffer_phys[i], TWL_HOBQPL_REG_ADDR(tw_dev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1306) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1307) 			/* Check status for over-run after each write */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1308) 			status = readl(TWL_STATUS_REG_ADDR(tw_dev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1309) 			if (!(status & TWL_STATUS_OVERRUN_SUBMIT))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1310) 			    i++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1311) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1312) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1313) 		/* Now check status */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1314) 		status = readl(TWL_STATUS_REG_ADDR(tw_dev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1315) 		if (status) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1316) 			TW_PRINTK(tw_dev->host, TW_DRIVER, 0x13, "Bad controller status after loading sense buffers");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1317) 			do_soft_reset = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1318) 			tries++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1319) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1320) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1321) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1322) 		/* Drain the AEN queue */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1323) 		if (twl_aen_drain_queue(tw_dev, soft_reset)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1324) 			TW_PRINTK(tw_dev->host, TW_DRIVER, 0x14, "AEN drain failed during reset sequence");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1325) 			do_soft_reset = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1326) 			tries++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1327) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1328) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1329) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1330) 		/* Load rest of compatibility struct */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1331) 		strncpy(tw_dev->tw_compat_info.driver_version, TW_DRIVER_VERSION, strlen(TW_DRIVER_VERSION));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1332) 		tw_dev->tw_compat_info.driver_srl_high = TW_CURRENT_DRIVER_SRL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1333) 		tw_dev->tw_compat_info.driver_branch_high = TW_CURRENT_DRIVER_BRANCH;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1334) 		tw_dev->tw_compat_info.driver_build_high = TW_CURRENT_DRIVER_BUILD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1335) 		tw_dev->tw_compat_info.driver_srl_low = TW_BASE_FW_SRL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1336) 		tw_dev->tw_compat_info.driver_branch_low = TW_BASE_FW_BRANCH;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1337) 		tw_dev->tw_compat_info.driver_build_low = TW_BASE_FW_BUILD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1338) 		tw_dev->tw_compat_info.fw_on_ctlr_srl = fw_on_ctlr_srl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1339) 		tw_dev->tw_compat_info.fw_on_ctlr_branch = fw_on_ctlr_branch;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1340) 		tw_dev->tw_compat_info.fw_on_ctlr_build = fw_on_ctlr_build;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1341) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1342) 		/* If we got here, controller is in a good state */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1343) 		retval = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1344) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1345) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1346) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1347) 	return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1348) } /* End twl_reset_sequence() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1349) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1350) /* This function will reset a device extension */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1351) static int twl_reset_device_extension(TW_Device_Extension *tw_dev, int ioctl_reset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1352) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1353) 	int i = 0, retval = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1354) 	unsigned long flags = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1355) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1356) 	/* Block SCSI requests while we are resetting */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1357) 	if (ioctl_reset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1358) 		scsi_block_requests(tw_dev->host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1359) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1360) 	set_bit(TW_IN_RESET, &tw_dev->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1361) 	TWL_MASK_INTERRUPTS(tw_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1362) 	TWL_CLEAR_DB_INTERRUPT(tw_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1363) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1364) 	spin_lock_irqsave(tw_dev->host->host_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1365) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1366) 	/* Abort all requests that are in progress */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1367) 	for (i = 0; i < TW_Q_LENGTH; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1368) 		if ((tw_dev->state[i] != TW_S_FINISHED) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1369) 		    (tw_dev->state[i] != TW_S_INITIAL) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1370) 		    (tw_dev->state[i] != TW_S_COMPLETED)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1371) 			struct scsi_cmnd *cmd = tw_dev->srb[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1372) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1373) 			if (cmd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1374) 				cmd->result = (DID_RESET << 16);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1375) 				scsi_dma_unmap(cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1376) 				cmd->scsi_done(cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1377) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1378) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1379) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1380) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1381) 	/* Reset queues and counts */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1382) 	for (i = 0; i < TW_Q_LENGTH; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1383) 		tw_dev->free_queue[i] = i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1384) 		tw_dev->state[i] = TW_S_INITIAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1385) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1386) 	tw_dev->free_head = TW_Q_START;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1387) 	tw_dev->free_tail = TW_Q_START;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1388) 	tw_dev->posted_request_count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1389) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1390) 	spin_unlock_irqrestore(tw_dev->host->host_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1391) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1392) 	if (twl_reset_sequence(tw_dev, 1))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1393) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1394) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1395) 	TWL_UNMASK_INTERRUPTS(tw_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1396) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1397) 	clear_bit(TW_IN_RESET, &tw_dev->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1398) 	tw_dev->chrdev_request_id = TW_IOCTL_CHRDEV_FREE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1399) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1400) 	retval = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1401) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1402) 	if (ioctl_reset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1403) 		scsi_unblock_requests(tw_dev->host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1404) 	return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1405) } /* End twl_reset_device_extension() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1406) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1407) /* This funciton returns unit geometry in cylinders/heads/sectors */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1408) static int twl_scsi_biosparam(struct scsi_device *sdev, struct block_device *bdev, sector_t capacity, int geom[])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1409) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1410) 	int heads, sectors;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1411) 	TW_Device_Extension *tw_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1412) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1413) 	tw_dev = (TW_Device_Extension *)sdev->host->hostdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1414) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1415) 	if (capacity >= 0x200000) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1416) 		heads = 255;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1417) 		sectors = 63;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1418) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1419) 		heads = 64;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1420) 		sectors = 32;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1421) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1422) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1423) 	geom[0] = heads;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1424) 	geom[1] = sectors;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1425) 	geom[2] = sector_div(capacity, heads * sectors); /* cylinders */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1426) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1427) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1428) } /* End twl_scsi_biosparam() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1429) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1430) /* This is the new scsi eh reset function */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1431) static int twl_scsi_eh_reset(struct scsi_cmnd *SCpnt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1432) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1433) 	TW_Device_Extension *tw_dev = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1434) 	int retval = FAILED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1435) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1436) 	tw_dev = (TW_Device_Extension *)SCpnt->device->host->hostdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1437) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1438) 	tw_dev->num_resets++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1439) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1440) 	sdev_printk(KERN_WARNING, SCpnt->device,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1441) 		"WARNING: (0x%02X:0x%04X): Command (0x%x) timed out, resetting card.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1442) 		TW_DRIVER, 0x2c, SCpnt->cmnd[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1443) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1444) 	/* Make sure we are not issuing an ioctl or resetting from ioctl */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1445) 	mutex_lock(&tw_dev->ioctl_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1446) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1447) 	/* Now reset the card and some of the device extension data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1448) 	if (twl_reset_device_extension(tw_dev, 0)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1449) 		TW_PRINTK(tw_dev->host, TW_DRIVER, 0x15, "Controller reset failed during scsi host reset");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1450) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1451) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1452) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1453) 	retval = SUCCESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1454) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1455) 	mutex_unlock(&tw_dev->ioctl_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1456) 	return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1457) } /* End twl_scsi_eh_reset() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1458) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1459) /* This is the main scsi queue function to handle scsi opcodes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1460) static int twl_scsi_queue_lck(struct scsi_cmnd *SCpnt, void (*done)(struct scsi_cmnd *))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1461) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1462) 	int request_id, retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1463) 	TW_Device_Extension *tw_dev = (TW_Device_Extension *)SCpnt->device->host->hostdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1464) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1465) 	/* If we are resetting due to timed out ioctl, report as busy */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1466) 	if (test_bit(TW_IN_RESET, &tw_dev->flags)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1467) 		retval = SCSI_MLQUEUE_HOST_BUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1468) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1469) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1470) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1471) 	/* Save done function into scsi_cmnd struct */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1472) 	SCpnt->scsi_done = done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1473) 		
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1474) 	/* Get a free request id */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1475) 	twl_get_request_id(tw_dev, &request_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1476) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1477) 	/* Save the scsi command for use by the ISR */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1478) 	tw_dev->srb[request_id] = SCpnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1479) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1480) 	retval = twl_scsiop_execute_scsi(tw_dev, request_id, NULL, 0, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1481) 	if (retval) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1482) 		tw_dev->state[request_id] = TW_S_COMPLETED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1483) 		twl_free_request_id(tw_dev, request_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1484) 		SCpnt->result = (DID_ERROR << 16);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1485) 		done(SCpnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1486) 		retval = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1487) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1488) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1489) 	return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1490) } /* End twl_scsi_queue() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1491) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1492) static DEF_SCSI_QCMD(twl_scsi_queue)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1493) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1494) /* This function tells the controller to shut down */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1495) static void __twl_shutdown(TW_Device_Extension *tw_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1496) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1497) 	/* Disable interrupts */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1498) 	TWL_MASK_INTERRUPTS(tw_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1499) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1500) 	/* Free up the IRQ */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1501) 	free_irq(tw_dev->tw_pci_dev->irq, tw_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1502) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1503) 	printk(KERN_WARNING "3w-sas: Shutting down host %d.\n", tw_dev->host->host_no);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1504) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1505) 	/* Tell the card we are shutting down */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1506) 	if (twl_initconnection(tw_dev, 1, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1507) 		TW_PRINTK(tw_dev->host, TW_DRIVER, 0x16, "Connection shutdown failed");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1508) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1509) 		printk(KERN_WARNING "3w-sas: Shutdown complete.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1510) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1511) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1512) 	/* Clear doorbell interrupt just before exit */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1513) 	TWL_CLEAR_DB_INTERRUPT(tw_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1514) } /* End __twl_shutdown() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1515) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1516) /* Wrapper for __twl_shutdown */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1517) static void twl_shutdown(struct pci_dev *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1518) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1519) 	struct Scsi_Host *host = pci_get_drvdata(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1520) 	TW_Device_Extension *tw_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1521) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1522) 	if (!host)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1523) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1524) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1525) 	tw_dev = (TW_Device_Extension *)host->hostdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1526) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1527) 	if (tw_dev->online) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1528) 		__twl_shutdown(tw_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1529) } /* End twl_shutdown() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1530) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1531) /* This function configures unit settings when a unit is coming on-line */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1532) static int twl_slave_configure(struct scsi_device *sdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1533) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1534) 	/* Force 60 second timeout */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1535) 	blk_queue_rq_timeout(sdev->request_queue, 60 * HZ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1536) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1537) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1538) } /* End twl_slave_configure() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1539) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1540) /* scsi_host_template initializer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1541) static struct scsi_host_template driver_template = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1542) 	.module			= THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1543) 	.name			= "3w-sas",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1544) 	.queuecommand		= twl_scsi_queue,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1545) 	.eh_host_reset_handler	= twl_scsi_eh_reset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1546) 	.bios_param		= twl_scsi_biosparam,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1547) 	.change_queue_depth	= scsi_change_queue_depth,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1548) 	.can_queue		= TW_Q_LENGTH-2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1549) 	.slave_configure	= twl_slave_configure,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1550) 	.this_id		= -1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1551) 	.sg_tablesize		= TW_LIBERATOR_MAX_SGL_LENGTH,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1552) 	.max_sectors		= TW_MAX_SECTORS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1553) 	.cmd_per_lun		= TW_MAX_CMDS_PER_LUN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1554) 	.shost_attrs		= twl_host_attrs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1555) 	.emulated		= 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1556) 	.no_write_same		= 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1557) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1558) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1559) /* This function will probe and initialize a card */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1560) static int twl_probe(struct pci_dev *pdev, const struct pci_device_id *dev_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1561) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1562) 	struct Scsi_Host *host = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1563) 	TW_Device_Extension *tw_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1564) 	int retval = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1565) 	int *ptr_phycount, phycount=0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1566) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1567) 	retval = pci_enable_device(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1568) 	if (retval) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1569) 		TW_PRINTK(host, TW_DRIVER, 0x17, "Failed to enable pci device");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1570) 		goto out_disable_device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1571) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1572) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1573) 	pci_set_master(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1574) 	pci_try_set_mwi(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1575) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1576) 	retval = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1577) 	if (retval)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1578) 		retval = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1579) 	if (retval) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1580) 		TW_PRINTK(host, TW_DRIVER, 0x18, "Failed to set dma mask");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1581) 		retval = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1582) 		goto out_disable_device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1583) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1584) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1585) 	host = scsi_host_alloc(&driver_template, sizeof(TW_Device_Extension));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1586) 	if (!host) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1587) 		TW_PRINTK(host, TW_DRIVER, 0x19, "Failed to allocate memory for device extension");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1588) 		retval = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1589) 		goto out_disable_device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1590) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1591) 	tw_dev = shost_priv(host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1592) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1593) 	/* Save values to device extension */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1594) 	tw_dev->host = host;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1595) 	tw_dev->tw_pci_dev = pdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1596) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1597) 	if (twl_initialize_device_extension(tw_dev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1598) 		TW_PRINTK(tw_dev->host, TW_DRIVER, 0x1a, "Failed to initialize device extension");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1599) 		retval = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1600) 		goto out_free_device_extension;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1601) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1602) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1603) 	/* Request IO regions */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1604) 	retval = pci_request_regions(pdev, "3w-sas");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1605) 	if (retval) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1606) 		TW_PRINTK(tw_dev->host, TW_DRIVER, 0x1b, "Failed to get mem region");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1607) 		goto out_free_device_extension;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1608) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1609) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1610) 	/* Save base address, use region 1 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1611) 	tw_dev->base_addr = pci_iomap(pdev, 1, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1612) 	if (!tw_dev->base_addr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1613) 		TW_PRINTK(tw_dev->host, TW_DRIVER, 0x1c, "Failed to ioremap");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1614) 		retval = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1615) 		goto out_release_mem_region;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1616) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1617) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1618) 	/* Disable interrupts on the card */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1619) 	TWL_MASK_INTERRUPTS(tw_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1620) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1621) 	/* Initialize the card */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1622) 	if (twl_reset_sequence(tw_dev, 0)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1623) 		TW_PRINTK(tw_dev->host, TW_DRIVER, 0x1d, "Controller reset failed during probe");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1624) 		retval = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1625) 		goto out_iounmap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1626) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1627) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1628) 	/* Set host specific parameters */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1629) 	host->max_id = TW_MAX_UNITS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1630) 	host->max_cmd_len = TW_MAX_CDB_LEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1631) 	host->max_lun = TW_MAX_LUNS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1632) 	host->max_channel = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1633) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1634) 	/* Register the card with the kernel SCSI layer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1635) 	retval = scsi_add_host(host, &pdev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1636) 	if (retval) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1637) 		TW_PRINTK(tw_dev->host, TW_DRIVER, 0x1e, "scsi add host failed");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1638) 		goto out_iounmap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1639) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1640) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1641) 	pci_set_drvdata(pdev, host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1642) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1643) 	printk(KERN_WARNING "3w-sas: scsi%d: Found an LSI 3ware %s Controller at 0x%llx, IRQ: %d.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1644) 	       host->host_no,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1645) 	       (char *)twl_get_param(tw_dev, 1, TW_VERSION_TABLE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1646) 				     TW_PARAM_MODEL, TW_PARAM_MODEL_LENGTH),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1647) 	       (u64)pci_resource_start(pdev, 1), pdev->irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1648) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1649) 	ptr_phycount = twl_get_param(tw_dev, 2, TW_PARAM_PHY_SUMMARY_TABLE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1650) 				     TW_PARAM_PHYCOUNT, TW_PARAM_PHYCOUNT_LENGTH);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1651) 	if (ptr_phycount)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1652) 		phycount = le32_to_cpu(*(int *)ptr_phycount);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1653) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1654) 	printk(KERN_WARNING "3w-sas: scsi%d: Firmware %s, BIOS %s, Phys: %d.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1655) 	       host->host_no,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1656) 	       (char *)twl_get_param(tw_dev, 1, TW_VERSION_TABLE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1657) 				     TW_PARAM_FWVER, TW_PARAM_FWVER_LENGTH),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1658) 	       (char *)twl_get_param(tw_dev, 2, TW_VERSION_TABLE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1659) 				     TW_PARAM_BIOSVER, TW_PARAM_BIOSVER_LENGTH),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1660) 	       phycount);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1661) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1662) 	/* Try to enable MSI */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1663) 	if (use_msi && !pci_enable_msi(pdev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1664) 		set_bit(TW_USING_MSI, &tw_dev->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1665) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1666) 	/* Now setup the interrupt handler */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1667) 	retval = request_irq(pdev->irq, twl_interrupt, IRQF_SHARED, "3w-sas", tw_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1668) 	if (retval) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1669) 		TW_PRINTK(tw_dev->host, TW_DRIVER, 0x1f, "Error requesting IRQ");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1670) 		goto out_remove_host;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1671) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1672) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1673) 	twl_device_extension_list[twl_device_extension_count] = tw_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1674) 	twl_device_extension_count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1675) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1676) 	/* Re-enable interrupts on the card */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1677) 	TWL_UNMASK_INTERRUPTS(tw_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1678) 	
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1679) 	/* Finally, scan the host */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1680) 	scsi_scan_host(host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1681) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1682) 	/* Add sysfs binary files */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1683) 	if (sysfs_create_bin_file(&host->shost_dev.kobj, &twl_sysfs_aen_read_attr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1684) 		TW_PRINTK(tw_dev->host, TW_DRIVER, 0x20, "Failed to create sysfs binary file: 3ware_aen_read");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1685) 	if (sysfs_create_bin_file(&host->shost_dev.kobj, &twl_sysfs_compat_info_attr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1686) 		TW_PRINTK(tw_dev->host, TW_DRIVER, 0x21, "Failed to create sysfs binary file: 3ware_compat_info");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1687) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1688) 	if (twl_major == -1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1689) 		if ((twl_major = register_chrdev (0, "twl", &twl_fops)) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1690) 			TW_PRINTK(host, TW_DRIVER, 0x22, "Failed to register character device");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1691) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1692) 	tw_dev->online = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1693) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1694) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1695) out_remove_host:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1696) 	if (test_bit(TW_USING_MSI, &tw_dev->flags))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1697) 		pci_disable_msi(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1698) 	scsi_remove_host(host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1699) out_iounmap:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1700) 	iounmap(tw_dev->base_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1701) out_release_mem_region:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1702) 	pci_release_regions(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1703) out_free_device_extension:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1704) 	twl_free_device_extension(tw_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1705) 	scsi_host_put(host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1706) out_disable_device:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1707) 	pci_disable_device(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1708) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1709) 	return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1710) } /* End twl_probe() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1711) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1712) /* This function is called to remove a device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1713) static void twl_remove(struct pci_dev *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1714) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1715) 	struct Scsi_Host *host = pci_get_drvdata(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1716) 	TW_Device_Extension *tw_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1717) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1718) 	if (!host)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1719) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1720) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1721) 	tw_dev = (TW_Device_Extension *)host->hostdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1722) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1723) 	if (!tw_dev->online)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1724) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1725) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1726) 	/* Remove sysfs binary files */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1727) 	sysfs_remove_bin_file(&host->shost_dev.kobj, &twl_sysfs_aen_read_attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1728) 	sysfs_remove_bin_file(&host->shost_dev.kobj, &twl_sysfs_compat_info_attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1729) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1730) 	scsi_remove_host(tw_dev->host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1731) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1732) 	/* Unregister character device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1733) 	if (twl_major >= 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1734) 		unregister_chrdev(twl_major, "twl");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1735) 		twl_major = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1736) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1737) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1738) 	/* Shutdown the card */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1739) 	__twl_shutdown(tw_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1740) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1741) 	/* Disable MSI if enabled */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1742) 	if (test_bit(TW_USING_MSI, &tw_dev->flags))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1743) 		pci_disable_msi(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1744) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1745) 	/* Free IO remapping */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1746) 	iounmap(tw_dev->base_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1747) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1748) 	/* Free up the mem region */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1749) 	pci_release_regions(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1750) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1751) 	/* Free up device extension resources */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1752) 	twl_free_device_extension(tw_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1753) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1754) 	scsi_host_put(tw_dev->host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1755) 	pci_disable_device(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1756) 	twl_device_extension_count--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1757) } /* End twl_remove() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1758) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1759) #ifdef CONFIG_PM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1760) /* This function is called on PCI suspend */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1761) static int twl_suspend(struct pci_dev *pdev, pm_message_t state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1762) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1763) 	struct Scsi_Host *host = pci_get_drvdata(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1764) 	TW_Device_Extension *tw_dev = (TW_Device_Extension *)host->hostdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1765) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1766) 	printk(KERN_WARNING "3w-sas: Suspending host %d.\n", tw_dev->host->host_no);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1767) 	/* Disable interrupts */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1768) 	TWL_MASK_INTERRUPTS(tw_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1769) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1770) 	free_irq(tw_dev->tw_pci_dev->irq, tw_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1771) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1772) 	/* Tell the card we are shutting down */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1773) 	if (twl_initconnection(tw_dev, 1, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1774) 		TW_PRINTK(tw_dev->host, TW_DRIVER, 0x23, "Connection shutdown failed during suspend");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1775) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1776) 		printk(KERN_WARNING "3w-sas: Suspend complete.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1777) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1778) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1779) 	/* Clear doorbell interrupt */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1780) 	TWL_CLEAR_DB_INTERRUPT(tw_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1781) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1782) 	pci_save_state(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1783) 	pci_disable_device(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1784) 	pci_set_power_state(pdev, pci_choose_state(pdev, state));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1785) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1786) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1787) } /* End twl_suspend() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1788) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1789) /* This function is called on PCI resume */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1790) static int twl_resume(struct pci_dev *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1791) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1792) 	int retval = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1793) 	struct Scsi_Host *host = pci_get_drvdata(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1794) 	TW_Device_Extension *tw_dev = (TW_Device_Extension *)host->hostdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1795) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1796) 	printk(KERN_WARNING "3w-sas: Resuming host %d.\n", tw_dev->host->host_no);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1797) 	pci_set_power_state(pdev, PCI_D0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1798) 	pci_enable_wake(pdev, PCI_D0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1799) 	pci_restore_state(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1800) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1801) 	retval = pci_enable_device(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1802) 	if (retval) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1803) 		TW_PRINTK(tw_dev->host, TW_DRIVER, 0x24, "Enable device failed during resume");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1804) 		return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1805) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1806) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1807) 	pci_set_master(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1808) 	pci_try_set_mwi(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1809) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1810) 	retval = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1811) 	if (retval)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1812) 		retval = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1813) 	if (retval) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1814) 		TW_PRINTK(host, TW_DRIVER, 0x25, "Failed to set dma mask during resume");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1815) 		retval = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1816) 		goto out_disable_device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1817) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1818) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1819) 	/* Initialize the card */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1820) 	if (twl_reset_sequence(tw_dev, 0)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1821) 		retval = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1822) 		goto out_disable_device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1823) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1824) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1825) 	/* Now setup the interrupt handler */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1826) 	retval = request_irq(pdev->irq, twl_interrupt, IRQF_SHARED, "3w-sas", tw_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1827) 	if (retval) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1828) 		TW_PRINTK(tw_dev->host, TW_DRIVER, 0x26, "Error requesting IRQ during resume");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1829) 		retval = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1830) 		goto out_disable_device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1831) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1832) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1833) 	/* Now enable MSI if enabled */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1834) 	if (test_bit(TW_USING_MSI, &tw_dev->flags))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1835) 		pci_enable_msi(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1836) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1837) 	/* Re-enable interrupts on the card */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1838) 	TWL_UNMASK_INTERRUPTS(tw_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1839) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1840) 	printk(KERN_WARNING "3w-sas: Resume complete.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1841) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1842) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1843) out_disable_device:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1844) 	scsi_remove_host(host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1845) 	pci_disable_device(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1846) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1847) 	return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1848) } /* End twl_resume() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1849) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1850) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1851) /* PCI Devices supported by this driver */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1852) static struct pci_device_id twl_pci_tbl[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1853) 	{ PCI_VDEVICE(3WARE, PCI_DEVICE_ID_3WARE_9750) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1854) 	{ }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1855) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1856) MODULE_DEVICE_TABLE(pci, twl_pci_tbl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1857) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1858) /* pci_driver initializer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1859) static struct pci_driver twl_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1860) 	.name		= "3w-sas",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1861) 	.id_table	= twl_pci_tbl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1862) 	.probe		= twl_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1863) 	.remove		= twl_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1864) #ifdef CONFIG_PM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1865) 	.suspend	= twl_suspend,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1866) 	.resume		= twl_resume,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1867) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1868) 	.shutdown	= twl_shutdown
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1869) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1870) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1871) /* This function is called on driver initialization */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1872) static int __init twl_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1873) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1874) 	printk(KERN_INFO "LSI 3ware SAS/SATA-RAID Controller device driver for Linux v%s.\n", TW_DRIVER_VERSION);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1875) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1876) 	return pci_register_driver(&twl_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1877) } /* End twl_init() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1878) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1879) /* This function is called on driver exit */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1880) static void __exit twl_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1881) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1882) 	pci_unregister_driver(&twl_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1883) } /* End twl_exit() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1884) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1885) module_init(twl_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1886) module_exit(twl_exit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1887)