isci: namespacecheck cleanups
[deliverable/linux.git] / drivers / scsi / isci / core / scic_sds_request.c
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
56
57 #include "intel_sas.h"
58 #include "intel_sata.h"
59 #include "intel_sat.h"
60 #include "sci_base_request.h"
61 #include "scic_controller.h"
62 #include "scic_io_request.h"
63 #include "scic_remote_device.h"
64 #include "scic_sds_controller.h"
65 #include "scic_sds_controller_registers.h"
66 #include "scic_sds_pci.h"
67 #include "scic_sds_port.h"
68 #include "scic_sds_remote_device.h"
69 #include "scic_sds_request.h"
70 #include "scic_sds_smp_request.h"
71 #include "scic_sds_stp_request.h"
72 #include "scic_sds_unsolicited_frame_control.h"
73 #include "sci_environment.h"
74 #include "sci_util.h"
75 #include "scu_completion_codes.h"
76 #include "scu_constants.h"
77 #include "scu_task_context.h"
78
79 #if !defined(DISABLE_ATAPI)
80 #include "scic_sds_stp_packet_request.h"
81 #endif
82
83 /*
84 * ****************************************************************************
85 * * SCIC SDS IO REQUEST CONSTANTS
86 * **************************************************************************** */
87
88 /**
89 *
90 *
91 * We have no timer requirements for IO requests right now
92 */
93 #define SCIC_SDS_IO_REQUEST_MINIMUM_TIMER_COUNT (0)
94 #define SCIC_SDS_IO_REQUEST_MAXIMUM_TIMER_COUNT (0)
95
96 /*
97 * ****************************************************************************
98 * * SCIC SDS IO REQUEST MACROS
99 * **************************************************************************** */
100
101 /**
102 * scic_ssp_io_request_get_object_size() -
103 *
104 * This macro returns the sizeof memory required to store the an SSP IO
105 * request. This does not include the size of the SGL or SCU Task Context
106 * memory.
107 */
108 #define scic_ssp_io_request_get_object_size() \
109 (\
110 sizeof(struct sci_ssp_command_iu) \
111 + sizeof(struct sci_ssp_response_iu) \
112 )
113
114 /**
115 * scic_sds_ssp_request_get_command_buffer() -
116 *
117 * This macro returns the address of the ssp command buffer in the io request
118 * memory
119 */
120 #define scic_sds_ssp_request_get_command_buffer(memory) \
121 ((struct sci_ssp_command_iu *)(\
122 ((char *)(memory)) + sizeof(struct scic_sds_request) \
123 ))
124
125 /**
126 * scic_sds_ssp_request_get_response_buffer() -
127 *
128 * This macro returns the address of the ssp response buffer in the io request
129 * memory
130 */
131 #define scic_sds_ssp_request_get_response_buffer(memory) \
132 ((struct sci_ssp_response_iu *)(\
133 ((char *)(scic_sds_ssp_request_get_command_buffer(memory))) \
134 + sizeof(struct sci_ssp_command_iu) \
135 ))
136
137 /**
138 * scic_sds_ssp_request_get_task_context_buffer() -
139 *
140 * This macro returns the address of the task context buffer in the io request
141 * memory
142 */
143 #define scic_sds_ssp_request_get_task_context_buffer(memory) \
144 ((struct scu_task_context *)(\
145 ((char *)(scic_sds_ssp_request_get_response_buffer(memory))) \
146 + sizeof(struct sci_ssp_response_iu) \
147 ))
148
149 /**
150 * scic_sds_ssp_request_get_sgl_element_buffer() -
151 *
152 * This macro returns the address of the sgl elment pairs in the io request
153 * memory buffer
154 */
155 #define scic_sds_ssp_request_get_sgl_element_buffer(memory) \
156 ((struct scu_sgl_element_pair *)(\
157 ((char *)(scic_sds_ssp_request_get_task_context_buffer(memory))) \
158 + sizeof(struct scu_task_context) \
159 ))
160
161
162 /**
163 * scic_ssp_task_request_get_object_size() -
164 *
165 * This macro returns the sizeof of memory required to store an SSP Task
166 * request. This does not include the size of the SCU Task Context memory.
167 */
168 #define scic_ssp_task_request_get_object_size() \
169 (\
170 sizeof(struct sci_ssp_task_iu) \
171 + sizeof(struct sci_ssp_response_iu) \
172 )
173
174 /**
175 * scic_sds_ssp_task_request_get_command_buffer() -
176 *
177 * This macro returns the address of the ssp command buffer in the task request
178 * memory. Yes its the same as the above macro except for the name.
179 */
180 #define scic_sds_ssp_task_request_get_command_buffer(memory) \
181 ((struct sci_ssp_task_iu *)(\
182 ((char *)(memory)) + sizeof(struct scic_sds_request) \
183 ))
184
185 /**
186 * scic_sds_ssp_task_request_get_response_buffer() -
187 *
188 * This macro returns the address of the ssp response buffer in the task
189 * request memory.
190 */
191 #define scic_sds_ssp_task_request_get_response_buffer(memory) \
192 ((struct sci_ssp_response_iu *)(\
193 ((char *)(scic_sds_ssp_task_request_get_command_buffer(memory))) \
194 + sizeof(struct sci_ssp_task_iu) \
195 ))
196
197 /**
198 * scic_sds_ssp_task_request_get_task_context_buffer() -
199 *
200 * This macro returs the task context buffer for the SSP task request.
201 */
202 #define scic_sds_ssp_task_request_get_task_context_buffer(memory) \
203 ((struct scu_task_context *)(\
204 ((char *)(scic_sds_ssp_task_request_get_response_buffer(memory))) \
205 + sizeof(struct sci_ssp_response_iu) \
206 ))
207
208
209
210 /*
211 * ****************************************************************************
212 * * SCIC SDS IO REQUEST PRIVATE METHODS
213 * **************************************************************************** */
214
215 /**
216 *
217 *
218 * This method returns the size required to store an SSP IO request object. u32
219 */
220 static u32 scic_sds_ssp_request_get_object_size(void)
221 {
222 return sizeof(struct scic_sds_request)
223 + scic_ssp_io_request_get_object_size()
224 + sizeof(struct scu_task_context)
225 + SMP_CACHE_BYTES
226 + sizeof(struct scu_sgl_element_pair) * SCU_MAX_SGL_ELEMENT_PAIRS;
227 }
228
229 /**
230 * This method returns the sgl element pair for the specificed sgl_pair index.
231 * @this_request: This parameter specifies the IO request for which to retrieve
232 * the Scatter-Gather List element pair.
233 * @sgl_pair_index: This parameter specifies the index into the SGL element
234 * pair to be retrieved.
235 *
236 * This method returns a pointer to an struct scu_sgl_element_pair.
237 */
238 static struct scu_sgl_element_pair *scic_sds_request_get_sgl_element_pair(
239 struct scic_sds_request *this_request,
240 u32 sgl_pair_index
241 ) {
242 struct scu_task_context *task_context;
243
244 task_context = (struct scu_task_context *)this_request->task_context_buffer;
245
246 if (sgl_pair_index == 0) {
247 return &task_context->sgl_pair_ab;
248 } else if (sgl_pair_index == 1) {
249 return &task_context->sgl_pair_cd;
250 }
251
252 return &this_request->sgl_element_pair_buffer[sgl_pair_index - 2];
253 }
254
255 /**
256 * This function will build the SGL list for an IO request.
257 * @this_request: This parameter specifies the IO request for which to build
258 * the Scatter-Gather List.
259 *
260 */
261 void scic_sds_request_build_sgl(struct scic_sds_request *sds_request)
262 {
263 struct isci_request *isci_request =
264 (struct isci_request *)sci_object_get_association(sds_request);
265 struct isci_host *isci_host = isci_request->isci_host;
266 struct sas_task *task = isci_request_access_task(isci_request);
267 struct scatterlist *sg = NULL;
268 dma_addr_t dma_addr;
269 u32 sg_idx = 0;
270 struct scu_sgl_element_pair *scu_sg = NULL;
271 struct scu_sgl_element_pair *prev_sg = NULL;
272
273 if (task->num_scatter > 0) {
274 sg = task->scatter;
275
276 while (sg) {
277 scu_sg = scic_sds_request_get_sgl_element_pair(
278 sds_request,
279 sg_idx);
280
281 SCU_SGL_COPY(scu_sg->A, sg);
282
283 sg = sg_next(sg);
284
285 if (sg) {
286 SCU_SGL_COPY(scu_sg->B, sg);
287 sg = sg_next(sg);
288 } else
289 SCU_SGL_ZERO(scu_sg->B);
290
291 if (prev_sg) {
292 dma_addr =
293 scic_io_request_get_dma_addr(
294 sds_request,
295 scu_sg);
296
297 prev_sg->next_pair_upper =
298 upper_32_bits(dma_addr);
299 prev_sg->next_pair_lower =
300 lower_32_bits(dma_addr);
301 }
302
303 prev_sg = scu_sg;
304 sg_idx++;
305 }
306 } else { /* handle when no sg */
307 scu_sg = scic_sds_request_get_sgl_element_pair(sds_request,
308 sg_idx);
309
310 dma_addr = dma_map_single(&isci_host->pdev->dev,
311 task->scatter,
312 task->total_xfer_len,
313 task->data_dir);
314
315 isci_request->zero_scatter_daddr = dma_addr;
316
317 scu_sg->A.length = task->total_xfer_len;
318 scu_sg->A.address_upper = upper_32_bits(dma_addr);
319 scu_sg->A.address_lower = lower_32_bits(dma_addr);
320 }
321
322 if (scu_sg) {
323 scu_sg->next_pair_upper = 0;
324 scu_sg->next_pair_lower = 0;
325 }
326 }
327
328 /**
329 * This method build the remainder of the IO request object.
330 * @this_request: This parameter specifies the request object being constructed.
331 *
332 * The scic_sds_general_request_construct() must be called before this call is
333 * valid. none
334 */
335 static void scic_sds_ssp_io_request_assign_buffers(
336 struct scic_sds_request *this_request)
337 {
338 this_request->command_buffer =
339 scic_sds_ssp_request_get_command_buffer(this_request);
340 this_request->response_buffer =
341 scic_sds_ssp_request_get_response_buffer(this_request);
342 this_request->sgl_element_pair_buffer =
343 scic_sds_ssp_request_get_sgl_element_buffer(this_request);
344 this_request->sgl_element_pair_buffer =
345 PTR_ALIGN(this_request->sgl_element_pair_buffer,
346 sizeof(struct scu_sgl_element_pair));
347
348 if (this_request->was_tag_assigned_by_user == false) {
349 this_request->task_context_buffer =
350 scic_sds_ssp_request_get_task_context_buffer(this_request);
351 this_request->task_context_buffer =
352 PTR_ALIGN(this_request->task_context_buffer,
353 SMP_CACHE_BYTES);
354 }
355 }
356
357 /**
358 * This method constructs the SSP Command IU data for this io request object.
359 * @this_request: This parameter specifies the request object for which the SSP
360 * command information unit is being built.
361 *
362 */
363 static void scic_sds_io_request_build_ssp_command_iu(
364 struct scic_sds_request *sds_request)
365 {
366 struct sci_ssp_command_iu *command_frame;
367 u32 cdb_length;
368 u32 *cdb_buffer;
369 struct isci_request *isci_request =
370 (struct isci_request *)sci_object_get_association(sds_request);
371
372 command_frame =
373 (struct sci_ssp_command_iu *)sds_request->command_buffer;
374
375 command_frame->lun_upper = 0;
376 command_frame->lun_lower =
377 isci_request_ssp_io_request_get_lun(isci_request);
378
379 ((u32 *)command_frame)[2] = 0;
380
381 cdb_length = isci_request_ssp_io_request_get_cdb_length(isci_request);
382 cdb_buffer = (u32 *)isci_request_ssp_io_request_get_cdb_address(
383 isci_request);
384
385 if (cdb_length > 16) {
386 command_frame->additional_cdb_length = cdb_length - 16;
387 }
388
389 /* / @todo Is it ok to leave junk at the end of the cdb buffer? */
390 scic_word_copy_with_swap(
391 (u32 *)(&command_frame->cdb),
392 (u32 *)(cdb_buffer),
393 (cdb_length + 3) / sizeof(u32)
394 );
395
396 command_frame->enable_first_burst = 0;
397 command_frame->task_priority =
398 isci_request_ssp_io_request_get_command_priority(isci_request);
399 command_frame->task_attribute =
400 isci_request_ssp_io_request_get_task_attribute(isci_request);
401 }
402
403
404 /**
405 * This method constructs the SSP Task IU data for this io request object.
406 * @this_request:
407 *
408 */
409 static void scic_sds_task_request_build_ssp_task_iu(
410 struct scic_sds_request *sds_request)
411 {
412 struct sci_ssp_task_iu *command_frame;
413 struct isci_request *isci_request =
414 (struct isci_request *)sci_object_get_association(sds_request);
415
416 command_frame =
417 (struct sci_ssp_task_iu *)sds_request->command_buffer;
418
419 command_frame->lun_upper = 0;
420 command_frame->lun_lower = isci_request_ssp_io_request_get_lun(
421 isci_request);
422
423 ((u32 *)command_frame)[2] = 0;
424
425 command_frame->task_function =
426 isci_task_ssp_request_get_function(isci_request);
427 command_frame->task_tag =
428 isci_task_ssp_request_get_io_tag_to_manage(
429 isci_request);
430 }
431
432
433 /**
434 * This method is will fill in the SCU Task Context for any type of SSP request.
435 * @this_request:
436 * @task_context:
437 *
438 */
439 static void scu_ssp_reqeust_construct_task_context(
440 struct scic_sds_request *sds_request,
441 struct scu_task_context *task_context)
442 {
443 dma_addr_t dma_addr;
444 struct scic_sds_controller *controller;
445 struct scic_sds_remote_device *target_device;
446 struct scic_sds_port *target_port;
447
448 controller = scic_sds_request_get_controller(sds_request);
449 target_device = scic_sds_request_get_device(sds_request);
450 target_port = scic_sds_request_get_port(sds_request);
451
452 /* Fill in the TC with the its required data */
453 task_context->abort = 0;
454 task_context->priority = 0;
455 task_context->initiator_request = 1;
456 task_context->connection_rate =
457 scic_remote_device_get_connection_rate(target_device);
458 task_context->protocol_engine_index =
459 scic_sds_controller_get_protocol_engine_group(controller);
460 task_context->logical_port_index =
461 scic_sds_port_get_index(target_port);
462 task_context->protocol_type = SCU_TASK_CONTEXT_PROTOCOL_SSP;
463 task_context->valid = SCU_TASK_CONTEXT_VALID;
464 task_context->context_type = SCU_TASK_CONTEXT_TYPE;
465
466 task_context->remote_node_index =
467 scic_sds_remote_device_get_index(sds_request->target_device);
468 task_context->command_code = 0;
469
470 task_context->link_layer_control = 0;
471 task_context->do_not_dma_ssp_good_response = 1;
472 task_context->strict_ordering = 0;
473 task_context->control_frame = 0;
474 task_context->timeout_enable = 0;
475 task_context->block_guard_enable = 0;
476
477 task_context->address_modifier = 0;
478
479 /* task_context->type.ssp.tag = this_request->io_tag; */
480 task_context->task_phase = 0x01;
481
482 if (sds_request->was_tag_assigned_by_user) {
483 /*
484 * Build the task context now since we have already read
485 * the data
486 */
487 sds_request->post_context =
488 (SCU_CONTEXT_COMMAND_REQUEST_TYPE_POST_TC |
489 (scic_sds_controller_get_protocol_engine_group(
490 controller) <<
491 SCU_CONTEXT_COMMAND_PROTOCOL_ENGINE_GROUP_SHIFT) |
492 (scic_sds_port_get_index(target_port) <<
493 SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT) |
494 scic_sds_io_tag_get_index(sds_request->io_tag));
495 } else {
496 /*
497 * Build the task context now since we have already read
498 * the data
499 *
500 * I/O tag index is not assigned because we have to wait
501 * until we get a TCi
502 */
503 sds_request->post_context =
504 (SCU_CONTEXT_COMMAND_REQUEST_TYPE_POST_TC |
505 (scic_sds_controller_get_protocol_engine_group(
506 owning_controller) <<
507 SCU_CONTEXT_COMMAND_PROTOCOL_ENGINE_GROUP_SHIFT) |
508 (scic_sds_port_get_index(target_port) <<
509 SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT));
510 }
511
512 /*
513 * Copy the physical address for the command buffer to the
514 * SCU Task Context
515 */
516 dma_addr = scic_io_request_get_dma_addr(sds_request,
517 sds_request->command_buffer);
518
519 task_context->command_iu_upper = upper_32_bits(dma_addr);
520 task_context->command_iu_lower = lower_32_bits(dma_addr);
521
522 /*
523 * Copy the physical address for the response buffer to the
524 * SCU Task Context
525 */
526 dma_addr = scic_io_request_get_dma_addr(sds_request,
527 sds_request->response_buffer);
528
529 task_context->response_iu_upper = upper_32_bits(dma_addr);
530 task_context->response_iu_lower = lower_32_bits(dma_addr);
531 }
532
533 /**
534 * This method is will fill in the SCU Task Context for a SSP IO request.
535 * @this_request:
536 *
537 */
538 static void scu_ssp_io_request_construct_task_context(
539 struct scic_sds_request *sci_req,
540 enum dma_data_direction dir,
541 u32 len)
542 {
543 struct scu_task_context *task_context;
544
545 task_context = scic_sds_request_get_task_context(sci_req);
546
547 scu_ssp_reqeust_construct_task_context(sci_req, task_context);
548
549 task_context->ssp_command_iu_length = sizeof(struct sci_ssp_command_iu) / sizeof(u32);
550 task_context->type.ssp.frame_type = SCI_SAS_COMMAND_FRAME;
551
552 switch (dir) {
553 case DMA_FROM_DEVICE:
554 case DMA_NONE:
555 default:
556 task_context->task_type = SCU_TASK_TYPE_IOREAD;
557 break;
558 case DMA_TO_DEVICE:
559 task_context->task_type = SCU_TASK_TYPE_IOWRITE;
560 break;
561 }
562
563 task_context->transfer_length_bytes = len;
564
565 if (task_context->transfer_length_bytes > 0)
566 scic_sds_request_build_sgl(sci_req);
567 }
568
569
570 /**
571 * This method will fill in the remainder of the io request object for SSP Task
572 * requests.
573 * @this_request:
574 *
575 */
576 static void scic_sds_ssp_task_request_assign_buffers(
577 struct scic_sds_request *this_request)
578 {
579 /* Assign all of the buffer pointers */
580 this_request->command_buffer =
581 scic_sds_ssp_task_request_get_command_buffer(this_request);
582 this_request->response_buffer =
583 scic_sds_ssp_task_request_get_response_buffer(this_request);
584 this_request->sgl_element_pair_buffer = NULL;
585
586 if (this_request->was_tag_assigned_by_user == false) {
587 this_request->task_context_buffer =
588 scic_sds_ssp_task_request_get_task_context_buffer(this_request);
589 this_request->task_context_buffer =
590 PTR_ALIGN(this_request->task_context_buffer, SMP_CACHE_BYTES);
591 }
592 }
593
594 /**
595 * This method will fill in the SCU Task Context for a SSP Task request. The
596 * following important settings are utilized: -# priority ==
597 * SCU_TASK_PRIORITY_HIGH. This ensures that the task request is issued
598 * ahead of other task destined for the same Remote Node. -# task_type ==
599 * SCU_TASK_TYPE_IOREAD. This simply indicates that a normal request type
600 * (i.e. non-raw frame) is being utilized to perform task management. -#
601 * control_frame == 1. This ensures that the proper endianess is set so
602 * that the bytes are transmitted in the right order for a task frame.
603 * @this_request: This parameter specifies the task request object being
604 * constructed.
605 *
606 */
607 static void scu_ssp_task_request_construct_task_context(
608 struct scic_sds_request *this_request)
609 {
610 struct scu_task_context *task_context;
611
612 task_context = scic_sds_request_get_task_context(this_request);
613
614 scu_ssp_reqeust_construct_task_context(this_request, task_context);
615
616 task_context->control_frame = 1;
617 task_context->priority = SCU_TASK_PRIORITY_HIGH;
618 task_context->task_type = SCU_TASK_TYPE_RAW_FRAME;
619 task_context->transfer_length_bytes = 0;
620 task_context->type.ssp.frame_type = SCI_SAS_TASK_FRAME;
621 task_context->ssp_command_iu_length = sizeof(struct sci_ssp_task_iu) / sizeof(u32);
622 }
623
624
625 /**
626 * This method constructs the SSP Command IU data for this ssp passthrough
627 * comand request object.
628 * @this_request: This parameter specifies the request object for which the SSP
629 * command information unit is being built.
630 *
631 * enum sci_status, returns invalid parameter is cdb > 16
632 */
633
634
635 /**
636 * This method constructs the SATA request object.
637 * @this_request:
638 * @sat_protocol:
639 * @transfer_length:
640 * @data_direction:
641 * @copy_rx_frame:
642 *
643 * enum sci_status
644 */
645 static enum sci_status scic_io_request_construct_sata(struct scic_sds_request *sci_req,
646 u8 proto, u32 len,
647 enum dma_data_direction dir,
648 bool copy)
649 {
650 enum sci_status status = SCI_SUCCESS;
651
652 switch (proto) {
653 case SAT_PROTOCOL_PIO_DATA_IN:
654 case SAT_PROTOCOL_PIO_DATA_OUT:
655 status = scic_sds_stp_pio_request_construct(sci_req, proto, copy);
656 break;
657
658 case SAT_PROTOCOL_UDMA_DATA_IN:
659 case SAT_PROTOCOL_UDMA_DATA_OUT:
660 status = scic_sds_stp_udma_request_construct(sci_req, len, dir);
661 break;
662
663 case SAT_PROTOCOL_ATA_HARD_RESET:
664 case SAT_PROTOCOL_SOFT_RESET:
665 status = scic_sds_stp_soft_reset_request_construct(sci_req);
666 break;
667
668 case SAT_PROTOCOL_NON_DATA:
669 status = scic_sds_stp_non_data_request_construct(sci_req);
670 break;
671
672 case SAT_PROTOCOL_FPDMA:
673 status = scic_sds_stp_ncq_request_construct(sci_req, len, dir);
674 break;
675
676 #if !defined(DISABLE_ATAPI)
677 case SAT_PROTOCOL_PACKET_NON_DATA:
678 case SAT_PROTOCOL_PACKET_DMA_DATA_IN:
679 case SAT_PROTOCOL_PACKET_DMA_DATA_OUT:
680 case SAT_PROTOCOL_PACKET_PIO_DATA_IN:
681 case SAT_PROTOCOL_PACKET_PIO_DATA_OUT:
682 status = scic_sds_stp_packet_request_construct(sci_req);
683 break;
684 #endif
685
686 case SAT_PROTOCOL_DMA_QUEUED:
687 case SAT_PROTOCOL_DMA:
688 case SAT_PROTOCOL_DEVICE_DIAGNOSTIC:
689 case SAT_PROTOCOL_DEVICE_RESET:
690 case SAT_PROTOCOL_RETURN_RESPONSE_INFO:
691 default:
692 dev_err(scic_to_dev(sci_req->owning_controller),
693 "%s: SCIC IO Request 0x%p received un-handled "
694 "SAT Protocl %d.\n",
695 __func__, sci_req, proto);
696
697 status = SCI_FAILURE;
698 break;
699 }
700
701 return status;
702 }
703
704 u32 scic_io_request_get_object_size(void)
705 {
706 u32 ssp_request_size;
707 u32 stp_request_size;
708 u32 smp_request_size;
709
710 ssp_request_size = scic_sds_ssp_request_get_object_size();
711 stp_request_size = scic_sds_stp_request_get_object_size();
712 smp_request_size = scic_sds_smp_request_get_object_size();
713
714 return max(ssp_request_size, max(stp_request_size, smp_request_size));
715 }
716
717 enum sci_status scic_io_request_construct_basic_ssp(
718 struct scic_sds_request *sci_req)
719 {
720 struct isci_request *isci_request =
721 (struct isci_request *)sci_object_get_association(sci_req);
722
723 sci_req->protocol = SCIC_SSP_PROTOCOL;
724
725 scu_ssp_io_request_construct_task_context(
726 sci_req,
727 isci_request_io_request_get_data_direction(isci_request),
728 isci_request_io_request_get_transfer_length(isci_request));
729
730 scic_sds_io_request_build_ssp_command_iu(sci_req);
731
732 sci_base_state_machine_change_state(
733 &sci_req->parent.state_machine,
734 SCI_BASE_REQUEST_STATE_CONSTRUCTED
735 );
736
737 return SCI_SUCCESS;
738 }
739
740
741 enum sci_status scic_task_request_construct_ssp(
742 struct scic_sds_request *sci_req)
743 {
744 /* Construct the SSP Task SCU Task Context */
745 scu_ssp_task_request_construct_task_context(sci_req);
746
747 /* Fill in the SSP Task IU */
748 scic_sds_task_request_build_ssp_task_iu(sci_req);
749
750 sci_base_state_machine_change_state(
751 &sci_req->parent.state_machine,
752 SCI_BASE_REQUEST_STATE_CONSTRUCTED
753 );
754
755 return SCI_SUCCESS;
756 }
757
758
759 enum sci_status scic_io_request_construct_basic_sata(
760 struct scic_sds_request *sci_req)
761 {
762 enum sci_status status;
763 struct scic_sds_stp_request *stp_req;
764 u8 proto;
765 u32 len;
766 enum dma_data_direction dir;
767 bool copy = false;
768 struct isci_request *isci_request =
769 (struct isci_request *)sci_object_get_association(sci_req);
770 struct sas_task *task = isci_request_access_task(isci_request);
771
772 stp_req = container_of(sci_req, typeof(*stp_req), parent);
773
774 sci_req->protocol = SCIC_STP_PROTOCOL;
775
776 len = isci_request_io_request_get_transfer_length(isci_request);
777 dir = isci_request_io_request_get_data_direction(isci_request);
778 proto = isci_sata_get_sat_protocol(isci_request);
779 copy = (task->data_dir == DMA_NONE) ? false : true;
780
781 status = scic_io_request_construct_sata(sci_req, proto, len, dir, copy);
782
783 if (status == SCI_SUCCESS)
784 sci_base_state_machine_change_state(
785 &sci_req->parent.state_machine,
786 SCI_BASE_REQUEST_STATE_CONSTRUCTED
787 );
788
789 return status;
790 }
791
792
793 enum sci_status scic_task_request_construct_sata(
794 struct scic_sds_request *sci_req)
795 {
796 enum sci_status status;
797 u8 sat_protocol;
798 struct isci_request *isci_request =
799 (struct isci_request *)sci_object_get_association(sci_req);
800
801 sat_protocol = isci_sata_get_sat_protocol(isci_request);
802
803 switch (sat_protocol) {
804 case SAT_PROTOCOL_ATA_HARD_RESET:
805 case SAT_PROTOCOL_SOFT_RESET:
806 status = scic_sds_stp_soft_reset_request_construct(sci_req);
807 break;
808
809 default:
810 dev_err(scic_to_dev(sci_req->owning_controller),
811 "%s: SCIC IO Request 0x%p received un-handled SAT "
812 "Protocl %d.\n",
813 __func__,
814 sci_req,
815 sat_protocol);
816
817 status = SCI_FAILURE;
818 break;
819 }
820
821 if (status == SCI_SUCCESS)
822 sci_base_state_machine_change_state(
823 &sci_req->parent.state_machine,
824 SCI_BASE_REQUEST_STATE_CONSTRUCTED
825 );
826
827 return status;
828 }
829
830
831 u16 scic_io_request_get_io_tag(
832 struct scic_sds_request *sci_req)
833 {
834 return sci_req->io_tag;
835 }
836
837
838 u32 scic_request_get_controller_status(
839 struct scic_sds_request *sci_req)
840 {
841 return sci_req->scu_status;
842 }
843
844
845 void *scic_io_request_get_command_iu_address(
846 struct scic_sds_request *sci_req)
847 {
848 return sci_req->command_buffer;
849 }
850
851
852 void *scic_io_request_get_response_iu_address(
853 struct scic_sds_request *sci_req)
854 {
855 return sci_req->response_buffer;
856 }
857
858
859 #define SCU_TASK_CONTEXT_SRAM 0x200000
860 u32 scic_io_request_get_number_of_bytes_transferred(
861 struct scic_sds_request *scic_sds_request)
862 {
863 u32 ret_val = 0;
864
865 if (SMU_AMR_READ(scic_sds_request->owning_controller) == 0) {
866 /*
867 * get the bytes of data from the Address == BAR1 + 20002Ch + (256*TCi) where
868 * BAR1 is the scu_registers
869 * 0x20002C = 0x200000 + 0x2c
870 * = start of task context SRAM + offset of (type.ssp.data_offset)
871 * TCi is the io_tag of struct scic_sds_request */
872 ret_val = scic_sds_pci_read_scu_dword(
873 scic_sds_request->owning_controller,
874 (
875 (u8 *)scic_sds_request->owning_controller->scu_registers +
876 (SCU_TASK_CONTEXT_SRAM + SCI_FIELD_OFFSET(struct scu_task_context, type.ssp.data_offset)) +
877 ((sizeof(struct scu_task_context)) * scic_sds_io_tag_get_index(scic_sds_request->io_tag))
878 )
879 );
880 }
881
882 return ret_val;
883 }
884
885
886 /*
887 * ****************************************************************************
888 * * SCIC SDS Interface Implementation
889 * **************************************************************************** */
890
891 /**
892 *
893 * @this_request: The SCIC_SDS_IO_REQUEST_T object for which the start
894 * operation is to be executed.
895 *
896 * This method invokes the base state start request handler for the
897 * SCIC_SDS_IO_REQUEST_T object. enum sci_status
898 */
899 enum sci_status scic_sds_request_start(
900 struct scic_sds_request *this_request)
901 {
902 if (
903 this_request->device_sequence
904 == scic_sds_remote_device_get_sequence(this_request->target_device)
905 ) {
906 return this_request->state_handlers->parent.start_handler(
907 &this_request->parent
908 );
909 }
910
911 return SCI_FAILURE;
912 }
913
914 /**
915 *
916 * @this_request: The SCIC_SDS_IO_REQUEST_T object for which the start
917 * operation is to be executed.
918 *
919 * This method invokes the base state terminate request handber for the
920 * SCIC_SDS_IO_REQUEST_T object. enum sci_status
921 */
922 enum sci_status scic_sds_io_request_terminate(
923 struct scic_sds_request *this_request)
924 {
925 return this_request->state_handlers->parent.abort_handler(
926 &this_request->parent);
927 }
928
929 /**
930 *
931 * @this_request: The SCIC_SDS_IO_REQUEST_T object for which the start
932 * operation is to be executed.
933 *
934 * This method invokes the base state request completion handler for the
935 * SCIC_SDS_IO_REQUEST_T object. enum sci_status
936 */
937 enum sci_status scic_sds_io_request_complete(
938 struct scic_sds_request *this_request)
939 {
940 return this_request->state_handlers->parent.complete_handler(
941 &this_request->parent);
942 }
943
944 /**
945 *
946 * @this_request: The SCIC_SDS_IO_REQUEST_T object for which the start
947 * operation is to be executed.
948 * @event_code: The event code returned by the hardware for the task reqeust.
949 *
950 * This method invokes the core state handler for the SCIC_SDS_IO_REQUEST_T
951 * object. enum sci_status
952 */
953 enum sci_status scic_sds_io_request_event_handler(
954 struct scic_sds_request *this_request,
955 u32 event_code)
956 {
957 return this_request->state_handlers->event_handler(this_request, event_code);
958 }
959
960 /**
961 *
962 * @this_request: The SCIC_SDS_IO_REQUEST_T object for which the start
963 * operation is to be executed.
964 * @frame_index: The frame index returned by the hardware for the reqeust
965 * object.
966 *
967 * This method invokes the core state frame handler for the
968 * SCIC_SDS_IO_REQUEST_T object. enum sci_status
969 */
970 enum sci_status scic_sds_io_request_frame_handler(
971 struct scic_sds_request *this_request,
972 u32 frame_index)
973 {
974 return this_request->state_handlers->frame_handler(this_request, frame_index);
975 }
976
977 /**
978 *
979 * @this_request: The SCIC_SDS_IO_REQUEST_T object for which the task start
980 * operation is to be executed.
981 *
982 * This method invokes the core state task complete handler for the
983 * SCIC_SDS_IO_REQUEST_T object. enum sci_status
984 */
985
986 /*
987 * ****************************************************************************
988 * * SCIC SDS PROTECTED METHODS
989 * **************************************************************************** */
990
991 /**
992 * This method copies response data for requests returning response data
993 * instead of sense data.
994 * @this_request: This parameter specifies the request object for which to copy
995 * the response data.
996 *
997 */
998 void scic_sds_io_request_copy_response(struct scic_sds_request *sds_request)
999 {
1000 void *response_buffer;
1001 u32 user_response_length;
1002 u32 core_response_length;
1003 struct sci_ssp_response_iu *ssp_response;
1004 struct isci_request *isci_request =
1005 (struct isci_request *)sci_object_get_association(sds_request);
1006
1007 ssp_response =
1008 (struct sci_ssp_response_iu *)sds_request->response_buffer;
1009
1010 response_buffer =
1011 isci_task_ssp_request_get_response_data_address(
1012 isci_request);
1013
1014 user_response_length =
1015 isci_task_ssp_request_get_response_data_length(
1016 isci_request);
1017
1018 core_response_length = sci_ssp_get_response_data_length(
1019 ssp_response->response_data_length);
1020
1021 user_response_length = min(user_response_length, core_response_length);
1022
1023 memcpy(response_buffer, ssp_response->data, user_response_length);
1024 }
1025
1026 /*
1027 * *****************************************************************************
1028 * * DEFAULT STATE HANDLERS
1029 * ***************************************************************************** */
1030
1031 /**
1032 * scic_sds_request_default_start_handler() -
1033 * @request: This is the struct sci_base_request object that is cast to the
1034 * SCIC_SDS_IO_REQUEST_T object for which the start operation is requested.
1035 *
1036 * This method is the default action to take when an SCIC_SDS_IO_REQUEST_T
1037 * object receives a scic_sds_request_start() request. The default action is
1038 * to log a warning and return a failure status. enum sci_status
1039 * SCI_FAILURE_INVALID_STATE
1040 */
1041 enum sci_status scic_sds_request_default_start_handler(
1042 struct sci_base_request *request)
1043 {
1044 struct scic_sds_request *scic_request =
1045 (struct scic_sds_request *)request;
1046
1047 dev_warn(scic_to_dev(scic_request->owning_controller),
1048 "%s: SCIC IO Request requested to start while in wrong "
1049 "state %d\n",
1050 __func__,
1051 sci_base_state_machine_get_state(
1052 &((struct scic_sds_request *)request)->parent.state_machine));
1053
1054 return SCI_FAILURE_INVALID_STATE;
1055 }
1056
1057 static enum sci_status scic_sds_request_default_abort_handler(
1058 struct sci_base_request *request)
1059 {
1060 struct scic_sds_request *scic_request =
1061 (struct scic_sds_request *)request;
1062
1063 dev_warn(scic_to_dev(scic_request->owning_controller),
1064 "%s: SCIC IO Request requested to abort while in wrong "
1065 "state %d\n",
1066 __func__,
1067 sci_base_state_machine_get_state(
1068 &((struct scic_sds_request *)request)->parent.state_machine));
1069
1070 return SCI_FAILURE_INVALID_STATE;
1071 }
1072
1073 /**
1074 * scic_sds_request_default_complete_handler() -
1075 * @request: This is the struct sci_base_request object that is cast to the
1076 * SCIC_SDS_IO_REQUEST_T object for which the start operation is requested.
1077 *
1078 * This method is the default action to take when an SCIC_SDS_IO_REQUEST_T
1079 * object receives a scic_sds_request_complete() request. The default action
1080 * is to log a warning and return a failure status. enum sci_status
1081 * SCI_FAILURE_INVALID_STATE
1082 */
1083 enum sci_status scic_sds_request_default_complete_handler(
1084 struct sci_base_request *request)
1085 {
1086 struct scic_sds_request *scic_request =
1087 (struct scic_sds_request *)request;
1088
1089 dev_warn(scic_to_dev(scic_request->owning_controller),
1090 "%s: SCIC IO Request requested to complete while in wrong "
1091 "state %d\n",
1092 __func__,
1093 sci_base_state_machine_get_state(
1094 &((struct scic_sds_request *)request)->parent.state_machine));
1095
1096 return SCI_FAILURE_INVALID_STATE;
1097 }
1098
1099 /**
1100 * scic_sds_request_default_destruct_handler() -
1101 * @request: This is the struct sci_base_request object that is cast to the
1102 * SCIC_SDS_IO_REQUEST_T object for which the start operation is requested.
1103 *
1104 * This method is the default action to take when an SCIC_SDS_IO_REQUEST_T
1105 * object receives a scic_sds_request_complete() request. The default action
1106 * is to log a warning and return a failure status. enum sci_status
1107 * SCI_FAILURE_INVALID_STATE
1108 */
1109 enum sci_status scic_sds_request_default_destruct_handler(
1110 struct sci_base_request *request)
1111 {
1112 struct scic_sds_request *scic_request =
1113 (struct scic_sds_request *)request;
1114
1115 dev_warn(scic_to_dev(scic_request->owning_controller),
1116 "%s: SCIC IO Request requested to destroy while in wrong "
1117 "state %d\n",
1118 __func__,
1119 sci_base_state_machine_get_state(
1120 &((struct scic_sds_request *)request)->parent.state_machine));
1121
1122 return SCI_FAILURE_INVALID_STATE;
1123 }
1124
1125 /**
1126 * scic_sds_request_default_tc_completion_handler() -
1127 * @request: This is the struct sci_base_request object that is cast to the
1128 * SCIC_SDS_IO_REQUEST_T object for which the start operation is requested.
1129 *
1130 * This method is the default action to take when an SCIC_SDS_IO_REQUEST_T
1131 * object receives a scic_sds_task_request_complete() request. The default
1132 * action is to log a warning and return a failure status. enum sci_status
1133 * SCI_FAILURE_INVALID_STATE
1134 */
1135 enum sci_status scic_sds_request_default_tc_completion_handler(
1136 struct scic_sds_request *this_request,
1137 u32 completion_code)
1138 {
1139 dev_warn(scic_to_dev(this_request->owning_controller),
1140 "%s: SCIC IO Request given task completion notification %x "
1141 "while in wrong state %d\n",
1142 __func__,
1143 completion_code,
1144 sci_base_state_machine_get_state(
1145 &this_request->parent.state_machine));
1146
1147 return SCI_FAILURE_INVALID_STATE;
1148
1149 }
1150
1151 /**
1152 * scic_sds_request_default_event_handler() -
1153 * @request: This is the struct sci_base_request object that is cast to the
1154 * SCIC_SDS_IO_REQUEST_T object for which the start operation is requested.
1155 *
1156 * This method is the default action to take when an SCIC_SDS_IO_REQUEST_T
1157 * object receives a scic_sds_request_event_handler() request. The default
1158 * action is to log a warning and return a failure status. enum sci_status
1159 * SCI_FAILURE_INVALID_STATE
1160 */
1161 enum sci_status scic_sds_request_default_event_handler(
1162 struct scic_sds_request *this_request,
1163 u32 event_code)
1164 {
1165 dev_warn(scic_to_dev(this_request->owning_controller),
1166 "%s: SCIC IO Request given event code notification %x while "
1167 "in wrong state %d\n",
1168 __func__,
1169 event_code,
1170 sci_base_state_machine_get_state(
1171 &this_request->parent.state_machine));
1172
1173 return SCI_FAILURE_INVALID_STATE;
1174 }
1175
1176 /**
1177 * scic_sds_request_default_frame_handler() -
1178 * @request: This is the struct sci_base_request object that is cast to the
1179 * SCIC_SDS_IO_REQUEST_T object for which the start operation is requested.
1180 *
1181 * This method is the default action to take when an SCIC_SDS_IO_REQUEST_T
1182 * object receives a scic_sds_request_event_handler() request. The default
1183 * action is to log a warning and return a failure status. enum sci_status
1184 * SCI_FAILURE_INVALID_STATE
1185 */
1186 enum sci_status scic_sds_request_default_frame_handler(
1187 struct scic_sds_request *this_request,
1188 u32 frame_index)
1189 {
1190 dev_warn(scic_to_dev(this_request->owning_controller),
1191 "%s: SCIC IO Request given unexpected frame %x while in "
1192 "state %d\n",
1193 __func__,
1194 frame_index,
1195 sci_base_state_machine_get_state(
1196 &this_request->parent.state_machine));
1197
1198 scic_sds_controller_release_frame(
1199 this_request->owning_controller, frame_index);
1200
1201 return SCI_FAILURE_INVALID_STATE;
1202 }
1203
1204 /*
1205 * *****************************************************************************
1206 * * CONSTRUCTED STATE HANDLERS
1207 * ***************************************************************************** */
1208
1209 /**
1210 * scic_sds_request_constructed_state_start_handler() -
1211 * @request: This is the struct sci_base_request object that is cast to the
1212 * SCIC_SDS_IO_REQUEST_T object for which the start operation is requested.
1213 *
1214 * This method implements the action taken when a constructed
1215 * SCIC_SDS_IO_REQUEST_T object receives a scic_sds_request_start() request.
1216 * This method will, if necessary, allocate a TCi for the io request object and
1217 * then will, if necessary, copy the constructed TC data into the actual TC
1218 * buffer. If everything is successful the post context field is updated with
1219 * the TCi so the controller can post the request to the hardware. enum sci_status
1220 * SCI_SUCCESS SCI_FAILURE_INSUFFICIENT_RESOURCES
1221 */
1222 static enum sci_status scic_sds_request_constructed_state_start_handler(
1223 struct sci_base_request *request)
1224 {
1225 struct scu_task_context *task_context;
1226 struct scic_sds_request *this_request = (struct scic_sds_request *)request;
1227
1228 if (this_request->io_tag == SCI_CONTROLLER_INVALID_IO_TAG) {
1229 this_request->io_tag =
1230 scic_controller_allocate_io_tag(this_request->owning_controller);
1231 }
1232
1233 /* Record the IO Tag in the request */
1234 if (this_request->io_tag != SCI_CONTROLLER_INVALID_IO_TAG) {
1235 task_context = this_request->task_context_buffer;
1236
1237 task_context->task_index = scic_sds_io_tag_get_index(this_request->io_tag);
1238
1239 switch (task_context->protocol_type) {
1240 case SCU_TASK_CONTEXT_PROTOCOL_SMP:
1241 case SCU_TASK_CONTEXT_PROTOCOL_SSP:
1242 /* SSP/SMP Frame */
1243 task_context->type.ssp.tag = this_request->io_tag;
1244 task_context->type.ssp.target_port_transfer_tag = 0xFFFF;
1245 break;
1246
1247 case SCU_TASK_CONTEXT_PROTOCOL_STP:
1248 /*
1249 * STP/SATA Frame
1250 * task_context->type.stp.ncq_tag = this_request->ncq_tag; */
1251 break;
1252
1253 case SCU_TASK_CONTEXT_PROTOCOL_NONE:
1254 /* / @todo When do we set no protocol type? */
1255 break;
1256
1257 default:
1258 /* This should never happen since we build the IO requests */
1259 break;
1260 }
1261
1262 /*
1263 * Check to see if we need to copy the task context buffer
1264 * or have been building into the task context buffer */
1265 if (this_request->was_tag_assigned_by_user == false) {
1266 scic_sds_controller_copy_task_context(
1267 this_request->owning_controller, this_request
1268 );
1269 }
1270
1271 /* Add to the post_context the io tag value */
1272 this_request->post_context |= scic_sds_io_tag_get_index(this_request->io_tag);
1273
1274 /* Everything is good go ahead and change state */
1275 sci_base_state_machine_change_state(
1276 &this_request->parent.state_machine,
1277 SCI_BASE_REQUEST_STATE_STARTED
1278 );
1279
1280 return SCI_SUCCESS;
1281 }
1282
1283 return SCI_FAILURE_INSUFFICIENT_RESOURCES;
1284 }
1285
1286 /**
1287 * scic_sds_request_constructed_state_abort_handler() -
1288 * @request: This is the struct sci_base_request object that is cast to the
1289 * SCIC_SDS_IO_REQUEST_T object for which the start operation is requested.
1290 *
1291 * This method implements the action to be taken when an SCIC_SDS_IO_REQUEST_T
1292 * object receives a scic_sds_request_terminate() request. Since the request
1293 * has not yet been posted to the hardware the request transitions to the
1294 * completed state. enum sci_status SCI_SUCCESS
1295 */
1296 static enum sci_status scic_sds_request_constructed_state_abort_handler(
1297 struct sci_base_request *request)
1298 {
1299 struct scic_sds_request *this_request = (struct scic_sds_request *)request;
1300
1301 /*
1302 * This request has been terminated by the user make sure that the correct
1303 * status code is returned */
1304 scic_sds_request_set_status(
1305 this_request,
1306 SCU_TASK_DONE_TASK_ABORT,
1307 SCI_FAILURE_IO_TERMINATED
1308 );
1309
1310 sci_base_state_machine_change_state(
1311 &this_request->parent.state_machine,
1312 SCI_BASE_REQUEST_STATE_COMPLETED
1313 );
1314
1315 return SCI_SUCCESS;
1316 }
1317
1318 /*
1319 * *****************************************************************************
1320 * * STARTED STATE HANDLERS
1321 * ***************************************************************************** */
1322
1323 /**
1324 * scic_sds_request_started_state_abort_handler() -
1325 * @request: This is the struct sci_base_request object that is cast to the
1326 * SCIC_SDS_IO_REQUEST_T object for which the start operation is requested.
1327 *
1328 * This method implements the action to be taken when an SCIC_SDS_IO_REQUEST_T
1329 * object receives a scic_sds_request_terminate() request. Since the request
1330 * has been posted to the hardware the io request state is changed to the
1331 * aborting state. enum sci_status SCI_SUCCESS
1332 */
1333 enum sci_status scic_sds_request_started_state_abort_handler(
1334 struct sci_base_request *request)
1335 {
1336 struct scic_sds_request *this_request = (struct scic_sds_request *)request;
1337
1338 if (this_request->has_started_substate_machine) {
1339 sci_base_state_machine_stop(&this_request->started_substate_machine);
1340 }
1341
1342 sci_base_state_machine_change_state(
1343 &this_request->parent.state_machine,
1344 SCI_BASE_REQUEST_STATE_ABORTING
1345 );
1346
1347 return SCI_SUCCESS;
1348 }
1349
1350 /**
1351 * scic_sds_request_started_state_tc_completion_handler() - This method process
1352 * TC (task context) completions for normal IO request (i.e. Task/Abort
1353 * Completions of type 0). This method will update the
1354 * SCIC_SDS_IO_REQUEST_T::status field.
1355 * @this_request: This parameter specifies the request for which a completion
1356 * occurred.
1357 * @completion_code: This parameter specifies the completion code received from
1358 * the SCU.
1359 *
1360 */
1361 enum sci_status scic_sds_request_started_state_tc_completion_handler(
1362 struct scic_sds_request *this_request,
1363 u32 completion_code)
1364 {
1365 u8 data_present;
1366 struct sci_ssp_response_iu *response_buffer;
1367
1368 /**
1369 * @todo Any SDMA return code of other than 0 is bad
1370 * decode 0x003C0000 to determine SDMA status
1371 */
1372 switch (SCU_GET_COMPLETION_TL_STATUS(completion_code)) {
1373 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_GOOD):
1374 scic_sds_request_set_status(
1375 this_request, SCU_TASK_DONE_GOOD, SCI_SUCCESS
1376 );
1377 break;
1378
1379 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_EARLY_RESP):
1380 {
1381 /*
1382 * There are times when the SCU hardware will return an early response
1383 * because the io request specified more data than is returned by the
1384 * target device (mode pages, inquiry data, etc.). We must check the
1385 * response stats to see if this is truly a failed request or a good
1386 * request that just got completed early. */
1387 struct sci_ssp_response_iu *response = (struct sci_ssp_response_iu *)
1388 this_request->response_buffer;
1389 scic_word_copy_with_swap(
1390 this_request->response_buffer,
1391 this_request->response_buffer,
1392 sizeof(struct sci_ssp_response_iu) / sizeof(u32)
1393 );
1394
1395 if (response->status == 0) {
1396 scic_sds_request_set_status(
1397 this_request, SCU_TASK_DONE_GOOD, SCI_SUCCESS_IO_DONE_EARLY
1398 );
1399 } else {
1400 scic_sds_request_set_status(
1401 this_request,
1402 SCU_TASK_DONE_CHECK_RESPONSE,
1403 SCI_FAILURE_IO_RESPONSE_VALID
1404 );
1405 }
1406 }
1407 break;
1408
1409 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_CHECK_RESPONSE):
1410 scic_word_copy_with_swap(
1411 this_request->response_buffer,
1412 this_request->response_buffer,
1413 sizeof(struct sci_ssp_response_iu) / sizeof(u32)
1414 );
1415
1416 scic_sds_request_set_status(
1417 this_request,
1418 SCU_TASK_DONE_CHECK_RESPONSE,
1419 SCI_FAILURE_IO_RESPONSE_VALID
1420 );
1421 break;
1422
1423 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_RESP_LEN_ERR):
1424 /*
1425 * / @todo With TASK_DONE_RESP_LEN_ERR is the response frame guaranteed
1426 * / to be received before this completion status is posted? */
1427 response_buffer =
1428 (struct sci_ssp_response_iu *)this_request->response_buffer;
1429 data_present =
1430 response_buffer->data_present & SCI_SSP_RESPONSE_IU_DATA_PRESENT_MASK;
1431
1432 if ((data_present == 0x01) || (data_present == 0x02)) {
1433 scic_sds_request_set_status(
1434 this_request,
1435 SCU_TASK_DONE_CHECK_RESPONSE,
1436 SCI_FAILURE_IO_RESPONSE_VALID
1437 );
1438 } else {
1439 scic_sds_request_set_status(
1440 this_request, SCU_TASK_DONE_GOOD, SCI_SUCCESS
1441 );
1442 }
1443 break;
1444
1445 /* only stp device gets suspended. */
1446 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_ACK_NAK_TO):
1447 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_LL_PERR):
1448 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_NAK_ERR):
1449 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_DATA_LEN_ERR):
1450 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_LL_ABORT_ERR):
1451 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_XR_WD_LEN):
1452 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_MAX_PLD_ERR):
1453 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_UNEXP_RESP):
1454 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_UNEXP_SDBFIS):
1455 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_REG_ERR):
1456 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_SDB_ERR):
1457 if (this_request->protocol == SCIC_STP_PROTOCOL) {
1458 scic_sds_request_set_status(
1459 this_request,
1460 SCU_GET_COMPLETION_TL_STATUS(completion_code) >> SCU_COMPLETION_TL_STATUS_SHIFT,
1461 SCI_FAILURE_REMOTE_DEVICE_RESET_REQUIRED
1462 );
1463 } else {
1464 scic_sds_request_set_status(
1465 this_request,
1466 SCU_GET_COMPLETION_TL_STATUS(completion_code) >> SCU_COMPLETION_TL_STATUS_SHIFT,
1467 SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR
1468 );
1469 }
1470 break;
1471
1472 /* both stp/ssp device gets suspended */
1473 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_LF_ERR):
1474 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_OPEN_REJECT_WRONG_DESTINATION):
1475 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_OPEN_REJECT_RESERVED_ABANDON_1):
1476 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_OPEN_REJECT_RESERVED_ABANDON_2):
1477 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_OPEN_REJECT_RESERVED_ABANDON_3):
1478 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_OPEN_REJECT_BAD_DESTINATION):
1479 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_OPEN_REJECT_ZONE_VIOLATION):
1480 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_OPEN_REJECT_STP_RESOURCES_BUSY):
1481 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_OPEN_REJECT_PROTOCOL_NOT_SUPPORTED):
1482 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_OPEN_REJECT_CONNECTION_RATE_NOT_SUPPORTED):
1483 scic_sds_request_set_status(
1484 this_request,
1485 SCU_GET_COMPLETION_TL_STATUS(completion_code) >> SCU_COMPLETION_TL_STATUS_SHIFT,
1486 SCI_FAILURE_REMOTE_DEVICE_RESET_REQUIRED
1487 );
1488 break;
1489
1490 /* neither ssp nor stp gets suspended. */
1491 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_NAK_CMD_ERR):
1492 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_UNEXP_XR):
1493 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_XR_IU_LEN_ERR):
1494 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_SDMA_ERR):
1495 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_OFFSET_ERR):
1496 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_EXCESS_DATA):
1497 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_SMP_RESP_TO_ERR):
1498 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_SMP_UFI_ERR):
1499 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_SMP_FRM_TYPE_ERR):
1500 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_SMP_LL_RX_ERR):
1501 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_UNEXP_DATA):
1502 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_OPEN_FAIL):
1503 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_VIIT_ENTRY_NV):
1504 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_IIT_ENTRY_NV):
1505 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_RNCNV_OUTBOUND):
1506 default:
1507 scic_sds_request_set_status(
1508 this_request,
1509 SCU_GET_COMPLETION_TL_STATUS(completion_code) >> SCU_COMPLETION_TL_STATUS_SHIFT,
1510 SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR
1511 );
1512 break;
1513 }
1514
1515 /**
1516 * @todo This is probably wrong for ACK/NAK timeout conditions
1517 */
1518
1519 /* In all cases we will treat this as the completion of the IO request. */
1520 sci_base_state_machine_change_state(
1521 &this_request->parent.state_machine,
1522 SCI_BASE_REQUEST_STATE_COMPLETED
1523 );
1524
1525 return SCI_SUCCESS;
1526 }
1527
1528 /**
1529 * scic_sds_request_started_state_frame_handler() -
1530 * @request: This is the struct sci_base_request object that is cast to the
1531 * SCIC_SDS_IO_REQUEST_T object for which the start operation is requested.
1532 * @frame_index: This is the index of the unsolicited frame to be processed.
1533 *
1534 * This method implements the action to be taken when an SCIC_SDS_IO_REQUEST_T
1535 * object receives a scic_sds_request_frame_handler() request. This method
1536 * first determines the frame type received. If this is a response frame then
1537 * the response data is copied to the io request response buffer for processing
1538 * at completion time. If the frame type is not a response buffer an error is
1539 * logged. enum sci_status SCI_SUCCESS SCI_FAILURE_INVALID_PARAMETER_VALUE
1540 */
1541 static enum sci_status scic_sds_request_started_state_frame_handler(
1542 struct scic_sds_request *this_request,
1543 u32 frame_index)
1544 {
1545 enum sci_status status;
1546 struct sci_ssp_frame_header *frame_header;
1547
1548 /* / @todo If this is a response frame we must record that we received it */
1549 status = scic_sds_unsolicited_frame_control_get_header(
1550 &(scic_sds_request_get_controller(this_request)->uf_control),
1551 frame_index,
1552 (void **)&frame_header
1553 );
1554
1555 if (frame_header->frame_type == SCI_SAS_RESPONSE_FRAME) {
1556 struct sci_ssp_response_iu *response_buffer;
1557
1558 status = scic_sds_unsolicited_frame_control_get_buffer(
1559 &(scic_sds_request_get_controller(this_request)->uf_control),
1560 frame_index,
1561 (void **)&response_buffer
1562 );
1563
1564 scic_word_copy_with_swap(
1565 this_request->response_buffer,
1566 (u32 *)response_buffer,
1567 sizeof(struct sci_ssp_response_iu)
1568 );
1569
1570 response_buffer = (struct sci_ssp_response_iu *)this_request->response_buffer;
1571
1572 if ((response_buffer->data_present == 0x01) ||
1573 (response_buffer->data_present == 0x02)) {
1574 scic_sds_request_set_status(
1575 this_request,
1576 SCU_TASK_DONE_CHECK_RESPONSE,
1577 SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR
1578 );
1579 } else
1580 scic_sds_request_set_status(
1581 this_request, SCU_TASK_DONE_GOOD, SCI_SUCCESS
1582 );
1583 } else
1584 /* This was not a response frame why did it get forwarded? */
1585 dev_err(scic_to_dev(this_request->owning_controller),
1586 "%s: SCIC IO Request 0x%p received unexpected "
1587 "frame %d type 0x%02x\n",
1588 __func__,
1589 this_request,
1590 frame_index,
1591 frame_header->frame_type);
1592
1593 /*
1594 * In any case we are done with this frame buffer return it to the
1595 * controller */
1596 scic_sds_controller_release_frame(
1597 this_request->owning_controller, frame_index
1598 );
1599
1600 return SCI_SUCCESS;
1601 }
1602
1603 /*
1604 * *****************************************************************************
1605 * * COMPLETED STATE HANDLERS
1606 * ***************************************************************************** */
1607
1608
1609 /**
1610 * scic_sds_request_completed_state_complete_handler() -
1611 * @request: This is the struct sci_base_request object that is cast to the
1612 * SCIC_SDS_IO_REQUEST_T object for which the start operation is requested.
1613 *
1614 * This method implements the action to be taken when an SCIC_SDS_IO_REQUEST_T
1615 * object receives a scic_sds_request_complete() request. This method frees up
1616 * any io request resources that have been allocated and transitions the
1617 * request to its final state. Consider stopping the state machine instead of
1618 * transitioning to the final state? enum sci_status SCI_SUCCESS
1619 */
1620 static enum sci_status scic_sds_request_completed_state_complete_handler(
1621 struct sci_base_request *request)
1622 {
1623 struct scic_sds_request *this_request = (struct scic_sds_request *)request;
1624
1625 if (this_request->was_tag_assigned_by_user != true) {
1626 scic_controller_free_io_tag(
1627 this_request->owning_controller, this_request->io_tag
1628 );
1629 }
1630
1631 if (this_request->saved_rx_frame_index != SCU_INVALID_FRAME_INDEX) {
1632 scic_sds_controller_release_frame(
1633 this_request->owning_controller, this_request->saved_rx_frame_index);
1634 }
1635
1636 sci_base_state_machine_change_state(
1637 &this_request->parent.state_machine,
1638 SCI_BASE_REQUEST_STATE_FINAL
1639 );
1640
1641 return SCI_SUCCESS;
1642 }
1643
1644 /*
1645 * *****************************************************************************
1646 * * ABORTING STATE HANDLERS
1647 * ***************************************************************************** */
1648
1649 /**
1650 * scic_sds_request_aborting_state_abort_handler() -
1651 * @request: This is the struct sci_base_request object that is cast to the
1652 * SCIC_SDS_IO_REQUEST_T object for which the start operation is requested.
1653 *
1654 * This method implements the action to be taken when an SCIC_SDS_IO_REQUEST_T
1655 * object receives a scic_sds_request_terminate() request. This method is the
1656 * io request aborting state abort handlers. On receipt of a multiple
1657 * terminate requests the io request will transition to the completed state.
1658 * This should not happen in normal operation. enum sci_status SCI_SUCCESS
1659 */
1660 static enum sci_status scic_sds_request_aborting_state_abort_handler(
1661 struct sci_base_request *request)
1662 {
1663 struct scic_sds_request *this_request = (struct scic_sds_request *)request;
1664
1665 sci_base_state_machine_change_state(
1666 &this_request->parent.state_machine,
1667 SCI_BASE_REQUEST_STATE_COMPLETED
1668 );
1669
1670 return SCI_SUCCESS;
1671 }
1672
1673 /**
1674 * scic_sds_request_aborting_state_tc_completion_handler() -
1675 * @request: This is the struct sci_base_request object that is cast to the
1676 * SCIC_SDS_IO_REQUEST_T object for which the start operation is requested.
1677 *
1678 * This method implements the action to be taken when an SCIC_SDS_IO_REQUEST_T
1679 * object receives a scic_sds_request_task_completion() request. This method
1680 * decodes the completion type waiting for the abort task complete
1681 * notification. When the abort task complete is received the io request
1682 * transitions to the completed state. enum sci_status SCI_SUCCESS
1683 */
1684 static enum sci_status scic_sds_request_aborting_state_tc_completion_handler(
1685 struct scic_sds_request *this_request,
1686 u32 completion_code)
1687 {
1688 switch (SCU_GET_COMPLETION_TL_STATUS(completion_code)) {
1689 case (SCU_TASK_DONE_GOOD << SCU_COMPLETION_TL_STATUS_SHIFT):
1690 case (SCU_TASK_DONE_TASK_ABORT << SCU_COMPLETION_TL_STATUS_SHIFT):
1691 scic_sds_request_set_status(
1692 this_request, SCU_TASK_DONE_TASK_ABORT, SCI_FAILURE_IO_TERMINATED
1693 );
1694
1695 sci_base_state_machine_change_state(
1696 &this_request->parent.state_machine,
1697 SCI_BASE_REQUEST_STATE_COMPLETED
1698 );
1699 break;
1700
1701 default:
1702 /*
1703 * Unless we get some strange error wait for the task abort to complete
1704 * TODO: Should there be a state change for this completion? */
1705 break;
1706 }
1707
1708 return SCI_SUCCESS;
1709 }
1710
1711 /**
1712 * scic_sds_request_aborting_state_frame_handler() -
1713 * @request: This is the struct sci_base_request object that is cast to the
1714 * SCIC_SDS_IO_REQUEST_T object for which the start operation is requested.
1715 *
1716 * This method implements the action to be taken when an SCIC_SDS_IO_REQUEST_T
1717 * object receives a scic_sds_request_frame_handler() request. This method
1718 * discards the unsolicited frame since we are waiting for the abort task
1719 * completion. enum sci_status SCI_SUCCESS
1720 */
1721 static enum sci_status scic_sds_request_aborting_state_frame_handler(
1722 struct scic_sds_request *this_request,
1723 u32 frame_index)
1724 {
1725 /* TODO: Is it even possible to get an unsolicited frame in the aborting state? */
1726
1727 scic_sds_controller_release_frame(
1728 this_request->owning_controller, frame_index);
1729
1730 return SCI_SUCCESS;
1731 }
1732
1733 static const struct scic_sds_io_request_state_handler scic_sds_request_state_handler_table[] = {
1734 [SCI_BASE_REQUEST_STATE_INITIAL] = {
1735 .parent.start_handler = scic_sds_request_default_start_handler,
1736 .parent.abort_handler = scic_sds_request_default_abort_handler,
1737 .parent.complete_handler = scic_sds_request_default_complete_handler,
1738 .parent.destruct_handler = scic_sds_request_default_destruct_handler,
1739 .tc_completion_handler = scic_sds_request_default_tc_completion_handler,
1740 .event_handler = scic_sds_request_default_event_handler,
1741 .frame_handler = scic_sds_request_default_frame_handler,
1742 },
1743 [SCI_BASE_REQUEST_STATE_CONSTRUCTED] = {
1744 .parent.start_handler = scic_sds_request_constructed_state_start_handler,
1745 .parent.abort_handler = scic_sds_request_constructed_state_abort_handler,
1746 .parent.complete_handler = scic_sds_request_default_complete_handler,
1747 .parent.destruct_handler = scic_sds_request_default_destruct_handler,
1748 .tc_completion_handler = scic_sds_request_default_tc_completion_handler,
1749 .event_handler = scic_sds_request_default_event_handler,
1750 .frame_handler = scic_sds_request_default_frame_handler,
1751 },
1752 [SCI_BASE_REQUEST_STATE_STARTED] = {
1753 .parent.start_handler = scic_sds_request_default_start_handler,
1754 .parent.abort_handler = scic_sds_request_started_state_abort_handler,
1755 .parent.complete_handler = scic_sds_request_default_complete_handler,
1756 .parent.destruct_handler = scic_sds_request_default_destruct_handler,
1757 .tc_completion_handler = scic_sds_request_started_state_tc_completion_handler,
1758 .event_handler = scic_sds_request_default_event_handler,
1759 .frame_handler = scic_sds_request_started_state_frame_handler,
1760 },
1761 [SCI_BASE_REQUEST_STATE_COMPLETED] = {
1762 .parent.start_handler = scic_sds_request_default_start_handler,
1763 .parent.abort_handler = scic_sds_request_default_abort_handler,
1764 .parent.complete_handler = scic_sds_request_completed_state_complete_handler,
1765 .parent.destruct_handler = scic_sds_request_default_destruct_handler,
1766 .tc_completion_handler = scic_sds_request_default_tc_completion_handler,
1767 .event_handler = scic_sds_request_default_event_handler,
1768 .frame_handler = scic_sds_request_default_frame_handler,
1769 },
1770 [SCI_BASE_REQUEST_STATE_ABORTING] = {
1771 .parent.start_handler = scic_sds_request_default_start_handler,
1772 .parent.abort_handler = scic_sds_request_aborting_state_abort_handler,
1773 .parent.complete_handler = scic_sds_request_default_complete_handler,
1774 .parent.destruct_handler = scic_sds_request_default_destruct_handler,
1775 .tc_completion_handler = scic_sds_request_aborting_state_tc_completion_handler,
1776 .event_handler = scic_sds_request_default_event_handler,
1777 .frame_handler = scic_sds_request_aborting_state_frame_handler,
1778 },
1779 [SCI_BASE_REQUEST_STATE_FINAL] = {
1780 .parent.start_handler = scic_sds_request_default_start_handler,
1781 .parent.abort_handler = scic_sds_request_default_abort_handler,
1782 .parent.complete_handler = scic_sds_request_default_complete_handler,
1783 .parent.destruct_handler = scic_sds_request_default_destruct_handler,
1784 .tc_completion_handler = scic_sds_request_default_tc_completion_handler,
1785 .event_handler = scic_sds_request_default_event_handler,
1786 .frame_handler = scic_sds_request_default_frame_handler,
1787 },
1788 };
1789
1790 /**
1791 * scic_sds_request_initial_state_enter() -
1792 * @object: This parameter specifies the base object for which the state
1793 * transition is occurring.
1794 *
1795 * This method implements the actions taken when entering the
1796 * SCI_BASE_REQUEST_STATE_INITIAL state. This state is entered when the initial
1797 * base request is constructed. Entry into the initial state sets all handlers
1798 * for the io request object to their default handlers. none
1799 */
1800 static void scic_sds_request_initial_state_enter(
1801 struct sci_base_object *object)
1802 {
1803 struct scic_sds_request *this_request = (struct scic_sds_request *)object;
1804
1805 SET_STATE_HANDLER(
1806 this_request,
1807 scic_sds_request_state_handler_table,
1808 SCI_BASE_REQUEST_STATE_INITIAL
1809 );
1810 }
1811
1812 /**
1813 * scic_sds_request_constructed_state_enter() -
1814 * @object: The io request object that is to enter the constructed state.
1815 *
1816 * This method implements the actions taken when entering the
1817 * SCI_BASE_REQUEST_STATE_CONSTRUCTED state. The method sets the state handlers
1818 * for the the constructed state. none
1819 */
1820 static void scic_sds_request_constructed_state_enter(
1821 struct sci_base_object *object)
1822 {
1823 struct scic_sds_request *this_request = (struct scic_sds_request *)object;
1824
1825 SET_STATE_HANDLER(
1826 this_request,
1827 scic_sds_request_state_handler_table,
1828 SCI_BASE_REQUEST_STATE_CONSTRUCTED
1829 );
1830 }
1831
1832 /**
1833 * scic_sds_request_started_state_enter() -
1834 * @object: This parameter specifies the base object for which the state
1835 * transition is occuring. This is cast into a SCIC_SDS_IO_REQUEST object.
1836 *
1837 * This method implements the actions taken when entering the
1838 * SCI_BASE_REQUEST_STATE_STARTED state. If the io request object type is a
1839 * SCSI Task request we must enter the started substate machine. none
1840 */
1841 static void scic_sds_request_started_state_enter(
1842 struct sci_base_object *object)
1843 {
1844 struct scic_sds_request *this_request = (struct scic_sds_request *)object;
1845
1846 SET_STATE_HANDLER(
1847 this_request,
1848 scic_sds_request_state_handler_table,
1849 SCI_BASE_REQUEST_STATE_STARTED
1850 );
1851
1852 /*
1853 * Most of the request state machines have a started substate machine so
1854 * start its execution on the entry to the started state. */
1855 if (this_request->has_started_substate_machine == true)
1856 sci_base_state_machine_start(&this_request->started_substate_machine);
1857 }
1858
1859 /**
1860 * scic_sds_request_started_state_exit() -
1861 * @object: This parameter specifies the base object for which the state
1862 * transition is occuring. This object is cast into a SCIC_SDS_IO_REQUEST
1863 * object.
1864 *
1865 * This method implements the actions taken when exiting the
1866 * SCI_BASE_REQUEST_STATE_STARTED state. For task requests the action will be
1867 * to stop the started substate machine. none
1868 */
1869 static void scic_sds_request_started_state_exit(
1870 struct sci_base_object *object)
1871 {
1872 struct scic_sds_request *this_request = (struct scic_sds_request *)object;
1873
1874 if (this_request->has_started_substate_machine == true)
1875 sci_base_state_machine_stop(&this_request->started_substate_machine);
1876 }
1877
1878 /**
1879 * scic_sds_request_completed_state_enter() -
1880 * @object: This parameter specifies the base object for which the state
1881 * transition is occuring. This object is cast into a SCIC_SDS_IO_REQUEST
1882 * object.
1883 *
1884 * This method implements the actions taken when entering the
1885 * SCI_BASE_REQUEST_STATE_COMPLETED state. This state is entered when the
1886 * SCIC_SDS_IO_REQUEST has completed. The method will decode the request
1887 * completion status and convert it to an enum sci_status to return in the
1888 * completion callback function. none
1889 */
1890 static void scic_sds_request_completed_state_enter(
1891 struct sci_base_object *object)
1892 {
1893 struct scic_sds_request *sci_req = (struct scic_sds_request *)object;
1894 struct scic_sds_controller *scic =
1895 scic_sds_request_get_controller(sci_req);
1896 struct isci_host *ihost = sci_object_get_association(scic);
1897 struct isci_request *ireq = sci_object_get_association(sci_req);
1898
1899
1900 SET_STATE_HANDLER(sci_req,
1901 scic_sds_request_state_handler_table,
1902 SCI_BASE_REQUEST_STATE_COMPLETED);
1903
1904 /* Tell the SCI_USER that the IO request is complete */
1905 if (sci_req->is_task_management_request == false)
1906 isci_request_io_request_complete(ihost,
1907 ireq,
1908 sci_req->sci_status);
1909 else
1910 isci_task_request_complete(ihost, ireq, sci_req->sci_status);
1911 }
1912
1913 /**
1914 * scic_sds_request_aborting_state_enter() -
1915 * @object: This parameter specifies the base object for which the state
1916 * transition is occuring. This object is cast into a SCIC_SDS_IO_REQUEST
1917 * object.
1918 *
1919 * This method implements the actions taken when entering the
1920 * SCI_BASE_REQUEST_STATE_ABORTING state. none
1921 */
1922 static void scic_sds_request_aborting_state_enter(
1923 struct sci_base_object *object)
1924 {
1925 struct scic_sds_request *this_request = (struct scic_sds_request *)object;
1926
1927 /* Setting the abort bit in the Task Context is required by the silicon. */
1928 this_request->task_context_buffer->abort = 1;
1929
1930 SET_STATE_HANDLER(
1931 this_request,
1932 scic_sds_request_state_handler_table,
1933 SCI_BASE_REQUEST_STATE_ABORTING
1934 );
1935 }
1936
1937 /**
1938 * scic_sds_request_final_state_enter() -
1939 * @object: This parameter specifies the base object for which the state
1940 * transition is occuring. This is cast into a SCIC_SDS_IO_REQUEST object.
1941 *
1942 * This method implements the actions taken when entering the
1943 * SCI_BASE_REQUEST_STATE_FINAL state. The only action required is to put the
1944 * state handlers in place. none
1945 */
1946 static void scic_sds_request_final_state_enter(
1947 struct sci_base_object *object)
1948 {
1949 struct scic_sds_request *this_request = (struct scic_sds_request *)object;
1950
1951 SET_STATE_HANDLER(
1952 this_request,
1953 scic_sds_request_state_handler_table,
1954 SCI_BASE_REQUEST_STATE_FINAL
1955 );
1956 }
1957
1958 static const struct sci_base_state scic_sds_request_state_table[] = {
1959 [SCI_BASE_REQUEST_STATE_INITIAL] = {
1960 .enter_state = scic_sds_request_initial_state_enter,
1961 },
1962 [SCI_BASE_REQUEST_STATE_CONSTRUCTED] = {
1963 .enter_state = scic_sds_request_constructed_state_enter,
1964 },
1965 [SCI_BASE_REQUEST_STATE_STARTED] = {
1966 .enter_state = scic_sds_request_started_state_enter,
1967 .exit_state = scic_sds_request_started_state_exit
1968 },
1969 [SCI_BASE_REQUEST_STATE_COMPLETED] = {
1970 .enter_state = scic_sds_request_completed_state_enter,
1971 },
1972 [SCI_BASE_REQUEST_STATE_ABORTING] = {
1973 .enter_state = scic_sds_request_aborting_state_enter,
1974 },
1975 [SCI_BASE_REQUEST_STATE_FINAL] = {
1976 .enter_state = scic_sds_request_final_state_enter,
1977 },
1978 };
1979
1980 static void scic_sds_general_request_construct(struct scic_sds_controller *scic,
1981 struct scic_sds_remote_device *sci_dev,
1982 u16 io_tag,
1983 void *user_io_request_object,
1984 struct scic_sds_request *sci_req)
1985 {
1986 sci_base_request_construct(&sci_req->parent, scic_sds_request_state_table);
1987 sci_req->io_tag = io_tag;
1988 sci_req->user_request = user_io_request_object;
1989 sci_req->owning_controller = scic;
1990 sci_req->target_device = sci_dev;
1991 sci_req->has_started_substate_machine = false;
1992 sci_req->protocol = SCIC_NO_PROTOCOL;
1993 sci_req->saved_rx_frame_index = SCU_INVALID_FRAME_INDEX;
1994 sci_req->device_sequence = scic_sds_remote_device_get_sequence(sci_dev);
1995
1996 sci_req->sci_status = SCI_SUCCESS;
1997 sci_req->scu_status = 0;
1998 sci_req->post_context = 0xFFFFFFFF;
1999
2000 sci_req->is_task_management_request = false;
2001
2002 if (io_tag == SCI_CONTROLLER_INVALID_IO_TAG) {
2003 sci_req->was_tag_assigned_by_user = false;
2004 sci_req->task_context_buffer = NULL;
2005 } else {
2006 sci_req->was_tag_assigned_by_user = true;
2007
2008 sci_req->task_context_buffer =
2009 scic_sds_controller_get_task_context_buffer(scic, io_tag);
2010 }
2011 }
2012
2013 enum sci_status scic_io_request_construct(struct scic_sds_controller *scic,
2014 struct scic_sds_remote_device *sci_dev,
2015 u16 io_tag,
2016 void *user_io_request_object,
2017 struct scic_sds_request *sci_req,
2018 struct scic_sds_request **new_scic_io_request_handle)
2019 {
2020 enum sci_status status = SCI_SUCCESS;
2021 struct smp_discover_response_protocols device_protocol;
2022
2023 /* Build the common part of the request */
2024 scic_sds_general_request_construct(scic, sci_dev, io_tag,
2025 user_io_request_object, sci_req);
2026
2027 if (sci_dev->rnc->remote_node_index == SCIC_SDS_REMOTE_NODE_CONTEXT_INVALID_INDEX)
2028 return SCI_FAILURE_INVALID_REMOTE_DEVICE;
2029
2030 scic_remote_device_get_protocols(sci_dev, &device_protocol);
2031
2032 if (device_protocol.u.bits.attached_ssp_target) {
2033 scic_sds_ssp_io_request_assign_buffers(sci_req);
2034 } else if (device_protocol.u.bits.attached_stp_target) {
2035 scic_sds_stp_request_assign_buffers(sci_req);
2036 memset(sci_req->command_buffer, 0, sizeof(struct sata_fis_reg_h2d));
2037 } else if (device_protocol.u.bits.attached_smp_target) {
2038 scic_sds_smp_request_assign_buffers(sci_req);
2039 memset(sci_req->command_buffer, 0, sizeof(struct smp_request));
2040 } else {
2041 status = SCI_FAILURE_UNSUPPORTED_PROTOCOL;
2042 }
2043
2044 if (status == SCI_SUCCESS) {
2045 memset(sci_req->task_context_buffer, 0,
2046 SCI_FIELD_OFFSET(struct scu_task_context, sgl_pair_ab));
2047 *new_scic_io_request_handle = sci_req;
2048 }
2049
2050 return status;
2051 }
2052
2053 enum sci_status scic_task_request_construct(struct scic_sds_controller *scic,
2054 struct scic_sds_remote_device *sci_dev,
2055 u16 io_tag,
2056 void *user_io_request_object,
2057 struct scic_sds_request *sci_req,
2058 struct scic_sds_request **new_sci_req)
2059 {
2060 enum sci_status status = SCI_SUCCESS;
2061 struct smp_discover_response_protocols device_protocol;
2062
2063 /* Build the common part of the request */
2064 scic_sds_general_request_construct(scic, sci_dev, io_tag,
2065 user_io_request_object,
2066 sci_req);
2067
2068 scic_remote_device_get_protocols(sci_dev, &device_protocol);
2069
2070 if (device_protocol.u.bits.attached_ssp_target) {
2071 scic_sds_ssp_task_request_assign_buffers(sci_req);
2072
2073 sci_req->has_started_substate_machine = true;
2074
2075 /* Construct the started sub-state machine. */
2076 sci_base_state_machine_construct(
2077 &sci_req->started_substate_machine,
2078 &sci_req->parent.parent,
2079 scic_sds_io_request_started_task_mgmt_substate_table,
2080 SCIC_SDS_IO_REQUEST_STARTED_TASK_MGMT_SUBSTATE_AWAIT_TC_COMPLETION
2081 );
2082 } else if (device_protocol.u.bits.attached_stp_target) {
2083 scic_sds_stp_request_assign_buffers(sci_req);
2084 } else {
2085 status = SCI_FAILURE_UNSUPPORTED_PROTOCOL;
2086 }
2087
2088 if (status == SCI_SUCCESS) {
2089 sci_req->is_task_management_request = true;
2090 memset(sci_req->task_context_buffer, 0, sizeof(struct scu_task_context));
2091 *new_sci_req = sci_req;
2092 }
2093
2094 return status;
2095 }
This page took 0.102874 seconds and 6 git commands to generate.