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)  * This file is provided under a dual BSD/GPLv2 license.  When using or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * redistributing this file, you may do so under either license.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * GPL LICENSE SUMMARY
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  * This program is free software; you can redistribute it and/or modify
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  * it under the terms of version 2 of the GNU General Public License as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)  * published by the Free Software Foundation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13)  * This program is distributed in the hope that it will be useful, but
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14)  * WITHOUT ANY WARRANTY; without even the implied warranty of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15)  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16)  * General Public License for more details.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18)  * You should have received a copy of the GNU General Public License
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19)  * along with this program; if not, write to the Free Software
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20)  * Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21)  * The full GNU General Public License is included in this distribution
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22)  * in the file called LICENSE.GPL.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24)  * BSD LICENSE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26)  * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27)  * All rights reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29)  * Redistribution and use in source and binary forms, with or without
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30)  * modification, are permitted provided that the following conditions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31)  * are met:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33)  *   * Redistributions of source code must retain the above copyright
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34)  *     notice, this list of conditions and the following disclaimer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35)  *   * Redistributions in binary form must reproduce the above copyright
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36)  *     notice, this list of conditions and the following disclaimer in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37)  *     the documentation and/or other materials provided with the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38)  *     distribution.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39)  *   * Neither the name of Intel Corporation nor the names of its
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40)  *     contributors may be used to endorse or promote products derived
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41)  *     from this software without specific prior written permission.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43)  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44)  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45)  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46)  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47)  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48)  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49)  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50)  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51)  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52)  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53)  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) #include <linux/completion.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) #include <linux/irqflags.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) #include "sas.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) #include <scsi/libsas.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) #include "remote_device.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) #include "remote_node_context.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) #include "isci.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) #include "request.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) #include "task.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) #include "host.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) * isci_task_refuse() - complete the request to the upper layer driver in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) *     the case where an I/O needs to be completed back in the submit path.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) * @ihost: host on which the the request was queued
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) * @task: request to complete
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) * @response: response code for the completed task.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) * @status: status code for the completed task.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) static void isci_task_refuse(struct isci_host *ihost, struct sas_task *task,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 			     enum service_response response,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 			     enum exec_status status)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	/* Normal notification (task_done) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	dev_dbg(&ihost->pdev->dev, "%s: task = %p, response=%d, status=%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 		__func__, task, response, status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	spin_lock_irqsave(&task->task_state_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	task->task_status.resp = response;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	task->task_status.stat = status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	/* Normal notification (task_done) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	task->task_state_flags |= SAS_TASK_STATE_DONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	task->task_state_flags &= ~(SAS_TASK_AT_INITIATOR |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 				    SAS_TASK_STATE_PENDING);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	task->lldd_task = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	spin_unlock_irqrestore(&task->task_state_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	task->task_done(task);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) #define for_each_sas_task(num, task) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	for (; num > 0; num--,\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	     task = list_entry(task->list.next, struct sas_task, list))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) static inline int isci_device_io_ready(struct isci_remote_device *idev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 				       struct sas_task *task)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	return idev ? test_bit(IDEV_IO_READY, &idev->flags) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 		      (test_bit(IDEV_IO_NCQERROR, &idev->flags) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 		       isci_task_is_ncq_recovery(task))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 		    : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116)  * isci_task_execute_task() - This function is one of the SAS Domain Template
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117)  *    functions. This function is called by libsas to send a task down to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118)  *    hardware.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119)  * @task: This parameter specifies the SAS task to send.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120)  * @gfp_flags: This parameter specifies the context of this call.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122)  * status, zero indicates success.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) int isci_task_execute_task(struct sas_task *task, gfp_t gfp_flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	struct isci_host *ihost = dev_to_ihost(task->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	struct isci_remote_device *idev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	enum sci_status status = SCI_FAILURE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	bool io_ready;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	u16 tag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	spin_lock_irqsave(&ihost->scic_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	idev = isci_lookup_device(task->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	io_ready = isci_device_io_ready(idev, task);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	tag = isci_alloc_tag(ihost);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	spin_unlock_irqrestore(&ihost->scic_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	dev_dbg(&ihost->pdev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 		"task: %p, dev: %p idev: %p:%#lx cmd = %p\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 		task, task->dev, idev, idev ? idev->flags : 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 		task->uldd_task);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	if (!idev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 		isci_task_refuse(ihost, task, SAS_TASK_UNDELIVERED,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 				 SAS_DEVICE_UNKNOWN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	} else if (!io_ready || tag == SCI_CONTROLLER_INVALID_IO_TAG) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 		/* Indicate QUEUE_FULL so that the scsi midlayer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 		 * retries.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 		  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 		isci_task_refuse(ihost, task, SAS_TASK_COMPLETE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 				 SAS_QUEUE_FULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 		/* There is a device and it's ready for I/O. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 		spin_lock_irqsave(&task->task_state_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 		if (task->task_state_flags & SAS_TASK_STATE_ABORTED) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 			/* The I/O was aborted. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 			spin_unlock_irqrestore(&task->task_state_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 			isci_task_refuse(ihost, task,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 					 SAS_TASK_UNDELIVERED,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 					 SAM_STAT_TASK_ABORTED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 			task->task_state_flags |= SAS_TASK_AT_INITIATOR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 			spin_unlock_irqrestore(&task->task_state_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 			/* build and send the request. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 			status = isci_request_execute(ihost, idev, task, tag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 			if (status != SCI_SUCCESS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 				spin_lock_irqsave(&task->task_state_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 				/* Did not really start this command. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 				task->task_state_flags &= ~SAS_TASK_AT_INITIATOR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 				spin_unlock_irqrestore(&task->task_state_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 				if (test_bit(IDEV_GONE, &idev->flags)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 					/* Indicate that the device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 					 * is gone.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 					 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 					isci_task_refuse(ihost, task,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 						SAS_TASK_UNDELIVERED,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 						SAS_DEVICE_UNKNOWN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 				} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 					/* Indicate QUEUE_FULL so that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 					 * the scsi midlayer retries.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 					 * If the request failed for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 					 * remote device reasons, it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 					 * gets returned as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 					 * SAS_TASK_UNDELIVERED next
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 					 * time through.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 					 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 					isci_task_refuse(ihost, task,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 						SAS_TASK_COMPLETE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 						SAS_QUEUE_FULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 			}
^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) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	if (status != SCI_SUCCESS && tag != SCI_CONTROLLER_INVALID_IO_TAG) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 		spin_lock_irqsave(&ihost->scic_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 		/* command never hit the device, so just free
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 		 * the tci and skip the sequence increment
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 		isci_tci_free(ihost, ISCI_TAG_TCI(tag));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 		spin_unlock_irqrestore(&ihost->scic_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 	isci_put_device(idev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) static struct isci_request *isci_task_request_build(struct isci_host *ihost,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 						    struct isci_remote_device *idev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 						    u16 tag, struct isci_tmf *isci_tmf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	enum sci_status status = SCI_FAILURE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 	struct isci_request *ireq = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	struct domain_device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	dev_dbg(&ihost->pdev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 		"%s: isci_tmf = %p\n", __func__, isci_tmf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	dev = idev->domain_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 	/* do common allocation and init of request object. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 	ireq = isci_tmf_request_from_tag(ihost, isci_tmf, tag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 	if (!ireq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 	/* let the core do it's construct. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 	status = sci_task_request_construct(ihost, idev, tag,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 					     ireq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 	if (status != SCI_SUCCESS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 		dev_warn(&ihost->pdev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 			 "%s: sci_task_request_construct failed - "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 			 "status = 0x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 			 __func__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 			 status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 	/* XXX convert to get this from task->tproto like other drivers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 	if (dev->dev_type == SAS_END_DEVICE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 		isci_tmf->proto = SAS_PROTOCOL_SSP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 		status = sci_task_request_construct_ssp(ireq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 		if (status != SCI_SUCCESS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 			return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 	return ireq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) static int isci_task_execute_tmf(struct isci_host *ihost,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 				 struct isci_remote_device *idev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 				 struct isci_tmf *tmf, unsigned long timeout_ms)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 	DECLARE_COMPLETION_ONSTACK(completion);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 	enum sci_status status = SCI_FAILURE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 	struct isci_request *ireq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 	int ret = TMF_RESP_FUNC_FAILED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 	unsigned long timeleft;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 	u16 tag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 	spin_lock_irqsave(&ihost->scic_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 	tag = isci_alloc_tag(ihost);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 	spin_unlock_irqrestore(&ihost->scic_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 	if (tag == SCI_CONTROLLER_INVALID_IO_TAG)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 	/* sanity check, return TMF_RESP_FUNC_FAILED
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 	 * if the device is not there and ready.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 	if (!idev ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 	    (!test_bit(IDEV_IO_READY, &idev->flags) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 	     !test_bit(IDEV_IO_NCQERROR, &idev->flags))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 		dev_dbg(&ihost->pdev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 			"%s: idev = %p not ready (%#lx)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 			__func__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 			idev, idev ? idev->flags : 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 		goto err_tci;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 	} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 		dev_dbg(&ihost->pdev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 			"%s: idev = %p\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 			__func__, idev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 	/* Assign the pointer to the TMF's completion kernel wait structure. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 	tmf->complete = &completion;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 	tmf->status = SCI_FAILURE_TIMEOUT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 	ireq = isci_task_request_build(ihost, idev, tag, tmf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 	if (!ireq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 		goto err_tci;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 	spin_lock_irqsave(&ihost->scic_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 	/* start the TMF io. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 	status = sci_controller_start_task(ihost, idev, ireq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 	if (status != SCI_SUCCESS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 		dev_dbg(&ihost->pdev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 			 "%s: start_io failed - status = 0x%x, request = %p\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 			 __func__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 			 status,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 			 ireq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 		spin_unlock_irqrestore(&ihost->scic_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 		goto err_tci;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 	spin_unlock_irqrestore(&ihost->scic_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 	/* The RNC must be unsuspended before the TMF can get a response. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 	isci_remote_device_resume_from_abort(ihost, idev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 	/* Wait for the TMF to complete, or a timeout. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 	timeleft = wait_for_completion_timeout(&completion,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 					       msecs_to_jiffies(timeout_ms));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 	if (timeleft == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 		/* The TMF did not complete - this could be because
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 		 * of an unplug.  Terminate the TMF request now.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 		isci_remote_device_suspend_terminate(ihost, idev, ireq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 	isci_print_tmf(ihost, tmf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 	if (tmf->status == SCI_SUCCESS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 		ret =  TMF_RESP_FUNC_COMPLETE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 	else if (tmf->status == SCI_FAILURE_IO_RESPONSE_VALID) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 		dev_dbg(&ihost->pdev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 			"%s: tmf.status == "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 			"SCI_FAILURE_IO_RESPONSE_VALID\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 			__func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 		ret =  TMF_RESP_FUNC_COMPLETE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 	/* Else - leave the default "failed" status alone. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 	dev_dbg(&ihost->pdev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 		"%s: completed request = %p\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 		__func__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 		ireq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349)  err_tci:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 	spin_lock_irqsave(&ihost->scic_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 	isci_tci_free(ihost, ISCI_TAG_TCI(tag));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 	spin_unlock_irqrestore(&ihost->scic_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 	return ret;
^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) static void isci_task_build_tmf(struct isci_tmf *tmf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 				enum isci_tmf_function_codes code)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 	memset(tmf, 0, sizeof(*tmf));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 	tmf->tmf_code = code;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) static void isci_task_build_abort_task_tmf(struct isci_tmf *tmf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 					   enum isci_tmf_function_codes code,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 					   struct isci_request *old_request)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 	isci_task_build_tmf(tmf, code);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 	tmf->io_tag = old_request->io_tag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373)  * isci_task_send_lu_reset_sas() - This function is called by of the SAS Domain
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374)  *    Template functions.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375)  * @lun: This parameter specifies the lun to be reset.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377)  * status, zero indicates success.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) static int isci_task_send_lu_reset_sas(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 	struct isci_host *isci_host,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 	struct isci_remote_device *isci_device,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 	u8 *lun)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 	struct isci_tmf tmf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 	int ret = TMF_RESP_FUNC_FAILED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 	dev_dbg(&isci_host->pdev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 		"%s: isci_host = %p, isci_device = %p\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 		__func__, isci_host, isci_device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 	/* Send the LUN reset to the target.  By the time the call returns,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 	 * the TMF has fully exected in the target (in which case the return
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 	 * value is "TMF_RESP_FUNC_COMPLETE", or the request timed-out (or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 	 * was otherwise unable to be executed ("TMF_RESP_FUNC_FAILED").
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 	isci_task_build_tmf(&tmf, isci_tmf_ssp_lun_reset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 	#define ISCI_LU_RESET_TIMEOUT_MS 2000 /* 2 second timeout. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 	ret = isci_task_execute_tmf(isci_host, isci_device, &tmf, ISCI_LU_RESET_TIMEOUT_MS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 	if (ret == TMF_RESP_FUNC_COMPLETE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 		dev_dbg(&isci_host->pdev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) 			"%s: %p: TMF_LU_RESET passed\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 			__func__, isci_device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 		dev_dbg(&isci_host->pdev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 			"%s: %p: TMF_LU_RESET failed (%x)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 			__func__, isci_device, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) int isci_task_lu_reset(struct domain_device *dev, u8 *lun)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 	struct isci_host *ihost = dev_to_ihost(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 	struct isci_remote_device *idev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 	int ret = TMF_RESP_FUNC_COMPLETE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 	spin_lock_irqsave(&ihost->scic_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 	idev = isci_get_device(dev->lldd_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 	spin_unlock_irqrestore(&ihost->scic_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 	dev_dbg(&ihost->pdev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) 		"%s: domain_device=%p, isci_host=%p; isci_device=%p\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) 		__func__, dev, ihost, idev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) 	if (!idev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) 		/* If the device is gone, escalate to I_T_Nexus_Reset. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 		dev_dbg(&ihost->pdev->dev, "%s: No dev\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 		ret = TMF_RESP_FUNC_FAILED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) 	/* Suspend the RNC, kill all TCs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) 	if (isci_remote_device_suspend_terminate(ihost, idev, NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) 	    != SCI_SUCCESS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) 		/* The suspend/terminate only fails if isci_get_device fails */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) 		ret = TMF_RESP_FUNC_FAILED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) 	/* All pending I/Os have been terminated and cleaned up. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) 	if (!test_bit(IDEV_GONE, &idev->flags)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) 		if (dev_is_sata(dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) 			sas_ata_schedule_reset(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) 			/* Send the task management part of the reset. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) 			ret = isci_task_send_lu_reset_sas(ihost, idev, lun);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450)  out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) 	isci_put_device(idev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) /*	 int (*lldd_clear_nexus_port)(struct asd_sas_port *); */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) int isci_task_clear_nexus_port(struct asd_sas_port *port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) 	return TMF_RESP_FUNC_FAILED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) int isci_task_clear_nexus_ha(struct sas_ha_struct *ha)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) 	return TMF_RESP_FUNC_FAILED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) /* Task Management Functions. Must be called from process context.	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472)  * isci_task_abort_task() - This function is one of the SAS Domain Template
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473)  *    functions. This function is called by libsas to abort a specified task.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474)  * @task: This parameter specifies the SAS task to abort.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476)  * status, zero indicates success.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) int isci_task_abort_task(struct sas_task *task)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) 	struct isci_host *ihost = dev_to_ihost(task->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) 	DECLARE_COMPLETION_ONSTACK(aborted_io_completion);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) 	struct isci_request       *old_request = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) 	struct isci_remote_device *idev = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) 	struct isci_tmf           tmf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) 	int                       ret = TMF_RESP_FUNC_FAILED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) 	unsigned long             flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) 	int                       target_done_already = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) 	/* Get the isci_request reference from the task.  Note that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) 	 * this check does not depend on the pending request list
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) 	 * in the device, because tasks driving resets may land here
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) 	 * after completion in the core.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) 	spin_lock_irqsave(&ihost->scic_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) 	spin_lock(&task->task_state_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) 	old_request = task->lldd_task;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) 	/* If task is already done, the request isn't valid */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) 	if (!(task->task_state_flags & SAS_TASK_STATE_DONE) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) 	    (task->task_state_flags & SAS_TASK_AT_INITIATOR) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) 	    old_request) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) 		idev = isci_get_device(task->dev->lldd_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) 		target_done_already = test_bit(IREQ_COMPLETE_IN_TARGET,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) 					       &old_request->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) 	spin_unlock(&task->task_state_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) 	spin_unlock_irqrestore(&ihost->scic_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) 	dev_warn(&ihost->pdev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) 		 "%s: dev = %p (%s%s), task = %p, old_request == %p\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) 		 __func__, idev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) 		 (dev_is_sata(task->dev) ? "STP/SATA"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) 					 : ((dev_is_expander(task->dev->dev_type))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) 						? "SMP"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) 						: "SSP")),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) 		 ((idev) ? ((test_bit(IDEV_GONE, &idev->flags))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) 			   ? " IDEV_GONE"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) 			   : "")
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) 			 : " <NULL>"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) 		 task, old_request);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) 	/* Device reset conditions signalled in task_state_flags are the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) 	 * responsbility of libsas to observe at the start of the error
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) 	 * handler thread.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) 	if (!idev || !old_request) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) 		/* The request has already completed and there
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) 		* is nothing to do here other than to set the task
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) 		* done bit, and indicate that the task abort function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) 		* was successful.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) 		*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) 		spin_lock_irqsave(&task->task_state_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) 		task->task_state_flags |= SAS_TASK_STATE_DONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) 		task->task_state_flags &= ~(SAS_TASK_AT_INITIATOR |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) 					    SAS_TASK_STATE_PENDING);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) 		spin_unlock_irqrestore(&task->task_state_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) 		ret = TMF_RESP_FUNC_COMPLETE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) 		dev_warn(&ihost->pdev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) 			 "%s: abort task not needed for %p\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) 			 __func__, task);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) 	/* Suspend the RNC, kill the TC */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) 	if (isci_remote_device_suspend_terminate(ihost, idev, old_request)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) 	    != SCI_SUCCESS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) 		dev_warn(&ihost->pdev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) 			 "%s: isci_remote_device_reset_terminate(dev=%p, "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) 				 "req=%p, task=%p) failed\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) 			 __func__, idev, old_request, task);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) 		ret = TMF_RESP_FUNC_FAILED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) 	spin_lock_irqsave(&ihost->scic_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) 	if (task->task_proto == SAS_PROTOCOL_SMP ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) 	    sas_protocol_ata(task->task_proto) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) 	    target_done_already ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) 	    test_bit(IDEV_GONE, &idev->flags)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) 		spin_unlock_irqrestore(&ihost->scic_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) 		/* No task to send, so explicitly resume the device here */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) 		isci_remote_device_resume_from_abort(ihost, idev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) 		dev_warn(&ihost->pdev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) 			 "%s: %s request"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) 				 " or complete_in_target (%d), "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) 				 "or IDEV_GONE (%d), thus no TMF\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) 			 __func__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) 			 ((task->task_proto == SAS_PROTOCOL_SMP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) 			  ? "SMP"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) 			  : (sas_protocol_ata(task->task_proto)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) 				? "SATA/STP"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) 				: "<other>")
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) 			  ),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) 			 test_bit(IREQ_COMPLETE_IN_TARGET,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) 				  &old_request->flags),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) 			 test_bit(IDEV_GONE, &idev->flags));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) 		spin_lock_irqsave(&task->task_state_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) 		task->task_state_flags &= ~(SAS_TASK_AT_INITIATOR |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) 					    SAS_TASK_STATE_PENDING);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) 		task->task_state_flags |= SAS_TASK_STATE_DONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) 		spin_unlock_irqrestore(&task->task_state_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) 		ret = TMF_RESP_FUNC_COMPLETE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) 		/* Fill in the tmf structure */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) 		isci_task_build_abort_task_tmf(&tmf, isci_tmf_ssp_task_abort,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) 					       old_request);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) 		spin_unlock_irqrestore(&ihost->scic_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) 		/* Send the task management request. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) 		#define ISCI_ABORT_TASK_TIMEOUT_MS 500 /* 1/2 second timeout */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) 		ret = isci_task_execute_tmf(ihost, idev, &tmf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) 					    ISCI_ABORT_TASK_TIMEOUT_MS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) 	dev_warn(&ihost->pdev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) 		 "%s: Done; dev = %p, task = %p , old_request == %p\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) 		 __func__, idev, task, old_request);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) 	isci_put_device(idev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611)  * isci_task_abort_task_set() - This function is one of the SAS Domain Template
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612)  *    functions. This is one of the Task Management functoins called by libsas,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613)  *    to abort all task for the given lun.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614)  * @d_device: This parameter specifies the domain device associated with this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615)  *    request.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616)  * @lun: This parameter specifies the lun associated with this request.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618)  * status, zero indicates success.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) int isci_task_abort_task_set(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) 	struct domain_device *d_device,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) 	u8 *lun)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) 	return TMF_RESP_FUNC_FAILED;
^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) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629)  * isci_task_clear_aca() - This function is one of the SAS Domain Template
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630)  *    functions. This is one of the Task Management functoins called by libsas.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631)  * @d_device: This parameter specifies the domain device associated with this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632)  *    request.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633)  * @lun: This parameter specifies the lun	 associated with this request.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635)  * status, zero indicates success.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) int isci_task_clear_aca(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) 	struct domain_device *d_device,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) 	u8 *lun)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) 	return TMF_RESP_FUNC_FAILED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647)  * isci_task_clear_task_set() - This function is one of the SAS Domain Template
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648)  *    functions. This is one of the Task Management functoins called by libsas.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649)  * @d_device: This parameter specifies the domain device associated with this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650)  *    request.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651)  * @lun: This parameter specifies the lun	 associated with this request.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653)  * status, zero indicates success.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) int isci_task_clear_task_set(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) 	struct domain_device *d_device,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) 	u8 *lun)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) 	return TMF_RESP_FUNC_FAILED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664)  * isci_task_query_task() - This function is implemented to cause libsas to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665)  *    correctly escalate the failed abort to a LUN or target reset (this is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666)  *    because sas_scsi_find_task libsas function does not correctly interpret
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667)  *    all return codes from the abort task call).  When TMF_RESP_FUNC_SUCC is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668)  *    returned, libsas turns this into a LUN reset; when FUNC_FAILED is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669)  *    returned, libsas will turn this into a target reset
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670)  * @task: This parameter specifies the sas task being queried.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671)  * @lun: This parameter specifies the lun associated with this request.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673)  * status, zero indicates success.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) int isci_task_query_task(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) 	struct sas_task *task)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) 	/* See if there is a pending device reset for this device. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) 	if (task->task_state_flags & SAS_TASK_NEED_DEV_RESET)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) 		return TMF_RESP_FUNC_FAILED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) 		return TMF_RESP_FUNC_SUCC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686)  * isci_task_request_complete() - This function is called by the sci core when
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687)  *    an task request completes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688)  * @ihost: This parameter specifies the ISCI host object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689)  * @ireq: This parameter is the completed isci_request object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690)  * @completion_status: This parameter specifies the completion status from the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691)  *    sci core.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693)  * none.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) isci_task_request_complete(struct isci_host *ihost,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) 			   struct isci_request *ireq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) 			   enum sci_task_status completion_status)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) 	struct isci_tmf *tmf = isci_request_access_tmf(ireq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) 	struct completion *tmf_complete = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) 	dev_dbg(&ihost->pdev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) 		"%s: request = %p, status=%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) 		__func__, ireq, completion_status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) 	set_bit(IREQ_COMPLETE_IN_TARGET, &ireq->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) 	if (tmf) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) 		tmf->status = completion_status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) 		if (tmf->proto == SAS_PROTOCOL_SSP) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) 			memcpy(&tmf->resp.resp_iu,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) 			       &ireq->ssp.rsp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) 			       SSP_RESP_IU_MAX_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) 		} else if (tmf->proto == SAS_PROTOCOL_SATA) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) 			memcpy(&tmf->resp.d2h_fis,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) 			       &ireq->stp.rsp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) 			       sizeof(struct dev_to_host_fis));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) 		/* PRINT_TMF( ((struct isci_tmf *)request->task)); */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) 		tmf_complete = tmf->complete;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) 	sci_controller_complete_io(ihost, ireq->target_device, ireq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) 	/* set the 'terminated' flag handle to make sure it cannot be terminated
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) 	 *  or completed again.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) 	set_bit(IREQ_TERMINATED, &ireq->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) 	if (test_and_clear_bit(IREQ_ABORT_PATH_ACTIVE, &ireq->flags))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) 		wake_up_all(&ihost->eventq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) 	if (!test_bit(IREQ_NO_AUTO_FREE_TAG, &ireq->flags))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) 		isci_free_tag(ihost, ireq->io_tag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) 	/* The task management part completes last. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) 	if (tmf_complete)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) 		complete(tmf_complete);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) static int isci_reset_device(struct isci_host *ihost,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) 			     struct domain_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) 			     struct isci_remote_device *idev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) 	int rc = TMF_RESP_FUNC_COMPLETE, reset_stat = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) 	struct sas_phy *phy = sas_get_local_phy(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) 	struct isci_port *iport = dev->port->lldd_port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) 	dev_dbg(&ihost->pdev->dev, "%s: idev %p\n", __func__, idev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) 	/* Suspend the RNC, terminate all outstanding TCs. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) 	if (isci_remote_device_suspend_terminate(ihost, idev, NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) 	    != SCI_SUCCESS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) 		rc = TMF_RESP_FUNC_FAILED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) 	/* Note that since the termination for outstanding requests succeeded,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) 	 * this function will return success.  This is because the resets will
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) 	 * only fail if the device has been removed (ie. hotplug), and the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) 	 * primary duty of this function is to cleanup tasks, so that is the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) 	 * relevant status.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) 	if (!test_bit(IDEV_GONE, &idev->flags)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) 		if (scsi_is_sas_phy_local(phy)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) 			struct isci_phy *iphy = &ihost->phys[phy->number];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) 			reset_stat = isci_port_perform_hard_reset(ihost, iport,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) 								  iphy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) 		} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770) 			reset_stat = sas_phy_reset(phy, !dev_is_sata(dev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) 	/* Explicitly resume the RNC here, since there was no task sent. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773) 	isci_remote_device_resume_from_abort(ihost, idev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) 	dev_dbg(&ihost->pdev->dev, "%s: idev %p complete, reset_stat=%d.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776) 		__func__, idev, reset_stat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777)  out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778) 	sas_put_local_phy(phy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782) int isci_task_I_T_nexus_reset(struct domain_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784) 	struct isci_host *ihost = dev_to_ihost(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785) 	struct isci_remote_device *idev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789) 	spin_lock_irqsave(&ihost->scic_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790) 	idev = isci_get_device(dev->lldd_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791) 	spin_unlock_irqrestore(&ihost->scic_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793) 	if (!idev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794) 		/* XXX: need to cleanup any ireqs targeting this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795) 		 * domain_device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797) 		ret = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801) 	ret = isci_reset_device(ihost, dev, idev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802)  out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803) 	isci_put_device(idev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805) }