Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1 | /* |
| 2 | * This file is provided under a dual BSD/GPLv2 license. When using or |
| 3 | * redistributing this file, you may do so under either license. |
| 4 | * |
| 5 | * GPL LICENSE SUMMARY |
| 6 | * |
| 7 | * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved. |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or modify |
| 10 | * it under the terms of version 2 of the GNU General Public License as |
| 11 | * published by the Free Software Foundation. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, but |
| 14 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 16 | * General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program; if not, write to the Free Software |
| 20 | * Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. |
| 21 | * The full GNU General Public License is included in this distribution |
| 22 | * in the file called LICENSE.GPL. |
| 23 | * |
| 24 | * BSD LICENSE |
| 25 | * |
| 26 | * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved. |
| 27 | * All rights reserved. |
| 28 | * |
| 29 | * Redistribution and use in source and binary forms, with or without |
| 30 | * modification, are permitted provided that the following conditions |
| 31 | * are met: |
| 32 | * |
| 33 | * * Redistributions of source code must retain the above copyright |
| 34 | * notice, this list of conditions and the following disclaimer. |
| 35 | * * Redistributions in binary form must reproduce the above copyright |
| 36 | * notice, this list of conditions and the following disclaimer in |
| 37 | * the documentation and/or other materials provided with the |
| 38 | * distribution. |
| 39 | * * Neither the name of Intel Corporation nor the names of its |
| 40 | * contributors may be used to endorse or promote products derived |
| 41 | * from this software without specific prior written permission. |
| 42 | * |
| 43 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 44 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 45 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 46 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 47 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 48 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 49 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 50 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 51 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 52 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 53 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 54 | */ |
| 55 | |
Dave Jiang | d20930a | 2011-05-04 18:07:09 -0700 | [diff] [blame] | 56 | #include <scsi/sas.h> |
Dan Williams | 3bff9d5 | 2011-05-08 22:15:10 -0700 | [diff] [blame] | 57 | #include "state_machine.h" |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 58 | #include "remote_device.h" |
Dan Williams | f1f52e7 | 2011-05-10 02:28:45 -0700 | [diff] [blame^] | 59 | #include "request.h" |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 60 | #include "scu_completion_codes.h" |
| 61 | #include "scu_task_context.h" |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 62 | #include "host.h" |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 63 | |
| 64 | static void scu_smp_request_construct_task_context( |
Dave Jiang | e2023b8 | 2011-04-21 05:34:49 +0000 | [diff] [blame] | 65 | struct scic_sds_request *sci_req, |
Dave Jiang | 2ec53eb | 2011-05-04 18:01:22 -0700 | [diff] [blame] | 66 | struct smp_req *smp_req); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 67 | |
Dan Williams | 2629826 | 2011-05-07 19:07:14 -0700 | [diff] [blame] | 68 | void scic_sds_smp_request_assign_buffers(struct scic_sds_request *sci_req) |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 69 | { |
Dan Williams | 2629826 | 2011-05-07 19:07:14 -0700 | [diff] [blame] | 70 | if (sci_req->was_tag_assigned_by_user == false) |
| 71 | sci_req->task_context_buffer = &sci_req->tc; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 72 | } |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 73 | |
Dave Jiang | 2ec53eb | 2011-05-04 18:01:22 -0700 | [diff] [blame] | 74 | /* |
| 75 | * This function will fill in the SCU Task Context for a SMP request. The |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 76 | * following important settings are utilized: -# task_type == |
| 77 | * SCU_TASK_TYPE_SMP. This simply indicates that a normal request type |
| 78 | * (i.e. non-raw frame) is being utilized to perform task management. -# |
| 79 | * control_frame == 1. This ensures that the proper endianess is set so |
| 80 | * that the bytes are transmitted in the right order for a smp request frame. |
Dave Jiang | e2023b8 | 2011-04-21 05:34:49 +0000 | [diff] [blame] | 81 | * @sci_req: This parameter specifies the smp request object being |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 82 | * constructed. |
| 83 | * |
| 84 | */ |
Dave Jiang | 2ec53eb | 2011-05-04 18:01:22 -0700 | [diff] [blame] | 85 | static void |
| 86 | scu_smp_request_construct_task_context(struct scic_sds_request *sci_req, |
| 87 | struct smp_req *smp_req) |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 88 | { |
Dave Jiang | 6389a77 | 2011-02-23 15:57:27 -0800 | [diff] [blame] | 89 | dma_addr_t dma_addr; |
Dave Jiang | 2ec53eb | 2011-05-04 18:01:22 -0700 | [diff] [blame] | 90 | struct scic_sds_controller *scic; |
Dan Williams | 7ab92c9 | 2011-04-19 13:48:49 -0700 | [diff] [blame] | 91 | struct scic_sds_remote_device *sci_dev; |
Dave Jiang | 2ec53eb | 2011-05-04 18:01:22 -0700 | [diff] [blame] | 92 | struct scic_sds_port *sci_port; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 93 | struct scu_task_context *task_context; |
Dave Jiang | 51a57cf | 2011-05-04 18:28:32 -0700 | [diff] [blame] | 94 | ssize_t word_cnt = sizeof(struct smp_req) / sizeof(u32); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 95 | |
| 96 | /* byte swap the smp request. */ |
Dan Williams | b764581 | 2011-05-08 02:35:32 -0700 | [diff] [blame] | 97 | sci_swab32_cpy(&sci_req->smp.cmd, smp_req, |
Dave Jiang | 51a57cf | 2011-05-04 18:28:32 -0700 | [diff] [blame] | 98 | word_cnt); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 99 | |
Dave Jiang | 2ec53eb | 2011-05-04 18:01:22 -0700 | [diff] [blame] | 100 | task_context = scic_sds_request_get_task_context(sci_req); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 101 | |
Dave Jiang | 2ec53eb | 2011-05-04 18:01:22 -0700 | [diff] [blame] | 102 | scic = scic_sds_request_get_controller(sci_req); |
| 103 | sci_dev = scic_sds_request_get_device(sci_req); |
| 104 | sci_port = scic_sds_request_get_port(sci_req); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 105 | |
| 106 | /* |
| 107 | * Fill in the TC with the its required data |
Dave Jiang | 6389a77 | 2011-02-23 15:57:27 -0800 | [diff] [blame] | 108 | * 00h |
| 109 | */ |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 110 | task_context->priority = 0; |
| 111 | task_context->initiator_request = 1; |
Dan Williams | 8f304c3 | 2011-04-29 13:20:30 -0700 | [diff] [blame] | 112 | task_context->connection_rate = sci_dev->connection_rate; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 113 | task_context->protocol_engine_index = |
Dave Jiang | 2ec53eb | 2011-05-04 18:01:22 -0700 | [diff] [blame] | 114 | scic_sds_controller_get_protocol_engine_group(scic); |
| 115 | task_context->logical_port_index = scic_sds_port_get_index(sci_port); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 116 | task_context->protocol_type = SCU_TASK_CONTEXT_PROTOCOL_SMP; |
| 117 | task_context->abort = 0; |
| 118 | task_context->valid = SCU_TASK_CONTEXT_VALID; |
| 119 | task_context->context_type = SCU_TASK_CONTEXT_TYPE; |
| 120 | |
| 121 | /* 04h */ |
Dan Williams | 7ab92c9 | 2011-04-19 13:48:49 -0700 | [diff] [blame] | 122 | task_context->remote_node_index = sci_dev->rnc.remote_node_index; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 123 | task_context->command_code = 0; |
| 124 | task_context->task_type = SCU_TASK_TYPE_SMP_REQUEST; |
| 125 | |
| 126 | /* 08h */ |
| 127 | task_context->link_layer_control = 0; |
| 128 | task_context->do_not_dma_ssp_good_response = 1; |
| 129 | task_context->strict_ordering = 0; |
| 130 | task_context->control_frame = 1; |
| 131 | task_context->timeout_enable = 0; |
| 132 | task_context->block_guard_enable = 0; |
| 133 | |
| 134 | /* 0ch */ |
| 135 | task_context->address_modifier = 0; |
| 136 | |
| 137 | /* 10h */ |
Dave Jiang | 2ec53eb | 2011-05-04 18:01:22 -0700 | [diff] [blame] | 138 | task_context->ssp_command_iu_length = smp_req->req_len; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 139 | |
| 140 | /* 14h */ |
| 141 | task_context->transfer_length_bytes = 0; |
| 142 | |
| 143 | /* |
| 144 | * 18h ~ 30h, protocol specific |
| 145 | * since commandIU has been build by framework at this point, we just |
| 146 | * copy the frist DWord from command IU to this location. */ |
Dan Williams | b764581 | 2011-05-08 02:35:32 -0700 | [diff] [blame] | 147 | memcpy(&task_context->type.smp, &sci_req->smp.cmd, sizeof(u32)); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 148 | |
| 149 | /* |
| 150 | * 40h |
Dave Jiang | 6389a77 | 2011-02-23 15:57:27 -0800 | [diff] [blame] | 151 | * "For SMP you could program it to zero. We would prefer that way |
| 152 | * so that done code will be consistent." - Venki |
| 153 | */ |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 154 | task_context->task_phase = 0; |
| 155 | |
Dave Jiang | 2ec53eb | 2011-05-04 18:01:22 -0700 | [diff] [blame] | 156 | if (sci_req->was_tag_assigned_by_user) { |
Dave Jiang | 6389a77 | 2011-02-23 15:57:27 -0800 | [diff] [blame] | 157 | /* |
| 158 | * Build the task context now since we have already read |
| 159 | * the data |
| 160 | */ |
Dave Jiang | 2ec53eb | 2011-05-04 18:01:22 -0700 | [diff] [blame] | 161 | sci_req->post_context = |
Dave Jiang | 6389a77 | 2011-02-23 15:57:27 -0800 | [diff] [blame] | 162 | (SCU_CONTEXT_COMMAND_REQUEST_TYPE_POST_TC | |
Dave Jiang | 2ec53eb | 2011-05-04 18:01:22 -0700 | [diff] [blame] | 163 | (scic_sds_controller_get_protocol_engine_group(scic) << |
Dave Jiang | 6389a77 | 2011-02-23 15:57:27 -0800 | [diff] [blame] | 164 | SCU_CONTEXT_COMMAND_PROTOCOL_ENGINE_GROUP_SHIFT) | |
Dave Jiang | 2ec53eb | 2011-05-04 18:01:22 -0700 | [diff] [blame] | 165 | (scic_sds_port_get_index(sci_port) << |
Dave Jiang | 6389a77 | 2011-02-23 15:57:27 -0800 | [diff] [blame] | 166 | SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT) | |
Dave Jiang | 2ec53eb | 2011-05-04 18:01:22 -0700 | [diff] [blame] | 167 | scic_sds_io_tag_get_index(sci_req->io_tag)); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 168 | } else { |
Dave Jiang | 6389a77 | 2011-02-23 15:57:27 -0800 | [diff] [blame] | 169 | /* |
| 170 | * Build the task context now since we have already read |
| 171 | * the data. |
| 172 | * I/O tag index is not assigned because we have to wait |
| 173 | * until we get a TCi. |
| 174 | */ |
Dave Jiang | 2ec53eb | 2011-05-04 18:01:22 -0700 | [diff] [blame] | 175 | sci_req->post_context = |
Dave Jiang | 6389a77 | 2011-02-23 15:57:27 -0800 | [diff] [blame] | 176 | (SCU_CONTEXT_COMMAND_REQUEST_TYPE_POST_TC | |
Dave Jiang | 2ec53eb | 2011-05-04 18:01:22 -0700 | [diff] [blame] | 177 | (scic_sds_controller_get_protocol_engine_group(scic) << |
Dave Jiang | 6389a77 | 2011-02-23 15:57:27 -0800 | [diff] [blame] | 178 | SCU_CONTEXT_COMMAND_PROTOCOL_ENGINE_GROUP_SHIFT) | |
Dave Jiang | 2ec53eb | 2011-05-04 18:01:22 -0700 | [diff] [blame] | 179 | (scic_sds_port_get_index(sci_port) << |
Dave Jiang | 6389a77 | 2011-02-23 15:57:27 -0800 | [diff] [blame] | 180 | SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT)); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 181 | } |
| 182 | |
| 183 | /* |
Dave Jiang | 6389a77 | 2011-02-23 15:57:27 -0800 | [diff] [blame] | 184 | * Copy the physical address for the command buffer to the SCU Task |
| 185 | * Context command buffer should not contain command header. |
| 186 | */ |
Dave Jiang | 2ec53eb | 2011-05-04 18:01:22 -0700 | [diff] [blame] | 187 | dma_addr = scic_io_request_get_dma_addr(sci_req, |
Dan Williams | b764581 | 2011-05-08 02:35:32 -0700 | [diff] [blame] | 188 | ((char *) &sci_req->smp.cmd) + |
Dave Jiang | 6389a77 | 2011-02-23 15:57:27 -0800 | [diff] [blame] | 189 | sizeof(u32)); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 190 | |
Dave Jiang | 6389a77 | 2011-02-23 15:57:27 -0800 | [diff] [blame] | 191 | task_context->command_iu_upper = upper_32_bits(dma_addr); |
| 192 | task_context->command_iu_lower = lower_32_bits(dma_addr); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 193 | |
| 194 | /* SMP response comes as UF, so no need to set response IU address. */ |
| 195 | task_context->response_iu_upper = 0; |
| 196 | task_context->response_iu_lower = 0; |
| 197 | } |
| 198 | |
Dave Jiang | d20930a | 2011-05-04 18:07:09 -0700 | [diff] [blame] | 199 | /* |
| 200 | * This function processes an unsolicited frame while the SMP request is waiting |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 201 | * for a response frame. It will copy the response data, release the |
| 202 | * unsolicited frame, and transition the request to the |
| 203 | * SCI_BASE_REQUEST_STATE_COMPLETED state. |
Dave Jiang | e2023b8 | 2011-04-21 05:34:49 +0000 | [diff] [blame] | 204 | * @sci_req: This parameter specifies the request for which the |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 205 | * unsolicited frame was received. |
| 206 | * @frame_index: This parameter indicates the unsolicited frame index that |
| 207 | * should contain the response. |
| 208 | * |
Dave Jiang | d20930a | 2011-05-04 18:07:09 -0700 | [diff] [blame] | 209 | * This function returns an indication of whether the response frame was handled |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 210 | * successfully or not. SCI_SUCCESS Currently this value is always returned and |
| 211 | * indicates successful processing of the TC response. |
| 212 | */ |
Dave Jiang | d20930a | 2011-05-04 18:07:09 -0700 | [diff] [blame] | 213 | static enum sci_status |
Dan Williams | b764581 | 2011-05-08 02:35:32 -0700 | [diff] [blame] | 214 | scic_sds_smp_request_await_response_frame_handler(struct scic_sds_request *sci_req, |
| 215 | u32 frame_index) |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 216 | { |
| 217 | enum sci_status status; |
| 218 | void *frame_header; |
Dan Williams | b764581 | 2011-05-08 02:35:32 -0700 | [diff] [blame] | 219 | struct smp_resp *rsp_hdr = &sci_req->smp.rsp; |
Dave Jiang | 51a57cf | 2011-05-04 18:28:32 -0700 | [diff] [blame] | 220 | ssize_t word_cnt = SMP_RESP_HDR_SZ / sizeof(u32); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 221 | |
| 222 | status = scic_sds_unsolicited_frame_control_get_header( |
Dave Jiang | e2023b8 | 2011-04-21 05:34:49 +0000 | [diff] [blame] | 223 | &(scic_sds_request_get_controller(sci_req)->uf_control), |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 224 | frame_index, |
Dave Jiang | d20930a | 2011-05-04 18:07:09 -0700 | [diff] [blame] | 225 | &frame_header); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 226 | |
| 227 | /* byte swap the header. */ |
Dan Williams | b764581 | 2011-05-08 02:35:32 -0700 | [diff] [blame] | 228 | sci_swab32_cpy(rsp_hdr, frame_header, word_cnt); |
Dave Jiang | d20930a | 2011-05-04 18:07:09 -0700 | [diff] [blame] | 229 | |
| 230 | if (rsp_hdr->frame_type == SMP_RESPONSE) { |
| 231 | void *smp_resp; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 232 | |
| 233 | status = scic_sds_unsolicited_frame_control_get_buffer( |
Dave Jiang | e2023b8 | 2011-04-21 05:34:49 +0000 | [diff] [blame] | 234 | &(scic_sds_request_get_controller(sci_req)->uf_control), |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 235 | frame_index, |
Dave Jiang | d20930a | 2011-05-04 18:07:09 -0700 | [diff] [blame] | 236 | &smp_resp); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 237 | |
Dave Jiang | 51a57cf | 2011-05-04 18:28:32 -0700 | [diff] [blame] | 238 | word_cnt = (sizeof(struct smp_req) - SMP_RESP_HDR_SZ) / |
| 239 | sizeof(u32); |
| 240 | |
Dan Williams | b764581 | 2011-05-08 02:35:32 -0700 | [diff] [blame] | 241 | sci_swab32_cpy(((u8 *) rsp_hdr) + SMP_RESP_HDR_SZ, |
Dave Jiang | 51a57cf | 2011-05-04 18:28:32 -0700 | [diff] [blame] | 242 | smp_resp, word_cnt); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 243 | |
| 244 | scic_sds_request_set_status( |
Dave Jiang | d20930a | 2011-05-04 18:07:09 -0700 | [diff] [blame] | 245 | sci_req, SCU_TASK_DONE_GOOD, SCI_SUCCESS); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 246 | |
| 247 | sci_base_state_machine_change_state( |
Dave Jiang | e2023b8 | 2011-04-21 05:34:49 +0000 | [diff] [blame] | 248 | &sci_req->started_substate_machine, |
Dave Jiang | d20930a | 2011-05-04 18:07:09 -0700 | [diff] [blame] | 249 | SCIC_SDS_SMP_REQUEST_STARTED_SUBSTATE_AWAIT_TC_COMPLETION); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 250 | } else { |
| 251 | /* This was not a response frame why did it get forwarded? */ |
Dave Jiang | e2023b8 | 2011-04-21 05:34:49 +0000 | [diff] [blame] | 252 | dev_err(scic_to_dev(sci_req->owning_controller), |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 253 | "%s: SCIC SMP Request 0x%p received unexpected frame " |
| 254 | "%d type 0x%02x\n", |
| 255 | __func__, |
Dave Jiang | e2023b8 | 2011-04-21 05:34:49 +0000 | [diff] [blame] | 256 | sci_req, |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 257 | frame_index, |
Dave Jiang | d20930a | 2011-05-04 18:07:09 -0700 | [diff] [blame] | 258 | rsp_hdr->frame_type); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 259 | |
| 260 | scic_sds_request_set_status( |
Dave Jiang | e2023b8 | 2011-04-21 05:34:49 +0000 | [diff] [blame] | 261 | sci_req, |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 262 | SCU_TASK_DONE_SMP_FRM_TYPE_ERR, |
Dave Jiang | d20930a | 2011-05-04 18:07:09 -0700 | [diff] [blame] | 263 | SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 264 | |
| 265 | sci_base_state_machine_change_state( |
Dave Jiang | e2023b8 | 2011-04-21 05:34:49 +0000 | [diff] [blame] | 266 | &sci_req->state_machine, |
Dave Jiang | d20930a | 2011-05-04 18:07:09 -0700 | [diff] [blame] | 267 | SCI_BASE_REQUEST_STATE_COMPLETED); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 268 | } |
| 269 | |
Dave Jiang | d20930a | 2011-05-04 18:07:09 -0700 | [diff] [blame] | 270 | scic_sds_controller_release_frame(sci_req->owning_controller, |
| 271 | frame_index); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 272 | |
| 273 | return SCI_SUCCESS; |
| 274 | } |
| 275 | |
| 276 | |
| 277 | /** |
| 278 | * This method processes an abnormal TC completion while the SMP request is |
| 279 | * waiting for a response frame. It decides what happened to the IO based |
| 280 | * on TC completion status. |
Dave Jiang | e2023b8 | 2011-04-21 05:34:49 +0000 | [diff] [blame] | 281 | * @sci_req: This parameter specifies the request for which the TC |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 282 | * completion was received. |
| 283 | * @completion_code: This parameter indicates the completion status information |
| 284 | * for the TC. |
| 285 | * |
| 286 | * Indicate if the tc completion handler was successful. SCI_SUCCESS currently |
| 287 | * this method always returns success. |
| 288 | */ |
| 289 | static enum sci_status scic_sds_smp_request_await_response_tc_completion_handler( |
Dave Jiang | e2023b8 | 2011-04-21 05:34:49 +0000 | [diff] [blame] | 290 | struct scic_sds_request *sci_req, |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 291 | u32 completion_code) |
| 292 | { |
| 293 | switch (SCU_GET_COMPLETION_TL_STATUS(completion_code)) { |
| 294 | case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_GOOD): |
| 295 | /* |
| 296 | * In the AWAIT RESPONSE state, any TC completion is unexpected. |
| 297 | * but if the TC has success status, we complete the IO anyway. */ |
| 298 | scic_sds_request_set_status( |
Dave Jiang | e2023b8 | 2011-04-21 05:34:49 +0000 | [diff] [blame] | 299 | sci_req, SCU_TASK_DONE_GOOD, SCI_SUCCESS |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 300 | ); |
| 301 | |
| 302 | sci_base_state_machine_change_state( |
Dave Jiang | e2023b8 | 2011-04-21 05:34:49 +0000 | [diff] [blame] | 303 | &sci_req->state_machine, |
Christoph Hellwig | 38aa74e | 2011-03-28 09:21:14 -0400 | [diff] [blame] | 304 | SCI_BASE_REQUEST_STATE_COMPLETED); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 305 | break; |
| 306 | |
| 307 | case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_SMP_RESP_TO_ERR): |
| 308 | case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_SMP_UFI_ERR): |
| 309 | case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_SMP_FRM_TYPE_ERR): |
| 310 | case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_SMP_LL_RX_ERR): |
| 311 | /* |
| 312 | * These status has been seen in a specific LSI expander, which sometimes |
| 313 | * is not able to send smp response within 2 ms. This causes our hardware |
| 314 | * break the connection and set TC completion with one of these SMP_XXX_XX_ERR |
| 315 | * status. For these type of error, we ask scic user to retry the request. */ |
| 316 | scic_sds_request_set_status( |
Dave Jiang | e2023b8 | 2011-04-21 05:34:49 +0000 | [diff] [blame] | 317 | sci_req, SCU_TASK_DONE_SMP_RESP_TO_ERR, SCI_FAILURE_RETRY_REQUIRED |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 318 | ); |
| 319 | |
| 320 | sci_base_state_machine_change_state( |
Dave Jiang | e2023b8 | 2011-04-21 05:34:49 +0000 | [diff] [blame] | 321 | &sci_req->state_machine, |
Christoph Hellwig | 38aa74e | 2011-03-28 09:21:14 -0400 | [diff] [blame] | 322 | SCI_BASE_REQUEST_STATE_COMPLETED); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 323 | break; |
| 324 | |
| 325 | default: |
| 326 | /* |
| 327 | * All other completion status cause the IO to be complete. If a NAK |
| 328 | * was received, then it is up to the user to retry the request. */ |
| 329 | scic_sds_request_set_status( |
Dave Jiang | e2023b8 | 2011-04-21 05:34:49 +0000 | [diff] [blame] | 330 | sci_req, |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 331 | SCU_NORMALIZE_COMPLETION_STATUS(completion_code), |
| 332 | SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR |
| 333 | ); |
| 334 | |
| 335 | sci_base_state_machine_change_state( |
Dave Jiang | e2023b8 | 2011-04-21 05:34:49 +0000 | [diff] [blame] | 336 | &sci_req->state_machine, |
Christoph Hellwig | 38aa74e | 2011-03-28 09:21:14 -0400 | [diff] [blame] | 337 | SCI_BASE_REQUEST_STATE_COMPLETED); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 338 | break; |
| 339 | } |
| 340 | |
| 341 | return SCI_SUCCESS; |
| 342 | } |
| 343 | |
| 344 | |
| 345 | /** |
| 346 | * This method processes the completions transport layer (TL) status to |
| 347 | * determine if the SMP request was sent successfully. If the SMP request |
| 348 | * was sent successfully, then the state for the SMP request transits to |
| 349 | * waiting for a response frame. |
Dave Jiang | e2023b8 | 2011-04-21 05:34:49 +0000 | [diff] [blame] | 350 | * @sci_req: This parameter specifies the request for which the TC |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 351 | * completion was received. |
| 352 | * @completion_code: This parameter indicates the completion status information |
| 353 | * for the TC. |
| 354 | * |
| 355 | * Indicate if the tc completion handler was successful. SCI_SUCCESS currently |
| 356 | * this method always returns success. |
| 357 | */ |
| 358 | static enum sci_status scic_sds_smp_request_await_tc_completion_tc_completion_handler( |
Dave Jiang | e2023b8 | 2011-04-21 05:34:49 +0000 | [diff] [blame] | 359 | struct scic_sds_request *sci_req, |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 360 | u32 completion_code) |
| 361 | { |
| 362 | switch (SCU_GET_COMPLETION_TL_STATUS(completion_code)) { |
| 363 | case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_GOOD): |
| 364 | scic_sds_request_set_status( |
Dave Jiang | e2023b8 | 2011-04-21 05:34:49 +0000 | [diff] [blame] | 365 | sci_req, SCU_TASK_DONE_GOOD, SCI_SUCCESS |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 366 | ); |
| 367 | |
| 368 | sci_base_state_machine_change_state( |
Dave Jiang | e2023b8 | 2011-04-21 05:34:49 +0000 | [diff] [blame] | 369 | &sci_req->state_machine, |
Christoph Hellwig | 38aa74e | 2011-03-28 09:21:14 -0400 | [diff] [blame] | 370 | SCI_BASE_REQUEST_STATE_COMPLETED); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 371 | break; |
| 372 | |
| 373 | default: |
| 374 | /* |
| 375 | * All other completion status cause the IO to be complete. If a NAK |
| 376 | * was received, then it is up to the user to retry the request. */ |
| 377 | scic_sds_request_set_status( |
Dave Jiang | e2023b8 | 2011-04-21 05:34:49 +0000 | [diff] [blame] | 378 | sci_req, |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 379 | SCU_NORMALIZE_COMPLETION_STATUS(completion_code), |
| 380 | SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR |
| 381 | ); |
| 382 | |
| 383 | sci_base_state_machine_change_state( |
Dave Jiang | e2023b8 | 2011-04-21 05:34:49 +0000 | [diff] [blame] | 384 | &sci_req->state_machine, |
Christoph Hellwig | 38aa74e | 2011-03-28 09:21:14 -0400 | [diff] [blame] | 385 | SCI_BASE_REQUEST_STATE_COMPLETED); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 386 | break; |
| 387 | } |
| 388 | |
| 389 | return SCI_SUCCESS; |
| 390 | } |
| 391 | |
| 392 | |
Dan Williams | 35173d5 | 2011-03-26 16:43:01 -0700 | [diff] [blame] | 393 | static const struct scic_sds_io_request_state_handler scic_sds_smp_request_started_substate_handler_table[] = { |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 394 | [SCIC_SDS_SMP_REQUEST_STARTED_SUBSTATE_AWAIT_RESPONSE] = { |
Christoph Hellwig | 38aa74e | 2011-03-28 09:21:14 -0400 | [diff] [blame] | 395 | .abort_handler = scic_sds_request_started_state_abort_handler, |
Christoph Hellwig | 38aa74e | 2011-03-28 09:21:14 -0400 | [diff] [blame] | 396 | .tc_completion_handler = scic_sds_smp_request_await_response_tc_completion_handler, |
Christoph Hellwig | 38aa74e | 2011-03-28 09:21:14 -0400 | [diff] [blame] | 397 | .frame_handler = scic_sds_smp_request_await_response_frame_handler, |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 398 | }, |
| 399 | [SCIC_SDS_SMP_REQUEST_STARTED_SUBSTATE_AWAIT_TC_COMPLETION] = { |
Christoph Hellwig | 38aa74e | 2011-03-28 09:21:14 -0400 | [diff] [blame] | 400 | .abort_handler = scic_sds_request_started_state_abort_handler, |
Christoph Hellwig | 38aa74e | 2011-03-28 09:21:14 -0400 | [diff] [blame] | 401 | .tc_completion_handler = scic_sds_smp_request_await_tc_completion_tc_completion_handler, |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 402 | } |
| 403 | }; |
| 404 | |
| 405 | /** |
| 406 | * This method performs the actions required when entering the |
| 407 | * SCIC_SDS_SMP_REQUEST_STARTED_SUBSTATE_AWAIT_TC_RESPONSE sub-state. This |
| 408 | * includes setting the IO request state handlers for this sub-state. |
| 409 | * @object: This parameter specifies the request object for which the sub-state |
Maciej Patelczyk | 9a0fff7 | 2011-04-28 22:06:01 +0000 | [diff] [blame] | 410 | * change is occurring. |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 411 | * |
| 412 | * none. |
| 413 | */ |
| 414 | static void scic_sds_smp_request_started_await_response_substate_enter( |
Maciej Patelczyk | 9a0fff7 | 2011-04-28 22:06:01 +0000 | [diff] [blame] | 415 | void *object) |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 416 | { |
Maciej Patelczyk | 890cae9 | 2011-04-28 22:06:31 +0000 | [diff] [blame] | 417 | struct scic_sds_request *sci_req = object; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 418 | |
| 419 | SET_STATE_HANDLER( |
Dave Jiang | e2023b8 | 2011-04-21 05:34:49 +0000 | [diff] [blame] | 420 | sci_req, |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 421 | scic_sds_smp_request_started_substate_handler_table, |
| 422 | SCIC_SDS_SMP_REQUEST_STARTED_SUBSTATE_AWAIT_RESPONSE |
| 423 | ); |
| 424 | } |
| 425 | |
| 426 | /** |
| 427 | * This method performs the actions required when entering the |
| 428 | * SCIC_SDS_SMP_REQUEST_STARTED_SUBSTATE_AWAIT_TC_COMPLETION sub-state. |
| 429 | * This includes setting the SMP request state handlers for this sub-state. |
| 430 | * @object: This parameter specifies the request object for which the sub-state |
Maciej Patelczyk | 9a0fff7 | 2011-04-28 22:06:01 +0000 | [diff] [blame] | 431 | * change is occurring. |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 432 | * |
| 433 | * none. |
| 434 | */ |
| 435 | static void scic_sds_smp_request_started_await_tc_completion_substate_enter( |
Maciej Patelczyk | 9a0fff7 | 2011-04-28 22:06:01 +0000 | [diff] [blame] | 436 | void *object) |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 437 | { |
Maciej Patelczyk | 890cae9 | 2011-04-28 22:06:31 +0000 | [diff] [blame] | 438 | struct scic_sds_request *sci_req = object; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 439 | |
| 440 | SET_STATE_HANDLER( |
Dave Jiang | e2023b8 | 2011-04-21 05:34:49 +0000 | [diff] [blame] | 441 | sci_req, |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 442 | scic_sds_smp_request_started_substate_handler_table, |
| 443 | SCIC_SDS_SMP_REQUEST_STARTED_SUBSTATE_AWAIT_TC_COMPLETION |
| 444 | ); |
| 445 | } |
| 446 | |
Dan Williams | 35173d5 | 2011-03-26 16:43:01 -0700 | [diff] [blame] | 447 | static const struct sci_base_state scic_sds_smp_request_started_substate_table[] = { |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 448 | [SCIC_SDS_SMP_REQUEST_STARTED_SUBSTATE_AWAIT_RESPONSE] = { |
| 449 | .enter_state = scic_sds_smp_request_started_await_response_substate_enter, |
| 450 | }, |
| 451 | [SCIC_SDS_SMP_REQUEST_STARTED_SUBSTATE_AWAIT_TC_COMPLETION] = { |
| 452 | .enter_state = scic_sds_smp_request_started_await_tc_completion_substate_enter, |
| 453 | }, |
| 454 | }; |
| 455 | |
Dan Williams | 35173d5 | 2011-03-26 16:43:01 -0700 | [diff] [blame] | 456 | /** |
| 457 | * This method is called by the SCI user to build an SMP IO request. |
| 458 | * |
| 459 | * - The user must have previously called scic_io_request_construct() on the |
| 460 | * supplied IO request. Indicate if the controller successfully built the IO |
| 461 | * request. SCI_SUCCESS This value is returned if the IO request was |
| 462 | * successfully built. SCI_FAILURE_UNSUPPORTED_PROTOCOL This value is returned |
| 463 | * if the remote_device does not support the SMP protocol. |
| 464 | * SCI_FAILURE_INVALID_ASSOCIATION This value is returned if the user did not |
| 465 | * properly set the association between the SCIC IO request and the user's IO |
Maciej Patelczyk | be2f41c | 2011-04-28 22:06:36 +0000 | [diff] [blame] | 466 | * request. |
Dan Williams | 35173d5 | 2011-03-26 16:43:01 -0700 | [diff] [blame] | 467 | */ |
| 468 | enum sci_status scic_io_request_construct_smp(struct scic_sds_request *sci_req) |
| 469 | { |
Dave Jiang | 2ec53eb | 2011-05-04 18:01:22 -0700 | [diff] [blame] | 470 | struct smp_req *smp_req = kmalloc(sizeof(*smp_req), GFP_KERNEL); |
Dan Williams | 35173d5 | 2011-03-26 16:43:01 -0700 | [diff] [blame] | 471 | |
| 472 | if (!smp_req) |
| 473 | return SCI_FAILURE_INSUFFICIENT_RESOURCES; |
| 474 | |
| 475 | sci_req->protocol = SCIC_SMP_PROTOCOL; |
| 476 | sci_req->has_started_substate_machine = true; |
| 477 | |
| 478 | /* Construct the started sub-state machine. */ |
| 479 | sci_base_state_machine_construct( |
| 480 | &sci_req->started_substate_machine, |
Maciej Patelczyk | 890cae9 | 2011-04-28 22:06:31 +0000 | [diff] [blame] | 481 | sci_req, |
Dan Williams | 35173d5 | 2011-03-26 16:43:01 -0700 | [diff] [blame] | 482 | scic_sds_smp_request_started_substate_table, |
| 483 | SCIC_SDS_SMP_REQUEST_STARTED_SUBSTATE_AWAIT_RESPONSE |
| 484 | ); |
| 485 | |
| 486 | /* Construct the SMP SCU Task Context */ |
Dan Williams | b764581 | 2011-05-08 02:35:32 -0700 | [diff] [blame] | 487 | memcpy(smp_req, &sci_req->smp.cmd, sizeof(*smp_req)); |
Dan Williams | 35173d5 | 2011-03-26 16:43:01 -0700 | [diff] [blame] | 488 | |
| 489 | /* |
| 490 | * Look at the SMP requests' header fields; for certain SAS 1.x SMP |
| 491 | * functions under SAS 2.0, a zero request length really indicates |
| 492 | * a non-zero default length. */ |
Dave Jiang | 2ec53eb | 2011-05-04 18:01:22 -0700 | [diff] [blame] | 493 | if (smp_req->req_len == 0) { |
| 494 | switch (smp_req->func) { |
| 495 | case SMP_DISCOVER: |
| 496 | case SMP_REPORT_PHY_ERR_LOG: |
| 497 | case SMP_REPORT_PHY_SATA: |
| 498 | case SMP_REPORT_ROUTE_INFO: |
| 499 | smp_req->req_len = 2; |
Dan Williams | 35173d5 | 2011-03-26 16:43:01 -0700 | [diff] [blame] | 500 | break; |
Dave Jiang | 2ec53eb | 2011-05-04 18:01:22 -0700 | [diff] [blame] | 501 | case SMP_CONF_ROUTE_INFO: |
| 502 | case SMP_PHY_CONTROL: |
| 503 | case SMP_PHY_TEST_FUNCTION: |
| 504 | smp_req->req_len = 9; |
Dan Williams | 35173d5 | 2011-03-26 16:43:01 -0700 | [diff] [blame] | 505 | break; |
| 506 | /* Default - zero is a valid default for 2.0. */ |
| 507 | } |
| 508 | } |
| 509 | |
| 510 | scu_smp_request_construct_task_context(sci_req, smp_req); |
| 511 | |
Christoph Hellwig | 38aa74e | 2011-03-28 09:21:14 -0400 | [diff] [blame] | 512 | sci_base_state_machine_change_state(&sci_req->state_machine, |
| 513 | SCI_BASE_REQUEST_STATE_CONSTRUCTED); |
Dan Williams | 35173d5 | 2011-03-26 16:43:01 -0700 | [diff] [blame] | 514 | |
| 515 | kfree(smp_req); |
| 516 | |
| 517 | return SCI_SUCCESS; |
| 518 | } |