| 
									
										
										
										
											2011-07-02 22:56:22 -07:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * This file is provided under a dual BSD/GPLv2 license.  When using or | 
					
						
							|  |  |  |  * redistributing this file, you may do so under either license. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * GPL LICENSE SUMMARY | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This program is free software; you can redistribute it and/or modify | 
					
						
							|  |  |  |  * it under the terms of version 2 of the GNU General Public License as | 
					
						
							|  |  |  |  * published by the Free Software Foundation. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This program is distributed in the hope that it will be useful, but | 
					
						
							|  |  |  |  * WITHOUT ANY WARRANTY; without even the implied warranty of | 
					
						
							|  |  |  |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU | 
					
						
							|  |  |  |  * General Public License for more details. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * You should have received a copy of the GNU General Public License | 
					
						
							|  |  |  |  * along with this program; if not, write to the Free Software | 
					
						
							|  |  |  |  * Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. | 
					
						
							|  |  |  |  * The full GNU General Public License is included in this distribution | 
					
						
							|  |  |  |  * in the file called LICENSE.GPL. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * BSD LICENSE | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved. | 
					
						
							|  |  |  |  * All rights reserved. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Redistribution and use in source and binary forms, with or without | 
					
						
							|  |  |  |  * modification, are permitted provided that the following conditions | 
					
						
							|  |  |  |  * are met: | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  *   * Redistributions of source code must retain the above copyright | 
					
						
							|  |  |  |  *     notice, this list of conditions and the following disclaimer. | 
					
						
							|  |  |  |  *   * Redistributions in binary form must reproduce the above copyright | 
					
						
							|  |  |  |  *     notice, this list of conditions and the following disclaimer in | 
					
						
							|  |  |  |  *     the documentation and/or other materials provided with the | 
					
						
							|  |  |  |  *     distribution. | 
					
						
							|  |  |  |  *   * Neither the name of Intel Corporation nor the names of its | 
					
						
							|  |  |  |  *     contributors may be used to endorse or promote products derived | 
					
						
							|  |  |  |  *     from this software without specific prior written permission. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 
					
						
							|  |  |  |  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 
					
						
							|  |  |  |  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 
					
						
							|  |  |  |  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 
					
						
							|  |  |  |  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 
					
						
							|  |  |  |  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 
					
						
							|  |  |  |  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 
					
						
							|  |  |  |  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 
					
						
							|  |  |  |  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 
					
						
							|  |  |  |  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 
					
						
							|  |  |  |  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-10 01:18:34 -08:00
										 |  |  | #include <scsi/scsi_cmnd.h>
 | 
					
						
							| 
									
										
										
										
											2011-07-02 22:56:22 -07:00
										 |  |  | #include "isci.h"
 | 
					
						
							|  |  |  | #include "task.h"
 | 
					
						
							|  |  |  | #include "request.h"
 | 
					
						
							|  |  |  | #include "scu_completion_codes.h"
 | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:49 -07:00
										 |  |  | #include "scu_event_codes.h"
 | 
					
						
							| 
									
										
										
										
											2011-05-04 18:01:22 -07:00
										 |  |  | #include "sas.h"
 | 
					
						
							| 
									
										
										
										
											2011-07-02 22:56:22 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-10 01:18:44 -08:00
										 |  |  | #undef C
 | 
					
						
							|  |  |  | #define C(a) (#a)
 | 
					
						
							|  |  |  | const char *req_state_name(enum sci_base_request_states state) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	static const char * const strings[] = REQUEST_STATES; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return strings[state]; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | #undef C
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-27 14:57:03 -07:00
										 |  |  | static struct scu_sgl_element_pair *to_sgl_element_pair(struct isci_request *ireq, | 
					
						
							| 
									
										
										
										
											2011-06-28 13:47:09 -07:00
										 |  |  | 							int idx) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if (idx == 0) | 
					
						
							| 
									
										
										
										
											2011-06-27 14:57:03 -07:00
										 |  |  | 		return &ireq->tc->sgl_pair_ab; | 
					
						
							| 
									
										
										
										
											2011-06-28 13:47:09 -07:00
										 |  |  | 	else if (idx == 1) | 
					
						
							| 
									
										
										
										
											2011-06-27 14:57:03 -07:00
										 |  |  | 		return &ireq->tc->sgl_pair_cd; | 
					
						
							| 
									
										
										
										
											2011-06-28 13:47:09 -07:00
										 |  |  | 	else if (idx < 0) | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 	else | 
					
						
							| 
									
										
										
										
											2011-06-27 14:57:03 -07:00
										 |  |  | 		return &ireq->sg_table[idx - 2]; | 
					
						
							| 
									
										
										
										
											2011-06-28 13:47:09 -07:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-30 17:38:32 -07:00
										 |  |  | static dma_addr_t to_sgl_element_pair_dma(struct isci_host *ihost, | 
					
						
							| 
									
										
										
										
											2011-06-27 14:57:03 -07:00
										 |  |  | 					  struct isci_request *ireq, u32 idx) | 
					
						
							| 
									
										
										
										
											2011-06-28 13:47:09 -07:00
										 |  |  | { | 
					
						
							|  |  |  | 	u32 offset; | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-28 13:47:09 -07:00
										 |  |  | 	if (idx == 0) { | 
					
						
							| 
									
										
										
										
											2011-06-27 14:57:03 -07:00
										 |  |  | 		offset = (void *) &ireq->tc->sgl_pair_ab - | 
					
						
							| 
									
										
										
										
											2011-06-30 17:38:32 -07:00
										 |  |  | 			 (void *) &ihost->task_context_table[0]; | 
					
						
							| 
									
										
										
										
											2012-02-15 13:58:42 -08:00
										 |  |  | 		return ihost->tc_dma + offset; | 
					
						
							| 
									
										
										
										
											2011-06-28 13:47:09 -07:00
										 |  |  | 	} else if (idx == 1) { | 
					
						
							| 
									
										
										
										
											2011-06-27 14:57:03 -07:00
										 |  |  | 		offset = (void *) &ireq->tc->sgl_pair_cd - | 
					
						
							| 
									
										
										
										
											2011-06-30 17:38:32 -07:00
										 |  |  | 			 (void *) &ihost->task_context_table[0]; | 
					
						
							| 
									
										
										
										
											2012-02-15 13:58:42 -08:00
										 |  |  | 		return ihost->tc_dma + offset; | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2011-07-02 22:56:22 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-30 19:14:33 -07:00
										 |  |  | 	return sci_io_request_get_dma_addr(ireq, &ireq->sg_table[idx - 2]); | 
					
						
							| 
									
										
										
										
											2011-06-28 13:47:09 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void init_sgl_element(struct scu_sgl_element *e, struct scatterlist *sg) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	e->length = sg_dma_len(sg); | 
					
						
							|  |  |  | 	e->address_upper = upper_32_bits(sg_dma_address(sg)); | 
					
						
							|  |  |  | 	e->address_lower = lower_32_bits(sg_dma_address(sg)); | 
					
						
							|  |  |  | 	e->address_modifier = 0; | 
					
						
							| 
									
										
										
										
											2011-07-02 22:56:22 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-30 19:14:33 -07:00
										 |  |  | static void sci_request_build_sgl(struct isci_request *ireq) | 
					
						
							| 
									
										
										
										
											2011-07-02 22:56:22 -07:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-06-30 17:38:32 -07:00
										 |  |  | 	struct isci_host *ihost = ireq->isci_host; | 
					
						
							| 
									
										
										
										
											2011-06-27 14:57:03 -07:00
										 |  |  | 	struct sas_task *task = isci_request_access_task(ireq); | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 	struct scatterlist *sg = NULL; | 
					
						
							|  |  |  | 	dma_addr_t dma_addr; | 
					
						
							|  |  |  | 	u32 sg_idx = 0; | 
					
						
							|  |  |  | 	struct scu_sgl_element_pair *scu_sg   = NULL; | 
					
						
							|  |  |  | 	struct scu_sgl_element_pair *prev_sg  = NULL; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (task->num_scatter > 0) { | 
					
						
							|  |  |  | 		sg = task->scatter; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		while (sg) { | 
					
						
							| 
									
										
										
										
											2011-06-27 14:57:03 -07:00
										 |  |  | 			scu_sg = to_sgl_element_pair(ireq, sg_idx); | 
					
						
							| 
									
										
										
										
											2011-06-28 13:47:09 -07:00
										 |  |  | 			init_sgl_element(&scu_sg->A, sg); | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 			sg = sg_next(sg); | 
					
						
							|  |  |  | 			if (sg) { | 
					
						
							| 
									
										
										
										
											2011-06-28 13:47:09 -07:00
										 |  |  | 				init_sgl_element(&scu_sg->B, sg); | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 				sg = sg_next(sg); | 
					
						
							|  |  |  | 			} else | 
					
						
							| 
									
										
										
										
											2011-06-28 13:47:09 -07:00
										 |  |  | 				memset(&scu_sg->B, 0, sizeof(scu_sg->B)); | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			if (prev_sg) { | 
					
						
							| 
									
										
										
										
											2011-06-30 17:38:32 -07:00
										 |  |  | 				dma_addr = to_sgl_element_pair_dma(ihost, | 
					
						
							| 
									
										
										
										
											2011-06-27 14:57:03 -07:00
										 |  |  | 								   ireq, | 
					
						
							| 
									
										
										
										
											2011-06-28 13:47:09 -07:00
										 |  |  | 								   sg_idx); | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 				prev_sg->next_pair_upper = | 
					
						
							|  |  |  | 					upper_32_bits(dma_addr); | 
					
						
							|  |  |  | 				prev_sg->next_pair_lower = | 
					
						
							|  |  |  | 					lower_32_bits(dma_addr); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			prev_sg = scu_sg; | 
					
						
							|  |  |  | 			sg_idx++; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} else {	/* handle when no sg */ | 
					
						
							| 
									
										
										
										
											2011-06-27 14:57:03 -07:00
										 |  |  | 		scu_sg = to_sgl_element_pair(ireq, sg_idx); | 
					
						
							| 
									
										
										
										
											2011-07-02 22:56:22 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-30 17:38:32 -07:00
										 |  |  | 		dma_addr = dma_map_single(&ihost->pdev->dev, | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 					  task->scatter, | 
					
						
							|  |  |  | 					  task->total_xfer_len, | 
					
						
							|  |  |  | 					  task->data_dir); | 
					
						
							| 
									
										
										
										
											2011-07-02 22:56:22 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-27 14:57:03 -07:00
										 |  |  | 		ireq->zero_scatter_daddr = dma_addr; | 
					
						
							| 
									
										
										
										
											2011-07-02 22:56:22 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 		scu_sg->A.length = task->total_xfer_len; | 
					
						
							|  |  |  | 		scu_sg->A.address_upper = upper_32_bits(dma_addr); | 
					
						
							|  |  |  | 		scu_sg->A.address_lower = lower_32_bits(dma_addr); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2011-07-02 22:56:22 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 	if (scu_sg) { | 
					
						
							|  |  |  | 		scu_sg->next_pair_upper = 0; | 
					
						
							|  |  |  | 		scu_sg->next_pair_lower = 0; | 
					
						
							| 
									
										
										
										
											2011-07-02 22:56:22 -07:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2011-07-02 22:56:22 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-30 19:14:33 -07:00
										 |  |  | static void sci_io_request_build_ssp_command_iu(struct isci_request *ireq) | 
					
						
							| 
									
										
										
										
											2011-07-02 22:56:22 -07:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 	struct ssp_cmd_iu *cmd_iu; | 
					
						
							| 
									
										
										
										
											2011-05-04 18:01:22 -07:00
										 |  |  | 	struct sas_task *task = isci_request_access_task(ireq); | 
					
						
							| 
									
										
										
										
											2011-07-02 22:56:22 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-27 14:57:03 -07:00
										 |  |  | 	cmd_iu = &ireq->ssp.cmd; | 
					
						
							| 
									
										
										
										
											2011-07-02 22:56:22 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 	memcpy(cmd_iu->LUN, task->ssp_task.LUN, 8); | 
					
						
							|  |  |  | 	cmd_iu->add_cdb_len = 0; | 
					
						
							|  |  |  | 	cmd_iu->_r_a = 0; | 
					
						
							|  |  |  | 	cmd_iu->_r_b = 0; | 
					
						
							|  |  |  | 	cmd_iu->en_fburst = 0; /* unsupported */ | 
					
						
							|  |  |  | 	cmd_iu->task_prio = task->ssp_task.task_prio; | 
					
						
							|  |  |  | 	cmd_iu->task_attr = task->ssp_task.task_attr; | 
					
						
							|  |  |  | 	cmd_iu->_r_c = 0; | 
					
						
							| 
									
										
										
										
											2011-07-02 22:56:22 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-07 15:38:18 -07:00
										 |  |  | 	sci_swab32_cpy(&cmd_iu->cdb, task->ssp_task.cmd->cmnd, | 
					
						
							| 
									
										
										
										
											2013-07-24 12:43:18 -07:00
										 |  |  | 		       (task->ssp_task.cmd->cmd_len+3) / sizeof(u32)); | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2011-07-02 22:56:22 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-30 19:14:33 -07:00
										 |  |  | static void sci_task_request_build_ssp_task_iu(struct isci_request *ireq) | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | { | 
					
						
							|  |  |  | 	struct ssp_task_iu *task_iu; | 
					
						
							|  |  |  | 	struct sas_task *task = isci_request_access_task(ireq); | 
					
						
							|  |  |  | 	struct isci_tmf *isci_tmf = isci_request_access_tmf(ireq); | 
					
						
							| 
									
										
										
										
											2011-07-02 22:56:22 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-27 14:57:03 -07:00
										 |  |  | 	task_iu = &ireq->ssp.tmf; | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	memset(task_iu, 0, sizeof(struct ssp_task_iu)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	memcpy(task_iu->LUN, task->ssp_task.LUN, 8); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	task_iu->task_func = isci_tmf->tmf_code; | 
					
						
							|  |  |  | 	task_iu->task_tag = | 
					
						
							| 
									
										
										
										
											2011-10-27 15:05:22 -07:00
										 |  |  | 		(test_bit(IREQ_TMF, &ireq->flags)) ? | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 		isci_tmf->io_tag : | 
					
						
							|  |  |  | 		SCI_CONTROLLER_INVALID_IO_TAG; | 
					
						
							| 
									
										
										
										
											2011-07-02 22:56:22 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /**
 | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  |  * This method is will fill in the SCU Task Context for any type of SSP request. | 
					
						
							|  |  |  |  * @sci_req: | 
					
						
							|  |  |  |  * @task_context: | 
					
						
							| 
									
										
										
										
											2011-07-02 22:56:22 -07:00
										 |  |  |  * | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | static void scu_ssp_reqeust_construct_task_context( | 
					
						
							| 
									
										
										
										
											2011-06-27 14:57:03 -07:00
										 |  |  | 	struct isci_request *ireq, | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 	struct scu_task_context *task_context) | 
					
						
							| 
									
										
										
										
											2011-07-02 22:56:22 -07:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 	dma_addr_t dma_addr; | 
					
						
							| 
									
										
										
										
											2011-06-30 16:31:37 -07:00
										 |  |  | 	struct isci_remote_device *idev; | 
					
						
							| 
									
										
										
										
											2011-06-29 13:09:25 -07:00
										 |  |  | 	struct isci_port *iport; | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-07-01 02:25:15 -07:00
										 |  |  | 	idev = ireq->target_device; | 
					
						
							|  |  |  | 	iport = idev->owning_port; | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* Fill in the TC with the its required data */ | 
					
						
							|  |  |  | 	task_context->abort = 0; | 
					
						
							|  |  |  | 	task_context->priority = 0; | 
					
						
							|  |  |  | 	task_context->initiator_request = 1; | 
					
						
							| 
									
										
										
										
											2011-06-30 16:31:37 -07:00
										 |  |  | 	task_context->connection_rate = idev->connection_rate; | 
					
						
							| 
									
										
										
										
											2011-07-01 02:25:15 -07:00
										 |  |  | 	task_context->protocol_engine_index = ISCI_PEG; | 
					
						
							|  |  |  | 	task_context->logical_port_index = iport->physical_port_index; | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 	task_context->protocol_type = SCU_TASK_CONTEXT_PROTOCOL_SSP; | 
					
						
							|  |  |  | 	task_context->valid = SCU_TASK_CONTEXT_VALID; | 
					
						
							|  |  |  | 	task_context->context_type = SCU_TASK_CONTEXT_TYPE; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-07-01 02:25:15 -07:00
										 |  |  | 	task_context->remote_node_index = idev->rnc.remote_node_index; | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 	task_context->command_code = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	task_context->link_layer_control = 0; | 
					
						
							|  |  |  | 	task_context->do_not_dma_ssp_good_response = 1; | 
					
						
							|  |  |  | 	task_context->strict_ordering = 0; | 
					
						
							|  |  |  | 	task_context->control_frame = 0; | 
					
						
							|  |  |  | 	task_context->timeout_enable = 0; | 
					
						
							|  |  |  | 	task_context->block_guard_enable = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	task_context->address_modifier = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-27 14:57:03 -07:00
										 |  |  | 	/* task_context->type.ssp.tag = ireq->io_tag; */ | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 	task_context->task_phase = 0x01; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-27 14:57:03 -07:00
										 |  |  | 	ireq->post_context = (SCU_CONTEXT_COMMAND_REQUEST_TYPE_POST_TC | | 
					
						
							| 
									
										
										
										
											2011-07-01 02:25:15 -07:00
										 |  |  | 			      (ISCI_PEG << SCU_CONTEXT_COMMAND_PROTOCOL_ENGINE_GROUP_SHIFT) | | 
					
						
							|  |  |  | 			      (iport->physical_port_index << | 
					
						
							| 
									
										
										
										
											2011-06-29 13:09:25 -07:00
										 |  |  | 			       SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT) | | 
					
						
							|  |  |  | 			      ISCI_TAG_TCI(ireq->io_tag)); | 
					
						
							| 
									
										
										
										
											2011-07-02 22:56:22 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 	/*
 | 
					
						
							|  |  |  | 	 * Copy the physical address for the command buffer to the | 
					
						
							|  |  |  | 	 * SCU Task Context | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2011-06-30 19:14:33 -07:00
										 |  |  | 	dma_addr = sci_io_request_get_dma_addr(ireq, &ireq->ssp.cmd); | 
					
						
							| 
									
										
										
										
											2011-07-02 22:56:22 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 	task_context->command_iu_upper = upper_32_bits(dma_addr); | 
					
						
							|  |  |  | 	task_context->command_iu_lower = lower_32_bits(dma_addr); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/*
 | 
					
						
							|  |  |  | 	 * Copy the physical address for the response buffer to the | 
					
						
							|  |  |  | 	 * SCU Task Context | 
					
						
							| 
									
										
										
										
											2011-07-02 22:56:22 -07:00
										 |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2011-06-30 19:14:33 -07:00
										 |  |  | 	dma_addr = sci_io_request_get_dma_addr(ireq, &ireq->ssp.rsp); | 
					
						
							| 
									
										
										
										
											2011-07-02 22:56:22 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 	task_context->response_iu_upper = upper_32_bits(dma_addr); | 
					
						
							|  |  |  | 	task_context->response_iu_lower = lower_32_bits(dma_addr); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2011-07-02 22:56:22 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-10 01:18:34 -08:00
										 |  |  | static u8 scu_bg_blk_size(struct scsi_device *sdp) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	switch (sdp->sector_size) { | 
					
						
							|  |  |  | 	case 512: | 
					
						
							|  |  |  | 		return 0; | 
					
						
							|  |  |  | 	case 1024: | 
					
						
							|  |  |  | 		return 1; | 
					
						
							|  |  |  | 	case 4096: | 
					
						
							|  |  |  | 		return 3; | 
					
						
							|  |  |  | 	default: | 
					
						
							|  |  |  | 		return 0xff; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static u32 scu_dif_bytes(u32 len, u32 sector_size) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return (len >> ilog2(sector_size)) * 8; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void scu_ssp_ireq_dif_insert(struct isci_request *ireq, u8 type, u8 op) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct scu_task_context *tc = ireq->tc; | 
					
						
							|  |  |  | 	struct scsi_cmnd *scmd = ireq->ttype_ptr.io_task_ptr->uldd_task; | 
					
						
							|  |  |  | 	u8 blk_sz = scu_bg_blk_size(scmd->device); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	tc->block_guard_enable = 1; | 
					
						
							|  |  |  | 	tc->blk_prot_en = 1; | 
					
						
							|  |  |  | 	tc->blk_sz = blk_sz; | 
					
						
							|  |  |  | 	/* DIF write insert */ | 
					
						
							|  |  |  | 	tc->blk_prot_func = 0x2; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	tc->transfer_length_bytes += scu_dif_bytes(tc->transfer_length_bytes, | 
					
						
							|  |  |  | 						   scmd->device->sector_size); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* always init to 0, used by hw */ | 
					
						
							|  |  |  | 	tc->interm_crc_val = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	tc->init_crc_seed = 0; | 
					
						
							|  |  |  | 	tc->app_tag_verify = 0; | 
					
						
							|  |  |  | 	tc->app_tag_gen = 0; | 
					
						
							|  |  |  | 	tc->ref_tag_seed_verify = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* always init to same as bg_blk_sz */ | 
					
						
							|  |  |  | 	tc->UD_bytes_immed_val = scmd->device->sector_size; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	tc->reserved_DC_0 = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* always init to 8 */ | 
					
						
							|  |  |  | 	tc->DIF_bytes_immed_val = 8; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	tc->reserved_DC_1 = 0; | 
					
						
							|  |  |  | 	tc->bgc_blk_sz = scmd->device->sector_size; | 
					
						
							|  |  |  | 	tc->reserved_E0_0 = 0; | 
					
						
							|  |  |  | 	tc->app_tag_gen_mask = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** setup block guard control **/ | 
					
						
							|  |  |  | 	tc->bgctl = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* DIF write insert */ | 
					
						
							|  |  |  | 	tc->bgctl_f.op = 0x2; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	tc->app_tag_verify_mask = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* must init to 0 for hw */ | 
					
						
							|  |  |  | 	tc->blk_guard_err = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	tc->reserved_E8_0 = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if ((type & SCSI_PROT_DIF_TYPE1) || (type & SCSI_PROT_DIF_TYPE2)) | 
					
						
							|  |  |  | 		tc->ref_tag_seed_gen = scsi_get_lba(scmd) & 0xffffffff; | 
					
						
							|  |  |  | 	else if (type & SCSI_PROT_DIF_TYPE3) | 
					
						
							|  |  |  | 		tc->ref_tag_seed_gen = 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void scu_ssp_ireq_dif_strip(struct isci_request *ireq, u8 type, u8 op) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct scu_task_context *tc = ireq->tc; | 
					
						
							|  |  |  | 	struct scsi_cmnd *scmd = ireq->ttype_ptr.io_task_ptr->uldd_task; | 
					
						
							|  |  |  | 	u8 blk_sz = scu_bg_blk_size(scmd->device); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	tc->block_guard_enable = 1; | 
					
						
							|  |  |  | 	tc->blk_prot_en = 1; | 
					
						
							|  |  |  | 	tc->blk_sz = blk_sz; | 
					
						
							|  |  |  | 	/* DIF read strip */ | 
					
						
							|  |  |  | 	tc->blk_prot_func = 0x1; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	tc->transfer_length_bytes += scu_dif_bytes(tc->transfer_length_bytes, | 
					
						
							|  |  |  | 						   scmd->device->sector_size); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* always init to 0, used by hw */ | 
					
						
							|  |  |  | 	tc->interm_crc_val = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	tc->init_crc_seed = 0; | 
					
						
							|  |  |  | 	tc->app_tag_verify = 0; | 
					
						
							|  |  |  | 	tc->app_tag_gen = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if ((type & SCSI_PROT_DIF_TYPE1) || (type & SCSI_PROT_DIF_TYPE2)) | 
					
						
							|  |  |  | 		tc->ref_tag_seed_verify = scsi_get_lba(scmd) & 0xffffffff; | 
					
						
							|  |  |  | 	else if (type & SCSI_PROT_DIF_TYPE3) | 
					
						
							|  |  |  | 		tc->ref_tag_seed_verify = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* always init to same as bg_blk_sz */ | 
					
						
							|  |  |  | 	tc->UD_bytes_immed_val = scmd->device->sector_size; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	tc->reserved_DC_0 = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* always init to 8 */ | 
					
						
							|  |  |  | 	tc->DIF_bytes_immed_val = 8; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	tc->reserved_DC_1 = 0; | 
					
						
							|  |  |  | 	tc->bgc_blk_sz = scmd->device->sector_size; | 
					
						
							|  |  |  | 	tc->reserved_E0_0 = 0; | 
					
						
							|  |  |  | 	tc->app_tag_gen_mask = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** setup block guard control **/ | 
					
						
							|  |  |  | 	tc->bgctl = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* DIF read strip */ | 
					
						
							|  |  |  | 	tc->bgctl_f.crc_verify = 1; | 
					
						
							|  |  |  | 	tc->bgctl_f.op = 0x1; | 
					
						
							|  |  |  | 	if ((type & SCSI_PROT_DIF_TYPE1) || (type & SCSI_PROT_DIF_TYPE2)) { | 
					
						
							|  |  |  | 		tc->bgctl_f.ref_tag_chk = 1; | 
					
						
							|  |  |  | 		tc->bgctl_f.app_f_detect = 1; | 
					
						
							|  |  |  | 	} else if (type & SCSI_PROT_DIF_TYPE3) | 
					
						
							|  |  |  | 		tc->bgctl_f.app_ref_f_detect = 1; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	tc->app_tag_verify_mask = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* must init to 0 for hw */ | 
					
						
							|  |  |  | 	tc->blk_guard_err = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	tc->reserved_E8_0 = 0; | 
					
						
							|  |  |  | 	tc->ref_tag_seed_gen = 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | /**
 | 
					
						
							|  |  |  |  * This method is will fill in the SCU Task Context for a SSP IO request. | 
					
						
							|  |  |  |  * @sci_req: | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2011-06-27 14:57:03 -07:00
										 |  |  | static void scu_ssp_io_request_construct_task_context(struct isci_request *ireq, | 
					
						
							| 
									
										
										
										
											2011-06-28 13:47:09 -07:00
										 |  |  | 						      enum dma_data_direction dir, | 
					
						
							|  |  |  | 						      u32 len) | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-06-27 14:57:03 -07:00
										 |  |  | 	struct scu_task_context *task_context = ireq->tc; | 
					
						
							| 
									
										
										
										
											2012-02-10 01:18:34 -08:00
										 |  |  | 	struct sas_task *sas_task = ireq->ttype_ptr.io_task_ptr; | 
					
						
							|  |  |  | 	struct scsi_cmnd *scmd = sas_task->uldd_task; | 
					
						
							|  |  |  | 	u8 prot_type = scsi_get_prot_type(scmd); | 
					
						
							|  |  |  | 	u8 prot_op = scsi_get_prot_op(scmd); | 
					
						
							| 
									
										
										
										
											2011-07-02 22:56:22 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-27 14:57:03 -07:00
										 |  |  | 	scu_ssp_reqeust_construct_task_context(ireq, task_context); | 
					
						
							| 
									
										
										
										
											2011-07-02 22:56:22 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 	task_context->ssp_command_iu_length = | 
					
						
							|  |  |  | 		sizeof(struct ssp_cmd_iu) / sizeof(u32); | 
					
						
							|  |  |  | 	task_context->type.ssp.frame_type = SSP_COMMAND; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	switch (dir) { | 
					
						
							|  |  |  | 	case DMA_FROM_DEVICE: | 
					
						
							|  |  |  | 	case DMA_NONE: | 
					
						
							|  |  |  | 	default: | 
					
						
							|  |  |  | 		task_context->task_type = SCU_TASK_TYPE_IOREAD; | 
					
						
							| 
									
										
										
										
											2011-04-21 18:44:45 -07:00
										 |  |  | 		break; | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 	case DMA_TO_DEVICE: | 
					
						
							|  |  |  | 		task_context->task_type = SCU_TASK_TYPE_IOWRITE; | 
					
						
							| 
									
										
										
										
											2011-04-21 18:44:45 -07:00
										 |  |  | 		break; | 
					
						
							| 
									
										
										
										
											2011-07-02 22:56:22 -07:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 	task_context->transfer_length_bytes = len; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (task_context->transfer_length_bytes > 0) | 
					
						
							| 
									
										
										
										
											2011-06-30 19:14:33 -07:00
										 |  |  | 		sci_request_build_sgl(ireq); | 
					
						
							| 
									
										
										
										
											2012-02-10 01:18:34 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (prot_type != SCSI_PROT_DIF_TYPE0) { | 
					
						
							|  |  |  | 		if (prot_op == SCSI_PROT_READ_STRIP) | 
					
						
							|  |  |  | 			scu_ssp_ireq_dif_strip(ireq, prot_type, prot_op); | 
					
						
							|  |  |  | 		else if (prot_op == SCSI_PROT_WRITE_INSERT) | 
					
						
							|  |  |  | 			scu_ssp_ireq_dif_insert(ireq, prot_type, prot_op); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2011-07-02 22:56:22 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /**
 | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  |  * This method will fill in the SCU Task Context for a SSP Task request.  The | 
					
						
							|  |  |  |  *    following important settings are utilized: -# priority == | 
					
						
							|  |  |  |  *    SCU_TASK_PRIORITY_HIGH.  This ensures that the task request is issued | 
					
						
							|  |  |  |  *    ahead of other task destined for the same Remote Node. -# task_type == | 
					
						
							|  |  |  |  *    SCU_TASK_TYPE_IOREAD.  This simply indicates that a normal request type | 
					
						
							|  |  |  |  *    (i.e. non-raw frame) is being utilized to perform task management. -# | 
					
						
							|  |  |  |  *    control_frame == 1.  This ensures that the proper endianess is set so | 
					
						
							|  |  |  |  *    that the bytes are transmitted in the right order for a task frame. | 
					
						
							|  |  |  |  * @sci_req: This parameter specifies the task request object being | 
					
						
							|  |  |  |  *    constructed. | 
					
						
							| 
									
										
										
										
											2011-07-02 22:56:22 -07:00
										 |  |  |  * | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2011-06-27 14:57:03 -07:00
										 |  |  | static void scu_ssp_task_request_construct_task_context(struct isci_request *ireq) | 
					
						
							| 
									
										
										
										
											2011-07-02 22:56:22 -07:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-06-27 14:57:03 -07:00
										 |  |  | 	struct scu_task_context *task_context = ireq->tc; | 
					
						
							| 
									
										
										
										
											2011-07-02 22:56:22 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-27 14:57:03 -07:00
										 |  |  | 	scu_ssp_reqeust_construct_task_context(ireq, task_context); | 
					
						
							| 
									
										
										
										
											2011-07-02 22:56:22 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 	task_context->control_frame                = 1; | 
					
						
							|  |  |  | 	task_context->priority                     = SCU_TASK_PRIORITY_HIGH; | 
					
						
							|  |  |  | 	task_context->task_type                    = SCU_TASK_TYPE_RAW_FRAME; | 
					
						
							|  |  |  | 	task_context->transfer_length_bytes        = 0; | 
					
						
							|  |  |  | 	task_context->type.ssp.frame_type          = SSP_TASK; | 
					
						
							|  |  |  | 	task_context->ssp_command_iu_length = | 
					
						
							|  |  |  | 		sizeof(struct ssp_task_iu) / sizeof(u32); | 
					
						
							| 
									
										
										
										
											2011-07-02 22:56:22 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:49 -07:00
										 |  |  | /**
 | 
					
						
							|  |  |  |  * This method is will fill in the SCU Task Context for any type of SATA | 
					
						
							|  |  |  |  *    request.  This is called from the various SATA constructors. | 
					
						
							|  |  |  |  * @sci_req: The general IO request object which is to be used in | 
					
						
							|  |  |  |  *    constructing the SCU task context. | 
					
						
							|  |  |  |  * @task_context: The buffer pointer for the SCU task context which is being | 
					
						
							|  |  |  |  *    constructed. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * The general io request construction is complete. The buffer assignment for | 
					
						
							|  |  |  |  * the command buffer is complete. none Revisit task context construction to | 
					
						
							|  |  |  |  * determine what is common for SSP/SMP/STP task context structures. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | static void scu_sata_reqeust_construct_task_context( | 
					
						
							| 
									
										
										
										
											2011-06-27 14:57:03 -07:00
										 |  |  | 	struct isci_request *ireq, | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:49 -07:00
										 |  |  | 	struct scu_task_context *task_context) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	dma_addr_t dma_addr; | 
					
						
							| 
									
										
										
										
											2011-06-30 16:31:37 -07:00
										 |  |  | 	struct isci_remote_device *idev; | 
					
						
							| 
									
										
										
										
											2011-06-29 13:09:25 -07:00
										 |  |  | 	struct isci_port *iport; | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:49 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-07-01 02:25:15 -07:00
										 |  |  | 	idev = ireq->target_device; | 
					
						
							|  |  |  | 	iport = idev->owning_port; | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:49 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* Fill in the TC with the its required data */ | 
					
						
							|  |  |  | 	task_context->abort = 0; | 
					
						
							|  |  |  | 	task_context->priority = SCU_TASK_PRIORITY_NORMAL; | 
					
						
							|  |  |  | 	task_context->initiator_request = 1; | 
					
						
							| 
									
										
										
										
											2011-06-30 16:31:37 -07:00
										 |  |  | 	task_context->connection_rate = idev->connection_rate; | 
					
						
							| 
									
										
										
										
											2011-07-01 02:25:15 -07:00
										 |  |  | 	task_context->protocol_engine_index = ISCI_PEG; | 
					
						
							|  |  |  | 	task_context->logical_port_index = iport->physical_port_index; | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:49 -07:00
										 |  |  | 	task_context->protocol_type = SCU_TASK_CONTEXT_PROTOCOL_STP; | 
					
						
							|  |  |  | 	task_context->valid = SCU_TASK_CONTEXT_VALID; | 
					
						
							|  |  |  | 	task_context->context_type = SCU_TASK_CONTEXT_TYPE; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-07-01 02:25:15 -07:00
										 |  |  | 	task_context->remote_node_index = idev->rnc.remote_node_index; | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:49 -07:00
										 |  |  | 	task_context->command_code = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	task_context->link_layer_control = 0; | 
					
						
							|  |  |  | 	task_context->do_not_dma_ssp_good_response = 1; | 
					
						
							|  |  |  | 	task_context->strict_ordering = 0; | 
					
						
							|  |  |  | 	task_context->control_frame = 0; | 
					
						
							|  |  |  | 	task_context->timeout_enable = 0; | 
					
						
							|  |  |  | 	task_context->block_guard_enable = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	task_context->address_modifier = 0; | 
					
						
							|  |  |  | 	task_context->task_phase = 0x01; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	task_context->ssp_command_iu_length = | 
					
						
							|  |  |  | 		(sizeof(struct host_to_dev_fis) - sizeof(u32)) / sizeof(u32); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* Set the first word of the H2D REG FIS */ | 
					
						
							| 
									
										
										
										
											2011-06-27 14:57:03 -07:00
										 |  |  | 	task_context->type.words[0] = *(u32 *)&ireq->stp.cmd; | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:49 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-27 14:57:03 -07:00
										 |  |  | 	ireq->post_context = (SCU_CONTEXT_COMMAND_REQUEST_TYPE_POST_TC | | 
					
						
							| 
									
										
										
										
											2011-07-01 02:25:15 -07:00
										 |  |  | 			      (ISCI_PEG << SCU_CONTEXT_COMMAND_PROTOCOL_ENGINE_GROUP_SHIFT) | | 
					
						
							|  |  |  | 			      (iport->physical_port_index << | 
					
						
							|  |  |  | 			       SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT) | | 
					
						
							|  |  |  | 			      ISCI_TAG_TCI(ireq->io_tag)); | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:49 -07:00
										 |  |  | 	/*
 | 
					
						
							|  |  |  | 	 * Copy the physical address for the command buffer to the SCU Task | 
					
						
							|  |  |  | 	 * Context. We must offset the command buffer by 4 bytes because the | 
					
						
							|  |  |  | 	 * first 4 bytes are transfered in the body of the TC. | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2011-06-30 19:14:33 -07:00
										 |  |  | 	dma_addr = sci_io_request_get_dma_addr(ireq, | 
					
						
							| 
									
										
										
										
											2011-06-27 14:57:03 -07:00
										 |  |  | 						((char *) &ireq->stp.cmd) + | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:49 -07:00
										 |  |  | 						sizeof(u32)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	task_context->command_iu_upper = upper_32_bits(dma_addr); | 
					
						
							|  |  |  | 	task_context->command_iu_lower = lower_32_bits(dma_addr); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* SATA Requests do not have a response buffer */ | 
					
						
							|  |  |  | 	task_context->response_iu_upper = 0; | 
					
						
							|  |  |  | 	task_context->response_iu_lower = 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-27 14:57:03 -07:00
										 |  |  | static void scu_stp_raw_request_construct_task_context(struct isci_request *ireq) | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:49 -07:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-06-27 14:57:03 -07:00
										 |  |  | 	struct scu_task_context *task_context = ireq->tc; | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:49 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-27 14:57:03 -07:00
										 |  |  | 	scu_sata_reqeust_construct_task_context(ireq, task_context); | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:49 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	task_context->control_frame         = 0; | 
					
						
							|  |  |  | 	task_context->priority              = SCU_TASK_PRIORITY_NORMAL; | 
					
						
							|  |  |  | 	task_context->task_type             = SCU_TASK_TYPE_SATA_RAW_FRAME; | 
					
						
							|  |  |  | 	task_context->type.stp.fis_type     = FIS_REGH2D; | 
					
						
							|  |  |  | 	task_context->transfer_length_bytes = sizeof(struct host_to_dev_fis) - sizeof(u32); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-30 19:14:33 -07:00
										 |  |  | static enum sci_status sci_stp_pio_request_construct(struct isci_request *ireq, | 
					
						
							| 
									
										
										
										
											2011-06-27 14:57:03 -07:00
										 |  |  | 							  bool copy_rx_frame) | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:49 -07:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-06-27 14:57:03 -07:00
										 |  |  | 	struct isci_stp_request *stp_req = &ireq->stp.req; | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:49 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-27 14:57:03 -07:00
										 |  |  | 	scu_stp_raw_request_construct_task_context(ireq); | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:49 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-27 11:56:41 -07:00
										 |  |  | 	stp_req->status = 0; | 
					
						
							|  |  |  | 	stp_req->sgl.offset = 0; | 
					
						
							|  |  |  | 	stp_req->sgl.set = SCU_SGL_ELEMENT_PAIR_A; | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:49 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (copy_rx_frame) { | 
					
						
							| 
									
										
										
										
											2011-06-30 19:14:33 -07:00
										 |  |  | 		sci_request_build_sgl(ireq); | 
					
						
							| 
									
										
										
										
											2011-06-27 11:56:41 -07:00
										 |  |  | 		stp_req->sgl.index = 0; | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:49 -07:00
										 |  |  | 	} else { | 
					
						
							|  |  |  | 		/* The user does not want the data copied to the SGL buffer location */ | 
					
						
							| 
									
										
										
										
											2011-06-27 11:56:41 -07:00
										 |  |  | 		stp_req->sgl.index = -1; | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:49 -07:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2011-07-02 22:56:22 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:49 -07:00
										 |  |  | 	return SCI_SUCCESS; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2011-07-02 22:56:22 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | /**
 | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:49 -07:00
										 |  |  |  * @sci_req: This parameter specifies the request to be constructed as an | 
					
						
							|  |  |  |  *    optimized request. | 
					
						
							|  |  |  |  * @optimized_task_type: This parameter specifies whether the request is to be | 
					
						
							|  |  |  |  *    an UDMA request or a NCQ request. - A value of 0 indicates UDMA. - A | 
					
						
							|  |  |  |  *    value of 1 indicates NCQ. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This method will perform request construction common to all types of STP | 
					
						
							|  |  |  |  * requests that are optimized by the silicon (i.e. UDMA, NCQ). This method | 
					
						
							|  |  |  |  * returns an indication as to whether the construction was successful. | 
					
						
							| 
									
										
										
										
											2011-07-02 22:56:22 -07:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2011-06-30 19:14:33 -07:00
										 |  |  | static void sci_stp_optimized_request_construct(struct isci_request *ireq, | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:49 -07:00
										 |  |  | 						     u8 optimized_task_type, | 
					
						
							|  |  |  | 						     u32 len, | 
					
						
							|  |  |  | 						     enum dma_data_direction dir) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2011-06-27 14:57:03 -07:00
										 |  |  | 	struct scu_task_context *task_context = ireq->tc; | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:49 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* Build the STP task context structure */ | 
					
						
							| 
									
										
										
										
											2011-06-27 14:57:03 -07:00
										 |  |  | 	scu_sata_reqeust_construct_task_context(ireq, task_context); | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:49 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* Copy over the SGL elements */ | 
					
						
							| 
									
										
										
										
											2011-06-30 19:14:33 -07:00
										 |  |  | 	sci_request_build_sgl(ireq); | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:49 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* Copy over the number of bytes to be transfered */ | 
					
						
							|  |  |  | 	task_context->transfer_length_bytes = len; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (dir == DMA_TO_DEVICE) { | 
					
						
							|  |  |  | 		/*
 | 
					
						
							|  |  |  | 		 * The difference between the DMA IN and DMA OUT request task type | 
					
						
							|  |  |  | 		 * values are consistent with the difference between FPDMA READ | 
					
						
							|  |  |  | 		 * and FPDMA WRITE values.  Add the supplied task type parameter | 
					
						
							|  |  |  | 		 * to this difference to set the task type properly for this | 
					
						
							|  |  |  | 		 * DATA OUT (WRITE) case. */ | 
					
						
							|  |  |  | 		task_context->task_type = optimized_task_type + (SCU_TASK_TYPE_DMA_OUT | 
					
						
							|  |  |  | 								 - SCU_TASK_TYPE_DMA_IN); | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		/*
 | 
					
						
							|  |  |  | 		 * For the DATA IN (READ) case, simply save the supplied | 
					
						
							|  |  |  | 		 * optimized task type. */ | 
					
						
							|  |  |  | 		task_context->task_type = optimized_task_type; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-09-30 18:52:19 -07:00
										 |  |  | static void sci_atapi_construct(struct isci_request *ireq) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct host_to_dev_fis *h2d_fis = &ireq->stp.cmd; | 
					
						
							|  |  |  | 	struct sas_task *task; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* To simplify the implementation we take advantage of the
 | 
					
						
							|  |  |  | 	 * silicon's partial acceleration of atapi protocol (dma data | 
					
						
							|  |  |  | 	 * transfers), so we promote all commands to dma protocol.  This | 
					
						
							|  |  |  | 	 * breaks compatibility with ATA_HORKAGE_ATAPI_MOD16_DMA drives. | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	h2d_fis->features |= ATAPI_PKT_DMA; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	scu_stp_raw_request_construct_task_context(ireq); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	task = isci_request_access_task(ireq); | 
					
						
							|  |  |  | 	if (task->data_dir == DMA_NONE) | 
					
						
							|  |  |  | 		task->total_xfer_len = 0; | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:49 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-09-30 18:52:19 -07:00
										 |  |  | 	/* clear the response so we can detect arrivial of an
 | 
					
						
							|  |  |  | 	 * unsolicited h2d fis | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	ireq->stp.rsp.fis_type = 0; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:49 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | static enum sci_status | 
					
						
							| 
									
										
										
										
											2011-06-30 19:14:33 -07:00
										 |  |  | sci_io_request_construct_sata(struct isci_request *ireq, | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 			       u32 len, | 
					
						
							|  |  |  | 			       enum dma_data_direction dir, | 
					
						
							|  |  |  | 			       bool copy) | 
					
						
							| 
									
										
										
										
											2011-07-02 22:56:22 -07:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 	enum sci_status status = SCI_SUCCESS; | 
					
						
							|  |  |  | 	struct sas_task *task = isci_request_access_task(ireq); | 
					
						
							| 
									
										
										
										
											2011-09-30 18:52:19 -07:00
										 |  |  | 	struct domain_device *dev = ireq->target_device->domain_dev; | 
					
						
							| 
									
										
										
										
											2011-07-02 22:56:22 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 	/* check for management protocols */ | 
					
						
							| 
									
										
										
										
											2011-10-27 15:05:22 -07:00
										 |  |  | 	if (test_bit(IREQ_TMF, &ireq->flags)) { | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 		struct isci_tmf *tmf = isci_request_access_tmf(ireq); | 
					
						
							| 
									
										
										
										
											2011-07-02 22:56:22 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-08 23:20:44 -08:00
										 |  |  | 		dev_err(&ireq->owning_controller->pdev->dev, | 
					
						
							|  |  |  | 			"%s: Request 0x%p received un-handled SAT " | 
					
						
							|  |  |  | 			"management protocol 0x%x.\n", | 
					
						
							|  |  |  | 			__func__, ireq, tmf->tmf_code); | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-08 23:20:44 -08:00
										 |  |  | 		return SCI_FAILURE; | 
					
						
							| 
									
										
										
										
											2011-07-02 22:56:22 -07:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 	if (!sas_protocol_ata(task->task_proto)) { | 
					
						
							| 
									
										
										
										
											2011-06-30 17:38:32 -07:00
										 |  |  | 		dev_err(&ireq->owning_controller->pdev->dev, | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 			"%s: Non-ATA protocol in SATA path: 0x%x\n", | 
					
						
							|  |  |  | 			__func__, | 
					
						
							|  |  |  | 			task->task_proto); | 
					
						
							|  |  |  | 		return SCI_FAILURE; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-09-30 18:52:19 -07:00
										 |  |  | 	/* ATAPI */ | 
					
						
							|  |  |  | 	if (dev->sata_dev.command_set == ATAPI_COMMAND_SET && | 
					
						
							|  |  |  | 	    task->ata_task.fis.command == ATA_CMD_PACKET) { | 
					
						
							|  |  |  | 		sci_atapi_construct(ireq); | 
					
						
							|  |  |  | 		return SCI_SUCCESS; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 	/* non data */ | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:49 -07:00
										 |  |  | 	if (task->data_dir == DMA_NONE) { | 
					
						
							| 
									
										
										
										
											2011-06-27 14:57:03 -07:00
										 |  |  | 		scu_stp_raw_request_construct_task_context(ireq); | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:49 -07:00
										 |  |  | 		return SCI_SUCCESS; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* NCQ */ | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:49 -07:00
										 |  |  | 	if (task->ata_task.use_ncq) { | 
					
						
							| 
									
										
										
										
											2011-06-30 19:14:33 -07:00
										 |  |  | 		sci_stp_optimized_request_construct(ireq, | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:49 -07:00
										 |  |  | 							 SCU_TASK_TYPE_FPDMAQ_READ, | 
					
						
							|  |  |  | 							 len, dir); | 
					
						
							|  |  |  | 		return SCI_SUCCESS; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* DMA */ | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:49 -07:00
										 |  |  | 	if (task->ata_task.dma_xfer) { | 
					
						
							| 
									
										
										
										
											2011-06-30 19:14:33 -07:00
										 |  |  | 		sci_stp_optimized_request_construct(ireq, | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:49 -07:00
										 |  |  | 							 SCU_TASK_TYPE_DMA_IN, | 
					
						
							|  |  |  | 							 len, dir); | 
					
						
							|  |  |  | 		return SCI_SUCCESS; | 
					
						
							|  |  |  | 	} else /* PIO */ | 
					
						
							| 
									
										
										
										
											2011-06-30 19:14:33 -07:00
										 |  |  | 		return sci_stp_pio_request_construct(ireq, copy); | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return status; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-30 19:14:33 -07:00
										 |  |  | static enum sci_status sci_io_request_construct_basic_ssp(struct isci_request *ireq) | 
					
						
							| 
									
										
										
										
											2011-07-02 22:56:22 -07:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 	struct sas_task *task = isci_request_access_task(ireq); | 
					
						
							| 
									
										
										
										
											2011-07-02 22:56:22 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-01 00:44:14 -08:00
										 |  |  | 	ireq->protocol = SAS_PROTOCOL_SSP; | 
					
						
							| 
									
										
										
										
											2011-07-02 22:56:22 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-27 14:57:03 -07:00
										 |  |  | 	scu_ssp_io_request_construct_task_context(ireq, | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 						  task->data_dir, | 
					
						
							|  |  |  | 						  task->total_xfer_len); | 
					
						
							| 
									
										
										
										
											2011-07-02 22:56:22 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-30 19:14:33 -07:00
										 |  |  | 	sci_io_request_build_ssp_command_iu(ireq); | 
					
						
							| 
									
										
										
										
											2011-07-02 22:56:22 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-27 14:57:03 -07:00
										 |  |  | 	sci_change_state(&ireq->sm, SCI_REQ_CONSTRUCTED); | 
					
						
							| 
									
										
										
										
											2011-03-31 13:10:36 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 	return SCI_SUCCESS; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2011-07-02 22:56:22 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-30 19:14:33 -07:00
										 |  |  | enum sci_status sci_task_request_construct_ssp( | 
					
						
							| 
									
										
										
										
											2011-06-27 14:57:03 -07:00
										 |  |  | 	struct isci_request *ireq) | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | { | 
					
						
							|  |  |  | 	/* Construct the SSP Task SCU Task Context */ | 
					
						
							| 
									
										
										
										
											2011-06-27 14:57:03 -07:00
										 |  |  | 	scu_ssp_task_request_construct_task_context(ireq); | 
					
						
							| 
									
										
										
										
											2011-07-02 22:56:22 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 	/* Fill in the SSP Task IU */ | 
					
						
							| 
									
										
										
										
											2011-06-30 19:14:33 -07:00
										 |  |  | 	sci_task_request_build_ssp_task_iu(ireq); | 
					
						
							| 
									
										
										
										
											2011-03-16 09:41:59 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-27 14:57:03 -07:00
										 |  |  | 	sci_change_state(&ireq->sm, SCI_REQ_CONSTRUCTED); | 
					
						
							| 
									
										
										
										
											2011-05-08 11:47:15 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 	return SCI_SUCCESS; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2011-05-08 11:47:15 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-30 19:14:33 -07:00
										 |  |  | static enum sci_status sci_io_request_construct_basic_sata(struct isci_request *ireq) | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | { | 
					
						
							|  |  |  | 	enum sci_status status; | 
					
						
							|  |  |  | 	bool copy = false; | 
					
						
							| 
									
										
										
										
											2011-06-27 14:57:03 -07:00
										 |  |  | 	struct sas_task *task = isci_request_access_task(ireq); | 
					
						
							| 
									
										
										
										
											2011-07-02 22:56:22 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-01 00:44:14 -08:00
										 |  |  | 	ireq->protocol = SAS_PROTOCOL_STP; | 
					
						
							| 
									
										
										
										
											2011-07-02 22:56:22 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 	copy = (task->data_dir == DMA_NONE) ? false : true; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-30 19:14:33 -07:00
										 |  |  | 	status = sci_io_request_construct_sata(ireq, | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 						task->total_xfer_len, | 
					
						
							|  |  |  | 						task->data_dir, | 
					
						
							|  |  |  | 						copy); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (status == SCI_SUCCESS) | 
					
						
							| 
									
										
										
										
											2011-06-27 14:57:03 -07:00
										 |  |  | 		sci_change_state(&ireq->sm, SCI_REQ_CONSTRUCTED); | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return status; | 
					
						
							| 
									
										
										
										
											2011-07-02 22:56:22 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /**
 | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  |  * sci_req_tx_bytes - bytes transferred when reply underruns request | 
					
						
							| 
									
										
										
										
											2011-09-30 18:52:19 -07:00
										 |  |  |  * @ireq: request that was terminated early | 
					
						
							| 
									
										
										
										
											2011-07-02 22:56:22 -07:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | #define SCU_TASK_CONTEXT_SRAM 0x200000
 | 
					
						
							| 
									
										
										
										
											2011-06-27 14:57:03 -07:00
										 |  |  | static u32 sci_req_tx_bytes(struct isci_request *ireq) | 
					
						
							| 
									
										
										
										
											2011-07-02 22:56:22 -07:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-06-30 17:38:32 -07:00
										 |  |  | 	struct isci_host *ihost = ireq->owning_controller; | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 	u32 ret_val = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-30 17:38:32 -07:00
										 |  |  | 	if (readl(&ihost->smu_registers->address_modifier) == 0) { | 
					
						
							|  |  |  | 		void __iomem *scu_reg_base = ihost->scu_registers; | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		/* get the bytes of data from the Address == BAR1 + 20002Ch + (256*TCi) where
 | 
					
						
							|  |  |  | 		 *   BAR1 is the scu_registers | 
					
						
							|  |  |  | 		 *   0x20002C = 0x200000 + 0x2c | 
					
						
							|  |  |  | 		 *            = start of task context SRAM + offset of (type.ssp.data_offset) | 
					
						
							| 
									
										
										
										
											2011-06-30 19:14:33 -07:00
										 |  |  | 		 *   TCi is the io_tag of struct sci_request | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 		 */ | 
					
						
							|  |  |  | 		ret_val = readl(scu_reg_base + | 
					
						
							|  |  |  | 				(SCU_TASK_CONTEXT_SRAM + offsetof(struct scu_task_context, type.ssp.data_offset)) + | 
					
						
							| 
									
										
										
										
											2011-06-27 14:57:03 -07:00
										 |  |  | 				((sizeof(struct scu_task_context)) * ISCI_TAG_TCI(ireq->io_tag))); | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return ret_val; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-30 19:14:33 -07:00
										 |  |  | enum sci_status sci_request_start(struct isci_request *ireq) | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-05-10 23:50:32 +00:00
										 |  |  | 	enum sci_base_request_states state; | 
					
						
							| 
									
										
										
										
											2011-06-27 14:57:03 -07:00
										 |  |  | 	struct scu_task_context *tc = ireq->tc; | 
					
						
							| 
									
										
										
										
											2011-06-30 17:38:32 -07:00
										 |  |  | 	struct isci_host *ihost = ireq->owning_controller; | 
					
						
							| 
									
										
										
										
											2011-05-10 23:50:32 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-27 14:57:03 -07:00
										 |  |  | 	state = ireq->sm.current_state_id; | 
					
						
							| 
									
										
										
										
											2011-06-02 00:10:43 +00:00
										 |  |  | 	if (state != SCI_REQ_CONSTRUCTED) { | 
					
						
							| 
									
										
										
										
											2011-06-30 17:38:32 -07:00
										 |  |  | 		dev_warn(&ihost->pdev->dev, | 
					
						
							| 
									
										
										
										
											2011-05-10 23:50:32 +00:00
										 |  |  | 			"%s: SCIC IO Request requested to start while in wrong " | 
					
						
							|  |  |  | 			 "state %d\n", __func__, state); | 
					
						
							|  |  |  | 		return SCI_FAILURE_INVALID_STATE; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-27 14:57:03 -07:00
										 |  |  | 	tc->task_index = ISCI_TAG_TCI(ireq->io_tag); | 
					
						
							| 
									
										
										
										
											2011-05-10 23:50:32 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-28 13:47:09 -07:00
										 |  |  | 	switch (tc->protocol_type) { | 
					
						
							|  |  |  | 	case SCU_TASK_CONTEXT_PROTOCOL_SMP: | 
					
						
							|  |  |  | 	case SCU_TASK_CONTEXT_PROTOCOL_SSP: | 
					
						
							|  |  |  | 		/* SSP/SMP Frame */ | 
					
						
							| 
									
										
										
										
											2011-06-27 14:57:03 -07:00
										 |  |  | 		tc->type.ssp.tag = ireq->io_tag; | 
					
						
							| 
									
										
										
										
											2011-06-28 13:47:09 -07:00
										 |  |  | 		tc->type.ssp.target_port_transfer_tag = 0xFFFF; | 
					
						
							|  |  |  | 		break; | 
					
						
							| 
									
										
										
										
											2011-05-10 23:50:32 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-28 13:47:09 -07:00
										 |  |  | 	case SCU_TASK_CONTEXT_PROTOCOL_STP: | 
					
						
							|  |  |  | 		/* STP/SATA Frame
 | 
					
						
							| 
									
										
										
										
											2011-06-27 14:57:03 -07:00
										 |  |  | 		 * tc->type.stp.ncq_tag = ireq->ncq_tag; | 
					
						
							| 
									
										
										
										
											2011-06-28 13:47:09 -07:00
										 |  |  | 		 */ | 
					
						
							|  |  |  | 		break; | 
					
						
							| 
									
										
										
										
											2011-05-10 23:50:32 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-28 13:47:09 -07:00
										 |  |  | 	case SCU_TASK_CONTEXT_PROTOCOL_NONE: | 
					
						
							|  |  |  | 		/* / @todo When do we set no protocol type? */ | 
					
						
							|  |  |  | 		break; | 
					
						
							| 
									
										
										
										
											2011-05-10 23:50:32 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-28 13:47:09 -07:00
										 |  |  | 	default: | 
					
						
							|  |  |  | 		/* This should never happen since we build the IO
 | 
					
						
							|  |  |  | 		 * requests */ | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2011-05-10 23:50:32 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-28 13:47:09 -07:00
										 |  |  | 	/* Add to the post_context the io tag value */ | 
					
						
							| 
									
										
										
										
											2011-06-27 14:57:03 -07:00
										 |  |  | 	ireq->post_context |= ISCI_TAG_TCI(ireq->io_tag); | 
					
						
							| 
									
										
										
										
											2011-05-10 23:50:32 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-28 13:47:09 -07:00
										 |  |  | 	/* Everything is good go ahead and change state */ | 
					
						
							| 
									
										
										
										
											2011-06-27 14:57:03 -07:00
										 |  |  | 	sci_change_state(&ireq->sm, SCI_REQ_STARTED); | 
					
						
							| 
									
										
										
										
											2011-05-10 23:50:32 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-28 13:47:09 -07:00
										 |  |  | 	return SCI_SUCCESS; | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | enum sci_status | 
					
						
							| 
									
										
										
										
											2011-06-30 19:14:33 -07:00
										 |  |  | sci_io_request_terminate(struct isci_request *ireq) | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-05-10 02:39:11 -07:00
										 |  |  | 	enum sci_base_request_states state; | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-27 14:57:03 -07:00
										 |  |  | 	state = ireq->sm.current_state_id; | 
					
						
							| 
									
										
										
										
											2011-05-10 02:39:11 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	switch (state) { | 
					
						
							| 
									
										
										
										
											2011-06-02 00:10:43 +00:00
										 |  |  | 	case SCI_REQ_CONSTRUCTED: | 
					
						
							| 
									
										
										
										
											2012-03-08 22:41:50 -08:00
										 |  |  | 		/* Set to make sure no HW terminate posting is done: */ | 
					
						
							|  |  |  | 		set_bit(IREQ_TC_ABORT_POSTED, &ireq->flags); | 
					
						
							| 
									
										
										
										
											2011-07-01 02:25:15 -07:00
										 |  |  | 		ireq->scu_status = SCU_TASK_DONE_TASK_ABORT; | 
					
						
							|  |  |  | 		ireq->sci_status = SCI_FAILURE_IO_TERMINATED; | 
					
						
							| 
									
										
										
										
											2011-06-27 14:57:03 -07:00
										 |  |  | 		sci_change_state(&ireq->sm, SCI_REQ_COMPLETED); | 
					
						
							| 
									
										
										
										
											2011-05-10 02:39:11 -07:00
										 |  |  | 		return SCI_SUCCESS; | 
					
						
							| 
									
										
										
										
											2011-06-02 00:10:43 +00:00
										 |  |  | 	case SCI_REQ_STARTED: | 
					
						
							|  |  |  | 	case SCI_REQ_TASK_WAIT_TC_COMP: | 
					
						
							|  |  |  | 	case SCI_REQ_SMP_WAIT_RESP: | 
					
						
							|  |  |  | 	case SCI_REQ_SMP_WAIT_TC_COMP: | 
					
						
							|  |  |  | 	case SCI_REQ_STP_UDMA_WAIT_TC_COMP: | 
					
						
							|  |  |  | 	case SCI_REQ_STP_UDMA_WAIT_D2H: | 
					
						
							|  |  |  | 	case SCI_REQ_STP_NON_DATA_WAIT_H2D: | 
					
						
							|  |  |  | 	case SCI_REQ_STP_NON_DATA_WAIT_D2H: | 
					
						
							|  |  |  | 	case SCI_REQ_STP_PIO_WAIT_H2D: | 
					
						
							|  |  |  | 	case SCI_REQ_STP_PIO_WAIT_FRAME: | 
					
						
							|  |  |  | 	case SCI_REQ_STP_PIO_DATA_IN: | 
					
						
							|  |  |  | 	case SCI_REQ_STP_PIO_DATA_OUT: | 
					
						
							| 
									
										
										
										
											2011-09-30 18:52:19 -07:00
										 |  |  | 	case SCI_REQ_ATAPI_WAIT_H2D: | 
					
						
							|  |  |  | 	case SCI_REQ_ATAPI_WAIT_PIO_SETUP: | 
					
						
							|  |  |  | 	case SCI_REQ_ATAPI_WAIT_D2H: | 
					
						
							|  |  |  | 	case SCI_REQ_ATAPI_WAIT_TC_COMP: | 
					
						
							| 
									
										
										
										
											2012-03-08 22:41:50 -08:00
										 |  |  | 		/* Fall through and change state to ABORTING... */ | 
					
						
							| 
									
										
										
										
											2011-06-02 00:10:43 +00:00
										 |  |  | 	case SCI_REQ_TASK_WAIT_TC_RESP: | 
					
						
							| 
									
										
										
										
											2011-07-29 17:17:05 -07:00
										 |  |  | 		/* The task frame was already confirmed to have been
 | 
					
						
							|  |  |  | 		 * sent by the SCU HW.  Since the state machine is | 
					
						
							|  |  |  | 		 * now only waiting for the task response itself, | 
					
						
							|  |  |  | 		 * abort the request and complete it immediately | 
					
						
							|  |  |  | 		 * and don't wait for the task response. | 
					
						
							|  |  |  | 		 */ | 
					
						
							| 
									
										
										
										
											2011-06-27 14:57:03 -07:00
										 |  |  | 		sci_change_state(&ireq->sm, SCI_REQ_ABORTING); | 
					
						
							| 
									
										
										
										
											2012-03-08 22:41:50 -08:00
										 |  |  | 		/* Fall through and handle like ABORTING... */ | 
					
						
							| 
									
										
										
										
											2011-06-02 00:10:43 +00:00
										 |  |  | 	case SCI_REQ_ABORTING: | 
					
						
							| 
									
										
										
										
											2012-03-08 22:41:50 -08:00
										 |  |  | 		if (!isci_remote_device_is_safe_to_abort(ireq->target_device)) | 
					
						
							|  |  |  | 			set_bit(IREQ_PENDING_ABORT, &ireq->flags); | 
					
						
							|  |  |  | 		else | 
					
						
							|  |  |  | 			clear_bit(IREQ_PENDING_ABORT, &ireq->flags); | 
					
						
							|  |  |  | 		/* If the request is only waiting on the remote device
 | 
					
						
							|  |  |  | 		 * suspension, return SUCCESS so the caller will wait too. | 
					
						
							| 
									
										
										
										
											2011-07-29 17:17:05 -07:00
										 |  |  | 		 */ | 
					
						
							| 
									
										
										
										
											2012-03-08 22:41:50 -08:00
										 |  |  | 		return SCI_SUCCESS; | 
					
						
							| 
									
										
										
										
											2011-06-02 00:10:43 +00:00
										 |  |  | 	case SCI_REQ_COMPLETED: | 
					
						
							| 
									
										
										
										
											2011-05-10 02:39:11 -07:00
										 |  |  | 	default: | 
					
						
							| 
									
										
										
										
											2011-06-30 17:38:32 -07:00
										 |  |  | 		dev_warn(&ireq->owning_controller->pdev->dev, | 
					
						
							| 
									
										
										
										
											2011-05-10 02:39:11 -07:00
										 |  |  | 			 "%s: SCIC IO Request requested to abort while in wrong " | 
					
						
							| 
									
										
										
										
											2012-03-08 22:41:50 -08:00
										 |  |  | 			 "state %d\n", __func__, ireq->sm.current_state_id); | 
					
						
							| 
									
										
										
										
											2011-05-10 02:39:11 -07:00
										 |  |  | 		break; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2011-07-02 22:56:22 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 	return SCI_FAILURE_INVALID_STATE; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2011-07-02 22:56:22 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-30 19:14:33 -07:00
										 |  |  | enum sci_status sci_request_complete(struct isci_request *ireq) | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-05-11 08:29:56 -07:00
										 |  |  | 	enum sci_base_request_states state; | 
					
						
							| 
									
										
										
										
											2011-06-30 17:38:32 -07:00
										 |  |  | 	struct isci_host *ihost = ireq->owning_controller; | 
					
						
							| 
									
										
										
										
											2011-05-11 08:29:56 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-27 14:57:03 -07:00
										 |  |  | 	state = ireq->sm.current_state_id; | 
					
						
							| 
									
										
										
										
											2011-06-02 00:10:43 +00:00
										 |  |  | 	if (WARN_ONCE(state != SCI_REQ_COMPLETED, | 
					
						
							| 
									
										
										
										
											2012-02-10 01:18:44 -08:00
										 |  |  | 		      "isci: request completion from wrong state (%s)\n", | 
					
						
							|  |  |  | 		      req_state_name(state))) | 
					
						
							| 
									
										
										
										
											2011-05-11 08:29:56 -07:00
										 |  |  | 		return SCI_FAILURE_INVALID_STATE; | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-27 14:57:03 -07:00
										 |  |  | 	if (ireq->saved_rx_frame_index != SCU_INVALID_FRAME_INDEX) | 
					
						
							| 
									
										
										
										
											2011-06-30 19:14:33 -07:00
										 |  |  | 		sci_controller_release_frame(ihost, | 
					
						
							| 
									
										
										
										
											2011-06-27 14:57:03 -07:00
										 |  |  | 						  ireq->saved_rx_frame_index); | 
					
						
							| 
									
										
										
										
											2011-05-11 08:29:56 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* XXX can we just stop the machine and remove the 'final' state? */ | 
					
						
							| 
									
										
										
										
											2011-06-27 14:57:03 -07:00
										 |  |  | 	sci_change_state(&ireq->sm, SCI_REQ_FINAL); | 
					
						
							| 
									
										
										
										
											2011-05-11 08:29:56 -07:00
										 |  |  | 	return SCI_SUCCESS; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-30 19:14:33 -07:00
										 |  |  | enum sci_status sci_io_request_event_handler(struct isci_request *ireq, | 
					
						
							| 
									
										
										
										
											2011-05-11 08:29:56 -07:00
										 |  |  | 						  u32 event_code) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	enum sci_base_request_states state; | 
					
						
							| 
									
										
										
										
											2011-06-30 17:38:32 -07:00
										 |  |  | 	struct isci_host *ihost = ireq->owning_controller; | 
					
						
							| 
									
										
										
										
											2011-05-11 08:29:56 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-27 14:57:03 -07:00
										 |  |  | 	state = ireq->sm.current_state_id; | 
					
						
							| 
									
										
										
										
											2011-05-11 08:29:56 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-02 00:10:43 +00:00
										 |  |  | 	if (state != SCI_REQ_STP_PIO_DATA_IN) { | 
					
						
							| 
									
										
										
										
											2012-02-10 01:18:44 -08:00
										 |  |  | 		dev_warn(&ihost->pdev->dev, "%s: (%x) in wrong state %s\n", | 
					
						
							|  |  |  | 			 __func__, event_code, req_state_name(state)); | 
					
						
							| 
									
										
										
										
											2011-05-11 08:29:56 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		return SCI_FAILURE_INVALID_STATE; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	switch (scu_get_event_specifier(event_code)) { | 
					
						
							|  |  |  | 	case SCU_TASK_DONE_CRC_ERR << SCU_EVENT_SPECIFIC_CODE_SHIFT: | 
					
						
							|  |  |  | 		/* We are waiting for data and the SCU has R_ERR the data frame.
 | 
					
						
							|  |  |  | 		 * Go back to waiting for the D2H Register FIS | 
					
						
							|  |  |  | 		 */ | 
					
						
							| 
									
										
										
										
											2011-06-27 14:57:03 -07:00
										 |  |  | 		sci_change_state(&ireq->sm, SCI_REQ_STP_PIO_WAIT_FRAME); | 
					
						
							| 
									
										
										
										
											2011-05-11 08:29:56 -07:00
										 |  |  | 		return SCI_SUCCESS; | 
					
						
							|  |  |  | 	default: | 
					
						
							| 
									
										
										
										
											2011-06-30 17:38:32 -07:00
										 |  |  | 		dev_err(&ihost->pdev->dev, | 
					
						
							| 
									
										
										
										
											2011-05-11 08:29:56 -07:00
										 |  |  | 			"%s: pio request unexpected event %#x\n", | 
					
						
							|  |  |  | 			__func__, event_code); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		/* TODO Should we fail the PIO request when we get an
 | 
					
						
							|  |  |  | 		 * unexpected event? | 
					
						
							|  |  |  | 		 */ | 
					
						
							|  |  |  | 		return SCI_FAILURE; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2011-07-02 22:56:22 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * This function copies response data for requests returning response data | 
					
						
							|  |  |  |  *    instead of sense data. | 
					
						
							|  |  |  |  * @sci_req: This parameter specifies the request object for which to copy | 
					
						
							|  |  |  |  *    the response data. | 
					
						
							| 
									
										
										
										
											2011-07-02 22:56:22 -07:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2011-06-30 19:14:33 -07:00
										 |  |  | static void sci_io_request_copy_response(struct isci_request *ireq) | 
					
						
							| 
									
										
										
										
											2011-07-02 22:56:22 -07:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 	void *resp_buf; | 
					
						
							|  |  |  | 	u32 len; | 
					
						
							|  |  |  | 	struct ssp_response_iu *ssp_response; | 
					
						
							|  |  |  | 	struct isci_tmf *isci_tmf = isci_request_access_tmf(ireq); | 
					
						
							| 
									
										
										
										
											2011-07-02 22:56:22 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-27 14:57:03 -07:00
										 |  |  | 	ssp_response = &ireq->ssp.rsp; | 
					
						
							| 
									
										
										
										
											2011-07-02 22:56:22 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 	resp_buf = &isci_tmf->resp.resp_iu; | 
					
						
							| 
									
										
										
										
											2011-07-02 22:56:22 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 	len = min_t(u32, | 
					
						
							|  |  |  | 		    SSP_RESP_IU_MAX_SIZE, | 
					
						
							|  |  |  | 		    be32_to_cpu(ssp_response->response_data_len)); | 
					
						
							| 
									
										
										
										
											2011-07-02 22:56:22 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 	memcpy(resp_buf, ssp_response->resp_data, len); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2011-07-02 22:56:22 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-02 00:10:43 +00:00
										 |  |  | static enum sci_status | 
					
						
							| 
									
										
										
										
											2011-06-27 14:57:03 -07:00
										 |  |  | request_started_state_tc_event(struct isci_request *ireq, | 
					
						
							| 
									
										
										
										
											2011-06-02 00:10:43 +00:00
										 |  |  | 			       u32 completion_code) | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | { | 
					
						
							|  |  |  | 	struct ssp_response_iu *resp_iu; | 
					
						
							| 
									
										
										
										
											2011-05-11 08:27:47 -07:00
										 |  |  | 	u8 datapres; | 
					
						
							| 
									
										
										
										
											2011-07-02 22:56:22 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-11 08:27:47 -07:00
										 |  |  | 	/* TODO: Any SDMA return code of other than 0 is bad decode 0x003C0000
 | 
					
						
							|  |  |  | 	 * to determine SDMA status | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 	 */ | 
					
						
							|  |  |  | 	switch (SCU_GET_COMPLETION_TL_STATUS(completion_code)) { | 
					
						
							|  |  |  | 	case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_GOOD): | 
					
						
							| 
									
										
										
										
											2011-07-01 02:25:15 -07:00
										 |  |  | 		ireq->scu_status = SCU_TASK_DONE_GOOD; | 
					
						
							|  |  |  | 		ireq->sci_status = SCI_SUCCESS; | 
					
						
							| 
									
										
										
										
											2011-07-02 22:56:22 -07:00
										 |  |  | 		break; | 
					
						
							| 
									
										
										
										
											2011-05-11 08:27:47 -07:00
										 |  |  | 	case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_EARLY_RESP): { | 
					
						
							|  |  |  | 		/* There are times when the SCU hardware will return an early
 | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 		 * response because the io request specified more data than is | 
					
						
							|  |  |  | 		 * returned by the target device (mode pages, inquiry data, | 
					
						
							|  |  |  | 		 * etc.).  We must check the response stats to see if this is | 
					
						
							|  |  |  | 		 * truly a failed request or a good request that just got | 
					
						
							|  |  |  | 		 * completed early. | 
					
						
							|  |  |  | 		 */ | 
					
						
							| 
									
										
										
										
											2011-06-27 14:57:03 -07:00
										 |  |  | 		struct ssp_response_iu *resp = &ireq->ssp.rsp; | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 		ssize_t word_cnt = SSP_RESP_IU_MAX_SIZE / sizeof(u32); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-27 14:57:03 -07:00
										 |  |  | 		sci_swab32_cpy(&ireq->ssp.rsp, | 
					
						
							|  |  |  | 			       &ireq->ssp.rsp, | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 			       word_cnt); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (resp->status == 0) { | 
					
						
							| 
									
										
										
										
											2011-07-01 02:25:15 -07:00
										 |  |  | 			ireq->scu_status = SCU_TASK_DONE_GOOD; | 
					
						
							|  |  |  | 			ireq->sci_status = SCI_SUCCESS_IO_DONE_EARLY; | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 		} else { | 
					
						
							| 
									
										
										
										
											2011-07-01 02:25:15 -07:00
										 |  |  | 			ireq->scu_status = SCU_TASK_DONE_CHECK_RESPONSE; | 
					
						
							|  |  |  | 			ireq->sci_status = SCI_FAILURE_IO_RESPONSE_VALID; | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2011-05-11 08:27:47 -07:00
										 |  |  | 		break; | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2011-05-11 08:27:47 -07:00
										 |  |  | 	case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_CHECK_RESPONSE): { | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 		ssize_t word_cnt = SSP_RESP_IU_MAX_SIZE / sizeof(u32); | 
					
						
							| 
									
										
										
										
											2011-07-02 22:56:22 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-27 14:57:03 -07:00
										 |  |  | 		sci_swab32_cpy(&ireq->ssp.rsp, | 
					
						
							|  |  |  | 			       &ireq->ssp.rsp, | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 			       word_cnt); | 
					
						
							| 
									
										
										
										
											2011-07-02 22:56:22 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-07-01 02:25:15 -07:00
										 |  |  | 		ireq->scu_status = SCU_TASK_DONE_CHECK_RESPONSE; | 
					
						
							|  |  |  | 		ireq->sci_status = SCI_FAILURE_IO_RESPONSE_VALID; | 
					
						
							| 
									
										
										
										
											2011-07-02 22:56:22 -07:00
										 |  |  | 		break; | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2011-07-02 22:56:22 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 	case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_RESP_LEN_ERR): | 
					
						
							| 
									
										
										
										
											2011-05-11 08:27:47 -07:00
										 |  |  | 		/* TODO With TASK_DONE_RESP_LEN_ERR is the response frame
 | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 		 * guaranteed to be received before this completion status is | 
					
						
							|  |  |  | 		 * posted? | 
					
						
							|  |  |  | 		 */ | 
					
						
							| 
									
										
										
										
											2011-06-27 14:57:03 -07:00
										 |  |  | 		resp_iu = &ireq->ssp.rsp; | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 		datapres = resp_iu->datapres; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-11 08:27:47 -07:00
										 |  |  | 		if (datapres == 1 || datapres == 2) { | 
					
						
							| 
									
										
										
										
											2011-07-01 02:25:15 -07:00
										 |  |  | 			ireq->scu_status = SCU_TASK_DONE_CHECK_RESPONSE; | 
					
						
							|  |  |  | 			ireq->sci_status = SCI_FAILURE_IO_RESPONSE_VALID; | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			ireq->scu_status = SCU_TASK_DONE_GOOD; | 
					
						
							|  |  |  | 			ireq->sci_status = SCI_SUCCESS; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2011-07-02 22:56:22 -07:00
										 |  |  | 		break; | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 	/* only stp device gets suspended. */ | 
					
						
							|  |  |  | 	case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_ACK_NAK_TO): | 
					
						
							|  |  |  | 	case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_LL_PERR): | 
					
						
							|  |  |  | 	case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_NAK_ERR): | 
					
						
							|  |  |  | 	case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_DATA_LEN_ERR): | 
					
						
							|  |  |  | 	case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_LL_ABORT_ERR): | 
					
						
							|  |  |  | 	case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_XR_WD_LEN): | 
					
						
							|  |  |  | 	case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_MAX_PLD_ERR): | 
					
						
							|  |  |  | 	case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_UNEXP_RESP): | 
					
						
							|  |  |  | 	case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_UNEXP_SDBFIS): | 
					
						
							|  |  |  | 	case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_REG_ERR): | 
					
						
							|  |  |  | 	case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_SDB_ERR): | 
					
						
							| 
									
										
										
										
											2012-02-01 00:44:14 -08:00
										 |  |  | 		if (ireq->protocol == SAS_PROTOCOL_STP) { | 
					
						
							| 
									
										
										
										
											2011-07-01 02:25:15 -07:00
										 |  |  | 			ireq->scu_status = SCU_GET_COMPLETION_TL_STATUS(completion_code) >> | 
					
						
							|  |  |  | 					   SCU_COMPLETION_TL_STATUS_SHIFT; | 
					
						
							|  |  |  | 			ireq->sci_status = SCI_FAILURE_REMOTE_DEVICE_RESET_REQUIRED; | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 		} else { | 
					
						
							| 
									
										
										
										
											2011-07-01 02:25:15 -07:00
										 |  |  | 			ireq->scu_status = SCU_GET_COMPLETION_TL_STATUS(completion_code) >> | 
					
						
							|  |  |  | 					   SCU_COMPLETION_TL_STATUS_SHIFT; | 
					
						
							|  |  |  | 			ireq->sci_status = SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR; | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2011-07-02 22:56:22 -07:00
										 |  |  | 		break; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 	/* both stp/ssp device gets suspended */ | 
					
						
							|  |  |  | 	case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_LF_ERR): | 
					
						
							|  |  |  | 	case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_OPEN_REJECT_WRONG_DESTINATION): | 
					
						
							|  |  |  | 	case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_OPEN_REJECT_RESERVED_ABANDON_1): | 
					
						
							|  |  |  | 	case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_OPEN_REJECT_RESERVED_ABANDON_2): | 
					
						
							|  |  |  | 	case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_OPEN_REJECT_RESERVED_ABANDON_3): | 
					
						
							|  |  |  | 	case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_OPEN_REJECT_BAD_DESTINATION): | 
					
						
							|  |  |  | 	case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_OPEN_REJECT_ZONE_VIOLATION): | 
					
						
							|  |  |  | 	case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_OPEN_REJECT_STP_RESOURCES_BUSY): | 
					
						
							|  |  |  | 	case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_OPEN_REJECT_PROTOCOL_NOT_SUPPORTED): | 
					
						
							|  |  |  | 	case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_OPEN_REJECT_CONNECTION_RATE_NOT_SUPPORTED): | 
					
						
							| 
									
										
										
										
											2011-07-01 02:25:15 -07:00
										 |  |  | 		ireq->scu_status = SCU_GET_COMPLETION_TL_STATUS(completion_code) >> | 
					
						
							|  |  |  | 				   SCU_COMPLETION_TL_STATUS_SHIFT; | 
					
						
							|  |  |  | 		ireq->sci_status = SCI_FAILURE_REMOTE_DEVICE_RESET_REQUIRED; | 
					
						
							| 
									
										
										
										
											2011-07-02 22:56:22 -07:00
										 |  |  | 		break; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 	/* neither ssp nor stp gets suspended. */ | 
					
						
							|  |  |  | 	case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_NAK_CMD_ERR): | 
					
						
							|  |  |  | 	case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_UNEXP_XR): | 
					
						
							|  |  |  | 	case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_XR_IU_LEN_ERR): | 
					
						
							|  |  |  | 	case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_SDMA_ERR): | 
					
						
							|  |  |  | 	case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_OFFSET_ERR): | 
					
						
							|  |  |  | 	case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_EXCESS_DATA): | 
					
						
							|  |  |  | 	case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_SMP_RESP_TO_ERR): | 
					
						
							|  |  |  | 	case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_SMP_UFI_ERR): | 
					
						
							|  |  |  | 	case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_SMP_FRM_TYPE_ERR): | 
					
						
							|  |  |  | 	case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_SMP_LL_RX_ERR): | 
					
						
							|  |  |  | 	case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_UNEXP_DATA): | 
					
						
							|  |  |  | 	case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_OPEN_FAIL): | 
					
						
							|  |  |  | 	case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_VIIT_ENTRY_NV): | 
					
						
							|  |  |  | 	case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_IIT_ENTRY_NV): | 
					
						
							|  |  |  | 	case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_RNCNV_OUTBOUND): | 
					
						
							| 
									
										
										
										
											2011-07-02 22:56:22 -07:00
										 |  |  | 	default: | 
					
						
							| 
									
										
										
										
											2011-07-01 02:25:15 -07:00
										 |  |  | 		ireq->scu_status = SCU_GET_COMPLETION_TL_STATUS(completion_code) >> | 
					
						
							|  |  |  | 				   SCU_COMPLETION_TL_STATUS_SHIFT; | 
					
						
							|  |  |  | 		ireq->sci_status = SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR; | 
					
						
							| 
									
										
										
										
											2011-07-02 22:56:22 -07:00
										 |  |  | 		break; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/*
 | 
					
						
							|  |  |  | 	 * TODO: This is probably wrong for ACK/NAK timeout conditions | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* In all cases we will treat this as the completion of the IO req. */ | 
					
						
							| 
									
										
										
										
											2011-06-27 14:57:03 -07:00
										 |  |  | 	sci_change_state(&ireq->sm, SCI_REQ_COMPLETED); | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 	return SCI_SUCCESS; | 
					
						
							| 
									
										
										
										
											2011-07-02 22:56:22 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-02 00:10:43 +00:00
										 |  |  | static enum sci_status | 
					
						
							| 
									
										
										
										
											2011-06-27 14:57:03 -07:00
										 |  |  | request_aborting_state_tc_event(struct isci_request *ireq, | 
					
						
							| 
									
										
										
										
											2011-06-02 00:10:43 +00:00
										 |  |  | 				u32 completion_code) | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | { | 
					
						
							|  |  |  | 	switch (SCU_GET_COMPLETION_TL_STATUS(completion_code)) { | 
					
						
							|  |  |  | 	case (SCU_TASK_DONE_GOOD << SCU_COMPLETION_TL_STATUS_SHIFT): | 
					
						
							|  |  |  | 	case (SCU_TASK_DONE_TASK_ABORT << SCU_COMPLETION_TL_STATUS_SHIFT): | 
					
						
							| 
									
										
										
										
											2011-07-01 02:25:15 -07:00
										 |  |  | 		ireq->scu_status = SCU_TASK_DONE_TASK_ABORT; | 
					
						
							|  |  |  | 		ireq->sci_status = SCI_FAILURE_IO_TERMINATED; | 
					
						
							| 
									
										
										
										
											2011-06-27 14:57:03 -07:00
										 |  |  | 		sci_change_state(&ireq->sm, SCI_REQ_COMPLETED); | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 		break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	default: | 
					
						
							| 
									
										
										
										
											2011-05-11 08:27:47 -07:00
										 |  |  | 		/* Unless we get some strange error wait for the task abort to complete
 | 
					
						
							|  |  |  | 		 * TODO: Should there be a state change for this completion? | 
					
						
							|  |  |  | 		 */ | 
					
						
							| 
									
										
										
										
											2011-07-02 22:56:22 -07:00
										 |  |  | 		break; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return SCI_SUCCESS; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-27 14:57:03 -07:00
										 |  |  | static enum sci_status ssp_task_request_await_tc_event(struct isci_request *ireq, | 
					
						
							| 
									
										
										
										
											2011-05-11 08:27:47 -07:00
										 |  |  | 						       u32 completion_code) | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:47 -07:00
										 |  |  | { | 
					
						
							|  |  |  | 	switch (SCU_GET_COMPLETION_TL_STATUS(completion_code)) { | 
					
						
							|  |  |  | 	case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_GOOD): | 
					
						
							| 
									
										
										
										
											2011-07-01 02:25:15 -07:00
										 |  |  | 		ireq->scu_status = SCU_TASK_DONE_GOOD; | 
					
						
							|  |  |  | 		ireq->sci_status = SCI_SUCCESS; | 
					
						
							| 
									
										
										
										
											2011-06-27 14:57:03 -07:00
										 |  |  | 		sci_change_state(&ireq->sm, SCI_REQ_TASK_WAIT_TC_RESP); | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:47 -07:00
										 |  |  | 		break; | 
					
						
							|  |  |  | 	case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_ACK_NAK_TO): | 
					
						
							| 
									
										
										
										
											2011-05-11 08:27:47 -07:00
										 |  |  | 		/* Currently, the decision is to simply allow the task request
 | 
					
						
							|  |  |  | 		 * to timeout if the task IU wasn't received successfully. | 
					
						
							|  |  |  | 		 * There is a potential for receiving multiple task responses if | 
					
						
							|  |  |  | 		 * we decide to send the task IU again. | 
					
						
							|  |  |  | 		 */ | 
					
						
							| 
									
										
										
										
											2011-06-30 17:38:32 -07:00
										 |  |  | 		dev_warn(&ireq->owning_controller->pdev->dev, | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:47 -07:00
										 |  |  | 			 "%s: TaskRequest:0x%p CompletionCode:%x - " | 
					
						
							| 
									
										
										
										
											2011-06-27 14:57:03 -07:00
										 |  |  | 			 "ACK/NAK timeout\n", __func__, ireq, | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:47 -07:00
										 |  |  | 			 completion_code); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-27 14:57:03 -07:00
										 |  |  | 		sci_change_state(&ireq->sm, SCI_REQ_TASK_WAIT_TC_RESP); | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:47 -07:00
										 |  |  | 		break; | 
					
						
							|  |  |  | 	default: | 
					
						
							| 
									
										
										
										
											2011-06-02 00:10:43 +00:00
										 |  |  | 		/*
 | 
					
						
							|  |  |  | 		 * All other completion status cause the IO to be complete. | 
					
						
							|  |  |  | 		 * If a NAK was received, then it is up to the user to retry | 
					
						
							|  |  |  | 		 * the request. | 
					
						
							| 
									
										
										
										
											2011-05-11 08:27:47 -07:00
										 |  |  | 		 */ | 
					
						
							| 
									
										
										
										
											2011-07-01 02:25:15 -07:00
										 |  |  | 		ireq->scu_status = SCU_NORMALIZE_COMPLETION_STATUS(completion_code); | 
					
						
							|  |  |  | 		ireq->sci_status = SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR; | 
					
						
							| 
									
										
										
										
											2011-06-27 14:57:03 -07:00
										 |  |  | 		sci_change_state(&ireq->sm, SCI_REQ_COMPLETED); | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:47 -07:00
										 |  |  | 		break; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return SCI_SUCCESS; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-02 00:10:43 +00:00
										 |  |  | static enum sci_status | 
					
						
							| 
									
										
										
										
											2011-06-27 14:57:03 -07:00
										 |  |  | smp_request_await_response_tc_event(struct isci_request *ireq, | 
					
						
							| 
									
										
										
										
											2011-06-02 00:10:43 +00:00
										 |  |  | 				    u32 completion_code) | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:48 -07:00
										 |  |  | { | 
					
						
							|  |  |  | 	switch (SCU_GET_COMPLETION_TL_STATUS(completion_code)) { | 
					
						
							|  |  |  | 	case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_GOOD): | 
					
						
							| 
									
										
										
										
											2011-05-11 08:27:47 -07:00
										 |  |  | 		/* In the AWAIT RESPONSE state, any TC completion is
 | 
					
						
							|  |  |  | 		 * unexpected.  but if the TC has success status, we | 
					
						
							|  |  |  | 		 * complete the IO anyway. | 
					
						
							|  |  |  | 		 */ | 
					
						
							| 
									
										
										
										
											2011-07-01 02:25:15 -07:00
										 |  |  | 		ireq->scu_status = SCU_TASK_DONE_GOOD; | 
					
						
							|  |  |  | 		ireq->sci_status = SCI_SUCCESS; | 
					
						
							| 
									
										
										
										
											2011-06-27 14:57:03 -07:00
										 |  |  | 		sci_change_state(&ireq->sm, SCI_REQ_COMPLETED); | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:48 -07:00
										 |  |  | 		break; | 
					
						
							|  |  |  | 	case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_SMP_RESP_TO_ERR): | 
					
						
							|  |  |  | 	case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_SMP_UFI_ERR): | 
					
						
							|  |  |  | 	case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_SMP_FRM_TYPE_ERR): | 
					
						
							|  |  |  | 	case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_SMP_LL_RX_ERR): | 
					
						
							| 
									
										
										
										
											2011-05-11 08:27:47 -07:00
										 |  |  | 		/* These status has been seen in a specific LSI
 | 
					
						
							|  |  |  | 		 * expander, which sometimes is not able to send smp | 
					
						
							|  |  |  | 		 * response within 2 ms. This causes our hardware break | 
					
						
							|  |  |  | 		 * the connection and set TC completion with one of | 
					
						
							|  |  |  | 		 * these SMP_XXX_XX_ERR status. For these type of error, | 
					
						
							| 
									
										
										
										
											2011-06-30 17:38:32 -07:00
										 |  |  | 		 * we ask ihost user to retry the request. | 
					
						
							| 
									
										
										
										
											2011-05-11 08:27:47 -07:00
										 |  |  | 		 */ | 
					
						
							| 
									
										
										
										
											2011-07-01 02:25:15 -07:00
										 |  |  | 		ireq->scu_status = SCU_TASK_DONE_SMP_RESP_TO_ERR; | 
					
						
							|  |  |  | 		ireq->sci_status = SCI_FAILURE_RETRY_REQUIRED; | 
					
						
							| 
									
										
										
										
											2011-06-27 14:57:03 -07:00
										 |  |  | 		sci_change_state(&ireq->sm, SCI_REQ_COMPLETED); | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:48 -07:00
										 |  |  | 		break; | 
					
						
							|  |  |  | 	default: | 
					
						
							| 
									
										
										
										
											2011-05-11 08:27:47 -07:00
										 |  |  | 		/* All other completion status cause the IO to be complete.  If a NAK
 | 
					
						
							|  |  |  | 		 * was received, then it is up to the user to retry the request | 
					
						
							|  |  |  | 		 */ | 
					
						
							| 
									
										
										
										
											2011-07-01 02:25:15 -07:00
										 |  |  | 		ireq->scu_status = SCU_NORMALIZE_COMPLETION_STATUS(completion_code); | 
					
						
							|  |  |  | 		ireq->sci_status = SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR; | 
					
						
							| 
									
										
										
										
											2011-06-27 14:57:03 -07:00
										 |  |  | 		sci_change_state(&ireq->sm, SCI_REQ_COMPLETED); | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:48 -07:00
										 |  |  | 		break; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return SCI_SUCCESS; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-02 00:10:43 +00:00
										 |  |  | static enum sci_status | 
					
						
							| 
									
										
										
										
											2011-06-27 14:57:03 -07:00
										 |  |  | smp_request_await_tc_event(struct isci_request *ireq, | 
					
						
							| 
									
										
										
										
											2011-06-02 00:10:43 +00:00
										 |  |  | 			   u32 completion_code) | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:49 -07:00
										 |  |  | { | 
					
						
							|  |  |  | 	switch (SCU_GET_COMPLETION_TL_STATUS(completion_code)) { | 
					
						
							|  |  |  | 	case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_GOOD): | 
					
						
							| 
									
										
										
										
											2011-07-01 02:25:15 -07:00
										 |  |  | 		ireq->scu_status = SCU_TASK_DONE_GOOD; | 
					
						
							|  |  |  | 		ireq->sci_status = SCI_SUCCESS; | 
					
						
							| 
									
										
										
										
											2011-06-27 14:57:03 -07:00
										 |  |  | 		sci_change_state(&ireq->sm, SCI_REQ_COMPLETED); | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:49 -07:00
										 |  |  | 		break; | 
					
						
							|  |  |  | 	default: | 
					
						
							| 
									
										
										
										
											2011-05-11 08:27:47 -07:00
										 |  |  | 		/* All other completion status cause the IO to be
 | 
					
						
							|  |  |  | 		 * complete.  If a NAK was received, then it is up to | 
					
						
							|  |  |  | 		 * the user to retry the request. | 
					
						
							|  |  |  | 		 */ | 
					
						
							| 
									
										
										
										
											2011-07-01 02:25:15 -07:00
										 |  |  | 		ireq->scu_status = SCU_NORMALIZE_COMPLETION_STATUS(completion_code); | 
					
						
							|  |  |  | 		ireq->sci_status = SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR; | 
					
						
							| 
									
										
										
										
											2011-06-27 14:57:03 -07:00
										 |  |  | 		sci_change_state(&ireq->sm, SCI_REQ_COMPLETED); | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:49 -07:00
										 |  |  | 		break; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return SCI_SUCCESS; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-27 11:56:41 -07:00
										 |  |  | static struct scu_sgl_element *pio_sgl_next(struct isci_stp_request *stp_req) | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:49 -07:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-06-28 13:47:09 -07:00
										 |  |  | 	struct scu_sgl_element *sgl; | 
					
						
							|  |  |  | 	struct scu_sgl_element_pair *sgl_pair; | 
					
						
							| 
									
										
										
										
											2011-06-27 14:57:03 -07:00
										 |  |  | 	struct isci_request *ireq = to_ireq(stp_req); | 
					
						
							| 
									
										
										
										
											2011-06-27 11:56:41 -07:00
										 |  |  | 	struct isci_stp_pio_sgl *pio_sgl = &stp_req->sgl; | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:49 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-27 14:57:03 -07:00
										 |  |  | 	sgl_pair = to_sgl_element_pair(ireq, pio_sgl->index); | 
					
						
							| 
									
										
										
										
											2011-06-28 13:47:09 -07:00
										 |  |  | 	if (!sgl_pair) | 
					
						
							|  |  |  | 		sgl = NULL; | 
					
						
							| 
									
										
										
										
											2011-06-27 11:56:41 -07:00
										 |  |  | 	else if (pio_sgl->set == SCU_SGL_ELEMENT_PAIR_A) { | 
					
						
							| 
									
										
										
										
											2011-06-28 13:47:09 -07:00
										 |  |  | 		if (sgl_pair->B.address_lower == 0 && | 
					
						
							|  |  |  | 		    sgl_pair->B.address_upper == 0) { | 
					
						
							|  |  |  | 			sgl = NULL; | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:49 -07:00
										 |  |  | 		} else { | 
					
						
							| 
									
										
										
										
											2011-06-27 11:56:41 -07:00
										 |  |  | 			pio_sgl->set = SCU_SGL_ELEMENT_PAIR_B; | 
					
						
							| 
									
										
										
										
											2011-06-28 13:47:09 -07:00
										 |  |  | 			sgl = &sgl_pair->B; | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:49 -07:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											2011-06-28 13:47:09 -07:00
										 |  |  | 		if (sgl_pair->next_pair_lower == 0 && | 
					
						
							|  |  |  | 		    sgl_pair->next_pair_upper == 0) { | 
					
						
							|  |  |  | 			sgl = NULL; | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:49 -07:00
										 |  |  | 		} else { | 
					
						
							| 
									
										
										
										
											2011-06-27 11:56:41 -07:00
										 |  |  | 			pio_sgl->index++; | 
					
						
							|  |  |  | 			pio_sgl->set = SCU_SGL_ELEMENT_PAIR_A; | 
					
						
							| 
									
										
										
										
											2011-06-27 14:57:03 -07:00
										 |  |  | 			sgl_pair = to_sgl_element_pair(ireq, pio_sgl->index); | 
					
						
							| 
									
										
										
										
											2011-06-28 13:47:09 -07:00
										 |  |  | 			sgl = &sgl_pair->A; | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:49 -07:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-28 13:47:09 -07:00
										 |  |  | 	return sgl; | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:49 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-02 00:10:43 +00:00
										 |  |  | static enum sci_status | 
					
						
							| 
									
										
										
										
											2011-06-27 14:57:03 -07:00
										 |  |  | stp_request_non_data_await_h2d_tc_event(struct isci_request *ireq, | 
					
						
							| 
									
										
										
										
											2011-06-02 00:10:43 +00:00
										 |  |  | 					u32 completion_code) | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:49 -07:00
										 |  |  | { | 
					
						
							|  |  |  | 	switch (SCU_GET_COMPLETION_TL_STATUS(completion_code)) { | 
					
						
							|  |  |  | 	case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_GOOD): | 
					
						
							| 
									
										
										
										
											2011-07-01 02:25:15 -07:00
										 |  |  | 		ireq->scu_status = SCU_TASK_DONE_GOOD; | 
					
						
							|  |  |  | 		ireq->sci_status = SCI_SUCCESS; | 
					
						
							| 
									
										
										
										
											2011-06-27 14:57:03 -07:00
										 |  |  | 		sci_change_state(&ireq->sm, SCI_REQ_STP_NON_DATA_WAIT_D2H); | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:49 -07:00
										 |  |  | 		break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	default: | 
					
						
							| 
									
										
										
										
											2011-05-11 08:27:47 -07:00
										 |  |  | 		/* All other completion status cause the IO to be
 | 
					
						
							|  |  |  | 		 * complete.  If a NAK was received, then it is up to | 
					
						
							|  |  |  | 		 * the user to retry the request. | 
					
						
							|  |  |  | 		 */ | 
					
						
							| 
									
										
										
										
											2011-07-01 02:25:15 -07:00
										 |  |  | 		ireq->scu_status = SCU_NORMALIZE_COMPLETION_STATUS(completion_code); | 
					
						
							|  |  |  | 		ireq->sci_status = SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR; | 
					
						
							| 
									
										
										
										
											2011-06-27 14:57:03 -07:00
										 |  |  | 		sci_change_state(&ireq->sm, SCI_REQ_COMPLETED); | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:49 -07:00
										 |  |  | 		break; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return SCI_SUCCESS; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define SCU_MAX_FRAME_BUFFER_SIZE  0x400  /* 1K is the maximum SCU frame data payload */
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* transmit DATA_FIS from (current sgl + offset) for input
 | 
					
						
							|  |  |  |  * parameter length. current sgl and offset is alreay stored in the IO request | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2011-06-30 19:14:33 -07:00
										 |  |  | static enum sci_status sci_stp_request_pio_data_out_trasmit_data_frame( | 
					
						
							| 
									
										
										
										
											2011-06-27 14:57:03 -07:00
										 |  |  | 	struct isci_request *ireq, | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:49 -07:00
										 |  |  | 	u32 length) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2011-06-27 14:57:03 -07:00
										 |  |  | 	struct isci_stp_request *stp_req = &ireq->stp.req; | 
					
						
							|  |  |  | 	struct scu_task_context *task_context = ireq->tc; | 
					
						
							| 
									
										
										
										
											2011-06-28 13:47:09 -07:00
										 |  |  | 	struct scu_sgl_element_pair *sgl_pair; | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:49 -07:00
										 |  |  | 	struct scu_sgl_element *current_sgl; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* Recycle the TC and reconstruct it for sending out DATA FIS containing
 | 
					
						
							|  |  |  | 	 * for the data from current_sgl+offset for the input length | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2011-06-27 14:57:03 -07:00
										 |  |  | 	sgl_pair = to_sgl_element_pair(ireq, stp_req->sgl.index); | 
					
						
							| 
									
										
										
										
											2011-06-27 11:56:41 -07:00
										 |  |  | 	if (stp_req->sgl.set == SCU_SGL_ELEMENT_PAIR_A) | 
					
						
							| 
									
										
										
										
											2011-06-28 13:47:09 -07:00
										 |  |  | 		current_sgl = &sgl_pair->A; | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:49 -07:00
										 |  |  | 	else | 
					
						
							| 
									
										
										
										
											2011-06-28 13:47:09 -07:00
										 |  |  | 		current_sgl = &sgl_pair->B; | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:49 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* update the TC */ | 
					
						
							|  |  |  | 	task_context->command_iu_upper = current_sgl->address_upper; | 
					
						
							|  |  |  | 	task_context->command_iu_lower = current_sgl->address_lower; | 
					
						
							|  |  |  | 	task_context->transfer_length_bytes = length; | 
					
						
							|  |  |  | 	task_context->type.stp.fis_type = FIS_DATA; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* send the new TC out. */ | 
					
						
							| 
									
										
										
										
											2011-06-30 19:14:33 -07:00
										 |  |  | 	return sci_controller_continue_io(ireq); | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:49 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-30 19:14:33 -07:00
										 |  |  | static enum sci_status sci_stp_request_pio_data_out_transmit_data(struct isci_request *ireq) | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:49 -07:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-06-27 14:57:03 -07:00
										 |  |  | 	struct isci_stp_request *stp_req = &ireq->stp.req; | 
					
						
							| 
									
										
										
										
											2011-06-28 13:47:09 -07:00
										 |  |  | 	struct scu_sgl_element_pair *sgl_pair; | 
					
						
							| 
									
										
										
										
											2011-09-30 18:52:19 -07:00
										 |  |  | 	enum sci_status status = SCI_SUCCESS; | 
					
						
							| 
									
										
										
										
											2011-06-27 11:56:41 -07:00
										 |  |  | 	struct scu_sgl_element *sgl; | 
					
						
							|  |  |  | 	u32 offset; | 
					
						
							|  |  |  | 	u32 len = 0; | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:49 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-27 11:56:41 -07:00
										 |  |  | 	offset = stp_req->sgl.offset; | 
					
						
							| 
									
										
										
										
											2011-06-27 14:57:03 -07:00
										 |  |  | 	sgl_pair = to_sgl_element_pair(ireq, stp_req->sgl.index); | 
					
						
							| 
									
										
										
										
											2011-06-28 13:47:09 -07:00
										 |  |  | 	if (WARN_ONCE(!sgl_pair, "%s: null sgl element", __func__)) | 
					
						
							|  |  |  | 		return SCI_FAILURE; | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:49 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-27 11:56:41 -07:00
										 |  |  | 	if (stp_req->sgl.set == SCU_SGL_ELEMENT_PAIR_A) { | 
					
						
							|  |  |  | 		sgl = &sgl_pair->A; | 
					
						
							|  |  |  | 		len = sgl_pair->A.length - offset; | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:49 -07:00
										 |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											2011-06-27 11:56:41 -07:00
										 |  |  | 		sgl = &sgl_pair->B; | 
					
						
							|  |  |  | 		len = sgl_pair->B.length - offset; | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:49 -07:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-27 11:56:41 -07:00
										 |  |  | 	if (stp_req->pio_len == 0) | 
					
						
							|  |  |  | 		return SCI_SUCCESS; | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:49 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-27 11:56:41 -07:00
										 |  |  | 	if (stp_req->pio_len >= len) { | 
					
						
							| 
									
										
										
										
											2011-06-30 19:14:33 -07:00
										 |  |  | 		status = sci_stp_request_pio_data_out_trasmit_data_frame(ireq, len); | 
					
						
							| 
									
										
										
										
											2011-06-27 11:56:41 -07:00
										 |  |  | 		if (status != SCI_SUCCESS) | 
					
						
							|  |  |  | 			return status; | 
					
						
							|  |  |  | 		stp_req->pio_len -= len; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		/* update the current sgl, offset and save for future */ | 
					
						
							|  |  |  | 		sgl = pio_sgl_next(stp_req); | 
					
						
							|  |  |  | 		offset = 0; | 
					
						
							|  |  |  | 	} else if (stp_req->pio_len < len) { | 
					
						
							| 
									
										
										
										
											2011-06-30 19:14:33 -07:00
										 |  |  | 		sci_stp_request_pio_data_out_trasmit_data_frame(ireq, stp_req->pio_len); | 
					
						
							| 
									
										
										
										
											2011-06-27 11:56:41 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		/* Sgl offset will be adjusted and saved for future */ | 
					
						
							|  |  |  | 		offset += stp_req->pio_len; | 
					
						
							|  |  |  | 		sgl->address_lower += stp_req->pio_len; | 
					
						
							|  |  |  | 		stp_req->pio_len = 0; | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:49 -07:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-27 11:56:41 -07:00
										 |  |  | 	stp_req->sgl.offset = offset; | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:49 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return status; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /**
 | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * @stp_request: The request that is used for the SGL processing. | 
					
						
							|  |  |  |  * @data_buffer: The buffer of data to be copied. | 
					
						
							|  |  |  |  * @length: The length of the data transfer. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Copy the data from the buffer for the length specified to the IO reqeust SGL | 
					
						
							|  |  |  |  * specified data region. enum sci_status | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | static enum sci_status | 
					
						
							| 
									
										
										
										
											2011-06-30 19:14:33 -07:00
										 |  |  | sci_stp_request_pio_data_in_copy_data_buffer(struct isci_stp_request *stp_req, | 
					
						
							| 
									
										
										
										
											2011-09-30 18:52:19 -07:00
										 |  |  | 					     u8 *data_buf, u32 len) | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:49 -07:00
										 |  |  | { | 
					
						
							|  |  |  | 	struct isci_request *ireq; | 
					
						
							|  |  |  | 	u8 *src_addr; | 
					
						
							|  |  |  | 	int copy_len; | 
					
						
							|  |  |  | 	struct sas_task *task; | 
					
						
							|  |  |  | 	struct scatterlist *sg; | 
					
						
							|  |  |  | 	void *kaddr; | 
					
						
							|  |  |  | 	int total_len = len; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-27 14:57:03 -07:00
										 |  |  | 	ireq = to_ireq(stp_req); | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:49 -07:00
										 |  |  | 	task = isci_request_access_task(ireq); | 
					
						
							|  |  |  | 	src_addr = data_buf; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (task->num_scatter > 0) { | 
					
						
							|  |  |  | 		sg = task->scatter; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		while (total_len > 0) { | 
					
						
							|  |  |  | 			struct page *page = sg_page(sg); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			copy_len = min_t(int, total_len, sg_dma_len(sg)); | 
					
						
							| 
									
										
										
										
											2011-11-25 23:14:23 +08:00
										 |  |  | 			kaddr = kmap_atomic(page); | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:49 -07:00
										 |  |  | 			memcpy(kaddr + sg->offset, src_addr, copy_len); | 
					
						
							| 
									
										
										
										
											2011-11-25 23:14:23 +08:00
										 |  |  | 			kunmap_atomic(kaddr); | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:49 -07:00
										 |  |  | 			total_len -= copy_len; | 
					
						
							|  |  |  | 			src_addr += copy_len; | 
					
						
							|  |  |  | 			sg = sg_next(sg); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		BUG_ON(task->total_xfer_len < total_len); | 
					
						
							|  |  |  | 		memcpy(task->scatter, src_addr, total_len); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return SCI_SUCCESS; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /**
 | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * @sci_req: The PIO DATA IN request that is to receive the data. | 
					
						
							|  |  |  |  * @data_buffer: The buffer to copy from. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Copy the data buffer to the io request data region. enum sci_status | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2011-06-30 19:14:33 -07:00
										 |  |  | static enum sci_status sci_stp_request_pio_data_in_copy_data( | 
					
						
							| 
									
										
										
										
											2011-06-27 11:56:41 -07:00
										 |  |  | 	struct isci_stp_request *stp_req, | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:49 -07:00
										 |  |  | 	u8 *data_buffer) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	enum sci_status status; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/*
 | 
					
						
							|  |  |  | 	 * If there is less than 1K remaining in the transfer request | 
					
						
							|  |  |  | 	 * copy just the data for the transfer */ | 
					
						
							| 
									
										
										
										
											2011-06-27 11:56:41 -07:00
										 |  |  | 	if (stp_req->pio_len < SCU_MAX_FRAME_BUFFER_SIZE) { | 
					
						
							| 
									
										
										
										
											2011-06-30 19:14:33 -07:00
										 |  |  | 		status = sci_stp_request_pio_data_in_copy_data_buffer( | 
					
						
							| 
									
										
										
										
											2011-06-27 11:56:41 -07:00
										 |  |  | 			stp_req, data_buffer, stp_req->pio_len); | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:49 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		if (status == SCI_SUCCESS) | 
					
						
							| 
									
										
										
										
											2011-06-27 11:56:41 -07:00
										 |  |  | 			stp_req->pio_len = 0; | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:49 -07:00
										 |  |  | 	} else { | 
					
						
							|  |  |  | 		/* We are transfering the whole frame so copy */ | 
					
						
							| 
									
										
										
										
											2011-06-30 19:14:33 -07:00
										 |  |  | 		status = sci_stp_request_pio_data_in_copy_data_buffer( | 
					
						
							| 
									
										
										
										
											2011-06-27 11:56:41 -07:00
										 |  |  | 			stp_req, data_buffer, SCU_MAX_FRAME_BUFFER_SIZE); | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:49 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		if (status == SCI_SUCCESS) | 
					
						
							| 
									
										
										
										
											2011-06-27 11:56:41 -07:00
										 |  |  | 			stp_req->pio_len -= SCU_MAX_FRAME_BUFFER_SIZE; | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:49 -07:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return status; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-02 00:10:43 +00:00
										 |  |  | static enum sci_status | 
					
						
							| 
									
										
										
										
											2011-06-27 14:57:03 -07:00
										 |  |  | stp_request_pio_await_h2d_completion_tc_event(struct isci_request *ireq, | 
					
						
							| 
									
										
										
										
											2011-06-02 00:10:43 +00:00
										 |  |  | 					      u32 completion_code) | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:49 -07:00
										 |  |  | { | 
					
						
							|  |  |  | 	enum sci_status status = SCI_SUCCESS; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	switch (SCU_GET_COMPLETION_TL_STATUS(completion_code)) { | 
					
						
							|  |  |  | 	case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_GOOD): | 
					
						
							| 
									
										
										
										
											2011-07-01 02:25:15 -07:00
										 |  |  | 		ireq->scu_status = SCU_TASK_DONE_GOOD; | 
					
						
							|  |  |  | 		ireq->sci_status = SCI_SUCCESS; | 
					
						
							| 
									
										
										
										
											2011-06-27 14:57:03 -07:00
										 |  |  | 		sci_change_state(&ireq->sm, SCI_REQ_STP_PIO_WAIT_FRAME); | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:49 -07:00
										 |  |  | 		break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	default: | 
					
						
							| 
									
										
										
										
											2011-05-11 08:27:47 -07:00
										 |  |  | 		/* All other completion status cause the IO to be
 | 
					
						
							|  |  |  | 		 * complete.  If a NAK was received, then it is up to | 
					
						
							|  |  |  | 		 * the user to retry the request. | 
					
						
							|  |  |  | 		 */ | 
					
						
							| 
									
										
										
										
											2011-07-01 02:25:15 -07:00
										 |  |  | 		ireq->scu_status = SCU_NORMALIZE_COMPLETION_STATUS(completion_code); | 
					
						
							|  |  |  | 		ireq->sci_status = SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR; | 
					
						
							| 
									
										
										
										
											2011-06-27 14:57:03 -07:00
										 |  |  | 		sci_change_state(&ireq->sm, SCI_REQ_COMPLETED); | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:49 -07:00
										 |  |  | 		break; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return status; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-02 00:10:43 +00:00
										 |  |  | static enum sci_status | 
					
						
							| 
									
										
										
										
											2011-06-27 14:57:03 -07:00
										 |  |  | pio_data_out_tx_done_tc_event(struct isci_request *ireq, | 
					
						
							| 
									
										
										
										
											2011-06-02 00:10:43 +00:00
										 |  |  | 			      u32 completion_code) | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:49 -07:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-05-11 08:27:47 -07:00
										 |  |  | 	enum sci_status status = SCI_SUCCESS; | 
					
						
							|  |  |  | 	bool all_frames_transferred = false; | 
					
						
							| 
									
										
										
										
											2011-06-27 14:57:03 -07:00
										 |  |  | 	struct isci_stp_request *stp_req = &ireq->stp.req; | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:49 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-11 08:27:47 -07:00
										 |  |  | 	switch (SCU_GET_COMPLETION_TL_STATUS(completion_code)) { | 
					
						
							|  |  |  | 	case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_GOOD): | 
					
						
							|  |  |  | 		/* Transmit data */ | 
					
						
							| 
									
										
										
										
											2011-06-27 11:56:41 -07:00
										 |  |  | 		if (stp_req->pio_len != 0) { | 
					
						
							| 
									
										
										
										
											2011-06-30 19:14:33 -07:00
										 |  |  | 			status = sci_stp_request_pio_data_out_transmit_data(ireq); | 
					
						
							| 
									
										
										
										
											2011-05-11 08:27:47 -07:00
										 |  |  | 			if (status == SCI_SUCCESS) { | 
					
						
							| 
									
										
										
										
											2011-06-27 11:56:41 -07:00
										 |  |  | 				if (stp_req->pio_len == 0) | 
					
						
							| 
									
										
										
										
											2011-05-11 08:27:47 -07:00
										 |  |  | 					all_frames_transferred = true; | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2011-06-27 11:56:41 -07:00
										 |  |  | 		} else if (stp_req->pio_len == 0) { | 
					
						
							| 
									
										
										
										
											2011-05-11 08:27:47 -07:00
										 |  |  | 			/*
 | 
					
						
							|  |  |  | 			 * this will happen if the all data is written at the | 
					
						
							|  |  |  | 			 * first time after the pio setup fis is received | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:49 -07:00
										 |  |  | 			 */ | 
					
						
							| 
									
										
										
										
											2011-05-11 08:27:47 -07:00
										 |  |  | 			all_frames_transferred  = true; | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:49 -07:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-11 08:27:47 -07:00
										 |  |  | 		/* all data transferred. */ | 
					
						
							|  |  |  | 		if (all_frames_transferred) { | 
					
						
							|  |  |  | 			/*
 | 
					
						
							| 
									
										
										
										
											2011-06-02 00:10:43 +00:00
										 |  |  | 			 * Change the state to SCI_REQ_STP_PIO_DATA_IN | 
					
						
							| 
									
										
										
										
											2011-05-11 08:27:47 -07:00
										 |  |  | 			 * and wait for PIO_SETUP fis / or D2H REg fis. */ | 
					
						
							| 
									
										
										
										
											2011-06-27 14:57:03 -07:00
										 |  |  | 			sci_change_state(&ireq->sm, SCI_REQ_STP_PIO_WAIT_FRAME); | 
					
						
							| 
									
										
										
										
											2011-05-11 08:27:47 -07:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:49 -07:00
										 |  |  | 		break; | 
					
						
							| 
									
										
										
										
											2011-06-02 00:10:43 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:49 -07:00
										 |  |  | 	default: | 
					
						
							| 
									
										
										
										
											2011-05-11 08:27:47 -07:00
										 |  |  | 		/*
 | 
					
						
							| 
									
										
										
										
											2011-06-02 00:10:43 +00:00
										 |  |  | 		 * All other completion status cause the IO to be complete. | 
					
						
							|  |  |  | 		 * If a NAK was received, then it is up to the user to retry | 
					
						
							|  |  |  | 		 * the request. | 
					
						
							|  |  |  | 		 */ | 
					
						
							| 
									
										
										
										
											2011-07-01 02:25:15 -07:00
										 |  |  | 		ireq->scu_status = SCU_NORMALIZE_COMPLETION_STATUS(completion_code); | 
					
						
							|  |  |  | 		ireq->sci_status = SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR; | 
					
						
							| 
									
										
										
										
											2011-06-27 14:57:03 -07:00
										 |  |  | 		sci_change_state(&ireq->sm, SCI_REQ_COMPLETED); | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:49 -07:00
										 |  |  | 		break; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return status; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-30 19:14:33 -07:00
										 |  |  | static enum sci_status sci_stp_request_udma_general_frame_handler(struct isci_request *ireq, | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:49 -07:00
										 |  |  | 								       u32 frame_index) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2011-06-30 17:38:32 -07:00
										 |  |  | 	struct isci_host *ihost = ireq->owning_controller; | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:49 -07:00
										 |  |  | 	struct dev_to_host_fis *frame_header; | 
					
						
							|  |  |  | 	enum sci_status status; | 
					
						
							|  |  |  | 	u32 *frame_buffer; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-30 19:14:33 -07:00
										 |  |  | 	status = sci_unsolicited_frame_control_get_header(&ihost->uf_control, | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:49 -07:00
										 |  |  | 							       frame_index, | 
					
						
							|  |  |  | 							       (void **)&frame_header); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if ((status == SCI_SUCCESS) && | 
					
						
							|  |  |  | 	    (frame_header->fis_type == FIS_REGD2H)) { | 
					
						
							| 
									
										
										
										
											2011-06-30 19:14:33 -07:00
										 |  |  | 		sci_unsolicited_frame_control_get_buffer(&ihost->uf_control, | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:49 -07:00
										 |  |  | 							      frame_index, | 
					
						
							|  |  |  | 							      (void **)&frame_buffer); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-30 19:14:33 -07:00
										 |  |  | 		sci_controller_copy_sata_response(&ireq->stp.rsp, | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:49 -07:00
										 |  |  | 						       frame_header, | 
					
						
							|  |  |  | 						       frame_buffer); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-30 19:14:33 -07:00
										 |  |  | 	sci_controller_release_frame(ihost, frame_index); | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:49 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return status; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-09-30 18:52:19 -07:00
										 |  |  | static enum sci_status process_unsolicited_fis(struct isci_request *ireq, | 
					
						
							|  |  |  | 					       u32 frame_index) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct isci_host *ihost = ireq->owning_controller; | 
					
						
							|  |  |  | 	enum sci_status status; | 
					
						
							|  |  |  | 	struct dev_to_host_fis *frame_header; | 
					
						
							|  |  |  | 	u32 *frame_buffer; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	status = sci_unsolicited_frame_control_get_header(&ihost->uf_control, | 
					
						
							|  |  |  | 							  frame_index, | 
					
						
							|  |  |  | 							  (void **)&frame_header); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (status != SCI_SUCCESS) | 
					
						
							|  |  |  | 		return status; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (frame_header->fis_type != FIS_REGD2H) { | 
					
						
							|  |  |  | 		dev_err(&ireq->isci_host->pdev->dev, | 
					
						
							|  |  |  | 			"%s ERROR: invalid fis type 0x%X\n", | 
					
						
							|  |  |  | 			__func__, frame_header->fis_type); | 
					
						
							|  |  |  | 		return SCI_FAILURE; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	sci_unsolicited_frame_control_get_buffer(&ihost->uf_control, | 
					
						
							|  |  |  | 						 frame_index, | 
					
						
							|  |  |  | 						 (void **)&frame_buffer); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	sci_controller_copy_sata_response(&ireq->stp.rsp, | 
					
						
							|  |  |  | 					  (u32 *)frame_header, | 
					
						
							|  |  |  | 					  frame_buffer); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* Frame has been decoded return it to the controller */ | 
					
						
							|  |  |  | 	sci_controller_release_frame(ihost, frame_index); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return status; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static enum sci_status atapi_d2h_reg_frame_handler(struct isci_request *ireq, | 
					
						
							|  |  |  | 						   u32 frame_index) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct sas_task *task = isci_request_access_task(ireq); | 
					
						
							|  |  |  | 	enum sci_status status; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	status = process_unsolicited_fis(ireq, frame_index); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (status == SCI_SUCCESS) { | 
					
						
							|  |  |  | 		if (ireq->stp.rsp.status & ATA_ERR) | 
					
						
							|  |  |  | 			status = SCI_IO_FAILURE_RESPONSE_VALID; | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		status = SCI_IO_FAILURE_RESPONSE_VALID; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (status != SCI_SUCCESS) { | 
					
						
							|  |  |  | 		ireq->scu_status = SCU_TASK_DONE_CHECK_RESPONSE; | 
					
						
							|  |  |  | 		ireq->sci_status = status; | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		ireq->scu_status = SCU_TASK_DONE_GOOD; | 
					
						
							|  |  |  | 		ireq->sci_status = SCI_SUCCESS; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* the d2h ufi is the end of non-data commands */ | 
					
						
							|  |  |  | 	if (task->data_dir == DMA_NONE) | 
					
						
							|  |  |  | 		sci_change_state(&ireq->sm, SCI_REQ_COMPLETED); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return status; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void scu_atapi_reconstruct_raw_frame_task_context(struct isci_request *ireq) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct ata_device *dev = sas_to_ata_dev(ireq->target_device->domain_dev); | 
					
						
							|  |  |  | 	void *atapi_cdb = ireq->ttype_ptr.io_task_ptr->ata_task.atapi_packet; | 
					
						
							|  |  |  | 	struct scu_task_context *task_context = ireq->tc; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* fill in the SCU Task Context for a DATA fis containing CDB in Raw Frame
 | 
					
						
							|  |  |  | 	 * type. The TC for previous Packet fis was already there, we only need to | 
					
						
							|  |  |  | 	 * change the H2D fis content. | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	memset(&ireq->stp.cmd, 0, sizeof(struct host_to_dev_fis)); | 
					
						
							|  |  |  | 	memcpy(((u8 *)&ireq->stp.cmd + sizeof(u32)), atapi_cdb, ATAPI_CDB_LEN); | 
					
						
							|  |  |  | 	memset(&(task_context->type.stp), 0, sizeof(struct stp_task_context)); | 
					
						
							|  |  |  | 	task_context->type.stp.fis_type = FIS_DATA; | 
					
						
							|  |  |  | 	task_context->transfer_length_bytes = dev->cdb_len; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void scu_atapi_construct_task_context(struct isci_request *ireq) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct ata_device *dev = sas_to_ata_dev(ireq->target_device->domain_dev); | 
					
						
							|  |  |  | 	struct sas_task *task = isci_request_access_task(ireq); | 
					
						
							|  |  |  | 	struct scu_task_context *task_context = ireq->tc; | 
					
						
							|  |  |  | 	int cdb_len = dev->cdb_len; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* reference: SSTL 1.13.4.2
 | 
					
						
							|  |  |  | 	 * task_type, sata_direction | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	if (task->data_dir == DMA_TO_DEVICE) { | 
					
						
							|  |  |  | 		task_context->task_type = SCU_TASK_TYPE_PACKET_DMA_OUT; | 
					
						
							|  |  |  | 		task_context->sata_direction = 0; | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		/* todo: for NO_DATA command, we need to send out raw frame. */ | 
					
						
							|  |  |  | 		task_context->task_type = SCU_TASK_TYPE_PACKET_DMA_IN; | 
					
						
							|  |  |  | 		task_context->sata_direction = 1; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	memset(&task_context->type.stp, 0, sizeof(task_context->type.stp)); | 
					
						
							|  |  |  | 	task_context->type.stp.fis_type = FIS_DATA; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	memset(&ireq->stp.cmd, 0, sizeof(ireq->stp.cmd)); | 
					
						
							|  |  |  | 	memcpy(&ireq->stp.cmd.lbal, task->ata_task.atapi_packet, cdb_len); | 
					
						
							|  |  |  | 	task_context->ssp_command_iu_length = cdb_len / sizeof(u32); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* task phase is set to TX_CMD */ | 
					
						
							|  |  |  | 	task_context->task_phase = 0x1; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* retry counter */ | 
					
						
							|  |  |  | 	task_context->stp_retry_count = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* data transfer size. */ | 
					
						
							|  |  |  | 	task_context->transfer_length_bytes = task->total_xfer_len; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* setup sgl */ | 
					
						
							|  |  |  | 	sci_request_build_sgl(ireq); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-02 00:10:43 +00:00
										 |  |  | enum sci_status | 
					
						
							| 
									
										
										
										
											2011-06-30 19:14:33 -07:00
										 |  |  | sci_io_request_frame_handler(struct isci_request *ireq, | 
					
						
							| 
									
										
										
										
											2011-06-02 00:10:43 +00:00
										 |  |  | 				  u32 frame_index) | 
					
						
							| 
									
										
										
										
											2011-05-11 08:27:47 -07:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-06-30 17:38:32 -07:00
										 |  |  | 	struct isci_host *ihost = ireq->owning_controller; | 
					
						
							| 
									
										
										
										
											2011-06-27 14:57:03 -07:00
										 |  |  | 	struct isci_stp_request *stp_req = &ireq->stp.req; | 
					
						
							| 
									
										
										
										
											2011-05-11 08:27:47 -07:00
										 |  |  | 	enum sci_base_request_states state; | 
					
						
							|  |  |  | 	enum sci_status status; | 
					
						
							|  |  |  | 	ssize_t word_cnt; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-27 14:57:03 -07:00
										 |  |  | 	state = ireq->sm.current_state_id; | 
					
						
							| 
									
										
										
										
											2011-05-11 08:27:47 -07:00
										 |  |  | 	switch (state)  { | 
					
						
							| 
									
										
										
										
											2011-06-02 00:10:43 +00:00
										 |  |  | 	case SCI_REQ_STARTED: { | 
					
						
							| 
									
										
										
										
											2011-05-11 08:27:47 -07:00
										 |  |  | 		struct ssp_frame_hdr ssp_hdr; | 
					
						
							|  |  |  | 		void *frame_header; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-30 19:14:33 -07:00
										 |  |  | 		sci_unsolicited_frame_control_get_header(&ihost->uf_control, | 
					
						
							| 
									
										
										
										
											2011-05-11 08:27:47 -07:00
										 |  |  | 							      frame_index, | 
					
						
							|  |  |  | 							      &frame_header); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		word_cnt = sizeof(struct ssp_frame_hdr) / sizeof(u32); | 
					
						
							|  |  |  | 		sci_swab32_cpy(&ssp_hdr, frame_header, word_cnt); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (ssp_hdr.frame_type == SSP_RESPONSE) { | 
					
						
							|  |  |  | 			struct ssp_response_iu *resp_iu; | 
					
						
							|  |  |  | 			ssize_t word_cnt = SSP_RESP_IU_MAX_SIZE / sizeof(u32); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-30 19:14:33 -07:00
										 |  |  | 			sci_unsolicited_frame_control_get_buffer(&ihost->uf_control, | 
					
						
							| 
									
										
										
										
											2011-05-11 08:27:47 -07:00
										 |  |  | 								      frame_index, | 
					
						
							|  |  |  | 								      (void **)&resp_iu); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-27 14:57:03 -07:00
										 |  |  | 			sci_swab32_cpy(&ireq->ssp.rsp, resp_iu, word_cnt); | 
					
						
							| 
									
										
										
										
											2011-05-11 08:27:47 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-27 14:57:03 -07:00
										 |  |  | 			resp_iu = &ireq->ssp.rsp; | 
					
						
							| 
									
										
										
										
											2011-05-11 08:27:47 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			if (resp_iu->datapres == 0x01 || | 
					
						
							|  |  |  | 			    resp_iu->datapres == 0x02) { | 
					
						
							| 
									
										
										
										
											2011-07-01 02:25:15 -07:00
										 |  |  | 				ireq->scu_status = SCU_TASK_DONE_CHECK_RESPONSE; | 
					
						
							|  |  |  | 				ireq->sci_status = SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR; | 
					
						
							|  |  |  | 			} else { | 
					
						
							|  |  |  | 				ireq->scu_status = SCU_TASK_DONE_GOOD; | 
					
						
							|  |  |  | 				ireq->sci_status = SCI_SUCCESS; | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2011-05-11 08:27:47 -07:00
										 |  |  | 		} else { | 
					
						
							|  |  |  | 			/* not a response frame, why did it get forwarded? */ | 
					
						
							| 
									
										
										
										
											2011-06-30 17:38:32 -07:00
										 |  |  | 			dev_err(&ihost->pdev->dev, | 
					
						
							| 
									
										
										
										
											2011-05-11 08:27:47 -07:00
										 |  |  | 				"%s: SCIC IO Request 0x%p received unexpected " | 
					
						
							| 
									
										
										
										
											2011-06-27 14:57:03 -07:00
										 |  |  | 				"frame %d type 0x%02x\n", __func__, ireq, | 
					
						
							| 
									
										
										
										
											2011-05-11 08:27:47 -07:00
										 |  |  | 				frame_index, ssp_hdr.frame_type); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		/*
 | 
					
						
							| 
									
										
										
										
											2011-06-02 00:10:43 +00:00
										 |  |  | 		 * In any case we are done with this frame buffer return it to | 
					
						
							|  |  |  | 		 * the controller | 
					
						
							| 
									
										
										
										
											2011-05-11 08:27:47 -07:00
										 |  |  | 		 */ | 
					
						
							| 
									
										
										
										
											2011-06-30 19:14:33 -07:00
										 |  |  | 		sci_controller_release_frame(ihost, frame_index); | 
					
						
							| 
									
										
										
										
											2011-05-11 08:27:47 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		return SCI_SUCCESS; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2011-06-02 00:10:43 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	case SCI_REQ_TASK_WAIT_TC_RESP: | 
					
						
							| 
									
										
										
										
											2011-06-30 19:14:33 -07:00
										 |  |  | 		sci_io_request_copy_response(ireq); | 
					
						
							| 
									
										
										
										
											2011-06-27 14:57:03 -07:00
										 |  |  | 		sci_change_state(&ireq->sm, SCI_REQ_COMPLETED); | 
					
						
							| 
									
										
										
										
											2011-06-30 19:14:33 -07:00
										 |  |  | 		sci_controller_release_frame(ihost, frame_index); | 
					
						
							| 
									
										
										
										
											2011-05-11 08:27:47 -07:00
										 |  |  | 		return SCI_SUCCESS; | 
					
						
							| 
									
										
										
										
											2011-06-02 00:10:43 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	case SCI_REQ_SMP_WAIT_RESP: { | 
					
						
							| 
									
										
										
										
											2011-09-28 18:35:27 -07:00
										 |  |  | 		struct sas_task *task = isci_request_access_task(ireq); | 
					
						
							|  |  |  | 		struct scatterlist *sg = &task->smp_task.smp_resp; | 
					
						
							|  |  |  | 		void *frame_header, *kaddr; | 
					
						
							|  |  |  | 		u8 *rsp; | 
					
						
							| 
									
										
										
										
											2011-05-11 08:27:47 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-30 19:14:33 -07:00
										 |  |  | 		sci_unsolicited_frame_control_get_header(&ihost->uf_control, | 
					
						
							| 
									
										
										
										
											2011-09-28 18:35:27 -07:00
										 |  |  | 							 frame_index, | 
					
						
							|  |  |  | 							 &frame_header); | 
					
						
							| 
									
										
										
										
											2011-11-25 23:14:23 +08:00
										 |  |  | 		kaddr = kmap_atomic(sg_page(sg)); | 
					
						
							| 
									
										
										
										
											2011-09-28 18:35:27 -07:00
										 |  |  | 		rsp = kaddr + sg->offset; | 
					
						
							|  |  |  | 		sci_swab32_cpy(rsp, frame_header, 1); | 
					
						
							| 
									
										
										
										
											2011-05-11 08:27:47 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-09-28 18:35:27 -07:00
										 |  |  | 		if (rsp[0] == SMP_RESPONSE) { | 
					
						
							| 
									
										
										
										
											2011-05-11 08:27:47 -07:00
										 |  |  | 			void *smp_resp; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-30 19:14:33 -07:00
										 |  |  | 			sci_unsolicited_frame_control_get_buffer(&ihost->uf_control, | 
					
						
							| 
									
										
										
										
											2011-09-28 18:35:27 -07:00
										 |  |  | 								 frame_index, | 
					
						
							|  |  |  | 								 &smp_resp); | 
					
						
							| 
									
										
										
										
											2011-05-11 08:27:47 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-09-28 18:35:27 -07:00
										 |  |  | 			word_cnt = (sg->length/4)-1; | 
					
						
							|  |  |  | 			if (word_cnt > 0) | 
					
						
							|  |  |  | 				word_cnt = min_t(unsigned int, word_cnt, | 
					
						
							|  |  |  | 						 SCU_UNSOLICITED_FRAME_BUFFER_SIZE/4); | 
					
						
							|  |  |  | 			sci_swab32_cpy(rsp + 4, smp_resp, word_cnt); | 
					
						
							| 
									
										
										
										
											2011-05-11 08:27:47 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-07-01 02:25:15 -07:00
										 |  |  | 			ireq->scu_status = SCU_TASK_DONE_GOOD; | 
					
						
							|  |  |  | 			ireq->sci_status = SCI_SUCCESS; | 
					
						
							| 
									
										
										
										
											2011-06-27 14:57:03 -07:00
										 |  |  | 			sci_change_state(&ireq->sm, SCI_REQ_SMP_WAIT_TC_COMP); | 
					
						
							| 
									
										
										
										
											2011-05-11 08:27:47 -07:00
										 |  |  | 		} else { | 
					
						
							| 
									
										
										
										
											2011-06-02 00:10:43 +00:00
										 |  |  | 			/*
 | 
					
						
							|  |  |  | 			 * This was not a response frame why did it get | 
					
						
							|  |  |  | 			 * forwarded? | 
					
						
							|  |  |  | 			 */ | 
					
						
							| 
									
										
										
										
											2011-06-30 17:38:32 -07:00
										 |  |  | 			dev_err(&ihost->pdev->dev, | 
					
						
							| 
									
										
										
										
											2011-06-02 00:10:43 +00:00
										 |  |  | 				"%s: SCIC SMP Request 0x%p received unexpected " | 
					
						
							|  |  |  | 				"frame %d type 0x%02x\n", | 
					
						
							|  |  |  | 				__func__, | 
					
						
							| 
									
										
										
										
											2011-06-27 14:57:03 -07:00
										 |  |  | 				ireq, | 
					
						
							| 
									
										
										
										
											2011-06-02 00:10:43 +00:00
										 |  |  | 				frame_index, | 
					
						
							| 
									
										
										
										
											2011-09-28 18:35:27 -07:00
										 |  |  | 				rsp[0]); | 
					
						
							| 
									
										
										
										
											2011-05-11 08:27:47 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-07-01 02:25:15 -07:00
										 |  |  | 			ireq->scu_status = SCU_TASK_DONE_SMP_FRM_TYPE_ERR; | 
					
						
							|  |  |  | 			ireq->sci_status = SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR; | 
					
						
							| 
									
										
										
										
											2011-06-27 14:57:03 -07:00
										 |  |  | 			sci_change_state(&ireq->sm, SCI_REQ_COMPLETED); | 
					
						
							| 
									
										
										
										
											2011-05-11 08:27:47 -07:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2011-11-25 23:14:23 +08:00
										 |  |  | 		kunmap_atomic(kaddr); | 
					
						
							| 
									
										
										
										
											2011-05-11 08:27:47 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-30 19:14:33 -07:00
										 |  |  | 		sci_controller_release_frame(ihost, frame_index); | 
					
						
							| 
									
										
										
										
											2011-05-11 08:27:47 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		return SCI_SUCCESS; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2011-06-02 00:10:43 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	case SCI_REQ_STP_UDMA_WAIT_TC_COMP: | 
					
						
							| 
									
										
										
										
											2011-06-30 19:14:33 -07:00
										 |  |  | 		return sci_stp_request_udma_general_frame_handler(ireq, | 
					
						
							| 
									
										
										
										
											2011-06-02 00:10:43 +00:00
										 |  |  | 								       frame_index); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	case SCI_REQ_STP_UDMA_WAIT_D2H: | 
					
						
							| 
									
										
										
										
											2011-05-11 08:27:47 -07:00
										 |  |  | 		/* Use the general frame handler to copy the resposne data */ | 
					
						
							| 
									
										
										
										
											2011-07-01 02:25:15 -07:00
										 |  |  | 		status = sci_stp_request_udma_general_frame_handler(ireq, frame_index); | 
					
						
							| 
									
										
										
										
											2011-05-11 08:27:47 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		if (status != SCI_SUCCESS) | 
					
						
							|  |  |  | 			return status; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-07-01 02:25:15 -07:00
										 |  |  | 		ireq->scu_status = SCU_TASK_DONE_CHECK_RESPONSE; | 
					
						
							|  |  |  | 		ireq->sci_status = SCI_FAILURE_IO_RESPONSE_VALID; | 
					
						
							|  |  |  | 		sci_change_state(&ireq->sm, SCI_REQ_COMPLETED); | 
					
						
							| 
									
										
										
										
											2011-05-11 08:27:47 -07:00
										 |  |  | 		return SCI_SUCCESS; | 
					
						
							| 
									
										
										
										
											2011-06-02 00:10:43 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	case SCI_REQ_STP_NON_DATA_WAIT_D2H: { | 
					
						
							| 
									
										
										
										
											2011-05-11 08:27:47 -07:00
										 |  |  | 		struct dev_to_host_fis *frame_header; | 
					
						
							|  |  |  | 		u32 *frame_buffer; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-30 19:14:33 -07:00
										 |  |  | 		status = sci_unsolicited_frame_control_get_header(&ihost->uf_control, | 
					
						
							| 
									
										
										
										
											2011-05-11 08:27:47 -07:00
										 |  |  | 								       frame_index, | 
					
						
							|  |  |  | 								       (void **)&frame_header); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (status != SCI_SUCCESS) { | 
					
						
							| 
									
										
										
										
											2011-06-30 17:38:32 -07:00
										 |  |  | 			dev_err(&ihost->pdev->dev, | 
					
						
							| 
									
										
										
										
											2011-06-02 00:10:43 +00:00
										 |  |  | 				"%s: SCIC IO Request 0x%p could not get frame " | 
					
						
							|  |  |  | 				"header for frame index %d, status %x\n", | 
					
						
							|  |  |  | 				__func__, | 
					
						
							|  |  |  | 				stp_req, | 
					
						
							|  |  |  | 				frame_index, | 
					
						
							|  |  |  | 				status); | 
					
						
							| 
									
										
										
										
											2011-05-11 08:27:47 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			return status; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		switch (frame_header->fis_type) { | 
					
						
							|  |  |  | 		case FIS_REGD2H: | 
					
						
							| 
									
										
										
										
											2011-06-30 19:14:33 -07:00
										 |  |  | 			sci_unsolicited_frame_control_get_buffer(&ihost->uf_control, | 
					
						
							| 
									
										
										
										
											2011-05-11 08:27:47 -07:00
										 |  |  | 								      frame_index, | 
					
						
							|  |  |  | 								      (void **)&frame_buffer); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-30 19:14:33 -07:00
										 |  |  | 			sci_controller_copy_sata_response(&ireq->stp.rsp, | 
					
						
							| 
									
										
										
										
											2011-05-11 08:27:47 -07:00
										 |  |  | 							       frame_header, | 
					
						
							|  |  |  | 							       frame_buffer); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			/* The command has completed with error */ | 
					
						
							| 
									
										
										
										
											2011-07-01 02:25:15 -07:00
										 |  |  | 			ireq->scu_status = SCU_TASK_DONE_CHECK_RESPONSE; | 
					
						
							|  |  |  | 			ireq->sci_status = SCI_FAILURE_IO_RESPONSE_VALID; | 
					
						
							| 
									
										
										
										
											2011-05-11 08:27:47 -07:00
										 |  |  | 			break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		default: | 
					
						
							| 
									
										
										
										
											2011-06-30 17:38:32 -07:00
										 |  |  | 			dev_warn(&ihost->pdev->dev, | 
					
						
							| 
									
										
										
										
											2011-05-11 08:27:47 -07:00
										 |  |  | 				 "%s: IO Request:0x%p Frame Id:%d protocol " | 
					
						
							|  |  |  | 				  "violation occurred\n", __func__, stp_req, | 
					
						
							|  |  |  | 				  frame_index); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-07-01 02:25:15 -07:00
										 |  |  | 			ireq->scu_status = SCU_TASK_DONE_UNEXP_FIS; | 
					
						
							|  |  |  | 			ireq->sci_status = SCI_FAILURE_PROTOCOL_VIOLATION; | 
					
						
							| 
									
										
										
										
											2011-05-11 08:27:47 -07:00
										 |  |  | 			break; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-27 14:57:03 -07:00
										 |  |  | 		sci_change_state(&ireq->sm, SCI_REQ_COMPLETED); | 
					
						
							| 
									
										
										
										
											2011-05-11 08:27:47 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		/* Frame has been decoded return it to the controller */ | 
					
						
							| 
									
										
										
										
											2011-06-30 19:14:33 -07:00
										 |  |  | 		sci_controller_release_frame(ihost, frame_index); | 
					
						
							| 
									
										
										
										
											2011-05-11 08:27:47 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		return status; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2011-06-02 00:10:43 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	case SCI_REQ_STP_PIO_WAIT_FRAME: { | 
					
						
							| 
									
										
										
										
											2011-05-11 08:27:47 -07:00
										 |  |  | 		struct sas_task *task = isci_request_access_task(ireq); | 
					
						
							|  |  |  | 		struct dev_to_host_fis *frame_header; | 
					
						
							|  |  |  | 		u32 *frame_buffer; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-30 19:14:33 -07:00
										 |  |  | 		status = sci_unsolicited_frame_control_get_header(&ihost->uf_control, | 
					
						
							| 
									
										
										
										
											2011-05-11 08:27:47 -07:00
										 |  |  | 								       frame_index, | 
					
						
							|  |  |  | 								       (void **)&frame_header); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (status != SCI_SUCCESS) { | 
					
						
							| 
									
										
										
										
											2011-06-30 17:38:32 -07:00
										 |  |  | 			dev_err(&ihost->pdev->dev, | 
					
						
							| 
									
										
										
										
											2011-06-02 00:10:43 +00:00
										 |  |  | 				"%s: SCIC IO Request 0x%p could not get frame " | 
					
						
							|  |  |  | 				"header for frame index %d, status %x\n", | 
					
						
							| 
									
										
										
										
											2011-05-11 08:27:47 -07:00
										 |  |  | 				__func__, stp_req, frame_index, status); | 
					
						
							|  |  |  | 			return status; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		switch (frame_header->fis_type) { | 
					
						
							|  |  |  | 		case FIS_PIO_SETUP: | 
					
						
							|  |  |  | 			/* Get from the frame buffer the PIO Setup Data */ | 
					
						
							| 
									
										
										
										
											2011-06-30 19:14:33 -07:00
										 |  |  | 			sci_unsolicited_frame_control_get_buffer(&ihost->uf_control, | 
					
						
							| 
									
										
										
										
											2011-05-11 08:27:47 -07:00
										 |  |  | 								      frame_index, | 
					
						
							|  |  |  | 								      (void **)&frame_buffer); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-02 00:10:43 +00:00
										 |  |  | 			/* Get the data from the PIO Setup The SCU Hardware
 | 
					
						
							|  |  |  | 			 * returns first word in the frame_header and the rest | 
					
						
							|  |  |  | 			 * of the data is in the frame buffer so we need to | 
					
						
							|  |  |  | 			 * back up one dword | 
					
						
							| 
									
										
										
										
											2011-05-11 08:27:47 -07:00
										 |  |  | 			 */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			/* transfer_count: first 16bits in the 4th dword */ | 
					
						
							| 
									
										
										
										
											2011-06-27 11:56:41 -07:00
										 |  |  | 			stp_req->pio_len = frame_buffer[3] & 0xffff; | 
					
						
							| 
									
										
										
										
											2011-05-11 08:27:47 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-27 11:56:41 -07:00
										 |  |  | 			/* status: 4th byte in the 3rd dword */ | 
					
						
							|  |  |  | 			stp_req->status = (frame_buffer[2] >> 24) & 0xff; | 
					
						
							| 
									
										
										
										
											2011-05-11 08:27:47 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-30 19:14:33 -07:00
										 |  |  | 			sci_controller_copy_sata_response(&ireq->stp.rsp, | 
					
						
							| 
									
										
										
										
											2011-05-11 08:27:47 -07:00
										 |  |  | 							       frame_header, | 
					
						
							|  |  |  | 							       frame_buffer); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-27 14:57:03 -07:00
										 |  |  | 			ireq->stp.rsp.status = stp_req->status; | 
					
						
							| 
									
										
										
										
											2011-05-11 08:27:47 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			/* The next state is dependent on whether the
 | 
					
						
							|  |  |  | 			 * request was PIO Data-in or Data out | 
					
						
							|  |  |  | 			 */ | 
					
						
							|  |  |  | 			if (task->data_dir == DMA_FROM_DEVICE) { | 
					
						
							| 
									
										
										
										
											2011-06-27 14:57:03 -07:00
										 |  |  | 				sci_change_state(&ireq->sm, SCI_REQ_STP_PIO_DATA_IN); | 
					
						
							| 
									
										
										
										
											2011-05-11 08:27:47 -07:00
										 |  |  | 			} else if (task->data_dir == DMA_TO_DEVICE) { | 
					
						
							|  |  |  | 				/* Transmit data */ | 
					
						
							| 
									
										
										
										
											2011-06-30 19:14:33 -07:00
										 |  |  | 				status = sci_stp_request_pio_data_out_transmit_data(ireq); | 
					
						
							| 
									
										
										
										
											2011-05-11 08:27:47 -07:00
										 |  |  | 				if (status != SCI_SUCCESS) | 
					
						
							|  |  |  | 					break; | 
					
						
							| 
									
										
										
										
											2011-06-27 14:57:03 -07:00
										 |  |  | 				sci_change_state(&ireq->sm, SCI_REQ_STP_PIO_DATA_OUT); | 
					
						
							| 
									
										
										
										
											2011-05-11 08:27:47 -07:00
										 |  |  | 			} | 
					
						
							|  |  |  | 			break; | 
					
						
							| 
									
										
										
										
											2011-06-02 00:10:43 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-11 08:27:47 -07:00
										 |  |  | 		case FIS_SETDEVBITS: | 
					
						
							| 
									
										
										
										
											2011-06-27 14:57:03 -07:00
										 |  |  | 			sci_change_state(&ireq->sm, SCI_REQ_STP_PIO_WAIT_FRAME); | 
					
						
							| 
									
										
										
										
											2011-05-11 08:27:47 -07:00
										 |  |  | 			break; | 
					
						
							| 
									
										
										
										
											2011-06-02 00:10:43 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-11 08:27:47 -07:00
										 |  |  | 		case FIS_REGD2H: | 
					
						
							|  |  |  | 			if (frame_header->status & ATA_BUSY) { | 
					
						
							| 
									
										
										
										
											2011-06-02 00:10:43 +00:00
										 |  |  | 				/*
 | 
					
						
							|  |  |  | 				 * Now why is the drive sending a D2H Register | 
					
						
							|  |  |  | 				 * FIS when it is still busy?  Do nothing since | 
					
						
							|  |  |  | 				 * we are still in the right state. | 
					
						
							| 
									
										
										
										
											2011-05-11 08:27:47 -07:00
										 |  |  | 				 */ | 
					
						
							| 
									
										
										
										
											2011-06-30 17:38:32 -07:00
										 |  |  | 				dev_dbg(&ihost->pdev->dev, | 
					
						
							| 
									
										
										
										
											2011-05-11 08:27:47 -07:00
										 |  |  | 					"%s: SCIC PIO Request 0x%p received " | 
					
						
							|  |  |  | 					"D2H Register FIS with BSY status " | 
					
						
							| 
									
										
										
										
											2011-06-02 00:10:43 +00:00
										 |  |  | 					"0x%x\n", | 
					
						
							|  |  |  | 					__func__, | 
					
						
							|  |  |  | 					stp_req, | 
					
						
							| 
									
										
										
										
											2011-05-11 08:27:47 -07:00
										 |  |  | 					frame_header->status); | 
					
						
							|  |  |  | 				break; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-30 19:14:33 -07:00
										 |  |  | 			sci_unsolicited_frame_control_get_buffer(&ihost->uf_control, | 
					
						
							| 
									
										
										
										
											2011-05-11 08:27:47 -07:00
										 |  |  | 								      frame_index, | 
					
						
							|  |  |  | 								      (void **)&frame_buffer); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-15 14:29:03 +02:00
										 |  |  | 			sci_controller_copy_sata_response(&ireq->stp.rsp, | 
					
						
							| 
									
										
										
										
											2011-05-11 08:27:47 -07:00
										 |  |  | 							       frame_header, | 
					
						
							|  |  |  | 							       frame_buffer); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-07-01 02:25:15 -07:00
										 |  |  | 			ireq->scu_status = SCU_TASK_DONE_CHECK_RESPONSE; | 
					
						
							|  |  |  | 			ireq->sci_status = SCI_FAILURE_IO_RESPONSE_VALID; | 
					
						
							| 
									
										
										
										
											2011-06-27 14:57:03 -07:00
										 |  |  | 			sci_change_state(&ireq->sm, SCI_REQ_COMPLETED); | 
					
						
							| 
									
										
										
										
											2011-05-11 08:27:47 -07:00
										 |  |  | 			break; | 
					
						
							| 
									
										
										
										
											2011-06-02 00:10:43 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-11 08:27:47 -07:00
										 |  |  | 		default: | 
					
						
							|  |  |  | 			/* FIXME: what do we do here? */ | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		/* Frame is decoded return it to the controller */ | 
					
						
							| 
									
										
										
										
											2011-06-30 19:14:33 -07:00
										 |  |  | 		sci_controller_release_frame(ihost, frame_index); | 
					
						
							| 
									
										
										
										
											2011-05-11 08:27:47 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		return status; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2011-06-02 00:10:43 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	case SCI_REQ_STP_PIO_DATA_IN: { | 
					
						
							| 
									
										
										
										
											2011-05-11 08:27:47 -07:00
										 |  |  | 		struct dev_to_host_fis *frame_header; | 
					
						
							|  |  |  | 		struct sata_fis_data *frame_buffer; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-30 19:14:33 -07:00
										 |  |  | 		status = sci_unsolicited_frame_control_get_header(&ihost->uf_control, | 
					
						
							| 
									
										
										
										
											2011-05-11 08:27:47 -07:00
										 |  |  | 								       frame_index, | 
					
						
							|  |  |  | 								       (void **)&frame_header); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (status != SCI_SUCCESS) { | 
					
						
							| 
									
										
										
										
											2011-06-30 17:38:32 -07:00
										 |  |  | 			dev_err(&ihost->pdev->dev, | 
					
						
							| 
									
										
										
										
											2011-06-02 00:10:43 +00:00
										 |  |  | 				"%s: SCIC IO Request 0x%p could not get frame " | 
					
						
							|  |  |  | 				"header for frame index %d, status %x\n", | 
					
						
							|  |  |  | 				__func__, | 
					
						
							|  |  |  | 				stp_req, | 
					
						
							|  |  |  | 				frame_index, | 
					
						
							|  |  |  | 				status); | 
					
						
							| 
									
										
										
										
											2011-05-11 08:27:47 -07:00
										 |  |  | 			return status; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (frame_header->fis_type != FIS_DATA) { | 
					
						
							| 
									
										
										
										
											2011-06-30 17:38:32 -07:00
										 |  |  | 			dev_err(&ihost->pdev->dev, | 
					
						
							| 
									
										
										
										
											2011-05-11 08:27:47 -07:00
										 |  |  | 				"%s: SCIC PIO Request 0x%p received frame %d " | 
					
						
							|  |  |  | 				"with fis type 0x%02x when expecting a data " | 
					
						
							| 
									
										
										
										
											2011-06-02 00:10:43 +00:00
										 |  |  | 				"fis.\n", | 
					
						
							|  |  |  | 				__func__, | 
					
						
							|  |  |  | 				stp_req, | 
					
						
							|  |  |  | 				frame_index, | 
					
						
							| 
									
										
										
										
											2011-05-11 08:27:47 -07:00
										 |  |  | 				frame_header->fis_type); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-07-01 02:25:15 -07:00
										 |  |  | 			ireq->scu_status = SCU_TASK_DONE_GOOD; | 
					
						
							|  |  |  | 			ireq->sci_status = SCI_FAILURE_IO_REQUIRES_SCSI_ABORT; | 
					
						
							| 
									
										
										
										
											2011-06-27 14:57:03 -07:00
										 |  |  | 			sci_change_state(&ireq->sm, SCI_REQ_COMPLETED); | 
					
						
							| 
									
										
										
										
											2011-05-11 08:27:47 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			/* Frame is decoded return it to the controller */ | 
					
						
							| 
									
										
										
										
											2011-06-30 19:14:33 -07:00
										 |  |  | 			sci_controller_release_frame(ihost, frame_index); | 
					
						
							| 
									
										
										
										
											2011-05-11 08:27:47 -07:00
										 |  |  | 			return status; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-27 11:56:41 -07:00
										 |  |  | 		if (stp_req->sgl.index < 0) { | 
					
						
							| 
									
										
										
										
											2011-06-27 14:57:03 -07:00
										 |  |  | 			ireq->saved_rx_frame_index = frame_index; | 
					
						
							| 
									
										
										
										
											2011-06-27 11:56:41 -07:00
										 |  |  | 			stp_req->pio_len = 0; | 
					
						
							| 
									
										
										
										
											2011-05-11 08:27:47 -07:00
										 |  |  | 		} else { | 
					
						
							| 
									
										
										
										
											2011-06-30 19:14:33 -07:00
										 |  |  | 			sci_unsolicited_frame_control_get_buffer(&ihost->uf_control, | 
					
						
							| 
									
										
										
										
											2011-05-11 08:27:47 -07:00
										 |  |  | 								      frame_index, | 
					
						
							|  |  |  | 								      (void **)&frame_buffer); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-30 19:14:33 -07:00
										 |  |  | 			status = sci_stp_request_pio_data_in_copy_data(stp_req, | 
					
						
							| 
									
										
										
										
											2011-05-11 08:27:47 -07:00
										 |  |  | 									    (u8 *)frame_buffer); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			/* Frame is decoded return it to the controller */ | 
					
						
							| 
									
										
										
										
											2011-06-30 19:14:33 -07:00
										 |  |  | 			sci_controller_release_frame(ihost, frame_index); | 
					
						
							| 
									
										
										
										
											2011-05-11 08:27:47 -07:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		/* Check for the end of the transfer, are there more
 | 
					
						
							|  |  |  | 		 * bytes remaining for this data transfer | 
					
						
							|  |  |  | 		 */ | 
					
						
							| 
									
										
										
										
											2011-06-27 11:56:41 -07:00
										 |  |  | 		if (status != SCI_SUCCESS || stp_req->pio_len != 0) | 
					
						
							| 
									
										
										
										
											2011-05-11 08:27:47 -07:00
										 |  |  | 			return status; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-27 11:56:41 -07:00
										 |  |  | 		if ((stp_req->status & ATA_BUSY) == 0) { | 
					
						
							| 
									
										
										
										
											2011-07-01 02:25:15 -07:00
										 |  |  | 			ireq->scu_status = SCU_TASK_DONE_CHECK_RESPONSE; | 
					
						
							|  |  |  | 			ireq->sci_status = SCI_FAILURE_IO_RESPONSE_VALID; | 
					
						
							| 
									
										
										
										
											2011-06-27 14:57:03 -07:00
										 |  |  | 			sci_change_state(&ireq->sm, SCI_REQ_COMPLETED); | 
					
						
							| 
									
										
										
										
											2011-05-11 08:27:47 -07:00
										 |  |  | 		} else { | 
					
						
							| 
									
										
										
										
											2011-06-27 14:57:03 -07:00
										 |  |  | 			sci_change_state(&ireq->sm, SCI_REQ_STP_PIO_WAIT_FRAME); | 
					
						
							| 
									
										
										
										
											2011-05-11 08:27:47 -07:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		return status; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2011-06-02 00:10:43 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-09-30 18:52:19 -07:00
										 |  |  | 	case SCI_REQ_ATAPI_WAIT_PIO_SETUP: { | 
					
						
							|  |  |  | 		struct sas_task *task = isci_request_access_task(ireq); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		sci_controller_release_frame(ihost, frame_index); | 
					
						
							|  |  |  | 		ireq->target_device->working_request = ireq; | 
					
						
							|  |  |  | 		if (task->data_dir == DMA_NONE) { | 
					
						
							|  |  |  | 			sci_change_state(&ireq->sm, SCI_REQ_ATAPI_WAIT_TC_COMP); | 
					
						
							|  |  |  | 			scu_atapi_reconstruct_raw_frame_task_context(ireq); | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			sci_change_state(&ireq->sm, SCI_REQ_ATAPI_WAIT_D2H); | 
					
						
							|  |  |  | 			scu_atapi_construct_task_context(ireq); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		sci_controller_continue_io(ireq); | 
					
						
							|  |  |  | 		return SCI_SUCCESS; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	case SCI_REQ_ATAPI_WAIT_D2H: | 
					
						
							|  |  |  | 		return atapi_d2h_reg_frame_handler(ireq, frame_index); | 
					
						
							| 
									
										
										
										
											2011-06-02 00:10:43 +00:00
										 |  |  | 	case SCI_REQ_ABORTING: | 
					
						
							|  |  |  | 		/*
 | 
					
						
							|  |  |  | 		 * TODO: Is it even possible to get an unsolicited frame in the | 
					
						
							| 
									
										
										
										
											2011-05-11 08:27:47 -07:00
										 |  |  | 		 * aborting state? | 
					
						
							|  |  |  | 		 */ | 
					
						
							| 
									
										
										
										
											2011-06-30 19:14:33 -07:00
										 |  |  | 		sci_controller_release_frame(ihost, frame_index); | 
					
						
							| 
									
										
										
										
											2011-05-11 08:27:47 -07:00
										 |  |  | 		return SCI_SUCCESS; | 
					
						
							| 
									
										
										
										
											2011-06-02 00:10:43 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-11 08:27:47 -07:00
										 |  |  | 	default: | 
					
						
							| 
									
										
										
										
											2011-06-30 17:38:32 -07:00
										 |  |  | 		dev_warn(&ihost->pdev->dev, | 
					
						
							| 
									
										
										
										
											2011-06-02 00:10:43 +00:00
										 |  |  | 			 "%s: SCIC IO Request given unexpected frame %x while " | 
					
						
							|  |  |  | 			 "in state %d\n", | 
					
						
							|  |  |  | 			 __func__, | 
					
						
							|  |  |  | 			 frame_index, | 
					
						
							|  |  |  | 			 state); | 
					
						
							| 
									
										
										
										
											2011-05-11 08:27:47 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-30 19:14:33 -07:00
										 |  |  | 		sci_controller_release_frame(ihost, frame_index); | 
					
						
							| 
									
										
										
										
											2011-05-11 08:27:47 -07:00
										 |  |  | 		return SCI_FAILURE_INVALID_STATE; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-27 14:57:03 -07:00
										 |  |  | static enum sci_status stp_request_udma_await_tc_event(struct isci_request *ireq, | 
					
						
							| 
									
										
										
										
											2011-05-11 08:27:47 -07:00
										 |  |  | 						       u32 completion_code) | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:49 -07:00
										 |  |  | { | 
					
						
							|  |  |  | 	enum sci_status status = SCI_SUCCESS; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	switch (SCU_GET_COMPLETION_TL_STATUS(completion_code)) { | 
					
						
							|  |  |  | 	case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_GOOD): | 
					
						
							| 
									
										
										
										
											2011-07-01 02:25:15 -07:00
										 |  |  | 		ireq->scu_status = SCU_TASK_DONE_GOOD; | 
					
						
							|  |  |  | 		ireq->sci_status = SCI_SUCCESS; | 
					
						
							|  |  |  | 		sci_change_state(&ireq->sm, SCI_REQ_COMPLETED); | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:49 -07:00
										 |  |  | 		break; | 
					
						
							|  |  |  | 	case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_UNEXP_FIS): | 
					
						
							|  |  |  | 	case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_REG_ERR): | 
					
						
							| 
									
										
										
										
											2011-05-11 08:27:47 -07:00
										 |  |  | 		/* We must check ther response buffer to see if the D2H
 | 
					
						
							|  |  |  | 		 * Register FIS was received before we got the TC | 
					
						
							|  |  |  | 		 * completion. | 
					
						
							|  |  |  | 		 */ | 
					
						
							| 
									
										
										
										
											2011-06-27 14:57:03 -07:00
										 |  |  | 		if (ireq->stp.rsp.fis_type == FIS_REGD2H) { | 
					
						
							| 
									
										
										
										
											2012-03-08 22:42:09 -08:00
										 |  |  | 			sci_remote_device_suspend(ireq->target_device, | 
					
						
							|  |  |  | 						  SCI_SW_SUSPEND_NORMAL); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-07-01 02:25:15 -07:00
										 |  |  | 			ireq->scu_status = SCU_TASK_DONE_CHECK_RESPONSE; | 
					
						
							|  |  |  | 			ireq->sci_status = SCI_FAILURE_IO_RESPONSE_VALID; | 
					
						
							|  |  |  | 			sci_change_state(&ireq->sm, SCI_REQ_COMPLETED); | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:49 -07:00
										 |  |  | 		} else { | 
					
						
							| 
									
										
										
										
											2011-05-11 08:27:47 -07:00
										 |  |  | 			/* If we have an error completion status for the
 | 
					
						
							|  |  |  | 			 * TC then we can expect a D2H register FIS from | 
					
						
							|  |  |  | 			 * the device so we must change state to wait | 
					
						
							|  |  |  | 			 * for it | 
					
						
							|  |  |  | 			 */ | 
					
						
							| 
									
										
										
										
											2011-06-27 14:57:03 -07:00
										 |  |  | 			sci_change_state(&ireq->sm, SCI_REQ_STP_UDMA_WAIT_D2H); | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:49 -07:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-11 08:27:47 -07:00
										 |  |  | 	/* TODO Check to see if any of these completion status need to
 | 
					
						
							|  |  |  | 	 * wait for the device to host register fis. | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	/* TODO We can retry the command for SCU_TASK_DONE_CMD_LL_R_ERR
 | 
					
						
							|  |  |  | 	 * - this comes only for B0 | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:49 -07:00
										 |  |  | 	default: | 
					
						
							|  |  |  | 		/* All other completion status cause the IO to be complete. */ | 
					
						
							| 
									
										
										
										
											2011-07-01 02:25:15 -07:00
										 |  |  | 		ireq->scu_status = SCU_NORMALIZE_COMPLETION_STATUS(completion_code); | 
					
						
							|  |  |  | 		ireq->sci_status = SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR; | 
					
						
							|  |  |  | 		sci_change_state(&ireq->sm, SCI_REQ_COMPLETED); | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:49 -07:00
										 |  |  | 		break; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return status; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-09-30 18:52:19 -07:00
										 |  |  | static enum sci_status atapi_raw_completion(struct isci_request *ireq, u32 completion_code, | 
					
						
							|  |  |  | 						  enum sci_base_request_states next) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	enum sci_status status = SCI_SUCCESS; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	switch (SCU_GET_COMPLETION_TL_STATUS(completion_code)) { | 
					
						
							|  |  |  | 	case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_GOOD): | 
					
						
							|  |  |  | 		ireq->scu_status = SCU_TASK_DONE_GOOD; | 
					
						
							|  |  |  | 		ireq->sci_status = SCI_SUCCESS; | 
					
						
							|  |  |  | 		sci_change_state(&ireq->sm, next); | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	default: | 
					
						
							|  |  |  | 		/* All other completion status cause the IO to be complete.
 | 
					
						
							|  |  |  | 		 * If a NAK was received, then it is up to the user to retry | 
					
						
							|  |  |  | 		 * the request. | 
					
						
							|  |  |  | 		 */ | 
					
						
							|  |  |  | 		ireq->scu_status = SCU_NORMALIZE_COMPLETION_STATUS(completion_code); | 
					
						
							|  |  |  | 		ireq->sci_status = SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		sci_change_state(&ireq->sm, SCI_REQ_COMPLETED); | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return status; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static enum sci_status atapi_data_tc_completion_handler(struct isci_request *ireq, | 
					
						
							|  |  |  | 							u32 completion_code) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct isci_remote_device *idev = ireq->target_device; | 
					
						
							|  |  |  | 	struct dev_to_host_fis *d2h = &ireq->stp.rsp; | 
					
						
							|  |  |  | 	enum sci_status status = SCI_SUCCESS; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	switch (SCU_GET_COMPLETION_TL_STATUS(completion_code)) { | 
					
						
							|  |  |  | 	case (SCU_TASK_DONE_GOOD << SCU_COMPLETION_TL_STATUS_SHIFT): | 
					
						
							|  |  |  | 		sci_change_state(&ireq->sm, SCI_REQ_COMPLETED); | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	case (SCU_TASK_DONE_UNEXP_FIS << SCU_COMPLETION_TL_STATUS_SHIFT): { | 
					
						
							|  |  |  | 		u16 len = sci_req_tx_bytes(ireq); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		/* likely non-error data underrrun, workaround missing
 | 
					
						
							|  |  |  | 		 * d2h frame from the controller | 
					
						
							|  |  |  | 		 */ | 
					
						
							|  |  |  | 		if (d2h->fis_type != FIS_REGD2H) { | 
					
						
							|  |  |  | 			d2h->fis_type = FIS_REGD2H; | 
					
						
							|  |  |  | 			d2h->flags = (1 << 6); | 
					
						
							|  |  |  | 			d2h->status = 0x50; | 
					
						
							|  |  |  | 			d2h->error = 0; | 
					
						
							|  |  |  | 			d2h->lbal = 0; | 
					
						
							|  |  |  | 			d2h->byte_count_low = len & 0xff; | 
					
						
							|  |  |  | 			d2h->byte_count_high = len >> 8; | 
					
						
							|  |  |  | 			d2h->device = 0xa0; | 
					
						
							|  |  |  | 			d2h->lbal_exp = 0; | 
					
						
							|  |  |  | 			d2h->lbam_exp = 0; | 
					
						
							|  |  |  | 			d2h->lbah_exp = 0; | 
					
						
							|  |  |  | 			d2h->_r_a = 0; | 
					
						
							|  |  |  | 			d2h->sector_count = 0x3; | 
					
						
							|  |  |  | 			d2h->sector_count_exp = 0; | 
					
						
							|  |  |  | 			d2h->_r_b = 0; | 
					
						
							|  |  |  | 			d2h->_r_c = 0; | 
					
						
							|  |  |  | 			d2h->_r_d = 0; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		ireq->scu_status = SCU_TASK_DONE_GOOD; | 
					
						
							|  |  |  | 		ireq->sci_status = SCI_SUCCESS_IO_DONE_EARLY; | 
					
						
							|  |  |  | 		status = ireq->sci_status; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		/* the hw will have suspended the rnc, so complete the
 | 
					
						
							|  |  |  | 		 * request upon pending resume | 
					
						
							|  |  |  | 		 */ | 
					
						
							|  |  |  | 		sci_change_state(&idev->sm, SCI_STP_DEV_ATAPI_ERROR); | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	case (SCU_TASK_DONE_EXCESS_DATA << SCU_COMPLETION_TL_STATUS_SHIFT): | 
					
						
							|  |  |  | 		/* In this case, there is no UF coming after.
 | 
					
						
							|  |  |  | 		 * compelte the IO now. | 
					
						
							|  |  |  | 		 */ | 
					
						
							|  |  |  | 		ireq->scu_status = SCU_TASK_DONE_GOOD; | 
					
						
							|  |  |  | 		ireq->sci_status = SCI_SUCCESS; | 
					
						
							|  |  |  | 		sci_change_state(&ireq->sm, SCI_REQ_COMPLETED); | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	default: | 
					
						
							|  |  |  | 		if (d2h->fis_type == FIS_REGD2H) { | 
					
						
							|  |  |  | 			/* UF received change the device state to ATAPI_ERROR */ | 
					
						
							|  |  |  | 			status = ireq->sci_status; | 
					
						
							|  |  |  | 			sci_change_state(&idev->sm, SCI_STP_DEV_ATAPI_ERROR); | 
					
						
							|  |  |  | 		} else { | 
					
						
							| 
									
										
										
										
											2012-09-01 10:31:09 -07:00
										 |  |  | 			/* If receiving any non-success TC status, no UF
 | 
					
						
							| 
									
										
										
										
											2011-09-30 18:52:19 -07:00
										 |  |  | 			 * received yet, then an UF for the status fis | 
					
						
							|  |  |  | 			 * is coming after (XXX: suspect this is | 
					
						
							|  |  |  | 			 * actually a protocol error or a bug like the | 
					
						
							|  |  |  | 			 * DONE_UNEXP_FIS case) | 
					
						
							|  |  |  | 			 */ | 
					
						
							|  |  |  | 			ireq->scu_status = SCU_TASK_DONE_CHECK_RESPONSE; | 
					
						
							|  |  |  | 			ireq->sci_status = SCI_FAILURE_IO_RESPONSE_VALID; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			sci_change_state(&ireq->sm, SCI_REQ_ATAPI_WAIT_D2H); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return status; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-08 22:41:50 -08:00
										 |  |  | static int sci_request_smp_completion_status_is_tx_suspend( | 
					
						
							|  |  |  | 	unsigned int completion_status) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	switch (completion_status) { | 
					
						
							|  |  |  | 	case SCU_TASK_OPEN_REJECT_WRONG_DESTINATION: | 
					
						
							|  |  |  | 	case SCU_TASK_OPEN_REJECT_RESERVED_ABANDON_1: | 
					
						
							|  |  |  | 	case SCU_TASK_OPEN_REJECT_RESERVED_ABANDON_2: | 
					
						
							|  |  |  | 	case SCU_TASK_OPEN_REJECT_RESERVED_ABANDON_3: | 
					
						
							|  |  |  | 	case SCU_TASK_OPEN_REJECT_BAD_DESTINATION: | 
					
						
							|  |  |  | 	case SCU_TASK_OPEN_REJECT_ZONE_VIOLATION: | 
					
						
							|  |  |  | 		return 1; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int sci_request_smp_completion_status_is_tx_rx_suspend( | 
					
						
							|  |  |  | 	unsigned int completion_status) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return 0; /* There are no Tx/Rx SMP suspend conditions. */ | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int sci_request_ssp_completion_status_is_tx_suspend( | 
					
						
							|  |  |  | 	unsigned int completion_status) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	switch (completion_status) { | 
					
						
							|  |  |  | 	case SCU_TASK_DONE_TX_RAW_CMD_ERR: | 
					
						
							|  |  |  | 	case SCU_TASK_DONE_LF_ERR: | 
					
						
							|  |  |  | 	case SCU_TASK_OPEN_REJECT_WRONG_DESTINATION: | 
					
						
							|  |  |  | 	case SCU_TASK_OPEN_REJECT_RESERVED_ABANDON_1: | 
					
						
							|  |  |  | 	case SCU_TASK_OPEN_REJECT_RESERVED_ABANDON_2: | 
					
						
							|  |  |  | 	case SCU_TASK_OPEN_REJECT_RESERVED_ABANDON_3: | 
					
						
							|  |  |  | 	case SCU_TASK_OPEN_REJECT_BAD_DESTINATION: | 
					
						
							|  |  |  | 	case SCU_TASK_OPEN_REJECT_ZONE_VIOLATION: | 
					
						
							|  |  |  | 	case SCU_TASK_OPEN_REJECT_STP_RESOURCES_BUSY: | 
					
						
							|  |  |  | 	case SCU_TASK_OPEN_REJECT_PROTOCOL_NOT_SUPPORTED: | 
					
						
							|  |  |  | 	case SCU_TASK_OPEN_REJECT_CONNECTION_RATE_NOT_SUPPORTED: | 
					
						
							|  |  |  | 		return 1; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int sci_request_ssp_completion_status_is_tx_rx_suspend( | 
					
						
							|  |  |  | 	unsigned int completion_status) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return 0; /* There are no Tx/Rx SSP suspend conditions. */ | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int sci_request_stpsata_completion_status_is_tx_suspend( | 
					
						
							|  |  |  | 	unsigned int completion_status) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	switch (completion_status) { | 
					
						
							|  |  |  | 	case SCU_TASK_DONE_TX_RAW_CMD_ERR: | 
					
						
							|  |  |  | 	case SCU_TASK_DONE_LL_R_ERR: | 
					
						
							|  |  |  | 	case SCU_TASK_DONE_LL_PERR: | 
					
						
							|  |  |  | 	case SCU_TASK_DONE_REG_ERR: | 
					
						
							|  |  |  | 	case SCU_TASK_DONE_SDB_ERR: | 
					
						
							|  |  |  | 	case SCU_TASK_OPEN_REJECT_WRONG_DESTINATION: | 
					
						
							|  |  |  | 	case SCU_TASK_OPEN_REJECT_RESERVED_ABANDON_1: | 
					
						
							|  |  |  | 	case SCU_TASK_OPEN_REJECT_RESERVED_ABANDON_2: | 
					
						
							|  |  |  | 	case SCU_TASK_OPEN_REJECT_RESERVED_ABANDON_3: | 
					
						
							|  |  |  | 	case SCU_TASK_OPEN_REJECT_BAD_DESTINATION: | 
					
						
							|  |  |  | 	case SCU_TASK_OPEN_REJECT_ZONE_VIOLATION: | 
					
						
							|  |  |  | 	case SCU_TASK_OPEN_REJECT_STP_RESOURCES_BUSY: | 
					
						
							|  |  |  | 	case SCU_TASK_OPEN_REJECT_PROTOCOL_NOT_SUPPORTED: | 
					
						
							|  |  |  | 	case SCU_TASK_OPEN_REJECT_CONNECTION_RATE_NOT_SUPPORTED: | 
					
						
							|  |  |  | 		return 1; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int sci_request_stpsata_completion_status_is_tx_rx_suspend( | 
					
						
							|  |  |  | 	unsigned int completion_status) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	switch (completion_status) { | 
					
						
							|  |  |  | 	case SCU_TASK_DONE_LF_ERR: | 
					
						
							|  |  |  | 	case SCU_TASK_DONE_LL_SY_TERM: | 
					
						
							|  |  |  | 	case SCU_TASK_DONE_LL_LF_TERM: | 
					
						
							|  |  |  | 	case SCU_TASK_DONE_BREAK_RCVD: | 
					
						
							|  |  |  | 	case SCU_TASK_DONE_INV_FIS_LEN: | 
					
						
							|  |  |  | 	case SCU_TASK_DONE_UNEXP_FIS: | 
					
						
							|  |  |  | 	case SCU_TASK_DONE_UNEXP_SDBFIS: | 
					
						
							|  |  |  | 	case SCU_TASK_DONE_MAX_PLD_ERR: | 
					
						
							|  |  |  | 		return 1; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void sci_request_handle_suspending_completions( | 
					
						
							|  |  |  | 	struct isci_request *ireq, | 
					
						
							|  |  |  | 	u32 completion_code) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	int is_tx = 0; | 
					
						
							|  |  |  | 	int is_tx_rx = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	switch (ireq->protocol) { | 
					
						
							|  |  |  | 	case SAS_PROTOCOL_SMP: | 
					
						
							|  |  |  | 		is_tx = sci_request_smp_completion_status_is_tx_suspend( | 
					
						
							|  |  |  | 			completion_code); | 
					
						
							|  |  |  | 		is_tx_rx = sci_request_smp_completion_status_is_tx_rx_suspend( | 
					
						
							|  |  |  | 			completion_code); | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	case SAS_PROTOCOL_SSP: | 
					
						
							|  |  |  | 		is_tx = sci_request_ssp_completion_status_is_tx_suspend( | 
					
						
							|  |  |  | 			completion_code); | 
					
						
							|  |  |  | 		is_tx_rx = sci_request_ssp_completion_status_is_tx_rx_suspend( | 
					
						
							|  |  |  | 			completion_code); | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	case SAS_PROTOCOL_STP: | 
					
						
							|  |  |  | 		is_tx = sci_request_stpsata_completion_status_is_tx_suspend( | 
					
						
							|  |  |  | 			completion_code); | 
					
						
							|  |  |  | 		is_tx_rx = | 
					
						
							|  |  |  | 			sci_request_stpsata_completion_status_is_tx_rx_suspend( | 
					
						
							|  |  |  | 				completion_code); | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	default: | 
					
						
							|  |  |  | 		dev_warn(&ireq->isci_host->pdev->dev, | 
					
						
							|  |  |  | 			 "%s: request %p has no valid protocol\n", | 
					
						
							|  |  |  | 			 __func__, ireq); | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	if (is_tx || is_tx_rx) { | 
					
						
							|  |  |  | 		BUG_ON(is_tx && is_tx_rx); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		sci_remote_node_context_suspend( | 
					
						
							|  |  |  | 			&ireq->target_device->rnc, | 
					
						
							| 
									
										
										
										
											2012-03-08 22:41:58 -08:00
										 |  |  | 			SCI_HW_SUSPEND, | 
					
						
							| 
									
										
										
										
											2012-03-08 22:41:50 -08:00
										 |  |  | 			(is_tx_rx) ? SCU_EVENT_TL_RNC_SUSPEND_TX_RX | 
					
						
							| 
									
										
										
										
											2012-03-08 22:41:59 -08:00
										 |  |  | 				   : SCU_EVENT_TL_RNC_SUSPEND_TX); | 
					
						
							| 
									
										
										
										
											2012-03-08 22:41:50 -08:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-11 08:27:47 -07:00
										 |  |  | enum sci_status | 
					
						
							| 
									
										
										
										
											2011-06-30 19:14:33 -07:00
										 |  |  | sci_io_request_tc_completion(struct isci_request *ireq, | 
					
						
							| 
									
										
										
										
											2012-03-08 22:41:50 -08:00
										 |  |  | 			     u32 completion_code) | 
					
						
							| 
									
										
										
										
											2011-05-11 08:27:47 -07:00
										 |  |  | { | 
					
						
							|  |  |  | 	enum sci_base_request_states state; | 
					
						
							| 
									
										
										
										
											2011-06-30 17:38:32 -07:00
										 |  |  | 	struct isci_host *ihost = ireq->owning_controller; | 
					
						
							| 
									
										
										
										
											2011-05-11 08:27:47 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-27 14:57:03 -07:00
										 |  |  | 	state = ireq->sm.current_state_id; | 
					
						
							| 
									
										
										
										
											2011-05-11 08:27:47 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-08 22:41:50 -08:00
										 |  |  | 	/* Decode those completions that signal upcoming suspension events. */ | 
					
						
							|  |  |  | 	sci_request_handle_suspending_completions( | 
					
						
							|  |  |  | 		ireq, SCU_GET_COMPLETION_TL_STATUS(completion_code)); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-11 08:27:47 -07:00
										 |  |  | 	switch (state) { | 
					
						
							| 
									
										
										
										
											2011-06-02 00:10:43 +00:00
										 |  |  | 	case SCI_REQ_STARTED: | 
					
						
							| 
									
										
										
										
											2011-06-27 14:57:03 -07:00
										 |  |  | 		return request_started_state_tc_event(ireq, completion_code); | 
					
						
							| 
									
										
										
										
											2011-06-02 00:10:43 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	case SCI_REQ_TASK_WAIT_TC_COMP: | 
					
						
							| 
									
										
										
										
											2011-06-27 14:57:03 -07:00
										 |  |  | 		return ssp_task_request_await_tc_event(ireq, | 
					
						
							| 
									
										
										
										
											2011-06-02 00:10:43 +00:00
										 |  |  | 						       completion_code); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	case SCI_REQ_SMP_WAIT_RESP: | 
					
						
							| 
									
										
										
										
											2011-06-27 14:57:03 -07:00
										 |  |  | 		return smp_request_await_response_tc_event(ireq, | 
					
						
							| 
									
										
										
										
											2011-06-02 00:10:43 +00:00
										 |  |  | 							   completion_code); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	case SCI_REQ_SMP_WAIT_TC_COMP: | 
					
						
							| 
									
										
										
										
											2011-06-27 14:57:03 -07:00
										 |  |  | 		return smp_request_await_tc_event(ireq, completion_code); | 
					
						
							| 
									
										
										
										
											2011-06-02 00:10:43 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	case SCI_REQ_STP_UDMA_WAIT_TC_COMP: | 
					
						
							| 
									
										
										
										
											2011-06-27 14:57:03 -07:00
										 |  |  | 		return stp_request_udma_await_tc_event(ireq, | 
					
						
							| 
									
										
										
										
											2011-06-02 00:10:43 +00:00
										 |  |  | 						       completion_code); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	case SCI_REQ_STP_NON_DATA_WAIT_H2D: | 
					
						
							| 
									
										
										
										
											2011-06-27 14:57:03 -07:00
										 |  |  | 		return stp_request_non_data_await_h2d_tc_event(ireq, | 
					
						
							| 
									
										
										
										
											2011-06-02 00:10:43 +00:00
										 |  |  | 							       completion_code); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	case SCI_REQ_STP_PIO_WAIT_H2D: | 
					
						
							| 
									
										
										
										
											2011-06-27 14:57:03 -07:00
										 |  |  | 		return stp_request_pio_await_h2d_completion_tc_event(ireq, | 
					
						
							| 
									
										
										
										
											2011-06-02 00:10:43 +00:00
										 |  |  | 								     completion_code); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	case SCI_REQ_STP_PIO_DATA_OUT: | 
					
						
							| 
									
										
										
										
											2011-06-27 14:57:03 -07:00
										 |  |  | 		return pio_data_out_tx_done_tc_event(ireq, completion_code); | 
					
						
							| 
									
										
										
										
											2011-06-02 00:10:43 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	case SCI_REQ_ABORTING: | 
					
						
							| 
									
										
										
										
											2011-06-27 14:57:03 -07:00
										 |  |  | 		return request_aborting_state_tc_event(ireq, | 
					
						
							| 
									
										
										
										
											2011-06-02 00:10:43 +00:00
										 |  |  | 						       completion_code); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-09-30 18:52:19 -07:00
										 |  |  | 	case SCI_REQ_ATAPI_WAIT_H2D: | 
					
						
							|  |  |  | 		return atapi_raw_completion(ireq, completion_code, | 
					
						
							|  |  |  | 					    SCI_REQ_ATAPI_WAIT_PIO_SETUP); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	case SCI_REQ_ATAPI_WAIT_TC_COMP: | 
					
						
							|  |  |  | 		return atapi_raw_completion(ireq, completion_code, | 
					
						
							|  |  |  | 					    SCI_REQ_ATAPI_WAIT_D2H); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	case SCI_REQ_ATAPI_WAIT_D2H: | 
					
						
							|  |  |  | 		return atapi_data_tc_completion_handler(ireq, completion_code); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-02 00:10:43 +00:00
										 |  |  | 	default: | 
					
						
							| 
									
										
										
										
											2012-02-10 01:18:44 -08:00
										 |  |  | 		dev_warn(&ihost->pdev->dev, "%s: %x in wrong state %s\n", | 
					
						
							|  |  |  | 			 __func__, completion_code, req_state_name(state)); | 
					
						
							| 
									
										
										
										
											2011-06-02 00:10:43 +00:00
										 |  |  | 		return SCI_FAILURE_INVALID_STATE; | 
					
						
							| 
									
										
										
										
											2011-05-11 08:27:47 -07:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-07-02 22:56:22 -07:00
										 |  |  | /**
 | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  |  * isci_request_process_response_iu() - This function sets the status and | 
					
						
							|  |  |  |  *    response iu, in the task struct, from the request object for the upper | 
					
						
							|  |  |  |  *    layer driver. | 
					
						
							|  |  |  |  * @sas_task: This parameter is the task struct from the upper layer driver. | 
					
						
							|  |  |  |  * @resp_iu: This parameter points to the response iu of the completed request. | 
					
						
							|  |  |  |  * @dev: This parameter specifies the linux device struct. | 
					
						
							| 
									
										
										
										
											2011-07-02 22:56:22 -07:00
										 |  |  |  * | 
					
						
							|  |  |  |  * none. | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | static void isci_request_process_response_iu( | 
					
						
							|  |  |  | 	struct sas_task *task, | 
					
						
							|  |  |  | 	struct ssp_response_iu *resp_iu, | 
					
						
							|  |  |  | 	struct device *dev) | 
					
						
							| 
									
										
										
										
											2011-07-02 22:56:22 -07:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 	dev_dbg(dev, | 
					
						
							|  |  |  | 		"%s: resp_iu = %p " | 
					
						
							|  |  |  | 		"resp_iu->status = 0x%x,\nresp_iu->datapres = %d " | 
					
						
							|  |  |  | 		"resp_iu->response_data_len = %x, " | 
					
						
							|  |  |  | 		"resp_iu->sense_data_len = %x\nrepsonse data: ", | 
					
						
							| 
									
										
										
										
											2011-07-02 22:56:22 -07:00
										 |  |  | 		__func__, | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 		resp_iu, | 
					
						
							|  |  |  | 		resp_iu->status, | 
					
						
							|  |  |  | 		resp_iu->datapres, | 
					
						
							|  |  |  | 		resp_iu->response_data_len, | 
					
						
							|  |  |  | 		resp_iu->sense_data_len); | 
					
						
							| 
									
										
										
										
											2011-07-02 22:56:22 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 	task->task_status.stat = resp_iu->status; | 
					
						
							| 
									
										
										
										
											2011-07-02 22:56:22 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 	/* libsas updates the task status fields based on the response iu. */ | 
					
						
							|  |  |  | 	sas_ssp_task_response(dev, task, resp_iu); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2011-07-02 22:56:22 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | /**
 | 
					
						
							|  |  |  |  * isci_request_set_open_reject_status() - This function prepares the I/O | 
					
						
							|  |  |  |  *    completion for OPEN_REJECT conditions. | 
					
						
							|  |  |  |  * @request: This parameter is the completed isci_request object. | 
					
						
							|  |  |  |  * @response_ptr: This parameter specifies the service response for the I/O. | 
					
						
							|  |  |  |  * @status_ptr: This parameter specifies the exec status for the I/O. | 
					
						
							|  |  |  |  * @open_rej_reason: This parameter specifies the encoded reason for the | 
					
						
							|  |  |  |  *    abandon-class reject. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * none. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | static void isci_request_set_open_reject_status( | 
					
						
							|  |  |  | 	struct isci_request *request, | 
					
						
							|  |  |  | 	struct sas_task *task, | 
					
						
							|  |  |  | 	enum service_response *response_ptr, | 
					
						
							|  |  |  | 	enum exec_status *status_ptr, | 
					
						
							|  |  |  | 	enum sas_open_rej_reason open_rej_reason) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	/* Task in the target is done. */ | 
					
						
							| 
									
										
										
										
											2011-06-23 14:33:48 -07:00
										 |  |  | 	set_bit(IREQ_COMPLETE_IN_TARGET, &request->flags); | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 	*response_ptr                     = SAS_TASK_UNDELIVERED; | 
					
						
							|  |  |  | 	*status_ptr                       = SAS_OPEN_REJECT; | 
					
						
							|  |  |  | 	task->task_status.open_rej_reason = open_rej_reason; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2011-07-02 22:56:22 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | /**
 | 
					
						
							|  |  |  |  * isci_request_handle_controller_specific_errors() - This function decodes | 
					
						
							|  |  |  |  *    controller-specific I/O completion error conditions. | 
					
						
							|  |  |  |  * @request: This parameter is the completed isci_request object. | 
					
						
							|  |  |  |  * @response_ptr: This parameter specifies the service response for the I/O. | 
					
						
							|  |  |  |  * @status_ptr: This parameter specifies the exec status for the I/O. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * none. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | static void isci_request_handle_controller_specific_errors( | 
					
						
							| 
									
										
										
										
											2011-06-13 17:39:44 -07:00
										 |  |  | 	struct isci_remote_device *idev, | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 	struct isci_request *request, | 
					
						
							|  |  |  | 	struct sas_task *task, | 
					
						
							|  |  |  | 	enum service_response *response_ptr, | 
					
						
							| 
									
										
										
										
											2012-03-08 22:41:54 -08:00
										 |  |  | 	enum exec_status *status_ptr) | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | { | 
					
						
							|  |  |  | 	unsigned int cstatus; | 
					
						
							| 
									
										
										
										
											2011-07-02 22:56:22 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-27 14:57:03 -07:00
										 |  |  | 	cstatus = request->scu_status; | 
					
						
							| 
									
										
										
										
											2011-03-04 14:06:42 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 	dev_dbg(&request->isci_host->pdev->dev, | 
					
						
							|  |  |  | 		"%s: %p SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR " | 
					
						
							|  |  |  | 		"- controller status = 0x%x\n", | 
					
						
							|  |  |  | 		__func__, request, cstatus); | 
					
						
							| 
									
										
										
										
											2011-07-02 22:56:22 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 	/* Decode the controller-specific errors; most
 | 
					
						
							|  |  |  | 	 * important is to recognize those conditions in which | 
					
						
							|  |  |  | 	 * the target may still have a task outstanding that | 
					
						
							|  |  |  | 	 * must be aborted. | 
					
						
							|  |  |  | 	 * | 
					
						
							|  |  |  | 	 * Note that there are SCU completion codes being | 
					
						
							|  |  |  | 	 * named in the decode below for which SCIC has already | 
					
						
							|  |  |  | 	 * done work to handle them in a way other than as | 
					
						
							|  |  |  | 	 * a controller-specific completion code; these are left | 
					
						
							|  |  |  | 	 * in the decode below for completeness sake. | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	switch (cstatus) { | 
					
						
							|  |  |  | 	case SCU_TASK_DONE_DMASETUP_DIRERR: | 
					
						
							|  |  |  | 	/* Also SCU_TASK_DONE_SMP_FRM_TYPE_ERR: */ | 
					
						
							|  |  |  | 	case SCU_TASK_DONE_XFERCNT_ERR: | 
					
						
							|  |  |  | 		/* Also SCU_TASK_DONE_SMP_UFI_ERR: */ | 
					
						
							|  |  |  | 		if (task->task_proto == SAS_PROTOCOL_SMP) { | 
					
						
							|  |  |  | 			/* SCU_TASK_DONE_SMP_UFI_ERR == Task Done. */ | 
					
						
							|  |  |  | 			*response_ptr = SAS_TASK_COMPLETE; | 
					
						
							| 
									
										
										
										
											2011-07-02 22:56:22 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 			/* See if the device has been/is being stopped. Note
 | 
					
						
							|  |  |  | 			 * that we ignore the quiesce state, since we are | 
					
						
							| 
									
										
										
										
											2011-07-02 22:56:22 -07:00
										 |  |  | 			 * concerned about the actual device state. | 
					
						
							|  |  |  | 			 */ | 
					
						
							| 
									
										
										
										
											2011-06-13 17:39:44 -07:00
										 |  |  | 			if (!idev) | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 				*status_ptr = SAS_DEVICE_UNKNOWN; | 
					
						
							|  |  |  | 			else | 
					
						
							|  |  |  | 				*status_ptr = SAS_ABORTED_TASK; | 
					
						
							| 
									
										
										
										
											2011-07-02 22:56:22 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-23 14:33:48 -07:00
										 |  |  | 			set_bit(IREQ_COMPLETE_IN_TARGET, &request->flags); | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 		} else { | 
					
						
							|  |  |  | 			/* Task in the target is not done. */ | 
					
						
							|  |  |  | 			*response_ptr = SAS_TASK_UNDELIVERED; | 
					
						
							| 
									
										
										
										
											2011-03-04 14:06:42 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-13 17:39:44 -07:00
										 |  |  | 			if (!idev) | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 				*status_ptr = SAS_DEVICE_UNKNOWN; | 
					
						
							|  |  |  | 			else | 
					
						
							|  |  |  | 				*status_ptr = SAM_STAT_TASK_ABORTED; | 
					
						
							| 
									
										
										
										
											2011-07-02 22:56:22 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-23 14:33:48 -07:00
										 |  |  | 			clear_bit(IREQ_COMPLETE_IN_TARGET, &request->flags); | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	case SCU_TASK_DONE_CRC_ERR: | 
					
						
							|  |  |  | 	case SCU_TASK_DONE_NAK_CMD_ERR: | 
					
						
							|  |  |  | 	case SCU_TASK_DONE_EXCESS_DATA: | 
					
						
							|  |  |  | 	case SCU_TASK_DONE_UNEXP_FIS: | 
					
						
							|  |  |  | 	/* Also SCU_TASK_DONE_UNEXP_RESP: */ | 
					
						
							|  |  |  | 	case SCU_TASK_DONE_VIIT_ENTRY_NV:       /* TODO - conditions? */ | 
					
						
							|  |  |  | 	case SCU_TASK_DONE_IIT_ENTRY_NV:        /* TODO - conditions? */ | 
					
						
							|  |  |  | 	case SCU_TASK_DONE_RNCNV_OUTBOUND:      /* TODO - conditions? */ | 
					
						
							|  |  |  | 		/* These are conditions in which the target
 | 
					
						
							|  |  |  | 		 * has completed the task, so that no cleanup | 
					
						
							|  |  |  | 		 * is necessary. | 
					
						
							| 
									
										
										
										
											2011-07-02 22:56:22 -07:00
										 |  |  | 		 */ | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 		*response_ptr = SAS_TASK_COMPLETE; | 
					
						
							| 
									
										
										
										
											2011-07-02 22:56:22 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		/* See if the device has been/is being stopped. Note
 | 
					
						
							|  |  |  | 		 * that we ignore the quiesce state, since we are | 
					
						
							|  |  |  | 		 * concerned about the actual device state. | 
					
						
							|  |  |  | 		 */ | 
					
						
							| 
									
										
										
										
											2011-06-13 17:39:44 -07:00
										 |  |  | 		if (!idev) | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 			*status_ptr = SAS_DEVICE_UNKNOWN; | 
					
						
							| 
									
										
										
										
											2011-07-02 22:56:22 -07:00
										 |  |  | 		else | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 			*status_ptr = SAS_ABORTED_TASK; | 
					
						
							| 
									
										
										
										
											2011-07-02 22:56:22 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-23 14:33:48 -07:00
										 |  |  | 		set_bit(IREQ_COMPLETE_IN_TARGET, &request->flags); | 
					
						
							| 
									
										
										
										
											2011-07-02 22:56:22 -07:00
										 |  |  | 		break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 	/* Note that the only open reject completion codes seen here will be
 | 
					
						
							|  |  |  | 	 * abandon-class codes; all others are automatically retried in the SCU. | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	case SCU_TASK_OPEN_REJECT_WRONG_DESTINATION: | 
					
						
							| 
									
										
										
										
											2011-03-04 14:06:42 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 		isci_request_set_open_reject_status( | 
					
						
							|  |  |  | 			request, task, response_ptr, status_ptr, | 
					
						
							| 
									
										
										
										
											2012-03-08 22:41:54 -08:00
										 |  |  | 			SAS_OREJ_WRONG_DEST); | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 		break; | 
					
						
							| 
									
										
										
										
											2011-03-04 14:06:42 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 	case SCU_TASK_OPEN_REJECT_ZONE_VIOLATION: | 
					
						
							| 
									
										
										
										
											2011-07-02 22:56:22 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 		/* Note - the return of AB0 will change when
 | 
					
						
							|  |  |  | 		 * libsas implements detection of zone violations. | 
					
						
							|  |  |  | 		 */ | 
					
						
							|  |  |  | 		isci_request_set_open_reject_status( | 
					
						
							|  |  |  | 			request, task, response_ptr, status_ptr, | 
					
						
							| 
									
										
										
										
											2012-03-08 22:41:54 -08:00
										 |  |  | 			SAS_OREJ_RESV_AB0); | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 		break; | 
					
						
							| 
									
										
										
										
											2011-07-02 22:56:22 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 	case SCU_TASK_OPEN_REJECT_RESERVED_ABANDON_1: | 
					
						
							| 
									
										
										
										
											2011-07-02 22:56:22 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 		isci_request_set_open_reject_status( | 
					
						
							|  |  |  | 			request, task, response_ptr, status_ptr, | 
					
						
							| 
									
										
										
										
											2012-03-08 22:41:54 -08:00
										 |  |  | 			SAS_OREJ_RESV_AB1); | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 		break; | 
					
						
							| 
									
										
										
										
											2011-07-02 22:56:22 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 	case SCU_TASK_OPEN_REJECT_RESERVED_ABANDON_2: | 
					
						
							| 
									
										
										
										
											2011-07-02 22:56:22 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 		isci_request_set_open_reject_status( | 
					
						
							|  |  |  | 			request, task, response_ptr, status_ptr, | 
					
						
							| 
									
										
										
										
											2012-03-08 22:41:54 -08:00
										 |  |  | 			SAS_OREJ_RESV_AB2); | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 		break; | 
					
						
							| 
									
										
										
										
											2011-07-02 22:56:22 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 	case SCU_TASK_OPEN_REJECT_RESERVED_ABANDON_3: | 
					
						
							| 
									
										
										
										
											2011-07-02 22:56:22 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 		isci_request_set_open_reject_status( | 
					
						
							|  |  |  | 			request, task, response_ptr, status_ptr, | 
					
						
							| 
									
										
										
										
											2012-03-08 22:41:54 -08:00
										 |  |  | 			SAS_OREJ_RESV_AB3); | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 		break; | 
					
						
							| 
									
										
										
										
											2011-07-02 22:56:22 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 	case SCU_TASK_OPEN_REJECT_BAD_DESTINATION: | 
					
						
							| 
									
										
										
										
											2011-07-02 22:56:22 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 		isci_request_set_open_reject_status( | 
					
						
							|  |  |  | 			request, task, response_ptr, status_ptr, | 
					
						
							| 
									
										
										
										
											2012-03-08 22:41:54 -08:00
										 |  |  | 			SAS_OREJ_BAD_DEST); | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 		break; | 
					
						
							| 
									
										
										
										
											2011-07-02 22:56:22 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 	case SCU_TASK_OPEN_REJECT_STP_RESOURCES_BUSY: | 
					
						
							| 
									
										
										
										
											2011-07-02 22:56:22 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 		isci_request_set_open_reject_status( | 
					
						
							|  |  |  | 			request, task, response_ptr, status_ptr, | 
					
						
							| 
									
										
										
										
											2012-03-08 22:41:54 -08:00
										 |  |  | 			SAS_OREJ_STP_NORES); | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 		break; | 
					
						
							| 
									
										
										
										
											2011-07-02 22:56:22 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 	case SCU_TASK_OPEN_REJECT_PROTOCOL_NOT_SUPPORTED: | 
					
						
							| 
									
										
										
										
											2011-07-02 22:56:22 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 		isci_request_set_open_reject_status( | 
					
						
							|  |  |  | 			request, task, response_ptr, status_ptr, | 
					
						
							| 
									
										
										
										
											2012-03-08 22:41:54 -08:00
										 |  |  | 			SAS_OREJ_EPROTO); | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 		break; | 
					
						
							| 
									
										
										
										
											2011-07-02 22:56:22 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 	case SCU_TASK_OPEN_REJECT_CONNECTION_RATE_NOT_SUPPORTED: | 
					
						
							| 
									
										
										
										
											2011-07-02 22:56:22 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 		isci_request_set_open_reject_status( | 
					
						
							|  |  |  | 			request, task, response_ptr, status_ptr, | 
					
						
							| 
									
										
										
										
											2012-03-08 22:41:54 -08:00
										 |  |  | 			SAS_OREJ_CONN_RATE); | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 		break; | 
					
						
							| 
									
										
										
										
											2011-07-02 22:56:22 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 	case SCU_TASK_DONE_LL_R_ERR: | 
					
						
							|  |  |  | 	/* Also SCU_TASK_DONE_ACK_NAK_TO: */ | 
					
						
							|  |  |  | 	case SCU_TASK_DONE_LL_PERR: | 
					
						
							|  |  |  | 	case SCU_TASK_DONE_LL_SY_TERM: | 
					
						
							|  |  |  | 	/* Also SCU_TASK_DONE_NAK_ERR:*/ | 
					
						
							|  |  |  | 	case SCU_TASK_DONE_LL_LF_TERM: | 
					
						
							|  |  |  | 	/* Also SCU_TASK_DONE_DATA_LEN_ERR: */ | 
					
						
							|  |  |  | 	case SCU_TASK_DONE_LL_ABORT_ERR: | 
					
						
							|  |  |  | 	case SCU_TASK_DONE_SEQ_INV_TYPE: | 
					
						
							|  |  |  | 	/* Also SCU_TASK_DONE_UNEXP_XR: */ | 
					
						
							|  |  |  | 	case SCU_TASK_DONE_XR_IU_LEN_ERR: | 
					
						
							|  |  |  | 	case SCU_TASK_DONE_INV_FIS_LEN: | 
					
						
							|  |  |  | 	/* Also SCU_TASK_DONE_XR_WD_LEN: */ | 
					
						
							|  |  |  | 	case SCU_TASK_DONE_SDMA_ERR: | 
					
						
							|  |  |  | 	case SCU_TASK_DONE_OFFSET_ERR: | 
					
						
							|  |  |  | 	case SCU_TASK_DONE_MAX_PLD_ERR: | 
					
						
							|  |  |  | 	case SCU_TASK_DONE_LF_ERR: | 
					
						
							|  |  |  | 	case SCU_TASK_DONE_SMP_RESP_TO_ERR:  /* Escalate to dev reset? */ | 
					
						
							|  |  |  | 	case SCU_TASK_DONE_SMP_LL_RX_ERR: | 
					
						
							|  |  |  | 	case SCU_TASK_DONE_UNEXP_DATA: | 
					
						
							|  |  |  | 	case SCU_TASK_DONE_UNEXP_SDBFIS: | 
					
						
							|  |  |  | 	case SCU_TASK_DONE_REG_ERR: | 
					
						
							|  |  |  | 	case SCU_TASK_DONE_SDB_ERR: | 
					
						
							|  |  |  | 	case SCU_TASK_DONE_TASK_ABORT: | 
					
						
							|  |  |  | 	default: | 
					
						
							|  |  |  | 		/* Task in the target is not done. */ | 
					
						
							|  |  |  | 		*response_ptr = SAS_TASK_UNDELIVERED; | 
					
						
							|  |  |  | 		*status_ptr = SAM_STAT_TASK_ABORTED; | 
					
						
							| 
									
										
										
										
											2011-07-02 22:56:22 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-08 22:41:54 -08:00
										 |  |  | 		if (task->task_proto == SAS_PROTOCOL_SMP) | 
					
						
							| 
									
										
										
										
											2011-06-23 14:33:48 -07:00
										 |  |  | 			set_bit(IREQ_COMPLETE_IN_TARGET, &request->flags); | 
					
						
							| 
									
										
										
										
											2012-03-08 22:41:54 -08:00
										 |  |  | 		else | 
					
						
							| 
									
										
										
										
											2011-06-23 14:33:48 -07:00
										 |  |  | 			clear_bit(IREQ_COMPLETE_IN_TARGET, &request->flags); | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 		break; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-07-29 17:16:40 -07:00
										 |  |  | static void isci_process_stp_response(struct sas_task *task, struct dev_to_host_fis *fis) | 
					
						
							| 
									
										
										
										
											2011-07-01 10:52:55 -07:00
										 |  |  | { | 
					
						
							|  |  |  | 	struct task_status_struct *ts = &task->task_status; | 
					
						
							|  |  |  | 	struct ata_task_resp *resp = (void *)&ts->buf[0]; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-07-29 17:16:40 -07:00
										 |  |  | 	resp->frame_len = sizeof(*fis); | 
					
						
							|  |  |  | 	memcpy(resp->ending_fis, fis, sizeof(*fis)); | 
					
						
							| 
									
										
										
										
											2011-07-01 10:52:55 -07:00
										 |  |  | 	ts->buf_valid_size = sizeof(*resp); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-06 12:23:15 -08:00
										 |  |  | 	/* If an error is flagged let libata decode the fis */ | 
					
						
							|  |  |  | 	if (ac_err_mask(fis->status)) | 
					
						
							| 
									
										
										
										
											2011-07-01 10:52:55 -07:00
										 |  |  | 		ts->stat = SAS_PROTO_RESPONSE; | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 		ts->stat = SAM_STAT_GOOD; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	ts->resp = SAS_TASK_COMPLETE; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-30 17:38:32 -07:00
										 |  |  | static void isci_request_io_request_complete(struct isci_host *ihost, | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 					     struct isci_request *request, | 
					
						
							|  |  |  | 					     enum sci_io_status completion_status) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct sas_task *task = isci_request_access_task(request); | 
					
						
							|  |  |  | 	struct ssp_response_iu *resp_iu; | 
					
						
							|  |  |  | 	unsigned long task_flags; | 
					
						
							| 
									
										
										
										
											2011-10-27 15:04:50 -07:00
										 |  |  | 	struct isci_remote_device *idev = request->target_device; | 
					
						
							|  |  |  | 	enum service_response response = SAS_TASK_UNDELIVERED; | 
					
						
							|  |  |  | 	enum exec_status status = SAS_ABORTED_TASK; | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-30 17:38:32 -07:00
										 |  |  | 	dev_dbg(&ihost->pdev->dev, | 
					
						
							| 
									
										
										
										
											2012-03-04 12:44:53 +00:00
										 |  |  | 		"%s: request = %p, task = %p, " | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 		"task->data_dir = %d completion_status = 0x%x\n", | 
					
						
							| 
									
										
										
										
											2012-03-04 12:44:53 +00:00
										 |  |  | 		__func__, request, task, task->data_dir, completion_status); | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-08 22:41:54 -08:00
										 |  |  | 	/* The request is done from an SCU HW perspective. */ | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-08 22:41:54 -08:00
										 |  |  | 	/* This is an active request being completed from the core. */ | 
					
						
							|  |  |  | 	switch (completion_status) { | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-08 22:41:54 -08:00
										 |  |  | 	case SCI_IO_FAILURE_RESPONSE_VALID: | 
					
						
							|  |  |  | 		dev_dbg(&ihost->pdev->dev, | 
					
						
							|  |  |  | 			"%s: SCI_IO_FAILURE_RESPONSE_VALID (%p/%p)\n", | 
					
						
							|  |  |  | 			__func__, request, task); | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-08 22:41:54 -08:00
										 |  |  | 		if (sas_protocol_ata(task->task_proto)) { | 
					
						
							|  |  |  | 			isci_process_stp_response(task, &request->stp.rsp); | 
					
						
							|  |  |  | 		} else if (SAS_PROTOCOL_SSP == task->task_proto) { | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-08 22:41:54 -08:00
										 |  |  | 			/* crack the iu response buffer. */ | 
					
						
							|  |  |  | 			resp_iu = &request->ssp.rsp; | 
					
						
							|  |  |  | 			isci_request_process_response_iu(task, resp_iu, | 
					
						
							|  |  |  | 							 &ihost->pdev->dev); | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-08 22:41:54 -08:00
										 |  |  | 		} else if (SAS_PROTOCOL_SMP == task->task_proto) { | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-08 22:41:54 -08:00
										 |  |  | 			dev_err(&ihost->pdev->dev, | 
					
						
							|  |  |  | 				"%s: SCI_IO_FAILURE_RESPONSE_VALID: " | 
					
						
							|  |  |  | 					"SAS_PROTOCOL_SMP protocol\n", | 
					
						
							|  |  |  | 				__func__); | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-08 22:41:54 -08:00
										 |  |  | 		} else | 
					
						
							|  |  |  | 			dev_err(&ihost->pdev->dev, | 
					
						
							|  |  |  | 				"%s: unknown protocol\n", __func__); | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-08 22:41:54 -08:00
										 |  |  | 		/* use the task status set in the task struct by the
 | 
					
						
							|  |  |  | 		* isci_request_process_response_iu call. | 
					
						
							|  |  |  | 		*/ | 
					
						
							|  |  |  | 		set_bit(IREQ_COMPLETE_IN_TARGET, &request->flags); | 
					
						
							|  |  |  | 		response = task->task_status.resp; | 
					
						
							|  |  |  | 		status = task->task_status.stat; | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 		break; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-08 22:41:54 -08:00
										 |  |  | 	case SCI_IO_SUCCESS: | 
					
						
							|  |  |  | 	case SCI_IO_SUCCESS_IO_DONE_EARLY: | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-08 22:41:54 -08:00
										 |  |  | 		response = SAS_TASK_COMPLETE; | 
					
						
							|  |  |  | 		status   = SAM_STAT_GOOD; | 
					
						
							| 
									
										
										
										
											2011-06-23 14:33:48 -07:00
										 |  |  | 		set_bit(IREQ_COMPLETE_IN_TARGET, &request->flags); | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-08 22:41:54 -08:00
										 |  |  | 		if (completion_status == SCI_IO_SUCCESS_IO_DONE_EARLY) { | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-08 22:41:54 -08:00
										 |  |  | 			/* This was an SSP / STP / SATA transfer.
 | 
					
						
							|  |  |  | 			* There is a possibility that less data than | 
					
						
							|  |  |  | 			* the maximum was transferred. | 
					
						
							|  |  |  | 			*/ | 
					
						
							|  |  |  | 			u32 transferred_length = sci_req_tx_bytes(request); | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-08 22:41:54 -08:00
										 |  |  | 			task->task_status.residual | 
					
						
							|  |  |  | 				= task->total_xfer_len - transferred_length; | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-08 22:41:54 -08:00
										 |  |  | 			/* If there were residual bytes, call this an
 | 
					
						
							|  |  |  | 			* underrun. | 
					
						
							|  |  |  | 			*/ | 
					
						
							|  |  |  | 			if (task->task_status.residual != 0) | 
					
						
							|  |  |  | 				status = SAS_DATA_UNDERRUN; | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-30 17:38:32 -07:00
										 |  |  | 			dev_dbg(&ihost->pdev->dev, | 
					
						
							| 
									
										
										
										
											2012-03-08 22:41:54 -08:00
										 |  |  | 				"%s: SCI_IO_SUCCESS_IO_DONE_EARLY %d\n", | 
					
						
							|  |  |  | 				__func__, status); | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-08 22:41:54 -08:00
										 |  |  | 		} else | 
					
						
							|  |  |  | 			dev_dbg(&ihost->pdev->dev, "%s: SCI_IO_SUCCESS\n", | 
					
						
							|  |  |  | 				__func__); | 
					
						
							|  |  |  | 		break; | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-08 22:41:54 -08:00
										 |  |  | 	case SCI_IO_FAILURE_TERMINATED: | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-08 22:41:54 -08:00
										 |  |  | 		dev_dbg(&ihost->pdev->dev, | 
					
						
							|  |  |  | 			"%s: SCI_IO_FAILURE_TERMINATED (%p/%p)\n", | 
					
						
							|  |  |  | 			__func__, request, task); | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-08 22:41:54 -08:00
										 |  |  | 		/* The request was terminated explicitly. */ | 
					
						
							| 
									
										
										
										
											2012-03-08 22:41:58 -08:00
										 |  |  | 		set_bit(IREQ_COMPLETE_IN_TARGET, &request->flags); | 
					
						
							| 
									
										
										
										
											2012-03-08 22:41:54 -08:00
										 |  |  | 		response = SAS_TASK_UNDELIVERED; | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-08 22:41:54 -08:00
										 |  |  | 		/* See if the device has been/is being stopped. Note
 | 
					
						
							|  |  |  | 		* that we ignore the quiesce state, since we are | 
					
						
							|  |  |  | 		* concerned about the actual device state. | 
					
						
							|  |  |  | 		*/ | 
					
						
							|  |  |  | 		if (!idev) | 
					
						
							|  |  |  | 			status = SAS_DEVICE_UNKNOWN; | 
					
						
							|  |  |  | 		else | 
					
						
							|  |  |  | 			status = SAS_ABORTED_TASK; | 
					
						
							|  |  |  | 		break; | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-08 22:41:54 -08:00
										 |  |  | 	case SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR: | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-08 22:41:54 -08:00
										 |  |  | 		isci_request_handle_controller_specific_errors(idev, request, | 
					
						
							|  |  |  | 							       task, &response, | 
					
						
							|  |  |  | 							       &status); | 
					
						
							|  |  |  | 		break; | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-08 22:41:54 -08:00
										 |  |  | 	case SCI_IO_FAILURE_REMOTE_DEVICE_RESET_REQUIRED: | 
					
						
							|  |  |  | 		/* This is a special case, in that the I/O completion
 | 
					
						
							|  |  |  | 		* is telling us that the device needs a reset. | 
					
						
							|  |  |  | 		* In order for the device reset condition to be | 
					
						
							|  |  |  | 		* noticed, the I/O has to be handled in the error | 
					
						
							|  |  |  | 		* handler.  Set the reset flag and cause the | 
					
						
							|  |  |  | 		* SCSI error thread to be scheduled. | 
					
						
							|  |  |  | 		*/ | 
					
						
							|  |  |  | 		spin_lock_irqsave(&task->task_state_lock, task_flags); | 
					
						
							|  |  |  | 		task->task_state_flags |= SAS_TASK_NEED_DEV_RESET; | 
					
						
							|  |  |  | 		spin_unlock_irqrestore(&task->task_state_lock, task_flags); | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-08 22:41:54 -08:00
										 |  |  | 		/* Fail the I/O. */ | 
					
						
							|  |  |  | 		response = SAS_TASK_UNDELIVERED; | 
					
						
							|  |  |  | 		status = SAM_STAT_TASK_ABORTED; | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-08 22:41:54 -08:00
										 |  |  | 		clear_bit(IREQ_COMPLETE_IN_TARGET, &request->flags); | 
					
						
							|  |  |  | 		break; | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-08 22:41:54 -08:00
										 |  |  | 	case SCI_FAILURE_RETRY_REQUIRED: | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-08 22:41:54 -08:00
										 |  |  | 		/* Fail the I/O so it can be retried. */ | 
					
						
							|  |  |  | 		response = SAS_TASK_UNDELIVERED; | 
					
						
							|  |  |  | 		if (!idev) | 
					
						
							|  |  |  | 			status = SAS_DEVICE_UNKNOWN; | 
					
						
							|  |  |  | 		else | 
					
						
							|  |  |  | 			status = SAS_ABORTED_TASK; | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-08 22:41:54 -08:00
										 |  |  | 		set_bit(IREQ_COMPLETE_IN_TARGET, &request->flags); | 
					
						
							|  |  |  | 		break; | 
					
						
							| 
									
										
										
										
											2011-07-02 22:56:22 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-08 22:41:54 -08:00
										 |  |  | 	default: | 
					
						
							|  |  |  | 		/* Catch any otherwise unhandled error codes here. */ | 
					
						
							|  |  |  | 		dev_dbg(&ihost->pdev->dev, | 
					
						
							|  |  |  | 			"%s: invalid completion code: 0x%x - " | 
					
						
							|  |  |  | 				"isci_request = %p\n", | 
					
						
							|  |  |  | 			__func__, completion_status, request); | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-08 22:41:54 -08:00
										 |  |  | 		response = SAS_TASK_UNDELIVERED; | 
					
						
							| 
									
										
										
										
											2011-06-20 14:09:06 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-08 22:41:54 -08:00
										 |  |  | 		/* See if the device has been/is being stopped. Note
 | 
					
						
							|  |  |  | 		* that we ignore the quiesce state, since we are | 
					
						
							|  |  |  | 		* concerned about the actual device state. | 
					
						
							|  |  |  | 		*/ | 
					
						
							|  |  |  | 		if (!idev) | 
					
						
							|  |  |  | 			status = SAS_DEVICE_UNKNOWN; | 
					
						
							|  |  |  | 		else | 
					
						
							|  |  |  | 			status = SAS_ABORTED_TASK; | 
					
						
							| 
									
										
										
										
											2011-06-20 14:09:06 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-08 22:41:54 -08:00
										 |  |  | 		if (SAS_PROTOCOL_SMP == task->task_proto) | 
					
						
							| 
									
										
										
										
											2011-06-23 14:33:48 -07:00
										 |  |  | 			set_bit(IREQ_COMPLETE_IN_TARGET, &request->flags); | 
					
						
							| 
									
										
										
										
											2012-03-08 22:41:54 -08:00
										 |  |  | 		else | 
					
						
							|  |  |  | 			clear_bit(IREQ_COMPLETE_IN_TARGET, &request->flags); | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 		break; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-17 10:40:43 -07:00
										 |  |  | 	switch (task->task_proto) { | 
					
						
							|  |  |  | 	case SAS_PROTOCOL_SSP: | 
					
						
							|  |  |  | 		if (task->data_dir == DMA_NONE) | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		if (task->num_scatter == 0) | 
					
						
							|  |  |  | 			/* 0 indicates a single dma address */ | 
					
						
							| 
									
										
										
										
											2011-06-30 17:38:32 -07:00
										 |  |  | 			dma_unmap_single(&ihost->pdev->dev, | 
					
						
							| 
									
										
										
										
											2011-06-17 10:40:43 -07:00
										 |  |  | 					 request->zero_scatter_daddr, | 
					
						
							|  |  |  | 					 task->total_xfer_len, task->data_dir); | 
					
						
							|  |  |  | 		else  /* unmap the sgl dma addresses */ | 
					
						
							| 
									
										
										
										
											2011-06-30 17:38:32 -07:00
										 |  |  | 			dma_unmap_sg(&ihost->pdev->dev, task->scatter, | 
					
						
							| 
									
										
										
										
											2011-06-17 10:40:43 -07:00
										 |  |  | 				     request->num_sg_entries, task->data_dir); | 
					
						
							|  |  |  | 		break; | 
					
						
							| 
									
										
										
										
											2011-06-16 16:59:56 -07:00
										 |  |  | 	case SAS_PROTOCOL_SMP: { | 
					
						
							|  |  |  | 		struct scatterlist *sg = &task->smp_task.smp_req; | 
					
						
							|  |  |  | 		struct smp_req *smp_req; | 
					
						
							|  |  |  | 		void *kaddr; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-30 17:38:32 -07:00
										 |  |  | 		dma_unmap_sg(&ihost->pdev->dev, sg, 1, DMA_TO_DEVICE); | 
					
						
							| 
									
										
										
										
											2011-06-16 16:59:56 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		/* need to swab it back in case the command buffer is re-used */ | 
					
						
							| 
									
										
										
										
											2011-11-25 23:14:23 +08:00
										 |  |  | 		kaddr = kmap_atomic(sg_page(sg)); | 
					
						
							| 
									
										
										
										
											2011-06-16 16:59:56 -07:00
										 |  |  | 		smp_req = kaddr + sg->offset; | 
					
						
							|  |  |  | 		sci_swab32_cpy(smp_req, smp_req, sg->length / sizeof(u32)); | 
					
						
							| 
									
										
										
										
											2011-11-25 23:14:23 +08:00
										 |  |  | 		kunmap_atomic(kaddr); | 
					
						
							| 
									
										
										
										
											2011-06-16 16:59:56 -07:00
										 |  |  | 		break; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2011-06-17 10:40:43 -07:00
										 |  |  | 	default: | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-08 22:41:54 -08:00
										 |  |  | 	spin_lock_irqsave(&task->task_state_lock, task_flags); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	task->task_status.resp = response; | 
					
						
							|  |  |  | 	task->task_status.stat = status; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (test_bit(IREQ_COMPLETE_IN_TARGET, &request->flags)) { | 
					
						
							|  |  |  | 		/* Normal notification (task_done) */ | 
					
						
							|  |  |  | 		task->task_state_flags |= SAS_TASK_STATE_DONE; | 
					
						
							|  |  |  | 		task->task_state_flags &= ~(SAS_TASK_AT_INITIATOR | | 
					
						
							|  |  |  | 					    SAS_TASK_STATE_PENDING); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	spin_unlock_irqrestore(&task->task_state_lock, task_flags); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 	/* complete the io request to the core. */ | 
					
						
							| 
									
										
										
										
											2011-06-30 19:14:33 -07:00
										 |  |  | 	sci_controller_complete_io(ihost, request->target_device, request); | 
					
						
							| 
									
										
										
										
											2011-06-13 17:39:44 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 	/* set terminated handle so it cannot be completed or
 | 
					
						
							|  |  |  | 	 * terminated again, and to cause any calls into abort | 
					
						
							|  |  |  | 	 * task to recognize the already completed case. | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2011-06-23 14:33:48 -07:00
										 |  |  | 	set_bit(IREQ_TERMINATED, &request->flags); | 
					
						
							| 
									
										
										
										
											2012-03-04 12:44:53 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	ireq_done(ihost, request, task); | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-30 19:14:33 -07:00
										 |  |  | static void sci_request_started_state_enter(struct sci_base_state_machine *sm) | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-06-27 14:57:03 -07:00
										 |  |  | 	struct isci_request *ireq = container_of(sm, typeof(*ireq), sm); | 
					
						
							| 
									
										
										
										
											2011-06-30 16:31:37 -07:00
										 |  |  | 	struct domain_device *dev = ireq->target_device->domain_dev; | 
					
						
							| 
									
										
										
										
											2011-09-30 18:52:19 -07:00
										 |  |  | 	enum sci_base_request_states state; | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:48 -07:00
										 |  |  | 	struct sas_task *task; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* XXX as hch said always creating an internal sas_task for tmf
 | 
					
						
							|  |  |  | 	 * requests would simplify the driver | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2011-10-27 15:05:22 -07:00
										 |  |  | 	task = (test_bit(IREQ_TMF, &ireq->flags)) ? NULL : isci_request_access_task(ireq); | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:49 -07:00
										 |  |  | 	/* all unaccelerated request types (non ssp or ncq) handled with
 | 
					
						
							|  |  |  | 	 * substates | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:47 -07:00
										 |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2013-05-07 14:44:06 -07:00
										 |  |  | 	if (!task && dev->dev_type == SAS_END_DEVICE) { | 
					
						
							| 
									
										
										
										
											2011-09-30 18:52:19 -07:00
										 |  |  | 		state = SCI_REQ_TASK_WAIT_TC_COMP; | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:48 -07:00
										 |  |  | 	} else if (task && task->task_proto == SAS_PROTOCOL_SMP) { | 
					
						
							| 
									
										
										
										
											2011-09-30 18:52:19 -07:00
										 |  |  | 		state = SCI_REQ_SMP_WAIT_RESP; | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:49 -07:00
										 |  |  | 	} else if (task && sas_protocol_ata(task->task_proto) && | 
					
						
							|  |  |  | 		   !task->ata_task.use_ncq) { | 
					
						
							| 
									
										
										
										
											2011-09-30 18:52:19 -07:00
										 |  |  | 		if (dev->sata_dev.command_set == ATAPI_COMMAND_SET && | 
					
						
							|  |  |  | 			task->ata_task.fis.command == ATA_CMD_PACKET) { | 
					
						
							|  |  |  | 			state = SCI_REQ_ATAPI_WAIT_H2D; | 
					
						
							|  |  |  | 		} else if (task->data_dir == DMA_NONE) { | 
					
						
							| 
									
										
										
										
											2011-06-02 00:10:43 +00:00
										 |  |  | 			state = SCI_REQ_STP_NON_DATA_WAIT_H2D; | 
					
						
							| 
									
										
										
										
											2011-09-30 18:52:19 -07:00
										 |  |  | 		} else if (task->ata_task.dma_xfer) { | 
					
						
							| 
									
										
										
										
											2011-06-02 00:10:43 +00:00
										 |  |  | 			state = SCI_REQ_STP_UDMA_WAIT_TC_COMP; | 
					
						
							| 
									
										
										
										
											2011-09-30 18:52:19 -07:00
										 |  |  | 		} else /* PIO */ { | 
					
						
							| 
									
										
										
										
											2011-06-02 00:10:43 +00:00
										 |  |  | 			state = SCI_REQ_STP_PIO_WAIT_H2D; | 
					
						
							| 
									
										
										
										
											2011-09-30 18:52:19 -07:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		/* SSP or NCQ are fully accelerated, no substates */ | 
					
						
							|  |  |  | 		return; | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:48 -07:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2011-09-30 18:52:19 -07:00
										 |  |  | 	sci_change_state(sm, state); | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-30 19:14:33 -07:00
										 |  |  | static void sci_request_completed_state_enter(struct sci_base_state_machine *sm) | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-06-27 14:57:03 -07:00
										 |  |  | 	struct isci_request *ireq = container_of(sm, typeof(*ireq), sm); | 
					
						
							| 
									
										
										
										
											2011-06-30 17:38:32 -07:00
										 |  |  | 	struct isci_host *ihost = ireq->owning_controller; | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* Tell the SCI_USER that the IO request is complete */ | 
					
						
							| 
									
										
										
										
											2011-06-23 14:33:48 -07:00
										 |  |  | 	if (!test_bit(IREQ_TMF, &ireq->flags)) | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 		isci_request_io_request_complete(ihost, ireq, | 
					
						
							| 
									
										
										
										
											2011-06-27 14:57:03 -07:00
										 |  |  | 						 ireq->sci_status); | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 	else | 
					
						
							| 
									
										
										
										
											2011-06-27 14:57:03 -07:00
										 |  |  | 		isci_task_request_complete(ihost, ireq, ireq->sci_status); | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-30 19:14:33 -07:00
										 |  |  | static void sci_request_aborting_state_enter(struct sci_base_state_machine *sm) | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-06-27 14:57:03 -07:00
										 |  |  | 	struct isci_request *ireq = container_of(sm, typeof(*ireq), sm); | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* Setting the abort bit in the Task Context is required by the silicon. */ | 
					
						
							| 
									
										
										
										
											2011-06-27 14:57:03 -07:00
										 |  |  | 	ireq->tc->abort = 1; | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:48 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-30 19:14:33 -07:00
										 |  |  | static void sci_stp_request_started_non_data_await_h2d_completion_enter(struct sci_base_state_machine *sm) | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:49 -07:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-06-27 14:57:03 -07:00
										 |  |  | 	struct isci_request *ireq = container_of(sm, typeof(*ireq), sm); | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:49 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-07-01 02:25:15 -07:00
										 |  |  | 	ireq->target_device->working_request = ireq; | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:49 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-30 19:14:33 -07:00
										 |  |  | static void sci_stp_request_started_pio_await_h2d_completion_enter(struct sci_base_state_machine *sm) | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:49 -07:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-06-27 14:57:03 -07:00
										 |  |  | 	struct isci_request *ireq = container_of(sm, typeof(*ireq), sm); | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:49 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-07-01 02:25:15 -07:00
										 |  |  | 	ireq->target_device->working_request = ireq; | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:49 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-30 19:14:33 -07:00
										 |  |  | static const struct sci_base_state sci_request_state_table[] = { | 
					
						
							| 
									
										
										
										
											2011-06-02 00:10:43 +00:00
										 |  |  | 	[SCI_REQ_INIT] = { }, | 
					
						
							|  |  |  | 	[SCI_REQ_CONSTRUCTED] = { }, | 
					
						
							|  |  |  | 	[SCI_REQ_STARTED] = { | 
					
						
							| 
									
										
										
										
											2011-06-30 19:14:33 -07:00
										 |  |  | 		.enter_state = sci_request_started_state_enter, | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:49 -07:00
										 |  |  | 	}, | 
					
						
							| 
									
										
										
										
											2011-06-02 00:10:43 +00:00
										 |  |  | 	[SCI_REQ_STP_NON_DATA_WAIT_H2D] = { | 
					
						
							| 
									
										
										
										
											2011-06-30 19:14:33 -07:00
										 |  |  | 		.enter_state = sci_stp_request_started_non_data_await_h2d_completion_enter, | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:49 -07:00
										 |  |  | 	}, | 
					
						
							| 
									
										
										
										
											2011-06-02 00:10:43 +00:00
										 |  |  | 	[SCI_REQ_STP_NON_DATA_WAIT_D2H] = { }, | 
					
						
							|  |  |  | 	[SCI_REQ_STP_PIO_WAIT_H2D] = { | 
					
						
							| 
									
										
										
										
											2011-06-30 19:14:33 -07:00
										 |  |  | 		.enter_state = sci_stp_request_started_pio_await_h2d_completion_enter, | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:49 -07:00
										 |  |  | 	}, | 
					
						
							| 
									
										
										
										
											2011-06-02 00:10:43 +00:00
										 |  |  | 	[SCI_REQ_STP_PIO_WAIT_FRAME] = { }, | 
					
						
							|  |  |  | 	[SCI_REQ_STP_PIO_DATA_IN] = { }, | 
					
						
							|  |  |  | 	[SCI_REQ_STP_PIO_DATA_OUT] = { }, | 
					
						
							|  |  |  | 	[SCI_REQ_STP_UDMA_WAIT_TC_COMP] = { }, | 
					
						
							|  |  |  | 	[SCI_REQ_STP_UDMA_WAIT_D2H] = { }, | 
					
						
							|  |  |  | 	[SCI_REQ_TASK_WAIT_TC_COMP] = { }, | 
					
						
							|  |  |  | 	[SCI_REQ_TASK_WAIT_TC_RESP] = { }, | 
					
						
							|  |  |  | 	[SCI_REQ_SMP_WAIT_RESP] = { }, | 
					
						
							|  |  |  | 	[SCI_REQ_SMP_WAIT_TC_COMP] = { }, | 
					
						
							| 
									
										
										
										
											2011-09-30 18:52:19 -07:00
										 |  |  | 	[SCI_REQ_ATAPI_WAIT_H2D] = { }, | 
					
						
							|  |  |  | 	[SCI_REQ_ATAPI_WAIT_PIO_SETUP] = { }, | 
					
						
							|  |  |  | 	[SCI_REQ_ATAPI_WAIT_D2H] = { }, | 
					
						
							|  |  |  | 	[SCI_REQ_ATAPI_WAIT_TC_COMP] = { }, | 
					
						
							| 
									
										
										
										
											2011-06-02 00:10:43 +00:00
										 |  |  | 	[SCI_REQ_COMPLETED] = { | 
					
						
							| 
									
										
										
										
											2011-06-30 19:14:33 -07:00
										 |  |  | 		.enter_state = sci_request_completed_state_enter, | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 	}, | 
					
						
							| 
									
										
										
										
											2011-06-02 00:10:43 +00:00
										 |  |  | 	[SCI_REQ_ABORTING] = { | 
					
						
							| 
									
										
										
										
											2011-06-30 19:14:33 -07:00
										 |  |  | 		.enter_state = sci_request_aborting_state_enter, | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 	}, | 
					
						
							| 
									
										
										
										
											2011-06-02 00:10:43 +00:00
										 |  |  | 	[SCI_REQ_FINAL] = { }, | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-02 00:10:43 +00:00
										 |  |  | static void | 
					
						
							| 
									
										
										
										
											2011-06-30 19:14:33 -07:00
										 |  |  | sci_general_request_construct(struct isci_host *ihost, | 
					
						
							| 
									
										
										
										
											2011-06-30 16:31:37 -07:00
										 |  |  | 				   struct isci_remote_device *idev, | 
					
						
							| 
									
										
										
										
											2011-06-27 14:57:03 -07:00
										 |  |  | 				   struct isci_request *ireq) | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-06-30 19:14:33 -07:00
										 |  |  | 	sci_init_sm(&ireq->sm, sci_request_state_table, SCI_REQ_INIT); | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-30 16:31:37 -07:00
										 |  |  | 	ireq->target_device = idev; | 
					
						
							| 
									
										
										
										
											2012-02-01 00:44:14 -08:00
										 |  |  | 	ireq->protocol = SAS_PROTOCOL_NONE; | 
					
						
							| 
									
										
										
										
											2011-06-27 14:57:03 -07:00
										 |  |  | 	ireq->saved_rx_frame_index = SCU_INVALID_FRAME_INDEX; | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-27 14:57:03 -07:00
										 |  |  | 	ireq->sci_status   = SCI_SUCCESS; | 
					
						
							|  |  |  | 	ireq->scu_status   = 0; | 
					
						
							|  |  |  | 	ireq->post_context = 0xFFFFFFFF; | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static enum sci_status | 
					
						
							| 
									
										
										
										
											2011-06-30 19:14:33 -07:00
										 |  |  | sci_io_request_construct(struct isci_host *ihost, | 
					
						
							| 
									
										
										
										
											2011-06-30 16:31:37 -07:00
										 |  |  | 			  struct isci_remote_device *idev, | 
					
						
							| 
									
										
										
										
											2011-06-27 14:57:03 -07:00
										 |  |  | 			  struct isci_request *ireq) | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-06-30 16:31:37 -07:00
										 |  |  | 	struct domain_device *dev = idev->domain_dev; | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 	enum sci_status status = SCI_SUCCESS; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* Build the common part of the request */ | 
					
						
							| 
									
										
										
										
											2011-06-30 19:14:33 -07:00
										 |  |  | 	sci_general_request_construct(ihost, idev, ireq); | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-30 16:31:37 -07:00
										 |  |  | 	if (idev->rnc.remote_node_index == SCIC_SDS_REMOTE_NODE_CONTEXT_INVALID_INDEX) | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 		return SCI_FAILURE_INVALID_REMOTE_DEVICE; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-07 14:44:06 -07:00
										 |  |  | 	if (dev->dev_type == SAS_END_DEVICE) | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:48 -07:00
										 |  |  | 		/* pass */; | 
					
						
							| 
									
										
										
										
											2012-02-01 00:23:10 -08:00
										 |  |  | 	else if (dev_is_sata(dev)) | 
					
						
							| 
									
										
										
										
											2011-06-27 14:57:03 -07:00
										 |  |  | 		memset(&ireq->stp.cmd, 0, sizeof(ireq->stp.cmd)); | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:48 -07:00
										 |  |  | 	else if (dev_is_expander(dev)) | 
					
						
							| 
									
										
										
										
											2011-06-16 16:59:56 -07:00
										 |  |  | 		/* pass */; | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:48 -07:00
										 |  |  | 	else | 
					
						
							|  |  |  | 		return SCI_FAILURE_UNSUPPORTED_PROTOCOL; | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-27 14:57:03 -07:00
										 |  |  | 	memset(ireq->tc, 0, offsetof(struct scu_task_context, sgl_pair_ab)); | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return status; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-30 19:14:33 -07:00
										 |  |  | enum sci_status sci_task_request_construct(struct isci_host *ihost, | 
					
						
							| 
									
										
										
										
											2011-06-30 16:31:37 -07:00
										 |  |  | 					    struct isci_remote_device *idev, | 
					
						
							| 
									
										
										
										
											2011-06-27 14:57:03 -07:00
										 |  |  | 					    u16 io_tag, struct isci_request *ireq) | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-06-30 16:31:37 -07:00
										 |  |  | 	struct domain_device *dev = idev->domain_dev; | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 	enum sci_status status = SCI_SUCCESS; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* Build the common part of the request */ | 
					
						
							| 
									
										
										
										
											2011-06-30 19:14:33 -07:00
										 |  |  | 	sci_general_request_construct(ihost, idev, ireq); | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-07 14:44:06 -07:00
										 |  |  | 	if (dev->dev_type == SAS_END_DEVICE || dev_is_sata(dev)) { | 
					
						
							| 
									
										
										
										
											2011-06-27 14:57:03 -07:00
										 |  |  | 		set_bit(IREQ_TMF, &ireq->flags); | 
					
						
							|  |  |  | 		memset(ireq->tc, 0, sizeof(struct scu_task_context)); | 
					
						
							| 
									
										
										
										
											2012-03-08 22:42:06 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		/* Set the protocol indicator. */ | 
					
						
							|  |  |  | 		if (dev_is_sata(dev)) | 
					
						
							|  |  |  | 			ireq->protocol = SAS_PROTOCOL_STP; | 
					
						
							|  |  |  | 		else | 
					
						
							|  |  |  | 			ireq->protocol = SAS_PROTOCOL_SSP; | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:48 -07:00
										 |  |  | 	} else | 
					
						
							|  |  |  | 		status = SCI_FAILURE_UNSUPPORTED_PROTOCOL; | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return status; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static enum sci_status isci_request_ssp_request_construct( | 
					
						
							|  |  |  | 	struct isci_request *request) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	enum sci_status status; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	dev_dbg(&request->isci_host->pdev->dev, | 
					
						
							|  |  |  | 		"%s: request = %p\n", | 
					
						
							|  |  |  | 		__func__, | 
					
						
							|  |  |  | 		request); | 
					
						
							| 
									
										
										
										
											2011-06-30 19:14:33 -07:00
										 |  |  | 	status = sci_io_request_construct_basic_ssp(request); | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 	return status; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-07-01 10:52:55 -07:00
										 |  |  | static enum sci_status isci_request_stp_request_construct(struct isci_request *ireq) | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-07-01 10:52:55 -07:00
										 |  |  | 	struct sas_task *task = isci_request_access_task(ireq); | 
					
						
							|  |  |  | 	struct host_to_dev_fis *fis = &ireq->stp.cmd; | 
					
						
							|  |  |  | 	struct ata_queued_cmd *qc = task->uldd_task; | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 	enum sci_status status; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-07-01 10:52:55 -07:00
										 |  |  | 	dev_dbg(&ireq->isci_host->pdev->dev, | 
					
						
							|  |  |  | 		"%s: ireq = %p\n", | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 		__func__, | 
					
						
							| 
									
										
										
										
											2011-07-01 10:52:55 -07:00
										 |  |  | 		ireq); | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-07-01 10:52:55 -07:00
										 |  |  | 	memcpy(fis, &task->ata_task.fis, sizeof(struct host_to_dev_fis)); | 
					
						
							|  |  |  | 	if (!task->ata_task.device_control_reg_update) | 
					
						
							|  |  |  | 		fis->flags |= 0x80; | 
					
						
							|  |  |  | 	fis->flags &= 0xF0; | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-07-01 10:52:55 -07:00
										 |  |  | 	status = sci_io_request_construct_basic_sata(ireq); | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-07-01 10:52:55 -07:00
										 |  |  | 	if (qc && (qc->tf.command == ATA_CMD_FPDMA_WRITE || | 
					
						
							|  |  |  | 		   qc->tf.command == ATA_CMD_FPDMA_READ)) { | 
					
						
							|  |  |  | 		fis->sector_count = qc->tag << 3; | 
					
						
							|  |  |  | 		ireq->tc->type.stp.ncq_tag = qc->tag; | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return status; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-16 16:59:56 -07:00
										 |  |  | static enum sci_status | 
					
						
							| 
									
										
										
										
											2011-06-30 19:14:33 -07:00
										 |  |  | sci_io_request_construct_smp(struct device *dev, | 
					
						
							| 
									
										
										
										
											2011-06-27 14:57:03 -07:00
										 |  |  | 			      struct isci_request *ireq, | 
					
						
							| 
									
										
										
										
											2011-06-16 16:59:56 -07:00
										 |  |  | 			      struct sas_task *task) | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:48 -07:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-06-16 16:59:56 -07:00
										 |  |  | 	struct scatterlist *sg = &task->smp_task.smp_req; | 
					
						
							| 
									
										
										
										
											2011-06-30 16:31:37 -07:00
										 |  |  | 	struct isci_remote_device *idev; | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:48 -07:00
										 |  |  | 	struct scu_task_context *task_context; | 
					
						
							| 
									
										
										
										
											2011-06-29 13:09:25 -07:00
										 |  |  | 	struct isci_port *iport; | 
					
						
							| 
									
										
										
										
											2011-06-16 16:59:56 -07:00
										 |  |  | 	struct smp_req *smp_req; | 
					
						
							|  |  |  | 	void *kaddr; | 
					
						
							|  |  |  | 	u8 req_len; | 
					
						
							|  |  |  | 	u32 cmd; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-11-25 23:14:23 +08:00
										 |  |  | 	kaddr = kmap_atomic(sg_page(sg)); | 
					
						
							| 
									
										
										
										
											2011-06-16 16:59:56 -07:00
										 |  |  | 	smp_req = kaddr + sg->offset; | 
					
						
							|  |  |  | 	/*
 | 
					
						
							|  |  |  | 	 * Look at the SMP requests' header fields; for certain SAS 1.x SMP | 
					
						
							|  |  |  | 	 * functions under SAS 2.0, a zero request length really indicates | 
					
						
							|  |  |  | 	 * a non-zero default length. | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	if (smp_req->req_len == 0) { | 
					
						
							|  |  |  | 		switch (smp_req->func) { | 
					
						
							|  |  |  | 		case SMP_DISCOVER: | 
					
						
							|  |  |  | 		case SMP_REPORT_PHY_ERR_LOG: | 
					
						
							|  |  |  | 		case SMP_REPORT_PHY_SATA: | 
					
						
							|  |  |  | 		case SMP_REPORT_ROUTE_INFO: | 
					
						
							|  |  |  | 			smp_req->req_len = 2; | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		case SMP_CONF_ROUTE_INFO: | 
					
						
							|  |  |  | 		case SMP_PHY_CONTROL: | 
					
						
							|  |  |  | 		case SMP_PHY_TEST_FUNCTION: | 
					
						
							|  |  |  | 			smp_req->req_len = 9; | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 			/* Default - zero is a valid default for 2.0. */ | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	req_len = smp_req->req_len; | 
					
						
							|  |  |  | 	sci_swab32_cpy(smp_req, smp_req, sg->length / sizeof(u32)); | 
					
						
							|  |  |  | 	cmd = *(u32 *) smp_req; | 
					
						
							| 
									
										
										
										
											2011-11-25 23:14:23 +08:00
										 |  |  | 	kunmap_atomic(kaddr); | 
					
						
							| 
									
										
										
										
											2011-06-16 16:59:56 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (!dma_map_sg(dev, sg, 1, DMA_TO_DEVICE)) | 
					
						
							|  |  |  | 		return SCI_FAILURE; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-01 00:44:14 -08:00
										 |  |  | 	ireq->protocol = SAS_PROTOCOL_SMP; | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:48 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* byte swap the smp request. */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-27 14:57:03 -07:00
										 |  |  | 	task_context = ireq->tc; | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:48 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-07-01 02:25:15 -07:00
										 |  |  | 	idev = ireq->target_device; | 
					
						
							|  |  |  | 	iport = idev->owning_port; | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:48 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/*
 | 
					
						
							|  |  |  | 	 * Fill in the TC with the its required data | 
					
						
							|  |  |  | 	 * 00h | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	task_context->priority = 0; | 
					
						
							|  |  |  | 	task_context->initiator_request = 1; | 
					
						
							| 
									
										
										
										
											2011-06-30 16:31:37 -07:00
										 |  |  | 	task_context->connection_rate = idev->connection_rate; | 
					
						
							| 
									
										
										
										
											2011-07-01 02:25:15 -07:00
										 |  |  | 	task_context->protocol_engine_index = ISCI_PEG; | 
					
						
							|  |  |  | 	task_context->logical_port_index = iport->physical_port_index; | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:48 -07:00
										 |  |  | 	task_context->protocol_type = SCU_TASK_CONTEXT_PROTOCOL_SMP; | 
					
						
							|  |  |  | 	task_context->abort = 0; | 
					
						
							|  |  |  | 	task_context->valid = SCU_TASK_CONTEXT_VALID; | 
					
						
							|  |  |  | 	task_context->context_type = SCU_TASK_CONTEXT_TYPE; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* 04h */ | 
					
						
							| 
									
										
										
										
											2011-06-30 16:31:37 -07:00
										 |  |  | 	task_context->remote_node_index = idev->rnc.remote_node_index; | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:48 -07:00
										 |  |  | 	task_context->command_code = 0; | 
					
						
							|  |  |  | 	task_context->task_type = SCU_TASK_TYPE_SMP_REQUEST; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* 08h */ | 
					
						
							|  |  |  | 	task_context->link_layer_control = 0; | 
					
						
							|  |  |  | 	task_context->do_not_dma_ssp_good_response = 1; | 
					
						
							|  |  |  | 	task_context->strict_ordering = 0; | 
					
						
							|  |  |  | 	task_context->control_frame = 1; | 
					
						
							|  |  |  | 	task_context->timeout_enable = 0; | 
					
						
							|  |  |  | 	task_context->block_guard_enable = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* 0ch */ | 
					
						
							|  |  |  | 	task_context->address_modifier = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* 10h */ | 
					
						
							| 
									
										
										
										
											2011-05-25 02:21:57 +00:00
										 |  |  | 	task_context->ssp_command_iu_length = req_len; | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:48 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* 14h */ | 
					
						
							|  |  |  | 	task_context->transfer_length_bytes = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/*
 | 
					
						
							|  |  |  | 	 * 18h ~ 30h, protocol specific | 
					
						
							|  |  |  | 	 * since commandIU has been build by framework at this point, we just | 
					
						
							|  |  |  | 	 * copy the frist DWord from command IU to this location. */ | 
					
						
							| 
									
										
										
										
											2011-06-16 16:59:56 -07:00
										 |  |  | 	memcpy(&task_context->type.smp, &cmd, sizeof(u32)); | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:48 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/*
 | 
					
						
							|  |  |  | 	 * 40h | 
					
						
							|  |  |  | 	 * "For SMP you could program it to zero. We would prefer that way | 
					
						
							|  |  |  | 	 * so that done code will be consistent." - Venki | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	task_context->task_phase = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-27 14:57:03 -07:00
										 |  |  | 	ireq->post_context = (SCU_CONTEXT_COMMAND_REQUEST_TYPE_POST_TC | | 
					
						
							| 
									
										
										
										
											2011-07-01 02:25:15 -07:00
										 |  |  | 			      (ISCI_PEG << SCU_CONTEXT_COMMAND_PROTOCOL_ENGINE_GROUP_SHIFT) | | 
					
						
							|  |  |  | 			       (iport->physical_port_index << | 
					
						
							|  |  |  | 				SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT) | | 
					
						
							|  |  |  | 			      ISCI_TAG_TCI(ireq->io_tag)); | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:48 -07:00
										 |  |  | 	/*
 | 
					
						
							|  |  |  | 	 * Copy the physical address for the command buffer to the SCU Task | 
					
						
							|  |  |  | 	 * Context command buffer should not contain command header. | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2011-06-16 16:59:56 -07:00
										 |  |  | 	task_context->command_iu_upper = upper_32_bits(sg_dma_address(sg)); | 
					
						
							|  |  |  | 	task_context->command_iu_lower = lower_32_bits(sg_dma_address(sg) + sizeof(u32)); | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:48 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* SMP response comes as UF, so no need to set response IU address. */ | 
					
						
							|  |  |  | 	task_context->response_iu_upper = 0; | 
					
						
							|  |  |  | 	task_context->response_iu_lower = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-27 14:57:03 -07:00
										 |  |  | 	sci_change_state(&ireq->sm, SCI_REQ_CONSTRUCTED); | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:48 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return SCI_SUCCESS; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * isci_smp_request_build() - This function builds the smp request. | 
					
						
							|  |  |  |  * @ireq: This parameter points to the isci_request allocated in the | 
					
						
							|  |  |  |  *    request construct function. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * SCI_SUCCESS on successfull completion, or specific failure code. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | static enum sci_status isci_smp_request_build(struct isci_request *ireq) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct sas_task *task = isci_request_access_task(ireq); | 
					
						
							| 
									
										
										
										
											2011-06-16 16:59:56 -07:00
										 |  |  | 	struct device *dev = &ireq->isci_host->pdev->dev; | 
					
						
							|  |  |  | 	enum sci_status status = SCI_FAILURE; | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-30 19:14:33 -07:00
										 |  |  | 	status = sci_io_request_construct_smp(dev, ireq, task); | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 	if (status != SCI_SUCCESS) | 
					
						
							| 
									
										
										
										
											2011-07-01 12:07:25 -07:00
										 |  |  | 		dev_dbg(&ireq->isci_host->pdev->dev, | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 			 "%s: failed with status = %d\n", | 
					
						
							|  |  |  | 			 __func__, | 
					
						
							|  |  |  | 			 status); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return status; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /**
 | 
					
						
							|  |  |  |  * isci_io_request_build() - This function builds the io request object. | 
					
						
							| 
									
										
										
										
											2011-06-30 17:38:32 -07:00
										 |  |  |  * @ihost: This parameter specifies the ISCI host object | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  |  * @request: This parameter points to the isci_request object allocated in the | 
					
						
							|  |  |  |  *    request construct function. | 
					
						
							|  |  |  |  * @sci_device: This parameter is the handle for the sci core's remote device | 
					
						
							|  |  |  |  *    object that is the destination for this request. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * SCI_SUCCESS on successfull completion, or specific failure code. | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2011-06-30 17:38:32 -07:00
										 |  |  | static enum sci_status isci_io_request_build(struct isci_host *ihost, | 
					
						
							| 
									
										
										
										
											2011-06-28 13:47:09 -07:00
										 |  |  | 					     struct isci_request *request, | 
					
						
							| 
									
										
										
										
											2011-06-30 16:31:37 -07:00
										 |  |  | 					     struct isci_remote_device *idev) | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | { | 
					
						
							|  |  |  | 	enum sci_status status = SCI_SUCCESS; | 
					
						
							|  |  |  | 	struct sas_task *task = isci_request_access_task(request); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-30 17:38:32 -07:00
										 |  |  | 	dev_dbg(&ihost->pdev->dev, | 
					
						
							| 
									
										
										
										
											2011-06-30 16:31:37 -07:00
										 |  |  | 		"%s: idev = 0x%p; request = %p, " | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 		"num_scatter = %d\n", | 
					
						
							|  |  |  | 		__func__, | 
					
						
							| 
									
										
										
										
											2011-06-30 16:31:37 -07:00
										 |  |  | 		idev, | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 		request, | 
					
						
							|  |  |  | 		task->num_scatter); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* map the sgl addresses, if present.
 | 
					
						
							|  |  |  | 	 * libata does the mapping for sata devices | 
					
						
							|  |  |  | 	 * before we get the request. | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	if (task->num_scatter && | 
					
						
							|  |  |  | 	    !sas_protocol_ata(task->task_proto) && | 
					
						
							|  |  |  | 	    !(SAS_PROTOCOL_SMP & task->task_proto)) { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		request->num_sg_entries = dma_map_sg( | 
					
						
							| 
									
										
										
										
											2011-06-30 17:38:32 -07:00
										 |  |  | 			&ihost->pdev->dev, | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 			task->scatter, | 
					
						
							|  |  |  | 			task->num_scatter, | 
					
						
							|  |  |  | 			task->data_dir | 
					
						
							|  |  |  | 			); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (request->num_sg_entries == 0) | 
					
						
							|  |  |  | 			return SCI_FAILURE_INSUFFICIENT_RESOURCES; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-30 19:14:33 -07:00
										 |  |  | 	status = sci_io_request_construct(ihost, idev, request); | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (status != SCI_SUCCESS) { | 
					
						
							| 
									
										
										
										
											2011-07-01 12:07:25 -07:00
										 |  |  | 		dev_dbg(&ihost->pdev->dev, | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 			 "%s: failed request construct\n", | 
					
						
							|  |  |  | 			 __func__); | 
					
						
							|  |  |  | 		return SCI_FAILURE; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	switch (task->task_proto) { | 
					
						
							|  |  |  | 	case SAS_PROTOCOL_SMP: | 
					
						
							|  |  |  | 		status = isci_smp_request_build(request); | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	case SAS_PROTOCOL_SSP: | 
					
						
							|  |  |  | 		status = isci_request_ssp_request_construct(request); | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	case SAS_PROTOCOL_SATA: | 
					
						
							|  |  |  | 	case SAS_PROTOCOL_STP: | 
					
						
							|  |  |  | 	case SAS_PROTOCOL_SATA | SAS_PROTOCOL_STP: | 
					
						
							|  |  |  | 		status = isci_request_stp_request_construct(request); | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	default: | 
					
						
							| 
									
										
										
										
											2011-07-01 12:07:25 -07:00
										 |  |  | 		dev_dbg(&ihost->pdev->dev, | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 			 "%s: unknown protocol\n", __func__); | 
					
						
							|  |  |  | 		return SCI_FAILURE; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return SCI_SUCCESS; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-17 14:18:39 -07:00
										 |  |  | static struct isci_request *isci_request_from_tag(struct isci_host *ihost, u16 tag) | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-06-13 00:51:30 -07:00
										 |  |  | 	struct isci_request *ireq; | 
					
						
							| 
									
										
										
										
											2011-03-07 16:40:47 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-17 14:18:39 -07:00
										 |  |  | 	ireq = ihost->reqs[ISCI_TAG_TCI(tag)]; | 
					
						
							| 
									
										
										
										
											2011-06-27 14:57:03 -07:00
										 |  |  | 	ireq->io_tag = tag; | 
					
						
							| 
									
										
										
										
											2011-06-13 00:51:30 -07:00
										 |  |  | 	ireq->io_request_completion = NULL; | 
					
						
							| 
									
										
										
										
											2011-06-23 14:33:48 -07:00
										 |  |  | 	ireq->flags = 0; | 
					
						
							| 
									
										
										
										
											2011-06-13 00:51:30 -07:00
										 |  |  | 	ireq->num_sg_entries = 0; | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-13 00:51:30 -07:00
										 |  |  | 	return ireq; | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-17 14:18:39 -07:00
										 |  |  | static struct isci_request *isci_io_request_from_tag(struct isci_host *ihost, | 
					
						
							|  |  |  | 						     struct sas_task *task, | 
					
						
							|  |  |  | 						     u16 tag) | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-06-13 00:51:30 -07:00
										 |  |  | 	struct isci_request *ireq; | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-17 14:18:39 -07:00
										 |  |  | 	ireq = isci_request_from_tag(ihost, tag); | 
					
						
							|  |  |  | 	ireq->ttype_ptr.io_task_ptr = task; | 
					
						
							| 
									
										
										
										
											2011-10-27 15:05:22 -07:00
										 |  |  | 	clear_bit(IREQ_TMF, &ireq->flags); | 
					
						
							| 
									
										
										
										
											2011-06-17 14:18:39 -07:00
										 |  |  | 	task->lldd_task = ireq; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-13 00:51:30 -07:00
										 |  |  | 	return ireq; | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2011-07-02 22:56:22 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-17 14:18:39 -07:00
										 |  |  | struct isci_request *isci_tmf_request_from_tag(struct isci_host *ihost, | 
					
						
							|  |  |  | 					       struct isci_tmf *isci_tmf, | 
					
						
							|  |  |  | 					       u16 tag) | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-06-13 00:51:30 -07:00
										 |  |  | 	struct isci_request *ireq; | 
					
						
							| 
									
										
										
										
											2011-07-02 22:56:22 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-17 14:18:39 -07:00
										 |  |  | 	ireq = isci_request_from_tag(ihost, tag); | 
					
						
							|  |  |  | 	ireq->ttype_ptr.tmf_task_ptr = isci_tmf; | 
					
						
							| 
									
										
										
										
											2011-10-27 15:05:22 -07:00
										 |  |  | 	set_bit(IREQ_TMF, &ireq->flags); | 
					
						
							| 
									
										
										
										
											2011-06-17 14:18:39 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-13 00:51:30 -07:00
										 |  |  | 	return ireq; | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-13 17:39:44 -07:00
										 |  |  | int isci_request_execute(struct isci_host *ihost, struct isci_remote_device *idev, | 
					
						
							| 
									
										
										
										
											2011-06-17 14:18:39 -07:00
										 |  |  | 			 struct sas_task *task, u16 tag) | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | { | 
					
						
							|  |  |  | 	enum sci_status status = SCI_FAILURE_UNSUPPORTED_PROTOCOL; | 
					
						
							| 
									
										
										
										
											2011-06-13 00:51:30 -07:00
										 |  |  | 	struct isci_request *ireq; | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 	unsigned long flags; | 
					
						
							| 
									
										
										
										
											2011-06-13 00:51:30 -07:00
										 |  |  | 	int ret = 0; | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* do common allocation and init of request object. */ | 
					
						
							| 
									
										
										
										
											2011-06-17 14:18:39 -07:00
										 |  |  | 	ireq = isci_io_request_from_tag(ihost, task, tag); | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-17 14:18:39 -07:00
										 |  |  | 	status = isci_io_request_build(ihost, ireq, idev); | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 	if (status != SCI_SUCCESS) { | 
					
						
							| 
									
										
										
										
											2011-07-01 12:07:25 -07:00
										 |  |  | 		dev_dbg(&ihost->pdev->dev, | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 			 "%s: request_construct failed - status = 0x%x\n", | 
					
						
							|  |  |  | 			 __func__, | 
					
						
							|  |  |  | 			 status); | 
					
						
							| 
									
										
										
										
											2011-06-17 14:18:39 -07:00
										 |  |  | 		return status; | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-13 00:51:30 -07:00
										 |  |  | 	spin_lock_irqsave(&ihost->scic_lock, flags); | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-23 17:09:02 -07:00
										 |  |  | 	if (test_bit(IDEV_IO_NCQERROR, &idev->flags)) { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (isci_task_is_ncq_recovery(task)) { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			/* The device is in an NCQ recovery state.  Issue the
 | 
					
						
							|  |  |  | 			 * request on the task side.  Note that it will | 
					
						
							|  |  |  | 			 * complete on the I/O request side because the | 
					
						
							|  |  |  | 			 * request was built that way (ie. | 
					
						
							|  |  |  | 			 * ireq->is_task_management_request is false). | 
					
						
							|  |  |  | 			 */ | 
					
						
							| 
									
										
										
										
											2011-06-30 19:14:33 -07:00
										 |  |  | 			status = sci_controller_start_task(ihost, | 
					
						
							| 
									
										
										
										
											2011-06-30 16:31:37 -07:00
										 |  |  | 							    idev, | 
					
						
							| 
									
										
										
										
											2011-06-27 14:57:03 -07:00
										 |  |  | 							    ireq); | 
					
						
							| 
									
										
										
										
											2011-06-23 17:09:02 -07:00
										 |  |  | 		} else { | 
					
						
							|  |  |  | 			status = SCI_FAILURE; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		/* send the request, let the core assign the IO TAG.	*/ | 
					
						
							| 
									
										
										
										
											2011-06-30 19:14:33 -07:00
										 |  |  | 		status = sci_controller_start_io(ihost, idev, | 
					
						
							| 
									
										
										
										
											2011-06-27 14:57:03 -07:00
										 |  |  | 						  ireq); | 
					
						
							| 
									
										
										
										
											2011-06-23 17:09:02 -07:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2011-06-28 13:47:09 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 	if (status != SCI_SUCCESS && | 
					
						
							|  |  |  | 	    status != SCI_FAILURE_REMOTE_DEVICE_RESET_REQUIRED) { | 
					
						
							| 
									
										
										
										
											2011-07-01 12:07:25 -07:00
										 |  |  | 		dev_dbg(&ihost->pdev->dev, | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 			 "%s: failed request start (0x%x)\n", | 
					
						
							|  |  |  | 			 __func__, status); | 
					
						
							| 
									
										
										
										
											2011-06-13 00:51:30 -07:00
										 |  |  | 		spin_unlock_irqrestore(&ihost->scic_lock, flags); | 
					
						
							| 
									
										
										
										
											2011-06-17 14:18:39 -07:00
										 |  |  | 		return status; | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	/* Either I/O started OK, or the core has signaled that
 | 
					
						
							|  |  |  | 	 * the device needs a target reset. | 
					
						
							| 
									
										
										
										
											2011-07-02 22:56:22 -07:00
										 |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2012-03-08 22:41:54 -08:00
										 |  |  | 	if (status != SCI_SUCCESS) { | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 		/* The request did not really start in the
 | 
					
						
							|  |  |  | 		 * hardware, so clear the request handle | 
					
						
							|  |  |  | 		 * here so no terminations will be done. | 
					
						
							|  |  |  | 		 */ | 
					
						
							| 
									
										
										
										
											2011-06-23 14:33:48 -07:00
										 |  |  | 		set_bit(IREQ_TERMINATED, &ireq->flags); | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2011-06-13 00:51:30 -07:00
										 |  |  | 	spin_unlock_irqrestore(&ihost->scic_lock, flags); | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (status == | 
					
						
							|  |  |  | 	    SCI_FAILURE_REMOTE_DEVICE_RESET_REQUIRED) { | 
					
						
							|  |  |  | 		/* Signal libsas that we need the SCSI error
 | 
					
						
							| 
									
										
										
										
											2011-06-28 13:47:09 -07:00
										 |  |  | 		 * handler thread to work on this I/O and that | 
					
						
							|  |  |  | 		 * we want a device reset. | 
					
						
							|  |  |  | 		 */ | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 		spin_lock_irqsave(&task->task_state_lock, flags); | 
					
						
							|  |  |  | 		task->task_state_flags |= SAS_TASK_NEED_DEV_RESET; | 
					
						
							|  |  |  | 		spin_unlock_irqrestore(&task->task_state_lock, flags); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		/* Cause this task to be scheduled in the SCSI error
 | 
					
						
							| 
									
										
										
										
											2011-06-28 13:47:09 -07:00
										 |  |  | 		 * handler thread. | 
					
						
							|  |  |  | 		 */ | 
					
						
							| 
									
										
										
										
											2011-11-17 17:59:50 -08:00
										 |  |  | 		sas_task_abort(task); | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		/* Change the status, since we are holding
 | 
					
						
							| 
									
										
										
										
											2011-06-28 13:47:09 -07:00
										 |  |  | 		 * the I/O until it is managed by the SCSI | 
					
						
							|  |  |  | 		 * error handler. | 
					
						
							|  |  |  | 		 */ | 
					
						
							| 
									
										
										
										
											2011-05-10 02:28:45 -07:00
										 |  |  | 		status = SCI_SUCCESS; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return ret; | 
					
						
							| 
									
										
										
										
											2011-07-02 22:56:22 -07:00
										 |  |  | } |